@effect/ai-openrouter 4.0.0-beta.70 → 4.0.0-beta.71

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.
@@ -1,21 +1,34 @@
1
1
  /**
2
- * The `OpenRouterConfig` module provides contextual configuration for the
3
- * OpenRouter provider integration. It is used to customize the HTTP client that
4
- * backs OpenRouter requests without rebuilding the provider layer itself.
2
+ * The `OpenRouterConfig` module provides scoped contextual configuration for
3
+ * OpenRouter request execution. It lets a workflow customize the HTTP client
4
+ * used by generated OpenRouter request methods without rebuilding the
5
+ * `OpenRouterClient` layer.
5
6
  *
6
- * Use {@link withClientTransform} when a single effect, workflow, or scoped
7
- * portion of an application needs to add cross-cutting HTTP client behavior
8
- * such as request logging, retries, proxy routing, additional headers, or test
9
- * doubles. The configuration is read from the current Effect context, so the
10
- * transform only applies where the returned effect is run with that context.
7
+ * **Mental model**
8
+ *
9
+ * - {@link OpenRouterConfig} is a context service carrying optional
10
+ * OpenRouter-specific request configuration
11
+ * - {@link withClientTransform} provides that service around one effect
12
+ * - Generated request methods read the current context and apply the transform
13
+ * to their `HttpClient`
14
+ * - The scoped configuration only applies while the returned effect is run
15
+ *
16
+ * **Common tasks**
17
+ *
18
+ * - Add request logging, retries, proxy routing, headers, or test doubles with
19
+ * {@link withClientTransform}
20
+ * - Scope OpenRouter client customization to one workflow without changing the
21
+ * shared client layer
11
22
  *
12
23
  * **Gotchas**
13
24
  *
14
- * - Each call to {@link withClientTransform} replaces the current client
15
- * transform for the provided effect; compose transforms manually when both
16
- * behaviors should apply.
25
+ * - Each {@link withClientTransform} call replaces the current scoped
26
+ * transform for the supplied effect; compose transforms manually when both
27
+ * behaviors should apply
17
28
  * - The transform receives and returns an `HttpClient`, so it should preserve
18
- * the OpenRouter client contract while adding behavior around it.
29
+ * the OpenRouter request contract while adding behavior around it
30
+ * - Streaming chat completion requests are sent directly by `OpenRouterClient`
31
+ * and do not read this scoped transform
19
32
  *
20
33
  * @since 4.0.0
21
34
  */
@@ -28,6 +41,13 @@ import type { HttpClient } from "effect/unstable/http/HttpClient"
28
41
  * Context service carrying scoped OpenRouter provider configuration for client
29
42
  * operations.
30
43
  *
44
+ * **When to use**
45
+ *
46
+ * Use as the context service tag when manually providing or reading scoped
47
+ * OpenRouter provider configuration in an Effect context.
48
+ *
49
+ * @see {@link withClientTransform} for scoping an HTTP client transformation
50
+ *
31
51
  * @category services
32
52
  * @since 4.0.0
33
53
  */
@@ -68,6 +88,24 @@ export declare namespace OpenRouterConfig {
68
88
  * Provides a scoped transform for the OpenRouter HTTP client used by provider
69
89
  * operations.
70
90
  *
91
+ * **When to use**
92
+ *
93
+ * Use when a single effect or workflow needs temporary OpenRouter HTTP client
94
+ * customization without rebuilding the client layer.
95
+ *
96
+ * **Details**
97
+ *
98
+ * Supports both data-first and data-last forms. The transform is stored in the
99
+ * scoped `OpenRouterConfig` service and read by generated OpenRouter request
100
+ * operations while running the supplied effect.
101
+ *
102
+ * **Gotchas**
103
+ *
104
+ * If a transform is already present in the scoped config, this helper replaces
105
+ * it. Compose transforms manually when both should apply. Streaming chat
106
+ * completion requests are sent directly by `OpenRouterClient.make` and do not
107
+ * read this scoped transform.
108
+ *
71
109
  * @category configuration
72
110
  * @since 4.0.0
73
111
  */
@@ -76,6 +114,24 @@ export const withClientTransform: {
76
114
  * Provides a scoped transform for the OpenRouter HTTP client used by provider
77
115
  * operations.
78
116
  *
117
+ * **When to use**
118
+ *
119
+ * Use when a single effect or workflow needs temporary OpenRouter HTTP client
120
+ * customization without rebuilding the client layer.
121
+ *
122
+ * **Details**
123
+ *
124
+ * Supports both data-first and data-last forms. The transform is stored in the
125
+ * scoped `OpenRouterConfig` service and read by generated OpenRouter request
126
+ * operations while running the supplied effect.
127
+ *
128
+ * **Gotchas**
129
+ *
130
+ * If a transform is already present in the scoped config, this helper replaces
131
+ * it. Compose transforms manually when both should apply. Streaming chat
132
+ * completion requests are sent directly by `OpenRouterClient.make` and do not
133
+ * read this scoped transform.
134
+ *
79
135
  * @category configuration
80
136
  * @since 4.0.0
81
137
  */
@@ -84,6 +140,24 @@ export const withClientTransform: {
84
140
  * Provides a scoped transform for the OpenRouter HTTP client used by provider
85
141
  * operations.
86
142
  *
143
+ * **When to use**
144
+ *
145
+ * Use when a single effect or workflow needs temporary OpenRouter HTTP client
146
+ * customization without rebuilding the client layer.
147
+ *
148
+ * **Details**
149
+ *
150
+ * Supports both data-first and data-last forms. The transform is stored in the
151
+ * scoped `OpenRouterConfig` service and read by generated OpenRouter request
152
+ * operations while running the supplied effect.
153
+ *
154
+ * **Gotchas**
155
+ *
156
+ * If a transform is already present in the scoped config, this helper replaces
157
+ * it. Compose transforms manually when both should apply. Streaming chat
158
+ * completion requests are sent directly by `OpenRouterClient.make` and do not
159
+ * read this scoped transform.
160
+ *
87
161
  * @category configuration
88
162
  * @since 4.0.0
89
163
  */
@@ -96,6 +170,24 @@ export const withClientTransform: {
96
170
  * Provides a scoped transform for the OpenRouter HTTP client used by provider
97
171
  * operations.
98
172
  *
173
+ * **When to use**
174
+ *
175
+ * Use when a single effect or workflow needs temporary OpenRouter HTTP client
176
+ * customization without rebuilding the client layer.
177
+ *
178
+ * **Details**
179
+ *
180
+ * Supports both data-first and data-last forms. The transform is stored in the
181
+ * scoped `OpenRouterConfig` service and read by generated OpenRouter request
182
+ * operations while running the supplied effect.
183
+ *
184
+ * **Gotchas**
185
+ *
186
+ * If a transform is already present in the scoped config, this helper replaces
187
+ * it. Compose transforms manually when both should apply. Streaming chat
188
+ * completion requests are sent directly by `OpenRouterClient.make` and do not
189
+ * read this scoped transform.
190
+ *
99
191
  * @category configuration
100
192
  * @since 4.0.0
101
193
  */
@@ -104,6 +196,24 @@ export const withClientTransform: {
104
196
  * Provides a scoped transform for the OpenRouter HTTP client used by provider
105
197
  * operations.
106
198
  *
199
+ * **When to use**
200
+ *
201
+ * Use when a single effect or workflow needs temporary OpenRouter HTTP client
202
+ * customization without rebuilding the client layer.
203
+ *
204
+ * **Details**
205
+ *
206
+ * Supports both data-first and data-last forms. The transform is stored in the
207
+ * scoped `OpenRouterConfig` service and read by generated OpenRouter request
208
+ * operations while running the supplied effect.
209
+ *
210
+ * **Gotchas**
211
+ *
212
+ * If a transform is already present in the scoped config, this helper replaces
213
+ * it. Compose transforms manually when both should apply. Streaming chat
214
+ * completion requests are sent directly by `OpenRouterClient.make` and do not
215
+ * read this scoped transform.
216
+ *
107
217
  * @category configuration
108
218
  * @since 4.0.0
109
219
  */
@@ -1,23 +1,42 @@
1
1
  /**
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.
2
+ * The `OpenRouterLanguageModel` module provides the OpenRouter implementation
3
+ * of Effect AI's `LanguageModel` service. It translates provider-neutral
4
+ * prompts, tools, files, structured output requests, reasoning metadata,
5
+ * cache-control hints, and telemetry annotations into OpenRouter chat
6
+ * completion requests, then converts responses and streams back into Effect AI
7
+ * response parts.
7
8
  *
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.
9
+ * **Mental model**
14
10
  *
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.
11
+ * `OpenRouterClient` owns HTTP transport and authentication. This module owns
12
+ * protocol translation: message assembly, tool conversion, structured output
13
+ * codec selection, streaming chunk handling, OpenRouter metadata round-trips,
14
+ * and GenAI telemetry annotations. {@link model}, {@link layer}, and
15
+ * {@link make} all build the same OpenRouter-backed
16
+ * `LanguageModel.LanguageModel` service from a model id and optional request
17
+ * defaults.
18
+ *
19
+ * **Common tasks**
20
+ *
21
+ * - Create an OpenRouter model descriptor for `Effect.provide`: {@link model}
22
+ * - Provide `LanguageModel.LanguageModel` as a `Layer`: {@link layer}
23
+ * - Construct the service effectfully from an existing `OpenRouterClient`:
24
+ * {@link make}
25
+ * - Supply or scope OpenRouter request defaults: {@link Config},
26
+ * {@link withConfigOverride}
27
+ * - Preserve OpenRouter reasoning and file metadata across turns:
28
+ * {@link ReasoningDetails}, {@link FileAnnotation}
29
+ *
30
+ * **Gotchas**
31
+ *
32
+ * - OpenRouter routes to many underlying providers, so support for images,
33
+ * files, tools, structured outputs, caching, and reasoning metadata depends
34
+ * on the selected model and route.
35
+ * - Provider-specific prompt and response metadata lives under the `openrouter`
36
+ * option namespace so later requests can replay reasoning details and file
37
+ * annotations when the model supports them.
38
+ * - Provider-defined tools are not supported by this integration; requests that
39
+ * include them fail before reaching OpenRouter.
21
40
  *
22
41
  * @since 4.0.0
23
42
  */
@@ -60,6 +79,13 @@ import { type ChatStreamingResponseChunkData, OpenRouterClient } from "./OpenRou
60
79
  /**
61
80
  * Service definition for OpenRouter language model configuration.
62
81
  *
82
+ * **When to use**
83
+ *
84
+ * Use to provide scoped OpenRouter chat completion defaults or per-operation
85
+ * overrides for an OpenRouter language model service.
86
+ *
87
+ * @see {@link withConfigOverride} for scoping language model request overrides
88
+ *
63
89
  * @category services
64
90
  * @since 4.0.0
65
91
  */
@@ -211,7 +237,7 @@ declare module "effect/unstable/ai/Prompt" {
211
237
  *
212
238
  * **When to use**
213
239
  *
214
- * Use these options to control how text content is sent to OpenRouter.
240
+ * Use when you use these options to control how text content is sent to OpenRouter.
215
241
  *
216
242
  * @category request
217
243
  * @since 4.0.0
@@ -490,7 +516,22 @@ declare module "effect/unstable/ai/Response" {
490
516
  // =============================================================================
491
517
 
492
518
  /**
493
- * Creates an AI model descriptor for an OpenRouter language model.
519
+ * Creates an OpenRouter model descriptor that can be provided with
520
+ * `Effect.provide`.
521
+ *
522
+ * **When to use**
523
+ *
524
+ * Use when you want an OpenRouter language model value that carries provider
525
+ * and model metadata and can be supplied directly to an Effect program.
526
+ *
527
+ * **Details**
528
+ *
529
+ * The returned model requires `OpenRouterClient` and provides
530
+ * `LanguageModel.LanguageModel`.
531
+ *
532
+ * @see {@link layer} for creating a `LanguageModel.LanguageModel` layer directly
533
+ * @see {@link make} for constructing the language model service effectfully
534
+ * @see {@link withConfigOverride} for scoping OpenRouter request overrides
494
535
  *
495
536
  * @category constructors
496
537
  * @since 4.0.0
@@ -502,7 +543,29 @@ export const model = (
502
543
  AiModel.make("openai", model, layer({ model, config }))
503
544
 
504
545
  /**
505
- * Creates an OpenRouter language model service.
546
+ * Creates an OpenRouter `LanguageModel` service from a model identifier and
547
+ * optional request defaults.
548
+ *
549
+ * **When to use**
550
+ *
551
+ * Use when an Effect needs to construct a `LanguageModel.Service` value backed
552
+ * by `OpenRouterClient`.
553
+ *
554
+ * **Details**
555
+ *
556
+ * The returned effect requires `OpenRouterClient`. Request defaults from the
557
+ * `config` option are merged with any `Config` service in the context, with
558
+ * context values taking precedence. The service supports both `generateText`
559
+ * and `streamText`.
560
+ *
561
+ * **Gotchas**
562
+ *
563
+ * Provider-defined tools are not supported by this provider integration;
564
+ * requests that include them fail with an `InvalidUserInputError`.
565
+ *
566
+ * @see {@link layer} for providing the service as a `Layer`
567
+ * @see {@link model} for creating a model descriptor for `Effect.provide`
568
+ * @see {@link withConfigOverride} for scoping request defaults around operations
506
569
  *
507
570
  * @category constructors
508
571
  * @since 4.0.0
@@ -573,6 +636,15 @@ export const make = Effect.fnUntraced(function*({ model, config: providerConfig
573
636
  /**
574
637
  * Creates a layer for the OpenRouter language model.
575
638
  *
639
+ * **When to use**
640
+ *
641
+ * Use when composing application layers and you want OpenRouter to satisfy
642
+ * `LanguageModel.LanguageModel` while supplying `OpenRouterClient` from another
643
+ * layer.
644
+ *
645
+ * @see {@link make} for constructing the language model service effectfully
646
+ * @see {@link model} for creating a model descriptor for `Effect.provide`
647
+ *
576
648
  * @category layers
577
649
  * @since 4.0.0
578
650
  */
@@ -585,6 +657,20 @@ export const layer = (options: {
585
657
  /**
586
658
  * Provides config overrides for OpenRouter language model operations.
587
659
  *
660
+ * **When to use**
661
+ *
662
+ * Use to apply OpenRouter request configuration to one effect without changing
663
+ * the model's default configuration.
664
+ *
665
+ * **Details**
666
+ *
667
+ * The overrides are merged with any existing `Config` service for the duration
668
+ * of the supplied effect. Fields in `overrides` take precedence over existing
669
+ * config, and the helper supports both pipe form and
670
+ * `withConfigOverride(effect, overrides)`.
671
+ *
672
+ * @see {@link Config} for available OpenRouter request configuration fields
673
+ *
588
674
  * @category configuration
589
675
  * @since 4.0.0
590
676
  */
@@ -592,6 +678,20 @@ export const withConfigOverride: {
592
678
  /**
593
679
  * Provides config overrides for OpenRouter language model operations.
594
680
  *
681
+ * **When to use**
682
+ *
683
+ * Use to apply OpenRouter request configuration to one effect without changing
684
+ * the model's default configuration.
685
+ *
686
+ * **Details**
687
+ *
688
+ * The overrides are merged with any existing `Config` service for the duration
689
+ * of the supplied effect. Fields in `overrides` take precedence over existing
690
+ * config, and the helper supports both pipe form and
691
+ * `withConfigOverride(effect, overrides)`.
692
+ *
693
+ * @see {@link Config} for available OpenRouter request configuration fields
694
+ *
595
695
  * @category configuration
596
696
  * @since 4.0.0
597
697
  */
@@ -599,6 +699,20 @@ export const withConfigOverride: {
599
699
  /**
600
700
  * Provides config overrides for OpenRouter language model operations.
601
701
  *
702
+ * **When to use**
703
+ *
704
+ * Use to apply OpenRouter request configuration to one effect without changing
705
+ * the model's default configuration.
706
+ *
707
+ * **Details**
708
+ *
709
+ * The overrides are merged with any existing `Config` service for the duration
710
+ * of the supplied effect. Fields in `overrides` take precedence over existing
711
+ * config, and the helper supports both pipe form and
712
+ * `withConfigOverride(effect, overrides)`.
713
+ *
714
+ * @see {@link Config} for available OpenRouter request configuration fields
715
+ *
602
716
  * @category configuration
603
717
  * @since 4.0.0
604
718
  */
@@ -607,6 +721,20 @@ export const withConfigOverride: {
607
721
  /**
608
722
  * Provides config overrides for OpenRouter language model operations.
609
723
  *
724
+ * **When to use**
725
+ *
726
+ * Use to apply OpenRouter request configuration to one effect without changing
727
+ * the model's default configuration.
728
+ *
729
+ * **Details**
730
+ *
731
+ * The overrides are merged with any existing `Config` service for the duration
732
+ * of the supplied effect. Fields in `overrides` take precedence over existing
733
+ * config, and the helper supports both pipe form and
734
+ * `withConfigOverride(effect, overrides)`.
735
+ *
736
+ * @see {@link Config} for available OpenRouter request configuration fields
737
+ *
610
738
  * @category configuration
611
739
  * @since 4.0.0
612
740
  */
@@ -614,6 +742,20 @@ export const withConfigOverride: {
614
742
  /**
615
743
  * Provides config overrides for OpenRouter language model operations.
616
744
  *
745
+ * **When to use**
746
+ *
747
+ * Use to apply OpenRouter request configuration to one effect without changing
748
+ * the model's default configuration.
749
+ *
750
+ * **Details**
751
+ *
752
+ * The overrides are merged with any existing `Config` service for the duration
753
+ * of the supplied effect. Fields in `overrides` take precedence over existing
754
+ * config, and the helper supports both pipe form and
755
+ * `withConfigOverride(effect, overrides)`.
756
+ *
757
+ * @see {@link Config} for available OpenRouter request configuration fields
758
+ *
617
759
  * @category configuration
618
760
  * @since 4.0.0
619
761
  */
package/src/index.ts CHANGED
@@ -10,86 +10,21 @@
10
10
  export * as Generated from "./Generated.ts"
11
11
 
12
12
  /**
13
- * The `OpenRouterClient` module provides an Effect service for calling
14
- * OpenRouter's chat completions API. It wraps the generated OpenRouter HTTP
15
- * client with Effect-native constructors, layers, typed errors, and streaming
16
- * support.
17
- *
18
- * **Common tasks**
19
- *
20
- * - Build a client from explicit options with {@link make}
21
- * - Provide the client to an application with {@link layer} or {@link layerConfig}
22
- * - Create non-streaming chat completions with {@link Service.createChatCompletion}
23
- * - Create server-sent event chat completion streams with
24
- * {@link Service.createChatCompletionStream}
25
- * - Customize authentication, base URL, OpenRouter ranking headers, or the
26
- * underlying HTTP client through {@link Options}
27
- *
28
- * **Gotchas**
29
- *
30
- * - Streaming requests are sent directly to `/chat/completions` with `stream`
31
- * and `stream_options.include_usage` enabled by this module.
32
- * - OpenRouter API failures, HTTP client failures, and schema decoding failures
33
- * are mapped into `AiError` values for the exported service methods.
34
- *
35
13
  * @since 4.0.0
36
14
  */
37
15
  export * as OpenRouterClient from "./OpenRouterClient.ts"
38
16
 
39
17
  /**
40
- * The `OpenRouterConfig` module provides contextual configuration for the
41
- * OpenRouter provider integration. It is used to customize the HTTP client that
42
- * backs OpenRouter requests without rebuilding the provider layer itself.
43
- *
44
- * Use {@link withClientTransform} when a single effect, workflow, or scoped
45
- * portion of an application needs to add cross-cutting HTTP client behavior
46
- * such as request logging, retries, proxy routing, additional headers, or test
47
- * doubles. The configuration is read from the current Effect context, so the
48
- * transform only applies where the returned effect is run with that context.
49
- *
50
- * **Gotchas**
51
- *
52
- * - Each call to {@link withClientTransform} replaces the current client
53
- * transform for the provided effect; compose transforms manually when both
54
- * behaviors should apply.
55
- * - The transform receives and returns an `HttpClient`, so it should preserve
56
- * the OpenRouter client contract while adding behavior around it.
57
- *
58
18
  * @since 4.0.0
59
19
  */
60
20
  export * as OpenRouterConfig from "./OpenRouterConfig.ts"
61
21
 
62
22
  /**
63
- * OpenRouter error metadata augmentation.
64
- *
65
- * Provides OpenRouter-specific metadata fields for AI error types through
66
- * module augmentation, enabling typed access to OpenRouter error details.
67
- *
68
23
  * @since 4.0.0
69
24
  */
70
25
  export * as OpenRouterError from "./OpenRouterError.ts"
71
26
 
72
27
  /**
73
- * The `OpenRouterLanguageModel` module provides constructors for using
74
- * OpenRouter chat completion models through the Effect AI `LanguageModel`
75
- * interface. It adapts Effect prompts, tools, structured output schemas, file
76
- * parts, reasoning details, cache-control hints, and telemetry annotations into
77
- * the OpenRouter request and response formats.
78
- *
79
- * Use this module when an application wants to select an OpenRouter model by
80
- * name while keeping the rest of its AI workflow provider-agnostic. The
81
- * exported layer and model constructors install a `LanguageModel` service backed
82
- * by `OpenRouterClient`, and `withConfigOverride` can scope per-request
83
- * OpenRouter options such as sampling, routing, tool use, or JSON schema
84
- * behavior.
85
- *
86
- * OpenRouter routes requests to many underlying providers, so model support for
87
- * images, files, tools, structured outputs, caching, and reasoning metadata can
88
- * vary. Provider-specific prompt and response metadata is preserved under the
89
- * `openrouter` option namespace so multi-turn conversations can round-trip
90
- * details such as reasoning blocks and file annotations when the selected model
91
- * supports them.
92
- *
93
28
  * @since 4.0.0
94
29
  */
95
30
  export * as OpenRouterLanguageModel from "./OpenRouterLanguageModel.ts"