UNPKG

@langchain/core

Version:
1 lines 9.17 kB
{"version":3,"file":"tool.d.ts","names":["BaseMessage","BaseMessageChunk","BaseMessageFields","$InferMessageContent","MessageStructure","ToolMessageFields","TStructure","Record","DirectToolOutput","isDirectToolOutput","ToolMessage","T","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 /**\n * Type guard to check if an object is a ToolMessage.\n * Preserves the MessageStructure type parameter when called with a typed BaseMessage.\n * @overload When called with a typed BaseMessage, preserves the TStructure type\n */\n static isInstance<T extends MessageStructure>(message: BaseMessage<T>): message is BaseMessage<T> & ToolMessage<T>;\n /**\n * Type guard to check if an object is a ToolMessage.\n * @overload When called with unknown, returns base ToolMessage type\n */\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,C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