@tanstack/ai-anthropic 0.16.2 → 0.16.4
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/summarize.js +39 -12
- package/dist/esm/adapters/summarize.js.map +1 -1
- package/dist/esm/adapters/text.js +841 -940
- package/dist/esm/adapters/text.js.map +1 -1
- package/dist/esm/index.js +3 -13
- package/dist/esm/model-meta.js +399 -74
- package/dist/esm/model-meta.js.map +1 -1
- package/dist/esm/text/text-provider-options.js +19 -26
- package/dist/esm/text/text-provider-options.js.map +1 -1
- package/dist/esm/tools/bash-tool.js +11 -12
- package/dist/esm/tools/bash-tool.js.map +1 -1
- package/dist/esm/tools/code-execution-tool.js +29 -30
- package/dist/esm/tools/code-execution-tool.js.map +1 -1
- package/dist/esm/tools/computer-use-tool.js +11 -12
- package/dist/esm/tools/computer-use-tool.js.map +1 -1
- package/dist/esm/tools/custom-tool.js +29 -30
- package/dist/esm/tools/custom-tool.js.map +1 -1
- package/dist/esm/tools/index.js +1 -14
- package/dist/esm/tools/memory-tool.js +14 -15
- package/dist/esm/tools/memory-tool.js.map +1 -1
- package/dist/esm/tools/text-editor-tool.js +11 -14
- package/dist/esm/tools/text-editor-tool.js.map +1 -1
- package/dist/esm/tools/tool-converter.js +41 -25
- package/dist/esm/tools/tool-converter.js.map +1 -1
- package/dist/esm/tools/web-fetch-tool.js +15 -16
- package/dist/esm/tools/web-fetch-tool.js.map +1 -1
- package/dist/esm/tools/web-search-tool.js +32 -56
- package/dist/esm/tools/web-search-tool.js.map +1 -1
- package/dist/esm/usage.js +33 -32
- package/dist/esm/usage.js.map +1 -1
- package/dist/esm/utils/client.js +23 -14
- package/dist/esm/utils/client.js.map +1 -1
- package/package.json +6 -6
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/tools/index.js.map +0 -1
|
@@ -1,63 +1,39 @@
|
|
|
1
1
|
import { brandProviderTool } from "@tanstack/ai";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
"allowed_domains and blocked_domains cannot be used together."
|
|
6
|
-
);
|
|
7
|
-
}
|
|
2
|
+
//#region src/tools/web-search-tool.ts
|
|
3
|
+
var validateDomains = (tool) => {
|
|
4
|
+
if (tool.allowed_domains && tool.blocked_domains) throw new Error("allowed_domains and blocked_domains cannot be used together.");
|
|
8
5
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (userLocation.country && userLocation.country.length !== 2) {
|
|
18
|
-
throw new Error("user_location.country must be exactly 2 characters.");
|
|
19
|
-
}
|
|
20
|
-
if (userLocation.region && (userLocation.region.length < 1 || userLocation.region.length > 255)) {
|
|
21
|
-
throw new Error(
|
|
22
|
-
"user_location.region must be between 1 and 255 characters."
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
if (userLocation.timezone && (userLocation.timezone.length < 1 || userLocation.timezone.length > 255)) {
|
|
26
|
-
throw new Error(
|
|
27
|
-
"user_location.timezone must be between 1 and 255 characters."
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
6
|
+
var validateUserLocation = (tool) => {
|
|
7
|
+
const userLocation = tool.user_location;
|
|
8
|
+
if (userLocation) {
|
|
9
|
+
if (userLocation.city && (userLocation.city.length < 1 || userLocation.city.length > 255)) throw new Error("user_location.city must be between 1 and 255 characters.");
|
|
10
|
+
if (userLocation.country && userLocation.country.length !== 2) throw new Error("user_location.country must be exactly 2 characters.");
|
|
11
|
+
if (userLocation.region && (userLocation.region.length < 1 || userLocation.region.length > 255)) throw new Error("user_location.region must be between 1 and 255 characters.");
|
|
12
|
+
if (userLocation.timezone && (userLocation.timezone.length < 1 || userLocation.timezone.length > 255)) throw new Error("user_location.timezone must be between 1 and 255 characters.");
|
|
13
|
+
}
|
|
31
14
|
};
|
|
32
15
|
function convertWebSearchToolToAdapterFormat(tool) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
...metadata.maxUses !== void 0 && { max_uses: metadata.maxUses },
|
|
44
|
-
...metadata.userLocation !== void 0 && {
|
|
45
|
-
user_location: metadata.userLocation
|
|
46
|
-
},
|
|
47
|
-
cache_control: metadata.cacheControl || null
|
|
48
|
-
};
|
|
16
|
+
const metadata = tool.metadata;
|
|
17
|
+
return {
|
|
18
|
+
name: "web_search",
|
|
19
|
+
type: "web_search_20250305",
|
|
20
|
+
...metadata.allowedDomains !== void 0 && { allowed_domains: metadata.allowedDomains },
|
|
21
|
+
...metadata.blockedDomains !== void 0 && { blocked_domains: metadata.blockedDomains },
|
|
22
|
+
...metadata.maxUses !== void 0 && { max_uses: metadata.maxUses },
|
|
23
|
+
...metadata.userLocation !== void 0 && { user_location: metadata.userLocation },
|
|
24
|
+
cache_control: metadata.cacheControl || null
|
|
25
|
+
};
|
|
49
26
|
}
|
|
50
27
|
function webSearchTool(config) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
28
|
+
validateDomains(config);
|
|
29
|
+
validateUserLocation(config);
|
|
30
|
+
return brandProviderTool({
|
|
31
|
+
name: "web_search",
|
|
32
|
+
description: "",
|
|
33
|
+
metadata: config
|
|
34
|
+
});
|
|
58
35
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
//# sourceMappingURL=web-search-tool.js.map
|
|
36
|
+
//#endregion
|
|
37
|
+
export { convertWebSearchToolToAdapterFormat, webSearchTool };
|
|
38
|
+
|
|
39
|
+
//# 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 { brandProviderTool } from '@tanstack/ai'\nimport 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 // Vendor `WebSearchTool20250305` declares these fields as `T | null`\n // (no `| undefined`) under exactOptionalPropertyTypes, so spread them\n // conditionally rather than passing explicit `undefined`.\n return {\n name: 'web_search',\n type: 'web_search_20250305',\n ...(metadata.allowedDomains !== undefined && {\n allowed_domains: metadata.allowedDomains,\n }),\n ...(metadata.blockedDomains !== undefined && {\n blocked_domains: metadata.blockedDomains,\n }),\n ...(metadata.maxUses !== undefined && { max_uses: metadata.maxUses }),\n ...(metadata.userLocation !== undefined && {\n user_location: metadata.userLocation,\n }),\n cache_control: metadata.cacheControl || null,\n }\n}\n\nexport function webSearchTool(\n config: WebSearchToolConfig,\n): AnthropicWebSearchTool {\n validateDomains(config)\n validateUserLocation(config)\n return brandProviderTool<AnthropicWebSearchTool>({\n name: 'web_search',\n description: '',\n metadata: config,\n })\n}\n"],"
|
|
1
|
+
{"version":3,"file":"web-search-tool.js","names":[],"sources":["../../../src/tools/web-search-tool.ts"],"sourcesContent":["import { brandProviderTool } from '@tanstack/ai'\nimport 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 // Vendor `WebSearchTool20250305` declares these fields as `T | null`\n // (no `| undefined`) under exactOptionalPropertyTypes, so spread them\n // conditionally rather than passing explicit `undefined`.\n return {\n name: 'web_search',\n type: 'web_search_20250305',\n ...(metadata.allowedDomains !== undefined && {\n allowed_domains: metadata.allowedDomains,\n }),\n ...(metadata.blockedDomains !== undefined && {\n blocked_domains: metadata.blockedDomains,\n }),\n ...(metadata.maxUses !== undefined && { max_uses: metadata.maxUses }),\n ...(metadata.userLocation !== undefined && {\n user_location: metadata.userLocation,\n }),\n cache_control: metadata.cacheControl || null,\n }\n}\n\nexport function webSearchTool(\n config: WebSearchToolConfig,\n): AnthropicWebSearchTool {\n validateDomains(config)\n validateUserLocation(config)\n return brandProviderTool<AnthropicWebSearchTool>({\n name: 'web_search',\n description: '',\n metadata: config,\n })\n}\n"],"mappings":";;AAYA,IAAM,mBAAmB,SAA8B;CACrD,IAAI,KAAK,mBAAmB,KAAK,iBAC/B,MAAM,IAAI,MACR,8DACF;AAEJ;AAEA,IAAM,wBAAwB,SAA8B;CAC1D,MAAM,eAAe,KAAK;CAC1B,IAAI,cAAc;EAChB,IACE,aAAa,SACZ,aAAa,KAAK,SAAS,KAAK,aAAa,KAAK,SAAS,MAE5D,MAAM,IAAI,MACR,0DACF;EAEF,IAAI,aAAa,WAAW,aAAa,QAAQ,WAAW,GAC1D,MAAM,IAAI,MAAM,qDAAqD;EAEvE,IACE,aAAa,WACZ,aAAa,OAAO,SAAS,KAAK,aAAa,OAAO,SAAS,MAEhE,MAAM,IAAI,MACR,4DACF;EAEF,IACE,aAAa,aACZ,aAAa,SAAS,SAAS,KAAK,aAAa,SAAS,SAAS,MAEpE,MAAM,IAAI,MACR,8DACF;CAEJ;AACF;AAEA,SAAgB,oCACd,MACqB;CACrB,MAAM,WAAW,KAAK;CAgBtB,OAAO;EACL,MAAM;EACN,MAAM;EACN,GAAI,SAAS,mBAAmB,KAAA,KAAa,EAC3C,iBAAiB,SAAS,eAC5B;EACA,GAAI,SAAS,mBAAmB,KAAA,KAAa,EAC3C,iBAAiB,SAAS,eAC5B;EACA,GAAI,SAAS,YAAY,KAAA,KAAa,EAAE,UAAU,SAAS,QAAQ;EACnE,GAAI,SAAS,iBAAiB,KAAA,KAAa,EACzC,eAAe,SAAS,aAC1B;EACA,eAAe,SAAS,gBAAgB;CAC1C;AACF;AAEA,SAAgB,cACd,QACwB;CACxB,gBAAgB,MAAM;CACtB,qBAAqB,MAAM;CAC3B,OAAO,kBAA0C;EAC/C,MAAM;EACN,aAAa;EACb,UAAU;CACZ,CAAC;AACH"}
|
package/dist/esm/usage.js
CHANGED
|
@@ -1,35 +1,36 @@
|
|
|
1
1
|
import { buildBaseUsage } from "@tanstack/ai";
|
|
2
|
+
//#region src/usage.ts
|
|
3
|
+
/**
|
|
4
|
+
* Build normalized TokenUsage from Anthropic's usage object.
|
|
5
|
+
* Handles cache tokens and server tool use metrics. Returns `undefined` when
|
|
6
|
+
* the provider reported no usage object, so callers omit the field rather than
|
|
7
|
+
* fabricating zeroed totals.
|
|
8
|
+
*/
|
|
2
9
|
function buildAnthropicUsage(usage) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (Object.keys(serverToolUseDetails).length > 0) {
|
|
26
|
-
result.providerUsageDetails = {
|
|
27
|
-
serverToolUse: serverToolUseDetails
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
return result;
|
|
10
|
+
if (!usage) return void 0;
|
|
11
|
+
const inputTokens = usage.input_tokens ?? 0;
|
|
12
|
+
const outputTokens = usage.output_tokens || 0;
|
|
13
|
+
const result = buildBaseUsage({
|
|
14
|
+
promptTokens: inputTokens,
|
|
15
|
+
completionTokens: outputTokens,
|
|
16
|
+
totalTokens: inputTokens + outputTokens
|
|
17
|
+
});
|
|
18
|
+
const cacheCreation = usage.cache_creation_input_tokens;
|
|
19
|
+
const cacheRead = usage.cache_read_input_tokens;
|
|
20
|
+
const promptTokensDetails = {
|
|
21
|
+
...cacheCreation ? { cacheWriteTokens: cacheCreation } : {},
|
|
22
|
+
...cacheRead ? { cachedTokens: cacheRead } : {}
|
|
23
|
+
};
|
|
24
|
+
if (Object.keys(promptTokensDetails).length > 0) result.promptTokensDetails = promptTokensDetails;
|
|
25
|
+
const serverToolUse = usage.server_tool_use;
|
|
26
|
+
const serverToolUseDetails = {
|
|
27
|
+
...serverToolUse?.web_search_requests ? { webSearchRequests: serverToolUse.web_search_requests } : {},
|
|
28
|
+
...serverToolUse?.web_fetch_requests ? { webFetchRequests: serverToolUse.web_fetch_requests } : {}
|
|
29
|
+
};
|
|
30
|
+
if (Object.keys(serverToolUseDetails).length > 0) result.providerUsageDetails = { serverToolUse: serverToolUseDetails };
|
|
31
|
+
return result;
|
|
31
32
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
//# sourceMappingURL=usage.js.map
|
|
33
|
+
//#endregion
|
|
34
|
+
export { buildAnthropicUsage };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=usage.js.map
|
package/dist/esm/usage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage.js","sources":["../../src/usage.ts"],"sourcesContent":["import { buildBaseUsage } from '@tanstack/ai'\nimport type { TokenUsage } from '@tanstack/ai'\nimport type Anthropic_SDK from '@anthropic-ai/sdk'\n\n/**\n * Anthropic-specific provider usage details.\n * These fields are unique to Anthropic and placed in providerUsageDetails.\n */\nexport type AnthropicProviderUsageDetails = {\n /**\n * Server-side tool usage metrics.\n * Available when using Anthropic's built-in tools like web search.\n */\n serverToolUse?: {\n /** Number of web search requests made during the response */\n webSearchRequests?: number\n /** Number of web fetch requests made during the response */\n webFetchRequests?: number\n }\n}\n\n/**\n * Build normalized TokenUsage from Anthropic's usage object.\n * Handles cache tokens and server tool use metrics. Returns `undefined` when\n * the provider reported no usage object, so callers omit the field rather than\n * fabricating zeroed totals.\n */\nexport function buildAnthropicUsage(\n usage:\n | Anthropic_SDK.Beta.BetaUsage\n | Anthropic_SDK.Beta.BetaMessageDeltaUsage\n | undefined\n | null,\n): TokenUsage<AnthropicProviderUsageDetails> | undefined {\n if (!usage) return undefined\n\n const inputTokens = usage.input_tokens ?? 0\n // `|| 0` (rather than `?? 0`) matches the sibling builders and stays defensive\n // against a runtime-absent count without tripping no-unnecessary-condition\n // (the SDK types output_tokens as a required number).\n const outputTokens = usage.output_tokens || 0\n\n const result = buildBaseUsage<AnthropicProviderUsageDetails>({\n promptTokens: inputTokens,\n completionTokens: outputTokens,\n totalTokens: inputTokens + outputTokens,\n })\n\n // Add prompt token details for cache tokens. Only attach the details object\n // when at least one field is present so we don't emit an empty `{}` (every\n // other adapter guards with the same Object.keys check).\n const cacheCreation = usage.cache_creation_input_tokens\n const cacheRead = usage.cache_read_input_tokens\n\n const promptTokensDetails = {\n ...(cacheCreation ? { cacheWriteTokens: cacheCreation } : {}),\n ...(cacheRead ? { cachedTokens: cacheRead } : {}),\n }\n if (Object.keys(promptTokensDetails).length > 0) {\n result.promptTokensDetails = promptTokensDetails\n }\n\n // Add provider-specific usage details for server tool use, again only when\n // the provider actually reported any server tool requests.\n const serverToolUse = usage.server_tool_use\n const serverToolUseDetails = {\n ...(serverToolUse?.web_search_requests\n ? { webSearchRequests: serverToolUse.web_search_requests }\n : {}),\n ...(serverToolUse?.web_fetch_requests\n ? { webFetchRequests: serverToolUse.web_fetch_requests }\n : {}),\n }\n if (Object.keys(serverToolUseDetails).length > 0) {\n result.providerUsageDetails = {\n serverToolUse: serverToolUseDetails,\n } satisfies AnthropicProviderUsageDetails\n }\n\n return result\n}\n"],"
|
|
1
|
+
{"version":3,"file":"usage.js","names":[],"sources":["../../src/usage.ts"],"sourcesContent":["import { buildBaseUsage } from '@tanstack/ai'\nimport type { TokenUsage } from '@tanstack/ai'\nimport type Anthropic_SDK from '@anthropic-ai/sdk'\n\n/**\n * Anthropic-specific provider usage details.\n * These fields are unique to Anthropic and placed in providerUsageDetails.\n */\nexport type AnthropicProviderUsageDetails = {\n /**\n * Server-side tool usage metrics.\n * Available when using Anthropic's built-in tools like web search.\n */\n serverToolUse?: {\n /** Number of web search requests made during the response */\n webSearchRequests?: number\n /** Number of web fetch requests made during the response */\n webFetchRequests?: number\n }\n}\n\n/**\n * Build normalized TokenUsage from Anthropic's usage object.\n * Handles cache tokens and server tool use metrics. Returns `undefined` when\n * the provider reported no usage object, so callers omit the field rather than\n * fabricating zeroed totals.\n */\nexport function buildAnthropicUsage(\n usage:\n | Anthropic_SDK.Beta.BetaUsage\n | Anthropic_SDK.Beta.BetaMessageDeltaUsage\n | undefined\n | null,\n): TokenUsage<AnthropicProviderUsageDetails> | undefined {\n if (!usage) return undefined\n\n const inputTokens = usage.input_tokens ?? 0\n // `|| 0` (rather than `?? 0`) matches the sibling builders and stays defensive\n // against a runtime-absent count without tripping no-unnecessary-condition\n // (the SDK types output_tokens as a required number).\n const outputTokens = usage.output_tokens || 0\n\n const result = buildBaseUsage<AnthropicProviderUsageDetails>({\n promptTokens: inputTokens,\n completionTokens: outputTokens,\n totalTokens: inputTokens + outputTokens,\n })\n\n // Add prompt token details for cache tokens. Only attach the details object\n // when at least one field is present so we don't emit an empty `{}` (every\n // other adapter guards with the same Object.keys check).\n const cacheCreation = usage.cache_creation_input_tokens\n const cacheRead = usage.cache_read_input_tokens\n\n const promptTokensDetails = {\n ...(cacheCreation ? { cacheWriteTokens: cacheCreation } : {}),\n ...(cacheRead ? { cachedTokens: cacheRead } : {}),\n }\n if (Object.keys(promptTokensDetails).length > 0) {\n result.promptTokensDetails = promptTokensDetails\n }\n\n // Add provider-specific usage details for server tool use, again only when\n // the provider actually reported any server tool requests.\n const serverToolUse = usage.server_tool_use\n const serverToolUseDetails = {\n ...(serverToolUse?.web_search_requests\n ? { webSearchRequests: serverToolUse.web_search_requests }\n : {}),\n ...(serverToolUse?.web_fetch_requests\n ? { webFetchRequests: serverToolUse.web_fetch_requests }\n : {}),\n }\n if (Object.keys(serverToolUseDetails).length > 0) {\n result.providerUsageDetails = {\n serverToolUse: serverToolUseDetails,\n } satisfies AnthropicProviderUsageDetails\n }\n\n return result\n}\n"],"mappings":";;;;;;;;AA2BA,SAAgB,oBACd,OAKuD;CACvD,IAAI,CAAC,OAAO,OAAO,KAAA;CAEnB,MAAM,cAAc,MAAM,gBAAgB;CAI1C,MAAM,eAAe,MAAM,iBAAiB;CAE5C,MAAM,SAAS,eAA8C;EAC3D,cAAc;EACd,kBAAkB;EAClB,aAAa,cAAc;CAC7B,CAAC;CAKD,MAAM,gBAAgB,MAAM;CAC5B,MAAM,YAAY,MAAM;CAExB,MAAM,sBAAsB;EAC1B,GAAI,gBAAgB,EAAE,kBAAkB,cAAc,IAAI,CAAC;EAC3D,GAAI,YAAY,EAAE,cAAc,UAAU,IAAI,CAAC;CACjD;CACA,IAAI,OAAO,KAAK,mBAAmB,CAAC,CAAC,SAAS,GAC5C,OAAO,sBAAsB;CAK/B,MAAM,gBAAgB,MAAM;CAC5B,MAAM,uBAAuB;EAC3B,GAAI,eAAe,sBACf,EAAE,mBAAmB,cAAc,oBAAoB,IACvD,CAAC;EACL,GAAI,eAAe,qBACf,EAAE,kBAAkB,cAAc,mBAAmB,IACrD,CAAC;CACP;CACA,IAAI,OAAO,KAAK,oBAAoB,CAAC,CAAC,SAAS,GAC7C,OAAO,uBAAuB,EAC5B,eAAe,qBACjB;CAGF,OAAO;AACT"}
|
package/dist/esm/utils/client.js
CHANGED
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
import Anthropic_SDK from "@anthropic-ai/sdk";
|
|
2
|
-
import { generateId
|
|
2
|
+
import { generateId, getApiKeyFromEnv } from "@tanstack/ai-utils";
|
|
3
|
+
//#region src/utils/client.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates an Anthropic SDK client instance
|
|
6
|
+
*/
|
|
3
7
|
function createAnthropicClient(config) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
return new Anthropic_SDK({
|
|
9
|
+
...config,
|
|
10
|
+
apiKey: config.apiKey
|
|
11
|
+
});
|
|
8
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Gets Anthropic API key from environment variables
|
|
15
|
+
* @throws Error if ANTHROPIC_API_KEY is not found
|
|
16
|
+
*/
|
|
9
17
|
function getAnthropicApiKeyFromEnv() {
|
|
10
|
-
|
|
18
|
+
return getApiKeyFromEnv("ANTHROPIC_API_KEY");
|
|
11
19
|
}
|
|
12
|
-
|
|
13
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Generates a unique ID with a prefix
|
|
22
|
+
*/
|
|
23
|
+
function generateId$1(prefix) {
|
|
24
|
+
return generateId(prefix);
|
|
14
25
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
//# sourceMappingURL=client.js.map
|
|
26
|
+
//#endregion
|
|
27
|
+
export { createAnthropicClient, generateId$1 as generateId, getAnthropicApiKeyFromEnv };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sources":["../../../src/utils/client.ts"],"sourcesContent":["import Anthropic_SDK from '@anthropic-ai/sdk'\nimport { generateId as _generateId, getApiKeyFromEnv } from '@tanstack/ai-utils'\nimport type { ClientOptions } from '@anthropic-ai/sdk'\n\nexport interface AnthropicClientConfig extends ClientOptions {\n apiKey: string\n}\n\n/**\n * Creates an Anthropic SDK client instance\n */\nexport function createAnthropicClient(\n config: AnthropicClientConfig,\n): Anthropic_SDK {\n return new Anthropic_SDK({\n ...config,\n apiKey: config.apiKey,\n })\n}\n\n/**\n * Gets Anthropic API key from environment variables\n * @throws Error if ANTHROPIC_API_KEY is not found\n */\nexport function getAnthropicApiKeyFromEnv(): string {\n return getApiKeyFromEnv('ANTHROPIC_API_KEY')\n}\n\n/**\n * Generates a unique ID with a prefix\n */\nexport function generateId(prefix: string): string {\n return _generateId(prefix)\n}\n"],"
|
|
1
|
+
{"version":3,"file":"client.js","names":[],"sources":["../../../src/utils/client.ts"],"sourcesContent":["import Anthropic_SDK from '@anthropic-ai/sdk'\nimport { generateId as _generateId, getApiKeyFromEnv } from '@tanstack/ai-utils'\nimport type { ClientOptions } from '@anthropic-ai/sdk'\n\nexport interface AnthropicClientConfig extends ClientOptions {\n apiKey: string\n}\n\n/**\n * Creates an Anthropic SDK client instance\n */\nexport function createAnthropicClient(\n config: AnthropicClientConfig,\n): Anthropic_SDK {\n return new Anthropic_SDK({\n ...config,\n apiKey: config.apiKey,\n })\n}\n\n/**\n * Gets Anthropic API key from environment variables\n * @throws Error if ANTHROPIC_API_KEY is not found\n */\nexport function getAnthropicApiKeyFromEnv(): string {\n return getApiKeyFromEnv('ANTHROPIC_API_KEY')\n}\n\n/**\n * Generates a unique ID with a prefix\n */\nexport function generateId(prefix: string): string {\n return _generateId(prefix)\n}\n"],"mappings":";;;;;;AAWA,SAAgB,sBACd,QACe;CACf,OAAO,IAAI,cAAc;EACvB,GAAG;EACH,QAAQ,OAAO;CACjB,CAAC;AACH;;;;;AAMA,SAAgB,4BAAoC;CAClD,OAAO,iBAAiB,mBAAmB;AAC7C;;;;AAKA,SAAgB,aAAW,QAAwB;CACjD,OAAO,WAAY,MAAM;AAC3B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/ai-anthropic",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.4",
|
|
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",
|
|
@@ -49,23 +49,23 @@
|
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@anthropic-ai/sdk": "^0.97.1",
|
|
52
|
-
"@tanstack/ai-utils": "0.
|
|
52
|
+
"@tanstack/ai-utils": "0.4.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"zod": "^4.0.0",
|
|
56
|
-
"@tanstack/ai": "^0.
|
|
56
|
+
"@tanstack/ai": "^0.43.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@vitest/coverage-v8": "4.0.14",
|
|
60
60
|
"zod": "^4.2.0",
|
|
61
|
-
"@tanstack/ai": "0.
|
|
61
|
+
"@tanstack/ai": "0.43.0"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"build": "vite build",
|
|
65
65
|
"clean": "premove ./build ./dist",
|
|
66
|
-
"lint:fix": "
|
|
66
|
+
"lint:fix": "oxlint src --type-aware --fix",
|
|
67
67
|
"test:build": "publint --strict",
|
|
68
|
-
"test:
|
|
68
|
+
"test:oxlint": "oxlint src --type-aware",
|
|
69
69
|
"test:lib": "vitest",
|
|
70
70
|
"test:lib:dev": "pnpm test:lib --watch",
|
|
71
71
|
"test:types": "tsc"
|
package/dist/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
|