@langchain/core 1.0.0-alpha.2 → 1.0.0-alpha.3
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/dist/agents.d.ts.map +1 -1
- package/dist/caches/base.cjs +5 -18
- package/dist/caches/base.cjs.map +1 -1
- package/dist/caches/base.d.cts +4 -20
- package/dist/caches/base.d.cts.map +1 -1
- package/dist/caches/base.d.ts +4 -20
- package/dist/caches/base.d.ts.map +1 -1
- package/dist/caches/base.js +5 -18
- package/dist/caches/base.js.map +1 -1
- package/dist/callbacks/base.d.cts +3 -2
- package/dist/callbacks/base.d.cts.map +1 -1
- package/dist/callbacks/base.d.ts +3 -2
- package/dist/callbacks/base.d.ts.map +1 -1
- package/dist/callbacks/manager.d.cts +1 -1
- package/dist/callbacks/manager.d.ts +1 -1
- package/dist/language_models/base.d.cts +1 -1
- package/dist/language_models/base.d.ts +1 -1
- package/dist/language_models/chat_models.cjs +1 -0
- package/dist/language_models/chat_models.cjs.map +1 -1
- package/dist/language_models/chat_models.d.cts +2 -1
- package/dist/language_models/chat_models.d.cts.map +1 -1
- package/dist/language_models/chat_models.d.ts +2 -1
- package/dist/language_models/chat_models.d.ts.map +1 -1
- package/dist/language_models/chat_models.js +2 -1
- package/dist/language_models/chat_models.js.map +1 -1
- package/dist/messages/ai.cjs +32 -60
- package/dist/messages/ai.cjs.map +1 -1
- package/dist/messages/ai.d.cts +26 -119
- package/dist/messages/ai.d.cts.map +1 -1
- package/dist/messages/ai.d.ts +26 -119
- package/dist/messages/ai.d.ts.map +1 -1
- package/dist/messages/ai.js +32 -60
- package/dist/messages/ai.js.map +1 -1
- package/dist/messages/base.cjs +48 -28
- package/dist/messages/base.cjs.map +1 -1
- package/dist/messages/base.d.cts +37 -39
- package/dist/messages/base.d.cts.map +1 -1
- package/dist/messages/base.d.ts +37 -39
- package/dist/messages/base.d.ts.map +1 -1
- package/dist/messages/base.js +48 -28
- package/dist/messages/base.js.map +1 -1
- package/dist/messages/chat.cjs +18 -12
- package/dist/messages/chat.cjs.map +1 -1
- package/dist/messages/chat.d.cts +21 -13
- package/dist/messages/chat.d.cts.map +1 -1
- package/dist/messages/chat.d.ts +21 -13
- package/dist/messages/chat.d.ts.map +1 -1
- package/dist/messages/chat.js +18 -12
- package/dist/messages/chat.js.map +1 -1
- package/dist/messages/content/index.cjs.map +1 -1
- package/dist/messages/content/index.d.cts +1 -1
- package/dist/messages/content/index.d.cts.map +1 -1
- package/dist/messages/content/index.d.ts +1 -1
- package/dist/messages/content/index.d.ts.map +1 -1
- package/dist/messages/content/index.js.map +1 -1
- package/dist/messages/function.cjs +8 -13
- package/dist/messages/function.cjs.map +1 -1
- package/dist/messages/function.d.cts +11 -11
- package/dist/messages/function.d.cts.map +1 -1
- package/dist/messages/function.d.ts +11 -11
- package/dist/messages/function.d.ts.map +1 -1
- package/dist/messages/function.js +8 -13
- package/dist/messages/function.js.map +1 -1
- package/dist/messages/human.cjs +20 -11
- package/dist/messages/human.cjs.map +1 -1
- package/dist/messages/human.d.cts +20 -15
- package/dist/messages/human.d.cts.map +1 -1
- package/dist/messages/human.d.ts +20 -15
- package/dist/messages/human.d.ts.map +1 -1
- package/dist/messages/human.js +20 -11
- package/dist/messages/human.js.map +1 -1
- package/dist/messages/index.cjs +10 -0
- package/dist/messages/index.cjs.map +1 -1
- package/dist/messages/index.d.cts +9 -7
- package/dist/messages/index.d.ts +9 -7
- package/dist/messages/index.js +8 -2
- package/dist/messages/index.js.map +1 -1
- package/dist/messages/message.cjs +15 -0
- package/dist/messages/message.cjs.map +1 -0
- package/dist/messages/message.d.cts +598 -0
- package/dist/messages/message.d.cts.map +1 -0
- package/dist/messages/message.d.ts +598 -0
- package/dist/messages/message.d.ts.map +1 -0
- package/dist/messages/message.js +14 -0
- package/dist/messages/message.js.map +1 -0
- package/dist/messages/metadata.cjs +41 -0
- package/dist/messages/metadata.cjs.map +1 -0
- package/dist/messages/metadata.d.cts +98 -0
- package/dist/messages/metadata.d.cts.map +1 -0
- package/dist/messages/metadata.d.ts +98 -0
- package/dist/messages/metadata.d.ts.map +1 -0
- package/dist/messages/metadata.js +40 -0
- package/dist/messages/metadata.js.map +1 -0
- package/dist/messages/modifier.cjs +5 -7
- package/dist/messages/modifier.cjs.map +1 -1
- package/dist/messages/modifier.d.cts +7 -5
- package/dist/messages/modifier.d.cts.map +1 -1
- package/dist/messages/modifier.d.ts +7 -5
- package/dist/messages/modifier.d.ts.map +1 -1
- package/dist/messages/modifier.js +5 -7
- package/dist/messages/modifier.js.map +1 -1
- package/dist/messages/system.cjs +20 -11
- package/dist/messages/system.cjs.map +1 -1
- package/dist/messages/system.d.cts +20 -15
- package/dist/messages/system.d.cts.map +1 -1
- package/dist/messages/system.d.ts +20 -15
- package/dist/messages/system.d.ts.map +1 -1
- package/dist/messages/system.js +20 -11
- package/dist/messages/system.js.map +1 -1
- package/dist/messages/tool.cjs +15 -13
- package/dist/messages/tool.cjs.map +1 -1
- package/dist/messages/tool.d.cts +72 -46
- package/dist/messages/tool.d.cts.map +1 -1
- package/dist/messages/tool.d.ts +72 -46
- package/dist/messages/tool.d.ts.map +1 -1
- package/dist/messages/tool.js +15 -13
- package/dist/messages/tool.js.map +1 -1
- package/dist/messages/transformers.cjs.map +1 -1
- package/dist/messages/transformers.d.cts +2 -1
- package/dist/messages/transformers.d.cts.map +1 -1
- package/dist/messages/transformers.d.ts +2 -1
- package/dist/messages/transformers.d.ts.map +1 -1
- package/dist/messages/transformers.js.map +1 -1
- package/dist/messages/utils.cjs +8 -1
- package/dist/messages/utils.cjs.map +1 -1
- package/dist/messages/utils.d.cts +83 -3
- package/dist/messages/utils.d.cts.map +1 -1
- package/dist/messages/utils.d.ts +83 -3
- package/dist/messages/utils.d.ts.map +1 -1
- package/dist/messages/utils.js +8 -2
- package/dist/messages/utils.js.map +1 -1
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.cts +1 -1
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.ts +1 -1
- package/dist/prompt_values.d.cts +4 -3
- package/dist/prompt_values.d.cts.map +1 -1
- package/dist/prompt_values.d.ts +4 -3
- package/dist/prompt_values.d.ts.map +1 -1
- package/dist/prompts/chat.d.cts +3 -3
- package/dist/prompts/chat.d.cts.map +1 -1
- package/dist/prompts/chat.d.ts +3 -3
- package/dist/prompts/chat.d.ts.map +1 -1
- package/dist/prompts/few_shot.d.cts +1 -1
- package/dist/prompts/few_shot.d.ts +1 -1
- package/dist/prompts/image.d.cts +1 -1
- package/dist/prompts/image.d.ts +1 -1
- package/dist/prompts/prompt.d.cts +1 -1
- package/dist/prompts/prompt.d.ts +1 -1
- package/dist/prompts/template.d.cts +1 -1
- package/dist/prompts/template.d.ts +1 -1
- package/dist/runnables/base.d.cts +1 -1
- package/dist/runnables/base.d.ts +1 -1
- package/dist/tools/index.d.cts +1 -1
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/types.d.cts +1 -1
- package/dist/tools/types.d.ts +1 -1
- package/dist/tracers/base.d.cts +1 -1
- package/dist/tracers/base.d.ts +1 -1
- package/dist/tracers/tracer_langchain_v1.d.cts +1 -1
- package/dist/tracers/tracer_langchain_v1.d.ts +1 -1
- package/dist/utils/testing/index.d.cts +4 -3
- package/dist/utils/testing/index.d.cts.map +1 -1
- package/dist/utils/testing/index.d.ts +4 -3
- package/dist/utils/testing/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/messages/message.ts
|
|
2
|
+
/**
|
|
3
|
+
* Type guard to check if a value is a valid Message object.
|
|
4
|
+
*
|
|
5
|
+
* @param message - The value to check
|
|
6
|
+
* @returns true if the value is a valid Message object, false otherwise
|
|
7
|
+
*/
|
|
8
|
+
function isMessage(message) {
|
|
9
|
+
return typeof message === "object" && message !== null && "type" in message && "content" in message && (typeof message.content === "string" || Array.isArray(message.content));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { isMessage };
|
|
14
|
+
//# sourceMappingURL=message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.js","names":["message: unknown"],"sources":["../../src/messages/message.ts"],"sourcesContent":["import type { ContentBlock } from \"./content/index.js\";\nimport type { ResponseMetadata, UsageMetadata } from \"./metadata.js\";\nimport type { $MergeDiscriminatedUnion, $MergeObjects } from \"./utils.js\";\n\n/**\n * Represents the possible types of messages in the system.\n * Includes standard message types (\"ai\", \"human\", \"tool\", \"system\")\n * and allows for custom string types that are non-null.\n *\n * @example\n * ```ts\n * // Standard message types\n * const messageType1: MessageType = \"ai\";\n * const messageType2: MessageType = \"human\";\n *\n * // Custom message type\n * const messageType3: MessageType = \"custom_type\";\n * ```\n */\nexport type MessageType =\n | \"ai\"\n | \"human\"\n | \"tool\"\n | \"system\"\n | (string & NonNullable<unknown>);\n\n/**\n * Represents the output version format for message content.\n *\n * This type determines how the content field is structured in a message:\n * - \"v0\": Content is represented as a simple string or array of content blocks\n * - provides backward compatibility with simpler content representations\n * - \"v1\": Content follows the structured ContentBlock format with typed discriminated unions\n * - enables full type safety and structured content block handling\n *\n * @example\n * ```ts\n * // v0 format - simple content representation\n * const v0Message: Message<{ outputVersion: \"v0\", content: ... }> = {\n * type: \"human\",\n * content: \"Hello world\" // string | Array<ContentBlock | ContentBlock.Text>\n * };\n *\n * // v1 format - structured content blocks\n * const v1Message: Message<{ outputVersion: \"v1\", content: ... }> = {\n * type: \"human\",\n * content: [\n * { type: \"text\", text: \"Hello world\" },\n * { type: \"image\", image_url: \"...\" }\n * ] // Array<ContentBlock | ...> (determined by the structure)\n * };\n * ```\n */\nexport type MessageOutputVersion = \"v0\" | \"v1\";\n\n/**\n * Represents the input and output types of a tool that can be used in messages.\n *\n * @template TInput - The type of input the tool accepts.\n * @template TOutput - The type of output the tool produces.\n *\n * @example\n * ```ts\n * // Tool that takes a string input and returns a number\n * interface StringToNumberTool extends MessageToolDefinition<string, number> {\n * input: string;\n * output: number;\n * }\n * ```\n */\nexport interface MessageToolDefinition<TInput = unknown, TOutput = unknown> {\n input: TInput;\n output: TOutput;\n}\n\n/**\n * Represents a structured set of tools by mapping tool names to definitions\n * that can be used in messages.\n *\n * @example\n * ```ts\n * interface MyToolSet extends MessageToolSet {\n * calculator: MessageToolDefinition<\n * { operation: string; numbers: number[] },\n * number\n * >;\n * translator: MessageToolDefinition<\n * { text: string; targetLanguage: string },\n * string\n * >;\n * }\n * ```\n */\nexport interface MessageToolSet {\n [key: string]: MessageToolDefinition;\n}\n\n/**\n * Represents a tool call block within a message structure by mapping tool names to their\n * corresponding tool call formats, including the input arguments and an optional identifier.\n *\n * @template TStructure - A message structure type that may contain tool definitions\n *\n * @example\n * ```ts\n * // Given a message structure with a calculator tool:\n * interface MyStructure extends MessageStructure {\n * tools: {\n * calculator: MessageToolDefinition<{ operation: string, numbers: number[] }, number>\n * }\n * }\n *\n * // The tool call block would be:\n * type CalcToolCall = $MessageToolCallBlock<MyStructure>;\n * // Resolves to:\n * // {\n * // type: \"tool_call\";\n * // name: \"calculator\";\n * // args: { operation: string, numbers: number[] };\n * // id?: string;\n * // }\n * ```\n */\nexport type $MessageToolCallBlock<TStructure extends MessageStructure> =\n TStructure[\"tools\"] extends MessageToolSet\n ? {\n [K in keyof TStructure[\"tools\"]]: K extends string\n ? TStructure[\"tools\"][K] extends MessageToolDefinition\n ? ContentBlock.Tools.ToolCall<K, TStructure[\"tools\"][K][\"input\"]>\n : never\n : never;\n }[keyof TStructure[\"tools\"]]\n : never;\n\n/**\n * Core interface that defines the structure of messages.\n *\n * @example\n * ```ts\n * // Basic message structure with just content blocks\n * interface SimpleMessageStructure extends MessageStructure {\n * content: {\n * human: ContentBlock.Text;\n * // allows for text + reasoning blocks in ai messages\n * ai: ContentBlock.Text | ContentBlock.Reasoning;\n * }\n * }\n *\n * // Message structure with tools and properties\n * interface AdvancedMessageStructure extends MessageStructure {\n * tools: {\n * calculator: MessageToolDefinition<\n * { operation: string; numbers: number[] },\n * number\n * >;\n * };\n * content: {\n * // allows for text + image blocks in human messages\n * human: ContentBlock.Text | ContentBlock.Multimodal.Image;\n * // only allows for text blocks in ai messages\n * ai: ContentBlock.Text;\n * };\n * properties: {\n * // pins properties to ai messages\n * ai: {\n * response_metadata: {\n * confidence: number;\n * model: string;\n * };\n * };\n * }\n * }\n *\n * // Using with $MergeMessageStructure to combine structures\n * // The resulting type when passed into BaseMessage will have a calculator tool,\n * // allow for text + image blocks in human messages,\n * // and text + reasoning blocks + additional arbitrary properties in ai messages.\n * type CombinedStructure = $MergeMessageStructure<\n * SimpleMessageStructure,\n * AdvancedMessageStructure\n * >;\n *\n * // Using in a Message object\n * const message: Message<CombinedStructure> = {\n * id: \"msg-123\",\n * type: \"human\",\n * content: [\n * { type: \"text\", text: \"Hello!\" }\n * { type: \"image\", mimeType: \"image/jpeg\", url: \"https://example.com/image.jpg\" }\n * // this block will throw an error because it's not defined in the structure\n * { type: \"reasoning\", reasoning: \"The answer is 42\" }\n * ]\n * };\n * ```\n */\nexport interface MessageStructure {\n /**\n * Optional output version for the message structure.\n * If not provided, defaults to \"v0\".\n */\n readonly outputVersion?: MessageOutputVersion;\n /**\n * Optional set of tool definitions that can be used in messages.\n * Each tool is defined with input/output types and can be referenced in tool messages.\n */\n readonly tools?: MessageToolSet;\n /**\n * Optional mapping of message types to their allowed content blocks.\n * Each message type can specify what content block types it supports (text, images, etc).\n */\n readonly content?: Partial<{\n [key in MessageType]: ContentBlock;\n }>;\n /**\n * Optional mapping of message types to arbitrary property objects.\n * Allows attaching custom metadata or other information to specific message types.\n */\n readonly properties?: Partial<{\n [key in MessageType]: Record<string, unknown>;\n }>;\n}\n\n/**\n * Normalizes an arbitrary type to a message output version or undefined.\n * Accepts unknown and narrows to a valid MessageOutputVersion if present.\n */\ntype $NormalizeMessageOutputVersion<T> =\n | Extract<T, MessageOutputVersion>\n | undefined;\n\n/**\n * Merges two output version types from message structures.\n *\n * This utility type determines the resulting output version when combining two message structures.\n * The merge logic follows these rules:\n *\n * - If both T and U are undefined, defaults to \"v0\" for backwards compatibility\n * - If T is undefined but U is defined, uses U's version\n * - If U is undefined but T is defined, uses T's version\n * - If both T and U are defined, U takes precedence (later structure wins)\n *\n * @template T - The output version from the first message structure\n * @template U - The output version from the second message structure\n *\n * @example\n * ```ts\n * // Both undefined - defaults to \"v0\"\n * type Result1 = $MergeOutputVersion<undefined, undefined>; // \"v0\"\n *\n * // One defined - uses the defined version\n * type Result2 = $MergeOutputVersion<undefined, \"v1\">; // \"v1\"\n * type Result3 = $MergeOutputVersion<\"v0\", undefined>; // \"v0\"\n *\n * // Both defined - second takes precedence\n * type Result4 = $MergeOutputVersion<\"v0\", \"v1\">; // \"v1\"\n * ```\n */\nexport type $MergeOutputVersion<T, U> =\n $NormalizeMessageOutputVersion<T> extends infer TV\n ? $NormalizeMessageOutputVersion<U> extends infer UV\n ? [TV, UV] extends [undefined, undefined]\n ? \"v0\"\n : [TV] extends [undefined]\n ? Exclude<UV, undefined>\n : [UV] extends [undefined]\n ? Exclude<TV, undefined>\n : UV\n : never\n : never;\n\n/**\n * Merges two content definition objects from message structures.\n *\n * This utility type combines content definitions from two message structures, handling\n * the merging of content block types for each message type. The merge logic follows\n * these rules:\n *\n * - For keys that exist in both T and U: Merges the content blocks using discriminated\n * union merging based on the \"type\" property. This allows combining different content\n * block types (e.g., text + image) for the same message type.\n * - For keys that exist only in T: Uses T's content definition as-is\n * - For keys that exist only in U: Uses U's content definition as-is\n *\n * @template T - The content definition from the first message structure\n * @template U - The content definition from the second message structure\n *\n * @example\n * ```ts\n * // T allows text content for human messages\n * type ContentA = {\n * human: ContentBlock.Text;\n * };\n *\n * // U allows image content for human messages and text for AI messages\n * type ContentB = {\n * human: ContentBlock.Multimodal.Image;\n * ai: ContentBlock.Text;\n * };\n *\n * // Merged result allows both text and images for human messages, text for AI\n * type Merged = $MergeContentDefinition<ContentA, ContentB>;\n * // Result: {\n * // human: ContentBlock.Text | ContentBlock.Multimodal.Image;\n * // ai: ContentBlock.Text;\n * // }\n * ```\n */\nexport type $MergeContentDefinition<T, U> = {\n [K in keyof T | keyof U as Extract<\n (K extends keyof T ? T[K] : never) | (K extends keyof U ? U[K] : never),\n ContentBlock\n > extends never\n ? never\n : K]: K extends keyof T\n ? K extends keyof U\n ? $MergeDiscriminatedUnion<\n Extract<T[K], ContentBlock>,\n Extract<U[K], ContentBlock>,\n \"type\"\n >\n : Extract<T[K], ContentBlock>\n : K extends keyof U\n ? Extract<U[K], ContentBlock>\n : never;\n};\n\n/**\n * Merges two message structures A and B into a combined structure.\n * This is a type utility that handles merging of tools, content blocks, and properties\n * from two message structures. The resulting type is usable as its own message structure.\n *\n * @example\n * ```ts\n * // Structure A allows text in human messages and has a confidence property on AI messages\n * interface StructureA extends MessageStructure {\n * content: {\n * human: ContentBlock.Text;\n * };\n * properties: {\n * ai: { confidence: number };\n * }\n * }\n *\n * // Structure B allows images in human messages and has a model property on AI messages\n * interface StructureB extends MessageStructure {\n * content: {\n * human: ContentBlock.Multimodal.Image;\n * };\n * properties: {\n * ai: { model: string };\n * }\n * }\n *\n * // Merged structure allows both text and images in human messages\n * // AI messages have both confidence and model properties\n * type Merged = $MergeMessageStructure<StructureA, StructureB>;\n * ```\n *\n * @template A - First message structure to merge\n * @template B - Second message structure to merge (takes precedence over A)\n */\nexport type $MergeMessageStructure<\n T extends MessageStructure,\n U extends MessageStructure\n> = {\n outputVersion: $MergeOutputVersion<T[\"outputVersion\"], U[\"outputVersion\"]>;\n tools: $MergeObjects<T[\"tools\"], U[\"tools\"]>;\n content: $MergeContentDefinition<T[\"content\"], U[\"content\"]>;\n properties: $MergeObjects<T[\"properties\"], U[\"properties\"]>;\n};\n\n/**\n * Standard message structured used to define the most basic message structure that's\n * used throughout the library.\n *\n * This is also the message structure that's used when a message structure is not provided.\n */\nexport interface StandardMessageStructure extends MessageStructure {\n content: {\n /** Text content for AI messages */\n ai: ContentBlock.Text;\n /** Text content for human messages */\n human: ContentBlock.Text;\n /** Text content for system messages */\n system: ContentBlock.Text;\n /** Text content for tool messages */\n tool: ContentBlock.Text;\n };\n properties: {\n /** Properties specific to AI messages */\n ai: {\n /** Metadata about the AI model response */\n response_metadata?: ResponseMetadata;\n /** Usage statistics for the AI response */\n usage_metadata?: UsageMetadata;\n };\n human: {\n /** Metadata about the human message */\n response_metadata?: Record<string, unknown>;\n };\n system: {\n /** Metadata about the system message */\n response_metadata?: Record<string, unknown>;\n };\n tool: {\n /** Metadata about the tool message */\n response_metadata?: Record<string, unknown>;\n };\n };\n}\n\n/**\n * Takes a message structure type T and normalizes it by merging it with the standard message structure.\n * If T is already a standard message structure, returns T unchanged.\n *\n * This ensures that any custom message structure includes all the standard message structure fields\n * by default while allowing overrides and extensions.\n *\n * @template T - The message structure type to normalize, must extend MessageStructure\n * @returns Either T if it's already a standard structure, or the merged result of T with standard structure\n */\nexport type $NormalizedMessageStructure<T extends MessageStructure> =\n T extends StandardMessageStructure\n ? T\n : $MergeMessageStructure<StandardMessageStructure, T>;\n\n/**\n * Infers the content blocks for a specific message type in a message structure.\n *\n * This utility type extracts the content block type that corresponds to a given message type\n * from the message structure's content definition.\n *\n * @template TStructure - The message structure to infer content from\n * @template TRole - The message role/type to get content for (e.g., \"ai\", \"human\", \"system\", \"tool\")\n * @returns The content block type for the specified type, or never if its not defined in the structure\n *\n * @example\n * ```ts\n * interface MyStructure extends MessageStructure {\n * content: {\n * human: ContentBlock.Text;\n * ai: ContentBlock.Text | ContentBlock.ToolCall;\n * };\n * }\n *\n * type HumanContent = $InferMessageContentBlocks<MyStructure, \"human\">;\n * // HumanContent = ContentBlock.Text\n *\n * type AIContent = $InferMessageContentBlocks<MyStructure, \"ai\">;\n * // AIContent = ContentBlock.Text | ContentBlock.ToolCall\n * ```\n */\nexport type $InferMessageContentBlocks<\n TStructure extends MessageStructure,\n TRole extends MessageType\n> = $NormalizedMessageStructure<TStructure> extends infer S\n ? S extends MessageStructure\n ? S[\"content\"] extends infer C\n ? C extends Record<PropertyKey, ContentBlock>\n ? TRole extends keyof C\n ? [$MessageToolCallBlock<TStructure>] extends [never]\n ? C[TRole]\n : $MergeDiscriminatedUnion<\n NonNullable<C[TRole]>,\n $MessageToolCallBlock<TStructure>,\n \"type\"\n >\n : never\n : never\n : never\n : never\n : never;\n\n/**\n * Infers the content type for a specific message type from a message structure.\n *\n * This utility type determines the appropriate content type based on the message structure's\n * output version and the specified message type. The content type varies depending on the\n * output version (see {@link MessageOutputVersion})\n *\n * @template TStructure - The message structure to infer content from\n * @template TRole - The message role/type to get content for (e.g., \"ai\", \"human\", \"system\", \"tool\")\n * @returns The content type for the specified role based on the output version\n *\n * @example\n * ```ts\n * interface MyStructure extends MessageStructure {\n * outputVersion: \"v0\";\n * content: {\n * human: ContentBlock.Text;\n * ai: ContentBlock.Text | ContentBlock.ToolCall;\n * };\n * }\n *\n * type HumanContentV0 = $InferMessageContent<MyStructure, \"human\">;\n * // HumanContentV0 = string | Array<ContentBlock | ContentBlock.Text>\n *\n * interface MyStructureV1 extends MessageStructure {\n * outputVersion: \"v1\";\n * content: {\n * human: ContentBlock.Text;\n * ai: ContentBlock.Text | ContentBlock.Reasoning;\n * };\n * }\n *\n * type HumanContentV1 = $InferMessageContent<MyStructureV1, \"human\">;\n * // HumanContentV1 = ContentBlock.Text\n *\n * type AIContentV1 = $InferMessageContent<MyStructureV1, \"ai\">;\n * // AIContentV1 = ContentBlock.Text | ContentBlock.Reasoning\n * ```\n */\nexport type $InferMessageContent<\n TStructure extends MessageStructure,\n TRole extends MessageType\n> = TStructure[\"outputVersion\"] extends \"v1\"\n ? Array<$InferMessageContentBlocks<TStructure, TRole>>\n : string | Array<ContentBlock | ContentBlock.Text>;\n\n/**\n * Infers the properties for a specific message type from a message structure.\n *\n * This utility type extracts the properties object that corresponds to a given message type\n * from the message structure's properties definition, and excludes the reserved\n * \"content\" and \"type\" properties to avoid conflicts with the core message structure.\n *\n * If the specified type is not defined in the message structure's properties, it returns\n * a generic Record<string, unknown> type to allow for arbitrary properties.\n *\n * @template TStructure - The message structure to infer properties from\n * @template TRole - The message type/role to get properties for (e.g., \"ai\", \"human\", \"system\", \"tool\")\n * @returns The properties object type for the specified type, excluding \"content\" and \"type\"\n *\n * @example\n * ```ts\n * interface MyStructure extends MessageStructure {\n * properties: {\n * ai: {\n * response_metadata: { model: string };\n * usage_metadata: { tokens: number };\n * content: string; // This will be omitted\n * type: string; // This will be omitted\n * };\n * human: { metadata: Record<string, unknown> };\n * };\n * }\n *\n * type AIProperties = $InferMessageProperties<MyStructure, \"ai\">;\n * // AIProperties = { response_metadata: { model: string }; usage_metadata: { tokens: number } }\n *\n * type HumanProperties = $InferMessageProperties<MyStructure, \"human\">;\n * // HumanProperties = { metadata: Record<string, unknown> }\n *\n * type SystemProperties = $InferMessageProperties<MyStructure, \"system\">;\n * // SystemProperties = Record<string, unknown> (fallback for undefined role)\n * ```\n */\nexport type $InferMessageProperties<\n TStructure extends MessageStructure,\n TRole extends MessageType\n> = $NormalizedMessageStructure<TStructure> extends infer S\n ? S extends MessageStructure\n ? S[\"properties\"] extends infer P | undefined\n ? P extends Record<PropertyKey, unknown>\n ? TRole extends keyof P\n ? Omit<P[TRole], \"content\" | \"type\">\n : Record<string, unknown>\n : Record<string, unknown>\n : Record<string, unknown>\n : never\n : never;\n\n/**\n * Infers the type of a specific property for a message type from a message structure.\n *\n * This utility type extracts the type of a single property by name from the properties\n * object that corresponds to a given message type. If the specified property key does\n * not exist in the type's properties, it returns `never`.\n *\n * @template TStructure - The message structure to infer the property from\n * @template TRole - The message type/role to get the property for (e.g., \"ai\", \"human\", \"system\", \"tool\")\n * @template K - The property key to extract the type for\n * @returns The type of the specified property, or `never` if the property doesn't exist\n *\n * @example\n * ```ts\n * interface MyStructure extends MessageStructure {\n * properties: {\n * ai: {\n * response_metadata: { model: string; temperature: number };\n * usage_metadata: { input_tokens: number; output_tokens: number };\n * };\n * human: { metadata: Record<string, unknown> };\n * };\n * }\n *\n * type ResponseMetadata = $InferMessageProperty<MyStructure, \"ai\", \"response_metadata\">;\n * // ResponseMetadata = { model: string; temperature: number }\n *\n * type UsageMetadata = $InferMessageProperty<MyStructure, \"ai\", \"usage_metadata\">;\n * // UsageMetadata = { input_tokens: number; output_tokens: number }\n *\n * type NonExistentProperty = $InferMessageProperty<MyStructure, \"ai\", \"nonExistent\">;\n * // NonExistentProperty = Record<string, unknown>\n *\n * type HumanMetadata = $InferMessageProperty<MyStructure, \"human\", \"metadata\">;\n * // HumanMetadata = Record<string, unknown>\n * ```\n */\nexport type $InferMessageProperty<\n TStructure extends MessageStructure,\n TRole extends MessageType,\n K extends string\n> = K extends keyof $InferMessageProperties<TStructure, TRole>\n ? $InferMessageProperties<TStructure, TRole>[K]\n : never;\n\n/**\n * Infers the response metadata type for a specific message type from a message structure.\n *\n * This utility type extracts the `response_metadata` property type for a given message type.\n *\n * @template TStructure - The message structure to infer the response metadata from\n * @template TRole - The message type/role to get the response metadata for (e.g., \"ai\", \"human\", \"system\", \"tool\")\n * @returns The type of the response_metadata property, or `Record<string, unknown>` as fallback\n *\n * @example\n * ```ts\n * interface MyStructure extends MessageStructure {\n * properties: {\n * ai: {\n * response_metadata: { model: string; temperature: number; tokens: number };\n * };\n * human: { metadata: Record<string, unknown> };\n * };\n * }\n *\n * type AIResponseMetadata = $InferResponseMetadata<MyStructure, \"ai\">;\n * // AIResponseMetadata = { model: string; temperature: number; tokens: number }\n *\n * type HumanResponseMetadata = $InferResponseMetadata<MyStructure, \"human\">;\n * // HumanResponseMetadata = Record<string, unknown> (fallback since not defined)\n * ```\n */\nexport type $InferResponseMetadata<\n TStructure extends MessageStructure,\n TRole extends MessageType\n> = $InferMessageProperty<\n TStructure,\n TRole,\n \"response_metadata\"\n> extends infer P\n ? [P] extends [unknown]\n ? Record<string, unknown>\n : P\n : never;\n\n/**\n * Represents a message object that organizes context for an LLM.\n *\n * @example\n * ```ts\n * // Basic message with text content\n * const message: Message = {\n * id: \"msg-123\",\n * name: \"user\",\n * type: \"human\",\n * content: [{ type: \"text\", text: \"Hello!\" }]\n * };\n *\n * // Basic ai message interface extension\n * interface MyMessage extends Message<StandardMessageStructure, \"ai\"> {\n * // Additional AI-specific properties can be added here\n * }\n *`\n * // Custom message structure\n * interface CustomStructure extends MessageStructure {\n * content: {\n * ai: ContentBlock.Text | ContentBlock.ToolCall<\"search\", { query: string }>;\n * human: ContentBlock.Text | ContentBlock.Multimodal.Image;\n * };\n * }\n *\n * // Create a message with custom structure\n * const message: Message<CustomStructure> = {\n * id: \"msg-123\",\n * name: \"user\",\n * type: \"ai\",\n * content: [\n * { type: \"text\", text: \"Hello!\" },\n * {\n * type: \"tool_call\",\n * name: \"search\",\n * args: { query: \"What is the capital of France?\" }\n * }\n * ]\n * };\n * ```\n */\nexport interface Message<\n TStructure extends MessageStructure = StandardMessageStructure,\n TRole extends MessageType = MessageType\n> {\n /** The message type/role */\n readonly type: TRole;\n /** Unique identifier for this message */\n id?: string;\n /** Optional name/identifier for the entity that created this message */\n name?: string;\n /** Array of content blocks that make up the message content */\n content: $InferMessageContent<TStructure, TRole>;\n /** Metadata about the message */\n response_metadata?: Partial<$InferResponseMetadata<TStructure, TRole>>;\n}\n\n/**\n * Type guard to check if a value is a valid Message object.\n *\n * @param message - The value to check\n * @returns true if the value is a valid Message object, false otherwise\n */\nexport function isMessage(message: unknown): message is Message {\n return (\n typeof message === \"object\" &&\n message !== null &&\n \"type\" in message &&\n \"content\" in message &&\n (typeof message.content === \"string\" || Array.isArray(message.content))\n );\n}\n"],"mappings":";;;;;;;AAitBA,SAAgB,UAAUA,SAAsC;AAC9D,QACE,OAAO,YAAY,YACnB,YAAY,QACZ,UAAU,WACV,aAAa,YACZ,OAAO,QAAQ,YAAY,YAAY,MAAM,QAAQ,QAAQ,QAAQ;AAEzE"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const require_base = require('./base.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/messages/metadata.ts
|
|
4
|
+
function mergeResponseMetadata(a, b) {
|
|
5
|
+
const output = require_base._mergeDicts(a ?? {}, b ?? {});
|
|
6
|
+
return output;
|
|
7
|
+
}
|
|
8
|
+
function mergeModalitiesTokenDetails(a, b) {
|
|
9
|
+
const output = {};
|
|
10
|
+
if (a?.audio !== void 0 || b?.audio !== void 0) output.audio = (a?.audio ?? 0) + (b?.audio ?? 0);
|
|
11
|
+
if (a?.image !== void 0 || b?.image !== void 0) output.image = (a?.image ?? 0) + (b?.image ?? 0);
|
|
12
|
+
if (a?.video !== void 0 || b?.video !== void 0) output.video = (a?.video ?? 0) + (b?.video ?? 0);
|
|
13
|
+
if (a?.document !== void 0 || b?.document !== void 0) output.document = (a?.document ?? 0) + (b?.document ?? 0);
|
|
14
|
+
if (a?.text !== void 0 || b?.text !== void 0) output.text = (a?.text ?? 0) + (b?.text ?? 0);
|
|
15
|
+
return output;
|
|
16
|
+
}
|
|
17
|
+
function mergeInputTokenDetails(a, b) {
|
|
18
|
+
const output = { ...mergeModalitiesTokenDetails(a, b) };
|
|
19
|
+
if (a?.cache_read !== void 0 || b?.cache_read !== void 0) output.cache_read = (a?.cache_read ?? 0) + (b?.cache_read ?? 0);
|
|
20
|
+
if (a?.cache_creation !== void 0 || b?.cache_creation !== void 0) output.cache_creation = (a?.cache_creation ?? 0) + (b?.cache_creation ?? 0);
|
|
21
|
+
return output;
|
|
22
|
+
}
|
|
23
|
+
function mergeOutputTokenDetails(a, b) {
|
|
24
|
+
const output = { ...mergeModalitiesTokenDetails(a, b) };
|
|
25
|
+
if (a?.reasoning !== void 0 || b?.reasoning !== void 0) output.reasoning = (a?.reasoning ?? 0) + (b?.reasoning ?? 0);
|
|
26
|
+
return output;
|
|
27
|
+
}
|
|
28
|
+
function mergeUsageMetadata(a, b) {
|
|
29
|
+
return {
|
|
30
|
+
input_tokens: (a?.input_tokens ?? 0) + (b?.input_tokens ?? 0),
|
|
31
|
+
output_tokens: (a?.output_tokens ?? 0) + (b?.output_tokens ?? 0),
|
|
32
|
+
total_tokens: (a?.total_tokens ?? 0) + (b?.total_tokens ?? 0),
|
|
33
|
+
input_token_details: mergeInputTokenDetails(a?.input_token_details, b?.input_token_details),
|
|
34
|
+
output_token_details: mergeOutputTokenDetails(a?.output_token_details, b?.output_token_details)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
exports.mergeResponseMetadata = mergeResponseMetadata;
|
|
40
|
+
exports.mergeUsageMetadata = mergeUsageMetadata;
|
|
41
|
+
//# sourceMappingURL=metadata.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata.cjs","names":["a?: ResponseMetadata","b?: ResponseMetadata","output: ResponseMetadata","_mergeDicts","a?: ModalitiesTokenDetails","b?: ModalitiesTokenDetails","output: ModalitiesTokenDetails","a?: InputTokenDetails","b?: InputTokenDetails","output: InputTokenDetails","a?: OutputTokenDetails","b?: OutputTokenDetails","output: OutputTokenDetails","a?: UsageMetadata","b?: UsageMetadata"],"sources":["../../src/messages/metadata.ts"],"sourcesContent":["import { _mergeDicts } from \"./base.js\";\n\nexport type ResponseMetadata = {\n model_provider?: string;\n model_name?: string;\n [key: string]: unknown;\n};\n\nexport function mergeResponseMetadata(\n a?: ResponseMetadata,\n b?: ResponseMetadata\n): ResponseMetadata {\n const output: ResponseMetadata = _mergeDicts(a ?? {}, b ?? {});\n return output;\n}\n\nexport type ModalitiesTokenDetails = {\n /**\n * Text tokens.\n * Does not need to be reported, but some models will do so.\n */\n text?: number;\n\n /**\n * Image (non-video) tokens.\n */\n image?: number;\n\n /**\n * Audio tokens.\n */\n audio?: number;\n\n /**\n * Video tokens.\n */\n video?: number;\n\n /**\n * Document tokens.\n * e.g. PDF\n */\n document?: number;\n};\n\nfunction mergeModalitiesTokenDetails(\n a?: ModalitiesTokenDetails,\n b?: ModalitiesTokenDetails\n): ModalitiesTokenDetails {\n const output: ModalitiesTokenDetails = {};\n if (a?.audio !== undefined || b?.audio !== undefined) {\n output.audio = (a?.audio ?? 0) + (b?.audio ?? 0);\n }\n if (a?.image !== undefined || b?.image !== undefined) {\n output.image = (a?.image ?? 0) + (b?.image ?? 0);\n }\n if (a?.video !== undefined || b?.video !== undefined) {\n output.video = (a?.video ?? 0) + (b?.video ?? 0);\n }\n if (a?.document !== undefined || b?.document !== undefined) {\n output.document = (a?.document ?? 0) + (b?.document ?? 0);\n }\n if (a?.text !== undefined || b?.text !== undefined) {\n output.text = (a?.text ?? 0) + (b?.text ?? 0);\n }\n return output;\n}\n\n/**\n * Breakdown of input token counts.\n *\n * Does not *need* to sum to full input token count. Does *not* need to have all keys.\n */\nexport type InputTokenDetails = ModalitiesTokenDetails & {\n /**\n * Input tokens that were cached and there was a cache hit.\n *\n * Since there was a cache hit, the tokens were read from the cache.\n * More precisely, the model state given these tokens was read from the cache.\n */\n cache_read?: number;\n\n /**\n * Input tokens that were cached and there was a cache miss.\n *\n * Since there was a cache miss, the cache was created from these tokens.\n */\n cache_creation?: number;\n};\n\nfunction mergeInputTokenDetails(\n a?: InputTokenDetails,\n b?: InputTokenDetails\n): InputTokenDetails {\n const output: InputTokenDetails = {\n ...mergeModalitiesTokenDetails(a, b),\n };\n if (a?.cache_read !== undefined || b?.cache_read !== undefined) {\n output.cache_read = (a?.cache_read ?? 0) + (b?.cache_read ?? 0);\n }\n if (a?.cache_creation !== undefined || b?.cache_creation !== undefined) {\n output.cache_creation = (a?.cache_creation ?? 0) + (b?.cache_creation ?? 0);\n }\n return output;\n}\n\n/**\n * Breakdown of output token counts.\n *\n * Does *not* need to sum to full output token count. Does *not* need to have all keys.\n */\nexport type OutputTokenDetails = ModalitiesTokenDetails & {\n /**\n * Reasoning output tokens.\n *\n * Tokens generated by the model in a chain of thought process (i.e. by\n * OpenAI's o1 models) that are not returned as part of model output.\n */\n reasoning?: number;\n};\n\nfunction mergeOutputTokenDetails(\n a?: OutputTokenDetails,\n b?: OutputTokenDetails\n): OutputTokenDetails {\n const output: OutputTokenDetails = {\n ...mergeModalitiesTokenDetails(a, b),\n };\n if (a?.reasoning !== undefined || b?.reasoning !== undefined) {\n output.reasoning = (a?.reasoning ?? 0) + (b?.reasoning ?? 0);\n }\n return output;\n}\n\n/**\n * Usage metadata for a message, such as token counts.\n */\nexport type UsageMetadata = {\n /**\n * Count of input (or prompt) tokens. Sum of all input token types.\n */\n input_tokens: number;\n /**\n * Count of output (or completion) tokens. Sum of all output token types.\n */\n output_tokens: number;\n /**\n * Total token count. Sum of input_tokens + output_tokens.\n */\n total_tokens: number;\n\n /**\n * Breakdown of input token counts.\n *\n * Does *not* need to sum to full input token count. Does *not* need to have all keys.\n */\n input_token_details?: InputTokenDetails;\n\n /**\n * Breakdown of output token counts.\n *\n * Does *not* need to sum to full output token count. Does *not* need to have all keys.\n */\n output_token_details?: OutputTokenDetails;\n};\n\nexport function mergeUsageMetadata(\n a?: UsageMetadata,\n b?: UsageMetadata\n): UsageMetadata {\n return {\n input_tokens: (a?.input_tokens ?? 0) + (b?.input_tokens ?? 0),\n output_tokens: (a?.output_tokens ?? 0) + (b?.output_tokens ?? 0),\n total_tokens: (a?.total_tokens ?? 0) + (b?.total_tokens ?? 0),\n input_token_details: mergeInputTokenDetails(\n a?.input_token_details,\n b?.input_token_details\n ),\n output_token_details: mergeOutputTokenDetails(\n a?.output_token_details,\n b?.output_token_details\n ),\n };\n}\n"],"mappings":";;;AAQA,SAAgB,sBACdA,GACAC,GACkB;CAClB,MAAMC,SAA2BC,yBAAY,KAAK,CAAE,GAAE,KAAK,CAAE,EAAC;AAC9D,QAAO;AACR;AA+BD,SAAS,4BACPC,GACAC,GACwB;CACxB,MAAMC,SAAiC,CAAE;AACzC,KAAI,GAAG,UAAU,UAAa,GAAG,UAAU,QACzC,OAAO,SAAS,GAAG,SAAS,MAAM,GAAG,SAAS;AAEhD,KAAI,GAAG,UAAU,UAAa,GAAG,UAAU,QACzC,OAAO,SAAS,GAAG,SAAS,MAAM,GAAG,SAAS;AAEhD,KAAI,GAAG,UAAU,UAAa,GAAG,UAAU,QACzC,OAAO,SAAS,GAAG,SAAS,MAAM,GAAG,SAAS;AAEhD,KAAI,GAAG,aAAa,UAAa,GAAG,aAAa,QAC/C,OAAO,YAAY,GAAG,YAAY,MAAM,GAAG,YAAY;AAEzD,KAAI,GAAG,SAAS,UAAa,GAAG,SAAS,QACvC,OAAO,QAAQ,GAAG,QAAQ,MAAM,GAAG,QAAQ;AAE7C,QAAO;AACR;AAwBD,SAAS,uBACPC,GACAC,GACmB;CACnB,MAAMC,SAA4B,EAChC,GAAG,4BAA4B,GAAG,EAAE,CACrC;AACD,KAAI,GAAG,eAAe,UAAa,GAAG,eAAe,QACnD,OAAO,cAAc,GAAG,cAAc,MAAM,GAAG,cAAc;AAE/D,KAAI,GAAG,mBAAmB,UAAa,GAAG,mBAAmB,QAC3D,OAAO,kBAAkB,GAAG,kBAAkB,MAAM,GAAG,kBAAkB;AAE3E,QAAO;AACR;AAiBD,SAAS,wBACPC,GACAC,GACoB;CACpB,MAAMC,SAA6B,EACjC,GAAG,4BAA4B,GAAG,EAAE,CACrC;AACD,KAAI,GAAG,cAAc,UAAa,GAAG,cAAc,QACjD,OAAO,aAAa,GAAG,aAAa,MAAM,GAAG,aAAa;AAE5D,QAAO;AACR;AAkCD,SAAgB,mBACdC,GACAC,GACe;AACf,QAAO;EACL,eAAe,GAAG,gBAAgB,MAAM,GAAG,gBAAgB;EAC3D,gBAAgB,GAAG,iBAAiB,MAAM,GAAG,iBAAiB;EAC9D,eAAe,GAAG,gBAAgB,MAAM,GAAG,gBAAgB;EAC3D,qBAAqB,uBACnB,GAAG,qBACH,GAAG,oBACJ;EACD,sBAAsB,wBACpB,GAAG,sBACH,GAAG,qBACJ;CACF;AACF"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
//#region src/messages/metadata.d.ts
|
|
2
|
+
type ResponseMetadata = {
|
|
3
|
+
model_provider?: string;
|
|
4
|
+
model_name?: string;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
};
|
|
7
|
+
declare function mergeResponseMetadata(a?: ResponseMetadata, b?: ResponseMetadata): ResponseMetadata;
|
|
8
|
+
type ModalitiesTokenDetails = {
|
|
9
|
+
/**
|
|
10
|
+
* Text tokens.
|
|
11
|
+
* Does not need to be reported, but some models will do so.
|
|
12
|
+
*/
|
|
13
|
+
text?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Image (non-video) tokens.
|
|
16
|
+
*/
|
|
17
|
+
image?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Audio tokens.
|
|
20
|
+
*/
|
|
21
|
+
audio?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Video tokens.
|
|
24
|
+
*/
|
|
25
|
+
video?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Document tokens.
|
|
28
|
+
* e.g. PDF
|
|
29
|
+
*/
|
|
30
|
+
document?: number;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Breakdown of input token counts.
|
|
34
|
+
*
|
|
35
|
+
* Does not *need* to sum to full input token count. Does *not* need to have all keys.
|
|
36
|
+
*/
|
|
37
|
+
type InputTokenDetails = ModalitiesTokenDetails & {
|
|
38
|
+
/**
|
|
39
|
+
* Input tokens that were cached and there was a cache hit.
|
|
40
|
+
*
|
|
41
|
+
* Since there was a cache hit, the tokens were read from the cache.
|
|
42
|
+
* More precisely, the model state given these tokens was read from the cache.
|
|
43
|
+
*/
|
|
44
|
+
cache_read?: number;
|
|
45
|
+
/**
|
|
46
|
+
* Input tokens that were cached and there was a cache miss.
|
|
47
|
+
*
|
|
48
|
+
* Since there was a cache miss, the cache was created from these tokens.
|
|
49
|
+
*/
|
|
50
|
+
cache_creation?: number;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Breakdown of output token counts.
|
|
54
|
+
*
|
|
55
|
+
* Does *not* need to sum to full output token count. Does *not* need to have all keys.
|
|
56
|
+
*/
|
|
57
|
+
type OutputTokenDetails = ModalitiesTokenDetails & {
|
|
58
|
+
/**
|
|
59
|
+
* Reasoning output tokens.
|
|
60
|
+
*
|
|
61
|
+
* Tokens generated by the model in a chain of thought process (i.e. by
|
|
62
|
+
* OpenAI's o1 models) that are not returned as part of model output.
|
|
63
|
+
*/
|
|
64
|
+
reasoning?: number;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Usage metadata for a message, such as token counts.
|
|
68
|
+
*/
|
|
69
|
+
type UsageMetadata = {
|
|
70
|
+
/**
|
|
71
|
+
* Count of input (or prompt) tokens. Sum of all input token types.
|
|
72
|
+
*/
|
|
73
|
+
input_tokens: number;
|
|
74
|
+
/**
|
|
75
|
+
* Count of output (or completion) tokens. Sum of all output token types.
|
|
76
|
+
*/
|
|
77
|
+
output_tokens: number;
|
|
78
|
+
/**
|
|
79
|
+
* Total token count. Sum of input_tokens + output_tokens.
|
|
80
|
+
*/
|
|
81
|
+
total_tokens: number;
|
|
82
|
+
/**
|
|
83
|
+
* Breakdown of input token counts.
|
|
84
|
+
*
|
|
85
|
+
* Does *not* need to sum to full input token count. Does *not* need to have all keys.
|
|
86
|
+
*/
|
|
87
|
+
input_token_details?: InputTokenDetails;
|
|
88
|
+
/**
|
|
89
|
+
* Breakdown of output token counts.
|
|
90
|
+
*
|
|
91
|
+
* Does *not* need to sum to full output token count. Does *not* need to have all keys.
|
|
92
|
+
*/
|
|
93
|
+
output_token_details?: OutputTokenDetails;
|
|
94
|
+
};
|
|
95
|
+
declare function mergeUsageMetadata(a?: UsageMetadata, b?: UsageMetadata): UsageMetadata;
|
|
96
|
+
//#endregion
|
|
97
|
+
export { InputTokenDetails, ModalitiesTokenDetails, OutputTokenDetails, ResponseMetadata, UsageMetadata, mergeResponseMetadata, mergeUsageMetadata };
|
|
98
|
+
//# sourceMappingURL=metadata.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata.d.cts","names":["ResponseMetadata","mergeResponseMetadata","ModalitiesTokenDetails","InputTokenDetails","OutputTokenDetails","UsageMetadata","mergeUsageMetadata"],"sources":["../../src/messages/metadata.d.ts"],"sourcesContent":["export type ResponseMetadata = {\n model_provider?: string;\n model_name?: string;\n [key: string]: unknown;\n};\nexport declare function mergeResponseMetadata(a?: ResponseMetadata, b?: ResponseMetadata): ResponseMetadata;\nexport type ModalitiesTokenDetails = {\n /**\n * Text tokens.\n * Does not need to be reported, but some models will do so.\n */\n text?: number;\n /**\n * Image (non-video) tokens.\n */\n image?: number;\n /**\n * Audio tokens.\n */\n audio?: number;\n /**\n * Video tokens.\n */\n video?: number;\n /**\n * Document tokens.\n * e.g. PDF\n */\n document?: number;\n};\n/**\n * Breakdown of input token counts.\n *\n * Does not *need* to sum to full input token count. Does *not* need to have all keys.\n */\nexport type InputTokenDetails = ModalitiesTokenDetails & {\n /**\n * Input tokens that were cached and there was a cache hit.\n *\n * Since there was a cache hit, the tokens were read from the cache.\n * More precisely, the model state given these tokens was read from the cache.\n */\n cache_read?: number;\n /**\n * Input tokens that were cached and there was a cache miss.\n *\n * Since there was a cache miss, the cache was created from these tokens.\n */\n cache_creation?: number;\n};\n/**\n * Breakdown of output token counts.\n *\n * Does *not* need to sum to full output token count. Does *not* need to have all keys.\n */\nexport type OutputTokenDetails = ModalitiesTokenDetails & {\n /**\n * Reasoning output tokens.\n *\n * Tokens generated by the model in a chain of thought process (i.e. by\n * OpenAI's o1 models) that are not returned as part of model output.\n */\n reasoning?: number;\n};\n/**\n * Usage metadata for a message, such as token counts.\n */\nexport type UsageMetadata = {\n /**\n * Count of input (or prompt) tokens. Sum of all input token types.\n */\n input_tokens: number;\n /**\n * Count of output (or completion) tokens. Sum of all output token types.\n */\n output_tokens: number;\n /**\n * Total token count. Sum of input_tokens + output_tokens.\n */\n total_tokens: number;\n /**\n * Breakdown of input token counts.\n *\n * Does *not* need to sum to full input token count. Does *not* need to have all keys.\n */\n input_token_details?: InputTokenDetails;\n /**\n * Breakdown of output token counts.\n *\n * Does *not* need to sum to full output token count. Does *not* need to have all keys.\n */\n output_token_details?: OutputTokenDetails;\n};\nexport declare function mergeUsageMetadata(a?: UsageMetadata, b?: UsageMetadata): UsageMetadata;\n"],"mappings":";KAAYA,gBAAAA;EAAAA,cAAAA,CAAAA,EAAAA,MAAgB;EAKJC,UAAAA,CAAAA,EAAAA,MAAAA;EAAqB,CAAA,GAAA,EAAA,MAAA,CAAA,EAAA,OAAA;CAAA;AAA2BD,iBAAhDC,qBAAAA,CAAgDD,CAAAA,CAAAA,EAAtBA,gBAAsBA,EAAAA,CAAAA,CAAAA,EAAAA,gBAAAA,CAAAA,EAAmBA,gBAAnBA;AAAmBA,KAC/EE,sBAAAA,GAD+EF;EAAgB;AAC3G;AA6BA;AAoBA;EAYYK,IAAAA,CAAAA,EAAAA,MAAAA;EAAa;;;EAwBoB,KAAA,CAAA,EAAA,MAAA;EAErBC;;;EAAoC,KAAMD,CAAAA,EAAAA,MAAAA;EAAa;AAAgB;;;;;;;;;;;;;;KA1DnFF,iBAAAA,GAAoBD;;;;;;;;;;;;;;;;;;;;KAoBpBE,kBAAAA,GAAqBF;;;;;;;;;;;;KAYrBG,aAAAA;;;;;;;;;;;;;;;;;;wBAkBcF;;;;;;yBAMCC;;iBAEHE,kBAAAA,KAAuBD,mBAAmBA,gBAAgBA"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
//#region src/messages/metadata.d.ts
|
|
2
|
+
type ResponseMetadata = {
|
|
3
|
+
model_provider?: string;
|
|
4
|
+
model_name?: string;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
};
|
|
7
|
+
declare function mergeResponseMetadata(a?: ResponseMetadata, b?: ResponseMetadata): ResponseMetadata;
|
|
8
|
+
type ModalitiesTokenDetails = {
|
|
9
|
+
/**
|
|
10
|
+
* Text tokens.
|
|
11
|
+
* Does not need to be reported, but some models will do so.
|
|
12
|
+
*/
|
|
13
|
+
text?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Image (non-video) tokens.
|
|
16
|
+
*/
|
|
17
|
+
image?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Audio tokens.
|
|
20
|
+
*/
|
|
21
|
+
audio?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Video tokens.
|
|
24
|
+
*/
|
|
25
|
+
video?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Document tokens.
|
|
28
|
+
* e.g. PDF
|
|
29
|
+
*/
|
|
30
|
+
document?: number;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Breakdown of input token counts.
|
|
34
|
+
*
|
|
35
|
+
* Does not *need* to sum to full input token count. Does *not* need to have all keys.
|
|
36
|
+
*/
|
|
37
|
+
type InputTokenDetails = ModalitiesTokenDetails & {
|
|
38
|
+
/**
|
|
39
|
+
* Input tokens that were cached and there was a cache hit.
|
|
40
|
+
*
|
|
41
|
+
* Since there was a cache hit, the tokens were read from the cache.
|
|
42
|
+
* More precisely, the model state given these tokens was read from the cache.
|
|
43
|
+
*/
|
|
44
|
+
cache_read?: number;
|
|
45
|
+
/**
|
|
46
|
+
* Input tokens that were cached and there was a cache miss.
|
|
47
|
+
*
|
|
48
|
+
* Since there was a cache miss, the cache was created from these tokens.
|
|
49
|
+
*/
|
|
50
|
+
cache_creation?: number;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Breakdown of output token counts.
|
|
54
|
+
*
|
|
55
|
+
* Does *not* need to sum to full output token count. Does *not* need to have all keys.
|
|
56
|
+
*/
|
|
57
|
+
type OutputTokenDetails = ModalitiesTokenDetails & {
|
|
58
|
+
/**
|
|
59
|
+
* Reasoning output tokens.
|
|
60
|
+
*
|
|
61
|
+
* Tokens generated by the model in a chain of thought process (i.e. by
|
|
62
|
+
* OpenAI's o1 models) that are not returned as part of model output.
|
|
63
|
+
*/
|
|
64
|
+
reasoning?: number;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Usage metadata for a message, such as token counts.
|
|
68
|
+
*/
|
|
69
|
+
type UsageMetadata = {
|
|
70
|
+
/**
|
|
71
|
+
* Count of input (or prompt) tokens. Sum of all input token types.
|
|
72
|
+
*/
|
|
73
|
+
input_tokens: number;
|
|
74
|
+
/**
|
|
75
|
+
* Count of output (or completion) tokens. Sum of all output token types.
|
|
76
|
+
*/
|
|
77
|
+
output_tokens: number;
|
|
78
|
+
/**
|
|
79
|
+
* Total token count. Sum of input_tokens + output_tokens.
|
|
80
|
+
*/
|
|
81
|
+
total_tokens: number;
|
|
82
|
+
/**
|
|
83
|
+
* Breakdown of input token counts.
|
|
84
|
+
*
|
|
85
|
+
* Does *not* need to sum to full input token count. Does *not* need to have all keys.
|
|
86
|
+
*/
|
|
87
|
+
input_token_details?: InputTokenDetails;
|
|
88
|
+
/**
|
|
89
|
+
* Breakdown of output token counts.
|
|
90
|
+
*
|
|
91
|
+
* Does *not* need to sum to full output token count. Does *not* need to have all keys.
|
|
92
|
+
*/
|
|
93
|
+
output_token_details?: OutputTokenDetails;
|
|
94
|
+
};
|
|
95
|
+
declare function mergeUsageMetadata(a?: UsageMetadata, b?: UsageMetadata): UsageMetadata;
|
|
96
|
+
//#endregion
|
|
97
|
+
export { InputTokenDetails, ModalitiesTokenDetails, OutputTokenDetails, ResponseMetadata, UsageMetadata, mergeResponseMetadata, mergeUsageMetadata };
|
|
98
|
+
//# sourceMappingURL=metadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata.d.ts","names":["ResponseMetadata","mergeResponseMetadata","ModalitiesTokenDetails","InputTokenDetails","OutputTokenDetails","UsageMetadata","mergeUsageMetadata"],"sources":["../../src/messages/metadata.d.ts"],"sourcesContent":["export type ResponseMetadata = {\n model_provider?: string;\n model_name?: string;\n [key: string]: unknown;\n};\nexport declare function mergeResponseMetadata(a?: ResponseMetadata, b?: ResponseMetadata): ResponseMetadata;\nexport type ModalitiesTokenDetails = {\n /**\n * Text tokens.\n * Does not need to be reported, but some models will do so.\n */\n text?: number;\n /**\n * Image (non-video) tokens.\n */\n image?: number;\n /**\n * Audio tokens.\n */\n audio?: number;\n /**\n * Video tokens.\n */\n video?: number;\n /**\n * Document tokens.\n * e.g. PDF\n */\n document?: number;\n};\n/**\n * Breakdown of input token counts.\n *\n * Does not *need* to sum to full input token count. Does *not* need to have all keys.\n */\nexport type InputTokenDetails = ModalitiesTokenDetails & {\n /**\n * Input tokens that were cached and there was a cache hit.\n *\n * Since there was a cache hit, the tokens were read from the cache.\n * More precisely, the model state given these tokens was read from the cache.\n */\n cache_read?: number;\n /**\n * Input tokens that were cached and there was a cache miss.\n *\n * Since there was a cache miss, the cache was created from these tokens.\n */\n cache_creation?: number;\n};\n/**\n * Breakdown of output token counts.\n *\n * Does *not* need to sum to full output token count. Does *not* need to have all keys.\n */\nexport type OutputTokenDetails = ModalitiesTokenDetails & {\n /**\n * Reasoning output tokens.\n *\n * Tokens generated by the model in a chain of thought process (i.e. by\n * OpenAI's o1 models) that are not returned as part of model output.\n */\n reasoning?: number;\n};\n/**\n * Usage metadata for a message, such as token counts.\n */\nexport type UsageMetadata = {\n /**\n * Count of input (or prompt) tokens. Sum of all input token types.\n */\n input_tokens: number;\n /**\n * Count of output (or completion) tokens. Sum of all output token types.\n */\n output_tokens: number;\n /**\n * Total token count. Sum of input_tokens + output_tokens.\n */\n total_tokens: number;\n /**\n * Breakdown of input token counts.\n *\n * Does *not* need to sum to full input token count. Does *not* need to have all keys.\n */\n input_token_details?: InputTokenDetails;\n /**\n * Breakdown of output token counts.\n *\n * Does *not* need to sum to full output token count. Does *not* need to have all keys.\n */\n output_token_details?: OutputTokenDetails;\n};\nexport declare function mergeUsageMetadata(a?: UsageMetadata, b?: UsageMetadata): UsageMetadata;\n"],"mappings":";KAAYA,gBAAAA;EAAAA,cAAAA,CAAAA,EAAAA,MAAgB;EAKJC,UAAAA,CAAAA,EAAAA,MAAAA;EAAqB,CAAA,GAAA,EAAA,MAAA,CAAA,EAAA,OAAA;CAAA;AAA2BD,iBAAhDC,qBAAAA,CAAgDD,CAAAA,CAAAA,EAAtBA,gBAAsBA,EAAAA,CAAAA,CAAAA,EAAAA,gBAAAA,CAAAA,EAAmBA,gBAAnBA;AAAmBA,KAC/EE,sBAAAA,GAD+EF;EAAgB;AAC3G;AA6BA;AAoBA;EAYYK,IAAAA,CAAAA,EAAAA,MAAAA;EAAa;;;EAwBoB,KAAA,CAAA,EAAA,MAAA;EAErBC;;;EAAoC,KAAMD,CAAAA,EAAAA,MAAAA;EAAa;AAAgB;;;;;;;;;;;;;;KA1DnFF,iBAAAA,GAAoBD;;;;;;;;;;;;;;;;;;;;KAoBpBE,kBAAAA,GAAqBF;;;;;;;;;;;;KAYrBG,aAAAA;;;;;;;;;;;;;;;;;;wBAkBcF;;;;;;yBAMCC;;iBAEHE,kBAAAA,KAAuBD,mBAAmBA,gBAAgBA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { _mergeDicts } from "./base.js";
|
|
2
|
+
|
|
3
|
+
//#region src/messages/metadata.ts
|
|
4
|
+
function mergeResponseMetadata(a, b) {
|
|
5
|
+
const output = _mergeDicts(a ?? {}, b ?? {});
|
|
6
|
+
return output;
|
|
7
|
+
}
|
|
8
|
+
function mergeModalitiesTokenDetails(a, b) {
|
|
9
|
+
const output = {};
|
|
10
|
+
if (a?.audio !== void 0 || b?.audio !== void 0) output.audio = (a?.audio ?? 0) + (b?.audio ?? 0);
|
|
11
|
+
if (a?.image !== void 0 || b?.image !== void 0) output.image = (a?.image ?? 0) + (b?.image ?? 0);
|
|
12
|
+
if (a?.video !== void 0 || b?.video !== void 0) output.video = (a?.video ?? 0) + (b?.video ?? 0);
|
|
13
|
+
if (a?.document !== void 0 || b?.document !== void 0) output.document = (a?.document ?? 0) + (b?.document ?? 0);
|
|
14
|
+
if (a?.text !== void 0 || b?.text !== void 0) output.text = (a?.text ?? 0) + (b?.text ?? 0);
|
|
15
|
+
return output;
|
|
16
|
+
}
|
|
17
|
+
function mergeInputTokenDetails(a, b) {
|
|
18
|
+
const output = { ...mergeModalitiesTokenDetails(a, b) };
|
|
19
|
+
if (a?.cache_read !== void 0 || b?.cache_read !== void 0) output.cache_read = (a?.cache_read ?? 0) + (b?.cache_read ?? 0);
|
|
20
|
+
if (a?.cache_creation !== void 0 || b?.cache_creation !== void 0) output.cache_creation = (a?.cache_creation ?? 0) + (b?.cache_creation ?? 0);
|
|
21
|
+
return output;
|
|
22
|
+
}
|
|
23
|
+
function mergeOutputTokenDetails(a, b) {
|
|
24
|
+
const output = { ...mergeModalitiesTokenDetails(a, b) };
|
|
25
|
+
if (a?.reasoning !== void 0 || b?.reasoning !== void 0) output.reasoning = (a?.reasoning ?? 0) + (b?.reasoning ?? 0);
|
|
26
|
+
return output;
|
|
27
|
+
}
|
|
28
|
+
function mergeUsageMetadata(a, b) {
|
|
29
|
+
return {
|
|
30
|
+
input_tokens: (a?.input_tokens ?? 0) + (b?.input_tokens ?? 0),
|
|
31
|
+
output_tokens: (a?.output_tokens ?? 0) + (b?.output_tokens ?? 0),
|
|
32
|
+
total_tokens: (a?.total_tokens ?? 0) + (b?.total_tokens ?? 0),
|
|
33
|
+
input_token_details: mergeInputTokenDetails(a?.input_token_details, b?.input_token_details),
|
|
34
|
+
output_token_details: mergeOutputTokenDetails(a?.output_token_details, b?.output_token_details)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { mergeResponseMetadata, mergeUsageMetadata };
|
|
40
|
+
//# sourceMappingURL=metadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata.js","names":["a?: ResponseMetadata","b?: ResponseMetadata","output: ResponseMetadata","a?: ModalitiesTokenDetails","b?: ModalitiesTokenDetails","output: ModalitiesTokenDetails","a?: InputTokenDetails","b?: InputTokenDetails","output: InputTokenDetails","a?: OutputTokenDetails","b?: OutputTokenDetails","output: OutputTokenDetails","a?: UsageMetadata","b?: UsageMetadata"],"sources":["../../src/messages/metadata.ts"],"sourcesContent":["import { _mergeDicts } from \"./base.js\";\n\nexport type ResponseMetadata = {\n model_provider?: string;\n model_name?: string;\n [key: string]: unknown;\n};\n\nexport function mergeResponseMetadata(\n a?: ResponseMetadata,\n b?: ResponseMetadata\n): ResponseMetadata {\n const output: ResponseMetadata = _mergeDicts(a ?? {}, b ?? {});\n return output;\n}\n\nexport type ModalitiesTokenDetails = {\n /**\n * Text tokens.\n * Does not need to be reported, but some models will do so.\n */\n text?: number;\n\n /**\n * Image (non-video) tokens.\n */\n image?: number;\n\n /**\n * Audio tokens.\n */\n audio?: number;\n\n /**\n * Video tokens.\n */\n video?: number;\n\n /**\n * Document tokens.\n * e.g. PDF\n */\n document?: number;\n};\n\nfunction mergeModalitiesTokenDetails(\n a?: ModalitiesTokenDetails,\n b?: ModalitiesTokenDetails\n): ModalitiesTokenDetails {\n const output: ModalitiesTokenDetails = {};\n if (a?.audio !== undefined || b?.audio !== undefined) {\n output.audio = (a?.audio ?? 0) + (b?.audio ?? 0);\n }\n if (a?.image !== undefined || b?.image !== undefined) {\n output.image = (a?.image ?? 0) + (b?.image ?? 0);\n }\n if (a?.video !== undefined || b?.video !== undefined) {\n output.video = (a?.video ?? 0) + (b?.video ?? 0);\n }\n if (a?.document !== undefined || b?.document !== undefined) {\n output.document = (a?.document ?? 0) + (b?.document ?? 0);\n }\n if (a?.text !== undefined || b?.text !== undefined) {\n output.text = (a?.text ?? 0) + (b?.text ?? 0);\n }\n return output;\n}\n\n/**\n * Breakdown of input token counts.\n *\n * Does not *need* to sum to full input token count. Does *not* need to have all keys.\n */\nexport type InputTokenDetails = ModalitiesTokenDetails & {\n /**\n * Input tokens that were cached and there was a cache hit.\n *\n * Since there was a cache hit, the tokens were read from the cache.\n * More precisely, the model state given these tokens was read from the cache.\n */\n cache_read?: number;\n\n /**\n * Input tokens that were cached and there was a cache miss.\n *\n * Since there was a cache miss, the cache was created from these tokens.\n */\n cache_creation?: number;\n};\n\nfunction mergeInputTokenDetails(\n a?: InputTokenDetails,\n b?: InputTokenDetails\n): InputTokenDetails {\n const output: InputTokenDetails = {\n ...mergeModalitiesTokenDetails(a, b),\n };\n if (a?.cache_read !== undefined || b?.cache_read !== undefined) {\n output.cache_read = (a?.cache_read ?? 0) + (b?.cache_read ?? 0);\n }\n if (a?.cache_creation !== undefined || b?.cache_creation !== undefined) {\n output.cache_creation = (a?.cache_creation ?? 0) + (b?.cache_creation ?? 0);\n }\n return output;\n}\n\n/**\n * Breakdown of output token counts.\n *\n * Does *not* need to sum to full output token count. Does *not* need to have all keys.\n */\nexport type OutputTokenDetails = ModalitiesTokenDetails & {\n /**\n * Reasoning output tokens.\n *\n * Tokens generated by the model in a chain of thought process (i.e. by\n * OpenAI's o1 models) that are not returned as part of model output.\n */\n reasoning?: number;\n};\n\nfunction mergeOutputTokenDetails(\n a?: OutputTokenDetails,\n b?: OutputTokenDetails\n): OutputTokenDetails {\n const output: OutputTokenDetails = {\n ...mergeModalitiesTokenDetails(a, b),\n };\n if (a?.reasoning !== undefined || b?.reasoning !== undefined) {\n output.reasoning = (a?.reasoning ?? 0) + (b?.reasoning ?? 0);\n }\n return output;\n}\n\n/**\n * Usage metadata for a message, such as token counts.\n */\nexport type UsageMetadata = {\n /**\n * Count of input (or prompt) tokens. Sum of all input token types.\n */\n input_tokens: number;\n /**\n * Count of output (or completion) tokens. Sum of all output token types.\n */\n output_tokens: number;\n /**\n * Total token count. Sum of input_tokens + output_tokens.\n */\n total_tokens: number;\n\n /**\n * Breakdown of input token counts.\n *\n * Does *not* need to sum to full input token count. Does *not* need to have all keys.\n */\n input_token_details?: InputTokenDetails;\n\n /**\n * Breakdown of output token counts.\n *\n * Does *not* need to sum to full output token count. Does *not* need to have all keys.\n */\n output_token_details?: OutputTokenDetails;\n};\n\nexport function mergeUsageMetadata(\n a?: UsageMetadata,\n b?: UsageMetadata\n): UsageMetadata {\n return {\n input_tokens: (a?.input_tokens ?? 0) + (b?.input_tokens ?? 0),\n output_tokens: (a?.output_tokens ?? 0) + (b?.output_tokens ?? 0),\n total_tokens: (a?.total_tokens ?? 0) + (b?.total_tokens ?? 0),\n input_token_details: mergeInputTokenDetails(\n a?.input_token_details,\n b?.input_token_details\n ),\n output_token_details: mergeOutputTokenDetails(\n a?.output_token_details,\n b?.output_token_details\n ),\n };\n}\n"],"mappings":";;;AAQA,SAAgB,sBACdA,GACAC,GACkB;CAClB,MAAMC,SAA2B,YAAY,KAAK,CAAE,GAAE,KAAK,CAAE,EAAC;AAC9D,QAAO;AACR;AA+BD,SAAS,4BACPC,GACAC,GACwB;CACxB,MAAMC,SAAiC,CAAE;AACzC,KAAI,GAAG,UAAU,UAAa,GAAG,UAAU,QACzC,OAAO,SAAS,GAAG,SAAS,MAAM,GAAG,SAAS;AAEhD,KAAI,GAAG,UAAU,UAAa,GAAG,UAAU,QACzC,OAAO,SAAS,GAAG,SAAS,MAAM,GAAG,SAAS;AAEhD,KAAI,GAAG,UAAU,UAAa,GAAG,UAAU,QACzC,OAAO,SAAS,GAAG,SAAS,MAAM,GAAG,SAAS;AAEhD,KAAI,GAAG,aAAa,UAAa,GAAG,aAAa,QAC/C,OAAO,YAAY,GAAG,YAAY,MAAM,GAAG,YAAY;AAEzD,KAAI,GAAG,SAAS,UAAa,GAAG,SAAS,QACvC,OAAO,QAAQ,GAAG,QAAQ,MAAM,GAAG,QAAQ;AAE7C,QAAO;AACR;AAwBD,SAAS,uBACPC,GACAC,GACmB;CACnB,MAAMC,SAA4B,EAChC,GAAG,4BAA4B,GAAG,EAAE,CACrC;AACD,KAAI,GAAG,eAAe,UAAa,GAAG,eAAe,QACnD,OAAO,cAAc,GAAG,cAAc,MAAM,GAAG,cAAc;AAE/D,KAAI,GAAG,mBAAmB,UAAa,GAAG,mBAAmB,QAC3D,OAAO,kBAAkB,GAAG,kBAAkB,MAAM,GAAG,kBAAkB;AAE3E,QAAO;AACR;AAiBD,SAAS,wBACPC,GACAC,GACoB;CACpB,MAAMC,SAA6B,EACjC,GAAG,4BAA4B,GAAG,EAAE,CACrC;AACD,KAAI,GAAG,cAAc,UAAa,GAAG,cAAc,QACjD,OAAO,aAAa,GAAG,aAAa,MAAM,GAAG,aAAa;AAE5D,QAAO;AACR;AAkCD,SAAgB,mBACdC,GACAC,GACe;AACf,QAAO;EACL,eAAe,GAAG,gBAAgB,MAAM,GAAG,gBAAgB;EAC3D,gBAAgB,GAAG,iBAAiB,MAAM,GAAG,iBAAiB;EAC9D,eAAe,GAAG,gBAAgB,MAAM,GAAG,gBAAgB;EAC3D,qBAAqB,uBACnB,GAAG,qBACH,GAAG,oBACJ;EACD,sBAAsB,wBACpB,GAAG,sBACH,GAAG,qBACJ;CACF;AACF"}
|
|
@@ -5,26 +5,24 @@ const require_base = require('./base.cjs');
|
|
|
5
5
|
* Message responsible for deleting other messages.
|
|
6
6
|
*/
|
|
7
7
|
var RemoveMessage = class extends require_base.BaseMessage {
|
|
8
|
+
type = "remove";
|
|
8
9
|
/**
|
|
9
10
|
* The ID of the message to remove.
|
|
10
11
|
*/
|
|
11
12
|
id;
|
|
12
13
|
constructor(fields) {
|
|
13
|
-
super(
|
|
14
|
-
...fields,
|
|
15
|
-
content: ""
|
|
16
|
-
});
|
|
14
|
+
super(fields);
|
|
17
15
|
this.id = fields.id;
|
|
18
16
|
}
|
|
19
|
-
_getType() {
|
|
20
|
-
return "remove";
|
|
21
|
-
}
|
|
22
17
|
get _printableFields() {
|
|
23
18
|
return {
|
|
24
19
|
...super._printableFields,
|
|
25
20
|
id: this.id
|
|
26
21
|
};
|
|
27
22
|
}
|
|
23
|
+
static isInstance(obj) {
|
|
24
|
+
return super.isInstance(obj) && obj.type === "remove";
|
|
25
|
+
}
|
|
28
26
|
};
|
|
29
27
|
|
|
30
28
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modifier.cjs","names":["BaseMessage","fields: RemoveMessageFields"],"sources":["../../src/messages/modifier.ts"],"sourcesContent":["import { BaseMessage, BaseMessageFields
|
|
1
|
+
{"version":3,"file":"modifier.cjs","names":["BaseMessage","fields: RemoveMessageFields<TStructure>","obj: unknown"],"sources":["../../src/messages/modifier.ts"],"sourcesContent":["import { BaseMessage, BaseMessageFields } from \"./base.js\";\nimport { MessageStructure } from \"./message.js\";\n\nexport interface RemoveMessageFields<\n TStructure extends MessageStructure = MessageStructure\n> extends Omit<BaseMessageFields<TStructure, \"remove\">, \"content\"> {\n /**\n * The ID of the message to remove.\n */\n id: string;\n}\n\n/**\n * Message responsible for deleting other messages.\n */\nexport class RemoveMessage<\n TStructure extends MessageStructure = MessageStructure\n> extends BaseMessage<TStructure, \"remove\"> {\n readonly type = \"remove\" as const;\n\n /**\n * The ID of the message to remove.\n */\n id: string;\n\n constructor(fields: RemoveMessageFields<TStructure>) {\n super(fields);\n this.id = fields.id;\n }\n\n override get _printableFields(): Record<string, unknown> {\n return {\n ...super._printableFields,\n id: this.id,\n };\n }\n\n static isInstance(obj: unknown): obj is RemoveMessage {\n return super.isInstance(obj) && obj.type === \"remove\";\n }\n}\n"],"mappings":";;;;;;AAeA,IAAa,gBAAb,cAEUA,yBAAkC;CAC1C,AAAS,OAAO;;;;CAKhB;CAEA,YAAYC,QAAyC;EACnD,MAAM,OAAO;EACb,KAAK,KAAK,OAAO;CAClB;CAED,IAAa,mBAA4C;AACvD,SAAO;GACL,GAAG,MAAM;GACT,IAAI,KAAK;EACV;CACF;CAED,OAAO,WAAWC,KAAoC;AACpD,SAAO,MAAM,WAAW,IAAI,IAAI,IAAI,SAAS;CAC9C;AACF"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { BaseMessage, BaseMessageFields
|
|
1
|
+
import { BaseMessage, BaseMessageFields } from "./base.cjs";
|
|
2
|
+
import { MessageStructure } from "./message.cjs";
|
|
2
3
|
|
|
3
4
|
//#region src/messages/modifier.d.ts
|
|
4
|
-
interface RemoveMessageFields extends Omit<BaseMessageFields, "content"> {
|
|
5
|
+
interface RemoveMessageFields<TStructure extends MessageStructure = MessageStructure> extends Omit<BaseMessageFields<TStructure, "remove">, "content"> {
|
|
5
6
|
/**
|
|
6
7
|
* The ID of the message to remove.
|
|
7
8
|
*/
|
|
@@ -10,14 +11,15 @@ interface RemoveMessageFields extends Omit<BaseMessageFields, "content"> {
|
|
|
10
11
|
/**
|
|
11
12
|
* Message responsible for deleting other messages.
|
|
12
13
|
*/
|
|
13
|
-
declare class RemoveMessage extends BaseMessage {
|
|
14
|
+
declare class RemoveMessage<TStructure extends MessageStructure = MessageStructure> extends BaseMessage<TStructure, "remove"> {
|
|
15
|
+
readonly type: "remove";
|
|
14
16
|
/**
|
|
15
17
|
* The ID of the message to remove.
|
|
16
18
|
*/
|
|
17
19
|
id: string;
|
|
18
|
-
constructor(fields: RemoveMessageFields);
|
|
19
|
-
_getType(): MessageType;
|
|
20
|
+
constructor(fields: RemoveMessageFields<TStructure>);
|
|
20
21
|
get _printableFields(): Record<string, unknown>;
|
|
22
|
+
static isInstance(obj: unknown): obj is RemoveMessage;
|
|
21
23
|
}
|
|
22
24
|
//#endregion
|
|
23
25
|
export { RemoveMessage, RemoveMessageFields };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modifier.d.cts","names":["BaseMessage","BaseMessageFields","
|
|
1
|
+
{"version":3,"file":"modifier.d.cts","names":["BaseMessage","BaseMessageFields","MessageStructure","RemoveMessageFields","TStructure","Omit","RemoveMessage","Record"],"sources":["../../src/messages/modifier.d.ts"],"sourcesContent":["import { BaseMessage, BaseMessageFields } from \"./base.js\";\nimport { MessageStructure } from \"./message.js\";\nexport interface RemoveMessageFields<TStructure extends MessageStructure = MessageStructure> extends Omit<BaseMessageFields<TStructure, \"remove\">, \"content\"> {\n /**\n * The ID of the message to remove.\n */\n id: string;\n}\n/**\n * Message responsible for deleting other messages.\n */\nexport declare class RemoveMessage<TStructure extends MessageStructure = MessageStructure> extends BaseMessage<TStructure, \"remove\"> {\n readonly type: \"remove\";\n /**\n * The ID of the message to remove.\n */\n id: string;\n constructor(fields: RemoveMessageFields<TStructure>);\n get _printableFields(): Record<string, unknown>;\n static isInstance(obj: unknown): obj is RemoveMessage;\n}\n"],"mappings":";;;;UAEiBG,uCAAuCD,mBAAmBA,0BAA0BG,KAAKJ,kBAAkBG;;AAA5H;;EAAoC,EAAA,EAAoBF,MAAAA;;;;;AAAiD,cASpFI,aAToF,CAAA,mBASnDJ,gBATmD,GAShCA,gBATgC,CAAA,SASNF,WATM,CASMI,UATN,EAAA,QAAA,CAAA,CAAA;EASpFE,SAAAA,IAAAA,EAAAA,QAAa;EAAA;;;EAAuD,EAAA,EAAsBF,MAAAA;EAAU,WAM7EA,CAAAA,MAAAA,EAApBD,mBAAoBC,CAAAA,UAAAA,CAAAA;EAAU,IAA9BD,gBAAAA,CAAAA,CAAAA,EACII,MADJJ,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;EAAmB,OACfI,UAAAA,CAAAA,GAAAA,EAAAA,OAAAA,CAAAA,EAAAA,GAAAA,IACgBD,aADhBC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { BaseMessage, BaseMessageFields
|
|
1
|
+
import { BaseMessage, BaseMessageFields } from "./base.js";
|
|
2
|
+
import { MessageStructure } from "./message.js";
|
|
2
3
|
|
|
3
4
|
//#region src/messages/modifier.d.ts
|
|
4
|
-
interface RemoveMessageFields extends Omit<BaseMessageFields, "content"> {
|
|
5
|
+
interface RemoveMessageFields<TStructure extends MessageStructure = MessageStructure> extends Omit<BaseMessageFields<TStructure, "remove">, "content"> {
|
|
5
6
|
/**
|
|
6
7
|
* The ID of the message to remove.
|
|
7
8
|
*/
|
|
@@ -10,14 +11,15 @@ interface RemoveMessageFields extends Omit<BaseMessageFields, "content"> {
|
|
|
10
11
|
/**
|
|
11
12
|
* Message responsible for deleting other messages.
|
|
12
13
|
*/
|
|
13
|
-
declare class RemoveMessage extends BaseMessage {
|
|
14
|
+
declare class RemoveMessage<TStructure extends MessageStructure = MessageStructure> extends BaseMessage<TStructure, "remove"> {
|
|
15
|
+
readonly type: "remove";
|
|
14
16
|
/**
|
|
15
17
|
* The ID of the message to remove.
|
|
16
18
|
*/
|
|
17
19
|
id: string;
|
|
18
|
-
constructor(fields: RemoveMessageFields);
|
|
19
|
-
_getType(): MessageType;
|
|
20
|
+
constructor(fields: RemoveMessageFields<TStructure>);
|
|
20
21
|
get _printableFields(): Record<string, unknown>;
|
|
22
|
+
static isInstance(obj: unknown): obj is RemoveMessage;
|
|
21
23
|
}
|
|
22
24
|
//#endregion
|
|
23
25
|
export { RemoveMessage, RemoveMessageFields };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modifier.d.ts","names":["BaseMessage","BaseMessageFields","
|
|
1
|
+
{"version":3,"file":"modifier.d.ts","names":["BaseMessage","BaseMessageFields","MessageStructure","RemoveMessageFields","TStructure","Omit","RemoveMessage","Record"],"sources":["../../src/messages/modifier.d.ts"],"sourcesContent":["import { BaseMessage, BaseMessageFields } from \"./base.js\";\nimport { MessageStructure } from \"./message.js\";\nexport interface RemoveMessageFields<TStructure extends MessageStructure = MessageStructure> extends Omit<BaseMessageFields<TStructure, \"remove\">, \"content\"> {\n /**\n * The ID of the message to remove.\n */\n id: string;\n}\n/**\n * Message responsible for deleting other messages.\n */\nexport declare class RemoveMessage<TStructure extends MessageStructure = MessageStructure> extends BaseMessage<TStructure, \"remove\"> {\n readonly type: \"remove\";\n /**\n * The ID of the message to remove.\n */\n id: string;\n constructor(fields: RemoveMessageFields<TStructure>);\n get _printableFields(): Record<string, unknown>;\n static isInstance(obj: unknown): obj is RemoveMessage;\n}\n"],"mappings":";;;;UAEiBG,uCAAuCD,mBAAmBA,0BAA0BG,KAAKJ,kBAAkBG;;AAA5H;;EAAoC,EAAA,EAAoBF,MAAAA;;;;;AAAiD,cASpFI,aAToF,CAAA,mBASnDJ,gBATmD,GAShCA,gBATgC,CAAA,SASNF,WATM,CASMI,UATN,EAAA,QAAA,CAAA,CAAA;EASpFE,SAAAA,IAAAA,EAAAA,QAAa;EAAA;;;EAAuD,EAAA,EAAsBF,MAAAA;EAAU,WAM7EA,CAAAA,MAAAA,EAApBD,mBAAoBC,CAAAA,UAAAA,CAAAA;EAAU,IAA9BD,gBAAAA,CAAAA,CAAAA,EACII,MADJJ,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;EAAmB,OACfI,UAAAA,CAAAA,GAAAA,EAAAA,OAAAA,CAAAA,EAAAA,GAAAA,IACgBD,aADhBC"}
|
|
@@ -5,26 +5,24 @@ import { BaseMessage } from "./base.js";
|
|
|
5
5
|
* Message responsible for deleting other messages.
|
|
6
6
|
*/
|
|
7
7
|
var RemoveMessage = class extends BaseMessage {
|
|
8
|
+
type = "remove";
|
|
8
9
|
/**
|
|
9
10
|
* The ID of the message to remove.
|
|
10
11
|
*/
|
|
11
12
|
id;
|
|
12
13
|
constructor(fields) {
|
|
13
|
-
super(
|
|
14
|
-
...fields,
|
|
15
|
-
content: ""
|
|
16
|
-
});
|
|
14
|
+
super(fields);
|
|
17
15
|
this.id = fields.id;
|
|
18
16
|
}
|
|
19
|
-
_getType() {
|
|
20
|
-
return "remove";
|
|
21
|
-
}
|
|
22
17
|
get _printableFields() {
|
|
23
18
|
return {
|
|
24
19
|
...super._printableFields,
|
|
25
20
|
id: this.id
|
|
26
21
|
};
|
|
27
22
|
}
|
|
23
|
+
static isInstance(obj) {
|
|
24
|
+
return super.isInstance(obj) && obj.type === "remove";
|
|
25
|
+
}
|
|
28
26
|
};
|
|
29
27
|
|
|
30
28
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modifier.js","names":["fields: RemoveMessageFields"],"sources":["../../src/messages/modifier.ts"],"sourcesContent":["import { BaseMessage, BaseMessageFields
|
|
1
|
+
{"version":3,"file":"modifier.js","names":["fields: RemoveMessageFields<TStructure>","obj: unknown"],"sources":["../../src/messages/modifier.ts"],"sourcesContent":["import { BaseMessage, BaseMessageFields } from \"./base.js\";\nimport { MessageStructure } from \"./message.js\";\n\nexport interface RemoveMessageFields<\n TStructure extends MessageStructure = MessageStructure\n> extends Omit<BaseMessageFields<TStructure, \"remove\">, \"content\"> {\n /**\n * The ID of the message to remove.\n */\n id: string;\n}\n\n/**\n * Message responsible for deleting other messages.\n */\nexport class RemoveMessage<\n TStructure extends MessageStructure = MessageStructure\n> extends BaseMessage<TStructure, \"remove\"> {\n readonly type = \"remove\" as const;\n\n /**\n * The ID of the message to remove.\n */\n id: string;\n\n constructor(fields: RemoveMessageFields<TStructure>) {\n super(fields);\n this.id = fields.id;\n }\n\n override get _printableFields(): Record<string, unknown> {\n return {\n ...super._printableFields,\n id: this.id,\n };\n }\n\n static isInstance(obj: unknown): obj is RemoveMessage {\n return super.isInstance(obj) && obj.type === \"remove\";\n }\n}\n"],"mappings":";;;;;;AAeA,IAAa,gBAAb,cAEU,YAAkC;CAC1C,AAAS,OAAO;;;;CAKhB;CAEA,YAAYA,QAAyC;EACnD,MAAM,OAAO;EACb,KAAK,KAAK,OAAO;CAClB;CAED,IAAa,mBAA4C;AACvD,SAAO;GACL,GAAG,MAAM;GACT,IAAI,KAAK;EACV;CACF;CAED,OAAO,WAAWC,KAAoC;AACpD,SAAO,MAAM,WAAW,IAAI,IAAI,IAAI,SAAS;CAC9C;AACF"}
|