@langchain/core 1.1.34 → 1.1.36
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/CHANGELOG.md +20 -0
- package/dist/callbacks/dispatch/index.d.ts +1 -0
- package/dist/callbacks/dispatch/index.d.ts.map +1 -1
- package/dist/callbacks/dispatch/web.d.ts +1 -0
- package/dist/callbacks/dispatch/web.d.ts.map +1 -1
- package/dist/language_models/base.cjs +1 -1
- package/dist/language_models/base.cjs.map +1 -1
- package/dist/language_models/base.d.cts +5 -7
- package/dist/language_models/base.d.cts.map +1 -1
- package/dist/language_models/base.d.ts +5 -7
- package/dist/language_models/base.d.ts.map +1 -1
- package/dist/language_models/base.js +1 -1
- package/dist/language_models/base.js.map +1 -1
- package/dist/language_models/chat_models.cjs +14 -3
- package/dist/language_models/chat_models.cjs.map +1 -1
- package/dist/language_models/chat_models.d.cts +12 -6
- package/dist/language_models/chat_models.d.cts.map +1 -1
- package/dist/language_models/chat_models.d.ts +12 -7
- package/dist/language_models/chat_models.d.ts.map +1 -1
- package/dist/language_models/chat_models.js +14 -3
- package/dist/language_models/chat_models.js.map +1 -1
- package/dist/language_models/llms.d.ts.map +1 -1
- package/dist/language_models/structured_output.d.ts.map +1 -1
- package/dist/messages/base.cjs +36 -12
- package/dist/messages/base.cjs.map +1 -1
- package/dist/messages/base.d.cts.map +1 -1
- package/dist/messages/base.d.ts.map +1 -1
- package/dist/messages/base.js +36 -12
- package/dist/messages/base.js.map +1 -1
- package/dist/messages/system.cjs +8 -4
- package/dist/messages/system.cjs.map +1 -1
- package/dist/messages/system.d.cts.map +1 -1
- package/dist/messages/system.d.ts.map +1 -1
- package/dist/messages/system.js +8 -4
- package/dist/messages/system.js.map +1 -1
- package/dist/output_parsers/base.d.ts.map +1 -1
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.cjs.map +1 -1
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.cts +3 -5
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.cts.map +1 -1
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.ts +3 -5
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.ts.map +1 -1
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.js.map +1 -1
- package/dist/prompts/structured.d.ts.map +1 -1
- package/dist/retrievers/index.d.ts.map +1 -1
- package/dist/runnables/branch.d.ts.map +1 -1
- package/dist/runnables/history.d.ts.map +1 -1
- package/dist/runnables/passthrough.d.ts.map +1 -1
- package/dist/runnables/router.d.ts.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/types.cjs.map +1 -1
- package/dist/tools/types.d.cts +3 -4
- package/dist/tools/types.d.cts.map +1 -1
- package/dist/tools/types.d.ts +3 -4
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js.map +1 -1
- package/dist/utils/json_schema.cjs.map +1 -1
- package/dist/utils/json_schema.d.cts +1 -1
- package/dist/utils/json_schema.d.cts.map +1 -1
- package/dist/utils/json_schema.d.ts.map +1 -1
- package/dist/utils/json_schema.js.map +1 -1
- package/dist/utils/types/index.d.cts +2 -2
- package/dist/utils/types/index.d.ts +2 -2
- package/dist/utils/types/zod.cjs +1 -1
- package/dist/utils/types/zod.cjs.map +1 -1
- package/dist/utils/types/zod.d.cts +141 -35
- package/dist/utils/types/zod.d.cts.map +1 -1
- package/dist/utils/types/zod.d.ts +141 -35
- package/dist/utils/types/zod.d.ts.map +1 -1
- package/dist/utils/types/zod.js +1 -1
- package/dist/utils/types/zod.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","names":[],"sources":["../../src/messages/base.ts"],"sourcesContent":["import { Serializable, SerializedConstructor } from \"../load/serializable.js\";\nimport { ContentBlock } from \"./content/index.js\";\nimport { isDataContentBlock } from \"./content/data.js\";\nimport { convertToV1FromAnthropicInput } from \"./block_translators/anthropic.js\";\nimport { convertToV1FromDataContent } from \"./block_translators/data.js\";\nimport { convertToV1FromChatCompletionsInput } from \"./block_translators/openai.js\";\nimport {\n $InferMessageContent,\n $InferResponseMetadata,\n MessageStructure,\n MessageType,\n isMessage,\n Message,\n} from \"./message.js\";\nimport {\n convertToFormattedString,\n type MessageStringFormat,\n} from \"./format.js\";\n\n/** @internal */\nconst MESSAGE_SYMBOL: symbol = Symbol.for(\"langchain.message\");\n\nexport interface StoredMessageData {\n content: string;\n role: string | undefined;\n name: string | undefined;\n tool_call_id: string | undefined;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n additional_kwargs?: Record<string, any>;\n /** Response metadata. For example: response headers, logprobs, token counts, model name. */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n response_metadata?: Record<string, any>;\n id?: string;\n}\n\nexport interface StoredMessage {\n type: string;\n data: StoredMessageData;\n}\n\nexport interface StoredGeneration {\n text: string;\n message?: StoredMessage;\n}\n\nexport interface StoredMessageV1 {\n type: string;\n role: string | undefined;\n text: string;\n}\n\nexport type MessageContent = string | Array<ContentBlock>;\n\nexport interface FunctionCall {\n /**\n * The arguments to call the function with, as generated by the model in JSON\n * format. Note that the model does not always generate valid JSON, and may\n * hallucinate parameters not defined by your function schema. Validate the\n * arguments in your code before calling your function.\n */\n arguments: string;\n\n /**\n * The name of the function to call.\n */\n name: string;\n}\n\nexport type BaseMessageFields<\n TStructure extends MessageStructure = MessageStructure,\n TRole extends MessageType = MessageType,\n> = Pick<Message, \"id\" | \"name\"> & {\n content?: $InferMessageContent<TStructure, TRole>;\n contentBlocks?: Array<ContentBlock.Standard>;\n /** @deprecated */\n additional_kwargs?: {\n /**\n * @deprecated Use \"tool_calls\" field on AIMessages instead\n */\n function_call?: FunctionCall;\n /**\n * @deprecated Use \"tool_calls\" field on AIMessages instead\n */\n tool_calls?: OpenAIToolCall[];\n [key: string]: unknown;\n };\n response_metadata?: Partial<$InferResponseMetadata<TStructure, TRole>>;\n};\n\nexport function mergeContent(\n firstContent: MessageContent,\n secondContent: MessageContent\n): MessageContent {\n // If first content is a string\n if (typeof firstContent === \"string\") {\n if (firstContent === \"\") {\n return secondContent;\n }\n if (typeof secondContent === \"string\") {\n return firstContent + secondContent;\n } else if (Array.isArray(secondContent) && secondContent.length === 0) {\n return firstContent;\n } else if (\n Array.isArray(secondContent) &&\n secondContent.some((c) => isDataContentBlock(c))\n ) {\n return [\n {\n type: \"text\",\n source_type: \"text\",\n text: firstContent,\n },\n ...secondContent,\n ];\n } else {\n return [{ type: \"text\", text: firstContent }, ...secondContent];\n }\n // If both are arrays\n } else if (Array.isArray(secondContent)) {\n return (\n _mergeLists(firstContent, secondContent) ?? [\n ...firstContent,\n ...secondContent,\n ]\n );\n } else {\n if (secondContent === \"\") {\n return firstContent;\n } else if (\n Array.isArray(firstContent) &&\n firstContent.some((c) => isDataContentBlock(c))\n ) {\n return [\n ...firstContent,\n {\n type: \"file\",\n source_type: \"text\",\n text: secondContent,\n },\n ];\n } else {\n return [...firstContent, { type: \"text\", text: secondContent }];\n }\n }\n}\n\n/**\n * 'Merge' two statuses. If either value passed is 'error', it will return 'error'. Else\n * it will return 'success'.\n *\n * @param {\"success\" | \"error\" | undefined} left The existing value to 'merge' with the new value.\n * @param {\"success\" | \"error\" | undefined} right The new value to 'merge' with the existing value\n * @returns {\"success\" | \"error\"} The 'merged' value.\n */\nexport function _mergeStatus(\n left?: \"success\" | \"error\",\n right?: \"success\" | \"error\"\n): \"success\" | \"error\" | undefined {\n if (left === \"error\" || right === \"error\") {\n return \"error\";\n }\n return \"success\";\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction stringifyWithDepthLimit(obj: any, depthLimit: number): string {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n function helper(obj: any, currentDepth: number): any {\n if (typeof obj !== \"object\" || obj === null || obj === undefined) {\n return obj;\n }\n if (currentDepth >= depthLimit) {\n if (Array.isArray(obj)) {\n return \"[Array]\";\n }\n return \"[Object]\";\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item) => helper(item, currentDepth + 1));\n }\n\n const result: Record<string, unknown> = {};\n for (const key of Object.keys(obj)) {\n result[key] = helper(obj[key], currentDepth + 1);\n }\n return result;\n }\n\n return JSON.stringify(helper(obj, 0), null, 2);\n}\n\n/**\n * Base class for all types of messages in a conversation. It includes\n * properties like `content`, `name`, and `additional_kwargs`. It also\n * includes methods like `toDict()` and `_getType()`.\n */\nexport abstract class BaseMessage<\n TStructure extends MessageStructure = MessageStructure,\n TRole extends MessageType = MessageType,\n>\n extends Serializable\n implements Message<TStructure, TRole>\n{\n lc_namespace = [\"langchain_core\", \"messages\"];\n\n lc_serializable = true;\n\n get lc_aliases(): Record<string, string> {\n // exclude snake case conversion to pascal case\n return {\n additional_kwargs: \"additional_kwargs\",\n response_metadata: \"response_metadata\",\n };\n }\n\n readonly [MESSAGE_SYMBOL] = true as const;\n\n abstract readonly type: TRole;\n\n id?: string;\n\n /** @inheritdoc */\n name?: string;\n\n content: $InferMessageContent<TStructure, TRole>;\n\n additional_kwargs: NonNullable<\n BaseMessageFields<TStructure, TRole>[\"additional_kwargs\"]\n >;\n\n response_metadata: NonNullable<\n BaseMessageFields<TStructure, TRole>[\"response_metadata\"]\n >;\n\n /**\n * @deprecated Use .getType() instead or import the proper typeguard.\n * For example:\n *\n * ```ts\n * import { isAIMessage } from \"@langchain/core/messages\";\n *\n * const message = new AIMessage(\"Hello!\");\n * isAIMessage(message); // true\n * ```\n */\n _getType(): MessageType {\n return this.type;\n }\n\n /**\n * @deprecated Use .type instead\n * The type of the message.\n */\n getType(): MessageType {\n return this._getType();\n }\n\n constructor(\n arg:\n | $InferMessageContent<TStructure, TRole>\n | BaseMessageFields<TStructure, TRole>\n ) {\n const fields: BaseMessageFields<TStructure, TRole> =\n typeof arg === \"string\" || Array.isArray(arg)\n ? ({ content: arg } as BaseMessageFields<TStructure, TRole>)\n : arg;\n if (!fields.additional_kwargs) {\n fields.additional_kwargs = {};\n }\n if (!fields.response_metadata) {\n fields.response_metadata = {};\n }\n super(fields);\n this.name = fields.name;\n if (fields.content === undefined && fields.contentBlocks !== undefined) {\n this.content = fields.contentBlocks as $InferMessageContent<\n TStructure,\n TRole\n >;\n this.response_metadata = {\n output_version: \"v1\",\n ...fields.response_metadata,\n };\n } else if (fields.content !== undefined) {\n this.content = fields.content ?? [];\n this.response_metadata = fields.response_metadata;\n } else {\n this.content = [] as $InferMessageContent<TStructure, TRole>;\n this.response_metadata = fields.response_metadata;\n }\n this.additional_kwargs = fields.additional_kwargs;\n this.id = fields.id;\n }\n\n /** Get text content of the message. */\n get text(): string {\n if (typeof this.content === \"string\") {\n return this.content;\n }\n if (!Array.isArray(this.content)) return \"\";\n return this.content\n .map((c) => {\n if (typeof c === \"string\") return c;\n if (c.type === \"text\") return c.text;\n return \"\";\n })\n .join(\"\");\n }\n\n get contentBlocks(): Array<ContentBlock.Standard> {\n const blocks: Array<ContentBlock> =\n typeof this.content === \"string\"\n ? [{ type: \"text\", text: this.content }]\n : this.content;\n const parsingSteps = [\n convertToV1FromDataContent,\n convertToV1FromChatCompletionsInput,\n convertToV1FromAnthropicInput,\n ];\n const parsedBlocks = parsingSteps.reduce(\n (blocks, step) => step(blocks),\n blocks\n );\n return parsedBlocks as Array<ContentBlock.Standard>;\n }\n\n toDict(): StoredMessage {\n return {\n type: this.getType(),\n data: (this.toJSON() as SerializedConstructor)\n .kwargs as StoredMessageData,\n };\n }\n\n static lc_name() {\n return \"BaseMessage\";\n }\n\n // Can't be protected for silly reasons\n get _printableFields(): Record<string, unknown> {\n return {\n id: this.id,\n content: this.content,\n name: this.name,\n additional_kwargs: this.additional_kwargs,\n response_metadata: this.response_metadata,\n };\n }\n\n static isInstance(obj: unknown): obj is BaseMessage {\n return (\n typeof obj === \"object\" &&\n obj !== null &&\n MESSAGE_SYMBOL in obj &&\n (obj as Record<symbol, unknown>)[MESSAGE_SYMBOL] === true &&\n isMessage(obj)\n );\n }\n\n // this private method is used to update the ID for the runtime\n // value as well as in lc_kwargs for serialisation\n _updateId(value: string | undefined) {\n this.id = value;\n\n // lc_attributes wouldn't work here, because jest compares the\n // whole object\n this.lc_kwargs.id = value;\n }\n\n get [Symbol.toStringTag]() {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (this.constructor as any).lc_name();\n }\n\n // Override the default behavior of console.log\n [Symbol.for(\"nodejs.util.inspect.custom\")](depth: number | null) {\n if (depth === null) {\n return this;\n }\n const printable = stringifyWithDepthLimit(\n this._printableFields,\n Math.max(4, depth)\n );\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return `${(this.constructor as any).lc_name()} ${printable}`;\n }\n\n toFormattedString(format: MessageStringFormat = \"pretty\"): string {\n return convertToFormattedString(this, format);\n }\n}\n\n/**\n * @deprecated Use \"tool_calls\" field on AIMessages instead\n */\nexport type OpenAIToolCall = {\n /**\n * The ID of the tool call.\n */\n id: string;\n\n /**\n * The function that the model called.\n */\n function: FunctionCall;\n\n /**\n * The type of the tool. Currently, only `function` is supported.\n */\n type: \"function\";\n\n index?: number;\n};\n\nexport function isOpenAIToolCallArray(\n value?: unknown\n): value is OpenAIToolCall[] {\n return (\n Array.isArray(value) &&\n value.every((v) => typeof (v as OpenAIToolCall).index === \"number\")\n );\n}\n\n/**\n * Default keys that should be preserved (not merged) when concatenating message chunks.\n * These are identification and timestamp fields that shouldn't be summed or concatenated.\n */\nexport const DEFAULT_MERGE_IGNORE_KEYS: readonly string[] = [\n \"index\", // Used for identification in tool calls, not accumulation\n \"created\", // Timestamp field\n \"timestamp\", // Timestamp field\n] as const;\n\n/**\n * Options for controlling merge behavior in `_mergeDicts`.\n */\nexport interface MergeDictsOptions {\n /**\n * Keys to ignore during merging. When a key is in this list:\n * - For numeric values: the original value is preserved (not summed)\n * - For string values: the original value is preserved (not concatenated)\n *\n * Defaults to `DEFAULT_MERGE_IGNORE_KEYS` which includes 'index', 'created', 'timestamp'.\n *\n * @example\n * // Extend defaults with custom keys\n * { ignoreKeys: [...DEFAULT_MERGE_IGNORE_KEYS, 'role', 'customField'] }\n */\n ignoreKeys?: readonly string[];\n}\n\nexport function _mergeDicts(\n /**\n * The left dictionary to merge.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n left: Record<string, any> | undefined,\n /**\n * The right dictionary to merge.\n * @type {Record<string, any>}\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n right: Record<string, any> | undefined,\n /**\n * The options for the merge.\n */\n options?: MergeDictsOptions\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): Record<string, any> | undefined {\n /**\n * The keys to ignore during merging.\n */\n const ignoreKeys = options?.ignoreKeys ?? DEFAULT_MERGE_IGNORE_KEYS;\n if (left == null && right == null) {\n return undefined;\n }\n if (left == null || right == null) {\n return left ?? right;\n }\n const merged = { ...left };\n for (const [key, value] of Object.entries(right)) {\n if (merged[key] == null) {\n merged[key] = value;\n } else if (value == null) {\n continue;\n } else if (\n typeof merged[key] !== typeof value ||\n Array.isArray(merged[key]) !== Array.isArray(value)\n ) {\n throw new Error(\n `field[${key}] already exists in the message chunk, but with a different type.`\n );\n } else if (typeof merged[key] === \"string\") {\n if (key === \"type\") {\n // Do not merge 'type' fields\n continue;\n } else if (\n [\"id\", \"name\", \"output_version\", \"model_provider\"].includes(key)\n ) {\n // Keep the incoming value for these fields if its defined\n if (value) {\n merged[key] = value;\n }\n } else if (ignoreKeys.includes(key)) {\n // Preserve the original value for ignored keys\n continue;\n } else {\n merged[key] += value;\n }\n } else if (typeof merged[key] === \"number\") {\n if (ignoreKeys.includes(key)) {\n // Preserve the original value for ignored keys\n continue;\n }\n merged[key] = merged[key] + value;\n } else if (typeof merged[key] === \"object\" && !Array.isArray(merged[key])) {\n merged[key] = _mergeDicts(merged[key], value, options);\n } else if (Array.isArray(merged[key])) {\n merged[key] = _mergeLists(merged[key], value, options);\n } else if (merged[key] === value) {\n continue;\n } else {\n console.warn(\n `field[${key}] already exists in this message chunk and value has unsupported type.`\n );\n }\n }\n return merged;\n}\n\nfunction isMergeableIndex(index: unknown): index is number | string {\n return typeof index === \"number\" || typeof index === \"string\";\n}\n\nfunction hasMergeableIndex(\n value: unknown\n): value is { index: number | string } {\n if (typeof value !== \"object\" || value === null) return false;\n if (!(\"index\" in value)) return false;\n return isMergeableIndex(value.index);\n}\n\nexport function _mergeLists<Content extends ContentBlock>(\n left?: Content[],\n right?: Content[],\n options?: MergeDictsOptions\n): Content[] | undefined {\n if (left == null && right == null) {\n return undefined;\n } else if (left == null || right == null) {\n return left || right;\n } else {\n const merged = [...left];\n for (const item of right) {\n if (hasMergeableIndex(item)) {\n const toMerge = merged.findIndex((leftItem) => {\n if (!hasMergeableIndex(leftItem)) return false;\n\n const indiciesMatch = leftItem.index === item.index;\n const leftHasId = leftItem.id != null && leftItem.id !== \"\";\n const rightHasId = item.id != null && item.id !== \"\";\n const idsMatch = leftHasId && rightHasId && leftItem.id === item.id;\n const eitherItemMissingID = !leftHasId || !rightHasId;\n return indiciesMatch && (idsMatch || eitherItemMissingID);\n });\n\n if (\n toMerge !== -1 &&\n typeof merged[toMerge] === \"object\" &&\n merged[toMerge] !== null\n ) {\n merged[toMerge] = _mergeDicts(\n merged[toMerge] as Record<string, unknown>,\n item as Record<string, unknown>,\n options\n ) as Content;\n } else {\n merged.push(item);\n }\n } else if (\n typeof item === \"object\" &&\n item !== null &&\n \"text\" in item &&\n item.text === \"\"\n ) {\n continue;\n } else {\n merged.push(item);\n }\n }\n return merged;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function _mergeObj<T = any>(\n left: T | undefined,\n right: T | undefined,\n options?: MergeDictsOptions\n): T | undefined {\n if (left == null && right == null) {\n return undefined;\n }\n if (left == null || right == null) {\n return left ?? right;\n } else if (typeof left !== typeof right) {\n throw new Error(\n `Cannot merge objects of different types.\\nLeft ${typeof left}\\nRight ${typeof right}`\n );\n } else if (typeof left === \"string\" && typeof right === \"string\") {\n return (left + right) as T;\n } else if (Array.isArray(left) && Array.isArray(right)) {\n return _mergeLists(left, right, options) as T;\n } else if (typeof left === \"object\" && typeof right === \"object\") {\n return _mergeDicts(\n left as Record<string, unknown>,\n right as Record<string, unknown>,\n options\n ) as T;\n } else if (left === right) {\n return left;\n } else {\n throw new Error(\n `Can not merge objects of different types.\\nLeft ${left}\\nRight ${right}`\n );\n }\n}\n\n/**\n * Represents a chunk of a message, which can be concatenated with other\n * message chunks. It includes a method `_merge_kwargs_dict()` for merging\n * additional keyword arguments from another `BaseMessageChunk` into this\n * one. It also overrides the `__add__()` method to support concatenation\n * of `BaseMessageChunk` instances.\n */\nexport abstract class BaseMessageChunk<\n TStructure extends MessageStructure = MessageStructure,\n TRole extends MessageType = MessageType,\n> extends BaseMessage<TStructure, TRole> {\n abstract concat(chunk: BaseMessageChunk): BaseMessageChunk<TStructure, TRole>;\n\n static isInstance(obj: unknown): obj is BaseMessageChunk {\n if (!super.isInstance(obj)) {\n return false;\n }\n // Check if obj is an instance of BaseMessageChunk by traversing the prototype chain\n let proto = Object.getPrototypeOf(obj);\n while (proto !== null) {\n if (proto === BaseMessageChunk.prototype) {\n return true;\n }\n proto = Object.getPrototypeOf(proto);\n }\n return false;\n }\n}\n\nexport type MessageFieldWithRole = {\n role: MessageType;\n content: MessageContent;\n name?: string;\n} & Record<string, unknown>;\n\nexport function _isMessageFieldWithRole(\n x: BaseMessageLike\n): x is MessageFieldWithRole {\n return typeof (x as MessageFieldWithRole).role === \"string\";\n}\n\nexport type BaseMessageLike =\n | BaseMessage\n | MessageFieldWithRole\n | [MessageType, MessageContent]\n | string\n /**\n * @deprecated Specifying \"type\" is deprecated and will be removed in 0.4.0.\n */\n | ({\n type: MessageType | \"user\" | \"assistant\" | \"placeholder\";\n } & BaseMessageFields &\n Record<string, unknown>)\n | SerializedConstructor;\n\n/**\n * @deprecated Use {@link BaseMessage.isInstance} instead\n */\nexport function isBaseMessage(\n messageLike?: unknown\n): messageLike is BaseMessage {\n return typeof (messageLike as BaseMessage)?._getType === \"function\";\n}\n\n/**\n * @deprecated Use {@link BaseMessageChunk.isInstance} instead\n */\nexport function isBaseMessageChunk(\n messageLike?: unknown\n): messageLike is BaseMessageChunk {\n return BaseMessageChunk.isInstance(messageLike);\n}\n"],"mappings":";;;;;;;;;AAoBA,MAAM,iBAAyB,OAAO,IAAI,oBAAoB;AAqE9D,SAAgB,aACd,cACA,eACgB;AAEhB,KAAI,OAAO,iBAAiB,UAAU;AACpC,MAAI,iBAAiB,GACnB,QAAO;AAET,MAAI,OAAO,kBAAkB,SAC3B,QAAO,eAAe;WACb,MAAM,QAAQ,cAAc,IAAI,cAAc,WAAW,EAClE,QAAO;WAEP,MAAM,QAAQ,cAAc,IAC5B,cAAc,MAAM,MAAM,mBAAmB,EAAE,CAAC,CAEhD,QAAO,CACL;GACE,MAAM;GACN,aAAa;GACb,MAAM;GACP,EACD,GAAG,cACJ;MAED,QAAO,CAAC;GAAE,MAAM;GAAQ,MAAM;GAAc,EAAE,GAAG,cAAc;YAGxD,MAAM,QAAQ,cAAc,CACrC,QACE,YAAY,cAAc,cAAc,IAAI,CAC1C,GAAG,cACH,GAAG,cACJ;UAGC,kBAAkB,GACpB,QAAO;UAEP,MAAM,QAAQ,aAAa,IAC3B,aAAa,MAAM,MAAM,mBAAmB,EAAE,CAAC,CAE/C,QAAO,CACL,GAAG,cACH;EACE,MAAM;EACN,aAAa;EACb,MAAM;EACP,CACF;KAED,QAAO,CAAC,GAAG,cAAc;EAAE,MAAM;EAAQ,MAAM;EAAe,CAAC;;;;;;;;;;AAarE,SAAgB,aACd,MACA,OACiC;AACjC,KAAI,SAAS,WAAW,UAAU,QAChC,QAAO;AAET,QAAO;;AAIT,SAAS,wBAAwB,KAAU,YAA4B;CAErE,SAAS,OAAO,KAAU,cAA2B;AACnD,MAAI,OAAO,QAAQ,YAAY,QAAQ,QAAQ,QAAQ,KAAA,EACrD,QAAO;AAET,MAAI,gBAAgB,YAAY;AAC9B,OAAI,MAAM,QAAQ,IAAI,CACpB,QAAO;AAET,UAAO;;AAGT,MAAI,MAAM,QA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ACL,MACA,OACA,QACD;UACQ,SAAS,MAClB,QAAO;KAEP,OAAM,IAAI,MACR,mDAAmD,KAAK,UAAU,QACnE;;;;;;;;;AAWL,IAAsB,mBAAtB,MAAsB,yBAGZ,YAA+B;CAGvC,OAAO,WAAW,KAAuC;AACvD,MAAI,CAAC,MAAM,WAAW,IAAI,CACxB,QAAO;EAGT,IAAI,QAAQ,OAAO,eAAe,IAAI;AACtC,SAAO,UAAU,MAAM;AACrB,OAAI,UAAU,iBAAiB,UAC7B,QAAO;AAET,WAAQ,OAAO,eAAe,MAAM;;AAEtC,SAAO;;;AAUX,SAAgB,wBACd,GAC2B;AAC3B,QAAO,OAAQ,EAA2B,SAAS;;;;;AAoBrD,SAAgB,cACd,aAC4B;AAC5B,QAAO,OAAQ,aAA6B,aAAa;;;;;AAM3D,SAAgB,mBACd,aACiC;AACjC,QAAO,iBAAiB,WAAW,YAAY"}
|
|
1
|
+
{"version":3,"file":"base.js","names":[],"sources":["../../src/messages/base.ts"],"sourcesContent":["import { Serializable, SerializedConstructor } from \"../load/serializable.js\";\nimport { ContentBlock } from \"./content/index.js\";\nimport { isDataContentBlock } from \"./content/data.js\";\nimport { convertToV1FromAnthropicInput } from \"./block_translators/anthropic.js\";\nimport { convertToV1FromDataContent } from \"./block_translators/data.js\";\nimport { convertToV1FromChatCompletionsInput } from \"./block_translators/openai.js\";\nimport {\n $InferMessageContent,\n $InferResponseMetadata,\n MessageStructure,\n MessageType,\n isMessage,\n Message,\n} from \"./message.js\";\nimport {\n convertToFormattedString,\n type MessageStringFormat,\n} from \"./format.js\";\n\n/** @internal */\nconst MESSAGE_SYMBOL: symbol = Symbol.for(\"langchain.message\");\n\nexport interface StoredMessageData {\n content: string;\n role: string | undefined;\n name: string | undefined;\n tool_call_id: string | undefined;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n additional_kwargs?: Record<string, any>;\n /** Response metadata. For example: response headers, logprobs, token counts, model name. */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n response_metadata?: Record<string, any>;\n id?: string;\n}\n\nexport interface StoredMessage {\n type: string;\n data: StoredMessageData;\n}\n\nexport interface StoredGeneration {\n text: string;\n message?: StoredMessage;\n}\n\nexport interface StoredMessageV1 {\n type: string;\n role: string | undefined;\n text: string;\n}\n\nexport type MessageContent = string | Array<ContentBlock>;\n\nexport interface FunctionCall {\n /**\n * The arguments to call the function with, as generated by the model in JSON\n * format. Note that the model does not always generate valid JSON, and may\n * hallucinate parameters not defined by your function schema. Validate the\n * arguments in your code before calling your function.\n */\n arguments: string;\n\n /**\n * The name of the function to call.\n */\n name: string;\n}\n\nexport type BaseMessageFields<\n TStructure extends MessageStructure = MessageStructure,\n TRole extends MessageType = MessageType,\n> = Pick<Message, \"id\" | \"name\"> & {\n content?: $InferMessageContent<TStructure, TRole>;\n contentBlocks?: Array<ContentBlock.Standard>;\n /** @deprecated */\n additional_kwargs?: {\n /**\n * @deprecated Use \"tool_calls\" field on AIMessages instead\n */\n function_call?: FunctionCall;\n /**\n * @deprecated Use \"tool_calls\" field on AIMessages instead\n */\n tool_calls?: OpenAIToolCall[];\n [key: string]: unknown;\n };\n response_metadata?: Partial<$InferResponseMetadata<TStructure, TRole>>;\n};\n\nexport function mergeContent(\n firstContent: MessageContent,\n secondContent: MessageContent\n): MessageContent {\n // If first content is a string\n if (typeof firstContent === \"string\") {\n if (firstContent === \"\") {\n return secondContent;\n }\n if (typeof secondContent === \"string\") {\n return firstContent + secondContent;\n } else if (Array.isArray(secondContent) && secondContent.length === 0) {\n return firstContent;\n } else if (\n Array.isArray(secondContent) &&\n secondContent.some((c) => isDataContentBlock(c))\n ) {\n return [\n {\n type: \"text\",\n source_type: \"text\",\n text: firstContent,\n },\n ...secondContent,\n ];\n } else {\n return [{ type: \"text\", text: firstContent }, ...secondContent];\n }\n // If both are arrays\n } else if (Array.isArray(secondContent)) {\n return (\n _mergeLists(firstContent, secondContent) ?? [\n ...firstContent,\n ...secondContent,\n ]\n );\n } else {\n if (secondContent === \"\") {\n return firstContent;\n } else if (\n Array.isArray(firstContent) &&\n firstContent.some((c) => isDataContentBlock(c))\n ) {\n return [\n ...firstContent,\n {\n type: \"file\",\n source_type: \"text\",\n text: secondContent,\n },\n ];\n } else {\n return [...firstContent, { type: \"text\", text: secondContent }];\n }\n }\n}\n\n/**\n * 'Merge' two statuses. If either value passed is 'error', it will return 'error'. Else\n * it will return 'success'.\n *\n * @param {\"success\" | \"error\" | undefined} left The existing value to 'merge' with the new value.\n * @param {\"success\" | \"error\" | undefined} right The new value to 'merge' with the existing value\n * @returns {\"success\" | \"error\"} The 'merged' value.\n */\nexport function _mergeStatus(\n left?: \"success\" | \"error\",\n right?: \"success\" | \"error\"\n): \"success\" | \"error\" | undefined {\n if (left === \"error\" || right === \"error\") {\n return \"error\";\n }\n return \"success\";\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction stringifyWithDepthLimit(obj: any, depthLimit: number): string {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n function helper(obj: any, currentDepth: number): any {\n if (typeof obj !== \"object\" || obj === null || obj === undefined) {\n return obj;\n }\n if (currentDepth >= depthLimit) {\n if (Array.isArray(obj)) {\n return \"[Array]\";\n }\n return \"[Object]\";\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item) => helper(item, currentDepth + 1));\n }\n\n const result: Record<string, unknown> = {};\n for (const key of Object.keys(obj)) {\n result[key] = helper(obj[key], currentDepth + 1);\n }\n return result;\n }\n\n return JSON.stringify(helper(obj, 0), null, 2);\n}\n\n/**\n * Base class for all types of messages in a conversation. It includes\n * properties like `content`, `name`, and `additional_kwargs`. It also\n * includes methods like `toDict()` and `_getType()`.\n */\nexport abstract class BaseMessage<\n TStructure extends MessageStructure = MessageStructure,\n TRole extends MessageType = MessageType,\n>\n extends Serializable\n implements Message<TStructure, TRole>\n{\n lc_namespace = [\"langchain_core\", \"messages\"];\n\n lc_serializable = true;\n\n get lc_aliases(): Record<string, string> {\n // exclude snake case conversion to pascal case\n return {\n additional_kwargs: \"additional_kwargs\",\n response_metadata: \"response_metadata\",\n };\n }\n\n readonly [MESSAGE_SYMBOL] = true as const;\n\n abstract readonly type: TRole;\n\n id?: string;\n\n /** @inheritdoc */\n name?: string;\n\n content: $InferMessageContent<TStructure, TRole>;\n\n additional_kwargs: NonNullable<\n BaseMessageFields<TStructure, TRole>[\"additional_kwargs\"]\n >;\n\n response_metadata: NonNullable<\n BaseMessageFields<TStructure, TRole>[\"response_metadata\"]\n >;\n\n /**\n * @deprecated Use .getType() instead or import the proper typeguard.\n * For example:\n *\n * ```ts\n * import { isAIMessage } from \"@langchain/core/messages\";\n *\n * const message = new AIMessage(\"Hello!\");\n * isAIMessage(message); // true\n * ```\n */\n _getType(): MessageType {\n return this.type;\n }\n\n /**\n * @deprecated Use .type instead\n * The type of the message.\n */\n getType(): MessageType {\n return this._getType();\n }\n\n constructor(\n arg:\n | $InferMessageContent<TStructure, TRole>\n | BaseMessageFields<TStructure, TRole>\n ) {\n const fields: BaseMessageFields<TStructure, TRole> =\n typeof arg === \"string\" || Array.isArray(arg)\n ? ({ content: arg } as BaseMessageFields<TStructure, TRole>)\n : arg;\n if (!fields.additional_kwargs) {\n fields.additional_kwargs = {};\n }\n if (!fields.response_metadata) {\n fields.response_metadata = {};\n }\n super(fields);\n this.name = fields.name;\n if (fields.content === undefined && fields.contentBlocks !== undefined) {\n this.content = fields.contentBlocks as $InferMessageContent<\n TStructure,\n TRole\n >;\n this.response_metadata = {\n output_version: \"v1\",\n ...fields.response_metadata,\n };\n } else if (fields.content !== undefined) {\n this.content = fields.content ?? [];\n this.response_metadata = fields.response_metadata;\n } else {\n this.content = [] as $InferMessageContent<TStructure, TRole>;\n this.response_metadata = fields.response_metadata;\n }\n this.additional_kwargs = fields.additional_kwargs;\n this.id = fields.id;\n }\n\n /** Get text content of the message. */\n get text(): string {\n if (typeof this.content === \"string\") {\n return this.content;\n }\n if (!Array.isArray(this.content)) return \"\";\n return this.content\n .map((c) => {\n if (typeof c === \"string\") return c;\n if (c.type === \"text\") return c.text;\n return \"\";\n })\n .join(\"\");\n }\n\n get contentBlocks(): Array<ContentBlock.Standard> {\n const blocks: Array<ContentBlock> =\n typeof this.content === \"string\"\n ? [{ type: \"text\", text: this.content }]\n : this.content;\n const parsingSteps = [\n convertToV1FromDataContent,\n convertToV1FromChatCompletionsInput,\n convertToV1FromAnthropicInput,\n ];\n const parsedBlocks = parsingSteps.reduce(\n (blocks, step) => step(blocks),\n blocks\n );\n return parsedBlocks as Array<ContentBlock.Standard>;\n }\n\n toDict(): StoredMessage {\n return {\n type: this.getType(),\n data: (this.toJSON() as SerializedConstructor)\n .kwargs as StoredMessageData,\n };\n }\n\n static lc_name() {\n return \"BaseMessage\";\n }\n\n // Can't be protected for silly reasons\n get _printableFields(): Record<string, unknown> {\n return {\n id: this.id,\n content: this.content,\n name: this.name,\n additional_kwargs: this.additional_kwargs,\n response_metadata: this.response_metadata,\n };\n }\n\n static isInstance(obj: unknown): obj is BaseMessage {\n return (\n typeof obj === \"object\" &&\n obj !== null &&\n MESSAGE_SYMBOL in obj &&\n (obj as Record<symbol, unknown>)[MESSAGE_SYMBOL] === true &&\n isMessage(obj)\n );\n }\n\n // this private method is used to update the ID for the runtime\n // value as well as in lc_kwargs for serialisation\n _updateId(value: string | undefined) {\n this.id = value;\n\n // lc_attributes wouldn't work here, because jest compares the\n // whole object\n this.lc_kwargs.id = value;\n }\n\n get [Symbol.toStringTag]() {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (this.constructor as any).lc_name();\n }\n\n // Override the default behavior of console.log\n [Symbol.for(\"nodejs.util.inspect.custom\")](depth: number | null) {\n if (depth === null) {\n return this;\n }\n const printable = stringifyWithDepthLimit(\n this._printableFields,\n Math.max(4, depth)\n );\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return `${(this.constructor as any).lc_name()} ${printable}`;\n }\n\n toFormattedString(format: MessageStringFormat = \"pretty\"): string {\n return convertToFormattedString(this, format);\n }\n}\n\n/**\n * @deprecated Use \"tool_calls\" field on AIMessages instead\n */\nexport type OpenAIToolCall = {\n /**\n * The ID of the tool call.\n */\n id: string;\n\n /**\n * The function that the model called.\n */\n function: FunctionCall;\n\n /**\n * The type of the tool. Currently, only `function` is supported.\n */\n type: \"function\";\n\n index?: number;\n};\n\nexport function isOpenAIToolCallArray(\n value?: unknown\n): value is OpenAIToolCall[] {\n return (\n Array.isArray(value) &&\n value.every((v) => typeof (v as OpenAIToolCall).index === \"number\")\n );\n}\n\n/**\n * Default keys that should be preserved (not merged) when concatenating message chunks.\n * These are identification and timestamp fields that shouldn't be summed or concatenated.\n */\nexport const DEFAULT_MERGE_IGNORE_KEYS: readonly string[] = [\n \"index\", // Used for identification in tool calls, not accumulation\n \"created\", // Timestamp field\n \"timestamp\", // Timestamp field\n] as const;\n\n/**\n * Options for controlling merge behavior in `_mergeDicts`.\n */\nexport interface MergeDictsOptions {\n /**\n * Keys to ignore during merging. When a key is in this list:\n * - For numeric values: the original value is preserved (not summed)\n * - For string values: the original value is preserved (not concatenated)\n *\n * Defaults to `DEFAULT_MERGE_IGNORE_KEYS` which includes 'index', 'created', 'timestamp'.\n *\n * @example\n * // Extend defaults with custom keys\n * { ignoreKeys: [...DEFAULT_MERGE_IGNORE_KEYS, 'role', 'customField'] }\n */\n ignoreKeys?: readonly string[];\n}\n\nexport function _mergeDicts(\n /**\n * The left dictionary to merge.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n left: Record<string, any> | undefined,\n /**\n * The right dictionary to merge.\n * @type {Record<string, any>}\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n right: Record<string, any> | undefined,\n /**\n * The options for the merge.\n */\n options?: MergeDictsOptions\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): Record<string, any> | undefined {\n /**\n * The keys to ignore during merging.\n */\n const ignoreKeys = options?.ignoreKeys ?? DEFAULT_MERGE_IGNORE_KEYS;\n if (left == null && right == null) {\n return undefined;\n }\n if (left == null || right == null) {\n return left ?? right;\n }\n const merged = { ...left };\n for (const [key, value] of Object.entries(right)) {\n if (merged[key] == null) {\n merged[key] = value;\n } else if (value == null) {\n continue;\n } else if (\n typeof merged[key] !== typeof value ||\n Array.isArray(merged[key]) !== Array.isArray(value)\n ) {\n throw new Error(\n `field[${key}] already exists in the message chunk, but with a different type.`\n );\n } else if (typeof merged[key] === \"string\") {\n if (key === \"type\") {\n // Do not merge 'type' fields\n continue;\n } else if (\n [\"id\", \"name\", \"output_version\", \"model_provider\"].includes(key)\n ) {\n // Keep the incoming value for these fields if its defined\n if (value) {\n merged[key] = value;\n }\n } else if (ignoreKeys.includes(key)) {\n // Preserve the original value for ignored keys\n continue;\n } else {\n merged[key] += value;\n }\n } else if (typeof merged[key] === \"number\") {\n if (ignoreKeys.includes(key)) {\n // Preserve the original value for ignored keys\n continue;\n }\n merged[key] = merged[key] + value;\n } else if (typeof merged[key] === \"object\" && !Array.isArray(merged[key])) {\n merged[key] = _mergeDicts(merged[key], value, options);\n } else if (Array.isArray(merged[key])) {\n merged[key] = _mergeLists(merged[key], value, options);\n } else if (merged[key] === value) {\n continue;\n } else {\n console.warn(\n `field[${key}] already exists in this message chunk and value has unsupported type.`\n );\n }\n }\n return merged;\n}\n\nfunction isMergeableIndex(index: unknown): index is number | string {\n return typeof index === \"number\" || typeof index === \"string\";\n}\n\nfunction hasMergeableIndex(\n value: unknown\n): value is { index: number | string } {\n if (typeof value !== \"object\" || value === null) return false;\n if (!(\"index\" in value)) return false;\n return isMergeableIndex(value.index);\n}\n\nfunction hasMergeableId(value: unknown): value is { id: string | number } {\n if (typeof value !== \"object\" || value === null) return false;\n if (!(\"id\" in value)) return false;\n const id = (value as Record<string, unknown>).id;\n return id != null && id !== \"\";\n}\n\n/**\n * Find the index of an existing item in `merged` that should be merged with\n * `item`, based on index and/or id matching.\n *\n * Matching priority:\n * 1. Both have index → match on index (+ id when both present)\n * 2. Neither has index, both have id → match on id alone\n * 3. Otherwise → no match (item should be appended)\n */\nfunction _findMergeTarget<Content extends ContentBlock>(\n merged: Content[],\n item: Content\n): number {\n const itemHasIndex = hasMergeableIndex(item);\n const itemHasId = hasMergeableId(item);\n\n if (!itemHasIndex && !itemHasId) return -1;\n\n return merged.findIndex((leftItem) => {\n const leftHasIndex = hasMergeableIndex(leftItem);\n const leftHasId = hasMergeableId(leftItem);\n\n if (itemHasIndex && leftHasIndex) {\n // Both have index: match on index, with id as tiebreaker\n const indicesMatch = leftItem.index === item.index;\n if (!indicesMatch) return false;\n if (leftHasId && itemHasId) return leftItem.id === item.id;\n return true; // indices match, one or both missing id\n }\n\n if (!itemHasIndex && !leftHasIndex && itemHasId && leftHasId) {\n // Neither has index: fall back to id-only matching. Handles providers\n // that don't include `index` on streaming tool call deltas.\n return leftItem.id === item.id;\n }\n\n return false;\n });\n}\n\nexport function _mergeLists<Content extends ContentBlock>(\n left?: Content[],\n right?: Content[],\n options?: MergeDictsOptions\n): Content[] | undefined {\n if (left == null && right == null) {\n return undefined;\n } else if (left == null || right == null) {\n return left || right;\n } else {\n const merged = [...left];\n for (const item of right) {\n const toMerge = _findMergeTarget(merged, item);\n if (toMerge !== -1) {\n merged[toMerge] = _mergeDicts(\n merged[toMerge],\n item,\n options\n ) as Content;\n } else if (\n typeof item === \"object\" &&\n item !== null &&\n \"text\" in item &&\n item.text === \"\"\n ) {\n continue;\n } else {\n merged.push(item);\n }\n }\n return merged;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function _mergeObj<T = any>(\n left: T | undefined,\n right: T | undefined,\n options?: MergeDictsOptions\n): T | undefined {\n if (left == null && right == null) {\n return undefined;\n }\n if (left == null || right == null) {\n return left ?? right;\n } else if (typeof left !== typeof right) {\n throw new Error(\n `Cannot merge objects of different types.\\nLeft ${typeof left}\\nRight ${typeof right}`\n );\n } else if (typeof left === \"string\" && typeof right === \"string\") {\n return (left + right) as T;\n } else if (Array.isArray(left) && Array.isArray(right)) {\n return _mergeLists(left, right, options) as T;\n } else if (typeof left === \"object\" && typeof right === \"object\") {\n return _mergeDicts(\n left as Record<string, unknown>,\n right as Record<string, unknown>,\n options\n ) as T;\n } else if (left === right) {\n return left;\n } else {\n throw new Error(\n `Can not merge objects of different types.\\nLeft ${left}\\nRight ${right}`\n );\n }\n}\n\n/**\n * Represents a chunk of a message, which can be concatenated with other\n * message chunks. It includes a method `_merge_kwargs_dict()` for merging\n * additional keyword arguments from another `BaseMessageChunk` into this\n * one. It also overrides the `__add__()` method to support concatenation\n * of `BaseMessageChunk` instances.\n */\nexport abstract class BaseMessageChunk<\n TStructure extends MessageStructure = MessageStructure,\n TRole extends MessageType = MessageType,\n> extends BaseMessage<TStructure, TRole> {\n abstract concat(chunk: BaseMessageChunk): BaseMessageChunk<TStructure, TRole>;\n\n static isInstance(obj: unknown): obj is BaseMessageChunk {\n if (!super.isInstance(obj)) {\n return false;\n }\n // Check if obj is an instance of BaseMessageChunk by traversing the prototype chain\n let proto = Object.getPrototypeOf(obj);\n while (proto !== null) {\n if (proto === BaseMessageChunk.prototype) {\n return true;\n }\n proto = Object.getPrototypeOf(proto);\n }\n return false;\n }\n}\n\nexport type MessageFieldWithRole = {\n role: MessageType;\n content: MessageContent;\n name?: string;\n} & Record<string, unknown>;\n\nexport function _isMessageFieldWithRole(\n x: BaseMessageLike\n): x is MessageFieldWithRole {\n return typeof (x as MessageFieldWithRole).role === \"string\";\n}\n\nexport type BaseMessageLike =\n | BaseMessage\n | MessageFieldWithRole\n | [MessageType, MessageContent]\n | string\n /**\n * @deprecated Specifying \"type\" is deprecated and will be removed in 0.4.0.\n */\n | ({\n type: MessageType | \"user\" | \"assistant\" | \"placeholder\";\n } & BaseMessageFields &\n Record<string, unknown>)\n | SerializedConstructor;\n\n/**\n * @deprecated Use {@link BaseMessage.isInstance} instead\n */\nexport function isBaseMessage(\n messageLike?: unknown\n): messageLike is BaseMessage {\n return typeof (messageLike as BaseMessage)?._getType === \"function\";\n}\n\n/**\n * @deprecated Use {@link BaseMessageChunk.isInstance} instead\n */\nexport function isBaseMessageChunk(\n messageLike?: unknown\n): messageLike is BaseMessageChunk {\n return BaseMessageChunk.isInstance(messageLike);\n}\n"],"mappings":";;;;;;;;;AAoBA,MAAM,iBAAyB,OAAO,IAAI,oBAAoB;AAqE9D,SAAgB,aACd,cACA,eACgB;AAEhB,KAAI,OAAO,iBAAiB,UAAU;AACpC,MAAI,iBAAiB,GACnB,QAAO;AAET,MAAI,OAAO,kBAAkB,SAC3B,QAAO,eAAe;WACb,MAAM,QAAQ,cAAc,IAAI,cAAc,WAAW,EAClE,QAAO;WAEP,MAAM,QAAQ,cAAc,IAC5B,cAAc,MAAM,MAAM,mBAAmB,EAAE,CAAC,CAEhD,QAAO,CACL;GACE,MAAM;GACN,aAAa;GACb,MAAM;GACP,EACD,GAAG,cACJ;MAED,QAAO,CAAC;GAAE,MAAM;GAAQ,MAAM;GAAc,EAAE,GAAG,cAAc;YAGxD,MAAM,QAAQ,cAAc,CACrC,QACE,YAAY,cAAc,cAAc,IAAI,CAC1C,GAAG,cACH,GAAG,cACJ;UAGC,kBAAkB,GACpB,QAAO;UAEP,MAAM,QAAQ,aAAa,IAC3B,aAAa,MAAM,MAAM,mBAAmB,EAAE,CAAC,CAE/C,QAAO,CACL,GAAG,cACH;EACE,MAAM;EACN,aAAa;EACb,MAAM;EACP,CACF;KAED,QAAO,CAAC,GAAG,cAAc;EAAE,MAAM;EAAQ,MAAM;EAAe,CAAC;;;;;;;;;;AAarE,SAAgB,aACd,MACA,OACiC;AACjC,KAAI,SAAS,WAAW,UAAU,QAChC,QAAO;AAET,QAAO;;AAIT,SAAS,wBAAwB,KAAU,YAA4B;CAErE,SAAS,OAAO,KAAU,cAA2B;AACnD,MAAI,OAAO,QAAQ,YAAY,QAAQ,QAAQ,QAAQ,KAAA,EACrD,QAAO;AAET,MAAI,gBAAgB,YAAY;AAC9B,OAAI,MAAM,QAAQ,IAAI,CACpB,QAAO;AAET,UAAO;;AAGT,MAAI,MAAM,QAAQ,IAAI,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SAAS,OAAO,MAChC,OAAM,IAAI,MACR,kDAAkD,OAAO,KAAK,UAAU,OAAO,QAChF;UACQ,OAAO,SAAS,YAAY,OAAO,UAAU,SACtD,QAAQ,OAAO;UACN,MAAM,QAAQ,KAAK,IAAI,MAAM,QAAQ,MAAM,CACpD,QAAO,YAAY,MAAM,OAAO,QAAQ;UAC/B,OAAO,SAAS,YAAY,OAAO,UAAU,SACtD,QAAO,YACL,MACA,OACA,QACD;UACQ,SAAS,MAClB,QAAO;KAEP,OAAM,IAAI,MACR,mDAAmD,KAAK,UAAU,QACnE;;;;;;;;;AAWL,IAAsB,mBAAtB,MAAsB,yBAGZ,YAA+B;CAGvC,OAAO,WAAW,KAAuC;AACvD,MAAI,CAAC,MAAM,WAAW,IAAI,CACxB,QAAO;EAGT,IAAI,QAAQ,OAAO,eAAe,IAAI;AACtC,SAAO,UAAU,MAAM;AACrB,OAAI,UAAU,iBAAiB,UAC7B,QAAO;AAET,WAAQ,OAAO,eAAe,MAAM;;AAEtC,SAAO;;;AAUX,SAAgB,wBACd,GAC2B;AAC3B,QAAO,OAAQ,EAA2B,SAAS;;;;;AAoBrD,SAAgB,cACd,aAC4B;AAC5B,QAAO,OAAQ,aAA6B,aAAa;;;;;AAM3D,SAAgB,mBACd,aACiC;AACjC,QAAO,iBAAiB,WAAW,YAAY"}
|
package/dist/messages/system.cjs
CHANGED
|
@@ -18,11 +18,14 @@ var SystemMessage = class SystemMessage extends require_base.BaseMessage {
|
|
|
18
18
|
*/
|
|
19
19
|
concat(chunk) {
|
|
20
20
|
if (typeof chunk === "string") return new SystemMessage({
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
content: require_base.mergeContent(this.content, chunk),
|
|
22
|
+
additional_kwargs: this.additional_kwargs,
|
|
23
|
+
response_metadata: this.response_metadata,
|
|
24
|
+
id: this.id,
|
|
25
|
+
name: this.name
|
|
23
26
|
});
|
|
24
27
|
if (SystemMessage.isInstance(chunk)) return new SystemMessage({
|
|
25
|
-
|
|
28
|
+
content: require_base.mergeContent(this.content, chunk.content),
|
|
26
29
|
additional_kwargs: {
|
|
27
30
|
...this.additional_kwargs,
|
|
28
31
|
...chunk.additional_kwargs
|
|
@@ -31,7 +34,8 @@ var SystemMessage = class SystemMessage extends require_base.BaseMessage {
|
|
|
31
34
|
...this.response_metadata,
|
|
32
35
|
...chunk.response_metadata
|
|
33
36
|
},
|
|
34
|
-
|
|
37
|
+
id: this.id ?? chunk.id,
|
|
38
|
+
name: this.name ?? chunk.name
|
|
35
39
|
});
|
|
36
40
|
throw new Error("Unexpected chunk type for system message");
|
|
37
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system.cjs","names":["BaseMessage","mergeContent","BaseMessageChunk","_mergeDicts"],"sources":["../../src/messages/system.ts"],"sourcesContent":["import {\n BaseMessage,\n BaseMessageChunk,\n mergeContent,\n _mergeDicts,\n type BaseMessageFields,\n} from \"./base.js\";\nimport { $InferMessageContent, MessageStructure } from \"./message.js\";\nimport { Constructor } from \"./utils.js\";\n\nexport interface SystemMessageFields<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessageFields<TStructure, \"system\"> {}\n\n/**\n * Represents a system message in a conversation.\n */\nexport class SystemMessage<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessage<TStructure, \"system\"> {\n static lc_name() {\n return \"SystemMessage\";\n }\n\n readonly type = \"system\" as const;\n\n constructor(\n fields:\n | $InferMessageContent<TStructure, \"system\">\n | SystemMessageFields<TStructure>\n ) {\n super(fields);\n }\n\n /**\n * Concatenates a string or another system message with the current system message.\n * @param chunk - The chunk to concatenate with the system message.\n * @returns A new system message with the concatenated content.\n */\n concat(chunk: string | SystemMessage) {\n if (typeof chunk === \"string\") {\n return new SystemMessage({\n
|
|
1
|
+
{"version":3,"file":"system.cjs","names":["BaseMessage","mergeContent","BaseMessageChunk","_mergeDicts"],"sources":["../../src/messages/system.ts"],"sourcesContent":["import {\n BaseMessage,\n BaseMessageChunk,\n mergeContent,\n _mergeDicts,\n type BaseMessageFields,\n} from \"./base.js\";\nimport { $InferMessageContent, MessageStructure } from \"./message.js\";\nimport { Constructor } from \"./utils.js\";\n\nexport interface SystemMessageFields<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessageFields<TStructure, \"system\"> {}\n\n/**\n * Represents a system message in a conversation.\n */\nexport class SystemMessage<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessage<TStructure, \"system\"> {\n static lc_name() {\n return \"SystemMessage\";\n }\n\n readonly type = \"system\" as const;\n\n constructor(\n fields:\n | $InferMessageContent<TStructure, \"system\">\n | SystemMessageFields<TStructure>\n ) {\n super(fields);\n }\n\n /**\n * Concatenates a string or another system message with the current system message.\n * @param chunk - The chunk to concatenate with the system message.\n * @returns A new system message with the concatenated content.\n */\n concat(chunk: string | SystemMessage) {\n if (typeof chunk === \"string\") {\n return new SystemMessage({\n content: mergeContent(this.content, chunk),\n additional_kwargs: this.additional_kwargs,\n response_metadata: this.response_metadata,\n id: this.id,\n name: this.name,\n } as SystemMessageFields<TStructure>);\n }\n\n if (SystemMessage.isInstance(chunk)) {\n return new SystemMessage({\n content: mergeContent(this.content, chunk.content),\n additional_kwargs: {\n ...this.additional_kwargs,\n ...chunk.additional_kwargs,\n },\n response_metadata: {\n ...this.response_metadata,\n ...chunk.response_metadata,\n },\n id: this.id ?? chunk.id,\n name: this.name ?? chunk.name,\n } as SystemMessageFields<TStructure>);\n }\n\n throw new Error(\"Unexpected chunk type for system message\");\n }\n\n static isInstance(obj: unknown): obj is SystemMessage {\n return super.isInstance(obj) && obj.type === \"system\";\n }\n}\n\n/**\n * Represents a chunk of a system message, which can be concatenated with\n * other system message chunks.\n */\nexport class SystemMessageChunk<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessageChunk<TStructure, \"system\"> {\n static lc_name() {\n return \"SystemMessageChunk\";\n }\n\n readonly type = \"system\" as const;\n\n constructor(\n fields:\n | $InferMessageContent<TStructure, \"system\">\n | SystemMessageFields<TStructure>\n ) {\n super(fields);\n }\n\n concat(chunk: SystemMessageChunk<TStructure>) {\n const Cls = this.constructor as Constructor<this>;\n return new Cls({\n content: mergeContent(this.content, chunk.content),\n additional_kwargs: _mergeDicts(\n this.additional_kwargs,\n chunk.additional_kwargs\n ),\n response_metadata: _mergeDicts(\n this.response_metadata,\n chunk.response_metadata\n ),\n id: this.id ?? chunk.id,\n });\n }\n\n static isInstance(obj: unknown): obj is SystemMessageChunk {\n return super.isInstance(obj) && obj.type === \"system\";\n }\n}\n\n/**\n * @deprecated Use {@link SystemMessage.isInstance} instead\n */\nexport function isSystemMessage<TStructure extends MessageStructure>(\n x: BaseMessage\n): x is SystemMessage<TStructure> {\n return x._getType() === \"system\";\n}\n\n/**\n * @deprecated Use {@link SystemMessageChunk.isInstance} instead\n */\nexport function isSystemMessageChunk<TStructure extends MessageStructure>(\n x: BaseMessageChunk\n): x is SystemMessageChunk<TStructure> {\n return x._getType() === \"system\";\n}\n"],"mappings":";;;;;AAiBA,IAAa,gBAAb,MAAa,sBAEHA,aAAAA,YAAkC;CAC1C,OAAO,UAAU;AACf,SAAO;;CAGT,OAAgB;CAEhB,YACE,QAGA;AACA,QAAM,OAAO;;;;;;;CAQf,OAAO,OAA+B;AACpC,MAAI,OAAO,UAAU,SACnB,QAAO,IAAI,cAAc;GACvB,SAASC,aAAAA,aAAa,KAAK,SAAS,MAAM;GAC1C,mBAAmB,KAAK;GACxB,mBAAmB,KAAK;GACxB,IAAI,KAAK;GACT,MAAM,KAAK;GACZ,CAAoC;AAGvC,MAAI,cAAc,WAAW,MAAM,CACjC,QAAO,IAAI,cAAc;GACvB,SAASA,aAAAA,aAAa,KAAK,SAAS,MAAM,QAAQ;GAClD,mBAAmB;IACjB,GAAG,KAAK;IACR,GAAG,MAAM;IACV;GACD,mBAAmB;IACjB,GAAG,KAAK;IACR,GAAG,MAAM;IACV;GACD,IAAI,KAAK,MAAM,MAAM;GACrB,MAAM,KAAK,QAAQ,MAAM;GAC1B,CAAoC;AAGvC,QAAM,IAAI,MAAM,2CAA2C;;CAG7D,OAAO,WAAW,KAAoC;AACpD,SAAO,MAAM,WAAW,IAAI,IAAI,IAAI,SAAS;;;;;;;AAQjD,IAAa,qBAAb,cAEUC,aAAAA,iBAAuC;CAC/C,OAAO,UAAU;AACf,SAAO;;CAGT,OAAgB;CAEhB,YACE,QAGA;AACA,QAAM,OAAO;;CAGf,OAAO,OAAuC;EAC5C,MAAM,MAAM,KAAK;AACjB,SAAO,IAAI,IAAI;GACb,SAASD,aAAAA,aAAa,KAAK,SAAS,MAAM,QAAQ;GAClD,mBAAmBE,aAAAA,YACjB,KAAK,mBACL,MAAM,kBACP;GACD,mBAAmBA,aAAAA,YACjB,KAAK,mBACL,MAAM,kBACP;GACD,IAAI,KAAK,MAAM,MAAM;GACtB,CAAC;;CAGJ,OAAO,WAAW,KAAyC;AACzD,SAAO,MAAM,WAAW,IAAI,IAAI,IAAI,SAAS;;;;;;AAOjD,SAAgB,gBACd,GACgC;AAChC,QAAO,EAAE,UAAU,KAAK;;;;;AAM1B,SAAgB,qBACd,GACqC;AACrC,QAAO,EAAE,UAAU,KAAK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system.d.cts","names":[],"sources":["../../src/messages/system.ts"],"mappings":";;;;UAUiB,mBAAA,oBACI,gBAAA,GAAmB,gBAAA,UAC9B,iBAAA,CAAkB,UAAA;AAF5B;;;AAAA,cAOa,aAAA,oBACQ,gBAAA,GAAmB,gBAAA,UAC9B,WAAA,CAAY,UAAA;EAAA,OACb,OAAA,CAAA;EAAA,SAIE,IAAA;EAET,WAAA,CACE,MAAA,EACI,oBAAA,CAAqB,UAAA,cACrB,mBAAA,CAAoB,UAAA;EAjBD;;;;;EA2BzB,MAAA,CAAO,KAAA,WAAgB,aAAA,GAAa,aAAA,CAAA,UAAA;EAAA,
|
|
1
|
+
{"version":3,"file":"system.d.cts","names":[],"sources":["../../src/messages/system.ts"],"mappings":";;;;UAU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A,CAAqB,UAAA,cACrB,mBAAA,CAAoB,UAAA;EAjBD;;;;;EA2BzB,MAAA,CAAO,KAAA,WAAgB,aAAA,GAAa,aAAA,CAAA,UAAA;EAAA,
|
|
1
|
+
{"version":3,"file":"system.d.ts","names":[],"sources":["../../src/messages/system.ts"],"mappings":";;;;UAUiB,mBAAA,oBACI,gBAAA,GAAmB,gBAAA,UAC9B,iBAAA,CAAkB,UAAA;AAF5B;;;AAAA,cAOa,aAAA,oBACQ,gBAAA,GAAmB,gBAAA,UAC9B,WAAA,CAAY,UAAA;EAAA,OACb,OAAA,CAAA;EAAA,SAIE,IAAA;EAET,WAAA,CACE,MAAA,EACI,oBAAA,CAAqB,UAAA,cACrB,mBAAA,CAAoB,UAAA;EAjBD;;;;;EA2BzB,MAAA,CAAO,KAAA,WAAgB,aAAA,GAAa,aAAA,CAAA,UAAA;EAAA,OA8B7B,UAAA,CAAW,GAAA,YAAe,GAAA,IAAO,aAAA;AAAA;;AApD1C;;;cA6Da,kBAAA,oBACQ,gBAAA,GAAmB,gBAAA,UAC9B,gBAAA,CAAiB,UAAA;EAAA,OAClB,OAAA,CAAA;EAAA,SAIE,IAAA;EAET,WAAA,CACE,MAAA,EACI,oBAAA,CAAqB,UAAA,cACrB,mBAAA,CAAoB,UAAA;EAK1B,MAAA,CAAO,KAAA,EAAO,kBAAA,CAAmB,UAAA;EAAA,OAgB1B,UAAA,CAAW,GAAA,YAAe,GAAA,IAAO,kBAAA;AAAA;;;;iBAQ1B,eAAA,oBAAmC,gBAAA,CAAA,CACjD,CAAA,EAAG,WAAA,GACF,CAAA,IAAK,aAAA,CAAc,UAAA;;;;iBAON,oBAAA,oBAAwC,gBAAA,CAAA,CACtD,CAAA,EAAG,gBAAA,GACF,CAAA,IAAK,kBAAA,CAAmB,UAAA"}
|
package/dist/messages/system.js
CHANGED
|
@@ -18,11 +18,14 @@ var SystemMessage = class SystemMessage extends BaseMessage {
|
|
|
18
18
|
*/
|
|
19
19
|
concat(chunk) {
|
|
20
20
|
if (typeof chunk === "string") return new SystemMessage({
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
content: mergeContent(this.content, chunk),
|
|
22
|
+
additional_kwargs: this.additional_kwargs,
|
|
23
|
+
response_metadata: this.response_metadata,
|
|
24
|
+
id: this.id,
|
|
25
|
+
name: this.name
|
|
23
26
|
});
|
|
24
27
|
if (SystemMessage.isInstance(chunk)) return new SystemMessage({
|
|
25
|
-
|
|
28
|
+
content: mergeContent(this.content, chunk.content),
|
|
26
29
|
additional_kwargs: {
|
|
27
30
|
...this.additional_kwargs,
|
|
28
31
|
...chunk.additional_kwargs
|
|
@@ -31,7 +34,8 @@ var SystemMessage = class SystemMessage extends BaseMessage {
|
|
|
31
34
|
...this.response_metadata,
|
|
32
35
|
...chunk.response_metadata
|
|
33
36
|
},
|
|
34
|
-
|
|
37
|
+
id: this.id ?? chunk.id,
|
|
38
|
+
name: this.name ?? chunk.name
|
|
35
39
|
});
|
|
36
40
|
throw new Error("Unexpected chunk type for system message");
|
|
37
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system.js","names":[],"sources":["../../src/messages/system.ts"],"sourcesContent":["import {\n BaseMessage,\n BaseMessageChunk,\n mergeContent,\n _mergeDicts,\n type BaseMessageFields,\n} from \"./base.js\";\nimport { $InferMessageContent, MessageStructure } from \"./message.js\";\nimport { Constructor } from \"./utils.js\";\n\nexport interface SystemMessageFields<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessageFields<TStructure, \"system\"> {}\n\n/**\n * Represents a system message in a conversation.\n */\nexport class SystemMessage<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessage<TStructure, \"system\"> {\n static lc_name() {\n return \"SystemMessage\";\n }\n\n readonly type = \"system\" as const;\n\n constructor(\n fields:\n | $InferMessageContent<TStructure, \"system\">\n | SystemMessageFields<TStructure>\n ) {\n super(fields);\n }\n\n /**\n * Concatenates a string or another system message with the current system message.\n * @param chunk - The chunk to concatenate with the system message.\n * @returns A new system message with the concatenated content.\n */\n concat(chunk: string | SystemMessage) {\n if (typeof chunk === \"string\") {\n return new SystemMessage({\n
|
|
1
|
+
{"version":3,"file":"system.js","names":[],"sources":["../../src/messages/system.ts"],"sourcesContent":["import {\n BaseMessage,\n BaseMessageChunk,\n mergeContent,\n _mergeDicts,\n type BaseMessageFields,\n} from \"./base.js\";\nimport { $InferMessageContent, MessageStructure } from \"./message.js\";\nimport { Constructor } from \"./utils.js\";\n\nexport interface SystemMessageFields<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessageFields<TStructure, \"system\"> {}\n\n/**\n * Represents a system message in a conversation.\n */\nexport class SystemMessage<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessage<TStructure, \"system\"> {\n static lc_name() {\n return \"SystemMessage\";\n }\n\n readonly type = \"system\" as const;\n\n constructor(\n fields:\n | $InferMessageContent<TStructure, \"system\">\n | SystemMessageFields<TStructure>\n ) {\n super(fields);\n }\n\n /**\n * Concatenates a string or another system message with the current system message.\n * @param chunk - The chunk to concatenate with the system message.\n * @returns A new system message with the concatenated content.\n */\n concat(chunk: string | SystemMessage) {\n if (typeof chunk === \"string\") {\n return new SystemMessage({\n content: mergeContent(this.content, chunk),\n additional_kwargs: this.additional_kwargs,\n response_metadata: this.response_metadata,\n id: this.id,\n name: this.name,\n } as SystemMessageFields<TStructure>);\n }\n\n if (SystemMessage.isInstance(chunk)) {\n return new SystemMessage({\n content: mergeContent(this.content, chunk.content),\n additional_kwargs: {\n ...this.additional_kwargs,\n ...chunk.additional_kwargs,\n },\n response_metadata: {\n ...this.response_metadata,\n ...chunk.response_metadata,\n },\n id: this.id ?? chunk.id,\n name: this.name ?? chunk.name,\n } as SystemMessageFields<TStructure>);\n }\n\n throw new Error(\"Unexpected chunk type for system message\");\n }\n\n static isInstance(obj: unknown): obj is SystemMessage {\n return super.isInstance(obj) && obj.type === \"system\";\n }\n}\n\n/**\n * Represents a chunk of a system message, which can be concatenated with\n * other system message chunks.\n */\nexport class SystemMessageChunk<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessageChunk<TStructure, \"system\"> {\n static lc_name() {\n return \"SystemMessageChunk\";\n }\n\n readonly type = \"system\" as const;\n\n constructor(\n fields:\n | $InferMessageContent<TStructure, \"system\">\n | SystemMessageFields<TStructure>\n ) {\n super(fields);\n }\n\n concat(chunk: SystemMessageChunk<TStructure>) {\n const Cls = this.constructor as Constructor<this>;\n return new Cls({\n content: mergeContent(this.content, chunk.content),\n additional_kwargs: _mergeDicts(\n this.additional_kwargs,\n chunk.additional_kwargs\n ),\n response_metadata: _mergeDicts(\n this.response_metadata,\n chunk.response_metadata\n ),\n id: this.id ?? chunk.id,\n });\n }\n\n static isInstance(obj: unknown): obj is SystemMessageChunk {\n return super.isInstance(obj) && obj.type === \"system\";\n }\n}\n\n/**\n * @deprecated Use {@link SystemMessage.isInstance} instead\n */\nexport function isSystemMessage<TStructure extends MessageStructure>(\n x: BaseMessage\n): x is SystemMessage<TStructure> {\n return x._getType() === \"system\";\n}\n\n/**\n * @deprecated Use {@link SystemMessageChunk.isInstance} instead\n */\nexport function isSystemMessageChunk<TStructure extends MessageStructure>(\n x: BaseMessageChunk\n): x is SystemMessageChunk<TStructure> {\n return x._getType() === \"system\";\n}\n"],"mappings":";;;;;AAiBA,IAAa,gBAAb,MAAa,sBAEH,YAAkC;CAC1C,OAAO,UAAU;AACf,SAAO;;CAGT,OAAgB;CAEhB,YACE,QAGA;AACA,QAAM,OAAO;;;;;;;CAQf,OAAO,OAA+B;AACpC,MAAI,OAAO,UAAU,SACnB,QAAO,IAAI,cAAc;GACvB,SAAS,aAAa,KAAK,SAAS,MAAM;GAC1C,mBAAmB,KAAK;GACxB,mBAAmB,KAAK;GACxB,IAAI,KAAK;GACT,MAAM,KAAK;GACZ,CAAoC;AAGvC,MAAI,cAAc,WAAW,MAAM,CACjC,QAAO,IAAI,cAAc;GACvB,SAAS,aAAa,KAAK,SAAS,MAAM,QAAQ;GAClD,mBAAmB;IACjB,GAAG,KAAK;IACR,GAAG,MAAM;IACV;GACD,mBAAmB;IACjB,GAAG,KAAK;IACR,GAAG,MAAM;IACV;GACD,IAAI,KAAK,MAAM,MAAM;GACrB,MAAM,KAAK,QAAQ,MAAM;GAC1B,CAAoC;AAGvC,QAAM,IAAI,MAAM,2CAA2C;;CAG7D,OAAO,WAAW,KAAoC;AACpD,SAAO,MAAM,WAAW,IAAI,IAAI,IAAI,SAAS;;;;;;;AAQjD,IAAa,qBAAb,cAEU,iBAAuC;CAC/C,OAAO,UAAU;AACf,SAAO;;CAGT,OAAgB;CAEhB,YACE,QAGA;AACA,QAAM,OAAO;;CAGf,OAAO,OAAuC;EAC5C,MAAM,MAAM,KAAK;AACjB,SAAO,IAAI,IAAI;GACb,SAAS,aAAa,KAAK,SAAS,MAAM,QAAQ;GAClD,mBAAmB,YACjB,KAAK,mBACL,MAAM,kBACP;GACD,mBAAmB,YACjB,KAAK,mBACL,MAAM,kBACP;GACD,IAAI,KAAK,MAAM,MAAM;GACtB,CAAC;;CAGJ,OAAO,WAAW,KAAyC;AACzD,SAAO,MAAM,WAAW,IAAI,IAAI,IAAI,SAAS;;;;;;AAOjD,SAAgB,gBACd,GACgC;AAChC,QAAO,EAAE,UAAU,KAAK;;;;;AAM1B,SAAgB,qBACd,GACqC;AACrC,QAAO,EAAE,UAAU,KAAK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","names":[],"sources":["../../src/output_parsers/base.ts"],"mappings":";;;;;;;;;;;UAWiB,yBAAA
|
|
1
|
+
{"version":3,"file":"base.d.ts","names":[],"sources":["../../src/output_parsers/base.ts"],"mappings":";;;;;;;;;;;UAWiB,yBAAA;AAAjB;;;;;AAAA,uBAOsB,mBAAA,sBAAyC,QAAA,UACpD,WAAA,EACT,CAAA;EAFuC;;;;;;;;EAAA,SAY9B,WAAA,CACP,WAAA,EAAa,UAAA,KAAe,cAAA,IAC5B,SAAA,GAAY,SAAA,GACX,OAAA,CAAQ,CAAA;EAWI;;;;;;;;EADf,qBAAA,CACE,WAAA,EAAa,UAAA,KAAe,cAAA,IAC5B,OAAA,EAAS,wBAAA,EACT,SAAA,GAAY,SAAA,GACX,OAAA,CAAQ,CAAA;EAAA,UAID,oBAAA,CAAqB,OAAA,EAAS,WAAA;EAAA,UAM9B,2BAAA,CAA4B,OAAA,EAAS,YAAA;EAiB5C;;;;;;;;;;EAHG,MAAA,CACJ,KAAA,WAAgB,WAAA,EAChB,OAAA,GAAU,cAAA,GACT,OAAA,CAAQ,CAAA;AAAA;;;;uBA8BS,gBAAA,sBAEZ,mBAAA,CAAoB,CAAA;EAC5B,WAAA,CACE,WAAA,EAAa,UAAA,KAAe,cAAA,IAC5B,SAAA,GAAY,SAAA,GACX,OAAA,CAAQ,CAAA;EAlEI;;;;;;EAAA,SA4EN,KAAA,CAAM,IAAA,UAAc,SAAA,GAAY,SAAA,GAAY,OAAA,CAAQ,CAAA;EAEvD,eAAA,CACJ,IAAA,UACA,OAAA,EAAS,wBAAA,EACT,SAAA,GAAY,SAAA,GACX,OAAA,CAAQ,CAAA;EA/EA;;;;;;;;;;;EAAA,SA8FF,qBAAA,CAAsB,OAAA,GAAU,yBAAA;EAnEtC;;;EAwEH,KAAA,CAAA;AAAA;;;;;;;;;;;;;;;;;;;cAuBW,qBAAA,SAA8B,KAAA;EACzC,SAAA;EAEA,WAAA;EAEA,SAAA;EAEA,WAAA,CACE,OAAA,UACA,SAAA,WACA,WAAA,WACA,SAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json_output_tools_parsers.cjs","names":["parsePartialJson","OutputParserException","BaseCumulativeTransformOutputParser","isAIMessage","interopSafeParseAsync"],"sources":["../../../src/output_parsers/openai_tools/json_output_tools_parsers.ts"],"sourcesContent":["import type * as z3 from \"zod/v3\";\nimport type * as z4 from \"zod/v4/core\";\nimport { ChatGeneration, ChatGenerationChunk } from \"../../outputs.js\";\nimport { OutputParserException } from \"../base.js\";\nimport { parsePartialJson } from \"../json.js\";\nimport { InvalidToolCall, ToolCall } from \"../../messages/tool.js\";\nimport {\n BaseCumulativeTransformOutputParser,\n BaseCumulativeTransformOutputParserInput,\n} from \"../transform.js\";\nimport { isAIMessage } from \"../../messages/ai.js\";\nimport {\n type InteropZodType,\n interopSafeParseAsync,\n} from \"../../utils/types/zod.js\";\nimport { SerializableSchema } from \"../../utils/standard_schema.js\";\n\nexport type ParsedToolCall = {\n id?: string;\n\n type: string;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n args: Record<string, any>;\n};\n\nexport type JsonOutputToolsParserParams = {\n /** Whether to return the tool call id. */\n returnId?: boolean;\n} & BaseCumulativeTransformOutputParserInput;\n\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options: { returnId?: boolean; partial: true }\n): ToolCall | undefined;\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options?: { returnId?: boolean; partial?: false }\n): ToolCall;\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options?: { returnId?: boolean; partial?: boolean }\n): ToolCall | undefined;\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options?: { returnId?: boolean; partial?: boolean }\n): ToolCall | undefined {\n if (rawToolCall.function === undefined) {\n return undefined;\n }\n let functionArgs;\n if (options?.partial) {\n try {\n functionArgs = parsePartialJson(rawToolCall.function.arguments ?? \"{}\");\n } catch {\n return undefined;\n }\n } else {\n try {\n functionArgs = JSON.parse(rawToolCall.function.arguments);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (e: any) {\n throw new OutputParserException(\n [\n `Function \"${rawToolCall.function.name}\" arguments:`,\n ``,\n rawToolCall.function.arguments,\n ``,\n `are not valid JSON.`,\n `Error: ${e.message}`,\n ].join(\"\\n\")\n );\n }\n }\n\n const parsedToolCall: ToolCall = {\n name: rawToolCall.function.name,\n args: functionArgs,\n type: \"tool_call\",\n };\n\n if (options?.returnId) {\n parsedToolCall.id = rawToolCall.id;\n }\n\n return parsedToolCall;\n}\n\nexport function convertLangChainToolCallToOpenAI(toolCall: ToolCall) {\n if (toolCall.id === undefined) {\n throw new Error(`All OpenAI tool calls must have an \"id\" field.`);\n }\n return {\n id: toolCall.id,\n type: \"function\",\n function: {\n name: toolCall.name,\n arguments: JSON.stringify(toolCall.args),\n },\n };\n}\n\nexport function makeInvalidToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n errorMsg?: string\n): InvalidToolCall {\n return {\n name: rawToolCall.function?.name,\n args: rawToolCall.function?.arguments,\n id: rawToolCall.id,\n error: errorMsg,\n type: \"invalid_tool_call\",\n };\n}\n\n/**\n * Class for parsing the output of a tool-calling LLM into a JSON object.\n */\nexport class JsonOutputToolsParser<\n T,\n> extends BaseCumulativeTransformOutputParser<T> {\n static lc_name() {\n return \"JsonOutputToolsParser\";\n }\n\n returnId = false;\n\n lc_namespace = [\"langchain\", \"output_parsers\", \"openai_tools\"];\n\n lc_serializable = true;\n\n constructor(fields?: JsonOutputToolsParserParams) {\n super(fields);\n this.returnId = fields?.returnId ?? this.returnId;\n }\n\n protected _diff() {\n throw new Error(\"Not supported.\");\n }\n\n async parse(): Promise<T> {\n throw new Error(\"Not implemented.\");\n }\n\n async parseResult(generations: ChatGeneration[]): Promise<T> {\n const result = await this.parsePartialResult(generations, false);\n return result;\n }\n\n /**\n * Parses the output and returns a JSON object. If `argsOnly` is true,\n * only the arguments of the function call are returned.\n * @param generations The output of the LLM to parse.\n * @returns A JSON object representation of the function call or its arguments.\n */\n async parsePartialResult(\n generations: ChatGenerationChunk[] | ChatGeneration[],\n partial = true\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): Promise<any> {\n const message = generations[0].message;\n let toolCalls;\n if (isAIMessage(message) && message.tool_calls?.length) {\n toolCalls = message.tool_calls.map((toolCall) => {\n const { id, ...rest } = toolCall;\n if (!this.returnId) {\n return rest;\n }\n return {\n id,\n ...rest,\n };\n });\n } else if (message.additional_kwargs.tool_calls !== undefined) {\n const rawToolCalls = JSON.parse(\n JSON.stringify(message.additional_kwargs.tool_calls)\n );\n toolCalls = rawToolCalls.map((rawToolCall: Record<string, unknown>) => {\n return parseToolCall(rawToolCall, { returnId: this.returnId, partial });\n });\n }\n if (!toolCalls) {\n return [];\n }\n const parsedToolCalls = [];\n for (const toolCall of toolCalls) {\n if (toolCall !== undefined) {\n const backwardsCompatibleToolCall: ParsedToolCall = {\n type: toolCall.name,\n args: toolCall.args,\n id: toolCall.id,\n };\n parsedToolCalls.push(backwardsCompatibleToolCall);\n }\n }\n return parsedToolCalls;\n }\n}\n\ntype JsonOutputKeyToolsParserParamsBase = {\n keyName: string;\n returnSingle?: boolean;\n} & JsonOutputToolsParserParams;\n\ntype JsonOutputKeyToolsParserParamsV3<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = { zodSchema?: z3.ZodType<T> } & JsonOutputKeyToolsParserParamsBase;\n\ntype JsonOutputKeyToolsParserParamsV4<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = { zodSchema?: z4.$ZodType<T, T> } & JsonOutputKeyToolsParserParamsBase;\n\nexport type JsonOutputKeyToolsParserParamsInterop<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = { zodSchema?: InteropZodType<T> } & JsonOutputKeyToolsParserParamsBase;\n\nexport type JsonOutputKeyToolsParserParamsSerializable<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = {\n serializableSchema?: SerializableSchema<T>;\n} & JsonOutputKeyToolsParserParamsBase;\n\n// Use Zod 3 for backwards compatibility\nexport type JsonOutputKeyToolsParserParams<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = JsonOutputKeyToolsParserParamsV3<T>;\n\n/**\n * Class for parsing the output of a tool-calling LLM into a JSON object if you are\n * expecting only a single tool to be called.\n */\nexport class JsonOutputKeyToolsParser<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> extends JsonOutputToolsParser<T> {\n static lc_name() {\n return \"JsonOutputKeyToolsParser\";\n }\n\n lc_namespace = [\"langchain\", \"output_parsers\", \"openai_tools\"];\n\n lc_serializable = true;\n\n returnId = false;\n\n /** The type of tool calls to return. */\n keyName: string;\n\n /** Whether to return only the first tool call. */\n returnSingle = false;\n\n zodSchema?: InteropZodType<T>;\n\n serializableSchema?: SerializableSchema<T>;\n\n constructor(params: JsonOutputKeyToolsParserParamsV3<T>);\n\n constructor(params: JsonOutputKeyToolsParserParamsV4<T>);\n\n constructor(params: JsonOutputKeyToolsParserParamsInterop<T>);\n\n constructor(\n params:\n | JsonOutputKeyToolsParserParamsV3<T>\n | JsonOutputKeyToolsParserParamsV4<T>\n | JsonOutputKeyToolsParserParamsInterop<T>\n | JsonOutputKeyToolsParserParamsSerializable<T>\n ) {\n super(params);\n this.keyName = params.keyName;\n this.returnSingle = params.returnSingle ?? this.returnSingle;\n if (\"zodSchema\" in params) {\n this.zodSchema = params.zodSchema;\n }\n if (\"serializableSchema\" in params) {\n this.serializableSchema = params.serializableSchema;\n }\n }\n\n protected async _validateResult(result: unknown): Promise<T> {\n if (this.serializableSchema !== undefined) {\n const validated =\n await this.serializableSchema[\"~standard\"].validate(result);\n if (validated.issues) {\n throw new OutputParserException(\n `Failed to parse. Text: \"${JSON.stringify(\n result,\n null,\n 2\n )}\". Error: ${JSON.stringify(validated.issues)}`,\n JSON.stringify(result, null, 2)\n );\n }\n return validated.value as T;\n }\n if (this.zodSchema === undefined) {\n return result as T;\n }\n const zodParsedResult = await interopSafeParseAsync(this.zodSchema, result);\n if (zodParsedResult.success) {\n return zodParsedResult.data;\n } else {\n throw new OutputParserException(\n `Failed to parse. Text: \"${JSON.stringify(\n result,\n null,\n 2\n )}\". Error: ${JSON.stringify(zodParsedResult.error?.issues)}`,\n JSON.stringify(result, null, 2)\n );\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async parsePartialResult(generations: ChatGeneration[]): Promise<any> {\n const results = await super.parsePartialResult(generations);\n const matchingResults = results.filter(\n (result: ParsedToolCall) => result.type === this.keyName\n );\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let returnedValues: ParsedToolCall[] | Record<string, any>[] =\n matchingResults;\n if (!matchingResults.length) {\n return undefined;\n }\n if (!this.returnId) {\n returnedValues = matchingResults.map(\n (result: ParsedToolCall) => result.args\n );\n }\n if (this.returnSingle) {\n return returnedValues[0];\n }\n return returnedValues;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async parseResult(generations: ChatGeneration[]): Promise<any> {\n const results = await super.parsePartialResult(generations, false);\n const matchingResults = results.filter(\n (result: ParsedToolCall) => result.type === this.keyName\n );\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let returnedValues: ParsedToolCall[] | Record<string, any>[] =\n matchingResults;\n if (!matchingResults.length) {\n return undefined;\n }\n if (!this.returnId) {\n returnedValues = matchingResults.map(\n (result: ParsedToolCall) => result.args\n );\n }\n if (this.returnSingle) {\n return this._validateResult(returnedValues[0]);\n }\n const toolCallResults = await Promise.all(\n returnedValues.map((value) => this._validateResult(value))\n );\n return toolCallResults;\n }\n}\n"],"mappings":";;;;;;;AA8CA,SAAgB,cAEd,aACA,SACsB;AACtB,KAAI,YAAY,aAAa,KAAA,EAC3B;CAEF,IAAI;AACJ,KAAI,SAAS,QACX,KAAI;AACF,iBAAeA,aAAAA,iBAAiB,YAAY,SAAS,aAAa,KAAK;SACjE;AACN;;KAGF,KAAI;AACF,iBAAe,KAAK,MAAM,YAAY,SAAS,UAAU;UAElD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AMG,YAAAA,sBAAsB,KAAK,WAAW,OAAO;AAC3E,MAAI,gBAAgB,QAClB,QAAO,gBAAgB;MAEvB,OAAM,IAAIH,aAAAA,sBACR,2BAA2B,KAAK,UAC9B,QACA,MACA,EACD,CAAC,YAAY,KAAK,UAAU,gBAAgB,OAAO,OAAO,IAC3D,KAAK,UAAU,QAAQ,MAAM,EAAE,CAChC;;CAKL,MAAM,mBAAmB,aAA6C;EAEpE,MAAM,mBADU,MAAM,MAAM,mBAAmB,YAAY,EAC3B,QAC7B,WAA2B,OAAO,SAAS,KAAK,QAClD;EAED,IAAI,iBACF;AACF,MAAI,CAAC,gBAAgB,OACnB;AAEF,MAAI,CAAC,KAAK,SACR,kBAAiB,gBAAgB,KAC9B,WAA2B,OAAO,KACpC;AAEH,MAAI,KAAK,aACP,QAAO,eAAe;AAExB,SAAO;;CAIT,MAAM,YAAY,aAA6C;EAE7D,MAAM,mBADU,MAAM,MAAM,mBAAmB,aAAa,MAAM,EAClC,QAC7B,WAA2B,OAAO,SAAS,KAAK,QAClD;EAED,IAAI,iBACF;AACF,MAAI,CAAC,gBAAgB,OACnB;AAEF,MAAI,CAAC,KAAK,SACR,kBAAiB,gBAAgB,KAC9B,WAA2B,OAAO,KACpC;AAEH,MAAI,KAAK,aACP,QAAO,KAAK,gBAAgB,eAAe,GAAG;AAKhD,SAHwB,MAAM,QAAQ,IACpC,eAAe,KAAK,UAAU,KAAK,gBAAgB,MAAM,CAAC,CAC3D"}
|
|
1
|
+
{"version":3,"file":"json_output_tools_parsers.cjs","names":["parsePartialJson","OutputParserException","BaseCumulativeTransformOutputParser","isAIMessage","interopSafeParseAsync"],"sources":["../../../src/output_parsers/openai_tools/json_output_tools_parsers.ts"],"sourcesContent":["import type { ZodV3Like, ZodV4Like } from \"../../utils/types/zod.js\";\nimport { ChatGeneration, ChatGenerationChunk } from \"../../outputs.js\";\nimport { OutputParserException } from \"../base.js\";\nimport { parsePartialJson } from \"../json.js\";\nimport { InvalidToolCall, ToolCall } from \"../../messages/tool.js\";\nimport {\n BaseCumulativeTransformOutputParser,\n BaseCumulativeTransformOutputParserInput,\n} from \"../transform.js\";\nimport { isAIMessage } from \"../../messages/ai.js\";\nimport {\n type InteropZodType,\n interopSafeParseAsync,\n} from \"../../utils/types/zod.js\";\nimport { SerializableSchema } from \"../../utils/standard_schema.js\";\n\nexport type ParsedToolCall = {\n id?: string;\n\n type: string;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n args: Record<string, any>;\n};\n\nexport type JsonOutputToolsParserParams = {\n /** Whether to return the tool call id. */\n returnId?: boolean;\n} & BaseCumulativeTransformOutputParserInput;\n\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options: { returnId?: boolean; partial: true }\n): ToolCall | undefined;\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options?: { returnId?: boolean; partial?: false }\n): ToolCall;\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options?: { returnId?: boolean; partial?: boolean }\n): ToolCall | undefined;\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options?: { returnId?: boolean; partial?: boolean }\n): ToolCall | undefined {\n if (rawToolCall.function === undefined) {\n return undefined;\n }\n let functionArgs;\n if (options?.partial) {\n try {\n functionArgs = parsePartialJson(rawToolCall.function.arguments ?? \"{}\");\n } catch {\n return undefined;\n }\n } else {\n try {\n functionArgs = JSON.parse(rawToolCall.function.arguments);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (e: any) {\n throw new OutputParserException(\n [\n `Function \"${rawToolCall.function.name}\" arguments:`,\n ``,\n rawToolCall.function.arguments,\n ``,\n `are not valid JSON.`,\n `Error: ${e.message}`,\n ].join(\"\\n\")\n );\n }\n }\n\n const parsedToolCall: ToolCall = {\n name: rawToolCall.function.name,\n args: functionArgs,\n type: \"tool_call\",\n };\n\n if (options?.returnId) {\n parsedToolCall.id = rawToolCall.id;\n }\n\n return parsedToolCall;\n}\n\nexport function convertLangChainToolCallToOpenAI(toolCall: ToolCall) {\n if (toolCall.id === undefined) {\n throw new Error(`All OpenAI tool calls must have an \"id\" field.`);\n }\n return {\n id: toolCall.id,\n type: \"function\",\n function: {\n name: toolCall.name,\n arguments: JSON.stringify(toolCall.args),\n },\n };\n}\n\nexport function makeInvalidToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n errorMsg?: string\n): InvalidToolCall {\n return {\n name: rawToolCall.function?.name,\n args: rawToolCall.function?.arguments,\n id: rawToolCall.id,\n error: errorMsg,\n type: \"invalid_tool_call\",\n };\n}\n\n/**\n * Class for parsing the output of a tool-calling LLM into a JSON object.\n */\nexport class JsonOutputToolsParser<\n T,\n> extends BaseCumulativeTransformOutputParser<T> {\n static lc_name() {\n return \"JsonOutputToolsParser\";\n }\n\n returnId = false;\n\n lc_namespace = [\"langchain\", \"output_parsers\", \"openai_tools\"];\n\n lc_serializable = true;\n\n constructor(fields?: JsonOutputToolsParserParams) {\n super(fields);\n this.returnId = fields?.returnId ?? this.returnId;\n }\n\n protected _diff() {\n throw new Error(\"Not supported.\");\n }\n\n async parse(): Promise<T> {\n throw new Error(\"Not implemented.\");\n }\n\n async parseResult(generations: ChatGeneration[]): Promise<T> {\n const result = await this.parsePartialResult(generations, false);\n return result;\n }\n\n /**\n * Parses the output and returns a JSON object. If `argsOnly` is true,\n * only the arguments of the function call are returned.\n * @param generations The output of the LLM to parse.\n * @returns A JSON object representation of the function call or its arguments.\n */\n async parsePartialResult(\n generations: ChatGenerationChunk[] | ChatGeneration[],\n partial = true\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): Promise<any> {\n const message = generations[0].message;\n let toolCalls;\n if (isAIMessage(message) && message.tool_calls?.length) {\n toolCalls = message.tool_calls.map((toolCall) => {\n const { id, ...rest } = toolCall;\n if (!this.returnId) {\n return rest;\n }\n return {\n id,\n ...rest,\n };\n });\n } else if (message.additional_kwargs.tool_calls !== undefined) {\n const rawToolCalls = JSON.parse(\n JSON.stringify(message.additional_kwargs.tool_calls)\n );\n toolCalls = rawToolCalls.map((rawToolCall: Record<string, unknown>) => {\n return parseToolCall(rawToolCall, { returnId: this.returnId, partial });\n });\n }\n if (!toolCalls) {\n return [];\n }\n const parsedToolCalls = [];\n for (const toolCall of toolCalls) {\n if (toolCall !== undefined) {\n const backwardsCompatibleToolCall: ParsedToolCall = {\n type: toolCall.name,\n args: toolCall.args,\n id: toolCall.id,\n };\n parsedToolCalls.push(backwardsCompatibleToolCall);\n }\n }\n return parsedToolCalls;\n }\n}\n\ntype JsonOutputKeyToolsParserParamsBase = {\n keyName: string;\n returnSingle?: boolean;\n} & JsonOutputToolsParserParams;\n\ntype JsonOutputKeyToolsParserParamsV3<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = { zodSchema?: ZodV3Like<T> } & JsonOutputKeyToolsParserParamsBase;\n\ntype JsonOutputKeyToolsParserParamsV4<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = { zodSchema?: ZodV4Like<T, T> } & JsonOutputKeyToolsParserParamsBase;\n\nexport type JsonOutputKeyToolsParserParamsInterop<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = { zodSchema?: InteropZodType<T> } & JsonOutputKeyToolsParserParamsBase;\n\nexport type JsonOutputKeyToolsParserParamsSerializable<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = {\n serializableSchema?: SerializableSchema<T>;\n} & JsonOutputKeyToolsParserParamsBase;\n\n// Use Zod 3 for backwards compatibility\nexport type JsonOutputKeyToolsParserParams<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = JsonOutputKeyToolsParserParamsV3<T>;\n\n/**\n * Class for parsing the output of a tool-calling LLM into a JSON object if you are\n * expecting only a single tool to be called.\n */\nexport class JsonOutputKeyToolsParser<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> extends JsonOutputToolsParser<T> {\n static lc_name() {\n return \"JsonOutputKeyToolsParser\";\n }\n\n lc_namespace = [\"langchain\", \"output_parsers\", \"openai_tools\"];\n\n lc_serializable = true;\n\n returnId = false;\n\n /** The type of tool calls to return. */\n keyName: string;\n\n /** Whether to return only the first tool call. */\n returnSingle = false;\n\n zodSchema?: InteropZodType<T>;\n\n serializableSchema?: SerializableSchema<T>;\n\n constructor(params: JsonOutputKeyToolsParserParamsV3<T>);\n\n constructor(params: JsonOutputKeyToolsParserParamsV4<T>);\n\n constructor(params: JsonOutputKeyToolsParserParamsInterop<T>);\n\n constructor(\n params:\n | JsonOutputKeyToolsParserParamsV3<T>\n | JsonOutputKeyToolsParserParamsV4<T>\n | JsonOutputKeyToolsParserParamsInterop<T>\n | JsonOutputKeyToolsParserParamsSerializable<T>\n ) {\n super(params);\n this.keyName = params.keyName;\n this.returnSingle = params.returnSingle ?? this.returnSingle;\n if (\"zodSchema\" in params) {\n this.zodSchema = params.zodSchema;\n }\n if (\"serializableSchema\" in params) {\n this.serializableSchema = params.serializableSchema;\n }\n }\n\n protected async _validateResult(result: unknown): Promise<T> {\n if (this.serializableSchema !== undefined) {\n const validated =\n await this.serializableSchema[\"~standard\"].validate(result);\n if (validated.issues) {\n throw new OutputParserException(\n `Failed to parse. Text: \"${JSON.stringify(\n result,\n null,\n 2\n )}\". Error: ${JSON.stringify(validated.issues)}`,\n JSON.stringify(result, null, 2)\n );\n }\n return validated.value as T;\n }\n if (this.zodSchema === undefined) {\n return result as T;\n }\n const zodParsedResult = await interopSafeParseAsync(this.zodSchema, result);\n if (zodParsedResult.success) {\n return zodParsedResult.data;\n } else {\n throw new OutputParserException(\n `Failed to parse. Text: \"${JSON.stringify(\n result,\n null,\n 2\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n )}\". Error: ${JSON.stringify((zodParsedResult.error as any)?.issues)}`,\n JSON.stringify(result, null, 2)\n );\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async parsePartialResult(generations: ChatGeneration[]): Promise<any> {\n const results = await super.parsePartialResult(generations);\n const matchingResults = results.filter(\n (result: ParsedToolCall) => result.type === this.keyName\n );\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let returnedValues: ParsedToolCall[] | Record<string, any>[] =\n matchingResults;\n if (!matchingResults.length) {\n return undefined;\n }\n if (!this.returnId) {\n returnedValues = matchingResults.map(\n (result: ParsedToolCall) => result.args\n );\n }\n if (this.returnSingle) {\n return returnedValues[0];\n }\n return returnedValues;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async parseResult(generations: ChatGeneration[]): Promise<any> {\n const results = await super.parsePartialResult(generations, false);\n const matchingResults = results.filter(\n (result: ParsedToolCall) => result.type === this.keyName\n );\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let returnedValues: ParsedToolCall[] | Record<string, any>[] =\n matchingResults;\n if (!matchingResults.length) {\n return undefined;\n }\n if (!this.returnId) {\n returnedValues = matchingResults.map(\n (result: ParsedToolCall) => result.args\n );\n }\n if (this.returnSingle) {\n return this._validateResult(returnedValues[0]);\n }\n const toolCallResults = await Promise.all(\n returnedValues.map((value) => this._validateResult(value))\n );\n return toolCallResults;\n }\n}\n"],"mappings":";;;;;;;AA6CA,SAAgB,cAEd,aACA,SACsB;AACtB,KAAI,YAAY,aAAa,KAAA,EAC3B;CAEF,IAAI;AACJ,KAAI,SAAS,QACX,KAAI;AACF,iBAAeA,aAAAA,iBAAiB,YAAY,SAAS,aAAa,KAAK;SACjE;AACN;;KAGF,KAAI;AACF,iBAAe,KAAK,MAAM,YAAY,SAAS,UAAU;UAElD,GAAQ;AACf,QAAM,I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KAAK,WAAW,OAAO;AAC3E,MAAI,gBAAgB,QAClB,QAAO,gBAAgB;MAEvB,OAAM,IAAIH,aAAAA,sBACR,2BAA2B,KAAK,UAC9B,QACA,MACA,EAED,CAAC,YAAY,KAAK,UAAW,gBAAgB,OAAe,OAAO,IACpE,KAAK,UAAU,QAAQ,MAAM,EAAE,CAChC;;CAKL,MAAM,mBAAmB,aAA6C;EAEpE,MAAM,mBADU,MAAM,MAAM,mBAAmB,YAAY,EAC3B,QAC7B,WAA2B,OAAO,SAAS,KAAK,QAClD;EAED,IAAI,iBACF;AACF,MAAI,CAAC,gBAAgB,OACnB;AAEF,MAAI,CAAC,KAAK,SACR,kBAAiB,gBAAgB,KAC9B,WAA2B,OAAO,KACpC;AAEH,MAAI,KAAK,aACP,QAAO,eAAe;AAExB,SAAO;;CAIT,MAAM,YAAY,aAA6C;EAE7D,MAAM,mBADU,MAAM,MAAM,mBAAmB,aAAa,MAAM,EAClC,QAC7B,WAA2B,OAAO,SAAS,KAAK,QAClD;EAED,IAAI,iBACF;AACF,MAAI,CAAC,gBAAgB,OACnB;AAEF,MAAI,CAAC,KAAK,SACR,kBAAiB,gBAAgB,KAC9B,WAA2B,OAAO,KACpC;AAEH,MAAI,KAAK,aACP,QAAO,KAAK,gBAAgB,eAAe,GAAG;AAKhD,SAHwB,MAAM,QAAQ,IACpC,eAAe,KAAK,UAAU,KAAK,gBAAgB,MAAM,CAAC,CAC3D"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { InvalidToolCall, ToolCall } from "../../messages/tool.cjs";
|
|
2
2
|
import { ChatGeneration, ChatGenerationChunk } from "../../outputs.cjs";
|
|
3
3
|
import { SerializableSchema } from "../../utils/standard_schema.cjs";
|
|
4
|
-
import { InteropZodType } from "../../utils/types/zod.cjs";
|
|
4
|
+
import { InteropZodType, ZodV3Like, ZodV4Like } from "../../utils/types/zod.cjs";
|
|
5
5
|
import { BaseCumulativeTransformOutputParser, BaseCumulativeTransformOutputParserInput } from "../transform.cjs";
|
|
6
|
-
import * as z3 from "zod/v3";
|
|
7
|
-
import * as z4 from "zod/v4/core";
|
|
8
6
|
|
|
9
7
|
//#region src/output_parsers/openai_tools/json_output_tools_parsers.d.ts
|
|
10
8
|
type ParsedToolCall = {
|
|
@@ -61,10 +59,10 @@ type JsonOutputKeyToolsParserParamsBase = {
|
|
|
61
59
|
returnSingle?: boolean;
|
|
62
60
|
} & JsonOutputToolsParserParams;
|
|
63
61
|
type JsonOutputKeyToolsParserParamsV3<T extends Record<string, any> = Record<string, any>> = {
|
|
64
|
-
zodSchema?:
|
|
62
|
+
zodSchema?: ZodV3Like<T>;
|
|
65
63
|
} & JsonOutputKeyToolsParserParamsBase;
|
|
66
64
|
type JsonOutputKeyToolsParserParamsV4<T extends Record<string, any> = Record<string, any>> = {
|
|
67
|
-
zodSchema?:
|
|
65
|
+
zodSchema?: ZodV4Like<T, T>;
|
|
68
66
|
} & JsonOutputKeyToolsParserParamsBase;
|
|
69
67
|
type JsonOutputKeyToolsParserParamsInterop<T extends Record<string, any> = Record<string, any>> = {
|
|
70
68
|
zodSchema?: InteropZodType<T>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json_output_tools_parsers.d.cts","names":[],"sources":["../../../src/output_parsers/openai_tools/json_output_tools_parsers.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"json_output_tools_parsers.d.cts","names":[],"sources":["../../../src/output_parsers/openai_tools/json_output_tools_parsers.ts"],"mappings":";;;;;;;KAgBY,cAAA;EACV,EAAA;EAEA,IAAA;EAGA,IAAA,EAAM,MAAA;AAAA;AAAA,KAGI,2BAAA;EANV,0CAQA,QAAA;AAAA,IACE,wCAAA;AAAA,iBAEY,aAAA,CAEd,WAAA,EAAa,MAAA,eACb,OAAA;EAAW,QAAA;EAAoB,OAAA;AAAA,IAC9B,QAAA;AAAA,iBACa,aAAA,CAEd,WAAA,EAAa,MAAA,eACb,OAAA;EAAY,QAAA;EAAoB,OAAA;AAAA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AAA,OACvB,OAAA,CAAA;EAIP,YAAA;EAEA,eAAA;EAEA,QAAA;EAlIgC;EAqIhC,OAAA;EAnI4C;EAsI5C,YAAA;EAEA,SAAA,GAAY,cAAA,CAAe,CAAA;EAE3B,kBAAA,GAAqB,kBAAA,CAAmB,CAAA;EAExC,WAAA,CAAY,MAAA,EAAQ,gCAAA,CAAiC,CAAA;EAErD,WAAA,CAAY,MAAA,EAAQ,gCAAA,CAAiC,CAAA;EAErD,WAAA,CAAY,MAAA,EAAQ,qCAAA,CAAsC,CAAA;EAAA,UAoB1C,eAAA,CAAgB,MAAA,YAAkB,OAAA,CAAQ,CAAA;EAoCpD,kBAAA,CAAmB,WAAA,EAAa,cAAA,KAAmB,OAAA;EAuBnD,WAAA,CAAY,WAAA,EAAa,cAAA,KAAmB,OAAA;AAAA"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { InvalidToolCall, ToolCall } from "../../messages/tool.js";
|
|
2
2
|
import { ChatGeneration, ChatGenerationChunk } from "../../outputs.js";
|
|
3
3
|
import { SerializableSchema } from "../../utils/standard_schema.js";
|
|
4
|
-
import { InteropZodType } from "../../utils/types/zod.js";
|
|
4
|
+
import { InteropZodType, ZodV3Like, ZodV4Like } from "../../utils/types/zod.js";
|
|
5
5
|
import { BaseCumulativeTransformOutputParser, BaseCumulativeTransformOutputParserInput } from "../transform.js";
|
|
6
|
-
import * as z3 from "zod/v3";
|
|
7
|
-
import * as z4 from "zod/v4/core";
|
|
8
6
|
|
|
9
7
|
//#region src/output_parsers/openai_tools/json_output_tools_parsers.d.ts
|
|
10
8
|
type ParsedToolCall = {
|
|
@@ -61,10 +59,10 @@ type JsonOutputKeyToolsParserParamsBase = {
|
|
|
61
59
|
returnSingle?: boolean;
|
|
62
60
|
} & JsonOutputToolsParserParams;
|
|
63
61
|
type JsonOutputKeyToolsParserParamsV3<T extends Record<string, any> = Record<string, any>> = {
|
|
64
|
-
zodSchema?:
|
|
62
|
+
zodSchema?: ZodV3Like<T>;
|
|
65
63
|
} & JsonOutputKeyToolsParserParamsBase;
|
|
66
64
|
type JsonOutputKeyToolsParserParamsV4<T extends Record<string, any> = Record<string, any>> = {
|
|
67
|
-
zodSchema?:
|
|
65
|
+
zodSchema?: ZodV4Like<T, T>;
|
|
68
66
|
} & JsonOutputKeyToolsParserParamsBase;
|
|
69
67
|
type JsonOutputKeyToolsParserParamsInterop<T extends Record<string, any> = Record<string, any>> = {
|
|
70
68
|
zodSchema?: InteropZodType<T>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json_output_tools_parsers.d.ts","names":[],"sources":["../../../src/output_parsers/openai_tools/json_output_tools_parsers.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"json_output_tools_parsers.d.ts","names":[],"sources":["../../../src/output_parsers/openai_tools/json_output_tools_parsers.ts"],"mappings":";;;;;;;KAgBY,cAAA;EACV,EAAA;EAEA,IAAA;EAGA,IAAA,EAAM,MAAA;AAAA;AAAA,KAGI,2BAAA;EANV,0CAQA,QAAA;AAAA,IACE,wCAAA;AAAA,iBAEY,aAAA,CAEd,WAAA,EAAa,MAAA,eACb,OAAA;EAAW,QAAA;EAAoB,OAAA;AAAA,IAC9B,QAAA;AAAA,iBACa,aAAA,CAEd,WAAA,EAAa,MAAA,eACb,OAAA;EAAY,QAAA;EAAoB,OAAA;AAAA,IAC/B,QAAA;AAAA,iBACa,aAAA,CAEd,WAAA,EAAa,MAAA,eACb,OAAA;EAAY,QAAA;EAAoB,OAAA;AAAA,IAC/B,QAAA;AAAA,iBA+Ca,gCAAA,CAAiC,QAAA,EAAU,QAAA;;;;;;;;iBAc3C,mBAAA,CAEd,WAAA,EAAa,MAAA,eACb,QAAA,YACC,eAAA;;;;cAaU,qBAAA,YAEH,mCAAA,CAAoC,CAAA;EAAA,OACrC,OAAA,CAAA;EAIP,QAAA;EAEA,YAAA;EAEA,eAAA;EAEA,WAAA,CAAY,MAAA,GAAS,2BAAA;EAAA,UAKX,KAAA,CAAA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AAA;EAoCpD,kBAAA,CAAmB,WAAA,EAAa,cAAA,KAAmB,OAAA;EAuBnD,WAAA,CAAY,WAAA,EAAa,cAAA,KAAmB,OAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json_output_tools_parsers.js","names":[],"sources":["../../../src/output_parsers/openai_tools/json_output_tools_parsers.ts"],"sourcesContent":["import type * as z3 from \"zod/v3\";\nimport type * as z4 from \"zod/v4/core\";\nimport { ChatGeneration, ChatGenerationChunk } from \"../../outputs.js\";\nimport { OutputParserException } from \"../base.js\";\nimport { parsePartialJson } from \"../json.js\";\nimport { InvalidToolCall, ToolCall } from \"../../messages/tool.js\";\nimport {\n BaseCumulativeTransformOutputParser,\n BaseCumulativeTransformOutputParserInput,\n} from \"../transform.js\";\nimport { isAIMessage } from \"../../messages/ai.js\";\nimport {\n type InteropZodType,\n interopSafeParseAsync,\n} from \"../../utils/types/zod.js\";\nimport { SerializableSchema } from \"../../utils/standard_schema.js\";\n\nexport type ParsedToolCall = {\n id?: string;\n\n type: string;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n args: Record<string, any>;\n};\n\nexport type JsonOutputToolsParserParams = {\n /** Whether to return the tool call id. */\n returnId?: boolean;\n} & BaseCumulativeTransformOutputParserInput;\n\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options: { returnId?: boolean; partial: true }\n): ToolCall | undefined;\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options?: { returnId?: boolean; partial?: false }\n): ToolCall;\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options?: { returnId?: boolean; partial?: boolean }\n): ToolCall | undefined;\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options?: { returnId?: boolean; partial?: boolean }\n): ToolCall | undefined {\n if (rawToolCall.function === undefined) {\n return undefined;\n }\n let functionArgs;\n if (options?.partial) {\n try {\n functionArgs = parsePartialJson(rawToolCall.function.arguments ?? \"{}\");\n } catch {\n return undefined;\n }\n } else {\n try {\n functionArgs = JSON.parse(rawToolCall.function.arguments);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (e: any) {\n throw new OutputParserException(\n [\n `Function \"${rawToolCall.function.name}\" arguments:`,\n ``,\n rawToolCall.function.arguments,\n ``,\n `are not valid JSON.`,\n `Error: ${e.message}`,\n ].join(\"\\n\")\n );\n }\n }\n\n const parsedToolCall: ToolCall = {\n name: rawToolCall.function.name,\n args: functionArgs,\n type: \"tool_call\",\n };\n\n if (options?.returnId) {\n parsedToolCall.id = rawToolCall.id;\n }\n\n return parsedToolCall;\n}\n\nexport function convertLangChainToolCallToOpenAI(toolCall: ToolCall) {\n if (toolCall.id === undefined) {\n throw new Error(`All OpenAI tool calls must have an \"id\" field.`);\n }\n return {\n id: toolCall.id,\n type: \"function\",\n function: {\n name: toolCall.name,\n arguments: JSON.stringify(toolCall.args),\n },\n };\n}\n\nexport function makeInvalidToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n errorMsg?: string\n): InvalidToolCall {\n return {\n name: rawToolCall.function?.name,\n args: rawToolCall.function?.arguments,\n id: rawToolCall.id,\n error: errorMsg,\n type: \"invalid_tool_call\",\n };\n}\n\n/**\n * Class for parsing the output of a tool-calling LLM into a JSON object.\n */\nexport class JsonOutputToolsParser<\n T,\n> extends BaseCumulativeTransformOutputParser<T> {\n static lc_name() {\n return \"JsonOutputToolsParser\";\n }\n\n returnId = false;\n\n lc_namespace = [\"langchain\", \"output_parsers\", \"openai_tools\"];\n\n lc_serializable = true;\n\n constructor(fields?: JsonOutputToolsParserParams) {\n super(fields);\n this.returnId = fields?.returnId ?? this.returnId;\n }\n\n protected _diff() {\n throw new Error(\"Not supported.\");\n }\n\n async parse(): Promise<T> {\n throw new Error(\"Not implemented.\");\n }\n\n async parseResult(generations: ChatGeneration[]): Promise<T> {\n const result = await this.parsePartialResult(generations, false);\n return result;\n }\n\n /**\n * Parses the output and returns a JSON object. If `argsOnly` is true,\n * only the arguments of the function call are returned.\n * @param generations The output of the LLM to parse.\n * @returns A JSON object representation of the function call or its arguments.\n */\n async parsePartialResult(\n generations: ChatGenerationChunk[] | ChatGeneration[],\n partial = true\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): Promise<any> {\n const message = generations[0].message;\n let toolCalls;\n if (isAIMessage(message) && message.tool_calls?.length) {\n toolCalls = message.tool_calls.map((toolCall) => {\n const { id, ...rest } = toolCall;\n if (!this.returnId) {\n return rest;\n }\n return {\n id,\n ...rest,\n };\n });\n } else if (message.additional_kwargs.tool_calls !== undefined) {\n const rawToolCalls = JSON.parse(\n JSON.stringify(message.additional_kwargs.tool_calls)\n );\n toolCalls = rawToolCalls.map((rawToolCall: Record<string, unknown>) => {\n return parseToolCall(rawToolCall, { returnId: this.returnId, partial });\n });\n }\n if (!toolCalls) {\n return [];\n }\n const parsedToolCalls = [];\n for (const toolCall of toolCalls) {\n if (toolCall !== undefined) {\n const backwardsCompatibleToolCall: ParsedToolCall = {\n type: toolCall.name,\n args: toolCall.args,\n id: toolCall.id,\n };\n parsedToolCalls.push(backwardsCompatibleToolCall);\n }\n }\n return parsedToolCalls;\n }\n}\n\ntype JsonOutputKeyToolsParserParamsBase = {\n keyName: string;\n returnSingle?: boolean;\n} & JsonOutputToolsParserParams;\n\ntype JsonOutputKeyToolsParserParamsV3<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = { zodSchema?: z3.ZodType<T> } & JsonOutputKeyToolsParserParamsBase;\n\ntype JsonOutputKeyToolsParserParamsV4<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = { zodSchema?: z4.$ZodType<T, T> } & JsonOutputKeyToolsParserParamsBase;\n\nexport type JsonOutputKeyToolsParserParamsInterop<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = { zodSchema?: InteropZodType<T> } & JsonOutputKeyToolsParserParamsBase;\n\nexport type JsonOutputKeyToolsParserParamsSerializable<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = {\n serializableSchema?: SerializableSchema<T>;\n} & JsonOutputKeyToolsParserParamsBase;\n\n// Use Zod 3 for backwards compatibility\nexport type JsonOutputKeyToolsParserParams<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = JsonOutputKeyToolsParserParamsV3<T>;\n\n/**\n * Class for parsing the output of a tool-calling LLM into a JSON object if you are\n * expecting only a single tool to be called.\n */\nexport class JsonOutputKeyToolsParser<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> extends JsonOutputToolsParser<T> {\n static lc_name() {\n return \"JsonOutputKeyToolsParser\";\n }\n\n lc_namespace = [\"langchain\", \"output_parsers\", \"openai_tools\"];\n\n lc_serializable = true;\n\n returnId = false;\n\n /** The type of tool calls to return. */\n keyName: string;\n\n /** Whether to return only the first tool call. */\n returnSingle = false;\n\n zodSchema?: InteropZodType<T>;\n\n serializableSchema?: SerializableSchema<T>;\n\n constructor(params: JsonOutputKeyToolsParserParamsV3<T>);\n\n constructor(params: JsonOutputKeyToolsParserParamsV4<T>);\n\n constructor(params: JsonOutputKeyToolsParserParamsInterop<T>);\n\n constructor(\n params:\n | JsonOutputKeyToolsParserParamsV3<T>\n | JsonOutputKeyToolsParserParamsV4<T>\n | JsonOutputKeyToolsParserParamsInterop<T>\n | JsonOutputKeyToolsParserParamsSerializable<T>\n ) {\n super(params);\n this.keyName = params.keyName;\n this.returnSingle = params.returnSingle ?? this.returnSingle;\n if (\"zodSchema\" in params) {\n this.zodSchema = params.zodSchema;\n }\n if (\"serializableSchema\" in params) {\n this.serializableSchema = params.serializableSchema;\n }\n }\n\n protected async _validateResult(result: unknown): Promise<T> {\n if (this.serializableSchema !== undefined) {\n const validated =\n await this.serializableSchema[\"~standard\"].validate(result);\n if (validated.issues) {\n throw new OutputParserException(\n `Failed to parse. Text: \"${JSON.stringify(\n result,\n null,\n 2\n )}\". Error: ${JSON.stringify(validated.issues)}`,\n JSON.stringify(result, null, 2)\n );\n }\n return validated.value as T;\n }\n if (this.zodSchema === undefined) {\n return result as T;\n }\n const zodParsedResult = await interopSafeParseAsync(this.zodSchema, result);\n if (zodParsedResult.success) {\n return zodParsedResult.data;\n } else {\n throw new OutputParserException(\n `Failed to parse. Text: \"${JSON.stringify(\n result,\n null,\n 2\n )}\". Error: ${JSON.stringify(zodParsedResult.error?.issues)}`,\n JSON.stringify(result, null, 2)\n );\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async parsePartialResult(generations: ChatGeneration[]): Promise<any> {\n const results = await super.parsePartialResult(generations);\n const matchingResults = results.filter(\n (result: ParsedToolCall) => result.type === this.keyName\n );\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let returnedValues: ParsedToolCall[] | Record<string, any>[] =\n matchingResults;\n if (!matchingResults.length) {\n return undefined;\n }\n if (!this.returnId) {\n returnedValues = matchingResults.map(\n (result: ParsedToolCall) => result.args\n );\n }\n if (this.returnSingle) {\n return returnedValues[0];\n }\n return returnedValues;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async parseResult(generations: ChatGeneration[]): Promise<any> {\n const results = await super.parsePartialResult(generations, false);\n const matchingResults = results.filter(\n (result: ParsedToolCall) => result.type === this.keyName\n );\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let returnedValues: ParsedToolCall[] | Record<string, any>[] =\n matchingResults;\n if (!matchingResults.length) {\n return undefined;\n }\n if (!this.returnId) {\n returnedValues = matchingResults.map(\n (result: ParsedToolCall) => result.args\n );\n }\n if (this.returnSingle) {\n return this._validateResult(returnedValues[0]);\n }\n const toolCallResults = await Promise.all(\n returnedValues.map((value) => this._validateResult(value))\n );\n return toolCallResults;\n }\n}\n"],"mappings":";;;;;;;AA8CA,SAAgB,cAEd,aACA,SACsB;AACtB,KAAI,YAAY,aAAa,KAAA,EAC3B;CAEF,IAAI;AACJ,KAAI,SAAS,QACX,KAAI;AACF,iBAAe,iBAAiB,YAAY,SAAS,aAAa,KAAK;SACjE;AACN;;KAGF,KAAI;AACF,iBAAe,KAAK,MAAM,YAAY,SAAS,UAAU;UAElD,GAAQ;AACf,QAAM,IAAI,sBACR;GACE,aAAa,YAAY,SAAS,KAAK;GACvC;GACA,YAAY,SAAS;GACrB;GACA;GACA,UAAU,EAAE;GACb,CAAC,KAAK,KAAK,CACb;;CAIL,MAAM,iBAA2B;EAC/B,MAAM,YAAY,SAAS;EAC3B,MAAM;EACN,MAAM;EACP;AAED,KAAI,SAAS,SACX,gBAAe,KAAK,YAAY;AAGlC,QAAO;;AAGT,SAAgB,iCAAiC,UAAoB;AACnE,KAAI,SAAS,OAAO,KAAA,EAClB,OAAM,IAAI,MAAM,iDAAiD;AAEnE,QAAO;EACL,IAAI,SAAS;EACb,MAAM;EACN,UAAU;GACR,MAAM,SAAS;GACf,WAAW,KAAK,UAAU,SAAS,KAAK;GACzC;EACF;;AAGH,SAAgB,oBAEd,aACA,UACiB;AACjB,QAAO;EACL,MAAM,YAAY,UAAU;EAC5B,MAAM,YAAY,UAAU;EAC5B,IAAI,YAAY;EAChB,OAAO;EACP,MAAM;EACP;;;;;AAMH,IAAa,wBAAb,cAEU,oCAAuC;CAC/C,OAAO,UAAU;AACf,SAAO;;CAGT,WAAW;CAEX,eAAe;EAAC;EAAa;EAAkB;EAAe;CAE9D,kBAAkB;CAElB,YAAY,QAAsC;AAChD,QAAM,OAAO;AACb,OAAK,WAAW,QAAQ,YAAY,KAAK;;CAG3C,QAAkB;AAChB,QAAM,IAAI,MAAM,iBAAiB;;CAGnC,MAAM,QAAoB;AACx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ers.js","names":[],"sources":["../../../src/output_parsers/openai_tools/json_output_tools_parsers.ts"],"sourcesContent":["import type { ZodV3Like, ZodV4Like } from \"../../utils/types/zod.js\";\nimport { ChatGeneration, ChatGenerationChunk } from \"../../outputs.js\";\nimport { OutputParserException } from \"../base.js\";\nimport { parsePartialJson } from \"../json.js\";\nimport { InvalidToolCall, ToolCall } from \"../../messages/tool.js\";\nimport {\n BaseCumulativeTransformOutputParser,\n BaseCumulativeTransformOutputParserInput,\n} from \"../transform.js\";\nimport { isAIMessage } from \"../../messages/ai.js\";\nimport {\n type InteropZodType,\n interopSafeParseAsync,\n} from \"../../utils/types/zod.js\";\nimport { SerializableSchema } from \"../../utils/standard_schema.js\";\n\nexport type ParsedToolCall = {\n id?: string;\n\n type: string;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n args: Record<string, any>;\n};\n\nexport type JsonOutputToolsParserParams = {\n /** Whether to return the tool call id. */\n returnId?: boolean;\n} & BaseCumulativeTransformOutputParserInput;\n\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options: { returnId?: boolean; partial: true }\n): ToolCall | undefined;\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options?: { returnId?: boolean; partial?: false }\n): ToolCall;\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options?: { returnId?: boolean; partial?: boolean }\n): ToolCall | undefined;\nexport function parseToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n options?: { returnId?: boolean; partial?: boolean }\n): ToolCall | undefined {\n if (rawToolCall.function === undefined) {\n return undefined;\n }\n let functionArgs;\n if (options?.partial) {\n try {\n functionArgs = parsePartialJson(rawToolCall.function.arguments ?? \"{}\");\n } catch {\n return undefined;\n }\n } else {\n try {\n functionArgs = JSON.parse(rawToolCall.function.arguments);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (e: any) {\n throw new OutputParserException(\n [\n `Function \"${rawToolCall.function.name}\" arguments:`,\n ``,\n rawToolCall.function.arguments,\n ``,\n `are not valid JSON.`,\n `Error: ${e.message}`,\n ].join(\"\\n\")\n );\n }\n }\n\n const parsedToolCall: ToolCall = {\n name: rawToolCall.function.name,\n args: functionArgs,\n type: \"tool_call\",\n };\n\n if (options?.returnId) {\n parsedToolCall.id = rawToolCall.id;\n }\n\n return parsedToolCall;\n}\n\nexport function convertLangChainToolCallToOpenAI(toolCall: ToolCall) {\n if (toolCall.id === undefined) {\n throw new Error(`All OpenAI tool calls must have an \"id\" field.`);\n }\n return {\n id: toolCall.id,\n type: \"function\",\n function: {\n name: toolCall.name,\n arguments: JSON.stringify(toolCall.args),\n },\n };\n}\n\nexport function makeInvalidToolCall(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCall: Record<string, any>,\n errorMsg?: string\n): InvalidToolCall {\n return {\n name: rawToolCall.function?.name,\n args: rawToolCall.function?.arguments,\n id: rawToolCall.id,\n error: errorMsg,\n type: \"invalid_tool_call\",\n };\n}\n\n/**\n * Class for parsing the output of a tool-calling LLM into a JSON object.\n */\nexport class JsonOutputToolsParser<\n T,\n> extends BaseCumulativeTransformOutputParser<T> {\n static lc_name() {\n return \"JsonOutputToolsParser\";\n }\n\n returnId = false;\n\n lc_namespace = [\"langchain\", \"output_parsers\", \"openai_tools\"];\n\n lc_serializable = true;\n\n constructor(fields?: JsonOutputToolsParserParams) {\n super(fields);\n this.returnId = fields?.returnId ?? this.returnId;\n }\n\n protected _diff() {\n throw new Error(\"Not supported.\");\n }\n\n async parse(): Promise<T> {\n throw new Error(\"Not implemented.\");\n }\n\n async parseResult(generations: ChatGeneration[]): Promise<T> {\n const result = await this.parsePartialResult(generations, false);\n return result;\n }\n\n /**\n * Parses the output and returns a JSON object. If `argsOnly` is true,\n * only the arguments of the function call are returned.\n * @param generations The output of the LLM to parse.\n * @returns A JSON object representation of the function call or its arguments.\n */\n async parsePartialResult(\n generations: ChatGenerationChunk[] | ChatGeneration[],\n partial = true\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): Promise<any> {\n const message = generations[0].message;\n let toolCalls;\n if (isAIMessage(message) && message.tool_calls?.length) {\n toolCalls = message.tool_calls.map((toolCall) => {\n const { id, ...rest } = toolCall;\n if (!this.returnId) {\n return rest;\n }\n return {\n id,\n ...rest,\n };\n });\n } else if (message.additional_kwargs.tool_calls !== undefined) {\n const rawToolCalls = JSON.parse(\n JSON.stringify(message.additional_kwargs.tool_calls)\n );\n toolCalls = rawToolCalls.map((rawToolCall: Record<string, unknown>) => {\n return parseToolCall(rawToolCall, { returnId: this.returnId, partial });\n });\n }\n if (!toolCalls) {\n return [];\n }\n const parsedToolCalls = [];\n for (const toolCall of toolCalls) {\n if (toolCall !== undefined) {\n const backwardsCompatibleToolCall: ParsedToolCall = {\n type: toolCall.name,\n args: toolCall.args,\n id: toolCall.id,\n };\n parsedToolCalls.push(backwardsCompatibleToolCall);\n }\n }\n return parsedToolCalls;\n }\n}\n\ntype JsonOutputKeyToolsParserParamsBase = {\n keyName: string;\n returnSingle?: boolean;\n} & JsonOutputToolsParserParams;\n\ntype JsonOutputKeyToolsParserParamsV3<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = { zodSchema?: ZodV3Like<T> } & JsonOutputKeyToolsParserParamsBase;\n\ntype JsonOutputKeyToolsParserParamsV4<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = { zodSchema?: ZodV4Like<T, T> } & JsonOutputKeyToolsParserParamsBase;\n\nexport type JsonOutputKeyToolsParserParamsInterop<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = { zodSchema?: InteropZodType<T> } & JsonOutputKeyToolsParserParamsBase;\n\nexport type JsonOutputKeyToolsParserParamsSerializable<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = {\n serializableSchema?: SerializableSchema<T>;\n} & JsonOutputKeyToolsParserParamsBase;\n\n// Use Zod 3 for backwards compatibility\nexport type JsonOutputKeyToolsParserParams<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> = JsonOutputKeyToolsParserParamsV3<T>;\n\n/**\n * Class for parsing the output of a tool-calling LLM into a JSON object if you are\n * expecting only a single tool to be called.\n */\nexport class JsonOutputKeyToolsParser<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> extends JsonOutputToolsParser<T> {\n static lc_name() {\n return \"JsonOutputKeyToolsParser\";\n }\n\n lc_namespace = [\"langchain\", \"output_parsers\", \"openai_tools\"];\n\n lc_serializable = true;\n\n returnId = false;\n\n /** The type of tool calls to return. */\n keyName: string;\n\n /** Whether to return only the first tool call. */\n returnSingle = false;\n\n zodSchema?: InteropZodType<T>;\n\n serializableSchema?: SerializableSchema<T>;\n\n constructor(params: JsonOutputKeyToolsParserParamsV3<T>);\n\n constructor(params: JsonOutputKeyToolsParserParamsV4<T>);\n\n constructor(params: JsonOutputKeyToolsParserParamsInterop<T>);\n\n constructor(\n params:\n | JsonOutputKeyToolsParserParamsV3<T>\n | JsonOutputKeyToolsParserParamsV4<T>\n | JsonOutputKeyToolsParserParamsInterop<T>\n | JsonOutputKeyToolsParserParamsSerializable<T>\n ) {\n super(params);\n this.keyName = params.keyName;\n this.returnSingle = params.returnSingle ?? this.returnSingle;\n if (\"zodSchema\" in params) {\n this.zodSchema = params.zodSchema;\n }\n if (\"serializableSchema\" in params) {\n this.serializableSchema = params.serializableSchema;\n }\n }\n\n protected async _validateResult(result: unknown): Promise<T> {\n if (this.serializableSchema !== undefined) {\n const validated =\n await this.serializableSchema[\"~standard\"].validate(result);\n if (validated.issues) {\n throw new OutputParserException(\n `Failed to parse. Text: \"${JSON.stringify(\n result,\n null,\n 2\n )}\". Error: ${JSON.stringify(validated.issues)}`,\n JSON.stringify(result, null, 2)\n );\n }\n return validated.value as T;\n }\n if (this.zodSchema === undefined) {\n return result as T;\n }\n const zodParsedResult = await interopSafeParseAsync(this.zodSchema, result);\n if (zodParsedResult.success) {\n return zodParsedResult.data;\n } else {\n throw new OutputParserException(\n `Failed to parse. Text: \"${JSON.stringify(\n result,\n null,\n 2\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n )}\". Error: ${JSON.stringify((zodParsedResult.error as any)?.issues)}`,\n JSON.stringify(result, null, 2)\n );\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async parsePartialResult(generations: ChatGeneration[]): Promise<any> {\n const results = await super.parsePartialResult(generations);\n const matchingResults = results.filter(\n (result: ParsedToolCall) => result.type === this.keyName\n );\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let returnedValues: ParsedToolCall[] | Record<string, any>[] =\n matchingResults;\n if (!matchingResults.length) {\n return undefined;\n }\n if (!this.returnId) {\n returnedValues = matchingResults.map(\n (result: ParsedToolCall) => result.args\n );\n }\n if (this.returnSingle) {\n return returnedValues[0];\n }\n return returnedValues;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async parseResult(generations: ChatGeneration[]): Promise<any> {\n const results = await super.parsePartialResult(generations, false);\n const matchingResults = results.filter(\n (result: ParsedToolCall) => result.type === this.keyName\n );\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let returnedValues: ParsedToolCall[] | Record<string, any>[] =\n matchingResults;\n if (!matchingResults.length) {\n return undefined;\n }\n if (!this.returnId) {\n returnedValues = matchingResults.map(\n (result: ParsedToolCall) => result.args\n );\n }\n if (this.returnSingle) {\n return this._validateResult(returnedValues[0]);\n }\n const toolCallResults = await Promise.all(\n returnedValues.map((value) => this._validateResult(value))\n );\n return toolCallResults;\n }\n}\n"],"mappings":";;;;;;;AA6CA,SAAgB,cAEd,aACA,SACsB;A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AAY,KAAK,UAAU,UAAU,OAAO,IAC9C,KAAK,UAAU,QAAQ,MAAM,EAAE,CAChC;AAEH,UAAO,UAAU;;AAEnB,MAAI,KAAK,cAAc,KAAA,EACrB,QAAO;EAET,MAAM,kBAAkB,MAAM,sBAAsB,KAAK,WAAW,OAAO;AAC3E,MAAI,gBAAgB,QAClB,QAAO,gBAAgB;MAEvB,OAAM,IAAI,sBACR,2BAA2B,KAAK,UAC9B,QACA,MACA,EAED,CAAC,YAAY,KAAK,UAAW,gBAAgB,OAAe,OAAO,IACpE,KAAK,UAAU,QAAQ,MAAM,EAAE,CAChC;;CAKL,MAAM,mBAAmB,aAA6C;EAEpE,MAAM,mBADU,MAAM,MAAM,mBAAmB,YAAY,EAC3B,QAC7B,WAA2B,OAAO,SAAS,KAAK,QAClD;EAED,IAAI,iBACF;AACF,MAAI,CAAC,gBAAgB,OACnB;AAEF,MAAI,CAAC,KAAK,SACR,kBAAiB,gBAAgB,KAC9B,WAA2B,OAAO,KACpC;AAEH,MAAI,KAAK,aACP,QAAO,eAAe;AAExB,SAAO;;CAIT,MAAM,YAAY,aAA6C;EAE7D,MAAM,mBADU,MAAM,MAAM,mBAAmB,aAAa,MAAM,EAClC,QAC7B,WAA2B,OAAO,SAAS,KAAK,QAClD;EAED,IAAI,iBACF;AACF,MAAI,CAAC,gBAAgB,OACnB;AAEF,MAAI,CAAC,KAAK,SACR,kBAAiB,gBAAgB,KAC9B,WAA2B,OAAO,KACpC;AAEH,MAAI,KAAK,aACP,QAAO,KAAK,gBAAgB,eAAe,GAAG;AAKhD,SAHwB,MAAM,QAAQ,IACpC,eAAe,KAAK,UAAU,KAAK,gBAAgB,MAAM,CAAC,CAC3D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structured.d.ts","names":[],"sources":["../../src/prompts/structured.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"structured.d.ts","names":[],"sources":["../../src/prompts/structured.ts"],"mappings":";;;;;;;;;AAkCA;UAAiB,qBAAA,kBAEE,WAAA,0DAGT,uBAAA,CAAwB,QAAA,EAAU,mBAAA;EAE1C,MAAA,EAAQ,MAAA;EACR,MAAA;AAAA;AAAA,cAGW,gBAAA,kBAEM,WAAA,0DAIT,kBAAA,CAAmB,QAAA,EAAU,mBAAA,aAC1B,qBAAA,CAAsB,QAAA,EAAU,mBAAA;EAG3C,MAAA,EAAQ,MAAA;EAER,MAAA;EAEA,YAAA;EAAA,IAEI,UAAA,CAAA,GAAc,MAAA;EAOlB,WAAA,CAAY,KAAA,EAAO,qBAAA,CAAsB,QAAA,EAAU,mBAAA;EAMnD,IAAA,cAAA,CACE,UAAA,EAAY,YAAA,CAAa,wBAAA,EAA0B,YAAA,IAClD,QAAA,CAAS,QAAA,EAAU,OAAA,CAAQ,YAAA,EAAc,KAAA,GAAQ,cAAA;EAAA,OA4B7C,qBAAA,kBAAuC,WAAA,OAAA,CAC5C,cAAA,GACI,kBAAA,CAAmB,WAAA,YACnB,6BAAA,KAEJ,MAAA,EAAQ,qBAAA,YACR,MAAA,gDAEC,kBAAA,CAAmB,QAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/retrievers/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/retrievers/index.ts"],"mappings":";;;;;;;;AA8BA;;;;;;;;;;;;AAiBA;;;;;;UAjBiB,kBAAA;EACf,SAAA,GAAY,SAAA;EACZ,IAAA;EACA,QAAA,GAAW,MAAA;EACX,OAAA;AAAA;;;;;;;AA8BF;;;;UAjBiB,sBAAA,kBAEE,MAAA,gBAAsB,MAAA,uBAC/B,iBAAA,SAA0B,iBAAA,CAAkB,QAAA;;;;;;;;;;;;;uBAchC,aAAA,kBAEH,MAAA,gBAAsB,MAAA,uBAE/B,QAAA,SAAiB,iBAAA,CAAkB,QAAA,gBAChC,sBAAA;EAAA;;;EAKX,SAAA,GAAY,SAAA;EARK;;;EAajB,IAAA;EAX2C;;;;EAiB3C,QAAA,GAAW,MAAA;EAAX;;;EAKA,OAAA;EAQqB;;;;;;EAArB,WAAA,CAAY,MAAA,GAAS,kBAAA;EA8BV;;;;;EAeT;;;;;;;;;;;;;;EAlBF,qBAAA,CACE,MAAA,UACA,UAAA,GAAa,8BAAA,GACZ,OAAA,CAAQ,iBAAA,CAAkB,QAAA;;;;;;;;;;EAavB,MAAA,CACJ,KAAA,UACA,OAAA,GAAU,cAAA,GACT,OAAA,CAAQ,iBAAA,CAAkB,QAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"branch.d.ts","names":[],"sources":["../../src/runnables/branch.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"branch.d.ts","names":[],"sources":["../../src/runnables/branch.ts"],"mappings":";;;;;;;AAoBA;;;;KAAY,MAAA,yBACV,QAAA,CAAS,QAAA,YACT,QAAA,CAAS,QAAA,EAAU,SAAA;AAAA,KAGT,UAAA,yBACV,YAAA,CAAa,QAAA,YACb,YAAA,CAAa,QAAA,EAAU,SAAA;;;;;;;;AAFzB;;;;;;;;;;;;;;;;;;;AAyCA;;;;;;;;;cAAa,cAAA,0CAAwD,QAAA,CACnE,QAAA,EACA,SAAA;EAAA,OAEO,OAAA,CAAA;EAIP,YAAA;EAEA,eAAA;EAEA,OAAA,EAAS,QAAA,CAAS,QAAA,EAAU,SAAA;EAE5B,QAAA,EAAU,MAAA,CAAO,QAAA,EAAU,SAAA;EAE3B,WAAA,CAAY,MAAA;IACV,QAAA,EAAU,MAAA,CAAO,QAAA,EAAU,SAAA;IAC3B,OAAA,EAAS,QAAA,CAAS,QAAA,EAAU,SAAA;EAAA;EAmCvB;;;;;;;;;;;;;;;;;;;;;;;;;EAAA,OAFA,IAAA,iCAAA,CACL,QAAA,MACK,UAAA,CAAW,QAAA,EAAU,SAAA,KACxB,YAAA,CAAa,QAAA,EAAU,SAAA,KACxB,cAAA,CAAA,QAAA,EAAA,SAAA;EAwBG,OAAA,CACJ,KAAA,EAAO,QAAA,EACP,MAAA,GAAS,OAAA,CAAQ,cAAA,GACjB,UAAA,GAAa,0BAAA,GACZ,OAAA,CAAQ,SAAA;EA+BL,MAAA,CACJ,KAAA,EAAO,QAAA,EACP,MAAA,GAAQ,cAAA,GACP,OAAA,CAAQ,SAAA;EAIJ,eAAA,CAAgB,KAAA,EAAO,QAAA,EAAU,MAAA,GAAS,OAAA,CAAQ,cAAA,IAAe,cAAA,CAAA,OAAA,CAAA,SAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.d.ts","names":[],"sources":["../../src/runnables/history.ts"],"mappings":";;;;;;;KAoBK,yBAAA,OAEA,IAAA,EAAM,KAAA,UAEP,OAAA,CAAQ,sBAAA,GAAyB,0BAAA,IACjC,sBAAA,GACA,0BAAA;AAAA,UAEa,gCAAA,8BAGP,IAAA,CAAK,mBAAA,CAAoB,QAAA,EAAU,SAAA;EAC3C,QAAA,EAAU,QAAA,CAAS,QAAA,EAAU,SAAA;EAC7B,iBAAA,EAAmB,yBAAA;EACnB,gBAAA;EACA,iBAAA;EACA,kBAAA;EACA,MAAA,GAAS,cAAA;AAAA
|
|
1
|
+
{"version":3,"file":"history.d.ts","names":[],"sources":["../../src/runnables/history.ts"],"mappings":";;;;;;;KAoBK,yBAAA,OAEA,IAAA,EAAM,KAAA,UAEP,OAAA,CAAQ,sBAAA,GAAyB,0BAAA,IACjC,sBAAA,GACA,0BAAA;AAAA,UAEa,gCAAA,8BAGP,IAAA,CAAK,mBAAA,CAAoB,QAAA,EAAU,SAAA;EAC3C,QAAA,EAAU,QAAA,CAAS,QAAA,EAAU,SAAA;EAC7B,iBAAA,EAAmB,yBAAA;EACnB,gBAAA;EACA,iBAAA;EACA,kBAAA;EACA,MAAA,GAAS,cAAA;AAAA;;;;;;;;;;;;;;;AATX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EA;;;;;;;;;;;;;;;;;cAAa,0BAAA,8BAGH,eAAA,CAAgB,QAAA,EAAU,SAAA;EAClC,QAAA,EAAU,QAAA,CAAS,QAAA,EAAU,SAAA;EAE7B,gBAAA;EAEA,iBAAA;EAEA,kBAAA;EAEA,iBAAA,EAAmB,yBAAA;EAEnB,WAAA,CAAY,MAAA,EAAQ,gCAAA,CAAiC,QAAA,EAAU,SAAA;EAkC/D,iBAAA,CAEE,UAAA,WAAqB,WAAA,GAAc,KAAA,CAAM,WAAA,IAAe,MAAA,gBACvD,KAAA,CAAM,WAAA;EAwCT,kBAAA,CAEE,WAAA,WAAsB,WAAA,GAAc,KAAA,CAAM,WAAA,IAAe,MAAA,gBACxD,KAAA,CAAM,WAAA;EA2CH,aAAA,CAEJ,KAAA,OACA,MAAA,GAAS,cAAA,GACR,OAAA,CAAQ,WAAA;EASL,YAAA,CAAa,GAAA,EAAK,GAAA,EAAK,MAAA,EAAQ,cAAA,GAAiB,OAAA;EAiChD,YAAA,CAAA,GAAgB,OAAA,EAAS,KAAA,CAAM,cAAA,gBAA2B,OAAA,CAAA,OAAA,CAAA,cAAA,CAAA,MAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"passthrough.d.ts","names":[],"sources":["../../src/runnables/passthrough.ts"],"mappings":";;;;KAUK,uBAAA,qBACC,KAAA,EAAO,QAAA,eACP,KAAA,EAAO,QAAA,EAAU,MAAA,GAAS,cAAA,eAC1B,KAAA,EAAO,QAAA,KAAa,OAAA,YACpB,KAAA,EAAO,QAAA,EAAU,MAAA,GAAS,cAAA,KAAmB,OAAA
|
|
1
|
+
{"version":3,"file":"passthrough.d.ts","names":[],"sources":["../../src/runnables/passthrough.ts"],"mappings":";;;;KAUK,uBAAA,qBACC,KAAA,EAAO,QAAA,eACP,KAAA,EAAO,QAAA,EAAU,MAAA,GAAS,cAAA,eAC1B,KAAA,EAAO,QAAA,KAAa,OAAA,YACpB,KAAA,EAAO,QAAA,EAAU,MAAA,GAAS,cAAA,KAAmB,OAAA;;AAPa;;;;;;;;;;;;;;;;;;;;;;;;;cAoCnD,mBAAA,yBAA4C,QAAA,CACvD,QAAA,EACA,QAAA;EAAA,OAEO,OAAA,CAAA;EAIP,YAAA;EAEA,eAAA;EAEA,IAAA,GAAO,uBAAA,CAAwB,QAAA;EAE/B,WAAA,CAAY,MAAA;IAAW,IAAA,GAAO,uBAAA,CAAwB,QAAA;EAAA;EAOhD,MAAA,CACJ,KAAA,EAAO,QAAA,EACP,OAAA,GAAU,OAAA,CAAQ,cAAA,IACjB,OAAA,CAAQ,QAAA;EAaJ,SAAA,CACL,SAAA,EAAW,cAAA,CAAe,QAAA,GAC1B,OAAA,EAAS,OAAA,CAAQ,cAAA,IAChB,cAAA,CAAe,QAAA;EA5Ba;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAA,OAuFxB,MAAA,kBACY,MAAA,oBAA0B,MAAA,qCACzB,MAAA,oBAA0B,MAAA,kBAAA,CAE5C,OAAA,EAAS,eAAA,CAAgB,QAAA,EAAU,SAAA,IAClC,cAAA,CAAe,QAAA,EAAU,QAAA,GAAW,SAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","names":[],"sources":["../../src/runnables/router.ts"],"mappings":";;;;;KAIY,WAAA;EACV,GAAA;EAEA,KAAA;AAAA
|
|
1
|
+
{"version":3,"file":"router.d.ts","names":[],"sources":["../../src/runnables/router.ts"],"mappings":";;;;;KAIY,WAAA;EACV,GAAA;EAEA,KAAA;AAAA;;;;AA8BF;;;;;;;;;;;;;;;;;;;;;;;;cAAa,cAAA,kBACM,WAAA,oCAGT,QAAA,CAAS,QAAA,EAAU,SAAA;EAAA,OACpB,OAAA,CAAA;EAIP,YAAA;EAEA,eAAA;EAEA,SAAA,EAAW,MAAA,SAAe,QAAA,CAAS,aAAA,EAAe,SAAA;EAElD,WAAA,CAAY,MAAA;IACV,SAAA,EAAW,MAAA,SAAe,QAAA,CAAS,aAAA,EAAe,SA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