toolpack-sdk 3.3.0 → 3.5.0
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 +45 -3
- package/dist/index.cjs +171 -171
- package/dist/index.d.cts +66 -5
- package/dist/index.d.ts +66 -5
- package/dist/index.js +172 -172
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -574,6 +574,48 @@ await sdk.loadToolProjects([myToolProject]);
|
|
|
574
574
|
| `tools` | ToolDefinition[] | ✓ | Array of tool definitions |
|
|
575
575
|
| `dependencies` | Record<string, string> | | npm dependencies (validated at load) |
|
|
576
576
|
|
|
577
|
+
### Tool Context and `actor`
|
|
578
|
+
|
|
579
|
+
Every tool's `execute` receives a context as its second argument. Besides `workspaceRoot` and `config`, it carries `ctx.actor`: who the run acts for (for example the signed-in user). The host sets it with the `actor` init option; the model never sees or sets it, so a tool can trust it for per-user data.
|
|
580
|
+
|
|
581
|
+
```typescript
|
|
582
|
+
const sdk = await Toolpack.init({
|
|
583
|
+
provider: 'openai',
|
|
584
|
+
tools: true,
|
|
585
|
+
actor: { id: 'user_123', kind: 'user' },
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
// In a tool:
|
|
589
|
+
execute: async (args, ctx) => {
|
|
590
|
+
const userId = ctx.actor?.id; // undefined when no actor was set
|
|
591
|
+
// load only this user's data
|
|
592
|
+
}
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
When one instance serves several people, pass a function (read on every tool call), for example `actor: () => requestStore.getStore() ?? null`.
|
|
596
|
+
|
|
597
|
+
### Stopping a request
|
|
598
|
+
|
|
599
|
+
Pass an `AbortSignal` as `signal` on a request. A stop takes effect at once, also in the middle of a provider call, a rate limit wait, or a tool.
|
|
600
|
+
|
|
601
|
+
```typescript
|
|
602
|
+
const controller = new AbortController();
|
|
603
|
+
stopButton.onclick = () => controller.abort(); // or a timeout, a newer message
|
|
604
|
+
|
|
605
|
+
for await (const chunk of sdk.stream({ model, messages, signal: controller.signal })) {
|
|
606
|
+
if (chunk.finish_reason === 'aborted') break; // stopped: what arrived before is kept
|
|
607
|
+
process.stdout.write(chunk.delta);
|
|
608
|
+
}
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
- `stream()` ends without throwing; its last chunk has `finish_reason: 'aborted'`
|
|
612
|
+
- `generate()` rejects with an `AbortedError` (`name` is `'AbortError'`, exported from the package root)
|
|
613
|
+
- Tools that have not started are not run. A tool can read `ctx.signal` to end its own long work early, for example `fetch(url, { signal: ctx.signal })`
|
|
614
|
+
|
|
615
|
+
### Returning files from tools
|
|
616
|
+
|
|
617
|
+
A tool can return a file by URL with `{ "type": "file", "mimeType": "application/pdf", "url": "https://..." }`. Anthropic and Vertex AI receive it as a native file part, and OpenAI receives images (other files get a placeholder). `data:` URIs keep working as before.
|
|
618
|
+
|
|
577
619
|
## Knowledge & RAG (Retrieval-Augmented Generation)
|
|
578
620
|
|
|
579
621
|
For AI applications that need to search and reference documentation, use the companion `@toolpack-sdk/knowledge` package:
|
|
@@ -1176,7 +1218,7 @@ const sdk = await Toolpack.init({
|
|
|
1176
1218
|
|--------|------|---------|-------------|
|
|
1177
1219
|
| `enabled` | boolean | `true` | Enable/disable the tool system entirely |
|
|
1178
1220
|
| `autoExecute` | boolean | `true` | Auto-execute tool calls from AI |
|
|
1179
|
-
| `maxToolRounds` | number | `5` | Max tool execution rounds per request |
|
|
1221
|
+
| `maxToolRounds` | number | `5` | Max tool execution rounds per request. When the cap is hit with tools still pending, the model gets one final text-only round to wrap up |
|
|
1180
1222
|
| `toolChoicePolicy` | string | `"auto"` | `"auto"`, `"required"`, or `"required_for_actions"` |
|
|
1181
1223
|
| `resultMaxChars` | number | `20000` | Max characters in a tool result |
|
|
1182
1224
|
| `enabledTools` | string[] | `[]` | Whitelist specific tools (empty = all) |
|
|
@@ -1250,7 +1292,7 @@ import { Toolpack } from 'toolpack-sdk';
|
|
|
1250
1292
|
// modeOverrides → configure modes directly via registerMode()
|
|
1251
1293
|
// configPath → configuration is now passed inline to Toolpack.init()
|
|
1252
1294
|
//
|
|
1253
|
-
// Fields: logging, hitl, toolsConfig, toolOverrides (v3.1.0)
|
|
1295
|
+
// Fields: logging, hitl, toolsConfig, toolOverrides (v3.1.0), actor and disableToolGuidance (v3.4.0)
|
|
1254
1296
|
const sdk = await Toolpack.init(config: ToolpackInitConfig): Promise<Toolpack>
|
|
1255
1297
|
|
|
1256
1298
|
// Completions (routes through workflow engine if mode has workflow enabled)
|
|
@@ -1316,7 +1358,7 @@ interface CompletionResponse {
|
|
|
1316
1358
|
interface CompletionChunk {
|
|
1317
1359
|
delta: string;
|
|
1318
1360
|
usage?: Usage;
|
|
1319
|
-
finish_reason?: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'error';
|
|
1361
|
+
finish_reason?: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'error' | 'aborted'; // 'aborted': stopped by the request's signal
|
|
1320
1362
|
tool_calls?: ToolCallResult[];
|
|
1321
1363
|
}
|
|
1322
1364
|
|