UNPKG

eve

Version:

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

2 lines 107 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,Bt as o,C as s,Dt as c,Et as l,Ft as u,G as d,H as f,I as p,J as m,L as h,Lt as g,M as _,Mt as v,Nt as y,P as ee,Pt as b,Q as x,R as S,Rt as C,S as w,U as T,V as E,Vt as D,W as O,X as k,Z as A,_ as j,_t as te,b as M,c as N,ct as P,dt as F,ft as I,g as ne,gt as re,h as L,i as R,jt as z,k as B,kt as ie,l as V,m as ae,mt as H,nt as U,o as oe,ot as W,q as se,rt as ce,s as le,st as ue,tt as G,vt as K,w as de,wt as q,xt as J,zt as Y}from"../../_chunks/workflow/dist-DhncQSl7.js";import{n as fe,t as pe}from"../../_chunks/workflow/dist-DsNhwdzf.js";var me=E(()=>K(u({type:z(`error`),error:u({type:C(),message:C()})}))),X=L({errorSchema:me,errorToMessage:e=>e.error.message}),he=E(()=>K(u({id:C(),type:z(`file`),filename:C(),mime_type:C(),size_bytes:b(),created_at:C(),downloadable:l().nullish()}))),ge=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=N(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 A({url:`${this.config.baseURL}/files`,headers:R(this.config.headers(),{"anthropic-beta":`files-api-2025-04-14`},i),formData:s,failedResponseHandler:X,successfulResponseHandler:j(he),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}}}}}},_e=u({type:C(),category:C().nullish(),explanation:C().nullish(),recommended_model:C().nullish()}),Z=o([u({type:z(`code_execution_20250825`),tool_id:C()}),u({type:z(`code_execution_20260120`),tool_id:C()}),u({type:z(`direct`)})]),ve=c(`type`,[u({type:z(`web_search_result_location`),cited_text:C(),url:C(),title:C().nullable(),encrypted_index:C()}),u({type:z(`page_location`),cited_text:C(),document_index:b(),document_title:C().nullable(),start_page_number:b(),end_page_number:b(),file_id:C().nullish()}),u({type:z(`char_location`),cited_text:C(),document_index:b(),document_title:C().nullable(),start_char_index:b(),end_char_index:b(),file_id:C().nullish()}),u({type:z(`content_block_location`),cited_text:C(),document_index:b(),document_title:C().nullable(),start_block_index:b(),end_block_index:b(),file_id:C().nullable()}),u({type:z(`search_result_location`),cited_text:C(),search_result_index:b(),source:C(),title:C().nullable(),start_block_index:b(),end_block_index:b()})]),ye=o([C(),q(o([C(),u({type:z(`text`),text:C(),citations:q(ie()).nullable().optional()})]))]),be=E(()=>K(u({type:z(`message`),id:C().nullish(),model:C().nullish(),content:q(c(`type`,[u({type:z(`text`),text:C(),citations:q(ve).nullable().optional()}),u({type:z(`thinking`),thinking:C(),signature:C()}),u({type:z(`redacted_thinking`),data:C()}),u({type:z(`compaction`),content:C()}),u({type:z(`tool_use`),id:C(),name:C(),input:D(),caller:Z.optional()}),u({type:z(`server_tool_use`),id:C(),name:C(),input:g(C(),D()).nullish(),caller:Z.optional()}),u({type:z(`mcp_tool_use`),id:C(),name:C(),input:D(),server_name:C()}),u({type:z(`mcp_tool_result`),tool_use_id:C(),is_error:l(),content:ye}),u({type:z(`web_fetch_tool_result`),tool_use_id:C(),caller:Z.optional(),content:o([u({type:z(`web_fetch_result`),url:C(),retrieved_at:C().nullable(),content:u({type:z(`document`),title:C().nullable(),citations:u({enabled:l()}).optional(),source:o([u({type:z(`base64`),media_type:z(`application/pdf`),data:C()}),u({type:z(`text`),media_type:z(`text/plain`),data:C()})])})}),u({type:z(`web_fetch_tool_result_error`),error_code:C()})])}),u({type:z(`web_search_tool_result`),tool_use_id:C(),caller:Z.optional(),content:o([q(u({type:z(`web_search_result`),url:C(),title:C().nullable(),encrypted_content:C(),page_age:C().nullish()})),u({type:z(`web_search_tool_result_error`),error_code:C()})])}),u({type:z(`code_execution_tool_result`),tool_use_id:C(),content:o([u({type:z(`code_execution_result`),stdout:C(),stderr:C(),return_code:b(),content:q(u({type:z(`code_execution_output`),file_id:C()})).optional().default([])}),u({type:z(`encrypted_code_execution_result`),encrypted_stdout:C(),stderr:C(),return_code:b(),content:q(u({type:z(`code_execution_output`),file_id:C()})).optional().default([])}),u({type:z(`code_execution_tool_result_error`),error_code:C()})])}),u({type:z(`bash_code_execution_tool_result`),tool_use_id:C(),content:c(`type`,[u({type:z(`bash_code_execution_result`),content:q(u({type:z(`bash_code_execution_output`),file_id:C()})),stdout:C(),stderr:C(),return_code:b()}),u({type:z(`bash_code_execution_tool_result_error`),error_code:C()})])}),u({type:z(`text_editor_code_execution_tool_result`),tool_use_id:C(),content:c(`type`,[u({type:z(`text_editor_code_execution_tool_result_error`),error_code:C()}),u({type:z(`text_editor_code_execution_view_result`),content:C(),file_type:C(),num_lines:b().nullable(),start_line:b().nullable(),total_lines:b().nullable()}),u({type:z(`text_editor_code_execution_create_result`),is_file_update:l()}),u({type:z(`text_editor_code_execution_str_replace_result`),lines:q(C()).nullable(),new_lines:b().nullable(),new_start:b().nullable(),old_lines:b().nullable(),old_start:b().nullable()})])}),u({type:z(`tool_search_tool_result`),tool_use_id:C(),content:o([u({type:z(`tool_search_tool_search_result`),tool_references:q(u({type:z(`tool_reference`),tool_name:C()}))}),u({type:z(`tool_search_tool_result_error`),error_code:C()})])}),u({type:z(`container_upload`),file_id:C()}),u({type:z(`advisor_tool_result`),tool_use_id:C(),content:c(`type`,[u({type:z(`advisor_result`),text:C(),stop_reason:C().nullish()}),u({type:z(`advisor_redacted_result`),encrypted_content:C(),stop_reason:C().nullish()}),u({type:z(`advisor_tool_result_error`),error_code:C()})])}),u({type:z(`fallback`)})])),stop_reason:C().nullish(),stop_sequence:C().nullish(),stop_details:_e.nullish(),usage:v({input_tokens:b(),output_tokens:b(),output_tokens_details:u({thinking_tokens:b().nullish()}).nullish(),cache_creation_input_tokens:b().nullish(),cache_read_input_tokens:b().nullish(),iterations:q(u({type:o([z(`compaction`),z(`message`),z(`advisor_message`),z(`fallback_message`)]),model:C().nullish(),input_tokens:b(),output_tokens:b(),cache_creation_input_tokens:b().nullish(),cache_read_input_tokens:b().nullish()})).nullish()}),container:u({expires_at:C(),id:C(),skills:q(u({type:o([z(`anthropic`),z(`custom`)]),skill_id:C(),version:C()})).nullish()}).nullish(),context_management:u({applied_edits:q(o([u({type:z(`clear_tool_uses_20250919`),cleared_tool_uses:b(),cleared_input_tokens:b()}),u({type:z(`clear_thinking_20251015`),cleared_thinking_turns:b(),cleared_input_tokens:b()}),u({type:z(`compact_20260112`)})]))}).nullish()}))),xe=E(()=>K(c(`type`,[u({type:z(`message_start`),message:u({id:C().nullish(),model:C().nullish(),role:C().nullish(),usage:v({input_tokens:b(),cache_creation_input_tokens:b().nullish(),cache_read_input_tokens:b().nullish()}),content:q(c(`type`,[u({type:z(`tool_use`),id:C(),name:C(),input:D(),caller:Z.optional()})])).nullish(),stop_reason:C().nullish(),container:u({expires_at:C(),id:C()}).nullish()})}),u({type:z(`content_block_start`),index:b(),content_block:c(`type`,[u({type:z(`text`),text:C()}),u({type:z(`thinking`),thinking:C()}),u({type:z(`tool_use`),id:C(),name:C(),input:g(C(),D()).optional(),caller:Z.optional()}),u({type:z(`redacted_thinking`),data:C()}),u({type:z(`compaction`),content:C().nullish()}),u({type:z(`server_tool_use`),id:C(),name:C(),input:g(C(),D()).nullish(),caller:Z.optional()}),u({type:z(`mcp_tool_use`),id:C(),name:C(),input:D(),server_name:C()}),u({type:z(`mcp_tool_result`),tool_use_id:C(),is_error:l(),content:ye}),u({type:z(`web_fetch_tool_result`),tool_use_id:C(),caller:Z.optional(),content:o([u({type:z(`web_fetch_result`),url:C(),retrieved_at:C().nullable(),content:u({type:z(`document`),title:C().nullable(),citations:u({enabled:l()}).optional(),source:o([u({type:z(`base64`),media_type:z(`application/pdf`),data:C()}),u({type:z(`text`),media_type:z(`text/plain`),data:C()})])})}),u({type:z(`web_fetch_tool_result_error`),error_code:C()})])}),u({type:z(`web_search_tool_result`),tool_use_id:C(),caller:Z.optional(),content:o([q(u({type:z(`web_search_result`),url:C(),title:C().nullable(),encrypted_content:C(),page_age:C().nullish()})),u({type:z(`web_search_tool_result_error`),error_code:C()})])}),u({type:z(`code_execution_tool_result`),tool_use_id:C(),content:o([u({type:z(`code_execution_result`),stdout:C(),stderr:C(),return_code:b(),content:q(u({type:z(`code_execution_output`),file_id:C()})).optional().default([])}),u({type:z(`encrypted_code_execution_result`),encrypted_stdout:C(),stderr:C(),return_code:b(),content:q(u({type:z(`code_execution_output`),file_id:C()})).optional().default([])}),u({type:z(`code_execution_tool_result_error`),error_code:C()})])}),u({type:z(`bash_code_execution_tool_result`),tool_use_id:C(),content:c(`type`,[u({type:z(`bash_code_execution_result`),content:q(u({type:z(`bash_code_execution_output`),file_id:C()})),stdout:C(),stderr:C(),return_code:b()}),u({type:z(`bash_code_execution_tool_result_error`),error_code:C()})])}),u({type:z(`text_editor_code_execution_tool_result`),tool_use_id:C(),content:c(`type`,[u({type:z(`text_editor_code_execution_tool_result_error`),error_code:C()}),u({type:z(`text_editor_code_execution_view_result`),content:C(),file_type:C(),num_lines:b().nullable(),start_line:b().nullable(),total_lines:b().nullable()}),u({type:z(`text_editor_code_execution_create_result`),is_file_update:l()}),u({type:z(`text_editor_code_execution_str_replace_result`),lines:q(C()).nullable(),new_lines:b().nullable(),new_start:b().nullable(),old_lines:b().nullable(),old_start:b().nullable()})])}),u({type:z(`tool_search_tool_result`),tool_use_id:C(),content:o([u({type:z(`tool_search_tool_search_result`),tool_references:q(u({type:z(`tool_reference`),tool_name:C()}))}),u({type:z(`tool_search_tool_result_error`),error_code:C()})])}),u({type:z(`advisor_tool_result`),tool_use_id:C(),content:c(`type`,[u({type:z(`advisor_result`),text:C(),stop_reason:C().nullish()}),u({type:z(`advisor_redacted_result`),encrypted_content:C(),stop_reason:C().nullish()}),u({type:z(`advisor_tool_result_error`),error_code:C()})])}),u({type:z(`fallback`)})])}),u({type:z(`content_block_delta`),index:b(),delta:c(`type`,[u({type:z(`input_json_delta`),partial_json:C()}),u({type:z(`text_delta`),text:C()}),u({type:z(`thinking_delta`),thinking:C()}),u({type:z(`signature_delta`),signature:C()}),u({type:z(`compaction_delta`),content:C().nullish()}),u({type:z(`citations_delta`),citation:ve})])}),u({type:z(`content_block_stop`),index:b()}),u({type:z(`error`),error:u({type:C(),message:C(),code:o([C(),b()]).nullish(),statusCode:b().nullish(),isRetryable:l().nullish(),data:D().nullish()})}),u({type:z(`message_delta`),delta:u({stop_reason:C().nullish(),stop_sequence:C().nullish(),stop_details:_e.nullish(),container:u({expires_at:C(),id:C(),skills:q(u({type:o([z(`anthropic`),z(`custom`)]),skill_id:C(),version:C()})).nullish()}).nullish()}),usage:v({input_tokens:b().nullish(),output_tokens:b(),output_tokens_details:u({thinking_tokens:b().nullish()}).nullish(),cache_creation_input_tokens:b().nullish(),cache_read_input_tokens:b().nullish(),iterations:q(u({type:o([z(`compaction`),z(`message`),z(`advisor_message`),z(`fallback_message`)]),model:C().nullish(),input_tokens:b(),output_tokens:b(),cache_creation_input_tokens:b().nullish(),cache_read_input_tokens:b().nullish()})).nullish()}),context_management:u({applied_edits:q(o([u({type:z(`clear_tool_uses_20250919`),cleared_tool_uses:b(),cleared_input_tokens:b()}),u({type:z(`clear_thinking_20251015`),cleared_thinking_turns:b(),cleared_input_tokens:b()}),u({type:z(`compact_20260112`)})]))}).nullish()}),u({type:z(`message_stop`)}),u({type:z(`ping`)})]))),Se=E(()=>K(u({signature:C().optional(),redactedData:C().optional()}))),Ce=u({containerUpload:l().optional(),citations:u({enabled:l()}).optional(),title:C().optional(),context:C().optional()}),we=u({clearAt:z(`next_user_message`).optional(),effort:J([`low`,`medium`,`high`,`xhigh`,`max`]).optional(),toolChanges:q(c(`type`,[u({type:z(`tool_addition`),toolName:C()}),u({type:z(`tool_removal`),toolName:C()})])).optional()}),Te=u({sendReasoning:l().optional(),structuredOutputMode:J([`outputFormat`,`jsonTool`,`auto`]).optional(),thinking:o([c(`type`,[u({type:z(`adaptive`),display:J([`omitted`,`summarized`,`updates`]).optional(),blockBinding:u({prefixMismatchBehavior:z(`drop_block`)}).optional()}),u({type:z(`enabled`),budgetTokens:b().optional()}),u({type:z(`disabled`)})]),u({type:y().optional(),blockBinding:u({prefixMismatchBehavior:z(`drop_block`)})})]).optional(),disableParallelToolUse:l().optional(),cacheControl:u({type:z(`ephemeral`),ttl:o([z(`5m`),z(`1h`)]).optional()}).optional(),metadata:u({userId:C().optional()}).optional(),mcpServers:q(u({type:z(`url`),name:C(),url:C(),authorizationToken:C().nullish(),toolConfiguration:u({enabled:l().nullish(),allowedTools:q(C()).nullish()}).nullish()})).optional(),container:u({id:C().optional(),skills:q(c(`type`,[u({type:z(`anthropic`),skillId:C(),version:C().optional()}),u({type:z(`custom`),providerReference:g(C(),C()),version:C().optional()})])).optional()}).optional(),toolStreaming:l().optional(),effort:J([`low`,`medium`,`high`,`xhigh`,`max`]).optional(),taskBudget:u({type:z(`tokens`),total:b().int().min(2e4),remaining:b().int().min(0).optional()}).optional(),speed:J([`fast`,`standard`]).optional(),serviceTier:J([`auto`,`standard_only`]).optional(),inferenceGeo:J([`us`,`global`]).optional(),fallbacks:o([z(`default`),q(u({model:C(),max_tokens:b().int().optional(),thinking:g(C(),D()).optional(),output_config:g(C(),D()).optional(),speed:J([`fast`,`standard`]).optional()}))]).optional(),anthropicBeta:q(C()).optional(),contextManagement:u({edits:q(c(`type`,[u({type:z(`clear_tool_uses_20250919`),trigger:c(`type`,[u({type:z(`input_tokens`),value:b()}),u({type:z(`tool_uses`),value:b()})]).optional(),keep:u({type:z(`tool_uses`),value:b()}).optional(),clearAtLeast:u({type:z(`input_tokens`),value:b()}).optional(),clearToolInputs:l().optional(),excludeTools:q(C()).optional()}),u({type:z(`clear_thinking_20251015`),keep:o([z(`all`),u({type:z(`thinking_turns`),value:b()})]).optional()}),u({type:z(`compact_20260112`),trigger:u({type:z(`input_tokens`),value:b()}).optional(),pauseAfterCompaction:l().optional(),instructions:C().optional()})]))}).optional()}),Ee=4;function De(e){let t=e?.anthropic;return t?.cacheControl??t?.cache_control}var Oe=class{constructor(){this.breakpointCount=0,this.warnings=[]}getCacheControl(e,t){let n=De(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>Ee){this.warnings.push({type:`unsupported`,feature:`cacheControl breakpoint limit`,details:`Maximum ${Ee} cache breakpoints exceeded (found ${this.breakpointCount}). This breakpoint will be ignored.`});return}return n}}getWarnings(){return this.warnings}},ke=E(()=>K(u({model:C(),maxUses:b().optional(),maxTokens:b().int().min(1024).optional(),caching:u({type:z(`ephemeral`),ttl:o([z(`5m`),z(`1h`)])}).optional()}))),Ae=E(()=>K(c(`type`,[u({type:z(`advisor_result`),text:C(),stopReason:C().optional()}),u({type:z(`advisor_redacted_result`),encryptedContent:C(),stopReason:C().optional()}),u({type:z(`advisor_tool_result_error`),errorCode:C()})]))),je=E(()=>K(u({}).strict())),Me=w({id:`anthropic.advisor_20260301`,inputSchema:je,outputSchema:Ae,supportsDeferredResults:!0}),Ne=e=>Me(e),Pe=E(()=>K(u({maxCharacters:b().optional()}))),Fe=E(()=>K(u({command:J([`view`,`create`,`str_replace`,`insert`]),path:C(),file_text:C().optional(),insert_line:b().int().optional(),new_str:C().optional(),insert_text:C().optional(),old_str:C().optional(),view_range:q(b().int()).optional()}))),Ie=M({id:`anthropic.text_editor_20250728`,inputSchema:Fe}),Le=(e={})=>Ie(e),Re=E(()=>K(u({maxUses:b().optional(),allowedDomains:q(C()).optional(),blockedDomains:q(C()).optional(),userLocation:u({type:z(`approximate`),city:C().optional(),region:C().optional(),country:C().optional(),timezone:C().optional()}).optional()}))),ze=E(()=>K(q(u({url:C(),title:C().nullable(),pageAge:C().nullable(),encryptedContent:C(),type:z(`web_search_result`)})))),Be=E(()=>K(u({query:C()}))),Ve=w({id:`anthropic.web_search_20260209`,inputSchema:Be,outputSchema:ze,supportsDeferredResults:!0}),He=(e={})=>Ve(e),Ue=E(()=>K(u({maxUses:b().optional(),allowedDomains:q(C()).optional(),blockedDomains:q(C()).optional(),userLocation:u({type:z(`approximate`),city:C().optional(),region:C().optional(),country:C().optional(),timezone:C().optional()}).optional()}))),We=E(()=>K(q(u({url:C(),title:C().nullable(),pageAge:C().nullable(),encryptedContent:C(),type:z(`web_search_result`)})))),Ge=E(()=>K(u({query:C()}))),Ke=w({id:`anthropic.web_search_20250305`,inputSchema:Ge,outputSchema:We,supportsDeferredResults:!0}),qe=(e={})=>Ke(e),Je=E(()=>K(u({maxUses:b().optional(),allowedDomains:q(C()).optional(),blockedDomains:q(C()).optional(),citations:u({enabled:l()}).optional(),maxContentTokens:b().optional()}))),Ye=E(()=>K(u({type:z(`web_fetch_result`),url:C(),content:u({type:z(`document`),title:C().nullable(),citations:u({enabled:l()}).optional(),source:o([u({type:z(`base64`),mediaType:z(`application/pdf`),data:C()}),u({type:z(`text`),mediaType:z(`text/plain`),data:C()})])}),retrievedAt:C().nullable()}))),Xe=E(()=>K(u({url:C()}))),Ze=w({id:`anthropic.web_fetch_20260209`,inputSchema:Xe,outputSchema:Ye,supportsDeferredResults:!0}),Qe=(e={})=>Ze(e),$e=E(()=>K(u({maxUses:b().optional(),allowedDomains:q(C()).optional(),blockedDomains:q(C()).optional(),citations:u({enabled:l()}).optional(),maxContentTokens:b().optional()}))),et=E(()=>K(u({type:z(`web_fetch_result`),url:C(),content:u({type:z(`document`),title:C().nullable(),citations:u({enabled:l()}).optional(),source:o([u({type:z(`base64`),mediaType:z(`application/pdf`),data:C()}),u({type:z(`text`),mediaType:z(`text/plain`),data:C()})])}),retrievedAt:C().nullable()}))),tt=E(()=>K(u({url:C()}))),nt=w({id:`anthropic.web_fetch_20250910`,inputSchema:tt,outputSchema:et,supportsDeferredResults:!0}),rt=(e={})=>nt(e);async function it({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 Oe;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 H({value:t.args,schema:Pe});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 H({value:t.args,schema:$e});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 H({value:t.args,schema:Je});d.push({type:`web_fetch_20260209`,name:`web_fetch`,max_uses:e.maxUses,allowed_domains:e.allowedDomains,blocked_domains:e.blockedDomains,citations:e.citations,max_content_tokens:e.maxContentTokens,cache_control:void 0});break}case`anthropic.web_search_20250305`:{let e=await H({value:t.args,schema:Ue});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 H({value:t.args,schema:Re});d.push({type:`web_search_20260209`,name:`web_search`,max_uses:e.maxUses,allowed_domains:e.allowedDomains,blocked_domains:e.blockedDomains,user_location:e.userLocation,cache_control:void 0});break}case`anthropic.tool_search_regex_20251119`:d.push({type:`tool_search_tool_regex_20251119`,name:`tool_search_tool_regex`});break;case`anthropic.tool_search_bm25_20251119`:d.push({type:`tool_search_tool_bm25_20251119`,name:`tool_search_tool_bm25`});break;case`anthropic.advisor_20260301`:{l.add(`advisor-tool-2026-03-01`);let e=await H({value:t.args,schema:ke});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 at({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 ot=E(()=>K(u({type:z(`code_execution_result`),stdout:C(),stderr:C(),return_code:b(),content:q(u({type:z(`code_execution_output`),file_id:C()})).optional().default([])}))),st=E(()=>K(u({code:C()}))),ct=w({id:`anthropic.code_execution_20250522`,inputSchema:st,outputSchema:ot}),lt=(e={})=>ct(e),ut=E(()=>K(c(`type`,[u({type:z(`code_execution_result`),stdout:C(),stderr:C(),return_code:b(),content:q(u({type:z(`code_execution_output`),file_id:C()})).optional().default([])}),u({type:z(`bash_code_execution_result`),content:q(u({type:z(`bash_code_execution_output`),file_id:C()})),stdout:C(),stderr:C(),return_code:b()}),u({type:z(`bash_code_execution_tool_result_error`),error_code:C()}),u({type:z(`text_editor_code_execution_tool_result_error`),error_code:C()}),u({type:z(`text_editor_code_execution_view_result`),content:C(),file_type:C(),num_lines:b().nullable(),start_line:b().nullable(),total_lines:b().nullable()}),u({type:z(`text_editor_code_execution_create_result`),is_file_update:l()}),u({type:z(`text_editor_code_execution_str_replace_result`),lines:q(C()).nullable(),new_lines:b().nullable(),new_start:b().nullable(),old_lines:b().nullable(),old_start:b().nullable()})]))),dt=E(()=>K(c(`type`,[u({type:z(`programmatic-tool-call`),code:C()}),u({type:z(`bash_code_execution`),command:C()}),c(`command`,[u({type:z(`text_editor_code_execution`),command:z(`view`),path:C()}),u({type:z(`text_editor_code_execution`),command:z(`create`),path:C(),file_text:C().nullish()}),u({type:z(`text_editor_code_execution`),command:z(`str_replace`),path:C(),old_str:C(),new_str:C()})])]))),ft=w({id:`anthropic.code_execution_20250825`,inputSchema:dt,outputSchema:ut,supportsDeferredResults:!0}),pt=(e={})=>F(ft(e),{type:`provider`,prepareProviderOptions:e=>{let t=e?.anthropic;return{...e,anthropic:{...t,allowedCallers:[...new Set([...t?.allowedCallers??[],`code_execution_20250825`])]}}}}),mt=E(()=>K(c(`type`,[u({type:z(`code_execution_result`),stdout:C(),stderr:C(),return_code:b(),content:q(u({type:z(`code_execution_output`),file_id:C()})).optional().default([])}),u({type:z(`encrypted_code_execution_result`),encrypted_stdout:C(),stderr:C(),return_code:b(),content:q(u({type:z(`code_execution_output`),file_id:C()})).optional().default([])}),u({type:z(`bash_code_execution_result`),content:q(u({type:z(`bash_code_execution_output`),file_id:C()})),stdout:C(),stderr:C(),return_code:b()}),u({type:z(`bash_code_execution_tool_result_error`),error_code:C()}),u({type:z(`text_editor_code_execution_tool_result_error`),error_code:C()}),u({type:z(`text_editor_code_execution_view_result`),content:C(),file_type:C(),num_lines:b().nullable(),start_line:b().nullable(),total_lines:b().nullable()}),u({type:z(`text_editor_code_execution_create_result`),is_file_update:l()}),u({type:z(`text_editor_code_execution_str_replace_result`),lines:q(C()).nullable(),new_lines:b().nullable(),new_start:b().nullable(),old_lines:b().nullable(),old_start:b().nullable()})]))),ht=E(()=>K(c(`type`,[u({type:z(`programmatic-tool-call`),code:C()}),u({type:z(`bash_code_execution`),command:C()}),c(`command`,[u({type:z(`text_editor_code_execution`),command:z(`view`),path:C()}),u({type:z(`text_editor_code_execution`),command:z(`create`),path:C(),file_text:C().nullish()}),u({type:z(`text_editor_code_execution`),command:z(`str_replace`),path:C(),old_str:C(),new_str:C()})])]))),gt=w({id:`anthropic.code_execution_20260120`,inputSchema:ht,outputSchema:mt,supportsDeferredResults:!0}),_t=(e={})=>F(gt(e),{type:`provider`,prepareProviderOptions:e=>{let t=e?.anthropic;return{...e,anthropic:{...t,allowedCallers:[...new Set([...t?.allowedCallers??[],`code_execution_20260120`])]}}}}),vt=E(()=>K(q(u({type:z(`tool_reference`),toolName:C()})))),yt=E(()=>K(u({pattern:C(),limit:b().optional()}))),bt=w({id:`anthropic.tool_search_regex_20251119`,inputSchema:yt,outputSchema:vt,supportsDeferredResults:!0}),xt=(e={})=>bt(e);function St(e){return typeof e==`string`?new TextDecoder().decode(le(e)):new TextDecoder().decode(e)}function Ct(e){try{if(typeof e==`string`)return ue(e);if(typeof e==`object`&&e)return e}catch{let t=e?.errorCode;return{errorCode:typeof t==`string`?t:`unavailable`}}return{}}async function wt({prompt:e,sendReasoning:t,warnings:n,cacheControlValidator:r,toolNameMapping:a}){let o=new Set,s=Tt(e),c=r||new Oe,l,u=[];async function d(e){return(await k({provider:`anthropic`,providerOptions:e,schema:Ce}))?.citations?.enabled??!1}async function f(e){return(await k({provider:`anthropic`,providerOptions:e,schema:Ce}))?.containerUpload??!1}async function m(e){let t=await k({provider:`anthropic`,providerOptions:e,schema:Ce});return{title:t?.title,context:t?.context}}for(let e=0;e<s.length;e++){let r=s[e],h=e===s.length-1,g=r.type;switch(g){case`system`:{let t=[];for(let{content:e,providerOptions:n}of r.messages){let r=await k({provider:`anthropic`,providerOptions:n,schema:we}),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=ce({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}):_(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 m(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=_(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:U({part:r}),data:V(r.data.data)},cache_control:l});else if(t===`application`&&(r.data.type===`url`?r.mediaType===`application/pdf`:U({part:r})===`application/pdf`)){o.add(`pdfs-2024-09-25`);let t=await d(r.providerOptions),n=await m(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:V(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 m(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:St(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=_(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:U({part:e}),data:V(e.data.data)}};if(U({part:e})===`application/pdf`)return o.add(`pdfs-2024-09-25`),{type:`document`,source:{type:`base64`,media_type:`application/pdf`,data:V(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(p);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:h&&l&&d?o.text.trim():o.text,...t?.citations!=null&&{citations:t.citations},cache_control:f});break}case`reasoning`:if(t){let t=await k({provider:`anthropic`,providerOptions:o.providerOptions,schema:Se});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=Dt(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:Ot(o.input),...t&&{caller:t},cache_control:f});break}case`tool-result`:{let t=a.toProviderToolName(o.toolName),r=Dt(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=ue(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 H({value:t.value,schema:ot});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 H({value:t.value,schema:mt});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 H({value:t.value,schema:ut});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:Ct(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 H({value:t.value,schema:et});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:Ct(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 H({value:t.value,schema:We});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 H({value:t.value,schema:vt})).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 H({value:t.value,schema:Ae});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:Et(e)});break}default:throw Error(`content type: ${g}`)}}return{prompt:{system:l,messages:u},betas:o}}function Tt(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 Et(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 Dt(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 Ot(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:{rawInvalidInput:e}}function kt({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 At=new Set([`date-time`,`time`,`date`,`duration`,`email`,`hostname`,`uri`,`ipv4`,`ipv6`,`uuid`]),jt=[`minimum`,`maximum`,`exclusiveMinimum`,`exclusiveMaximum`,`multipleOf`,`minLength`,`maxLength`,`pattern`,`minItems`,`maxItems`,`uniqueItems`,`minProperties`,`maxProperties`,`not`];function Mt(e){return Nt(e)}function Q(e){return typeof e==`boolean`||!S(e)?e:Nt(e)}function Nt(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`&&At.has(e.format)&&(t.format=e.format);let r=Pt(e);return r!=null&&(t.description=t.description==null?r:`${t.description}
${r}`),t}function Pt(e){let t=jt.flatMap(t=>{let n=e[t];return n==null||n===!1?[]:`${Ft(t)}: ${It(n)}`});return typeof e.format==`string`&&!At.has(e.format)&&t.push(`format: ${e.format}`),t.length===0?void 0:`${t.join(`; `)}.`}function Ft(e){return e.replace(/[A-Z]/g,e=>` ${e.toLowerCase()}`)}function It(e){return typeof e==`string`?e:JSON.stringify(e)}function Lt(e){let t=Rt(e.type);return s({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 Rt(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 Bt(e){return e==null?void 0:{type:e.type,toolId:`tool_id`in e?e.tool_id:void 0}}function $(e){let t=Bt(e);return t==null?{}:{providerMetadata:{anthropic:{caller:t}}}}var Vt=class t{constructor(e,t){this.specificationVersion=`v4`,this.modelId=e,this.config=t,this.generateId=t.generateId??B}static[fe](e){return P({modelId:e.modelId,config:e.config})}static[pe](e){return new t(e.modelId,e.config)}supportsUrl(e){return e.protocol===`https:`}get provider(){return this.config.provider}get providerOptionsName(){let e=this.config.provider,t=e.indexOf(`.`);return t===-1?e:e.substring(0,t)}get supportedUrls(){var e;return(e=this.config).supportedUrls?.call(e)??{}}async getArgs({userSuppliedBetas:e,prompt:t,maxOutputTokens:n,temperature:r,topP:i,topK:a,frequencyPenalty:o,presencePenalty:s,stopSequences:c,responseFormat:l,seed:u,tools:d,toolChoice:f,reasoning:p,providerOptions:m,stream:h}){let g=[];o!=null&&g.push({type:`unsupported`,feature:`frequencyPenalty`}),s!=null&&g.push({type:`unsupported`,feature:`presencePenalty`}),u!=null&&g.push({type:`unsupported`,feature:`seed`}),r!=null&&r>1?(g.push({type:`unsupported`,feature:`temperature`,details:`${r} exceeds anthropic maximum of 1.0. clamped to 1.0`}),r=1):r!=null&&r<0&&(g.push({type:`unsupported`,feature:`temperature`,details:`${r} is below anthropic minimum of 0. clamped to 0`}),r=0),l?.type===`json`&&(l.schema??g.push({type:`unsupported`,feature:`responseFormat`,details:`JSON response format requires a schema. The response format is ignored.`}));let _=this.providerOptionsName,v=await k({provider:`anthropic`,providerOptions:m,schema:Te}),y=_===`anthropic`?null:await k({provider:_,providerOptions:m,schema:Te}),b=y!=null,x=Object.assign({},v??{},y??{}),{maxOutputTokens:S,supportsStructuredOutput:C,supportsAdaptiveThinking:w,rejectsSamplingParameters:T,supportsXhighEffort:E,rejectsThinkingDisabledAboveHighEffort:D,isKnownModel:O}=Ht(this.modelId);!O&&n==null&&g.push({type:`compatibility`,feature:`maxOutputTokens`,details:`The model "${this.modelId}" is unknown. The max output tokens have been limited to ${S}. Set maxOutputTokens explicitly to override this limit.`}),T&&(r!=null&&(g.push({type:`unsupported`,feature:`temperature`,details:`temperature is not supported by ${this.modelId} and will be ignored`}),r=void 0),a!=null&&(g.push({type:`unsupported`,feature:`topK`,details:`topK is not supported by ${this.modelId} and will be ignored`}),a=void 0),i!=null&&(g.push({type:`unsupported`,feature:`topP`,details:`topP is not supported by ${this.modelId} and will be ignored`}),i=void 0));let A=O||this.modelId.includes(`claude-`),j=(this.config.supportsNativeStructuredOutput??!0)&&C,te=(this.config.supportsStrictTools??!0)&&C,M=x?.structuredOutputMode??`auto`,N=M===`outputFormat`||M===`auto`&&j,P=l?.type===`json`&&l.schema!=null&&!N?{type:`function`,name:`json`,description:`Respond with a JSON object.`,inputSchema:l.schema}:void 0;P!=null&&x?.disableParallelToolUse===!1&&g.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 F=x?.contextManagement,I=new Oe,ne=de({tools:d,providerToolNames:{"anthropic.code_execution_20250522":`code_execution`,"anthropic.code_execution_20250825":`code_execution`,"anthropic.code_execution_20260120":`code_execution`,"anthropic.computer_20241022":`computer`,"anthropic.computer_20250124":`computer`,"anthropic.text_editor_20241022":`str_replace_editor`,"anthropic.text_editor_20250124":`str_replace_editor`,"anthropic.text_editor_20250429":`str_replace_based_edit_tool`,"anthropic.text_editor_20250728":`str_replace_based_edit_tool`,"anthropic.bash_20241022":`bash`,"anthropic.bash_20250124":`bash`,"anthropic.memory_20250818":`memory`,"anthropic.web_search_20250305":`web_search`,"anthropic.web_search_20260209":`web_search`,"anthropic.web_fetch_20250910":`web_fetch`,"anthropic.web_fetch_20260209":`web_fetch`,"anthropic.tool_search_regex_20251119":`tool_search_tool_regex`,"anthropic.tool_search_bm25_20251119":`tool_search_tool_bm25`,"anthropic.advisor_20260301":`advisor`}}),{prompt:re,betas:L}=await wt({prompt:t,sendReasoning:x?.sendReasoning??!0,warnings:g,cacheControlValidator:I,toolNameMapping:ne});if(ee(p)&&x?.effort==null){let e=Wt({reasoning:p,supportsAdaptiveThinking:w,supportsXhighEffort:E,maxOutputTokensForModel:S,warnings:g});e!=null&&(x.thinking??=e.thinking,e.effort!=null&&x.thinking?.type!==`disabled`&&(x.effort=e.effort))}D&&x?.thinking?.type===`disabled`&&(x.effort===`xhigh`||x.effort===`max`)&&(g.push({type:`unsupported`,feature:`providerOptions.anthropic.effort`,details:`effort '${x.effort}' is not supported by ${this.modelId} when thinking is disabled. The effort has been lowered to 'high'.`}),x.effort=`high`);let R=x?.thinking?.type,z=R===`enabled`||R===`adaptive`,B=x?.thinking!=null&&`blockBinding`in x.thinking?x.thinking.blockBinding:void 0,ie=z||R===`disabled`||B!=null,V=R===`enabled`?x?.thinking?.budgetTokens:void 0,ae=R===`adaptive`?x?.thinking?.display:void 0,H=n??S,U={model:this.modelId,max_tokens:H,temperature:r,top_k:a,top_p:i,stop_sequences:c,...ie&&{thinking:{...R!=null&&{type:R},...V!=null&&{budget_tokens:V},...ae!=null&&{display:ae},...B!=null&&{block_binding:{prefix_mismatch_behavior:B.prefixMismatchBehavior}}}},...(x?.effort||x?.taskBudget||N&&l?.type===`json`&&l.schema!=null)&&{output_config:{...x?.effort&&{effort:x.effort},...x?.taskBudget&&{task_budget:{type:x.taskBudget.type,total:x.taskBudget.total,...x.taskBudget.remaining!=null&&{remaining:x.taskBudget.remaining}}},...N&&l?.type===`json`&&l.schema!=null&&{format:{type:`json_schema`,schema:Mt(l.schema)}}}},...x?.speed&&{speed:x.speed},...x?.serviceTier&&{service_tier:x.serviceTier},...x?.inferenceGeo&&{inference_geo:x.inferenceGeo},...x?.fallbacks!=null&&(x.fallbacks==="default"||x.fallbacks.length>0)&&{fallbacks:x.fallbacks},...x?.cacheControl&&{cache_control:x.cacheControl},...x?.metadata?.userId!=null&&{metadata:{user_id:x.metadata.userId}},...x?.mcpServers&&x.mcpServers.length>0&&{mcp_servers:x.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}))},...x?.container&&{container:x.container.skills&&x.container.skills.length>0?{id:x.container.id,skills:x.container.skills.map(e=>({type:e.type,skill_id:e.type===`custom`?ce({reference:e.providerReference,provider:`anthropic`}):e.skillId,version:e.version}))}:x.container.id},system:re.system,messages:re.messages,...F&&{context_management:{edits:F.edits.map(e=>{let t=e.type;switch(t){case`clear_tool_uses_20250919`:return{type:e.type,...e.trigger!==void 0&&{trigger:e.trigger},...e.keep!==void 0&&{keep:e.keep},...e.clearAtLeast!==void 0&&{clear_at_least:e.clearAtLeast},...e.clearToolInputs!==void 0&&{clear_tool_inputs:e.clearToolInputs},...e.excludeTools!==void 0&&{exclude_tools:e.excludeTools}};case`clear_thinking_20251015`:return{type:e.type,...e.keep!==void 0&&{keep:e.keep}};case`compact_20260112`:return{type:e.type,...e.trigger!==void 0&&{trigger:e.trigger},...e.pauseAfterCompaction!==void 0&&{pause_after_compaction:e.pauseAfterCompaction},...e.instructions!==void 0&&{instructions:e.instructions}};default:g.push({type:`other`,message:`Unknown context management strategy: ${t}`});return}}).filter(e=>e!==void 0)}}};z?(R===`enabled`&&V==null&&(g.push({type:`compatibility`,feature:`extended thinking`,details:`thinking budget is required when thinking is enabled. using default budget of 1024 tokens.`}),U.thinking={type:`enabled`,budget_tokens:1024},V=1024),U.temperature!=null&&(U.temperature=void 0,g.push({type:`unsupported`,feature:`temperature`,details:`temperature is not supported when thinking is enabled`})),a!=null&&(U.top_k=void 0,g.push({type:`unsupported`,feature:`topK`,details:`topK is not supported when thinking is enabled`})),i!=null&&(U.top_p=void 0,g.push({type:`unsupported`,feature:`topP`,details:`topP is not supported when thinking is enabled`})),U.max_tokens=H+(V??0)):A&&i!=null&&r!=null&&(g.push({type:`unsupported`,feature:`topP`,details:`topP is not supported when temperature is set. topP is ignored.`}),U.top_p=void 0),O&&U.max_tokens>S&&(n!=null&&g.push({type:`unsupported`,feature:`maxOutputTokens`,details:`${U.max_tokens} (maxOutputTokens + thinkingBudget) is greater than ${this.modelId} ${S} max output tokens. The max output tokens have been limited to ${S}.`}),U.max_tokens=S),x?.mcpServers&&x.mcpServers.length>0&&L.add(`mcp-client-2025-04-04`),F&&(L.add(`context-management-2025-06-27`),F.edits.some(e=>e.type===`compact_20260112`)&&L.add(`compact-2026-01-12`)),x?.container&&x.container.skills&&x.container.skills.length>0&&(L.add(`code-execution-2025-08-25`),L.add(`skills-2025-10-02`),L.add(`files-api-2025-04-14`),d?.some(e=>e.type===`provider`&&(e.id===`anthropic.code_execution_20250825`||e.id===`anthropic.code_execution_20260120`))||g.push({type:`other`,message:`code execution tool is required when using skills`})),x?.taskBudget&&L.add(`task-budgets-2026-03-13`),x?.speed===`fast`&&L.add(`fast-mode-2026-02-01`),ae===`updates`&&L.add(`thinking-display-updates-2026-08-18`),B!=null&&L.add(`thinking-binding-controls-2026-08-01`),x?.fallbacks==="default"?L.add(`server-side-fallback-2026-07-01`):x?.fallbacks&&x.fallbacks.length>0&&L.add(`server-side-fallback-2026-06-01`);let oe=h&&(x?.toolStreaming??!0),{tools:W,toolChoice:se,toolWarnings:le,betas:ue}=await it(P==null?{tools:d??[],toolChoice:f,disableParallelToolUse:x?.disableParallelToolUse,cacheControlValidator:I,supportsStructuredOutput:j,supportsStrictTools:te,defaultEagerInputStreaming:oe}:{tools:[...d??[],P],toolChoice:{type:`required`},disableParallelToolUse:!0,cacheControlValidator:I,supportsStructuredOutput:!1,supportsStrictTools:te,defaultEagerInputStreaming:oe}),G=I.getWarnings();return{args:{...U,tools:W,tool_choice:se,stream:h===!0||void 0},warnings:[...g,...le,...G],betas:new Set([...L,...ue,...e,...x?.anthropicBeta??[]]),usesJsonResponseTool:P!=null,toolNameMapping:ne,providerOptionsName:_,usedCustomProviderKey:b}}async getHeaders({betas:e,headers:t}){return R(this.config.headers?await G(this.config.headers):void 0,t,e.size>0?{"anthropic-beta":Array.from(e).join(`,`)}:{})}async getBetasFromHeaders(e){let t=(this.config.headers?await G(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=Ut(t.tools),{responseHeaders:u,value:d,rawValue:f}=await x({url:this.buildRequestUrl(!1),headers:await this.getHeaders({betas:r,headers:e.headers}),body:this.transformRequestBody(t,r),failedResponseHandler:X,successfulResponseHandler:j(be),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:kt({finishReason:d.stop_reason,isJsonResponseFromTool:g}),raw:d.stop_reason??void 0},usage:at({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=Kt(d.stop_details),t={usage:d.usage,stopSequence:d.stop_sequence??null,...e==null?{}:{stopDetails:e},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:Gt(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=Ut(r.tools),f=this.buildRequestUrl(!0),{responseHeaders:p,value:m}=await x({url:f,headers:await this.getHeaders({betas:a,headers:t.headers}),body:this.transformRequestBody(r,a),failedResponseHandler:X,successfulResponseHandler:ae(xe),abortSignal:t.abortSignal,fetch:this.config.fetch}),g={unified:`other`,raw:void 0},_={input_tokens:0,output_tokens:0,cache_creation_input_tokens:0,cache_read_input_tokens:0,iterations:null},v={},y={},ee={},b=null,S,C=null,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;v[i.index]={type:`text`,citations:[]},r.enqueue({type:`text-start`,id:String(i.index)});return;case`thinking`:v[i.index]={type:`reasoning`},r.enqueue({type:`reasoning-start`,id:String(i.index)});return;case`redacted_thinking`:v[i.index]={type:`reasoning`},r.enqueue({type:`reasoning-start`,id:String(i.index),providerMetadata:{anthropic:{redactedData:e.data}}});return;case`compaction`:v[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,v[i.index]={type:`text`,citations:[]},r.enqueue({type:`text-start`,id:String(i.index)});else{let t=Bt(e.caller),n=e.input&&Object.keys(e.input).length>0?JSON.stringify(e.input):``;v[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=Bt(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):``;v[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`){ee[e.id]=e.name;let n=s.toCustomToolName(e.name);v[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`);v[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=ee[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`:y[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(y[e.id]);return;case`mcp_tool_result`:r.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:y[e.tool_use_id].toolName,isError:e.is_error,result:e.content,dynamic:!0,providerMetadata:y[e.tool_use_id].providerMetadata});return;default:throw Error(`Unsupported content block type: ${t}`)}}case`content_block_stop`:if(v[i.index]!=null){let e=v[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=ue(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 v[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=v[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=v[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,_.input_tokens=i.message.usage.input_tokens,_.cache_read_input_tokens=i.message.usage.cache_read_input_tokens??0,_.cache_creation_input_tokens=i.message.usage.cache_creation_input_tokens??0,S={...i.message.usage},i.message.container!=null&&(T={expiresAt:i.message.container.expires_at,id:i.message.container.id,skills:null}),i.message.stop_reason!=null&&(g={unified:kt({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=Bt(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&&_.input_tokens!==i.usage.input_tokens&&(_.input_tokens=i.usage.input_tokens),_.output_tokens=i.usage.output_tokens,i.usage.output_tokens_details!=null&&(_.output_tokens_details=i.usage.output_tokens_details),i.usage.cache_read_input_tokens!=null&&(_.cache_read_input_tokens=i.usage.cache_read_input_tokens),i.usage.cache_creation_input_tokens!=null&&(_.cache_creation_input_tokens=i.usage.cache_creation_input_tokens),i.usage.iterations!=null&&(_.iterations=i.usage.iterations),g={unified:kt({finishReason:i.delta.stop_reason,isJsonResponseFromTool:E}),raw:i.delta.stop_reason??void 0},C=i.delta.stop_sequence??null,w=Kt(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=Gt(i.context_management)),S={...S,...i.usage};return;case`message_stop`:{D=!1,O=void 0;let e={usage:S??null,stopSequence:C,...w==null?{}:{stopDetails:w},iterations:_.iterations?_.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:g,usage:at({usage:_,rawUsage:S}),providerMetadata:t});return}case`error`:r.enqueue({type:`error`,error:Lt(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 h(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 Ht(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 Ut(e){if(!e)return!1;let t=!1,n=!1;for(let r of e){if(`type`in r&&(r.type===`web_fetch_20260209`||r.type===`web_search_20260209`)){t=!0;continue}if(`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 Wt({reasoning:e,supportsAdaptiveThinking:t,supportsXhighEffort:n,maxOutputTokensForModel:r,warnings:i}){if(!ee(e))return;if(e===`none`)return{thinking:{type:`disabled`}};if(t)return{thinking:{type:`adaptive`,display:`summarized`},effort:d({reasoning:e,effortMap:{minimal:`low`,low:`low`,medium:`medium`,high:`high`,xhigh:n?`xhigh`:`max`},warnings:i})};let a=O({reasoning:e,maxOutputTokens:r,maxReasoningBudget:r,warnings:i});if(a!=null)return{thinking:{type:`enabled`,budgetTokens:a}}}function Gt(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 Kt(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 qt=/^[A-Za-z0-9_-]{1,64}$/,Jt=Te.pick({anthropicBeta:!0}),Yt=E(()=>K(u({id:C(),type:z(`message_batch`),processing_status:C(),request_counts:u({processing:b(),succeeded:b(),errored:b(),canceled:b(),expired:b()}),created_at:C(),expires_at:C(),archived_at:C().nullish(),cancel_initiated_at:C().nullish(),ended_at:C().nullish(),results_url:C().nullish()}))),Xt=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`]),Zt=E(()=>K(c(`type`,[u({type:z(`succeeded`),message:D()}),u({type:z(`errored`),error:u({type:z(`error`),error:u({type:C(),message:C()}),request_id:C().nullish()})}),u({type:z(`canceled`)}),u({type:z(`expired`)})]))),Qt=E(()=>K(u({custom_id:C(),result:D()}))),$t=class e extends Vt{static[fe](e){return Vt[fe](e)}static[pe](t){return new e(t.modelId,t.config)}constructor(e,t){super(e,t)}async experimental_doStartBatch({requests:e,providerOptions:t,headers:n,abortSignal:r,webhookUrl:a}){tn(e);let o=new Set(await en({provider:this.config.provider,providerOptions:t})),s=new Set(o),c=[],l=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 en({provider:this.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 startTextBatch instead.`});let e=await this.getArgs({...t.options,stream:!1,userSuppliedBetas:new Set(o)});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=this.transformRequestBody(e.args,e.betas);nn({body:r,requestId:t.id}),c.push({custom_id:t.id,params:r});for(let t of e.betas)s.add(t);for(let n of e.warnings)l.push({requestId:t.id,warning:n})}let{value:u}=await x({url:this.getBatchUrl(``),headers:await this.getStartBatchHeaders({betas:s,headers:n}),body:{requests:c},failedResponseHandler:X,successfulResponseHandler:j(Yt),abortSignal:r,fetch:this.config.fetch});return{batchId:u.id,...rn(u),warnings:l}}async experimental_doGetBatchStatus(e){return rn(await this.retrieveBatch(e))}async experimental_doGetBatchResults(e){let r=await this.retrieveBatch(e);if(rn(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 a({url:r.results_url,validateUrl:!0,credentialedOrigin:this.config.baseURL,trustedOrigin:this.config.baseURL,headers:await this.getBatchHeaders(e.headers),failedResponseHandler:X,successfulResponseHandler:ne(Qt),abortSignal:e.abortSignal,fetch:this.config.fetch});return oe(this.iterateBatchResults(i))}async retrieveBatch(e){let{value:t}=await a({url:this.getBatchUrl(`/${encodeURIComponent(e.batchId)}`),validateUrl:!1,headers:await this.getBatchHeaders(e.headers),failedResponseHandler:X,successfulResponseHandler:j(Yt),abortSignal:e.abortSignal,fetch:this.config.fetch});return t}async*iterateBatchResults(e){for await(let t of e)yield await sn(t,this.generateId)}getBatchUrl(e){return`${this.config.baseURL}/messages/batches${e}`}async getStartBatchHeaders({betas:e,headers:t}){return R(m(await this.getBatchHeaders(t)),{"anthropic-beta":e.size>0?Array.from(e).join(`,`):void 0})}async getBatchHeaders(e){return R(this.config.headers?await G(this.config.headers):void 0,e)}};async function en({provider:e,providerOptions:t}){let n=e.split(`.`)[0],r=await k({provider:`anthropic`,providerOptions:t,schema:Jt}),i=n===`anthropic`?void 0:await k({provider:n,providerOptions:t,schema:Jt});return Object.assign({},r??{},i??{}).anthropicBeta??[]}function tn(e){let n=new Set;for(let r of e){if(!qt.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 nn({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 rn(e){let t=on(e.request_counts);return{status:an(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 an(e){switch(e){case`ended`:return`completed`;default:return`pending`}}function on(e){return se({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 sn(e,t){let n=await W({value:e.result,schema:Zt});if(!n.success)return cn(e.custom_id);let r=n.value;switch(r.type){case`canceled`:return{id:e.custom_id,status:`cancelled`};case`expired`:return{id:e.custom_id,status:`expired`};case`errored`:{let t=r.error.request_id;return{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 ln(r.message);return n==null?cn(e.custom_id):{id:e.custom_id,status:`succeeded`,result:un(n,t)}}}}function cn(e){return{id:e,status:`failed`,error:{message:`Anthropic returned an invalid Message batch result.`,code:`invalid_response`}}}async function ln(e){let t=await W({value:e,schema:be});if(t.success)return t.value;if(!S(e)||!Array.isArray(e.content))return;let n=[];for(let t of e.content){let r=await W({value:{...e,content:[t]},schema:be});if(r.success){let[e]=r.value.content;e!=null&&n.push(e)}else if(!S(t)||typeof t.type!=`string`||Xt.has(t.type))return}let r=await W({value:{...e,content:n},schema:be});return r.success?r.value:void 0}function un(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:kt({finishReason:e.stop_reason}),raw:e.stop_reason??void 0},usage:at({usage:e.usage}),response:{id:e.id??void 0,modelId:e.model??void 0},warnings:[],providerMetadata:{anthropic:fn(e)}}}function dn(e){return e==null?{}:{providerMetadata:{anthropic:{caller:{type:e.type,toolId:e.tool_id}}}}}function fn(e){let t=mn(e.stop_details);return{usage:e.usage,stopSequence:e.stop_sequence??null,...t==null?{}:{stopDetails:t},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:pn(e.context_management)}}function pn(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 mn(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 hn=E(()=>K(u({command:C(),restart:l().optional()}))),gn=M({id:`anthropic.bash_20241022`,inputSchema:hn});function _n(e={}){let{execute:t,...n}=e;return gn(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 vn=E(()=>K(u({command:C(),restart:l().optional()}))),yn=M({id:`anthropic.bash_20250124`,inputSchema:vn});function bn(e={}){let{execute:t,...n}=e;return yn(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 xn=E(()=>K(u({action:J([`key`,`type`,`mouse_move`,`left_click`,`left_click_drag`,`right_click`,`middle_click`,`double_click`,`screenshot`,`cursor_position`]),coordinate:q(b().int()).optional(),text:C().optional()}))),Sn=M({id:`anthropic.computer_20241022`,inputSchema:xn}),Cn=E(()=>K(u({action:J([`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:Y([b().int(),b().int()]).optional(),duration:b().optional(),scroll_amount:b().optional(),scroll_direction:J([`up`,`down`,`left`,`right`]).optional(),start_coordinate:Y([b().int(),b().int()]).optional(),text:C().optional()}))),wn=M({id:`anthropic.computer_20250124`,inputSchema:Cn}),Tn=E(()=>K(u({action:J([`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:Y([b().int(),b().int()]).optional(),duration:b().optional(),region:Y([b().int(),b().int(),b().int(),b().int()]).optional(),scroll_amount:b().optional(),scroll_direction:J([`up`,`down`,`left`,`right`]).optional(),start_coordinate:Y([b().int(),b().int()]).optional(),text:C().optional()}))),En=M({id:`anthropic.computer_20251124`,inputSchema:Tn}),Dn=E(()=>K(c(`command`,[u({command:z(`view`),path:C(),view_range:Y([b(),b()]).optional()}),u({command:z(`create`),path:C(),file_text:C()}),u({command:z(`str_replace`),path:C(),old_str:C(),new_str:C()}),u({command:z(`insert`),path:C(),insert_line:b(),insert_text:C()}),u({command:z(`delete`),path:C()}),u({command:z(`rename`),old_path:C(),new_path:C()})]))),On=M({id:`anthropic.memory_20250818`,inputSchema:Dn}),kn=E(()=>K(u({command:J([`view`,`create`,`str_replace`,`insert`,`undo_edit`]),path:C(),file_text:C().optional(),insert_line:b().int().optional(),new_str:C().optional(),insert_text:C().optional(),old_str:C().optional(),view_range:q(b().int()).optional()}))),An=M({id:`anthropic.text_editor_20241022`,inputSchema:kn}),jn=E(()=>K(u({command:J([`view`,`create`,`str_replace`,`insert`,`undo_edit`]),path:C(),file_text:C().optional(),insert_line:b().int().optional(),new_str:C().optional(),insert_text:C().optional(),old_str:C().optional(),view_range:q(b().int()).optional()}))),Mn=M({id:`anthropic.text_editor_20250124`,inputSchema:jn}),Nn=E(()=>K(u({command:J([`view`,`create`,`str_replace`,`insert`]),path:C(),file_text:C().optional(),insert_line:b().int().optional(),new_str:C().optional(),insert_text:C().optional(),old_str:C().optional(),view_range:q(b().int()).optional()}))),Pn=M({id:`anthropic.text_editor_20250429`,inputSchema:Nn}),Fn=E(()=>K(q(u({type:z(`tool_reference`),toolName:C()})))),In=E(()=>K(u({query:C(),limit:b().optional()}))),Ln=w({id:`anthropic.tool_search_bm25_20251119`,inputSchema:In,outputSchema:Fn,supportsDeferredResults:!0}),Rn={advisor_20260301:Ne,bash_20241022:_n,bash_20250124:bn,codeExecution_20250522:lt,codeExecution_20250825:pt,codeExecution_20260120:_t,computer_20241022:Sn,computer_20250124:wn,computer_20251124:En,memory_20250818:On,textEditor_20241022:An,textEditor_20250124:Mn,textEditor_20250429:Pn,textEditor_20250728:Le,webFetch_20250910:rt,webFetch_20260209:Qe,webSearch_20250305:qe,webSearch_20260209:He,toolSearchRegex_20251119:xt,toolSearchBm25_20251119:(e={})=>Ln(e)},zn=E(()=>K(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()})));E(()=>K(u({data:q(u({version:C()}))})));var Bn=E(()=>K(u({type:C(),skill_id:C(),name:C().nullish(),description:C().nullish()})));function Vn(e){let t=encodeURIComponent(e);return t===`.`?`%252E`:t===`..`?`%252E%252E`:t}var Hn=class{constructor(e){this.config=e,this.specificationVersion=`v4`}get provider(){return this.config.provider}async getHeaders(){return R(await G(this.config.headers),{"anthropic-beta":`skills-2025-10-02`})}async fetchVersionMetadata({skillId:e,version:t,headers:n}){let{value:r}=await a({url:`${this.config.baseURL}/skills/${Vn(e)}/versions/${Vn(t)}`,validateUrl:!1,headers:n,failedResponseHandler:X,successfulResponseHandler:j(Bn),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=N(t.data);n.append(`files[]`,new Blob([e]),t.path)}let r=await this.getHeaders(),{value:i}=await A({url:`${this.config.baseURL}/skills`,headers:r,formData:n,failedResponseHandler:X,successfulResponseHandler:j(zn),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}}},Un=`4.0.49`,Wn=`https://api.anthropic.com`,Gn=`${Wn}/v1`;function Kn(e){let t=te(I(e));return t===Wn?Gn:t}function qn(e={}){let n=Kn(T({settingValue:e.baseURL,environmentVariableName:`ANTHROPIC_BASE_URL`}))??Gn,i=e.name??`anthropic.messages`;if(e.apiKey&&e.authToken)throw new t({argument:`apiKey/authToken`,message:`Both apiKey and authToken were provided. Please use only one authentication method.`});let a=()=>{let t=e.authToken?{Authorization:`Bearer ${e.authToken}`}:{"x-api-key":f({apiKey:e.apiKey,environmentVariableName:`ANTHROPIC_API_KEY`,description:`Anthropic`})};return re({"anthropic-version":`2023-06-01`,...t,...e.headers},`ai-sdk/anthropic/${Un}`)},o=t=>new $t(t,{provider:i,baseURL:n,headers:a,fetch:e.fetch,generateId:e.generateId??B,supportedUrls:()=>({"image/*":[/^https?:\/\/.*$/],"application/pdf":[/^https?:\/\/.*$/]})}),s=()=>new Hn({provider:`${i.replace(`.messages`,``)}.skills`,baseURL:n,headers:a,fetch:e.fetch}),c=function(e){if(new.target)throw Error(`The Anthropic model function cannot be called with the new keyword.`);return o(e)};return c.specificationVersion=`v4`,c.languageModel=o,c.chat=o,c.messages=o,c.embeddingModel=e=>{throw new r({modelId:e,modelType:`embeddingModel`})},c.textEmbeddingModel=c.embeddingModel,c.imageModel=e=>{throw new r({modelId:e,modelType:`imageModel`})},c.files=()=>new ge({provider:i,baseURL:n,headers:a,fetch:e.fetch}),c.skills=s,c.tools=Rn,c}var Jn=qn();function Yn({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{Un as VERSION,Jn as anthropic,qn as createAnthropic,Yn as forwardAnthropicContainerIdFromLastStep};