GeezerVison is showing github.com — v2 SDK (#5216) · Stephanvs/opencode@ea7ec60
File treeExpand file treeCollapse file tree Open diff view settings Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: bun.lock +40-56Lines changed: 40 additions & 56 deletions Collapse file Copy file name to clipboardExpand all lines: package.json +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 39 | 39 | "fuzzysort": "3.1.0", | 40 | 40 | "luxon": "3.6.1", | 41 | 41 | "typescript": "5.8.2", | 42 | | - "@typescript/native-preview": "7.0.0-dev.20251014.1", | | 42 | + "@typescript/native-preview": "7.0.0-dev.20251207.1", | 43 | 43 | "zod": "4.1.8", | 44 | 44 | "remeda": "2.26.0", | 45 | 45 | "solid-list": "0.3.0", | |
Collapse file Copy file name to clipboardExpand all lines: packages/desktop/src/components/prompt-input.tsx +13-17Lines changed: 13 additions & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -235,9 +235,7 @@ export const PromptInput: Component<PromptInputProps> = (props) => { | 235 | 235 |
| 236 | 236 | const abort = () => | 237 | 237 | sdk.client.session.abort({ | 238 | | - path: { | 239 | | - id: session.id!, | 240 | | - }, | | 238 | + sessionID: session.id!, | 241 | 239 | }) | 242 | 240 |
| 243 | 241 | const handleKeyDown = (event: KeyboardEvent) => { | @@ -329,21 +327,19 @@ export const PromptInput: Component<PromptInputProps> = (props) => { | 329 | 327 | session.prompt.set([{ type: "text", content: "", start: 0, end: 0 }], 0) | 330 | 328 |
| 331 | 329 | sdk.client.session.prompt({ | 332 | | - path: { id: existing.id }, | 333 | | - body: { | 334 | | - agent: local.agent.current()!.name, | 335 | | - model: { | 336 | | - modelID: local.model.current()!.id, | 337 | | - providerID: local.model.current()!.provider.id, | 338 | | - }, | 339 | | - parts: [ | 340 | | - { | 341 | | - type: "text", | 342 | | - text, | 343 | | - }, | 344 | | - ...attachmentParts, | 345 | | - ], | | 330 | + sessionID: existing.id, | | 331 | + agent: local.agent.current()!.name, | | 332 | + model: { | | 333 | + modelID: local.model.current()!.id, | | 334 | + providerID: local.model.current()!.provider.id, | 346 | 335 | }, | | 336 | + parts: [ | | 337 | + { | | 338 | + type: "text", | | 339 | + text, | | 340 | + }, | | 341 | + ...attachmentParts, | | 342 | + ], | 347 | 343 | }) | 348 | 344 | } | 349 | 345 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/desktop/src/components/terminal.tsx +8-12Lines changed: 8 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -74,12 +74,10 @@ export const Terminal = (props: TerminalProps) => { | 74 | 74 | term.onResize(async (size) => { | 75 | 75 | if (ws && ws.readyState === WebSocket.OPEN) { | 76 | 76 | await sdk.client.pty.update({ | 77 | | - path: { id: local.pty.id }, | 78 | | - body: { | 79 | | - size: { | 80 | | - cols: size.cols, | 81 | | - rows: size.rows, | 82 | | - }, | | 77 | + ptyID: local.pty.id, | | 78 | + size: { | | 79 | + cols: size.cols, | | 80 | + rows: size.rows, | 83 | 81 | }, | 84 | 82 | }) | 85 | 83 | } | @@ -100,12 +98,10 @@ export const Terminal = (props: TerminalProps) => { | 100 | 98 | ws.addEventListener("open", () => { | 101 | 99 | console.log("WebSocket connected") | 102 | 100 | sdk.client.pty.update({ | 103 | | - path: { id: local.pty.id }, | 104 | | - body: { | 105 | | - size: { | 106 | | - cols: term.cols, | 107 | | - rows: term.rows, | 108 | | - }, | | 101 | + ptyID: local.pty.id, | | 102 | + size: { | | 103 | + cols: term.cols, | | 104 | + rows: term.rows, | 109 | 105 | }, | 110 | 106 | }) | 111 | 107 | }) | |
Collapse file Copy file name to clipboardExpand all lines: packages/desktop/src/context/global-sdk.tsx +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { createOpencodeClient, type Event } from "@opencode-ai/sdk/client" | | 1 | +import { createOpencodeClient, type Event } from "@opencode-ai/sdk/v2/client" | 2 | 2 | import { createSimpleContext } from "@opencode-ai/ui/context" | 3 | 3 | import { createGlobalEmitter } from "@solid-primitives/event-bus" | 4 | 4 | import { onCleanup } from "solid-js" | |
Collapse file Copy file name to clipboardExpand all lines: packages/desktop/src/context/global-sync.tsx +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -12,7 +12,7 @@ import type { | 12 | 12 | FileDiff, | 13 | 13 | Todo, | 14 | 14 | SessionStatus, | 15 | | -} from "@opencode-ai/sdk" | | 15 | +} from "@opencode-ai/sdk/v2" | 16 | 16 | import { createStore, produce, reconcile } from "solid-js/store" | 17 | 17 | import { Binary } from "@opencode-ai/util/binary" | 18 | 18 | import { createSimpleContext } from "@opencode-ai/ui/context" | |
Collapse file Copy file name to clipboardExpand all lines: packages/desktop/src/context/local.tsx +5-6Lines changed: 5 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { createStore, produce, reconcile } from "solid-js/store" | 2 | 2 | import { batch, createEffect, createMemo } from "solid-js" | 3 | 3 | import { uniqueBy } from "remeda" | 4 | | -import type { FileContent, FileNode, Model, Provider, File as FileStatus } from "@opencode-ai/sdk" | | 4 | +import type { FileContent, FileNode, Model, Provider, File as FileStatus } from "@opencode-ai/sdk/v2" | 5 | 5 | import { createSimpleContext } from "@opencode-ai/ui/context" | 6 | 6 | import { useSDK } from "./sdk" | 7 | 7 | import { useSync } from "./sync" | @@ -257,7 +257,7 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({ | 257 | 257 |
| 258 | 258 | const load = async (path: string) => { | 259 | 259 | const relativePath = relative(path) | 260 | | - sdk.client.file.read({ query: { path: relativePath } }).then((x) => { | | 260 | + sdk.client.file.read({ path: relativePath }).then((x) => { | 261 | 261 | setStore( | 262 | 262 | "node", | 263 | 263 | relativePath, | @@ -305,7 +305,7 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({ | 305 | 305 | } | 306 | 306 |
| 307 | 307 | const list = async (path: string) => { | 308 | | - return sdk.client.file.list({ query: { path: path + "/" } }).then((x) => { | | 308 | + return sdk.client.file.list({ path: path + "/" }).then((x) => { | 309 | 309 | setStore( | 310 | 310 | "node", | 311 | 311 | produce((draft) => { | @@ -318,10 +318,9 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({ | 318 | 318 | }) | 319 | 319 | } | 320 | 320 |
| 321 | | - const searchFiles = (query: string) => | 322 | | - sdk.client.find.files({ query: { query, dirs: "false" } }).then((x) => x.data!) | | 321 | + const searchFiles = (query: string) => sdk.client.find.files({ query, dirs: "false" }).then((x) => x.data!) | 323 | 322 | const searchFilesAndDirectories = (query: string) => | 324 | | - sdk.client.find.files({ query: { query, dirs: "true" } }).then((x) => x.data!) | | 323 | + sdk.client.find.files({ query, dirs: "true" }).then((x) => x.data!) | 325 | 324 |
| 326 | 325 | sdk.event.listen((e) => { | 327 | 326 | const event = e.details | |
Collapse file Copy file name to clipboardExpand all lines: packages/desktop/src/context/sdk.tsx +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { createOpencodeClient, type Event } from "@opencode-ai/sdk/client" | | 1 | +import { createOpencodeClient, type Event } from "@opencode-ai/sdk/v2/client" | 2 | 2 | import { createSimpleContext } from "@opencode-ai/ui/context" | 3 | 3 | import { createGlobalEmitter } from "@solid-primitives/event-bus" | 4 | 4 | import { onCleanup } from "solid-js" | |
Collapse file Copy file name to clipboardExpand all lines: packages/desktop/src/context/session.tsx +7-8Lines changed: 7 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,7 +5,7 @@ import { useSync } from "./sync" | 5 | 5 | import { makePersisted } from "@solid-primitives/storage" | 6 | 6 | import { TextSelection } from "./local" | 7 | 7 | import { pipe, sumBy } from "remeda" | 8 | | -import { AssistantMessage, UserMessage } from "@opencode-ai/sdk" | | 8 | +import { AssistantMessage, UserMessage } from "@opencode-ai/sdk/v2" | 9 | 9 | import { useParams } from "@solidjs/router" | 10 | 10 | import { base64Encode } from "@/utils" | 11 | 11 | import { useSDK } from "./sdk" | @@ -198,7 +198,7 @@ export const { use: useSession, provider: SessionProvider } = createSimpleContex | 198 | 198 | all: createMemo(() => Object.values(store.terminals.all)), | 199 | 199 | active: createMemo(() => store.terminals.active), | 200 | 200 | new() { | 201 | | - sdk.client.pty.create({ body: { title: `Terminal ${store.terminals.all.length + 1}` } }).then((pty) => { | | 201 | + sdk.client.pty.create({ title: `Terminal ${store.terminals.all.length + 1}` }).then((pty) => { | 202 | 202 | const id = pty.data?.id | 203 | 203 | if (!id) return | 204 | 204 | setStore("terminals", "all", [ | @@ -214,18 +214,17 @@ export const { use: useSession, provider: SessionProvider } = createSimpleContex | 214 | 214 | update(pty: Partial<LocalPTY> & { id: string }) { | 215 | 215 | setStore("terminals", "all", (x) => x.map((x) => (x.id === pty.id ? { ...x, ...pty } : x))) | 216 | 216 | sdk.client.pty.update({ | 217 | | - path: { id: pty.id }, | 218 | | - body: { title: pty.title, size: pty.cols && pty.rows ? { rows: pty.rows, cols: pty.cols } : undefined }, | | 217 | + ptyID: pty.id, | | 218 | + title: pty.title, | | 219 | + size: pty.cols && pty.rows ? { rows: pty.rows, cols: pty.cols } : undefined, | 219 | 220 | }) | 220 | 221 | }, | 221 | 222 | async clone(id: string) { | 222 | 223 | const index = store.terminals.all.findIndex((x) => x.id === id) | 223 | 224 | const pty = store.terminals.all[index] | 224 | 225 | if (!pty) return | 225 | 226 | const clone = await sdk.client.pty.create({ | 226 | | - body: { | 227 | | - title: pty.title, | 228 | | - }, | | 227 | + title: pty.title, | 229 | 228 | }) | 230 | 229 | if (!clone.data) return | 231 | 230 | setStore("terminals", "all", index, { | @@ -252,7 +251,7 @@ export const { use: useSession, provider: SessionProvider } = createSimpleContex | 252 | 251 | setStore("terminals", "active", previous) | 253 | 252 | } | 254 | 253 | }) | 255 | | - await sdk.client.pty.remove({ path: { id } }) | | 254 | + await sdk.client.pty.remove({ ptyID: id }) | 256 | 255 | }, | 257 | 256 | move(id: string, to: number) { | 258 | 257 | const index = store.terminals.all.findIndex((f) => f.id === id) | |
Collapse file Copy file name to clipboardExpand all lines: packages/desktop/src/context/sync.tsx +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -28,7 +28,7 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({ | 28 | 28 | status: () => sdk.client.session.status().then((x) => setStore("session_status", x.data!)), | 29 | 29 | config: () => sdk.client.config.get().then((x) => setStore("config", x.data!)), | 30 | 30 | changes: () => sdk.client.file.status().then((x) => setStore("changes", x.data!)), | 31 | | - node: () => sdk.client.file.list({ query: { path: "/" } }).then((x) => setStore("node", x.data!)), | | 31 | + node: () => sdk.client.file.list({ path: "/" }).then((x) => setStore("node", x.data!)), | 32 | 32 | } | 33 | 33 |
| 34 | 34 | Promise.all(Object.values(load).map((p) => p())).then(() => setStore("ready", true)) | @@ -49,10 +49,10 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({ | 49 | 49 | }, | 50 | 50 | async sync(sessionID: string, _isRetry = false) { | 51 | 51 | const [session, messages, todo, diff] = await Promise.all([ | 52 | | - sdk.client.session.get({ path: { id: sessionID }, throwOnError: true }), | 53 | | - sdk.client.session.messages({ path: { id: sessionID }, query: { limit: 100 } }), | 54 | | - sdk.client.session.todo({ path: { id: sessionID } }), | 55 | | - sdk.client.session.diff({ path: { id: sessionID } }), | | 52 | + sdk.client.session.get({ sessionID }, { throwOnError: true }), | | 53 | + sdk.client.session.messages({ sessionID, limit: 100 }), | | 54 | + sdk.client.session.todo({ sessionID }), | | 55 | + sdk.client.session.diff({ sessionID }), | 56 | 56 | ]) | 57 | 57 | setStore( | 58 | 58 | produce((draft) => { | |
|