@tanstack/ai-anthropic 0.7.4 → 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 (49) hide show
  1. package/dist/esm/adapters/summarize.js +5 -4
  2. package/dist/esm/adapters/summarize.js.map +1 -1
  3. package/dist/esm/adapters/text.d.ts +5 -4
  4. package/dist/esm/adapters/text.js +121 -35
  5. package/dist/esm/adapters/text.js.map +1 -1
  6. package/dist/esm/index.d.ts +1 -1
  7. package/dist/esm/model-meta.d.ts +28 -0
  8. package/dist/esm/model-meta.js.map +1 -1
  9. package/dist/esm/tools/bash-tool.d.ts +7 -4
  10. package/dist/esm/tools/bash-tool.js +8 -0
  11. package/dist/esm/tools/bash-tool.js.map +1 -1
  12. package/dist/esm/tools/code-execution-tool.d.ts +7 -4
  13. package/dist/esm/tools/code-execution-tool.js +8 -0
  14. package/dist/esm/tools/code-execution-tool.js.map +1 -1
  15. package/dist/esm/tools/computer-use-tool.d.ts +7 -4
  16. package/dist/esm/tools/computer-use-tool.js +8 -0
  17. package/dist/esm/tools/computer-use-tool.js.map +1 -1
  18. package/dist/esm/tools/custom-tool.d.ts +4 -2
  19. package/dist/esm/tools/custom-tool.js +12 -1
  20. package/dist/esm/tools/custom-tool.js.map +1 -1
  21. package/dist/esm/tools/index.d.ts +8 -1
  22. package/dist/esm/tools/index.js +19 -0
  23. package/dist/esm/tools/index.js.map +1 -0
  24. package/dist/esm/tools/memory-tool.d.ts +7 -4
  25. package/dist/esm/tools/memory-tool.js +9 -1
  26. package/dist/esm/tools/memory-tool.js.map +1 -1
  27. package/dist/esm/tools/text-editor-tool.d.ts +7 -4
  28. package/dist/esm/tools/text-editor-tool.js +9 -1
  29. package/dist/esm/tools/text-editor-tool.js.map +1 -1
  30. package/dist/esm/tools/web-fetch-tool.d.ts +7 -4
  31. package/dist/esm/tools/web-fetch-tool.js +9 -1
  32. package/dist/esm/tools/web-fetch-tool.js.map +1 -1
  33. package/dist/esm/tools/web-search-tool.d.ts +7 -4
  34. package/dist/esm/tools/web-search-tool.js +41 -1
  35. package/dist/esm/tools/web-search-tool.js.map +1 -1
  36. package/package.json +7 -3
  37. package/src/adapters/summarize.ts +8 -4
  38. package/src/adapters/text.ts +155 -40
  39. package/src/index.ts +2 -1
  40. package/src/model-meta.ts +126 -0
  41. package/src/tools/bash-tool.ts +13 -6
  42. package/src/tools/code-execution-tool.ts +17 -6
  43. package/src/tools/computer-use-tool.ts +14 -6
  44. package/src/tools/custom-tool.ts +5 -3
  45. package/src/tools/index.ts +49 -12
  46. package/src/tools/memory-tool.ts +12 -6
  47. package/src/tools/text-editor-tool.ts +14 -6
  48. package/src/tools/web-fetch-tool.ts +15 -7
  49. package/src/tools/web-search-tool.ts +17 -7
@@ -6,5 +6,12 @@ import { MemoryTool } from './memory-tool.js';
6
6
  import { TextEditorTool } from './text-editor-tool.js';
7
7
  import { WebFetchTool } from './web-fetch-tool.js';
8
8
  import { WebSearchTool } from './web-search-tool.js';
9
+ export { bashTool, type AnthropicBashTool, type BashToolConfig, type BashTool, } from './bash-tool.js';
10
+ export { codeExecutionTool, type AnthropicCodeExecutionTool, type CodeExecutionToolConfig, type CodeExecutionTool, } from './code-execution-tool.js';
11
+ export { computerUseTool, type AnthropicComputerUseTool, type ComputerUseToolConfig, type ComputerUseTool, } from './computer-use-tool.js';
12
+ export { customTool, type CustomToolConfig, type CustomTool, } from './custom-tool.js';
13
+ export { memoryTool, type AnthropicMemoryTool, type MemoryToolConfig, type MemoryTool, } from './memory-tool.js';
14
+ export { textEditorTool, type AnthropicTextEditorTool, type TextEditorToolConfig, type TextEditorTool, } from './text-editor-tool.js';
15
+ export { webFetchTool, type AnthropicWebFetchTool, type WebFetchToolConfig, type WebFetchTool, } from './web-fetch-tool.js';
16
+ export { webSearchTool, type AnthropicWebSearchTool, type WebSearchToolConfig, type WebSearchTool, } from './web-search-tool.js';
9
17
  export type AnthropicTool = BashTool | CodeExecutionTool | ComputerUseTool | CustomTool | MemoryTool | TextEditorTool | WebFetchTool | WebSearchTool;
10
- export type { CustomTool, };
@@ -0,0 +1,19 @@
1
+ import { bashTool } from "./bash-tool.js";
2
+ import { codeExecutionTool } from "./code-execution-tool.js";
3
+ import { computerUseTool } from "./computer-use-tool.js";
4
+ import { customTool } from "./custom-tool.js";
5
+ import { memoryTool } from "./memory-tool.js";
6
+ import { textEditorTool } from "./text-editor-tool.js";
7
+ import { webFetchTool } from "./web-fetch-tool.js";
8
+ import { webSearchTool } from "./web-search-tool.js";
9
+ export {
10
+ bashTool,
11
+ codeExecutionTool,
12
+ computerUseTool,
13
+ customTool,
14
+ memoryTool,
15
+ textEditorTool,
16
+ webFetchTool,
17
+ webSearchTool
18
+ };
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
@@ -1,5 +1,8 @@
1
1
  import { BetaMemoryTool20250818 } from '@anthropic-ai/sdk/resources/beta';
2
- import { Tool } from '@tanstack/ai';
3
- export type MemoryTool = BetaMemoryTool20250818;
4
- export declare function convertMemoryToolToAdapterFormat(tool: Tool): MemoryTool;
5
- export declare function memoryTool(config?: MemoryTool): Tool;
2
+ import { ProviderTool, Tool } from '@tanstack/ai';
3
+ export type MemoryToolConfig = BetaMemoryTool20250818;
4
+ /** @deprecated Renamed to `MemoryToolConfig`. Will be removed in a future release. */
5
+ export type MemoryTool = MemoryToolConfig;
6
+ export type AnthropicMemoryTool = ProviderTool<'anthropic', 'memory'>;
7
+ export declare function convertMemoryToolToAdapterFormat(tool: Tool): MemoryToolConfig;
8
+ export declare function memoryTool(config?: MemoryToolConfig): AnthropicMemoryTool;
@@ -5,7 +5,15 @@ function convertMemoryToolToAdapterFormat(tool) {
5
5
  ...metadata
6
6
  };
7
7
  }
8
+ function memoryTool(config) {
9
+ return {
10
+ name: "memory",
11
+ description: "",
12
+ metadata: config
13
+ };
14
+ }
8
15
  export {
9
- convertMemoryToolToAdapterFormat
16
+ convertMemoryToolToAdapterFormat,
17
+ memoryTool
10
18
  };
11
19
  //# sourceMappingURL=memory-tool.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"memory-tool.js","sources":["../../../src/tools/memory-tool.ts"],"sourcesContent":["import type { BetaMemoryTool20250818 } from '@anthropic-ai/sdk/resources/beta'\nimport type { Tool } from '@tanstack/ai'\n\nexport type MemoryTool = BetaMemoryTool20250818\n\nexport function convertMemoryToolToAdapterFormat(tool: Tool): MemoryTool {\n const metadata = tool.metadata as Omit<MemoryTool, 'type'>\n return {\n type: 'memory_20250818',\n ...metadata,\n }\n}\n\nexport function memoryTool(config?: MemoryTool): Tool {\n return {\n name: 'memory',\n description: '',\n metadata: config,\n }\n}\n"],"names":[],"mappings":"AAKO,SAAS,iCAAiC,MAAwB;AACvE,QAAM,WAAW,KAAK;AACtB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,GAAG;AAAA,EAAA;AAEP;"}
1
+ {"version":3,"file":"memory-tool.js","sources":["../../../src/tools/memory-tool.ts"],"sourcesContent":["import type { BetaMemoryTool20250818 } from '@anthropic-ai/sdk/resources/beta'\nimport type { ProviderTool, Tool } from '@tanstack/ai'\n\nexport type MemoryToolConfig = BetaMemoryTool20250818\n\n/** @deprecated Renamed to `MemoryToolConfig`. Will be removed in a future release. */\nexport type MemoryTool = MemoryToolConfig\n\nexport type AnthropicMemoryTool = ProviderTool<'anthropic', 'memory'>\n\nexport function convertMemoryToolToAdapterFormat(tool: Tool): MemoryToolConfig {\n const metadata = tool.metadata as Omit<MemoryToolConfig, 'type'>\n return {\n type: 'memory_20250818',\n ...metadata,\n }\n}\n\nexport function memoryTool(config?: MemoryToolConfig): AnthropicMemoryTool {\n // Phantom-brand cast: '~provider'/'~toolKind' are type-only and never assigned at runtime.\n return {\n name: 'memory',\n description: '',\n metadata: config,\n } as unknown as AnthropicMemoryTool\n}\n"],"names":[],"mappings":"AAUO,SAAS,iCAAiC,MAA8B;AAC7E,QAAM,WAAW,KAAK;AACtB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,GAAG;AAAA,EAAA;AAEP;AAEO,SAAS,WAAW,QAAgD;AAEzE,SAAO;AAAA,IACL,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,EAAA;AAEd;"}
@@ -1,5 +1,8 @@
1
1
  import { ToolTextEditor20250124, ToolTextEditor20250429, ToolTextEditor20250728 } from '@anthropic-ai/sdk/resources/messages';
2
- import { Tool } from '@tanstack/ai';
3
- export type TextEditorTool = ToolTextEditor20250124 | ToolTextEditor20250429 | ToolTextEditor20250728;
4
- export declare function convertTextEditorToolToAdapterFormat(tool: Tool): TextEditorTool;
5
- export declare function textEditorTool<T extends TextEditorTool>(config: T): Tool;
2
+ import { ProviderTool, Tool } from '@tanstack/ai';
3
+ export type TextEditorToolConfig = ToolTextEditor20250124 | ToolTextEditor20250429 | ToolTextEditor20250728;
4
+ /** @deprecated Renamed to `TextEditorToolConfig`. Will be removed in a future release. */
5
+ export type TextEditorTool = TextEditorToolConfig;
6
+ export type AnthropicTextEditorTool = ProviderTool<'anthropic', 'text_editor'>;
7
+ export declare function convertTextEditorToolToAdapterFormat(tool: Tool): TextEditorToolConfig;
8
+ export declare function textEditorTool<T extends TextEditorToolConfig>(config: T): AnthropicTextEditorTool;
@@ -4,7 +4,15 @@ function convertTextEditorToolToAdapterFormat(tool) {
4
4
  ...metadata
5
5
  };
6
6
  }
7
+ function textEditorTool(config) {
8
+ return {
9
+ name: "str_replace_editor",
10
+ description: "",
11
+ metadata: config
12
+ };
13
+ }
7
14
  export {
8
- convertTextEditorToolToAdapterFormat
15
+ convertTextEditorToolToAdapterFormat,
16
+ textEditorTool
9
17
  };
10
18
  //# sourceMappingURL=text-editor-tool.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"text-editor-tool.js","sources":["../../../src/tools/text-editor-tool.ts"],"sourcesContent":["import type {\n ToolTextEditor20250124,\n ToolTextEditor20250429,\n ToolTextEditor20250728,\n} from '@anthropic-ai/sdk/resources/messages'\nimport type { Tool } from '@tanstack/ai'\n\nexport type TextEditorTool =\n | ToolTextEditor20250124\n | ToolTextEditor20250429\n | ToolTextEditor20250728\n\nexport function convertTextEditorToolToAdapterFormat(\n tool: Tool,\n): TextEditorTool {\n const metadata = tool.metadata as TextEditorTool\n return {\n ...metadata,\n }\n}\n\nexport function textEditorTool<T extends TextEditorTool>(config: T): Tool {\n return {\n name: 'str_replace_editor',\n description: '',\n metadata: config,\n }\n}\n"],"names":[],"mappings":"AAYO,SAAS,qCACd,MACgB;AAChB,QAAM,WAAW,KAAK;AACtB,SAAO;AAAA,IACL,GAAG;AAAA,EAAA;AAEP;"}
1
+ {"version":3,"file":"text-editor-tool.js","sources":["../../../src/tools/text-editor-tool.ts"],"sourcesContent":["import type {\n ToolTextEditor20250124,\n ToolTextEditor20250429,\n ToolTextEditor20250728,\n} from '@anthropic-ai/sdk/resources/messages'\nimport type { ProviderTool, Tool } from '@tanstack/ai'\n\nexport type TextEditorToolConfig =\n | ToolTextEditor20250124\n | ToolTextEditor20250429\n | ToolTextEditor20250728\n\n/** @deprecated Renamed to `TextEditorToolConfig`. Will be removed in a future release. */\nexport type TextEditorTool = TextEditorToolConfig\n\nexport type AnthropicTextEditorTool = ProviderTool<'anthropic', 'text_editor'>\n\nexport function convertTextEditorToolToAdapterFormat(\n tool: Tool,\n): TextEditorToolConfig {\n const metadata = tool.metadata as TextEditorToolConfig\n return {\n ...metadata,\n }\n}\n\nexport function textEditorTool<T extends TextEditorToolConfig>(\n config: T,\n): AnthropicTextEditorTool {\n // Phantom-brand cast: '~provider'/'~toolKind' are type-only and never assigned at runtime.\n return {\n name: 'str_replace_editor',\n description: '',\n metadata: config,\n } as unknown as AnthropicTextEditorTool\n}\n"],"names":[],"mappings":"AAiBO,SAAS,qCACd,MACsB;AACtB,QAAM,WAAW,KAAK;AACtB,SAAO;AAAA,IACL,GAAG;AAAA,EAAA;AAEP;AAEO,SAAS,eACd,QACyB;AAEzB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,EAAA;AAEd;"}
@@ -1,5 +1,8 @@
1
1
  import { BetaWebFetchTool20250910 } from '@anthropic-ai/sdk/resources/beta';
2
- import { Tool } from '@tanstack/ai';
3
- export type WebFetchTool = BetaWebFetchTool20250910;
4
- export declare function convertWebFetchToolToAdapterFormat(tool: Tool): WebFetchTool;
5
- export declare function webFetchTool(config?: Omit<WebFetchTool, 'type' | 'name'>): Tool;
2
+ import { ProviderTool, Tool } from '@tanstack/ai';
3
+ export type WebFetchToolConfig = BetaWebFetchTool20250910;
4
+ /** @deprecated Renamed to `WebFetchToolConfig`. Will be removed in a future release. */
5
+ export type WebFetchTool = WebFetchToolConfig;
6
+ export type AnthropicWebFetchTool = ProviderTool<'anthropic', 'web_fetch'>;
7
+ export declare function convertWebFetchToolToAdapterFormat(tool: Tool): WebFetchToolConfig;
8
+ export declare function webFetchTool(config?: Omit<WebFetchToolConfig, 'type' | 'name'>): AnthropicWebFetchTool;
@@ -6,7 +6,15 @@ function convertWebFetchToolToAdapterFormat(tool) {
6
6
  ...metadata
7
7
  };
8
8
  }
9
+ function webFetchTool(config) {
10
+ return {
11
+ name: "web_fetch",
12
+ description: "",
13
+ metadata: config
14
+ };
15
+ }
9
16
  export {
10
- convertWebFetchToolToAdapterFormat
17
+ convertWebFetchToolToAdapterFormat,
18
+ webFetchTool
11
19
  };
12
20
  //# sourceMappingURL=web-fetch-tool.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"web-fetch-tool.js","sources":["../../../src/tools/web-fetch-tool.ts"],"sourcesContent":["import type { BetaWebFetchTool20250910 } from '@anthropic-ai/sdk/resources/beta'\nimport type { Tool } from '@tanstack/ai'\n\nexport type WebFetchTool = BetaWebFetchTool20250910\n\nexport function convertWebFetchToolToAdapterFormat(tool: Tool): WebFetchTool {\n const metadata = tool.metadata as Omit<WebFetchTool, 'type' | 'name'>\n return {\n name: 'web_fetch',\n type: 'web_fetch_20250910',\n ...metadata,\n }\n}\n\nexport function webFetchTool(\n config?: Omit<WebFetchTool, 'type' | 'name'>,\n): Tool {\n return {\n name: 'web_fetch',\n description: '',\n metadata: config,\n }\n}\n"],"names":[],"mappings":"AAKO,SAAS,mCAAmC,MAA0B;AAC3E,QAAM,WAAW,KAAK;AACtB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAM;AAAA,IACN,GAAG;AAAA,EAAA;AAEP;"}
1
+ {"version":3,"file":"web-fetch-tool.js","sources":["../../../src/tools/web-fetch-tool.ts"],"sourcesContent":["import type { BetaWebFetchTool20250910 } from '@anthropic-ai/sdk/resources/beta'\nimport type { ProviderTool, Tool } from '@tanstack/ai'\n\nexport type WebFetchToolConfig = BetaWebFetchTool20250910\n\n/** @deprecated Renamed to `WebFetchToolConfig`. Will be removed in a future release. */\nexport type WebFetchTool = WebFetchToolConfig\n\nexport type AnthropicWebFetchTool = ProviderTool<'anthropic', 'web_fetch'>\n\nexport function convertWebFetchToolToAdapterFormat(\n tool: Tool,\n): WebFetchToolConfig {\n const metadata = tool.metadata as Omit<WebFetchToolConfig, 'type' | 'name'>\n return {\n name: 'web_fetch',\n type: 'web_fetch_20250910',\n ...metadata,\n }\n}\n\nexport function webFetchTool(\n config?: Omit<WebFetchToolConfig, 'type' | 'name'>,\n): AnthropicWebFetchTool {\n // Phantom-brand cast: '~provider'/'~toolKind' are type-only and never assigned at runtime.\n return {\n name: 'web_fetch',\n description: '',\n metadata: config,\n } as unknown as AnthropicWebFetchTool\n}\n"],"names":[],"mappings":"AAUO,SAAS,mCACd,MACoB;AACpB,QAAM,WAAW,KAAK;AACtB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAM;AAAA,IACN,GAAG;AAAA,EAAA;AAEP;AAEO,SAAS,aACd,QACuB;AAEvB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,EAAA;AAEd;"}
@@ -1,5 +1,8 @@
1
1
  import { WebSearchTool20250305 } from '@anthropic-ai/sdk/resources/messages';
2
- import { Tool } from '@tanstack/ai';
3
- export type WebSearchTool = WebSearchTool20250305;
4
- export declare function convertWebSearchToolToAdapterFormat(tool: Tool): WebSearchTool;
5
- export declare function webSearchTool(config: WebSearchTool): Tool;
2
+ import { ProviderTool, Tool } from '@tanstack/ai';
3
+ export type WebSearchToolConfig = WebSearchTool20250305;
4
+ /** @deprecated Renamed to `WebSearchToolConfig`. Will be removed in a future release. */
5
+ export type WebSearchTool = WebSearchToolConfig;
6
+ export type AnthropicWebSearchTool = ProviderTool<'anthropic', 'web_search'>;
7
+ export declare function convertWebSearchToolToAdapterFormat(tool: Tool): WebSearchToolConfig;
8
+ export declare function webSearchTool(config: WebSearchToolConfig): AnthropicWebSearchTool;
@@ -1,3 +1,33 @@
1
+ const validateDomains = (tool) => {
2
+ if (tool.allowed_domains && tool.blocked_domains) {
3
+ throw new Error(
4
+ "allowed_domains and blocked_domains cannot be used together."
5
+ );
6
+ }
7
+ };
8
+ const validateUserLocation = (tool) => {
9
+ const userLocation = tool.user_location;
10
+ if (userLocation) {
11
+ if (userLocation.city && (userLocation.city.length < 1 || userLocation.city.length > 255)) {
12
+ throw new Error(
13
+ "user_location.city must be between 1 and 255 characters."
14
+ );
15
+ }
16
+ if (userLocation.country && userLocation.country.length !== 2) {
17
+ throw new Error("user_location.country must be exactly 2 characters.");
18
+ }
19
+ if (userLocation.region && (userLocation.region.length < 1 || userLocation.region.length > 255)) {
20
+ throw new Error(
21
+ "user_location.region must be between 1 and 255 characters."
22
+ );
23
+ }
24
+ if (userLocation.timezone && (userLocation.timezone.length < 1 || userLocation.timezone.length > 255)) {
25
+ throw new Error(
26
+ "user_location.timezone must be between 1 and 255 characters."
27
+ );
28
+ }
29
+ }
30
+ };
1
31
  function convertWebSearchToolToAdapterFormat(tool) {
2
32
  const metadata = tool.metadata;
3
33
  return {
@@ -10,7 +40,17 @@ function convertWebSearchToolToAdapterFormat(tool) {
10
40
  cache_control: metadata.cacheControl || null
11
41
  };
12
42
  }
43
+ function webSearchTool(config) {
44
+ validateDomains(config);
45
+ validateUserLocation(config);
46
+ return {
47
+ name: "web_search",
48
+ description: "",
49
+ metadata: config
50
+ };
51
+ }
13
52
  export {
14
- convertWebSearchToolToAdapterFormat
53
+ convertWebSearchToolToAdapterFormat,
54
+ webSearchTool
15
55
  };
16
56
  //# sourceMappingURL=web-search-tool.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"web-search-tool.js","sources":["../../../src/tools/web-search-tool.ts"],"sourcesContent":["import type { WebSearchTool20250305 } from '@anthropic-ai/sdk/resources/messages'\nimport type { CacheControl } from '../text/text-provider-options'\nimport type { Tool } from '@tanstack/ai'\n\nexport type WebSearchTool = WebSearchTool20250305\n\nconst validateDomains = (tool: WebSearchTool) => {\n if (tool.allowed_domains && tool.blocked_domains) {\n throw new Error(\n 'allowed_domains and blocked_domains cannot be used together.',\n )\n }\n}\n\nconst validateUserLocation = (tool: WebSearchTool) => {\n const userLocation = tool.user_location\n if (userLocation) {\n if (\n userLocation.city &&\n (userLocation.city.length < 1 || userLocation.city.length > 255)\n ) {\n throw new Error(\n 'user_location.city must be between 1 and 255 characters.',\n )\n }\n if (userLocation.country && userLocation.country.length !== 2) {\n throw new Error('user_location.country must be exactly 2 characters.')\n }\n if (\n userLocation.region &&\n (userLocation.region.length < 1 || userLocation.region.length > 255)\n ) {\n throw new Error(\n 'user_location.region must be between 1 and 255 characters.',\n )\n }\n if (\n userLocation.timezone &&\n (userLocation.timezone.length < 1 || userLocation.timezone.length > 255)\n ) {\n throw new Error(\n 'user_location.timezone must be between 1 and 255 characters.',\n )\n }\n }\n}\n\nexport function convertWebSearchToolToAdapterFormat(tool: Tool): WebSearchTool {\n const metadata = tool.metadata as {\n allowedDomains?: Array<string> | null\n blockedDomains?: Array<string> | null\n maxUses?: number | null\n userLocation?: {\n type: 'approximate'\n city?: string | null\n country?: string | null\n region?: string | null\n timezone?: string | null\n } | null\n cacheControl?: CacheControl | null\n }\n return {\n name: 'web_search',\n type: 'web_search_20250305',\n allowed_domains: metadata.allowedDomains,\n blocked_domains: metadata.blockedDomains,\n max_uses: metadata.maxUses,\n user_location: metadata.userLocation,\n cache_control: metadata.cacheControl || null,\n }\n}\n\nexport function webSearchTool(config: WebSearchTool): Tool {\n validateDomains(config)\n validateUserLocation(config)\n return {\n name: 'web_search',\n description: '',\n metadata: config,\n }\n}\n"],"names":[],"mappings":"AA+CO,SAAS,oCAAoC,MAA2B;AAC7E,QAAM,WAAW,KAAK;AAatB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAM;AAAA,IACN,iBAAiB,SAAS;AAAA,IAC1B,iBAAiB,SAAS;AAAA,IAC1B,UAAU,SAAS;AAAA,IACnB,eAAe,SAAS;AAAA,IACxB,eAAe,SAAS,gBAAgB;AAAA,EAAA;AAE5C;"}
1
+ {"version":3,"file":"web-search-tool.js","sources":["../../../src/tools/web-search-tool.ts"],"sourcesContent":["import type { WebSearchTool20250305 } from '@anthropic-ai/sdk/resources/messages'\nimport type { CacheControl } from '../text/text-provider-options'\nimport type { ProviderTool, Tool } from '@tanstack/ai'\n\nexport type WebSearchToolConfig = WebSearchTool20250305\n\n/** @deprecated Renamed to `WebSearchToolConfig`. Will be removed in a future release. */\nexport type WebSearchTool = WebSearchToolConfig\n\nexport type AnthropicWebSearchTool = ProviderTool<'anthropic', 'web_search'>\n\nconst validateDomains = (tool: WebSearchToolConfig) => {\n if (tool.allowed_domains && tool.blocked_domains) {\n throw new Error(\n 'allowed_domains and blocked_domains cannot be used together.',\n )\n }\n}\n\nconst validateUserLocation = (tool: WebSearchToolConfig) => {\n const userLocation = tool.user_location\n if (userLocation) {\n if (\n userLocation.city &&\n (userLocation.city.length < 1 || userLocation.city.length > 255)\n ) {\n throw new Error(\n 'user_location.city must be between 1 and 255 characters.',\n )\n }\n if (userLocation.country && userLocation.country.length !== 2) {\n throw new Error('user_location.country must be exactly 2 characters.')\n }\n if (\n userLocation.region &&\n (userLocation.region.length < 1 || userLocation.region.length > 255)\n ) {\n throw new Error(\n 'user_location.region must be between 1 and 255 characters.',\n )\n }\n if (\n userLocation.timezone &&\n (userLocation.timezone.length < 1 || userLocation.timezone.length > 255)\n ) {\n throw new Error(\n 'user_location.timezone must be between 1 and 255 characters.',\n )\n }\n }\n}\n\nexport function convertWebSearchToolToAdapterFormat(\n tool: Tool,\n): WebSearchToolConfig {\n const metadata = tool.metadata as {\n allowedDomains?: Array<string> | null\n blockedDomains?: Array<string> | null\n maxUses?: number | null\n userLocation?: {\n type: 'approximate'\n city?: string | null\n country?: string | null\n region?: string | null\n timezone?: string | null\n } | null\n cacheControl?: CacheControl | null\n }\n return {\n name: 'web_search',\n type: 'web_search_20250305',\n allowed_domains: metadata.allowedDomains,\n blocked_domains: metadata.blockedDomains,\n max_uses: metadata.maxUses,\n user_location: metadata.userLocation,\n cache_control: metadata.cacheControl || null,\n }\n}\n\nexport function webSearchTool(\n config: WebSearchToolConfig,\n): AnthropicWebSearchTool {\n validateDomains(config)\n validateUserLocation(config)\n // Phantom-brand cast: '~provider'/'~toolKind' are type-only and never assigned at runtime.\n return {\n name: 'web_search',\n description: '',\n metadata: config,\n } as unknown as AnthropicWebSearchTool\n}\n"],"names":[],"mappings":"AAWA,MAAM,kBAAkB,CAAC,SAA8B;AACrD,MAAI,KAAK,mBAAmB,KAAK,iBAAiB;AAChD,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AACF;AAEA,MAAM,uBAAuB,CAAC,SAA8B;AAC1D,QAAM,eAAe,KAAK;AAC1B,MAAI,cAAc;AAChB,QACE,aAAa,SACZ,aAAa,KAAK,SAAS,KAAK,aAAa,KAAK,SAAS,MAC5D;AACA,YAAM,IAAI;AAAA,QACR;AAAA,MAAA;AAAA,IAEJ;AACA,QAAI,aAAa,WAAW,aAAa,QAAQ,WAAW,GAAG;AAC7D,YAAM,IAAI,MAAM,qDAAqD;AAAA,IACvE;AACA,QACE,aAAa,WACZ,aAAa,OAAO,SAAS,KAAK,aAAa,OAAO,SAAS,MAChE;AACA,YAAM,IAAI;AAAA,QACR;AAAA,MAAA;AAAA,IAEJ;AACA,QACE,aAAa,aACZ,aAAa,SAAS,SAAS,KAAK,aAAa,SAAS,SAAS,MACpE;AACA,YAAM,IAAI;AAAA,QACR;AAAA,MAAA;AAAA,IAEJ;AAAA,EACF;AACF;AAEO,SAAS,oCACd,MACqB;AACrB,QAAM,WAAW,KAAK;AAatB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAM;AAAA,IACN,iBAAiB,SAAS;AAAA,IAC1B,iBAAiB,SAAS;AAAA,IAC1B,UAAU,SAAS;AAAA,IACnB,eAAe,SAAS;AAAA,IACxB,eAAe,SAAS,gBAAgB;AAAA,EAAA;AAE5C;AAEO,SAAS,cACd,QACwB;AACxB,kBAAgB,MAAM;AACtB,uBAAqB,MAAM;AAE3B,SAAO;AAAA,IACL,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,EAAA;AAEd;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/ai-anthropic",
3
- "version": "0.7.4",
3
+ "version": "0.8.0",
4
4
  "description": "Anthropic Claude adapter for TanStack AI",
5
5
  "author": "",
6
6
  "license": "MIT",
@@ -23,6 +23,10 @@
23
23
  ".": {
24
24
  "types": "./dist/esm/index.d.ts",
25
25
  "import": "./dist/esm/index.js"
26
+ },
27
+ "./tools": {
28
+ "types": "./dist/esm/tools/index.d.ts",
29
+ "import": "./dist/esm/tools/index.js"
26
30
  }
27
31
  },
28
32
  "files": [
@@ -34,12 +38,12 @@
34
38
  },
35
39
  "peerDependencies": {
36
40
  "zod": "^4.0.0",
37
- "@tanstack/ai": "^0.10.3"
41
+ "@tanstack/ai": "^0.12.0"
38
42
  },
39
43
  "devDependencies": {
40
44
  "@vitest/coverage-v8": "4.0.14",
41
45
  "zod": "^4.2.0",
42
- "@tanstack/ai": "0.10.3"
46
+ "@tanstack/ai": "0.12.0"
43
47
  },
44
48
  "scripts": {
45
49
  "build": "vite build",
@@ -12,6 +12,10 @@ import type {
12
12
  } from '@tanstack/ai'
13
13
  import type { AnthropicClientConfig } from '../utils'
14
14
 
15
+ /** Cast an event object to StreamChunk. */
16
+ const asChunk = (chunk: Record<string, unknown>) =>
17
+ chunk as unknown as StreamChunk
18
+
15
19
  /**
16
20
  * Configuration for Anthropic summarize adapter
17
21
  */
@@ -103,18 +107,18 @@ export class AnthropicSummarizeAdapter<
103
107
  if (event.delta.type === 'text_delta') {
104
108
  const delta = event.delta.text
105
109
  accumulatedContent += delta
106
- yield {
110
+ yield asChunk({
107
111
  type: 'TEXT_MESSAGE_CONTENT',
108
112
  messageId: id,
109
113
  model,
110
114
  timestamp: Date.now(),
111
115
  delta,
112
116
  content: accumulatedContent,
113
- }
117
+ })
114
118
  }
115
119
  } else if (event.type === 'message_delta') {
116
120
  outputTokens = event.usage.output_tokens
117
- yield {
121
+ yield asChunk({
118
122
  type: 'RUN_FINISHED',
119
123
  runId: id,
120
124
  model,
@@ -129,7 +133,7 @@ export class AnthropicSummarizeAdapter<
129
133
  completionTokens: outputTokens,
130
134
  totalTokens: inputTokens + outputTokens,
131
135
  },
132
- }
136
+ })
133
137
  }
134
138
  }
135
139
  }