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
@@ -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';