toolpack-sdk 3.4.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 +19 -1
- package/dist/index.cjs +150 -150
- package/dist/index.d.cts +26 -3
- package/dist/index.d.ts +26 -3
- package/dist/index.js +147 -147
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -594,6 +594,24 @@ execute: async (args, ctx) => {
|
|
|
594
594
|
|
|
595
595
|
When one instance serves several people, pass a function (read on every tool call), for example `actor: () => requestStore.getStore() ?? null`.
|
|
596
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
|
+
|
|
597
615
|
### Returning files from tools
|
|
598
616
|
|
|
599
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.
|
|
@@ -1340,7 +1358,7 @@ interface CompletionResponse {
|
|
|
1340
1358
|
interface CompletionChunk {
|
|
1341
1359
|
delta: string;
|
|
1342
1360
|
usage?: Usage;
|
|
1343
|
-
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
|
|
1344
1362
|
tool_calls?: ToolCallResult[];
|
|
1345
1363
|
}
|
|
1346
1364
|
|