@genkit-ai/anthropic
Version:
Genkit AI framework plugin for Anthropic APIs.
1 lines • 3.2 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/runner/converters/beta.ts"],"sourcesContent":["/**\n * Copyright 2025 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Converters for beta API content blocks.\n */\n\nimport type { BetaRequestDocumentBlock } from '@anthropic-ai/sdk/resources/beta/messages';\nimport type { Part } from 'genkit';\nimport type { AnthropicDocumentOptions } from '../../types.mjs';\nimport { convertDocumentSource, createDocumentBlock } from './shared.mjs';\n\n/**\n * Converts a server_tool_use block to a Genkit Part.\n * In the beta API, name may be undefined and server_name prefix is supported.\n */\nexport function betaServerToolUseBlockToPart(block: {\n id: string;\n name?: string;\n input: unknown;\n server_name?: string;\n}): Part {\n const baseName = block.name ?? 'unknown_tool';\n const serverToolName = block.server_name\n ? `${block.server_name}/${baseName}`\n : baseName;\n return {\n text: `[Anthropic server tool ${serverToolName}] input: ${JSON.stringify(block.input)}`,\n metadata: {\n anthropicServerToolUse: {\n id: block.id,\n name: serverToolName,\n input: block.input,\n },\n },\n };\n}\n\n/**\n * Error message for unsupported server tool block types in the beta API.\n */\nexport function unsupportedServerToolError(blockType: string): string {\n return `Anthropic beta runner does not yet support server-managed tool block '${blockType}'. Please retry against the stable API or wait for dedicated support.`;\n}\n\n/**\n * Converts AnthropicDocumentOptions to Anthropic's beta API document block format.\n * The beta API supports file-based sources via the Files API.\n */\nexport function toBetaDocumentBlock(\n options: AnthropicDocumentOptions\n): BetaRequestDocumentBlock {\n return createDocumentBlock<BetaRequestDocumentBlock>(options, (source) =>\n convertDocumentSource<BetaRequestDocumentBlock['source']>(\n source,\n (fileId) =>\n ({\n type: 'file',\n file_id: fileId,\n }) as BetaRequestDocumentBlock['source']\n )\n );\n}\n"],"mappings":"AAuBA,SAAS,uBAAuB,2BAA2B;AAMpD,SAAS,6BAA6B,OAKpC;AACP,QAAM,WAAW,MAAM,QAAQ;AAC/B,QAAM,iBAAiB,MAAM,cACzB,GAAG,MAAM,WAAW,IAAI,QAAQ,KAChC;AACJ,SAAO;AAAA,IACL,MAAM,0BAA0B,cAAc,YAAY,KAAK,UAAU,MAAM,KAAK,CAAC;AAAA,IACrF,UAAU;AAAA,MACR,wBAAwB;AAAA,QACtB,IAAI,MAAM;AAAA,QACV,MAAM;AAAA,QACN,OAAO,MAAM;AAAA,MACf;AAAA,IACF;AAAA,EACF;AACF;AAKO,SAAS,2BAA2B,WAA2B;AACpE,SAAO,yEAAyE,SAAS;AAC3F;AAMO,SAAS,oBACd,SAC0B;AAC1B,SAAO;AAAA,IAA8C;AAAA,IAAS,CAAC,WAC7D;AAAA,MACE;AAAA,MACA,CAAC,YACE;AAAA,QACC,MAAM;AAAA,QACN,SAAS;AAAA,MACX;AAAA,IACJ;AAAA,EACF;AACF;","names":[]}