@langchain/core 1.4.0 → 1.4.1
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 +6 -0
- package/dist/language_models/base.cjs +1 -1
- package/dist/language_models/base.js +1 -1
- package/dist/messages/base.cjs +4 -1
- 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 +4 -1
- package/dist/messages/base.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @langchain/core
|
|
2
2
|
|
|
3
|
+
## 1.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#12230](https://github.com/langchain-ai/langchainjs/pull/12230) [`84e85cc`](https://github.com/langchain-ai/langchainjs/commit/84e85cc8657a6922c9db34ff7a2a1a692e83a503) Thanks [@thushanth-bengre-langchain](https://github.com/thushanth-bengre-langchain)! - Merge streamed `input_json_delta` blocks into the preceding `tool_use` / `server_tool_use` block at the same index
|
|
8
|
+
|
|
3
9
|
## 1.4.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
|
@@ -139,7 +139,7 @@ var BaseLangChain = class extends require_base.Runnable {
|
|
|
139
139
|
this.callbacks = params.callbacks;
|
|
140
140
|
this.tags = params.tags ?? [];
|
|
141
141
|
this.metadata = params.metadata ?? {};
|
|
142
|
-
this._addVersion("@langchain/core", "1.4.
|
|
142
|
+
this._addVersion("@langchain/core", "1.4.1");
|
|
143
143
|
}
|
|
144
144
|
_addVersion(pkg, version) {
|
|
145
145
|
const existing = this.metadata?.versions;
|
|
@@ -138,7 +138,7 @@ var BaseLangChain = class extends Runnable {
|
|
|
138
138
|
this.callbacks = params.callbacks;
|
|
139
139
|
this.tags = params.tags ?? [];
|
|
140
140
|
this.metadata = params.metadata ?? {};
|
|
141
|
-
this._addVersion("@langchain/core", "1.4.
|
|
141
|
+
this._addVersion("@langchain/core", "1.4.1");
|
|
142
142
|
}
|
|
143
143
|
_addVersion(pkg, version) {
|
|
144
144
|
const existing = this.metadata?.versions;
|
package/dist/messages/base.cjs
CHANGED
|
@@ -255,11 +255,14 @@ function hasMergeableId(value) {
|
|
|
255
255
|
function getMergeableTypeBase(type) {
|
|
256
256
|
return type.endsWith("_delta") ? type.slice(0, -6) : type;
|
|
257
257
|
}
|
|
258
|
+
const INPUT_JSON_DELTA_TARGETS = /* @__PURE__ */ new Set(["tool_use", "server_tool_use"]);
|
|
258
259
|
function hasMismatchedMergeableType(left, right) {
|
|
259
260
|
if (typeof left !== "object" || left === null) return false;
|
|
260
261
|
if (typeof right !== "object" || right === null) return false;
|
|
261
262
|
if (!("type" in left) || !("type" in right)) return false;
|
|
262
|
-
|
|
263
|
+
if (typeof left.type !== "string" || typeof right.type !== "string") return false;
|
|
264
|
+
if (right.type === "input_json_delta" && INPUT_JSON_DELTA_TARGETS.has(left.type)) return false;
|
|
265
|
+
return getMergeableTypeBase(left.type) !== getMergeableTypeBase(right.type);
|
|
263
266
|
}
|
|
264
267
|
/**
|
|
265
268
|
* Find the index of an existing item in `merged` that should be merged with
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.cjs","names":["isDataContentBlock","Serializable","convertToV1FromDataContent","convertToV1FromChatCompletionsInput","convertToV1FromAnthropicInput","isMessage","convertToFormattedString"],"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 // oxlint-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 // oxlint-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\n/**\n * Normalize non-string `firstContent` to a block array for merge/spread.\n * Some serializers (e.g. Anthropic-style) yield a single block object instead of a one-element array;\n * spreading that object as an array throws (\"is not iterable\").\n */\nfunction contentBlocksFromNonStringFirst(\n firstContent: MessageContent\n): ContentBlock[] {\n if (Array.isArray(firstContent)) {\n return firstContent;\n }\n if (typeof firstContent === \"string\") {\n return firstContent === \"\" ? [] : [{ type: \"text\", text: firstContent }];\n }\n if (firstContent == null) {\n return [];\n }\n return [firstContent as ContentBlock];\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 const left = contentBlocksFromNonStringFirst(firstContent);\n return _mergeLists(left, secondContent) ?? [...left, ...secondContent];\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 const left = contentBlocksFromNonStringFirst(firstContent);\n return [...left, { 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// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nfunction stringifyWithDepthLimit(obj: any, depthLimit: number): string {\n // oxlint-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 const textBlocks: ContentBlock.Text[] = this.contentBlocks.filter(\n (block: ContentBlock.Standard) => block.type === \"text\"\n );\n return textBlocks.reduce(\n (acc: string, block: ContentBlock.Text) => acc + (block.text ?? \"\"),\n \"\"\n );\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 static [Symbol.hasInstance](obj: unknown) {\n return this.isInstance(obj);\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 // oxlint-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 // oxlint-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 // oxlint-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 // oxlint-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 // oxlint-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\nfunction getMergeableTypeBase(type: string): string {\n return type.endsWith(\"_delta\") ? type.slice(0, -\"_delta\".length) : type;\n}\n\nfunction hasMismatchedMergeableType(left: unknown, right: unknown): boolean {\n if (typeof left !== \"object\" || left === null) return false;\n if (typeof right !== \"object\" || right === null) return false;\n if (!(\"type\" in left) || !(\"type\" in right)) return false;\n\n return (\n typeof left.type === \"string\" &&\n typeof right.type === \"string\" &&\n getMergeableTypeBase(left.type) !== getMergeableTypeBase(right.type)\n );\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 (hasMismatchedMergeableType(leftItem, item)) 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// oxlint-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 static [Symbol.hasInstance](obj: unknown) {\n return this.isInstance(obj);\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 * Serialized form of {@link RemoveMessage}. At runtime,\n * {@link coerceMessageLikeToMessage} converts this to a `RemoveMessage`\n * instance which the `add_messages` reducer uses to delete messages by ID.\n */\n | { type: \"remove\"; id: 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,mBAAmB;;;;;;AA0E7D,SAAS,gCACP,cACgB;CAChB,IAAI,MAAM,QAAQ,YAAY,GAC5B,OAAO;CAET,IAAI,OAAO,iBAAiB,UAC1B,OAAO,iBAAiB,KAAK,CAAC,IAAI,CAAC;EAAE,MAAM;EAAQ,MAAM;CAAa,CAAC;CAEzE,IAAI,gBAAgB,MAClB,OAAO,CAAC;CAEV,OAAO,CAAC,YAA4B;AACtC;AAEA,SAAgB,aACd,cACA,eACgB;CAEhB,IAAI,OAAO,iBAAiB,UAAU;EACpC,IAAI,iBAAiB,IACnB,OAAO;EAET,IAAI,OAAO,kBAAkB,UAC3B,OAAO,eAAe;OACjB,IAAI,MAAM,QAAQ,aAAa,KAAK,cAAc,WAAW,GAClE,OAAO;OACF,IACL,MAAM,QAAQ,aAAa,KAC3B,cAAc,MAAM,MAAMA,aAAAA,mBAAmB,CAAC,CAAC,GAE/C,OAAO,CACL;GACE,MAAM;GACN,aAAa;GACb,MAAM;EACR,GACA,GAAG,aACL;OAEA,OAAO,CAAC;GAAE,MAAM;GAAQ,MAAM;EAAa,GAAG,GAAG,aAAa;CAGlE,OAAO,IAAI,MAAM,QAAQ,aAAa,GAAG;EACvC,MAAM,OAAO,gCAAgC,YAAY;EACzD,OAAO,YAAY,MAAM,aAAa,KAAK,CAAC,GAAG,MAAM,GAAG,aAAa;CACvE,OACE,IAAI,kBAAkB,IACpB,OAAO;MACF,IACL,MAAM,QAAQ,YAAY,KAC1B,aAAa,MAAM,MAAMA,aAAAA,mBAAmB,CAAC,CAAC,GAE9C,OAAO,CACL,GAAG,cACH;EACE,MAAM;EACN,aAAa;EACb,MAAM;CACR,CACF;MAGA,OAAO,CAAC,GADK,gCAAgC,YAC/B,GAAG;EAA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,MAAM,QAAQ,IAAI,KAAK,MAAM,QAAQ,KAAK,GACnD,OAAO,YAAY,MAAM,OAAO,OAAO;MAClC,IAAI,OAAO,SAAS,YAAY,OAAO,UAAU,UACtD,OAAO,YACL,MACA,OACA,OACF;MACK,IAAI,SAAS,OAClB,OAAO;MAEP,MAAM,IAAI,MACR,mDAAmD,KAAK,UAAU,OACpE;AAEJ;;;;;;;;AASA,IAAsB,mBAAtB,MAAsB,yBAGZ,YAA+B;CAGvC,OAAO,WAAW,KAAuC;EACvD,IAAI,CAAC,MAAM,WAAW,GAAG,GACvB,OAAO;EAGT,IAAI,QAAQ,OAAO,eAAe,GAAG;EACrC,OAAO,UAAU,MAAM;GACrB,IAAI,UAAU,iBAAiB,WAC7B,OAAO;GAET,QAAQ,OAAO,eAAe,KAAK;EACrC;EACA,OAAO;CACT;CAEA,QAAQ,OAAO,aAAa,KAAc;EACxC,OAAO,KAAK,WAAW,GAAG;CAC5B;AACF;AAQA,SAAgB,wBACd,GAC2B;CAC3B,OAAO,OAAQ,EAA2B,SAAS;AACrD;;;;AAyBA,SAAgB,cACd,aAC4B;CAC5B,OAAO,OAAQ,aAA6B,aAAa;AAC3D;;;;AAKA,SAAgB,mBACd,aACiC;CACjC,OAAO,iBAAiB,WAAW,WAAW;AAChD"}
|
|
1
|
+
{"version":3,"file":"base.cjs","names":["isDataContentBlock","Serializable","convertToV1FromDataContent","convertToV1FromChatCompletionsInput","convertToV1FromAnthropicInput","isMessage","convertToFormattedString"],"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 // oxlint-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 // oxlint-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\n/**\n * Normalize non-string `firstContent` to a block array for merge/spread.\n * Some serializers (e.g. Anthropic-style) yield a single block object instead of a one-element array;\n * spreading that object as an array throws (\"is not iterable\").\n */\nfunction contentBlocksFromNonStringFirst(\n firstContent: MessageContent\n): ContentBlock[] {\n if (Array.isArray(firstContent)) {\n return firstContent;\n }\n if (typeof firstContent === \"string\") {\n return firstContent === \"\" ? [] : [{ type: \"text\", text: firstContent }];\n }\n if (firstContent == null) {\n return [];\n }\n return [firstContent as ContentBlock];\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 const left = contentBlocksFromNonStringFirst(firstContent);\n return _mergeLists(left, secondContent) ?? [...left, ...secondContent];\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 const left = contentBlocksFromNonStringFirst(firstContent);\n return [...left, { 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// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nfunction stringifyWithDepthLimit(obj: any, depthLimit: number): string {\n // oxlint-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 const textBlocks: ContentBlock.Text[] = this.contentBlocks.filter(\n (block: ContentBlock.Standard) => block.type === \"text\"\n );\n return textBlocks.reduce(\n (acc: string, block: ContentBlock.Text) => acc + (block.text ?? \"\"),\n \"\"\n );\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 static [Symbol.hasInstance](obj: unknown) {\n return this.isInstance(obj);\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 // oxlint-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 // oxlint-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 // oxlint-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 // oxlint-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 // oxlint-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\nfunction getMergeableTypeBase(type: string): string {\n return type.endsWith(\"_delta\") ? type.slice(0, -\"_delta\".length) : type;\n}\n\n// Anthropic streams tool arguments as `input_json_delta` blocks that continue\n// the preceding `tool_use` / `server_tool_use` block at the same index.\nconst INPUT_JSON_DELTA_TARGETS = new Set([\"tool_use\", \"server_tool_use\"]);\n\nfunction hasMismatchedMergeableType(left: unknown, right: unknown): boolean {\n if (typeof left !== \"object\" || left === null) return false;\n if (typeof right !== \"object\" || right === null) return false;\n if (!(\"type\" in left) || !(\"type\" in right)) return false;\n if (typeof left.type !== \"string\" || typeof right.type !== \"string\") {\n return false;\n }\n if (\n right.type === \"input_json_delta\" &&\n INPUT_JSON_DELTA_TARGETS.has(left.type)\n ) {\n return false;\n }\n\n return getMergeableTypeBase(left.type) !== getMergeableTypeBase(right.type);\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 (hasMismatchedMergeableType(leftItem, item)) 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// oxlint-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 static [Symbol.hasInstance](obj: unknown) {\n return this.isInstance(obj);\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 * Serialized form of {@link RemoveMessage}. At runtime,\n * {@link coerceMessageLikeToMessage} converts this to a `RemoveMessage`\n * instance which the `add_messages` reducer uses to delete messages by ID.\n */\n | { type: \"remove\"; id: 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,mBAAmB;;;;;;AA0E7D,SAAS,gCACP,cACgB;CAChB,IAAI,MAAM,QAAQ,YAAY,GAC5B,OAAO;CAET,IAAI,OAAO,iBAAiB,UAC1B,OAAO,iBAAiB,KAAK,CAAC,IAAI,CAAC;EAAE,MAAM;EAAQ,MAAM;CAAa,CAAC;CAEzE,IAAI,gBAAgB,MAClB,OAAO,CAAC;CAEV,OAAO,CAAC,YAA4B;AACtC;AAEA,SAAgB,aACd,cACA,eACgB;CAEhB,IAAI,OAAO,iBAAiB,UAAU;EACpC,IAAI,iBAAiB,IACnB,OAAO;EAET,IAAI,OAAO,kBAAkB,UAC3B,OAAO,eAAe;OACjB,IAAI,MAAM,QAAQ,aAAa,KAAK,cAAc,WAAW,GAClE,OAAO;OACF,IACL,MAAM,QAAQ,aAAa,KAC3B,cAAc,MAAM,MAAMA,aAAAA,mBAAmB,CAAC,CAAC,GAE/C,OAAO,CACL;GACE,MAAM;GACN,aAAa;GACb,MAAM;EACR,GACA,GAAG,aACL;OAEA,OAAO,CAAC;GAAE,MAAM;GAAQ,MAAM;EAAa,GAAG,GAAG,aAAa;CAGlE,OAAO,IAAI,MAAM,QAAQ,aAAa,GAAG;EACvC,MAAM,OAAO,gCAAgC,YAAY;EACzD,OAAO,YAAY,MAAM,aAAa,KAAK,CAAC,GAAG,MAAM,GAAG,aAAa;CACvE,OACE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MAAM;;;;;AAMN,OAAO;;;;AAIP,UAAU,oBAET;wBAmJa,YAAY,gBAAgB,cAC1C,OAAO,WACP,QAAQ,WACR,UAAU,oBACT;wBA+Ba,UAAU,SACxB,MAAM,eACN,OAAO,eACP,UAAU,oBACT;;;;;;;;8BAoCmB,iBACpB,mBAAmB,mBAAmB,kBACtC,cAAc,cAAc,qBACpB,YAAY,YAAY;WACvB,OAAO,OAAO,mBAAmB,iBAAiB,YAAY;SAEhE,WAAW,eAAe,OAAO;UAehC,OAAO,aAAa,eAAY,OAAA,iBAAA,iBAfAA,iBAeA;;YAK9B;EACV,MAAM;EACN,SAAS;EACT;IACE;wBAEY,wBACd,GAAG,kBACF,KAAK;YAII,kBACR,cACA,wBACC,aAAa;;;;;;;EAOZ;EAAgB;;;;;;EAKhB,MAAM;IACJ,oBACF,2BACF;;;;wBAKY,cACd,wBACC,eAAe;;;;wBAOF,mBACd,wBACC,eAAe"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","names":["_$__message_js0.MessageToolSet"],"sources":["../../src/messages/base.ts"],"mappings":";;;;;cAoBM;iBAEW;EACf;EACA;EACA;EACA;EAEA,oBAAoB;;EAGpB,oBAAoB;EACpB;;iBAGe;EACf;EACA,MAAM;;iBAGS;EACf;EACA,UAAU;;iBAGK;EACf;EACA;EACA;;YAGU,0BAA0B,MAAM;iBAE3B;;;;;;;EAOf;;;;EAKA;;YAGU,kBACV,mBAAmB,mBAAmB,kBACtC,cAAc,cAAc,eAC1B,KAAK;EACP,UAAU,qBAAqB,YAAY;EAC3C,gBAAgB,MAAM,aAAa;;EAEnC;;;;IAIE,gBAAgB;;;;IAIhB,aAAa;KACZ;;EAEH,oBAAoB,QAAQ,uBAAuB,YAAY;;wBAuBjD,aACd,cAAc,gBACd,eAAe,iBACd;;;;;;;;;wBA2Da,aACd,4BACA;;;;;;8BAyCoB,YACpB,mBAAmB,mBAAmB,kBACtC,cAAc,cAAc,qBAEpB,wBACG,Q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base.js
CHANGED
|
@@ -255,11 +255,14 @@ function hasMergeableId(value) {
|
|
|
255
255
|
function getMergeableTypeBase(type) {
|
|
256
256
|
return type.endsWith("_delta") ? type.slice(0, -6) : type;
|
|
257
257
|
}
|
|
258
|
+
const INPUT_JSON_DELTA_TARGETS = /* @__PURE__ */ new Set(["tool_use", "server_tool_use"]);
|
|
258
259
|
function hasMismatchedMergeableType(left, right) {
|
|
259
260
|
if (typeof left !== "object" || left === null) return false;
|
|
260
261
|
if (typeof right !== "object" || right === null) return false;
|
|
261
262
|
if (!("type" in left) || !("type" in right)) return false;
|
|
262
|
-
|
|
263
|
+
if (typeof left.type !== "string" || typeof right.type !== "string") return false;
|
|
264
|
+
if (right.type === "input_json_delta" && INPUT_JSON_DELTA_TARGETS.has(left.type)) return false;
|
|
265
|
+
return getMergeableTypeBase(left.type) !== getMergeableTypeBase(right.type);
|
|
263
266
|
}
|
|
264
267
|
/**
|
|
265
268
|
* Find the index of an existing item in `merged` that should be merged with
|
|
@@ -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 // oxlint-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 // oxlint-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\n/**\n * Normalize non-string `firstContent` to a block array for merge/spread.\n * Some serializers (e.g. Anthropic-style) yield a single block object instead of a one-element array;\n * spreading that object as an array throws (\"is not iterable\").\n */\nfunction contentBlocksFromNonStringFirst(\n firstContent: MessageContent\n): ContentBlock[] {\n if (Array.isArray(firstContent)) {\n return firstContent;\n }\n if (typeof firstContent === \"string\") {\n return firstContent === \"\" ? [] : [{ type: \"text\", text: firstContent }];\n }\n if (firstContent == null) {\n return [];\n }\n return [firstContent as ContentBlock];\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 const left = contentBlocksFromNonStringFirst(firstContent);\n return _mergeLists(left, secondContent) ?? [...left, ...secondContent];\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 const left = contentBlocksFromNonStringFirst(firstContent);\n return [...left, { 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// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nfunction stringifyWithDepthLimit(obj: any, depthLimit: number): string {\n // oxlint-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 const textBlocks: ContentBlock.Text[] = this.contentBlocks.filter(\n (block: ContentBlock.Standard) => block.type === \"text\"\n );\n return textBlocks.reduce(\n (acc: string, block: ContentBlock.Text) => acc + (block.text ?? \"\"),\n \"\"\n );\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 static [Symbol.hasInstance](obj: unknown) {\n return this.isInstance(obj);\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 // oxlint-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 // oxlint-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 // oxlint-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 // oxlint-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 // oxlint-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\nfunction getMergeableTypeBase(type: string): string {\n return type.endsWith(\"_delta\") ? type.slice(0, -\"_delta\".length) : type;\n}\n\nfunction hasMismatchedMergeableType(left: unknown, right: unknown): boolean {\n if (typeof left !== \"object\" || left === null) return false;\n if (typeof right !== \"object\" || right === null) return false;\n if (!(\"type\" in left) || !(\"type\" in right)) return false;\n\n return (\n typeof left.type === \"string\" &&\n typeof right.type === \"string\" &&\n getMergeableTypeBase(left.type) !== getMergeableTypeBase(right.type)\n );\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 (hasMismatchedMergeableType(leftItem, item)) 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// oxlint-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 static [Symbol.hasInstance](obj: unknown) {\n return this.isInstance(obj);\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 * Serialized form of {@link RemoveMessage}. At runtime,\n * {@link coerceMessageLikeToMessage} converts this to a `RemoveMessage`\n * instance which the `add_messages` reducer uses to delete messages by ID.\n */\n | { type: \"remove\"; id: 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,mBAAmB;;;;;;AA0E7D,SAAS,gCACP,cACgB;CAChB,IAAI,MAAM,QAAQ,YAA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O,WAAW,KAAuC;EACvD,IAAI,CAAC,MAAM,WAAW,GAAG,GACvB,OAAO;EAGT,IAAI,QAAQ,OAAO,eAAe,GAAG;EACrC,OAAO,UAAU,MAAM;GACrB,IAAI,UAAU,iBAAiB,WAC7B,OAAO;GAET,QAAQ,OAAO,eAAe,KAAK;EACrC;EACA,OAAO;CACT;CAEA,QAAQ,OAAO,aAAa,KAAc;EACxC,OAAO,KAAK,WAAW,GAAG;CAC5B;AACF;AAQA,SAAgB,wBACd,GAC2B;CAC3B,OAAO,OAAQ,EAA2B,SAAS;AACrD;;;;AAyBA,SAAgB,cACd,aAC4B;CAC5B,OAAO,OAAQ,aAA6B,aAAa;AAC3D;;;;AAKA,SAAgB,mBACd,aACiC;CACjC,OAAO,iBAAiB,WAAW,WAAW;AAChD"}
|
|
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 // oxlint-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 // oxlint-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\n/**\n * Normalize non-string `firstContent` to a block array for merge/spread.\n * Some serializers (e.g. Anthropic-style) yield a single block object instead of a one-element array;\n * spreading that object as an array throws (\"is not iterable\").\n */\nfunction contentBlocksFromNonStringFirst(\n firstContent: MessageContent\n): ContentBlock[] {\n if (Array.isArray(firstContent)) {\n return firstContent;\n }\n if (typeof firstContent === \"string\") {\n return firstContent === \"\" ? [] : [{ type: \"text\", text: firstContent }];\n }\n if (firstContent == null) {\n return [];\n }\n return [firstContent as ContentBlock];\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 const left = contentBlocksFromNonStringFirst(firstContent);\n return _mergeLists(left, secondContent) ?? [...left, ...secondContent];\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 const left = contentBlocksFromNonStringFirst(firstContent);\n return [...left, { 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// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nfunction stringifyWithDepthLimit(obj: any, depthLimit: number): string {\n // oxlint-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 const textBlocks: ContentBlock.Text[] = this.contentBlocks.filter(\n (block: ContentBlock.Standard) => block.type === \"text\"\n );\n return textBlocks.reduce(\n (acc: string, block: ContentBlock.Text) => acc + (block.text ?? \"\"),\n \"\"\n );\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 static [Symbol.hasInstance](obj: unknown) {\n return this.isInstance(obj);\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 // oxlint-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 // oxlint-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 // oxlint-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 // oxlint-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 // oxlint-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\nfunction getMergeableTypeBase(type: string): string {\n return type.endsWith(\"_delta\") ? type.slice(0, -\"_delta\".length) : type;\n}\n\n// Anthropic streams tool arguments as `input_json_delta` blocks that continue\n// the preceding `tool_use` / `server_tool_use` block at the same index.\nconst INPUT_JSON_DELTA_TARGETS = new Set([\"tool_use\", \"server_tool_use\"]);\n\nfunction hasMismatchedMergeableType(left: unknown, right: unknown): boolean {\n if (typeof left !== \"object\" || left === null) return false;\n if (typeof right !== \"object\" || right === null) return false;\n if (!(\"type\" in left) || !(\"type\" in right)) return false;\n if (typeof left.type !== \"string\" || typeof right.type !== \"string\") {\n return false;\n }\n if (\n right.type === \"input_json_delta\" &&\n INPUT_JSON_DELTA_TARGETS.has(left.type)\n ) {\n return false;\n }\n\n return getMergeableTypeBase(left.type) !== getMergeableTypeBase(right.type);\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 (hasMismatchedMergeableType(leftItem, item)) 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// oxlint-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 static [Symbol.hasInstance](obj: unknown) {\n return this.isInstance(obj);\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 * Serialized form of {@link RemoveMessage}. At runtime,\n * {@link coerceMessageLikeToMessage} converts this to a `RemoveMessage`\n * instance which the `add_messages` reducer uses to delete messages by ID.\n */\n | { type: \"remove\"; id: 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,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