@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.
Files changed (90) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +47 -12
  3. package/helpers/beta/json-schema.d.mts +19 -0
  4. package/helpers/beta/json-schema.d.mts.map +1 -0
  5. package/helpers/beta/json-schema.d.ts +19 -0
  6. package/helpers/beta/json-schema.d.ts.map +1 -0
  7. package/helpers/beta/json-schema.js +22 -0
  8. package/helpers/beta/json-schema.js.map +1 -0
  9. package/helpers/beta/json-schema.mjs +19 -0
  10. package/helpers/beta/json-schema.mjs.map +1 -0
  11. package/helpers/beta/zod.d.mts +16 -0
  12. package/helpers/beta/zod.d.mts.map +1 -0
  13. package/helpers/beta/zod.d.ts +16 -0
  14. package/helpers/beta/zod.d.ts.map +1 -0
  15. package/helpers/beta/zod.js +28 -0
  16. package/helpers/beta/zod.js.map +1 -0
  17. package/helpers/beta/zod.mjs +24 -0
  18. package/helpers/beta/zod.mjs.map +1 -0
  19. package/internal/utils/values.js +3 -3
  20. package/internal/utils/values.js.map +1 -1
  21. package/internal/utils/values.mjs +3 -3
  22. package/internal/utils/values.mjs.map +1 -1
  23. package/lib/tools/BetaRunnableTool.d.mts +7 -0
  24. package/lib/tools/BetaRunnableTool.d.mts.map +1 -0
  25. package/lib/tools/BetaRunnableTool.d.ts +7 -0
  26. package/lib/tools/BetaRunnableTool.d.ts.map +1 -0
  27. package/lib/tools/BetaRunnableTool.js +3 -0
  28. package/lib/tools/BetaRunnableTool.js.map +1 -0
  29. package/lib/tools/BetaRunnableTool.mjs +2 -0
  30. package/lib/tools/BetaRunnableTool.mjs.map +1 -0
  31. package/lib/tools/BetaToolRunner.d.mts +132 -0
  32. package/lib/tools/BetaToolRunner.d.mts.map +1 -0
  33. package/lib/tools/BetaToolRunner.d.ts +132 -0
  34. package/lib/tools/BetaToolRunner.d.ts.map +1 -0
  35. package/lib/tools/BetaToolRunner.js +288 -0
  36. package/lib/tools/BetaToolRunner.js.map +1 -0
  37. package/lib/tools/BetaToolRunner.mjs +284 -0
  38. package/lib/tools/BetaToolRunner.mjs.map +1 -0
  39. package/lib/tools/ToolRunner.d.mts +132 -0
  40. package/lib/tools/ToolRunner.d.mts.map +1 -0
  41. package/lib/tools/ToolRunner.d.ts +132 -0
  42. package/lib/tools/ToolRunner.d.ts.map +1 -0
  43. package/lib/tools/ToolRunner.js +288 -0
  44. package/lib/tools/ToolRunner.js.map +1 -0
  45. package/lib/tools/ToolRunner.mjs +284 -0
  46. package/lib/tools/ToolRunner.mjs.map +1 -0
  47. package/package.json +22 -2
  48. package/resources/beta/beta.d.mts +2 -2
  49. package/resources/beta/beta.d.mts.map +1 -1
  50. package/resources/beta/beta.d.ts +2 -2
  51. package/resources/beta/beta.d.ts.map +1 -1
  52. package/resources/beta/beta.js.map +1 -1
  53. package/resources/beta/beta.mjs.map +1 -1
  54. package/resources/beta/index.d.mts +1 -1
  55. package/resources/beta/index.d.mts.map +1 -1
  56. package/resources/beta/index.d.ts +1 -1
  57. package/resources/beta/index.d.ts.map +1 -1
  58. package/resources/beta/index.js.map +1 -1
  59. package/resources/beta/index.mjs.map +1 -1
  60. package/resources/beta/messages/index.d.mts +2 -1
  61. package/resources/beta/messages/index.d.mts.map +1 -1
  62. package/resources/beta/messages/index.d.ts +2 -1
  63. package/resources/beta/messages/index.d.ts.map +1 -1
  64. package/resources/beta/messages/index.js +3 -1
  65. package/resources/beta/messages/index.js.map +1 -1
  66. package/resources/beta/messages/index.mjs +1 -0
  67. package/resources/beta/messages/index.mjs.map +1 -1
  68. package/resources/beta/messages/messages.d.mts +13 -2
  69. package/resources/beta/messages/messages.d.mts.map +1 -1
  70. package/resources/beta/messages/messages.d.ts +13 -2
  71. package/resources/beta/messages/messages.d.ts.map +1 -1
  72. package/resources/beta/messages/messages.js +9 -2
  73. package/resources/beta/messages/messages.js.map +1 -1
  74. package/resources/beta/messages/messages.mjs +7 -1
  75. package/resources/beta/messages/messages.mjs.map +1 -1
  76. package/src/helpers/beta/json-schema.ts +32 -0
  77. package/src/helpers/beta/zod.ts +35 -0
  78. package/src/internal/utils/values.ts +3 -3
  79. package/src/lib/tools/BetaRunnableTool.ts +10 -0
  80. package/src/lib/tools/BetaToolRunner.ts +374 -0
  81. package/src/lib/tools/ToolRunner.ts +374 -0
  82. package/src/resources/beta/beta.ts +2 -0
  83. package/src/resources/beta/index.ts +1 -0
  84. package/src/resources/beta/messages/index.ts +2 -0
  85. package/src/resources/beta/messages/messages.ts +20 -2
  86. package/src/version.ts +1 -1
  87. package/version.d.mts +1 -1
  88. package/version.d.ts +1 -1
  89. package/version.js +1 -1
  90. package/version.mjs +1 -1
@@ -0,0 +1,284 @@
1
+ var _BetaToolRunner_instances, _BetaToolRunner_consumed, _BetaToolRunner_mutated, _BetaToolRunner_state, _BetaToolRunner_message, _BetaToolRunner_toolResponse, _BetaToolRunner_completion, _BetaToolRunner_iterationCount, _BetaToolRunner_generateToolResponse;
2
+ import { __classPrivateFieldGet, __classPrivateFieldSet } from "../../internal/tslib.mjs";
3
+ import { AnthropicError } from "../../core/error.mjs";
4
+ /**
5
+ * Just Promise.withResolvers(), which is not available in all environments.
6
+ */
7
+ function promiseWithResolvers() {
8
+ let resolve;
9
+ let reject;
10
+ const promise = new Promise((res, rej) => {
11
+ resolve = res;
12
+ reject = rej;
13
+ });
14
+ return { promise, resolve: resolve, reject: reject };
15
+ }
16
+ /**
17
+ * A ToolRunner handles the automatic conversation loop between the assistant and tools.
18
+ *
19
+ * A ToolRunner is an async iterable that yields either BetaMessage or BetaMessageStream objects
20
+ * depending on the streaming configuration.
21
+ */
22
+ export class BetaToolRunner {
23
+ constructor(client, params) {
24
+ _BetaToolRunner_instances.add(this);
25
+ this.client = client;
26
+ /** Whether the async iterator has been consumed */
27
+ _BetaToolRunner_consumed.set(this, false);
28
+ /** Whether parameters have been mutated since the last API call */
29
+ _BetaToolRunner_mutated.set(this, false);
30
+ /** Current state containing the request parameters */
31
+ _BetaToolRunner_state.set(this, void 0);
32
+ /** Promise for the last message received from the assistant */
33
+ _BetaToolRunner_message.set(this, void 0);
34
+ /** Cached tool response to avoid redundant executions */
35
+ _BetaToolRunner_toolResponse.set(this, void 0);
36
+ /** Promise resolvers for waiting on completion */
37
+ _BetaToolRunner_completion.set(this, void 0);
38
+ /** Number of iterations (API requests) made so far */
39
+ _BetaToolRunner_iterationCount.set(this, 0);
40
+ __classPrivateFieldSet(this, _BetaToolRunner_state, {
41
+ params: {
42
+ // You can't clone the entire params since there are functions as handlers.
43
+ // You also don't really need to clone params.messages, but it probably will prevent a foot gun
44
+ // somewhere.
45
+ ...params,
46
+ messages: structuredClone(params.messages),
47
+ },
48
+ }, "f");
49
+ __classPrivateFieldSet(this, _BetaToolRunner_completion, promiseWithResolvers(), "f");
50
+ }
51
+ async *[(_BetaToolRunner_consumed = new WeakMap(), _BetaToolRunner_mutated = new WeakMap(), _BetaToolRunner_state = new WeakMap(), _BetaToolRunner_message = new WeakMap(), _BetaToolRunner_toolResponse = new WeakMap(), _BetaToolRunner_completion = new WeakMap(), _BetaToolRunner_iterationCount = new WeakMap(), _BetaToolRunner_instances = new WeakSet(), Symbol.asyncIterator)]() {
52
+ var _a;
53
+ if (__classPrivateFieldGet(this, _BetaToolRunner_consumed, "f")) {
54
+ throw new AnthropicError('Cannot iterate over a consumed stream');
55
+ }
56
+ __classPrivateFieldSet(this, _BetaToolRunner_consumed, true, "f");
57
+ __classPrivateFieldSet(this, _BetaToolRunner_mutated, true, "f");
58
+ __classPrivateFieldSet(this, _BetaToolRunner_toolResponse, undefined, "f");
59
+ try {
60
+ while (true) {
61
+ let stream;
62
+ try {
63
+ if (__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.max_iterations &&
64
+ __classPrivateFieldGet(this, _BetaToolRunner_iterationCount, "f") >= __classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.max_iterations) {
65
+ break;
66
+ }
67
+ __classPrivateFieldSet(this, _BetaToolRunner_mutated, false, "f");
68
+ __classPrivateFieldSet(this, _BetaToolRunner_message, undefined, "f");
69
+ __classPrivateFieldSet(this, _BetaToolRunner_toolResponse, undefined, "f");
70
+ __classPrivateFieldSet(this, _BetaToolRunner_iterationCount, (_a = __classPrivateFieldGet(this, _BetaToolRunner_iterationCount, "f"), _a++, _a), "f");
71
+ const { max_iterations, ...params } = __classPrivateFieldGet(this, _BetaToolRunner_state, "f").params;
72
+ if (params.stream) {
73
+ stream = this.client.beta.messages.stream({ ...params });
74
+ __classPrivateFieldSet(this, _BetaToolRunner_message, stream.finalMessage(), "f");
75
+ yield stream;
76
+ }
77
+ else {
78
+ __classPrivateFieldSet(this, _BetaToolRunner_message, this.client.beta.messages.create({ ...params, stream: false }), "f");
79
+ yield __classPrivateFieldGet(this, _BetaToolRunner_message, "f");
80
+ }
81
+ if (!__classPrivateFieldGet(this, _BetaToolRunner_mutated, "f")) {
82
+ const { role, content } = await __classPrivateFieldGet(this, _BetaToolRunner_message, "f");
83
+ __classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.messages.push({ role, content });
84
+ }
85
+ const toolMessage = await __classPrivateFieldGet(this, _BetaToolRunner_instances, "m", _BetaToolRunner_generateToolResponse).call(this, __classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.messages.at(-1));
86
+ if (toolMessage) {
87
+ __classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.messages.push(toolMessage);
88
+ }
89
+ if (!toolMessage && !__classPrivateFieldGet(this, _BetaToolRunner_mutated, "f")) {
90
+ break;
91
+ }
92
+ }
93
+ finally {
94
+ if (stream) {
95
+ stream.abort();
96
+ }
97
+ }
98
+ }
99
+ if (!__classPrivateFieldGet(this, _BetaToolRunner_message, "f")) {
100
+ throw new AnthropicError('ToolRunner concluded without a message from the server');
101
+ }
102
+ __classPrivateFieldGet(this, _BetaToolRunner_completion, "f").resolve(await __classPrivateFieldGet(this, _BetaToolRunner_message, "f"));
103
+ }
104
+ catch (error) {
105
+ __classPrivateFieldSet(this, _BetaToolRunner_consumed, false, "f");
106
+ // Silence unhandled promise errors
107
+ __classPrivateFieldGet(this, _BetaToolRunner_completion, "f").promise.catch(() => { });
108
+ __classPrivateFieldGet(this, _BetaToolRunner_completion, "f").reject(error);
109
+ __classPrivateFieldSet(this, _BetaToolRunner_completion, promiseWithResolvers(), "f");
110
+ throw error;
111
+ }
112
+ }
113
+ setMessagesParams(paramsOrMutator) {
114
+ if (typeof paramsOrMutator === 'function') {
115
+ __classPrivateFieldGet(this, _BetaToolRunner_state, "f").params = paramsOrMutator(__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params);
116
+ }
117
+ else {
118
+ __classPrivateFieldGet(this, _BetaToolRunner_state, "f").params = paramsOrMutator;
119
+ }
120
+ __classPrivateFieldSet(this, _BetaToolRunner_mutated, true, "f");
121
+ // Invalidate cached tool response since parameters changed
122
+ __classPrivateFieldSet(this, _BetaToolRunner_toolResponse, undefined, "f");
123
+ }
124
+ /**
125
+ * Get the tool response for the last message from the assistant.
126
+ * Avoids redundant tool executions by caching results.
127
+ *
128
+ * @returns A promise that resolves to a BetaMessageParam containing tool results, or null if no tools need to be executed
129
+ *
130
+ * @example
131
+ * const toolResponse = await runner.generateToolResponse();
132
+ * if (toolResponse) {
133
+ * console.log('Tool results:', toolResponse.content);
134
+ * }
135
+ */
136
+ async generateToolResponse() {
137
+ const message = (await __classPrivateFieldGet(this, _BetaToolRunner_message, "f")) ?? this.params.messages.at(-1);
138
+ if (!message) {
139
+ return null;
140
+ }
141
+ return __classPrivateFieldGet(this, _BetaToolRunner_instances, "m", _BetaToolRunner_generateToolResponse).call(this, message);
142
+ }
143
+ /**
144
+ * Wait for the async iterator to complete. This works even if the async iterator hasn't yet started, and
145
+ * will wait for an instance to start and go to completion.
146
+ *
147
+ * @returns A promise that resolves to the final BetaMessage when the iterator completes
148
+ *
149
+ * @example
150
+ * // Start consuming the iterator
151
+ * for await (const message of runner) {
152
+ * console.log('Message:', message.content);
153
+ * }
154
+ *
155
+ * // Meanwhile, wait for completion from another part of the code
156
+ * const finalMessage = await runner.done();
157
+ * console.log('Final response:', finalMessage.content);
158
+ */
159
+ done() {
160
+ return __classPrivateFieldGet(this, _BetaToolRunner_completion, "f").promise;
161
+ }
162
+ /**
163
+ * Returns a promise indicating that the stream is done. Unlike .done(), this will eagerly read the stream:
164
+ * * If the iterator has not been consumed, consume the entire iterator and return the final message from the
165
+ * assistant.
166
+ * * If the iterator has been consumed, waits for it to complete and returns the final message.
167
+ *
168
+ * @returns A promise that resolves to the final BetaMessage from the conversation
169
+ * @throws {AnthropicError} If no messages were processed during the conversation
170
+ *
171
+ * @example
172
+ * const finalMessage = await runner.runUntilDone();
173
+ * console.log('Final response:', finalMessage.content);
174
+ */
175
+ async runUntilDone() {
176
+ // If not yet consumed, start consuming and wait for completion
177
+ if (!__classPrivateFieldGet(this, _BetaToolRunner_consumed, "f")) {
178
+ for await (const _ of this) {
179
+ // Iterator naturally populates this.#message
180
+ }
181
+ }
182
+ // If consumed but not completed, wait for completion
183
+ return this.done();
184
+ }
185
+ /**
186
+ * Get the current parameters being used by the ToolRunner.
187
+ *
188
+ * @returns A readonly view of the current ToolRunnerParams
189
+ *
190
+ * @example
191
+ * const currentParams = runner.params;
192
+ * console.log('Current model:', currentParams.model);
193
+ * console.log('Message count:', currentParams.messages.length);
194
+ */
195
+ get params() {
196
+ return __classPrivateFieldGet(this, _BetaToolRunner_state, "f").params;
197
+ }
198
+ /**
199
+ * Add one or more messages to the conversation history.
200
+ *
201
+ * @param messages - One or more BetaMessageParam objects to add to the conversation
202
+ *
203
+ * @example
204
+ * runner.pushMessages(
205
+ * { role: 'user', content: 'Also, what about the weather in NYC?' }
206
+ * );
207
+ *
208
+ * @example
209
+ * // Adding multiple messages
210
+ * runner.pushMessages(
211
+ * { role: 'user', content: 'What about NYC?' },
212
+ * { role: 'user', content: 'And Boston?' }
213
+ * );
214
+ */
215
+ pushMessages(...messages) {
216
+ this.setMessagesParams((params) => ({
217
+ ...params,
218
+ messages: [...params.messages, ...messages],
219
+ }));
220
+ }
221
+ /**
222
+ * Makes the ToolRunner directly awaitable, equivalent to calling .runUntilDone()
223
+ * This allows using `await runner` instead of `await runner.runUntilDone()`
224
+ */
225
+ then(onfulfilled, onrejected) {
226
+ return this.runUntilDone().then(onfulfilled, onrejected);
227
+ }
228
+ }
229
+ _BetaToolRunner_generateToolResponse = async function _BetaToolRunner_generateToolResponse(lastMessage) {
230
+ if (__classPrivateFieldGet(this, _BetaToolRunner_toolResponse, "f") !== undefined) {
231
+ return __classPrivateFieldGet(this, _BetaToolRunner_toolResponse, "f");
232
+ }
233
+ __classPrivateFieldSet(this, _BetaToolRunner_toolResponse, generateToolResponse(__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params, lastMessage), "f");
234
+ return __classPrivateFieldGet(this, _BetaToolRunner_toolResponse, "f");
235
+ };
236
+ async function generateToolResponse(params, lastMessage = params.messages.at(-1)) {
237
+ // Only process if the last message is from the assistant and has tool use blocks
238
+ if (!lastMessage ||
239
+ lastMessage.role !== 'assistant' ||
240
+ !lastMessage.content ||
241
+ typeof lastMessage.content === 'string') {
242
+ return null;
243
+ }
244
+ const toolUseBlocks = lastMessage.content.filter((content) => content.type === 'tool_use');
245
+ if (toolUseBlocks.length === 0) {
246
+ return null;
247
+ }
248
+ const toolResults = await Promise.all(toolUseBlocks.map(async (toolUse) => {
249
+ const tool = params.tools.find((t) => t.name === toolUse.name);
250
+ if (!tool || !('run' in tool)) {
251
+ return {
252
+ type: 'tool_result',
253
+ tool_use_id: toolUse.id,
254
+ content: `Error: Tool '${toolUse.name}' not found`,
255
+ is_error: true,
256
+ };
257
+ }
258
+ try {
259
+ let input = toolUse.input;
260
+ if ('parse' in tool && tool.parse) {
261
+ input = tool.parse(input);
262
+ }
263
+ const result = await tool.run(input);
264
+ return {
265
+ type: 'tool_result',
266
+ tool_use_id: toolUse.id,
267
+ content: result,
268
+ };
269
+ }
270
+ catch (error) {
271
+ return {
272
+ type: 'tool_result',
273
+ tool_use_id: toolUse.id,
274
+ content: `Error: ${error instanceof Error ? error.message : String(error)}`,
275
+ is_error: true,
276
+ };
277
+ }
278
+ }));
279
+ return {
280
+ role: 'user',
281
+ content: toolResults,
282
+ };
283
+ }
284
+ //# sourceMappingURL=BetaToolRunner.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BetaToolRunner.mjs","sourceRoot":"","sources":["../../src/lib/tools/BetaToolRunner.ts"],"names":[],"mappings":";;OAEO,EAAE,cAAc,EAAE;AAIzB;;GAEG;AACH,SAAS,oBAAoB;IAK3B,IAAI,OAA2B,CAAC;IAChC,IAAI,MAA8B,CAAC;IACnC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAC1C,OAAO,GAAG,GAAG,CAAC;QACd,MAAM,GAAG,GAAG,CAAC;IACf,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAQ,EAAE,MAAM,EAAE,MAAO,EAAE,CAAC;AACzD,CAAC;AAED;;;;;GAKG;AACH,MAAM,OAAO,cAAc;IAoBzB,YACU,MAAiB,EACzB,MAA4B;;QADpB,WAAM,GAAN,MAAM,CAAW;QApB3B,mDAAmD;QACnD,mCAAY,KAAK,EAAC;QAClB,mEAAmE;QACnE,kCAAW,KAAK,EAAC;QACjB,sDAAsD;QACtD,wCAAyC;QACzC,+DAA+D;QAC/D,0CAA4C;QAC5C,yDAAyD;QACzD,+CAA6D;QAC7D,kDAAkD;QAClD,6CAIE;QACF,sDAAsD;QACtD,yCAAkB,CAAC,EAAC;QAMlB,uBAAA,IAAI,yBAAU;YACZ,MAAM,EAAE;gBACN,2EAA2E;gBAC3E,+FAA+F;gBAC/F,aAAa;gBACb,GAAG,MAAM;gBACT,QAAQ,EAAE,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC;aAC3C;SACF,MAAA,CAAC;QAEF,uBAAA,IAA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BAC5B,WAAW,EAAE,OAAO,CAAC,EAAE;gBACvB,OAAO,EAAE,UAAU,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;gBAC3E,QAAQ,EAAE,IAAI;aACf,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CACH,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,MAAe;QACrB,OAAO,EAAE,WAAW;KACrB,CAAC;AACJ,CAAC"}
@@ -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=ToolRunner.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ToolRunner.d.mts","sourceRoot":"","sources":["../../src/lib/tools/ToolRunner.ts"],"names":[],"mappings":"OAAO,EAAE,gBAAgB,EAAE;OACpB,EAAE,SAAS,EAAE;OAEb,EAAE,WAAW,EAAE,gBAAgB,EAAE,aAAa,EAAE,mBAAmB,EAAE;OACrE,EAAE,iBAAiB,EAAE;AAmB5B;;;;;GAKG;AACH,qBAAa,cAAc,CAAC,MAAM,SAAS,OAAO;;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AAE,GAAG,EAAE,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CACzC,IAAI,CAAC,mBAAmB,EAAE,OAAO,CAAC,GAAG;IACnC,KAAK,EAAE,CAAC,aAAa,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;IACjD;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CACF,CAAC"}
@@ -0,0 +1,132 @@
1
+ import { BetaRunnableTool } from "./BetaRunnableTool.js";
2
+ import { Anthropic } from "../../index.js";
3
+ import { BetaMessage, BetaMessageParam, BetaToolUnion, MessageCreateParams } from "../../resources/beta.js";
4
+ import { BetaMessageStream } from "../BetaMessageStream.js";
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=ToolRunner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ToolRunner.d.ts","sourceRoot":"","sources":["../../src/lib/tools/ToolRunner.ts"],"names":[],"mappings":"OAAO,EAAE,gBAAgB,EAAE;OACpB,EAAE,SAAS,EAAE;OAEb,EAAE,WAAW,EAAE,gBAAgB,EAAE,aAAa,EAAE,mBAAmB,EAAE;OACrE,EAAE,iBAAiB,EAAE;AAmB5B;;;;;GAKG;AACH,qBAAa,cAAc,CAAC,MAAM,SAAS,OAAO;;IAqB9C,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,SAAS,EACzB,MAA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