stacks-ai 0.2.5 → 0.2.7

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 CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  AI-powered infinite canvas workspace for notes, images, and creative organization.
4
4
 
5
+ Free to use for personal use, one-time license of $49 for unrestricted usage - bit.ly/4aNe23d
6
+
7
+ Please consider a license
8
+
5
9
  ## Features
6
10
 
7
11
  - Infinite canvas with zoom and pan
package/bin/stacks.cjs CHANGED
@@ -258,6 +258,40 @@ function stopRunningInstance() {
258
258
  return false
259
259
  }
260
260
 
261
+ // Proxy process management
262
+ let proxyProcess = null
263
+
264
+ function startProxy() {
265
+ try {
266
+ const proxyPath = path.join(APP_DIR, 'dist', 'mcp', 'proxy.js')
267
+ if (!fs.existsSync(proxyPath)) {
268
+ console.error('⚠️ MCP proxy not found. Run `npm run build` first.')
269
+ return
270
+ }
271
+
272
+ const nodeCmd = getNodeCommand()
273
+ proxyProcess = spawn(nodeCmd, [proxyPath], {
274
+ stdio: 'ignore',
275
+ detached: false
276
+ })
277
+
278
+ proxyProcess.on('error', (err) => {
279
+ console.error('MCP proxy error:', err.message)
280
+ })
281
+ } catch (err) {
282
+ console.error('Failed to start proxy:', err.message)
283
+ }
284
+ }
285
+
286
+ function stopProxy() {
287
+ if (proxyProcess) {
288
+ try {
289
+ proxyProcess.kill('SIGTERM')
290
+ proxyProcess = null
291
+ } catch {}
292
+ }
293
+ }
294
+
261
295
  async function launch() {
262
296
  try {
263
297
  console.log(`\n🚀 Starting Stacks...\n`)
@@ -1 +1 @@
1
- import{s as n}from"./index-CHhe65ps.js";import{c as s,o as g,a as y}from"./index-D0ZoqtYh.js";const a={},I=r=>{const e={anthropic:"anthropic-api-key",openai:"openai-api-key",google:"gemini-api-key"}[r],t=localStorage.getItem(e);return t||{anthropic:a==null?void 0:a.VITE_ANTHROPIC_API_KEY,openai:a==null?void 0:a.VITE_OPENAI_API_KEY,google:a==null?void 0:a.VITE_GEMINI_API_KEY}[r]||""},p=r=>{const o=r.apiKey||I(r.provider);if(!o)throw new Error(`${r.provider} API key not configured. Please add your API key in Settings → Providers.`);const e=localStorage.getItem("text-model");switch(r.provider){case"anthropic":return y(r.model||e||"claude-sonnet-4-5-20250929",{apiKey:o});case"openai":return g(r.model||e||"gpt-4o",{apiKey:o});case"google":return s({apiKey:o})(r.model||e||"gemini-2.0-flash-exp");default:throw new Error(`Unknown provider: ${r.provider}`)}},P=async(r,o,e)=>{const t=(e==null?void 0:e.provider)||"google",c=p({provider:t,model:e==null?void 0:e.model}),d=await n({model:c,system:e==null?void 0:e.systemPrompt,prompt:r});for await(const l of d.textStream)o(l)};export{P as generateTextStream,p as getLanguageModel};
1
+ import{s as n}from"./index-BuyyCfeJ.js";import{c as s,o as g,a as y}from"./index-B7ilsstg.js";const a={},I=r=>{const e={anthropic:"anthropic-api-key",openai:"openai-api-key",google:"gemini-api-key"}[r],t=localStorage.getItem(e);return t||{anthropic:a==null?void 0:a.VITE_ANTHROPIC_API_KEY,openai:a==null?void 0:a.VITE_OPENAI_API_KEY,google:a==null?void 0:a.VITE_GEMINI_API_KEY}[r]||""},p=r=>{const o=r.apiKey||I(r.provider);if(!o)throw new Error(`${r.provider} API key not configured. Please add your API key in Settings → Providers.`);const e=localStorage.getItem("text-model");switch(r.provider){case"anthropic":return y(r.model||e||"claude-sonnet-4-5-20250929",{apiKey:o});case"openai":return g(r.model||e||"gpt-4o",{apiKey:o});case"google":return s({apiKey:o})(r.model||e||"gemini-2.0-flash-exp");default:throw new Error(`Unknown provider: ${r.provider}`)}},P=async(r,o,e)=>{const t=(e==null?void 0:e.provider)||"google",c=p({provider:t,model:e==null?void 0:e.model}),d=await n({model:c,system:e==null?void 0:e.systemPrompt,prompt:r});for await(const l of d.textStream)o(l)};export{P as generateTextStream,p as getLanguageModel};
@@ -1,4 +1,4 @@
1
- import{_ as eo,Z as to,w as Le,l as Nt,a as pe,b as He,p as me,c as Rt,d as ge,r as Se,e as fe,A as Ot,f as je,o as t,h as be,i as Oe,v as ce,j as P,k as Mt,m as Ie,U as _e,n as Y,q as ne,t as x,u as ae,x as n,y as e,z as a,B as Q,C as Ge,D,N as et,E as ve,F as Pe,G as we,H as ue,I as ye,J as De,K as Me,L as Et,M as oo,O as qe,P as tt,T as qt,Q as At,R as no,S as $t,V as Ve,W as ao,X as io,Y as lo}from"./index-CHhe65ps.js";function so(o){return eo(to,o)}var ro="3.0.8",uo=P(()=>D(t({type:n("error"),error:t({type:e(),message:e()})}))),ot=Ge({errorSchema:uo,errorToMessage:o=>o.error.message}),po=P(()=>D(t({type:n("message"),id:e().nullish(),model:e().nullish(),content:x(ae("type",[t({type:n("text"),text:e(),citations:x(ae("type",[t({type:n("web_search_result_location"),cited_text:e(),url:e(),title:e(),encrypted_index:e()}),t({type:n("page_location"),cited_text:e(),document_index:a(),document_title:e().nullable(),start_page_number:a(),end_page_number:a()}),t({type:n("char_location"),cited_text:e(),document_index:a(),document_title:e().nullable(),start_char_index:a(),end_char_index:a()})])).optional()}),t({type:n("thinking"),thinking:e(),signature:e()}),t({type:n("redacted_thinking"),data:e()}),t({type:n("tool_use"),id:e(),name:e(),input:we(),caller:Q([t({type:n("code_execution_20250825"),tool_id:e()}),t({type:n("direct")})]).optional()}),t({type:n("server_tool_use"),id:e(),name:e(),input:ue(e(),we()).nullish()}),t({type:n("mcp_tool_use"),id:e(),name:e(),input:we(),server_name:e()}),t({type:n("mcp_tool_result"),tool_use_id:e(),is_error:ne(),content:x(Q([e(),t({type:n("text"),text:e()})]))}),t({type:n("web_fetch_tool_result"),tool_use_id:e(),content:Q([t({type:n("web_fetch_result"),url:e(),retrieved_at:e(),content:t({type:n("document"),title:e().nullable(),citations:t({enabled:ne()}).optional(),source:Q([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(),content:Q([x(t({type:n("web_search_result"),url:e(),title:e(),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:Q([t({type:n("code_execution_result"),stdout:e(),stderr:e(),return_code:a(),content:x(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:ae("type",[t({type:n("bash_code_execution_result"),content:x(t({type:n("bash_code_execution_output"),file_id:e()})),stdout:e(),stderr:e(),return_code:a()}),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:ae("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:a().nullable(),start_line:a().nullable(),total_lines:a().nullable()}),t({type:n("text_editor_code_execution_create_result"),is_file_update:ne()}),t({type:n("text_editor_code_execution_str_replace_result"),lines:x(e()).nullable(),new_lines:a().nullable(),new_start:a().nullable(),old_lines:a().nullable(),old_start:a().nullable()})])}),t({type:n("tool_search_tool_result"),tool_use_id:e(),content:Q([t({type:n("tool_search_tool_search_result"),tool_references:x(t({type:n("tool_reference"),tool_name:e()}))}),t({type:n("tool_search_tool_result_error"),error_code:e()})])})])),stop_reason:e().nullish(),stop_sequence:e().nullish(),usage:Pe({input_tokens:a(),output_tokens:a(),cache_creation_input_tokens:a().nullish(),cache_read_input_tokens:a().nullish()}),container:t({expires_at:e(),id:e(),skills:x(t({type:Q([n("anthropic"),n("custom")]),skill_id:e(),version:e()})).nullish()}).nullish(),context_management:t({applied_edits:x(Q([t({type:n("clear_tool_uses_20250919"),cleared_tool_uses:a(),cleared_input_tokens:a()}),t({type:n("clear_thinking_20251015"),cleared_thinking_turns:a(),cleared_input_tokens:a()})]))}).nullish()}))),co=P(()=>D(ae("type",[t({type:n("message_start"),message:t({id:e().nullish(),model:e().nullish(),role:e().nullish(),usage:Pe({input_tokens:a(),cache_creation_input_tokens:a().nullish(),cache_read_input_tokens:a().nullish()}),content:x(ae("type",[t({type:n("tool_use"),id:e(),name:e(),input:we(),caller:Q([t({type:n("code_execution_20250825"),tool_id:e()}),t({type:n("direct")})]).optional()})])).nullish(),stop_reason:e().nullish(),container:t({expires_at:e(),id:e()}).nullish()})}),t({type:n("content_block_start"),index:a(),content_block:ae("type",[t({type:n("text"),text:e()}),t({type:n("thinking"),thinking:e()}),t({type:n("tool_use"),id:e(),name:e(),input:ue(e(),we()).optional(),caller:Q([t({type:n("code_execution_20250825"),tool_id:e()}),t({type:n("direct")})]).optional()}),t({type:n("redacted_thinking"),data:e()}),t({type:n("server_tool_use"),id:e(),name:e(),input:ue(e(),we()).nullish()}),t({type:n("mcp_tool_use"),id:e(),name:e(),input:we(),server_name:e()}),t({type:n("mcp_tool_result"),tool_use_id:e(),is_error:ne(),content:x(Q([e(),t({type:n("text"),text:e()})]))}),t({type:n("web_fetch_tool_result"),tool_use_id:e(),content:Q([t({type:n("web_fetch_result"),url:e(),retrieved_at:e(),content:t({type:n("document"),title:e().nullable(),citations:t({enabled:ne()}).optional(),source:Q([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(),content:Q([x(t({type:n("web_search_result"),url:e(),title:e(),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:Q([t({type:n("code_execution_result"),stdout:e(),stderr:e(),return_code:a(),content:x(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:ae("type",[t({type:n("bash_code_execution_result"),content:x(t({type:n("bash_code_execution_output"),file_id:e()})),stdout:e(),stderr:e(),return_code:a()}),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:ae("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:a().nullable(),start_line:a().nullable(),total_lines:a().nullable()}),t({type:n("text_editor_code_execution_create_result"),is_file_update:ne()}),t({type:n("text_editor_code_execution_str_replace_result"),lines:x(e()).nullable(),new_lines:a().nullable(),new_start:a().nullable(),old_lines:a().nullable(),old_start:a().nullable()})])}),t({type:n("tool_search_tool_result"),tool_use_id:e(),content:Q([t({type:n("tool_search_tool_search_result"),tool_references:x(t({type:n("tool_reference"),tool_name:e()}))}),t({type:n("tool_search_tool_result_error"),error_code:e()})])})])}),t({type:n("content_block_delta"),index:a(),delta:ae("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("citations_delta"),citation:ae("type",[t({type:n("web_search_result_location"),cited_text:e(),url:e(),title:e(),encrypted_index:e()}),t({type:n("page_location"),cited_text:e(),document_index:a(),document_title:e().nullable(),start_page_number:a(),end_page_number:a()}),t({type:n("char_location"),cited_text:e(),document_index:a(),document_title:e().nullable(),start_char_index:a(),end_char_index:a()})])})])}),t({type:n("content_block_stop"),index:a()}),t({type:n("error"),error:t({type:e(),message:e()})}),t({type:n("message_delta"),delta:t({stop_reason:e().nullish(),stop_sequence:e().nullish(),container:t({expires_at:e(),id:e(),skills:x(t({type:Q([n("anthropic"),n("custom")]),skill_id:e(),version:e()})).nullish()}).nullish(),context_management:t({applied_edits:x(Q([t({type:n("clear_tool_uses_20250919"),cleared_tool_uses:a(),cleared_input_tokens:a()}),t({type:n("clear_thinking_20251015"),cleared_thinking_turns:a(),cleared_input_tokens:a()})]))}).nullish()}),usage:Pe({output_tokens:a(),cache_creation_input_tokens:a().nullish()})}),t({type:n("message_stop")}),t({type:n("ping")})]))),_o=P(()=>D(t({signature:e().optional(),redactedData:e().optional()}))),nt=t({citations:t({enabled:ne()}).optional(),title:e().optional(),context:e().optional()}),mo=t({sendReasoning:ne().optional(),structuredOutputMode:Y(["outputFormat","jsonTool","auto"]).optional(),thinking:t({type:Q([n("enabled"),n("disabled")]),budgetTokens:a().optional()}).optional(),disableParallelToolUse:ne().optional(),cacheControl:t({type:n("ephemeral"),ttl:Q([n("5m"),n("1h")]).optional()}).optional(),mcpServers:x(t({type:n("url"),name:e(),url:e(),authorizationToken:e().nullish(),toolConfiguration:t({enabled:ne().nullish(),allowedTools:x(e()).nullish()}).nullish()})).optional(),container:t({id:e().optional(),skills:x(t({type:Q([n("anthropic"),n("custom")]),skillId:e(),version:e().optional()})).optional()}).optional(),toolStreaming:ne().optional(),effort:Y(["low","medium","high"]).optional(),contextManagement:t({edits:x(ae("type",[t({type:n("clear_tool_uses_20250919"),trigger:ae("type",[t({type:n("input_tokens"),value:a()}),t({type:n("tool_uses"),value:a()})]).optional(),keep:t({type:n("tool_uses"),value:a()}).optional(),clearAtLeast:t({type:n("input_tokens"),value:a()}).optional(),clearToolInputs:ne().optional(),excludeTools:x(e()).optional()}),t({type:n("clear_thinking_20251015"),keep:Q([n("all"),t({type:n("thinking_turns"),value:a()})]).optional()})]))}).optional()}),at=4;function ho(o){var l;const s=o==null?void 0:o.anthropic;return(l=s==null?void 0:s.cacheControl)!=null?l:s==null?void 0:s.cache_control}var Be=class{constructor(){this.breakpointCount=0,this.warnings=[]}getCacheControl(o,l){const s=ho(o);if(s){if(!l.canCache){this.warnings.push({type:"unsupported",feature:"cache_control on non-cacheable context",details:`cache_control cannot be set on ${l.type}. It will be ignored.`});return}if(this.breakpointCount++,this.breakpointCount>at){this.warnings.push({type:"unsupported",feature:"cacheControl breakpoint limit",details:`Maximum ${at} cache breakpoints exceeded (found ${this.breakpointCount}). This breakpoint will be ignored.`});return}return s}}getWarnings(){return this.warnings}},go=P(()=>D(t({maxCharacters:a().optional()}))),fo=P(()=>D(t({command:Y(["view","create","str_replace","insert"]),path:e(),file_text:e().optional(),insert_line:a().int().optional(),new_str:e().optional(),old_str:e().optional(),view_range:x(a().int()).optional()}))),yo=ve({id:"anthropic.text_editor_20250728",inputSchema:fo}),vo=(o={})=>yo(o),bo=P(()=>D(t({maxUses:a().optional(),allowedDomains:x(e()).optional(),blockedDomains:x(e()).optional(),userLocation:t({type:n("approximate"),city:e().optional(),region:e().optional(),country:e().optional(),timezone:e().optional()}).optional()}))),Pt=P(()=>D(x(t({url:e(),title:e().nullable(),pageAge:e().nullable(),encryptedContent:e(),type:n("web_search_result")})))),xo=P(()=>D(t({query:e()}))),wo=ye({id:"anthropic.web_search_20250305",inputSchema:xo,outputSchema:Pt,supportsDeferredResults:!0}),ko=(o={})=>wo(o),Co=P(()=>D(t({maxUses:a().optional(),allowedDomains:x(e()).optional(),blockedDomains:x(e()).optional(),citations:t({enabled:ne()}).optional(),maxContentTokens:a().optional()}))),Dt=P(()=>D(t({type:n("web_fetch_result"),url:e(),content:t({type:n("document"),title:e().nullable(),citations:t({enabled:ne()}).optional(),source:Q([t({type:n("base64"),mediaType:n("application/pdf"),data:e()}),t({type:n("text"),mediaType:n("text/plain"),data:e()})])}),retrievedAt:e().nullable()}))),Io=P(()=>D(t({url:e()}))),To=ye({id:"anthropic.web_fetch_20250910",inputSchema:Io,outputSchema:Dt,supportsDeferredResults:!0}),So=(o={})=>To(o);async function No({tools:o,toolChoice:l,disableParallelToolUse:s,cacheControlValidator:p,supportsStructuredOutput:c}){var m;o=o!=null&&o.length?o:void 0;const u=[],d=new Set,b=p||new Be;if(o==null)return{tools:void 0,toolChoice:void 0,toolWarnings:u,betas:d};const _=[];for(const w of o)switch(w.type){case"function":{const y=b.getCacheControl(w.providerOptions,{type:"tool definition",canCache:!0}),g=(m=w.providerOptions)==null?void 0:m.anthropic,k=g==null?void 0:g.deferLoading,C=g==null?void 0:g.allowedCallers;_.push({name:w.name,description:w.description,input_schema:w.inputSchema,cache_control:y,...c===!0&&w.strict!=null?{strict:w.strict}:{},...k!=null?{defer_loading:k}:{},...C!=null?{allowed_callers:C}:{},...w.inputExamples!=null?{input_examples:w.inputExamples.map(f=>f.input)}:{}}),c===!0&&d.add("structured-outputs-2025-11-13"),(w.inputExamples!=null||C!=null)&&d.add("advanced-tool-use-2025-11-20");break}case"provider":{switch(w.id){case"anthropic.code_execution_20250522":{d.add("code-execution-2025-05-22"),_.push({type:"code_execution_20250522",name:"code_execution",cache_control:void 0});break}case"anthropic.code_execution_20250825":{d.add("code-execution-2025-08-25"),_.push({type:"code_execution_20250825",name:"code_execution"});break}case"anthropic.computer_20250124":{d.add("computer-use-2025-01-24"),_.push({name:"computer",type:"computer_20250124",display_width_px:w.args.displayWidthPx,display_height_px:w.args.displayHeightPx,display_number:w.args.displayNumber,cache_control:void 0});break}case"anthropic.computer_20241022":{d.add("computer-use-2024-10-22"),_.push({name:"computer",type:"computer_20241022",display_width_px:w.args.displayWidthPx,display_height_px:w.args.displayHeightPx,display_number:w.args.displayNumber,cache_control:void 0});break}case"anthropic.text_editor_20250124":{d.add("computer-use-2025-01-24"),_.push({name:"str_replace_editor",type:"text_editor_20250124",cache_control:void 0});break}case"anthropic.text_editor_20241022":{d.add("computer-use-2024-10-22"),_.push({name:"str_replace_editor",type:"text_editor_20241022",cache_control:void 0});break}case"anthropic.text_editor_20250429":{d.add("computer-use-2025-01-24"),_.push({name:"str_replace_based_edit_tool",type:"text_editor_20250429",cache_control:void 0});break}case"anthropic.text_editor_20250728":{const y=await ce({value:w.args,schema:go});_.push({name:"str_replace_based_edit_tool",type:"text_editor_20250728",max_characters:y.maxCharacters,cache_control:void 0});break}case"anthropic.bash_20250124":{d.add("computer-use-2025-01-24"),_.push({name:"bash",type:"bash_20250124",cache_control:void 0});break}case"anthropic.bash_20241022":{d.add("computer-use-2024-10-22"),_.push({name:"bash",type:"bash_20241022",cache_control:void 0});break}case"anthropic.memory_20250818":{d.add("context-management-2025-06-27"),_.push({name:"memory",type:"memory_20250818"});break}case"anthropic.web_fetch_20250910":{d.add("web-fetch-2025-09-10");const y=await ce({value:w.args,schema:Co});_.push({type:"web_fetch_20250910",name:"web_fetch",max_uses:y.maxUses,allowed_domains:y.allowedDomains,blocked_domains:y.blockedDomains,citations:y.citations,max_content_tokens:y.maxContentTokens,cache_control:void 0});break}case"anthropic.web_search_20250305":{const y=await ce({value:w.args,schema:bo});_.push({type:"web_search_20250305",name:"web_search",max_uses:y.maxUses,allowed_domains:y.allowedDomains,blocked_domains:y.blockedDomains,user_location:y.userLocation,cache_control:void 0});break}case"anthropic.tool_search_regex_20251119":{d.add("advanced-tool-use-2025-11-20"),_.push({type:"tool_search_tool_regex_20251119",name:"tool_search_tool_regex"});break}case"anthropic.tool_search_bm25_20251119":{d.add("advanced-tool-use-2025-11-20"),_.push({type:"tool_search_tool_bm25_20251119",name:"tool_search_tool_bm25"});break}default:{u.push({type:"unsupported",feature:`provider-defined tool ${w.id}`});break}}break}default:{u.push({type:"unsupported",feature:`tool ${w}`});break}}if(l==null)return{tools:_,toolChoice:s?{type:"auto",disable_parallel_tool_use:s}:void 0,toolWarnings:u,betas:d};const T=l.type;switch(T){case"auto":return{tools:_,toolChoice:{type:"auto",disable_parallel_tool_use:s},toolWarnings:u,betas:d};case"required":return{tools:_,toolChoice:{type:"any",disable_parallel_tool_use:s},toolWarnings:u,betas:d};case"none":return{tools:void 0,toolChoice:void 0,toolWarnings:u,betas:d};case"tool":return{tools:_,toolChoice:{type:"tool",name:l.toolName,disable_parallel_tool_use:s},toolWarnings:u,betas:d};default:{const w=T;throw new _e({functionality:`tool choice type: ${w}`})}}}function it(o){var l,s;const p=o.input_tokens,c=o.output_tokens,m=(l=o.cache_creation_input_tokens)!=null?l:0,u=(s=o.cache_read_input_tokens)!=null?s:0;return{inputTokens:{total:p+m+u,noCache:p,cacheRead:u,cacheWrite:m},outputTokens:{total:c,text:void 0,reasoning:void 0},raw:o}}var Ut=P(()=>D(t({type:n("code_execution_result"),stdout:e(),stderr:e(),return_code:a(),content:x(t({type:n("code_execution_output"),file_id:e()})).optional().default([])}))),Ro=P(()=>D(t({code:e()}))),Oo=ye({id:"anthropic.code_execution_20250522",inputSchema:Ro,outputSchema:Ut}),Mo=(o={})=>Oo(o),Lt=P(()=>D(ae("type",[t({type:n("code_execution_result"),stdout:e(),stderr:e(),return_code:a(),content:x(t({type:n("code_execution_output"),file_id:e()})).optional().default([])}),t({type:n("bash_code_execution_result"),content:x(t({type:n("bash_code_execution_output"),file_id:e()})),stdout:e(),stderr:e(),return_code:a()}),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:a().nullable(),start_line:a().nullable(),total_lines:a().nullable()}),t({type:n("text_editor_code_execution_create_result"),is_file_update:ne()}),t({type:n("text_editor_code_execution_str_replace_result"),lines:x(e()).nullable(),new_lines:a().nullable(),new_start:a().nullable(),old_lines:a().nullable(),old_start:a().nullable()})]))),Eo=P(()=>D(ae("type",[t({type:n("programmatic-tool-call"),code:e()}),t({type:n("bash_code_execution"),command:e()}),ae("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()})])]))),qo=ye({id:"anthropic.code_execution_20250825",inputSchema:Eo,outputSchema:Lt,supportsDeferredResults:!0}),Ao=(o={})=>qo(o),Ht=P(()=>D(x(t({type:n("tool_reference"),toolName:e()})))),$o=P(()=>D(t({pattern:e(),limit:a().optional()}))),Po=ye({id:"anthropic.tool_search_regex_20251119",inputSchema:$o,outputSchema:Ht}),Do=(o={})=>Po(o);function Uo(o){if(typeof o=="string")return Buffer.from(o,"base64").toString("utf-8");if(o instanceof Uint8Array)return new TextDecoder().decode(o);throw o instanceof URL?new _e({functionality:"URL-based text documents are not supported for citations"}):new _e({functionality:`unsupported data type for text documents: ${typeof o}`})}async function Lo({prompt:o,sendReasoning:l,warnings:s,cacheControlValidator:p,toolNameMapping:c}){var m,u,d,b,_,T,w,y,g,k,C,f,L,$,E;const X=new Set,q=Ho(o),i=p||new Be;let A;const ie=[];async function h(N){var S,G;const M=await me({provider:"anthropic",providerOptions:N,schema:nt});return(G=(S=M==null?void 0:M.citations)==null?void 0:S.enabled)!=null?G:!1}async function K(N){const S=await me({provider:"anthropic",providerOptions:N,schema:nt});return{title:S==null?void 0:S.title,context:S==null?void 0:S.context}}for(let N=0;N<q.length;N++){const S=q[N],G=N===q.length-1,M=S.type;switch(M){case"system":{if(A!=null)throw new _e({functionality:"Multiple system messages that are separated by user/assistant messages"});A=S.messages.map(({content:I,providerOptions:F})=>({type:"text",text:I,cache_control:i.getCacheControl(F,{type:"system message",canCache:!0})}));break}case"user":{const I=[];for(const F of S.messages){const{role:V,content:W}=F;switch(V){case"user":{for(let ee=0;ee<W.length;ee++){const H=W[ee],le=ee===W.length-1,R=(m=i.getCacheControl(H.providerOptions,{type:"user message part",canCache:!0}))!=null?m:le?i.getCacheControl(F.providerOptions,{type:"user message",canCache:!0}):void 0;switch(H.type){case"text":{I.push({type:"text",text:H.text,cache_control:R});break}case"file":{if(H.mediaType.startsWith("image/"))I.push({type:"image",source:H.data instanceof URL?{type:"url",url:H.data.toString()}:{type:"base64",media_type:H.mediaType==="image/*"?"image/jpeg":H.mediaType,data:Ie(H.data)},cache_control:R});else if(H.mediaType==="application/pdf"){X.add("pdfs-2024-09-25");const re=await h(H.providerOptions),z=await K(H.providerOptions);I.push({type:"document",source:H.data instanceof URL?{type:"url",url:H.data.toString()}:{type:"base64",media_type:"application/pdf",data:Ie(H.data)},title:(u=z.title)!=null?u:H.filename,...z.context&&{context:z.context},...re&&{citations:{enabled:!0}},cache_control:R})}else if(H.mediaType==="text/plain"){const re=await h(H.providerOptions),z=await K(H.providerOptions);I.push({type:"document",source:H.data instanceof URL?{type:"url",url:H.data.toString()}:{type:"text",media_type:"text/plain",data:Uo(H.data)},title:(d=z.title)!=null?d:H.filename,...z.context&&{context:z.context},...re&&{citations:{enabled:!0}},cache_control:R})}else throw new _e({functionality:`media type: ${H.mediaType}`});break}}}break}case"tool":{for(let ee=0;ee<W.length;ee++){const H=W[ee];if(H.type==="tool-approval-response")continue;const le=ee===W.length-1,R=(b=i.getCacheControl(H.providerOptions,{type:"tool result part",canCache:!0}))!=null?b:le?i.getCacheControl(F.providerOptions,{type:"tool result message",canCache:!0}):void 0,re=H.output;let z;switch(re.type){case"content":z=re.value.map(te=>{switch(te.type){case"text":return{type:"text",text:te.text};case"image-data":return{type:"image",source:{type:"base64",media_type:te.mediaType,data:te.data}};case"image-url":return{type:"image",source:{type:"url",url:te.url}};case"file-url":return{type:"document",source:{type:"url",url:te.url}};case"file-data":{if(te.mediaType==="application/pdf")return X.add("pdfs-2024-09-25"),{type:"document",source:{type:"base64",media_type:te.mediaType,data:te.data}};s.push({type:"other",message:`unsupported tool content part type: ${te.type} with media type: ${te.mediaType}`});return}default:{s.push({type:"other",message:`unsupported tool content part type: ${te.type}`});return}}}).filter(Mt);break;case"text":case"error-text":z=re.value;break;case"execution-denied":z=(_=re.reason)!=null?_:"Tool execution denied.";break;case"json":case"error-json":default:z=JSON.stringify(re.value);break}I.push({type:"tool_result",tool_use_id:H.toolCallId,content:z,is_error:re.type==="error-text"||re.type==="error-json"?!0:void 0,cache_control:R})}break}default:{const ee=V;throw new Error(`Unsupported role: ${ee}`)}}}ie.push({role:"user",content:I});break}case"assistant":{const I=[],F=new Set;for(let V=0;V<S.messages.length;V++){const W=S.messages[V],ee=V===S.messages.length-1,{content:H}=W;for(let le=0;le<H.length;le++){const R=H[le],re=le===H.length-1,z=(T=i.getCacheControl(R.providerOptions,{type:"assistant message part",canCache:!0}))!=null?T:re?i.getCacheControl(W.providerOptions,{type:"assistant message",canCache:!0}):void 0;switch(R.type){case"text":{I.push({type:"text",text:G&&ee&&re?R.text.trim():R.text,cache_control:z});break}case"reasoning":{if(l){const te=await me({provider:"anthropic",providerOptions:R.providerOptions,schema:_o});te!=null?te.signature!=null?(i.getCacheControl(R.providerOptions,{type:"thinking block",canCache:!1}),I.push({type:"thinking",thinking:R.text,signature:te.signature})):te.redactedData!=null?(i.getCacheControl(R.providerOptions,{type:"redacted thinking block",canCache:!1}),I.push({type:"redacted_thinking",data:te.redactedData})):s.push({type:"other",message:"unsupported reasoning metadata"}):s.push({type:"other",message:"unsupported reasoning metadata"})}else s.push({type:"other",message:"sending reasoning content is disabled for this model"});break}case"tool-call":{if(R.providerExecuted){const J=c.toProviderToolName(R.toolName);if(((y=(w=R.providerOptions)==null?void 0:w.anthropic)==null?void 0:y.type)==="mcp-tool-use"){F.add(R.toolCallId);const v=(k=(g=R.providerOptions)==null?void 0:g.anthropic)==null?void 0:k.serverName;if(v==null||typeof v!="string"){s.push({type:"other",message:"mcp tool use server name is required and must be a string"});break}I.push({type:"mcp_tool_use",id:R.toolCallId,name:R.toolName,input:R.input,server_name:v,cache_control:z})}else if(J==="code_execution"&&R.input!=null&&typeof R.input=="object"&&"type"in R.input&&typeof R.input.type=="string"&&(R.input.type==="bash_code_execution"||R.input.type==="text_editor_code_execution"))I.push({type:"server_tool_use",id:R.toolCallId,name:R.input.type,input:R.input,cache_control:z});else if(J==="code_execution"&&R.input!=null&&typeof R.input=="object"&&"type"in R.input&&R.input.type==="programmatic-tool-call"){const{type:v,...oe}=R.input;I.push({type:"server_tool_use",id:R.toolCallId,name:"code_execution",input:oe,cache_control:z})}else J==="code_execution"||J==="web_fetch"||J==="web_search"?I.push({type:"server_tool_use",id:R.toolCallId,name:J,input:R.input,cache_control:z}):J==="tool_search_tool_regex"||J==="tool_search_tool_bm25"?I.push({type:"server_tool_use",id:R.toolCallId,name:J,input:R.input,cache_control:z}):s.push({type:"other",message:`provider executed tool call for tool ${R.toolName} is not supported`});break}const te=(C=R.providerOptions)==null?void 0:C.anthropic,j=te!=null&&te.caller?te.caller.type==="code_execution_20250825"&&te.caller.toolId?{type:"code_execution_20250825",tool_id:te.caller.toolId}:te.caller.type==="direct"?{type:"direct"}:void 0:void 0;I.push({type:"tool_use",id:R.toolCallId,name:R.toolName,input:R.input,...j&&{caller:j},cache_control:z});break}case"tool-result":{const te=c.toProviderToolName(R.toolName);if(F.has(R.toolCallId)){const j=R.output;if(j.type!=="json"&&j.type!=="error-json"){s.push({type:"other",message:`provider executed tool result output type ${j.type} for tool ${R.toolName} is not supported`});break}I.push({type:"mcp_tool_result",tool_use_id:R.toolCallId,is_error:j.type==="error-json",content:j.value,cache_control:z})}else if(te==="code_execution"){const j=R.output;if(j.type==="error-text"||j.type==="error-json"){let J={};try{typeof j.value=="string"?J=JSON.parse(j.value):typeof j.value=="object"&&j.value!==null&&(J=j.value)}catch{}J.type==="code_execution_tool_result_error"?I.push({type:"code_execution_tool_result",tool_use_id:R.toolCallId,content:{type:"code_execution_tool_result_error",error_code:(f=J.errorCode)!=null?f:"unknown"},cache_control:z}):I.push({type:"bash_code_execution_tool_result",tool_use_id:R.toolCallId,cache_control:z,content:{type:"bash_code_execution_tool_result_error",error_code:(L=J.errorCode)!=null?L:"unknown"}});break}if(j.type!=="json"){s.push({type:"other",message:`provider executed tool result output type ${j.type} for tool ${R.toolName} is not supported`});break}if(j.value==null||typeof j.value!="object"||!("type"in j.value)||typeof j.value.type!="string"){s.push({type:"other",message:`provider executed tool result output value is not a valid code execution result for tool ${R.toolName}`});break}if(j.value.type==="code_execution_result"){const J=await ce({value:j.value,schema:Ut});I.push({type:"code_execution_tool_result",tool_use_id:R.toolCallId,content:{type:J.type,stdout:J.stdout,stderr:J.stderr,return_code:J.return_code,content:($=J.content)!=null?$:[]},cache_control:z})}else{const J=await ce({value:j.value,schema:Lt});J.type==="code_execution_result"?I.push({type:"code_execution_tool_result",tool_use_id:R.toolCallId,content:{type:J.type,stdout:J.stdout,stderr:J.stderr,return_code:J.return_code,content:(E=J.content)!=null?E:[]},cache_control:z}):J.type==="bash_code_execution_result"||J.type==="bash_code_execution_tool_result_error"?I.push({type:"bash_code_execution_tool_result",tool_use_id:R.toolCallId,cache_control:z,content:J}):I.push({type:"text_editor_code_execution_tool_result",tool_use_id:R.toolCallId,cache_control:z,content:J})}break}if(te==="web_fetch"){const j=R.output;if(j.type==="error-json"){const U=JSON.parse(j.value);I.push({type:"web_fetch_tool_result",tool_use_id:R.toolCallId,content:{type:"web_fetch_tool_result_error",error_code:U.errorCode},cache_control:z});break}if(j.type!=="json"){s.push({type:"other",message:`provider executed tool result output type ${j.type} for tool ${R.toolName} is not supported`});break}const J=await ce({value:j.value,schema:Dt});I.push({type:"web_fetch_tool_result",tool_use_id:R.toolCallId,content:{type:"web_fetch_result",url:J.url,retrieved_at:J.retrievedAt,content:{type:"document",title:J.content.title,citations:J.content.citations,source:{type:J.content.source.type,media_type:J.content.source.mediaType,data:J.content.source.data}}},cache_control:z});break}if(te==="web_search"){const j=R.output;if(j.type!=="json"){s.push({type:"other",message:`provider executed tool result output type ${j.type} for tool ${R.toolName} is not supported`});break}const J=await ce({value:j.value,schema:Pt});I.push({type:"web_search_tool_result",tool_use_id:R.toolCallId,content:J.map(U=>({url:U.url,title:U.title,page_age:U.pageAge,encrypted_content:U.encryptedContent,type:U.type})),cache_control:z});break}if(te==="tool_search_tool_regex"||te==="tool_search_tool_bm25"){const j=R.output;if(j.type!=="json"){s.push({type:"other",message:`provider executed tool result output type ${j.type} for tool ${R.toolName} is not supported`});break}const U=(await ce({value:j.value,schema:Ht})).map(v=>({type:"tool_reference",tool_name:v.toolName}));I.push({type:"tool_search_tool_result",tool_use_id:R.toolCallId,content:{type:"tool_search_tool_search_result",tool_references:U},cache_control:z});break}s.push({type:"other",message:`provider executed tool result for tool ${R.toolName} is not supported`});break}}}}ie.push({role:"assistant",content:I});break}default:{const I=M;throw new Error(`content type: ${I}`)}}}return{prompt:{system:A,messages:ie},betas:X}}function Ho(o){const l=[];let s;for(const p of o){const{role:c}=p;switch(c){case"system":{(s==null?void 0:s.type)!=="system"&&(s={type:"system",messages:[]},l.push(s)),s.messages.push(p);break}case"assistant":{(s==null?void 0:s.type)!=="assistant"&&(s={type:"assistant",messages:[]},l.push(s)),s.messages.push(p);break}case"user":{(s==null?void 0:s.type)!=="user"&&(s={type:"user",messages:[]},l.push(s)),s.messages.push(p);break}case"tool":{(s==null?void 0:s.type)!=="user"&&(s={type:"user",messages:[]},l.push(s)),s.messages.push(p);break}default:{const m=c;throw new Error(`Unsupported role: ${m}`)}}}return l}function Ae({finishReason:o,isJsonResponseFromTool:l}){switch(o){case"pause_turn":case"end_turn":case"stop_sequence":return"stop";case"refusal":return"content-filter";case"tool_use":return l?"stop":"tool-calls";case"max_tokens":case"model_context_window_exceeded":return"length";default:return"other"}}function lt(o,l,s){var p;if(o.type!=="page_location"&&o.type!=="char_location")return;const c=l[o.document_index];if(c)return{type:"source",sourceType:"document",id:s(),mediaType:c.mediaType,title:(p=o.document_title)!=null?p:c.title,filename:c.filename,providerMetadata:{anthropic:o.type==="page_location"?{citedText:o.cited_text,startPageNumber:o.start_page_number,endPageNumber:o.end_page_number}:{citedText:o.cited_text,startCharIndex:o.start_char_index,endCharIndex:o.end_char_index}}}}var jo=class{constructor(o,l){this.specificationVersion="v3";var s;this.modelId=o,this.config=l,this.generateId=(s=l.generateId)!=null?s:pe}supportsUrl(o){return o.protocol==="https:"}get provider(){return this.config.provider}get supportedUrls(){var o,l,s;return(s=(l=(o=this.config).supportedUrls)==null?void 0:l.call(o))!=null?s:{}}async getArgs({userSuppliedBetas:o,prompt:l,maxOutputTokens:s,temperature:p,topP:c,topK:m,frequencyPenalty:u,presencePenalty:d,stopSequences:b,responseFormat:_,seed:T,tools:w,toolChoice:y,providerOptions:g,stream:k}){var C,f,L,$,E,X;const q=[];u!=null&&q.push({type:"unsupported",feature:"frequencyPenalty"}),d!=null&&q.push({type:"unsupported",feature:"presencePenalty"}),T!=null&&q.push({type:"unsupported",feature:"seed"}),p!=null&&p>1?(q.push({type:"unsupported",feature:"temperature",details:`${p} exceeds anthropic maximum of 1.0. clamped to 1.0`}),p=1):p!=null&&p<0&&(q.push({type:"unsupported",feature:"temperature",details:`${p} is below anthropic minimum of 0. clamped to 0`}),p=0),(_==null?void 0:_.type)==="json"&&_.schema==null&&q.push({type:"unsupported",feature:"responseFormat",details:"JSON response format requires a schema. The response format is ignored."});const i=await me({provider:"anthropic",providerOptions:g,schema:mo}),{maxOutputTokens:A,supportsStructuredOutput:ie,isKnownModel:h}=Go(this.modelId),K=((C=this.config.supportsNativeStructuredOutput)!=null?C:!0)&&ie,N=(f=i==null?void 0:i.structuredOutputMode)!=null?f:"auto",S=N==="outputFormat"||N==="auto"&&K,G=(_==null?void 0:_.type)==="json"&&_.schema!=null&&!S?{type:"function",name:"json",description:"Respond with a JSON object.",inputSchema:_.schema}:void 0,M=i==null?void 0:i.contextManagement,I=new Be,F=Rt({tools:w,providerToolNames:{"anthropic.code_execution_20250522":"code_execution","anthropic.code_execution_20250825":"code_execution","anthropic.computer_20241022":"computer","anthropic.computer_20250124":"computer","anthropic.text_editor_20241022":"str_replace_editor","anthropic.text_editor_20250124":"str_replace_editor","anthropic.text_editor_20250429":"str_replace_based_edit_tool","anthropic.text_editor_20250728":"str_replace_based_edit_tool","anthropic.bash_20241022":"bash","anthropic.bash_20250124":"bash","anthropic.memory_20250818":"memory","anthropic.web_search_20250305":"web_search","anthropic.web_fetch_20250910":"web_fetch","anthropic.tool_search_regex_20251119":"tool_search_tool_regex","anthropic.tool_search_bm25_20251119":"tool_search_tool_bm25"}}),{prompt:V,betas:W}=await Lo({prompt:l,sendReasoning:(L=i==null?void 0:i.sendReasoning)!=null?L:!0,warnings:q,cacheControlValidator:I,toolNameMapping:F}),ee=(($=i==null?void 0:i.thinking)==null?void 0:$.type)==="enabled";let H=(E=i==null?void 0:i.thinking)==null?void 0:E.budgetTokens;const le=s??A,R={model:this.modelId,max_tokens:le,temperature:p,top_k:m,top_p:c,stop_sequences:b,...ee&&{thinking:{type:"enabled",budget_tokens:H}},...(i==null?void 0:i.effort)&&{output_config:{effort:i.effort}},...S&&(_==null?void 0:_.type)==="json"&&_.schema!=null&&{output_format:{type:"json_schema",schema:_.schema}},...(i==null?void 0:i.mcpServers)&&i.mcpServers.length>0&&{mcp_servers:i.mcpServers.map(v=>({type:v.type,name:v.name,url:v.url,authorization_token:v.authorizationToken,tool_configuration:v.toolConfiguration?{allowed_tools:v.toolConfiguration.allowedTools,enabled:v.toolConfiguration.enabled}:void 0}))},...(i==null?void 0:i.container)&&{container:i.container.skills&&i.container.skills.length>0?{id:i.container.id,skills:i.container.skills.map(v=>({type:v.type,skill_id:v.skillId,version:v.version}))}:i.container.id},system:V.system,messages:V.messages,...M&&{context_management:{edits:M.edits.map(v=>{const oe=v.type;switch(oe){case"clear_tool_uses_20250919":return{type:v.type,...v.trigger!==void 0&&{trigger:v.trigger},...v.keep!==void 0&&{keep:v.keep},...v.clearAtLeast!==void 0&&{clear_at_least:v.clearAtLeast},...v.clearToolInputs!==void 0&&{clear_tool_inputs:v.clearToolInputs},...v.excludeTools!==void 0&&{exclude_tools:v.excludeTools}};case"clear_thinking_20251015":return{type:v.type,...v.keep!==void 0&&{keep:v.keep}};default:q.push({type:"other",message:`Unknown context management strategy: ${oe}`});return}}).filter(v=>v!==void 0)}}};ee?(H==null&&(q.push({type:"compatibility",feature:"extended thinking",details:"thinking budget is required when thinking is enabled. using default budget of 1024 tokens."}),R.thinking={type:"enabled",budget_tokens:1024},H=1024),R.temperature!=null&&(R.temperature=void 0,q.push({type:"unsupported",feature:"temperature",details:"temperature is not supported when thinking is enabled"})),m!=null&&(R.top_k=void 0,q.push({type:"unsupported",feature:"topK",details:"topK is not supported when thinking is enabled"})),c!=null&&(R.top_p=void 0,q.push({type:"unsupported",feature:"topP",details:"topP is not supported when thinking is enabled"})),R.max_tokens=le+(H??0)):c!=null&&p!=null&&(q.push({type:"unsupported",feature:"topP",details:"topP is not supported when temperature is set. topP is ignored."}),R.top_p=void 0),h&&R.max_tokens>A&&(s!=null&&q.push({type:"unsupported",feature:"maxOutputTokens",details:`${R.max_tokens} (maxOutputTokens + thinkingBudget) is greater than ${this.modelId} ${A} max output tokens. The max output tokens have been limited to ${A}.`}),R.max_tokens=A),i!=null&&i.mcpServers&&i.mcpServers.length>0&&W.add("mcp-client-2025-04-04"),M&&W.add("context-management-2025-06-27"),i!=null&&i.container&&i.container.skills&&i.container.skills.length>0&&(W.add("code-execution-2025-08-25"),W.add("skills-2025-10-02"),W.add("files-api-2025-04-14"),w!=null&&w.some(v=>v.type==="provider"&&v.id==="anthropic.code_execution_20250825")||q.push({type:"other",message:"code execution tool is required when using skills"})),i!=null&&i.effort&&W.add("effort-2025-11-24"),k&&((X=i==null?void 0:i.toolStreaming)==null||X)&&W.add("fine-grained-tool-streaming-2025-05-14"),S&&(_==null?void 0:_.type)==="json"&&_.schema!=null&&W.add("structured-outputs-2025-11-13");const{tools:z,toolChoice:te,toolWarnings:j,betas:J}=await No(G!=null?{tools:[...w??[],G],toolChoice:{type:"required"},disableParallelToolUse:!0,cacheControlValidator:I,supportsStructuredOutput:K}:{tools:w??[],toolChoice:y,disableParallelToolUse:i==null?void 0:i.disableParallelToolUse,cacheControlValidator:I,supportsStructuredOutput:K}),U=I.getWarnings();return{args:{...R,tools:z,tool_choice:te,stream:k===!0?!0:void 0},warnings:[...q,...j,...U],betas:new Set([...W,...J,...o]),usesJsonResponseTool:G!=null,toolNameMapping:F}}async getHeaders({betas:o,headers:l}){return ge(await Se(this.config.headers),l,o.size>0?{"anthropic-beta":Array.from(o).join(",")}:{})}async getBetasFromHeaders(o){var l,s;const c=(l=(await Se(this.config.headers))["anthropic-beta"])!=null?l:"",m=(s=o==null?void 0:o["anthropic-beta"])!=null?s:"";return new Set([...c.toLowerCase().split(","),...m.toLowerCase().split(",")].map(u=>u.trim()).filter(u=>u!==""))}buildRequestUrl(o){var l,s,p;return(p=(s=(l=this.config).buildRequestUrl)==null?void 0:s.call(l,this.config.baseURL,o))!=null?p:`${this.config.baseURL}/messages`}transformRequestBody(o){var l,s,p;return(p=(s=(l=this.config).transformRequestBody)==null?void 0:s.call(l,o))!=null?p:o}extractCitationDocuments(o){const l=s=>{var p,c;if(s.type!=="file"||s.mediaType!=="application/pdf"&&s.mediaType!=="text/plain")return!1;const m=(p=s.providerOptions)==null?void 0:p.anthropic,u=m==null?void 0:m.citations;return(c=u==null?void 0:u.enabled)!=null?c:!1};return o.filter(s=>s.role==="user").flatMap(s=>s.content).filter(l).map(s=>{var p;const c=s;return{title:(p=c.filename)!=null?p:"Untitled Document",filename:c.filename,mediaType:c.mediaType}})}async doGenerate(o){var l,s,p,c,m,u,d,b,_,T,w;const{args:y,warnings:g,betas:k,usesJsonResponseTool:C,toolNameMapping:f}=await this.getArgs({...o,stream:!1,userSuppliedBetas:await this.getBetasFromHeaders(o.headers)}),L=this.extractCitationDocuments(o.prompt),{responseHeaders:$,value:E,rawValue:X}=await fe({url:this.buildRequestUrl(!1),headers:await this.getHeaders({betas:k,headers:o.headers}),body:this.transformRequestBody(y),failedResponseHandler:ot,successfulResponseHandler:be(po),abortSignal:o.abortSignal,fetch:this.config.fetch}),q=[],i={},A={};let ie=!1;for(const h of E.content)switch(h.type){case"text":{if(!C&&(q.push({type:"text",text:h.text}),h.citations))for(const K of h.citations){const N=lt(K,L,this.generateId);N&&q.push(N)}break}case"thinking":{q.push({type:"reasoning",text:h.thinking,providerMetadata:{anthropic:{signature:h.signature}}});break}case"redacted_thinking":{q.push({type:"reasoning",text:"",providerMetadata:{anthropic:{redactedData:h.data}}});break}case"tool_use":{if(C&&h.name==="json")ie=!0,q.push({type:"text",text:JSON.stringify(h.input)});else{const N=h.caller,S=N?{type:N.type,toolId:"tool_id"in N?N.tool_id:void 0}:void 0;q.push({type:"tool-call",toolCallId:h.id,toolName:h.name,input:JSON.stringify(h.input),...S&&{providerMetadata:{anthropic:{caller:S}}}})}break}case"server_tool_use":{if(h.name==="text_editor_code_execution"||h.name==="bash_code_execution")q.push({type:"tool-call",toolCallId:h.id,toolName:f.toCustomToolName("code_execution"),input:JSON.stringify({type:h.name,...h.input}),providerExecuted:!0});else if(h.name==="web_search"||h.name==="code_execution"||h.name==="web_fetch"){const K=h.name==="code_execution"&&h.input!=null&&typeof h.input=="object"&&"code"in h.input&&!("type"in h.input)?{type:"programmatic-tool-call",...h.input}:h.input;q.push({type:"tool-call",toolCallId:h.id,toolName:f.toCustomToolName(h.name),input:JSON.stringify(K),providerExecuted:!0})}else(h.name==="tool_search_tool_regex"||h.name==="tool_search_tool_bm25")&&(A[h.id]=h.name,q.push({type:"tool-call",toolCallId:h.id,toolName:f.toCustomToolName(h.name),input:JSON.stringify(h.input),providerExecuted:!0}));break}case"mcp_tool_use":{i[h.id]={type:"tool-call",toolCallId:h.id,toolName:h.name,input:JSON.stringify(h.input),providerExecuted:!0,dynamic:!0,providerMetadata:{anthropic:{type:"mcp-tool-use",serverName:h.server_name}}},q.push(i[h.id]);break}case"mcp_tool_result":{q.push({type:"tool-result",toolCallId:h.tool_use_id,toolName:i[h.tool_use_id].toolName,isError:h.is_error,result:h.content,dynamic:!0,providerMetadata:i[h.tool_use_id].providerMetadata});break}case"web_fetch_tool_result":{h.content.type==="web_fetch_result"?q.push({type:"tool-result",toolCallId:h.tool_use_id,toolName:f.toCustomToolName("web_fetch"),result:{type:"web_fetch_result",url:h.content.url,retrievedAt:h.content.retrieved_at,content:{type:h.content.content.type,title:h.content.content.title,citations:h.content.content.citations,source:{type:h.content.content.source.type,mediaType:h.content.content.source.media_type,data:h.content.content.source.data}}}}):h.content.type==="web_fetch_tool_result_error"&&q.push({type:"tool-result",toolCallId:h.tool_use_id,toolName:f.toCustomToolName("web_fetch"),isError:!0,result:{type:"web_fetch_tool_result_error",errorCode:h.content.error_code}});break}case"web_search_tool_result":{if(Array.isArray(h.content)){q.push({type:"tool-result",toolCallId:h.tool_use_id,toolName:f.toCustomToolName("web_search"),result:h.content.map(K=>{var N;return{url:K.url,title:K.title,pageAge:(N=K.page_age)!=null?N:null,encryptedContent:K.encrypted_content,type:K.type}})});for(const K of h.content)q.push({type:"source",sourceType:"url",id:this.generateId(),url:K.url,title:K.title,providerMetadata:{anthropic:{pageAge:(l=K.page_age)!=null?l:null}}})}else q.push({type:"tool-result",toolCallId:h.tool_use_id,toolName:f.toCustomToolName("web_search"),isError:!0,result:{type:"web_search_tool_result_error",errorCode:h.content.error_code}});break}case"code_execution_tool_result":{h.content.type==="code_execution_result"?q.push({type:"tool-result",toolCallId:h.tool_use_id,toolName:f.toCustomToolName("code_execution"),result:{type:h.content.type,stdout:h.content.stdout,stderr:h.content.stderr,return_code:h.content.return_code,content:(s=h.content.content)!=null?s:[]}}):h.content.type==="code_execution_tool_result_error"&&q.push({type:"tool-result",toolCallId:h.tool_use_id,toolName:f.toCustomToolName("code_execution"),isError:!0,result:{type:"code_execution_tool_result_error",errorCode:h.content.error_code}});break}case"bash_code_execution_tool_result":case"text_editor_code_execution_tool_result":{q.push({type:"tool-result",toolCallId:h.tool_use_id,toolName:f.toCustomToolName("code_execution"),result:h.content});break}case"tool_search_tool_result":{const K=(p=A[h.tool_use_id])!=null?p:"tool_search_tool_regex";h.content.type==="tool_search_tool_search_result"?q.push({type:"tool-result",toolCallId:h.tool_use_id,toolName:f.toCustomToolName(K),result:h.content.tool_references.map(N=>({type:N.type,toolName:N.tool_name}))}):q.push({type:"tool-result",toolCallId:h.tool_use_id,toolName:f.toCustomToolName(K),isError:!0,result:{type:"tool_search_tool_result_error",errorCode:h.content.error_code}});break}}return{content:q,finishReason:{unified:Ae({finishReason:E.stop_reason,isJsonResponseFromTool:ie}),raw:(c=E.stop_reason)!=null?c:void 0},usage:it(E.usage),request:{body:y},response:{id:(m=E.id)!=null?m:void 0,modelId:(u=E.model)!=null?u:void 0,headers:$,body:X},warnings:g,providerMetadata:{anthropic:{usage:E.usage,cacheCreationInputTokens:(d=E.usage.cache_creation_input_tokens)!=null?d:null,stopSequence:(b=E.stop_sequence)!=null?b:null,container:E.container?{expiresAt:E.container.expires_at,id:E.container.id,skills:(T=(_=E.container.skills)==null?void 0:_.map(h=>({type:h.type,skillId:h.skill_id,version:h.version})))!=null?T:null}:null,contextManagement:(w=st(E.context_management))!=null?w:null}}}}async doStream(o){var l,s;const{args:p,warnings:c,betas:m,usesJsonResponseTool:u,toolNameMapping:d}=await this.getArgs({...o,stream:!0,userSuppliedBetas:await this.getBetasFromHeaders(o.headers)}),b=this.extractCitationDocuments(o.prompt),_=this.buildRequestUrl(!0),{responseHeaders:T,value:w}=await fe({url:_,headers:await this.getHeaders({betas:m,headers:o.headers}),body:this.transformRequestBody(p),failedResponseHandler:ot,successfulResponseHandler:Oe(co),abortSignal:o.abortSignal,fetch:this.config.fetch});let y={unified:"other",raw:void 0};const g={input_tokens:0,output_tokens:0,cache_creation_input_tokens:0,cache_read_input_tokens:0},k={},C={},f={};let L=null,$,E=null,X=null,q=null,i=!1,A;const ie=this.generateId,h=w.pipeThrough(new TransformStream({start(G){G.enqueue({type:"stream-start",warnings:c})},transform(G,M){var I,F,V,W,ee,H,le,R,re,z,te,j,J;if(o.includeRawChunks&&M.enqueue({type:"raw",rawValue:G.rawValue}),!G.success){M.enqueue({type:"error",error:G.error});return}const U=G.value;switch(U.type){case"ping":return;case"content_block_start":{const v=U.content_block,oe=v.type;switch(A=oe,oe){case"text":{if(u)return;k[U.index]={type:"text"},M.enqueue({type:"text-start",id:String(U.index)});return}case"thinking":{k[U.index]={type:"reasoning"},M.enqueue({type:"reasoning-start",id:String(U.index)});return}case"redacted_thinking":{k[U.index]={type:"reasoning"},M.enqueue({type:"reasoning-start",id:String(U.index),providerMetadata:{anthropic:{redactedData:v.data}}});return}case"tool_use":{if(u&&v.name==="json")i=!0,k[U.index]={type:"text"},M.enqueue({type:"text-start",id:String(U.index)});else{const Z=v.caller,he=Z?{type:Z.type,toolId:"tool_id"in Z?Z.tool_id:void 0}:void 0,Ne=v.input&&Object.keys(v.input).length>0?JSON.stringify(v.input):"";k[U.index]={type:"tool-call",toolCallId:v.id,toolName:v.name,input:Ne,firstDelta:Ne.length===0,...he&&{caller:he}},M.enqueue({type:"tool-input-start",id:v.id,toolName:v.name})}return}case"server_tool_use":{if(["web_fetch","web_search","code_execution","text_editor_code_execution","bash_code_execution"].includes(v.name)){const O=v.name==="text_editor_code_execution"||v.name==="bash_code_execution"?"code_execution":v.name,Z=d.toCustomToolName(O);k[U.index]={type:"tool-call",toolCallId:v.id,toolName:Z,input:"",providerExecuted:!0,firstDelta:!0,providerToolName:v.name},M.enqueue({type:"tool-input-start",id:v.id,toolName:Z,providerExecuted:!0})}else if(v.name==="tool_search_tool_regex"||v.name==="tool_search_tool_bm25"){f[v.id]=v.name;const O=d.toCustomToolName(v.name);k[U.index]={type:"tool-call",toolCallId:v.id,toolName:O,input:"",providerExecuted:!0,firstDelta:!0,providerToolName:v.name},M.enqueue({type:"tool-input-start",id:v.id,toolName:O,providerExecuted:!0})}return}case"web_fetch_tool_result":{v.content.type==="web_fetch_result"?M.enqueue({type:"tool-result",toolCallId:v.tool_use_id,toolName:d.toCustomToolName("web_fetch"),result:{type:"web_fetch_result",url:v.content.url,retrievedAt:v.content.retrieved_at,content:{type:v.content.content.type,title:v.content.content.title,citations:v.content.content.citations,source:{type:v.content.content.source.type,mediaType:v.content.content.source.media_type,data:v.content.content.source.data}}}}):v.content.type==="web_fetch_tool_result_error"&&M.enqueue({type:"tool-result",toolCallId:v.tool_use_id,toolName:d.toCustomToolName("web_fetch"),isError:!0,result:{type:"web_fetch_tool_result_error",errorCode:v.content.error_code}});return}case"web_search_tool_result":{if(Array.isArray(v.content)){M.enqueue({type:"tool-result",toolCallId:v.tool_use_id,toolName:d.toCustomToolName("web_search"),result:v.content.map(O=>{var Z;return{url:O.url,title:O.title,pageAge:(Z=O.page_age)!=null?Z:null,encryptedContent:O.encrypted_content,type:O.type}})});for(const O of v.content)M.enqueue({type:"source",sourceType:"url",id:ie(),url:O.url,title:O.title,providerMetadata:{anthropic:{pageAge:(I=O.page_age)!=null?I:null}}})}else M.enqueue({type:"tool-result",toolCallId:v.tool_use_id,toolName:d.toCustomToolName("web_search"),isError:!0,result:{type:"web_search_tool_result_error",errorCode:v.content.error_code}});return}case"code_execution_tool_result":{v.content.type==="code_execution_result"?M.enqueue({type:"tool-result",toolCallId:v.tool_use_id,toolName:d.toCustomToolName("code_execution"),result:{type:v.content.type,stdout:v.content.stdout,stderr:v.content.stderr,return_code:v.content.return_code,content:(F=v.content.content)!=null?F:[]}}):v.content.type==="code_execution_tool_result_error"&&M.enqueue({type:"tool-result",toolCallId:v.tool_use_id,toolName:d.toCustomToolName("code_execution"),isError:!0,result:{type:"code_execution_tool_result_error",errorCode:v.content.error_code}});return}case"bash_code_execution_tool_result":case"text_editor_code_execution_tool_result":{M.enqueue({type:"tool-result",toolCallId:v.tool_use_id,toolName:d.toCustomToolName("code_execution"),result:v.content});return}case"tool_search_tool_result":{const O=(V=f[v.tool_use_id])!=null?V:"tool_search_tool_regex";v.content.type==="tool_search_tool_search_result"?M.enqueue({type:"tool-result",toolCallId:v.tool_use_id,toolName:d.toCustomToolName(O),result:v.content.tool_references.map(Z=>({type:Z.type,toolName:Z.tool_name}))}):M.enqueue({type:"tool-result",toolCallId:v.tool_use_id,toolName:d.toCustomToolName(O),isError:!0,result:{type:"tool_search_tool_result_error",errorCode:v.content.error_code}});return}case"mcp_tool_use":{C[v.id]={type:"tool-call",toolCallId:v.id,toolName:v.name,input:JSON.stringify(v.input),providerExecuted:!0,dynamic:!0,providerMetadata:{anthropic:{type:"mcp-tool-use",serverName:v.server_name}}},M.enqueue(C[v.id]);return}case"mcp_tool_result":{M.enqueue({type:"tool-result",toolCallId:v.tool_use_id,toolName:C[v.tool_use_id].toolName,isError:v.is_error,result:v.content,dynamic:!0,providerMetadata:C[v.tool_use_id].providerMetadata});return}default:{const O=oe;throw new Error(`Unsupported content block type: ${O}`)}}}case"content_block_stop":{if(k[U.index]!=null){const v=k[U.index];switch(v.type){case"text":{M.enqueue({type:"text-end",id:String(U.index)});break}case"reasoning":{M.enqueue({type:"reasoning-end",id:String(U.index)});break}case"tool-call":if(!(u&&v.toolName==="json")){M.enqueue({type:"tool-input-end",id:v.toolCallId});let O=v.input===""?"{}":v.input;if(v.providerToolName==="code_execution")try{const Z=JSON.parse(O);Z!=null&&typeof Z=="object"&&"code"in Z&&!("type"in Z)&&(O=JSON.stringify({type:"programmatic-tool-call",...Z}))}catch{}M.enqueue({type:"tool-call",toolCallId:v.toolCallId,toolName:v.toolName,input:O,providerExecuted:v.providerExecuted,...v.caller&&{providerMetadata:{anthropic:{caller:v.caller}}}})}break}delete k[U.index]}A=void 0;return}case"content_block_delta":{const v=U.delta.type;switch(v){case"text_delta":{if(u)return;M.enqueue({type:"text-delta",id:String(U.index),delta:U.delta.text});return}case"thinking_delta":{M.enqueue({type:"reasoning-delta",id:String(U.index),delta:U.delta.thinking});return}case"signature_delta":{A==="thinking"&&M.enqueue({type:"reasoning-delta",id:String(U.index),delta:"",providerMetadata:{anthropic:{signature:U.delta.signature}}});return}case"input_json_delta":{const oe=k[U.index];let O=U.delta.partial_json;if(O.length===0)return;if(i){if((oe==null?void 0:oe.type)!=="text")return;M.enqueue({type:"text-delta",id:String(U.index),delta:O})}else{if((oe==null?void 0:oe.type)!=="tool-call")return;oe.firstDelta&&(oe.providerToolName==="bash_code_execution"||oe.providerToolName==="text_editor_code_execution")&&(O=`{"type": "${oe.providerToolName}",${O.substring(1)}`),M.enqueue({type:"tool-input-delta",id:oe.toolCallId,delta:O}),oe.input+=O,oe.firstDelta=!1}return}case"citations_delta":{const oe=U.delta.citation,O=lt(oe,b,ie);O&&M.enqueue(O);return}default:{const oe=v;throw new Error(`Unsupported delta type: ${oe}`)}}}case"message_start":{if(g.input_tokens=U.message.usage.input_tokens,g.cache_read_input_tokens=(W=U.message.usage.cache_read_input_tokens)!=null?W:0,g.cache_creation_input_tokens=(ee=U.message.usage.cache_creation_input_tokens)!=null?ee:0,$={...U.message.usage},E=(H=U.message.usage.cache_creation_input_tokens)!=null?H:null,U.message.container!=null&&(q={expiresAt:U.message.container.expires_at,id:U.message.container.id,skills:null}),U.message.stop_reason!=null&&(y={unified:Ae({finishReason:U.message.stop_reason,isJsonResponseFromTool:i}),raw:U.message.stop_reason}),M.enqueue({type:"response-metadata",id:(le=U.message.id)!=null?le:void 0,modelId:(R=U.message.model)!=null?R:void 0}),U.message.content!=null)for(let v=0;v<U.message.content.length;v++){const oe=U.message.content[v];if(oe.type==="tool_use"){const O=oe.caller,Z=O?{type:O.type,toolId:"tool_id"in O?O.tool_id:void 0}:void 0;M.enqueue({type:"tool-input-start",id:oe.id,toolName:oe.name});const he=JSON.stringify((re=oe.input)!=null?re:{});M.enqueue({type:"tool-input-delta",id:oe.id,delta:he}),M.enqueue({type:"tool-input-end",id:oe.id}),M.enqueue({type:"tool-call",toolCallId:oe.id,toolName:oe.name,input:he,...Z&&{providerMetadata:{anthropic:{caller:Z}}}})}}return}case"message_delta":{g.output_tokens=U.usage.output_tokens,y={unified:Ae({finishReason:U.delta.stop_reason,isJsonResponseFromTool:i}),raw:(z=U.delta.stop_reason)!=null?z:void 0},X=(te=U.delta.stop_sequence)!=null?te:null,q=U.delta.container!=null?{expiresAt:U.delta.container.expires_at,id:U.delta.container.id,skills:(J=(j=U.delta.container.skills)==null?void 0:j.map(v=>({type:v.type,skillId:v.skill_id,version:v.version})))!=null?J:null}:null,U.delta.context_management&&(L=st(U.delta.context_management)),$={...$,...U.usage};return}case"message_stop":{M.enqueue({type:"finish",finishReason:y,usage:it(g),providerMetadata:{anthropic:{usage:$??null,cacheCreationInputTokens:E,stopSequence:X,container:q,contextManagement:L}}});return}case"error":{M.enqueue({type:"error",error:U.error});return}default:{const v=U;throw new Error(`Unsupported chunk type: ${v}`)}}}})),[K,N]=h.tee(),S=K.getReader();try{await S.read();let G=await S.read();if(((l=G.value)==null?void 0:l.type)==="raw"&&(G=await S.read()),((s=G.value)==null?void 0:s.type)==="error"){const M=G.value.error;throw new Ot({message:M.message,url:_,requestBodyValues:p,statusCode:M.type==="overloaded_error"?529:500,responseHeaders:T,responseBody:JSON.stringify(M),isRetryable:M.type==="overloaded_error"})}}finally{S.cancel().catch(()=>{}),S.releaseLock()}return{stream:N,request:{body:p},response:{headers:T}}}};function Go(o){return o.includes("claude-sonnet-4-5")||o.includes("claude-opus-4-5")||o.includes("claude-haiku-4-5")?{maxOutputTokens:64e3,supportsStructuredOutput:!0,isKnownModel:!0}:o.includes("claude-opus-4-1")?{maxOutputTokens:32e3,supportsStructuredOutput:!0,isKnownModel:!0}:o.includes("claude-sonnet-4-")||o.includes("claude-3-7-sonnet")?{maxOutputTokens:64e3,supportsStructuredOutput:!1,isKnownModel:!0}:o.includes("claude-opus-4-")?{maxOutputTokens:32e3,supportsStructuredOutput:!1,isKnownModel:!0}:o.includes("claude-3-5-haiku")?{maxOutputTokens:8192,supportsStructuredOutput:!1,isKnownModel:!0}:o.includes("claude-3-haiku")?{maxOutputTokens:4096,supportsStructuredOutput:!1,isKnownModel:!0}:{maxOutputTokens:4096,supportsStructuredOutput:!1,isKnownModel:!1}}function st(o){return o?{appliedEdits:o.applied_edits.map(l=>{switch(l.type){case"clear_tool_uses_20250919":return{type:l.type,clearedToolUses:l.cleared_tool_uses,clearedInputTokens:l.cleared_input_tokens};case"clear_thinking_20251015":return{type:l.type,clearedThinkingTurns:l.cleared_thinking_turns,clearedInputTokens:l.cleared_input_tokens}}}).filter(l=>l!==void 0)}:null}var Vo=P(()=>D(t({command:e(),restart:ne().optional()}))),Bo=ve({id:"anthropic.bash_20241022",inputSchema:Vo}),Wo=P(()=>D(t({command:e(),restart:ne().optional()}))),Fo=ve({id:"anthropic.bash_20250124",inputSchema:Wo}),Jo=P(()=>D(t({action:Y(["key","type","mouse_move","left_click","left_click_drag","right_click","middle_click","double_click","screenshot","cursor_position"]),coordinate:x(a().int()).optional(),text:e().optional()}))),Ko=ve({id:"anthropic.computer_20241022",inputSchema:Jo}),zo=P(()=>D(t({action:Y(["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:De([a().int(),a().int()]).optional(),duration:a().optional(),scroll_amount:a().optional(),scroll_direction:Y(["up","down","left","right"]).optional(),start_coordinate:De([a().int(),a().int()]).optional(),text:e().optional()}))),Yo=ve({id:"anthropic.computer_20250124",inputSchema:zo}),Xo=P(()=>D(ae("command",[t({command:n("view"),path:e(),view_range:De([a(),a()]).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:a(),insert_text:e()}),t({command:n("delete"),path:e()}),t({command:n("rename"),old_path:e(),new_path:e()})]))),Qo=ve({id:"anthropic.memory_20250818",inputSchema:Xo}),Zo=P(()=>D(t({command:Y(["view","create","str_replace","insert","undo_edit"]),path:e(),file_text:e().optional(),insert_line:a().int().optional(),new_str:e().optional(),old_str:e().optional(),view_range:x(a().int()).optional()}))),en=ve({id:"anthropic.text_editor_20241022",inputSchema:Zo}),tn=P(()=>D(t({command:Y(["view","create","str_replace","insert","undo_edit"]),path:e(),file_text:e().optional(),insert_line:a().int().optional(),new_str:e().optional(),old_str:e().optional(),view_range:x(a().int()).optional()}))),on=ve({id:"anthropic.text_editor_20250124",inputSchema:tn}),nn=P(()=>D(t({command:Y(["view","create","str_replace","insert"]),path:e(),file_text:e().optional(),insert_line:a().int().optional(),new_str:e().optional(),old_str:e().optional(),view_range:x(a().int()).optional()}))),an=ve({id:"anthropic.text_editor_20250429",inputSchema:nn}),ln=P(()=>D(x(t({type:n("tool_reference"),toolName:e()})))),sn=P(()=>D(t({query:e(),limit:a().optional()}))),rn=ye({id:"anthropic.tool_search_bm25_20251119",inputSchema:sn,outputSchema:ln}),un=(o={})=>rn(o),pn={bash_20241022:Bo,bash_20250124:Fo,codeExecution_20250522:Mo,codeExecution_20250825:Ao,computer_20241022:Ko,computer_20250124:Yo,memory_20250818:Qo,textEditor_20241022:en,textEditor_20250124:on,textEditor_20250429:an,textEditor_20250728:vo,webFetch_20250910:So,webSearch_20250305:ko,toolSearchRegex_20251119:Do,toolSearchBm25_20251119:un};function cn(o={}){var l,s;const p=(l=Le(Nt({settingValue:o.baseURL,environmentVariableName:"ANTHROPIC_BASE_URL"})))!=null?l:"https://api.anthropic.com/v1",c=(s=o.name)!=null?s:"anthropic.messages",m=()=>He({"anthropic-version":"2023-06-01","x-api-key":je({apiKey:o.apiKey,environmentVariableName:"ANTHROPIC_API_KEY",description:"Anthropic"}),...o.headers},`ai-sdk/anthropic/${ro}`),u=b=>{var _;return new jo(b,{provider:c,baseURL:p,headers:m,fetch:o.fetch,generateId:(_=o.generateId)!=null?_:pe,supportedUrls:()=>({"image/*":[/^https?:\/\/.*$/]})})},d=function(b){if(new.target)throw new Error("The Anthropic model function cannot be called with the new keyword.");return u(b)};return d.specificationVersion="v3",d.languageModel=u,d.chat=u,d.messages=u,d.embeddingModel=b=>{throw new et({modelId:b,modelType:"embeddingModel"})},d.textEmbeddingModel=d.embeddingModel,d.imageModel=b=>{throw new et({modelId:b,modelType:"imageModel"})},d.tools=pn,d}var ri=cn(),We=t({error:t({message:e(),type:e().nullish(),param:Me().nullish(),code:Q([e(),a()]).nullish()})}),ke=Ge({errorSchema:We,errorToMessage:o=>o.error.message});function jt(o){const l=o.startsWith("o3")||o.startsWith("o4-mini")||o.startsWith("gpt-5")&&!o.startsWith("gpt-5-chat"),s=o.startsWith("gpt-4")||o.startsWith("gpt-5-mini")||o.startsWith("gpt-5")&&!o.startsWith("gpt-5-nano")&&!o.startsWith("gpt-5-chat")||o.startsWith("o3")||o.startsWith("o4-mini"),p=o.startsWith("o1")||o.startsWith("o3")||o.startsWith("o4-mini")||o.startsWith("codex-mini")||o.startsWith("computer-use-preview")||o.startsWith("gpt-5")&&!o.startsWith("gpt-5-chat"),c=o.startsWith("gpt-5.1")||o.startsWith("gpt-5.2");return{supportsFlexProcessing:l,supportsPriorityProcessing:s,isReasoningModel:p,systemMessageMode:p?"developer":"system",supportsNonReasoningParameters:c}}function rt(o){var l,s,p,c,m,u;if(o==null)return{inputTokens:{total:void 0,noCache:void 0,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:void 0,text:void 0,reasoning:void 0},raw:void 0};const d=(l=o.prompt_tokens)!=null?l:0,b=(s=o.completion_tokens)!=null?s:0,_=(c=(p=o.prompt_tokens_details)==null?void 0:p.cached_tokens)!=null?c:0,T=(u=(m=o.completion_tokens_details)==null?void 0:m.reasoning_tokens)!=null?u:0;return{inputTokens:{total:d,noCache:d-_,cacheRead:_,cacheWrite:void 0},outputTokens:{total:b,text:b-T,reasoning:T},raw:o}}function dn({prompt:o,systemMessageMode:l="system"}){var s;const p=[],c=[];for(const{role:m,content:u}of o)switch(m){case"system":{switch(l){case"system":{p.push({role:"system",content:u});break}case"developer":{p.push({role:"developer",content:u});break}case"remove":{c.push({type:"other",message:"system messages are removed for this model"});break}default:{const d=l;throw new Error(`Unsupported system message mode: ${d}`)}}break}case"user":{if(u.length===1&&u[0].type==="text"){p.push({role:"user",content:u[0].text});break}p.push({role:"user",content:u.map((d,b)=>{var _,T,w;switch(d.type){case"text":return{type:"text",text:d.text};case"file":if(d.mediaType.startsWith("image/")){const y=d.mediaType==="image/*"?"image/jpeg":d.mediaType;return{type:"image_url",image_url:{url:d.data instanceof URL?d.data.toString():`data:${y};base64,${Ie(d.data)}`,detail:(T=(_=d.providerOptions)==null?void 0:_.openai)==null?void 0:T.imageDetail}}}else if(d.mediaType.startsWith("audio/")){if(d.data instanceof URL)throw new _e({functionality:"audio file parts with URLs"});switch(d.mediaType){case"audio/wav":return{type:"input_audio",input_audio:{data:Ie(d.data),format:"wav"}};case"audio/mp3":case"audio/mpeg":return{type:"input_audio",input_audio:{data:Ie(d.data),format:"mp3"}};default:throw new _e({functionality:`audio content parts with media type ${d.mediaType}`})}}else if(d.mediaType==="application/pdf"){if(d.data instanceof URL)throw new _e({functionality:"PDF file parts with URLs"});return{type:"file",file:typeof d.data=="string"&&d.data.startsWith("file-")?{file_id:d.data}:{filename:(w=d.filename)!=null?w:`part-${b}.pdf`,file_data:`data:application/pdf;base64,${Ie(d.data)}`}}}else throw new _e({functionality:`file part media type ${d.mediaType}`})}})});break}case"assistant":{let d="";const b=[];for(const _ of u)switch(_.type){case"text":{d+=_.text;break}case"tool-call":{b.push({id:_.toolCallId,type:"function",function:{name:_.toolName,arguments:JSON.stringify(_.input)}});break}}p.push({role:"assistant",content:d,tool_calls:b.length>0?b:void 0});break}case"tool":{for(const d of u){if(d.type==="tool-approval-response")continue;const b=d.output;let _;switch(b.type){case"text":case"error-text":_=b.value;break;case"execution-denied":_=(s=b.reason)!=null?s:"Tool execution denied.";break;case"content":case"json":case"error-json":_=JSON.stringify(b.value);break}p.push({role:"tool",tool_call_id:d.toolCallId,content:_})}break}default:{const d=m;throw new Error(`Unsupported role: ${d}`)}}return{messages:p,warnings:c}}function $e({id:o,model:l,created:s}){return{id:o??void 0,modelId:l??void 0,timestamp:s?new Date(s*1e3):void 0}}function ut(o){switch(o){case"stop":return"stop";case"length":return"length";case"content_filter":return"content-filter";case"function_call":case"tool_calls":return"tool-calls";default:return"other"}}var _n=P(()=>D(t({id:e().nullish(),created:a().nullish(),model:e().nullish(),choices:x(t({message:t({role:n("assistant").nullish(),content:e().nullish(),tool_calls:x(t({id:e().nullish(),type:n("function"),function:t({name:e(),arguments:e()})})).nullish(),annotations:x(t({type:n("url_citation"),url_citation:t({start_index:a(),end_index:a(),url:e(),title:e()})})).nullish()}),index:a(),logprobs:t({content:x(t({token:e(),logprob:a(),top_logprobs:x(t({token:e(),logprob:a()}))})).nullish()}).nullish(),finish_reason:e().nullish()})),usage:t({prompt_tokens:a().nullish(),completion_tokens:a().nullish(),total_tokens:a().nullish(),prompt_tokens_details:t({cached_tokens:a().nullish()}).nullish(),completion_tokens_details:t({reasoning_tokens:a().nullish(),accepted_prediction_tokens:a().nullish(),rejected_prediction_tokens:a().nullish()}).nullish()}).nullish()}))),mn=P(()=>D(Q([t({id:e().nullish(),created:a().nullish(),model:e().nullish(),choices:x(t({delta:t({role:Y(["assistant"]).nullish(),content:e().nullish(),tool_calls:x(t({index:a(),id:e().nullish(),type:n("function").nullish(),function:t({name:e().nullish(),arguments:e().nullish()})})).nullish(),annotations:x(t({type:n("url_citation"),url_citation:t({start_index:a(),end_index:a(),url:e(),title:e()})})).nullish()}).nullish(),logprobs:t({content:x(t({token:e(),logprob:a(),top_logprobs:x(t({token:e(),logprob:a()}))})).nullish()}).nullish(),finish_reason:e().nullish(),index:a()})),usage:t({prompt_tokens:a().nullish(),completion_tokens:a().nullish(),total_tokens:a().nullish(),prompt_tokens_details:t({cached_tokens:a().nullish()}).nullish(),completion_tokens_details:t({reasoning_tokens:a().nullish(),accepted_prediction_tokens:a().nullish(),rejected_prediction_tokens:a().nullish()}).nullish()}).nullish()}),We]))),hn=P(()=>D(t({logitBias:ue(so(),a()).optional(),logprobs:Q([ne(),a()]).optional(),parallelToolCalls:ne().optional(),user:e().optional(),reasoningEffort:Y(["none","minimal","low","medium","high","xhigh"]).optional(),maxCompletionTokens:a().optional(),store:ne().optional(),metadata:ue(e().max(64),e().max(512)).optional(),prediction:ue(e(),Me()).optional(),serviceTier:Y(["auto","flex","priority","default"]).optional(),strictJsonSchema:ne().optional(),textVerbosity:Y(["low","medium","high"]).optional(),promptCacheKey:e().optional(),promptCacheRetention:Y(["in_memory","24h"]).optional(),safetyIdentifier:e().optional(),systemMessageMode:Y(["system","developer","remove"]).optional(),forceReasoning:ne().optional()})));function gn({tools:o,toolChoice:l}){o=o!=null&&o.length?o:void 0;const s=[];if(o==null)return{tools:void 0,toolChoice:void 0,toolWarnings:s};const p=[];for(const m of o)switch(m.type){case"function":p.push({type:"function",function:{name:m.name,description:m.description,parameters:m.inputSchema,...m.strict!=null?{strict:m.strict}:{}}});break;default:s.push({type:"unsupported",feature:`tool type: ${m.type}`});break}if(l==null)return{tools:p,toolChoice:void 0,toolWarnings:s};const c=l.type;switch(c){case"auto":case"none":case"required":return{tools:p,toolChoice:c,toolWarnings:s};case"tool":return{tools:p,toolChoice:{type:"function",function:{name:l.toolName}},toolWarnings:s};default:{const m=c;throw new _e({functionality:`tool choice type: ${m}`})}}}var fn=class{constructor(o,l){this.specificationVersion="v3",this.supportedUrls={"image/*":[/^https?:\/\/.*$/]},this.modelId=o,this.config=l}get provider(){return this.config.provider}async getArgs({prompt:o,maxOutputTokens:l,temperature:s,topP:p,topK:c,frequencyPenalty:m,presencePenalty:u,stopSequences:d,responseFormat:b,seed:_,tools:T,toolChoice:w,providerOptions:y}){var g,k,C,f,L;const $=[],E=(g=await me({provider:"openai",providerOptions:y,schema:hn}))!=null?g:{},X=jt(this.modelId),q=(k=E.forceReasoning)!=null?k:X.isReasoningModel;c!=null&&$.push({type:"unsupported",feature:"topK"});const{messages:i,warnings:A}=dn({prompt:o,systemMessageMode:(C=E.systemMessageMode)!=null?C:q?"developer":X.systemMessageMode});$.push(...A);const ie=(f=E.strictJsonSchema)!=null?f:!0,h={model:this.modelId,logit_bias:E.logitBias,logprobs:E.logprobs===!0||typeof E.logprobs=="number"?!0:void 0,top_logprobs:typeof E.logprobs=="number"?E.logprobs:typeof E.logprobs=="boolean"&&E.logprobs?0:void 0,user:E.user,parallel_tool_calls:E.parallelToolCalls,max_tokens:l,temperature:s,top_p:p,frequency_penalty:m,presence_penalty:u,response_format:(b==null?void 0:b.type)==="json"?b.schema!=null?{type:"json_schema",json_schema:{schema:b.schema,strict:ie,name:(L=b.name)!=null?L:"response",description:b.description}}:{type:"json_object"}:void 0,stop:d,seed:_,verbosity:E.textVerbosity,max_completion_tokens:E.maxCompletionTokens,store:E.store,metadata:E.metadata,prediction:E.prediction,reasoning_effort:E.reasoningEffort,service_tier:E.serviceTier,prompt_cache_key:E.promptCacheKey,prompt_cache_retention:E.promptCacheRetention,safety_identifier:E.safetyIdentifier,messages:i};q?((E.reasoningEffort!=="none"||!X.supportsNonReasoningParameters)&&(h.temperature!=null&&(h.temperature=void 0,$.push({type:"unsupported",feature:"temperature",details:"temperature is not supported for reasoning models"})),h.top_p!=null&&(h.top_p=void 0,$.push({type:"unsupported",feature:"topP",details:"topP is not supported for reasoning models"})),h.logprobs!=null&&(h.logprobs=void 0,$.push({type:"other",message:"logprobs is not supported for reasoning models"}))),h.frequency_penalty!=null&&(h.frequency_penalty=void 0,$.push({type:"unsupported",feature:"frequencyPenalty",details:"frequencyPenalty is not supported for reasoning models"})),h.presence_penalty!=null&&(h.presence_penalty=void 0,$.push({type:"unsupported",feature:"presencePenalty",details:"presencePenalty is not supported for reasoning models"})),h.logit_bias!=null&&(h.logit_bias=void 0,$.push({type:"other",message:"logitBias is not supported for reasoning models"})),h.top_logprobs!=null&&(h.top_logprobs=void 0,$.push({type:"other",message:"topLogprobs is not supported for reasoning models"})),h.max_tokens!=null&&(h.max_completion_tokens==null&&(h.max_completion_tokens=h.max_tokens),h.max_tokens=void 0)):(this.modelId.startsWith("gpt-4o-search-preview")||this.modelId.startsWith("gpt-4o-mini-search-preview"))&&h.temperature!=null&&(h.temperature=void 0,$.push({type:"unsupported",feature:"temperature",details:"temperature is not supported for the search preview models and has been removed."})),E.serviceTier==="flex"&&!X.supportsFlexProcessing&&($.push({type:"unsupported",feature:"serviceTier",details:"flex processing is only available for o3, o4-mini, and gpt-5 models"}),h.service_tier=void 0),E.serviceTier==="priority"&&!X.supportsPriorityProcessing&&($.push({type:"unsupported",feature:"serviceTier",details:"priority processing is only available for supported models (gpt-4, gpt-5, gpt-5-mini, o3, o4-mini) and requires Enterprise access. gpt-5-nano is not supported"}),h.service_tier=void 0);const{tools:K,toolChoice:N,toolWarnings:S}=gn({tools:T,toolChoice:w});return{args:{...h,tools:K,tool_choice:N},warnings:[...$,...S]}}async doGenerate(o){var l,s,p,c,m,u,d;const{args:b,warnings:_}=await this.getArgs(o),{responseHeaders:T,value:w,rawValue:y}=await fe({url:this.config.url({path:"/chat/completions",modelId:this.modelId}),headers:ge(this.config.headers(),o.headers),body:b,failedResponseHandler:ke,successfulResponseHandler:be(_n),abortSignal:o.abortSignal,fetch:this.config.fetch}),g=w.choices[0],k=[],C=g.message.content;C!=null&&C.length>0&&k.push({type:"text",text:C});for(const $ of(l=g.message.tool_calls)!=null?l:[])k.push({type:"tool-call",toolCallId:(s=$.id)!=null?s:pe(),toolName:$.function.name,input:$.function.arguments});for(const $ of(p=g.message.annotations)!=null?p:[])k.push({type:"source",sourceType:"url",id:pe(),url:$.url_citation.url,title:$.url_citation.title});const f=(c=w.usage)==null?void 0:c.completion_tokens_details;(m=w.usage)==null||m.prompt_tokens_details;const L={openai:{}};return(f==null?void 0:f.accepted_prediction_tokens)!=null&&(L.openai.acceptedPredictionTokens=f==null?void 0:f.accepted_prediction_tokens),(f==null?void 0:f.rejected_prediction_tokens)!=null&&(L.openai.rejectedPredictionTokens=f==null?void 0:f.rejected_prediction_tokens),((u=g.logprobs)==null?void 0:u.content)!=null&&(L.openai.logprobs=g.logprobs.content),{content:k,finishReason:{unified:ut(g.finish_reason),raw:(d=g.finish_reason)!=null?d:void 0},usage:rt(w.usage),request:{body:b},response:{...$e(w),headers:T,body:y},warnings:_,providerMetadata:L}}async doStream(o){const{args:l,warnings:s}=await this.getArgs(o),p={...l,stream:!0,stream_options:{include_usage:!0}},{responseHeaders:c,value:m}=await fe({url:this.config.url({path:"/chat/completions",modelId:this.modelId}),headers:ge(this.config.headers(),o.headers),body:p,failedResponseHandler:ke,successfulResponseHandler:Oe(mn),abortSignal:o.abortSignal,fetch:this.config.fetch}),u=[];let d={unified:"other",raw:void 0},b,_=!1,T=!1;const w={openai:{}};return{stream:m.pipeThrough(new TransformStream({start(y){y.enqueue({type:"stream-start",warnings:s})},transform(y,g){var k,C,f,L,$,E,X,q,i,A,ie,h,K,N,S,G,M;if(o.includeRawChunks&&g.enqueue({type:"raw",rawValue:y.rawValue}),!y.success){d={unified:"error",raw:void 0},g.enqueue({type:"error",error:y.error});return}const I=y.value;if("error"in I){d={unified:"error",raw:void 0},g.enqueue({type:"error",error:I.error});return}if(!_){const W=$e(I);Object.values(W).some(Boolean)&&(_=!0,g.enqueue({type:"response-metadata",...$e(I)}))}I.usage!=null&&(b=I.usage,((k=I.usage.completion_tokens_details)==null?void 0:k.accepted_prediction_tokens)!=null&&(w.openai.acceptedPredictionTokens=(C=I.usage.completion_tokens_details)==null?void 0:C.accepted_prediction_tokens),((f=I.usage.completion_tokens_details)==null?void 0:f.rejected_prediction_tokens)!=null&&(w.openai.rejectedPredictionTokens=(L=I.usage.completion_tokens_details)==null?void 0:L.rejected_prediction_tokens));const F=I.choices[0];if((F==null?void 0:F.finish_reason)!=null&&(d={unified:ut(F.finish_reason),raw:F.finish_reason}),(($=F==null?void 0:F.logprobs)==null?void 0:$.content)!=null&&(w.openai.logprobs=F.logprobs.content),(F==null?void 0:F.delta)==null)return;const V=F.delta;if(V.content!=null&&(T||(g.enqueue({type:"text-start",id:"0"}),T=!0),g.enqueue({type:"text-delta",id:"0",delta:V.content})),V.tool_calls!=null)for(const W of V.tool_calls){const ee=W.index;if(u[ee]==null){if(W.type!=="function")throw new qe({data:W,message:"Expected 'function' type."});if(W.id==null)throw new qe({data:W,message:"Expected 'id' to be a string."});if(((E=W.function)==null?void 0:E.name)==null)throw new qe({data:W,message:"Expected 'function.name' to be a string."});g.enqueue({type:"tool-input-start",id:W.id,toolName:W.function.name}),u[ee]={id:W.id,type:"function",function:{name:W.function.name,arguments:(X=W.function.arguments)!=null?X:""},hasFinished:!1};const le=u[ee];((q=le.function)==null?void 0:q.name)!=null&&((i=le.function)==null?void 0:i.arguments)!=null&&(le.function.arguments.length>0&&g.enqueue({type:"tool-input-delta",id:le.id,delta:le.function.arguments}),tt(le.function.arguments)&&(g.enqueue({type:"tool-input-end",id:le.id}),g.enqueue({type:"tool-call",toolCallId:(A=le.id)!=null?A:pe(),toolName:le.function.name,input:le.function.arguments}),le.hasFinished=!0));continue}const H=u[ee];H.hasFinished||(((ie=W.function)==null?void 0:ie.arguments)!=null&&(H.function.arguments+=(K=(h=W.function)==null?void 0:h.arguments)!=null?K:""),g.enqueue({type:"tool-input-delta",id:H.id,delta:(N=W.function.arguments)!=null?N:""}),((S=H.function)==null?void 0:S.name)!=null&&((G=H.function)==null?void 0:G.arguments)!=null&&tt(H.function.arguments)&&(g.enqueue({type:"tool-input-end",id:H.id}),g.enqueue({type:"tool-call",toolCallId:(M=H.id)!=null?M:pe(),toolName:H.function.name,input:H.function.arguments}),H.hasFinished=!0))}if(V.annotations!=null)for(const W of V.annotations)g.enqueue({type:"source",sourceType:"url",id:pe(),url:W.url_citation.url,title:W.url_citation.title})},flush(y){T&&y.enqueue({type:"text-end",id:"0"}),y.enqueue({type:"finish",finishReason:d,usage:rt(b),...w!=null?{providerMetadata:w}:{}})}})),request:{body:p},response:{headers:c}}}};function pt(o){var l,s,p,c;if(o==null)return{inputTokens:{total:void 0,noCache:void 0,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:void 0,text:void 0,reasoning:void 0},raw:void 0};const m=(l=o.prompt_tokens)!=null?l:0,u=(s=o.completion_tokens)!=null?s:0;return{inputTokens:{total:(p=o.prompt_tokens)!=null?p:void 0,noCache:m,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:(c=o.completion_tokens)!=null?c:void 0,text:u,reasoning:void 0},raw:o}}function yn({prompt:o,user:l="user",assistant:s="assistant"}){let p="";o[0].role==="system"&&(p+=`${o[0].content}
1
+ import{_ as eo,Z as to,w as Le,l as Nt,a as pe,b as He,p as me,c as Rt,d as ge,r as Se,e as fe,A as Ot,f as je,o as t,h as be,i as Oe,v as ce,j as P,k as Mt,m as Ie,U as _e,n as Y,q as ne,t as x,u as ae,x as n,y as e,z as a,B as Q,C as Ge,D,N as et,E as ve,F as Pe,G as we,H as ue,I as ye,J as De,K as Me,L as Et,M as oo,O as qe,P as tt,T as qt,Q as At,R as no,S as $t,V as Ve,W as ao,X as io,Y as lo}from"./index-BuyyCfeJ.js";function so(o){return eo(to,o)}var ro="3.0.8",uo=P(()=>D(t({type:n("error"),error:t({type:e(),message:e()})}))),ot=Ge({errorSchema:uo,errorToMessage:o=>o.error.message}),po=P(()=>D(t({type:n("message"),id:e().nullish(),model:e().nullish(),content:x(ae("type",[t({type:n("text"),text:e(),citations:x(ae("type",[t({type:n("web_search_result_location"),cited_text:e(),url:e(),title:e(),encrypted_index:e()}),t({type:n("page_location"),cited_text:e(),document_index:a(),document_title:e().nullable(),start_page_number:a(),end_page_number:a()}),t({type:n("char_location"),cited_text:e(),document_index:a(),document_title:e().nullable(),start_char_index:a(),end_char_index:a()})])).optional()}),t({type:n("thinking"),thinking:e(),signature:e()}),t({type:n("redacted_thinking"),data:e()}),t({type:n("tool_use"),id:e(),name:e(),input:we(),caller:Q([t({type:n("code_execution_20250825"),tool_id:e()}),t({type:n("direct")})]).optional()}),t({type:n("server_tool_use"),id:e(),name:e(),input:ue(e(),we()).nullish()}),t({type:n("mcp_tool_use"),id:e(),name:e(),input:we(),server_name:e()}),t({type:n("mcp_tool_result"),tool_use_id:e(),is_error:ne(),content:x(Q([e(),t({type:n("text"),text:e()})]))}),t({type:n("web_fetch_tool_result"),tool_use_id:e(),content:Q([t({type:n("web_fetch_result"),url:e(),retrieved_at:e(),content:t({type:n("document"),title:e().nullable(),citations:t({enabled:ne()}).optional(),source:Q([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(),content:Q([x(t({type:n("web_search_result"),url:e(),title:e(),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:Q([t({type:n("code_execution_result"),stdout:e(),stderr:e(),return_code:a(),content:x(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:ae("type",[t({type:n("bash_code_execution_result"),content:x(t({type:n("bash_code_execution_output"),file_id:e()})),stdout:e(),stderr:e(),return_code:a()}),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:ae("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:a().nullable(),start_line:a().nullable(),total_lines:a().nullable()}),t({type:n("text_editor_code_execution_create_result"),is_file_update:ne()}),t({type:n("text_editor_code_execution_str_replace_result"),lines:x(e()).nullable(),new_lines:a().nullable(),new_start:a().nullable(),old_lines:a().nullable(),old_start:a().nullable()})])}),t({type:n("tool_search_tool_result"),tool_use_id:e(),content:Q([t({type:n("tool_search_tool_search_result"),tool_references:x(t({type:n("tool_reference"),tool_name:e()}))}),t({type:n("tool_search_tool_result_error"),error_code:e()})])})])),stop_reason:e().nullish(),stop_sequence:e().nullish(),usage:Pe({input_tokens:a(),output_tokens:a(),cache_creation_input_tokens:a().nullish(),cache_read_input_tokens:a().nullish()}),container:t({expires_at:e(),id:e(),skills:x(t({type:Q([n("anthropic"),n("custom")]),skill_id:e(),version:e()})).nullish()}).nullish(),context_management:t({applied_edits:x(Q([t({type:n("clear_tool_uses_20250919"),cleared_tool_uses:a(),cleared_input_tokens:a()}),t({type:n("clear_thinking_20251015"),cleared_thinking_turns:a(),cleared_input_tokens:a()})]))}).nullish()}))),co=P(()=>D(ae("type",[t({type:n("message_start"),message:t({id:e().nullish(),model:e().nullish(),role:e().nullish(),usage:Pe({input_tokens:a(),cache_creation_input_tokens:a().nullish(),cache_read_input_tokens:a().nullish()}),content:x(ae("type",[t({type:n("tool_use"),id:e(),name:e(),input:we(),caller:Q([t({type:n("code_execution_20250825"),tool_id:e()}),t({type:n("direct")})]).optional()})])).nullish(),stop_reason:e().nullish(),container:t({expires_at:e(),id:e()}).nullish()})}),t({type:n("content_block_start"),index:a(),content_block:ae("type",[t({type:n("text"),text:e()}),t({type:n("thinking"),thinking:e()}),t({type:n("tool_use"),id:e(),name:e(),input:ue(e(),we()).optional(),caller:Q([t({type:n("code_execution_20250825"),tool_id:e()}),t({type:n("direct")})]).optional()}),t({type:n("redacted_thinking"),data:e()}),t({type:n("server_tool_use"),id:e(),name:e(),input:ue(e(),we()).nullish()}),t({type:n("mcp_tool_use"),id:e(),name:e(),input:we(),server_name:e()}),t({type:n("mcp_tool_result"),tool_use_id:e(),is_error:ne(),content:x(Q([e(),t({type:n("text"),text:e()})]))}),t({type:n("web_fetch_tool_result"),tool_use_id:e(),content:Q([t({type:n("web_fetch_result"),url:e(),retrieved_at:e(),content:t({type:n("document"),title:e().nullable(),citations:t({enabled:ne()}).optional(),source:Q([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(),content:Q([x(t({type:n("web_search_result"),url:e(),title:e(),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:Q([t({type:n("code_execution_result"),stdout:e(),stderr:e(),return_code:a(),content:x(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:ae("type",[t({type:n("bash_code_execution_result"),content:x(t({type:n("bash_code_execution_output"),file_id:e()})),stdout:e(),stderr:e(),return_code:a()}),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:ae("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:a().nullable(),start_line:a().nullable(),total_lines:a().nullable()}),t({type:n("text_editor_code_execution_create_result"),is_file_update:ne()}),t({type:n("text_editor_code_execution_str_replace_result"),lines:x(e()).nullable(),new_lines:a().nullable(),new_start:a().nullable(),old_lines:a().nullable(),old_start:a().nullable()})])}),t({type:n("tool_search_tool_result"),tool_use_id:e(),content:Q([t({type:n("tool_search_tool_search_result"),tool_references:x(t({type:n("tool_reference"),tool_name:e()}))}),t({type:n("tool_search_tool_result_error"),error_code:e()})])})])}),t({type:n("content_block_delta"),index:a(),delta:ae("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("citations_delta"),citation:ae("type",[t({type:n("web_search_result_location"),cited_text:e(),url:e(),title:e(),encrypted_index:e()}),t({type:n("page_location"),cited_text:e(),document_index:a(),document_title:e().nullable(),start_page_number:a(),end_page_number:a()}),t({type:n("char_location"),cited_text:e(),document_index:a(),document_title:e().nullable(),start_char_index:a(),end_char_index:a()})])})])}),t({type:n("content_block_stop"),index:a()}),t({type:n("error"),error:t({type:e(),message:e()})}),t({type:n("message_delta"),delta:t({stop_reason:e().nullish(),stop_sequence:e().nullish(),container:t({expires_at:e(),id:e(),skills:x(t({type:Q([n("anthropic"),n("custom")]),skill_id:e(),version:e()})).nullish()}).nullish(),context_management:t({applied_edits:x(Q([t({type:n("clear_tool_uses_20250919"),cleared_tool_uses:a(),cleared_input_tokens:a()}),t({type:n("clear_thinking_20251015"),cleared_thinking_turns:a(),cleared_input_tokens:a()})]))}).nullish()}),usage:Pe({output_tokens:a(),cache_creation_input_tokens:a().nullish()})}),t({type:n("message_stop")}),t({type:n("ping")})]))),_o=P(()=>D(t({signature:e().optional(),redactedData:e().optional()}))),nt=t({citations:t({enabled:ne()}).optional(),title:e().optional(),context:e().optional()}),mo=t({sendReasoning:ne().optional(),structuredOutputMode:Y(["outputFormat","jsonTool","auto"]).optional(),thinking:t({type:Q([n("enabled"),n("disabled")]),budgetTokens:a().optional()}).optional(),disableParallelToolUse:ne().optional(),cacheControl:t({type:n("ephemeral"),ttl:Q([n("5m"),n("1h")]).optional()}).optional(),mcpServers:x(t({type:n("url"),name:e(),url:e(),authorizationToken:e().nullish(),toolConfiguration:t({enabled:ne().nullish(),allowedTools:x(e()).nullish()}).nullish()})).optional(),container:t({id:e().optional(),skills:x(t({type:Q([n("anthropic"),n("custom")]),skillId:e(),version:e().optional()})).optional()}).optional(),toolStreaming:ne().optional(),effort:Y(["low","medium","high"]).optional(),contextManagement:t({edits:x(ae("type",[t({type:n("clear_tool_uses_20250919"),trigger:ae("type",[t({type:n("input_tokens"),value:a()}),t({type:n("tool_uses"),value:a()})]).optional(),keep:t({type:n("tool_uses"),value:a()}).optional(),clearAtLeast:t({type:n("input_tokens"),value:a()}).optional(),clearToolInputs:ne().optional(),excludeTools:x(e()).optional()}),t({type:n("clear_thinking_20251015"),keep:Q([n("all"),t({type:n("thinking_turns"),value:a()})]).optional()})]))}).optional()}),at=4;function ho(o){var l;const s=o==null?void 0:o.anthropic;return(l=s==null?void 0:s.cacheControl)!=null?l:s==null?void 0:s.cache_control}var Be=class{constructor(){this.breakpointCount=0,this.warnings=[]}getCacheControl(o,l){const s=ho(o);if(s){if(!l.canCache){this.warnings.push({type:"unsupported",feature:"cache_control on non-cacheable context",details:`cache_control cannot be set on ${l.type}. It will be ignored.`});return}if(this.breakpointCount++,this.breakpointCount>at){this.warnings.push({type:"unsupported",feature:"cacheControl breakpoint limit",details:`Maximum ${at} cache breakpoints exceeded (found ${this.breakpointCount}). This breakpoint will be ignored.`});return}return s}}getWarnings(){return this.warnings}},go=P(()=>D(t({maxCharacters:a().optional()}))),fo=P(()=>D(t({command:Y(["view","create","str_replace","insert"]),path:e(),file_text:e().optional(),insert_line:a().int().optional(),new_str:e().optional(),old_str:e().optional(),view_range:x(a().int()).optional()}))),yo=ve({id:"anthropic.text_editor_20250728",inputSchema:fo}),vo=(o={})=>yo(o),bo=P(()=>D(t({maxUses:a().optional(),allowedDomains:x(e()).optional(),blockedDomains:x(e()).optional(),userLocation:t({type:n("approximate"),city:e().optional(),region:e().optional(),country:e().optional(),timezone:e().optional()}).optional()}))),Pt=P(()=>D(x(t({url:e(),title:e().nullable(),pageAge:e().nullable(),encryptedContent:e(),type:n("web_search_result")})))),xo=P(()=>D(t({query:e()}))),wo=ye({id:"anthropic.web_search_20250305",inputSchema:xo,outputSchema:Pt,supportsDeferredResults:!0}),ko=(o={})=>wo(o),Co=P(()=>D(t({maxUses:a().optional(),allowedDomains:x(e()).optional(),blockedDomains:x(e()).optional(),citations:t({enabled:ne()}).optional(),maxContentTokens:a().optional()}))),Dt=P(()=>D(t({type:n("web_fetch_result"),url:e(),content:t({type:n("document"),title:e().nullable(),citations:t({enabled:ne()}).optional(),source:Q([t({type:n("base64"),mediaType:n("application/pdf"),data:e()}),t({type:n("text"),mediaType:n("text/plain"),data:e()})])}),retrievedAt:e().nullable()}))),Io=P(()=>D(t({url:e()}))),To=ye({id:"anthropic.web_fetch_20250910",inputSchema:Io,outputSchema:Dt,supportsDeferredResults:!0}),So=(o={})=>To(o);async function No({tools:o,toolChoice:l,disableParallelToolUse:s,cacheControlValidator:p,supportsStructuredOutput:c}){var m;o=o!=null&&o.length?o:void 0;const u=[],d=new Set,b=p||new Be;if(o==null)return{tools:void 0,toolChoice:void 0,toolWarnings:u,betas:d};const _=[];for(const w of o)switch(w.type){case"function":{const y=b.getCacheControl(w.providerOptions,{type:"tool definition",canCache:!0}),g=(m=w.providerOptions)==null?void 0:m.anthropic,k=g==null?void 0:g.deferLoading,C=g==null?void 0:g.allowedCallers;_.push({name:w.name,description:w.description,input_schema:w.inputSchema,cache_control:y,...c===!0&&w.strict!=null?{strict:w.strict}:{},...k!=null?{defer_loading:k}:{},...C!=null?{allowed_callers:C}:{},...w.inputExamples!=null?{input_examples:w.inputExamples.map(f=>f.input)}:{}}),c===!0&&d.add("structured-outputs-2025-11-13"),(w.inputExamples!=null||C!=null)&&d.add("advanced-tool-use-2025-11-20");break}case"provider":{switch(w.id){case"anthropic.code_execution_20250522":{d.add("code-execution-2025-05-22"),_.push({type:"code_execution_20250522",name:"code_execution",cache_control:void 0});break}case"anthropic.code_execution_20250825":{d.add("code-execution-2025-08-25"),_.push({type:"code_execution_20250825",name:"code_execution"});break}case"anthropic.computer_20250124":{d.add("computer-use-2025-01-24"),_.push({name:"computer",type:"computer_20250124",display_width_px:w.args.displayWidthPx,display_height_px:w.args.displayHeightPx,display_number:w.args.displayNumber,cache_control:void 0});break}case"anthropic.computer_20241022":{d.add("computer-use-2024-10-22"),_.push({name:"computer",type:"computer_20241022",display_width_px:w.args.displayWidthPx,display_height_px:w.args.displayHeightPx,display_number:w.args.displayNumber,cache_control:void 0});break}case"anthropic.text_editor_20250124":{d.add("computer-use-2025-01-24"),_.push({name:"str_replace_editor",type:"text_editor_20250124",cache_control:void 0});break}case"anthropic.text_editor_20241022":{d.add("computer-use-2024-10-22"),_.push({name:"str_replace_editor",type:"text_editor_20241022",cache_control:void 0});break}case"anthropic.text_editor_20250429":{d.add("computer-use-2025-01-24"),_.push({name:"str_replace_based_edit_tool",type:"text_editor_20250429",cache_control:void 0});break}case"anthropic.text_editor_20250728":{const y=await ce({value:w.args,schema:go});_.push({name:"str_replace_based_edit_tool",type:"text_editor_20250728",max_characters:y.maxCharacters,cache_control:void 0});break}case"anthropic.bash_20250124":{d.add("computer-use-2025-01-24"),_.push({name:"bash",type:"bash_20250124",cache_control:void 0});break}case"anthropic.bash_20241022":{d.add("computer-use-2024-10-22"),_.push({name:"bash",type:"bash_20241022",cache_control:void 0});break}case"anthropic.memory_20250818":{d.add("context-management-2025-06-27"),_.push({name:"memory",type:"memory_20250818"});break}case"anthropic.web_fetch_20250910":{d.add("web-fetch-2025-09-10");const y=await ce({value:w.args,schema:Co});_.push({type:"web_fetch_20250910",name:"web_fetch",max_uses:y.maxUses,allowed_domains:y.allowedDomains,blocked_domains:y.blockedDomains,citations:y.citations,max_content_tokens:y.maxContentTokens,cache_control:void 0});break}case"anthropic.web_search_20250305":{const y=await ce({value:w.args,schema:bo});_.push({type:"web_search_20250305",name:"web_search",max_uses:y.maxUses,allowed_domains:y.allowedDomains,blocked_domains:y.blockedDomains,user_location:y.userLocation,cache_control:void 0});break}case"anthropic.tool_search_regex_20251119":{d.add("advanced-tool-use-2025-11-20"),_.push({type:"tool_search_tool_regex_20251119",name:"tool_search_tool_regex"});break}case"anthropic.tool_search_bm25_20251119":{d.add("advanced-tool-use-2025-11-20"),_.push({type:"tool_search_tool_bm25_20251119",name:"tool_search_tool_bm25"});break}default:{u.push({type:"unsupported",feature:`provider-defined tool ${w.id}`});break}}break}default:{u.push({type:"unsupported",feature:`tool ${w}`});break}}if(l==null)return{tools:_,toolChoice:s?{type:"auto",disable_parallel_tool_use:s}:void 0,toolWarnings:u,betas:d};const T=l.type;switch(T){case"auto":return{tools:_,toolChoice:{type:"auto",disable_parallel_tool_use:s},toolWarnings:u,betas:d};case"required":return{tools:_,toolChoice:{type:"any",disable_parallel_tool_use:s},toolWarnings:u,betas:d};case"none":return{tools:void 0,toolChoice:void 0,toolWarnings:u,betas:d};case"tool":return{tools:_,toolChoice:{type:"tool",name:l.toolName,disable_parallel_tool_use:s},toolWarnings:u,betas:d};default:{const w=T;throw new _e({functionality:`tool choice type: ${w}`})}}}function it(o){var l,s;const p=o.input_tokens,c=o.output_tokens,m=(l=o.cache_creation_input_tokens)!=null?l:0,u=(s=o.cache_read_input_tokens)!=null?s:0;return{inputTokens:{total:p+m+u,noCache:p,cacheRead:u,cacheWrite:m},outputTokens:{total:c,text:void 0,reasoning:void 0},raw:o}}var Ut=P(()=>D(t({type:n("code_execution_result"),stdout:e(),stderr:e(),return_code:a(),content:x(t({type:n("code_execution_output"),file_id:e()})).optional().default([])}))),Ro=P(()=>D(t({code:e()}))),Oo=ye({id:"anthropic.code_execution_20250522",inputSchema:Ro,outputSchema:Ut}),Mo=(o={})=>Oo(o),Lt=P(()=>D(ae("type",[t({type:n("code_execution_result"),stdout:e(),stderr:e(),return_code:a(),content:x(t({type:n("code_execution_output"),file_id:e()})).optional().default([])}),t({type:n("bash_code_execution_result"),content:x(t({type:n("bash_code_execution_output"),file_id:e()})),stdout:e(),stderr:e(),return_code:a()}),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:a().nullable(),start_line:a().nullable(),total_lines:a().nullable()}),t({type:n("text_editor_code_execution_create_result"),is_file_update:ne()}),t({type:n("text_editor_code_execution_str_replace_result"),lines:x(e()).nullable(),new_lines:a().nullable(),new_start:a().nullable(),old_lines:a().nullable(),old_start:a().nullable()})]))),Eo=P(()=>D(ae("type",[t({type:n("programmatic-tool-call"),code:e()}),t({type:n("bash_code_execution"),command:e()}),ae("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()})])]))),qo=ye({id:"anthropic.code_execution_20250825",inputSchema:Eo,outputSchema:Lt,supportsDeferredResults:!0}),Ao=(o={})=>qo(o),Ht=P(()=>D(x(t({type:n("tool_reference"),toolName:e()})))),$o=P(()=>D(t({pattern:e(),limit:a().optional()}))),Po=ye({id:"anthropic.tool_search_regex_20251119",inputSchema:$o,outputSchema:Ht}),Do=(o={})=>Po(o);function Uo(o){if(typeof o=="string")return Buffer.from(o,"base64").toString("utf-8");if(o instanceof Uint8Array)return new TextDecoder().decode(o);throw o instanceof URL?new _e({functionality:"URL-based text documents are not supported for citations"}):new _e({functionality:`unsupported data type for text documents: ${typeof o}`})}async function Lo({prompt:o,sendReasoning:l,warnings:s,cacheControlValidator:p,toolNameMapping:c}){var m,u,d,b,_,T,w,y,g,k,C,f,L,$,E;const X=new Set,q=Ho(o),i=p||new Be;let A;const ie=[];async function h(N){var S,G;const M=await me({provider:"anthropic",providerOptions:N,schema:nt});return(G=(S=M==null?void 0:M.citations)==null?void 0:S.enabled)!=null?G:!1}async function K(N){const S=await me({provider:"anthropic",providerOptions:N,schema:nt});return{title:S==null?void 0:S.title,context:S==null?void 0:S.context}}for(let N=0;N<q.length;N++){const S=q[N],G=N===q.length-1,M=S.type;switch(M){case"system":{if(A!=null)throw new _e({functionality:"Multiple system messages that are separated by user/assistant messages"});A=S.messages.map(({content:I,providerOptions:F})=>({type:"text",text:I,cache_control:i.getCacheControl(F,{type:"system message",canCache:!0})}));break}case"user":{const I=[];for(const F of S.messages){const{role:V,content:W}=F;switch(V){case"user":{for(let ee=0;ee<W.length;ee++){const H=W[ee],le=ee===W.length-1,R=(m=i.getCacheControl(H.providerOptions,{type:"user message part",canCache:!0}))!=null?m:le?i.getCacheControl(F.providerOptions,{type:"user message",canCache:!0}):void 0;switch(H.type){case"text":{I.push({type:"text",text:H.text,cache_control:R});break}case"file":{if(H.mediaType.startsWith("image/"))I.push({type:"image",source:H.data instanceof URL?{type:"url",url:H.data.toString()}:{type:"base64",media_type:H.mediaType==="image/*"?"image/jpeg":H.mediaType,data:Ie(H.data)},cache_control:R});else if(H.mediaType==="application/pdf"){X.add("pdfs-2024-09-25");const re=await h(H.providerOptions),z=await K(H.providerOptions);I.push({type:"document",source:H.data instanceof URL?{type:"url",url:H.data.toString()}:{type:"base64",media_type:"application/pdf",data:Ie(H.data)},title:(u=z.title)!=null?u:H.filename,...z.context&&{context:z.context},...re&&{citations:{enabled:!0}},cache_control:R})}else if(H.mediaType==="text/plain"){const re=await h(H.providerOptions),z=await K(H.providerOptions);I.push({type:"document",source:H.data instanceof URL?{type:"url",url:H.data.toString()}:{type:"text",media_type:"text/plain",data:Uo(H.data)},title:(d=z.title)!=null?d:H.filename,...z.context&&{context:z.context},...re&&{citations:{enabled:!0}},cache_control:R})}else throw new _e({functionality:`media type: ${H.mediaType}`});break}}}break}case"tool":{for(let ee=0;ee<W.length;ee++){const H=W[ee];if(H.type==="tool-approval-response")continue;const le=ee===W.length-1,R=(b=i.getCacheControl(H.providerOptions,{type:"tool result part",canCache:!0}))!=null?b:le?i.getCacheControl(F.providerOptions,{type:"tool result message",canCache:!0}):void 0,re=H.output;let z;switch(re.type){case"content":z=re.value.map(te=>{switch(te.type){case"text":return{type:"text",text:te.text};case"image-data":return{type:"image",source:{type:"base64",media_type:te.mediaType,data:te.data}};case"image-url":return{type:"image",source:{type:"url",url:te.url}};case"file-url":return{type:"document",source:{type:"url",url:te.url}};case"file-data":{if(te.mediaType==="application/pdf")return X.add("pdfs-2024-09-25"),{type:"document",source:{type:"base64",media_type:te.mediaType,data:te.data}};s.push({type:"other",message:`unsupported tool content part type: ${te.type} with media type: ${te.mediaType}`});return}default:{s.push({type:"other",message:`unsupported tool content part type: ${te.type}`});return}}}).filter(Mt);break;case"text":case"error-text":z=re.value;break;case"execution-denied":z=(_=re.reason)!=null?_:"Tool execution denied.";break;case"json":case"error-json":default:z=JSON.stringify(re.value);break}I.push({type:"tool_result",tool_use_id:H.toolCallId,content:z,is_error:re.type==="error-text"||re.type==="error-json"?!0:void 0,cache_control:R})}break}default:{const ee=V;throw new Error(`Unsupported role: ${ee}`)}}}ie.push({role:"user",content:I});break}case"assistant":{const I=[],F=new Set;for(let V=0;V<S.messages.length;V++){const W=S.messages[V],ee=V===S.messages.length-1,{content:H}=W;for(let le=0;le<H.length;le++){const R=H[le],re=le===H.length-1,z=(T=i.getCacheControl(R.providerOptions,{type:"assistant message part",canCache:!0}))!=null?T:re?i.getCacheControl(W.providerOptions,{type:"assistant message",canCache:!0}):void 0;switch(R.type){case"text":{I.push({type:"text",text:G&&ee&&re?R.text.trim():R.text,cache_control:z});break}case"reasoning":{if(l){const te=await me({provider:"anthropic",providerOptions:R.providerOptions,schema:_o});te!=null?te.signature!=null?(i.getCacheControl(R.providerOptions,{type:"thinking block",canCache:!1}),I.push({type:"thinking",thinking:R.text,signature:te.signature})):te.redactedData!=null?(i.getCacheControl(R.providerOptions,{type:"redacted thinking block",canCache:!1}),I.push({type:"redacted_thinking",data:te.redactedData})):s.push({type:"other",message:"unsupported reasoning metadata"}):s.push({type:"other",message:"unsupported reasoning metadata"})}else s.push({type:"other",message:"sending reasoning content is disabled for this model"});break}case"tool-call":{if(R.providerExecuted){const J=c.toProviderToolName(R.toolName);if(((y=(w=R.providerOptions)==null?void 0:w.anthropic)==null?void 0:y.type)==="mcp-tool-use"){F.add(R.toolCallId);const v=(k=(g=R.providerOptions)==null?void 0:g.anthropic)==null?void 0:k.serverName;if(v==null||typeof v!="string"){s.push({type:"other",message:"mcp tool use server name is required and must be a string"});break}I.push({type:"mcp_tool_use",id:R.toolCallId,name:R.toolName,input:R.input,server_name:v,cache_control:z})}else if(J==="code_execution"&&R.input!=null&&typeof R.input=="object"&&"type"in R.input&&typeof R.input.type=="string"&&(R.input.type==="bash_code_execution"||R.input.type==="text_editor_code_execution"))I.push({type:"server_tool_use",id:R.toolCallId,name:R.input.type,input:R.input,cache_control:z});else if(J==="code_execution"&&R.input!=null&&typeof R.input=="object"&&"type"in R.input&&R.input.type==="programmatic-tool-call"){const{type:v,...oe}=R.input;I.push({type:"server_tool_use",id:R.toolCallId,name:"code_execution",input:oe,cache_control:z})}else J==="code_execution"||J==="web_fetch"||J==="web_search"?I.push({type:"server_tool_use",id:R.toolCallId,name:J,input:R.input,cache_control:z}):J==="tool_search_tool_regex"||J==="tool_search_tool_bm25"?I.push({type:"server_tool_use",id:R.toolCallId,name:J,input:R.input,cache_control:z}):s.push({type:"other",message:`provider executed tool call for tool ${R.toolName} is not supported`});break}const te=(C=R.providerOptions)==null?void 0:C.anthropic,j=te!=null&&te.caller?te.caller.type==="code_execution_20250825"&&te.caller.toolId?{type:"code_execution_20250825",tool_id:te.caller.toolId}:te.caller.type==="direct"?{type:"direct"}:void 0:void 0;I.push({type:"tool_use",id:R.toolCallId,name:R.toolName,input:R.input,...j&&{caller:j},cache_control:z});break}case"tool-result":{const te=c.toProviderToolName(R.toolName);if(F.has(R.toolCallId)){const j=R.output;if(j.type!=="json"&&j.type!=="error-json"){s.push({type:"other",message:`provider executed tool result output type ${j.type} for tool ${R.toolName} is not supported`});break}I.push({type:"mcp_tool_result",tool_use_id:R.toolCallId,is_error:j.type==="error-json",content:j.value,cache_control:z})}else if(te==="code_execution"){const j=R.output;if(j.type==="error-text"||j.type==="error-json"){let J={};try{typeof j.value=="string"?J=JSON.parse(j.value):typeof j.value=="object"&&j.value!==null&&(J=j.value)}catch{}J.type==="code_execution_tool_result_error"?I.push({type:"code_execution_tool_result",tool_use_id:R.toolCallId,content:{type:"code_execution_tool_result_error",error_code:(f=J.errorCode)!=null?f:"unknown"},cache_control:z}):I.push({type:"bash_code_execution_tool_result",tool_use_id:R.toolCallId,cache_control:z,content:{type:"bash_code_execution_tool_result_error",error_code:(L=J.errorCode)!=null?L:"unknown"}});break}if(j.type!=="json"){s.push({type:"other",message:`provider executed tool result output type ${j.type} for tool ${R.toolName} is not supported`});break}if(j.value==null||typeof j.value!="object"||!("type"in j.value)||typeof j.value.type!="string"){s.push({type:"other",message:`provider executed tool result output value is not a valid code execution result for tool ${R.toolName}`});break}if(j.value.type==="code_execution_result"){const J=await ce({value:j.value,schema:Ut});I.push({type:"code_execution_tool_result",tool_use_id:R.toolCallId,content:{type:J.type,stdout:J.stdout,stderr:J.stderr,return_code:J.return_code,content:($=J.content)!=null?$:[]},cache_control:z})}else{const J=await ce({value:j.value,schema:Lt});J.type==="code_execution_result"?I.push({type:"code_execution_tool_result",tool_use_id:R.toolCallId,content:{type:J.type,stdout:J.stdout,stderr:J.stderr,return_code:J.return_code,content:(E=J.content)!=null?E:[]},cache_control:z}):J.type==="bash_code_execution_result"||J.type==="bash_code_execution_tool_result_error"?I.push({type:"bash_code_execution_tool_result",tool_use_id:R.toolCallId,cache_control:z,content:J}):I.push({type:"text_editor_code_execution_tool_result",tool_use_id:R.toolCallId,cache_control:z,content:J})}break}if(te==="web_fetch"){const j=R.output;if(j.type==="error-json"){const U=JSON.parse(j.value);I.push({type:"web_fetch_tool_result",tool_use_id:R.toolCallId,content:{type:"web_fetch_tool_result_error",error_code:U.errorCode},cache_control:z});break}if(j.type!=="json"){s.push({type:"other",message:`provider executed tool result output type ${j.type} for tool ${R.toolName} is not supported`});break}const J=await ce({value:j.value,schema:Dt});I.push({type:"web_fetch_tool_result",tool_use_id:R.toolCallId,content:{type:"web_fetch_result",url:J.url,retrieved_at:J.retrievedAt,content:{type:"document",title:J.content.title,citations:J.content.citations,source:{type:J.content.source.type,media_type:J.content.source.mediaType,data:J.content.source.data}}},cache_control:z});break}if(te==="web_search"){const j=R.output;if(j.type!=="json"){s.push({type:"other",message:`provider executed tool result output type ${j.type} for tool ${R.toolName} is not supported`});break}const J=await ce({value:j.value,schema:Pt});I.push({type:"web_search_tool_result",tool_use_id:R.toolCallId,content:J.map(U=>({url:U.url,title:U.title,page_age:U.pageAge,encrypted_content:U.encryptedContent,type:U.type})),cache_control:z});break}if(te==="tool_search_tool_regex"||te==="tool_search_tool_bm25"){const j=R.output;if(j.type!=="json"){s.push({type:"other",message:`provider executed tool result output type ${j.type} for tool ${R.toolName} is not supported`});break}const U=(await ce({value:j.value,schema:Ht})).map(v=>({type:"tool_reference",tool_name:v.toolName}));I.push({type:"tool_search_tool_result",tool_use_id:R.toolCallId,content:{type:"tool_search_tool_search_result",tool_references:U},cache_control:z});break}s.push({type:"other",message:`provider executed tool result for tool ${R.toolName} is not supported`});break}}}}ie.push({role:"assistant",content:I});break}default:{const I=M;throw new Error(`content type: ${I}`)}}}return{prompt:{system:A,messages:ie},betas:X}}function Ho(o){const l=[];let s;for(const p of o){const{role:c}=p;switch(c){case"system":{(s==null?void 0:s.type)!=="system"&&(s={type:"system",messages:[]},l.push(s)),s.messages.push(p);break}case"assistant":{(s==null?void 0:s.type)!=="assistant"&&(s={type:"assistant",messages:[]},l.push(s)),s.messages.push(p);break}case"user":{(s==null?void 0:s.type)!=="user"&&(s={type:"user",messages:[]},l.push(s)),s.messages.push(p);break}case"tool":{(s==null?void 0:s.type)!=="user"&&(s={type:"user",messages:[]},l.push(s)),s.messages.push(p);break}default:{const m=c;throw new Error(`Unsupported role: ${m}`)}}}return l}function Ae({finishReason:o,isJsonResponseFromTool:l}){switch(o){case"pause_turn":case"end_turn":case"stop_sequence":return"stop";case"refusal":return"content-filter";case"tool_use":return l?"stop":"tool-calls";case"max_tokens":case"model_context_window_exceeded":return"length";default:return"other"}}function lt(o,l,s){var p;if(o.type!=="page_location"&&o.type!=="char_location")return;const c=l[o.document_index];if(c)return{type:"source",sourceType:"document",id:s(),mediaType:c.mediaType,title:(p=o.document_title)!=null?p:c.title,filename:c.filename,providerMetadata:{anthropic:o.type==="page_location"?{citedText:o.cited_text,startPageNumber:o.start_page_number,endPageNumber:o.end_page_number}:{citedText:o.cited_text,startCharIndex:o.start_char_index,endCharIndex:o.end_char_index}}}}var jo=class{constructor(o,l){this.specificationVersion="v3";var s;this.modelId=o,this.config=l,this.generateId=(s=l.generateId)!=null?s:pe}supportsUrl(o){return o.protocol==="https:"}get provider(){return this.config.provider}get supportedUrls(){var o,l,s;return(s=(l=(o=this.config).supportedUrls)==null?void 0:l.call(o))!=null?s:{}}async getArgs({userSuppliedBetas:o,prompt:l,maxOutputTokens:s,temperature:p,topP:c,topK:m,frequencyPenalty:u,presencePenalty:d,stopSequences:b,responseFormat:_,seed:T,tools:w,toolChoice:y,providerOptions:g,stream:k}){var C,f,L,$,E,X;const q=[];u!=null&&q.push({type:"unsupported",feature:"frequencyPenalty"}),d!=null&&q.push({type:"unsupported",feature:"presencePenalty"}),T!=null&&q.push({type:"unsupported",feature:"seed"}),p!=null&&p>1?(q.push({type:"unsupported",feature:"temperature",details:`${p} exceeds anthropic maximum of 1.0. clamped to 1.0`}),p=1):p!=null&&p<0&&(q.push({type:"unsupported",feature:"temperature",details:`${p} is below anthropic minimum of 0. clamped to 0`}),p=0),(_==null?void 0:_.type)==="json"&&_.schema==null&&q.push({type:"unsupported",feature:"responseFormat",details:"JSON response format requires a schema. The response format is ignored."});const i=await me({provider:"anthropic",providerOptions:g,schema:mo}),{maxOutputTokens:A,supportsStructuredOutput:ie,isKnownModel:h}=Go(this.modelId),K=((C=this.config.supportsNativeStructuredOutput)!=null?C:!0)&&ie,N=(f=i==null?void 0:i.structuredOutputMode)!=null?f:"auto",S=N==="outputFormat"||N==="auto"&&K,G=(_==null?void 0:_.type)==="json"&&_.schema!=null&&!S?{type:"function",name:"json",description:"Respond with a JSON object.",inputSchema:_.schema}:void 0,M=i==null?void 0:i.contextManagement,I=new Be,F=Rt({tools:w,providerToolNames:{"anthropic.code_execution_20250522":"code_execution","anthropic.code_execution_20250825":"code_execution","anthropic.computer_20241022":"computer","anthropic.computer_20250124":"computer","anthropic.text_editor_20241022":"str_replace_editor","anthropic.text_editor_20250124":"str_replace_editor","anthropic.text_editor_20250429":"str_replace_based_edit_tool","anthropic.text_editor_20250728":"str_replace_based_edit_tool","anthropic.bash_20241022":"bash","anthropic.bash_20250124":"bash","anthropic.memory_20250818":"memory","anthropic.web_search_20250305":"web_search","anthropic.web_fetch_20250910":"web_fetch","anthropic.tool_search_regex_20251119":"tool_search_tool_regex","anthropic.tool_search_bm25_20251119":"tool_search_tool_bm25"}}),{prompt:V,betas:W}=await Lo({prompt:l,sendReasoning:(L=i==null?void 0:i.sendReasoning)!=null?L:!0,warnings:q,cacheControlValidator:I,toolNameMapping:F}),ee=(($=i==null?void 0:i.thinking)==null?void 0:$.type)==="enabled";let H=(E=i==null?void 0:i.thinking)==null?void 0:E.budgetTokens;const le=s??A,R={model:this.modelId,max_tokens:le,temperature:p,top_k:m,top_p:c,stop_sequences:b,...ee&&{thinking:{type:"enabled",budget_tokens:H}},...(i==null?void 0:i.effort)&&{output_config:{effort:i.effort}},...S&&(_==null?void 0:_.type)==="json"&&_.schema!=null&&{output_format:{type:"json_schema",schema:_.schema}},...(i==null?void 0:i.mcpServers)&&i.mcpServers.length>0&&{mcp_servers:i.mcpServers.map(v=>({type:v.type,name:v.name,url:v.url,authorization_token:v.authorizationToken,tool_configuration:v.toolConfiguration?{allowed_tools:v.toolConfiguration.allowedTools,enabled:v.toolConfiguration.enabled}:void 0}))},...(i==null?void 0:i.container)&&{container:i.container.skills&&i.container.skills.length>0?{id:i.container.id,skills:i.container.skills.map(v=>({type:v.type,skill_id:v.skillId,version:v.version}))}:i.container.id},system:V.system,messages:V.messages,...M&&{context_management:{edits:M.edits.map(v=>{const oe=v.type;switch(oe){case"clear_tool_uses_20250919":return{type:v.type,...v.trigger!==void 0&&{trigger:v.trigger},...v.keep!==void 0&&{keep:v.keep},...v.clearAtLeast!==void 0&&{clear_at_least:v.clearAtLeast},...v.clearToolInputs!==void 0&&{clear_tool_inputs:v.clearToolInputs},...v.excludeTools!==void 0&&{exclude_tools:v.excludeTools}};case"clear_thinking_20251015":return{type:v.type,...v.keep!==void 0&&{keep:v.keep}};default:q.push({type:"other",message:`Unknown context management strategy: ${oe}`});return}}).filter(v=>v!==void 0)}}};ee?(H==null&&(q.push({type:"compatibility",feature:"extended thinking",details:"thinking budget is required when thinking is enabled. using default budget of 1024 tokens."}),R.thinking={type:"enabled",budget_tokens:1024},H=1024),R.temperature!=null&&(R.temperature=void 0,q.push({type:"unsupported",feature:"temperature",details:"temperature is not supported when thinking is enabled"})),m!=null&&(R.top_k=void 0,q.push({type:"unsupported",feature:"topK",details:"topK is not supported when thinking is enabled"})),c!=null&&(R.top_p=void 0,q.push({type:"unsupported",feature:"topP",details:"topP is not supported when thinking is enabled"})),R.max_tokens=le+(H??0)):c!=null&&p!=null&&(q.push({type:"unsupported",feature:"topP",details:"topP is not supported when temperature is set. topP is ignored."}),R.top_p=void 0),h&&R.max_tokens>A&&(s!=null&&q.push({type:"unsupported",feature:"maxOutputTokens",details:`${R.max_tokens} (maxOutputTokens + thinkingBudget) is greater than ${this.modelId} ${A} max output tokens. The max output tokens have been limited to ${A}.`}),R.max_tokens=A),i!=null&&i.mcpServers&&i.mcpServers.length>0&&W.add("mcp-client-2025-04-04"),M&&W.add("context-management-2025-06-27"),i!=null&&i.container&&i.container.skills&&i.container.skills.length>0&&(W.add("code-execution-2025-08-25"),W.add("skills-2025-10-02"),W.add("files-api-2025-04-14"),w!=null&&w.some(v=>v.type==="provider"&&v.id==="anthropic.code_execution_20250825")||q.push({type:"other",message:"code execution tool is required when using skills"})),i!=null&&i.effort&&W.add("effort-2025-11-24"),k&&((X=i==null?void 0:i.toolStreaming)==null||X)&&W.add("fine-grained-tool-streaming-2025-05-14"),S&&(_==null?void 0:_.type)==="json"&&_.schema!=null&&W.add("structured-outputs-2025-11-13");const{tools:z,toolChoice:te,toolWarnings:j,betas:J}=await No(G!=null?{tools:[...w??[],G],toolChoice:{type:"required"},disableParallelToolUse:!0,cacheControlValidator:I,supportsStructuredOutput:K}:{tools:w??[],toolChoice:y,disableParallelToolUse:i==null?void 0:i.disableParallelToolUse,cacheControlValidator:I,supportsStructuredOutput:K}),U=I.getWarnings();return{args:{...R,tools:z,tool_choice:te,stream:k===!0?!0:void 0},warnings:[...q,...j,...U],betas:new Set([...W,...J,...o]),usesJsonResponseTool:G!=null,toolNameMapping:F}}async getHeaders({betas:o,headers:l}){return ge(await Se(this.config.headers),l,o.size>0?{"anthropic-beta":Array.from(o).join(",")}:{})}async getBetasFromHeaders(o){var l,s;const c=(l=(await Se(this.config.headers))["anthropic-beta"])!=null?l:"",m=(s=o==null?void 0:o["anthropic-beta"])!=null?s:"";return new Set([...c.toLowerCase().split(","),...m.toLowerCase().split(",")].map(u=>u.trim()).filter(u=>u!==""))}buildRequestUrl(o){var l,s,p;return(p=(s=(l=this.config).buildRequestUrl)==null?void 0:s.call(l,this.config.baseURL,o))!=null?p:`${this.config.baseURL}/messages`}transformRequestBody(o){var l,s,p;return(p=(s=(l=this.config).transformRequestBody)==null?void 0:s.call(l,o))!=null?p:o}extractCitationDocuments(o){const l=s=>{var p,c;if(s.type!=="file"||s.mediaType!=="application/pdf"&&s.mediaType!=="text/plain")return!1;const m=(p=s.providerOptions)==null?void 0:p.anthropic,u=m==null?void 0:m.citations;return(c=u==null?void 0:u.enabled)!=null?c:!1};return o.filter(s=>s.role==="user").flatMap(s=>s.content).filter(l).map(s=>{var p;const c=s;return{title:(p=c.filename)!=null?p:"Untitled Document",filename:c.filename,mediaType:c.mediaType}})}async doGenerate(o){var l,s,p,c,m,u,d,b,_,T,w;const{args:y,warnings:g,betas:k,usesJsonResponseTool:C,toolNameMapping:f}=await this.getArgs({...o,stream:!1,userSuppliedBetas:await this.getBetasFromHeaders(o.headers)}),L=this.extractCitationDocuments(o.prompt),{responseHeaders:$,value:E,rawValue:X}=await fe({url:this.buildRequestUrl(!1),headers:await this.getHeaders({betas:k,headers:o.headers}),body:this.transformRequestBody(y),failedResponseHandler:ot,successfulResponseHandler:be(po),abortSignal:o.abortSignal,fetch:this.config.fetch}),q=[],i={},A={};let ie=!1;for(const h of E.content)switch(h.type){case"text":{if(!C&&(q.push({type:"text",text:h.text}),h.citations))for(const K of h.citations){const N=lt(K,L,this.generateId);N&&q.push(N)}break}case"thinking":{q.push({type:"reasoning",text:h.thinking,providerMetadata:{anthropic:{signature:h.signature}}});break}case"redacted_thinking":{q.push({type:"reasoning",text:"",providerMetadata:{anthropic:{redactedData:h.data}}});break}case"tool_use":{if(C&&h.name==="json")ie=!0,q.push({type:"text",text:JSON.stringify(h.input)});else{const N=h.caller,S=N?{type:N.type,toolId:"tool_id"in N?N.tool_id:void 0}:void 0;q.push({type:"tool-call",toolCallId:h.id,toolName:h.name,input:JSON.stringify(h.input),...S&&{providerMetadata:{anthropic:{caller:S}}}})}break}case"server_tool_use":{if(h.name==="text_editor_code_execution"||h.name==="bash_code_execution")q.push({type:"tool-call",toolCallId:h.id,toolName:f.toCustomToolName("code_execution"),input:JSON.stringify({type:h.name,...h.input}),providerExecuted:!0});else if(h.name==="web_search"||h.name==="code_execution"||h.name==="web_fetch"){const K=h.name==="code_execution"&&h.input!=null&&typeof h.input=="object"&&"code"in h.input&&!("type"in h.input)?{type:"programmatic-tool-call",...h.input}:h.input;q.push({type:"tool-call",toolCallId:h.id,toolName:f.toCustomToolName(h.name),input:JSON.stringify(K),providerExecuted:!0})}else(h.name==="tool_search_tool_regex"||h.name==="tool_search_tool_bm25")&&(A[h.id]=h.name,q.push({type:"tool-call",toolCallId:h.id,toolName:f.toCustomToolName(h.name),input:JSON.stringify(h.input),providerExecuted:!0}));break}case"mcp_tool_use":{i[h.id]={type:"tool-call",toolCallId:h.id,toolName:h.name,input:JSON.stringify(h.input),providerExecuted:!0,dynamic:!0,providerMetadata:{anthropic:{type:"mcp-tool-use",serverName:h.server_name}}},q.push(i[h.id]);break}case"mcp_tool_result":{q.push({type:"tool-result",toolCallId:h.tool_use_id,toolName:i[h.tool_use_id].toolName,isError:h.is_error,result:h.content,dynamic:!0,providerMetadata:i[h.tool_use_id].providerMetadata});break}case"web_fetch_tool_result":{h.content.type==="web_fetch_result"?q.push({type:"tool-result",toolCallId:h.tool_use_id,toolName:f.toCustomToolName("web_fetch"),result:{type:"web_fetch_result",url:h.content.url,retrievedAt:h.content.retrieved_at,content:{type:h.content.content.type,title:h.content.content.title,citations:h.content.content.citations,source:{type:h.content.content.source.type,mediaType:h.content.content.source.media_type,data:h.content.content.source.data}}}}):h.content.type==="web_fetch_tool_result_error"&&q.push({type:"tool-result",toolCallId:h.tool_use_id,toolName:f.toCustomToolName("web_fetch"),isError:!0,result:{type:"web_fetch_tool_result_error",errorCode:h.content.error_code}});break}case"web_search_tool_result":{if(Array.isArray(h.content)){q.push({type:"tool-result",toolCallId:h.tool_use_id,toolName:f.toCustomToolName("web_search"),result:h.content.map(K=>{var N;return{url:K.url,title:K.title,pageAge:(N=K.page_age)!=null?N:null,encryptedContent:K.encrypted_content,type:K.type}})});for(const K of h.content)q.push({type:"source",sourceType:"url",id:this.generateId(),url:K.url,title:K.title,providerMetadata:{anthropic:{pageAge:(l=K.page_age)!=null?l:null}}})}else q.push({type:"tool-result",toolCallId:h.tool_use_id,toolName:f.toCustomToolName("web_search"),isError:!0,result:{type:"web_search_tool_result_error",errorCode:h.content.error_code}});break}case"code_execution_tool_result":{h.content.type==="code_execution_result"?q.push({type:"tool-result",toolCallId:h.tool_use_id,toolName:f.toCustomToolName("code_execution"),result:{type:h.content.type,stdout:h.content.stdout,stderr:h.content.stderr,return_code:h.content.return_code,content:(s=h.content.content)!=null?s:[]}}):h.content.type==="code_execution_tool_result_error"&&q.push({type:"tool-result",toolCallId:h.tool_use_id,toolName:f.toCustomToolName("code_execution"),isError:!0,result:{type:"code_execution_tool_result_error",errorCode:h.content.error_code}});break}case"bash_code_execution_tool_result":case"text_editor_code_execution_tool_result":{q.push({type:"tool-result",toolCallId:h.tool_use_id,toolName:f.toCustomToolName("code_execution"),result:h.content});break}case"tool_search_tool_result":{const K=(p=A[h.tool_use_id])!=null?p:"tool_search_tool_regex";h.content.type==="tool_search_tool_search_result"?q.push({type:"tool-result",toolCallId:h.tool_use_id,toolName:f.toCustomToolName(K),result:h.content.tool_references.map(N=>({type:N.type,toolName:N.tool_name}))}):q.push({type:"tool-result",toolCallId:h.tool_use_id,toolName:f.toCustomToolName(K),isError:!0,result:{type:"tool_search_tool_result_error",errorCode:h.content.error_code}});break}}return{content:q,finishReason:{unified:Ae({finishReason:E.stop_reason,isJsonResponseFromTool:ie}),raw:(c=E.stop_reason)!=null?c:void 0},usage:it(E.usage),request:{body:y},response:{id:(m=E.id)!=null?m:void 0,modelId:(u=E.model)!=null?u:void 0,headers:$,body:X},warnings:g,providerMetadata:{anthropic:{usage:E.usage,cacheCreationInputTokens:(d=E.usage.cache_creation_input_tokens)!=null?d:null,stopSequence:(b=E.stop_sequence)!=null?b:null,container:E.container?{expiresAt:E.container.expires_at,id:E.container.id,skills:(T=(_=E.container.skills)==null?void 0:_.map(h=>({type:h.type,skillId:h.skill_id,version:h.version})))!=null?T:null}:null,contextManagement:(w=st(E.context_management))!=null?w:null}}}}async doStream(o){var l,s;const{args:p,warnings:c,betas:m,usesJsonResponseTool:u,toolNameMapping:d}=await this.getArgs({...o,stream:!0,userSuppliedBetas:await this.getBetasFromHeaders(o.headers)}),b=this.extractCitationDocuments(o.prompt),_=this.buildRequestUrl(!0),{responseHeaders:T,value:w}=await fe({url:_,headers:await this.getHeaders({betas:m,headers:o.headers}),body:this.transformRequestBody(p),failedResponseHandler:ot,successfulResponseHandler:Oe(co),abortSignal:o.abortSignal,fetch:this.config.fetch});let y={unified:"other",raw:void 0};const g={input_tokens:0,output_tokens:0,cache_creation_input_tokens:0,cache_read_input_tokens:0},k={},C={},f={};let L=null,$,E=null,X=null,q=null,i=!1,A;const ie=this.generateId,h=w.pipeThrough(new TransformStream({start(G){G.enqueue({type:"stream-start",warnings:c})},transform(G,M){var I,F,V,W,ee,H,le,R,re,z,te,j,J;if(o.includeRawChunks&&M.enqueue({type:"raw",rawValue:G.rawValue}),!G.success){M.enqueue({type:"error",error:G.error});return}const U=G.value;switch(U.type){case"ping":return;case"content_block_start":{const v=U.content_block,oe=v.type;switch(A=oe,oe){case"text":{if(u)return;k[U.index]={type:"text"},M.enqueue({type:"text-start",id:String(U.index)});return}case"thinking":{k[U.index]={type:"reasoning"},M.enqueue({type:"reasoning-start",id:String(U.index)});return}case"redacted_thinking":{k[U.index]={type:"reasoning"},M.enqueue({type:"reasoning-start",id:String(U.index),providerMetadata:{anthropic:{redactedData:v.data}}});return}case"tool_use":{if(u&&v.name==="json")i=!0,k[U.index]={type:"text"},M.enqueue({type:"text-start",id:String(U.index)});else{const Z=v.caller,he=Z?{type:Z.type,toolId:"tool_id"in Z?Z.tool_id:void 0}:void 0,Ne=v.input&&Object.keys(v.input).length>0?JSON.stringify(v.input):"";k[U.index]={type:"tool-call",toolCallId:v.id,toolName:v.name,input:Ne,firstDelta:Ne.length===0,...he&&{caller:he}},M.enqueue({type:"tool-input-start",id:v.id,toolName:v.name})}return}case"server_tool_use":{if(["web_fetch","web_search","code_execution","text_editor_code_execution","bash_code_execution"].includes(v.name)){const O=v.name==="text_editor_code_execution"||v.name==="bash_code_execution"?"code_execution":v.name,Z=d.toCustomToolName(O);k[U.index]={type:"tool-call",toolCallId:v.id,toolName:Z,input:"",providerExecuted:!0,firstDelta:!0,providerToolName:v.name},M.enqueue({type:"tool-input-start",id:v.id,toolName:Z,providerExecuted:!0})}else if(v.name==="tool_search_tool_regex"||v.name==="tool_search_tool_bm25"){f[v.id]=v.name;const O=d.toCustomToolName(v.name);k[U.index]={type:"tool-call",toolCallId:v.id,toolName:O,input:"",providerExecuted:!0,firstDelta:!0,providerToolName:v.name},M.enqueue({type:"tool-input-start",id:v.id,toolName:O,providerExecuted:!0})}return}case"web_fetch_tool_result":{v.content.type==="web_fetch_result"?M.enqueue({type:"tool-result",toolCallId:v.tool_use_id,toolName:d.toCustomToolName("web_fetch"),result:{type:"web_fetch_result",url:v.content.url,retrievedAt:v.content.retrieved_at,content:{type:v.content.content.type,title:v.content.content.title,citations:v.content.content.citations,source:{type:v.content.content.source.type,mediaType:v.content.content.source.media_type,data:v.content.content.source.data}}}}):v.content.type==="web_fetch_tool_result_error"&&M.enqueue({type:"tool-result",toolCallId:v.tool_use_id,toolName:d.toCustomToolName("web_fetch"),isError:!0,result:{type:"web_fetch_tool_result_error",errorCode:v.content.error_code}});return}case"web_search_tool_result":{if(Array.isArray(v.content)){M.enqueue({type:"tool-result",toolCallId:v.tool_use_id,toolName:d.toCustomToolName("web_search"),result:v.content.map(O=>{var Z;return{url:O.url,title:O.title,pageAge:(Z=O.page_age)!=null?Z:null,encryptedContent:O.encrypted_content,type:O.type}})});for(const O of v.content)M.enqueue({type:"source",sourceType:"url",id:ie(),url:O.url,title:O.title,providerMetadata:{anthropic:{pageAge:(I=O.page_age)!=null?I:null}}})}else M.enqueue({type:"tool-result",toolCallId:v.tool_use_id,toolName:d.toCustomToolName("web_search"),isError:!0,result:{type:"web_search_tool_result_error",errorCode:v.content.error_code}});return}case"code_execution_tool_result":{v.content.type==="code_execution_result"?M.enqueue({type:"tool-result",toolCallId:v.tool_use_id,toolName:d.toCustomToolName("code_execution"),result:{type:v.content.type,stdout:v.content.stdout,stderr:v.content.stderr,return_code:v.content.return_code,content:(F=v.content.content)!=null?F:[]}}):v.content.type==="code_execution_tool_result_error"&&M.enqueue({type:"tool-result",toolCallId:v.tool_use_id,toolName:d.toCustomToolName("code_execution"),isError:!0,result:{type:"code_execution_tool_result_error",errorCode:v.content.error_code}});return}case"bash_code_execution_tool_result":case"text_editor_code_execution_tool_result":{M.enqueue({type:"tool-result",toolCallId:v.tool_use_id,toolName:d.toCustomToolName("code_execution"),result:v.content});return}case"tool_search_tool_result":{const O=(V=f[v.tool_use_id])!=null?V:"tool_search_tool_regex";v.content.type==="tool_search_tool_search_result"?M.enqueue({type:"tool-result",toolCallId:v.tool_use_id,toolName:d.toCustomToolName(O),result:v.content.tool_references.map(Z=>({type:Z.type,toolName:Z.tool_name}))}):M.enqueue({type:"tool-result",toolCallId:v.tool_use_id,toolName:d.toCustomToolName(O),isError:!0,result:{type:"tool_search_tool_result_error",errorCode:v.content.error_code}});return}case"mcp_tool_use":{C[v.id]={type:"tool-call",toolCallId:v.id,toolName:v.name,input:JSON.stringify(v.input),providerExecuted:!0,dynamic:!0,providerMetadata:{anthropic:{type:"mcp-tool-use",serverName:v.server_name}}},M.enqueue(C[v.id]);return}case"mcp_tool_result":{M.enqueue({type:"tool-result",toolCallId:v.tool_use_id,toolName:C[v.tool_use_id].toolName,isError:v.is_error,result:v.content,dynamic:!0,providerMetadata:C[v.tool_use_id].providerMetadata});return}default:{const O=oe;throw new Error(`Unsupported content block type: ${O}`)}}}case"content_block_stop":{if(k[U.index]!=null){const v=k[U.index];switch(v.type){case"text":{M.enqueue({type:"text-end",id:String(U.index)});break}case"reasoning":{M.enqueue({type:"reasoning-end",id:String(U.index)});break}case"tool-call":if(!(u&&v.toolName==="json")){M.enqueue({type:"tool-input-end",id:v.toolCallId});let O=v.input===""?"{}":v.input;if(v.providerToolName==="code_execution")try{const Z=JSON.parse(O);Z!=null&&typeof Z=="object"&&"code"in Z&&!("type"in Z)&&(O=JSON.stringify({type:"programmatic-tool-call",...Z}))}catch{}M.enqueue({type:"tool-call",toolCallId:v.toolCallId,toolName:v.toolName,input:O,providerExecuted:v.providerExecuted,...v.caller&&{providerMetadata:{anthropic:{caller:v.caller}}}})}break}delete k[U.index]}A=void 0;return}case"content_block_delta":{const v=U.delta.type;switch(v){case"text_delta":{if(u)return;M.enqueue({type:"text-delta",id:String(U.index),delta:U.delta.text});return}case"thinking_delta":{M.enqueue({type:"reasoning-delta",id:String(U.index),delta:U.delta.thinking});return}case"signature_delta":{A==="thinking"&&M.enqueue({type:"reasoning-delta",id:String(U.index),delta:"",providerMetadata:{anthropic:{signature:U.delta.signature}}});return}case"input_json_delta":{const oe=k[U.index];let O=U.delta.partial_json;if(O.length===0)return;if(i){if((oe==null?void 0:oe.type)!=="text")return;M.enqueue({type:"text-delta",id:String(U.index),delta:O})}else{if((oe==null?void 0:oe.type)!=="tool-call")return;oe.firstDelta&&(oe.providerToolName==="bash_code_execution"||oe.providerToolName==="text_editor_code_execution")&&(O=`{"type": "${oe.providerToolName}",${O.substring(1)}`),M.enqueue({type:"tool-input-delta",id:oe.toolCallId,delta:O}),oe.input+=O,oe.firstDelta=!1}return}case"citations_delta":{const oe=U.delta.citation,O=lt(oe,b,ie);O&&M.enqueue(O);return}default:{const oe=v;throw new Error(`Unsupported delta type: ${oe}`)}}}case"message_start":{if(g.input_tokens=U.message.usage.input_tokens,g.cache_read_input_tokens=(W=U.message.usage.cache_read_input_tokens)!=null?W:0,g.cache_creation_input_tokens=(ee=U.message.usage.cache_creation_input_tokens)!=null?ee:0,$={...U.message.usage},E=(H=U.message.usage.cache_creation_input_tokens)!=null?H:null,U.message.container!=null&&(q={expiresAt:U.message.container.expires_at,id:U.message.container.id,skills:null}),U.message.stop_reason!=null&&(y={unified:Ae({finishReason:U.message.stop_reason,isJsonResponseFromTool:i}),raw:U.message.stop_reason}),M.enqueue({type:"response-metadata",id:(le=U.message.id)!=null?le:void 0,modelId:(R=U.message.model)!=null?R:void 0}),U.message.content!=null)for(let v=0;v<U.message.content.length;v++){const oe=U.message.content[v];if(oe.type==="tool_use"){const O=oe.caller,Z=O?{type:O.type,toolId:"tool_id"in O?O.tool_id:void 0}:void 0;M.enqueue({type:"tool-input-start",id:oe.id,toolName:oe.name});const he=JSON.stringify((re=oe.input)!=null?re:{});M.enqueue({type:"tool-input-delta",id:oe.id,delta:he}),M.enqueue({type:"tool-input-end",id:oe.id}),M.enqueue({type:"tool-call",toolCallId:oe.id,toolName:oe.name,input:he,...Z&&{providerMetadata:{anthropic:{caller:Z}}}})}}return}case"message_delta":{g.output_tokens=U.usage.output_tokens,y={unified:Ae({finishReason:U.delta.stop_reason,isJsonResponseFromTool:i}),raw:(z=U.delta.stop_reason)!=null?z:void 0},X=(te=U.delta.stop_sequence)!=null?te:null,q=U.delta.container!=null?{expiresAt:U.delta.container.expires_at,id:U.delta.container.id,skills:(J=(j=U.delta.container.skills)==null?void 0:j.map(v=>({type:v.type,skillId:v.skill_id,version:v.version})))!=null?J:null}:null,U.delta.context_management&&(L=st(U.delta.context_management)),$={...$,...U.usage};return}case"message_stop":{M.enqueue({type:"finish",finishReason:y,usage:it(g),providerMetadata:{anthropic:{usage:$??null,cacheCreationInputTokens:E,stopSequence:X,container:q,contextManagement:L}}});return}case"error":{M.enqueue({type:"error",error:U.error});return}default:{const v=U;throw new Error(`Unsupported chunk type: ${v}`)}}}})),[K,N]=h.tee(),S=K.getReader();try{await S.read();let G=await S.read();if(((l=G.value)==null?void 0:l.type)==="raw"&&(G=await S.read()),((s=G.value)==null?void 0:s.type)==="error"){const M=G.value.error;throw new Ot({message:M.message,url:_,requestBodyValues:p,statusCode:M.type==="overloaded_error"?529:500,responseHeaders:T,responseBody:JSON.stringify(M),isRetryable:M.type==="overloaded_error"})}}finally{S.cancel().catch(()=>{}),S.releaseLock()}return{stream:N,request:{body:p},response:{headers:T}}}};function Go(o){return o.includes("claude-sonnet-4-5")||o.includes("claude-opus-4-5")||o.includes("claude-haiku-4-5")?{maxOutputTokens:64e3,supportsStructuredOutput:!0,isKnownModel:!0}:o.includes("claude-opus-4-1")?{maxOutputTokens:32e3,supportsStructuredOutput:!0,isKnownModel:!0}:o.includes("claude-sonnet-4-")||o.includes("claude-3-7-sonnet")?{maxOutputTokens:64e3,supportsStructuredOutput:!1,isKnownModel:!0}:o.includes("claude-opus-4-")?{maxOutputTokens:32e3,supportsStructuredOutput:!1,isKnownModel:!0}:o.includes("claude-3-5-haiku")?{maxOutputTokens:8192,supportsStructuredOutput:!1,isKnownModel:!0}:o.includes("claude-3-haiku")?{maxOutputTokens:4096,supportsStructuredOutput:!1,isKnownModel:!0}:{maxOutputTokens:4096,supportsStructuredOutput:!1,isKnownModel:!1}}function st(o){return o?{appliedEdits:o.applied_edits.map(l=>{switch(l.type){case"clear_tool_uses_20250919":return{type:l.type,clearedToolUses:l.cleared_tool_uses,clearedInputTokens:l.cleared_input_tokens};case"clear_thinking_20251015":return{type:l.type,clearedThinkingTurns:l.cleared_thinking_turns,clearedInputTokens:l.cleared_input_tokens}}}).filter(l=>l!==void 0)}:null}var Vo=P(()=>D(t({command:e(),restart:ne().optional()}))),Bo=ve({id:"anthropic.bash_20241022",inputSchema:Vo}),Wo=P(()=>D(t({command:e(),restart:ne().optional()}))),Fo=ve({id:"anthropic.bash_20250124",inputSchema:Wo}),Jo=P(()=>D(t({action:Y(["key","type","mouse_move","left_click","left_click_drag","right_click","middle_click","double_click","screenshot","cursor_position"]),coordinate:x(a().int()).optional(),text:e().optional()}))),Ko=ve({id:"anthropic.computer_20241022",inputSchema:Jo}),zo=P(()=>D(t({action:Y(["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:De([a().int(),a().int()]).optional(),duration:a().optional(),scroll_amount:a().optional(),scroll_direction:Y(["up","down","left","right"]).optional(),start_coordinate:De([a().int(),a().int()]).optional(),text:e().optional()}))),Yo=ve({id:"anthropic.computer_20250124",inputSchema:zo}),Xo=P(()=>D(ae("command",[t({command:n("view"),path:e(),view_range:De([a(),a()]).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:a(),insert_text:e()}),t({command:n("delete"),path:e()}),t({command:n("rename"),old_path:e(),new_path:e()})]))),Qo=ve({id:"anthropic.memory_20250818",inputSchema:Xo}),Zo=P(()=>D(t({command:Y(["view","create","str_replace","insert","undo_edit"]),path:e(),file_text:e().optional(),insert_line:a().int().optional(),new_str:e().optional(),old_str:e().optional(),view_range:x(a().int()).optional()}))),en=ve({id:"anthropic.text_editor_20241022",inputSchema:Zo}),tn=P(()=>D(t({command:Y(["view","create","str_replace","insert","undo_edit"]),path:e(),file_text:e().optional(),insert_line:a().int().optional(),new_str:e().optional(),old_str:e().optional(),view_range:x(a().int()).optional()}))),on=ve({id:"anthropic.text_editor_20250124",inputSchema:tn}),nn=P(()=>D(t({command:Y(["view","create","str_replace","insert"]),path:e(),file_text:e().optional(),insert_line:a().int().optional(),new_str:e().optional(),old_str:e().optional(),view_range:x(a().int()).optional()}))),an=ve({id:"anthropic.text_editor_20250429",inputSchema:nn}),ln=P(()=>D(x(t({type:n("tool_reference"),toolName:e()})))),sn=P(()=>D(t({query:e(),limit:a().optional()}))),rn=ye({id:"anthropic.tool_search_bm25_20251119",inputSchema:sn,outputSchema:ln}),un=(o={})=>rn(o),pn={bash_20241022:Bo,bash_20250124:Fo,codeExecution_20250522:Mo,codeExecution_20250825:Ao,computer_20241022:Ko,computer_20250124:Yo,memory_20250818:Qo,textEditor_20241022:en,textEditor_20250124:on,textEditor_20250429:an,textEditor_20250728:vo,webFetch_20250910:So,webSearch_20250305:ko,toolSearchRegex_20251119:Do,toolSearchBm25_20251119:un};function cn(o={}){var l,s;const p=(l=Le(Nt({settingValue:o.baseURL,environmentVariableName:"ANTHROPIC_BASE_URL"})))!=null?l:"https://api.anthropic.com/v1",c=(s=o.name)!=null?s:"anthropic.messages",m=()=>He({"anthropic-version":"2023-06-01","x-api-key":je({apiKey:o.apiKey,environmentVariableName:"ANTHROPIC_API_KEY",description:"Anthropic"}),...o.headers},`ai-sdk/anthropic/${ro}`),u=b=>{var _;return new jo(b,{provider:c,baseURL:p,headers:m,fetch:o.fetch,generateId:(_=o.generateId)!=null?_:pe,supportedUrls:()=>({"image/*":[/^https?:\/\/.*$/]})})},d=function(b){if(new.target)throw new Error("The Anthropic model function cannot be called with the new keyword.");return u(b)};return d.specificationVersion="v3",d.languageModel=u,d.chat=u,d.messages=u,d.embeddingModel=b=>{throw new et({modelId:b,modelType:"embeddingModel"})},d.textEmbeddingModel=d.embeddingModel,d.imageModel=b=>{throw new et({modelId:b,modelType:"imageModel"})},d.tools=pn,d}var ri=cn(),We=t({error:t({message:e(),type:e().nullish(),param:Me().nullish(),code:Q([e(),a()]).nullish()})}),ke=Ge({errorSchema:We,errorToMessage:o=>o.error.message});function jt(o){const l=o.startsWith("o3")||o.startsWith("o4-mini")||o.startsWith("gpt-5")&&!o.startsWith("gpt-5-chat"),s=o.startsWith("gpt-4")||o.startsWith("gpt-5-mini")||o.startsWith("gpt-5")&&!o.startsWith("gpt-5-nano")&&!o.startsWith("gpt-5-chat")||o.startsWith("o3")||o.startsWith("o4-mini"),p=o.startsWith("o1")||o.startsWith("o3")||o.startsWith("o4-mini")||o.startsWith("codex-mini")||o.startsWith("computer-use-preview")||o.startsWith("gpt-5")&&!o.startsWith("gpt-5-chat"),c=o.startsWith("gpt-5.1")||o.startsWith("gpt-5.2");return{supportsFlexProcessing:l,supportsPriorityProcessing:s,isReasoningModel:p,systemMessageMode:p?"developer":"system",supportsNonReasoningParameters:c}}function rt(o){var l,s,p,c,m,u;if(o==null)return{inputTokens:{total:void 0,noCache:void 0,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:void 0,text:void 0,reasoning:void 0},raw:void 0};const d=(l=o.prompt_tokens)!=null?l:0,b=(s=o.completion_tokens)!=null?s:0,_=(c=(p=o.prompt_tokens_details)==null?void 0:p.cached_tokens)!=null?c:0,T=(u=(m=o.completion_tokens_details)==null?void 0:m.reasoning_tokens)!=null?u:0;return{inputTokens:{total:d,noCache:d-_,cacheRead:_,cacheWrite:void 0},outputTokens:{total:b,text:b-T,reasoning:T},raw:o}}function dn({prompt:o,systemMessageMode:l="system"}){var s;const p=[],c=[];for(const{role:m,content:u}of o)switch(m){case"system":{switch(l){case"system":{p.push({role:"system",content:u});break}case"developer":{p.push({role:"developer",content:u});break}case"remove":{c.push({type:"other",message:"system messages are removed for this model"});break}default:{const d=l;throw new Error(`Unsupported system message mode: ${d}`)}}break}case"user":{if(u.length===1&&u[0].type==="text"){p.push({role:"user",content:u[0].text});break}p.push({role:"user",content:u.map((d,b)=>{var _,T,w;switch(d.type){case"text":return{type:"text",text:d.text};case"file":if(d.mediaType.startsWith("image/")){const y=d.mediaType==="image/*"?"image/jpeg":d.mediaType;return{type:"image_url",image_url:{url:d.data instanceof URL?d.data.toString():`data:${y};base64,${Ie(d.data)}`,detail:(T=(_=d.providerOptions)==null?void 0:_.openai)==null?void 0:T.imageDetail}}}else if(d.mediaType.startsWith("audio/")){if(d.data instanceof URL)throw new _e({functionality:"audio file parts with URLs"});switch(d.mediaType){case"audio/wav":return{type:"input_audio",input_audio:{data:Ie(d.data),format:"wav"}};case"audio/mp3":case"audio/mpeg":return{type:"input_audio",input_audio:{data:Ie(d.data),format:"mp3"}};default:throw new _e({functionality:`audio content parts with media type ${d.mediaType}`})}}else if(d.mediaType==="application/pdf"){if(d.data instanceof URL)throw new _e({functionality:"PDF file parts with URLs"});return{type:"file",file:typeof d.data=="string"&&d.data.startsWith("file-")?{file_id:d.data}:{filename:(w=d.filename)!=null?w:`part-${b}.pdf`,file_data:`data:application/pdf;base64,${Ie(d.data)}`}}}else throw new _e({functionality:`file part media type ${d.mediaType}`})}})});break}case"assistant":{let d="";const b=[];for(const _ of u)switch(_.type){case"text":{d+=_.text;break}case"tool-call":{b.push({id:_.toolCallId,type:"function",function:{name:_.toolName,arguments:JSON.stringify(_.input)}});break}}p.push({role:"assistant",content:d,tool_calls:b.length>0?b:void 0});break}case"tool":{for(const d of u){if(d.type==="tool-approval-response")continue;const b=d.output;let _;switch(b.type){case"text":case"error-text":_=b.value;break;case"execution-denied":_=(s=b.reason)!=null?s:"Tool execution denied.";break;case"content":case"json":case"error-json":_=JSON.stringify(b.value);break}p.push({role:"tool",tool_call_id:d.toolCallId,content:_})}break}default:{const d=m;throw new Error(`Unsupported role: ${d}`)}}return{messages:p,warnings:c}}function $e({id:o,model:l,created:s}){return{id:o??void 0,modelId:l??void 0,timestamp:s?new Date(s*1e3):void 0}}function ut(o){switch(o){case"stop":return"stop";case"length":return"length";case"content_filter":return"content-filter";case"function_call":case"tool_calls":return"tool-calls";default:return"other"}}var _n=P(()=>D(t({id:e().nullish(),created:a().nullish(),model:e().nullish(),choices:x(t({message:t({role:n("assistant").nullish(),content:e().nullish(),tool_calls:x(t({id:e().nullish(),type:n("function"),function:t({name:e(),arguments:e()})})).nullish(),annotations:x(t({type:n("url_citation"),url_citation:t({start_index:a(),end_index:a(),url:e(),title:e()})})).nullish()}),index:a(),logprobs:t({content:x(t({token:e(),logprob:a(),top_logprobs:x(t({token:e(),logprob:a()}))})).nullish()}).nullish(),finish_reason:e().nullish()})),usage:t({prompt_tokens:a().nullish(),completion_tokens:a().nullish(),total_tokens:a().nullish(),prompt_tokens_details:t({cached_tokens:a().nullish()}).nullish(),completion_tokens_details:t({reasoning_tokens:a().nullish(),accepted_prediction_tokens:a().nullish(),rejected_prediction_tokens:a().nullish()}).nullish()}).nullish()}))),mn=P(()=>D(Q([t({id:e().nullish(),created:a().nullish(),model:e().nullish(),choices:x(t({delta:t({role:Y(["assistant"]).nullish(),content:e().nullish(),tool_calls:x(t({index:a(),id:e().nullish(),type:n("function").nullish(),function:t({name:e().nullish(),arguments:e().nullish()})})).nullish(),annotations:x(t({type:n("url_citation"),url_citation:t({start_index:a(),end_index:a(),url:e(),title:e()})})).nullish()}).nullish(),logprobs:t({content:x(t({token:e(),logprob:a(),top_logprobs:x(t({token:e(),logprob:a()}))})).nullish()}).nullish(),finish_reason:e().nullish(),index:a()})),usage:t({prompt_tokens:a().nullish(),completion_tokens:a().nullish(),total_tokens:a().nullish(),prompt_tokens_details:t({cached_tokens:a().nullish()}).nullish(),completion_tokens_details:t({reasoning_tokens:a().nullish(),accepted_prediction_tokens:a().nullish(),rejected_prediction_tokens:a().nullish()}).nullish()}).nullish()}),We]))),hn=P(()=>D(t({logitBias:ue(so(),a()).optional(),logprobs:Q([ne(),a()]).optional(),parallelToolCalls:ne().optional(),user:e().optional(),reasoningEffort:Y(["none","minimal","low","medium","high","xhigh"]).optional(),maxCompletionTokens:a().optional(),store:ne().optional(),metadata:ue(e().max(64),e().max(512)).optional(),prediction:ue(e(),Me()).optional(),serviceTier:Y(["auto","flex","priority","default"]).optional(),strictJsonSchema:ne().optional(),textVerbosity:Y(["low","medium","high"]).optional(),promptCacheKey:e().optional(),promptCacheRetention:Y(["in_memory","24h"]).optional(),safetyIdentifier:e().optional(),systemMessageMode:Y(["system","developer","remove"]).optional(),forceReasoning:ne().optional()})));function gn({tools:o,toolChoice:l}){o=o!=null&&o.length?o:void 0;const s=[];if(o==null)return{tools:void 0,toolChoice:void 0,toolWarnings:s};const p=[];for(const m of o)switch(m.type){case"function":p.push({type:"function",function:{name:m.name,description:m.description,parameters:m.inputSchema,...m.strict!=null?{strict:m.strict}:{}}});break;default:s.push({type:"unsupported",feature:`tool type: ${m.type}`});break}if(l==null)return{tools:p,toolChoice:void 0,toolWarnings:s};const c=l.type;switch(c){case"auto":case"none":case"required":return{tools:p,toolChoice:c,toolWarnings:s};case"tool":return{tools:p,toolChoice:{type:"function",function:{name:l.toolName}},toolWarnings:s};default:{const m=c;throw new _e({functionality:`tool choice type: ${m}`})}}}var fn=class{constructor(o,l){this.specificationVersion="v3",this.supportedUrls={"image/*":[/^https?:\/\/.*$/]},this.modelId=o,this.config=l}get provider(){return this.config.provider}async getArgs({prompt:o,maxOutputTokens:l,temperature:s,topP:p,topK:c,frequencyPenalty:m,presencePenalty:u,stopSequences:d,responseFormat:b,seed:_,tools:T,toolChoice:w,providerOptions:y}){var g,k,C,f,L;const $=[],E=(g=await me({provider:"openai",providerOptions:y,schema:hn}))!=null?g:{},X=jt(this.modelId),q=(k=E.forceReasoning)!=null?k:X.isReasoningModel;c!=null&&$.push({type:"unsupported",feature:"topK"});const{messages:i,warnings:A}=dn({prompt:o,systemMessageMode:(C=E.systemMessageMode)!=null?C:q?"developer":X.systemMessageMode});$.push(...A);const ie=(f=E.strictJsonSchema)!=null?f:!0,h={model:this.modelId,logit_bias:E.logitBias,logprobs:E.logprobs===!0||typeof E.logprobs=="number"?!0:void 0,top_logprobs:typeof E.logprobs=="number"?E.logprobs:typeof E.logprobs=="boolean"&&E.logprobs?0:void 0,user:E.user,parallel_tool_calls:E.parallelToolCalls,max_tokens:l,temperature:s,top_p:p,frequency_penalty:m,presence_penalty:u,response_format:(b==null?void 0:b.type)==="json"?b.schema!=null?{type:"json_schema",json_schema:{schema:b.schema,strict:ie,name:(L=b.name)!=null?L:"response",description:b.description}}:{type:"json_object"}:void 0,stop:d,seed:_,verbosity:E.textVerbosity,max_completion_tokens:E.maxCompletionTokens,store:E.store,metadata:E.metadata,prediction:E.prediction,reasoning_effort:E.reasoningEffort,service_tier:E.serviceTier,prompt_cache_key:E.promptCacheKey,prompt_cache_retention:E.promptCacheRetention,safety_identifier:E.safetyIdentifier,messages:i};q?((E.reasoningEffort!=="none"||!X.supportsNonReasoningParameters)&&(h.temperature!=null&&(h.temperature=void 0,$.push({type:"unsupported",feature:"temperature",details:"temperature is not supported for reasoning models"})),h.top_p!=null&&(h.top_p=void 0,$.push({type:"unsupported",feature:"topP",details:"topP is not supported for reasoning models"})),h.logprobs!=null&&(h.logprobs=void 0,$.push({type:"other",message:"logprobs is not supported for reasoning models"}))),h.frequency_penalty!=null&&(h.frequency_penalty=void 0,$.push({type:"unsupported",feature:"frequencyPenalty",details:"frequencyPenalty is not supported for reasoning models"})),h.presence_penalty!=null&&(h.presence_penalty=void 0,$.push({type:"unsupported",feature:"presencePenalty",details:"presencePenalty is not supported for reasoning models"})),h.logit_bias!=null&&(h.logit_bias=void 0,$.push({type:"other",message:"logitBias is not supported for reasoning models"})),h.top_logprobs!=null&&(h.top_logprobs=void 0,$.push({type:"other",message:"topLogprobs is not supported for reasoning models"})),h.max_tokens!=null&&(h.max_completion_tokens==null&&(h.max_completion_tokens=h.max_tokens),h.max_tokens=void 0)):(this.modelId.startsWith("gpt-4o-search-preview")||this.modelId.startsWith("gpt-4o-mini-search-preview"))&&h.temperature!=null&&(h.temperature=void 0,$.push({type:"unsupported",feature:"temperature",details:"temperature is not supported for the search preview models and has been removed."})),E.serviceTier==="flex"&&!X.supportsFlexProcessing&&($.push({type:"unsupported",feature:"serviceTier",details:"flex processing is only available for o3, o4-mini, and gpt-5 models"}),h.service_tier=void 0),E.serviceTier==="priority"&&!X.supportsPriorityProcessing&&($.push({type:"unsupported",feature:"serviceTier",details:"priority processing is only available for supported models (gpt-4, gpt-5, gpt-5-mini, o3, o4-mini) and requires Enterprise access. gpt-5-nano is not supported"}),h.service_tier=void 0);const{tools:K,toolChoice:N,toolWarnings:S}=gn({tools:T,toolChoice:w});return{args:{...h,tools:K,tool_choice:N},warnings:[...$,...S]}}async doGenerate(o){var l,s,p,c,m,u,d;const{args:b,warnings:_}=await this.getArgs(o),{responseHeaders:T,value:w,rawValue:y}=await fe({url:this.config.url({path:"/chat/completions",modelId:this.modelId}),headers:ge(this.config.headers(),o.headers),body:b,failedResponseHandler:ke,successfulResponseHandler:be(_n),abortSignal:o.abortSignal,fetch:this.config.fetch}),g=w.choices[0],k=[],C=g.message.content;C!=null&&C.length>0&&k.push({type:"text",text:C});for(const $ of(l=g.message.tool_calls)!=null?l:[])k.push({type:"tool-call",toolCallId:(s=$.id)!=null?s:pe(),toolName:$.function.name,input:$.function.arguments});for(const $ of(p=g.message.annotations)!=null?p:[])k.push({type:"source",sourceType:"url",id:pe(),url:$.url_citation.url,title:$.url_citation.title});const f=(c=w.usage)==null?void 0:c.completion_tokens_details;(m=w.usage)==null||m.prompt_tokens_details;const L={openai:{}};return(f==null?void 0:f.accepted_prediction_tokens)!=null&&(L.openai.acceptedPredictionTokens=f==null?void 0:f.accepted_prediction_tokens),(f==null?void 0:f.rejected_prediction_tokens)!=null&&(L.openai.rejectedPredictionTokens=f==null?void 0:f.rejected_prediction_tokens),((u=g.logprobs)==null?void 0:u.content)!=null&&(L.openai.logprobs=g.logprobs.content),{content:k,finishReason:{unified:ut(g.finish_reason),raw:(d=g.finish_reason)!=null?d:void 0},usage:rt(w.usage),request:{body:b},response:{...$e(w),headers:T,body:y},warnings:_,providerMetadata:L}}async doStream(o){const{args:l,warnings:s}=await this.getArgs(o),p={...l,stream:!0,stream_options:{include_usage:!0}},{responseHeaders:c,value:m}=await fe({url:this.config.url({path:"/chat/completions",modelId:this.modelId}),headers:ge(this.config.headers(),o.headers),body:p,failedResponseHandler:ke,successfulResponseHandler:Oe(mn),abortSignal:o.abortSignal,fetch:this.config.fetch}),u=[];let d={unified:"other",raw:void 0},b,_=!1,T=!1;const w={openai:{}};return{stream:m.pipeThrough(new TransformStream({start(y){y.enqueue({type:"stream-start",warnings:s})},transform(y,g){var k,C,f,L,$,E,X,q,i,A,ie,h,K,N,S,G,M;if(o.includeRawChunks&&g.enqueue({type:"raw",rawValue:y.rawValue}),!y.success){d={unified:"error",raw:void 0},g.enqueue({type:"error",error:y.error});return}const I=y.value;if("error"in I){d={unified:"error",raw:void 0},g.enqueue({type:"error",error:I.error});return}if(!_){const W=$e(I);Object.values(W).some(Boolean)&&(_=!0,g.enqueue({type:"response-metadata",...$e(I)}))}I.usage!=null&&(b=I.usage,((k=I.usage.completion_tokens_details)==null?void 0:k.accepted_prediction_tokens)!=null&&(w.openai.acceptedPredictionTokens=(C=I.usage.completion_tokens_details)==null?void 0:C.accepted_prediction_tokens),((f=I.usage.completion_tokens_details)==null?void 0:f.rejected_prediction_tokens)!=null&&(w.openai.rejectedPredictionTokens=(L=I.usage.completion_tokens_details)==null?void 0:L.rejected_prediction_tokens));const F=I.choices[0];if((F==null?void 0:F.finish_reason)!=null&&(d={unified:ut(F.finish_reason),raw:F.finish_reason}),(($=F==null?void 0:F.logprobs)==null?void 0:$.content)!=null&&(w.openai.logprobs=F.logprobs.content),(F==null?void 0:F.delta)==null)return;const V=F.delta;if(V.content!=null&&(T||(g.enqueue({type:"text-start",id:"0"}),T=!0),g.enqueue({type:"text-delta",id:"0",delta:V.content})),V.tool_calls!=null)for(const W of V.tool_calls){const ee=W.index;if(u[ee]==null){if(W.type!=="function")throw new qe({data:W,message:"Expected 'function' type."});if(W.id==null)throw new qe({data:W,message:"Expected 'id' to be a string."});if(((E=W.function)==null?void 0:E.name)==null)throw new qe({data:W,message:"Expected 'function.name' to be a string."});g.enqueue({type:"tool-input-start",id:W.id,toolName:W.function.name}),u[ee]={id:W.id,type:"function",function:{name:W.function.name,arguments:(X=W.function.arguments)!=null?X:""},hasFinished:!1};const le=u[ee];((q=le.function)==null?void 0:q.name)!=null&&((i=le.function)==null?void 0:i.arguments)!=null&&(le.function.arguments.length>0&&g.enqueue({type:"tool-input-delta",id:le.id,delta:le.function.arguments}),tt(le.function.arguments)&&(g.enqueue({type:"tool-input-end",id:le.id}),g.enqueue({type:"tool-call",toolCallId:(A=le.id)!=null?A:pe(),toolName:le.function.name,input:le.function.arguments}),le.hasFinished=!0));continue}const H=u[ee];H.hasFinished||(((ie=W.function)==null?void 0:ie.arguments)!=null&&(H.function.arguments+=(K=(h=W.function)==null?void 0:h.arguments)!=null?K:""),g.enqueue({type:"tool-input-delta",id:H.id,delta:(N=W.function.arguments)!=null?N:""}),((S=H.function)==null?void 0:S.name)!=null&&((G=H.function)==null?void 0:G.arguments)!=null&&tt(H.function.arguments)&&(g.enqueue({type:"tool-input-end",id:H.id}),g.enqueue({type:"tool-call",toolCallId:(M=H.id)!=null?M:pe(),toolName:H.function.name,input:H.function.arguments}),H.hasFinished=!0))}if(V.annotations!=null)for(const W of V.annotations)g.enqueue({type:"source",sourceType:"url",id:pe(),url:W.url_citation.url,title:W.url_citation.title})},flush(y){T&&y.enqueue({type:"text-end",id:"0"}),y.enqueue({type:"finish",finishReason:d,usage:rt(b),...w!=null?{providerMetadata:w}:{}})}})),request:{body:p},response:{headers:c}}}};function pt(o){var l,s,p,c;if(o==null)return{inputTokens:{total:void 0,noCache:void 0,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:void 0,text:void 0,reasoning:void 0},raw:void 0};const m=(l=o.prompt_tokens)!=null?l:0,u=(s=o.completion_tokens)!=null?s:0;return{inputTokens:{total:(p=o.prompt_tokens)!=null?p:void 0,noCache:m,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:(c=o.completion_tokens)!=null?c:void 0,text:u,reasoning:void 0},raw:o}}function yn({prompt:o,user:l="user",assistant:s="assistant"}){let p="";o[0].role==="system"&&(p+=`${o[0].content}
2
2
 
3
3
  `,o=o.slice(1));for(const{role:c,content:m}of o)switch(c){case"system":throw new lo({message:"Unexpected system message in prompt: ${content}",prompt:o});case"user":{const u=m.map(d=>{switch(d.type){case"text":return d.text}}).filter(Boolean).join("");p+=`${l}:
4
4
  ${u}