summaryrefslogtreecommitdiffhomepage
path: root/packages/web/src
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-08-21 17:15:21 -0400
committerDax Raad <[email protected]>2025-08-21 17:15:21 -0400
commit5d508cc9c2d840b03161ee6f9e836240fd8e474a (patch)
treebf88358fd5073a7a3c60e08368f237ee5113825f /packages/web/src
parentd9233872b97b23a52827569df693dd3ff702313c (diff)
downloadopencode-5d508cc9c2d840b03161ee6f9e836240fd8e474a.tar.gz
opencode-5d508cc9c2d840b03161ee6f9e836240fd8e474a.zip
docs: update SDK documentation
Diffstat (limited to 'packages/web/src')
-rw-r--r--packages/web/src/content/docs/docs/sdk.mdx36
1 files changed, 24 insertions, 12 deletions
diff --git a/packages/web/src/content/docs/docs/sdk.mdx b/packages/web/src/content/docs/docs/sdk.mdx
index 2b6ea23ec..6002d135a 100644
--- a/packages/web/src/content/docs/docs/sdk.mdx
+++ b/packages/web/src/content/docs/docs/sdk.mdx
@@ -36,10 +36,13 @@ const client = createOpencodeClient({
#### Options
-| Option | Type | Description | Default |
-| --------- | ---------- | --------------------------- | ----------------------- |
-| `baseUrl` | `string` | URL of the opencode server | `http://localhost:4096` |
-| `fetch` | `function` | Custom fetch implementation | `globalThis.fetch` |
+| Option | Type | Description | Default |
+| --------------- | ---------- | --------------------------------- | ----------------------- |
+| `baseUrl` | `string` | URL of the opencode server | `http://localhost:4096` |
+| `fetch` | `function` | Custom fetch implementation | `globalThis.fetch` |
+| `parseAs` | `string` | Response parsing method | `auto` |
+| `responseStyle` | `string` | Return style: `data` or `fields` | `fields` |
+| `throwOnError` | `boolean` | Throw errors instead of returning | `false` |
---
@@ -47,18 +50,27 @@ const client = createOpencodeClient({
You can also programmatically start an opencode server:
-```javascript
+````javascript
import { createOpencodeServer } from "@opencode-ai/sdk"
const server = await createOpencodeServer({
- host: "127.0.0.1",
+ hostname: "127.0.0.1",
port: 4096,
})
console.log(`Server running at ${server.url}`)
server.close()
-```
+}
+
+#### Options
+
+| Option | Type | Description | Default |
+| ---------- | -------------- | ------------------------------ | ------------- |
+| `hostname` | `string` | Server hostname | `127.0.0.1` |
+| `port` | `number` | Server port | `4096` |
+| `signal` | `AbortSignal` | Abort signal for cancellation | `undefined` |
+| `timeout` | `number` | Timeout in ms for server start | `5000` |
---
@@ -68,7 +80,7 @@ The SDK includes TypeScript definitions for all API types. Import them directly:
```typescript
import type { Session, Message, Part } from "@opencode-ai/sdk"
-```
+````
All types are generated from the server's OpenAPI specification and available in the <a href={typesUrl}>types file</a>.
@@ -167,7 +179,7 @@ const message = await client.session.chat({
id: session.id,
providerID: "anthropic",
modelID: "claude-3-5-sonnet-20241022",
- parts: [{ type: "text", text: "Hello!" }]
+ parts: [{ type: "text", text: "Hello!" }],
})
```
@@ -210,7 +222,7 @@ const content = await client.file.read({ path: "src/index.ts" })
await client.log.write({
service: "my-app",
level: "info",
- message: "Operation completed"
+ message: "Operation completed",
})
```
@@ -257,7 +269,7 @@ const agents = await client.agent.list()
await client.tui.appendPrompt({ text: "Add this to prompt" })
await client.tui.showToast({
message: "Task completed",
- variant: "success"
+ variant: "success",
})
```
@@ -277,7 +289,7 @@ await client.tui.showToast({
await client.auth.set({
id: "anthropic",
type: "api",
- key: "your-api-key"
+ key: "your-api-key",
})
```