@ai-sdk/anthropic 3.0.54 → 3.0.55
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 +6 -0
- package/dist/index.d.mts +18 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +232 -175
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +212 -155
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +18 -0
- package/dist/internal/index.d.ts +18 -0
- package/dist/internal/index.js +231 -174
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +211 -154
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/anthropic-messages-language-model.ts +29 -0
- package/src/convert-to-anthropic-messages-prompt.ts +31 -3
- package/src/tool/code-execution_20260120.ts +38 -0
package/package.json
CHANGED
|
@@ -1056,6 +1056,19 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
|
|
|
1056
1056
|
content: part.content.content ?? [],
|
|
1057
1057
|
},
|
|
1058
1058
|
});
|
|
1059
|
+
} else if (part.content.type === 'encrypted_code_execution_result') {
|
|
1060
|
+
content.push({
|
|
1061
|
+
type: 'tool-result',
|
|
1062
|
+
toolCallId: part.tool_use_id,
|
|
1063
|
+
toolName: toolNameMapping.toCustomToolName('code_execution'),
|
|
1064
|
+
result: {
|
|
1065
|
+
type: part.content.type,
|
|
1066
|
+
encrypted_stdout: part.content.encrypted_stdout,
|
|
1067
|
+
stderr: part.content.stderr,
|
|
1068
|
+
return_code: part.content.return_code,
|
|
1069
|
+
content: part.content.content ?? [],
|
|
1070
|
+
},
|
|
1071
|
+
});
|
|
1059
1072
|
} else if (part.content.type === 'code_execution_tool_result_error') {
|
|
1060
1073
|
content.push({
|
|
1061
1074
|
type: 'tool-result',
|
|
@@ -1622,6 +1635,22 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
|
|
|
1622
1635
|
content: part.content.content ?? [],
|
|
1623
1636
|
},
|
|
1624
1637
|
});
|
|
1638
|
+
} else if (
|
|
1639
|
+
part.content.type === 'encrypted_code_execution_result'
|
|
1640
|
+
) {
|
|
1641
|
+
controller.enqueue({
|
|
1642
|
+
type: 'tool-result',
|
|
1643
|
+
toolCallId: part.tool_use_id,
|
|
1644
|
+
toolName:
|
|
1645
|
+
toolNameMapping.toCustomToolName('code_execution'),
|
|
1646
|
+
result: {
|
|
1647
|
+
type: part.content.type,
|
|
1648
|
+
encrypted_stdout: part.content.encrypted_stdout,
|
|
1649
|
+
stderr: part.content.stderr,
|
|
1650
|
+
return_code: part.content.return_code,
|
|
1651
|
+
content: part.content.content ?? [],
|
|
1652
|
+
},
|
|
1653
|
+
});
|
|
1625
1654
|
} else if (
|
|
1626
1655
|
part.content.type === 'code_execution_tool_result_error'
|
|
1627
1656
|
) {
|
|
@@ -26,6 +26,7 @@ import { anthropicFilePartProviderOptions } from './anthropic-messages-options';
|
|
|
26
26
|
import { CacheControlValidator } from './get-cache-control';
|
|
27
27
|
import { codeExecution_20250522OutputSchema } from './tool/code-execution_20250522';
|
|
28
28
|
import { codeExecution_20250825OutputSchema } from './tool/code-execution_20250825';
|
|
29
|
+
import { codeExecution_20260120OutputSchema } from './tool/code-execution_20260120';
|
|
29
30
|
import { toolSearchRegex_20251119OutputSchema as toolSearchOutputSchema } from './tool/tool-search-regex_20251119';
|
|
30
31
|
import { webFetch_20250910OutputSchema } from './tool/web-fetch-20250910';
|
|
31
32
|
import { webSearch_20250305OutputSchema } from './tool/web-search_20250305';
|
|
@@ -767,8 +768,9 @@ export async function convertToAnthropicMessagesPrompt({
|
|
|
767
768
|
break;
|
|
768
769
|
}
|
|
769
770
|
|
|
770
|
-
// to distinguish between code execution 20250522
|
|
771
|
-
//
|
|
771
|
+
// to distinguish between code execution 20250522, 20250825,
|
|
772
|
+
// and encrypted results (from web_fetch_20260209/web_search_20260209 injection),
|
|
773
|
+
// we check the type property in output.value
|
|
772
774
|
if (output.value.type === 'code_execution_result') {
|
|
773
775
|
// code execution 20250522
|
|
774
776
|
const codeExecutionOutput = await validateTypes({
|
|
@@ -788,6 +790,33 @@ export async function convertToAnthropicMessagesPrompt({
|
|
|
788
790
|
},
|
|
789
791
|
cache_control: cacheControl,
|
|
790
792
|
});
|
|
793
|
+
} else if (
|
|
794
|
+
output.value.type === 'encrypted_code_execution_result'
|
|
795
|
+
) {
|
|
796
|
+
// code execution 20260120 encrypted result
|
|
797
|
+
const codeExecutionOutput = await validateTypes({
|
|
798
|
+
value: output.value,
|
|
799
|
+
schema: codeExecution_20260120OutputSchema,
|
|
800
|
+
});
|
|
801
|
+
|
|
802
|
+
if (
|
|
803
|
+
codeExecutionOutput.type ===
|
|
804
|
+
'encrypted_code_execution_result'
|
|
805
|
+
) {
|
|
806
|
+
anthropicContent.push({
|
|
807
|
+
type: 'code_execution_tool_result',
|
|
808
|
+
tool_use_id: part.toolCallId,
|
|
809
|
+
content: {
|
|
810
|
+
type: codeExecutionOutput.type,
|
|
811
|
+
encrypted_stdout:
|
|
812
|
+
codeExecutionOutput.encrypted_stdout,
|
|
813
|
+
stderr: codeExecutionOutput.stderr,
|
|
814
|
+
return_code: codeExecutionOutput.return_code,
|
|
815
|
+
content: codeExecutionOutput.content ?? [],
|
|
816
|
+
},
|
|
817
|
+
cache_control: cacheControl,
|
|
818
|
+
});
|
|
819
|
+
}
|
|
791
820
|
} else {
|
|
792
821
|
// code execution 20250825
|
|
793
822
|
const codeExecutionOutput = await validateTypes({
|
|
@@ -796,7 +825,6 @@ export async function convertToAnthropicMessagesPrompt({
|
|
|
796
825
|
});
|
|
797
826
|
|
|
798
827
|
if (codeExecutionOutput.type === 'code_execution_result') {
|
|
799
|
-
// Programmatic tool calling result - same format as 20250522
|
|
800
828
|
anthropicContent.push({
|
|
801
829
|
type: 'code_execution_tool_result',
|
|
802
830
|
tool_use_id: part.toolCallId,
|
|
@@ -23,6 +23,21 @@ export const codeExecution_20260120OutputSchema = lazySchema(() =>
|
|
|
23
23
|
.optional()
|
|
24
24
|
.default([]),
|
|
25
25
|
}),
|
|
26
|
+
z.object({
|
|
27
|
+
type: z.literal('encrypted_code_execution_result'),
|
|
28
|
+
encrypted_stdout: z.string(),
|
|
29
|
+
stderr: z.string(),
|
|
30
|
+
return_code: z.number(),
|
|
31
|
+
content: z
|
|
32
|
+
.array(
|
|
33
|
+
z.object({
|
|
34
|
+
type: z.literal('code_execution_output'),
|
|
35
|
+
file_id: z.string(),
|
|
36
|
+
}),
|
|
37
|
+
)
|
|
38
|
+
.optional()
|
|
39
|
+
.default([]),
|
|
40
|
+
}),
|
|
26
41
|
z.object({
|
|
27
42
|
type: z.literal('bash_code_execution_result'),
|
|
28
43
|
content: z.array(
|
|
@@ -183,6 +198,29 @@ const factory = createProviderToolFactoryWithOutputSchema<
|
|
|
183
198
|
*/
|
|
184
199
|
return_code: number;
|
|
185
200
|
|
|
201
|
+
/**
|
|
202
|
+
* Output file Id list
|
|
203
|
+
*/
|
|
204
|
+
content: Array<{ type: 'code_execution_output'; file_id: string }>;
|
|
205
|
+
}
|
|
206
|
+
| {
|
|
207
|
+
type: 'encrypted_code_execution_result';
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Encrypted output from successful execution
|
|
211
|
+
*/
|
|
212
|
+
encrypted_stdout: string;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Error messages if execution fails
|
|
216
|
+
*/
|
|
217
|
+
stderr: string;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* 0 for success, non-zero for failure
|
|
221
|
+
*/
|
|
222
|
+
return_code: number;
|
|
223
|
+
|
|
186
224
|
/**
|
|
187
225
|
* Output file Id list
|
|
188
226
|
*/
|