@langchain/anthropic 0.3.23 → 0.3.25
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/dist/chat_models.cjs +8 -1
- package/dist/chat_models.js +8 -1
- package/dist/index.d.ts +1 -0
- package/dist/output_parsers.cjs +0 -10
- package/dist/output_parsers.js +0 -10
- package/dist/types.d.ts +2 -1
- package/dist/utils/message_inputs.cjs +36 -4
- package/dist/utils/message_inputs.js +36 -4
- package/dist/utils/message_outputs.cjs +0 -11
- package/dist/utils/message_outputs.js +0 -11
- package/package.json +3 -3
package/dist/chat_models.cjs
CHANGED
|
@@ -44,7 +44,14 @@ function isAnthropicTool(tool) {
|
|
|
44
44
|
return "input_schema" in tool;
|
|
45
45
|
}
|
|
46
46
|
function isBuiltinTool(tool) {
|
|
47
|
-
const builtinTools = [
|
|
47
|
+
const builtinTools = [
|
|
48
|
+
"web_search",
|
|
49
|
+
"bash",
|
|
50
|
+
"code_execution",
|
|
51
|
+
"computer",
|
|
52
|
+
"str_replace_editor",
|
|
53
|
+
"str_replace_based_edit_tool",
|
|
54
|
+
];
|
|
48
55
|
return (typeof tool === "object" &&
|
|
49
56
|
tool !== null &&
|
|
50
57
|
"type" in tool &&
|
package/dist/chat_models.js
CHANGED
|
@@ -41,7 +41,14 @@ function isAnthropicTool(tool) {
|
|
|
41
41
|
return "input_schema" in tool;
|
|
42
42
|
}
|
|
43
43
|
function isBuiltinTool(tool) {
|
|
44
|
-
const builtinTools = [
|
|
44
|
+
const builtinTools = [
|
|
45
|
+
"web_search",
|
|
46
|
+
"bash",
|
|
47
|
+
"code_execution",
|
|
48
|
+
"computer",
|
|
49
|
+
"str_replace_editor",
|
|
50
|
+
"str_replace_based_edit_tool",
|
|
51
|
+
];
|
|
45
52
|
return (typeof tool === "object" &&
|
|
46
53
|
tool !== null &&
|
|
47
54
|
"type" in tool &&
|
package/dist/index.d.ts
CHANGED
package/dist/output_parsers.cjs
CHANGED
|
@@ -101,16 +101,6 @@ function extractToolCalls(content) {
|
|
|
101
101
|
type: "tool_call",
|
|
102
102
|
});
|
|
103
103
|
}
|
|
104
|
-
else if (block.type === "server_tool_use" &&
|
|
105
|
-
block.name === "web_search") {
|
|
106
|
-
// Handle Anthropic built-in web search tool
|
|
107
|
-
toolCalls.push({
|
|
108
|
-
name: block.name,
|
|
109
|
-
args: block.input,
|
|
110
|
-
id: block.id,
|
|
111
|
-
type: "tool_call",
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
104
|
}
|
|
115
105
|
return toolCalls;
|
|
116
106
|
}
|
package/dist/output_parsers.js
CHANGED
|
@@ -96,16 +96,6 @@ export function extractToolCalls(content) {
|
|
|
96
96
|
type: "tool_call",
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
|
-
else if (block.type === "server_tool_use" &&
|
|
100
|
-
block.name === "web_search") {
|
|
101
|
-
// Handle Anthropic built-in web search tool
|
|
102
|
-
toolCalls.push({
|
|
103
|
-
name: block.name,
|
|
104
|
-
args: block.input,
|
|
105
|
-
id: block.id,
|
|
106
|
-
type: "tool_call",
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
99
|
}
|
|
110
100
|
return toolCalls;
|
|
111
101
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export type AnthropicRedactedThinkingBlockParam = Anthropic.Messages.RedactedThi
|
|
|
28
28
|
export type AnthropicServerToolUseBlockParam = Anthropic.Messages.ServerToolUseBlockParam;
|
|
29
29
|
export type AnthropicWebSearchToolResultBlockParam = Anthropic.Messages.WebSearchToolResultBlockParam;
|
|
30
30
|
export type AnthropicWebSearchResultBlockParam = Anthropic.Messages.WebSearchResultBlockParam;
|
|
31
|
-
export type
|
|
31
|
+
export type AnthropicSearchResultBlockParam = Anthropic.Beta.BetaSearchResultBlockParam;
|
|
32
|
+
export type ChatAnthropicContentBlock = AnthropicTextBlockParam | AnthropicImageBlockParam | AnthropicToolUseBlockParam | AnthropicToolResultBlockParam | AnthropicDocumentBlockParam | AnthropicThinkingBlockParam | AnthropicRedactedThinkingBlockParam | AnthropicServerToolUseBlockParam | AnthropicWebSearchToolResultBlockParam | AnthropicWebSearchResultBlockParam | AnthropicSearchResultBlockParam;
|
|
32
33
|
export declare function isAnthropicImageBlockParam(block: unknown): block is AnthropicImageBlockParam;
|
|
33
34
|
export type AnthropicBuiltInToolUnion = Exclude<Anthropic.Messages.ToolUnion, Anthropic.Messages.Tool>;
|
|
@@ -77,7 +77,7 @@ function _ensureMessageContents(messages) {
|
|
|
77
77
|
type: "tool_result",
|
|
78
78
|
// rare case: message.content could be undefined
|
|
79
79
|
...(message.content != null
|
|
80
|
-
? { content: _formatContent(message
|
|
80
|
+
? { content: _formatContent(message) }
|
|
81
81
|
: {}),
|
|
82
82
|
tool_use_id: message.tool_call_id,
|
|
83
83
|
},
|
|
@@ -284,7 +284,7 @@ const standardContentBlockConverter = {
|
|
|
284
284
|
}
|
|
285
285
|
},
|
|
286
286
|
};
|
|
287
|
-
function _formatContent(
|
|
287
|
+
function _formatContent(message) {
|
|
288
288
|
const toolTypes = [
|
|
289
289
|
"tool_use",
|
|
290
290
|
"tool_result",
|
|
@@ -294,6 +294,7 @@ function _formatContent(content) {
|
|
|
294
294
|
"web_search_result",
|
|
295
295
|
];
|
|
296
296
|
const textTypes = ["text", "text_delta"];
|
|
297
|
+
const { content } = message;
|
|
297
298
|
if (typeof content === "string") {
|
|
298
299
|
return content;
|
|
299
300
|
}
|
|
@@ -344,6 +345,21 @@ function _formatContent(content) {
|
|
|
344
345
|
};
|
|
345
346
|
return block;
|
|
346
347
|
}
|
|
348
|
+
else if (contentPart.type === "search_result") {
|
|
349
|
+
const block = {
|
|
350
|
+
type: "search_result", // Explicitly setting the type as "search_result"
|
|
351
|
+
title: contentPart.title,
|
|
352
|
+
source: contentPart.source,
|
|
353
|
+
...("cache_control" in contentPart && contentPart.cache_control
|
|
354
|
+
? { cache_control: contentPart.cache_control }
|
|
355
|
+
: {}),
|
|
356
|
+
...("citations" in contentPart && contentPart.citations
|
|
357
|
+
? { citations: contentPart.citations }
|
|
358
|
+
: {}),
|
|
359
|
+
content: contentPart.content,
|
|
360
|
+
};
|
|
361
|
+
return block;
|
|
362
|
+
}
|
|
347
363
|
else if (textTypes.find((t) => t === contentPart.type) &&
|
|
348
364
|
"text" in contentPart) {
|
|
349
365
|
// Assuming contentPart is of type MessageContentText here
|
|
@@ -385,6 +401,22 @@ function _formatContent(content) {
|
|
|
385
401
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
386
402
|
};
|
|
387
403
|
}
|
|
404
|
+
else if ("functionCall" in contentPart &&
|
|
405
|
+
contentPart.functionCall &&
|
|
406
|
+
typeof contentPart.functionCall === "object" &&
|
|
407
|
+
(0, messages_1.isAIMessage)(message)) {
|
|
408
|
+
const correspondingToolCall = message.tool_calls?.find((toolCall) => toolCall.name === contentPart.functionCall.name);
|
|
409
|
+
if (!correspondingToolCall) {
|
|
410
|
+
throw new Error(`Could not find tool call for function call ${contentPart.functionCall.name}`);
|
|
411
|
+
}
|
|
412
|
+
// Google GenAI models include a `functionCall` object inside content. We should ignore it as Anthropic will not support it.
|
|
413
|
+
return {
|
|
414
|
+
id: correspondingToolCall.id,
|
|
415
|
+
type: "tool_use",
|
|
416
|
+
name: correspondingToolCall.name,
|
|
417
|
+
input: contentPart.functionCall.args,
|
|
418
|
+
};
|
|
419
|
+
}
|
|
388
420
|
else {
|
|
389
421
|
throw new Error("Unsupported message content format");
|
|
390
422
|
}
|
|
@@ -451,14 +483,14 @@ function _convertMessagesToAnthropicPayload(messages) {
|
|
|
451
483
|
}
|
|
452
484
|
return {
|
|
453
485
|
role,
|
|
454
|
-
content: _formatContent(message
|
|
486
|
+
content: _formatContent(message),
|
|
455
487
|
};
|
|
456
488
|
}
|
|
457
489
|
}
|
|
458
490
|
else {
|
|
459
491
|
return {
|
|
460
492
|
role,
|
|
461
|
-
content: _formatContent(message
|
|
493
|
+
content: _formatContent(message),
|
|
462
494
|
};
|
|
463
495
|
}
|
|
464
496
|
});
|
|
@@ -73,7 +73,7 @@ function _ensureMessageContents(messages) {
|
|
|
73
73
|
type: "tool_result",
|
|
74
74
|
// rare case: message.content could be undefined
|
|
75
75
|
...(message.content != null
|
|
76
|
-
? { content: _formatContent(message
|
|
76
|
+
? { content: _formatContent(message) }
|
|
77
77
|
: {}),
|
|
78
78
|
tool_use_id: message.tool_call_id,
|
|
79
79
|
},
|
|
@@ -280,7 +280,7 @@ const standardContentBlockConverter = {
|
|
|
280
280
|
}
|
|
281
281
|
},
|
|
282
282
|
};
|
|
283
|
-
function _formatContent(
|
|
283
|
+
function _formatContent(message) {
|
|
284
284
|
const toolTypes = [
|
|
285
285
|
"tool_use",
|
|
286
286
|
"tool_result",
|
|
@@ -290,6 +290,7 @@ function _formatContent(content) {
|
|
|
290
290
|
"web_search_result",
|
|
291
291
|
];
|
|
292
292
|
const textTypes = ["text", "text_delta"];
|
|
293
|
+
const { content } = message;
|
|
293
294
|
if (typeof content === "string") {
|
|
294
295
|
return content;
|
|
295
296
|
}
|
|
@@ -340,6 +341,21 @@ function _formatContent(content) {
|
|
|
340
341
|
};
|
|
341
342
|
return block;
|
|
342
343
|
}
|
|
344
|
+
else if (contentPart.type === "search_result") {
|
|
345
|
+
const block = {
|
|
346
|
+
type: "search_result", // Explicitly setting the type as "search_result"
|
|
347
|
+
title: contentPart.title,
|
|
348
|
+
source: contentPart.source,
|
|
349
|
+
...("cache_control" in contentPart && contentPart.cache_control
|
|
350
|
+
? { cache_control: contentPart.cache_control }
|
|
351
|
+
: {}),
|
|
352
|
+
...("citations" in contentPart && contentPart.citations
|
|
353
|
+
? { citations: contentPart.citations }
|
|
354
|
+
: {}),
|
|
355
|
+
content: contentPart.content,
|
|
356
|
+
};
|
|
357
|
+
return block;
|
|
358
|
+
}
|
|
343
359
|
else if (textTypes.find((t) => t === contentPart.type) &&
|
|
344
360
|
"text" in contentPart) {
|
|
345
361
|
// Assuming contentPart is of type MessageContentText here
|
|
@@ -381,6 +397,22 @@ function _formatContent(content) {
|
|
|
381
397
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
382
398
|
};
|
|
383
399
|
}
|
|
400
|
+
else if ("functionCall" in contentPart &&
|
|
401
|
+
contentPart.functionCall &&
|
|
402
|
+
typeof contentPart.functionCall === "object" &&
|
|
403
|
+
isAIMessage(message)) {
|
|
404
|
+
const correspondingToolCall = message.tool_calls?.find((toolCall) => toolCall.name === contentPart.functionCall.name);
|
|
405
|
+
if (!correspondingToolCall) {
|
|
406
|
+
throw new Error(`Could not find tool call for function call ${contentPart.functionCall.name}`);
|
|
407
|
+
}
|
|
408
|
+
// Google GenAI models include a `functionCall` object inside content. We should ignore it as Anthropic will not support it.
|
|
409
|
+
return {
|
|
410
|
+
id: correspondingToolCall.id,
|
|
411
|
+
type: "tool_use",
|
|
412
|
+
name: correspondingToolCall.name,
|
|
413
|
+
input: contentPart.functionCall.args,
|
|
414
|
+
};
|
|
415
|
+
}
|
|
384
416
|
else {
|
|
385
417
|
throw new Error("Unsupported message content format");
|
|
386
418
|
}
|
|
@@ -447,14 +479,14 @@ export function _convertMessagesToAnthropicPayload(messages) {
|
|
|
447
479
|
}
|
|
448
480
|
return {
|
|
449
481
|
role,
|
|
450
|
-
content: _formatContent(message
|
|
482
|
+
content: _formatContent(message),
|
|
451
483
|
};
|
|
452
484
|
}
|
|
453
485
|
}
|
|
454
486
|
else {
|
|
455
487
|
return {
|
|
456
488
|
role,
|
|
457
|
-
content: _formatContent(message
|
|
489
|
+
content: _formatContent(message),
|
|
458
490
|
};
|
|
459
491
|
}
|
|
460
492
|
});
|
|
@@ -79,17 +79,6 @@ function _makeMessageChunkFromAnthropicEvent(data, fields) {
|
|
|
79
79
|
},
|
|
80
80
|
];
|
|
81
81
|
}
|
|
82
|
-
else if (contentBlock.type === "server_tool_use") {
|
|
83
|
-
// Handle anthropic built-in server tool use (like web search)
|
|
84
|
-
toolCallChunks = [
|
|
85
|
-
{
|
|
86
|
-
id: contentBlock.id,
|
|
87
|
-
index: data.index,
|
|
88
|
-
name: contentBlock.name,
|
|
89
|
-
args: "",
|
|
90
|
-
},
|
|
91
|
-
];
|
|
92
|
-
}
|
|
93
82
|
else {
|
|
94
83
|
toolCallChunks = [];
|
|
95
84
|
}
|
|
@@ -75,17 +75,6 @@ export function _makeMessageChunkFromAnthropicEvent(data, fields) {
|
|
|
75
75
|
},
|
|
76
76
|
];
|
|
77
77
|
}
|
|
78
|
-
else if (contentBlock.type === "server_tool_use") {
|
|
79
|
-
// Handle anthropic built-in server tool use (like web search)
|
|
80
|
-
toolCallChunks = [
|
|
81
|
-
{
|
|
82
|
-
id: contentBlock.id,
|
|
83
|
-
index: data.index,
|
|
84
|
-
name: contentBlock.name,
|
|
85
|
-
args: "",
|
|
86
|
-
},
|
|
87
|
-
];
|
|
88
|
-
}
|
|
89
78
|
else {
|
|
90
79
|
toolCallChunks = [];
|
|
91
80
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/anthropic",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.25",
|
|
4
4
|
"description": "Anthropic integrations for LangChain.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -35,14 +35,14 @@
|
|
|
35
35
|
"author": "LangChain",
|
|
36
36
|
"license": "MIT",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@anthropic-ai/sdk": "^0.
|
|
38
|
+
"@anthropic-ai/sdk": "^0.56.0",
|
|
39
39
|
"fast-xml-parser": "^4.4.1"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@langchain/core": ">=0.3.58 <0.4.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@anthropic-ai/vertex-sdk": "^0.
|
|
45
|
+
"@anthropic-ai/vertex-sdk": "^0.11.5",
|
|
46
46
|
"@jest/globals": "^29.5.0",
|
|
47
47
|
"@langchain/core": "workspace:*",
|
|
48
48
|
"@langchain/scripts": ">=0.1.0 <0.2.0",
|