@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
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import { BetaRunnableTool } from './BetaRunnableTool';
|
|
2
|
+
import { Anthropic } from '../..';
|
|
3
|
+
import { AnthropicError } from '../../core/error';
|
|
4
|
+
import { BetaMessage, BetaMessageParam, BetaToolUnion, MessageCreateParams } from '../../resources/beta';
|
|
5
|
+
import { BetaMessageStream } from '../BetaMessageStream';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Just Promise.withResolvers(), which is not available in all environments.
|
|
9
|
+
*/
|
|
10
|
+
function promiseWithResolvers<T>(): {
|
|
11
|
+
promise: Promise<T>;
|
|
12
|
+
resolve: (value: T) => void;
|
|
13
|
+
reject: (reason?: any) => void;
|
|
14
|
+
} {
|
|
15
|
+
let resolve: (value: T) => void;
|
|
16
|
+
let reject: (reason?: any) => void;
|
|
17
|
+
const promise = new Promise<T>((res, rej) => {
|
|
18
|
+
resolve = res;
|
|
19
|
+
reject = rej;
|
|
20
|
+
});
|
|
21
|
+
return { promise, resolve: resolve!, reject: reject! };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A ToolRunner handles the automatic conversation loop between the assistant and tools.
|
|
26
|
+
*
|
|
27
|
+
* A ToolRunner is an async iterable that yields either BetaMessage or BetaMessageStream objects
|
|
28
|
+
* depending on the streaming configuration.
|
|
29
|
+
*/
|
|
30
|
+
export class BetaToolRunner<Stream extends boolean> {
|
|
31
|
+
/** Whether the async iterator has been consumed */
|
|
32
|
+
#consumed = false;
|
|
33
|
+
/** Whether parameters have been mutated since the last API call */
|
|
34
|
+
#mutated = false;
|
|
35
|
+
/** Current state containing the request parameters */
|
|
36
|
+
#state: { params: BetaToolRunnerParams };
|
|
37
|
+
/** Promise for the last message received from the assistant */
|
|
38
|
+
#message?: Promise<BetaMessage> | undefined;
|
|
39
|
+
/** Cached tool response to avoid redundant executions */
|
|
40
|
+
#toolResponse?: Promise<BetaMessageParam | null> | undefined;
|
|
41
|
+
/** Promise resolvers for waiting on completion */
|
|
42
|
+
#completion: {
|
|
43
|
+
promise: Promise<BetaMessage>;
|
|
44
|
+
resolve: (value: BetaMessage) => void;
|
|
45
|
+
reject: (reason?: any) => void;
|
|
46
|
+
};
|
|
47
|
+
/** Number of iterations (API requests) made so far */
|
|
48
|
+
#iterationCount = 0;
|
|
49
|
+
|
|
50
|
+
constructor(
|
|
51
|
+
private client: Anthropic,
|
|
52
|
+
params: BetaToolRunnerParams,
|
|
53
|
+
) {
|
|
54
|
+
this.#state = {
|
|
55
|
+
params: {
|
|
56
|
+
// You can't clone the entire params since there are functions as handlers.
|
|
57
|
+
// You also don't really need to clone params.messages, but it probably will prevent a foot gun
|
|
58
|
+
// somewhere.
|
|
59
|
+
...params,
|
|
60
|
+
messages: structuredClone(params.messages),
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
this.#completion = promiseWithResolvers();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async *[Symbol.asyncIterator](): AsyncIterator<
|
|
68
|
+
Stream extends true ? BetaMessageStream
|
|
69
|
+
: Stream extends false ? BetaMessage
|
|
70
|
+
: BetaMessage | BetaMessageStream
|
|
71
|
+
> {
|
|
72
|
+
if (this.#consumed) {
|
|
73
|
+
throw new AnthropicError('Cannot iterate over a consumed stream');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
this.#consumed = true;
|
|
77
|
+
this.#mutated = true;
|
|
78
|
+
this.#toolResponse = undefined;
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
while (true) {
|
|
82
|
+
let stream;
|
|
83
|
+
try {
|
|
84
|
+
if (
|
|
85
|
+
this.#state.params.max_iterations &&
|
|
86
|
+
this.#iterationCount >= this.#state.params.max_iterations
|
|
87
|
+
) {
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
this.#mutated = false;
|
|
92
|
+
this.#message = undefined;
|
|
93
|
+
this.#toolResponse = undefined;
|
|
94
|
+
this.#iterationCount++;
|
|
95
|
+
|
|
96
|
+
const { max_iterations, ...params } = this.#state.params;
|
|
97
|
+
if (params.stream) {
|
|
98
|
+
stream = this.client.beta.messages.stream({ ...params });
|
|
99
|
+
this.#message = stream.finalMessage();
|
|
100
|
+
yield stream as any;
|
|
101
|
+
} else {
|
|
102
|
+
this.#message = this.client.beta.messages.create({ ...params, stream: false });
|
|
103
|
+
yield this.#message as any;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (!this.#mutated) {
|
|
107
|
+
const { role, content } = await this.#message;
|
|
108
|
+
this.#state.params.messages.push({ role, content });
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const toolMessage = await this.#generateToolResponse(this.#state.params.messages.at(-1)!);
|
|
112
|
+
if (toolMessage) {
|
|
113
|
+
this.#state.params.messages.push(toolMessage);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (!toolMessage && !this.#mutated) {
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
} finally {
|
|
120
|
+
if (stream) {
|
|
121
|
+
stream.abort();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (!this.#message) {
|
|
127
|
+
throw new AnthropicError('ToolRunner concluded without a message from the server');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
this.#completion.resolve(await this.#message);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
this.#consumed = false;
|
|
133
|
+
// Silence unhandled promise errors
|
|
134
|
+
this.#completion.promise.catch(() => {});
|
|
135
|
+
this.#completion.reject(error);
|
|
136
|
+
this.#completion = promiseWithResolvers();
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Update the parameters for the next API call. This invalidates any cached tool responses.
|
|
143
|
+
*
|
|
144
|
+
* @param paramsOrMutator - Either new parameters or a function to mutate existing parameters
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* // Direct parameter update
|
|
148
|
+
* runner.setMessagesParams({
|
|
149
|
+
* model: 'claude-3-5-haiku-latest',
|
|
150
|
+
* max_tokens: 500,
|
|
151
|
+
* });
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* // Using a mutator function
|
|
155
|
+
* runner.setMessagesParams((params) => ({
|
|
156
|
+
* ...params,
|
|
157
|
+
* max_tokens: 100,
|
|
158
|
+
* }));
|
|
159
|
+
*/
|
|
160
|
+
setMessagesParams(params: BetaToolRunnerParams): void;
|
|
161
|
+
setMessagesParams(mutator: (prevParams: BetaToolRunnerParams) => BetaToolRunnerParams): void;
|
|
162
|
+
setMessagesParams(
|
|
163
|
+
paramsOrMutator: BetaToolRunnerParams | ((prevParams: BetaToolRunnerParams) => BetaToolRunnerParams),
|
|
164
|
+
) {
|
|
165
|
+
if (typeof paramsOrMutator === 'function') {
|
|
166
|
+
this.#state.params = paramsOrMutator(this.#state.params);
|
|
167
|
+
} else {
|
|
168
|
+
this.#state.params = paramsOrMutator;
|
|
169
|
+
}
|
|
170
|
+
this.#mutated = true;
|
|
171
|
+
// Invalidate cached tool response since parameters changed
|
|
172
|
+
this.#toolResponse = undefined;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Get the tool response for the last message from the assistant.
|
|
177
|
+
* Avoids redundant tool executions by caching results.
|
|
178
|
+
*
|
|
179
|
+
* @returns A promise that resolves to a BetaMessageParam containing tool results, or null if no tools need to be executed
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* const toolResponse = await runner.generateToolResponse();
|
|
183
|
+
* if (toolResponse) {
|
|
184
|
+
* console.log('Tool results:', toolResponse.content);
|
|
185
|
+
* }
|
|
186
|
+
*/
|
|
187
|
+
async generateToolResponse() {
|
|
188
|
+
const message = (await this.#message) ?? this.params.messages.at(-1);
|
|
189
|
+
if (!message) {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
return this.#generateToolResponse(message);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async #generateToolResponse(lastMessage: BetaMessageParam) {
|
|
196
|
+
if (this.#toolResponse !== undefined) {
|
|
197
|
+
return this.#toolResponse;
|
|
198
|
+
}
|
|
199
|
+
this.#toolResponse = generateToolResponse(this.#state.params, lastMessage);
|
|
200
|
+
return this.#toolResponse;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Wait for the async iterator to complete. This works even if the async iterator hasn't yet started, and
|
|
205
|
+
* will wait for an instance to start and go to completion.
|
|
206
|
+
*
|
|
207
|
+
* @returns A promise that resolves to the final BetaMessage when the iterator completes
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* // Start consuming the iterator
|
|
211
|
+
* for await (const message of runner) {
|
|
212
|
+
* console.log('Message:', message.content);
|
|
213
|
+
* }
|
|
214
|
+
*
|
|
215
|
+
* // Meanwhile, wait for completion from another part of the code
|
|
216
|
+
* const finalMessage = await runner.done();
|
|
217
|
+
* console.log('Final response:', finalMessage.content);
|
|
218
|
+
*/
|
|
219
|
+
done(): Promise<BetaMessage> {
|
|
220
|
+
return this.#completion.promise;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Returns a promise indicating that the stream is done. Unlike .done(), this will eagerly read the stream:
|
|
225
|
+
* * If the iterator has not been consumed, consume the entire iterator and return the final message from the
|
|
226
|
+
* assistant.
|
|
227
|
+
* * If the iterator has been consumed, waits for it to complete and returns the final message.
|
|
228
|
+
*
|
|
229
|
+
* @returns A promise that resolves to the final BetaMessage from the conversation
|
|
230
|
+
* @throws {AnthropicError} If no messages were processed during the conversation
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* const finalMessage = await runner.runUntilDone();
|
|
234
|
+
* console.log('Final response:', finalMessage.content);
|
|
235
|
+
*/
|
|
236
|
+
async runUntilDone(): Promise<BetaMessage> {
|
|
237
|
+
// If not yet consumed, start consuming and wait for completion
|
|
238
|
+
if (!this.#consumed) {
|
|
239
|
+
for await (const _ of this) {
|
|
240
|
+
// Iterator naturally populates this.#message
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// If consumed but not completed, wait for completion
|
|
245
|
+
return this.done();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Get the current parameters being used by the ToolRunner.
|
|
250
|
+
*
|
|
251
|
+
* @returns A readonly view of the current ToolRunnerParams
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* const currentParams = runner.params;
|
|
255
|
+
* console.log('Current model:', currentParams.model);
|
|
256
|
+
* console.log('Message count:', currentParams.messages.length);
|
|
257
|
+
*/
|
|
258
|
+
get params(): Readonly<BetaToolRunnerParams> {
|
|
259
|
+
return this.#state.params as Readonly<BetaToolRunnerParams>;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Add one or more messages to the conversation history.
|
|
264
|
+
*
|
|
265
|
+
* @param messages - One or more BetaMessageParam objects to add to the conversation
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* runner.pushMessages(
|
|
269
|
+
* { role: 'user', content: 'Also, what about the weather in NYC?' }
|
|
270
|
+
* );
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* // Adding multiple messages
|
|
274
|
+
* runner.pushMessages(
|
|
275
|
+
* { role: 'user', content: 'What about NYC?' },
|
|
276
|
+
* { role: 'user', content: 'And Boston?' }
|
|
277
|
+
* );
|
|
278
|
+
*/
|
|
279
|
+
pushMessages(...messages: BetaMessageParam[]) {
|
|
280
|
+
this.setMessagesParams((params) => ({
|
|
281
|
+
...params,
|
|
282
|
+
messages: [...params.messages, ...messages],
|
|
283
|
+
}));
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Makes the ToolRunner directly awaitable, equivalent to calling .runUntilDone()
|
|
288
|
+
* This allows using `await runner` instead of `await runner.runUntilDone()`
|
|
289
|
+
*/
|
|
290
|
+
then<TResult1 = BetaMessage, TResult2 = never>(
|
|
291
|
+
onfulfilled?: ((value: BetaMessage) => TResult1 | PromiseLike<TResult1>) | undefined | null,
|
|
292
|
+
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null,
|
|
293
|
+
): Promise<TResult1 | TResult2> {
|
|
294
|
+
return this.runUntilDone().then(onfulfilled, onrejected);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
async function generateToolResponse(
|
|
299
|
+
params: BetaToolRunnerParams,
|
|
300
|
+
lastMessage = params.messages.at(-1),
|
|
301
|
+
): Promise<BetaMessageParam | null> {
|
|
302
|
+
// Only process if the last message is from the assistant and has tool use blocks
|
|
303
|
+
if (
|
|
304
|
+
!lastMessage ||
|
|
305
|
+
lastMessage.role !== 'assistant' ||
|
|
306
|
+
!lastMessage.content ||
|
|
307
|
+
typeof lastMessage.content === 'string'
|
|
308
|
+
) {
|
|
309
|
+
return null;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const toolUseBlocks = lastMessage.content.filter((content) => content.type === 'tool_use');
|
|
313
|
+
if (toolUseBlocks.length === 0) {
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const toolResults = await Promise.all(
|
|
318
|
+
toolUseBlocks.map(async (toolUse) => {
|
|
319
|
+
const tool = params.tools.find((t) => t.name === toolUse.name);
|
|
320
|
+
if (!tool || !('run' in tool)) {
|
|
321
|
+
return {
|
|
322
|
+
type: 'tool_result' as const,
|
|
323
|
+
tool_use_id: toolUse.id,
|
|
324
|
+
content: `Error: Tool '${toolUse.name}' not found`,
|
|
325
|
+
is_error: true,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
try {
|
|
330
|
+
let input = toolUse.input;
|
|
331
|
+
if ('parse' in tool && tool.parse) {
|
|
332
|
+
input = tool.parse(input);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const result = await tool.run(input);
|
|
336
|
+
return {
|
|
337
|
+
type: 'tool_result' as const,
|
|
338
|
+
tool_use_id: toolUse.id,
|
|
339
|
+
content: result,
|
|
340
|
+
};
|
|
341
|
+
} catch (error) {
|
|
342
|
+
return {
|
|
343
|
+
type: 'tool_result' as const,
|
|
344
|
+
tool_use_id: toolUse.id,
|
|
345
|
+
content: `Error: ${error instanceof Error ? error.message : String(error)}`,
|
|
346
|
+
is_error: true,
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
}),
|
|
350
|
+
);
|
|
351
|
+
|
|
352
|
+
return {
|
|
353
|
+
role: 'user' as const,
|
|
354
|
+
content: toolResults,
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// vendored from typefest just to make things look a bit nicer on hover
|
|
359
|
+
type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Parameters for creating a ToolRunner, extending MessageCreateParams with runnable tools.
|
|
363
|
+
*/
|
|
364
|
+
export type BetaToolRunnerParams = Simplify<
|
|
365
|
+
Omit<MessageCreateParams, 'tools'> & {
|
|
366
|
+
tools: (BetaToolUnion | BetaRunnableTool<any>)[];
|
|
367
|
+
/**
|
|
368
|
+
* Maximum number of iterations (API requests) to make in the tool execution loop.
|
|
369
|
+
* Each iteration consists of: assistant response → tool execution → tool results.
|
|
370
|
+
* When exceeded, the loop will terminate even if tools are still being requested.
|
|
371
|
+
*/
|
|
372
|
+
max_iterations?: number;
|
|
373
|
+
}
|
|
374
|
+
>;
|
|
@@ -129,6 +129,7 @@ import {
|
|
|
129
129
|
BetaToolComputerUse20241022,
|
|
130
130
|
BetaToolComputerUse20250124,
|
|
131
131
|
BetaToolResultBlockParam,
|
|
132
|
+
BetaToolResultContentBlockParam,
|
|
132
133
|
BetaToolTextEditor20241022,
|
|
133
134
|
BetaToolTextEditor20250124,
|
|
134
135
|
BetaToolTextEditor20250429,
|
|
@@ -402,6 +403,7 @@ export declare namespace Beta {
|
|
|
402
403
|
type BetaToolComputerUse20241022 as BetaToolComputerUse20241022,
|
|
403
404
|
type BetaToolComputerUse20250124 as BetaToolComputerUse20250124,
|
|
404
405
|
type BetaToolResultBlockParam as BetaToolResultBlockParam,
|
|
406
|
+
type BetaToolResultContentBlockParam as BetaToolResultContentBlockParam,
|
|
405
407
|
type BetaToolTextEditor20241022 as BetaToolTextEditor20241022,
|
|
406
408
|
type BetaToolTextEditor20250124 as BetaToolTextEditor20250124,
|
|
407
409
|
type BetaToolTextEditor20250429 as BetaToolTextEditor20250429,
|
|
@@ -139,6 +139,7 @@ export {
|
|
|
139
139
|
type BetaToolComputerUse20241022,
|
|
140
140
|
type BetaToolComputerUse20250124,
|
|
141
141
|
type BetaToolResultBlockParam,
|
|
142
|
+
type BetaToolResultContentBlockParam,
|
|
142
143
|
type BetaToolTextEditor20241022,
|
|
143
144
|
type BetaToolTextEditor20250124,
|
|
144
145
|
type BetaToolTextEditor20250429,
|
|
@@ -132,6 +132,7 @@ export {
|
|
|
132
132
|
type BetaToolComputerUse20241022,
|
|
133
133
|
type BetaToolComputerUse20250124,
|
|
134
134
|
type BetaToolResultBlockParam,
|
|
135
|
+
type BetaToolResultContentBlockParam,
|
|
135
136
|
type BetaToolTextEditor20241022,
|
|
136
137
|
type BetaToolTextEditor20250124,
|
|
137
138
|
type BetaToolTextEditor20250429,
|
|
@@ -167,3 +168,4 @@ export {
|
|
|
167
168
|
type MessageCountTokensParams,
|
|
168
169
|
type BetaMessageStreamParams,
|
|
169
170
|
} from './messages';
|
|
171
|
+
export { BetaToolRunner, type BetaToolRunnerParams } from './messages';
|
|
@@ -30,6 +30,9 @@ import { buildHeaders } from '../../../internal/headers';
|
|
|
30
30
|
import { RequestOptions } from '../../../internal/request-options';
|
|
31
31
|
import type { Model } from '../../messages/messages';
|
|
32
32
|
import { BetaMessageStream } from '../../../lib/BetaMessageStream';
|
|
33
|
+
import { MODEL_NONSTREAMING_TOKENS } from '../../../internal/constants';
|
|
34
|
+
import { BetaToolRunner, BetaToolRunnerParams } from '../../../lib/tools/BetaToolRunner';
|
|
35
|
+
import { Anthropic } from '../../../client';
|
|
33
36
|
|
|
34
37
|
const DEPRECATED_MODELS: {
|
|
35
38
|
[K in Model]?: string;
|
|
@@ -46,7 +49,6 @@ const DEPRECATED_MODELS: {
|
|
|
46
49
|
'claude-3-5-sonnet-20241022': 'October 22, 2025',
|
|
47
50
|
'claude-3-5-sonnet-20240620': 'October 22, 2025',
|
|
48
51
|
};
|
|
49
|
-
import { MODEL_NONSTREAMING_TOKENS } from '../../../internal/constants';
|
|
50
52
|
|
|
51
53
|
export class Messages extends APIResource {
|
|
52
54
|
batches: BatchesAPI.Batches = new BatchesAPI.Batches(this._client);
|
|
@@ -148,6 +150,13 @@ export class Messages extends APIResource {
|
|
|
148
150
|
]),
|
|
149
151
|
});
|
|
150
152
|
}
|
|
153
|
+
|
|
154
|
+
toolRunner(body: BetaToolRunnerParams & { stream?: false }): BetaToolRunner<false>;
|
|
155
|
+
toolRunner(body: BetaToolRunnerParams & { stream: true }): BetaToolRunner<true>;
|
|
156
|
+
toolRunner(body: BetaToolRunnerParams): BetaToolRunner<boolean>;
|
|
157
|
+
toolRunner(body: BetaToolRunnerParams): BetaToolRunner<boolean> {
|
|
158
|
+
return new BetaToolRunner(this._client as Anthropic, body);
|
|
159
|
+
}
|
|
151
160
|
}
|
|
152
161
|
|
|
153
162
|
export type BetaMessageStreamParams = MessageCreateParamsBase;
|
|
@@ -1424,7 +1433,7 @@ export namespace BetaTool {
|
|
|
1424
1433
|
|
|
1425
1434
|
properties?: unknown | null;
|
|
1426
1435
|
|
|
1427
|
-
required?:
|
|
1436
|
+
required?: string[] | readonly string[] | null;
|
|
1428
1437
|
|
|
1429
1438
|
[k: string]: unknown;
|
|
1430
1439
|
}
|
|
@@ -1604,6 +1613,8 @@ export interface BetaToolResultBlockParam {
|
|
|
1604
1613
|
is_error?: boolean;
|
|
1605
1614
|
}
|
|
1606
1615
|
|
|
1616
|
+
export type BetaToolResultContentBlockParam = Extract<BetaToolResultBlockParam['content'], any[]>[number];
|
|
1617
|
+
|
|
1607
1618
|
export interface BetaToolTextEditor20241022 {
|
|
1608
1619
|
/**
|
|
1609
1620
|
* Name of the tool.
|
|
@@ -2550,8 +2561,12 @@ export interface MessageCountTokensParams {
|
|
|
2550
2561
|
betas?: Array<BetaAPI.AnthropicBeta>;
|
|
2551
2562
|
}
|
|
2552
2563
|
|
|
2564
|
+
export { BetaToolRunner, type BetaToolRunnerParams } from '../../../lib/tools/BetaToolRunner';
|
|
2565
|
+
|
|
2553
2566
|
Messages.Batches = Batches;
|
|
2554
2567
|
|
|
2568
|
+
Messages.BetaToolRunner = BetaToolRunner;
|
|
2569
|
+
|
|
2555
2570
|
export declare namespace Messages {
|
|
2556
2571
|
export {
|
|
2557
2572
|
type BetaBase64ImageSource as BetaBase64ImageSource,
|
|
@@ -2665,6 +2680,7 @@ export declare namespace Messages {
|
|
|
2665
2680
|
type BetaToolComputerUse20241022 as BetaToolComputerUse20241022,
|
|
2666
2681
|
type BetaToolComputerUse20250124 as BetaToolComputerUse20250124,
|
|
2667
2682
|
type BetaToolResultBlockParam as BetaToolResultBlockParam,
|
|
2683
|
+
type BetaToolResultContentBlockParam as BetaToolResultContentBlockParam,
|
|
2668
2684
|
type BetaToolTextEditor20241022 as BetaToolTextEditor20241022,
|
|
2669
2685
|
type BetaToolTextEditor20250124 as BetaToolTextEditor20250124,
|
|
2670
2686
|
type BetaToolTextEditor20250429 as BetaToolTextEditor20250429,
|
|
@@ -2700,6 +2716,8 @@ export declare namespace Messages {
|
|
|
2700
2716
|
type MessageCountTokensParams as MessageCountTokensParams,
|
|
2701
2717
|
};
|
|
2702
2718
|
|
|
2719
|
+
export { type BetaToolRunnerParams, BetaToolRunner };
|
|
2720
|
+
|
|
2703
2721
|
export {
|
|
2704
2722
|
Batches as Batches,
|
|
2705
2723
|
type BetaDeletedMessageBatch as BetaDeletedMessageBatch,
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.63.1'; // x-release-please-version
|
package/version.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.63.1";
|
|
2
2
|
//# sourceMappingURL=version.d.mts.map
|
package/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.63.1";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/version.js
CHANGED
package/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.63.1'; // x-release-please-version
|
|
2
2
|
//# sourceMappingURL=version.mjs.map
|