@langchain/core 1.0.0-alpha.1 → 1.0.0-alpha.3
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/agents.d.ts.map +1 -1
- package/dist/caches/base.cjs +5 -18
- package/dist/caches/base.cjs.map +1 -1
- package/dist/caches/base.d.cts +4 -20
- package/dist/caches/base.d.cts.map +1 -1
- package/dist/caches/base.d.ts +4 -20
- package/dist/caches/base.d.ts.map +1 -1
- package/dist/caches/base.js +5 -18
- package/dist/caches/base.js.map +1 -1
- package/dist/callbacks/base.d.cts +3 -2
- package/dist/callbacks/base.d.cts.map +1 -1
- package/dist/callbacks/base.d.ts +3 -2
- package/dist/callbacks/base.d.ts.map +1 -1
- package/dist/callbacks/manager.d.cts +1 -1
- package/dist/callbacks/manager.d.ts +1 -1
- package/dist/index.cjs +0 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/language_models/base.d.cts +1 -1
- package/dist/language_models/base.d.ts +1 -1
- package/dist/language_models/chat_models.cjs +1 -0
- package/dist/language_models/chat_models.cjs.map +1 -1
- package/dist/language_models/chat_models.d.cts +2 -1
- package/dist/language_models/chat_models.d.cts.map +1 -1
- package/dist/language_models/chat_models.d.ts +2 -1
- package/dist/language_models/chat_models.d.ts.map +1 -1
- package/dist/language_models/chat_models.js +2 -1
- package/dist/language_models/chat_models.js.map +1 -1
- package/dist/messages/ai.cjs +32 -60
- package/dist/messages/ai.cjs.map +1 -1
- package/dist/messages/ai.d.cts +26 -119
- package/dist/messages/ai.d.cts.map +1 -1
- package/dist/messages/ai.d.ts +26 -119
- package/dist/messages/ai.d.ts.map +1 -1
- package/dist/messages/ai.js +32 -60
- package/dist/messages/ai.js.map +1 -1
- package/dist/messages/base.cjs +48 -28
- package/dist/messages/base.cjs.map +1 -1
- package/dist/messages/base.d.cts +37 -39
- package/dist/messages/base.d.cts.map +1 -1
- package/dist/messages/base.d.ts +37 -39
- package/dist/messages/base.d.ts.map +1 -1
- package/dist/messages/base.js +48 -28
- package/dist/messages/base.js.map +1 -1
- package/dist/messages/chat.cjs +18 -12
- package/dist/messages/chat.cjs.map +1 -1
- package/dist/messages/chat.d.cts +21 -13
- package/dist/messages/chat.d.cts.map +1 -1
- package/dist/messages/chat.d.ts +21 -13
- package/dist/messages/chat.d.ts.map +1 -1
- package/dist/messages/chat.js +18 -12
- package/dist/messages/chat.js.map +1 -1
- package/dist/messages/content/index.cjs.map +1 -1
- package/dist/messages/content/index.d.cts +1 -1
- package/dist/messages/content/index.d.cts.map +1 -1
- package/dist/messages/content/index.d.ts +1 -1
- package/dist/messages/content/index.d.ts.map +1 -1
- package/dist/messages/content/index.js.map +1 -1
- package/dist/messages/function.cjs +8 -13
- package/dist/messages/function.cjs.map +1 -1
- package/dist/messages/function.d.cts +11 -11
- package/dist/messages/function.d.cts.map +1 -1
- package/dist/messages/function.d.ts +11 -11
- package/dist/messages/function.d.ts.map +1 -1
- package/dist/messages/function.js +8 -13
- package/dist/messages/function.js.map +1 -1
- package/dist/messages/human.cjs +20 -11
- package/dist/messages/human.cjs.map +1 -1
- package/dist/messages/human.d.cts +20 -15
- package/dist/messages/human.d.cts.map +1 -1
- package/dist/messages/human.d.ts +20 -15
- package/dist/messages/human.d.ts.map +1 -1
- package/dist/messages/human.js +20 -11
- package/dist/messages/human.js.map +1 -1
- package/dist/messages/index.cjs +10 -0
- package/dist/messages/index.cjs.map +1 -1
- package/dist/messages/index.d.cts +9 -7
- package/dist/messages/index.d.ts +9 -7
- package/dist/messages/index.js +8 -2
- package/dist/messages/index.js.map +1 -1
- package/dist/messages/message.cjs +15 -0
- package/dist/messages/message.cjs.map +1 -0
- package/dist/messages/message.d.cts +598 -0
- package/dist/messages/message.d.cts.map +1 -0
- package/dist/messages/message.d.ts +598 -0
- package/dist/messages/message.d.ts.map +1 -0
- package/dist/messages/message.js +14 -0
- package/dist/messages/message.js.map +1 -0
- package/dist/messages/metadata.cjs +41 -0
- package/dist/messages/metadata.cjs.map +1 -0
- package/dist/messages/metadata.d.cts +98 -0
- package/dist/messages/metadata.d.cts.map +1 -0
- package/dist/messages/metadata.d.ts +98 -0
- package/dist/messages/metadata.d.ts.map +1 -0
- package/dist/messages/metadata.js +40 -0
- package/dist/messages/metadata.js.map +1 -0
- package/dist/messages/modifier.cjs +5 -7
- package/dist/messages/modifier.cjs.map +1 -1
- package/dist/messages/modifier.d.cts +7 -5
- package/dist/messages/modifier.d.cts.map +1 -1
- package/dist/messages/modifier.d.ts +7 -5
- package/dist/messages/modifier.d.ts.map +1 -1
- package/dist/messages/modifier.js +5 -7
- package/dist/messages/modifier.js.map +1 -1
- package/dist/messages/system.cjs +20 -11
- package/dist/messages/system.cjs.map +1 -1
- package/dist/messages/system.d.cts +20 -15
- package/dist/messages/system.d.cts.map +1 -1
- package/dist/messages/system.d.ts +20 -15
- package/dist/messages/system.d.ts.map +1 -1
- package/dist/messages/system.js +20 -11
- package/dist/messages/system.js.map +1 -1
- package/dist/messages/tool.cjs +16 -14
- package/dist/messages/tool.cjs.map +1 -1
- package/dist/messages/tool.d.cts +73 -47
- package/dist/messages/tool.d.cts.map +1 -1
- package/dist/messages/tool.d.ts +73 -47
- package/dist/messages/tool.d.ts.map +1 -1
- package/dist/messages/tool.js +16 -14
- package/dist/messages/tool.js.map +1 -1
- package/dist/messages/transformers.cjs.map +1 -1
- package/dist/messages/transformers.d.cts +2 -1
- package/dist/messages/transformers.d.cts.map +1 -1
- package/dist/messages/transformers.d.ts +2 -1
- package/dist/messages/transformers.d.ts.map +1 -1
- package/dist/messages/transformers.js.map +1 -1
- package/dist/messages/utils.cjs +8 -1
- package/dist/messages/utils.cjs.map +1 -1
- package/dist/messages/utils.d.cts +83 -3
- package/dist/messages/utils.d.cts.map +1 -1
- package/dist/messages/utils.d.ts +83 -3
- package/dist/messages/utils.d.ts.map +1 -1
- package/dist/messages/utils.js +8 -2
- package/dist/messages/utils.js.map +1 -1
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.cts +1 -1
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.ts +1 -1
- package/dist/prompt_values.d.cts +4 -3
- package/dist/prompt_values.d.cts.map +1 -1
- package/dist/prompt_values.d.ts +4 -3
- package/dist/prompt_values.d.ts.map +1 -1
- package/dist/prompts/chat.d.cts +3 -3
- package/dist/prompts/chat.d.cts.map +1 -1
- package/dist/prompts/chat.d.ts +3 -3
- package/dist/prompts/chat.d.ts.map +1 -1
- package/dist/prompts/few_shot.d.cts +1 -1
- package/dist/prompts/few_shot.d.ts +1 -1
- package/dist/prompts/image.d.cts +1 -1
- package/dist/prompts/image.d.ts +1 -1
- package/dist/prompts/prompt.d.cts +1 -1
- package/dist/prompts/prompt.d.ts +1 -1
- package/dist/prompts/template.d.cts +1 -1
- package/dist/prompts/template.d.ts +1 -1
- package/dist/runnables/base.cjs +1 -1
- package/dist/runnables/base.cjs.map +1 -1
- package/dist/runnables/base.d.cts +1 -1
- package/dist/runnables/base.d.ts +1 -1
- package/dist/runnables/base.js +2 -2
- package/dist/runnables/base.js.map +1 -1
- package/dist/tools/index.cjs +11 -1
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.d.cts +1 -1
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/index.js +11 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/types.cjs.map +1 -1
- package/dist/tools/types.d.cts +5 -2
- package/dist/tools/types.d.cts.map +1 -1
- package/dist/tools/types.d.ts +5 -2
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js.map +1 -1
- package/dist/tracers/base.d.cts +1 -1
- package/dist/tracers/base.d.ts +1 -1
- package/dist/tracers/tracer_langchain.d.ts.map +1 -1
- package/dist/tracers/tracer_langchain_v1.d.cts +1 -1
- package/dist/tracers/tracer_langchain_v1.d.ts +1 -1
- package/dist/utils/async_caller.cjs +2 -1
- package/dist/utils/async_caller.cjs.map +1 -1
- package/dist/utils/async_caller.js +2 -1
- package/dist/utils/async_caller.js.map +1 -1
- package/dist/utils/signal.cjs +23 -2
- package/dist/utils/signal.cjs.map +1 -1
- package/dist/utils/signal.js +23 -3
- package/dist/utils/signal.js.map +1 -1
- package/dist/utils/testing/index.d.cts +4 -3
- package/dist/utils/testing/index.d.cts.map +1 -1
- package/dist/utils/testing/index.d.ts +4 -3
- package/dist/utils/testing/index.d.ts.map +1 -1
- package/package.json +19 -18
package/dist/messages/tool.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { BaseMessage, BaseMessageChunk, BaseMessageFields
|
|
1
|
+
import { BaseMessage, BaseMessageChunk, BaseMessageFields } from "./base.cjs";
|
|
2
|
+
import { $InferMessageContent, MessageStructure } from "./message.cjs";
|
|
2
3
|
|
|
3
4
|
//#region src/messages/tool.d.ts
|
|
4
|
-
|
|
5
|
-
interface ToolMessageFieldsWithToolCallId extends ToolMessageFields {
|
|
5
|
+
interface ToolMessageFields<TStructure extends MessageStructure = MessageStructure> extends BaseMessageFields<TStructure, "tool"> {
|
|
6
6
|
/**
|
|
7
7
|
* Artifact of the Tool execution which is not meant to be sent to the model.
|
|
8
8
|
*
|
|
@@ -13,10 +13,6 @@ interface ToolMessageFieldsWithToolCallId extends ToolMessageFields {
|
|
|
13
13
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
14
|
artifact?: any;
|
|
15
15
|
tool_call_id: string;
|
|
16
|
-
/**
|
|
17
|
-
* Status of the tool invocation.
|
|
18
|
-
* @version 0.2.19
|
|
19
|
-
*/
|
|
20
16
|
status?: "success" | "error";
|
|
21
17
|
}
|
|
22
18
|
/**
|
|
@@ -33,11 +29,11 @@ declare function isDirectToolOutput(x: unknown): x is DirectToolOutput;
|
|
|
33
29
|
/**
|
|
34
30
|
* Represents a tool message in a conversation.
|
|
35
31
|
*/
|
|
36
|
-
declare class ToolMessage extends BaseMessage implements DirectToolOutput {
|
|
37
|
-
content: MessageContent;
|
|
32
|
+
declare class ToolMessage<TStructure extends MessageStructure = MessageStructure> extends BaseMessage<TStructure, "tool"> implements DirectToolOutput {
|
|
38
33
|
static lc_name(): string;
|
|
39
34
|
get lc_aliases(): Record<string, string>;
|
|
40
35
|
lc_direct_tool_output: true;
|
|
36
|
+
readonly type: "tool";
|
|
41
37
|
/**
|
|
42
38
|
* Status of the tool invocation.
|
|
43
39
|
* @version 0.2.19
|
|
@@ -53,18 +49,17 @@ declare class ToolMessage extends BaseMessage implements DirectToolOutput {
|
|
|
53
49
|
*/
|
|
54
50
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
51
|
artifact?: any;
|
|
56
|
-
constructor(fields:
|
|
57
|
-
constructor(fields:
|
|
58
|
-
|
|
59
|
-
static isInstance(message: BaseMessage): message is ToolMessage;
|
|
52
|
+
constructor(fields: $InferMessageContent<TStructure, "tool"> | ToolMessageFields, tool_call_id: string, name?: string);
|
|
53
|
+
constructor(fields: ToolMessageFields<TStructure>);
|
|
54
|
+
static isInstance(message: unknown): message is ToolMessage;
|
|
60
55
|
get _printableFields(): Record<string, unknown>;
|
|
61
56
|
}
|
|
62
57
|
/**
|
|
63
58
|
* Represents a chunk of a tool message, which can be concatenated
|
|
64
59
|
* with other tool message chunks.
|
|
65
60
|
*/
|
|
66
|
-
declare class ToolMessageChunk extends BaseMessageChunk {
|
|
67
|
-
|
|
61
|
+
declare class ToolMessageChunk<TStructure extends MessageStructure = MessageStructure> extends BaseMessageChunk<TStructure, "tool"> {
|
|
62
|
+
readonly type: "tool";
|
|
68
63
|
tool_call_id: string;
|
|
69
64
|
/**
|
|
70
65
|
* Status of the tool invocation.
|
|
@@ -80,25 +75,26 @@ declare class ToolMessageChunk extends BaseMessageChunk {
|
|
|
80
75
|
*/
|
|
81
76
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
82
77
|
artifact?: any;
|
|
83
|
-
constructor(fields:
|
|
78
|
+
constructor(fields: ToolMessageFields<TStructure>);
|
|
84
79
|
static lc_name(): string;
|
|
85
|
-
|
|
86
|
-
concat(chunk: ToolMessageChunk): ToolMessageChunk;
|
|
80
|
+
concat(chunk: ToolMessageChunk<TStructure>): this;
|
|
87
81
|
get _printableFields(): Record<string, unknown>;
|
|
88
82
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
*/
|
|
95
|
-
type ToolCall = {
|
|
96
|
-
name: string;
|
|
97
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
98
|
-
args: Record<string, any>;
|
|
83
|
+
interface ToolCall<TName extends string = string, TArgs extends Record<string, unknown> = Record<string, unknown>> {
|
|
84
|
+
readonly type?: "tool_call";
|
|
85
|
+
/**
|
|
86
|
+
* If provided, an identifier associated with the tool call
|
|
87
|
+
*/
|
|
99
88
|
id?: string;
|
|
100
|
-
|
|
101
|
-
|
|
89
|
+
/**
|
|
90
|
+
* The name of the tool being called
|
|
91
|
+
*/
|
|
92
|
+
name: TName;
|
|
93
|
+
/**
|
|
94
|
+
* The arguments to the tool call
|
|
95
|
+
*/
|
|
96
|
+
args: TArgs;
|
|
97
|
+
}
|
|
102
98
|
/**
|
|
103
99
|
* A chunk of a tool call (e.g., as part of a stream).
|
|
104
100
|
* When merging ToolCallChunks (e.g., via AIMessageChunk.__add__),
|
|
@@ -143,31 +139,61 @@ type ToolCall = {
|
|
|
143
139
|
* // }
|
|
144
140
|
* // ]
|
|
145
141
|
* ```
|
|
146
|
-
*
|
|
147
|
-
* @property {string} [name] - If provided, a substring of the name of the tool to be called
|
|
148
|
-
* @property {string} [args] - If provided, a JSON substring of the arguments to the tool call
|
|
149
|
-
* @property {string} [id] - If provided, a substring of an identifier for the tool call
|
|
150
|
-
* @property {number} [index] - If provided, the index of the tool call in a sequence
|
|
151
142
|
*/
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
143
|
+
interface ToolCallChunk<TName extends string = string> {
|
|
144
|
+
readonly type?: "tool_call_chunk";
|
|
145
|
+
/**
|
|
146
|
+
* If provided, a substring of an identifier for the tool call
|
|
147
|
+
*/
|
|
155
148
|
id?: string;
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
149
|
+
/**
|
|
150
|
+
* If provided, a substring of the name of the tool to be called
|
|
151
|
+
*/
|
|
152
|
+
name?: TName;
|
|
153
|
+
/**
|
|
154
|
+
* If provided, a JSON substring of the arguments to the tool call
|
|
155
|
+
*/
|
|
161
156
|
args?: string;
|
|
157
|
+
/**
|
|
158
|
+
* If provided, the index of the tool call in a sequence
|
|
159
|
+
*/
|
|
160
|
+
index?: number;
|
|
161
|
+
}
|
|
162
|
+
interface InvalidToolCall<TName extends string = string> {
|
|
163
|
+
readonly type?: "invalid_tool_call";
|
|
164
|
+
/**
|
|
165
|
+
* If provided, an identifier associated with the tool call
|
|
166
|
+
*/
|
|
162
167
|
id?: string;
|
|
168
|
+
/**
|
|
169
|
+
/**
|
|
170
|
+
* The name of the tool being called
|
|
171
|
+
*/
|
|
172
|
+
name?: TName;
|
|
173
|
+
/**
|
|
174
|
+
* The arguments to the tool call
|
|
175
|
+
*/
|
|
176
|
+
args?: string;
|
|
177
|
+
/**
|
|
178
|
+
* An error message associated with the tool call
|
|
179
|
+
*/
|
|
163
180
|
error?: string;
|
|
164
|
-
|
|
165
|
-
|
|
181
|
+
/**
|
|
182
|
+
* Index of block in aggregate response
|
|
183
|
+
*/
|
|
184
|
+
index?: string | number;
|
|
185
|
+
}
|
|
166
186
|
declare function defaultToolCallParser(
|
|
167
187
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
168
188
|
rawToolCalls: Record<string, any>[]): [ToolCall[], InvalidToolCall[]];
|
|
169
|
-
|
|
189
|
+
/**
|
|
190
|
+
* @deprecated Use {@link ToolMessage.isInstance} instead
|
|
191
|
+
*/
|
|
192
|
+
declare function isToolMessage(x: unknown): x is ToolMessage;
|
|
193
|
+
/**
|
|
194
|
+
* @deprecated Use {@link ToolMessageChunk.isInstance} instead
|
|
195
|
+
*/
|
|
170
196
|
declare function isToolMessageChunk(x: BaseMessageChunk): x is ToolMessageChunk;
|
|
171
197
|
//#endregion
|
|
172
|
-
export { DirectToolOutput, InvalidToolCall, ToolCall, ToolCallChunk, ToolMessage, ToolMessageChunk, ToolMessageFields,
|
|
198
|
+
export { DirectToolOutput, InvalidToolCall, ToolCall, ToolCallChunk, ToolMessage, ToolMessageChunk, ToolMessageFields, defaultToolCallParser, isDirectToolOutput, isToolMessage, isToolMessageChunk };
|
|
173
199
|
//# sourceMappingURL=tool.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.d.cts","names":["BaseMessage","BaseMessageChunk","BaseMessageFields","
|
|
1
|
+
{"version":3,"file":"tool.d.cts","names":["BaseMessage","BaseMessageChunk","BaseMessageFields","$InferMessageContent","MessageStructure","ToolMessageFields","TStructure","DirectToolOutput","isDirectToolOutput","ToolMessage","Record","ToolMessageChunk","ToolCall","TName","TArgs","ToolCallChunk","InvalidToolCall","defaultToolCallParser","isToolMessage","isToolMessageChunk"],"sources":["../../src/messages/tool.d.ts"],"sourcesContent":["import { BaseMessage, BaseMessageChunk, type BaseMessageFields } from \"./base.js\";\nimport { $InferMessageContent, MessageStructure } from \"./message.js\";\nexport interface ToolMessageFields<TStructure extends MessageStructure = MessageStructure> extends BaseMessageFields<TStructure, \"tool\"> {\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n tool_call_id: string;\n status?: \"success\" | \"error\";\n}\n/**\n * Marker parameter for objects that tools can return directly.\n *\n * If a custom BaseTool is invoked with a ToolCall and the output of custom code is\n * not an instance of DirectToolOutput, the output will automatically be coerced to\n * a string and wrapped in a ToolMessage.\n */\nexport interface DirectToolOutput {\n readonly lc_direct_tool_output: true;\n}\nexport declare function isDirectToolOutput(x: unknown): x is DirectToolOutput;\n/**\n * Represents a tool message in a conversation.\n */\nexport declare class ToolMessage<TStructure extends MessageStructure = MessageStructure> extends BaseMessage<TStructure, \"tool\"> implements DirectToolOutput {\n static lc_name(): string;\n get lc_aliases(): Record<string, string>;\n lc_direct_tool_output: true;\n readonly type: \"tool\";\n /**\n * Status of the tool invocation.\n * @version 0.2.19\n */\n status?: \"success\" | \"error\";\n tool_call_id: string;\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n constructor(fields: $InferMessageContent<TStructure, \"tool\"> | ToolMessageFields, tool_call_id: string, name?: string);\n constructor(fields: ToolMessageFields<TStructure>);\n static isInstance(message: unknown): message is ToolMessage;\n get _printableFields(): Record<string, unknown>;\n}\n/**\n * Represents a chunk of a tool message, which can be concatenated\n * with other tool message chunks.\n */\nexport declare class ToolMessageChunk<TStructure extends MessageStructure = MessageStructure> extends BaseMessageChunk<TStructure, \"tool\"> {\n readonly type: \"tool\";\n tool_call_id: string;\n /**\n * Status of the tool invocation.\n * @version 0.2.19\n */\n status?: \"success\" | \"error\";\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n constructor(fields: ToolMessageFields<TStructure>);\n static lc_name(): string;\n concat(chunk: ToolMessageChunk<TStructure>): this;\n get _printableFields(): Record<string, unknown>;\n}\nexport interface ToolCall<TName extends string = string, TArgs extends Record<string, unknown> = Record<string, unknown>> {\n readonly type?: \"tool_call\";\n /**\n * If provided, an identifier associated with the tool call\n */\n id?: string;\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n}\n/**\n * A chunk of a tool call (e.g., as part of a stream).\n * When merging ToolCallChunks (e.g., via AIMessageChunk.__add__),\n * all string attributes are concatenated. Chunks are only merged if their\n * values of `index` are equal and not None.\n *\n * @example\n * ```ts\n * const leftChunks = [\n * {\n * name: \"foo\",\n * args: '{\"a\":',\n * index: 0\n * }\n * ];\n *\n * const leftAIMessageChunk = new AIMessageChunk({\n * content: \"\",\n * tool_call_chunks: leftChunks\n * });\n *\n * const rightChunks = [\n * {\n * name: undefined,\n * args: '1}',\n * index: 0\n * }\n * ];\n *\n * const rightAIMessageChunk = new AIMessageChunk({\n * content: \"\",\n * tool_call_chunks: rightChunks\n * });\n *\n * const result = leftAIMessageChunk.concat(rightAIMessageChunk);\n * // result.tool_call_chunks is equal to:\n * // [\n * // {\n * // name: \"foo\",\n * // args: '{\"a\":1}'\n * // index: 0\n * // }\n * // ]\n * ```\n */\nexport interface ToolCallChunk<TName extends string = string> {\n readonly type?: \"tool_call_chunk\";\n /**\n * If provided, a substring of an identifier for the tool call\n */\n id?: string;\n /**\n * If provided, a substring of the name of the tool to be called\n */\n name?: TName;\n /**\n * If provided, a JSON substring of the arguments to the tool call\n */\n args?: string;\n /**\n * If provided, the index of the tool call in a sequence\n */\n index?: number;\n}\nexport interface InvalidToolCall<TName extends string = string> {\n readonly type?: \"invalid_tool_call\";\n /**\n * If provided, an identifier associated with the tool call\n */\n id?: string;\n /**\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * An error message associated with the tool call\n */\n error?: string;\n /**\n * Index of block in aggregate response\n */\n index?: string | number;\n}\nexport declare function defaultToolCallParser(\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nrawToolCalls: Record<string, any>[]): [ToolCall[], InvalidToolCall[]];\n/**\n * @deprecated Use {@link ToolMessage.isInstance} instead\n */\nexport declare function isToolMessage(x: unknown): x is ToolMessage;\n/**\n * @deprecated Use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AA,OAAA,CAAA,EAAA,OAAA,IApIOG,WAoIP;EAAA,IAE/BC,gBAAAA,CAAAA,CAAAA,EArIcA,MAqIdA,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;;;AAAoD;AAIlE;AAIA;AAA0C,cAvIrBC,gBAuIqB,CAAA,mBAvIeP,gBAuIf,GAvIkCA,gBAuIlC,CAAA,SAvI4DH,gBAuI5D,CAvI6EK,UAuI7E,EAAA,MAAA,CAAA,CAAA;EAAA,SAAIL,IAAAA,EAAAA,MAAAA;EAAgB,YAAQU,EAAAA,MAAAA;EAAgB;;;;;;;;;;;;;;sBAtH9DN,kBAAkBC;;gBAExBK,iBAAiBL;0BACPI;;UAEXE,sDAAsDF,0BAA0BA;;;;;;;;;QASvFG;;;;QAIAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UA+COC;;;;;;;;;SASNF;;;;;;;;;;UAUMG;;;;;;;;;;SAUNH;;;;;;;;;;;;;;iBAcaI,qBAAAA;;cAEVP,yBAAyBE,YAAYI;;;;iBAI3BE,aAAAA,mBAAgCT;;;;iBAIhCU,kBAAAA,IAAsBlB,wBAAwBU"}
|
package/dist/messages/tool.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { BaseMessage, BaseMessageChunk, BaseMessageFields
|
|
1
|
+
import { BaseMessage, BaseMessageChunk, BaseMessageFields } from "./base.js";
|
|
2
|
+
import { $InferMessageContent, MessageStructure } from "./message.js";
|
|
2
3
|
|
|
3
4
|
//#region src/messages/tool.d.ts
|
|
4
|
-
|
|
5
|
-
interface ToolMessageFieldsWithToolCallId extends ToolMessageFields {
|
|
5
|
+
interface ToolMessageFields<TStructure extends MessageStructure = MessageStructure> extends BaseMessageFields<TStructure, "tool"> {
|
|
6
6
|
/**
|
|
7
7
|
* Artifact of the Tool execution which is not meant to be sent to the model.
|
|
8
8
|
*
|
|
@@ -13,10 +13,6 @@ interface ToolMessageFieldsWithToolCallId extends ToolMessageFields {
|
|
|
13
13
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
14
|
artifact?: any;
|
|
15
15
|
tool_call_id: string;
|
|
16
|
-
/**
|
|
17
|
-
* Status of the tool invocation.
|
|
18
|
-
* @version 0.2.19
|
|
19
|
-
*/
|
|
20
16
|
status?: "success" | "error";
|
|
21
17
|
}
|
|
22
18
|
/**
|
|
@@ -33,11 +29,11 @@ declare function isDirectToolOutput(x: unknown): x is DirectToolOutput;
|
|
|
33
29
|
/**
|
|
34
30
|
* Represents a tool message in a conversation.
|
|
35
31
|
*/
|
|
36
|
-
declare class ToolMessage extends BaseMessage implements DirectToolOutput {
|
|
37
|
-
content: MessageContent;
|
|
32
|
+
declare class ToolMessage<TStructure extends MessageStructure = MessageStructure> extends BaseMessage<TStructure, "tool"> implements DirectToolOutput {
|
|
38
33
|
static lc_name(): string;
|
|
39
34
|
get lc_aliases(): Record<string, string>;
|
|
40
35
|
lc_direct_tool_output: true;
|
|
36
|
+
readonly type: "tool";
|
|
41
37
|
/**
|
|
42
38
|
* Status of the tool invocation.
|
|
43
39
|
* @version 0.2.19
|
|
@@ -53,18 +49,17 @@ declare class ToolMessage extends BaseMessage implements DirectToolOutput {
|
|
|
53
49
|
*/
|
|
54
50
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
51
|
artifact?: any;
|
|
56
|
-
constructor(fields:
|
|
57
|
-
constructor(fields:
|
|
58
|
-
|
|
59
|
-
static isInstance(message: BaseMessage): message is ToolMessage;
|
|
52
|
+
constructor(fields: $InferMessageContent<TStructure, "tool"> | ToolMessageFields, tool_call_id: string, name?: string);
|
|
53
|
+
constructor(fields: ToolMessageFields<TStructure>);
|
|
54
|
+
static isInstance(message: unknown): message is ToolMessage;
|
|
60
55
|
get _printableFields(): Record<string, unknown>;
|
|
61
56
|
}
|
|
62
57
|
/**
|
|
63
58
|
* Represents a chunk of a tool message, which can be concatenated
|
|
64
59
|
* with other tool message chunks.
|
|
65
60
|
*/
|
|
66
|
-
declare class ToolMessageChunk extends BaseMessageChunk {
|
|
67
|
-
|
|
61
|
+
declare class ToolMessageChunk<TStructure extends MessageStructure = MessageStructure> extends BaseMessageChunk<TStructure, "tool"> {
|
|
62
|
+
readonly type: "tool";
|
|
68
63
|
tool_call_id: string;
|
|
69
64
|
/**
|
|
70
65
|
* Status of the tool invocation.
|
|
@@ -80,25 +75,26 @@ declare class ToolMessageChunk extends BaseMessageChunk {
|
|
|
80
75
|
*/
|
|
81
76
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
82
77
|
artifact?: any;
|
|
83
|
-
constructor(fields:
|
|
78
|
+
constructor(fields: ToolMessageFields<TStructure>);
|
|
84
79
|
static lc_name(): string;
|
|
85
|
-
|
|
86
|
-
concat(chunk: ToolMessageChunk): ToolMessageChunk;
|
|
80
|
+
concat(chunk: ToolMessageChunk<TStructure>): this;
|
|
87
81
|
get _printableFields(): Record<string, unknown>;
|
|
88
82
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
*/
|
|
95
|
-
type ToolCall = {
|
|
96
|
-
name: string;
|
|
97
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
98
|
-
args: Record<string, any>;
|
|
83
|
+
interface ToolCall<TName extends string = string, TArgs extends Record<string, unknown> = Record<string, unknown>> {
|
|
84
|
+
readonly type?: "tool_call";
|
|
85
|
+
/**
|
|
86
|
+
* If provided, an identifier associated with the tool call
|
|
87
|
+
*/
|
|
99
88
|
id?: string;
|
|
100
|
-
|
|
101
|
-
|
|
89
|
+
/**
|
|
90
|
+
* The name of the tool being called
|
|
91
|
+
*/
|
|
92
|
+
name: TName;
|
|
93
|
+
/**
|
|
94
|
+
* The arguments to the tool call
|
|
95
|
+
*/
|
|
96
|
+
args: TArgs;
|
|
97
|
+
}
|
|
102
98
|
/**
|
|
103
99
|
* A chunk of a tool call (e.g., as part of a stream).
|
|
104
100
|
* When merging ToolCallChunks (e.g., via AIMessageChunk.__add__),
|
|
@@ -143,31 +139,61 @@ type ToolCall = {
|
|
|
143
139
|
* // }
|
|
144
140
|
* // ]
|
|
145
141
|
* ```
|
|
146
|
-
*
|
|
147
|
-
* @property {string} [name] - If provided, a substring of the name of the tool to be called
|
|
148
|
-
* @property {string} [args] - If provided, a JSON substring of the arguments to the tool call
|
|
149
|
-
* @property {string} [id] - If provided, a substring of an identifier for the tool call
|
|
150
|
-
* @property {number} [index] - If provided, the index of the tool call in a sequence
|
|
151
142
|
*/
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
143
|
+
interface ToolCallChunk<TName extends string = string> {
|
|
144
|
+
readonly type?: "tool_call_chunk";
|
|
145
|
+
/**
|
|
146
|
+
* If provided, a substring of an identifier for the tool call
|
|
147
|
+
*/
|
|
155
148
|
id?: string;
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
149
|
+
/**
|
|
150
|
+
* If provided, a substring of the name of the tool to be called
|
|
151
|
+
*/
|
|
152
|
+
name?: TName;
|
|
153
|
+
/**
|
|
154
|
+
* If provided, a JSON substring of the arguments to the tool call
|
|
155
|
+
*/
|
|
161
156
|
args?: string;
|
|
157
|
+
/**
|
|
158
|
+
* If provided, the index of the tool call in a sequence
|
|
159
|
+
*/
|
|
160
|
+
index?: number;
|
|
161
|
+
}
|
|
162
|
+
interface InvalidToolCall<TName extends string = string> {
|
|
163
|
+
readonly type?: "invalid_tool_call";
|
|
164
|
+
/**
|
|
165
|
+
* If provided, an identifier associated with the tool call
|
|
166
|
+
*/
|
|
162
167
|
id?: string;
|
|
168
|
+
/**
|
|
169
|
+
/**
|
|
170
|
+
* The name of the tool being called
|
|
171
|
+
*/
|
|
172
|
+
name?: TName;
|
|
173
|
+
/**
|
|
174
|
+
* The arguments to the tool call
|
|
175
|
+
*/
|
|
176
|
+
args?: string;
|
|
177
|
+
/**
|
|
178
|
+
* An error message associated with the tool call
|
|
179
|
+
*/
|
|
163
180
|
error?: string;
|
|
164
|
-
|
|
165
|
-
|
|
181
|
+
/**
|
|
182
|
+
* Index of block in aggregate response
|
|
183
|
+
*/
|
|
184
|
+
index?: string | number;
|
|
185
|
+
}
|
|
166
186
|
declare function defaultToolCallParser(
|
|
167
187
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
168
188
|
rawToolCalls: Record<string, any>[]): [ToolCall[], InvalidToolCall[]];
|
|
169
|
-
|
|
189
|
+
/**
|
|
190
|
+
* @deprecated Use {@link ToolMessage.isInstance} instead
|
|
191
|
+
*/
|
|
192
|
+
declare function isToolMessage(x: unknown): x is ToolMessage;
|
|
193
|
+
/**
|
|
194
|
+
* @deprecated Use {@link ToolMessageChunk.isInstance} instead
|
|
195
|
+
*/
|
|
170
196
|
declare function isToolMessageChunk(x: BaseMessageChunk): x is ToolMessageChunk;
|
|
171
197
|
//#endregion
|
|
172
|
-
export { DirectToolOutput, InvalidToolCall, ToolCall, ToolCallChunk, ToolMessage, ToolMessageChunk, ToolMessageFields,
|
|
198
|
+
export { DirectToolOutput, InvalidToolCall, ToolCall, ToolCallChunk, ToolMessage, ToolMessageChunk, ToolMessageFields, defaultToolCallParser, isDirectToolOutput, isToolMessage, isToolMessageChunk };
|
|
173
199
|
//# sourceMappingURL=tool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.d.ts","names":["BaseMessage","BaseMessageChunk","BaseMessageFields","
|
|
1
|
+
{"version":3,"file":"tool.d.ts","names":["BaseMessage","BaseMessageChunk","BaseMessageFields","$InferMessageContent","MessageStructure","ToolMessageFields","TStructure","DirectToolOutput","isDirectToolOutput","ToolMessage","Record","ToolMessageChunk","ToolCall","TName","TArgs","ToolCallChunk","InvalidToolCall","defaultToolCallParser","isToolMessage","isToolMessageChunk"],"sources":["../../src/messages/tool.d.ts"],"sourcesContent":["import { BaseMessage, BaseMessageChunk, type BaseMessageFields } from \"./base.js\";\nimport { $InferMessageContent, MessageStructure } from \"./message.js\";\nexport interface ToolMessageFields<TStructure extends MessageStructure = MessageStructure> extends BaseMessageFields<TStructure, \"tool\"> {\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n tool_call_id: string;\n status?: \"success\" | \"error\";\n}\n/**\n * Marker parameter for objects that tools can return directly.\n *\n * If a custom BaseTool is invoked with a ToolCall and the output of custom code is\n * not an instance of DirectToolOutput, the output will automatically be coerced to\n * a string and wrapped in a ToolMessage.\n */\nexport interface DirectToolOutput {\n readonly lc_direct_tool_output: true;\n}\nexport declare function isDirectToolOutput(x: unknown): x is DirectToolOutput;\n/**\n * Represents a tool message in a conversation.\n */\nexport declare class ToolMessage<TStructure extends MessageStructure = MessageStructure> extends BaseMessage<TStructure, \"tool\"> implements DirectToolOutput {\n static lc_name(): string;\n get lc_aliases(): Record<string, string>;\n lc_direct_tool_output: true;\n readonly type: \"tool\";\n /**\n * Status of the tool invocation.\n * @version 0.2.19\n */\n status?: \"success\" | \"error\";\n tool_call_id: string;\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n constructor(fields: $InferMessageContent<TStructure, \"tool\"> | ToolMessageFields, tool_call_id: string, name?: string);\n constructor(fields: ToolMessageFields<TStructure>);\n static isInstance(message: unknown): message is ToolMessage;\n get _printableFields(): Record<string, unknown>;\n}\n/**\n * Represents a chunk of a tool message, which can be concatenated\n * with other tool message chunks.\n */\nexport declare class ToolMessageChunk<TStructure extends MessageStructure = MessageStructure> extends BaseMessageChunk<TStructure, \"tool\"> {\n readonly type: \"tool\";\n tool_call_id: string;\n /**\n * Status of the tool invocation.\n * @version 0.2.19\n */\n status?: \"success\" | \"error\";\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n constructor(fields: ToolMessageFields<TStructure>);\n static lc_name(): string;\n concat(chunk: ToolMessageChunk<TStructure>): this;\n get _printableFields(): Record<string, unknown>;\n}\nexport interface ToolCall<TName extends string = string, TArgs extends Record<string, unknown> = Record<string, unknown>> {\n readonly type?: \"tool_call\";\n /**\n * If provided, an identifier associated with the tool call\n */\n id?: string;\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n}\n/**\n * A chunk of a tool call (e.g., as part of a stream).\n * When merging ToolCallChunks (e.g., via AIMessageChunk.__add__),\n * all string attributes are concatenated. Chunks are only merged if their\n * values of `index` are equal and not None.\n *\n * @example\n * ```ts\n * const leftChunks = [\n * {\n * name: \"foo\",\n * args: '{\"a\":',\n * index: 0\n * }\n * ];\n *\n * const leftAIMessageChunk = new AIMessageChunk({\n * content: \"\",\n * tool_call_chunks: leftChunks\n * });\n *\n * const rightChunks = [\n * {\n * name: undefined,\n * args: '1}',\n * index: 0\n * }\n * ];\n *\n * const rightAIMessageChunk = new AIMessageChunk({\n * content: \"\",\n * tool_call_chunks: rightChunks\n * });\n *\n * const result = leftAIMessageChunk.concat(rightAIMessageChunk);\n * // result.tool_call_chunks is equal to:\n * // [\n * // {\n * // name: \"foo\",\n * // args: '{\"a\":1}'\n * // index: 0\n * // }\n * // ]\n * ```\n */\nexport interface ToolCallChunk<TName extends string = string> {\n readonly type?: \"tool_call_chunk\";\n /**\n * If provided, a substring of an identifier for the tool call\n */\n id?: string;\n /**\n * If provided, a substring of the name of the tool to be called\n */\n name?: TName;\n /**\n * If provided, a JSON substring of the arguments to the tool call\n */\n args?: string;\n /**\n * If provided, the index of the tool call in a sequence\n */\n index?: number;\n}\nexport interface InvalidToolCall<TName extends string = string> {\n readonly type?: \"invalid_tool_call\";\n /**\n * If provided, an identifier associated with the tool call\n */\n id?: string;\n /**\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * An error message associated with the tool call\n */\n error?: string;\n /**\n * Index of block in aggregate response\n */\n index?: string | number;\n}\nexport declare function defaultToolCallParser(\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nrawToolCalls: Record<string, any>[]): [ToolCall[], InvalidToolCall[]];\n/**\n * @deprecated Use {@link ToolMessage.isInstance} instead\n */\nexport declare function isToolMessage(x: unknown): x is ToolMessage;\n/**\n * @deprecated Use {@link ToolMessageChunk.isInstance} instead\n */\nexport declare function isToolMessageChunk(x: BaseMessageChunk): x is ToolMessageChunk;\n"],"mappings":";;;;UAEiBK,qCAAqCD,mBAAmBA,0BAA0BF,kBAAkBI;;AAArH;;;;;;EAAoH;EAoBnGC,QAAAA,CAAAA,EAAAA,GAAAA;EAGOC,YAAAA,EAAAA,MAAAA;EAIHC,MAAAA,CAAAA,EAAAA,SAAW,GAAA,OAAA;;;;;;;;;AAqBUH,UA5BzBC,gBAAAA,CA4ByBD;EAAU,SAA5BD,qBAAAA,EAAAA,IAAAA;;AAEIK,iBA3BJF,kBAAAA,CA2BIE,CAAAA,EAAAA,OAAAA,CAAAA,EAAAA,CAAAA,IA3BiCH,gBA2BjCG;;;AAvBgI;AA6BvIC,cA7BAF,WA6BgB,CAAA,mBA7BeL,gBA6Bf,GA7BkCA,gBA6BlC,CAAA,SA7B4DJ,WA6B5D,CA7BwEM,UA6BxE,EAAA,MAAA,CAAA,YA7BuGC,gBA6BvG,CAAA;EAAA,OAAA,OAAA,CAAA,CAAA,EAAA,MAAA;EAAA,IAAoBH,UAAAA,CAAAA,CAAAA,EA3BnCM,MA2BmCN,CAAAA,MAAAA,EAAAA,MAAAA,CAAAA;EAAgB,qBAAGA,EAAAA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age = class extends BaseMessage {
|
|
|
25
25
|
return { tool_call_id: "tool_call_id" };
|
|
26
26
|
}
|
|
27
27
|
lc_direct_tool_output = true;
|
|
28
|
+
type = "tool";
|
|
28
29
|
/**
|
|
29
30
|
* Status of the tool invocation.
|
|
30
31
|
* @version 0.2.19
|
|
@@ -40,7 +41,7 @@ var ToolMessage = class extends BaseMessage {
|
|
|
40
41
|
*/
|
|
41
42
|
artifact;
|
|
42
43
|
constructor(fields, tool_call_id, name) {
|
|
43
|
-
if (typeof fields === "string") fields = {
|
|
44
|
+
if (typeof fields === "string" || Array.isArray(fields)) fields = {
|
|
44
45
|
content: fields,
|
|
45
46
|
name,
|
|
46
47
|
tool_call_id
|
|
@@ -50,11 +51,8 @@ var ToolMessage = class extends BaseMessage {
|
|
|
50
51
|
this.artifact = fields.artifact;
|
|
51
52
|
this.status = fields.status;
|
|
52
53
|
}
|
|
53
|
-
_getType() {
|
|
54
|
-
return "tool";
|
|
55
|
-
}
|
|
56
54
|
static isInstance(message) {
|
|
57
|
-
return
|
|
55
|
+
return super.isInstance(message) && message.type === "tool";
|
|
58
56
|
}
|
|
59
57
|
get _printableFields() {
|
|
60
58
|
return {
|
|
@@ -68,7 +66,8 @@ var ToolMessage = class extends BaseMessage {
|
|
|
68
66
|
* Represents a chunk of a tool message, which can be concatenated
|
|
69
67
|
* with other tool message chunks.
|
|
70
68
|
*/
|
|
71
|
-
var ToolMessageChunk = class
|
|
69
|
+
var ToolMessageChunk = class extends BaseMessageChunk {
|
|
70
|
+
type = "tool";
|
|
72
71
|
tool_call_id;
|
|
73
72
|
/**
|
|
74
73
|
* Status of the tool invocation.
|
|
@@ -92,11 +91,9 @@ var ToolMessageChunk = class ToolMessageChunk extends BaseMessageChunk {
|
|
|
92
91
|
static lc_name() {
|
|
93
92
|
return "ToolMessageChunk";
|
|
94
93
|
}
|
|
95
|
-
_getType() {
|
|
96
|
-
return "tool";
|
|
97
|
-
}
|
|
98
94
|
concat(chunk) {
|
|
99
|
-
|
|
95
|
+
const Cls = this.constructor;
|
|
96
|
+
return new Cls({
|
|
100
97
|
content: mergeContent(this.content, chunk.content),
|
|
101
98
|
additional_kwargs: _mergeDicts(this.additional_kwargs, chunk.additional_kwargs),
|
|
102
99
|
response_metadata: _mergeDicts(this.response_metadata, chunk.response_metadata),
|
|
@@ -122,12 +119,11 @@ function defaultToolCallParser(rawToolCalls) {
|
|
|
122
119
|
const functionName = toolCall.function.name;
|
|
123
120
|
try {
|
|
124
121
|
const functionArgs = JSON.parse(toolCall.function.arguments);
|
|
125
|
-
|
|
122
|
+
toolCalls.push({
|
|
126
123
|
name: functionName || "",
|
|
127
124
|
args: functionArgs || {},
|
|
128
125
|
id: toolCall.id
|
|
129
|
-
};
|
|
130
|
-
toolCalls.push(parsed);
|
|
126
|
+
});
|
|
131
127
|
} catch (error) {
|
|
132
128
|
invalidToolCalls.push({
|
|
133
129
|
name: functionName,
|
|
@@ -139,9 +135,15 @@ function defaultToolCallParser(rawToolCalls) {
|
|
|
139
135
|
}
|
|
140
136
|
return [toolCalls, invalidToolCalls];
|
|
141
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* @deprecated Use {@link ToolMessage.isInstance} instead
|
|
140
|
+
*/
|
|
142
141
|
function isToolMessage(x) {
|
|
143
|
-
return x.
|
|
142
|
+
return typeof x === "object" && x !== null && "getType" in x && typeof x.getType === "function" && x.getType() === "tool";
|
|
144
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* @deprecated Use {@link ToolMessageChunk.isInstance} instead
|
|
146
|
+
*/
|
|
145
147
|
function isToolMessageChunk(x) {
|
|
146
148
|
return x._getType() === "tool";
|
|
147
149
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.js","names":["x: unknown","fields: string | ToolMessageFieldsWithToolCallId","tool_call_id?: string","name?: string","message: BaseMessage","fields: ToolMessageFieldsWithToolCallId","chunk: ToolMessageChunk","rawToolCalls: Record<string, any>[]","toolCalls: ToolCall[]","invalidToolCalls: InvalidToolCall[]","x: BaseMessage","x: BaseMessageChunk"],"sources":["../../src/messages/tool.ts"],"sourcesContent":["import {\n BaseMessage,\n BaseMessageChunk,\n type BaseMessageFields,\n mergeContent,\n _mergeDicts,\n type MessageType,\n _mergeObj,\n _mergeStatus,\n type MessageContent,\n} from \"./base.js\";\n\nexport type ToolMessageFields = BaseMessageFields;\n\nexport interface ToolMessageFieldsWithToolCallId extends ToolMessageFields {\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n tool_call_id: string;\n /**\n * Status of the tool invocation.\n * @version 0.2.19\n */\n status?: \"success\" | \"error\";\n}\n\n/**\n * Marker parameter for objects that tools can return directly.\n *\n * If a custom BaseTool is invoked with a ToolCall and the output of custom code is\n * not an instance of DirectToolOutput, the output will automatically be coerced to\n * a string and wrapped in a ToolMessage.\n */\nexport interface DirectToolOutput {\n readonly lc_direct_tool_output: true;\n}\n\nexport function isDirectToolOutput(x: unknown): x is DirectToolOutput {\n return (\n x != null &&\n typeof x === \"object\" &&\n \"lc_direct_tool_output\" in x &&\n x.lc_direct_tool_output === true\n );\n}\n\n/**\n * Represents a tool message in a conversation.\n */\nexport class ToolMessage extends BaseMessage implements DirectToolOutput {\n declare content: MessageContent;\n\n static lc_name() {\n return \"ToolMessage\";\n }\n\n get lc_aliases(): Record<string, string> {\n // exclude snake case conversion to pascal case\n return { tool_call_id: \"tool_call_id\" };\n }\n\n lc_direct_tool_output = true as const;\n\n /**\n * Status of the tool invocation.\n * @version 0.2.19\n */\n status?: \"success\" | \"error\";\n\n tool_call_id: string;\n\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n\n constructor(fields: ToolMessageFieldsWithToolCallId);\n\n constructor(\n fields: string | ToolMessageFields,\n tool_call_id: string,\n name?: string\n );\n\n constructor(\n fields: string | ToolMessageFieldsWithToolCallId,\n tool_call_id?: string,\n name?: string\n ) {\n if (typeof fields === \"string\") {\n // eslint-disable-next-line no-param-reassign, @typescript-eslint/no-non-null-assertion\n fields = { content: fields, name, tool_call_id: tool_call_id! };\n }\n super(fields);\n this.tool_call_id = fields.tool_call_id;\n this.artifact = fields.artifact;\n this.status = fields.status;\n }\n\n _getType(): MessageType {\n return \"tool\";\n }\n\n static isInstance(message: BaseMessage): message is ToolMessage {\n return message._getType() === \"tool\";\n }\n\n override get _printableFields(): Record<string, unknown> {\n return {\n ...super._printableFields,\n tool_call_id: this.tool_call_id,\n artifact: this.artifact,\n };\n }\n}\n\n/**\n * Represents a chunk of a tool message, which can be concatenated\n * with other tool message chunks.\n */\nexport class ToolMessageChunk extends BaseMessageChunk {\n declare content: MessageContent;\n\n tool_call_id: string;\n\n /**\n * Status of the tool invocation.\n * @version 0.2.19\n */\n status?: \"success\" | \"error\";\n\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n\n constructor(fields: ToolMessageFieldsWithToolCallId) {\n super(fields);\n this.tool_call_id = fields.tool_call_id;\n this.artifact = fields.artifact;\n this.status = fields.status;\n }\n\n static lc_name() {\n return \"ToolMessageChunk\";\n }\n\n _getType(): MessageType {\n return \"tool\";\n }\n\n concat(chunk: ToolMessageChunk) {\n return new ToolMessageChunk({\n content: mergeContent(this.content, chunk.content),\n additional_kwargs: _mergeDicts(\n this.additional_kwargs,\n chunk.additional_kwargs\n ),\n response_metadata: _mergeDicts(\n this.response_metadata,\n chunk.response_metadata\n ),\n artifact: _mergeObj(this.artifact, chunk.artifact),\n tool_call_id: this.tool_call_id,\n id: this.id ?? chunk.id,\n status: _mergeStatus(this.status, chunk.status),\n });\n }\n\n override get _printableFields(): Record<string, unknown> {\n return {\n ...super._printableFields,\n tool_call_id: this.tool_call_id,\n artifact: this.artifact,\n };\n }\n}\n\n/**\n * A call to a tool.\n * @property {string} name - The name of the tool to be called\n * @property {Record<string, any>} args - The arguments to the tool call\n * @property {string} [id] - If provided, an identifier associated with the tool call\n */\nexport type ToolCall = {\n name: string;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n args: Record<string, any>;\n\n id?: string;\n\n type?: \"tool_call\";\n};\n\n/**\n * A chunk of a tool call (e.g., as part of a stream).\n * When merging ToolCallChunks (e.g., via AIMessageChunk.__add__),\n * all string attributes are concatenated. Chunks are only merged if their\n * values of `index` are equal and not None.\n *\n * @example\n * ```ts\n * const leftChunks = [\n * {\n * name: \"foo\",\n * args: '{\"a\":',\n * index: 0\n * }\n * ];\n *\n * const leftAIMessageChunk = new AIMessageChunk({\n * content: \"\",\n * tool_call_chunks: leftChunks\n * });\n *\n * const rightChunks = [\n * {\n * name: undefined,\n * args: '1}',\n * index: 0\n * }\n * ];\n *\n * const rightAIMessageChunk = new AIMessageChunk({\n * content: \"\",\n * tool_call_chunks: rightChunks\n * });\n *\n * const result = leftAIMessageChunk.concat(rightAIMessageChunk);\n * // result.tool_call_chunks is equal to:\n * // [\n * // {\n * // name: \"foo\",\n * // args: '{\"a\":1}'\n * // index: 0\n * // }\n * // ]\n * ```\n *\n * @property {string} [name] - If provided, a substring of the name of the tool to be called\n * @property {string} [args] - If provided, a JSON substring of the arguments to the tool call\n * @property {string} [id] - If provided, a substring of an identifier for the tool call\n * @property {number} [index] - If provided, the index of the tool call in a sequence\n */\nexport type ToolCallChunk = {\n name?: string;\n\n args?: string;\n\n id?: string;\n\n index?: number;\n\n type?: \"tool_call_chunk\";\n};\n\nexport type InvalidToolCall = {\n name?: string;\n args?: string;\n id?: string;\n error?: string;\n type?: \"invalid_tool_call\";\n};\n\nexport function defaultToolCallParser(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCalls: Record<string, any>[]\n): [ToolCall[], InvalidToolCall[]] {\n const toolCalls: ToolCall[] = [];\n const invalidToolCalls: InvalidToolCall[] = [];\n for (const toolCall of rawToolCalls) {\n if (!toolCall.function) {\n continue;\n } else {\n const functionName = toolCall.function.name;\n try {\n const functionArgs = JSON.parse(toolCall.function.arguments);\n const parsed = {\n name: functionName || \"\",\n args: functionArgs || {},\n id: toolCall.id,\n };\n toolCalls.push(parsed);\n } catch (error) {\n invalidToolCalls.push({\n name: functionName,\n args: toolCall.function.arguments,\n id: toolCall.id,\n error: \"Malformed args.\",\n });\n }\n }\n }\n return [toolCalls, invalidToolCalls];\n}\n\nexport function isToolMessage(x: BaseMessage): x is ToolMessage {\n return x._getType() === \"tool\";\n}\n\nexport function isToolMessageChunk(x: BaseMessageChunk): x is ToolMessageChunk {\n return x._getType() === \"tool\";\n}\n"],"mappings":";;;;;;;;;;;;;AA2CA,SAAgB,mBAAmBA,GAAmC;AACpE,QACE,KAAK,QACL,OAAO,MAAM,YACb,2BAA2B,KAC3B,EAAE,0BAA0B;AAE/B;;;;AAKD,IAAa,cAAb,cAAiC,YAAwC;CAGvE,OAAO,UAAU;AACf,SAAO;CACR;CAED,IAAI,aAAqC;AAEvC,SAAO,EAAE,cAAc,eAAgB;CACxC;CAED,wBAAwB;;;;;CAMxB;CAEA;;;;;;;;CAUA;CAUA,YACEC,QACAC,cACAC,MACA;AACA,MAAI,OAAO,WAAW,UAEpB,SAAS;GAAE,SAAS;GAAQ;GAAoB;EAAe;EAEjE,MAAM,OAAO;EACb,KAAK,eAAe,OAAO;EAC3B,KAAK,WAAW,OAAO;EACvB,KAAK,SAAS,OAAO;CACtB;CAED,WAAwB;AACtB,SAAO;CACR;CAED,OAAO,WAAWC,SAA8C;AAC9D,SAAO,QAAQ,UAAU,KAAK;CAC/B;CAED,IAAa,mBA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H,QAAO,CAAC,WAAW,gBAAiB;AACrC;AAED,SAAgB,cAAcC,GAAkC;AAC9D,QAAO,EAAE,UAAU,KAAK;AACzB;AAED,SAAgB,mBAAmBC,GAA4C;AAC7E,QAAO,EAAE,UAAU,KAAK;AACzB"}
|
|
1
|
+
{"version":3,"file":"tool.js","names":["x: unknown","fields:\n | $InferMessageContent<TStructure, \"tool\">\n | ToolMessageFields<TStructure>","tool_call_id?: string","name?: string","message: unknown","fields: ToolMessageFields<TStructure>","chunk: ToolMessageChunk<TStructure>","rawToolCalls: Record<string, any>[]","toolCalls: ToolCall[]","invalidToolCalls: InvalidToolCall[]","x: BaseMessageChunk"],"sources":["../../src/messages/tool.ts"],"sourcesContent":["import {\n BaseMessage,\n BaseMessageChunk,\n type BaseMessageFields,\n mergeContent,\n _mergeDicts,\n _mergeObj,\n _mergeStatus,\n} from \"./base.js\";\nimport { $InferMessageContent, MessageStructure } from \"./message.js\";\nimport { Constructor } from \"./utils.js\";\n\nexport interface ToolMessageFields<\n TStructure extends MessageStructure = MessageStructure\n> extends BaseMessageFields<TStructure, \"tool\"> {\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n tool_call_id: string;\n status?: \"success\" | \"error\";\n}\n\n/**\n * Marker parameter for objects that tools can return directly.\n *\n * If a custom BaseTool is invoked with a ToolCall and the output of custom code is\n * not an instance of DirectToolOutput, the output will automatically be coerced to\n * a string and wrapped in a ToolMessage.\n */\nexport interface DirectToolOutput {\n readonly lc_direct_tool_output: true;\n}\n\nexport function isDirectToolOutput(x: unknown): x is DirectToolOutput {\n return (\n x != null &&\n typeof x === \"object\" &&\n \"lc_direct_tool_output\" in x &&\n x.lc_direct_tool_output === true\n );\n}\n\n/**\n * Represents a tool message in a conversation.\n */\nexport class ToolMessage<TStructure extends MessageStructure = MessageStructure>\n extends BaseMessage<TStructure, \"tool\">\n implements DirectToolOutput\n{\n static lc_name() {\n return \"ToolMessage\";\n }\n\n get lc_aliases(): Record<string, string> {\n // exclude snake case conversion to pascal case\n return { tool_call_id: \"tool_call_id\" };\n }\n\n lc_direct_tool_output = true as const;\n\n readonly type = \"tool\" as const;\n\n /**\n * Status of the tool invocation.\n * @version 0.2.19\n */\n status?: \"success\" | \"error\";\n\n tool_call_id: string;\n\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n\n constructor(\n fields: $InferMessageContent<TStructure, \"tool\"> | ToolMessageFields,\n tool_call_id: string,\n name?: string\n );\n\n constructor(fields: ToolMessageFields<TStructure>);\n\n constructor(\n fields:\n | $InferMessageContent<TStructure, \"tool\">\n | ToolMessageFields<TStructure>,\n tool_call_id?: string,\n name?: string\n ) {\n if (typeof fields === \"string\" || Array.isArray(fields)) {\n // eslint-disable-next-line no-param-reassign, @typescript-eslint/no-non-null-assertion\n fields = { content: fields, name, tool_call_id: tool_call_id! };\n }\n super(fields);\n this.tool_call_id = fields.tool_call_id;\n this.artifact = fields.artifact;\n this.status = fields.status;\n }\n\n static isInstance(message: unknown): message is ToolMessage {\n return super.isInstance(message) && message.type === \"tool\";\n }\n\n override get _printableFields(): Record<string, unknown> {\n return {\n ...super._printableFields,\n tool_call_id: this.tool_call_id,\n artifact: this.artifact,\n };\n }\n}\n\n/**\n * Represents a chunk of a tool message, which can be concatenated\n * with other tool message chunks.\n */\nexport class ToolMessageChunk<\n TStructure extends MessageStructure = MessageStructure\n> extends BaseMessageChunk<TStructure, \"tool\"> {\n readonly type = \"tool\" as const;\n\n tool_call_id: string;\n\n /**\n * Status of the tool invocation.\n * @version 0.2.19\n */\n status?: \"success\" | \"error\";\n\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n\n constructor(fields: ToolMessageFields<TStructure>) {\n super(fields);\n this.tool_call_id = fields.tool_call_id;\n this.artifact = fields.artifact;\n this.status = fields.status;\n }\n\n static lc_name() {\n return \"ToolMessageChunk\";\n }\n\n concat(chunk: ToolMessageChunk<TStructure>) {\n const Cls = this.constructor as Constructor<this>;\n return new Cls({\n content: mergeContent(this.content, chunk.content),\n additional_kwargs: _mergeDicts(\n this.additional_kwargs,\n chunk.additional_kwargs\n ),\n response_metadata: _mergeDicts(\n this.response_metadata,\n chunk.response_metadata\n ),\n artifact: _mergeObj(this.artifact, chunk.artifact),\n tool_call_id: this.tool_call_id,\n id: this.id ?? chunk.id,\n status: _mergeStatus(this.status, chunk.status),\n });\n }\n\n override get _printableFields(): Record<string, unknown> {\n return {\n ...super._printableFields,\n tool_call_id: this.tool_call_id,\n artifact: this.artifact,\n };\n }\n}\n\nexport interface ToolCall<\n TName extends string = string,\n TArgs extends Record<string, unknown> = Record<string, unknown>\n> {\n readonly type?: \"tool_call\";\n /**\n * If provided, an identifier associated with the tool call\n */\n id?: string;\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n}\n\n/**\n * A chunk of a tool call (e.g., as part of a stream).\n * When merging ToolCallChunks (e.g., via AIMessageChunk.__add__),\n * all string attributes are concatenated. Chunks are only merged if their\n * values of `index` are equal and not None.\n *\n * @example\n * ```ts\n * const leftChunks = [\n * {\n * name: \"foo\",\n * args: '{\"a\":',\n * index: 0\n * }\n * ];\n *\n * const leftAIMessageChunk = new AIMessageChunk({\n * content: \"\",\n * tool_call_chunks: leftChunks\n * });\n *\n * const rightChunks = [\n * {\n * name: undefined,\n * args: '1}',\n * index: 0\n * }\n * ];\n *\n * const rightAIMessageChunk = new AIMessageChunk({\n * content: \"\",\n * tool_call_chunks: rightChunks\n * });\n *\n * const result = leftAIMessageChunk.concat(rightAIMessageChunk);\n * // result.tool_call_chunks is equal to:\n * // [\n * // {\n * // name: \"foo\",\n * // args: '{\"a\":1}'\n * // index: 0\n * // }\n * // ]\n * ```\n */\nexport interface ToolCallChunk<TName extends string = string> {\n readonly type?: \"tool_call_chunk\";\n /**\n * If provided, a substring of an identifier for the tool call\n */\n id?: string;\n /**\n * If provided, a substring of the name of the tool to be called\n */\n name?: TName;\n /**\n * If provided, a JSON substring of the arguments to the tool call\n */\n args?: string;\n /**\n * If provided, the index of the tool call in a sequence\n */\n index?: number;\n}\n\nexport interface InvalidToolCall<TName extends string = string> {\n readonly type?: \"invalid_tool_call\";\n /**\n * If provided, an identifier associated with the tool call\n */\n id?: string;\n /**\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * An error message associated with the tool call\n */\n error?: string;\n /**\n * Index of block in aggregate response\n */\n index?: string | number;\n}\n\nexport function defaultToolCallParser(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCalls: Record<string, any>[]\n): [ToolCall[], InvalidToolCall[]] {\n const toolCalls: ToolCall[] = [];\n const invalidToolCalls: InvalidToolCall[] = [];\n for (const toolCall of rawToolCalls) {\n if (!toolCall.function) {\n continue;\n } else {\n const functionName = toolCall.function.name;\n try {\n const functionArgs = JSON.parse(toolCall.function.arguments);\n toolCalls.push({\n name: functionName || \"\",\n args: functionArgs || {},\n id: toolCall.id,\n });\n } catch (error) {\n invalidToolCalls.push({\n name: functionName,\n args: toolCall.function.arguments,\n id: toolCall.id,\n error: \"Malformed args.\",\n });\n }\n }\n }\n return [toolCalls, invalidToolCalls];\n}\n\n/**\n * @deprecated Use {@link ToolMessage.isInstance} instead\n */\nexport function isToolMessage(x: unknown): x is ToolMessage {\n return (\n typeof x === \"object\" &&\n x !== null &&\n \"getType\" in x &&\n typeof x.getType === \"function\" &&\n x.getType() === \"tool\"\n );\n}\n\n/**\n * @deprecated Use {@link ToolMessageChunk.isInstance} instead\n */\nexport function isToolMessageChunk(x: BaseMessageChunk): x is ToolMessageChunk {\n return x._getType() === \"tool\";\n}\n"],"mappings":";;;;;;;;;;;;;AAuCA,SAAgB,mBAAmBA,GAAmC;AACpE,QACE,KAAK,QACL,OAAO,MAAM,YACb,2BAA2B,KAC3B,EAAE,0BAA0B;AAE/B;;;;AAKD,IAAa,cAAb,cACU,YAEV;CACE,OAAO,UAAU;AACf,SAAO;CACR;CAED,IAAI,aAAqC;AAEvC,SAAO,EAAE,cAAc,eAAgB;CACxC;CAED,wBAAwB;CAExB,AAAS,OAAO;;;;;CAMhB;CAEA;;;;;;;;CAUA;CAUA,YACEC,QAGAC,cACAC,MACA;AACA,MAAI,OAAO,WAAW,YAAY,MAAM,QAAQ,OAAO,EAErD,SAAS;GAAE,SAAS;GAAQ;GAAoB;EAAe;EAEjE,MAAM,OAAO;EACb,KAAK,eAAe,OAAO;EAC3B,KAAK,WAAW,OAAO;EACvB,KAAK,SAAS,OAAO;CACtB;CAED,OAAO,WAAWC,SAA0C;AAC1D,SAAO,MAAM,WAAW,QAAQ,IAAI,QAAQ,SAAS;CACtD;CAED,IAAa,mBAA4C;AACvD,SAAO;GACL,GAAG,MAAM;GACT,cAAc,KAAK;GACnB,UAAU,KAAK;EAChB;CACF;AACF;;;;;AAMD,IAAa,mBAAb,cAEU,iBAAqC;CAC7C,AAAS,OAAO;CAEhB;;;;;CAMA;;;;;;;;CAUA;CAEA,YAAYC,QAAuC;EACjD,MAAM,OAAO;EACb,KAAK,eAAe,OAAO;EAC3B,KAAK,WAAW,OAAO;EACvB,KAAK,SAAS,OAAO;CACtB;CAED,OAAO,UAAU;AACf,SAAO;CACR;CAED,OAAOC,OAAqC;EAC1C,MAAM,MAAM,KAAK;AACjB,SAAO,IAAI,IAAI;GACb,SAAS,aAAa,KAAK,SAAS,MAAM,QAAQ;GAClD,mBA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