experimental-ash 0.8.3 → 0.10.0
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/CHANGELOG.md +92 -0
- package/dist/docs/public/channels/slack.md +76 -25
- package/dist/src/compiled/.vendor-stamp.json +14 -14
- package/dist/src/compiled/@ai-sdk/anthropic/index.js +2 -2
- package/dist/src/compiled/@ai-sdk/google/index.js +4 -4
- package/dist/src/compiled/@ai-sdk/mcp/index.js +1 -1
- package/dist/src/compiled/@ai-sdk/openai/index.js +6 -6
- package/dist/src/compiled/@ai-sdk/otel/index.js +1 -1
- package/dist/src/compiled/@ai-sdk/provider/_json-schema.d.ts +5 -0
- package/dist/src/compiled/@ai-sdk/provider/index.d.ts +6632 -1
- package/dist/src/compiled/@chat-adapter/slack/_chat-adapter-shared.d.ts +9 -0
- package/dist/src/compiled/@chat-adapter/slack/index.d.ts +632 -54
- package/dist/src/compiled/@chat-adapter/slack/index.js +25 -29
- package/dist/src/compiled/@chat-adapter/slack/package.json +1 -1
- package/dist/src/compiled/@chat-adapter/state-memory/index.d.ts +41 -25
- package/dist/src/compiled/@chat-adapter/state-memory/package.json +1 -1
- package/dist/src/compiled/@standard-schema/spec/index.d.ts +115 -62
- package/dist/src/compiled/@vercel/sandbox/index.d.ts +4 -1
- package/dist/src/compiled/@vercel/sandbox/index.js +5 -5
- package/dist/src/compiled/@workflow/core/index.js +1 -1
- package/dist/src/compiled/@workflow/core/runtime.d.ts +6 -2
- package/dist/src/compiled/@workflow/core/runtime.js +4 -4
- package/dist/src/compiled/@workflow/core/workflow.js +1 -1
- package/dist/src/compiled/@workflow/errors/_ms.d.ts +4 -0
- package/dist/src/compiled/@workflow/errors/error-codes.d.ts +17 -0
- package/dist/src/compiled/@workflow/errors/index.d.ts +438 -56
- package/dist/src/compiled/@workflow/errors/index.js +1 -1
- package/dist/src/compiled/_chunks/node/{auth-CdwuOxMs.js → auth-vbe4XEEK.js} +2 -2
- package/dist/src/compiled/_chunks/node/{dist-B6IOtzm1.js → dist-BdWHjlRQ.js} +12 -12
- package/dist/src/compiled/_chunks/node/retry-BOcy5BbJ.js +1 -0
- package/dist/src/compiled/_chunks/workflow/{context-errors-CXifqq6a.js → context-errors-zbKocOyk.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/{dist-BuELZxm6.js → dist-Ci2brnHh.js} +3 -3
- package/dist/src/compiled/_chunks/workflow/{resume-hook-CgfgCU87.js → resume-hook-CL8Ed91K.js} +2 -2
- package/dist/src/compiled/_chunks/workflow/sleep-Dn3i9nxI.js +1 -0
- package/dist/src/compiled/chat/_mdast.d.ts +24 -0
- package/dist/src/compiled/chat/_workflow-serde.d.ts +5 -0
- package/dist/src/compiled/chat/index.d.ts +3851 -72
- package/dist/src/compiled/chat/index.js +1 -1
- package/dist/src/compiled/chat/jsx-runtime-DxGwoLu2.d.ts +782 -0
- package/dist/src/compiled/chat/package.json +1 -1
- package/dist/src/compiled/just-bash/index.js +1 -1
- package/dist/src/execution/authorization-challenge-defaults.d.ts +1 -1
- package/dist/src/execution/authorization-challenge-defaults.js +1 -1
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/public/channels/slack/index.d.ts +1 -1
- package/dist/src/public/channels/slack/slack.d.ts +2 -1
- package/dist/src/public/channels/slack/slack.js +5 -1
- package/dist/src/public/channels/slack/slackChannel.d.ts +67 -5
- package/dist/src/public/channels/slack/slackChannel.js +40 -15
- package/dist/src/runtime/connections/authorization-tokens.d.ts +1 -1
- package/dist/src/runtime/connections/authorization-tokens.js +1 -1
- package/package.json +16 -16
- package/dist/src/compiled/_chunks/node/ms-B2k_qBoq.js +0 -1
- package/dist/src/compiled/_chunks/workflow/sleep-BzS_cSYx.js +0 -1
- /package/dist/src/compiled/_chunks/workflow/{dist-C9DdsXoK.js → dist-0iNBqPYp.js} +0 -0
- /package/dist/src/compiled/_chunks/workflow/{dist-BHbmiLmM.js → dist-D774SUM4.js} +0 -0
- /package/dist/src/compiled/_chunks/workflow/{src-CidBwKAD.js → src-ClRYdO4-.js} +0 -0
- /package/dist/src/compiled/_chunks/workflow/{symbols-BC0BVTM7.js → symbols-D-4tVV8x.js} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{At as e,Bt as t,Et as n,Kn as r,Nn as i,Rn as a,Tn as o,Xn as s,Zn as c,dn as l,fn as u,wn as d,yt as f}from"../../_chunks/workflow/schemas-DFZoEyCn.js";import{APICallError as p,InvalidArgumentError as m,NoSuchModelError as h,UnsupportedFunctionalityError as g}from"../provider/index.js";import{A as _,B as v,C as y,E as b,F as x,G as S,I as C,J as w,K as T,L as E,M as D,O,R as k,U as ee,X as A,Y as j,a as M,b as N,d as P,f as F,g as te,h as I,i as L,j as R,k as z,o as B,p as V,q as H,r as U,u as W,w as ne,x as G,z as K}from"../../_chunks/workflow/dist-BuELZxm6.js";var q=P({errorSchema:O(()=>w(o({type:l(`error`),error:o({type:a(),message:a()})}))),errorToMessage:e=>e.error.message}),re=O(()=>w(o({id:a(),type:l(`file`),filename:a(),mime_type:a(),size_bytes:d(),created_at:a(),downloadable:e().nullish()}))),ie=class{constructor(e){this.config=e,this.specificationVersion=`v4`}get provider(){return this.config.provider}async uploadFile({data:e,mediaType:t,filename:n}){let r=M(e),i=new Blob([r],{type:t}),a=new FormData;n==null?a.append(`file`,i):a.append(`file`,i,n);let{value:o}=await C({url:`${this.config.baseURL}/files`,headers:U(this.config.headers(),{"anthropic-beta":`files-api-2025-04-14`}),formData:a,failedResponseHandler:q,successfulResponseHandler:F(re),fetch:this.config.fetch});return{warnings:[],providerReference:{anthropic:o.id},mediaType:o.mime_type??t,filename:o.filename??n,providerMetadata:{anthropic:{filename:o.filename,mimeType:o.mime_type,sizeBytes:o.size_bytes,createdAt:o.created_at,...o.downloadable==null?{}:{downloadable:o.downloadable}}}}}},ae=O(()=>w(o({type:l(`message`),id:a().nullish(),model:a().nullish(),content:n(t(`type`,[o({type:l(`text`),text:a(),citations:n(t(`type`,[o({type:l(`web_search_result_location`),cited_text:a(),url:a(),title:a(),encrypted_index:a()}),o({type:l(`page_location`),cited_text:a(),document_index:d(),document_title:a().nullable(),start_page_number:d(),end_page_number:d()}),o({type:l(`char_location`),cited_text:a(),document_index:d(),document_title:a().nullable(),start_char_index:d(),end_char_index:d()})])).optional()}),o({type:l(`thinking`),thinking:a(),signature:a()}),o({type:l(`redacted_thinking`),data:a()}),o({type:l(`compaction`),content:a()}),o({type:l(`tool_use`),id:a(),name:a(),input:c(),caller:s([o({type:l(`code_execution_20250825`),tool_id:a()}),o({type:l(`code_execution_20260120`),tool_id:a()}),o({type:l(`direct`)})]).optional()}),o({type:l(`server_tool_use`),id:a(),name:a(),input:i(a(),c()).nullish(),caller:s([o({type:l(`code_execution_20260120`),tool_id:a()}),o({type:l(`direct`)})]).optional()}),o({type:l(`mcp_tool_use`),id:a(),name:a(),input:c(),server_name:a()}),o({type:l(`mcp_tool_result`),tool_use_id:a(),is_error:e(),content:n(s([a(),o({type:l(`text`),text:a()})]))}),o({type:l(`web_fetch_tool_result`),tool_use_id:a(),content:s([o({type:l(`web_fetch_result`),url:a(),retrieved_at:a(),content:o({type:l(`document`),title:a().nullable(),citations:o({enabled:e()}).optional(),source:s([o({type:l(`base64`),media_type:l(`application/pdf`),data:a()}),o({type:l(`text`),media_type:l(`text/plain`),data:a()})])})}),o({type:l(`web_fetch_tool_result_error`),error_code:a()})])}),o({type:l(`web_search_tool_result`),tool_use_id:a(),content:s([n(o({type:l(`web_search_result`),url:a(),title:a(),encrypted_content:a(),page_age:a().nullish()})),o({type:l(`web_search_tool_result_error`),error_code:a()})])}),o({type:l(`code_execution_tool_result`),tool_use_id:a(),content:s([o({type:l(`code_execution_result`),stdout:a(),stderr:a(),return_code:d(),content:n(o({type:l(`code_execution_output`),file_id:a()})).optional().default([])}),o({type:l(`encrypted_code_execution_result`),encrypted_stdout:a(),stderr:a(),return_code:d(),content:n(o({type:l(`code_execution_output`),file_id:a()})).optional().default([])}),o({type:l(`code_execution_tool_result_error`),error_code:a()})])}),o({type:l(`bash_code_execution_tool_result`),tool_use_id:a(),content:t(`type`,[o({type:l(`bash_code_execution_result`),content:n(o({type:l(`bash_code_execution_output`),file_id:a()})),stdout:a(),stderr:a(),return_code:d()}),o({type:l(`bash_code_execution_tool_result_error`),error_code:a()})])}),o({type:l(`text_editor_code_execution_tool_result`),tool_use_id:a(),content:t(`type`,[o({type:l(`text_editor_code_execution_tool_result_error`),error_code:a()}),o({type:l(`text_editor_code_execution_view_result`),content:a(),file_type:a(),num_lines:d().nullable(),start_line:d().nullable(),total_lines:d().nullable()}),o({type:l(`text_editor_code_execution_create_result`),is_file_update:e()}),o({type:l(`text_editor_code_execution_str_replace_result`),lines:n(a()).nullable(),new_lines:d().nullable(),new_start:d().nullable(),old_lines:d().nullable(),old_start:d().nullable()})])}),o({type:l(`tool_search_tool_result`),tool_use_id:a(),content:s([o({type:l(`tool_search_tool_search_result`),tool_references:n(o({type:l(`tool_reference`),tool_name:a()}))}),o({type:l(`tool_search_tool_result_error`),error_code:a()})])})])),stop_reason:a().nullish(),stop_sequence:a().nullish(),usage:u({input_tokens:d(),output_tokens:d(),cache_creation_input_tokens:d().nullish(),cache_read_input_tokens:d().nullish(),iterations:n(o({type:s([l(`compaction`),l(`message`)]),input_tokens:d(),output_tokens:d()})).nullish()}),container:o({expires_at:a(),id:a(),skills:n(o({type:s([l(`anthropic`),l(`custom`)]),skill_id:a(),version:a()})).nullish()}).nullish(),context_management:o({applied_edits:n(s([o({type:l(`clear_tool_uses_20250919`),cleared_tool_uses:d(),cleared_input_tokens:d()}),o({type:l(`clear_thinking_20251015`),cleared_thinking_turns:d(),cleared_input_tokens:d()}),o({type:l(`compact_20260112`)})]))}).nullish()}))),J=O(()=>w(t(`type`,[o({type:l(`message_start`),message:o({id:a().nullish(),model:a().nullish(),role:a().nullish(),usage:u({input_tokens:d(),cache_creation_input_tokens:d().nullish(),cache_read_input_tokens:d().nullish()}),content:n(t(`type`,[o({type:l(`tool_use`),id:a(),name:a(),input:c(),caller:s([o({type:l(`code_execution_20250825`),tool_id:a()}),o({type:l(`code_execution_20260120`),tool_id:a()}),o({type:l(`direct`)})]).optional()})])).nullish(),stop_reason:a().nullish(),container:o({expires_at:a(),id:a()}).nullish()})}),o({type:l(`content_block_start`),index:d(),content_block:t(`type`,[o({type:l(`text`),text:a()}),o({type:l(`thinking`),thinking:a()}),o({type:l(`tool_use`),id:a(),name:a(),input:i(a(),c()).optional(),caller:s([o({type:l(`code_execution_20250825`),tool_id:a()}),o({type:l(`code_execution_20260120`),tool_id:a()}),o({type:l(`direct`)})]).optional()}),o({type:l(`redacted_thinking`),data:a()}),o({type:l(`compaction`),content:a().nullish()}),o({type:l(`server_tool_use`),id:a(),name:a(),input:i(a(),c()).nullish(),caller:s([o({type:l(`code_execution_20260120`),tool_id:a()}),o({type:l(`direct`)})]).optional()}),o({type:l(`mcp_tool_use`),id:a(),name:a(),input:c(),server_name:a()}),o({type:l(`mcp_tool_result`),tool_use_id:a(),is_error:e(),content:n(s([a(),o({type:l(`text`),text:a()})]))}),o({type:l(`web_fetch_tool_result`),tool_use_id:a(),content:s([o({type:l(`web_fetch_result`),url:a(),retrieved_at:a(),content:o({type:l(`document`),title:a().nullable(),citations:o({enabled:e()}).optional(),source:s([o({type:l(`base64`),media_type:l(`application/pdf`),data:a()}),o({type:l(`text`),media_type:l(`text/plain`),data:a()})])})}),o({type:l(`web_fetch_tool_result_error`),error_code:a()})])}),o({type:l(`web_search_tool_result`),tool_use_id:a(),content:s([n(o({type:l(`web_search_result`),url:a(),title:a(),encrypted_content:a(),page_age:a().nullish()})),o({type:l(`web_search_tool_result_error`),error_code:a()})])}),o({type:l(`code_execution_tool_result`),tool_use_id:a(),content:s([o({type:l(`code_execution_result`),stdout:a(),stderr:a(),return_code:d(),content:n(o({type:l(`code_execution_output`),file_id:a()})).optional().default([])}),o({type:l(`encrypted_code_execution_result`),encrypted_stdout:a(),stderr:a(),return_code:d(),content:n(o({type:l(`code_execution_output`),file_id:a()})).optional().default([])}),o({type:l(`code_execution_tool_result_error`),error_code:a()})])}),o({type:l(`bash_code_execution_tool_result`),tool_use_id:a(),content:t(`type`,[o({type:l(`bash_code_execution_result`),content:n(o({type:l(`bash_code_execution_output`),file_id:a()})),stdout:a(),stderr:a(),return_code:d()}),o({type:l(`bash_code_execution_tool_result_error`),error_code:a()})])}),o({type:l(`text_editor_code_execution_tool_result`),tool_use_id:a(),content:t(`type`,[o({type:l(`text_editor_code_execution_tool_result_error`),error_code:a()}),o({type:l(`text_editor_code_execution_view_result`),content:a(),file_type:a(),num_lines:d().nullable(),start_line:d().nullable(),total_lines:d().nullable()}),o({type:l(`text_editor_code_execution_create_result`),is_file_update:e()}),o({type:l(`text_editor_code_execution_str_replace_result`),lines:n(a()).nullable(),new_lines:d().nullable(),new_start:d().nullable(),old_lines:d().nullable(),old_start:d().nullable()})])}),o({type:l(`tool_search_tool_result`),tool_use_id:a(),content:s([o({type:l(`tool_search_tool_search_result`),tool_references:n(o({type:l(`tool_reference`),tool_name:a()}))}),o({type:l(`tool_search_tool_result_error`),error_code:a()})])})])}),o({type:l(`content_block_delta`),index:d(),delta:t(`type`,[o({type:l(`input_json_delta`),partial_json:a()}),o({type:l(`text_delta`),text:a()}),o({type:l(`thinking_delta`),thinking:a()}),o({type:l(`signature_delta`),signature:a()}),o({type:l(`compaction_delta`),content:a().nullish()}),o({type:l(`citations_delta`),citation:t(`type`,[o({type:l(`web_search_result_location`),cited_text:a(),url:a(),title:a(),encrypted_index:a()}),o({type:l(`page_location`),cited_text:a(),document_index:d(),document_title:a().nullable(),start_page_number:d(),end_page_number:d()}),o({type:l(`char_location`),cited_text:a(),document_index:d(),document_title:a().nullable(),start_char_index:d(),end_char_index:d()})])})])}),o({type:l(`content_block_stop`),index:d()}),o({type:l(`error`),error:o({type:a(),message:a()})}),o({type:l(`message_delta`),delta:o({stop_reason:a().nullish(),stop_sequence:a().nullish(),container:o({expires_at:a(),id:a(),skills:n(o({type:s([l(`anthropic`),l(`custom`)]),skill_id:a(),version:a()})).nullish()}).nullish()}),usage:u({input_tokens:d().nullish(),output_tokens:d(),cache_creation_input_tokens:d().nullish(),cache_read_input_tokens:d().nullish(),iterations:n(o({type:s([l(`compaction`),l(`message`)]),input_tokens:d(),output_tokens:d()})).nullish()}),context_management:o({applied_edits:n(s([o({type:l(`clear_tool_uses_20250919`),cleared_tool_uses:d(),cleared_input_tokens:d()}),o({type:l(`clear_thinking_20251015`),cleared_thinking_turns:d(),cleared_input_tokens:d()}),o({type:l(`compact_20260112`)})]))}).nullish()}),o({type:l(`message_stop`)}),o({type:l(`ping`)})]))),oe=O(()=>w(o({signature:a().optional(),redactedData:a().optional()}))),Y=o({citations:o({enabled:e()}).optional(),title:a().optional(),context:a().optional()}),se=o({sendReasoning:e().optional(),structuredOutputMode:f([`outputFormat`,`jsonTool`,`auto`]).optional(),thinking:t(`type`,[o({type:l(`adaptive`),display:f([`omitted`,`summarized`]).optional()}),o({type:l(`enabled`),budgetTokens:d().optional()}),o({type:l(`disabled`)})]).optional(),disableParallelToolUse:e().optional(),cacheControl:o({type:l(`ephemeral`),ttl:s([l(`5m`),l(`1h`)]).optional()}).optional(),metadata:o({userId:a().optional()}).optional(),mcpServers:n(o({type:l(`url`),name:a(),url:a(),authorizationToken:a().nullish(),toolConfiguration:o({enabled:e().nullish(),allowedTools:n(a()).nullish()}).nullish()})).optional(),container:o({id:a().optional(),skills:n(t(`type`,[o({type:l(`anthropic`),skillId:a(),version:a().optional()}),o({type:l(`custom`),providerReference:i(a(),a()),version:a().optional()})])).optional()}).optional(),toolStreaming:e().optional(),effort:f([`low`,`medium`,`high`,`xhigh`,`max`]).optional(),taskBudget:o({type:l(`tokens`),total:d().int().min(2e4),remaining:d().int().min(0).optional()}).optional(),speed:f([`fast`,`standard`]).optional(),inferenceGeo:f([`us`,`global`]).optional(),anthropicBeta:n(a()).optional(),contextManagement:o({edits:n(t(`type`,[o({type:l(`clear_tool_uses_20250919`),trigger:t(`type`,[o({type:l(`input_tokens`),value:d()}),o({type:l(`tool_uses`),value:d()})]).optional(),keep:o({type:l(`tool_uses`),value:d()}).optional(),clearAtLeast:o({type:l(`input_tokens`),value:d()}).optional(),clearToolInputs:e().optional(),excludeTools:n(a()).optional()}),o({type:l(`clear_thinking_20251015`),keep:s([l(`all`),o({type:l(`thinking_turns`),value:d()})]).optional()}),o({type:l(`compact_20260112`),trigger:o({type:l(`input_tokens`),value:d()}).optional(),pauseAfterCompaction:e().optional(),instructions:a().optional()})]))}).optional()}),ce=4;function le(e){let t=e?.anthropic;return t?.cacheControl??t?.cache_control}var X=class{constructor(){this.breakpointCount=0,this.warnings=[]}getCacheControl(e,t){let n=le(e);if(n){if(!t.canCache){this.warnings.push({type:`unsupported`,feature:`cache_control on non-cacheable context`,details:`cache_control cannot be set on ${t.type}. It will be ignored.`});return}if(this.breakpointCount++,this.breakpointCount>ce){this.warnings.push({type:`unsupported`,feature:`cacheControl breakpoint limit`,details:`Maximum ${ce} cache breakpoints exceeded (found ${this.breakpointCount}). This breakpoint will be ignored.`});return}return n}}getWarnings(){return this.warnings}},ue=O(()=>w(o({maxCharacters:d().optional()}))),de=V({id:`anthropic.text_editor_20250728`,inputSchema:O(()=>w(o({command:f([`view`,`create`,`str_replace`,`insert`]),path:a(),file_text:a().optional(),insert_line:d().int().optional(),new_str:a().optional(),insert_text:a().optional(),old_str:a().optional(),view_range:n(d().int()).optional()})))}),fe=(e={})=>de(e),pe=O(()=>w(o({maxUses:d().optional(),allowedDomains:n(a()).optional(),blockedDomains:n(a()).optional(),userLocation:o({type:l(`approximate`),city:a().optional(),region:a().optional(),country:a().optional(),timezone:a().optional()}).optional()}))),me=O(()=>w(n(o({url:a(),title:a().nullable(),pageAge:a().nullable(),encryptedContent:a(),type:l(`web_search_result`)})))),he=I({id:`anthropic.web_search_20260209`,inputSchema:O(()=>w(o({query:a()}))),outputSchema:me,supportsDeferredResults:!0}),ge=(e={})=>he(e),_e=O(()=>w(o({maxUses:d().optional(),allowedDomains:n(a()).optional(),blockedDomains:n(a()).optional(),userLocation:o({type:l(`approximate`),city:a().optional(),region:a().optional(),country:a().optional(),timezone:a().optional()}).optional()}))),ve=O(()=>w(n(o({url:a(),title:a().nullable(),pageAge:a().nullable(),encryptedContent:a(),type:l(`web_search_result`)})))),ye=I({id:`anthropic.web_search_20250305`,inputSchema:O(()=>w(o({query:a()}))),outputSchema:ve,supportsDeferredResults:!0}),be=(e={})=>ye(e),xe=O(()=>w(o({maxUses:d().optional(),allowedDomains:n(a()).optional(),blockedDomains:n(a()).optional(),citations:o({enabled:e()}).optional(),maxContentTokens:d().optional()}))),Se=O(()=>w(o({type:l(`web_fetch_result`),url:a(),content:o({type:l(`document`),title:a().nullable(),citations:o({enabled:e()}).optional(),source:s([o({type:l(`base64`),mediaType:l(`application/pdf`),data:a()}),o({type:l(`text`),mediaType:l(`text/plain`),data:a()})])}),retrievedAt:a().nullable()}))),Ce=I({id:`anthropic.web_fetch_20260209`,inputSchema:O(()=>w(o({url:a()}))),outputSchema:Se,supportsDeferredResults:!0}),we=(e={})=>Ce(e),Te=O(()=>w(o({maxUses:d().optional(),allowedDomains:n(a()).optional(),blockedDomains:n(a()).optional(),citations:o({enabled:e()}).optional(),maxContentTokens:d().optional()}))),Ee=O(()=>w(o({type:l(`web_fetch_result`),url:a(),content:o({type:l(`document`),title:a().nullable(),citations:o({enabled:e()}).optional(),source:s([o({type:l(`base64`),mediaType:l(`application/pdf`),data:a()}),o({type:l(`text`),mediaType:l(`text/plain`),data:a()})])}),retrievedAt:a().nullable()}))),De=I({id:`anthropic.web_fetch_20250910`,inputSchema:O(()=>w(o({url:a()}))),outputSchema:Ee,supportsDeferredResults:!0}),Oe=(e={})=>De(e);async function ke({tools:e,toolChoice:t,disableParallelToolUse:n,cacheControlValidator:r,supportsStructuredOutput:i,supportsStrictTools:a,defaultEagerInputStreaming:o=!1}){e=e?.length?e:void 0;let s=[],c=new Set,l=r||new X;if(e==null)return{tools:void 0,toolChoice:void 0,toolWarnings:s,betas:c};let u=[];for(let t of e)switch(t.type){case`function`:{let e=l.getCacheControl(t.providerOptions,{type:`tool definition`,canCache:!0}),n=t.providerOptions?.anthropic,r=n?.eagerInputStreaming??o,d=n?.deferLoading,f=n?.allowedCallers;!a&&t.strict!=null&&s.push({type:`unsupported`,feature:`strict`,details:`Tool '${t.name}' has strict: ${t.strict}, but strict mode is not supported by this provider. The strict property will be ignored.`}),u.push({name:t.name,description:t.description,input_schema:t.inputSchema,cache_control:e,...r?{eager_input_streaming:!0}:{},...a===!0&&t.strict!=null?{strict:t.strict}:{},...d==null?{}:{defer_loading:d},...f==null?{}:{allowed_callers:f},...t.inputExamples==null?{}:{input_examples:t.inputExamples.map(e=>e.input)}}),i===!0&&c.add(`structured-outputs-2025-11-13`),(t.inputExamples!=null||f!=null)&&c.add(`advanced-tool-use-2025-11-20`);break}case`provider`:switch(t.id){case`anthropic.code_execution_20250522`:c.add(`code-execution-2025-05-22`),u.push({type:`code_execution_20250522`,name:`code_execution`,cache_control:void 0});break;case`anthropic.code_execution_20250825`:c.add(`code-execution-2025-08-25`),u.push({type:`code_execution_20250825`,name:`code_execution`});break;case`anthropic.code_execution_20260120`:u.push({type:`code_execution_20260120`,name:`code_execution`});break;case`anthropic.computer_20250124`:c.add(`computer-use-2025-01-24`),u.push({name:`computer`,type:`computer_20250124`,display_width_px:t.args.displayWidthPx,display_height_px:t.args.displayHeightPx,display_number:t.args.displayNumber,cache_control:void 0});break;case`anthropic.computer_20251124`:c.add(`computer-use-2025-11-24`),u.push({name:`computer`,type:`computer_20251124`,display_width_px:t.args.displayWidthPx,display_height_px:t.args.displayHeightPx,display_number:t.args.displayNumber,enable_zoom:t.args.enableZoom,cache_control:void 0});break;case`anthropic.computer_20241022`:c.add(`computer-use-2024-10-22`),u.push({name:`computer`,type:`computer_20241022`,display_width_px:t.args.displayWidthPx,display_height_px:t.args.displayHeightPx,display_number:t.args.displayNumber,cache_control:void 0});break;case`anthropic.text_editor_20250124`:c.add(`computer-use-2025-01-24`),u.push({name:`str_replace_editor`,type:`text_editor_20250124`,cache_control:void 0});break;case`anthropic.text_editor_20241022`:c.add(`computer-use-2024-10-22`),u.push({name:`str_replace_editor`,type:`text_editor_20241022`,cache_control:void 0});break;case`anthropic.text_editor_20250429`:c.add(`computer-use-2025-01-24`),u.push({name:`str_replace_based_edit_tool`,type:`text_editor_20250429`,cache_control:void 0});break;case`anthropic.text_editor_20250728`:{let e=await S({value:t.args,schema:ue});u.push({name:`str_replace_based_edit_tool`,type:`text_editor_20250728`,max_characters:e.maxCharacters,cache_control:void 0});break}case`anthropic.bash_20250124`:c.add(`computer-use-2025-01-24`),u.push({name:`bash`,type:`bash_20250124`,cache_control:void 0});break;case`anthropic.bash_20241022`:c.add(`computer-use-2024-10-22`),u.push({name:`bash`,type:`bash_20241022`,cache_control:void 0});break;case`anthropic.memory_20250818`:c.add(`context-management-2025-06-27`),u.push({name:`memory`,type:`memory_20250818`});break;case`anthropic.web_fetch_20250910`:{c.add(`web-fetch-2025-09-10`);let e=await S({value:t.args,schema:Te});u.push({type:`web_fetch_20250910`,name:`web_fetch`,max_uses:e.maxUses,allowed_domains:e.allowedDomains,blocked_domains:e.blockedDomains,citations:e.citations,max_content_tokens:e.maxContentTokens,cache_control:void 0});break}case`anthropic.web_fetch_20260209`:{c.add(`code-execution-web-tools-2026-02-09`);let e=await S({value:t.args,schema:xe});u.push({type:`web_fetch_20260209`,name:`web_fetch`,max_uses:e.maxUses,allowed_domains:e.allowedDomains,blocked_domains:e.blockedDomains,citations:e.citations,max_content_tokens:e.maxContentTokens,cache_control:void 0});break}case`anthropic.web_search_20250305`:{let e=await S({value:t.args,schema:_e});u.push({type:`web_search_20250305`,name:`web_search`,max_uses:e.maxUses,allowed_domains:e.allowedDomains,blocked_domains:e.blockedDomains,user_location:e.userLocation,cache_control:void 0});break}case`anthropic.web_search_20260209`:{c.add(`code-execution-web-tools-2026-02-09`);let e=await S({value:t.args,schema:pe});u.push({type:`web_search_20260209`,name:`web_search`,max_uses:e.maxUses,allowed_domains:e.allowedDomains,blocked_domains:e.blockedDomains,user_location:e.userLocation,cache_control:void 0});break}case`anthropic.tool_search_regex_20251119`:u.push({type:`tool_search_tool_regex_20251119`,name:`tool_search_tool_regex`});break;case`anthropic.tool_search_bm25_20251119`:u.push({type:`tool_search_tool_bm25_20251119`,name:`tool_search_tool_bm25`});break;default:s.push({type:`unsupported`,feature:`provider-defined tool ${t.id}`});break}break;default:s.push({type:`unsupported`,feature:`tool ${t}`});break}if(t==null)return{tools:u,toolChoice:n?{type:`auto`,disable_parallel_tool_use:n}:void 0,toolWarnings:s,betas:c};let d=t.type;switch(d){case`auto`:return{tools:u,toolChoice:{type:`auto`,disable_parallel_tool_use:n},toolWarnings:s,betas:c};case`required`:return{tools:u,toolChoice:{type:`any`,disable_parallel_tool_use:n},toolWarnings:s,betas:c};case`none`:return{tools:void 0,toolChoice:void 0,toolWarnings:s,betas:c};case`tool`:return{tools:u,toolChoice:{type:`tool`,name:t.toolName,disable_parallel_tool_use:n},toolWarnings:s,betas:c};default:throw new g({functionality:`tool choice type: ${d}`})}}function Ae({usage:e,rawUsage:t}){let n=e.cache_creation_input_tokens??0,r=e.cache_read_input_tokens??0,i,a;if(e.iterations&&e.iterations.length>0){let t=e.iterations.reduce((e,t)=>({input:e.input+t.input_tokens,output:e.output+t.output_tokens}),{input:0,output:0});i=t.input,a=t.output}else i=e.input_tokens,a=e.output_tokens;return{inputTokens:{total:i+n+r,noCache:i,cacheRead:r,cacheWrite:n},outputTokens:{total:a,text:void 0,reasoning:void 0},raw:t??e}}var je=O(()=>w(o({type:l(`code_execution_result`),stdout:a(),stderr:a(),return_code:d(),content:n(o({type:l(`code_execution_output`),file_id:a()})).optional().default([])}))),Me=I({id:`anthropic.code_execution_20250522`,inputSchema:O(()=>w(o({code:a()}))),outputSchema:je}),Ne=(e={})=>Me(e),Pe=O(()=>w(t(`type`,[o({type:l(`code_execution_result`),stdout:a(),stderr:a(),return_code:d(),content:n(o({type:l(`code_execution_output`),file_id:a()})).optional().default([])}),o({type:l(`bash_code_execution_result`),content:n(o({type:l(`bash_code_execution_output`),file_id:a()})),stdout:a(),stderr:a(),return_code:d()}),o({type:l(`bash_code_execution_tool_result_error`),error_code:a()}),o({type:l(`text_editor_code_execution_tool_result_error`),error_code:a()}),o({type:l(`text_editor_code_execution_view_result`),content:a(),file_type:a(),num_lines:d().nullable(),start_line:d().nullable(),total_lines:d().nullable()}),o({type:l(`text_editor_code_execution_create_result`),is_file_update:e()}),o({type:l(`text_editor_code_execution_str_replace_result`),lines:n(a()).nullable(),new_lines:d().nullable(),new_start:d().nullable(),old_lines:d().nullable(),old_start:d().nullable()})]))),Fe=I({id:`anthropic.code_execution_20250825`,inputSchema:O(()=>w(t(`type`,[o({type:l(`programmatic-tool-call`),code:a()}),o({type:l(`bash_code_execution`),command:a()}),t(`command`,[o({type:l(`text_editor_code_execution`),command:l(`view`),path:a()}),o({type:l(`text_editor_code_execution`),command:l(`create`),path:a(),file_text:a().nullish()}),o({type:l(`text_editor_code_execution`),command:l(`str_replace`),path:a(),old_str:a(),new_str:a()})])]))),outputSchema:Pe,supportsDeferredResults:!0}),Ie=(e={})=>Fe(e),Le=O(()=>w(t(`type`,[o({type:l(`code_execution_result`),stdout:a(),stderr:a(),return_code:d(),content:n(o({type:l(`code_execution_output`),file_id:a()})).optional().default([])}),o({type:l(`encrypted_code_execution_result`),encrypted_stdout:a(),stderr:a(),return_code:d(),content:n(o({type:l(`code_execution_output`),file_id:a()})).optional().default([])}),o({type:l(`bash_code_execution_result`),content:n(o({type:l(`bash_code_execution_output`),file_id:a()})),stdout:a(),stderr:a(),return_code:d()}),o({type:l(`bash_code_execution_tool_result_error`),error_code:a()}),o({type:l(`text_editor_code_execution_tool_result_error`),error_code:a()}),o({type:l(`text_editor_code_execution_view_result`),content:a(),file_type:a(),num_lines:d().nullable(),start_line:d().nullable(),total_lines:d().nullable()}),o({type:l(`text_editor_code_execution_create_result`),is_file_update:e()}),o({type:l(`text_editor_code_execution_str_replace_result`),lines:n(a()).nullable(),new_lines:d().nullable(),new_start:d().nullable(),old_lines:d().nullable(),old_start:d().nullable()})]))),Re=I({id:`anthropic.code_execution_20260120`,inputSchema:O(()=>w(t(`type`,[o({type:l(`programmatic-tool-call`),code:a()}),o({type:l(`bash_code_execution`),command:a()}),t(`command`,[o({type:l(`text_editor_code_execution`),command:l(`view`),path:a()}),o({type:l(`text_editor_code_execution`),command:l(`create`),path:a(),file_text:a().nullish()}),o({type:l(`text_editor_code_execution`),command:l(`str_replace`),path:a(),old_str:a(),new_str:a()})])]))),outputSchema:Le,supportsDeferredResults:!0}),ze=(e={})=>Re(e),Be=O(()=>w(n(o({type:l(`tool_reference`),toolName:a()})))),Ve=I({id:`anthropic.tool_search_regex_20251119`,inputSchema:O(()=>w(o({pattern:a(),limit:d().optional()}))),outputSchema:Be,supportsDeferredResults:!0}),He=(e={})=>Ve(e);function Ue(e){return typeof e==`string`?new TextDecoder().decode(L(e)):new TextDecoder().decode(e)}async function We({prompt:e,sendReasoning:t,warnings:n,cacheControlValidator:r,toolNameMapping:i}){let a=new Set,o=Ge(e),s=r||new X,c,l=[];async function u(e){return(await x({provider:`anthropic`,providerOptions:e,schema:Y}))?.citations?.enabled??!1}async function d(e){let t=await x({provider:`anthropic`,providerOptions:e,schema:Y});return{title:t?.title,context:t?.context}}for(let e=0;e<o.length;e++){let r=o[e],f=e===o.length-1,p=r.type;switch(p){case`system`:if(c!=null)throw new g({functionality:`Multiple system messages that are separated by user/assistant messages`});c=r.messages.map(({content:e,providerOptions:t})=>({type:`text`,text:e,cache_control:s.getCacheControl(t,{type:`system message`,canCache:!0})}));break;case`user`:{let e=[];for(let t of r.messages){let{role:r,content:i}=t;switch(r){case`user`:for(let n=0;n<i.length;n++){let r=i[n],o=n===i.length-1,c=s.getCacheControl(r.providerOptions,{type:`user message part`,canCache:!0})??(o?s.getCacheControl(t.providerOptions,{type:`user message`,canCache:!0}):void 0);switch(r.type){case`text`:e.push({type:`text`,text:r.text,cache_control:c});break;case`file`:switch(r.data.type){case`reference`:{let t=v({reference:r.data.reference,provider:`anthropic`});a.add(`files-api-2025-04-14`),y(r.mediaType)===`image`?e.push({type:`image`,source:{type:`file`,file_id:t},cache_control:c}):e.push({type:`document`,source:{type:`file`,file_id:t},cache_control:c});break}case`text`:{let t=await u(r.providerOptions),n=await d(r.providerOptions);e.push({type:`document`,source:{type:`text`,media_type:`text/plain`,data:r.data.text},title:n.title??r.filename,...n.context&&{context:n.context},...t&&{citations:{enabled:!0}},cache_control:c});break}case`url`:case`data`:{let t=y(r.mediaType);if(t===`image`)e.push({type:`image`,source:r.data.type===`url`?{type:`url`,url:r.data.url.toString()}:{type:`base64`,media_type:K({part:r}),data:B(r.data.data)},cache_control:c});else if(t===`application`&&(r.data.type===`url`?r.mediaType===`application/pdf`:K({part:r})===`application/pdf`)){a.add(`pdfs-2024-09-25`);let t=await u(r.providerOptions),n=await d(r.providerOptions);e.push({type:`document`,source:r.data.type===`url`?{type:`url`,url:r.data.url.toString()}:{type:`base64`,media_type:`application/pdf`,data:B(r.data.data)},title:n.title??r.filename,...n.context&&{context:n.context},...t&&{citations:{enabled:!0}},cache_control:c})}else if(r.mediaType===`text/plain`){let t=await u(r.providerOptions),n=await d(r.providerOptions);e.push({type:`document`,source:r.data.type===`url`?{type:`url`,url:r.data.url.toString()}:{type:`text`,media_type:`text/plain`,data:Ue(r.data.data)},title:n.title??r.filename,...n.context&&{context:n.context},...t&&{citations:{enabled:!0}},cache_control:c})}else throw new g({functionality:`media type: ${r.mediaType}`});break}}break}}break;case`tool`:for(let r=0;r<i.length;r++){let o=i[r];if(o.type===`tool-approval-response`)continue;let c=r===i.length-1,l=s.getCacheControl(o.providerOptions,{type:`tool result part`,canCache:!0})??(c?s.getCacheControl(t.providerOptions,{type:`tool result message`,canCache:!0}):void 0),u=o.output,d;switch(u.type){case`content`:d=u.value.map(e=>{switch(e.type){case`text`:return{type:`text`,text:e.text};case`file`:{let t=y(e.mediaType);if(e.data.type===`url`)return t===`image`?{type:`image`,source:{type:`url`,url:e.data.url.toString()}}:{type:`document`,source:{type:`url`,url:e.data.url.toString()}};if(e.data.type===`data`){if(t===`image`)return{type:`image`,source:{type:`base64`,media_type:K({part:e}),data:B(e.data.data)}};if(K({part:e})===`application/pdf`)return a.add(`pdfs-2024-09-25`),{type:`document`,source:{type:`base64`,media_type:`application/pdf`,data:B(e.data.data)}};n.push({type:`other`,message:`unsupported tool content part type: ${e.type} with media type: ${e.mediaType}`});return}n.push({type:`other`,message:`unsupported tool content part type: ${e.type} with data type: ${e.data.type}`});return}case`custom`:{let t=e.providerOptions?.anthropic;if(t?.type===`tool-reference`)return{type:`tool_reference`,tool_name:t.toolName};n.push({type:`other`,message:`unsupported custom tool content part`});return}default:n.push({type:`other`,message:`unsupported tool content part type: ${e.type}`});return}}).filter(b);break;case`text`:case`error-text`:d=u.value;break;case`execution-denied`:d=u.reason??`Tool call execution denied.`;break;default:d=JSON.stringify(u.value);break}e.push({type:`tool_result`,tool_use_id:o.toolCallId,content:d,is_error:u.type===`error-text`||u.type===`error-json`?!0:void 0,cache_control:l})}break;default:throw Error(`Unsupported role: ${r}`)}}l.push({role:`user`,content:e});break}case`assistant`:{let e=[],a=new Set;for(let o=0;o<r.messages.length;o++){let c=r.messages[o],l=o===r.messages.length-1,{content:u}=c;for(let r=0;r<u.length;r++){let o=u[r],d=r===u.length-1,p=s.getCacheControl(o.providerOptions,{type:`assistant message part`,canCache:!0})??(d?s.getCacheControl(c.providerOptions,{type:`assistant message`,canCache:!0}):void 0);switch(o.type){case`text`:o.providerOptions?.anthropic?.type===`compaction`?e.push({type:`compaction`,content:o.text,cache_control:p}):e.push({type:`text`,text:f&&l&&d?o.text.trim():o.text,cache_control:p});break;case`reasoning`:if(t){let t=await x({provider:`anthropic`,providerOptions:o.providerOptions,schema:oe});t==null?n.push({type:`other`,message:`unsupported reasoning metadata`}):t.signature==null?t.redactedData==null?n.push({type:`other`,message:`unsupported reasoning metadata`}):(s.getCacheControl(o.providerOptions,{type:`redacted thinking block`,canCache:!1}),e.push({type:`redacted_thinking`,data:t.redactedData})):(s.getCacheControl(o.providerOptions,{type:`thinking block`,canCache:!1}),e.push({type:`thinking`,thinking:o.text,signature:t.signature}))}else n.push({type:`other`,message:`sending reasoning content is disabled for this model`});break;case`tool-call`:{if(o.providerExecuted){let t=i.toProviderToolName(o.toolName);if(o.providerOptions?.anthropic?.type===`mcp-tool-use`){a.add(o.toolCallId);let t=o.providerOptions?.anthropic?.serverName;if(t==null||typeof t!=`string`){n.push({type:`other`,message:`mcp tool use server name is required and must be a string`});break}e.push({type:`mcp_tool_use`,id:o.toolCallId,name:o.toolName,input:o.input,server_name:t,cache_control:p})}else if(t===`code_execution`&&o.input!=null&&typeof o.input==`object`&&`type`in o.input&&typeof o.input.type==`string`&&(o.input.type===`bash_code_execution`||o.input.type===`text_editor_code_execution`))e.push({type:`server_tool_use`,id:o.toolCallId,name:o.input.type,input:o.input,cache_control:p});else if(t===`code_execution`&&o.input!=null&&typeof o.input==`object`&&`type`in o.input&&o.input.type===`programmatic-tool-call`){let{type:t,...n}=o.input;e.push({type:`server_tool_use`,id:o.toolCallId,name:`code_execution`,input:n,cache_control:p})}else t===`code_execution`||t===`web_fetch`||t===`web_search`||t===`tool_search_tool_regex`||t===`tool_search_tool_bm25`?e.push({type:`server_tool_use`,id:o.toolCallId,name:t,input:o.input,cache_control:p}):n.push({type:`other`,message:`provider executed tool call for tool ${o.toolName} is not supported`});break}let t=o.providerOptions?.anthropic,r=t?.caller?(t.caller.type===`code_execution_20250825`||t.caller.type===`code_execution_20260120`)&&t.caller.toolId?{type:t.caller.type,tool_id:t.caller.toolId}:t.caller.type===`direct`?{type:`direct`}:void 0:void 0;e.push({type:`tool_use`,id:o.toolCallId,name:o.toolName,input:o.input,...r&&{caller:r},cache_control:p});break}case`tool-result`:{let t=i.toProviderToolName(o.toolName);if(a.has(o.toolCallId)){let t=o.output;if(t.type!==`json`&&t.type!==`error-json`){n.push({type:`other`,message:`provider executed tool result output type ${t.type} for tool ${o.toolName} is not supported`});break}e.push({type:`mcp_tool_result`,tool_use_id:o.toolCallId,is_error:t.type===`error-json`,content:t.value,cache_control:p})}else if(t===`code_execution`){let t=o.output;if(t.type===`error-text`||t.type===`error-json`){let n={};try{typeof t.value==`string`?n=JSON.parse(t.value):typeof t.value==`object`&&t.value!==null&&(n=t.value)}catch{}n.type===`code_execution_tool_result_error`?e.push({type:`code_execution_tool_result`,tool_use_id:o.toolCallId,content:{type:`code_execution_tool_result_error`,error_code:n.errorCode??`unknown`},cache_control:p}):e.push({type:`bash_code_execution_tool_result`,tool_use_id:o.toolCallId,cache_control:p,content:{type:`bash_code_execution_tool_result_error`,error_code:n.errorCode??`unknown`}});break}if(t.type!==`json`){n.push({type:`other`,message:`provider executed tool result output type ${t.type} for tool ${o.toolName} is not supported`});break}if(t.value==null||typeof t.value!=`object`||!(`type`in t.value)||typeof t.value.type!=`string`){n.push({type:`other`,message:`provider executed tool result output value is not a valid code execution result for tool ${o.toolName}`});break}if(t.value.type===`code_execution_result`){let n=await S({value:t.value,schema:je});e.push({type:`code_execution_tool_result`,tool_use_id:o.toolCallId,content:{type:n.type,stdout:n.stdout,stderr:n.stderr,return_code:n.return_code,content:n.content??[]},cache_control:p})}else if(t.value.type===`encrypted_code_execution_result`){let n=await S({value:t.value,schema:Le});n.type===`encrypted_code_execution_result`&&e.push({type:`code_execution_tool_result`,tool_use_id:o.toolCallId,content:{type:n.type,encrypted_stdout:n.encrypted_stdout,stderr:n.stderr,return_code:n.return_code,content:n.content??[]},cache_control:p})}else{let n=await S({value:t.value,schema:Pe});n.type===`code_execution_result`?e.push({type:`code_execution_tool_result`,tool_use_id:o.toolCallId,content:{type:n.type,stdout:n.stdout,stderr:n.stderr,return_code:n.return_code,content:n.content??[]},cache_control:p}):n.type===`bash_code_execution_result`||n.type===`bash_code_execution_tool_result_error`?e.push({type:`bash_code_execution_tool_result`,tool_use_id:o.toolCallId,cache_control:p,content:n}):e.push({type:`text_editor_code_execution_tool_result`,tool_use_id:o.toolCallId,cache_control:p,content:n})}break}if(t===`web_fetch`){let t=o.output;if(t.type===`error-json`){let n={};try{typeof t.value==`string`?n=JSON.parse(t.value):typeof t.value==`object`&&t.value!==null&&(n=t.value)}catch{let e=t.value?.errorCode;n={errorCode:typeof e==`string`?e:`unavailable`}}e.push({type:`web_fetch_tool_result`,tool_use_id:o.toolCallId,content:{type:`web_fetch_tool_result_error`,error_code:n.errorCode??`unavailable`},cache_control:p});break}if(t.type!==`json`){n.push({type:`other`,message:`provider executed tool result output type ${t.type} for tool ${o.toolName} is not supported`});break}let r=await S({value:t.value,schema:Ee});e.push({type:`web_fetch_tool_result`,tool_use_id:o.toolCallId,content:{type:`web_fetch_result`,url:r.url,retrieved_at:r.retrievedAt,content:{type:`document`,title:r.content.title,citations:r.content.citations,source:{type:r.content.source.type,media_type:r.content.source.mediaType,data:r.content.source.data}}},cache_control:p});break}if(t===`web_search`){let t=o.output;if(t.type!==`json`){n.push({type:`other`,message:`provider executed tool result output type ${t.type} for tool ${o.toolName} is not supported`});break}let r=await S({value:t.value,schema:ve});e.push({type:`web_search_tool_result`,tool_use_id:o.toolCallId,content:r.map(e=>({url:e.url,title:e.title,page_age:e.pageAge,encrypted_content:e.encryptedContent,type:e.type})),cache_control:p});break}if(t===`tool_search_tool_regex`||t===`tool_search_tool_bm25`){let t=o.output;if(t.type!==`json`){n.push({type:`other`,message:`provider executed tool result output type ${t.type} for tool ${o.toolName} is not supported`});break}let r=(await S({value:t.value,schema:Be})).map(e=>({type:`tool_reference`,tool_name:e.toolName}));e.push({type:`tool_search_tool_result`,tool_use_id:o.toolCallId,content:{type:`tool_search_tool_search_result`,tool_references:r},cache_control:p});break}n.push({type:`other`,message:`provider executed tool result for tool ${o.toolName} is not supported`});break}}}}l.push({role:`assistant`,content:e});break}default:throw Error(`content type: ${p}`)}}return{prompt:{system:c,messages:l},betas:a}}function Ge(e){let t=[],n;for(let r of e){let{role:e}=r;switch(e){case`system`:n?.type!==`system`&&(n={type:`system`,messages:[]},t.push(n)),n.messages.push(r);break;case`assistant`:n?.type!==`assistant`&&(n={type:`assistant`,messages:[]},t.push(n)),n.messages.push(r);break;case`user`:n?.type!==`user`&&(n={type:`user`,messages:[]},t.push(n)),n.messages.push(r);break;case`tool`:n?.type!==`user`&&(n={type:`user`,messages:[]},t.push(n)),n.messages.push(r);break;default:throw Error(`Unsupported role: ${e}`)}}return t}function Z({finishReason:e,isJsonResponseFromTool:t}){switch(e){case`pause_turn`:case`end_turn`:case`stop_sequence`:return`stop`;case`refusal`:return`content-filter`;case`tool_use`:return t?`stop`:`tool-calls`;case`max_tokens`:case`model_context_window_exceeded`:return`length`;case`compaction`:return`other`;default:return`other`}}var Ke=new Set([`date-time`,`time`,`date`,`duration`,`email`,`hostname`,`uri`,`ipv4`,`ipv6`,`uuid`]),qe=[`minimum`,`maximum`,`exclusiveMinimum`,`exclusiveMaximum`,`multipleOf`,`minLength`,`maxLength`,`pattern`,`minItems`,`maxItems`,`uniqueItems`,`minProperties`,`maxProperties`,`not`];function Je(e){return Ye(e)}function Q(e){return typeof e==`boolean`||!$e(e)?e:Ye(e)}function Ye(e){let t={},n=e;if(e.$ref!=null)return{$ref:e.$ref};if(e.$schema!=null&&(t.$schema=e.$schema),e.$id!=null&&(t.$id=e.$id),e.title!=null&&(t.title=e.title),e.description!=null&&(t.description=e.description),e.default!==void 0&&(t.default=e.default),e.const!==void 0&&(t.const=e.const),e.enum!=null&&(t.enum=e.enum),e.type!=null&&(t.type=e.type),e.anyOf==null?e.oneOf!=null&&(t.anyOf=e.oneOf.map(Q)):t.anyOf=e.anyOf.map(Q),e.allOf!=null&&(t.allOf=e.allOf.map(Q)),e.definitions!=null&&(t.definitions=Object.fromEntries(Object.entries(e.definitions).map(([e,t])=>[e,Q(t)]))),n.$defs!=null){let e=t;e.$defs=Object.fromEntries(Object.entries(n.$defs).map(([e,t])=>[e,Q(t)]))}(e.type===`object`||e.properties!=null)&&(e.properties!=null&&(t.properties=Object.fromEntries(Object.entries(e.properties).map(([e,t])=>[e,Q(t)]))),t.additionalProperties=!1,e.required!=null&&(t.required=e.required)),e.items!=null&&(t.items=Array.isArray(e.items)?e.items.map(Q):Q(e.items)),typeof e.format==`string`&&Ke.has(e.format)&&(t.format=e.format);let r=Xe(e);return r!=null&&(t.description=t.description==null?r:`${t.description}
|
|
2
|
-
${r}`),t}function Xe(e){let t=qe.flatMap(t=>{let n=e[t];return n==null||n===!1?[]:`${Ze(t)}: ${Qe(n)}`});return typeof e.format==`string`&&!Ke.has(e.format)&&t.push(`format: ${e.format}`),t.length===0?void 0:`${t.join(`; `)}.`}function Ze(e){return e.replace(/[A-Z]/g,e=>` ${e.toLowerCase()}`)}function Qe(e){return typeof e==`string`?e:JSON.stringify(e)}function $e(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function $(e,t,n){if(e.type===`web_search_result_location`)return{type:`source`,sourceType:`url`,id:n(),url:e.url,title:e.title,providerMetadata:{anthropic:{citedText:e.cited_text,encryptedIndex:e.encrypted_index}}};if(e.type!==`page_location`&&e.type!==`char_location`)return;let r=t[e.document_index];if(r)return{type:`source`,sourceType:`document`,id:n(),mediaType:r.mediaType,title:e.document_title??r.title,filename:r.filename,providerMetadata:{anthropic:e.type===`page_location`?{citedText:e.cited_text,startPageNumber:e.start_page_number,endPageNumber:e.end_page_number}:{citedText:e.cited_text,startCharIndex:e.start_char_index,endCharIndex:e.end_char_index}}}}var et=class e{constructor(e,t){this.specificationVersion=`v4`,this.modelId=e,this.config=t,this.generateId=t.generateId??N}static[A](e){return ee({modelId:e.modelId,config:e.config})}static[j](t){return new e(t.modelId,t.config)}supportsUrl(e){return e.protocol===`https:`}get provider(){return this.config.provider}get providerOptionsName(){let e=this.config.provider,t=e.indexOf(`.`);return t===-1?e:e.substring(0,t)}get supportedUrls(){var e;return(e=this.config).supportedUrls?.call(e)??{}}async getArgs({userSuppliedBetas:e,prompt:t,maxOutputTokens:n,temperature:r,topP:i,topK:a,frequencyPenalty:o,presencePenalty:s,stopSequences:c,responseFormat:l,seed:u,tools:d,toolChoice:f,reasoning:p,providerOptions:m,stream:h}){let g=[];o!=null&&g.push({type:`unsupported`,feature:`frequencyPenalty`}),s!=null&&g.push({type:`unsupported`,feature:`presencePenalty`}),u!=null&&g.push({type:`unsupported`,feature:`seed`}),r!=null&&r>1?(g.push({type:`unsupported`,feature:`temperature`,details:`${r} exceeds anthropic maximum of 1.0. clamped to 1.0`}),r=1):r!=null&&r<0&&(g.push({type:`unsupported`,feature:`temperature`,details:`${r} is below anthropic minimum of 0. clamped to 0`}),r=0),l?.type===`json`&&(l.schema??g.push({type:`unsupported`,feature:`responseFormat`,details:`JSON response format requires a schema. The response format is ignored.`}));let _=this.providerOptionsName,y=await x({provider:`anthropic`,providerOptions:m,schema:se}),b=_===`anthropic`?null:await x({provider:_,providerOptions:m,schema:se}),S=b!=null,C=Object.assign({},y??{},b??{}),{maxOutputTokens:w,supportsStructuredOutput:T,supportsAdaptiveThinking:E,rejectsSamplingParameters:D,supportsXhighEffort:O,isKnownModel:k}=tt(this.modelId);D&&(r!=null&&(g.push({type:`unsupported`,feature:`temperature`,details:`temperature is not supported by ${this.modelId} and will be ignored`}),r=void 0),a!=null&&(g.push({type:`unsupported`,feature:`topK`,details:`topK is not supported by ${this.modelId} and will be ignored`}),a=void 0),i!=null&&(g.push({type:`unsupported`,feature:`topP`,details:`topP is not supported by ${this.modelId} and will be ignored`}),i=void 0));let ee=k||this.modelId.startsWith(`claude-`),A=(this.config.supportsNativeStructuredOutput??!0)&&T,j=(this.config.supportsStrictTools??!0)&&T,M=C?.structuredOutputMode??`auto`,N=M===`outputFormat`||M===`auto`&&A,P=l?.type===`json`&&l.schema!=null&&!N?{type:`function`,name:`json`,description:`Respond with a JSON object.`,inputSchema:l.schema}:void 0,F=C?.contextManagement,I=new X,L=te({tools:d,providerToolNames:{"anthropic.code_execution_20250522":`code_execution`,"anthropic.code_execution_20250825":`code_execution`,"anthropic.code_execution_20260120":`code_execution`,"anthropic.computer_20241022":`computer`,"anthropic.computer_20250124":`computer`,"anthropic.text_editor_20241022":`str_replace_editor`,"anthropic.text_editor_20250124":`str_replace_editor`,"anthropic.text_editor_20250429":`str_replace_based_edit_tool`,"anthropic.text_editor_20250728":`str_replace_based_edit_tool`,"anthropic.bash_20241022":`bash`,"anthropic.bash_20250124":`bash`,"anthropic.memory_20250818":`memory`,"anthropic.web_search_20250305":`web_search`,"anthropic.web_search_20260209":`web_search`,"anthropic.web_fetch_20250910":`web_fetch`,"anthropic.web_fetch_20260209":`web_fetch`,"anthropic.tool_search_regex_20251119":`tool_search_tool_regex`,"anthropic.tool_search_bm25_20251119":`tool_search_tool_bm25`}}),{prompt:R,betas:z}=await We({prompt:t,sendReasoning:C?.sendReasoning??!0,warnings:g,cacheControlValidator:I,toolNameMapping:L});if(ne(p)&&C?.effort==null){let e=rt({reasoning:p,supportsAdaptiveThinking:E,supportsXhighEffort:O,maxOutputTokensForModel:w,warnings:g});e!=null&&(C.thinking??=e.thinking,e.effort!=null&&C.thinking?.type!==`disabled`&&(C.effort=e.effort))}let B=C?.thinking?.type,V=B===`enabled`||B===`adaptive`,H=B===`enabled`?C?.thinking?.budgetTokens:void 0,U=B===`adaptive`?C?.thinking?.display:void 0,W=n??w,G={model:this.modelId,max_tokens:W,temperature:r,top_k:a,top_p:i,stop_sequences:c,...V&&{thinking:{type:B,...H!=null&&{budget_tokens:H},...U!=null&&{display:U}}},...(C?.effort||C?.taskBudget||N&&l?.type===`json`&&l.schema!=null)&&{output_config:{...C?.effort&&{effort:C.effort},...C?.taskBudget&&{task_budget:{type:C.taskBudget.type,total:C.taskBudget.total,...C.taskBudget.remaining!=null&&{remaining:C.taskBudget.remaining}}},...N&&l?.type===`json`&&l.schema!=null&&{format:{type:`json_schema`,schema:Je(l.schema)}}}},...C?.speed&&{speed:C.speed},...C?.inferenceGeo&&{inference_geo:C.inferenceGeo},...C?.cacheControl&&{cache_control:C.cacheControl},...C?.metadata?.userId!=null&&{metadata:{user_id:C.metadata.userId}},...C?.mcpServers&&C.mcpServers.length>0&&{mcp_servers:C.mcpServers.map(e=>({type:e.type,name:e.name,url:e.url,authorization_token:e.authorizationToken,tool_configuration:e.toolConfiguration?{allowed_tools:e.toolConfiguration.allowedTools,enabled:e.toolConfiguration.enabled}:void 0}))},...C?.container&&{container:C.container.skills&&C.container.skills.length>0?{id:C.container.id,skills:C.container.skills.map(e=>({type:e.type,skill_id:e.type===`custom`?v({reference:e.providerReference,provider:`anthropic`}):e.skillId,version:e.version}))}:C.container.id},system:R.system,messages:R.messages,...F&&{context_management:{edits:F.edits.map(e=>{let t=e.type;switch(t){case`clear_tool_uses_20250919`:return{type:e.type,...e.trigger!==void 0&&{trigger:e.trigger},...e.keep!==void 0&&{keep:e.keep},...e.clearAtLeast!==void 0&&{clear_at_least:e.clearAtLeast},...e.clearToolInputs!==void 0&&{clear_tool_inputs:e.clearToolInputs},...e.excludeTools!==void 0&&{exclude_tools:e.excludeTools}};case`clear_thinking_20251015`:return{type:e.type,...e.keep!==void 0&&{keep:e.keep}};case`compact_20260112`:return{type:e.type,...e.trigger!==void 0&&{trigger:e.trigger},...e.pauseAfterCompaction!==void 0&&{pause_after_compaction:e.pauseAfterCompaction},...e.instructions!==void 0&&{instructions:e.instructions}};default:g.push({type:`other`,message:`Unknown context management strategy: ${t}`});return}}).filter(e=>e!==void 0)}}};V?(B===`enabled`&&H==null&&(g.push({type:`compatibility`,feature:`extended thinking`,details:`thinking budget is required when thinking is enabled. using default budget of 1024 tokens.`}),G.thinking={type:`enabled`,budget_tokens:1024},H=1024),G.temperature!=null&&(G.temperature=void 0,g.push({type:`unsupported`,feature:`temperature`,details:`temperature is not supported when thinking is enabled`})),a!=null&&(G.top_k=void 0,g.push({type:`unsupported`,feature:`topK`,details:`topK is not supported when thinking is enabled`})),i!=null&&(G.top_p=void 0,g.push({type:`unsupported`,feature:`topP`,details:`topP is not supported when thinking is enabled`})),G.max_tokens=W+(H??0)):ee&&i!=null&&r!=null&&(g.push({type:`unsupported`,feature:`topP`,details:`topP is not supported when temperature is set. topP is ignored.`}),G.top_p=void 0),k&&G.max_tokens>w&&(n!=null&&g.push({type:`unsupported`,feature:`maxOutputTokens`,details:`${G.max_tokens} (maxOutputTokens + thinkingBudget) is greater than ${this.modelId} ${w} max output tokens. The max output tokens have been limited to ${w}.`}),G.max_tokens=w),C?.mcpServers&&C.mcpServers.length>0&&z.add(`mcp-client-2025-04-04`),F&&(z.add(`context-management-2025-06-27`),F.edits.some(e=>e.type===`compact_20260112`)&&z.add(`compact-2026-01-12`)),C?.container&&C.container.skills&&C.container.skills.length>0&&(z.add(`code-execution-2025-08-25`),z.add(`skills-2025-10-02`),z.add(`files-api-2025-04-14`),d?.some(e=>e.type===`provider`&&(e.id===`anthropic.code_execution_20250825`||e.id===`anthropic.code_execution_20260120`))||g.push({type:`other`,message:`code execution tool is required when using skills`})),C?.taskBudget&&z.add(`task-budgets-2026-03-13`),C?.speed===`fast`&&z.add(`fast-mode-2026-02-01`);let K=h&&(C?.toolStreaming??!0),{tools:q,toolChoice:re,toolWarnings:ie,betas:ae}=await ke(P==null?{tools:d??[],toolChoice:f,disableParallelToolUse:C?.disableParallelToolUse,cacheControlValidator:I,supportsStructuredOutput:A,supportsStrictTools:j,defaultEagerInputStreaming:K}:{tools:[...d??[],P],toolChoice:{type:`required`},disableParallelToolUse:!0,cacheControlValidator:I,supportsStructuredOutput:!1,supportsStrictTools:j,defaultEagerInputStreaming:K}),J=I.getWarnings();return{args:{...G,tools:q,tool_choice:re,stream:h===!0?!0:void 0},warnings:[...g,...ie,...J],betas:new Set([...z,...ae,...e,...C?.anthropicBeta??[]]),usesJsonResponseTool:P!=null,toolNameMapping:L,providerOptionsName:_,usedCustomProviderKey:S}}async getHeaders({betas:e,headers:t}){return U(this.config.headers?await k(this.config.headers):void 0,t,e.size>0?{"anthropic-beta":Array.from(e).join(`,`)}:{})}async getBetasFromHeaders(e){let t=(this.config.headers?await k(this.config.headers):void 0)?.[`anthropic-beta`]??``,n=e?.[`anthropic-beta`]??``;return new Set([...t.toLowerCase().split(`,`),...n.toLowerCase().split(`,`)].map(e=>e.trim()).filter(e=>e!==``))}buildRequestUrl(e){var t;return(t=this.config).buildRequestUrl?.call(t,this.config.baseURL,e)??`${this.config.baseURL}/messages`}transformRequestBody(e,t){var n;return(n=this.config).transformRequestBody?.call(n,e,t)??e}extractCitationDocuments(e){return e.filter(e=>e.role===`user`).flatMap(e=>e.content).filter(e=>e.type!==`file`||e.mediaType!==`application/pdf`&&e.mediaType!==`text/plain`?!1:e.providerOptions?.anthropic?.citations?.enabled??!1).map(e=>{let t=e;return{title:t.filename??`Untitled Document`,filename:t.filename,mediaType:t.mediaType}})}async doGenerate(e){let{args:t,warnings:n,betas:r,usesJsonResponseTool:i,toolNameMapping:a,providerOptionsName:o,usedCustomProviderKey:s}=await this.getArgs({...e,stream:!1,userSuppliedBetas:await this.getBetasFromHeaders(e.headers)}),c=[...this.extractCitationDocuments(e.prompt)],l=nt(t.tools),{responseHeaders:u,value:d,rawValue:f}=await E({url:this.buildRequestUrl(!1),headers:await this.getHeaders({betas:r,headers:e.headers}),body:this.transformRequestBody(t,r),failedResponseHandler:q,successfulResponseHandler:F(ae),abortSignal:e.abortSignal,fetch:this.config.fetch}),p=[],m={},h={},g=!1;for(let e of d.content)switch(e.type){case`text`:if(!i&&(p.push({type:`text`,text:e.text}),e.citations))for(let t of e.citations){let e=$(t,c,this.generateId);e&&p.push(e)}break;case`thinking`:p.push({type:`reasoning`,text:e.thinking,providerMetadata:{anthropic:{signature:e.signature}}});break;case`redacted_thinking`:p.push({type:`reasoning`,text:``,providerMetadata:{anthropic:{redactedData:e.data}}});break;case`compaction`:p.push({type:`text`,text:e.content,providerMetadata:{anthropic:{type:`compaction`}}});break;case`tool_use`:if(i&&e.name===`json`)g=!0,p.push({type:`text`,text:JSON.stringify(e.input)});else{let t=e.caller,n=t?{type:t.type,toolId:`tool_id`in t?t.tool_id:void 0}:void 0;p.push({type:`tool-call`,toolCallId:e.id,toolName:e.name,input:JSON.stringify(e.input),...n&&{providerMetadata:{anthropic:{caller:n}}}})}break;case`server_tool_use`:if(e.name===`text_editor_code_execution`||e.name===`bash_code_execution`)p.push({type:`tool-call`,toolCallId:e.id,toolName:a.toCustomToolName(`code_execution`),input:JSON.stringify({type:e.name,...e.input}),providerExecuted:!0});else if(e.name===`web_search`||e.name===`code_execution`||e.name===`web_fetch`){let t=e.name===`code_execution`&&e.input!=null&&typeof e.input==`object`&&`code`in e.input&&!(`type`in e.input)?{type:`programmatic-tool-call`,...e.input}:e.input;p.push({type:`tool-call`,toolCallId:e.id,toolName:a.toCustomToolName(e.name),input:JSON.stringify(t),providerExecuted:!0,...l&&e.name===`code_execution`?{dynamic:!0}:{}})}else (e.name===`tool_search_tool_regex`||e.name===`tool_search_tool_bm25`)&&(h[e.id]=e.name,p.push({type:`tool-call`,toolCallId:e.id,toolName:a.toCustomToolName(e.name),input:JSON.stringify(e.input),providerExecuted:!0}));break;case`mcp_tool_use`:m[e.id]={type:`tool-call`,toolCallId:e.id,toolName:e.name,input:JSON.stringify(e.input),providerExecuted:!0,dynamic:!0,providerMetadata:{anthropic:{type:`mcp-tool-use`,serverName:e.server_name}}},p.push(m[e.id]);break;case`mcp_tool_result`:p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:m[e.tool_use_id].toolName,isError:e.is_error,result:e.content,dynamic:!0,providerMetadata:m[e.tool_use_id].providerMetadata});break;case`web_fetch_tool_result`:e.content.type===`web_fetch_result`?(c.push({title:e.content.content.title??e.content.url,mediaType:e.content.content.source.media_type}),p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`web_fetch`),result:{type:`web_fetch_result`,url:e.content.url,retrievedAt:e.content.retrieved_at,content:{type:e.content.content.type,title:e.content.content.title,citations:e.content.content.citations,source:{type:e.content.content.source.type,mediaType:e.content.content.source.media_type,data:e.content.content.source.data}}}})):e.content.type===`web_fetch_tool_result_error`&&p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`web_fetch`),isError:!0,result:{type:`web_fetch_tool_result_error`,errorCode:e.content.error_code}});break;case`web_search_tool_result`:if(Array.isArray(e.content)){p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`web_search`),result:e.content.map(e=>({url:e.url,title:e.title,pageAge:e.page_age??null,encryptedContent:e.encrypted_content,type:e.type}))});for(let t of e.content)p.push({type:`source`,sourceType:`url`,id:this.generateId(),url:t.url,title:t.title,providerMetadata:{anthropic:{pageAge:t.page_age??null}}})}else p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`web_search`),isError:!0,result:{type:`web_search_tool_result_error`,errorCode:e.content.error_code}});break;case`code_execution_tool_result`:e.content.type===`code_execution_result`?p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`code_execution`),result:{type:e.content.type,stdout:e.content.stdout,stderr:e.content.stderr,return_code:e.content.return_code,content:e.content.content??[]}}):e.content.type===`encrypted_code_execution_result`?p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`code_execution`),result:{type:e.content.type,encrypted_stdout:e.content.encrypted_stdout,stderr:e.content.stderr,return_code:e.content.return_code,content:e.content.content??[]}}):e.content.type===`code_execution_tool_result_error`&&p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`code_execution`),isError:!0,result:{type:`code_execution_tool_result_error`,errorCode:e.content.error_code}});break;case`bash_code_execution_tool_result`:case`text_editor_code_execution_tool_result`:p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`code_execution`),result:e.content});break;case`tool_search_tool_result`:{let t=h[e.tool_use_id];if(t==null){let e=a.toCustomToolName(`tool_search_tool_bm25`);a.toCustomToolName(`tool_search_tool_regex`),t=e===`tool_search_tool_bm25`?`tool_search_tool_regex`:`tool_search_tool_bm25`}e.content.type===`tool_search_tool_search_result`?p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(t),result:e.content.tool_references.map(e=>({type:e.type,toolName:e.tool_name}))}):p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(t),isError:!0,result:{type:`tool_search_tool_result_error`,errorCode:e.content.error_code}});break}}return{content:p,finishReason:{unified:Z({finishReason:d.stop_reason,isJsonResponseFromTool:g}),raw:d.stop_reason??void 0},usage:Ae({usage:d.usage}),request:{body:t},response:{id:d.id??void 0,modelId:d.model??void 0,headers:u,body:f},warnings:n,providerMetadata:(()=>{let e={usage:d.usage,stopSequence:d.stop_sequence??null,iterations:d.usage.iterations?d.usage.iterations.map(e=>({type:e.type,inputTokens:e.input_tokens,outputTokens:e.output_tokens})):null,container:d.container?{expiresAt:d.container.expires_at,id:d.container.id,skills:d.container.skills?.map(e=>({type:e.type,skillId:e.skill_id,version:e.version}))??null}:null,contextManagement:it(d.context_management)??null},t={anthropic:e};return s&&o!==`anthropic`&&(t[o]=e),t})()}}async doStream(e){"use step";let{args:t,warnings:n,betas:r,usesJsonResponseTool:i,toolNameMapping:a,providerOptionsName:o,usedCustomProviderKey:s}=await this.getArgs({...e,stream:!0,userSuppliedBetas:await this.getBetasFromHeaders(e.headers)}),c=[...this.extractCitationDocuments(e.prompt)],l=nt(t.tools),u=this.buildRequestUrl(!0),{responseHeaders:d,value:f}=await E({url:u,headers:await this.getHeaders({betas:r,headers:e.headers}),body:this.transformRequestBody(t,r),failedResponseHandler:q,successfulResponseHandler:W(J),abortSignal:e.abortSignal,fetch:this.config.fetch}),m={unified:`other`,raw:void 0},h={input_tokens:0,output_tokens:0,cache_creation_input_tokens:0,cache_read_input_tokens:0,iterations:null},g={},_={},v={},y=null,b,x=null,S=null,C=!1,w,T=this.generateId,[D,O]=f.pipeThrough(new TransformStream({start(e){e.enqueue({type:`stream-start`,warnings:n})},transform(t,n){if(e.includeRawChunks&&n.enqueue({type:`raw`,rawValue:t.rawValue}),!t.success){n.enqueue({type:`error`,error:t.error});return}let r=t.value;switch(r.type){case`ping`:return;case`content_block_start`:{let e=r.content_block,t=e.type;switch(w=t,t){case`text`:if(i)return;g[r.index]={type:`text`},n.enqueue({type:`text-start`,id:String(r.index)});return;case`thinking`:g[r.index]={type:`reasoning`},n.enqueue({type:`reasoning-start`,id:String(r.index)});return;case`redacted_thinking`:g[r.index]={type:`reasoning`},n.enqueue({type:`reasoning-start`,id:String(r.index),providerMetadata:{anthropic:{redactedData:e.data}}});return;case`compaction`:g[r.index]={type:`text`},n.enqueue({type:`text-start`,id:String(r.index),providerMetadata:{anthropic:{type:`compaction`}}});return;case`tool_use`:if(i&&e.name===`json`)C=!0,g[r.index]={type:`text`},n.enqueue({type:`text-start`,id:String(r.index)});else{let t=e.caller,i=t?{type:t.type,toolId:`tool_id`in t?t.tool_id:void 0}:void 0,a=e.input&&Object.keys(e.input).length>0?JSON.stringify(e.input):``;g[r.index]={type:`tool-call`,toolCallId:e.id,toolName:e.name,input:a,firstDelta:a.length===0,...i&&{caller:i}},n.enqueue({type:`tool-input-start`,id:e.id,toolName:e.name})}return;case`server_tool_use`:if([`web_fetch`,`web_search`,`code_execution`,`text_editor_code_execution`,`bash_code_execution`].includes(e.name)){let t=e.name===`text_editor_code_execution`||e.name===`bash_code_execution`?`code_execution`:e.name,i=a.toCustomToolName(t),o=e.input!=null&&typeof e.input==`object`&&Object.keys(e.input).length>0?JSON.stringify(e.input):``;g[r.index]={type:`tool-call`,toolCallId:e.id,toolName:i,input:o,providerExecuted:!0,...l&&t===`code_execution`?{dynamic:!0}:{},firstDelta:!0,providerToolName:e.name},n.enqueue({type:`tool-input-start`,id:e.id,toolName:i,providerExecuted:!0,...l&&t===`code_execution`?{dynamic:!0}:{}})}else if(e.name===`tool_search_tool_regex`||e.name===`tool_search_tool_bm25`){v[e.id]=e.name;let t=a.toCustomToolName(e.name);g[r.index]={type:`tool-call`,toolCallId:e.id,toolName:t,input:``,providerExecuted:!0,firstDelta:!0,providerToolName:e.name},n.enqueue({type:`tool-input-start`,id:e.id,toolName:t,providerExecuted:!0})}return;case`web_fetch_tool_result`:e.content.type===`web_fetch_result`?(c.push({title:e.content.content.title??e.content.url,mediaType:e.content.content.source.media_type}),n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`web_fetch`),result:{type:`web_fetch_result`,url:e.content.url,retrievedAt:e.content.retrieved_at,content:{type:e.content.content.type,title:e.content.content.title,citations:e.content.content.citations,source:{type:e.content.content.source.type,mediaType:e.content.content.source.media_type,data:e.content.content.source.data}}}})):e.content.type===`web_fetch_tool_result_error`&&n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`web_fetch`),isError:!0,result:{type:`web_fetch_tool_result_error`,errorCode:e.content.error_code}});return;case`web_search_tool_result`:if(Array.isArray(e.content)){n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`web_search`),result:e.content.map(e=>({url:e.url,title:e.title,pageAge:e.page_age??null,encryptedContent:e.encrypted_content,type:e.type}))});for(let t of e.content)n.enqueue({type:`source`,sourceType:`url`,id:T(),url:t.url,title:t.title,providerMetadata:{anthropic:{pageAge:t.page_age??null}}})}else n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`web_search`),isError:!0,result:{type:`web_search_tool_result_error`,errorCode:e.content.error_code}});return;case`code_execution_tool_result`:e.content.type===`code_execution_result`?n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`code_execution`),result:{type:e.content.type,stdout:e.content.stdout,stderr:e.content.stderr,return_code:e.content.return_code,content:e.content.content??[]}}):e.content.type===`encrypted_code_execution_result`?n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`code_execution`),result:{type:e.content.type,encrypted_stdout:e.content.encrypted_stdout,stderr:e.content.stderr,return_code:e.content.return_code,content:e.content.content??[]}}):e.content.type===`code_execution_tool_result_error`&&n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`code_execution`),isError:!0,result:{type:`code_execution_tool_result_error`,errorCode:e.content.error_code}});return;case`bash_code_execution_tool_result`:case`text_editor_code_execution_tool_result`:n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`code_execution`),result:e.content});return;case`tool_search_tool_result`:{let t=v[e.tool_use_id];if(t==null){let e=a.toCustomToolName(`tool_search_tool_bm25`);a.toCustomToolName(`tool_search_tool_regex`),t=e===`tool_search_tool_bm25`?`tool_search_tool_regex`:`tool_search_tool_bm25`}e.content.type===`tool_search_tool_search_result`?n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(t),result:e.content.tool_references.map(e=>({type:e.type,toolName:e.tool_name}))}):n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(t),isError:!0,result:{type:`tool_search_tool_result_error`,errorCode:e.content.error_code}});return}case`mcp_tool_use`:_[e.id]={type:`tool-call`,toolCallId:e.id,toolName:e.name,input:JSON.stringify(e.input),providerExecuted:!0,dynamic:!0,providerMetadata:{anthropic:{type:`mcp-tool-use`,serverName:e.server_name}}},n.enqueue(_[e.id]);return;case`mcp_tool_result`:n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:_[e.tool_use_id].toolName,isError:e.is_error,result:e.content,dynamic:!0,providerMetadata:_[e.tool_use_id].providerMetadata});return;default:throw Error(`Unsupported content block type: ${t}`)}}case`content_block_stop`:if(g[r.index]!=null){let e=g[r.index];switch(e.type){case`text`:n.enqueue({type:`text-end`,id:String(r.index)});break;case`reasoning`:n.enqueue({type:`reasoning-end`,id:String(r.index)});break;case`tool-call`:if(!(i&&e.toolName===`json`)){n.enqueue({type:`tool-input-end`,id:e.toolCallId});let t=e.input===``?`{}`:e.input;if(e.providerToolName===`code_execution`)try{let e=JSON.parse(t);typeof e==`object`&&e&&`code`in e&&!(`type`in e)&&(t=JSON.stringify({type:`programmatic-tool-call`,...e}))}catch{}n.enqueue({type:`tool-call`,toolCallId:e.toolCallId,toolName:e.toolName,input:t,providerExecuted:e.providerExecuted,...l&&e.providerToolName===`code_execution`?{dynamic:!0}:{},...e.caller&&{providerMetadata:{anthropic:{caller:e.caller}}}})}break}delete g[r.index]}w=void 0;return;case`content_block_delta`:{let e=r.delta.type;switch(e){case`text_delta`:if(i)return;n.enqueue({type:`text-delta`,id:String(r.index),delta:r.delta.text});return;case`thinking_delta`:n.enqueue({type:`reasoning-delta`,id:String(r.index),delta:r.delta.thinking});return;case`signature_delta`:w===`thinking`&&n.enqueue({type:`reasoning-delta`,id:String(r.index),delta:``,providerMetadata:{anthropic:{signature:r.delta.signature}}});return;case`compaction_delta`:r.delta.content!=null&&n.enqueue({type:`text-delta`,id:String(r.index),delta:r.delta.content});return;case`input_json_delta`:{let e=g[r.index],t=r.delta.partial_json;if(t.length===0)return;if(C){if(e?.type!==`text`)return;n.enqueue({type:`text-delta`,id:String(r.index),delta:t})}else{if(e?.type!==`tool-call`)return;e.firstDelta&&(e.providerToolName===`bash_code_execution`||e.providerToolName===`text_editor_code_execution`)&&(t=`{"type": "${e.providerToolName}",${t.substring(1)}`),n.enqueue({type:`tool-input-delta`,id:e.toolCallId,delta:t}),e.input+=t,e.firstDelta=!1}return}case`citations_delta`:{let e=r.delta.citation,t=$(e,c,T);t&&n.enqueue(t);return}default:throw Error(`Unsupported delta type: ${e}`)}}case`message_start`:if(h.input_tokens=r.message.usage.input_tokens,h.cache_read_input_tokens=r.message.usage.cache_read_input_tokens??0,h.cache_creation_input_tokens=r.message.usage.cache_creation_input_tokens??0,b={...r.message.usage},r.message.container!=null&&(S={expiresAt:r.message.container.expires_at,id:r.message.container.id,skills:null}),r.message.stop_reason!=null&&(m={unified:Z({finishReason:r.message.stop_reason,isJsonResponseFromTool:C}),raw:r.message.stop_reason}),n.enqueue({type:`response-metadata`,id:r.message.id??void 0,modelId:r.message.model??void 0}),r.message.content!=null)for(let e=0;e<r.message.content.length;e++){let t=r.message.content[e];if(t.type===`tool_use`){let e=t.caller,r=e?{type:e.type,toolId:`tool_id`in e?e.tool_id:void 0}:void 0;n.enqueue({type:`tool-input-start`,id:t.id,toolName:t.name});let i=JSON.stringify(t.input??{});n.enqueue({type:`tool-input-delta`,id:t.id,delta:i}),n.enqueue({type:`tool-input-end`,id:t.id}),n.enqueue({type:`tool-call`,toolCallId:t.id,toolName:t.name,input:i,...r&&{providerMetadata:{anthropic:{caller:r}}}})}}return;case`message_delta`:r.usage.input_tokens!=null&&h.input_tokens!==r.usage.input_tokens&&(h.input_tokens=r.usage.input_tokens),h.output_tokens=r.usage.output_tokens,r.usage.cache_read_input_tokens!=null&&(h.cache_read_input_tokens=r.usage.cache_read_input_tokens),r.usage.cache_creation_input_tokens!=null&&(h.cache_creation_input_tokens=r.usage.cache_creation_input_tokens),r.usage.iterations!=null&&(h.iterations=r.usage.iterations),m={unified:Z({finishReason:r.delta.stop_reason,isJsonResponseFromTool:C}),raw:r.delta.stop_reason??void 0},x=r.delta.stop_sequence??null,S=r.delta.container==null?null:{expiresAt:r.delta.container.expires_at,id:r.delta.container.id,skills:r.delta.container.skills?.map(e=>({type:e.type,skillId:e.skill_id,version:e.version}))??null},r.context_management&&(y=it(r.context_management)),b={...b,...r.usage};return;case`message_stop`:{let e={usage:b??null,stopSequence:x,iterations:h.iterations?h.iterations.map(e=>({type:e.type,inputTokens:e.input_tokens,outputTokens:e.output_tokens})):null,container:S,contextManagement:y},t={anthropic:e};s&&o!==`anthropic`&&(t[o]=e),n.enqueue({type:`finish`,finishReason:m,usage:Ae({usage:h,rawUsage:b}),providerMetadata:t});return}case`error`:n.enqueue({type:`error`,error:r.error});return;default:throw Error(`Unsupported chunk type: ${r}`)}}})).tee(),k=D.getReader();try{await k.read();let e=await k.read();if(e.value?.type===`raw`&&(e=await k.read()),e.value?.type===`error`){let n=e.value.error;throw new p({message:n.message,url:u,requestBodyValues:t,statusCode:n.type===`overloaded_error`?529:500,responseHeaders:d,responseBody:JSON.stringify(n),isRetryable:n.type===`overloaded_error`})}}finally{k.cancel().catch(()=>{}),k.releaseLock()}return{stream:O,request:{body:t},response:{headers:d}}}};function tt(e){return e.includes(`claude-opus-4-7`)?{maxOutputTokens:128e3,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!0,supportsXhighEffort:!0,isKnownModel:!0}:e.includes(`claude-sonnet-4-6`)||e.includes(`claude-opus-4-6`)?{maxOutputTokens:128e3,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!0}:e.includes(`claude-sonnet-4-5`)||e.includes(`claude-opus-4-5`)||e.includes(`claude-haiku-4-5`)?{maxOutputTokens:64e3,supportsStructuredOutput:!0,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!0}:e.includes(`claude-opus-4-1`)?{maxOutputTokens:32e3,supportsStructuredOutput:!0,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!0}:e.includes(`claude-sonnet-4-`)?{maxOutputTokens:64e3,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!0}:e.includes(`claude-opus-4-`)?{maxOutputTokens:32e3,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!0}:e.includes(`claude-3-haiku`)?{maxOutputTokens:4096,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!0}:{maxOutputTokens:4096,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!1}}function nt(e){if(!e)return!1;let t=!1,n=!1;for(let r of e){if(`type`in r&&(r.type===`web_fetch_20260209`||r.type===`web_search_20260209`)){t=!0;continue}if(r.name===`code_execution`){n=!0;break}}return t&&!n}function rt({reasoning:e,supportsAdaptiveThinking:t,supportsXhighEffort:n,maxOutputTokensForModel:r,warnings:i}){if(!ne(e))return;if(e===`none`)return{thinking:{type:`disabled`}};if(t)return{thinking:{type:`adaptive`},effort:D({reasoning:e,effortMap:{minimal:`low`,low:`low`,medium:`medium`,high:`high`,xhigh:n?`xhigh`:`max`},warnings:i})};let a=R({reasoning:e,maxOutputTokens:r,maxReasoningBudget:r,warnings:i});if(a!=null)return{thinking:{type:`enabled`,budgetTokens:a}}}function it(e){return e?{appliedEdits:e.applied_edits.map(e=>{switch(e.type){case`clear_tool_uses_20250919`:return{type:e.type,clearedToolUses:e.cleared_tool_uses,clearedInputTokens:e.cleared_input_tokens};case`clear_thinking_20251015`:return{type:e.type,clearedThinkingTurns:e.cleared_thinking_turns,clearedInputTokens:e.cleared_input_tokens};case`compact_20260112`:return{type:e.type}}}).filter(e=>e!==void 0)}:null}var at=V({id:`anthropic.bash_20241022`,inputSchema:O(()=>w(o({command:a(),restart:e().optional()})))}),ot=V({id:`anthropic.bash_20250124`,inputSchema:O(()=>w(o({command:a(),restart:e().optional()})))}),st=V({id:`anthropic.computer_20241022`,inputSchema:O(()=>w(o({action:f([`key`,`type`,`mouse_move`,`left_click`,`left_click_drag`,`right_click`,`middle_click`,`double_click`,`screenshot`,`cursor_position`]),coordinate:n(d().int()).optional(),text:a().optional()})))}),ct=V({id:`anthropic.computer_20250124`,inputSchema:O(()=>w(o({action:f([`key`,`hold_key`,`type`,`cursor_position`,`mouse_move`,`left_mouse_down`,`left_mouse_up`,`left_click`,`left_click_drag`,`right_click`,`middle_click`,`double_click`,`triple_click`,`scroll`,`wait`,`screenshot`]),coordinate:r([d().int(),d().int()]).optional(),duration:d().optional(),scroll_amount:d().optional(),scroll_direction:f([`up`,`down`,`left`,`right`]).optional(),start_coordinate:r([d().int(),d().int()]).optional(),text:a().optional()})))}),lt=V({id:`anthropic.computer_20251124`,inputSchema:O(()=>w(o({action:f([`key`,`hold_key`,`type`,`cursor_position`,`mouse_move`,`left_mouse_down`,`left_mouse_up`,`left_click`,`left_click_drag`,`right_click`,`middle_click`,`double_click`,`triple_click`,`scroll`,`wait`,`screenshot`,`zoom`]),coordinate:r([d().int(),d().int()]).optional(),duration:d().optional(),region:r([d().int(),d().int(),d().int(),d().int()]).optional(),scroll_amount:d().optional(),scroll_direction:f([`up`,`down`,`left`,`right`]).optional(),start_coordinate:r([d().int(),d().int()]).optional(),text:a().optional()})))}),ut=V({id:`anthropic.memory_20250818`,inputSchema:O(()=>w(t(`command`,[o({command:l(`view`),path:a(),view_range:r([d(),d()]).optional()}),o({command:l(`create`),path:a(),file_text:a()}),o({command:l(`str_replace`),path:a(),old_str:a(),new_str:a()}),o({command:l(`insert`),path:a(),insert_line:d(),insert_text:a()}),o({command:l(`delete`),path:a()}),o({command:l(`rename`),old_path:a(),new_path:a()})])))}),dt=V({id:`anthropic.text_editor_20241022`,inputSchema:O(()=>w(o({command:f([`view`,`create`,`str_replace`,`insert`,`undo_edit`]),path:a(),file_text:a().optional(),insert_line:d().int().optional(),new_str:a().optional(),insert_text:a().optional(),old_str:a().optional(),view_range:n(d().int()).optional()})))}),ft=V({id:`anthropic.text_editor_20250124`,inputSchema:O(()=>w(o({command:f([`view`,`create`,`str_replace`,`insert`,`undo_edit`]),path:a(),file_text:a().optional(),insert_line:d().int().optional(),new_str:a().optional(),insert_text:a().optional(),old_str:a().optional(),view_range:n(d().int()).optional()})))}),pt=V({id:`anthropic.text_editor_20250429`,inputSchema:O(()=>w(o({command:f([`view`,`create`,`str_replace`,`insert`]),path:a(),file_text:a().optional(),insert_line:d().int().optional(),new_str:a().optional(),insert_text:a().optional(),old_str:a().optional(),view_range:n(d().int()).optional()})))}),mt=O(()=>w(n(o({type:l(`tool_reference`),toolName:a()})))),ht=I({id:`anthropic.tool_search_bm25_20251119`,inputSchema:O(()=>w(o({query:a(),limit:d().optional()}))),outputSchema:mt,supportsDeferredResults:!0}),gt={bash_20241022:at,bash_20250124:ot,codeExecution_20250522:Ne,codeExecution_20250825:Ie,codeExecution_20260120:ze,computer_20241022:st,computer_20250124:ct,computer_20251124:lt,memory_20250818:ut,textEditor_20241022:dt,textEditor_20250124:ft,textEditor_20250429:pt,textEditor_20250728:fe,webFetch_20250910:Oe,webFetch_20260209:we,webSearch_20250305:be,webSearch_20260209:ge,toolSearchRegex_20251119:He,toolSearchBm25_20251119:(e={})=>ht(e)},_t=O(()=>w(o({id:a(),display_title:a().nullish(),name:a().nullish(),description:a().nullish(),latest_version:a().nullish(),source:a(),created_at:a(),updated_at:a()})));O(()=>w(o({data:n(o({version:a()}))})));var vt=O(()=>w(o({type:a(),skill_id:a(),name:a().nullish(),description:a().nullish()}))),yt=class{constructor(e){this.config=e,this.specificationVersion=`v4`}get provider(){return this.config.provider}async getHeaders(){return U(await k(this.config.headers),{"anthropic-beta":`skills-2025-10-02`})}async fetchVersionMetadata({skillId:e,version:t,headers:n}){let{value:r}=await G({url:`${this.config.baseURL}/skills/${e}/versions/${t}`,headers:n,failedResponseHandler:q,successfulResponseHandler:F(vt),fetch:this.config.fetch});return{...r.name==null?{}:{name:r.name},...r.description==null?{}:{description:r.description}}}async uploadSkill(e){let t=[],n=new FormData;e.displayTitle!=null&&n.append(`display_title`,e.displayTitle);for(let t of e.files){let e=M(t.data);n.append(`files[]`,new Blob([e]),t.path)}let r=await this.getHeaders(),{value:i}=await C({url:`${this.config.baseURL}/skills`,headers:r,formData:n,failedResponseHandler:q,successfulResponseHandler:F(_t),fetch:this.config.fetch}),a=i.latest_version==null?{}:await this.fetchVersionMetadata({skillId:i.id,version:i.latest_version,headers:r}),o=a.name??i.name,s=a.description??i.description;return{providerReference:{anthropic:i.id},...i.display_title==null?{}:{displayTitle:i.display_title},...o==null?{}:{name:o},...s==null?{}:{description:s},...i.latest_version==null?{}:{latestVersion:i.latest_version},providerMetadata:{anthropic:{...i.source==null?{}:{source:i.source},...i.created_at==null?{}:{createdAt:i.created_at},...i.updated_at==null?{}:{updatedAt:i.updated_at}}},warnings:t}}},bt=`4.0.0-canary.46`;function xt(e={}){let t=H(_({settingValue:e.baseURL,environmentVariableName:`ANTHROPIC_BASE_URL`}))??`https://api.anthropic.com/v1`,n=e.name??`anthropic.messages`;if(e.apiKey&&e.authToken)throw new m({argument:`apiKey/authToken`,message:`Both apiKey and authToken were provided. Please use only one authentication method.`});let r=()=>T({"anthropic-version":`2023-06-01`,...e.authToken?{Authorization:`Bearer ${e.authToken}`}:{"x-api-key":z({apiKey:e.apiKey,environmentVariableName:`ANTHROPIC_API_KEY`,description:`Anthropic`})},...e.headers},`ai-sdk/anthropic/${bt}`),i=i=>new et(i,{provider:n,baseURL:t,headers:r,fetch:e.fetch,generateId:e.generateId??N,supportedUrls:()=>({"image/*":[/^https?:\/\/.*$/],"application/pdf":[/^https?:\/\/.*$/]})}),a=()=>new yt({provider:`${n.replace(`.messages`,``)}.skills`,baseURL:t,headers:r,fetch:e.fetch}),o=function(e){if(new.target)throw Error(`The Anthropic model function cannot be called with the new keyword.`);return i(e)};return o.specificationVersion=`v4`,o.languageModel=i,o.chat=i,o.messages=i,o.embeddingModel=e=>{throw new h({modelId:e,modelType:`embeddingModel`})},o.textEmbeddingModel=o.embeddingModel,o.imageModel=e=>{throw new h({modelId:e,modelType:`imageModel`})},o.files=()=>new ie({provider:n,baseURL:t,headers:r,fetch:e.fetch}),o.skills=a,o.tools=gt,o}var St=xt();function Ct({steps:e}){for(let t=e.length-1;t>=0;t--){let n=e[t].providerMetadata?.anthropic?.container?.id;if(n)return{providerOptions:{anthropic:{container:{id:n}}}}}}export{bt as VERSION,St as anthropic,xt as createAnthropic,Ct as forwardAnthropicContainerIdFromLastStep};
|
|
1
|
+
import{APICallError as e,InvalidArgumentError as t,NoSuchModelError as n,UnsupportedFunctionalityError as r}from"../provider/index.js";import{At as i,Bt as a,Et as o,Kn as s,Nn as c,Rn as l,Tn as u,Xn as d,Zn as f,dn as p,fn as m,wn as h,yt as g}from"../../_chunks/workflow/schemas-DFZoEyCn.js";import{A as _,B as v,C as y,E as b,F as x,G as S,I as C,J as w,K as T,L as E,M as D,O,R as k,U as ee,X as A,Y as j,a as M,b as N,d as P,f as F,g as te,h as I,i as L,j as R,k as z,o as B,p as V,q as H,r as U,u as W,w as ne,x as G,z as K}from"../../_chunks/workflow/dist-Ci2brnHh.js";var q=P({errorSchema:O(()=>w(u({type:p(`error`),error:u({type:l(),message:l()})}))),errorToMessage:e=>e.error.message}),re=O(()=>w(u({id:l(),type:p(`file`),filename:l(),mime_type:l(),size_bytes:h(),created_at:l(),downloadable:i().nullish()}))),ie=class{constructor(e){this.config=e,this.specificationVersion=`v4`}get provider(){return this.config.provider}async uploadFile({data:e,mediaType:t,filename:n}){let r=M(e),i=new Blob([r],{type:t}),a=new FormData;n==null?a.append(`file`,i):a.append(`file`,i,n);let{value:o}=await C({url:`${this.config.baseURL}/files`,headers:U(this.config.headers(),{"anthropic-beta":`files-api-2025-04-14`}),formData:a,failedResponseHandler:q,successfulResponseHandler:F(re),fetch:this.config.fetch});return{warnings:[],providerReference:{anthropic:o.id},mediaType:o.mime_type??t,filename:o.filename??n,providerMetadata:{anthropic:{filename:o.filename,mimeType:o.mime_type,sizeBytes:o.size_bytes,createdAt:o.created_at,...o.downloadable==null?{}:{downloadable:o.downloadable}}}}}},ae=O(()=>w(u({type:p(`message`),id:l().nullish(),model:l().nullish(),content:o(a(`type`,[u({type:p(`text`),text:l(),citations:o(a(`type`,[u({type:p(`web_search_result_location`),cited_text:l(),url:l(),title:l(),encrypted_index:l()}),u({type:p(`page_location`),cited_text:l(),document_index:h(),document_title:l().nullable(),start_page_number:h(),end_page_number:h()}),u({type:p(`char_location`),cited_text:l(),document_index:h(),document_title:l().nullable(),start_char_index:h(),end_char_index:h()})])).optional()}),u({type:p(`thinking`),thinking:l(),signature:l()}),u({type:p(`redacted_thinking`),data:l()}),u({type:p(`compaction`),content:l()}),u({type:p(`tool_use`),id:l(),name:l(),input:f(),caller:d([u({type:p(`code_execution_20250825`),tool_id:l()}),u({type:p(`code_execution_20260120`),tool_id:l()}),u({type:p(`direct`)})]).optional()}),u({type:p(`server_tool_use`),id:l(),name:l(),input:c(l(),f()).nullish(),caller:d([u({type:p(`code_execution_20260120`),tool_id:l()}),u({type:p(`direct`)})]).optional()}),u({type:p(`mcp_tool_use`),id:l(),name:l(),input:f(),server_name:l()}),u({type:p(`mcp_tool_result`),tool_use_id:l(),is_error:i(),content:o(d([l(),u({type:p(`text`),text:l()})]))}),u({type:p(`web_fetch_tool_result`),tool_use_id:l(),content:d([u({type:p(`web_fetch_result`),url:l(),retrieved_at:l(),content:u({type:p(`document`),title:l().nullable(),citations:u({enabled:i()}).optional(),source:d([u({type:p(`base64`),media_type:p(`application/pdf`),data:l()}),u({type:p(`text`),media_type:p(`text/plain`),data:l()})])})}),u({type:p(`web_fetch_tool_result_error`),error_code:l()})])}),u({type:p(`web_search_tool_result`),tool_use_id:l(),content:d([o(u({type:p(`web_search_result`),url:l(),title:l(),encrypted_content:l(),page_age:l().nullish()})),u({type:p(`web_search_tool_result_error`),error_code:l()})])}),u({type:p(`code_execution_tool_result`),tool_use_id:l(),content:d([u({type:p(`code_execution_result`),stdout:l(),stderr:l(),return_code:h(),content:o(u({type:p(`code_execution_output`),file_id:l()})).optional().default([])}),u({type:p(`encrypted_code_execution_result`),encrypted_stdout:l(),stderr:l(),return_code:h(),content:o(u({type:p(`code_execution_output`),file_id:l()})).optional().default([])}),u({type:p(`code_execution_tool_result_error`),error_code:l()})])}),u({type:p(`bash_code_execution_tool_result`),tool_use_id:l(),content:a(`type`,[u({type:p(`bash_code_execution_result`),content:o(u({type:p(`bash_code_execution_output`),file_id:l()})),stdout:l(),stderr:l(),return_code:h()}),u({type:p(`bash_code_execution_tool_result_error`),error_code:l()})])}),u({type:p(`text_editor_code_execution_tool_result`),tool_use_id:l(),content:a(`type`,[u({type:p(`text_editor_code_execution_tool_result_error`),error_code:l()}),u({type:p(`text_editor_code_execution_view_result`),content:l(),file_type:l(),num_lines:h().nullable(),start_line:h().nullable(),total_lines:h().nullable()}),u({type:p(`text_editor_code_execution_create_result`),is_file_update:i()}),u({type:p(`text_editor_code_execution_str_replace_result`),lines:o(l()).nullable(),new_lines:h().nullable(),new_start:h().nullable(),old_lines:h().nullable(),old_start:h().nullable()})])}),u({type:p(`tool_search_tool_result`),tool_use_id:l(),content:d([u({type:p(`tool_search_tool_search_result`),tool_references:o(u({type:p(`tool_reference`),tool_name:l()}))}),u({type:p(`tool_search_tool_result_error`),error_code:l()})])})])),stop_reason:l().nullish(),stop_sequence:l().nullish(),usage:m({input_tokens:h(),output_tokens:h(),cache_creation_input_tokens:h().nullish(),cache_read_input_tokens:h().nullish(),iterations:o(u({type:d([p(`compaction`),p(`message`)]),input_tokens:h(),output_tokens:h()})).nullish()}),container:u({expires_at:l(),id:l(),skills:o(u({type:d([p(`anthropic`),p(`custom`)]),skill_id:l(),version:l()})).nullish()}).nullish(),context_management:u({applied_edits:o(d([u({type:p(`clear_tool_uses_20250919`),cleared_tool_uses:h(),cleared_input_tokens:h()}),u({type:p(`clear_thinking_20251015`),cleared_thinking_turns:h(),cleared_input_tokens:h()}),u({type:p(`compact_20260112`)})]))}).nullish()}))),J=O(()=>w(a(`type`,[u({type:p(`message_start`),message:u({id:l().nullish(),model:l().nullish(),role:l().nullish(),usage:m({input_tokens:h(),cache_creation_input_tokens:h().nullish(),cache_read_input_tokens:h().nullish()}),content:o(a(`type`,[u({type:p(`tool_use`),id:l(),name:l(),input:f(),caller:d([u({type:p(`code_execution_20250825`),tool_id:l()}),u({type:p(`code_execution_20260120`),tool_id:l()}),u({type:p(`direct`)})]).optional()})])).nullish(),stop_reason:l().nullish(),container:u({expires_at:l(),id:l()}).nullish()})}),u({type:p(`content_block_start`),index:h(),content_block:a(`type`,[u({type:p(`text`),text:l()}),u({type:p(`thinking`),thinking:l()}),u({type:p(`tool_use`),id:l(),name:l(),input:c(l(),f()).optional(),caller:d([u({type:p(`code_execution_20250825`),tool_id:l()}),u({type:p(`code_execution_20260120`),tool_id:l()}),u({type:p(`direct`)})]).optional()}),u({type:p(`redacted_thinking`),data:l()}),u({type:p(`compaction`),content:l().nullish()}),u({type:p(`server_tool_use`),id:l(),name:l(),input:c(l(),f()).nullish(),caller:d([u({type:p(`code_execution_20260120`),tool_id:l()}),u({type:p(`direct`)})]).optional()}),u({type:p(`mcp_tool_use`),id:l(),name:l(),input:f(),server_name:l()}),u({type:p(`mcp_tool_result`),tool_use_id:l(),is_error:i(),content:o(d([l(),u({type:p(`text`),text:l()})]))}),u({type:p(`web_fetch_tool_result`),tool_use_id:l(),content:d([u({type:p(`web_fetch_result`),url:l(),retrieved_at:l(),content:u({type:p(`document`),title:l().nullable(),citations:u({enabled:i()}).optional(),source:d([u({type:p(`base64`),media_type:p(`application/pdf`),data:l()}),u({type:p(`text`),media_type:p(`text/plain`),data:l()})])})}),u({type:p(`web_fetch_tool_result_error`),error_code:l()})])}),u({type:p(`web_search_tool_result`),tool_use_id:l(),content:d([o(u({type:p(`web_search_result`),url:l(),title:l(),encrypted_content:l(),page_age:l().nullish()})),u({type:p(`web_search_tool_result_error`),error_code:l()})])}),u({type:p(`code_execution_tool_result`),tool_use_id:l(),content:d([u({type:p(`code_execution_result`),stdout:l(),stderr:l(),return_code:h(),content:o(u({type:p(`code_execution_output`),file_id:l()})).optional().default([])}),u({type:p(`encrypted_code_execution_result`),encrypted_stdout:l(),stderr:l(),return_code:h(),content:o(u({type:p(`code_execution_output`),file_id:l()})).optional().default([])}),u({type:p(`code_execution_tool_result_error`),error_code:l()})])}),u({type:p(`bash_code_execution_tool_result`),tool_use_id:l(),content:a(`type`,[u({type:p(`bash_code_execution_result`),content:o(u({type:p(`bash_code_execution_output`),file_id:l()})),stdout:l(),stderr:l(),return_code:h()}),u({type:p(`bash_code_execution_tool_result_error`),error_code:l()})])}),u({type:p(`text_editor_code_execution_tool_result`),tool_use_id:l(),content:a(`type`,[u({type:p(`text_editor_code_execution_tool_result_error`),error_code:l()}),u({type:p(`text_editor_code_execution_view_result`),content:l(),file_type:l(),num_lines:h().nullable(),start_line:h().nullable(),total_lines:h().nullable()}),u({type:p(`text_editor_code_execution_create_result`),is_file_update:i()}),u({type:p(`text_editor_code_execution_str_replace_result`),lines:o(l()).nullable(),new_lines:h().nullable(),new_start:h().nullable(),old_lines:h().nullable(),old_start:h().nullable()})])}),u({type:p(`tool_search_tool_result`),tool_use_id:l(),content:d([u({type:p(`tool_search_tool_search_result`),tool_references:o(u({type:p(`tool_reference`),tool_name:l()}))}),u({type:p(`tool_search_tool_result_error`),error_code:l()})])})])}),u({type:p(`content_block_delta`),index:h(),delta:a(`type`,[u({type:p(`input_json_delta`),partial_json:l()}),u({type:p(`text_delta`),text:l()}),u({type:p(`thinking_delta`),thinking:l()}),u({type:p(`signature_delta`),signature:l()}),u({type:p(`compaction_delta`),content:l().nullish()}),u({type:p(`citations_delta`),citation:a(`type`,[u({type:p(`web_search_result_location`),cited_text:l(),url:l(),title:l(),encrypted_index:l()}),u({type:p(`page_location`),cited_text:l(),document_index:h(),document_title:l().nullable(),start_page_number:h(),end_page_number:h()}),u({type:p(`char_location`),cited_text:l(),document_index:h(),document_title:l().nullable(),start_char_index:h(),end_char_index:h()})])})])}),u({type:p(`content_block_stop`),index:h()}),u({type:p(`error`),error:u({type:l(),message:l()})}),u({type:p(`message_delta`),delta:u({stop_reason:l().nullish(),stop_sequence:l().nullish(),container:u({expires_at:l(),id:l(),skills:o(u({type:d([p(`anthropic`),p(`custom`)]),skill_id:l(),version:l()})).nullish()}).nullish()}),usage:m({input_tokens:h().nullish(),output_tokens:h(),cache_creation_input_tokens:h().nullish(),cache_read_input_tokens:h().nullish(),iterations:o(u({type:d([p(`compaction`),p(`message`)]),input_tokens:h(),output_tokens:h()})).nullish()}),context_management:u({applied_edits:o(d([u({type:p(`clear_tool_uses_20250919`),cleared_tool_uses:h(),cleared_input_tokens:h()}),u({type:p(`clear_thinking_20251015`),cleared_thinking_turns:h(),cleared_input_tokens:h()}),u({type:p(`compact_20260112`)})]))}).nullish()}),u({type:p(`message_stop`)}),u({type:p(`ping`)})]))),oe=O(()=>w(u({signature:l().optional(),redactedData:l().optional()}))),Y=u({citations:u({enabled:i()}).optional(),title:l().optional(),context:l().optional()}),se=u({sendReasoning:i().optional(),structuredOutputMode:g([`outputFormat`,`jsonTool`,`auto`]).optional(),thinking:a(`type`,[u({type:p(`adaptive`),display:g([`omitted`,`summarized`]).optional()}),u({type:p(`enabled`),budgetTokens:h().optional()}),u({type:p(`disabled`)})]).optional(),disableParallelToolUse:i().optional(),cacheControl:u({type:p(`ephemeral`),ttl:d([p(`5m`),p(`1h`)]).optional()}).optional(),metadata:u({userId:l().optional()}).optional(),mcpServers:o(u({type:p(`url`),name:l(),url:l(),authorizationToken:l().nullish(),toolConfiguration:u({enabled:i().nullish(),allowedTools:o(l()).nullish()}).nullish()})).optional(),container:u({id:l().optional(),skills:o(a(`type`,[u({type:p(`anthropic`),skillId:l(),version:l().optional()}),u({type:p(`custom`),providerReference:c(l(),l()),version:l().optional()})])).optional()}).optional(),toolStreaming:i().optional(),effort:g([`low`,`medium`,`high`,`xhigh`,`max`]).optional(),taskBudget:u({type:p(`tokens`),total:h().int().min(2e4),remaining:h().int().min(0).optional()}).optional(),speed:g([`fast`,`standard`]).optional(),inferenceGeo:g([`us`,`global`]).optional(),anthropicBeta:o(l()).optional(),contextManagement:u({edits:o(a(`type`,[u({type:p(`clear_tool_uses_20250919`),trigger:a(`type`,[u({type:p(`input_tokens`),value:h()}),u({type:p(`tool_uses`),value:h()})]).optional(),keep:u({type:p(`tool_uses`),value:h()}).optional(),clearAtLeast:u({type:p(`input_tokens`),value:h()}).optional(),clearToolInputs:i().optional(),excludeTools:o(l()).optional()}),u({type:p(`clear_thinking_20251015`),keep:d([p(`all`),u({type:p(`thinking_turns`),value:h()})]).optional()}),u({type:p(`compact_20260112`),trigger:u({type:p(`input_tokens`),value:h()}).optional(),pauseAfterCompaction:i().optional(),instructions:l().optional()})]))}).optional()}),ce=4;function le(e){let t=e?.anthropic;return t?.cacheControl??t?.cache_control}var X=class{constructor(){this.breakpointCount=0,this.warnings=[]}getCacheControl(e,t){let n=le(e);if(n){if(!t.canCache){this.warnings.push({type:`unsupported`,feature:`cache_control on non-cacheable context`,details:`cache_control cannot be set on ${t.type}. It will be ignored.`});return}if(this.breakpointCount++,this.breakpointCount>ce){this.warnings.push({type:`unsupported`,feature:`cacheControl breakpoint limit`,details:`Maximum ${ce} cache breakpoints exceeded (found ${this.breakpointCount}). This breakpoint will be ignored.`});return}return n}}getWarnings(){return this.warnings}},ue=O(()=>w(u({maxCharacters:h().optional()}))),de=V({id:`anthropic.text_editor_20250728`,inputSchema:O(()=>w(u({command:g([`view`,`create`,`str_replace`,`insert`]),path:l(),file_text:l().optional(),insert_line:h().int().optional(),new_str:l().optional(),insert_text:l().optional(),old_str:l().optional(),view_range:o(h().int()).optional()})))}),fe=(e={})=>de(e),pe=O(()=>w(u({maxUses:h().optional(),allowedDomains:o(l()).optional(),blockedDomains:o(l()).optional(),userLocation:u({type:p(`approximate`),city:l().optional(),region:l().optional(),country:l().optional(),timezone:l().optional()}).optional()}))),me=O(()=>w(o(u({url:l(),title:l().nullable(),pageAge:l().nullable(),encryptedContent:l(),type:p(`web_search_result`)})))),he=I({id:`anthropic.web_search_20260209`,inputSchema:O(()=>w(u({query:l()}))),outputSchema:me,supportsDeferredResults:!0}),ge=(e={})=>he(e),_e=O(()=>w(u({maxUses:h().optional(),allowedDomains:o(l()).optional(),blockedDomains:o(l()).optional(),userLocation:u({type:p(`approximate`),city:l().optional(),region:l().optional(),country:l().optional(),timezone:l().optional()}).optional()}))),ve=O(()=>w(o(u({url:l(),title:l().nullable(),pageAge:l().nullable(),encryptedContent:l(),type:p(`web_search_result`)})))),ye=I({id:`anthropic.web_search_20250305`,inputSchema:O(()=>w(u({query:l()}))),outputSchema:ve,supportsDeferredResults:!0}),be=(e={})=>ye(e),xe=O(()=>w(u({maxUses:h().optional(),allowedDomains:o(l()).optional(),blockedDomains:o(l()).optional(),citations:u({enabled:i()}).optional(),maxContentTokens:h().optional()}))),Se=O(()=>w(u({type:p(`web_fetch_result`),url:l(),content:u({type:p(`document`),title:l().nullable(),citations:u({enabled:i()}).optional(),source:d([u({type:p(`base64`),mediaType:p(`application/pdf`),data:l()}),u({type:p(`text`),mediaType:p(`text/plain`),data:l()})])}),retrievedAt:l().nullable()}))),Ce=I({id:`anthropic.web_fetch_20260209`,inputSchema:O(()=>w(u({url:l()}))),outputSchema:Se,supportsDeferredResults:!0}),we=(e={})=>Ce(e),Te=O(()=>w(u({maxUses:h().optional(),allowedDomains:o(l()).optional(),blockedDomains:o(l()).optional(),citations:u({enabled:i()}).optional(),maxContentTokens:h().optional()}))),Ee=O(()=>w(u({type:p(`web_fetch_result`),url:l(),content:u({type:p(`document`),title:l().nullable(),citations:u({enabled:i()}).optional(),source:d([u({type:p(`base64`),mediaType:p(`application/pdf`),data:l()}),u({type:p(`text`),mediaType:p(`text/plain`),data:l()})])}),retrievedAt:l().nullable()}))),De=I({id:`anthropic.web_fetch_20250910`,inputSchema:O(()=>w(u({url:l()}))),outputSchema:Ee,supportsDeferredResults:!0}),Oe=(e={})=>De(e);async function ke({tools:e,toolChoice:t,disableParallelToolUse:n,cacheControlValidator:i,supportsStructuredOutput:a,supportsStrictTools:o,defaultEagerInputStreaming:s=!1}){e=e?.length?e:void 0;let c=[],l=new Set,u=i||new X;if(e==null)return{tools:void 0,toolChoice:void 0,toolWarnings:c,betas:l};let d=[];for(let t of e)switch(t.type){case`function`:{let e=u.getCacheControl(t.providerOptions,{type:`tool definition`,canCache:!0}),n=t.providerOptions?.anthropic,r=n?.eagerInputStreaming??s,i=n?.deferLoading,f=n?.allowedCallers;!o&&t.strict!=null&&c.push({type:`unsupported`,feature:`strict`,details:`Tool '${t.name}' has strict: ${t.strict}, but strict mode is not supported by this provider. The strict property will be ignored.`}),d.push({name:t.name,description:t.description,input_schema:t.inputSchema,cache_control:e,...r?{eager_input_streaming:!0}:{},...o===!0&&t.strict!=null?{strict:t.strict}:{},...i==null?{}:{defer_loading:i},...f==null?{}:{allowed_callers:f},...t.inputExamples==null?{}:{input_examples:t.inputExamples.map(e=>e.input)}}),a===!0&&l.add(`structured-outputs-2025-11-13`),(t.inputExamples!=null||f!=null)&&l.add(`advanced-tool-use-2025-11-20`);break}case`provider`:switch(t.id){case`anthropic.code_execution_20250522`:l.add(`code-execution-2025-05-22`),d.push({type:`code_execution_20250522`,name:`code_execution`,cache_control:void 0});break;case`anthropic.code_execution_20250825`:l.add(`code-execution-2025-08-25`),d.push({type:`code_execution_20250825`,name:`code_execution`});break;case`anthropic.code_execution_20260120`:d.push({type:`code_execution_20260120`,name:`code_execution`});break;case`anthropic.computer_20250124`:l.add(`computer-use-2025-01-24`),d.push({name:`computer`,type:`computer_20250124`,display_width_px:t.args.displayWidthPx,display_height_px:t.args.displayHeightPx,display_number:t.args.displayNumber,cache_control:void 0});break;case`anthropic.computer_20251124`:l.add(`computer-use-2025-11-24`),d.push({name:`computer`,type:`computer_20251124`,display_width_px:t.args.displayWidthPx,display_height_px:t.args.displayHeightPx,display_number:t.args.displayNumber,enable_zoom:t.args.enableZoom,cache_control:void 0});break;case`anthropic.computer_20241022`:l.add(`computer-use-2024-10-22`),d.push({name:`computer`,type:`computer_20241022`,display_width_px:t.args.displayWidthPx,display_height_px:t.args.displayHeightPx,display_number:t.args.displayNumber,cache_control:void 0});break;case`anthropic.text_editor_20250124`:l.add(`computer-use-2025-01-24`),d.push({name:`str_replace_editor`,type:`text_editor_20250124`,cache_control:void 0});break;case`anthropic.text_editor_20241022`:l.add(`computer-use-2024-10-22`),d.push({name:`str_replace_editor`,type:`text_editor_20241022`,cache_control:void 0});break;case`anthropic.text_editor_20250429`:l.add(`computer-use-2025-01-24`),d.push({name:`str_replace_based_edit_tool`,type:`text_editor_20250429`,cache_control:void 0});break;case`anthropic.text_editor_20250728`:{let e=await S({value:t.args,schema:ue});d.push({name:`str_replace_based_edit_tool`,type:`text_editor_20250728`,max_characters:e.maxCharacters,cache_control:void 0});break}case`anthropic.bash_20250124`:l.add(`computer-use-2025-01-24`),d.push({name:`bash`,type:`bash_20250124`,cache_control:void 0});break;case`anthropic.bash_20241022`:l.add(`computer-use-2024-10-22`),d.push({name:`bash`,type:`bash_20241022`,cache_control:void 0});break;case`anthropic.memory_20250818`:l.add(`context-management-2025-06-27`),d.push({name:`memory`,type:`memory_20250818`});break;case`anthropic.web_fetch_20250910`:{l.add(`web-fetch-2025-09-10`);let e=await S({value:t.args,schema:Te});d.push({type:`web_fetch_20250910`,name:`web_fetch`,max_uses:e.maxUses,allowed_domains:e.allowedDomains,blocked_domains:e.blockedDomains,citations:e.citations,max_content_tokens:e.maxContentTokens,cache_control:void 0});break}case`anthropic.web_fetch_20260209`:{l.add(`code-execution-web-tools-2026-02-09`);let e=await S({value:t.args,schema:xe});d.push({type:`web_fetch_20260209`,name:`web_fetch`,max_uses:e.maxUses,allowed_domains:e.allowedDomains,blocked_domains:e.blockedDomains,citations:e.citations,max_content_tokens:e.maxContentTokens,cache_control:void 0});break}case`anthropic.web_search_20250305`:{let e=await S({value:t.args,schema:_e});d.push({type:`web_search_20250305`,name:`web_search`,max_uses:e.maxUses,allowed_domains:e.allowedDomains,blocked_domains:e.blockedDomains,user_location:e.userLocation,cache_control:void 0});break}case`anthropic.web_search_20260209`:{l.add(`code-execution-web-tools-2026-02-09`);let e=await S({value:t.args,schema:pe});d.push({type:`web_search_20260209`,name:`web_search`,max_uses:e.maxUses,allowed_domains:e.allowedDomains,blocked_domains:e.blockedDomains,user_location:e.userLocation,cache_control:void 0});break}case`anthropic.tool_search_regex_20251119`:d.push({type:`tool_search_tool_regex_20251119`,name:`tool_search_tool_regex`});break;case`anthropic.tool_search_bm25_20251119`:d.push({type:`tool_search_tool_bm25_20251119`,name:`tool_search_tool_bm25`});break;default:c.push({type:`unsupported`,feature:`provider-defined tool ${t.id}`});break}break;default:c.push({type:`unsupported`,feature:`tool ${t}`});break}if(t==null)return{tools:d,toolChoice:n?{type:`auto`,disable_parallel_tool_use:n}:void 0,toolWarnings:c,betas:l};let f=t.type;switch(f){case`auto`:return{tools:d,toolChoice:{type:`auto`,disable_parallel_tool_use:n},toolWarnings:c,betas:l};case`required`:return{tools:d,toolChoice:{type:`any`,disable_parallel_tool_use:n},toolWarnings:c,betas:l};case`none`:return{tools:void 0,toolChoice:void 0,toolWarnings:c,betas:l};case`tool`:return{tools:d,toolChoice:{type:`tool`,name:t.toolName,disable_parallel_tool_use:n},toolWarnings:c,betas:l};default:throw new r({functionality:`tool choice type: ${f}`})}}function Ae({usage:e,rawUsage:t}){let n=e.cache_creation_input_tokens??0,r=e.cache_read_input_tokens??0,i,a;if(e.iterations&&e.iterations.length>0){let t=e.iterations.reduce((e,t)=>({input:e.input+t.input_tokens,output:e.output+t.output_tokens}),{input:0,output:0});i=t.input,a=t.output}else i=e.input_tokens,a=e.output_tokens;return{inputTokens:{total:i+n+r,noCache:i,cacheRead:r,cacheWrite:n},outputTokens:{total:a,text:void 0,reasoning:void 0},raw:t??e}}var je=O(()=>w(u({type:p(`code_execution_result`),stdout:l(),stderr:l(),return_code:h(),content:o(u({type:p(`code_execution_output`),file_id:l()})).optional().default([])}))),Me=I({id:`anthropic.code_execution_20250522`,inputSchema:O(()=>w(u({code:l()}))),outputSchema:je}),Ne=(e={})=>Me(e),Pe=O(()=>w(a(`type`,[u({type:p(`code_execution_result`),stdout:l(),stderr:l(),return_code:h(),content:o(u({type:p(`code_execution_output`),file_id:l()})).optional().default([])}),u({type:p(`bash_code_execution_result`),content:o(u({type:p(`bash_code_execution_output`),file_id:l()})),stdout:l(),stderr:l(),return_code:h()}),u({type:p(`bash_code_execution_tool_result_error`),error_code:l()}),u({type:p(`text_editor_code_execution_tool_result_error`),error_code:l()}),u({type:p(`text_editor_code_execution_view_result`),content:l(),file_type:l(),num_lines:h().nullable(),start_line:h().nullable(),total_lines:h().nullable()}),u({type:p(`text_editor_code_execution_create_result`),is_file_update:i()}),u({type:p(`text_editor_code_execution_str_replace_result`),lines:o(l()).nullable(),new_lines:h().nullable(),new_start:h().nullable(),old_lines:h().nullable(),old_start:h().nullable()})]))),Fe=I({id:`anthropic.code_execution_20250825`,inputSchema:O(()=>w(a(`type`,[u({type:p(`programmatic-tool-call`),code:l()}),u({type:p(`bash_code_execution`),command:l()}),a(`command`,[u({type:p(`text_editor_code_execution`),command:p(`view`),path:l()}),u({type:p(`text_editor_code_execution`),command:p(`create`),path:l(),file_text:l().nullish()}),u({type:p(`text_editor_code_execution`),command:p(`str_replace`),path:l(),old_str:l(),new_str:l()})])]))),outputSchema:Pe,supportsDeferredResults:!0}),Ie=(e={})=>Fe(e),Le=O(()=>w(a(`type`,[u({type:p(`code_execution_result`),stdout:l(),stderr:l(),return_code:h(),content:o(u({type:p(`code_execution_output`),file_id:l()})).optional().default([])}),u({type:p(`encrypted_code_execution_result`),encrypted_stdout:l(),stderr:l(),return_code:h(),content:o(u({type:p(`code_execution_output`),file_id:l()})).optional().default([])}),u({type:p(`bash_code_execution_result`),content:o(u({type:p(`bash_code_execution_output`),file_id:l()})),stdout:l(),stderr:l(),return_code:h()}),u({type:p(`bash_code_execution_tool_result_error`),error_code:l()}),u({type:p(`text_editor_code_execution_tool_result_error`),error_code:l()}),u({type:p(`text_editor_code_execution_view_result`),content:l(),file_type:l(),num_lines:h().nullable(),start_line:h().nullable(),total_lines:h().nullable()}),u({type:p(`text_editor_code_execution_create_result`),is_file_update:i()}),u({type:p(`text_editor_code_execution_str_replace_result`),lines:o(l()).nullable(),new_lines:h().nullable(),new_start:h().nullable(),old_lines:h().nullable(),old_start:h().nullable()})]))),Re=I({id:`anthropic.code_execution_20260120`,inputSchema:O(()=>w(a(`type`,[u({type:p(`programmatic-tool-call`),code:l()}),u({type:p(`bash_code_execution`),command:l()}),a(`command`,[u({type:p(`text_editor_code_execution`),command:p(`view`),path:l()}),u({type:p(`text_editor_code_execution`),command:p(`create`),path:l(),file_text:l().nullish()}),u({type:p(`text_editor_code_execution`),command:p(`str_replace`),path:l(),old_str:l(),new_str:l()})])]))),outputSchema:Le,supportsDeferredResults:!0}),ze=(e={})=>Re(e),Be=O(()=>w(o(u({type:p(`tool_reference`),toolName:l()})))),Ve=I({id:`anthropic.tool_search_regex_20251119`,inputSchema:O(()=>w(u({pattern:l(),limit:h().optional()}))),outputSchema:Be,supportsDeferredResults:!0}),He=(e={})=>Ve(e);function Ue(e){return typeof e==`string`?new TextDecoder().decode(L(e)):new TextDecoder().decode(e)}async function We({prompt:e,sendReasoning:t,warnings:n,cacheControlValidator:i,toolNameMapping:a}){let o=new Set,s=Ge(e),c=i||new X,l,u=[];async function d(e){return(await x({provider:`anthropic`,providerOptions:e,schema:Y}))?.citations?.enabled??!1}async function f(e){let t=await x({provider:`anthropic`,providerOptions:e,schema:Y});return{title:t?.title,context:t?.context}}for(let e=0;e<s.length;e++){let i=s[e],p=e===s.length-1,m=i.type;switch(m){case`system`:if(l!=null)throw new r({functionality:`Multiple system messages that are separated by user/assistant messages`});l=i.messages.map(({content:e,providerOptions:t})=>({type:`text`,text:e,cache_control:c.getCacheControl(t,{type:`system message`,canCache:!0})}));break;case`user`:{let e=[];for(let t of i.messages){let{role:i,content:a}=t;switch(i){case`user`:for(let n=0;n<a.length;n++){let i=a[n],s=n===a.length-1,l=c.getCacheControl(i.providerOptions,{type:`user message part`,canCache:!0})??(s?c.getCacheControl(t.providerOptions,{type:`user message`,canCache:!0}):void 0);switch(i.type){case`text`:e.push({type:`text`,text:i.text,cache_control:l});break;case`file`:switch(i.data.type){case`reference`:{let t=v({reference:i.data.reference,provider:`anthropic`});o.add(`files-api-2025-04-14`),y(i.mediaType)===`image`?e.push({type:`image`,source:{type:`file`,file_id:t},cache_control:l}):e.push({type:`document`,source:{type:`file`,file_id:t},cache_control:l});break}case`text`:{let t=await d(i.providerOptions),n=await f(i.providerOptions);e.push({type:`document`,source:{type:`text`,media_type:`text/plain`,data:i.data.text},title:n.title??i.filename,...n.context&&{context:n.context},...t&&{citations:{enabled:!0}},cache_control:l});break}case`url`:case`data`:{let t=y(i.mediaType);if(t===`image`)e.push({type:`image`,source:i.data.type===`url`?{type:`url`,url:i.data.url.toString()}:{type:`base64`,media_type:K({part:i}),data:B(i.data.data)},cache_control:l});else if(t===`application`&&(i.data.type===`url`?i.mediaType===`application/pdf`:K({part:i})===`application/pdf`)){o.add(`pdfs-2024-09-25`);let t=await d(i.providerOptions),n=await f(i.providerOptions);e.push({type:`document`,source:i.data.type===`url`?{type:`url`,url:i.data.url.toString()}:{type:`base64`,media_type:`application/pdf`,data:B(i.data.data)},title:n.title??i.filename,...n.context&&{context:n.context},...t&&{citations:{enabled:!0}},cache_control:l})}else if(i.mediaType===`text/plain`){let t=await d(i.providerOptions),n=await f(i.providerOptions);e.push({type:`document`,source:i.data.type===`url`?{type:`url`,url:i.data.url.toString()}:{type:`text`,media_type:`text/plain`,data:Ue(i.data.data)},title:n.title??i.filename,...n.context&&{context:n.context},...t&&{citations:{enabled:!0}},cache_control:l})}else throw new r({functionality:`media type: ${i.mediaType}`});break}}break}}break;case`tool`:for(let r=0;r<a.length;r++){let i=a[r];if(i.type===`tool-approval-response`)continue;let s=r===a.length-1,l=c.getCacheControl(i.providerOptions,{type:`tool result part`,canCache:!0})??(s?c.getCacheControl(t.providerOptions,{type:`tool result message`,canCache:!0}):void 0),u=i.output,d;switch(u.type){case`content`:d=u.value.map(e=>{switch(e.type){case`text`:return{type:`text`,text:e.text};case`file`:{let t=y(e.mediaType);if(e.data.type===`url`)return t===`image`?{type:`image`,source:{type:`url`,url:e.data.url.toString()}}:{type:`document`,source:{type:`url`,url:e.data.url.toString()}};if(e.data.type===`data`){if(t===`image`)return{type:`image`,source:{type:`base64`,media_type:K({part:e}),data:B(e.data.data)}};if(K({part:e})===`application/pdf`)return o.add(`pdfs-2024-09-25`),{type:`document`,source:{type:`base64`,media_type:`application/pdf`,data:B(e.data.data)}};n.push({type:`other`,message:`unsupported tool content part type: ${e.type} with media type: ${e.mediaType}`});return}n.push({type:`other`,message:`unsupported tool content part type: ${e.type} with data type: ${e.data.type}`});return}case`custom`:{let t=e.providerOptions?.anthropic;if(t?.type===`tool-reference`)return{type:`tool_reference`,tool_name:t.toolName};n.push({type:`other`,message:`unsupported custom tool content part`});return}default:n.push({type:`other`,message:`unsupported tool content part type: ${e.type}`});return}}).filter(b);break;case`text`:case`error-text`:d=u.value;break;case`execution-denied`:d=u.reason??`Tool call execution denied.`;break;default:d=JSON.stringify(u.value);break}e.push({type:`tool_result`,tool_use_id:i.toolCallId,content:d,is_error:u.type===`error-text`||u.type===`error-json`?!0:void 0,cache_control:l})}break;default:throw Error(`Unsupported role: ${i}`)}}u.push({role:`user`,content:e});break}case`assistant`:{let e=[],r=new Set;for(let o=0;o<i.messages.length;o++){let s=i.messages[o],l=o===i.messages.length-1,{content:u}=s;for(let i=0;i<u.length;i++){let o=u[i],d=i===u.length-1,f=c.getCacheControl(o.providerOptions,{type:`assistant message part`,canCache:!0})??(d?c.getCacheControl(s.providerOptions,{type:`assistant message`,canCache:!0}):void 0);switch(o.type){case`text`:o.providerOptions?.anthropic?.type===`compaction`?e.push({type:`compaction`,content:o.text,cache_control:f}):e.push({type:`text`,text:p&&l&&d?o.text.trim():o.text,cache_control:f});break;case`reasoning`:if(t){let t=await x({provider:`anthropic`,providerOptions:o.providerOptions,schema:oe});t==null?n.push({type:`other`,message:`unsupported reasoning metadata`}):t.signature==null?t.redactedData==null?n.push({type:`other`,message:`unsupported reasoning metadata`}):(c.getCacheControl(o.providerOptions,{type:`redacted thinking block`,canCache:!1}),e.push({type:`redacted_thinking`,data:t.redactedData})):(c.getCacheControl(o.providerOptions,{type:`thinking block`,canCache:!1}),e.push({type:`thinking`,thinking:o.text,signature:t.signature}))}else n.push({type:`other`,message:`sending reasoning content is disabled for this model`});break;case`tool-call`:{if(o.providerExecuted){let t=a.toProviderToolName(o.toolName);if(o.providerOptions?.anthropic?.type===`mcp-tool-use`){r.add(o.toolCallId);let t=o.providerOptions?.anthropic?.serverName;if(t==null||typeof t!=`string`){n.push({type:`other`,message:`mcp tool use server name is required and must be a string`});break}e.push({type:`mcp_tool_use`,id:o.toolCallId,name:o.toolName,input:o.input,server_name:t,cache_control:f})}else if(t===`code_execution`&&o.input!=null&&typeof o.input==`object`&&`type`in o.input&&typeof o.input.type==`string`&&(o.input.type===`bash_code_execution`||o.input.type===`text_editor_code_execution`))e.push({type:`server_tool_use`,id:o.toolCallId,name:o.input.type,input:o.input,cache_control:f});else if(t===`code_execution`&&o.input!=null&&typeof o.input==`object`&&`type`in o.input&&o.input.type===`programmatic-tool-call`){let{type:t,...n}=o.input;e.push({type:`server_tool_use`,id:o.toolCallId,name:`code_execution`,input:n,cache_control:f})}else t===`code_execution`||t===`web_fetch`||t===`web_search`||t===`tool_search_tool_regex`||t===`tool_search_tool_bm25`?e.push({type:`server_tool_use`,id:o.toolCallId,name:t,input:o.input,cache_control:f}):n.push({type:`other`,message:`provider executed tool call for tool ${o.toolName} is not supported`});break}let t=o.providerOptions?.anthropic,i=t?.caller?(t.caller.type===`code_execution_20250825`||t.caller.type===`code_execution_20260120`)&&t.caller.toolId?{type:t.caller.type,tool_id:t.caller.toolId}:t.caller.type===`direct`?{type:`direct`}:void 0:void 0;e.push({type:`tool_use`,id:o.toolCallId,name:o.toolName,input:o.input,...i&&{caller:i},cache_control:f});break}case`tool-result`:{let t=a.toProviderToolName(o.toolName);if(r.has(o.toolCallId)){let t=o.output;if(t.type!==`json`&&t.type!==`error-json`){n.push({type:`other`,message:`provider executed tool result output type ${t.type} for tool ${o.toolName} is not supported`});break}e.push({type:`mcp_tool_result`,tool_use_id:o.toolCallId,is_error:t.type===`error-json`,content:t.value,cache_control:f})}else if(t===`code_execution`){let t=o.output;if(t.type===`error-text`||t.type===`error-json`){let n={};try{typeof t.value==`string`?n=JSON.parse(t.value):typeof t.value==`object`&&t.value!==null&&(n=t.value)}catch{}n.type===`code_execution_tool_result_error`?e.push({type:`code_execution_tool_result`,tool_use_id:o.toolCallId,content:{type:`code_execution_tool_result_error`,error_code:n.errorCode??`unknown`},cache_control:f}):e.push({type:`bash_code_execution_tool_result`,tool_use_id:o.toolCallId,cache_control:f,content:{type:`bash_code_execution_tool_result_error`,error_code:n.errorCode??`unknown`}});break}if(t.type!==`json`){n.push({type:`other`,message:`provider executed tool result output type ${t.type} for tool ${o.toolName} is not supported`});break}if(t.value==null||typeof t.value!=`object`||!(`type`in t.value)||typeof t.value.type!=`string`){n.push({type:`other`,message:`provider executed tool result output value is not a valid code execution result for tool ${o.toolName}`});break}if(t.value.type===`code_execution_result`){let n=await S({value:t.value,schema:je});e.push({type:`code_execution_tool_result`,tool_use_id:o.toolCallId,content:{type:n.type,stdout:n.stdout,stderr:n.stderr,return_code:n.return_code,content:n.content??[]},cache_control:f})}else if(t.value.type===`encrypted_code_execution_result`){let n=await S({value:t.value,schema:Le});n.type===`encrypted_code_execution_result`&&e.push({type:`code_execution_tool_result`,tool_use_id:o.toolCallId,content:{type:n.type,encrypted_stdout:n.encrypted_stdout,stderr:n.stderr,return_code:n.return_code,content:n.content??[]},cache_control:f})}else{let n=await S({value:t.value,schema:Pe});n.type===`code_execution_result`?e.push({type:`code_execution_tool_result`,tool_use_id:o.toolCallId,content:{type:n.type,stdout:n.stdout,stderr:n.stderr,return_code:n.return_code,content:n.content??[]},cache_control:f}):n.type===`bash_code_execution_result`||n.type===`bash_code_execution_tool_result_error`?e.push({type:`bash_code_execution_tool_result`,tool_use_id:o.toolCallId,cache_control:f,content:n}):e.push({type:`text_editor_code_execution_tool_result`,tool_use_id:o.toolCallId,cache_control:f,content:n})}break}if(t===`web_fetch`){let t=o.output;if(t.type===`error-json`){let n={};try{typeof t.value==`string`?n=JSON.parse(t.value):typeof t.value==`object`&&t.value!==null&&(n=t.value)}catch{let e=t.value?.errorCode;n={errorCode:typeof e==`string`?e:`unavailable`}}e.push({type:`web_fetch_tool_result`,tool_use_id:o.toolCallId,content:{type:`web_fetch_tool_result_error`,error_code:n.errorCode??`unavailable`},cache_control:f});break}if(t.type!==`json`){n.push({type:`other`,message:`provider executed tool result output type ${t.type} for tool ${o.toolName} is not supported`});break}let r=await S({value:t.value,schema:Ee});e.push({type:`web_fetch_tool_result`,tool_use_id:o.toolCallId,content:{type:`web_fetch_result`,url:r.url,retrieved_at:r.retrievedAt,content:{type:`document`,title:r.content.title,citations:r.content.citations,source:{type:r.content.source.type,media_type:r.content.source.mediaType,data:r.content.source.data}}},cache_control:f});break}if(t===`web_search`){let t=o.output;if(t.type!==`json`){n.push({type:`other`,message:`provider executed tool result output type ${t.type} for tool ${o.toolName} is not supported`});break}let r=await S({value:t.value,schema:ve});e.push({type:`web_search_tool_result`,tool_use_id:o.toolCallId,content:r.map(e=>({url:e.url,title:e.title,page_age:e.pageAge,encrypted_content:e.encryptedContent,type:e.type})),cache_control:f});break}if(t===`tool_search_tool_regex`||t===`tool_search_tool_bm25`){let t=o.output;if(t.type!==`json`){n.push({type:`other`,message:`provider executed tool result output type ${t.type} for tool ${o.toolName} is not supported`});break}let r=(await S({value:t.value,schema:Be})).map(e=>({type:`tool_reference`,tool_name:e.toolName}));e.push({type:`tool_search_tool_result`,tool_use_id:o.toolCallId,content:{type:`tool_search_tool_search_result`,tool_references:r},cache_control:f});break}n.push({type:`other`,message:`provider executed tool result for tool ${o.toolName} is not supported`});break}}}}u.push({role:`assistant`,content:e});break}default:throw Error(`content type: ${m}`)}}return{prompt:{system:l,messages:u},betas:o}}function Ge(e){let t=[],n;for(let r of e){let{role:e}=r;switch(e){case`system`:n?.type!==`system`&&(n={type:`system`,messages:[]},t.push(n)),n.messages.push(r);break;case`assistant`:n?.type!==`assistant`&&(n={type:`assistant`,messages:[]},t.push(n)),n.messages.push(r);break;case`user`:n?.type!==`user`&&(n={type:`user`,messages:[]},t.push(n)),n.messages.push(r);break;case`tool`:n?.type!==`user`&&(n={type:`user`,messages:[]},t.push(n)),n.messages.push(r);break;default:throw Error(`Unsupported role: ${e}`)}}return t}function Z({finishReason:e,isJsonResponseFromTool:t}){switch(e){case`pause_turn`:case`end_turn`:case`stop_sequence`:return`stop`;case`refusal`:return`content-filter`;case`tool_use`:return t?`stop`:`tool-calls`;case`max_tokens`:case`model_context_window_exceeded`:return`length`;case`compaction`:return`other`;default:return`other`}}var Ke=new Set([`date-time`,`time`,`date`,`duration`,`email`,`hostname`,`uri`,`ipv4`,`ipv6`,`uuid`]),qe=[`minimum`,`maximum`,`exclusiveMinimum`,`exclusiveMaximum`,`multipleOf`,`minLength`,`maxLength`,`pattern`,`minItems`,`maxItems`,`uniqueItems`,`minProperties`,`maxProperties`,`not`];function Je(e){return $(e)}function Q(e){return typeof e==`boolean`||!Qe(e)?e:$(e)}function $(e){let t={},n=e;if(e.$ref!=null)return{$ref:e.$ref};if(e.$schema!=null&&(t.$schema=e.$schema),e.$id!=null&&(t.$id=e.$id),e.title!=null&&(t.title=e.title),e.description!=null&&(t.description=e.description),e.default!==void 0&&(t.default=e.default),e.const!==void 0&&(t.const=e.const),e.enum!=null&&(t.enum=e.enum),e.type!=null&&(t.type=e.type),e.anyOf==null?e.oneOf!=null&&(t.anyOf=e.oneOf.map(Q)):t.anyOf=e.anyOf.map(Q),e.allOf!=null&&(t.allOf=e.allOf.map(Q)),e.definitions!=null&&(t.definitions=Object.fromEntries(Object.entries(e.definitions).map(([e,t])=>[e,Q(t)]))),n.$defs!=null){let e=t;e.$defs=Object.fromEntries(Object.entries(n.$defs).map(([e,t])=>[e,Q(t)]))}(e.type===`object`||e.properties!=null)&&(e.properties!=null&&(t.properties=Object.fromEntries(Object.entries(e.properties).map(([e,t])=>[e,Q(t)]))),t.additionalProperties=!1,e.required!=null&&(t.required=e.required)),e.items!=null&&(t.items=Array.isArray(e.items)?e.items.map(Q):Q(e.items)),typeof e.format==`string`&&Ke.has(e.format)&&(t.format=e.format);let r=Ye(e);return r!=null&&(t.description=t.description==null?r:`${t.description}
|
|
2
|
+
${r}`),t}function Ye(e){let t=qe.flatMap(t=>{let n=e[t];return n==null||n===!1?[]:`${Xe(t)}: ${Ze(n)}`});return typeof e.format==`string`&&!Ke.has(e.format)&&t.push(`format: ${e.format}`),t.length===0?void 0:`${t.join(`; `)}.`}function Xe(e){return e.replace(/[A-Z]/g,e=>` ${e.toLowerCase()}`)}function Ze(e){return typeof e==`string`?e:JSON.stringify(e)}function Qe(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function $e(e,t,n){if(e.type===`web_search_result_location`)return{type:`source`,sourceType:`url`,id:n(),url:e.url,title:e.title,providerMetadata:{anthropic:{citedText:e.cited_text,encryptedIndex:e.encrypted_index}}};if(e.type!==`page_location`&&e.type!==`char_location`)return;let r=t[e.document_index];if(r)return{type:`source`,sourceType:`document`,id:n(),mediaType:r.mediaType,title:e.document_title??r.title,filename:r.filename,providerMetadata:{anthropic:e.type===`page_location`?{citedText:e.cited_text,startPageNumber:e.start_page_number,endPageNumber:e.end_page_number}:{citedText:e.cited_text,startCharIndex:e.start_char_index,endCharIndex:e.end_char_index}}}}var et=class t{constructor(e,t){this.specificationVersion=`v4`,this.modelId=e,this.config=t,this.generateId=t.generateId??N}static[A](e){return ee({modelId:e.modelId,config:e.config})}static[j](e){return new t(e.modelId,e.config)}supportsUrl(e){return e.protocol===`https:`}get provider(){return this.config.provider}get providerOptionsName(){let e=this.config.provider,t=e.indexOf(`.`);return t===-1?e:e.substring(0,t)}get supportedUrls(){var e;return(e=this.config).supportedUrls?.call(e)??{}}async getArgs({userSuppliedBetas:e,prompt:t,maxOutputTokens:n,temperature:r,topP:i,topK:a,frequencyPenalty:o,presencePenalty:s,stopSequences:c,responseFormat:l,seed:u,tools:d,toolChoice:f,reasoning:p,providerOptions:m,stream:h}){let g=[];o!=null&&g.push({type:`unsupported`,feature:`frequencyPenalty`}),s!=null&&g.push({type:`unsupported`,feature:`presencePenalty`}),u!=null&&g.push({type:`unsupported`,feature:`seed`}),r!=null&&r>1?(g.push({type:`unsupported`,feature:`temperature`,details:`${r} exceeds anthropic maximum of 1.0. clamped to 1.0`}),r=1):r!=null&&r<0&&(g.push({type:`unsupported`,feature:`temperature`,details:`${r} is below anthropic minimum of 0. clamped to 0`}),r=0),l?.type===`json`&&(l.schema??g.push({type:`unsupported`,feature:`responseFormat`,details:`JSON response format requires a schema. The response format is ignored.`}));let _=this.providerOptionsName,y=await x({provider:`anthropic`,providerOptions:m,schema:se}),b=_===`anthropic`?null:await x({provider:_,providerOptions:m,schema:se}),S=b!=null,C=Object.assign({},y??{},b??{}),{maxOutputTokens:w,supportsStructuredOutput:T,supportsAdaptiveThinking:E,rejectsSamplingParameters:D,supportsXhighEffort:O,isKnownModel:k}=tt(this.modelId);D&&(r!=null&&(g.push({type:`unsupported`,feature:`temperature`,details:`temperature is not supported by ${this.modelId} and will be ignored`}),r=void 0),a!=null&&(g.push({type:`unsupported`,feature:`topK`,details:`topK is not supported by ${this.modelId} and will be ignored`}),a=void 0),i!=null&&(g.push({type:`unsupported`,feature:`topP`,details:`topP is not supported by ${this.modelId} and will be ignored`}),i=void 0));let ee=k||this.modelId.startsWith(`claude-`),A=(this.config.supportsNativeStructuredOutput??!0)&&T,j=(this.config.supportsStrictTools??!0)&&T,M=C?.structuredOutputMode??`auto`,N=M===`outputFormat`||M===`auto`&&A,P=l?.type===`json`&&l.schema!=null&&!N?{type:`function`,name:`json`,description:`Respond with a JSON object.`,inputSchema:l.schema}:void 0,F=C?.contextManagement,I=new X,L=te({tools:d,providerToolNames:{"anthropic.code_execution_20250522":`code_execution`,"anthropic.code_execution_20250825":`code_execution`,"anthropic.code_execution_20260120":`code_execution`,"anthropic.computer_20241022":`computer`,"anthropic.computer_20250124":`computer`,"anthropic.text_editor_20241022":`str_replace_editor`,"anthropic.text_editor_20250124":`str_replace_editor`,"anthropic.text_editor_20250429":`str_replace_based_edit_tool`,"anthropic.text_editor_20250728":`str_replace_based_edit_tool`,"anthropic.bash_20241022":`bash`,"anthropic.bash_20250124":`bash`,"anthropic.memory_20250818":`memory`,"anthropic.web_search_20250305":`web_search`,"anthropic.web_search_20260209":`web_search`,"anthropic.web_fetch_20250910":`web_fetch`,"anthropic.web_fetch_20260209":`web_fetch`,"anthropic.tool_search_regex_20251119":`tool_search_tool_regex`,"anthropic.tool_search_bm25_20251119":`tool_search_tool_bm25`}}),{prompt:R,betas:z}=await We({prompt:t,sendReasoning:C?.sendReasoning??!0,warnings:g,cacheControlValidator:I,toolNameMapping:L});if(ne(p)&&C?.effort==null){let e=rt({reasoning:p,supportsAdaptiveThinking:E,supportsXhighEffort:O,maxOutputTokensForModel:w,warnings:g});e!=null&&(C.thinking??=e.thinking,e.effort!=null&&C.thinking?.type!==`disabled`&&(C.effort=e.effort))}let B=C?.thinking?.type,V=B===`enabled`||B===`adaptive`,H=B===`enabled`?C?.thinking?.budgetTokens:void 0,U=B===`adaptive`?C?.thinking?.display:void 0,W=n??w,G={model:this.modelId,max_tokens:W,temperature:r,top_k:a,top_p:i,stop_sequences:c,...V&&{thinking:{type:B,...H!=null&&{budget_tokens:H},...U!=null&&{display:U}}},...(C?.effort||C?.taskBudget||N&&l?.type===`json`&&l.schema!=null)&&{output_config:{...C?.effort&&{effort:C.effort},...C?.taskBudget&&{task_budget:{type:C.taskBudget.type,total:C.taskBudget.total,...C.taskBudget.remaining!=null&&{remaining:C.taskBudget.remaining}}},...N&&l?.type===`json`&&l.schema!=null&&{format:{type:`json_schema`,schema:Je(l.schema)}}}},...C?.speed&&{speed:C.speed},...C?.inferenceGeo&&{inference_geo:C.inferenceGeo},...C?.cacheControl&&{cache_control:C.cacheControl},...C?.metadata?.userId!=null&&{metadata:{user_id:C.metadata.userId}},...C?.mcpServers&&C.mcpServers.length>0&&{mcp_servers:C.mcpServers.map(e=>({type:e.type,name:e.name,url:e.url,authorization_token:e.authorizationToken,tool_configuration:e.toolConfiguration?{allowed_tools:e.toolConfiguration.allowedTools,enabled:e.toolConfiguration.enabled}:void 0}))},...C?.container&&{container:C.container.skills&&C.container.skills.length>0?{id:C.container.id,skills:C.container.skills.map(e=>({type:e.type,skill_id:e.type===`custom`?v({reference:e.providerReference,provider:`anthropic`}):e.skillId,version:e.version}))}:C.container.id},system:R.system,messages:R.messages,...F&&{context_management:{edits:F.edits.map(e=>{let t=e.type;switch(t){case`clear_tool_uses_20250919`:return{type:e.type,...e.trigger!==void 0&&{trigger:e.trigger},...e.keep!==void 0&&{keep:e.keep},...e.clearAtLeast!==void 0&&{clear_at_least:e.clearAtLeast},...e.clearToolInputs!==void 0&&{clear_tool_inputs:e.clearToolInputs},...e.excludeTools!==void 0&&{exclude_tools:e.excludeTools}};case`clear_thinking_20251015`:return{type:e.type,...e.keep!==void 0&&{keep:e.keep}};case`compact_20260112`:return{type:e.type,...e.trigger!==void 0&&{trigger:e.trigger},...e.pauseAfterCompaction!==void 0&&{pause_after_compaction:e.pauseAfterCompaction},...e.instructions!==void 0&&{instructions:e.instructions}};default:g.push({type:`other`,message:`Unknown context management strategy: ${t}`});return}}).filter(e=>e!==void 0)}}};V?(B===`enabled`&&H==null&&(g.push({type:`compatibility`,feature:`extended thinking`,details:`thinking budget is required when thinking is enabled. using default budget of 1024 tokens.`}),G.thinking={type:`enabled`,budget_tokens:1024},H=1024),G.temperature!=null&&(G.temperature=void 0,g.push({type:`unsupported`,feature:`temperature`,details:`temperature is not supported when thinking is enabled`})),a!=null&&(G.top_k=void 0,g.push({type:`unsupported`,feature:`topK`,details:`topK is not supported when thinking is enabled`})),i!=null&&(G.top_p=void 0,g.push({type:`unsupported`,feature:`topP`,details:`topP is not supported when thinking is enabled`})),G.max_tokens=W+(H??0)):ee&&i!=null&&r!=null&&(g.push({type:`unsupported`,feature:`topP`,details:`topP is not supported when temperature is set. topP is ignored.`}),G.top_p=void 0),k&&G.max_tokens>w&&(n!=null&&g.push({type:`unsupported`,feature:`maxOutputTokens`,details:`${G.max_tokens} (maxOutputTokens + thinkingBudget) is greater than ${this.modelId} ${w} max output tokens. The max output tokens have been limited to ${w}.`}),G.max_tokens=w),C?.mcpServers&&C.mcpServers.length>0&&z.add(`mcp-client-2025-04-04`),F&&(z.add(`context-management-2025-06-27`),F.edits.some(e=>e.type===`compact_20260112`)&&z.add(`compact-2026-01-12`)),C?.container&&C.container.skills&&C.container.skills.length>0&&(z.add(`code-execution-2025-08-25`),z.add(`skills-2025-10-02`),z.add(`files-api-2025-04-14`),d?.some(e=>e.type===`provider`&&(e.id===`anthropic.code_execution_20250825`||e.id===`anthropic.code_execution_20260120`))||g.push({type:`other`,message:`code execution tool is required when using skills`})),C?.taskBudget&&z.add(`task-budgets-2026-03-13`),C?.speed===`fast`&&z.add(`fast-mode-2026-02-01`);let K=h&&(C?.toolStreaming??!0),{tools:q,toolChoice:re,toolWarnings:ie,betas:ae}=await ke(P==null?{tools:d??[],toolChoice:f,disableParallelToolUse:C?.disableParallelToolUse,cacheControlValidator:I,supportsStructuredOutput:A,supportsStrictTools:j,defaultEagerInputStreaming:K}:{tools:[...d??[],P],toolChoice:{type:`required`},disableParallelToolUse:!0,cacheControlValidator:I,supportsStructuredOutput:!1,supportsStrictTools:j,defaultEagerInputStreaming:K}),J=I.getWarnings();return{args:{...G,tools:q,tool_choice:re,stream:h===!0?!0:void 0},warnings:[...g,...ie,...J],betas:new Set([...z,...ae,...e,...C?.anthropicBeta??[]]),usesJsonResponseTool:P!=null,toolNameMapping:L,providerOptionsName:_,usedCustomProviderKey:S}}async getHeaders({betas:e,headers:t}){return U(this.config.headers?await k(this.config.headers):void 0,t,e.size>0?{"anthropic-beta":Array.from(e).join(`,`)}:{})}async getBetasFromHeaders(e){let t=(this.config.headers?await k(this.config.headers):void 0)?.[`anthropic-beta`]??``,n=e?.[`anthropic-beta`]??``;return new Set([...t.toLowerCase().split(`,`),...n.toLowerCase().split(`,`)].map(e=>e.trim()).filter(e=>e!==``))}buildRequestUrl(e){var t;return(t=this.config).buildRequestUrl?.call(t,this.config.baseURL,e)??`${this.config.baseURL}/messages`}transformRequestBody(e,t){var n;return(n=this.config).transformRequestBody?.call(n,e,t)??e}extractCitationDocuments(e){return e.filter(e=>e.role===`user`).flatMap(e=>e.content).filter(e=>e.type!==`file`||e.mediaType!==`application/pdf`&&e.mediaType!==`text/plain`?!1:e.providerOptions?.anthropic?.citations?.enabled??!1).map(e=>{let t=e;return{title:t.filename??`Untitled Document`,filename:t.filename,mediaType:t.mediaType}})}async doGenerate(e){let{args:t,warnings:n,betas:r,usesJsonResponseTool:i,toolNameMapping:a,providerOptionsName:o,usedCustomProviderKey:s}=await this.getArgs({...e,stream:!1,userSuppliedBetas:await this.getBetasFromHeaders(e.headers)}),c=[...this.extractCitationDocuments(e.prompt)],l=nt(t.tools),{responseHeaders:u,value:d,rawValue:f}=await E({url:this.buildRequestUrl(!1),headers:await this.getHeaders({betas:r,headers:e.headers}),body:this.transformRequestBody(t,r),failedResponseHandler:q,successfulResponseHandler:F(ae),abortSignal:e.abortSignal,fetch:this.config.fetch}),p=[],m={},h={},g=!1;for(let e of d.content)switch(e.type){case`text`:if(!i&&(p.push({type:`text`,text:e.text}),e.citations))for(let t of e.citations){let e=$e(t,c,this.generateId);e&&p.push(e)}break;case`thinking`:p.push({type:`reasoning`,text:e.thinking,providerMetadata:{anthropic:{signature:e.signature}}});break;case`redacted_thinking`:p.push({type:`reasoning`,text:``,providerMetadata:{anthropic:{redactedData:e.data}}});break;case`compaction`:p.push({type:`text`,text:e.content,providerMetadata:{anthropic:{type:`compaction`}}});break;case`tool_use`:if(i&&e.name===`json`)g=!0,p.push({type:`text`,text:JSON.stringify(e.input)});else{let t=e.caller,n=t?{type:t.type,toolId:`tool_id`in t?t.tool_id:void 0}:void 0;p.push({type:`tool-call`,toolCallId:e.id,toolName:e.name,input:JSON.stringify(e.input),...n&&{providerMetadata:{anthropic:{caller:n}}}})}break;case`server_tool_use`:if(e.name===`text_editor_code_execution`||e.name===`bash_code_execution`)p.push({type:`tool-call`,toolCallId:e.id,toolName:a.toCustomToolName(`code_execution`),input:JSON.stringify({type:e.name,...e.input}),providerExecuted:!0});else if(e.name===`web_search`||e.name===`code_execution`||e.name===`web_fetch`){let t=e.name===`code_execution`&&e.input!=null&&typeof e.input==`object`&&`code`in e.input&&!(`type`in e.input)?{type:`programmatic-tool-call`,...e.input}:e.input;p.push({type:`tool-call`,toolCallId:e.id,toolName:a.toCustomToolName(e.name),input:JSON.stringify(t),providerExecuted:!0,...l&&e.name===`code_execution`?{dynamic:!0}:{}})}else (e.name===`tool_search_tool_regex`||e.name===`tool_search_tool_bm25`)&&(h[e.id]=e.name,p.push({type:`tool-call`,toolCallId:e.id,toolName:a.toCustomToolName(e.name),input:JSON.stringify(e.input),providerExecuted:!0}));break;case`mcp_tool_use`:m[e.id]={type:`tool-call`,toolCallId:e.id,toolName:e.name,input:JSON.stringify(e.input),providerExecuted:!0,dynamic:!0,providerMetadata:{anthropic:{type:`mcp-tool-use`,serverName:e.server_name}}},p.push(m[e.id]);break;case`mcp_tool_result`:p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:m[e.tool_use_id].toolName,isError:e.is_error,result:e.content,dynamic:!0,providerMetadata:m[e.tool_use_id].providerMetadata});break;case`web_fetch_tool_result`:e.content.type===`web_fetch_result`?(c.push({title:e.content.content.title??e.content.url,mediaType:e.content.content.source.media_type}),p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`web_fetch`),result:{type:`web_fetch_result`,url:e.content.url,retrievedAt:e.content.retrieved_at,content:{type:e.content.content.type,title:e.content.content.title,citations:e.content.content.citations,source:{type:e.content.content.source.type,mediaType:e.content.content.source.media_type,data:e.content.content.source.data}}}})):e.content.type===`web_fetch_tool_result_error`&&p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`web_fetch`),isError:!0,result:{type:`web_fetch_tool_result_error`,errorCode:e.content.error_code}});break;case`web_search_tool_result`:if(Array.isArray(e.content)){p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`web_search`),result:e.content.map(e=>({url:e.url,title:e.title,pageAge:e.page_age??null,encryptedContent:e.encrypted_content,type:e.type}))});for(let t of e.content)p.push({type:`source`,sourceType:`url`,id:this.generateId(),url:t.url,title:t.title,providerMetadata:{anthropic:{pageAge:t.page_age??null}}})}else p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`web_search`),isError:!0,result:{type:`web_search_tool_result_error`,errorCode:e.content.error_code}});break;case`code_execution_tool_result`:e.content.type===`code_execution_result`?p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`code_execution`),result:{type:e.content.type,stdout:e.content.stdout,stderr:e.content.stderr,return_code:e.content.return_code,content:e.content.content??[]}}):e.content.type===`encrypted_code_execution_result`?p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`code_execution`),result:{type:e.content.type,encrypted_stdout:e.content.encrypted_stdout,stderr:e.content.stderr,return_code:e.content.return_code,content:e.content.content??[]}}):e.content.type===`code_execution_tool_result_error`&&p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`code_execution`),isError:!0,result:{type:`code_execution_tool_result_error`,errorCode:e.content.error_code}});break;case`bash_code_execution_tool_result`:case`text_editor_code_execution_tool_result`:p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`code_execution`),result:e.content});break;case`tool_search_tool_result`:{let t=h[e.tool_use_id];if(t==null){let e=a.toCustomToolName(`tool_search_tool_bm25`);a.toCustomToolName(`tool_search_tool_regex`),t=e===`tool_search_tool_bm25`?`tool_search_tool_regex`:`tool_search_tool_bm25`}e.content.type===`tool_search_tool_search_result`?p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(t),result:e.content.tool_references.map(e=>({type:e.type,toolName:e.tool_name}))}):p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(t),isError:!0,result:{type:`tool_search_tool_result_error`,errorCode:e.content.error_code}});break}}return{content:p,finishReason:{unified:Z({finishReason:d.stop_reason,isJsonResponseFromTool:g}),raw:d.stop_reason??void 0},usage:Ae({usage:d.usage}),request:{body:t},response:{id:d.id??void 0,modelId:d.model??void 0,headers:u,body:f},warnings:n,providerMetadata:(()=>{let e={usage:d.usage,stopSequence:d.stop_sequence??null,iterations:d.usage.iterations?d.usage.iterations.map(e=>({type:e.type,inputTokens:e.input_tokens,outputTokens:e.output_tokens})):null,container:d.container?{expiresAt:d.container.expires_at,id:d.container.id,skills:d.container.skills?.map(e=>({type:e.type,skillId:e.skill_id,version:e.version}))??null}:null,contextManagement:it(d.context_management)??null},t={anthropic:e};return s&&o!==`anthropic`&&(t[o]=e),t})()}}async doStream(t){"use step";let{args:n,warnings:r,betas:i,usesJsonResponseTool:a,toolNameMapping:o,providerOptionsName:s,usedCustomProviderKey:c}=await this.getArgs({...t,stream:!0,userSuppliedBetas:await this.getBetasFromHeaders(t.headers)}),l=[...this.extractCitationDocuments(t.prompt)],u=nt(n.tools),d=this.buildRequestUrl(!0),{responseHeaders:f,value:p}=await E({url:d,headers:await this.getHeaders({betas:i,headers:t.headers}),body:this.transformRequestBody(n,i),failedResponseHandler:q,successfulResponseHandler:W(J),abortSignal:t.abortSignal,fetch:this.config.fetch}),m={unified:`other`,raw:void 0},h={input_tokens:0,output_tokens:0,cache_creation_input_tokens:0,cache_read_input_tokens:0,iterations:null},g={},_={},v={},y=null,b,x=null,S=null,C=!1,w,T=this.generateId,[D,O]=p.pipeThrough(new TransformStream({start(e){e.enqueue({type:`stream-start`,warnings:r})},transform(e,n){if(t.includeRawChunks&&n.enqueue({type:`raw`,rawValue:e.rawValue}),!e.success){n.enqueue({type:`error`,error:e.error});return}let r=e.value;switch(r.type){case`ping`:return;case`content_block_start`:{let e=r.content_block,t=e.type;switch(w=t,t){case`text`:if(a)return;g[r.index]={type:`text`},n.enqueue({type:`text-start`,id:String(r.index)});return;case`thinking`:g[r.index]={type:`reasoning`},n.enqueue({type:`reasoning-start`,id:String(r.index)});return;case`redacted_thinking`:g[r.index]={type:`reasoning`},n.enqueue({type:`reasoning-start`,id:String(r.index),providerMetadata:{anthropic:{redactedData:e.data}}});return;case`compaction`:g[r.index]={type:`text`},n.enqueue({type:`text-start`,id:String(r.index),providerMetadata:{anthropic:{type:`compaction`}}});return;case`tool_use`:if(a&&e.name===`json`)C=!0,g[r.index]={type:`text`},n.enqueue({type:`text-start`,id:String(r.index)});else{let t=e.caller,i=t?{type:t.type,toolId:`tool_id`in t?t.tool_id:void 0}:void 0,a=e.input&&Object.keys(e.input).length>0?JSON.stringify(e.input):``;g[r.index]={type:`tool-call`,toolCallId:e.id,toolName:e.name,input:a,firstDelta:a.length===0,...i&&{caller:i}},n.enqueue({type:`tool-input-start`,id:e.id,toolName:e.name})}return;case`server_tool_use`:if([`web_fetch`,`web_search`,`code_execution`,`text_editor_code_execution`,`bash_code_execution`].includes(e.name)){let t=e.name===`text_editor_code_execution`||e.name===`bash_code_execution`?`code_execution`:e.name,i=o.toCustomToolName(t),a=e.input!=null&&typeof e.input==`object`&&Object.keys(e.input).length>0?JSON.stringify(e.input):``;g[r.index]={type:`tool-call`,toolCallId:e.id,toolName:i,input:a,providerExecuted:!0,...u&&t===`code_execution`?{dynamic:!0}:{},firstDelta:!0,providerToolName:e.name},n.enqueue({type:`tool-input-start`,id:e.id,toolName:i,providerExecuted:!0,...u&&t===`code_execution`?{dynamic:!0}:{}})}else if(e.name===`tool_search_tool_regex`||e.name===`tool_search_tool_bm25`){v[e.id]=e.name;let t=o.toCustomToolName(e.name);g[r.index]={type:`tool-call`,toolCallId:e.id,toolName:t,input:``,providerExecuted:!0,firstDelta:!0,providerToolName:e.name},n.enqueue({type:`tool-input-start`,id:e.id,toolName:t,providerExecuted:!0})}return;case`web_fetch_tool_result`:e.content.type===`web_fetch_result`?(l.push({title:e.content.content.title??e.content.url,mediaType:e.content.content.source.media_type}),n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(`web_fetch`),result:{type:`web_fetch_result`,url:e.content.url,retrievedAt:e.content.retrieved_at,content:{type:e.content.content.type,title:e.content.content.title,citations:e.content.content.citations,source:{type:e.content.content.source.type,mediaType:e.content.content.source.media_type,data:e.content.content.source.data}}}})):e.content.type===`web_fetch_tool_result_error`&&n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(`web_fetch`),isError:!0,result:{type:`web_fetch_tool_result_error`,errorCode:e.content.error_code}});return;case`web_search_tool_result`:if(Array.isArray(e.content)){n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(`web_search`),result:e.content.map(e=>({url:e.url,title:e.title,pageAge:e.page_age??null,encryptedContent:e.encrypted_content,type:e.type}))});for(let t of e.content)n.enqueue({type:`source`,sourceType:`url`,id:T(),url:t.url,title:t.title,providerMetadata:{anthropic:{pageAge:t.page_age??null}}})}else n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(`web_search`),isError:!0,result:{type:`web_search_tool_result_error`,errorCode:e.content.error_code}});return;case`code_execution_tool_result`:e.content.type===`code_execution_result`?n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(`code_execution`),result:{type:e.content.type,stdout:e.content.stdout,stderr:e.content.stderr,return_code:e.content.return_code,content:e.content.content??[]}}):e.content.type===`encrypted_code_execution_result`?n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(`code_execution`),result:{type:e.content.type,encrypted_stdout:e.content.encrypted_stdout,stderr:e.content.stderr,return_code:e.content.return_code,content:e.content.content??[]}}):e.content.type===`code_execution_tool_result_error`&&n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(`code_execution`),isError:!0,result:{type:`code_execution_tool_result_error`,errorCode:e.content.error_code}});return;case`bash_code_execution_tool_result`:case`text_editor_code_execution_tool_result`:n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(`code_execution`),result:e.content});return;case`tool_search_tool_result`:{let t=v[e.tool_use_id];if(t==null){let e=o.toCustomToolName(`tool_search_tool_bm25`);o.toCustomToolName(`tool_search_tool_regex`),t=e===`tool_search_tool_bm25`?`tool_search_tool_regex`:`tool_search_tool_bm25`}e.content.type===`tool_search_tool_search_result`?n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(t),result:e.content.tool_references.map(e=>({type:e.type,toolName:e.tool_name}))}):n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(t),isError:!0,result:{type:`tool_search_tool_result_error`,errorCode:e.content.error_code}});return}case`mcp_tool_use`:_[e.id]={type:`tool-call`,toolCallId:e.id,toolName:e.name,input:JSON.stringify(e.input),providerExecuted:!0,dynamic:!0,providerMetadata:{anthropic:{type:`mcp-tool-use`,serverName:e.server_name}}},n.enqueue(_[e.id]);return;case`mcp_tool_result`:n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:_[e.tool_use_id].toolName,isError:e.is_error,result:e.content,dynamic:!0,providerMetadata:_[e.tool_use_id].providerMetadata});return;default:throw Error(`Unsupported content block type: ${t}`)}}case`content_block_stop`:if(g[r.index]!=null){let e=g[r.index];switch(e.type){case`text`:n.enqueue({type:`text-end`,id:String(r.index)});break;case`reasoning`:n.enqueue({type:`reasoning-end`,id:String(r.index)});break;case`tool-call`:if(!(a&&e.toolName===`json`)){n.enqueue({type:`tool-input-end`,id:e.toolCallId});let t=e.input===``?`{}`:e.input;if(e.providerToolName===`code_execution`)try{let e=JSON.parse(t);typeof e==`object`&&e&&`code`in e&&!(`type`in e)&&(t=JSON.stringify({type:`programmatic-tool-call`,...e}))}catch{}n.enqueue({type:`tool-call`,toolCallId:e.toolCallId,toolName:e.toolName,input:t,providerExecuted:e.providerExecuted,...u&&e.providerToolName===`code_execution`?{dynamic:!0}:{},...e.caller&&{providerMetadata:{anthropic:{caller:e.caller}}}})}break}delete g[r.index]}w=void 0;return;case`content_block_delta`:{let e=r.delta.type;switch(e){case`text_delta`:if(a)return;n.enqueue({type:`text-delta`,id:String(r.index),delta:r.delta.text});return;case`thinking_delta`:n.enqueue({type:`reasoning-delta`,id:String(r.index),delta:r.delta.thinking});return;case`signature_delta`:w===`thinking`&&n.enqueue({type:`reasoning-delta`,id:String(r.index),delta:``,providerMetadata:{anthropic:{signature:r.delta.signature}}});return;case`compaction_delta`:r.delta.content!=null&&n.enqueue({type:`text-delta`,id:String(r.index),delta:r.delta.content});return;case`input_json_delta`:{let e=g[r.index],t=r.delta.partial_json;if(t.length===0)return;if(C){if(e?.type!==`text`)return;n.enqueue({type:`text-delta`,id:String(r.index),delta:t})}else{if(e?.type!==`tool-call`)return;e.firstDelta&&(e.providerToolName===`bash_code_execution`||e.providerToolName===`text_editor_code_execution`)&&(t=`{"type": "${e.providerToolName}",${t.substring(1)}`),n.enqueue({type:`tool-input-delta`,id:e.toolCallId,delta:t}),e.input+=t,e.firstDelta=!1}return}case`citations_delta`:{let e=r.delta.citation,t=$e(e,l,T);t&&n.enqueue(t);return}default:throw Error(`Unsupported delta type: ${e}`)}}case`message_start`:if(h.input_tokens=r.message.usage.input_tokens,h.cache_read_input_tokens=r.message.usage.cache_read_input_tokens??0,h.cache_creation_input_tokens=r.message.usage.cache_creation_input_tokens??0,b={...r.message.usage},r.message.container!=null&&(S={expiresAt:r.message.container.expires_at,id:r.message.container.id,skills:null}),r.message.stop_reason!=null&&(m={unified:Z({finishReason:r.message.stop_reason,isJsonResponseFromTool:C}),raw:r.message.stop_reason}),n.enqueue({type:`response-metadata`,id:r.message.id??void 0,modelId:r.message.model??void 0}),r.message.content!=null)for(let e=0;e<r.message.content.length;e++){let t=r.message.content[e];if(t.type===`tool_use`){let e=t.caller,r=e?{type:e.type,toolId:`tool_id`in e?e.tool_id:void 0}:void 0;n.enqueue({type:`tool-input-start`,id:t.id,toolName:t.name});let i=JSON.stringify(t.input??{});n.enqueue({type:`tool-input-delta`,id:t.id,delta:i}),n.enqueue({type:`tool-input-end`,id:t.id}),n.enqueue({type:`tool-call`,toolCallId:t.id,toolName:t.name,input:i,...r&&{providerMetadata:{anthropic:{caller:r}}}})}}return;case`message_delta`:r.usage.input_tokens!=null&&h.input_tokens!==r.usage.input_tokens&&(h.input_tokens=r.usage.input_tokens),h.output_tokens=r.usage.output_tokens,r.usage.cache_read_input_tokens!=null&&(h.cache_read_input_tokens=r.usage.cache_read_input_tokens),r.usage.cache_creation_input_tokens!=null&&(h.cache_creation_input_tokens=r.usage.cache_creation_input_tokens),r.usage.iterations!=null&&(h.iterations=r.usage.iterations),m={unified:Z({finishReason:r.delta.stop_reason,isJsonResponseFromTool:C}),raw:r.delta.stop_reason??void 0},x=r.delta.stop_sequence??null,S=r.delta.container==null?null:{expiresAt:r.delta.container.expires_at,id:r.delta.container.id,skills:r.delta.container.skills?.map(e=>({type:e.type,skillId:e.skill_id,version:e.version}))??null},r.context_management&&(y=it(r.context_management)),b={...b,...r.usage};return;case`message_stop`:{let e={usage:b??null,stopSequence:x,iterations:h.iterations?h.iterations.map(e=>({type:e.type,inputTokens:e.input_tokens,outputTokens:e.output_tokens})):null,container:S,contextManagement:y},t={anthropic:e};c&&s!==`anthropic`&&(t[s]=e),n.enqueue({type:`finish`,finishReason:m,usage:Ae({usage:h,rawUsage:b}),providerMetadata:t});return}case`error`:n.enqueue({type:`error`,error:r.error});return;default:throw Error(`Unsupported chunk type: ${r}`)}}})).tee(),k=D.getReader();try{await k.read();let t=await k.read();if(t.value?.type===`raw`&&(t=await k.read()),t.value?.type===`error`){let r=t.value.error;throw new e({message:r.message,url:d,requestBodyValues:n,statusCode:r.type===`overloaded_error`?529:500,responseHeaders:f,responseBody:JSON.stringify(r),isRetryable:r.type===`overloaded_error`})}}finally{k.cancel().catch(()=>{}),k.releaseLock()}return{stream:O,request:{body:n},response:{headers:f}}}};function tt(e){return e.includes(`claude-opus-4-7`)?{maxOutputTokens:128e3,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!0,supportsXhighEffort:!0,isKnownModel:!0}:e.includes(`claude-sonnet-4-6`)||e.includes(`claude-opus-4-6`)?{maxOutputTokens:128e3,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!0}:e.includes(`claude-sonnet-4-5`)||e.includes(`claude-opus-4-5`)||e.includes(`claude-haiku-4-5`)?{maxOutputTokens:64e3,supportsStructuredOutput:!0,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!0}:e.includes(`claude-opus-4-1`)?{maxOutputTokens:32e3,supportsStructuredOutput:!0,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!0}:e.includes(`claude-sonnet-4-`)?{maxOutputTokens:64e3,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!0}:e.includes(`claude-opus-4-`)?{maxOutputTokens:32e3,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!0}:e.includes(`claude-3-haiku`)?{maxOutputTokens:4096,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!0}:{maxOutputTokens:4096,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!1}}function nt(e){if(!e)return!1;let t=!1,n=!1;for(let r of e){if(`type`in r&&(r.type===`web_fetch_20260209`||r.type===`web_search_20260209`)){t=!0;continue}if(r.name===`code_execution`){n=!0;break}}return t&&!n}function rt({reasoning:e,supportsAdaptiveThinking:t,supportsXhighEffort:n,maxOutputTokensForModel:r,warnings:i}){if(!ne(e))return;if(e===`none`)return{thinking:{type:`disabled`}};if(t)return{thinking:{type:`adaptive`},effort:D({reasoning:e,effortMap:{minimal:`low`,low:`low`,medium:`medium`,high:`high`,xhigh:n?`xhigh`:`max`},warnings:i})};let a=R({reasoning:e,maxOutputTokens:r,maxReasoningBudget:r,warnings:i});if(a!=null)return{thinking:{type:`enabled`,budgetTokens:a}}}function it(e){return e?{appliedEdits:e.applied_edits.map(e=>{switch(e.type){case`clear_tool_uses_20250919`:return{type:e.type,clearedToolUses:e.cleared_tool_uses,clearedInputTokens:e.cleared_input_tokens};case`clear_thinking_20251015`:return{type:e.type,clearedThinkingTurns:e.cleared_thinking_turns,clearedInputTokens:e.cleared_input_tokens};case`compact_20260112`:return{type:e.type}}}).filter(e=>e!==void 0)}:null}var at=V({id:`anthropic.bash_20241022`,inputSchema:O(()=>w(u({command:l(),restart:i().optional()})))}),ot=V({id:`anthropic.bash_20250124`,inputSchema:O(()=>w(u({command:l(),restart:i().optional()})))}),st=V({id:`anthropic.computer_20241022`,inputSchema:O(()=>w(u({action:g([`key`,`type`,`mouse_move`,`left_click`,`left_click_drag`,`right_click`,`middle_click`,`double_click`,`screenshot`,`cursor_position`]),coordinate:o(h().int()).optional(),text:l().optional()})))}),ct=V({id:`anthropic.computer_20250124`,inputSchema:O(()=>w(u({action:g([`key`,`hold_key`,`type`,`cursor_position`,`mouse_move`,`left_mouse_down`,`left_mouse_up`,`left_click`,`left_click_drag`,`right_click`,`middle_click`,`double_click`,`triple_click`,`scroll`,`wait`,`screenshot`]),coordinate:s([h().int(),h().int()]).optional(),duration:h().optional(),scroll_amount:h().optional(),scroll_direction:g([`up`,`down`,`left`,`right`]).optional(),start_coordinate:s([h().int(),h().int()]).optional(),text:l().optional()})))}),lt=V({id:`anthropic.computer_20251124`,inputSchema:O(()=>w(u({action:g([`key`,`hold_key`,`type`,`cursor_position`,`mouse_move`,`left_mouse_down`,`left_mouse_up`,`left_click`,`left_click_drag`,`right_click`,`middle_click`,`double_click`,`triple_click`,`scroll`,`wait`,`screenshot`,`zoom`]),coordinate:s([h().int(),h().int()]).optional(),duration:h().optional(),region:s([h().int(),h().int(),h().int(),h().int()]).optional(),scroll_amount:h().optional(),scroll_direction:g([`up`,`down`,`left`,`right`]).optional(),start_coordinate:s([h().int(),h().int()]).optional(),text:l().optional()})))}),ut=V({id:`anthropic.memory_20250818`,inputSchema:O(()=>w(a(`command`,[u({command:p(`view`),path:l(),view_range:s([h(),h()]).optional()}),u({command:p(`create`),path:l(),file_text:l()}),u({command:p(`str_replace`),path:l(),old_str:l(),new_str:l()}),u({command:p(`insert`),path:l(),insert_line:h(),insert_text:l()}),u({command:p(`delete`),path:l()}),u({command:p(`rename`),old_path:l(),new_path:l()})])))}),dt=V({id:`anthropic.text_editor_20241022`,inputSchema:O(()=>w(u({command:g([`view`,`create`,`str_replace`,`insert`,`undo_edit`]),path:l(),file_text:l().optional(),insert_line:h().int().optional(),new_str:l().optional(),insert_text:l().optional(),old_str:l().optional(),view_range:o(h().int()).optional()})))}),ft=V({id:`anthropic.text_editor_20250124`,inputSchema:O(()=>w(u({command:g([`view`,`create`,`str_replace`,`insert`,`undo_edit`]),path:l(),file_text:l().optional(),insert_line:h().int().optional(),new_str:l().optional(),insert_text:l().optional(),old_str:l().optional(),view_range:o(h().int()).optional()})))}),pt=V({id:`anthropic.text_editor_20250429`,inputSchema:O(()=>w(u({command:g([`view`,`create`,`str_replace`,`insert`]),path:l(),file_text:l().optional(),insert_line:h().int().optional(),new_str:l().optional(),insert_text:l().optional(),old_str:l().optional(),view_range:o(h().int()).optional()})))}),mt=O(()=>w(o(u({type:p(`tool_reference`),toolName:l()})))),ht=I({id:`anthropic.tool_search_bm25_20251119`,inputSchema:O(()=>w(u({query:l(),limit:h().optional()}))),outputSchema:mt,supportsDeferredResults:!0}),gt={bash_20241022:at,bash_20250124:ot,codeExecution_20250522:Ne,codeExecution_20250825:Ie,codeExecution_20260120:ze,computer_20241022:st,computer_20250124:ct,computer_20251124:lt,memory_20250818:ut,textEditor_20241022:dt,textEditor_20250124:ft,textEditor_20250429:pt,textEditor_20250728:fe,webFetch_20250910:Oe,webFetch_20260209:we,webSearch_20250305:be,webSearch_20260209:ge,toolSearchRegex_20251119:He,toolSearchBm25_20251119:(e={})=>ht(e)},_t=O(()=>w(u({id:l(),display_title:l().nullish(),name:l().nullish(),description:l().nullish(),latest_version:l().nullish(),source:l(),created_at:l(),updated_at:l()})));O(()=>w(u({data:o(u({version:l()}))})));var vt=O(()=>w(u({type:l(),skill_id:l(),name:l().nullish(),description:l().nullish()}))),yt=class{constructor(e){this.config=e,this.specificationVersion=`v4`}get provider(){return this.config.provider}async getHeaders(){return U(await k(this.config.headers),{"anthropic-beta":`skills-2025-10-02`})}async fetchVersionMetadata({skillId:e,version:t,headers:n}){let{value:r}=await G({url:`${this.config.baseURL}/skills/${e}/versions/${t}`,headers:n,failedResponseHandler:q,successfulResponseHandler:F(vt),fetch:this.config.fetch});return{...r.name==null?{}:{name:r.name},...r.description==null?{}:{description:r.description}}}async uploadSkill(e){let t=[],n=new FormData;e.displayTitle!=null&&n.append(`display_title`,e.displayTitle);for(let t of e.files){let e=M(t.data);n.append(`files[]`,new Blob([e]),t.path)}let r=await this.getHeaders(),{value:i}=await C({url:`${this.config.baseURL}/skills`,headers:r,formData:n,failedResponseHandler:q,successfulResponseHandler:F(_t),fetch:this.config.fetch}),a=i.latest_version==null?{}:await this.fetchVersionMetadata({skillId:i.id,version:i.latest_version,headers:r}),o=a.name??i.name,s=a.description??i.description;return{providerReference:{anthropic:i.id},...i.display_title==null?{}:{displayTitle:i.display_title},...o==null?{}:{name:o},...s==null?{}:{description:s},...i.latest_version==null?{}:{latestVersion:i.latest_version},providerMetadata:{anthropic:{...i.source==null?{}:{source:i.source},...i.created_at==null?{}:{createdAt:i.created_at},...i.updated_at==null?{}:{updatedAt:i.updated_at}}},warnings:t}}},bt=`4.0.0-canary.46`;function xt(e={}){let r=H(_({settingValue:e.baseURL,environmentVariableName:`ANTHROPIC_BASE_URL`}))??`https://api.anthropic.com/v1`,i=e.name??`anthropic.messages`;if(e.apiKey&&e.authToken)throw new t({argument:`apiKey/authToken`,message:`Both apiKey and authToken were provided. Please use only one authentication method.`});let a=()=>T({"anthropic-version":`2023-06-01`,...e.authToken?{Authorization:`Bearer ${e.authToken}`}:{"x-api-key":z({apiKey:e.apiKey,environmentVariableName:`ANTHROPIC_API_KEY`,description:`Anthropic`})},...e.headers},`ai-sdk/anthropic/${bt}`),o=t=>new et(t,{provider:i,baseURL:r,headers:a,fetch:e.fetch,generateId:e.generateId??N,supportedUrls:()=>({"image/*":[/^https?:\/\/.*$/],"application/pdf":[/^https?:\/\/.*$/]})}),s=()=>new yt({provider:`${i.replace(`.messages`,``)}.skills`,baseURL:r,headers:a,fetch:e.fetch}),c=function(e){if(new.target)throw Error(`The Anthropic model function cannot be called with the new keyword.`);return o(e)};return c.specificationVersion=`v4`,c.languageModel=o,c.chat=o,c.messages=o,c.embeddingModel=e=>{throw new n({modelId:e,modelType:`embeddingModel`})},c.textEmbeddingModel=c.embeddingModel,c.imageModel=e=>{throw new n({modelId:e,modelType:`imageModel`})},c.files=()=>new ie({provider:i,baseURL:r,headers:a,fetch:e.fetch}),c.skills=s,c.tools=gt,c}var St=xt();function Ct({steps:e}){for(let t=e.length-1;t>=0;t--){let n=e[t].providerMetadata?.anthropic?.container?.id;if(n)return{providerOptions:{anthropic:{container:{id:n}}}}}}export{bt as VERSION,St as anthropic,xt as createAnthropic,Ct as forwardAnthropicContainerIdFromLastStep};
|