@effect/ai-openrouter 4.0.0-beta.66 → 4.0.0-beta.68
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/Generated.d.ts +1 -1
- package/dist/Generated.js +1 -1
- package/dist/OpenRouterClient.d.ts +39 -10
- package/dist/OpenRouterClient.d.ts.map +1 -1
- package/dist/OpenRouterClient.js +5 -5
- package/dist/OpenRouterClient.js.map +1 -1
- package/dist/OpenRouterConfig.d.ts +45 -8
- package/dist/OpenRouterConfig.d.ts.map +1 -1
- package/dist/OpenRouterConfig.js +30 -4
- package/dist/OpenRouterConfig.js.map +1 -1
- package/dist/OpenRouterError.d.ts +124 -3
- package/dist/OpenRouterError.d.ts.map +1 -1
- package/dist/OpenRouterError.js +1 -1
- package/dist/OpenRouterLanguageModel.d.ts +224 -9
- package/dist/OpenRouterLanguageModel.d.ts.map +1 -1
- package/dist/OpenRouterLanguageModel.js +28 -6
- package/dist/OpenRouterLanguageModel.js.map +1 -1
- package/dist/index.d.ts +66 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +66 -6
- package/dist/index.js.map +1 -1
- package/dist/internal/utilities.js +0 -1
- package/dist/internal/utilities.js.map +1 -1
- package/package.json +3 -3
- package/src/Generated.ts +1 -1
- package/src/OpenRouterClient.ts +39 -10
- package/src/OpenRouterConfig.ts +53 -10
- package/src/OpenRouterError.ts +124 -3
- package/src/OpenRouterLanguageModel.ts +247 -12
- package/src/index.ts +66 -6
- package/src/internal/utilities.ts +0 -1
|
@@ -101,25 +101,43 @@ declare const Config_base: Context.ServiceClass<Config, "@effect/ai-openrouter/O
|
|
|
101
101
|
/**
|
|
102
102
|
* Service definition for OpenRouter language model configuration.
|
|
103
103
|
*
|
|
104
|
-
* @since 1.0.0
|
|
105
104
|
* @category services
|
|
105
|
+
* @since 4.0.0
|
|
106
106
|
*/
|
|
107
107
|
export declare class Config extends Config_base {
|
|
108
108
|
}
|
|
109
109
|
/**
|
|
110
|
-
*
|
|
110
|
+
* OpenRouter assistant reasoning detail blocks preserved for multi-turn
|
|
111
|
+
* conversations.
|
|
112
|
+
*
|
|
111
113
|
* @category models
|
|
114
|
+
* @since 4.0.0
|
|
112
115
|
*/
|
|
113
116
|
export type ReasoningDetails = Exclude<typeof Generated.AssistantMessage.Encoded["reasoning_details"], undefined>;
|
|
114
117
|
/**
|
|
115
|
-
*
|
|
118
|
+
* File annotations emitted on OpenRouter assistant messages and exposed in
|
|
119
|
+
* finish metadata.
|
|
120
|
+
*
|
|
116
121
|
* @category models
|
|
122
|
+
* @since 4.0.0
|
|
117
123
|
*/
|
|
118
124
|
export type FileAnnotation = Extract<NonNullable<typeof Generated.AssistantMessage.fields.annotations.Type>[number], {
|
|
119
125
|
type: "file";
|
|
120
126
|
}>;
|
|
121
127
|
declare module "effect/unstable/ai/Prompt" {
|
|
128
|
+
/**
|
|
129
|
+
* OpenRouter-specific options for system messages.
|
|
130
|
+
*
|
|
131
|
+
* These options are used when translating system instructions into
|
|
132
|
+
* OpenRouter chat messages.
|
|
133
|
+
*
|
|
134
|
+
* @category request
|
|
135
|
+
* @since 4.0.0
|
|
136
|
+
*/
|
|
122
137
|
interface SystemMessageOptions extends ProviderOptions {
|
|
138
|
+
/**
|
|
139
|
+
* Provider-specific options sent to OpenRouter for the system message.
|
|
140
|
+
*/
|
|
123
141
|
readonly openrouter?: {
|
|
124
142
|
/**
|
|
125
143
|
* A breakpoint which marks the end of reusable content eligible for caching.
|
|
@@ -127,7 +145,19 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
127
145
|
readonly cacheControl?: typeof Generated.ChatMessageContentItemCacheControl.Encoded | null;
|
|
128
146
|
} | null;
|
|
129
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* OpenRouter-specific options for user messages.
|
|
150
|
+
*
|
|
151
|
+
* These options are used when translating user content into OpenRouter chat
|
|
152
|
+
* messages.
|
|
153
|
+
*
|
|
154
|
+
* @category request
|
|
155
|
+
* @since 4.0.0
|
|
156
|
+
*/
|
|
130
157
|
interface UserMessageOptions extends ProviderOptions {
|
|
158
|
+
/**
|
|
159
|
+
* Provider-specific options sent to OpenRouter for the user message.
|
|
160
|
+
*/
|
|
131
161
|
readonly openrouter?: {
|
|
132
162
|
/**
|
|
133
163
|
* A breakpoint which marks the end of reusable content eligible for caching.
|
|
@@ -135,7 +165,19 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
135
165
|
readonly cacheControl?: typeof Generated.ChatMessageContentItemCacheControl.Encoded | null;
|
|
136
166
|
} | null;
|
|
137
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* OpenRouter-specific options for assistant messages.
|
|
170
|
+
*
|
|
171
|
+
* Preserves reasoning metadata when assistant messages are replayed in later
|
|
172
|
+
* OpenRouter requests.
|
|
173
|
+
*
|
|
174
|
+
* @category request
|
|
175
|
+
* @since 4.0.0
|
|
176
|
+
*/
|
|
138
177
|
interface AssistantMessageOptions extends ProviderOptions {
|
|
178
|
+
/**
|
|
179
|
+
* Provider-specific options sent to OpenRouter for the assistant message.
|
|
180
|
+
*/
|
|
139
181
|
readonly openrouter?: {
|
|
140
182
|
/**
|
|
141
183
|
* A breakpoint which marks the end of reusable content eligible for caching.
|
|
@@ -147,7 +189,19 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
147
189
|
readonly reasoningDetails?: ReasoningDetails | null;
|
|
148
190
|
} | null;
|
|
149
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* OpenRouter-specific options for tool messages.
|
|
194
|
+
*
|
|
195
|
+
* These options are used when converting tool results into OpenRouter chat
|
|
196
|
+
* messages.
|
|
197
|
+
*
|
|
198
|
+
* @category request
|
|
199
|
+
* @since 4.0.0
|
|
200
|
+
*/
|
|
150
201
|
interface ToolMessageOptions extends ProviderOptions {
|
|
202
|
+
/**
|
|
203
|
+
* Provider-specific options sent to OpenRouter for the tool message.
|
|
204
|
+
*/
|
|
151
205
|
readonly openrouter?: {
|
|
152
206
|
/**
|
|
153
207
|
* A breakpoint which marks the end of reusable content eligible for caching.
|
|
@@ -155,7 +209,18 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
155
209
|
readonly cacheControl?: typeof Generated.ChatMessageContentItemCacheControl.Encoded | null;
|
|
156
210
|
} | null;
|
|
157
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* OpenRouter-specific options for text prompt parts.
|
|
214
|
+
*
|
|
215
|
+
* Use these options to control how text content is sent to OpenRouter.
|
|
216
|
+
*
|
|
217
|
+
* @category request
|
|
218
|
+
* @since 4.0.0
|
|
219
|
+
*/
|
|
158
220
|
interface TextPartOptions extends ProviderOptions {
|
|
221
|
+
/**
|
|
222
|
+
* Provider-specific options sent to OpenRouter for the text part.
|
|
223
|
+
*/
|
|
159
224
|
readonly openrouter?: {
|
|
160
225
|
/**
|
|
161
226
|
* A breakpoint which marks the end of reusable content eligible for caching.
|
|
@@ -163,7 +228,19 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
163
228
|
readonly cacheControl?: typeof Generated.ChatMessageContentItemCacheControl.Encoded | null;
|
|
164
229
|
} | null;
|
|
165
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* OpenRouter-specific options for reasoning prompt parts.
|
|
233
|
+
*
|
|
234
|
+
* Preserves provider reasoning blocks so reasoning-aware conversations can
|
|
235
|
+
* continue across OpenRouter requests.
|
|
236
|
+
*
|
|
237
|
+
* @category request
|
|
238
|
+
* @since 4.0.0
|
|
239
|
+
*/
|
|
166
240
|
interface ReasoningPartOptions extends ProviderOptions {
|
|
241
|
+
/**
|
|
242
|
+
* Provider-specific options sent to OpenRouter for the reasoning part.
|
|
243
|
+
*/
|
|
167
244
|
readonly openrouter?: {
|
|
168
245
|
/**
|
|
169
246
|
* A breakpoint which marks the end of reusable content eligible for caching.
|
|
@@ -175,7 +252,18 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
175
252
|
readonly reasoningDetails?: ReasoningDetails | null;
|
|
176
253
|
} | null;
|
|
177
254
|
}
|
|
255
|
+
/**
|
|
256
|
+
* OpenRouter-specific options for file prompt parts.
|
|
257
|
+
*
|
|
258
|
+
* Controls file naming and prompt caching for files sent to OpenRouter.
|
|
259
|
+
*
|
|
260
|
+
* @category request
|
|
261
|
+
* @since 4.0.0
|
|
262
|
+
*/
|
|
178
263
|
interface FilePartOptions extends ProviderOptions {
|
|
264
|
+
/**
|
|
265
|
+
* Provider-specific options sent to OpenRouter for the file part.
|
|
266
|
+
*/
|
|
179
267
|
readonly openrouter?: {
|
|
180
268
|
/**
|
|
181
269
|
* The name to give to the file. Will be prioritized over the file name
|
|
@@ -188,7 +276,19 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
188
276
|
readonly cacheControl?: typeof Generated.ChatMessageContentItemCacheControl.Encoded | null;
|
|
189
277
|
} | null;
|
|
190
278
|
}
|
|
279
|
+
/**
|
|
280
|
+
* OpenRouter-specific options for tool call prompt parts.
|
|
281
|
+
*
|
|
282
|
+
* Preserves reasoning details associated with tool calls when a conversation
|
|
283
|
+
* is sent back to OpenRouter.
|
|
284
|
+
*
|
|
285
|
+
* @category request
|
|
286
|
+
* @since 4.0.0
|
|
287
|
+
*/
|
|
191
288
|
interface ToolCallPartOptions extends ProviderOptions {
|
|
289
|
+
/**
|
|
290
|
+
* Provider-specific options sent to OpenRouter for the tool call part.
|
|
291
|
+
*/
|
|
192
292
|
readonly openrouter?: {
|
|
193
293
|
/**
|
|
194
294
|
* Reasoning details associated with the tool call part.
|
|
@@ -196,7 +296,18 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
196
296
|
readonly reasoningDetails?: ReasoningDetails | null;
|
|
197
297
|
} | null;
|
|
198
298
|
}
|
|
299
|
+
/**
|
|
300
|
+
* OpenRouter-specific options for tool result prompt parts.
|
|
301
|
+
*
|
|
302
|
+
* Controls prompt caching for tool results sent to OpenRouter.
|
|
303
|
+
*
|
|
304
|
+
* @category request
|
|
305
|
+
* @since 4.0.0
|
|
306
|
+
*/
|
|
199
307
|
interface ToolResultPartOptions extends ProviderOptions {
|
|
308
|
+
/**
|
|
309
|
+
* Provider-specific options sent to OpenRouter for the tool result part.
|
|
310
|
+
*/
|
|
200
311
|
readonly openrouter?: {
|
|
201
312
|
/**
|
|
202
313
|
* A breakpoint which marks the end of reusable content eligible for caching.
|
|
@@ -206,52 +317,156 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
206
317
|
}
|
|
207
318
|
}
|
|
208
319
|
declare module "effect/unstable/ai/Response" {
|
|
320
|
+
/**
|
|
321
|
+
* OpenRouter metadata attached to completed reasoning response parts.
|
|
322
|
+
*
|
|
323
|
+
* Preserves provider reasoning details that can be sent back in later turns.
|
|
324
|
+
*
|
|
325
|
+
* @category response
|
|
326
|
+
* @since 4.0.0
|
|
327
|
+
*/
|
|
209
328
|
interface ReasoningPartMetadata extends ProviderMetadata {
|
|
329
|
+
/**
|
|
330
|
+
* Provider-specific metadata returned for the reasoning part.
|
|
331
|
+
*/
|
|
210
332
|
readonly openrouter?: {
|
|
333
|
+
/**
|
|
334
|
+
* Reasoning details emitted by the underlying provider for this part.
|
|
335
|
+
*/
|
|
211
336
|
readonly reasoningDetails?: ReasoningDetails | null;
|
|
212
337
|
} | null;
|
|
213
338
|
}
|
|
339
|
+
/**
|
|
340
|
+
* OpenRouter metadata emitted when a streamed reasoning part starts.
|
|
341
|
+
*
|
|
342
|
+
* Carries the first reasoning detail chunk when OpenRouter exposes one.
|
|
343
|
+
*
|
|
344
|
+
* @category response
|
|
345
|
+
* @since 4.0.0
|
|
346
|
+
*/
|
|
214
347
|
interface ReasoningStartPartMetadata extends ProviderMetadata {
|
|
348
|
+
/**
|
|
349
|
+
* Provider-specific metadata returned for the streamed reasoning start.
|
|
350
|
+
*/
|
|
215
351
|
readonly openrouter?: {
|
|
352
|
+
/**
|
|
353
|
+
* Reasoning details emitted by the underlying provider for this part.
|
|
354
|
+
*/
|
|
216
355
|
readonly reasoningDetails?: ReasoningDetails | null;
|
|
217
356
|
} | null;
|
|
218
357
|
}
|
|
358
|
+
/**
|
|
359
|
+
* OpenRouter metadata emitted for streamed reasoning deltas.
|
|
360
|
+
*
|
|
361
|
+
* Carries provider reasoning detail chunks as they arrive from OpenRouter.
|
|
362
|
+
*
|
|
363
|
+
* @category response
|
|
364
|
+
* @since 4.0.0
|
|
365
|
+
*/
|
|
219
366
|
interface ReasoningDeltaPartMetadata extends ProviderMetadata {
|
|
367
|
+
/**
|
|
368
|
+
* Provider-specific metadata returned for the streamed reasoning delta.
|
|
369
|
+
*/
|
|
220
370
|
readonly openrouter?: {
|
|
371
|
+
/**
|
|
372
|
+
* Reasoning details emitted by the underlying provider for this delta.
|
|
373
|
+
*/
|
|
221
374
|
readonly reasoningDetails?: ReasoningDetails | null;
|
|
222
375
|
} | null;
|
|
223
376
|
}
|
|
377
|
+
/**
|
|
378
|
+
* OpenRouter metadata attached to tool-call response parts.
|
|
379
|
+
*
|
|
380
|
+
* Associates tool calls with provider reasoning details when the model emits
|
|
381
|
+
* reasoning and tool calls together.
|
|
382
|
+
*
|
|
383
|
+
* @category response
|
|
384
|
+
* @since 4.0.0
|
|
385
|
+
*/
|
|
224
386
|
interface ToolCallPartMetadata extends ProviderMetadata {
|
|
387
|
+
/**
|
|
388
|
+
* Provider-specific metadata returned for the tool call.
|
|
389
|
+
*/
|
|
225
390
|
readonly openrouter?: {
|
|
391
|
+
/**
|
|
392
|
+
* Reasoning details associated with this tool call.
|
|
393
|
+
*/
|
|
226
394
|
readonly reasoningDetails?: ReasoningDetails | null;
|
|
227
395
|
} | null;
|
|
228
396
|
}
|
|
397
|
+
/**
|
|
398
|
+
* OpenRouter metadata attached to URL source citations.
|
|
399
|
+
*
|
|
400
|
+
* Includes citation text and offsets returned by providers that support URL
|
|
401
|
+
* annotations.
|
|
402
|
+
*
|
|
403
|
+
* @category response
|
|
404
|
+
* @since 4.0.0
|
|
405
|
+
*/
|
|
229
406
|
interface UrlSourcePartMetadata extends ProviderMetadata {
|
|
407
|
+
/**
|
|
408
|
+
* Provider-specific citation metadata returned for the URL source.
|
|
409
|
+
*/
|
|
230
410
|
readonly openrouter?: {
|
|
411
|
+
/**
|
|
412
|
+
* The cited source content returned by the provider.
|
|
413
|
+
*/
|
|
231
414
|
readonly content?: string | null;
|
|
415
|
+
/**
|
|
416
|
+
* The zero-based start index of the citation in the generated text.
|
|
417
|
+
*/
|
|
232
418
|
readonly startIndex?: number | null;
|
|
419
|
+
/**
|
|
420
|
+
* The zero-based end index of the citation in the generated text.
|
|
421
|
+
*/
|
|
233
422
|
readonly endIndex?: number | null;
|
|
234
423
|
} | null;
|
|
235
424
|
}
|
|
425
|
+
/**
|
|
426
|
+
* OpenRouter metadata attached to finish response parts.
|
|
427
|
+
*
|
|
428
|
+
* Exposes provider response details that are not represented by the common
|
|
429
|
+
* Effect AI finish part fields.
|
|
430
|
+
*
|
|
431
|
+
* @category response
|
|
432
|
+
* @since 4.0.0
|
|
433
|
+
*/
|
|
236
434
|
interface FinishPartMetadata extends ProviderMetadata {
|
|
435
|
+
/**
|
|
436
|
+
* Provider-specific metadata returned when the OpenRouter response finishes.
|
|
437
|
+
*/
|
|
237
438
|
readonly openrouter?: {
|
|
439
|
+
/**
|
|
440
|
+
* Provider fingerprint for the backend configuration that served the request.
|
|
441
|
+
*/
|
|
238
442
|
readonly systemFingerprint?: string | null;
|
|
443
|
+
/**
|
|
444
|
+
* Raw token usage reported by OpenRouter.
|
|
445
|
+
*/
|
|
239
446
|
readonly usage?: typeof Generated.ChatGenerationTokenUsage.Encoded | null;
|
|
447
|
+
/**
|
|
448
|
+
* File annotations returned by the provider.
|
|
449
|
+
*/
|
|
240
450
|
readonly annotations?: ReadonlyArray<FileAnnotation> | null;
|
|
451
|
+
/**
|
|
452
|
+
* The OpenRouter provider that served the request, when reported.
|
|
453
|
+
*/
|
|
241
454
|
readonly provider?: string | null;
|
|
242
455
|
} | null;
|
|
243
456
|
}
|
|
244
457
|
}
|
|
245
458
|
/**
|
|
246
|
-
*
|
|
459
|
+
* Creates an AI model descriptor for an OpenRouter language model.
|
|
460
|
+
*
|
|
247
461
|
* @category constructors
|
|
462
|
+
* @since 4.0.0
|
|
248
463
|
*/
|
|
249
464
|
export declare const model: (model: string, config?: Omit<typeof Config.Service, "model">) => AiModel.Model<"openai", LanguageModel.LanguageModel, OpenRouterClient>;
|
|
250
465
|
/**
|
|
251
466
|
* Creates an OpenRouter language model service.
|
|
252
467
|
*
|
|
253
|
-
* @since 1.0.0
|
|
254
468
|
* @category constructors
|
|
469
|
+
* @since 4.0.0
|
|
255
470
|
*/
|
|
256
471
|
export declare const make: (args_0: {
|
|
257
472
|
readonly model: string;
|
|
@@ -260,8 +475,8 @@ export declare const make: (args_0: {
|
|
|
260
475
|
/**
|
|
261
476
|
* Creates a layer for the OpenRouter language model.
|
|
262
477
|
*
|
|
263
|
-
* @since 1.0.0
|
|
264
478
|
* @category layers
|
|
479
|
+
* @since 4.0.0
|
|
265
480
|
*/
|
|
266
481
|
export declare const layer: (options: {
|
|
267
482
|
readonly model: string;
|
|
@@ -270,22 +485,22 @@ export declare const layer: (options: {
|
|
|
270
485
|
/**
|
|
271
486
|
* Provides config overrides for OpenRouter language model operations.
|
|
272
487
|
*
|
|
273
|
-
* @since 1.0.0
|
|
274
488
|
* @category configuration
|
|
489
|
+
* @since 4.0.0
|
|
275
490
|
*/
|
|
276
491
|
export declare const withConfigOverride: {
|
|
277
492
|
/**
|
|
278
493
|
* Provides config overrides for OpenRouter language model operations.
|
|
279
494
|
*
|
|
280
|
-
* @since 1.0.0
|
|
281
495
|
* @category configuration
|
|
496
|
+
* @since 4.0.0
|
|
282
497
|
*/
|
|
283
498
|
(overrides: typeof Config.Service): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>;
|
|
284
499
|
/**
|
|
285
500
|
* Provides config overrides for OpenRouter language model operations.
|
|
286
501
|
*
|
|
287
|
-
* @since 1.0.0
|
|
288
502
|
* @category configuration
|
|
503
|
+
* @since 4.0.0
|
|
289
504
|
*/
|
|
290
505
|
<A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service): Effect.Effect<A, E, Exclude<R, Config>>;
|
|
291
506
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenRouterLanguageModel.d.ts","sourceRoot":"","sources":["../src/OpenRouterLanguageModel.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"OpenRouterLanguageModel.d.ts","sourceRoot":"","sources":["../src/OpenRouterLanguageModel.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AAEzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAGvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAYrC,OAAO,KAAK,aAAa,MAAM,kCAAkC,CAAA;AACjE,OAAO,KAAK,OAAO,MAAM,0BAA0B,CAAA;AAQnD,OAAO,KAAK,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAEhD,OAAO,EAAuC,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gCA4B3D,OAAO,GAAG,SAAS;;AAtBrD;;;;;GAKG;AACH,qBAAa,MAAO,SAAQ,WAmB+B;CAAG;AAM9D;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC,OAAO,SAAS,CAAC,gBAAgB,CAAC,OAAO,CAAC,mBAAmB,CAAC,EAAE,SAAS,CAAC,CAAA;AAEjH;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,CAClC,WAAW,CAAC,OAAO,SAAS,CAAC,gBAAgB,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,EAC9E;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CACjB,CAAA;AAED,OAAO,QAAQ,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C,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAA;IACtH;;;;;OAKG;IACH,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAA;CAwBhH,CAAA"}
|
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The `OpenRouterLanguageModel` module provides constructors for using
|
|
3
|
+
* OpenRouter chat completion models through the Effect AI `LanguageModel`
|
|
4
|
+
* interface. It adapts Effect prompts, tools, structured output schemas, file
|
|
5
|
+
* parts, reasoning details, cache-control hints, and telemetry annotations into
|
|
6
|
+
* the OpenRouter request and response formats.
|
|
7
|
+
*
|
|
8
|
+
* Use this module when an application wants to select an OpenRouter model by
|
|
9
|
+
* name while keeping the rest of its AI workflow provider-agnostic. The
|
|
10
|
+
* exported layer and model constructors install a `LanguageModel` service backed
|
|
11
|
+
* by `OpenRouterClient`, and `withConfigOverride` can scope per-request
|
|
12
|
+
* OpenRouter options such as sampling, routing, tool use, or JSON schema
|
|
13
|
+
* behavior.
|
|
14
|
+
*
|
|
15
|
+
* OpenRouter routes requests to many underlying providers, so model support for
|
|
16
|
+
* images, files, tools, structured outputs, caching, and reasoning metadata can
|
|
17
|
+
* vary. Provider-specific prompt and response metadata is preserved under the
|
|
18
|
+
* `openrouter` option namespace so multi-turn conversations can round-trip
|
|
19
|
+
* details such as reasoning blocks and file annotations when the selected model
|
|
20
|
+
* supports them.
|
|
21
|
+
*
|
|
22
|
+
* @since 4.0.0
|
|
3
23
|
*/
|
|
4
24
|
/** @effect-diagnostics preferSchemaOverJson:skip-file */
|
|
5
25
|
import * as Arr from "effect/Array";
|
|
@@ -30,16 +50,18 @@ import { OpenRouterClient } from "./OpenRouterClient.js";
|
|
|
30
50
|
/**
|
|
31
51
|
* Service definition for OpenRouter language model configuration.
|
|
32
52
|
*
|
|
33
|
-
* @since 1.0.0
|
|
34
53
|
* @category services
|
|
54
|
+
* @since 4.0.0
|
|
35
55
|
*/
|
|
36
56
|
export class Config extends /*#__PURE__*/Context.Service()("@effect/ai-openrouter/OpenRouterLanguageModel/Config") {}
|
|
37
57
|
// =============================================================================
|
|
38
58
|
// Language Model
|
|
39
59
|
// =============================================================================
|
|
40
60
|
/**
|
|
41
|
-
*
|
|
61
|
+
* Creates an AI model descriptor for an OpenRouter language model.
|
|
62
|
+
*
|
|
42
63
|
* @category constructors
|
|
64
|
+
* @since 4.0.0
|
|
43
65
|
*/
|
|
44
66
|
export const model = (model, config) => AiModel.make("openai", model, layer({
|
|
45
67
|
model,
|
|
@@ -48,8 +70,8 @@ export const model = (model, config) => AiModel.make("openai", model, layer({
|
|
|
48
70
|
/**
|
|
49
71
|
* Creates an OpenRouter language model service.
|
|
50
72
|
*
|
|
51
|
-
* @since 1.0.0
|
|
52
73
|
* @category constructors
|
|
74
|
+
* @since 4.0.0
|
|
53
75
|
*/
|
|
54
76
|
export const make = /*#__PURE__*/Effect.fnUntraced(function* ({
|
|
55
77
|
model,
|
|
@@ -136,15 +158,15 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* ({
|
|
|
136
158
|
/**
|
|
137
159
|
* Creates a layer for the OpenRouter language model.
|
|
138
160
|
*
|
|
139
|
-
* @since 1.0.0
|
|
140
161
|
* @category layers
|
|
162
|
+
* @since 4.0.0
|
|
141
163
|
*/
|
|
142
164
|
export const layer = options => Layer.effect(LanguageModel.LanguageModel, make(options));
|
|
143
165
|
/**
|
|
144
166
|
* Provides config overrides for OpenRouter language model operations.
|
|
145
167
|
*
|
|
146
|
-
* @since 1.0.0
|
|
147
168
|
* @category configuration
|
|
169
|
+
* @since 4.0.0
|
|
148
170
|
*/
|
|
149
171
|
export const withConfigOverride = /*#__PURE__*/dual(2, (self, overrides) => Effect.flatMap(Effect.serviceOption(Config), config => Effect.provideService(self, Config, {
|
|
150
172
|
...(config._tag === "Some" ? config.value : {}),
|