@standardagents/anthropic 0.0.0-stub.ffffff → 0.17.1
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/LICENSE.txt +48 -0
- package/README.md +33 -1
- package/dist/index.d.ts +220 -0
- package/dist/index.js +1432 -0
- package/dist/index.js.map +1 -0
- package/package.json +45 -7
- package/index.js +0 -1
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
PROPRIETARY SOFTWARE LICENSE
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2025 FormKit Inc. All Rights Reserved.
|
|
4
|
+
|
|
5
|
+
UNLICENSED - DO NOT USE
|
|
6
|
+
|
|
7
|
+
This software and associated documentation files (the "Software") are the sole
|
|
8
|
+
and exclusive property of FormKit Inc. ("FormKit").
|
|
9
|
+
|
|
10
|
+
USE RESTRICTIONS
|
|
11
|
+
|
|
12
|
+
The Software is UNLICENSED and proprietary. NO PERMISSION is granted to use,
|
|
13
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
14
|
+
the Software, or to permit persons to whom the Software is furnished to do so,
|
|
15
|
+
under any circumstances, without prior written authorization from FormKit Inc.
|
|
16
|
+
|
|
17
|
+
UNAUTHORIZED USE PROHIBITED
|
|
18
|
+
|
|
19
|
+
Any use of this Software without a valid, written license agreement signed by
|
|
20
|
+
authorized officers of FormKit Inc. is strictly prohibited and constitutes
|
|
21
|
+
unauthorized use and infringement of FormKit's intellectual property rights.
|
|
22
|
+
|
|
23
|
+
LICENSING INQUIRIES
|
|
24
|
+
|
|
25
|
+
Organizations interested in licensing this Software should contact:
|
|
26
|
+
enterprise@formkit.com
|
|
27
|
+
|
|
28
|
+
A written license agreement must be executed before any use of this Software
|
|
29
|
+
is authorized.
|
|
30
|
+
|
|
31
|
+
NO WARRANTY
|
|
32
|
+
|
|
33
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
34
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
35
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
36
|
+
FORMKIT INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
37
|
+
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
38
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
39
|
+
|
|
40
|
+
GOVERNING LAW
|
|
41
|
+
|
|
42
|
+
This license shall be governed by and construed in accordance with the laws
|
|
43
|
+
of the jurisdiction in which FormKit Inc. is incorporated, without regard to
|
|
44
|
+
its conflict of law provisions.
|
|
45
|
+
|
|
46
|
+
FormKit Inc.
|
|
47
|
+
https://formkit.com
|
|
48
|
+
enterprise@formkit.com
|
package/README.md
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
1
|
# @standardagents/anthropic
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Anthropic (Claude) provider for [Standard Agents](https://standardagentbuilder.com). Wraps the official `@anthropic-ai/sdk` and translates between the Standard Agents provider spec and the Anthropic Messages API.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Streaming and non-streaming generation through the Messages API
|
|
8
|
+
- Tool use with parallel tool results and image tool outputs
|
|
9
|
+
- Extended thinking across model generations: adaptive thinking + effort on Claude 4.6+, token budgets on Claude 4.0-4.5, with thinking blocks (text + signature) round-tripped exactly on multi-turn conversations
|
|
10
|
+
- Anthropic server-side `web_search` tool exposed as a provider tool
|
|
11
|
+
- Vision (images), PDF and plain-text document inputs
|
|
12
|
+
- Structured outputs via `output_config.format` for JSON schema response formats
|
|
13
|
+
- Prompt caching opt-in for the system prompt (`providerOptions.cacheSystemPrompt`)
|
|
14
|
+
- Live model listing and per-model capability detection via the Anthropic Models API
|
|
15
|
+
- Usage normalization (prompt/completion/cached/reasoning tokens) plus exact per-request cost derived from raw billing buckets (cache writes at 1.25x/2x, cache reads at 0.1x) for documented Claude models
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { defineModel } from '@standardagents/spec';
|
|
21
|
+
import { anthropic } from '@standardagents/anthropic';
|
|
22
|
+
|
|
23
|
+
export default defineModel({
|
|
24
|
+
name: 'claude-opus',
|
|
25
|
+
provider: anthropic,
|
|
26
|
+
model: 'claude-opus-4-8',
|
|
27
|
+
inputPrice: 5,
|
|
28
|
+
outputPrice: 25,
|
|
29
|
+
providerOptions: {
|
|
30
|
+
cacheSystemPrompt: true,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Set `ANTHROPIC_API_KEY` in your environment.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { LLMProviderInterface, ProviderFactoryConfig, ModelCapabilities, ToolDefinition, ToolArgs, ToolTenvs, ProviderModelInfo, ProviderRequest, ProviderResponse, ProviderStreamChunk, InspectedRequest, ProviderFactoryWithOptions } from '@standardagents/spec';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Anthropic provider options schema.
|
|
7
|
+
*
|
|
8
|
+
* Defines typed providerOptions for Anthropic (Claude) models, providing
|
|
9
|
+
* TypeScript autocompletion and runtime validation.
|
|
10
|
+
*
|
|
11
|
+
* @see https://platform.claude.com/docs/en/api/messages
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Anthropic provider options schema.
|
|
17
|
+
*
|
|
18
|
+
* These options are passed directly to the Anthropic Messages API and control
|
|
19
|
+
* various aspects of request handling and generation.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* providerOptions: {
|
|
24
|
+
* service_tier: 'auto',
|
|
25
|
+
* metadata: { user_id: 'user-123' },
|
|
26
|
+
* cacheSystemPrompt: true,
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare const anthropicProviderOptions: z.ZodObject<{
|
|
31
|
+
service_tier: z.ZodOptional<z.ZodEnum<{
|
|
32
|
+
auto: "auto";
|
|
33
|
+
standard_only: "standard_only";
|
|
34
|
+
}>>;
|
|
35
|
+
metadata: z.ZodOptional<z.ZodObject<{
|
|
36
|
+
user_id: z.ZodOptional<z.ZodString>;
|
|
37
|
+
}, z.core.$strip>>;
|
|
38
|
+
cacheSystemPrompt: z.ZodOptional<z.ZodBoolean>;
|
|
39
|
+
thinking: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
40
|
+
}, z.core.$loose>;
|
|
41
|
+
/**
|
|
42
|
+
* TypeScript type for Anthropic provider options.
|
|
43
|
+
* Inferred from the Zod schema for type-safe usage.
|
|
44
|
+
*/
|
|
45
|
+
type AnthropicProviderOptions = z.infer<typeof anthropicProviderOptions>;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Known Anthropic model pricing for request cost calculation.
|
|
49
|
+
*
|
|
50
|
+
* The Anthropic Messages API reports token usage (including cache buckets)
|
|
51
|
+
* but no dollar cost, and the Models API exposes no pricing data — so cost
|
|
52
|
+
* is derived here from the raw usage buckets and a maintained price table.
|
|
53
|
+
* This is more accurate than a flat promptTokens * inputPrice calculation
|
|
54
|
+
* because Anthropic bills the prompt in three differently-priced buckets:
|
|
55
|
+
*
|
|
56
|
+
* - uncached input tokens: base input rate
|
|
57
|
+
* - cache writes: 1.25x input (5-minute TTL) or 2x input (1-hour TTL)
|
|
58
|
+
* - cache reads: 0.1x input
|
|
59
|
+
*
|
|
60
|
+
* Thinking tokens are billed as ordinary output tokens (already included in
|
|
61
|
+
* output_tokens), so no separate reasoning rate applies.
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
type AnthropicUsage = Anthropic.Messages.Usage;
|
|
65
|
+
interface AnthropicModelPricing {
|
|
66
|
+
/** USD per million input tokens */
|
|
67
|
+
inputPerMillion: number;
|
|
68
|
+
/** USD per million output tokens (includes thinking tokens) */
|
|
69
|
+
outputPerMillion: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Look up pricing for a model ID via longest-prefix match.
|
|
73
|
+
* Returns null for unknown models so callers fall back to model-defined
|
|
74
|
+
* inputPrice/outputPrice rather than guessing.
|
|
75
|
+
*/
|
|
76
|
+
declare function getAnthropicModelPricing(modelId: string | null | undefined): AnthropicModelPricing | null;
|
|
77
|
+
/**
|
|
78
|
+
* Token buckets needed for exact cost calculation. Mirrors the relevant
|
|
79
|
+
* subset of the API's usage object so stream state can reuse this shape.
|
|
80
|
+
*/
|
|
81
|
+
interface AnthropicUsageBuckets {
|
|
82
|
+
inputTokens: number;
|
|
83
|
+
outputTokens: number;
|
|
84
|
+
cacheReadTokens: number;
|
|
85
|
+
cacheWrite5mTokens: number;
|
|
86
|
+
cacheWrite1hTokens: number;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Extract billing buckets from an API usage object. When the per-TTL cache
|
|
90
|
+
* creation breakdown is absent, all cache writes are assumed 5-minute TTL
|
|
91
|
+
* (the API default and by far the most common case).
|
|
92
|
+
*/
|
|
93
|
+
declare function extractUsageBuckets(usage: AnthropicUsage): AnthropicUsageBuckets;
|
|
94
|
+
/**
|
|
95
|
+
* Calculate the exact USD cost of a request from its raw usage buckets.
|
|
96
|
+
* Returns undefined when the model has no known pricing, so the execution
|
|
97
|
+
* engine can fall back to model-configured prices.
|
|
98
|
+
*/
|
|
99
|
+
declare function calculateAnthropicUsageCost(modelId: string | null | undefined, buckets: AnthropicUsageBuckets): number | undefined;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Anthropic provider implementation for Standard Agents
|
|
103
|
+
*
|
|
104
|
+
* Uses the Messages API for all requests via the official @anthropic-ai/sdk.
|
|
105
|
+
* Supports the full Claude family: claude-fable-5, claude-opus-4-x,
|
|
106
|
+
* claude-sonnet-4-x, claude-haiku-4-5, claude-3-x, etc.
|
|
107
|
+
*/
|
|
108
|
+
declare class AnthropicProvider implements LLMProviderInterface {
|
|
109
|
+
readonly name = "anthropic";
|
|
110
|
+
readonly specificationVersion: "1";
|
|
111
|
+
private client;
|
|
112
|
+
private config;
|
|
113
|
+
/** Cache for models list to avoid repeated API calls */
|
|
114
|
+
private static modelsCache;
|
|
115
|
+
private static modelsCacheTime;
|
|
116
|
+
private static readonly CACHE_TTL;
|
|
117
|
+
constructor(config: ProviderFactoryConfig);
|
|
118
|
+
private getClient;
|
|
119
|
+
supportsModel(modelId: string): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Get the icon for this provider as a data URI.
|
|
122
|
+
* Always returns the Anthropic icon since all models are from Anthropic.
|
|
123
|
+
*/
|
|
124
|
+
getIcon(_modelId?: string): string;
|
|
125
|
+
/**
|
|
126
|
+
* Capability mappings for Anthropic models, keyed by model ID prefix.
|
|
127
|
+
* Used as a fallback when the live Models API is unavailable; the API's
|
|
128
|
+
* capability listing takes precedence when reachable.
|
|
129
|
+
*/
|
|
130
|
+
private static readonly MODEL_CAPABILITIES;
|
|
131
|
+
/**
|
|
132
|
+
* Look up static capabilities for a model by exact then prefix match.
|
|
133
|
+
*/
|
|
134
|
+
private static lookupStaticCapabilities;
|
|
135
|
+
/**
|
|
136
|
+
* Map a live Models API capability listing to Standard Agents capabilities.
|
|
137
|
+
*/
|
|
138
|
+
private static mapLiveCapabilities;
|
|
139
|
+
/**
|
|
140
|
+
* Get capabilities for a specific model.
|
|
141
|
+
* Prefers the live Models API (which reports per-model capability flags)
|
|
142
|
+
* and falls back to the static prefix table when the API is unreachable.
|
|
143
|
+
*/
|
|
144
|
+
getModelCapabilities(modelId: string): Promise<ModelCapabilities | null>;
|
|
145
|
+
/**
|
|
146
|
+
* Provider-embedded tools using defineTool().
|
|
147
|
+
* These are Anthropic's server-side tools that execute on Anthropic's
|
|
148
|
+
* servers. The execute function is a no-op since execution is handled by
|
|
149
|
+
* the provider; results surface as providerTools entries on the response.
|
|
150
|
+
*/
|
|
151
|
+
private static readonly TOOLS;
|
|
152
|
+
/**
|
|
153
|
+
* Get tools embedded in this provider.
|
|
154
|
+
* Anthropic's web_search server tool is available on all current models.
|
|
155
|
+
*
|
|
156
|
+
* @param modelId - Optional filter to get tools available for a specific model
|
|
157
|
+
* @returns Record of tool name to tool definition
|
|
158
|
+
*/
|
|
159
|
+
getTools(_modelId?: string): Record<string, ToolDefinition<any, ToolArgs | null, ToolTenvs | null>>;
|
|
160
|
+
/**
|
|
161
|
+
* Fetch models from the Anthropic Models API with caching.
|
|
162
|
+
*/
|
|
163
|
+
private fetchModelsWithCache;
|
|
164
|
+
/**
|
|
165
|
+
* Map Anthropic model info to ProviderModelInfo.
|
|
166
|
+
*/
|
|
167
|
+
private mapToProviderModelInfo;
|
|
168
|
+
/**
|
|
169
|
+
* Get list of available models from Anthropic.
|
|
170
|
+
* Fetches from the Models API with caching.
|
|
171
|
+
*
|
|
172
|
+
* @param filter - Optional search string to filter models by name/id
|
|
173
|
+
*/
|
|
174
|
+
getModels(filter?: string): Promise<ProviderModelInfo[]>;
|
|
175
|
+
/**
|
|
176
|
+
* Resolve the default max_tokens for a model from the static capability
|
|
177
|
+
* table, clamped so non-streaming requests stay under HTTP timeouts.
|
|
178
|
+
*/
|
|
179
|
+
private defaultMaxTokensFor;
|
|
180
|
+
generate(request: ProviderRequest): Promise<ProviderResponse>;
|
|
181
|
+
stream(request: ProviderRequest): Promise<AsyncIterable<ProviderStreamChunk>>;
|
|
182
|
+
private toProviderError;
|
|
183
|
+
/**
|
|
184
|
+
* Transform a ProviderRequest to Anthropic Messages API format for inspection.
|
|
185
|
+
* Returns the exact request body that would be sent, with base64 data truncated.
|
|
186
|
+
*/
|
|
187
|
+
inspectRequest(request: ProviderRequest): Promise<InspectedRequest>;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Anthropic (Claude) provider factory for Standard Agents
|
|
192
|
+
*
|
|
193
|
+
* Includes typed providerOptions for Anthropic-specific configuration.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* import { defineModel } from '@standardagents/builder';
|
|
198
|
+
* import { anthropic } from '@standardagents/anthropic';
|
|
199
|
+
*
|
|
200
|
+
* export default defineModel({
|
|
201
|
+
* name: 'claude-opus',
|
|
202
|
+
* provider: anthropic,
|
|
203
|
+
* model: 'claude-opus-4-8',
|
|
204
|
+
* inputPrice: 5,
|
|
205
|
+
* outputPrice: 25,
|
|
206
|
+
* capabilities: {
|
|
207
|
+
* supportsImages: true,
|
|
208
|
+
* supportsToolCalls: true,
|
|
209
|
+
* supportsJsonMode: true,
|
|
210
|
+
* maxContextTokens: 1000000,
|
|
211
|
+
* },
|
|
212
|
+
* providerOptions: {
|
|
213
|
+
* cacheSystemPrompt: true,
|
|
214
|
+
* },
|
|
215
|
+
* });
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
declare const anthropic: ProviderFactoryWithOptions<typeof anthropicProviderOptions>;
|
|
219
|
+
|
|
220
|
+
export { type AnthropicModelPricing, AnthropicProvider, type AnthropicProviderOptions, type AnthropicUsageBuckets, anthropic, anthropicProviderOptions, calculateAnthropicUsageCost, extractUsageBuckets, getAnthropicModelPricing };
|