summaryrefslogtreecommitdiffhomepage
path: root/packages/sdk/js
diff options
context:
space:
mode:
authorJames Long <[email protected]>2026-03-25 10:47:40 -0400
committerGitHub <[email protected]>2026-03-25 10:47:40 -0400
commitb0017bf1b96ef14fc1ecf91c0b9c4b18e2dfea71 (patch)
tree9995f618fae9c35c7308934fe8e5260c6c8fe2aa /packages/sdk/js
parent0c0c6f3bdb75663837555b07110d7a1b313daeac (diff)
downloadopencode-b0017bf1b96ef14fc1ecf91c0b9c4b18e2dfea71.tar.gz
opencode-b0017bf1b96ef14fc1ecf91c0b9c4b18e2dfea71.zip
feat(core): initial implementation of syncing (#17814)
Diffstat (limited to 'packages/sdk/js')
-rw-r--r--packages/sdk/js/src/v2/gen/sdk.gen.ts20
-rw-r--r--packages/sdk/js/src/v2/gen/types.gen.ts911
2 files changed, 537 insertions, 394 deletions
diff --git a/packages/sdk/js/src/v2/gen/sdk.gen.ts b/packages/sdk/js/src/v2/gen/sdk.gen.ts
index 7a4f4e40c..410906844 100644
--- a/packages/sdk/js/src/v2/gen/sdk.gen.ts
+++ b/packages/sdk/js/src/v2/gen/sdk.gen.ts
@@ -46,6 +46,7 @@ import type {
GlobalDisposeResponses,
GlobalEventResponses,
GlobalHealthResponses,
+ GlobalSyncEventSubscribeResponses,
GlobalUpgradeErrors,
GlobalUpgradeResponses,
InstanceDisposeResponses,
@@ -230,6 +231,20 @@ class HeyApiRegistry<T> {
}
}
+export class SyncEvent extends HeyApiClient {
+ /**
+ * Subscribe to global sync events
+ *
+ * Get global sync events
+ */
+ public subscribe<ThrowOnError extends boolean = false>(options?: Options<never, ThrowOnError>) {
+ return (options?.client ?? this.client).sse.get<GlobalSyncEventSubscribeResponses, unknown, ThrowOnError>({
+ url: "/global/sync-event",
+ ...options,
+ })
+ }
+}
+
export class Config extends HeyApiClient {
/**
* Get global configuration
@@ -329,6 +344,11 @@ export class Global extends HeyApiClient {
})
}
+ private _syncEvent?: SyncEvent
+ get syncEvent(): SyncEvent {
+ return (this._syncEvent ??= new SyncEvent({ client: this.client }))
+ }
+
private _config?: Config
get config(): Config {
return (this._config ??= new Config({ client: this.client }))
diff --git a/packages/sdk/js/src/v2/gen/types.gen.ts b/packages/sdk/js/src/v2/gen/types.gen.ts
index 86a0c7e42..43ce02921 100644
--- a/packages/sdk/js/src/v2/gen/types.gen.ts
+++ b/packages/sdk/js/src/v2/gen/types.gen.ts
@@ -83,6 +83,153 @@ export type EventLspUpdated = {
}
}
+export type EventMessagePartDelta = {
+ type: "message.part.delta"
+ properties: {
+ sessionID: string
+ messageID: string
+ partID: string
+ field: string
+ delta: string
+ }
+}
+
+export type PermissionRequest = {
+ id: string
+ sessionID: string
+ permission: string
+ patterns: Array<string>
+ metadata: {
+ [key: string]: unknown
+ }
+ always: Array<string>
+ tool?: {
+ messageID: string
+ callID: string
+ }
+}
+
+export type EventPermissionAsked = {
+ type: "permission.asked"
+ properties: PermissionRequest
+}
+
+export type EventPermissionReplied = {
+ type: "permission.replied"
+ properties: {
+ sessionID: string
+ requestID: string
+ reply: "once" | "always" | "reject"
+ }
+}
+
+export type SessionStatus =
+ | {
+ type: "idle"
+ }
+ | {
+ type: "retry"
+ attempt: number
+ message: string
+ next: number
+ }
+ | {
+ type: "busy"
+ }
+
+export type EventSessionStatus = {
+ type: "session.status"
+ properties: {
+ sessionID: string
+ status: SessionStatus
+ }
+}
+
+export type EventSessionIdle = {
+ type: "session.idle"
+ properties: {
+ sessionID: string
+ }
+}
+
+export type QuestionOption = {
+ /**
+ * Display text (1-5 words, concise)
+ */
+ label: string
+ /**
+ * Explanation of choice
+ */
+ description: string
+}
+
+export type QuestionInfo = {
+ /**
+ * Complete question
+ */
+ question: string
+ /**
+ * Very short label (max 30 chars)
+ */
+ header: string
+ /**
+ * Available choices
+ */
+ options: Array<QuestionOption>
+ /**
+ * Allow selecting multiple choices
+ */
+ multiple?: boolean
+ /**
+ * Allow typing a custom answer (default: true)
+ */
+ custom?: boolean
+}
+
+export type QuestionRequest = {
+ id: string
+ sessionID: string
+ /**
+ * Questions to ask
+ */
+ questions: Array<QuestionInfo>
+ tool?: {
+ messageID: string
+ callID: string
+ }
+}
+
+export type EventQuestionAsked = {
+ type: "question.asked"
+ properties: QuestionRequest
+}
+
+export type QuestionAnswer = Array<string>
+
+export type EventQuestionReplied = {
+ type: "question.replied"
+ properties: {
+ sessionID: string
+ requestID: string
+ answers: Array<QuestionAnswer>
+ }
+}
+
+export type EventQuestionRejected = {
+ type: "question.rejected"
+ properties: {
+ sessionID: string
+ requestID: string
+ }
+}
+
+export type EventSessionCompacted = {
+ type: "session.compacted"
+ properties: {
+ sessionID: string
+ }
+}
+
export type EventFileEdited = {
type: "file.edited"
properties: {
@@ -90,21 +237,115 @@ export type EventFileEdited = {
}
}
-export type OutputFormatText = {
- type: "text"
+export type EventFileWatcherUpdated = {
+ type: "file.watcher.updated"
+ properties: {
+ file: string
+ event: "add" | "change" | "unlink"
+ }
}
-export type JsonSchema = {
- [key: string]: unknown
+export type Todo = {
+ /**
+ * Brief description of the task
+ */
+ content: string
+ /**
+ * Current status of the task: pending, in_progress, completed, cancelled
+ */
+ status: string
+ /**
+ * Priority level of the task: high, medium, low
+ */
+ priority: string
}
-export type OutputFormatJsonSchema = {
- type: "json_schema"
- schema: JsonSchema
- retryCount?: number
+export type EventTodoUpdated = {
+ type: "todo.updated"
+ properties: {
+ sessionID: string
+ todos: Array<Todo>
+ }
}
-export type OutputFormat = OutputFormatText | OutputFormatJsonSchema
+export type EventTuiPromptAppend = {
+ type: "tui.prompt.append"
+ properties: {
+ text: string
+ }
+}
+
+export type EventTuiCommandExecute = {
+ type: "tui.command.execute"
+ properties: {
+ command:
+ | "session.list"
+ | "session.new"
+ | "session.share"
+ | "session.interrupt"
+ | "session.compact"
+ | "session.page.up"
+ | "session.page.down"
+ | "session.line.up"
+ | "session.line.down"
+ | "session.half.page.up"
+ | "session.half.page.down"
+ | "session.first"
+ | "session.last"
+ | "prompt.clear"
+ | "prompt.submit"
+ | "agent.cycle"
+ | string
+ }
+}
+
+export type EventTuiToastShow = {
+ type: "tui.toast.show"
+ properties: {
+ title?: string
+ message: string
+ variant: "info" | "success" | "warning" | "error"
+ /**
+ * Duration in milliseconds
+ */
+ duration?: number
+ }
+}
+
+export type EventTuiSessionSelect = {
+ type: "tui.session.select"
+ properties: {
+ /**
+ * Session ID to navigate to
+ */
+ sessionID: string
+ }
+}
+
+export type EventMcpToolsChanged = {
+ type: "mcp.tools.changed"
+ properties: {
+ server: string
+ }
+}
+
+export type EventMcpBrowserOpenFailed = {
+ type: "mcp.browser.open.failed"
+ properties: {
+ mcpName: string
+ url: string
+ }
+}
+
+export type EventCommandExecuted = {
+ type: "command.executed"
+ properties: {
+ name: string
+ sessionID: string
+ arguments: string
+ messageID: string
+ }
+}
export type FileDiff = {
file: string
@@ -115,29 +356,12 @@ export type FileDiff = {
status?: "added" | "deleted" | "modified"
}
-export type UserMessage = {
- id: string
- sessionID: string
- role: "user"
- time: {
- created: number
- }
- format?: OutputFormat
- summary?: {
- title?: string
- body?: string
- diffs: Array<FileDiff>
- }
- agent: string
- model: {
- providerID: string
- modelID: string
- }
- system?: string
- tools?: {
- [key: string]: boolean
+export type EventSessionDiff = {
+ type: "session.diff"
+ properties: {
+ sessionID: string
+ diff: Array<FileDiff>
}
- variant?: string
}
export type ProviderAuthError = {
@@ -201,6 +425,137 @@ export type ApiError = {
}
}
+export type EventSessionError = {
+ type: "session.error"
+ properties: {
+ sessionID?: string
+ error?:
+ | ProviderAuthError
+ | UnknownError
+ | MessageOutputLengthError
+ | MessageAbortedError
+ | StructuredOutputError
+ | ContextOverflowError
+ | ApiError
+ }
+}
+
+export type EventVcsBranchUpdated = {
+ type: "vcs.branch.updated"
+ properties: {
+ branch?: string
+ }
+}
+
+export type EventWorkspaceReady = {
+ type: "workspace.ready"
+ properties: {
+ name: string
+ }
+}
+
+export type EventWorkspaceFailed = {
+ type: "workspace.failed"
+ properties: {
+ message: string
+ }
+}
+
+export type Pty = {
+ id: string
+ title: string
+ command: string
+ args: Array<string>
+ cwd: string
+ status: "running" | "exited"
+ pid: number
+}
+
+export type EventPtyCreated = {
+ type: "pty.created"
+ properties: {
+ info: Pty
+ }
+}
+
+export type EventPtyUpdated = {
+ type: "pty.updated"
+ properties: {
+ info: Pty
+ }
+}
+
+export type EventPtyExited = {
+ type: "pty.exited"
+ properties: {
+ id: string
+ exitCode: number
+ }
+}
+
+export type EventPtyDeleted = {
+ type: "pty.deleted"
+ properties: {
+ id: string
+ }
+}
+
+export type EventWorktreeReady = {
+ type: "worktree.ready"
+ properties: {
+ name: string
+ branch: string
+ }
+}
+
+export type EventWorktreeFailed = {
+ type: "worktree.failed"
+ properties: {
+ message: string
+ }
+}
+
+export type OutputFormatText = {
+ type: "text"
+}
+
+export type JsonSchema = {
+ [key: string]: unknown
+}
+
+export type OutputFormatJsonSchema = {
+ type: "json_schema"
+ schema: JsonSchema
+ retryCount?: number
+}
+
+export type OutputFormat = OutputFormatText | OutputFormatJsonSchema
+
+export type UserMessage = {
+ id: string
+ sessionID: string
+ role: "user"
+ time: {
+ created: number
+ }
+ format?: OutputFormat
+ summary?: {
+ title?: string
+ body?: string
+ diffs: Array<FileDiff>
+ }
+ agent: string
+ model: {
+ providerID: string
+ modelID: string
+ }
+ system?: string
+ tools?: {
+ [key: string]: boolean
+ }
+ variant?: string
+}
+
export type AssistantMessage = {
id: string
sessionID: string
@@ -248,6 +603,7 @@ export type Message = UserMessage | AssistantMessage
export type EventMessageUpdated = {
type: "message.updated"
properties: {
+ sessionID: string
info: Message
}
}
@@ -525,18 +881,9 @@ export type Part =
export type EventMessagePartUpdated = {
type: "message.part.updated"
properties: {
- part: Part
- }
-}
-
-export type EventMessagePartDelta = {
- type: "message.part.delta"
- properties: {
sessionID: string
- messageID: string
- partID: string
- field: string
- delta: string
+ part: Part
+ time: number
}
}
@@ -549,252 +896,6 @@ export type EventMessagePartRemoved = {
}
}
-export type PermissionRequest = {
- id: string
- sessionID: string
- permission: string
- patterns: Array<string>
- metadata: {
- [key: string]: unknown
- }
- always: Array<string>
- tool?: {
- messageID: string
- callID: string
- }
-}
-
-export type EventPermissionAsked = {
- type: "permission.asked"
- properties: PermissionRequest
-}
-
-export type EventPermissionReplied = {
- type: "permission.replied"
- properties: {
- sessionID: string
- requestID: string
- reply: "once" | "always" | "reject"
- }
-}
-
-export type SessionStatus =
- | {
- type: "idle"
- }
- | {
- type: "retry"
- attempt: number
- message: string
- next: number
- }
- | {
- type: "busy"
- }
-
-export type EventSessionStatus = {
- type: "session.status"
- properties: {
- sessionID: string
- status: SessionStatus
- }
-}
-
-export type EventSessionIdle = {
- type: "session.idle"
- properties: {
- sessionID: string
- }
-}
-
-export type QuestionOption = {
- /**
- * Display text (1-5 words, concise)
- */
- label: string
- /**
- * Explanation of choice
- */
- description: string
-}
-
-export type QuestionInfo = {
- /**
- * Complete question
- */
- question: string
- /**
- * Very short label (max 30 chars)
- */
- header: string
- /**
- * Available choices
- */
- options: Array<QuestionOption>
- /**
- * Allow selecting multiple choices
- */
- multiple?: boolean
- /**
- * Allow typing a custom answer (default: true)
- */
- custom?: boolean
-}
-
-export type QuestionRequest = {
- id: string
- sessionID: string
- /**
- * Questions to ask
- */
- questions: Array<QuestionInfo>
- tool?: {
- messageID: string
- callID: string
- }
-}
-
-export type EventQuestionAsked = {
- type: "question.asked"
- properties: QuestionRequest
-}
-
-export type QuestionAnswer = Array<string>
-
-export type EventQuestionReplied = {
- type: "question.replied"
- properties: {
- sessionID: string
- requestID: string
- answers: Array<QuestionAnswer>
- }
-}
-
-export type EventQuestionRejected = {
- type: "question.rejected"
- properties: {
- sessionID: string
- requestID: string
- }
-}
-
-export type EventSessionCompacted = {
- type: "session.compacted"
- properties: {
- sessionID: string
- }
-}
-
-export type EventFileWatcherUpdated = {
- type: "file.watcher.updated"
- properties: {
- file: string
- event: "add" | "change" | "unlink"
- }
-}
-
-export type Todo = {
- /**
- * Brief description of the task
- */
- content: string
- /**
- * Current status of the task: pending, in_progress, completed, cancelled
- */
- status: string
- /**
- * Priority level of the task: high, medium, low
- */
- priority: string
-}
-
-export type EventTodoUpdated = {
- type: "todo.updated"
- properties: {
- sessionID: string
- todos: Array<Todo>
- }
-}
-
-export type EventTuiPromptAppend = {
- type: "tui.prompt.append"
- properties: {
- text: string
- }
-}
-
-export type EventTuiCommandExecute = {
- type: "tui.command.execute"
- properties: {
- command:
- | "session.list"
- | "session.new"
- | "session.share"
- | "session.interrupt"
- | "session.compact"
- | "session.page.up"
- | "session.page.down"
- | "session.line.up"
- | "session.line.down"
- | "session.half.page.up"
- | "session.half.page.down"
- | "session.first"
- | "session.last"
- | "prompt.clear"
- | "prompt.submit"
- | "agent.cycle"
- | string
- }
-}
-
-export type EventTuiToastShow = {
- type: "tui.toast.show"
- properties: {
- title?: string
- message: string
- variant: "info" | "success" | "warning" | "error"
- /**
- * Duration in milliseconds
- */
- duration?: number
- }
-}
-
-export type EventTuiSessionSelect = {
- type: "tui.session.select"
- properties: {
- /**
- * Session ID to navigate to
- */
- sessionID: string
- }
-}
-
-export type EventMcpToolsChanged = {
- type: "mcp.tools.changed"
- properties: {
- server: string
- }
-}
-
-export type EventMcpBrowserOpenFailed = {
- type: "mcp.browser.open.failed"
- properties: {
- mcpName: string
- url: string
- }
-}
-
-export type EventCommandExecuted = {
- type: "command.executed"
- properties: {
- name: string
- sessionID: string
- arguments: string
- messageID: string
- }
-}
-
export type PermissionAction = "allow" | "deny" | "ask"
export type PermissionRule = {
@@ -841,6 +942,7 @@ export type Session = {
export type EventSessionCreated = {
type: "session.created"
properties: {
+ sessionID: string
info: Session
}
}
@@ -848,6 +950,7 @@ export type EventSessionCreated = {
export type EventSessionUpdated = {
type: "session.updated"
properties: {
+ sessionID: string
info: Session
}
}
@@ -855,105 +958,8 @@ export type EventSessionUpdated = {
export type EventSessionDeleted = {
type: "session.deleted"
properties: {
- info: Session
- }
-}
-
-export type EventSessionDiff = {
- type: "session.diff"
- properties: {
sessionID: string
- diff: Array<FileDiff>
- }
-}
-
-export type EventSessionError = {
- type: "session.error"
- properties: {
- sessionID?: string
- error?:
- | ProviderAuthError
- | UnknownError
- | MessageOutputLengthError
- | MessageAbortedError
- | StructuredOutputError
- | ContextOverflowError
- | ApiError
- }
-}
-
-export type EventVcsBranchUpdated = {
- type: "vcs.branch.updated"
- properties: {
- branch?: string
- }
-}
-
-export type EventWorkspaceReady = {
- type: "workspace.ready"
- properties: {
- name: string
- }
-}
-
-export type EventWorkspaceFailed = {
- type: "workspace.failed"
- properties: {
- message: string
- }
-}
-
-export type Pty = {
- id: string
- title: string
- command: string
- args: Array<string>
- cwd: string
- status: "running" | "exited"
- pid: number
-}
-
-export type EventPtyCreated = {
- type: "pty.created"
- properties: {
- info: Pty
- }
-}
-
-export type EventPtyUpdated = {
- type: "pty.updated"
- properties: {
- info: Pty
- }
-}
-
-export type EventPtyExited = {
- type: "pty.exited"
- properties: {
- id: string
- exitCode: number
- }
-}
-
-export type EventPtyDeleted = {
- type: "pty.deleted"
- properties: {
- id: string
- }
-}
-
-export type EventWorktreeReady = {
- type: "worktree.ready"
- properties: {
- name: string
- branch: string
- }
-}
-
-export type EventWorktreeFailed = {
- type: "worktree.failed"
- properties: {
- message: string
+ info: Session
}
}
@@ -966,12 +972,7 @@ export type Event =
| EventGlobalDisposed
| EventLspClientDiagnostics
| EventLspUpdated
- | EventFileEdited
- | EventMessageUpdated
- | EventMessageRemoved
- | EventMessagePartUpdated
| EventMessagePartDelta
- | EventMessagePartRemoved
| EventPermissionAsked
| EventPermissionReplied
| EventSessionStatus
@@ -980,6 +981,7 @@ export type Event =
| EventQuestionReplied
| EventQuestionRejected
| EventSessionCompacted
+ | EventFileEdited
| EventFileWatcherUpdated
| EventTodoUpdated
| EventTuiPromptAppend
@@ -989,9 +991,6 @@ export type Event =
| EventMcpToolsChanged
| EventMcpBrowserOpenFailed
| EventCommandExecuted
- | EventSessionCreated
- | EventSessionUpdated
- | EventSessionDeleted
| EventSessionDiff
| EventSessionError
| EventVcsBranchUpdated
@@ -1003,12 +1002,119 @@ export type Event =
| EventPtyDeleted
| EventWorktreeReady
| EventWorktreeFailed
+ | EventMessageUpdated
+ | EventMessageRemoved
+ | EventMessagePartUpdated
+ | EventMessagePartRemoved
+ | EventSessionCreated
+ | EventSessionUpdated
+ | EventSessionDeleted
export type GlobalEvent = {
directory: string
payload: Event
}
+export type SyncEventMessageUpdated = {
+ type: "message.updated.1"
+ aggregate: "sessionID"
+ data: {
+ sessionID: string
+ info: Message
+ }
+}
+
+export type SyncEventMessageRemoved = {
+ type: "message.removed.1"
+ aggregate: "sessionID"
+ data: {
+ sessionID: string
+ messageID: string
+ }
+}
+
+export type SyncEventMessagePartUpdated = {
+ type: "message.part.updated.1"
+ aggregate: "sessionID"
+ data: {
+ sessionID: string
+ part: Part
+ time: number
+ }
+}
+
+export type SyncEventMessagePartRemoved = {
+ type: "message.part.removed.1"
+ aggregate: "sessionID"
+ data: {
+ sessionID: string
+ messageID: string
+ partID: string
+ }
+}
+
+export type SyncEventSessionCreated = {
+ type: "session.created.1"
+ aggregate: "sessionID"
+ data: {
+ sessionID: string
+ info: Session
+ }
+}
+
+export type SyncEventSessionUpdated = {
+ type: "session.updated.1"
+ aggregate: "sessionID"
+ data: {
+ sessionID: string
+ info: {
+ id?: string
+ slug?: string
+ projectID?: string
+ workspaceID?: string
+ directory?: string
+ parentID?: string
+ summary?: {
+ additions: number
+ deletions: number
+ files: number
+ diffs?: Array<FileDiff>
+ }
+ share?: {
+ url?: string
+ }
+ title?: string
+ version?: string
+ time?: {
+ created?: number
+ updated?: number
+ compacting?: number
+ archived?: number
+ }
+ permission?: PermissionRuleset
+ revert?: {
+ messageID: string
+ partID?: string
+ snapshot?: string
+ diff?: string
+ }
+ }
+ }
+}
+
+export type SyncEventSessionDeleted = {
+ type: "session.deleted.1"
+ aggregate: "sessionID"
+ data: {
+ sessionID: string
+ info: Session
+ }
+}
+
+export type SyncEvent = {
+ payload: SyncEvent
+}
+
/**
* Log level
*/
@@ -1973,6 +2079,23 @@ export type GlobalEventResponses = {
export type GlobalEventResponse = GlobalEventResponses[keyof GlobalEventResponses]
+export type GlobalSyncEventSubscribeData = {
+ body?: never
+ path?: never
+ query?: never
+ url: "/global/sync-event"
+}
+
+export type GlobalSyncEventSubscribeResponses = {
+ /**
+ * Event stream
+ */
+ 200: SyncEvent
+}
+
+export type GlobalSyncEventSubscribeResponse =
+ GlobalSyncEventSubscribeResponses[keyof GlobalSyncEventSubscribeResponses]
+
export type GlobalConfigGetData = {
body?: never
path?: never