@ai-sdk/anthropic 1.2.10 → 2.0.0-alpha.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 +183 -19
- package/README.md +2 -2
- package/dist/index.d.mts +12 -30
- package/dist/index.d.ts +12 -30
- package/dist/index.js +345 -313
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +347 -315
- package/dist/index.mjs.map +1 -1
- package/{internal/dist → dist/internal}/index.d.mts +10 -37
- package/{internal/dist → dist/internal}/index.d.ts +10 -37
- package/{internal/dist → dist/internal}/index.js +336 -309
- package/dist/internal/index.js.map +1 -0
- package/{internal/dist → dist/internal}/index.mjs +338 -311
- package/dist/internal/index.mjs.map +1 -0
- package/internal.d.ts +1 -0
- package/package.json +19 -17
- package/internal/dist/index.js.map +0 -1
- package/internal/dist/index.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -15,11 +15,11 @@ import {
|
|
|
15
15
|
combineHeaders,
|
|
16
16
|
createEventSourceResponseHandler,
|
|
17
17
|
createJsonResponseHandler,
|
|
18
|
-
parseProviderOptions,
|
|
18
|
+
parseProviderOptions as parseProviderOptions2,
|
|
19
19
|
postJsonToApi,
|
|
20
20
|
resolve
|
|
21
21
|
} from "@ai-sdk/provider-utils";
|
|
22
|
-
import { z as
|
|
22
|
+
import { z as z3 } from "zod";
|
|
23
23
|
|
|
24
24
|
// src/anthropic-error.ts
|
|
25
25
|
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
@@ -36,17 +36,34 @@ var anthropicFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
36
36
|
errorToMessage: (data) => data.error.message
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
+
// src/anthropic-messages-options.ts
|
|
40
|
+
import { z as z2 } from "zod";
|
|
41
|
+
var anthropicProviderOptions = z2.object({
|
|
42
|
+
/**
|
|
43
|
+
Include reasoning content in requests sent to the model. Defaults to `true`.
|
|
44
|
+
|
|
45
|
+
If you are experiencing issues with the model handling requests involving
|
|
46
|
+
*/
|
|
47
|
+
sendReasoning: z2.boolean().optional(),
|
|
48
|
+
thinking: z2.object({
|
|
49
|
+
type: z2.union([z2.literal("enabled"), z2.literal("disabled")]),
|
|
50
|
+
budgetTokens: z2.number().optional()
|
|
51
|
+
}).optional()
|
|
52
|
+
});
|
|
53
|
+
|
|
39
54
|
// src/anthropic-prepare-tools.ts
|
|
40
55
|
import {
|
|
41
56
|
UnsupportedFunctionalityError
|
|
42
57
|
} from "@ai-sdk/provider";
|
|
43
|
-
function prepareTools(
|
|
44
|
-
|
|
45
|
-
|
|
58
|
+
function prepareTools({
|
|
59
|
+
tools,
|
|
60
|
+
toolChoice
|
|
61
|
+
}) {
|
|
62
|
+
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
46
63
|
const toolWarnings = [];
|
|
47
64
|
const betas = /* @__PURE__ */ new Set();
|
|
48
65
|
if (tools == null) {
|
|
49
|
-
return { tools: void 0,
|
|
66
|
+
return { tools: void 0, toolChoice: void 0, toolWarnings, betas };
|
|
50
67
|
}
|
|
51
68
|
const anthropicTools2 = [];
|
|
52
69
|
for (const tool of tools) {
|
|
@@ -118,11 +135,10 @@ function prepareTools(mode) {
|
|
|
118
135
|
break;
|
|
119
136
|
}
|
|
120
137
|
}
|
|
121
|
-
const toolChoice = mode.toolChoice;
|
|
122
138
|
if (toolChoice == null) {
|
|
123
139
|
return {
|
|
124
140
|
tools: anthropicTools2,
|
|
125
|
-
|
|
141
|
+
toolChoice: void 0,
|
|
126
142
|
toolWarnings,
|
|
127
143
|
betas
|
|
128
144
|
};
|
|
@@ -132,30 +148,30 @@ function prepareTools(mode) {
|
|
|
132
148
|
case "auto":
|
|
133
149
|
return {
|
|
134
150
|
tools: anthropicTools2,
|
|
135
|
-
|
|
151
|
+
toolChoice: { type: "auto" },
|
|
136
152
|
toolWarnings,
|
|
137
153
|
betas
|
|
138
154
|
};
|
|
139
155
|
case "required":
|
|
140
156
|
return {
|
|
141
157
|
tools: anthropicTools2,
|
|
142
|
-
|
|
158
|
+
toolChoice: { type: "any" },
|
|
143
159
|
toolWarnings,
|
|
144
160
|
betas
|
|
145
161
|
};
|
|
146
162
|
case "none":
|
|
147
|
-
return { tools: void 0,
|
|
163
|
+
return { tools: void 0, toolChoice: void 0, toolWarnings, betas };
|
|
148
164
|
case "tool":
|
|
149
165
|
return {
|
|
150
166
|
tools: anthropicTools2,
|
|
151
|
-
|
|
167
|
+
toolChoice: { type: "tool", name: toolChoice.toolName },
|
|
152
168
|
toolWarnings,
|
|
153
169
|
betas
|
|
154
170
|
};
|
|
155
171
|
default: {
|
|
156
172
|
const _exhaustiveCheck = type;
|
|
157
173
|
throw new UnsupportedFunctionalityError({
|
|
158
|
-
functionality: `
|
|
174
|
+
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
159
175
|
});
|
|
160
176
|
}
|
|
161
177
|
}
|
|
@@ -165,13 +181,13 @@ function prepareTools(mode) {
|
|
|
165
181
|
import {
|
|
166
182
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
167
183
|
} from "@ai-sdk/provider";
|
|
168
|
-
import {
|
|
169
|
-
function convertToAnthropicMessagesPrompt({
|
|
184
|
+
import { convertToBase64, parseProviderOptions } from "@ai-sdk/provider-utils";
|
|
185
|
+
async function convertToAnthropicMessagesPrompt({
|
|
170
186
|
prompt,
|
|
171
187
|
sendReasoning,
|
|
172
188
|
warnings
|
|
173
189
|
}) {
|
|
174
|
-
var _a, _b, _c
|
|
190
|
+
var _a, _b, _c;
|
|
175
191
|
const betas = /* @__PURE__ */ new Set();
|
|
176
192
|
const blocks = groupIntoBlocks(prompt);
|
|
177
193
|
let system = void 0;
|
|
@@ -193,10 +209,10 @@ function convertToAnthropicMessagesPrompt({
|
|
|
193
209
|
functionality: "Multiple system messages that are separated by user/assistant messages"
|
|
194
210
|
});
|
|
195
211
|
}
|
|
196
|
-
system = block.messages.map(({ content,
|
|
212
|
+
system = block.messages.map(({ content, providerOptions }) => ({
|
|
197
213
|
type: "text",
|
|
198
214
|
text: content,
|
|
199
|
-
cache_control: getCacheControl(
|
|
215
|
+
cache_control: getCacheControl(providerOptions)
|
|
200
216
|
}));
|
|
201
217
|
break;
|
|
202
218
|
}
|
|
@@ -209,7 +225,7 @@ function convertToAnthropicMessagesPrompt({
|
|
|
209
225
|
for (let j = 0; j < content.length; j++) {
|
|
210
226
|
const part = content[j];
|
|
211
227
|
const isLastPart = j === content.length - 1;
|
|
212
|
-
const cacheControl = (_a = getCacheControl(part.
|
|
228
|
+
const cacheControl = (_a = getCacheControl(part.providerOptions)) != null ? _a : isLastPart ? getCacheControl(message.providerOptions) : void 0;
|
|
213
229
|
switch (part.type) {
|
|
214
230
|
case "text": {
|
|
215
231
|
anthropicContent.push({
|
|
@@ -219,40 +235,39 @@ function convertToAnthropicMessagesPrompt({
|
|
|
219
235
|
});
|
|
220
236
|
break;
|
|
221
237
|
}
|
|
222
|
-
case "image": {
|
|
223
|
-
anthropicContent.push({
|
|
224
|
-
type: "image",
|
|
225
|
-
source: part.image instanceof URL ? {
|
|
226
|
-
type: "url",
|
|
227
|
-
url: part.image.toString()
|
|
228
|
-
} : {
|
|
229
|
-
type: "base64",
|
|
230
|
-
media_type: (_b = part.mimeType) != null ? _b : "image/jpeg",
|
|
231
|
-
data: convertUint8ArrayToBase64(part.image)
|
|
232
|
-
},
|
|
233
|
-
cache_control: cacheControl
|
|
234
|
-
});
|
|
235
|
-
break;
|
|
236
|
-
}
|
|
237
238
|
case "file": {
|
|
238
|
-
if (part.
|
|
239
|
+
if (part.mediaType.startsWith("image/")) {
|
|
240
|
+
anthropicContent.push({
|
|
241
|
+
type: "image",
|
|
242
|
+
source: part.data instanceof URL ? {
|
|
243
|
+
type: "url",
|
|
244
|
+
url: part.data.toString()
|
|
245
|
+
} : {
|
|
246
|
+
type: "base64",
|
|
247
|
+
media_type: part.mediaType === "image/*" ? "image/jpeg" : part.mediaType,
|
|
248
|
+
data: convertToBase64(part.data)
|
|
249
|
+
},
|
|
250
|
+
cache_control: cacheControl
|
|
251
|
+
});
|
|
252
|
+
} else if (part.mediaType === "application/pdf") {
|
|
253
|
+
betas.add("pdfs-2024-09-25");
|
|
254
|
+
anthropicContent.push({
|
|
255
|
+
type: "document",
|
|
256
|
+
source: part.data instanceof URL ? {
|
|
257
|
+
type: "url",
|
|
258
|
+
url: part.data.toString()
|
|
259
|
+
} : {
|
|
260
|
+
type: "base64",
|
|
261
|
+
media_type: "application/pdf",
|
|
262
|
+
data: convertToBase64(part.data)
|
|
263
|
+
},
|
|
264
|
+
cache_control: cacheControl
|
|
265
|
+
});
|
|
266
|
+
} else {
|
|
239
267
|
throw new UnsupportedFunctionalityError2({
|
|
240
|
-
functionality:
|
|
268
|
+
functionality: `media type: ${part.mediaType}`
|
|
241
269
|
});
|
|
242
270
|
}
|
|
243
|
-
betas.add("pdfs-2024-09-25");
|
|
244
|
-
anthropicContent.push({
|
|
245
|
-
type: "document",
|
|
246
|
-
source: part.data instanceof URL ? {
|
|
247
|
-
type: "url",
|
|
248
|
-
url: part.data.toString()
|
|
249
|
-
} : {
|
|
250
|
-
type: "base64",
|
|
251
|
-
media_type: "application/pdf",
|
|
252
|
-
data: part.data
|
|
253
|
-
},
|
|
254
|
-
cache_control: cacheControl
|
|
255
|
-
});
|
|
256
271
|
break;
|
|
257
272
|
}
|
|
258
273
|
}
|
|
@@ -263,7 +278,7 @@ function convertToAnthropicMessagesPrompt({
|
|
|
263
278
|
for (let i2 = 0; i2 < content.length; i2++) {
|
|
264
279
|
const part = content[i2];
|
|
265
280
|
const isLastPart = i2 === content.length - 1;
|
|
266
|
-
const cacheControl = (
|
|
281
|
+
const cacheControl = (_b = getCacheControl(part.providerOptions)) != null ? _b : isLastPart ? getCacheControl(message.providerOptions) : void 0;
|
|
267
282
|
const toolResultContent = part.content != null ? part.content.map((part2) => {
|
|
268
283
|
var _a2;
|
|
269
284
|
switch (part2.type) {
|
|
@@ -278,7 +293,7 @@ function convertToAnthropicMessagesPrompt({
|
|
|
278
293
|
type: "image",
|
|
279
294
|
source: {
|
|
280
295
|
type: "base64",
|
|
281
|
-
media_type: (_a2 = part2.
|
|
296
|
+
media_type: (_a2 = part2.mediaType) != null ? _a2 : "image/jpeg",
|
|
282
297
|
data: part2.data
|
|
283
298
|
},
|
|
284
299
|
cache_control: void 0
|
|
@@ -313,7 +328,7 @@ function convertToAnthropicMessagesPrompt({
|
|
|
313
328
|
for (let k = 0; k < content.length; k++) {
|
|
314
329
|
const part = content[k];
|
|
315
330
|
const isLastContentPart = k === content.length - 1;
|
|
316
|
-
const cacheControl = (
|
|
331
|
+
const cacheControl = (_c = getCacheControl(part.providerOptions)) != null ? _c : isLastContentPart ? getCacheControl(message.providerOptions) : void 0;
|
|
317
332
|
switch (part.type) {
|
|
318
333
|
case "text": {
|
|
319
334
|
anthropicContent.push({
|
|
@@ -330,12 +345,37 @@ function convertToAnthropicMessagesPrompt({
|
|
|
330
345
|
}
|
|
331
346
|
case "reasoning": {
|
|
332
347
|
if (sendReasoning) {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
cache_control: cacheControl
|
|
348
|
+
const reasoningMetadata = await parseProviderOptions({
|
|
349
|
+
provider: "anthropic",
|
|
350
|
+
providerOptions: part.providerOptions,
|
|
351
|
+
schema: anthropicReasoningMetadataSchema
|
|
338
352
|
});
|
|
353
|
+
if (reasoningMetadata != null) {
|
|
354
|
+
if (reasoningMetadata.signature != null) {
|
|
355
|
+
anthropicContent.push({
|
|
356
|
+
type: "thinking",
|
|
357
|
+
thinking: part.text,
|
|
358
|
+
signature: reasoningMetadata.signature,
|
|
359
|
+
cache_control: cacheControl
|
|
360
|
+
});
|
|
361
|
+
} else if (reasoningMetadata.redactedData != null) {
|
|
362
|
+
anthropicContent.push({
|
|
363
|
+
type: "redacted_thinking",
|
|
364
|
+
data: reasoningMetadata.redactedData,
|
|
365
|
+
cache_control: cacheControl
|
|
366
|
+
});
|
|
367
|
+
} else {
|
|
368
|
+
warnings.push({
|
|
369
|
+
type: "other",
|
|
370
|
+
message: "unsupported reasoning metadata"
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
} else {
|
|
374
|
+
warnings.push({
|
|
375
|
+
type: "other",
|
|
376
|
+
message: "unsupported reasoning metadata"
|
|
377
|
+
});
|
|
378
|
+
}
|
|
339
379
|
} else {
|
|
340
380
|
warnings.push({
|
|
341
381
|
type: "other",
|
|
@@ -344,14 +384,6 @@ function convertToAnthropicMessagesPrompt({
|
|
|
344
384
|
}
|
|
345
385
|
break;
|
|
346
386
|
}
|
|
347
|
-
case "redacted-reasoning": {
|
|
348
|
-
anthropicContent.push({
|
|
349
|
-
type: "redacted_thinking",
|
|
350
|
-
data: part.data,
|
|
351
|
-
cache_control: cacheControl
|
|
352
|
-
});
|
|
353
|
-
break;
|
|
354
|
-
}
|
|
355
387
|
case "tool-call": {
|
|
356
388
|
anthropicContent.push({
|
|
357
389
|
type: "tool_use",
|
|
@@ -370,7 +402,7 @@ function convertToAnthropicMessagesPrompt({
|
|
|
370
402
|
}
|
|
371
403
|
default: {
|
|
372
404
|
const _exhaustiveCheck = type;
|
|
373
|
-
throw new Error(`
|
|
405
|
+
throw new Error(`content type: ${_exhaustiveCheck}`);
|
|
374
406
|
}
|
|
375
407
|
}
|
|
376
408
|
}
|
|
@@ -443,11 +475,9 @@ function mapAnthropicStopReason(finishReason) {
|
|
|
443
475
|
|
|
444
476
|
// src/anthropic-messages-language-model.ts
|
|
445
477
|
var AnthropicMessagesLanguageModel = class {
|
|
446
|
-
constructor(modelId,
|
|
447
|
-
this.specificationVersion = "
|
|
448
|
-
this.defaultObjectGenerationMode = "tool";
|
|
478
|
+
constructor(modelId, config) {
|
|
479
|
+
this.specificationVersion = "v2";
|
|
449
480
|
this.modelId = modelId;
|
|
450
|
-
this.settings = settings;
|
|
451
481
|
this.config = config;
|
|
452
482
|
}
|
|
453
483
|
supportsUrl(url) {
|
|
@@ -456,13 +486,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
456
486
|
get provider() {
|
|
457
487
|
return this.config.provider;
|
|
458
488
|
}
|
|
459
|
-
get
|
|
460
|
-
|
|
489
|
+
get supportedUrls() {
|
|
490
|
+
var _a, _b, _c;
|
|
491
|
+
return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
|
|
461
492
|
}
|
|
462
493
|
async getArgs({
|
|
463
|
-
mode,
|
|
464
494
|
prompt,
|
|
465
|
-
|
|
495
|
+
maxOutputTokens = 4096,
|
|
466
496
|
// 4096: max model output tokens TODO update default in v5
|
|
467
497
|
temperature,
|
|
468
498
|
topP,
|
|
@@ -472,10 +502,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
472
502
|
stopSequences,
|
|
473
503
|
responseFormat,
|
|
474
504
|
seed,
|
|
475
|
-
|
|
505
|
+
tools,
|
|
506
|
+
toolChoice,
|
|
507
|
+
providerOptions
|
|
476
508
|
}) {
|
|
477
509
|
var _a, _b, _c;
|
|
478
|
-
const type = mode.type;
|
|
479
510
|
const warnings = [];
|
|
480
511
|
if (frequencyPenalty != null) {
|
|
481
512
|
warnings.push({
|
|
@@ -502,15 +533,15 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
502
533
|
details: "JSON response format is not supported."
|
|
503
534
|
});
|
|
504
535
|
}
|
|
505
|
-
const
|
|
506
|
-
prompt,
|
|
507
|
-
sendReasoning: (_a = this.settings.sendReasoning) != null ? _a : true,
|
|
508
|
-
warnings
|
|
509
|
-
});
|
|
510
|
-
const anthropicOptions = parseProviderOptions({
|
|
536
|
+
const anthropicOptions = await parseProviderOptions2({
|
|
511
537
|
provider: "anthropic",
|
|
512
538
|
providerOptions,
|
|
513
|
-
schema:
|
|
539
|
+
schema: anthropicProviderOptions
|
|
540
|
+
});
|
|
541
|
+
const { prompt: messagesPrompt, betas: messagesBetas } = await convertToAnthropicMessagesPrompt({
|
|
542
|
+
prompt,
|
|
543
|
+
sendReasoning: (_a = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _a : true,
|
|
544
|
+
warnings
|
|
514
545
|
});
|
|
515
546
|
const isThinking = ((_b = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _b.type) === "enabled";
|
|
516
547
|
const thinkingBudget = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.budgetTokens;
|
|
@@ -518,7 +549,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
518
549
|
// model id:
|
|
519
550
|
model: this.modelId,
|
|
520
551
|
// standardized settings:
|
|
521
|
-
max_tokens:
|
|
552
|
+
max_tokens: maxOutputTokens,
|
|
522
553
|
temperature,
|
|
523
554
|
top_k: topK,
|
|
524
555
|
top_p: topP,
|
|
@@ -561,44 +592,23 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
561
592
|
details: "topP is not supported when thinking is enabled"
|
|
562
593
|
});
|
|
563
594
|
}
|
|
564
|
-
baseArgs.max_tokens =
|
|
565
|
-
}
|
|
566
|
-
switch (type) {
|
|
567
|
-
case "regular": {
|
|
568
|
-
const {
|
|
569
|
-
tools,
|
|
570
|
-
tool_choice,
|
|
571
|
-
toolWarnings,
|
|
572
|
-
betas: toolsBetas
|
|
573
|
-
} = prepareTools(mode);
|
|
574
|
-
return {
|
|
575
|
-
args: { ...baseArgs, tools, tool_choice },
|
|
576
|
-
warnings: [...warnings, ...toolWarnings],
|
|
577
|
-
betas: /* @__PURE__ */ new Set([...messagesBetas, ...toolsBetas])
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
case "object-json": {
|
|
581
|
-
throw new UnsupportedFunctionalityError3({
|
|
582
|
-
functionality: "json-mode object generation"
|
|
583
|
-
});
|
|
584
|
-
}
|
|
585
|
-
case "object-tool": {
|
|
586
|
-
const { name, description, parameters } = mode.tool;
|
|
587
|
-
return {
|
|
588
|
-
args: {
|
|
589
|
-
...baseArgs,
|
|
590
|
-
tools: [{ name, description, input_schema: parameters }],
|
|
591
|
-
tool_choice: { type: "tool", name }
|
|
592
|
-
},
|
|
593
|
-
warnings,
|
|
594
|
-
betas: messagesBetas
|
|
595
|
-
};
|
|
596
|
-
}
|
|
597
|
-
default: {
|
|
598
|
-
const _exhaustiveCheck = type;
|
|
599
|
-
throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
|
|
600
|
-
}
|
|
595
|
+
baseArgs.max_tokens = maxOutputTokens + thinkingBudget;
|
|
601
596
|
}
|
|
597
|
+
const {
|
|
598
|
+
tools: anthropicTools2,
|
|
599
|
+
toolChoice: anthropicToolChoice,
|
|
600
|
+
toolWarnings,
|
|
601
|
+
betas: toolsBetas
|
|
602
|
+
} = prepareTools({ tools, toolChoice });
|
|
603
|
+
return {
|
|
604
|
+
args: {
|
|
605
|
+
...baseArgs,
|
|
606
|
+
tools: anthropicTools2,
|
|
607
|
+
tool_choice: anthropicToolChoice
|
|
608
|
+
},
|
|
609
|
+
warnings: [...warnings, ...toolWarnings],
|
|
610
|
+
betas: /* @__PURE__ */ new Set([...messagesBetas, ...toolsBetas])
|
|
611
|
+
};
|
|
602
612
|
}
|
|
603
613
|
async getHeaders({
|
|
604
614
|
betas,
|
|
@@ -636,65 +646,71 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
636
646
|
abortSignal: options.abortSignal,
|
|
637
647
|
fetch: this.config.fetch
|
|
638
648
|
});
|
|
639
|
-
const
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
649
|
+
const content = [];
|
|
650
|
+
for (const part of response.content) {
|
|
651
|
+
switch (part.type) {
|
|
652
|
+
case "text": {
|
|
653
|
+
content.push({ type: "text", text: part.text });
|
|
654
|
+
break;
|
|
655
|
+
}
|
|
656
|
+
case "thinking": {
|
|
657
|
+
content.push({
|
|
658
|
+
type: "reasoning",
|
|
659
|
+
text: part.thinking,
|
|
660
|
+
providerMetadata: {
|
|
661
|
+
anthropic: {
|
|
662
|
+
signature: part.signature
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
});
|
|
666
|
+
break;
|
|
667
|
+
}
|
|
668
|
+
case "redacted_thinking": {
|
|
669
|
+
content.push({
|
|
670
|
+
type: "reasoning",
|
|
671
|
+
text: "",
|
|
672
|
+
providerMetadata: {
|
|
673
|
+
anthropic: {
|
|
674
|
+
redactedData: part.data
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
});
|
|
678
|
+
break;
|
|
679
|
+
}
|
|
680
|
+
case "tool_use": {
|
|
681
|
+
content.push({
|
|
682
|
+
type: "tool-call",
|
|
652
683
|
toolCallType: "function",
|
|
653
|
-
toolCallId:
|
|
654
|
-
toolName:
|
|
655
|
-
args: JSON.stringify(
|
|
684
|
+
toolCallId: part.id,
|
|
685
|
+
toolName: part.name,
|
|
686
|
+
args: JSON.stringify(part.input)
|
|
656
687
|
});
|
|
688
|
+
break;
|
|
657
689
|
}
|
|
658
690
|
}
|
|
659
691
|
}
|
|
660
|
-
const reasoning = response.content.filter(
|
|
661
|
-
(content) => content.type === "redacted_thinking" || content.type === "thinking"
|
|
662
|
-
).map(
|
|
663
|
-
(content) => content.type === "thinking" ? {
|
|
664
|
-
type: "text",
|
|
665
|
-
text: content.thinking,
|
|
666
|
-
signature: content.signature
|
|
667
|
-
} : {
|
|
668
|
-
type: "redacted",
|
|
669
|
-
data: content.data
|
|
670
|
-
}
|
|
671
|
-
);
|
|
672
692
|
return {
|
|
673
|
-
|
|
674
|
-
reasoning: reasoning.length > 0 ? reasoning : void 0,
|
|
675
|
-
toolCalls,
|
|
693
|
+
content,
|
|
676
694
|
finishReason: mapAnthropicStopReason(response.stop_reason),
|
|
677
695
|
usage: {
|
|
678
|
-
|
|
679
|
-
|
|
696
|
+
inputTokens: response.usage.input_tokens,
|
|
697
|
+
outputTokens: response.usage.output_tokens,
|
|
698
|
+
totalTokens: response.usage.input_tokens + response.usage.output_tokens,
|
|
699
|
+
cachedInputTokens: (_a = response.usage.cache_read_input_tokens) != null ? _a : void 0
|
|
680
700
|
},
|
|
681
|
-
|
|
682
|
-
|
|
701
|
+
request: { body: args },
|
|
702
|
+
response: {
|
|
703
|
+
id: (_b = response.id) != null ? _b : void 0,
|
|
704
|
+
modelId: (_c = response.model) != null ? _c : void 0,
|
|
683
705
|
headers: responseHeaders,
|
|
684
706
|
body: rawResponse
|
|
685
707
|
},
|
|
686
|
-
response: {
|
|
687
|
-
id: (_a = response.id) != null ? _a : void 0,
|
|
688
|
-
modelId: (_b = response.model) != null ? _b : void 0
|
|
689
|
-
},
|
|
690
708
|
warnings,
|
|
691
709
|
providerMetadata: {
|
|
692
710
|
anthropic: {
|
|
693
|
-
cacheCreationInputTokens: (
|
|
694
|
-
cacheReadInputTokens: (_d = response.usage.cache_read_input_tokens) != null ? _d : null
|
|
711
|
+
cacheCreationInputTokens: (_d = response.usage.cache_creation_input_tokens) != null ? _d : null
|
|
695
712
|
}
|
|
696
|
-
}
|
|
697
|
-
request: { body: JSON.stringify(args) }
|
|
713
|
+
}
|
|
698
714
|
};
|
|
699
715
|
}
|
|
700
716
|
async doStream(options) {
|
|
@@ -711,11 +727,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
711
727
|
abortSignal: options.abortSignal,
|
|
712
728
|
fetch: this.config.fetch
|
|
713
729
|
});
|
|
714
|
-
const { messages: rawPrompt, ...rawSettings } = args;
|
|
715
730
|
let finishReason = "unknown";
|
|
716
731
|
const usage = {
|
|
717
|
-
|
|
718
|
-
|
|
732
|
+
inputTokens: void 0,
|
|
733
|
+
outputTokens: void 0,
|
|
734
|
+
totalTokens: void 0
|
|
719
735
|
};
|
|
720
736
|
const toolCallContentBlocks = {};
|
|
721
737
|
let providerMetadata = void 0;
|
|
@@ -723,8 +739,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
723
739
|
return {
|
|
724
740
|
stream: response.pipeThrough(
|
|
725
741
|
new TransformStream({
|
|
742
|
+
start(controller) {
|
|
743
|
+
controller.enqueue({ type: "stream-start", warnings });
|
|
744
|
+
},
|
|
726
745
|
transform(chunk, controller) {
|
|
727
|
-
var _a, _b, _c, _d;
|
|
746
|
+
var _a, _b, _c, _d, _e, _f;
|
|
728
747
|
if (!chunk.success) {
|
|
729
748
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
730
749
|
return;
|
|
@@ -744,9 +763,15 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
744
763
|
}
|
|
745
764
|
case "redacted_thinking": {
|
|
746
765
|
controller.enqueue({
|
|
747
|
-
type: "
|
|
748
|
-
|
|
766
|
+
type: "reasoning",
|
|
767
|
+
text: "",
|
|
768
|
+
providerMetadata: {
|
|
769
|
+
anthropic: {
|
|
770
|
+
redactedData: value.content_block.data
|
|
771
|
+
}
|
|
772
|
+
}
|
|
749
773
|
});
|
|
774
|
+
controller.enqueue({ type: "reasoning-part-finish" });
|
|
750
775
|
return;
|
|
751
776
|
}
|
|
752
777
|
case "tool_use": {
|
|
@@ -785,24 +810,30 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
785
810
|
switch (deltaType) {
|
|
786
811
|
case "text_delta": {
|
|
787
812
|
controller.enqueue({
|
|
788
|
-
type: "text
|
|
789
|
-
|
|
813
|
+
type: "text",
|
|
814
|
+
text: value.delta.text
|
|
790
815
|
});
|
|
791
816
|
return;
|
|
792
817
|
}
|
|
793
818
|
case "thinking_delta": {
|
|
794
819
|
controller.enqueue({
|
|
795
820
|
type: "reasoning",
|
|
796
|
-
|
|
821
|
+
text: value.delta.thinking
|
|
797
822
|
});
|
|
798
823
|
return;
|
|
799
824
|
}
|
|
800
825
|
case "signature_delta": {
|
|
801
826
|
if (blockType === "thinking") {
|
|
802
827
|
controller.enqueue({
|
|
803
|
-
type: "reasoning
|
|
804
|
-
|
|
828
|
+
type: "reasoning",
|
|
829
|
+
text: "",
|
|
830
|
+
providerMetadata: {
|
|
831
|
+
anthropic: {
|
|
832
|
+
signature: value.delta.signature
|
|
833
|
+
}
|
|
834
|
+
}
|
|
805
835
|
});
|
|
836
|
+
controller.enqueue({ type: "reasoning-part-finish" });
|
|
806
837
|
}
|
|
807
838
|
return;
|
|
808
839
|
}
|
|
@@ -827,12 +858,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
827
858
|
}
|
|
828
859
|
}
|
|
829
860
|
case "message_start": {
|
|
830
|
-
usage.
|
|
831
|
-
usage.
|
|
861
|
+
usage.inputTokens = value.message.usage.input_tokens;
|
|
862
|
+
usage.cachedInputTokens = (_a = value.message.usage.cache_read_input_tokens) != null ? _a : void 0;
|
|
832
863
|
providerMetadata = {
|
|
833
864
|
anthropic: {
|
|
834
|
-
cacheCreationInputTokens: (
|
|
835
|
-
cacheReadInputTokens: (_b = value.message.usage.cache_read_input_tokens) != null ? _b : null
|
|
865
|
+
cacheCreationInputTokens: (_b = value.message.usage.cache_creation_input_tokens) != null ? _b : null
|
|
836
866
|
}
|
|
837
867
|
};
|
|
838
868
|
controller.enqueue({
|
|
@@ -843,7 +873,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
843
873
|
return;
|
|
844
874
|
}
|
|
845
875
|
case "message_delta": {
|
|
846
|
-
usage.
|
|
876
|
+
usage.outputTokens = value.usage.output_tokens;
|
|
877
|
+
usage.totalTokens = ((_e = usage.inputTokens) != null ? _e : 0) + ((_f = value.usage.output_tokens) != null ? _f : 0);
|
|
847
878
|
finishReason = mapAnthropicStopReason(value.delta.stop_reason);
|
|
848
879
|
return;
|
|
849
880
|
}
|
|
@@ -868,142 +899,138 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
868
899
|
}
|
|
869
900
|
})
|
|
870
901
|
),
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
warnings,
|
|
874
|
-
request: { body: JSON.stringify(body) }
|
|
902
|
+
request: { body },
|
|
903
|
+
response: { headers: responseHeaders }
|
|
875
904
|
};
|
|
876
905
|
}
|
|
877
906
|
};
|
|
878
|
-
var anthropicMessagesResponseSchema =
|
|
879
|
-
type:
|
|
880
|
-
id:
|
|
881
|
-
model:
|
|
882
|
-
content:
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
type:
|
|
886
|
-
text:
|
|
907
|
+
var anthropicMessagesResponseSchema = z3.object({
|
|
908
|
+
type: z3.literal("message"),
|
|
909
|
+
id: z3.string().nullish(),
|
|
910
|
+
model: z3.string().nullish(),
|
|
911
|
+
content: z3.array(
|
|
912
|
+
z3.discriminatedUnion("type", [
|
|
913
|
+
z3.object({
|
|
914
|
+
type: z3.literal("text"),
|
|
915
|
+
text: z3.string()
|
|
887
916
|
}),
|
|
888
|
-
|
|
889
|
-
type:
|
|
890
|
-
thinking:
|
|
891
|
-
signature:
|
|
917
|
+
z3.object({
|
|
918
|
+
type: z3.literal("thinking"),
|
|
919
|
+
thinking: z3.string(),
|
|
920
|
+
signature: z3.string()
|
|
892
921
|
}),
|
|
893
|
-
|
|
894
|
-
type:
|
|
895
|
-
data:
|
|
922
|
+
z3.object({
|
|
923
|
+
type: z3.literal("redacted_thinking"),
|
|
924
|
+
data: z3.string()
|
|
896
925
|
}),
|
|
897
|
-
|
|
898
|
-
type:
|
|
899
|
-
id:
|
|
900
|
-
name:
|
|
901
|
-
input:
|
|
926
|
+
z3.object({
|
|
927
|
+
type: z3.literal("tool_use"),
|
|
928
|
+
id: z3.string(),
|
|
929
|
+
name: z3.string(),
|
|
930
|
+
input: z3.unknown()
|
|
902
931
|
})
|
|
903
932
|
])
|
|
904
933
|
),
|
|
905
|
-
stop_reason:
|
|
906
|
-
usage:
|
|
907
|
-
input_tokens:
|
|
908
|
-
output_tokens:
|
|
909
|
-
cache_creation_input_tokens:
|
|
910
|
-
cache_read_input_tokens:
|
|
934
|
+
stop_reason: z3.string().nullish(),
|
|
935
|
+
usage: z3.object({
|
|
936
|
+
input_tokens: z3.number(),
|
|
937
|
+
output_tokens: z3.number(),
|
|
938
|
+
cache_creation_input_tokens: z3.number().nullish(),
|
|
939
|
+
cache_read_input_tokens: z3.number().nullish()
|
|
911
940
|
})
|
|
912
941
|
});
|
|
913
|
-
var anthropicMessagesChunkSchema =
|
|
914
|
-
|
|
915
|
-
type:
|
|
916
|
-
message:
|
|
917
|
-
id:
|
|
918
|
-
model:
|
|
919
|
-
usage:
|
|
920
|
-
input_tokens:
|
|
921
|
-
output_tokens:
|
|
922
|
-
cache_creation_input_tokens:
|
|
923
|
-
cache_read_input_tokens:
|
|
942
|
+
var anthropicMessagesChunkSchema = z3.discriminatedUnion("type", [
|
|
943
|
+
z3.object({
|
|
944
|
+
type: z3.literal("message_start"),
|
|
945
|
+
message: z3.object({
|
|
946
|
+
id: z3.string().nullish(),
|
|
947
|
+
model: z3.string().nullish(),
|
|
948
|
+
usage: z3.object({
|
|
949
|
+
input_tokens: z3.number(),
|
|
950
|
+
output_tokens: z3.number(),
|
|
951
|
+
cache_creation_input_tokens: z3.number().nullish(),
|
|
952
|
+
cache_read_input_tokens: z3.number().nullish()
|
|
924
953
|
})
|
|
925
954
|
})
|
|
926
955
|
}),
|
|
927
|
-
|
|
928
|
-
type:
|
|
929
|
-
index:
|
|
930
|
-
content_block:
|
|
931
|
-
|
|
932
|
-
type:
|
|
933
|
-
text:
|
|
956
|
+
z3.object({
|
|
957
|
+
type: z3.literal("content_block_start"),
|
|
958
|
+
index: z3.number(),
|
|
959
|
+
content_block: z3.discriminatedUnion("type", [
|
|
960
|
+
z3.object({
|
|
961
|
+
type: z3.literal("text"),
|
|
962
|
+
text: z3.string()
|
|
934
963
|
}),
|
|
935
|
-
|
|
936
|
-
type:
|
|
937
|
-
thinking:
|
|
964
|
+
z3.object({
|
|
965
|
+
type: z3.literal("thinking"),
|
|
966
|
+
thinking: z3.string()
|
|
938
967
|
}),
|
|
939
|
-
|
|
940
|
-
type:
|
|
941
|
-
id:
|
|
942
|
-
name:
|
|
968
|
+
z3.object({
|
|
969
|
+
type: z3.literal("tool_use"),
|
|
970
|
+
id: z3.string(),
|
|
971
|
+
name: z3.string()
|
|
943
972
|
}),
|
|
944
|
-
|
|
945
|
-
type:
|
|
946
|
-
data:
|
|
973
|
+
z3.object({
|
|
974
|
+
type: z3.literal("redacted_thinking"),
|
|
975
|
+
data: z3.string()
|
|
947
976
|
})
|
|
948
977
|
])
|
|
949
978
|
}),
|
|
950
|
-
|
|
951
|
-
type:
|
|
952
|
-
index:
|
|
953
|
-
delta:
|
|
954
|
-
|
|
955
|
-
type:
|
|
956
|
-
partial_json:
|
|
979
|
+
z3.object({
|
|
980
|
+
type: z3.literal("content_block_delta"),
|
|
981
|
+
index: z3.number(),
|
|
982
|
+
delta: z3.discriminatedUnion("type", [
|
|
983
|
+
z3.object({
|
|
984
|
+
type: z3.literal("input_json_delta"),
|
|
985
|
+
partial_json: z3.string()
|
|
957
986
|
}),
|
|
958
|
-
|
|
959
|
-
type:
|
|
960
|
-
text:
|
|
987
|
+
z3.object({
|
|
988
|
+
type: z3.literal("text_delta"),
|
|
989
|
+
text: z3.string()
|
|
961
990
|
}),
|
|
962
|
-
|
|
963
|
-
type:
|
|
964
|
-
thinking:
|
|
991
|
+
z3.object({
|
|
992
|
+
type: z3.literal("thinking_delta"),
|
|
993
|
+
thinking: z3.string()
|
|
965
994
|
}),
|
|
966
|
-
|
|
967
|
-
type:
|
|
968
|
-
signature:
|
|
995
|
+
z3.object({
|
|
996
|
+
type: z3.literal("signature_delta"),
|
|
997
|
+
signature: z3.string()
|
|
969
998
|
})
|
|
970
999
|
])
|
|
971
1000
|
}),
|
|
972
|
-
|
|
973
|
-
type:
|
|
974
|
-
index:
|
|
1001
|
+
z3.object({
|
|
1002
|
+
type: z3.literal("content_block_stop"),
|
|
1003
|
+
index: z3.number()
|
|
975
1004
|
}),
|
|
976
|
-
|
|
977
|
-
type:
|
|
978
|
-
error:
|
|
979
|
-
type:
|
|
980
|
-
message:
|
|
1005
|
+
z3.object({
|
|
1006
|
+
type: z3.literal("error"),
|
|
1007
|
+
error: z3.object({
|
|
1008
|
+
type: z3.string(),
|
|
1009
|
+
message: z3.string()
|
|
981
1010
|
})
|
|
982
1011
|
}),
|
|
983
|
-
|
|
984
|
-
type:
|
|
985
|
-
delta:
|
|
986
|
-
usage:
|
|
1012
|
+
z3.object({
|
|
1013
|
+
type: z3.literal("message_delta"),
|
|
1014
|
+
delta: z3.object({ stop_reason: z3.string().nullish() }),
|
|
1015
|
+
usage: z3.object({ output_tokens: z3.number() })
|
|
987
1016
|
}),
|
|
988
|
-
|
|
989
|
-
type:
|
|
1017
|
+
z3.object({
|
|
1018
|
+
type: z3.literal("message_stop")
|
|
990
1019
|
}),
|
|
991
|
-
|
|
992
|
-
type:
|
|
1020
|
+
z3.object({
|
|
1021
|
+
type: z3.literal("ping")
|
|
993
1022
|
})
|
|
994
1023
|
]);
|
|
995
|
-
var
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
budgetTokens: z2.number().optional()
|
|
999
|
-
}).optional()
|
|
1024
|
+
var anthropicReasoningMetadataSchema = z3.object({
|
|
1025
|
+
signature: z3.string().optional(),
|
|
1026
|
+
redactedData: z3.string().optional()
|
|
1000
1027
|
});
|
|
1001
1028
|
|
|
1002
1029
|
// src/anthropic-tools.ts
|
|
1003
|
-
import { z as
|
|
1004
|
-
var Bash20241022Parameters =
|
|
1005
|
-
command:
|
|
1006
|
-
restart:
|
|
1030
|
+
import { z as z4 } from "zod";
|
|
1031
|
+
var Bash20241022Parameters = z4.object({
|
|
1032
|
+
command: z4.string(),
|
|
1033
|
+
restart: z4.boolean().optional()
|
|
1007
1034
|
});
|
|
1008
1035
|
function bashTool_20241022(options = {}) {
|
|
1009
1036
|
return {
|
|
@@ -1015,9 +1042,9 @@ function bashTool_20241022(options = {}) {
|
|
|
1015
1042
|
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1016
1043
|
};
|
|
1017
1044
|
}
|
|
1018
|
-
var Bash20250124Parameters =
|
|
1019
|
-
command:
|
|
1020
|
-
restart:
|
|
1045
|
+
var Bash20250124Parameters = z4.object({
|
|
1046
|
+
command: z4.string(),
|
|
1047
|
+
restart: z4.boolean().optional()
|
|
1021
1048
|
});
|
|
1022
1049
|
function bashTool_20250124(options = {}) {
|
|
1023
1050
|
return {
|
|
@@ -1029,14 +1056,14 @@ function bashTool_20250124(options = {}) {
|
|
|
1029
1056
|
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1030
1057
|
};
|
|
1031
1058
|
}
|
|
1032
|
-
var TextEditor20241022Parameters =
|
|
1033
|
-
command:
|
|
1034
|
-
path:
|
|
1035
|
-
file_text:
|
|
1036
|
-
insert_line:
|
|
1037
|
-
new_str:
|
|
1038
|
-
old_str:
|
|
1039
|
-
view_range:
|
|
1059
|
+
var TextEditor20241022Parameters = z4.object({
|
|
1060
|
+
command: z4.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
|
|
1061
|
+
path: z4.string(),
|
|
1062
|
+
file_text: z4.string().optional(),
|
|
1063
|
+
insert_line: z4.number().int().optional(),
|
|
1064
|
+
new_str: z4.string().optional(),
|
|
1065
|
+
old_str: z4.string().optional(),
|
|
1066
|
+
view_range: z4.array(z4.number().int()).optional()
|
|
1040
1067
|
});
|
|
1041
1068
|
function textEditorTool_20241022(options = {}) {
|
|
1042
1069
|
return {
|
|
@@ -1048,14 +1075,14 @@ function textEditorTool_20241022(options = {}) {
|
|
|
1048
1075
|
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1049
1076
|
};
|
|
1050
1077
|
}
|
|
1051
|
-
var TextEditor20250124Parameters =
|
|
1052
|
-
command:
|
|
1053
|
-
path:
|
|
1054
|
-
file_text:
|
|
1055
|
-
insert_line:
|
|
1056
|
-
new_str:
|
|
1057
|
-
old_str:
|
|
1058
|
-
view_range:
|
|
1078
|
+
var TextEditor20250124Parameters = z4.object({
|
|
1079
|
+
command: z4.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
|
|
1080
|
+
path: z4.string(),
|
|
1081
|
+
file_text: z4.string().optional(),
|
|
1082
|
+
insert_line: z4.number().int().optional(),
|
|
1083
|
+
new_str: z4.string().optional(),
|
|
1084
|
+
old_str: z4.string().optional(),
|
|
1085
|
+
view_range: z4.array(z4.number().int()).optional()
|
|
1059
1086
|
});
|
|
1060
1087
|
function textEditorTool_20250124(options = {}) {
|
|
1061
1088
|
return {
|
|
@@ -1067,8 +1094,8 @@ function textEditorTool_20250124(options = {}) {
|
|
|
1067
1094
|
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1068
1095
|
};
|
|
1069
1096
|
}
|
|
1070
|
-
var Computer20241022Parameters =
|
|
1071
|
-
action:
|
|
1097
|
+
var Computer20241022Parameters = z4.object({
|
|
1098
|
+
action: z4.enum([
|
|
1072
1099
|
"key",
|
|
1073
1100
|
"type",
|
|
1074
1101
|
"mouse_move",
|
|
@@ -1080,8 +1107,8 @@ var Computer20241022Parameters = z3.object({
|
|
|
1080
1107
|
"screenshot",
|
|
1081
1108
|
"cursor_position"
|
|
1082
1109
|
]),
|
|
1083
|
-
coordinate:
|
|
1084
|
-
text:
|
|
1110
|
+
coordinate: z4.array(z4.number().int()).optional(),
|
|
1111
|
+
text: z4.string().optional()
|
|
1085
1112
|
});
|
|
1086
1113
|
function computerTool_20241022(options) {
|
|
1087
1114
|
return {
|
|
@@ -1097,8 +1124,8 @@ function computerTool_20241022(options) {
|
|
|
1097
1124
|
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1098
1125
|
};
|
|
1099
1126
|
}
|
|
1100
|
-
var Computer20250124Parameters =
|
|
1101
|
-
action:
|
|
1127
|
+
var Computer20250124Parameters = z4.object({
|
|
1128
|
+
action: z4.enum([
|
|
1102
1129
|
"key",
|
|
1103
1130
|
"hold_key",
|
|
1104
1131
|
"type",
|
|
@@ -1116,12 +1143,12 @@ var Computer20250124Parameters = z3.object({
|
|
|
1116
1143
|
"wait",
|
|
1117
1144
|
"screenshot"
|
|
1118
1145
|
]),
|
|
1119
|
-
coordinate:
|
|
1120
|
-
duration:
|
|
1121
|
-
scroll_amount:
|
|
1122
|
-
scroll_direction:
|
|
1123
|
-
start_coordinate:
|
|
1124
|
-
text:
|
|
1146
|
+
coordinate: z4.tuple([z4.number().int(), z4.number().int()]).optional(),
|
|
1147
|
+
duration: z4.number().optional(),
|
|
1148
|
+
scroll_amount: z4.number().optional(),
|
|
1149
|
+
scroll_direction: z4.enum(["up", "down", "left", "right"]).optional(),
|
|
1150
|
+
start_coordinate: z4.tuple([z4.number().int(), z4.number().int()]).optional(),
|
|
1151
|
+
text: z4.string().optional()
|
|
1125
1152
|
});
|
|
1126
1153
|
function computerTool_20250124(options) {
|
|
1127
1154
|
return {
|
|
@@ -1159,20 +1186,22 @@ function createAnthropic(options = {}) {
|
|
|
1159
1186
|
}),
|
|
1160
1187
|
...options.headers
|
|
1161
1188
|
});
|
|
1162
|
-
const createChatModel = (modelId
|
|
1189
|
+
const createChatModel = (modelId) => new AnthropicMessagesLanguageModel(modelId, {
|
|
1163
1190
|
provider: "anthropic.messages",
|
|
1164
1191
|
baseURL,
|
|
1165
1192
|
headers: getHeaders,
|
|
1166
1193
|
fetch: options.fetch,
|
|
1167
|
-
|
|
1194
|
+
supportedUrls: () => ({
|
|
1195
|
+
"image/*": [/^https?:\/\/.*$/]
|
|
1196
|
+
})
|
|
1168
1197
|
});
|
|
1169
|
-
const provider = function(modelId
|
|
1198
|
+
const provider = function(modelId) {
|
|
1170
1199
|
if (new.target) {
|
|
1171
1200
|
throw new Error(
|
|
1172
1201
|
"The Anthropic model function cannot be called with the new keyword."
|
|
1173
1202
|
);
|
|
1174
1203
|
}
|
|
1175
|
-
return createChatModel(modelId
|
|
1204
|
+
return createChatModel(modelId);
|
|
1176
1205
|
};
|
|
1177
1206
|
provider.languageModel = createChatModel;
|
|
1178
1207
|
provider.chat = createChatModel;
|
|
@@ -1180,6 +1209,9 @@ function createAnthropic(options = {}) {
|
|
|
1180
1209
|
provider.textEmbeddingModel = (modelId) => {
|
|
1181
1210
|
throw new NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
|
|
1182
1211
|
};
|
|
1212
|
+
provider.imageModel = (modelId) => {
|
|
1213
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
1214
|
+
};
|
|
1183
1215
|
provider.tools = anthropicTools;
|
|
1184
1216
|
return provider;
|
|
1185
1217
|
}
|