@langchain/core
Version:
Core LangChain.js abstractions and schemas
1 lines • 11.9 kB
Source Map (JSON)
{"version":3,"file":"base.d.cts","names":["Serializable","SerializedConstructor","ContentBlock","$InferMessageContent","$InferResponseMetadata","MessageStructure","MessageType","Message","MessageStringFormat","MESSAGE_SYMBOL","StoredMessageData","Record","StoredMessage","StoredGeneration","StoredMessageV1","MessageContent","Array","FunctionCall","BaseMessageFields","TStructure","TRole","Pick","Standard","OpenAIToolCall","Partial","mergeContent","_mergeStatus","BaseMessage","NonNullable","Symbol","toStringTag","isOpenAIToolCallArray","_mergeDicts","_mergeLists","Content","_mergeObj","T","BaseMessageChunk","MessageFieldWithRole","_isMessageFieldWithRole","BaseMessageLike","isBaseMessage","isBaseMessageChunk"],"sources":["../../src/messages/base.d.ts"],"sourcesContent":["import { Serializable, SerializedConstructor } from \"../load/serializable.js\";\nimport { ContentBlock } from \"./content/index.js\";\nimport { $InferMessageContent, $InferResponseMetadata, MessageStructure, MessageType, Message } from \"./message.js\";\nimport { type MessageStringFormat } from \"./format.js\";\n/** @internal */\ndeclare const MESSAGE_SYMBOL: unique symbol;\nexport interface StoredMessageData {\n content: string;\n role: string | undefined;\n name: string | undefined;\n tool_call_id: string | undefined;\n additional_kwargs?: Record<string, any>;\n /** Response metadata. For example: response headers, logprobs, token counts, model name. */\n response_metadata?: Record<string, any>;\n id?: string;\n}\nexport interface StoredMessage {\n type: string;\n data: StoredMessageData;\n}\nexport interface StoredGeneration {\n text: string;\n message?: StoredMessage;\n}\nexport interface StoredMessageV1 {\n type: string;\n role: string | undefined;\n text: string;\n}\nexport type MessageContent = string | Array<ContentBlock>;\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 * The name of the function to call.\n */\n name: string;\n}\nexport type BaseMessageFields<TStructure extends MessageStructure = MessageStructure, TRole extends MessageType = MessageType> = 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};\nexport declare function mergeContent(firstContent: MessageContent, secondContent: MessageContent): MessageContent;\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 declare function _mergeStatus(left?: \"success\" | \"error\", right?: \"success\" | \"error\"): \"success\" | \"error\" | undefined;\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 declare abstract class BaseMessage<TStructure extends MessageStructure = MessageStructure, TRole extends MessageType = MessageType> extends Serializable implements Message<TStructure, TRole> {\n lc_namespace: string[];\n lc_serializable: boolean;\n get lc_aliases(): Record<string, string>;\n readonly [MESSAGE_SYMBOL]: true;\n abstract readonly type: TRole;\n id?: string;\n /** @inheritdoc */\n name?: string;\n content: $InferMessageContent<TStructure, TRole>;\n additional_kwargs: NonNullable<BaseMessageFields<TStructure, TRole>[\"additional_kwargs\"]>;\n response_metadata: NonNullable<BaseMessageFields<TStructure, TRole>[\"response_metadata\"]>;\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 /**\n * @deprecated Use .type instead\n * The type of the message.\n */\n getType(): MessageType;\n constructor(arg: $InferMessageContent<TStructure, TRole> | BaseMessageFields<TStructure, TRole>);\n /** Get text content of the message. */\n get text(): string;\n get contentBlocks(): Array<ContentBlock.Standard>;\n toDict(): StoredMessage;\n static lc_name(): string;\n get _printableFields(): Record<string, unknown>;\n static isInstance(obj: unknown): obj is BaseMessage;\n _updateId(value: string | undefined): void;\n get [Symbol.toStringTag](): any;\n toFormattedString(format?: MessageStringFormat): string;\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 * The function that the model called.\n */\n function: FunctionCall;\n /**\n * The type of the tool. Currently, only `function` is supported.\n */\n type: \"function\";\n index?: number;\n};\nexport declare function isOpenAIToolCallArray(value?: unknown): value is OpenAIToolCall[];\nexport declare function _mergeDicts(left?: Record<string, any>, right?: Record<string, any>): Record<string, any>;\nexport declare function _mergeLists<Content extends ContentBlock>(left?: Content[], right?: Content[]): Content[] | undefined;\nexport declare function _mergeObj<T = any>(left: T | undefined, right: T | undefined): T | undefined;\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 declare abstract class BaseMessageChunk<TStructure extends MessageStructure = MessageStructure, TRole extends MessageType = MessageType> extends BaseMessage<TStructure, TRole> {\n abstract concat(chunk: BaseMessageChunk): BaseMessageChunk<TStructure, TRole>;\n static isInstance(obj: unknown): obj is BaseMessageChunk;\n}\nexport type MessageFieldWithRole = {\n role: MessageType;\n content: MessageContent;\n name?: string;\n} & Record<string, unknown>;\nexport declare function _isMessageFieldWithRole(x: BaseMessageLike): x is MessageFieldWithRole;\nexport type BaseMessageLike = BaseMessage | MessageFieldWithRole | [MessageType, MessageContent] | 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 & Record<string, unknown>) | SerializedConstructor;\n/**\n * @deprecated Use {@link BaseMessage.isInstance} instead\n */\nexport declare function isBaseMessage(messageLike?: unknown): messageLike is BaseMessage;\n/**\n * @deprecated Use {@link BaseMessageChunk.isInstance} instead\n */\nexport declare function isBaseMessageChunk(messageLike?: unknown): messageLike is BaseMessageChunk;\nexport {};\n//# sourceMappingURL=base.d.ts.map"],"mappings":";;;;;;;cAKcS;AAAAA,UACGC,iBAAAA,CAD0B;EAC1BA,OAAAA,EAAAA,MAAAA;EAUAE,IAAAA,EAAAA,MAAAA,GAAAA,SAAa;EAIbC,IAAAA,EAAAA,MAAAA,GAAAA,SAAgB;EAIhBC,YAAAA,EAAAA,MAAe,GAAA,SAAA;EAKpBC,iBAAc,CAAA,EAlBFJ,MAkBE,CAAA,MAAkBT,EAAAA,GAAAA,CAAAA;EAC3Be;EAaLC,iBAAAA,CAAAA,EA9BYP,MA8BK,CAAAQ,MAAAA,EAAAA,GAAAA,CAAAC;EAAoBf,EAAAA,CAAAA,EAAAA,MAAAA;;AAAmDC,UA3BnFM,aAAAA,CA2BmFN;EAAcA,IAAAA,EAAAA,MAAAA;EAAoBC,IAAAA,EAzB5HG,iBAyB4HH;;AACnGY,UAxBlBN,gBAAAA,CAwBkBM;EAAYC,IAAAA,EAAAA,MAAAA;EAAjCjB,OAAAA,CAAAA,EAtBAS,aAsBAT;;AACMa,UArBHF,eAAAA,CAqBGE;EAMIC,IAAAA,EAAAA,MAAAA;EAIHM,IAAAA,EAAAA,MAAAA,GAAAA,SAAAA;EAGkCJ,IAAAA,EAAAA,MAAAA;;AAAvBf,KA7BpBW,cAAAA,GA6BoBX,MAAAA,GA7BMY,KA6BNZ,CA7BYF,YA6BZE,CAAAA;AAARoB,UA5BPP,YAAAA,CA4BOO;EAAO;AAE/B;;;;AAAiH;EASzFE,SAAAA,EAAAA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