@assemble-dev/providers 0.1.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/LICENSE +93 -0
- package/dist/index.cjs +1989 -0
- package/dist/index.d.cts +562 -0
- package/dist/index.d.ts +562 -0
- package/dist/index.js +1919 -0
- package/package.json +47 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { JsonValue } from '@assemble-dev/shared-types/json';
|
|
3
|
+
import { TokenUsage } from '@assemble-dev/shared-types/runs';
|
|
4
|
+
import { AppError } from '@assemble-dev/shared-utils/errors';
|
|
5
|
+
import * as _assemble_dev_shared_types from '@assemble-dev/shared-types';
|
|
6
|
+
|
|
7
|
+
declare const ChatMessageRoleSchema: z.ZodEnum<{
|
|
8
|
+
system: "system";
|
|
9
|
+
user: "user";
|
|
10
|
+
assistant: "assistant";
|
|
11
|
+
tool: "tool";
|
|
12
|
+
}>;
|
|
13
|
+
type ChatMessageRole = z.infer<typeof ChatMessageRoleSchema>;
|
|
14
|
+
declare const MessageContentBlockSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
15
|
+
type: z.ZodLiteral<"text">;
|
|
16
|
+
text: z.ZodString;
|
|
17
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
18
|
+
type: z.ZodLiteral<"image">;
|
|
19
|
+
mediaType: z.ZodString;
|
|
20
|
+
dataBase64: z.ZodString;
|
|
21
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
22
|
+
type: z.ZodLiteral<"document">;
|
|
23
|
+
mediaType: z.ZodString;
|
|
24
|
+
dataBase64: z.ZodString;
|
|
25
|
+
}, z.core.$strip>], "type">;
|
|
26
|
+
type MessageContentBlock = z.infer<typeof MessageContentBlockSchema>;
|
|
27
|
+
declare const ModelToolCallSchema: z.ZodObject<{
|
|
28
|
+
id: z.ZodString;
|
|
29
|
+
toolName: z.ZodString;
|
|
30
|
+
input: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
|
|
31
|
+
}, z.core.$strip>;
|
|
32
|
+
type ModelToolCall = z.infer<typeof ModelToolCallSchema>;
|
|
33
|
+
declare const ChatMessageSchema: z.ZodObject<{
|
|
34
|
+
role: z.ZodEnum<{
|
|
35
|
+
system: "system";
|
|
36
|
+
user: "user";
|
|
37
|
+
assistant: "assistant";
|
|
38
|
+
tool: "tool";
|
|
39
|
+
}>;
|
|
40
|
+
content: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
41
|
+
type: z.ZodLiteral<"text">;
|
|
42
|
+
text: z.ZodString;
|
|
43
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
44
|
+
type: z.ZodLiteral<"image">;
|
|
45
|
+
mediaType: z.ZodString;
|
|
46
|
+
dataBase64: z.ZodString;
|
|
47
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
48
|
+
type: z.ZodLiteral<"document">;
|
|
49
|
+
mediaType: z.ZodString;
|
|
50
|
+
dataBase64: z.ZodString;
|
|
51
|
+
}, z.core.$strip>], "type">>]>;
|
|
52
|
+
toolName: z.ZodOptional<z.ZodString>;
|
|
53
|
+
toolCallId: z.ZodOptional<z.ZodString>;
|
|
54
|
+
toolCalls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
55
|
+
id: z.ZodString;
|
|
56
|
+
toolName: z.ZodString;
|
|
57
|
+
input: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
|
|
58
|
+
}, z.core.$strip>>>;
|
|
59
|
+
}, z.core.$strip>;
|
|
60
|
+
type ChatMessage = z.infer<typeof ChatMessageSchema>;
|
|
61
|
+
type ModelToolDefinition = {
|
|
62
|
+
name: string;
|
|
63
|
+
description: string;
|
|
64
|
+
inputJsonSchema: JsonValue;
|
|
65
|
+
};
|
|
66
|
+
type ModelToolChoice = "auto" | "required" | "none" | {
|
|
67
|
+
toolName: string;
|
|
68
|
+
};
|
|
69
|
+
declare const ChatStopReasonSchema: z.ZodEnum<{
|
|
70
|
+
end_turn: "end_turn";
|
|
71
|
+
tool_use: "tool_use";
|
|
72
|
+
max_tokens: "max_tokens";
|
|
73
|
+
stop_sequence: "stop_sequence";
|
|
74
|
+
}>;
|
|
75
|
+
type ChatStopReason = z.infer<typeof ChatStopReasonSchema>;
|
|
76
|
+
type ChatCompletionRequest = {
|
|
77
|
+
messages: ChatMessage[];
|
|
78
|
+
temperature?: number;
|
|
79
|
+
maxOutputTokens?: number;
|
|
80
|
+
tools?: ModelToolDefinition[];
|
|
81
|
+
toolChoice?: ModelToolChoice;
|
|
82
|
+
abortSignal?: AbortSignal;
|
|
83
|
+
};
|
|
84
|
+
type ChatCompletionResult = {
|
|
85
|
+
content: string;
|
|
86
|
+
tokenUsage: TokenUsage;
|
|
87
|
+
latencyMs: number;
|
|
88
|
+
toolCalls?: ModelToolCall[];
|
|
89
|
+
stopReason?: ChatStopReason;
|
|
90
|
+
};
|
|
91
|
+
type ChatStreamEvent = {
|
|
92
|
+
type: "text_delta";
|
|
93
|
+
text: string;
|
|
94
|
+
} | {
|
|
95
|
+
type: "tool_call_started";
|
|
96
|
+
id: string;
|
|
97
|
+
toolName: string;
|
|
98
|
+
} | {
|
|
99
|
+
type: "tool_call_input_delta";
|
|
100
|
+
id: string;
|
|
101
|
+
inputJsonText: string;
|
|
102
|
+
} | {
|
|
103
|
+
type: "completed";
|
|
104
|
+
result: ChatCompletionResult;
|
|
105
|
+
};
|
|
106
|
+
type StructuredOutputRequest<T> = {
|
|
107
|
+
messages: ChatMessage[];
|
|
108
|
+
schema: z.ZodType<T>;
|
|
109
|
+
temperature?: number;
|
|
110
|
+
maxOutputTokens?: number;
|
|
111
|
+
abortSignal?: AbortSignal;
|
|
112
|
+
};
|
|
113
|
+
type StructuredOutputResult<T> = {
|
|
114
|
+
value: T;
|
|
115
|
+
tokenUsage: TokenUsage;
|
|
116
|
+
latencyMs: number;
|
|
117
|
+
};
|
|
118
|
+
type ModelAdapter = {
|
|
119
|
+
name: string;
|
|
120
|
+
generateChatCompletion(request: ChatCompletionRequest): Promise<ChatCompletionResult>;
|
|
121
|
+
generateStructuredOutput<T>(request: StructuredOutputRequest<T>): Promise<StructuredOutputResult<T>>;
|
|
122
|
+
streamChatCompletion?(request: ChatCompletionRequest): AsyncIterable<ChatStreamEvent>;
|
|
123
|
+
};
|
|
124
|
+
declare function extractMessageText(message: ChatMessage): string;
|
|
125
|
+
|
|
126
|
+
declare const defaultProviderRetryMaxAttempts = 3;
|
|
127
|
+
declare const defaultProviderRetryInitialDelayMs = 500;
|
|
128
|
+
declare const defaultProviderRetryMaxDelayMs = 8000;
|
|
129
|
+
type ProviderRetryOptions = {
|
|
130
|
+
maxAttempts?: number;
|
|
131
|
+
initialDelayMs?: number;
|
|
132
|
+
maxDelayMs?: number;
|
|
133
|
+
};
|
|
134
|
+
declare function isRetryableProviderAppError(appError: AppError): boolean;
|
|
135
|
+
declare function executeProviderCallWithRetry<T>(retryOptions: ProviderRetryOptions | undefined, executeCall: () => Promise<T>, waitFor?: (ms: number) => Promise<void>): Promise<T>;
|
|
136
|
+
declare function calculateProviderRetryDelayMs(retryOptions: ProviderRetryOptions, attemptNumber: number): number;
|
|
137
|
+
|
|
138
|
+
declare const defaultOpenAiBaseUrl = "https://api.openai.com/v1";
|
|
139
|
+
type OpenAiAdapterOptions = {
|
|
140
|
+
model: string;
|
|
141
|
+
baseURL?: string;
|
|
142
|
+
apiKey?: string;
|
|
143
|
+
apiKeyName?: string;
|
|
144
|
+
fetchImplementation?: typeof fetch;
|
|
145
|
+
temperature?: number;
|
|
146
|
+
maxOutputTokens?: number;
|
|
147
|
+
retry?: ProviderRetryOptions;
|
|
148
|
+
fallbackModel?: string;
|
|
149
|
+
};
|
|
150
|
+
declare function openai(options: OpenAiAdapterOptions): ModelAdapter;
|
|
151
|
+
|
|
152
|
+
type AnthropicPromptCachingMode = "auto" | "off";
|
|
153
|
+
type AnthropicThinkingOptions = {
|
|
154
|
+
budgetTokens: number;
|
|
155
|
+
};
|
|
156
|
+
type AnthropicCacheControl = {
|
|
157
|
+
type: "ephemeral";
|
|
158
|
+
};
|
|
159
|
+
type AnthropicRequestContentBlock = {
|
|
160
|
+
type: "text";
|
|
161
|
+
text: string;
|
|
162
|
+
} | {
|
|
163
|
+
type: "image";
|
|
164
|
+
source: {
|
|
165
|
+
type: "base64";
|
|
166
|
+
media_type: string;
|
|
167
|
+
data: string;
|
|
168
|
+
};
|
|
169
|
+
} | {
|
|
170
|
+
type: "document";
|
|
171
|
+
source: {
|
|
172
|
+
type: "base64";
|
|
173
|
+
media_type: string;
|
|
174
|
+
data: string;
|
|
175
|
+
};
|
|
176
|
+
} | {
|
|
177
|
+
type: "tool_use";
|
|
178
|
+
id: string;
|
|
179
|
+
name: string;
|
|
180
|
+
input: JsonValue;
|
|
181
|
+
} | {
|
|
182
|
+
type: "tool_result";
|
|
183
|
+
tool_use_id: string;
|
|
184
|
+
content: string;
|
|
185
|
+
};
|
|
186
|
+
type AnthropicRequestMessage = {
|
|
187
|
+
role: "user" | "assistant";
|
|
188
|
+
content: string | AnthropicRequestContentBlock[];
|
|
189
|
+
};
|
|
190
|
+
type AnthropicSystemContentBlock = {
|
|
191
|
+
type: "text";
|
|
192
|
+
text: string;
|
|
193
|
+
cache_control?: AnthropicCacheControl;
|
|
194
|
+
};
|
|
195
|
+
type AnthropicToolDefinition = {
|
|
196
|
+
name: string;
|
|
197
|
+
description: string;
|
|
198
|
+
input_schema: JsonValue;
|
|
199
|
+
cache_control?: AnthropicCacheControl;
|
|
200
|
+
};
|
|
201
|
+
type AnthropicToolChoice = {
|
|
202
|
+
type: "auto";
|
|
203
|
+
} | {
|
|
204
|
+
type: "any";
|
|
205
|
+
} | {
|
|
206
|
+
type: "none";
|
|
207
|
+
} | {
|
|
208
|
+
type: "tool";
|
|
209
|
+
name: string;
|
|
210
|
+
};
|
|
211
|
+
type AnthropicRequestBody = {
|
|
212
|
+
model: string;
|
|
213
|
+
max_tokens: number;
|
|
214
|
+
messages: AnthropicRequestMessage[];
|
|
215
|
+
system?: string | AnthropicSystemContentBlock[];
|
|
216
|
+
temperature?: number;
|
|
217
|
+
thinking?: {
|
|
218
|
+
type: "enabled";
|
|
219
|
+
budget_tokens: number;
|
|
220
|
+
};
|
|
221
|
+
tools?: AnthropicToolDefinition[];
|
|
222
|
+
tool_choice?: AnthropicToolChoice;
|
|
223
|
+
stream?: true;
|
|
224
|
+
};
|
|
225
|
+
type AnthropicRequestInput = {
|
|
226
|
+
messages: ChatMessage[];
|
|
227
|
+
temperature?: number;
|
|
228
|
+
maxOutputTokens?: number;
|
|
229
|
+
tools?: ModelToolDefinition[];
|
|
230
|
+
toolChoice?: ModelToolChoice;
|
|
231
|
+
abortSignal?: AbortSignal;
|
|
232
|
+
};
|
|
233
|
+
type AnthropicRequestSettings = {
|
|
234
|
+
model: string;
|
|
235
|
+
defaultMaxOutputTokens: number;
|
|
236
|
+
promptCaching?: AnthropicPromptCachingMode;
|
|
237
|
+
thinking?: AnthropicThinkingOptions;
|
|
238
|
+
};
|
|
239
|
+
declare function buildAnthropicRequestBody(settings: AnthropicRequestSettings, input: AnthropicRequestInput): AnthropicRequestBody;
|
|
240
|
+
declare function mapModelToolDefinitionsToAnthropicTools(tools: ModelToolDefinition[], promptCaching: AnthropicPromptCachingMode | undefined): AnthropicToolDefinition[];
|
|
241
|
+
declare function mapModelToolChoiceToAnthropicToolChoice(toolChoice: ModelToolChoice): AnthropicToolChoice;
|
|
242
|
+
declare function joinSystemMessageText(messages: ChatMessage[]): string;
|
|
243
|
+
declare function mapChatMessageToAnthropicRequestMessage(message: ChatMessage): AnthropicRequestMessage;
|
|
244
|
+
|
|
245
|
+
declare const defaultAnthropicBaseUrl = "https://api.anthropic.com";
|
|
246
|
+
declare const defaultAnthropicMaxOutputTokens = 1024;
|
|
247
|
+
|
|
248
|
+
type AnthropicAdapterOptions = {
|
|
249
|
+
model: string;
|
|
250
|
+
baseURL?: string;
|
|
251
|
+
apiKey?: string;
|
|
252
|
+
apiKeyName?: string;
|
|
253
|
+
fetchImplementation?: typeof fetch;
|
|
254
|
+
temperature?: number;
|
|
255
|
+
maxOutputTokens?: number;
|
|
256
|
+
promptCaching?: AnthropicPromptCachingMode;
|
|
257
|
+
thinking?: AnthropicThinkingOptions;
|
|
258
|
+
retry?: ProviderRetryOptions;
|
|
259
|
+
fallbackModel?: string;
|
|
260
|
+
};
|
|
261
|
+
declare function anthropic(options: AnthropicAdapterOptions): ModelAdapter;
|
|
262
|
+
|
|
263
|
+
declare const defaultGeminiBaseUrl = "https://generativelanguage.googleapis.com";
|
|
264
|
+
type GeminiAdapterOptions = {
|
|
265
|
+
model: string;
|
|
266
|
+
baseURL?: string;
|
|
267
|
+
apiKey?: string;
|
|
268
|
+
apiKeyName?: string;
|
|
269
|
+
fetchImplementation?: typeof fetch;
|
|
270
|
+
temperature?: number;
|
|
271
|
+
maxOutputTokens?: number;
|
|
272
|
+
retry?: ProviderRetryOptions;
|
|
273
|
+
fallbackModel?: string;
|
|
274
|
+
};
|
|
275
|
+
declare function gemini(options: GeminiAdapterOptions): ModelAdapter;
|
|
276
|
+
|
|
277
|
+
type MockModelOptions = {
|
|
278
|
+
name?: string;
|
|
279
|
+
scriptedResponses?: string[];
|
|
280
|
+
respond?: (request: ChatCompletionRequest) => string;
|
|
281
|
+
};
|
|
282
|
+
declare function mockModel(options?: MockModelOptions): ModelAdapter;
|
|
283
|
+
|
|
284
|
+
type ResolveProviderApiKeyInput = {
|
|
285
|
+
providerLabel: string;
|
|
286
|
+
adapterFunctionName: string;
|
|
287
|
+
baseEnvVarName: string;
|
|
288
|
+
apiKey?: string;
|
|
289
|
+
apiKeyName?: string;
|
|
290
|
+
};
|
|
291
|
+
declare function resolveProviderApiKey(input: ResolveProviderApiKeyInput): string;
|
|
292
|
+
|
|
293
|
+
declare function executeProviderCallWithModelFallback<T>(fallbackModel: string | undefined, executePrimaryCall: () => Promise<T>, executeFallbackCall: (fallbackModelId: string) => Promise<T>): Promise<T>;
|
|
294
|
+
|
|
295
|
+
type ModelPricingUsdPerMillionTokens = {
|
|
296
|
+
inputUsdPerMillionTokens: number;
|
|
297
|
+
outputUsdPerMillionTokens: number;
|
|
298
|
+
cacheWriteUsdPerMillionTokens?: number;
|
|
299
|
+
cacheReadUsdPerMillionTokens?: number;
|
|
300
|
+
};
|
|
301
|
+
declare function estimateModelCallCostUsd(modelName: string, tokenUsage: TokenUsage): number | null;
|
|
302
|
+
|
|
303
|
+
declare function isAbortError(error: Error): boolean;
|
|
304
|
+
declare function buildProviderCanceledError(providerLabel: string): AppError;
|
|
305
|
+
declare function executeAbortableProviderFetch(providerLabel: string, performFetch: () => Promise<Response>): Promise<Response>;
|
|
306
|
+
|
|
307
|
+
declare const AnthropicUsageSchema: z.ZodObject<{
|
|
308
|
+
input_tokens: z.ZodNumber;
|
|
309
|
+
output_tokens: z.ZodNumber;
|
|
310
|
+
cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
|
|
311
|
+
cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
|
|
312
|
+
}, z.core.$strip>;
|
|
313
|
+
type AnthropicUsage = z.infer<typeof AnthropicUsageSchema>;
|
|
314
|
+
declare const AnthropicMessagesResponseSchema: z.ZodObject<{
|
|
315
|
+
content: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
316
|
+
type: z.ZodLiteral<"text">;
|
|
317
|
+
text: z.ZodString;
|
|
318
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
319
|
+
type: z.ZodLiteral<"tool_use">;
|
|
320
|
+
id: z.ZodString;
|
|
321
|
+
name: z.ZodString;
|
|
322
|
+
input: z.ZodType<_assemble_dev_shared_types.JsonValue, unknown, z.core.$ZodTypeInternals<_assemble_dev_shared_types.JsonValue, unknown>>;
|
|
323
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
324
|
+
type: z.ZodLiteral<"thinking">;
|
|
325
|
+
thinking: z.ZodOptional<z.ZodString>;
|
|
326
|
+
signature: z.ZodOptional<z.ZodString>;
|
|
327
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
328
|
+
type: z.ZodLiteral<"redacted_thinking">;
|
|
329
|
+
data: z.ZodOptional<z.ZodString>;
|
|
330
|
+
}, z.core.$strip>], "type">>;
|
|
331
|
+
stop_reason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
332
|
+
usage: z.ZodObject<{
|
|
333
|
+
input_tokens: z.ZodNumber;
|
|
334
|
+
output_tokens: z.ZodNumber;
|
|
335
|
+
cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
|
|
336
|
+
cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
|
|
337
|
+
}, z.core.$strip>;
|
|
338
|
+
}, z.core.$strip>;
|
|
339
|
+
type AnthropicMessagesResponse = z.infer<typeof AnthropicMessagesResponseSchema>;
|
|
340
|
+
declare function mapAnthropicResponseToChatCompletionResult(response: AnthropicMessagesResponse, latencyMs: number): ChatCompletionResult;
|
|
341
|
+
declare function extractAnthropicToolCalls(response: AnthropicMessagesResponse): ModelToolCall[];
|
|
342
|
+
declare function extractAnthropicTextContent(response: AnthropicMessagesResponse, allowEmptyText: boolean): string;
|
|
343
|
+
declare function normalizeAnthropicStopReason(providerStopReason: string): ChatStopReason;
|
|
344
|
+
declare function mapAnthropicUsageToTokenUsage(usage: AnthropicUsage): TokenUsage;
|
|
345
|
+
|
|
346
|
+
type AnthropicStreamRequestInput = {
|
|
347
|
+
url: string;
|
|
348
|
+
headers: Record<string, string>;
|
|
349
|
+
body: AnthropicRequestBody;
|
|
350
|
+
fetchImplementation: typeof fetch;
|
|
351
|
+
retry?: ProviderRetryOptions;
|
|
352
|
+
abortSignal?: AbortSignal;
|
|
353
|
+
};
|
|
354
|
+
declare function streamAnthropicChatCompletion(input: AnthropicStreamRequestInput): AsyncGenerator<ChatStreamEvent, void, void>;
|
|
355
|
+
declare function parseAnthropicStreamEvents(body: ReadableStream<Uint8Array>, startedAt: number, abortSignal: AbortSignal | undefined): AsyncGenerator<ChatStreamEvent, void, void>;
|
|
356
|
+
declare function parseAnthropicToolInputJson(inputJsonText: string): JsonValue;
|
|
357
|
+
|
|
358
|
+
declare const AnthropicStreamEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
359
|
+
type: z.ZodLiteral<"message_start">;
|
|
360
|
+
message: z.ZodObject<{
|
|
361
|
+
usage: z.ZodObject<{
|
|
362
|
+
input_tokens: z.ZodNumber;
|
|
363
|
+
output_tokens: z.ZodOptional<z.ZodNumber>;
|
|
364
|
+
cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
|
|
365
|
+
cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
|
|
366
|
+
}, z.core.$strip>;
|
|
367
|
+
}, z.core.$strip>;
|
|
368
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
369
|
+
type: z.ZodLiteral<"content_block_start">;
|
|
370
|
+
index: z.ZodNumber;
|
|
371
|
+
content_block: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
372
|
+
type: z.ZodLiteral<"text">;
|
|
373
|
+
text: z.ZodOptional<z.ZodString>;
|
|
374
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
375
|
+
type: z.ZodLiteral<"tool_use">;
|
|
376
|
+
id: z.ZodString;
|
|
377
|
+
name: z.ZodString;
|
|
378
|
+
}, z.core.$strip>], "type">;
|
|
379
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
380
|
+
type: z.ZodLiteral<"content_block_delta">;
|
|
381
|
+
index: z.ZodNumber;
|
|
382
|
+
delta: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
383
|
+
type: z.ZodLiteral<"text_delta">;
|
|
384
|
+
text: z.ZodString;
|
|
385
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
386
|
+
type: z.ZodLiteral<"input_json_delta">;
|
|
387
|
+
partial_json: z.ZodString;
|
|
388
|
+
}, z.core.$strip>], "type">;
|
|
389
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
390
|
+
type: z.ZodLiteral<"content_block_stop">;
|
|
391
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
392
|
+
type: z.ZodLiteral<"message_delta">;
|
|
393
|
+
delta: z.ZodObject<{
|
|
394
|
+
stop_reason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
395
|
+
}, z.core.$strip>;
|
|
396
|
+
usage: z.ZodOptional<z.ZodObject<{
|
|
397
|
+
output_tokens: z.ZodNumber;
|
|
398
|
+
}, z.core.$strip>>;
|
|
399
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
400
|
+
type: z.ZodLiteral<"message_stop">;
|
|
401
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
402
|
+
type: z.ZodLiteral<"ping">;
|
|
403
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
404
|
+
type: z.ZodLiteral<"error">;
|
|
405
|
+
error: z.ZodObject<{
|
|
406
|
+
message: z.ZodString;
|
|
407
|
+
}, z.core.$strip>;
|
|
408
|
+
}, z.core.$strip>], "type">;
|
|
409
|
+
type AnthropicStreamEvent = z.infer<typeof AnthropicStreamEventSchema>;
|
|
410
|
+
type AnthropicStreamStartUsage = Extract<AnthropicStreamEvent, {
|
|
411
|
+
type: "message_start";
|
|
412
|
+
}>["message"]["usage"];
|
|
413
|
+
|
|
414
|
+
type OpenAiContentPart = {
|
|
415
|
+
type: "text";
|
|
416
|
+
text: string;
|
|
417
|
+
} | {
|
|
418
|
+
type: "image_url";
|
|
419
|
+
image_url: {
|
|
420
|
+
url: string;
|
|
421
|
+
};
|
|
422
|
+
};
|
|
423
|
+
type OpenAiRequestToolCall = {
|
|
424
|
+
id: string;
|
|
425
|
+
type: "function";
|
|
426
|
+
function: {
|
|
427
|
+
name: string;
|
|
428
|
+
arguments: string;
|
|
429
|
+
};
|
|
430
|
+
};
|
|
431
|
+
type OpenAiRequestMessage = {
|
|
432
|
+
role: ChatMessage["role"];
|
|
433
|
+
content: string | OpenAiContentPart[] | null;
|
|
434
|
+
name?: string;
|
|
435
|
+
tool_call_id?: string;
|
|
436
|
+
tool_calls?: OpenAiRequestToolCall[];
|
|
437
|
+
};
|
|
438
|
+
type OpenAiToolDefinition = {
|
|
439
|
+
type: "function";
|
|
440
|
+
function: {
|
|
441
|
+
name: string;
|
|
442
|
+
description: string;
|
|
443
|
+
parameters: JsonValue;
|
|
444
|
+
};
|
|
445
|
+
};
|
|
446
|
+
type OpenAiToolChoice = "auto" | "required" | "none" | {
|
|
447
|
+
type: "function";
|
|
448
|
+
function: {
|
|
449
|
+
name: string;
|
|
450
|
+
};
|
|
451
|
+
};
|
|
452
|
+
type OpenAiRequestBody = {
|
|
453
|
+
model: string;
|
|
454
|
+
messages: OpenAiRequestMessage[];
|
|
455
|
+
temperature?: number;
|
|
456
|
+
max_tokens?: number;
|
|
457
|
+
response_format?: {
|
|
458
|
+
type: "json_object";
|
|
459
|
+
};
|
|
460
|
+
tools?: OpenAiToolDefinition[];
|
|
461
|
+
tool_choice?: OpenAiToolChoice;
|
|
462
|
+
};
|
|
463
|
+
type OpenAiCallInput = {
|
|
464
|
+
messages: ChatMessage[];
|
|
465
|
+
temperature?: number;
|
|
466
|
+
maxOutputTokens?: number;
|
|
467
|
+
requireJsonObjectResponse: boolean;
|
|
468
|
+
tools?: ModelToolDefinition[];
|
|
469
|
+
toolChoice?: ModelToolChoice;
|
|
470
|
+
abortSignal?: AbortSignal;
|
|
471
|
+
};
|
|
472
|
+
declare function buildOpenAiRequestBody(model: string, input: OpenAiCallInput): OpenAiRequestBody;
|
|
473
|
+
declare function mapModelToolDefinitionToOpenAiTool(tool: ModelToolDefinition): OpenAiToolDefinition;
|
|
474
|
+
declare function mapModelToolChoiceToOpenAiToolChoice(toolChoice: ModelToolChoice): OpenAiToolChoice;
|
|
475
|
+
declare function mapChatMessageToOpenAiRequestMessage(message: ChatMessage): OpenAiRequestMessage;
|
|
476
|
+
|
|
477
|
+
declare const AnthropicMessageBatchResponseSchema: z.ZodObject<{
|
|
478
|
+
id: z.ZodString;
|
|
479
|
+
processing_status: z.ZodEnum<{
|
|
480
|
+
in_progress: "in_progress";
|
|
481
|
+
canceling: "canceling";
|
|
482
|
+
ended: "ended";
|
|
483
|
+
}>;
|
|
484
|
+
request_counts: z.ZodObject<{
|
|
485
|
+
processing: z.ZodNumber;
|
|
486
|
+
succeeded: z.ZodNumber;
|
|
487
|
+
errored: z.ZodNumber;
|
|
488
|
+
canceled: z.ZodNumber;
|
|
489
|
+
expired: z.ZodNumber;
|
|
490
|
+
}, z.core.$strip>;
|
|
491
|
+
results_url: z.ZodNullable<z.ZodString>;
|
|
492
|
+
created_at: z.ZodString;
|
|
493
|
+
ended_at: z.ZodNullable<z.ZodString>;
|
|
494
|
+
}, z.core.$strip>;
|
|
495
|
+
type AnthropicMessageBatchResponse = z.infer<typeof AnthropicMessageBatchResponseSchema>;
|
|
496
|
+
type AnthropicMessageBatchProcessingStatus = AnthropicMessageBatchResponse["processing_status"];
|
|
497
|
+
type AnthropicMessageBatchRequestCounts = {
|
|
498
|
+
processing: number;
|
|
499
|
+
succeeded: number;
|
|
500
|
+
errored: number;
|
|
501
|
+
canceled: number;
|
|
502
|
+
expired: number;
|
|
503
|
+
};
|
|
504
|
+
type AnthropicMessageBatch = {
|
|
505
|
+
id: string;
|
|
506
|
+
processingStatus: AnthropicMessageBatchProcessingStatus;
|
|
507
|
+
requestCounts: AnthropicMessageBatchRequestCounts;
|
|
508
|
+
resultsUrl: string | null;
|
|
509
|
+
createdAt: string;
|
|
510
|
+
endedAt: string | null;
|
|
511
|
+
};
|
|
512
|
+
type AnthropicBatchSucceededOutcome = {
|
|
513
|
+
type: "succeeded";
|
|
514
|
+
content: string;
|
|
515
|
+
tokenUsage: TokenUsage;
|
|
516
|
+
};
|
|
517
|
+
type AnthropicBatchErroredOutcome = {
|
|
518
|
+
type: "errored";
|
|
519
|
+
errorType: string;
|
|
520
|
+
errorMessage: string;
|
|
521
|
+
};
|
|
522
|
+
type AnthropicBatchCanceledOutcome = {
|
|
523
|
+
type: "canceled";
|
|
524
|
+
};
|
|
525
|
+
type AnthropicBatchExpiredOutcome = {
|
|
526
|
+
type: "expired";
|
|
527
|
+
};
|
|
528
|
+
type AnthropicBatchResultOutcome = AnthropicBatchSucceededOutcome | AnthropicBatchErroredOutcome | AnthropicBatchCanceledOutcome | AnthropicBatchExpiredOutcome;
|
|
529
|
+
type AnthropicBatchResult = {
|
|
530
|
+
customId: string;
|
|
531
|
+
outcome: AnthropicBatchResultOutcome;
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
declare const defaultAnthropicBatchPollIntervalMs = 5000;
|
|
535
|
+
declare const defaultAnthropicBatchTimeoutMs = 3600000;
|
|
536
|
+
type AnthropicBatchClientOptions = {
|
|
537
|
+
apiKey?: string;
|
|
538
|
+
apiKeyName?: string;
|
|
539
|
+
baseURL?: string;
|
|
540
|
+
fetchImplementation?: typeof fetch;
|
|
541
|
+
};
|
|
542
|
+
type AnthropicBatchMessageRequest = {
|
|
543
|
+
customId: string;
|
|
544
|
+
model: string;
|
|
545
|
+
messages: ChatMessage[];
|
|
546
|
+
maxOutputTokens?: number;
|
|
547
|
+
temperature?: number;
|
|
548
|
+
};
|
|
549
|
+
type AnthropicBatchWaitOptions = {
|
|
550
|
+
pollIntervalMs?: number;
|
|
551
|
+
timeoutMs?: number;
|
|
552
|
+
waitFor?: (ms: number) => Promise<void>;
|
|
553
|
+
};
|
|
554
|
+
type AnthropicBatchClient = {
|
|
555
|
+
submitMessageBatch(requests: AnthropicBatchMessageRequest[]): Promise<AnthropicMessageBatch>;
|
|
556
|
+
fetchMessageBatch(batchId: string): Promise<AnthropicMessageBatch>;
|
|
557
|
+
listMessageBatchResults(batchId: string): Promise<AnthropicBatchResult[]>;
|
|
558
|
+
waitForMessageBatchCompletion(batchId: string, waitOptions?: AnthropicBatchWaitOptions): Promise<AnthropicMessageBatch>;
|
|
559
|
+
};
|
|
560
|
+
declare function createAnthropicBatchClient(options: AnthropicBatchClientOptions): AnthropicBatchClient;
|
|
561
|
+
|
|
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 };
|