mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-20 01:04:22 +01:00
wip: sdk
This commit is contained in:
@@ -54,14 +54,14 @@ export type Event =
|
|||||||
} & EventIdeInstalled)
|
} & EventIdeInstalled)
|
||||||
|
|
||||||
export type EventInstallationUpdated = {
|
export type EventInstallationUpdated = {
|
||||||
type: string
|
type: "installation.updated"
|
||||||
properties: {
|
properties: {
|
||||||
version: string
|
version: string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type EventLspClientDiagnostics = {
|
export type EventLspClientDiagnostics = {
|
||||||
type: string
|
type: "lsp.client.diagnostics"
|
||||||
properties: {
|
properties: {
|
||||||
serverID: string
|
serverID: string
|
||||||
path: string
|
path: string
|
||||||
@@ -69,7 +69,7 @@ export type EventLspClientDiagnostics = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type EventMessageUpdated = {
|
export type EventMessageUpdated = {
|
||||||
type: string
|
type: "message.updated"
|
||||||
properties: {
|
properties: {
|
||||||
info: Message
|
info: Message
|
||||||
}
|
}
|
||||||
@@ -86,7 +86,7 @@ export type Message =
|
|||||||
export type UserMessage = {
|
export type UserMessage = {
|
||||||
id: string
|
id: string
|
||||||
sessionID: string
|
sessionID: string
|
||||||
role: string
|
role: "user"
|
||||||
time: {
|
time: {
|
||||||
created: number
|
created: number
|
||||||
}
|
}
|
||||||
@@ -95,7 +95,7 @@ export type UserMessage = {
|
|||||||
export type AssistantMessage = {
|
export type AssistantMessage = {
|
||||||
id: string
|
id: string
|
||||||
sessionID: string
|
sessionID: string
|
||||||
role: string
|
role: "assistant"
|
||||||
time: {
|
time: {
|
||||||
created: number
|
created: number
|
||||||
completed?: number
|
completed?: number
|
||||||
@@ -135,7 +135,7 @@ export type AssistantMessage = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type ProviderAuthError = {
|
export type ProviderAuthError = {
|
||||||
name: string
|
name: "ProviderAuthError"
|
||||||
data: {
|
data: {
|
||||||
providerID: string
|
providerID: string
|
||||||
message: string
|
message: string
|
||||||
@@ -143,28 +143,28 @@ export type ProviderAuthError = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type UnknownError = {
|
export type UnknownError = {
|
||||||
name: string
|
name: "UnknownError"
|
||||||
data: {
|
data: {
|
||||||
message: string
|
message: string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type MessageOutputLengthError = {
|
export type MessageOutputLengthError = {
|
||||||
name: string
|
name: "MessageOutputLengthError"
|
||||||
data: {
|
data: {
|
||||||
[key: string]: unknown
|
[key: string]: unknown
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type MessageAbortedError = {
|
export type MessageAbortedError = {
|
||||||
name: string
|
name: "MessageAbortedError"
|
||||||
data: {
|
data: {
|
||||||
[key: string]: unknown
|
[key: string]: unknown
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type EventMessageRemoved = {
|
export type EventMessageRemoved = {
|
||||||
type: string
|
type: "message.removed"
|
||||||
properties: {
|
properties: {
|
||||||
sessionID: string
|
sessionID: string
|
||||||
messageID: string
|
messageID: string
|
||||||
@@ -172,7 +172,7 @@ export type EventMessageRemoved = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type EventMessagePartUpdated = {
|
export type EventMessagePartUpdated = {
|
||||||
type: string
|
type: "message.part.updated"
|
||||||
properties: {
|
properties: {
|
||||||
part: Part
|
part: Part
|
||||||
}
|
}
|
||||||
@@ -211,7 +211,7 @@ export type TextPart = {
|
|||||||
id: string
|
id: string
|
||||||
sessionID: string
|
sessionID: string
|
||||||
messageID: string
|
messageID: string
|
||||||
type: string
|
type: "text"
|
||||||
text: string
|
text: string
|
||||||
synthetic?: boolean
|
synthetic?: boolean
|
||||||
time?: {
|
time?: {
|
||||||
@@ -224,7 +224,7 @@ export type ReasoningPart = {
|
|||||||
id: string
|
id: string
|
||||||
sessionID: string
|
sessionID: string
|
||||||
messageID: string
|
messageID: string
|
||||||
type: string
|
type: "reasoning"
|
||||||
text: string
|
text: string
|
||||||
metadata?: {
|
metadata?: {
|
||||||
[key: string]: unknown
|
[key: string]: unknown
|
||||||
@@ -239,7 +239,7 @@ export type FilePart = {
|
|||||||
id: string
|
id: string
|
||||||
sessionID: string
|
sessionID: string
|
||||||
messageID: string
|
messageID: string
|
||||||
type: string
|
type: "file"
|
||||||
mime: string
|
mime: string
|
||||||
filename?: string
|
filename?: string
|
||||||
url: string
|
url: string
|
||||||
@@ -256,7 +256,7 @@ export type FilePartSource =
|
|||||||
|
|
||||||
export type FileSource = {
|
export type FileSource = {
|
||||||
text: FilePartSourceText
|
text: FilePartSourceText
|
||||||
type: string
|
type: "file"
|
||||||
path: string
|
path: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,7 +268,7 @@ export type FilePartSourceText = {
|
|||||||
|
|
||||||
export type SymbolSource = {
|
export type SymbolSource = {
|
||||||
text: FilePartSourceText
|
text: FilePartSourceText
|
||||||
type: string
|
type: "symbol"
|
||||||
path: string
|
path: string
|
||||||
range: Range
|
range: Range
|
||||||
name: string
|
name: string
|
||||||
@@ -290,7 +290,7 @@ export type ToolPart = {
|
|||||||
id: string
|
id: string
|
||||||
sessionID: string
|
sessionID: string
|
||||||
messageID: string
|
messageID: string
|
||||||
type: string
|
type: "tool"
|
||||||
callID: string
|
callID: string
|
||||||
tool: string
|
tool: string
|
||||||
state: ToolState
|
state: ToolState
|
||||||
@@ -311,11 +311,11 @@ export type ToolState =
|
|||||||
} & ToolStateError)
|
} & ToolStateError)
|
||||||
|
|
||||||
export type ToolStatePending = {
|
export type ToolStatePending = {
|
||||||
status: string
|
status: "pending"
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ToolStateRunning = {
|
export type ToolStateRunning = {
|
||||||
status: string
|
status: "running"
|
||||||
input?: unknown
|
input?: unknown
|
||||||
title?: string
|
title?: string
|
||||||
metadata?: {
|
metadata?: {
|
||||||
@@ -327,7 +327,7 @@ export type ToolStateRunning = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type ToolStateCompleted = {
|
export type ToolStateCompleted = {
|
||||||
status: string
|
status: "completed"
|
||||||
input: {
|
input: {
|
||||||
[key: string]: unknown
|
[key: string]: unknown
|
||||||
}
|
}
|
||||||
@@ -343,7 +343,7 @@ export type ToolStateCompleted = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type ToolStateError = {
|
export type ToolStateError = {
|
||||||
status: string
|
status: "error"
|
||||||
input: {
|
input: {
|
||||||
[key: string]: unknown
|
[key: string]: unknown
|
||||||
}
|
}
|
||||||
@@ -358,14 +358,14 @@ export type StepStartPart = {
|
|||||||
id: string
|
id: string
|
||||||
sessionID: string
|
sessionID: string
|
||||||
messageID: string
|
messageID: string
|
||||||
type: string
|
type: "step-start"
|
||||||
}
|
}
|
||||||
|
|
||||||
export type StepFinishPart = {
|
export type StepFinishPart = {
|
||||||
id: string
|
id: string
|
||||||
sessionID: string
|
sessionID: string
|
||||||
messageID: string
|
messageID: string
|
||||||
type: string
|
type: "step-finish"
|
||||||
cost: number
|
cost: number
|
||||||
tokens: {
|
tokens: {
|
||||||
input: number
|
input: number
|
||||||
@@ -382,7 +382,7 @@ export type SnapshotPart = {
|
|||||||
id: string
|
id: string
|
||||||
sessionID: string
|
sessionID: string
|
||||||
messageID: string
|
messageID: string
|
||||||
type: string
|
type: "snapshot"
|
||||||
snapshot: string
|
snapshot: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -390,7 +390,7 @@ export type PatchPart = {
|
|||||||
id: string
|
id: string
|
||||||
sessionID: string
|
sessionID: string
|
||||||
messageID: string
|
messageID: string
|
||||||
type: string
|
type: "patch"
|
||||||
hash: string
|
hash: string
|
||||||
files: Array<string>
|
files: Array<string>
|
||||||
}
|
}
|
||||||
@@ -399,7 +399,7 @@ export type AgentPart = {
|
|||||||
id: string
|
id: string
|
||||||
sessionID: string
|
sessionID: string
|
||||||
messageID: string
|
messageID: string
|
||||||
type: string
|
type: "agent"
|
||||||
name: string
|
name: string
|
||||||
source?: {
|
source?: {
|
||||||
value: string
|
value: string
|
||||||
@@ -409,7 +409,7 @@ export type AgentPart = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type EventMessagePartRemoved = {
|
export type EventMessagePartRemoved = {
|
||||||
type: string
|
type: "message.part.removed"
|
||||||
properties: {
|
properties: {
|
||||||
sessionID: string
|
sessionID: string
|
||||||
messageID: string
|
messageID: string
|
||||||
@@ -418,7 +418,7 @@ export type EventMessagePartRemoved = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type EventStorageWrite = {
|
export type EventStorageWrite = {
|
||||||
type: string
|
type: "storage.write"
|
||||||
properties: {
|
properties: {
|
||||||
key: string
|
key: string
|
||||||
content?: unknown
|
content?: unknown
|
||||||
@@ -426,21 +426,21 @@ export type EventStorageWrite = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type EventFileEdited = {
|
export type EventFileEdited = {
|
||||||
type: string
|
type: "file.edited"
|
||||||
properties: {
|
properties: {
|
||||||
file: string
|
file: string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type EventServerConnected = {
|
export type EventServerConnected = {
|
||||||
type: string
|
type: "server.connected"
|
||||||
properties: {
|
properties: {
|
||||||
[key: string]: unknown
|
[key: string]: unknown
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type EventPermissionUpdated = {
|
export type EventPermissionUpdated = {
|
||||||
type: string
|
type: "permission.updated"
|
||||||
properties: Permission
|
properties: Permission
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -461,7 +461,7 @@ export type Permission = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type EventPermissionReplied = {
|
export type EventPermissionReplied = {
|
||||||
type: string
|
type: "permission.replied"
|
||||||
properties: {
|
properties: {
|
||||||
sessionID: string
|
sessionID: string
|
||||||
permissionID: string
|
permissionID: string
|
||||||
@@ -470,7 +470,7 @@ export type EventPermissionReplied = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type EventSessionUpdated = {
|
export type EventSessionUpdated = {
|
||||||
type: string
|
type: "session.updated"
|
||||||
properties: {
|
properties: {
|
||||||
info: Session
|
info: Session
|
||||||
}
|
}
|
||||||
@@ -497,21 +497,21 @@ export type Session = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type EventSessionDeleted = {
|
export type EventSessionDeleted = {
|
||||||
type: string
|
type: "session.deleted"
|
||||||
properties: {
|
properties: {
|
||||||
info: Session
|
info: Session
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type EventSessionIdle = {
|
export type EventSessionIdle = {
|
||||||
type: string
|
type: "session.idle"
|
||||||
properties: {
|
properties: {
|
||||||
sessionID: string
|
sessionID: string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type EventSessionError = {
|
export type EventSessionError = {
|
||||||
type: string
|
type: "session.error"
|
||||||
properties: {
|
properties: {
|
||||||
sessionID?: string
|
sessionID?: string
|
||||||
error?:
|
error?:
|
||||||
@@ -531,15 +531,15 @@ export type EventSessionError = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type EventFileWatcherUpdated = {
|
export type EventFileWatcherUpdated = {
|
||||||
type: string
|
type: "file.watcher.updated"
|
||||||
properties: {
|
properties: {
|
||||||
file: string
|
file: string
|
||||||
event: string
|
event: "rename" | "change"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type EventIdeInstalled = {
|
export type EventIdeInstalled = {
|
||||||
type: string
|
type: "ide.installed"
|
||||||
properties: {
|
properties: {
|
||||||
ide: string
|
ide: string
|
||||||
}
|
}
|
||||||
@@ -569,6 +569,9 @@ export type Config = {
|
|||||||
* Theme name to use for the interface
|
* Theme name to use for the interface
|
||||||
*/
|
*/
|
||||||
theme?: string
|
theme?: string
|
||||||
|
/**
|
||||||
|
* Custom keybind configurations
|
||||||
|
*/
|
||||||
keybinds?: KeybindsConfig
|
keybinds?: KeybindsConfig
|
||||||
plugin?: Array<string>
|
plugin?: Array<string>
|
||||||
snapshot?: boolean
|
snapshot?: boolean
|
||||||
@@ -683,7 +686,7 @@ export type Config = {
|
|||||||
lsp?: {
|
lsp?: {
|
||||||
[key: string]:
|
[key: string]:
|
||||||
| {
|
| {
|
||||||
disabled: boolean
|
disabled: true
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
command: Array<string>
|
command: Array<string>
|
||||||
@@ -701,15 +704,18 @@ export type Config = {
|
|||||||
* Additional instruction files or patterns to include
|
* Additional instruction files or patterns to include
|
||||||
*/
|
*/
|
||||||
instructions?: Array<string>
|
instructions?: Array<string>
|
||||||
|
/**
|
||||||
|
* @deprecated Always uses stretch layout.
|
||||||
|
*/
|
||||||
layout?: LayoutConfig
|
layout?: LayoutConfig
|
||||||
permission?: {
|
permission?: {
|
||||||
edit?: string
|
edit?: "ask" | "allow" | "deny"
|
||||||
bash?:
|
bash?:
|
||||||
| string
|
| ("ask" | "allow" | "deny")
|
||||||
| {
|
| {
|
||||||
[key: string]: string
|
[key: string]: "ask" | "allow" | "deny"
|
||||||
}
|
}
|
||||||
webfetch?: string
|
webfetch?: "ask" | "allow" | "deny"
|
||||||
}
|
}
|
||||||
experimental?: {
|
experimental?: {
|
||||||
hook?: {
|
hook?: {
|
||||||
@@ -911,15 +917,15 @@ export type AgentConfig = {
|
|||||||
* Description of when to use the agent
|
* Description of when to use the agent
|
||||||
*/
|
*/
|
||||||
description?: string
|
description?: string
|
||||||
mode?: string
|
mode?: "subagent" | "primary" | "all"
|
||||||
permission?: {
|
permission?: {
|
||||||
edit?: string
|
edit?: "ask" | "allow" | "deny"
|
||||||
bash?:
|
bash?:
|
||||||
| string
|
| ("ask" | "allow" | "deny")
|
||||||
| {
|
| {
|
||||||
[key: string]: string
|
[key: string]: "ask" | "allow" | "deny"
|
||||||
}
|
}
|
||||||
webfetch?: string
|
webfetch?: "ask" | "allow" | "deny"
|
||||||
}
|
}
|
||||||
[key: string]:
|
[key: string]:
|
||||||
| unknown
|
| unknown
|
||||||
@@ -929,15 +935,15 @@ export type AgentConfig = {
|
|||||||
[key: string]: boolean
|
[key: string]: boolean
|
||||||
}
|
}
|
||||||
| boolean
|
| boolean
|
||||||
| string
|
| ("subagent" | "primary" | "all")
|
||||||
| {
|
| {
|
||||||
edit?: string
|
edit?: "ask" | "allow" | "deny"
|
||||||
bash?:
|
bash?:
|
||||||
| string
|
| ("ask" | "allow" | "deny")
|
||||||
| {
|
| {
|
||||||
[key: string]: string
|
[key: string]: "ask" | "allow" | "deny"
|
||||||
}
|
}
|
||||||
webfetch?: string
|
webfetch?: "ask" | "allow" | "deny"
|
||||||
}
|
}
|
||||||
| undefined
|
| undefined
|
||||||
}
|
}
|
||||||
@@ -980,7 +986,7 @@ export type McpLocalConfig = {
|
|||||||
/**
|
/**
|
||||||
* Type of MCP server connection
|
* Type of MCP server connection
|
||||||
*/
|
*/
|
||||||
type: string
|
type: "local"
|
||||||
/**
|
/**
|
||||||
* Command and arguments to run the MCP server
|
* Command and arguments to run the MCP server
|
||||||
*/
|
*/
|
||||||
@@ -1001,7 +1007,7 @@ export type McpRemoteConfig = {
|
|||||||
/**
|
/**
|
||||||
* Type of MCP server connection
|
* Type of MCP server connection
|
||||||
*/
|
*/
|
||||||
type: string
|
type: "remote"
|
||||||
/**
|
/**
|
||||||
* URL of the remote MCP server
|
* URL of the remote MCP server
|
||||||
*/
|
*/
|
||||||
@@ -1028,7 +1034,7 @@ export type _Error = {
|
|||||||
|
|
||||||
export type TextPartInput = {
|
export type TextPartInput = {
|
||||||
id?: string
|
id?: string
|
||||||
type: string
|
type: "text"
|
||||||
text: string
|
text: string
|
||||||
synthetic?: boolean
|
synthetic?: boolean
|
||||||
time?: {
|
time?: {
|
||||||
@@ -1039,7 +1045,7 @@ export type TextPartInput = {
|
|||||||
|
|
||||||
export type FilePartInput = {
|
export type FilePartInput = {
|
||||||
id?: string
|
id?: string
|
||||||
type: string
|
type: "file"
|
||||||
mime: string
|
mime: string
|
||||||
filename?: string
|
filename?: string
|
||||||
url: string
|
url: string
|
||||||
@@ -1048,7 +1054,7 @@ export type FilePartInput = {
|
|||||||
|
|
||||||
export type AgentPartInput = {
|
export type AgentPartInput = {
|
||||||
id?: string
|
id?: string
|
||||||
type: string
|
type: "agent"
|
||||||
name: string
|
name: string
|
||||||
source?: {
|
source?: {
|
||||||
value: string
|
value: string
|
||||||
@@ -1076,15 +1082,15 @@ export type File = {
|
|||||||
export type Agent = {
|
export type Agent = {
|
||||||
name: string
|
name: string
|
||||||
description?: string
|
description?: string
|
||||||
mode: string
|
mode: "subagent" | "primary" | "all"
|
||||||
topP?: number
|
topP?: number
|
||||||
temperature?: number
|
temperature?: number
|
||||||
permission: {
|
permission: {
|
||||||
edit: string
|
edit: "ask" | "allow" | "deny"
|
||||||
bash: {
|
bash: {
|
||||||
[key: string]: string
|
[key: string]: "ask" | "allow" | "deny"
|
||||||
}
|
}
|
||||||
webfetch?: string
|
webfetch?: "ask" | "allow" | "deny"
|
||||||
}
|
}
|
||||||
model?: {
|
model?: {
|
||||||
modelID: string
|
modelID: string
|
||||||
|
|||||||
@@ -2,8 +2,34 @@ import { createClient } from "./gen/client/client.js"
|
|||||||
import { type Config } from "./gen/client/types.js"
|
import { type Config } from "./gen/client/types.js"
|
||||||
import { OpencodeClient } from "./gen/sdk.gen.js"
|
import { OpencodeClient } from "./gen/sdk.gen.js"
|
||||||
export * from "./gen/types.gen.js"
|
export * from "./gen/types.gen.js"
|
||||||
|
import { spawn } from "child_process"
|
||||||
|
|
||||||
export function createOpencodeClient(config?: Config) {
|
export function createOpencodeClient(config?: Config) {
|
||||||
const client = createClient(config)
|
const client = createClient(config)
|
||||||
return new OpencodeClient({ client })
|
return new OpencodeClient({ client })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ServerConfig = {
|
||||||
|
host?: string
|
||||||
|
port?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createOpencodeServer(config?: ServerConfig) {
|
||||||
|
config = Object.assign(
|
||||||
|
{
|
||||||
|
host: "127.0.0.1",
|
||||||
|
port: 4096,
|
||||||
|
},
|
||||||
|
config ?? {},
|
||||||
|
)
|
||||||
|
|
||||||
|
const proc = spawn(`opencode`, [`serve`, `--host=${config.host}`, `--port=${config.port}`])
|
||||||
|
const url = `http://${config.host}:${config.port}`
|
||||||
|
|
||||||
|
return {
|
||||||
|
url,
|
||||||
|
close() {
|
||||||
|
proc.kill()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user