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