@langchain/community
Version:
Third-party integrations for LangChain.js
1 lines • 26.5 kB
Source Map (JSON)
{"version":3,"file":"anthropic.cjs","names":["ToolMessage","HumanMessage","SystemMessage","AIMessage","AIMessageChunk"],"sources":["../../../src/utils/bedrock/anthropic.ts"],"sourcesContent":["import {\n AIMessage,\n AIMessageChunk,\n BaseMessage,\n HumanMessage,\n isAIMessage,\n MessageContent,\n SystemMessage,\n ToolMessage,\n UsageMetadata,\n} from \"@langchain/core/messages\";\nimport { ToolCall, ToolCallChunk } from \"@langchain/core/messages/tool\";\nimport { concat } from \"@langchain/core/utils/stream\";\n\n// oxlint-disable-next-line typescript/no-explicit-any\nexport function extractToolCalls(content: Record<string, any>[]) {\n const toolCalls: ToolCall[] = [];\n for (const block of content) {\n if (block.type === \"tool_use\") {\n toolCalls.push({\n name: block.name,\n args: block.input,\n id: block.id,\n type: \"tool_call\",\n });\n }\n }\n return toolCalls;\n}\n\nfunction _formatImage(imageUrl: string) {\n const regex = /^data:(image\\/.+);base64,(.+)$/;\n const match = imageUrl.match(regex);\n if (match === null) {\n throw new Error(\n [\n \"Anthropic only supports base64-encoded images currently.\",\n \"Example: data:image/png;base64,/9j/4AAQSk...\",\n ].join(\"\\n\\n\")\n );\n }\n return {\n type: \"base64\",\n media_type: match[1] ?? \"\",\n data: match[2] ?? \"\",\n };\n}\n\nfunction _ensureMessageContents(\n messages: BaseMessage[]\n): (SystemMessage | HumanMessage | AIMessage)[] {\n // Merge runs of human/tool messages into single human messages with content blocks.\n const updatedMsgs: (SystemMessage | HumanMessage | AIMessage)[] = [];\n for (const message of messages) {\n if (ToolMessage.isInstance(message)) {\n if (typeof message.content === \"string\") {\n const previousMessage = updatedMsgs[updatedMsgs.length - 1];\n if (\n previousMessage?._getType() === \"human\" &&\n Array.isArray(previousMessage.content) &&\n \"type\" in previousMessage.content[0] &&\n previousMessage.content[0].type === \"tool_result\"\n ) {\n // If the previous message was a tool result, we merge this tool message into it.\n previousMessage.content.push({\n type: \"tool_result\",\n content: message.content,\n tool_use_id: message.tool_call_id,\n });\n } else {\n // If not, we create a new human message with the tool result.\n updatedMsgs.push(\n new HumanMessage({\n content: [\n {\n type: \"tool_result\",\n content: message.content,\n tool_use_id: message.tool_call_id,\n },\n ],\n })\n );\n }\n } else {\n updatedMsgs.push(\n new HumanMessage({\n content: [\n {\n type: \"tool_result\",\n content: _formatContent(message.content),\n tool_use_id: message.tool_call_id,\n },\n ],\n })\n );\n }\n } else if (\n SystemMessage.isInstance(message) ||\n HumanMessage.isInstance(message) ||\n AIMessage.isInstance(message)\n ) {\n updatedMsgs.push(message);\n } else {\n throw new Error(`Message type \"${message._getType()}\" is not supported.`);\n }\n }\n return updatedMsgs;\n}\n\nexport function _convertLangChainToolCallToAnthropic(\n toolCall: ToolCall\n // oxlint-disable-next-line typescript/no-explicit-any\n): Record<string, any> {\n if (toolCall.id === undefined) {\n throw new Error(`Anthropic requires all tool calls to have an \"id\".`);\n }\n return {\n type: \"tool_use\",\n id: toolCall.id,\n name: toolCall.name,\n input: toolCall.args,\n };\n}\n\nfunction _formatContent(content: MessageContent) {\n if (typeof content === \"string\") {\n return content;\n } else {\n return content.flatMap((contentPart) => {\n // Legacy data content blocks (have source_type property) — must come\n // first because they share `type` values with the new multimodal blocks\n // but use different property names (e.g. mime_type vs mimeType).\n if (\"source_type\" in contentPart) {\n const sourceType = (contentPart as Record<string, unknown>)\n .source_type as string;\n const blockType = contentPart.type as string;\n\n if (sourceType === \"base64\" && blockType === \"image\") {\n return {\n type: \"image\" as const,\n source: {\n type: \"base64\" as const,\n media_type:\n (contentPart as Record<string, unknown>).mime_type ?? \"\",\n data: (contentPart as Record<string, unknown>).data ?? \"\",\n },\n };\n } else if (sourceType === \"base64\" && blockType === \"file\") {\n return {\n type: \"document\" as const,\n source: {\n type: \"base64\" as const,\n media_type:\n (contentPart as Record<string, unknown>).mime_type ?? \"\",\n data: (contentPart as Record<string, unknown>).data ?? \"\",\n },\n };\n } else if (sourceType === \"url\" && blockType === \"file\") {\n // NOTE: URL source may not work on Bedrock (see file block below).\n return {\n type: \"document\" as const,\n source: {\n type: \"url\" as const,\n url: (contentPart as Record<string, unknown>).url ?? \"\",\n },\n };\n } else if (sourceType === \"text\") {\n return {\n type: \"text\" as const,\n text: (contentPart as Record<string, unknown>).text ?? \"\",\n };\n }\n // Skip unsupported legacy source types (audio, id, etc.)\n return [];\n } else if (contentPart.type === \"image_url\") {\n let imageUrl: string;\n if (typeof contentPart.image_url === \"string\") {\n imageUrl = contentPart.image_url;\n } else if (\n typeof contentPart.image_url === \"object\" &&\n contentPart.image_url !== null &&\n \"url\" in contentPart.image_url &&\n typeof contentPart.image_url.url === \"string\"\n ) {\n imageUrl = contentPart.image_url.url;\n } else {\n return [];\n }\n return {\n type: \"image\" as const,\n source: _formatImage(imageUrl),\n };\n } else if (contentPart.type === \"image\") {\n // New multimodal image format\n if (\"url\" in contentPart && typeof contentPart.url === \"string\") {\n const source = _formatImage(contentPart.url);\n return {\n type: \"image\" as const,\n source,\n };\n } else if (\n \"data\" in contentPart &&\n (typeof contentPart.data === \"string\" ||\n // eslint-disable-next-line no-instanceof/no-instanceof\n contentPart.data instanceof Uint8Array)\n ) {\n const mimeType =\n \"mimeType\" in contentPart &&\n typeof contentPart.mimeType === \"string\"\n ? contentPart.mimeType\n : \"image/jpeg\";\n const data =\n typeof contentPart.data === \"string\"\n ? contentPart.data\n : Buffer.from(contentPart.data).toString(\"base64\");\n return {\n type: \"image\" as const,\n source: {\n type: \"base64\" as const,\n media_type: mimeType,\n data,\n },\n };\n }\n return [];\n } else if (contentPart.type === \"file\") {\n // New multimodal file format → Anthropic document block.\n // NOTE: URL source type may not be supported on Bedrock. The AWS\n // Bedrock docs only document base64 sources. URL sources are included\n // here to match the @langchain/anthropic reference implementation;\n // if Bedrock rejects them, users will receive a clear API error.\n if (\"url\" in contentPart && typeof contentPart.url === \"string\") {\n return {\n type: \"document\" as const,\n source: {\n type: \"url\" as const,\n url: contentPart.url,\n },\n };\n } else if (\n \"data\" in contentPart &&\n (typeof contentPart.data === \"string\" ||\n // eslint-disable-next-line no-instanceof/no-instanceof\n contentPart.data instanceof Uint8Array)\n ) {\n const mimeType =\n \"mimeType\" in contentPart &&\n typeof contentPart.mimeType === \"string\"\n ? contentPart.mimeType\n : \"application/pdf\";\n const data =\n typeof contentPart.data === \"string\"\n ? contentPart.data\n : Buffer.from(contentPart.data).toString(\"base64\");\n return {\n type: \"document\" as const,\n source: {\n type: \"base64\" as const,\n media_type: mimeType,\n data,\n },\n };\n }\n return [];\n } else if (contentPart.type === \"document\") {\n // Anthropic-native document block — pass through\n\n return { ...contentPart };\n } else if (\n contentPart.type === \"text\" ||\n contentPart.type === \"text_delta\"\n ) {\n if (contentPart.text === \"\") {\n return [];\n }\n return {\n type: \"text\" as const,\n text: contentPart.text,\n };\n } else if (\n contentPart.type === \"tool_use\" ||\n contentPart.type === \"tool_result\"\n ) {\n // TODO: Fix when SDK types are fixed\n return {\n ...contentPart,\n };\n } else if (contentPart.type === \"input_json_delta\") {\n return [];\n } else {\n // Silently skip unsupported types (audio, video, etc.)\n return [];\n }\n });\n }\n}\n\nexport function formatMessagesForAnthropic(messages: BaseMessage[]): {\n system?: string;\n messages: Record<string, unknown>[];\n} {\n const mergedMessages = _ensureMessageContents(messages);\n let system: string | undefined;\n if (mergedMessages.length > 0 && mergedMessages[0]._getType() === \"system\") {\n if (typeof messages[0].content !== \"string\") {\n throw new Error(\"System message content must be a string.\");\n }\n system = messages[0].content;\n }\n const conversationMessages =\n system !== undefined ? mergedMessages.slice(1) : mergedMessages;\n const formattedMessages = conversationMessages.map((message) => {\n let role;\n if (message._getType() === \"human\") {\n role = \"user\" as const;\n } else if (message._getType() === \"ai\") {\n role = \"assistant\" as const;\n } else if (message._getType() === \"tool\") {\n role = \"user\" as const;\n } else if (message._getType() === \"system\") {\n throw new Error(\n \"System messages are only permitted as the first passed message.\"\n );\n } else {\n throw new Error(`Message type \"${message._getType()}\" is not supported.`);\n }\n if (isAIMessage(message) && !!message.tool_calls?.length) {\n if (typeof message.content === \"string\") {\n if (message.content === \"\") {\n return {\n role,\n content: message.tool_calls.map(\n _convertLangChainToolCallToAnthropic\n ),\n };\n } else {\n return {\n role,\n content: [\n { type: \"text\", text: message.content },\n ...message.tool_calls.map(_convertLangChainToolCallToAnthropic),\n ],\n };\n }\n } else {\n const formattedContent = _formatContent(message.content);\n if (Array.isArray(formattedContent)) {\n const formattedToolsContent = message.tool_calls.map(\n _convertLangChainToolCallToAnthropic\n );\n return {\n role,\n content: [...formattedContent, ...formattedToolsContent],\n };\n }\n\n return {\n role,\n content: formattedContent,\n };\n }\n } else {\n return {\n role,\n content: _formatContent(message.content),\n };\n }\n });\n return {\n messages: formattedMessages,\n system,\n };\n}\n\nexport function isAnthropicTool(\n tool: unknown\n): tool is Record<string, unknown> {\n if (typeof tool !== \"object\" || !tool) return false;\n return \"input_schema\" in tool;\n}\n\nexport function _makeMessageChunkFromAnthropicEvent(\n // oxlint-disable-next-line typescript/no-explicit-any\n data: Record<string, any>,\n fields: {\n coerceContentToString?: boolean;\n }\n): AIMessageChunk | null {\n if (data.type === \"message_start\") {\n const { content, usage, ...additionalKwargs } = data.message;\n // oxlint-disable-next-line typescript/no-explicit-any\n const filteredAdditionalKwargs: Record<string, any> = {};\n for (const [key, value] of Object.entries(additionalKwargs)) {\n if (value !== undefined && value !== null) {\n filteredAdditionalKwargs[key] = value;\n }\n }\n return new AIMessageChunk({\n content: fields.coerceContentToString ? \"\" : [],\n additional_kwargs: filteredAdditionalKwargs,\n });\n } else if (data.type === \"message_delta\") {\n let usageMetadata: UsageMetadata | undefined;\n return new AIMessageChunk({\n content: fields.coerceContentToString ? \"\" : [],\n additional_kwargs: { ...data.delta },\n usage_metadata: usageMetadata,\n });\n } else if (\n data.type === \"content_block_start\" &&\n data.content_block.type === \"tool_use\"\n ) {\n return new AIMessageChunk({\n content: fields.coerceContentToString\n ? \"\"\n : [\n {\n index: data.index,\n ...data.content_block,\n input: \"\",\n },\n ],\n additional_kwargs: {},\n });\n } else if (\n data.type === \"content_block_delta\" &&\n data.delta.type === \"text_delta\"\n ) {\n const content = data.delta?.text;\n if (content !== undefined) {\n return new AIMessageChunk({\n content: fields.coerceContentToString\n ? content\n : [\n {\n index: data.index,\n ...data.delta,\n },\n ],\n additional_kwargs: {},\n });\n }\n } else if (\n data.type === \"content_block_delta\" &&\n data.delta.type === \"input_json_delta\"\n ) {\n return new AIMessageChunk({\n content: fields.coerceContentToString\n ? \"\"\n : [\n {\n index: data.index,\n input: data.delta.partial_json,\n type: data.delta.type,\n },\n ],\n additional_kwargs: {},\n });\n } else if (\n data.type === \"message_stop\" &&\n data[\"amazon-bedrock-invocationMetrics\"] !== undefined\n ) {\n return new AIMessageChunk({\n content: \"\",\n response_metadata: {\n \"amazon-bedrock-invocationMetrics\":\n data[\"amazon-bedrock-invocationMetrics\"],\n },\n usage_metadata: {\n input_tokens: data[\"amazon-bedrock-invocationMetrics\"].inputTokenCount,\n output_tokens:\n data[\"amazon-bedrock-invocationMetrics\"].outputTokenCount,\n total_tokens:\n data[\"amazon-bedrock-invocationMetrics\"].inputTokenCount +\n data[\"amazon-bedrock-invocationMetrics\"].outputTokenCount,\n },\n });\n }\n\n return null;\n}\n\nexport function extractToolCallChunk(\n chunk: AIMessageChunk\n): ToolCallChunk | undefined {\n let newToolCallChunk: ToolCallChunk | undefined;\n\n // Initial chunk for tool calls from anthropic contains identifying information like ID and name.\n // This chunk does not contain any input JSON.\n const toolUseChunks = Array.isArray(chunk.content)\n ? chunk.content.find((c) => c.type === \"tool_use\")\n : undefined;\n if (\n toolUseChunks &&\n \"index\" in toolUseChunks &&\n typeof toolUseChunks.index === \"number\" &&\n \"name\" in toolUseChunks &&\n typeof toolUseChunks.name === \"string\" &&\n \"id\" in toolUseChunks &&\n typeof toolUseChunks.id === \"string\"\n ) {\n newToolCallChunk = {\n args: \"\",\n id: toolUseChunks.id,\n name: toolUseChunks.name,\n index: toolUseChunks.index,\n type: \"tool_call_chunk\",\n };\n }\n\n // Chunks after the initial chunk only contain the index and partial JSON.\n const inputJsonDeltaChunks = Array.isArray(chunk.content)\n ? chunk.content.find((c) => c.type === \"input_json_delta\")\n : undefined;\n if (\n inputJsonDeltaChunks &&\n \"index\" in inputJsonDeltaChunks &&\n typeof inputJsonDeltaChunks.index === \"number\" &&\n \"input\" in inputJsonDeltaChunks\n ) {\n if (typeof inputJsonDeltaChunks.input === \"string\") {\n newToolCallChunk = {\n args: inputJsonDeltaChunks.input,\n index: inputJsonDeltaChunks.index,\n type: \"tool_call_chunk\",\n };\n } else {\n newToolCallChunk = {\n args: JSON.stringify(inputJsonDeltaChunks.input, null, 2),\n index: inputJsonDeltaChunks.index,\n type: \"tool_call_chunk\",\n };\n }\n }\n\n return newToolCallChunk;\n}\n\nexport function extractToken(chunk: AIMessageChunk): string | undefined {\n return typeof chunk.content === \"string\" && chunk.content !== \"\"\n ? chunk.content\n : undefined;\n}\n\nexport function extractToolUseContent(\n chunk: AIMessageChunk,\n concatenatedChunks: AIMessageChunk | undefined\n) {\n let newConcatenatedChunks = concatenatedChunks;\n // Remove `tool_use` content types until the last chunk.\n let toolUseContent:\n | {\n id: string;\n type: \"tool_use\";\n name: string;\n input: Record<string, unknown>;\n }\n | undefined;\n if (!newConcatenatedChunks) {\n newConcatenatedChunks = chunk;\n } else {\n newConcatenatedChunks = concat(newConcatenatedChunks, chunk);\n }\n if (\n Array.isArray(newConcatenatedChunks.content) &&\n newConcatenatedChunks.content.find((c) => c.type === \"tool_use\")\n ) {\n try {\n const toolUseMsg = newConcatenatedChunks.content.find(\n (c) => c.type === \"tool_use\"\n );\n if (\n !toolUseMsg ||\n !(\"input\" in toolUseMsg || \"name\" in toolUseMsg || \"id\" in toolUseMsg)\n )\n return;\n if (\n typeof toolUseMsg.id !== \"string\" ||\n typeof toolUseMsg.name !== \"string\" ||\n typeof toolUseMsg.input !== \"string\"\n ) {\n return;\n }\n const parsedArgs = JSON.parse(toolUseMsg.input);\n if (parsedArgs) {\n toolUseContent = {\n type: \"tool_use\",\n id: toolUseMsg.id,\n name: toolUseMsg.name,\n input: parsedArgs,\n };\n }\n } catch (_) {\n // no-op\n }\n }\n\n return {\n toolUseContent,\n concatenatedChunks: newConcatenatedChunks,\n };\n}\n\n// oxlint-disable-next-line typescript/no-explicit-any\nexport function _toolsInParams(params: Record<string, any>): boolean {\n return !!(params.tools && params.tools.length > 0);\n}\n"],"mappings":";;;;AAeA,SAAgB,iBAAiB,SAAgC;CAC/D,MAAM,YAAwB,EAAE;AAChC,MAAK,MAAM,SAAS,QAClB,KAAI,MAAM,SAAS,WACjB,WAAU,KAAK;EACb,MAAM,MAAM;EACZ,MAAM,MAAM;EACZ,IAAI,MAAM;EACV,MAAM;EACP,CAAC;AAGN,QAAO;;AAGT,SAAS,aAAa,UAAkB;CAEtC,MAAM,QAAQ,SAAS,MADT,iCACqB;AACnC,KAAI,UAAU,KACZ,OAAM,IAAI,MACR,CACE,4DACA,+CACD,CAAC,KAAK,OAAO,CACf;AAEH,QAAO;EACL,MAAM;EACN,YAAY,MAAM,MAAM;EACxB,MAAM,MAAM,MAAM;EACnB;;AAGH,SAAS,uBACP,UAC8C;CAE9C,MAAM,cAA4D,EAAE;AACpE,MAAK,MAAM,WAAW,SACpB,KAAIA,yBAAAA,YAAY,WAAW,QAAQ,CACjC,KAAI,OAAO,QAAQ,YAAY,UAAU;EACvC,MAAM,kBAAkB,YAAY,YAAY,SAAS;AACzD,MACE,iBAAiB,UAAU,KAAK,WAChC,MAAM,QAAQ,gBAAgB,QAAQ,IACtC,UAAU,gBAAgB,QAAQ,MAClC,gBAAgB,QAAQ,GAAG,SAAS,cAGpC,iBAAgB,QAAQ,KAAK;GAC3B,MAAM;GACN,SAAS,QAAQ;GACjB,aAAa,QAAQ;GACtB,CAAC;MAGF,aAAY,KACV,IAAIC,yBAAAA,aAAa,EACf,SAAS,CACP;GACE,MAAM;GACN,SAAS,QAAQ;GACjB,aAAa,QAAQ;GACtB,CACF,EACF,CAAC,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