@nocobase/plugin-ai 2.0.0-beta.7 → 2.0.0-beta.8
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/client/index.js +1 -1
- package/dist/externalVersion.js +11 -11
- package/dist/node_modules/@langchain/anthropic/dist/chat_models.cjs +43 -8
- package/dist/node_modules/@langchain/anthropic/dist/chat_models.d.ts +15 -5
- package/dist/node_modules/@langchain/anthropic/dist/chat_models.js +43 -8
- package/dist/node_modules/@langchain/anthropic/dist/index.d.ts +1 -0
- package/dist/node_modules/@langchain/anthropic/dist/output_parsers.cjs +0 -10
- package/dist/node_modules/@langchain/anthropic/dist/output_parsers.js +0 -10
- package/dist/node_modules/@langchain/anthropic/dist/types.d.ts +3 -1
- package/dist/node_modules/@langchain/anthropic/dist/utils/message_inputs.cjs +36 -5
- package/dist/node_modules/@langchain/anthropic/dist/utils/message_inputs.js +36 -5
- package/dist/node_modules/@langchain/anthropic/dist/utils/message_outputs.cjs +4 -11
- package/dist/node_modules/@langchain/anthropic/dist/utils/message_outputs.js +4 -11
- package/dist/node_modules/@langchain/anthropic/dist/utils/tools.cjs +5 -0
- package/dist/node_modules/@langchain/anthropic/dist/utils/tools.d.ts +1 -1
- package/dist/node_modules/@langchain/anthropic/dist/utils/tools.js +5 -0
- package/dist/node_modules/@langchain/anthropic/index.cjs +1 -1
- package/dist/node_modules/@langchain/anthropic/package.json +1 -1
- package/dist/node_modules/@langchain/core/package.json +1 -1
- package/dist/node_modules/@langchain/deepseek/package.json +1 -1
- package/dist/node_modules/@langchain/google-genai/package.json +1 -1
- package/dist/node_modules/@langchain/ollama/package.json +1 -1
- package/dist/node_modules/@langchain/openai/package.json +1 -1
- package/dist/node_modules/nodejs-snowflake/package.json +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/node_modules/zod-to-json-schema/package.json +1 -1
- package/dist/server/features/vector-store-provider.d.ts +2 -3
- package/dist/server/llm-providers/anthropic.js +25 -4
- package/dist/server/llm-providers/google-genai.js +0 -3
- package/dist/server/llm-providers/provider.js +0 -3
- package/package.json +6 -3
- package/patches/@langchain+anthropic+0.3.34.patch +32 -0
package/dist/externalVersion.js
CHANGED
|
@@ -8,29 +8,29 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
|
-
"@nocobase/plugin-acl": "2.0.0-beta.
|
|
12
|
-
"@nocobase/plugin-workflow": "2.0.0-beta.
|
|
13
|
-
"@nocobase/client": "2.0.0-beta.
|
|
14
|
-
"@nocobase/utils": "2.0.0-beta.
|
|
15
|
-
"@nocobase/database": "2.0.0-beta.
|
|
16
|
-
"@nocobase/server": "2.0.0-beta.
|
|
11
|
+
"@nocobase/plugin-acl": "2.0.0-beta.8",
|
|
12
|
+
"@nocobase/plugin-workflow": "2.0.0-beta.8",
|
|
13
|
+
"@nocobase/client": "2.0.0-beta.8",
|
|
14
|
+
"@nocobase/utils": "2.0.0-beta.8",
|
|
15
|
+
"@nocobase/database": "2.0.0-beta.8",
|
|
16
|
+
"@nocobase/server": "2.0.0-beta.8",
|
|
17
17
|
"axios": "1.7.7",
|
|
18
|
-
"@nocobase/actions": "2.0.0-beta.
|
|
18
|
+
"@nocobase/actions": "2.0.0-beta.8",
|
|
19
19
|
"react": "18.2.0",
|
|
20
20
|
"antd": "5.24.2",
|
|
21
21
|
"@formily/core": "2.3.7",
|
|
22
22
|
"@formily/react": "2.3.7",
|
|
23
|
-
"@nocobase/flow-engine": "2.0.0-beta.
|
|
23
|
+
"@nocobase/flow-engine": "2.0.0-beta.8",
|
|
24
24
|
"@ant-design/icons": "5.6.1",
|
|
25
25
|
"@formily/antd-v5": "1.2.3",
|
|
26
26
|
"@formily/shared": "2.3.7",
|
|
27
27
|
"lodash": "4.17.21",
|
|
28
|
-
"@nocobase/plugin-file-manager": "2.0.0-beta.
|
|
29
|
-
"@nocobase/resourcer": "2.0.0-beta.
|
|
28
|
+
"@nocobase/plugin-file-manager": "2.0.0-beta.8",
|
|
29
|
+
"@nocobase/resourcer": "2.0.0-beta.8",
|
|
30
30
|
"@emotion/css": "11.13.0",
|
|
31
31
|
"react-router-dom": "6.30.1",
|
|
32
32
|
"react-i18next": "11.18.6",
|
|
33
|
-
"@nocobase/plugin-data-source-manager": "2.0.0-beta.
|
|
33
|
+
"@nocobase/plugin-data-source-manager": "2.0.0-beta.8",
|
|
34
34
|
"ahooks": "3.7.8",
|
|
35
35
|
"@formily/reactive": "2.3.7"
|
|
36
36
|
};
|
|
@@ -29,7 +29,7 @@ function _documentsInParams(params) {
|
|
|
29
29
|
block != null &&
|
|
30
30
|
block.type === "document" &&
|
|
31
31
|
typeof block.citations === "object" &&
|
|
32
|
-
block.citations
|
|
32
|
+
block.citations?.enabled) {
|
|
33
33
|
return true;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -44,14 +44,22 @@ function isAnthropicTool(tool) {
|
|
|
44
44
|
return "input_schema" in tool;
|
|
45
45
|
}
|
|
46
46
|
function isBuiltinTool(tool) {
|
|
47
|
-
const
|
|
47
|
+
const builtInToolPrefixes = [
|
|
48
|
+
"text_editor_",
|
|
49
|
+
"computer_",
|
|
50
|
+
"bash_",
|
|
51
|
+
"web_search_",
|
|
52
|
+
"web_fetch_",
|
|
53
|
+
"str_replace_editor_",
|
|
54
|
+
"str_replace_based_edit_tool_",
|
|
55
|
+
"code_execution_",
|
|
56
|
+
"memory_",
|
|
57
|
+
];
|
|
48
58
|
return (typeof tool === "object" &&
|
|
49
59
|
tool !== null &&
|
|
50
60
|
"type" in tool &&
|
|
51
61
|
"name" in tool &&
|
|
52
|
-
typeof tool.type === "string" &&
|
|
53
|
-
typeof tool.name === "string" &&
|
|
54
|
-
builtinTools.includes(tool.name));
|
|
62
|
+
builtInToolPrefixes.some((prefix) => typeof tool.type === "string" && tool.type.startsWith(prefix)));
|
|
55
63
|
}
|
|
56
64
|
function extractToken(chunk) {
|
|
57
65
|
if (typeof chunk.content === "string") {
|
|
@@ -554,6 +562,12 @@ class ChatAnthropicMessages extends chat_models_1.BaseChatModel {
|
|
|
554
562
|
writable: true,
|
|
555
563
|
value: { type: "disabled" }
|
|
556
564
|
});
|
|
565
|
+
Object.defineProperty(this, "contextManagement", {
|
|
566
|
+
enumerable: true,
|
|
567
|
+
configurable: true,
|
|
568
|
+
writable: true,
|
|
569
|
+
value: void 0
|
|
570
|
+
});
|
|
557
571
|
// Used for non-streaming requests
|
|
558
572
|
Object.defineProperty(this, "batchClient", {
|
|
559
573
|
enumerable: true,
|
|
@@ -601,15 +615,31 @@ class ChatAnthropicMessages extends chat_models_1.BaseChatModel {
|
|
|
601
615
|
this.modelName = fields?.model ?? fields?.modelName ?? this.model;
|
|
602
616
|
this.model = this.modelName;
|
|
603
617
|
this.invocationKwargs = fields?.invocationKwargs ?? {};
|
|
604
|
-
this.
|
|
618
|
+
if (this.model.includes("opus-4-1") ||
|
|
619
|
+
this.model.includes("sonnet-4-5") ||
|
|
620
|
+
this.model.includes("haiku-4-5")) {
|
|
621
|
+
this.temperature =
|
|
622
|
+
fields?.temperature === null ? undefined : fields?.temperature;
|
|
623
|
+
this.topP = fields?.topP === null ? undefined : fields?.topP;
|
|
624
|
+
}
|
|
625
|
+
else {
|
|
626
|
+
this.topP = fields?.topP ?? this.topP;
|
|
627
|
+
}
|
|
628
|
+
// If the user passes `null`, set it to `undefined`. Otherwise, use their value or the default. We have to check for null, because
|
|
629
|
+
// there's no way for us to know if they explicitly set it to `undefined`, or never passed a value
|
|
630
|
+
this.temperature =
|
|
631
|
+
fields?.temperature === null
|
|
632
|
+
? undefined
|
|
633
|
+
: fields?.temperature ?? this.temperature;
|
|
605
634
|
this.topK = fields?.topK ?? this.topK;
|
|
606
|
-
this.topP = fields?.topP ?? this.topP;
|
|
607
635
|
this.maxTokens =
|
|
608
636
|
fields?.maxTokensToSample ?? fields?.maxTokens ?? this.maxTokens;
|
|
609
637
|
this.stopSequences = fields?.stopSequences ?? this.stopSequences;
|
|
610
638
|
this.streaming = fields?.streaming ?? false;
|
|
611
639
|
this.streamUsage = fields?.streamUsage ?? this.streamUsage;
|
|
612
640
|
this.thinking = fields?.thinking ?? this.thinking;
|
|
641
|
+
this.contextManagement =
|
|
642
|
+
fields?.contextManagement ?? this.contextManagement;
|
|
613
643
|
this.createClient =
|
|
614
644
|
fields?.createClient ??
|
|
615
645
|
((options) => new sdk_1.Anthropic(options));
|
|
@@ -677,7 +707,11 @@ class ChatAnthropicMessages extends chat_models_1.BaseChatModel {
|
|
|
677
707
|
if (this.topK !== -1) {
|
|
678
708
|
throw new Error("topK is not supported when thinking is enabled");
|
|
679
709
|
}
|
|
680
|
-
if (this.
|
|
710
|
+
if (this.model.includes("opus-4-1") ||
|
|
711
|
+
this.model.includes("sonnet-4-5") ||
|
|
712
|
+
this.model.includes("haiku-4-5")
|
|
713
|
+
? this.topP !== undefined
|
|
714
|
+
: this.topP !== -1) {
|
|
681
715
|
throw new Error("topP is not supported when thinking is enabled");
|
|
682
716
|
}
|
|
683
717
|
if (this.temperature !== 1) {
|
|
@@ -705,6 +739,7 @@ class ChatAnthropicMessages extends chat_models_1.BaseChatModel {
|
|
|
705
739
|
tools: this.formatStructuredToolToAnthropic(options?.tools),
|
|
706
740
|
tool_choice,
|
|
707
741
|
thinking: this.thinking,
|
|
742
|
+
context_management: this.contextManagement,
|
|
708
743
|
...this.invocationKwargs,
|
|
709
744
|
};
|
|
710
745
|
}
|
|
@@ -7,7 +7,7 @@ import { BaseChatModel, BaseChatModelCallOptions, LangSmithParams, type BaseChat
|
|
|
7
7
|
import { type StructuredOutputMethodOptions, type BaseLanguageModelInput } from "@langchain/core/language_models/base";
|
|
8
8
|
import { Runnable } from "@langchain/core/runnables";
|
|
9
9
|
import { InteropZodType } from "@langchain/core/utils/types";
|
|
10
|
-
import { AnthropicMessageCreateParams, AnthropicMessageStreamEvent, AnthropicRequestOptions, AnthropicStreamingMessageCreateParams, AnthropicThinkingConfigParam, AnthropicToolChoice, ChatAnthropicToolType } from "./types.js";
|
|
10
|
+
import { AnthropicContextManagementConfigParam, AnthropicMessageCreateParams, AnthropicMessageStreamEvent, AnthropicRequestOptions, AnthropicStreamingMessageCreateParams, AnthropicThinkingConfigParam, AnthropicToolChoice, ChatAnthropicToolType } from "./types.js";
|
|
11
11
|
export interface ChatAnthropicCallOptions extends BaseChatModelCallOptions, Pick<AnthropicInput, "streamUsage"> {
|
|
12
12
|
tools?: ChatAnthropicToolType[];
|
|
13
13
|
/**
|
|
@@ -33,8 +33,10 @@ export interface AnthropicInput {
|
|
|
33
33
|
* from 0 to 1. Use temp closer to 0 for analytical /
|
|
34
34
|
* multiple choice, and temp closer to 1 for creative
|
|
35
35
|
* and generative tasks.
|
|
36
|
+
* To not set this field, pass `null`. If `undefined` is passed,
|
|
37
|
+
* the default (1) will be used.
|
|
36
38
|
*/
|
|
37
|
-
temperature?: number;
|
|
39
|
+
temperature?: number | null;
|
|
38
40
|
/** Only sample from the top K options for each subsequent
|
|
39
41
|
* token. Used to remove "long tail" low probability
|
|
40
42
|
* responses. Defaults to -1, which disables it.
|
|
@@ -47,8 +49,11 @@ export interface AnthropicInput {
|
|
|
47
49
|
* specified by top_p. Defaults to -1, which disables it.
|
|
48
50
|
* Note that you should either alter temperature or top_p,
|
|
49
51
|
* but not both.
|
|
52
|
+
*
|
|
53
|
+
* To not set this field, pass `null`. If `undefined` is passed,
|
|
54
|
+
* the default (-1) will be used.
|
|
50
55
|
*/
|
|
51
|
-
topP?: number;
|
|
56
|
+
topP?: number | null;
|
|
52
57
|
/** A maximum number of tokens to generate before stopping. */
|
|
53
58
|
maxTokens?: number;
|
|
54
59
|
/**
|
|
@@ -95,6 +100,10 @@ export interface AnthropicInput {
|
|
|
95
100
|
* Options for extended thinking.
|
|
96
101
|
*/
|
|
97
102
|
thinking?: AnthropicThinkingConfigParam;
|
|
103
|
+
/**
|
|
104
|
+
* Configuration for context management. See https://docs.claude.com/en/docs/build-with-claude/context-editing
|
|
105
|
+
*/
|
|
106
|
+
contextManagement?: AnthropicContextManagementConfigParam;
|
|
98
107
|
}
|
|
99
108
|
/**
|
|
100
109
|
* A type representing additional parameters that can be passed to the
|
|
@@ -487,9 +496,9 @@ export declare class ChatAnthropicMessages<CallOptions extends ChatAnthropicCall
|
|
|
487
496
|
anthropicApiKey?: string;
|
|
488
497
|
apiKey?: string;
|
|
489
498
|
apiUrl?: string;
|
|
490
|
-
temperature: number;
|
|
499
|
+
temperature: number | undefined;
|
|
491
500
|
topK: number;
|
|
492
|
-
topP: number;
|
|
501
|
+
topP: number | undefined;
|
|
493
502
|
maxTokens: number;
|
|
494
503
|
modelName: string;
|
|
495
504
|
model: string;
|
|
@@ -498,6 +507,7 @@ export declare class ChatAnthropicMessages<CallOptions extends ChatAnthropicCall
|
|
|
498
507
|
streaming: boolean;
|
|
499
508
|
clientOptions: ClientOptions;
|
|
500
509
|
thinking: AnthropicThinkingConfigParam;
|
|
510
|
+
contextManagement?: AnthropicContextManagementConfigParam;
|
|
501
511
|
protected batchClient: Anthropic;
|
|
502
512
|
protected streamingClient: Anthropic;
|
|
503
513
|
streamUsage: boolean;
|
|
@@ -26,7 +26,7 @@ function _documentsInParams(params) {
|
|
|
26
26
|
block != null &&
|
|
27
27
|
block.type === "document" &&
|
|
28
28
|
typeof block.citations === "object" &&
|
|
29
|
-
block.citations
|
|
29
|
+
block.citations?.enabled) {
|
|
30
30
|
return true;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -41,14 +41,22 @@ function isAnthropicTool(tool) {
|
|
|
41
41
|
return "input_schema" in tool;
|
|
42
42
|
}
|
|
43
43
|
function isBuiltinTool(tool) {
|
|
44
|
-
const
|
|
44
|
+
const builtInToolPrefixes = [
|
|
45
|
+
"text_editor_",
|
|
46
|
+
"computer_",
|
|
47
|
+
"bash_",
|
|
48
|
+
"web_search_",
|
|
49
|
+
"web_fetch_",
|
|
50
|
+
"str_replace_editor_",
|
|
51
|
+
"str_replace_based_edit_tool_",
|
|
52
|
+
"code_execution_",
|
|
53
|
+
"memory_",
|
|
54
|
+
];
|
|
45
55
|
return (typeof tool === "object" &&
|
|
46
56
|
tool !== null &&
|
|
47
57
|
"type" in tool &&
|
|
48
58
|
"name" in tool &&
|
|
49
|
-
typeof tool.type === "string" &&
|
|
50
|
-
typeof tool.name === "string" &&
|
|
51
|
-
builtinTools.includes(tool.name));
|
|
59
|
+
builtInToolPrefixes.some((prefix) => typeof tool.type === "string" && tool.type.startsWith(prefix)));
|
|
52
60
|
}
|
|
53
61
|
function extractToken(chunk) {
|
|
54
62
|
if (typeof chunk.content === "string") {
|
|
@@ -551,6 +559,12 @@ export class ChatAnthropicMessages extends BaseChatModel {
|
|
|
551
559
|
writable: true,
|
|
552
560
|
value: { type: "disabled" }
|
|
553
561
|
});
|
|
562
|
+
Object.defineProperty(this, "contextManagement", {
|
|
563
|
+
enumerable: true,
|
|
564
|
+
configurable: true,
|
|
565
|
+
writable: true,
|
|
566
|
+
value: void 0
|
|
567
|
+
});
|
|
554
568
|
// Used for non-streaming requests
|
|
555
569
|
Object.defineProperty(this, "batchClient", {
|
|
556
570
|
enumerable: true,
|
|
@@ -598,15 +612,31 @@ export class ChatAnthropicMessages extends BaseChatModel {
|
|
|
598
612
|
this.modelName = fields?.model ?? fields?.modelName ?? this.model;
|
|
599
613
|
this.model = this.modelName;
|
|
600
614
|
this.invocationKwargs = fields?.invocationKwargs ?? {};
|
|
601
|
-
this.
|
|
615
|
+
if (this.model.includes("opus-4-1") ||
|
|
616
|
+
this.model.includes("sonnet-4-5") ||
|
|
617
|
+
this.model.includes("haiku-4-5")) {
|
|
618
|
+
this.temperature =
|
|
619
|
+
fields?.temperature === null ? undefined : fields?.temperature;
|
|
620
|
+
this.topP = fields?.topP === null ? undefined : fields?.topP;
|
|
621
|
+
}
|
|
622
|
+
else {
|
|
623
|
+
this.topP = fields?.topP ?? this.topP;
|
|
624
|
+
}
|
|
625
|
+
// If the user passes `null`, set it to `undefined`. Otherwise, use their value or the default. We have to check for null, because
|
|
626
|
+
// there's no way for us to know if they explicitly set it to `undefined`, or never passed a value
|
|
627
|
+
this.temperature =
|
|
628
|
+
fields?.temperature === null
|
|
629
|
+
? undefined
|
|
630
|
+
: fields?.temperature ?? this.temperature;
|
|
602
631
|
this.topK = fields?.topK ?? this.topK;
|
|
603
|
-
this.topP = fields?.topP ?? this.topP;
|
|
604
632
|
this.maxTokens =
|
|
605
633
|
fields?.maxTokensToSample ?? fields?.maxTokens ?? this.maxTokens;
|
|
606
634
|
this.stopSequences = fields?.stopSequences ?? this.stopSequences;
|
|
607
635
|
this.streaming = fields?.streaming ?? false;
|
|
608
636
|
this.streamUsage = fields?.streamUsage ?? this.streamUsage;
|
|
609
637
|
this.thinking = fields?.thinking ?? this.thinking;
|
|
638
|
+
this.contextManagement =
|
|
639
|
+
fields?.contextManagement ?? this.contextManagement;
|
|
610
640
|
this.createClient =
|
|
611
641
|
fields?.createClient ??
|
|
612
642
|
((options) => new Anthropic(options));
|
|
@@ -674,7 +704,11 @@ export class ChatAnthropicMessages extends BaseChatModel {
|
|
|
674
704
|
if (this.topK !== -1) {
|
|
675
705
|
throw new Error("topK is not supported when thinking is enabled");
|
|
676
706
|
}
|
|
677
|
-
if (this.
|
|
707
|
+
if (this.model.includes("opus-4-1") ||
|
|
708
|
+
this.model.includes("sonnet-4-5") ||
|
|
709
|
+
this.model.includes("haiku-4-5")
|
|
710
|
+
? this.topP !== undefined
|
|
711
|
+
: this.topP !== -1) {
|
|
678
712
|
throw new Error("topP is not supported when thinking is enabled");
|
|
679
713
|
}
|
|
680
714
|
if (this.temperature !== 1) {
|
|
@@ -702,6 +736,7 @@ export class ChatAnthropicMessages extends BaseChatModel {
|
|
|
702
736
|
tools: this.formatStructuredToolToAnthropic(options?.tools),
|
|
703
737
|
tool_choice,
|
|
704
738
|
thinking: this.thinking,
|
|
739
|
+
context_management: this.contextManagement,
|
|
705
740
|
...this.invocationKwargs,
|
|
706
741
|
};
|
|
707
742
|
}
|
|
@@ -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
|
}
|
|
@@ -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
|
}
|
|
@@ -11,6 +11,7 @@ export type AnthropicMessageResponse = Anthropic.ContentBlock | AnthropicToolRes
|
|
|
11
11
|
export type AnthropicMessageCreateParams = Anthropic.MessageCreateParamsNonStreaming;
|
|
12
12
|
export type AnthropicStreamingMessageCreateParams = Anthropic.MessageCreateParamsStreaming;
|
|
13
13
|
export type AnthropicThinkingConfigParam = Anthropic.ThinkingConfigParam;
|
|
14
|
+
export type AnthropicContextManagementConfigParam = Anthropic.Beta.BetaContextManagementConfig;
|
|
14
15
|
export type AnthropicMessageStreamEvent = Anthropic.MessageStreamEvent;
|
|
15
16
|
export type AnthropicRequestOptions = Anthropic.RequestOptions;
|
|
16
17
|
export type AnthropicToolChoice = {
|
|
@@ -28,6 +29,7 @@ export type AnthropicRedactedThinkingBlockParam = Anthropic.Messages.RedactedThi
|
|
|
28
29
|
export type AnthropicServerToolUseBlockParam = Anthropic.Messages.ServerToolUseBlockParam;
|
|
29
30
|
export type AnthropicWebSearchToolResultBlockParam = Anthropic.Messages.WebSearchToolResultBlockParam;
|
|
30
31
|
export type AnthropicWebSearchResultBlockParam = Anthropic.Messages.WebSearchResultBlockParam;
|
|
31
|
-
export type
|
|
32
|
+
export type AnthropicSearchResultBlockParam = Anthropic.SearchResultBlockParam;
|
|
33
|
+
export type ChatAnthropicContentBlock = AnthropicTextBlockParam | AnthropicImageBlockParam | AnthropicToolUseBlockParam | AnthropicToolResultBlockParam | AnthropicDocumentBlockParam | AnthropicThinkingBlockParam | AnthropicRedactedThinkingBlockParam | AnthropicServerToolUseBlockParam | AnthropicWebSearchToolResultBlockParam | AnthropicWebSearchResultBlockParam | AnthropicSearchResultBlockParam;
|
|
32
34
|
export declare function isAnthropicImageBlockParam(block: unknown): block is AnthropicImageBlockParam;
|
|
33
35
|
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
|
},
|
|
@@ -141,7 +141,6 @@ const standardContentBlockConverter = {
|
|
|
141
141
|
source: {
|
|
142
142
|
type: "url",
|
|
143
143
|
url: block.url,
|
|
144
|
-
media_type: block.mime_type ?? "",
|
|
145
144
|
},
|
|
146
145
|
...("cache_control" in (block.metadata ?? {})
|
|
147
146
|
? { cache_control: block.metadata.cache_control }
|
|
@@ -284,7 +283,7 @@ const standardContentBlockConverter = {
|
|
|
284
283
|
}
|
|
285
284
|
},
|
|
286
285
|
};
|
|
287
|
-
function _formatContent(
|
|
286
|
+
function _formatContent(message) {
|
|
288
287
|
const toolTypes = [
|
|
289
288
|
"tool_use",
|
|
290
289
|
"tool_result",
|
|
@@ -294,6 +293,7 @@ function _formatContent(content) {
|
|
|
294
293
|
"web_search_result",
|
|
295
294
|
];
|
|
296
295
|
const textTypes = ["text", "text_delta"];
|
|
296
|
+
const { content } = message;
|
|
297
297
|
if (typeof content === "string") {
|
|
298
298
|
return content;
|
|
299
299
|
}
|
|
@@ -344,6 +344,21 @@ function _formatContent(content) {
|
|
|
344
344
|
};
|
|
345
345
|
return block;
|
|
346
346
|
}
|
|
347
|
+
else if (contentPart.type === "search_result") {
|
|
348
|
+
const block = {
|
|
349
|
+
type: "search_result", // Explicitly setting the type as "search_result"
|
|
350
|
+
title: contentPart.title,
|
|
351
|
+
source: contentPart.source,
|
|
352
|
+
...("cache_control" in contentPart && contentPart.cache_control
|
|
353
|
+
? { cache_control: contentPart.cache_control }
|
|
354
|
+
: {}),
|
|
355
|
+
...("citations" in contentPart && contentPart.citations
|
|
356
|
+
? { citations: contentPart.citations }
|
|
357
|
+
: {}),
|
|
358
|
+
content: contentPart.content,
|
|
359
|
+
};
|
|
360
|
+
return block;
|
|
361
|
+
}
|
|
347
362
|
else if (textTypes.find((t) => t === contentPart.type) &&
|
|
348
363
|
"text" in contentPart) {
|
|
349
364
|
// Assuming contentPart is of type MessageContentText here
|
|
@@ -385,6 +400,22 @@ function _formatContent(content) {
|
|
|
385
400
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
386
401
|
};
|
|
387
402
|
}
|
|
403
|
+
else if ("functionCall" in contentPart &&
|
|
404
|
+
contentPart.functionCall &&
|
|
405
|
+
typeof contentPart.functionCall === "object" &&
|
|
406
|
+
(0, messages_1.isAIMessage)(message)) {
|
|
407
|
+
const correspondingToolCall = message.tool_calls?.find((toolCall) => toolCall.name === contentPart.functionCall.name);
|
|
408
|
+
if (!correspondingToolCall) {
|
|
409
|
+
throw new Error(`Could not find tool call for function call ${contentPart.functionCall.name}`);
|
|
410
|
+
}
|
|
411
|
+
// Google GenAI models include a `functionCall` object inside content. We should ignore it as Anthropic will not support it.
|
|
412
|
+
return {
|
|
413
|
+
id: correspondingToolCall.id,
|
|
414
|
+
type: "tool_use",
|
|
415
|
+
name: correspondingToolCall.name,
|
|
416
|
+
input: contentPart.functionCall.args,
|
|
417
|
+
};
|
|
418
|
+
}
|
|
388
419
|
else {
|
|
389
420
|
throw new Error("Unsupported message content format");
|
|
390
421
|
}
|
|
@@ -451,14 +482,14 @@ function _convertMessagesToAnthropicPayload(messages) {
|
|
|
451
482
|
}
|
|
452
483
|
return {
|
|
453
484
|
role,
|
|
454
|
-
content: _formatContent(message
|
|
485
|
+
content: _formatContent(message),
|
|
455
486
|
};
|
|
456
487
|
}
|
|
457
488
|
}
|
|
458
489
|
else {
|
|
459
490
|
return {
|
|
460
491
|
role,
|
|
461
|
-
content: _formatContent(message
|
|
492
|
+
content: _formatContent(message),
|
|
462
493
|
};
|
|
463
494
|
}
|
|
464
495
|
});
|
|
@@ -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
|
},
|
|
@@ -137,7 +137,6 @@ const standardContentBlockConverter = {
|
|
|
137
137
|
source: {
|
|
138
138
|
type: "url",
|
|
139
139
|
url: block.url,
|
|
140
|
-
media_type: block.mime_type ?? "",
|
|
141
140
|
},
|
|
142
141
|
...("cache_control" in (block.metadata ?? {})
|
|
143
142
|
? { cache_control: block.metadata.cache_control }
|
|
@@ -280,7 +279,7 @@ const standardContentBlockConverter = {
|
|
|
280
279
|
}
|
|
281
280
|
},
|
|
282
281
|
};
|
|
283
|
-
function _formatContent(
|
|
282
|
+
function _formatContent(message) {
|
|
284
283
|
const toolTypes = [
|
|
285
284
|
"tool_use",
|
|
286
285
|
"tool_result",
|
|
@@ -290,6 +289,7 @@ function _formatContent(content) {
|
|
|
290
289
|
"web_search_result",
|
|
291
290
|
];
|
|
292
291
|
const textTypes = ["text", "text_delta"];
|
|
292
|
+
const { content } = message;
|
|
293
293
|
if (typeof content === "string") {
|
|
294
294
|
return content;
|
|
295
295
|
}
|
|
@@ -340,6 +340,21 @@ function _formatContent(content) {
|
|
|
340
340
|
};
|
|
341
341
|
return block;
|
|
342
342
|
}
|
|
343
|
+
else if (contentPart.type === "search_result") {
|
|
344
|
+
const block = {
|
|
345
|
+
type: "search_result", // Explicitly setting the type as "search_result"
|
|
346
|
+
title: contentPart.title,
|
|
347
|
+
source: contentPart.source,
|
|
348
|
+
...("cache_control" in contentPart && contentPart.cache_control
|
|
349
|
+
? { cache_control: contentPart.cache_control }
|
|
350
|
+
: {}),
|
|
351
|
+
...("citations" in contentPart && contentPart.citations
|
|
352
|
+
? { citations: contentPart.citations }
|
|
353
|
+
: {}),
|
|
354
|
+
content: contentPart.content,
|
|
355
|
+
};
|
|
356
|
+
return block;
|
|
357
|
+
}
|
|
343
358
|
else if (textTypes.find((t) => t === contentPart.type) &&
|
|
344
359
|
"text" in contentPart) {
|
|
345
360
|
// Assuming contentPart is of type MessageContentText here
|
|
@@ -381,6 +396,22 @@ function _formatContent(content) {
|
|
|
381
396
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
382
397
|
};
|
|
383
398
|
}
|
|
399
|
+
else if ("functionCall" in contentPart &&
|
|
400
|
+
contentPart.functionCall &&
|
|
401
|
+
typeof contentPart.functionCall === "object" &&
|
|
402
|
+
isAIMessage(message)) {
|
|
403
|
+
const correspondingToolCall = message.tool_calls?.find((toolCall) => toolCall.name === contentPart.functionCall.name);
|
|
404
|
+
if (!correspondingToolCall) {
|
|
405
|
+
throw new Error(`Could not find tool call for function call ${contentPart.functionCall.name}`);
|
|
406
|
+
}
|
|
407
|
+
// Google GenAI models include a `functionCall` object inside content. We should ignore it as Anthropic will not support it.
|
|
408
|
+
return {
|
|
409
|
+
id: correspondingToolCall.id,
|
|
410
|
+
type: "tool_use",
|
|
411
|
+
name: correspondingToolCall.name,
|
|
412
|
+
input: contentPart.functionCall.args,
|
|
413
|
+
};
|
|
414
|
+
}
|
|
384
415
|
else {
|
|
385
416
|
throw new Error("Unsupported message content format");
|
|
386
417
|
}
|
|
@@ -447,14 +478,14 @@ export function _convertMessagesToAnthropicPayload(messages) {
|
|
|
447
478
|
}
|
|
448
479
|
return {
|
|
449
480
|
role,
|
|
450
|
-
content: _formatContent(message
|
|
481
|
+
content: _formatContent(message),
|
|
451
482
|
};
|
|
452
483
|
}
|
|
453
484
|
}
|
|
454
485
|
else {
|
|
455
486
|
return {
|
|
456
487
|
role,
|
|
457
|
-
content: _formatContent(message
|
|
488
|
+
content: _formatContent(message),
|
|
458
489
|
};
|
|
459
490
|
}
|
|
460
491
|
});
|
|
@@ -52,11 +52,15 @@ function _makeMessageChunkFromAnthropicEvent(data, fields) {
|
|
|
52
52
|
cache_read: data.usage.cache_read_input_tokens,
|
|
53
53
|
},
|
|
54
54
|
};
|
|
55
|
+
const responseMetadata = "context_management" in data.delta
|
|
56
|
+
? { context_management: data.delta.context_management }
|
|
57
|
+
: undefined;
|
|
55
58
|
return {
|
|
56
59
|
chunk: new messages_1.AIMessageChunk({
|
|
57
60
|
content: fields.coerceContentToString ? "" : [],
|
|
58
61
|
additional_kwargs: { ...data.delta },
|
|
59
62
|
usage_metadata: fields.streamUsage ? usageMetadata : undefined,
|
|
63
|
+
response_metadata: responseMetadata,
|
|
60
64
|
}),
|
|
61
65
|
};
|
|
62
66
|
}
|
|
@@ -79,17 +83,6 @@ function _makeMessageChunkFromAnthropicEvent(data, fields) {
|
|
|
79
83
|
},
|
|
80
84
|
];
|
|
81
85
|
}
|
|
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
86
|
else {
|
|
94
87
|
toolCallChunks = [];
|
|
95
88
|
}
|
|
@@ -48,11 +48,15 @@ export function _makeMessageChunkFromAnthropicEvent(data, fields) {
|
|
|
48
48
|
cache_read: data.usage.cache_read_input_tokens,
|
|
49
49
|
},
|
|
50
50
|
};
|
|
51
|
+
const responseMetadata = "context_management" in data.delta
|
|
52
|
+
? { context_management: data.delta.context_management }
|
|
53
|
+
: undefined;
|
|
51
54
|
return {
|
|
52
55
|
chunk: new AIMessageChunk({
|
|
53
56
|
content: fields.coerceContentToString ? "" : [],
|
|
54
57
|
additional_kwargs: { ...data.delta },
|
|
55
58
|
usage_metadata: fields.streamUsage ? usageMetadata : undefined,
|
|
59
|
+
response_metadata: responseMetadata,
|
|
56
60
|
}),
|
|
57
61
|
};
|
|
58
62
|
}
|
|
@@ -75,17 +79,6 @@ export function _makeMessageChunkFromAnthropicEvent(data, fields) {
|
|
|
75
79
|
},
|
|
76
80
|
];
|
|
77
81
|
}
|
|
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
82
|
else {
|
|
90
83
|
toolCallChunks = [];
|
|
91
84
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Anthropic } from "@anthropic-ai/sdk";
|
|
2
2
|
import { AnthropicToolChoice } from "../types.js";
|
|
3
|
-
export declare function handleToolChoice(toolChoice?: AnthropicToolChoice): Anthropic.Messages.ToolChoiceAuto | Anthropic.Messages.ToolChoiceAny | Anthropic.Messages.ToolChoiceTool | undefined;
|
|
3
|
+
export declare function handleToolChoice(toolChoice?: AnthropicToolChoice): Anthropic.Messages.ToolChoiceAuto | Anthropic.Messages.ToolChoiceAny | Anthropic.Messages.ToolChoiceTool | Anthropic.Messages.ToolChoiceNone | undefined;
|