@langchain/core
Version:
Core LangChain.js abstractions and schemas
1 lines • 8.45 kB
Source Map (JSON)
{"version":3,"file":"tool.d.ts","names":["BaseMessage","BaseMessageChunk","BaseMessageFields","$InferMessageContent","MessageStructure","ToolMessageFields","TStructure","Record","DirectToolOutput","isDirectToolOutput","ToolMessage","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 artifact?: any;\n tool_call_id: string;\n status?: \"success\" | \"error\";\n metadata?: Record<string, unknown>;\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 metadata?: Record<string, unknown>;\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 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 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, any> = Record<string, any>> {\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(rawToolCalls: 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//# sourceMappingURL=tool.d.ts.map"],"mappings":";;;;UAEiBK,qCAAqCD,mBAAmBA,0BAA0BF,kBAAkBI;;AAArH;;;;;;EAAoH,QAAA,CAAA,EAAA,GAAA;EAoBnGE,YAAAA,EAAAA,MAAgB;EAGTC,MAAAA,CAAAA,EAAAA,SAAAA,GAAkB,OAAA;EAIrBC,QAAAA,CAAAA,EAhBNH,MAgBiB,CAAA,MAAAD,EAAAA,OAAAA,CAAAA;;;;;;;;;AAqBUA,UA5BzBE,gBAAAA,CA4ByBF;EAAlBD,SAAAA,qBAAAA,EAAAA,IAAAA;;AAEIE,iBA3BJE,kBAAAA,CA2BIF,CAAAA,EAAAA,OAAAA,CAAAA,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