@fairyhunter13/ai-anthropic 3.0.58-fork.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.
Files changed (53) hide show
  1. package/CHANGELOG.md +2521 -0
  2. package/LICENSE +13 -0
  3. package/README.md +43 -0
  4. package/dist/index.d.mts +1099 -0
  5. package/dist/index.d.ts +1099 -0
  6. package/dist/index.js +5222 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/index.mjs +5298 -0
  9. package/dist/index.mjs.map +1 -0
  10. package/dist/internal/index.d.mts +960 -0
  11. package/dist/internal/index.d.ts +960 -0
  12. package/dist/internal/index.js +5122 -0
  13. package/dist/internal/index.js.map +1 -0
  14. package/dist/internal/index.mjs +5190 -0
  15. package/dist/internal/index.mjs.map +1 -0
  16. package/docs/05-anthropic.mdx +1321 -0
  17. package/internal.d.ts +1 -0
  18. package/package.json +83 -0
  19. package/src/anthropic-error.ts +26 -0
  20. package/src/anthropic-message-metadata.ts +143 -0
  21. package/src/anthropic-messages-api.ts +1348 -0
  22. package/src/anthropic-messages-language-model.ts +2407 -0
  23. package/src/anthropic-messages-options.ts +267 -0
  24. package/src/anthropic-prepare-tools.ts +404 -0
  25. package/src/anthropic-provider.ts +177 -0
  26. package/src/anthropic-tools.ts +238 -0
  27. package/src/convert-anthropic-messages-usage.ts +73 -0
  28. package/src/convert-to-anthropic-messages-prompt.ts +1144 -0
  29. package/src/forward-anthropic-container-id-from-last-step.ts +38 -0
  30. package/src/get-cache-control.ts +63 -0
  31. package/src/index.ts +17 -0
  32. package/src/internal/index.ts +4 -0
  33. package/src/map-anthropic-stop-reason.ts +30 -0
  34. package/src/tool/bash_20241022.ts +33 -0
  35. package/src/tool/bash_20250124.ts +33 -0
  36. package/src/tool/code-execution_20250522.ts +61 -0
  37. package/src/tool/code-execution_20250825.ts +281 -0
  38. package/src/tool/code-execution_20260120.ts +315 -0
  39. package/src/tool/computer_20241022.ts +87 -0
  40. package/src/tool/computer_20250124.ts +130 -0
  41. package/src/tool/computer_20251124.ts +151 -0
  42. package/src/tool/memory_20250818.ts +62 -0
  43. package/src/tool/text-editor_20241022.ts +69 -0
  44. package/src/tool/text-editor_20250124.ts +69 -0
  45. package/src/tool/text-editor_20250429.ts +70 -0
  46. package/src/tool/text-editor_20250728.ts +86 -0
  47. package/src/tool/tool-search-bm25_20251119.ts +99 -0
  48. package/src/tool/tool-search-regex_20251119.ts +111 -0
  49. package/src/tool/web-fetch-20250910.ts +145 -0
  50. package/src/tool/web-fetch-20260209.ts +145 -0
  51. package/src/tool/web-search_20250305.ts +136 -0
  52. package/src/tool/web-search_20260209.ts +136 -0
  53. package/src/version.ts +6 -0
@@ -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,69 @@
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
+ insert_text: z.string().optional(),
17
+ old_str: z.string().optional(),
18
+ view_range: z.array(z.number().int()).optional(),
19
+ }),
20
+ ),
21
+ );
22
+
23
+ export const textEditor_20241022 = createProviderToolFactory<
24
+ {
25
+ /**
26
+ * The commands to run. Allowed options are: `view`, `create`, `str_replace`, `insert`, `undo_edit`.
27
+ */
28
+ command: 'view' | 'create' | 'str_replace' | 'insert' | 'undo_edit';
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).
47
+ */
48
+ new_str?: string;
49
+
50
+ /**
51
+ * Required parameter of `insert` command containing the text to insert.
52
+ */
53
+ insert_text?: 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
+ id: 'anthropic.text_editor_20241022',
68
+ inputSchema: textEditor_20241022InputSchema,
69
+ });
@@ -0,0 +1,69 @@
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
+ insert_text: z.string().optional(),
17
+ old_str: z.string().optional(),
18
+ view_range: z.array(z.number().int()).optional(),
19
+ }),
20
+ ),
21
+ );
22
+
23
+ export const textEditor_20250124 = createProviderToolFactory<
24
+ {
25
+ /**
26
+ * The commands to run. Allowed options are: `view`, `create`, `str_replace`, `insert`, `undo_edit`.
27
+ */
28
+ command: 'view' | 'create' | 'str_replace' | 'insert' | 'undo_edit';
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).
47
+ */
48
+ new_str?: string;
49
+
50
+ /**
51
+ * Required parameter of `insert` command containing the text to insert.
52
+ */
53
+ insert_text?: 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
+ id: 'anthropic.text_editor_20250124',
68
+ inputSchema: textEditor_20250124InputSchema,
69
+ });
@@ -0,0 +1,70 @@
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
+ insert_text: z.string().optional(),
17
+ old_str: z.string().optional(),
18
+ view_range: z.array(z.number().int()).optional(),
19
+ }),
20
+ ),
21
+ );
22
+
23
+ export const textEditor_20250429 = createProviderToolFactory<
24
+ {
25
+ /**
26
+ * The commands to run. Allowed options are: `view`, `create`, `str_replace`, `insert`.
27
+ * Note: `undo_edit` is not supported in Claude 4 models.
28
+ */
29
+ command: 'view' | 'create' | 'str_replace' | 'insert';
30
+
31
+ /**
32
+ * Absolute path to file or directory, e.g. `/repo/file.py` or `/repo`.
33
+ */
34
+ path: string;
35
+
36
+ /**
37
+ * Required parameter of `create` command, with the content of the file to be created.
38
+ */
39
+ file_text?: string;
40
+
41
+ /**
42
+ * Required parameter of `insert` command. The `new_str` will be inserted AFTER the line `insert_line` of `path`.
43
+ */
44
+ insert_line?: number;
45
+
46
+ /**
47
+ * Optional parameter of `str_replace` command containing the new string (if not given, no string will be added).
48
+ */
49
+ new_str?: string;
50
+
51
+ /**
52
+ * Required parameter of `insert` command containing the text to insert.
53
+ */
54
+ insert_text?: string;
55
+
56
+ /**
57
+ * Required parameter of `str_replace` command containing the string in `path` to replace.
58
+ */
59
+ old_str?: string;
60
+
61
+ /**
62
+ * 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.
63
+ */
64
+ view_range?: number[];
65
+ },
66
+ {}
67
+ >({
68
+ id: 'anthropic.text_editor_20250429',
69
+ inputSchema: textEditor_20250429InputSchema,
70
+ });
@@ -0,0 +1,86 @@
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
+ insert_text: z.string().optional(),
22
+ old_str: z.string().optional(),
23
+ view_range: z.array(z.number().int()).optional(),
24
+ }),
25
+ ),
26
+ );
27
+
28
+ const factory = createProviderToolFactory<
29
+ {
30
+ /**
31
+ * The commands to run. Allowed options are: `view`, `create`, `str_replace`, `insert`.
32
+ * Note: `undo_edit` is not supported in Claude 4 models.
33
+ */
34
+ command: 'view' | 'create' | 'str_replace' | 'insert';
35
+
36
+ /**
37
+ * Absolute path to file or directory, e.g. `/repo/file.py` or `/repo`.
38
+ */
39
+ path: string;
40
+
41
+ /**
42
+ * Required parameter of `create` command, with the content of the file to be created.
43
+ */
44
+ file_text?: string;
45
+
46
+ /**
47
+ * Required parameter of `insert` command. The `new_str` will be inserted AFTER the line `insert_line` of `path`.
48
+ */
49
+ insert_line?: number;
50
+
51
+ /**
52
+ * Optional parameter of `str_replace` command containing the new string (if not given, no string will be added).
53
+ */
54
+ new_str?: string;
55
+
56
+ /**
57
+ * Required parameter of `insert` command containing the text to insert.
58
+ */
59
+ insert_text?: string;
60
+
61
+ /**
62
+ * Required parameter of `str_replace` command containing the string in `path` to replace.
63
+ */
64
+ old_str?: string;
65
+
66
+ /**
67
+ * 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.
68
+ */
69
+ view_range?: number[];
70
+ },
71
+ {
72
+ /**
73
+ * Optional parameter to control truncation when viewing large files. Only compatible with text_editor_20250728 and later versions.
74
+ */
75
+ maxCharacters?: number;
76
+ }
77
+ >({
78
+ id: 'anthropic.text_editor_20250728',
79
+ inputSchema: textEditor_20250728InputSchema,
80
+ });
81
+
82
+ export const textEditor_20250728 = (
83
+ args: Parameters<typeof factory>[0] = {}, // default
84
+ ) => {
85
+ return factory(args);
86
+ };
@@ -0,0 +1,99 @@
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
+ supportsDeferredResults: true,
68
+ });
69
+
70
+ /**
71
+ * Creates a tool search tool that uses BM25 (natural language) to find tools.
72
+ *
73
+ * The tool search tool enables Claude to work with hundreds or thousands of tools
74
+ * by dynamically discovering and loading them on-demand. Instead of loading all
75
+ * tool definitions into the context window upfront, Claude searches your tool
76
+ * catalog and loads only the tools it needs.
77
+ *
78
+ * When Claude uses this tool, it uses natural language queries (NOT regex patterns)
79
+ * to search for tools using BM25 text search.
80
+ *
81
+ * **Important**: This tool should never have `deferLoading: true` in providerOptions.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * import { anthropicTools } from '@ai-sdk/anthropic';
86
+ *
87
+ * const tools = {
88
+ * toolSearch: anthropicTools.toolSearchBm25_20251119(),
89
+ * // Other tools with deferLoading...
90
+ * };
91
+ * ```
92
+ *
93
+ * @see https://docs.anthropic.com/en/docs/agents-and-tools/tool-search-tool
94
+ */
95
+ export const toolSearchBm25_20251119 = (
96
+ args: Parameters<typeof factory>[0] = {},
97
+ ) => {
98
+ return factory(args);
99
+ };
@@ -0,0 +1,111 @@
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
+ supportsDeferredResults: true,
80
+ });
81
+
82
+ /**
83
+ * Creates a tool search tool that uses regex patterns to find tools.
84
+ *
85
+ * The tool search tool enables Claude to work with hundreds or thousands of tools
86
+ * by dynamically discovering and loading them on-demand. Instead of loading all
87
+ * tool definitions into the context window upfront, Claude searches your tool
88
+ * catalog and loads only the tools it needs.
89
+ *
90
+ * When Claude uses this tool, it constructs regex patterns using Python's
91
+ * re.search() syntax (NOT natural language queries).
92
+ *
93
+ * **Important**: This tool should never have `deferLoading: true` in providerOptions.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * import { anthropicTools } from '@ai-sdk/anthropic';
98
+ *
99
+ * const tools = {
100
+ * toolSearch: anthropicTools.toolSearchRegex_20251119(),
101
+ * // Other tools with deferLoading...
102
+ * };
103
+ * ```
104
+ *
105
+ * @see https://docs.anthropic.com/en/docs/agents-and-tools/tool-search-tool
106
+ */
107
+ export const toolSearchRegex_20251119 = (
108
+ args: Parameters<typeof factory>[0] = {},
109
+ ) => {
110
+ return factory(args);
111
+ };