@codeany/open-agent-sdk 0.1.0 → 0.2.1
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 +144 -31
- package/dist/agent.d.ts +113 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +446 -0
- package/dist/agent.js.map +1 -0
- package/dist/engine.d.ts +62 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +494 -0
- package/dist/engine.js.map +1 -0
- package/dist/hooks.d.ts +111 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +179 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +66 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +133 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/client.d.ts +19 -0
- package/dist/mcp/client.d.ts.map +1 -0
- package/dist/mcp/client.js +126 -0
- package/dist/mcp/client.js.map +1 -0
- package/dist/providers/anthropic.d.ts +17 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +47 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/index.d.ts +20 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +26 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/openai.d.ts +26 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +212 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/types.d.ts +84 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +11 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/sdk-mcp-server.d.ts +52 -0
- package/dist/sdk-mcp-server.d.ts.map +1 -0
- package/dist/sdk-mcp-server.js +57 -0
- package/dist/sdk-mcp-server.js.map +1 -0
- package/dist/session.d.ts +73 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +159 -0
- package/dist/session.js.map +1 -0
- package/dist/skills/bundled/commit.d.ts +7 -0
- package/dist/skills/bundled/commit.d.ts.map +1 -0
- package/dist/skills/bundled/commit.js +35 -0
- package/dist/skills/bundled/commit.js.map +1 -0
- package/dist/skills/bundled/debug.d.ts +7 -0
- package/dist/skills/bundled/debug.d.ts.map +1 -0
- package/dist/skills/bundled/debug.js +46 -0
- package/dist/skills/bundled/debug.js.map +1 -0
- package/dist/skills/bundled/index.d.ts +11 -0
- package/dist/skills/bundled/index.d.ts.map +1 -0
- package/dist/skills/bundled/index.js +26 -0
- package/dist/skills/bundled/index.js.map +1 -0
- package/dist/skills/bundled/review.d.ts +7 -0
- package/dist/skills/bundled/review.d.ts.map +1 -0
- package/dist/skills/bundled/review.js +38 -0
- package/dist/skills/bundled/review.js.map +1 -0
- package/dist/skills/bundled/simplify.d.ts +8 -0
- package/dist/skills/bundled/simplify.d.ts.map +1 -0
- package/dist/skills/bundled/simplify.js +48 -0
- package/dist/skills/bundled/simplify.js.map +1 -0
- package/dist/skills/bundled/test.d.ts +7 -0
- package/dist/skills/bundled/test.d.ts.map +1 -0
- package/dist/skills/bundled/test.js +40 -0
- package/dist/skills/bundled/test.js.map +1 -0
- package/dist/skills/index.d.ts +7 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/index.js +8 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/skills/registry.d.ts +43 -0
- package/dist/skills/registry.d.ts.map +1 -0
- package/dist/skills/registry.js +111 -0
- package/dist/skills/registry.js.map +1 -0
- package/dist/skills/types.d.ts +83 -0
- package/dist/skills/types.d.ts.map +1 -0
- package/dist/skills/types.js +8 -0
- package/dist/skills/types.js.map +1 -0
- package/dist/tool-helper.d.ts +73 -0
- package/dist/tool-helper.d.ts.map +1 -0
- package/dist/tool-helper.js +86 -0
- package/dist/tool-helper.js.map +1 -0
- package/dist/tools/agent-tool.d.ts +17 -0
- package/dist/tools/agent-tool.d.ts.map +1 -0
- package/dist/tools/agent-tool.js +146 -0
- package/dist/tools/agent-tool.js.map +1 -0
- package/dist/tools/ask-user.d.ts +18 -0
- package/dist/tools/ask-user.d.ts.map +1 -0
- package/dist/tools/ask-user.js +72 -0
- package/dist/tools/ask-user.js.map +1 -0
- package/dist/tools/bash.d.ts +5 -0
- package/dist/tools/bash.d.ts.map +1 -0
- package/dist/tools/bash.js +67 -0
- package/dist/tools/bash.js.map +1 -0
- package/dist/tools/config-tool.d.ts +20 -0
- package/dist/tools/config-tool.d.ts.map +1 -0
- package/dist/tools/config-tool.js +83 -0
- package/dist/tools/config-tool.js.map +1 -0
- package/dist/tools/cron-tools.d.ts +33 -0
- package/dist/tools/cron-tools.d.ts.map +1 -0
- package/dist/tools/cron-tools.js +128 -0
- package/dist/tools/cron-tools.js.map +1 -0
- package/dist/tools/edit.d.ts +5 -0
- package/dist/tools/edit.d.ts.map +1 -0
- package/dist/tools/edit.js +70 -0
- package/dist/tools/edit.js.map +1 -0
- package/dist/tools/glob.d.ts +5 -0
- package/dist/tools/glob.d.ts.map +1 -0
- package/dist/tools/glob.js +75 -0
- package/dist/tools/glob.js.map +1 -0
- package/dist/tools/grep.d.ts +5 -0
- package/dist/tools/grep.d.ts.map +1 -0
- package/dist/tools/grep.js +168 -0
- package/dist/tools/grep.js.map +1 -0
- package/dist/tools/index.d.ts +45 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +162 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/lsp-tool.d.ts +9 -0
- package/dist/tools/lsp-tool.d.ts.map +1 -0
- package/dist/tools/lsp-tool.js +137 -0
- package/dist/tools/lsp-tool.js.map +1 -0
- package/dist/tools/mcp-resource-tools.d.ts +14 -0
- package/dist/tools/mcp-resource-tools.d.ts.map +1 -0
- package/dist/tools/mcp-resource-tools.js +117 -0
- package/dist/tools/mcp-resource-tools.js.map +1 -0
- package/dist/tools/notebook-edit.d.ts +5 -0
- package/dist/tools/notebook-edit.d.ts.map +1 -0
- package/dist/tools/notebook-edit.js +85 -0
- package/dist/tools/notebook-edit.js.map +1 -0
- package/dist/tools/plan-tools.d.ts +12 -0
- package/dist/tools/plan-tools.d.ts.map +1 -0
- package/dist/tools/plan-tools.js +77 -0
- package/dist/tools/plan-tools.js.map +1 -0
- package/dist/tools/read.d.ts +5 -0
- package/dist/tools/read.d.ts.map +1 -0
- package/dist/tools/read.js +66 -0
- package/dist/tools/read.js.map +1 -0
- package/dist/tools/send-message.d.ts +31 -0
- package/dist/tools/send-message.d.ts.map +1 -0
- package/dist/tools/send-message.js +77 -0
- package/dist/tools/send-message.js.map +1 -0
- package/dist/tools/skill-tool.d.ts +9 -0
- package/dist/tools/skill-tool.d.ts.map +1 -0
- package/dist/tools/skill-tool.js +115 -0
- package/dist/tools/skill-tool.js.map +1 -0
- package/dist/tools/task-tools.d.ts +48 -0
- package/dist/tools/task-tools.d.ts.map +1 -0
- package/dist/tools/task-tools.js +242 -0
- package/dist/tools/task-tools.js.map +1 -0
- package/dist/tools/team-tools.d.ts +34 -0
- package/dist/tools/team-tools.d.ts.map +1 -0
- package/dist/tools/team-tools.js +103 -0
- package/dist/tools/team-tools.js.map +1 -0
- package/dist/tools/todo-tool.d.ts +22 -0
- package/dist/tools/todo-tool.d.ts.map +1 -0
- package/dist/tools/todo-tool.js +93 -0
- package/dist/tools/todo-tool.js.map +1 -0
- package/dist/tools/tool-search.d.ts +13 -0
- package/dist/tools/tool-search.d.ts.map +1 -0
- package/dist/tools/tool-search.js +76 -0
- package/dist/tools/tool-search.js.map +1 -0
- package/dist/tools/types.d.ts +29 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +52 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/tools/web-fetch.d.ts +5 -0
- package/dist/tools/web-fetch.d.ts.map +1 -0
- package/dist/tools/web-fetch.js +60 -0
- package/dist/tools/web-fetch.js.map +1 -0
- package/dist/tools/web-search.d.ts +5 -0
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js +77 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/tools/worktree-tools.d.ts +10 -0
- package/dist/tools/worktree-tools.d.ts.map +1 -0
- package/dist/tools/worktree-tools.js +130 -0
- package/dist/tools/worktree-tools.js.map +1 -0
- package/dist/tools/write.d.ts +5 -0
- package/dist/tools/write.d.ts.map +1 -0
- package/dist/tools/write.js +40 -0
- package/dist/tools/write.js.map +1 -0
- package/dist/types.d.ts +423 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/compact.d.ts +44 -0
- package/dist/utils/compact.d.ts.map +1 -0
- package/dist/utils/compact.js +162 -0
- package/dist/utils/compact.js.map +1 -0
- package/dist/utils/context.d.ts +35 -0
- package/dist/utils/context.d.ts.map +1 -0
- package/dist/utils/context.js +174 -0
- package/dist/utils/context.js.map +1 -0
- package/dist/utils/fileCache.d.ts +64 -0
- package/dist/utils/fileCache.d.ts.map +1 -0
- package/dist/utils/fileCache.js +117 -0
- package/dist/utils/fileCache.js.map +1 -0
- package/dist/utils/messages.d.ts +57 -0
- package/dist/utils/messages.d.ts.map +1 -0
- package/dist/utils/messages.js +152 -0
- package/dist/utils/messages.js.map +1 -0
- package/dist/utils/retry.d.ts +48 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +111 -0
- package/dist/utils/retry.js.map +1 -0
- package/dist/utils/tokens.d.ts +57 -0
- package/dist/utils/tokens.d.ts.map +1 -0
- package/dist/utils/tokens.js +134 -0
- package/dist/utils/tokens.js.map +1 -0
- package/package.json +7 -1
- package/src/agent.ts +106 -15
- package/src/engine.ts +169 -59
- package/src/index.ts +51 -1
- package/src/providers/anthropic.ts +60 -0
- package/src/providers/index.ts +34 -0
- package/src/providers/openai.ts +315 -0
- package/src/providers/types.ts +85 -0
- package/src/session.ts +5 -5
- package/src/skills/bundled/commit.ts +38 -0
- package/src/skills/bundled/debug.ts +48 -0
- package/src/skills/bundled/index.ts +28 -0
- package/src/skills/bundled/review.ts +41 -0
- package/src/skills/bundled/simplify.ts +51 -0
- package/src/skills/bundled/test.ts +43 -0
- package/src/skills/index.ts +25 -0
- package/src/skills/registry.ts +133 -0
- package/src/skills/types.ts +99 -0
- package/src/tools/agent-tool.ts +13 -2
- package/src/tools/index.ts +8 -0
- package/src/tools/skill-tool.ts +133 -0
- package/src/tools/types.ts +7 -3
- package/src/types.ts +35 -8
- package/src/utils/compact.ts +18 -17
- package/src/utils/messages.ts +12 -13
- package/src/utils/tokens.ts +29 -6
- package/.env.example +0 -8
- package/examples/01-simple-query.ts +0 -43
- package/examples/02-multi-tool.ts +0 -44
- package/examples/03-multi-turn.ts +0 -39
- package/examples/04-prompt-api.ts +0 -29
- package/examples/05-custom-system-prompt.ts +0 -26
- package/examples/06-mcp-server.ts +0 -49
- package/examples/07-custom-tools.ts +0 -87
- package/examples/08-official-api-compat.ts +0 -38
- package/examples/09-subagents.ts +0 -48
- package/examples/10-permissions.ts +0 -40
- package/examples/11-custom-mcp-tools.ts +0 -101
- package/examples/web/index.html +0 -365
- package/examples/web/server.ts +0 -157
- package/tsconfig.json +0 -19
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://nodejs.org)
|
|
5
5
|
[](./LICENSE)
|
|
6
6
|
|
|
7
|
-
Open-source Agent SDK that runs the full agent loop **in-process** — no subprocess or CLI required. Deploy anywhere: cloud, serverless, Docker, CI/CD.
|
|
7
|
+
Open-source Agent SDK that runs the full agent loop **in-process** — no subprocess or CLI required. Supports both **Anthropic** and **OpenAI-compatible** APIs. Deploy anywhere: cloud, serverless, Docker, CI/CD.
|
|
8
8
|
|
|
9
9
|
Also available in **Go**: [open-agent-sdk-go](https://github.com/codeany-ai/open-agent-sdk-go)
|
|
10
10
|
|
|
@@ -20,7 +20,18 @@ Set your API key:
|
|
|
20
20
|
export CODEANY_API_KEY=your-api-key
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
### OpenAI-compatible models
|
|
24
|
+
|
|
25
|
+
Works with OpenAI, DeepSeek, Qwen, Mistral, or any OpenAI-compatible endpoint:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
export CODEANY_API_TYPE=openai-completions
|
|
29
|
+
export CODEANY_API_KEY=sk-...
|
|
30
|
+
export CODEANY_BASE_URL=https://api.openai.com/v1
|
|
31
|
+
export CODEANY_MODEL=gpt-4o
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Third-party Anthropic-compatible providers
|
|
24
35
|
|
|
25
36
|
```bash
|
|
26
37
|
export CODEANY_BASE_URL=https://openrouter.ai/api
|
|
@@ -64,6 +75,24 @@ console.log(
|
|
|
64
75
|
);
|
|
65
76
|
```
|
|
66
77
|
|
|
78
|
+
### OpenAI / GPT models
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import { createAgent } from "@codeany/open-agent-sdk";
|
|
82
|
+
|
|
83
|
+
const agent = createAgent({
|
|
84
|
+
apiType: "openai-completions",
|
|
85
|
+
model: "gpt-4o",
|
|
86
|
+
apiKey: "sk-...",
|
|
87
|
+
baseURL: "https://api.openai.com/v1",
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const result = await agent.prompt("What files are in this project?");
|
|
91
|
+
console.log(result.text);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The `apiType` is auto-detected from model name — models containing `gpt-`, `o1`, `o3`, `deepseek`, `qwen`, `mistral`, etc. automatically use `openai-completions`.
|
|
95
|
+
|
|
67
96
|
### Multi-turn conversation
|
|
68
97
|
|
|
69
98
|
```typescript
|
|
@@ -137,6 +166,66 @@ const r = await agent.prompt("Calculate 2**10 * 3");
|
|
|
137
166
|
console.log(r.text);
|
|
138
167
|
```
|
|
139
168
|
|
|
169
|
+
### Skills
|
|
170
|
+
|
|
171
|
+
Skills are reusable prompt templates that extend agent capabilities. Five bundled skills are included: `simplify`, `commit`, `review`, `debug`, `test`.
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
import {
|
|
175
|
+
createAgent,
|
|
176
|
+
registerSkill,
|
|
177
|
+
getAllSkills,
|
|
178
|
+
} from "@codeany/open-agent-sdk";
|
|
179
|
+
|
|
180
|
+
// Register a custom skill
|
|
181
|
+
registerSkill({
|
|
182
|
+
name: "explain",
|
|
183
|
+
description: "Explain a concept in simple terms",
|
|
184
|
+
userInvocable: true,
|
|
185
|
+
async getPrompt(args) {
|
|
186
|
+
return [
|
|
187
|
+
{
|
|
188
|
+
type: "text",
|
|
189
|
+
text: `Explain in simple terms: ${args || "Ask what to explain."}`,
|
|
190
|
+
},
|
|
191
|
+
];
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
console.log(`${getAllSkills().length} skills registered`);
|
|
196
|
+
|
|
197
|
+
// The model can invoke skills via the Skill tool
|
|
198
|
+
const agent = createAgent();
|
|
199
|
+
const result = await agent.prompt('Use the "explain" skill to explain git rebase');
|
|
200
|
+
console.log(result.text);
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Hooks (lifecycle events)
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
import { createAgent, createHookRegistry } from "@codeany/open-agent-sdk";
|
|
207
|
+
|
|
208
|
+
const hooks = createHookRegistry({
|
|
209
|
+
PreToolUse: [
|
|
210
|
+
{
|
|
211
|
+
handler: async (input) => {
|
|
212
|
+
console.log(`About to use: ${input.toolName}`);
|
|
213
|
+
// Return { block: true } to prevent tool execution
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
],
|
|
217
|
+
PostToolUse: [
|
|
218
|
+
{
|
|
219
|
+
handler: async (input) => {
|
|
220
|
+
console.log(`Tool ${input.toolName} completed`);
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
],
|
|
224
|
+
});
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
20 lifecycle events: `PreToolUse`, `PostToolUse`, `PostToolUseFailure`, `SessionStart`, `SessionEnd`, `Stop`, `SubagentStart`, `SubagentStop`, `UserPromptSubmit`, `PermissionRequest`, `PermissionDenied`, `TaskCreated`, `TaskCompleted`, `ConfigChange`, `CwdChanged`, `FileChanged`, `Notification`, `PreCompact`, `PostCompact`, `TeammateIdle`.
|
|
228
|
+
|
|
140
229
|
### MCP server integration
|
|
141
230
|
|
|
142
231
|
```typescript
|
|
@@ -214,9 +303,12 @@ npx tsx examples/web/server.ts
|
|
|
214
303
|
| `tool(name, desc, schema, handler)` | Create a tool with Zod schema validation |
|
|
215
304
|
| `createSdkMcpServer({ name, tools })` | Bundle tools into an in-process MCP server |
|
|
216
305
|
| `defineTool(config)` | Low-level tool definition helper |
|
|
217
|
-
| `getAllBaseTools()` | Get all
|
|
306
|
+
| `getAllBaseTools()` | Get all 35+ built-in tools |
|
|
307
|
+
| `registerSkill(definition)` | Register a custom skill |
|
|
308
|
+
| `getAllSkills()` | Get all registered skills |
|
|
309
|
+
| `createProvider(apiType, opts)` | Create an LLM provider directly |
|
|
310
|
+
| `createHookRegistry(config)` | Create a hook registry for lifecycle events |
|
|
218
311
|
| `listSessions()` | List persisted sessions |
|
|
219
|
-
| `getSessionMessages(id)` | Retrieve messages from a session |
|
|
220
312
|
| `forkSession(id)` | Fork a session for branching |
|
|
221
313
|
|
|
222
314
|
### Agent methods
|
|
@@ -230,12 +322,14 @@ npx tsx examples/web/server.ts
|
|
|
230
322
|
| `agent.interrupt()` | Abort current query |
|
|
231
323
|
| `agent.setModel(model)` | Change model mid-session |
|
|
232
324
|
| `agent.setPermissionMode(mode)` | Change permission mode |
|
|
325
|
+
| `agent.getApiType()` | Get current API type |
|
|
233
326
|
| `agent.close()` | Close MCP connections, persist session |
|
|
234
327
|
|
|
235
328
|
### Options
|
|
236
329
|
|
|
237
330
|
| Option | Type | Default | Description |
|
|
238
331
|
| -------------------- | --------------------------------------- | ---------------------- | -------------------------------------------------------------------- |
|
|
332
|
+
| `apiType` | `string` | auto-detected | `'anthropic-messages'` or `'openai-completions'` |
|
|
239
333
|
| `model` | `string` | `claude-sonnet-4-6` | LLM model ID |
|
|
240
334
|
| `apiKey` | `string` | `CODEANY_API_KEY` | API key |
|
|
241
335
|
| `baseURL` | `string` | — | Custom API endpoint |
|
|
@@ -266,12 +360,13 @@ npx tsx examples/web/server.ts
|
|
|
266
360
|
|
|
267
361
|
### Environment variables
|
|
268
362
|
|
|
269
|
-
| Variable | Description
|
|
270
|
-
| -------------------- |
|
|
271
|
-
| `CODEANY_API_KEY` | API key (required)
|
|
272
|
-
| `
|
|
273
|
-
| `
|
|
274
|
-
| `
|
|
363
|
+
| Variable | Description |
|
|
364
|
+
| -------------------- | -------------------------------------------------------- |
|
|
365
|
+
| `CODEANY_API_KEY` | API key (required) |
|
|
366
|
+
| `CODEANY_API_TYPE` | `anthropic-messages` (default) or `openai-completions` |
|
|
367
|
+
| `CODEANY_MODEL` | Default model override |
|
|
368
|
+
| `CODEANY_BASE_URL` | Custom API endpoint |
|
|
369
|
+
| `CODEANY_AUTH_TOKEN` | Alternative auth token |
|
|
275
370
|
|
|
276
371
|
## Built-in tools
|
|
277
372
|
|
|
@@ -287,6 +382,7 @@ npx tsx examples/web/server.ts
|
|
|
287
382
|
| **WebSearch** | Search the web |
|
|
288
383
|
| **NotebookEdit** | Edit Jupyter notebook cells |
|
|
289
384
|
| **Agent** | Spawn subagents for parallel work |
|
|
385
|
+
| **Skill** | Invoke registered skills |
|
|
290
386
|
| **TaskCreate/List/Update/Get/Stop/Output** | Task management system |
|
|
291
387
|
| **TeamCreate/Delete** | Multi-agent team coordination |
|
|
292
388
|
| **SendMessage** | Inter-agent messaging |
|
|
@@ -301,6 +397,18 @@ npx tsx examples/web/server.ts
|
|
|
301
397
|
| **Config** | Dynamic configuration |
|
|
302
398
|
| **TodoWrite** | Session todo list |
|
|
303
399
|
|
|
400
|
+
## Bundled skills
|
|
401
|
+
|
|
402
|
+
| Skill | Description |
|
|
403
|
+
| ------------ | -------------------------------------------------------------- |
|
|
404
|
+
| `simplify` | Review changed code for reuse, quality, and efficiency |
|
|
405
|
+
| `commit` | Create a git commit with a well-crafted message |
|
|
406
|
+
| `review` | Review code changes for correctness, security, and performance |
|
|
407
|
+
| `debug` | Systematic debugging using structured investigation |
|
|
408
|
+
| `test` | Run tests and analyze failures |
|
|
409
|
+
|
|
410
|
+
Register custom skills with `registerSkill()`.
|
|
411
|
+
|
|
304
412
|
## Architecture
|
|
305
413
|
|
|
306
414
|
```
|
|
@@ -312,7 +420,7 @@ npx tsx examples/web/server.ts
|
|
|
312
420
|
│
|
|
313
421
|
┌──────────▼──────────┐
|
|
314
422
|
│ Agent │ Session state, tool pool,
|
|
315
|
-
│ query() / prompt() │ MCP connections
|
|
423
|
+
│ query() / prompt() │ MCP connections, hooks
|
|
316
424
|
└──────────┬──────────┘
|
|
317
425
|
│
|
|
318
426
|
┌──────────▼──────────┐
|
|
@@ -323,26 +431,28 @@ npx tsx examples/web/server.ts
|
|
|
323
431
|
┌───────────────┼───────────────┐
|
|
324
432
|
│ │ │
|
|
325
433
|
┌─────▼─────┐ ┌─────▼─────┐ ┌─────▼─────┐
|
|
326
|
-
│
|
|
327
|
-
│
|
|
328
|
-
│
|
|
329
|
-
|
|
330
|
-
|
|
434
|
+
│ Provider │ │ 35 Tools │ │ MCP │
|
|
435
|
+
│ Anthropic │ │ Bash,Read │ │ Servers │
|
|
436
|
+
│ OpenAI │ │ Edit,... │ │ stdio/SSE/ │
|
|
437
|
+
│ DeepSeek │ │ + Skills │ │ HTTP/SDK │
|
|
438
|
+
└───────────┘ └───────────┘ └───────────┘
|
|
331
439
|
```
|
|
332
440
|
|
|
333
441
|
**Key internals:**
|
|
334
442
|
|
|
335
|
-
| Component | Description
|
|
336
|
-
| --------------------- |
|
|
337
|
-
| **
|
|
338
|
-
| **
|
|
339
|
-
| **
|
|
340
|
-
| **
|
|
341
|
-
| **
|
|
342
|
-
| **
|
|
343
|
-
| **
|
|
344
|
-
| **
|
|
345
|
-
| **
|
|
443
|
+
| Component | Description |
|
|
444
|
+
| --------------------- | ------------------------------------------------------------------ |
|
|
445
|
+
| **Provider layer** | Abstracts Anthropic / OpenAI API differences |
|
|
446
|
+
| **QueryEngine** | Core agentic loop with auto-compact, retry, tool orchestration |
|
|
447
|
+
| **Skill system** | Reusable prompt templates with 5 bundled skills |
|
|
448
|
+
| **Hook system** | 20 lifecycle events integrated into the engine |
|
|
449
|
+
| **Auto-compact** | Summarizes conversation when context window fills up |
|
|
450
|
+
| **Micro-compact** | Truncates oversized tool results |
|
|
451
|
+
| **Retry** | Exponential backoff for rate limits and transient errors |
|
|
452
|
+
| **Token estimation** | Rough token counting with pricing for Claude, GPT, DeepSeek models |
|
|
453
|
+
| **File cache** | LRU cache (100 entries, 25 MB) for file reads |
|
|
454
|
+
| **Session storage** | Persist / resume / fork sessions on disk |
|
|
455
|
+
| **Context injection** | Git status + AGENT.md automatically injected into system prompt |
|
|
346
456
|
|
|
347
457
|
## Examples
|
|
348
458
|
|
|
@@ -359,6 +469,9 @@ npx tsx examples/web/server.ts
|
|
|
359
469
|
| 09 | `examples/09-subagents.ts` | Subagent delegation |
|
|
360
470
|
| 10 | `examples/10-permissions.ts` | Read-only agent with tool restrictions |
|
|
361
471
|
| 11 | `examples/11-custom-mcp-tools.ts` | `tool()` + `createSdkMcpServer()` |
|
|
472
|
+
| 12 | `examples/12-skills.ts` | Skill system usage |
|
|
473
|
+
| 13 | `examples/13-hooks.ts` | Lifecycle hooks |
|
|
474
|
+
| 14 | `examples/14-openai-compat.ts` | OpenAI / DeepSeek models |
|
|
362
475
|
| web | `examples/web/` | Web chat UI for testing |
|
|
363
476
|
|
|
364
477
|
Run any example:
|
|
@@ -375,11 +488,11 @@ npx tsx examples/web/server.ts
|
|
|
375
488
|
|
|
376
489
|
## Star History
|
|
377
490
|
|
|
378
|
-
<a href="https://www.star-history.com/?repos=
|
|
491
|
+
<a href="https://www.star-history.com/?repos=codeany-ai%2Fopen-agent-sdk-typescript&type=timeline&legend=top-left">
|
|
379
492
|
<picture>
|
|
380
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/image?repos=
|
|
381
|
-
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/image?repos=
|
|
382
|
-
<img alt="Star History Chart" src="https://api.star-history.com/image?repos=
|
|
493
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/image?repos=codeany-ai/open-agent-sdk-typescript&type=timeline&theme=dark&legend=top-left" />
|
|
494
|
+
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/image?repos=codeany-ai/open-agent-sdk-typescript&type=timeline&legend=top-left" />
|
|
495
|
+
<img alt="Star History Chart" src="https://api.star-history.com/image?repos=codeany-ai/open-agent-sdk-typescript&type=timeline&legend=top-left" />
|
|
383
496
|
</picture>
|
|
384
497
|
</a>
|
|
385
498
|
|
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent - High-level API
|
|
3
|
+
*
|
|
4
|
+
* Provides createAgent() and query() interfaces compatible with
|
|
5
|
+
* open-agent-sdk.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* import { createAgent } from 'open-agent-sdk'
|
|
9
|
+
* const agent = createAgent({ model: 'claude-sonnet-4-6' })
|
|
10
|
+
* for await (const event of agent.query('Hello')) { ... }
|
|
11
|
+
*
|
|
12
|
+
* // OpenAI-compatible models
|
|
13
|
+
* const agent = createAgent({
|
|
14
|
+
* apiType: 'openai-completions',
|
|
15
|
+
* model: 'gpt-4o',
|
|
16
|
+
* apiKey: 'sk-...',
|
|
17
|
+
* baseURL: 'https://api.openai.com/v1',
|
|
18
|
+
* })
|
|
19
|
+
*/
|
|
20
|
+
import type { AgentOptions, QueryResult, SDKMessage, Message, PermissionMode } from './types.js';
|
|
21
|
+
import { type ApiType } from './providers/index.js';
|
|
22
|
+
export declare class Agent {
|
|
23
|
+
private cfg;
|
|
24
|
+
private toolPool;
|
|
25
|
+
private modelId;
|
|
26
|
+
private apiType;
|
|
27
|
+
private apiCredentials;
|
|
28
|
+
private provider;
|
|
29
|
+
private mcpLinks;
|
|
30
|
+
private history;
|
|
31
|
+
private messageLog;
|
|
32
|
+
private setupDone;
|
|
33
|
+
private sid;
|
|
34
|
+
private abortCtrl;
|
|
35
|
+
private currentEngine;
|
|
36
|
+
private hookRegistry;
|
|
37
|
+
constructor(options?: AgentOptions);
|
|
38
|
+
/**
|
|
39
|
+
* Resolve API type from options, env, or model name heuristic.
|
|
40
|
+
*/
|
|
41
|
+
private resolveApiType;
|
|
42
|
+
/** Pick API key and base URL from options or CODEANY_* env vars. */
|
|
43
|
+
private pickCredentials;
|
|
44
|
+
/** Read a value from process.env (returns undefined if missing). */
|
|
45
|
+
private readEnv;
|
|
46
|
+
/** Assemble the available tool set based on options. */
|
|
47
|
+
private buildToolPool;
|
|
48
|
+
/**
|
|
49
|
+
* Async initialization: connect MCP servers, register agents, resume sessions.
|
|
50
|
+
*/
|
|
51
|
+
private setup;
|
|
52
|
+
/**
|
|
53
|
+
* Run a query with streaming events.
|
|
54
|
+
*/
|
|
55
|
+
query(prompt: string, overrides?: Partial<AgentOptions>): AsyncGenerator<SDKMessage, void>;
|
|
56
|
+
/**
|
|
57
|
+
* Convenience method: send a prompt and collect the final answer as a single object.
|
|
58
|
+
* Internally iterates through the streaming query and aggregates the outcome.
|
|
59
|
+
*/
|
|
60
|
+
prompt(text: string, overrides?: Partial<AgentOptions>): Promise<QueryResult>;
|
|
61
|
+
/**
|
|
62
|
+
* Get conversation messages.
|
|
63
|
+
*/
|
|
64
|
+
getMessages(): Message[];
|
|
65
|
+
/**
|
|
66
|
+
* Reset conversation history.
|
|
67
|
+
*/
|
|
68
|
+
clear(): void;
|
|
69
|
+
/**
|
|
70
|
+
* Interrupt the current query.
|
|
71
|
+
*/
|
|
72
|
+
interrupt(): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Change the model during a session.
|
|
75
|
+
*/
|
|
76
|
+
setModel(model?: string): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Change the permission mode during a session.
|
|
79
|
+
*/
|
|
80
|
+
setPermissionMode(mode: PermissionMode): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Set maximum thinking tokens.
|
|
83
|
+
*/
|
|
84
|
+
setMaxThinkingTokens(maxThinkingTokens: number | null): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Get the session ID.
|
|
87
|
+
*/
|
|
88
|
+
getSessionId(): string;
|
|
89
|
+
/**
|
|
90
|
+
* Get the current API type.
|
|
91
|
+
*/
|
|
92
|
+
getApiType(): ApiType;
|
|
93
|
+
/**
|
|
94
|
+
* Stop a background task.
|
|
95
|
+
*/
|
|
96
|
+
stopTask(taskId: string): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Close MCP connections and clean up.
|
|
99
|
+
* Optionally persist session to disk.
|
|
100
|
+
*/
|
|
101
|
+
close(): Promise<void>;
|
|
102
|
+
}
|
|
103
|
+
/** Factory: shorthand for `new Agent(options)`. */
|
|
104
|
+
export declare function createAgent(options?: AgentOptions): Agent;
|
|
105
|
+
/**
|
|
106
|
+
* Execute a single agentic query without managing an Agent instance.
|
|
107
|
+
* The agent is created, used, and cleaned up automatically.
|
|
108
|
+
*/
|
|
109
|
+
export declare function query(params: {
|
|
110
|
+
prompt: string;
|
|
111
|
+
options?: AgentOptions;
|
|
112
|
+
}): AsyncGenerator<SDKMessage, void>;
|
|
113
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,UAAU,EAGV,OAAO,EACP,cAAc,EACf,MAAM,YAAY,CAAA;AAYnB,OAAO,EAAoC,KAAK,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAOrF,qBAAa,KAAK;IAChB,OAAO,CAAC,GAAG,CAAc;IACzB,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,cAAc,CAAoC;IAC1D,OAAO,CAAC,QAAQ,CAAa;IAC7B,OAAO,CAAC,QAAQ,CAAsB;IACtC,OAAO,CAAC,OAAO,CAA+B;IAC9C,OAAO,CAAC,UAAU,CAAgB;IAClC,OAAO,CAAC,SAAS,CAAe;IAChC,OAAO,CAAC,GAAG,CAAQ;IACnB,OAAO,CAAC,SAAS,CAA+B;IAChD,OAAO,CAAC,aAAa,CAA2B;IAChD,OAAO,CAAC,YAAY,CAAc;gBAEtB,OAAO,GAAE,YAAiB;IAkDtC;;OAEG;IACH,OAAO,CAAC,cAAc;IAgCtB,oEAAoE;IACpE,OAAO,CAAC,eAAe;IAgBvB,oEAAoE;IACpE,OAAO,CAAC,OAAO;IAIf,wDAAwD;IACxD,OAAO,CAAC,aAAa;IAerB;;OAEG;YACW,KAAK;IAsCnB;;OAEG;IACI,KAAK,CACV,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAChC,cAAc,CAAC,UAAU,EAAE,IAAI,CAAC;IAqHnC;;;OAGG;IACG,MAAM,CACV,IAAI,EAAE,MAAM,EACZ,SAAS,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAChC,OAAO,CAAC,WAAW,CAAC;IA+BvB;;OAEG;IACH,WAAW,IAAI,OAAO,EAAE;IAIxB;;OAEG;IACH,KAAK,IAAI,IAAI;IAKb;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAIhC;;OAEG;IACG,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO7C;;OAEG;IACG,iBAAiB,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5D;;OAEG;IACG,oBAAoB,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ3E;;OAEG;IACH,YAAY,IAAI,MAAM;IAItB;;OAEG;IACH,UAAU,IAAI,OAAO;IAIrB;;OAEG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ7C;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAmB7B;AAMD,mDAAmD;AACnD,wBAAgB,WAAW,CAAC,OAAO,GAAE,YAAiB,GAAG,KAAK,CAE7D;AAMD;;;GAGG;AACH,wBAAuB,KAAK,CAAC,MAAM,EAAE;IACnC,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,YAAY,CAAA;CACvB,GAAG,cAAc,CAAC,UAAU,EAAE,IAAI,CAAC,CAOnC"}
|