@ai-sdk/anthropic 1.2.11 → 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 +179 -22
- 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 +18 -16
- package/internal/dist/index.js.map +0 -1
- package/internal/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
|
32
32
|
// src/anthropic-messages-language-model.ts
|
|
33
33
|
var import_provider3 = require("@ai-sdk/provider");
|
|
34
34
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
35
|
-
var
|
|
35
|
+
var import_zod3 = require("zod");
|
|
36
36
|
|
|
37
37
|
// src/anthropic-error.ts
|
|
38
38
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
@@ -49,15 +49,32 @@ var anthropicFailedResponseHandler = (0, import_provider_utils.createJsonErrorRe
|
|
|
49
49
|
errorToMessage: (data) => data.error.message
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
+
// src/anthropic-messages-options.ts
|
|
53
|
+
var import_zod2 = require("zod");
|
|
54
|
+
var anthropicProviderOptions = import_zod2.z.object({
|
|
55
|
+
/**
|
|
56
|
+
Include reasoning content in requests sent to the model. Defaults to `true`.
|
|
57
|
+
|
|
58
|
+
If you are experiencing issues with the model handling requests involving
|
|
59
|
+
*/
|
|
60
|
+
sendReasoning: import_zod2.z.boolean().optional(),
|
|
61
|
+
thinking: import_zod2.z.object({
|
|
62
|
+
type: import_zod2.z.union([import_zod2.z.literal("enabled"), import_zod2.z.literal("disabled")]),
|
|
63
|
+
budgetTokens: import_zod2.z.number().optional()
|
|
64
|
+
}).optional()
|
|
65
|
+
});
|
|
66
|
+
|
|
52
67
|
// src/anthropic-prepare-tools.ts
|
|
53
68
|
var import_provider = require("@ai-sdk/provider");
|
|
54
|
-
function prepareTools(
|
|
55
|
-
|
|
56
|
-
|
|
69
|
+
function prepareTools({
|
|
70
|
+
tools,
|
|
71
|
+
toolChoice
|
|
72
|
+
}) {
|
|
73
|
+
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
57
74
|
const toolWarnings = [];
|
|
58
75
|
const betas = /* @__PURE__ */ new Set();
|
|
59
76
|
if (tools == null) {
|
|
60
|
-
return { tools: void 0,
|
|
77
|
+
return { tools: void 0, toolChoice: void 0, toolWarnings, betas };
|
|
61
78
|
}
|
|
62
79
|
const anthropicTools2 = [];
|
|
63
80
|
for (const tool of tools) {
|
|
@@ -129,11 +146,10 @@ function prepareTools(mode) {
|
|
|
129
146
|
break;
|
|
130
147
|
}
|
|
131
148
|
}
|
|
132
|
-
const toolChoice = mode.toolChoice;
|
|
133
149
|
if (toolChoice == null) {
|
|
134
150
|
return {
|
|
135
151
|
tools: anthropicTools2,
|
|
136
|
-
|
|
152
|
+
toolChoice: void 0,
|
|
137
153
|
toolWarnings,
|
|
138
154
|
betas
|
|
139
155
|
};
|
|
@@ -143,30 +159,30 @@ function prepareTools(mode) {
|
|
|
143
159
|
case "auto":
|
|
144
160
|
return {
|
|
145
161
|
tools: anthropicTools2,
|
|
146
|
-
|
|
162
|
+
toolChoice: { type: "auto" },
|
|
147
163
|
toolWarnings,
|
|
148
164
|
betas
|
|
149
165
|
};
|
|
150
166
|
case "required":
|
|
151
167
|
return {
|
|
152
168
|
tools: anthropicTools2,
|
|
153
|
-
|
|
169
|
+
toolChoice: { type: "any" },
|
|
154
170
|
toolWarnings,
|
|
155
171
|
betas
|
|
156
172
|
};
|
|
157
173
|
case "none":
|
|
158
|
-
return { tools: void 0,
|
|
174
|
+
return { tools: void 0, toolChoice: void 0, toolWarnings, betas };
|
|
159
175
|
case "tool":
|
|
160
176
|
return {
|
|
161
177
|
tools: anthropicTools2,
|
|
162
|
-
|
|
178
|
+
toolChoice: { type: "tool", name: toolChoice.toolName },
|
|
163
179
|
toolWarnings,
|
|
164
180
|
betas
|
|
165
181
|
};
|
|
166
182
|
default: {
|
|
167
183
|
const _exhaustiveCheck = type;
|
|
168
184
|
throw new import_provider.UnsupportedFunctionalityError({
|
|
169
|
-
functionality: `
|
|
185
|
+
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
170
186
|
});
|
|
171
187
|
}
|
|
172
188
|
}
|
|
@@ -175,12 +191,12 @@ function prepareTools(mode) {
|
|
|
175
191
|
// src/convert-to-anthropic-messages-prompt.ts
|
|
176
192
|
var import_provider2 = require("@ai-sdk/provider");
|
|
177
193
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
178
|
-
function convertToAnthropicMessagesPrompt({
|
|
194
|
+
async function convertToAnthropicMessagesPrompt({
|
|
179
195
|
prompt,
|
|
180
196
|
sendReasoning,
|
|
181
197
|
warnings
|
|
182
198
|
}) {
|
|
183
|
-
var _a, _b, _c
|
|
199
|
+
var _a, _b, _c;
|
|
184
200
|
const betas = /* @__PURE__ */ new Set();
|
|
185
201
|
const blocks = groupIntoBlocks(prompt);
|
|
186
202
|
let system = void 0;
|
|
@@ -202,10 +218,10 @@ function convertToAnthropicMessagesPrompt({
|
|
|
202
218
|
functionality: "Multiple system messages that are separated by user/assistant messages"
|
|
203
219
|
});
|
|
204
220
|
}
|
|
205
|
-
system = block.messages.map(({ content,
|
|
221
|
+
system = block.messages.map(({ content, providerOptions }) => ({
|
|
206
222
|
type: "text",
|
|
207
223
|
text: content,
|
|
208
|
-
cache_control: getCacheControl(
|
|
224
|
+
cache_control: getCacheControl(providerOptions)
|
|
209
225
|
}));
|
|
210
226
|
break;
|
|
211
227
|
}
|
|
@@ -218,7 +234,7 @@ function convertToAnthropicMessagesPrompt({
|
|
|
218
234
|
for (let j = 0; j < content.length; j++) {
|
|
219
235
|
const part = content[j];
|
|
220
236
|
const isLastPart = j === content.length - 1;
|
|
221
|
-
const cacheControl = (_a = getCacheControl(part.
|
|
237
|
+
const cacheControl = (_a = getCacheControl(part.providerOptions)) != null ? _a : isLastPart ? getCacheControl(message.providerOptions) : void 0;
|
|
222
238
|
switch (part.type) {
|
|
223
239
|
case "text": {
|
|
224
240
|
anthropicContent.push({
|
|
@@ -228,40 +244,39 @@ function convertToAnthropicMessagesPrompt({
|
|
|
228
244
|
});
|
|
229
245
|
break;
|
|
230
246
|
}
|
|
231
|
-
case "image": {
|
|
232
|
-
anthropicContent.push({
|
|
233
|
-
type: "image",
|
|
234
|
-
source: part.image instanceof URL ? {
|
|
235
|
-
type: "url",
|
|
236
|
-
url: part.image.toString()
|
|
237
|
-
} : {
|
|
238
|
-
type: "base64",
|
|
239
|
-
media_type: (_b = part.mimeType) != null ? _b : "image/jpeg",
|
|
240
|
-
data: (0, import_provider_utils2.convertUint8ArrayToBase64)(part.image)
|
|
241
|
-
},
|
|
242
|
-
cache_control: cacheControl
|
|
243
|
-
});
|
|
244
|
-
break;
|
|
245
|
-
}
|
|
246
247
|
case "file": {
|
|
247
|
-
if (part.
|
|
248
|
+
if (part.mediaType.startsWith("image/")) {
|
|
249
|
+
anthropicContent.push({
|
|
250
|
+
type: "image",
|
|
251
|
+
source: part.data instanceof URL ? {
|
|
252
|
+
type: "url",
|
|
253
|
+
url: part.data.toString()
|
|
254
|
+
} : {
|
|
255
|
+
type: "base64",
|
|
256
|
+
media_type: part.mediaType === "image/*" ? "image/jpeg" : part.mediaType,
|
|
257
|
+
data: (0, import_provider_utils2.convertToBase64)(part.data)
|
|
258
|
+
},
|
|
259
|
+
cache_control: cacheControl
|
|
260
|
+
});
|
|
261
|
+
} else if (part.mediaType === "application/pdf") {
|
|
262
|
+
betas.add("pdfs-2024-09-25");
|
|
263
|
+
anthropicContent.push({
|
|
264
|
+
type: "document",
|
|
265
|
+
source: part.data instanceof URL ? {
|
|
266
|
+
type: "url",
|
|
267
|
+
url: part.data.toString()
|
|
268
|
+
} : {
|
|
269
|
+
type: "base64",
|
|
270
|
+
media_type: "application/pdf",
|
|
271
|
+
data: (0, import_provider_utils2.convertToBase64)(part.data)
|
|
272
|
+
},
|
|
273
|
+
cache_control: cacheControl
|
|
274
|
+
});
|
|
275
|
+
} else {
|
|
248
276
|
throw new import_provider2.UnsupportedFunctionalityError({
|
|
249
|
-
functionality:
|
|
277
|
+
functionality: `media type: ${part.mediaType}`
|
|
250
278
|
});
|
|
251
279
|
}
|
|
252
|
-
betas.add("pdfs-2024-09-25");
|
|
253
|
-
anthropicContent.push({
|
|
254
|
-
type: "document",
|
|
255
|
-
source: part.data instanceof URL ? {
|
|
256
|
-
type: "url",
|
|
257
|
-
url: part.data.toString()
|
|
258
|
-
} : {
|
|
259
|
-
type: "base64",
|
|
260
|
-
media_type: "application/pdf",
|
|
261
|
-
data: part.data
|
|
262
|
-
},
|
|
263
|
-
cache_control: cacheControl
|
|
264
|
-
});
|
|
265
280
|
break;
|
|
266
281
|
}
|
|
267
282
|
}
|
|
@@ -272,7 +287,7 @@ function convertToAnthropicMessagesPrompt({
|
|
|
272
287
|
for (let i2 = 0; i2 < content.length; i2++) {
|
|
273
288
|
const part = content[i2];
|
|
274
289
|
const isLastPart = i2 === content.length - 1;
|
|
275
|
-
const cacheControl = (
|
|
290
|
+
const cacheControl = (_b = getCacheControl(part.providerOptions)) != null ? _b : isLastPart ? getCacheControl(message.providerOptions) : void 0;
|
|
276
291
|
const toolResultContent = part.content != null ? part.content.map((part2) => {
|
|
277
292
|
var _a2;
|
|
278
293
|
switch (part2.type) {
|
|
@@ -287,7 +302,7 @@ function convertToAnthropicMessagesPrompt({
|
|
|
287
302
|
type: "image",
|
|
288
303
|
source: {
|
|
289
304
|
type: "base64",
|
|
290
|
-
media_type: (_a2 = part2.
|
|
305
|
+
media_type: (_a2 = part2.mediaType) != null ? _a2 : "image/jpeg",
|
|
291
306
|
data: part2.data
|
|
292
307
|
},
|
|
293
308
|
cache_control: void 0
|
|
@@ -322,7 +337,7 @@ function convertToAnthropicMessagesPrompt({
|
|
|
322
337
|
for (let k = 0; k < content.length; k++) {
|
|
323
338
|
const part = content[k];
|
|
324
339
|
const isLastContentPart = k === content.length - 1;
|
|
325
|
-
const cacheControl = (
|
|
340
|
+
const cacheControl = (_c = getCacheControl(part.providerOptions)) != null ? _c : isLastContentPart ? getCacheControl(message.providerOptions) : void 0;
|
|
326
341
|
switch (part.type) {
|
|
327
342
|
case "text": {
|
|
328
343
|
anthropicContent.push({
|
|
@@ -339,12 +354,37 @@ function convertToAnthropicMessagesPrompt({
|
|
|
339
354
|
}
|
|
340
355
|
case "reasoning": {
|
|
341
356
|
if (sendReasoning) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
cache_control: cacheControl
|
|
357
|
+
const reasoningMetadata = await (0, import_provider_utils2.parseProviderOptions)({
|
|
358
|
+
provider: "anthropic",
|
|
359
|
+
providerOptions: part.providerOptions,
|
|
360
|
+
schema: anthropicReasoningMetadataSchema
|
|
347
361
|
});
|
|
362
|
+
if (reasoningMetadata != null) {
|
|
363
|
+
if (reasoningMetadata.signature != null) {
|
|
364
|
+
anthropicContent.push({
|
|
365
|
+
type: "thinking",
|
|
366
|
+
thinking: part.text,
|
|
367
|
+
signature: reasoningMetadata.signature,
|
|
368
|
+
cache_control: cacheControl
|
|
369
|
+
});
|
|
370
|
+
} else if (reasoningMetadata.redactedData != null) {
|
|
371
|
+
anthropicContent.push({
|
|
372
|
+
type: "redacted_thinking",
|
|
373
|
+
data: reasoningMetadata.redactedData,
|
|
374
|
+
cache_control: cacheControl
|
|
375
|
+
});
|
|
376
|
+
} else {
|
|
377
|
+
warnings.push({
|
|
378
|
+
type: "other",
|
|
379
|
+
message: "unsupported reasoning metadata"
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
} else {
|
|
383
|
+
warnings.push({
|
|
384
|
+
type: "other",
|
|
385
|
+
message: "unsupported reasoning metadata"
|
|
386
|
+
});
|
|
387
|
+
}
|
|
348
388
|
} else {
|
|
349
389
|
warnings.push({
|
|
350
390
|
type: "other",
|
|
@@ -353,14 +393,6 @@ function convertToAnthropicMessagesPrompt({
|
|
|
353
393
|
}
|
|
354
394
|
break;
|
|
355
395
|
}
|
|
356
|
-
case "redacted-reasoning": {
|
|
357
|
-
anthropicContent.push({
|
|
358
|
-
type: "redacted_thinking",
|
|
359
|
-
data: part.data,
|
|
360
|
-
cache_control: cacheControl
|
|
361
|
-
});
|
|
362
|
-
break;
|
|
363
|
-
}
|
|
364
396
|
case "tool-call": {
|
|
365
397
|
anthropicContent.push({
|
|
366
398
|
type: "tool_use",
|
|
@@ -379,7 +411,7 @@ function convertToAnthropicMessagesPrompt({
|
|
|
379
411
|
}
|
|
380
412
|
default: {
|
|
381
413
|
const _exhaustiveCheck = type;
|
|
382
|
-
throw new Error(`
|
|
414
|
+
throw new Error(`content type: ${_exhaustiveCheck}`);
|
|
383
415
|
}
|
|
384
416
|
}
|
|
385
417
|
}
|
|
@@ -452,11 +484,9 @@ function mapAnthropicStopReason(finishReason) {
|
|
|
452
484
|
|
|
453
485
|
// src/anthropic-messages-language-model.ts
|
|
454
486
|
var AnthropicMessagesLanguageModel = class {
|
|
455
|
-
constructor(modelId,
|
|
456
|
-
this.specificationVersion = "
|
|
457
|
-
this.defaultObjectGenerationMode = "tool";
|
|
487
|
+
constructor(modelId, config) {
|
|
488
|
+
this.specificationVersion = "v2";
|
|
458
489
|
this.modelId = modelId;
|
|
459
|
-
this.settings = settings;
|
|
460
490
|
this.config = config;
|
|
461
491
|
}
|
|
462
492
|
supportsUrl(url) {
|
|
@@ -465,13 +495,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
465
495
|
get provider() {
|
|
466
496
|
return this.config.provider;
|
|
467
497
|
}
|
|
468
|
-
get
|
|
469
|
-
|
|
498
|
+
get supportedUrls() {
|
|
499
|
+
var _a, _b, _c;
|
|
500
|
+
return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
|
|
470
501
|
}
|
|
471
502
|
async getArgs({
|
|
472
|
-
mode,
|
|
473
503
|
prompt,
|
|
474
|
-
|
|
504
|
+
maxOutputTokens = 4096,
|
|
475
505
|
// 4096: max model output tokens TODO update default in v5
|
|
476
506
|
temperature,
|
|
477
507
|
topP,
|
|
@@ -481,10 +511,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
481
511
|
stopSequences,
|
|
482
512
|
responseFormat,
|
|
483
513
|
seed,
|
|
484
|
-
|
|
514
|
+
tools,
|
|
515
|
+
toolChoice,
|
|
516
|
+
providerOptions
|
|
485
517
|
}) {
|
|
486
518
|
var _a, _b, _c;
|
|
487
|
-
const type = mode.type;
|
|
488
519
|
const warnings = [];
|
|
489
520
|
if (frequencyPenalty != null) {
|
|
490
521
|
warnings.push({
|
|
@@ -511,15 +542,15 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
511
542
|
details: "JSON response format is not supported."
|
|
512
543
|
});
|
|
513
544
|
}
|
|
514
|
-
const
|
|
515
|
-
prompt,
|
|
516
|
-
sendReasoning: (_a = this.settings.sendReasoning) != null ? _a : true,
|
|
517
|
-
warnings
|
|
518
|
-
});
|
|
519
|
-
const anthropicOptions = (0, import_provider_utils3.parseProviderOptions)({
|
|
545
|
+
const anthropicOptions = await (0, import_provider_utils3.parseProviderOptions)({
|
|
520
546
|
provider: "anthropic",
|
|
521
547
|
providerOptions,
|
|
522
|
-
schema:
|
|
548
|
+
schema: anthropicProviderOptions
|
|
549
|
+
});
|
|
550
|
+
const { prompt: messagesPrompt, betas: messagesBetas } = await convertToAnthropicMessagesPrompt({
|
|
551
|
+
prompt,
|
|
552
|
+
sendReasoning: (_a = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _a : true,
|
|
553
|
+
warnings
|
|
523
554
|
});
|
|
524
555
|
const isThinking = ((_b = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _b.type) === "enabled";
|
|
525
556
|
const thinkingBudget = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.budgetTokens;
|
|
@@ -527,7 +558,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
527
558
|
// model id:
|
|
528
559
|
model: this.modelId,
|
|
529
560
|
// standardized settings:
|
|
530
|
-
max_tokens:
|
|
561
|
+
max_tokens: maxOutputTokens,
|
|
531
562
|
temperature,
|
|
532
563
|
top_k: topK,
|
|
533
564
|
top_p: topP,
|
|
@@ -570,44 +601,23 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
570
601
|
details: "topP is not supported when thinking is enabled"
|
|
571
602
|
});
|
|
572
603
|
}
|
|
573
|
-
baseArgs.max_tokens =
|
|
574
|
-
}
|
|
575
|
-
switch (type) {
|
|
576
|
-
case "regular": {
|
|
577
|
-
const {
|
|
578
|
-
tools,
|
|
579
|
-
tool_choice,
|
|
580
|
-
toolWarnings,
|
|
581
|
-
betas: toolsBetas
|
|
582
|
-
} = prepareTools(mode);
|
|
583
|
-
return {
|
|
584
|
-
args: { ...baseArgs, tools, tool_choice },
|
|
585
|
-
warnings: [...warnings, ...toolWarnings],
|
|
586
|
-
betas: /* @__PURE__ */ new Set([...messagesBetas, ...toolsBetas])
|
|
587
|
-
};
|
|
588
|
-
}
|
|
589
|
-
case "object-json": {
|
|
590
|
-
throw new import_provider3.UnsupportedFunctionalityError({
|
|
591
|
-
functionality: "json-mode object generation"
|
|
592
|
-
});
|
|
593
|
-
}
|
|
594
|
-
case "object-tool": {
|
|
595
|
-
const { name, description, parameters } = mode.tool;
|
|
596
|
-
return {
|
|
597
|
-
args: {
|
|
598
|
-
...baseArgs,
|
|
599
|
-
tools: [{ name, description, input_schema: parameters }],
|
|
600
|
-
tool_choice: { type: "tool", name }
|
|
601
|
-
},
|
|
602
|
-
warnings,
|
|
603
|
-
betas: messagesBetas
|
|
604
|
-
};
|
|
605
|
-
}
|
|
606
|
-
default: {
|
|
607
|
-
const _exhaustiveCheck = type;
|
|
608
|
-
throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
|
|
609
|
-
}
|
|
604
|
+
baseArgs.max_tokens = maxOutputTokens + thinkingBudget;
|
|
610
605
|
}
|
|
606
|
+
const {
|
|
607
|
+
tools: anthropicTools2,
|
|
608
|
+
toolChoice: anthropicToolChoice,
|
|
609
|
+
toolWarnings,
|
|
610
|
+
betas: toolsBetas
|
|
611
|
+
} = prepareTools({ tools, toolChoice });
|
|
612
|
+
return {
|
|
613
|
+
args: {
|
|
614
|
+
...baseArgs,
|
|
615
|
+
tools: anthropicTools2,
|
|
616
|
+
tool_choice: anthropicToolChoice
|
|
617
|
+
},
|
|
618
|
+
warnings: [...warnings, ...toolWarnings],
|
|
619
|
+
betas: /* @__PURE__ */ new Set([...messagesBetas, ...toolsBetas])
|
|
620
|
+
};
|
|
611
621
|
}
|
|
612
622
|
async getHeaders({
|
|
613
623
|
betas,
|
|
@@ -645,65 +655,71 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
645
655
|
abortSignal: options.abortSignal,
|
|
646
656
|
fetch: this.config.fetch
|
|
647
657
|
});
|
|
648
|
-
const
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
658
|
+
const content = [];
|
|
659
|
+
for (const part of response.content) {
|
|
660
|
+
switch (part.type) {
|
|
661
|
+
case "text": {
|
|
662
|
+
content.push({ type: "text", text: part.text });
|
|
663
|
+
break;
|
|
664
|
+
}
|
|
665
|
+
case "thinking": {
|
|
666
|
+
content.push({
|
|
667
|
+
type: "reasoning",
|
|
668
|
+
text: part.thinking,
|
|
669
|
+
providerMetadata: {
|
|
670
|
+
anthropic: {
|
|
671
|
+
signature: part.signature
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
});
|
|
675
|
+
break;
|
|
676
|
+
}
|
|
677
|
+
case "redacted_thinking": {
|
|
678
|
+
content.push({
|
|
679
|
+
type: "reasoning",
|
|
680
|
+
text: "",
|
|
681
|
+
providerMetadata: {
|
|
682
|
+
anthropic: {
|
|
683
|
+
redactedData: part.data
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
break;
|
|
688
|
+
}
|
|
689
|
+
case "tool_use": {
|
|
690
|
+
content.push({
|
|
691
|
+
type: "tool-call",
|
|
661
692
|
toolCallType: "function",
|
|
662
|
-
toolCallId:
|
|
663
|
-
toolName:
|
|
664
|
-
args: JSON.stringify(
|
|
693
|
+
toolCallId: part.id,
|
|
694
|
+
toolName: part.name,
|
|
695
|
+
args: JSON.stringify(part.input)
|
|
665
696
|
});
|
|
697
|
+
break;
|
|
666
698
|
}
|
|
667
699
|
}
|
|
668
700
|
}
|
|
669
|
-
const reasoning = response.content.filter(
|
|
670
|
-
(content) => content.type === "redacted_thinking" || content.type === "thinking"
|
|
671
|
-
).map(
|
|
672
|
-
(content) => content.type === "thinking" ? {
|
|
673
|
-
type: "text",
|
|
674
|
-
text: content.thinking,
|
|
675
|
-
signature: content.signature
|
|
676
|
-
} : {
|
|
677
|
-
type: "redacted",
|
|
678
|
-
data: content.data
|
|
679
|
-
}
|
|
680
|
-
);
|
|
681
701
|
return {
|
|
682
|
-
|
|
683
|
-
reasoning: reasoning.length > 0 ? reasoning : void 0,
|
|
684
|
-
toolCalls,
|
|
702
|
+
content,
|
|
685
703
|
finishReason: mapAnthropicStopReason(response.stop_reason),
|
|
686
704
|
usage: {
|
|
687
|
-
|
|
688
|
-
|
|
705
|
+
inputTokens: response.usage.input_tokens,
|
|
706
|
+
outputTokens: response.usage.output_tokens,
|
|
707
|
+
totalTokens: response.usage.input_tokens + response.usage.output_tokens,
|
|
708
|
+
cachedInputTokens: (_a = response.usage.cache_read_input_tokens) != null ? _a : void 0
|
|
689
709
|
},
|
|
690
|
-
|
|
691
|
-
|
|
710
|
+
request: { body: args },
|
|
711
|
+
response: {
|
|
712
|
+
id: (_b = response.id) != null ? _b : void 0,
|
|
713
|
+
modelId: (_c = response.model) != null ? _c : void 0,
|
|
692
714
|
headers: responseHeaders,
|
|
693
715
|
body: rawResponse
|
|
694
716
|
},
|
|
695
|
-
response: {
|
|
696
|
-
id: (_a = response.id) != null ? _a : void 0,
|
|
697
|
-
modelId: (_b = response.model) != null ? _b : void 0
|
|
698
|
-
},
|
|
699
717
|
warnings,
|
|
700
718
|
providerMetadata: {
|
|
701
719
|
anthropic: {
|
|
702
|
-
cacheCreationInputTokens: (
|
|
703
|
-
cacheReadInputTokens: (_d = response.usage.cache_read_input_tokens) != null ? _d : null
|
|
720
|
+
cacheCreationInputTokens: (_d = response.usage.cache_creation_input_tokens) != null ? _d : null
|
|
704
721
|
}
|
|
705
|
-
}
|
|
706
|
-
request: { body: JSON.stringify(args) }
|
|
722
|
+
}
|
|
707
723
|
};
|
|
708
724
|
}
|
|
709
725
|
async doStream(options) {
|
|
@@ -720,11 +736,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
720
736
|
abortSignal: options.abortSignal,
|
|
721
737
|
fetch: this.config.fetch
|
|
722
738
|
});
|
|
723
|
-
const { messages: rawPrompt, ...rawSettings } = args;
|
|
724
739
|
let finishReason = "unknown";
|
|
725
740
|
const usage = {
|
|
726
|
-
|
|
727
|
-
|
|
741
|
+
inputTokens: void 0,
|
|
742
|
+
outputTokens: void 0,
|
|
743
|
+
totalTokens: void 0
|
|
728
744
|
};
|
|
729
745
|
const toolCallContentBlocks = {};
|
|
730
746
|
let providerMetadata = void 0;
|
|
@@ -732,8 +748,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
732
748
|
return {
|
|
733
749
|
stream: response.pipeThrough(
|
|
734
750
|
new TransformStream({
|
|
751
|
+
start(controller) {
|
|
752
|
+
controller.enqueue({ type: "stream-start", warnings });
|
|
753
|
+
},
|
|
735
754
|
transform(chunk, controller) {
|
|
736
|
-
var _a, _b, _c, _d;
|
|
755
|
+
var _a, _b, _c, _d, _e, _f;
|
|
737
756
|
if (!chunk.success) {
|
|
738
757
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
739
758
|
return;
|
|
@@ -753,9 +772,15 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
753
772
|
}
|
|
754
773
|
case "redacted_thinking": {
|
|
755
774
|
controller.enqueue({
|
|
756
|
-
type: "
|
|
757
|
-
|
|
775
|
+
type: "reasoning",
|
|
776
|
+
text: "",
|
|
777
|
+
providerMetadata: {
|
|
778
|
+
anthropic: {
|
|
779
|
+
redactedData: value.content_block.data
|
|
780
|
+
}
|
|
781
|
+
}
|
|
758
782
|
});
|
|
783
|
+
controller.enqueue({ type: "reasoning-part-finish" });
|
|
759
784
|
return;
|
|
760
785
|
}
|
|
761
786
|
case "tool_use": {
|
|
@@ -794,24 +819,30 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
794
819
|
switch (deltaType) {
|
|
795
820
|
case "text_delta": {
|
|
796
821
|
controller.enqueue({
|
|
797
|
-
type: "text
|
|
798
|
-
|
|
822
|
+
type: "text",
|
|
823
|
+
text: value.delta.text
|
|
799
824
|
});
|
|
800
825
|
return;
|
|
801
826
|
}
|
|
802
827
|
case "thinking_delta": {
|
|
803
828
|
controller.enqueue({
|
|
804
829
|
type: "reasoning",
|
|
805
|
-
|
|
830
|
+
text: value.delta.thinking
|
|
806
831
|
});
|
|
807
832
|
return;
|
|
808
833
|
}
|
|
809
834
|
case "signature_delta": {
|
|
810
835
|
if (blockType === "thinking") {
|
|
811
836
|
controller.enqueue({
|
|
812
|
-
type: "reasoning
|
|
813
|
-
|
|
837
|
+
type: "reasoning",
|
|
838
|
+
text: "",
|
|
839
|
+
providerMetadata: {
|
|
840
|
+
anthropic: {
|
|
841
|
+
signature: value.delta.signature
|
|
842
|
+
}
|
|
843
|
+
}
|
|
814
844
|
});
|
|
845
|
+
controller.enqueue({ type: "reasoning-part-finish" });
|
|
815
846
|
}
|
|
816
847
|
return;
|
|
817
848
|
}
|
|
@@ -836,12 +867,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
836
867
|
}
|
|
837
868
|
}
|
|
838
869
|
case "message_start": {
|
|
839
|
-
usage.
|
|
840
|
-
usage.
|
|
870
|
+
usage.inputTokens = value.message.usage.input_tokens;
|
|
871
|
+
usage.cachedInputTokens = (_a = value.message.usage.cache_read_input_tokens) != null ? _a : void 0;
|
|
841
872
|
providerMetadata = {
|
|
842
873
|
anthropic: {
|
|
843
|
-
cacheCreationInputTokens: (
|
|
844
|
-
cacheReadInputTokens: (_b = value.message.usage.cache_read_input_tokens) != null ? _b : null
|
|
874
|
+
cacheCreationInputTokens: (_b = value.message.usage.cache_creation_input_tokens) != null ? _b : null
|
|
845
875
|
}
|
|
846
876
|
};
|
|
847
877
|
controller.enqueue({
|
|
@@ -852,7 +882,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
852
882
|
return;
|
|
853
883
|
}
|
|
854
884
|
case "message_delta": {
|
|
855
|
-
usage.
|
|
885
|
+
usage.outputTokens = value.usage.output_tokens;
|
|
886
|
+
usage.totalTokens = ((_e = usage.inputTokens) != null ? _e : 0) + ((_f = value.usage.output_tokens) != null ? _f : 0);
|
|
856
887
|
finishReason = mapAnthropicStopReason(value.delta.stop_reason);
|
|
857
888
|
return;
|
|
858
889
|
}
|
|
@@ -877,142 +908,138 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
877
908
|
}
|
|
878
909
|
})
|
|
879
910
|
),
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
warnings,
|
|
883
|
-
request: { body: JSON.stringify(body) }
|
|
911
|
+
request: { body },
|
|
912
|
+
response: { headers: responseHeaders }
|
|
884
913
|
};
|
|
885
914
|
}
|
|
886
915
|
};
|
|
887
|
-
var anthropicMessagesResponseSchema =
|
|
888
|
-
type:
|
|
889
|
-
id:
|
|
890
|
-
model:
|
|
891
|
-
content:
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
type:
|
|
895
|
-
text:
|
|
916
|
+
var anthropicMessagesResponseSchema = import_zod3.z.object({
|
|
917
|
+
type: import_zod3.z.literal("message"),
|
|
918
|
+
id: import_zod3.z.string().nullish(),
|
|
919
|
+
model: import_zod3.z.string().nullish(),
|
|
920
|
+
content: import_zod3.z.array(
|
|
921
|
+
import_zod3.z.discriminatedUnion("type", [
|
|
922
|
+
import_zod3.z.object({
|
|
923
|
+
type: import_zod3.z.literal("text"),
|
|
924
|
+
text: import_zod3.z.string()
|
|
896
925
|
}),
|
|
897
|
-
|
|
898
|
-
type:
|
|
899
|
-
thinking:
|
|
900
|
-
signature:
|
|
926
|
+
import_zod3.z.object({
|
|
927
|
+
type: import_zod3.z.literal("thinking"),
|
|
928
|
+
thinking: import_zod3.z.string(),
|
|
929
|
+
signature: import_zod3.z.string()
|
|
901
930
|
}),
|
|
902
|
-
|
|
903
|
-
type:
|
|
904
|
-
data:
|
|
931
|
+
import_zod3.z.object({
|
|
932
|
+
type: import_zod3.z.literal("redacted_thinking"),
|
|
933
|
+
data: import_zod3.z.string()
|
|
905
934
|
}),
|
|
906
|
-
|
|
907
|
-
type:
|
|
908
|
-
id:
|
|
909
|
-
name:
|
|
910
|
-
input:
|
|
935
|
+
import_zod3.z.object({
|
|
936
|
+
type: import_zod3.z.literal("tool_use"),
|
|
937
|
+
id: import_zod3.z.string(),
|
|
938
|
+
name: import_zod3.z.string(),
|
|
939
|
+
input: import_zod3.z.unknown()
|
|
911
940
|
})
|
|
912
941
|
])
|
|
913
942
|
),
|
|
914
|
-
stop_reason:
|
|
915
|
-
usage:
|
|
916
|
-
input_tokens:
|
|
917
|
-
output_tokens:
|
|
918
|
-
cache_creation_input_tokens:
|
|
919
|
-
cache_read_input_tokens:
|
|
943
|
+
stop_reason: import_zod3.z.string().nullish(),
|
|
944
|
+
usage: import_zod3.z.object({
|
|
945
|
+
input_tokens: import_zod3.z.number(),
|
|
946
|
+
output_tokens: import_zod3.z.number(),
|
|
947
|
+
cache_creation_input_tokens: import_zod3.z.number().nullish(),
|
|
948
|
+
cache_read_input_tokens: import_zod3.z.number().nullish()
|
|
920
949
|
})
|
|
921
950
|
});
|
|
922
|
-
var anthropicMessagesChunkSchema =
|
|
923
|
-
|
|
924
|
-
type:
|
|
925
|
-
message:
|
|
926
|
-
id:
|
|
927
|
-
model:
|
|
928
|
-
usage:
|
|
929
|
-
input_tokens:
|
|
930
|
-
output_tokens:
|
|
931
|
-
cache_creation_input_tokens:
|
|
932
|
-
cache_read_input_tokens:
|
|
951
|
+
var anthropicMessagesChunkSchema = import_zod3.z.discriminatedUnion("type", [
|
|
952
|
+
import_zod3.z.object({
|
|
953
|
+
type: import_zod3.z.literal("message_start"),
|
|
954
|
+
message: import_zod3.z.object({
|
|
955
|
+
id: import_zod3.z.string().nullish(),
|
|
956
|
+
model: import_zod3.z.string().nullish(),
|
|
957
|
+
usage: import_zod3.z.object({
|
|
958
|
+
input_tokens: import_zod3.z.number(),
|
|
959
|
+
output_tokens: import_zod3.z.number(),
|
|
960
|
+
cache_creation_input_tokens: import_zod3.z.number().nullish(),
|
|
961
|
+
cache_read_input_tokens: import_zod3.z.number().nullish()
|
|
933
962
|
})
|
|
934
963
|
})
|
|
935
964
|
}),
|
|
936
|
-
|
|
937
|
-
type:
|
|
938
|
-
index:
|
|
939
|
-
content_block:
|
|
940
|
-
|
|
941
|
-
type:
|
|
942
|
-
text:
|
|
965
|
+
import_zod3.z.object({
|
|
966
|
+
type: import_zod3.z.literal("content_block_start"),
|
|
967
|
+
index: import_zod3.z.number(),
|
|
968
|
+
content_block: import_zod3.z.discriminatedUnion("type", [
|
|
969
|
+
import_zod3.z.object({
|
|
970
|
+
type: import_zod3.z.literal("text"),
|
|
971
|
+
text: import_zod3.z.string()
|
|
943
972
|
}),
|
|
944
|
-
|
|
945
|
-
type:
|
|
946
|
-
thinking:
|
|
973
|
+
import_zod3.z.object({
|
|
974
|
+
type: import_zod3.z.literal("thinking"),
|
|
975
|
+
thinking: import_zod3.z.string()
|
|
947
976
|
}),
|
|
948
|
-
|
|
949
|
-
type:
|
|
950
|
-
id:
|
|
951
|
-
name:
|
|
977
|
+
import_zod3.z.object({
|
|
978
|
+
type: import_zod3.z.literal("tool_use"),
|
|
979
|
+
id: import_zod3.z.string(),
|
|
980
|
+
name: import_zod3.z.string()
|
|
952
981
|
}),
|
|
953
|
-
|
|
954
|
-
type:
|
|
955
|
-
data:
|
|
982
|
+
import_zod3.z.object({
|
|
983
|
+
type: import_zod3.z.literal("redacted_thinking"),
|
|
984
|
+
data: import_zod3.z.string()
|
|
956
985
|
})
|
|
957
986
|
])
|
|
958
987
|
}),
|
|
959
|
-
|
|
960
|
-
type:
|
|
961
|
-
index:
|
|
962
|
-
delta:
|
|
963
|
-
|
|
964
|
-
type:
|
|
965
|
-
partial_json:
|
|
988
|
+
import_zod3.z.object({
|
|
989
|
+
type: import_zod3.z.literal("content_block_delta"),
|
|
990
|
+
index: import_zod3.z.number(),
|
|
991
|
+
delta: import_zod3.z.discriminatedUnion("type", [
|
|
992
|
+
import_zod3.z.object({
|
|
993
|
+
type: import_zod3.z.literal("input_json_delta"),
|
|
994
|
+
partial_json: import_zod3.z.string()
|
|
966
995
|
}),
|
|
967
|
-
|
|
968
|
-
type:
|
|
969
|
-
text:
|
|
996
|
+
import_zod3.z.object({
|
|
997
|
+
type: import_zod3.z.literal("text_delta"),
|
|
998
|
+
text: import_zod3.z.string()
|
|
970
999
|
}),
|
|
971
|
-
|
|
972
|
-
type:
|
|
973
|
-
thinking:
|
|
1000
|
+
import_zod3.z.object({
|
|
1001
|
+
type: import_zod3.z.literal("thinking_delta"),
|
|
1002
|
+
thinking: import_zod3.z.string()
|
|
974
1003
|
}),
|
|
975
|
-
|
|
976
|
-
type:
|
|
977
|
-
signature:
|
|
1004
|
+
import_zod3.z.object({
|
|
1005
|
+
type: import_zod3.z.literal("signature_delta"),
|
|
1006
|
+
signature: import_zod3.z.string()
|
|
978
1007
|
})
|
|
979
1008
|
])
|
|
980
1009
|
}),
|
|
981
|
-
|
|
982
|
-
type:
|
|
983
|
-
index:
|
|
1010
|
+
import_zod3.z.object({
|
|
1011
|
+
type: import_zod3.z.literal("content_block_stop"),
|
|
1012
|
+
index: import_zod3.z.number()
|
|
984
1013
|
}),
|
|
985
|
-
|
|
986
|
-
type:
|
|
987
|
-
error:
|
|
988
|
-
type:
|
|
989
|
-
message:
|
|
1014
|
+
import_zod3.z.object({
|
|
1015
|
+
type: import_zod3.z.literal("error"),
|
|
1016
|
+
error: import_zod3.z.object({
|
|
1017
|
+
type: import_zod3.z.string(),
|
|
1018
|
+
message: import_zod3.z.string()
|
|
990
1019
|
})
|
|
991
1020
|
}),
|
|
992
|
-
|
|
993
|
-
type:
|
|
994
|
-
delta:
|
|
995
|
-
usage:
|
|
1021
|
+
import_zod3.z.object({
|
|
1022
|
+
type: import_zod3.z.literal("message_delta"),
|
|
1023
|
+
delta: import_zod3.z.object({ stop_reason: import_zod3.z.string().nullish() }),
|
|
1024
|
+
usage: import_zod3.z.object({ output_tokens: import_zod3.z.number() })
|
|
996
1025
|
}),
|
|
997
|
-
|
|
998
|
-
type:
|
|
1026
|
+
import_zod3.z.object({
|
|
1027
|
+
type: import_zod3.z.literal("message_stop")
|
|
999
1028
|
}),
|
|
1000
|
-
|
|
1001
|
-
type:
|
|
1029
|
+
import_zod3.z.object({
|
|
1030
|
+
type: import_zod3.z.literal("ping")
|
|
1002
1031
|
})
|
|
1003
1032
|
]);
|
|
1004
|
-
var
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
budgetTokens: import_zod2.z.number().optional()
|
|
1008
|
-
}).optional()
|
|
1033
|
+
var anthropicReasoningMetadataSchema = import_zod3.z.object({
|
|
1034
|
+
signature: import_zod3.z.string().optional(),
|
|
1035
|
+
redactedData: import_zod3.z.string().optional()
|
|
1009
1036
|
});
|
|
1010
1037
|
|
|
1011
1038
|
// src/anthropic-tools.ts
|
|
1012
|
-
var
|
|
1013
|
-
var Bash20241022Parameters =
|
|
1014
|
-
command:
|
|
1015
|
-
restart:
|
|
1039
|
+
var import_zod4 = require("zod");
|
|
1040
|
+
var Bash20241022Parameters = import_zod4.z.object({
|
|
1041
|
+
command: import_zod4.z.string(),
|
|
1042
|
+
restart: import_zod4.z.boolean().optional()
|
|
1016
1043
|
});
|
|
1017
1044
|
function bashTool_20241022(options = {}) {
|
|
1018
1045
|
return {
|
|
@@ -1024,9 +1051,9 @@ function bashTool_20241022(options = {}) {
|
|
|
1024
1051
|
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1025
1052
|
};
|
|
1026
1053
|
}
|
|
1027
|
-
var Bash20250124Parameters =
|
|
1028
|
-
command:
|
|
1029
|
-
restart:
|
|
1054
|
+
var Bash20250124Parameters = import_zod4.z.object({
|
|
1055
|
+
command: import_zod4.z.string(),
|
|
1056
|
+
restart: import_zod4.z.boolean().optional()
|
|
1030
1057
|
});
|
|
1031
1058
|
function bashTool_20250124(options = {}) {
|
|
1032
1059
|
return {
|
|
@@ -1038,14 +1065,14 @@ function bashTool_20250124(options = {}) {
|
|
|
1038
1065
|
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1039
1066
|
};
|
|
1040
1067
|
}
|
|
1041
|
-
var TextEditor20241022Parameters =
|
|
1042
|
-
command:
|
|
1043
|
-
path:
|
|
1044
|
-
file_text:
|
|
1045
|
-
insert_line:
|
|
1046
|
-
new_str:
|
|
1047
|
-
old_str:
|
|
1048
|
-
view_range:
|
|
1068
|
+
var TextEditor20241022Parameters = import_zod4.z.object({
|
|
1069
|
+
command: import_zod4.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
|
|
1070
|
+
path: import_zod4.z.string(),
|
|
1071
|
+
file_text: import_zod4.z.string().optional(),
|
|
1072
|
+
insert_line: import_zod4.z.number().int().optional(),
|
|
1073
|
+
new_str: import_zod4.z.string().optional(),
|
|
1074
|
+
old_str: import_zod4.z.string().optional(),
|
|
1075
|
+
view_range: import_zod4.z.array(import_zod4.z.number().int()).optional()
|
|
1049
1076
|
});
|
|
1050
1077
|
function textEditorTool_20241022(options = {}) {
|
|
1051
1078
|
return {
|
|
@@ -1057,14 +1084,14 @@ function textEditorTool_20241022(options = {}) {
|
|
|
1057
1084
|
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1058
1085
|
};
|
|
1059
1086
|
}
|
|
1060
|
-
var TextEditor20250124Parameters =
|
|
1061
|
-
command:
|
|
1062
|
-
path:
|
|
1063
|
-
file_text:
|
|
1064
|
-
insert_line:
|
|
1065
|
-
new_str:
|
|
1066
|
-
old_str:
|
|
1067
|
-
view_range:
|
|
1087
|
+
var TextEditor20250124Parameters = import_zod4.z.object({
|
|
1088
|
+
command: import_zod4.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
|
|
1089
|
+
path: import_zod4.z.string(),
|
|
1090
|
+
file_text: import_zod4.z.string().optional(),
|
|
1091
|
+
insert_line: import_zod4.z.number().int().optional(),
|
|
1092
|
+
new_str: import_zod4.z.string().optional(),
|
|
1093
|
+
old_str: import_zod4.z.string().optional(),
|
|
1094
|
+
view_range: import_zod4.z.array(import_zod4.z.number().int()).optional()
|
|
1068
1095
|
});
|
|
1069
1096
|
function textEditorTool_20250124(options = {}) {
|
|
1070
1097
|
return {
|
|
@@ -1076,8 +1103,8 @@ function textEditorTool_20250124(options = {}) {
|
|
|
1076
1103
|
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1077
1104
|
};
|
|
1078
1105
|
}
|
|
1079
|
-
var Computer20241022Parameters =
|
|
1080
|
-
action:
|
|
1106
|
+
var Computer20241022Parameters = import_zod4.z.object({
|
|
1107
|
+
action: import_zod4.z.enum([
|
|
1081
1108
|
"key",
|
|
1082
1109
|
"type",
|
|
1083
1110
|
"mouse_move",
|
|
@@ -1089,8 +1116,8 @@ var Computer20241022Parameters = import_zod3.z.object({
|
|
|
1089
1116
|
"screenshot",
|
|
1090
1117
|
"cursor_position"
|
|
1091
1118
|
]),
|
|
1092
|
-
coordinate:
|
|
1093
|
-
text:
|
|
1119
|
+
coordinate: import_zod4.z.array(import_zod4.z.number().int()).optional(),
|
|
1120
|
+
text: import_zod4.z.string().optional()
|
|
1094
1121
|
});
|
|
1095
1122
|
function computerTool_20241022(options) {
|
|
1096
1123
|
return {
|
|
@@ -1106,8 +1133,8 @@ function computerTool_20241022(options) {
|
|
|
1106
1133
|
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1107
1134
|
};
|
|
1108
1135
|
}
|
|
1109
|
-
var Computer20250124Parameters =
|
|
1110
|
-
action:
|
|
1136
|
+
var Computer20250124Parameters = import_zod4.z.object({
|
|
1137
|
+
action: import_zod4.z.enum([
|
|
1111
1138
|
"key",
|
|
1112
1139
|
"hold_key",
|
|
1113
1140
|
"type",
|
|
@@ -1125,12 +1152,12 @@ var Computer20250124Parameters = import_zod3.z.object({
|
|
|
1125
1152
|
"wait",
|
|
1126
1153
|
"screenshot"
|
|
1127
1154
|
]),
|
|
1128
|
-
coordinate:
|
|
1129
|
-
duration:
|
|
1130
|
-
scroll_amount:
|
|
1131
|
-
scroll_direction:
|
|
1132
|
-
start_coordinate:
|
|
1133
|
-
text:
|
|
1155
|
+
coordinate: import_zod4.z.tuple([import_zod4.z.number().int(), import_zod4.z.number().int()]).optional(),
|
|
1156
|
+
duration: import_zod4.z.number().optional(),
|
|
1157
|
+
scroll_amount: import_zod4.z.number().optional(),
|
|
1158
|
+
scroll_direction: import_zod4.z.enum(["up", "down", "left", "right"]).optional(),
|
|
1159
|
+
start_coordinate: import_zod4.z.tuple([import_zod4.z.number().int(), import_zod4.z.number().int()]).optional(),
|
|
1160
|
+
text: import_zod4.z.string().optional()
|
|
1134
1161
|
});
|
|
1135
1162
|
function computerTool_20250124(options) {
|
|
1136
1163
|
return {
|
|
@@ -1168,20 +1195,22 @@ function createAnthropic(options = {}) {
|
|
|
1168
1195
|
}),
|
|
1169
1196
|
...options.headers
|
|
1170
1197
|
});
|
|
1171
|
-
const createChatModel = (modelId
|
|
1198
|
+
const createChatModel = (modelId) => new AnthropicMessagesLanguageModel(modelId, {
|
|
1172
1199
|
provider: "anthropic.messages",
|
|
1173
1200
|
baseURL,
|
|
1174
1201
|
headers: getHeaders,
|
|
1175
1202
|
fetch: options.fetch,
|
|
1176
|
-
|
|
1203
|
+
supportedUrls: () => ({
|
|
1204
|
+
"image/*": [/^https?:\/\/.*$/]
|
|
1205
|
+
})
|
|
1177
1206
|
});
|
|
1178
|
-
const provider = function(modelId
|
|
1207
|
+
const provider = function(modelId) {
|
|
1179
1208
|
if (new.target) {
|
|
1180
1209
|
throw new Error(
|
|
1181
1210
|
"The Anthropic model function cannot be called with the new keyword."
|
|
1182
1211
|
);
|
|
1183
1212
|
}
|
|
1184
|
-
return createChatModel(modelId
|
|
1213
|
+
return createChatModel(modelId);
|
|
1185
1214
|
};
|
|
1186
1215
|
provider.languageModel = createChatModel;
|
|
1187
1216
|
provider.chat = createChatModel;
|
|
@@ -1189,6 +1218,9 @@ function createAnthropic(options = {}) {
|
|
|
1189
1218
|
provider.textEmbeddingModel = (modelId) => {
|
|
1190
1219
|
throw new import_provider4.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
|
|
1191
1220
|
};
|
|
1221
|
+
provider.imageModel = (modelId) => {
|
|
1222
|
+
throw new import_provider4.NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
1223
|
+
};
|
|
1192
1224
|
provider.tools = anthropicTools;
|
|
1193
1225
|
return provider;
|
|
1194
1226
|
}
|