@ai-sdk/anthropic 3.0.17 → 3.0.19

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 (78) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/index.js +57 -30
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +57 -30
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/internal/index.js +56 -29
  7. package/dist/internal/index.js.map +1 -1
  8. package/dist/internal/index.mjs +56 -29
  9. package/dist/internal/index.mjs.map +1 -1
  10. package/package.json +3 -2
  11. package/src/__fixtures__/anthropic-code-execution-20250825.1.chunks.txt +248 -0
  12. package/src/__fixtures__/anthropic-code-execution-20250825.1.json +70 -0
  13. package/src/__fixtures__/anthropic-code-execution-20250825.2.chunks.txt +984 -0
  14. package/src/__fixtures__/anthropic-code-execution-20250825.2.json +111 -0
  15. package/src/__fixtures__/anthropic-code-execution-20250825.pptx-skill.chunks.txt +691 -0
  16. package/src/__fixtures__/anthropic-code-execution-20250825.pptx-skill.json +1801 -0
  17. package/src/__fixtures__/anthropic-json-other-tool.1.chunks.txt +13 -0
  18. package/src/__fixtures__/anthropic-json-other-tool.1.json +26 -0
  19. package/src/__fixtures__/anthropic-json-output-format.1.chunks.txt +120 -0
  20. package/src/__fixtures__/anthropic-json-output-format.1.json +25 -0
  21. package/src/__fixtures__/anthropic-json-tool.1.chunks.txt +9 -0
  22. package/src/__fixtures__/anthropic-json-tool.1.json +37 -0
  23. package/src/__fixtures__/anthropic-json-tool.2.chunks.txt +14 -0
  24. package/src/__fixtures__/anthropic-mcp.1.chunks.txt +17 -0
  25. package/src/__fixtures__/anthropic-mcp.1.json +39 -0
  26. package/src/__fixtures__/anthropic-memory-20250818.1.json +28 -0
  27. package/src/__fixtures__/anthropic-message-delta-input-tokens.chunks.txt +8 -0
  28. package/src/__fixtures__/anthropic-programmatic-tool-calling.1.chunks.txt +278 -0
  29. package/src/__fixtures__/anthropic-programmatic-tool-calling.1.json +106 -0
  30. package/src/__fixtures__/anthropic-tool-no-args.chunks.txt +13 -0
  31. package/src/__fixtures__/anthropic-tool-no-args.json +31 -0
  32. package/src/__fixtures__/anthropic-tool-search-bm25.1.chunks.txt +47 -0
  33. package/src/__fixtures__/anthropic-tool-search-bm25.1.json +67 -0
  34. package/src/__fixtures__/anthropic-tool-search-regex.1.chunks.txt +51 -0
  35. package/src/__fixtures__/anthropic-tool-search-regex.1.json +65 -0
  36. package/src/__fixtures__/anthropic-web-fetch-tool.1.chunks.txt +64 -0
  37. package/src/__fixtures__/anthropic-web-fetch-tool.1.json +54 -0
  38. package/src/__fixtures__/anthropic-web-fetch-tool.2.json +56 -0
  39. package/src/__fixtures__/anthropic-web-fetch-tool.error.json +46 -0
  40. package/src/__fixtures__/anthropic-web-search-tool.1.chunks.txt +120 -0
  41. package/src/__fixtures__/anthropic-web-search-tool.1.json +181 -0
  42. package/src/__snapshots__/anthropic-messages-language-model.test.ts.snap +16719 -0
  43. package/src/anthropic-error.test.ts +42 -0
  44. package/src/anthropic-error.ts +26 -0
  45. package/src/anthropic-message-metadata.ts +105 -0
  46. package/src/anthropic-messages-api.ts +1188 -0
  47. package/src/anthropic-messages-language-model.test.ts +7170 -0
  48. package/src/anthropic-messages-language-model.ts +2067 -0
  49. package/src/anthropic-messages-options.ts +213 -0
  50. package/src/anthropic-prepare-tools.test.ts +1219 -0
  51. package/src/anthropic-prepare-tools.ts +341 -0
  52. package/src/anthropic-provider.test.ts +162 -0
  53. package/src/anthropic-provider.ts +152 -0
  54. package/src/anthropic-tools.ts +182 -0
  55. package/src/convert-anthropic-messages-usage.ts +32 -0
  56. package/src/convert-to-anthropic-messages-prompt.test.ts +2902 -0
  57. package/src/convert-to-anthropic-messages-prompt.ts +1050 -0
  58. package/src/forward-anthropic-container-id-from-last-step.ts +38 -0
  59. package/src/get-cache-control.ts +63 -0
  60. package/src/index.ts +10 -0
  61. package/src/internal/index.ts +4 -0
  62. package/src/map-anthropic-stop-reason.ts +28 -0
  63. package/src/tool/bash_20241022.ts +33 -0
  64. package/src/tool/bash_20250124.ts +33 -0
  65. package/src/tool/code-execution_20250522.ts +61 -0
  66. package/src/tool/code-execution_20250825.ts +281 -0
  67. package/src/tool/computer_20241022.ts +87 -0
  68. package/src/tool/computer_20250124.ts +130 -0
  69. package/src/tool/memory_20250818.ts +62 -0
  70. package/src/tool/text-editor_20241022.ts +63 -0
  71. package/src/tool/text-editor_20250124.ts +63 -0
  72. package/src/tool/text-editor_20250429.ts +64 -0
  73. package/src/tool/text-editor_20250728.ts +80 -0
  74. package/src/tool/tool-search-bm25_20251119.ts +98 -0
  75. package/src/tool/tool-search-regex_20251119.ts +110 -0
  76. package/src/tool/web-fetch-20250910.ts +145 -0
  77. package/src/tool/web-search_20250305.ts +136 -0
  78. package/src/version.ts +6 -0
@@ -0,0 +1,130 @@
1
+ import {
2
+ createProviderToolFactory,
3
+ lazySchema,
4
+ zodSchema,
5
+ } from '@ai-sdk/provider-utils';
6
+ import { z } from 'zod/v4';
7
+
8
+ const computer_20250124InputSchema = lazySchema(() =>
9
+ zodSchema(
10
+ z.object({
11
+ action: z.enum([
12
+ 'key',
13
+ 'hold_key',
14
+ 'type',
15
+ 'cursor_position',
16
+ 'mouse_move',
17
+ 'left_mouse_down',
18
+ 'left_mouse_up',
19
+ 'left_click',
20
+ 'left_click_drag',
21
+ 'right_click',
22
+ 'middle_click',
23
+ 'double_click',
24
+ 'triple_click',
25
+ 'scroll',
26
+ 'wait',
27
+ 'screenshot',
28
+ ]),
29
+ coordinate: z.tuple([z.number().int(), z.number().int()]).optional(),
30
+ duration: z.number().optional(),
31
+ scroll_amount: z.number().optional(),
32
+ scroll_direction: z.enum(['up', 'down', 'left', 'right']).optional(),
33
+ start_coordinate: z
34
+ .tuple([z.number().int(), z.number().int()])
35
+ .optional(),
36
+ text: z.string().optional(),
37
+ }),
38
+ ),
39
+ );
40
+
41
+ export const computer_20250124 = createProviderToolFactory<
42
+ {
43
+ /**
44
+ * - `key`: Press a key or key-combination on the keyboard.
45
+ * - This supports xdotool's `key` syntax.
46
+ * - Examples: "a", "Return", "alt+Tab", "ctrl+s", "Up", "KP_0" (for the numpad 0 key).
47
+ * - `hold_key`: Hold down a key or multiple keys for a specified duration (in seconds). Supports the same syntax as `key`.
48
+ * - `type`: Type a string of text on the keyboard.
49
+ * - `cursor_position`: Get the current (x, y) pixel coordinate of the cursor on the screen.
50
+ * - `mouse_move`: Move the cursor to a specified (x, y) pixel coordinate on the screen.
51
+ * - `left_mouse_down`: Press the left mouse button.
52
+ * - `left_mouse_up`: Release the left mouse button.
53
+ * - `left_click`: Click the left mouse button at the specified (x, y) pixel coordinate on the screen. You can also include a key combination to hold down while clicking using the `text` parameter.
54
+ * - `left_click_drag`: Click and drag the cursor from `start_coordinate` to a specified (x, y) pixel coordinate on the screen.
55
+ * - `right_click`: Click the right mouse button at the specified (x, y) pixel coordinate on the screen.
56
+ * - `middle_click`: Click the middle mouse button at the specified (x, y) pixel coordinate on the screen.
57
+ * - `double_click`: Double-click the left mouse button at the specified (x, y) pixel coordinate on the screen.
58
+ * - `triple_click`: Triple-click the left mouse button at the specified (x, y) pixel coordinate on the screen.
59
+ * - `scroll`: Scroll the screen in a specified direction by a specified amount of clicks of the scroll wheel, at the specified (x, y) pixel coordinate. DO NOT use PageUp/PageDown to scroll.
60
+ * - `wait`: Wait for a specified duration (in seconds).
61
+ * - `screenshot`: Take a screenshot of the screen.
62
+ */
63
+ action:
64
+ | 'key'
65
+ | 'hold_key'
66
+ | 'type'
67
+ | 'cursor_position'
68
+ | 'mouse_move'
69
+ | 'left_mouse_down'
70
+ | 'left_mouse_up'
71
+ | 'left_click'
72
+ | 'left_click_drag'
73
+ | 'right_click'
74
+ | 'middle_click'
75
+ | 'double_click'
76
+ | 'triple_click'
77
+ | 'scroll'
78
+ | 'wait'
79
+ | 'screenshot';
80
+
81
+ /**
82
+ * (x, y): The x (pixels from the left edge) and y (pixels from the top edge) coordinates to move the mouse to. Required only by `action=mouse_move` and `action=left_click_drag`.
83
+ */
84
+ coordinate?: [number, number];
85
+
86
+ /**
87
+ * The duration to hold the key down for. Required only by `action=hold_key` and `action=wait`.
88
+ */
89
+ duration?: number;
90
+
91
+ /**
92
+ * The number of 'clicks' to scroll. Required only by `action=scroll`.
93
+ */
94
+ scroll_amount?: number;
95
+
96
+ /**
97
+ * The direction to scroll the screen. Required only by `action=scroll`.
98
+ */
99
+ scroll_direction?: 'up' | 'down' | 'left' | 'right';
100
+
101
+ /**
102
+ * (x, y): The x (pixels from the left edge) and y (pixels from the top edge) coordinates to start the drag from. Required only by `action=left_click_drag`.
103
+ */
104
+ start_coordinate?: [number, number];
105
+
106
+ /**
107
+ * Required only by `action=type`, `action=key`, and `action=hold_key`. Can also be used by click or scroll actions to hold down keys while clicking or scrolling.
108
+ */
109
+ text?: string;
110
+ },
111
+ {
112
+ /**
113
+ * The width of the display being controlled by the model in pixels.
114
+ */
115
+ displayWidthPx: number;
116
+
117
+ /**
118
+ * The height of the display being controlled by the model in pixels.
119
+ */
120
+ displayHeightPx: number;
121
+
122
+ /**
123
+ * The display number to control (only relevant for X11 environments). If specified, the tool will be provided a display number in the tool definition.
124
+ */
125
+ displayNumber?: number;
126
+ }
127
+ >({
128
+ id: 'anthropic.computer_20250124',
129
+ inputSchema: computer_20250124InputSchema,
130
+ });
@@ -0,0 +1,62 @@
1
+ import {
2
+ createProviderToolFactory,
3
+ lazySchema,
4
+ zodSchema,
5
+ } from '@ai-sdk/provider-utils';
6
+ import { z } from 'zod/v4';
7
+
8
+ const memory_20250818InputSchema = lazySchema(() =>
9
+ zodSchema(
10
+ z.discriminatedUnion('command', [
11
+ z.object({
12
+ command: z.literal('view'),
13
+ path: z.string(),
14
+ view_range: z.tuple([z.number(), z.number()]).optional(),
15
+ }),
16
+ z.object({
17
+ command: z.literal('create'),
18
+ path: z.string(),
19
+ file_text: z.string(),
20
+ }),
21
+ z.object({
22
+ command: z.literal('str_replace'),
23
+ path: z.string(),
24
+ old_str: z.string(),
25
+ new_str: z.string(),
26
+ }),
27
+ z.object({
28
+ command: z.literal('insert'),
29
+ path: z.string(),
30
+ insert_line: z.number(),
31
+ insert_text: z.string(),
32
+ }),
33
+ z.object({
34
+ command: z.literal('delete'),
35
+ path: z.string(),
36
+ }),
37
+ z.object({
38
+ command: z.literal('rename'),
39
+ old_path: z.string(),
40
+ new_path: z.string(),
41
+ }),
42
+ ]),
43
+ ),
44
+ );
45
+
46
+ export const memory_20250818 = createProviderToolFactory<
47
+ | { command: 'view'; path: string; view_range?: [number, number] }
48
+ | { command: 'create'; path: string; file_text: string }
49
+ | { command: 'str_replace'; path: string; old_str: string; new_str: string }
50
+ | {
51
+ command: 'insert';
52
+ path: string;
53
+ insert_line: number;
54
+ insert_text: string;
55
+ }
56
+ | { command: 'delete'; path: string }
57
+ | { command: 'rename'; old_path: string; new_path: string },
58
+ {}
59
+ >({
60
+ id: 'anthropic.memory_20250818',
61
+ inputSchema: memory_20250818InputSchema,
62
+ });
@@ -0,0 +1,63 @@
1
+ import {
2
+ createProviderToolFactory,
3
+ lazySchema,
4
+ zodSchema,
5
+ } from '@ai-sdk/provider-utils';
6
+ import { z } from 'zod/v4';
7
+
8
+ const textEditor_20241022InputSchema = lazySchema(() =>
9
+ zodSchema(
10
+ z.object({
11
+ command: z.enum(['view', 'create', 'str_replace', 'insert', 'undo_edit']),
12
+ path: z.string(),
13
+ file_text: z.string().optional(),
14
+ insert_line: z.number().int().optional(),
15
+ new_str: z.string().optional(),
16
+ old_str: z.string().optional(),
17
+ view_range: z.array(z.number().int()).optional(),
18
+ }),
19
+ ),
20
+ );
21
+
22
+ export const textEditor_20241022 = createProviderToolFactory<
23
+ {
24
+ /**
25
+ * The commands to run. Allowed options are: `view`, `create`, `str_replace`, `insert`, `undo_edit`.
26
+ */
27
+ command: 'view' | 'create' | 'str_replace' | 'insert' | 'undo_edit';
28
+
29
+ /**
30
+ * Absolute path to file or directory, e.g. `/repo/file.py` or `/repo`.
31
+ */
32
+ path: string;
33
+
34
+ /**
35
+ * Required parameter of `create` command, with the content of the file to be created.
36
+ */
37
+ file_text?: string;
38
+
39
+ /**
40
+ * Required parameter of `insert` command. The `new_str` will be inserted AFTER the line `insert_line` of `path`.
41
+ */
42
+ insert_line?: number;
43
+
44
+ /**
45
+ * Optional parameter of `str_replace` command containing the new string (if not given, no string will be added). Required parameter of `insert` command containing the string to insert.
46
+ */
47
+ new_str?: string;
48
+
49
+ /**
50
+ * Required parameter of `str_replace` command containing the string in `path` to replace.
51
+ */
52
+ old_str?: string;
53
+
54
+ /**
55
+ * Optional parameter of `view` command when `path` points to a file. If none is given, the full file is shown. If provided, the file will be shown in the indicated line number range, e.g. [11, 12] will show lines 11 and 12. Indexing at 1 to start. Setting `[start_line, -1]` shows all lines from `start_line` to the end of the file.
56
+ */
57
+ view_range?: number[];
58
+ },
59
+ {}
60
+ >({
61
+ id: 'anthropic.text_editor_20241022',
62
+ inputSchema: textEditor_20241022InputSchema,
63
+ });
@@ -0,0 +1,63 @@
1
+ import {
2
+ createProviderToolFactory,
3
+ lazySchema,
4
+ zodSchema,
5
+ } from '@ai-sdk/provider-utils';
6
+ import { z } from 'zod/v4';
7
+
8
+ const textEditor_20250124InputSchema = lazySchema(() =>
9
+ zodSchema(
10
+ z.object({
11
+ command: z.enum(['view', 'create', 'str_replace', 'insert', 'undo_edit']),
12
+ path: z.string(),
13
+ file_text: z.string().optional(),
14
+ insert_line: z.number().int().optional(),
15
+ new_str: z.string().optional(),
16
+ old_str: z.string().optional(),
17
+ view_range: z.array(z.number().int()).optional(),
18
+ }),
19
+ ),
20
+ );
21
+
22
+ export const textEditor_20250124 = createProviderToolFactory<
23
+ {
24
+ /**
25
+ * The commands to run. Allowed options are: `view`, `create`, `str_replace`, `insert`, `undo_edit`.
26
+ */
27
+ command: 'view' | 'create' | 'str_replace' | 'insert' | 'undo_edit';
28
+
29
+ /**
30
+ * Absolute path to file or directory, e.g. `/repo/file.py` or `/repo`.
31
+ */
32
+ path: string;
33
+
34
+ /**
35
+ * Required parameter of `create` command, with the content of the file to be created.
36
+ */
37
+ file_text?: string;
38
+
39
+ /**
40
+ * Required parameter of `insert` command. The `new_str` will be inserted AFTER the line `insert_line` of `path`.
41
+ */
42
+ insert_line?: number;
43
+
44
+ /**
45
+ * Optional parameter of `str_replace` command containing the new string (if not given, no string will be added). Required parameter of `insert` command containing the string to insert.
46
+ */
47
+ new_str?: string;
48
+
49
+ /**
50
+ * Required parameter of `str_replace` command containing the string in `path` to replace.
51
+ */
52
+ old_str?: string;
53
+
54
+ /**
55
+ * Optional parameter of `view` command when `path` points to a file. If none is given, the full file is shown. If provided, the file will be shown in the indicated line number range, e.g. [11, 12] will show lines 11 and 12. Indexing at 1 to start. Setting `[start_line, -1]` shows all lines from `start_line` to the end of the file.
56
+ */
57
+ view_range?: number[];
58
+ },
59
+ {}
60
+ >({
61
+ id: 'anthropic.text_editor_20250124',
62
+ inputSchema: textEditor_20250124InputSchema,
63
+ });
@@ -0,0 +1,64 @@
1
+ import {
2
+ createProviderToolFactory,
3
+ lazySchema,
4
+ zodSchema,
5
+ } from '@ai-sdk/provider-utils';
6
+ import { z } from 'zod/v4';
7
+
8
+ const textEditor_20250429InputSchema = lazySchema(() =>
9
+ zodSchema(
10
+ z.object({
11
+ command: z.enum(['view', 'create', 'str_replace', 'insert']),
12
+ path: z.string(),
13
+ file_text: z.string().optional(),
14
+ insert_line: z.number().int().optional(),
15
+ new_str: z.string().optional(),
16
+ old_str: z.string().optional(),
17
+ view_range: z.array(z.number().int()).optional(),
18
+ }),
19
+ ),
20
+ );
21
+
22
+ export const textEditor_20250429 = createProviderToolFactory<
23
+ {
24
+ /**
25
+ * The commands to run. Allowed options are: `view`, `create`, `str_replace`, `insert`.
26
+ * Note: `undo_edit` is not supported in Claude 4 models.
27
+ */
28
+ command: 'view' | 'create' | 'str_replace' | 'insert';
29
+
30
+ /**
31
+ * Absolute path to file or directory, e.g. `/repo/file.py` or `/repo`.
32
+ */
33
+ path: string;
34
+
35
+ /**
36
+ * Required parameter of `create` command, with the content of the file to be created.
37
+ */
38
+ file_text?: string;
39
+
40
+ /**
41
+ * Required parameter of `insert` command. The `new_str` will be inserted AFTER the line `insert_line` of `path`.
42
+ */
43
+ insert_line?: number;
44
+
45
+ /**
46
+ * Optional parameter of `str_replace` command containing the new string (if not given, no string will be added). Required parameter of `insert` command containing the string to insert.
47
+ */
48
+ new_str?: string;
49
+
50
+ /**
51
+ * Required parameter of `str_replace` command containing the string in `path` to replace.
52
+ */
53
+ old_str?: string;
54
+
55
+ /**
56
+ * Optional parameter of `view` command when `path` points to a file. If none is given, the full file is shown. If provided, the file will be shown in the indicated line number range, e.g. [11, 12] will show lines 11 and 12. Indexing at 1 to start. Setting `[start_line, -1]` shows all lines from `start_line` to the end of the file.
57
+ */
58
+ view_range?: number[];
59
+ },
60
+ {}
61
+ >({
62
+ id: 'anthropic.text_editor_20250429',
63
+ inputSchema: textEditor_20250429InputSchema,
64
+ });
@@ -0,0 +1,80 @@
1
+ import { createProviderToolFactory } from '@ai-sdk/provider-utils';
2
+ import { z } from 'zod/v4';
3
+ import { lazySchema, zodSchema } from '@ai-sdk/provider-utils';
4
+
5
+ export const textEditor_20250728ArgsSchema = lazySchema(() =>
6
+ zodSchema(
7
+ z.object({
8
+ maxCharacters: z.number().optional(),
9
+ }),
10
+ ),
11
+ );
12
+
13
+ const textEditor_20250728InputSchema = lazySchema(() =>
14
+ zodSchema(
15
+ z.object({
16
+ command: z.enum(['view', 'create', 'str_replace', 'insert']),
17
+ path: z.string(),
18
+ file_text: z.string().optional(),
19
+ insert_line: z.number().int().optional(),
20
+ new_str: z.string().optional(),
21
+ old_str: z.string().optional(),
22
+ view_range: z.array(z.number().int()).optional(),
23
+ }),
24
+ ),
25
+ );
26
+
27
+ const factory = createProviderToolFactory<
28
+ {
29
+ /**
30
+ * The commands to run. Allowed options are: `view`, `create`, `str_replace`, `insert`.
31
+ * Note: `undo_edit` is not supported in Claude 4 models.
32
+ */
33
+ command: 'view' | 'create' | 'str_replace' | 'insert';
34
+
35
+ /**
36
+ * Absolute path to file or directory, e.g. `/repo/file.py` or `/repo`.
37
+ */
38
+ path: string;
39
+
40
+ /**
41
+ * Required parameter of `create` command, with the content of the file to be created.
42
+ */
43
+ file_text?: string;
44
+
45
+ /**
46
+ * Required parameter of `insert` command. The `new_str` will be inserted AFTER the line `insert_line` of `path`.
47
+ */
48
+ insert_line?: number;
49
+
50
+ /**
51
+ * Optional parameter of `str_replace` command containing the new string (if not given, no string will be added). Required parameter of `insert` command containing the string to insert.
52
+ */
53
+ new_str?: string;
54
+
55
+ /**
56
+ * Required parameter of `str_replace` command containing the string in `path` to replace.
57
+ */
58
+ old_str?: string;
59
+
60
+ /**
61
+ * Optional parameter of `view` command when `path` points to a file. If none is given, the full file is shown. If provided, the file will be shown in the indicated line number range, e.g. [11, 12] will show lines 11 and 12. Indexing at 1 to start. Setting `[start_line, -1]` shows all lines from `start_line` to the end of the file.
62
+ */
63
+ view_range?: number[];
64
+ },
65
+ {
66
+ /**
67
+ * Optional parameter to control truncation when viewing large files. Only compatible with text_editor_20250728 and later versions.
68
+ */
69
+ maxCharacters?: number;
70
+ }
71
+ >({
72
+ id: 'anthropic.text_editor_20250728',
73
+ inputSchema: textEditor_20250728InputSchema,
74
+ });
75
+
76
+ export const textEditor_20250728 = (
77
+ args: Parameters<typeof factory>[0] = {}, // default
78
+ ) => {
79
+ return factory(args);
80
+ };
@@ -0,0 +1,98 @@
1
+ import {
2
+ createProviderToolFactoryWithOutputSchema,
3
+ lazySchema,
4
+ zodSchema,
5
+ } from '@ai-sdk/provider-utils';
6
+ import { z } from 'zod/v4';
7
+
8
+ /**
9
+ * Output schema for tool search results - returns tool references
10
+ * that are automatically expanded into full tool definitions by the API.
11
+ */
12
+ export const toolSearchBm25_20251119OutputSchema = lazySchema(() =>
13
+ zodSchema(
14
+ z.array(
15
+ z.object({
16
+ type: z.literal('tool_reference'),
17
+ toolName: z.string(),
18
+ }),
19
+ ),
20
+ ),
21
+ );
22
+
23
+ /**
24
+ * Input schema for BM25-based tool search.
25
+ * Claude uses natural language queries to search for tools.
26
+ */
27
+ const toolSearchBm25_20251119InputSchema = lazySchema(() =>
28
+ zodSchema(
29
+ z.object({
30
+ /**
31
+ * A natural language query to search for tools.
32
+ * Claude will use BM25 text search to find relevant tools.
33
+ */
34
+ query: z.string(),
35
+ /**
36
+ * Maximum number of tools to return. Optional.
37
+ */
38
+ limit: z.number().optional(),
39
+ }),
40
+ ),
41
+ );
42
+
43
+ const factory = createProviderToolFactoryWithOutputSchema<
44
+ {
45
+ /**
46
+ * A natural language query to search for tools.
47
+ * Claude will use BM25 text search to find relevant tools.
48
+ */
49
+ query: string;
50
+ /**
51
+ * Maximum number of tools to return. Optional.
52
+ */
53
+ limit?: number;
54
+ },
55
+ Array<{
56
+ type: 'tool_reference';
57
+ /**
58
+ * The name of the discovered tool.
59
+ */
60
+ toolName: string;
61
+ }>,
62
+ {}
63
+ >({
64
+ id: 'anthropic.tool_search_bm25_20251119',
65
+ inputSchema: toolSearchBm25_20251119InputSchema,
66
+ outputSchema: toolSearchBm25_20251119OutputSchema,
67
+ });
68
+
69
+ /**
70
+ * Creates a tool search tool that uses BM25 (natural language) to find tools.
71
+ *
72
+ * The tool search tool enables Claude to work with hundreds or thousands of tools
73
+ * by dynamically discovering and loading them on-demand. Instead of loading all
74
+ * tool definitions into the context window upfront, Claude searches your tool
75
+ * catalog and loads only the tools it needs.
76
+ *
77
+ * When Claude uses this tool, it uses natural language queries (NOT regex patterns)
78
+ * to search for tools using BM25 text search.
79
+ *
80
+ * **Important**: This tool should never have `deferLoading: true` in providerOptions.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * import { anthropicTools } from '@ai-sdk/anthropic';
85
+ *
86
+ * const tools = {
87
+ * toolSearch: anthropicTools.toolSearchBm25_20251119(),
88
+ * // Other tools with deferLoading...
89
+ * };
90
+ * ```
91
+ *
92
+ * @see https://docs.anthropic.com/en/docs/agents-and-tools/tool-search-tool
93
+ */
94
+ export const toolSearchBm25_20251119 = (
95
+ args: Parameters<typeof factory>[0] = {},
96
+ ) => {
97
+ return factory(args);
98
+ };
@@ -0,0 +1,110 @@
1
+ import {
2
+ createProviderToolFactoryWithOutputSchema,
3
+ lazySchema,
4
+ zodSchema,
5
+ } from '@ai-sdk/provider-utils';
6
+ import { z } from 'zod/v4';
7
+
8
+ /**
9
+ * Output schema for tool search results - returns tool references
10
+ * that are automatically expanded into full tool definitions by the API.
11
+ */
12
+ export const toolSearchRegex_20251119OutputSchema = lazySchema(() =>
13
+ zodSchema(
14
+ z.array(
15
+ z.object({
16
+ type: z.literal('tool_reference'),
17
+ toolName: z.string(),
18
+ }),
19
+ ),
20
+ ),
21
+ );
22
+
23
+ /**
24
+ * Input schema for regex-based tool search.
25
+ * Claude constructs regex patterns using Python's re.search() syntax.
26
+ */
27
+ const toolSearchRegex_20251119InputSchema = lazySchema(() =>
28
+ zodSchema(
29
+ z.object({
30
+ /**
31
+ * A regex pattern to search for tools.
32
+ * Uses Python re.search() syntax. Maximum 200 characters.
33
+ *
34
+ * Examples:
35
+ * - "weather" - matches tool names/descriptions containing "weather"
36
+ * - "get_.*_data" - matches tools like get_user_data, get_weather_data
37
+ * - "database.*query|query.*database" - OR patterns for flexibility
38
+ * - "(?i)slack" - case-insensitive search
39
+ */
40
+ pattern: z.string(),
41
+ /**
42
+ * Maximum number of tools to return. Optional.
43
+ */
44
+ limit: z.number().optional(),
45
+ }),
46
+ ),
47
+ );
48
+
49
+ const factory = createProviderToolFactoryWithOutputSchema<
50
+ {
51
+ /**
52
+ * A regex pattern to search for tools.
53
+ * Uses Python re.search() syntax. Maximum 200 characters.
54
+ *
55
+ * Examples:
56
+ * - "weather" - matches tool names/descriptions containing "weather"
57
+ * - "get_.*_data" - matches tools like get_user_data, get_weather_data
58
+ * - "database.*query|query.*database" - OR patterns for flexibility
59
+ * - "(?i)slack" - case-insensitive search
60
+ */
61
+ pattern: string;
62
+ /**
63
+ * Maximum number of tools to return. Optional.
64
+ */
65
+ limit?: number;
66
+ },
67
+ Array<{
68
+ type: 'tool_reference';
69
+ /**
70
+ * The name of the discovered tool.
71
+ */
72
+ toolName: string;
73
+ }>,
74
+ {}
75
+ >({
76
+ id: 'anthropic.tool_search_regex_20251119',
77
+ inputSchema: toolSearchRegex_20251119InputSchema,
78
+ outputSchema: toolSearchRegex_20251119OutputSchema,
79
+ });
80
+
81
+ /**
82
+ * Creates a tool search tool that uses regex patterns to find tools.
83
+ *
84
+ * The tool search tool enables Claude to work with hundreds or thousands of tools
85
+ * by dynamically discovering and loading them on-demand. Instead of loading all
86
+ * tool definitions into the context window upfront, Claude searches your tool
87
+ * catalog and loads only the tools it needs.
88
+ *
89
+ * When Claude uses this tool, it constructs regex patterns using Python's
90
+ * re.search() syntax (NOT natural language queries).
91
+ *
92
+ * **Important**: This tool should never have `deferLoading: true` in providerOptions.
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * import { anthropicTools } from '@ai-sdk/anthropic';
97
+ *
98
+ * const tools = {
99
+ * toolSearch: anthropicTools.toolSearchRegex_20251119(),
100
+ * // Other tools with deferLoading...
101
+ * };
102
+ * ```
103
+ *
104
+ * @see https://docs.anthropic.com/en/docs/agents-and-tools/tool-search-tool
105
+ */
106
+ export const toolSearchRegex_20251119 = (
107
+ args: Parameters<typeof factory>[0] = {},
108
+ ) => {
109
+ return factory(args);
110
+ };