@langchain/core 1.0.0-alpha.1 → 1.0.0-alpha.2
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/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/messages/tool.cjs +1 -1
- package/dist/messages/tool.cjs.map +1 -1
- package/dist/messages/tool.d.cts +1 -1
- package/dist/messages/tool.d.cts.map +1 -1
- package/dist/messages/tool.d.ts +1 -1
- package/dist/messages/tool.d.ts.map +1 -1
- package/dist/messages/tool.js +1 -1
- package/dist/messages/tool.js.map +1 -1
- package/dist/runnables/base.cjs +1 -1
- package/dist/runnables/base.cjs.map +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.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 +4 -1
- package/dist/tools/types.d.cts.map +1 -1
- package/dist/tools/types.d.ts +4 -1
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js.map +1 -1
- package/dist/tracers/tracer_langchain.d.ts.map +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/package.json +19 -18
package/dist/index.cjs
CHANGED
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["export {};\n"],"mappings":""}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export {};\n"],"mappings":""}
|
package/dist/messages/tool.cjs
CHANGED
|
@@ -140,7 +140,7 @@ function defaultToolCallParser(rawToolCalls) {
|
|
|
140
140
|
return [toolCalls, invalidToolCalls];
|
|
141
141
|
}
|
|
142
142
|
function isToolMessage(x) {
|
|
143
|
-
return x.
|
|
143
|
+
return typeof x === "object" && x !== null && "getType" in x && typeof x.getType === "function" && x.getType() === "tool";
|
|
144
144
|
}
|
|
145
145
|
function isToolMessageChunk(x) {
|
|
146
146
|
return x._getType() === "tool";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.cjs","names":["x: unknown","BaseMessage","fields: string | ToolMessageFieldsWithToolCallId","tool_call_id?: string","name?: string","message: BaseMessage","BaseMessageChunk","fields: ToolMessageFieldsWithToolCallId","chunk: ToolMessageChunk","mergeContent","_mergeDicts","_mergeObj","_mergeStatus","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,cAAiCC,yBAAwC;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,mBAA4C;AACvD,SAAO;GACL,GAAG,MAAM;GACT,cAAc,KAAK;GACnB,UAAU,KAAK;EAChB;CACF;AACF;;;;;AAMD,IAAa,mBAAb,MAAa,yBAAyBC,8BAAiB;CAGrD;;;;;CAMA;;;;;;;;CAUA;CAEA,YAAYC,QAAyC;EACnD,MAAM,OAAO;EACb,KAAK,eAAe,OAAO;EAC3B,KAAK,WAAW,OAAO;EACvB,KAAK,SAAS,OAAO;CACtB;CAED,OAAO,UAAU;AACf,SAAO;CACR;CAED,WAAwB;AACtB,SAAO;CACR;CAED,OAAOC,OAAyB;AAC9B,SAAO,IAAI,iBAAiB;GAC1B,SAASC,0BAAa,KAAK,SAAS,MAAM,QAAQ;GAClD,mBAAmBC,yBACjB,KAAK,mBACL,MAAM,kBACP;GACD,mBAAmBA,yBACjB,KAAK,mBACL,MAAM,kBACP;GACD,UAAUC,uBAAU,KAAK,UAAU,MAAM,SAAS;GAClD,cAAc,KAAK;GACnB,IAAI,KAAK,MAAM,MAAM;GACrB,QAAQC,0BAAa,KAAK,QAAQ,MAAM,OAAO;EAChD;CACF;CAED,IAAa,mBAA4C;AACvD,SAAO;GACL,GAAG,MAAM;GACT,cAAc,KAAK;GACnB,UAAU,KAAK;EAChB;CACF;AACF;AAyFD,SAAgB,sBAEdC,cACiC;CACjC,MAAMC,YAAwB,CAAE;CAChC,MAAMC,mBAAsC,CAAE;AAC9C,MAAK,MAAM,YAAY,aACrB,KAAI,CAAC,SAAS,SACZ;MACK;EACL,MAAM,eAAe,SAAS,SAAS;AACvC,MAAI;GACF,MAAM,eAAe,KAAK,MAAM,SAAS,SAAS,UAAU;GAC5D,MAAM,SAAS;IACb,MAAM,gBAAgB;IACtB,MAAM,gBAAgB,CAAE;IACxB,IAAI,SAAS;GACd;GACD,UAAU,KAAK,OAAO;EACvB,SAAQ,OAAO;GACd,iBAAiB,KAAK;IACpB,MAAM;IACN,MAAM,SAAS,SAAS;IACxB,IAAI,SAAS;IACb,OAAO;GACR,EAAC;EACH;CACF;AAEH,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.cjs","names":["x: unknown","BaseMessage","fields: string | ToolMessageFieldsWithToolCallId","tool_call_id?: string","name?: string","message: BaseMessage","BaseMessageChunk","fields: ToolMessageFieldsWithToolCallId","chunk: ToolMessageChunk","mergeContent","_mergeDicts","_mergeObj","_mergeStatus","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 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: 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\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,cAAiCC,yBAAwC;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,mBAA4C;AACvD,SAAO;GACL,GAAG,MAAM;GACT,cAAc,KAAK;GACnB,UAAU,KAAK;EAChB;CACF;AACF;;;;;AAMD,IAAa,mBAAb,MAAa,yBAAyBC,8BAAiB;CAGrD;;;;;CAMA;;;;;;;;CAUA;CAEA,YAAYC,QAAyC;EACnD,MAAM,OAAO;EACb,KAAK,eAAe,OAAO;EAC3B,KAAK,WAAW,OAAO;EACvB,KAAK,SAAS,OAAO;CACtB;CAED,OAAO,UAAU;AACf,SAAO;CACR;CAED,WAAwB;AACtB,SAAO;CACR;CAED,OAAOC,OAAyB;AAC9B,SAAO,IAAI,iBAAiB;GAC1B,SAASC,0BAAa,KAAK,SAAS,MAAM,QAAQ;GAClD,mBAAmBC,yBACjB,KAAK,mBACL,MAAM,kBACP;GACD,mBAAmBA,yBACjB,KAAK,mBACL,MAAM,kBACP;GACD,UAAUC,uBAAU,KAAK,UAAU,MAAM,SAAS;GAClD,cAAc,KAAK;GACnB,IAAI,KAAK,MAAM,MAAM;GACrB,QAAQC,0BAAa,KAAK,QAAQ,MAAM,OAAO;EAChD;CACF;CAED,IAAa,mBAA4C;AACvD,SAAO;GACL,GAAG,MAAM;GACT,cAAc,KAAK;GACnB,UAAU,KAAK;EAChB;CACF;AACF;AAyFD,SAAgB,sBAEdC,cACiC;CACjC,MAAMC,YAAwB,CAAE;CAChC,MAAMC,mBAAsC,CAAE;AAC9C,MAAK,MAAM,YAAY,aACrB,KAAI,CAAC,SAAS,SACZ;MACK;EACL,MAAM,eAAe,SAAS,SAAS;AACvC,MAAI;GACF,MAAM,eAAe,KAAK,MAAM,SAAS,SAAS,UAAU;GAC5D,MAAM,SAAS;IACb,MAAM,gBAAgB;IACtB,MAAM,gBAAgB,CAAE;IACxB,IAAI,SAAS;GACd;GACD,UAAU,KAAK,OAAO;EACvB,SAAQ,OAAO;GACd,iBAAiB,KAAK;IACpB,MAAM;IACN,MAAM,SAAS,SAAS;IACxB,IAAI,SAAS;IACb,OAAO;GACR,EAAC;EACH;CACF;AAEH,QAAO,CAAC,WAAW,gBAAiB;AACrC;AAED,SAAgB,cAAcf,GAA8B;AAC1D,QACE,OAAO,MAAM,YACb,MAAM,QACN,aAAa,KACb,OAAO,EAAE,YAAY,cACrB,EAAE,SAAS,KAAK;AAEnB;AAED,SAAgB,mBAAmBgB,GAA4C;AAC7E,QAAO,EAAE,UAAU,KAAK;AACzB"}
|
package/dist/messages/tool.d.cts
CHANGED
|
@@ -166,7 +166,7 @@ type InvalidToolCall = {
|
|
|
166
166
|
declare function defaultToolCallParser(
|
|
167
167
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
168
168
|
rawToolCalls: Record<string, any>[]): [ToolCall[], InvalidToolCall[]];
|
|
169
|
-
declare function isToolMessage(x:
|
|
169
|
+
declare function isToolMessage(x: unknown): x is ToolMessage;
|
|
170
170
|
declare function isToolMessageChunk(x: BaseMessageChunk): x is ToolMessageChunk;
|
|
171
171
|
//#endregion
|
|
172
172
|
export { DirectToolOutput, InvalidToolCall, ToolCall, ToolCallChunk, ToolMessage, ToolMessageChunk, ToolMessageFields, ToolMessageFieldsWithToolCallId, defaultToolCallParser, isDirectToolOutput, isToolMessage, isToolMessageChunk };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.d.cts","names":["BaseMessage","BaseMessageChunk","BaseMessageFields","MessageType","MessageContent","ToolMessageFields","ToolMessageFieldsWithToolCallId","DirectToolOutput","isDirectToolOutput","ToolMessage","Record","ToolMessageChunk","ToolCall","ToolCallChunk","InvalidToolCall","defaultToolCallParser","isToolMessage","isToolMessageChunk"],"sources":["../../src/messages/tool.d.ts"],"sourcesContent":["import { BaseMessage, BaseMessageChunk, type BaseMessageFields, type MessageType, type MessageContent } from \"./base.js\";\nexport type ToolMessageFields = BaseMessageFields;\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 * 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 extends BaseMessage implements DirectToolOutput {\n content: MessageContent;\n static lc_name(): string;\n get lc_aliases(): Record<string, string>;\n lc_direct_tool_output: true;\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: ToolMessageFieldsWithToolCallId);\n constructor(fields: string | ToolMessageFields, tool_call_id: string, name?: string);\n _getType(): MessageType;\n static isInstance(message: BaseMessage): 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 extends BaseMessageChunk {\n content: MessageContent;\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: ToolMessageFieldsWithToolCallId);\n static lc_name(): string;\n _getType(): MessageType;\n concat(chunk: ToolMessageChunk): ToolMessageChunk;\n get _printableFields(): Record<string, unknown>;\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\n args: Record<string, any>;\n id?: string;\n type?: \"tool_call\";\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 args?: string;\n id?: string;\n index?: number;\n type?: \"tool_call_chunk\";\n};\nexport type InvalidToolCall = {\n name?: string;\n args?: string;\n id?: string;\n error?: string;\n type?: \"invalid_tool_call\";\n};\nexport declare function defaultToolCallParser(\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nrawToolCalls: Record<string, any>[]): [ToolCall[], InvalidToolCall[]];\nexport declare function isToolMessage(x:
|
|
1
|
+
{"version":3,"file":"tool.d.cts","names":["BaseMessage","BaseMessageChunk","BaseMessageFields","MessageType","MessageContent","ToolMessageFields","ToolMessageFieldsWithToolCallId","DirectToolOutput","isDirectToolOutput","ToolMessage","Record","ToolMessageChunk","ToolCall","ToolCallChunk","InvalidToolCall","defaultToolCallParser","isToolMessage","isToolMessageChunk"],"sources":["../../src/messages/tool.d.ts"],"sourcesContent":["import { BaseMessage, BaseMessageChunk, type BaseMessageFields, type MessageType, type MessageContent } from \"./base.js\";\nexport type ToolMessageFields = BaseMessageFields;\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 * 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 extends BaseMessage implements DirectToolOutput {\n content: MessageContent;\n static lc_name(): string;\n get lc_aliases(): Record<string, string>;\n lc_direct_tool_output: true;\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: ToolMessageFieldsWithToolCallId);\n constructor(fields: string | ToolMessageFields, tool_call_id: string, name?: string);\n _getType(): MessageType;\n static isInstance(message: BaseMessage): 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 extends BaseMessageChunk {\n content: MessageContent;\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: ToolMessageFieldsWithToolCallId);\n static lc_name(): string;\n _getType(): MessageType;\n concat(chunk: ToolMessageChunk): ToolMessageChunk;\n get _printableFields(): Record<string, unknown>;\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\n args: Record<string, any>;\n id?: string;\n type?: \"tool_call\";\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 args?: string;\n id?: string;\n index?: number;\n type?: \"tool_call_chunk\";\n};\nexport type InvalidToolCall = {\n name?: string;\n args?: string;\n id?: string;\n error?: string;\n type?: \"invalid_tool_call\";\n};\nexport declare function defaultToolCallParser(\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nrawToolCalls: Record<string, any>[]): [ToolCall[], InvalidToolCall[]];\nexport declare function isToolMessage(x: unknown): x is ToolMessage;\nexport declare function isToolMessageChunk(x: BaseMessageChunk): x is ToolMessageChunk;\n"],"mappings":";;;KACYK,iBAAAA,GAAoBH;UACfI,+BAAAA,SAAwCD;EAD7CA;AACZ;AAwBA;AAGA;AAIA;;;EAC2B;EAEC,QAiBJC,CAAAA,EAAAA,GAAAA;EAA+B,YACtBD,EAAAA,MAAAA;EAAiB;;;;EAGhB,MAxBOL,CAAAA,EAAAA,SAAAA,GAAAA,OAAAA;;AAAuC;AA8BhF;;;;;;AAoBqCW,UAzDpBJ,gBAAAA,CAyDoBI;EAAgB,SACzBD,qBAAAA,EAAAA,IAAAA;;AArBkC,iBAlCtCF,kBAAAA,CAkCsC,CAAA,EAAA,OAAA,CAAA,EAAA,CAAA,IAlCDD,gBAkCC;AA6B9D;AAyDA;AAOA;AAOwBQ,cAlIHN,WAAAA,SAAoBT,WAAAA,YAAuBO,gBAkInB,CAAA;EAAA,OAAA,EAjIhCH,cAiIgC;EAAA,OAE/BM,OAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAAM,IAAmBE,UAAAA,CAAAA,CAAAA,EAjIjBF,MAiIiBE,CAAAA,MAAAA,EAAAA,MAAAA,CAAAA;EAAQ,qBAAIE,EAAAA,IAAAA;EAAe;AAClE;AACA;;EAA0C,MAAIb,CAAAA,EAAAA,SAAAA,GAAAA,OAAAA;EAAgB,YAAQU,EAAAA,MAAAA;EAAgB;;;;;;;;;sBAlH9DL;+BACSD;cACjBF;6BACeH,yBAAyBS;0BAC5BC;;;;;;cAMPC,gBAAAA,SAAyBV,gBAAAA;WACjCG;;;;;;;;;;;;;;;;sBAgBWE;;cAERH;gBACEQ,mBAAmBA;0BACTD;;;;;;;;KAQhBE,QAAAA;;;QAGFF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAsDEG,aAAAA;;;;;;;KAOAC,eAAAA;;;;;;;iBAOYC,qBAAAA;;cAEVL,yBAAyBE,YAAYE;iBAC3BE,aAAAA,mBAAgCP;iBAChCQ,kBAAAA,IAAsBhB,wBAAwBU"}
|
package/dist/messages/tool.d.ts
CHANGED
|
@@ -166,7 +166,7 @@ type InvalidToolCall = {
|
|
|
166
166
|
declare function defaultToolCallParser(
|
|
167
167
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
168
168
|
rawToolCalls: Record<string, any>[]): [ToolCall[], InvalidToolCall[]];
|
|
169
|
-
declare function isToolMessage(x:
|
|
169
|
+
declare function isToolMessage(x: unknown): x is ToolMessage;
|
|
170
170
|
declare function isToolMessageChunk(x: BaseMessageChunk): x is ToolMessageChunk;
|
|
171
171
|
//#endregion
|
|
172
172
|
export { DirectToolOutput, InvalidToolCall, ToolCall, ToolCallChunk, ToolMessage, ToolMessageChunk, ToolMessageFields, ToolMessageFieldsWithToolCallId, defaultToolCallParser, isDirectToolOutput, isToolMessage, isToolMessageChunk };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.d.ts","names":["BaseMessage","BaseMessageChunk","BaseMessageFields","MessageType","MessageContent","ToolMessageFields","ToolMessageFieldsWithToolCallId","DirectToolOutput","isDirectToolOutput","ToolMessage","Record","ToolMessageChunk","ToolCall","ToolCallChunk","InvalidToolCall","defaultToolCallParser","isToolMessage","isToolMessageChunk"],"sources":["../../src/messages/tool.d.ts"],"sourcesContent":["import { BaseMessage, BaseMessageChunk, type BaseMessageFields, type MessageType, type MessageContent } from \"./base.js\";\nexport type ToolMessageFields = BaseMessageFields;\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 * 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 extends BaseMessage implements DirectToolOutput {\n content: MessageContent;\n static lc_name(): string;\n get lc_aliases(): Record<string, string>;\n lc_direct_tool_output: true;\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: ToolMessageFieldsWithToolCallId);\n constructor(fields: string | ToolMessageFields, tool_call_id: string, name?: string);\n _getType(): MessageType;\n static isInstance(message: BaseMessage): 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 extends BaseMessageChunk {\n content: MessageContent;\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: ToolMessageFieldsWithToolCallId);\n static lc_name(): string;\n _getType(): MessageType;\n concat(chunk: ToolMessageChunk): ToolMessageChunk;\n get _printableFields(): Record<string, unknown>;\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\n args: Record<string, any>;\n id?: string;\n type?: \"tool_call\";\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 args?: string;\n id?: string;\n index?: number;\n type?: \"tool_call_chunk\";\n};\nexport type InvalidToolCall = {\n name?: string;\n args?: string;\n id?: string;\n error?: string;\n type?: \"invalid_tool_call\";\n};\nexport declare function defaultToolCallParser(\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nrawToolCalls: Record<string, any>[]): [ToolCall[], InvalidToolCall[]];\nexport declare function isToolMessage(x:
|
|
1
|
+
{"version":3,"file":"tool.d.ts","names":["BaseMessage","BaseMessageChunk","BaseMessageFields","MessageType","MessageContent","ToolMessageFields","ToolMessageFieldsWithToolCallId","DirectToolOutput","isDirectToolOutput","ToolMessage","Record","ToolMessageChunk","ToolCall","ToolCallChunk","InvalidToolCall","defaultToolCallParser","isToolMessage","isToolMessageChunk"],"sources":["../../src/messages/tool.d.ts"],"sourcesContent":["import { BaseMessage, BaseMessageChunk, type BaseMessageFields, type MessageType, type MessageContent } from \"./base.js\";\nexport type ToolMessageFields = BaseMessageFields;\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 * 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 extends BaseMessage implements DirectToolOutput {\n content: MessageContent;\n static lc_name(): string;\n get lc_aliases(): Record<string, string>;\n lc_direct_tool_output: true;\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: ToolMessageFieldsWithToolCallId);\n constructor(fields: string | ToolMessageFields, tool_call_id: string, name?: string);\n _getType(): MessageType;\n static isInstance(message: BaseMessage): 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 extends BaseMessageChunk {\n content: MessageContent;\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: ToolMessageFieldsWithToolCallId);\n static lc_name(): string;\n _getType(): MessageType;\n concat(chunk: ToolMessageChunk): ToolMessageChunk;\n get _printableFields(): Record<string, unknown>;\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\n args: Record<string, any>;\n id?: string;\n type?: \"tool_call\";\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 args?: string;\n id?: string;\n index?: number;\n type?: \"tool_call_chunk\";\n};\nexport type InvalidToolCall = {\n name?: string;\n args?: string;\n id?: string;\n error?: string;\n type?: \"invalid_tool_call\";\n};\nexport declare function defaultToolCallParser(\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nrawToolCalls: Record<string, any>[]): [ToolCall[], InvalidToolCall[]];\nexport declare function isToolMessage(x: unknown): x is ToolMessage;\nexport declare function isToolMessageChunk(x: BaseMessageChunk): x is ToolMessageChunk;\n"],"mappings":";;;KACYK,iBAAAA,GAAoBH;UACfI,+BAAAA,SAAwCD;EAD7CA;AACZ;AAwBA;AAGA;AAIA;;;EAC2B;EAEC,QAiBJC,CAAAA,EAAAA,GAAAA;EAA+B,YACtBD,EAAAA,MAAAA;EAAiB;;;;EAGhB,MAxBOL,CAAAA,EAAAA,SAAAA,GAAAA,OAAAA;;AAAuC;AA8BhF;;;;;;AAoBqCW,UAzDpBJ,gBAAAA,CAyDoBI;EAAgB,SACzBD,qBAAAA,EAAAA,IAAAA;;AArBkC,iBAlCtCF,kBAAAA,CAkCsC,CAAA,EAAA,OAAA,CAAA,EAAA,CAAA,IAlCDD,gBAkCC;AA6B9D;AAyDA;AAOA;AAOwBQ,cAlIHN,WAAAA,SAAoBT,WAAAA,YAAuBO,gBAkInB,CAAA;EAAA,OAAA,EAjIhCH,cAiIgC;EAAA,OAE/BM,OAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAAM,IAAmBE,UAAAA,CAAAA,CAAAA,EAjIjBF,MAiIiBE,CAAAA,MAAAA,EAAAA,MAAAA,CAAAA;EAAQ,qBAAIE,EAAAA,IAAAA;EAAe;AAClE;AACA;;EAA0C,MAAIb,CAAAA,EAAAA,SAAAA,GAAAA,OAAAA;EAAgB,YAAQU,EAAAA,MAAAA;EAAgB;;;;;;;;;sBAlH9DL;+BACSD;cACjBF;6BACeH,yBAAyBS;0BAC5BC;;;;;;cAMPC,gBAAAA,SAAyBV,gBAAAA;WACjCG;;;;;;;;;;;;;;;;sBAgBWE;;cAERH;gBACEQ,mBAAmBA;0BACTD;;;;;;;;KAQhBE,QAAAA;;;QAGFF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAsDEG,aAAAA;;;;;;;KAOAC,eAAAA;;;;;;;iBAOYC,qBAAAA;;cAEVL,yBAAyBE,YAAYE;iBAC3BE,aAAAA,mBAAgCP;iBAChCQ,kBAAAA,IAAsBhB,wBAAwBU"}
|
package/dist/messages/tool.js
CHANGED
|
@@ -140,7 +140,7 @@ function defaultToolCallParser(rawToolCalls) {
|
|
|
140
140
|
return [toolCalls, invalidToolCalls];
|
|
141
141
|
}
|
|
142
142
|
function isToolMessage(x) {
|
|
143
|
-
return x.
|
|
143
|
+
return typeof x === "object" && x !== null && "getType" in x && typeof x.getType === "function" && x.getType() === "tool";
|
|
144
144
|
}
|
|
145
145
|
function isToolMessageChunk(x) {
|
|
146
146
|
return x._getType() === "tool";
|
|
@@ -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,mBAA4C;AACvD,SAAO;GACL,GAAG,MAAM;GACT,cAAc,KAAK;GACnB,UAAU,KAAK;EAChB;CACF;AACF;;;;;AAMD,IAAa,mBAAb,MAAa,yBAAyB,iBAAiB;CAGrD;;;;;CAMA;;;;;;;;CAUA;CAEA,YAAYC,QAAyC;EACnD,MAAM,OAAO;EACb,KAAK,eAAe,OAAO;EAC3B,KAAK,WAAW,OAAO;EACvB,KAAK,SAAS,OAAO;CACtB;CAED,OAAO,UAAU;AACf,SAAO;CACR;CAED,WAAwB;AACtB,SAAO;CACR;CAED,OAAOC,OAAyB;AAC9B,SAAO,IAAI,iBAAiB;GAC1B,SAAS,aAAa,KAAK,SAAS,MAAM,QAAQ;GAClD,mBAAmB,YACjB,KAAK,mBACL,MAAM,kBACP;GACD,mBAAmB,YACjB,KAAK,mBACL,MAAM,kBACP;GACD,UAAU,UAAU,KAAK,UAAU,MAAM,SAAS;GAClD,cAAc,KAAK;GACnB,IAAI,KAAK,MAAM,MAAM;GACrB,QAAQ,aAAa,KAAK,QAAQ,MAAM,OAAO;EAChD;CACF;CAED,IAAa,mBAA4C;AACvD,SAAO;GACL,GAAG,MAAM;GACT,cAAc,KAAK;GACnB,UAAU,KAAK;EAChB;CACF;AACF;AAyFD,SAAgB,sBAEdC,cACiC;CACjC,MAAMC,YAAwB,CAAE;CAChC,MAAMC,mBAAsC,CAAE;AAC9C,MAAK,MAAM,YAAY,aACrB,KAAI,CAAC,SAAS,SACZ;MACK;EACL,MAAM,eAAe,SAAS,SAAS;AACvC,MAAI;GACF,MAAM,eAAe,KAAK,MAAM,SAAS,SAAS,UAAU;GAC5D,MAAM,SAAS;IACb,MAAM,gBAAgB;IACtB,MAAM,gBAAgB,CAAE;IACxB,IAAI,SAAS;GACd;GACD,UAAU,KAAK,OAAO;EACvB,SAAQ,OAAO;GACd,iBAAiB,KAAK;IACpB,MAAM;IACN,MAAM,SAAS,SAAS;IACxB,IAAI,SAAS;IACb,OAAO;GACR,EAAC;EACH;CACF;AAEH,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: string | ToolMessageFieldsWithToolCallId","tool_call_id?: string","name?: string","message: BaseMessage","fields: ToolMessageFieldsWithToolCallId","chunk: ToolMessageChunk","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 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: 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\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,mBAA4C;AACvD,SAAO;GACL,GAAG,MAAM;GACT,cAAc,KAAK;GACnB,UAAU,KAAK;EAChB;CACF;AACF;;;;;AAMD,IAAa,mBAAb,MAAa,yBAAyB,iBAAiB;CAGrD;;;;;CAMA;;;;;;;;CAUA;CAEA,YAAYC,QAAyC;EACnD,MAAM,OAAO;EACb,KAAK,eAAe,OAAO;EAC3B,KAAK,WAAW,OAAO;EACvB,KAAK,SAAS,OAAO;CACtB;CAED,OAAO,UAAU;AACf,SAAO;CACR;CAED,WAAwB;AACtB,SAAO;CACR;CAED,OAAOC,OAAyB;AAC9B,SAAO,IAAI,iBAAiB;GAC1B,SAAS,aAAa,KAAK,SAAS,MAAM,QAAQ;GAClD,mBAAmB,YACjB,KAAK,mBACL,MAAM,kBACP;GACD,mBAAmB,YACjB,KAAK,mBACL,MAAM,kBACP;GACD,UAAU,UAAU,KAAK,UAAU,MAAM,SAAS;GAClD,cAAc,KAAK;GACnB,IAAI,KAAK,MAAM,MAAM;GACrB,QAAQ,aAAa,KAAK,QAAQ,MAAM,OAAO;EAChD;CACF;CAED,IAAa,mBAA4C;AACvD,SAAO;GACL,GAAG,MAAM;GACT,cAAc,KAAK;GACnB,UAAU,KAAK;EAChB;CACF;AACF;AAyFD,SAAgB,sBAEdC,cACiC;CACjC,MAAMC,YAAwB,CAAE;CAChC,MAAMC,mBAAsC,CAAE;AAC9C,MAAK,MAAM,YAAY,aACrB,KAAI,CAAC,SAAS,SACZ;MACK;EACL,MAAM,eAAe,SAAS,SAAS;AACvC,MAAI;GACF,MAAM,eAAe,KAAK,MAAM,SAAS,SAAS,UAAU;GAC5D,MAAM,SAAS;IACb,MAAM,gBAAgB;IACtB,MAAM,gBAAgB,CAAE;IACxB,IAAI,SAAS;GACd;GACD,UAAU,KAAK,OAAO;EACvB,SAAQ,OAAO;GACd,iBAAiB,KAAK;IACpB,MAAM;IACN,MAAM,SAAS,SAAS;IACxB,IAAI,SAAS;IACb,OAAO;GACR,EAAC;EACH;CACF;AAEH,QAAO,CAAC,WAAW,gBAAiB;AACrC;AAED,SAAgB,cAAcT,GAA8B;AAC1D,QACE,OAAO,MAAM,YACb,MAAM,QACN,aAAa,KACb,OAAO,EAAE,YAAY,cACrB,EAAE,SAAS,KAAK;AAEnB;AAED,SAAgB,mBAAmBU,GAA4C;AAC7E,QAAO,EAAE,UAAU,KAAK;AACzB"}
|
package/dist/runnables/base.cjs
CHANGED
|
@@ -987,7 +987,7 @@ var RunnableSequence = class RunnableSequence extends Runnable {
|
|
|
987
987
|
const promise = step.invoke(nextStepInput, require_config.patchConfig(config, { callbacks: runManager?.getChild(this.omitSequenceTags ? void 0 : `seq:step:${i + 1}`) }));
|
|
988
988
|
nextStepInput = await require_signal.raceWithSignal(promise, options?.signal);
|
|
989
989
|
}
|
|
990
|
-
if (options?.signal?.aborted) throw
|
|
990
|
+
if (options?.signal?.aborted) throw require_signal.getAbortSignalError(options.signal);
|
|
991
991
|
finalOutput = await this.last.invoke(nextStepInput, require_config.patchConfig(config, { callbacks: runManager?.getChild(this.omitSequenceTags ? void 0 : `seq:step:${this.steps.length}`) }));
|
|
992
992
|
} catch (e) {
|
|
993
993
|
await runManager?.handleChainError(e);
|