UNPKG

eve

Version:

Filesystem-first framework for durable backend AI agents that run anywhere.

2 lines 112 kB
import{APICallError as e,InvalidArgumentError as t,InvalidResponseDataError as n,NoSuchModelError as r,UnsupportedFunctionalityError as i}from"../provider/index.js";import{A as a,C as o,D as s,T as c,_ as l,b as u,c as d,f,g as p,k as m,m as h,r as g,u as _,v,y}from"../../_chunks/workflow/schemas-4CmFgxN_.js";import{$ as b,B as ee,C as x,F as S,G as C,J as w,K as T,L as E,M as D,N as O,S as k,V as A,W as j,X as te,Z as M,_ as N,_t as P,at as F,b as I,bt as L,c as R,dt as ne,et as z,g as B,h as V,ht as re,i as H,it as U,l as W,lt as G,m as ie,mt as K,o as ae,ot as oe,q as se,s as ce,tt as q,ut as J,w as le,xt as Y,yt as ue,z as de}from"../../_chunks/workflow/dist-C3919PVU.js";import{n as fe,r as pe,t as me}from"../../_chunks/workflow/experimental-evaluation-D8_K_Pe9.js";var he=j(()=>Y(u({type:p(`error`),error:u({type:c(),message:c()})}))),X=V({errorSchema:he,errorToMessage:e=>e.error.message}),ge=j(()=>Y(u({id:c(),type:p(`file`),filename:c(),mime_type:c(),size_bytes:y(),created_at:c(),downloadable:_().nullish()}))),_e=class{constructor(e){this.config=e,this.specificationVersion=`v4`}get provider(){return this.config.provider}async uploadFile({data:e,mediaType:t,filename:n,abortSignal:r,headers:i}){let a=R(e),o=new Blob([a],{type:t}),s=new FormData;n==null?s.append(`file`,o):s.append(`file`,o,n);let{value:c}=await z({url:`${this.config.baseURL}/files`,headers:H(this.config.headers(),{"anthropic-beta":`files-api-2025-04-14`},i),formData:s,failedResponseHandler:X,successfulResponseHandler:N(ge),abortSignal:r,fetch:this.config.fetch});return{warnings:[],providerReference:{anthropic:c.id},mediaType:c.mime_type??t,filename:c.filename??n,providerMetadata:{anthropic:{filename:c.filename,mimeType:c.mime_type,sizeBytes:c.size_bytes,createdAt:c.created_at,...c.downloadable==null?{}:{downloadable:c.downloadable}}}}}},ve=u({type:c(),category:c().nullish(),explanation:c().nullish(),recommended_model:c().nullish()}),Z=m([u({type:p(`code_execution_20250825`),tool_id:c()}),u({type:p(`code_execution_20260120`),tool_id:c()}),u({type:p(`direct`)})]),ye=f(`type`,[u({type:p(`web_search_result_location`),cited_text:c(),url:c(),title:c().nullable(),encrypted_index:c()}),u({type:p(`page_location`),cited_text:c(),document_index:y(),document_title:c().nullable(),start_page_number:y(),end_page_number:y(),file_id:c().nullish()}),u({type:p(`char_location`),cited_text:c(),document_index:y(),document_title:c().nullable(),start_char_index:y(),end_char_index:y(),file_id:c().nullish()}),u({type:p(`content_block_location`),cited_text:c(),document_index:y(),document_title:c().nullable(),start_block_index:y(),end_block_index:y(),file_id:c().nullable()}),u({type:p(`search_result_location`),cited_text:c(),search_result_index:y(),source:c(),title:c().nullable(),start_block_index:y(),end_block_index:y()})]),be=m([c(),d(m([c(),u({type:p(`text`),text:c(),citations:d(h()).nullable().optional()})]))]),xe=u({type:c(),path:c(),reason:c()}),Se=j(()=>Y(u({type:p(`message`),id:c().nullish(),model:c().nullish(),content:d(f(`type`,[u({type:p(`text`),text:c(),citations:d(ye).nullable().optional()}),u({type:p(`thinking`),thinking:c(),signature:c()}),u({type:p(`redacted_thinking`),data:c()}),u({type:p(`compaction`),content:c()}),u({type:p(`tool_use`),id:c(),name:c(),input:a(),caller:Z.optional()}),u({type:p(`server_tool_use`),id:c(),name:c(),input:o(c(),a()).nullish(),caller:Z.optional()}),u({type:p(`mcp_tool_use`),id:c(),name:c(),input:a(),server_name:c()}),u({type:p(`mcp_tool_result`),tool_use_id:c(),is_error:_(),content:be}),u({type:p(`web_fetch_tool_result`),tool_use_id:c(),caller:Z.optional(),content:m([u({type:p(`web_fetch_result`),url:c(),retrieved_at:c().nullable(),content:u({type:p(`document`),title:c().nullable(),citations:u({enabled:_()}).optional(),source:m([u({type:p(`base64`),media_type:p(`application/pdf`),data:c()}),u({type:p(`text`),media_type:p(`text/plain`),data:c()})])})}),u({type:p(`web_fetch_tool_result_error`),error_code:c()})])}),u({type:p(`web_search_tool_result`),tool_use_id:c(),caller:Z.optional(),content:m([d(u({type:p(`web_search_result`),url:c(),title:c().nullable(),encrypted_content:c(),page_age:c().nullish()})),u({type:p(`web_search_tool_result_error`),error_code:c()})])}),u({type:p(`code_execution_tool_result`),tool_use_id:c(),content:m([u({type:p(`code_execution_result`),stdout:c(),stderr:c(),return_code:y(),content:d(u({type:p(`code_execution_output`),file_id:c()})).optional().default([])}),u({type:p(`encrypted_code_execution_result`),encrypted_stdout:c(),stderr:c(),return_code:y(),content:d(u({type:p(`code_execution_output`),file_id:c()})).optional().default([])}),u({type:p(`code_execution_tool_result_error`),error_code:c()})])}),u({type:p(`bash_code_execution_tool_result`),tool_use_id:c(),content:f(`type`,[u({type:p(`bash_code_execution_result`),content:d(u({type:p(`bash_code_execution_output`),file_id:c()})),stdout:c(),stderr:c(),return_code:y()}),u({type:p(`bash_code_execution_tool_result_error`),error_code:c()})])}),u({type:p(`text_editor_code_execution_tool_result`),tool_use_id:c(),content:f(`type`,[u({type:p(`text_editor_code_execution_tool_result_error`),error_code:c()}),u({type:p(`text_editor_code_execution_view_result`),content:c(),file_type:c(),num_lines:y().nullable(),start_line:y().nullable(),total_lines:y().nullable()}),u({type:p(`text_editor_code_execution_create_result`),is_file_update:_()}),u({type:p(`text_editor_code_execution_str_replace_result`),lines:d(c()).nullable(),new_lines:y().nullable(),new_start:y().nullable(),old_lines:y().nullable(),old_start:y().nullable()})])}),u({type:p(`tool_search_tool_result`),tool_use_id:c(),content:m([u({type:p(`tool_search_tool_search_result`),tool_references:d(u({type:p(`tool_reference`),tool_name:c()}))}),u({type:p(`tool_search_tool_result_error`),error_code:c()})])}),u({type:p(`container_upload`),file_id:c()}),u({type:p(`advisor_tool_result`),tool_use_id:c(),content:f(`type`,[u({type:p(`advisor_result`),text:c(),stop_reason:c().nullish()}),u({type:p(`advisor_redacted_result`),encrypted_content:c(),stop_reason:c().nullish()}),u({type:p(`advisor_tool_result_error`),error_code:c()})])}),u({type:p(`fallback`)})])),stop_reason:c().nullish(),stop_sequence:c().nullish(),stop_details:ve.nullish(),input_transformations:d(xe).nullish(),usage:l({input_tokens:y(),output_tokens:y(),output_tokens_details:u({thinking_tokens:y().nullish()}).nullish(),cache_creation_input_tokens:y().nullish(),cache_read_input_tokens:y().nullish(),iterations:d(u({type:m([p(`compaction`),p(`message`),p(`advisor_message`),p(`fallback_message`)]),model:c().nullish(),input_tokens:y(),output_tokens:y(),cache_creation_input_tokens:y().nullish(),cache_read_input_tokens:y().nullish()})).nullish()}),container:u({expires_at:c(),id:c(),skills:d(u({type:m([p(`anthropic`),p(`custom`)]),skill_id:c(),version:c()})).nullish()}).nullish(),context_management:u({applied_edits:d(m([u({type:p(`clear_tool_uses_20250919`),cleared_tool_uses:y(),cleared_input_tokens:y()}),u({type:p(`clear_thinking_20251015`),cleared_thinking_turns:y(),cleared_input_tokens:y()}),u({type:p(`compact_20260112`)})]))}).nullish()}))),Ce=j(()=>Y(f(`type`,[u({type:p(`message_start`),message:u({id:c().nullish(),model:c().nullish(),role:c().nullish(),usage:l({input_tokens:y(),cache_creation_input_tokens:y().nullish(),cache_read_input_tokens:y().nullish()}),content:d(f(`type`,[u({type:p(`tool_use`),id:c(),name:c(),input:a(),caller:Z.optional()})])).nullish(),stop_reason:c().nullish(),input_transformations:d(xe).nullish(),container:u({expires_at:c(),id:c()}).nullish()})}),u({type:p(`content_block_start`),index:y(),content_block:f(`type`,[u({type:p(`text`),text:c()}),u({type:p(`thinking`),thinking:c()}),u({type:p(`tool_use`),id:c(),name:c(),input:o(c(),a()).optional(),caller:Z.optional()}),u({type:p(`redacted_thinking`),data:c()}),u({type:p(`compaction`),content:c().nullish()}),u({type:p(`server_tool_use`),id:c(),name:c(),input:o(c(),a()).nullish(),caller:Z.optional()}),u({type:p(`mcp_tool_use`),id:c(),name:c(),input:a(),server_name:c()}),u({type:p(`mcp_tool_result`),tool_use_id:c(),is_error:_(),content:be}),u({type:p(`web_fetch_tool_result`),tool_use_id:c(),caller:Z.optional(),content:m([u({type:p(`web_fetch_result`),url:c(),retrieved_at:c().nullable(),content:u({type:p(`document`),title:c().nullable(),citations:u({enabled:_()}).optional(),source:m([u({type:p(`base64`),media_type:p(`application/pdf`),data:c()}),u({type:p(`text`),media_type:p(`text/plain`),data:c()})])})}),u({type:p(`web_fetch_tool_result_error`),error_code:c()})])}),u({type:p(`web_search_tool_result`),tool_use_id:c(),caller:Z.optional(),content:m([d(u({type:p(`web_search_result`),url:c(),title:c().nullable(),encrypted_content:c(),page_age:c().nullish()})),u({type:p(`web_search_tool_result_error`),error_code:c()})])}),u({type:p(`code_execution_tool_result`),tool_use_id:c(),content:m([u({type:p(`code_execution_result`),stdout:c(),stderr:c(),return_code:y(),content:d(u({type:p(`code_execution_output`),file_id:c()})).optional().default([])}),u({type:p(`encrypted_code_execution_result`),encrypted_stdout:c(),stderr:c(),return_code:y(),content:d(u({type:p(`code_execution_output`),file_id:c()})).optional().default([])}),u({type:p(`code_execution_tool_result_error`),error_code:c()})])}),u({type:p(`bash_code_execution_tool_result`),tool_use_id:c(),content:f(`type`,[u({type:p(`bash_code_execution_result`),content:d(u({type:p(`bash_code_execution_output`),file_id:c()})),stdout:c(),stderr:c(),return_code:y()}),u({type:p(`bash_code_execution_tool_result_error`),error_code:c()})])}),u({type:p(`text_editor_code_execution_tool_result`),tool_use_id:c(),content:f(`type`,[u({type:p(`text_editor_code_execution_tool_result_error`),error_code:c()}),u({type:p(`text_editor_code_execution_view_result`),content:c(),file_type:c(),num_lines:y().nullable(),start_line:y().nullable(),total_lines:y().nullable()}),u({type:p(`text_editor_code_execution_create_result`),is_file_update:_()}),u({type:p(`text_editor_code_execution_str_replace_result`),lines:d(c()).nullable(),new_lines:y().nullable(),new_start:y().nullable(),old_lines:y().nullable(),old_start:y().nullable()})])}),u({type:p(`tool_search_tool_result`),tool_use_id:c(),content:m([u({type:p(`tool_search_tool_search_result`),tool_references:d(u({type:p(`tool_reference`),tool_name:c()}))}),u({type:p(`tool_search_tool_result_error`),error_code:c()})])}),u({type:p(`advisor_tool_result`),tool_use_id:c(),content:f(`type`,[u({type:p(`advisor_result`),text:c(),stop_reason:c().nullish()}),u({type:p(`advisor_redacted_result`),encrypted_content:c(),stop_reason:c().nullish()}),u({type:p(`advisor_tool_result_error`),error_code:c()})])}),u({type:p(`fallback`)})])}),u({type:p(`content_block_delta`),index:y(),delta:f(`type`,[u({type:p(`input_json_delta`),partial_json:c()}),u({type:p(`text_delta`),text:c()}),u({type:p(`thinking_delta`),thinking:c()}),u({type:p(`signature_delta`),signature:c()}),u({type:p(`compaction_delta`),content:c().nullish()}),u({type:p(`citations_delta`),citation:ye})])}),u({type:p(`content_block_stop`),index:y()}),u({type:p(`error`),error:u({type:c(),message:c(),code:m([c(),y()]).nullish(),statusCode:y().nullish(),isRetryable:_().nullish(),data:a().nullish()})}),u({type:p(`message_delta`),delta:u({stop_reason:c().nullish(),stop_sequence:c().nullish(),stop_details:ve.nullish(),container:u({expires_at:c(),id:c(),skills:d(u({type:m([p(`anthropic`),p(`custom`)]),skill_id:c(),version:c()})).nullish()}).nullish()}),usage:l({input_tokens:y().nullish(),output_tokens:y(),output_tokens_details:u({thinking_tokens:y().nullish()}).nullish(),cache_creation_input_tokens:y().nullish(),cache_read_input_tokens:y().nullish(),iterations:d(u({type:m([p(`compaction`),p(`message`),p(`advisor_message`),p(`fallback_message`)]),model:c().nullish(),input_tokens:y(),output_tokens:y(),cache_creation_input_tokens:y().nullish(),cache_read_input_tokens:y().nullish()})).nullish()}),input_transformations:d(xe).nullish(),context_management:u({applied_edits:d(m([u({type:p(`clear_tool_uses_20250919`),cleared_tool_uses:y(),cleared_input_tokens:y()}),u({type:p(`clear_thinking_20251015`),cleared_thinking_turns:y(),cleared_input_tokens:y()}),u({type:p(`compact_20260112`)})]))}).nullish()}),u({type:p(`message_stop`)}),u({type:p(`ping`)})]))),we=j(()=>Y(u({signature:c().optional(),redactedData:c().optional()}))),Te=u({containerUpload:_().optional(),citations:u({enabled:_()}).optional(),title:c().optional(),context:c().optional()}),Ee=u({clearAt:p(`next_user_message`).optional(),effort:g([`low`,`medium`,`high`,`xhigh`,`max`]).optional(),toolChanges:d(f(`type`,[u({type:p(`tool_addition`),toolName:c()}),u({type:p(`tool_removal`),toolName:c()})])).optional()}),De=u({sendReasoning:_().optional(),structuredOutputMode:g([`outputFormat`,`jsonTool`,`auto`]).optional(),thinking:m([f(`type`,[u({type:p(`adaptive`),display:g([`omitted`,`summarized`,`updates`]).optional(),blockBinding:u({prefixMismatchBehavior:g([`error`,`drop_block`])}).optional()}),u({type:p(`enabled`),budgetTokens:y().optional()}),u({type:p(`disabled`)})]),u({type:v().optional(),blockBinding:u({prefixMismatchBehavior:g([`error`,`drop_block`])})})]).optional(),disableParallelToolUse:_().optional(),cacheControl:u({type:p(`ephemeral`),ttl:m([p(`5m`),p(`1h`)]).optional()}).optional(),metadata:u({userId:c().optional()}).optional(),mcpServers:d(u({type:p(`url`),name:c(),url:c(),authorizationToken:c().nullish(),toolConfiguration:u({enabled:_().nullish(),allowedTools:d(c()).nullish()}).nullish()})).optional(),container:u({id:c().optional(),skills:d(f(`type`,[u({type:p(`anthropic`),skillId:c(),version:c().optional()}),u({type:p(`custom`),providerReference:o(c(),c()),version:c().optional()})])).optional()}).optional(),toolStreaming:_().optional(),effort:g([`low`,`medium`,`high`,`xhigh`,`max`]).optional(),taskBudget:u({type:p(`tokens`),total:y().int().min(2e4),remaining:y().int().min(0).optional()}).optional(),speed:g([`fast`,`standard`]).optional(),serviceTier:g([`auto`,`standard_only`]).optional(),inferenceGeo:g([`us`,`global`]).optional(),fallbacks:m([p(`default`),d(u({model:c(),max_tokens:y().int().optional(),thinking:o(c(),a()).optional(),output_config:o(c(),a()).optional(),speed:g([`fast`,`standard`]).optional()}))]).optional(),anthropicBeta:d(c()).optional(),contextManagement:u({edits:d(f(`type`,[u({type:p(`clear_tool_uses_20250919`),trigger:f(`type`,[u({type:p(`input_tokens`),value:y()}),u({type:p(`tool_uses`),value:y()})]).optional(),keep:u({type:p(`tool_uses`),value:y()}).optional(),clearAtLeast:u({type:p(`input_tokens`),value:y()}).optional(),clearToolInputs:_().optional(),excludeTools:d(c()).optional()}),u({type:p(`clear_thinking_20251015`),keep:m([p(`all`),u({type:p(`thinking_turns`),value:y()})]).optional()}),u({type:p(`compact_20260112`),trigger:u({type:p(`input_tokens`),value:y()}).optional(),pauseAfterCompaction:_().optional(),instructions:c().optional()})]))}).optional()}),Oe=4;function ke(e){let t=e?.anthropic;return t?.cacheControl??t?.cache_control}var Ae=class{constructor(){this.breakpointCount=0,this.warnings=[]}getCacheControl(e,t){let n=ke(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>Oe){this.warnings.push({type:`unsupported`,feature:`cacheControl breakpoint limit`,details:`Maximum ${Oe} cache breakpoints exceeded (found ${this.breakpointCount}). This breakpoint will be ignored.`});return}return n}}getWarnings(){return this.warnings}},je=j(()=>Y(u({model:c(),maxUses:y().optional(),maxTokens:y().int().min(1024).optional(),caching:u({type:p(`ephemeral`),ttl:m([p(`5m`),p(`1h`)])}).optional()}))),Me=j(()=>Y(f(`type`,[u({type:p(`advisor_result`),text:c(),stopReason:c().optional()}),u({type:p(`advisor_redacted_result`),encryptedContent:c(),stopReason:c().optional()}),u({type:p(`advisor_tool_result_error`),errorCode:c()})]))),Ne=j(()=>Y(u({}).strict())),Pe=k({id:`anthropic.advisor_20260301`,inputSchema:Ne,outputSchema:Me,supportsDeferredResults:!0}),Fe=e=>Pe(e),Ie=j(()=>Y(u({maxCharacters:y().optional()}))),Le=j(()=>Y(u({command:g([`view`,`create`,`str_replace`,`insert`]),path:c(),file_text:c().optional(),insert_line:y().int().optional(),new_str:c().optional(),insert_text:c().optional(),old_str:c().optional(),view_range:d(y().int()).optional()}))),Re=I({id:`anthropic.text_editor_20250728`,inputSchema:Le}),ze=(e={})=>Re(e),Be=j(()=>Y(u({maxUses:y().optional(),allowedDomains:d(c()).optional(),blockedDomains:d(c()).optional(),userLocation:u({type:p(`approximate`),city:c().optional(),region:c().optional(),country:c().optional(),timezone:c().optional()}).optional(),responseInclusion:g([`full`,`excluded`]).optional()}))),Ve=j(()=>Y(d(u({url:c(),title:c().nullable(),pageAge:c().nullable(),encryptedContent:c(),type:p(`web_search_result`)})))),He=j(()=>Y(u({query:c()}))),Ue=k({id:`anthropic.web_search_20260318`,inputSchema:He,outputSchema:Ve,supportsDeferredResults:!0}),We=(e={})=>Ue(e),Ge=j(()=>Y(u({maxUses:y().optional(),allowedDomains:d(c()).optional(),blockedDomains:d(c()).optional(),userLocation:u({type:p(`approximate`),city:c().optional(),region:c().optional(),country:c().optional(),timezone:c().optional()}).optional()}))),Ke=j(()=>Y(d(u({url:c(),title:c().nullable(),pageAge:c().nullable(),encryptedContent:c(),type:p(`web_search_result`)})))),qe=j(()=>Y(u({query:c()}))),Je=k({id:`anthropic.web_search_20260209`,inputSchema:qe,outputSchema:Ke,supportsDeferredResults:!0}),Ye=(e={})=>Je(e),Xe=j(()=>Y(u({maxUses:y().optional(),allowedDomains:d(c()).optional(),blockedDomains:d(c()).optional(),userLocation:u({type:p(`approximate`),city:c().optional(),region:c().optional(),country:c().optional(),timezone:c().optional()}).optional()}))),Ze=j(()=>Y(d(u({url:c(),title:c().nullable(),pageAge:c().nullable(),encryptedContent:c(),type:p(`web_search_result`)})))),Qe=j(()=>Y(u({query:c()}))),$e=k({id:`anthropic.web_search_20250305`,inputSchema:Qe,outputSchema:Ze,supportsDeferredResults:!0}),et=(e={})=>$e(e),tt=j(()=>Y(u({maxUses:y().optional(),allowedDomains:d(c()).optional(),blockedDomains:d(c()).optional(),citations:u({enabled:_()}).optional(),maxContentTokens:y().optional(),useCache:_().optional(),responseInclusion:g([`full`,`excluded`]).optional()}))),nt=j(()=>Y(u({type:p(`web_fetch_result`),url:c(),content:u({type:p(`document`),title:c().nullable(),citations:u({enabled:_()}).optional(),source:m([u({type:p(`base64`),mediaType:p(`application/pdf`),data:c()}),u({type:p(`text`),mediaType:p(`text/plain`),data:c()})])}),retrievedAt:c().nullable()}))),rt=j(()=>Y(u({url:c()}))),it=k({id:`anthropic.web_fetch_20260318`,inputSchema:rt,outputSchema:nt,supportsDeferredResults:!0}),at=(e={})=>it(e),ot=j(()=>Y(u({maxUses:y().optional(),allowedDomains:d(c()).optional(),blockedDomains:d(c()).optional(),citations:u({enabled:_()}).optional(),maxContentTokens:y().optional()}))),st=j(()=>Y(u({type:p(`web_fetch_result`),url:c(),content:u({type:p(`document`),title:c().nullable(),citations:u({enabled:_()}).optional(),source:m([u({type:p(`base64`),mediaType:p(`application/pdf`),data:c()}),u({type:p(`text`),mediaType:p(`text/plain`),data:c()})])}),retrievedAt:c().nullable()}))),ct=j(()=>Y(u({url:c()}))),lt=k({id:`anthropic.web_fetch_20260209`,inputSchema:ct,outputSchema:st,supportsDeferredResults:!0}),ut=(e={})=>lt(e),dt=j(()=>Y(u({maxUses:y().optional(),allowedDomains:d(c()).optional(),blockedDomains:d(c()).optional(),citations:u({enabled:_()}).optional(),maxContentTokens:y().optional()}))),ft=j(()=>Y(u({type:p(`web_fetch_result`),url:c(),content:u({type:p(`document`),title:c().nullable(),citations:u({enabled:_()}).optional(),source:m([u({type:p(`base64`),mediaType:p(`application/pdf`),data:c()}),u({type:p(`text`),mediaType:p(`text/plain`),data:c()})])}),retrievedAt:c().nullable()}))),pt=j(()=>Y(u({url:c()}))),mt=k({id:`anthropic.web_fetch_20250910`,inputSchema:pt,outputSchema:ft,supportsDeferredResults:!0}),ht=(e={})=>mt(e);async function gt({tools:e,toolChoice:t,disableParallelToolUse:n,cacheControlValidator:r,supportsStructuredOutput:a,supportsStrictTools:o,defaultEagerInputStreaming:s=!1}){e=e?.length?e:void 0;let c=[],l=new Set,u=r||new Ae;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 P({value:t.args,schema:Ie});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 P({value:t.args,schema:dt});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 P({value:t.args,schema:ot});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_fetch_20260318`:{let e=await P({value:t.args,schema:tt});d.push({type:`web_fetch_20260318`,name:`web_fetch`,max_uses:e.maxUses,allowed_domains:e.allowedDomains,blocked_domains:e.blockedDomains,citations:e.citations,max_content_tokens:e.maxContentTokens,use_cache:e.useCache,response_inclusion:e.responseInclusion,cache_control:void 0});break}case`anthropic.web_search_20250305`:{let e=await P({value:t.args,schema:Xe});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 P({value:t.args,schema:Ge});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.web_search_20260318`:{let e=await P({value:t.args,schema:Be});d.push({type:`web_search_20260318`,name:`web_search`,max_uses:e.maxUses,allowed_domains:e.allowedDomains,blocked_domains:e.blockedDomains,user_location:e.userLocation,response_inclusion:e.responseInclusion,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;case`anthropic.advisor_20260301`:{l.add(`advisor-tool-2026-03-01`);let e=await P({value:t.args,schema:je});d.push({type:`advisor_20260301`,name:`advisor`,model:e.model,...e.maxUses!==void 0&&{max_uses:e.maxUses},...e.maxTokens!==void 0&&{max_tokens:e.maxTokens},...e.caching!==void 0&&{caching:e.caching}});break}default:c.push({type:`unsupported`,feature:`provider-defined tool ${t.id}`})}break;default:c.push({type:`unsupported`,feature:`tool ${t}`})}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 i({functionality:`tool choice type: ${f}`})}}function _t({usage:e,rawUsage:t}){let n=e.cache_creation_input_tokens??0,r=e.cache_read_input_tokens??0,i=e.output_tokens_details?.thinking_tokens??void 0,a,o,s=e.iterations?.some(e=>e.type===`fallback_message`);if(e.iterations&&e.iterations.length>0&&!s){let t=e.iterations.filter(e=>e.type===`compaction`||e.type===`message`);if(t.length>0){let e=t.reduce((e,t)=>({input:e.input+t.input_tokens,output:e.output+t.output_tokens}),{input:0,output:0});a=e.input,o=e.output}else a=e.input_tokens,o=e.output_tokens}else a=e.input_tokens,o=e.output_tokens;return{inputTokens:{total:a+n+r,noCache:a,cacheRead:r,cacheWrite:n},outputTokens:{total:o,text:i==null?void 0:o-i,reasoning:i},raw:t??e}}var vt=j(()=>Y(u({type:p(`code_execution_result`),stdout:c(),stderr:c(),return_code:y(),content:d(u({type:p(`code_execution_output`),file_id:c()})).optional().default([])}))),yt=j(()=>Y(u({code:c()}))),bt=k({id:`anthropic.code_execution_20250522`,inputSchema:yt,outputSchema:vt}),xt=(e={})=>bt(e),St=j(()=>Y(f(`type`,[u({type:p(`code_execution_result`),stdout:c(),stderr:c(),return_code:y(),content:d(u({type:p(`code_execution_output`),file_id:c()})).optional().default([])}),u({type:p(`bash_code_execution_result`),content:d(u({type:p(`bash_code_execution_output`),file_id:c()})),stdout:c(),stderr:c(),return_code:y()}),u({type:p(`bash_code_execution_tool_result_error`),error_code:c()}),u({type:p(`text_editor_code_execution_tool_result_error`),error_code:c()}),u({type:p(`text_editor_code_execution_view_result`),content:c(),file_type:c(),num_lines:y().nullable(),start_line:y().nullable(),total_lines:y().nullable()}),u({type:p(`text_editor_code_execution_create_result`),is_file_update:_()}),u({type:p(`text_editor_code_execution_str_replace_result`),lines:d(c()).nullable(),new_lines:y().nullable(),new_start:y().nullable(),old_lines:y().nullable(),old_start:y().nullable()})]))),Ct=j(()=>Y(f(`type`,[u({type:p(`programmatic-tool-call`),code:c()}),u({type:p(`bash_code_execution`),command:c()}),f(`command`,[u({type:p(`text_editor_code_execution`),command:p(`view`),path:c()}),u({type:p(`text_editor_code_execution`),command:p(`create`),path:c(),file_text:c().nullish()}),u({type:p(`text_editor_code_execution`),command:p(`str_replace`),path:c(),old_str:c(),new_str:c()})])]))),wt=k({id:`anthropic.code_execution_20250825`,inputSchema:Ct,outputSchema:St,supportsDeferredResults:!0}),Tt=(e={})=>K(wt(e),{type:`provider`,prepareProviderOptions:e=>{let t=e?.anthropic;return{...e,anthropic:{...t,allowedCallers:[...new Set([...t?.allowedCallers??[],`code_execution_20250825`])]}}}}),Et=j(()=>Y(f(`type`,[u({type:p(`code_execution_result`),stdout:c(),stderr:c(),return_code:y(),content:d(u({type:p(`code_execution_output`),file_id:c()})).optional().default([])}),u({type:p(`encrypted_code_execution_result`),encrypted_stdout:c(),stderr:c(),return_code:y(),content:d(u({type:p(`code_execution_output`),file_id:c()})).optional().default([])}),u({type:p(`bash_code_execution_result`),content:d(u({type:p(`bash_code_execution_output`),file_id:c()})),stdout:c(),stderr:c(),return_code:y()}),u({type:p(`bash_code_execution_tool_result_error`),error_code:c()}),u({type:p(`text_editor_code_execution_tool_result_error`),error_code:c()}),u({type:p(`text_editor_code_execution_view_result`),content:c(),file_type:c(),num_lines:y().nullable(),start_line:y().nullable(),total_lines:y().nullable()}),u({type:p(`text_editor_code_execution_create_result`),is_file_update:_()}),u({type:p(`text_editor_code_execution_str_replace_result`),lines:d(c()).nullable(),new_lines:y().nullable(),new_start:y().nullable(),old_lines:y().nullable(),old_start:y().nullable()})]))),Dt=j(()=>Y(f(`type`,[u({type:p(`programmatic-tool-call`),code:c()}),u({type:p(`bash_code_execution`),command:c()}),f(`command`,[u({type:p(`text_editor_code_execution`),command:p(`view`),path:c()}),u({type:p(`text_editor_code_execution`),command:p(`create`),path:c(),file_text:c().nullish()}),u({type:p(`text_editor_code_execution`),command:p(`str_replace`),path:c(),old_str:c(),new_str:c()})])]))),Ot=k({id:`anthropic.code_execution_20260120`,inputSchema:Dt,outputSchema:Et,supportsDeferredResults:!0}),kt=(e={})=>K(Ot(e),{type:`provider`,prepareProviderOptions:e=>{let t=e?.anthropic;return{...e,anthropic:{...t,allowedCallers:[...new Set([...t?.allowedCallers??[],`code_execution_20260120`])]}}}}),At=j(()=>Y(d(u({type:p(`tool_reference`),toolName:c()})))),jt=j(()=>Y(u({pattern:c(),limit:y().optional()}))),Mt=k({id:`anthropic.tool_search_regex_20251119`,inputSchema:jt,outputSchema:At,supportsDeferredResults:!0}),Nt=(e={})=>Mt(e);function Pt(e){return typeof e==`string`?new TextDecoder().decode(ce(e)):new TextDecoder().decode(e)}function Ft(e){try{if(typeof e==`string`)return J(e);if(typeof e==`object`&&e)return e}catch{let t=e?.errorCode;return{errorCode:typeof t==`string`?t:`unavailable`}}return{}}async function It({prompt:e,sendReasoning:t,warnings:n,cacheControlValidator:r,toolNameMapping:a}){let o=new Set,s=Lt(e),c=r||new Ae,l,u=[];async function d(e){return(await b({provider:`anthropic`,providerOptions:e,schema:Te}))?.citations?.enabled??!1}async function f(e){return(await b({provider:`anthropic`,providerOptions:e,schema:Te}))?.containerUpload??!1}async function p(e){let t=await b({provider:`anthropic`,providerOptions:e,schema:Te});return{title:t?.title,context:t?.context}}for(let e=0;e<s.length;e++){let r=s[e],m=e===s.length-1,h=r.type;switch(h){case`system`:{let t=[];for(let{content:e,providerOptions:n}of r.messages){let r=await b({provider:`anthropic`,providerOptions:n,schema:Ee}),i=r?.toolChanges??[],o=[];(e!==``||i.length===0&&r?.clearAt==null&&r?.effort==null)&&o.push({type:`text`,text:e,cache_control:c.getCacheControl(n,{type:`system message`,canCache:!0})});for(let e of i)o.push({type:e.type,tool:{type:`tool_reference`,name:a.toProviderToolName(e.toolName)}});t.push({content:o,clearAt:r?.clearAt,effort:r?.effort,toolChangeCount:i.length})}let i=t.reduce((e,t)=>e+t.toolChangeCount,0),s=t.some(e=>e.clearAt!=null||e.effort!=null);if(e===0||l==null&&i===0&&!s){i>0&&n.push({type:`other`,message:`tool changes on the initial system message are not supported by Anthropic. Configure the initial tool set via the tools option instead. The tool changes have been ignored.`});for(let e of t)(e.clearAt!=null||e.effort!=null)&&n.push({type:`other`,message:`clearAt and effort on the initial system message are not supported by Anthropic. These options have been ignored.`});l=t.flatMap(e=>e.content.filter(e=>e.type===`text`))}else{o.add(`mid-conversation-system-2026-04-07`);for(let e of t)u.push({role:`system`,content:e.content,...e.clearAt!=null&&{clear_at:e.clearAt},...e.effort!=null&&{output_config:{effort:e.effort}}}),e.toolChangeCount>0&&o.add(`mid-conversation-tool-changes-2026-07-01`),e.clearAt!=null&&o.add(`mid-conversation-system-clear-at-2026-08-21`),e.effort!=null&&o.add(`mid-conversation-effort-2026-08-01`)}break}case`user`:{let e=[];for(let t of r.messages){let{role:r,content:a}=t;switch(r){case`user`:for(let n=0;n<a.length;n++){let r=a[n],s=n===a.length-1,l=c.getCacheControl(r.providerOptions,{type:`user message part`,canCache:!0})??(s?c.getCacheControl(t.providerOptions,{type:`user message`,canCache:!0}):void 0);switch(r.type){case`text`:e.push({type:`text`,text:r.text,cache_control:l});break;case`file`:switch(r.data.type){case`reference`:{let t=oe({reference:r.data.reference,provider:`anthropic`});o.add(`files-api-2025-04-14`),await f(r.providerOptions)?e.push({type:`container_upload`,file_id:t}):S(r.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(r.providerOptions),n=await p(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:l});break}case`url`:case`data`:{let t=S(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:F({part:r}),data:W(r.data.data)},cache_control:l});else if(t===`application`&&(r.data.type===`url`?r.mediaType===`application/pdf`:F({part:r})===`application/pdf`)){o.add(`pdfs-2024-09-25`);let t=await d(r.providerOptions),n=await p(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:W(r.data.data)},title:n.title??r.filename,...n.context&&{context:n.context},...t&&{citations:{enabled:!0}},cache_control:l})}else if(r.mediaType===`text/plain`){let t=await d(r.providerOptions),n=await p(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:Pt(r.data.data)},title:n.title??r.filename,...n.context&&{context:n.context},...t&&{citations:{enabled:!0}},cache_control:l})}else throw new i({functionality:`media type: ${r.mediaType}`});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=i.output,l=`providerOptions`in s?s.providerOptions:s.type===`content`?s.value.find(e=>e.providerOptions!=null)?.providerOptions:void 0,u=r===a.length-1,d=c.getCacheControl(i.providerOptions,{type:`tool result part`,canCache:!0})??c.getCacheControl(l,{type:`tool result output`,canCache:!0})??(u?c.getCacheControl(t.providerOptions,{type:`tool result message`,canCache:!0}):void 0),f;switch(s.type){case`content`:f=s.value.map(e=>{switch(e.type){case`text`:return{type:`text`,text:e.text};case`file`:{let t=S(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:F({part:e}),data:W(e.data.data)}};if(F({part:e})===`application/pdf`)return o.add(`pdfs-2024-09-25`),{type:`document`,source:{type:`base64`,media_type:`application/pdf`,data:W(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(de);break;case`text`:case`error-text`:f=s.value;break;case`execution-denied`:f=s.reason??`Tool call execution denied.`;break;default:f=JSON.stringify(s.value)}e.push({type:`tool_result`,tool_use_id:i.toolCallId,content:f,is_error:s.type===`error-text`||s.type===`error-json`||void 0,cache_control:d})}break;default:throw Error(`Unsupported role: ${r}`)}}u.push({role:`user`,content:e});break}case`assistant`:{let e=[],i=new Set;for(let o=0;o<r.messages.length;o++){let s=r.messages[o],l=o===r.messages.length-1,{content:u}=s;for(let r=0;r<u.length;r++){let o=u[r],d=r===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`:{let t=o.providerOptions?.anthropic;t?.type===`compaction`?e.push({type:`compaction`,content:o.text,cache_control:f}):e.push({type:`text`,text:m&&l&&d?o.text.trim():o.text,...t?.citations!=null&&{citations:t.citations},cache_control:f});break}case`reasoning`:if(t){let t=await b({provider:`anthropic`,providerOptions:o.providerOptions,schema:we});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`:{let t=zt(o.providerOptions);if(o.providerExecuted){let r=a.toProviderToolName(o.toolName);if(o.providerOptions?.anthropic?.type===`mcp-tool-use`){i.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(r===`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`)){let{type:n,...r}=o.input;e.push({type:`server_tool_use`,id:o.toolCallId,name:n,input:r,...t&&{caller:t},cache_control:f})}else if(r===`code_execution`&&o.input!=null&&typeof o.input==`object`&&`type`in o.input&&o.input.type===`programmatic-tool-call`){let{type:n,...r}=o.input;e.push({type:`server_tool_use`,id:o.toolCallId,name:`code_execution`,input:r,...t&&{caller:t},cache_control:f})}else r===`code_execution`||r===`web_fetch`||r===`web_search`||r===`tool_search_tool_regex`||r===`tool_search_tool_bm25`?e.push({type:`server_tool_use`,id:o.toolCallId,name:r,input:o.input,...t&&{caller:t},cache_control:f}):r===`advisor`?e.push({type:`server_tool_use`,id:o.toolCallId,name:`advisor`,input:{},...t&&{caller:t},cache_control:f}):n.push({type:`other`,message:`provider executed tool call for tool ${o.toolName} is not supported`});break}e.push({type:`tool_use`,id:o.toolCallId,name:o.toolName,input:Bt(o.input),...t&&{caller:t},cache_control:f});break}case`tool-result`:{let t=a.toProviderToolName(o.toolName),r=zt(o.providerOptions);if(i.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=J(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 P({value:t.value,schema:vt});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 P({value:t.value,schema:Et});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 P({value:t.value,schema:St});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.type===`bash_code_execution_result`?{type:n.type,stdout:n.stdout,stderr:n.stderr,return_code:n.return_code,content:n.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`){e.push({type:`web_fetch_tool_result`,tool_use_id:o.toolCallId,content:{type:`web_fetch_tool_result_error`,error_code:Ft(t.value).errorCode??`unavailable`},...r&&{caller:r},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 i=await P({value:t.value,schema:ft});e.push({type:`web_fetch_tool_result`,tool_use_id:o.toolCallId,content:{type:`web_fetch_result`,url:i.url,retrieved_at:i.retrievedAt,content:{type:`document`,title:i.content.title,citations:i.content.citations,source:{type:i.content.source.type,media_type:i.content.source.mediaType,data:i.content.source.data}}},...r&&{caller:r},cache_control:f});break}if(t===`web_search`){let t=o.output;if(t.type===`error-json`){e.push({type:`web_search_tool_result`,tool_use_id:o.toolCallId,content:{type:`web_search_tool_result_error`,error_code:Ft(t.value).errorCode??`unavailable`},...r&&{caller:r},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 i=await P({value:t.value,schema:Ze});e.push({type:`web_search_tool_result`,tool_use_id:o.toolCallId,content:i.map(e=>({url:e.url,title:e.title,page_age:e.pageAge,encrypted_content:e.encryptedContent,type:e.type})),...r&&{caller:r},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 P({value:t.value,schema:At})).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}if(t===`advisor`){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}let r=await P({value:t.value,schema:Me});r.type===`advisor_result`?e.push({type:`advisor_tool_result`,tool_use_id:o.toolCallId,content:{type:`advisor_result`,text:r.text,...r.stopReason!==void 0&&{stop_reason:r.stopReason}},cache_control:f}):r.type===`advisor_redacted_result`?e.push({type:`advisor_tool_result`,tool_use_id:o.toolCallId,content:{type:`advisor_redacted_result`,encrypted_content:r.encryptedContent,...r.stopReason!==void 0&&{stop_reason:r.stopReason}},cache_control:f}):e.push({type:`advisor_tool_result`,tool_use_id:o.toolCallId,content:{type:`advisor_tool_result_error`,error_code:r.errorCode},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:Rt(e)});break}default:throw Error(`content type: ${h}`)}}return{prompt:{system:l,messages:u},betas:o}}function Lt(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 Rt(e){let t=[],n=[];function r(){t.push(...n.filter(e=>e.type!==`tool_use`),...n.filter(e=>e.type===`tool_use`)),n=[]}for(let i of e)i.type===`thinking`||i.type===`redacted_thinking`?(r(),t.push(i)):n.push(i);return r(),t}function zt(e){let t=e?.anthropic?.caller;return(t?.type===`code_execution_20250825`||t?.type===`code_execution_20260120`)&&t.toolId?{type:t.type,tool_id:t.toolId}:t?.type===`direct`?{type:`direct`}:void 0}function Bt(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:{rawInvalidInput:e}}function Vt({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 Ht=new Set([`date-time`,`time`,`date`,`duration`,`email`,`hostname`,`uri`,`ipv4`,`ipv6`,`uuid`]),Ut=[`minimum`,`maximum`,`exclusiveMinimum`,`exclusiveMaximum`,`multipleOf`,`minLength`,`maxLength`,`pattern`,`minItems`,`maxItems`,`uniqueItems`,`minProperties`,`maxProperties`,`not`];function Wt(e){return Gt(e)}function Q(e){return typeof e==`boolean`||!A(e)?e:Gt(e)}function Gt(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`&&Ht.has(e.format)&&(t.format=e.format);let r=Kt(e);return r!=null&&(t.description=t.description==null?r:`${t.description}
${r}`),t}function Kt(e){let t=Ut.flatMap(t=>{let n=e[t];return n==null||n===!1?[]:`${qt(t)}: ${Jt(n)}`});return typeof e.format==`string`&&!Ht.has(e.format)&&t.push(`format: ${e.format}`),t.length===0?void 0:`${t.join(`; `)}.`}function qt(e){return e.replace(/[A-Z]/g,e=>` ${e.toLowerCase()}`)}function Jt(e){return typeof e==`string`?e:JSON.stringify(e)}function Yt(e){let t=Xt(e.type);return x({message:e.message,type:e.type,code:e.code??void 0,statusCode:e.statusCode??t.statusCode,isRetryable:e.isRetryable??t.isRetryable,data:`data`in e?e.data:e})}function Xt(e){switch(e){case`api_error`:return{statusCode:500,isRetryable:!0};case`overloaded_error`:return{statusCode:529,isRetryable:!0};case`rate_limit_error`:return{statusCode:429,isRetryable:!0};case`request_too_large`:return{statusCode:413,isRetryable:!1};case`authentication_error`:return{statusCode:401,isRetryable:!1};case`permission_error`:return{statusCode:403,isRetryable:!1};case`not_found_error`:return{statusCode:404,isRetryable:!1};case`billing_error`:case`invalid_request_error`:return{statusCode:400,isRetryable:!1};default:return{}}}function Zt(e,t,n){if(e.type===`web_search_result_location`)return{type:`source`,sourceType:`url`,id:n(),url:e.url,title:e.title??void 0,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}}}}function Qt(e){return e==null?void 0:{type:e.type,toolId:`tool_id`in e?e.tool_id:void 0}}function $(e){let t=Qt(e);return t==null?{}:{providerMetadata:{anthropic:{caller:t}}}}function $t(e){let t=e.indexOf(`.`);return t===-1?e:e.substring(0,t)}var en=class t{constructor(e,t){this.specificationVersion=`v4`,this.modelId=e,this.config=t,this.generateId=t.generateId??D}static[pe](e){return ne({modelId:e.modelId,config:e.config})}static[fe](e){return new t(e.modelId,e.config)}supportsUrl(e){return e.protocol===`https:`}get provider(){return this.config.provider}get supportedUrls(){var e;return(e=this.config).supportedUrls?.call(e)??{}}static async prepareRequest({modelId:e,config:t,options:{userSuppliedBetas:n,prompt:r,maxOutputTokens:i,temperature:a,topP:o,topK:s,frequencyPenalty:c,presencePenalty:l,stopSequences:u,responseFormat:d,seed:f,tools:p,toolChoice:m,reasoning:h,providerOptions:g,stream:_}}){let v=[];c!=null&&v.push({type:`unsupported`,feature:`frequencyPenalty`}),l!=null&&v.push({type:`unsupported`,feature:`presencePenalty`}),f!=null&&v.push({type:`unsupported`,feature:`seed`}),a!=null&&a>1?(v.push({type:`unsupported`,feature:`temperature`,details:`${a} exceeds anthropic maximum of 1.0. clamped to 1.0`}),a=1):a!=null&&a<0&&(v.push({type:`unsupported`,feature:`temperature`,details:`${a} is below anthropic minimum of 0. clamped to 0`}),a=0),d?.type===`json`&&(d.schema??v.push({type:`unsupported`,feature:`responseFormat`,details:`JSON response format requires a schema. The response format is ignored.`}));let y=$t(t.provider),ee=await b({provider:`anthropic`,providerOptions:g,schema:De}),x=y===`anthropic`?null:await b({provider:y,providerOptions:g,schema:De}),S=x!=null,C=Object.assign({},ee??{},x??{}),{maxOutputTokens:w,supportsStructuredOutput:T,supportsAdaptiveThinking:D,rejectsSamplingParameters:O,supportsXhighEffort:k,rejectsThinkingDisabledAboveHighEffort:A,isKnownModel:j}=tn(e);!j&&i==null&&v.push({type:`compatibility`,feature:`maxOutputTokens`,details:`The model "${e}" is unknown. The max output tokens have been limited to ${w}. Set maxOutputTokens explicitly to override this limit.`}),O&&(a!=null&&(v.push({type:`unsupported`,feature:`temperature`,details:`temperature is not supported by ${e} and will be ignored`}),a=void 0),s!=null&&(v.push({type:`unsupported`,feature:`topK`,details:`topK is not supported by ${e} and will be ignored`}),s=void 0),o!=null&&(v.push({type:`unsupported`,feature:`topP`,details:`topP is not supported by ${e} and will be ignored`}),o=void 0));let te=j||e.includes(`claude-`),M=(t.supportsNativeStructuredOutput??!0)&&T,N=(t.supportsStrictTools??!0)&&T,P=C?.structuredOutputMode??`auto`,F=P===`outputFormat`||P===`auto`&&M,I=d?.type===`json`&&d.schema!=null&&!F?{type:`function`,name:`json`,description:`Respond with a JSON object.`,inputSchema:d.schema}:void 0;I!=null&&C?.disableParallelToolUse===!1&&v.push({type:`unsupported`,feature:`providerOptions.anthropic.disableParallelToolUse`,details:"`disableParallelToolUse: false` is ignored when using the JSON response tool. Parallel tool use is disabled to ensure a single coherent JSON tool call."});let L=C?.contextManagement,R=new Ae,ne=le({tools:p,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_search_20260318":`web_search`,"anthropic.web_fetch_20250910":`web_fetch`,"anthropic.web_fetch_20260209":`web_fetch`,"anthropic.web_fetch_20260318":`web_fetch`,"anthropic.tool_search_regex_20251119":`tool_search_tool_regex`,"anthropic.tool_search_bm25_20251119":`tool_search_tool_bm25`,"anthropic.advisor_20260301":`advisor`}}),{prompt:z,betas:B}=await It({prompt:r,sendReasoning:C?.sendReasoning??!0,warnings:v,cacheControlValidator:R,toolNameMapping:ne});if(E(h)&&C?.effort==null){let e=rn({reasoning:h,supportsAdaptiveThinking:D,supportsXhighEffort:k,maxOutputTokensForModel:w,warnings:v});e!=null&&(C.thinking??=e.thinking,e.effort!=null&&C.thinking?.type!==`disabled`&&(C.effort=e.effort))}A&&C?.thinking?.type===`disabled`&&(C.effort===`xhigh`||C.effort===`max`)&&(v.push({type:`unsupported`,feature:`providerOptions.anthropic.effort`,details:`effort '${C.effort}' is not supported by ${e} when thinking is disabled. The effort has been lowered to 'high'.`}),C.effort=`high`);let V=C?.thinking?.type,re=V===`enabled`||V===`adaptive`,H=C?.thinking!=null&&`blockBinding`in C.thinking?C.thinking.blockBinding:void 0,U=re||V===`disabled`||H!=null,W=V===`enabled`?C?.thinking?.budgetTokens:void 0,G=V===`adaptive`?C?.thinking?.display:void 0,ie=i??w,K={model:e,max_tokens:ie,temperature:a,top_k:s,top_p:o,stop_sequences:u,...U&&{thinking:{...V!=null&&{type:V},...W!=null&&{budget_tokens:W},...G!=null&&{display:G},...H!=null&&{block_binding:{prefix_mismatch_behavior:H.prefixMismatchBehavior}}}},...(C?.effort||C?.taskBudget||F&&d?.type===`json`&&d.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}}},...F&&d?.type===`json`&&d.schema!=null&&{format:{type:`json_schema`,schema:Wt(d.schema)}}}},...C?.speed&&{speed:C.speed},...C?.serviceTier&&{service_tier:C.serviceTier},...C?.inferenceGeo&&{inference_geo:C.inferenceGeo},...C?.fallbacks!=null&&(C.fallbacks==="default"||C.fallbacks.length>0)&&{fallbacks:C.fallbacks},...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`?oe({reference:e.providerReference,provider:`anthropic`}):e.skillId,version:e.version}))}:C.container.id},system:z.system,messages:z.messages,...L&&{context_management:{edits:L.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:v.push({type:`other`,message:`Unknown context management strategy: ${t}`});return}}).filter(e=>e!==void 0)}}};re?(V===`enabled`&&W==null&&(v.push({type:`compatibility`,feature:`extended thinking`,details:`thinking budget is required when thinking is enabled. using default budget of 1024 tokens.`}),K.thinking={type:`enabled`,budget_tokens:1024},W=1024),K.temperature!=null&&(K.temperature=void 0,v.push({type:`unsupported`,feature:`temperature`,details:`temperature is not supported when thinking is enabled`})),s!=null&&(K.top_k=void 0,v.push({type:`unsupported`,feature:`topK`,details:`topK is not supported when thinking is enabled`})),o!=null&&(K.top_p=void 0,v.push({type:`unsupported`,feature:`topP`,details:`topP is not supported when thinking is enabled`})),K.max_tokens=ie+(W??0)):te&&o!=null&&a!=null&&(v.push({type:`unsupported`,feature:`topP`,details:`topP is not supported when temperature is set. topP is ignored.`}),K.top_p=void 0),j&&K.max_tokens>w&&(i!=null&&v.push({type:`unsupported`,feature:`maxOutputTokens`,details:`${K.max_tokens} (maxOutputTokens + thinkingBudget) is greater than ${e} ${w} max output tokens. The max output tokens have been limited to ${w}.`}),K.max_tokens=w),C?.mcpServers&&C.mcpServers.length>0&&B.add(`mcp-client-2025-04-04`),L&&(B.add(`context-management-2025-06-27`),L.edits.some(e=>e.type===`compact_20260112`)&&B.add(`compact-2026-01-12`)),C?.container&&C.container.skills&&C.container.skills.length>0&&(B.add(`code-execution-2025-08-25`),B.add(`skills-2025-10-02`),B.add(`files-api-2025-04-14`),p?.some(e=>e.type===`provider`&&(e.id===`anthropic.code_execution_20250825`||e.id===`anthropic.code_execution_20260120`))||v.push({type:`other`,message:`code execution tool is required when using skills`})),C?.taskBudget&&B.add(`task-budgets-2026-03-13`),C?.speed===`fast`&&B.add(`fast-mode-2026-02-01`),G===`updates`&&B.add(`thinking-display-updates-2026-08-18`),H!=null&&B.add(`thinking-binding-controls-2026-08-01`),C?.fallbacks==="default"?B.add(`server-side-fallback-2026-07-01`):C?.fallbacks&&C.fallbacks.length>0&&B.add(`server-side-fallback-2026-06-01`);let ae=_&&(C?.toolStreaming??!0),{tools:se,toolChoice:ce,toolWarnings:q,betas:J}=await gt(I==null?{tools:p??[],toolChoice:m,disableParallelToolUse:C?.disableParallelToolUse,cacheControlValidator:R,supportsStructuredOutput:M,supportsStrictTools:N,defaultEagerInputStreaming:ae}:{tools:[...p??[],I],toolChoice:{type:`required`},disableParallelToolUse:!0,cacheControlValidator:R,supportsStructuredOutput:!1,supportsStrictTools:N,defaultEagerInputStreaming:ae}),Y=R.getWarnings();return{args:{...K,tools:se,tool_choice:ce,stream:_===!0||void 0},warnings:[...v,...q,...Y],betas:new Set([...B,...J,...n,...C?.anthropicBeta??[]]),usesJsonResponseTool:I!=null,toolNameMapping:ne,providerOptionsName:y,usedCustomProviderKey:S}}getArgs(e){return t.prepareRequest({modelId:this.modelId,config:this.config,options:e})}async getHeaders({betas:e,headers:t}){return H(this.config.headers?await U(this.config.headers):void 0,t,e.size>0?{"anthropic-beta":Array.from(e).join(`,`)}:{})}async getBetasFromHeaders(e){let t=(this.config.headers?await U(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=nn(t.tools),{responseHeaders:u,value:d,rawValue:f}=await q({url:this.buildRequestUrl(!1),headers:await this.getHeaders({betas:r,headers:e.headers}),body:this.transformRequestBody(t,r),failedResponseHandler:X,successfulResponseHandler:N(Se),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){let t=e.citations?.filter(e=>e.type===`web_search_result_location`);if(p.push({type:`text`,text:e.text,...t!=null&&t.length>0&&{providerMetadata:{anthropic:{citations:t}}}}),e.citations)for(let t of e.citations){let e=Zt(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`container_upload`:p.push({type:`custom`,kind:`anthropic.container_upload`,providerMetadata:{anthropic:{fileId:e.file_id}}});break;case`compaction`:p.push({type:`text`,text:e.content,providerMetadata:{anthropic:{type:`compaction`}}});break;case`tool_use`:i&&e.name===`json`?(g=!0,p.push({type:`text`,text:JSON.stringify(e.input)})):p.push({type:`tool-call`,toolCallId:e.id,toolName:e.name,input:JSON.stringify(e.input),...$(e.caller)});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,...l?{dynamic:!0}:{},...$(e.caller)});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}:{},...$(e.caller)})}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,...$(e.caller)})):e.name===`advisor`&&p.push({type:`tool-call`,toolCallId:e.id,toolName:a.toCustomToolName(`advisor`),input:JSON.stringify(e.input),providerExecuted:!0,...$(e.caller)});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.caller)})):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},...$(e.caller)});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,...e.title==null?{}:{title:e.title},pageAge:e.page_age??null,encryptedContent:e.encrypted_content,type:e.type})),...$(e.caller)});for(let t of e.content)p.push({type:`source`,sourceType:`url`,id:this.generateId(),url:t.url,...t.title==null?{}:{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},...$(e.caller)});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}case`advisor_tool_result`:{let t=a.toCustomToolName(`advisor`);e.content.type===`advisor_result`?p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:t,result:{type:`advisor_result`,text:e.content.text,...e.content.stop_reason!=null&&{stopReason:e.content.stop_reason}}}):e.content.type===`advisor_redacted_result`?p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:t,result:{type:`advisor_redacted_result`,encryptedContent:e.content.encrypted_content,...e.content.stop_reason!=null&&{stopReason:e.content.stop_reason}}}):p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:t,isError:!0,result:{type:`advisor_tool_result_error`,errorCode:e.content.error_code}});break}}return{content:p,finishReason:{unified:Vt({finishReason:d.stop_reason,isJsonResponseFromTool:g}),raw:d.stop_reason??void 0},usage:_t({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=on(d.stop_details),t={usage:d.usage,stopSequence:d.stop_sequence??null,...e==null?{}:{stopDetails:e},...d.input_transformations==null?{}:{inputTransformations:d.input_transformations},iterations:d.usage.iterations?d.usage.iterations.map(e=>({type:e.type,...e.model==null?{}:{model:e.model},inputTokens:e.input_tokens,outputTokens:e.output_tokens,...e.cache_creation_input_tokens?{cacheCreationInputTokens:e.cache_creation_input_tokens}:{},...e.cache_read_input_tokens?{cacheReadInputTokens:e.cache_read_input_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:an(d.context_management)??null},n={anthropic:t};return s&&o!==`anthropic`&&(n[o]=t),n})()}}async doStream(t){"use step";let{args:r,warnings:i,betas:a,usesJsonResponseTool:o,toolNameMapping:s,providerOptionsName:c,usedCustomProviderKey:l}=await this.getArgs({...t,stream:!0,userSuppliedBetas:await this.getBetasFromHeaders(t.headers)}),u=[...this.extractCitationDocuments(t.prompt)],d=nn(r.tools),f=this.buildRequestUrl(!0),{responseHeaders:p,value:m}=await q({url:f,headers:await this.getHeaders({betas:a,headers:t.headers}),body:this.transformRequestBody(r,a),failedResponseHandler:X,successfulResponseHandler:ie(Ce),abortSignal:t.abortSignal,fetch:this.config.fetch}),h={unified:`other`,raw:void 0},g={input_tokens:0,output_tokens:0,cache_creation_input_tokens:0,cache_read_input_tokens:0,iterations:null},_={},v={},y={},b=null,x,S=null,C,w,T=null,E=!1,D=!1,O,k=!1,A,j=this.generateId,[te,M]=m.pipeThrough(new TransformStream({start(e){e.enqueue({type:`stream-start`,warnings:i})},transform(e,r){if(k)return;if(t.includeRawChunks&&r.enqueue({type:`raw`,rawValue:e.rawValue}),!e.success){r.enqueue({type:`error`,error:e.error});return}let i=e.value;switch(i.type){case`ping`:return;case`content_block_start`:{let e=i.content_block,t=e.type;if(t===`fallback`)return;switch(A=t,t){case`text`:if(o)return;_[i.index]={type:`text`,citations:[]},r.enqueue({type:`text-start`,id:String(i.index)});return;case`thinking`:_[i.index]={type:`reasoning`},r.enqueue({type:`reasoning-start`,id:String(i.index)});return;case`redacted_thinking`:_[i.index]={type:`reasoning`},r.enqueue({type:`reasoning-start`,id:String(i.index),providerMetadata:{anthropic:{redactedData:e.data}}});return;case`compaction`:_[i.index]={type:`text`,citations:[]},r.enqueue({type:`text-start`,id:String(i.index),providerMetadata:{anthropic:{type:`compaction`}}});return;case`tool_use`:if(o&&e.name===`json`)E=!0,_[i.index]={type:`text`,citations:[]},r.enqueue({type:`text-start`,id:String(i.index)});else{let t=Qt(e.caller),n=e.input&&Object.keys(e.input).length>0?JSON.stringify(e.input):``;_[i.index]={type:`tool-call`,toolCallId:e.id,toolName:e.name,input:n,firstDelta:n.length===0,...t&&{caller:t}},r.enqueue({type:`tool-input-start`,id:e.id,toolName:e.name})}return;case`server_tool_use`:{let t=Qt(e.caller);if([`web_fetch`,`web_search`,`code_execution`,`text_editor_code_execution`,`bash_code_execution`].includes(e.name)){let n=e.name===`text_editor_code_execution`||e.name===`bash_code_execution`?`code_execution`:e.name,a=e.name===`text_editor_code_execution`||e.name===`bash_code_execution`?e.name:e.name===`code_execution`?`programmatic-tool-call`:void 0,o=s.toCustomToolName(n),c=e.input!=null&&typeof e.input==`object`&&Object.keys(e.input).length>0?JSON.stringify(e.input):``;_[i.index]={type:`tool-call`,toolCallId:e.id,toolName:o,input:c,providerExecuted:!0,...d&&n===`code_execution`?{dynamic:!0}:{},firstDelta:c.length===0,providerToolName:n,providerToolInputType:a,...t&&{caller:t}},r.enqueue({type:`tool-input-start`,id:e.id,toolName:o,providerExecuted:!0,...d&&n===`code_execution`?{dynamic:!0}:{}})}else if(e.name===`tool_search_tool_regex`||e.name===`tool_search_tool_bm25`){y[e.id]=e.name;let n=s.toCustomToolName(e.name);_[i.index]={type:`tool-call`,toolCallId:e.id,toolName:n,input:``,providerExecuted:!0,firstDelta:!0,providerToolName:e.name,...t&&{caller:t}},r.enqueue({type:`tool-input-start`,id:e.id,toolName:n,providerExecuted:!0})}else if(e.name===`advisor`){let n=s.toCustomToolName(`advisor`);_[i.index]={type:`tool-call`,toolCallId:e.id,toolName:n,input:`{}`,providerExecuted:!0,firstDelta:!0,providerToolName:e.name,...t&&{caller:t}},r.enqueue({type:`tool-input-start`,id:e.id,toolName:n,providerExecuted:!0})}return}case`web_fetch_tool_result`:e.content.type===`web_fetch_result`?(u.push({title:e.content.content.title??e.content.url,mediaType:e.content.content.source.media_type}),r.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:s.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.caller)})):e.content.type===`web_fetch_tool_result_error`&&r.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:s.toCustomToolName(`web_fetch`),isError:!0,result:{type:`web_fetch_tool_result_error`,errorCode:e.content.error_code},...$(e.caller)});return;case`web_search_tool_result`:if(Array.isArray(e.content)){r.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:s.toCustomToolName(`web_search`),result:e.content.map(e=>({url:e.url,...e.title==null?{}:{title:e.title},pageAge:e.page_age??null,encryptedContent:e.encrypted_content,type:e.type})),...$(e.caller)});for(let t of e.content)r.enqueue({type:`source`,sourceType:`url`,id:j(),url:t.url,...t.title==null?{}:{title:t.title},providerMetadata:{anthropic:{pageAge:t.page_age??null}}})}else r.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:s.toCustomToolName(`web_search`),isError:!0,result:{type:`web_search_tool_result_error`,errorCode:e.content.error_code},...$(e.caller)});return;case`code_execution_tool_result`:e.content.type===`code_execution_result`?r.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:s.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`?r.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:s.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`&&r.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:s.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`:r.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:s.toCustomToolName(`code_execution`),result:e.content});return;case`tool_search_tool_result`:{let t=y[e.tool_use_id];if(t==null){let e=s.toCustomToolName(`tool_search_tool_bm25`);s.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`?r.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:s.toCustomToolName(t),result:e.content.tool_references.map(e=>({type:e.type,toolName:e.tool_name}))}):r.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:s.toCustomToolName(t),isError:!0,result:{type:`tool_search_tool_result_error`,errorCode:e.content.error_code}});return}case`advisor_tool_result`:{let t=s.toCustomToolName(`advisor`);e.content.type===`advisor_result`?r.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:t,result:{type:`advisor_result`,text:e.content.text,...e.content.stop_reason!=null&&{stopReason:e.content.stop_reason}}}):e.content.type===`advisor_redacted_result`?r.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:t,result:{type:`advisor_redacted_result`,encryptedContent:e.content.encrypted_content,...e.content.stop_reason!=null&&{stopReason:e.content.stop_reason}}}):r.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:t,isError:!0,result:{type:`advisor_tool_result_error`,errorCode:e.content.error_code}});return}case`mcp_tool_use`:v[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}}},r.enqueue(v[e.id]);return;case`mcp_tool_result`:r.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:v[e.tool_use_id].toolName,isError:e.is_error,result:e.content,dynamic:!0,providerMetadata:v[e.tool_use_id].providerMetadata});return;default:throw Error(`Unsupported content block type: ${t}`)}}case`content_block_stop`:if(_[i.index]!=null){let e=_[i.index];switch(e.type){case`text`:r.enqueue({type:`text-end`,id:String(i.index),...e.citations.length>0&&{providerMetadata:{anthropic:{citations:e.citations}}}});break;case`reasoning`:r.enqueue({type:`reasoning-end`,id:String(i.index)});break;case`tool-call`:if(!(o&&e.toolName===`json`)){r.enqueue({type:`tool-input-end`,id:e.toolCallId});let t=e.input===``?`{}`:e.input;if(e.providerToolName===`code_execution`)try{let e=J(t);typeof e==`object`&&e&&`code`in e&&!(`type`in e)&&(t=JSON.stringify({type:`programmatic-tool-call`,...e}))}catch{}r.enqueue({type:`tool-call`,toolCallId:e.toolCallId,toolName:e.toolName,input:t,providerExecuted:e.providerExecuted,...d&&e.providerToolName===`code_execution`?{dynamic:!0}:{},...e.caller&&{providerMetadata:{anthropic:{caller:e.caller}}}})}}delete _[i.index]}A=void 0;return;case`content_block_delta`:{let e=i.delta.type;switch(e){case`text_delta`:if(o)return;r.enqueue({type:`text-delta`,id:String(i.index),delta:i.delta.text});return;case`thinking_delta`:r.enqueue({type:`reasoning-delta`,id:String(i.index),delta:i.delta.thinking});return;case`signature_delta`:A===`thinking`&&r.enqueue({type:`reasoning-delta`,id:String(i.index),delta:``,providerMetadata:{anthropic:{signature:i.delta.signature}}});return;case`compaction_delta`:i.delta.content!=null&&r.enqueue({type:`text-delta`,id:String(i.index),delta:i.delta.content});return;case`input_json_delta`:{let e=_[i.index],t=i.delta.partial_json;if(t.length===0)return;if(E){if(e?.type!==`text`)return;r.enqueue({type:`text-delta`,id:String(i.index),delta:t})}else{if(e?.type!==`tool-call`)return;e.firstDelta&&e.providerToolInputType!=null&&(t=`{"type": "${e.providerToolInputType}",${t.substring(1)}`),r.enqueue({type:`tool-input-delta`,id:e.toolCallId,delta:t}),e.input+=t,e.firstDelta=!1}return}case`citations_delta`:{let e=i.delta.citation,t=_[i.index];t?.type===`text`&&e.type===`web_search_result_location`&&t.citations.push(e);let n=Zt(e,u,j);n&&r.enqueue(n);return}default:throw Error(`Unsupported delta type: ${e}`)}}case`message_start`:if(D){if(O===i.message.id)return;k=!0,r.enqueue({type:`error`,error:new n({data:i,message:`Received message_start for message ${JSON.stringify(i.message.id)} while message ${JSON.stringify(O)} is still open.`})});return}if(D=!0,O=i.message.id,g.input_tokens=i.message.usage.input_tokens,g.cache_read_input_tokens=i.message.usage.cache_read_input_tokens??0,g.cache_creation_input_tokens=i.message.usage.cache_creation_input_tokens??0,x={...i.message.usage},i.message.input_transformations!=null&&(w=i.message.input_transformations),i.message.container!=null&&(T={expiresAt:i.message.container.expires_at,id:i.message.container.id,skills:null}),i.message.stop_reason!=null&&(h={unified:Vt({finishReason:i.message.stop_reason,isJsonResponseFromTool:E}),raw:i.message.stop_reason}),r.enqueue({type:`response-metadata`,id:i.message.id??void 0,modelId:i.message.model??void 0}),i.message.content!=null)for(let e=0;e<i.message.content.length;e++){let t=i.message.content[e];if(t.type===`tool_use`){let e=Qt(t.caller);r.enqueue({type:`tool-input-start`,id:t.id,toolName:t.name});let n=JSON.stringify(t.input??{});r.enqueue({type:`tool-input-delta`,id:t.id,delta:n}),r.enqueue({type:`tool-input-end`,id:t.id}),r.enqueue({type:`tool-call`,toolCallId:t.id,toolName:t.name,input:n,...e&&{providerMetadata:{anthropic:{caller:e}}}})}}return;case`message_delta`:i.usage.input_tokens!=null&&g.input_tokens!==i.usage.input_tokens&&(g.input_tokens=i.usage.input_tokens),g.output_tokens=i.usage.output_tokens,i.usage.output_tokens_details!=null&&(g.output_tokens_details=i.usage.output_tokens_details),i.usage.cache_read_input_tokens!=null&&(g.cache_read_input_tokens=i.usage.cache_read_input_tokens),i.usage.cache_creation_input_tokens!=null&&(g.cache_creation_input_tokens=i.usage.cache_creation_input_tokens),i.usage.iterations!=null&&(g.iterations=i.usage.iterations),h={unified:Vt({finishReason:i.delta.stop_reason,isJsonResponseFromTool:E}),raw:i.delta.stop_reason??void 0},S=i.delta.stop_sequence??null,C=on(i.delta.stop_details),T=i.delta.container==null?null:{expiresAt:i.delta.container.expires_at,id:i.delta.container.id,skills:i.delta.container.skills?.map(e=>({type:e.type,skillId:e.skill_id,version:e.version}))??null},i.context_management&&(b=an(i.context_management)),i.input_transformations!=null&&(w=i.input_transformations),x={...x,...i.usage};return;case`message_stop`:{D=!1,O=void 0;let e={usage:x??null,stopSequence:S,...C==null?{}:{stopDetails:C},...w==null?{}:{inputTransformations:w},iterations:g.iterations?g.iterations.map(e=>({type:e.type,...e.model==null?{}:{model:e.model},inputTokens:e.input_tokens,outputTokens:e.output_tokens,...e.cache_creation_input_tokens?{cacheCreationInputTokens:e.cache_creation_input_tokens}:{},...e.cache_read_input_tokens?{cacheReadInputTokens:e.cache_read_input_tokens}:{}})):null,container:T,contextManagement:b},t={anthropic:e};l&&c!==`anthropic`&&(t[c]=e),r.enqueue({type:`finish`,finishReason:h,usage:_t({usage:g,rawUsage:x}),providerMetadata:t});return}case`error`:r.enqueue({type:`error`,error:Yt(i.error)});return;default:throw Error(`Unsupported chunk type: ${i}`)}}})).tee(),N=te.getReader();try{await N.read();let t=await N.read();if(t.value?.type===`raw`&&(t=await N.read()),t.value?.type===`error`){let n=t.value.error;throw ee(n)?new e({message:n.message,url:f,requestBodyValues:r,statusCode:n.statusCode??500,responseHeaders:p,responseBody:JSON.stringify(n.data),isRetryable:n.isRetryable??!1}):Error(`Expected a normalized Anthropic stream error`)}}finally{N.cancel().catch(()=>{}),N.releaseLock()}return{stream:M,request:{body:r},response:{headers:p}}}};function tn(e){return e.includes(`claude-opus-5`)?{maxOutputTokens:128e3,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!0,supportsXhighEffort:!0,rejectsThinkingDisabledAboveHighEffort:!0,isKnownModel:!0}:e.includes(`claude-opus-4-8`)||e.includes(`claude-opus-4-7`)||e.includes(`claude-fable-5`)||e.includes(`claude-sonnet-5`)?{maxOutputTokens:128e3,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!0,supportsXhighEffort:!0,rejectsThinkingDisabledAboveHighEffort:!1,isKnownModel:!0}:e.includes(`claude-sonnet-4-6`)||e.includes(`claude-opus-4-6`)?{maxOutputTokens:128e3,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!1,supportsXhighEffort:!1,rejectsThinkingDisabledAboveHighEffort:!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,rejectsThinkingDisabledAboveHighEffort:!1,isKnownModel:!0}:e.includes(`claude-opus-4-1`)?{maxOutputTokens:32e3,supportsStructuredOutput:!0,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,rejectsThinkingDisabledAboveHighEffort:!1,isKnownModel:!0}:/claude-sonnet-4(?:-|@)/.test(e)?{maxOutputTokens:64e3,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,rejectsThinkingDisabledAboveHighEffort:!1,isKnownModel:!0}:/claude-opus-4(?:-|@)/.test(e)?{maxOutputTokens:32e3,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,rejectsThinkingDisabledAboveHighEffort:!1,isKnownModel:!0}:e.includes(`claude-3-haiku`)?{maxOutputTokens:4096,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,rejectsThinkingDisabledAboveHighEffort:!1,isKnownModel:!0}:/claude-(?:instant(?:-|$)|v?2(?=$|[-.:])|3(?=$|[-.]))/.test(e)?{maxOutputTokens:4096,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,rejectsThinkingDisabledAboveHighEffort:!1,isKnownModel:!1}:e.includes(`claude-`)?{maxOutputTokens:128e3,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!0,supportsXhighEffort:!0,rejectsThinkingDisabledAboveHighEffort:!0,isKnownModel:!1}:{maxOutputTokens:4096,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,rejectsThinkingDisabledAboveHighEffort:!1,isKnownModel:!1}}function nn(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_fetch_20260318`||r.type===`web_search_20260209`||r.type===`web_search_20260318`)){t=!0;continue}if(`type`in r&&(r.type===`code_execution_20250522`||r.type===`code_execution_20250825`||r.type===`code_execution_20260120`)){n=!0;break}}return t&&!n}function rn({reasoning:e,supportsAdaptiveThinking:t,supportsXhighEffort:n,maxOutputTokensForModel:r,warnings:i}){if(!E(e))return;if(e===`none`)return{thinking:{type:`disabled`}};if(t)return{thinking:{type:`adaptive`,display:`summarized`},effort:w({reasoning:e,effortMap:{minimal:`low`,low:`low`,medium:`medium`,high:`high`,xhigh:n?`xhigh`:`max`},warnings:i})};let a=se({reasoning:e,maxOutputTokens:r,maxReasoningBudget:r,warnings:i});if(a!=null)return{thinking:{type:`enabled`,budgetTokens:a}}}function an(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}function on(e){if(e!=null)return{type:e.type,...e.category==null?{}:{category:e.category},...e.explanation==null?{}:{explanation:e.explanation},...e.recommended_model==null?{}:{recommendedModel:e.recommended_model}}}var sn=/^[A-Za-z0-9_-]{1,64}$/,cn=De.pick({anthropicBeta:!0}),ln=()=>u({id:c(),type:p(`message_batch`),processing_status:c(),request_counts:u({processing:y(),succeeded:y(),errored:y(),canceled:y(),expired:y()}),created_at:c(),expires_at:c(),archived_at:c().nullish(),cancel_initiated_at:c().nullish(),ended_at:c().nullish(),results_url:c().nullish()}),un=j(()=>Y(ln())),dn=j(()=>Y(u({data:d(ln()),has_more:_(),last_id:c().nullish()}))),fn=new Set([`advisor_tool_result`,`bash_code_execution_tool_result`,`code_execution_tool_result`,`compaction`,`container_upload`,`fallback`,`mcp_tool_result`,`mcp_tool_use`,`redacted_thinking`,`server_tool_use`,`text`,`text_editor_code_execution_tool_result`,`thinking`,`tool_search_tool_result`,`tool_use`,`web_fetch_tool_result`,`web_search_tool_result`]),pn=j(()=>Y(f(`type`,[u({type:p(`succeeded`),message:a()}),u({type:p(`errored`),error:u({type:p(`error`),error:u({type:c(),message:c()}),request_id:c().nullish()})}),u({type:p(`canceled`)}),u({type:p(`expired`)})]))),mn=j(()=>Y(u({custom_id:c(),result:a()})));function hn(e){for(let t of e){let e=t.type;if(e!==`text`)throw new i({functionality:`batch request type: ${e}`,message:`The Anthropic Message Batches API does not support batch requests with type "${e}".`})}}var gn=class{constructor(e){this.options=e,this.specificationVersion=`v4`,this.provider=e.provider,this.supportedUrls=e.supportedUrls,this.generateId=e.config.generateId??D}async doStartBatch({requests:e,providerOptions:t,headers:n,abortSignal:r,webhookUrl:a}){var o;hn(e),vn(e);let s=new Set(await _n({provider:this.options.config.provider,providerOptions:t})),c=new Set(s),l=[],u=a==null?[]:[{warning:{type:`unsupported`,feature:`webhookUrl`,details:`The Anthropic Message Batches API does not support completion webhooks.`}}];for(let t of e){if((await _n({provider:this.options.config.provider,providerOptions:t.options.providerOptions})).length>0)throw new i({functionality:`per-request providerOptions.anthropic.anthropicBeta`,message:`Anthropic Message Batches do not support per-request betas (request "${t.id}"). Set providerOptions.anthropic.anthropicBeta on startBatch instead.`});let e=await en.prepareRequest({modelId:t.modelId,config:this.options.config,options:{...t.options,stream:!1,userSuppliedBetas:new Set(s)}});if(e.usesJsonResponseTool)throw new i({functionality:`batch responseFormat JSON-tool fallback`,message:`Anthropic Message Batches cannot decode the JSON-tool structured-output fallback (request "${t.id}") because batch results are retrieved independently of the start call. Use a model that supports native output_format structured outputs.`});let n=t.options.tools?.find(t=>t.type===`provider`&&e.toolNameMapping.toProviderToolName(t.name)!==t.name);if(n!=null)throw new i({functionality:`aliased provider tool names in batches`,message:`Anthropic Message Batches cannot restore the custom provider-tool name "${n.name}" when results are retrieved independently of the start call (request "${t.id}"). Use the provider's canonical tool name.`});let r=(o=this.options.config).transformRequestBody?.call(o,e.args,e.betas)??e.args;yn({body:r,requestId:t.id}),l.push({custom_id:t.id,params:r});for(let t of e.betas)c.add(t);for(let n of e.warnings)u.push({requestId:t.id,warning:n})}let{value:d}=await q({url:this.getBatchUrl(``),headers:await this.getStartBatchHeaders({betas:c,headers:n}),body:{requests:l},failedResponseHandler:X,successfulResponseHandler:N(un),abortSignal:r,fetch:this.options.config.fetch});return{batchId:d.id,...bn(d),warnings:u}}async doGetBatchStatus(e){return bn(await this.retrieveBatch(e))}async doCancelBatch(e){return await q({url:this.getBatchUrl(`/${encodeURIComponent(e.batchId)}/cancel`),headers:await this.getBatchHeaders(e.headers),body:{},failedResponseHandler:X,successfulResponseHandler:N(un),abortSignal:e.abortSignal,fetch:this.options.config.fetch}),{}}async doListBatches(e){let t=new URL(this.getBatchUrl(``));e.limit!=null&&t.searchParams.set(`limit`,String(e.limit)),e.cursor!=null&&t.searchParams.set(`after_id`,e.cursor);let{value:n}=await O({url:t.toString(),validateUrl:!1,headers:await this.getBatchHeaders(e.headers),failedResponseHandler:X,successfulResponseHandler:N(dn),abortSignal:e.abortSignal,fetch:this.options.config.fetch});return{batches:n.data.map(e=>({batchId:e.id,...bn(e)})),...n.has_more&&n.last_id!=null?{nextCursor:n.last_id}:{}}}async doGetBatchResults(e){let r=await this.retrieveBatch(e);if(bn(r).status===`pending`)throw new t({argument:`batchId`,message:`Anthropic batch "${e.batchId}" is not complete.`});if(r.archived_at!=null)throw new t({argument:`batchId`,message:`Anthropic batch "${e.batchId}" results are no longer available.`});if(r.results_url==null)throw new n({data:r,message:`Anthropic batch "${e.batchId}" completed without batch output.`});let{value:i}=await O({url:r.results_url,validateUrl:!0,credentialedOrigin:this.options.config.baseURL,trustedOrigin:this.options.config.baseURL,headers:await this.getBatchHeaders(e.headers),failedResponseHandler:X,successfulResponseHandler:B(mn),abortSignal:e.abortSignal,fetch:this.options.config.fetch});return ae(this.iterateBatchResults(i))}async retrieveBatch(e){let{value:t}=await O({url:this.getBatchUrl(`/${encodeURIComponent(e.batchId)}`),validateUrl:!1,headers:await this.getBatchHeaders(e.headers),failedResponseHandler:X,successfulResponseHandler:N(un),abortSignal:e.abortSignal,fetch:this.options.config.fetch});return t}async*iterateBatchResults(e){for await(let t of e)yield await Cn(t,this.generateId)}getBatchUrl(e){return`${this.options.config.baseURL}/messages/batches${e}`}async getStartBatchHeaders({betas:e,headers:t}){return H(M(await this.getBatchHeaders(t)),{"anthropic-beta":e.size>0?Array.from(e).join(`,`):void 0})}async getBatchHeaders(e){return H(this.options.config.headers?await U(this.options.config.headers):void 0,e)}};async function _n({provider:e,providerOptions:t}){let n=e.split(`.`)[0],r=await b({provider:`anthropic`,providerOptions:t,schema:cn}),i=n===`anthropic`?void 0:await b({provider:n,providerOptions:t,schema:cn});return Object.assign({},r??{},i??{}).anthropicBeta??[]}function vn(e){let n=new Set;for(let r of e){if(!sn.test(r.id))throw new t({argument:`requests`,message:`Anthropic batch request ID "${r.id}" must match ^[A-Za-z0-9_-]{1,64}$.`});if(n.has(r.id))throw new t({argument:`requests`,message:`Anthropic batch request IDs must be unique; duplicate ID "${r.id}".`});n.add(r.id)}}function yn({body:e,requestId:t}){if(e.speed!=null)throw new i({functionality:`providerOptions.anthropic.speed`,message:`Anthropic Message Batches do not support speed (request "${t}").`});if(Array.isArray(e.fallbacks)&&e.fallbacks.some(e=>typeof e==`object`&&!!e&&`speed`in e&&e.speed!=null))throw new i({functionality:`providerOptions.anthropic.fallbacks[].speed`,message:`Anthropic Message Batches do not support fallback speed (request "${t}").`})}function bn(e){let t=Sn(e.request_counts);return{status:xn(e.processing_status),rawStatus:e.processing_status,...t==null?{}:{requestCounts:t},createdAt:e.created_at,expiresAt:e.expires_at,providerMetadata:{anthropic:{archivedAt:e.archived_at??null,cancelInitiatedAt:e.cancel_initiated_at??null,endedAt:e.ended_at??null,requestCounts:e.request_counts,resultsUrl:e.results_url??null}}}}function xn(e){switch(e){case`ended`:return`completed`;default:return`pending`}}function Sn(e){return te({total:e.processing+e.succeeded+e.errored+e.canceled+e.expired,pending:e.processing,completed:e.succeeded,failed:e.errored+e.canceled+e.expired})}async function Cn(e,t){let n=await G({value:e.result,schema:pn});if(!n.success)return wn(e.custom_id);let r=n.value;switch(r.type){case`canceled`:return{type:`text`,id:e.custom_id,status:`cancelled`};case`expired`:return{type:`text`,id:e.custom_id,status:`expired`};case`errored`:{let t=r.error.request_id;return{type:`text`,id:e.custom_id,status:`failed`,error:{message:r.error.error.message,type:r.error.error.type},...t==null?{}:{providerMetadata:{anthropic:{requestId:t}}}}}case`succeeded`:{let n=await Tn(r.message);return n==null?wn(e.custom_id):{type:`text`,id:e.custom_id,status:`succeeded`,result:En(n,t)}}}}function wn(e){return{type:`text`,id:e,status:`failed`,error:{message:`Anthropic returned an invalid Message batch result.`,code:`invalid_response`}}}async function Tn(e){let t=await G({value:e,schema:Se});if(t.success)return t.value;if(!A(e)||!Array.isArray(e.content))return;let n=[];for(let t of e.content){let r=await G({value:{...e,content:[t]},schema:Se});if(r.success){let[e]=r.value.content;e!=null&&n.push(e)}else if(!A(t)||typeof t.type!=`string`||fn.has(t.type))return}let r=await G({value:{...e,content:n},schema:Se});return r.success?r.value:void 0}function En(e,t){let n=[],r={},i={};for(let a of e.content)switch(a.type){case`text`:let e=a.citations;n.push({type:`text`,text:a.text,...e!=null&&e.length>0&&{providerMetadata:{anthropic:{citations:e}}}});for(let e of a.citations??[]){let r=Zt(e,[],t);r!=null&&n.push(r)}break;case`thinking`:n.push({type:`reasoning`,text:a.thinking,providerMetadata:{anthropic:{signature:a.signature}}});break;case`redacted_thinking`:n.push({type:`reasoning`,text:``,providerMetadata:{anthropic:{redactedData:a.data}}});break;case`container_upload`:n.push({type:`custom`,kind:`anthropic.container_upload`,providerMetadata:{anthropic:{fileId:a.file_id}}});break;case`compaction`:n.push({type:`text`,text:a.content,providerMetadata:{anthropic:{type:`compaction`}}});break;case`tool_use`:n.push({type:`tool-call`,toolCallId:a.id,toolName:a.name,input:JSON.stringify(a.input),...Dn(a.caller)});break;case`server_tool_use`:{let e=a.name===`bash_code_execution`||a.name===`text_editor_code_execution`,t=e||a.name===`code_execution`,r=e?`code_execution`:a.name;(a.name===`tool_search_tool_bm25`||a.name===`tool_search_tool_regex`)&&(i[a.id]=a.name),n.push({type:`tool-call`,toolCallId:a.id,toolName:r,input:JSON.stringify(e?{type:a.name,...a.input??{}}:a.name===`code_execution`&&a.input!=null&&`code`in a.input&&!(`type`in a.input)?{type:`programmatic-tool-call`,...a.input}:a.input),providerExecuted:!0,...t?{dynamic:!0}:{},...Dn(a.caller)});break}case`mcp_tool_use`:{let e={type:`tool-call`,toolCallId:a.id,toolName:a.name,input:JSON.stringify(a.input),providerExecuted:!0,dynamic:!0,providerMetadata:{anthropic:{serverName:a.server_name,type:`mcp-tool-use`}}};r[a.id]=e,n.push(e);break}case`mcp_tool_result`:{let e=r[a.tool_use_id];n.push({type:`tool-result`,toolCallId:a.tool_use_id,toolName:e?.toolName??`mcp`,isError:a.is_error,result:a.content,dynamic:!0,...e?.providerMetadata!=null&&{providerMetadata:e.providerMetadata}});break}case`web_fetch_tool_result`:n.push({type:`tool-result`,toolCallId:a.tool_use_id,toolName:`web_fetch`,...a.content.type===`web_fetch_tool_result_error`?{isError:!0,result:{errorCode:a.content.error_code,type:a.content.type}}:{result:{content:{citations:a.content.content.citations,source:{data:a.content.content.source.data,mediaType:a.content.content.source.media_type,type:a.content.content.source.type},title:a.content.content.title,type:a.content.content.type},retrievedAt:a.content.retrieved_at,type:a.content.type,url:a.content.url}},...Dn(a.caller)});break;case`web_search_tool_result`:if(n.push({type:`tool-result`,toolCallId:a.tool_use_id,toolName:`web_search`,...Array.isArray(a.content)?{result:a.content.map(e=>({encryptedContent:e.encrypted_content,pageAge:e.page_age??null,...e.title==null?{}:{title:e.title},type:e.type,url:e.url}))}:{isError:!0,result:{errorCode:a.content.error_code,type:a.content.type}},...Dn(a.caller)}),Array.isArray(a.content))for(let e of a.content)n.push({type:`source`,sourceType:`url`,id:t(),url:e.url,...e.title==null?{}:{title:e.title},providerMetadata:{anthropic:{pageAge:e.page_age??null}}});break;case`code_execution_tool_result`:n.push({type:`tool-result`,toolCallId:a.tool_use_id,toolName:`code_execution`,...a.content.type===`code_execution_tool_result_error`?{isError:!0,result:{errorCode:a.content.error_code,type:a.content.type}}:{result:a.content}});break;case`bash_code_execution_tool_result`:case`text_editor_code_execution_tool_result`:n.push({type:`tool-result`,toolCallId:a.tool_use_id,toolName:`code_execution`,result:a.content});break;case`tool_search_tool_result`:{let e=i[a.tool_use_id]??`tool_search_tool_regex`;n.push({type:`tool-result`,toolCallId:a.tool_use_id,toolName:e,...a.content.type===`tool_search_tool_result_error`?{isError:!0,result:{errorCode:a.content.error_code,type:a.content.type}}:{result:a.content.tool_references.map(e=>({toolName:e.tool_name,type:e.type}))}});break}case`advisor_tool_result`:a.content.type===`advisor_result`?n.push({type:`tool-result`,toolCallId:a.tool_use_id,toolName:`advisor`,result:{type:a.content.type,text:a.content.text,...a.content.stop_reason==null?{}:{stopReason:a.content.stop_reason}}}):a.content.type===`advisor_redacted_result`?n.push({type:`tool-result`,toolCallId:a.tool_use_id,toolName:`advisor`,result:{type:a.content.type,encryptedContent:a.content.encrypted_content,...a.content.stop_reason==null?{}:{stopReason:a.content.stop_reason}}}):n.push({type:`tool-result`,toolCallId:a.tool_use_id,toolName:`advisor`,isError:!0,result:{errorCode:a.content.error_code,type:a.content.type}})}return{content:n,finishReason:{unified:Vt({finishReason:e.stop_reason}),raw:e.stop_reason??void 0},usage:_t({usage:e.usage}),response:{id:e.id??void 0,modelId:e.model??void 0},warnings:[],providerMetadata:{anthropic:On(e)}}}function Dn(e){return e==null?{}:{providerMetadata:{anthropic:{caller:{type:e.type,toolId:e.tool_id}}}}}function On(e){let t=An(e.stop_details);return{usage:e.usage,stopSequence:e.stop_sequence??null,...t==null?{}:{stopDetails:t},...e.input_transformations==null?{}:{inputTransformations:e.input_transformations},iterations:e.usage.iterations?e.usage.iterations.map(e=>({type:e.type,...e.model==null?{}:{model:e.model},inputTokens:e.input_tokens,outputTokens:e.output_tokens,...e.cache_creation_input_tokens?{cacheCreationInputTokens:e.cache_creation_input_tokens}:{},...e.cache_read_input_tokens?{cacheReadInputTokens:e.cache_read_input_tokens}:{}})):null,container:e.container?{expiresAt:e.container.expires_at,id:e.container.id,skills:e.container.skills?.map(e=>({type:e.type,skillId:e.skill_id,version:e.version}))??null}:null,contextManagement:kn(e.context_management)}}function kn(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}}})}:null}function An(e){if(e!=null)return{type:e.type,...e.category==null?{}:{category:e.category},...e.explanation==null?{}:{explanation:e.explanation},...e.recommended_model==null?{}:{recommendedModel:e.recommended_model}}}var jn=j(()=>Y(u({command:c(),restart:_().optional()}))),Mn=I({id:`anthropic.bash_20241022`,inputSchema:jn});function Nn(e={}){let{execute:t,...n}=e;return Mn(t===void 0?{...n,execute:async({command:e},{abortSignal:t,experimental_sandbox:n})=>{if(!n)throw Error(`Sandbox session is not available`);return await n.run({command:e,abortSignal:t})}}:{...n,...t===null?{}:{execute:t}})}var Pn=j(()=>Y(u({command:c(),restart:_().optional()}))),Fn=I({id:`anthropic.bash_20250124`,inputSchema:Pn});function In(e={}){let{execute:t,...n}=e;return Fn(t===void 0?{...n,execute:async({command:e},{abortSignal:t,experimental_sandbox:n})=>{if(!n)throw Error(`Sandbox session is not available`);return await n.run({command:e,abortSignal:t})}}:{...n,...t===null?{}:{execute:t}})}var Ln=j(()=>Y(u({action:g([`key`,`type`,`mouse_move`,`left_click`,`left_click_drag`,`right_click`,`middle_click`,`double_click`,`screenshot`,`cursor_position`]),coordinate:d(y().int()).optional(),text:c().optional()}))),Rn=I({id:`anthropic.computer_20241022`,inputSchema:Ln}),zn=j(()=>Y(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([y().int(),y().int()]).optional(),duration:y().optional(),scroll_amount:y().optional(),scroll_direction:g([`up`,`down`,`left`,`right`]).optional(),start_coordinate:s([y().int(),y().int()]).optional(),text:c().optional()}))),Bn=I({id:`anthropic.computer_20250124`,inputSchema:zn}),Vn=j(()=>Y(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([y().int(),y().int()]).optional(),duration:y().optional(),region:s([y().int(),y().int(),y().int(),y().int()]).optional(),scroll_amount:y().optional(),scroll_direction:g([`up`,`down`,`left`,`right`]).optional(),start_coordinate:s([y().int(),y().int()]).optional(),text:c().optional()}))),Hn=I({id:`anthropic.computer_20251124`,inputSchema:Vn}),Un=j(()=>Y(f(`command`,[u({command:p(`view`),path:c(),view_range:s([y(),y()]).optional()}),u({command:p(`create`),path:c(),file_text:c()}),u({command:p(`str_replace`),path:c(),old_str:c(),new_str:c()}),u({command:p(`insert`),path:c(),insert_line:y(),insert_text:c()}),u({command:p(`delete`),path:c()}),u({command:p(`rename`),old_path:c(),new_path:c()})]))),Wn=I({id:`anthropic.memory_20250818`,inputSchema:Un}),Gn=j(()=>Y(u({command:g([`view`,`create`,`str_replace`,`insert`,`undo_edit`]),path:c(),file_text:c().optional(),insert_line:y().int().optional(),new_str:c().optional(),insert_text:c().optional(),old_str:c().optional(),view_range:d(y().int()).optional()}))),Kn=I({id:`anthropic.text_editor_20241022`,inputSchema:Gn}),qn=j(()=>Y(u({command:g([`view`,`create`,`str_replace`,`insert`,`undo_edit`]),path:c(),file_text:c().optional(),insert_line:y().int().optional(),new_str:c().optional(),insert_text:c().optional(),old_str:c().optional(),view_range:d(y().int()).optional()}))),Jn=I({id:`anthropic.text_editor_20250124`,inputSchema:qn}),Yn=j(()=>Y(u({command:g([`view`,`create`,`str_replace`,`insert`]),path:c(),file_text:c().optional(),insert_line:y().int().optional(),new_str:c().optional(),insert_text:c().optional(),old_str:c().optional(),view_range:d(y().int()).optional()}))),Xn=I({id:`anthropic.text_editor_20250429`,inputSchema:Yn}),Zn=j(()=>Y(d(u({type:p(`tool_reference`),toolName:c()})))),Qn=j(()=>Y(u({query:c(),limit:y().optional()}))),$n=k({id:`anthropic.tool_search_bm25_20251119`,inputSchema:Qn,outputSchema:Zn,supportsDeferredResults:!0}),er={advisor_20260301:Fe,bash_20241022:Nn,bash_20250124:In,codeExecution_20250522:xt,codeExecution_20250825:Tt,codeExecution_20260120:kt,computer_20241022:Rn,computer_20250124:Bn,computer_20251124:Hn,memory_20250818:Wn,textEditor_20241022:Kn,textEditor_20250124:Jn,textEditor_20250429:Xn,textEditor_20250728:ze,webFetch_20250910:ht,webFetch_20260209:ut,webFetch_20260318:at,webSearch_20250305:et,webSearch_20260209:Ye,webSearch_20260318:We,toolSearchRegex_20251119:Nt,toolSearchBm25_20251119:(e={})=>$n(e)},tr=j(()=>Y(u({id:c(),display_title:c().nullish(),name:c().nullish(),description:c().nullish(),latest_version:c().nullish(),source:c(),created_at:c(),updated_at:c()})));j(()=>Y(u({data:d(u({version:c()}))})));var nr=j(()=>Y(u({type:c(),skill_id:c(),name:c().nullish(),description:c().nullish()})));function rr(e){let t=encodeURIComponent(e);return t===`.`?`%252E`:t===`..`?`%252E%252E`:t}var ir=class{constructor(e){this.config=e,this.specificationVersion=`v4`}get provider(){return this.config.provider}async getHeaders(){return H(await U(this.config.headers),{"anthropic-beta":`skills-2025-10-02`})}async fetchVersionMetadata({skillId:e,version:t,headers:n}){let{value:r}=await O({url:`${this.config.baseURL}/skills/${rr(e)}/versions/${rr(t)}`,validateUrl:!1,headers:n,failedResponseHandler:X,successfulResponseHandler:N(nr),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=R(t.data);n.append(`files[]`,new Blob([e]),t.path)}let r=await this.getHeaders(),{value:i}=await z({url:`${this.config.baseURL}/skills`,headers:r,formData:n,failedResponseHandler:X,successfulResponseHandler:N(tr),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}}},ar=`4.0.56`,or=`https://api.anthropic.com`,sr=`${or}/v1`;function cr(e){let t=L(re(e));return t===or?sr:t}function lr(e={}){let n=cr(T({settingValue:e.baseURL,environmentVariableName:`ANTHROPIC_BASE_URL`}))??sr,i=e.name??`anthropic.messages`,a={"image/*":[/^https?:\/\/.*$/],"application/pdf":[/^https?:\/\/.*$/]};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 o=()=>{let t=e.authToken?{Authorization:`Bearer ${e.authToken}`}:{"x-api-key":C({apiKey:e.apiKey,environmentVariableName:`ANTHROPIC_API_KEY`,description:`Anthropic`})};return ue({"anthropic-version":`2023-06-01`,...t,...e.headers},`ai-sdk/anthropic/${ar}`)},s={provider:i,baseURL:n,headers:o,fetch:e.fetch,generateId:e.generateId??D,supportedUrls:()=>a},c=e=>new en(e,s),l=()=>new gn({provider:`${i.replace(/\.messages$/,``)}.batch`,config:s,supportedUrls:a}),u=()=>new ir({provider:`${i.replace(`.messages`,``)}.skills`,baseURL:n,headers:o,fetch:e.fetch}),d=function(e){if(new.target)throw Error(`The Anthropic model function cannot be called with the new keyword.`);return c(e)};return d.specificationVersion=`v4`,d.languageModel=c,d.chat=c,d.messages=c,d.evaluationModel=e=>new me({model:c(e),provider:`${i.replace(/\.messages$/,``)}.evaluation`}),d.experimental_batch=l,d.embeddingModel=e=>{throw new r({modelId:e,modelType:`embeddingModel`})},d.textEmbeddingModel=d.embeddingModel,d.imageModel=e=>{throw new r({modelId:e,modelType:`imageModel`})},d.files=()=>new _e({provider:i,baseURL:n,headers:o,fetch:e.fetch}),d.skills=u,d.tools=er,d}var ur=lr();function dr({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{ar as VERSION,ur as anthropic,lr as createAnthropic,dr as forwardAnthropicContainerIdFromLastStep};