@tanstack/ai-anthropic 0.16.5 → 0.16.7
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/esm/adapters/text.js +4 -3
- package/dist/esm/adapters/text.js.map +1 -1
- package/dist/esm/model-meta.d.ts +45 -1
- package/dist/esm/model-meta.js +47 -1
- package/dist/esm/model-meta.js.map +1 -1
- package/dist/esm/tools/anthropic-provider-tool.d.ts +24 -0
- package/dist/esm/tools/anthropic-provider-tool.js +50 -0
- package/dist/esm/tools/anthropic-provider-tool.js.map +1 -0
- package/dist/esm/tools/bash-tool.js +4 -4
- package/dist/esm/tools/bash-tool.js.map +1 -1
- package/dist/esm/tools/code-execution-tool.js +10 -9
- package/dist/esm/tools/code-execution-tool.js.map +1 -1
- package/dist/esm/tools/computer-use-tool.js +4 -4
- package/dist/esm/tools/computer-use-tool.js.map +1 -1
- package/dist/esm/tools/memory-tool.js +4 -4
- package/dist/esm/tools/memory-tool.js.map +1 -1
- package/dist/esm/tools/text-editor-tool.js +4 -4
- package/dist/esm/tools/text-editor-tool.js.map +1 -1
- package/dist/esm/tools/tool-converter.js +7 -4
- package/dist/esm/tools/tool-converter.js.map +1 -1
- package/dist/esm/tools/web-fetch-tool.js +4 -4
- package/dist/esm/tools/web-fetch-tool.js.map +1 -1
- package/dist/esm/tools/web-search-tool.js +9 -9
- package/dist/esm/tools/web-search-tool.js.map +1 -1
- package/package.json +4 -4
- package/src/adapters/text.ts +8 -5
- package/src/model-meta.ts +82 -0
- package/src/tools/anthropic-provider-tool.ts +68 -0
- package/src/tools/bash-tool.ts +13 -7
- package/src/tools/code-execution-tool.ts +22 -8
- package/src/tools/computer-use-tool.ts +15 -7
- package/src/tools/memory-tool.ts +16 -7
- package/src/tools/text-editor-tool.ts +15 -7
- package/src/tools/tool-converter.ts +7 -6
- package/src/tools/web-fetch-tool.ts +16 -7
- package/src/tools/web-search-tool.ts +27 -31
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/ai-anthropic",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.7",
|
|
4
4
|
"description": "Anthropic Claude adapter for TanStack AI chat, tool calling, thinking, and structured outputs.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -53,12 +53,12 @@
|
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"zod": "^4.0.0",
|
|
56
|
-
"@tanstack/ai": "^0.
|
|
56
|
+
"@tanstack/ai": "^0.46.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@vitest/coverage-v8": "4.
|
|
59
|
+
"@vitest/coverage-v8": "4.1.10",
|
|
60
60
|
"zod": "^4.2.0",
|
|
61
|
-
"@tanstack/ai": "0.
|
|
61
|
+
"@tanstack/ai": "0.46.0"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"build": "vite build",
|
package/src/adapters/text.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { EventType, normalizeSystemPrompts } from '@tanstack/ai'
|
|
|
2
2
|
import { toRunErrorRawEvent } from '@tanstack/ai/adapter-internals'
|
|
3
3
|
import { BaseTextAdapter } from '@tanstack/ai/adapters'
|
|
4
4
|
import { convertToolsToProviderFormat } from '../tools/tool-converter'
|
|
5
|
+
import { getAnthropicProviderToolKind } from '../tools/anthropic-provider-tool'
|
|
5
6
|
import {
|
|
6
7
|
readCodeExecutionConfig,
|
|
7
8
|
readCodeExecutionSkills,
|
|
@@ -171,7 +172,9 @@ export function computeAnthropicBetas(
|
|
|
171
172
|
|
|
172
173
|
// Code-execution beta is version-aware: select from the FIRST code_execution
|
|
173
174
|
// tool's config type.
|
|
174
|
-
const codeExecTool = tools?.find(
|
|
175
|
+
const codeExecTool = tools?.find(
|
|
176
|
+
(tool) => getAnthropicProviderToolKind(tool) === 'code_execution',
|
|
177
|
+
)
|
|
175
178
|
if (codeExecTool) {
|
|
176
179
|
const cfgType = readCodeExecutionConfig(codeExecTool)?.type
|
|
177
180
|
// Each code_execution tool version pairs with a specific beta. Known
|
|
@@ -188,9 +191,9 @@ export function computeAnthropicBetas(
|
|
|
188
191
|
// container-lift, which lifts skills from any code_execution tool that
|
|
189
192
|
// carries them (not just the first).
|
|
190
193
|
const hasSkills = tools?.some(
|
|
191
|
-
(
|
|
192
|
-
|
|
193
|
-
(readCodeExecutionSkills(
|
|
194
|
+
(tool) =>
|
|
195
|
+
getAnthropicProviderToolKind(tool) === 'code_execution' &&
|
|
196
|
+
(readCodeExecutionSkills(tool)?.length ?? 0) > 0,
|
|
194
197
|
)
|
|
195
198
|
if (hasSkills) betas.add('skills-2025-10-02')
|
|
196
199
|
|
|
@@ -575,7 +578,7 @@ export class AnthropicTextAdapter<
|
|
|
575
578
|
// canonical path for skills; `modelOptions.container.skills` is deprecated.
|
|
576
579
|
const toolSkills = options.tools
|
|
577
580
|
?.map((tool) =>
|
|
578
|
-
tool
|
|
581
|
+
getAnthropicProviderToolKind(tool) === 'code_execution'
|
|
579
582
|
? readCodeExecutionSkills(tool)
|
|
580
583
|
: undefined,
|
|
581
584
|
)
|
package/src/model-meta.ts
CHANGED
|
@@ -502,7 +502,67 @@ const CLAUDE_SONNET_5 = {
|
|
|
502
502
|
* via the `speed` parameter, not a model id) were removed after Anthropic
|
|
503
503
|
* turned them off.
|
|
504
504
|
*/
|
|
505
|
+
const CLAUDE_OPUS_5 = {
|
|
506
|
+
name: 'claude-opus-5',
|
|
507
|
+
id: 'claude-opus-5',
|
|
508
|
+
context_window: 1_000_000,
|
|
509
|
+
max_output_tokens: 128_000,
|
|
510
|
+
supports: {
|
|
511
|
+
input: ['text', 'image', 'document'],
|
|
512
|
+
tools: [],
|
|
513
|
+
},
|
|
514
|
+
pricing: {
|
|
515
|
+
input: {
|
|
516
|
+
normal: 5,
|
|
517
|
+
cached: 0.5,
|
|
518
|
+
},
|
|
519
|
+
output: {
|
|
520
|
+
normal: 25,
|
|
521
|
+
},
|
|
522
|
+
},
|
|
523
|
+
} as const satisfies ModelMeta<
|
|
524
|
+
AnthropicContainerOptions &
|
|
525
|
+
AnthropicContextManagementOptions &
|
|
526
|
+
AnthropicMCPOptions &
|
|
527
|
+
AnthropicServiceTierOptions &
|
|
528
|
+
AnthropicStopSequencesOptions &
|
|
529
|
+
AnthropicThinkingOptions &
|
|
530
|
+
AnthropicToolChoiceOptions &
|
|
531
|
+
AnthropicSamplingOptions
|
|
532
|
+
>
|
|
533
|
+
|
|
534
|
+
const CLAUDE_OPUS_5_FAST = {
|
|
535
|
+
name: 'claude-opus-5-fast',
|
|
536
|
+
id: 'claude-opus-5-fast',
|
|
537
|
+
context_window: 1_000_000,
|
|
538
|
+
max_output_tokens: 128_000,
|
|
539
|
+
supports: {
|
|
540
|
+
input: ['text', 'image', 'document'],
|
|
541
|
+
tools: [],
|
|
542
|
+
},
|
|
543
|
+
pricing: {
|
|
544
|
+
input: {
|
|
545
|
+
normal: 10,
|
|
546
|
+
cached: 1,
|
|
547
|
+
},
|
|
548
|
+
output: {
|
|
549
|
+
normal: 50,
|
|
550
|
+
},
|
|
551
|
+
},
|
|
552
|
+
} as const satisfies ModelMeta<
|
|
553
|
+
AnthropicContainerOptions &
|
|
554
|
+
AnthropicContextManagementOptions &
|
|
555
|
+
AnthropicMCPOptions &
|
|
556
|
+
AnthropicServiceTierOptions &
|
|
557
|
+
AnthropicStopSequencesOptions &
|
|
558
|
+
AnthropicThinkingOptions &
|
|
559
|
+
AnthropicToolChoiceOptions &
|
|
560
|
+
AnthropicSamplingOptions
|
|
561
|
+
>
|
|
562
|
+
|
|
505
563
|
export const ANTHROPIC_MODELS = [
|
|
564
|
+
CLAUDE_OPUS_5.id,
|
|
565
|
+
CLAUDE_OPUS_5_FAST.id,
|
|
506
566
|
CLAUDE_OPUS_4_6.id,
|
|
507
567
|
CLAUDE_OPUS_4_5.id,
|
|
508
568
|
CLAUDE_SONNET_4_6.id,
|
|
@@ -552,6 +612,8 @@ const ANTHROPIC_MODEL_MAX_OUTPUT_TOKENS: Record<string, number> = {
|
|
|
552
612
|
[CLAUDE_OPUS_4_8.id]: CLAUDE_OPUS_4_8.max_output_tokens,
|
|
553
613
|
[CLAUDE_FABLE_5.id]: CLAUDE_FABLE_5.max_output_tokens,
|
|
554
614
|
[CLAUDE_SONNET_5.id]: CLAUDE_SONNET_5.max_output_tokens,
|
|
615
|
+
[CLAUDE_OPUS_5.id]: CLAUDE_OPUS_5.max_output_tokens,
|
|
616
|
+
[CLAUDE_OPUS_5_FAST.id]: CLAUDE_OPUS_5_FAST.max_output_tokens,
|
|
555
617
|
}
|
|
556
618
|
|
|
557
619
|
/**
|
|
@@ -728,6 +790,22 @@ export type AnthropicChatModelProviderOptionsByName = {
|
|
|
728
790
|
AnthropicToolChoiceOptions &
|
|
729
791
|
AnthropicMaxTokensOptions &
|
|
730
792
|
AnthropicOutputConfigOptions
|
|
793
|
+
[CLAUDE_OPUS_5.id]: AnthropicContainerOptions &
|
|
794
|
+
AnthropicContextManagementOptions &
|
|
795
|
+
AnthropicMCPOptions &
|
|
796
|
+
AnthropicServiceTierOptions &
|
|
797
|
+
AnthropicStopSequencesOptions &
|
|
798
|
+
AnthropicThinkingOptions &
|
|
799
|
+
AnthropicToolChoiceOptions &
|
|
800
|
+
AnthropicSamplingOptions
|
|
801
|
+
[CLAUDE_OPUS_5_FAST.id]: AnthropicContainerOptions &
|
|
802
|
+
AnthropicContextManagementOptions &
|
|
803
|
+
AnthropicMCPOptions &
|
|
804
|
+
AnthropicServiceTierOptions &
|
|
805
|
+
AnthropicStopSequencesOptions &
|
|
806
|
+
AnthropicThinkingOptions &
|
|
807
|
+
AnthropicToolChoiceOptions &
|
|
808
|
+
AnthropicSamplingOptions
|
|
731
809
|
}
|
|
732
810
|
|
|
733
811
|
export type AnthropicChatModelToolCapabilitiesByName = {
|
|
@@ -741,6 +819,8 @@ export type AnthropicChatModelToolCapabilitiesByName = {
|
|
|
741
819
|
[CLAUDE_OPUS_4_8.id]: typeof CLAUDE_OPUS_4_8.supports.tools
|
|
742
820
|
[CLAUDE_FABLE_5.id]: typeof CLAUDE_FABLE_5.supports.tools
|
|
743
821
|
[CLAUDE_SONNET_5.id]: typeof CLAUDE_SONNET_5.supports.tools
|
|
822
|
+
[CLAUDE_OPUS_5.id]: typeof CLAUDE_OPUS_5.supports.tools
|
|
823
|
+
[CLAUDE_OPUS_5_FAST.id]: typeof CLAUDE_OPUS_5_FAST.supports.tools
|
|
744
824
|
}
|
|
745
825
|
|
|
746
826
|
/**
|
|
@@ -765,4 +845,6 @@ export type AnthropicModelInputModalitiesByName = {
|
|
|
765
845
|
[CLAUDE_OPUS_4_8.id]: typeof CLAUDE_OPUS_4_8.supports.input
|
|
766
846
|
[CLAUDE_FABLE_5.id]: typeof CLAUDE_FABLE_5.supports.input
|
|
767
847
|
[CLAUDE_SONNET_5.id]: typeof CLAUDE_SONNET_5.supports.input
|
|
848
|
+
[CLAUDE_OPUS_5.id]: typeof CLAUDE_OPUS_5.supports.input
|
|
849
|
+
[CLAUDE_OPUS_5_FAST.id]: typeof CLAUDE_OPUS_5_FAST.supports.input
|
|
768
850
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { brandProviderTool } from '@tanstack/ai'
|
|
2
|
+
import type { ProviderTool, Tool } from '@tanstack/ai'
|
|
3
|
+
|
|
4
|
+
const ANTHROPIC_PROVIDER_TOOL_KINDS = {
|
|
5
|
+
bash: 'anthropic.bash',
|
|
6
|
+
code_execution: 'anthropic.code_execution',
|
|
7
|
+
computer_use: 'anthropic.computer_use',
|
|
8
|
+
memory: 'anthropic.memory',
|
|
9
|
+
text_editor: 'anthropic.text_editor',
|
|
10
|
+
web_fetch: 'anthropic.web_fetch',
|
|
11
|
+
web_search: 'anthropic.web_search',
|
|
12
|
+
} as const
|
|
13
|
+
|
|
14
|
+
type AnthropicProviderToolKind = keyof typeof ANTHROPIC_PROVIDER_TOOL_KINDS
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Adds a stable runtime discriminator to an Anthropic-native tool.
|
|
18
|
+
*
|
|
19
|
+
* The core ProviderTool brand is intentionally type-only. Anthropic also needs
|
|
20
|
+
* a runtime discriminator because custom functions may use the same public
|
|
21
|
+
* names as native tools. Adapter metadata is the repository-wide extension
|
|
22
|
+
* point for this plain-data marker; converters remove it from the wire shape.
|
|
23
|
+
*/
|
|
24
|
+
export function brandAnthropicProviderTool<
|
|
25
|
+
T extends ProviderTool<'anthropic', AnthropicProviderToolKind>,
|
|
26
|
+
>(tool: Omit<T, '~provider' | '~toolKind'>, toolKind: T['~toolKind']): T {
|
|
27
|
+
return brandProviderTool<T>({
|
|
28
|
+
...tool,
|
|
29
|
+
metadata: {
|
|
30
|
+
...tool.metadata,
|
|
31
|
+
__kind: ANTHROPIC_PROVIDER_TOOL_KINDS[toolKind],
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function getAnthropicProviderToolKind(
|
|
37
|
+
tool: Tool,
|
|
38
|
+
): AnthropicProviderToolKind | undefined {
|
|
39
|
+
const toolKind = tool.metadata?.['__kind']
|
|
40
|
+
switch (toolKind) {
|
|
41
|
+
case 'anthropic.bash':
|
|
42
|
+
return 'bash'
|
|
43
|
+
case 'anthropic.code_execution':
|
|
44
|
+
return 'code_execution'
|
|
45
|
+
case 'anthropic.computer_use':
|
|
46
|
+
return 'computer_use'
|
|
47
|
+
case 'anthropic.memory':
|
|
48
|
+
return 'memory'
|
|
49
|
+
case 'anthropic.text_editor':
|
|
50
|
+
return 'text_editor'
|
|
51
|
+
case 'anthropic.web_fetch':
|
|
52
|
+
return 'web_fetch'
|
|
53
|
+
case 'anthropic.web_search':
|
|
54
|
+
return 'web_search'
|
|
55
|
+
default:
|
|
56
|
+
return undefined
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Returns adapter metadata without the internal runtime discriminator. */
|
|
61
|
+
export function getAnthropicProviderToolMetadata(tool: Tool): Tool['metadata'] {
|
|
62
|
+
if (!tool.metadata) {
|
|
63
|
+
return undefined
|
|
64
|
+
}
|
|
65
|
+
const { __kind: _kind, ...metadata } = tool.metadata
|
|
66
|
+
void _kind
|
|
67
|
+
return metadata
|
|
68
|
+
}
|
package/src/tools/bash-tool.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
brandAnthropicProviderTool,
|
|
3
|
+
getAnthropicProviderToolMetadata,
|
|
4
|
+
} from './anthropic-provider-tool'
|
|
2
5
|
import type {
|
|
3
6
|
BetaToolBash20241022,
|
|
4
7
|
BetaToolBash20250124,
|
|
@@ -13,14 +16,17 @@ export type BashTool = BashToolConfig
|
|
|
13
16
|
export type AnthropicBashTool = ProviderTool<'anthropic', 'bash'>
|
|
14
17
|
|
|
15
18
|
export function convertBashToolToAdapterFormat(tool: Tool): BashToolConfig {
|
|
16
|
-
const metadata = tool
|
|
19
|
+
const metadata = getAnthropicProviderToolMetadata(tool) as BashToolConfig
|
|
17
20
|
return metadata
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
export function bashTool(config: BashToolConfig): AnthropicBashTool {
|
|
21
|
-
return
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
return brandAnthropicProviderTool<AnthropicBashTool>(
|
|
25
|
+
{
|
|
26
|
+
name: 'bash',
|
|
27
|
+
description: '',
|
|
28
|
+
metadata: config,
|
|
29
|
+
},
|
|
30
|
+
'bash',
|
|
31
|
+
)
|
|
26
32
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
brandAnthropicProviderTool,
|
|
3
|
+
getAnthropicProviderToolMetadata,
|
|
4
|
+
} from './anthropic-provider-tool'
|
|
2
5
|
import type {
|
|
3
6
|
BetaCodeExecutionTool20250522,
|
|
4
7
|
BetaCodeExecutionTool20250825,
|
|
@@ -56,7 +59,11 @@ export function convertCodeExecutionToolToAdapterFormat(
|
|
|
56
59
|
export function readCodeExecutionConfig(
|
|
57
60
|
tool: Tool,
|
|
58
61
|
): CodeExecutionToolConfig | undefined {
|
|
59
|
-
return (
|
|
62
|
+
return (
|
|
63
|
+
getAnthropicProviderToolMetadata(tool) as
|
|
64
|
+
| CodeExecutionToolMetadata
|
|
65
|
+
| undefined
|
|
66
|
+
)?.config
|
|
60
67
|
}
|
|
61
68
|
|
|
62
69
|
/**
|
|
@@ -66,7 +73,11 @@ export function readCodeExecutionConfig(
|
|
|
66
73
|
export function readCodeExecutionSkills(
|
|
67
74
|
tool: Tool,
|
|
68
75
|
): Array<AnthropicContainerSkill> | undefined {
|
|
69
|
-
return (
|
|
76
|
+
return (
|
|
77
|
+
getAnthropicProviderToolMetadata(tool) as
|
|
78
|
+
| CodeExecutionToolMetadata
|
|
79
|
+
| undefined
|
|
80
|
+
)?.skills
|
|
70
81
|
}
|
|
71
82
|
|
|
72
83
|
export function codeExecutionTool(
|
|
@@ -88,9 +99,12 @@ export function codeExecutionTool(
|
|
|
88
99
|
config,
|
|
89
100
|
...(skills && { skills }),
|
|
90
101
|
}
|
|
91
|
-
return
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
102
|
+
return brandAnthropicProviderTool<AnthropicCodeExecutionTool>(
|
|
103
|
+
{
|
|
104
|
+
name: 'code_execution',
|
|
105
|
+
description: '',
|
|
106
|
+
metadata,
|
|
107
|
+
},
|
|
108
|
+
'code_execution',
|
|
109
|
+
)
|
|
96
110
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
brandAnthropicProviderTool,
|
|
3
|
+
getAnthropicProviderToolMetadata,
|
|
4
|
+
} from './anthropic-provider-tool'
|
|
2
5
|
import type {
|
|
3
6
|
BetaToolComputerUse20241022,
|
|
4
7
|
BetaToolComputerUse20250124,
|
|
@@ -17,16 +20,21 @@ export type AnthropicComputerUseTool = ProviderTool<'anthropic', 'computer_use'>
|
|
|
17
20
|
export function convertComputerUseToolToAdapterFormat(
|
|
18
21
|
tool: Tool,
|
|
19
22
|
): ComputerUseToolConfig {
|
|
20
|
-
const metadata =
|
|
23
|
+
const metadata = getAnthropicProviderToolMetadata(
|
|
24
|
+
tool,
|
|
25
|
+
) as ComputerUseToolConfig
|
|
21
26
|
return metadata
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
export function computerUseTool(
|
|
25
30
|
config: ComputerUseToolConfig,
|
|
26
31
|
): AnthropicComputerUseTool {
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
return brandAnthropicProviderTool<AnthropicComputerUseTool>(
|
|
33
|
+
{
|
|
34
|
+
name: 'computer',
|
|
35
|
+
description: '',
|
|
36
|
+
metadata: config,
|
|
37
|
+
},
|
|
38
|
+
'computer_use',
|
|
39
|
+
)
|
|
32
40
|
}
|
package/src/tools/memory-tool.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
brandAnthropicProviderTool,
|
|
3
|
+
getAnthropicProviderToolMetadata,
|
|
4
|
+
} from './anthropic-provider-tool'
|
|
2
5
|
import type { BetaMemoryTool20250818 } from '@anthropic-ai/sdk/resources/beta'
|
|
3
6
|
import type { ProviderTool, Tool } from '@tanstack/ai'
|
|
4
7
|
|
|
@@ -10,7 +13,10 @@ export type MemoryTool = MemoryToolConfig
|
|
|
10
13
|
export type AnthropicMemoryTool = ProviderTool<'anthropic', 'memory'>
|
|
11
14
|
|
|
12
15
|
export function convertMemoryToolToAdapterFormat(tool: Tool): MemoryToolConfig {
|
|
13
|
-
const metadata = tool
|
|
16
|
+
const metadata = getAnthropicProviderToolMetadata(tool) as Omit<
|
|
17
|
+
MemoryToolConfig,
|
|
18
|
+
'type'
|
|
19
|
+
>
|
|
14
20
|
return {
|
|
15
21
|
type: 'memory_20250818',
|
|
16
22
|
...metadata,
|
|
@@ -18,9 +24,12 @@ export function convertMemoryToolToAdapterFormat(tool: Tool): MemoryToolConfig {
|
|
|
18
24
|
}
|
|
19
25
|
|
|
20
26
|
export function memoryTool(config?: MemoryToolConfig): AnthropicMemoryTool {
|
|
21
|
-
return
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
return brandAnthropicProviderTool<AnthropicMemoryTool>(
|
|
28
|
+
{
|
|
29
|
+
name: 'memory',
|
|
30
|
+
description: '',
|
|
31
|
+
metadata: config,
|
|
32
|
+
},
|
|
33
|
+
'memory',
|
|
34
|
+
)
|
|
26
35
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
brandAnthropicProviderTool,
|
|
3
|
+
getAnthropicProviderToolMetadata,
|
|
4
|
+
} from './anthropic-provider-tool'
|
|
2
5
|
import type {
|
|
3
6
|
ToolTextEditor20250124,
|
|
4
7
|
ToolTextEditor20250429,
|
|
@@ -19,7 +22,9 @@ export type AnthropicTextEditorTool = ProviderTool<'anthropic', 'text_editor'>
|
|
|
19
22
|
export function convertTextEditorToolToAdapterFormat(
|
|
20
23
|
tool: Tool,
|
|
21
24
|
): TextEditorToolConfig {
|
|
22
|
-
const metadata =
|
|
25
|
+
const metadata = getAnthropicProviderToolMetadata(
|
|
26
|
+
tool,
|
|
27
|
+
) as TextEditorToolConfig
|
|
23
28
|
return {
|
|
24
29
|
...metadata,
|
|
25
30
|
}
|
|
@@ -28,9 +33,12 @@ export function convertTextEditorToolToAdapterFormat(
|
|
|
28
33
|
export function textEditorTool<T extends TextEditorToolConfig>(
|
|
29
34
|
config: T,
|
|
30
35
|
): AnthropicTextEditorTool {
|
|
31
|
-
return
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
return brandAnthropicProviderTool<AnthropicTextEditorTool>(
|
|
37
|
+
{
|
|
38
|
+
name: 'str_replace_editor',
|
|
39
|
+
description: '',
|
|
40
|
+
metadata: config,
|
|
41
|
+
},
|
|
42
|
+
'text_editor',
|
|
43
|
+
)
|
|
36
44
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { assertUniqueToolNames } from '@tanstack/ai/adapter-internals'
|
|
2
|
+
import { getAnthropicProviderToolKind } from './anthropic-provider-tool'
|
|
1
3
|
import { convertBashToolToAdapterFormat } from './bash-tool'
|
|
2
4
|
import { convertCodeExecutionToolToAdapterFormat } from './code-execution-tool'
|
|
3
5
|
import { convertComputerUseToolToAdapterFormat } from './computer-use-tool'
|
|
@@ -36,25 +38,24 @@ import type { Tool } from '@tanstack/ai'
|
|
|
36
38
|
export function convertToolsToProviderFormat<TTool extends Tool>(
|
|
37
39
|
tools: Array<TTool>,
|
|
38
40
|
): Array<AnthropicTool> {
|
|
41
|
+
assertUniqueToolNames(tools)
|
|
39
42
|
return tools.map((tool) => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
switch (name) {
|
|
43
|
+
switch (getAnthropicProviderToolKind(tool)) {
|
|
43
44
|
case 'bash':
|
|
44
45
|
return convertBashToolToAdapterFormat(tool)
|
|
45
46
|
case 'code_execution':
|
|
46
47
|
return convertCodeExecutionToolToAdapterFormat(tool)
|
|
47
|
-
case '
|
|
48
|
+
case 'computer_use':
|
|
48
49
|
return convertComputerUseToolToAdapterFormat(tool)
|
|
49
50
|
case 'memory':
|
|
50
51
|
return convertMemoryToolToAdapterFormat(tool)
|
|
51
|
-
case '
|
|
52
|
+
case 'text_editor':
|
|
52
53
|
return convertTextEditorToolToAdapterFormat(tool)
|
|
53
54
|
case 'web_fetch':
|
|
54
55
|
return convertWebFetchToolToAdapterFormat(tool)
|
|
55
56
|
case 'web_search':
|
|
56
57
|
return convertWebSearchToolToAdapterFormat(tool)
|
|
57
|
-
|
|
58
|
+
case undefined:
|
|
58
59
|
return convertCustomToolToAdapterFormat(tool)
|
|
59
60
|
}
|
|
60
61
|
})
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
brandAnthropicProviderTool,
|
|
3
|
+
getAnthropicProviderToolMetadata,
|
|
4
|
+
} from './anthropic-provider-tool'
|
|
2
5
|
import type { BetaWebFetchTool20250910 } from '@anthropic-ai/sdk/resources/beta'
|
|
3
6
|
import type { ProviderTool, Tool } from '@tanstack/ai'
|
|
4
7
|
|
|
@@ -12,7 +15,10 @@ export type AnthropicWebFetchTool = ProviderTool<'anthropic', 'web_fetch'>
|
|
|
12
15
|
export function convertWebFetchToolToAdapterFormat(
|
|
13
16
|
tool: Tool,
|
|
14
17
|
): WebFetchToolConfig {
|
|
15
|
-
const metadata = tool
|
|
18
|
+
const metadata = getAnthropicProviderToolMetadata(tool) as Omit<
|
|
19
|
+
WebFetchToolConfig,
|
|
20
|
+
'type' | 'name'
|
|
21
|
+
>
|
|
16
22
|
return {
|
|
17
23
|
name: 'web_fetch',
|
|
18
24
|
type: 'web_fetch_20250910',
|
|
@@ -23,9 +29,12 @@ export function convertWebFetchToolToAdapterFormat(
|
|
|
23
29
|
export function webFetchTool(
|
|
24
30
|
config?: Omit<WebFetchToolConfig, 'type' | 'name'>,
|
|
25
31
|
): AnthropicWebFetchTool {
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
return brandAnthropicProviderTool<AnthropicWebFetchTool>(
|
|
33
|
+
{
|
|
34
|
+
name: 'web_fetch',
|
|
35
|
+
description: '',
|
|
36
|
+
metadata: config,
|
|
37
|
+
},
|
|
38
|
+
'web_fetch',
|
|
39
|
+
)
|
|
31
40
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
brandAnthropicProviderTool,
|
|
3
|
+
getAnthropicProviderToolMetadata,
|
|
4
|
+
} from './anthropic-provider-tool'
|
|
2
5
|
import type { WebSearchTool20250305 } from '@anthropic-ai/sdk/resources/messages'
|
|
3
|
-
import type { CacheControl } from '../text/text-provider-options'
|
|
4
6
|
import type { ProviderTool, Tool } from '@tanstack/ai'
|
|
5
7
|
|
|
6
8
|
export type WebSearchToolConfig = WebSearchTool20250305
|
|
@@ -54,36 +56,27 @@ const validateUserLocation = (tool: WebSearchToolConfig) => {
|
|
|
54
56
|
export function convertWebSearchToolToAdapterFormat(
|
|
55
57
|
tool: Tool,
|
|
56
58
|
): WebSearchToolConfig {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
type: 'approximate'
|
|
63
|
-
city?: string | null
|
|
64
|
-
country?: string | null
|
|
65
|
-
region?: string | null
|
|
66
|
-
timezone?: string | null
|
|
67
|
-
} | null
|
|
68
|
-
cacheControl?: CacheControl | null
|
|
69
|
-
}
|
|
70
|
-
// Vendor `WebSearchTool20250305` declares these fields as `T | null`
|
|
71
|
-
// (no `| undefined`) under exactOptionalPropertyTypes, so spread them
|
|
72
|
-
// conditionally rather than passing explicit `undefined`.
|
|
59
|
+
// The factory stores the SDK config (`allowed_domains`, `max_uses`, …)
|
|
60
|
+
// on `metadata`. Vendor `WebSearchTool20250305` declares those fields as
|
|
61
|
+
// `T | null` (no `| undefined`) under exactOptionalPropertyTypes, so
|
|
62
|
+
// spread them only when present rather than passing explicit `undefined`.
|
|
63
|
+
const metadata = getAnthropicProviderToolMetadata(tool)
|
|
73
64
|
return {
|
|
74
65
|
name: 'web_search',
|
|
75
66
|
type: 'web_search_20250305',
|
|
76
|
-
...(metadata
|
|
77
|
-
allowed_domains: metadata.
|
|
67
|
+
...(metadata?.allowed_domains !== undefined && {
|
|
68
|
+
allowed_domains: metadata.allowed_domains,
|
|
69
|
+
}),
|
|
70
|
+
...(metadata?.blocked_domains !== undefined && {
|
|
71
|
+
blocked_domains: metadata.blocked_domains,
|
|
78
72
|
}),
|
|
79
|
-
...(metadata
|
|
80
|
-
|
|
73
|
+
...(metadata?.max_uses !== undefined && { max_uses: metadata.max_uses }),
|
|
74
|
+
...(metadata?.user_location !== undefined && {
|
|
75
|
+
user_location: metadata.user_location,
|
|
81
76
|
}),
|
|
82
|
-
...(metadata
|
|
83
|
-
|
|
84
|
-
user_location: metadata.userLocation,
|
|
77
|
+
...(metadata?.cache_control !== undefined && {
|
|
78
|
+
cache_control: metadata.cache_control,
|
|
85
79
|
}),
|
|
86
|
-
cache_control: metadata.cacheControl || null,
|
|
87
80
|
}
|
|
88
81
|
}
|
|
89
82
|
|
|
@@ -92,9 +85,12 @@ export function webSearchTool(
|
|
|
92
85
|
): AnthropicWebSearchTool {
|
|
93
86
|
validateDomains(config)
|
|
94
87
|
validateUserLocation(config)
|
|
95
|
-
return
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
88
|
+
return brandAnthropicProviderTool<AnthropicWebSearchTool>(
|
|
89
|
+
{
|
|
90
|
+
name: 'web_search',
|
|
91
|
+
description: '',
|
|
92
|
+
metadata: config,
|
|
93
|
+
},
|
|
94
|
+
'web_search',
|
|
95
|
+
)
|
|
100
96
|
}
|