@tanstack/ai-anthropic 0.7.5 → 0.8.0

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 (45) hide show
  1. package/dist/esm/adapters/text.d.ts +5 -4
  2. package/dist/esm/adapters/text.js.map +1 -1
  3. package/dist/esm/index.d.ts +1 -1
  4. package/dist/esm/model-meta.d.ts +28 -0
  5. package/dist/esm/model-meta.js.map +1 -1
  6. package/dist/esm/tools/bash-tool.d.ts +7 -4
  7. package/dist/esm/tools/bash-tool.js +8 -0
  8. package/dist/esm/tools/bash-tool.js.map +1 -1
  9. package/dist/esm/tools/code-execution-tool.d.ts +7 -4
  10. package/dist/esm/tools/code-execution-tool.js +8 -0
  11. package/dist/esm/tools/code-execution-tool.js.map +1 -1
  12. package/dist/esm/tools/computer-use-tool.d.ts +7 -4
  13. package/dist/esm/tools/computer-use-tool.js +8 -0
  14. package/dist/esm/tools/computer-use-tool.js.map +1 -1
  15. package/dist/esm/tools/custom-tool.d.ts +4 -2
  16. package/dist/esm/tools/custom-tool.js +12 -1
  17. package/dist/esm/tools/custom-tool.js.map +1 -1
  18. package/dist/esm/tools/index.d.ts +8 -1
  19. package/dist/esm/tools/index.js +19 -0
  20. package/dist/esm/tools/index.js.map +1 -0
  21. package/dist/esm/tools/memory-tool.d.ts +7 -4
  22. package/dist/esm/tools/memory-tool.js +9 -1
  23. package/dist/esm/tools/memory-tool.js.map +1 -1
  24. package/dist/esm/tools/text-editor-tool.d.ts +7 -4
  25. package/dist/esm/tools/text-editor-tool.js +9 -1
  26. package/dist/esm/tools/text-editor-tool.js.map +1 -1
  27. package/dist/esm/tools/web-fetch-tool.d.ts +7 -4
  28. package/dist/esm/tools/web-fetch-tool.js +9 -1
  29. package/dist/esm/tools/web-fetch-tool.js.map +1 -1
  30. package/dist/esm/tools/web-search-tool.d.ts +7 -4
  31. package/dist/esm/tools/web-search-tool.js +41 -1
  32. package/dist/esm/tools/web-search-tool.js.map +1 -1
  33. package/package.json +7 -3
  34. package/src/adapters/text.ts +13 -4
  35. package/src/index.ts +2 -1
  36. package/src/model-meta.ts +126 -0
  37. package/src/tools/bash-tool.ts +13 -6
  38. package/src/tools/code-execution-tool.ts +17 -6
  39. package/src/tools/computer-use-tool.ts +14 -6
  40. package/src/tools/custom-tool.ts +5 -3
  41. package/src/tools/index.ts +49 -12
  42. package/src/tools/memory-tool.ts +12 -6
  43. package/src/tools/text-editor-tool.ts +14 -6
  44. package/src/tools/web-fetch-tool.ts +15 -7
  45. package/src/tools/web-search-tool.ts +17 -7
@@ -2,18 +2,25 @@ import type {
2
2
  BetaToolBash20241022,
3
3
  BetaToolBash20250124,
4
4
  } from '@anthropic-ai/sdk/resources/beta'
5
- import type { Tool } from '@tanstack/ai'
5
+ import type { ProviderTool, Tool } from '@tanstack/ai'
6
6
 
7
- export type BashTool = BetaToolBash20241022 | BetaToolBash20250124
7
+ export type BashToolConfig = BetaToolBash20241022 | BetaToolBash20250124
8
8
 
9
- export function convertBashToolToAdapterFormat(tool: Tool): BashTool {
10
- const metadata = tool.metadata as BashTool
9
+ /** @deprecated Renamed to `BashToolConfig`. Will be removed in a future release. */
10
+ export type BashTool = BashToolConfig
11
+
12
+ export type AnthropicBashTool = ProviderTool<'anthropic', 'bash'>
13
+
14
+ export function convertBashToolToAdapterFormat(tool: Tool): BashToolConfig {
15
+ const metadata = tool.metadata as BashToolConfig
11
16
  return metadata
12
17
  }
13
- export function bashTool(config: BashTool): Tool {
18
+
19
+ export function bashTool(config: BashToolConfig): AnthropicBashTool {
20
+ // Phantom-brand cast: '~provider'/'~toolKind' are type-only and never assigned at runtime.
14
21
  return {
15
22
  name: 'bash',
16
23
  description: '',
17
24
  metadata: config,
18
- }
25
+ } as unknown as AnthropicBashTool
19
26
  }
@@ -2,23 +2,34 @@ import type {
2
2
  BetaCodeExecutionTool20250522,
3
3
  BetaCodeExecutionTool20250825,
4
4
  } from '@anthropic-ai/sdk/resources/beta'
5
- import type { Tool } from '@tanstack/ai'
5
+ import type { ProviderTool, Tool } from '@tanstack/ai'
6
6
 
7
- export type CodeExecutionTool =
7
+ export type CodeExecutionToolConfig =
8
8
  | BetaCodeExecutionTool20250522
9
9
  | BetaCodeExecutionTool20250825
10
10
 
11
+ /** @deprecated Renamed to `CodeExecutionToolConfig`. Will be removed in a future release. */
12
+ export type CodeExecutionTool = CodeExecutionToolConfig
13
+
14
+ export type AnthropicCodeExecutionTool = ProviderTool<
15
+ 'anthropic',
16
+ 'code_execution'
17
+ >
18
+
11
19
  export function convertCodeExecutionToolToAdapterFormat(
12
20
  tool: Tool,
13
- ): CodeExecutionTool {
14
- const metadata = tool.metadata as CodeExecutionTool
21
+ ): CodeExecutionToolConfig {
22
+ const metadata = tool.metadata as CodeExecutionToolConfig
15
23
  return metadata
16
24
  }
17
25
 
18
- export function codeExecutionTool(config: CodeExecutionTool): Tool {
26
+ export function codeExecutionTool(
27
+ config: CodeExecutionToolConfig,
28
+ ): AnthropicCodeExecutionTool {
29
+ // Phantom-brand cast: '~provider'/'~toolKind' are type-only and never assigned at runtime.
19
30
  return {
20
31
  name: 'code_execution',
21
32
  description: '',
22
33
  metadata: config,
23
- }
34
+ } as unknown as AnthropicCodeExecutionTool
24
35
  }
@@ -2,23 +2,31 @@ import type {
2
2
  BetaToolComputerUse20241022,
3
3
  BetaToolComputerUse20250124,
4
4
  } from '@anthropic-ai/sdk/resources/beta'
5
- import type { Tool } from '@tanstack/ai'
5
+ import type { ProviderTool, Tool } from '@tanstack/ai'
6
6
 
7
- export type ComputerUseTool =
7
+ export type ComputerUseToolConfig =
8
8
  | BetaToolComputerUse20241022
9
9
  | BetaToolComputerUse20250124
10
10
 
11
+ /** @deprecated Renamed to `ComputerUseToolConfig`. Will be removed in a future release. */
12
+ export type ComputerUseTool = ComputerUseToolConfig
13
+
14
+ export type AnthropicComputerUseTool = ProviderTool<'anthropic', 'computer_use'>
15
+
11
16
  export function convertComputerUseToolToAdapterFormat(
12
17
  tool: Tool,
13
- ): ComputerUseTool {
14
- const metadata = tool.metadata as ComputerUseTool
18
+ ): ComputerUseToolConfig {
19
+ const metadata = tool.metadata as ComputerUseToolConfig
15
20
  return metadata
16
21
  }
17
22
 
18
- export function computerUseTool(config: ComputerUseTool): Tool {
23
+ export function computerUseTool(
24
+ config: ComputerUseToolConfig,
25
+ ): AnthropicComputerUseTool {
26
+ // Phantom-brand cast: '~provider'/'~toolKind' are type-only and never assigned at runtime.
19
27
  return {
20
28
  name: 'computer',
21
29
  description: '',
22
30
  metadata: config,
23
- }
31
+ } as unknown as AnthropicComputerUseTool
24
32
  }
@@ -1,7 +1,7 @@
1
1
  import type { JSONSchema, SchemaInput, Tool } from '@tanstack/ai'
2
2
  import type { CacheControl } from '../text/text-provider-options'
3
3
 
4
- export interface CustomTool {
4
+ export interface CustomToolConfig {
5
5
  /**
6
6
  * The name of the tool.
7
7
  */
@@ -23,11 +23,13 @@ export interface CustomTool {
23
23
  cache_control?: CacheControl | null
24
24
  }
25
25
 
26
- export function convertCustomToolToAdapterFormat(tool: Tool): CustomTool {
26
+ /** @deprecated Renamed to `CustomToolConfig`. Will be removed in a future release. */
27
+ export type CustomTool = CustomToolConfig
28
+
29
+ export function convertCustomToolToAdapterFormat(tool: Tool): CustomToolConfig {
27
30
  const metadata =
28
31
  (tool.metadata as { cacheControl?: CacheControl | null } | undefined) || {}
29
32
 
30
- // Tool schemas are already converted to JSON Schema in the ai layer
31
33
  const jsonSchema = (tool.inputSchema ?? {
32
34
  type: 'object',
33
35
  properties: {},
@@ -7,6 +7,55 @@ import type { TextEditorTool } from './text-editor-tool'
7
7
  import type { WebFetchTool } from './web-fetch-tool'
8
8
  import type { WebSearchTool } from './web-search-tool'
9
9
 
10
+ export {
11
+ bashTool,
12
+ type AnthropicBashTool,
13
+ type BashToolConfig,
14
+ type BashTool,
15
+ } from './bash-tool'
16
+ export {
17
+ codeExecutionTool,
18
+ type AnthropicCodeExecutionTool,
19
+ type CodeExecutionToolConfig,
20
+ type CodeExecutionTool,
21
+ } from './code-execution-tool'
22
+ export {
23
+ computerUseTool,
24
+ type AnthropicComputerUseTool,
25
+ type ComputerUseToolConfig,
26
+ type ComputerUseTool,
27
+ } from './computer-use-tool'
28
+ export {
29
+ customTool,
30
+ type CustomToolConfig,
31
+ type CustomTool,
32
+ } from './custom-tool'
33
+ export {
34
+ memoryTool,
35
+ type AnthropicMemoryTool,
36
+ type MemoryToolConfig,
37
+ type MemoryTool,
38
+ } from './memory-tool'
39
+ export {
40
+ textEditorTool,
41
+ type AnthropicTextEditorTool,
42
+ type TextEditorToolConfig,
43
+ type TextEditorTool,
44
+ } from './text-editor-tool'
45
+ export {
46
+ webFetchTool,
47
+ type AnthropicWebFetchTool,
48
+ type WebFetchToolConfig,
49
+ type WebFetchTool,
50
+ } from './web-fetch-tool'
51
+ export {
52
+ webSearchTool,
53
+ type AnthropicWebSearchTool,
54
+ type WebSearchToolConfig,
55
+ type WebSearchTool,
56
+ } from './web-search-tool'
57
+
58
+ // Keep the discriminated union defined inline (no barrel exports).
10
59
  export type AnthropicTool =
11
60
  | BashTool
12
61
  | CodeExecutionTool
@@ -16,15 +65,3 @@ export type AnthropicTool =
16
65
  | TextEditorTool
17
66
  | WebFetchTool
18
67
  | WebSearchTool
19
-
20
- // Export individual tool types
21
- export type {
22
- // BashTool,
23
- // CodeExecutionTool,
24
- // ComputerUseTool,
25
- CustomTool,
26
- // MemoryTool,
27
- // TextEditorTool,
28
- // WebFetchTool,
29
- // WebSearchTool,
30
- }
@@ -1,20 +1,26 @@
1
1
  import type { BetaMemoryTool20250818 } from '@anthropic-ai/sdk/resources/beta'
2
- import type { Tool } from '@tanstack/ai'
2
+ import type { ProviderTool, Tool } from '@tanstack/ai'
3
3
 
4
- export type MemoryTool = BetaMemoryTool20250818
4
+ export type MemoryToolConfig = BetaMemoryTool20250818
5
5
 
6
- export function convertMemoryToolToAdapterFormat(tool: Tool): MemoryTool {
7
- const metadata = tool.metadata as Omit<MemoryTool, 'type'>
6
+ /** @deprecated Renamed to `MemoryToolConfig`. Will be removed in a future release. */
7
+ export type MemoryTool = MemoryToolConfig
8
+
9
+ export type AnthropicMemoryTool = ProviderTool<'anthropic', 'memory'>
10
+
11
+ export function convertMemoryToolToAdapterFormat(tool: Tool): MemoryToolConfig {
12
+ const metadata = tool.metadata as Omit<MemoryToolConfig, 'type'>
8
13
  return {
9
14
  type: 'memory_20250818',
10
15
  ...metadata,
11
16
  }
12
17
  }
13
18
 
14
- export function memoryTool(config?: MemoryTool): Tool {
19
+ export function memoryTool(config?: MemoryToolConfig): AnthropicMemoryTool {
20
+ // Phantom-brand cast: '~provider'/'~toolKind' are type-only and never assigned at runtime.
15
21
  return {
16
22
  name: 'memory',
17
23
  description: '',
18
24
  metadata: config,
19
- }
25
+ } as unknown as AnthropicMemoryTool
20
26
  }
@@ -3,26 +3,34 @@ import type {
3
3
  ToolTextEditor20250429,
4
4
  ToolTextEditor20250728,
5
5
  } from '@anthropic-ai/sdk/resources/messages'
6
- import type { Tool } from '@tanstack/ai'
6
+ import type { ProviderTool, Tool } from '@tanstack/ai'
7
7
 
8
- export type TextEditorTool =
8
+ export type TextEditorToolConfig =
9
9
  | ToolTextEditor20250124
10
10
  | ToolTextEditor20250429
11
11
  | ToolTextEditor20250728
12
12
 
13
+ /** @deprecated Renamed to `TextEditorToolConfig`. Will be removed in a future release. */
14
+ export type TextEditorTool = TextEditorToolConfig
15
+
16
+ export type AnthropicTextEditorTool = ProviderTool<'anthropic', 'text_editor'>
17
+
13
18
  export function convertTextEditorToolToAdapterFormat(
14
19
  tool: Tool,
15
- ): TextEditorTool {
16
- const metadata = tool.metadata as TextEditorTool
20
+ ): TextEditorToolConfig {
21
+ const metadata = tool.metadata as TextEditorToolConfig
17
22
  return {
18
23
  ...metadata,
19
24
  }
20
25
  }
21
26
 
22
- export function textEditorTool<T extends TextEditorTool>(config: T): Tool {
27
+ export function textEditorTool<T extends TextEditorToolConfig>(
28
+ config: T,
29
+ ): AnthropicTextEditorTool {
30
+ // Phantom-brand cast: '~provider'/'~toolKind' are type-only and never assigned at runtime.
23
31
  return {
24
32
  name: 'str_replace_editor',
25
33
  description: '',
26
34
  metadata: config,
27
- }
35
+ } as unknown as AnthropicTextEditorTool
28
36
  }
@@ -1,10 +1,17 @@
1
1
  import type { BetaWebFetchTool20250910 } from '@anthropic-ai/sdk/resources/beta'
2
- import type { Tool } from '@tanstack/ai'
2
+ import type { ProviderTool, Tool } from '@tanstack/ai'
3
3
 
4
- export type WebFetchTool = BetaWebFetchTool20250910
4
+ export type WebFetchToolConfig = BetaWebFetchTool20250910
5
5
 
6
- export function convertWebFetchToolToAdapterFormat(tool: Tool): WebFetchTool {
7
- const metadata = tool.metadata as Omit<WebFetchTool, 'type' | 'name'>
6
+ /** @deprecated Renamed to `WebFetchToolConfig`. Will be removed in a future release. */
7
+ export type WebFetchTool = WebFetchToolConfig
8
+
9
+ export type AnthropicWebFetchTool = ProviderTool<'anthropic', 'web_fetch'>
10
+
11
+ export function convertWebFetchToolToAdapterFormat(
12
+ tool: Tool,
13
+ ): WebFetchToolConfig {
14
+ const metadata = tool.metadata as Omit<WebFetchToolConfig, 'type' | 'name'>
8
15
  return {
9
16
  name: 'web_fetch',
10
17
  type: 'web_fetch_20250910',
@@ -13,11 +20,12 @@ export function convertWebFetchToolToAdapterFormat(tool: Tool): WebFetchTool {
13
20
  }
14
21
 
15
22
  export function webFetchTool(
16
- config?: Omit<WebFetchTool, 'type' | 'name'>,
17
- ): Tool {
23
+ config?: Omit<WebFetchToolConfig, 'type' | 'name'>,
24
+ ): AnthropicWebFetchTool {
25
+ // Phantom-brand cast: '~provider'/'~toolKind' are type-only and never assigned at runtime.
18
26
  return {
19
27
  name: 'web_fetch',
20
28
  description: '',
21
29
  metadata: config,
22
- }
30
+ } as unknown as AnthropicWebFetchTool
23
31
  }
@@ -1,10 +1,15 @@
1
1
  import type { WebSearchTool20250305 } from '@anthropic-ai/sdk/resources/messages'
2
2
  import type { CacheControl } from '../text/text-provider-options'
3
- import type { Tool } from '@tanstack/ai'
3
+ import type { ProviderTool, Tool } from '@tanstack/ai'
4
4
 
5
- export type WebSearchTool = WebSearchTool20250305
5
+ export type WebSearchToolConfig = WebSearchTool20250305
6
6
 
7
- const validateDomains = (tool: WebSearchTool) => {
7
+ /** @deprecated Renamed to `WebSearchToolConfig`. Will be removed in a future release. */
8
+ export type WebSearchTool = WebSearchToolConfig
9
+
10
+ export type AnthropicWebSearchTool = ProviderTool<'anthropic', 'web_search'>
11
+
12
+ const validateDomains = (tool: WebSearchToolConfig) => {
8
13
  if (tool.allowed_domains && tool.blocked_domains) {
9
14
  throw new Error(
10
15
  'allowed_domains and blocked_domains cannot be used together.',
@@ -12,7 +17,7 @@ const validateDomains = (tool: WebSearchTool) => {
12
17
  }
13
18
  }
14
19
 
15
- const validateUserLocation = (tool: WebSearchTool) => {
20
+ const validateUserLocation = (tool: WebSearchToolConfig) => {
16
21
  const userLocation = tool.user_location
17
22
  if (userLocation) {
18
23
  if (
@@ -45,7 +50,9 @@ const validateUserLocation = (tool: WebSearchTool) => {
45
50
  }
46
51
  }
47
52
 
48
- export function convertWebSearchToolToAdapterFormat(tool: Tool): WebSearchTool {
53
+ export function convertWebSearchToolToAdapterFormat(
54
+ tool: Tool,
55
+ ): WebSearchToolConfig {
49
56
  const metadata = tool.metadata as {
50
57
  allowedDomains?: Array<string> | null
51
58
  blockedDomains?: Array<string> | null
@@ -70,12 +77,15 @@ export function convertWebSearchToolToAdapterFormat(tool: Tool): WebSearchTool {
70
77
  }
71
78
  }
72
79
 
73
- export function webSearchTool(config: WebSearchTool): Tool {
80
+ export function webSearchTool(
81
+ config: WebSearchToolConfig,
82
+ ): AnthropicWebSearchTool {
74
83
  validateDomains(config)
75
84
  validateUserLocation(config)
85
+ // Phantom-brand cast: '~provider'/'~toolKind' are type-only and never assigned at runtime.
76
86
  return {
77
87
  name: 'web_search',
78
88
  description: '',
79
89
  metadata: config,
80
- }
90
+ } as unknown as AnthropicWebSearchTool
81
91
  }