@tanstack/ai-anthropic 0.18.0 → 0.18.2
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.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { brandAnthropicProviderTool, getAnthropicProviderToolMetadata } from "./anthropic-provider-tool.js";
|
|
2
|
+
import { SkillLimitError } from "@tanstack/ai";
|
|
2
3
|
//#region src/tools/code-execution-tool.ts
|
|
3
4
|
function convertCodeExecutionToolToAdapterFormat(tool) {
|
|
4
5
|
return readCodeExecutionConfig(tool);
|
|
@@ -20,7 +21,14 @@ function readCodeExecutionSkills(tool) {
|
|
|
20
21
|
function codeExecutionTool(config, options = {}) {
|
|
21
22
|
const { skills } = options;
|
|
22
23
|
if (skills) {
|
|
23
|
-
if (skills.length > 8) throw new
|
|
24
|
+
if (skills.length > 8) throw new SkillLimitError({
|
|
25
|
+
provider: "anthropic",
|
|
26
|
+
path: "native",
|
|
27
|
+
limit: "code_execution supports at most 8 skills per request",
|
|
28
|
+
allowed: 8,
|
|
29
|
+
actual: skills.length,
|
|
30
|
+
offending: skills.map((s) => s.skill_id)
|
|
31
|
+
});
|
|
24
32
|
for (const skill of skills) if (skill.skill_id.length < 1 || skill.skill_id.length > 64) throw new Error("skill_id must be between 1 and 64 characters.");
|
|
25
33
|
}
|
|
26
34
|
const metadata = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-execution-tool.js","names":[],"sources":["../../../src/tools/code-execution-tool.ts"],"sourcesContent":["import {\n brandAnthropicProviderTool,\n getAnthropicProviderToolMetadata,\n} from './anthropic-provider-tool'\nimport type {\n BetaCodeExecutionTool20250522,\n BetaCodeExecutionTool20250825,\n} from '@anthropic-ai/sdk/resources/beta'\nimport type { ProviderTool, Tool } from '@tanstack/ai'\n\nexport type CodeExecutionToolConfig =\n | BetaCodeExecutionTool20250522\n | BetaCodeExecutionTool20250825\n\n/** @deprecated Renamed to `CodeExecutionToolConfig`. Will be removed in a future release. */\nexport type CodeExecutionTool = CodeExecutionToolConfig\n\n/**\n * A hosted/managed Anthropic Skill reference. Lifted by the text adapter into\n * the top-level `container.skills` request param (NOT serialized into the\n * `tools[]` entry). Requires the `code_execution` tool to be enabled.\n */\nexport interface AnthropicContainerSkill {\n /** 1–64 characters. */\n skill_id: string\n type: 'anthropic' | 'custom'\n /** Skill version, or `'latest'` (default) when omitted. */\n version?: string\n}\n\nexport interface CodeExecutionToolOptions {\n /** Hosted skills to load into the code-execution container (max 8). */\n skills?: Array<AnthropicContainerSkill>\n}\n\ninterface CodeExecutionToolMetadata {\n config: CodeExecutionToolConfig\n skills?: Array<AnthropicContainerSkill>\n}\n\nexport type AnthropicCodeExecutionTool = ProviderTool<\n 'anthropic',\n 'code_execution'\n>\n\nexport function convertCodeExecutionToolToAdapterFormat(\n tool: Tool,\n): CodeExecutionToolConfig {\n // The converter is only called for real `code_execution` tools, so a\n // non-undefined config is expected — but read via optional chaining so an\n // absent metadata object doesn't throw.\n return readCodeExecutionConfig(tool) as CodeExecutionToolConfig\n}\n\n/**\n * Reads the SDK tool config attached to a `code_execution` tool, if any.\n * Used by the text adapter to select the version-aware code-execution beta.\n */\nexport function readCodeExecutionConfig(\n tool: Tool,\n): CodeExecutionToolConfig | undefined {\n return (\n getAnthropicProviderToolMetadata(tool) as\n | CodeExecutionToolMetadata\n | undefined\n )?.config\n}\n\n/**\n * Reads the hosted skills attached to a `code_execution` tool, if any.\n * Used by the text adapter to build the top-level `container.skills` param.\n */\nexport function readCodeExecutionSkills(\n tool: Tool,\n): Array<AnthropicContainerSkill> | undefined {\n return (\n getAnthropicProviderToolMetadata(tool) as\n | CodeExecutionToolMetadata\n | undefined\n )?.skills\n}\n\nexport function codeExecutionTool(\n config: CodeExecutionToolConfig,\n options: CodeExecutionToolOptions = {},\n): AnthropicCodeExecutionTool {\n const { skills } = options\n if (skills) {\n if (skills.length > 8) {\n throw new
|
|
1
|
+
{"version":3,"file":"code-execution-tool.js","names":[],"sources":["../../../src/tools/code-execution-tool.ts"],"sourcesContent":["import {\n brandAnthropicProviderTool,\n getAnthropicProviderToolMetadata,\n} from './anthropic-provider-tool'\nimport type {\n BetaCodeExecutionTool20250522,\n BetaCodeExecutionTool20250825,\n} from '@anthropic-ai/sdk/resources/beta'\nimport { SkillLimitError } from '@tanstack/ai'\nimport type { ProviderTool, Tool } from '@tanstack/ai'\n\nexport type CodeExecutionToolConfig =\n | BetaCodeExecutionTool20250522\n | BetaCodeExecutionTool20250825\n\n/** @deprecated Renamed to `CodeExecutionToolConfig`. Will be removed in a future release. */\nexport type CodeExecutionTool = CodeExecutionToolConfig\n\n/**\n * A hosted/managed Anthropic Skill reference. Lifted by the text adapter into\n * the top-level `container.skills` request param (NOT serialized into the\n * `tools[]` entry). Requires the `code_execution` tool to be enabled.\n */\nexport interface AnthropicContainerSkill {\n /** 1–64 characters. */\n skill_id: string\n type: 'anthropic' | 'custom'\n /** Skill version, or `'latest'` (default) when omitted. */\n version?: string\n}\n\nexport interface CodeExecutionToolOptions {\n /** Hosted skills to load into the code-execution container (max 8). */\n skills?: Array<AnthropicContainerSkill>\n}\n\ninterface CodeExecutionToolMetadata {\n config: CodeExecutionToolConfig\n skills?: Array<AnthropicContainerSkill>\n}\n\nexport type AnthropicCodeExecutionTool = ProviderTool<\n 'anthropic',\n 'code_execution'\n>\n\nexport function convertCodeExecutionToolToAdapterFormat(\n tool: Tool,\n): CodeExecutionToolConfig {\n // The converter is only called for real `code_execution` tools, so a\n // non-undefined config is expected — but read via optional chaining so an\n // absent metadata object doesn't throw.\n return readCodeExecutionConfig(tool) as CodeExecutionToolConfig\n}\n\n/**\n * Reads the SDK tool config attached to a `code_execution` tool, if any.\n * Used by the text adapter to select the version-aware code-execution beta.\n */\nexport function readCodeExecutionConfig(\n tool: Tool,\n): CodeExecutionToolConfig | undefined {\n return (\n getAnthropicProviderToolMetadata(tool) as\n | CodeExecutionToolMetadata\n | undefined\n )?.config\n}\n\n/**\n * Reads the hosted skills attached to a `code_execution` tool, if any.\n * Used by the text adapter to build the top-level `container.skills` param.\n */\nexport function readCodeExecutionSkills(\n tool: Tool,\n): Array<AnthropicContainerSkill> | undefined {\n return (\n getAnthropicProviderToolMetadata(tool) as\n | CodeExecutionToolMetadata\n | undefined\n )?.skills\n}\n\nexport function codeExecutionTool(\n config: CodeExecutionToolConfig,\n options: CodeExecutionToolOptions = {},\n): AnthropicCodeExecutionTool {\n const { skills } = options\n if (skills) {\n if (skills.length > 8) {\n throw new SkillLimitError({\n provider: 'anthropic',\n path: 'native',\n limit: 'code_execution supports at most 8 skills per request',\n allowed: 8,\n actual: skills.length,\n offending: skills.map((s) => s.skill_id),\n })\n }\n for (const skill of skills) {\n if (skill.skill_id.length < 1 || skill.skill_id.length > 64) {\n throw new Error('skill_id must be between 1 and 64 characters.')\n }\n }\n }\n const metadata: CodeExecutionToolMetadata = {\n config,\n ...(skills && { skills }),\n }\n return brandAnthropicProviderTool<AnthropicCodeExecutionTool>(\n {\n name: 'code_execution',\n description: '',\n metadata,\n },\n 'code_execution',\n )\n}\n"],"mappings":";;;AA8CA,SAAgB,wCACd,MACyB;CAIzB,OAAO,wBAAwB,IAAI;AACrC;;;;;AAMA,SAAgB,wBACd,MACqC;CACrC,OACE,iCAAiC,IAAI,CAAC,EAGrC;AACL;;;;;AAMA,SAAgB,wBACd,MAC4C;CAC5C,OACE,iCAAiC,IAAI,CAAC,EAGrC;AACL;AAEA,SAAgB,kBACd,QACA,UAAoC,CAAC,GACT;CAC5B,MAAM,EAAE,WAAW;CACnB,IAAI,QAAQ;EACV,IAAI,OAAO,SAAS,GAClB,MAAM,IAAI,gBAAgB;GACxB,UAAU;GACV,MAAM;GACN,OAAO;GACP,SAAS;GACT,QAAQ,OAAO;GACf,WAAW,OAAO,KAAK,MAAM,EAAE,QAAQ;EACzC,CAAC;EAEH,KAAK,MAAM,SAAS,QAClB,IAAI,MAAM,SAAS,SAAS,KAAK,MAAM,SAAS,SAAS,IACvD,MAAM,IAAI,MAAM,+CAA+C;CAGrE;CACA,MAAM,WAAsC;EAC1C;EACA,GAAI,UAAU,EAAE,OAAO;CACzB;CACA,OAAO,2BACL;EACE,MAAM;EACN,aAAa;EACb;CACF,GACA,gBACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/ai-anthropic",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.2",
|
|
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",
|
|
@@ -61,8 +61,7 @@
|
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"@anthropic-ai/vertex-sdk": "^0.19.0",
|
|
64
|
-
"
|
|
65
|
-
"@tanstack/ai": "^0.49.1"
|
|
64
|
+
"@tanstack/ai": "^0.51.0"
|
|
66
65
|
},
|
|
67
66
|
"peerDependenciesMeta": {
|
|
68
67
|
"@anthropic-ai/vertex-sdk": {
|
|
@@ -74,7 +73,7 @@
|
|
|
74
73
|
"@anthropic-ai/vertex-sdk": "^0.19.0",
|
|
75
74
|
"@vitest/coverage-v8": "4.1.10",
|
|
76
75
|
"zod": "^4.2.0",
|
|
77
|
-
"@tanstack/ai": "0.
|
|
76
|
+
"@tanstack/ai": "0.51.0"
|
|
78
77
|
},
|
|
79
78
|
"scripts": {
|
|
80
79
|
"build": "vite build",
|
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
BetaCodeExecutionTool20250522,
|
|
7
7
|
BetaCodeExecutionTool20250825,
|
|
8
8
|
} from '@anthropic-ai/sdk/resources/beta'
|
|
9
|
+
import { SkillLimitError } from '@tanstack/ai'
|
|
9
10
|
import type { ProviderTool, Tool } from '@tanstack/ai'
|
|
10
11
|
|
|
11
12
|
export type CodeExecutionToolConfig =
|
|
@@ -87,7 +88,14 @@ export function codeExecutionTool(
|
|
|
87
88
|
const { skills } = options
|
|
88
89
|
if (skills) {
|
|
89
90
|
if (skills.length > 8) {
|
|
90
|
-
throw new
|
|
91
|
+
throw new SkillLimitError({
|
|
92
|
+
provider: 'anthropic',
|
|
93
|
+
path: 'native',
|
|
94
|
+
limit: 'code_execution supports at most 8 skills per request',
|
|
95
|
+
allowed: 8,
|
|
96
|
+
actual: skills.length,
|
|
97
|
+
offending: skills.map((s) => s.skill_id),
|
|
98
|
+
})
|
|
91
99
|
}
|
|
92
100
|
for (const skill of skills) {
|
|
93
101
|
if (skill.skill_id.length < 1 || skill.skill_id.length > 64) {
|