UNPKG

@genkit-ai/anthropic

Version:

Genkit AI framework plugin for Anthropic APIs.

1 lines 2.52 kB
{"version":3,"sources":["../../../src/runner/converters/stable.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 stable API content blocks.\n */\n\nimport type { DocumentBlockParam } from '@anthropic-ai/sdk/resources/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 stable API, name is always present.\n */\nexport function serverToolUseBlockToPart(block: {\n id: string;\n name: string;\n input: unknown;\n}): Part {\n return {\n text: `[Anthropic server tool ${block.name}] input: ${JSON.stringify(block.input)}`,\n metadata: {\n anthropicServerToolUse: {\n id: block.id,\n name: block.name,\n input: block.input,\n },\n },\n };\n}\n\n/**\n * Converts AnthropicDocumentOptions to Anthropic's stable API document block format.\n * Note: The stable API does not support file-based sources (Files API).\n */\nexport function toDocumentBlock(\n options: AnthropicDocumentOptions\n): DocumentBlockParam {\n return createDocumentBlock<DocumentBlockParam>(options, (source) =>\n convertDocumentSource<DocumentBlockParam['source']>(source, () => {\n throw new Error(\n 'File-based document sources require the beta API. Set apiVersion: \"beta\" in your plugin config or request config.'\n );\n })\n );\n}\n"],"mappings":"AAuBA,SAAS,uBAAuB,2BAA2B;AAMpD,SAAS,yBAAyB,OAIhC;AACP,SAAO;AAAA,IACL,MAAM,0BAA0B,MAAM,IAAI,YAAY,KAAK,UAAU,MAAM,KAAK,CAAC;AAAA,IACjF,UAAU;AAAA,MACR,wBAAwB;AAAA,QACtB,IAAI,MAAM;AAAA,QACV,MAAM,MAAM;AAAA,QACZ,OAAO,MAAM;AAAA,MACf;AAAA,IACF;AAAA,EACF;AACF;AAMO,SAAS,gBACd,SACoB;AACpB,SAAO;AAAA,IAAwC;AAAA,IAAS,CAAC,WACvD,sBAAoD,QAAQ,MAAM;AAChE,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}