UNPKG

@langchain/core

Version:
1 lines 12.5 kB
{"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","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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\n additional_kwargs?: Record<string, any>;\n /** Response metadata. For example: response headers, logprobs, token counts, model name. */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n response_metadata?: Record<string, any>;\n id?: string;\n}\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> = {\n id?: string;\n name?: string;\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 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 // Can't be protected for silly reasons\n get _printableFields(): Record<string, unknown>;\n static isInstance(obj: unknown): obj is BaseMessage;\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): 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(\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nleft?: Record<string, any>, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nright?: Record<string, any>\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\n): Record<string, any>;\nexport declare function _mergeLists<Content extends ContentBlock>(left?: Content[], right?: Content[]): Content[] | undefined;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport declare function _mergeObj<T = any>(left: T | undefined, right: T | undefined): T;\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"],"mappings":";;;;;;;cAKcS;AAAAA,UACGC,iBAAAA,CAD0B;EAC1BA,OAAAA,EAAAA,MAAAA;EAAiB,IAAA,EAAA,MAAA,GAAA,SAAA;EAAA,IAMVC,EAAAA,MAAAA,GAAAA,SAAAA;EAAM,YAGNA,EAAAA,MAAAA,GAAAA,SAAAA;EAAM;EAGbC,iBAAa,CAAA,EANND,MAMM,CAAA,MAEpBD,EAAAA,GAAAA,CAAAA;EAEOG;EAIAC;EAKLC,iBAAc,CAAA,EAhBFJ,MAgBE,CAAA,MAAA,EAAA,GAAA,CAAA;EAAA,EAAA,CAAA,EAAA,MAAA;;AAAYK,UAbrBJ,aAAAA,CAaqBI;EAAK,IAAA,EAAA,MAAA;EAC1BC,IAAAA,EAZPP,iBAYmB;AAa7B;AAA6B,UAvBZG,gBAAAA,CAuBY;EAAA,IAAoBR,EAAAA,MAAAA;EAAgB,OAAGA,CAAAA,EArBtDO,aAqBsDP;;AAA8CC,UAnBjGQ,eAAAA,CAmBiGR;EAAW,IAG1Fa,EAAAA,MAAAA;EAAU,IAAEC,EAAAA,MAAAA,GAAAA,SAAAA;EAAK,IAAt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