@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.
@@ -1,5 +1,23 @@
1
1
  /**
2
- * @since 1.0.0
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.
5
+ *
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.
11
+ *
12
+ * **Gotchas**
13
+ *
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.
17
+ * - The transform receives and returns an `HttpClient`, so it should preserve
18
+ * the OpenRouter client contract while adding behavior around it.
19
+ *
20
+ * @since 4.0.0
3
21
  */
4
22
  import * as Context from "effect/Context"
5
23
  import * as Effect from "effect/Effect"
@@ -7,15 +25,20 @@ import { dual } from "effect/Function"
7
25
  import type { HttpClient } from "effect/unstable/http/HttpClient"
8
26
 
9
27
  /**
10
- * @since 1.0.0
28
+ * Context service carrying scoped OpenRouter provider configuration for client
29
+ * operations.
30
+ *
11
31
  * @category services
32
+ * @since 4.0.0
12
33
  */
13
34
  export class OpenRouterConfig extends Context.Service<
14
35
  OpenRouterConfig,
15
36
  OpenRouterConfig.Service
16
37
  >()("@effect/ai-openrouter/OpenRouterConfig") {
17
38
  /**
18
- * @since 1.0.0
39
+ * Gets the configured OpenRouter service from the current context when present.
40
+ *
41
+ * @since 4.0.0
19
42
  */
20
43
  static readonly getOrUndefined: Effect.Effect<typeof OpenRouterConfig.Service | undefined> = Effect.map(
21
44
  Effect.context<never>(),
@@ -24,12 +47,17 @@ export class OpenRouterConfig extends Context.Service<
24
47
  }
25
48
 
26
49
  /**
27
- * @since 1.0.0
50
+ * Types associated with the `OpenRouterConfig` context service.
51
+ *
52
+ * @since 4.0.0
28
53
  */
29
54
  export declare namespace OpenRouterConfig {
30
55
  /**
31
- * @since 1.0.0
56
+ * Configuration values read by OpenRouter provider operations when resolving
57
+ * the generated HTTP client.
58
+ *
32
59
  * @category models
60
+ * @since 4.0.0
33
61
  */
34
62
  export interface Service {
35
63
  readonly transformClient?: ((client: HttpClient) => HttpClient) | undefined
@@ -37,18 +65,27 @@ export declare namespace OpenRouterConfig {
37
65
  }
38
66
 
39
67
  /**
40
- * @since 1.0.0
68
+ * Provides a scoped transform for the OpenRouter HTTP client used by provider
69
+ * operations.
70
+ *
41
71
  * @category configuration
72
+ * @since 4.0.0
42
73
  */
43
74
  export const withClientTransform: {
44
75
  /**
45
- * @since 1.0.0
76
+ * Provides a scoped transform for the OpenRouter HTTP client used by provider
77
+ * operations.
78
+ *
46
79
  * @category configuration
80
+ * @since 4.0.0
47
81
  */
48
82
  (transform: (client: HttpClient) => HttpClient): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
49
83
  /**
50
- * @since 1.0.0
84
+ * Provides a scoped transform for the OpenRouter HTTP client used by provider
85
+ * operations.
86
+ *
51
87
  * @category configuration
88
+ * @since 4.0.0
52
89
  */
53
90
  <A, E, R>(
54
91
  self: Effect.Effect<A, E, R>,
@@ -56,13 +93,19 @@ export const withClientTransform: {
56
93
  ): Effect.Effect<A, E, R>
57
94
  } = dual<
58
95
  /**
59
- * @since 1.0.0
96
+ * Provides a scoped transform for the OpenRouter HTTP client used by provider
97
+ * operations.
98
+ *
60
99
  * @category configuration
100
+ * @since 4.0.0
61
101
  */
62
102
  (transform: (client: HttpClient) => HttpClient) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,
63
103
  /**
64
- * @since 1.0.0
104
+ * Provides a scoped transform for the OpenRouter HTTP client used by provider
105
+ * operations.
106
+ *
65
107
  * @category configuration
108
+ * @since 4.0.0
66
109
  */
67
110
  <A, E, R>(
68
111
  self: Effect.Effect<A, E, R>,
@@ -4,14 +4,14 @@
4
4
  * Provides OpenRouter-specific metadata fields for AI error types through
5
5
  * module augmentation, enabling typed access to OpenRouter error details.
6
6
  *
7
- * @since 1.0.0
7
+ * @since 4.0.0
8
8
  */
9
9
 
10
10
  /**
11
11
  * OpenRouter-specific error metadata fields.
12
12
  *
13
- * @since 1.0.0
14
13
  * @category models
14
+ * @since 4.0.0
15
15
  */
16
16
  export type OpenRouterErrorMetadata = {
17
17
  /**
@@ -31,8 +31,8 @@ export type OpenRouterErrorMetadata = {
31
31
  /**
32
32
  * OpenRouter-specific rate limit metadata fields.
33
33
  *
34
- * @since 1.0.0
35
34
  * @category models
35
+ * @since 4.0.0
36
36
  */
37
37
  export type OpenRouterRateLimitMetadata = OpenRouterErrorMetadata & {
38
38
  readonly limit: string | null
@@ -42,43 +42,164 @@ export type OpenRouterRateLimitMetadata = OpenRouterErrorMetadata & {
42
42
  }
43
43
 
44
44
  declare module "effect/unstable/ai/AiError" {
45
+ /**
46
+ * OpenRouter metadata attached to `RateLimitError` values.
47
+ *
48
+ * Captures OpenRouter error details together with rate limit header
49
+ * information from responses where the provider rejected the request because
50
+ * a limit was reached.
51
+ *
52
+ * @category configuration
53
+ * @since 4.0.0
54
+ */
45
55
  export interface RateLimitErrorMetadata {
56
+ /**
57
+ * OpenRouter-specific details for the rate limit response.
58
+ */
46
59
  readonly openrouter?: OpenRouterRateLimitMetadata | null
47
60
  }
48
61
 
62
+ /**
63
+ * OpenRouter metadata attached to `QuotaExhaustedError` values.
64
+ *
65
+ * Preserves provider error details for failures caused by exhausted account,
66
+ * billing, or usage quota.
67
+ *
68
+ * @category configuration
69
+ * @since 4.0.0
70
+ */
49
71
  export interface QuotaExhaustedErrorMetadata {
72
+ /**
73
+ * OpenRouter-specific details for the quota exhaustion response.
74
+ */
50
75
  readonly openrouter?: OpenRouterErrorMetadata | null
51
76
  }
52
77
 
78
+ /**
79
+ * OpenRouter metadata attached to `AuthenticationError` values.
80
+ *
81
+ * Preserves provider error details for failed API key, authorization, or
82
+ * permission checks.
83
+ *
84
+ * @category configuration
85
+ * @since 4.0.0
86
+ */
53
87
  export interface AuthenticationErrorMetadata {
88
+ /**
89
+ * OpenRouter-specific details for the authentication failure.
90
+ */
54
91
  readonly openrouter?: OpenRouterErrorMetadata | null
55
92
  }
56
93
 
94
+ /**
95
+ * OpenRouter metadata attached to `ContentPolicyError` values.
96
+ *
97
+ * Preserves provider error details when OpenRouter rejects input or output
98
+ * because it violates a content policy.
99
+ *
100
+ * @category configuration
101
+ * @since 4.0.0
102
+ */
57
103
  export interface ContentPolicyErrorMetadata {
104
+ /**
105
+ * OpenRouter-specific details for the content policy response.
106
+ */
58
107
  readonly openrouter?: OpenRouterErrorMetadata | null
59
108
  }
60
109
 
110
+ /**
111
+ * OpenRouter metadata attached to `InvalidRequestError` values.
112
+ *
113
+ * Preserves provider error details for malformed requests, unsupported
114
+ * parameters, or other request validation failures reported by OpenRouter.
115
+ *
116
+ * @category configuration
117
+ * @since 4.0.0
118
+ */
61
119
  export interface InvalidRequestErrorMetadata {
120
+ /**
121
+ * OpenRouter-specific details for the invalid request response.
122
+ */
62
123
  readonly openrouter?: OpenRouterErrorMetadata | null
63
124
  }
64
125
 
126
+ /**
127
+ * OpenRouter metadata attached to `InternalProviderError` values.
128
+ *
129
+ * Preserves provider error details for OpenRouter-side failures such as
130
+ * transient server errors or overload responses.
131
+ *
132
+ * @category configuration
133
+ * @since 4.0.0
134
+ */
65
135
  export interface InternalProviderErrorMetadata {
136
+ /**
137
+ * OpenRouter-specific details for the internal provider response.
138
+ */
66
139
  readonly openrouter?: OpenRouterErrorMetadata | null
67
140
  }
68
141
 
142
+ /**
143
+ * OpenRouter metadata attached to `InvalidOutputError` values.
144
+ *
145
+ * Preserves provider error details when an OpenRouter response cannot be
146
+ * parsed or validated as the expected output.
147
+ *
148
+ * @category configuration
149
+ * @since 4.0.0
150
+ */
69
151
  export interface InvalidOutputErrorMetadata {
152
+ /**
153
+ * OpenRouter-specific details for the invalid output response.
154
+ */
70
155
  readonly openrouter?: OpenRouterErrorMetadata | null
71
156
  }
72
157
 
158
+ /**
159
+ * OpenRouter metadata attached to `StructuredOutputError` values.
160
+ *
161
+ * Preserves provider error details when OpenRouter returns content that does
162
+ * not satisfy the requested structured output schema.
163
+ *
164
+ * @category configuration
165
+ * @since 4.0.0
166
+ */
73
167
  export interface StructuredOutputErrorMetadata {
168
+ /**
169
+ * OpenRouter-specific details for the structured output failure.
170
+ */
74
171
  readonly openrouter?: OpenRouterErrorMetadata | null
75
172
  }
76
173
 
174
+ /**
175
+ * OpenRouter metadata attached to `UnsupportedSchemaError` values.
176
+ *
177
+ * Preserves provider error details when an unsupported schema failure is
178
+ * associated with an OpenRouter response.
179
+ *
180
+ * @category configuration
181
+ * @since 4.0.0
182
+ */
77
183
  export interface UnsupportedSchemaErrorMetadata {
184
+ /**
185
+ * OpenRouter-specific details for the unsupported schema failure.
186
+ */
78
187
  readonly openrouter?: OpenRouterErrorMetadata | null
79
188
  }
80
189
 
190
+ /**
191
+ * OpenRouter metadata attached to `UnknownError` values.
192
+ *
193
+ * Preserves provider error details for OpenRouter failures that do not map
194
+ * cleanly to a more specific AI error category.
195
+ *
196
+ * @category configuration
197
+ * @since 4.0.0
198
+ */
81
199
  export interface UnknownErrorMetadata {
200
+ /**
201
+ * OpenRouter-specific details for the unclassified provider failure.
202
+ */
82
203
  readonly openrouter?: OpenRouterErrorMetadata | null
83
204
  }
84
205
  }