@providerprotocol/ai 0.0.20 → 0.0.21
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/anthropic/index.d.ts +184 -14
- package/dist/anthropic/index.js +210 -82
- package/dist/anthropic/index.js.map +1 -1
- package/dist/{chunk-U3FZWV4U.js → chunk-EDENPF3E.js} +5 -2
- package/dist/{chunk-U3FZWV4U.js.map → chunk-EDENPF3E.js.map} +1 -1
- package/dist/{chunk-UMKWXGO3.js → chunk-M4BMM5IB.js} +86 -2
- package/dist/chunk-M4BMM5IB.js.map +1 -0
- package/dist/{chunk-P5IRTEM5.js → chunk-Y3GBJNA2.js} +2 -2
- package/dist/{chunk-U4JJC2YX.js → chunk-Z4ILICF5.js} +2 -2
- package/dist/chunk-Z4ILICF5.js.map +1 -0
- package/dist/google/index.d.ts +16 -19
- package/dist/google/index.js +14 -36
- package/dist/google/index.js.map +1 -1
- package/dist/http/index.d.ts +2 -2
- package/dist/http/index.js +3 -3
- package/dist/index.d.ts +101 -38
- package/dist/index.js +69 -43
- package/dist/index.js.map +1 -1
- package/dist/ollama/index.d.ts +14 -16
- package/dist/ollama/index.js +5 -7
- package/dist/ollama/index.js.map +1 -1
- package/dist/openai/index.d.ts +25 -133
- package/dist/openai/index.js +27 -81
- package/dist/openai/index.js.map +1 -1
- package/dist/openrouter/index.d.ts +28 -53
- package/dist/openrouter/index.js +20 -43
- package/dist/openrouter/index.js.map +1 -1
- package/dist/provider-DGQHYE6I.d.ts +1319 -0
- package/dist/proxy/index.d.ts +2 -3
- package/dist/proxy/index.js +5 -7
- package/dist/proxy/index.js.map +1 -1
- package/dist/{retry-DR7YRJDz.d.ts → retry-Pcs3hnbu.d.ts} +2 -2
- package/dist/{stream-DRHy6q1a.d.ts → stream-Di9acos2.d.ts} +1 -1
- package/dist/xai/index.d.ts +16 -88
- package/dist/xai/index.js +30 -58
- package/dist/xai/index.js.map +1 -1
- package/package.json +4 -1
- package/dist/chunk-MSR5P65T.js +0 -39
- package/dist/chunk-MSR5P65T.js.map +0 -1
- package/dist/chunk-U4JJC2YX.js.map +0 -1
- package/dist/chunk-UMKWXGO3.js.map +0 -1
- package/dist/content-DEl3z_W2.d.ts +0 -276
- package/dist/image-Dhq-Yuq4.d.ts +0 -456
- package/dist/provider-BBMBZuGn.d.ts +0 -570
- /package/dist/{chunk-P5IRTEM5.js.map → chunk-Y3GBJNA2.js.map} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { g as Provider } from '../provider-DGQHYE6I.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @fileoverview Anthropic API type definitions.
|
|
@@ -6,6 +6,83 @@ import { d as Provider } from '../provider-BBMBZuGn.js';
|
|
|
6
6
|
* Contains TypeScript interfaces for Anthropic's Messages API request/response
|
|
7
7
|
* structures, streaming events, and provider-specific parameters.
|
|
8
8
|
*/
|
|
9
|
+
/**
|
|
10
|
+
* Known Anthropic beta header values.
|
|
11
|
+
*
|
|
12
|
+
* Beta features are enabled by passing these values in the `betas` config option
|
|
13
|
+
* or via the `anthropic-beta` HTTP header. Multiple betas can be enabled simultaneously.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { anthropic, betas } from 'provider-protocol/anthropic';
|
|
18
|
+
*
|
|
19
|
+
* // Using the betas config option (recommended)
|
|
20
|
+
* const provider = anthropic('claude-sonnet-4-20250514', {
|
|
21
|
+
* betas: [betas.structuredOutputs, betas.interleavedThinking],
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // Or use string values directly for new/unlisted betas
|
|
25
|
+
* const provider = anthropic('claude-sonnet-4-20250514', {
|
|
26
|
+
* betas: ['new-beta-2025-12-01'],
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare const betas: {
|
|
31
|
+
/** Guaranteed JSON schema conformance for responses. Available for Claude Sonnet 4.5+. */
|
|
32
|
+
readonly structuredOutputs: "structured-outputs-2025-11-13";
|
|
33
|
+
/** Enables Claude to think between tool calls in Claude 4 models. */
|
|
34
|
+
readonly interleavedThinking: "interleaved-thinking-2025-05-14";
|
|
35
|
+
/** Developer mode for full thinking output visibility. */
|
|
36
|
+
readonly devFullThinking: "dev-full-thinking-2025-05-14";
|
|
37
|
+
/** Effort parameter for Claude Opus 4.5 - controls response thoroughness vs efficiency. */
|
|
38
|
+
readonly effort: "effort-2025-11-24";
|
|
39
|
+
/** Legacy computer use tool (Claude 3.x models). */
|
|
40
|
+
readonly computerUseLegacy: "computer-use-2024-10-22";
|
|
41
|
+
/** Computer use tool for Claude 4 models (mouse, keyboard, screenshots). */
|
|
42
|
+
readonly computerUse: "computer-use-2025-01-24";
|
|
43
|
+
/** Computer use tool for Claude Opus 4.5 with additional commands. */
|
|
44
|
+
readonly computerUseOpus: "computer-use-2025-11-24";
|
|
45
|
+
/** Enables up to 8,192 output tokens from Claude Sonnet 3.5. */
|
|
46
|
+
readonly maxTokens35Sonnet: "max-tokens-3-5-sonnet-2024-07-15";
|
|
47
|
+
/** Enables 128K token output length. */
|
|
48
|
+
readonly output128k: "output-128k-2025-02-19";
|
|
49
|
+
/** Enables 1 million token context window for Claude Sonnet 4. */
|
|
50
|
+
readonly context1m: "context-1m-2025-08-07";
|
|
51
|
+
/** Reduces output token consumption by up to 70% for tool calls. */
|
|
52
|
+
readonly tokenEfficientTools: "token-efficient-tools-2025-02-19";
|
|
53
|
+
/** Streams tool use parameters without buffering/JSON validation. */
|
|
54
|
+
readonly fineGrainedToolStreaming: "fine-grained-tool-streaming-2025-05-14";
|
|
55
|
+
/** Code execution tool for running Python/Bash in secure sandbox. */
|
|
56
|
+
readonly codeExecution: "code-execution-2025-08-25";
|
|
57
|
+
/** Advanced tool use: Tool Search, Programmatic Tool Calling, Tool Use Examples. */
|
|
58
|
+
readonly advancedToolUse: "advanced-tool-use-2025-11-20";
|
|
59
|
+
/** Files API for uploading and managing files. */
|
|
60
|
+
readonly filesApi: "files-api-2025-04-14";
|
|
61
|
+
/** PDF document support. */
|
|
62
|
+
readonly pdfs: "pdfs-2024-09-25";
|
|
63
|
+
/** MCP connector to connect to remote MCP servers. */
|
|
64
|
+
readonly mcpClient: "mcp-client-2025-04-04";
|
|
65
|
+
/** Updated MCP client. */
|
|
66
|
+
readonly mcpClientLatest: "mcp-client-2025-11-20";
|
|
67
|
+
/** Prompt caching for reduced latency and costs. Now works automatically with cache_control. */
|
|
68
|
+
readonly promptCaching: "prompt-caching-2024-07-31";
|
|
69
|
+
/** Enables 1-hour cache TTL (vs default 5-minute). */
|
|
70
|
+
readonly extendedCacheTtl: "extended-cache-ttl-2025-04-11";
|
|
71
|
+
/** Automatic tool call clearing for context management. */
|
|
72
|
+
readonly contextManagement: "context-management-2025-06-27";
|
|
73
|
+
/** Handling for when model context window is exceeded. */
|
|
74
|
+
readonly modelContextWindowExceeded: "model-context-window-exceeded-2025-08-26";
|
|
75
|
+
/** Message Batches API for async processing at 50% cost. */
|
|
76
|
+
readonly messageBatches: "message-batches-2024-09-24";
|
|
77
|
+
/** Token counting endpoint. */
|
|
78
|
+
readonly tokenCounting: "token-counting-2024-11-01";
|
|
79
|
+
/** Agent Skills for specialized tasks (PowerPoint, Excel, Word, PDF). */
|
|
80
|
+
readonly skills: "skills-2025-10-02";
|
|
81
|
+
};
|
|
82
|
+
/** Type representing any valid beta key from the betas object. */
|
|
83
|
+
type BetaKey = keyof typeof betas;
|
|
84
|
+
/** Type representing a beta value (either a known constant or arbitrary string). */
|
|
85
|
+
type BetaValue = (typeof betas)[BetaKey] | string;
|
|
9
86
|
/**
|
|
10
87
|
* Provider-specific parameters for Anthropic Claude models.
|
|
11
88
|
*
|
|
@@ -68,7 +145,7 @@ interface AnthropicLLMParams {
|
|
|
68
145
|
* const model = llm({
|
|
69
146
|
* model: anthropic('claude-sonnet-4-20250514'),
|
|
70
147
|
* params: {
|
|
71
|
-
*
|
|
148
|
+
* tools: [
|
|
72
149
|
* tools.webSearch({ max_uses: 5 }),
|
|
73
150
|
* tools.codeExecution(),
|
|
74
151
|
* ],
|
|
@@ -76,13 +153,56 @@ interface AnthropicLLMParams {
|
|
|
76
153
|
* });
|
|
77
154
|
* ```
|
|
78
155
|
*/
|
|
79
|
-
|
|
156
|
+
tools?: AnthropicBuiltInTool[];
|
|
80
157
|
/**
|
|
81
158
|
* Container ID for code execution tool reuse.
|
|
82
159
|
* Pass the container ID from a previous response to reuse the same environment.
|
|
83
160
|
*/
|
|
84
161
|
container?: string;
|
|
85
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Request body structure for Anthropic's Messages API.
|
|
165
|
+
*
|
|
166
|
+
* This interface represents the full request payload sent to the
|
|
167
|
+
* `/v1/messages` endpoint.
|
|
168
|
+
*/
|
|
169
|
+
/**
|
|
170
|
+
* Native structured output format configuration.
|
|
171
|
+
*
|
|
172
|
+
* When provided, Claude's response will be constrained to match the
|
|
173
|
+
* specified JSON schema. Requires the beta header `structured-outputs-2025-11-13`.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* const outputFormat: AnthropicOutputFormat = {
|
|
178
|
+
* type: 'json_schema',
|
|
179
|
+
* schema: {
|
|
180
|
+
* type: 'object',
|
|
181
|
+
* properties: {
|
|
182
|
+
* name: { type: 'string' },
|
|
183
|
+
* age: { type: 'integer' },
|
|
184
|
+
* },
|
|
185
|
+
* required: ['name', 'age'],
|
|
186
|
+
* additionalProperties: false,
|
|
187
|
+
* },
|
|
188
|
+
* };
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
interface AnthropicOutputFormat {
|
|
192
|
+
/** Output format type - currently only 'json_schema' is supported. */
|
|
193
|
+
type: 'json_schema';
|
|
194
|
+
/** JSON Schema defining the expected response structure. */
|
|
195
|
+
schema: {
|
|
196
|
+
/** Schema type (always 'object' for structured outputs). */
|
|
197
|
+
type: 'object';
|
|
198
|
+
/** Property definitions for each field. */
|
|
199
|
+
properties: Record<string, unknown>;
|
|
200
|
+
/** List of required property names. */
|
|
201
|
+
required?: string[];
|
|
202
|
+
/** Must be false for structured outputs. */
|
|
203
|
+
additionalProperties?: false;
|
|
204
|
+
};
|
|
205
|
+
}
|
|
86
206
|
/**
|
|
87
207
|
* Anthropic-specific HTTP headers for API requests.
|
|
88
208
|
*
|
|
@@ -454,7 +574,7 @@ declare function toolSearchTool(options?: {
|
|
|
454
574
|
* const model = llm({
|
|
455
575
|
* model: anthropic('claude-sonnet-4-20250514'),
|
|
456
576
|
* params: {
|
|
457
|
-
*
|
|
577
|
+
* tools: [
|
|
458
578
|
* tools.webSearch({ max_uses: 5 }),
|
|
459
579
|
* tools.codeExecution(),
|
|
460
580
|
* ],
|
|
@@ -478,25 +598,75 @@ declare const tools: {
|
|
|
478
598
|
};
|
|
479
599
|
|
|
480
600
|
/**
|
|
481
|
-
*
|
|
601
|
+
* Options for configuring an Anthropic model reference.
|
|
602
|
+
*
|
|
603
|
+
* @example
|
|
604
|
+
* ```typescript
|
|
605
|
+
* import { anthropic, betas } from 'provider-protocol/anthropic';
|
|
606
|
+
*
|
|
607
|
+
* // Enable structured outputs beta
|
|
608
|
+
* const model = anthropic('claude-sonnet-4-20250514', {
|
|
609
|
+
* betas: [betas.structuredOutputs],
|
|
610
|
+
* });
|
|
611
|
+
*
|
|
612
|
+
* // Enable multiple betas
|
|
613
|
+
* const modelWithBetas = anthropic('claude-sonnet-4-20250514', {
|
|
614
|
+
* betas: [betas.structuredOutputs, betas.interleavedThinking],
|
|
615
|
+
* });
|
|
616
|
+
*
|
|
617
|
+
* // Use string values for new/unlisted betas
|
|
618
|
+
* const modelWithCustomBeta = anthropic('claude-sonnet-4-20250514', {
|
|
619
|
+
* betas: ['new-beta-2025-12-01'],
|
|
620
|
+
* });
|
|
621
|
+
* ```
|
|
622
|
+
*/
|
|
623
|
+
interface AnthropicModelOptions {
|
|
624
|
+
/**
|
|
625
|
+
* Beta features to enable for this model.
|
|
626
|
+
*
|
|
627
|
+
* Use values from the `betas` export or pass arbitrary strings for new betas.
|
|
628
|
+
* Multiple betas are combined into a comma-separated `anthropic-beta` header.
|
|
629
|
+
*/
|
|
630
|
+
betas?: BetaValue[];
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Anthropic provider for the Universal Provider Protocol.
|
|
482
634
|
*
|
|
483
635
|
* Provides access to Claude language models through a unified interface.
|
|
484
|
-
*
|
|
485
|
-
*
|
|
636
|
+
* Supports LLM modality with streaming, tool use, structured output,
|
|
637
|
+
* and image input capabilities.
|
|
638
|
+
*
|
|
639
|
+
* @param modelId - The model identifier (e.g., 'claude-sonnet-4-20250514')
|
|
640
|
+
* @param options - Optional configuration including beta features
|
|
641
|
+
* @returns A model reference for use with `llm()`
|
|
486
642
|
*
|
|
487
643
|
* @example
|
|
488
644
|
* ```typescript
|
|
489
|
-
* import { anthropic } from '
|
|
645
|
+
* import { anthropic, betas } from 'provider-protocol/anthropic';
|
|
646
|
+
* import { llm } from 'provider-protocol';
|
|
647
|
+
*
|
|
648
|
+
* // Basic usage
|
|
649
|
+
* const model = llm({ model: anthropic('claude-sonnet-4-20250514') });
|
|
650
|
+
*
|
|
651
|
+
* // With structured outputs beta
|
|
652
|
+
* const modelWithBetas = llm({
|
|
653
|
+
* model: anthropic('claude-sonnet-4-20250514', {
|
|
654
|
+
* betas: [betas.structuredOutputs],
|
|
655
|
+
* }),
|
|
656
|
+
* structure: { properties: { name: { type: 'string' } } },
|
|
657
|
+
* });
|
|
490
658
|
*
|
|
491
|
-
*
|
|
492
|
-
* const
|
|
493
|
-
*
|
|
494
|
-
*
|
|
659
|
+
* // With multiple betas
|
|
660
|
+
* const advancedModel = llm({
|
|
661
|
+
* model: anthropic('claude-sonnet-4-20250514', {
|
|
662
|
+
* betas: [betas.structuredOutputs, betas.tokenEfficientTools],
|
|
663
|
+
* }),
|
|
495
664
|
* });
|
|
496
665
|
* ```
|
|
497
666
|
*
|
|
667
|
+
* @see {@link betas} for available beta features
|
|
498
668
|
* @see {@link AnthropicLLMParams} for provider-specific parameters
|
|
499
669
|
*/
|
|
500
|
-
declare const anthropic: Provider<
|
|
670
|
+
declare const anthropic: Provider<AnthropicModelOptions>;
|
|
501
671
|
|
|
502
|
-
export { type AnthropicBashTool, type AnthropicBuiltInTool, type AnthropicCodeExecutionTool, type AnthropicComputerTool, type AnthropicHeaders, type AnthropicLLMParams, type AnthropicTextEditorTool, type AnthropicToolSearchTool, type AnthropicUserLocation, type AnthropicWebSearchTool, anthropic, tools };
|
|
672
|
+
export { type AnthropicBashTool, type AnthropicBuiltInTool, type AnthropicCodeExecutionTool, type AnthropicComputerTool, type AnthropicHeaders, type AnthropicLLMParams, type AnthropicModelOptions, type AnthropicOutputFormat, type AnthropicTextEditorTool, type AnthropicToolSearchTool, type AnthropicUserLocation, type AnthropicWebSearchTool, type BetaKey, type BetaValue, anthropic, betas, tools };
|
package/dist/anthropic/index.js
CHANGED
|
@@ -1,29 +1,151 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createProvider
|
|
3
|
-
} from "../chunk-MSR5P65T.js";
|
|
4
1
|
import {
|
|
5
2
|
AssistantMessage,
|
|
3
|
+
createProvider,
|
|
6
4
|
isAssistantMessage,
|
|
7
5
|
isToolResultMessage,
|
|
8
6
|
isUserMessage
|
|
9
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-M4BMM5IB.js";
|
|
10
8
|
import {
|
|
11
9
|
parseSSEStream
|
|
12
10
|
} from "../chunk-Z7RBRCRN.js";
|
|
13
11
|
import {
|
|
14
12
|
resolveApiKey
|
|
15
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-Y3GBJNA2.js";
|
|
16
14
|
import {
|
|
17
15
|
UPPError,
|
|
18
16
|
doFetch,
|
|
19
17
|
doStreamFetch,
|
|
20
18
|
normalizeHttpError
|
|
21
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-EDENPF3E.js";
|
|
20
|
+
|
|
21
|
+
// src/providers/anthropic/types.ts
|
|
22
|
+
var betas = {
|
|
23
|
+
// Structured Outputs
|
|
24
|
+
/** Guaranteed JSON schema conformance for responses. Available for Claude Sonnet 4.5+. */
|
|
25
|
+
structuredOutputs: "structured-outputs-2025-11-13",
|
|
26
|
+
// Extended Thinking / Reasoning
|
|
27
|
+
/** Enables Claude to think between tool calls in Claude 4 models. */
|
|
28
|
+
interleavedThinking: "interleaved-thinking-2025-05-14",
|
|
29
|
+
/** Developer mode for full thinking output visibility. */
|
|
30
|
+
devFullThinking: "dev-full-thinking-2025-05-14",
|
|
31
|
+
/** Effort parameter for Claude Opus 4.5 - controls response thoroughness vs efficiency. */
|
|
32
|
+
effort: "effort-2025-11-24",
|
|
33
|
+
// Computer Use
|
|
34
|
+
/** Legacy computer use tool (Claude 3.x models). */
|
|
35
|
+
computerUseLegacy: "computer-use-2024-10-22",
|
|
36
|
+
/** Computer use tool for Claude 4 models (mouse, keyboard, screenshots). */
|
|
37
|
+
computerUse: "computer-use-2025-01-24",
|
|
38
|
+
/** Computer use tool for Claude Opus 4.5 with additional commands. */
|
|
39
|
+
computerUseOpus: "computer-use-2025-11-24",
|
|
40
|
+
// Extended Output / Context
|
|
41
|
+
/** Enables up to 8,192 output tokens from Claude Sonnet 3.5. */
|
|
42
|
+
maxTokens35Sonnet: "max-tokens-3-5-sonnet-2024-07-15",
|
|
43
|
+
/** Enables 128K token output length. */
|
|
44
|
+
output128k: "output-128k-2025-02-19",
|
|
45
|
+
/** Enables 1 million token context window for Claude Sonnet 4. */
|
|
46
|
+
context1m: "context-1m-2025-08-07",
|
|
47
|
+
// Token Efficiency
|
|
48
|
+
/** Reduces output token consumption by up to 70% for tool calls. */
|
|
49
|
+
tokenEfficientTools: "token-efficient-tools-2025-02-19",
|
|
50
|
+
/** Streams tool use parameters without buffering/JSON validation. */
|
|
51
|
+
fineGrainedToolStreaming: "fine-grained-tool-streaming-2025-05-14",
|
|
52
|
+
// Code Execution
|
|
53
|
+
/** Code execution tool for running Python/Bash in secure sandbox. */
|
|
54
|
+
codeExecution: "code-execution-2025-08-25",
|
|
55
|
+
// Advanced Tool Use
|
|
56
|
+
/** Advanced tool use: Tool Search, Programmatic Tool Calling, Tool Use Examples. */
|
|
57
|
+
advancedToolUse: "advanced-tool-use-2025-11-20",
|
|
58
|
+
// Files & Documents
|
|
59
|
+
/** Files API for uploading and managing files. */
|
|
60
|
+
filesApi: "files-api-2025-04-14",
|
|
61
|
+
/** PDF document support. */
|
|
62
|
+
pdfs: "pdfs-2024-09-25",
|
|
63
|
+
// MCP (Model Context Protocol)
|
|
64
|
+
/** MCP connector to connect to remote MCP servers. */
|
|
65
|
+
mcpClient: "mcp-client-2025-04-04",
|
|
66
|
+
/** Updated MCP client. */
|
|
67
|
+
mcpClientLatest: "mcp-client-2025-11-20",
|
|
68
|
+
// Caching
|
|
69
|
+
/** Prompt caching for reduced latency and costs. Now works automatically with cache_control. */
|
|
70
|
+
promptCaching: "prompt-caching-2024-07-31",
|
|
71
|
+
/** Enables 1-hour cache TTL (vs default 5-minute). */
|
|
72
|
+
extendedCacheTtl: "extended-cache-ttl-2025-04-11",
|
|
73
|
+
// Context Management
|
|
74
|
+
/** Automatic tool call clearing for context management. */
|
|
75
|
+
contextManagement: "context-management-2025-06-27",
|
|
76
|
+
/** Handling for when model context window is exceeded. */
|
|
77
|
+
modelContextWindowExceeded: "model-context-window-exceeded-2025-08-26",
|
|
78
|
+
// Message Batches (generally available but may still need header)
|
|
79
|
+
/** Message Batches API for async processing at 50% cost. */
|
|
80
|
+
messageBatches: "message-batches-2024-09-24",
|
|
81
|
+
// Token Counting (generally available)
|
|
82
|
+
/** Token counting endpoint. */
|
|
83
|
+
tokenCounting: "token-counting-2024-11-01",
|
|
84
|
+
// Skills
|
|
85
|
+
/** Agent Skills for specialized tasks (PowerPoint, Excel, Word, PDF). */
|
|
86
|
+
skills: "skills-2025-10-02"
|
|
87
|
+
};
|
|
88
|
+
function webSearchTool(options) {
|
|
89
|
+
return {
|
|
90
|
+
type: "web_search_20250305",
|
|
91
|
+
name: "web_search",
|
|
92
|
+
...options
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function computerTool(options) {
|
|
96
|
+
const { version = "20250124", ...rest } = options;
|
|
97
|
+
return {
|
|
98
|
+
type: version === "20251124" ? "computer_20251124" : "computer_20250124",
|
|
99
|
+
name: "computer",
|
|
100
|
+
...rest
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function textEditorTool(options) {
|
|
104
|
+
const version = options?.version ?? "20250728";
|
|
105
|
+
return {
|
|
106
|
+
type: version === "20250728" ? "text_editor_20250728" : "text_editor_20250124",
|
|
107
|
+
name: version === "20250728" ? "str_replace_based_edit_tool" : "str_replace_editor",
|
|
108
|
+
...options?.max_characters !== void 0 && { max_characters: options.max_characters }
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function bashTool() {
|
|
112
|
+
return {
|
|
113
|
+
type: "bash_20250124",
|
|
114
|
+
name: "bash"
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function codeExecutionTool() {
|
|
118
|
+
return {
|
|
119
|
+
type: "code_execution_20250825",
|
|
120
|
+
name: "code_execution"
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function toolSearchTool(options) {
|
|
124
|
+
const mode = options?.mode ?? "regex";
|
|
125
|
+
return {
|
|
126
|
+
type: mode === "regex" ? "tool_search_tool_regex_20251119" : "tool_search_tool_bm25_20251119",
|
|
127
|
+
name: mode === "regex" ? "tool_search_tool_regex" : "tool_search_tool_bm25"
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
var tools = {
|
|
131
|
+
/** Creates a web search tool configuration */
|
|
132
|
+
webSearch: webSearchTool,
|
|
133
|
+
/** Creates a computer use tool configuration */
|
|
134
|
+
computer: computerTool,
|
|
135
|
+
/** Creates a text editor tool configuration */
|
|
136
|
+
textEditor: textEditorTool,
|
|
137
|
+
/** Creates a bash tool configuration */
|
|
138
|
+
bash: bashTool,
|
|
139
|
+
/** Creates a code execution tool configuration */
|
|
140
|
+
codeExecution: codeExecutionTool,
|
|
141
|
+
/** Creates a tool search tool configuration */
|
|
142
|
+
toolSearch: toolSearchTool
|
|
143
|
+
};
|
|
22
144
|
|
|
23
145
|
// src/providers/anthropic/transform.ts
|
|
24
|
-
function transformRequest(request, modelId) {
|
|
146
|
+
function transformRequest(request, modelId, useNativeStructuredOutput = false) {
|
|
25
147
|
const params = request.params ?? {};
|
|
26
|
-
const { builtInTools, ...restParams } = params;
|
|
148
|
+
const { tools: builtInTools, ...restParams } = params;
|
|
27
149
|
const anthropicRequest = {
|
|
28
150
|
...restParams,
|
|
29
151
|
model: modelId,
|
|
@@ -44,17 +166,30 @@ function transformRequest(request, modelId) {
|
|
|
44
166
|
anthropicRequest.tool_choice = { type: "auto" };
|
|
45
167
|
}
|
|
46
168
|
if (request.structure) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
169
|
+
if (useNativeStructuredOutput) {
|
|
170
|
+
const outputFormat = {
|
|
171
|
+
type: "json_schema",
|
|
172
|
+
schema: {
|
|
173
|
+
type: "object",
|
|
174
|
+
properties: request.structure.properties,
|
|
175
|
+
required: request.structure.required,
|
|
176
|
+
additionalProperties: false
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
anthropicRequest.output_format = outputFormat;
|
|
180
|
+
} else {
|
|
181
|
+
const structuredTool = {
|
|
182
|
+
name: "json_response",
|
|
183
|
+
description: "Return the response in the specified JSON format. You MUST use this tool to provide your response.",
|
|
184
|
+
input_schema: {
|
|
185
|
+
type: "object",
|
|
186
|
+
properties: request.structure.properties,
|
|
187
|
+
required: request.structure.required
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
anthropicRequest.tools = [...anthropicRequest.tools ?? [], structuredTool];
|
|
191
|
+
anthropicRequest.tool_choice = { type: "tool", name: "json_response" };
|
|
192
|
+
}
|
|
58
193
|
}
|
|
59
194
|
return anthropicRequest;
|
|
60
195
|
}
|
|
@@ -182,13 +317,19 @@ function transformTool(tool) {
|
|
|
182
317
|
...cacheControl ? { cache_control: cacheControl } : {}
|
|
183
318
|
};
|
|
184
319
|
}
|
|
185
|
-
function transformResponse(data) {
|
|
320
|
+
function transformResponse(data, useNativeStructuredOutput = false) {
|
|
186
321
|
const textContent = [];
|
|
187
322
|
const toolCalls = [];
|
|
188
323
|
let structuredData;
|
|
189
324
|
for (const block of data.content) {
|
|
190
325
|
if (block.type === "text") {
|
|
191
326
|
textContent.push({ type: "text", text: block.text });
|
|
327
|
+
if (useNativeStructuredOutput && structuredData === void 0) {
|
|
328
|
+
try {
|
|
329
|
+
structuredData = JSON.parse(block.text);
|
|
330
|
+
} catch {
|
|
331
|
+
}
|
|
332
|
+
}
|
|
192
333
|
} else if (block.type === "tool_use") {
|
|
193
334
|
if (block.name === "json_response") {
|
|
194
335
|
structuredData = block.input;
|
|
@@ -346,7 +487,7 @@ function transformStreamEvent(event, state) {
|
|
|
346
487
|
return null;
|
|
347
488
|
}
|
|
348
489
|
}
|
|
349
|
-
function buildResponseFromState(state) {
|
|
490
|
+
function buildResponseFromState(state, useNativeStructuredOutput = false) {
|
|
350
491
|
const textContent = [];
|
|
351
492
|
const toolCalls = [];
|
|
352
493
|
let structuredData;
|
|
@@ -354,6 +495,12 @@ function buildResponseFromState(state) {
|
|
|
354
495
|
if (!block) continue;
|
|
355
496
|
if (block.type === "text" && block.text) {
|
|
356
497
|
textContent.push({ type: "text", text: block.text });
|
|
498
|
+
if (useNativeStructuredOutput && structuredData === void 0) {
|
|
499
|
+
try {
|
|
500
|
+
structuredData = JSON.parse(block.text);
|
|
501
|
+
} catch {
|
|
502
|
+
}
|
|
503
|
+
}
|
|
357
504
|
} else if (block.type === "tool_use" && block.id && block.name) {
|
|
358
505
|
let args = {};
|
|
359
506
|
if (block.input) {
|
|
@@ -411,6 +558,16 @@ ${block.fileContent}\`\`\`
|
|
|
411
558
|
}
|
|
412
559
|
|
|
413
560
|
// src/providers/anthropic/llm.ts
|
|
561
|
+
function shouldUseNativeStructuredOutput(config, structure) {
|
|
562
|
+
if (!structure) {
|
|
563
|
+
return false;
|
|
564
|
+
}
|
|
565
|
+
const betaHeader = config.headers?.["anthropic-beta"];
|
|
566
|
+
if (!betaHeader) {
|
|
567
|
+
return false;
|
|
568
|
+
}
|
|
569
|
+
return betaHeader.includes(betas.structuredOutputs);
|
|
570
|
+
}
|
|
414
571
|
var ANTHROPIC_API_URL = "https://api.anthropic.com/v1/messages";
|
|
415
572
|
var ANTHROPIC_VERSION = "2023-06-01";
|
|
416
573
|
var ANTHROPIC_CAPABILITIES = {
|
|
@@ -449,8 +606,12 @@ function createLLMHandler() {
|
|
|
449
606
|
"anthropic",
|
|
450
607
|
"llm"
|
|
451
608
|
);
|
|
609
|
+
const useNativeStructuredOutput = shouldUseNativeStructuredOutput(
|
|
610
|
+
request.config,
|
|
611
|
+
request.structure
|
|
612
|
+
);
|
|
452
613
|
const baseUrl = request.config.baseUrl ?? ANTHROPIC_API_URL;
|
|
453
|
-
const body = transformRequest(request, modelId);
|
|
614
|
+
const body = transformRequest(request, modelId, useNativeStructuredOutput);
|
|
454
615
|
const headers = {
|
|
455
616
|
"Content-Type": "application/json",
|
|
456
617
|
"x-api-key": apiKey,
|
|
@@ -476,10 +637,14 @@ function createLLMHandler() {
|
|
|
476
637
|
"llm"
|
|
477
638
|
);
|
|
478
639
|
const data = await response.json();
|
|
479
|
-
return transformResponse(data);
|
|
640
|
+
return transformResponse(data, useNativeStructuredOutput);
|
|
480
641
|
},
|
|
481
642
|
stream(request) {
|
|
482
643
|
const state = createStreamState();
|
|
644
|
+
const useNativeStructuredOutput = shouldUseNativeStructuredOutput(
|
|
645
|
+
request.config,
|
|
646
|
+
request.structure
|
|
647
|
+
);
|
|
483
648
|
let responseResolve;
|
|
484
649
|
let responseReject;
|
|
485
650
|
const responsePromise = new Promise((resolve, reject) => {
|
|
@@ -495,7 +660,7 @@ function createLLMHandler() {
|
|
|
495
660
|
"llm"
|
|
496
661
|
);
|
|
497
662
|
const baseUrl = request.config.baseUrl ?? ANTHROPIC_API_URL;
|
|
498
|
-
const body = transformRequest(request, modelId);
|
|
663
|
+
const body = transformRequest(request, modelId, useNativeStructuredOutput);
|
|
499
664
|
body.stream = true;
|
|
500
665
|
const headers = {
|
|
501
666
|
"Content-Type": "application/json",
|
|
@@ -555,7 +720,7 @@ function createLLMHandler() {
|
|
|
555
720
|
}
|
|
556
721
|
}
|
|
557
722
|
}
|
|
558
|
-
responseResolve(buildResponseFromState(state));
|
|
723
|
+
responseResolve(buildResponseFromState(state, useNativeStructuredOutput));
|
|
559
724
|
} catch (error) {
|
|
560
725
|
responseReject(error);
|
|
561
726
|
throw error;
|
|
@@ -574,74 +739,37 @@ function createLLMHandler() {
|
|
|
574
739
|
};
|
|
575
740
|
}
|
|
576
741
|
|
|
577
|
-
// src/providers/anthropic/
|
|
578
|
-
function
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
};
|
|
584
|
-
}
|
|
585
|
-
function computerTool(options) {
|
|
586
|
-
const { version = "20250124", ...rest } = options;
|
|
587
|
-
return {
|
|
588
|
-
type: version === "20251124" ? "computer_20251124" : "computer_20250124",
|
|
589
|
-
name: "computer",
|
|
590
|
-
...rest
|
|
591
|
-
};
|
|
592
|
-
}
|
|
593
|
-
function textEditorTool(options) {
|
|
594
|
-
const version = options?.version ?? "20250728";
|
|
595
|
-
return {
|
|
596
|
-
type: version === "20250728" ? "text_editor_20250728" : "text_editor_20250124",
|
|
597
|
-
name: version === "20250728" ? "str_replace_based_edit_tool" : "str_replace_editor",
|
|
598
|
-
...options?.max_characters !== void 0 && { max_characters: options.max_characters }
|
|
599
|
-
};
|
|
600
|
-
}
|
|
601
|
-
function bashTool() {
|
|
602
|
-
return {
|
|
603
|
-
type: "bash_20250124",
|
|
604
|
-
name: "bash"
|
|
605
|
-
};
|
|
606
|
-
}
|
|
607
|
-
function codeExecutionTool() {
|
|
608
|
-
return {
|
|
609
|
-
type: "code_execution_20250825",
|
|
610
|
-
name: "code_execution"
|
|
611
|
-
};
|
|
612
|
-
}
|
|
613
|
-
function toolSearchTool(options) {
|
|
614
|
-
const mode = options?.mode ?? "regex";
|
|
742
|
+
// src/providers/anthropic/index.ts
|
|
743
|
+
function createProviderConfig(options) {
|
|
744
|
+
if (!options?.betas || options.betas.length === 0) {
|
|
745
|
+
return void 0;
|
|
746
|
+
}
|
|
747
|
+
const betaHeader = options.betas.join(",");
|
|
615
748
|
return {
|
|
616
|
-
|
|
617
|
-
|
|
749
|
+
headers: {
|
|
750
|
+
"anthropic-beta": betaHeader
|
|
751
|
+
}
|
|
618
752
|
};
|
|
619
753
|
}
|
|
620
|
-
var tools = {
|
|
621
|
-
/** Creates a web search tool configuration */
|
|
622
|
-
webSearch: webSearchTool,
|
|
623
|
-
/** Creates a computer use tool configuration */
|
|
624
|
-
computer: computerTool,
|
|
625
|
-
/** Creates a text editor tool configuration */
|
|
626
|
-
textEditor: textEditorTool,
|
|
627
|
-
/** Creates a bash tool configuration */
|
|
628
|
-
bash: bashTool,
|
|
629
|
-
/** Creates a code execution tool configuration */
|
|
630
|
-
codeExecution: codeExecutionTool,
|
|
631
|
-
/** Creates a tool search tool configuration */
|
|
632
|
-
toolSearch: toolSearchTool
|
|
633
|
-
};
|
|
634
|
-
|
|
635
|
-
// src/providers/anthropic/index.ts
|
|
636
754
|
var anthropic = createProvider({
|
|
637
755
|
name: "anthropic",
|
|
638
756
|
version: "1.0.0",
|
|
639
|
-
|
|
757
|
+
handlers: {
|
|
640
758
|
llm: createLLMHandler()
|
|
759
|
+
},
|
|
760
|
+
createModelReference: (modelId, options, provider) => {
|
|
761
|
+
const providerConfig = createProviderConfig(options);
|
|
762
|
+
return {
|
|
763
|
+
modelId,
|
|
764
|
+
provider,
|
|
765
|
+
options,
|
|
766
|
+
...providerConfig && { providerConfig }
|
|
767
|
+
};
|
|
641
768
|
}
|
|
642
769
|
});
|
|
643
770
|
export {
|
|
644
771
|
anthropic,
|
|
772
|
+
betas,
|
|
645
773
|
tools
|
|
646
774
|
};
|
|
647
775
|
//# sourceMappingURL=index.js.map
|