@fairyhunter13/ai-anthropic 3.0.75-fork.4 → 3.0.75-fork.6
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/dist/index.d.ts +61 -9
- package/dist/index.js +38 -2
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +61 -9
- package/dist/internal/index.js +38 -2
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +25 -5
- package/package.json +3 -3
- package/src/tool/bash_20241022.ts +77 -12
- package/src/tool/bash_20250124.ts +77 -12
package/docs/05-anthropic.mdx
CHANGED
|
@@ -723,14 +723,31 @@ For more on prompt caching with Anthropic, see [Anthropic's Cache Control docume
|
|
|
723
723
|
|
|
724
724
|
### Bash Tool
|
|
725
725
|
|
|
726
|
-
The Bash Tool allows running bash commands.
|
|
726
|
+
The Bash Tool allows running bash commands. By default, the tool executes
|
|
727
|
+
commands through the `sandbox` that you pass to `generateText` or `streamText`:
|
|
727
728
|
|
|
728
729
|
```ts
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
730
|
+
import { anthropic } from '@ai-sdk/anthropic';
|
|
731
|
+
import { generateText, isStepCount } from 'ai';
|
|
732
|
+
|
|
733
|
+
const result = await generateText({
|
|
734
|
+
model: anthropic('claude-opus-4-7'),
|
|
735
|
+
tools: {
|
|
736
|
+
bash: anthropic.tools.bash_20250124(),
|
|
737
|
+
},
|
|
738
|
+
sandbox: {
|
|
739
|
+
description: 'A sandboxed shell environment.',
|
|
740
|
+
executeCommand: async ({ command }) => {
|
|
741
|
+
// Run the command in your sandbox and return the result.
|
|
742
|
+
return {
|
|
743
|
+
exitCode: 0,
|
|
744
|
+
stdout: `Executed: ${command}`,
|
|
745
|
+
stderr: '',
|
|
746
|
+
};
|
|
747
|
+
},
|
|
733
748
|
},
|
|
749
|
+
stopWhen: isStepCount(2),
|
|
750
|
+
prompt: 'List the files in the current directory.',
|
|
734
751
|
});
|
|
735
752
|
```
|
|
736
753
|
|
|
@@ -744,6 +761,9 @@ Parameters:
|
|
|
744
761
|
Only certain Claude versions are supported.
|
|
745
762
|
</Note>
|
|
746
763
|
|
|
764
|
+
You can also provide a custom `execute` function when you want to handle bash
|
|
765
|
+
execution directly instead of using the request sandbox.
|
|
766
|
+
|
|
747
767
|
### Memory Tool
|
|
748
768
|
|
|
749
769
|
The [Memory Tool](https://docs.claude.com/en/docs/agents-and-tools/tool-use/memory-tool) allows Claude to use a local memory, e.g. in the filesystem.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fairyhunter13/ai-anthropic",
|
|
3
|
-
"version": "3.0.75-fork.
|
|
3
|
+
"version": "3.0.75-fork.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@fairyhunter13/ai-provider": "3.0.10-fork.
|
|
52
|
-
"@fairyhunter13/ai-provider-utils": "4.0.26-fork.
|
|
51
|
+
"@fairyhunter13/ai-provider": "3.0.10-fork.13",
|
|
52
|
+
"@fairyhunter13/ai-provider-utils": "4.0.26-fork.13"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@ai-sdk/test-server": "workspace:*",
|
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createProviderDefinedToolFactory,
|
|
3
3
|
lazySchema,
|
|
4
|
+
type ProviderDefinedTool,
|
|
5
|
+
type Sandbox,
|
|
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,69 @@ const bash_20241022InputSchema = lazySchema(() =>
|
|
|
14
30
|
),
|
|
15
31
|
);
|
|
16
32
|
|
|
17
|
-
export const
|
|
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<Sandbox['executeCommand']>>;
|
|
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 ({ command }, { sandbox }) => {
|
|
83
|
+
if (!sandbox) {
|
|
84
|
+
throw new Error('Sandbox is not available');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return await sandbox.executeCommand({ command });
|
|
88
|
+
},
|
|
89
|
+
} as Bash20241022Options<Bash20241022DefaultOutput>) as ReturnType<
|
|
90
|
+
typeof bash_20241022_internal<OUTPUT>
|
|
91
|
+
>;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return bash_20241022_internal({
|
|
95
|
+
...rest,
|
|
96
|
+
...(execute === null ? {} : { execute }),
|
|
97
|
+
} as Bash20241022Options<OUTPUT>);
|
|
98
|
+
}
|
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createProviderDefinedToolFactory,
|
|
3
3
|
lazySchema,
|
|
4
|
+
type ProviderDefinedTool,
|
|
5
|
+
type Sandbox,
|
|
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 Bash20250124Input = {
|
|
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_20250124InputSchema = lazySchema(() =>
|
|
9
25
|
zodSchema(
|
|
10
26
|
z.object({
|
|
@@ -14,20 +30,69 @@ const bash_20250124InputSchema = lazySchema(() =>
|
|
|
14
30
|
),
|
|
15
31
|
);
|
|
16
32
|
|
|
17
|
-
export const
|
|
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_20250124_internal = createProviderDefinedToolFactory<
|
|
34
|
+
Bash20250124Input,
|
|
29
35
|
{}
|
|
30
36
|
>({
|
|
31
37
|
id: 'anthropic.bash_20250124',
|
|
32
38
|
inputSchema: bash_20250124InputSchema,
|
|
33
39
|
});
|
|
40
|
+
|
|
41
|
+
type Bash20250124Options<OUTPUT> = {
|
|
42
|
+
execute?: ToolExecuteFunction<Bash20250124Input, OUTPUT, {}>;
|
|
43
|
+
needsApproval?: Tool<Bash20250124Input, OUTPUT, {}>['needsApproval'];
|
|
44
|
+
toModelOutput?: Tool<Bash20250124Input, OUTPUT, {}>['toModelOutput'];
|
|
45
|
+
onInputStart?: Tool<Bash20250124Input, OUTPUT, {}>['onInputStart'];
|
|
46
|
+
onInputDelta?: Tool<Bash20250124Input, OUTPUT, {}>['onInputDelta'];
|
|
47
|
+
onInputAvailable?: Tool<Bash20250124Input, OUTPUT, {}>['onInputAvailable'];
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
type Bash20250124OptionsWithNullableExecute<OUTPUT> = Omit<
|
|
51
|
+
Bash20250124Options<OUTPUT>,
|
|
52
|
+
'execute'
|
|
53
|
+
> & {
|
|
54
|
+
execute?: Bash20250124Options<OUTPUT>['execute'] | null;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
type Bash20250124DefaultOutput = Awaited<ReturnType<Sandbox['executeCommand']>>;
|
|
58
|
+
|
|
59
|
+
export function bash_20250124(
|
|
60
|
+
options?: Omit<Bash20250124Options<Bash20250124DefaultOutput>, 'execute'> & {
|
|
61
|
+
execute?: undefined;
|
|
62
|
+
},
|
|
63
|
+
): ProviderDefinedTool<Bash20250124Input, Bash20250124DefaultOutput, {}>;
|
|
64
|
+
export function bash_20250124<OUTPUT = never>(
|
|
65
|
+
options: Omit<Bash20250124Options<OUTPUT>, 'execute'> & {
|
|
66
|
+
execute: null;
|
|
67
|
+
},
|
|
68
|
+
): ProviderDefinedTool<Bash20250124Input, OUTPUT, {}>;
|
|
69
|
+
export function bash_20250124<OUTPUT>(
|
|
70
|
+
options: Omit<Bash20250124Options<OUTPUT>, 'execute'> & {
|
|
71
|
+
execute: Bash20250124Options<OUTPUT>['execute'];
|
|
72
|
+
},
|
|
73
|
+
): ProviderDefinedTool<Bash20250124Input, OUTPUT, {}>;
|
|
74
|
+
export function bash_20250124<OUTPUT>(
|
|
75
|
+
options: Bash20250124OptionsWithNullableExecute<OUTPUT> = {},
|
|
76
|
+
): ProviderDefinedTool<Bash20250124Input, OUTPUT, {}> {
|
|
77
|
+
const { execute, ...rest } = options;
|
|
78
|
+
|
|
79
|
+
if (execute === undefined) {
|
|
80
|
+
return bash_20250124_internal({
|
|
81
|
+
...rest,
|
|
82
|
+
execute: async ({ command }, { sandbox }) => {
|
|
83
|
+
if (!sandbox) {
|
|
84
|
+
throw new Error('Sandbox is not available');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return await sandbox.executeCommand({ command });
|
|
88
|
+
},
|
|
89
|
+
} as Bash20250124Options<Bash20250124DefaultOutput>) as ReturnType<
|
|
90
|
+
typeof bash_20250124_internal<OUTPUT>
|
|
91
|
+
>;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return bash_20250124_internal({
|
|
95
|
+
...rest,
|
|
96
|
+
...(execute === null ? {} : { execute }),
|
|
97
|
+
} as Bash20250124Options<OUTPUT>);
|
|
98
|
+
}
|