@assemble-dev/providers 0.1.0 → 0.2.0

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/index.d.cts CHANGED
@@ -3,6 +3,9 @@ import { JsonValue } from '@assemble-dev/shared-types/json';
3
3
  import { TokenUsage } from '@assemble-dev/shared-types/runs';
4
4
  import { AppError } from '@assemble-dev/shared-utils/errors';
5
5
  import * as _assemble_dev_shared_types from '@assemble-dev/shared-types';
6
+ import { RunMetadata } from '@assemble-dev/shared-types/run-metadata';
7
+ import { TraceEvent } from '@assemble-dev/shared-types/trace-events';
8
+ import { ValidationSchema } from '@assemble-dev/shared-types/validation';
6
9
 
7
10
  declare const ChatMessageRoleSchema: z.ZodEnum<{
8
11
  system: "system";
@@ -30,6 +33,13 @@ declare const ModelToolCallSchema: z.ZodObject<{
30
33
  input: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
31
34
  }, z.core.$strip>;
32
35
  type ModelToolCall = z.infer<typeof ModelToolCallSchema>;
36
+ declare const ChatMessageCacheControlSchema: z.ZodObject<{
37
+ ttl: z.ZodOptional<z.ZodEnum<{
38
+ "5m": "5m";
39
+ "1h": "1h";
40
+ }>>;
41
+ }, z.core.$strip>;
42
+ type ChatMessageCacheControl = z.infer<typeof ChatMessageCacheControlSchema>;
33
43
  declare const ChatMessageSchema: z.ZodObject<{
34
44
  role: z.ZodEnum<{
35
45
  system: "system";
@@ -56,6 +66,12 @@ declare const ChatMessageSchema: z.ZodObject<{
56
66
  toolName: z.ZodString;
57
67
  input: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
58
68
  }, z.core.$strip>>>;
69
+ cacheControl: z.ZodOptional<z.ZodObject<{
70
+ ttl: z.ZodOptional<z.ZodEnum<{
71
+ "5m": "5m";
72
+ "1h": "1h";
73
+ }>>;
74
+ }, z.core.$strip>>;
59
75
  }, z.core.$strip>;
60
76
  type ChatMessage = z.infer<typeof ChatMessageSchema>;
61
77
  type ModelToolDefinition = {
@@ -80,6 +96,7 @@ type ChatCompletionRequest = {
80
96
  tools?: ModelToolDefinition[];
81
97
  toolChoice?: ModelToolChoice;
82
98
  abortSignal?: AbortSignal;
99
+ extraBody?: Record<string, JsonValue>;
83
100
  };
84
101
  type ChatCompletionResult = {
85
102
  content: string;
@@ -146,19 +163,17 @@ type OpenAiAdapterOptions = {
146
163
  maxOutputTokens?: number;
147
164
  retry?: ProviderRetryOptions;
148
165
  fallbackModel?: string;
166
+ extraBody?: Record<string, JsonValue>;
149
167
  };
150
168
  declare function openai(options: OpenAiAdapterOptions): ModelAdapter;
151
169
 
152
- type AnthropicPromptCachingMode = "auto" | "off";
153
170
  type AnthropicThinkingOptions = {
154
171
  budgetTokens: number;
155
172
  };
156
- type AnthropicCacheControl = {
157
- type: "ephemeral";
158
- };
159
173
  type AnthropicRequestContentBlock = {
160
174
  type: "text";
161
175
  text: string;
176
+ cache_control?: AnthropicCacheControl;
162
177
  } | {
163
178
  type: "image";
164
179
  source: {
@@ -166,6 +181,7 @@ type AnthropicRequestContentBlock = {
166
181
  media_type: string;
167
182
  data: string;
168
183
  };
184
+ cache_control?: AnthropicCacheControl;
169
185
  } | {
170
186
  type: "document";
171
187
  source: {
@@ -173,15 +189,18 @@ type AnthropicRequestContentBlock = {
173
189
  media_type: string;
174
190
  data: string;
175
191
  };
192
+ cache_control?: AnthropicCacheControl;
176
193
  } | {
177
194
  type: "tool_use";
178
195
  id: string;
179
196
  name: string;
180
197
  input: JsonValue;
198
+ cache_control?: AnthropicCacheControl;
181
199
  } | {
182
200
  type: "tool_result";
183
201
  tool_use_id: string;
184
202
  content: string;
203
+ cache_control?: AnthropicCacheControl;
185
204
  };
186
205
  type AnthropicRequestMessage = {
187
206
  role: "user" | "assistant";
@@ -229,19 +248,35 @@ type AnthropicRequestInput = {
229
248
  tools?: ModelToolDefinition[];
230
249
  toolChoice?: ModelToolChoice;
231
250
  abortSignal?: AbortSignal;
251
+ extraBody?: Record<string, JsonValue>;
232
252
  };
233
253
  type AnthropicRequestSettings = {
234
254
  model: string;
235
255
  defaultMaxOutputTokens: number;
236
- promptCaching?: AnthropicPromptCachingMode;
256
+ promptCaching?: AnthropicPromptCachingOptions;
237
257
  thinking?: AnthropicThinkingOptions;
238
258
  };
239
259
  declare function buildAnthropicRequestBody(settings: AnthropicRequestSettings, input: AnthropicRequestInput): AnthropicRequestBody;
240
- declare function mapModelToolDefinitionsToAnthropicTools(tools: ModelToolDefinition[], promptCaching: AnthropicPromptCachingMode | undefined): AnthropicToolDefinition[];
260
+ declare function mapModelToolDefinitionsToAnthropicTools(tools: ModelToolDefinition[], promptCaching: AnthropicPromptCachingOptions | undefined): AnthropicToolDefinition[];
241
261
  declare function mapModelToolChoiceToAnthropicToolChoice(toolChoice: ModelToolChoice): AnthropicToolChoice;
242
262
  declare function joinSystemMessageText(messages: ChatMessage[]): string;
243
263
  declare function mapChatMessageToAnthropicRequestMessage(message: ChatMessage): AnthropicRequestMessage;
244
264
 
265
+ type AnthropicPromptCachingMode = "auto" | "off";
266
+ type AnthropicCacheTtl = "5m" | "1h";
267
+ type AnthropicPromptCachingSettings = {
268
+ mode: "auto" | "messages" | "off";
269
+ ttl?: AnthropicCacheTtl;
270
+ };
271
+ type AnthropicPromptCachingOptions = AnthropicPromptCachingMode | AnthropicPromptCachingSettings;
272
+ type AnthropicCacheControl = {
273
+ type: "ephemeral";
274
+ ttl?: AnthropicCacheTtl;
275
+ };
276
+ declare function resolveAnthropicPromptCachingSettings(promptCaching: AnthropicPromptCachingOptions | undefined): AnthropicPromptCachingSettings;
277
+ declare function buildAnthropicCacheControl(ttl: AnthropicCacheTtl | undefined): AnthropicCacheControl;
278
+ declare function applyCacheControlToLastContentBlock(requestMessage: AnthropicRequestMessage, cacheControl: AnthropicCacheControl): void;
279
+
245
280
  declare const defaultAnthropicBaseUrl = "https://api.anthropic.com";
246
281
  declare const defaultAnthropicMaxOutputTokens = 1024;
247
282
 
@@ -253,13 +288,17 @@ type AnthropicAdapterOptions = {
253
288
  fetchImplementation?: typeof fetch;
254
289
  temperature?: number;
255
290
  maxOutputTokens?: number;
256
- promptCaching?: AnthropicPromptCachingMode;
291
+ promptCaching?: AnthropicPromptCachingOptions;
257
292
  thinking?: AnthropicThinkingOptions;
258
293
  retry?: ProviderRetryOptions;
259
294
  fallbackModel?: string;
295
+ extraBody?: Record<string, JsonValue>;
260
296
  };
261
297
  declare function anthropic(options: AnthropicAdapterOptions): ModelAdapter;
262
298
 
299
+ type ProviderExtraBody = Record<string, JsonValue>;
300
+ declare function mergeProviderRequestExtraBody<TRequestBody extends object>(requestBody: TRequestBody, adapterExtraBody: ProviderExtraBody | undefined, requestExtraBody: ProviderExtraBody | undefined): TRequestBody & ProviderExtraBody;
301
+
263
302
  declare const defaultGeminiBaseUrl = "https://generativelanguage.googleapis.com";
264
303
  type GeminiAdapterOptions = {
265
304
  model: string;
@@ -271,6 +310,7 @@ type GeminiAdapterOptions = {
271
310
  maxOutputTokens?: number;
272
311
  retry?: ProviderRetryOptions;
273
312
  fallbackModel?: string;
313
+ extraBody?: Record<string, JsonValue>;
274
314
  };
275
315
  declare function gemini(options: GeminiAdapterOptions): ModelAdapter;
276
316
 
@@ -468,12 +508,46 @@ type OpenAiCallInput = {
468
508
  tools?: ModelToolDefinition[];
469
509
  toolChoice?: ModelToolChoice;
470
510
  abortSignal?: AbortSignal;
511
+ extraBody?: Record<string, JsonValue>;
471
512
  };
472
513
  declare function buildOpenAiRequestBody(model: string, input: OpenAiCallInput): OpenAiRequestBody;
473
514
  declare function mapModelToolDefinitionToOpenAiTool(tool: ModelToolDefinition): OpenAiToolDefinition;
474
515
  declare function mapModelToolChoiceToOpenAiToolChoice(toolChoice: ModelToolChoice): OpenAiToolChoice;
475
516
  declare function mapChatMessageToOpenAiRequestMessage(message: ChatMessage): OpenAiRequestMessage;
476
517
 
518
+ type AnthropicBatchPromptCachingMode = "auto" | "off";
519
+ type AnthropicBatchMessageRequest = {
520
+ customId: string;
521
+ model: string;
522
+ messages: ChatMessage[];
523
+ maxOutputTokens?: number;
524
+ temperature?: number;
525
+ promptCaching?: AnthropicBatchPromptCachingMode;
526
+ requireJsonResponse?: boolean;
527
+ };
528
+ type AnthropicBatchApiRequestMessage = {
529
+ role: "user" | "assistant";
530
+ content: string;
531
+ };
532
+ type AnthropicBatchSystemContentBlock = {
533
+ type: "text";
534
+ text: string;
535
+ cache_control?: {
536
+ type: "ephemeral";
537
+ };
538
+ };
539
+ type AnthropicBatchApiRequestParams = {
540
+ model: string;
541
+ max_tokens: number;
542
+ messages: AnthropicBatchApiRequestMessage[];
543
+ system?: string | AnthropicBatchSystemContentBlock[];
544
+ temperature?: number;
545
+ };
546
+ type AnthropicBatchApiRequest = {
547
+ custom_id: string;
548
+ params: AnthropicBatchApiRequestParams;
549
+ };
550
+
477
551
  declare const AnthropicMessageBatchResponseSchema: z.ZodObject<{
478
552
  id: z.ZodString;
479
553
  processing_status: z.ZodEnum<{
@@ -531,6 +605,13 @@ type AnthropicBatchResult = {
531
605
  outcome: AnthropicBatchResultOutcome;
532
606
  };
533
607
 
608
+ declare const anthropicBatchTraceWorkflowName = "anthropic-message-batch";
609
+ type AnthropicBatchTraceEventHandler = (traceEvent: TraceEvent) => void;
610
+ type AnthropicBatchSubmittedRequestSummary = {
611
+ customId: string;
612
+ model: string;
613
+ };
614
+
534
615
  declare const defaultAnthropicBatchPollIntervalMs = 5000;
535
616
  declare const defaultAnthropicBatchTimeoutMs = 3600000;
536
617
  type AnthropicBatchClientOptions = {
@@ -538,13 +619,8 @@ type AnthropicBatchClientOptions = {
538
619
  apiKeyName?: string;
539
620
  baseURL?: string;
540
621
  fetchImplementation?: typeof fetch;
541
- };
542
- type AnthropicBatchMessageRequest = {
543
- customId: string;
544
- model: string;
545
- messages: ChatMessage[];
546
- maxOutputTokens?: number;
547
- temperature?: number;
622
+ onTraceEvent?: AnthropicBatchTraceEventHandler;
623
+ metadata?: RunMetadata;
548
624
  };
549
625
  type AnthropicBatchWaitOptions = {
550
626
  pollIntervalMs?: number;
@@ -559,4 +635,7 @@ type AnthropicBatchClient = {
559
635
  };
560
636
  declare function createAnthropicBatchClient(options: AnthropicBatchClientOptions): AnthropicBatchClient;
561
637
 
562
- export { type AnthropicAdapterOptions, type AnthropicBatchCanceledOutcome, type AnthropicBatchClient, type AnthropicBatchClientOptions, type AnthropicBatchErroredOutcome, type AnthropicBatchExpiredOutcome, type AnthropicBatchMessageRequest, type AnthropicBatchResult, type AnthropicBatchResultOutcome, type AnthropicBatchSucceededOutcome, type AnthropicBatchWaitOptions, type AnthropicMessageBatch, type AnthropicMessageBatchProcessingStatus, type AnthropicMessageBatchRequestCounts, type AnthropicMessagesResponse, AnthropicMessagesResponseSchema, type AnthropicPromptCachingMode, type AnthropicRequestBody, type AnthropicRequestContentBlock, type AnthropicRequestInput, type AnthropicRequestMessage, type AnthropicRequestSettings, type AnthropicStreamEvent, AnthropicStreamEventSchema, type AnthropicStreamRequestInput, type AnthropicStreamStartUsage, type AnthropicSystemContentBlock, type AnthropicThinkingOptions, type AnthropicToolChoice, type AnthropicToolDefinition, type AnthropicUsage, type ChatCompletionRequest, type ChatCompletionResult, type ChatMessage, type ChatMessageRole, ChatMessageRoleSchema, ChatMessageSchema, type ChatStopReason, ChatStopReasonSchema, type ChatStreamEvent, type GeminiAdapterOptions, type MessageContentBlock, MessageContentBlockSchema, type MockModelOptions, type ModelAdapter, type ModelPricingUsdPerMillionTokens, type ModelToolCall, ModelToolCallSchema, type ModelToolChoice, type ModelToolDefinition, type OpenAiAdapterOptions, type OpenAiCallInput, type OpenAiContentPart, type OpenAiRequestBody, type OpenAiRequestMessage, type OpenAiRequestToolCall, type OpenAiToolChoice, type OpenAiToolDefinition, type ProviderRetryOptions, type ResolveProviderApiKeyInput, type StructuredOutputRequest, type StructuredOutputResult, anthropic, buildAnthropicRequestBody, buildOpenAiRequestBody, buildProviderCanceledError, calculateProviderRetryDelayMs, createAnthropicBatchClient, defaultAnthropicBaseUrl, defaultAnthropicBatchPollIntervalMs, defaultAnthropicBatchTimeoutMs, defaultAnthropicMaxOutputTokens, defaultGeminiBaseUrl, defaultOpenAiBaseUrl, defaultProviderRetryInitialDelayMs, defaultProviderRetryMaxAttempts, defaultProviderRetryMaxDelayMs, estimateModelCallCostUsd, executeAbortableProviderFetch, executeProviderCallWithModelFallback, executeProviderCallWithRetry, extractAnthropicTextContent, extractAnthropicToolCalls, extractMessageText, gemini, isAbortError, isRetryableProviderAppError, joinSystemMessageText, mapAnthropicResponseToChatCompletionResult, mapAnthropicUsageToTokenUsage, mapChatMessageToAnthropicRequestMessage, mapChatMessageToOpenAiRequestMessage, mapModelToolChoiceToAnthropicToolChoice, mapModelToolChoiceToOpenAiToolChoice, mapModelToolDefinitionToOpenAiTool, mapModelToolDefinitionsToAnthropicTools, mockModel, normalizeAnthropicStopReason, openai, parseAnthropicStreamEvents, parseAnthropicToolInputJson, resolveProviderApiKey, streamAnthropicChatCompletion };
638
+ declare const anthropicBatchJsonOnlySystemInstruction = "Respond with a single JSON object that satisfies the caller's requested structure. Output only valid JSON with no surrounding text.";
639
+ declare function parseAnthropicBatchStructuredContent<T>(content: string, schema: ValidationSchema<T>): T;
640
+
641
+ export { type AnthropicAdapterOptions, type AnthropicBatchApiRequest, type AnthropicBatchApiRequestMessage, type AnthropicBatchApiRequestParams, type AnthropicBatchCanceledOutcome, type AnthropicBatchClient, type AnthropicBatchClientOptions, type AnthropicBatchErroredOutcome, type AnthropicBatchExpiredOutcome, type AnthropicBatchMessageRequest, type AnthropicBatchPromptCachingMode, type AnthropicBatchResult, type AnthropicBatchResultOutcome, type AnthropicBatchSubmittedRequestSummary, type AnthropicBatchSucceededOutcome, type AnthropicBatchSystemContentBlock, type AnthropicBatchTraceEventHandler, type AnthropicBatchWaitOptions, type AnthropicCacheControl, type AnthropicCacheTtl, type AnthropicMessageBatch, type AnthropicMessageBatchProcessingStatus, type AnthropicMessageBatchRequestCounts, type AnthropicMessagesResponse, AnthropicMessagesResponseSchema, type AnthropicPromptCachingMode, type AnthropicPromptCachingOptions, type AnthropicPromptCachingSettings, type AnthropicRequestBody, type AnthropicRequestContentBlock, type AnthropicRequestInput, type AnthropicRequestMessage, type AnthropicRequestSettings, type AnthropicStreamEvent, AnthropicStreamEventSchema, type AnthropicStreamRequestInput, type AnthropicStreamStartUsage, type AnthropicSystemContentBlock, type AnthropicThinkingOptions, type AnthropicToolChoice, type AnthropicToolDefinition, type AnthropicUsage, type ChatCompletionRequest, type ChatCompletionResult, type ChatMessage, type ChatMessageCacheControl, ChatMessageCacheControlSchema, type ChatMessageRole, ChatMessageRoleSchema, ChatMessageSchema, type ChatStopReason, ChatStopReasonSchema, type ChatStreamEvent, type GeminiAdapterOptions, type MessageContentBlock, MessageContentBlockSchema, type MockModelOptions, type ModelAdapter, type ModelPricingUsdPerMillionTokens, type ModelToolCall, ModelToolCallSchema, type ModelToolChoice, type ModelToolDefinition, type OpenAiAdapterOptions, type OpenAiCallInput, type OpenAiContentPart, type OpenAiRequestBody, type OpenAiRequestMessage, type OpenAiRequestToolCall, type OpenAiToolChoice, type OpenAiToolDefinition, type ProviderExtraBody, type ProviderRetryOptions, type ResolveProviderApiKeyInput, type StructuredOutputRequest, type StructuredOutputResult, anthropic, anthropicBatchJsonOnlySystemInstruction, anthropicBatchTraceWorkflowName, applyCacheControlToLastContentBlock, buildAnthropicCacheControl, buildAnthropicRequestBody, buildOpenAiRequestBody, buildProviderCanceledError, calculateProviderRetryDelayMs, createAnthropicBatchClient, defaultAnthropicBaseUrl, defaultAnthropicBatchPollIntervalMs, defaultAnthropicBatchTimeoutMs, defaultAnthropicMaxOutputTokens, defaultGeminiBaseUrl, defaultOpenAiBaseUrl, defaultProviderRetryInitialDelayMs, defaultProviderRetryMaxAttempts, defaultProviderRetryMaxDelayMs, estimateModelCallCostUsd, executeAbortableProviderFetch, executeProviderCallWithModelFallback, executeProviderCallWithRetry, extractAnthropicTextContent, extractAnthropicToolCalls, extractMessageText, gemini, isAbortError, isRetryableProviderAppError, joinSystemMessageText, mapAnthropicResponseToChatCompletionResult, mapAnthropicUsageToTokenUsage, mapChatMessageToAnthropicRequestMessage, mapChatMessageToOpenAiRequestMessage, mapModelToolChoiceToAnthropicToolChoice, mapModelToolChoiceToOpenAiToolChoice, mapModelToolDefinitionToOpenAiTool, mapModelToolDefinitionsToAnthropicTools, mergeProviderRequestExtraBody, mockModel, normalizeAnthropicStopReason, openai, parseAnthropicBatchStructuredContent, parseAnthropicStreamEvents, parseAnthropicToolInputJson, resolveAnthropicPromptCachingSettings, resolveProviderApiKey, streamAnthropicChatCompletion };
package/dist/index.d.ts CHANGED
@@ -3,6 +3,9 @@ import { JsonValue } from '@assemble-dev/shared-types/json';
3
3
  import { TokenUsage } from '@assemble-dev/shared-types/runs';
4
4
  import { AppError } from '@assemble-dev/shared-utils/errors';
5
5
  import * as _assemble_dev_shared_types from '@assemble-dev/shared-types';
6
+ import { RunMetadata } from '@assemble-dev/shared-types/run-metadata';
7
+ import { TraceEvent } from '@assemble-dev/shared-types/trace-events';
8
+ import { ValidationSchema } from '@assemble-dev/shared-types/validation';
6
9
 
7
10
  declare const ChatMessageRoleSchema: z.ZodEnum<{
8
11
  system: "system";
@@ -30,6 +33,13 @@ declare const ModelToolCallSchema: z.ZodObject<{
30
33
  input: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
31
34
  }, z.core.$strip>;
32
35
  type ModelToolCall = z.infer<typeof ModelToolCallSchema>;
36
+ declare const ChatMessageCacheControlSchema: z.ZodObject<{
37
+ ttl: z.ZodOptional<z.ZodEnum<{
38
+ "5m": "5m";
39
+ "1h": "1h";
40
+ }>>;
41
+ }, z.core.$strip>;
42
+ type ChatMessageCacheControl = z.infer<typeof ChatMessageCacheControlSchema>;
33
43
  declare const ChatMessageSchema: z.ZodObject<{
34
44
  role: z.ZodEnum<{
35
45
  system: "system";
@@ -56,6 +66,12 @@ declare const ChatMessageSchema: z.ZodObject<{
56
66
  toolName: z.ZodString;
57
67
  input: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
58
68
  }, z.core.$strip>>>;
69
+ cacheControl: z.ZodOptional<z.ZodObject<{
70
+ ttl: z.ZodOptional<z.ZodEnum<{
71
+ "5m": "5m";
72
+ "1h": "1h";
73
+ }>>;
74
+ }, z.core.$strip>>;
59
75
  }, z.core.$strip>;
60
76
  type ChatMessage = z.infer<typeof ChatMessageSchema>;
61
77
  type ModelToolDefinition = {
@@ -80,6 +96,7 @@ type ChatCompletionRequest = {
80
96
  tools?: ModelToolDefinition[];
81
97
  toolChoice?: ModelToolChoice;
82
98
  abortSignal?: AbortSignal;
99
+ extraBody?: Record<string, JsonValue>;
83
100
  };
84
101
  type ChatCompletionResult = {
85
102
  content: string;
@@ -146,19 +163,17 @@ type OpenAiAdapterOptions = {
146
163
  maxOutputTokens?: number;
147
164
  retry?: ProviderRetryOptions;
148
165
  fallbackModel?: string;
166
+ extraBody?: Record<string, JsonValue>;
149
167
  };
150
168
  declare function openai(options: OpenAiAdapterOptions): ModelAdapter;
151
169
 
152
- type AnthropicPromptCachingMode = "auto" | "off";
153
170
  type AnthropicThinkingOptions = {
154
171
  budgetTokens: number;
155
172
  };
156
- type AnthropicCacheControl = {
157
- type: "ephemeral";
158
- };
159
173
  type AnthropicRequestContentBlock = {
160
174
  type: "text";
161
175
  text: string;
176
+ cache_control?: AnthropicCacheControl;
162
177
  } | {
163
178
  type: "image";
164
179
  source: {
@@ -166,6 +181,7 @@ type AnthropicRequestContentBlock = {
166
181
  media_type: string;
167
182
  data: string;
168
183
  };
184
+ cache_control?: AnthropicCacheControl;
169
185
  } | {
170
186
  type: "document";
171
187
  source: {
@@ -173,15 +189,18 @@ type AnthropicRequestContentBlock = {
173
189
  media_type: string;
174
190
  data: string;
175
191
  };
192
+ cache_control?: AnthropicCacheControl;
176
193
  } | {
177
194
  type: "tool_use";
178
195
  id: string;
179
196
  name: string;
180
197
  input: JsonValue;
198
+ cache_control?: AnthropicCacheControl;
181
199
  } | {
182
200
  type: "tool_result";
183
201
  tool_use_id: string;
184
202
  content: string;
203
+ cache_control?: AnthropicCacheControl;
185
204
  };
186
205
  type AnthropicRequestMessage = {
187
206
  role: "user" | "assistant";
@@ -229,19 +248,35 @@ type AnthropicRequestInput = {
229
248
  tools?: ModelToolDefinition[];
230
249
  toolChoice?: ModelToolChoice;
231
250
  abortSignal?: AbortSignal;
251
+ extraBody?: Record<string, JsonValue>;
232
252
  };
233
253
  type AnthropicRequestSettings = {
234
254
  model: string;
235
255
  defaultMaxOutputTokens: number;
236
- promptCaching?: AnthropicPromptCachingMode;
256
+ promptCaching?: AnthropicPromptCachingOptions;
237
257
  thinking?: AnthropicThinkingOptions;
238
258
  };
239
259
  declare function buildAnthropicRequestBody(settings: AnthropicRequestSettings, input: AnthropicRequestInput): AnthropicRequestBody;
240
- declare function mapModelToolDefinitionsToAnthropicTools(tools: ModelToolDefinition[], promptCaching: AnthropicPromptCachingMode | undefined): AnthropicToolDefinition[];
260
+ declare function mapModelToolDefinitionsToAnthropicTools(tools: ModelToolDefinition[], promptCaching: AnthropicPromptCachingOptions | undefined): AnthropicToolDefinition[];
241
261
  declare function mapModelToolChoiceToAnthropicToolChoice(toolChoice: ModelToolChoice): AnthropicToolChoice;
242
262
  declare function joinSystemMessageText(messages: ChatMessage[]): string;
243
263
  declare function mapChatMessageToAnthropicRequestMessage(message: ChatMessage): AnthropicRequestMessage;
244
264
 
265
+ type AnthropicPromptCachingMode = "auto" | "off";
266
+ type AnthropicCacheTtl = "5m" | "1h";
267
+ type AnthropicPromptCachingSettings = {
268
+ mode: "auto" | "messages" | "off";
269
+ ttl?: AnthropicCacheTtl;
270
+ };
271
+ type AnthropicPromptCachingOptions = AnthropicPromptCachingMode | AnthropicPromptCachingSettings;
272
+ type AnthropicCacheControl = {
273
+ type: "ephemeral";
274
+ ttl?: AnthropicCacheTtl;
275
+ };
276
+ declare function resolveAnthropicPromptCachingSettings(promptCaching: AnthropicPromptCachingOptions | undefined): AnthropicPromptCachingSettings;
277
+ declare function buildAnthropicCacheControl(ttl: AnthropicCacheTtl | undefined): AnthropicCacheControl;
278
+ declare function applyCacheControlToLastContentBlock(requestMessage: AnthropicRequestMessage, cacheControl: AnthropicCacheControl): void;
279
+
245
280
  declare const defaultAnthropicBaseUrl = "https://api.anthropic.com";
246
281
  declare const defaultAnthropicMaxOutputTokens = 1024;
247
282
 
@@ -253,13 +288,17 @@ type AnthropicAdapterOptions = {
253
288
  fetchImplementation?: typeof fetch;
254
289
  temperature?: number;
255
290
  maxOutputTokens?: number;
256
- promptCaching?: AnthropicPromptCachingMode;
291
+ promptCaching?: AnthropicPromptCachingOptions;
257
292
  thinking?: AnthropicThinkingOptions;
258
293
  retry?: ProviderRetryOptions;
259
294
  fallbackModel?: string;
295
+ extraBody?: Record<string, JsonValue>;
260
296
  };
261
297
  declare function anthropic(options: AnthropicAdapterOptions): ModelAdapter;
262
298
 
299
+ type ProviderExtraBody = Record<string, JsonValue>;
300
+ declare function mergeProviderRequestExtraBody<TRequestBody extends object>(requestBody: TRequestBody, adapterExtraBody: ProviderExtraBody | undefined, requestExtraBody: ProviderExtraBody | undefined): TRequestBody & ProviderExtraBody;
301
+
263
302
  declare const defaultGeminiBaseUrl = "https://generativelanguage.googleapis.com";
264
303
  type GeminiAdapterOptions = {
265
304
  model: string;
@@ -271,6 +310,7 @@ type GeminiAdapterOptions = {
271
310
  maxOutputTokens?: number;
272
311
  retry?: ProviderRetryOptions;
273
312
  fallbackModel?: string;
313
+ extraBody?: Record<string, JsonValue>;
274
314
  };
275
315
  declare function gemini(options: GeminiAdapterOptions): ModelAdapter;
276
316
 
@@ -468,12 +508,46 @@ type OpenAiCallInput = {
468
508
  tools?: ModelToolDefinition[];
469
509
  toolChoice?: ModelToolChoice;
470
510
  abortSignal?: AbortSignal;
511
+ extraBody?: Record<string, JsonValue>;
471
512
  };
472
513
  declare function buildOpenAiRequestBody(model: string, input: OpenAiCallInput): OpenAiRequestBody;
473
514
  declare function mapModelToolDefinitionToOpenAiTool(tool: ModelToolDefinition): OpenAiToolDefinition;
474
515
  declare function mapModelToolChoiceToOpenAiToolChoice(toolChoice: ModelToolChoice): OpenAiToolChoice;
475
516
  declare function mapChatMessageToOpenAiRequestMessage(message: ChatMessage): OpenAiRequestMessage;
476
517
 
518
+ type AnthropicBatchPromptCachingMode = "auto" | "off";
519
+ type AnthropicBatchMessageRequest = {
520
+ customId: string;
521
+ model: string;
522
+ messages: ChatMessage[];
523
+ maxOutputTokens?: number;
524
+ temperature?: number;
525
+ promptCaching?: AnthropicBatchPromptCachingMode;
526
+ requireJsonResponse?: boolean;
527
+ };
528
+ type AnthropicBatchApiRequestMessage = {
529
+ role: "user" | "assistant";
530
+ content: string;
531
+ };
532
+ type AnthropicBatchSystemContentBlock = {
533
+ type: "text";
534
+ text: string;
535
+ cache_control?: {
536
+ type: "ephemeral";
537
+ };
538
+ };
539
+ type AnthropicBatchApiRequestParams = {
540
+ model: string;
541
+ max_tokens: number;
542
+ messages: AnthropicBatchApiRequestMessage[];
543
+ system?: string | AnthropicBatchSystemContentBlock[];
544
+ temperature?: number;
545
+ };
546
+ type AnthropicBatchApiRequest = {
547
+ custom_id: string;
548
+ params: AnthropicBatchApiRequestParams;
549
+ };
550
+
477
551
  declare const AnthropicMessageBatchResponseSchema: z.ZodObject<{
478
552
  id: z.ZodString;
479
553
  processing_status: z.ZodEnum<{
@@ -531,6 +605,13 @@ type AnthropicBatchResult = {
531
605
  outcome: AnthropicBatchResultOutcome;
532
606
  };
533
607
 
608
+ declare const anthropicBatchTraceWorkflowName = "anthropic-message-batch";
609
+ type AnthropicBatchTraceEventHandler = (traceEvent: TraceEvent) => void;
610
+ type AnthropicBatchSubmittedRequestSummary = {
611
+ customId: string;
612
+ model: string;
613
+ };
614
+
534
615
  declare const defaultAnthropicBatchPollIntervalMs = 5000;
535
616
  declare const defaultAnthropicBatchTimeoutMs = 3600000;
536
617
  type AnthropicBatchClientOptions = {
@@ -538,13 +619,8 @@ type AnthropicBatchClientOptions = {
538
619
  apiKeyName?: string;
539
620
  baseURL?: string;
540
621
  fetchImplementation?: typeof fetch;
541
- };
542
- type AnthropicBatchMessageRequest = {
543
- customId: string;
544
- model: string;
545
- messages: ChatMessage[];
546
- maxOutputTokens?: number;
547
- temperature?: number;
622
+ onTraceEvent?: AnthropicBatchTraceEventHandler;
623
+ metadata?: RunMetadata;
548
624
  };
549
625
  type AnthropicBatchWaitOptions = {
550
626
  pollIntervalMs?: number;
@@ -559,4 +635,7 @@ type AnthropicBatchClient = {
559
635
  };
560
636
  declare function createAnthropicBatchClient(options: AnthropicBatchClientOptions): AnthropicBatchClient;
561
637
 
562
- export { type AnthropicAdapterOptions, type AnthropicBatchCanceledOutcome, type AnthropicBatchClient, type AnthropicBatchClientOptions, type AnthropicBatchErroredOutcome, type AnthropicBatchExpiredOutcome, type AnthropicBatchMessageRequest, type AnthropicBatchResult, type AnthropicBatchResultOutcome, type AnthropicBatchSucceededOutcome, type AnthropicBatchWaitOptions, type AnthropicMessageBatch, type AnthropicMessageBatchProcessingStatus, type AnthropicMessageBatchRequestCounts, type AnthropicMessagesResponse, AnthropicMessagesResponseSchema, type AnthropicPromptCachingMode, type AnthropicRequestBody, type AnthropicRequestContentBlock, type AnthropicRequestInput, type AnthropicRequestMessage, type AnthropicRequestSettings, type AnthropicStreamEvent, AnthropicStreamEventSchema, type AnthropicStreamRequestInput, type AnthropicStreamStartUsage, type AnthropicSystemContentBlock, type AnthropicThinkingOptions, type AnthropicToolChoice, type AnthropicToolDefinition, type AnthropicUsage, type ChatCompletionRequest, type ChatCompletionResult, type ChatMessage, type ChatMessageRole, ChatMessageRoleSchema, ChatMessageSchema, type ChatStopReason, ChatStopReasonSchema, type ChatStreamEvent, type GeminiAdapterOptions, type MessageContentBlock, MessageContentBlockSchema, type MockModelOptions, type ModelAdapter, type ModelPricingUsdPerMillionTokens, type ModelToolCall, ModelToolCallSchema, type ModelToolChoice, type ModelToolDefinition, type OpenAiAdapterOptions, type OpenAiCallInput, type OpenAiContentPart, type OpenAiRequestBody, type OpenAiRequestMessage, type OpenAiRequestToolCall, type OpenAiToolChoice, type OpenAiToolDefinition, type ProviderRetryOptions, type ResolveProviderApiKeyInput, type StructuredOutputRequest, type StructuredOutputResult, anthropic, buildAnthropicRequestBody, buildOpenAiRequestBody, buildProviderCanceledError, calculateProviderRetryDelayMs, createAnthropicBatchClient, defaultAnthropicBaseUrl, defaultAnthropicBatchPollIntervalMs, defaultAnthropicBatchTimeoutMs, defaultAnthropicMaxOutputTokens, defaultGeminiBaseUrl, defaultOpenAiBaseUrl, defaultProviderRetryInitialDelayMs, defaultProviderRetryMaxAttempts, defaultProviderRetryMaxDelayMs, estimateModelCallCostUsd, executeAbortableProviderFetch, executeProviderCallWithModelFallback, executeProviderCallWithRetry, extractAnthropicTextContent, extractAnthropicToolCalls, extractMessageText, gemini, isAbortError, isRetryableProviderAppError, joinSystemMessageText, mapAnthropicResponseToChatCompletionResult, mapAnthropicUsageToTokenUsage, mapChatMessageToAnthropicRequestMessage, mapChatMessageToOpenAiRequestMessage, mapModelToolChoiceToAnthropicToolChoice, mapModelToolChoiceToOpenAiToolChoice, mapModelToolDefinitionToOpenAiTool, mapModelToolDefinitionsToAnthropicTools, mockModel, normalizeAnthropicStopReason, openai, parseAnthropicStreamEvents, parseAnthropicToolInputJson, resolveProviderApiKey, streamAnthropicChatCompletion };
638
+ declare const anthropicBatchJsonOnlySystemInstruction = "Respond with a single JSON object that satisfies the caller's requested structure. Output only valid JSON with no surrounding text.";
639
+ declare function parseAnthropicBatchStructuredContent<T>(content: string, schema: ValidationSchema<T>): T;
640
+
641
+ export { type AnthropicAdapterOptions, type AnthropicBatchApiRequest, type AnthropicBatchApiRequestMessage, type AnthropicBatchApiRequestParams, type AnthropicBatchCanceledOutcome, type AnthropicBatchClient, type AnthropicBatchClientOptions, type AnthropicBatchErroredOutcome, type AnthropicBatchExpiredOutcome, type AnthropicBatchMessageRequest, type AnthropicBatchPromptCachingMode, type AnthropicBatchResult, type AnthropicBatchResultOutcome, type AnthropicBatchSubmittedRequestSummary, type AnthropicBatchSucceededOutcome, type AnthropicBatchSystemContentBlock, type AnthropicBatchTraceEventHandler, type AnthropicBatchWaitOptions, type AnthropicCacheControl, type AnthropicCacheTtl, type AnthropicMessageBatch, type AnthropicMessageBatchProcessingStatus, type AnthropicMessageBatchRequestCounts, type AnthropicMessagesResponse, AnthropicMessagesResponseSchema, type AnthropicPromptCachingMode, type AnthropicPromptCachingOptions, type AnthropicPromptCachingSettings, type AnthropicRequestBody, type AnthropicRequestContentBlock, type AnthropicRequestInput, type AnthropicRequestMessage, type AnthropicRequestSettings, type AnthropicStreamEvent, AnthropicStreamEventSchema, type AnthropicStreamRequestInput, type AnthropicStreamStartUsage, type AnthropicSystemContentBlock, type AnthropicThinkingOptions, type AnthropicToolChoice, type AnthropicToolDefinition, type AnthropicUsage, type ChatCompletionRequest, type ChatCompletionResult, type ChatMessage, type ChatMessageCacheControl, ChatMessageCacheControlSchema, type ChatMessageRole, ChatMessageRoleSchema, ChatMessageSchema, type ChatStopReason, ChatStopReasonSchema, type ChatStreamEvent, type GeminiAdapterOptions, type MessageContentBlock, MessageContentBlockSchema, type MockModelOptions, type ModelAdapter, type ModelPricingUsdPerMillionTokens, type ModelToolCall, ModelToolCallSchema, type ModelToolChoice, type ModelToolDefinition, type OpenAiAdapterOptions, type OpenAiCallInput, type OpenAiContentPart, type OpenAiRequestBody, type OpenAiRequestMessage, type OpenAiRequestToolCall, type OpenAiToolChoice, type OpenAiToolDefinition, type ProviderExtraBody, type ProviderRetryOptions, type ResolveProviderApiKeyInput, type StructuredOutputRequest, type StructuredOutputResult, anthropic, anthropicBatchJsonOnlySystemInstruction, anthropicBatchTraceWorkflowName, applyCacheControlToLastContentBlock, buildAnthropicCacheControl, buildAnthropicRequestBody, buildOpenAiRequestBody, buildProviderCanceledError, calculateProviderRetryDelayMs, createAnthropicBatchClient, defaultAnthropicBaseUrl, defaultAnthropicBatchPollIntervalMs, defaultAnthropicBatchTimeoutMs, defaultAnthropicMaxOutputTokens, defaultGeminiBaseUrl, defaultOpenAiBaseUrl, defaultProviderRetryInitialDelayMs, defaultProviderRetryMaxAttempts, defaultProviderRetryMaxDelayMs, estimateModelCallCostUsd, executeAbortableProviderFetch, executeProviderCallWithModelFallback, executeProviderCallWithRetry, extractAnthropicTextContent, extractAnthropicToolCalls, extractMessageText, gemini, isAbortError, isRetryableProviderAppError, joinSystemMessageText, mapAnthropicResponseToChatCompletionResult, mapAnthropicUsageToTokenUsage, mapChatMessageToAnthropicRequestMessage, mapChatMessageToOpenAiRequestMessage, mapModelToolChoiceToAnthropicToolChoice, mapModelToolChoiceToOpenAiToolChoice, mapModelToolDefinitionToOpenAiTool, mapModelToolDefinitionsToAnthropicTools, mergeProviderRequestExtraBody, mockModel, normalizeAnthropicStopReason, openai, parseAnthropicBatchStructuredContent, parseAnthropicStreamEvents, parseAnthropicToolInputJson, resolveAnthropicPromptCachingSettings, resolveProviderApiKey, streamAnthropicChatCompletion };