@ai-sdk/anthropic 4.0.0-beta.5 → 4.0.0-beta.67

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +500 -4
  2. package/README.md +2 -0
  3. package/dist/index.d.ts +265 -68
  4. package/dist/index.js +2636 -1427
  5. package/dist/index.js.map +1 -1
  6. package/dist/internal/index.d.ts +234 -62
  7. package/dist/internal/index.js +2605 -1413
  8. package/dist/internal/index.js.map +1 -1
  9. package/docs/05-anthropic.mdx +303 -20
  10. package/package.json +16 -17
  11. package/src/{anthropic-messages-api.ts → anthropic-api.ts} +158 -17
  12. package/src/anthropic-error.ts +1 -1
  13. package/src/anthropic-files.ts +95 -0
  14. package/src/{anthropic-messages-options.ts → anthropic-language-model-options.ts} +104 -11
  15. package/src/{anthropic-messages-language-model.ts → anthropic-language-model.ts} +494 -96
  16. package/src/anthropic-message-metadata.ts +69 -9
  17. package/src/anthropic-prepare-tools.ts +31 -7
  18. package/src/anthropic-provider.ts +42 -13
  19. package/src/anthropic-tools.ts +31 -0
  20. package/src/convert-anthropic-usage.ts +109 -0
  21. package/src/{convert-to-anthropic-messages-prompt.ts → convert-to-anthropic-prompt.ts} +376 -198
  22. package/src/forward-anthropic-container-id-from-last-step.ts +2 -2
  23. package/src/get-cache-control.ts +5 -2
  24. package/src/index.ts +1 -1
  25. package/src/internal/index.ts +13 -2
  26. package/src/map-anthropic-stop-reason.ts +1 -1
  27. package/src/sanitize-json-schema.ts +203 -0
  28. package/src/skills/anthropic-skills-api.ts +44 -0
  29. package/src/skills/anthropic-skills.ts +132 -0
  30. package/src/tool/advisor_20260301.ts +128 -0
  31. package/src/tool/bash_20241022.ts +84 -13
  32. package/src/tool/bash_20250124.ts +84 -13
  33. package/src/tool/code-execution_20250522.ts +2 -2
  34. package/src/tool/code-execution_20250825.ts +2 -2
  35. package/src/tool/code-execution_20260120.ts +2 -2
  36. package/src/tool/computer_20241022.ts +2 -2
  37. package/src/tool/computer_20250124.ts +2 -2
  38. package/src/tool/computer_20251124.ts +2 -2
  39. package/src/tool/memory_20250818.ts +2 -2
  40. package/src/tool/text-editor_20241022.ts +2 -2
  41. package/src/tool/text-editor_20250124.ts +2 -2
  42. package/src/tool/text-editor_20250429.ts +2 -2
  43. package/src/tool/text-editor_20250728.ts +6 -3
  44. package/src/tool/tool-search-bm25_20251119.ts +2 -2
  45. package/src/tool/tool-search-regex_20251119.ts +2 -2
  46. package/src/tool/web-fetch-20250910.ts +2 -2
  47. package/src/tool/web-fetch-20260209.ts +2 -2
  48. package/src/tool/web-search_20250305.ts +2 -2
  49. package/src/tool/web-search_20260209.ts +2 -2
  50. package/dist/index.d.mts +0 -1090
  51. package/dist/index.mjs +0 -5244
  52. package/dist/index.mjs.map +0 -1
  53. package/dist/internal/index.d.mts +0 -969
  54. package/dist/internal/index.mjs +0 -5136
  55. package/dist/internal/index.mjs.map +0 -1
  56. package/src/convert-anthropic-messages-usage.ts +0 -73
@@ -1,5 +1,5 @@
1
- import { JSONObject } from '@ai-sdk/provider';
2
- import { AnthropicMessageMetadata } from './anthropic-message-metadata';
1
+ import type { JSONObject } from '@ai-sdk/provider';
2
+ import type { AnthropicMessageMetadata } from './anthropic-message-metadata';
3
3
 
4
4
  /**
5
5
  * Sets the Anthropic container ID in the provider options based on
@@ -1,5 +1,8 @@
1
- import { SharedV4Warning, SharedV4ProviderMetadata } from '@ai-sdk/provider';
2
- import { AnthropicCacheControl } from './anthropic-messages-api';
1
+ import type {
2
+ SharedV4Warning,
3
+ SharedV4ProviderMetadata,
4
+ } from '@ai-sdk/provider';
5
+ import type { AnthropicCacheControl } from './anthropic-api';
3
6
 
4
7
  // Anthropic allows a maximum of 4 cache breakpoints per request
5
8
  const MAX_CACHE_BREAKPOINTS = 4;
package/src/index.ts CHANGED
@@ -6,7 +6,7 @@ export type {
6
6
  AnthropicLanguageModelOptions,
7
7
  /** @deprecated Use `AnthropicLanguageModelOptions` instead. */
8
8
  AnthropicLanguageModelOptions as AnthropicProviderOptions,
9
- } from './anthropic-messages-options';
9
+ } from './anthropic-language-model-options';
10
10
  export type { AnthropicToolOptions } from './anthropic-prepare-tools';
11
11
  export { anthropic, createAnthropic } from './anthropic-provider';
12
12
  export type {
@@ -1,4 +1,15 @@
1
- export { AnthropicMessagesLanguageModel } from '../anthropic-messages-language-model';
1
+ export { AnthropicFiles } from '../anthropic-files';
2
+ export {
3
+ AnthropicLanguageModel,
4
+ /** @deprecated Use `AnthropicLanguageModel` instead. */
5
+ AnthropicLanguageModel as AnthropicMessagesLanguageModel,
6
+ getModelCapabilities,
7
+ } from '../anthropic-language-model';
2
8
  export { anthropicTools } from '../anthropic-tools';
3
- export type { AnthropicMessagesModelId } from '../anthropic-messages-options';
9
+ export type {
10
+ AnthropicModelId,
11
+ /** @deprecated Use `AnthropicModelId` instead. */
12
+ AnthropicModelId as AnthropicMessagesModelId,
13
+ } from '../anthropic-language-model-options';
4
14
  export { prepareTools } from '../anthropic-prepare-tools';
15
+ export { AnthropicSkills } from '../skills/anthropic-skills';
@@ -1,4 +1,4 @@
1
- import { LanguageModelV4FinishReason } from '@ai-sdk/provider';
1
+ import type { LanguageModelV4FinishReason } from '@ai-sdk/provider';
2
2
 
3
3
  /**
4
4
  * @see https://docs.anthropic.com/en/api/messages#response-stop-reason
@@ -0,0 +1,203 @@
1
+ import type { JSONSchema7, JSONSchema7Definition } from '@ai-sdk/provider';
2
+
3
+ const SUPPORTED_STRING_FORMATS = new Set([
4
+ 'date-time',
5
+ 'time',
6
+ 'date',
7
+ 'duration',
8
+ 'email',
9
+ 'hostname',
10
+ 'uri',
11
+ 'ipv4',
12
+ 'ipv6',
13
+ 'uuid',
14
+ ]);
15
+
16
+ const DESCRIPTION_CONSTRAINT_KEYS = [
17
+ 'minimum',
18
+ 'maximum',
19
+ 'exclusiveMinimum',
20
+ 'exclusiveMaximum',
21
+ 'multipleOf',
22
+ 'minLength',
23
+ 'maxLength',
24
+ 'pattern',
25
+ 'minItems',
26
+ 'maxItems',
27
+ 'uniqueItems',
28
+ 'minProperties',
29
+ 'maxProperties',
30
+ 'not',
31
+ ] satisfies Array<keyof JSONSchema7>;
32
+
33
+ /**
34
+ * Removes JSON Schema keywords that Anthropic rejects in
35
+ * `output_config.format.schema`.
36
+ *
37
+ * The full original schema is still used by AI SDK result validation. This
38
+ * only relaxes the schema sent to Anthropic's constrained decoder.
39
+ */
40
+ export function sanitizeJsonSchema(schema: JSONSchema7): JSONSchema7 {
41
+ return sanitizeSchema(schema) as JSONSchema7;
42
+ }
43
+
44
+ function sanitizeDefinition(
45
+ definition: JSONSchema7Definition,
46
+ ): JSONSchema7Definition {
47
+ if (typeof definition === 'boolean' || !isPlainObject(definition)) {
48
+ return definition;
49
+ }
50
+
51
+ return sanitizeSchema(definition as JSONSchema7);
52
+ }
53
+
54
+ function sanitizeSchema(schema: JSONSchema7): JSONSchema7 {
55
+ const result: JSONSchema7 = {};
56
+ const schemaWithDefs = schema as JSONSchema7 & {
57
+ $defs?: Record<string, JSONSchema7Definition>;
58
+ };
59
+
60
+ if (schema.$ref != null) {
61
+ return { $ref: schema.$ref };
62
+ }
63
+
64
+ if (schema.$schema != null) {
65
+ result.$schema = schema.$schema;
66
+ }
67
+
68
+ if (schema.$id != null) {
69
+ result.$id = schema.$id;
70
+ }
71
+
72
+ if (schema.title != null) {
73
+ result.title = schema.title;
74
+ }
75
+
76
+ if (schema.description != null) {
77
+ result.description = schema.description;
78
+ }
79
+
80
+ if (schema.default !== undefined) {
81
+ result.default = schema.default;
82
+ }
83
+
84
+ if (schema.const !== undefined) {
85
+ result.const = schema.const;
86
+ }
87
+
88
+ if (schema.enum != null) {
89
+ result.enum = schema.enum;
90
+ }
91
+
92
+ if (schema.type != null) {
93
+ result.type = schema.type;
94
+ }
95
+
96
+ if (schema.anyOf != null) {
97
+ result.anyOf = schema.anyOf.map(sanitizeDefinition);
98
+ } else if (schema.oneOf != null) {
99
+ result.anyOf = schema.oneOf.map(sanitizeDefinition);
100
+ }
101
+
102
+ if (schema.allOf != null) {
103
+ result.allOf = schema.allOf.map(sanitizeDefinition);
104
+ }
105
+
106
+ if (schema.definitions != null) {
107
+ result.definitions = Object.fromEntries(
108
+ Object.entries(schema.definitions).map(([name, definition]) => [
109
+ name,
110
+ sanitizeDefinition(definition),
111
+ ]),
112
+ );
113
+ }
114
+
115
+ if (schemaWithDefs.$defs != null) {
116
+ const resultWithDefs = result as JSONSchema7 & {
117
+ $defs?: Record<string, JSONSchema7Definition>;
118
+ };
119
+ resultWithDefs.$defs = Object.fromEntries(
120
+ Object.entries(schemaWithDefs.$defs).map(([name, definition]) => [
121
+ name,
122
+ sanitizeDefinition(definition),
123
+ ]),
124
+ );
125
+ }
126
+
127
+ if (schema.type === 'object' || schema.properties != null) {
128
+ if (schema.properties != null) {
129
+ result.properties = Object.fromEntries(
130
+ Object.entries(schema.properties).map(([name, definition]) => [
131
+ name,
132
+ sanitizeDefinition(definition),
133
+ ]),
134
+ );
135
+ }
136
+
137
+ result.additionalProperties = false;
138
+
139
+ if (schema.required != null) {
140
+ result.required = schema.required;
141
+ }
142
+ }
143
+
144
+ if (schema.items != null) {
145
+ result.items = Array.isArray(schema.items)
146
+ ? schema.items.map(sanitizeDefinition)
147
+ : sanitizeDefinition(schema.items);
148
+ }
149
+
150
+ if (
151
+ typeof schema.format === 'string' &&
152
+ SUPPORTED_STRING_FORMATS.has(schema.format)
153
+ ) {
154
+ result.format = schema.format;
155
+ }
156
+
157
+ const constraintDescription = getConstraintDescription(schema);
158
+ if (constraintDescription != null) {
159
+ result.description =
160
+ result.description == null
161
+ ? constraintDescription
162
+ : `${result.description}\n${constraintDescription}`;
163
+ }
164
+
165
+ return result;
166
+ }
167
+
168
+ function getConstraintDescription(schema: JSONSchema7): string | undefined {
169
+ const descriptions = DESCRIPTION_CONSTRAINT_KEYS.flatMap(key => {
170
+ const value = schema[key];
171
+
172
+ if (value == null || value === false) {
173
+ return [];
174
+ }
175
+
176
+ return `${formatConstraintName(key)}: ${formatConstraintValue(value)}`;
177
+ });
178
+
179
+ if (
180
+ typeof schema.format === 'string' &&
181
+ !SUPPORTED_STRING_FORMATS.has(schema.format)
182
+ ) {
183
+ descriptions.push(`format: ${schema.format}`);
184
+ }
185
+
186
+ return descriptions.length === 0 ? undefined : `${descriptions.join('; ')}.`;
187
+ }
188
+
189
+ function formatConstraintName(key: string): string {
190
+ return key.replace(/[A-Z]/g, match => ` ${match.toLowerCase()}`);
191
+ }
192
+
193
+ function formatConstraintValue(value: unknown): string {
194
+ if (typeof value === 'string') {
195
+ return value;
196
+ }
197
+
198
+ return JSON.stringify(value);
199
+ }
200
+
201
+ function isPlainObject(value: unknown): value is Record<string, unknown> {
202
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
203
+ }
@@ -0,0 +1,44 @@
1
+ import { lazySchema, zodSchema } from '@ai-sdk/provider-utils';
2
+ import { z } from 'zod/v4';
3
+
4
+ export const anthropicSkillResponseSchema = lazySchema(() =>
5
+ zodSchema(
6
+ z.object({
7
+ id: z.string(),
8
+ display_title: z.string().nullish(),
9
+ name: z.string().nullish(),
10
+ description: z.string().nullish(),
11
+ latest_version: z.string().nullish(),
12
+ source: z.string(),
13
+ created_at: z.string(),
14
+ updated_at: z.string(),
15
+ }),
16
+ ),
17
+ );
18
+
19
+ export type AnthropicSkillResponse = ReturnType<
20
+ typeof anthropicSkillResponseSchema
21
+ >['_type'];
22
+
23
+ export const anthropicSkillVersionListResponseSchema = lazySchema(() =>
24
+ zodSchema(
25
+ z.object({
26
+ data: z.array(
27
+ z.object({
28
+ version: z.string(),
29
+ }),
30
+ ),
31
+ }),
32
+ ),
33
+ );
34
+
35
+ export const anthropicSkillVersionResponseSchema = lazySchema(() =>
36
+ zodSchema(
37
+ z.object({
38
+ type: z.string(),
39
+ skill_id: z.string(),
40
+ name: z.string().nullish(),
41
+ description: z.string().nullish(),
42
+ }),
43
+ ),
44
+ );
@@ -0,0 +1,132 @@
1
+ import type { SkillsV4, SharedV4Warning } from '@ai-sdk/provider';
2
+ import {
3
+ combineHeaders,
4
+ convertInlineFileDataToUint8Array,
5
+ createJsonResponseHandler,
6
+ getFromApi,
7
+ postFormDataToApi,
8
+ resolve,
9
+ type FetchFunction,
10
+ type Resolvable,
11
+ } from '@ai-sdk/provider-utils';
12
+ import { anthropicFailedResponseHandler } from '../anthropic-error';
13
+ import {
14
+ anthropicSkillResponseSchema,
15
+ anthropicSkillVersionResponseSchema,
16
+ } from './anthropic-skills-api';
17
+
18
+ interface AnthropicSkillsConfig {
19
+ provider: string;
20
+ baseURL: string;
21
+ headers: Resolvable<Record<string, string | undefined>>;
22
+ fetch?: FetchFunction;
23
+ }
24
+
25
+ export class AnthropicSkills implements SkillsV4 {
26
+ readonly specificationVersion = 'v4';
27
+
28
+ get provider(): string {
29
+ return this.config.provider;
30
+ }
31
+
32
+ constructor(private readonly config: AnthropicSkillsConfig) {}
33
+
34
+ private async getHeaders(): Promise<Record<string, string | undefined>> {
35
+ return combineHeaders(await resolve(this.config.headers), {
36
+ 'anthropic-beta': 'skills-2025-10-02',
37
+ });
38
+ }
39
+
40
+ private async fetchVersionMetadata({
41
+ skillId,
42
+ version,
43
+ headers,
44
+ }: {
45
+ skillId: string;
46
+ version: string;
47
+ headers: Record<string, string | undefined>;
48
+ }): Promise<{ name?: string; description?: string }> {
49
+ const { value: versionResponse } = await getFromApi({
50
+ url: `${this.config.baseURL}/skills/${skillId}/versions/${version}`,
51
+ headers,
52
+ failedResponseHandler: anthropicFailedResponseHandler,
53
+ successfulResponseHandler: createJsonResponseHandler(
54
+ anthropicSkillVersionResponseSchema,
55
+ ),
56
+ fetch: this.config.fetch,
57
+ });
58
+
59
+ return {
60
+ ...(versionResponse.name != null ? { name: versionResponse.name } : {}),
61
+ ...(versionResponse.description != null
62
+ ? { description: versionResponse.description }
63
+ : {}),
64
+ };
65
+ }
66
+
67
+ async uploadSkill(
68
+ params: Parameters<SkillsV4['uploadSkill']>[0],
69
+ ): Promise<Awaited<ReturnType<SkillsV4['uploadSkill']>>> {
70
+ const warnings: SharedV4Warning[] = [];
71
+
72
+ const formData = new FormData();
73
+
74
+ if (params.displayTitle != null) {
75
+ formData.append('display_title', params.displayTitle);
76
+ }
77
+
78
+ for (const file of params.files) {
79
+ const content = convertInlineFileDataToUint8Array(file.data);
80
+ formData.append('files[]', new Blob([content]), file.path);
81
+ }
82
+
83
+ const headers = await this.getHeaders();
84
+
85
+ const { value: response } = await postFormDataToApi({
86
+ url: `${this.config.baseURL}/skills`,
87
+ headers,
88
+ formData,
89
+ failedResponseHandler: anthropicFailedResponseHandler,
90
+ successfulResponseHandler: createJsonResponseHandler(
91
+ anthropicSkillResponseSchema,
92
+ ),
93
+ fetch: this.config.fetch,
94
+ });
95
+
96
+ const versionMetadata =
97
+ response.latest_version != null
98
+ ? await this.fetchVersionMetadata({
99
+ skillId: response.id,
100
+ version: response.latest_version,
101
+ headers,
102
+ })
103
+ : {};
104
+
105
+ const name = versionMetadata.name ?? response.name;
106
+ const description = versionMetadata.description ?? response.description;
107
+
108
+ return {
109
+ providerReference: { anthropic: response.id },
110
+ ...(response.display_title != null
111
+ ? { displayTitle: response.display_title }
112
+ : {}),
113
+ ...(name != null ? { name } : {}),
114
+ ...(description != null ? { description } : {}),
115
+ ...(response.latest_version != null
116
+ ? { latestVersion: response.latest_version }
117
+ : {}),
118
+ providerMetadata: {
119
+ anthropic: {
120
+ ...(response.source != null ? { source: response.source } : {}),
121
+ ...(response.created_at != null
122
+ ? { createdAt: response.created_at }
123
+ : {}),
124
+ ...(response.updated_at != null
125
+ ? { updatedAt: response.updated_at }
126
+ : {}),
127
+ },
128
+ },
129
+ warnings,
130
+ };
131
+ }
132
+ }
@@ -0,0 +1,128 @@
1
+ import {
2
+ createProviderExecutedToolFactory,
3
+ lazySchema,
4
+ zodSchema,
5
+ } from '@ai-sdk/provider-utils';
6
+ import { z } from 'zod/v4';
7
+
8
+ export const advisor_20260301ArgsSchema = lazySchema(() =>
9
+ zodSchema(
10
+ z.object({
11
+ model: z.string(),
12
+ maxUses: z.number().optional(),
13
+ caching: z
14
+ .object({
15
+ type: z.literal('ephemeral'),
16
+ ttl: z.union([z.literal('5m'), z.literal('1h')]),
17
+ })
18
+ .optional(),
19
+ }),
20
+ ),
21
+ );
22
+
23
+ export const advisor_20260301OutputSchema = lazySchema(() =>
24
+ zodSchema(
25
+ z.discriminatedUnion('type', [
26
+ z.object({
27
+ type: z.literal('advisor_result'),
28
+ text: z.string(),
29
+ }),
30
+ z.object({
31
+ type: z.literal('advisor_redacted_result'),
32
+ encryptedContent: z.string(),
33
+ }),
34
+ z.object({
35
+ type: z.literal('advisor_tool_result_error'),
36
+ errorCode: z.string(),
37
+ }),
38
+ ]),
39
+ ),
40
+ );
41
+
42
+ const advisor_20260301InputSchema = lazySchema(() =>
43
+ zodSchema(z.object({}).strict()),
44
+ );
45
+
46
+ const factory = createProviderExecutedToolFactory<
47
+ // Input is always empty: the executor emits server_tool_use with empty input
48
+ // and the server constructs the advisor's view from the full transcript.
49
+ {},
50
+ | {
51
+ type: 'advisor_result';
52
+
53
+ /**
54
+ * Plaintext advice from the advisor model.
55
+ */
56
+ text: string;
57
+ }
58
+ | {
59
+ type: 'advisor_redacted_result';
60
+
61
+ /**
62
+ * Opaque, encrypted advice. Must be round-tripped verbatim on subsequent
63
+ * turns; the server decrypts it server-side when rendering the advisor's
64
+ * advice into the executor's prompt.
65
+ */
66
+ encryptedContent: string;
67
+ }
68
+ | {
69
+ type: 'advisor_tool_result_error';
70
+
71
+ /**
72
+ * Available options: `max_uses_exceeded`, `too_many_requests`,
73
+ * `overloaded`, `prompt_too_long`, `execution_time_exceeded`,
74
+ * `unavailable`.
75
+ */
76
+ errorCode: string;
77
+ },
78
+ {
79
+ /**
80
+ * The advisor model ID, such as `"claude-opus-4-8"`. Billed at this
81
+ * model's rates for the sub-inference.
82
+ *
83
+ * The advisor must be at least as capable as the executor; an invalid
84
+ * pair returns a `400 invalid_request_error` from the API.
85
+ */
86
+ model: string;
87
+
88
+ /**
89
+ * Maximum number of advisor calls allowed in a single request. Once the
90
+ * executor reaches this cap, further advisor calls return an
91
+ * `advisor_tool_result_error` with `error_code: "max_uses_exceeded"` and
92
+ * the executor continues without further advice.
93
+ *
94
+ * This is a per-request cap, not a per-conversation cap. To enforce
95
+ * conversation-level limits, count advisor calls client-side; when you
96
+ * hit your cap, remove the advisor tool from `tools` AND strip all
97
+ * `advisor_tool_result` blocks from your message history (otherwise the
98
+ * API returns `400 invalid_request_error`).
99
+ */
100
+ maxUses?: number;
101
+
102
+ /**
103
+ * Enables prompt caching for the advisor's own transcript across calls
104
+ * within a conversation. Unlike `cache_control` on content blocks, this
105
+ * is not a breakpoint marker; it is an on/off switch. The server decides
106
+ * where cache boundaries go.
107
+ *
108
+ * The cache write costs more than the reads save when the advisor is
109
+ * called two or fewer times per conversation; caching breaks even at
110
+ * roughly three advisor calls. Enable it for long agent loops; keep it
111
+ * off for short tasks. Keep it consistent across a conversation —
112
+ * toggling causes cache misses.
113
+ */
114
+ caching?: {
115
+ type: 'ephemeral';
116
+ ttl: '5m' | '1h';
117
+ };
118
+ }
119
+ >({
120
+ id: 'anthropic.advisor_20260301',
121
+ inputSchema: advisor_20260301InputSchema,
122
+ outputSchema: advisor_20260301OutputSchema,
123
+ supportsDeferredResults: true,
124
+ });
125
+
126
+ export const advisor_20260301 = (args: Parameters<typeof factory>[0]) => {
127
+ return factory(args);
128
+ };
@@ -1,10 +1,26 @@
1
1
  import {
2
- createProviderToolFactory,
2
+ createProviderDefinedToolFactory,
3
3
  lazySchema,
4
+ type Experimental_SandboxSession as SandboxSession,
5
+ type ProviderDefinedTool,
6
+ type Tool,
7
+ type ToolExecuteFunction,
4
8
  zodSchema,
5
9
  } from '@ai-sdk/provider-utils';
6
10
  import { z } from 'zod/v4';
7
11
 
12
+ type Bash20241022Input = {
13
+ /**
14
+ * The bash command to run. Required unless the tool is being restarted.
15
+ */
16
+ command: string;
17
+
18
+ /**
19
+ * Specifying true will restart this tool. Otherwise, leave this unspecified.
20
+ */
21
+ restart?: boolean;
22
+ };
23
+
8
24
  const bash_20241022InputSchema = lazySchema(() =>
9
25
  zodSchema(
10
26
  z.object({
@@ -14,20 +30,75 @@ const bash_20241022InputSchema = lazySchema(() =>
14
30
  ),
15
31
  );
16
32
 
17
- export const bash_20241022 = createProviderToolFactory<
18
- {
19
- /**
20
- * The bash command to run. Required unless the tool is being restarted.
21
- */
22
- command: string;
23
-
24
- /**
25
- * Specifying true will restart this tool. Otherwise, leave this unspecified.
26
- */
27
- restart?: boolean;
28
- },
33
+ export const bash_20241022_internal = createProviderDefinedToolFactory<
34
+ Bash20241022Input,
29
35
  {}
30
36
  >({
31
37
  id: 'anthropic.bash_20241022',
32
38
  inputSchema: bash_20241022InputSchema,
33
39
  });
40
+
41
+ type Bash20241022Options<OUTPUT> = {
42
+ execute?: ToolExecuteFunction<Bash20241022Input, OUTPUT, {}>;
43
+ needsApproval?: Tool<Bash20241022Input, OUTPUT, {}>['needsApproval'];
44
+ toModelOutput?: Tool<Bash20241022Input, OUTPUT, {}>['toModelOutput'];
45
+ onInputStart?: Tool<Bash20241022Input, OUTPUT, {}>['onInputStart'];
46
+ onInputDelta?: Tool<Bash20241022Input, OUTPUT, {}>['onInputDelta'];
47
+ onInputAvailable?: Tool<Bash20241022Input, OUTPUT, {}>['onInputAvailable'];
48
+ };
49
+
50
+ type Bash20241022OptionsWithNullableExecute<OUTPUT> = Omit<
51
+ Bash20241022Options<OUTPUT>,
52
+ 'execute'
53
+ > & {
54
+ execute?: Bash20241022Options<OUTPUT>['execute'] | null;
55
+ };
56
+
57
+ type Bash20241022DefaultOutput = Awaited<ReturnType<SandboxSession['run']>>;
58
+
59
+ export function bash_20241022(
60
+ options?: Omit<Bash20241022Options<Bash20241022DefaultOutput>, 'execute'> & {
61
+ execute?: undefined;
62
+ },
63
+ ): ProviderDefinedTool<Bash20241022Input, Bash20241022DefaultOutput, {}>;
64
+ export function bash_20241022<OUTPUT = never>(
65
+ options: Omit<Bash20241022Options<OUTPUT>, 'execute'> & {
66
+ execute: null;
67
+ },
68
+ ): ProviderDefinedTool<Bash20241022Input, OUTPUT, {}>;
69
+ export function bash_20241022<OUTPUT>(
70
+ options: Omit<Bash20241022Options<OUTPUT>, 'execute'> & {
71
+ execute: Bash20241022Options<OUTPUT>['execute'];
72
+ },
73
+ ): ProviderDefinedTool<Bash20241022Input, OUTPUT, {}>;
74
+ export function bash_20241022<OUTPUT>(
75
+ options: Bash20241022OptionsWithNullableExecute<OUTPUT> = {},
76
+ ): ProviderDefinedTool<Bash20241022Input, OUTPUT, {}> {
77
+ const { execute, ...rest } = options;
78
+
79
+ if (execute === undefined) {
80
+ return bash_20241022_internal({
81
+ ...rest,
82
+ execute: async (
83
+ { command },
84
+ { abortSignal, experimental_sandbox: sandbox },
85
+ ) => {
86
+ if (!sandbox) {
87
+ throw new Error('Sandbox session is not available');
88
+ }
89
+
90
+ return await sandbox.run({
91
+ command,
92
+ abortSignal,
93
+ });
94
+ },
95
+ } as Bash20241022Options<Bash20241022DefaultOutput>) as ReturnType<
96
+ typeof bash_20241022_internal<OUTPUT>
97
+ >;
98
+ }
99
+
100
+ return bash_20241022_internal({
101
+ ...rest,
102
+ ...(execute === null ? {} : { execute }),
103
+ } as Bash20241022Options<OUTPUT>);
104
+ }