murmur-rag 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -17
- package/dist/cdn/{anthropic-ynz7717b.js → anthropic-tw416spz.js} +2 -2
- package/dist/cdn/chunk-xyp6nm65.js +1 -0
- package/dist/cdn/{embed-xtkxyrpe.js → embed-3am76qfd.js} +6 -6
- package/dist/cdn/embed-50pfy67v.js +83 -0
- package/dist/cdn/{embed-n5nzhrf2.js → embed-cx1r66ch.js} +6 -6
- package/dist/cdn/{embed-7pk91zq8.js → embed-g0p6yc29.js} +2 -2
- package/dist/cdn/{embed-krrjjyf5.js → embed-q81wdr1z.js} +4 -4
- package/dist/cdn/embed-rjpq8psf.js +10 -0
- package/dist/cdn/{embed-0m8xctqy.js → embed-yz75savs.js} +3 -3
- package/dist/cdn/{google-k5kwa54v.js → google-556tp13p.js} +8 -8
- package/dist/cdn/index-8r44b2wt.js +1 -0
- package/dist/cdn/index-a5j4aat5.js +1 -0
- package/dist/cdn/index-ft8r539a.js +1 -0
- package/dist/cdn/index-pjxy71n5.js +1 -0
- package/dist/cdn/{index-gyd02jvt.js → index-qpy1k923.js} +2 -2
- package/dist/cdn/{mistral-p2qcnn42.js → mistral-25w1nsx5.js} +2 -2
- package/dist/cdn/{murmur-d6t6cjc7.js → murmur-1a55et82.js} +3 -3
- package/dist/cdn/murmur.js +7 -7
- package/dist/cdn/{openai-d3q1d6cz.js → openai-bjrbem49.js} +12 -12
- package/dist/cdn/{openai-compatible-psnkrpxy.js → openai-compatible-sg25g0vj.js} +6 -6
- package/dist/cdn/retriever-06ybegpd.js +1 -0
- package/dist/cdn/{transformers.web-xn16v7pz.js → transformers.web-49m0ht4a.js} +7 -7
- package/dist/lib/chunks/{index-y3v46yjp.js → index-4ftk20yq.js} +143 -39
- package/dist/lib/embed.js +8 -2
- package/dist/lib/llm/index.js +23 -0
- package/dist/lib/local/index.js +38 -2
- package/dist/lib/widget/index.js +2 -2
- package/dist/types/llm/index.d.ts +8 -0
- package/dist/types/local/index.d.ts +12 -0
- package/dist/types/widget/element.d.ts +4 -0
- package/dist/types/widget/i18n.d.ts +1 -0
- package/dist/types/widget/session.d.ts +43 -7
- package/dist/types/widget/styles.d.ts +1 -1
- package/package.json +1 -1
- package/dist/cdn/chunk-hpx6rpea.js +0 -1
- package/dist/cdn/embed-dbkjhg16.js +0 -83
- package/dist/cdn/embed-rp9gb1qq.js +0 -10
- package/dist/cdn/index-db4ne93m.js +0 -1
- package/dist/cdn/index-qc8kgsdt.js +0 -1
- package/dist/cdn/index-t0qn2m4r.js +0 -1
- package/dist/cdn/index-y0faj89r.js +0 -1
- package/dist/cdn/retriever-6qvn2maq.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{oe,qt,Be,ht,gt}from"./embed-rp9gb1qq.js";import{et}from"./embed-0m8xctqy.js";import{w,b,P,Ge,u,e,r,c,v,Ae,o,t,U,l,f,ce,y,bn,i,n,G,k,T,d,ae,N,M,we,le,xe,st,qe,F,z,de,C,R,Fe,L,he,pe,W,Se,it,ge,Q,a,s,x,j,h,g,ne,re,S,_,O,H,I,D,p,_e,E,pt,Y,Ke}from"./embed-dbkjhg16.js";var Io=a(()=>s(t({type:n("error"),error:t({type:e(),message:e()})}))),ct=I({errorSchema:Io,errorToMessage:(m)=>m.error.message}),Ao=a(()=>s(t({id:e(),type:n("file"),filename:e(),mime_type:e(),size_bytes:r(),created_at:e(),downloadable:c().nullish()}))),Ro=class{get provider(){return this.config.provider}constructor(m){this.config=m,this.specificationVersion="v4"}async uploadFile({data:m,mediaType:A,filename:B,abortSignal:V,headers:me}){let Ne=we(m),K=new Blob([Ne],{type:A}),ie=new FormData;if(B!=null)ie.append("file",K,B);else ie.append("file",K);let{value:se}=await ne({url:`${this.config.baseURL}/files`,headers:d(await _(this.config.headers),{"anthropic-beta":"files-api-2025-04-14"},me),formData:ie,failedResponseHandler:ct,successfulResponseHandler:p(Ao),abortSignal:V,fetch:this.config.fetch});return{warnings:[],providerReference:{anthropic:se.id},mediaType:se.mime_type??A,filename:se.filename??B,providerMetadata:{anthropic:{filename:se.filename,mimeType:se.mime_type,sizeBytes:se.size_bytes,createdAt:se.created_at,...se.downloadable!=null?{downloadable:se.downloadable}:{}}}}}};function Bt(m,A){if(m.type==="web_search_result_location"||m.type==="search_result_location"){let V=m.type==="web_search_result_location"?m.url:m.source;return{source:{type:"source",sourceType:"url",id:V,url:V,title:m.title??void 0,providerMetadata:{anthropic:{...m}}},citedText:m.cited_text}}let B=A[m.document_index];return{source:{type:"source",sourceType:"document",id:m.file_id??String(m.document_index),mediaType:B?.mediaType??"text/plain",title:m.document_title??B?.title??`Document ${m.document_index}`,filename:B?.filename,providerMetadata:{anthropic:{...m}}},citedText:m.cited_text}}var Ut=()=>t({type:n("fallback"),from:t({model:e()}),to:t({model:e()})}),Bo=a(()=>s(Ut())),ao=()=>t({type:e(),category:e().nullish(),explanation:e().nullish(),recommended_model:e().nullish()}),io=()=>t({type:e(),status:t({type:e(),tool_uses:y(e(),t({type:e(),outcome:e().nullish(),explanation:e().nullish()})).nullish()})}),ut=()=>l([t({type:n("code_execution_20250825"),tool_id:e()}),t({type:n("code_execution_20260120"),tool_id:e()}),t({type:n("direct")})]),so=()=>f("type",[t({type:n("web_search_result_location"),cited_text:e(),url:e(),title:e().nullable(),encrypted_index:e()}),t({type:n("page_location"),cited_text:e(),document_index:r(),document_title:e().nullable(),start_page_number:r(),end_page_number:r(),file_id:e().nullish()}),t({type:n("char_location"),cited_text:e(),document_index:r(),document_title:e().nullable(),start_char_index:r(),end_char_index:r(),file_id:e().nullish()}),t({type:n("content_block_location"),cited_text:e(),document_index:r(),document_title:e().nullable(),start_block_index:r(),end_block_index:r(),file_id:e().nullable()}),t({type:n("search_result_location"),cited_text:e(),search_result_index:r(),source:e(),title:e().nullable(),start_block_index:r(),end_block_index:r()})]),lo=()=>l([e(),o(l([e(),t({type:n("text"),text:e(),citations:o(G()).nullable().optional()})]))]),Et=()=>t({type:e(),path:e(),reason:e()}),Ct=a(()=>s(t({type:n("message"),id:e().nullish(),model:e().nullish(),content:o(f("type",[t({type:n("text"),text:e(),citations:o(so()).nullable().optional()}),t({type:n("thinking"),thinking:e(),signature:e()}),t({type:n("redacted_thinking"),data:e()}),t({type:n("compaction"),content:e().nullish(),signature:e().nullish()}),t({type:n("tool_use"),id:e(),name:e(),input:v(),caller:ut().optional(),toolset_name:e().nullish()}),t({type:n("server_tool_use"),id:e(),name:e(),input:y(e(),v()).nullish(),caller:ut().optional()}),t({type:n("mcp_tool_use"),id:e(),name:e(),input:v(),server_name:e()}),t({type:n("mcp_tool_result"),tool_use_id:e(),is_error:c(),content:lo()}),t({type:n("web_fetch_tool_result"),tool_use_id:e(),caller:ut().optional(),content:l([t({type:n("web_fetch_result"),url:e(),retrieved_at:e().nullable(),content:t({type:n("document"),title:e().nullable(),citations:t({enabled:c()}).optional(),source:l([t({type:n("base64"),media_type:n("application/pdf"),data:e()}),t({type:n("text"),media_type:n("text/plain"),data:e()})])})}),t({type:n("web_fetch_tool_result_error"),error_code:e()})])}),t({type:n("web_search_tool_result"),tool_use_id:e(),caller:ut().optional(),content:l([o(t({type:n("web_search_result"),url:e(),title:e().nullable(),encrypted_content:e(),page_age:e().nullish()})),t({type:n("web_search_tool_result_error"),error_code:e()})])}),t({type:n("code_execution_tool_result"),tool_use_id:e(),content:l([t({type:n("code_execution_result"),stdout:e(),stderr:e(),return_code:r(),content:o(t({type:n("code_execution_output"),file_id:e()})).optional().default([])}),t({type:n("encrypted_code_execution_result"),encrypted_stdout:e(),stderr:e(),return_code:r(),content:o(t({type:n("code_execution_output"),file_id:e()})).optional().default([])}),t({type:n("code_execution_tool_result_error"),error_code:e()})])}),t({type:n("bash_code_execution_tool_result"),tool_use_id:e(),content:f("type",[t({type:n("bash_code_execution_result"),content:o(t({type:n("bash_code_execution_output"),file_id:e()})),stdout:e(),stderr:e(),return_code:r()}),t({type:n("bash_code_execution_tool_result_error"),error_code:e()})])}),t({type:n("text_editor_code_execution_tool_result"),tool_use_id:e(),content:f("type",[t({type:n("text_editor_code_execution_tool_result_error"),error_code:e()}),t({type:n("text_editor_code_execution_view_result"),content:e(),file_type:e(),num_lines:r().nullable(),start_line:r().nullable(),total_lines:r().nullable()}),t({type:n("text_editor_code_execution_create_result"),is_file_update:c()}),t({type:n("text_editor_code_execution_str_replace_result"),lines:o(e()).nullable(),new_lines:r().nullable(),new_start:r().nullable(),old_lines:r().nullable(),old_start:r().nullable()})])}),t({type:n("tool_search_tool_result"),tool_use_id:e(),content:l([t({type:n("tool_search_tool_search_result"),tool_references:o(t({type:n("tool_reference"),tool_name:e()}))}),t({type:n("tool_search_tool_result_error"),error_code:e()})])}),t({type:n("container_upload"),file_id:e()}),t({type:n("advisor_tool_result"),tool_use_id:e(),content:f("type",[t({type:n("advisor_result"),text:e(),stop_reason:e().nullish()}),t({type:n("advisor_redacted_result"),encrypted_content:e(),stop_reason:e().nullish()}),t({type:n("advisor_tool_result_error"),error_code:e()})])}),Ut()])),stop_reason:e().nullish(),stop_sequence:e().nullish(),stop_details:ao().nullish(),input_transformations:o(Et()).nullish(),safeguard_results:o(io()).nullish(),usage:U({input_tokens:r(),output_tokens:r(),output_tokens_details:t({thinking_tokens:r().nullish()}).nullish(),cache_creation_input_tokens:r().nullish(),cache_read_input_tokens:r().nullish(),iterations:o(t({type:l([n("compaction"),n("message"),n("advisor_message"),n("fallback_message")]),model:e().nullish(),input_tokens:r(),output_tokens:r(),cache_creation_input_tokens:r().nullish(),cache_read_input_tokens:r().nullish()})).nullish()}),container:t({expires_at:e(),id:e(),skills:o(t({type:l([n("anthropic"),n("custom")]),skill_id:e(),version:e()})).nullish()}).nullish(),context_management:t({applied_edits:o(l([t({type:n("clear_tool_uses_20250919"),cleared_tool_uses:r(),cleared_input_tokens:r()}),t({type:n("clear_thinking_20251015"),cleared_thinking_turns:r(),cleared_input_tokens:r()}),t({type:n("compact_20260112")})]))}).nullish()}))),Eo=a(()=>s(f("type",[t({type:n("message_start"),message:t({id:e().nullish(),model:e().nullish(),role:e().nullish(),usage:U({input_tokens:r(),cache_creation_input_tokens:r().nullish(),cache_read_input_tokens:r().nullish()}),content:o(f("type",[t({type:n("tool_use"),id:e(),name:e(),input:v(),caller:ut().optional(),toolset_name:e().nullish()})])).nullish(),stop_reason:e().nullish(),input_transformations:o(Et()).nullish(),container:t({expires_at:e(),id:e()}).nullish()})}),t({type:n("content_block_start"),index:r(),content_block:f("type",[t({type:n("text"),text:e()}),t({type:n("thinking"),thinking:e()}),t({type:n("tool_use"),id:e(),name:e(),input:y(e(),v()).optional(),caller:ut().optional(),toolset_name:e().nullish()}),t({type:n("redacted_thinking"),data:e()}),t({type:n("compaction"),content:e().nullish(),signature:e().nullish()}),t({type:n("server_tool_use"),id:e(),name:e(),input:y(e(),v()).nullish(),caller:ut().optional()}),t({type:n("mcp_tool_use"),id:e(),name:e(),input:v(),server_name:e()}),t({type:n("mcp_tool_result"),tool_use_id:e(),is_error:c(),content:lo()}),t({type:n("web_fetch_tool_result"),tool_use_id:e(),caller:ut().optional(),content:l([t({type:n("web_fetch_result"),url:e(),retrieved_at:e().nullable(),content:t({type:n("document"),title:e().nullable(),citations:t({enabled:c()}).optional(),source:l([t({type:n("base64"),media_type:n("application/pdf"),data:e()}),t({type:n("text"),media_type:n("text/plain"),data:e()})])})}),t({type:n("web_fetch_tool_result_error"),error_code:e()})])}),t({type:n("web_search_tool_result"),tool_use_id:e(),caller:ut().optional(),content:l([o(t({type:n("web_search_result"),url:e(),title:e().nullable(),encrypted_content:e(),page_age:e().nullish()})),t({type:n("web_search_tool_result_error"),error_code:e()})])}),t({type:n("code_execution_tool_result"),tool_use_id:e(),content:l([t({type:n("code_execution_result"),stdout:e(),stderr:e(),return_code:r(),content:o(t({type:n("code_execution_output"),file_id:e()})).optional().default([])}),t({type:n("encrypted_code_execution_result"),encrypted_stdout:e(),stderr:e(),return_code:r(),content:o(t({type:n("code_execution_output"),file_id:e()})).optional().default([])}),t({type:n("code_execution_tool_result_error"),error_code:e()})])}),t({type:n("bash_code_execution_tool_result"),tool_use_id:e(),content:f("type",[t({type:n("bash_code_execution_result"),content:o(t({type:n("bash_code_execution_output"),file_id:e()})),stdout:e(),stderr:e(),return_code:r()}),t({type:n("bash_code_execution_tool_result_error"),error_code:e()})])}),t({type:n("text_editor_code_execution_tool_result"),tool_use_id:e(),content:f("type",[t({type:n("text_editor_code_execution_tool_result_error"),error_code:e()}),t({type:n("text_editor_code_execution_view_result"),content:e(),file_type:e(),num_lines:r().nullable(),start_line:r().nullable(),total_lines:r().nullable()}),t({type:n("text_editor_code_execution_create_result"),is_file_update:c()}),t({type:n("text_editor_code_execution_str_replace_result"),lines:o(e()).nullable(),new_lines:r().nullable(),new_start:r().nullable(),old_lines:r().nullable(),old_start:r().nullable()})])}),t({type:n("tool_search_tool_result"),tool_use_id:e(),content:l([t({type:n("tool_search_tool_search_result"),tool_references:o(t({type:n("tool_reference"),tool_name:e()}))}),t({type:n("tool_search_tool_result_error"),error_code:e()})])}),t({type:n("advisor_tool_result"),tool_use_id:e(),content:f("type",[t({type:n("advisor_result"),text:e(),stop_reason:e().nullish()}),t({type:n("advisor_redacted_result"),encrypted_content:e(),stop_reason:e().nullish()}),t({type:n("advisor_tool_result_error"),error_code:e()})])}),Ut()])}),t({type:n("content_block_delta"),index:r(),delta:f("type",[t({type:n("input_json_delta"),partial_json:e()}),t({type:n("text_delta"),text:e()}),t({type:n("thinking_delta"),thinking:e()}),t({type:n("signature_delta"),signature:e()}),t({type:n("compaction_delta"),content:e().nullish()}),t({type:n("citations_delta"),citation:so()})])}),t({type:n("content_block_stop"),index:r()}),t({type:n("error"),error:t({type:e(),message:e(),code:l([e(),r()]).nullish(),statusCode:r().nullish(),isRetryable:c().nullish(),data:v().nullish()})}),t({type:n("message_delta"),delta:t({stop_reason:e().nullish(),stop_sequence:e().nullish(),stop_details:ao().nullish(),safeguard_results:o(io()).nullish(),container:t({expires_at:e(),id:e(),skills:o(t({type:l([n("anthropic"),n("custom")]),skill_id:e(),version:e()})).nullish()}).nullish()}),usage:U({input_tokens:r().nullish(),output_tokens:r(),output_tokens_details:t({thinking_tokens:r().nullish()}).nullish(),cache_creation_input_tokens:r().nullish(),cache_read_input_tokens:r().nullish(),iterations:o(t({type:l([n("compaction"),n("message"),n("advisor_message"),n("fallback_message")]),model:e().nullish(),input_tokens:r(),output_tokens:r(),cache_creation_input_tokens:r().nullish(),cache_read_input_tokens:r().nullish()})).nullish()}),input_transformations:o(Et()).nullish(),context_management:t({applied_edits:o(l([t({type:n("clear_tool_uses_20250919"),cleared_tool_uses:r(),cleared_input_tokens:r()}),t({type:n("clear_thinking_20251015"),cleared_thinking_turns:r(),cleared_input_tokens:r()}),t({type:n("compact_20260112")})]))}).nullish()}),t({type:n("message_stop")}),t({type:n("ping")})]))),Mo=a(()=>s(t({signature:e().optional(),redactedData:e().optional()}))),It=a(()=>s(t({containerUpload:c().optional(),citations:t({enabled:c()}).optional(),title:e().optional(),context:e().optional()}))),Uo=a(()=>s(t({clearAt:n("next_user_message").optional(),effort:i(["low","medium","high","xhigh","max"]).optional(),toolChanges:o(f("type",[t({type:n("tool_addition"),toolName:e()}),t({type:n("tool_removal"),toolName:e()})])).optional()}))),Jt=a(()=>s(t({sendReasoning:c().optional(),structuredOutputMode:i(["outputFormat","jsonTool","auto"]).optional(),thinking:l([f("type",[t({type:n("adaptive"),display:i(["omitted","summarized","updates"]).optional(),blockBinding:t({prefixMismatchBehavior:i(["error","drop_block"])}).optional()}),t({type:n("enabled"),budgetTokens:r().optional()}),t({type:n("disabled")}),t({type:n("between_tools")})]),t({type:Ae().optional(),blockBinding:t({prefixMismatchBehavior:i(["error","drop_block"])})})]).optional(),disableParallelToolUse:c().optional(),cacheControl:t({type:n("ephemeral"),ttl:l([n("5m"),n("1h")]).optional()}).optional(),metadata:t({userId:e().optional()}).optional(),mcpServers:o(t({type:n("url"),name:e(),url:e(),authorizationToken:e().nullish(),toolConfiguration:t({enabled:c().nullish(),allowedTools:o(e()).nullish()}).nullish()})).optional(),container:t({id:e().optional(),skills:o(f("type",[t({type:n("anthropic"),skillId:e(),version:e().optional()}),t({type:n("custom"),providerReference:y(e(),e()),version:e().optional()})])).optional()}).optional(),toolStreaming:c().optional(),effort:i(["low","medium","high","xhigh","max"]).optional(),taskBudget:t({type:n("tokens"),total:r().int().min(20000),remaining:r().int().min(0).optional()}).optional(),speed:i(["fast","standard"]).optional(),serviceTier:i(["auto","standard_only"]).optional(),inferenceGeo:i(["us","global"]).optional(),fallbacks:l([n("default"),o(t({model:e(),max_tokens:r().int().optional(),thinking:y(e(),v()).optional(),output_config:y(e(),v()).optional(),speed:i(["fast","standard"]).optional()}))]).optional(),anthropicBeta:o(e()).optional(),safeguards:o(t({type:n("dangerous_tool_use"),classifierContext:y(e(),v()).optional()})).optional(),compaction:t({type:n("summarize"),instructions:e().optional()}).optional(),contextManagement:t({edits:o(f("type",[t({type:n("clear_tool_uses_20250919"),trigger:f("type",[t({type:n("input_tokens"),value:r()}),t({type:n("tool_uses"),value:r()})]).optional(),keep:t({type:n("tool_uses"),value:r()}).optional(),clearAtLeast:t({type:n("input_tokens"),value:r()}).optional(),clearToolInputs:c().optional(),excludeTools:o(e()).optional()}),t({type:n("clear_thinking_20251015"),keep:l([n("all"),t({type:n("thinking_turns"),value:r()})]).optional()}),t({type:n("compact_20260112"),trigger:t({type:n("input_tokens"),value:r()}).optional(),pauseAfterCompaction:c().optional(),instructions:e().optional()})]))}).optional()}))),Kt=4;function $o(m,A){let B=m?.[A],V=m?.anthropic;return B?.cacheControl??B?.cache_control??V?.cacheControl??V?.cache_control}var $t=class{constructor(m="anthropic"){this.providerOptionsName=m,this.breakpointCount=0,this.warnings=[]}getCacheControl(m,A){let B=$o(m,this.providerOptionsName);if(!B)return;if(!A.canCache){this.warnings.push({type:"unsupported",feature:"cache_control on non-cacheable context",details:`cache_control cannot be set on ${A.type}. It will be ignored.`});return}if(this.breakpointCount++,this.breakpointCount>Kt){this.warnings.push({type:"unsupported",feature:"cacheControl breakpoint limit",details:`Maximum ${Kt} cache breakpoints exceeded (found ${this.breakpointCount}). This breakpoint will be ignored.`});return}return B}getWarnings(){return this.warnings}},qo=a(()=>s(t({model:e(),maxUses:r().optional(),maxTokens:r().int().min(1024).optional(),caching:t({type:n("ephemeral"),ttl:l([n("5m"),n("1h")])}).optional()}))),co=a(()=>s(f("type",[t({type:n("advisor_result"),text:e(),stopReason:e().optional()}),t({type:n("advisor_redacted_result"),encryptedContent:e(),stopReason:e().optional()}),t({type:n("advisor_tool_result_error"),errorCode:e()})]))),Do=a(()=>s(t({}).strict())),Ho=S({id:"anthropic.advisor_20260301",inputSchema:Do,outputSchema:co,supportsDeferredResults:!0}),Po=(m)=>Ho(m),uo=["screenshot","zoom","left_click","right_click","middle_click","double_click","triple_click","left_click_drag","mouse_move","left_mouse_down","left_mouse_up","cursor_position","scroll","type","key","hold_key","wait"],Lo=a(()=>s(t({action:i(uo),coordinate:ce([r().int(),r().int()]).optional(),duration:r().optional(),region:ce([r().int(),r().int(),r().int(),r().int()]).optional(),repeat:r().int().optional(),scroll_amount:r().optional(),scroll_direction:i(["up","down","left","right"]).optional(),start_coordinate:ce([r().int(),r().int()]).optional(),text:e().optional()}))),Fo=a(()=>s(t({configs:bn(i(uo),t({enabled:c().optional(),deferLoading:c().optional()})).optional()}))),Jo=re({id:"anthropic.computer_toolset_20260801",inputSchema:Lo}),Ko=a(()=>s(t({maxCharacters:r().optional()}))),zo=a(()=>s(t({command:i(["view","create","str_replace","insert"]),path:e(),file_text:e().optional(),insert_line:r().int().optional(),new_str:e().optional(),insert_text:e().optional(),old_str:e().optional(),view_range:o(r().int()).optional()}))),Wo=re({id:"anthropic.text_editor_20250728",inputSchema:zo}),Vo=(m={})=>Wo(m),Xo=a(()=>s(t({maxUses:r().optional(),allowedDomains:o(e()).optional(),blockedDomains:o(e()).optional(),userLocation:t({type:n("approximate"),city:e().optional(),region:e().optional(),country:e().optional(),timezone:e().optional()}).optional(),responseInclusion:i(["full","excluded"]).optional()}))),Go=a(()=>s(o(t({url:e(),title:e().nullable(),pageAge:e().nullable(),encryptedContent:e(),type:n("web_search_result")})))),Zo=a(()=>s(t({query:e()}))),Yo=S({id:"anthropic.web_search_20260318",inputSchema:Zo,outputSchema:Go,supportsDeferredResults:!0}),Qo=(m={})=>Yo(m),en=a(()=>s(t({maxUses:r().optional(),allowedDomains:o(e()).optional(),blockedDomains:o(e()).optional(),userLocation:t({type:n("approximate"),city:e().optional(),region:e().optional(),country:e().optional(),timezone:e().optional()}).optional()}))),tn=a(()=>s(o(t({url:e(),title:e().nullable(),pageAge:e().nullable(),encryptedContent:e(),type:n("web_search_result")})))),on=a(()=>s(t({query:e()}))),nn=S({id:"anthropic.web_search_20260209",inputSchema:on,outputSchema:tn,supportsDeferredResults:!0}),rn=(m={})=>nn(m),an=a(()=>s(t({maxUses:r().optional(),allowedDomains:o(e()).optional(),blockedDomains:o(e()).optional(),userLocation:t({type:n("approximate"),city:e().optional(),region:e().optional(),country:e().optional(),timezone:e().optional()}).optional()}))),po=a(()=>s(o(t({url:e(),title:e().nullable(),pageAge:e().nullable(),encryptedContent:e(),type:n("web_search_result")})))),sn=a(()=>s(t({query:e()}))),ln=S({id:"anthropic.web_search_20250305",inputSchema:sn,outputSchema:po,supportsDeferredResults:!0}),cn=(m={})=>ln(m),un=a(()=>s(t({maxUses:r().optional(),allowedDomains:o(e()).optional(),blockedDomains:o(e()).optional(),citations:t({enabled:c()}).optional(),maxContentTokens:r().optional(),useCache:c().optional(),responseInclusion:i(["full","excluded"]).optional()}))),pn=a(()=>s(t({type:n("web_fetch_result"),url:e(),content:t({type:n("document"),title:e().nullable(),citations:t({enabled:c()}).optional(),source:l([t({type:n("base64"),mediaType:n("application/pdf"),data:e()}),t({type:n("text"),mediaType:n("text/plain"),data:e()})])}),retrievedAt:e().nullable()}))),dn=a(()=>s(t({url:e()}))),_n=S({id:"anthropic.web_fetch_20260318",inputSchema:dn,outputSchema:pn,supportsDeferredResults:!0}),hn=(m={})=>_n(m),mn=a(()=>s(t({maxUses:r().optional(),allowedDomains:o(e()).optional(),blockedDomains:o(e()).optional(),citations:t({enabled:c()}).optional(),maxContentTokens:r().optional()}))),gn=a(()=>s(t({type:n("web_fetch_result"),url:e(),content:t({type:n("document"),title:e().nullable(),citations:t({enabled:c()}).optional(),source:l([t({type:n("base64"),mediaType:n("application/pdf"),data:e()}),t({type:n("text"),mediaType:n("text/plain"),data:e()})])}),retrievedAt:e().nullable()}))),fn=a(()=>s(t({url:e()}))),yn=S({id:"anthropic.web_fetch_20260209",inputSchema:fn,outputSchema:gn,supportsDeferredResults:!0}),xn=(m={})=>yn(m),vn=a(()=>s(t({maxUses:r().optional(),allowedDomains:o(e()).optional(),blockedDomains:o(e()).optional(),citations:t({enabled:c()}).optional(),maxContentTokens:r().optional()}))),_o=a(()=>s(t({type:n("web_fetch_result"),url:e(),content:t({type:n("document"),title:e().nullable(),citations:t({enabled:c()}).optional(),source:l([t({type:n("base64"),mediaType:n("application/pdf"),data:e()}),t({type:n("text"),mediaType:n("text/plain"),data:e()})])}),retrievedAt:e().nullable()}))),kn=a(()=>s(t({url:e()}))),wn=S({id:"anthropic.web_fetch_20250910",inputSchema:kn,outputSchema:_o,supportsDeferredResults:!0}),jn=(m={})=>wn(m);async function Tn({tools:m,toolChoice:A,disableParallelToolUse:B,cacheControlValidator:V,supportsStructuredOutput:me,supportsStrictTools:Ne,defaultEagerInputStreaming:K=!1,rejectsForcedToolUse:ie=!1}){m=m?.length?m:void 0;let se=[],fe=new Set,$e=V||new $t;if(m==null)return{tools:void 0,toolChoice:void 0,toolWarnings:se,betas:fe};let Ce=[];for(let ve of m)switch(ve.type){case"function":{let ke=$e.getCacheControl(ve.providerOptions,{type:"tool definition",canCache:!0}),Me=ve.providerOptions?.anthropic,Ve=Me?.eagerInputStreaming??K,Je=Me?.deferLoading,Le=Me?.allowedCallers;if(!Ne&&ve.strict===!0)se.push({type:"unsupported",feature:"strict",details:`Tool '${ve.name}' has strict: ${ve.strict}, but strict mode is not supported by this provider. The strict property will be ignored.`});if(Ce.push({name:ve.name,description:ve.description,input_schema:ve.inputSchema,cache_control:ke,...Ve?{eager_input_streaming:!0}:{},...Ne===!0&&ve.strict!=null?{strict:ve.strict}:{},...Je!=null?{defer_loading:Je}:{},...Le!=null?{allowed_callers:Le}:{},...ve.inputExamples!=null?{input_examples:ve.inputExamples.map((Re)=>Re.input)}:{}}),me===!0)fe.add("structured-outputs-2025-11-13");if(ve.inputExamples!=null||Le!=null)fe.add("advanced-tool-use-2025-11-20");break}case"provider":switch(ve.id){case"anthropic.code_execution_20250522":fe.add("code-execution-2025-05-22"),Ce.push({type:"code_execution_20250522",name:"code_execution",cache_control:void 0});break;case"anthropic.code_execution_20250825":fe.add("code-execution-2025-08-25"),Ce.push({type:"code_execution_20250825",name:"code_execution"});break;case"anthropic.code_execution_20260120":Ce.push({type:"code_execution_20260120",name:"code_execution"});break;case"anthropic.computer_20250124":fe.add("computer-use-2025-01-24"),Ce.push({name:"computer",type:"computer_20250124",display_width_px:ve.args.displayWidthPx,display_height_px:ve.args.displayHeightPx,display_number:ve.args.displayNumber,cache_control:void 0});break;case"anthropic.computer_20251124":fe.add("computer-use-2025-11-24"),Ce.push({name:"computer",type:"computer_20251124",display_width_px:ve.args.displayWidthPx,display_height_px:ve.args.displayHeightPx,display_number:ve.args.displayNumber,enable_zoom:ve.args.enableZoom,cache_control:void 0});break;case"anthropic.computer_toolset_20260801":{let ke=await x({value:ve.args,schema:Fo}),Me=ke.configs!=null?Object.fromEntries(Object.entries(ke.configs).map(([Ve,Je])=>[Ve,{...Je?.enabled!=null&&{enabled:Je.enabled},...Je?.deferLoading!=null&&{defer_loading:Je.deferLoading}}])):void 0;Ce.push({type:"computer_toolset_20260801",...Me!=null&&{configs:Me},cache_control:void 0});break}case"anthropic.computer_20241022":fe.add("computer-use-2024-10-22"),Ce.push({name:"computer",type:"computer_20241022",display_width_px:ve.args.displayWidthPx,display_height_px:ve.args.displayHeightPx,display_number:ve.args.displayNumber,cache_control:void 0});break;case"anthropic.text_editor_20250124":fe.add("computer-use-2025-01-24"),Ce.push({name:"str_replace_editor",type:"text_editor_20250124",cache_control:void 0});break;case"anthropic.text_editor_20241022":fe.add("computer-use-2024-10-22"),Ce.push({name:"str_replace_editor",type:"text_editor_20241022",cache_control:void 0});break;case"anthropic.text_editor_20250429":fe.add("computer-use-2025-01-24"),Ce.push({name:"str_replace_based_edit_tool",type:"text_editor_20250429",cache_control:void 0});break;case"anthropic.text_editor_20250728":{let ke=await x({value:ve.args,schema:Ko});Ce.push({name:"str_replace_based_edit_tool",type:"text_editor_20250728",max_characters:ke.maxCharacters,cache_control:void 0});break}case"anthropic.bash_20250124":fe.add("computer-use-2025-01-24"),Ce.push({name:"bash",type:"bash_20250124",cache_control:void 0});break;case"anthropic.bash_20241022":fe.add("computer-use-2024-10-22"),Ce.push({name:"bash",type:"bash_20241022",cache_control:void 0});break;case"anthropic.memory_20250818":fe.add("context-management-2025-06-27"),Ce.push({name:"memory",type:"memory_20250818"});break;case"anthropic.web_fetch_20250910":{fe.add("web-fetch-2025-09-10");let ke=await x({value:ve.args,schema:vn});Ce.push({type:"web_fetch_20250910",name:"web_fetch",max_uses:ke.maxUses,allowed_domains:ke.allowedDomains,blocked_domains:ke.blockedDomains,citations:ke.citations,max_content_tokens:ke.maxContentTokens,cache_control:void 0});break}case"anthropic.web_fetch_20260209":{fe.add("code-execution-web-tools-2026-02-09");let ke=await x({value:ve.args,schema:mn});Ce.push({type:"web_fetch_20260209",name:"web_fetch",max_uses:ke.maxUses,allowed_domains:ke.allowedDomains,blocked_domains:ke.blockedDomains,citations:ke.citations,max_content_tokens:ke.maxContentTokens,cache_control:void 0});break}case"anthropic.web_fetch_20260318":{let ke=await x({value:ve.args,schema:un});Ce.push({type:"web_fetch_20260318",name:"web_fetch",max_uses:ke.maxUses,allowed_domains:ke.allowedDomains,blocked_domains:ke.blockedDomains,citations:ke.citations,max_content_tokens:ke.maxContentTokens,use_cache:ke.useCache,response_inclusion:ke.responseInclusion,cache_control:void 0});break}case"anthropic.web_search_20250305":{let ke=await x({value:ve.args,schema:an});Ce.push({type:"web_search_20250305",name:"web_search",max_uses:ke.maxUses,allowed_domains:ke.allowedDomains,blocked_domains:ke.blockedDomains,user_location:ke.userLocation,cache_control:void 0});break}case"anthropic.web_search_20260209":{fe.add("code-execution-web-tools-2026-02-09");let ke=await x({value:ve.args,schema:en});Ce.push({type:"web_search_20260209",name:"web_search",max_uses:ke.maxUses,allowed_domains:ke.allowedDomains,blocked_domains:ke.blockedDomains,user_location:ke.userLocation,cache_control:void 0});break}case"anthropic.web_search_20260318":{let ke=await x({value:ve.args,schema:Xo});Ce.push({type:"web_search_20260318",name:"web_search",max_uses:ke.maxUses,allowed_domains:ke.allowedDomains,blocked_domains:ke.blockedDomains,user_location:ke.userLocation,response_inclusion:ke.responseInclusion,cache_control:void 0});break}case"anthropic.tool_search_regex_20251119":Ce.push({type:"tool_search_tool_regex_20251119",name:"tool_search_tool_regex"});break;case"anthropic.tool_search_bm25_20251119":Ce.push({type:"tool_search_tool_bm25_20251119",name:"tool_search_tool_bm25"});break;case"anthropic.advisor_20260301":{fe.add("advisor-tool-2026-03-01");let ke=await x({value:ve.args,schema:qo});Ce.push({type:"advisor_20260301",name:"advisor",model:ke.model,...ke.maxUses!==void 0&&{max_uses:ke.maxUses},...ke.maxTokens!==void 0&&{max_tokens:ke.maxTokens},...ke.caching!==void 0&&{caching:ke.caching}});break}default:se.push({type:"unsupported",feature:`provider-defined tool ${ve.id}`})}break;default:se.push({type:"unsupported",feature:`tool ${ve}`})}if(A==null)return{tools:Ce,toolChoice:B?{type:"auto",disable_parallel_tool_use:B}:void 0,toolWarnings:se,betas:fe};let Ze=A.type;switch(Ze){case"auto":return{tools:Ce,toolChoice:{type:"auto",disable_parallel_tool_use:B},toolWarnings:se,betas:fe};case"required":if(ie)return se.push({type:"unsupported",feature:"toolChoice",details:"toolChoice 'required' is not supported with this model or thinking configuration. Using 'auto' instead. Instruct the model to use a tool in the prompt and verify that a tool call was made."}),{tools:Ce,toolChoice:{type:"auto",disable_parallel_tool_use:B},toolWarnings:se,betas:fe};return{tools:Ce,toolChoice:{type:"any",disable_parallel_tool_use:B},toolWarnings:se,betas:fe};case"none":return{tools:Ce,toolChoice:{type:"none"},toolWarnings:se,betas:fe};case"tool":if(ie)return se.push({type:"unsupported",feature:"toolChoice",details:`toolChoice 'tool' is not supported with this model or thinking configuration. Only the '${A.toolName}' tool is sent with 'auto' tool choice. Instruct the model to use the tool in the prompt and verify that a tool call was made.`}),{tools:Ce.filter((ve)=>("name"in ve)&&ve.name===A.toolName),toolChoice:{type:"auto",disable_parallel_tool_use:B},toolWarnings:se,betas:fe};return{tools:Ce,toolChoice:{type:"tool",name:A.toolName,disable_parallel_tool_use:B},toolWarnings:se,betas:fe};default:throw new u({functionality:`tool choice type: ${Ze}`})}}function Mt({usage:m,rawUsage:A}){let B=m.cache_creation_input_tokens??0,V=m.cache_read_input_tokens??0,me=m.output_tokens_details?.thinking_tokens??void 0,Ne,K,ie=m.iterations?.some((se)=>se.type==="fallback_message");if(m.iterations&&m.iterations.length>0&&!ie){let se=m.iterations.filter((fe)=>fe.type==="compaction"||fe.type==="message");if(se.length>0){let fe=se.reduce(($e,Ce)=>({input:$e.input+Ce.input_tokens,output:$e.output+Ce.output_tokens}),{input:0,output:0});Ne=fe.input,K=fe.output}else Ne=m.input_tokens,K=m.output_tokens}else Ne=m.input_tokens,K=m.output_tokens;return{inputTokens:{total:Ne+B+V,noCache:Ne,cacheRead:V,cacheWrite:B},outputTokens:{total:K,text:me==null?void 0:K-me,reasoning:me},raw:A??m}}var ho=a(()=>s(t({type:n("code_execution_result"),stdout:e(),stderr:e(),return_code:r(),content:o(t({type:n("code_execution_output"),file_id:e()})).optional().default([])}))),Cn=a(()=>s(t({code:e()}))),Sn=S({id:"anthropic.code_execution_20250522",inputSchema:Cn,outputSchema:ho}),Nn=(m={})=>Sn(m),mo=a(()=>s(f("type",[t({type:n("code_execution_result"),stdout:e(),stderr:e(),return_code:r(),content:o(t({type:n("code_execution_output"),file_id:e()})).optional().default([])}),t({type:n("bash_code_execution_result"),content:o(t({type:n("bash_code_execution_output"),file_id:e()})),stdout:e(),stderr:e(),return_code:r()}),t({type:n("bash_code_execution_tool_result_error"),error_code:e()}),t({type:n("text_editor_code_execution_tool_result_error"),error_code:e()}),t({type:n("text_editor_code_execution_view_result"),content:e(),file_type:e(),num_lines:r().nullable(),start_line:r().nullable(),total_lines:r().nullable()}),t({type:n("text_editor_code_execution_create_result"),is_file_update:c()}),t({type:n("text_editor_code_execution_str_replace_result"),lines:o(e()).nullable(),new_lines:r().nullable(),new_start:r().nullable(),old_lines:r().nullable(),old_start:r().nullable()})]))),On=a(()=>s(f("type",[t({type:n("programmatic-tool-call"),code:e()}),t({type:n("bash_code_execution"),command:e()}),f("command",[t({type:n("text_editor_code_execution"),command:n("view"),path:e()}),t({type:n("text_editor_code_execution"),command:n("create"),path:e(),file_text:e().nullish()}),t({type:n("text_editor_code_execution"),command:n("str_replace"),path:e(),old_str:e(),new_str:e()})])]))),In=S({id:"anthropic.code_execution_20250825",inputSchema:On,outputSchema:mo,supportsDeferredResults:!0}),An=(m={})=>Ke(In(m),{type:"provider",prepareProviderOptions:(A)=>{let B=A?.anthropic;return{...A,anthropic:{...B,allowedCallers:[...new Set([...B?.allowedCallers??[],"code_execution_20250825"])]}}}}),go=a(()=>s(f("type",[t({type:n("code_execution_result"),stdout:e(),stderr:e(),return_code:r(),content:o(t({type:n("code_execution_output"),file_id:e()})).optional().default([])}),t({type:n("encrypted_code_execution_result"),encrypted_stdout:e(),stderr:e(),return_code:r(),content:o(t({type:n("code_execution_output"),file_id:e()})).optional().default([])}),t({type:n("bash_code_execution_result"),content:o(t({type:n("bash_code_execution_output"),file_id:e()})),stdout:e(),stderr:e(),return_code:r()}),t({type:n("bash_code_execution_tool_result_error"),error_code:e()}),t({type:n("text_editor_code_execution_tool_result_error"),error_code:e()}),t({type:n("text_editor_code_execution_view_result"),content:e(),file_type:e(),num_lines:r().nullable(),start_line:r().nullable(),total_lines:r().nullable()}),t({type:n("text_editor_code_execution_create_result"),is_file_update:c()}),t({type:n("text_editor_code_execution_str_replace_result"),lines:o(e()).nullable(),new_lines:r().nullable(),new_start:r().nullable(),old_lines:r().nullable(),old_start:r().nullable()})]))),Rn=a(()=>s(f("type",[t({type:n("programmatic-tool-call"),code:e()}),t({type:n("bash_code_execution"),command:e()}),f("command",[t({type:n("text_editor_code_execution"),command:n("view"),path:e()}),t({type:n("text_editor_code_execution"),command:n("create"),path:e(),file_text:e().nullish()}),t({type:n("text_editor_code_execution"),command:n("str_replace"),path:e(),old_str:e(),new_str:e()})])]))),Bn=S({id:"anthropic.code_execution_20260120",inputSchema:Rn,outputSchema:go,supportsDeferredResults:!0}),En=(m={})=>Ke(Bn(m),{type:"provider",prepareProviderOptions:(A)=>{let B=A?.anthropic;return{...A,anthropic:{...B,allowedCallers:[...new Set([...B?.allowedCallers??[],"code_execution_20260120"])]}}}}),fo=a(()=>s(o(t({type:n("tool_reference"),toolName:e()})))),Mn=a(()=>s(t({pattern:e(),limit:r().optional()}))),Un=S({id:"anthropic.tool_search_regex_20251119",inputSchema:Mn,outputSchema:fo,supportsDeferredResults:!0}),$n=(m={})=>Un(m);function qn(m){if(typeof m==="string")return new TextDecoder().decode(N(m));return new TextDecoder().decode(m)}function At(m){try{if(typeof m==="string")return Q(m);else if(typeof m==="object"&&m!==null)return m}catch{let A=m?.errorCode;return{errorCode:typeof A==="string"?A:"unavailable"}}return{}}async function Dn({prompt:m,sendReasoning:A,warnings:B,cacheControlValidator:V,toolNameMapping:me,toolsetNames:Ne={},convertMediaPart:K}){let ie=new Set,se=Hn(m),fe=V||new $t,$e=void 0,Ce=[],Ze=-1;async function ve(Le){return(await h({provider:"anthropic",providerOptions:Le,schema:It}))?.citations?.enabled??!1}async function ke(Le){return(await h({provider:"anthropic",providerOptions:Le,schema:It}))?.containerUpload??!1}async function Me(Le){let Re=await h({provider:"anthropic",providerOptions:Le,schema:It});return{title:Re?.title,context:Re?.context}}for(let Le=0;Le<se.length;Le++){let Re=se[Le],J=Le===se.length-1,Ee=Re.type;switch(Ee){case"system":{let ye=[];for(let{content:He,providerOptions:X}of Re.messages){let Te=await h({provider:"anthropic",providerOptions:X,schema:Uo}),Xe=Te?.toolChanges??[],Z=[];if(He!==""||Xe.length===0&&Te?.clearAt==null&&Te?.effort==null)Z.push({type:"text",text:He,cache_control:fe.getCacheControl(X,{type:"system message",canCache:!0})});for(let nt of Xe)Z.push({type:nt.type,tool:{type:"tool_reference",name:me.toProviderToolName(nt.toolName)}});ye.push({content:Z,clearAt:Te?.clearAt,effort:Te?.effort,toolChangeCount:Xe.length})}let Pe=ye.reduce((He,X)=>He+X.toolChangeCount,0),ot=ye.some((He)=>He.clearAt!=null||He.effort!=null);if(Le===0||$e==null&&Pe===0&&!ot){if(Pe>0)B.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 He of ye)if(He.content.length===0&&He.clearAt==null&&He.effort!=null)Ce.push({role:"system",content:[],output_config:{effort:He.effort}}),ie.add("mid-conversation-output-config-2026-07-01");else if(He.clearAt!=null||He.effort!=null)B.push({type:"other",message:"clearAt and effort on this initial system message are not supported by Anthropic. Use a separate effort-only system message with empty content to set effort. These options have been ignored."});$e=ye.flatMap((He)=>He.content.filter((X)=>X.type==="text"))}else{ie.add("mid-conversation-system-2026-04-07");for(let He of ye){if(Ce.push({role:"system",content:He.content,...He.clearAt!=null&&{clear_at:He.clearAt},...He.effort!=null&&{output_config:{effort:He.effort}}}),He.toolChangeCount>0)ie.add("mid-conversation-tool-changes-2026-07-01");if(He.clearAt!=null)ie.add("mid-conversation-system-clear-at-2026-08-21");if(He.effort!=null)ie.add("mid-conversation-output-config-2026-07-01")}}break}case"user":{let ye=[];for(let Pe of Re.messages){let{role:ot,content:He}=Pe;switch(ot){case"user":if(He.length>0)Ze=Ce.length;for(let X=0;X<He.length;X++){let Te=He[X],Xe=X===He.length-1,Z=fe.getCacheControl(Te.providerOptions,{type:"user message part",canCache:!0})??(Xe?fe.getCacheControl(Pe.providerOptions,{type:"user message",canCache:!0}):void 0);switch(Te.type){case"text":ye.push({type:"text",text:Te.text,cache_control:Z});break;case"file":{let nt=await K?.(Te);if(nt!=null){ye.push({...nt,cache_control:Z});break}switch(Te.data.type){case"reference":{let Ue=H({reference:Te.data.reference,provider:"anthropic"});if(ie.add("files-api-2025-04-14"),await ke(Te.providerOptions))ye.push({type:"container_upload",file_id:Ue});else if(z(Te.mediaType)==="image")ye.push({type:"image",source:{type:"file",file_id:Ue},cache_control:Z});else ye.push({type:"document",source:{type:"file",file_id:Ue},cache_control:Z});break}case"text":{let Ue=await ve(Te.providerOptions),Oe=await Me(Te.providerOptions);ye.push({type:"document",source:{type:"text",media_type:"text/plain",data:Te.data.text},title:Oe.title??Te.filename,...Oe.context&&{context:Oe.context},...Ue&&{citations:{enabled:!0}},cache_control:Z});break}case"url":case"data":{let Ue=z(Te.mediaType);if(Ue==="image")ye.push({type:"image",source:Te.data.type==="url"?{type:"url",url:Te.data.url.toString()}:{type:"base64",media_type:O({part:Te}),data:M(Te.data.data)},cache_control:Z});else if(Ue==="application"&&(Te.data.type==="url"?Te.mediaType==="application/pdf":O({part:Te})==="application/pdf")){ie.add("pdfs-2024-09-25");let Oe=await ve(Te.providerOptions),We=await Me(Te.providerOptions);ye.push({type:"document",source:Te.data.type==="url"?{type:"url",url:Te.data.url.toString()}:{type:"base64",media_type:"application/pdf",data:M(Te.data.data)},title:We.title??Te.filename,...We.context&&{context:We.context},...Oe&&{citations:{enabled:!0}},cache_control:Z})}else if(Te.mediaType==="text/plain"){let Oe=await ve(Te.providerOptions),We=await Me(Te.providerOptions);ye.push({type:"document",source:Te.data.type==="url"?{type:"url",url:Te.data.url.toString()}:{type:"text",media_type:"text/plain",data:qn(Te.data.data)},title:We.title??Te.filename,...We.context&&{context:We.context},...Oe&&{citations:{enabled:!0}},cache_control:Z})}else throw new u({functionality:`media type: ${Te.mediaType}`});break}}break}}}break;case"tool":for(let X=0;X<He.length;X++){let Te=He[X];if(Te.type==="tool-approval-response")continue;let Xe=Te.output,Z="providerOptions"in Xe?Xe.providerOptions:Xe.type==="content"?Xe.value.find((te)=>te.providerOptions!=null)?.providerOptions:void 0,nt=X===He.length-1,Ue=fe.getCacheControl(Te.providerOptions,{type:"tool result part",canCache:!0})??fe.getCacheControl(Z,{type:"tool result output",canCache:!0})??(nt?fe.getCacheControl(Pe.providerOptions,{type:"tool result message",canCache:!0}):void 0),Oe;switch(Xe.type){case"content":Oe=Xe.value.map((te)=>{switch(te.type){case"text":return{type:"text",text:te.text};case"file":{let ue=z(te.mediaType);if(te.data.type==="reference"){let Ye=H({reference:te.data.reference,provider:"anthropic"});if(ie.add("files-api-2025-04-14"),ue==="image")return{type:"image",source:{type:"file",file_id:Ye}};return{type:"document",source:{type:"file",file_id:Ye}}}if(te.data.type==="url"){if(ue==="image")return{type:"image",source:{type:"url",url:te.data.url.toString()}};return{type:"document",source:{type:"url",url:te.data.url.toString()}}}if(te.data.type==="data"){if(ue==="image")return{type:"image",source:{type:"base64",media_type:O({part:te}),data:M(te.data.data)}};if(O({part:te})==="application/pdf")return ie.add("pdfs-2024-09-25"),{type:"document",source:{type:"base64",media_type:"application/pdf",data:M(te.data.data)}};B.push({type:"other",message:`unsupported tool content part type: ${te.type} with media type: ${te.mediaType}`});return}B.push({type:"other",message:`unsupported tool content part type: ${te.type} with data type: ${te.data.type}`});return}case"custom":{let ue=te.providerOptions?.anthropic;if(ue?.type==="tool-reference")return{type:"tool_reference",tool_name:ue.toolName};B.push({type:"other",message:"unsupported custom tool content part"});return}default:B.push({type:"other",message:`unsupported tool content part type: ${te.type}`});return}}).filter(Fe);break;case"text":case"error-text":Oe=Xe.value;break;case"execution-denied":Oe=Xe.reason??"Tool call execution denied.";break;default:Oe=JSON.stringify(Xe.value)}let We=zt({toolName:Te.toolName,providerOptions:Te.providerOptions,toolsetNames:Ne});ye.push({type:"tool_result",tool_use_id:Te.toolCallId,...We!=null&&{toolset_name:We},content:Oe,is_error:Xe.type==="error-text"||Xe.type==="error-json"?!0:void 0,cache_control:Ue})}break;default:throw Error(`Unsupported role: ${ot}`)}}Ce.push({role:"user",content:ye});break}case"assistant":{let ye=[],Pe=new Set;for(let ot=0;ot<Re.messages.length;ot++){let He=Re.messages[ot],X=ot===Re.messages.length-1,{content:Te}=He;for(let Xe=0;Xe<Te.length;Xe++){let Z=Te[Xe],nt=Xe===Te.length-1,Ue=fe.getCacheControl(Z.providerOptions,{type:"assistant message part",canCache:!0})??(nt?fe.getCacheControl(He.providerOptions,{type:"assistant message",canCache:!0}):void 0);switch(Z.type){case"text":{let Oe=Z.providerOptions?.anthropic;if(Oe?.type==="compaction"){if(Z.text==="")break;if(typeof Oe.signature==="string")ie.add("compact-2026-09-04");ye.push({type:"compaction",content:Z.text,...typeof Oe.signature==="string"&&{signature:Oe.signature},cache_control:Ue})}else ye.push({type:"text",text:J&&X&&nt?Z.text.trim():Z.text,...Oe?.citations!=null&&{citations:Oe.citations},cache_control:Ue});break}case"reasoning":if(A){let Oe=await h({provider:"anthropic",providerOptions:Z.providerOptions,schema:Mo});if(Oe!=null)if(Oe.signature!=null)fe.getCacheControl(Z.providerOptions,{type:"thinking block",canCache:!1}),ye.push({type:"thinking",thinking:Z.text,signature:Oe.signature});else if(Oe.redactedData!=null)fe.getCacheControl(Z.providerOptions,{type:"redacted thinking block",canCache:!1}),ye.push({type:"redacted_thinking",data:Oe.redactedData});else B.push({type:"other",message:"unsupported reasoning metadata"});else B.push({type:"other",message:"unsupported reasoning metadata"})}else B.push({type:"other",message:"sending reasoning content is disabled for this model"});break;case"custom":{if(Z.kind!=="anthropic.fallback")break;let Oe=await j({value:Z.providerOptions?.anthropic,schema:Bo});if(!Oe.success){B.push({type:"other",message:"anthropic fallback metadata must include from.model and to.model"});break}ie.add("server-side-fallback-2026-06-01"),ye.push({type:"fallback",from:Oe.value.from,to:Oe.value.to});break}case"tool-call":{let Oe=Wt(Z.providerOptions);if(Z.providerExecuted){let te=me.toProviderToolName(Z.toolName);if(Z.providerOptions?.anthropic?.type==="mcp-tool-use"){Pe.add(Z.toolCallId);let ue=Z.providerOptions?.anthropic?.serverName;if(ue==null||typeof ue!=="string"){B.push({type:"other",message:"mcp tool use server name is required and must be a string"});break}ye.push({type:"mcp_tool_use",id:Z.toolCallId,name:Z.toolName,input:Z.input,server_name:ue,cache_control:Ue})}else if(te==="code_execution"&&Z.input!=null&&typeof Z.input==="object"&&"type"in Z.input&&typeof Z.input.type==="string"&&(Z.input.type==="bash_code_execution"||Z.input.type==="text_editor_code_execution")){let{type:ue,...Ye}=Z.input;ye.push({type:"server_tool_use",id:Z.toolCallId,name:ue,input:Ye,...Oe&&{caller:Oe},cache_control:Ue})}else if(te==="code_execution"&&Z.input!=null&&typeof Z.input==="object"&&"type"in Z.input&&Z.input.type==="programmatic-tool-call"){let{type:ue,...Ye}=Z.input;ye.push({type:"server_tool_use",id:Z.toolCallId,name:"code_execution",input:Ye,...Oe&&{caller:Oe},cache_control:Ue})}else if(te==="code_execution"||te==="web_fetch"||te==="web_search")ye.push({type:"server_tool_use",id:Z.toolCallId,name:te,input:Z.input,...Oe&&{caller:Oe},cache_control:Ue});else if(te==="tool_search_tool_regex"||te==="tool_search_tool_bm25")ye.push({type:"server_tool_use",id:Z.toolCallId,name:te,input:Z.input,...Oe&&{caller:Oe},cache_control:Ue});else if(te==="advisor")ye.push({type:"server_tool_use",id:Z.toolCallId,name:"advisor",input:{},...Oe&&{caller:Oe},cache_control:Ue});else B.push({type:"other",message:`provider executed tool call for tool ${Z.toolName} is not supported`});break}let We=zt({toolName:Z.toolName,providerOptions:Z.providerOptions,toolsetNames:Ne});if(We!=null){let te=Vt(Z.input),{action:ue}=te,Ye=typeof ue==="string";if(!Ye)B.push({type:"other",message:`toolset tool call for tool ${Z.toolName} is missing the action`});ye.push({type:"tool_use",id:Z.toolCallId,name:Ye?ue:We,toolset_name:We,input:te,...Oe&&{caller:Oe},cache_control:Ue});break}ye.push({type:"tool_use",id:Z.toolCallId,name:Z.toolName,input:Vt(Z.input),...Oe&&{caller:Oe},cache_control:Ue});break}case"tool-result":{let Oe=me.toProviderToolName(Z.toolName),We=Wt(Z.providerOptions);if(Pe.has(Z.toolCallId)){let te=Z.output;if(te.type!=="json"&&te.type!=="error-json"){B.push({type:"other",message:`provider executed tool result output type ${te.type} for tool ${Z.toolName} is not supported`});break}ye.push({type:"mcp_tool_result",tool_use_id:Z.toolCallId,is_error:te.type==="error-json",content:te.value,cache_control:Ue})}else if(Oe==="code_execution"){let te=Z.output;if(te.type==="error-text"||te.type==="error-json"){let ue={};try{if(typeof te.value==="string")ue=Q(te.value);else if(typeof te.value==="object"&&te.value!==null)ue=te.value}catch{}if(ue.type==="code_execution_tool_result_error")ye.push({type:"code_execution_tool_result",tool_use_id:Z.toolCallId,content:{type:"code_execution_tool_result_error",error_code:ue.errorCode??"unknown"},cache_control:Ue});else ye.push({type:"bash_code_execution_tool_result",tool_use_id:Z.toolCallId,cache_control:Ue,content:{type:"bash_code_execution_tool_result_error",error_code:ue.errorCode??"unknown"}});break}if(te.type!=="json"){B.push({type:"other",message:`provider executed tool result output type ${te.type} for tool ${Z.toolName} is not supported`});break}if(te.value==null||typeof te.value!=="object"||!("type"in te.value)||typeof te.value.type!=="string"){B.push({type:"other",message:`provider executed tool result output value is not a valid code execution result for tool ${Z.toolName}`});break}if(te.value.type==="code_execution_result"){let ue=await x({value:te.value,schema:ho});ye.push({type:"code_execution_tool_result",tool_use_id:Z.toolCallId,content:{type:ue.type,stdout:ue.stdout,stderr:ue.stderr,return_code:ue.return_code,content:ue.content??[]},cache_control:Ue})}else if(te.value.type==="encrypted_code_execution_result"){let ue=await x({value:te.value,schema:go});if(ue.type==="encrypted_code_execution_result")ye.push({type:"code_execution_tool_result",tool_use_id:Z.toolCallId,content:{type:ue.type,encrypted_stdout:ue.encrypted_stdout,stderr:ue.stderr,return_code:ue.return_code,content:ue.content??[]},cache_control:Ue})}else{let ue=await x({value:te.value,schema:mo});if(ue.type==="code_execution_result")ye.push({type:"code_execution_tool_result",tool_use_id:Z.toolCallId,content:{type:ue.type,stdout:ue.stdout,stderr:ue.stderr,return_code:ue.return_code,content:ue.content??[]},cache_control:Ue});else if(ue.type==="bash_code_execution_result"||ue.type==="bash_code_execution_tool_result_error")ye.push({type:"bash_code_execution_tool_result",tool_use_id:Z.toolCallId,cache_control:Ue,content:ue.type==="bash_code_execution_result"?{type:ue.type,stdout:ue.stdout,stderr:ue.stderr,return_code:ue.return_code,content:ue.content}:ue});else ye.push({type:"text_editor_code_execution_tool_result",tool_use_id:Z.toolCallId,cache_control:Ue,content:ue})}break}if(Oe==="web_fetch"){let te=Z.output;if(te.type==="error-json"){ye.push({type:"web_fetch_tool_result",tool_use_id:Z.toolCallId,content:{type:"web_fetch_tool_result_error",error_code:At(te.value).errorCode??"unavailable"},...We&&{caller:We},cache_control:Ue});break}if(te.type!=="json"){B.push({type:"other",message:`provider executed tool result output type ${te.type} for tool ${Z.toolName} is not supported`});break}let ue=await x({value:te.value,schema:_o});ye.push({type:"web_fetch_tool_result",tool_use_id:Z.toolCallId,content:{type:"web_fetch_result",url:ue.url,retrieved_at:ue.retrievedAt,content:{type:"document",title:ue.content.title,citations:ue.content.citations,source:{type:ue.content.source.type,media_type:ue.content.source.mediaType,data:ue.content.source.data}}},...We&&{caller:We},cache_control:Ue});break}if(Oe==="web_search"){let te=Z.output;if(te.type==="error-json"){ye.push({type:"web_search_tool_result",tool_use_id:Z.toolCallId,content:{type:"web_search_tool_result_error",error_code:At(te.value).errorCode??"unavailable"},...We&&{caller:We},cache_control:Ue});break}if(te.type!=="json"){B.push({type:"other",message:`provider executed tool result output type ${te.type} for tool ${Z.toolName} is not supported`});break}let ue=await x({value:te.value,schema:po});ye.push({type:"web_search_tool_result",tool_use_id:Z.toolCallId,content:ue.map((Ye)=>({url:Ye.url,title:Ye.title,page_age:Ye.pageAge,encrypted_content:Ye.encryptedContent,type:Ye.type})),...We&&{caller:We},cache_control:Ue});break}if(Oe==="tool_search_tool_regex"||Oe==="tool_search_tool_bm25"){let te=Z.output;if(te.type==="error-json"||te.type==="json"&&te.value!=null&&typeof te.value==="object"&&!Array.isArray(te.value)&&"type"in te.value&&te.value.type==="tool_search_tool_result_error"){ye.push({type:"tool_search_tool_result",tool_use_id:Z.toolCallId,content:{type:"tool_search_tool_result_error",error_code:At(te.value).errorCode??"unavailable"},cache_control:Ue});break}if(te.type!=="json"){B.push({type:"other",message:`provider executed tool result output type ${te.type} for tool ${Z.toolName} is not supported`});break}let ue=(await x({value:te.value,schema:fo})).map((Ye)=>({type:"tool_reference",tool_name:Ye.toolName}));ye.push({type:"tool_search_tool_result",tool_use_id:Z.toolCallId,content:{type:"tool_search_tool_search_result",tool_references:ue},cache_control:Ue});break}if(Oe==="advisor"){let te=Z.output;if(te.type!=="json"&&te.type!=="error-json"){B.push({type:"other",message:`provider executed tool result output type ${te.type} for tool ${Z.toolName} is not supported`});break}let ue=await x({value:te.value,schema:co});if(ue.type==="advisor_result")ye.push({type:"advisor_tool_result",tool_use_id:Z.toolCallId,content:{type:"advisor_result",text:ue.text,...ue.stopReason!==void 0&&{stop_reason:ue.stopReason}},cache_control:Ue});else if(ue.type==="advisor_redacted_result")ye.push({type:"advisor_tool_result",tool_use_id:Z.toolCallId,content:{type:"advisor_redacted_result",encrypted_content:ue.encryptedContent,...ue.stopReason!==void 0&&{stop_reason:ue.stopReason}},cache_control:Ue});else ye.push({type:"advisor_tool_result",tool_use_id:Z.toolCallId,content:{type:"advisor_tool_result_error",error_code:ue.errorCode},cache_control:Ue});break}B.push({type:"other",message:`provider executed tool result for tool ${Z.toolName} is not supported`});break}}}}if(ye.length>0)Ce.push({role:"assistant",content:Pn(ye)});break}default:throw Error(`content type: ${Ee}`)}}let Ve=new Set;for(let Le of Ce){if(Le.role!=="assistant")continue;for(let Re of Le.content)if(Re.type==="server_tool_use"&&Re.name==="code_execution")Ve.add(Re.id)}let Je=new Set;for(let Le=0;Le<Ze;Le++){let Re=Ce[Le];if(Re.role!=="assistant")continue;for(let J of Re.content){if(!("caller"in J))continue;let Ee=J.caller;if(Ee==null||Ee.type==="direct"||Ve.has(Ee.tool_id))continue;let ye="id"in J?J.id:J.tool_use_id;if(delete J.caller,!Je.has(ye))Je.add(ye),B.push({type:"other",message:`Omitted caller metadata for tool ${ye} because source code execution tool ${Ee.tool_id} is missing from the conversation history.`})}}return{prompt:{system:$e,messages:Ce},betas:ie}}function Hn(m){let A=[],B=void 0;for(let V of m){let{role:me}=V;switch(me){case"system":if(B?.type!=="system")B={type:"system",messages:[]},A.push(B);B.messages.push(V);break;case"assistant":if(B?.type!=="assistant")B={type:"assistant",messages:[]},A.push(B);B.messages.push(V);break;case"user":if(B?.type!=="user")B={type:"user",messages:[]},A.push(B);B.messages.push(V);break;case"tool":if(B?.type!=="user")B={type:"user",messages:[]},A.push(B);B.messages.push(V);break;default:throw Error(`Unsupported role: ${me}`)}}return A}function Pn(m){let A=[],B=[];function V(){A.push(...B.filter((me)=>me.type!=="tool_use"),...B.filter((me)=>me.type==="tool_use")),B=[]}for(let me of m)if(me.type==="thinking"||me.type==="redacted_thinking"||me.type==="fallback")V(),A.push(me);else B.push(me);return V(),A}function zt({toolName:m,providerOptions:A,toolsetNames:B}){let V=B[m];if(V!=null)return V;let me=A?.anthropic?.toolsetName;return typeof me==="string"?me:void 0}function Wt(m){let A=m?.anthropic?.caller;if((A?.type==="code_execution_20250825"||A?.type==="code_execution_20260120")&&A.toolId)return{type:A.type,tool_id:A.toolId};return A?.type==="direct"?{type:"direct"}:void 0}function Vt(m){return typeof m==="object"&&m!==null&&!Array.isArray(m)?m:{rawInvalidInput:m}}function St({finishReason:m,isJsonResponseFromTool:A}){switch(m){case"pause_turn":case"end_turn":case"stop_sequence":return"stop";case"refusal":return"content-filter";case"tool_use":return A?"stop":"tool-calls";case"max_tokens":case"model_context_window_exceeded":return"length";case"compaction":return"other";default:return"other"}}var yo=new Set(["date-time","time","date","duration","email","hostname","uri","ipv4","ipv6","uuid"]),Ln=["minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf","minLength","maxLength","pattern","minItems","maxItems","uniqueItems","minProperties","maxProperties","not"];function Fn(m){return bo(m)}function mt(m){if(typeof m==="boolean"||!L(m))return m;return bo(m)}function bo(m){let A={},B=m;if(m.$ref!=null)return{$ref:m.$ref};if(m.$schema!=null)A.$schema=m.$schema;if(m.$id!=null)A.$id=m.$id;if(m.title!=null)A.title=m.title;if(m.description!=null)A.description=m.description;if(m.default!==void 0)A.default=m.default;if(m.const!==void 0)A.const=m.const;if(m.enum!=null)A.enum=m.enum;if(m.type!=null)A.type=m.type;if(m.anyOf!=null)A.anyOf=m.anyOf.map(mt);else if(m.oneOf!=null)A.anyOf=m.oneOf.map(mt);if(m.allOf!=null)A.allOf=m.allOf.map(mt);if(m.definitions!=null)A.definitions=Object.fromEntries(Object.entries(m.definitions).map(([me,Ne])=>[me,mt(Ne)]));if(B.$defs!=null){let me=A;me.$defs=Object.fromEntries(Object.entries(B.$defs).map(([Ne,K])=>[Ne,mt(K)]))}if(m.type==="object"||m.properties!=null){if(m.properties!=null)A.properties=Object.fromEntries(Object.entries(m.properties).map(([me,Ne])=>[me,mt(Ne)]));if(A.additionalProperties=!1,m.required!=null)A.required=m.required}if(m.items!=null)A.items=Array.isArray(m.items)?m.items.map(mt):mt(m.items);if(typeof m.format==="string"&&yo.has(m.format))A.format=m.format;let V=Jn(m);if(V!=null)A.description=A.description==null?V:`${A.description}
|
|
2
|
-
${V}`;return A}function Jn(m){let A=Ln.flatMap((B)=>{let V=m[B];if(V==null||V===!1)return[];return`${Kn(B)}: ${zn(V)}`});if(typeof m.format==="string"&&!yo.has(m.format))A.push(`format: ${m.format}`);return A.length===0?void 0:`${A.join("; ")}.`}function Kn(m){return m.replace(/[A-Z]/g,(A)=>` ${A.toLowerCase()}`)}function zn(m){if(typeof m==="string")return m;return JSON.stringify(m)}function Wn(m){let A=Vn(m.type);return xe({message:m.message,type:m.type,code:m.code??void 0,statusCode:m.statusCode??A.statusCode,isRetryable:m.isRetryable??A.isRetryable,data:"data"in m?m.data:m})}function Vn(m){switch(m){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 Nt(m,A,B){if(m.type==="web_search_result_location")return{type:"source",sourceType:"url",id:B(),url:m.url,title:m.title??void 0,providerMetadata:{anthropic:{citedText:m.cited_text,encryptedIndex:m.encrypted_index}}};if(m.type!=="page_location"&&m.type!=="char_location")return;let V=A[m.document_index];if(!V)return;return{type:"source",sourceType:"document",id:B(),mediaType:V.mediaType,title:m.document_title??V.title,filename:V.filename,providerMetadata:{anthropic:m.type==="page_location"?{citedText:m.cited_text,startPageNumber:m.start_page_number,endPageNumber:m.end_page_number}:{citedText:m.cited_text,startCharIndex:m.start_char_index,endCharIndex:m.end_char_index}}}}function vt(m){return m==null?void 0:{type:m.type,toolId:"tool_id"in m?m.tool_id:void 0}}function at(m){let A=vt(m);return A==null?{}:{providerMetadata:{anthropic:{caller:A}}}}function Xn(m){let A={};for(let B of m??[])if(B.type==="provider"&&B.id==="anthropic.computer_toolset_20260801")A[B.name]="computer";return A}function Xt({memberName:m,input:A}){return{action:m,...typeof A==="object"&&A!==null&&!Array.isArray(A)?A:{}}}function Gt(m){let A=m.indexOf(".");return A===-1?m:m.substring(0,A)}var xo=class m{static[k](A){return E({modelId:A.modelId,config:A.config})}static[T](A){return new m(A.modelId,A.config)}constructor(A,B){this.specificationVersion="v4",this.modelId=A,this.config=B,this.generateId=B.generateId??C}supportsUrl(A){return A.protocol==="https:"}get provider(){return this.config.provider}get supportedUrls(){return this.config.supportedUrls?.()??{}}static async prepareRequest({modelId:A,config:B,options:{userSuppliedBetas:V,prompt:me,maxOutputTokens:Ne,temperature:K,topP:ie,topK:se,frequencyPenalty:fe,presencePenalty:$e,stopSequences:Ce,responseFormat:Ze,seed:ve,tools:ke,toolChoice:Me,reasoning:Ve,providerOptions:Je,stream:Le}}){let Re=[];if(fe!=null)Re.push({type:"unsupported",feature:"frequencyPenalty"});if($e!=null)Re.push({type:"unsupported",feature:"presencePenalty"});if(ve!=null)Re.push({type:"unsupported",feature:"seed"});let J=B.maxTemperature??1,Ee=B.maxTemperature==null?"anthropic":Gt(B.provider);if(K!=null&&K>J)Re.push({type:"unsupported",feature:"temperature",details:`${K} exceeds ${Ee} maximum of ${J.toFixed(1)}. clamped to ${J.toFixed(1)}`}),K=J;else if(K!=null&&K<0)Re.push({type:"unsupported",feature:"temperature",details:`${K} is below ${Ee} minimum of 0. clamped to 0`}),K=0;if(Ze?.type==="json"){if(Ze.schema==null)Re.push({type:"unsupported",feature:"responseFormat",details:"JSON response format requires a schema. The response format is ignored."})}let ye=Gt(B.provider),Pe=await h({provider:"anthropic",providerOptions:Je,schema:Jt}),ot=ye!=="anthropic"?await h({provider:ye,providerOptions:Je,schema:Jt}):null,He=ot!=null,X=Object.assign({},Pe??{},ot??{}),{maxOutputTokens:Te,supportsStructuredOutput:Xe,supportsAdaptiveThinking:Z,rejectsSamplingParameters:nt,supportsXhighEffort:Ue,rejectsThinkingDisabledAboveHighEffort:Oe,rejectsThinkingDisabled:We,rejectsBudgetThinking:te,rejectsForcedToolUse:ue,supportsBetweenToolsThinking:Ye,isKnownModel:ft}=Gn(A);if(!ft&&Ne==null)Re.push({type:"compatibility",feature:"maxOutputTokens",details:`The model "${A}" is unknown. The max output tokens have been limited to ${Te}. Set maxOutputTokens explicitly to override this limit.`});if(nt){if(K!=null)Re.push({type:"unsupported",feature:"temperature",details:`temperature is not supported by ${A} and will be ignored`}),K=void 0;if(se!=null)Re.push({type:"unsupported",feature:"topK",details:`topK is not supported by ${A} and will be ignored`}),se=void 0;if(ie!=null)Re.push({type:"unsupported",feature:"topP",details:`topP is not supported by ${A} and will be ignored`}),ie=void 0}let yt=ft||A.includes("claude-"),bt=(B.supportsNativeStructuredOutput??!0)&&Xe,kt=(B.supportsStrictTools??!0)&&Xe,dt=X?.structuredOutputMode??"auto",Qe=dt==="outputFormat"||dt==="auto"&&bt;if(!Qe&&ue&&bt&&Ze?.type==="json"&&Ze.schema!=null)Re.push({type:"unsupported",feature:"providerOptions.anthropic.structuredOutputMode",details:`structuredOutputMode 'jsonTool' is not supported by ${A} because it rejects forced tool use. Using 'outputFormat' instead.`}),Qe=!0;let je=Ze?.type==="json"&&Ze.schema!=null&&!Qe?{type:"function",name:"json",description:"Respond with a JSON object.",inputSchema:Ze.schema}:void 0;if(je!=null&&X?.disableParallelToolUse===!1)Re.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 ee=X?.contextManagement,q=X?.compaction;if(ee!=null&&q!=null)throw new b({argument:"providerOptions",message:"Anthropic provider options `compaction` and `contextManagement` cannot be used together."});let De=new $t(B.cacheControlProviderOptionsName),be=le({tools:ke,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.computer_20251124":"computer","anthropic.computer_toolset_20260801":"computer","anthropic.text_editor_20241022":"str_replace_editor","anthropic.text_editor_20250124":"str_replace_editor","anthropic.text_editor_20250429":"str_replace_based_edit_tool","anthropic.text_editor_20250728":"str_replace_based_edit_tool","anthropic.bash_20241022":"bash","anthropic.bash_20250124":"bash","anthropic.memory_20250818":"memory","anthropic.web_search_20250305":"web_search","anthropic.web_search_20260209":"web_search","anthropic.web_search_20260318":"web_search","anthropic.web_fetch_20250910":"web_fetch","anthropic.web_fetch_20260209":"web_fetch","anthropic.web_fetch_20260318":"web_fetch","anthropic.tool_search_regex_20251119":"tool_search_tool_regex","anthropic.tool_search_bm25_20251119":"tool_search_tool_bm25","anthropic.advisor_20260301":"advisor"}}),ze=Xn(ke),{prompt:_t,betas:tt}=await Dn({prompt:me,sendReasoning:X?.sendReasoning??!0,warnings:Re,cacheControlValidator:De,toolNameMapping:be,toolsetNames:ze,convertMediaPart:B.convertMediaPart});if(W(Ve)&&X?.effort==null){let Ie=Zn({reasoning:Ve,modelId:A,supportsAdaptiveThinking:Z,supportsXhighEffort:Ue,rejectsThinkingDisabled:We,supportsBetweenToolsThinking:Ye,maxOutputTokensForModel:Te,warnings:Re});if(Ie!=null){if(X.thinking==null)X.thinking=Ie.thinking;if(Ie.effort!=null&&X.thinking?.type!=="disabled")X.effort=Ie.effort}}if(We&&X?.thinking!=null){let Ie=X.thinking;if(Ie.type==="disabled"&&Ye)Re.push({type:"unsupported",feature:"providerOptions.anthropic.thinking",details:`thinking cannot be disabled for ${A}. Using 'between_tools' thinking, the lowest thinking setting, instead.`}),X.thinking={type:"between_tools"};else if(Ie.type==="disabled")Re.push({type:"unsupported",feature:"providerOptions.anthropic.thinking",details:`thinking cannot be disabled for ${A}; it always uses adaptive thinking. The thinking setting has been removed. Lower 'effort' to reduce thinking.`}),X.thinking=void 0}if(te&&X?.thinking?.type==="enabled")Re.push({type:"unsupported",feature:"providerOptions.anthropic.thinking",details:We?`budget-based thinking is not supported by ${A}; it always uses adaptive thinking. Using adaptive thinking instead. Use 'effort' to control how much the model thinks.`:`budget-based thinking is not supported by ${A}. Using adaptive thinking instead. Use 'effort' to control how much the model thinks.`}),X.thinking={type:"adaptive"};if(Oe&&X?.thinking?.type==="disabled"&&(X.effort==="xhigh"||X.effort==="max"))Re.push({type:"unsupported",feature:"providerOptions.anthropic.effort",details:`effort '${X.effort}' is not supported by ${A} when thinking is disabled. The effort has been lowered to 'high'.`}),X.effort="high";if(X?.thinking?.type==="between_tools"&&(X.effort==="xhigh"||X.effort==="max"))Re.push({type:"unsupported",feature:"providerOptions.anthropic.effort",details:`effort '${X.effort}' is not supported with 'between_tools' thinking. The effort has been lowered to 'high'.`}),X.effort="high";let rt=X?.thinking?.type,Ht=rt==="enabled"||rt==="adaptive"||rt==="between_tools",wt=X?.thinking!=null&&"blockBinding"in X.thinking?X.thinking.blockBinding:void 0,jo=Ht||rt==="disabled"||wt!=null,xt=rt==="enabled"?X?.thinking?.budgetTokens:void 0,Ot=rt==="adaptive"?X?.thinking?.display:void 0,Pt=Ne??Te,lt={model:A,max_tokens:Pt,temperature:K,top_k:se,top_p:ie,stop_sequences:Ce,...jo&&{thinking:{...rt!=null&&{type:rt},...xt!=null&&{budget_tokens:xt},...Ot!=null&&{display:Ot},...wt!=null&&{block_binding:{prefix_mismatch_behavior:wt.prefixMismatchBehavior}}}},...(X?.effort||X?.taskBudget||Qe&&Ze?.type==="json"&&Ze.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}}},...Qe&&Ze?.type==="json"&&Ze.schema!=null&&{format:{type:"json_schema",schema:Fn(Ze.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((Ie)=>({type:Ie.type,name:Ie.name,url:Ie.url,authorization_token:Ie.authorizationToken,tool_configuration:Ie.toolConfiguration?{allowed_tools:Ie.toolConfiguration.allowedTools,enabled:Ie.toolConfiguration.enabled}:void 0}))},...X?.container&&{container:X.container.skills&&X.container.skills.length>0?{id:X.container.id,skills:X.container.skills.map((Ie)=>({type:Ie.type,skill_id:Ie.type==="custom"?H({reference:Ie.providerReference,provider:"anthropic"}):Ie.skillId,version:Ie.version}))}:X.container.id},system:_t.system,messages:_t.messages,...X?.safeguards&&X.safeguards.length>0&&{safeguards:X.safeguards.map((Ie)=>({type:Ie.type,...Ie.classifierContext!==void 0&&{classifier_context:Ie.classifierContext}}))},...q&&{compaction:{type:q.type,...q.instructions!==void 0&&{instructions:q.instructions}}},...ee&&{context_management:{edits:ee.edits.map((Ie)=>{let Ft=Ie.type;switch(Ft){case"clear_tool_uses_20250919":return{type:Ie.type,...Ie.trigger!==void 0&&{trigger:Ie.trigger},...Ie.keep!==void 0&&{keep:Ie.keep},...Ie.clearAtLeast!==void 0&&{clear_at_least:Ie.clearAtLeast},...Ie.clearToolInputs!==void 0&&{clear_tool_inputs:Ie.clearToolInputs},...Ie.excludeTools!==void 0&&{exclude_tools:Ie.excludeTools}};case"clear_thinking_20251015":return{type:Ie.type,...Ie.keep!==void 0&&{keep:Ie.keep}};case"compact_20260112":return{type:Ie.type,...Ie.trigger!==void 0&&{trigger:Ie.trigger},...Ie.pauseAfterCompaction!==void 0&&{pause_after_compaction:Ie.pauseAfterCompaction},...Ie.instructions!==void 0&&{instructions:Ie.instructions}};default:Re.push({type:"other",message:`Unknown context management strategy: ${Ft}`});return}}).filter((Ie)=>Ie!==void 0)}}};if(Ht){if(rt==="enabled"&&xt==null)Re.push({type:"compatibility",feature:"extended thinking",details:"thinking budget is required when thinking is enabled. using default budget of 1024 tokens."}),lt.thinking={type:"enabled",budget_tokens:1024},xt=1024;if(lt.temperature!=null&&!B.supportsTemperatureAndTopPWithThinking)lt.temperature=void 0,Re.push({type:"unsupported",feature:"temperature",details:"temperature is not supported when thinking is enabled"});if(se!=null)lt.top_k=void 0,Re.push({type:"unsupported",feature:"topK",details:"topK is not supported when thinking is enabled"});if(ie!=null&&!B.supportsTemperatureAndTopPWithThinking)lt.top_p=void 0,Re.push({type:"unsupported",feature:"topP",details:"topP is not supported when thinking is enabled"});lt.max_tokens=Pt+(xt??0)}else if(yt&&ie!=null&&K!=null)Re.push({type:"unsupported",feature:"topP",details:"topP is not supported when temperature is set. topP is ignored."}),lt.top_p=void 0;if(ft&<.max_tokens>Te){if(Ne!=null)Re.push({type:"unsupported",feature:"maxOutputTokens",details:`${lt.max_tokens} (maxOutputTokens + thinkingBudget) is greater than ${A} ${Te} max output tokens. The max output tokens have been limited to ${Te}.`});lt.max_tokens=Te}if(X?.mcpServers&&X.mcpServers.length>0)tt.add("mcp-client-2025-04-04");if(X?.safeguards&&X.safeguards.length>0)tt.add("dangerous-tool-use-2026-09-03");if(q)tt.add("compact-2026-09-04");if(ee){if(tt.add("context-management-2025-06-27"),ee.edits.some((Ie)=>Ie.type==="compact_20260112"))tt.add("compact-2026-01-12")}if(X?.container&&X.container.skills&&X.container.skills.length>0){if(tt.add("code-execution-2025-08-25"),tt.add("skills-2025-10-02"),tt.add("files-api-2025-04-14"),!ke?.some((Ie)=>Ie.type==="provider"&&(Ie.id==="anthropic.code_execution_20250825"||Ie.id==="anthropic.code_execution_20260120")))Re.push({type:"other",message:"code execution tool is required when using skills"})}if(X?.taskBudget)tt.add("task-budgets-2026-03-13");if(X?.speed==="fast")tt.add("fast-mode-2026-02-01");if(Ot==="updates")tt.add("thinking-display-updates-2026-08-18");if(wt!=null)tt.add("thinking-binding-controls-2026-08-01");if(X?.fallbacks==="default")tt.add("server-side-fallback-2026-07-01");else if(X?.fallbacks&&X.fallbacks.length>0)tt.add("server-side-fallback-2026-06-01");let Lt=Le&&(X?.toolStreaming??!0),{tools:To,toolChoice:Co,toolWarnings:So,betas:No}=await Tn(je!=null?{tools:[...ke??[],je],toolChoice:{type:"required"},disableParallelToolUse:!0,cacheControlValidator:De,supportsStructuredOutput:!1,supportsStrictTools:kt,defaultEagerInputStreaming:Lt,rejectsForcedToolUse:ue||rt==="enabled"}:{tools:ke??[],toolChoice:Me,disableParallelToolUse:X?.disableParallelToolUse,cacheControlValidator:De,supportsStructuredOutput:bt,supportsStrictTools:kt,defaultEagerInputStreaming:Lt,rejectsForcedToolUse:ue||rt==="enabled"}),Oo=De.getWarnings();return{args:{...lt,tools:To,tool_choice:Co,stream:Le===!0?!0:void 0},warnings:[...Re,...So,...Oo],betas:new Set([...tt,...No,...V,...X?.anthropicBeta??[]]),usesJsonResponseTool:je!=null,toolNameMapping:be,providerOptionsName:ye,usedCustomProviderKey:He}}getArgs(A){return m.prepareRequest({modelId:this.modelId,config:this.config,options:A})}async getHeaders({betas:A,configHeaders:B,headers:V,providerOptions:me}){let Ne=d(B,V,A.size>0?{"anthropic-beta":Array.from(A).join(",")}:{});return this.config.transformRequestHeaders?this.config.transformRequestHeaders(Ne,me):Ne}getBetasFromHeaders(A,B){let V=A?.["anthropic-beta"]??"",me=B?.["anthropic-beta"]??"";return new Set([...V.toLowerCase().split(","),...me.toLowerCase().split(",")].map((Ne)=>Ne.trim()).filter((Ne)=>Ne!==""))}buildRequestUrl(A){return this.config.buildRequestUrl?.(this.config.baseURL,A)??`${this.config.baseURL}/messages`}transformRequestBody(A,B){return this.config.transformRequestBody?.(A,B)??A}extractCitationDocuments(A){let B=(V)=>{if(V.type!=="file")return!1;if(V.mediaType!=="application/pdf"&&V.mediaType!=="text/plain")return!1;return V.providerOptions?.anthropic?.citations?.enabled??!1};return A.filter((V)=>V.role==="user").flatMap((V)=>V.content).filter(B).map((V)=>{let me=V;return{title:me.filename??"Untitled Document",filename:me.filename,mediaType:me.mediaType}})}async doGenerate(A){let B=this.config.headers?await _(this.config.headers):void 0,{args:V,warnings:me,betas:Ne,usesJsonResponseTool:K,toolNameMapping:ie,providerOptionsName:se,usedCustomProviderKey:fe}=await this.getArgs({...A,stream:!1,userSuppliedBetas:this.getBetasFromHeaders(B,A.headers)}),$e=[...this.extractCitationDocuments(A.prompt)],Ce=Zt(V.tools),{responseHeaders:Ze,value:ve,rawValue:ke}=await g({url:this.buildRequestUrl(!1),headers:await this.getHeaders({betas:Ne,configHeaders:B,headers:A.headers,providerOptions:A.providerOptions}),body:this.transformRequestBody(V,Ne),failedResponseHandler:ct,successfulResponseHandler:p(Ct),abortSignal:A.abortSignal,fetch:this.config.fetch}),Me=[],Ve={},Je={},Le=!1,Re=ve.content.some((J)=>J.type==="web_search_tool_result"&&Array.isArray(J.content)&&J.content.length>0);for(let J of ve.content)switch(J.type){case"text":if(!K){let Ee=J.citations??[];if(Me.push({type:"text",text:J.text,...Ee.length>0&&{citations:Ee.map((ye)=>Bt(ye,$e))},...Ee.length>0&&{providerMetadata:{anthropic:{citations:Ee}}}}),J.citations)for(let ye of J.citations){if(ye.type==="web_search_result_location"&&Re)continue;let Pe=Nt(ye,$e,this.generateId);if(Pe)Me.push(Pe)}}break;case"thinking":Me.push({type:"reasoning",text:J.thinking,providerMetadata:{anthropic:{signature:J.signature}}});break;case"redacted_thinking":Me.push({type:"reasoning",text:"",providerMetadata:{anthropic:{redactedData:J.data}}});break;case"container_upload":Me.push({type:"custom",kind:"anthropic.container_upload",providerMetadata:{anthropic:{fileId:J.file_id}}});break;case"compaction":if(!J.content)break;Me.push({type:"text",text:J.content,providerMetadata:{anthropic:{type:"compaction",...J.signature!=null&&{signature:J.signature}}}});break;case"tool_use":if(K&&J.name==="json")Le=!0,Me.push({type:"text",text:JSON.stringify(J.input)});else if(J.toolset_name!=null)Me.push({type:"tool-call",toolCallId:J.id,toolName:ie.toCustomToolName(J.toolset_name),input:JSON.stringify(Xt({memberName:J.name,input:J.input})),providerMetadata:{anthropic:{toolsetName:J.toolset_name,...at(J.caller).providerMetadata?.anthropic}}});else Me.push({type:"tool-call",toolCallId:J.id,toolName:J.name,input:JSON.stringify(J.input),...at(J.caller)});break;case"server_tool_use":if(J.name==="text_editor_code_execution"||J.name==="bash_code_execution")Me.push({type:"tool-call",toolCallId:J.id,toolName:ie.toCustomToolName("code_execution"),input:JSON.stringify({type:J.name,...J.input}),providerExecuted:!0,...Ce?{dynamic:!0}:{},...at(J.caller)});else if(J.name==="web_search"||J.name==="code_execution"||J.name==="web_fetch"){let Ee=J.name==="code_execution"&&J.input!=null&&typeof J.input==="object"&&"code"in J.input&&!("type"in J.input)?{type:"programmatic-tool-call",...J.input}:J.input;Me.push({type:"tool-call",toolCallId:J.id,toolName:ie.toCustomToolName(J.name),input:JSON.stringify(Ee),providerExecuted:!0,...Ce&&J.name==="code_execution"?{dynamic:!0}:{},...at(J.caller)})}else if(J.name==="tool_search_tool_regex"||J.name==="tool_search_tool_bm25")Je[J.id]=J.name,Me.push({type:"tool-call",toolCallId:J.id,toolName:ie.toCustomToolName(J.name),input:JSON.stringify(J.input),providerExecuted:!0,...at(J.caller)});else if(J.name==="advisor")Me.push({type:"tool-call",toolCallId:J.id,toolName:ie.toCustomToolName("advisor"),input:JSON.stringify(J.input),providerExecuted:!0,...at(J.caller)});break;case"mcp_tool_use":Ve[J.id]={type:"tool-call",toolCallId:J.id,toolName:J.name,input:JSON.stringify(J.input),providerExecuted:!0,dynamic:!0,providerMetadata:{anthropic:{type:"mcp-tool-use",serverName:J.server_name}}},Me.push(Ve[J.id]);break;case"mcp_tool_result":Me.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:Ve[J.tool_use_id].toolName,isError:J.is_error,result:J.content,dynamic:!0,providerMetadata:Ve[J.tool_use_id].providerMetadata});break;case"web_fetch_tool_result":if(J.content.type==="web_fetch_result")$e.push({title:J.content.content.title??J.content.url,mediaType:J.content.content.source.media_type}),Me.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:ie.toCustomToolName("web_fetch"),result:{type:"web_fetch_result",url:J.content.url,retrievedAt:J.content.retrieved_at,content:{type:J.content.content.type,title:J.content.content.title,citations:J.content.content.citations,source:{type:J.content.content.source.type,mediaType:J.content.content.source.media_type,data:J.content.content.source.data}}},...at(J.caller)});else if(J.content.type==="web_fetch_tool_result_error")Me.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:ie.toCustomToolName("web_fetch"),isError:!0,result:{type:"web_fetch_tool_result_error",errorCode:J.content.error_code},...at(J.caller)});break;case"web_search_tool_result":if(Array.isArray(J.content)){Me.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:ie.toCustomToolName("web_search"),result:J.content.map((Ee)=>({url:Ee.url,...Ee.title!=null?{title:Ee.title}:{},pageAge:Ee.page_age??null,encryptedContent:Ee.encrypted_content,type:Ee.type})),...at(J.caller)});for(let Ee of J.content)Me.push({type:"source",sourceType:"url",id:this.generateId(),url:Ee.url,...Ee.title!=null?{title:Ee.title}:{},providerMetadata:{anthropic:{pageAge:Ee.page_age??null}}})}else Me.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:ie.toCustomToolName("web_search"),isError:!0,result:{type:"web_search_tool_result_error",errorCode:J.content.error_code},...at(J.caller)});break;case"code_execution_tool_result":if(J.content.type==="code_execution_result")Me.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:ie.toCustomToolName("code_execution"),result:{type:J.content.type,stdout:J.content.stdout,stderr:J.content.stderr,return_code:J.content.return_code,content:J.content.content??[]}});else if(J.content.type==="encrypted_code_execution_result")Me.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:ie.toCustomToolName("code_execution"),result:{type:J.content.type,encrypted_stdout:J.content.encrypted_stdout,stderr:J.content.stderr,return_code:J.content.return_code,content:J.content.content??[]}});else if(J.content.type==="code_execution_tool_result_error")Me.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:ie.toCustomToolName("code_execution"),isError:!0,result:{type:"code_execution_tool_result_error",errorCode:J.content.error_code}});break;case"bash_code_execution_tool_result":case"text_editor_code_execution_tool_result":Me.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:ie.toCustomToolName("code_execution"),result:J.content});break;case"tool_search_tool_result":{let Ee=Je[J.tool_use_id];if(Ee==null){let ye=ie.toCustomToolName("tool_search_tool_bm25"),Pe=ie.toCustomToolName("tool_search_tool_regex");if(ye!=="tool_search_tool_bm25")Ee="tool_search_tool_bm25";else if(Pe!=="tool_search_tool_regex")Ee="tool_search_tool_regex";else Ee="tool_search_tool_regex"}if(J.content.type==="tool_search_tool_search_result")Me.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:ie.toCustomToolName(Ee),result:J.content.tool_references.map((ye)=>({type:ye.type,toolName:ye.tool_name}))});else Me.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:ie.toCustomToolName(Ee),isError:!0,result:{type:"tool_search_tool_result_error",errorCode:J.content.error_code}});break}case"advisor_tool_result":{let Ee=ie.toCustomToolName("advisor");if(J.content.type==="advisor_result")Me.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:Ee,result:{type:"advisor_result",text:J.content.text,...J.content.stop_reason!=null&&{stopReason:J.content.stop_reason}}});else if(J.content.type==="advisor_redacted_result")Me.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:Ee,result:{type:"advisor_redacted_result",encryptedContent:J.content.encrypted_content,...J.content.stop_reason!=null&&{stopReason:J.content.stop_reason}}});else Me.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:Ee,isError:!0,result:{type:"advisor_tool_result_error",errorCode:J.content.error_code}});break}case"fallback":Me.push({type:"custom",kind:"anthropic.fallback",providerMetadata:{anthropic:{type:"fallback",from:J.from,to:J.to}}})}return{content:Me,finishReason:{unified:St({finishReason:ve.stop_reason,isJsonResponseFromTool:Le}),raw:ve.stop_reason??void 0},usage:Mt({usage:ve.usage}),request:{body:V},response:{id:ve.id??void 0,modelId:ve.model??void 0,headers:Ze,body:ke},warnings:me,providerMetadata:(()=>{let J=Qt(ve.stop_details),Ee={usage:ve.usage,stopSequence:ve.stop_sequence??null,...J!=null?{stopDetails:J}:{},...ve.input_transformations!=null?{inputTransformations:ve.input_transformations}:{},...ve.safeguard_results!=null?{safeguardResults:ve.safeguard_results}:{},iterations:ve.usage.iterations?ve.usage.iterations.map((Pe)=>({type:Pe.type,...Pe.model!=null?{model:Pe.model}:{},inputTokens:Pe.input_tokens,outputTokens:Pe.output_tokens,...Pe.cache_creation_input_tokens?{cacheCreationInputTokens:Pe.cache_creation_input_tokens}:{},...Pe.cache_read_input_tokens?{cacheReadInputTokens:Pe.cache_read_input_tokens}:{}})):null,container:ve.container?{expiresAt:ve.container.expires_at,id:ve.container.id,skills:ve.container.skills?.map((Pe)=>({type:Pe.type,skillId:Pe.skill_id,version:Pe.version}))??null}:null,contextManagement:Yt(ve.context_management)??null},ye={anthropic:Ee};if(fe&&se!=="anthropic")ye[se]=Ee;return ye})()}}async doStream(A){let B=this.config.headers?await _(this.config.headers):void 0,{args:V,warnings:me,betas:Ne,usesJsonResponseTool:K,toolNameMapping:ie,providerOptionsName:se,usedCustomProviderKey:fe}=await this.getArgs({...A,stream:!0,userSuppliedBetas:this.getBetasFromHeaders(B,A.headers)}),$e=[...this.extractCitationDocuments(A.prompt)],Ce=Zt(V.tools),Ze=this.buildRequestUrl(!0),{responseHeaders:ve,value:ke}=await g({url:Ze,headers:await this.getHeaders({betas:Ne,configHeaders:B,headers:A.headers,providerOptions:A.providerOptions}),body:this.transformRequestBody(V,Ne),failedResponseHandler:ct,successfulResponseHandler:D(Eo),abortSignal:A.abortSignal,fetch:this.config.fetch}),Me={unified:"other",raw:void 0},Ve={input_tokens:0,output_tokens:0,cache_creation_input_tokens:0,cache_read_input_tokens:0,iterations:null},Je={},Le={},Re={},J=null,Ee=void 0,ye=null,Pe=void 0,ot,He,X=null,Te=!1,Xe=!1,Z=[],nt=!1,Ue,Oe=!1,We=void 0,te=this.generateId,ue=ke.pipeThrough(new TransformStream({start(Qe){Qe.enqueue({type:"stream-start",warnings:me})},transform(Qe,je){if(Oe)return;if(A.includeRawChunks)je.enqueue({type:"raw",rawValue:Qe.rawValue});if(!Qe.success){je.enqueue({type:"error",error:Qe.error});return}let ee=Qe.value;switch(ee.type){case"ping":return;case"content_block_start":{let q=ee.content_block,De=q.type;if(De==="fallback"){je.enqueue({type:"custom",kind:"anthropic.fallback",providerMetadata:{anthropic:{type:"fallback",from:q.from,to:q.to}}});return}switch(We=De,De){case"text":if(K)return;Je[ee.index]={type:"text",citations:[]},je.enqueue({type:"text-start",id:String(ee.index)});return;case"thinking":Je[ee.index]={type:"reasoning"},je.enqueue({type:"reasoning-start",id:String(ee.index)});return;case"redacted_thinking":Je[ee.index]={type:"reasoning"},je.enqueue({type:"reasoning-start",id:String(ee.index),providerMetadata:{anthropic:{redactedData:q.data}}});return;case"compaction":if(Je[ee.index]={type:"text",citations:[]},je.enqueue({type:"text-start",id:String(ee.index),providerMetadata:{anthropic:{type:"compaction",...q.signature!=null&&{signature:q.signature}}}}),q.signature!=null&&q.content!=null&&q.content!=="")je.enqueue({type:"text-delta",id:String(ee.index),delta:q.content});return;case"tool_use":if(K&&q.name==="json")Te=!0,Je[ee.index]={type:"text",citations:[]},je.enqueue({type:"text-start",id:String(ee.index)});else if(q.toolset_name!=null){let be=vt(q.caller),ze=ie.toCustomToolName(q.toolset_name),_t=q.input&&Object.keys(q.input).length>0;Je[ee.index]={type:"tool-call",toolCallId:q.id,toolName:ze,input:_t?JSON.stringify(q.input):"",firstDelta:!0,toolset:{name:q.toolset_name,memberName:q.name},...be&&{caller:be}},je.enqueue({type:"tool-input-start",id:q.id,toolName:ze})}else{let be=vt(q.caller),ze=q.input&&Object.keys(q.input).length>0?JSON.stringify(q.input):"";Je[ee.index]={type:"tool-call",toolCallId:q.id,toolName:q.name,input:ze,firstDelta:ze.length===0,...be&&{caller:be}},je.enqueue({type:"tool-input-start",id:q.id,toolName:q.name})}return;case"server_tool_use":{let be=vt(q.caller);if(["web_fetch","web_search","code_execution","text_editor_code_execution","bash_code_execution"].includes(q.name)){let ze=q.name==="text_editor_code_execution"||q.name==="bash_code_execution"?"code_execution":q.name,_t=q.name==="text_editor_code_execution"||q.name==="bash_code_execution"?q.name:q.name==="code_execution"?"programmatic-tool-call":void 0,tt=ie.toCustomToolName(ze),rt=q.input!=null&&typeof q.input==="object"&&Object.keys(q.input).length>0?JSON.stringify(q.input):"";Je[ee.index]={type:"tool-call",toolCallId:q.id,toolName:tt,input:rt,providerExecuted:!0,...Ce&&ze==="code_execution"?{dynamic:!0}:{},firstDelta:rt.length===0,providerToolName:ze,providerToolInputType:_t,...be&&{caller:be}},je.enqueue({type:"tool-input-start",id:q.id,toolName:tt,providerExecuted:!0,...Ce&&ze==="code_execution"?{dynamic:!0}:{}})}else if(q.name==="tool_search_tool_regex"||q.name==="tool_search_tool_bm25"){Re[q.id]=q.name;let ze=ie.toCustomToolName(q.name);Je[ee.index]={type:"tool-call",toolCallId:q.id,toolName:ze,input:"",providerExecuted:!0,firstDelta:!0,providerToolName:q.name,...be&&{caller:be}},je.enqueue({type:"tool-input-start",id:q.id,toolName:ze,providerExecuted:!0})}else if(q.name==="advisor"){let ze=ie.toCustomToolName("advisor");Je[ee.index]={type:"tool-call",toolCallId:q.id,toolName:ze,input:"{}",providerExecuted:!0,firstDelta:!0,providerToolName:q.name,...be&&{caller:be}},je.enqueue({type:"tool-input-start",id:q.id,toolName:ze,providerExecuted:!0})}return}case"web_fetch_tool_result":if(q.content.type==="web_fetch_result")$e.push({title:q.content.content.title??q.content.url,mediaType:q.content.content.source.media_type}),je.enqueue({type:"tool-result",toolCallId:q.tool_use_id,toolName:ie.toCustomToolName("web_fetch"),result:{type:"web_fetch_result",url:q.content.url,retrievedAt:q.content.retrieved_at,content:{type:q.content.content.type,title:q.content.content.title,citations:q.content.content.citations,source:{type:q.content.content.source.type,mediaType:q.content.content.source.media_type,data:q.content.content.source.data}}},...at(q.caller)});else if(q.content.type==="web_fetch_tool_result_error")je.enqueue({type:"tool-result",toolCallId:q.tool_use_id,toolName:ie.toCustomToolName("web_fetch"),isError:!0,result:{type:"web_fetch_tool_result_error",errorCode:q.content.error_code},...at(q.caller)});return;case"web_search_tool_result":if(Array.isArray(q.content)){je.enqueue({type:"tool-result",toolCallId:q.tool_use_id,toolName:ie.toCustomToolName("web_search"),result:q.content.map((be)=>({url:be.url,...be.title!=null?{title:be.title}:{},pageAge:be.page_age??null,encryptedContent:be.encrypted_content,type:be.type})),...at(q.caller)});for(let be of q.content)Xe=!0,je.enqueue({type:"source",sourceType:"url",id:te(),url:be.url,...be.title!=null?{title:be.title}:{},providerMetadata:{anthropic:{pageAge:be.page_age??null}}})}else je.enqueue({type:"tool-result",toolCallId:q.tool_use_id,toolName:ie.toCustomToolName("web_search"),isError:!0,result:{type:"web_search_tool_result_error",errorCode:q.content.error_code},...at(q.caller)});return;case"code_execution_tool_result":if(q.content.type==="code_execution_result")je.enqueue({type:"tool-result",toolCallId:q.tool_use_id,toolName:ie.toCustomToolName("code_execution"),result:{type:q.content.type,stdout:q.content.stdout,stderr:q.content.stderr,return_code:q.content.return_code,content:q.content.content??[]}});else if(q.content.type==="encrypted_code_execution_result")je.enqueue({type:"tool-result",toolCallId:q.tool_use_id,toolName:ie.toCustomToolName("code_execution"),result:{type:q.content.type,encrypted_stdout:q.content.encrypted_stdout,stderr:q.content.stderr,return_code:q.content.return_code,content:q.content.content??[]}});else if(q.content.type==="code_execution_tool_result_error")je.enqueue({type:"tool-result",toolCallId:q.tool_use_id,toolName:ie.toCustomToolName("code_execution"),isError:!0,result:{type:"code_execution_tool_result_error",errorCode:q.content.error_code}});return;case"bash_code_execution_tool_result":case"text_editor_code_execution_tool_result":je.enqueue({type:"tool-result",toolCallId:q.tool_use_id,toolName:ie.toCustomToolName("code_execution"),result:q.content});return;case"tool_search_tool_result":{let be=Re[q.tool_use_id];if(be==null){let ze=ie.toCustomToolName("tool_search_tool_bm25"),_t=ie.toCustomToolName("tool_search_tool_regex");if(ze!=="tool_search_tool_bm25")be="tool_search_tool_bm25";else if(_t!=="tool_search_tool_regex")be="tool_search_tool_regex";else be="tool_search_tool_regex"}if(q.content.type==="tool_search_tool_search_result")je.enqueue({type:"tool-result",toolCallId:q.tool_use_id,toolName:ie.toCustomToolName(be),result:q.content.tool_references.map((ze)=>({type:ze.type,toolName:ze.tool_name}))});else je.enqueue({type:"tool-result",toolCallId:q.tool_use_id,toolName:ie.toCustomToolName(be),isError:!0,result:{type:"tool_search_tool_result_error",errorCode:q.content.error_code}});return}case"advisor_tool_result":{let be=ie.toCustomToolName("advisor");if(q.content.type==="advisor_result")je.enqueue({type:"tool-result",toolCallId:q.tool_use_id,toolName:be,result:{type:"advisor_result",text:q.content.text,...q.content.stop_reason!=null&&{stopReason:q.content.stop_reason}}});else if(q.content.type==="advisor_redacted_result")je.enqueue({type:"tool-result",toolCallId:q.tool_use_id,toolName:be,result:{type:"advisor_redacted_result",encryptedContent:q.content.encrypted_content,...q.content.stop_reason!=null&&{stopReason:q.content.stop_reason}}});else je.enqueue({type:"tool-result",toolCallId:q.tool_use_id,toolName:be,isError:!0,result:{type:"advisor_tool_result_error",errorCode:q.content.error_code}});return}case"mcp_tool_use":Le[q.id]={type:"tool-call",toolCallId:q.id,toolName:q.name,input:JSON.stringify(q.input),providerExecuted:!0,dynamic:!0,providerMetadata:{anthropic:{type:"mcp-tool-use",serverName:q.server_name}}},je.enqueue(Le[q.id]);return;case"mcp_tool_result":je.enqueue({type:"tool-result",toolCallId:q.tool_use_id,toolName:Le[q.tool_use_id].toolName,isError:q.is_error,result:q.content,dynamic:!0,providerMetadata:Le[q.tool_use_id].providerMetadata});return;default:throw Error(`Unsupported content block type: ${De}`)}}case"content_block_stop":if(Je[ee.index]!=null){let q=Je[ee.index];switch(q.type){case"text":je.enqueue({type:"text-end",id:String(ee.index),...q.citations.length>0&&{citations:q.citations.map((De)=>Bt(De,$e)),providerMetadata:{anthropic:{citations:q.citations}}}});break;case"reasoning":je.enqueue({type:"reasoning-end",id:String(ee.index)});break;case"tool-call":if(!(K&&q.toolName==="json")){if(q.toolset!=null){let be={};try{be=q.input===""?{}:Q(q.input)}catch{be=void 0}q.input=be===void 0?q.input:JSON.stringify(Xt({memberName:q.toolset.memberName,input:be})),je.enqueue({type:"tool-input-delta",id:q.toolCallId,delta:q.input})}je.enqueue({type:"tool-input-end",id:q.toolCallId});let De=q.input===""?"{}":q.input;if(q.providerToolName==="code_execution")try{let be=Q(De);if(be!=null&&typeof be==="object"&&"code"in be&&!("type"in be))De=JSON.stringify({type:"programmatic-tool-call",...be})}catch{}je.enqueue({type:"tool-call",toolCallId:q.toolCallId,toolName:q.toolName,input:De,providerExecuted:q.providerExecuted,...Ce&&q.providerToolName==="code_execution"?{dynamic:!0}:{},...(q.caller||q.toolset)&&{providerMetadata:{anthropic:{...q.toolset&&{toolsetName:q.toolset.name},...q.caller&&{caller:q.caller}}}}})}}delete Je[ee.index]}We=void 0;return;case"content_block_delta":{let q=ee.delta.type;switch(q){case"text_delta":if(K)return;je.enqueue({type:"text-delta",id:String(ee.index),delta:ee.delta.text});return;case"thinking_delta":je.enqueue({type:"reasoning-delta",id:String(ee.index),delta:ee.delta.thinking});return;case"signature_delta":if(We==="thinking")je.enqueue({type:"reasoning-delta",id:String(ee.index),delta:"",providerMetadata:{anthropic:{signature:ee.delta.signature}}});return;case"compaction_delta":if(ee.delta.content!=null)je.enqueue({type:"text-delta",id:String(ee.index),delta:ee.delta.content});return;case"input_json_delta":{let De=Je[ee.index],be=ee.delta.partial_json;if(be.length===0)return;if(Te){if(De?.type!=="text")return;je.enqueue({type:"text-delta",id:String(ee.index),delta:be})}else{if(De?.type!=="tool-call")return;if(De.toolset!=null){De.input+=be;return}if(De.firstDelta&&De.providerToolInputType!=null)be=`{"type": "${De.providerToolInputType}",${be.substring(1)}`;je.enqueue({type:"tool-input-delta",id:De.toolCallId,delta:be}),De.input+=be,De.firstDelta=!1}return}case"citations_delta":{let De=ee.delta.citation,be=Je[ee.index];if(be?.type==="text")be.citations.push(De);if(De.type==="web_search_result_location")Z.push(De);else{let ze=Nt(De,$e,te);if(ze)je.enqueue(ze)}return}default:throw Error(`Unsupported delta type: ${q}`)}}case"message_start":if(nt){if(Ue===ee.message.id)return;Oe=!0,je.enqueue({type:"error",error:new P({data:ee,message:`Received message_start for message ${JSON.stringify(ee.message.id)} while message ${JSON.stringify(Ue)} is still open.`})});return}if(nt=!0,Ue=ee.message.id,Ve.input_tokens=ee.message.usage.input_tokens,Ve.cache_read_input_tokens=ee.message.usage.cache_read_input_tokens??0,Ve.cache_creation_input_tokens=ee.message.usage.cache_creation_input_tokens??0,Ee={...ee.message.usage},ee.message.input_transformations!=null)ot=ee.message.input_transformations;if(ee.message.container!=null)X={expiresAt:ee.message.container.expires_at,id:ee.message.container.id,skills:null};if(ee.message.stop_reason!=null)Me={unified:St({finishReason:ee.message.stop_reason,isJsonResponseFromTool:Te}),raw:ee.message.stop_reason};if(je.enqueue({type:"response-metadata",id:ee.message.id??void 0,modelId:ee.message.model??void 0}),je.enqueue({type:"custom",kind:"anthropic.message_start",providerMetadata:{anthropic:{id:ee.message.id??null,model:ee.message.model??null,usage:Ee}}}),ee.message.content!=null)for(let q=0;q<ee.message.content.length;q++){let De=ee.message.content[q];if(De.type==="tool_use"){let be=vt(De.caller);je.enqueue({type:"tool-input-start",id:De.id,toolName:De.name});let ze=JSON.stringify(De.input??{});je.enqueue({type:"tool-input-delta",id:De.id,delta:ze}),je.enqueue({type:"tool-input-end",id:De.id}),je.enqueue({type:"tool-call",toolCallId:De.id,toolName:De.name,input:ze,...be&&{providerMetadata:{anthropic:{caller:be}}}})}}return;case"message_delta":if(ee.usage.input_tokens!=null&&Ve.input_tokens!==ee.usage.input_tokens)Ve.input_tokens=ee.usage.input_tokens;if(Ve.output_tokens=ee.usage.output_tokens,ee.usage.output_tokens_details!=null)Ve.output_tokens_details=ee.usage.output_tokens_details;if(ee.usage.cache_read_input_tokens!=null)Ve.cache_read_input_tokens=ee.usage.cache_read_input_tokens;if(ee.usage.cache_creation_input_tokens!=null)Ve.cache_creation_input_tokens=ee.usage.cache_creation_input_tokens;if(ee.usage.iterations!=null)Ve.iterations=ee.usage.iterations;if(Me={unified:St({finishReason:ee.delta.stop_reason,isJsonResponseFromTool:Te}),raw:ee.delta.stop_reason??void 0},ye=ee.delta.stop_sequence??null,Pe=Qt(ee.delta.stop_details),X=ee.delta.container!=null?{expiresAt:ee.delta.container.expires_at,id:ee.delta.container.id,skills:ee.delta.container.skills?.map((q)=>({type:q.type,skillId:q.skill_id,version:q.version}))??null}:null,ee.context_management)J=Yt(ee.context_management);if(ee.input_transformations!=null)ot=ee.input_transformations;if(ee.delta.safeguard_results!=null)He=ee.delta.safeguard_results;Ee={...Ee,...ee.usage};return;case"message_stop":{nt=!1,Ue=void 0;let q={usage:Ee??null,stopSequence:ye,...Pe!=null?{stopDetails:Pe}:{},...ot!=null?{inputTransformations:ot}:{},...He!=null?{safeguardResults:He}:{},iterations:Ve.iterations?Ve.iterations.map((be)=>({type:be.type,...be.model!=null?{model:be.model}:{},inputTokens:be.input_tokens,outputTokens:be.output_tokens,...be.cache_creation_input_tokens?{cacheCreationInputTokens:be.cache_creation_input_tokens}:{},...be.cache_read_input_tokens?{cacheReadInputTokens:be.cache_read_input_tokens}:{}})):null,container:X,contextManagement:J},De={anthropic:q};if(fe&&se!=="anthropic")De[se]=q;if(!Xe)for(let be of Z){let ze=Nt(be,$e,te);if(ze)je.enqueue(ze)}Z.length=0,je.enqueue({type:"finish",finishReason:Me,usage:Mt({usage:Ve,rawUsage:Ee}),providerMetadata:De});return}case"error":je.enqueue({type:"error",error:Wn(ee.error)});return;default:throw Error(`Unsupported chunk type: ${ee}`)}}})),Ye=!1,ft=!1,yt,[bt,kt]=ue.pipeThrough(new TransformStream({transform(Qe,je){switch(Qe.type){case"response-metadata":Ye=!1;break;case"finish":Ye=!1,yt=Qe;break;case"error":ft=!0;break;case"text-delta":case"reasoning-delta":case"tool-input-delta":Ye||=Qe.delta.length>0;break;case"tool-call":Ye=!0}je.enqueue(Qe)},flush(Qe){if(Ye&&!ft)Qe.enqueue({type:"finish",finishReason:{unified:"interrupted",raw:void 0},usage:yt?.usage??{inputTokens:{total:void 0,noCache:void 0,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:void 0,text:void 0,reasoning:void 0}},...yt?.providerMetadata!=null?{providerMetadata:yt.providerMetadata}:{}})}})).tee(),dt=bt.getReader();try{await dt.read();let Qe=await dt.read();if(Qe.value?.type==="raw")Qe=await dt.read();if(Qe.value?.type==="error"){let je=Qe.value.error;if(!st(je))throw Error("Expected a normalized Anthropic stream error");throw new w({message:je.message,url:Ze,requestBodyValues:V,statusCode:je.statusCode??500,responseHeaders:ve,responseBody:JSON.stringify(je.data),isRetryable:je.isRetryable??!1})}}finally{dt.cancel().catch(()=>{}),dt.releaseLock()}return{stream:kt,request:{body:V},response:{headers:ve}}}};function Gn(m){if(m.includes("claude-sonnet-5-5"))return{maxOutputTokens:128000,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!0,supportsXhighEffort:!0,rejectsThinkingDisabledAboveHighEffort:!0,rejectsThinkingDisabled:!0,rejectsBudgetThinking:!0,rejectsForcedToolUse:!0,supportsBetweenToolsThinking:!0,isKnownModel:!0};else if(m.includes("claude-opus-5-5"))return{maxOutputTokens:128000,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!0,supportsXhighEffort:!0,rejectsThinkingDisabledAboveHighEffort:!0,rejectsThinkingDisabled:!0,rejectsBudgetThinking:!0,rejectsForcedToolUse:!0,supportsBetweenToolsThinking:!1,isKnownModel:!0};else if(m.includes("claude-haiku-5-5"))return{maxOutputTokens:128000,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!0,supportsXhighEffort:!0,rejectsThinkingDisabledAboveHighEffort:!0,rejectsThinkingDisabled:!1,rejectsBudgetThinking:!0,rejectsForcedToolUse:!1,supportsBetweenToolsThinking:!1,isKnownModel:!0};else if(m.includes("claude-opus-5"))return{maxOutputTokens:128000,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!0,supportsXhighEffort:!0,rejectsThinkingDisabledAboveHighEffort:!0,rejectsThinkingDisabled:!1,rejectsBudgetThinking:!1,rejectsForcedToolUse:!1,supportsBetweenToolsThinking:!1,isKnownModel:!0};else if(m.includes("claude-fable-5-1"))return{maxOutputTokens:128000,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!0,supportsXhighEffort:!0,rejectsThinkingDisabledAboveHighEffort:!1,rejectsThinkingDisabled:!0,rejectsBudgetThinking:!0,rejectsForcedToolUse:!0,supportsBetweenToolsThinking:!1,isKnownModel:!0};else if(m.includes("claude-fable-5"))return{maxOutputTokens:128000,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!0,supportsXhighEffort:!0,rejectsThinkingDisabledAboveHighEffort:!1,rejectsThinkingDisabled:!0,rejectsBudgetThinking:!0,rejectsForcedToolUse:!1,supportsBetweenToolsThinking:!1,isKnownModel:!0};else if(m.includes("claude-opus-4-8")||m.includes("claude-opus-4-7")||m.includes("claude-sonnet-5"))return{maxOutputTokens:128000,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!0,supportsXhighEffort:!0,rejectsThinkingDisabledAboveHighEffort:!1,rejectsThinkingDisabled:!1,rejectsBudgetThinking:!1,rejectsForcedToolUse:!1,supportsBetweenToolsThinking:!1,isKnownModel:!0};else if(m.includes("claude-sonnet-4-6")||m.includes("claude-opus-4-6"))return{maxOutputTokens:128000,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!1,supportsXhighEffort:!1,rejectsThinkingDisabledAboveHighEffort:!1,rejectsThinkingDisabled:!1,rejectsBudgetThinking:!1,rejectsForcedToolUse:!1,supportsBetweenToolsThinking:!1,isKnownModel:!0};else if(m.includes("claude-sonnet-4-5")||m.includes("claude-opus-4-5")||m.includes("claude-haiku-4-5"))return{maxOutputTokens:64000,supportsStructuredOutput:!0,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,rejectsThinkingDisabledAboveHighEffort:!1,rejectsThinkingDisabled:!1,rejectsBudgetThinking:!1,rejectsForcedToolUse:!1,supportsBetweenToolsThinking:!1,isKnownModel:!0};else if(m.includes("claude-opus-4-1"))return{maxOutputTokens:32000,supportsStructuredOutput:!0,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,rejectsThinkingDisabledAboveHighEffort:!1,rejectsThinkingDisabled:!1,rejectsBudgetThinking:!1,rejectsForcedToolUse:!1,supportsBetweenToolsThinking:!1,isKnownModel:!0};else if(/claude-sonnet-4(?:-|@)/.test(m))return{maxOutputTokens:64000,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,rejectsThinkingDisabledAboveHighEffort:!1,rejectsThinkingDisabled:!1,rejectsBudgetThinking:!1,rejectsForcedToolUse:!1,supportsBetweenToolsThinking:!1,isKnownModel:!0};else if(/claude-opus-4(?:-|@)/.test(m))return{maxOutputTokens:32000,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,rejectsThinkingDisabledAboveHighEffort:!1,rejectsThinkingDisabled:!1,rejectsBudgetThinking:!1,rejectsForcedToolUse:!1,supportsBetweenToolsThinking:!1,isKnownModel:!0};else if(m.includes("claude-3-haiku"))return{maxOutputTokens:4096,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,rejectsThinkingDisabledAboveHighEffort:!1,rejectsThinkingDisabled:!1,rejectsBudgetThinking:!1,rejectsForcedToolUse:!1,supportsBetweenToolsThinking:!1,isKnownModel:!0};else if(/claude-(?:instant(?:-|$)|v?2(?=$|[-.:])|3(?=$|[-.]))/.test(m))return{maxOutputTokens:4096,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,rejectsThinkingDisabledAboveHighEffort:!1,rejectsThinkingDisabled:!1,rejectsBudgetThinking:!1,rejectsForcedToolUse:!1,supportsBetweenToolsThinking:!1,isKnownModel:!1};else if(m.includes("claude-"))return{maxOutputTokens:128000,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!0,supportsXhighEffort:!0,rejectsThinkingDisabledAboveHighEffort:!0,rejectsThinkingDisabled:!1,rejectsBudgetThinking:!1,rejectsForcedToolUse:!1,supportsBetweenToolsThinking:!1,isKnownModel:!1};else return{maxOutputTokens:4096,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,rejectsThinkingDisabledAboveHighEffort:!1,rejectsThinkingDisabled:!1,rejectsBudgetThinking:!1,rejectsForcedToolUse:!1,supportsBetweenToolsThinking:!1,isKnownModel:!1}}function Zt(m){if(!m)return!1;let A=!1,B=!1;for(let V of m){if("type"in V&&(V.type==="web_fetch_20260209"||V.type==="web_fetch_20260318"||V.type==="web_search_20260209"||V.type==="web_search_20260318")){A=!0;continue}if("type"in V&&(V.type==="code_execution_20250522"||V.type==="code_execution_20250825"||V.type==="code_execution_20260120")){B=!0;break}}return A&&!B}function Zn({reasoning:m,modelId:A,supportsAdaptiveThinking:B,supportsXhighEffort:V,rejectsThinkingDisabled:me,supportsBetweenToolsThinking:Ne,maxOutputTokensForModel:K,warnings:ie}){if(!W(m))return;if(m==="none"){if(Ne)return{thinking:{type:"between_tools"}};if(me)return ie.push({type:"compatibility",feature:"reasoning",details:`reasoning 'none' is not supported by ${A}; it always uses adaptive thinking. Using effort 'low' to minimize thinking instead.`}),{effort:"low"};return{thinking:{type:"disabled"}}}if(B)return{thinking:{type:"adaptive",display:"summarized"},effort:Se({reasoning:m,effortMap:{minimal:"low",low:"low",medium:"medium",high:"high",xhigh:V?"xhigh":"max",max:"max"},warnings:ie})};let se=it({reasoning:m,maxOutputTokens:K,maxReasoningBudget:K,warnings:ie});if(se==null)return;return{thinking:{type:"enabled",budgetTokens:se}}}function Yt(m){return m?{appliedEdits:m.applied_edits.map((A)=>{switch(A.type){case"clear_tool_uses_20250919":return{type:A.type,clearedToolUses:A.cleared_tool_uses,clearedInputTokens:A.cleared_input_tokens};case"clear_thinking_20251015":return{type:A.type,clearedThinkingTurns:A.cleared_thinking_turns,clearedInputTokens:A.cleared_input_tokens};case"compact_20260112":return{type:A.type}}}).filter((A)=>A!==void 0)}:null}function Qt(m){if(m==null)return;return{type:m.type,...m.category!=null?{category:m.category}:{},...m.explanation!=null?{explanation:m.explanation}:{},...m.recommended_model!=null?{recommendedModel:m.recommended_model}:{}}}var Yn=/^[A-Za-z0-9_-]{1,64}$/,eo=a(()=>s(t({anthropicBeta:o(e()).optional()}))),vo=()=>t({id:e(),type:n("message_batch"),processing_status:e(),request_counts:t({processing:r(),succeeded:r(),errored:r(),canceled:r(),expired:r()}),created_at:e(),expires_at:e(),archived_at:e().nullish(),cancel_initiated_at:e().nullish(),ended_at:e().nullish(),results_url:e().nullish()}),Rt=a(()=>s(vo())),Qn=a(()=>s(t({data:o(vo()),has_more:c(),last_id:e().nullish()}))),er=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"]),tr=a(()=>s(f("type",[t({type:n("succeeded"),message:v()}),t({type:n("errored"),error:t({type:n("error"),error:t({type:e(),message:e()}),request_id:e().nullish()})}),t({type:n("canceled")}),t({type:n("expired")})]))),or=a(()=>s(t({custom_id:e(),result:v()})));function nr(m){for(let A of m){let B=A.type;if(B!=="text")throw new u({functionality:`batch request type: ${B}`,message:`The Anthropic Message Batches API does not support batch requests with type "${B}".`})}}var rr=class{constructor(m){this.options=m,this.specificationVersion="v4",this.provider=m.provider,this.supportedUrls=m.supportedUrls,this.generateId=m.config.generateId??C}async doStartBatch({requests:m,providerOptions:A,headers:B,abortSignal:V,webhookUrl:me}){nr(m),ar(m);let Ne=new Set(await to({provider:this.options.config.provider,providerOptions:A})),K=new Set(Ne),ie=[],se=me==null?[]:[{warning:{type:"unsupported",feature:"webhookUrl",details:"The Anthropic Message Batches API does not support completion webhooks."}}];for(let $e of m){if((await to({provider:this.options.config.provider,providerOptions:$e.options.providerOptions})).length>0)throw new u({functionality:"per-request providerOptions.anthropic.anthropicBeta",message:`Anthropic Message Batches do not support per-request betas (request "${$e.id}"). Set providerOptions.anthropic.anthropicBeta on startBatch instead.`});let Ce=await xo.prepareRequest({modelId:$e.modelId,config:this.options.config,options:{...$e.options,stream:!1,userSuppliedBetas:new Set(Ne)}});if(Ce.usesJsonResponseTool)throw new u({functionality:"batch responseFormat JSON-tool fallback",message:`Anthropic Message Batches cannot decode the JSON-tool structured-output fallback (request "${$e.id}") because batch results are retrieved independently of the start call. Use a model that supports native output_format structured outputs.`});let Ze=$e.options.tools?.find((ke)=>ke.type==="provider"&&Ce.toolNameMapping.toProviderToolName(ke.name)!==ke.name);if(Ze!=null)throw new u({functionality:"aliased provider tool names in batches",message:`Anthropic Message Batches cannot restore the custom provider-tool name "${Ze.name}" when results are retrieved independently of the start call (request "${$e.id}"). Use the provider's canonical tool name.`});let ve=this.options.config.transformRequestBody?.(Ce.args,Ce.betas)??Ce.args;ir({body:ve,requestId:$e.id}),ie.push({custom_id:$e.id,params:ve});for(let ke of Ce.betas)K.add(ke);for(let ke of Ce.warnings)se.push({requestId:$e.id,warning:ke})}let{value:fe}=await g({url:this.getBatchUrl(""),headers:await this.getStartBatchHeaders({betas:K,headers:B}),body:{requests:ie},failedResponseHandler:ct,successfulResponseHandler:p(Rt),abortSignal:V,fetch:this.options.config.fetch});return{batchId:fe.id,...jt(fe),warnings:se}}async doGetBatchStatus(m){return jt(await this.retrieveBatch(m))}async doCancelBatch(m){return await g({url:this.getBatchUrl(`/${encodeURIComponent(m.batchId)}/cancel`),headers:await this.getBatchHeaders(m.headers),body:{},failedResponseHandler:ct,successfulResponseHandler:p(Rt),abortSignal:m.abortSignal,fetch:this.options.config.fetch}),{}}async doListBatches(m){let A=new URL(this.getBatchUrl(""));if(m.limit!=null)A.searchParams.set("limit",String(m.limit));if(m.cursor!=null)A.searchParams.set("after_id",m.cursor);let{value:B}=await R({url:A.toString(),validateUrl:!1,headers:await this.getBatchHeaders(m.headers),failedResponseHandler:ct,successfulResponseHandler:p(Qn),abortSignal:m.abortSignal,fetch:this.options.config.fetch});return{batches:B.data.map((V)=>({batchId:V.id,...jt(V)})),...B.has_more&&B.last_id!=null?{nextCursor:B.last_id}:{}}}async doGetBatchResults(m){let A=await this.retrieveBatch(m);if(jt(A).status==="pending")throw new b({argument:"batchId",message:`Anthropic batch "${m.batchId}" is not complete.`});if(A.archived_at!=null)throw new b({argument:"batchId",message:`Anthropic batch "${m.batchId}" results are no longer available.`});if(A.results_url==null)throw new P({data:A,message:`Anthropic batch "${m.batchId}" completed without batch output.`});let{value:B}=await R({url:A.results_url,validateUrl:!0,credentialedOrigin:this.options.config.baseURL,trustedOrigin:this.options.config.baseURL,headers:await this.getBatchHeaders(m.headers),failedResponseHandler:ct,successfulResponseHandler:_e(or,{maxLineBytes:this.options.maxLineBytes}),abortSignal:m.abortSignal,fetch:this.options.config.fetch});return ae(this.iterateBatchResults(B))}async retrieveBatch(m){let{value:A}=await R({url:this.getBatchUrl(`/${encodeURIComponent(m.batchId)}`),validateUrl:!1,headers:await this.getBatchHeaders(m.headers),failedResponseHandler:ct,successfulResponseHandler:p(Rt),abortSignal:m.abortSignal,fetch:this.options.config.fetch});return A}async*iterateBatchResults(m){for await(let A of m)yield await cr(A,this.generateId)}getBatchUrl(m){return`${this.options.config.baseURL}/messages/batches${m}`}async getStartBatchHeaders({betas:m,headers:A}){return d(qe(await this.getBatchHeaders(A)),{"anthropic-beta":m.size>0?Array.from(m).join(","):void 0})}async getBatchHeaders(m){return d(this.options.config.headers?await _(this.options.config.headers):void 0,m)}};async function to({provider:m,providerOptions:A}){let B=m.split(".")[0],V=await h({provider:"anthropic",providerOptions:A,schema:eo}),me=B!=="anthropic"?await h({provider:B,providerOptions:A,schema:eo}):void 0;return Object.assign({},V??{},me??{}).anthropicBeta??[]}function ar(m){let A=new Set;for(let B of m){if(!Yn.test(B.id))throw new b({argument:"requests",message:`Anthropic batch request ID "${B.id}" must match ^[A-Za-z0-9_-]{1,64}$.`});if(A.has(B.id))throw new b({argument:"requests",message:`Anthropic batch request IDs must be unique; duplicate ID "${B.id}".`});A.add(B.id)}}function ir({body:m,requestId:A}){if(m.speed!=null)throw new u({functionality:"providerOptions.anthropic.speed",message:`Anthropic Message Batches do not support speed (request "${A}").`});if(Array.isArray(m.fallbacks)&&m.fallbacks.some((B)=>B!=null&&typeof B==="object"&&("speed"in B)&&B.speed!=null))throw new u({functionality:"providerOptions.anthropic.fallbacks[].speed",message:`Anthropic Message Batches do not support fallback speed (request "${A}").`})}function jt(m){let A=lr(m.request_counts);return{status:sr(m.processing_status),rawStatus:m.processing_status,...A!=null?{requestCounts:A}:{},createdAt:m.created_at,expiresAt:m.expires_at,providerMetadata:{anthropic:{archivedAt:m.archived_at??null,cancelInitiatedAt:m.cancel_initiated_at??null,endedAt:m.ended_at??null,requestCounts:m.request_counts,resultsUrl:m.results_url??null}}}}function sr(m){switch(m){case"ended":return"completed";default:return"pending"}}function lr(m){return ge({total:m.processing+m.succeeded+m.errored+m.canceled+m.expired,pending:m.processing,completed:m.succeeded,failed:m.errored+m.canceled+m.expired})}async function cr(m,A){let B=await j({value:m.result,schema:tr});if(!B.success)return oo(m.custom_id);let V=B.value;switch(V.type){case"canceled":return{type:"text",id:m.custom_id,status:"cancelled"};case"expired":return{type:"text",id:m.custom_id,status:"expired"};case"errored":{let me=V.error.request_id;return{type:"text",id:m.custom_id,status:"failed",error:{message:V.error.error.message,type:V.error.error.type},...me!=null?{providerMetadata:{anthropic:{requestId:me}}}:{}}}case"succeeded":{let me=await ur(V.message);if(me==null)return oo(m.custom_id);return{type:"text",id:m.custom_id,status:"succeeded",result:pr(me,A)}}}}function oo(m){return{type:"text",id:m,status:"failed",error:{message:"Anthropic returned an invalid Message batch result.",code:"invalid_response"}}}async function ur(m){let A=await j({value:m,schema:Ct});if(A.success)return A.value;if(!L(m)||!Array.isArray(m.content))return;let B=[];for(let me of m.content){let Ne=await j({value:{...m,content:[me]},schema:Ct});if(Ne.success){let[K]=Ne.value.content;if(K!=null)B.push(K)}else if(!L(me)||typeof me.type!=="string"||er.has(me.type))return}let V=await j({value:{...m,content:B},schema:Ct});return V.success?V.value:void 0}function pr(m,A){let B=[],V={},me={},Ne=m.content.some((K)=>K.type==="web_search_tool_result"&&Array.isArray(K.content)&&K.content.length>0);for(let K of m.content)switch(K.type){case"text":let ie=K.citations;B.push({type:"text",text:K.text,...ie!=null&&ie.length>0&&{citations:ie.map((se)=>Bt(se,[]))},...ie!=null&&ie.length>0&&{providerMetadata:{anthropic:{citations:ie}}}});for(let se of K.citations??[])if(se.type==="web_search_result_location"&&!Ne){let fe=Nt(se,[],A);if(fe)B.push(fe)}break;case"thinking":B.push({type:"reasoning",text:K.thinking,providerMetadata:{anthropic:{signature:K.signature}}});break;case"redacted_thinking":B.push({type:"reasoning",text:"",providerMetadata:{anthropic:{redactedData:K.data}}});break;case"container_upload":B.push({type:"custom",kind:"anthropic.container_upload",providerMetadata:{anthropic:{fileId:K.file_id}}});break;case"compaction":if(!K.content)break;B.push({type:"text",text:K.content,providerMetadata:{anthropic:{type:"compaction",...K.signature!=null&&{signature:K.signature}}}});break;case"tool_use":B.push({type:"tool-call",toolCallId:K.id,toolName:K.name,input:JSON.stringify(K.input),...Tt(K.caller)});break;case"server_tool_use":{let se=K.name==="bash_code_execution"||K.name==="text_editor_code_execution",fe=se||K.name==="code_execution",$e=se?"code_execution":K.name;if(K.name==="tool_search_tool_bm25"||K.name==="tool_search_tool_regex")me[K.id]=K.name;B.push({type:"tool-call",toolCallId:K.id,toolName:$e,input:JSON.stringify(se?{type:K.name,...K.input}:K.name==="code_execution"&&K.input!=null&&("code"in K.input)&&!("type"in K.input)?{type:"programmatic-tool-call",...K.input}:K.input),providerExecuted:!0,...fe?{dynamic:!0}:{},...Tt(K.caller)});break}case"mcp_tool_use":{let se={type:"tool-call",toolCallId:K.id,toolName:K.name,input:JSON.stringify(K.input),providerExecuted:!0,dynamic:!0,providerMetadata:{anthropic:{serverName:K.server_name,type:"mcp-tool-use"}}};V[K.id]=se,B.push(se);break}case"mcp_tool_result":{let se=V[K.tool_use_id];B.push({type:"tool-result",toolCallId:K.tool_use_id,toolName:se?.toolName??"mcp",isError:K.is_error,result:K.content,dynamic:!0,...se?.providerMetadata!=null&&{providerMetadata:se.providerMetadata}});break}case"web_fetch_tool_result":B.push({type:"tool-result",toolCallId:K.tool_use_id,toolName:"web_fetch",...K.content.type==="web_fetch_tool_result_error"?{isError:!0,result:{errorCode:K.content.error_code,type:K.content.type}}:{result:{content:{citations:K.content.content.citations,source:{data:K.content.content.source.data,mediaType:K.content.content.source.media_type,type:K.content.content.source.type},title:K.content.content.title,type:K.content.content.type},retrievedAt:K.content.retrieved_at,type:K.content.type,url:K.content.url}},...Tt(K.caller)});break;case"web_search_tool_result":if(B.push({type:"tool-result",toolCallId:K.tool_use_id,toolName:"web_search",...Array.isArray(K.content)?{result:K.content.map((se)=>({encryptedContent:se.encrypted_content,pageAge:se.page_age??null,...se.title!=null?{title:se.title}:{},type:se.type,url:se.url}))}:{isError:!0,result:{errorCode:K.content.error_code,type:K.content.type}},...Tt(K.caller)}),Array.isArray(K.content))for(let se of K.content)B.push({type:"source",sourceType:"url",id:A(),url:se.url,...se.title!=null?{title:se.title}:{},providerMetadata:{anthropic:{pageAge:se.page_age??null}}});break;case"code_execution_tool_result":B.push({type:"tool-result",toolCallId:K.tool_use_id,toolName:"code_execution",...K.content.type==="code_execution_tool_result_error"?{isError:!0,result:{errorCode:K.content.error_code,type:K.content.type}}:{result:K.content}});break;case"bash_code_execution_tool_result":case"text_editor_code_execution_tool_result":B.push({type:"tool-result",toolCallId:K.tool_use_id,toolName:"code_execution",result:K.content});break;case"tool_search_tool_result":{let se=me[K.tool_use_id]??"tool_search_tool_regex";B.push({type:"tool-result",toolCallId:K.tool_use_id,toolName:se,...K.content.type==="tool_search_tool_result_error"?{isError:!0,result:{errorCode:K.content.error_code,type:K.content.type}}:{result:K.content.tool_references.map((fe)=>({toolName:fe.tool_name,type:fe.type}))}});break}case"advisor_tool_result":if(K.content.type==="advisor_result")B.push({type:"tool-result",toolCallId:K.tool_use_id,toolName:"advisor",result:{type:K.content.type,text:K.content.text,...K.content.stop_reason!=null?{stopReason:K.content.stop_reason}:{}}});else if(K.content.type==="advisor_redacted_result")B.push({type:"tool-result",toolCallId:K.tool_use_id,toolName:"advisor",result:{type:K.content.type,encryptedContent:K.content.encrypted_content,...K.content.stop_reason!=null?{stopReason:K.content.stop_reason}:{}}});else B.push({type:"tool-result",toolCallId:K.tool_use_id,toolName:"advisor",isError:!0,result:{errorCode:K.content.error_code,type:K.content.type}});break;case"fallback":B.push({type:"custom",kind:"anthropic.fallback",providerMetadata:{anthropic:{type:"fallback",from:K.from,to:K.to}}})}return{content:B,finishReason:{unified:St({finishReason:m.stop_reason}),raw:m.stop_reason??void 0},usage:Mt({usage:m.usage}),response:{id:m.id??void 0,modelId:m.model??void 0},warnings:[],providerMetadata:{anthropic:dr(m)}}}function Tt(m){return m==null?{}:{providerMetadata:{anthropic:{caller:{type:m.type,toolId:m.tool_id}}}}}function dr(m){let A=hr(m.stop_details);return{usage:m.usage,stopSequence:m.stop_sequence??null,...A!=null?{stopDetails:A}:{},...m.input_transformations!=null?{inputTransformations:m.input_transformations}:{},...m.safeguard_results!=null?{safeguardResults:m.safeguard_results}:{},iterations:m.usage.iterations?m.usage.iterations.map((B)=>({type:B.type,...B.model!=null?{model:B.model}:{},inputTokens:B.input_tokens,outputTokens:B.output_tokens,...B.cache_creation_input_tokens?{cacheCreationInputTokens:B.cache_creation_input_tokens}:{},...B.cache_read_input_tokens?{cacheReadInputTokens:B.cache_read_input_tokens}:{}})):null,container:m.container?{expiresAt:m.container.expires_at,id:m.container.id,skills:m.container.skills?.map((B)=>({type:B.type,skillId:B.skill_id,version:B.version}))??null}:null,contextManagement:_r(m.context_management)}}function _r(m){return m?{appliedEdits:m.applied_edits.map((A)=>{switch(A.type){case"clear_tool_uses_20250919":return{type:A.type,clearedToolUses:A.cleared_tool_uses,clearedInputTokens:A.cleared_input_tokens};case"clear_thinking_20251015":return{type:A.type,clearedThinkingTurns:A.cleared_thinking_turns,clearedInputTokens:A.cleared_input_tokens};case"compact_20260112":return{type:A.type}}})}:null}function hr(m){if(m==null)return;return{type:m.type,...m.category!=null?{category:m.category}:{},...m.explanation!=null?{explanation:m.explanation}:{},...m.recommended_model!=null?{recommendedModel:m.recommended_model}:{}}}var mr=a(()=>s(t({command:e(),restart:c().optional()}))),no=re({id:"anthropic.bash_20241022",inputSchema:mr});function gr(m={}){let{execute:A,...B}=m;if(A===void 0)return no({...B,execute:async({command:V},{abortSignal:me,experimental_sandbox:Ne})=>{if(!Ne)throw Error("Sandbox session is not available");return await Ne.run({command:V,abortSignal:me})}});return no({...B,...A===null?{}:{execute:A}})}var fr=a(()=>s(t({command:e(),restart:c().optional()}))),ro=re({id:"anthropic.bash_20250124",inputSchema:fr});function yr(m={}){let{execute:A,...B}=m;if(A===void 0)return ro({...B,execute:async({command:V},{abortSignal:me,experimental_sandbox:Ne})=>{if(!Ne)throw Error("Sandbox session is not available");return await Ne.run({command:V,abortSignal:me})}});return ro({...B,...A===null?{}:{execute:A}})}var br=a(()=>s(t({action:i(["key","type","mouse_move","left_click","left_click_drag","right_click","middle_click","double_click","screenshot","cursor_position"]),coordinate:o(r().int()).optional(),text:e().optional()}))),xr=re({id:"anthropic.computer_20241022",inputSchema:br}),vr=a(()=>s(t({action:i(["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:ce([r().int(),r().int()]).optional(),duration:r().optional(),scroll_amount:r().optional(),scroll_direction:i(["up","down","left","right"]).optional(),start_coordinate:ce([r().int(),r().int()]).optional(),text:e().optional()}))),kr=re({id:"anthropic.computer_20250124",inputSchema:vr}),wr=a(()=>s(t({action:i(["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:ce([r().int(),r().int()]).optional(),duration:r().optional(),region:ce([r().int(),r().int(),r().int(),r().int()]).optional(),scroll_amount:r().optional(),scroll_direction:i(["up","down","left","right"]).optional(),start_coordinate:ce([r().int(),r().int()]).optional(),text:e().optional()}))),jr=re({id:"anthropic.computer_20251124",inputSchema:wr}),Tr=a(()=>s(f("command",[t({command:n("view"),path:e(),view_range:ce([r(),r()]).optional()}),t({command:n("create"),path:e(),file_text:e()}),t({command:n("str_replace"),path:e(),old_str:e(),new_str:e()}),t({command:n("insert"),path:e(),insert_line:r(),insert_text:e()}),t({command:n("delete"),path:e()}),t({command:n("rename"),old_path:e(),new_path:e()})]))),Cr=re({id:"anthropic.memory_20250818",inputSchema:Tr}),Sr=a(()=>s(t({command:i(["view","create","str_replace","insert","undo_edit"]),path:e(),file_text:e().optional(),insert_line:r().int().optional(),new_str:e().optional(),insert_text:e().optional(),old_str:e().optional(),view_range:o(r().int()).optional()}))),Nr=re({id:"anthropic.text_editor_20241022",inputSchema:Sr}),Or=a(()=>s(t({command:i(["view","create","str_replace","insert","undo_edit"]),path:e(),file_text:e().optional(),insert_line:r().int().optional(),new_str:e().optional(),insert_text:e().optional(),old_str:e().optional(),view_range:o(r().int()).optional()}))),Ir=re({id:"anthropic.text_editor_20250124",inputSchema:Or}),Ar=a(()=>s(t({command:i(["view","create","str_replace","insert"]),path:e(),file_text:e().optional(),insert_line:r().int().optional(),new_str:e().optional(),insert_text:e().optional(),old_str:e().optional(),view_range:o(r().int()).optional()}))),Rr=re({id:"anthropic.text_editor_20250429",inputSchema:Ar}),Br=a(()=>s(o(t({type:n("tool_reference"),toolName:e()})))),Er=a(()=>s(t({query:e(),limit:r().optional()}))),Mr=S({id:"anthropic.tool_search_bm25_20251119",inputSchema:Er,outputSchema:Br,supportsDeferredResults:!0}),Ur=(m={})=>Mr(m),$r={advisor_20260301:Po,bash_20241022:gr,bash_20250124:yr,codeExecution_20250522:Nn,codeExecution_20250825:An,codeExecution_20260120:En,computer_20241022:xr,computer_20250124:kr,computer_20251124:jr,computerToolset_20260801:Jo,memory_20250818:Cr,textEditor_20241022:Nr,textEditor_20250124:Ir,textEditor_20250429:Rr,textEditor_20250728:Vo,webFetch_20250910:jn,webFetch_20260209:xn,webFetch_20260318:hn,webSearch_20250305:cn,webSearch_20260209:rn,webSearch_20260318:Qo,toolSearchRegex_20251119:$n,toolSearchBm25_20251119:Ur},qr=a(()=>s(t({id:e(),display_title:e().nullish(),name:e().nullish(),description:e().nullish(),latest_version:e().nullish(),source:e(),created_at:e(),updated_at:e()})));a(()=>s(t({data:o(t({version:e()}))})));var Dr=a(()=>s(t({type:e(),skill_id:e(),name:e().nullish(),description:e().nullish()}))),Hr=class{get provider(){return this.config.provider}constructor(m){this.config=m,this.specificationVersion="v4"}async getHeaders(){return d(await _(this.config.headers),{"anthropic-beta":"skills-2025-10-02"})}async fetchVersionMetadata({skillId:m,version:A}){let{value:B}=await R({url:`${this.config.baseURL}/skills/${de(m)}/versions/${de(A)}`,validateUrl:!1,headers:await this.getHeaders(),failedResponseHandler:ct,successfulResponseHandler:p(Dr),fetch:this.config.fetch});return{...B.name!=null?{name:B.name}:{},...B.description!=null?{description:B.description}:{}}}async uploadSkill(m){let A=[],B=new FormData;if(m.displayTitle!=null)B.append("display_title",m.displayTitle);for(let ie of m.files){let se=we(ie.data);B.append("files[]",new Blob([se]),ie.path)}let{value:V}=await ne({url:`${this.config.baseURL}/skills`,headers:await this.getHeaders(),formData:B,failedResponseHandler:ct,successfulResponseHandler:p(qr),fetch:this.config.fetch}),me=V.latest_version!=null?await this.fetchVersionMetadata({skillId:V.id,version:V.latest_version}):{},Ne=me.name??V.name,K=me.description??V.description;return{providerReference:{anthropic:V.id},...V.display_title!=null?{displayTitle:V.display_title}:{},...Ne!=null?{name:Ne}:{},...K!=null?{description:K}:{},...V.latest_version!=null?{latestVersion:V.latest_version}:{},providerMetadata:{anthropic:{...V.source!=null?{source:V.source}:{},...V.created_at!=null?{createdAt:V.created_at}:{},...V.updated_at!=null?{updatedAt:V.updated_at}:{}}},warnings:A}}},Pr="4.0.90",ko="https://api.anthropic.com",wo=`${ko}/v1`;function Lr(m){let A=Y(pt(m));return A===ko?wo:A}function Dt(m={}){let A=Lr(pe({settingValue:m.baseURL,environmentVariableName:"ANTHROPIC_BASE_URL"}))??wo,B=m.name??"anthropic.messages",V={"image/*":[/^https?:\/\/.*$/],"application/pdf":[/^https?:\/\/.*$/]};if(m.apiKey&&m.authToken)throw new b({argument:"apiKey/authToken",message:"Both apiKey and authToken were provided. Please use only one authentication method."});let me=async()=>{let $e=m.authToken?{Authorization:`Bearer ${await _(m.authToken)}`}:{"x-api-key":he({apiKey:m.apiKey,environmentVariableName:"ANTHROPIC_API_KEY",description:"Anthropic"})};return F({"anthropic-version":"2023-06-01",...$e,...m.headers},`ai-sdk-anthropic/${Pr}`)},Ne={provider:B,baseURL:A,headers:me,fetch:m.fetch,generateId:m.generateId??C,supportedUrls:()=>V},K=($e)=>new xo($e,Ne),ie=()=>new rr({provider:`${B.replace(/\.messages$/,"")}.batch`,maxLineBytes:m.batchResultDownloads?.maxLineBytes,config:Ne,supportedUrls:V}),se=()=>new Hr({provider:`${B.replace(".messages","")}.skills`,baseURL:A,headers:me,fetch:m.fetch}),fe=function($e){if(new.target)throw Error("The Anthropic model function cannot be called with the new keyword.");return K($e)};return fe.specificationVersion="v4",fe.languageModel=K,fe.chat=K,fe.messages=K,fe.decisionModel=($e)=>new et({model:K($e),provider:`${B.replace(/\.messages$/,"")}.decision`}),fe.evaluationModel=fe.decisionModel,fe.experimental_batch=ie,fe.embeddingModel=($e)=>{throw new Ge({modelId:$e,modelType:"embeddingModel"})},fe.textEmbeddingModel=fe.embeddingModel,fe.imageModel=($e)=>{throw new Ge({modelId:$e,modelType:"imageModel"})},fe.files=()=>new Ro({provider:B,baseURL:A,headers:me,fetch:m.fetch}),fe.skills=se,fe.tools=$r,fe}var Xr=Dt();var Fr=(m)=>Dt({apiKey:m.apiKey,...m.baseURL&&{baseURL:ht(m.baseURL)},headers:{...m.headers,...Be(m.baseURL??qt.anthropic)&&{[gt]:"true"}},...m.fetch&&{fetch:m.fetch}})(m.model);function aa(){oe("anthropic",Fr)}export{aa as register};
|
|
1
|
+
import{oe,Dt,Ve,yt,bt}from"./embed-rjpq8psf.js";import{rt}from"./embed-yz75savs.js";import{w,b,P,He,u,e,r,c,v,Ae,o,t,U,l,f,ce,y,xn,i,n,G,k,T,d,ae,j,M,we,le,xe,lt,ze,F,z,de,C,R,De,L,he,pe,W,Se,ut,ge,Q,a,s,x,q,h,g,ne,re,S,_,O,H,I,D,p,_e,E,ht,Y,Xe}from"./embed-50pfy67v.js";var Io=a(()=>s(t({type:n("error"),error:t({type:e(),message:e()})}))),st=I({errorSchema:Io,errorToMessage:(m)=>m.error.message}),Ao=a(()=>s(t({id:e(),type:n("file"),filename:e(),mime_type:e(),size_bytes:r(),created_at:e(),downloadable:c().nullish()}))),Ro=class{get provider(){return this.config.provider}constructor(m){this.config=m,this.specificationVersion="v4"}async uploadFile({data:m,mediaType:N,filename:A,abortSignal:V,headers:me}){let Ne=we(m),K=new Blob([Ne],{type:N}),ie=new FormData;if(A!=null)ie.append("file",K,A);else ie.append("file",K);let{value:se}=await ne({url:`${this.config.baseURL}/files`,headers:d(await _(this.config.headers),{"anthropic-beta":"files-api-2025-04-14"},me),formData:ie,failedResponseHandler:st,successfulResponseHandler:p(Ao),abortSignal:V,fetch:this.config.fetch});return{warnings:[],providerReference:{anthropic:se.id},mediaType:se.mime_type??N,filename:se.filename??A,providerMetadata:{anthropic:{filename:se.filename,mimeType:se.mime_type,sizeBytes:se.size_bytes,createdAt:se.created_at,...se.downloadable!=null?{downloadable:se.downloadable}:{}}}}}};function Bt(m,N){if(m.type==="web_search_result_location"||m.type==="search_result_location"){let V=m.type==="web_search_result_location"?m.url:m.source;return{source:{type:"source",sourceType:"url",id:V,url:V,title:m.title??void 0,providerMetadata:{anthropic:{...m}}},citedText:m.cited_text}}let A=N[m.document_index];return{source:{type:"source",sourceType:"document",id:m.file_id??String(m.document_index),mediaType:A?.mediaType??"text/plain",title:m.document_title??A?.title??`Document ${m.document_index}`,filename:A?.filename,providerMetadata:{anthropic:{...m}}},citedText:m.cited_text}}var Ut=()=>t({type:n("fallback"),from:t({model:e()}),to:t({model:e()})}),Bo=a(()=>s(Ut())),ao=()=>t({type:e(),category:e().nullish(),explanation:e().nullish(),recommended_model:e().nullish()}),io=()=>t({type:e(),status:t({type:e(),tool_uses:y(e(),t({type:e(),outcome:e().nullish(),explanation:e().nullish()})).nullish()})}),ct=()=>l([t({type:n("code_execution_20250825"),tool_id:e()}),t({type:n("code_execution_20260120"),tool_id:e()}),t({type:n("direct")})]),so=()=>f("type",[t({type:n("web_search_result_location"),cited_text:e(),url:e(),title:e().nullable(),encrypted_index:e()}),t({type:n("page_location"),cited_text:e(),document_index:r(),document_title:e().nullable(),start_page_number:r(),end_page_number:r(),file_id:e().nullish()}),t({type:n("char_location"),cited_text:e(),document_index:r(),document_title:e().nullable(),start_char_index:r(),end_char_index:r(),file_id:e().nullish()}),t({type:n("content_block_location"),cited_text:e(),document_index:r(),document_title:e().nullable(),start_block_index:r(),end_block_index:r(),file_id:e().nullable()}),t({type:n("search_result_location"),cited_text:e(),search_result_index:r(),source:e(),title:e().nullable(),start_block_index:r(),end_block_index:r()})]),lo=()=>l([e(),o(l([e(),t({type:n("text"),text:e(),citations:o(G()).nullable().optional()})]))]),Et=()=>t({type:e(),path:e(),reason:e()}),Ct=a(()=>s(t({type:n("message"),id:e().nullish(),model:e().nullish(),content:o(f("type",[t({type:n("text"),text:e(),citations:o(so()).nullable().optional()}),t({type:n("thinking"),thinking:e(),signature:e()}),t({type:n("redacted_thinking"),data:e()}),t({type:n("compaction"),content:e().nullish(),signature:e().nullish()}),t({type:n("tool_use"),id:e(),name:e(),input:v(),caller:ct().optional(),toolset_name:e().nullish()}),t({type:n("server_tool_use"),id:e(),name:e(),input:y(e(),v()).nullish(),caller:ct().optional()}),t({type:n("mcp_tool_use"),id:e(),name:e(),input:v(),server_name:e()}),t({type:n("mcp_tool_result"),tool_use_id:e(),is_error:c(),content:lo()}),t({type:n("web_fetch_tool_result"),tool_use_id:e(),caller:ct().optional(),content:l([t({type:n("web_fetch_result"),url:e(),retrieved_at:e().nullable(),content:t({type:n("document"),title:e().nullable(),citations:t({enabled:c()}).optional(),source:l([t({type:n("base64"),media_type:n("application/pdf"),data:e()}),t({type:n("text"),media_type:n("text/plain"),data:e()})])})}),t({type:n("web_fetch_tool_result_error"),error_code:e()})])}),t({type:n("web_search_tool_result"),tool_use_id:e(),caller:ct().optional(),content:l([o(t({type:n("web_search_result"),url:e(),title:e().nullable(),encrypted_content:e(),page_age:e().nullish()})),t({type:n("web_search_tool_result_error"),error_code:e()})])}),t({type:n("code_execution_tool_result"),tool_use_id:e(),content:l([t({type:n("code_execution_result"),stdout:e(),stderr:e(),return_code:r(),content:o(t({type:n("code_execution_output"),file_id:e()})).optional().default([])}),t({type:n("encrypted_code_execution_result"),encrypted_stdout:e(),stderr:e(),return_code:r(),content:o(t({type:n("code_execution_output"),file_id:e()})).optional().default([])}),t({type:n("code_execution_tool_result_error"),error_code:e()})])}),t({type:n("bash_code_execution_tool_result"),tool_use_id:e(),content:f("type",[t({type:n("bash_code_execution_result"),content:o(t({type:n("bash_code_execution_output"),file_id:e()})),stdout:e(),stderr:e(),return_code:r()}),t({type:n("bash_code_execution_tool_result_error"),error_code:e()})])}),t({type:n("text_editor_code_execution_tool_result"),tool_use_id:e(),content:f("type",[t({type:n("text_editor_code_execution_tool_result_error"),error_code:e()}),t({type:n("text_editor_code_execution_view_result"),content:e(),file_type:e(),num_lines:r().nullable(),start_line:r().nullable(),total_lines:r().nullable()}),t({type:n("text_editor_code_execution_create_result"),is_file_update:c()}),t({type:n("text_editor_code_execution_str_replace_result"),lines:o(e()).nullable(),new_lines:r().nullable(),new_start:r().nullable(),old_lines:r().nullable(),old_start:r().nullable()})])}),t({type:n("tool_search_tool_result"),tool_use_id:e(),content:l([t({type:n("tool_search_tool_search_result"),tool_references:o(t({type:n("tool_reference"),tool_name:e()}))}),t({type:n("tool_search_tool_result_error"),error_code:e()})])}),t({type:n("container_upload"),file_id:e()}),t({type:n("advisor_tool_result"),tool_use_id:e(),content:f("type",[t({type:n("advisor_result"),text:e(),stop_reason:e().nullish()}),t({type:n("advisor_redacted_result"),encrypted_content:e(),stop_reason:e().nullish()}),t({type:n("advisor_tool_result_error"),error_code:e()})])}),Ut()])),stop_reason:e().nullish(),stop_sequence:e().nullish(),stop_details:ao().nullish(),input_transformations:o(Et()).nullish(),safeguard_results:o(io()).nullish(),usage:U({input_tokens:r(),output_tokens:r(),output_tokens_details:t({thinking_tokens:r().nullish()}).nullish(),cache_creation_input_tokens:r().nullish(),cache_read_input_tokens:r().nullish(),iterations:o(t({type:l([n("compaction"),n("message"),n("advisor_message"),n("fallback_message")]),model:e().nullish(),input_tokens:r(),output_tokens:r(),cache_creation_input_tokens:r().nullish(),cache_read_input_tokens:r().nullish()})).nullish()}),container:t({expires_at:e(),id:e(),skills:o(t({type:l([n("anthropic"),n("custom")]),skill_id:e(),version:e()})).nullish()}).nullish(),context_management:t({applied_edits:o(l([t({type:n("clear_tool_uses_20250919"),cleared_tool_uses:r(),cleared_input_tokens:r()}),t({type:n("clear_thinking_20251015"),cleared_thinking_turns:r(),cleared_input_tokens:r()}),t({type:n("compact_20260112")})]))}).nullish()}))),Eo=a(()=>s(f("type",[t({type:n("message_start"),message:t({id:e().nullish(),model:e().nullish(),role:e().nullish(),usage:U({input_tokens:r(),cache_creation_input_tokens:r().nullish(),cache_read_input_tokens:r().nullish()}),content:o(f("type",[t({type:n("tool_use"),id:e(),name:e(),input:v(),caller:ct().optional(),toolset_name:e().nullish()})])).nullish(),stop_reason:e().nullish(),input_transformations:o(Et()).nullish(),container:t({expires_at:e(),id:e()}).nullish()})}),t({type:n("content_block_start"),index:r(),content_block:f("type",[t({type:n("text"),text:e()}),t({type:n("thinking"),thinking:e()}),t({type:n("tool_use"),id:e(),name:e(),input:y(e(),v()).optional(),caller:ct().optional(),toolset_name:e().nullish()}),t({type:n("redacted_thinking"),data:e()}),t({type:n("compaction"),content:e().nullish(),signature:e().nullish()}),t({type:n("server_tool_use"),id:e(),name:e(),input:y(e(),v()).nullish(),caller:ct().optional()}),t({type:n("mcp_tool_use"),id:e(),name:e(),input:v(),server_name:e()}),t({type:n("mcp_tool_result"),tool_use_id:e(),is_error:c(),content:lo()}),t({type:n("web_fetch_tool_result"),tool_use_id:e(),caller:ct().optional(),content:l([t({type:n("web_fetch_result"),url:e(),retrieved_at:e().nullable(),content:t({type:n("document"),title:e().nullable(),citations:t({enabled:c()}).optional(),source:l([t({type:n("base64"),media_type:n("application/pdf"),data:e()}),t({type:n("text"),media_type:n("text/plain"),data:e()})])})}),t({type:n("web_fetch_tool_result_error"),error_code:e()})])}),t({type:n("web_search_tool_result"),tool_use_id:e(),caller:ct().optional(),content:l([o(t({type:n("web_search_result"),url:e(),title:e().nullable(),encrypted_content:e(),page_age:e().nullish()})),t({type:n("web_search_tool_result_error"),error_code:e()})])}),t({type:n("code_execution_tool_result"),tool_use_id:e(),content:l([t({type:n("code_execution_result"),stdout:e(),stderr:e(),return_code:r(),content:o(t({type:n("code_execution_output"),file_id:e()})).optional().default([])}),t({type:n("encrypted_code_execution_result"),encrypted_stdout:e(),stderr:e(),return_code:r(),content:o(t({type:n("code_execution_output"),file_id:e()})).optional().default([])}),t({type:n("code_execution_tool_result_error"),error_code:e()})])}),t({type:n("bash_code_execution_tool_result"),tool_use_id:e(),content:f("type",[t({type:n("bash_code_execution_result"),content:o(t({type:n("bash_code_execution_output"),file_id:e()})),stdout:e(),stderr:e(),return_code:r()}),t({type:n("bash_code_execution_tool_result_error"),error_code:e()})])}),t({type:n("text_editor_code_execution_tool_result"),tool_use_id:e(),content:f("type",[t({type:n("text_editor_code_execution_tool_result_error"),error_code:e()}),t({type:n("text_editor_code_execution_view_result"),content:e(),file_type:e(),num_lines:r().nullable(),start_line:r().nullable(),total_lines:r().nullable()}),t({type:n("text_editor_code_execution_create_result"),is_file_update:c()}),t({type:n("text_editor_code_execution_str_replace_result"),lines:o(e()).nullable(),new_lines:r().nullable(),new_start:r().nullable(),old_lines:r().nullable(),old_start:r().nullable()})])}),t({type:n("tool_search_tool_result"),tool_use_id:e(),content:l([t({type:n("tool_search_tool_search_result"),tool_references:o(t({type:n("tool_reference"),tool_name:e()}))}),t({type:n("tool_search_tool_result_error"),error_code:e()})])}),t({type:n("advisor_tool_result"),tool_use_id:e(),content:f("type",[t({type:n("advisor_result"),text:e(),stop_reason:e().nullish()}),t({type:n("advisor_redacted_result"),encrypted_content:e(),stop_reason:e().nullish()}),t({type:n("advisor_tool_result_error"),error_code:e()})])}),Ut()])}),t({type:n("content_block_delta"),index:r(),delta:f("type",[t({type:n("input_json_delta"),partial_json:e()}),t({type:n("text_delta"),text:e()}),t({type:n("thinking_delta"),thinking:e()}),t({type:n("signature_delta"),signature:e()}),t({type:n("compaction_delta"),content:e().nullish()}),t({type:n("citations_delta"),citation:so()})])}),t({type:n("content_block_stop"),index:r()}),t({type:n("error"),error:t({type:e(),message:e(),code:l([e(),r()]).nullish(),statusCode:r().nullish(),isRetryable:c().nullish(),data:v().nullish()})}),t({type:n("message_delta"),delta:t({stop_reason:e().nullish(),stop_sequence:e().nullish(),stop_details:ao().nullish(),safeguard_results:o(io()).nullish(),container:t({expires_at:e(),id:e(),skills:o(t({type:l([n("anthropic"),n("custom")]),skill_id:e(),version:e()})).nullish()}).nullish()}),usage:U({input_tokens:r().nullish(),output_tokens:r(),output_tokens_details:t({thinking_tokens:r().nullish()}).nullish(),cache_creation_input_tokens:r().nullish(),cache_read_input_tokens:r().nullish(),iterations:o(t({type:l([n("compaction"),n("message"),n("advisor_message"),n("fallback_message")]),model:e().nullish(),input_tokens:r(),output_tokens:r(),cache_creation_input_tokens:r().nullish(),cache_read_input_tokens:r().nullish()})).nullish()}),input_transformations:o(Et()).nullish(),context_management:t({applied_edits:o(l([t({type:n("clear_tool_uses_20250919"),cleared_tool_uses:r(),cleared_input_tokens:r()}),t({type:n("clear_thinking_20251015"),cleared_thinking_turns:r(),cleared_input_tokens:r()}),t({type:n("compact_20260112")})]))}).nullish()}),t({type:n("message_stop")}),t({type:n("ping")})]))),Mo=a(()=>s(t({signature:e().optional(),redactedData:e().optional()}))),It=a(()=>s(t({containerUpload:c().optional(),citations:t({enabled:c()}).optional(),title:e().optional(),context:e().optional()}))),Uo=a(()=>s(t({clearAt:n("next_user_message").optional(),effort:i(["low","medium","high","xhigh","max"]).optional(),toolChanges:o(f("type",[t({type:n("tool_addition"),toolName:e()}),t({type:n("tool_removal"),toolName:e()})])).optional()}))),Jt=a(()=>s(t({sendReasoning:c().optional(),structuredOutputMode:i(["outputFormat","jsonTool","auto"]).optional(),thinking:l([f("type",[t({type:n("adaptive"),display:i(["omitted","summarized","updates"]).optional(),blockBinding:t({prefixMismatchBehavior:i(["error","drop_block"])}).optional()}),t({type:n("enabled"),budgetTokens:r().optional()}),t({type:n("disabled")}),t({type:n("between_tools")})]),t({type:Ae().optional(),blockBinding:t({prefixMismatchBehavior:i(["error","drop_block"])})})]).optional(),disableParallelToolUse:c().optional(),cacheControl:t({type:n("ephemeral"),ttl:l([n("5m"),n("1h")]).optional()}).optional(),metadata:t({userId:e().optional()}).optional(),mcpServers:o(t({type:n("url"),name:e(),url:e(),authorizationToken:e().nullish(),toolConfiguration:t({enabled:c().nullish(),allowedTools:o(e()).nullish()}).nullish()})).optional(),container:t({id:e().optional(),skills:o(f("type",[t({type:n("anthropic"),skillId:e(),version:e().optional()}),t({type:n("custom"),providerReference:y(e(),e()),version:e().optional()})])).optional()}).optional(),toolStreaming:c().optional(),effort:i(["low","medium","high","xhigh","max"]).optional(),taskBudget:t({type:n("tokens"),total:r().int().min(20000),remaining:r().int().min(0).optional()}).optional(),speed:i(["fast","standard"]).optional(),serviceTier:i(["auto","standard_only"]).optional(),inferenceGeo:i(["us","global"]).optional(),fallbacks:l([n("default"),o(t({model:e(),max_tokens:r().int().optional(),thinking:y(e(),v()).optional(),output_config:y(e(),v()).optional(),speed:i(["fast","standard"]).optional()}))]).optional(),anthropicBeta:o(e()).optional(),safeguards:o(t({type:n("dangerous_tool_use"),classifierContext:y(e(),v()).optional()})).optional(),compaction:t({type:n("summarize"),instructions:e().optional()}).optional(),contextManagement:t({edits:o(f("type",[t({type:n("clear_tool_uses_20250919"),trigger:f("type",[t({type:n("input_tokens"),value:r()}),t({type:n("tool_uses"),value:r()})]).optional(),keep:t({type:n("tool_uses"),value:r()}).optional(),clearAtLeast:t({type:n("input_tokens"),value:r()}).optional(),clearToolInputs:c().optional(),excludeTools:o(e()).optional()}),t({type:n("clear_thinking_20251015"),keep:l([n("all"),t({type:n("thinking_turns"),value:r()})]).optional()}),t({type:n("compact_20260112"),trigger:t({type:n("input_tokens"),value:r()}).optional(),pauseAfterCompaction:c().optional(),instructions:e().optional()})]))}).optional()}))),Kt=4;function $o(m,N){let A=m?.[N],V=m?.anthropic;return A?.cacheControl??A?.cache_control??V?.cacheControl??V?.cache_control}var $t=class{constructor(m="anthropic"){this.providerOptionsName=m,this.breakpointCount=0,this.warnings=[]}getCacheControl(m,N){let A=$o(m,this.providerOptionsName);if(!A)return;if(!N.canCache){this.warnings.push({type:"unsupported",feature:"cache_control on non-cacheable context",details:`cache_control cannot be set on ${N.type}. It will be ignored.`});return}if(this.breakpointCount++,this.breakpointCount>Kt){this.warnings.push({type:"unsupported",feature:"cacheControl breakpoint limit",details:`Maximum ${Kt} cache breakpoints exceeded (found ${this.breakpointCount}). This breakpoint will be ignored.`});return}return A}getWarnings(){return this.warnings}},qo=a(()=>s(t({model:e(),maxUses:r().optional(),maxTokens:r().int().min(1024).optional(),caching:t({type:n("ephemeral"),ttl:l([n("5m"),n("1h")])}).optional()}))),co=a(()=>s(f("type",[t({type:n("advisor_result"),text:e(),stopReason:e().optional()}),t({type:n("advisor_redacted_result"),encryptedContent:e(),stopReason:e().optional()}),t({type:n("advisor_tool_result_error"),errorCode:e()})]))),Do=a(()=>s(t({}).strict())),Ho=S({id:"anthropic.advisor_20260301",inputSchema:Do,outputSchema:co,supportsDeferredResults:!0}),Po=(m)=>Ho(m),uo=["screenshot","zoom","left_click","right_click","middle_click","double_click","triple_click","left_click_drag","mouse_move","left_mouse_down","left_mouse_up","cursor_position","scroll","type","key","hold_key","wait"],Lo=a(()=>s(t({action:i(uo),coordinate:ce([r().int(),r().int()]).optional(),duration:r().optional(),region:ce([r().int(),r().int(),r().int(),r().int()]).optional(),repeat:r().int().optional(),scroll_amount:r().optional(),scroll_direction:i(["up","down","left","right"]).optional(),start_coordinate:ce([r().int(),r().int()]).optional(),text:e().optional()}))),Fo=a(()=>s(t({configs:xn(i(uo),t({enabled:c().optional(),deferLoading:c().optional()})).optional()}))),Jo=re({id:"anthropic.computer_toolset_20260801",inputSchema:Lo}),Ko=a(()=>s(t({maxCharacters:r().optional()}))),zo=a(()=>s(t({command:i(["view","create","str_replace","insert"]),path:e(),file_text:e().optional(),insert_line:r().int().optional(),new_str:e().optional(),insert_text:e().optional(),old_str:e().optional(),view_range:o(r().int()).optional()}))),Wo=re({id:"anthropic.text_editor_20250728",inputSchema:zo}),Vo=(m={})=>Wo(m),Xo=a(()=>s(t({maxUses:r().optional(),allowedDomains:o(e()).optional(),blockedDomains:o(e()).optional(),userLocation:t({type:n("approximate"),city:e().optional(),region:e().optional(),country:e().optional(),timezone:e().optional()}).optional(),responseInclusion:i(["full","excluded"]).optional()}))),Go=a(()=>s(o(t({url:e(),title:e().nullable(),pageAge:e().nullable(),encryptedContent:e(),type:n("web_search_result")})))),Zo=a(()=>s(t({query:e()}))),Yo=S({id:"anthropic.web_search_20260318",inputSchema:Zo,outputSchema:Go,supportsDeferredResults:!0}),Qo=(m={})=>Yo(m),en=a(()=>s(t({maxUses:r().optional(),allowedDomains:o(e()).optional(),blockedDomains:o(e()).optional(),userLocation:t({type:n("approximate"),city:e().optional(),region:e().optional(),country:e().optional(),timezone:e().optional()}).optional()}))),tn=a(()=>s(o(t({url:e(),title:e().nullable(),pageAge:e().nullable(),encryptedContent:e(),type:n("web_search_result")})))),on=a(()=>s(t({query:e()}))),nn=S({id:"anthropic.web_search_20260209",inputSchema:on,outputSchema:tn,supportsDeferredResults:!0}),rn=(m={})=>nn(m),an=a(()=>s(t({maxUses:r().optional(),allowedDomains:o(e()).optional(),blockedDomains:o(e()).optional(),userLocation:t({type:n("approximate"),city:e().optional(),region:e().optional(),country:e().optional(),timezone:e().optional()}).optional()}))),po=a(()=>s(o(t({url:e(),title:e().nullable(),pageAge:e().nullable(),encryptedContent:e(),type:n("web_search_result")})))),sn=a(()=>s(t({query:e()}))),ln=S({id:"anthropic.web_search_20250305",inputSchema:sn,outputSchema:po,supportsDeferredResults:!0}),cn=(m={})=>ln(m),un=a(()=>s(t({maxUses:r().optional(),allowedDomains:o(e()).optional(),blockedDomains:o(e()).optional(),citations:t({enabled:c()}).optional(),maxContentTokens:r().optional(),useCache:c().optional(),responseInclusion:i(["full","excluded"]).optional()}))),pn=a(()=>s(t({type:n("web_fetch_result"),url:e(),content:t({type:n("document"),title:e().nullable(),citations:t({enabled:c()}).optional(),source:l([t({type:n("base64"),mediaType:n("application/pdf"),data:e()}),t({type:n("text"),mediaType:n("text/plain"),data:e()})])}),retrievedAt:e().nullable()}))),dn=a(()=>s(t({url:e()}))),_n=S({id:"anthropic.web_fetch_20260318",inputSchema:dn,outputSchema:pn,supportsDeferredResults:!0}),hn=(m={})=>_n(m),mn=a(()=>s(t({maxUses:r().optional(),allowedDomains:o(e()).optional(),blockedDomains:o(e()).optional(),citations:t({enabled:c()}).optional(),maxContentTokens:r().optional()}))),gn=a(()=>s(t({type:n("web_fetch_result"),url:e(),content:t({type:n("document"),title:e().nullable(),citations:t({enabled:c()}).optional(),source:l([t({type:n("base64"),mediaType:n("application/pdf"),data:e()}),t({type:n("text"),mediaType:n("text/plain"),data:e()})])}),retrievedAt:e().nullable()}))),fn=a(()=>s(t({url:e()}))),yn=S({id:"anthropic.web_fetch_20260209",inputSchema:fn,outputSchema:gn,supportsDeferredResults:!0}),bn=(m={})=>yn(m),vn=a(()=>s(t({maxUses:r().optional(),allowedDomains:o(e()).optional(),blockedDomains:o(e()).optional(),citations:t({enabled:c()}).optional(),maxContentTokens:r().optional()}))),_o=a(()=>s(t({type:n("web_fetch_result"),url:e(),content:t({type:n("document"),title:e().nullable(),citations:t({enabled:c()}).optional(),source:l([t({type:n("base64"),mediaType:n("application/pdf"),data:e()}),t({type:n("text"),mediaType:n("text/plain"),data:e()})])}),retrievedAt:e().nullable()}))),kn=a(()=>s(t({url:e()}))),wn=S({id:"anthropic.web_fetch_20250910",inputSchema:kn,outputSchema:_o,supportsDeferredResults:!0}),jn=(m={})=>wn(m);async function Tn({tools:m,toolChoice:N,disableParallelToolUse:A,cacheControlValidator:V,supportsStructuredOutput:me,supportsStrictTools:Ne,defaultEagerInputStreaming:K=!1,rejectsForcedToolUse:ie=!1}){m=m?.length?m:void 0;let se=[],fe=new Set,Ue=V||new $t;if(m==null)return{tools:void 0,toolChoice:void 0,toolWarnings:se,betas:fe};let Ce=[];for(let ve of m)switch(ve.type){case"function":{let ke=Ue.getCacheControl(ve.providerOptions,{type:"tool definition",canCache:!0}),Ee=ve.providerOptions?.anthropic,We=Ee?.eagerInputStreaming??K,Fe=Ee?.deferLoading,Le=Ee?.allowedCallers;if(!Ne&&ve.strict===!0)se.push({type:"unsupported",feature:"strict",details:`Tool '${ve.name}' has strict: ${ve.strict}, but strict mode is not supported by this provider. The strict property will be ignored.`});if(Ce.push({name:ve.name,description:ve.description,input_schema:ve.inputSchema,cache_control:ke,...We?{eager_input_streaming:!0}:{},...Ne===!0&&ve.strict!=null?{strict:ve.strict}:{},...Fe!=null?{defer_loading:Fe}:{},...Le!=null?{allowed_callers:Le}:{},...ve.inputExamples!=null?{input_examples:ve.inputExamples.map((Re)=>Re.input)}:{}}),me===!0)fe.add("structured-outputs-2025-11-13");if(ve.inputExamples!=null||Le!=null)fe.add("advanced-tool-use-2025-11-20");break}case"provider":switch(ve.id){case"anthropic.code_execution_20250522":fe.add("code-execution-2025-05-22"),Ce.push({type:"code_execution_20250522",name:"code_execution",cache_control:void 0});break;case"anthropic.code_execution_20250825":fe.add("code-execution-2025-08-25"),Ce.push({type:"code_execution_20250825",name:"code_execution"});break;case"anthropic.code_execution_20260120":Ce.push({type:"code_execution_20260120",name:"code_execution"});break;case"anthropic.computer_20250124":fe.add("computer-use-2025-01-24"),Ce.push({name:"computer",type:"computer_20250124",display_width_px:ve.args.displayWidthPx,display_height_px:ve.args.displayHeightPx,display_number:ve.args.displayNumber,cache_control:void 0});break;case"anthropic.computer_20251124":fe.add("computer-use-2025-11-24"),Ce.push({name:"computer",type:"computer_20251124",display_width_px:ve.args.displayWidthPx,display_height_px:ve.args.displayHeightPx,display_number:ve.args.displayNumber,enable_zoom:ve.args.enableZoom,cache_control:void 0});break;case"anthropic.computer_toolset_20260801":{let ke=await x({value:ve.args,schema:Fo}),Ee=ke.configs!=null?Object.fromEntries(Object.entries(ke.configs).map(([We,Fe])=>[We,{...Fe?.enabled!=null&&{enabled:Fe.enabled},...Fe?.deferLoading!=null&&{defer_loading:Fe.deferLoading}}])):void 0;Ce.push({type:"computer_toolset_20260801",...Ee!=null&&{configs:Ee},cache_control:void 0});break}case"anthropic.computer_20241022":fe.add("computer-use-2024-10-22"),Ce.push({name:"computer",type:"computer_20241022",display_width_px:ve.args.displayWidthPx,display_height_px:ve.args.displayHeightPx,display_number:ve.args.displayNumber,cache_control:void 0});break;case"anthropic.text_editor_20250124":fe.add("computer-use-2025-01-24"),Ce.push({name:"str_replace_editor",type:"text_editor_20250124",cache_control:void 0});break;case"anthropic.text_editor_20241022":fe.add("computer-use-2024-10-22"),Ce.push({name:"str_replace_editor",type:"text_editor_20241022",cache_control:void 0});break;case"anthropic.text_editor_20250429":fe.add("computer-use-2025-01-24"),Ce.push({name:"str_replace_based_edit_tool",type:"text_editor_20250429",cache_control:void 0});break;case"anthropic.text_editor_20250728":{let ke=await x({value:ve.args,schema:Ko});Ce.push({name:"str_replace_based_edit_tool",type:"text_editor_20250728",max_characters:ke.maxCharacters,cache_control:void 0});break}case"anthropic.bash_20250124":fe.add("computer-use-2025-01-24"),Ce.push({name:"bash",type:"bash_20250124",cache_control:void 0});break;case"anthropic.bash_20241022":fe.add("computer-use-2024-10-22"),Ce.push({name:"bash",type:"bash_20241022",cache_control:void 0});break;case"anthropic.memory_20250818":fe.add("context-management-2025-06-27"),Ce.push({name:"memory",type:"memory_20250818"});break;case"anthropic.web_fetch_20250910":{fe.add("web-fetch-2025-09-10");let ke=await x({value:ve.args,schema:vn});Ce.push({type:"web_fetch_20250910",name:"web_fetch",max_uses:ke.maxUses,allowed_domains:ke.allowedDomains,blocked_domains:ke.blockedDomains,citations:ke.citations,max_content_tokens:ke.maxContentTokens,cache_control:void 0});break}case"anthropic.web_fetch_20260209":{fe.add("code-execution-web-tools-2026-02-09");let ke=await x({value:ve.args,schema:mn});Ce.push({type:"web_fetch_20260209",name:"web_fetch",max_uses:ke.maxUses,allowed_domains:ke.allowedDomains,blocked_domains:ke.blockedDomains,citations:ke.citations,max_content_tokens:ke.maxContentTokens,cache_control:void 0});break}case"anthropic.web_fetch_20260318":{let ke=await x({value:ve.args,schema:un});Ce.push({type:"web_fetch_20260318",name:"web_fetch",max_uses:ke.maxUses,allowed_domains:ke.allowedDomains,blocked_domains:ke.blockedDomains,citations:ke.citations,max_content_tokens:ke.maxContentTokens,use_cache:ke.useCache,response_inclusion:ke.responseInclusion,cache_control:void 0});break}case"anthropic.web_search_20250305":{let ke=await x({value:ve.args,schema:an});Ce.push({type:"web_search_20250305",name:"web_search",max_uses:ke.maxUses,allowed_domains:ke.allowedDomains,blocked_domains:ke.blockedDomains,user_location:ke.userLocation,cache_control:void 0});break}case"anthropic.web_search_20260209":{fe.add("code-execution-web-tools-2026-02-09");let ke=await x({value:ve.args,schema:en});Ce.push({type:"web_search_20260209",name:"web_search",max_uses:ke.maxUses,allowed_domains:ke.allowedDomains,blocked_domains:ke.blockedDomains,user_location:ke.userLocation,cache_control:void 0});break}case"anthropic.web_search_20260318":{let ke=await x({value:ve.args,schema:Xo});Ce.push({type:"web_search_20260318",name:"web_search",max_uses:ke.maxUses,allowed_domains:ke.allowedDomains,blocked_domains:ke.blockedDomains,user_location:ke.userLocation,response_inclusion:ke.responseInclusion,cache_control:void 0});break}case"anthropic.tool_search_regex_20251119":Ce.push({type:"tool_search_tool_regex_20251119",name:"tool_search_tool_regex"});break;case"anthropic.tool_search_bm25_20251119":Ce.push({type:"tool_search_tool_bm25_20251119",name:"tool_search_tool_bm25"});break;case"anthropic.advisor_20260301":{fe.add("advisor-tool-2026-03-01");let ke=await x({value:ve.args,schema:qo});Ce.push({type:"advisor_20260301",name:"advisor",model:ke.model,...ke.maxUses!==void 0&&{max_uses:ke.maxUses},...ke.maxTokens!==void 0&&{max_tokens:ke.maxTokens},...ke.caching!==void 0&&{caching:ke.caching}});break}default:se.push({type:"unsupported",feature:`provider-defined tool ${ve.id}`})}break;default:se.push({type:"unsupported",feature:`tool ${ve}`})}if(N==null)return{tools:Ce,toolChoice:A?{type:"auto",disable_parallel_tool_use:A}:void 0,toolWarnings:se,betas:fe};let Ze=N.type;switch(Ze){case"auto":return{tools:Ce,toolChoice:{type:"auto",disable_parallel_tool_use:A},toolWarnings:se,betas:fe};case"required":if(ie)return se.push({type:"unsupported",feature:"toolChoice",details:"toolChoice 'required' is not supported with this model or thinking configuration. Using 'auto' instead. Instruct the model to use a tool in the prompt and verify that a tool call was made."}),{tools:Ce,toolChoice:{type:"auto",disable_parallel_tool_use:A},toolWarnings:se,betas:fe};return{tools:Ce,toolChoice:{type:"any",disable_parallel_tool_use:A},toolWarnings:se,betas:fe};case"none":return{tools:Ce,toolChoice:{type:"none"},toolWarnings:se,betas:fe};case"tool":if(ie)return se.push({type:"unsupported",feature:"toolChoice",details:`toolChoice 'tool' is not supported with this model or thinking configuration. Only the '${N.toolName}' tool is sent with 'auto' tool choice. Instruct the model to use the tool in the prompt and verify that a tool call was made.`}),{tools:Ce.filter((ve)=>("name"in ve)&&ve.name===N.toolName),toolChoice:{type:"auto",disable_parallel_tool_use:A},toolWarnings:se,betas:fe};return{tools:Ce,toolChoice:{type:"tool",name:N.toolName,disable_parallel_tool_use:A},toolWarnings:se,betas:fe};default:throw new u({functionality:`tool choice type: ${Ze}`})}}function Mt({usage:m,rawUsage:N}){let A=m.cache_creation_input_tokens??0,V=m.cache_read_input_tokens??0,me=m.output_tokens_details?.thinking_tokens??void 0,Ne,K,ie=m.iterations?.some((se)=>se.type==="fallback_message");if(m.iterations&&m.iterations.length>0&&!ie){let se=m.iterations.filter((fe)=>fe.type==="compaction"||fe.type==="message");if(se.length>0){let fe=se.reduce((Ue,Ce)=>({input:Ue.input+Ce.input_tokens,output:Ue.output+Ce.output_tokens}),{input:0,output:0});Ne=fe.input,K=fe.output}else Ne=m.input_tokens,K=m.output_tokens}else Ne=m.input_tokens,K=m.output_tokens;return{inputTokens:{total:Ne+A+V,noCache:Ne,cacheRead:V,cacheWrite:A},outputTokens:{total:K,text:me==null?void 0:K-me,reasoning:me},raw:N??m}}var ho=a(()=>s(t({type:n("code_execution_result"),stdout:e(),stderr:e(),return_code:r(),content:o(t({type:n("code_execution_output"),file_id:e()})).optional().default([])}))),Cn=a(()=>s(t({code:e()}))),Sn=S({id:"anthropic.code_execution_20250522",inputSchema:Cn,outputSchema:ho}),Nn=(m={})=>Sn(m),mo=a(()=>s(f("type",[t({type:n("code_execution_result"),stdout:e(),stderr:e(),return_code:r(),content:o(t({type:n("code_execution_output"),file_id:e()})).optional().default([])}),t({type:n("bash_code_execution_result"),content:o(t({type:n("bash_code_execution_output"),file_id:e()})),stdout:e(),stderr:e(),return_code:r()}),t({type:n("bash_code_execution_tool_result_error"),error_code:e()}),t({type:n("text_editor_code_execution_tool_result_error"),error_code:e()}),t({type:n("text_editor_code_execution_view_result"),content:e(),file_type:e(),num_lines:r().nullable(),start_line:r().nullable(),total_lines:r().nullable()}),t({type:n("text_editor_code_execution_create_result"),is_file_update:c()}),t({type:n("text_editor_code_execution_str_replace_result"),lines:o(e()).nullable(),new_lines:r().nullable(),new_start:r().nullable(),old_lines:r().nullable(),old_start:r().nullable()})]))),On=a(()=>s(f("type",[t({type:n("programmatic-tool-call"),code:e()}),t({type:n("bash_code_execution"),command:e()}),f("command",[t({type:n("text_editor_code_execution"),command:n("view"),path:e()}),t({type:n("text_editor_code_execution"),command:n("create"),path:e(),file_text:e().nullish()}),t({type:n("text_editor_code_execution"),command:n("str_replace"),path:e(),old_str:e(),new_str:e()})])]))),In=S({id:"anthropic.code_execution_20250825",inputSchema:On,outputSchema:mo,supportsDeferredResults:!0}),An=(m={})=>Xe(In(m),{type:"provider",prepareProviderOptions:(N)=>{let A=N?.anthropic;return{...N,anthropic:{...A,allowedCallers:[...new Set([...A?.allowedCallers??[],"code_execution_20250825"])]}}}}),go=a(()=>s(f("type",[t({type:n("code_execution_result"),stdout:e(),stderr:e(),return_code:r(),content:o(t({type:n("code_execution_output"),file_id:e()})).optional().default([])}),t({type:n("encrypted_code_execution_result"),encrypted_stdout:e(),stderr:e(),return_code:r(),content:o(t({type:n("code_execution_output"),file_id:e()})).optional().default([])}),t({type:n("bash_code_execution_result"),content:o(t({type:n("bash_code_execution_output"),file_id:e()})),stdout:e(),stderr:e(),return_code:r()}),t({type:n("bash_code_execution_tool_result_error"),error_code:e()}),t({type:n("text_editor_code_execution_tool_result_error"),error_code:e()}),t({type:n("text_editor_code_execution_view_result"),content:e(),file_type:e(),num_lines:r().nullable(),start_line:r().nullable(),total_lines:r().nullable()}),t({type:n("text_editor_code_execution_create_result"),is_file_update:c()}),t({type:n("text_editor_code_execution_str_replace_result"),lines:o(e()).nullable(),new_lines:r().nullable(),new_start:r().nullable(),old_lines:r().nullable(),old_start:r().nullable()})]))),Rn=a(()=>s(f("type",[t({type:n("programmatic-tool-call"),code:e()}),t({type:n("bash_code_execution"),command:e()}),f("command",[t({type:n("text_editor_code_execution"),command:n("view"),path:e()}),t({type:n("text_editor_code_execution"),command:n("create"),path:e(),file_text:e().nullish()}),t({type:n("text_editor_code_execution"),command:n("str_replace"),path:e(),old_str:e(),new_str:e()})])]))),Bn=S({id:"anthropic.code_execution_20260120",inputSchema:Rn,outputSchema:go,supportsDeferredResults:!0}),En=(m={})=>Xe(Bn(m),{type:"provider",prepareProviderOptions:(N)=>{let A=N?.anthropic;return{...N,anthropic:{...A,allowedCallers:[...new Set([...A?.allowedCallers??[],"code_execution_20260120"])]}}}}),fo=a(()=>s(o(t({type:n("tool_reference"),toolName:e()})))),Mn=a(()=>s(t({pattern:e(),limit:r().optional()}))),Un=S({id:"anthropic.tool_search_regex_20251119",inputSchema:Mn,outputSchema:fo,supportsDeferredResults:!0}),$n=(m={})=>Un(m);function qn(m){if(typeof m==="string")return new TextDecoder().decode(j(m));return new TextDecoder().decode(m)}function At(m){try{if(typeof m==="string")return Q(m);else if(typeof m==="object"&&m!==null)return m}catch{let N=m?.errorCode;return{errorCode:typeof N==="string"?N:"unavailable"}}return{}}async function Dn({prompt:m,sendReasoning:N,warnings:A,cacheControlValidator:V,toolNameMapping:me,toolsetNames:Ne={},convertMediaPart:K}){let ie=new Set,se=Hn(m),fe=V||new $t,Ue=void 0,Ce=[],Ze=-1;async function ve(Le){return(await h({provider:"anthropic",providerOptions:Le,schema:It}))?.citations?.enabled??!1}async function ke(Le){return(await h({provider:"anthropic",providerOptions:Le,schema:It}))?.containerUpload??!1}async function Ee(Le){let Re=await h({provider:"anthropic",providerOptions:Le,schema:It});return{title:Re?.title,context:Re?.context}}for(let Le=0;Le<se.length;Le++){let Re=se[Le],J=Le===se.length-1,Be=Re.type;switch(Be){case"system":{let ye=[];for(let{content:qe,providerOptions:X}of Re.messages){let Te=await h({provider:"anthropic",providerOptions:X,schema:Uo}),Ge=Te?.toolChanges??[],Z=[];if(qe!==""||Ge.length===0&&Te?.clearAt==null&&Te?.effort==null)Z.push({type:"text",text:qe,cache_control:fe.getCacheControl(X,{type:"system message",canCache:!0})});for(let ot of Ge)Z.push({type:ot.type,tool:{type:"tool_reference",name:me.toProviderToolName(ot.toolName)}});ye.push({content:Z,clearAt:Te?.clearAt,effort:Te?.effort,toolChangeCount:Ge.length})}let Pe=ye.reduce((qe,X)=>qe+X.toolChangeCount,0),tt=ye.some((qe)=>qe.clearAt!=null||qe.effort!=null);if(Le===0||Ue==null&&Pe===0&&!tt){if(Pe>0)A.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 qe of ye)if(qe.content.length===0&&qe.clearAt==null&&qe.effort!=null)Ce.push({role:"system",content:[],output_config:{effort:qe.effort}}),ie.add("mid-conversation-output-config-2026-07-01");else if(qe.clearAt!=null||qe.effort!=null)A.push({type:"other",message:"clearAt and effort on this initial system message are not supported by Anthropic. Use a separate effort-only system message with empty content to set effort. These options have been ignored."});Ue=ye.flatMap((qe)=>qe.content.filter((X)=>X.type==="text"))}else{ie.add("mid-conversation-system-2026-04-07");for(let qe of ye){if(Ce.push({role:"system",content:qe.content,...qe.clearAt!=null&&{clear_at:qe.clearAt},...qe.effort!=null&&{output_config:{effort:qe.effort}}}),qe.toolChangeCount>0)ie.add("mid-conversation-tool-changes-2026-07-01");if(qe.clearAt!=null)ie.add("mid-conversation-system-clear-at-2026-08-21");if(qe.effort!=null)ie.add("mid-conversation-output-config-2026-07-01")}}break}case"user":{let ye=[];for(let Pe of Re.messages){let{role:tt,content:qe}=Pe;switch(tt){case"user":if(qe.length>0)Ze=Ce.length;for(let X=0;X<qe.length;X++){let Te=qe[X],Ge=X===qe.length-1,Z=fe.getCacheControl(Te.providerOptions,{type:"user message part",canCache:!0})??(Ge?fe.getCacheControl(Pe.providerOptions,{type:"user message",canCache:!0}):void 0);switch(Te.type){case"text":ye.push({type:"text",text:Te.text,cache_control:Z});break;case"file":{let ot=await K?.(Te);if(ot!=null){ye.push({...ot,cache_control:Z});break}switch(Te.data.type){case"reference":{let Me=H({reference:Te.data.reference,provider:"anthropic"});if(ie.add("files-api-2025-04-14"),await ke(Te.providerOptions))ye.push({type:"container_upload",file_id:Me});else if(z(Te.mediaType)==="image")ye.push({type:"image",source:{type:"file",file_id:Me},cache_control:Z});else ye.push({type:"document",source:{type:"file",file_id:Me},cache_control:Z});break}case"text":{let Me=await ve(Te.providerOptions),Oe=await Ee(Te.providerOptions);ye.push({type:"document",source:{type:"text",media_type:"text/plain",data:Te.data.text},title:Oe.title??Te.filename,...Oe.context&&{context:Oe.context},...Me&&{citations:{enabled:!0}},cache_control:Z});break}case"url":case"data":{let Me=z(Te.mediaType);if(Me==="image")ye.push({type:"image",source:Te.data.type==="url"?{type:"url",url:Te.data.url.toString()}:{type:"base64",media_type:O({part:Te}),data:M(Te.data.data)},cache_control:Z});else if(Me==="application"&&(Te.data.type==="url"?Te.mediaType==="application/pdf":O({part:Te})==="application/pdf")){ie.add("pdfs-2024-09-25");let Oe=await ve(Te.providerOptions),Ke=await Ee(Te.providerOptions);ye.push({type:"document",source:Te.data.type==="url"?{type:"url",url:Te.data.url.toString()}:{type:"base64",media_type:"application/pdf",data:M(Te.data.data)},title:Ke.title??Te.filename,...Ke.context&&{context:Ke.context},...Oe&&{citations:{enabled:!0}},cache_control:Z})}else if(Te.mediaType==="text/plain"){let Oe=await ve(Te.providerOptions),Ke=await Ee(Te.providerOptions);ye.push({type:"document",source:Te.data.type==="url"?{type:"url",url:Te.data.url.toString()}:{type:"text",media_type:"text/plain",data:qn(Te.data.data)},title:Ke.title??Te.filename,...Ke.context&&{context:Ke.context},...Oe&&{citations:{enabled:!0}},cache_control:Z})}else throw new u({functionality:`media type: ${Te.mediaType}`});break}}break}}}break;case"tool":for(let X=0;X<qe.length;X++){let Te=qe[X];if(Te.type==="tool-approval-response")continue;let Ge=Te.output,Z="providerOptions"in Ge?Ge.providerOptions:Ge.type==="content"?Ge.value.find((te)=>te.providerOptions!=null)?.providerOptions:void 0,ot=X===qe.length-1,Me=fe.getCacheControl(Te.providerOptions,{type:"tool result part",canCache:!0})??fe.getCacheControl(Z,{type:"tool result output",canCache:!0})??(ot?fe.getCacheControl(Pe.providerOptions,{type:"tool result message",canCache:!0}):void 0),Oe;switch(Ge.type){case"content":Oe=Ge.value.map((te)=>{switch(te.type){case"text":return{type:"text",text:te.text};case"file":{let ue=z(te.mediaType);if(te.data.type==="reference"){let Ye=H({reference:te.data.reference,provider:"anthropic"});if(ie.add("files-api-2025-04-14"),ue==="image")return{type:"image",source:{type:"file",file_id:Ye}};return{type:"document",source:{type:"file",file_id:Ye}}}if(te.data.type==="url"){if(ue==="image")return{type:"image",source:{type:"url",url:te.data.url.toString()}};return{type:"document",source:{type:"url",url:te.data.url.toString()}}}if(te.data.type==="data"){if(ue==="image")return{type:"image",source:{type:"base64",media_type:O({part:te}),data:M(te.data.data)}};if(O({part:te})==="application/pdf")return ie.add("pdfs-2024-09-25"),{type:"document",source:{type:"base64",media_type:"application/pdf",data:M(te.data.data)}};A.push({type:"other",message:`unsupported tool content part type: ${te.type} with media type: ${te.mediaType}`});return}A.push({type:"other",message:`unsupported tool content part type: ${te.type} with data type: ${te.data.type}`});return}case"custom":{let ue=te.providerOptions?.anthropic;if(ue?.type==="tool-reference")return{type:"tool_reference",tool_name:ue.toolName};A.push({type:"other",message:"unsupported custom tool content part"});return}default:A.push({type:"other",message:`unsupported tool content part type: ${te.type}`});return}}).filter(De);break;case"text":case"error-text":Oe=Ge.value;break;case"execution-denied":Oe=Ge.reason??"Tool call execution denied.";break;default:Oe=JSON.stringify(Ge.value)}let Ke=zt({toolName:Te.toolName,providerOptions:Te.providerOptions,toolsetNames:Ne});ye.push({type:"tool_result",tool_use_id:Te.toolCallId,...Ke!=null&&{toolset_name:Ke},content:Oe,is_error:Ge.type==="error-text"||Ge.type==="error-json"?!0:void 0,cache_control:Me})}break;default:throw Error(`Unsupported role: ${tt}`)}}Ce.push({role:"user",content:ye});break}case"assistant":{let ye=[],Pe=new Set;for(let tt=0;tt<Re.messages.length;tt++){let qe=Re.messages[tt],X=tt===Re.messages.length-1,{content:Te}=qe;for(let Ge=0;Ge<Te.length;Ge++){let Z=Te[Ge],ot=Ge===Te.length-1,Me=fe.getCacheControl(Z.providerOptions,{type:"assistant message part",canCache:!0})??(ot?fe.getCacheControl(qe.providerOptions,{type:"assistant message",canCache:!0}):void 0);switch(Z.type){case"text":{let Oe=Z.providerOptions?.anthropic;if(Oe?.type==="compaction"){if(Z.text==="")break;if(typeof Oe.signature==="string")ie.add("compact-2026-09-04");ye.push({type:"compaction",content:Z.text,...typeof Oe.signature==="string"&&{signature:Oe.signature},cache_control:Me})}else ye.push({type:"text",text:J&&X&&ot?Z.text.trim():Z.text,...Oe?.citations!=null&&{citations:Oe.citations},cache_control:Me});break}case"reasoning":if(N){let Oe=await h({provider:"anthropic",providerOptions:Z.providerOptions,schema:Mo});if(Oe!=null)if(Oe.signature!=null)fe.getCacheControl(Z.providerOptions,{type:"thinking block",canCache:!1}),ye.push({type:"thinking",thinking:Z.text,signature:Oe.signature});else if(Oe.redactedData!=null)fe.getCacheControl(Z.providerOptions,{type:"redacted thinking block",canCache:!1}),ye.push({type:"redacted_thinking",data:Oe.redactedData});else A.push({type:"other",message:"unsupported reasoning metadata"});else A.push({type:"other",message:"unsupported reasoning metadata"})}else A.push({type:"other",message:"sending reasoning content is disabled for this model"});break;case"custom":{if(Z.kind!=="anthropic.fallback")break;let Oe=await q({value:Z.providerOptions?.anthropic,schema:Bo});if(!Oe.success){A.push({type:"other",message:"anthropic fallback metadata must include from.model and to.model"});break}ie.add("server-side-fallback-2026-06-01"),ye.push({type:"fallback",from:Oe.value.from,to:Oe.value.to});break}case"tool-call":{let Oe=Wt(Z.providerOptions);if(Z.providerExecuted){let te=me.toProviderToolName(Z.toolName);if(Z.providerOptions?.anthropic?.type==="mcp-tool-use"){Pe.add(Z.toolCallId);let ue=Z.providerOptions?.anthropic?.serverName;if(ue==null||typeof ue!=="string"){A.push({type:"other",message:"mcp tool use server name is required and must be a string"});break}ye.push({type:"mcp_tool_use",id:Z.toolCallId,name:Z.toolName,input:Z.input,server_name:ue,cache_control:Me})}else if(te==="code_execution"&&Z.input!=null&&typeof Z.input==="object"&&"type"in Z.input&&typeof Z.input.type==="string"&&(Z.input.type==="bash_code_execution"||Z.input.type==="text_editor_code_execution")){let{type:ue,...Ye}=Z.input;ye.push({type:"server_tool_use",id:Z.toolCallId,name:ue,input:Ye,...Oe&&{caller:Oe},cache_control:Me})}else if(te==="code_execution"&&Z.input!=null&&typeof Z.input==="object"&&"type"in Z.input&&Z.input.type==="programmatic-tool-call"){let{type:ue,...Ye}=Z.input;ye.push({type:"server_tool_use",id:Z.toolCallId,name:"code_execution",input:Ye,...Oe&&{caller:Oe},cache_control:Me})}else if(te==="code_execution"||te==="web_fetch"||te==="web_search")ye.push({type:"server_tool_use",id:Z.toolCallId,name:te,input:Z.input,...Oe&&{caller:Oe},cache_control:Me});else if(te==="tool_search_tool_regex"||te==="tool_search_tool_bm25")ye.push({type:"server_tool_use",id:Z.toolCallId,name:te,input:Z.input,...Oe&&{caller:Oe},cache_control:Me});else if(te==="advisor")ye.push({type:"server_tool_use",id:Z.toolCallId,name:"advisor",input:{},...Oe&&{caller:Oe},cache_control:Me});else A.push({type:"other",message:`provider executed tool call for tool ${Z.toolName} is not supported`});break}let Ke=zt({toolName:Z.toolName,providerOptions:Z.providerOptions,toolsetNames:Ne});if(Ke!=null){let te=Vt(Z.input),{action:ue}=te,Ye=typeof ue==="string";if(!Ye)A.push({type:"other",message:`toolset tool call for tool ${Z.toolName} is missing the action`});ye.push({type:"tool_use",id:Z.toolCallId,name:Ye?ue:Ke,toolset_name:Ke,input:te,...Oe&&{caller:Oe},cache_control:Me});break}ye.push({type:"tool_use",id:Z.toolCallId,name:Z.toolName,input:Vt(Z.input),...Oe&&{caller:Oe},cache_control:Me});break}case"tool-result":{let Oe=me.toProviderToolName(Z.toolName),Ke=Wt(Z.providerOptions);if(Pe.has(Z.toolCallId)){let te=Z.output;if(te.type!=="json"&&te.type!=="error-json"){A.push({type:"other",message:`provider executed tool result output type ${te.type} for tool ${Z.toolName} is not supported`});break}ye.push({type:"mcp_tool_result",tool_use_id:Z.toolCallId,is_error:te.type==="error-json",content:te.value,cache_control:Me})}else if(Oe==="code_execution"){let te=Z.output;if(te.type==="error-text"||te.type==="error-json"){let ue={};try{if(typeof te.value==="string")ue=Q(te.value);else if(typeof te.value==="object"&&te.value!==null)ue=te.value}catch{}if(ue.type==="code_execution_tool_result_error")ye.push({type:"code_execution_tool_result",tool_use_id:Z.toolCallId,content:{type:"code_execution_tool_result_error",error_code:ue.errorCode??"unknown"},cache_control:Me});else ye.push({type:"bash_code_execution_tool_result",tool_use_id:Z.toolCallId,cache_control:Me,content:{type:"bash_code_execution_tool_result_error",error_code:ue.errorCode??"unknown"}});break}if(te.type!=="json"){A.push({type:"other",message:`provider executed tool result output type ${te.type} for tool ${Z.toolName} is not supported`});break}if(te.value==null||typeof te.value!=="object"||!("type"in te.value)||typeof te.value.type!=="string"){A.push({type:"other",message:`provider executed tool result output value is not a valid code execution result for tool ${Z.toolName}`});break}if(te.value.type==="code_execution_result"){let ue=await x({value:te.value,schema:ho});ye.push({type:"code_execution_tool_result",tool_use_id:Z.toolCallId,content:{type:ue.type,stdout:ue.stdout,stderr:ue.stderr,return_code:ue.return_code,content:ue.content??[]},cache_control:Me})}else if(te.value.type==="encrypted_code_execution_result"){let ue=await x({value:te.value,schema:go});if(ue.type==="encrypted_code_execution_result")ye.push({type:"code_execution_tool_result",tool_use_id:Z.toolCallId,content:{type:ue.type,encrypted_stdout:ue.encrypted_stdout,stderr:ue.stderr,return_code:ue.return_code,content:ue.content??[]},cache_control:Me})}else{let ue=await x({value:te.value,schema:mo});if(ue.type==="code_execution_result")ye.push({type:"code_execution_tool_result",tool_use_id:Z.toolCallId,content:{type:ue.type,stdout:ue.stdout,stderr:ue.stderr,return_code:ue.return_code,content:ue.content??[]},cache_control:Me});else if(ue.type==="bash_code_execution_result"||ue.type==="bash_code_execution_tool_result_error")ye.push({type:"bash_code_execution_tool_result",tool_use_id:Z.toolCallId,cache_control:Me,content:ue.type==="bash_code_execution_result"?{type:ue.type,stdout:ue.stdout,stderr:ue.stderr,return_code:ue.return_code,content:ue.content}:ue});else ye.push({type:"text_editor_code_execution_tool_result",tool_use_id:Z.toolCallId,cache_control:Me,content:ue})}break}if(Oe==="web_fetch"){let te=Z.output;if(te.type==="error-json"){ye.push({type:"web_fetch_tool_result",tool_use_id:Z.toolCallId,content:{type:"web_fetch_tool_result_error",error_code:At(te.value).errorCode??"unavailable"},...Ke&&{caller:Ke},cache_control:Me});break}if(te.type!=="json"){A.push({type:"other",message:`provider executed tool result output type ${te.type} for tool ${Z.toolName} is not supported`});break}let ue=await x({value:te.value,schema:_o});ye.push({type:"web_fetch_tool_result",tool_use_id:Z.toolCallId,content:{type:"web_fetch_result",url:ue.url,retrieved_at:ue.retrievedAt,content:{type:"document",title:ue.content.title,citations:ue.content.citations,source:{type:ue.content.source.type,media_type:ue.content.source.mediaType,data:ue.content.source.data}}},...Ke&&{caller:Ke},cache_control:Me});break}if(Oe==="web_search"){let te=Z.output;if(te.type==="error-json"){ye.push({type:"web_search_tool_result",tool_use_id:Z.toolCallId,content:{type:"web_search_tool_result_error",error_code:At(te.value).errorCode??"unavailable"},...Ke&&{caller:Ke},cache_control:Me});break}if(te.type!=="json"){A.push({type:"other",message:`provider executed tool result output type ${te.type} for tool ${Z.toolName} is not supported`});break}let ue=await x({value:te.value,schema:po});ye.push({type:"web_search_tool_result",tool_use_id:Z.toolCallId,content:ue.map((Ye)=>({url:Ye.url,title:Ye.title,page_age:Ye.pageAge,encrypted_content:Ye.encryptedContent,type:Ye.type})),...Ke&&{caller:Ke},cache_control:Me});break}if(Oe==="tool_search_tool_regex"||Oe==="tool_search_tool_bm25"){let te=Z.output;if(te.type==="error-json"||te.type==="json"&&te.value!=null&&typeof te.value==="object"&&!Array.isArray(te.value)&&"type"in te.value&&te.value.type==="tool_search_tool_result_error"){ye.push({type:"tool_search_tool_result",tool_use_id:Z.toolCallId,content:{type:"tool_search_tool_result_error",error_code:At(te.value).errorCode??"unavailable"},cache_control:Me});break}if(te.type!=="json"){A.push({type:"other",message:`provider executed tool result output type ${te.type} for tool ${Z.toolName} is not supported`});break}let ue=(await x({value:te.value,schema:fo})).map((Ye)=>({type:"tool_reference",tool_name:Ye.toolName}));ye.push({type:"tool_search_tool_result",tool_use_id:Z.toolCallId,content:{type:"tool_search_tool_search_result",tool_references:ue},cache_control:Me});break}if(Oe==="advisor"){let te=Z.output;if(te.type!=="json"&&te.type!=="error-json"){A.push({type:"other",message:`provider executed tool result output type ${te.type} for tool ${Z.toolName} is not supported`});break}let ue=await x({value:te.value,schema:co});if(ue.type==="advisor_result")ye.push({type:"advisor_tool_result",tool_use_id:Z.toolCallId,content:{type:"advisor_result",text:ue.text,...ue.stopReason!==void 0&&{stop_reason:ue.stopReason}},cache_control:Me});else if(ue.type==="advisor_redacted_result")ye.push({type:"advisor_tool_result",tool_use_id:Z.toolCallId,content:{type:"advisor_redacted_result",encrypted_content:ue.encryptedContent,...ue.stopReason!==void 0&&{stop_reason:ue.stopReason}},cache_control:Me});else ye.push({type:"advisor_tool_result",tool_use_id:Z.toolCallId,content:{type:"advisor_tool_result_error",error_code:ue.errorCode},cache_control:Me});break}A.push({type:"other",message:`provider executed tool result for tool ${Z.toolName} is not supported`});break}}}}if(ye.length>0)Ce.push({role:"assistant",content:Pn(ye)});break}default:throw Error(`content type: ${Be}`)}}let We=new Set;for(let Le of Ce){if(Le.role!=="assistant")continue;for(let Re of Le.content)if(Re.type==="server_tool_use"&&Re.name==="code_execution")We.add(Re.id)}let Fe=new Set;for(let Le=0;Le<Ze;Le++){let Re=Ce[Le];if(Re.role!=="assistant")continue;for(let J of Re.content){if(!("caller"in J))continue;let Be=J.caller;if(Be==null||Be.type==="direct"||We.has(Be.tool_id))continue;let ye="id"in J?J.id:J.tool_use_id;if(delete J.caller,!Fe.has(ye))Fe.add(ye),A.push({type:"other",message:`Omitted caller metadata for tool ${ye} because source code execution tool ${Be.tool_id} is missing from the conversation history.`})}}return{prompt:{system:Ue,messages:Ce},betas:ie}}function Hn(m){let N=[],A=void 0;for(let V of m){let{role:me}=V;switch(me){case"system":if(A?.type!=="system")A={type:"system",messages:[]},N.push(A);A.messages.push(V);break;case"assistant":if(A?.type!=="assistant")A={type:"assistant",messages:[]},N.push(A);A.messages.push(V);break;case"user":if(A?.type!=="user")A={type:"user",messages:[]},N.push(A);A.messages.push(V);break;case"tool":if(A?.type!=="user")A={type:"user",messages:[]},N.push(A);A.messages.push(V);break;default:throw Error(`Unsupported role: ${me}`)}}return N}function Pn(m){let N=[],A=[];function V(){N.push(...A.filter((me)=>me.type!=="tool_use"),...A.filter((me)=>me.type==="tool_use")),A=[]}for(let me of m)if(me.type==="thinking"||me.type==="redacted_thinking"||me.type==="fallback")V(),N.push(me);else A.push(me);return V(),N}function zt({toolName:m,providerOptions:N,toolsetNames:A}){let V=A[m];if(V!=null)return V;let me=N?.anthropic?.toolsetName;return typeof me==="string"?me:void 0}function Wt(m){let N=m?.anthropic?.caller;if((N?.type==="code_execution_20250825"||N?.type==="code_execution_20260120")&&N.toolId)return{type:N.type,tool_id:N.toolId};return N?.type==="direct"?{type:"direct"}:void 0}function Vt(m){return typeof m==="object"&&m!==null&&!Array.isArray(m)?m:{rawInvalidInput:m}}function St({finishReason:m,isJsonResponseFromTool:N}){switch(m){case"pause_turn":case"end_turn":case"stop_sequence":return"stop";case"refusal":return"content-filter";case"tool_use":return N?"stop":"tool-calls";case"max_tokens":case"model_context_window_exceeded":return"length";case"compaction":return"other";default:return"other"}}var yo=new Set(["date-time","time","date","duration","email","hostname","uri","ipv4","ipv6","uuid"]),Ln=["minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf","minLength","maxLength","pattern","minItems","maxItems","uniqueItems","minProperties","maxProperties","not"];function Fn(m){return bo(m)}function _t(m){if(typeof m==="boolean"||!L(m))return m;return bo(m)}function bo(m){let N={},A=m;if(m.$ref!=null)return{$ref:m.$ref};if(m.$schema!=null)N.$schema=m.$schema;if(m.$id!=null)N.$id=m.$id;if(m.title!=null)N.title=m.title;if(m.description!=null)N.description=m.description;if(m.default!==void 0)N.default=m.default;if(m.const!==void 0)N.const=m.const;if(m.enum!=null)N.enum=m.enum;if(m.type!=null)N.type=m.type;if(m.anyOf!=null)N.anyOf=m.anyOf.map(_t);else if(m.oneOf!=null)N.anyOf=m.oneOf.map(_t);if(m.allOf!=null)N.allOf=m.allOf.map(_t);if(m.definitions!=null)N.definitions=Object.fromEntries(Object.entries(m.definitions).map(([me,Ne])=>[me,_t(Ne)]));if(A.$defs!=null){let me=N;me.$defs=Object.fromEntries(Object.entries(A.$defs).map(([Ne,K])=>[Ne,_t(K)]))}if(m.type==="object"||m.properties!=null){if(m.properties!=null)N.properties=Object.fromEntries(Object.entries(m.properties).map(([me,Ne])=>[me,_t(Ne)]));if(N.additionalProperties=!1,m.required!=null)N.required=m.required}if(m.items!=null)N.items=Array.isArray(m.items)?m.items.map(_t):_t(m.items);if(typeof m.format==="string"&&yo.has(m.format))N.format=m.format;let V=Jn(m);if(V!=null)N.description=N.description==null?V:`${N.description}
|
|
2
|
+
${V}`;return N}function Jn(m){let N=Ln.flatMap((A)=>{let V=m[A];if(V==null||V===!1)return[];return`${Kn(A)}: ${zn(V)}`});if(typeof m.format==="string"&&!yo.has(m.format))N.push(`format: ${m.format}`);return N.length===0?void 0:`${N.join("; ")}.`}function Kn(m){return m.replace(/[A-Z]/g,(N)=>` ${N.toLowerCase()}`)}function zn(m){if(typeof m==="string")return m;return JSON.stringify(m)}function Wn(m){let N=Vn(m.type);return xe({message:m.message,type:m.type,code:m.code??void 0,statusCode:m.statusCode??N.statusCode,isRetryable:m.isRetryable??N.isRetryable,data:"data"in m?m.data:m})}function Vn(m){switch(m){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 Nt(m,N,A){if(m.type==="web_search_result_location")return{type:"source",sourceType:"url",id:A(),url:m.url,title:m.title??void 0,providerMetadata:{anthropic:{citedText:m.cited_text,encryptedIndex:m.encrypted_index}}};if(m.type!=="page_location"&&m.type!=="char_location")return;let V=N[m.document_index];if(!V)return;return{type:"source",sourceType:"document",id:A(),mediaType:V.mediaType,title:m.document_title??V.title,filename:V.filename,providerMetadata:{anthropic:m.type==="page_location"?{citedText:m.cited_text,startPageNumber:m.start_page_number,endPageNumber:m.end_page_number}:{citedText:m.cited_text,startCharIndex:m.start_char_index,endCharIndex:m.end_char_index}}}}function vt(m){return m==null?void 0:{type:m.type,toolId:"tool_id"in m?m.tool_id:void 0}}function at(m){let N=vt(m);return N==null?{}:{providerMetadata:{anthropic:{caller:N}}}}function Xn(m){let N={};for(let A of m??[])if(A.type==="provider"&&A.id==="anthropic.computer_toolset_20260801")N[A.name]="computer";return N}function Xt({memberName:m,input:N}){return{action:m,...typeof N==="object"&&N!==null&&!Array.isArray(N)?N:{}}}function Gt(m){let N=m.indexOf(".");return N===-1?m:m.substring(0,N)}var xo=class m{static[k](N){return E({modelId:N.modelId,config:N.config})}static[T](N){return new m(N.modelId,N.config)}constructor(N,A){this.specificationVersion="v4",this.modelId=N,this.config=A,this.generateId=A.generateId??C}supportsUrl(N){return N.protocol==="https:"}get provider(){return this.config.provider}get supportedUrls(){return this.config.supportedUrls?.()??{}}static async prepareRequest({modelId:N,config:A,options:{userSuppliedBetas:V,prompt:me,maxOutputTokens:Ne,temperature:K,topP:ie,topK:se,frequencyPenalty:fe,presencePenalty:Ue,stopSequences:Ce,responseFormat:Ze,seed:ve,tools:ke,toolChoice:Ee,reasoning:We,providerOptions:Fe,stream:Le}}){let Re=[];if(fe!=null)Re.push({type:"unsupported",feature:"frequencyPenalty"});if(Ue!=null)Re.push({type:"unsupported",feature:"presencePenalty"});if(ve!=null)Re.push({type:"unsupported",feature:"seed"});let J=A.maxTemperature??1,Be=A.maxTemperature==null?"anthropic":Gt(A.provider);if(K!=null&&K>J)Re.push({type:"unsupported",feature:"temperature",details:`${K} exceeds ${Be} maximum of ${J.toFixed(1)}. clamped to ${J.toFixed(1)}`}),K=J;else if(K!=null&&K<0)Re.push({type:"unsupported",feature:"temperature",details:`${K} is below ${Be} minimum of 0. clamped to 0`}),K=0;if(Ze?.type==="json"){if(Ze.schema==null)Re.push({type:"unsupported",feature:"responseFormat",details:"JSON response format requires a schema. The response format is ignored."})}let ye=Gt(A.provider),Pe=await h({provider:"anthropic",providerOptions:Fe,schema:Jt}),tt=ye!=="anthropic"?await h({provider:ye,providerOptions:Fe,schema:Jt}):null,qe=tt!=null,X=Object.assign({},Pe??{},tt??{}),{maxOutputTokens:Te,supportsStructuredOutput:Ge,supportsAdaptiveThinking:Z,rejectsSamplingParameters:ot,supportsXhighEffort:Me,rejectsThinkingDisabledAboveHighEffort:Oe,rejectsThinkingDisabled:Ke,rejectsBudgetThinking:te,rejectsForcedToolUse:ue,supportsBetweenToolsThinking:Ye,isKnownModel:mt}=Gn(N);if(!mt&&Ne==null)Re.push({type:"compatibility",feature:"maxOutputTokens",details:`The model "${N}" is unknown. The max output tokens have been limited to ${Te}. Set maxOutputTokens explicitly to override this limit.`});if(ot){if(K!=null)Re.push({type:"unsupported",feature:"temperature",details:`temperature is not supported by ${N} and will be ignored`}),K=void 0;if(se!=null)Re.push({type:"unsupported",feature:"topK",details:`topK is not supported by ${N} and will be ignored`}),se=void 0;if(ie!=null)Re.push({type:"unsupported",feature:"topP",details:`topP is not supported by ${N} and will be ignored`}),ie=void 0}let gt=mt||N.includes("claude-"),ft=(A.supportsNativeStructuredOutput??!0)&&Ge,kt=(A.supportsStrictTools??!0)&&Ge,pt=X?.structuredOutputMode??"auto",Qe=pt==="outputFormat"||pt==="auto"&&ft;if(!Qe&&ue&&ft&&Ze?.type==="json"&&Ze.schema!=null)Re.push({type:"unsupported",feature:"providerOptions.anthropic.structuredOutputMode",details:`structuredOutputMode 'jsonTool' is not supported by ${N} because it rejects forced tool use. Using 'outputFormat' instead.`}),Qe=!0;let je=Ze?.type==="json"&&Ze.schema!=null&&!Qe?{type:"function",name:"json",description:"Respond with a JSON object.",inputSchema:Ze.schema}:void 0;if(je!=null&&X?.disableParallelToolUse===!1)Re.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 ee=X?.contextManagement,B=X?.compaction;if(ee!=null&&B!=null)throw new b({argument:"providerOptions",message:"Anthropic provider options `compaction` and `contextManagement` cannot be used together."});let $e=new $t(A.cacheControlProviderOptionsName),be=le({tools:ke,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.computer_20251124":"computer","anthropic.computer_toolset_20260801":"computer","anthropic.text_editor_20241022":"str_replace_editor","anthropic.text_editor_20250124":"str_replace_editor","anthropic.text_editor_20250429":"str_replace_based_edit_tool","anthropic.text_editor_20250728":"str_replace_based_edit_tool","anthropic.bash_20241022":"bash","anthropic.bash_20250124":"bash","anthropic.memory_20250818":"memory","anthropic.web_search_20250305":"web_search","anthropic.web_search_20260209":"web_search","anthropic.web_search_20260318":"web_search","anthropic.web_fetch_20250910":"web_fetch","anthropic.web_fetch_20260209":"web_fetch","anthropic.web_fetch_20260318":"web_fetch","anthropic.tool_search_regex_20251119":"tool_search_tool_regex","anthropic.tool_search_bm25_20251119":"tool_search_tool_bm25","anthropic.advisor_20260301":"advisor"}}),Je=Xn(ke),{prompt:dt,betas:et}=await Dn({prompt:me,sendReasoning:X?.sendReasoning??!0,warnings:Re,cacheControlValidator:$e,toolNameMapping:be,toolsetNames:Je,convertMediaPart:A.convertMediaPart});if(W(We)&&X?.effort==null){let Ie=Zn({reasoning:We,modelId:N,supportsAdaptiveThinking:Z,supportsXhighEffort:Me,rejectsThinkingDisabled:Ke,supportsBetweenToolsThinking:Ye,maxOutputTokensForModel:Te,warnings:Re});if(Ie!=null){if(X.thinking==null)X.thinking=Ie.thinking;if(Ie.effort!=null&&X.thinking?.type!=="disabled")X.effort=Ie.effort}}if(Ke&&X?.thinking!=null){let Ie=X.thinking;if(Ie.type==="disabled"&&Ye)Re.push({type:"unsupported",feature:"providerOptions.anthropic.thinking",details:`thinking cannot be disabled for ${N}. Using 'between_tools' thinking, the lowest thinking setting, instead.`}),X.thinking={type:"between_tools"};else if(Ie.type==="disabled")Re.push({type:"unsupported",feature:"providerOptions.anthropic.thinking",details:`thinking cannot be disabled for ${N}; it always uses adaptive thinking. The thinking setting has been removed. Lower 'effort' to reduce thinking.`}),X.thinking=void 0}if(te&&X?.thinking?.type==="enabled")Re.push({type:"unsupported",feature:"providerOptions.anthropic.thinking",details:Ke?`budget-based thinking is not supported by ${N}; it always uses adaptive thinking. Using adaptive thinking instead. Use 'effort' to control how much the model thinks.`:`budget-based thinking is not supported by ${N}. Using adaptive thinking instead. Use 'effort' to control how much the model thinks.`}),X.thinking={type:"adaptive"};if(Oe&&X?.thinking?.type==="disabled"&&(X.effort==="xhigh"||X.effort==="max"))Re.push({type:"unsupported",feature:"providerOptions.anthropic.effort",details:`effort '${X.effort}' is not supported by ${N} when thinking is disabled. The effort has been lowered to 'high'.`}),X.effort="high";if(X?.thinking?.type==="between_tools"&&(X.effort==="xhigh"||X.effort==="max"))Re.push({type:"unsupported",feature:"providerOptions.anthropic.effort",details:`effort '${X.effort}' is not supported with 'between_tools' thinking. The effort has been lowered to 'high'.`}),X.effort="high";let nt=X?.thinking?.type,Ht=nt==="enabled"||nt==="adaptive"||nt==="between_tools",wt=X?.thinking!=null&&"blockBinding"in X.thinking?X.thinking.blockBinding:void 0,jo=Ht||nt==="disabled"||wt!=null,xt=nt==="enabled"?X?.thinking?.budgetTokens:void 0,Ot=nt==="adaptive"?X?.thinking?.display:void 0,Pt=Ne??Te,it={model:N,max_tokens:Pt,temperature:K,top_k:se,top_p:ie,stop_sequences:Ce,...jo&&{thinking:{...nt!=null&&{type:nt},...xt!=null&&{budget_tokens:xt},...Ot!=null&&{display:Ot},...wt!=null&&{block_binding:{prefix_mismatch_behavior:wt.prefixMismatchBehavior}}}},...(X?.effort||X?.taskBudget||Qe&&Ze?.type==="json"&&Ze.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}}},...Qe&&Ze?.type==="json"&&Ze.schema!=null&&{format:{type:"json_schema",schema:Fn(Ze.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((Ie)=>({type:Ie.type,name:Ie.name,url:Ie.url,authorization_token:Ie.authorizationToken,tool_configuration:Ie.toolConfiguration?{allowed_tools:Ie.toolConfiguration.allowedTools,enabled:Ie.toolConfiguration.enabled}:void 0}))},...X?.container&&{container:X.container.skills&&X.container.skills.length>0?{id:X.container.id,skills:X.container.skills.map((Ie)=>({type:Ie.type,skill_id:Ie.type==="custom"?H({reference:Ie.providerReference,provider:"anthropic"}):Ie.skillId,version:Ie.version}))}:X.container.id},system:dt.system,messages:dt.messages,...X?.safeguards&&X.safeguards.length>0&&{safeguards:X.safeguards.map((Ie)=>({type:Ie.type,...Ie.classifierContext!==void 0&&{classifier_context:Ie.classifierContext}}))},...B&&{compaction:{type:B.type,...B.instructions!==void 0&&{instructions:B.instructions}}},...ee&&{context_management:{edits:ee.edits.map((Ie)=>{let Ft=Ie.type;switch(Ft){case"clear_tool_uses_20250919":return{type:Ie.type,...Ie.trigger!==void 0&&{trigger:Ie.trigger},...Ie.keep!==void 0&&{keep:Ie.keep},...Ie.clearAtLeast!==void 0&&{clear_at_least:Ie.clearAtLeast},...Ie.clearToolInputs!==void 0&&{clear_tool_inputs:Ie.clearToolInputs},...Ie.excludeTools!==void 0&&{exclude_tools:Ie.excludeTools}};case"clear_thinking_20251015":return{type:Ie.type,...Ie.keep!==void 0&&{keep:Ie.keep}};case"compact_20260112":return{type:Ie.type,...Ie.trigger!==void 0&&{trigger:Ie.trigger},...Ie.pauseAfterCompaction!==void 0&&{pause_after_compaction:Ie.pauseAfterCompaction},...Ie.instructions!==void 0&&{instructions:Ie.instructions}};default:Re.push({type:"other",message:`Unknown context management strategy: ${Ft}`});return}}).filter((Ie)=>Ie!==void 0)}}};if(Ht){if(nt==="enabled"&&xt==null)Re.push({type:"compatibility",feature:"extended thinking",details:"thinking budget is required when thinking is enabled. using default budget of 1024 tokens."}),it.thinking={type:"enabled",budget_tokens:1024},xt=1024;if(it.temperature!=null&&!A.supportsTemperatureAndTopPWithThinking)it.temperature=void 0,Re.push({type:"unsupported",feature:"temperature",details:"temperature is not supported when thinking is enabled"});if(se!=null)it.top_k=void 0,Re.push({type:"unsupported",feature:"topK",details:"topK is not supported when thinking is enabled"});if(ie!=null&&!A.supportsTemperatureAndTopPWithThinking)it.top_p=void 0,Re.push({type:"unsupported",feature:"topP",details:"topP is not supported when thinking is enabled"});it.max_tokens=Pt+(xt??0)}else if(gt&&ie!=null&&K!=null)Re.push({type:"unsupported",feature:"topP",details:"topP is not supported when temperature is set. topP is ignored."}),it.top_p=void 0;if(mt&&it.max_tokens>Te){if(Ne!=null)Re.push({type:"unsupported",feature:"maxOutputTokens",details:`${it.max_tokens} (maxOutputTokens + thinkingBudget) is greater than ${N} ${Te} max output tokens. The max output tokens have been limited to ${Te}.`});it.max_tokens=Te}if(X?.mcpServers&&X.mcpServers.length>0)et.add("mcp-client-2025-04-04");if(X?.safeguards&&X.safeguards.length>0)et.add("dangerous-tool-use-2026-09-03");if(B)et.add("compact-2026-09-04");if(ee){if(et.add("context-management-2025-06-27"),ee.edits.some((Ie)=>Ie.type==="compact_20260112"))et.add("compact-2026-01-12")}if(X?.container&&X.container.skills&&X.container.skills.length>0){if(et.add("code-execution-2025-08-25"),et.add("skills-2025-10-02"),et.add("files-api-2025-04-14"),!ke?.some((Ie)=>Ie.type==="provider"&&(Ie.id==="anthropic.code_execution_20250825"||Ie.id==="anthropic.code_execution_20260120")))Re.push({type:"other",message:"code execution tool is required when using skills"})}if(X?.taskBudget)et.add("task-budgets-2026-03-13");if(X?.speed==="fast")et.add("fast-mode-2026-02-01");if(Ot==="updates")et.add("thinking-display-updates-2026-08-18");if(wt!=null)et.add("thinking-binding-controls-2026-08-01");if(X?.fallbacks==="default")et.add("server-side-fallback-2026-07-01");else if(X?.fallbacks&&X.fallbacks.length>0)et.add("server-side-fallback-2026-06-01");let Lt=Le&&(X?.toolStreaming??!0),{tools:To,toolChoice:Co,toolWarnings:So,betas:No}=await Tn(je!=null?{tools:[...ke??[],je],toolChoice:{type:"required"},disableParallelToolUse:!0,cacheControlValidator:$e,supportsStructuredOutput:!1,supportsStrictTools:kt,defaultEagerInputStreaming:Lt,rejectsForcedToolUse:ue||nt==="enabled"}:{tools:ke??[],toolChoice:Ee,disableParallelToolUse:X?.disableParallelToolUse,cacheControlValidator:$e,supportsStructuredOutput:ft,supportsStrictTools:kt,defaultEagerInputStreaming:Lt,rejectsForcedToolUse:ue||nt==="enabled"}),Oo=$e.getWarnings();return{args:{...it,tools:To,tool_choice:Co,stream:Le===!0?!0:void 0},warnings:[...Re,...So,...Oo],betas:new Set([...et,...No,...V,...X?.anthropicBeta??[]]),usesJsonResponseTool:je!=null,toolNameMapping:be,providerOptionsName:ye,usedCustomProviderKey:qe}}getArgs(N){return m.prepareRequest({modelId:this.modelId,config:this.config,options:N})}async getHeaders({betas:N,configHeaders:A,headers:V,providerOptions:me}){let Ne=d(A,V,N.size>0?{"anthropic-beta":Array.from(N).join(",")}:{});return this.config.transformRequestHeaders?this.config.transformRequestHeaders(Ne,me):Ne}getBetasFromHeaders(N,A){let V=N?.["anthropic-beta"]??"",me=A?.["anthropic-beta"]??"";return new Set([...V.toLowerCase().split(","),...me.toLowerCase().split(",")].map((Ne)=>Ne.trim()).filter((Ne)=>Ne!==""))}buildRequestUrl(N){return this.config.buildRequestUrl?.(this.config.baseURL,N)??`${this.config.baseURL}/messages`}transformRequestBody(N,A){return this.config.transformRequestBody?.(N,A)??N}extractCitationDocuments(N){let A=(V)=>{if(V.type!=="file")return!1;if(V.mediaType!=="application/pdf"&&V.mediaType!=="text/plain")return!1;return V.providerOptions?.anthropic?.citations?.enabled??!1};return N.filter((V)=>V.role==="user").flatMap((V)=>V.content).filter(A).map((V)=>{let me=V;return{title:me.filename??"Untitled Document",filename:me.filename,mediaType:me.mediaType}})}async doGenerate(N){let A=this.config.headers?await _(this.config.headers):void 0,{args:V,warnings:me,betas:Ne,usesJsonResponseTool:K,toolNameMapping:ie,providerOptionsName:se,usedCustomProviderKey:fe}=await this.getArgs({...N,stream:!1,userSuppliedBetas:this.getBetasFromHeaders(A,N.headers)}),Ue=[...this.extractCitationDocuments(N.prompt)],Ce=Zt(V.tools),{responseHeaders:Ze,value:ve,rawValue:ke}=await g({url:this.buildRequestUrl(!1),headers:await this.getHeaders({betas:Ne,configHeaders:A,headers:N.headers,providerOptions:N.providerOptions}),body:this.transformRequestBody(V,Ne),failedResponseHandler:st,successfulResponseHandler:p(Ct),abortSignal:N.abortSignal,fetch:this.config.fetch}),Ee=[],We={},Fe={},Le=!1,Re=ve.content.some((J)=>J.type==="web_search_tool_result"&&Array.isArray(J.content)&&J.content.length>0);for(let J of ve.content)switch(J.type){case"text":if(!K){let Be=J.citations??[];if(Ee.push({type:"text",text:J.text,...Be.length>0&&{citations:Be.map((ye)=>Bt(ye,Ue))},...Be.length>0&&{providerMetadata:{anthropic:{citations:Be}}}}),J.citations)for(let ye of J.citations){if(ye.type==="web_search_result_location"&&Re)continue;let Pe=Nt(ye,Ue,this.generateId);if(Pe)Ee.push(Pe)}}break;case"thinking":Ee.push({type:"reasoning",text:J.thinking,providerMetadata:{anthropic:{signature:J.signature}}});break;case"redacted_thinking":Ee.push({type:"reasoning",text:"",providerMetadata:{anthropic:{redactedData:J.data}}});break;case"container_upload":Ee.push({type:"custom",kind:"anthropic.container_upload",providerMetadata:{anthropic:{fileId:J.file_id}}});break;case"compaction":if(!J.content)break;Ee.push({type:"text",text:J.content,providerMetadata:{anthropic:{type:"compaction",...J.signature!=null&&{signature:J.signature}}}});break;case"tool_use":if(K&&J.name==="json")Le=!0,Ee.push({type:"text",text:JSON.stringify(J.input)});else if(J.toolset_name!=null)Ee.push({type:"tool-call",toolCallId:J.id,toolName:ie.toCustomToolName(J.toolset_name),input:JSON.stringify(Xt({memberName:J.name,input:J.input})),providerMetadata:{anthropic:{toolsetName:J.toolset_name,...at(J.caller).providerMetadata?.anthropic}}});else Ee.push({type:"tool-call",toolCallId:J.id,toolName:J.name,input:JSON.stringify(J.input),...at(J.caller)});break;case"server_tool_use":if(J.name==="text_editor_code_execution"||J.name==="bash_code_execution")Ee.push({type:"tool-call",toolCallId:J.id,toolName:ie.toCustomToolName("code_execution"),input:JSON.stringify({type:J.name,...J.input}),providerExecuted:!0,...Ce?{dynamic:!0}:{},...at(J.caller)});else if(J.name==="web_search"||J.name==="code_execution"||J.name==="web_fetch"){let Be=J.name==="code_execution"&&J.input!=null&&typeof J.input==="object"&&"code"in J.input&&!("type"in J.input)?{type:"programmatic-tool-call",...J.input}:J.input;Ee.push({type:"tool-call",toolCallId:J.id,toolName:ie.toCustomToolName(J.name),input:JSON.stringify(Be),providerExecuted:!0,...Ce&&J.name==="code_execution"?{dynamic:!0}:{},...at(J.caller)})}else if(J.name==="tool_search_tool_regex"||J.name==="tool_search_tool_bm25")Fe[J.id]=J.name,Ee.push({type:"tool-call",toolCallId:J.id,toolName:ie.toCustomToolName(J.name),input:JSON.stringify(J.input),providerExecuted:!0,...at(J.caller)});else if(J.name==="advisor")Ee.push({type:"tool-call",toolCallId:J.id,toolName:ie.toCustomToolName("advisor"),input:JSON.stringify(J.input),providerExecuted:!0,...at(J.caller)});break;case"mcp_tool_use":We[J.id]={type:"tool-call",toolCallId:J.id,toolName:J.name,input:JSON.stringify(J.input),providerExecuted:!0,dynamic:!0,providerMetadata:{anthropic:{type:"mcp-tool-use",serverName:J.server_name}}},Ee.push(We[J.id]);break;case"mcp_tool_result":Ee.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:We[J.tool_use_id].toolName,isError:J.is_error,result:J.content,dynamic:!0,providerMetadata:We[J.tool_use_id].providerMetadata});break;case"web_fetch_tool_result":if(J.content.type==="web_fetch_result")Ue.push({title:J.content.content.title??J.content.url,mediaType:J.content.content.source.media_type}),Ee.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:ie.toCustomToolName("web_fetch"),result:{type:"web_fetch_result",url:J.content.url,retrievedAt:J.content.retrieved_at,content:{type:J.content.content.type,title:J.content.content.title,citations:J.content.content.citations,source:{type:J.content.content.source.type,mediaType:J.content.content.source.media_type,data:J.content.content.source.data}}},...at(J.caller)});else if(J.content.type==="web_fetch_tool_result_error")Ee.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:ie.toCustomToolName("web_fetch"),isError:!0,result:{type:"web_fetch_tool_result_error",errorCode:J.content.error_code},...at(J.caller)});break;case"web_search_tool_result":if(Array.isArray(J.content)){Ee.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:ie.toCustomToolName("web_search"),result:J.content.map((Be)=>({url:Be.url,...Be.title!=null?{title:Be.title}:{},pageAge:Be.page_age??null,encryptedContent:Be.encrypted_content,type:Be.type})),...at(J.caller)});for(let Be of J.content)Ee.push({type:"source",sourceType:"url",id:this.generateId(),url:Be.url,...Be.title!=null?{title:Be.title}:{},providerMetadata:{anthropic:{pageAge:Be.page_age??null}}})}else Ee.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:ie.toCustomToolName("web_search"),isError:!0,result:{type:"web_search_tool_result_error",errorCode:J.content.error_code},...at(J.caller)});break;case"code_execution_tool_result":if(J.content.type==="code_execution_result")Ee.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:ie.toCustomToolName("code_execution"),result:{type:J.content.type,stdout:J.content.stdout,stderr:J.content.stderr,return_code:J.content.return_code,content:J.content.content??[]}});else if(J.content.type==="encrypted_code_execution_result")Ee.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:ie.toCustomToolName("code_execution"),result:{type:J.content.type,encrypted_stdout:J.content.encrypted_stdout,stderr:J.content.stderr,return_code:J.content.return_code,content:J.content.content??[]}});else if(J.content.type==="code_execution_tool_result_error")Ee.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:ie.toCustomToolName("code_execution"),isError:!0,result:{type:"code_execution_tool_result_error",errorCode:J.content.error_code}});break;case"bash_code_execution_tool_result":case"text_editor_code_execution_tool_result":Ee.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:ie.toCustomToolName("code_execution"),result:J.content});break;case"tool_search_tool_result":{let Be=Fe[J.tool_use_id];if(Be==null){let ye=ie.toCustomToolName("tool_search_tool_bm25"),Pe=ie.toCustomToolName("tool_search_tool_regex");if(ye!=="tool_search_tool_bm25")Be="tool_search_tool_bm25";else if(Pe!=="tool_search_tool_regex")Be="tool_search_tool_regex";else Be="tool_search_tool_regex"}if(J.content.type==="tool_search_tool_search_result")Ee.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:ie.toCustomToolName(Be),result:J.content.tool_references.map((ye)=>({type:ye.type,toolName:ye.tool_name}))});else Ee.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:ie.toCustomToolName(Be),isError:!0,result:{type:"tool_search_tool_result_error",errorCode:J.content.error_code}});break}case"advisor_tool_result":{let Be=ie.toCustomToolName("advisor");if(J.content.type==="advisor_result")Ee.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:Be,result:{type:"advisor_result",text:J.content.text,...J.content.stop_reason!=null&&{stopReason:J.content.stop_reason}}});else if(J.content.type==="advisor_redacted_result")Ee.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:Be,result:{type:"advisor_redacted_result",encryptedContent:J.content.encrypted_content,...J.content.stop_reason!=null&&{stopReason:J.content.stop_reason}}});else Ee.push({type:"tool-result",toolCallId:J.tool_use_id,toolName:Be,isError:!0,result:{type:"advisor_tool_result_error",errorCode:J.content.error_code}});break}case"fallback":Ee.push({type:"custom",kind:"anthropic.fallback",providerMetadata:{anthropic:{type:"fallback",from:J.from,to:J.to}}})}return{content:Ee,finishReason:{unified:St({finishReason:ve.stop_reason,isJsonResponseFromTool:Le}),raw:ve.stop_reason??void 0},usage:Mt({usage:ve.usage}),request:{body:V},response:{id:ve.id??void 0,modelId:ve.model??void 0,headers:Ze,body:ke},warnings:me,providerMetadata:(()=>{let J=Qt(ve.stop_details),Be={usage:ve.usage,stopSequence:ve.stop_sequence??null,...J!=null?{stopDetails:J}:{},...ve.input_transformations!=null?{inputTransformations:ve.input_transformations}:{},...ve.safeguard_results!=null?{safeguardResults:ve.safeguard_results}:{},iterations:ve.usage.iterations?ve.usage.iterations.map((Pe)=>({type:Pe.type,...Pe.model!=null?{model:Pe.model}:{},inputTokens:Pe.input_tokens,outputTokens:Pe.output_tokens,...Pe.cache_creation_input_tokens?{cacheCreationInputTokens:Pe.cache_creation_input_tokens}:{},...Pe.cache_read_input_tokens?{cacheReadInputTokens:Pe.cache_read_input_tokens}:{}})):null,container:ve.container?{expiresAt:ve.container.expires_at,id:ve.container.id,skills:ve.container.skills?.map((Pe)=>({type:Pe.type,skillId:Pe.skill_id,version:Pe.version}))??null}:null,contextManagement:Yt(ve.context_management)??null},ye={anthropic:Be};if(fe&&se!=="anthropic")ye[se]=Be;return ye})()}}async doStream(N){let A=this.config.headers?await _(this.config.headers):void 0,{args:V,warnings:me,betas:Ne,usesJsonResponseTool:K,toolNameMapping:ie,providerOptionsName:se,usedCustomProviderKey:fe}=await this.getArgs({...N,stream:!0,userSuppliedBetas:this.getBetasFromHeaders(A,N.headers)}),Ue=[...this.extractCitationDocuments(N.prompt)],Ce=Zt(V.tools),Ze=this.buildRequestUrl(!0),{responseHeaders:ve,value:ke}=await g({url:Ze,headers:await this.getHeaders({betas:Ne,configHeaders:A,headers:N.headers,providerOptions:N.providerOptions}),body:this.transformRequestBody(V,Ne),failedResponseHandler:st,successfulResponseHandler:D(Eo),abortSignal:N.abortSignal,fetch:this.config.fetch}),Ee={unified:"other",raw:void 0},We={input_tokens:0,output_tokens:0,cache_creation_input_tokens:0,cache_read_input_tokens:0,iterations:null},Fe={},Le={},Re={},J=null,Be=void 0,ye=null,Pe=void 0,tt,qe,X=null,Te=!1,Ge=!1,Z=[],ot=!1,Me,Oe=!1,Ke=void 0,te=this.generateId,ue=ke.pipeThrough(new TransformStream({start(Qe){Qe.enqueue({type:"stream-start",warnings:me})},transform(Qe,je){if(Oe)return;if(N.includeRawChunks)je.enqueue({type:"raw",rawValue:Qe.rawValue});if(!Qe.success){je.enqueue({type:"error",error:Qe.error});return}let ee=Qe.value;switch(ee.type){case"ping":return;case"content_block_start":{let B=ee.content_block,$e=B.type;if($e==="fallback"){je.enqueue({type:"custom",kind:"anthropic.fallback",providerMetadata:{anthropic:{type:"fallback",from:B.from,to:B.to}}});return}switch(Ke=$e,$e){case"text":if(K)return;Fe[ee.index]={type:"text",citations:[]},je.enqueue({type:"text-start",id:String(ee.index)});return;case"thinking":Fe[ee.index]={type:"reasoning"},je.enqueue({type:"reasoning-start",id:String(ee.index)});return;case"redacted_thinking":Fe[ee.index]={type:"reasoning"},je.enqueue({type:"reasoning-start",id:String(ee.index),providerMetadata:{anthropic:{redactedData:B.data}}});return;case"compaction":if(Fe[ee.index]={type:"text",citations:[]},je.enqueue({type:"text-start",id:String(ee.index),providerMetadata:{anthropic:{type:"compaction",...B.signature!=null&&{signature:B.signature}}}}),B.signature!=null&&B.content!=null&&B.content!=="")je.enqueue({type:"text-delta",id:String(ee.index),delta:B.content});return;case"tool_use":if(K&&B.name==="json")Te=!0,Fe[ee.index]={type:"text",citations:[]},je.enqueue({type:"text-start",id:String(ee.index)});else if(B.toolset_name!=null){let be=vt(B.caller),Je=ie.toCustomToolName(B.toolset_name),dt=B.input&&Object.keys(B.input).length>0;Fe[ee.index]={type:"tool-call",toolCallId:B.id,toolName:Je,input:dt?JSON.stringify(B.input):"",firstDelta:!0,toolset:{name:B.toolset_name,memberName:B.name},...be&&{caller:be}},je.enqueue({type:"tool-input-start",id:B.id,toolName:Je})}else{let be=vt(B.caller),Je=B.input&&Object.keys(B.input).length>0?JSON.stringify(B.input):"";Fe[ee.index]={type:"tool-call",toolCallId:B.id,toolName:B.name,input:Je,firstDelta:Je.length===0,...be&&{caller:be}},je.enqueue({type:"tool-input-start",id:B.id,toolName:B.name})}return;case"server_tool_use":{let be=vt(B.caller);if(["web_fetch","web_search","code_execution","text_editor_code_execution","bash_code_execution"].includes(B.name)){let Je=B.name==="text_editor_code_execution"||B.name==="bash_code_execution"?"code_execution":B.name,dt=B.name==="text_editor_code_execution"||B.name==="bash_code_execution"?B.name:B.name==="code_execution"?"programmatic-tool-call":void 0,et=ie.toCustomToolName(Je),nt=B.input!=null&&typeof B.input==="object"&&Object.keys(B.input).length>0?JSON.stringify(B.input):"";Fe[ee.index]={type:"tool-call",toolCallId:B.id,toolName:et,input:nt,providerExecuted:!0,...Ce&&Je==="code_execution"?{dynamic:!0}:{},firstDelta:nt.length===0,providerToolName:Je,providerToolInputType:dt,...be&&{caller:be}},je.enqueue({type:"tool-input-start",id:B.id,toolName:et,providerExecuted:!0,...Ce&&Je==="code_execution"?{dynamic:!0}:{}})}else if(B.name==="tool_search_tool_regex"||B.name==="tool_search_tool_bm25"){Re[B.id]=B.name;let Je=ie.toCustomToolName(B.name);Fe[ee.index]={type:"tool-call",toolCallId:B.id,toolName:Je,input:"",providerExecuted:!0,firstDelta:!0,providerToolName:B.name,...be&&{caller:be}},je.enqueue({type:"tool-input-start",id:B.id,toolName:Je,providerExecuted:!0})}else if(B.name==="advisor"){let Je=ie.toCustomToolName("advisor");Fe[ee.index]={type:"tool-call",toolCallId:B.id,toolName:Je,input:"{}",providerExecuted:!0,firstDelta:!0,providerToolName:B.name,...be&&{caller:be}},je.enqueue({type:"tool-input-start",id:B.id,toolName:Je,providerExecuted:!0})}return}case"web_fetch_tool_result":if(B.content.type==="web_fetch_result")Ue.push({title:B.content.content.title??B.content.url,mediaType:B.content.content.source.media_type}),je.enqueue({type:"tool-result",toolCallId:B.tool_use_id,toolName:ie.toCustomToolName("web_fetch"),result:{type:"web_fetch_result",url:B.content.url,retrievedAt:B.content.retrieved_at,content:{type:B.content.content.type,title:B.content.content.title,citations:B.content.content.citations,source:{type:B.content.content.source.type,mediaType:B.content.content.source.media_type,data:B.content.content.source.data}}},...at(B.caller)});else if(B.content.type==="web_fetch_tool_result_error")je.enqueue({type:"tool-result",toolCallId:B.tool_use_id,toolName:ie.toCustomToolName("web_fetch"),isError:!0,result:{type:"web_fetch_tool_result_error",errorCode:B.content.error_code},...at(B.caller)});return;case"web_search_tool_result":if(Array.isArray(B.content)){je.enqueue({type:"tool-result",toolCallId:B.tool_use_id,toolName:ie.toCustomToolName("web_search"),result:B.content.map((be)=>({url:be.url,...be.title!=null?{title:be.title}:{},pageAge:be.page_age??null,encryptedContent:be.encrypted_content,type:be.type})),...at(B.caller)});for(let be of B.content)Ge=!0,je.enqueue({type:"source",sourceType:"url",id:te(),url:be.url,...be.title!=null?{title:be.title}:{},providerMetadata:{anthropic:{pageAge:be.page_age??null}}})}else je.enqueue({type:"tool-result",toolCallId:B.tool_use_id,toolName:ie.toCustomToolName("web_search"),isError:!0,result:{type:"web_search_tool_result_error",errorCode:B.content.error_code},...at(B.caller)});return;case"code_execution_tool_result":if(B.content.type==="code_execution_result")je.enqueue({type:"tool-result",toolCallId:B.tool_use_id,toolName:ie.toCustomToolName("code_execution"),result:{type:B.content.type,stdout:B.content.stdout,stderr:B.content.stderr,return_code:B.content.return_code,content:B.content.content??[]}});else if(B.content.type==="encrypted_code_execution_result")je.enqueue({type:"tool-result",toolCallId:B.tool_use_id,toolName:ie.toCustomToolName("code_execution"),result:{type:B.content.type,encrypted_stdout:B.content.encrypted_stdout,stderr:B.content.stderr,return_code:B.content.return_code,content:B.content.content??[]}});else if(B.content.type==="code_execution_tool_result_error")je.enqueue({type:"tool-result",toolCallId:B.tool_use_id,toolName:ie.toCustomToolName("code_execution"),isError:!0,result:{type:"code_execution_tool_result_error",errorCode:B.content.error_code}});return;case"bash_code_execution_tool_result":case"text_editor_code_execution_tool_result":je.enqueue({type:"tool-result",toolCallId:B.tool_use_id,toolName:ie.toCustomToolName("code_execution"),result:B.content});return;case"tool_search_tool_result":{let be=Re[B.tool_use_id];if(be==null){let Je=ie.toCustomToolName("tool_search_tool_bm25"),dt=ie.toCustomToolName("tool_search_tool_regex");if(Je!=="tool_search_tool_bm25")be="tool_search_tool_bm25";else if(dt!=="tool_search_tool_regex")be="tool_search_tool_regex";else be="tool_search_tool_regex"}if(B.content.type==="tool_search_tool_search_result")je.enqueue({type:"tool-result",toolCallId:B.tool_use_id,toolName:ie.toCustomToolName(be),result:B.content.tool_references.map((Je)=>({type:Je.type,toolName:Je.tool_name}))});else je.enqueue({type:"tool-result",toolCallId:B.tool_use_id,toolName:ie.toCustomToolName(be),isError:!0,result:{type:"tool_search_tool_result_error",errorCode:B.content.error_code}});return}case"advisor_tool_result":{let be=ie.toCustomToolName("advisor");if(B.content.type==="advisor_result")je.enqueue({type:"tool-result",toolCallId:B.tool_use_id,toolName:be,result:{type:"advisor_result",text:B.content.text,...B.content.stop_reason!=null&&{stopReason:B.content.stop_reason}}});else if(B.content.type==="advisor_redacted_result")je.enqueue({type:"tool-result",toolCallId:B.tool_use_id,toolName:be,result:{type:"advisor_redacted_result",encryptedContent:B.content.encrypted_content,...B.content.stop_reason!=null&&{stopReason:B.content.stop_reason}}});else je.enqueue({type:"tool-result",toolCallId:B.tool_use_id,toolName:be,isError:!0,result:{type:"advisor_tool_result_error",errorCode:B.content.error_code}});return}case"mcp_tool_use":Le[B.id]={type:"tool-call",toolCallId:B.id,toolName:B.name,input:JSON.stringify(B.input),providerExecuted:!0,dynamic:!0,providerMetadata:{anthropic:{type:"mcp-tool-use",serverName:B.server_name}}},je.enqueue(Le[B.id]);return;case"mcp_tool_result":je.enqueue({type:"tool-result",toolCallId:B.tool_use_id,toolName:Le[B.tool_use_id].toolName,isError:B.is_error,result:B.content,dynamic:!0,providerMetadata:Le[B.tool_use_id].providerMetadata});return;default:throw Error(`Unsupported content block type: ${$e}`)}}case"content_block_stop":if(Fe[ee.index]!=null){let B=Fe[ee.index];switch(B.type){case"text":je.enqueue({type:"text-end",id:String(ee.index),...B.citations.length>0&&{citations:B.citations.map(($e)=>Bt($e,Ue)),providerMetadata:{anthropic:{citations:B.citations}}}});break;case"reasoning":je.enqueue({type:"reasoning-end",id:String(ee.index)});break;case"tool-call":if(!(K&&B.toolName==="json")){if(B.toolset!=null){let be={};try{be=B.input===""?{}:Q(B.input)}catch{be=void 0}B.input=be===void 0?B.input:JSON.stringify(Xt({memberName:B.toolset.memberName,input:be})),je.enqueue({type:"tool-input-delta",id:B.toolCallId,delta:B.input})}je.enqueue({type:"tool-input-end",id:B.toolCallId});let $e=B.input===""?"{}":B.input;if(B.providerToolName==="code_execution")try{let be=Q($e);if(be!=null&&typeof be==="object"&&"code"in be&&!("type"in be))$e=JSON.stringify({type:"programmatic-tool-call",...be})}catch{}je.enqueue({type:"tool-call",toolCallId:B.toolCallId,toolName:B.toolName,input:$e,providerExecuted:B.providerExecuted,...Ce&&B.providerToolName==="code_execution"?{dynamic:!0}:{},...(B.caller||B.toolset)&&{providerMetadata:{anthropic:{...B.toolset&&{toolsetName:B.toolset.name},...B.caller&&{caller:B.caller}}}}})}}delete Fe[ee.index]}Ke=void 0;return;case"content_block_delta":{let B=ee.delta.type;switch(B){case"text_delta":if(K)return;je.enqueue({type:"text-delta",id:String(ee.index),delta:ee.delta.text});return;case"thinking_delta":je.enqueue({type:"reasoning-delta",id:String(ee.index),delta:ee.delta.thinking});return;case"signature_delta":if(Ke==="thinking")je.enqueue({type:"reasoning-delta",id:String(ee.index),delta:"",providerMetadata:{anthropic:{signature:ee.delta.signature}}});return;case"compaction_delta":if(ee.delta.content!=null)je.enqueue({type:"text-delta",id:String(ee.index),delta:ee.delta.content});return;case"input_json_delta":{let $e=Fe[ee.index],be=ee.delta.partial_json;if(be.length===0)return;if(Te){if($e?.type!=="text")return;je.enqueue({type:"text-delta",id:String(ee.index),delta:be})}else{if($e?.type!=="tool-call")return;if($e.toolset!=null){$e.input+=be;return}if($e.firstDelta&&$e.providerToolInputType!=null)be=`{"type": "${$e.providerToolInputType}",${be.substring(1)}`;je.enqueue({type:"tool-input-delta",id:$e.toolCallId,delta:be}),$e.input+=be,$e.firstDelta=!1}return}case"citations_delta":{let $e=ee.delta.citation,be=Fe[ee.index];if(be?.type==="text")be.citations.push($e);if($e.type==="web_search_result_location")Z.push($e);else{let Je=Nt($e,Ue,te);if(Je)je.enqueue(Je)}return}default:throw Error(`Unsupported delta type: ${B}`)}}case"message_start":if(ot){if(Me===ee.message.id)return;Oe=!0,je.enqueue({type:"error",error:new P({data:ee,message:`Received message_start for message ${JSON.stringify(ee.message.id)} while message ${JSON.stringify(Me)} is still open.`})});return}if(ot=!0,Me=ee.message.id,We.input_tokens=ee.message.usage.input_tokens,We.cache_read_input_tokens=ee.message.usage.cache_read_input_tokens??0,We.cache_creation_input_tokens=ee.message.usage.cache_creation_input_tokens??0,Be={...ee.message.usage},ee.message.input_transformations!=null)tt=ee.message.input_transformations;if(ee.message.container!=null)X={expiresAt:ee.message.container.expires_at,id:ee.message.container.id,skills:null};if(ee.message.stop_reason!=null)Ee={unified:St({finishReason:ee.message.stop_reason,isJsonResponseFromTool:Te}),raw:ee.message.stop_reason};if(je.enqueue({type:"response-metadata",id:ee.message.id??void 0,modelId:ee.message.model??void 0}),je.enqueue({type:"custom",kind:"anthropic.message_start",providerMetadata:{anthropic:{id:ee.message.id??null,model:ee.message.model??null,usage:Be}}}),ee.message.content!=null)for(let B=0;B<ee.message.content.length;B++){let $e=ee.message.content[B];if($e.type==="tool_use"){let be=vt($e.caller);je.enqueue({type:"tool-input-start",id:$e.id,toolName:$e.name});let Je=JSON.stringify($e.input??{});je.enqueue({type:"tool-input-delta",id:$e.id,delta:Je}),je.enqueue({type:"tool-input-end",id:$e.id}),je.enqueue({type:"tool-call",toolCallId:$e.id,toolName:$e.name,input:Je,...be&&{providerMetadata:{anthropic:{caller:be}}}})}}return;case"message_delta":if(ee.usage.input_tokens!=null&&We.input_tokens!==ee.usage.input_tokens)We.input_tokens=ee.usage.input_tokens;if(We.output_tokens=ee.usage.output_tokens,ee.usage.output_tokens_details!=null)We.output_tokens_details=ee.usage.output_tokens_details;if(ee.usage.cache_read_input_tokens!=null)We.cache_read_input_tokens=ee.usage.cache_read_input_tokens;if(ee.usage.cache_creation_input_tokens!=null)We.cache_creation_input_tokens=ee.usage.cache_creation_input_tokens;if(ee.usage.iterations!=null)We.iterations=ee.usage.iterations;if(Ee={unified:St({finishReason:ee.delta.stop_reason,isJsonResponseFromTool:Te}),raw:ee.delta.stop_reason??void 0},ye=ee.delta.stop_sequence??null,Pe=Qt(ee.delta.stop_details),X=ee.delta.container!=null?{expiresAt:ee.delta.container.expires_at,id:ee.delta.container.id,skills:ee.delta.container.skills?.map((B)=>({type:B.type,skillId:B.skill_id,version:B.version}))??null}:null,ee.context_management)J=Yt(ee.context_management);if(ee.input_transformations!=null)tt=ee.input_transformations;if(ee.delta.safeguard_results!=null)qe=ee.delta.safeguard_results;Be={...Be,...ee.usage};return;case"message_stop":{ot=!1,Me=void 0;let B={usage:Be??null,stopSequence:ye,...Pe!=null?{stopDetails:Pe}:{},...tt!=null?{inputTransformations:tt}:{},...qe!=null?{safeguardResults:qe}:{},iterations:We.iterations?We.iterations.map((be)=>({type:be.type,...be.model!=null?{model:be.model}:{},inputTokens:be.input_tokens,outputTokens:be.output_tokens,...be.cache_creation_input_tokens?{cacheCreationInputTokens:be.cache_creation_input_tokens}:{},...be.cache_read_input_tokens?{cacheReadInputTokens:be.cache_read_input_tokens}:{}})):null,container:X,contextManagement:J},$e={anthropic:B};if(fe&&se!=="anthropic")$e[se]=B;if(!Ge)for(let be of Z){let Je=Nt(be,Ue,te);if(Je)je.enqueue(Je)}Z.length=0,je.enqueue({type:"finish",finishReason:Ee,usage:Mt({usage:We,rawUsage:Be}),providerMetadata:$e});return}case"error":je.enqueue({type:"error",error:Wn(ee.error)});return;default:throw Error(`Unsupported chunk type: ${ee}`)}}})),Ye=!1,mt=!1,gt,[ft,kt]=ue.pipeThrough(new TransformStream({transform(Qe,je){switch(Qe.type){case"response-metadata":Ye=!1;break;case"finish":Ye=!1,gt=Qe;break;case"error":mt=!0;break;case"text-delta":case"reasoning-delta":case"tool-input-delta":Ye||=Qe.delta.length>0;break;case"tool-call":Ye=!0}je.enqueue(Qe)},flush(Qe){if(Ye&&!mt)Qe.enqueue({type:"finish",finishReason:{unified:"interrupted",raw:void 0},usage:gt?.usage??{inputTokens:{total:void 0,noCache:void 0,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:void 0,text:void 0,reasoning:void 0}},...gt?.providerMetadata!=null?{providerMetadata:gt.providerMetadata}:{}})}})).tee(),pt=ft.getReader();try{await pt.read();let Qe=await pt.read();if(Qe.value?.type==="raw")Qe=await pt.read();if(Qe.value?.type==="error"){let je=Qe.value.error;if(!lt(je))throw Error("Expected a normalized Anthropic stream error");throw new w({message:je.message,url:Ze,requestBodyValues:V,statusCode:je.statusCode??500,responseHeaders:ve,responseBody:JSON.stringify(je.data),isRetryable:je.isRetryable??!1})}}finally{pt.cancel().catch(()=>{}),pt.releaseLock()}return{stream:kt,request:{body:V},response:{headers:ve}}}};function Gn(m){if(m.includes("claude-sonnet-5-5"))return{maxOutputTokens:128000,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!0,supportsXhighEffort:!0,rejectsThinkingDisabledAboveHighEffort:!0,rejectsThinkingDisabled:!0,rejectsBudgetThinking:!0,rejectsForcedToolUse:!0,supportsBetweenToolsThinking:!0,isKnownModel:!0};else if(m.includes("claude-opus-5-5"))return{maxOutputTokens:128000,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!0,supportsXhighEffort:!0,rejectsThinkingDisabledAboveHighEffort:!0,rejectsThinkingDisabled:!0,rejectsBudgetThinking:!0,rejectsForcedToolUse:!0,supportsBetweenToolsThinking:!1,isKnownModel:!0};else if(m.includes("claude-haiku-5-5"))return{maxOutputTokens:128000,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!0,supportsXhighEffort:!0,rejectsThinkingDisabledAboveHighEffort:!0,rejectsThinkingDisabled:!1,rejectsBudgetThinking:!0,rejectsForcedToolUse:!1,supportsBetweenToolsThinking:!1,isKnownModel:!0};else if(m.includes("claude-opus-5"))return{maxOutputTokens:128000,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!0,supportsXhighEffort:!0,rejectsThinkingDisabledAboveHighEffort:!0,rejectsThinkingDisabled:!1,rejectsBudgetThinking:!1,rejectsForcedToolUse:!1,supportsBetweenToolsThinking:!1,isKnownModel:!0};else if(m.includes("claude-fable-5-1"))return{maxOutputTokens:128000,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!0,supportsXhighEffort:!0,rejectsThinkingDisabledAboveHighEffort:!1,rejectsThinkingDisabled:!0,rejectsBudgetThinking:!0,rejectsForcedToolUse:!0,supportsBetweenToolsThinking:!1,isKnownModel:!0};else if(m.includes("claude-fable-5"))return{maxOutputTokens:128000,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!0,supportsXhighEffort:!0,rejectsThinkingDisabledAboveHighEffort:!1,rejectsThinkingDisabled:!0,rejectsBudgetThinking:!0,rejectsForcedToolUse:!1,supportsBetweenToolsThinking:!1,isKnownModel:!0};else if(m.includes("claude-opus-4-8")||m.includes("claude-opus-4-7")||m.includes("claude-sonnet-5"))return{maxOutputTokens:128000,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!0,supportsXhighEffort:!0,rejectsThinkingDisabledAboveHighEffort:!1,rejectsThinkingDisabled:!1,rejectsBudgetThinking:!1,rejectsForcedToolUse:!1,supportsBetweenToolsThinking:!1,isKnownModel:!0};else if(m.includes("claude-sonnet-4-6")||m.includes("claude-opus-4-6"))return{maxOutputTokens:128000,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!1,supportsXhighEffort:!1,rejectsThinkingDisabledAboveHighEffort:!1,rejectsThinkingDisabled:!1,rejectsBudgetThinking:!1,rejectsForcedToolUse:!1,supportsBetweenToolsThinking:!1,isKnownModel:!0};else if(m.includes("claude-sonnet-4-5")||m.includes("claude-opus-4-5")||m.includes("claude-haiku-4-5"))return{maxOutputTokens:64000,supportsStructuredOutput:!0,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,rejectsThinkingDisabledAboveHighEffort:!1,rejectsThinkingDisabled:!1,rejectsBudgetThinking:!1,rejectsForcedToolUse:!1,supportsBetweenToolsThinking:!1,isKnownModel:!0};else if(m.includes("claude-opus-4-1"))return{maxOutputTokens:32000,supportsStructuredOutput:!0,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,rejectsThinkingDisabledAboveHighEffort:!1,rejectsThinkingDisabled:!1,rejectsBudgetThinking:!1,rejectsForcedToolUse:!1,supportsBetweenToolsThinking:!1,isKnownModel:!0};else if(/claude-sonnet-4(?:-|@)/.test(m))return{maxOutputTokens:64000,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,rejectsThinkingDisabledAboveHighEffort:!1,rejectsThinkingDisabled:!1,rejectsBudgetThinking:!1,rejectsForcedToolUse:!1,supportsBetweenToolsThinking:!1,isKnownModel:!0};else if(/claude-opus-4(?:-|@)/.test(m))return{maxOutputTokens:32000,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,rejectsThinkingDisabledAboveHighEffort:!1,rejectsThinkingDisabled:!1,rejectsBudgetThinking:!1,rejectsForcedToolUse:!1,supportsBetweenToolsThinking:!1,isKnownModel:!0};else if(m.includes("claude-3-haiku"))return{maxOutputTokens:4096,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,rejectsThinkingDisabledAboveHighEffort:!1,rejectsThinkingDisabled:!1,rejectsBudgetThinking:!1,rejectsForcedToolUse:!1,supportsBetweenToolsThinking:!1,isKnownModel:!0};else if(/claude-(?:instant(?:-|$)|v?2(?=$|[-.:])|3(?=$|[-.]))/.test(m))return{maxOutputTokens:4096,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,rejectsThinkingDisabledAboveHighEffort:!1,rejectsThinkingDisabled:!1,rejectsBudgetThinking:!1,rejectsForcedToolUse:!1,supportsBetweenToolsThinking:!1,isKnownModel:!1};else if(m.includes("claude-"))return{maxOutputTokens:128000,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!0,supportsXhighEffort:!0,rejectsThinkingDisabledAboveHighEffort:!0,rejectsThinkingDisabled:!1,rejectsBudgetThinking:!1,rejectsForcedToolUse:!1,supportsBetweenToolsThinking:!1,isKnownModel:!1};else return{maxOutputTokens:4096,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,rejectsThinkingDisabledAboveHighEffort:!1,rejectsThinkingDisabled:!1,rejectsBudgetThinking:!1,rejectsForcedToolUse:!1,supportsBetweenToolsThinking:!1,isKnownModel:!1}}function Zt(m){if(!m)return!1;let N=!1,A=!1;for(let V of m){if("type"in V&&(V.type==="web_fetch_20260209"||V.type==="web_fetch_20260318"||V.type==="web_search_20260209"||V.type==="web_search_20260318")){N=!0;continue}if("type"in V&&(V.type==="code_execution_20250522"||V.type==="code_execution_20250825"||V.type==="code_execution_20260120")){A=!0;break}}return N&&!A}function Zn({reasoning:m,modelId:N,supportsAdaptiveThinking:A,supportsXhighEffort:V,rejectsThinkingDisabled:me,supportsBetweenToolsThinking:Ne,maxOutputTokensForModel:K,warnings:ie}){if(!W(m))return;if(m==="none"){if(Ne)return{thinking:{type:"between_tools"}};if(me)return ie.push({type:"compatibility",feature:"reasoning",details:`reasoning 'none' is not supported by ${N}; it always uses adaptive thinking. Using effort 'low' to minimize thinking instead.`}),{effort:"low"};return{thinking:{type:"disabled"}}}if(A)return{thinking:{type:"adaptive",display:"summarized"},effort:Se({reasoning:m,effortMap:{minimal:"low",low:"low",medium:"medium",high:"high",xhigh:V?"xhigh":"max",max:"max"},warnings:ie})};let se=ut({reasoning:m,maxOutputTokens:K,maxReasoningBudget:K,warnings:ie});if(se==null)return;return{thinking:{type:"enabled",budgetTokens:se}}}function Yt(m){return m?{appliedEdits:m.applied_edits.map((N)=>{switch(N.type){case"clear_tool_uses_20250919":return{type:N.type,clearedToolUses:N.cleared_tool_uses,clearedInputTokens:N.cleared_input_tokens};case"clear_thinking_20251015":return{type:N.type,clearedThinkingTurns:N.cleared_thinking_turns,clearedInputTokens:N.cleared_input_tokens};case"compact_20260112":return{type:N.type}}}).filter((N)=>N!==void 0)}:null}function Qt(m){if(m==null)return;return{type:m.type,...m.category!=null?{category:m.category}:{},...m.explanation!=null?{explanation:m.explanation}:{},...m.recommended_model!=null?{recommendedModel:m.recommended_model}:{}}}var Yn=/^[A-Za-z0-9_-]{1,64}$/,eo=a(()=>s(t({anthropicBeta:o(e()).optional()}))),vo=()=>t({id:e(),type:n("message_batch"),processing_status:e(),request_counts:t({processing:r(),succeeded:r(),errored:r(),canceled:r(),expired:r()}),created_at:e(),expires_at:e(),archived_at:e().nullish(),cancel_initiated_at:e().nullish(),ended_at:e().nullish(),results_url:e().nullish()}),Rt=a(()=>s(vo())),Qn=a(()=>s(t({data:o(vo()),has_more:c(),last_id:e().nullish()}))),er=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"]),tr=a(()=>s(f("type",[t({type:n("succeeded"),message:v()}),t({type:n("errored"),error:t({type:n("error"),error:t({type:e(),message:e()}),request_id:e().nullish()})}),t({type:n("canceled")}),t({type:n("expired")})]))),or=a(()=>s(t({custom_id:e(),result:v()})));function nr(m){for(let N of m){let A=N.type;if(A!=="text")throw new u({functionality:`batch request type: ${A}`,message:`The Anthropic Message Batches API does not support batch requests with type "${A}".`})}}var rr=class{constructor(m){this.options=m,this.specificationVersion="v4",this.provider=m.provider,this.supportedUrls=m.supportedUrls,this.generateId=m.config.generateId??C}async doStartBatch({requests:m,providerOptions:N,headers:A,abortSignal:V,webhookUrl:me}){nr(m),ar(m);let Ne=new Set(await to({provider:this.options.config.provider,providerOptions:N})),K=new Set(Ne),ie=[],se=me==null?[]:[{warning:{type:"unsupported",feature:"webhookUrl",details:"The Anthropic Message Batches API does not support completion webhooks."}}];for(let Ue of m){if((await to({provider:this.options.config.provider,providerOptions:Ue.options.providerOptions})).length>0)throw new u({functionality:"per-request providerOptions.anthropic.anthropicBeta",message:`Anthropic Message Batches do not support per-request betas (request "${Ue.id}"). Set providerOptions.anthropic.anthropicBeta on startBatch instead.`});let Ce=await xo.prepareRequest({modelId:Ue.modelId,config:this.options.config,options:{...Ue.options,stream:!1,userSuppliedBetas:new Set(Ne)}});if(Ce.usesJsonResponseTool)throw new u({functionality:"batch responseFormat JSON-tool fallback",message:`Anthropic Message Batches cannot decode the JSON-tool structured-output fallback (request "${Ue.id}") because batch results are retrieved independently of the start call. Use a model that supports native output_format structured outputs.`});let Ze=Ue.options.tools?.find((ke)=>ke.type==="provider"&&Ce.toolNameMapping.toProviderToolName(ke.name)!==ke.name);if(Ze!=null)throw new u({functionality:"aliased provider tool names in batches",message:`Anthropic Message Batches cannot restore the custom provider-tool name "${Ze.name}" when results are retrieved independently of the start call (request "${Ue.id}"). Use the provider's canonical tool name.`});let ve=this.options.config.transformRequestBody?.(Ce.args,Ce.betas)??Ce.args;ir({body:ve,requestId:Ue.id}),ie.push({custom_id:Ue.id,params:ve});for(let ke of Ce.betas)K.add(ke);for(let ke of Ce.warnings)se.push({requestId:Ue.id,warning:ke})}let{value:fe}=await g({url:this.getBatchUrl(""),headers:await this.getStartBatchHeaders({betas:K,headers:A}),body:{requests:ie},failedResponseHandler:st,successfulResponseHandler:p(Rt),abortSignal:V,fetch:this.options.config.fetch});return{batchId:fe.id,...jt(fe),warnings:se}}async doGetBatchStatus(m){return jt(await this.retrieveBatch(m))}async doCancelBatch(m){return await g({url:this.getBatchUrl(`/${encodeURIComponent(m.batchId)}/cancel`),headers:await this.getBatchHeaders(m.headers),body:{},failedResponseHandler:st,successfulResponseHandler:p(Rt),abortSignal:m.abortSignal,fetch:this.options.config.fetch}),{}}async doListBatches(m){let N=new URL(this.getBatchUrl(""));if(m.limit!=null)N.searchParams.set("limit",String(m.limit));if(m.cursor!=null)N.searchParams.set("after_id",m.cursor);let{value:A}=await R({url:N.toString(),validateUrl:!1,headers:await this.getBatchHeaders(m.headers),failedResponseHandler:st,successfulResponseHandler:p(Qn),abortSignal:m.abortSignal,fetch:this.options.config.fetch});return{batches:A.data.map((V)=>({batchId:V.id,...jt(V)})),...A.has_more&&A.last_id!=null?{nextCursor:A.last_id}:{}}}async doGetBatchResults(m){let N=await this.retrieveBatch(m);if(jt(N).status==="pending")throw new b({argument:"batchId",message:`Anthropic batch "${m.batchId}" is not complete.`});if(N.archived_at!=null)throw new b({argument:"batchId",message:`Anthropic batch "${m.batchId}" results are no longer available.`});if(N.results_url==null)throw new P({data:N,message:`Anthropic batch "${m.batchId}" completed without batch output.`});let{value:A}=await R({url:N.results_url,validateUrl:!0,credentialedOrigin:this.options.config.baseURL,trustedOrigin:this.options.config.baseURL,headers:await this.getBatchHeaders(m.headers),failedResponseHandler:st,successfulResponseHandler:_e(or,{maxLineBytes:this.options.maxLineBytes}),abortSignal:m.abortSignal,fetch:this.options.config.fetch});return ae(this.iterateBatchResults(A))}async retrieveBatch(m){let{value:N}=await R({url:this.getBatchUrl(`/${encodeURIComponent(m.batchId)}`),validateUrl:!1,headers:await this.getBatchHeaders(m.headers),failedResponseHandler:st,successfulResponseHandler:p(Rt),abortSignal:m.abortSignal,fetch:this.options.config.fetch});return N}async*iterateBatchResults(m){for await(let N of m)yield await cr(N,this.generateId)}getBatchUrl(m){return`${this.options.config.baseURL}/messages/batches${m}`}async getStartBatchHeaders({betas:m,headers:N}){return d(ze(await this.getBatchHeaders(N)),{"anthropic-beta":m.size>0?Array.from(m).join(","):void 0})}async getBatchHeaders(m){return d(this.options.config.headers?await _(this.options.config.headers):void 0,m)}};async function to({provider:m,providerOptions:N}){let A=m.split(".")[0],V=await h({provider:"anthropic",providerOptions:N,schema:eo}),me=A!=="anthropic"?await h({provider:A,providerOptions:N,schema:eo}):void 0;return Object.assign({},V??{},me??{}).anthropicBeta??[]}function ar(m){let N=new Set;for(let A of m){if(!Yn.test(A.id))throw new b({argument:"requests",message:`Anthropic batch request ID "${A.id}" must match ^[A-Za-z0-9_-]{1,64}$.`});if(N.has(A.id))throw new b({argument:"requests",message:`Anthropic batch request IDs must be unique; duplicate ID "${A.id}".`});N.add(A.id)}}function ir({body:m,requestId:N}){if(m.speed!=null)throw new u({functionality:"providerOptions.anthropic.speed",message:`Anthropic Message Batches do not support speed (request "${N}").`});if(Array.isArray(m.fallbacks)&&m.fallbacks.some((A)=>A!=null&&typeof A==="object"&&("speed"in A)&&A.speed!=null))throw new u({functionality:"providerOptions.anthropic.fallbacks[].speed",message:`Anthropic Message Batches do not support fallback speed (request "${N}").`})}function jt(m){let N=lr(m.request_counts);return{status:sr(m.processing_status),rawStatus:m.processing_status,...N!=null?{requestCounts:N}:{},createdAt:m.created_at,expiresAt:m.expires_at,providerMetadata:{anthropic:{archivedAt:m.archived_at??null,cancelInitiatedAt:m.cancel_initiated_at??null,endedAt:m.ended_at??null,requestCounts:m.request_counts,resultsUrl:m.results_url??null}}}}function sr(m){switch(m){case"ended":return"completed";default:return"pending"}}function lr(m){return ge({total:m.processing+m.succeeded+m.errored+m.canceled+m.expired,pending:m.processing,completed:m.succeeded,failed:m.errored+m.canceled+m.expired})}async function cr(m,N){let A=await q({value:m.result,schema:tr});if(!A.success)return oo(m.custom_id);let V=A.value;switch(V.type){case"canceled":return{type:"text",id:m.custom_id,status:"cancelled"};case"expired":return{type:"text",id:m.custom_id,status:"expired"};case"errored":{let me=V.error.request_id;return{type:"text",id:m.custom_id,status:"failed",error:{message:V.error.error.message,type:V.error.error.type},...me!=null?{providerMetadata:{anthropic:{requestId:me}}}:{}}}case"succeeded":{let me=await ur(V.message);if(me==null)return oo(m.custom_id);return{type:"text",id:m.custom_id,status:"succeeded",result:pr(me,N)}}}}function oo(m){return{type:"text",id:m,status:"failed",error:{message:"Anthropic returned an invalid Message batch result.",code:"invalid_response"}}}async function ur(m){let N=await q({value:m,schema:Ct});if(N.success)return N.value;if(!L(m)||!Array.isArray(m.content))return;let A=[];for(let me of m.content){let Ne=await q({value:{...m,content:[me]},schema:Ct});if(Ne.success){let[K]=Ne.value.content;if(K!=null)A.push(K)}else if(!L(me)||typeof me.type!=="string"||er.has(me.type))return}let V=await q({value:{...m,content:A},schema:Ct});return V.success?V.value:void 0}function pr(m,N){let A=[],V={},me={},Ne=m.content.some((K)=>K.type==="web_search_tool_result"&&Array.isArray(K.content)&&K.content.length>0);for(let K of m.content)switch(K.type){case"text":let ie=K.citations;A.push({type:"text",text:K.text,...ie!=null&&ie.length>0&&{citations:ie.map((se)=>Bt(se,[]))},...ie!=null&&ie.length>0&&{providerMetadata:{anthropic:{citations:ie}}}});for(let se of K.citations??[])if(se.type==="web_search_result_location"&&!Ne){let fe=Nt(se,[],N);if(fe)A.push(fe)}break;case"thinking":A.push({type:"reasoning",text:K.thinking,providerMetadata:{anthropic:{signature:K.signature}}});break;case"redacted_thinking":A.push({type:"reasoning",text:"",providerMetadata:{anthropic:{redactedData:K.data}}});break;case"container_upload":A.push({type:"custom",kind:"anthropic.container_upload",providerMetadata:{anthropic:{fileId:K.file_id}}});break;case"compaction":if(!K.content)break;A.push({type:"text",text:K.content,providerMetadata:{anthropic:{type:"compaction",...K.signature!=null&&{signature:K.signature}}}});break;case"tool_use":A.push({type:"tool-call",toolCallId:K.id,toolName:K.name,input:JSON.stringify(K.input),...Tt(K.caller)});break;case"server_tool_use":{let se=K.name==="bash_code_execution"||K.name==="text_editor_code_execution",fe=se||K.name==="code_execution",Ue=se?"code_execution":K.name;if(K.name==="tool_search_tool_bm25"||K.name==="tool_search_tool_regex")me[K.id]=K.name;A.push({type:"tool-call",toolCallId:K.id,toolName:Ue,input:JSON.stringify(se?{type:K.name,...K.input}:K.name==="code_execution"&&K.input!=null&&("code"in K.input)&&!("type"in K.input)?{type:"programmatic-tool-call",...K.input}:K.input),providerExecuted:!0,...fe?{dynamic:!0}:{},...Tt(K.caller)});break}case"mcp_tool_use":{let se={type:"tool-call",toolCallId:K.id,toolName:K.name,input:JSON.stringify(K.input),providerExecuted:!0,dynamic:!0,providerMetadata:{anthropic:{serverName:K.server_name,type:"mcp-tool-use"}}};V[K.id]=se,A.push(se);break}case"mcp_tool_result":{let se=V[K.tool_use_id];A.push({type:"tool-result",toolCallId:K.tool_use_id,toolName:se?.toolName??"mcp",isError:K.is_error,result:K.content,dynamic:!0,...se?.providerMetadata!=null&&{providerMetadata:se.providerMetadata}});break}case"web_fetch_tool_result":A.push({type:"tool-result",toolCallId:K.tool_use_id,toolName:"web_fetch",...K.content.type==="web_fetch_tool_result_error"?{isError:!0,result:{errorCode:K.content.error_code,type:K.content.type}}:{result:{content:{citations:K.content.content.citations,source:{data:K.content.content.source.data,mediaType:K.content.content.source.media_type,type:K.content.content.source.type},title:K.content.content.title,type:K.content.content.type},retrievedAt:K.content.retrieved_at,type:K.content.type,url:K.content.url}},...Tt(K.caller)});break;case"web_search_tool_result":if(A.push({type:"tool-result",toolCallId:K.tool_use_id,toolName:"web_search",...Array.isArray(K.content)?{result:K.content.map((se)=>({encryptedContent:se.encrypted_content,pageAge:se.page_age??null,...se.title!=null?{title:se.title}:{},type:se.type,url:se.url}))}:{isError:!0,result:{errorCode:K.content.error_code,type:K.content.type}},...Tt(K.caller)}),Array.isArray(K.content))for(let se of K.content)A.push({type:"source",sourceType:"url",id:N(),url:se.url,...se.title!=null?{title:se.title}:{},providerMetadata:{anthropic:{pageAge:se.page_age??null}}});break;case"code_execution_tool_result":A.push({type:"tool-result",toolCallId:K.tool_use_id,toolName:"code_execution",...K.content.type==="code_execution_tool_result_error"?{isError:!0,result:{errorCode:K.content.error_code,type:K.content.type}}:{result:K.content}});break;case"bash_code_execution_tool_result":case"text_editor_code_execution_tool_result":A.push({type:"tool-result",toolCallId:K.tool_use_id,toolName:"code_execution",result:K.content});break;case"tool_search_tool_result":{let se=me[K.tool_use_id]??"tool_search_tool_regex";A.push({type:"tool-result",toolCallId:K.tool_use_id,toolName:se,...K.content.type==="tool_search_tool_result_error"?{isError:!0,result:{errorCode:K.content.error_code,type:K.content.type}}:{result:K.content.tool_references.map((fe)=>({toolName:fe.tool_name,type:fe.type}))}});break}case"advisor_tool_result":if(K.content.type==="advisor_result")A.push({type:"tool-result",toolCallId:K.tool_use_id,toolName:"advisor",result:{type:K.content.type,text:K.content.text,...K.content.stop_reason!=null?{stopReason:K.content.stop_reason}:{}}});else if(K.content.type==="advisor_redacted_result")A.push({type:"tool-result",toolCallId:K.tool_use_id,toolName:"advisor",result:{type:K.content.type,encryptedContent:K.content.encrypted_content,...K.content.stop_reason!=null?{stopReason:K.content.stop_reason}:{}}});else A.push({type:"tool-result",toolCallId:K.tool_use_id,toolName:"advisor",isError:!0,result:{errorCode:K.content.error_code,type:K.content.type}});break;case"fallback":A.push({type:"custom",kind:"anthropic.fallback",providerMetadata:{anthropic:{type:"fallback",from:K.from,to:K.to}}})}return{content:A,finishReason:{unified:St({finishReason:m.stop_reason}),raw:m.stop_reason??void 0},usage:Mt({usage:m.usage}),response:{id:m.id??void 0,modelId:m.model??void 0},warnings:[],providerMetadata:{anthropic:dr(m)}}}function Tt(m){return m==null?{}:{providerMetadata:{anthropic:{caller:{type:m.type,toolId:m.tool_id}}}}}function dr(m){let N=hr(m.stop_details);return{usage:m.usage,stopSequence:m.stop_sequence??null,...N!=null?{stopDetails:N}:{},...m.input_transformations!=null?{inputTransformations:m.input_transformations}:{},...m.safeguard_results!=null?{safeguardResults:m.safeguard_results}:{},iterations:m.usage.iterations?m.usage.iterations.map((A)=>({type:A.type,...A.model!=null?{model:A.model}:{},inputTokens:A.input_tokens,outputTokens:A.output_tokens,...A.cache_creation_input_tokens?{cacheCreationInputTokens:A.cache_creation_input_tokens}:{},...A.cache_read_input_tokens?{cacheReadInputTokens:A.cache_read_input_tokens}:{}})):null,container:m.container?{expiresAt:m.container.expires_at,id:m.container.id,skills:m.container.skills?.map((A)=>({type:A.type,skillId:A.skill_id,version:A.version}))??null}:null,contextManagement:_r(m.context_management)}}function _r(m){return m?{appliedEdits:m.applied_edits.map((N)=>{switch(N.type){case"clear_tool_uses_20250919":return{type:N.type,clearedToolUses:N.cleared_tool_uses,clearedInputTokens:N.cleared_input_tokens};case"clear_thinking_20251015":return{type:N.type,clearedThinkingTurns:N.cleared_thinking_turns,clearedInputTokens:N.cleared_input_tokens};case"compact_20260112":return{type:N.type}}})}:null}function hr(m){if(m==null)return;return{type:m.type,...m.category!=null?{category:m.category}:{},...m.explanation!=null?{explanation:m.explanation}:{},...m.recommended_model!=null?{recommendedModel:m.recommended_model}:{}}}var mr=a(()=>s(t({command:e(),restart:c().optional()}))),no=re({id:"anthropic.bash_20241022",inputSchema:mr});function gr(m={}){let{execute:N,...A}=m;if(N===void 0)return no({...A,execute:async({command:V},{abortSignal:me,experimental_sandbox:Ne})=>{if(!Ne)throw Error("Sandbox session is not available");return await Ne.run({command:V,abortSignal:me})}});return no({...A,...N===null?{}:{execute:N}})}var fr=a(()=>s(t({command:e(),restart:c().optional()}))),ro=re({id:"anthropic.bash_20250124",inputSchema:fr});function yr(m={}){let{execute:N,...A}=m;if(N===void 0)return ro({...A,execute:async({command:V},{abortSignal:me,experimental_sandbox:Ne})=>{if(!Ne)throw Error("Sandbox session is not available");return await Ne.run({command:V,abortSignal:me})}});return ro({...A,...N===null?{}:{execute:N}})}var br=a(()=>s(t({action:i(["key","type","mouse_move","left_click","left_click_drag","right_click","middle_click","double_click","screenshot","cursor_position"]),coordinate:o(r().int()).optional(),text:e().optional()}))),xr=re({id:"anthropic.computer_20241022",inputSchema:br}),vr=a(()=>s(t({action:i(["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:ce([r().int(),r().int()]).optional(),duration:r().optional(),scroll_amount:r().optional(),scroll_direction:i(["up","down","left","right"]).optional(),start_coordinate:ce([r().int(),r().int()]).optional(),text:e().optional()}))),kr=re({id:"anthropic.computer_20250124",inputSchema:vr}),wr=a(()=>s(t({action:i(["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:ce([r().int(),r().int()]).optional(),duration:r().optional(),region:ce([r().int(),r().int(),r().int(),r().int()]).optional(),scroll_amount:r().optional(),scroll_direction:i(["up","down","left","right"]).optional(),start_coordinate:ce([r().int(),r().int()]).optional(),text:e().optional()}))),jr=re({id:"anthropic.computer_20251124",inputSchema:wr}),Tr=a(()=>s(f("command",[t({command:n("view"),path:e(),view_range:ce([r(),r()]).optional()}),t({command:n("create"),path:e(),file_text:e()}),t({command:n("str_replace"),path:e(),old_str:e(),new_str:e()}),t({command:n("insert"),path:e(),insert_line:r(),insert_text:e()}),t({command:n("delete"),path:e()}),t({command:n("rename"),old_path:e(),new_path:e()})]))),Cr=re({id:"anthropic.memory_20250818",inputSchema:Tr}),Sr=a(()=>s(t({command:i(["view","create","str_replace","insert","undo_edit"]),path:e(),file_text:e().optional(),insert_line:r().int().optional(),new_str:e().optional(),insert_text:e().optional(),old_str:e().optional(),view_range:o(r().int()).optional()}))),Nr=re({id:"anthropic.text_editor_20241022",inputSchema:Sr}),Or=a(()=>s(t({command:i(["view","create","str_replace","insert","undo_edit"]),path:e(),file_text:e().optional(),insert_line:r().int().optional(),new_str:e().optional(),insert_text:e().optional(),old_str:e().optional(),view_range:o(r().int()).optional()}))),Ir=re({id:"anthropic.text_editor_20250124",inputSchema:Or}),Ar=a(()=>s(t({command:i(["view","create","str_replace","insert"]),path:e(),file_text:e().optional(),insert_line:r().int().optional(),new_str:e().optional(),insert_text:e().optional(),old_str:e().optional(),view_range:o(r().int()).optional()}))),Rr=re({id:"anthropic.text_editor_20250429",inputSchema:Ar}),Br=a(()=>s(o(t({type:n("tool_reference"),toolName:e()})))),Er=a(()=>s(t({query:e(),limit:r().optional()}))),Mr=S({id:"anthropic.tool_search_bm25_20251119",inputSchema:Er,outputSchema:Br,supportsDeferredResults:!0}),Ur=(m={})=>Mr(m),$r={advisor_20260301:Po,bash_20241022:gr,bash_20250124:yr,codeExecution_20250522:Nn,codeExecution_20250825:An,codeExecution_20260120:En,computer_20241022:xr,computer_20250124:kr,computer_20251124:jr,computerToolset_20260801:Jo,memory_20250818:Cr,textEditor_20241022:Nr,textEditor_20250124:Ir,textEditor_20250429:Rr,textEditor_20250728:Vo,webFetch_20250910:jn,webFetch_20260209:bn,webFetch_20260318:hn,webSearch_20250305:cn,webSearch_20260209:rn,webSearch_20260318:Qo,toolSearchRegex_20251119:$n,toolSearchBm25_20251119:Ur},qr=a(()=>s(t({id:e(),display_title:e().nullish(),name:e().nullish(),description:e().nullish(),latest_version:e().nullish(),source:e(),created_at:e(),updated_at:e()})));a(()=>s(t({data:o(t({version:e()}))})));var Dr=a(()=>s(t({type:e(),skill_id:e(),name:e().nullish(),description:e().nullish()}))),Hr=class{get provider(){return this.config.provider}constructor(m){this.config=m,this.specificationVersion="v4"}async getHeaders(){return d(await _(this.config.headers),{"anthropic-beta":"skills-2025-10-02"})}async fetchVersionMetadata({skillId:m,version:N}){let{value:A}=await R({url:`${this.config.baseURL}/skills/${de(m)}/versions/${de(N)}`,validateUrl:!1,headers:await this.getHeaders(),failedResponseHandler:st,successfulResponseHandler:p(Dr),fetch:this.config.fetch});return{...A.name!=null?{name:A.name}:{},...A.description!=null?{description:A.description}:{}}}async uploadSkill(m){let N=[],A=new FormData;if(m.displayTitle!=null)A.append("display_title",m.displayTitle);for(let ie of m.files){let se=we(ie.data);A.append("files[]",new Blob([se]),ie.path)}let{value:V}=await ne({url:`${this.config.baseURL}/skills`,headers:await this.getHeaders(),formData:A,failedResponseHandler:st,successfulResponseHandler:p(qr),fetch:this.config.fetch}),me=V.latest_version!=null?await this.fetchVersionMetadata({skillId:V.id,version:V.latest_version}):{},Ne=me.name??V.name,K=me.description??V.description;return{providerReference:{anthropic:V.id},...V.display_title!=null?{displayTitle:V.display_title}:{},...Ne!=null?{name:Ne}:{},...K!=null?{description:K}:{},...V.latest_version!=null?{latestVersion:V.latest_version}:{},providerMetadata:{anthropic:{...V.source!=null?{source:V.source}:{},...V.created_at!=null?{createdAt:V.created_at}:{},...V.updated_at!=null?{updatedAt:V.updated_at}:{}}},warnings:N}}},Pr="4.0.90",ko="https://api.anthropic.com",wo=`${ko}/v1`;function Lr(m){let N=Y(ht(m));return N===ko?wo:N}function qt(m={}){let N=Lr(pe({settingValue:m.baseURL,environmentVariableName:"ANTHROPIC_BASE_URL"}))??wo,A=m.name??"anthropic.messages",V={"image/*":[/^https?:\/\/.*$/],"application/pdf":[/^https?:\/\/.*$/]};if(m.apiKey&&m.authToken)throw new b({argument:"apiKey/authToken",message:"Both apiKey and authToken were provided. Please use only one authentication method."});let me=async()=>{let Ue=m.authToken?{Authorization:`Bearer ${await _(m.authToken)}`}:{"x-api-key":he({apiKey:m.apiKey,environmentVariableName:"ANTHROPIC_API_KEY",description:"Anthropic"})};return F({"anthropic-version":"2023-06-01",...Ue,...m.headers},`ai-sdk-anthropic/${Pr}`)},Ne={provider:A,baseURL:N,headers:me,fetch:m.fetch,generateId:m.generateId??C,supportedUrls:()=>V},K=(Ue)=>new xo(Ue,Ne),ie=()=>new rr({provider:`${A.replace(/\.messages$/,"")}.batch`,maxLineBytes:m.batchResultDownloads?.maxLineBytes,config:Ne,supportedUrls:V}),se=()=>new Hr({provider:`${A.replace(".messages","")}.skills`,baseURL:N,headers:me,fetch:m.fetch}),fe=function(Ue){if(new.target)throw Error("The Anthropic model function cannot be called with the new keyword.");return K(Ue)};return fe.specificationVersion="v4",fe.languageModel=K,fe.chat=K,fe.messages=K,fe.decisionModel=(Ue)=>new rt({model:K(Ue),provider:`${A.replace(/\.messages$/,"")}.decision`}),fe.evaluationModel=fe.decisionModel,fe.experimental_batch=ie,fe.embeddingModel=(Ue)=>{throw new He({modelId:Ue,modelType:"embeddingModel"})},fe.textEmbeddingModel=fe.embeddingModel,fe.imageModel=(Ue)=>{throw new He({modelId:Ue,modelType:"imageModel"})},fe.files=()=>new Ro({provider:A,baseURL:N,headers:me,fetch:m.fetch}),fe.skills=se,fe.tools=$r,fe}var Xr=qt();var Fr=(m)=>qt({apiKey:m.apiKey,...m.baseURL&&{baseURL:yt(m.baseURL)},headers:{...m.headers,...Ve(m.baseURL??Dt.anthropic)&&{[bt]:"true"}},...m.fetch&&{fetch:m.fetch}})(m.model);function aa(){oe("anthropic",Fr)}export{aa as register};
|