mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-15 06:04:43 +00:00
chore: sync workspace changes
This commit is contained in:
parent
d24f983e2c
commit
bf58891edf
139 changed files with 5454 additions and 8986 deletions
|
|
@ -3,7 +3,7 @@ title: "TypeScript SDK"
|
|||
description: "Use the generated client to manage sessions and stream events."
|
||||
---
|
||||
|
||||
The TypeScript SDK is generated from the OpenAPI spec that ships with the daemon. It provides a typed
|
||||
The TypeScript SDK is generated from the OpenAPI spec that ships with the server. It provides a typed
|
||||
client for sessions, events, and agent operations.
|
||||
|
||||
## Install
|
||||
|
|
@ -15,34 +15,22 @@ npm install sandbox-agent
|
|||
## Create a client
|
||||
|
||||
```ts
|
||||
import { SandboxDaemonClient } from "sandbox-agent";
|
||||
import { SandboxAgent } from "sandbox-agent";
|
||||
|
||||
const client = new SandboxDaemonClient({
|
||||
const client = await SandboxAgent.connect({
|
||||
baseUrl: "http://127.0.0.1:2468",
|
||||
token: process.env.SANDBOX_TOKEN,
|
||||
});
|
||||
```
|
||||
|
||||
Or with the factory helper:
|
||||
|
||||
```ts
|
||||
import { createSandboxDaemonClient } from "sandbox-agent";
|
||||
|
||||
const client = createSandboxDaemonClient({
|
||||
baseUrl: "http://127.0.0.1:2468",
|
||||
});
|
||||
```
|
||||
|
||||
## Autospawn (Node only)
|
||||
|
||||
If you run locally, the SDK can launch the daemon for you.
|
||||
If you run locally, the SDK can launch the server for you.
|
||||
|
||||
```ts
|
||||
import { connectSandboxDaemonClient } from "sandbox-agent";
|
||||
import { SandboxAgent } from "sandbox-agent";
|
||||
|
||||
const client = await connectSandboxDaemonClient({
|
||||
spawn: { enabled: true },
|
||||
});
|
||||
const client = await SandboxAgent.start();
|
||||
|
||||
await client.dispose();
|
||||
```
|
||||
|
|
@ -55,8 +43,8 @@ Autospawn uses the local `sandbox-agent` binary. Install `@sandbox-agent/cli` (r
|
|||
```ts
|
||||
await client.createSession("demo-session", {
|
||||
agent: "codex",
|
||||
agent_mode: "default",
|
||||
permission_mode: "plan",
|
||||
agentMode: "default",
|
||||
permissionMode: "plan",
|
||||
});
|
||||
|
||||
await client.postMessage("demo-session", { message: "Hello" });
|
||||
|
|
@ -76,11 +64,11 @@ console.log(codex?.capabilities);
|
|||
const events = await client.getEvents("demo-session", {
|
||||
offset: 0,
|
||||
limit: 200,
|
||||
include_raw: false,
|
||||
includeRaw: false,
|
||||
});
|
||||
|
||||
for (const event of events.events) {
|
||||
console.log(event.event_type, event.data);
|
||||
console.log(event.type, event.data);
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -89,9 +77,9 @@ for (const event of events.events) {
|
|||
```ts
|
||||
for await (const event of client.streamEvents("demo-session", {
|
||||
offset: 0,
|
||||
include_raw: false,
|
||||
includeRaw: false,
|
||||
})) {
|
||||
console.log(event.event_type, event.data);
|
||||
console.log(event.type, event.data);
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -100,20 +88,20 @@ The SDK parses `text/event-stream` into `UniversalEvent` objects. If you want fu
|
|||
|
||||
## Optional raw payloads
|
||||
|
||||
Set `include_raw: true` on `getEvents` or `streamEvents` to include the raw provider payload in
|
||||
Set `includeRaw: true` on `getEvents` or `streamEvents` to include the raw provider payload in
|
||||
`event.raw`. This is useful for debugging and conversion analysis.
|
||||
|
||||
## Error handling
|
||||
|
||||
All HTTP errors throw `SandboxDaemonError`:
|
||||
All HTTP errors throw `SandboxAgentError`:
|
||||
|
||||
```ts
|
||||
import { SandboxDaemonError } from "sandbox-agent";
|
||||
import { SandboxAgentError } from "sandbox-agent";
|
||||
|
||||
try {
|
||||
await client.postMessage("missing-session", { message: "Hi" });
|
||||
} catch (error) {
|
||||
if (error instanceof SandboxDaemonError) {
|
||||
if (error instanceof SandboxAgentError) {
|
||||
console.error(error.status, error.problem);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue