@anthropic-ai/sdk 0.62.0 → 0.63.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/CHANGELOG.md +29 -0
- package/README.md +47 -12
- package/helpers/beta/json-schema.d.mts +19 -0
- package/helpers/beta/json-schema.d.mts.map +1 -0
- package/helpers/beta/json-schema.d.ts +19 -0
- package/helpers/beta/json-schema.d.ts.map +1 -0
- package/helpers/beta/json-schema.js +22 -0
- package/helpers/beta/json-schema.js.map +1 -0
- package/helpers/beta/json-schema.mjs +19 -0
- package/helpers/beta/json-schema.mjs.map +1 -0
- package/helpers/beta/zod.d.mts +16 -0
- package/helpers/beta/zod.d.mts.map +1 -0
- package/helpers/beta/zod.d.ts +16 -0
- package/helpers/beta/zod.d.ts.map +1 -0
- package/helpers/beta/zod.js +28 -0
- package/helpers/beta/zod.js.map +1 -0
- package/helpers/beta/zod.mjs +24 -0
- package/helpers/beta/zod.mjs.map +1 -0
- package/internal/utils/values.js +3 -3
- package/internal/utils/values.js.map +1 -1
- package/internal/utils/values.mjs +3 -3
- package/internal/utils/values.mjs.map +1 -1
- package/lib/tools/BetaRunnableTool.d.mts +7 -0
- package/lib/tools/BetaRunnableTool.d.mts.map +1 -0
- package/lib/tools/BetaRunnableTool.d.ts +7 -0
- package/lib/tools/BetaRunnableTool.d.ts.map +1 -0
- package/lib/tools/BetaRunnableTool.js +3 -0
- package/lib/tools/BetaRunnableTool.js.map +1 -0
- package/lib/tools/BetaRunnableTool.mjs +2 -0
- package/lib/tools/BetaRunnableTool.mjs.map +1 -0
- package/lib/tools/BetaToolRunner.d.mts +132 -0
- package/lib/tools/BetaToolRunner.d.mts.map +1 -0
- package/lib/tools/BetaToolRunner.d.ts +132 -0
- package/lib/tools/BetaToolRunner.d.ts.map +1 -0
- package/lib/tools/BetaToolRunner.js +288 -0
- package/lib/tools/BetaToolRunner.js.map +1 -0
- package/lib/tools/BetaToolRunner.mjs +284 -0
- package/lib/tools/BetaToolRunner.mjs.map +1 -0
- package/lib/tools/ToolRunner.d.mts +132 -0
- package/lib/tools/ToolRunner.d.mts.map +1 -0
- package/lib/tools/ToolRunner.d.ts +132 -0
- package/lib/tools/ToolRunner.d.ts.map +1 -0
- package/lib/tools/ToolRunner.js +288 -0
- package/lib/tools/ToolRunner.js.map +1 -0
- package/lib/tools/ToolRunner.mjs +284 -0
- package/lib/tools/ToolRunner.mjs.map +1 -0
- package/package.json +22 -2
- package/resources/beta/beta.d.mts +2 -2
- package/resources/beta/beta.d.mts.map +1 -1
- package/resources/beta/beta.d.ts +2 -2
- package/resources/beta/beta.d.ts.map +1 -1
- package/resources/beta/beta.js.map +1 -1
- package/resources/beta/beta.mjs.map +1 -1
- package/resources/beta/index.d.mts +1 -1
- package/resources/beta/index.d.mts.map +1 -1
- package/resources/beta/index.d.ts +1 -1
- package/resources/beta/index.d.ts.map +1 -1
- package/resources/beta/index.js.map +1 -1
- package/resources/beta/index.mjs.map +1 -1
- package/resources/beta/messages/index.d.mts +2 -1
- package/resources/beta/messages/index.d.mts.map +1 -1
- package/resources/beta/messages/index.d.ts +2 -1
- package/resources/beta/messages/index.d.ts.map +1 -1
- package/resources/beta/messages/index.js +3 -1
- package/resources/beta/messages/index.js.map +1 -1
- package/resources/beta/messages/index.mjs +1 -0
- package/resources/beta/messages/index.mjs.map +1 -1
- package/resources/beta/messages/messages.d.mts +13 -2
- package/resources/beta/messages/messages.d.mts.map +1 -1
- package/resources/beta/messages/messages.d.ts +13 -2
- package/resources/beta/messages/messages.d.ts.map +1 -1
- package/resources/beta/messages/messages.js +9 -2
- package/resources/beta/messages/messages.js.map +1 -1
- package/resources/beta/messages/messages.mjs +7 -1
- package/resources/beta/messages/messages.mjs.map +1 -1
- package/src/helpers/beta/json-schema.ts +32 -0
- package/src/helpers/beta/zod.ts +35 -0
- package/src/internal/utils/values.ts +3 -3
- package/src/lib/tools/BetaRunnableTool.ts +10 -0
- package/src/lib/tools/BetaToolRunner.ts +374 -0
- package/src/lib/tools/ToolRunner.ts +374 -0
- package/src/resources/beta/beta.ts +2 -0
- package/src/resources/beta/index.ts +1 -0
- package/src/resources/beta/messages/index.ts +2 -0
- package/src/resources/beta/messages/messages.ts +20 -2
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.63.1 (2025-09-23)
|
|
4
|
+
|
|
5
|
+
Full Changelog: [sdk-v0.63.0...sdk-v0.63.1](https://github.com/anthropics/anthropic-sdk-typescript/compare/sdk-v0.63.0...sdk-v0.63.1)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
* **helpers/zod:** fix compat with zod 3 ([a2952e1](https://github.com/anthropics/anthropic-sdk-typescript/commit/a2952e1a64e4dfb2a03f90c9af4e816627bf85e7))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Chores
|
|
13
|
+
|
|
14
|
+
* do not install brew dependencies in ./scripts/bootstrap by default ([115d81a](https://github.com/anthropics/anthropic-sdk-typescript/commit/115d81aef0623746220fb13c58c4ba87603a511d))
|
|
15
|
+
* **internal:** update CI ([dfa991a](https://github.com/anthropics/anthropic-sdk-typescript/commit/dfa991aca8f4cbbbf5af8ea32bb5be0a8dae1ace))
|
|
16
|
+
* **package:** lower zod peer dependency constraints ([b40cfec](https://github.com/anthropics/anthropic-sdk-typescript/commit/b40cfeca234432f9a0b1b3ddd8b90c29ff25be02))
|
|
17
|
+
|
|
18
|
+
## 0.63.0 (2025-09-17)
|
|
19
|
+
|
|
20
|
+
Full Changelog: [sdk-v0.62.0...sdk-v0.63.0](https://github.com/anthropics/anthropic-sdk-typescript/compare/sdk-v0.62.0...sdk-v0.63.0)
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* **client:** add support for toolRunner helpers ([28f5837](https://github.com/anthropics/anthropic-sdk-typescript/commit/28f583739d4f15c202ecc88002cd8abc9d3aed76))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Chores
|
|
28
|
+
|
|
29
|
+
* **internal:** fix tests ([003617d](https://github.com/anthropics/anthropic-sdk-typescript/commit/003617d1b1386bbddadb102e0e8e7922d23c1643))
|
|
30
|
+
* **vertex:** update model string to valid example ([7b77da0](https://github.com/anthropics/anthropic-sdk-typescript/commit/7b77da02620a886b50d984a797a74b650ea88181))
|
|
31
|
+
|
|
3
32
|
## 0.62.0 (2025-09-10)
|
|
4
33
|
|
|
5
34
|
Full Changelog: [sdk-v0.61.0...sdk-v0.62.0](https://github.com/anthropics/anthropic-sdk-typescript/compare/sdk-v0.61.0...sdk-v0.62.0)
|
package/README.md
CHANGED
|
@@ -124,6 +124,39 @@ Streaming with `client.messages.stream(...)` exposes [various helpers for your c
|
|
|
124
124
|
|
|
125
125
|
Alternatively, you can use `client.messages.create({ ..., stream: true })` which only returns an async iterable of the events in the stream and thus uses less memory (it does not build up a final message object for you).
|
|
126
126
|
|
|
127
|
+
## Tool Helpers
|
|
128
|
+
|
|
129
|
+
This SDK provides helpers for making it easy to create and run tools in the Messages API. You can use Zod schemas or JSON Schemas to describe the input to a tool. You can then run those tools using the `client.messages.toolRunner()` method. This method will handle passing the inputs generated by the chosen model into the right tool and passing the result back to the model.
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
133
|
+
|
|
134
|
+
import { betaZodTool } from '@anthropic-ai/sdk/helpers';
|
|
135
|
+
import { z } from 'zod';
|
|
136
|
+
|
|
137
|
+
const anthropic = new Anthropic();
|
|
138
|
+
|
|
139
|
+
const weatherTool = betaZodTool({
|
|
140
|
+
name: 'get_weather',
|
|
141
|
+
inputSchema: z.object({
|
|
142
|
+
location: z.string(),
|
|
143
|
+
}),
|
|
144
|
+
description: 'Get the current weather in a given location',
|
|
145
|
+
run: (input) => {
|
|
146
|
+
return `The weather in ${input.location} is foggy and 60°F`;
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const finalMessage = await anthropic.beta.messages.toolRunner({
|
|
151
|
+
model: 'claude-3-5-sonnet-20241022',
|
|
152
|
+
max_tokens: 1000,
|
|
153
|
+
messages: [{ role: 'user', content: 'What is the weather in San Francisco?' }],
|
|
154
|
+
tools: [weatherTool],
|
|
155
|
+
});
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
You can find more details on how to use these tool helpers [here](helpers.md#tool-helpers).
|
|
159
|
+
|
|
127
160
|
## Message Batches
|
|
128
161
|
|
|
129
162
|
This SDK provides support for the [Message Batches API](https://docs.anthropic.com/en/docs/build-with-claude/message-batches) under the `client.messages.batches` namespace.
|
|
@@ -611,37 +644,39 @@ const client = new Anthropic({
|
|
|
611
644
|
```
|
|
612
645
|
|
|
613
646
|
### Beta Features
|
|
614
|
-
|
|
647
|
+
|
|
648
|
+
We introduce beta features before they are generally available to get early feedback and test new functionality. You can check the availability of all of Claude's capabilities and tools [here](https://docs.anthropic.com/en/docs/build-with-claude/overview).
|
|
615
649
|
|
|
616
650
|
You can access most beta API features through the beta property of the client. To enable a particular beta feature, you need to add the appropriate [beta header](https://docs.anthropic.com/en/api/beta-headers) to the `betas` field when creating a message.
|
|
617
651
|
|
|
618
652
|
For example, to use code execution:
|
|
653
|
+
|
|
619
654
|
```ts
|
|
620
655
|
import Anthropic from 'npm:@anthropic-ai/sdk';
|
|
621
656
|
|
|
622
657
|
const client = new Anthropic();
|
|
623
658
|
const response = await client.beta.messages.create({
|
|
624
659
|
max_tokens: 1024,
|
|
625
|
-
model:
|
|
660
|
+
model: 'claude-sonnet-4-20250514',
|
|
626
661
|
messages: [
|
|
627
662
|
{
|
|
628
|
-
role:
|
|
663
|
+
role: 'user',
|
|
629
664
|
content: [
|
|
630
665
|
{
|
|
631
|
-
type:
|
|
666
|
+
type: 'text',
|
|
632
667
|
text: "What's 4242424242 * 4242424242?.",
|
|
633
|
-
}
|
|
634
|
-
]
|
|
635
|
-
}
|
|
668
|
+
},
|
|
669
|
+
],
|
|
670
|
+
},
|
|
636
671
|
],
|
|
637
672
|
tools: [
|
|
638
673
|
{
|
|
639
|
-
name:
|
|
640
|
-
type:
|
|
641
|
-
}
|
|
674
|
+
name: 'code_execution',
|
|
675
|
+
type: 'code_execution_20250522',
|
|
676
|
+
},
|
|
642
677
|
],
|
|
643
|
-
betas: [
|
|
644
|
-
})
|
|
678
|
+
betas: ['code-execution-2025-05-22'],
|
|
679
|
+
});
|
|
645
680
|
```
|
|
646
681
|
|
|
647
682
|
## Frequently Asked Questions
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
2
|
+
import { Promisable, BetaRunnableTool } from "../../lib/tools/BetaRunnableTool.mjs";
|
|
3
|
+
import { BetaToolResultContentBlockParam } from "../../resources/beta.mjs";
|
|
4
|
+
type NoInfer<T> = T extends infer R ? R : never;
|
|
5
|
+
/**
|
|
6
|
+
* Creates a Tool with a provided JSON schema that can be passed
|
|
7
|
+
* to the `.toolRunner()` method. The schema is used to automatically validate
|
|
8
|
+
* the input arguments for the tool.
|
|
9
|
+
*/
|
|
10
|
+
export declare function betaTool<const Schema extends Exclude<JSONSchema, boolean> & {
|
|
11
|
+
type: 'object';
|
|
12
|
+
}>(options: {
|
|
13
|
+
name: string;
|
|
14
|
+
inputSchema: Schema;
|
|
15
|
+
description: string;
|
|
16
|
+
run: (args: NoInfer<FromSchema<Schema>>) => Promisable<string | Array<BetaToolResultContentBlockParam>>;
|
|
17
|
+
}): BetaRunnableTool<NoInfer<FromSchema<Schema>>>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=json-schema.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-schema.d.mts","sourceRoot":"","sources":["../../src/helpers/beta/json-schema.ts"],"names":[],"mappings":"OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB;OACnD,EAAE,UAAU,EAAE,gBAAgB,EAAE;OAChC,EAAE,+BAA+B,EAAE;AAE1C,KAAK,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAEhD;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,CAAC,MAAM,SAAS,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,EAAE,OAAO,EAAE;IACxG,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,KAAK,UAAU,CAAC,MAAM,GAAG,KAAK,CAAC,+BAA+B,CAAC,CAAC,CAAC;CACzG,GAAG,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAehD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
2
|
+
import { Promisable, BetaRunnableTool } from "../../lib/tools/BetaRunnableTool.js";
|
|
3
|
+
import { BetaToolResultContentBlockParam } from "../../resources/beta.js";
|
|
4
|
+
type NoInfer<T> = T extends infer R ? R : never;
|
|
5
|
+
/**
|
|
6
|
+
* Creates a Tool with a provided JSON schema that can be passed
|
|
7
|
+
* to the `.toolRunner()` method. The schema is used to automatically validate
|
|
8
|
+
* the input arguments for the tool.
|
|
9
|
+
*/
|
|
10
|
+
export declare function betaTool<const Schema extends Exclude<JSONSchema, boolean> & {
|
|
11
|
+
type: 'object';
|
|
12
|
+
}>(options: {
|
|
13
|
+
name: string;
|
|
14
|
+
inputSchema: Schema;
|
|
15
|
+
description: string;
|
|
16
|
+
run: (args: NoInfer<FromSchema<Schema>>) => Promisable<string | Array<BetaToolResultContentBlockParam>>;
|
|
17
|
+
}): BetaRunnableTool<NoInfer<FromSchema<Schema>>>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=json-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-schema.d.ts","sourceRoot":"","sources":["../../src/helpers/beta/json-schema.ts"],"names":[],"mappings":"OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB;OACnD,EAAE,UAAU,EAAE,gBAAgB,EAAE;OAChC,EAAE,+BAA+B,EAAE;AAE1C,KAAK,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAEhD;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,CAAC,MAAM,SAAS,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,EAAE,OAAO,EAAE;IACxG,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,KAAK,UAAU,CAAC,MAAM,GAAG,KAAK,CAAC,+BAA+B,CAAC,CAAC,CAAC;CACzG,GAAG,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAehD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.betaTool = betaTool;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a Tool with a provided JSON schema that can be passed
|
|
6
|
+
* to the `.toolRunner()` method. The schema is used to automatically validate
|
|
7
|
+
* the input arguments for the tool.
|
|
8
|
+
*/
|
|
9
|
+
function betaTool(options) {
|
|
10
|
+
if (options.inputSchema.type !== 'object') {
|
|
11
|
+
throw new Error(`JSON schema for tool "${options.name}" must be an object, but got ${options.inputSchema.type}`);
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
type: 'custom',
|
|
15
|
+
name: options.name,
|
|
16
|
+
input_schema: options.inputSchema,
|
|
17
|
+
description: options.description,
|
|
18
|
+
run: options.run,
|
|
19
|
+
parse: (content) => content,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=json-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-schema.js","sourceRoot":"","sources":["../../src/helpers/beta/json-schema.ts"],"names":[],"mappings":";;AAWA,4BAoBC;AAzBD;;;;GAIG;AACH,SAAgB,QAAQ,CAAyE,OAKhG;IACC,IAAI,OAAO,CAAC,WAAW,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CACb,yBAAyB,OAAO,CAAC,IAAI,gCAAgC,OAAO,CAAC,WAAW,CAAC,IAAI,EAAE,CAChG,CAAC;IACJ,CAAC;IAED,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,YAAY,EAAE,OAAO,CAAC,WAAW;QACjC,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,KAAK,EAAE,CAAC,OAAgB,EAAE,EAAE,CAAC,OAA6B;KACpD,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a Tool with a provided JSON schema that can be passed
|
|
3
|
+
* to the `.toolRunner()` method. The schema is used to automatically validate
|
|
4
|
+
* the input arguments for the tool.
|
|
5
|
+
*/
|
|
6
|
+
export function betaTool(options) {
|
|
7
|
+
if (options.inputSchema.type !== 'object') {
|
|
8
|
+
throw new Error(`JSON schema for tool "${options.name}" must be an object, but got ${options.inputSchema.type}`);
|
|
9
|
+
}
|
|
10
|
+
return {
|
|
11
|
+
type: 'custom',
|
|
12
|
+
name: options.name,
|
|
13
|
+
input_schema: options.inputSchema,
|
|
14
|
+
description: options.description,
|
|
15
|
+
run: options.run,
|
|
16
|
+
parse: (content) => content,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=json-schema.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-schema.mjs","sourceRoot":"","sources":["../../src/helpers/beta/json-schema.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAyE,OAKhG;IACC,IAAI,OAAO,CAAC,WAAW,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CACb,yBAAyB,OAAO,CAAC,IAAI,gCAAgC,OAAO,CAAC,WAAW,CAAC,IAAI,EAAE,CAChG,CAAC;IACJ,CAAC;IAED,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,YAAY,EAAE,OAAO,CAAC,WAAW;QACjC,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,KAAK,EAAE,CAAC,OAAgB,EAAE,EAAE,CAAC,OAA6B;KACpD,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { infer as zodInfer, ZodType } from 'zod/v4';
|
|
2
|
+
import { Promisable, BetaRunnableTool } from "../../lib/tools/BetaRunnableTool.mjs";
|
|
3
|
+
import { BetaToolResultContentBlockParam } from "../../resources/beta.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a tool using the provided Zod schema that can be passed
|
|
6
|
+
* into the `.toolRunner()` method. The Zod schema will automatically be
|
|
7
|
+
* converted into JSON Schema when passed to the API. The provided function's
|
|
8
|
+
* input arguments will also be validated against the provided schema.
|
|
9
|
+
*/
|
|
10
|
+
export declare function betaZodTool<InputSchema extends ZodType>(options: {
|
|
11
|
+
name: string;
|
|
12
|
+
inputSchema: InputSchema;
|
|
13
|
+
description: string;
|
|
14
|
+
run: (args: zodInfer<InputSchema>) => Promisable<string | Array<BetaToolResultContentBlockParam>>;
|
|
15
|
+
}): BetaRunnableTool<zodInfer<InputSchema>>;
|
|
16
|
+
//# sourceMappingURL=zod.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod.d.mts","sourceRoot":"","sources":["../../src/helpers/beta/zod.ts"],"names":[],"mappings":"OAAO,KAAK,EAAE,KAAK,IAAI,QAAQ,EAAE,OAAO,EAAE,MAAM,QAAQ;OAEjD,EAAE,UAAU,EAAE,gBAAgB,EAAE;OAChC,EAAE,+BAA+B,EAAE;AAE1C;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,WAAW,SAAS,OAAO,EAAE,OAAO,EAAE;IAChE,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,WAAW,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,WAAW,CAAC,KAAK,UAAU,CAAC,MAAM,GAAG,KAAK,CAAC,+BAA+B,CAAC,CAAC,CAAC;CACnG,GAAG,gBAAgB,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAkB1C"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { infer as zodInfer, ZodType } from 'zod/v4';
|
|
2
|
+
import { Promisable, BetaRunnableTool } from "../../lib/tools/BetaRunnableTool.js";
|
|
3
|
+
import { BetaToolResultContentBlockParam } from "../../resources/beta.js";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a tool using the provided Zod schema that can be passed
|
|
6
|
+
* into the `.toolRunner()` method. The Zod schema will automatically be
|
|
7
|
+
* converted into JSON Schema when passed to the API. The provided function's
|
|
8
|
+
* input arguments will also be validated against the provided schema.
|
|
9
|
+
*/
|
|
10
|
+
export declare function betaZodTool<InputSchema extends ZodType>(options: {
|
|
11
|
+
name: string;
|
|
12
|
+
inputSchema: InputSchema;
|
|
13
|
+
description: string;
|
|
14
|
+
run: (args: zodInfer<InputSchema>) => Promisable<string | Array<BetaToolResultContentBlockParam>>;
|
|
15
|
+
}): BetaRunnableTool<zodInfer<InputSchema>>;
|
|
16
|
+
//# sourceMappingURL=zod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../src/helpers/beta/zod.ts"],"names":[],"mappings":"OAAO,KAAK,EAAE,KAAK,IAAI,QAAQ,EAAE,OAAO,EAAE,MAAM,QAAQ;OAEjD,EAAE,UAAU,EAAE,gBAAgB,EAAE;OAChC,EAAE,+BAA+B,EAAE;AAE1C;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,WAAW,SAAS,OAAO,EAAE,OAAO,EAAE;IAChE,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,WAAW,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,WAAW,CAAC,KAAK,UAAU,CAAC,MAAM,GAAG,KAAK,CAAC,+BAA+B,CAAC,CAAC,CAAC;CACnG,GAAG,gBAAgB,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAkB1C"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.betaZodTool = betaZodTool;
|
|
4
|
+
const tslib_1 = require("../../internal/tslib.js");
|
|
5
|
+
const z = tslib_1.__importStar(require("zod/v4"));
|
|
6
|
+
/**
|
|
7
|
+
* Creates a tool using the provided Zod schema that can be passed
|
|
8
|
+
* into the `.toolRunner()` method. The Zod schema will automatically be
|
|
9
|
+
* converted into JSON Schema when passed to the API. The provided function's
|
|
10
|
+
* input arguments will also be validated against the provided schema.
|
|
11
|
+
*/
|
|
12
|
+
function betaZodTool(options) {
|
|
13
|
+
const jsonSchema = z.toJSONSchema(options.inputSchema, { reused: 'ref' });
|
|
14
|
+
if (jsonSchema.type !== 'object') {
|
|
15
|
+
throw new Error(`Zod schema for tool "${options.name}" must be an object, but got ${jsonSchema.type}`);
|
|
16
|
+
}
|
|
17
|
+
// TypeScript doesn't narrow the type after the runtime check, so we need to assert it
|
|
18
|
+
const objectSchema = jsonSchema;
|
|
19
|
+
return {
|
|
20
|
+
type: 'custom',
|
|
21
|
+
name: options.name,
|
|
22
|
+
input_schema: objectSchema,
|
|
23
|
+
description: options.description,
|
|
24
|
+
run: options.run,
|
|
25
|
+
parse: (args) => options.inputSchema.parse(args),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=zod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod.js","sourceRoot":"","sources":["../../src/helpers/beta/zod.ts"],"names":[],"mappings":";;AAWA,kCAuBC;;AAjCD,kDAA4B;AAI5B;;;;;GAKG;AACH,SAAgB,WAAW,CAA8B,OAKxD;IACC,MAAM,UAAU,GAAG,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IAE1E,IAAI,UAAU,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CAAC,wBAAwB,OAAO,CAAC,IAAI,gCAAgC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;IACzG,CAAC;IAED,sFAAsF;IACtF,MAAM,YAAY,GAAG,UAAoD,CAAC;IAE1E,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,YAAY,EAAE,YAAY;QAC1B,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,KAAK,EAAE,CAAC,IAAa,EAAE,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAA0B;KACnF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a tool using the provided Zod schema that can be passed
|
|
4
|
+
* into the `.toolRunner()` method. The Zod schema will automatically be
|
|
5
|
+
* converted into JSON Schema when passed to the API. The provided function's
|
|
6
|
+
* input arguments will also be validated against the provided schema.
|
|
7
|
+
*/
|
|
8
|
+
export function betaZodTool(options) {
|
|
9
|
+
const jsonSchema = z.toJSONSchema(options.inputSchema, { reused: 'ref' });
|
|
10
|
+
if (jsonSchema.type !== 'object') {
|
|
11
|
+
throw new Error(`Zod schema for tool "${options.name}" must be an object, but got ${jsonSchema.type}`);
|
|
12
|
+
}
|
|
13
|
+
// TypeScript doesn't narrow the type after the runtime check, so we need to assert it
|
|
14
|
+
const objectSchema = jsonSchema;
|
|
15
|
+
return {
|
|
16
|
+
type: 'custom',
|
|
17
|
+
name: options.name,
|
|
18
|
+
input_schema: objectSchema,
|
|
19
|
+
description: options.description,
|
|
20
|
+
run: options.run,
|
|
21
|
+
parse: (args) => options.inputSchema.parse(args),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=zod.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod.mjs","sourceRoot":"","sources":["../../src/helpers/beta/zod.ts"],"names":[],"mappings":"OACO,KAAK,CAAC,MAAM,QAAQ;AAI3B;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAA8B,OAKxD;IACC,MAAM,UAAU,GAAG,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IAE1E,IAAI,UAAU,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CAAC,wBAAwB,OAAO,CAAC,IAAI,gCAAgC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;IACzG,CAAC;IAED,sFAAsF;IACtF,MAAM,YAAY,GAAG,UAAoD,CAAC;IAE1E,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,YAAY,EAAE,YAAY;QAC1B,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,KAAK,EAAE,CAAC,IAAa,EAAE,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAA0B;KACnF,CAAC;AACJ,CAAC"}
|
package/internal/utils/values.js
CHANGED
|
@@ -80,21 +80,21 @@ const coerceBoolean = (value) => {
|
|
|
80
80
|
};
|
|
81
81
|
exports.coerceBoolean = coerceBoolean;
|
|
82
82
|
const maybeCoerceInteger = (value) => {
|
|
83
|
-
if (value
|
|
83
|
+
if (value == null) {
|
|
84
84
|
return undefined;
|
|
85
85
|
}
|
|
86
86
|
return (0, exports.coerceInteger)(value);
|
|
87
87
|
};
|
|
88
88
|
exports.maybeCoerceInteger = maybeCoerceInteger;
|
|
89
89
|
const maybeCoerceFloat = (value) => {
|
|
90
|
-
if (value
|
|
90
|
+
if (value == null) {
|
|
91
91
|
return undefined;
|
|
92
92
|
}
|
|
93
93
|
return (0, exports.coerceFloat)(value);
|
|
94
94
|
};
|
|
95
95
|
exports.maybeCoerceFloat = maybeCoerceFloat;
|
|
96
96
|
const maybeCoerceBoolean = (value) => {
|
|
97
|
-
if (value
|
|
97
|
+
if (value == null) {
|
|
98
98
|
return undefined;
|
|
99
99
|
}
|
|
100
100
|
return (0, exports.coerceBoolean)(value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"values.js","sourceRoot":"","sources":["../../src/internal/utils/values.ts"],"names":[],"mappings":";AAAA,sFAAsF;;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A,gBAAgB,oBAK3B;AAEK,MAAM,kBAAkB,GAAG,CAAC,KAAc,EAAuB,EAAE;IACxE,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;QAClB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,IAAA,qBAAa,EAAC,KAAK,CAAC,CAAC;AAC9B,CAAC,CAAC;AALW,QAAA,kBAAkB,sBAK7B;AAEK,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,EAAE;IACvC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC,CAAC;AANW,QAAA,QAAQ,YAMnB"}
|
|
@@ -66,19 +66,19 @@ export const coerceBoolean = (value) => {
|
|
|
66
66
|
return Boolean(value);
|
|
67
67
|
};
|
|
68
68
|
export const maybeCoerceInteger = (value) => {
|
|
69
|
-
if (value
|
|
69
|
+
if (value == null) {
|
|
70
70
|
return undefined;
|
|
71
71
|
}
|
|
72
72
|
return coerceInteger(value);
|
|
73
73
|
};
|
|
74
74
|
export const maybeCoerceFloat = (value) => {
|
|
75
|
-
if (value
|
|
75
|
+
if (value == null) {
|
|
76
76
|
return undefined;
|
|
77
77
|
}
|
|
78
78
|
return coerceFloat(value);
|
|
79
79
|
};
|
|
80
80
|
export const maybeCoerceBoolean = (value) => {
|
|
81
|
-
if (value
|
|
81
|
+
if (value == null) {
|
|
82
82
|
return undefined;
|
|
83
83
|
}
|
|
84
84
|
return coerceBoolean(value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"values.mjs","sourceRoot":"","sources":["../../src/internal/utils/values.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,cAAc,EAAE;AAEzB,iDAAiD;AACjD,MAAM,sBAAsB,GAAG,sBAAsB,CAAC;AAEtD,MAAM,CAAC,MAAM,aAAa,GAAG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CAAC;QACb,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BetaTool, BetaToolResultContentBlockParam } from "../../resources/beta.mjs";
|
|
2
|
+
export type Promisable<T> = T | Promise<T>;
|
|
3
|
+
export interface BetaRunnableTool<Input = any> extends BetaTool {
|
|
4
|
+
run: (args: Input) => Promisable<string | Array<BetaToolResultContentBlockParam>>;
|
|
5
|
+
parse: (content: unknown) => Input;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=BetaRunnableTool.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BetaRunnableTool.d.mts","sourceRoot":"","sources":["../../src/lib/tools/BetaRunnableTool.ts"],"names":[],"mappings":"OAAO,EAAE,QAAQ,EAAE,+BAA+B,EAAE;AAEpD,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAI3C,MAAM,WAAW,gBAAgB,CAAC,KAAK,GAAG,GAAG,CAAE,SAAQ,QAAQ;IAC7D,GAAG,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,UAAU,CAAC,MAAM,GAAG,KAAK,CAAC,+BAA+B,CAAC,CAAC,CAAC;IAClF,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,KAAK,CAAC;CACpC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BetaTool, BetaToolResultContentBlockParam } from "../../resources/beta.js";
|
|
2
|
+
export type Promisable<T> = T | Promise<T>;
|
|
3
|
+
export interface BetaRunnableTool<Input = any> extends BetaTool {
|
|
4
|
+
run: (args: Input) => Promisable<string | Array<BetaToolResultContentBlockParam>>;
|
|
5
|
+
parse: (content: unknown) => Input;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=BetaRunnableTool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BetaRunnableTool.d.ts","sourceRoot":"","sources":["../../src/lib/tools/BetaRunnableTool.ts"],"names":[],"mappings":"OAAO,EAAE,QAAQ,EAAE,+BAA+B,EAAE;AAEpD,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAI3C,MAAM,WAAW,gBAAgB,CAAC,KAAK,GAAG,GAAG,CAAE,SAAQ,QAAQ;IAC7D,GAAG,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,UAAU,CAAC,MAAM,GAAG,KAAK,CAAC,+BAA+B,CAAC,CAAC,CAAC;IAClF,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,KAAK,CAAC;CACpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BetaRunnableTool.js","sourceRoot":"","sources":["../../src/lib/tools/BetaRunnableTool.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BetaRunnableTool.mjs","sourceRoot":"","sources":["../../src/lib/tools/BetaRunnableTool.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { BetaRunnableTool } from "./BetaRunnableTool.mjs";
|
|
2
|
+
import { Anthropic } from "../../index.mjs";
|
|
3
|
+
import { BetaMessage, BetaMessageParam, BetaToolUnion, MessageCreateParams } from "../../resources/beta.mjs";
|
|
4
|
+
import { BetaMessageStream } from "../BetaMessageStream.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* A ToolRunner handles the automatic conversation loop between the assistant and tools.
|
|
7
|
+
*
|
|
8
|
+
* A ToolRunner is an async iterable that yields either BetaMessage or BetaMessageStream objects
|
|
9
|
+
* depending on the streaming configuration.
|
|
10
|
+
*/
|
|
11
|
+
export declare class BetaToolRunner<Stream extends boolean> {
|
|
12
|
+
#private;
|
|
13
|
+
private client;
|
|
14
|
+
constructor(client: Anthropic, params: BetaToolRunnerParams);
|
|
15
|
+
[Symbol.asyncIterator](): AsyncIterator<Stream extends true ? BetaMessageStream : Stream extends false ? BetaMessage : BetaMessage | BetaMessageStream>;
|
|
16
|
+
/**
|
|
17
|
+
* Update the parameters for the next API call. This invalidates any cached tool responses.
|
|
18
|
+
*
|
|
19
|
+
* @param paramsOrMutator - Either new parameters or a function to mutate existing parameters
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // Direct parameter update
|
|
23
|
+
* runner.setMessagesParams({
|
|
24
|
+
* model: 'claude-3-5-haiku-latest',
|
|
25
|
+
* max_tokens: 500,
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Using a mutator function
|
|
30
|
+
* runner.setMessagesParams((params) => ({
|
|
31
|
+
* ...params,
|
|
32
|
+
* max_tokens: 100,
|
|
33
|
+
* }));
|
|
34
|
+
*/
|
|
35
|
+
setMessagesParams(params: BetaToolRunnerParams): void;
|
|
36
|
+
setMessagesParams(mutator: (prevParams: BetaToolRunnerParams) => BetaToolRunnerParams): void;
|
|
37
|
+
/**
|
|
38
|
+
* Get the tool response for the last message from the assistant.
|
|
39
|
+
* Avoids redundant tool executions by caching results.
|
|
40
|
+
*
|
|
41
|
+
* @returns A promise that resolves to a BetaMessageParam containing tool results, or null if no tools need to be executed
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* const toolResponse = await runner.generateToolResponse();
|
|
45
|
+
* if (toolResponse) {
|
|
46
|
+
* console.log('Tool results:', toolResponse.content);
|
|
47
|
+
* }
|
|
48
|
+
*/
|
|
49
|
+
generateToolResponse(): Promise<Anthropic.Beta.Messages.BetaMessageParam | null>;
|
|
50
|
+
/**
|
|
51
|
+
* Wait for the async iterator to complete. This works even if the async iterator hasn't yet started, and
|
|
52
|
+
* will wait for an instance to start and go to completion.
|
|
53
|
+
*
|
|
54
|
+
* @returns A promise that resolves to the final BetaMessage when the iterator completes
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* // Start consuming the iterator
|
|
58
|
+
* for await (const message of runner) {
|
|
59
|
+
* console.log('Message:', message.content);
|
|
60
|
+
* }
|
|
61
|
+
*
|
|
62
|
+
* // Meanwhile, wait for completion from another part of the code
|
|
63
|
+
* const finalMessage = await runner.done();
|
|
64
|
+
* console.log('Final response:', finalMessage.content);
|
|
65
|
+
*/
|
|
66
|
+
done(): Promise<BetaMessage>;
|
|
67
|
+
/**
|
|
68
|
+
* Returns a promise indicating that the stream is done. Unlike .done(), this will eagerly read the stream:
|
|
69
|
+
* * If the iterator has not been consumed, consume the entire iterator and return the final message from the
|
|
70
|
+
* assistant.
|
|
71
|
+
* * If the iterator has been consumed, waits for it to complete and returns the final message.
|
|
72
|
+
*
|
|
73
|
+
* @returns A promise that resolves to the final BetaMessage from the conversation
|
|
74
|
+
* @throws {AnthropicError} If no messages were processed during the conversation
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* const finalMessage = await runner.runUntilDone();
|
|
78
|
+
* console.log('Final response:', finalMessage.content);
|
|
79
|
+
*/
|
|
80
|
+
runUntilDone(): Promise<BetaMessage>;
|
|
81
|
+
/**
|
|
82
|
+
* Get the current parameters being used by the ToolRunner.
|
|
83
|
+
*
|
|
84
|
+
* @returns A readonly view of the current ToolRunnerParams
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* const currentParams = runner.params;
|
|
88
|
+
* console.log('Current model:', currentParams.model);
|
|
89
|
+
* console.log('Message count:', currentParams.messages.length);
|
|
90
|
+
*/
|
|
91
|
+
get params(): Readonly<BetaToolRunnerParams>;
|
|
92
|
+
/**
|
|
93
|
+
* Add one or more messages to the conversation history.
|
|
94
|
+
*
|
|
95
|
+
* @param messages - One or more BetaMessageParam objects to add to the conversation
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* runner.pushMessages(
|
|
99
|
+
* { role: 'user', content: 'Also, what about the weather in NYC?' }
|
|
100
|
+
* );
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* // Adding multiple messages
|
|
104
|
+
* runner.pushMessages(
|
|
105
|
+
* { role: 'user', content: 'What about NYC?' },
|
|
106
|
+
* { role: 'user', content: 'And Boston?' }
|
|
107
|
+
* );
|
|
108
|
+
*/
|
|
109
|
+
pushMessages(...messages: BetaMessageParam[]): void;
|
|
110
|
+
/**
|
|
111
|
+
* Makes the ToolRunner directly awaitable, equivalent to calling .runUntilDone()
|
|
112
|
+
* This allows using `await runner` instead of `await runner.runUntilDone()`
|
|
113
|
+
*/
|
|
114
|
+
then<TResult1 = BetaMessage, TResult2 = never>(onfulfilled?: ((value: BetaMessage) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
|
|
115
|
+
}
|
|
116
|
+
type Simplify<T> = {
|
|
117
|
+
[KeyType in keyof T]: T[KeyType];
|
|
118
|
+
} & {};
|
|
119
|
+
/**
|
|
120
|
+
* Parameters for creating a ToolRunner, extending MessageCreateParams with runnable tools.
|
|
121
|
+
*/
|
|
122
|
+
export type BetaToolRunnerParams = Simplify<Omit<MessageCreateParams, 'tools'> & {
|
|
123
|
+
tools: (BetaToolUnion | BetaRunnableTool<any>)[];
|
|
124
|
+
/**
|
|
125
|
+
* Maximum number of iterations (API requests) to make in the tool execution loop.
|
|
126
|
+
* Each iteration consists of: assistant response → tool execution → tool results.
|
|
127
|
+
* When exceeded, the loop will terminate even if tools are still being requested.
|
|
128
|
+
*/
|
|
129
|
+
max_iterations?: number;
|
|
130
|
+
}>;
|
|
131
|
+
export {};
|
|
132
|
+
//# sourceMappingURL=BetaToolRunner.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BetaToolRunner.d.mts","sourceRoot":"","sources":["../../src/lib/tools/BetaToolRunner.ts"],"names":[],"mappings":"OAAO,EAAE,gBAAgB,EAAE;OACpB,EAAE,SAAS,EAAE;OAEb,EAAE,WAAW,EA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