@absolutejs/ai 0.0.49 → 0.0.51
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 +127 -0
- package/dist/ai/client/index.js +30 -1
- package/dist/ai/client/index.js.map +5 -5
- package/dist/ai/index.js +1174 -92
- package/dist/ai/index.js.map +18 -16
- package/dist/ai/providers/anthropic.js +105 -26
- package/dist/ai/providers/anthropic.js.map +5 -5
- package/dist/ai/providers/gemini.js +37 -4
- package/dist/ai/providers/gemini.js.map +5 -5
- package/dist/ai/providers/ollama.js +7 -3
- package/dist/ai/providers/ollama.js.map +4 -4
- package/dist/ai/providers/openai.js +177 -36
- package/dist/ai/providers/openai.js.map +5 -5
- package/dist/ai/providers/openaiCompatible.js +177 -36
- package/dist/ai/providers/openaiCompatible.js.map +5 -5
- package/dist/ai/providers/openaiResponses.js +147 -33
- package/dist/ai/providers/openaiResponses.js.map +5 -5
- package/dist/ai/providers/openrouter.js +2607 -0
- package/dist/ai/providers/openrouter.js.map +18 -0
- 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/generateAI.d.ts +4 -1
- package/dist/src/ai/index.d.ts +2 -0
- package/dist/src/ai/providers/openai.d.ts +7 -3
- package/dist/src/ai/providers/openaiResponses.d.ts +9 -4
- package/dist/src/ai/providers/openrouter.d.ts +157 -0
- package/dist/src/ai/providers/openrouterClient.d.ts +276 -0
- 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 +116 -8
- 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 +9 -2
|
@@ -13,6 +13,8 @@ export declare const serverMessageToAction: (message: AIServerMessage) => {
|
|
|
13
13
|
imageId?: undefined;
|
|
14
14
|
isPartial?: undefined;
|
|
15
15
|
revisedPrompt?: undefined;
|
|
16
|
+
audioId?: undefined;
|
|
17
|
+
transcript?: undefined;
|
|
16
18
|
durationMs?: undefined;
|
|
17
19
|
model?: undefined;
|
|
18
20
|
sources?: undefined;
|
|
@@ -42,6 +44,8 @@ export declare const serverMessageToAction: (message: AIServerMessage) => {
|
|
|
42
44
|
imageId?: undefined;
|
|
43
45
|
isPartial?: undefined;
|
|
44
46
|
revisedPrompt?: undefined;
|
|
47
|
+
audioId?: undefined;
|
|
48
|
+
transcript?: undefined;
|
|
45
49
|
durationMs?: undefined;
|
|
46
50
|
model?: undefined;
|
|
47
51
|
sources?: undefined;
|
|
@@ -71,6 +75,8 @@ export declare const serverMessageToAction: (message: AIServerMessage) => {
|
|
|
71
75
|
imageId?: undefined;
|
|
72
76
|
isPartial?: undefined;
|
|
73
77
|
revisedPrompt?: undefined;
|
|
78
|
+
audioId?: undefined;
|
|
79
|
+
transcript?: undefined;
|
|
74
80
|
durationMs?: undefined;
|
|
75
81
|
model?: undefined;
|
|
76
82
|
sources?: undefined;
|
|
@@ -100,6 +106,39 @@ export declare const serverMessageToAction: (message: AIServerMessage) => {
|
|
|
100
106
|
name?: undefined;
|
|
101
107
|
result?: undefined;
|
|
102
108
|
status?: undefined;
|
|
109
|
+
audioId?: undefined;
|
|
110
|
+
transcript?: undefined;
|
|
111
|
+
durationMs?: undefined;
|
|
112
|
+
model?: undefined;
|
|
113
|
+
sources?: undefined;
|
|
114
|
+
usage?: undefined;
|
|
115
|
+
position?: undefined;
|
|
116
|
+
attachments?: undefined;
|
|
117
|
+
fromMessageId?: undefined;
|
|
118
|
+
mode?: undefined;
|
|
119
|
+
newConversationId?: undefined;
|
|
120
|
+
oldConversationId?: undefined;
|
|
121
|
+
retrievalStartedAt?: undefined;
|
|
122
|
+
retrievalDurationMs?: undefined;
|
|
123
|
+
retrievedAt?: undefined;
|
|
124
|
+
trace?: undefined;
|
|
125
|
+
message?: undefined;
|
|
126
|
+
} | {
|
|
127
|
+
audioId: string | undefined;
|
|
128
|
+
conversationId: string;
|
|
129
|
+
data: string;
|
|
130
|
+
format: string;
|
|
131
|
+
messageId: string;
|
|
132
|
+
transcript: string | undefined;
|
|
133
|
+
type: "audio";
|
|
134
|
+
content?: undefined;
|
|
135
|
+
input?: undefined;
|
|
136
|
+
name?: undefined;
|
|
137
|
+
result?: undefined;
|
|
138
|
+
status?: undefined;
|
|
139
|
+
imageId?: undefined;
|
|
140
|
+
isPartial?: undefined;
|
|
141
|
+
revisedPrompt?: undefined;
|
|
103
142
|
durationMs?: undefined;
|
|
104
143
|
model?: undefined;
|
|
105
144
|
sources?: undefined;
|
|
@@ -133,6 +172,8 @@ export declare const serverMessageToAction: (message: AIServerMessage) => {
|
|
|
133
172
|
imageId?: undefined;
|
|
134
173
|
isPartial?: undefined;
|
|
135
174
|
revisedPrompt?: undefined;
|
|
175
|
+
audioId?: undefined;
|
|
176
|
+
transcript?: undefined;
|
|
136
177
|
position?: undefined;
|
|
137
178
|
attachments?: undefined;
|
|
138
179
|
fromMessageId?: undefined;
|
|
@@ -159,6 +200,8 @@ export declare const serverMessageToAction: (message: AIServerMessage) => {
|
|
|
159
200
|
imageId?: undefined;
|
|
160
201
|
isPartial?: undefined;
|
|
161
202
|
revisedPrompt?: undefined;
|
|
203
|
+
audioId?: undefined;
|
|
204
|
+
transcript?: undefined;
|
|
162
205
|
durationMs?: undefined;
|
|
163
206
|
model?: undefined;
|
|
164
207
|
sources?: undefined;
|
|
@@ -187,6 +230,8 @@ export declare const serverMessageToAction: (message: AIServerMessage) => {
|
|
|
187
230
|
imageId?: undefined;
|
|
188
231
|
isPartial?: undefined;
|
|
189
232
|
revisedPrompt?: undefined;
|
|
233
|
+
audioId?: undefined;
|
|
234
|
+
transcript?: undefined;
|
|
190
235
|
durationMs?: undefined;
|
|
191
236
|
model?: undefined;
|
|
192
237
|
sources?: undefined;
|
|
@@ -221,6 +266,8 @@ export declare const serverMessageToAction: (message: AIServerMessage) => {
|
|
|
221
266
|
imageId?: undefined;
|
|
222
267
|
isPartial?: undefined;
|
|
223
268
|
revisedPrompt?: undefined;
|
|
269
|
+
audioId?: undefined;
|
|
270
|
+
transcript?: undefined;
|
|
224
271
|
durationMs?: undefined;
|
|
225
272
|
model?: undefined;
|
|
226
273
|
sources?: undefined;
|
|
@@ -246,6 +293,8 @@ export declare const serverMessageToAction: (message: AIServerMessage) => {
|
|
|
246
293
|
imageId?: undefined;
|
|
247
294
|
isPartial?: undefined;
|
|
248
295
|
revisedPrompt?: undefined;
|
|
296
|
+
audioId?: undefined;
|
|
297
|
+
transcript?: undefined;
|
|
249
298
|
durationMs?: undefined;
|
|
250
299
|
model?: undefined;
|
|
251
300
|
sources?: undefined;
|
|
@@ -279,6 +328,8 @@ export declare const serverMessageToAction: (message: AIServerMessage) => {
|
|
|
279
328
|
imageId?: undefined;
|
|
280
329
|
isPartial?: undefined;
|
|
281
330
|
revisedPrompt?: undefined;
|
|
331
|
+
audioId?: undefined;
|
|
332
|
+
transcript?: undefined;
|
|
282
333
|
durationMs?: undefined;
|
|
283
334
|
model?: undefined;
|
|
284
335
|
usage?: undefined;
|
|
@@ -304,6 +355,8 @@ export declare const serverMessageToAction: (message: AIServerMessage) => {
|
|
|
304
355
|
imageId?: undefined;
|
|
305
356
|
isPartial?: undefined;
|
|
306
357
|
revisedPrompt?: undefined;
|
|
358
|
+
audioId?: undefined;
|
|
359
|
+
transcript?: undefined;
|
|
307
360
|
durationMs?: undefined;
|
|
308
361
|
model?: undefined;
|
|
309
362
|
sources?: undefined;
|
|
@@ -9,6 +9,8 @@ export type ProviderErrorInit = {
|
|
|
9
9
|
type?: string | null;
|
|
10
10
|
retryable: boolean;
|
|
11
11
|
cause?: unknown;
|
|
12
|
+
/** Provider-native structured details, when the response exposes them. */
|
|
13
|
+
metadata?: Record<string, unknown>;
|
|
12
14
|
};
|
|
13
15
|
export declare class ProviderError extends Error {
|
|
14
16
|
readonly provider: string;
|
|
@@ -17,6 +19,7 @@ export declare class ProviderError extends Error {
|
|
|
17
19
|
readonly type: string | null;
|
|
18
20
|
/** Whether retrying the same request later could plausibly succeed. */
|
|
19
21
|
readonly retryable: boolean;
|
|
22
|
+
readonly metadata: Record<string, unknown> | undefined;
|
|
20
23
|
/** Provider status page, when known — for surfacing "is it them?" to users. */
|
|
21
24
|
readonly statusPageUrl: string | null;
|
|
22
25
|
constructor(init: ProviderErrorInit);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AIProviderConfig, AIProviderMessage, AIProviderResponseFormat, AIProviderToolChoice, AIProviderToolDefinition, AIToolMap, AIUsage, ReasoningConfig } from "../../types/ai";
|
|
1
|
+
import type { AICitationChunk, AIProviderConfig, AIProviderMessage, AIProviderResponseFormat, AIProviderToolChoice, AIProviderToolDefinition, AIResponseMetadata, AIToolMap, AIUsage, ReasoningConfig } from "../../types/ai";
|
|
2
2
|
export type GenerateAIToolCall = {
|
|
3
3
|
id: string;
|
|
4
4
|
name: string;
|
|
@@ -13,6 +13,7 @@ export type GenerateAIOptions = {
|
|
|
13
13
|
cacheSystemPrompt?: boolean;
|
|
14
14
|
/** Per-call override of the provider `promptCaching` default. See AIProviderStreamParams. */
|
|
15
15
|
promptCaching?: boolean;
|
|
16
|
+
providerOptions?: Record<string, unknown>;
|
|
16
17
|
maxTokens?: number;
|
|
17
18
|
temperature?: number;
|
|
18
19
|
topP?: number;
|
|
@@ -25,6 +26,8 @@ export type GenerateAIOptions = {
|
|
|
25
26
|
signal?: AbortSignal;
|
|
26
27
|
};
|
|
27
28
|
export type GenerateAIResult = {
|
|
29
|
+
citations: AICitationChunk[];
|
|
30
|
+
metadata?: AIResponseMetadata;
|
|
28
31
|
text: string;
|
|
29
32
|
toolCalls: GenerateAIToolCall[];
|
|
30
33
|
usage?: AIUsage;
|
package/dist/src/ai/index.d.ts
CHANGED
|
@@ -24,6 +24,8 @@ export { gemini } from "./providers/gemini";
|
|
|
24
24
|
export { anthropic } from "./providers/anthropic";
|
|
25
25
|
export { ollama } from "./providers/ollama";
|
|
26
26
|
export { openai } from "./providers/openai";
|
|
27
|
+
export { createOpenRouterClient, openrouter, openrouterMessages, openrouterResponses, openRouterModelMatchesRule, verifyOpenRouterWebhookSignature, } from "./providers/openrouter";
|
|
28
|
+
export type { OpenRouterClient, OpenRouterClientConfig, OpenRouterConfig, OpenRouterDataCollection, OpenRouterEmbeddingRequest, OpenRouterEmbeddingResponse, OpenRouterFile, OpenRouterFileList, OpenRouterHttpRequestOptions, OpenRouterImageModelEndpoint, OpenRouterImageModelEndpoints, OpenRouterImageRequest, OpenRouterImageResponse, OpenRouterImageStreamEvent, OpenRouterMaxPrice, OpenRouterModel, OpenRouterModelList, OpenRouterModelQuery, OpenRouterPerformancePreference, OpenRouterPlugin, OpenRouterProviderRouting, OpenRouterQuantization, OpenRouterRequestOptions, OpenRouterRerankRequest, OpenRouterRerankResponse, OpenRouterResponseCache, OpenRouterResponsesRequest, OpenRouterServerTool, OpenRouterServiceTier, OpenRouterSpeechRequest, OpenRouterSort, OpenRouterSortStrategy, OpenRouterTrace, OpenRouterTranscriptionRequest, OpenRouterVideoJob, OpenRouterVideoRequest, OpenRouterVideoWebhookEvent, OpenRouterZdrEndpoint, } from "./providers/openrouter";
|
|
27
29
|
export { createOAuth2ClientCredentialsTokenSource } from "./providers/oauth2TokenSource";
|
|
28
30
|
export type { OAuth2ClientCredentialsConfig } from "./providers/oauth2TokenSource";
|
|
29
31
|
export { ProviderError, PROVIDER_STATUS_PAGES, providerStatusPage, } from "./errors/providerError";
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import type { AIProviderConfig } from "../../../types/ai";
|
|
2
|
-
type OpenAIConfig = {
|
|
1
|
+
import type { AIProviderConfig, AIProviderStreamParams } from "../../../types/ai";
|
|
2
|
+
export type OpenAIConfig = {
|
|
3
3
|
apiKey?: string;
|
|
4
4
|
baseUrl?: string;
|
|
5
|
+
fetch?: typeof globalThis.fetch;
|
|
6
|
+
headers?: HeadersInit | ((params: AIProviderStreamParams) => HeadersInit | Promise<HeadersInit>);
|
|
7
|
+
modelForCapabilities?: (model: string) => string;
|
|
8
|
+
providerName?: string;
|
|
5
9
|
tokenSource?: () => Promise<string> | string;
|
|
10
|
+
transformRequestBody?: (body: Record<string, unknown>, params: AIProviderStreamParams) => Record<string, unknown>;
|
|
6
11
|
};
|
|
7
12
|
export declare const openai: (config: OpenAIConfig) => AIProviderConfig;
|
|
8
|
-
export {};
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import type { AIProviderConfig } from "../../../types/ai";
|
|
2
|
-
type OpenAIResponsesConfig = {
|
|
3
|
-
apiKey
|
|
1
|
+
import type { AIProviderConfig, AIProviderStreamParams } from "../../../types/ai";
|
|
2
|
+
export type OpenAIResponsesConfig = {
|
|
3
|
+
apiKey?: string;
|
|
4
4
|
baseUrl?: string;
|
|
5
|
+
fetch?: typeof globalThis.fetch;
|
|
6
|
+
headers?: HeadersInit | ((params: AIProviderStreamParams) => HeadersInit | Promise<HeadersInit>);
|
|
5
7
|
imageModels?: Set<string> | string[];
|
|
8
|
+
modelForCapabilities?: (model: string) => string;
|
|
9
|
+
providerName?: string;
|
|
10
|
+
tokenSource?: () => Promise<string> | string;
|
|
11
|
+
transformRequestBody?: (body: Record<string, unknown>, params: AIProviderStreamParams) => Record<string, unknown>;
|
|
6
12
|
};
|
|
7
13
|
export declare const openaiResponses: (config: OpenAIResponsesConfig) => AIProviderConfig;
|
|
8
|
-
export {};
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type { AIProviderConfig } from "../../../types/ai";
|
|
2
|
+
export type OpenRouterDataCollection = "allow" | "deny";
|
|
3
|
+
export type OpenRouterQuantization = "bf16" | "fp4" | "fp6" | "fp8" | "fp16" | "fp32" | "int4" | "int8" | "unknown";
|
|
4
|
+
export type OpenRouterSortStrategy = "latency" | "price" | "throughput";
|
|
5
|
+
export type OpenRouterSort = OpenRouterSortStrategy | {
|
|
6
|
+
by: OpenRouterSortStrategy;
|
|
7
|
+
partition?: "model" | "none";
|
|
8
|
+
};
|
|
9
|
+
export type OpenRouterPerformancePreference = number | {
|
|
10
|
+
p50?: number;
|
|
11
|
+
p75?: number;
|
|
12
|
+
p90?: number;
|
|
13
|
+
p99?: number;
|
|
14
|
+
};
|
|
15
|
+
export type OpenRouterMaxPrice = {
|
|
16
|
+
/** Maximum completion-token price in USD per million tokens. */
|
|
17
|
+
completion?: number;
|
|
18
|
+
/** Maximum price in USD per image. */
|
|
19
|
+
image?: number;
|
|
20
|
+
/** Maximum prompt-token price in USD per million tokens. */
|
|
21
|
+
prompt?: number;
|
|
22
|
+
/** Maximum price in USD per request. */
|
|
23
|
+
request?: number;
|
|
24
|
+
};
|
|
25
|
+
export type OpenRouterProviderRouting = {
|
|
26
|
+
allowFallbacks?: boolean;
|
|
27
|
+
dataCollection?: OpenRouterDataCollection;
|
|
28
|
+
enforceDistillableText?: boolean;
|
|
29
|
+
ignore?: readonly string[];
|
|
30
|
+
maxPrice?: OpenRouterMaxPrice;
|
|
31
|
+
only?: readonly string[];
|
|
32
|
+
order?: readonly string[];
|
|
33
|
+
preferredMaxLatency?: OpenRouterPerformancePreference;
|
|
34
|
+
preferredMinThroughput?: OpenRouterPerformancePreference;
|
|
35
|
+
quantizations?: readonly OpenRouterQuantization[];
|
|
36
|
+
requireParameters?: boolean;
|
|
37
|
+
sort?: OpenRouterSort;
|
|
38
|
+
zdr?: boolean;
|
|
39
|
+
};
|
|
40
|
+
export type OpenRouterServiceTier = "auto" | "default" | "flex" | "priority" | "fast";
|
|
41
|
+
export type OpenRouterResponseCache = {
|
|
42
|
+
clear?: boolean;
|
|
43
|
+
enabled: boolean;
|
|
44
|
+
/** OpenRouter response-cache TTL in seconds (1-86400). */
|
|
45
|
+
ttlSeconds?: number;
|
|
46
|
+
};
|
|
47
|
+
export type OpenRouterCacheControl = {
|
|
48
|
+
type: "ephemeral";
|
|
49
|
+
ttl?: "5m" | "1h";
|
|
50
|
+
};
|
|
51
|
+
export type OpenRouterPromptCacheOptions = {
|
|
52
|
+
mode: "explicit";
|
|
53
|
+
ttl?: string;
|
|
54
|
+
};
|
|
55
|
+
export type OpenRouterReasoning = {
|
|
56
|
+
context?: "all_turns" | "auto" | "current_turn";
|
|
57
|
+
effort?: "minimal" | "low" | "medium" | "high" | "max" | "xhigh";
|
|
58
|
+
enabled?: boolean;
|
|
59
|
+
exclude?: boolean;
|
|
60
|
+
maxTokens?: number;
|
|
61
|
+
mode?: "pro";
|
|
62
|
+
summary?: "auto" | "concise" | "detailed";
|
|
63
|
+
};
|
|
64
|
+
export type OpenRouterTrace = Record<string, unknown> & {
|
|
65
|
+
generation_name?: string;
|
|
66
|
+
parent_span_id?: string;
|
|
67
|
+
span_name?: string;
|
|
68
|
+
trace_id?: string;
|
|
69
|
+
trace_name?: string;
|
|
70
|
+
};
|
|
71
|
+
export type OpenRouterAudioOutput = {
|
|
72
|
+
format: "wav" | "mp3" | "flac" | "opus" | "pcm16";
|
|
73
|
+
voice: string;
|
|
74
|
+
};
|
|
75
|
+
export type OpenRouterPlugin = {
|
|
76
|
+
id: string;
|
|
77
|
+
[option: string]: unknown;
|
|
78
|
+
};
|
|
79
|
+
export type OpenRouterServerTool = {
|
|
80
|
+
type: "openrouter:web_search" | "openrouter:web_fetch" | "openrouter:datetime" | "openrouter:image_generation" | "openrouter:apply_patch" | "openrouter:shell" | "openrouter:fusion" | "openrouter:advisor" | "openrouter:subagent" | "openrouter:experimental__search_models";
|
|
81
|
+
parameters?: Record<string, unknown>;
|
|
82
|
+
};
|
|
83
|
+
export type OpenRouterRequestOptions = {
|
|
84
|
+
/** Stream text and synthesized audio from an audio-output chat model. */
|
|
85
|
+
audioOutput?: OpenRouterAudioOutput;
|
|
86
|
+
/** Automatic top-level prompt caching, including optional Anthropic TTL. */
|
|
87
|
+
cacheControl?: OpenRouterCacheControl;
|
|
88
|
+
/** Future OpenRouter fields. Security-sensitive routing fields are rejected. */
|
|
89
|
+
extraBody?: Record<string, unknown>;
|
|
90
|
+
fallbackModels?: readonly string[];
|
|
91
|
+
includeReasoning?: boolean;
|
|
92
|
+
maxToolCalls?: number;
|
|
93
|
+
/** Native `/messages` server-tool definitions and replayable tool shapes. */
|
|
94
|
+
messagesTools?: readonly Record<string, unknown>[];
|
|
95
|
+
plugins?: readonly OpenRouterPlugin[];
|
|
96
|
+
/** Stable cache identity used by compatible OpenAI-family models. */
|
|
97
|
+
promptCacheKey?: string;
|
|
98
|
+
/** OpenAI explicit-cache mode and TTL. */
|
|
99
|
+
promptCacheOptions?: OpenRouterPromptCacheOptions;
|
|
100
|
+
preset?: string;
|
|
101
|
+
responseCache?: OpenRouterResponseCache;
|
|
102
|
+
/** OpenRouter-native reasoning controls beyond the portable effort knob. */
|
|
103
|
+
reasoning?: OpenRouterReasoning;
|
|
104
|
+
routerMetadata?: boolean;
|
|
105
|
+
routing?: OpenRouterProviderRouting;
|
|
106
|
+
serverTools?: readonly OpenRouterServerTool[];
|
|
107
|
+
serviceTier?: OpenRouterServiceTier;
|
|
108
|
+
sessionId?: string;
|
|
109
|
+
stopServerToolsWhen?: readonly Record<string, unknown>[];
|
|
110
|
+
/** Metadata forwarded to configured OpenRouter Broadcast destinations. */
|
|
111
|
+
trace?: OpenRouterTrace;
|
|
112
|
+
transforms?: readonly string[];
|
|
113
|
+
user?: string;
|
|
114
|
+
verbosity?: "low" | "medium" | "high";
|
|
115
|
+
};
|
|
116
|
+
export type OpenRouterConfig = {
|
|
117
|
+
/**
|
|
118
|
+
* Local model policy. Entries are exact model IDs or namespace wildcards such
|
|
119
|
+
* as `anthropic/*`. Requests outside the list fail before network access.
|
|
120
|
+
*/
|
|
121
|
+
allowedModels?: readonly string[];
|
|
122
|
+
/** Preset slugs deliberately approved for use with this provider. */
|
|
123
|
+
allowedPresets?: readonly string[];
|
|
124
|
+
/**
|
|
125
|
+
* Inference-provider policy sent as OpenRouter's `provider.only`. When
|
|
126
|
+
* `routing.only` is also set, every entry must be allowed by this policy.
|
|
127
|
+
*/
|
|
128
|
+
allowedProviders?: readonly string[];
|
|
129
|
+
apiKey?: string;
|
|
130
|
+
/** Up to two OpenRouter marketplace categories. */
|
|
131
|
+
appCategories?: readonly string[];
|
|
132
|
+
/** Public application name used for optional OpenRouter attribution. */
|
|
133
|
+
appName?: string;
|
|
134
|
+
/** Public application URL used for optional OpenRouter attribution. */
|
|
135
|
+
appUrl?: string;
|
|
136
|
+
baseUrl?: string;
|
|
137
|
+
fetch?: typeof globalThis.fetch;
|
|
138
|
+
headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
|
|
139
|
+
/** Default OpenRouter request options, overridable per call. */
|
|
140
|
+
requestOptions?: OpenRouterRequestOptions;
|
|
141
|
+
routing?: OpenRouterProviderRouting;
|
|
142
|
+
tokenSource?: () => Promise<string> | string;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* OpenRouter provider for the shared AbsoluteJS AI contract.
|
|
146
|
+
*
|
|
147
|
+
* Uses the existing OpenAI-compatible streaming implementation while adding
|
|
148
|
+
* OpenRouter attribution, typed provider routing, local model policy, provider
|
|
149
|
+
* allowlists, cost metadata, and OpenRouter-specific error attribution.
|
|
150
|
+
*/
|
|
151
|
+
export declare const openrouter: (config: OpenRouterConfig) => AIProviderConfig;
|
|
152
|
+
/** OpenRouter's stateless OpenAI-compatible Responses API provider skin. */
|
|
153
|
+
export declare const openrouterResponses: (config: OpenRouterConfig) => AIProviderConfig;
|
|
154
|
+
/** OpenRouter provider using the native Anthropic Messages protocol skin. */
|
|
155
|
+
export declare const openrouterMessages: (config: OpenRouterConfig) => AIProviderConfig;
|
|
156
|
+
export { createOpenRouterClient, openRouterModelMatchesRule, verifyOpenRouterWebhookSignature, } from "./openrouterClient";
|
|
157
|
+
export type { OpenRouterClient, OpenRouterClientConfig, OpenRouterEmbeddingRequest, OpenRouterEmbeddingResponse, OpenRouterFile, OpenRouterFileList, OpenRouterHttpRequestOptions, OpenRouterImageModelEndpoint, OpenRouterImageModelEndpoints, OpenRouterImageRequest, OpenRouterImageResponse, OpenRouterImageStreamEvent, OpenRouterModel, OpenRouterModelList, OpenRouterModelQuery, OpenRouterRerankRequest, OpenRouterRerankResponse, OpenRouterResponsesRequest, OpenRouterSpeechRequest, OpenRouterTranscriptionRequest, OpenRouterVideoJob, OpenRouterVideoRequest, OpenRouterVideoWebhookEvent, OpenRouterZdrEndpoint, } from "./openrouterClient";
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
export type OpenRouterClientConfig = {
|
|
2
|
+
allowedModels?: readonly string[];
|
|
3
|
+
apiKey?: string;
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
fetch?: typeof globalThis.fetch;
|
|
6
|
+
headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
|
|
7
|
+
tokenSource?: () => Promise<string> | string;
|
|
8
|
+
};
|
|
9
|
+
export type OpenRouterModel = {
|
|
10
|
+
id: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
context_length?: number;
|
|
14
|
+
architecture?: Record<string, unknown>;
|
|
15
|
+
pricing?: Record<string, string>;
|
|
16
|
+
supported_parameters?: string[] | Record<string, unknown>;
|
|
17
|
+
[field: string]: unknown;
|
|
18
|
+
};
|
|
19
|
+
export type OpenRouterModelList = {
|
|
20
|
+
data: OpenRouterModel[];
|
|
21
|
+
};
|
|
22
|
+
export type OpenRouterModelQuery = {
|
|
23
|
+
arch?: string;
|
|
24
|
+
context?: number;
|
|
25
|
+
distillable?: "false" | "true";
|
|
26
|
+
input_modalities?: string;
|
|
27
|
+
max_price?: number;
|
|
28
|
+
min_price?: number;
|
|
29
|
+
model_authors?: string;
|
|
30
|
+
output_modalities?: string;
|
|
31
|
+
providers?: string;
|
|
32
|
+
q?: string;
|
|
33
|
+
region?: "eu";
|
|
34
|
+
supported_parameters?: string;
|
|
35
|
+
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";
|
|
36
|
+
zdr?: "true";
|
|
37
|
+
};
|
|
38
|
+
export type OpenRouterEmbeddingRequest = {
|
|
39
|
+
model: string;
|
|
40
|
+
input: string | string[] | number[] | number[][];
|
|
41
|
+
dimensions?: number;
|
|
42
|
+
encoding_format?: "float" | "base64";
|
|
43
|
+
provider?: Record<string, unknown>;
|
|
44
|
+
user?: string;
|
|
45
|
+
};
|
|
46
|
+
export type OpenRouterEmbeddingResponse = {
|
|
47
|
+
data: Array<{
|
|
48
|
+
embedding: number[] | string;
|
|
49
|
+
index: number;
|
|
50
|
+
object: string;
|
|
51
|
+
}>;
|
|
52
|
+
model: string;
|
|
53
|
+
object: string;
|
|
54
|
+
usage?: {
|
|
55
|
+
prompt_tokens: number;
|
|
56
|
+
total_tokens: number;
|
|
57
|
+
cost?: number;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
export type OpenRouterRerankRequest = {
|
|
61
|
+
model: string;
|
|
62
|
+
query: string;
|
|
63
|
+
documents: Array<string | {
|
|
64
|
+
text: string;
|
|
65
|
+
}>;
|
|
66
|
+
top_n?: number;
|
|
67
|
+
return_documents?: boolean;
|
|
68
|
+
};
|
|
69
|
+
export type OpenRouterRerankResponse = {
|
|
70
|
+
id?: string;
|
|
71
|
+
model?: string;
|
|
72
|
+
results: Array<{
|
|
73
|
+
document?: {
|
|
74
|
+
text: string;
|
|
75
|
+
};
|
|
76
|
+
index: number;
|
|
77
|
+
relevance_score: number;
|
|
78
|
+
}>;
|
|
79
|
+
usage?: Record<string, number>;
|
|
80
|
+
};
|
|
81
|
+
export type OpenRouterImageRequest = {
|
|
82
|
+
model: string;
|
|
83
|
+
prompt: string;
|
|
84
|
+
n?: number;
|
|
85
|
+
resolution?: string;
|
|
86
|
+
aspect_ratio?: string;
|
|
87
|
+
size?: string;
|
|
88
|
+
quality?: "auto" | "low" | "medium" | "high";
|
|
89
|
+
output_format?: "png" | "jpeg" | "webp" | "svg";
|
|
90
|
+
background?: "auto" | "transparent" | "opaque";
|
|
91
|
+
output_compression?: number;
|
|
92
|
+
seed?: number;
|
|
93
|
+
input_references?: Array<Record<string, unknown>>;
|
|
94
|
+
provider?: Record<string, unknown>;
|
|
95
|
+
stream?: boolean;
|
|
96
|
+
};
|
|
97
|
+
export type OpenRouterImageResponse = {
|
|
98
|
+
created: number;
|
|
99
|
+
data: Array<{
|
|
100
|
+
b64_json: string;
|
|
101
|
+
media_type?: string;
|
|
102
|
+
}>;
|
|
103
|
+
usage?: Record<string, number>;
|
|
104
|
+
};
|
|
105
|
+
export type OpenRouterImageModelEndpoint = {
|
|
106
|
+
allowed_passthrough_parameters: string[];
|
|
107
|
+
pricing: Array<{
|
|
108
|
+
billable: string;
|
|
109
|
+
cost_usd: number;
|
|
110
|
+
unit: "image" | "megapixel" | "token" | string;
|
|
111
|
+
variant?: string;
|
|
112
|
+
}>;
|
|
113
|
+
provider_name: string;
|
|
114
|
+
provider_slug: string;
|
|
115
|
+
provider_tag: string | null;
|
|
116
|
+
supported_parameters: Record<string, unknown>;
|
|
117
|
+
supports_streaming: boolean;
|
|
118
|
+
};
|
|
119
|
+
export type OpenRouterImageModelEndpoints = {
|
|
120
|
+
endpoints: OpenRouterImageModelEndpoint[];
|
|
121
|
+
id: string;
|
|
122
|
+
};
|
|
123
|
+
export type OpenRouterResponsesRequest = Record<string, unknown> & {
|
|
124
|
+
input: unknown;
|
|
125
|
+
model: string;
|
|
126
|
+
stream?: boolean;
|
|
127
|
+
};
|
|
128
|
+
export type OpenRouterSpeechRequest = Record<string, unknown> & {
|
|
129
|
+
input: string;
|
|
130
|
+
model: string;
|
|
131
|
+
voice: string;
|
|
132
|
+
};
|
|
133
|
+
export type OpenRouterTranscriptionRequest = Record<string, unknown> & {
|
|
134
|
+
model: string;
|
|
135
|
+
};
|
|
136
|
+
export type OpenRouterVideoRequest = Record<string, unknown> & {
|
|
137
|
+
model: string;
|
|
138
|
+
prompt: string;
|
|
139
|
+
};
|
|
140
|
+
export type OpenRouterImageStreamEvent = Record<string, unknown> & {
|
|
141
|
+
type: string;
|
|
142
|
+
b64_json?: string;
|
|
143
|
+
media_type?: string;
|
|
144
|
+
partial_image_index?: number;
|
|
145
|
+
usage?: Record<string, number>;
|
|
146
|
+
};
|
|
147
|
+
export type OpenRouterFile = {
|
|
148
|
+
created_at: string;
|
|
149
|
+
downloadable: boolean;
|
|
150
|
+
filename: string;
|
|
151
|
+
id: string;
|
|
152
|
+
mime_type: string;
|
|
153
|
+
size_bytes: number;
|
|
154
|
+
type: "file";
|
|
155
|
+
};
|
|
156
|
+
export type OpenRouterFileList = {
|
|
157
|
+
cursor: string | null;
|
|
158
|
+
data: OpenRouterFile[];
|
|
159
|
+
first_id: string | null;
|
|
160
|
+
has_more: boolean;
|
|
161
|
+
last_id: string | null;
|
|
162
|
+
};
|
|
163
|
+
export type OpenRouterVideoJob = {
|
|
164
|
+
error?: string;
|
|
165
|
+
generation_id?: string | null;
|
|
166
|
+
id: string;
|
|
167
|
+
polling_url?: string;
|
|
168
|
+
status: "pending" | "in_progress" | "completed" | "failed" | "cancelled" | "expired";
|
|
169
|
+
unsigned_urls?: string[];
|
|
170
|
+
usage?: {
|
|
171
|
+
cost?: number;
|
|
172
|
+
is_byok?: boolean;
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
export type OpenRouterVideoWebhookEvent = {
|
|
176
|
+
created_at: string;
|
|
177
|
+
data: OpenRouterVideoJob & {
|
|
178
|
+
model?: string | null;
|
|
179
|
+
};
|
|
180
|
+
type: "video.generation.completed" | "video.generation.failed" | "video.generation.cancelled" | "video.generation.expired";
|
|
181
|
+
};
|
|
182
|
+
export type OpenRouterZdrEndpoint = Record<string, unknown> & {
|
|
183
|
+
context_length: number;
|
|
184
|
+
model_id: string;
|
|
185
|
+
model_name: string;
|
|
186
|
+
name: string;
|
|
187
|
+
pricing: Record<string, string>;
|
|
188
|
+
provider_name: string;
|
|
189
|
+
supported_parameters: string[];
|
|
190
|
+
tag: string;
|
|
191
|
+
};
|
|
192
|
+
export type OpenRouterHttpRequestOptions = Omit<RequestInit, "body" | "headers"> & {
|
|
193
|
+
body?: unknown;
|
|
194
|
+
headers?: HeadersInit;
|
|
195
|
+
query?: Record<string, boolean | number | string | undefined>;
|
|
196
|
+
};
|
|
197
|
+
export type OpenRouterClient = ReturnType<typeof createOpenRouterClient>;
|
|
198
|
+
export declare const openRouterModelMatchesRule: (model: string, rule: string) => boolean;
|
|
199
|
+
/** Verify `X-OpenRouter-Signature` against the exact raw webhook bytes. */
|
|
200
|
+
export declare const verifyOpenRouterWebhookSignature: (options: {
|
|
201
|
+
body: string | Uint8Array;
|
|
202
|
+
header: string;
|
|
203
|
+
secret: string;
|
|
204
|
+
nowSeconds?: number;
|
|
205
|
+
toleranceSeconds?: number;
|
|
206
|
+
}) => Promise<boolean>;
|
|
207
|
+
export declare const createOpenRouterClient: (config: OpenRouterClientConfig) => {
|
|
208
|
+
cancelBatch: (id: string) => Promise<Record<string, unknown>>;
|
|
209
|
+
createBatch: (body: Record<string, unknown>) => Promise<Record<string, unknown>>;
|
|
210
|
+
createEmbedding: (body: OpenRouterEmbeddingRequest) => Promise<OpenRouterEmbeddingResponse>;
|
|
211
|
+
generateImage: (body: OpenRouterImageRequest) => Promise<OpenRouterImageResponse>;
|
|
212
|
+
deleteFile: (id: string, workspaceId?: string) => Promise<{
|
|
213
|
+
id: string;
|
|
214
|
+
type: "file_deleted";
|
|
215
|
+
}>;
|
|
216
|
+
downloadFile: (id: string, workspaceId?: string) => Promise<Response>;
|
|
217
|
+
downloadVideo: (id: string, index?: number) => Promise<Response>;
|
|
218
|
+
generateVideo: (body: OpenRouterVideoRequest) => Promise<OpenRouterVideoJob>;
|
|
219
|
+
getBatch: (id: string) => Promise<Record<string, unknown>>;
|
|
220
|
+
getCredits: () => Promise<{
|
|
221
|
+
data: Record<string, number>;
|
|
222
|
+
}>;
|
|
223
|
+
getCurrentKey: () => Promise<{
|
|
224
|
+
data: Record<string, unknown>;
|
|
225
|
+
}>;
|
|
226
|
+
getFile: (id: string, workspaceId?: string) => Promise<OpenRouterFile>;
|
|
227
|
+
getGeneration: (id: string) => Promise<{
|
|
228
|
+
data: Record<string, unknown>;
|
|
229
|
+
}>;
|
|
230
|
+
getModelEndpoints: (model: string) => Promise<Record<string, unknown>>;
|
|
231
|
+
getModel: (model: string) => Promise<{
|
|
232
|
+
data: OpenRouterModel;
|
|
233
|
+
}>;
|
|
234
|
+
getImageModelEndpoints: (model: string) => Promise<OpenRouterImageModelEndpoints>;
|
|
235
|
+
getVideo: (id: string) => Promise<OpenRouterVideoJob>;
|
|
236
|
+
listImageModels: () => Promise<OpenRouterModelList>;
|
|
237
|
+
listFiles: (query?: {
|
|
238
|
+
cursor?: string;
|
|
239
|
+
limit?: number;
|
|
240
|
+
workspace_id?: string;
|
|
241
|
+
}) => Promise<OpenRouterFileList>;
|
|
242
|
+
listModels: (query?: OpenRouterModelQuery) => Promise<OpenRouterModelList>;
|
|
243
|
+
listUserModels: () => Promise<OpenRouterModelList>;
|
|
244
|
+
listZdrEndpoints: () => Promise<{
|
|
245
|
+
data: OpenRouterZdrEndpoint[];
|
|
246
|
+
}>;
|
|
247
|
+
countModels: (outputModalities?: string) => Promise<{
|
|
248
|
+
data: {
|
|
249
|
+
count: number;
|
|
250
|
+
};
|
|
251
|
+
}>;
|
|
252
|
+
listPresets: (offset?: number, limit?: number) => Promise<{
|
|
253
|
+
data: Record<string, unknown>[];
|
|
254
|
+
total_count: number;
|
|
255
|
+
}>;
|
|
256
|
+
listPresetVersions: (slug: string, offset?: number, limit?: number) => Promise<{
|
|
257
|
+
data: Record<string, unknown>[];
|
|
258
|
+
total_count: number;
|
|
259
|
+
}>;
|
|
260
|
+
listProviders: () => Promise<{
|
|
261
|
+
data: Record<string, unknown>[];
|
|
262
|
+
}>;
|
|
263
|
+
listRerankModels: () => Promise<OpenRouterModelList>;
|
|
264
|
+
listVideoModels: () => Promise<OpenRouterModelList>;
|
|
265
|
+
request: <T>(path: string, options?: OpenRouterHttpRequestOptions) => Promise<T>;
|
|
266
|
+
requestRaw: (path: string, options?: OpenRouterHttpRequestOptions) => Promise<Response>;
|
|
267
|
+
streamImage: (body: Omit<OpenRouterImageRequest, "stream">, options?: Omit<OpenRouterHttpRequestOptions, "body" | "method">) => AsyncGenerator<OpenRouterImageStreamEvent, void, any>;
|
|
268
|
+
respond: (body: OpenRouterResponsesRequest) => Promise<Response> | Promise<Record<string, unknown>>;
|
|
269
|
+
rerank: (body: OpenRouterRerankRequest) => Promise<OpenRouterRerankResponse>;
|
|
270
|
+
speak: (body: OpenRouterSpeechRequest) => Promise<Response>;
|
|
271
|
+
transcribe: (body: OpenRouterTranscriptionRequest | FormData) => Promise<Record<string, unknown>>;
|
|
272
|
+
uploadFile: (file: Blob, options?: {
|
|
273
|
+
filename?: string;
|
|
274
|
+
workspaceId?: string;
|
|
275
|
+
}) => Promise<OpenRouterFile>;
|
|
276
|
+
};
|
|
@@ -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. */
|