@langchain/core 1.0.0-alpha.5 → 1.0.0-alpha.7
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/LICENSE +6 -6
- package/dist/agents.d.ts.map +1 -1
- package/dist/caches/base.d.ts.map +1 -1
- package/dist/callbacks/base.d.ts.map +1 -1
- package/dist/callbacks/manager.cjs +9 -64
- package/dist/callbacks/manager.cjs.map +1 -1
- package/dist/callbacks/manager.d.cts +1 -23
- package/dist/callbacks/manager.d.cts.map +1 -1
- package/dist/callbacks/manager.d.ts +1 -23
- package/dist/callbacks/manager.d.ts.map +1 -1
- package/dist/callbacks/manager.js +10 -63
- package/dist/callbacks/manager.js.map +1 -1
- package/dist/chat_history.cjs +0 -4
- package/dist/chat_history.cjs.map +1 -1
- package/dist/chat_history.d.cts +1 -3
- package/dist/chat_history.d.cts.map +1 -1
- package/dist/chat_history.d.ts +1 -3
- package/dist/chat_history.d.ts.map +1 -1
- package/dist/chat_history.js +0 -4
- package/dist/chat_history.js.map +1 -1
- package/dist/document_loaders/base.cjs +1 -13
- package/dist/document_loaders/base.cjs.map +1 -1
- package/dist/document_loaders/base.d.cts +0 -9
- package/dist/document_loaders/base.d.cts.map +1 -1
- package/dist/document_loaders/base.d.ts +0 -9
- package/dist/document_loaders/base.d.ts.map +1 -1
- package/dist/document_loaders/base.js +1 -13
- package/dist/document_loaders/base.js.map +1 -1
- package/dist/document_loaders/langsmith.d.cts +1 -1
- package/dist/language_models/base.cjs.map +1 -1
- package/dist/language_models/base.d.cts +0 -16
- package/dist/language_models/base.d.cts.map +1 -1
- package/dist/language_models/base.d.ts +0 -16
- package/dist/language_models/base.d.ts.map +1 -1
- package/dist/language_models/base.js.map +1 -1
- package/dist/language_models/chat_models.cjs +1 -80
- package/dist/language_models/chat_models.cjs.map +1 -1
- package/dist/language_models/chat_models.d.cts +1 -53
- package/dist/language_models/chat_models.d.cts.map +1 -1
- package/dist/language_models/chat_models.d.ts +1 -53
- package/dist/language_models/chat_models.d.ts.map +1 -1
- package/dist/language_models/chat_models.js +2 -80
- package/dist/language_models/chat_models.js.map +1 -1
- package/dist/language_models/llms.cjs +0 -56
- package/dist/language_models/llms.cjs.map +1 -1
- package/dist/language_models/llms.d.cts +1 -43
- package/dist/language_models/llms.d.cts.map +1 -1
- package/dist/language_models/llms.d.ts +1 -43
- package/dist/language_models/llms.d.ts.map +1 -1
- package/dist/language_models/llms.js +0 -56
- package/dist/language_models/llms.js.map +1 -1
- package/dist/load/import_map.cjs +1 -7
- package/dist/load/import_map.cjs.map +1 -1
- package/dist/load/import_map.js +1 -7
- package/dist/load/import_map.js.map +1 -1
- package/dist/messages/ai.cjs +8 -4
- package/dist/messages/ai.cjs.map +1 -1
- package/dist/messages/ai.js +8 -4
- package/dist/messages/ai.js.map +1 -1
- package/dist/messages/base.cjs +1 -1
- package/dist/messages/base.cjs.map +1 -1
- package/dist/messages/base.d.cts +2 -2
- package/dist/messages/base.d.cts.map +1 -1
- package/dist/messages/base.d.ts +2 -2
- package/dist/messages/base.d.ts.map +1 -1
- package/dist/messages/base.js +1 -1
- package/dist/messages/base.js.map +1 -1
- package/dist/messages/block_translators/anthropic.cjs +191 -144
- package/dist/messages/block_translators/anthropic.cjs.map +1 -1
- package/dist/messages/block_translators/anthropic.js +191 -144
- package/dist/messages/block_translators/anthropic.js.map +1 -1
- package/dist/messages/block_translators/bedrock_converse.cjs +213 -0
- package/dist/messages/block_translators/bedrock_converse.cjs.map +1 -0
- package/dist/messages/block_translators/bedrock_converse.js +213 -0
- package/dist/messages/block_translators/bedrock_converse.js.map +1 -0
- package/dist/messages/block_translators/google_genai.cjs +73 -0
- package/dist/messages/block_translators/google_genai.cjs.map +1 -0
- package/dist/messages/block_translators/google_genai.js +73 -0
- package/dist/messages/block_translators/google_genai.js.map +1 -0
- package/dist/messages/block_translators/google_vertexai.cjs +74 -0
- package/dist/messages/block_translators/google_vertexai.cjs.map +1 -0
- package/dist/messages/block_translators/google_vertexai.js +74 -0
- package/dist/messages/block_translators/google_vertexai.js.map +1 -0
- package/dist/messages/block_translators/index.cjs +10 -1
- package/dist/messages/block_translators/index.cjs.map +1 -1
- package/dist/messages/block_translators/index.js +12 -3
- package/dist/messages/block_translators/index.js.map +1 -1
- package/dist/messages/block_translators/openai.cjs +78 -22
- package/dist/messages/block_translators/openai.cjs.map +1 -1
- package/dist/messages/block_translators/openai.js +78 -22
- package/dist/messages/block_translators/openai.js.map +1 -1
- package/dist/messages/block_translators/utils.cjs +4 -0
- package/dist/messages/block_translators/utils.cjs.map +1 -1
- package/dist/messages/block_translators/utils.js +4 -1
- package/dist/messages/block_translators/utils.js.map +1 -1
- package/dist/messages/content/index.cjs.map +1 -1
- package/dist/messages/content/index.d.cts +20 -1
- package/dist/messages/content/index.d.cts.map +1 -1
- package/dist/messages/content/index.d.ts +20 -1
- package/dist/messages/content/index.d.ts.map +1 -1
- package/dist/messages/content/index.js.map +1 -1
- package/dist/messages/content/tools.cjs +3 -4
- package/dist/messages/content/tools.cjs.map +1 -1
- package/dist/messages/content/tools.d.cts +22 -45
- package/dist/messages/content/tools.d.cts.map +1 -1
- package/dist/messages/content/tools.d.ts +22 -45
- package/dist/messages/content/tools.d.ts.map +1 -1
- package/dist/messages/content/tools.js +3 -4
- package/dist/messages/content/tools.js.map +1 -1
- package/dist/messages/index.cjs +4 -0
- package/dist/messages/index.cjs.map +1 -1
- package/dist/messages/index.d.cts +2 -2
- package/dist/messages/index.d.ts +2 -2
- package/dist/messages/index.js +4 -2
- package/dist/messages/index.js.map +1 -1
- package/dist/messages/message.cjs.map +1 -1
- package/dist/messages/message.d.cts +6 -6
- package/dist/messages/message.d.cts.map +1 -1
- package/dist/messages/message.d.ts +6 -6
- package/dist/messages/message.d.ts.map +1 -1
- package/dist/messages/message.js.map +1 -1
- package/dist/messages/metadata.cjs.map +1 -1
- package/dist/messages/metadata.d.cts +3 -0
- package/dist/messages/metadata.d.cts.map +1 -1
- package/dist/messages/metadata.d.ts +3 -0
- package/dist/messages/metadata.d.ts.map +1 -1
- package/dist/messages/metadata.js.map +1 -1
- package/dist/messages/tool.cjs +2 -0
- package/dist/messages/tool.cjs.map +1 -1
- package/dist/messages/tool.d.cts +5 -1
- package/dist/messages/tool.d.cts.map +1 -1
- package/dist/messages/tool.d.ts +5 -1
- package/dist/messages/tool.d.ts.map +1 -1
- package/dist/messages/tool.js +2 -0
- package/dist/messages/tool.js.map +1 -1
- package/dist/output_parsers/json.cjs +5 -0
- package/dist/output_parsers/json.cjs.map +1 -1
- package/dist/output_parsers/json.d.cts +2 -0
- package/dist/output_parsers/json.d.cts.map +1 -1
- package/dist/output_parsers/json.d.ts +2 -0
- package/dist/output_parsers/json.d.ts.map +1 -1
- package/dist/output_parsers/json.js +5 -0
- package/dist/output_parsers/json.js.map +1 -1
- package/dist/prompts/base.cjs +0 -36
- package/dist/prompts/base.cjs.map +1 -1
- package/dist/prompts/base.d.cts +0 -16
- package/dist/prompts/base.d.cts.map +1 -1
- package/dist/prompts/base.d.ts +0 -16
- package/dist/prompts/base.d.ts.map +1 -1
- package/dist/prompts/base.js +0 -36
- package/dist/prompts/base.js.map +1 -1
- package/dist/prompts/chat.cjs +1 -5
- package/dist/prompts/chat.cjs.map +1 -1
- package/dist/prompts/chat.d.cts +1 -4
- package/dist/prompts/chat.d.cts.map +1 -1
- package/dist/prompts/chat.d.ts +1 -4
- package/dist/prompts/chat.d.ts.map +1 -1
- package/dist/prompts/chat.js +1 -5
- package/dist/prompts/chat.js.map +1 -1
- package/dist/prompts/dict.d.cts +1 -1
- package/dist/prompts/dict.d.ts +1 -1
- package/dist/prompts/few_shot.d.cts +2 -2
- package/dist/prompts/few_shot.d.ts +2 -2
- package/dist/prompts/image.d.cts +1 -1
- package/dist/prompts/image.d.ts +1 -1
- package/dist/prompts/index.d.cts +2 -2
- package/dist/prompts/index.d.ts +2 -2
- package/dist/prompts/pipeline.d.cts +1 -1
- package/dist/prompts/pipeline.d.ts +1 -1
- package/dist/prompts/prompt.d.cts +2 -2
- package/dist/prompts/prompt.d.ts +2 -2
- package/dist/retrievers/index.cjs +3 -18
- package/dist/retrievers/index.cjs.map +1 -1
- package/dist/retrievers/index.d.cts +2 -27
- package/dist/retrievers/index.d.cts.map +1 -1
- package/dist/retrievers/index.d.ts +2 -27
- package/dist/retrievers/index.d.ts.map +1 -1
- package/dist/retrievers/index.js +3 -18
- package/dist/retrievers/index.js.map +1 -1
- package/dist/runnables/base.cjs +24 -63
- package/dist/runnables/base.cjs.map +1 -1
- package/dist/runnables/base.d.cts +10 -39
- package/dist/runnables/base.d.cts.map +1 -1
- package/dist/runnables/base.d.ts +10 -39
- package/dist/runnables/base.d.ts.map +1 -1
- package/dist/runnables/base.js +24 -63
- package/dist/runnables/base.js.map +1 -1
- package/dist/runnables/graph.cjs +1 -1
- package/dist/runnables/graph.cjs.map +1 -1
- package/dist/runnables/graph.js +2 -2
- package/dist/runnables/graph.js.map +1 -1
- package/dist/runnables/graph_mermaid.cjs +1 -10
- package/dist/runnables/graph_mermaid.cjs.map +1 -1
- package/dist/runnables/graph_mermaid.js +1 -10
- package/dist/runnables/graph_mermaid.js.map +1 -1
- package/dist/runnables/history.cjs +1 -1
- package/dist/runnables/history.cjs.map +1 -1
- package/dist/runnables/history.d.cts +2 -2
- package/dist/runnables/history.d.cts.map +1 -1
- package/dist/runnables/history.d.ts +2 -2
- package/dist/runnables/history.d.ts.map +1 -1
- package/dist/runnables/history.js +1 -1
- package/dist/runnables/history.js.map +1 -1
- package/dist/stores.cjs.map +1 -1
- package/dist/stores.d.cts +3 -29
- package/dist/stores.d.cts.map +1 -1
- package/dist/stores.d.ts +3 -29
- package/dist/stores.d.ts.map +1 -1
- package/dist/stores.js.map +1 -1
- package/dist/tools/index.cjs +12 -4
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.js +12 -4
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/types.cjs.map +1 -1
- package/dist/tools/types.d.cts +4 -0
- package/dist/tools/types.d.cts.map +1 -1
- package/dist/tools/types.d.ts +4 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js.map +1 -1
- package/dist/tracers/base.cjs +1 -1
- package/dist/tracers/base.cjs.map +1 -1
- package/dist/tracers/base.d.cts +1 -1
- package/dist/tracers/base.js +2 -2
- package/dist/tracers/base.js.map +1 -1
- package/dist/tracers/log_stream.d.cts +1 -1
- package/dist/tracers/log_stream.d.ts +1 -1
- package/dist/tracers/tracer_langchain.cjs +1 -0
- package/dist/tracers/tracer_langchain.cjs.map +1 -1
- package/dist/tracers/tracer_langchain.d.cts +2 -2
- package/dist/tracers/tracer_langchain.js +1 -0
- package/dist/tracers/tracer_langchain.js.map +1 -1
- package/dist/utils/env.cjs +1 -9
- package/dist/utils/env.cjs.map +1 -1
- package/dist/utils/env.d.cts +2 -6
- package/dist/utils/env.d.cts.map +1 -1
- package/dist/utils/env.d.ts +2 -6
- package/dist/utils/env.d.ts.map +1 -1
- package/dist/utils/env.js +2 -9
- package/dist/utils/env.js.map +1 -1
- package/dist/utils/testing/message_history.cjs +1 -1
- package/dist/utils/testing/message_history.cjs.map +1 -1
- package/dist/utils/testing/message_history.d.cts +1 -1
- package/dist/utils/testing/message_history.d.cts.map +1 -1
- package/dist/utils/testing/message_history.d.ts +1 -1
- package/dist/utils/testing/message_history.d.ts.map +1 -1
- package/dist/utils/testing/message_history.js +1 -1
- package/dist/utils/testing/message_history.js.map +1 -1
- package/dist/utils/types/index.cjs +8 -0
- package/dist/utils/types/index.d.cts +2 -2
- package/dist/utils/types/index.d.ts +2 -2
- package/dist/utils/types/index.js +6 -2
- package/dist/utils/types/zod.cjs +62 -3
- package/dist/utils/types/zod.cjs.map +1 -1
- package/dist/utils/types/zod.d.cts +28 -1
- package/dist/utils/types/zod.d.cts.map +1 -1
- package/dist/utils/types/zod.d.ts +28 -1
- package/dist/utils/types/zod.d.ts.map +1 -1
- package/dist/utils/types/zod.js +59 -4
- package/dist/utils/types/zod.js.map +1 -1
- package/package.json +1 -37
- package/dist/runnables/remote.cjs +0 -399
- package/dist/runnables/remote.cjs.map +0 -1
- package/dist/runnables/remote.d.cts +0 -73
- package/dist/runnables/remote.d.cts.map +0 -1
- package/dist/runnables/remote.d.ts +0 -73
- package/dist/runnables/remote.d.ts.map +0 -1
- package/dist/runnables/remote.js +0 -393
- package/dist/runnables/remote.js.map +0 -1
- package/dist/tracers/initialize.cjs +0 -46
- package/dist/tracers/initialize.cjs.map +0 -1
- package/dist/tracers/initialize.d.cts +0 -26
- package/dist/tracers/initialize.d.cts.map +0 -1
- package/dist/tracers/initialize.d.ts +0 -26
- package/dist/tracers/initialize.d.ts.map +0 -1
- package/dist/tracers/initialize.js +0 -39
- package/dist/tracers/initialize.js.map +0 -1
- package/dist/tracers/tracer_langchain_v1.cjs +0 -168
- package/dist/tracers/tracer_langchain_v1.cjs.map +0 -1
- package/dist/tracers/tracer_langchain_v1.d.cts +0 -64
- package/dist/tracers/tracer_langchain_v1.d.cts.map +0 -1
- package/dist/tracers/tracer_langchain_v1.d.ts +0 -64
- package/dist/tracers/tracer_langchain_v1.d.ts.map +0 -1
- package/dist/tracers/tracer_langchain_v1.js +0 -162
- package/dist/tracers/tracer_langchain_v1.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.js","names":["message: AIMessage","blocks: Array<ContentBlock.Standard>","blocks: Array<ContentBlock>","convertedBlocks: Array<ContentBlock.Standard>","annotation: ContentBlock","message: AIMessageChunk","openaiTranslator: StandardContentBlockTranslator"],"sources":["../../../src/messages/block_translators/openai.ts"],"sourcesContent":["import type { ContentBlock } from \"../content/index.js\";\nimport type { AIMessageChunk, AIMessage } from \"../ai.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { convertToV1FromOpenAIDataBlock, isOpenAIDataBlock } from \"./data.js\";\nimport {\n _isArray,\n _isContentBlock,\n _isObject,\n _isString,\n iife,\n} from \"./utils.js\";\n\n/**\n * Converts a ChatOpenAICompletions message to an array of v1 standard content blocks.\n *\n * This function processes an AI message from ChatOpenAICompletions API format\n * and converts it to the standardized v1 content block format. It handles both\n * string content and structured content blocks, as well as tool calls.\n *\n * @param message - The AI message containing ChatOpenAICompletions formatted content\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const message = new AIMessage(\"Hello world\");\n * const standardBlocks = convertToV1FromChatCompletions(message);\n * // Returns: [{ type: \"text\", text: \"Hello world\" }]\n * ```\n *\n * @example\n * ```typescript\n * const message = new AIMessage([\n * { type: \"text\", text: \"Hello\" },\n * { type: \"image_url\", image_url: { url: \"https://example.com/image.png\" } }\n * ]);\n * message.tool_calls = [\n * { id: \"call_123\", name: \"calculator\", args: { a: 1, b: 2 } }\n * ];\n *\n * const standardBlocks = convertToV1FromChatCompletions(message);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Hello\" },\n * // { type: \"image\", url: \"https://example.com/image.png\" },\n * // { type: \"tool_call\", id: \"call_123\", name: \"calculator\", args: { a: 1, b: 2 } }\n * // ]\n * ```\n */\nexport function convertToV1FromChatCompletions(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n const blocks: Array<ContentBlock.Standard> = [];\n if (typeof message.content === \"string\") {\n blocks.push({\n type: \"text\",\n text: message.content,\n });\n } else {\n blocks.push(...convertToV1FromChatCompletionsInput(message.content));\n }\n for (const toolCall of message.tool_calls ?? []) {\n blocks.push({\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n });\n }\n return blocks;\n}\n\n/**\n * Converts a ChatOpenAICompletions message chunk to an array of v1 standard content blocks.\n *\n * This function processes an AI message chunk from OpenAI's chat completions API and converts\n * it to the standardized v1 content block format. It handles both string and array content,\n * as well as tool calls that may be present in the chunk.\n *\n * @param message - The AI message chunk containing OpenAI-formatted content blocks\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const chunk = new AIMessage(\"Hello\");\n * const standardBlocks = convertToV1FromChatCompletionsChunk(chunk);\n * // Returns: [{ type: \"text\", text: \"Hello\" }]\n * ```\n *\n * @example\n * ```typescript\n * const chunk = new AIMessage([\n * { type: \"text\", text: \"Processing...\" }\n * ]);\n * chunk.tool_calls = [\n * { id: \"call_456\", name: \"search\", args: { query: \"test\" } }\n * ];\n *\n * const standardBlocks = convertToV1FromChatCompletionsChunk(chunk);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Processing...\" },\n * // { type: \"tool_call\", id: \"call_456\", name: \"search\", args: { query: \"test\" } }\n * // ]\n * ```\n */\nexport function convertToV1FromChatCompletionsChunk(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n const blocks: Array<ContentBlock.Standard> = [];\n if (typeof message.content === \"string\") {\n blocks.push({\n type: \"text\",\n text: message.content,\n });\n } else {\n blocks.push(...convertToV1FromChatCompletionsInput(message.content));\n }\n\n // TODO: parse chunk position information\n for (const toolCall of message.tool_calls ?? []) {\n blocks.push({\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n });\n }\n return blocks;\n}\n\n/**\n * Converts an array of ChatOpenAICompletions content blocks to v1 standard content blocks.\n *\n * This function processes content blocks from OpenAI's Chat Completions API format\n * and converts them to the standardized v1 content block format. It handles both\n * OpenAI-specific data blocks (which require conversion) and standard blocks\n * (which are passed through with type assertion).\n *\n * @param blocks - Array of content blocks in ChatOpenAICompletions format\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const openaiBlocks = [\n * { type: \"text\", text: \"Hello world\" },\n * { type: \"image_url\", image_url: { url: \"https://example.com/image.png\" } }\n * ];\n *\n * const standardBlocks = convertToV1FromChatCompletionsInput(openaiBlocks);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Hello world\" },\n * // { type: \"image\", url: \"https://example.com/image.png\" }\n * // ]\n * ```\n */\nexport function convertToV1FromChatCompletionsInput(\n blocks: Array<ContentBlock>\n): Array<ContentBlock.Standard> {\n const convertedBlocks: Array<ContentBlock.Standard> = [];\n for (const block of blocks) {\n if (isOpenAIDataBlock(block)) {\n convertedBlocks.push(convertToV1FromOpenAIDataBlock(block));\n } else {\n convertedBlocks.push(block as ContentBlock.Standard);\n }\n }\n return convertedBlocks;\n}\n\nfunction convertResponsesAnnotation(\n annotation: ContentBlock\n): ContentBlock | ContentBlock.Citation {\n if (annotation.type === \"url_citation\") {\n const { url, title, start_index, end_index } = annotation;\n return {\n type: \"citation\",\n url,\n title,\n startIndex: start_index,\n endIndex: end_index,\n };\n }\n if (annotation.type === \"file_citation\") {\n const { file_id, filename, index } = annotation;\n return {\n type: \"citation\",\n title: filename,\n startIndex: index,\n endIndex: index,\n fileId: file_id,\n };\n }\n return annotation;\n}\n\n/**\n * Converts a ChatOpenAIResponses message to an array of v1 standard content blocks.\n *\n * This function processes an AI message containing OpenAI Responses-specific content blocks\n * and converts them to the standardized v1 content block format. It handles reasoning summaries,\n * text content with annotations, tool calls, and various tool outputs including code interpreter,\n * web search, file search, computer calls, and MCP-related blocks.\n *\n * @param message - The AI message containing OpenAI Responses-formatted content blocks\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const message = new AIMessage({\n * content: [{ type: \"text\", text: \"Hello world\", annotations: [] }],\n * tool_calls: [{ id: \"123\", name: \"calculator\", args: { a: 1, b: 2 } }],\n * additional_kwargs: {\n * reasoning: { summary: [{ text: \"Let me calculate this...\" }] },\n * tool_outputs: [\n * {\n * type: \"code_interpreter_call\",\n * code: \"print('hello')\",\n * outputs: [{ type: \"logs\", logs: \"hello\" }]\n * }\n * ]\n * }\n * });\n *\n * const standardBlocks = convertToV1FromResponses(message);\n * // Returns:\n * // [\n * // { type: \"reasoning\", reasoning: \"Let me calculate this...\" },\n * // { type: \"text\", text: \"Hello world\", annotations: [] },\n * // { type: \"tool_call\", id: \"123\", name: \"calculator\", args: { a: 1, b: 2 } },\n * // { type: \"code_interpreter_call\", code: \"print('hello')\" },\n * // { type: \"code_interpreter_result\", output: [{ type: \"code_interpreter_output\", returnCode: 0, stdout: \"hello\" }] }\n * // ]\n * ```\n */\nexport function convertToV1FromResponses(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n if (\n _isObject(message.additional_kwargs?.reasoning) &&\n _isArray(message.additional_kwargs.reasoning.summary)\n ) {\n const summary =\n message.additional_kwargs.reasoning.summary.reduce<string>(\n (acc, item) => {\n if (_isObject(item) && _isString(item.text)) {\n return `${acc}${item.text}`;\n }\n return acc;\n },\n \"\"\n );\n yield {\n type: \"reasoning\",\n reasoning: summary,\n };\n }\n const content =\n typeof message.content === \"string\"\n ? [{ type: \"text\", text: message.content }]\n : message.content;\n for (const block of content) {\n if (_isContentBlock(block, \"text\")) {\n const { text, annotations, ...rest } = block;\n if (Array.isArray(annotations)) {\n yield {\n ...rest,\n type: \"text\",\n text: String(text),\n annotations: annotations.map(convertResponsesAnnotation),\n };\n } else {\n yield {\n ...rest,\n type: \"text\",\n text: String(text),\n };\n }\n }\n }\n for (const toolCall of message.tool_calls ?? []) {\n yield {\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n };\n }\n if (\n _isObject(message.additional_kwargs) &&\n _isArray(message.additional_kwargs.tool_outputs)\n ) {\n for (const toolOutput of message.additional_kwargs.tool_outputs) {\n if (_isContentBlock(toolOutput, \"web_search_call\")) {\n continue;\n } else if (_isContentBlock(toolOutput, \"file_search_call\")) {\n continue;\n } else if (_isContentBlock(toolOutput, \"computer_call\")) {\n continue;\n } else if (_isContentBlock(toolOutput, \"code_interpreter_call\")) {\n if (_isString(toolOutput.code)) {\n yield {\n type: \"code_interpreter_call\",\n code: toolOutput.code,\n };\n }\n if (_isArray(toolOutput.outputs)) {\n const returnCode = iife(() => {\n if (toolOutput.status === \"in_progress\") return undefined;\n if (toolOutput.status === \"completed\") return 0;\n if (toolOutput.status === \"incomplete\") return 127;\n if (toolOutput.status === \"interpreting\") return undefined;\n if (toolOutput.status === \"failed\") return 1;\n return undefined;\n });\n for (const output of toolOutput.outputs) {\n if (_isContentBlock(output, \"logs\")) {\n yield {\n type: \"code_interpreter_result\",\n output: [\n {\n type: \"code_interpreter_output\",\n returnCode,\n stderr: [0, undefined].includes(returnCode)\n ? undefined\n : String(output.logs),\n stdout: [0, undefined].includes(returnCode)\n ? String(output.logs)\n : undefined,\n },\n ],\n };\n }\n }\n }\n } else if (_isContentBlock(toolOutput, \"mcp_call\")) {\n continue;\n } else if (_isContentBlock(toolOutput, \"mcp_list_tools\")) {\n continue;\n } else if (_isContentBlock(toolOutput, \"mcp_approval_request\")) {\n continue;\n } else if (_isContentBlock(toolOutput, \"image_generation_call\")) {\n continue;\n }\n }\n }\n }\n return Array.from(iterateContent());\n}\n\n/**\n * Converts a ChatOpenAIResponses message chunk to an array of v1 standard content blocks.\n *\n * This function processes an AI message chunk containing OpenAI-specific content blocks\n * and converts them to the standardized v1 content block format. It handles both the\n * regular message content and tool call chunks that are specific to streaming responses.\n *\n * @param message - The AI message chunk containing OpenAI-formatted content blocks\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const messageChunk = new AIMessageChunk({\n * content: [{ type: \"text\", text: \"Hello\" }],\n * tool_call_chunks: [\n * { id: \"call_123\", name: \"calculator\", args: '{\"a\": 1' }\n * ]\n * });\n *\n * const standardBlocks = convertToV1FromResponsesChunk(messageChunk);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Hello\" },\n * // { type: \"tool_call_chunk\", id: \"call_123\", name: \"calculator\", args: '{\"a\": 1' }\n * // ]\n * ```\n */\nexport function convertToV1FromResponsesChunk(\n message: AIMessageChunk\n): Array<ContentBlock.Standard> {\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n yield* convertToV1FromResponses(message);\n for (const toolCallChunk of message.tool_call_chunks ?? []) {\n yield {\n type: \"tool_call_chunk\",\n id: toolCallChunk.id,\n name: toolCallChunk.name,\n args: toolCallChunk.args,\n };\n }\n }\n return Array.from(iterateContent());\n}\n\nexport const openaiTranslator: StandardContentBlockTranslator = {\n translateContent: (message) => {\n if (typeof message.content === \"string\") {\n return convertToV1FromChatCompletions(message);\n }\n return convertToV1FromResponses(message);\n },\n translateContentChunk: (message) => {\n if (typeof message.content === \"string\") {\n return convertToV1FromChatCompletionsChunk(message);\n }\n return convertToV1FromResponsesChunk(message);\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAgB,+BACdA,SAC8B;CAC9B,MAAMC,SAAuC,CAAE;AAC/C,KAAI,OAAO,QAAQ,YAAY,UAC7B,OAAO,KAAK;EACV,MAAM;EACN,MAAM,QAAQ;CACf,EAAC;MAEF,OAAO,KAAK,GAAG,oCAAoC,QAAQ,QAAQ,CAAC;AAEtE,MAAK,MAAM,YAAY,QAAQ,cAAc,CAAE,GAC7C,OAAO,KAAK;EACV,MAAM;EACN,IAAI,SAAS;EACb,MAAM,SAAS;EACf,MAAM,SAAS;CAChB,EAAC;AAEJ,QAAO;AACR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCD,SAAgB,oCACdD,SAC8B;CAC9B,MAAMC,SAAuC,CAAE;AAC/C,KAAI,OAAO,QAAQ,YAAY,UAC7B,OAAO,KAAK;EACV,MAAM;EACN,MAAM,QAAQ;CACf,EAAC;MAEF,OAAO,KAAK,GAAG,oCAAoC,QAAQ,QAAQ,CAAC;AAItE,MAAK,MAAM,YAAY,QAAQ,cAAc,CAAE,GAC7C,OAAO,KAAK;EACV,MAAM;EACN,IAAI,SAAS;EACb,MAAM,SAAS;EACf,MAAM,SAAS;CAChB,EAAC;AAEJ,QAAO;AACR;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BD,SAAgB,oCACdC,QAC8B;CAC9B,MAAMC,kBAAgD,CAAE;AACxD,MAAK,MAAM,SAAS,OAClB,KAAI,kBAAkB,MAAM,EAC1B,gBAAgB,KAAK,+BAA+B,MAAM,CAAC;MAE3D,gBAAgB,KAAK,MAA+B;AAGxD,QA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B,UAAU,iBAAkD;EAC1D,OAAO,yBAAyB,QAAQ;AACxC,OAAK,MAAM,iBAAiB,QAAQ,oBAAoB,CAAE,GACxD,MAAM;GACJ,MAAM;GACN,IAAI,cAAc;GAClB,MAAM,cAAc;GACpB,MAAM,cAAc;EACrB;CAEJ;AACD,QAAO,MAAM,KAAK,gBAAgB,CAAC;AACpC;AAED,MAAaC,mBAAmD;CAC9D,kBAAkB,CAAC,YAAY;AAC7B,MAAI,OAAO,QAAQ,YAAY,SAC7B,QAAO,+BAA+B,QAAQ;AAEhD,SAAO,yBAAyB,QAAQ;CACzC;CACD,uBAAuB,CAAC,YAAY;AAClC,MAAI,OAAO,QAAQ,YAAY,SAC7B,QAAO,oCAAoC,QAAQ;AAErD,SAAO,8BAA8B,QAAQ;CAC9C;AACF"}
|
|
1
|
+
{"version":3,"file":"openai.js","names":["message: AIMessage","blocks: Array<ContentBlock.Standard>","blocks: Array<ContentBlock>","convertedBlocks: Array<ContentBlock.Standard>","annotation: ContentBlock","message: AIMessageChunk","ChatOpenAITranslator: StandardContentBlockTranslator"],"sources":["../../../src/messages/block_translators/openai.ts"],"sourcesContent":["import type { ContentBlock } from \"../content/index.js\";\nimport type { AIMessageChunk, AIMessage } from \"../ai.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { convertToV1FromOpenAIDataBlock, isOpenAIDataBlock } from \"./data.js\";\nimport {\n _isArray,\n _isContentBlock,\n _isObject,\n _isString,\n iife,\n} from \"./utils.js\";\n\n/**\n * Converts a ChatOpenAICompletions message to an array of v1 standard content blocks.\n *\n * This function processes an AI message from ChatOpenAICompletions API format\n * and converts it to the standardized v1 content block format. It handles both\n * string content and structured content blocks, as well as tool calls.\n *\n * @param message - The AI message containing ChatOpenAICompletions formatted content\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const message = new AIMessage(\"Hello world\");\n * const standardBlocks = convertToV1FromChatCompletions(message);\n * // Returns: [{ type: \"text\", text: \"Hello world\" }]\n * ```\n *\n * @example\n * ```typescript\n * const message = new AIMessage([\n * { type: \"text\", text: \"Hello\" },\n * { type: \"image_url\", image_url: { url: \"https://example.com/image.png\" } }\n * ]);\n * message.tool_calls = [\n * { id: \"call_123\", name: \"calculator\", args: { a: 1, b: 2 } }\n * ];\n *\n * const standardBlocks = convertToV1FromChatCompletions(message);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Hello\" },\n * // { type: \"image\", url: \"https://example.com/image.png\" },\n * // { type: \"tool_call\", id: \"call_123\", name: \"calculator\", args: { a: 1, b: 2 } }\n * // ]\n * ```\n */\nexport function convertToV1FromChatCompletions(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n const blocks: Array<ContentBlock.Standard> = [];\n if (typeof message.content === \"string\") {\n blocks.push({\n type: \"text\",\n text: message.content,\n });\n } else {\n blocks.push(...convertToV1FromChatCompletionsInput(message.content));\n }\n for (const toolCall of message.tool_calls ?? []) {\n blocks.push({\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n });\n }\n return blocks;\n}\n\n/**\n * Converts a ChatOpenAICompletions message chunk to an array of v1 standard content blocks.\n *\n * This function processes an AI message chunk from OpenAI's chat completions API and converts\n * it to the standardized v1 content block format. It handles both string and array content,\n * as well as tool calls that may be present in the chunk.\n *\n * @param message - The AI message chunk containing OpenAI-formatted content blocks\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const chunk = new AIMessage(\"Hello\");\n * const standardBlocks = convertToV1FromChatCompletionsChunk(chunk);\n * // Returns: [{ type: \"text\", text: \"Hello\" }]\n * ```\n *\n * @example\n * ```typescript\n * const chunk = new AIMessage([\n * { type: \"text\", text: \"Processing...\" }\n * ]);\n * chunk.tool_calls = [\n * { id: \"call_456\", name: \"search\", args: { query: \"test\" } }\n * ];\n *\n * const standardBlocks = convertToV1FromChatCompletionsChunk(chunk);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Processing...\" },\n * // { type: \"tool_call\", id: \"call_456\", name: \"search\", args: { query: \"test\" } }\n * // ]\n * ```\n */\nexport function convertToV1FromChatCompletionsChunk(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n const blocks: Array<ContentBlock.Standard> = [];\n if (typeof message.content === \"string\") {\n blocks.push({\n type: \"text\",\n text: message.content,\n });\n } else {\n blocks.push(...convertToV1FromChatCompletionsInput(message.content));\n }\n\n // TODO: parse chunk position information\n for (const toolCall of message.tool_calls ?? []) {\n blocks.push({\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n });\n }\n return blocks;\n}\n\n/**\n * Converts an array of ChatOpenAICompletions content blocks to v1 standard content blocks.\n *\n * This function processes content blocks from OpenAI's Chat Completions API format\n * and converts them to the standardized v1 content block format. It handles both\n * OpenAI-specific data blocks (which require conversion) and standard blocks\n * (which are passed through with type assertion).\n *\n * @param blocks - Array of content blocks in ChatOpenAICompletions format\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const openaiBlocks = [\n * { type: \"text\", text: \"Hello world\" },\n * { type: \"image_url\", image_url: { url: \"https://example.com/image.png\" } }\n * ];\n *\n * const standardBlocks = convertToV1FromChatCompletionsInput(openaiBlocks);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Hello world\" },\n * // { type: \"image\", url: \"https://example.com/image.png\" }\n * // ]\n * ```\n */\nexport function convertToV1FromChatCompletionsInput(\n blocks: Array<ContentBlock>\n): Array<ContentBlock.Standard> {\n const convertedBlocks: Array<ContentBlock.Standard> = [];\n for (const block of blocks) {\n if (isOpenAIDataBlock(block)) {\n convertedBlocks.push(convertToV1FromOpenAIDataBlock(block));\n } else {\n convertedBlocks.push(block as ContentBlock.Standard);\n }\n }\n return convertedBlocks;\n}\n\nfunction convertResponsesAnnotation(\n annotation: ContentBlock\n): ContentBlock | ContentBlock.Citation {\n if (annotation.type === \"url_citation\") {\n const { url, title, start_index, end_index } = annotation;\n return {\n type: \"citation\",\n url,\n title,\n startIndex: start_index,\n endIndex: end_index,\n };\n }\n if (annotation.type === \"file_citation\") {\n const { file_id, filename, index } = annotation;\n return {\n type: \"citation\",\n title: filename,\n startIndex: index,\n endIndex: index,\n fileId: file_id,\n };\n }\n return annotation;\n}\n\n/**\n * Converts a ChatOpenAIResponses message to an array of v1 standard content blocks.\n *\n * This function processes an AI message containing OpenAI Responses-specific content blocks\n * and converts them to the standardized v1 content block format. It handles reasoning summaries,\n * text content with annotations, tool calls, and various tool outputs including code interpreter,\n * web search, file search, computer calls, and MCP-related blocks.\n *\n * @param message - The AI message containing OpenAI Responses-formatted content blocks\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const message = new AIMessage({\n * content: [{ type: \"text\", text: \"Hello world\", annotations: [] }],\n * tool_calls: [{ id: \"123\", name: \"calculator\", args: { a: 1, b: 2 } }],\n * additional_kwargs: {\n * reasoning: { summary: [{ text: \"Let me calculate this...\" }] },\n * tool_outputs: [\n * {\n * type: \"code_interpreter_call\",\n * code: \"print('hello')\",\n * outputs: [{ type: \"logs\", logs: \"hello\" }]\n * }\n * ]\n * }\n * });\n *\n * const standardBlocks = convertToV1FromResponses(message);\n * // Returns:\n * // [\n * // { type: \"reasoning\", reasoning: \"Let me calculate this...\" },\n * // { type: \"text\", text: \"Hello world\", annotations: [] },\n * // { type: \"tool_call\", id: \"123\", name: \"calculator\", args: { a: 1, b: 2 } },\n * // { type: \"code_interpreter_call\", code: \"print('hello')\" },\n * // { type: \"code_interpreter_result\", output: [{ type: \"code_interpreter_output\", returnCode: 0, stdout: \"hello\" }] }\n * // ]\n * ```\n */\nexport function convertToV1FromResponses(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n if (\n _isObject(message.additional_kwargs?.reasoning) &&\n _isArray(message.additional_kwargs.reasoning.summary)\n ) {\n const summary =\n message.additional_kwargs.reasoning.summary.reduce<string>(\n (acc, item) => {\n if (_isObject(item) && _isString(item.text)) {\n return `${acc}${item.text}`;\n }\n return acc;\n },\n \"\"\n );\n yield {\n type: \"reasoning\",\n reasoning: summary,\n };\n }\n const content =\n typeof message.content === \"string\"\n ? [{ type: \"text\", text: message.content }]\n : message.content;\n for (const block of content) {\n if (_isContentBlock(block, \"text\")) {\n const { text, annotations, ...rest } = block;\n if (Array.isArray(annotations)) {\n yield {\n ...rest,\n type: \"text\",\n text: String(text),\n annotations: annotations.map(convertResponsesAnnotation),\n };\n } else {\n yield {\n ...rest,\n type: \"text\",\n text: String(text),\n };\n }\n }\n }\n for (const toolCall of message.tool_calls ?? []) {\n yield {\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n };\n }\n if (\n _isObject(message.additional_kwargs) &&\n _isArray(message.additional_kwargs.tool_outputs)\n ) {\n for (const toolOutput of message.additional_kwargs.tool_outputs) {\n if (_isContentBlock(toolOutput, \"web_search_call\")) {\n yield {\n id: toolOutput.id,\n type: \"server_tool_call\",\n name: \"web_search\",\n args: { query: toolOutput.query },\n };\n continue;\n } else if (_isContentBlock(toolOutput, \"file_search_call\")) {\n yield {\n id: toolOutput.id,\n type: \"server_tool_call\",\n name: \"file_search\",\n args: { query: toolOutput.query },\n };\n continue;\n } else if (_isContentBlock(toolOutput, \"computer_call\")) {\n yield { type: \"non_standard\", value: toolOutput };\n continue;\n } else if (_isContentBlock(toolOutput, \"code_interpreter_call\")) {\n if (_isString(toolOutput.code)) {\n yield {\n id: toolOutput.id,\n type: \"server_tool_call\",\n name: \"code_interpreter\",\n args: { code: toolOutput.code },\n };\n }\n if (_isArray(toolOutput.outputs)) {\n const returnCode = iife(() => {\n if (toolOutput.status === \"in_progress\") return undefined;\n if (toolOutput.status === \"completed\") return 0;\n if (toolOutput.status === \"incomplete\") return 127;\n if (toolOutput.status === \"interpreting\") return undefined;\n if (toolOutput.status === \"failed\") return 1;\n return undefined;\n });\n for (const output of toolOutput.outputs) {\n if (_isContentBlock(output, \"logs\")) {\n yield {\n type: \"server_tool_call_result\",\n toolCallId: toolOutput.id ?? \"\",\n status: \"success\",\n output: {\n type: \"code_interpreter_output\",\n returnCode: returnCode ?? 0,\n stderr: [0, undefined].includes(returnCode)\n ? undefined\n : String(output.logs),\n stdout: [0, undefined].includes(returnCode)\n ? String(output.logs)\n : undefined,\n },\n };\n continue;\n }\n }\n }\n continue;\n } else if (_isContentBlock(toolOutput, \"mcp_call\")) {\n yield {\n id: toolOutput.id,\n type: \"server_tool_call\",\n name: \"mcp_call\",\n args: toolOutput.input,\n };\n continue;\n } else if (_isContentBlock(toolOutput, \"mcp_list_tools\")) {\n yield {\n id: toolOutput.id,\n type: \"server_tool_call\",\n name: \"mcp_list_tools\",\n args: toolOutput.input,\n };\n continue;\n } else if (_isContentBlock(toolOutput, \"mcp_approval_request\")) {\n yield { type: \"non_standard\", value: toolOutput };\n continue;\n } else if (_isContentBlock(toolOutput, \"image_generation_call\")) {\n yield { type: \"non_standard\", value: toolOutput };\n continue;\n }\n if (_isObject(toolOutput)) {\n yield { type: \"non_standard\", value: toolOutput };\n }\n }\n }\n }\n return Array.from(iterateContent());\n}\n\n/**\n * Converts a ChatOpenAIResponses message chunk to an array of v1 standard content blocks.\n *\n * This function processes an AI message chunk containing OpenAI-specific content blocks\n * and converts them to the standardized v1 content block format. It handles both the\n * regular message content and tool call chunks that are specific to streaming responses.\n *\n * @param message - The AI message chunk containing OpenAI-formatted content blocks\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const messageChunk = new AIMessageChunk({\n * content: [{ type: \"text\", text: \"Hello\" }],\n * tool_call_chunks: [\n * { id: \"call_123\", name: \"calculator\", args: '{\"a\": 1' }\n * ]\n * });\n *\n * const standardBlocks = convertToV1FromResponsesChunk(messageChunk);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Hello\" },\n * // { type: \"tool_call_chunk\", id: \"call_123\", name: \"calculator\", args: '{\"a\": 1' }\n * // ]\n * ```\n */\nexport function convertToV1FromResponsesChunk(\n message: AIMessageChunk\n): Array<ContentBlock.Standard> {\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n yield* convertToV1FromResponses(message);\n for (const toolCallChunk of message.tool_call_chunks ?? []) {\n yield {\n type: \"tool_call_chunk\",\n id: toolCallChunk.id,\n name: toolCallChunk.name,\n args: toolCallChunk.args,\n };\n }\n }\n return Array.from(iterateContent());\n}\n\nexport const ChatOpenAITranslator: StandardContentBlockTranslator = {\n translateContent: (message) => {\n if (typeof message.content === \"string\") {\n return convertToV1FromChatCompletions(message);\n }\n return convertToV1FromResponses(message);\n },\n translateContentChunk: (message) => {\n if (typeof message.content === \"string\") {\n return convertToV1FromChatCompletionsChunk(message);\n }\n return convertToV1FromResponsesChunk(message);\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAgB,+BACdA,SAC8B;CAC9B,MAAMC,SAAuC,CAAE;AAC/C,KAAI,OAAO,QAAQ,YAAY,UAC7B,OAAO,KAAK;EACV,MAAM;EACN,MAAM,QAAQ;CACf,EAAC;MAEF,OAAO,KAAK,GAAG,oCAAoC,QAAQ,QAAQ,CAAC;AAEtE,MAAK,MAAM,YAAY,QAAQ,cAAc,CAAE,GAC7C,OAAO,KAAK;EACV,MAAM;EACN,IAAI,SAAS;EACb,MAAM,SAAS;EACf,MAAM,SAAS;CAChB,EAAC;AAEJ,QAAO;AACR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCD,SAAgB,oCACdD,SAC8B;CAC9B,MAAMC,SAAuC,CAAE;AAC/C,KAAI,OAAO,QAAQ,YAAY,UAC7B,OAAO,KAAK;EACV,MAAM;EACN,MAAM,QAAQ;CACf,EAAC;MAEF,OAAO,KAAK,GAAG,oCAAoC,QAAQ,QAAQ,CAAC;AAItE,MAAK,MAAM,YAAY,QAAQ,cAAc,CAAE,GAC7C,OAAO,KAAK;EACV,MAAM;EACN,IAAI,SAAS;EACb,MAAM,SAAS;EACf,MAAM,SAAS;CAChB,EAAC;A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,YAAY;AAC7B,MAAI,OAAO,QAAQ,YAAY,SAC7B,QAAO,+BAA+B,QAAQ;AAEhD,SAAO,yBAAyB,QAAQ;CACzC;CACD,uBAAuB,CAAC,YAAY;AAClC,MAAI,OAAO,QAAQ,YAAY,SAC7B,QAAO,oCAAoC,QAAQ;AAErD,SAAO,8BAA8B,QAAQ;CAC9C;AACF"}
|
|
@@ -15,6 +15,9 @@ function _isString(value) {
|
|
|
15
15
|
function _isNumber(value) {
|
|
16
16
|
return typeof value === "number";
|
|
17
17
|
}
|
|
18
|
+
function _isBytesArray(value) {
|
|
19
|
+
return value instanceof Uint8Array;
|
|
20
|
+
}
|
|
18
21
|
function safeParseJson(value) {
|
|
19
22
|
try {
|
|
20
23
|
return JSON.parse(value);
|
|
@@ -26,6 +29,7 @@ const iife = (fn) => fn();
|
|
|
26
29
|
|
|
27
30
|
//#endregion
|
|
28
31
|
exports._isArray = _isArray;
|
|
32
|
+
exports._isBytesArray = _isBytesArray;
|
|
29
33
|
exports._isContentBlock = _isContentBlock;
|
|
30
34
|
exports._isNumber = _isNumber;
|
|
31
35
|
exports._isObject = _isObject;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","names":["block: unknown","type: T","value: unknown","value: string","fn: () => T"],"sources":["../../../src/messages/block_translators/utils.ts"],"sourcesContent":["import type { ContentBlock } from \"../content/index.js\";\n\nexport function _isContentBlock<T extends string>(\n block: unknown,\n type: T\n): block is ContentBlock & { type: T } {\n return _isObject(block) && block.type === type;\n}\n\nexport function _isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\nexport function _isArray<T>(value: unknown): value is T[] {\n return Array.isArray(value);\n}\n\nexport function _isString(value: unknown): value is string {\n return typeof value === \"string\";\n}\n\nexport function _isNumber(value: unknown): value is number {\n return typeof value === \"number\";\n}\n\nexport function safeParseJson<T = unknown>(value: string): T | undefined {\n try {\n return JSON.parse(value);\n } catch {\n return undefined;\n }\n}\n\nexport const iife = <T>(fn: () => T): T => fn();\n"],"mappings":";;AAEA,SAAgB,gBACdA,OACAC,MACqC;AACrC,QAAO,UAAU,MAAM,IAAI,MAAM,SAAS;AAC3C;AAED,SAAgB,UAAUC,OAAkD;AAC1E,QAAO,OAAO,UAAU,YAAY,UAAU;AAC/C;AAED,SAAgB,SAAYA,OAA8B;AACxD,QAAO,MAAM,QAAQ,MAAM;AAC5B;AAED,SAAgB,UAAUA,OAAiC;AACzD,QAAO,OAAO,UAAU;AACzB;AAED,SAAgB,UAAUA,OAAiC;AACzD,QAAO,OAAO,UAAU;AACzB;AAED,SAAgB,cAA2BC,OAA8B;AACvE,KAAI;AACF,SAAO,KAAK,MAAM,MAAM;CACzB,QAAO;AACN,SAAO;CACR;AACF;AAED,MAAa,OAAO,CAAIC,OAAmB,IAAI"}
|
|
1
|
+
{"version":3,"file":"utils.cjs","names":["block: unknown","type: T","value: unknown","value: string","fn: () => T"],"sources":["../../../src/messages/block_translators/utils.ts"],"sourcesContent":["import type { ContentBlock } from \"../content/index.js\";\n\nexport function _isContentBlock<T extends string>(\n block: unknown,\n type: T\n): block is ContentBlock & { type: T } {\n return _isObject(block) && block.type === type;\n}\n\nexport function _isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\nexport function _isArray<T>(value: unknown): value is T[] {\n return Array.isArray(value);\n}\n\nexport function _isString(value: unknown): value is string {\n return typeof value === \"string\";\n}\n\nexport function _isNumber(value: unknown): value is number {\n return typeof value === \"number\";\n}\n\nexport function _isBytesArray(value: unknown): value is Uint8Array {\n // eslint-disable-next-line no-instanceof/no-instanceof\n return value instanceof Uint8Array;\n}\n\nexport function safeParseJson<T = unknown>(value: string): T | undefined {\n try {\n return JSON.parse(value);\n } catch {\n return undefined;\n }\n}\n\nexport const iife = <T>(fn: () => T): T => fn();\n"],"mappings":";;AAEA,SAAgB,gBACdA,OACAC,MACqC;AACrC,QAAO,UAAU,MAAM,IAAI,MAAM,SAAS;AAC3C;AAED,SAAgB,UAAUC,OAAkD;AAC1E,QAAO,OAAO,UAAU,YAAY,UAAU;AAC/C;AAED,SAAgB,SAAYA,OAA8B;AACxD,QAAO,MAAM,QAAQ,MAAM;AAC5B;AAED,SAAgB,UAAUA,OAAiC;AACzD,QAAO,OAAO,UAAU;AACzB;AAED,SAAgB,UAAUA,OAAiC;AACzD,QAAO,OAAO,UAAU;AACzB;AAED,SAAgB,cAAcA,OAAqC;AAEjE,QAAO,iBAAiB;AACzB;AAED,SAAgB,cAA2BC,OAA8B;AACvE,KAAI;AACF,SAAO,KAAK,MAAM,MAAM;CACzB,QAAO;AACN,SAAO;CACR;AACF;AAED,MAAa,OAAO,CAAIC,OAAmB,IAAI"}
|
|
@@ -14,6 +14,9 @@ function _isString(value) {
|
|
|
14
14
|
function _isNumber(value) {
|
|
15
15
|
return typeof value === "number";
|
|
16
16
|
}
|
|
17
|
+
function _isBytesArray(value) {
|
|
18
|
+
return value instanceof Uint8Array;
|
|
19
|
+
}
|
|
17
20
|
function safeParseJson(value) {
|
|
18
21
|
try {
|
|
19
22
|
return JSON.parse(value);
|
|
@@ -24,5 +27,5 @@ function safeParseJson(value) {
|
|
|
24
27
|
const iife = (fn) => fn();
|
|
25
28
|
|
|
26
29
|
//#endregion
|
|
27
|
-
export { _isArray, _isContentBlock, _isNumber, _isObject, _isString, iife, safeParseJson };
|
|
30
|
+
export { _isArray, _isBytesArray, _isContentBlock, _isNumber, _isObject, _isString, iife, safeParseJson };
|
|
28
31
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["block: unknown","type: T","value: unknown","value: string","fn: () => T"],"sources":["../../../src/messages/block_translators/utils.ts"],"sourcesContent":["import type { ContentBlock } from \"../content/index.js\";\n\nexport function _isContentBlock<T extends string>(\n block: unknown,\n type: T\n): block is ContentBlock & { type: T } {\n return _isObject(block) && block.type === type;\n}\n\nexport function _isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\nexport function _isArray<T>(value: unknown): value is T[] {\n return Array.isArray(value);\n}\n\nexport function _isString(value: unknown): value is string {\n return typeof value === \"string\";\n}\n\nexport function _isNumber(value: unknown): value is number {\n return typeof value === \"number\";\n}\n\nexport function safeParseJson<T = unknown>(value: string): T | undefined {\n try {\n return JSON.parse(value);\n } catch {\n return undefined;\n }\n}\n\nexport const iife = <T>(fn: () => T): T => fn();\n"],"mappings":";AAEA,SAAgB,gBACdA,OACAC,MACqC;AACrC,QAAO,UAAU,MAAM,IAAI,MAAM,SAAS;AAC3C;AAED,SAAgB,UAAUC,OAAkD;AAC1E,QAAO,OAAO,UAAU,YAAY,UAAU;AAC/C;AAED,SAAgB,SAAYA,OAA8B;AACxD,QAAO,MAAM,QAAQ,MAAM;AAC5B;AAED,SAAgB,UAAUA,OAAiC;AACzD,QAAO,OAAO,UAAU;AACzB;AAED,SAAgB,UAAUA,OAAiC;AACzD,QAAO,OAAO,UAAU;AACzB;AAED,SAAgB,cAA2BC,OAA8B;AACvE,KAAI;AACF,SAAO,KAAK,MAAM,MAAM;CACzB,QAAO;AACN,SAAO;CACR;AACF;AAED,MAAa,OAAO,CAAIC,OAAmB,IAAI"}
|
|
1
|
+
{"version":3,"file":"utils.js","names":["block: unknown","type: T","value: unknown","value: string","fn: () => T"],"sources":["../../../src/messages/block_translators/utils.ts"],"sourcesContent":["import type { ContentBlock } from \"../content/index.js\";\n\nexport function _isContentBlock<T extends string>(\n block: unknown,\n type: T\n): block is ContentBlock & { type: T } {\n return _isObject(block) && block.type === type;\n}\n\nexport function _isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\nexport function _isArray<T>(value: unknown): value is T[] {\n return Array.isArray(value);\n}\n\nexport function _isString(value: unknown): value is string {\n return typeof value === \"string\";\n}\n\nexport function _isNumber(value: unknown): value is number {\n return typeof value === \"number\";\n}\n\nexport function _isBytesArray(value: unknown): value is Uint8Array {\n // eslint-disable-next-line no-instanceof/no-instanceof\n return value instanceof Uint8Array;\n}\n\nexport function safeParseJson<T = unknown>(value: string): T | undefined {\n try {\n return JSON.parse(value);\n } catch {\n return undefined;\n }\n}\n\nexport const iife = <T>(fn: () => T): T => fn();\n"],"mappings":";AAEA,SAAgB,gBACdA,OACAC,MACqC;AACrC,QAAO,UAAU,MAAM,IAAI,MAAM,SAAS;AAC3C;AAED,SAAgB,UAAUC,OAAkD;AAC1E,QAAO,OAAO,UAAU,YAAY,UAAU;AAC/C;AAED,SAAgB,SAAYA,OAA8B;AACxD,QAAO,MAAM,QAAQ,MAAM;AAC5B;AAED,SAAgB,UAAUA,OAAiC;AACzD,QAAO,OAAO,UAAU;AACzB;AAED,SAAgB,UAAUA,OAAiC;AACzD,QAAO,OAAO,UAAU;AACzB;AAED,SAAgB,cAAcA,OAAqC;AAEjE,QAAO,iBAAiB;AACzB;AAED,SAAgB,cAA2BC,OAA8B;AACvE,KAAI;AACF,SAAO,KAAK,MAAM,MAAM;CACzB,QAAO;AACN,SAAO;CACR;AACF;AAED,MAAa,OAAO,CAAIC,OAAmB,IAAI"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["KNOWN_BLOCK_TYPES","KNOWN_TOOL_BLOCK_TYPES","KNOWN_MULTIMODAL_BLOCK_TYPES"],"sources":["../../../src/messages/content/index.ts"],"sourcesContent":["import type { BaseContentBlock } from \"./base.js\";\nimport {\n KNOWN_BLOCK_TYPES as KNOWN_TOOL_BLOCK_TYPES,\n type Tools,\n} from \"./tools.js\";\nimport {\n KNOWN_BLOCK_TYPES as KNOWN_MULTIMODAL_BLOCK_TYPES,\n type Multimodal,\n} from \"./multimodal.js\";\nimport { type Data } from \"./data.js\";\n\nexport interface ContentBlock extends BaseContentBlock {}\n\nexport const KNOWN_BLOCK_TYPES = [\n \"text\",\n \"reasoning\",\n ...KNOWN_TOOL_BLOCK_TYPES,\n ...KNOWN_MULTIMODAL_BLOCK_TYPES,\n];\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport declare namespace ContentBlock {\n /**\n * Annotation for citing data from a document.\n */\n export interface Citation {\n /**\n * Type of the content block\n */\n readonly type: \"citation\";\n /**\n * Source type for the citation.\n */\n source?: string;\n /**\n * URL of the document source\n */\n url?: string;\n /**\n * Source document title.\n *\n * For example, the page title for a web page or the title of a paper.\n */\n title?: string;\n /**\n * Start index of the **response text** for which the annotation applies.\n *\n * @see {Text}\n */\n startIndex?: number;\n /**\n * End index of the **response text** for which the annotation applies.\n *\n * @see {Text}\n */\n endIndex?: number;\n /**\n * Excerpt of source text being cited.\n */\n citedText?: string;\n }\n\n /**\n * Text output from a LLM.\n *\n * This typically represents the main text content of a message, such as the response\n * from a language model or the text of a user message.\n */\n export interface Text extends ContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"text\";\n /**\n * Block text.\n */\n text: string;\n /**\n * Index of block in aggregate response. Used during streaming.\n */\n index?: number;\n /**\n * Citations and other annotations.\n */\n annotations?: Array<Citation | BaseContentBlock>;\n }\n\n /**\n * Reasoning output from a LLM.\n */\n export interface Reasoning extends ContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"reasoning\";\n /**\n * Reasoning text.\n *\n * Either the thought summary or the raw reasoning text itself.\n * This is often parsed from `<think>` tags in the model's response.\n */\n reasoning: string;\n /**\n * Index of block in aggregate response. Used during streaming.\n */\n index?: number;\n }\n\n export { Tools };\n export { Multimodal };\n export { Data };\n\n export type Standard =\n | Text\n | Reasoning\n | Tools.Standard\n | Multimodal.Standard;\n}\n"],"mappings":";;;;AAaA,MAAaA,sBAAoB;CAC/B;CACA;CACA,GAAGC;CACH,GAAGC;AACJ"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["KNOWN_BLOCK_TYPES","KNOWN_TOOL_BLOCK_TYPES","KNOWN_MULTIMODAL_BLOCK_TYPES"],"sources":["../../../src/messages/content/index.ts"],"sourcesContent":["import type { BaseContentBlock } from \"./base.js\";\nimport {\n KNOWN_BLOCK_TYPES as KNOWN_TOOL_BLOCK_TYPES,\n type Tools,\n} from \"./tools.js\";\nimport {\n KNOWN_BLOCK_TYPES as KNOWN_MULTIMODAL_BLOCK_TYPES,\n type Multimodal,\n} from \"./multimodal.js\";\nimport { type Data } from \"./data.js\";\n\nexport interface ContentBlock extends BaseContentBlock {}\n\nexport const KNOWN_BLOCK_TYPES = [\n \"text\",\n \"reasoning\",\n ...KNOWN_TOOL_BLOCK_TYPES,\n ...KNOWN_MULTIMODAL_BLOCK_TYPES,\n];\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport declare namespace ContentBlock {\n /**\n * Annotation for citing data from a document.\n */\n export interface Citation {\n /**\n * Type of the content block\n */\n readonly type: \"citation\";\n /**\n * Source type for the citation.\n */\n source?: string;\n /**\n * URL of the document source\n */\n url?: string;\n /**\n * Source document title.\n *\n * For example, the page title for a web page or the title of a paper.\n */\n title?: string;\n /**\n * Start index of the **response text** for which the annotation applies.\n *\n * @see {Text}\n */\n startIndex?: number;\n /**\n * End index of the **response text** for which the annotation applies.\n *\n * @see {Text}\n */\n endIndex?: number;\n /**\n * Excerpt of source text being cited.\n */\n citedText?: string;\n }\n\n /**\n * Text output from a LLM.\n *\n * This typically represents the main text content of a message, such as the response\n * from a language model or the text of a user message.\n */\n export interface Text extends ContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"text\";\n /**\n * Block text.\n */\n text: string;\n /**\n * Index of block in aggregate response. Used during streaming.\n */\n index?: number;\n /**\n * Citations and other annotations.\n */\n annotations?: Array<Citation | BaseContentBlock>;\n }\n\n /**\n * Reasoning output from a LLM.\n */\n export interface Reasoning extends ContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"reasoning\";\n /**\n * Reasoning text.\n *\n * Either the thought summary or the raw reasoning text itself.\n * This is often parsed from `<think>` tags in the model's response.\n */\n reasoning: string;\n /**\n * Index of block in aggregate response. Used during streaming.\n */\n index?: number;\n }\n\n /**\n * Provider-specific content block.\n *\n * This is used to represent content blocks that are not part of the standard LangChain content model.\n * If a provider's non-standard output includes reasoning and tool calls, it should be\n * the adapter's job to parse that payload and emit the corresponding standard reasoning and tool call blocks.\n */\n export interface NonStandard<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TValue extends Record<string, any> = Record<string, any>\n > extends ContentBlock {\n /**\n * Type of the content block\n */\n type: \"non_standard\";\n /**\n * Provider-specific data\n */\n value: TValue;\n }\n\n export { Tools };\n export { Multimodal };\n export { Data };\n\n export type Standard =\n | Text\n | Reasoning\n | NonStandard\n | Tools.Standard\n | Multimodal.Standard;\n}\n"],"mappings":";;;;AAaA,MAAaA,sBAAoB;CAC/B;CACA;CACA,GAAGC;CACH,GAAGC;AACJ"}
|
|
@@ -91,10 +91,29 @@ declare namespace ContentBlock {
|
|
|
91
91
|
*/
|
|
92
92
|
index?: number;
|
|
93
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Provider-specific content block.
|
|
96
|
+
*
|
|
97
|
+
* This is used to represent content blocks that are not part of the standard LangChain content model.
|
|
98
|
+
* If a provider's non-standard output includes reasoning and tool calls, it should be
|
|
99
|
+
* the adapter's job to parse that payload and emit the corresponding standard reasoning and tool call blocks.
|
|
100
|
+
*/
|
|
101
|
+
export interface NonStandard<
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
103
|
+
TValue extends Record<string, any> = Record<string, any>> extends ContentBlock {
|
|
104
|
+
/**
|
|
105
|
+
* Type of the content block
|
|
106
|
+
*/
|
|
107
|
+
type: "non_standard";
|
|
108
|
+
/**
|
|
109
|
+
* Provider-specific data
|
|
110
|
+
*/
|
|
111
|
+
value: TValue;
|
|
112
|
+
}
|
|
94
113
|
export { Tools };
|
|
95
114
|
export { Multimodal };
|
|
96
115
|
export { Data };
|
|
97
|
-
export type Standard = Text | Reasoning | Tools.Standard | Multimodal.Standard;
|
|
116
|
+
export type Standard = Text | Reasoning | NonStandard | Tools.Standard | Multimodal.Standard;
|
|
98
117
|
}
|
|
99
118
|
//#endregion
|
|
100
119
|
export { ContentBlock, KNOWN_BLOCK_TYPES };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":["BaseContentBlock","Tools","Multimodal","Data","ContentBlock","KNOWN_BLOCK_TYPES","Citation","Array","Text","Reasoning","Standard"],"sources":["../../../src/messages/content/index.d.ts"],"sourcesContent":["import type { BaseContentBlock } from \"./base.js\";\nimport { type Tools } from \"./tools.js\";\nimport { type Multimodal } from \"./multimodal.js\";\nimport { type Data } from \"./data.js\";\nexport interface ContentBlock extends BaseContentBlock {\n}\nexport declare const KNOWN_BLOCK_TYPES: string[];\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport declare namespace ContentBlock {\n /**\n * Annotation for citing data from a document.\n */\n export interface Citation {\n /**\n * Type of the content block\n */\n readonly type: \"citation\";\n /**\n * Source type for the citation.\n */\n source?: string;\n /**\n * URL of the document source\n */\n url?: string;\n /**\n * Source document title.\n *\n * For example, the page title for a web page or the title of a paper.\n */\n title?: string;\n /**\n * Start index of the **response text** for which the annotation applies.\n *\n * @see {Text}\n */\n startIndex?: number;\n /**\n * End index of the **response text** for which the annotation applies.\n *\n * @see {Text}\n */\n endIndex?: number;\n /**\n * Excerpt of source text being cited.\n */\n citedText?: string;\n }\n /**\n * Text output from a LLM.\n *\n * This typically represents the main text content of a message, such as the response\n * from a language model or the text of a user message.\n */\n export interface Text extends ContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"text\";\n /**\n * Block text.\n */\n text: string;\n /**\n * Index of block in aggregate response. Used during streaming.\n */\n index?: number;\n /**\n * Citations and other annotations.\n */\n annotations?: Array<Citation | BaseContentBlock>;\n }\n /**\n * Reasoning output from a LLM.\n */\n export interface Reasoning extends ContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"reasoning\";\n /**\n * Reasoning text.\n *\n * Either the thought summary or the raw reasoning text itself.\n * This is often parsed from `<think>` tags in the model's response.\n */\n reasoning: string;\n /**\n * Index of block in aggregate response. Used during streaming.\n */\n index?: number;\n }\n export { Tools };\n export { Multimodal };\n export { Data };\n export type Standard = Text | Reasoning | Tools.Standard | Multimodal.Standard;\n}\n"],"mappings":";;;;;;UAIiBI,YAAAA,SAAqBJ;AAArBI,cAEIC,iBAFiBL,EAAAA,MAAAA,EAAgB;AAEtD;AAEyBI,kBAAAA,YAAAA,CAAY;EAAA;;;EA8DkB,OAAjCG,UAAAA,QAAAA,CAAAA;IAhBYH;;;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":["BaseContentBlock","Tools","Multimodal","Data","ContentBlock","KNOWN_BLOCK_TYPES","Citation","Array","Record","TValue","Text","Reasoning","NonStandard","Standard"],"sources":["../../../src/messages/content/index.d.ts"],"sourcesContent":["import type { BaseContentBlock } from \"./base.js\";\nimport { type Tools } from \"./tools.js\";\nimport { type Multimodal } from \"./multimodal.js\";\nimport { type Data } from \"./data.js\";\nexport interface ContentBlock extends BaseContentBlock {\n}\nexport declare const KNOWN_BLOCK_TYPES: string[];\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport declare namespace ContentBlock {\n /**\n * Annotation for citing data from a document.\n */\n export interface Citation {\n /**\n * Type of the content block\n */\n readonly type: \"citation\";\n /**\n * Source type for the citation.\n */\n source?: string;\n /**\n * URL of the document source\n */\n url?: string;\n /**\n * Source document title.\n *\n * For example, the page title for a web page or the title of a paper.\n */\n title?: string;\n /**\n * Start index of the **response text** for which the annotation applies.\n *\n * @see {Text}\n */\n startIndex?: number;\n /**\n * End index of the **response text** for which the annotation applies.\n *\n * @see {Text}\n */\n endIndex?: number;\n /**\n * Excerpt of source text being cited.\n */\n citedText?: string;\n }\n /**\n * Text output from a LLM.\n *\n * This typically represents the main text content of a message, such as the response\n * from a language model or the text of a user message.\n */\n export interface Text extends ContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"text\";\n /**\n * Block text.\n */\n text: string;\n /**\n * Index of block in aggregate response. Used during streaming.\n */\n index?: number;\n /**\n * Citations and other annotations.\n */\n annotations?: Array<Citation | BaseContentBlock>;\n }\n /**\n * Reasoning output from a LLM.\n */\n export interface Reasoning extends ContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"reasoning\";\n /**\n * Reasoning text.\n *\n * Either the thought summary or the raw reasoning text itself.\n * This is often parsed from `<think>` tags in the model's response.\n */\n reasoning: string;\n /**\n * Index of block in aggregate response. Used during streaming.\n */\n index?: number;\n }\n /**\n * Provider-specific content block.\n *\n * This is used to represent content blocks that are not part of the standard LangChain content model.\n * If a provider's non-standard output includes reasoning and tool calls, it should be\n * the adapter's job to parse that payload and emit the corresponding standard reasoning and tool call blocks.\n */\n export interface NonStandard<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TValue extends Record<string, any> = Record<string, any>> extends ContentBlock {\n /**\n * Type of the content block\n */\n type: \"non_standard\";\n /**\n * Provider-specific data\n */\n value: TValue;\n }\n export { Tools };\n export { Multimodal };\n export { Data };\n export type Standard = Text | Reasoning | NonStandard | Tools.Standard | Multimodal.Standard;\n}\n"],"mappings":";;;;;;UAIiBI,YAAAA,SAAqBJ;AAArBI,cAEIC,iBAFiBL,EAAAA,MAAAA,EAAgB;AAEtD;AAEyBI,kBAAAA,YAAAA,CAAY;EAAA;;;EA8DkB,OAAjCG,UAAAA,QAAAA,CAAAA;IAhBYH;;;IA+COI,SAAAA,IAAAA,EAAAA,UAAAA;IAQ1BC;;;IAGFP,MAAAA,CAAAA,EAAAA,MAAAA;IACAC;;;IACiCS,GAAAA,CAAAA,EAAAA,MAAAA;IAAcX;;AAAoC;;;;;;;;;;;;;;;;;;;;;;;;;;;gCA5D9DG;;;;;;;;;;;;;;;;kBAgBZG,MAAMD,WAAWN;;;;;qCAKAI;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0BpBI,sBAAsBA,6BAA6BJ;;;;;;;;WAQvDK;;WAEFR;WACAC;WACAC;yBACcO,OAAOC,YAAYC,cAAcX,KAAAA,CAAMY,WAAWX,UAAAA,CAAWW"}
|
|
@@ -91,10 +91,29 @@ declare namespace ContentBlock {
|
|
|
91
91
|
*/
|
|
92
92
|
index?: number;
|
|
93
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Provider-specific content block.
|
|
96
|
+
*
|
|
97
|
+
* This is used to represent content blocks that are not part of the standard LangChain content model.
|
|
98
|
+
* If a provider's non-standard output includes reasoning and tool calls, it should be
|
|
99
|
+
* the adapter's job to parse that payload and emit the corresponding standard reasoning and tool call blocks.
|
|
100
|
+
*/
|
|
101
|
+
export interface NonStandard<
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
103
|
+
TValue extends Record<string, any> = Record<string, any>> extends ContentBlock {
|
|
104
|
+
/**
|
|
105
|
+
* Type of the content block
|
|
106
|
+
*/
|
|
107
|
+
type: "non_standard";
|
|
108
|
+
/**
|
|
109
|
+
* Provider-specific data
|
|
110
|
+
*/
|
|
111
|
+
value: TValue;
|
|
112
|
+
}
|
|
94
113
|
export { Tools };
|
|
95
114
|
export { Multimodal };
|
|
96
115
|
export { Data };
|
|
97
|
-
export type Standard = Text | Reasoning | Tools.Standard | Multimodal.Standard;
|
|
116
|
+
export type Standard = Text | Reasoning | NonStandard | Tools.Standard | Multimodal.Standard;
|
|
98
117
|
}
|
|
99
118
|
//#endregion
|
|
100
119
|
export { ContentBlock, KNOWN_BLOCK_TYPES };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["BaseContentBlock","Tools","Multimodal","Data","ContentBlock","KNOWN_BLOCK_TYPES","Citation","Array","Text","Reasoning","Standard"],"sources":["../../../src/messages/content/index.d.ts"],"sourcesContent":["import type { BaseContentBlock } from \"./base.js\";\nimport { type Tools } from \"./tools.js\";\nimport { type Multimodal } from \"./multimodal.js\";\nimport { type Data } from \"./data.js\";\nexport interface ContentBlock extends BaseContentBlock {\n}\nexport declare const KNOWN_BLOCK_TYPES: string[];\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport declare namespace ContentBlock {\n /**\n * Annotation for citing data from a document.\n */\n export interface Citation {\n /**\n * Type of the content block\n */\n readonly type: \"citation\";\n /**\n * Source type for the citation.\n */\n source?: string;\n /**\n * URL of the document source\n */\n url?: string;\n /**\n * Source document title.\n *\n * For example, the page title for a web page or the title of a paper.\n */\n title?: string;\n /**\n * Start index of the **response text** for which the annotation applies.\n *\n * @see {Text}\n */\n startIndex?: number;\n /**\n * End index of the **response text** for which the annotation applies.\n *\n * @see {Text}\n */\n endIndex?: number;\n /**\n * Excerpt of source text being cited.\n */\n citedText?: string;\n }\n /**\n * Text output from a LLM.\n *\n * This typically represents the main text content of a message, such as the response\n * from a language model or the text of a user message.\n */\n export interface Text extends ContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"text\";\n /**\n * Block text.\n */\n text: string;\n /**\n * Index of block in aggregate response. Used during streaming.\n */\n index?: number;\n /**\n * Citations and other annotations.\n */\n annotations?: Array<Citation | BaseContentBlock>;\n }\n /**\n * Reasoning output from a LLM.\n */\n export interface Reasoning extends ContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"reasoning\";\n /**\n * Reasoning text.\n *\n * Either the thought summary or the raw reasoning text itself.\n * This is often parsed from `<think>` tags in the model's response.\n */\n reasoning: string;\n /**\n * Index of block in aggregate response. Used during streaming.\n */\n index?: number;\n }\n export { Tools };\n export { Multimodal };\n export { Data };\n export type Standard = Text | Reasoning | Tools.Standard | Multimodal.Standard;\n}\n"],"mappings":";;;;;;UAIiBI,YAAAA,SAAqBJ;AAArBI,cAEIC,iBAFiBL,EAAAA,MAAAA,EAAgB;AAEtD;AAEyBI,kBAAAA,YAAAA,CAAY;EAAA;;;EA8DkB,OAAjCG,UAAAA,QAAAA,CAAAA;IAhBYH;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["BaseContentBlock","Tools","Multimodal","Data","ContentBlock","KNOWN_BLOCK_TYPES","Citation","Array","Record","TValue","Text","Reasoning","NonStandard","Standard"],"sources":["../../../src/messages/content/index.d.ts"],"sourcesContent":["import type { BaseContentBlock } from \"./base.js\";\nimport { type Tools } from \"./tools.js\";\nimport { type Multimodal } from \"./multimodal.js\";\nimport { type Data } from \"./data.js\";\nexport interface ContentBlock extends BaseContentBlock {\n}\nexport declare const KNOWN_BLOCK_TYPES: string[];\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport declare namespace ContentBlock {\n /**\n * Annotation for citing data from a document.\n */\n export interface Citation {\n /**\n * Type of the content block\n */\n readonly type: \"citation\";\n /**\n * Source type for the citation.\n */\n source?: string;\n /**\n * URL of the document source\n */\n url?: string;\n /**\n * Source document title.\n *\n * For example, the page title for a web page or the title of a paper.\n */\n title?: string;\n /**\n * Start index of the **response text** for which the annotation applies.\n *\n * @see {Text}\n */\n startIndex?: number;\n /**\n * End index of the **response text** for which the annotation applies.\n *\n * @see {Text}\n */\n endIndex?: number;\n /**\n * Excerpt of source text being cited.\n */\n citedText?: string;\n }\n /**\n * Text output from a LLM.\n *\n * This typically represents the main text content of a message, such as the response\n * from a language model or the text of a user message.\n */\n export interface Text extends ContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"text\";\n /**\n * Block text.\n */\n text: string;\n /**\n * Index of block in aggregate response. Used during streaming.\n */\n index?: number;\n /**\n * Citations and other annotations.\n */\n annotations?: Array<Citation | BaseContentBlock>;\n }\n /**\n * Reasoning output from a LLM.\n */\n export interface Reasoning extends ContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"reasoning\";\n /**\n * Reasoning text.\n *\n * Either the thought summary or the raw reasoning text itself.\n * This is often parsed from `<think>` tags in the model's response.\n */\n reasoning: string;\n /**\n * Index of block in aggregate response. Used during streaming.\n */\n index?: number;\n }\n /**\n * Provider-specific content block.\n *\n * This is used to represent content blocks that are not part of the standard LangChain content model.\n * If a provider's non-standard output includes reasoning and tool calls, it should be\n * the adapter's job to parse that payload and emit the corresponding standard reasoning and tool call blocks.\n */\n export interface NonStandard<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TValue extends Record<string, any> = Record<string, any>> extends ContentBlock {\n /**\n * Type of the content block\n */\n type: \"non_standard\";\n /**\n * Provider-specific data\n */\n value: TValue;\n }\n export { Tools };\n export { Multimodal };\n export { Data };\n export type Standard = Text | Reasoning | NonStandard | Tools.Standard | Multimodal.Standard;\n}\n"],"mappings":";;;;;;UAIiBI,YAAAA,SAAqBJ;AAArBI,cAEIC,iBAFiBL,EAAAA,MAAAA,EAAgB;AAEtD;AAEyBI,kBAAAA,YAAAA,CAAY;EAAA;;;EA8DkB,OAAjCG,UAAAA,QAAAA,CAAAA;IAhBYH;;;IA+COI,SAAAA,IAAAA,EAAAA,UAAAA;IAQ1BC;;;IAGFP,MAAAA,CAAAA,EAAAA,MAAAA;IACAC;;;IACiCS,GAAAA,CAAAA,EAAAA,MAAAA;IAAcX;;AAAoC;;;;;;;;;;;;;;;;;;;;;;;;;;;gCA5D9DG;;;;;;;;;;;;;;;;kBAgBZG,MAAMD,WAAWN;;;;;qCAKAI;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0BpBI,sBAAsBA,6BAA6BJ;;;;;;;;WAQvDK;;WAEFR;WACAC;WACAC;yBACcO,OAAOC,YAAYC,cAAcX,KAAAA,CAAMY,WAAWX,UAAAA,CAAWW"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["KNOWN_BLOCK_TYPES","KNOWN_TOOL_BLOCK_TYPES","KNOWN_MULTIMODAL_BLOCK_TYPES"],"sources":["../../../src/messages/content/index.ts"],"sourcesContent":["import type { BaseContentBlock } from \"./base.js\";\nimport {\n KNOWN_BLOCK_TYPES as KNOWN_TOOL_BLOCK_TYPES,\n type Tools,\n} from \"./tools.js\";\nimport {\n KNOWN_BLOCK_TYPES as KNOWN_MULTIMODAL_BLOCK_TYPES,\n type Multimodal,\n} from \"./multimodal.js\";\nimport { type Data } from \"./data.js\";\n\nexport interface ContentBlock extends BaseContentBlock {}\n\nexport const KNOWN_BLOCK_TYPES = [\n \"text\",\n \"reasoning\",\n ...KNOWN_TOOL_BLOCK_TYPES,\n ...KNOWN_MULTIMODAL_BLOCK_TYPES,\n];\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport declare namespace ContentBlock {\n /**\n * Annotation for citing data from a document.\n */\n export interface Citation {\n /**\n * Type of the content block\n */\n readonly type: \"citation\";\n /**\n * Source type for the citation.\n */\n source?: string;\n /**\n * URL of the document source\n */\n url?: string;\n /**\n * Source document title.\n *\n * For example, the page title for a web page or the title of a paper.\n */\n title?: string;\n /**\n * Start index of the **response text** for which the annotation applies.\n *\n * @see {Text}\n */\n startIndex?: number;\n /**\n * End index of the **response text** for which the annotation applies.\n *\n * @see {Text}\n */\n endIndex?: number;\n /**\n * Excerpt of source text being cited.\n */\n citedText?: string;\n }\n\n /**\n * Text output from a LLM.\n *\n * This typically represents the main text content of a message, such as the response\n * from a language model or the text of a user message.\n */\n export interface Text extends ContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"text\";\n /**\n * Block text.\n */\n text: string;\n /**\n * Index of block in aggregate response. Used during streaming.\n */\n index?: number;\n /**\n * Citations and other annotations.\n */\n annotations?: Array<Citation | BaseContentBlock>;\n }\n\n /**\n * Reasoning output from a LLM.\n */\n export interface Reasoning extends ContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"reasoning\";\n /**\n * Reasoning text.\n *\n * Either the thought summary or the raw reasoning text itself.\n * This is often parsed from `<think>` tags in the model's response.\n */\n reasoning: string;\n /**\n * Index of block in aggregate response. Used during streaming.\n */\n index?: number;\n }\n\n export { Tools };\n export { Multimodal };\n export { Data };\n\n export type Standard =\n | Text\n | Reasoning\n | Tools.Standard\n | Multimodal.Standard;\n}\n"],"mappings":";;;;AAaA,MAAaA,sBAAoB;CAC/B;CACA;CACA,GAAGC;CACH,GAAGC;AACJ"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["KNOWN_BLOCK_TYPES","KNOWN_TOOL_BLOCK_TYPES","KNOWN_MULTIMODAL_BLOCK_TYPES"],"sources":["../../../src/messages/content/index.ts"],"sourcesContent":["import type { BaseContentBlock } from \"./base.js\";\nimport {\n KNOWN_BLOCK_TYPES as KNOWN_TOOL_BLOCK_TYPES,\n type Tools,\n} from \"./tools.js\";\nimport {\n KNOWN_BLOCK_TYPES as KNOWN_MULTIMODAL_BLOCK_TYPES,\n type Multimodal,\n} from \"./multimodal.js\";\nimport { type Data } from \"./data.js\";\n\nexport interface ContentBlock extends BaseContentBlock {}\n\nexport const KNOWN_BLOCK_TYPES = [\n \"text\",\n \"reasoning\",\n ...KNOWN_TOOL_BLOCK_TYPES,\n ...KNOWN_MULTIMODAL_BLOCK_TYPES,\n];\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport declare namespace ContentBlock {\n /**\n * Annotation for citing data from a document.\n */\n export interface Citation {\n /**\n * Type of the content block\n */\n readonly type: \"citation\";\n /**\n * Source type for the citation.\n */\n source?: string;\n /**\n * URL of the document source\n */\n url?: string;\n /**\n * Source document title.\n *\n * For example, the page title for a web page or the title of a paper.\n */\n title?: string;\n /**\n * Start index of the **response text** for which the annotation applies.\n *\n * @see {Text}\n */\n startIndex?: number;\n /**\n * End index of the **response text** for which the annotation applies.\n *\n * @see {Text}\n */\n endIndex?: number;\n /**\n * Excerpt of source text being cited.\n */\n citedText?: string;\n }\n\n /**\n * Text output from a LLM.\n *\n * This typically represents the main text content of a message, such as the response\n * from a language model or the text of a user message.\n */\n export interface Text extends ContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"text\";\n /**\n * Block text.\n */\n text: string;\n /**\n * Index of block in aggregate response. Used during streaming.\n */\n index?: number;\n /**\n * Citations and other annotations.\n */\n annotations?: Array<Citation | BaseContentBlock>;\n }\n\n /**\n * Reasoning output from a LLM.\n */\n export interface Reasoning extends ContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"reasoning\";\n /**\n * Reasoning text.\n *\n * Either the thought summary or the raw reasoning text itself.\n * This is often parsed from `<think>` tags in the model's response.\n */\n reasoning: string;\n /**\n * Index of block in aggregate response. Used during streaming.\n */\n index?: number;\n }\n\n /**\n * Provider-specific content block.\n *\n * This is used to represent content blocks that are not part of the standard LangChain content model.\n * If a provider's non-standard output includes reasoning and tool calls, it should be\n * the adapter's job to parse that payload and emit the corresponding standard reasoning and tool call blocks.\n */\n export interface NonStandard<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TValue extends Record<string, any> = Record<string, any>\n > extends ContentBlock {\n /**\n * Type of the content block\n */\n type: \"non_standard\";\n /**\n * Provider-specific data\n */\n value: TValue;\n }\n\n export { Tools };\n export { Multimodal };\n export { Data };\n\n export type Standard =\n | Text\n | Reasoning\n | NonStandard\n | Tools.Standard\n | Multimodal.Standard;\n}\n"],"mappings":";;;;AAaA,MAAaA,sBAAoB;CAC/B;CACA;CACA,GAAGC;CACH,GAAGC;AACJ"}
|
|
@@ -4,10 +4,9 @@ const KNOWN_BLOCK_TYPES = [
|
|
|
4
4
|
"tool_call",
|
|
5
5
|
"tool_call_chunk",
|
|
6
6
|
"invalid_tool_call",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"code_interpreter_result"
|
|
7
|
+
"server_tool_call",
|
|
8
|
+
"server_tool_call_chunk",
|
|
9
|
+
"server_tool_call_result"
|
|
11
10
|
];
|
|
12
11
|
|
|
13
12
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.cjs","names":[],"sources":["../../../src/messages/content/tools.ts"],"sourcesContent":["import { BaseContentBlock } from \"./base.js\";\n\nexport type Tools = never;\n\nexport const KNOWN_BLOCK_TYPES = [\n \"tool_call\",\n \"tool_call_chunk\",\n \"invalid_tool_call\",\n \"
|
|
1
|
+
{"version":3,"file":"tools.cjs","names":[],"sources":["../../../src/messages/content/tools.ts"],"sourcesContent":["import { BaseContentBlock } from \"./base.js\";\n\nexport type Tools = never;\n\nexport const KNOWN_BLOCK_TYPES = [\n \"tool_call\",\n \"tool_call_chunk\",\n \"invalid_tool_call\",\n \"server_tool_call\",\n \"server_tool_call_chunk\",\n \"server_tool_call_result\",\n];\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport declare namespace Tools {\n /**\n * Represents a request to call a tool.\n *\n * @example\n * ```ts\n * const toolCall: ToolCall = {\n * type: \"tool_call\",\n * name: \"foo\",\n * args: { a: 1 },\n * callId: \"123\"\n * };\n * ```\n * This represents a request to call the tool named \"foo\" with arguments {\"a\": 1}\n * and an identifier of \"123\".\n */\n export interface ToolCall<TName extends string = string, TArgs = unknown>\n extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"tool_call\";\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n }\n\n /** Content block to represent partial data of a tool call */\n export interface ToolCallChunk<TName extends string = string>\n extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"tool_call_chunk\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * The index of the tool call chunk\n */\n index?: number;\n }\n\n /** Content block to represent an invalid tool call */\n export interface InvalidToolCall<TName extends string = string>\n extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"invalid_tool_call\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * An error message associated with the tool call\n */\n error?: string;\n /**\n * Index of block in aggregate response\n */\n index?: string | number;\n }\n\n export interface ServerToolCall<\n TName extends string = string,\n TArgs = unknown\n > extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"server_tool_call\";\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n }\n\n export interface ServerToolCallChunk<TName extends string = string>\n extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"server_tool_call_chunk\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n }\n\n export interface ServerToolCallResult<TOutput = Record<string, unknown>>\n extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"server_tool_call_result\";\n /**\n * The unique identifier of the tool call that this result corresponds to\n */\n toolCallId: string;\n /**\n * The status of the server tool call\n */\n status: \"success\" | \"error\";\n /**\n * The output of the server tool call\n */\n output: TOutput;\n }\n\n export type Standard =\n | ToolCall\n | ToolCallChunk\n | InvalidToolCall\n | ServerToolCall\n | ServerToolCallChunk\n | ServerToolCallResult;\n}\n"],"mappings":";;AAIA,MAAa,oBAAoB;CAC/B;CACA;CACA;CACA;CACA;CACA;AACD"}
|
|
@@ -75,76 +75,53 @@ declare namespace Tools {
|
|
|
75
75
|
*/
|
|
76
76
|
index?: string | number;
|
|
77
77
|
}
|
|
78
|
-
|
|
79
|
-
interface WebSearchCall extends BaseContentBlock {
|
|
78
|
+
interface ServerToolCall<TName extends string = string, TArgs = unknown> extends BaseContentBlock {
|
|
80
79
|
/**
|
|
81
80
|
* Type of the content block
|
|
82
81
|
*/
|
|
83
|
-
readonly type: "
|
|
82
|
+
readonly type: "server_tool_call";
|
|
84
83
|
/**
|
|
85
|
-
* The
|
|
86
|
-
*/
|
|
87
|
-
query?: string;
|
|
88
|
-
}
|
|
89
|
-
/** Content block for the result of a built-in search tool call */
|
|
90
|
-
interface WebSearchResult extends BaseContentBlock {
|
|
91
|
-
/**
|
|
92
|
-
* Type of the content block
|
|
84
|
+
* The name of the tool being called
|
|
93
85
|
*/
|
|
94
|
-
|
|
86
|
+
name: TName;
|
|
95
87
|
/**
|
|
96
|
-
*
|
|
88
|
+
* The arguments to the tool call
|
|
97
89
|
*/
|
|
98
|
-
|
|
90
|
+
args: TArgs;
|
|
99
91
|
}
|
|
100
|
-
|
|
101
|
-
interface CodeInterpreterCall extends BaseContentBlock {
|
|
92
|
+
interface ServerToolCallChunk<TName extends string = string> extends BaseContentBlock {
|
|
102
93
|
/**
|
|
103
94
|
* Type of the content block
|
|
104
95
|
*/
|
|
105
|
-
readonly type: "
|
|
96
|
+
readonly type: "server_tool_call_chunk";
|
|
106
97
|
/**
|
|
107
|
-
* The
|
|
98
|
+
* The name of the tool being called
|
|
108
99
|
*/
|
|
109
|
-
|
|
100
|
+
name?: TName;
|
|
110
101
|
/**
|
|
111
|
-
* The
|
|
102
|
+
* The arguments to the tool call
|
|
112
103
|
*/
|
|
113
|
-
|
|
104
|
+
args?: string;
|
|
114
105
|
}
|
|
115
|
-
|
|
116
|
-
interface CodeInterpreterOutput {
|
|
117
|
-
readonly type: "code_interpreter_output";
|
|
106
|
+
interface ServerToolCallResult<TOutput = Record<string, unknown>> extends BaseContentBlock {
|
|
118
107
|
/**
|
|
119
|
-
*
|
|
120
|
-
* Example: 0 for success, non-zero for failure
|
|
121
|
-
*/
|
|
122
|
-
returnCode?: number;
|
|
123
|
-
/**
|
|
124
|
-
* Standard error output of the executed code
|
|
125
|
-
*/
|
|
126
|
-
stderr?: string;
|
|
127
|
-
/**
|
|
128
|
-
* Standard output of the executed code
|
|
108
|
+
* Type of the content block
|
|
129
109
|
*/
|
|
130
|
-
|
|
110
|
+
readonly type: "server_tool_call_result";
|
|
131
111
|
/**
|
|
132
|
-
*
|
|
112
|
+
* The unique identifier of the tool call that this result corresponds to
|
|
133
113
|
*/
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
/** Content block for the result of a code interpreter tool call */
|
|
137
|
-
interface CodeInterpreterResult extends BaseContentBlock {
|
|
114
|
+
toolCallId: string;
|
|
138
115
|
/**
|
|
139
|
-
*
|
|
116
|
+
* The status of the server tool call
|
|
140
117
|
*/
|
|
141
|
-
|
|
118
|
+
status: "success" | "error";
|
|
142
119
|
/**
|
|
143
|
-
* The
|
|
120
|
+
* The output of the server tool call
|
|
144
121
|
*/
|
|
145
|
-
output:
|
|
122
|
+
output: TOutput;
|
|
146
123
|
}
|
|
147
|
-
type Standard = ToolCall | ToolCallChunk | InvalidToolCall |
|
|
124
|
+
type Standard = ToolCall | ToolCallChunk | InvalidToolCall | ServerToolCall | ServerToolCallChunk | ServerToolCallResult;
|
|
148
125
|
}
|
|
149
126
|
//#endregion
|
|
150
127
|
export { Tools };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.cts","names":["BaseContentBlock","Tools","KNOWN_BLOCK_TYPES","TName","TArgs","
|
|
1
|
+
{"version":3,"file":"tools.d.cts","names":["BaseContentBlock","Tools","KNOWN_BLOCK_TYPES","TName","TArgs","Record","TOutput","ToolCall","ToolCallChunk","InvalidToolCall","ServerToolCall","ServerToolCallChunk","ServerToolCallResult"],"sources":["../../../src/messages/content/tools.d.ts"],"sourcesContent":["import { BaseContentBlock } from \"./base.js\";\nexport type Tools = never;\nexport declare const KNOWN_BLOCK_TYPES: string[];\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport declare namespace Tools {\n /**\n * Represents a request to call a tool.\n *\n * @example\n * ```ts\n * const toolCall: ToolCall = {\n * type: \"tool_call\",\n * name: \"foo\",\n * args: { a: 1 },\n * callId: \"123\"\n * };\n * ```\n * This represents a request to call the tool named \"foo\" with arguments {\"a\": 1}\n * and an identifier of \"123\".\n */\n interface ToolCall<TName extends string = string, TArgs = unknown> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"tool_call\";\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n }\n /** Content block to represent partial data of a tool call */\n interface ToolCallChunk<TName extends string = string> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"tool_call_chunk\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * The index of the tool call chunk\n */\n index?: number;\n }\n /** Content block to represent an invalid tool call */\n interface InvalidToolCall<TName extends string = string> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"invalid_tool_call\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * An error message associated with the tool call\n */\n error?: string;\n /**\n * Index of block in aggregate response\n */\n index?: string | number;\n }\n interface ServerToolCall<TName extends string = string, TArgs = unknown> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"server_tool_call\";\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n }\n interface ServerToolCallChunk<TName extends string = string> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"server_tool_call_chunk\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n }\n interface ServerToolCallResult<TOutput = Record<string, unknown>> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"server_tool_call_result\";\n /**\n * The unique identifier of the tool call that this result corresponds to\n */\n toolCallId: string;\n /**\n * The status of the server tool call\n */\n status: \"success\" | \"error\";\n /**\n * The output of the server tool call\n */\n output: TOutput;\n }\n type Standard = ToolCall | ToolCallChunk | InvalidToolCall | ServerToolCall | ServerToolCallChunk | ServerToolCallResult;\n}\n"],"mappings":";;;KACYC,KAAAA;AAAZ;AAGyBA,kBAAAA,KAAAA,CAAK;EAAA;;;;;;;;;;;;;;;EAoHP,UAhBuDD,QAAAA,CAAAA,cAAAA,MAAAA,GAAAA,MAAAA,EAAAA,QAAAA,OAAAA,CAAAA,SApFCA,gBAoFDA,CAAAA;IAkB1DO;;;IAA6CG,SAAAA,IAAAA,EAAAA,WAAAA;IAAiBC;;AAA0C;UA9F9GR;;;;UAIAC;;;iEAGqDJ;;;;;;;;WAQpDG;;;;;;;;;;;mEAWsDH;;;;;;;;WAQtDG;;;;;;;;;;;;;;mFAcsEH;;;;;;;;UAQvEG;;;;UAIAC;;uEAE2DJ;;;;;;;;WAQ1DG;;;;;;2CAM8BE,iCAAiCL;;;;;;;;;;;;;;;;YAgB9DM;;kBAEIC,WAAWC,gBAAgBC,kBAAkBC,iBAAiBC,sBAAsBC"}
|
|
@@ -75,76 +75,53 @@ declare namespace Tools {
|
|
|
75
75
|
*/
|
|
76
76
|
index?: string | number;
|
|
77
77
|
}
|
|
78
|
-
|
|
79
|
-
interface WebSearchCall extends BaseContentBlock {
|
|
78
|
+
interface ServerToolCall<TName extends string = string, TArgs = unknown> extends BaseContentBlock {
|
|
80
79
|
/**
|
|
81
80
|
* Type of the content block
|
|
82
81
|
*/
|
|
83
|
-
readonly type: "
|
|
82
|
+
readonly type: "server_tool_call";
|
|
84
83
|
/**
|
|
85
|
-
* The
|
|
86
|
-
*/
|
|
87
|
-
query?: string;
|
|
88
|
-
}
|
|
89
|
-
/** Content block for the result of a built-in search tool call */
|
|
90
|
-
interface WebSearchResult extends BaseContentBlock {
|
|
91
|
-
/**
|
|
92
|
-
* Type of the content block
|
|
84
|
+
* The name of the tool being called
|
|
93
85
|
*/
|
|
94
|
-
|
|
86
|
+
name: TName;
|
|
95
87
|
/**
|
|
96
|
-
*
|
|
88
|
+
* The arguments to the tool call
|
|
97
89
|
*/
|
|
98
|
-
|
|
90
|
+
args: TArgs;
|
|
99
91
|
}
|
|
100
|
-
|
|
101
|
-
interface CodeInterpreterCall extends BaseContentBlock {
|
|
92
|
+
interface ServerToolCallChunk<TName extends string = string> extends BaseContentBlock {
|
|
102
93
|
/**
|
|
103
94
|
* Type of the content block
|
|
104
95
|
*/
|
|
105
|
-
readonly type: "
|
|
96
|
+
readonly type: "server_tool_call_chunk";
|
|
106
97
|
/**
|
|
107
|
-
* The
|
|
98
|
+
* The name of the tool being called
|
|
108
99
|
*/
|
|
109
|
-
|
|
100
|
+
name?: TName;
|
|
110
101
|
/**
|
|
111
|
-
* The
|
|
102
|
+
* The arguments to the tool call
|
|
112
103
|
*/
|
|
113
|
-
|
|
104
|
+
args?: string;
|
|
114
105
|
}
|
|
115
|
-
|
|
116
|
-
interface CodeInterpreterOutput {
|
|
117
|
-
readonly type: "code_interpreter_output";
|
|
106
|
+
interface ServerToolCallResult<TOutput = Record<string, unknown>> extends BaseContentBlock {
|
|
118
107
|
/**
|
|
119
|
-
*
|
|
120
|
-
* Example: 0 for success, non-zero for failure
|
|
121
|
-
*/
|
|
122
|
-
returnCode?: number;
|
|
123
|
-
/**
|
|
124
|
-
* Standard error output of the executed code
|
|
125
|
-
*/
|
|
126
|
-
stderr?: string;
|
|
127
|
-
/**
|
|
128
|
-
* Standard output of the executed code
|
|
108
|
+
* Type of the content block
|
|
129
109
|
*/
|
|
130
|
-
|
|
110
|
+
readonly type: "server_tool_call_result";
|
|
131
111
|
/**
|
|
132
|
-
*
|
|
112
|
+
* The unique identifier of the tool call that this result corresponds to
|
|
133
113
|
*/
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
/** Content block for the result of a code interpreter tool call */
|
|
137
|
-
interface CodeInterpreterResult extends BaseContentBlock {
|
|
114
|
+
toolCallId: string;
|
|
138
115
|
/**
|
|
139
|
-
*
|
|
116
|
+
* The status of the server tool call
|
|
140
117
|
*/
|
|
141
|
-
|
|
118
|
+
status: "success" | "error";
|
|
142
119
|
/**
|
|
143
|
-
* The
|
|
120
|
+
* The output of the server tool call
|
|
144
121
|
*/
|
|
145
|
-
output:
|
|
122
|
+
output: TOutput;
|
|
146
123
|
}
|
|
147
|
-
type Standard = ToolCall | ToolCallChunk | InvalidToolCall |
|
|
124
|
+
type Standard = ToolCall | ToolCallChunk | InvalidToolCall | ServerToolCall | ServerToolCallChunk | ServerToolCallResult;
|
|
148
125
|
}
|
|
149
126
|
//#endregion
|
|
150
127
|
export { Tools };
|