feat: migrate to OpenCode SDK v2

Update all import statements to use @opencode-ai/sdk/v2
Modify Vite configurations to alias new SDK path
Update API client method signatures for SDK v2 compatibility
This commit is contained in:
Bohdan Triapitsyn
2026-01-03 13:39:59 +02:00
parent 5029acfb9d
commit f2507d58cf
46 changed files with 167 additions and 184 deletions
+7 -7
View File
@@ -12,12 +12,12 @@ export default defineConfig({
root: path.resolve(__dirname, '.'),
plugins: [react(), themeStoragePlugin()],
resolve: {
alias: {
'@desktop': path.resolve(__dirname, './src'),
'@openchamber/ui': path.resolve(__dirname, '../ui/src'),
'@': path.resolve(__dirname, '../ui/src'),
'@opencode-ai/sdk': path.resolve(__dirname, '../../node_modules/@opencode-ai/sdk/dist/client.js'),
},
alias: [
{ find: '@opencode-ai/sdk/v2', replacement: path.resolve(__dirname, '../../node_modules/@opencode-ai/sdk/dist/v2/client.js') },
{ find: '@openchamber/ui', replacement: path.resolve(__dirname, '../ui/src') },
{ find: '@desktop', replacement: path.resolve(__dirname, './src') },
{ find: '@', replacement: path.resolve(__dirname, '../ui/src') },
],
},
worker: {
format: 'es',
@@ -31,7 +31,7 @@ export default defineConfig({
__APP_VERSION__: JSON.stringify(packageJson.version),
},
optimizeDeps: {
include: ['@opencode-ai/sdk'],
include: ['@opencode-ai/sdk/v2'],
exclude: [
'@tauri-apps/plugin-dialog',
'@tauri-apps/api/core',
@@ -1,5 +1,5 @@
import React from 'react';
import type { Message, Part } from '@opencode-ai/sdk';
import type { Message, Part } from '@opencode-ai/sdk/v2';
import { useShallow } from 'zustand/react/shallow';
import { defaultCodeDark, defaultCodeLight } from '@/lib/codeTheme';
@@ -1,7 +1,7 @@
import React from 'react';
import { Streamdown } from 'streamdown';
import { FadeInOnReveal } from './message/FadeInOnReveal';
import type { Part } from '@opencode-ai/sdk';
import type { Part } from '@opencode-ai/sdk/v2';
import { cn } from '@/lib/utils';
import { RiFileCopyLine, RiCheckLine, RiDownloadLine } from '@remixicon/react';
@@ -1,5 +1,5 @@
import React from 'react';
import type { Message, Part } from '@opencode-ai/sdk';
import type { Message, Part } from '@opencode-ai/sdk/v2';
import ChatMessage from './ChatMessage';
import { PermissionCard } from './PermissionCard';
@@ -12,7 +12,7 @@ import { useSessionStore } from '@/stores/useSessionStore';
import { useMessageStore } from '@/stores/messageStore';
import { cn } from '@/lib/utils';
import { RiLoader4Line, RiSearchLine, RiTimeLine, RiGitBranchLine } from '@remixicon/react';
import type { Part } from '@opencode-ai/sdk';
import type { Part } from '@opencode-ai/sdk/v2';
interface TimelineDialogProps {
open: boolean;
@@ -1,5 +1,5 @@
import React from 'react';
import type { Message, Part } from '@opencode-ai/sdk';
import type { Message, Part } from '@opencode-ai/sdk/v2';
import { useCurrentSessionActivity } from '@/hooks/useSessionActivity';
import { useUIStore } from '@/stores/useUIStore';
@@ -1,5 +1,5 @@
import React from 'react';
import type { Part } from '@opencode-ai/sdk';
import type { Part } from '@opencode-ai/sdk/v2';
import AssistantTextPart from './parts/AssistantTextPart';
import UserTextPart from './parts/UserTextPart';
@@ -8,7 +8,7 @@ import ToolPart from './parts/ToolPart';
import ProgressiveGroup from './parts/ProgressiveGroup';
import MigratingPart from './parts/MigratingPart';
import { MessageFilesDisplay } from '../FileAttachment';
import type { ToolPart as ToolPartType } from '@opencode-ai/sdk';
import type { ToolPart as ToolPartType } from '@opencode-ai/sdk/v2';
import type { StreamPhase, ToolPopupContent, AgentMentionInfo } from './types';
import type { TurnGroupingContext } from '../hooks/useTurnGrouping';
import { cn } from '@/lib/utils';
@@ -1,4 +1,4 @@
import type { Message } from '@opencode-ai/sdk';
import type { Message } from '@opencode-ai/sdk/v2';
export interface MessageRoleInfo {
role: string;
@@ -1,4 +1,4 @@
import type { Part } from '@opencode-ai/sdk';
import type { Part } from '@opencode-ai/sdk/v2';
type PartWithText = Part & { text?: string; content?: string; value?: string };
@@ -1,5 +1,5 @@
import React from 'react';
import type { Part } from '@opencode-ai/sdk';
import type { Part } from '@opencode-ai/sdk/v2';
import { MarkdownRenderer } from '../../MarkdownRenderer';
import type { StreamPhase } from '../types';
import type { ContentChangeReason } from '@/hooks/useChatScrollManager';
@@ -1,5 +1,5 @@
import React from 'react';
import type { Part } from '@opencode-ai/sdk';
import type { Part } from '@opencode-ai/sdk/v2';
import type { ContentChangeReason } from '@/hooks/useChatScrollManager';
import { ReasoningTimelineBlock } from './ReasoningPart';
@@ -2,7 +2,7 @@ import React from 'react';
import { RiArrowDownSLine, RiArrowRightSLine, RiStackLine } from '@remixicon/react';
import { cn } from '@/lib/utils';
import type { TurnActivityPart } from '../../hooks/useTurnGrouping';
import type { ToolPart as ToolPartType } from '@opencode-ai/sdk';
import type { ToolPart as ToolPartType } from '@opencode-ai/sdk/v2';
import type { ContentChangeReason } from '@/hooks/useChatScrollManager';
import type { ToolPopupContent } from '../types';
import ToolPart from './ToolPart';
@@ -1,6 +1,6 @@
import React from 'react';
import type { ComponentType } from 'react';
import type { Part } from '@opencode-ai/sdk';
import type { Part } from '@opencode-ai/sdk/v2';
import { RiArrowDownSLine, RiArrowRightSLine, RiBrainAi3Line, RiChatAi3Line } from '@remixicon/react';
import { cn } from '@/lib/utils';
import type { ContentChangeReason } from '@/hooks/useChatScrollManager';
@@ -5,7 +5,7 @@ import { RiArrowDownSLine, RiArrowRightSLine, RiBookLine, RiFileEditLine, RiFile
import { cn } from '@/lib/utils';
import { SimpleMarkdownRenderer } from '../../MarkdownRenderer';
import { getToolMetadata, getLanguageFromExtension, isImageFile, getImageMimeType } from '@/lib/toolHelpers';
import type { ToolPart as ToolPartType, ToolState as ToolStateUnion } from '@opencode-ai/sdk';
import type { ToolPart as ToolPartType, ToolState as ToolStateUnion } from '@opencode-ai/sdk/v2';
import { toolDisplayStyles } from '@/lib/typography';
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
import { useDirectoryStore } from '@/stores/useDirectoryStore';
@@ -1,7 +1,7 @@
import React from 'react';
import { cn } from '@/lib/utils';
import type { Part } from '@opencode-ai/sdk';
import type { Part } from '@opencode-ai/sdk/v2';
import type { AgentMentionInfo } from '../types';
type PartWithText = Part & { text?: string; content?: string; value?: string };
@@ -23,7 +23,7 @@ import { useUIStore } from '@/stores/useUIStore';
import { useDeviceInfo } from '@/lib/device';
import { isVSCodeRuntime } from '@/lib/desktop';
import { cn } from '@/lib/utils';
import type { Agent } from '@opencode-ai/sdk';
import type { Agent } from '@opencode-ai/sdk/v2';
import { ScrollableOverlay } from '@/components/ui/ScrollableOverlay';
interface AgentsSidebarProps {
@@ -400,10 +400,8 @@ export const DirectoryTree: React.FC<DirectoryTreeProps> = ({
const tempClient = opencodeClient.getApiClient();
const response = await tempClient.file.list({
query: {
path: '.',
directory: path
}
path: '.',
directory: path
});
if (!response.data) {
@@ -25,7 +25,7 @@ import { RiCheckboxBlankLine, RiCheckboxLine, RiDeleteBinLine } from '@remixicon
import { MobileOverlayPanel } from '@/components/ui/MobileOverlayPanel';
import { DirectoryExplorerDialog } from './DirectoryExplorerDialog';
import { cn, formatPathForDisplay } from '@/lib/utils';
import type { Session } from '@opencode-ai/sdk';
import type { Session } from '@opencode-ai/sdk/v2';
import type { WorktreeMetadata } from '@/types/worktree';
import {
archiveWorktree,
@@ -1,5 +1,5 @@
import React from 'react';
import type { Session } from '@opencode-ai/sdk';
import type { Session } from '@opencode-ai/sdk/v2';
import { toast } from 'sonner';
import {
DropdownMenu,
+1 -1
View File
@@ -15,7 +15,7 @@ import {
import { ScrollableOverlay } from '@/components/ui/ScrollableOverlay';
import { RiGitBranchLine, RiLoader4Line } from '@remixicon/react';
import { toast } from 'sonner';
import type { Session } from '@opencode-ai/sdk';
import type { Session } from '@opencode-ai/sdk/v2';
import { useRuntimeAPIs } from '@/hooks/useRuntimeAPIs';
import { useUIStore } from '@/stores/useUIStore';
+1 -1
View File
@@ -1,5 +1,5 @@
import React from 'react';
import type { AssistantMessage, Message, Part, ReasoningPart, TextPart, ToolPart } from '@opencode-ai/sdk';
import type { AssistantMessage, Message, Part, ReasoningPart, TextPart, ToolPart } from '@opencode-ai/sdk/v2';
import { useShallow } from 'zustand/react/shallow';
import type { MessageStreamPhase } from '@/stores/types/sessionTypes';
@@ -1,5 +1,5 @@
import React from 'react';
import type { Part } from '@opencode-ai/sdk';
import type { Part } from '@opencode-ai/sdk/v2';
import { MessageFreshnessDetector } from '@/lib/messageFreshness';
+1 -1
View File
@@ -5,7 +5,7 @@ import { useSessionStore } from '@/stores/useSessionStore';
import { useConfigStore } from '@/stores/useConfigStore';
import { useUIStore, type EventStreamStatus } from '@/stores/useUIStore';
import { useDirectoryStore } from '@/stores/useDirectoryStore';
import type { Part, Session, Message, Permission } from '@opencode-ai/sdk';
import type { Part, Session, Message, Permission } from '@opencode-ai/sdk/v2';
import { streamDebugEnabled } from '@/stores/utils/streamDebug';
import { handleTodoUpdatedEvent } from '@/stores/useTodoStore';
+1 -1
View File
@@ -1,5 +1,5 @@
import React from 'react';
import type { AssistantMessage, Message, Part } from '@opencode-ai/sdk';
import type { AssistantMessage, Message, Part } from '@opencode-ai/sdk/v2';
import { useSessionStore, MEMORY_LIMITS } from '@/stores/useSessionStore';
import { opencodeClient } from '@/lib/opencode/client';
import { readSessionCursor } from '@/lib/messageCursorPersistence';
+1 -1
View File
@@ -1,7 +1,7 @@
import React from 'react';
import { useConfigStore } from '@/stores/useConfigStore';
import { useUIStore } from '@/stores/useUIStore';
import type { Provider } from '@opencode-ai/sdk';
import type { Provider } from '@opencode-ai/sdk/v2';
type ProviderModel = Provider["models"][string];
type ProviderWithModelList = Omit<Provider, "models"> & { models: ProviderModel[] };
@@ -1,5 +1,5 @@
import React from 'react';
import type { Session } from '@opencode-ai/sdk';
import type { Session } from '@opencode-ai/sdk/v2';
import { useSessionStore } from '@/stores/useSessionStore';
import { useUIStore } from '@/stores/useUIStore';
+1 -1
View File
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { Part } from "@opencode-ai/sdk";
import type { Part } from "@opencode-ai/sdk/v2";
import { isFullySyntheticMessage } from "@/lib/messages/synthetic";
export interface MessageInfo {
+1 -1
View File
@@ -1,4 +1,4 @@
import type { Message } from '@opencode-ai/sdk';
import type { Message } from '@opencode-ai/sdk/v2';
export class MessageFreshnessDetector {
private static instance: MessageFreshnessDetector;
@@ -1,4 +1,4 @@
import type { Agent } from "@opencode-ai/sdk";
import type { Agent } from "@opencode-ai/sdk/v2";
export interface AgentMentionSource {
value: string;
+1 -1
View File
@@ -1,4 +1,4 @@
import type { Part } from '@opencode-ai/sdk';
import type { Part } from '@opencode-ai/sdk/v2';
type TextLikePart = Part & { text?: string; content?: string };
+1 -1
View File
@@ -1,4 +1,4 @@
import type { Part } from "@opencode-ai/sdk";
import type { Part } from "@opencode-ai/sdk/v2";
export const isSyntheticPart = (part: Part | undefined): boolean => {
if (!part || typeof part !== "object") {
+74 -85
View File
@@ -1,4 +1,4 @@
import { createOpencodeClient, OpencodeClient } from "@opencode-ai/sdk";
import { createOpencodeClient, OpencodeClient } from "@opencode-ai/sdk/v2";
import type { FilesAPI, RuntimeAPIs } from "../api/types";
import { getDesktopHomeDirectory } from "../desktop";
import type {
@@ -12,7 +12,7 @@ import type {
TextPartInput,
FilePartInput,
Event,
} from "@opencode-ai/sdk";
} from "@opencode-ai/sdk/v2";
type StreamEvent<TData> = {
data: TData;
event?: string;
@@ -238,9 +238,9 @@ class OpencodeService {
};
try {
const response = await this.client.path.get({
query: this.currentDirectory ? { directory: this.currentDirectory } : undefined
});
const response = await this.client.path.get(
this.currentDirectory ? { directory: this.currentDirectory } : undefined
);
const info = response.data;
if (info) {
addCandidate(info.directory);
@@ -253,9 +253,9 @@ class OpencodeService {
if (!candidates.size) {
try {
const project = await this.client.project.current({
query: this.currentDirectory ? { directory: this.currentDirectory } : undefined
});
const project = await this.client.project.current(
this.currentDirectory ? { directory: this.currentDirectory } : undefined
);
addCandidate(project.data?.worktree);
} catch (error) {
console.debug('Failed to load project info:', error);
@@ -296,19 +296,17 @@ class OpencodeService {
// Session Management
async listSessions(): Promise<Session[]> {
const response = await this.client.session.list({
query: this.currentDirectory ? { directory: this.currentDirectory } : undefined
});
const response = await this.client.session.list(
this.currentDirectory ? { directory: this.currentDirectory } : undefined
);
return Array.isArray(response.data) ? response.data : [];
}
async createSession(params?: { parentID?: string; title?: string }): Promise<Session> {
const response = await this.client.session.create({
query: this.currentDirectory ? { directory: this.currentDirectory } : undefined,
body: {
parentID: params?.parentID,
title: params?.title
}
...(this.currentDirectory ? { directory: this.currentDirectory } : {}),
parentID: params?.parentID,
title: params?.title
});
if (!response.data) throw new Error('Failed to create session');
return response.data;
@@ -316,8 +314,8 @@ class OpencodeService {
async getSession(id: string): Promise<Session> {
const response = await this.client.session.get({
path: { id },
query: this.currentDirectory ? { directory: this.currentDirectory } : undefined
sessionID: id,
...(this.currentDirectory ? { directory: this.currentDirectory } : {})
});
if (!response.data) throw new Error('Session not found');
return response.data;
@@ -325,17 +323,17 @@ class OpencodeService {
async deleteSession(id: string): Promise<boolean> {
const response = await this.client.session.delete({
path: { id },
query: this.currentDirectory ? { directory: this.currentDirectory } : undefined
sessionID: id,
...(this.currentDirectory ? { directory: this.currentDirectory } : {})
});
return response.data || false;
}
async updateSession(id: string, title?: string): Promise<Session> {
const response = await this.client.session.update({
path: { id },
query: this.currentDirectory ? { directory: this.currentDirectory } : undefined,
body: { title }
sessionID: id,
...(this.currentDirectory ? { directory: this.currentDirectory } : {}),
title
});
if (!response.data) throw new Error('Failed to update session');
return response.data;
@@ -343,8 +341,8 @@ class OpencodeService {
async getSessionMessages(id: string): Promise<{ info: Message; parts: Part[] }[]> {
const response = await this.client.session.messages({
path: { id },
query: this.currentDirectory ? { directory: this.currentDirectory } : undefined
sessionID: id,
...(this.currentDirectory ? { directory: this.currentDirectory } : {})
});
return response.data || [];
}
@@ -618,17 +616,15 @@ class OpencodeService {
// Use SDK session.prompt() method
// DON'T send messageID - let server generate it (fixes Claude empty response issue)
await this.client.session.prompt({
path: { id: params.id },
query: this.currentDirectory ? { directory: this.currentDirectory } : undefined,
body: {
// messageID intentionally omitted - server will generate
model: {
providerID: params.providerID,
modelID: params.modelID
},
agent: params.agent,
parts
}
sessionID: params.id,
...(this.currentDirectory ? { directory: this.currentDirectory } : {}),
// messageID intentionally omitted - server will generate
model: {
providerID: params.providerID,
modelID: params.modelID
},
agent: params.agent,
parts
});
// Return temporary ID for optimistic UI
@@ -637,19 +633,22 @@ class OpencodeService {
}
async abortSession(id: string): Promise<boolean> {
const response = await this.client.session.abort({
path: { id },
query: this.currentDirectory ? { directory: this.currentDirectory } : undefined,
throwOnError: true,
});
const response = await this.client.session.abort(
{
sessionID: id,
...(this.currentDirectory ? { directory: this.currentDirectory } : {})
},
{ throwOnError: true }
);
return Boolean(response.data);
}
async revertSession(sessionId: string, messageId: string, partId?: string): Promise<Session> {
const response = await this.client.session.revert({
path: { id: sessionId },
query: this.currentDirectory ? { directory: this.currentDirectory } : undefined,
body: { messageID: messageId, partID: partId }
sessionID: sessionId,
...(this.currentDirectory ? { directory: this.currentDirectory } : {}),
messageID: messageId,
partID: partId
});
if (!response.data) throw new Error('Failed to revert session');
return response.data;
@@ -657,33 +656,25 @@ class OpencodeService {
async unrevertSession(sessionId: string): Promise<Session> {
const response = await this.client.session.unrevert({
path: { id: sessionId },
query: this.currentDirectory ? { directory: this.currentDirectory } : undefined
sessionID: sessionId,
...(this.currentDirectory ? { directory: this.currentDirectory } : {})
});
if (!response.data) throw new Error('Failed to unrevert session');
return response.data;
}
async forkSession(sessionId: string, messageId?: string): Promise<Session> {
const baseUrl = this.baseUrl.replace(/\/$/, '');
const url = new URL(`/api/session/${sessionId}/fork`, baseUrl);
if (this.currentDirectory) {
url.searchParams.set('directory', this.currentDirectory);
}
const response = await fetch(url.toString(), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(messageId ? { messageID: messageId } : {}),
const response = await this.client.session.fork({
sessionID: sessionId,
...(this.currentDirectory ? { directory: this.currentDirectory } : {}),
messageID: messageId
});
if (!response.ok) {
const text = await response.text();
throw new Error(`Failed to fork session: ${text || response.statusText}`);
if (!response.data) {
throw new Error('Failed to fork session');
}
return response.json();
return response.data;
}
async getSessionStatus(): Promise<
@@ -741,10 +732,11 @@ class OpencodeService {
permissionId: string,
response: 'once' | 'always' | 'reject'
): Promise<boolean> {
const result = await this.client.postSessionIdPermissionsPermissionId({
path: { id: sessionId, permissionID: permissionId },
query: this.currentDirectory ? { directory: this.currentDirectory } : undefined,
body: { response }
const result = await this.client.permission.respond({
sessionID: sessionId,
permissionID: permissionId,
...(this.currentDirectory ? { directory: this.currentDirectory } : {}),
response
});
return result.data || false;
}
@@ -800,9 +792,9 @@ class OpencodeService {
providers: Provider[];
default: { [key: string]: string };
}> {
const response = await this.client.config.providers({
query: this.currentDirectory ? { directory: this.currentDirectory } : undefined
});
const response = await this.client.config.providers(
this.currentDirectory ? { directory: this.currentDirectory } : undefined
);
if (!response.data) throw new Error('Failed to get providers');
return response.data;
}
@@ -829,9 +821,9 @@ class OpencodeService {
// Agent Management
async listAgents(): Promise<Agent[]> {
try {
const response = await this.client.app.agents({
query: this.currentDirectory ? { directory: this.currentDirectory } : undefined
});
const response = await this.client.app.agents(
this.currentDirectory ? { directory: this.currentDirectory } : undefined
);
return response.data || [];
} catch {
return [];
@@ -868,17 +860,15 @@ class OpencodeService {
const connect = async (attempt: number): Promise<void> => {
try {
const subscribeParameters = resolvedDirectory ? { directory: resolvedDirectory } : undefined;
const subscribeOptions: {
query?: { directory?: string };
signal: AbortSignal;
sseDefaultRetryDelay: number;
sseMaxRetryDelay: number;
onSseError?: (error: unknown) => void;
onSseEvent: (event: StreamEvent<unknown>) => void;
headers?: Record<string, string>;
lastEventId?: string;
} = {
query: resolvedDirectory ? { directory: resolvedDirectory } : undefined,
signal: abortController.signal,
sseDefaultRetryDelay: 3000,
sseMaxRetryDelay: 30000,
@@ -904,11 +894,10 @@ class OpencodeService {
};
if (lastEventId) {
subscribeOptions.lastEventId = lastEventId;
subscribeOptions.headers = { ...(subscribeOptions.headers || {}), 'Last-Event-ID': lastEventId };
}
const result = await this.client.event.subscribe(subscribeOptions);
const result = await this.client.event.subscribe(subscribeParameters, subscribeOptions);
if (onOpen && !abortController.signal.aborted) {
console.log('[OpencodeClient] SSE connection opened');
@@ -1019,9 +1008,9 @@ class OpencodeService {
// Command Management
async listCommands(): Promise<Array<{ name: string; description?: string; agent?: string; model?: string }>> {
try {
const response = await this.client.command.list({
query: this.currentDirectory ? { directory: this.currentDirectory } : undefined
});
const response = await this.client.command.list(
this.currentDirectory ? { directory: this.currentDirectory } : undefined
);
// Return only lightweight info for autocomplete
return (response.data || []).map((cmd: Record<string, unknown>) => ({
name: cmd.name as string,
@@ -1037,9 +1026,9 @@ class OpencodeService {
async listCommandsWithDetails(): Promise<Array<{ name: string; description?: string; agent?: string; model?: string; template?: string; subtask?: boolean }>> {
try {
const response = await this.client.command.list({
query: this.currentDirectory ? { directory: this.currentDirectory } : undefined
});
const response = await this.client.command.list(
this.currentDirectory ? { directory: this.currentDirectory } : undefined
);
// Return full command details including template
return (response.data || []).map((cmd: Record<string, unknown>) => ({
name: cmd.name as string,
@@ -1056,9 +1045,9 @@ class OpencodeService {
async getCommandDetails(name: string): Promise<{ name: string; template: string; description?: string; agent?: string; model?: string } | null> {
try {
const response = await this.client.command.list({
query: this.currentDirectory ? { directory: this.currentDirectory } : undefined
});
const response = await this.client.command.list(
this.currentDirectory ? { directory: this.currentDirectory } : undefined
);
if (response.data) {
const command = response.data.find((cmd: Record<string, unknown>) => cmd.name === name);
+1 -1
View File
@@ -1,4 +1,4 @@
import type { Session } from '@opencode-ai/sdk';
import type { Session } from '@opencode-ai/sdk/v2';
import type { WorktreeMetadata } from '@/types/worktree';
export type SessionDeleteRequest = {
+2 -4
View File
@@ -216,10 +216,8 @@ export const useFileStore = create<FileStore>()(
const filename = lastSlashIndex > 0 ? path.substring(lastSlashIndex + 1) : path;
const response = await tempClient.file.read({
query: {
path: filename,
directory: directory,
},
path: filename,
directory: directory,
});
if (response.data && "content" in response.data) {
+10 -14
View File
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { create } from "zustand";
import { devtools, persist, createJSONStorage } from "zustand/middleware";
import type { Message, Part } from "@opencode-ai/sdk";
import type { Message, Part } from "@opencode-ai/sdk/v2";
import { opencodeClient } from "@/lib/opencode/client";
import { isExecutionForkMetaText } from "@/lib/messages/executionMeta";
import type { SessionMemoryState, MessageStreamLifecycle, AttachedFile } from "./types/sessionTypes";
@@ -586,13 +586,11 @@ export const useMessageStore = create<MessageStore>()(
const messageId = `msg_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
await apiClient.session.init({
path: { id: sessionId },
body: {
messageID: messageId,
providerID,
modelID,
},
query: directory ? { directory } : undefined,
sessionID: sessionId,
...(directory ? { directory } : {}),
messageID: messageId,
providerID,
modelID,
});
return;
@@ -600,12 +598,10 @@ export const useMessageStore = create<MessageStore>()(
if (command === "summarize") {
await apiClient.session.summarize({
path: { id: sessionId },
body: {
providerID,
modelID,
},
query: directory ? { directory } : undefined,
sessionID: sessionId,
...(directory ? { directory } : {}),
providerID,
modelID,
});
return;
+11 -11
View File
@@ -1,6 +1,6 @@
import { create } from "zustand";
import { devtools, persist, createJSONStorage } from "zustand/middleware";
import type { Session } from "@opencode-ai/sdk";
import type { Session } from "@opencode-ai/sdk/v2";
import { opencodeClient } from "@/lib/opencode/client";
import { getSafeStorage } from "./utils/safeStorage";
import type { WorktreeMetadata } from "@/types/worktree";
@@ -254,9 +254,9 @@ export const useSessionStore = create<SessionStore>()(
const apiClient = opencodeClient.getApiClient();
const fetchSessions = async (directoryParam?: string | null): Promise<Session[]> => {
const response = await apiClient.session.list({
query: directoryParam ? { directory: directoryParam } : undefined,
});
const response = await apiClient.session.list(
directoryParam ? { directory: directoryParam } : undefined
);
return Array.isArray(response.data) ? response.data : [];
};
@@ -536,9 +536,9 @@ export const useSessionStore = create<SessionStore>()(
const attempts = 20;
for (let attempt = 0; attempt < attempts; attempt += 1) {
try {
const response = await apiClient.session.list({
query: targetDirectory ? { directory: targetDirectory } : undefined,
});
const response = await apiClient.session.list(
targetDirectory ? { directory: targetDirectory } : undefined
);
const list = Array.isArray(response.data) ? response.data : [];
const candidate = list.find((entry) => {
if (existingIds.has(entry.id)) return false;
@@ -817,8 +817,8 @@ export const useSessionStore = create<SessionStore>()(
const shareRequest = async () => {
const directory = sessionDirectory ?? opencodeClient.getDirectory();
return apiClient.session.share({
path: { id },
query: directory ? { directory } : undefined,
sessionID: id,
...(directory ? { directory } : {})
});
};
const response = overrideDirectory
@@ -849,8 +849,8 @@ export const useSessionStore = create<SessionStore>()(
const unshareRequest = async () => {
const directory = sessionDirectory ?? opencodeClient.getDirectory();
return apiClient.session.unshare({
path: { id },
query: directory ? { directory } : undefined,
sessionID: id,
...(directory ? { directory } : {})
});
};
const response = overrideDirectory
+1 -1
View File
@@ -1,4 +1,4 @@
import type { Session, Message, Part } from "@opencode-ai/sdk";
import type { Session, Message, Part } from "@opencode-ai/sdk/v2";
import type { Permission, PermissionResponse } from "@/types/permission";
export interface AttachedFile {
+5 -3
View File
@@ -1,7 +1,7 @@
import { create } from "zustand";
import type { StoreApi, UseBoundStore } from "zustand";
import { devtools, persist, createJSONStorage } from "zustand/middleware";
import type { Agent } from "@opencode-ai/sdk";
import type { Agent } from "@opencode-ai/sdk/v2";
import { opencodeClient } from "@/lib/opencode/client";
import { emitConfigChange, scopeMatches, subscribeToConfigChanges } from "@/lib/configSync";
import {
@@ -62,8 +62,10 @@ export type AgentWithExtras = Agent & {
};
// Helper to check if agent is built-in (handles both SDK 'builtIn' and API 'native')
export const isAgentBuiltIn = (agent: Agent): boolean =>
agent.builtIn || (agent as AgentWithExtras).native === true;
export const isAgentBuiltIn = (agent: Agent): boolean => {
const extended = agent as AgentWithExtras & { builtIn?: boolean };
return extended.native === true || extended.builtIn === true;
};
// Helper to check if agent is hidden (internal agents like title, compaction, summary)
// Checks both top-level hidden and options.hidden (OpenCode API inconsistency workaround)
+1 -1
View File
@@ -1,7 +1,7 @@
import { create } from "zustand";
import type { StoreApi, UseBoundStore } from "zustand";
import { devtools, persist, createJSONStorage } from "zustand/middleware";
import type { Provider, Agent } from "@opencode-ai/sdk";
import type { Provider, Agent } from "@opencode-ai/sdk/v2";
import { opencodeClient } from "@/lib/opencode/client";
import { scopeMatches, subscribeToConfigChanges } from "@/lib/configSync";
import type { ModelMetadata } from "@/types";
+1 -1
View File
@@ -1,7 +1,7 @@
import { create } from "zustand";
import type { StoreApi, UseBoundStore } from "zustand";
import { devtools } from "zustand/middleware";
import type { Session, Message, Part } from "@opencode-ai/sdk";
import type { Session, Message, Part } from "@opencode-ai/sdk/v2";
import type { Permission, PermissionResponse } from "@/types/permission";
import type { SessionStore, AttachedFile, EditPermissionMode } from "./types/sessionTypes";
import { ACTIVE_SESSION_WINDOW, MEMORY_LIMITS } from "./types/sessionTypes";
+1 -1
View File
@@ -1,4 +1,4 @@
import type { Part } from "@opencode-ai/sdk";
import type { Part } from "@opencode-ai/sdk/v2";
const extractTextFromDelta = (delta: unknown): string => {
if (!delta) return '';
+1 -1
View File
@@ -1,4 +1,4 @@
import type { Message, Part } from "@opencode-ai/sdk";
import type { Message, Part } from "@opencode-ai/sdk/v2";
type TokenBreakdown = {
input?: number;
+1 -1
View File
@@ -1,4 +1,4 @@
import type { Session, Message, Part, Provider } from "@opencode-ai/sdk";
import type { Session, Message, Part, Provider } from "@opencode-ai/sdk/v2";
export type { Session, Message, Part, Provider };
+7 -7
View File
@@ -10,12 +10,12 @@ export default defineConfig({
base: './', // Use relative paths for VS Code webview
plugins: [react()],
resolve: {
alias: {
'@': path.resolve(__dirname, '../ui/src'),
'@vscode': path.resolve(__dirname, './webview'),
'@openchamber/ui': path.resolve(__dirname, '../ui/src'),
'@opencode-ai/sdk': path.resolve(__dirname, '../../node_modules/@opencode-ai/sdk/dist/client.js'),
},
alias: [
{ find: '@opencode-ai/sdk/v2', replacement: path.resolve(__dirname, '../../node_modules/@opencode-ai/sdk/dist/v2/client.js') },
{ find: '@openchamber/ui', replacement: path.resolve(__dirname, '../ui/src') },
{ find: '@vscode', replacement: path.resolve(__dirname, './webview') },
{ find: '@', replacement: path.resolve(__dirname, '../ui/src') },
],
},
worker: {
format: 'es',
@@ -26,7 +26,7 @@ export default defineConfig({
},
envPrefix: ['VITE_'],
optimizeDeps: {
include: ['@opencode-ai/sdk'],
include: ['@opencode-ai/sdk/v2'],
},
build: {
outDir: path.resolve(__dirname, 'dist/webview'),
+7 -7
View File
@@ -15,12 +15,12 @@ export default defineConfig({
themeStoragePlugin(),
],
resolve: {
alias: {
'@': path.resolve(__dirname, '../ui/src'),
'@web': path.resolve(__dirname, './src'),
'@openchamber/ui': path.resolve(__dirname, '../ui/src'),
'@opencode-ai/sdk': path.resolve(__dirname, '../../node_modules/@opencode-ai/sdk/dist/client.js'),
},
alias: [
{ find: '@opencode-ai/sdk/v2', replacement: path.resolve(__dirname, '../../node_modules/@opencode-ai/sdk/dist/v2/client.js') },
{ find: '@openchamber/ui', replacement: path.resolve(__dirname, '../ui/src') },
{ find: '@web', replacement: path.resolve(__dirname, './src') },
{ find: '@', replacement: path.resolve(__dirname, '../ui/src') },
],
},
worker: {
format: 'es',
@@ -31,7 +31,7 @@ export default defineConfig({
__APP_VERSION__: JSON.stringify(packageJson.version),
},
optimizeDeps: {
include: ['@opencode-ai/sdk'],
include: ['@opencode-ai/sdk/v2'],
},
server: {
port: 5173,
+5 -5
View File
@@ -12,10 +12,10 @@ export default defineConfig({
themeStoragePlugin(),
],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
'@opencode-ai/sdk': path.resolve(__dirname, './node_modules/@opencode-ai/sdk/dist/client.js'),
},
alias: [
{ find: '@opencode-ai/sdk/v2', replacement: path.resolve(__dirname, './node_modules/@opencode-ai/sdk/dist/v2/client.js') },
{ find: '@', replacement: path.resolve(__dirname, './src') },
],
},
worker: {
format: 'es',
@@ -25,7 +25,7 @@ export default defineConfig({
global: 'globalThis',
},
optimizeDeps: {
include: ['@opencode-ai/sdk'],
include: ['@opencode-ai/sdk/v2'],
},
build: {
chunkSizeWarningLimit: 1200,