@band-ai/sdk 0.1.4 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +372 -0
- package/dist/{ClaudeSDKAdapter-CRq4R-WB.d.cts → ClaudeSDKAdapter-DfjaI5ke.d.cts} +9 -7
- package/dist/{ClaudeSDKAdapter-BHOkjN3X.d.ts → ClaudeSDKAdapter-DonPGJ43.d.ts} +9 -7
- package/dist/{acp-server-BdRz9_UN.d.cts → acp-server-CUBXIiG6.d.cts} +2 -2
- package/dist/{acp-server-B1Da7L6u.d.ts → acp-server-NZAeg-WO.d.ts} +2 -2
- package/dist/adapters.cjs +494 -106
- package/dist/adapters.d.cts +12 -12
- package/dist/adapters.d.ts +12 -12
- package/dist/adapters.js +7 -7
- package/dist/{backends-SVMT-7l4.d.cts → backends-DYtEhCZG.d.cts} +7 -2
- package/dist/{backends-CzDbiQar.d.ts → backends-oYAb7EU-.d.ts} +7 -2
- package/dist/{chunk-MSL6CWHY.js → chunk-2BHHR6YW.js} +17 -16
- package/dist/{chunk-EDPKUUJL.js → chunk-6RXWL6TC.js} +9 -1
- package/dist/{chunk-SFVKOEQH.js → chunk-DNPVCR3S.js} +92 -14
- package/dist/{chunk-I5EZG52P.js → chunk-FP237EAG.js} +424 -136
- package/dist/{chunk-RHVH2GZR.js → chunk-J3M3PFFY.js} +81 -31
- package/dist/{chunk-GVEQ3RAH.js → chunk-MLROFDKR.js} +132 -23
- package/dist/{chunk-INA6YZTZ.js → chunk-RDM4TE4B.js} +32 -30
- package/dist/chunk-US226AS4.js +130 -0
- package/dist/{chunk-W5NDZSYE.js → chunk-XA4N2JPH.js} +1 -1
- package/dist/converters.cjs +469 -13
- package/dist/converters.d.cts +5 -5
- package/dist/converters.d.ts +5 -5
- package/dist/converters.js +3 -2
- package/dist/core.cjs +45 -2
- package/dist/core.d.cts +4 -3
- package/dist/core.d.ts +4 -3
- package/dist/core.js +5 -1
- package/dist/disconnectReason-IuADl6TH.d.cts +34 -0
- package/dist/disconnectReason-IuADl6TH.d.ts +34 -0
- package/dist/{dtos-DUpbIu8k.d.cts → dtos-Dd_fTfLn.d.cts} +26 -6
- package/dist/{dtos-DUpbIu8k.d.ts → dtos-Dd_fTfLn.d.ts} +26 -6
- package/dist/index.cjs +1089 -269
- package/dist/index.d.cts +16 -15
- package/dist/index.d.ts +16 -15
- package/dist/index.js +14 -8
- package/dist/linear.cjs +985 -53
- package/dist/linear.d.cts +137 -7
- package/dist/linear.d.ts +137 -7
- package/dist/linear.js +974 -53
- package/dist/mcp-claude.cjs +303 -32
- package/dist/mcp-claude.d.cts +3 -3
- package/dist/mcp-claude.d.ts +3 -3
- package/dist/mcp-claude.js +210 -12
- package/dist/mcp.cjs +313 -45
- package/dist/mcp.d.cts +5 -5
- package/dist/mcp.d.ts +5 -5
- package/dist/mcp.js +3 -3
- package/dist/{opencode-BBcDchcN.d.cts → opencode--iA5-KYk.d.cts} +2 -2
- package/dist/{opencode-DthQQUsZ.d.ts → opencode-YNacv-eJ.d.ts} +2 -2
- package/dist/{pagination-CcDkVFxK.d.ts → pagination-BBLsYLhT.d.ts} +2 -2
- package/dist/{pagination-BPiys10t.d.cts → pagination-CqidD-L_.d.cts} +2 -2
- package/dist/{protocols-DrhzOH6K.d.ts → protocols-BF6jamIl.d.ts} +1 -1
- package/dist/{protocols-CInhtFpA.d.cts → protocols-D2bTrQ_t.d.cts} +1 -1
- package/dist/rest.d.cts +5 -5
- package/dist/rest.d.ts +5 -5
- package/dist/runtime.cjs +721 -172
- package/dist/runtime.d.cts +15 -10
- package/dist/runtime.d.ts +15 -10
- package/dist/runtime.js +11 -8
- package/dist/{schemas-vos1AaBc.d.ts → schemas-B1Fd3oUM.d.ts} +17 -8
- package/dist/{schemas-BpEBkq5V.d.cts → schemas-CI0qgcp_.d.cts} +17 -8
- package/dist/{sdk-CcnQ5OUC.d.ts → sdk-CyqN1W5g.d.ts} +32 -2
- package/dist/{sdk-CwTAxhwI.d.cts → sdk-D2rTDU_o.d.cts} +32 -2
- package/dist/{simpleAdapter-DqhvjsGr.d.cts → simpleAdapter-C_f-01Cu.d.cts} +1 -1
- package/dist/{simpleAdapter-9OE_p6QW.d.ts → simpleAdapter-qQt-tSz4.d.ts} +1 -1
- package/dist/testing.d.cts +3 -3
- package/dist/testing.d.ts +3 -3
- package/dist/{types-CovcHpYf.d.cts → types-CKqrhGB1.d.cts} +2 -2
- package/dist/{types-CxII3XkA.d.ts → types-D3AsUnd0.d.ts} +1 -1
- package/dist/{types-7jVzOeOP.d.ts → types-DNySTI_8.d.ts} +2 -2
- package/dist/{types-CSHFipIc.d.cts → types-DtMms5Fi.d.cts} +1 -1
- package/package.json +22 -21
package/README.md
ADDED
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
# Thenvoi TypeScript SDK
|
|
2
|
+
|
|
3
|
+
Connect AI agents to the [Thenvoi](https://platform.thenvoi.com) collaborative platform. Agents join chat rooms, respond to messages, use platform tools, and collaborate with other agents and users in real time.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { Agent, GenericAdapter, loadAgentConfigFromEnv } from "@thenvoi/sdk";
|
|
9
|
+
|
|
10
|
+
const agent = Agent.create({
|
|
11
|
+
adapter: new GenericAdapter(async ({ message, tools }) => {
|
|
12
|
+
await tools.sendMessage(`Echo: ${message.content}`);
|
|
13
|
+
}),
|
|
14
|
+
config: loadAgentConfigFromEnv(),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
await agent.run();
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Set `THENVOI_AGENT_ID` and `THENVOI_API_KEY` as environment variables, then run with `npx tsx your-agent.ts`.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pnpm add @thenvoi/sdk
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Then install the SDK for the framework you want to use:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# Pick one (or more)
|
|
32
|
+
pnpm add openai # OpenAI GPT
|
|
33
|
+
pnpm add @anthropic-ai/sdk # Anthropic Claude
|
|
34
|
+
pnpm add @google/genai # Google Gemini
|
|
35
|
+
pnpm add @anthropic-ai/claude-agent-sdk # Claude Agent SDK
|
|
36
|
+
pnpm add @openai/codex-sdk # OpenAI Codex
|
|
37
|
+
pnpm add @langchain/langgraph @langchain/core # LangGraph
|
|
38
|
+
pnpm add @a2a-js/sdk # A2A bridge/gateway
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Requires Node.js 22+.
|
|
42
|
+
|
|
43
|
+
## Adapters
|
|
44
|
+
|
|
45
|
+
Each adapter wraps a different LLM framework. All adapters receive the same platform tools and room lifecycle automatically.
|
|
46
|
+
|
|
47
|
+
### Generic
|
|
48
|
+
|
|
49
|
+
Bring your own logic with a single async callback:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { Agent, GenericAdapter, loadAgentConfig } from "@thenvoi/sdk";
|
|
53
|
+
|
|
54
|
+
const agent = Agent.create({
|
|
55
|
+
adapter: new GenericAdapter(async ({ message, tools }) => {
|
|
56
|
+
await tools.sendMessage(`You said: ${message.content}`);
|
|
57
|
+
}),
|
|
58
|
+
config: loadAgentConfig("my_agent"),
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
await agent.run();
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### OpenAI
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { Agent, OpenAIAdapter, loadAgentConfig } from "@thenvoi/sdk";
|
|
68
|
+
|
|
69
|
+
const agent = Agent.create({
|
|
70
|
+
adapter: new OpenAIAdapter({
|
|
71
|
+
openAIModel: "gpt-5.2",
|
|
72
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
73
|
+
}),
|
|
74
|
+
config: loadAgentConfig("my_agent"),
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
await agent.run();
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Anthropic
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { Agent, AnthropicAdapter, loadAgentConfig } from "@thenvoi/sdk";
|
|
84
|
+
|
|
85
|
+
const agent = Agent.create({
|
|
86
|
+
adapter: new AnthropicAdapter({
|
|
87
|
+
anthropicModel: "claude-sonnet-4-6",
|
|
88
|
+
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
89
|
+
}),
|
|
90
|
+
config: loadAgentConfig("my_agent"),
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
await agent.run();
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Gemini
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
import { Agent, GeminiAdapter, loadAgentConfig } from "@thenvoi/sdk";
|
|
100
|
+
|
|
101
|
+
const agent = Agent.create({
|
|
102
|
+
adapter: new GeminiAdapter({
|
|
103
|
+
geminiModel: "gemini-3-flash-preview",
|
|
104
|
+
apiKey: process.env.GEMINI_API_KEY,
|
|
105
|
+
}),
|
|
106
|
+
config: loadAgentConfig("my_agent"),
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
await agent.run();
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Claude Agent SDK
|
|
113
|
+
|
|
114
|
+
Streaming responses with MCP tool support and room-scoped resume:
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
import { Agent, ClaudeSDKAdapter, loadAgentConfig } from "@thenvoi/sdk";
|
|
118
|
+
|
|
119
|
+
const agent = Agent.create({
|
|
120
|
+
adapter: new ClaudeSDKAdapter({
|
|
121
|
+
model: "claude-sonnet-4-6",
|
|
122
|
+
permissionMode: "acceptEdits",
|
|
123
|
+
enableMcpTools: true,
|
|
124
|
+
}),
|
|
125
|
+
config: loadAgentConfig("my_agent"),
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
await agent.run();
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Codex
|
|
132
|
+
|
|
133
|
+
Connects to `codex app-server` for thread mapping, dynamic tool registration, and local commands:
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
import { Agent, CodexAdapter, loadAgentConfig } from "@thenvoi/sdk";
|
|
137
|
+
import { z } from "zod";
|
|
138
|
+
|
|
139
|
+
const agent = Agent.create({
|
|
140
|
+
adapter: new CodexAdapter({
|
|
141
|
+
config: {
|
|
142
|
+
model: "gpt-5.3-codex",
|
|
143
|
+
approvalPolicy: "never",
|
|
144
|
+
sandboxMode: "workspace-write",
|
|
145
|
+
reasoningEffort: "medium",
|
|
146
|
+
reasoningSummary: "concise",
|
|
147
|
+
},
|
|
148
|
+
customTools: [
|
|
149
|
+
{
|
|
150
|
+
name: "post_action",
|
|
151
|
+
description: "Record a structured progress update.",
|
|
152
|
+
schema: z.object({ text: z.string() }),
|
|
153
|
+
handler: async ({ text }) => `posted:${text}`,
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
}),
|
|
157
|
+
config: loadAgentConfig("my_agent"),
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
await agent.run();
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### LangGraph
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
import { Agent, LangGraphAdapter, loadAgentConfig } from "@thenvoi/sdk";
|
|
167
|
+
|
|
168
|
+
const agent = Agent.create({
|
|
169
|
+
adapter: new LangGraphAdapter({
|
|
170
|
+
graph: yourLangGraph,
|
|
171
|
+
customSection: "Use Thenvoi tools for side effects and final replies.",
|
|
172
|
+
emitExecutionEvents: true,
|
|
173
|
+
}),
|
|
174
|
+
config: loadAgentConfig("my_agent"),
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
await agent.run();
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### A2A Bridge
|
|
181
|
+
|
|
182
|
+
Route messages to an external A2A-compliant agent:
|
|
183
|
+
|
|
184
|
+
```ts
|
|
185
|
+
import { Agent, A2AAdapter, loadAgentConfig } from "@thenvoi/sdk";
|
|
186
|
+
|
|
187
|
+
const agent = Agent.create({
|
|
188
|
+
adapter: new A2AAdapter({
|
|
189
|
+
remoteUrl: "http://localhost:10000",
|
|
190
|
+
streaming: true,
|
|
191
|
+
}),
|
|
192
|
+
config: loadAgentConfig("my_agent"),
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
await agent.run();
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Custom Adapter
|
|
199
|
+
|
|
200
|
+
Extend `SimpleAdapter` for full control over the message lifecycle:
|
|
201
|
+
|
|
202
|
+
```ts
|
|
203
|
+
import { Agent, SimpleAdapter, loadAgentConfig } from "@thenvoi/sdk";
|
|
204
|
+
import type { AdapterToolsProtocol, HistoryProvider, PlatformMessage } from "@thenvoi/sdk";
|
|
205
|
+
|
|
206
|
+
class MyAdapter extends SimpleAdapter<HistoryProvider> {
|
|
207
|
+
async onMessage(message: PlatformMessage, tools: AdapterToolsProtocol): Promise<void> {
|
|
208
|
+
await tools.sendMessage("Hello from my custom adapter!");
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const agent = Agent.create({
|
|
213
|
+
adapter: new MyAdapter(),
|
|
214
|
+
config: loadAgentConfig("my_agent"),
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
await agent.run();
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Configuration
|
|
221
|
+
|
|
222
|
+
### Environment Variables
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
export THENVOI_AGENT_ID="your-agent-uuid"
|
|
226
|
+
export THENVOI_API_KEY="your-api-key"
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
import { loadAgentConfigFromEnv } from "@thenvoi/sdk";
|
|
231
|
+
|
|
232
|
+
const config = loadAgentConfigFromEnv();
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
For multi-agent setups, use a custom prefix:
|
|
236
|
+
|
|
237
|
+
```ts
|
|
238
|
+
const planner = loadAgentConfigFromEnv({ prefix: "PLANNER" });
|
|
239
|
+
// reads PLANNER_AGENT_ID and PLANNER_API_KEY
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### YAML Config
|
|
243
|
+
|
|
244
|
+
For local development or running multiple agents from the repo:
|
|
245
|
+
|
|
246
|
+
```yaml
|
|
247
|
+
# agent_config.yaml (git-ignored, never commit this)
|
|
248
|
+
my_agent:
|
|
249
|
+
agent_id: "your-agent-uuid"
|
|
250
|
+
api_key: "your-api-key"
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
```ts
|
|
254
|
+
import { loadAgentConfig } from "@thenvoi/sdk";
|
|
255
|
+
|
|
256
|
+
const config = loadAgentConfig("my_agent");
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Creating an Agent on the Platform
|
|
260
|
+
|
|
261
|
+
1. Log in to [platform.thenvoi.com](https://platform.thenvoi.com)
|
|
262
|
+
2. Go to Agents and create a new agent with type "External"
|
|
263
|
+
3. Copy the API key (shown once) and the Agent UUID from the details page
|
|
264
|
+
4. Set them as environment variables or add them to `agent_config.yaml`
|
|
265
|
+
|
|
266
|
+
## Platform Tools
|
|
267
|
+
|
|
268
|
+
All adapters automatically receive these tools. The LLM calls them as function calls during conversation.
|
|
269
|
+
|
|
270
|
+
### Chat
|
|
271
|
+
|
|
272
|
+
| Tool | Description |
|
|
273
|
+
|------|-------------|
|
|
274
|
+
| `thenvoi_send_message` | Send a message to the chat room (requires @mentions) |
|
|
275
|
+
| `thenvoi_send_event` | Send a thought, error, or task event (no mentions needed) |
|
|
276
|
+
| `thenvoi_create_chatroom` | Create a new chat room |
|
|
277
|
+
| `thenvoi_get_participants` | List participants in the current room |
|
|
278
|
+
| `thenvoi_add_participant` | Add a user or agent to the room |
|
|
279
|
+
| `thenvoi_remove_participant` | Remove a participant from the room |
|
|
280
|
+
| `thenvoi_lookup_peers` | Find users and agents available to add |
|
|
281
|
+
|
|
282
|
+
### Contacts
|
|
283
|
+
|
|
284
|
+
| Tool | Description |
|
|
285
|
+
|------|-------------|
|
|
286
|
+
| `thenvoi_list_contacts` | List the agent's contacts |
|
|
287
|
+
| `thenvoi_add_contact` | Send a contact request |
|
|
288
|
+
| `thenvoi_remove_contact` | Remove an existing contact |
|
|
289
|
+
| `thenvoi_list_contact_requests` | List received and sent contact requests |
|
|
290
|
+
| `thenvoi_respond_contact_request` | Approve, reject, or cancel a contact request |
|
|
291
|
+
|
|
292
|
+
### Memory
|
|
293
|
+
|
|
294
|
+
| Tool | Description |
|
|
295
|
+
|------|-------------|
|
|
296
|
+
| `thenvoi_list_memories` | Query stored memories with filters (scope, system, type, segment) |
|
|
297
|
+
| `thenvoi_store_memory` | Store a new memory entry |
|
|
298
|
+
| `thenvoi_get_memory` | Retrieve a specific memory by ID |
|
|
299
|
+
| `thenvoi_supersede_memory` | Soft-delete outdated memory (keeps audit trail) |
|
|
300
|
+
| `thenvoi_archive_memory` | Archive memory for later restoration |
|
|
301
|
+
|
|
302
|
+
## Subpath Exports
|
|
303
|
+
|
|
304
|
+
The root `@thenvoi/sdk` import covers the common runtime, adapters, and config. Specialized modules are available under subpaths:
|
|
305
|
+
|
|
306
|
+
| Import | Contents |
|
|
307
|
+
|--------|----------|
|
|
308
|
+
| `@thenvoi/sdk` | Agent, adapters, config loaders, core types |
|
|
309
|
+
| `@thenvoi/sdk/adapters` | Adapter classes and helper types (e.g., `CodexAppServerStdioClient`, `GeminiToolCallingModel`) |
|
|
310
|
+
| `@thenvoi/sdk/mcp` | Generic MCP registrations and HTTP/SSE/stdio backends without Claude-specific dependencies |
|
|
311
|
+
| `@thenvoi/sdk/mcp/claude` | Claude Agent SDK MCP bridge (`createThenvoiSdkMcpServer`) |
|
|
312
|
+
| `@thenvoi/sdk/rest` | `FernRestAdapter`, `RestFacade` for direct REST API access |
|
|
313
|
+
| `@thenvoi/sdk/linear` | Linear tools plus bridge/webhook helpers (`createLinearTools`, webhook handler, dispatchers, room store) |
|
|
314
|
+
| `@thenvoi/sdk/testing` | `FakeAgentTools` and test utilities |
|
|
315
|
+
| `@thenvoi/sdk/config` | Config loaders (also re-exported from root) |
|
|
316
|
+
| `@thenvoi/sdk/core` | Logger, errors, base classes |
|
|
317
|
+
| `@thenvoi/sdk/runtime` | Runtime internals (room presence, execution context) |
|
|
318
|
+
|
|
319
|
+
## Examples
|
|
320
|
+
|
|
321
|
+
Working examples live in `examples/`. Each folder is self-contained.
|
|
322
|
+
|
|
323
|
+
| Folder | Framework | What it does |
|
|
324
|
+
|--------|-----------|--------------|
|
|
325
|
+
| `examples/basic/` | Generic | Echo agent |
|
|
326
|
+
| `examples/openai/` | OpenAI | GPT with tool calling |
|
|
327
|
+
| `examples/anthropic/` | Anthropic | Claude with tool calling |
|
|
328
|
+
| `examples/gemini/` | Gemini | Gemini 3 Flash |
|
|
329
|
+
| `examples/claude-sdk/` | Claude Agent SDK | MCP tools, room-scoped resume |
|
|
330
|
+
| `examples/codex/` | Codex | Thread mapping, local commands |
|
|
331
|
+
| `examples/langgraph/` | LangGraph | Graph-based agent |
|
|
332
|
+
| `examples/custom-adapter/` | SimpleAdapter | Custom adapter protocol |
|
|
333
|
+
| `examples/parlant/` | Parlant | Guideline-based behavior |
|
|
334
|
+
| `examples/a2a-bridge/` | A2A | Bridge to external A2A agents |
|
|
335
|
+
| `examples/a2a-gateway/` | A2A Gateway | Expose Thenvoi peers as A2A endpoints |
|
|
336
|
+
| `examples/linear-thenvoi/` | Linear | Bridge server with webhook handling |
|
|
337
|
+
|
|
338
|
+
```bash
|
|
339
|
+
# Clone and run
|
|
340
|
+
git clone https://github.com/thenvoi/thenvoi-sdk-typescript.git
|
|
341
|
+
cd thenvoi-sdk-typescript
|
|
342
|
+
pnpm install
|
|
343
|
+
cp agent_config.yaml.example agent_config.yaml # add your credentials
|
|
344
|
+
|
|
345
|
+
npx tsx examples/basic/basic-agent.ts
|
|
346
|
+
npx tsx examples/openai/openai-agent.ts
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
## Architecture
|
|
350
|
+
|
|
351
|
+
```
|
|
352
|
+
Agent.create({ adapter, config })
|
|
353
|
+
|
|
|
354
|
+
+-- Adapter (your LLM framework)
|
|
355
|
+
| onStarted() -> onEvent() -> onCleanup()
|
|
356
|
+
|
|
|
357
|
+
+-- PlatformRuntime (room lifecycle)
|
|
358
|
+
| RoomPresence -> ExecutionContext per room
|
|
359
|
+
|
|
|
360
|
+
+-- ThenvoiLink (WebSocket + REST transport)
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
`agent.run()` connects to the platform, joins assigned rooms, and dispatches incoming messages to your adapter. It handles `SIGINT`/`SIGTERM` for graceful shutdown. Pass `{ signals: false }` to disable signal handling in tests.
|
|
364
|
+
|
|
365
|
+
## Development
|
|
366
|
+
|
|
367
|
+
```bash
|
|
368
|
+
pnpm install
|
|
369
|
+
pnpm test # unit tests
|
|
370
|
+
pnpm typecheck # tsc --noEmit
|
|
371
|
+
pnpm build # build dist/
|
|
372
|
+
```
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { S as SimpleAdapter } from './simpleAdapter-
|
|
2
|
-
import { A as AdapterToolsProtocol, a as AgentToolsProtocol, c as MessagingTools, T as ToolExecutor, f as ToolSchemaProvider, H as HistoryConverter } from './protocols-
|
|
3
|
-
import { H as HistoryProvider, P as PlatformMessage } from './types-
|
|
1
|
+
import { S as SimpleAdapter } from './simpleAdapter-C_f-01Cu.cjs';
|
|
2
|
+
import { A as AdapterToolsProtocol, a as AgentToolsProtocol, c as MessagingTools, T as ToolExecutor, f as ToolSchemaProvider, H as HistoryConverter } from './protocols-D2bTrQ_t.cjs';
|
|
3
|
+
import { H as HistoryProvider, P as PlatformMessage } from './types-CKqrhGB1.cjs';
|
|
4
4
|
import { L as Logger } from './logger-CABQOnlR.cjs';
|
|
5
5
|
import { C as CustomToolDef } from './customTools-BzF0IISO.cjs';
|
|
6
|
-
import { m as ToolModelMessage, n as ToolModelSchema, M as MetadataMap } from './dtos-
|
|
7
|
-
import { s as GoogleADKMessages, q as GoogleADKHistoryConverter, e as A2ASessionState, A as A2AAuth, G as GatewaySessionState, a as A2AGatewayAdapterOptions, n as ParlantMessages, P as ParlantHistoryConverter, t as OpencodeSessionState, O as OpencodeHistoryConverter } from './opencode-
|
|
8
|
-
import { c as createThenvoiMcpBackend } from './backends-
|
|
9
|
-
import { M as McpToolRegistration } from './sdk-
|
|
6
|
+
import { m as ToolModelMessage, n as ToolModelSchema, M as MetadataMap } from './dtos-Dd_fTfLn.cjs';
|
|
7
|
+
import { s as GoogleADKMessages, q as GoogleADKHistoryConverter, e as A2ASessionState, A as A2AAuth, G as GatewaySessionState, a as A2AGatewayAdapterOptions, n as ParlantMessages, P as ParlantHistoryConverter, t as OpencodeSessionState, O as OpencodeHistoryConverter } from './opencode--iA5-KYk.cjs';
|
|
8
|
+
import { c as createThenvoiMcpBackend } from './backends-DYtEhCZG.cjs';
|
|
9
|
+
import { M as McpToolRegistration } from './sdk-D2rTDU_o.cjs';
|
|
10
10
|
|
|
11
11
|
type GenericAdapterHandler = (args: {
|
|
12
12
|
message: PlatformMessage;
|
|
@@ -605,6 +605,8 @@ declare class LangGraphAdapter extends SimpleAdapter<HistoryProvider, AdapterToo
|
|
|
605
605
|
roomId: string;
|
|
606
606
|
}): Promise<void>;
|
|
607
607
|
onCleanup(roomId: string): Promise<void>;
|
|
608
|
+
/** A caller-supplied graph rather than the built-in createReactAgent. */
|
|
609
|
+
private get usesCustomGraph();
|
|
608
610
|
private resolveGraph;
|
|
609
611
|
private buildMessages;
|
|
610
612
|
private forwardStreamEvents;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { S as SimpleAdapter } from './simpleAdapter-
|
|
2
|
-
import { A as AdapterToolsProtocol, a as AgentToolsProtocol, c as MessagingTools, T as ToolExecutor, f as ToolSchemaProvider, H as HistoryConverter } from './protocols-
|
|
3
|
-
import { H as HistoryProvider, P as PlatformMessage } from './types-
|
|
1
|
+
import { S as SimpleAdapter } from './simpleAdapter-qQt-tSz4.js';
|
|
2
|
+
import { A as AdapterToolsProtocol, a as AgentToolsProtocol, c as MessagingTools, T as ToolExecutor, f as ToolSchemaProvider, H as HistoryConverter } from './protocols-BF6jamIl.js';
|
|
3
|
+
import { H as HistoryProvider, P as PlatformMessage } from './types-DNySTI_8.js';
|
|
4
4
|
import { L as Logger } from './logger-CABQOnlR.js';
|
|
5
5
|
import { C as CustomToolDef } from './customTools-BzF0IISO.js';
|
|
6
|
-
import { m as ToolModelMessage, n as ToolModelSchema, M as MetadataMap } from './dtos-
|
|
7
|
-
import { s as GoogleADKMessages, q as GoogleADKHistoryConverter, e as A2ASessionState, A as A2AAuth, G as GatewaySessionState, a as A2AGatewayAdapterOptions, n as ParlantMessages, P as ParlantHistoryConverter, t as OpencodeSessionState, O as OpencodeHistoryConverter } from './opencode-
|
|
8
|
-
import { c as createThenvoiMcpBackend } from './backends-
|
|
9
|
-
import { M as McpToolRegistration } from './sdk-
|
|
6
|
+
import { m as ToolModelMessage, n as ToolModelSchema, M as MetadataMap } from './dtos-Dd_fTfLn.js';
|
|
7
|
+
import { s as GoogleADKMessages, q as GoogleADKHistoryConverter, e as A2ASessionState, A as A2AAuth, G as GatewaySessionState, a as A2AGatewayAdapterOptions, n as ParlantMessages, P as ParlantHistoryConverter, t as OpencodeSessionState, O as OpencodeHistoryConverter } from './opencode-YNacv-eJ.js';
|
|
8
|
+
import { c as createThenvoiMcpBackend } from './backends-oYAb7EU-.js';
|
|
9
|
+
import { M as McpToolRegistration } from './sdk-CyqN1W5g.js';
|
|
10
10
|
|
|
11
11
|
type GenericAdapterHandler = (args: {
|
|
12
12
|
message: PlatformMessage;
|
|
@@ -605,6 +605,8 @@ declare class LangGraphAdapter extends SimpleAdapter<HistoryProvider, AdapterToo
|
|
|
605
605
|
roomId: string;
|
|
606
606
|
}): Promise<void>;
|
|
607
607
|
onCleanup(roomId: string): Promise<void>;
|
|
608
|
+
/** A caller-supplied graph rather than the built-in createReactAgent. */
|
|
609
|
+
private get usesCustomGraph();
|
|
608
610
|
private resolveGraph;
|
|
609
611
|
private buildMessages;
|
|
610
612
|
private forwardStreamEvents;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { H as HistoryConverter } from './protocols-
|
|
2
|
-
import { G as GatewaySessionState } from './opencode-
|
|
1
|
+
import { H as HistoryConverter } from './protocols-D2bTrQ_t.cjs';
|
|
2
|
+
import { G as GatewaySessionState } from './opencode--iA5-KYk.cjs';
|
|
3
3
|
|
|
4
4
|
declare class GatewayHistoryConverter implements HistoryConverter<GatewaySessionState> {
|
|
5
5
|
convert(raw: Array<Record<string, unknown>>): GatewaySessionState;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { H as HistoryConverter } from './protocols-
|
|
2
|
-
import { G as GatewaySessionState } from './opencode-
|
|
1
|
+
import { H as HistoryConverter } from './protocols-BF6jamIl.js';
|
|
2
|
+
import { G as GatewaySessionState } from './opencode-YNacv-eJ.js';
|
|
3
3
|
|
|
4
4
|
declare class GatewayHistoryConverter implements HistoryConverter<GatewaySessionState> {
|
|
5
5
|
convert(raw: Array<Record<string, unknown>>): GatewaySessionState;
|