@assemble-dev/providers 0.1.0 → 0.3.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.cjs +1751 -302
- package/dist/index.d.cts +252 -20
- package/dist/index.d.ts +252 -20
- package/dist/index.js +1707 -291
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { JsonValue } from '@assemble-dev/shared-types/json';
|
|
2
|
+
import { JsonValue, JsonObject } 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;
|
|
@@ -87,10 +104,14 @@ type ChatCompletionResult = {
|
|
|
87
104
|
latencyMs: number;
|
|
88
105
|
toolCalls?: ModelToolCall[];
|
|
89
106
|
stopReason?: ChatStopReason;
|
|
107
|
+
thinkingText?: string;
|
|
90
108
|
};
|
|
91
109
|
type ChatStreamEvent = {
|
|
92
110
|
type: "text_delta";
|
|
93
111
|
text: string;
|
|
112
|
+
} | {
|
|
113
|
+
type: "thinking_delta";
|
|
114
|
+
text: string;
|
|
94
115
|
} | {
|
|
95
116
|
type: "tool_call_started";
|
|
96
117
|
id: string;
|
|
@@ -146,19 +167,17 @@ type OpenAiAdapterOptions = {
|
|
|
146
167
|
maxOutputTokens?: number;
|
|
147
168
|
retry?: ProviderRetryOptions;
|
|
148
169
|
fallbackModel?: string;
|
|
170
|
+
extraBody?: Record<string, JsonValue>;
|
|
149
171
|
};
|
|
150
172
|
declare function openai(options: OpenAiAdapterOptions): ModelAdapter;
|
|
151
173
|
|
|
152
|
-
type AnthropicPromptCachingMode = "auto" | "off";
|
|
153
174
|
type AnthropicThinkingOptions = {
|
|
154
175
|
budgetTokens: number;
|
|
155
176
|
};
|
|
156
|
-
type AnthropicCacheControl = {
|
|
157
|
-
type: "ephemeral";
|
|
158
|
-
};
|
|
159
177
|
type AnthropicRequestContentBlock = {
|
|
160
178
|
type: "text";
|
|
161
179
|
text: string;
|
|
180
|
+
cache_control?: AnthropicCacheControl;
|
|
162
181
|
} | {
|
|
163
182
|
type: "image";
|
|
164
183
|
source: {
|
|
@@ -166,6 +185,7 @@ type AnthropicRequestContentBlock = {
|
|
|
166
185
|
media_type: string;
|
|
167
186
|
data: string;
|
|
168
187
|
};
|
|
188
|
+
cache_control?: AnthropicCacheControl;
|
|
169
189
|
} | {
|
|
170
190
|
type: "document";
|
|
171
191
|
source: {
|
|
@@ -173,15 +193,18 @@ type AnthropicRequestContentBlock = {
|
|
|
173
193
|
media_type: string;
|
|
174
194
|
data: string;
|
|
175
195
|
};
|
|
196
|
+
cache_control?: AnthropicCacheControl;
|
|
176
197
|
} | {
|
|
177
198
|
type: "tool_use";
|
|
178
199
|
id: string;
|
|
179
200
|
name: string;
|
|
180
201
|
input: JsonValue;
|
|
202
|
+
cache_control?: AnthropicCacheControl;
|
|
181
203
|
} | {
|
|
182
204
|
type: "tool_result";
|
|
183
205
|
tool_use_id: string;
|
|
184
206
|
content: string;
|
|
207
|
+
cache_control?: AnthropicCacheControl;
|
|
185
208
|
};
|
|
186
209
|
type AnthropicRequestMessage = {
|
|
187
210
|
role: "user" | "assistant";
|
|
@@ -208,6 +231,12 @@ type AnthropicToolChoice = {
|
|
|
208
231
|
type: "tool";
|
|
209
232
|
name: string;
|
|
210
233
|
};
|
|
234
|
+
type AnthropicOutputConfig = {
|
|
235
|
+
format: {
|
|
236
|
+
type: "json_schema";
|
|
237
|
+
schema: JsonObject;
|
|
238
|
+
};
|
|
239
|
+
};
|
|
211
240
|
type AnthropicRequestBody = {
|
|
212
241
|
model: string;
|
|
213
242
|
max_tokens: number;
|
|
@@ -220,6 +249,7 @@ type AnthropicRequestBody = {
|
|
|
220
249
|
};
|
|
221
250
|
tools?: AnthropicToolDefinition[];
|
|
222
251
|
tool_choice?: AnthropicToolChoice;
|
|
252
|
+
output_config?: AnthropicOutputConfig;
|
|
223
253
|
stream?: true;
|
|
224
254
|
};
|
|
225
255
|
type AnthropicRequestInput = {
|
|
@@ -228,20 +258,37 @@ type AnthropicRequestInput = {
|
|
|
228
258
|
maxOutputTokens?: number;
|
|
229
259
|
tools?: ModelToolDefinition[];
|
|
230
260
|
toolChoice?: ModelToolChoice;
|
|
261
|
+
structuredOutputJsonSchema?: JsonObject;
|
|
231
262
|
abortSignal?: AbortSignal;
|
|
263
|
+
extraBody?: Record<string, JsonValue>;
|
|
232
264
|
};
|
|
233
265
|
type AnthropicRequestSettings = {
|
|
234
266
|
model: string;
|
|
235
267
|
defaultMaxOutputTokens: number;
|
|
236
|
-
promptCaching?:
|
|
268
|
+
promptCaching?: AnthropicPromptCachingOptions;
|
|
237
269
|
thinking?: AnthropicThinkingOptions;
|
|
238
270
|
};
|
|
239
271
|
declare function buildAnthropicRequestBody(settings: AnthropicRequestSettings, input: AnthropicRequestInput): AnthropicRequestBody;
|
|
240
|
-
declare function mapModelToolDefinitionsToAnthropicTools(tools: ModelToolDefinition[], promptCaching:
|
|
272
|
+
declare function mapModelToolDefinitionsToAnthropicTools(tools: ModelToolDefinition[], promptCaching: AnthropicPromptCachingOptions | undefined): AnthropicToolDefinition[];
|
|
241
273
|
declare function mapModelToolChoiceToAnthropicToolChoice(toolChoice: ModelToolChoice): AnthropicToolChoice;
|
|
242
274
|
declare function joinSystemMessageText(messages: ChatMessage[]): string;
|
|
243
275
|
declare function mapChatMessageToAnthropicRequestMessage(message: ChatMessage): AnthropicRequestMessage;
|
|
244
276
|
|
|
277
|
+
type AnthropicPromptCachingMode = "auto" | "off";
|
|
278
|
+
type AnthropicCacheTtl = "5m" | "1h";
|
|
279
|
+
type AnthropicPromptCachingSettings = {
|
|
280
|
+
mode: "auto" | "messages" | "off";
|
|
281
|
+
ttl?: AnthropicCacheTtl;
|
|
282
|
+
};
|
|
283
|
+
type AnthropicPromptCachingOptions = AnthropicPromptCachingMode | AnthropicPromptCachingSettings;
|
|
284
|
+
type AnthropicCacheControl = {
|
|
285
|
+
type: "ephemeral";
|
|
286
|
+
ttl?: AnthropicCacheTtl;
|
|
287
|
+
};
|
|
288
|
+
declare function resolveAnthropicPromptCachingSettings(promptCaching: AnthropicPromptCachingOptions | undefined): AnthropicPromptCachingSettings;
|
|
289
|
+
declare function buildAnthropicCacheControl(ttl: AnthropicCacheTtl | undefined): AnthropicCacheControl;
|
|
290
|
+
declare function applyCacheControlToLastContentBlock(requestMessage: AnthropicRequestMessage, cacheControl: AnthropicCacheControl): void;
|
|
291
|
+
|
|
245
292
|
declare const defaultAnthropicBaseUrl = "https://api.anthropic.com";
|
|
246
293
|
declare const defaultAnthropicMaxOutputTokens = 1024;
|
|
247
294
|
|
|
@@ -253,13 +300,17 @@ type AnthropicAdapterOptions = {
|
|
|
253
300
|
fetchImplementation?: typeof fetch;
|
|
254
301
|
temperature?: number;
|
|
255
302
|
maxOutputTokens?: number;
|
|
256
|
-
promptCaching?:
|
|
303
|
+
promptCaching?: AnthropicPromptCachingOptions;
|
|
257
304
|
thinking?: AnthropicThinkingOptions;
|
|
258
305
|
retry?: ProviderRetryOptions;
|
|
259
306
|
fallbackModel?: string;
|
|
307
|
+
extraBody?: Record<string, JsonValue>;
|
|
260
308
|
};
|
|
261
309
|
declare function anthropic(options: AnthropicAdapterOptions): ModelAdapter;
|
|
262
310
|
|
|
311
|
+
type ProviderExtraBody = Record<string, JsonValue>;
|
|
312
|
+
declare function mergeProviderRequestExtraBody<TRequestBody extends object>(requestBody: TRequestBody, adapterExtraBody: ProviderExtraBody | undefined, requestExtraBody: ProviderExtraBody | undefined): TRequestBody & ProviderExtraBody;
|
|
313
|
+
|
|
263
314
|
declare const defaultGeminiBaseUrl = "https://generativelanguage.googleapis.com";
|
|
264
315
|
type GeminiAdapterOptions = {
|
|
265
316
|
model: string;
|
|
@@ -271,6 +322,7 @@ type GeminiAdapterOptions = {
|
|
|
271
322
|
maxOutputTokens?: number;
|
|
272
323
|
retry?: ProviderRetryOptions;
|
|
273
324
|
fallbackModel?: string;
|
|
325
|
+
extraBody?: Record<string, JsonValue>;
|
|
274
326
|
};
|
|
275
327
|
declare function gemini(options: GeminiAdapterOptions): ModelAdapter;
|
|
276
328
|
|
|
@@ -304,6 +356,16 @@ declare function isAbortError(error: Error): boolean;
|
|
|
304
356
|
declare function buildProviderCanceledError(providerLabel: string): AppError;
|
|
305
357
|
declare function executeAbortableProviderFetch(providerLabel: string, performFetch: () => Promise<Response>): Promise<Response>;
|
|
306
358
|
|
|
359
|
+
declare const openAiStructuredOutputSchemaName = "structured_output";
|
|
360
|
+
declare function convertZodSchemaToJsonSchema<T>(schema: z.ZodType<T>): JsonObject;
|
|
361
|
+
declare function buildAnthropicStructuredOutputJsonSchema<T>(schema: z.ZodType<T>): JsonObject;
|
|
362
|
+
declare function sanitizeJsonSchemaForAnthropicStructuredOutput(jsonSchema: JsonObject): JsonObject;
|
|
363
|
+
declare function buildOpenAiStructuredOutputJsonSchema<T>(schema: z.ZodType<T>): JsonObject;
|
|
364
|
+
declare function sanitizeJsonSchemaForOpenAiStructuredOutput(jsonSchema: JsonObject): JsonObject;
|
|
365
|
+
|
|
366
|
+
declare function buildGeminiResponseSchema<T>(schema: z.ZodType<T>): JsonObject;
|
|
367
|
+
declare function sanitizeJsonSchemaForGeminiResponseSchema(jsonSchema: JsonObject): JsonObject;
|
|
368
|
+
|
|
307
369
|
declare const AnthropicUsageSchema: z.ZodObject<{
|
|
308
370
|
input_tokens: z.ZodNumber;
|
|
309
371
|
output_tokens: z.ZodNumber;
|
|
@@ -339,6 +401,7 @@ declare const AnthropicMessagesResponseSchema: z.ZodObject<{
|
|
|
339
401
|
type AnthropicMessagesResponse = z.infer<typeof AnthropicMessagesResponseSchema>;
|
|
340
402
|
declare function mapAnthropicResponseToChatCompletionResult(response: AnthropicMessagesResponse, latencyMs: number): ChatCompletionResult;
|
|
341
403
|
declare function extractAnthropicToolCalls(response: AnthropicMessagesResponse): ModelToolCall[];
|
|
404
|
+
declare function extractAnthropicThinkingText(response: AnthropicMessagesResponse): string;
|
|
342
405
|
declare function extractAnthropicTextContent(response: AnthropicMessagesResponse, allowEmptyText: boolean): string;
|
|
343
406
|
declare function normalizeAnthropicStopReason(providerStopReason: string): ChatStopReason;
|
|
344
407
|
declare function mapAnthropicUsageToTokenUsage(usage: AnthropicUsage): TokenUsage;
|
|
@@ -371,6 +434,12 @@ declare const AnthropicStreamEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
371
434
|
content_block: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
372
435
|
type: z.ZodLiteral<"text">;
|
|
373
436
|
text: z.ZodOptional<z.ZodString>;
|
|
437
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
438
|
+
type: z.ZodLiteral<"thinking">;
|
|
439
|
+
thinking: z.ZodOptional<z.ZodString>;
|
|
440
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
441
|
+
type: z.ZodLiteral<"redacted_thinking">;
|
|
442
|
+
data: z.ZodOptional<z.ZodString>;
|
|
374
443
|
}, z.core.$strip>, z.ZodObject<{
|
|
375
444
|
type: z.ZodLiteral<"tool_use">;
|
|
376
445
|
id: z.ZodString;
|
|
@@ -382,6 +451,12 @@ declare const AnthropicStreamEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
382
451
|
delta: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
383
452
|
type: z.ZodLiteral<"text_delta">;
|
|
384
453
|
text: z.ZodString;
|
|
454
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
455
|
+
type: z.ZodLiteral<"thinking_delta">;
|
|
456
|
+
thinking: z.ZodString;
|
|
457
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
458
|
+
type: z.ZodLiteral<"signature_delta">;
|
|
459
|
+
signature: z.ZodString;
|
|
385
460
|
}, z.core.$strip>, z.ZodObject<{
|
|
386
461
|
type: z.ZodLiteral<"input_json_delta">;
|
|
387
462
|
partial_json: z.ZodString;
|
|
@@ -449,14 +524,22 @@ type OpenAiToolChoice = "auto" | "required" | "none" | {
|
|
|
449
524
|
name: string;
|
|
450
525
|
};
|
|
451
526
|
};
|
|
527
|
+
type OpenAiResponseFormat = {
|
|
528
|
+
type: "json_object";
|
|
529
|
+
} | {
|
|
530
|
+
type: "json_schema";
|
|
531
|
+
json_schema: {
|
|
532
|
+
name: string;
|
|
533
|
+
strict: true;
|
|
534
|
+
schema: JsonObject;
|
|
535
|
+
};
|
|
536
|
+
};
|
|
452
537
|
type OpenAiRequestBody = {
|
|
453
538
|
model: string;
|
|
454
539
|
messages: OpenAiRequestMessage[];
|
|
455
540
|
temperature?: number;
|
|
456
541
|
max_tokens?: number;
|
|
457
|
-
response_format?:
|
|
458
|
-
type: "json_object";
|
|
459
|
-
};
|
|
542
|
+
response_format?: OpenAiResponseFormat;
|
|
460
543
|
tools?: OpenAiToolDefinition[];
|
|
461
544
|
tool_choice?: OpenAiToolChoice;
|
|
462
545
|
};
|
|
@@ -464,16 +547,53 @@ type OpenAiCallInput = {
|
|
|
464
547
|
messages: ChatMessage[];
|
|
465
548
|
temperature?: number;
|
|
466
549
|
maxOutputTokens?: number;
|
|
467
|
-
|
|
550
|
+
structuredOutputJsonSchema?: JsonObject;
|
|
551
|
+
requireJsonObjectResponse?: boolean;
|
|
468
552
|
tools?: ModelToolDefinition[];
|
|
469
553
|
toolChoice?: ModelToolChoice;
|
|
470
554
|
abortSignal?: AbortSignal;
|
|
555
|
+
extraBody?: Record<string, JsonValue>;
|
|
471
556
|
};
|
|
472
557
|
declare function buildOpenAiRequestBody(model: string, input: OpenAiCallInput): OpenAiRequestBody;
|
|
473
558
|
declare function mapModelToolDefinitionToOpenAiTool(tool: ModelToolDefinition): OpenAiToolDefinition;
|
|
474
559
|
declare function mapModelToolChoiceToOpenAiToolChoice(toolChoice: ModelToolChoice): OpenAiToolChoice;
|
|
475
560
|
declare function mapChatMessageToOpenAiRequestMessage(message: ChatMessage): OpenAiRequestMessage;
|
|
476
561
|
|
|
562
|
+
type AnthropicBatchPromptCachingMode = "auto" | "off";
|
|
563
|
+
type AnthropicBatchMessageRequest = {
|
|
564
|
+
customId: string;
|
|
565
|
+
model: string;
|
|
566
|
+
messages: ChatMessage[];
|
|
567
|
+
maxOutputTokens?: number;
|
|
568
|
+
temperature?: number;
|
|
569
|
+
promptCaching?: AnthropicBatchPromptCachingMode;
|
|
570
|
+
requireJsonResponse?: boolean;
|
|
571
|
+
structuredOutputJsonSchema?: JsonObject;
|
|
572
|
+
};
|
|
573
|
+
type AnthropicBatchApiRequestMessage = {
|
|
574
|
+
role: "user" | "assistant";
|
|
575
|
+
content: string;
|
|
576
|
+
};
|
|
577
|
+
type AnthropicBatchSystemContentBlock = {
|
|
578
|
+
type: "text";
|
|
579
|
+
text: string;
|
|
580
|
+
cache_control?: {
|
|
581
|
+
type: "ephemeral";
|
|
582
|
+
};
|
|
583
|
+
};
|
|
584
|
+
type AnthropicBatchApiRequestParams = {
|
|
585
|
+
model: string;
|
|
586
|
+
max_tokens: number;
|
|
587
|
+
messages: AnthropicBatchApiRequestMessage[];
|
|
588
|
+
system?: string | AnthropicBatchSystemContentBlock[];
|
|
589
|
+
temperature?: number;
|
|
590
|
+
output_config?: AnthropicOutputConfig;
|
|
591
|
+
};
|
|
592
|
+
type AnthropicBatchApiRequest = {
|
|
593
|
+
custom_id: string;
|
|
594
|
+
params: AnthropicBatchApiRequestParams;
|
|
595
|
+
};
|
|
596
|
+
|
|
477
597
|
declare const AnthropicMessageBatchResponseSchema: z.ZodObject<{
|
|
478
598
|
id: z.ZodString;
|
|
479
599
|
processing_status: z.ZodEnum<{
|
|
@@ -531,6 +651,13 @@ type AnthropicBatchResult = {
|
|
|
531
651
|
outcome: AnthropicBatchResultOutcome;
|
|
532
652
|
};
|
|
533
653
|
|
|
654
|
+
declare const anthropicBatchTraceWorkflowName = "anthropic-message-batch";
|
|
655
|
+
type AnthropicBatchTraceEventHandler = (traceEvent: TraceEvent) => void;
|
|
656
|
+
type AnthropicBatchSubmittedRequestSummary = {
|
|
657
|
+
customId: string;
|
|
658
|
+
model: string;
|
|
659
|
+
};
|
|
660
|
+
|
|
534
661
|
declare const defaultAnthropicBatchPollIntervalMs = 5000;
|
|
535
662
|
declare const defaultAnthropicBatchTimeoutMs = 3600000;
|
|
536
663
|
type AnthropicBatchClientOptions = {
|
|
@@ -538,13 +665,8 @@ type AnthropicBatchClientOptions = {
|
|
|
538
665
|
apiKeyName?: string;
|
|
539
666
|
baseURL?: string;
|
|
540
667
|
fetchImplementation?: typeof fetch;
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
customId: string;
|
|
544
|
-
model: string;
|
|
545
|
-
messages: ChatMessage[];
|
|
546
|
-
maxOutputTokens?: number;
|
|
547
|
-
temperature?: number;
|
|
668
|
+
onTraceEvent?: AnthropicBatchTraceEventHandler;
|
|
669
|
+
metadata?: RunMetadata;
|
|
548
670
|
};
|
|
549
671
|
type AnthropicBatchWaitOptions = {
|
|
550
672
|
pollIntervalMs?: number;
|
|
@@ -559,4 +681,114 @@ type AnthropicBatchClient = {
|
|
|
559
681
|
};
|
|
560
682
|
declare function createAnthropicBatchClient(options: AnthropicBatchClientOptions): AnthropicBatchClient;
|
|
561
683
|
|
|
562
|
-
|
|
684
|
+
declare const anthropicBatchJsonOnlySystemInstruction = "Respond with a single JSON object that satisfies the caller's requested structure. Output only valid JSON with no surrounding text.";
|
|
685
|
+
declare function parseAnthropicBatchStructuredContent<T>(content: string, schema: ValidationSchema<T>): T;
|
|
686
|
+
|
|
687
|
+
declare const defaultAzureOpenAiApiVersion = "2024-10-21";
|
|
688
|
+
type AzureOpenAiAdapterOptions = {
|
|
689
|
+
deployment: string;
|
|
690
|
+
resourceName?: string;
|
|
691
|
+
baseURL?: string;
|
|
692
|
+
apiVersion?: string;
|
|
693
|
+
apiKey?: string;
|
|
694
|
+
apiKeyName?: string;
|
|
695
|
+
fetchImplementation?: typeof fetch;
|
|
696
|
+
temperature?: number;
|
|
697
|
+
maxOutputTokens?: number;
|
|
698
|
+
retry?: ProviderRetryOptions;
|
|
699
|
+
extraBody?: Record<string, JsonValue>;
|
|
700
|
+
};
|
|
701
|
+
type AzureOpenAiChatRequestBody = Omit<OpenAiRequestBody, "model">;
|
|
702
|
+
declare function azureOpenai(options: AzureOpenAiAdapterOptions): ModelAdapter;
|
|
703
|
+
declare function buildAzureOpenAiChatCompletionsUrl(options: AzureOpenAiAdapterOptions): string;
|
|
704
|
+
declare function buildAzureOpenAiChatRequestBody(input: OpenAiCallInput): AzureOpenAiChatRequestBody;
|
|
705
|
+
|
|
706
|
+
declare const AzureOpenAiUsageSchema: z.ZodObject<{
|
|
707
|
+
prompt_tokens: z.ZodNumber;
|
|
708
|
+
completion_tokens: z.ZodNumber;
|
|
709
|
+
total_tokens: z.ZodNumber;
|
|
710
|
+
}, z.core.$strip>;
|
|
711
|
+
type AzureOpenAiUsage = z.infer<typeof AzureOpenAiUsageSchema>;
|
|
712
|
+
declare const AzureOpenAiChatCompletionResponseSchema: z.ZodObject<{
|
|
713
|
+
choices: z.ZodArray<z.ZodObject<{
|
|
714
|
+
message: z.ZodObject<{
|
|
715
|
+
content: z.ZodNullable<z.ZodString>;
|
|
716
|
+
tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
717
|
+
id: z.ZodString;
|
|
718
|
+
function: z.ZodObject<{
|
|
719
|
+
name: z.ZodString;
|
|
720
|
+
arguments: z.ZodString;
|
|
721
|
+
}, z.core.$strip>;
|
|
722
|
+
}, z.core.$strip>>>;
|
|
723
|
+
}, z.core.$strip>;
|
|
724
|
+
finish_reason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
725
|
+
}, z.core.$strip>>;
|
|
726
|
+
usage: z.ZodObject<{
|
|
727
|
+
prompt_tokens: z.ZodNumber;
|
|
728
|
+
completion_tokens: z.ZodNumber;
|
|
729
|
+
total_tokens: z.ZodNumber;
|
|
730
|
+
}, z.core.$strip>;
|
|
731
|
+
}, z.core.$strip>;
|
|
732
|
+
type AzureOpenAiChatCompletionResponse = z.infer<typeof AzureOpenAiChatCompletionResponseSchema>;
|
|
733
|
+
declare function mapAzureOpenAiResponseToChatCompletionResult(response: AzureOpenAiChatCompletionResponse, latencyMs: number): ChatCompletionResult;
|
|
734
|
+
declare function parseAzureOpenAiToolArgumentsJson(argumentsJsonText: string): JsonValue;
|
|
735
|
+
declare function normalizeAzureOpenAiFinishReason(finishReason: string): ChatStopReason;
|
|
736
|
+
declare function mapAzureOpenAiUsageToTokenUsage(usage: AzureOpenAiUsage): TokenUsage;
|
|
737
|
+
|
|
738
|
+
type AzureOpenAiStreamRequestBody = Omit<OpenAiRequestBody, "model"> & {
|
|
739
|
+
stream: true;
|
|
740
|
+
stream_options: {
|
|
741
|
+
include_usage: boolean;
|
|
742
|
+
};
|
|
743
|
+
};
|
|
744
|
+
type AzureOpenAiStreamRequestInput = {
|
|
745
|
+
url: string;
|
|
746
|
+
headers: Record<string, string>;
|
|
747
|
+
body: AzureOpenAiStreamRequestBody;
|
|
748
|
+
fetchImplementation: typeof fetch;
|
|
749
|
+
retry?: ProviderRetryOptions;
|
|
750
|
+
abortSignal?: AbortSignal;
|
|
751
|
+
};
|
|
752
|
+
declare function streamAzureOpenAiChatCompletion(input: AzureOpenAiStreamRequestInput): AsyncGenerator<ChatStreamEvent, void, void>;
|
|
753
|
+
declare function parseAzureOpenAiStreamEvents(body: ReadableStream<Uint8Array>, startedAt: number, abortSignal: AbortSignal | undefined): AsyncGenerator<ChatStreamEvent, void, void>;
|
|
754
|
+
|
|
755
|
+
declare const awsSigV4Algorithm = "AWS4-HMAC-SHA256";
|
|
756
|
+
type AwsCredentials = {
|
|
757
|
+
accessKeyId: string;
|
|
758
|
+
secretAccessKey: string;
|
|
759
|
+
sessionToken?: string;
|
|
760
|
+
};
|
|
761
|
+
type AwsSigV4SigningInput = {
|
|
762
|
+
method: string;
|
|
763
|
+
url: URL;
|
|
764
|
+
headers: Record<string, string>;
|
|
765
|
+
bodyText: string;
|
|
766
|
+
region: string;
|
|
767
|
+
service: string;
|
|
768
|
+
credentials: AwsCredentials;
|
|
769
|
+
signingDate?: Date;
|
|
770
|
+
};
|
|
771
|
+
declare function signAwsRequestWithSigV4(input: AwsSigV4SigningInput): Promise<Record<string, string>>;
|
|
772
|
+
|
|
773
|
+
declare const bedrockAnthropicVersion = "bedrock-2023-05-31";
|
|
774
|
+
declare const defaultBedrockMaxOutputTokens = 1024;
|
|
775
|
+
type BedrockCredentials = AwsCredentials;
|
|
776
|
+
type BedrockAdapterOptions = {
|
|
777
|
+
region: string;
|
|
778
|
+
modelId: string;
|
|
779
|
+
credentials?: BedrockCredentials;
|
|
780
|
+
fetchImplementation?: typeof fetch;
|
|
781
|
+
temperature?: number;
|
|
782
|
+
maxOutputTokens?: number;
|
|
783
|
+
retry?: ProviderRetryOptions;
|
|
784
|
+
extraBody?: Record<string, JsonValue>;
|
|
785
|
+
};
|
|
786
|
+
type BedrockInvokeModelRequestBody = Omit<AnthropicRequestBody, "model" | "stream"> & {
|
|
787
|
+
anthropic_version: string;
|
|
788
|
+
};
|
|
789
|
+
declare function bedrock(options: BedrockAdapterOptions): ModelAdapter;
|
|
790
|
+
declare function buildBedrockInvokeModelUrl(region: string, modelId: string): string;
|
|
791
|
+
declare function resolveBedrockCredentials(options: BedrockAdapterOptions): BedrockCredentials;
|
|
792
|
+
declare function buildBedrockInvokeModelRequestBody(input: AnthropicRequestInput): BedrockInvokeModelRequestBody;
|
|
793
|
+
|
|
794
|
+
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 AnthropicOutputConfig, 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 AwsCredentials, type AwsSigV4SigningInput, type AzureOpenAiAdapterOptions, type AzureOpenAiChatCompletionResponse, AzureOpenAiChatCompletionResponseSchema, type AzureOpenAiChatRequestBody, type AzureOpenAiStreamRequestBody, type AzureOpenAiStreamRequestInput, type AzureOpenAiUsage, type BedrockAdapterOptions, type BedrockCredentials, type BedrockInvokeModelRequestBody, 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 OpenAiResponseFormat, type OpenAiToolChoice, type OpenAiToolDefinition, type ProviderExtraBody, type ProviderRetryOptions, type ResolveProviderApiKeyInput, type StructuredOutputRequest, type StructuredOutputResult, anthropic, anthropicBatchJsonOnlySystemInstruction, anthropicBatchTraceWorkflowName, applyCacheControlToLastContentBlock, awsSigV4Algorithm, azureOpenai, bedrock, bedrockAnthropicVersion, buildAnthropicCacheControl, buildAnthropicRequestBody, buildAnthropicStructuredOutputJsonSchema, buildAzureOpenAiChatCompletionsUrl, buildAzureOpenAiChatRequestBody, buildBedrockInvokeModelRequestBody, buildBedrockInvokeModelUrl, buildGeminiResponseSchema, buildOpenAiRequestBody, buildOpenAiStructuredOutputJsonSchema, buildProviderCanceledError, calculateProviderRetryDelayMs, convertZodSchemaToJsonSchema, createAnthropicBatchClient, defaultAnthropicBaseUrl, defaultAnthropicBatchPollIntervalMs, defaultAnthropicBatchTimeoutMs, defaultAnthropicMaxOutputTokens, defaultAzureOpenAiApiVersion, defaultBedrockMaxOutputTokens, defaultGeminiBaseUrl, defaultOpenAiBaseUrl, defaultProviderRetryInitialDelayMs, defaultProviderRetryMaxAttempts, defaultProviderRetryMaxDelayMs, estimateModelCallCostUsd, executeAbortableProviderFetch, executeProviderCallWithModelFallback, executeProviderCallWithRetry, extractAnthropicTextContent, extractAnthropicThinkingText, extractAnthropicToolCalls, extractMessageText, gemini, isAbortError, isRetryableProviderAppError, joinSystemMessageText, mapAnthropicResponseToChatCompletionResult, mapAnthropicUsageToTokenUsage, mapAzureOpenAiResponseToChatCompletionResult, mapAzureOpenAiUsageToTokenUsage, mapChatMessageToAnthropicRequestMessage, mapChatMessageToOpenAiRequestMessage, mapModelToolChoiceToAnthropicToolChoice, mapModelToolChoiceToOpenAiToolChoice, mapModelToolDefinitionToOpenAiTool, mapModelToolDefinitionsToAnthropicTools, mergeProviderRequestExtraBody, mockModel, normalizeAnthropicStopReason, normalizeAzureOpenAiFinishReason, openAiStructuredOutputSchemaName, openai, parseAnthropicBatchStructuredContent, parseAnthropicStreamEvents, parseAnthropicToolInputJson, parseAzureOpenAiStreamEvents, parseAzureOpenAiToolArgumentsJson, resolveAnthropicPromptCachingSettings, resolveBedrockCredentials, resolveProviderApiKey, sanitizeJsonSchemaForAnthropicStructuredOutput, sanitizeJsonSchemaForGeminiResponseSchema, sanitizeJsonSchemaForOpenAiStructuredOutput, signAwsRequestWithSigV4, streamAnthropicChatCompletion, streamAzureOpenAiChatCompletion };
|