@tanstack/ai-anthropic 0.16.3 → 0.16.5
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 +842 -940
- package/dist/esm/adapters/text.js.map +1 -1
- package/dist/esm/index.js +3 -13
- package/dist/esm/model-meta.d.ts +11 -11
- package/dist/esm/model-meta.js +399 -74
- package/dist/esm/model-meta.js.map +1 -1
- package/dist/esm/text/text-provider-options.d.ts +16 -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/src/adapters/text.ts +1 -0
- package/src/model-meta.ts +41 -20
- package/src/text/text-provider-options.ts +18 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/tools/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-fetch-tool.js","sources":["../../../src/tools/web-fetch-tool.ts"],"sourcesContent":["import { brandProviderTool } from '@tanstack/ai'\nimport 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 return brandProviderTool<AnthropicWebFetchTool>({\n name: 'web_fetch',\n description: '',\n metadata: config,\n })\n}\n"],"
|
|
1
|
+
{"version":3,"file":"web-fetch-tool.js","names":[],"sources":["../../../src/tools/web-fetch-tool.ts"],"sourcesContent":["import { brandProviderTool } from '@tanstack/ai'\nimport 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 return brandProviderTool<AnthropicWebFetchTool>({\n name: 'web_fetch',\n description: '',\n metadata: config,\n })\n}\n"],"mappings":";;AAWA,SAAgB,mCACd,MACoB;CAEpB,OAAO;EACL,MAAM;EACN,MAAM;EACN,GAJe,KAAK;CAKtB;AACF;AAEA,SAAgB,aACd,QACuB;CACvB,OAAO,kBAAyC;EAC9C,MAAM;EACN,aAAa;EACb,UAAU;CACZ,CAAC;AACH"}
|
|
@@ -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.5",
|
|
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.44.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.44.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/src/adapters/text.ts
CHANGED
|
@@ -455,6 +455,7 @@ export class AnthropicTextAdapter<
|
|
|
455
455
|
const validProviderOptions: Partial<InternalTextProviderOptions> = {}
|
|
456
456
|
if (modelOptions) {
|
|
457
457
|
const validKeys: Array<keyof AnthropicTextProviderOptions> = [
|
|
458
|
+
'cache_control',
|
|
458
459
|
'container',
|
|
459
460
|
'context_management',
|
|
460
461
|
'effort',
|
package/src/model-meta.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type {
|
|
|
2
2
|
AnthropicAdaptiveOnlyThinkingOptions,
|
|
3
3
|
AnthropicAdaptiveOrDisabledThinkingOptions,
|
|
4
4
|
AnthropicAdaptiveThinkingOptions,
|
|
5
|
+
AnthropicCacheControlOptions,
|
|
5
6
|
AnthropicContainerOptions,
|
|
6
7
|
AnthropicContextManagementOptions,
|
|
7
8
|
AnthropicMCPOptions,
|
|
@@ -94,7 +95,8 @@ const CLAUDE_OPUS_4_6 = {
|
|
|
94
95
|
],
|
|
95
96
|
},
|
|
96
97
|
} as const satisfies ModelMeta<
|
|
97
|
-
|
|
98
|
+
AnthropicCacheControlOptions &
|
|
99
|
+
AnthropicContainerOptions &
|
|
98
100
|
AnthropicContextManagementOptions &
|
|
99
101
|
AnthropicMCPOptions &
|
|
100
102
|
AnthropicServiceTierOptions &
|
|
@@ -133,7 +135,8 @@ const CLAUDE_OPUS_4_5 = {
|
|
|
133
135
|
],
|
|
134
136
|
},
|
|
135
137
|
} as const satisfies ModelMeta<
|
|
136
|
-
|
|
138
|
+
AnthropicCacheControlOptions &
|
|
139
|
+
AnthropicContainerOptions &
|
|
137
140
|
AnthropicContextManagementOptions &
|
|
138
141
|
AnthropicMCPOptions &
|
|
139
142
|
AnthropicServiceTierOptions &
|
|
@@ -175,7 +178,8 @@ const CLAUDE_SONNET_4_6 = {
|
|
|
175
178
|
],
|
|
176
179
|
},
|
|
177
180
|
} as const satisfies ModelMeta<
|
|
178
|
-
|
|
181
|
+
AnthropicCacheControlOptions &
|
|
182
|
+
AnthropicContainerOptions &
|
|
179
183
|
AnthropicContextManagementOptions &
|
|
180
184
|
AnthropicMCPOptions &
|
|
181
185
|
AnthropicServiceTierOptions &
|
|
@@ -214,7 +218,8 @@ const CLAUDE_SONNET_4_5 = {
|
|
|
214
218
|
],
|
|
215
219
|
},
|
|
216
220
|
} as const satisfies ModelMeta<
|
|
217
|
-
|
|
221
|
+
AnthropicCacheControlOptions &
|
|
222
|
+
AnthropicContainerOptions &
|
|
218
223
|
AnthropicContextManagementOptions &
|
|
219
224
|
AnthropicMCPOptions &
|
|
220
225
|
AnthropicServiceTierOptions &
|
|
@@ -253,7 +258,8 @@ const CLAUDE_HAIKU_4_5 = {
|
|
|
253
258
|
],
|
|
254
259
|
},
|
|
255
260
|
} as const satisfies ModelMeta<
|
|
256
|
-
|
|
261
|
+
AnthropicCacheControlOptions &
|
|
262
|
+
AnthropicContainerOptions &
|
|
257
263
|
AnthropicContextManagementOptions &
|
|
258
264
|
AnthropicMCPOptions &
|
|
259
265
|
AnthropicServiceTierOptions &
|
|
@@ -292,7 +298,8 @@ const CLAUDE_OPUS_4_1 = {
|
|
|
292
298
|
],
|
|
293
299
|
},
|
|
294
300
|
} as const satisfies ModelMeta<
|
|
295
|
-
|
|
301
|
+
AnthropicCacheControlOptions &
|
|
302
|
+
AnthropicContainerOptions &
|
|
296
303
|
AnthropicContextManagementOptions &
|
|
297
304
|
AnthropicMCPOptions &
|
|
298
305
|
AnthropicServiceTierOptions &
|
|
@@ -335,7 +342,8 @@ const CLAUDE_OPUS_4_7 = {
|
|
|
335
342
|
},
|
|
336
343
|
},
|
|
337
344
|
} as const satisfies ModelMeta<
|
|
338
|
-
|
|
345
|
+
AnthropicCacheControlOptions &
|
|
346
|
+
AnthropicContainerOptions &
|
|
339
347
|
AnthropicContextManagementOptions &
|
|
340
348
|
AnthropicMCPOptions &
|
|
341
349
|
AnthropicServiceTierOptions &
|
|
@@ -378,7 +386,8 @@ const CLAUDE_OPUS_4_8 = {
|
|
|
378
386
|
},
|
|
379
387
|
},
|
|
380
388
|
} as const satisfies ModelMeta<
|
|
381
|
-
|
|
389
|
+
AnthropicCacheControlOptions &
|
|
390
|
+
AnthropicContainerOptions &
|
|
382
391
|
AnthropicContextManagementOptions &
|
|
383
392
|
AnthropicMCPOptions &
|
|
384
393
|
AnthropicServiceTierOptions &
|
|
@@ -424,7 +433,8 @@ const CLAUDE_FABLE_5 = {
|
|
|
424
433
|
},
|
|
425
434
|
},
|
|
426
435
|
} as const satisfies ModelMeta<
|
|
427
|
-
|
|
436
|
+
AnthropicCacheControlOptions &
|
|
437
|
+
AnthropicContainerOptions &
|
|
428
438
|
AnthropicContextManagementOptions &
|
|
429
439
|
AnthropicMCPOptions &
|
|
430
440
|
AnthropicServiceTierOptions &
|
|
@@ -471,7 +481,8 @@ const CLAUDE_SONNET_5 = {
|
|
|
471
481
|
},
|
|
472
482
|
},
|
|
473
483
|
} as const satisfies ModelMeta<
|
|
474
|
-
|
|
484
|
+
AnthropicCacheControlOptions &
|
|
485
|
+
AnthropicContainerOptions &
|
|
475
486
|
AnthropicContextManagementOptions &
|
|
476
487
|
AnthropicMCPOptions &
|
|
477
488
|
AnthropicServiceTierOptions &
|
|
@@ -612,7 +623,8 @@ export type AnthropicChatModel = (typeof ANTHROPIC_MODELS)[number]
|
|
|
612
623
|
export type AnthropicChatModelProviderOptionsByName = {
|
|
613
624
|
// 4.6 generation: adaptive thinking plus the deprecated budget-based
|
|
614
625
|
// shape; sampling parameters still accepted.
|
|
615
|
-
[CLAUDE_OPUS_4_6.id]:
|
|
626
|
+
[CLAUDE_OPUS_4_6.id]: AnthropicCacheControlOptions &
|
|
627
|
+
AnthropicContainerOptions &
|
|
616
628
|
AnthropicContextManagementOptions &
|
|
617
629
|
AnthropicMCPOptions &
|
|
618
630
|
AnthropicServiceTierOptions &
|
|
@@ -620,7 +632,8 @@ export type AnthropicChatModelProviderOptionsByName = {
|
|
|
620
632
|
AnthropicAdaptiveThinkingOptions &
|
|
621
633
|
AnthropicToolChoiceOptions &
|
|
622
634
|
AnthropicSamplingOptions
|
|
623
|
-
[CLAUDE_SONNET_4_6.id]:
|
|
635
|
+
[CLAUDE_SONNET_4_6.id]: AnthropicCacheControlOptions &
|
|
636
|
+
AnthropicContainerOptions &
|
|
624
637
|
AnthropicContextManagementOptions &
|
|
625
638
|
AnthropicMCPOptions &
|
|
626
639
|
AnthropicServiceTierOptions &
|
|
@@ -630,7 +643,8 @@ export type AnthropicChatModelProviderOptionsByName = {
|
|
|
630
643
|
AnthropicSamplingOptions
|
|
631
644
|
|
|
632
645
|
// Pre-4.6 models: budget-based extended thinking and sampling parameters.
|
|
633
|
-
[CLAUDE_OPUS_4_5.id]:
|
|
646
|
+
[CLAUDE_OPUS_4_5.id]: AnthropicCacheControlOptions &
|
|
647
|
+
AnthropicContainerOptions &
|
|
634
648
|
AnthropicContextManagementOptions &
|
|
635
649
|
AnthropicMCPOptions &
|
|
636
650
|
AnthropicServiceTierOptions &
|
|
@@ -638,7 +652,8 @@ export type AnthropicChatModelProviderOptionsByName = {
|
|
|
638
652
|
AnthropicThinkingOptions &
|
|
639
653
|
AnthropicToolChoiceOptions &
|
|
640
654
|
AnthropicSamplingOptions
|
|
641
|
-
[CLAUDE_SONNET_4_5.id]:
|
|
655
|
+
[CLAUDE_SONNET_4_5.id]: AnthropicCacheControlOptions &
|
|
656
|
+
AnthropicContainerOptions &
|
|
642
657
|
AnthropicContextManagementOptions &
|
|
643
658
|
AnthropicMCPOptions &
|
|
644
659
|
AnthropicServiceTierOptions &
|
|
@@ -646,7 +661,8 @@ export type AnthropicChatModelProviderOptionsByName = {
|
|
|
646
661
|
AnthropicThinkingOptions &
|
|
647
662
|
AnthropicToolChoiceOptions &
|
|
648
663
|
AnthropicSamplingOptions
|
|
649
|
-
[CLAUDE_HAIKU_4_5.id]:
|
|
664
|
+
[CLAUDE_HAIKU_4_5.id]: AnthropicCacheControlOptions &
|
|
665
|
+
AnthropicContainerOptions &
|
|
650
666
|
AnthropicContextManagementOptions &
|
|
651
667
|
AnthropicMCPOptions &
|
|
652
668
|
AnthropicServiceTierOptions &
|
|
@@ -654,7 +670,8 @@ export type AnthropicChatModelProviderOptionsByName = {
|
|
|
654
670
|
AnthropicThinkingOptions &
|
|
655
671
|
AnthropicToolChoiceOptions &
|
|
656
672
|
AnthropicSamplingOptions
|
|
657
|
-
[CLAUDE_OPUS_4_1.id]:
|
|
673
|
+
[CLAUDE_OPUS_4_1.id]: AnthropicCacheControlOptions &
|
|
674
|
+
AnthropicContainerOptions &
|
|
658
675
|
AnthropicContextManagementOptions &
|
|
659
676
|
AnthropicMCPOptions &
|
|
660
677
|
AnthropicServiceTierOptions &
|
|
@@ -665,7 +682,8 @@ export type AnthropicChatModelProviderOptionsByName = {
|
|
|
665
682
|
|
|
666
683
|
// Opus 4.7/4.8: adaptive thinking (or explicit disable), no
|
|
667
684
|
// budget_tokens, no sampling parameters — see the constants above.
|
|
668
|
-
[CLAUDE_OPUS_4_7.id]:
|
|
685
|
+
[CLAUDE_OPUS_4_7.id]: AnthropicCacheControlOptions &
|
|
686
|
+
AnthropicContainerOptions &
|
|
669
687
|
AnthropicContextManagementOptions &
|
|
670
688
|
AnthropicMCPOptions &
|
|
671
689
|
AnthropicServiceTierOptions &
|
|
@@ -674,7 +692,8 @@ export type AnthropicChatModelProviderOptionsByName = {
|
|
|
674
692
|
AnthropicToolChoiceOptions &
|
|
675
693
|
AnthropicMaxTokensOptions &
|
|
676
694
|
AnthropicOutputConfigOptions
|
|
677
|
-
[CLAUDE_OPUS_4_8.id]:
|
|
695
|
+
[CLAUDE_OPUS_4_8.id]: AnthropicCacheControlOptions &
|
|
696
|
+
AnthropicContainerOptions &
|
|
678
697
|
AnthropicContextManagementOptions &
|
|
679
698
|
AnthropicMCPOptions &
|
|
680
699
|
AnthropicServiceTierOptions &
|
|
@@ -686,7 +705,8 @@ export type AnthropicChatModelProviderOptionsByName = {
|
|
|
686
705
|
|
|
687
706
|
// Claude Fable 5: thinking always on (adaptive-only config); sampling
|
|
688
707
|
// parameters removed — see the CLAUDE_FABLE_5 constant above.
|
|
689
|
-
[CLAUDE_FABLE_5.id]:
|
|
708
|
+
[CLAUDE_FABLE_5.id]: AnthropicCacheControlOptions &
|
|
709
|
+
AnthropicContainerOptions &
|
|
690
710
|
AnthropicContextManagementOptions &
|
|
691
711
|
AnthropicMCPOptions &
|
|
692
712
|
AnthropicServiceTierOptions &
|
|
@@ -698,7 +718,8 @@ export type AnthropicChatModelProviderOptionsByName = {
|
|
|
698
718
|
// Claude Sonnet 5: adaptive thinking by default, explicit disable
|
|
699
719
|
// allowed; no budget_tokens, no sampling parameters — see the
|
|
700
720
|
// CLAUDE_SONNET_5 constant above.
|
|
701
|
-
[CLAUDE_SONNET_5.id]:
|
|
721
|
+
[CLAUDE_SONNET_5.id]: AnthropicCacheControlOptions &
|
|
722
|
+
AnthropicContainerOptions &
|
|
702
723
|
AnthropicContextManagementOptions &
|
|
703
724
|
AnthropicMCPOptions &
|
|
704
725
|
AnthropicServiceTierOptions &
|
|
@@ -41,6 +41,22 @@ export interface AnthropicSystemPromptMetadata {
|
|
|
41
41
|
cache_control?: CacheControlEphemeral
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Top-level prompt-caching control.
|
|
46
|
+
*
|
|
47
|
+
* Anthropic's Messages API accepts `cache_control` as a request-level
|
|
48
|
+
* parameter: it auto-places the breakpoint on the last cacheable block of the
|
|
49
|
+
* rendered prompt (`tools` → `system` → `messages`). Use this when you don't
|
|
50
|
+
* need per-block placement; for a breakpoint on a specific system prompt, use
|
|
51
|
+
* the structured `systemPrompts` form with
|
|
52
|
+
* {@link AnthropicSystemPromptMetadata} instead.
|
|
53
|
+
*
|
|
54
|
+
* @see https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching
|
|
55
|
+
*/
|
|
56
|
+
export interface AnthropicCacheControlOptions {
|
|
57
|
+
cache_control?: CacheControlEphemeral
|
|
58
|
+
}
|
|
59
|
+
|
|
44
60
|
export interface AnthropicContainerOptions {
|
|
45
61
|
/**
|
|
46
62
|
* Container identifier for reuse across requests.
|
|
@@ -288,7 +304,8 @@ Required range: x >= 0
|
|
|
288
304
|
max_tokens?: number
|
|
289
305
|
}
|
|
290
306
|
|
|
291
|
-
export type ExternalTextProviderOptions =
|
|
307
|
+
export type ExternalTextProviderOptions = AnthropicCacheControlOptions &
|
|
308
|
+
AnthropicContainerOptions &
|
|
292
309
|
AnthropicContextManagementOptions &
|
|
293
310
|
AnthropicMCPOptions &
|
|
294
311
|
AnthropicServiceTierOptions &
|
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":";;;;;;;;"}
|