40044f29bb8d33a8e008a69bbaa00d18afb8e47e5bd267e44a208d53e3fa11cf.json 16 KB

1
  1. {"ast":null,"code":"import { BaseMessage, BaseMessageChunk, mergeContent, _mergeDicts, _mergeObj, _mergeStatus } from \"./base.js\";\n/**\n * Represents a tool message in a conversation.\n */\nexport class ToolMessage extends BaseMessage {\n static lc_name() {\n return \"ToolMessage\";\n }\n get lc_aliases() {\n // exclude snake case conversion to pascal case\n return {\n tool_call_id: \"tool_call_id\"\n };\n }\n constructor(fields, tool_call_id, name) {\n if (typeof fields === \"string\") {\n // eslint-disable-next-line no-param-reassign, @typescript-eslint/no-non-null-assertion\n fields = {\n content: fields,\n name,\n tool_call_id: tool_call_id\n };\n }\n super(fields);\n /**\n * Status of the tool invocation.\n * @version 0.2.19\n */\n Object.defineProperty(this, \"status\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n Object.defineProperty(this, \"tool_call_id\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\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 Object.defineProperty(this, \"artifact\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n this.tool_call_id = fields.tool_call_id;\n this.artifact = fields.artifact;\n this.status = fields.status;\n }\n _getType() {\n return \"tool\";\n }\n static isInstance(message) {\n return message._getType() === \"tool\";\n }\n get _printableFields() {\n return {\n ...super._printableFields,\n tool_call_id: this.tool_call_id,\n artifact: this.artifact\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 constructor(fields) {\n super(fields);\n Object.defineProperty(this, \"tool_call_id\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n /**\n * Status of the tool invocation.\n * @version 0.2.19\n */\n Object.defineProperty(this, \"status\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\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 Object.defineProperty(this, \"artifact\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n this.tool_call_id = fields.tool_call_id;\n this.artifact = fields.artifact;\n this.status = fields.status;\n }\n static lc_name() {\n return \"ToolMessageChunk\";\n }\n _getType() {\n return \"tool\";\n }\n concat(chunk) {\n var _this$id;\n return new ToolMessageChunk({\n content: mergeContent(this.content, chunk.content),\n additional_kwargs: _mergeDicts(this.additional_kwargs, chunk.additional_kwargs),\n response_metadata: _mergeDicts(this.response_metadata, chunk.response_metadata),\n artifact: _mergeObj(this.artifact, chunk.artifact),\n tool_call_id: this.tool_call_id,\n id: (_this$id = this.id) !== null && _this$id !== void 0 ? _this$id : chunk.id,\n status: _mergeStatus(this.status, chunk.status)\n });\n }\n get _printableFields() {\n return {\n ...super._printableFields,\n tool_call_id: this.tool_call_id,\n artifact: this.artifact\n };\n }\n}\nexport function defaultToolCallParser(\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nrawToolCalls) {\n const toolCalls = [];\n const invalidToolCalls = [];\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}\nexport function isToolMessage(x) {\n return x._getType() === \"tool\";\n}\nexport function isToolMessageChunk(x) {\n return x._getType() === \"tool\";\n}","map":{"version":3,"names":["BaseMessage","BaseMessageChunk","mergeContent","_mergeDicts","_mergeObj","_mergeStatus","ToolMessage","lc_name","lc_aliases","tool_call_id","constructor","fields","name","content","Object","defineProperty","enumerable","configurable","writable","value","artifact","status","_getType","isInstance","message","_printableFields","ToolMessageChunk","concat","chunk","_this$id","additional_kwargs","response_metadata","id","defaultToolCallParser","rawToolCalls","toolCalls","invalidToolCalls","toolCall","function","functionName","functionArgs","JSON","parse","arguments","parsed","args","push","error","isToolMessage","x","isToolMessageChunk"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@langchain/core/dist/messages/tool.js"],"sourcesContent":["import { BaseMessage, BaseMessageChunk, mergeContent, _mergeDicts, _mergeObj, _mergeStatus, } from \"./base.js\";\n/**\n * Represents a tool message in a conversation.\n */\nexport class ToolMessage extends BaseMessage {\n static lc_name() {\n return \"ToolMessage\";\n }\n get lc_aliases() {\n // exclude snake case conversion to pascal case\n return { tool_call_id: \"tool_call_id\" };\n }\n constructor(fields, tool_call_id, name) {\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 /**\n * Status of the tool invocation.\n * @version 0.2.19\n */\n Object.defineProperty(this, \"status\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n Object.defineProperty(this, \"tool_call_id\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\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 Object.defineProperty(this, \"artifact\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n this.tool_call_id = fields.tool_call_id;\n this.artifact = fields.artifact;\n this.status = fields.status;\n }\n _getType() {\n return \"tool\";\n }\n static isInstance(message) {\n return message._getType() === \"tool\";\n }\n get _printableFields() {\n return {\n ...super._printableFields,\n tool_call_id: this.tool_call_id,\n artifact: this.artifact,\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 constructor(fields) {\n super(fields);\n Object.defineProperty(this, \"tool_call_id\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n /**\n * Status of the tool invocation.\n * @version 0.2.19\n */\n Object.defineProperty(this, \"status\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\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 Object.defineProperty(this, \"artifact\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n this.tool_call_id = fields.tool_call_id;\n this.artifact = fields.artifact;\n this.status = fields.status;\n }\n static lc_name() {\n return \"ToolMessageChunk\";\n }\n _getType() {\n return \"tool\";\n }\n concat(chunk) {\n return new ToolMessageChunk({\n content: mergeContent(this.content, chunk.content),\n additional_kwargs: _mergeDicts(this.additional_kwargs, chunk.additional_kwargs),\n response_metadata: _mergeDicts(this.response_metadata, chunk.response_metadata),\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 get _printableFields() {\n return {\n ...super._printableFields,\n tool_call_id: this.tool_call_id,\n artifact: this.artifact,\n };\n }\n}\nexport function defaultToolCallParser(\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nrawToolCalls) {\n const toolCalls = [];\n const invalidToolCalls = [];\n for (const toolCall of rawToolCalls) {\n if (!toolCall.function) {\n continue;\n }\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 }\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}\nexport function isToolMessage(x) {\n return x._getType() === \"tool\";\n}\nexport function isToolMessageChunk(x) {\n return x._getType() === \"tool\";\n}\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,gBAAgB,EAAEC,YAAY,EAAEC,WAAW,EAAEC,SAAS,EAAEC,YAAY,QAAS,WAAW;AAC9G;AACA;AACA;AACA,OAAO,MAAMC,WAAW,SAASN,WAAW,CAAC;EACzC,OAAOO,OAAOA,CAAA,EAAG;IACb,OAAO,aAAa;EACxB;EACA,IAAIC,UAAUA,CAAA,EAAG;IACb;IACA,OAAO;MAAEC,YAAY,EAAE;IAAe,CAAC;EAC3C;EACAC,WAAWA,CAACC,MAAM,EAAEF,YAAY,EAAEG,IAAI,EAAE;IACpC,IAAI,OAAOD,MAAM,KAAK,QAAQ,EAAE;MAC5B;MACAA,MAAM,GAAG;QAAEE,OAAO,EAAEF,MAAM;QAAEC,IAAI;QAAEH,YAAY,EAAEA;MAAa,CAAC;IAClE;IACA,KAAK,CAACE,MAAM,CAAC;IACb;AACR;AACA;AACA;IACQG,MAAM,CAACC,cAAc,CAAC,IAAI,EAAE,QAAQ,EAAE;MAClCC,UAAU,EAAE,IAAI;MAChBC,YAAY,EAAE,IAAI;MAClBC,QAAQ,EAAE,IAAI;MACdC,KAAK,EAAE,KAAK;IAChB,CAAC,CAAC;IACFL,MAAM,CAACC,cAAc,CAAC,IAAI,EAAE,cAAc,EAAE;MACxCC,UAAU,EAAE,IAAI;MAChBC,YAAY,EAAE,IAAI;MAClBC,QAAQ,EAAE,IAAI;MACdC,KAAK,EAAE,KAAK;IAChB,CAAC,CAAC;IACF;AACR;A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