eve 0.24.0 → 0.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/dist/src/compiled/.vendor-stamp.json +11 -11
- package/dist/src/compiled/@ai-sdk/anthropic/index.d.ts +1 -1
- package/dist/src/compiled/@ai-sdk/anthropic/index.js +2 -2
- package/dist/src/compiled/@ai-sdk/google/index.d.ts +7 -0
- package/dist/src/compiled/@ai-sdk/google/index.js +6 -6
- package/dist/src/compiled/@ai-sdk/mcp/index.d.ts +42 -1
- package/dist/src/compiled/@ai-sdk/mcp/index.js +1 -1
- package/dist/src/compiled/@ai-sdk/openai/index.d.ts +34 -6
- package/dist/src/compiled/@ai-sdk/openai/index.js +2 -2
- package/dist/src/compiled/@ai-sdk/otel/index.js +1 -1
- package/dist/src/compiled/@ai-sdk/provider/index.d.ts +245 -3
- package/dist/src/compiled/@ai-sdk/provider-utils/index.d.ts +273 -15
- package/dist/src/compiled/@workflow/core/index.js +1 -1
- package/dist/src/compiled/@workflow/core/runtime/start.d.ts +12 -0
- package/dist/src/compiled/@workflow/core/runtime.js +1 -1
- package/dist/src/compiled/@workflow/core/version.d.ts +1 -1
- package/dist/src/compiled/@workflow/core/workflow.js +1 -1
- package/dist/src/compiled/@workflow/world/analytics.d.ts +56 -21
- package/dist/src/compiled/@workflow/world/index.d.ts +1 -1
- package/dist/src/compiled/@workflow/world/interfaces.d.ts +46 -0
- package/dist/src/compiled/@workflow/world/queue.d.ts +12 -0
- package/dist/src/compiled/@workflow/world-local/index.js +3 -3
- package/dist/src/compiled/@workflow/world-vercel/index.js +16 -16
- package/dist/src/compiled/_chunks/workflow/attribute-changes-MGTOG_uX.js +20 -0
- package/dist/src/compiled/_chunks/workflow/{dist-CQenixFf.js → dist-Blxnyb7-.js} +2 -2
- package/dist/src/compiled/_chunks/workflow/dist-zLevmMyU.js +77 -0
- package/dist/src/compiled/_chunks/workflow/{resume-hook-BH01MfRF.js → resume-hook-DHP5ql3-.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/run-D8hv1ptT.js +1 -0
- package/dist/src/compiled/_chunks/workflow/{sleep-BkAHCD_s.js → sleep-uA9pS-PT.js} +1 -1
- package/dist/src/compiler/artifacts.d.ts +7 -6
- package/dist/src/compiler/artifacts.js +1 -1
- package/dist/src/compiler/compile-agent.d.ts +15 -2
- package/dist/src/compiler/compile-agent.js +3 -3
- package/dist/src/execution/sandbox/prewarm.d.ts +1 -0
- package/dist/src/execution/sandbox/prewarm.js +1 -1
- package/dist/src/harness/instrumentation-runtime-context.d.ts +1 -1
- package/dist/src/harness/tool-loop.js +3 -1
- package/dist/src/internal/application/build-workspace.d.ts +36 -0
- package/dist/src/internal/application/build-workspace.js +1 -0
- package/dist/src/internal/application/compiled-artifacts.d.ts +5 -0
- package/dist/src/internal/application/compiled-artifacts.js +4 -3
- package/dist/src/internal/application/output-publication-artifacts.d.ts +7 -0
- package/dist/src/internal/application/output-publication-artifacts.js +1 -0
- package/dist/src/internal/application/output-publication-journal.d.ts +30 -0
- package/dist/src/internal/application/output-publication-journal.js +1 -0
- package/dist/src/internal/application/output-publication-lock.d.ts +10 -0
- package/dist/src/internal/application/output-publication-lock.js +1 -0
- package/dist/src/internal/application/output-publication.d.ts +33 -0
- package/dist/src/internal/application/output-publication.js +1 -0
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/internal/application/production-compiler-artifacts.d.ts +4 -0
- package/dist/src/internal/application/production-compiler-artifacts.js +1 -0
- package/dist/src/internal/application/tsconfig-dependencies.js +1 -1
- package/dist/src/internal/authored-directive-prologue.d.ts +4 -0
- package/dist/src/internal/authored-directive-prologue.js +1 -0
- package/dist/src/internal/authored-module-loader.d.ts +15 -5
- package/dist/src/internal/authored-module-loader.js +4 -2
- package/dist/src/internal/authored-module-map-loader.js +1 -1
- package/dist/src/internal/authored-package-boundary.d.ts +25 -0
- package/dist/src/internal/authored-package-boundary.js +1 -0
- package/dist/src/internal/authored-package-tsconfig-paths.js +1 -1
- package/dist/src/internal/bundler/nitro-node-file-trace.d.ts +10 -0
- package/dist/src/internal/bundler/nitro-node-file-trace.js +1 -0
- package/dist/src/internal/materialize-authored-external-dependencies.d.ts +10 -0
- package/dist/src/internal/materialize-authored-external-dependencies.js +2 -0
- package/dist/src/internal/materialized-authored-modules.d.ts +15 -0
- package/dist/src/internal/materialized-authored-modules.js +1 -0
- package/dist/src/internal/nitro/dev-runtime-artifacts.d.ts +1 -9
- package/dist/src/internal/nitro/dev-runtime-artifacts.js +1 -1
- package/dist/src/internal/nitro/development-generation.d.ts +12 -0
- package/dist/src/internal/nitro/development-generation.js +1 -0
- package/dist/src/internal/nitro/host/artifacts-config.d.ts +9 -11
- package/dist/src/internal/nitro/host/artifacts-config.js +1 -1
- package/dist/src/internal/nitro/host/build-application.js +1 -1
- package/dist/src/internal/nitro/host/build-vercel-agent-summary.d.ts +1 -7
- package/dist/src/internal/nitro/host/build-vercel-agent-summary.js +1 -1
- package/dist/src/internal/nitro/host/channel-routes.d.ts +3 -3
- package/dist/src/internal/nitro/host/configure-nitro-routes.d.ts +9 -5
- package/dist/src/internal/nitro/host/configure-nitro-routes.js +3 -3
- package/dist/src/internal/nitro/host/create-application-nitro.d.ts +18 -10
- package/dist/src/internal/nitro/host/create-application-nitro.js +1 -1
- package/dist/src/internal/nitro/host/dev-authored-source-watcher.js +1 -1
- package/dist/src/internal/nitro/host/dispatch-schedule-in-dev.d.ts +2 -2
- package/dist/src/internal/nitro/host/dispatch-schedule-in-dev.js +1 -1
- package/dist/src/internal/nitro/host/prepare-application-host.d.ts +13 -5
- package/dist/src/internal/nitro/host/prepare-application-host.js +1 -1
- package/dist/src/internal/nitro/host/schedule-task-routes.d.ts +3 -3
- package/dist/src/internal/nitro/host/start-development-server.js +2 -2
- package/dist/src/internal/nitro/routes/agent-info/load-agent-info-data.d.ts +3 -6
- package/dist/src/internal/nitro/routes/agent-info/load-agent-info-data.js +1 -1
- package/dist/src/internal/nitro/routes/channel-dispatch.js +1 -1
- package/dist/src/internal/nitro/routes/dev-schedule-dispatch.d.ts +2 -2
- package/dist/src/internal/nitro/routes/info.d.ts +1 -6
- package/dist/src/internal/nitro/routes/info.js +1 -1
- package/dist/src/internal/nitro/routes/runtime-artifacts.d.ts +9 -5
- package/dist/src/internal/nitro/routes/runtime-artifacts.js +1 -1
- package/dist/src/internal/workflow-bundle/build-queue.d.ts +1 -0
- package/dist/src/internal/workflow-bundle/build-queue.js +1 -0
- package/dist/src/internal/workflow-bundle/builder-support.d.ts +0 -1
- package/dist/src/internal/workflow-bundle/builder-support.js +2 -2
- package/dist/src/internal/workflow-bundle/builder.js +2 -2
- package/dist/src/internal/workflow-bundle/nitro-step-entry.d.ts +1 -0
- package/dist/src/internal/workflow-bundle/nitro-step-entry.js +2 -2
- package/dist/src/public/instrumentation/index.d.ts +3 -3
- package/dist/src/setup/scaffold/create/add-to-project.js +1 -1
- package/dist/src/setup/scaffold/create/project.js +2 -2
- package/dist/src/setup/scaffold/update/channels.js +1 -1
- package/dist/src/shared/atomic-write-file.d.ts +11 -0
- package/dist/src/shared/atomic-write-file.js +1 -0
- package/dist/src/shared/guards.d.ts +7 -0
- package/dist/src/shared/guards.js +1 -1
- package/dist/src/shared/path-exists.d.ts +9 -0
- package/dist/src/shared/path-exists.js +1 -0
- package/docs/reference/cli.md +4 -2
- package/package.json +14 -14
- package/dist/src/compiled/_chunks/workflow/attribute-changes-Dmf_myUv.js +0 -20
- package/dist/src/compiled/_chunks/workflow/dist-D7CzPkf8.js +0 -77
- package/dist/src/compiled/_chunks/workflow/run-CL3mguvM.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# eve
|
|
2
2
|
|
|
3
|
+
## 0.24.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e0b64a5: Keep development runtime generations executable after authored source or dependencies change by bundling ordinary dependencies and materializing configured external dependency closures.
|
|
8
|
+
- c4f5b58: Model calls now merge multiple system instructions into one message, avoiding provider failures when dynamic instructions are combined with array-form user content.
|
|
9
|
+
- 6aac45d: `eve build` now uses invocation-owned compiler, host, Nitro, Workflow, and output workspaces. Concurrent builds can run beside `eve dev`, and failed builds preserve the last successfully published output.
|
|
10
|
+
- 0046308: Update the bundled Workflow runtime dependencies to their latest 5.0 beta releases.
|
|
11
|
+
|
|
3
12
|
## 0.24.0
|
|
4
13
|
|
|
5
14
|
### Minor Changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"moduleVersions": {
|
|
3
|
-
"@ai-sdk/anthropic": "4.0.
|
|
3
|
+
"@ai-sdk/anthropic": "4.0.14",
|
|
4
4
|
"chat": "4.31.0",
|
|
5
5
|
"@chat-adapter/slack": "4.31.0",
|
|
6
6
|
"@chat-adapter/state-memory": "4.31.0",
|
|
@@ -9,30 +9,30 @@
|
|
|
9
9
|
"commander": "14.0.3",
|
|
10
10
|
"experimental-ai-sdk-code-mode": "1.0.16",
|
|
11
11
|
"eventsource-parser": "3.0.8",
|
|
12
|
-
"@ai-sdk/google": "4.0.
|
|
12
|
+
"@ai-sdk/google": "4.0.14",
|
|
13
13
|
"gray-matter": "4.0.3",
|
|
14
14
|
"jose": "6.2.3",
|
|
15
15
|
"jsonc-parser": "3.3.1",
|
|
16
16
|
"@types/json-schema": "7.0.15",
|
|
17
|
-
"@ai-sdk/mcp": "2.0.
|
|
18
|
-
"@ai-sdk/openai": "4.0.
|
|
17
|
+
"@ai-sdk/mcp": "2.0.12",
|
|
18
|
+
"@ai-sdk/openai": "4.0.13",
|
|
19
19
|
"@opentelemetry/api": "1.9.1",
|
|
20
|
-
"@ai-sdk/otel": "1.0.
|
|
20
|
+
"@ai-sdk/otel": "1.0.26",
|
|
21
21
|
"picocolors": "1.1.1",
|
|
22
|
-
"@ai-sdk/provider": "4.0.
|
|
23
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
22
|
+
"@ai-sdk/provider": "4.0.3",
|
|
23
|
+
"@ai-sdk/provider-utils": "5.0.9",
|
|
24
24
|
"semver": "7.8.4",
|
|
25
25
|
"@standard-schema/spec": "1.1.0",
|
|
26
26
|
"turndown": "7.2.4",
|
|
27
27
|
"@vercel/detect-agent": "1.2.3",
|
|
28
28
|
"@vercel/oidc": "3.5.0",
|
|
29
29
|
"@vercel/sandbox": "2.3.0",
|
|
30
|
-
"@workflow/core": "5.0.0-beta.
|
|
30
|
+
"@workflow/core": "5.0.0-beta.34",
|
|
31
31
|
"@workflow/errors": "5.0.0-beta.10",
|
|
32
32
|
"@workflow/serde": "5.0.0-beta.2",
|
|
33
|
-
"@workflow/world": "5.0.0-beta.
|
|
34
|
-
"@workflow/world-local": "5.0.0-beta.
|
|
35
|
-
"@workflow/world-vercel": "5.0.0-beta.
|
|
33
|
+
"@workflow/world": "5.0.0-beta.20",
|
|
34
|
+
"@workflow/world-local": "5.0.0-beta.28",
|
|
35
|
+
"@workflow/world-vercel": "5.0.0-beta.30",
|
|
36
36
|
"zod": "4.4.3",
|
|
37
37
|
"zod-validation-error": "5.0.0"
|
|
38
38
|
},
|
|
@@ -183,7 +183,7 @@ interface AnthropicMessageMetadata {
|
|
|
183
183
|
} | null;
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
type AnthropicModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-fable-5' | (string & {});
|
|
186
|
+
type AnthropicModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-fable-5' | 'claude-sonnet-5' | (string & {});
|
|
187
187
|
declare const anthropicLanguageModelOptions: z.ZodObject<{
|
|
188
188
|
sendReasoning: z.ZodOptional<z.ZodBoolean>;
|
|
189
189
|
structuredOutputMode: z.ZodOptional<z.ZodEnum<{
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{APICallError as e,InvalidArgumentError as t,NoSuchModelError as n,UnsupportedFunctionalityError as r}from"../provider/index.js";import{A as i,B as a,C as o,D as s,G as c,H as l,J as u,L as d,M as f,N as p,P as m,Q as h,R as g,T as _,V as v,X as y,Y as b,Z as x,_t as S,a as C,b as w,d as T,dt as E,f as D,ft as O,g as k,gt as A,h as j,ht as M,i as ee,it as N,j as P,lt as F,mt as I,o as L,ot as R,p as z,q as B,r as V,st as H,tt as U,u as W,ut as G,vt as K,x as q,z as J}from"../../_chunks/workflow/dist-D7CzPkf8.js";var Y=T({errorSchema:i(()=>y(O({type:F(`error`),error:O({type:M(),message:M()})}))),errorToMessage:e=>e.error.message}),te=i(()=>y(O({id:M(),type:F(`file`),filename:M(),mime_type:M(),size_bytes:E(),created_at:M(),downloadable:R().nullish()}))),ne=class{constructor(e){this.config=e,this.specificationVersion=`v4`}get provider(){return this.config.provider}async uploadFile({data:e,mediaType:t,filename:n}){let r=C(e),i=new Blob([r],{type:t}),a=new FormData;n==null?a.append(`file`,i):a.append(`file`,i,n);let{value:o}=await g({url:`${this.config.baseURL}/files`,headers:V(this.config.headers(),{"anthropic-beta":`files-api-2025-04-14`}),formData:a,failedResponseHandler:Y,successfulResponseHandler:D(te),fetch:this.config.fetch});return{warnings:[],providerReference:{anthropic:o.id},mediaType:o.mime_type??t,filename:o.filename??n,providerMetadata:{anthropic:{filename:o.filename,mimeType:o.mime_type,sizeBytes:o.size_bytes,createdAt:o.created_at,...o.downloadable==null?{}:{downloadable:o.downloadable}}}}}},X=O({type:M(),category:M().nullish(),explanation:M().nullish(),recommended_model:M().nullish()}),re=i(()=>y(O({type:F(`message`),id:M().nullish(),model:M().nullish(),content:N(H(`type`,[O({type:F(`text`),text:M(),citations:N(H(`type`,[O({type:F(`web_search_result_location`),cited_text:M(),url:M(),title:M(),encrypted_index:M()}),O({type:F(`page_location`),cited_text:M(),document_index:E(),document_title:M().nullable(),start_page_number:E(),end_page_number:E()}),O({type:F(`char_location`),cited_text:M(),document_index:E(),document_title:M().nullable(),start_char_index:E(),end_char_index:E()})])).optional()}),O({type:F(`thinking`),thinking:M(),signature:M()}),O({type:F(`redacted_thinking`),data:M()}),O({type:F(`compaction`),content:M()}),O({type:F(`tool_use`),id:M(),name:M(),input:K(),caller:S([O({type:F(`code_execution_20250825`),tool_id:M()}),O({type:F(`code_execution_20260120`),tool_id:M()}),O({type:F(`direct`)})]).optional()}),O({type:F(`server_tool_use`),id:M(),name:M(),input:I(M(),K()).nullish(),caller:S([O({type:F(`code_execution_20260120`),tool_id:M()}),O({type:F(`direct`)})]).optional()}),O({type:F(`mcp_tool_use`),id:M(),name:M(),input:K(),server_name:M()}),O({type:F(`mcp_tool_result`),tool_use_id:M(),is_error:R(),content:N(S([M(),O({type:F(`text`),text:M()})]))}),O({type:F(`web_fetch_tool_result`),tool_use_id:M(),content:S([O({type:F(`web_fetch_result`),url:M(),retrieved_at:M(),content:O({type:F(`document`),title:M().nullable(),citations:O({enabled:R()}).optional(),source:S([O({type:F(`base64`),media_type:F(`application/pdf`),data:M()}),O({type:F(`text`),media_type:F(`text/plain`),data:M()})])})}),O({type:F(`web_fetch_tool_result_error`),error_code:M()})])}),O({type:F(`web_search_tool_result`),tool_use_id:M(),content:S([N(O({type:F(`web_search_result`),url:M(),title:M(),encrypted_content:M(),page_age:M().nullish()})),O({type:F(`web_search_tool_result_error`),error_code:M()})])}),O({type:F(`code_execution_tool_result`),tool_use_id:M(),content:S([O({type:F(`code_execution_result`),stdout:M(),stderr:M(),return_code:E(),content:N(O({type:F(`code_execution_output`),file_id:M()})).optional().default([])}),O({type:F(`encrypted_code_execution_result`),encrypted_stdout:M(),stderr:M(),return_code:E(),content:N(O({type:F(`code_execution_output`),file_id:M()})).optional().default([])}),O({type:F(`code_execution_tool_result_error`),error_code:M()})])}),O({type:F(`bash_code_execution_tool_result`),tool_use_id:M(),content:H(`type`,[O({type:F(`bash_code_execution_result`),content:N(O({type:F(`bash_code_execution_output`),file_id:M()})),stdout:M(),stderr:M(),return_code:E()}),O({type:F(`bash_code_execution_tool_result_error`),error_code:M()})])}),O({type:F(`text_editor_code_execution_tool_result`),tool_use_id:M(),content:H(`type`,[O({type:F(`text_editor_code_execution_tool_result_error`),error_code:M()}),O({type:F(`text_editor_code_execution_view_result`),content:M(),file_type:M(),num_lines:E().nullable(),start_line:E().nullable(),total_lines:E().nullable()}),O({type:F(`text_editor_code_execution_create_result`),is_file_update:R()}),O({type:F(`text_editor_code_execution_str_replace_result`),lines:N(M()).nullable(),new_lines:E().nullable(),new_start:E().nullable(),old_lines:E().nullable(),old_start:E().nullable()})])}),O({type:F(`tool_search_tool_result`),tool_use_id:M(),content:S([O({type:F(`tool_search_tool_search_result`),tool_references:N(O({type:F(`tool_reference`),tool_name:M()}))}),O({type:F(`tool_search_tool_result_error`),error_code:M()})])}),O({type:F(`advisor_tool_result`),tool_use_id:M(),content:H(`type`,[O({type:F(`advisor_result`),text:M()}),O({type:F(`advisor_redacted_result`),encrypted_content:M()}),O({type:F(`advisor_tool_result_error`),error_code:M()})])}),O({type:F(`fallback`)})])),stop_reason:M().nullish(),stop_sequence:M().nullish(),stop_details:X.nullish(),usage:G({input_tokens:E(),output_tokens:E(),cache_creation_input_tokens:E().nullish(),cache_read_input_tokens:E().nullish(),iterations:N(O({type:S([F(`compaction`),F(`message`),F(`advisor_message`),F(`fallback_message`)]),model:M().nullish(),input_tokens:E(),output_tokens:E(),cache_creation_input_tokens:E().nullish(),cache_read_input_tokens:E().nullish()})).nullish()}),container:O({expires_at:M(),id:M(),skills:N(O({type:S([F(`anthropic`),F(`custom`)]),skill_id:M(),version:M()})).nullish()}).nullish(),context_management:O({applied_edits:N(S([O({type:F(`clear_tool_uses_20250919`),cleared_tool_uses:E(),cleared_input_tokens:E()}),O({type:F(`clear_thinking_20251015`),cleared_thinking_turns:E(),cleared_input_tokens:E()}),O({type:F(`compact_20260112`)})]))}).nullish()}))),ie=i(()=>y(H(`type`,[O({type:F(`message_start`),message:O({id:M().nullish(),model:M().nullish(),role:M().nullish(),usage:G({input_tokens:E(),cache_creation_input_tokens:E().nullish(),cache_read_input_tokens:E().nullish()}),content:N(H(`type`,[O({type:F(`tool_use`),id:M(),name:M(),input:K(),caller:S([O({type:F(`code_execution_20250825`),tool_id:M()}),O({type:F(`code_execution_20260120`),tool_id:M()}),O({type:F(`direct`)})]).optional()})])).nullish(),stop_reason:M().nullish(),container:O({expires_at:M(),id:M()}).nullish()})}),O({type:F(`content_block_start`),index:E(),content_block:H(`type`,[O({type:F(`text`),text:M()}),O({type:F(`thinking`),thinking:M()}),O({type:F(`tool_use`),id:M(),name:M(),input:I(M(),K()).optional(),caller:S([O({type:F(`code_execution_20250825`),tool_id:M()}),O({type:F(`code_execution_20260120`),tool_id:M()}),O({type:F(`direct`)})]).optional()}),O({type:F(`redacted_thinking`),data:M()}),O({type:F(`compaction`),content:M().nullish()}),O({type:F(`server_tool_use`),id:M(),name:M(),input:I(M(),K()).nullish(),caller:S([O({type:F(`code_execution_20260120`),tool_id:M()}),O({type:F(`direct`)})]).optional()}),O({type:F(`mcp_tool_use`),id:M(),name:M(),input:K(),server_name:M()}),O({type:F(`mcp_tool_result`),tool_use_id:M(),is_error:R(),content:N(S([M(),O({type:F(`text`),text:M()})]))}),O({type:F(`web_fetch_tool_result`),tool_use_id:M(),content:S([O({type:F(`web_fetch_result`),url:M(),retrieved_at:M(),content:O({type:F(`document`),title:M().nullable(),citations:O({enabled:R()}).optional(),source:S([O({type:F(`base64`),media_type:F(`application/pdf`),data:M()}),O({type:F(`text`),media_type:F(`text/plain`),data:M()})])})}),O({type:F(`web_fetch_tool_result_error`),error_code:M()})])}),O({type:F(`web_search_tool_result`),tool_use_id:M(),content:S([N(O({type:F(`web_search_result`),url:M(),title:M(),encrypted_content:M(),page_age:M().nullish()})),O({type:F(`web_search_tool_result_error`),error_code:M()})])}),O({type:F(`code_execution_tool_result`),tool_use_id:M(),content:S([O({type:F(`code_execution_result`),stdout:M(),stderr:M(),return_code:E(),content:N(O({type:F(`code_execution_output`),file_id:M()})).optional().default([])}),O({type:F(`encrypted_code_execution_result`),encrypted_stdout:M(),stderr:M(),return_code:E(),content:N(O({type:F(`code_execution_output`),file_id:M()})).optional().default([])}),O({type:F(`code_execution_tool_result_error`),error_code:M()})])}),O({type:F(`bash_code_execution_tool_result`),tool_use_id:M(),content:H(`type`,[O({type:F(`bash_code_execution_result`),content:N(O({type:F(`bash_code_execution_output`),file_id:M()})),stdout:M(),stderr:M(),return_code:E()}),O({type:F(`bash_code_execution_tool_result_error`),error_code:M()})])}),O({type:F(`text_editor_code_execution_tool_result`),tool_use_id:M(),content:H(`type`,[O({type:F(`text_editor_code_execution_tool_result_error`),error_code:M()}),O({type:F(`text_editor_code_execution_view_result`),content:M(),file_type:M(),num_lines:E().nullable(),start_line:E().nullable(),total_lines:E().nullable()}),O({type:F(`text_editor_code_execution_create_result`),is_file_update:R()}),O({type:F(`text_editor_code_execution_str_replace_result`),lines:N(M()).nullable(),new_lines:E().nullable(),new_start:E().nullable(),old_lines:E().nullable(),old_start:E().nullable()})])}),O({type:F(`tool_search_tool_result`),tool_use_id:M(),content:S([O({type:F(`tool_search_tool_search_result`),tool_references:N(O({type:F(`tool_reference`),tool_name:M()}))}),O({type:F(`tool_search_tool_result_error`),error_code:M()})])}),O({type:F(`advisor_tool_result`),tool_use_id:M(),content:H(`type`,[O({type:F(`advisor_result`),text:M()}),O({type:F(`advisor_redacted_result`),encrypted_content:M()}),O({type:F(`advisor_tool_result_error`),error_code:M()})])}),O({type:F(`fallback`)})])}),O({type:F(`content_block_delta`),index:E(),delta:H(`type`,[O({type:F(`input_json_delta`),partial_json:M()}),O({type:F(`text_delta`),text:M()}),O({type:F(`thinking_delta`),thinking:M()}),O({type:F(`signature_delta`),signature:M()}),O({type:F(`compaction_delta`),content:M().nullish()}),O({type:F(`citations_delta`),citation:H(`type`,[O({type:F(`web_search_result_location`),cited_text:M(),url:M(),title:M(),encrypted_index:M()}),O({type:F(`page_location`),cited_text:M(),document_index:E(),document_title:M().nullable(),start_page_number:E(),end_page_number:E()}),O({type:F(`char_location`),cited_text:M(),document_index:E(),document_title:M().nullable(),start_char_index:E(),end_char_index:E()})])})])}),O({type:F(`content_block_stop`),index:E()}),O({type:F(`error`),error:O({type:M(),message:M()})}),O({type:F(`message_delta`),delta:O({stop_reason:M().nullish(),stop_sequence:M().nullish(),stop_details:X.nullish(),container:O({expires_at:M(),id:M(),skills:N(O({type:S([F(`anthropic`),F(`custom`)]),skill_id:M(),version:M()})).nullish()}).nullish()}),usage:G({input_tokens:E().nullish(),output_tokens:E(),cache_creation_input_tokens:E().nullish(),cache_read_input_tokens:E().nullish(),iterations:N(O({type:S([F(`compaction`),F(`message`),F(`advisor_message`),F(`fallback_message`)]),model:M().nullish(),input_tokens:E(),output_tokens:E(),cache_creation_input_tokens:E().nullish(),cache_read_input_tokens:E().nullish()})).nullish()}),context_management:O({applied_edits:N(S([O({type:F(`clear_tool_uses_20250919`),cleared_tool_uses:E(),cleared_input_tokens:E()}),O({type:F(`clear_thinking_20251015`),cleared_thinking_turns:E(),cleared_input_tokens:E()}),O({type:F(`compact_20260112`)})]))}).nullish()}),O({type:F(`message_stop`)}),O({type:F(`ping`)})]))),ae=i(()=>y(O({signature:M().optional(),redactedData:M().optional()}))),Z=O({containerUpload:R().optional(),citations:O({enabled:R()}).optional(),title:M().optional(),context:M().optional()}),oe=O({sendReasoning:R().optional(),structuredOutputMode:U([`outputFormat`,`jsonTool`,`auto`]).optional(),thinking:H(`type`,[O({type:F(`adaptive`),display:U([`omitted`,`summarized`]).optional()}),O({type:F(`enabled`),budgetTokens:E().optional()}),O({type:F(`disabled`)})]).optional(),disableParallelToolUse:R().optional(),cacheControl:O({type:F(`ephemeral`),ttl:S([F(`5m`),F(`1h`)]).optional()}).optional(),metadata:O({userId:M().optional()}).optional(),mcpServers:N(O({type:F(`url`),name:M(),url:M(),authorizationToken:M().nullish(),toolConfiguration:O({enabled:R().nullish(),allowedTools:N(M()).nullish()}).nullish()})).optional(),container:O({id:M().optional(),skills:N(H(`type`,[O({type:F(`anthropic`),skillId:M(),version:M().optional()}),O({type:F(`custom`),providerReference:I(M(),M()),version:M().optional()})])).optional()}).optional(),toolStreaming:R().optional(),effort:U([`low`,`medium`,`high`,`xhigh`,`max`]).optional(),taskBudget:O({type:F(`tokens`),total:E().int().min(2e4),remaining:E().int().min(0).optional()}).optional(),speed:U([`fast`,`standard`]).optional(),inferenceGeo:U([`us`,`global`]).optional(),fallbacks:N(O({model:M(),max_tokens:E().int().optional(),thinking:I(M(),K()).optional(),output_config:I(M(),K()).optional(),speed:U([`fast`,`standard`]).optional()})).optional(),anthropicBeta:N(M()).optional(),contextManagement:O({edits:N(H(`type`,[O({type:F(`clear_tool_uses_20250919`),trigger:H(`type`,[O({type:F(`input_tokens`),value:E()}),O({type:F(`tool_uses`),value:E()})]).optional(),keep:O({type:F(`tool_uses`),value:E()}).optional(),clearAtLeast:O({type:F(`input_tokens`),value:E()}).optional(),clearToolInputs:R().optional(),excludeTools:N(M()).optional()}),O({type:F(`clear_thinking_20251015`),keep:S([F(`all`),O({type:F(`thinking_turns`),value:E()})]).optional()}),O({type:F(`compact_20260112`),trigger:O({type:F(`input_tokens`),value:E()}).optional(),pauseAfterCompaction:R().optional(),instructions:M().optional()})]))}).optional()}),se=4;function ce(e){let t=e?.anthropic;return t?.cacheControl??t?.cache_control}var Q=class{constructor(){this.breakpointCount=0,this.warnings=[]}getCacheControl(e,t){let n=ce(e);if(n){if(!t.canCache){this.warnings.push({type:`unsupported`,feature:`cache_control on non-cacheable context`,details:`cache_control cannot be set on ${t.type}. It will be ignored.`});return}if(this.breakpointCount++,this.breakpointCount>se){this.warnings.push({type:`unsupported`,feature:`cacheControl breakpoint limit`,details:`Maximum ${se} cache breakpoints exceeded (found ${this.breakpointCount}). This breakpoint will be ignored.`});return}return n}}getWarnings(){return this.warnings}},le=i(()=>y(O({model:M(),maxUses:E().optional(),caching:O({type:F(`ephemeral`),ttl:S([F(`5m`),F(`1h`)])}).optional()}))),ue=i(()=>y(H(`type`,[O({type:F(`advisor_result`),text:M()}),O({type:F(`advisor_redacted_result`),encryptedContent:M()}),O({type:F(`advisor_tool_result_error`),errorCode:M()})]))),de=j({id:`anthropic.advisor_20260301`,inputSchema:i(()=>y(O({}).strict())),outputSchema:ue,supportsDeferredResults:!0}),fe=e=>de(e),pe=i(()=>y(O({maxCharacters:E().optional()}))),me=z({id:`anthropic.text_editor_20250728`,inputSchema:i(()=>y(O({command:U([`view`,`create`,`str_replace`,`insert`]),path:M(),file_text:M().optional(),insert_line:E().int().optional(),new_str:M().optional(),insert_text:M().optional(),old_str:M().optional(),view_range:N(E().int()).optional()})))}),he=(e={})=>me(e),ge=i(()=>y(O({maxUses:E().optional(),allowedDomains:N(M()).optional(),blockedDomains:N(M()).optional(),userLocation:O({type:F(`approximate`),city:M().optional(),region:M().optional(),country:M().optional(),timezone:M().optional()}).optional()}))),_e=i(()=>y(N(O({url:M(),title:M().nullable(),pageAge:M().nullable(),encryptedContent:M(),type:F(`web_search_result`)})))),ve=j({id:`anthropic.web_search_20260209`,inputSchema:i(()=>y(O({query:M()}))),outputSchema:_e,supportsDeferredResults:!0}),ye=(e={})=>ve(e),be=i(()=>y(O({maxUses:E().optional(),allowedDomains:N(M()).optional(),blockedDomains:N(M()).optional(),userLocation:O({type:F(`approximate`),city:M().optional(),region:M().optional(),country:M().optional(),timezone:M().optional()}).optional()}))),xe=i(()=>y(N(O({url:M(),title:M().nullable(),pageAge:M().nullable(),encryptedContent:M(),type:F(`web_search_result`)})))),Se=j({id:`anthropic.web_search_20250305`,inputSchema:i(()=>y(O({query:M()}))),outputSchema:xe,supportsDeferredResults:!0}),Ce=(e={})=>Se(e),we=i(()=>y(O({maxUses:E().optional(),allowedDomains:N(M()).optional(),blockedDomains:N(M()).optional(),citations:O({enabled:R()}).optional(),maxContentTokens:E().optional()}))),Te=i(()=>y(O({type:F(`web_fetch_result`),url:M(),content:O({type:F(`document`),title:M().nullable(),citations:O({enabled:R()}).optional(),source:S([O({type:F(`base64`),mediaType:F(`application/pdf`),data:M()}),O({type:F(`text`),mediaType:F(`text/plain`),data:M()})])}),retrievedAt:M().nullable()}))),Ee=j({id:`anthropic.web_fetch_20260209`,inputSchema:i(()=>y(O({url:M()}))),outputSchema:Te,supportsDeferredResults:!0}),De=(e={})=>Ee(e),Oe=i(()=>y(O({maxUses:E().optional(),allowedDomains:N(M()).optional(),blockedDomains:N(M()).optional(),citations:O({enabled:R()}).optional(),maxContentTokens:E().optional()}))),ke=i(()=>y(O({type:F(`web_fetch_result`),url:M(),content:O({type:F(`document`),title:M().nullable(),citations:O({enabled:R()}).optional(),source:S([O({type:F(`base64`),mediaType:F(`application/pdf`),data:M()}),O({type:F(`text`),mediaType:F(`text/plain`),data:M()})])}),retrievedAt:M().nullable()}))),Ae=j({id:`anthropic.web_fetch_20250910`,inputSchema:i(()=>y(O({url:M()}))),outputSchema:ke,supportsDeferredResults:!0}),je=(e={})=>Ae(e);async function Me({tools:e,toolChoice:t,disableParallelToolUse:n,cacheControlValidator:i,supportsStructuredOutput:a,supportsStrictTools:o,defaultEagerInputStreaming:s=!1}){e=e?.length?e:void 0;let c=[],l=new Set,u=i||new Q;if(e==null)return{tools:void 0,toolChoice:void 0,toolWarnings:c,betas:l};let d=[];for(let t of e)switch(t.type){case`function`:{let e=u.getCacheControl(t.providerOptions,{type:`tool definition`,canCache:!0}),n=t.providerOptions?.anthropic,r=n?.eagerInputStreaming??s,i=n?.deferLoading,f=n?.allowedCallers;!o&&t.strict!=null&&c.push({type:`unsupported`,feature:`strict`,details:`Tool '${t.name}' has strict: ${t.strict}, but strict mode is not supported by this provider. The strict property will be ignored.`}),d.push({name:t.name,description:t.description,input_schema:t.inputSchema,cache_control:e,...r?{eager_input_streaming:!0}:{},...o===!0&&t.strict!=null?{strict:t.strict}:{},...i==null?{}:{defer_loading:i},...f==null?{}:{allowed_callers:f},...t.inputExamples==null?{}:{input_examples:t.inputExamples.map(e=>e.input)}}),a===!0&&l.add(`structured-outputs-2025-11-13`),(t.inputExamples!=null||f!=null)&&l.add(`advanced-tool-use-2025-11-20`);break}case`provider`:switch(t.id){case`anthropic.code_execution_20250522`:l.add(`code-execution-2025-05-22`),d.push({type:`code_execution_20250522`,name:`code_execution`,cache_control:void 0});break;case`anthropic.code_execution_20250825`:l.add(`code-execution-2025-08-25`),d.push({type:`code_execution_20250825`,name:`code_execution`});break;case`anthropic.code_execution_20260120`:d.push({type:`code_execution_20260120`,name:`code_execution`});break;case`anthropic.computer_20250124`:l.add(`computer-use-2025-01-24`),d.push({name:`computer`,type:`computer_20250124`,display_width_px:t.args.displayWidthPx,display_height_px:t.args.displayHeightPx,display_number:t.args.displayNumber,cache_control:void 0});break;case`anthropic.computer_20251124`:l.add(`computer-use-2025-11-24`),d.push({name:`computer`,type:`computer_20251124`,display_width_px:t.args.displayWidthPx,display_height_px:t.args.displayHeightPx,display_number:t.args.displayNumber,enable_zoom:t.args.enableZoom,cache_control:void 0});break;case`anthropic.computer_20241022`:l.add(`computer-use-2024-10-22`),d.push({name:`computer`,type:`computer_20241022`,display_width_px:t.args.displayWidthPx,display_height_px:t.args.displayHeightPx,display_number:t.args.displayNumber,cache_control:void 0});break;case`anthropic.text_editor_20250124`:l.add(`computer-use-2025-01-24`),d.push({name:`str_replace_editor`,type:`text_editor_20250124`,cache_control:void 0});break;case`anthropic.text_editor_20241022`:l.add(`computer-use-2024-10-22`),d.push({name:`str_replace_editor`,type:`text_editor_20241022`,cache_control:void 0});break;case`anthropic.text_editor_20250429`:l.add(`computer-use-2025-01-24`),d.push({name:`str_replace_based_edit_tool`,type:`text_editor_20250429`,cache_control:void 0});break;case`anthropic.text_editor_20250728`:{let e=await B({value:t.args,schema:pe});d.push({name:`str_replace_based_edit_tool`,type:`text_editor_20250728`,max_characters:e.maxCharacters,cache_control:void 0});break}case`anthropic.bash_20250124`:l.add(`computer-use-2025-01-24`),d.push({name:`bash`,type:`bash_20250124`,cache_control:void 0});break;case`anthropic.bash_20241022`:l.add(`computer-use-2024-10-22`),d.push({name:`bash`,type:`bash_20241022`,cache_control:void 0});break;case`anthropic.memory_20250818`:l.add(`context-management-2025-06-27`),d.push({name:`memory`,type:`memory_20250818`});break;case`anthropic.web_fetch_20250910`:{l.add(`web-fetch-2025-09-10`);let e=await B({value:t.args,schema:Oe});d.push({type:`web_fetch_20250910`,name:`web_fetch`,max_uses:e.maxUses,allowed_domains:e.allowedDomains,blocked_domains:e.blockedDomains,citations:e.citations,max_content_tokens:e.maxContentTokens,cache_control:void 0});break}case`anthropic.web_fetch_20260209`:{l.add(`code-execution-web-tools-2026-02-09`);let e=await B({value:t.args,schema:we});d.push({type:`web_fetch_20260209`,name:`web_fetch`,max_uses:e.maxUses,allowed_domains:e.allowedDomains,blocked_domains:e.blockedDomains,citations:e.citations,max_content_tokens:e.maxContentTokens,cache_control:void 0});break}case`anthropic.web_search_20250305`:{let e=await B({value:t.args,schema:be});d.push({type:`web_search_20250305`,name:`web_search`,max_uses:e.maxUses,allowed_domains:e.allowedDomains,blocked_domains:e.blockedDomains,user_location:e.userLocation,cache_control:void 0});break}case`anthropic.web_search_20260209`:{l.add(`code-execution-web-tools-2026-02-09`);let e=await B({value:t.args,schema:ge});d.push({type:`web_search_20260209`,name:`web_search`,max_uses:e.maxUses,allowed_domains:e.allowedDomains,blocked_domains:e.blockedDomains,user_location:e.userLocation,cache_control:void 0});break}case`anthropic.tool_search_regex_20251119`:d.push({type:`tool_search_tool_regex_20251119`,name:`tool_search_tool_regex`});break;case`anthropic.tool_search_bm25_20251119`:d.push({type:`tool_search_tool_bm25_20251119`,name:`tool_search_tool_bm25`});break;case`anthropic.advisor_20260301`:{l.add(`advisor-tool-2026-03-01`);let e=await B({value:t.args,schema:le});d.push({type:`advisor_20260301`,name:`advisor`,model:e.model,...e.maxUses!==void 0&&{max_uses:e.maxUses},...e.caching!==void 0&&{caching:e.caching}});break}default:c.push({type:`unsupported`,feature:`provider-defined tool ${t.id}`});break}break;default:c.push({type:`unsupported`,feature:`tool ${t}`});break}if(t==null)return{tools:d,toolChoice:n?{type:`auto`,disable_parallel_tool_use:n}:void 0,toolWarnings:c,betas:l};let f=t.type;switch(f){case`auto`:return{tools:d,toolChoice:{type:`auto`,disable_parallel_tool_use:n},toolWarnings:c,betas:l};case`required`:return{tools:d,toolChoice:{type:`any`,disable_parallel_tool_use:n},toolWarnings:c,betas:l};case`none`:return{tools:void 0,toolChoice:void 0,toolWarnings:c,betas:l};case`tool`:return{tools:d,toolChoice:{type:`tool`,name:t.toolName,disable_parallel_tool_use:n},toolWarnings:c,betas:l};default:throw new r({functionality:`tool choice type: ${f}`})}}function Ne({usage:e,rawUsage:t}){let n=e.cache_creation_input_tokens??0,r=e.cache_read_input_tokens??0,i,a,o=e.iterations?.some(e=>e.type===`fallback_message`);if(e.iterations&&e.iterations.length>0&&!o){let t=e.iterations.filter(e=>e.type===`compaction`||e.type===`message`);if(t.length>0){let e=t.reduce((e,t)=>({input:e.input+t.input_tokens,output:e.output+t.output_tokens}),{input:0,output:0});i=e.input,a=e.output}else i=e.input_tokens,a=e.output_tokens}else i=e.input_tokens,a=e.output_tokens;return{inputTokens:{total:i+n+r,noCache:i,cacheRead:r,cacheWrite:n},outputTokens:{total:a,text:void 0,reasoning:void 0},raw:t??e}}var Pe=i(()=>y(O({type:F(`code_execution_result`),stdout:M(),stderr:M(),return_code:E(),content:N(O({type:F(`code_execution_output`),file_id:M()})).optional().default([])}))),Fe=j({id:`anthropic.code_execution_20250522`,inputSchema:i(()=>y(O({code:M()}))),outputSchema:Pe}),Ie=(e={})=>Fe(e),Le=i(()=>y(H(`type`,[O({type:F(`code_execution_result`),stdout:M(),stderr:M(),return_code:E(),content:N(O({type:F(`code_execution_output`),file_id:M()})).optional().default([])}),O({type:F(`bash_code_execution_result`),content:N(O({type:F(`bash_code_execution_output`),file_id:M()})),stdout:M(),stderr:M(),return_code:E()}),O({type:F(`bash_code_execution_tool_result_error`),error_code:M()}),O({type:F(`text_editor_code_execution_tool_result_error`),error_code:M()}),O({type:F(`text_editor_code_execution_view_result`),content:M(),file_type:M(),num_lines:E().nullable(),start_line:E().nullable(),total_lines:E().nullable()}),O({type:F(`text_editor_code_execution_create_result`),is_file_update:R()}),O({type:F(`text_editor_code_execution_str_replace_result`),lines:N(M()).nullable(),new_lines:E().nullable(),new_start:E().nullable(),old_lines:E().nullable(),old_start:E().nullable()})]))),Re=j({id:`anthropic.code_execution_20250825`,inputSchema:i(()=>y(H(`type`,[O({type:F(`programmatic-tool-call`),code:M()}),O({type:F(`bash_code_execution`),command:M()}),H(`command`,[O({type:F(`text_editor_code_execution`),command:F(`view`),path:M()}),O({type:F(`text_editor_code_execution`),command:F(`create`),path:M(),file_text:M().nullish()}),O({type:F(`text_editor_code_execution`),command:F(`str_replace`),path:M(),old_str:M(),new_str:M()})])]))),outputSchema:Le,supportsDeferredResults:!0}),ze=(e={})=>Re(e),Be=i(()=>y(H(`type`,[O({type:F(`code_execution_result`),stdout:M(),stderr:M(),return_code:E(),content:N(O({type:F(`code_execution_output`),file_id:M()})).optional().default([])}),O({type:F(`encrypted_code_execution_result`),encrypted_stdout:M(),stderr:M(),return_code:E(),content:N(O({type:F(`code_execution_output`),file_id:M()})).optional().default([])}),O({type:F(`bash_code_execution_result`),content:N(O({type:F(`bash_code_execution_output`),file_id:M()})),stdout:M(),stderr:M(),return_code:E()}),O({type:F(`bash_code_execution_tool_result_error`),error_code:M()}),O({type:F(`text_editor_code_execution_tool_result_error`),error_code:M()}),O({type:F(`text_editor_code_execution_view_result`),content:M(),file_type:M(),num_lines:E().nullable(),start_line:E().nullable(),total_lines:E().nullable()}),O({type:F(`text_editor_code_execution_create_result`),is_file_update:R()}),O({type:F(`text_editor_code_execution_str_replace_result`),lines:N(M()).nullable(),new_lines:E().nullable(),new_start:E().nullable(),old_lines:E().nullable(),old_start:E().nullable()})]))),Ve=j({id:`anthropic.code_execution_20260120`,inputSchema:i(()=>y(H(`type`,[O({type:F(`programmatic-tool-call`),code:M()}),O({type:F(`bash_code_execution`),command:M()}),H(`command`,[O({type:F(`text_editor_code_execution`),command:F(`view`),path:M()}),O({type:F(`text_editor_code_execution`),command:F(`create`),path:M(),file_text:M().nullish()}),O({type:F(`text_editor_code_execution`),command:F(`str_replace`),path:M(),old_str:M(),new_str:M()})])]))),outputSchema:Be,supportsDeferredResults:!0}),He=(e={})=>Ve(e),Ue=i(()=>y(N(O({type:F(`tool_reference`),toolName:M()})))),We=j({id:`anthropic.tool_search_regex_20251119`,inputSchema:i(()=>y(O({pattern:M(),limit:E().optional()}))),outputSchema:Ue,supportsDeferredResults:!0}),Ge=(e={})=>We(e);function Ke(e){return typeof e==`string`?new TextDecoder().decode(ee(e)):new TextDecoder().decode(e)}function qe(e){try{if(typeof e==`string`)return JSON.parse(e);if(typeof e==`object`&&e)return e}catch{let t=e?.errorCode;return{errorCode:typeof t==`string`?t:`unavailable`}}return{}}async function Je({prompt:e,sendReasoning:t,warnings:n,cacheControlValidator:i,toolNameMapping:a}){let c=new Set,u=Ye(e),f=i||new Q,p,m=[];async function h(e){return(await d({provider:`anthropic`,providerOptions:e,schema:Z}))?.citations?.enabled??!1}async function g(e){return(await d({provider:`anthropic`,providerOptions:e,schema:Z}))?.containerUpload??!1}async function _(e){let t=await d({provider:`anthropic`,providerOptions:e,schema:Z});return{title:t?.title,context:t?.context}}for(let e=0;e<u.length;e++){let i=u[e],y=e===u.length-1,b=i.type;switch(b){case`system`:{let e=i.messages.map(({content:e,providerOptions:t})=>({type:`text`,text:e,cache_control:f.getCacheControl(t,{type:`system message`,canCache:!0})}));p==null?p=e:(m.push({role:`system`,content:e}),c.add(`mid-conversation-system-2026-04-07`));break}case`user`:{let e=[];for(let t of i.messages){let{role:i,content:a}=t;switch(i){case`user`:for(let n=0;n<a.length;n++){let i=a[n],s=n===a.length-1,u=f.getCacheControl(i.providerOptions,{type:`user message part`,canCache:!0})??(s?f.getCacheControl(t.providerOptions,{type:`user message`,canCache:!0}):void 0);switch(i.type){case`text`:e.push({type:`text`,text:i.text,cache_control:u});break;case`file`:switch(i.data.type){case`reference`:{let t=l({reference:i.data.reference,provider:`anthropic`});c.add(`files-api-2025-04-14`),await g(i.providerOptions)?e.push({type:`container_upload`,file_id:t}):o(i.mediaType)===`image`?e.push({type:`image`,source:{type:`file`,file_id:t},cache_control:u}):e.push({type:`document`,source:{type:`file`,file_id:t},cache_control:u});break}case`text`:{let t=await h(i.providerOptions),n=await _(i.providerOptions);e.push({type:`document`,source:{type:`text`,media_type:`text/plain`,data:i.data.text},title:n.title??i.filename,...n.context&&{context:n.context},...t&&{citations:{enabled:!0}},cache_control:u});break}case`url`:case`data`:{let t=o(i.mediaType);if(t===`image`)e.push({type:`image`,source:i.data.type===`url`?{type:`url`,url:i.data.url.toString()}:{type:`base64`,media_type:v({part:i}),data:L(i.data.data)},cache_control:u});else if(t===`application`&&(i.data.type===`url`?i.mediaType===`application/pdf`:v({part:i})===`application/pdf`)){c.add(`pdfs-2024-09-25`);let t=await h(i.providerOptions),n=await _(i.providerOptions);e.push({type:`document`,source:i.data.type===`url`?{type:`url`,url:i.data.url.toString()}:{type:`base64`,media_type:`application/pdf`,data:L(i.data.data)},title:n.title??i.filename,...n.context&&{context:n.context},...t&&{citations:{enabled:!0}},cache_control:u})}else if(i.mediaType===`text/plain`){let t=await h(i.providerOptions),n=await _(i.providerOptions);e.push({type:`document`,source:i.data.type===`url`?{type:`url`,url:i.data.url.toString()}:{type:`text`,media_type:`text/plain`,data:Ke(i.data.data)},title:n.title??i.filename,...n.context&&{context:n.context},...t&&{citations:{enabled:!0}},cache_control:u})}else throw new r({functionality:`media type: ${i.mediaType}`});break}}break}}break;case`tool`:for(let r=0;r<a.length;r++){let i=a[r];if(i.type===`tool-approval-response`)continue;let l=i.output,u=`providerOptions`in l?l.providerOptions:l.type===`content`?l.value.find(e=>e.providerOptions!=null)?.providerOptions:void 0,d=r===a.length-1,p=f.getCacheControl(i.providerOptions,{type:`tool result part`,canCache:!0})??f.getCacheControl(u,{type:`tool result output`,canCache:!0})??(d?f.getCacheControl(t.providerOptions,{type:`tool result message`,canCache:!0}):void 0),m;switch(l.type){case`content`:m=l.value.map(e=>{switch(e.type){case`text`:return{type:`text`,text:e.text};case`file`:{let t=o(e.mediaType);if(e.data.type===`url`)return t===`image`?{type:`image`,source:{type:`url`,url:e.data.url.toString()}}:{type:`document`,source:{type:`url`,url:e.data.url.toString()}};if(e.data.type===`data`){if(t===`image`)return{type:`image`,source:{type:`base64`,media_type:v({part:e}),data:L(e.data.data)}};if(v({part:e})===`application/pdf`)return c.add(`pdfs-2024-09-25`),{type:`document`,source:{type:`base64`,media_type:`application/pdf`,data:L(e.data.data)}};n.push({type:`other`,message:`unsupported tool content part type: ${e.type} with media type: ${e.mediaType}`});return}n.push({type:`other`,message:`unsupported tool content part type: ${e.type} with data type: ${e.data.type}`});return}case`custom`:{let t=e.providerOptions?.anthropic;if(t?.type===`tool-reference`)return{type:`tool_reference`,tool_name:t.toolName};n.push({type:`other`,message:`unsupported custom tool content part`});return}default:n.push({type:`other`,message:`unsupported tool content part type: ${e.type}`});return}}).filter(s);break;case`text`:case`error-text`:m=l.value;break;case`execution-denied`:m=l.reason??`Tool call execution denied.`;break;default:m=JSON.stringify(l.value);break}e.push({type:`tool_result`,tool_use_id:i.toolCallId,content:m,is_error:l.type===`error-text`||l.type===`error-json`?!0:void 0,cache_control:p})}break;default:throw Error(`Unsupported role: ${i}`)}}m.push({role:`user`,content:e});break}case`assistant`:{let e=[],r=new Set;for(let o=0;o<i.messages.length;o++){let s=i.messages[o],c=o===i.messages.length-1,{content:l}=s;for(let i=0;i<l.length;i++){let o=l[i],u=i===l.length-1,p=f.getCacheControl(o.providerOptions,{type:`assistant message part`,canCache:!0})??(u?f.getCacheControl(s.providerOptions,{type:`assistant message`,canCache:!0}):void 0);switch(o.type){case`text`:o.providerOptions?.anthropic?.type===`compaction`?e.push({type:`compaction`,content:o.text,cache_control:p}):e.push({type:`text`,text:y&&c&&u?o.text.trim():o.text,cache_control:p});break;case`reasoning`:if(t){let t=await d({provider:`anthropic`,providerOptions:o.providerOptions,schema:ae});t==null?n.push({type:`other`,message:`unsupported reasoning metadata`}):t.signature==null?t.redactedData==null?n.push({type:`other`,message:`unsupported reasoning metadata`}):(f.getCacheControl(o.providerOptions,{type:`redacted thinking block`,canCache:!1}),e.push({type:`redacted_thinking`,data:t.redactedData})):(f.getCacheControl(o.providerOptions,{type:`thinking block`,canCache:!1}),e.push({type:`thinking`,thinking:o.text,signature:t.signature}))}else n.push({type:`other`,message:`sending reasoning content is disabled for this model`});break;case`tool-call`:{if(o.providerExecuted){let t=a.toProviderToolName(o.toolName);if(o.providerOptions?.anthropic?.type===`mcp-tool-use`){r.add(o.toolCallId);let t=o.providerOptions?.anthropic?.serverName;if(t==null||typeof t!=`string`){n.push({type:`other`,message:`mcp tool use server name is required and must be a string`});break}e.push({type:`mcp_tool_use`,id:o.toolCallId,name:o.toolName,input:o.input,server_name:t,cache_control:p})}else if(t===`code_execution`&&o.input!=null&&typeof o.input==`object`&&`type`in o.input&&typeof o.input.type==`string`&&(o.input.type===`bash_code_execution`||o.input.type===`text_editor_code_execution`))e.push({type:`server_tool_use`,id:o.toolCallId,name:o.input.type,input:o.input,cache_control:p});else if(t===`code_execution`&&o.input!=null&&typeof o.input==`object`&&`type`in o.input&&o.input.type===`programmatic-tool-call`){let{type:t,...n}=o.input;e.push({type:`server_tool_use`,id:o.toolCallId,name:`code_execution`,input:n,cache_control:p})}else t===`code_execution`||t===`web_fetch`||t===`web_search`||t===`tool_search_tool_regex`||t===`tool_search_tool_bm25`?e.push({type:`server_tool_use`,id:o.toolCallId,name:t,input:o.input,cache_control:p}):t===`advisor`?e.push({type:`server_tool_use`,id:o.toolCallId,name:`advisor`,input:{},cache_control:p}):n.push({type:`other`,message:`provider executed tool call for tool ${o.toolName} is not supported`});break}let t=o.providerOptions?.anthropic,i=t?.caller?(t.caller.type===`code_execution_20250825`||t.caller.type===`code_execution_20260120`)&&t.caller.toolId?{type:t.caller.type,tool_id:t.caller.toolId}:t.caller.type===`direct`?{type:`direct`}:void 0:void 0;e.push({type:`tool_use`,id:o.toolCallId,name:o.toolName,input:o.input,...i&&{caller:i},cache_control:p});break}case`tool-result`:{let t=a.toProviderToolName(o.toolName);if(r.has(o.toolCallId)){let t=o.output;if(t.type!==`json`&&t.type!==`error-json`){n.push({type:`other`,message:`provider executed tool result output type ${t.type} for tool ${o.toolName} is not supported`});break}e.push({type:`mcp_tool_result`,tool_use_id:o.toolCallId,is_error:t.type===`error-json`,content:t.value,cache_control:p})}else if(t===`code_execution`){let t=o.output;if(t.type===`error-text`||t.type===`error-json`){let n={};try{typeof t.value==`string`?n=JSON.parse(t.value):typeof t.value==`object`&&t.value!==null&&(n=t.value)}catch{}n.type===`code_execution_tool_result_error`?e.push({type:`code_execution_tool_result`,tool_use_id:o.toolCallId,content:{type:`code_execution_tool_result_error`,error_code:n.errorCode??`unknown`},cache_control:p}):e.push({type:`bash_code_execution_tool_result`,tool_use_id:o.toolCallId,cache_control:p,content:{type:`bash_code_execution_tool_result_error`,error_code:n.errorCode??`unknown`}});break}if(t.type!==`json`){n.push({type:`other`,message:`provider executed tool result output type ${t.type} for tool ${o.toolName} is not supported`});break}if(t.value==null||typeof t.value!=`object`||!(`type`in t.value)||typeof t.value.type!=`string`){n.push({type:`other`,message:`provider executed tool result output value is not a valid code execution result for tool ${o.toolName}`});break}if(t.value.type===`code_execution_result`){let n=await B({value:t.value,schema:Pe});e.push({type:`code_execution_tool_result`,tool_use_id:o.toolCallId,content:{type:n.type,stdout:n.stdout,stderr:n.stderr,return_code:n.return_code,content:n.content??[]},cache_control:p})}else if(t.value.type===`encrypted_code_execution_result`){let n=await B({value:t.value,schema:Be});n.type===`encrypted_code_execution_result`&&e.push({type:`code_execution_tool_result`,tool_use_id:o.toolCallId,content:{type:n.type,encrypted_stdout:n.encrypted_stdout,stderr:n.stderr,return_code:n.return_code,content:n.content??[]},cache_control:p})}else{let n=await B({value:t.value,schema:Le});n.type===`code_execution_result`?e.push({type:`code_execution_tool_result`,tool_use_id:o.toolCallId,content:{type:n.type,stdout:n.stdout,stderr:n.stderr,return_code:n.return_code,content:n.content??[]},cache_control:p}):n.type===`bash_code_execution_result`||n.type===`bash_code_execution_tool_result_error`?e.push({type:`bash_code_execution_tool_result`,tool_use_id:o.toolCallId,cache_control:p,content:n}):e.push({type:`text_editor_code_execution_tool_result`,tool_use_id:o.toolCallId,cache_control:p,content:n})}break}if(t===`web_fetch`){let t=o.output;if(t.type===`error-json`){e.push({type:`web_fetch_tool_result`,tool_use_id:o.toolCallId,content:{type:`web_fetch_tool_result_error`,error_code:qe(t.value).errorCode??`unavailable`},cache_control:p});break}if(t.type!==`json`){n.push({type:`other`,message:`provider executed tool result output type ${t.type} for tool ${o.toolName} is not supported`});break}let r=await B({value:t.value,schema:ke});e.push({type:`web_fetch_tool_result`,tool_use_id:o.toolCallId,content:{type:`web_fetch_result`,url:r.url,retrieved_at:r.retrievedAt,content:{type:`document`,title:r.content.title,citations:r.content.citations,source:{type:r.content.source.type,media_type:r.content.source.mediaType,data:r.content.source.data}}},cache_control:p});break}if(t===`web_search`){let t=o.output;if(t.type===`error-json`){e.push({type:`web_search_tool_result`,tool_use_id:o.toolCallId,content:{type:`web_search_tool_result_error`,error_code:qe(t.value).errorCode??`unavailable`},cache_control:p});break}if(t.type!==`json`){n.push({type:`other`,message:`provider executed tool result output type ${t.type} for tool ${o.toolName} is not supported`});break}let r=await B({value:t.value,schema:xe});e.push({type:`web_search_tool_result`,tool_use_id:o.toolCallId,content:r.map(e=>({url:e.url,title:e.title,page_age:e.pageAge,encrypted_content:e.encryptedContent,type:e.type})),cache_control:p});break}if(t===`tool_search_tool_regex`||t===`tool_search_tool_bm25`){let t=o.output;if(t.type!==`json`){n.push({type:`other`,message:`provider executed tool result output type ${t.type} for tool ${o.toolName} is not supported`});break}let r=(await B({value:t.value,schema:Ue})).map(e=>({type:`tool_reference`,tool_name:e.toolName}));e.push({type:`tool_search_tool_result`,tool_use_id:o.toolCallId,content:{type:`tool_search_tool_search_result`,tool_references:r},cache_control:p});break}if(t===`advisor`){let t=o.output;if(t.type!==`json`&&t.type!==`error-json`){n.push({type:`other`,message:`provider executed tool result output type ${t.type} for tool ${o.toolName} is not supported`});break}let r=await B({value:t.value,schema:ue});r.type===`advisor_result`?e.push({type:`advisor_tool_result`,tool_use_id:o.toolCallId,content:{type:`advisor_result`,text:r.text},cache_control:p}):r.type===`advisor_redacted_result`?e.push({type:`advisor_tool_result`,tool_use_id:o.toolCallId,content:{type:`advisor_redacted_result`,encrypted_content:r.encryptedContent},cache_control:p}):e.push({type:`advisor_tool_result`,tool_use_id:o.toolCallId,content:{type:`advisor_tool_result_error`,error_code:r.errorCode},cache_control:p});break}n.push({type:`other`,message:`provider executed tool result for tool ${o.toolName} is not supported`});break}}}}m.push({role:`assistant`,content:Xe(e)});break}default:throw Error(`content type: ${b}`)}}return{prompt:{system:p,messages:m},betas:c}}function Ye(e){let t=[],n;for(let r of e){let{role:e}=r;switch(e){case`system`:n?.type!==`system`&&(n={type:`system`,messages:[]},t.push(n)),n.messages.push(r);break;case`assistant`:n?.type!==`assistant`&&(n={type:`assistant`,messages:[]},t.push(n)),n.messages.push(r);break;case`user`:n?.type!==`user`&&(n={type:`user`,messages:[]},t.push(n)),n.messages.push(r);break;case`tool`:n?.type!==`user`&&(n={type:`user`,messages:[]},t.push(n)),n.messages.push(r);break;default:throw Error(`Unsupported role: ${e}`)}}return t}function Xe(e){let t=[],n=[];function r(){t.push(...n.filter(e=>e.type!==`tool_use`),...n.filter(e=>e.type===`tool_use`)),n=[]}for(let i of e)i.type===`thinking`||i.type===`redacted_thinking`?(r(),t.push(i)):n.push(i);return r(),t}function Ze({finishReason:e,isJsonResponseFromTool:t}){switch(e){case`pause_turn`:case`end_turn`:case`stop_sequence`:return`stop`;case`refusal`:return`content-filter`;case`tool_use`:return t?`stop`:`tool-calls`;case`max_tokens`:case`model_context_window_exceeded`:return`length`;case`compaction`:return`other`;default:return`other`}}var Qe=new Set([`date-time`,`time`,`date`,`duration`,`email`,`hostname`,`uri`,`ipv4`,`ipv6`,`uuid`]),$e=[`minimum`,`maximum`,`exclusiveMinimum`,`exclusiveMaximum`,`multipleOf`,`minLength`,`maxLength`,`pattern`,`minItems`,`maxItems`,`uniqueItems`,`minProperties`,`maxProperties`,`not`];function et(e){return tt(e)}function $(e){return typeof e==`boolean`||!at(e)?e:tt(e)}function tt(e){let t={},n=e;if(e.$ref!=null)return{$ref:e.$ref};if(e.$schema!=null&&(t.$schema=e.$schema),e.$id!=null&&(t.$id=e.$id),e.title!=null&&(t.title=e.title),e.description!=null&&(t.description=e.description),e.default!==void 0&&(t.default=e.default),e.const!==void 0&&(t.const=e.const),e.enum!=null&&(t.enum=e.enum),e.type!=null&&(t.type=e.type),e.anyOf==null?e.oneOf!=null&&(t.anyOf=e.oneOf.map($)):t.anyOf=e.anyOf.map($),e.allOf!=null&&(t.allOf=e.allOf.map($)),e.definitions!=null&&(t.definitions=Object.fromEntries(Object.entries(e.definitions).map(([e,t])=>[e,$(t)]))),n.$defs!=null){let e=t;e.$defs=Object.fromEntries(Object.entries(n.$defs).map(([e,t])=>[e,$(t)]))}(e.type===`object`||e.properties!=null)&&(e.properties!=null&&(t.properties=Object.fromEntries(Object.entries(e.properties).map(([e,t])=>[e,$(t)]))),t.additionalProperties=!1,e.required!=null&&(t.required=e.required)),e.items!=null&&(t.items=Array.isArray(e.items)?e.items.map($):$(e.items)),typeof e.format==`string`&&Qe.has(e.format)&&(t.format=e.format);let r=nt(e);return r!=null&&(t.description=t.description==null?r:`${t.description}
|
|
2
|
-
${r}`),t}function nt(e){let t=$e.flatMap(t=>{let n=e[t];return n==null||n===!1?[]:`${rt(t)}: ${it(n)}`});return typeof e.format==`string`&&!Qe.has(e.format)&&t.push(`format: ${e.format}`),t.length===0?void 0:`${t.join(`; `)}.`}function rt(e){return e.replace(/[A-Z]/g,e=>` ${e.toLowerCase()}`)}function it(e){return typeof e==`string`?e:JSON.stringify(e)}function at(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ot(e,t,n){if(e.type===`web_search_result_location`)return{type:`source`,sourceType:`url`,id:n(),url:e.url,title:e.title,providerMetadata:{anthropic:{citedText:e.cited_text,encryptedIndex:e.encrypted_index}}};if(e.type!==`page_location`&&e.type!==`char_location`)return;let r=t[e.document_index];if(r)return{type:`source`,sourceType:`document`,id:n(),mediaType:r.mediaType,title:e.document_title??r.title,filename:r.filename,providerMetadata:{anthropic:e.type===`page_location`?{citedText:e.cited_text,startPageNumber:e.start_page_number,endPageNumber:e.end_page_number}:{citedText:e.cited_text,startCharIndex:e.start_char_index,endCharIndex:e.end_char_index}}}}var st=class t{constructor(e,t){this.specificationVersion=`v4`,this.modelId=e,this.config=t,this.generateId=t.generateId??w}static[h](e){return c({modelId:e.modelId,config:e.config})}static[x](e){return new t(e.modelId,e.config)}supportsUrl(e){return e.protocol===`https:`}get provider(){return this.config.provider}get providerOptionsName(){let e=this.config.provider,t=e.indexOf(`.`);return t===-1?e:e.substring(0,t)}get supportedUrls(){var e;return(e=this.config).supportedUrls?.call(e)??{}}async getArgs({userSuppliedBetas:e,prompt:t,maxOutputTokens:n,temperature:r,topP:i,topK:a,frequencyPenalty:o,presencePenalty:s,stopSequences:c,responseFormat:u,seed:f,tools:p,toolChoice:m,reasoning:h,providerOptions:g,stream:v}){let y=[];o!=null&&y.push({type:`unsupported`,feature:`frequencyPenalty`}),s!=null&&y.push({type:`unsupported`,feature:`presencePenalty`}),f!=null&&y.push({type:`unsupported`,feature:`seed`}),r!=null&&r>1?(y.push({type:`unsupported`,feature:`temperature`,details:`${r} exceeds anthropic maximum of 1.0. clamped to 1.0`}),r=1):r!=null&&r<0&&(y.push({type:`unsupported`,feature:`temperature`,details:`${r} is below anthropic minimum of 0. clamped to 0`}),r=0),u?.type===`json`&&(u.schema??y.push({type:`unsupported`,feature:`responseFormat`,details:`JSON response format requires a schema. The response format is ignored.`}));let b=this.providerOptionsName,x=await d({provider:`anthropic`,providerOptions:g,schema:oe}),S=b===`anthropic`?null:await d({provider:b,providerOptions:g,schema:oe}),C=S!=null,w=Object.assign({},x??{},S??{}),{maxOutputTokens:T,supportsStructuredOutput:E,supportsAdaptiveThinking:D,rejectsSamplingParameters:O,supportsXhighEffort:A,isKnownModel:j}=ct(this.modelId);O&&(r!=null&&(y.push({type:`unsupported`,feature:`temperature`,details:`temperature is not supported by ${this.modelId} and will be ignored`}),r=void 0),a!=null&&(y.push({type:`unsupported`,feature:`topK`,details:`topK is not supported by ${this.modelId} and will be ignored`}),a=void 0),i!=null&&(y.push({type:`unsupported`,feature:`topP`,details:`topP is not supported by ${this.modelId} and will be ignored`}),i=void 0));let M=j||this.modelId.startsWith(`claude-`),ee=(this.config.supportsNativeStructuredOutput??!0)&&E,N=(this.config.supportsStrictTools??!0)&&E,P=w?.structuredOutputMode??`auto`,F=P===`outputFormat`||P===`auto`&&ee,I=u?.type===`json`&&u.schema!=null&&!F?{type:`function`,name:`json`,description:`Respond with a JSON object.`,inputSchema:u.schema}:void 0,L=w?.contextManagement,R=new Q,z=k({tools:p,providerToolNames:{"anthropic.code_execution_20250522":`code_execution`,"anthropic.code_execution_20250825":`code_execution`,"anthropic.code_execution_20260120":`code_execution`,"anthropic.computer_20241022":`computer`,"anthropic.computer_20250124":`computer`,"anthropic.text_editor_20241022":`str_replace_editor`,"anthropic.text_editor_20250124":`str_replace_editor`,"anthropic.text_editor_20250429":`str_replace_based_edit_tool`,"anthropic.text_editor_20250728":`str_replace_based_edit_tool`,"anthropic.bash_20241022":`bash`,"anthropic.bash_20250124":`bash`,"anthropic.memory_20250818":`memory`,"anthropic.web_search_20250305":`web_search`,"anthropic.web_search_20260209":`web_search`,"anthropic.web_fetch_20250910":`web_fetch`,"anthropic.web_fetch_20260209":`web_fetch`,"anthropic.tool_search_regex_20251119":`tool_search_tool_regex`,"anthropic.tool_search_bm25_20251119":`tool_search_tool_bm25`,"anthropic.advisor_20260301":`advisor`}}),{prompt:B,betas:V}=await Je({prompt:t,sendReasoning:w?.sendReasoning??!0,warnings:y,cacheControlValidator:R,toolNameMapping:z});if(_(h)&&w?.effort==null){let e=ut({reasoning:h,supportsAdaptiveThinking:D,supportsXhighEffort:A,maxOutputTokensForModel:T,warnings:y});e!=null&&(w.thinking??=e.thinking,e.effort!=null&&w.thinking?.type!==`disabled`&&(w.effort=e.effort))}let H=w?.thinking?.type,U=H===`enabled`||H===`adaptive`,W=H===`enabled`?w?.thinking?.budgetTokens:void 0,G=H===`adaptive`?w?.thinking?.display:void 0,K=n??T,q={model:this.modelId,max_tokens:K,temperature:r,top_k:a,top_p:i,stop_sequences:c,...U&&{thinking:{type:H,...W!=null&&{budget_tokens:W},...G!=null&&{display:G}}},...(w?.effort||w?.taskBudget||F&&u?.type===`json`&&u.schema!=null)&&{output_config:{...w?.effort&&{effort:w.effort},...w?.taskBudget&&{task_budget:{type:w.taskBudget.type,total:w.taskBudget.total,...w.taskBudget.remaining!=null&&{remaining:w.taskBudget.remaining}}},...F&&u?.type===`json`&&u.schema!=null&&{format:{type:`json_schema`,schema:et(u.schema)}}}},...w?.speed&&{speed:w.speed},...w?.inferenceGeo&&{inference_geo:w.inferenceGeo},...w?.fallbacks&&w.fallbacks.length>0&&{fallbacks:w.fallbacks},...w?.cacheControl&&{cache_control:w.cacheControl},...w?.metadata?.userId!=null&&{metadata:{user_id:w.metadata.userId}},...w?.mcpServers&&w.mcpServers.length>0&&{mcp_servers:w.mcpServers.map(e=>({type:e.type,name:e.name,url:e.url,authorization_token:e.authorizationToken,tool_configuration:e.toolConfiguration?{allowed_tools:e.toolConfiguration.allowedTools,enabled:e.toolConfiguration.enabled}:void 0}))},...w?.container&&{container:w.container.skills&&w.container.skills.length>0?{id:w.container.id,skills:w.container.skills.map(e=>({type:e.type,skill_id:e.type===`custom`?l({reference:e.providerReference,provider:`anthropic`}):e.skillId,version:e.version}))}:w.container.id},system:B.system,messages:B.messages,...L&&{context_management:{edits:L.edits.map(e=>{let t=e.type;switch(t){case`clear_tool_uses_20250919`:return{type:e.type,...e.trigger!==void 0&&{trigger:e.trigger},...e.keep!==void 0&&{keep:e.keep},...e.clearAtLeast!==void 0&&{clear_at_least:e.clearAtLeast},...e.clearToolInputs!==void 0&&{clear_tool_inputs:e.clearToolInputs},...e.excludeTools!==void 0&&{exclude_tools:e.excludeTools}};case`clear_thinking_20251015`:return{type:e.type,...e.keep!==void 0&&{keep:e.keep}};case`compact_20260112`:return{type:e.type,...e.trigger!==void 0&&{trigger:e.trigger},...e.pauseAfterCompaction!==void 0&&{pause_after_compaction:e.pauseAfterCompaction},...e.instructions!==void 0&&{instructions:e.instructions}};default:y.push({type:`other`,message:`Unknown context management strategy: ${t}`});return}}).filter(e=>e!==void 0)}}};U?(H===`enabled`&&W==null&&(y.push({type:`compatibility`,feature:`extended thinking`,details:`thinking budget is required when thinking is enabled. using default budget of 1024 tokens.`}),q.thinking={type:`enabled`,budget_tokens:1024},W=1024),q.temperature!=null&&(q.temperature=void 0,y.push({type:`unsupported`,feature:`temperature`,details:`temperature is not supported when thinking is enabled`})),a!=null&&(q.top_k=void 0,y.push({type:`unsupported`,feature:`topK`,details:`topK is not supported when thinking is enabled`})),i!=null&&(q.top_p=void 0,y.push({type:`unsupported`,feature:`topP`,details:`topP is not supported when thinking is enabled`})),q.max_tokens=K+(W??0)):M&&i!=null&&r!=null&&(y.push({type:`unsupported`,feature:`topP`,details:`topP is not supported when temperature is set. topP is ignored.`}),q.top_p=void 0),j&&q.max_tokens>T&&(n!=null&&y.push({type:`unsupported`,feature:`maxOutputTokens`,details:`${q.max_tokens} (maxOutputTokens + thinkingBudget) is greater than ${this.modelId} ${T} max output tokens. The max output tokens have been limited to ${T}.`}),q.max_tokens=T),w?.mcpServers&&w.mcpServers.length>0&&V.add(`mcp-client-2025-04-04`),L&&(V.add(`context-management-2025-06-27`),L.edits.some(e=>e.type===`compact_20260112`)&&V.add(`compact-2026-01-12`)),w?.container&&w.container.skills&&w.container.skills.length>0&&(V.add(`code-execution-2025-08-25`),V.add(`skills-2025-10-02`),V.add(`files-api-2025-04-14`),p?.some(e=>e.type===`provider`&&(e.id===`anthropic.code_execution_20250825`||e.id===`anthropic.code_execution_20260120`))||y.push({type:`other`,message:`code execution tool is required when using skills`})),w?.taskBudget&&V.add(`task-budgets-2026-03-13`),w?.speed===`fast`&&V.add(`fast-mode-2026-02-01`),w?.fallbacks&&w.fallbacks.length>0&&V.add(`server-side-fallback-2026-06-01`);let J=v&&(w?.toolStreaming??!0),{tools:Y,toolChoice:te,toolWarnings:ne,betas:X}=await Me(I==null?{tools:p??[],toolChoice:m,disableParallelToolUse:w?.disableParallelToolUse,cacheControlValidator:R,supportsStructuredOutput:ee,supportsStrictTools:N,defaultEagerInputStreaming:J}:{tools:[...p??[],I],toolChoice:{type:`required`},disableParallelToolUse:!0,cacheControlValidator:R,supportsStructuredOutput:!1,supportsStrictTools:N,defaultEagerInputStreaming:J}),re=R.getWarnings();return{args:{...q,tools:Y,tool_choice:te,stream:v===!0?!0:void 0},warnings:[...y,...ne,...re],betas:new Set([...V,...X,...e,...w?.anthropicBeta??[]]),usesJsonResponseTool:I!=null,toolNameMapping:z,providerOptionsName:b,usedCustomProviderKey:C}}async getHeaders({betas:e,headers:t}){return V(this.config.headers?await a(this.config.headers):void 0,t,e.size>0?{"anthropic-beta":Array.from(e).join(`,`)}:{})}async getBetasFromHeaders(e){let t=(this.config.headers?await a(this.config.headers):void 0)?.[`anthropic-beta`]??``,n=e?.[`anthropic-beta`]??``;return new Set([...t.toLowerCase().split(`,`),...n.toLowerCase().split(`,`)].map(e=>e.trim()).filter(e=>e!==``))}buildRequestUrl(e){var t;return(t=this.config).buildRequestUrl?.call(t,this.config.baseURL,e)??`${this.config.baseURL}/messages`}transformRequestBody(e,t){var n;return(n=this.config).transformRequestBody?.call(n,e,t)??e}extractCitationDocuments(e){return e.filter(e=>e.role===`user`).flatMap(e=>e.content).filter(e=>e.type!==`file`||e.mediaType!==`application/pdf`&&e.mediaType!==`text/plain`?!1:e.providerOptions?.anthropic?.citations?.enabled??!1).map(e=>{let t=e;return{title:t.filename??`Untitled Document`,filename:t.filename,mediaType:t.mediaType}})}async doGenerate(e){let{args:t,warnings:n,betas:r,usesJsonResponseTool:i,toolNameMapping:a,providerOptionsName:o,usedCustomProviderKey:s}=await this.getArgs({...e,stream:!1,userSuppliedBetas:await this.getBetasFromHeaders(e.headers)}),c=[...this.extractCitationDocuments(e.prompt)],l=lt(t.tools),{responseHeaders:u,value:d,rawValue:f}=await J({url:this.buildRequestUrl(!1),headers:await this.getHeaders({betas:r,headers:e.headers}),body:this.transformRequestBody(t,r),failedResponseHandler:Y,successfulResponseHandler:D(re),abortSignal:e.abortSignal,fetch:this.config.fetch}),p=[],m={},h={},g=!1;for(let e of d.content)switch(e.type){case`text`:if(!i&&(p.push({type:`text`,text:e.text}),e.citations))for(let t of e.citations){let e=ot(t,c,this.generateId);e&&p.push(e)}break;case`thinking`:p.push({type:`reasoning`,text:e.thinking,providerMetadata:{anthropic:{signature:e.signature}}});break;case`redacted_thinking`:p.push({type:`reasoning`,text:``,providerMetadata:{anthropic:{redactedData:e.data}}});break;case`compaction`:p.push({type:`text`,text:e.content,providerMetadata:{anthropic:{type:`compaction`}}});break;case`tool_use`:if(i&&e.name===`json`)g=!0,p.push({type:`text`,text:JSON.stringify(e.input)});else{let t=e.caller,n=t?{type:t.type,toolId:`tool_id`in t?t.tool_id:void 0}:void 0;p.push({type:`tool-call`,toolCallId:e.id,toolName:e.name,input:JSON.stringify(e.input),...n&&{providerMetadata:{anthropic:{caller:n}}}})}break;case`server_tool_use`:if(e.name===`text_editor_code_execution`||e.name===`bash_code_execution`)p.push({type:`tool-call`,toolCallId:e.id,toolName:a.toCustomToolName(`code_execution`),input:JSON.stringify({type:e.name,...e.input}),providerExecuted:!0,...l?{dynamic:!0}:{}});else if(e.name===`web_search`||e.name===`code_execution`||e.name===`web_fetch`){let t=e.name===`code_execution`&&e.input!=null&&typeof e.input==`object`&&`code`in e.input&&!(`type`in e.input)?{type:`programmatic-tool-call`,...e.input}:e.input;p.push({type:`tool-call`,toolCallId:e.id,toolName:a.toCustomToolName(e.name),input:JSON.stringify(t),providerExecuted:!0,...l&&e.name===`code_execution`?{dynamic:!0}:{}})}else e.name===`tool_search_tool_regex`||e.name===`tool_search_tool_bm25`?(h[e.id]=e.name,p.push({type:`tool-call`,toolCallId:e.id,toolName:a.toCustomToolName(e.name),input:JSON.stringify(e.input),providerExecuted:!0})):e.name===`advisor`&&p.push({type:`tool-call`,toolCallId:e.id,toolName:a.toCustomToolName(`advisor`),input:JSON.stringify(e.input),providerExecuted:!0});break;case`mcp_tool_use`:m[e.id]={type:`tool-call`,toolCallId:e.id,toolName:e.name,input:JSON.stringify(e.input),providerExecuted:!0,dynamic:!0,providerMetadata:{anthropic:{type:`mcp-tool-use`,serverName:e.server_name}}},p.push(m[e.id]);break;case`mcp_tool_result`:p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:m[e.tool_use_id].toolName,isError:e.is_error,result:e.content,dynamic:!0,providerMetadata:m[e.tool_use_id].providerMetadata});break;case`web_fetch_tool_result`:e.content.type===`web_fetch_result`?(c.push({title:e.content.content.title??e.content.url,mediaType:e.content.content.source.media_type}),p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`web_fetch`),result:{type:`web_fetch_result`,url:e.content.url,retrievedAt:e.content.retrieved_at,content:{type:e.content.content.type,title:e.content.content.title,citations:e.content.content.citations,source:{type:e.content.content.source.type,mediaType:e.content.content.source.media_type,data:e.content.content.source.data}}}})):e.content.type===`web_fetch_tool_result_error`&&p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`web_fetch`),isError:!0,result:{type:`web_fetch_tool_result_error`,errorCode:e.content.error_code}});break;case`web_search_tool_result`:if(Array.isArray(e.content)){p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`web_search`),result:e.content.map(e=>({url:e.url,title:e.title,pageAge:e.page_age??null,encryptedContent:e.encrypted_content,type:e.type}))});for(let t of e.content)p.push({type:`source`,sourceType:`url`,id:this.generateId(),url:t.url,title:t.title,providerMetadata:{anthropic:{pageAge:t.page_age??null}}})}else p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`web_search`),isError:!0,result:{type:`web_search_tool_result_error`,errorCode:e.content.error_code}});break;case`code_execution_tool_result`:e.content.type===`code_execution_result`?p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`code_execution`),result:{type:e.content.type,stdout:e.content.stdout,stderr:e.content.stderr,return_code:e.content.return_code,content:e.content.content??[]}}):e.content.type===`encrypted_code_execution_result`?p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`code_execution`),result:{type:e.content.type,encrypted_stdout:e.content.encrypted_stdout,stderr:e.content.stderr,return_code:e.content.return_code,content:e.content.content??[]}}):e.content.type===`code_execution_tool_result_error`&&p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`code_execution`),isError:!0,result:{type:`code_execution_tool_result_error`,errorCode:e.content.error_code}});break;case`bash_code_execution_tool_result`:case`text_editor_code_execution_tool_result`:p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(`code_execution`),result:e.content});break;case`tool_search_tool_result`:{let t=h[e.tool_use_id];if(t==null){let e=a.toCustomToolName(`tool_search_tool_bm25`);a.toCustomToolName(`tool_search_tool_regex`),t=e===`tool_search_tool_bm25`?`tool_search_tool_regex`:`tool_search_tool_bm25`}e.content.type===`tool_search_tool_search_result`?p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(t),result:e.content.tool_references.map(e=>({type:e.type,toolName:e.tool_name}))}):p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:a.toCustomToolName(t),isError:!0,result:{type:`tool_search_tool_result_error`,errorCode:e.content.error_code}});break}case`advisor_tool_result`:{let t=a.toCustomToolName(`advisor`);e.content.type===`advisor_result`?p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:t,result:{type:`advisor_result`,text:e.content.text}}):e.content.type===`advisor_redacted_result`?p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:t,result:{type:`advisor_redacted_result`,encryptedContent:e.content.encrypted_content}}):p.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:t,isError:!0,result:{type:`advisor_tool_result_error`,errorCode:e.content.error_code}});break}case`fallback`:break}return{content:p,finishReason:{unified:Ze({finishReason:d.stop_reason,isJsonResponseFromTool:g}),raw:d.stop_reason??void 0},usage:Ne({usage:d.usage}),request:{body:t},response:{id:d.id??void 0,modelId:d.model??void 0,headers:u,body:f},warnings:n,providerMetadata:(()=>{let e=ft(d.stop_details),t={usage:d.usage,stopSequence:d.stop_sequence??null,...e==null?{}:{stopDetails:e},iterations:d.usage.iterations?d.usage.iterations.map(e=>({type:e.type,...e.model==null?{}:{model:e.model},inputTokens:e.input_tokens,outputTokens:e.output_tokens,...e.cache_creation_input_tokens?{cacheCreationInputTokens:e.cache_creation_input_tokens}:{},...e.cache_read_input_tokens?{cacheReadInputTokens:e.cache_read_input_tokens}:{}})):null,container:d.container?{expiresAt:d.container.expires_at,id:d.container.id,skills:d.container.skills?.map(e=>({type:e.type,skillId:e.skill_id,version:e.version}))??null}:null,contextManagement:dt(d.context_management)??null},n={anthropic:t};return s&&o!==`anthropic`&&(n[o]=t),n})()}}async doStream(t){"use step";let{args:n,warnings:r,betas:i,usesJsonResponseTool:a,toolNameMapping:o,providerOptionsName:s,usedCustomProviderKey:c}=await this.getArgs({...t,stream:!0,userSuppliedBetas:await this.getBetasFromHeaders(t.headers)}),l=[...this.extractCitationDocuments(t.prompt)],u=lt(n.tools),d=this.buildRequestUrl(!0),{responseHeaders:f,value:p}=await J({url:d,headers:await this.getHeaders({betas:i,headers:t.headers}),body:this.transformRequestBody(n,i),failedResponseHandler:Y,successfulResponseHandler:W(ie),abortSignal:t.abortSignal,fetch:this.config.fetch}),m={unified:`other`,raw:void 0},h={input_tokens:0,output_tokens:0,cache_creation_input_tokens:0,cache_read_input_tokens:0,iterations:null},g={},_={},v={},y=null,b,x=null,S,C=null,w=!1,T,E=this.generateId,[D,O]=p.pipeThrough(new TransformStream({start(e){e.enqueue({type:`stream-start`,warnings:r})},transform(e,n){if(t.includeRawChunks&&n.enqueue({type:`raw`,rawValue:e.rawValue}),!e.success){n.enqueue({type:`error`,error:e.error});return}let r=e.value;switch(r.type){case`ping`:return;case`content_block_start`:{let e=r.content_block,t=e.type;if(t===`fallback`)return;switch(T=t,t){case`text`:if(a)return;g[r.index]={type:`text`},n.enqueue({type:`text-start`,id:String(r.index)});return;case`thinking`:g[r.index]={type:`reasoning`},n.enqueue({type:`reasoning-start`,id:String(r.index)});return;case`redacted_thinking`:g[r.index]={type:`reasoning`},n.enqueue({type:`reasoning-start`,id:String(r.index),providerMetadata:{anthropic:{redactedData:e.data}}});return;case`compaction`:g[r.index]={type:`text`},n.enqueue({type:`text-start`,id:String(r.index),providerMetadata:{anthropic:{type:`compaction`}}});return;case`tool_use`:if(a&&e.name===`json`)w=!0,g[r.index]={type:`text`},n.enqueue({type:`text-start`,id:String(r.index)});else{let t=e.caller,i=t?{type:t.type,toolId:`tool_id`in t?t.tool_id:void 0}:void 0,a=e.input&&Object.keys(e.input).length>0?JSON.stringify(e.input):``;g[r.index]={type:`tool-call`,toolCallId:e.id,toolName:e.name,input:a,firstDelta:a.length===0,...i&&{caller:i}},n.enqueue({type:`tool-input-start`,id:e.id,toolName:e.name})}return;case`server_tool_use`:if([`web_fetch`,`web_search`,`code_execution`,`text_editor_code_execution`,`bash_code_execution`].includes(e.name)){let t=e.name===`text_editor_code_execution`||e.name===`bash_code_execution`?`code_execution`:e.name,i=o.toCustomToolName(t),a=e.input!=null&&typeof e.input==`object`&&Object.keys(e.input).length>0?JSON.stringify(e.input):``;g[r.index]={type:`tool-call`,toolCallId:e.id,toolName:i,input:a,providerExecuted:!0,...u&&t===`code_execution`?{dynamic:!0}:{},firstDelta:!0,providerToolName:t},n.enqueue({type:`tool-input-start`,id:e.id,toolName:i,providerExecuted:!0,...u&&t===`code_execution`?{dynamic:!0}:{}})}else if(e.name===`tool_search_tool_regex`||e.name===`tool_search_tool_bm25`){v[e.id]=e.name;let t=o.toCustomToolName(e.name);g[r.index]={type:`tool-call`,toolCallId:e.id,toolName:t,input:``,providerExecuted:!0,firstDelta:!0,providerToolName:e.name},n.enqueue({type:`tool-input-start`,id:e.id,toolName:t,providerExecuted:!0})}else if(e.name===`advisor`){let t=o.toCustomToolName(`advisor`);g[r.index]={type:`tool-call`,toolCallId:e.id,toolName:t,input:`{}`,providerExecuted:!0,firstDelta:!0,providerToolName:e.name},n.enqueue({type:`tool-input-start`,id:e.id,toolName:t,providerExecuted:!0})}return;case`web_fetch_tool_result`:e.content.type===`web_fetch_result`?(l.push({title:e.content.content.title??e.content.url,mediaType:e.content.content.source.media_type}),n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(`web_fetch`),result:{type:`web_fetch_result`,url:e.content.url,retrievedAt:e.content.retrieved_at,content:{type:e.content.content.type,title:e.content.content.title,citations:e.content.content.citations,source:{type:e.content.content.source.type,mediaType:e.content.content.source.media_type,data:e.content.content.source.data}}}})):e.content.type===`web_fetch_tool_result_error`&&n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(`web_fetch`),isError:!0,result:{type:`web_fetch_tool_result_error`,errorCode:e.content.error_code}});return;case`web_search_tool_result`:if(Array.isArray(e.content)){n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(`web_search`),result:e.content.map(e=>({url:e.url,title:e.title,pageAge:e.page_age??null,encryptedContent:e.encrypted_content,type:e.type}))});for(let t of e.content)n.enqueue({type:`source`,sourceType:`url`,id:E(),url:t.url,title:t.title,providerMetadata:{anthropic:{pageAge:t.page_age??null}}})}else n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(`web_search`),isError:!0,result:{type:`web_search_tool_result_error`,errorCode:e.content.error_code}});return;case`code_execution_tool_result`:e.content.type===`code_execution_result`?n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(`code_execution`),result:{type:e.content.type,stdout:e.content.stdout,stderr:e.content.stderr,return_code:e.content.return_code,content:e.content.content??[]}}):e.content.type===`encrypted_code_execution_result`?n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(`code_execution`),result:{type:e.content.type,encrypted_stdout:e.content.encrypted_stdout,stderr:e.content.stderr,return_code:e.content.return_code,content:e.content.content??[]}}):e.content.type===`code_execution_tool_result_error`&&n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(`code_execution`),isError:!0,result:{type:`code_execution_tool_result_error`,errorCode:e.content.error_code}});return;case`bash_code_execution_tool_result`:case`text_editor_code_execution_tool_result`:n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(`code_execution`),result:e.content});return;case`tool_search_tool_result`:{let t=v[e.tool_use_id];if(t==null){let e=o.toCustomToolName(`tool_search_tool_bm25`);o.toCustomToolName(`tool_search_tool_regex`),t=e===`tool_search_tool_bm25`?`tool_search_tool_regex`:`tool_search_tool_bm25`}e.content.type===`tool_search_tool_search_result`?n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(t),result:e.content.tool_references.map(e=>({type:e.type,toolName:e.tool_name}))}):n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(t),isError:!0,result:{type:`tool_search_tool_result_error`,errorCode:e.content.error_code}});return}case`advisor_tool_result`:{let t=o.toCustomToolName(`advisor`);e.content.type===`advisor_result`?n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:t,result:{type:`advisor_result`,text:e.content.text}}):e.content.type===`advisor_redacted_result`?n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:t,result:{type:`advisor_redacted_result`,encryptedContent:e.content.encrypted_content}}):n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:t,isError:!0,result:{type:`advisor_tool_result_error`,errorCode:e.content.error_code}});return}case`mcp_tool_use`:_[e.id]={type:`tool-call`,toolCallId:e.id,toolName:e.name,input:JSON.stringify(e.input),providerExecuted:!0,dynamic:!0,providerMetadata:{anthropic:{type:`mcp-tool-use`,serverName:e.server_name}}},n.enqueue(_[e.id]);return;case`mcp_tool_result`:n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:_[e.tool_use_id].toolName,isError:e.is_error,result:e.content,dynamic:!0,providerMetadata:_[e.tool_use_id].providerMetadata});return;default:throw Error(`Unsupported content block type: ${t}`)}}case`content_block_stop`:if(g[r.index]!=null){let e=g[r.index];switch(e.type){case`text`:n.enqueue({type:`text-end`,id:String(r.index)});break;case`reasoning`:n.enqueue({type:`reasoning-end`,id:String(r.index)});break;case`tool-call`:if(!(a&&e.toolName===`json`)){n.enqueue({type:`tool-input-end`,id:e.toolCallId});let t=e.input===``?`{}`:e.input;if(e.providerToolName===`code_execution`)try{let e=JSON.parse(t);typeof e==`object`&&e&&`code`in e&&!(`type`in e)&&(t=JSON.stringify({type:`programmatic-tool-call`,...e}))}catch{}n.enqueue({type:`tool-call`,toolCallId:e.toolCallId,toolName:e.toolName,input:t,providerExecuted:e.providerExecuted,...u&&e.providerToolName===`code_execution`?{dynamic:!0}:{},...e.caller&&{providerMetadata:{anthropic:{caller:e.caller}}}})}break}delete g[r.index]}T=void 0;return;case`content_block_delta`:{let e=r.delta.type;switch(e){case`text_delta`:if(a)return;n.enqueue({type:`text-delta`,id:String(r.index),delta:r.delta.text});return;case`thinking_delta`:n.enqueue({type:`reasoning-delta`,id:String(r.index),delta:r.delta.thinking});return;case`signature_delta`:T===`thinking`&&n.enqueue({type:`reasoning-delta`,id:String(r.index),delta:``,providerMetadata:{anthropic:{signature:r.delta.signature}}});return;case`compaction_delta`:r.delta.content!=null&&n.enqueue({type:`text-delta`,id:String(r.index),delta:r.delta.content});return;case`input_json_delta`:{let e=g[r.index],t=r.delta.partial_json;if(t.length===0)return;if(w){if(e?.type!==`text`)return;n.enqueue({type:`text-delta`,id:String(r.index),delta:t})}else{if(e?.type!==`tool-call`)return;e.firstDelta&&e.providerToolName===`code_execution`&&(t=`{"type": "programmatic-tool-call",${t.substring(1)}`),n.enqueue({type:`tool-input-delta`,id:e.toolCallId,delta:t}),e.input+=t,e.firstDelta=!1}return}case`citations_delta`:{let e=r.delta.citation,t=ot(e,l,E);t&&n.enqueue(t);return}default:throw Error(`Unsupported delta type: ${e}`)}}case`message_start`:if(h.input_tokens=r.message.usage.input_tokens,h.cache_read_input_tokens=r.message.usage.cache_read_input_tokens??0,h.cache_creation_input_tokens=r.message.usage.cache_creation_input_tokens??0,b={...r.message.usage},r.message.container!=null&&(C={expiresAt:r.message.container.expires_at,id:r.message.container.id,skills:null}),r.message.stop_reason!=null&&(m={unified:Ze({finishReason:r.message.stop_reason,isJsonResponseFromTool:w}),raw:r.message.stop_reason}),n.enqueue({type:`response-metadata`,id:r.message.id??void 0,modelId:r.message.model??void 0}),r.message.content!=null)for(let e=0;e<r.message.content.length;e++){let t=r.message.content[e];if(t.type===`tool_use`){let e=t.caller,r=e?{type:e.type,toolId:`tool_id`in e?e.tool_id:void 0}:void 0;n.enqueue({type:`tool-input-start`,id:t.id,toolName:t.name});let i=JSON.stringify(t.input??{});n.enqueue({type:`tool-input-delta`,id:t.id,delta:i}),n.enqueue({type:`tool-input-end`,id:t.id}),n.enqueue({type:`tool-call`,toolCallId:t.id,toolName:t.name,input:i,...r&&{providerMetadata:{anthropic:{caller:r}}}})}}return;case`message_delta`:r.usage.input_tokens!=null&&h.input_tokens!==r.usage.input_tokens&&(h.input_tokens=r.usage.input_tokens),h.output_tokens=r.usage.output_tokens,r.usage.cache_read_input_tokens!=null&&(h.cache_read_input_tokens=r.usage.cache_read_input_tokens),r.usage.cache_creation_input_tokens!=null&&(h.cache_creation_input_tokens=r.usage.cache_creation_input_tokens),r.usage.iterations!=null&&(h.iterations=r.usage.iterations),m={unified:Ze({finishReason:r.delta.stop_reason,isJsonResponseFromTool:w}),raw:r.delta.stop_reason??void 0},x=r.delta.stop_sequence??null,S=ft(r.delta.stop_details),C=r.delta.container==null?null:{expiresAt:r.delta.container.expires_at,id:r.delta.container.id,skills:r.delta.container.skills?.map(e=>({type:e.type,skillId:e.skill_id,version:e.version}))??null},r.context_management&&(y=dt(r.context_management)),b={...b,...r.usage};return;case`message_stop`:{let e={usage:b??null,stopSequence:x,...S==null?{}:{stopDetails:S},iterations:h.iterations?h.iterations.map(e=>({type:e.type,...e.model==null?{}:{model:e.model},inputTokens:e.input_tokens,outputTokens:e.output_tokens,...e.cache_creation_input_tokens?{cacheCreationInputTokens:e.cache_creation_input_tokens}:{},...e.cache_read_input_tokens?{cacheReadInputTokens:e.cache_read_input_tokens}:{}})):null,container:C,contextManagement:y},t={anthropic:e};c&&s!==`anthropic`&&(t[s]=e),n.enqueue({type:`finish`,finishReason:m,usage:Ne({usage:h,rawUsage:b}),providerMetadata:t});return}case`error`:n.enqueue({type:`error`,error:r.error});return;default:throw Error(`Unsupported chunk type: ${r}`)}}})).tee(),k=D.getReader();try{await k.read();let t=await k.read();if(t.value?.type===`raw`&&(t=await k.read()),t.value?.type===`error`){let r=t.value.error;throw new e({message:r.message,url:d,requestBodyValues:n,statusCode:r.type===`overloaded_error`?529:500,responseHeaders:f,responseBody:JSON.stringify(r),isRetryable:r.type===`overloaded_error`})}}finally{k.cancel().catch(()=>{}),k.releaseLock()}return{stream:O,request:{body:n},response:{headers:f}}}};function ct(e){return e.includes(`claude-opus-4-8`)||e.includes(`claude-opus-4-7`)||e.includes(`claude-fable-5`)?{maxOutputTokens:128e3,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!0,supportsXhighEffort:!0,isKnownModel:!0}:e.includes(`claude-sonnet-4-6`)||e.includes(`claude-opus-4-6`)?{maxOutputTokens:128e3,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!0}:e.includes(`claude-sonnet-4-5`)||e.includes(`claude-opus-4-5`)||e.includes(`claude-haiku-4-5`)?{maxOutputTokens:64e3,supportsStructuredOutput:!0,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!0}:e.includes(`claude-opus-4-1`)?{maxOutputTokens:32e3,supportsStructuredOutput:!0,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!0}:e.includes(`claude-sonnet-4-`)?{maxOutputTokens:64e3,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!0}:e.includes(`claude-opus-4-`)?{maxOutputTokens:32e3,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!0}:e.includes(`claude-3-haiku`)?{maxOutputTokens:4096,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!0}:{maxOutputTokens:4096,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!1}}function lt(e){if(!e)return!1;let t=!1,n=!1;for(let r of e){if(`type`in r&&(r.type===`web_fetch_20260209`||r.type===`web_search_20260209`)){t=!0;continue}if(r.name===`code_execution`){n=!0;break}}return t&&!n}function ut({reasoning:e,supportsAdaptiveThinking:t,supportsXhighEffort:n,maxOutputTokensForModel:r,warnings:i}){if(!_(e))return;if(e===`none`)return{thinking:{type:`disabled`}};if(t)return{thinking:{type:`adaptive`},effort:m({reasoning:e,effortMap:{minimal:`low`,low:`low`,medium:`medium`,high:`high`,xhigh:n?`xhigh`:`max`},warnings:i})};let a=p({reasoning:e,maxOutputTokens:r,maxReasoningBudget:r,warnings:i});if(a!=null)return{thinking:{type:`enabled`,budgetTokens:a}}}function dt(e){return e?{appliedEdits:e.applied_edits.map(e=>{switch(e.type){case`clear_tool_uses_20250919`:return{type:e.type,clearedToolUses:e.cleared_tool_uses,clearedInputTokens:e.cleared_input_tokens};case`clear_thinking_20251015`:return{type:e.type,clearedThinkingTurns:e.cleared_thinking_turns,clearedInputTokens:e.cleared_input_tokens};case`compact_20260112`:return{type:e.type}}}).filter(e=>e!==void 0)}:null}function ft(e){if(e!=null)return{type:e.type,...e.category==null?{}:{category:e.category},...e.explanation==null?{}:{explanation:e.explanation},...e.recommended_model==null?{}:{recommendedModel:e.recommended_model}}}var pt=z({id:`anthropic.bash_20241022`,inputSchema:i(()=>y(O({command:M(),restart:R().optional()})))});function mt(e={}){let{execute:t,...n}=e;return pt(t===void 0?{...n,execute:async({command:e},{abortSignal:t,experimental_sandbox:n})=>{if(!n)throw Error(`Sandbox session is not available`);return await n.run({command:e,abortSignal:t})}}:{...n,...t===null?{}:{execute:t}})}var ht=z({id:`anthropic.bash_20250124`,inputSchema:i(()=>y(O({command:M(),restart:R().optional()})))});function gt(e={}){let{execute:t,...n}=e;return ht(t===void 0?{...n,execute:async({command:e},{abortSignal:t,experimental_sandbox:n})=>{if(!n)throw Error(`Sandbox session is not available`);return await n.run({command:e,abortSignal:t})}}:{...n,...t===null?{}:{execute:t}})}var _t=z({id:`anthropic.computer_20241022`,inputSchema:i(()=>y(O({action:U([`key`,`type`,`mouse_move`,`left_click`,`left_click_drag`,`right_click`,`middle_click`,`double_click`,`screenshot`,`cursor_position`]),coordinate:N(E().int()).optional(),text:M().optional()})))}),vt=z({id:`anthropic.computer_20250124`,inputSchema:i(()=>y(O({action:U([`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:A([E().int(),E().int()]).optional(),duration:E().optional(),scroll_amount:E().optional(),scroll_direction:U([`up`,`down`,`left`,`right`]).optional(),start_coordinate:A([E().int(),E().int()]).optional(),text:M().optional()})))}),yt=z({id:`anthropic.computer_20251124`,inputSchema:i(()=>y(O({action:U([`key`,`hold_key`,`type`,`cursor_position`,`mouse_move`,`left_mouse_down`,`left_mouse_up`,`left_click`,`left_click_drag`,`right_click`,`middle_click`,`double_click`,`triple_click`,`scroll`,`wait`,`screenshot`,`zoom`]),coordinate:A([E().int(),E().int()]).optional(),duration:E().optional(),region:A([E().int(),E().int(),E().int(),E().int()]).optional(),scroll_amount:E().optional(),scroll_direction:U([`up`,`down`,`left`,`right`]).optional(),start_coordinate:A([E().int(),E().int()]).optional(),text:M().optional()})))}),bt=z({id:`anthropic.memory_20250818`,inputSchema:i(()=>y(H(`command`,[O({command:F(`view`),path:M(),view_range:A([E(),E()]).optional()}),O({command:F(`create`),path:M(),file_text:M()}),O({command:F(`str_replace`),path:M(),old_str:M(),new_str:M()}),O({command:F(`insert`),path:M(),insert_line:E(),insert_text:M()}),O({command:F(`delete`),path:M()}),O({command:F(`rename`),old_path:M(),new_path:M()})])))}),xt=z({id:`anthropic.text_editor_20241022`,inputSchema:i(()=>y(O({command:U([`view`,`create`,`str_replace`,`insert`,`undo_edit`]),path:M(),file_text:M().optional(),insert_line:E().int().optional(),new_str:M().optional(),insert_text:M().optional(),old_str:M().optional(),view_range:N(E().int()).optional()})))}),St=z({id:`anthropic.text_editor_20250124`,inputSchema:i(()=>y(O({command:U([`view`,`create`,`str_replace`,`insert`,`undo_edit`]),path:M(),file_text:M().optional(),insert_line:E().int().optional(),new_str:M().optional(),insert_text:M().optional(),old_str:M().optional(),view_range:N(E().int()).optional()})))}),Ct=z({id:`anthropic.text_editor_20250429`,inputSchema:i(()=>y(O({command:U([`view`,`create`,`str_replace`,`insert`]),path:M(),file_text:M().optional(),insert_line:E().int().optional(),new_str:M().optional(),insert_text:M().optional(),old_str:M().optional(),view_range:N(E().int()).optional()})))}),wt=i(()=>y(N(O({type:F(`tool_reference`),toolName:M()})))),Tt=j({id:`anthropic.tool_search_bm25_20251119`,inputSchema:i(()=>y(O({query:M(),limit:E().optional()}))),outputSchema:wt,supportsDeferredResults:!0}),Et={advisor_20260301:fe,bash_20241022:mt,bash_20250124:gt,codeExecution_20250522:Ie,codeExecution_20250825:ze,codeExecution_20260120:He,computer_20241022:_t,computer_20250124:vt,computer_20251124:yt,memory_20250818:bt,textEditor_20241022:xt,textEditor_20250124:St,textEditor_20250429:Ct,textEditor_20250728:he,webFetch_20250910:je,webFetch_20260209:De,webSearch_20250305:Ce,webSearch_20260209:ye,toolSearchRegex_20251119:Ge,toolSearchBm25_20251119:(e={})=>Tt(e)},Dt=i(()=>y(O({id:M(),display_title:M().nullish(),name:M().nullish(),description:M().nullish(),latest_version:M().nullish(),source:M(),created_at:M(),updated_at:M()})));i(()=>y(O({data:N(O({version:M()}))})));var Ot=i(()=>y(O({type:M(),skill_id:M(),name:M().nullish(),description:M().nullish()}))),kt=class{constructor(e){this.config=e,this.specificationVersion=`v4`}get provider(){return this.config.provider}async getHeaders(){return V(await a(this.config.headers),{"anthropic-beta":`skills-2025-10-02`})}async fetchVersionMetadata({skillId:e,version:t,headers:n}){let{value:r}=await q({url:`${this.config.baseURL}/skills/${e}/versions/${t}`,headers:n,failedResponseHandler:Y,successfulResponseHandler:D(Ot),fetch:this.config.fetch});return{...r.name==null?{}:{name:r.name},...r.description==null?{}:{description:r.description}}}async uploadSkill(e){let t=[],n=new FormData;e.displayTitle!=null&&n.append(`display_title`,e.displayTitle);for(let t of e.files){let e=C(t.data);n.append(`files[]`,new Blob([e]),t.path)}let r=await this.getHeaders(),{value:i}=await g({url:`${this.config.baseURL}/skills`,headers:r,formData:n,failedResponseHandler:Y,successfulResponseHandler:D(Dt),fetch:this.config.fetch}),a=i.latest_version==null?{}:await this.fetchVersionMetadata({skillId:i.id,version:i.latest_version,headers:r}),o=a.name??i.name,s=a.description??i.description;return{providerReference:{anthropic:i.id},...i.display_title==null?{}:{displayTitle:i.display_title},...o==null?{}:{name:o},...s==null?{}:{description:s},...i.latest_version==null?{}:{latestVersion:i.latest_version},providerMetadata:{anthropic:{...i.source==null?{}:{source:i.source},...i.created_at==null?{}:{createdAt:i.created_at},...i.updated_at==null?{}:{updatedAt:i.updated_at}}},warnings:t}}},At=`4.0.0`;function jt(e={}){let r=b(f({settingValue:e.baseURL,environmentVariableName:`ANTHROPIC_BASE_URL`}))??`https://api.anthropic.com/v1`,i=e.name??`anthropic.messages`;if(e.apiKey&&e.authToken)throw new t({argument:`apiKey/authToken`,message:`Both apiKey and authToken were provided. Please use only one authentication method.`});let a=()=>u({"anthropic-version":`2023-06-01`,...e.authToken?{Authorization:`Bearer ${e.authToken}`}:{"x-api-key":P({apiKey:e.apiKey,environmentVariableName:`ANTHROPIC_API_KEY`,description:`Anthropic`})},...e.headers},`ai-sdk/anthropic/${At}`),o=t=>new st(t,{provider:i,baseURL:r,headers:a,fetch:e.fetch,generateId:e.generateId??w,supportedUrls:()=>({"image/*":[/^https?:\/\/.*$/],"application/pdf":[/^https?:\/\/.*$/]})}),s=()=>new kt({provider:`${i.replace(`.messages`,``)}.skills`,baseURL:r,headers:a,fetch:e.fetch}),c=function(e){if(new.target)throw Error(`The Anthropic model function cannot be called with the new keyword.`);return o(e)};return c.specificationVersion=`v4`,c.languageModel=o,c.chat=o,c.messages=o,c.embeddingModel=e=>{throw new n({modelId:e,modelType:`embeddingModel`})},c.textEmbeddingModel=c.embeddingModel,c.imageModel=e=>{throw new n({modelId:e,modelType:`imageModel`})},c.files=()=>new ne({provider:i,baseURL:r,headers:a,fetch:e.fetch}),c.skills=s,c.tools=Et,c}var Mt=jt();function Nt({steps:e}){for(let t=e.length-1;t>=0;t--){let n=e[t].providerMetadata?.anthropic?.container?.id;if(n)return{providerOptions:{anthropic:{container:{id:n}}}}}}export{At as VERSION,Mt as anthropic,jt as createAnthropic,Nt as forwardAnthropicContainerIdFromLastStep};
|
|
1
|
+
import{APICallError as e,InvalidArgumentError as t,NoSuchModelError as n,UnsupportedFunctionalityError as r}from"../provider/index.js";import{B as i,Ct as a,E as o,F as s,H as c,J as l,M as u,N as d,O as f,P as p,Q as m,R as h,S as g,St as _,U as v,V as y,Z as b,_ as x,_t as S,a as C,bt as w,d as T,et as E,f as D,ft as O,g as k,gt as A,ht as j,it as ee,j as M,m as N,nt as P,o as F,p as I,pt as L,q as R,r as z,rt as te,s as B,st as V,tt as H,ut as U,vt as W,w as G,wt as K,x as q,xt as J,z as ne}from"../../_chunks/workflow/dist-zLevmMyU.js";var Y=D({errorSchema:M(()=>P(W({type:j(`error`),error:W({type:J(),message:J()})}))),errorToMessage:e=>e.error.message}),re=M(()=>P(W({id:J(),type:j(`file`),filename:J(),mime_type:J(),size_bytes:S(),created_at:J(),downloadable:O().nullish()}))),ie=class{constructor(e){this.config=e,this.specificationVersion=`v4`}get provider(){return this.config.provider}async uploadFile({data:e,mediaType:t,filename:n}){let r=F(e),i=new Blob([r],{type:t}),a=new FormData;n==null?a.append(`file`,i):a.append(`file`,i,n);let{value:o}=await ne({url:`${this.config.baseURL}/files`,headers:z(this.config.headers(),{"anthropic-beta":`files-api-2025-04-14`}),formData:a,failedResponseHandler:Y,successfulResponseHandler:I(re),fetch:this.config.fetch});return{warnings:[],providerReference:{anthropic:o.id},mediaType:o.mime_type??t,filename:o.filename??n,providerMetadata:{anthropic:{filename:o.filename,mimeType:o.mime_type,sizeBytes:o.size_bytes,createdAt:o.created_at,...o.downloadable==null?{}:{downloadable:o.downloadable}}}}}},X=W({type:J(),category:J().nullish(),explanation:J().nullish(),recommended_model:J().nullish()}),ae=M(()=>P(W({type:j(`message`),id:J().nullish(),model:J().nullish(),content:U(L(`type`,[W({type:j(`text`),text:J(),citations:U(L(`type`,[W({type:j(`web_search_result_location`),cited_text:J(),url:J(),title:J(),encrypted_index:J()}),W({type:j(`page_location`),cited_text:J(),document_index:S(),document_title:J().nullable(),start_page_number:S(),end_page_number:S()}),W({type:j(`char_location`),cited_text:J(),document_index:S(),document_title:J().nullable(),start_char_index:S(),end_char_index:S()})])).optional()}),W({type:j(`thinking`),thinking:J(),signature:J()}),W({type:j(`redacted_thinking`),data:J()}),W({type:j(`compaction`),content:J()}),W({type:j(`tool_use`),id:J(),name:J(),input:K(),caller:a([W({type:j(`code_execution_20250825`),tool_id:J()}),W({type:j(`code_execution_20260120`),tool_id:J()}),W({type:j(`direct`)})]).optional()}),W({type:j(`server_tool_use`),id:J(),name:J(),input:w(J(),K()).nullish(),caller:a([W({type:j(`code_execution_20260120`),tool_id:J()}),W({type:j(`direct`)})]).optional()}),W({type:j(`mcp_tool_use`),id:J(),name:J(),input:K(),server_name:J()}),W({type:j(`mcp_tool_result`),tool_use_id:J(),is_error:O(),content:U(a([J(),W({type:j(`text`),text:J()})]))}),W({type:j(`web_fetch_tool_result`),tool_use_id:J(),content:a([W({type:j(`web_fetch_result`),url:J(),retrieved_at:J(),content:W({type:j(`document`),title:J().nullable(),citations:W({enabled:O()}).optional(),source:a([W({type:j(`base64`),media_type:j(`application/pdf`),data:J()}),W({type:j(`text`),media_type:j(`text/plain`),data:J()})])})}),W({type:j(`web_fetch_tool_result_error`),error_code:J()})])}),W({type:j(`web_search_tool_result`),tool_use_id:J(),content:a([U(W({type:j(`web_search_result`),url:J(),title:J(),encrypted_content:J(),page_age:J().nullish()})),W({type:j(`web_search_tool_result_error`),error_code:J()})])}),W({type:j(`code_execution_tool_result`),tool_use_id:J(),content:a([W({type:j(`code_execution_result`),stdout:J(),stderr:J(),return_code:S(),content:U(W({type:j(`code_execution_output`),file_id:J()})).optional().default([])}),W({type:j(`encrypted_code_execution_result`),encrypted_stdout:J(),stderr:J(),return_code:S(),content:U(W({type:j(`code_execution_output`),file_id:J()})).optional().default([])}),W({type:j(`code_execution_tool_result_error`),error_code:J()})])}),W({type:j(`bash_code_execution_tool_result`),tool_use_id:J(),content:L(`type`,[W({type:j(`bash_code_execution_result`),content:U(W({type:j(`bash_code_execution_output`),file_id:J()})),stdout:J(),stderr:J(),return_code:S()}),W({type:j(`bash_code_execution_tool_result_error`),error_code:J()})])}),W({type:j(`text_editor_code_execution_tool_result`),tool_use_id:J(),content:L(`type`,[W({type:j(`text_editor_code_execution_tool_result_error`),error_code:J()}),W({type:j(`text_editor_code_execution_view_result`),content:J(),file_type:J(),num_lines:S().nullable(),start_line:S().nullable(),total_lines:S().nullable()}),W({type:j(`text_editor_code_execution_create_result`),is_file_update:O()}),W({type:j(`text_editor_code_execution_str_replace_result`),lines:U(J()).nullable(),new_lines:S().nullable(),new_start:S().nullable(),old_lines:S().nullable(),old_start:S().nullable()})])}),W({type:j(`tool_search_tool_result`),tool_use_id:J(),content:a([W({type:j(`tool_search_tool_search_result`),tool_references:U(W({type:j(`tool_reference`),tool_name:J()}))}),W({type:j(`tool_search_tool_result_error`),error_code:J()})])}),W({type:j(`advisor_tool_result`),tool_use_id:J(),content:L(`type`,[W({type:j(`advisor_result`),text:J()}),W({type:j(`advisor_redacted_result`),encrypted_content:J()}),W({type:j(`advisor_tool_result_error`),error_code:J()})])}),W({type:j(`fallback`)})])),stop_reason:J().nullish(),stop_sequence:J().nullish(),stop_details:X.nullish(),usage:A({input_tokens:S(),output_tokens:S(),cache_creation_input_tokens:S().nullish(),cache_read_input_tokens:S().nullish(),iterations:U(W({type:a([j(`compaction`),j(`message`),j(`advisor_message`),j(`fallback_message`)]),model:J().nullish(),input_tokens:S(),output_tokens:S(),cache_creation_input_tokens:S().nullish(),cache_read_input_tokens:S().nullish()})).nullish()}),container:W({expires_at:J(),id:J(),skills:U(W({type:a([j(`anthropic`),j(`custom`)]),skill_id:J(),version:J()})).nullish()}).nullish(),context_management:W({applied_edits:U(a([W({type:j(`clear_tool_uses_20250919`),cleared_tool_uses:S(),cleared_input_tokens:S()}),W({type:j(`clear_thinking_20251015`),cleared_thinking_turns:S(),cleared_input_tokens:S()}),W({type:j(`compact_20260112`)})]))}).nullish()}))),oe=M(()=>P(L(`type`,[W({type:j(`message_start`),message:W({id:J().nullish(),model:J().nullish(),role:J().nullish(),usage:A({input_tokens:S(),cache_creation_input_tokens:S().nullish(),cache_read_input_tokens:S().nullish()}),content:U(L(`type`,[W({type:j(`tool_use`),id:J(),name:J(),input:K(),caller:a([W({type:j(`code_execution_20250825`),tool_id:J()}),W({type:j(`code_execution_20260120`),tool_id:J()}),W({type:j(`direct`)})]).optional()})])).nullish(),stop_reason:J().nullish(),container:W({expires_at:J(),id:J()}).nullish()})}),W({type:j(`content_block_start`),index:S(),content_block:L(`type`,[W({type:j(`text`),text:J()}),W({type:j(`thinking`),thinking:J()}),W({type:j(`tool_use`),id:J(),name:J(),input:w(J(),K()).optional(),caller:a([W({type:j(`code_execution_20250825`),tool_id:J()}),W({type:j(`code_execution_20260120`),tool_id:J()}),W({type:j(`direct`)})]).optional()}),W({type:j(`redacted_thinking`),data:J()}),W({type:j(`compaction`),content:J().nullish()}),W({type:j(`server_tool_use`),id:J(),name:J(),input:w(J(),K()).nullish(),caller:a([W({type:j(`code_execution_20260120`),tool_id:J()}),W({type:j(`direct`)})]).optional()}),W({type:j(`mcp_tool_use`),id:J(),name:J(),input:K(),server_name:J()}),W({type:j(`mcp_tool_result`),tool_use_id:J(),is_error:O(),content:U(a([J(),W({type:j(`text`),text:J()})]))}),W({type:j(`web_fetch_tool_result`),tool_use_id:J(),content:a([W({type:j(`web_fetch_result`),url:J(),retrieved_at:J(),content:W({type:j(`document`),title:J().nullable(),citations:W({enabled:O()}).optional(),source:a([W({type:j(`base64`),media_type:j(`application/pdf`),data:J()}),W({type:j(`text`),media_type:j(`text/plain`),data:J()})])})}),W({type:j(`web_fetch_tool_result_error`),error_code:J()})])}),W({type:j(`web_search_tool_result`),tool_use_id:J(),content:a([U(W({type:j(`web_search_result`),url:J(),title:J(),encrypted_content:J(),page_age:J().nullish()})),W({type:j(`web_search_tool_result_error`),error_code:J()})])}),W({type:j(`code_execution_tool_result`),tool_use_id:J(),content:a([W({type:j(`code_execution_result`),stdout:J(),stderr:J(),return_code:S(),content:U(W({type:j(`code_execution_output`),file_id:J()})).optional().default([])}),W({type:j(`encrypted_code_execution_result`),encrypted_stdout:J(),stderr:J(),return_code:S(),content:U(W({type:j(`code_execution_output`),file_id:J()})).optional().default([])}),W({type:j(`code_execution_tool_result_error`),error_code:J()})])}),W({type:j(`bash_code_execution_tool_result`),tool_use_id:J(),content:L(`type`,[W({type:j(`bash_code_execution_result`),content:U(W({type:j(`bash_code_execution_output`),file_id:J()})),stdout:J(),stderr:J(),return_code:S()}),W({type:j(`bash_code_execution_tool_result_error`),error_code:J()})])}),W({type:j(`text_editor_code_execution_tool_result`),tool_use_id:J(),content:L(`type`,[W({type:j(`text_editor_code_execution_tool_result_error`),error_code:J()}),W({type:j(`text_editor_code_execution_view_result`),content:J(),file_type:J(),num_lines:S().nullable(),start_line:S().nullable(),total_lines:S().nullable()}),W({type:j(`text_editor_code_execution_create_result`),is_file_update:O()}),W({type:j(`text_editor_code_execution_str_replace_result`),lines:U(J()).nullable(),new_lines:S().nullable(),new_start:S().nullable(),old_lines:S().nullable(),old_start:S().nullable()})])}),W({type:j(`tool_search_tool_result`),tool_use_id:J(),content:a([W({type:j(`tool_search_tool_search_result`),tool_references:U(W({type:j(`tool_reference`),tool_name:J()}))}),W({type:j(`tool_search_tool_result_error`),error_code:J()})])}),W({type:j(`advisor_tool_result`),tool_use_id:J(),content:L(`type`,[W({type:j(`advisor_result`),text:J()}),W({type:j(`advisor_redacted_result`),encrypted_content:J()}),W({type:j(`advisor_tool_result_error`),error_code:J()})])}),W({type:j(`fallback`)})])}),W({type:j(`content_block_delta`),index:S(),delta:L(`type`,[W({type:j(`input_json_delta`),partial_json:J()}),W({type:j(`text_delta`),text:J()}),W({type:j(`thinking_delta`),thinking:J()}),W({type:j(`signature_delta`),signature:J()}),W({type:j(`compaction_delta`),content:J().nullish()}),W({type:j(`citations_delta`),citation:L(`type`,[W({type:j(`web_search_result_location`),cited_text:J(),url:J(),title:J(),encrypted_index:J()}),W({type:j(`page_location`),cited_text:J(),document_index:S(),document_title:J().nullable(),start_page_number:S(),end_page_number:S()}),W({type:j(`char_location`),cited_text:J(),document_index:S(),document_title:J().nullable(),start_char_index:S(),end_char_index:S()})])})])}),W({type:j(`content_block_stop`),index:S()}),W({type:j(`error`),error:W({type:J(),message:J()})}),W({type:j(`message_delta`),delta:W({stop_reason:J().nullish(),stop_sequence:J().nullish(),stop_details:X.nullish(),container:W({expires_at:J(),id:J(),skills:U(W({type:a([j(`anthropic`),j(`custom`)]),skill_id:J(),version:J()})).nullish()}).nullish()}),usage:A({input_tokens:S().nullish(),output_tokens:S(),cache_creation_input_tokens:S().nullish(),cache_read_input_tokens:S().nullish(),iterations:U(W({type:a([j(`compaction`),j(`message`),j(`advisor_message`),j(`fallback_message`)]),model:J().nullish(),input_tokens:S(),output_tokens:S(),cache_creation_input_tokens:S().nullish(),cache_read_input_tokens:S().nullish()})).nullish()}),context_management:W({applied_edits:U(a([W({type:j(`clear_tool_uses_20250919`),cleared_tool_uses:S(),cleared_input_tokens:S()}),W({type:j(`clear_thinking_20251015`),cleared_thinking_turns:S(),cleared_input_tokens:S()}),W({type:j(`compact_20260112`)})]))}).nullish()}),W({type:j(`message_stop`)}),W({type:j(`ping`)})]))),se=M(()=>P(W({signature:J().optional(),redactedData:J().optional()}))),Z=W({containerUpload:O().optional(),citations:W({enabled:O()}).optional(),title:J().optional(),context:J().optional()}),ce=W({sendReasoning:O().optional(),structuredOutputMode:V([`outputFormat`,`jsonTool`,`auto`]).optional(),thinking:L(`type`,[W({type:j(`adaptive`),display:V([`omitted`,`summarized`]).optional()}),W({type:j(`enabled`),budgetTokens:S().optional()}),W({type:j(`disabled`)})]).optional(),disableParallelToolUse:O().optional(),cacheControl:W({type:j(`ephemeral`),ttl:a([j(`5m`),j(`1h`)]).optional()}).optional(),metadata:W({userId:J().optional()}).optional(),mcpServers:U(W({type:j(`url`),name:J(),url:J(),authorizationToken:J().nullish(),toolConfiguration:W({enabled:O().nullish(),allowedTools:U(J()).nullish()}).nullish()})).optional(),container:W({id:J().optional(),skills:U(L(`type`,[W({type:j(`anthropic`),skillId:J(),version:J().optional()}),W({type:j(`custom`),providerReference:w(J(),J()),version:J().optional()})])).optional()}).optional(),toolStreaming:O().optional(),effort:V([`low`,`medium`,`high`,`xhigh`,`max`]).optional(),taskBudget:W({type:j(`tokens`),total:S().int().min(2e4),remaining:S().int().min(0).optional()}).optional(),speed:V([`fast`,`standard`]).optional(),inferenceGeo:V([`us`,`global`]).optional(),fallbacks:U(W({model:J(),max_tokens:S().int().optional(),thinking:w(J(),K()).optional(),output_config:w(J(),K()).optional(),speed:V([`fast`,`standard`]).optional()})).optional(),anthropicBeta:U(J()).optional(),contextManagement:W({edits:U(L(`type`,[W({type:j(`clear_tool_uses_20250919`),trigger:L(`type`,[W({type:j(`input_tokens`),value:S()}),W({type:j(`tool_uses`),value:S()})]).optional(),keep:W({type:j(`tool_uses`),value:S()}).optional(),clearAtLeast:W({type:j(`input_tokens`),value:S()}).optional(),clearToolInputs:O().optional(),excludeTools:U(J()).optional()}),W({type:j(`clear_thinking_20251015`),keep:a([j(`all`),W({type:j(`thinking_turns`),value:S()})]).optional()}),W({type:j(`compact_20260112`),trigger:W({type:j(`input_tokens`),value:S()}).optional(),pauseAfterCompaction:O().optional(),instructions:J().optional()})]))}).optional()}),le=4;function ue(e){let t=e?.anthropic;return t?.cacheControl??t?.cache_control}var Q=class{constructor(){this.breakpointCount=0,this.warnings=[]}getCacheControl(e,t){let n=ue(e);if(n){if(!t.canCache){this.warnings.push({type:`unsupported`,feature:`cache_control on non-cacheable context`,details:`cache_control cannot be set on ${t.type}. It will be ignored.`});return}if(this.breakpointCount++,this.breakpointCount>le){this.warnings.push({type:`unsupported`,feature:`cacheControl breakpoint limit`,details:`Maximum ${le} cache breakpoints exceeded (found ${this.breakpointCount}). This breakpoint will be ignored.`});return}return n}}getWarnings(){return this.warnings}},de=M(()=>P(W({model:J(),maxUses:S().optional(),caching:W({type:j(`ephemeral`),ttl:a([j(`5m`),j(`1h`)])}).optional()}))),fe=M(()=>P(L(`type`,[W({type:j(`advisor_result`),text:J()}),W({type:j(`advisor_redacted_result`),encryptedContent:J()}),W({type:j(`advisor_tool_result_error`),errorCode:J()})]))),pe=k({id:`anthropic.advisor_20260301`,inputSchema:M(()=>P(W({}).strict())),outputSchema:fe,supportsDeferredResults:!0}),me=e=>pe(e),he=M(()=>P(W({maxCharacters:S().optional()}))),ge=N({id:`anthropic.text_editor_20250728`,inputSchema:M(()=>P(W({command:V([`view`,`create`,`str_replace`,`insert`]),path:J(),file_text:J().optional(),insert_line:S().int().optional(),new_str:J().optional(),insert_text:J().optional(),old_str:J().optional(),view_range:U(S().int()).optional()})))}),_e=(e={})=>ge(e),ve=M(()=>P(W({maxUses:S().optional(),allowedDomains:U(J()).optional(),blockedDomains:U(J()).optional(),userLocation:W({type:j(`approximate`),city:J().optional(),region:J().optional(),country:J().optional(),timezone:J().optional()}).optional()}))),ye=M(()=>P(U(W({url:J(),title:J().nullable(),pageAge:J().nullable(),encryptedContent:J(),type:j(`web_search_result`)})))),be=k({id:`anthropic.web_search_20260209`,inputSchema:M(()=>P(W({query:J()}))),outputSchema:ye,supportsDeferredResults:!0}),xe=(e={})=>be(e),Se=M(()=>P(W({maxUses:S().optional(),allowedDomains:U(J()).optional(),blockedDomains:U(J()).optional(),userLocation:W({type:j(`approximate`),city:J().optional(),region:J().optional(),country:J().optional(),timezone:J().optional()}).optional()}))),Ce=M(()=>P(U(W({url:J(),title:J().nullable(),pageAge:J().nullable(),encryptedContent:J(),type:j(`web_search_result`)})))),we=k({id:`anthropic.web_search_20250305`,inputSchema:M(()=>P(W({query:J()}))),outputSchema:Ce,supportsDeferredResults:!0}),Te=(e={})=>we(e),Ee=M(()=>P(W({maxUses:S().optional(),allowedDomains:U(J()).optional(),blockedDomains:U(J()).optional(),citations:W({enabled:O()}).optional(),maxContentTokens:S().optional()}))),De=M(()=>P(W({type:j(`web_fetch_result`),url:J(),content:W({type:j(`document`),title:J().nullable(),citations:W({enabled:O()}).optional(),source:a([W({type:j(`base64`),mediaType:j(`application/pdf`),data:J()}),W({type:j(`text`),mediaType:j(`text/plain`),data:J()})])}),retrievedAt:J().nullable()}))),Oe=k({id:`anthropic.web_fetch_20260209`,inputSchema:M(()=>P(W({url:J()}))),outputSchema:De,supportsDeferredResults:!0}),ke=(e={})=>Oe(e),Ae=M(()=>P(W({maxUses:S().optional(),allowedDomains:U(J()).optional(),blockedDomains:U(J()).optional(),citations:W({enabled:O()}).optional(),maxContentTokens:S().optional()}))),je=M(()=>P(W({type:j(`web_fetch_result`),url:J(),content:W({type:j(`document`),title:J().nullable(),citations:W({enabled:O()}).optional(),source:a([W({type:j(`base64`),mediaType:j(`application/pdf`),data:J()}),W({type:j(`text`),mediaType:j(`text/plain`),data:J()})])}),retrievedAt:J().nullable()}))),Me=k({id:`anthropic.web_fetch_20250910`,inputSchema:M(()=>P(W({url:J()}))),outputSchema:je,supportsDeferredResults:!0}),Ne=(e={})=>Me(e);async function Pe({tools:e,toolChoice:t,disableParallelToolUse:n,cacheControlValidator:i,supportsStructuredOutput:a,supportsStrictTools:o,defaultEagerInputStreaming:s=!1}){e=e?.length?e:void 0;let c=[],l=new Set,u=i||new Q;if(e==null)return{tools:void 0,toolChoice:void 0,toolWarnings:c,betas:l};let d=[];for(let t of e)switch(t.type){case`function`:{let e=u.getCacheControl(t.providerOptions,{type:`tool definition`,canCache:!0}),n=t.providerOptions?.anthropic,r=n?.eagerInputStreaming??s,i=n?.deferLoading,f=n?.allowedCallers;!o&&t.strict!=null&&c.push({type:`unsupported`,feature:`strict`,details:`Tool '${t.name}' has strict: ${t.strict}, but strict mode is not supported by this provider. The strict property will be ignored.`}),d.push({name:t.name,description:t.description,input_schema:t.inputSchema,cache_control:e,...r?{eager_input_streaming:!0}:{},...o===!0&&t.strict!=null?{strict:t.strict}:{},...i==null?{}:{defer_loading:i},...f==null?{}:{allowed_callers:f},...t.inputExamples==null?{}:{input_examples:t.inputExamples.map(e=>e.input)}}),a===!0&&l.add(`structured-outputs-2025-11-13`),(t.inputExamples!=null||f!=null)&&l.add(`advanced-tool-use-2025-11-20`);break}case`provider`:switch(t.id){case`anthropic.code_execution_20250522`:l.add(`code-execution-2025-05-22`),d.push({type:`code_execution_20250522`,name:`code_execution`,cache_control:void 0});break;case`anthropic.code_execution_20250825`:l.add(`code-execution-2025-08-25`),d.push({type:`code_execution_20250825`,name:`code_execution`});break;case`anthropic.code_execution_20260120`:d.push({type:`code_execution_20260120`,name:`code_execution`});break;case`anthropic.computer_20250124`:l.add(`computer-use-2025-01-24`),d.push({name:`computer`,type:`computer_20250124`,display_width_px:t.args.displayWidthPx,display_height_px:t.args.displayHeightPx,display_number:t.args.displayNumber,cache_control:void 0});break;case`anthropic.computer_20251124`:l.add(`computer-use-2025-11-24`),d.push({name:`computer`,type:`computer_20251124`,display_width_px:t.args.displayWidthPx,display_height_px:t.args.displayHeightPx,display_number:t.args.displayNumber,enable_zoom:t.args.enableZoom,cache_control:void 0});break;case`anthropic.computer_20241022`:l.add(`computer-use-2024-10-22`),d.push({name:`computer`,type:`computer_20241022`,display_width_px:t.args.displayWidthPx,display_height_px:t.args.displayHeightPx,display_number:t.args.displayNumber,cache_control:void 0});break;case`anthropic.text_editor_20250124`:l.add(`computer-use-2025-01-24`),d.push({name:`str_replace_editor`,type:`text_editor_20250124`,cache_control:void 0});break;case`anthropic.text_editor_20241022`:l.add(`computer-use-2024-10-22`),d.push({name:`str_replace_editor`,type:`text_editor_20241022`,cache_control:void 0});break;case`anthropic.text_editor_20250429`:l.add(`computer-use-2025-01-24`),d.push({name:`str_replace_based_edit_tool`,type:`text_editor_20250429`,cache_control:void 0});break;case`anthropic.text_editor_20250728`:{let e=await m({value:t.args,schema:he});d.push({name:`str_replace_based_edit_tool`,type:`text_editor_20250728`,max_characters:e.maxCharacters,cache_control:void 0});break}case`anthropic.bash_20250124`:l.add(`computer-use-2025-01-24`),d.push({name:`bash`,type:`bash_20250124`,cache_control:void 0});break;case`anthropic.bash_20241022`:l.add(`computer-use-2024-10-22`),d.push({name:`bash`,type:`bash_20241022`,cache_control:void 0});break;case`anthropic.memory_20250818`:l.add(`context-management-2025-06-27`),d.push({name:`memory`,type:`memory_20250818`});break;case`anthropic.web_fetch_20250910`:{l.add(`web-fetch-2025-09-10`);let e=await m({value:t.args,schema:Ae});d.push({type:`web_fetch_20250910`,name:`web_fetch`,max_uses:e.maxUses,allowed_domains:e.allowedDomains,blocked_domains:e.blockedDomains,citations:e.citations,max_content_tokens:e.maxContentTokens,cache_control:void 0});break}case`anthropic.web_fetch_20260209`:{l.add(`code-execution-web-tools-2026-02-09`);let e=await m({value:t.args,schema:Ee});d.push({type:`web_fetch_20260209`,name:`web_fetch`,max_uses:e.maxUses,allowed_domains:e.allowedDomains,blocked_domains:e.blockedDomains,citations:e.citations,max_content_tokens:e.maxContentTokens,cache_control:void 0});break}case`anthropic.web_search_20250305`:{let e=await m({value:t.args,schema:Se});d.push({type:`web_search_20250305`,name:`web_search`,max_uses:e.maxUses,allowed_domains:e.allowedDomains,blocked_domains:e.blockedDomains,user_location:e.userLocation,cache_control:void 0});break}case`anthropic.web_search_20260209`:{l.add(`code-execution-web-tools-2026-02-09`);let e=await m({value:t.args,schema:ve});d.push({type:`web_search_20260209`,name:`web_search`,max_uses:e.maxUses,allowed_domains:e.allowedDomains,blocked_domains:e.blockedDomains,user_location:e.userLocation,cache_control:void 0});break}case`anthropic.tool_search_regex_20251119`:d.push({type:`tool_search_tool_regex_20251119`,name:`tool_search_tool_regex`});break;case`anthropic.tool_search_bm25_20251119`:d.push({type:`tool_search_tool_bm25_20251119`,name:`tool_search_tool_bm25`});break;case`anthropic.advisor_20260301`:{l.add(`advisor-tool-2026-03-01`);let e=await m({value:t.args,schema:de});d.push({type:`advisor_20260301`,name:`advisor`,model:e.model,...e.maxUses!==void 0&&{max_uses:e.maxUses},...e.caching!==void 0&&{caching:e.caching}});break}default:c.push({type:`unsupported`,feature:`provider-defined tool ${t.id}`});break}break;default:c.push({type:`unsupported`,feature:`tool ${t}`});break}if(t==null)return{tools:d,toolChoice:n?{type:`auto`,disable_parallel_tool_use:n}:void 0,toolWarnings:c,betas:l};let f=t.type;switch(f){case`auto`:return{tools:d,toolChoice:{type:`auto`,disable_parallel_tool_use:n},toolWarnings:c,betas:l};case`required`:return{tools:d,toolChoice:{type:`any`,disable_parallel_tool_use:n},toolWarnings:c,betas:l};case`none`:return{tools:void 0,toolChoice:void 0,toolWarnings:c,betas:l};case`tool`:return{tools:d,toolChoice:{type:`tool`,name:t.toolName,disable_parallel_tool_use:n},toolWarnings:c,betas:l};default:throw new r({functionality:`tool choice type: ${f}`})}}function Fe({usage:e,rawUsage:t}){let n=e.cache_creation_input_tokens??0,r=e.cache_read_input_tokens??0,i,a,o=e.iterations?.some(e=>e.type===`fallback_message`);if(e.iterations&&e.iterations.length>0&&!o){let t=e.iterations.filter(e=>e.type===`compaction`||e.type===`message`);if(t.length>0){let e=t.reduce((e,t)=>({input:e.input+t.input_tokens,output:e.output+t.output_tokens}),{input:0,output:0});i=e.input,a=e.output}else i=e.input_tokens,a=e.output_tokens}else i=e.input_tokens,a=e.output_tokens;return{inputTokens:{total:i+n+r,noCache:i,cacheRead:r,cacheWrite:n},outputTokens:{total:a,text:void 0,reasoning:void 0},raw:t??e}}var Ie=M(()=>P(W({type:j(`code_execution_result`),stdout:J(),stderr:J(),return_code:S(),content:U(W({type:j(`code_execution_output`),file_id:J()})).optional().default([])}))),Le=k({id:`anthropic.code_execution_20250522`,inputSchema:M(()=>P(W({code:J()}))),outputSchema:Ie}),Re=(e={})=>Le(e),ze=M(()=>P(L(`type`,[W({type:j(`code_execution_result`),stdout:J(),stderr:J(),return_code:S(),content:U(W({type:j(`code_execution_output`),file_id:J()})).optional().default([])}),W({type:j(`bash_code_execution_result`),content:U(W({type:j(`bash_code_execution_output`),file_id:J()})),stdout:J(),stderr:J(),return_code:S()}),W({type:j(`bash_code_execution_tool_result_error`),error_code:J()}),W({type:j(`text_editor_code_execution_tool_result_error`),error_code:J()}),W({type:j(`text_editor_code_execution_view_result`),content:J(),file_type:J(),num_lines:S().nullable(),start_line:S().nullable(),total_lines:S().nullable()}),W({type:j(`text_editor_code_execution_create_result`),is_file_update:O()}),W({type:j(`text_editor_code_execution_str_replace_result`),lines:U(J()).nullable(),new_lines:S().nullable(),new_start:S().nullable(),old_lines:S().nullable(),old_start:S().nullable()})]))),Be=k({id:`anthropic.code_execution_20250825`,inputSchema:M(()=>P(L(`type`,[W({type:j(`programmatic-tool-call`),code:J()}),W({type:j(`bash_code_execution`),command:J()}),L(`command`,[W({type:j(`text_editor_code_execution`),command:j(`view`),path:J()}),W({type:j(`text_editor_code_execution`),command:j(`create`),path:J(),file_text:J().nullish()}),W({type:j(`text_editor_code_execution`),command:j(`str_replace`),path:J(),old_str:J(),new_str:J()})])]))),outputSchema:ze,supportsDeferredResults:!0}),Ve=(e={})=>Be(e),He=M(()=>P(L(`type`,[W({type:j(`code_execution_result`),stdout:J(),stderr:J(),return_code:S(),content:U(W({type:j(`code_execution_output`),file_id:J()})).optional().default([])}),W({type:j(`encrypted_code_execution_result`),encrypted_stdout:J(),stderr:J(),return_code:S(),content:U(W({type:j(`code_execution_output`),file_id:J()})).optional().default([])}),W({type:j(`bash_code_execution_result`),content:U(W({type:j(`bash_code_execution_output`),file_id:J()})),stdout:J(),stderr:J(),return_code:S()}),W({type:j(`bash_code_execution_tool_result_error`),error_code:J()}),W({type:j(`text_editor_code_execution_tool_result_error`),error_code:J()}),W({type:j(`text_editor_code_execution_view_result`),content:J(),file_type:J(),num_lines:S().nullable(),start_line:S().nullable(),total_lines:S().nullable()}),W({type:j(`text_editor_code_execution_create_result`),is_file_update:O()}),W({type:j(`text_editor_code_execution_str_replace_result`),lines:U(J()).nullable(),new_lines:S().nullable(),new_start:S().nullable(),old_lines:S().nullable(),old_start:S().nullable()})]))),Ue=k({id:`anthropic.code_execution_20260120`,inputSchema:M(()=>P(L(`type`,[W({type:j(`programmatic-tool-call`),code:J()}),W({type:j(`bash_code_execution`),command:J()}),L(`command`,[W({type:j(`text_editor_code_execution`),command:j(`view`),path:J()}),W({type:j(`text_editor_code_execution`),command:j(`create`),path:J(),file_text:J().nullish()}),W({type:j(`text_editor_code_execution`),command:j(`str_replace`),path:J(),old_str:J(),new_str:J()})])]))),outputSchema:He,supportsDeferredResults:!0}),We=(e={})=>Ue(e),Ge=M(()=>P(U(W({type:j(`tool_reference`),toolName:J()})))),Ke=k({id:`anthropic.tool_search_regex_20251119`,inputSchema:M(()=>P(W({pattern:J(),limit:S().optional()}))),outputSchema:Ge,supportsDeferredResults:!0}),qe=(e={})=>Ke(e);function Je(e){return typeof e==`string`?new TextDecoder().decode(C(e)):new TextDecoder().decode(e)}function Ye(e){try{if(typeof e==`string`)return R(e);if(typeof e==`object`&&e)return e}catch{let t=e?.errorCode;return{errorCode:typeof t==`string`?t:`unavailable`}}return{}}async function Xe({prompt:e,sendReasoning:t,warnings:n,cacheControlValidator:i,toolNameMapping:a}){let o=new Set,s=Ze(e),l=i||new Q,u,d=[];async function p(e){return(await h({provider:`anthropic`,providerOptions:e,schema:Z}))?.citations?.enabled??!1}async function g(e){return(await h({provider:`anthropic`,providerOptions:e,schema:Z}))?.containerUpload??!1}async function _(e){let t=await h({provider:`anthropic`,providerOptions:e,schema:Z});return{title:t?.title,context:t?.context}}for(let e=0;e<s.length;e++){let i=s[e],y=e===s.length-1,b=i.type;switch(b){case`system`:{let e=i.messages.map(({content:e,providerOptions:t})=>({type:`text`,text:e,cache_control:l.getCacheControl(t,{type:`system message`,canCache:!0})}));u==null?u=e:(d.push({role:`system`,content:e}),o.add(`mid-conversation-system-2026-04-07`));break}case`user`:{let e=[];for(let t of i.messages){let{role:i,content:a}=t;switch(i){case`user`:for(let n=0;n<a.length;n++){let i=a[n],s=n===a.length-1,u=l.getCacheControl(i.providerOptions,{type:`user message part`,canCache:!0})??(s?l.getCacheControl(t.providerOptions,{type:`user message`,canCache:!0}):void 0);switch(i.type){case`text`:e.push({type:`text`,text:i.text,cache_control:u});break;case`file`:switch(i.data.type){case`reference`:{let t=v({reference:i.data.reference,provider:`anthropic`});o.add(`files-api-2025-04-14`),await g(i.providerOptions)?e.push({type:`container_upload`,file_id:t}):G(i.mediaType)===`image`?e.push({type:`image`,source:{type:`file`,file_id:t},cache_control:u}):e.push({type:`document`,source:{type:`file`,file_id:t},cache_control:u});break}case`text`:{let t=await p(i.providerOptions),n=await _(i.providerOptions);e.push({type:`document`,source:{type:`text`,media_type:`text/plain`,data:i.data.text},title:n.title??i.filename,...n.context&&{context:n.context},...t&&{citations:{enabled:!0}},cache_control:u});break}case`url`:case`data`:{let t=G(i.mediaType);if(t===`image`)e.push({type:`image`,source:i.data.type===`url`?{type:`url`,url:i.data.url.toString()}:{type:`base64`,media_type:c({part:i}),data:B(i.data.data)},cache_control:u});else if(t===`application`&&(i.data.type===`url`?i.mediaType===`application/pdf`:c({part:i})===`application/pdf`)){o.add(`pdfs-2024-09-25`);let t=await p(i.providerOptions),n=await _(i.providerOptions);e.push({type:`document`,source:i.data.type===`url`?{type:`url`,url:i.data.url.toString()}:{type:`base64`,media_type:`application/pdf`,data:B(i.data.data)},title:n.title??i.filename,...n.context&&{context:n.context},...t&&{citations:{enabled:!0}},cache_control:u})}else if(i.mediaType===`text/plain`){let t=await p(i.providerOptions),n=await _(i.providerOptions);e.push({type:`document`,source:i.data.type===`url`?{type:`url`,url:i.data.url.toString()}:{type:`text`,media_type:`text/plain`,data:Je(i.data.data)},title:n.title??i.filename,...n.context&&{context:n.context},...t&&{citations:{enabled:!0}},cache_control:u})}else throw new r({functionality:`media type: ${i.mediaType}`});break}}break}}break;case`tool`:for(let r=0;r<a.length;r++){let i=a[r];if(i.type===`tool-approval-response`)continue;let s=i.output,u=`providerOptions`in s?s.providerOptions:s.type===`content`?s.value.find(e=>e.providerOptions!=null)?.providerOptions:void 0,d=r===a.length-1,p=l.getCacheControl(i.providerOptions,{type:`tool result part`,canCache:!0})??l.getCacheControl(u,{type:`tool result output`,canCache:!0})??(d?l.getCacheControl(t.providerOptions,{type:`tool result message`,canCache:!0}):void 0),m;switch(s.type){case`content`:m=s.value.map(e=>{switch(e.type){case`text`:return{type:`text`,text:e.text};case`file`:{let t=G(e.mediaType);if(e.data.type===`url`)return t===`image`?{type:`image`,source:{type:`url`,url:e.data.url.toString()}}:{type:`document`,source:{type:`url`,url:e.data.url.toString()}};if(e.data.type===`data`){if(t===`image`)return{type:`image`,source:{type:`base64`,media_type:c({part:e}),data:B(e.data.data)}};if(c({part:e})===`application/pdf`)return o.add(`pdfs-2024-09-25`),{type:`document`,source:{type:`base64`,media_type:`application/pdf`,data:B(e.data.data)}};n.push({type:`other`,message:`unsupported tool content part type: ${e.type} with media type: ${e.mediaType}`});return}n.push({type:`other`,message:`unsupported tool content part type: ${e.type} with data type: ${e.data.type}`});return}case`custom`:{let t=e.providerOptions?.anthropic;if(t?.type===`tool-reference`)return{type:`tool_reference`,tool_name:t.toolName};n.push({type:`other`,message:`unsupported custom tool content part`});return}default:n.push({type:`other`,message:`unsupported tool content part type: ${e.type}`});return}}).filter(f);break;case`text`:case`error-text`:m=s.value;break;case`execution-denied`:m=s.reason??`Tool call execution denied.`;break;default:m=JSON.stringify(s.value);break}e.push({type:`tool_result`,tool_use_id:i.toolCallId,content:m,is_error:s.type===`error-text`||s.type===`error-json`?!0:void 0,cache_control:p})}break;default:throw Error(`Unsupported role: ${i}`)}}d.push({role:`user`,content:e});break}case`assistant`:{let e=[],r=new Set;for(let o=0;o<i.messages.length;o++){let s=i.messages[o],c=o===i.messages.length-1,{content:u}=s;for(let i=0;i<u.length;i++){let o=u[i],d=i===u.length-1,f=l.getCacheControl(o.providerOptions,{type:`assistant message part`,canCache:!0})??(d?l.getCacheControl(s.providerOptions,{type:`assistant message`,canCache:!0}):void 0);switch(o.type){case`text`:o.providerOptions?.anthropic?.type===`compaction`?e.push({type:`compaction`,content:o.text,cache_control:f}):e.push({type:`text`,text:y&&c&&d?o.text.trim():o.text,cache_control:f});break;case`reasoning`:if(t){let t=await h({provider:`anthropic`,providerOptions:o.providerOptions,schema:se});t==null?n.push({type:`other`,message:`unsupported reasoning metadata`}):t.signature==null?t.redactedData==null?n.push({type:`other`,message:`unsupported reasoning metadata`}):(l.getCacheControl(o.providerOptions,{type:`redacted thinking block`,canCache:!1}),e.push({type:`redacted_thinking`,data:t.redactedData})):(l.getCacheControl(o.providerOptions,{type:`thinking block`,canCache:!1}),e.push({type:`thinking`,thinking:o.text,signature:t.signature}))}else n.push({type:`other`,message:`sending reasoning content is disabled for this model`});break;case`tool-call`:{if(o.providerExecuted){let t=a.toProviderToolName(o.toolName);if(o.providerOptions?.anthropic?.type===`mcp-tool-use`){r.add(o.toolCallId);let t=o.providerOptions?.anthropic?.serverName;if(t==null||typeof t!=`string`){n.push({type:`other`,message:`mcp tool use server name is required and must be a string`});break}e.push({type:`mcp_tool_use`,id:o.toolCallId,name:o.toolName,input:o.input,server_name:t,cache_control:f})}else if(t===`code_execution`&&o.input!=null&&typeof o.input==`object`&&`type`in o.input&&typeof o.input.type==`string`&&(o.input.type===`bash_code_execution`||o.input.type===`text_editor_code_execution`))e.push({type:`server_tool_use`,id:o.toolCallId,name:o.input.type,input:o.input,cache_control:f});else if(t===`code_execution`&&o.input!=null&&typeof o.input==`object`&&`type`in o.input&&o.input.type===`programmatic-tool-call`){let{type:t,...n}=o.input;e.push({type:`server_tool_use`,id:o.toolCallId,name:`code_execution`,input:n,cache_control:f})}else t===`code_execution`||t===`web_fetch`||t===`web_search`||t===`tool_search_tool_regex`||t===`tool_search_tool_bm25`?e.push({type:`server_tool_use`,id:o.toolCallId,name:t,input:o.input,cache_control:f}):t===`advisor`?e.push({type:`server_tool_use`,id:o.toolCallId,name:`advisor`,input:{},cache_control:f}):n.push({type:`other`,message:`provider executed tool call for tool ${o.toolName} is not supported`});break}let t=o.providerOptions?.anthropic,i=t?.caller?(t.caller.type===`code_execution_20250825`||t.caller.type===`code_execution_20260120`)&&t.caller.toolId?{type:t.caller.type,tool_id:t.caller.toolId}:t.caller.type===`direct`?{type:`direct`}:void 0:void 0;e.push({type:`tool_use`,id:o.toolCallId,name:o.toolName,input:$e(o.input),...i&&{caller:i},cache_control:f});break}case`tool-result`:{let t=a.toProviderToolName(o.toolName);if(r.has(o.toolCallId)){let t=o.output;if(t.type!==`json`&&t.type!==`error-json`){n.push({type:`other`,message:`provider executed tool result output type ${t.type} for tool ${o.toolName} is not supported`});break}e.push({type:`mcp_tool_result`,tool_use_id:o.toolCallId,is_error:t.type===`error-json`,content:t.value,cache_control:f})}else if(t===`code_execution`){let t=o.output;if(t.type===`error-text`||t.type===`error-json`){let n={};try{typeof t.value==`string`?n=R(t.value):typeof t.value==`object`&&t.value!==null&&(n=t.value)}catch{}n.type===`code_execution_tool_result_error`?e.push({type:`code_execution_tool_result`,tool_use_id:o.toolCallId,content:{type:`code_execution_tool_result_error`,error_code:n.errorCode??`unknown`},cache_control:f}):e.push({type:`bash_code_execution_tool_result`,tool_use_id:o.toolCallId,cache_control:f,content:{type:`bash_code_execution_tool_result_error`,error_code:n.errorCode??`unknown`}});break}if(t.type!==`json`){n.push({type:`other`,message:`provider executed tool result output type ${t.type} for tool ${o.toolName} is not supported`});break}if(t.value==null||typeof t.value!=`object`||!(`type`in t.value)||typeof t.value.type!=`string`){n.push({type:`other`,message:`provider executed tool result output value is not a valid code execution result for tool ${o.toolName}`});break}if(t.value.type===`code_execution_result`){let n=await m({value:t.value,schema:Ie});e.push({type:`code_execution_tool_result`,tool_use_id:o.toolCallId,content:{type:n.type,stdout:n.stdout,stderr:n.stderr,return_code:n.return_code,content:n.content??[]},cache_control:f})}else if(t.value.type===`encrypted_code_execution_result`){let n=await m({value:t.value,schema:He});n.type===`encrypted_code_execution_result`&&e.push({type:`code_execution_tool_result`,tool_use_id:o.toolCallId,content:{type:n.type,encrypted_stdout:n.encrypted_stdout,stderr:n.stderr,return_code:n.return_code,content:n.content??[]},cache_control:f})}else{let n=await m({value:t.value,schema:ze});n.type===`code_execution_result`?e.push({type:`code_execution_tool_result`,tool_use_id:o.toolCallId,content:{type:n.type,stdout:n.stdout,stderr:n.stderr,return_code:n.return_code,content:n.content??[]},cache_control:f}):n.type===`bash_code_execution_result`||n.type===`bash_code_execution_tool_result_error`?e.push({type:`bash_code_execution_tool_result`,tool_use_id:o.toolCallId,cache_control:f,content:n}):e.push({type:`text_editor_code_execution_tool_result`,tool_use_id:o.toolCallId,cache_control:f,content:n})}break}if(t===`web_fetch`){let t=o.output;if(t.type===`error-json`){e.push({type:`web_fetch_tool_result`,tool_use_id:o.toolCallId,content:{type:`web_fetch_tool_result_error`,error_code:Ye(t.value).errorCode??`unavailable`},cache_control:f});break}if(t.type!==`json`){n.push({type:`other`,message:`provider executed tool result output type ${t.type} for tool ${o.toolName} is not supported`});break}let r=await m({value:t.value,schema:je});e.push({type:`web_fetch_tool_result`,tool_use_id:o.toolCallId,content:{type:`web_fetch_result`,url:r.url,retrieved_at:r.retrievedAt,content:{type:`document`,title:r.content.title,citations:r.content.citations,source:{type:r.content.source.type,media_type:r.content.source.mediaType,data:r.content.source.data}}},cache_control:f});break}if(t===`web_search`){let t=o.output;if(t.type===`error-json`){e.push({type:`web_search_tool_result`,tool_use_id:o.toolCallId,content:{type:`web_search_tool_result_error`,error_code:Ye(t.value).errorCode??`unavailable`},cache_control:f});break}if(t.type!==`json`){n.push({type:`other`,message:`provider executed tool result output type ${t.type} for tool ${o.toolName} is not supported`});break}let r=await m({value:t.value,schema:Ce});e.push({type:`web_search_tool_result`,tool_use_id:o.toolCallId,content:r.map(e=>({url:e.url,title:e.title,page_age:e.pageAge,encrypted_content:e.encryptedContent,type:e.type})),cache_control:f});break}if(t===`tool_search_tool_regex`||t===`tool_search_tool_bm25`){let t=o.output;if(t.type!==`json`){n.push({type:`other`,message:`provider executed tool result output type ${t.type} for tool ${o.toolName} is not supported`});break}let r=(await m({value:t.value,schema:Ge})).map(e=>({type:`tool_reference`,tool_name:e.toolName}));e.push({type:`tool_search_tool_result`,tool_use_id:o.toolCallId,content:{type:`tool_search_tool_search_result`,tool_references:r},cache_control:f});break}if(t===`advisor`){let t=o.output;if(t.type!==`json`&&t.type!==`error-json`){n.push({type:`other`,message:`provider executed tool result output type ${t.type} for tool ${o.toolName} is not supported`});break}let r=await m({value:t.value,schema:fe});r.type===`advisor_result`?e.push({type:`advisor_tool_result`,tool_use_id:o.toolCallId,content:{type:`advisor_result`,text:r.text},cache_control:f}):r.type===`advisor_redacted_result`?e.push({type:`advisor_tool_result`,tool_use_id:o.toolCallId,content:{type:`advisor_redacted_result`,encrypted_content:r.encryptedContent},cache_control:f}):e.push({type:`advisor_tool_result`,tool_use_id:o.toolCallId,content:{type:`advisor_tool_result_error`,error_code:r.errorCode},cache_control:f});break}n.push({type:`other`,message:`provider executed tool result for tool ${o.toolName} is not supported`});break}}}}d.push({role:`assistant`,content:Qe(e)});break}default:throw Error(`content type: ${b}`)}}return{prompt:{system:u,messages:d},betas:o}}function Ze(e){let t=[],n;for(let r of e){let{role:e}=r;switch(e){case`system`:n?.type!==`system`&&(n={type:`system`,messages:[]},t.push(n)),n.messages.push(r);break;case`assistant`:n?.type!==`assistant`&&(n={type:`assistant`,messages:[]},t.push(n)),n.messages.push(r);break;case`user`:n?.type!==`user`&&(n={type:`user`,messages:[]},t.push(n)),n.messages.push(r);break;case`tool`:n?.type!==`user`&&(n={type:`user`,messages:[]},t.push(n)),n.messages.push(r);break;default:throw Error(`Unsupported role: ${e}`)}}return t}function Qe(e){let t=[],n=[];function r(){t.push(...n.filter(e=>e.type!==`tool_use`),...n.filter(e=>e.type===`tool_use`)),n=[]}for(let i of e)i.type===`thinking`||i.type===`redacted_thinking`?(r(),t.push(i)):n.push(i);return r(),t}function $e(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:{rawInvalidInput:e}}function et({finishReason:e,isJsonResponseFromTool:t}){switch(e){case`pause_turn`:case`end_turn`:case`stop_sequence`:return`stop`;case`refusal`:return`content-filter`;case`tool_use`:return t?`stop`:`tool-calls`;case`max_tokens`:case`model_context_window_exceeded`:return`length`;case`compaction`:return`other`;default:return`other`}}var tt=new Set([`date-time`,`time`,`date`,`duration`,`email`,`hostname`,`uri`,`ipv4`,`ipv6`,`uuid`]),nt=[`minimum`,`maximum`,`exclusiveMinimum`,`exclusiveMaximum`,`multipleOf`,`minLength`,`maxLength`,`pattern`,`minItems`,`maxItems`,`uniqueItems`,`minProperties`,`maxProperties`,`not`];function rt(e){return it(e)}function $(e){return typeof e==`boolean`||!ct(e)?e:it(e)}function it(e){let t={},n=e;if(e.$ref!=null)return{$ref:e.$ref};if(e.$schema!=null&&(t.$schema=e.$schema),e.$id!=null&&(t.$id=e.$id),e.title!=null&&(t.title=e.title),e.description!=null&&(t.description=e.description),e.default!==void 0&&(t.default=e.default),e.const!==void 0&&(t.const=e.const),e.enum!=null&&(t.enum=e.enum),e.type!=null&&(t.type=e.type),e.anyOf==null?e.oneOf!=null&&(t.anyOf=e.oneOf.map($)):t.anyOf=e.anyOf.map($),e.allOf!=null&&(t.allOf=e.allOf.map($)),e.definitions!=null&&(t.definitions=Object.fromEntries(Object.entries(e.definitions).map(([e,t])=>[e,$(t)]))),n.$defs!=null){let e=t;e.$defs=Object.fromEntries(Object.entries(n.$defs).map(([e,t])=>[e,$(t)]))}(e.type===`object`||e.properties!=null)&&(e.properties!=null&&(t.properties=Object.fromEntries(Object.entries(e.properties).map(([e,t])=>[e,$(t)]))),t.additionalProperties=!1,e.required!=null&&(t.required=e.required)),e.items!=null&&(t.items=Array.isArray(e.items)?e.items.map($):$(e.items)),typeof e.format==`string`&&tt.has(e.format)&&(t.format=e.format);let r=at(e);return r!=null&&(t.description=t.description==null?r:`${t.description}
|
|
2
|
+
${r}`),t}function at(e){let t=nt.flatMap(t=>{let n=e[t];return n==null||n===!1?[]:`${ot(t)}: ${st(n)}`});return typeof e.format==`string`&&!tt.has(e.format)&&t.push(`format: ${e.format}`),t.length===0?void 0:`${t.join(`; `)}.`}function ot(e){return e.replace(/[A-Z]/g,e=>` ${e.toLowerCase()}`)}function st(e){return typeof e==`string`?e:JSON.stringify(e)}function ct(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function lt(e,t,n){if(e.type===`web_search_result_location`)return{type:`source`,sourceType:`url`,id:n(),url:e.url,title:e.title,providerMetadata:{anthropic:{citedText:e.cited_text,encryptedIndex:e.encrypted_index}}};if(e.type!==`page_location`&&e.type!==`char_location`)return;let r=t[e.document_index];if(r)return{type:`source`,sourceType:`document`,id:n(),mediaType:r.mediaType,title:e.document_title??r.title,filename:r.filename,providerMetadata:{anthropic:e.type===`page_location`?{citedText:e.cited_text,startPageNumber:e.start_page_number,endPageNumber:e.end_page_number}:{citedText:e.cited_text,startCharIndex:e.start_char_index,endCharIndex:e.end_char_index}}}}var ut=class t{constructor(e,t){this.specificationVersion=`v4`,this.modelId=e,this.config=t,this.generateId=t.generateId??q}static[ee](e){return l({modelId:e.modelId,config:e.config})}static[te](e){return new t(e.modelId,e.config)}supportsUrl(e){return e.protocol===`https:`}get provider(){return this.config.provider}get providerOptionsName(){let e=this.config.provider,t=e.indexOf(`.`);return t===-1?e:e.substring(0,t)}get supportedUrls(){var e;return(e=this.config).supportedUrls?.call(e)??{}}async getArgs({userSuppliedBetas:e,prompt:t,maxOutputTokens:n,temperature:r,topP:i,topK:a,frequencyPenalty:s,presencePenalty:c,stopSequences:l,responseFormat:u,seed:d,tools:f,toolChoice:p,reasoning:m,providerOptions:g,stream:_}){let y=[];s!=null&&y.push({type:`unsupported`,feature:`frequencyPenalty`}),c!=null&&y.push({type:`unsupported`,feature:`presencePenalty`}),d!=null&&y.push({type:`unsupported`,feature:`seed`}),r!=null&&r>1?(y.push({type:`unsupported`,feature:`temperature`,details:`${r} exceeds anthropic maximum of 1.0. clamped to 1.0`}),r=1):r!=null&&r<0&&(y.push({type:`unsupported`,feature:`temperature`,details:`${r} is below anthropic minimum of 0. clamped to 0`}),r=0),u?.type===`json`&&(u.schema??y.push({type:`unsupported`,feature:`responseFormat`,details:`JSON response format requires a schema. The response format is ignored.`}));let b=this.providerOptionsName,S=await h({provider:`anthropic`,providerOptions:g,schema:ce}),C=b===`anthropic`?null:await h({provider:b,providerOptions:g,schema:ce}),w=C!=null,T=Object.assign({},S??{},C??{}),{maxOutputTokens:E,supportsStructuredOutput:D,supportsAdaptiveThinking:O,rejectsSamplingParameters:k,supportsXhighEffort:A,isKnownModel:j}=dt(this.modelId);k&&(r!=null&&(y.push({type:`unsupported`,feature:`temperature`,details:`temperature is not supported by ${this.modelId} and will be ignored`}),r=void 0),a!=null&&(y.push({type:`unsupported`,feature:`topK`,details:`topK is not supported by ${this.modelId} and will be ignored`}),a=void 0),i!=null&&(y.push({type:`unsupported`,feature:`topP`,details:`topP is not supported by ${this.modelId} and will be ignored`}),i=void 0));let ee=j||this.modelId.startsWith(`claude-`),M=(this.config.supportsNativeStructuredOutput??!0)&&D,N=(this.config.supportsStrictTools??!0)&&D,P=T?.structuredOutputMode??`auto`,F=P===`outputFormat`||P===`auto`&&M,I=u?.type===`json`&&u.schema!=null&&!F?{type:`function`,name:`json`,description:`Respond with a JSON object.`,inputSchema:u.schema}:void 0,L=T?.contextManagement,R=new Q,z=x({tools:f,providerToolNames:{"anthropic.code_execution_20250522":`code_execution`,"anthropic.code_execution_20250825":`code_execution`,"anthropic.code_execution_20260120":`code_execution`,"anthropic.computer_20241022":`computer`,"anthropic.computer_20250124":`computer`,"anthropic.text_editor_20241022":`str_replace_editor`,"anthropic.text_editor_20250124":`str_replace_editor`,"anthropic.text_editor_20250429":`str_replace_based_edit_tool`,"anthropic.text_editor_20250728":`str_replace_based_edit_tool`,"anthropic.bash_20241022":`bash`,"anthropic.bash_20250124":`bash`,"anthropic.memory_20250818":`memory`,"anthropic.web_search_20250305":`web_search`,"anthropic.web_search_20260209":`web_search`,"anthropic.web_fetch_20250910":`web_fetch`,"anthropic.web_fetch_20260209":`web_fetch`,"anthropic.tool_search_regex_20251119":`tool_search_tool_regex`,"anthropic.tool_search_bm25_20251119":`tool_search_tool_bm25`,"anthropic.advisor_20260301":`advisor`}}),{prompt:te,betas:B}=await Xe({prompt:t,sendReasoning:T?.sendReasoning??!0,warnings:y,cacheControlValidator:R,toolNameMapping:z});if(o(m)&&T?.effort==null){let e=pt({reasoning:m,supportsAdaptiveThinking:O,supportsXhighEffort:A,maxOutputTokensForModel:E,warnings:y});e!=null&&(T.thinking??=e.thinking,e.effort!=null&&T.thinking?.type!==`disabled`&&(T.effort=e.effort))}let V=T?.thinking?.type,H=V===`enabled`||V===`adaptive`,U=H||V===`disabled`,W=V===`enabled`?T?.thinking?.budgetTokens:void 0,G=V===`adaptive`?T?.thinking?.display:void 0,K=n??E,q={model:this.modelId,max_tokens:K,temperature:r,top_k:a,top_p:i,stop_sequences:l,...U&&{thinking:{type:V,...W!=null&&{budget_tokens:W},...G!=null&&{display:G}}},...(T?.effort||T?.taskBudget||F&&u?.type===`json`&&u.schema!=null)&&{output_config:{...T?.effort&&{effort:T.effort},...T?.taskBudget&&{task_budget:{type:T.taskBudget.type,total:T.taskBudget.total,...T.taskBudget.remaining!=null&&{remaining:T.taskBudget.remaining}}},...F&&u?.type===`json`&&u.schema!=null&&{format:{type:`json_schema`,schema:rt(u.schema)}}}},...T?.speed&&{speed:T.speed},...T?.inferenceGeo&&{inference_geo:T.inferenceGeo},...T?.fallbacks&&T.fallbacks.length>0&&{fallbacks:T.fallbacks},...T?.cacheControl&&{cache_control:T.cacheControl},...T?.metadata?.userId!=null&&{metadata:{user_id:T.metadata.userId}},...T?.mcpServers&&T.mcpServers.length>0&&{mcp_servers:T.mcpServers.map(e=>({type:e.type,name:e.name,url:e.url,authorization_token:e.authorizationToken,tool_configuration:e.toolConfiguration?{allowed_tools:e.toolConfiguration.allowedTools,enabled:e.toolConfiguration.enabled}:void 0}))},...T?.container&&{container:T.container.skills&&T.container.skills.length>0?{id:T.container.id,skills:T.container.skills.map(e=>({type:e.type,skill_id:e.type===`custom`?v({reference:e.providerReference,provider:`anthropic`}):e.skillId,version:e.version}))}:T.container.id},system:te.system,messages:te.messages,...L&&{context_management:{edits:L.edits.map(e=>{let t=e.type;switch(t){case`clear_tool_uses_20250919`:return{type:e.type,...e.trigger!==void 0&&{trigger:e.trigger},...e.keep!==void 0&&{keep:e.keep},...e.clearAtLeast!==void 0&&{clear_at_least:e.clearAtLeast},...e.clearToolInputs!==void 0&&{clear_tool_inputs:e.clearToolInputs},...e.excludeTools!==void 0&&{exclude_tools:e.excludeTools}};case`clear_thinking_20251015`:return{type:e.type,...e.keep!==void 0&&{keep:e.keep}};case`compact_20260112`:return{type:e.type,...e.trigger!==void 0&&{trigger:e.trigger},...e.pauseAfterCompaction!==void 0&&{pause_after_compaction:e.pauseAfterCompaction},...e.instructions!==void 0&&{instructions:e.instructions}};default:y.push({type:`other`,message:`Unknown context management strategy: ${t}`});return}}).filter(e=>e!==void 0)}}};H?(V===`enabled`&&W==null&&(y.push({type:`compatibility`,feature:`extended thinking`,details:`thinking budget is required when thinking is enabled. using default budget of 1024 tokens.`}),q.thinking={type:`enabled`,budget_tokens:1024},W=1024),q.temperature!=null&&(q.temperature=void 0,y.push({type:`unsupported`,feature:`temperature`,details:`temperature is not supported when thinking is enabled`})),a!=null&&(q.top_k=void 0,y.push({type:`unsupported`,feature:`topK`,details:`topK is not supported when thinking is enabled`})),i!=null&&(q.top_p=void 0,y.push({type:`unsupported`,feature:`topP`,details:`topP is not supported when thinking is enabled`})),q.max_tokens=K+(W??0)):ee&&i!=null&&r!=null&&(y.push({type:`unsupported`,feature:`topP`,details:`topP is not supported when temperature is set. topP is ignored.`}),q.top_p=void 0),j&&q.max_tokens>E&&(n!=null&&y.push({type:`unsupported`,feature:`maxOutputTokens`,details:`${q.max_tokens} (maxOutputTokens + thinkingBudget) is greater than ${this.modelId} ${E} max output tokens. The max output tokens have been limited to ${E}.`}),q.max_tokens=E),T?.mcpServers&&T.mcpServers.length>0&&B.add(`mcp-client-2025-04-04`),L&&(B.add(`context-management-2025-06-27`),L.edits.some(e=>e.type===`compact_20260112`)&&B.add(`compact-2026-01-12`)),T?.container&&T.container.skills&&T.container.skills.length>0&&(B.add(`code-execution-2025-08-25`),B.add(`skills-2025-10-02`),B.add(`files-api-2025-04-14`),f?.some(e=>e.type===`provider`&&(e.id===`anthropic.code_execution_20250825`||e.id===`anthropic.code_execution_20260120`))||y.push({type:`other`,message:`code execution tool is required when using skills`})),T?.taskBudget&&B.add(`task-budgets-2026-03-13`),T?.speed===`fast`&&B.add(`fast-mode-2026-02-01`),T?.fallbacks&&T.fallbacks.length>0&&B.add(`server-side-fallback-2026-06-01`);let J=_&&(T?.toolStreaming??!0),{tools:ne,toolChoice:Y,toolWarnings:re,betas:ie}=await Pe(I==null?{tools:f??[],toolChoice:p,disableParallelToolUse:T?.disableParallelToolUse,cacheControlValidator:R,supportsStructuredOutput:M,supportsStrictTools:N,defaultEagerInputStreaming:J}:{tools:[...f??[],I],toolChoice:{type:`required`},disableParallelToolUse:!0,cacheControlValidator:R,supportsStructuredOutput:!1,supportsStrictTools:N,defaultEagerInputStreaming:J}),X=R.getWarnings();return{args:{...q,tools:ne,tool_choice:Y,stream:_===!0?!0:void 0},warnings:[...y,...re,...X],betas:new Set([...B,...ie,...e,...T?.anthropicBeta??[]]),usesJsonResponseTool:I!=null,toolNameMapping:z,providerOptionsName:b,usedCustomProviderKey:w}}async getHeaders({betas:e,headers:t}){return z(this.config.headers?await y(this.config.headers):void 0,t,e.size>0?{"anthropic-beta":Array.from(e).join(`,`)}:{})}async getBetasFromHeaders(e){let t=(this.config.headers?await y(this.config.headers):void 0)?.[`anthropic-beta`]??``,n=e?.[`anthropic-beta`]??``;return new Set([...t.toLowerCase().split(`,`),...n.toLowerCase().split(`,`)].map(e=>e.trim()).filter(e=>e!==``))}buildRequestUrl(e){var t;return(t=this.config).buildRequestUrl?.call(t,this.config.baseURL,e)??`${this.config.baseURL}/messages`}transformRequestBody(e,t){var n;return(n=this.config).transformRequestBody?.call(n,e,t)??e}extractCitationDocuments(e){return e.filter(e=>e.role===`user`).flatMap(e=>e.content).filter(e=>e.type!==`file`||e.mediaType!==`application/pdf`&&e.mediaType!==`text/plain`?!1:e.providerOptions?.anthropic?.citations?.enabled??!1).map(e=>{let t=e;return{title:t.filename??`Untitled Document`,filename:t.filename,mediaType:t.mediaType}})}async doGenerate(e){let{args:t,warnings:n,betas:r,usesJsonResponseTool:a,toolNameMapping:o,providerOptionsName:s,usedCustomProviderKey:c}=await this.getArgs({...e,stream:!1,userSuppliedBetas:await this.getBetasFromHeaders(e.headers)}),l=[...this.extractCitationDocuments(e.prompt)],u=ft(t.tools),{responseHeaders:d,value:f,rawValue:p}=await i({url:this.buildRequestUrl(!1),headers:await this.getHeaders({betas:r,headers:e.headers}),body:this.transformRequestBody(t,r),failedResponseHandler:Y,successfulResponseHandler:I(ae),abortSignal:e.abortSignal,fetch:this.config.fetch}),m=[],h={},g={},_=!1;for(let e of f.content)switch(e.type){case`text`:if(!a&&(m.push({type:`text`,text:e.text}),e.citations))for(let t of e.citations){let e=lt(t,l,this.generateId);e&&m.push(e)}break;case`thinking`:m.push({type:`reasoning`,text:e.thinking,providerMetadata:{anthropic:{signature:e.signature}}});break;case`redacted_thinking`:m.push({type:`reasoning`,text:``,providerMetadata:{anthropic:{redactedData:e.data}}});break;case`compaction`:m.push({type:`text`,text:e.content,providerMetadata:{anthropic:{type:`compaction`}}});break;case`tool_use`:if(a&&e.name===`json`)_=!0,m.push({type:`text`,text:JSON.stringify(e.input)});else{let t=e.caller,n=t?{type:t.type,toolId:`tool_id`in t?t.tool_id:void 0}:void 0;m.push({type:`tool-call`,toolCallId:e.id,toolName:e.name,input:JSON.stringify(e.input),...n&&{providerMetadata:{anthropic:{caller:n}}}})}break;case`server_tool_use`:if(e.name===`text_editor_code_execution`||e.name===`bash_code_execution`)m.push({type:`tool-call`,toolCallId:e.id,toolName:o.toCustomToolName(`code_execution`),input:JSON.stringify({type:e.name,...e.input}),providerExecuted:!0,...u?{dynamic:!0}:{}});else if(e.name===`web_search`||e.name===`code_execution`||e.name===`web_fetch`){let t=e.name===`code_execution`&&e.input!=null&&typeof e.input==`object`&&`code`in e.input&&!(`type`in e.input)?{type:`programmatic-tool-call`,...e.input}:e.input;m.push({type:`tool-call`,toolCallId:e.id,toolName:o.toCustomToolName(e.name),input:JSON.stringify(t),providerExecuted:!0,...u&&e.name===`code_execution`?{dynamic:!0}:{}})}else e.name===`tool_search_tool_regex`||e.name===`tool_search_tool_bm25`?(g[e.id]=e.name,m.push({type:`tool-call`,toolCallId:e.id,toolName:o.toCustomToolName(e.name),input:JSON.stringify(e.input),providerExecuted:!0})):e.name===`advisor`&&m.push({type:`tool-call`,toolCallId:e.id,toolName:o.toCustomToolName(`advisor`),input:JSON.stringify(e.input),providerExecuted:!0});break;case`mcp_tool_use`:h[e.id]={type:`tool-call`,toolCallId:e.id,toolName:e.name,input:JSON.stringify(e.input),providerExecuted:!0,dynamic:!0,providerMetadata:{anthropic:{type:`mcp-tool-use`,serverName:e.server_name}}},m.push(h[e.id]);break;case`mcp_tool_result`:m.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:h[e.tool_use_id].toolName,isError:e.is_error,result:e.content,dynamic:!0,providerMetadata:h[e.tool_use_id].providerMetadata});break;case`web_fetch_tool_result`:e.content.type===`web_fetch_result`?(l.push({title:e.content.content.title??e.content.url,mediaType:e.content.content.source.media_type}),m.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(`web_fetch`),result:{type:`web_fetch_result`,url:e.content.url,retrievedAt:e.content.retrieved_at,content:{type:e.content.content.type,title:e.content.content.title,citations:e.content.content.citations,source:{type:e.content.content.source.type,mediaType:e.content.content.source.media_type,data:e.content.content.source.data}}}})):e.content.type===`web_fetch_tool_result_error`&&m.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(`web_fetch`),isError:!0,result:{type:`web_fetch_tool_result_error`,errorCode:e.content.error_code}});break;case`web_search_tool_result`:if(Array.isArray(e.content)){m.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(`web_search`),result:e.content.map(e=>({url:e.url,title:e.title,pageAge:e.page_age??null,encryptedContent:e.encrypted_content,type:e.type}))});for(let t of e.content)m.push({type:`source`,sourceType:`url`,id:this.generateId(),url:t.url,title:t.title,providerMetadata:{anthropic:{pageAge:t.page_age??null}}})}else m.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(`web_search`),isError:!0,result:{type:`web_search_tool_result_error`,errorCode:e.content.error_code}});break;case`code_execution_tool_result`:e.content.type===`code_execution_result`?m.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(`code_execution`),result:{type:e.content.type,stdout:e.content.stdout,stderr:e.content.stderr,return_code:e.content.return_code,content:e.content.content??[]}}):e.content.type===`encrypted_code_execution_result`?m.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(`code_execution`),result:{type:e.content.type,encrypted_stdout:e.content.encrypted_stdout,stderr:e.content.stderr,return_code:e.content.return_code,content:e.content.content??[]}}):e.content.type===`code_execution_tool_result_error`&&m.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(`code_execution`),isError:!0,result:{type:`code_execution_tool_result_error`,errorCode:e.content.error_code}});break;case`bash_code_execution_tool_result`:case`text_editor_code_execution_tool_result`:m.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(`code_execution`),result:e.content});break;case`tool_search_tool_result`:{let t=g[e.tool_use_id];if(t==null){let e=o.toCustomToolName(`tool_search_tool_bm25`);o.toCustomToolName(`tool_search_tool_regex`),t=e===`tool_search_tool_bm25`?`tool_search_tool_regex`:`tool_search_tool_bm25`}e.content.type===`tool_search_tool_search_result`?m.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(t),result:e.content.tool_references.map(e=>({type:e.type,toolName:e.tool_name}))}):m.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:o.toCustomToolName(t),isError:!0,result:{type:`tool_search_tool_result_error`,errorCode:e.content.error_code}});break}case`advisor_tool_result`:{let t=o.toCustomToolName(`advisor`);e.content.type===`advisor_result`?m.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:t,result:{type:`advisor_result`,text:e.content.text}}):e.content.type===`advisor_redacted_result`?m.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:t,result:{type:`advisor_redacted_result`,encryptedContent:e.content.encrypted_content}}):m.push({type:`tool-result`,toolCallId:e.tool_use_id,toolName:t,isError:!0,result:{type:`advisor_tool_result_error`,errorCode:e.content.error_code}});break}case`fallback`:break}return{content:m,finishReason:{unified:et({finishReason:f.stop_reason,isJsonResponseFromTool:_}),raw:f.stop_reason??void 0},usage:Fe({usage:f.usage}),request:{body:t},response:{id:f.id??void 0,modelId:f.model??void 0,headers:d,body:p},warnings:n,providerMetadata:(()=>{let e=ht(f.stop_details),t={usage:f.usage,stopSequence:f.stop_sequence??null,...e==null?{}:{stopDetails:e},iterations:f.usage.iterations?f.usage.iterations.map(e=>({type:e.type,...e.model==null?{}:{model:e.model},inputTokens:e.input_tokens,outputTokens:e.output_tokens,...e.cache_creation_input_tokens?{cacheCreationInputTokens:e.cache_creation_input_tokens}:{},...e.cache_read_input_tokens?{cacheReadInputTokens:e.cache_read_input_tokens}:{}})):null,container:f.container?{expiresAt:f.container.expires_at,id:f.container.id,skills:f.container.skills?.map(e=>({type:e.type,skillId:e.skill_id,version:e.version}))??null}:null,contextManagement:mt(f.context_management)??null},n={anthropic:t};return c&&s!==`anthropic`&&(n[s]=t),n})()}}async doStream(t){"use step";let{args:n,warnings:r,betas:a,usesJsonResponseTool:o,toolNameMapping:s,providerOptionsName:c,usedCustomProviderKey:l}=await this.getArgs({...t,stream:!0,userSuppliedBetas:await this.getBetasFromHeaders(t.headers)}),u=[...this.extractCitationDocuments(t.prompt)],d=ft(n.tools),f=this.buildRequestUrl(!0),{responseHeaders:p,value:m}=await i({url:f,headers:await this.getHeaders({betas:a,headers:t.headers}),body:this.transformRequestBody(n,a),failedResponseHandler:Y,successfulResponseHandler:T(oe),abortSignal:t.abortSignal,fetch:this.config.fetch}),h={unified:`other`,raw:void 0},g={input_tokens:0,output_tokens:0,cache_creation_input_tokens:0,cache_read_input_tokens:0,iterations:null},_={},v={},y={},b=null,x,S=null,C,w=null,E=!1,D,O=this.generateId,[k,A]=m.pipeThrough(new TransformStream({start(e){e.enqueue({type:`stream-start`,warnings:r})},transform(e,n){if(t.includeRawChunks&&n.enqueue({type:`raw`,rawValue:e.rawValue}),!e.success){n.enqueue({type:`error`,error:e.error});return}let r=e.value;switch(r.type){case`ping`:return;case`content_block_start`:{let e=r.content_block,t=e.type;if(t===`fallback`)return;switch(D=t,t){case`text`:if(o)return;_[r.index]={type:`text`},n.enqueue({type:`text-start`,id:String(r.index)});return;case`thinking`:_[r.index]={type:`reasoning`},n.enqueue({type:`reasoning-start`,id:String(r.index)});return;case`redacted_thinking`:_[r.index]={type:`reasoning`},n.enqueue({type:`reasoning-start`,id:String(r.index),providerMetadata:{anthropic:{redactedData:e.data}}});return;case`compaction`:_[r.index]={type:`text`},n.enqueue({type:`text-start`,id:String(r.index),providerMetadata:{anthropic:{type:`compaction`}}});return;case`tool_use`:if(o&&e.name===`json`)E=!0,_[r.index]={type:`text`},n.enqueue({type:`text-start`,id:String(r.index)});else{let t=e.caller,i=t?{type:t.type,toolId:`tool_id`in t?t.tool_id:void 0}:void 0,a=e.input&&Object.keys(e.input).length>0?JSON.stringify(e.input):``;_[r.index]={type:`tool-call`,toolCallId:e.id,toolName:e.name,input:a,firstDelta:a.length===0,...i&&{caller:i}},n.enqueue({type:`tool-input-start`,id:e.id,toolName:e.name})}return;case`server_tool_use`:if([`web_fetch`,`web_search`,`code_execution`,`text_editor_code_execution`,`bash_code_execution`].includes(e.name)){let t=e.name===`text_editor_code_execution`||e.name===`bash_code_execution`?`code_execution`:e.name,i=e.name===`text_editor_code_execution`||e.name===`bash_code_execution`?e.name:e.name===`code_execution`?`programmatic-tool-call`:void 0,a=s.toCustomToolName(t),o=e.input!=null&&typeof e.input==`object`&&Object.keys(e.input).length>0?JSON.stringify(e.input):``;_[r.index]={type:`tool-call`,toolCallId:e.id,toolName:a,input:o,providerExecuted:!0,...d&&t===`code_execution`?{dynamic:!0}:{},firstDelta:o.length===0,providerToolName:t,providerToolInputType:i},n.enqueue({type:`tool-input-start`,id:e.id,toolName:a,providerExecuted:!0,...d&&t===`code_execution`?{dynamic:!0}:{}})}else if(e.name===`tool_search_tool_regex`||e.name===`tool_search_tool_bm25`){y[e.id]=e.name;let t=s.toCustomToolName(e.name);_[r.index]={type:`tool-call`,toolCallId:e.id,toolName:t,input:``,providerExecuted:!0,firstDelta:!0,providerToolName:e.name},n.enqueue({type:`tool-input-start`,id:e.id,toolName:t,providerExecuted:!0})}else if(e.name===`advisor`){let t=s.toCustomToolName(`advisor`);_[r.index]={type:`tool-call`,toolCallId:e.id,toolName:t,input:`{}`,providerExecuted:!0,firstDelta:!0,providerToolName:e.name},n.enqueue({type:`tool-input-start`,id:e.id,toolName:t,providerExecuted:!0})}return;case`web_fetch_tool_result`:e.content.type===`web_fetch_result`?(u.push({title:e.content.content.title??e.content.url,mediaType:e.content.content.source.media_type}),n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:s.toCustomToolName(`web_fetch`),result:{type:`web_fetch_result`,url:e.content.url,retrievedAt:e.content.retrieved_at,content:{type:e.content.content.type,title:e.content.content.title,citations:e.content.content.citations,source:{type:e.content.content.source.type,mediaType:e.content.content.source.media_type,data:e.content.content.source.data}}}})):e.content.type===`web_fetch_tool_result_error`&&n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:s.toCustomToolName(`web_fetch`),isError:!0,result:{type:`web_fetch_tool_result_error`,errorCode:e.content.error_code}});return;case`web_search_tool_result`:if(Array.isArray(e.content)){n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:s.toCustomToolName(`web_search`),result:e.content.map(e=>({url:e.url,title:e.title,pageAge:e.page_age??null,encryptedContent:e.encrypted_content,type:e.type}))});for(let t of e.content)n.enqueue({type:`source`,sourceType:`url`,id:O(),url:t.url,title:t.title,providerMetadata:{anthropic:{pageAge:t.page_age??null}}})}else n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:s.toCustomToolName(`web_search`),isError:!0,result:{type:`web_search_tool_result_error`,errorCode:e.content.error_code}});return;case`code_execution_tool_result`:e.content.type===`code_execution_result`?n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:s.toCustomToolName(`code_execution`),result:{type:e.content.type,stdout:e.content.stdout,stderr:e.content.stderr,return_code:e.content.return_code,content:e.content.content??[]}}):e.content.type===`encrypted_code_execution_result`?n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:s.toCustomToolName(`code_execution`),result:{type:e.content.type,encrypted_stdout:e.content.encrypted_stdout,stderr:e.content.stderr,return_code:e.content.return_code,content:e.content.content??[]}}):e.content.type===`code_execution_tool_result_error`&&n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:s.toCustomToolName(`code_execution`),isError:!0,result:{type:`code_execution_tool_result_error`,errorCode:e.content.error_code}});return;case`bash_code_execution_tool_result`:case`text_editor_code_execution_tool_result`:n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:s.toCustomToolName(`code_execution`),result:e.content});return;case`tool_search_tool_result`:{let t=y[e.tool_use_id];if(t==null){let e=s.toCustomToolName(`tool_search_tool_bm25`);s.toCustomToolName(`tool_search_tool_regex`),t=e===`tool_search_tool_bm25`?`tool_search_tool_regex`:`tool_search_tool_bm25`}e.content.type===`tool_search_tool_search_result`?n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:s.toCustomToolName(t),result:e.content.tool_references.map(e=>({type:e.type,toolName:e.tool_name}))}):n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:s.toCustomToolName(t),isError:!0,result:{type:`tool_search_tool_result_error`,errorCode:e.content.error_code}});return}case`advisor_tool_result`:{let t=s.toCustomToolName(`advisor`);e.content.type===`advisor_result`?n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:t,result:{type:`advisor_result`,text:e.content.text}}):e.content.type===`advisor_redacted_result`?n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:t,result:{type:`advisor_redacted_result`,encryptedContent:e.content.encrypted_content}}):n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:t,isError:!0,result:{type:`advisor_tool_result_error`,errorCode:e.content.error_code}});return}case`mcp_tool_use`:v[e.id]={type:`tool-call`,toolCallId:e.id,toolName:e.name,input:JSON.stringify(e.input),providerExecuted:!0,dynamic:!0,providerMetadata:{anthropic:{type:`mcp-tool-use`,serverName:e.server_name}}},n.enqueue(v[e.id]);return;case`mcp_tool_result`:n.enqueue({type:`tool-result`,toolCallId:e.tool_use_id,toolName:v[e.tool_use_id].toolName,isError:e.is_error,result:e.content,dynamic:!0,providerMetadata:v[e.tool_use_id].providerMetadata});return;default:throw Error(`Unsupported content block type: ${t}`)}}case`content_block_stop`:if(_[r.index]!=null){let e=_[r.index];switch(e.type){case`text`:n.enqueue({type:`text-end`,id:String(r.index)});break;case`reasoning`:n.enqueue({type:`reasoning-end`,id:String(r.index)});break;case`tool-call`:if(!(o&&e.toolName===`json`)){n.enqueue({type:`tool-input-end`,id:e.toolCallId});let t=e.input===``?`{}`:e.input;if(e.providerToolName===`code_execution`)try{let e=R(t);typeof e==`object`&&e&&`code`in e&&!(`type`in e)&&(t=JSON.stringify({type:`programmatic-tool-call`,...e}))}catch{}n.enqueue({type:`tool-call`,toolCallId:e.toolCallId,toolName:e.toolName,input:t,providerExecuted:e.providerExecuted,...d&&e.providerToolName===`code_execution`?{dynamic:!0}:{},...e.caller&&{providerMetadata:{anthropic:{caller:e.caller}}}})}break}delete _[r.index]}D=void 0;return;case`content_block_delta`:{let e=r.delta.type;switch(e){case`text_delta`:if(o)return;n.enqueue({type:`text-delta`,id:String(r.index),delta:r.delta.text});return;case`thinking_delta`:n.enqueue({type:`reasoning-delta`,id:String(r.index),delta:r.delta.thinking});return;case`signature_delta`:D===`thinking`&&n.enqueue({type:`reasoning-delta`,id:String(r.index),delta:``,providerMetadata:{anthropic:{signature:r.delta.signature}}});return;case`compaction_delta`:r.delta.content!=null&&n.enqueue({type:`text-delta`,id:String(r.index),delta:r.delta.content});return;case`input_json_delta`:{let e=_[r.index],t=r.delta.partial_json;if(t.length===0)return;if(E){if(e?.type!==`text`)return;n.enqueue({type:`text-delta`,id:String(r.index),delta:t})}else{if(e?.type!==`tool-call`)return;e.firstDelta&&e.providerToolInputType!=null&&(t=`{"type": "${e.providerToolInputType}",${t.substring(1)}`),n.enqueue({type:`tool-input-delta`,id:e.toolCallId,delta:t}),e.input+=t,e.firstDelta=!1}return}case`citations_delta`:{let e=r.delta.citation,t=lt(e,u,O);t&&n.enqueue(t);return}default:throw Error(`Unsupported delta type: ${e}`)}}case`message_start`:if(g.input_tokens=r.message.usage.input_tokens,g.cache_read_input_tokens=r.message.usage.cache_read_input_tokens??0,g.cache_creation_input_tokens=r.message.usage.cache_creation_input_tokens??0,x={...r.message.usage},r.message.container!=null&&(w={expiresAt:r.message.container.expires_at,id:r.message.container.id,skills:null}),r.message.stop_reason!=null&&(h={unified:et({finishReason:r.message.stop_reason,isJsonResponseFromTool:E}),raw:r.message.stop_reason}),n.enqueue({type:`response-metadata`,id:r.message.id??void 0,modelId:r.message.model??void 0}),r.message.content!=null)for(let e=0;e<r.message.content.length;e++){let t=r.message.content[e];if(t.type===`tool_use`){let e=t.caller,r=e?{type:e.type,toolId:`tool_id`in e?e.tool_id:void 0}:void 0;n.enqueue({type:`tool-input-start`,id:t.id,toolName:t.name});let i=JSON.stringify(t.input??{});n.enqueue({type:`tool-input-delta`,id:t.id,delta:i}),n.enqueue({type:`tool-input-end`,id:t.id}),n.enqueue({type:`tool-call`,toolCallId:t.id,toolName:t.name,input:i,...r&&{providerMetadata:{anthropic:{caller:r}}}})}}return;case`message_delta`:r.usage.input_tokens!=null&&g.input_tokens!==r.usage.input_tokens&&(g.input_tokens=r.usage.input_tokens),g.output_tokens=r.usage.output_tokens,r.usage.cache_read_input_tokens!=null&&(g.cache_read_input_tokens=r.usage.cache_read_input_tokens),r.usage.cache_creation_input_tokens!=null&&(g.cache_creation_input_tokens=r.usage.cache_creation_input_tokens),r.usage.iterations!=null&&(g.iterations=r.usage.iterations),h={unified:et({finishReason:r.delta.stop_reason,isJsonResponseFromTool:E}),raw:r.delta.stop_reason??void 0},S=r.delta.stop_sequence??null,C=ht(r.delta.stop_details),w=r.delta.container==null?null:{expiresAt:r.delta.container.expires_at,id:r.delta.container.id,skills:r.delta.container.skills?.map(e=>({type:e.type,skillId:e.skill_id,version:e.version}))??null},r.context_management&&(b=mt(r.context_management)),x={...x,...r.usage};return;case`message_stop`:{let e={usage:x??null,stopSequence:S,...C==null?{}:{stopDetails:C},iterations:g.iterations?g.iterations.map(e=>({type:e.type,...e.model==null?{}:{model:e.model},inputTokens:e.input_tokens,outputTokens:e.output_tokens,...e.cache_creation_input_tokens?{cacheCreationInputTokens:e.cache_creation_input_tokens}:{},...e.cache_read_input_tokens?{cacheReadInputTokens:e.cache_read_input_tokens}:{}})):null,container:w,contextManagement:b},t={anthropic:e};l&&c!==`anthropic`&&(t[c]=e),n.enqueue({type:`finish`,finishReason:h,usage:Fe({usage:g,rawUsage:x}),providerMetadata:t});return}case`error`:n.enqueue({type:`error`,error:r.error});return;default:throw Error(`Unsupported chunk type: ${r}`)}}})).tee(),j=k.getReader();try{await j.read();let t=await j.read();if(t.value?.type===`raw`&&(t=await j.read()),t.value?.type===`error`){let r=t.value.error;throw new e({message:r.message,url:f,requestBodyValues:n,statusCode:r.type===`overloaded_error`?529:500,responseHeaders:p,responseBody:JSON.stringify(r),isRetryable:r.type===`overloaded_error`})}}finally{j.cancel().catch(()=>{}),j.releaseLock()}return{stream:A,request:{body:n},response:{headers:p}}}};function dt(e){return e.includes(`claude-opus-4-8`)||e.includes(`claude-opus-4-7`)||e.includes(`claude-fable-5`)||e.includes(`claude-sonnet-5`)?{maxOutputTokens:128e3,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!0,supportsXhighEffort:!0,isKnownModel:!0}:e.includes(`claude-sonnet-4-6`)||e.includes(`claude-opus-4-6`)?{maxOutputTokens:128e3,supportsStructuredOutput:!0,supportsAdaptiveThinking:!0,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!0}:e.includes(`claude-sonnet-4-5`)||e.includes(`claude-opus-4-5`)||e.includes(`claude-haiku-4-5`)?{maxOutputTokens:64e3,supportsStructuredOutput:!0,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!0}:e.includes(`claude-opus-4-1`)?{maxOutputTokens:32e3,supportsStructuredOutput:!0,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!0}:e.includes(`claude-sonnet-4-`)?{maxOutputTokens:64e3,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!0}:e.includes(`claude-opus-4-`)?{maxOutputTokens:32e3,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!0}:e.includes(`claude-3-haiku`)?{maxOutputTokens:4096,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!0}:{maxOutputTokens:4096,supportsStructuredOutput:!1,supportsAdaptiveThinking:!1,rejectsSamplingParameters:!1,supportsXhighEffort:!1,isKnownModel:!1}}function ft(e){if(!e)return!1;let t=!1,n=!1;for(let r of e){if(`type`in r&&(r.type===`web_fetch_20260209`||r.type===`web_search_20260209`)){t=!0;continue}if(r.name===`code_execution`){n=!0;break}}return t&&!n}function pt({reasoning:e,supportsAdaptiveThinking:t,supportsXhighEffort:n,maxOutputTokensForModel:r,warnings:i}){if(!o(e))return;if(e===`none`)return{thinking:{type:`disabled`}};if(t)return{thinking:{type:`adaptive`},effort:s({reasoning:e,effortMap:{minimal:`low`,low:`low`,medium:`medium`,high:`high`,xhigh:n?`xhigh`:`max`},warnings:i})};let a=p({reasoning:e,maxOutputTokens:r,maxReasoningBudget:r,warnings:i});if(a!=null)return{thinking:{type:`enabled`,budgetTokens:a}}}function mt(e){return e?{appliedEdits:e.applied_edits.map(e=>{switch(e.type){case`clear_tool_uses_20250919`:return{type:e.type,clearedToolUses:e.cleared_tool_uses,clearedInputTokens:e.cleared_input_tokens};case`clear_thinking_20251015`:return{type:e.type,clearedThinkingTurns:e.cleared_thinking_turns,clearedInputTokens:e.cleared_input_tokens};case`compact_20260112`:return{type:e.type}}}).filter(e=>e!==void 0)}:null}function ht(e){if(e!=null)return{type:e.type,...e.category==null?{}:{category:e.category},...e.explanation==null?{}:{explanation:e.explanation},...e.recommended_model==null?{}:{recommendedModel:e.recommended_model}}}var gt=N({id:`anthropic.bash_20241022`,inputSchema:M(()=>P(W({command:J(),restart:O().optional()})))});function _t(e={}){let{execute:t,...n}=e;return gt(t===void 0?{...n,execute:async({command:e},{abortSignal:t,experimental_sandbox:n})=>{if(!n)throw Error(`Sandbox session is not available`);return await n.run({command:e,abortSignal:t})}}:{...n,...t===null?{}:{execute:t}})}var vt=N({id:`anthropic.bash_20250124`,inputSchema:M(()=>P(W({command:J(),restart:O().optional()})))});function yt(e={}){let{execute:t,...n}=e;return vt(t===void 0?{...n,execute:async({command:e},{abortSignal:t,experimental_sandbox:n})=>{if(!n)throw Error(`Sandbox session is not available`);return await n.run({command:e,abortSignal:t})}}:{...n,...t===null?{}:{execute:t}})}var bt=N({id:`anthropic.computer_20241022`,inputSchema:M(()=>P(W({action:V([`key`,`type`,`mouse_move`,`left_click`,`left_click_drag`,`right_click`,`middle_click`,`double_click`,`screenshot`,`cursor_position`]),coordinate:U(S().int()).optional(),text:J().optional()})))}),xt=N({id:`anthropic.computer_20250124`,inputSchema:M(()=>P(W({action:V([`key`,`hold_key`,`type`,`cursor_position`,`mouse_move`,`left_mouse_down`,`left_mouse_up`,`left_click`,`left_click_drag`,`right_click`,`middle_click`,`double_click`,`triple_click`,`scroll`,`wait`,`screenshot`]),coordinate:_([S().int(),S().int()]).optional(),duration:S().optional(),scroll_amount:S().optional(),scroll_direction:V([`up`,`down`,`left`,`right`]).optional(),start_coordinate:_([S().int(),S().int()]).optional(),text:J().optional()})))}),St=N({id:`anthropic.computer_20251124`,inputSchema:M(()=>P(W({action:V([`key`,`hold_key`,`type`,`cursor_position`,`mouse_move`,`left_mouse_down`,`left_mouse_up`,`left_click`,`left_click_drag`,`right_click`,`middle_click`,`double_click`,`triple_click`,`scroll`,`wait`,`screenshot`,`zoom`]),coordinate:_([S().int(),S().int()]).optional(),duration:S().optional(),region:_([S().int(),S().int(),S().int(),S().int()]).optional(),scroll_amount:S().optional(),scroll_direction:V([`up`,`down`,`left`,`right`]).optional(),start_coordinate:_([S().int(),S().int()]).optional(),text:J().optional()})))}),Ct=N({id:`anthropic.memory_20250818`,inputSchema:M(()=>P(L(`command`,[W({command:j(`view`),path:J(),view_range:_([S(),S()]).optional()}),W({command:j(`create`),path:J(),file_text:J()}),W({command:j(`str_replace`),path:J(),old_str:J(),new_str:J()}),W({command:j(`insert`),path:J(),insert_line:S(),insert_text:J()}),W({command:j(`delete`),path:J()}),W({command:j(`rename`),old_path:J(),new_path:J()})])))}),wt=N({id:`anthropic.text_editor_20241022`,inputSchema:M(()=>P(W({command:V([`view`,`create`,`str_replace`,`insert`,`undo_edit`]),path:J(),file_text:J().optional(),insert_line:S().int().optional(),new_str:J().optional(),insert_text:J().optional(),old_str:J().optional(),view_range:U(S().int()).optional()})))}),Tt=N({id:`anthropic.text_editor_20250124`,inputSchema:M(()=>P(W({command:V([`view`,`create`,`str_replace`,`insert`,`undo_edit`]),path:J(),file_text:J().optional(),insert_line:S().int().optional(),new_str:J().optional(),insert_text:J().optional(),old_str:J().optional(),view_range:U(S().int()).optional()})))}),Et=N({id:`anthropic.text_editor_20250429`,inputSchema:M(()=>P(W({command:V([`view`,`create`,`str_replace`,`insert`]),path:J(),file_text:J().optional(),insert_line:S().int().optional(),new_str:J().optional(),insert_text:J().optional(),old_str:J().optional(),view_range:U(S().int()).optional()})))}),Dt=M(()=>P(U(W({type:j(`tool_reference`),toolName:J()})))),Ot=k({id:`anthropic.tool_search_bm25_20251119`,inputSchema:M(()=>P(W({query:J(),limit:S().optional()}))),outputSchema:Dt,supportsDeferredResults:!0}),kt={advisor_20260301:me,bash_20241022:_t,bash_20250124:yt,codeExecution_20250522:Re,codeExecution_20250825:Ve,codeExecution_20260120:We,computer_20241022:bt,computer_20250124:xt,computer_20251124:St,memory_20250818:Ct,textEditor_20241022:wt,textEditor_20250124:Tt,textEditor_20250429:Et,textEditor_20250728:_e,webFetch_20250910:Ne,webFetch_20260209:ke,webSearch_20250305:Te,webSearch_20260209:xe,toolSearchRegex_20251119:qe,toolSearchBm25_20251119:(e={})=>Ot(e)},At=M(()=>P(W({id:J(),display_title:J().nullish(),name:J().nullish(),description:J().nullish(),latest_version:J().nullish(),source:J(),created_at:J(),updated_at:J()})));M(()=>P(W({data:U(W({version:J()}))})));var jt=M(()=>P(W({type:J(),skill_id:J(),name:J().nullish(),description:J().nullish()}))),Mt=class{constructor(e){this.config=e,this.specificationVersion=`v4`}get provider(){return this.config.provider}async getHeaders(){return z(await y(this.config.headers),{"anthropic-beta":`skills-2025-10-02`})}async fetchVersionMetadata({skillId:e,version:t,headers:n}){let{value:r}=await g({url:`${this.config.baseURL}/skills/${e}/versions/${t}`,validateUrl:!1,headers:n,failedResponseHandler:Y,successfulResponseHandler:I(jt),fetch:this.config.fetch});return{...r.name==null?{}:{name:r.name},...r.description==null?{}:{description:r.description}}}async uploadSkill(e){let t=[],n=new FormData;e.displayTitle!=null&&n.append(`display_title`,e.displayTitle);for(let t of e.files){let e=F(t.data);n.append(`files[]`,new Blob([e]),t.path)}let r=await this.getHeaders(),{value:i}=await ne({url:`${this.config.baseURL}/skills`,headers:r,formData:n,failedResponseHandler:Y,successfulResponseHandler:I(At),fetch:this.config.fetch}),a=i.latest_version==null?{}:await this.fetchVersionMetadata({skillId:i.id,version:i.latest_version,headers:r}),o=a.name??i.name,s=a.description??i.description;return{providerReference:{anthropic:i.id},...i.display_title==null?{}:{displayTitle:i.display_title},...o==null?{}:{name:o},...s==null?{}:{description:s},...i.latest_version==null?{}:{latestVersion:i.latest_version},providerMetadata:{anthropic:{...i.source==null?{}:{source:i.source},...i.created_at==null?{}:{createdAt:i.created_at},...i.updated_at==null?{}:{updatedAt:i.updated_at}}},warnings:t}}},Nt=`4.0.14`,Pt=`https://api.anthropic.com`,Ft=`${Pt}/v1`;function It(e){let t=H(b(e));return t===Pt?Ft:t}function Lt(e={}){let r=It(d({settingValue:e.baseURL,environmentVariableName:`ANTHROPIC_BASE_URL`}))??Ft,i=e.name??`anthropic.messages`;if(e.apiKey&&e.authToken)throw new t({argument:`apiKey/authToken`,message:`Both apiKey and authToken were provided. Please use only one authentication method.`});let a=()=>E({"anthropic-version":`2023-06-01`,...e.authToken?{Authorization:`Bearer ${e.authToken}`}:{"x-api-key":u({apiKey:e.apiKey,environmentVariableName:`ANTHROPIC_API_KEY`,description:`Anthropic`})},...e.headers},`ai-sdk/anthropic/${Nt}`),o=t=>new ut(t,{provider:i,baseURL:r,headers:a,fetch:e.fetch,generateId:e.generateId??q,supportedUrls:()=>({"image/*":[/^https?:\/\/.*$/],"application/pdf":[/^https?:\/\/.*$/]})}),s=()=>new Mt({provider:`${i.replace(`.messages`,``)}.skills`,baseURL:r,headers:a,fetch:e.fetch}),c=function(e){if(new.target)throw Error(`The Anthropic model function cannot be called with the new keyword.`);return o(e)};return c.specificationVersion=`v4`,c.languageModel=o,c.chat=o,c.messages=o,c.embeddingModel=e=>{throw new n({modelId:e,modelType:`embeddingModel`})},c.textEmbeddingModel=c.embeddingModel,c.imageModel=e=>{throw new n({modelId:e,modelType:`imageModel`})},c.files=()=>new ie({provider:i,baseURL:r,headers:a,fetch:e.fetch}),c.skills=s,c.tools=kt,c}var Rt=Lt();function zt({steps:e}){for(let t=e.length-1;t>=0;t--){let n=e[t].providerMetadata?.anthropic?.container?.id;if(n)return{providerOptions:{anthropic:{container:{id:n}}}}}}export{Nt as VERSION,Rt as anthropic,Lt as createAnthropic,zt as forwardAnthropicContainerIdFromLastStep};
|
|
@@ -387,6 +387,13 @@ type GoogleInteractionsProviderMetadata = {
|
|
|
387
387
|
* Service tier used for this interaction (passthrough for observability).
|
|
388
388
|
*/
|
|
389
389
|
serviceTier?: string;
|
|
390
|
+
/**
|
|
391
|
+
* Output token counts keyed by modality (e.g. `{ video: 57920 }`), sourced
|
|
392
|
+
* from the Interactions API `output_tokens_by_modality`. Present only when
|
|
393
|
+
* the response reports a breakdown. Preview surface for per-modality billing;
|
|
394
|
+
* may be promoted to a first-class usage field later.
|
|
395
|
+
*/
|
|
396
|
+
outputTokensByModality?: Record<string, number>;
|
|
390
397
|
/**
|
|
391
398
|
* Per-block signature hash for backend validation. Set by the SDK on output
|
|
392
399
|
* reasoning / tool-call parts and round-tripped on input parts.
|