UNPKG

@langchain/core

Version:
1 lines 22.7 kB
{"version":3,"file":"anthropic.cjs","names":["citation: ContentBlock","_isString","_isNumber","block: ContentBlock","_isContentBlock","_isObject","content: Array<ContentBlock>","message: AIMessage","_isArray","iife","safeParseJson","content","ChatAnthropicTranslator: StandardContentBlockTranslator","message: unknown"],"sources":["../../../src/messages/block_translators/anthropic.ts"],"sourcesContent":["import type { StandardContentBlockTranslator } from \"./index.js\";\nimport type { ContentBlock } from \"../content/index.js\";\nimport type { AIMessageChunk, AIMessage } from \"../ai.js\";\nimport type { BaseMessage, BaseMessageChunk } from \"../base.js\";\nimport {\n _isArray,\n _isContentBlock,\n _isNumber,\n _isObject,\n _isString,\n safeParseJson,\n iife,\n} from \"./utils.js\";\n\nfunction convertAnthropicAnnotation(\n citation: ContentBlock\n): ContentBlock.Citation | undefined {\n if (\n citation.type === \"char_location\" &&\n _isString(citation.document_title) &&\n _isNumber(citation.start_char_index) &&\n _isNumber(citation.end_char_index) &&\n _isString(citation.cited_text)\n ) {\n const {\n document_title,\n start_char_index,\n end_char_index,\n cited_text,\n ...rest\n } = citation;\n return {\n ...rest,\n type: \"citation\",\n source: \"char\",\n title: document_title ?? undefined,\n startIndex: start_char_index,\n endIndex: end_char_index,\n citedText: cited_text,\n };\n }\n if (\n citation.type === \"page_location\" &&\n _isString(citation.document_title) &&\n _isNumber(citation.start_page_number) &&\n _isNumber(citation.end_page_number) &&\n _isString(citation.cited_text)\n ) {\n const {\n document_title,\n start_page_number,\n end_page_number,\n cited_text,\n ...rest\n } = citation;\n return {\n ...rest,\n type: \"citation\",\n source: \"page\",\n title: document_title ?? undefined,\n startIndex: start_page_number,\n endIndex: end_page_number,\n citedText: cited_text,\n };\n }\n if (\n citation.type === \"content_block_location\" &&\n _isString(citation.document_title) &&\n _isNumber(citation.start_block_index) &&\n _isNumber(citation.end_block_index) &&\n _isString(citation.cited_text)\n ) {\n const {\n document_title,\n start_block_index,\n end_block_index,\n cited_text,\n ...rest\n } = citation;\n return {\n ...rest,\n type: \"citation\",\n source: \"block\",\n title: document_title ?? undefined,\n startIndex: start_block_index,\n endIndex: end_block_index,\n citedText: cited_text,\n };\n }\n if (\n citation.type === \"web_search_result_location\" &&\n _isString(citation.url) &&\n _isString(citation.title) &&\n _isString(citation.encrypted_index) &&\n _isString(citation.cited_text)\n ) {\n const { url, title, encrypted_index, cited_text, ...rest } = citation;\n return {\n ...rest,\n type: \"citation\",\n source: \"url\",\n url,\n title,\n startIndex: Number(encrypted_index),\n endIndex: Number(encrypted_index),\n citedText: cited_text,\n };\n }\n if (\n citation.type === \"search_result_location\" &&\n _isString(citation.source) &&\n _isString(citation.title) &&\n _isNumber(citation.start_block_index) &&\n _isNumber(citation.end_block_index) &&\n _isString(citation.cited_text)\n ) {\n const {\n source,\n title,\n start_block_index,\n end_block_index,\n cited_text,\n ...rest\n } = citation;\n return {\n ...rest,\n type: \"citation\",\n source: \"search\",\n url: source,\n title: title ?? undefined,\n startIndex: start_block_index,\n endIndex: end_block_index,\n citedText: cited_text,\n };\n }\n return undefined;\n}\n\n/**\n * Converts an Anthropic content block to a standard V1 content block.\n *\n * This function handles the conversion of Anthropic-specific content blocks\n * (document and image blocks) to the standardized V1 format. It supports\n * various source types including base64 data, URLs, file IDs, and text data.\n *\n * @param block - The Anthropic content block to convert\n * @returns A standard V1 content block if conversion is successful, undefined otherwise\n *\n * @example\n * ```typescript\n * const anthropicBlock = {\n * type: \"image\",\n * source: {\n * type: \"base64\",\n * media_type: \"image/png\",\n * data: \"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==\"\n * }\n * };\n *\n * const standardBlock = convertToV1FromAnthropicContentBlock(anthropicBlock);\n * // Returns: { type: \"image\", mimeType: \"image/png\", data: \"...\" }\n * ```\n */\nexport function convertToV1FromAnthropicContentBlock(\n block: ContentBlock\n): ContentBlock.Standard | undefined {\n if (\n _isContentBlock(block, \"document\") &&\n _isObject(block.source) &&\n \"type\" in block.source\n ) {\n if (\n block.source.type === \"base64\" &&\n _isString(block.source.media_type) &&\n _isString(block.source.data)\n ) {\n return {\n type: \"file\",\n mimeType: block.source.media_type,\n data: block.source.data,\n };\n } else if (block.source.type === \"url\" && _isString(block.source.url)) {\n return {\n type: \"file\",\n url: block.source.url,\n };\n } else if (\n block.source.type === \"file\" &&\n _isString(block.source.file_id)\n ) {\n return {\n type: \"file\",\n fileId: block.source.file_id,\n };\n } else if (block.source.type === \"text\" && _isString(block.source.data)) {\n return {\n type: \"file\",\n mimeType: String(block.source.media_type ?? \"text/plain\"),\n data: block.source.data,\n };\n }\n } else if (\n _isContentBlock(block, \"image\") &&\n _isObject(block.source) &&\n \"type\" in block.source\n ) {\n if (\n block.source.type === \"base64\" &&\n _isString(block.source.media_type) &&\n _isString(block.source.data)\n ) {\n return {\n type: \"image\",\n mimeType: block.source.media_type,\n data: block.source.data,\n };\n } else if (block.source.type === \"url\" && _isString(block.source.url)) {\n return {\n type: \"image\",\n url: block.source.url,\n };\n } else if (\n block.source.type === \"file\" &&\n _isString(block.source.file_id)\n ) {\n return {\n type: \"image\",\n fileId: block.source.file_id,\n };\n }\n }\n return undefined;\n}\n\n/**\n * Converts an array of content blocks from Anthropic format to v1 standard format.\n *\n * This function processes each content block in the input array, attempting to convert\n * Anthropic-specific block formats (like image blocks with source objects, document blocks, etc.)\n * to the standardized v1 content block format. If a block cannot be converted, it is\n * passed through as-is with a type assertion to ContentBlock.Standard.\n *\n * @param content - Array of content blocks in Anthropic format to be converted\n * @returns Array of content blocks in v1 standard format\n */\nexport function convertToV1FromAnthropicInput(\n content: Array<ContentBlock>\n): Array<ContentBlock.Standard> {\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n for (const block of content) {\n const stdBlock = convertToV1FromAnthropicContentBlock(block);\n if (stdBlock) {\n yield stdBlock;\n } else {\n yield block as ContentBlock.Standard;\n }\n }\n }\n return Array.from(iterateContent());\n}\n\n/**\n * Converts an Anthropic AI message to an array of v1 standard content blocks.\n *\n * This function processes an AI message containing Anthropic-specific content blocks\n * and converts them to the standardized v1 content block format.\n *\n * @param message - The AI message containing Anthropic-formatted content blocks\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const message = new AIMessage([\n * { type: \"text\", text: \"Hello world\" },\n * { type: \"thinking\", text: \"Let me think about this...\" },\n * { type: \"tool_use\", id: \"123\", name: \"calculator\", input: { a: 1, b: 2 } }\n * ]);\n *\n * const standardBlocks = convertToV1FromAnthropicMessage(message);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Hello world\" },\n * // { type: \"reasoning\", reasoning: \"Let me think about this...\" },\n * // { type: \"tool_call\", id: \"123\", name: \"calculator\", args: { a: 1, b: 2 } }\n * // ]\n * ```\n */\nexport function convertToV1FromAnthropicMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n const content =\n typeof message.content === \"string\"\n ? [{ type: \"text\", text: message.content }]\n : message.content;\n for (const block of content) {\n // TextBlock\n if (_isContentBlock(block, \"text\") && _isString(block.text)) {\n const { text, citations, ...rest } = block;\n if (_isArray(citations) && citations.length) {\n const _citations = citations.reduce<ContentBlock.Citation[]>(\n (acc, item) => {\n const citation = convertAnthropicAnnotation(item as ContentBlock);\n if (citation) {\n return [...acc, citation];\n }\n return acc;\n },\n []\n );\n yield {\n ...rest,\n type: \"text\",\n text,\n annotations: _citations,\n };\n continue;\n } else {\n yield {\n ...rest,\n type: \"text\",\n text,\n };\n continue;\n }\n }\n // ThinkingBlock\n else if (\n _isContentBlock(block, \"thinking\") &&\n _isString(block.thinking)\n ) {\n const { thinking, signature, ...rest } = block;\n yield {\n ...rest,\n type: \"reasoning\",\n reasoning: thinking,\n signature,\n };\n continue;\n }\n // RedactedThinkingBlock\n else if (_isContentBlock(block, \"redacted_thinking\")) {\n yield { type: \"non_standard\", value: block };\n continue;\n }\n // ToolUseBlock\n else if (\n _isContentBlock(block, \"tool_use\") &&\n _isString(block.name) &&\n _isString(block.id)\n ) {\n yield {\n type: \"tool_call\",\n id: block.id,\n name: block.name,\n args: block.input,\n };\n continue;\n }\n // message chunks can have input_json_delta contents\n else if (_isContentBlock(block, \"input_json_delta\")) {\n if (_isAIMessageChunk(message) && message.tool_call_chunks?.length) {\n const tool_call_chunk = message.tool_call_chunks[0];\n yield {\n type: \"tool_call_chunk\",\n id: tool_call_chunk.id,\n name: tool_call_chunk.name,\n args: tool_call_chunk.args,\n index: tool_call_chunk.index,\n };\n continue;\n }\n }\n // ServerToolUseBlock\n else if (\n _isContentBlock(block, \"server_tool_use\") &&\n _isString(block.name) &&\n _isString(block.id)\n ) {\n const { name, id } = block;\n if (name === \"web_search\") {\n const query = iife(() => {\n if (typeof block.input === \"string\") {\n return block.input;\n } else if (_isObject(block.input) && _isString(block.input.query)) {\n return block.input.query;\n } else if (_isString(block.partial_json)) {\n const json = safeParseJson<{ query?: string }>(\n block.partial_json\n );\n if (json?.query) {\n return json.query;\n }\n }\n return \"\";\n });\n yield {\n id,\n type: \"server_tool_call\",\n name: \"web_search\",\n args: { query },\n };\n continue;\n } else if (block.name === \"code_execution\") {\n const code = iife(() => {\n if (typeof block.input === \"string\") {\n return block.input;\n } else if (_isObject(block.input) && _isString(block.input.code)) {\n return block.input.code;\n } else if (_isString(block.partial_json)) {\n const json = safeParseJson<{ code?: string }>(block.partial_json);\n if (json?.code) {\n return json.code;\n }\n }\n return \"\";\n });\n yield {\n id,\n type: \"server_tool_call\",\n name: \"code_execution\",\n args: { code },\n };\n continue;\n }\n }\n // WebSearchToolResultBlock\n else if (\n _isContentBlock(block, \"web_search_tool_result\") &&\n _isString(block.tool_use_id) &&\n _isArray(block.content)\n ) {\n const { content, tool_use_id } = block;\n const urls = content.reduce<string[]>((acc, content) => {\n if (_isContentBlock(content, \"web_search_result\")) {\n return [...acc, content.url as string];\n }\n return acc;\n }, []);\n yield {\n type: \"server_tool_call_result\",\n name: \"web_search\",\n toolCallId: tool_use_id,\n status: \"success\",\n output: {\n urls,\n },\n };\n continue;\n }\n // CodeExecutionToolResultBlock\n else if (\n _isContentBlock(block, \"code_execution_tool_result\") &&\n _isString(block.tool_use_id) &&\n _isObject(block.content)\n ) {\n yield {\n type: \"server_tool_call_result\",\n name: \"code_execution\",\n toolCallId: block.tool_use_id,\n status: \"success\",\n output: block.content,\n };\n continue;\n }\n // MCPToolUseBlock\n else if (_isContentBlock(block, \"mcp_tool_use\")) {\n yield {\n id: block.id,\n type: \"server_tool_call\",\n name: \"mcp_tool_use\",\n args: block.input,\n };\n continue;\n }\n // MCPToolResultBlock\n else if (\n _isContentBlock(block, \"mcp_tool_result\") &&\n _isString(block.tool_use_id) &&\n _isObject(block.content)\n ) {\n yield {\n type: \"server_tool_call_result\",\n name: \"mcp_tool_use\",\n toolCallId: block.tool_use_id,\n status: \"success\",\n output: block.content,\n };\n continue;\n }\n // ContainerUploadBlock\n else if (_isContentBlock(block, \"container_upload\")) {\n yield {\n type: \"server_tool_call\",\n name: \"container_upload\",\n args: block.input,\n };\n continue;\n }\n // SearchResultBlockParam\n else if (_isContentBlock(block, \"search_result\")) {\n yield { id: block.id, type: \"non_standard\", value: block };\n continue;\n }\n // ToolResultBlockParam\n else if (_isContentBlock(block, \"tool_result\")) {\n yield { id: block.id, type: \"non_standard\", value: block };\n continue;\n } else {\n // For all other blocks, we try to convert them to a standard block\n const stdBlock = convertToV1FromAnthropicContentBlock(block);\n if (stdBlock) {\n yield stdBlock;\n continue;\n }\n }\n yield { type: \"non_standard\", value: block };\n }\n }\n return Array.from(iterateContent());\n}\n\nexport const ChatAnthropicTranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromAnthropicMessage,\n translateContentChunk: convertToV1FromAnthropicMessage,\n};\n\nfunction _isAIMessageChunk(message: unknown): message is AIMessageChunk {\n return (\n typeof (message as BaseMessage)?._getType === \"function\" &&\n typeof (message as BaseMessageChunk).concat === \"function\" &&\n (message as BaseMessageChunk)._getType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