@absolutejs/ai 0.0.50 → 0.0.52
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/README.md +84 -15
- package/dist/ai/client/index.js +30 -1
- package/dist/ai/client/index.js.map +5 -5
- package/dist/ai/index.js +753 -62
- package/dist/ai/index.js.map +15 -15
- package/dist/ai/providers/anthropic.js +100 -25
- package/dist/ai/providers/anthropic.js.map +5 -5
- package/dist/ai/providers/gemini.js +5 -2
- package/dist/ai/providers/gemini.js.map +4 -4
- package/dist/ai/providers/ollama.js +5 -2
- package/dist/ai/providers/ollama.js.map +4 -4
- package/dist/ai/providers/openai.js +56 -10
- package/dist/ai/providers/openai.js.map +5 -5
- package/dist/ai/providers/openaiCompatible.js +56 -10
- package/dist/ai/providers/openaiCompatible.js.map +5 -5
- package/dist/ai/providers/openaiResponses.js +100 -16
- package/dist/ai/providers/openaiResponses.js.map +5 -5
- package/dist/ai/providers/openrouter.js +1111 -45
- package/dist/ai/providers/openrouter.js.map +10 -9
- package/dist/angular/ai/index.js +30 -1
- package/dist/angular/ai/index.js.map +5 -5
- package/dist/react/ai/index.js +30 -1
- package/dist/react/ai/index.js.map +5 -5
- package/dist/src/ai/client/actions.d.ts +53 -0
- package/dist/src/ai/errors/providerError.d.ts +3 -0
- package/dist/src/ai/index.d.ts +2 -2
- package/dist/src/ai/providers/openrouter.d.ts +56 -3
- package/dist/src/ai/providers/openrouterClient.d.ts +495 -9
- package/dist/src/ai/streamAIWithTools.d.ts +6 -0
- package/dist/svelte/ai/index.js +30 -1
- package/dist/svelte/ai/index.js.map +5 -5
- package/dist/types/ai.d.ts +54 -3
- package/dist/types/anthropic.d.ts +13 -5
- package/dist/vue/ai/index.js +30 -1
- package/dist/vue/ai/index.js.map +5 -5
- package/package.json +1 -1
|
@@ -1,10 +1,96 @@
|
|
|
1
1
|
export type OpenRouterClientConfig = {
|
|
2
2
|
allowedModels?: readonly string[];
|
|
3
3
|
apiKey?: string;
|
|
4
|
+
batchBaseUrl?: string;
|
|
4
5
|
baseUrl?: string;
|
|
5
6
|
fetch?: typeof globalThis.fetch;
|
|
6
7
|
headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
|
|
7
8
|
tokenSource?: () => Promise<string> | string;
|
|
9
|
+
/** Default workspace for APIs that accept explicit workspace selection. */
|
|
10
|
+
workspaceId?: string;
|
|
11
|
+
};
|
|
12
|
+
export type OpenRouterPKCE = {
|
|
13
|
+
codeChallenge: string;
|
|
14
|
+
codeChallengeMethod: "S256";
|
|
15
|
+
codeVerifier: string;
|
|
16
|
+
};
|
|
17
|
+
export type OpenRouterAuthorizationUrlOptions = {
|
|
18
|
+
baseUrl?: string;
|
|
19
|
+
callbackUrl?: string;
|
|
20
|
+
codeChallenge?: string;
|
|
21
|
+
codeChallengeMethod?: "S256" | "plain";
|
|
22
|
+
keyLabel?: string;
|
|
23
|
+
};
|
|
24
|
+
export type OpenRouterAuthCodeExchangeRequest = {
|
|
25
|
+
code: string;
|
|
26
|
+
code_challenge_method?: "S256" | "plain";
|
|
27
|
+
code_verifier?: string;
|
|
28
|
+
};
|
|
29
|
+
export type OpenRouterAuthCodeExchangeResponse = {
|
|
30
|
+
key: string;
|
|
31
|
+
user_id: string | null;
|
|
32
|
+
};
|
|
33
|
+
export type OpenRouterCreateAuthCodeRequest = {
|
|
34
|
+
callback_url: string;
|
|
35
|
+
code_challenge?: string;
|
|
36
|
+
code_challenge_method?: "S256" | "plain";
|
|
37
|
+
expires_at?: string;
|
|
38
|
+
key_label?: string;
|
|
39
|
+
limit?: number;
|
|
40
|
+
usage_limit_type?: string;
|
|
41
|
+
workspace_id?: string;
|
|
42
|
+
};
|
|
43
|
+
export type OpenRouterCreateAuthCodeResponse = {
|
|
44
|
+
data: {
|
|
45
|
+
app_id: number;
|
|
46
|
+
created_at: string;
|
|
47
|
+
id: string;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export type OpenRouterBatchEndpoint = "/v1/chat/completions" | "/v1/responses" | "/v1/messages" | "/v1/embeddings";
|
|
51
|
+
export type OpenRouterBatchStatus = "validating" | "in_progress" | "finalizing" | "completed" | "failed" | "expired" | "cancelling" | "cancelled";
|
|
52
|
+
export type OpenRouterBatchRequest = {
|
|
53
|
+
custom_id: string;
|
|
54
|
+
body: Record<string, unknown>;
|
|
55
|
+
};
|
|
56
|
+
export type OpenRouterBatchResult = {
|
|
57
|
+
custom_id: string;
|
|
58
|
+
id: string;
|
|
59
|
+
response?: {
|
|
60
|
+
body: Record<string, unknown>;
|
|
61
|
+
request_id: string;
|
|
62
|
+
status_code: number;
|
|
63
|
+
};
|
|
64
|
+
error?: Record<string, unknown>;
|
|
65
|
+
};
|
|
66
|
+
export type OpenRouterBatch = {
|
|
67
|
+
id: string;
|
|
68
|
+
endpoint: OpenRouterBatchEndpoint;
|
|
69
|
+
model: string;
|
|
70
|
+
status: OpenRouterBatchStatus;
|
|
71
|
+
completion_window?: "24h";
|
|
72
|
+
created_at?: string;
|
|
73
|
+
completed_at?: string | null;
|
|
74
|
+
request_counts?: {
|
|
75
|
+
completed: number;
|
|
76
|
+
failed: number;
|
|
77
|
+
total: number;
|
|
78
|
+
};
|
|
79
|
+
results?: OpenRouterBatchResult[];
|
|
80
|
+
usage?: {
|
|
81
|
+
completion_tokens: number;
|
|
82
|
+
cost: number;
|
|
83
|
+
is_byok: boolean;
|
|
84
|
+
prompt_tokens: number;
|
|
85
|
+
total_tokens: number;
|
|
86
|
+
};
|
|
87
|
+
[field: string]: unknown;
|
|
88
|
+
};
|
|
89
|
+
export type OpenRouterCreateBatchRequest = {
|
|
90
|
+
endpoint: OpenRouterBatchEndpoint;
|
|
91
|
+
model: string;
|
|
92
|
+
requests: [OpenRouterBatchRequest, ...OpenRouterBatchRequest[]];
|
|
93
|
+
completion_window?: "24h";
|
|
8
94
|
};
|
|
9
95
|
export type OpenRouterModel = {
|
|
10
96
|
id: string;
|
|
@@ -12,13 +98,39 @@ export type OpenRouterModel = {
|
|
|
12
98
|
description?: string;
|
|
13
99
|
context_length?: number;
|
|
14
100
|
architecture?: Record<string, unknown>;
|
|
15
|
-
pricing?:
|
|
101
|
+
pricing?: OpenRouterPricing;
|
|
16
102
|
supported_parameters?: string[] | Record<string, unknown>;
|
|
17
103
|
[field: string]: unknown;
|
|
18
104
|
};
|
|
105
|
+
export type OpenRouterPricingKey = "prompt" | "completion" | "request" | "image" | "web_search" | "internal_reasoning" | "input_cache_read" | "input_cache_write";
|
|
106
|
+
export type OpenRouterPricing = Partial<Record<OpenRouterPricingKey, string>> & Record<string, string | undefined>;
|
|
107
|
+
export type OpenRouterCostUnits = Partial<Record<OpenRouterPricingKey, number>>;
|
|
108
|
+
export type OpenRouterCostEstimate = {
|
|
109
|
+
components: Partial<Record<OpenRouterPricingKey, number>>;
|
|
110
|
+
total: number;
|
|
111
|
+
};
|
|
112
|
+
/** Estimate USD cost using OpenRouter's per-unit model pricing fields. */
|
|
113
|
+
export declare const estimateOpenRouterCost: (pricing: OpenRouterPricing, units: OpenRouterCostUnits) => OpenRouterCostEstimate;
|
|
114
|
+
export declare const estimateOpenRouterModelCost: (model: Pick<OpenRouterModel, "pricing">, units: OpenRouterCostUnits) => OpenRouterCostEstimate;
|
|
19
115
|
export type OpenRouterModelList = {
|
|
20
116
|
data: OpenRouterModel[];
|
|
21
117
|
};
|
|
118
|
+
export type OpenRouterModelQuery = {
|
|
119
|
+
arch?: string;
|
|
120
|
+
context?: number;
|
|
121
|
+
distillable?: "false" | "true";
|
|
122
|
+
input_modalities?: string;
|
|
123
|
+
max_price?: number;
|
|
124
|
+
min_price?: number;
|
|
125
|
+
model_authors?: string;
|
|
126
|
+
output_modalities?: string;
|
|
127
|
+
providers?: string;
|
|
128
|
+
q?: string;
|
|
129
|
+
region?: "eu";
|
|
130
|
+
supported_parameters?: string;
|
|
131
|
+
sort?: "pricing-low-to-high" | "pricing-high-to-low" | "context-high-to-low" | "throughput-high-to-low" | "latency-low-to-high" | "most-popular" | "top-weekly" | "newest" | "intelligence-high-to-low" | "design-arena-elo-high-to-low";
|
|
132
|
+
zdr?: "true";
|
|
133
|
+
};
|
|
22
134
|
export type OpenRouterEmbeddingRequest = {
|
|
23
135
|
model: string;
|
|
24
136
|
input: string | string[] | number[] | number[][];
|
|
@@ -76,6 +188,7 @@ export type OpenRouterImageRequest = {
|
|
|
76
188
|
seed?: number;
|
|
77
189
|
input_references?: Array<Record<string, unknown>>;
|
|
78
190
|
provider?: Record<string, unknown>;
|
|
191
|
+
stream?: boolean;
|
|
79
192
|
};
|
|
80
193
|
export type OpenRouterImageResponse = {
|
|
81
194
|
created: number;
|
|
@@ -85,6 +198,24 @@ export type OpenRouterImageResponse = {
|
|
|
85
198
|
}>;
|
|
86
199
|
usage?: Record<string, number>;
|
|
87
200
|
};
|
|
201
|
+
export type OpenRouterImageModelEndpoint = {
|
|
202
|
+
allowed_passthrough_parameters: string[];
|
|
203
|
+
pricing: Array<{
|
|
204
|
+
billable: string;
|
|
205
|
+
cost_usd: number;
|
|
206
|
+
unit: "image" | "megapixel" | "token" | string;
|
|
207
|
+
variant?: string;
|
|
208
|
+
}>;
|
|
209
|
+
provider_name: string;
|
|
210
|
+
provider_slug: string;
|
|
211
|
+
provider_tag: string | null;
|
|
212
|
+
supported_parameters: Record<string, unknown>;
|
|
213
|
+
supports_streaming: boolean;
|
|
214
|
+
};
|
|
215
|
+
export type OpenRouterImageModelEndpoints = {
|
|
216
|
+
endpoints: OpenRouterImageModelEndpoint[];
|
|
217
|
+
id: string;
|
|
218
|
+
};
|
|
88
219
|
export type OpenRouterResponsesRequest = Record<string, unknown> & {
|
|
89
220
|
input: unknown;
|
|
90
221
|
model: string;
|
|
@@ -96,12 +227,263 @@ export type OpenRouterSpeechRequest = Record<string, unknown> & {
|
|
|
96
227
|
voice: string;
|
|
97
228
|
};
|
|
98
229
|
export type OpenRouterTranscriptionRequest = Record<string, unknown> & {
|
|
230
|
+
input_audio: {
|
|
231
|
+
data: string;
|
|
232
|
+
format: string;
|
|
233
|
+
};
|
|
234
|
+
language?: string;
|
|
99
235
|
model: string;
|
|
236
|
+
provider?: Record<string, unknown>;
|
|
237
|
+
temperature?: number;
|
|
238
|
+
};
|
|
239
|
+
export type OpenRouterTranscriptionResponse = {
|
|
240
|
+
text: string;
|
|
241
|
+
usage: {
|
|
242
|
+
cost: number;
|
|
243
|
+
input_tokens: number;
|
|
244
|
+
output_tokens: number;
|
|
245
|
+
seconds: number;
|
|
246
|
+
total_tokens: number;
|
|
247
|
+
};
|
|
100
248
|
};
|
|
101
249
|
export type OpenRouterVideoRequest = Record<string, unknown> & {
|
|
102
250
|
model: string;
|
|
103
251
|
prompt: string;
|
|
104
252
|
};
|
|
253
|
+
export type OpenRouterImageStreamEvent = Record<string, unknown> & {
|
|
254
|
+
type: string;
|
|
255
|
+
b64_json?: string;
|
|
256
|
+
media_type?: string;
|
|
257
|
+
partial_image_index?: number;
|
|
258
|
+
usage?: Record<string, number>;
|
|
259
|
+
};
|
|
260
|
+
export type OpenRouterFile = {
|
|
261
|
+
created_at: string;
|
|
262
|
+
downloadable: boolean;
|
|
263
|
+
filename: string;
|
|
264
|
+
id: string;
|
|
265
|
+
mime_type: string;
|
|
266
|
+
size_bytes: number;
|
|
267
|
+
type: "file";
|
|
268
|
+
};
|
|
269
|
+
export type OpenRouterFileList = {
|
|
270
|
+
cursor: string | null;
|
|
271
|
+
data: OpenRouterFile[];
|
|
272
|
+
first_id: string | null;
|
|
273
|
+
has_more: boolean;
|
|
274
|
+
last_id: string | null;
|
|
275
|
+
};
|
|
276
|
+
export type OpenRouterVideoJob = {
|
|
277
|
+
error?: string;
|
|
278
|
+
generation_id?: string | null;
|
|
279
|
+
id: string;
|
|
280
|
+
polling_url?: string;
|
|
281
|
+
status: "pending" | "in_progress" | "completed" | "failed" | "cancelled" | "expired";
|
|
282
|
+
unsigned_urls?: string[];
|
|
283
|
+
usage?: {
|
|
284
|
+
cost?: number;
|
|
285
|
+
is_byok?: boolean;
|
|
286
|
+
};
|
|
287
|
+
};
|
|
288
|
+
export type OpenRouterVideoWebhookEvent = {
|
|
289
|
+
created_at: string;
|
|
290
|
+
data: OpenRouterVideoJob & {
|
|
291
|
+
model?: string | null;
|
|
292
|
+
};
|
|
293
|
+
type: "video.generation.completed" | "video.generation.failed" | "video.generation.cancelled" | "video.generation.expired";
|
|
294
|
+
};
|
|
295
|
+
export type OpenRouterZdrEndpoint = Record<string, unknown> & {
|
|
296
|
+
context_length: number;
|
|
297
|
+
model_id: string;
|
|
298
|
+
model_name: string;
|
|
299
|
+
name: string;
|
|
300
|
+
pricing: Record<string, string>;
|
|
301
|
+
provider_name: string;
|
|
302
|
+
supported_parameters: string[];
|
|
303
|
+
tag: string;
|
|
304
|
+
};
|
|
305
|
+
export type OpenRouterPresetVersion = {
|
|
306
|
+
config: Record<string, unknown>;
|
|
307
|
+
created_at: string;
|
|
308
|
+
creator_id: string;
|
|
309
|
+
id: string;
|
|
310
|
+
preset_id: string;
|
|
311
|
+
system_prompt: string | null;
|
|
312
|
+
updated_at: string | null;
|
|
313
|
+
version: number;
|
|
314
|
+
};
|
|
315
|
+
export type OpenRouterPreset = {
|
|
316
|
+
created_at: string;
|
|
317
|
+
creator_user_id: string;
|
|
318
|
+
designated_version: OpenRouterPresetVersion;
|
|
319
|
+
designated_version_id: string;
|
|
320
|
+
description: string | null;
|
|
321
|
+
id: string;
|
|
322
|
+
name: string;
|
|
323
|
+
slug: string;
|
|
324
|
+
status: string;
|
|
325
|
+
status_updated_at: string | null;
|
|
326
|
+
updated_at: string | null;
|
|
327
|
+
workspace_id: string;
|
|
328
|
+
};
|
|
329
|
+
export type OpenRouterPresetResponse = {
|
|
330
|
+
data: OpenRouterPreset;
|
|
331
|
+
};
|
|
332
|
+
export type OpenRouterPresetVersionResponse = {
|
|
333
|
+
data: OpenRouterPresetVersion;
|
|
334
|
+
};
|
|
335
|
+
export type OpenRouterPresetInferenceRequest = Record<string, unknown> & {
|
|
336
|
+
model?: string;
|
|
337
|
+
models?: string[];
|
|
338
|
+
};
|
|
339
|
+
export type OpenRouterActivityQuery = {
|
|
340
|
+
api_key_hash?: string;
|
|
341
|
+
date?: string;
|
|
342
|
+
user_id?: string;
|
|
343
|
+
workspace_id?: string;
|
|
344
|
+
};
|
|
345
|
+
export type OpenRouterActivityItem = {
|
|
346
|
+
byok_usage_inference: number;
|
|
347
|
+
completion_tokens: number;
|
|
348
|
+
date: string;
|
|
349
|
+
endpoint_id: string;
|
|
350
|
+
model: string;
|
|
351
|
+
model_permaslug: string;
|
|
352
|
+
prompt_tokens: number;
|
|
353
|
+
provider_name: string;
|
|
354
|
+
reasoning_tokens: number;
|
|
355
|
+
requests: number;
|
|
356
|
+
usage: number;
|
|
357
|
+
workspace_id?: string;
|
|
358
|
+
};
|
|
359
|
+
export type OpenRouterAnalyticsQuery = {
|
|
360
|
+
metrics: [string, ...string[]];
|
|
361
|
+
dimensions?: string[];
|
|
362
|
+
filters?: Array<{
|
|
363
|
+
field: string;
|
|
364
|
+
operator: string;
|
|
365
|
+
value: unknown;
|
|
366
|
+
}>;
|
|
367
|
+
granularity?: string;
|
|
368
|
+
group_limit?: number;
|
|
369
|
+
limit?: number;
|
|
370
|
+
order_by?: {
|
|
371
|
+
direction: "asc" | "desc";
|
|
372
|
+
field: string;
|
|
373
|
+
};
|
|
374
|
+
time_range?: {
|
|
375
|
+
end: string;
|
|
376
|
+
start: string;
|
|
377
|
+
};
|
|
378
|
+
};
|
|
379
|
+
export type OpenRouterAnalyticsResponse = {
|
|
380
|
+
data: {
|
|
381
|
+
data: Record<string, unknown>[];
|
|
382
|
+
metadata: {
|
|
383
|
+
query_time_ms: number;
|
|
384
|
+
row_count: number;
|
|
385
|
+
truncated: boolean;
|
|
386
|
+
};
|
|
387
|
+
};
|
|
388
|
+
};
|
|
389
|
+
export type OpenRouterAnalyticsMeta = {
|
|
390
|
+
data: {
|
|
391
|
+
dimensions: Array<{
|
|
392
|
+
display_label: string;
|
|
393
|
+
name: string;
|
|
394
|
+
}>;
|
|
395
|
+
granularities: Array<{
|
|
396
|
+
display_label: string;
|
|
397
|
+
name: string;
|
|
398
|
+
}>;
|
|
399
|
+
metrics: Array<{
|
|
400
|
+
display_format: string;
|
|
401
|
+
display_label: string;
|
|
402
|
+
is_rate: boolean;
|
|
403
|
+
name: string;
|
|
404
|
+
}>;
|
|
405
|
+
operators: Array<{
|
|
406
|
+
name: string;
|
|
407
|
+
value_type: string;
|
|
408
|
+
}>;
|
|
409
|
+
};
|
|
410
|
+
};
|
|
411
|
+
export type OpenRouterTaskClassifications = {
|
|
412
|
+
data: {
|
|
413
|
+
as_of: string;
|
|
414
|
+
classifications: Array<{
|
|
415
|
+
category_token_share: number;
|
|
416
|
+
category_usage_share: number;
|
|
417
|
+
display_name: string;
|
|
418
|
+
macro_category: string;
|
|
419
|
+
models: Array<{
|
|
420
|
+
id: string;
|
|
421
|
+
tag_token_share: number;
|
|
422
|
+
tag_usage_share: number;
|
|
423
|
+
}>;
|
|
424
|
+
tag: string;
|
|
425
|
+
token_share: number;
|
|
426
|
+
usage_share: number;
|
|
427
|
+
}>;
|
|
428
|
+
macro_categories: Array<{
|
|
429
|
+
key: string;
|
|
430
|
+
label: string;
|
|
431
|
+
token_share: number;
|
|
432
|
+
usage_share: number;
|
|
433
|
+
}>;
|
|
434
|
+
window_days: 7;
|
|
435
|
+
};
|
|
436
|
+
};
|
|
437
|
+
export type OpenRouterWorkspace = {
|
|
438
|
+
created_at: string;
|
|
439
|
+
created_by: string;
|
|
440
|
+
default_image_model: string | null;
|
|
441
|
+
default_provider_sort: "price" | "throughput" | "latency" | "exacto" | null;
|
|
442
|
+
default_text_model: string | null;
|
|
443
|
+
description: string | null;
|
|
444
|
+
id: string;
|
|
445
|
+
io_logging_api_key_ids: number[] | null;
|
|
446
|
+
io_logging_sampling_rate: number;
|
|
447
|
+
is_data_discount_logging_enabled: boolean;
|
|
448
|
+
is_observability_broadcast_enabled: boolean;
|
|
449
|
+
is_observability_io_logging_enabled: boolean;
|
|
450
|
+
name: string;
|
|
451
|
+
slug: string;
|
|
452
|
+
updated_at: string | null;
|
|
453
|
+
};
|
|
454
|
+
export type OpenRouterWorkspaceOptions = {
|
|
455
|
+
default_image_model?: string | null;
|
|
456
|
+
default_provider_sort?: OpenRouterWorkspace["default_provider_sort"];
|
|
457
|
+
default_text_model?: string | null;
|
|
458
|
+
description?: string | null;
|
|
459
|
+
io_logging_api_key_ids?: number[] | null;
|
|
460
|
+
io_logging_sampling_rate?: number;
|
|
461
|
+
is_data_discount_logging_enabled?: boolean;
|
|
462
|
+
is_observability_broadcast_enabled?: boolean;
|
|
463
|
+
is_observability_io_logging_enabled?: boolean;
|
|
464
|
+
name?: string;
|
|
465
|
+
slug?: string;
|
|
466
|
+
};
|
|
467
|
+
export type OpenRouterCreateWorkspaceRequest = OpenRouterWorkspaceOptions & {
|
|
468
|
+
name: string;
|
|
469
|
+
slug: string;
|
|
470
|
+
};
|
|
471
|
+
export type OpenRouterWorkspaceBudgetInterval = "daily" | "weekly" | "monthly" | "lifetime";
|
|
472
|
+
export type OpenRouterWorkspaceBudget = {
|
|
473
|
+
created_at: string;
|
|
474
|
+
id: string;
|
|
475
|
+
limit_usd: number;
|
|
476
|
+
reset_interval: OpenRouterWorkspaceBudgetInterval;
|
|
477
|
+
updated_at: string | null;
|
|
478
|
+
workspace_id: string;
|
|
479
|
+
};
|
|
480
|
+
export type OpenRouterWorkspaceMember = {
|
|
481
|
+
created_at: string;
|
|
482
|
+
id: string;
|
|
483
|
+
role: string;
|
|
484
|
+
user_id: string;
|
|
485
|
+
workspace_id: string;
|
|
486
|
+
};
|
|
105
487
|
export type OpenRouterHttpRequestOptions = Omit<RequestInit, "body" | "headers"> & {
|
|
106
488
|
body?: unknown;
|
|
107
489
|
headers?: HeadersInit;
|
|
@@ -109,28 +491,104 @@ export type OpenRouterHttpRequestOptions = Omit<RequestInit, "body" | "headers">
|
|
|
109
491
|
};
|
|
110
492
|
export type OpenRouterClient = ReturnType<typeof createOpenRouterClient>;
|
|
111
493
|
export declare const openRouterModelMatchesRule: (model: string, rule: string) => boolean;
|
|
494
|
+
export declare const generateOpenRouterPKCE: () => Promise<OpenRouterPKCE>;
|
|
495
|
+
export declare const createOpenRouterAuthorizationUrl: (options?: OpenRouterAuthorizationUrlOptions) => string;
|
|
496
|
+
/** Exchange a single-use OAuth code. This endpoint intentionally has no API-key authentication. */
|
|
497
|
+
export declare const exchangeOpenRouterAuthCode: (body: OpenRouterAuthCodeExchangeRequest, options?: {
|
|
498
|
+
baseUrl?: string;
|
|
499
|
+
fetch?: typeof globalThis.fetch;
|
|
500
|
+
}) => Promise<OpenRouterAuthCodeExchangeResponse>;
|
|
501
|
+
export declare const createOpenRouterKeyLinks: (key: string, siteUrl?: string) => Promise<{
|
|
502
|
+
hash: string;
|
|
503
|
+
logsUrl: string;
|
|
504
|
+
settingsUrl: string;
|
|
505
|
+
}>;
|
|
506
|
+
/** Verify `X-OpenRouter-Signature` against the exact raw webhook bytes. */
|
|
507
|
+
export declare const verifyOpenRouterWebhookSignature: (options: {
|
|
508
|
+
body: string | Uint8Array;
|
|
509
|
+
header: string;
|
|
510
|
+
secret: string;
|
|
511
|
+
nowSeconds?: number;
|
|
512
|
+
toleranceSeconds?: number;
|
|
513
|
+
}) => Promise<boolean>;
|
|
112
514
|
export declare const createOpenRouterClient: (config: OpenRouterClientConfig) => {
|
|
113
|
-
|
|
114
|
-
|
|
515
|
+
addWorkspaceMembers: (id: string, userIds: readonly string[]) => Promise<{
|
|
516
|
+
added_count: number;
|
|
517
|
+
data: OpenRouterWorkspaceMember[];
|
|
518
|
+
}>;
|
|
519
|
+
createAuthCode: (body: OpenRouterCreateAuthCodeRequest) => Promise<OpenRouterCreateAuthCodeResponse>;
|
|
520
|
+
createPresetFromChatCompletions: (slug: string, body: OpenRouterPresetInferenceRequest) => Promise<OpenRouterPresetResponse>;
|
|
521
|
+
createPresetFromMessages: (slug: string, body: OpenRouterPresetInferenceRequest) => Promise<OpenRouterPresetResponse>;
|
|
522
|
+
createPresetFromResponses: (slug: string, body: OpenRouterPresetInferenceRequest) => Promise<OpenRouterPresetResponse>;
|
|
523
|
+
createWorkspace: (body: OpenRouterCreateWorkspaceRequest) => Promise<{
|
|
524
|
+
data: OpenRouterWorkspace;
|
|
525
|
+
}>;
|
|
526
|
+
createBatch: (body: OpenRouterCreateBatchRequest) => Promise<OpenRouterBatch>;
|
|
115
527
|
createEmbedding: (body: OpenRouterEmbeddingRequest) => Promise<OpenRouterEmbeddingResponse>;
|
|
116
528
|
generateImage: (body: OpenRouterImageRequest) => Promise<OpenRouterImageResponse>;
|
|
117
|
-
|
|
118
|
-
|
|
529
|
+
deleteFile: (id: string, workspaceId?: string | undefined) => Promise<{
|
|
530
|
+
id: string;
|
|
531
|
+
type: "file_deleted";
|
|
532
|
+
}>;
|
|
533
|
+
deleteWorkspace: (id: string) => Promise<{
|
|
534
|
+
deleted: true;
|
|
535
|
+
}>;
|
|
536
|
+
deleteWorkspaceBudget: (id: string, interval: OpenRouterWorkspaceBudgetInterval) => Promise<{
|
|
537
|
+
deleted: true;
|
|
538
|
+
}>;
|
|
539
|
+
downloadFile: (id: string, workspaceId?: string | undefined) => Promise<Response>;
|
|
540
|
+
downloadVideo: (id: string, index?: number) => Promise<Response>;
|
|
541
|
+
generateVideo: (body: OpenRouterVideoRequest) => Promise<OpenRouterVideoJob>;
|
|
542
|
+
getBatch: (id: string) => Promise<OpenRouterBatch>;
|
|
543
|
+
getActivity: (query?: OpenRouterActivityQuery) => Promise<{
|
|
544
|
+
data: OpenRouterActivityItem[];
|
|
545
|
+
}>;
|
|
546
|
+
getAnalyticsMeta: () => Promise<OpenRouterAnalyticsMeta>;
|
|
119
547
|
getCredits: () => Promise<{
|
|
120
548
|
data: Record<string, number>;
|
|
121
549
|
}>;
|
|
122
550
|
getCurrentKey: () => Promise<{
|
|
123
551
|
data: Record<string, unknown>;
|
|
124
552
|
}>;
|
|
553
|
+
getFile: (id: string, workspaceId?: string | undefined) => Promise<OpenRouterFile>;
|
|
125
554
|
getGeneration: (id: string) => Promise<{
|
|
126
555
|
data: Record<string, unknown>;
|
|
127
556
|
}>;
|
|
557
|
+
getGenerationContent: (id: string) => Promise<Record<string, unknown>>;
|
|
128
558
|
getModelEndpoints: (model: string) => Promise<Record<string, unknown>>;
|
|
129
|
-
|
|
559
|
+
getModel: (model: string) => Promise<{
|
|
560
|
+
data: OpenRouterModel;
|
|
561
|
+
}>;
|
|
562
|
+
getImageModelEndpoints: (model: string) => Promise<OpenRouterImageModelEndpoints>;
|
|
563
|
+
getPreset: (slug: string) => Promise<OpenRouterPresetResponse>;
|
|
564
|
+
getPresetVersion: (slug: string, version: number | string) => Promise<OpenRouterPresetVersionResponse>;
|
|
565
|
+
getTaskClassifications: (window?: "7d") => Promise<OpenRouterTaskClassifications>;
|
|
566
|
+
getVideo: (id: string) => Promise<OpenRouterVideoJob>;
|
|
567
|
+
getWorkspace: (id: string) => Promise<{
|
|
568
|
+
data: OpenRouterWorkspace;
|
|
569
|
+
}>;
|
|
130
570
|
listImageModels: () => Promise<OpenRouterModelList>;
|
|
131
|
-
|
|
571
|
+
listFiles: (query?: {
|
|
572
|
+
cursor?: string;
|
|
573
|
+
limit?: number;
|
|
574
|
+
workspace_id?: string;
|
|
575
|
+
}) => Promise<OpenRouterFileList>;
|
|
576
|
+
listModels: (query?: OpenRouterModelQuery) => Promise<OpenRouterModelList>;
|
|
577
|
+
listUserModels: () => Promise<OpenRouterModelList>;
|
|
578
|
+
listZdrEndpoints: () => Promise<{
|
|
579
|
+
data: OpenRouterZdrEndpoint[];
|
|
580
|
+
}>;
|
|
581
|
+
countModels: (outputModalities?: string) => Promise<{
|
|
582
|
+
data: {
|
|
583
|
+
count: number;
|
|
584
|
+
};
|
|
585
|
+
}>;
|
|
132
586
|
listPresets: (offset?: number, limit?: number) => Promise<{
|
|
133
|
-
data:
|
|
587
|
+
data: OpenRouterPreset[];
|
|
588
|
+
total_count: number;
|
|
589
|
+
}>;
|
|
590
|
+
listPresetVersions: (slug: string, offset?: number, limit?: number) => Promise<{
|
|
591
|
+
data: OpenRouterPresetVersion[];
|
|
134
592
|
total_count: number;
|
|
135
593
|
}>;
|
|
136
594
|
listProviders: () => Promise<{
|
|
@@ -138,10 +596,38 @@ export declare const createOpenRouterClient: (config: OpenRouterClientConfig) =>
|
|
|
138
596
|
}>;
|
|
139
597
|
listRerankModels: () => Promise<OpenRouterModelList>;
|
|
140
598
|
listVideoModels: () => Promise<OpenRouterModelList>;
|
|
599
|
+
listWorkspaceBudgets: (id: string) => Promise<{
|
|
600
|
+
data: OpenRouterWorkspaceBudget[];
|
|
601
|
+
}>;
|
|
602
|
+
listWorkspaces: (offset?: number, limit?: number) => Promise<{
|
|
603
|
+
data: OpenRouterWorkspace[];
|
|
604
|
+
total_count: number;
|
|
605
|
+
}>;
|
|
606
|
+
queryAnalytics: (body: OpenRouterAnalyticsQuery) => Promise<OpenRouterAnalyticsResponse>;
|
|
607
|
+
removeWorkspaceMembers: (id: string, userIds: readonly string[]) => Promise<{
|
|
608
|
+
data: OpenRouterWorkspaceMember[];
|
|
609
|
+
removed_count: number;
|
|
610
|
+
}>;
|
|
141
611
|
request: <T>(path: string, options?: OpenRouterHttpRequestOptions) => Promise<T>;
|
|
142
612
|
requestRaw: (path: string, options?: OpenRouterHttpRequestOptions) => Promise<Response>;
|
|
613
|
+
streamImage: (body: Omit<OpenRouterImageRequest, "stream">, options?: Omit<OpenRouterHttpRequestOptions, "body" | "method">) => AsyncGenerator<OpenRouterImageStreamEvent, void, any>;
|
|
143
614
|
respond: (body: OpenRouterResponsesRequest) => Promise<Response> | Promise<Record<string, unknown>>;
|
|
144
615
|
rerank: (body: OpenRouterRerankRequest) => Promise<OpenRouterRerankResponse>;
|
|
145
616
|
speak: (body: OpenRouterSpeechRequest) => Promise<Response>;
|
|
146
|
-
transcribe: (body: OpenRouterTranscriptionRequest | FormData) => Promise<
|
|
617
|
+
transcribe: (body: OpenRouterTranscriptionRequest | FormData) => Promise<OpenRouterTranscriptionResponse>;
|
|
618
|
+
uploadFile: (file: Blob, options?: {
|
|
619
|
+
filename?: string;
|
|
620
|
+
workspaceId?: string;
|
|
621
|
+
}) => Promise<OpenRouterFile>;
|
|
622
|
+
updateWorkspace: (id: string, body: OpenRouterWorkspaceOptions) => Promise<{
|
|
623
|
+
data: OpenRouterWorkspace;
|
|
624
|
+
}>;
|
|
625
|
+
upsertWorkspaceBudget: (id: string, interval: OpenRouterWorkspaceBudgetInterval, limitUsd: number) => Promise<{
|
|
626
|
+
data: OpenRouterWorkspaceBudget;
|
|
627
|
+
}>;
|
|
628
|
+
waitForBatch: (id: string, options?: {
|
|
629
|
+
intervalMs?: number;
|
|
630
|
+
signal?: AbortSignal;
|
|
631
|
+
timeoutMs?: number;
|
|
632
|
+
}) => Promise<OpenRouterBatch>;
|
|
147
633
|
};
|
|
@@ -23,6 +23,12 @@ export type StreamAIWithToolsEvent = {
|
|
|
23
23
|
} | {
|
|
24
24
|
type: "text";
|
|
25
25
|
content: string;
|
|
26
|
+
} | {
|
|
27
|
+
type: "audio";
|
|
28
|
+
data: string;
|
|
29
|
+
format: string;
|
|
30
|
+
transcript?: string;
|
|
31
|
+
audioId?: string;
|
|
26
32
|
}
|
|
27
33
|
/** A model turn finished streaming — carries that turn's own usage, so
|
|
28
34
|
* metering can bill per-turn instead of waiting for the summed total. */
|
package/dist/svelte/ai/index.js
CHANGED
|
@@ -106,6 +106,16 @@ var serverMessageToAction = (message) => {
|
|
|
106
106
|
revisedPrompt: message.revisedPrompt,
|
|
107
107
|
type: "image"
|
|
108
108
|
};
|
|
109
|
+
case "audio":
|
|
110
|
+
return {
|
|
111
|
+
audioId: message.audioId,
|
|
112
|
+
conversationId: message.conversationId,
|
|
113
|
+
data: message.data,
|
|
114
|
+
format: message.format,
|
|
115
|
+
messageId: message.messageId,
|
|
116
|
+
transcript: message.transcript,
|
|
117
|
+
type: "audio"
|
|
118
|
+
};
|
|
109
119
|
case "complete":
|
|
110
120
|
return {
|
|
111
121
|
conversationId: message.conversationId,
|
|
@@ -181,6 +191,8 @@ var isValidAIServerMessage = (data) => {
|
|
|
181
191
|
return "name" in data && "status" in data && "messageId" in data && "conversationId" in data;
|
|
182
192
|
case "image":
|
|
183
193
|
return "data" in data && typeof data.data === "string" && "format" in data && typeof data.format === "string" && "isPartial" in data && typeof data.isPartial === "boolean" && "messageId" in data && "conversationId" in data;
|
|
194
|
+
case "audio":
|
|
195
|
+
return "data" in data && typeof data.data === "string" && "format" in data && typeof data.format === "string" && "messageId" in data && "conversationId" in data;
|
|
184
196
|
case "complete":
|
|
185
197
|
return "messageId" in data && "conversationId" in data;
|
|
186
198
|
case "turn_queued":
|
|
@@ -543,6 +555,20 @@ var handleImage = (state, action) => {
|
|
|
543
555
|
});
|
|
544
556
|
conversation.messages = [...conversation.messages];
|
|
545
557
|
};
|
|
558
|
+
var handleAudio = (state, action) => {
|
|
559
|
+
const conversation = getOrCreate(state, action.conversationId);
|
|
560
|
+
const message = getOrCreateAssistantMessage(conversation, action.messageId, action.conversationId);
|
|
561
|
+
message.audio = [
|
|
562
|
+
...message.audio ?? [],
|
|
563
|
+
{
|
|
564
|
+
audioId: action.audioId,
|
|
565
|
+
data: action.data,
|
|
566
|
+
format: action.format,
|
|
567
|
+
transcript: action.transcript
|
|
568
|
+
}
|
|
569
|
+
];
|
|
570
|
+
conversation.messages = [...conversation.messages];
|
|
571
|
+
};
|
|
546
572
|
var handleComplete = (state, action) => {
|
|
547
573
|
const conversation = state.conversations.get(action.conversationId);
|
|
548
574
|
if (conversation) {
|
|
@@ -613,6 +639,9 @@ var applyAction = (state, action) => {
|
|
|
613
639
|
case "image":
|
|
614
640
|
handleImage(state, action);
|
|
615
641
|
break;
|
|
642
|
+
case "audio":
|
|
643
|
+
handleAudio(state, action);
|
|
644
|
+
break;
|
|
616
645
|
case "complete":
|
|
617
646
|
handleComplete(state, action);
|
|
618
647
|
break;
|
|
@@ -772,5 +801,5 @@ export {
|
|
|
772
801
|
createAIStream
|
|
773
802
|
};
|
|
774
803
|
|
|
775
|
-
//# debugId=
|
|
804
|
+
//# debugId=D75F7C4E06A093F864756E2164756E21
|
|
776
805
|
//# sourceMappingURL=index.js.map
|