@effect/ai-openrouter 4.0.0-beta.10 → 4.0.0-beta.100

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/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@effect/ai-openrouter",
3
- "version": "4.0.0-beta.10",
3
+ "version": "4.0.0-beta.100",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "An OpenRouter provider integration for Effect AI SDK",
7
7
  "homepage": "https://effect.website",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "https://github.com/Effect-TS/effect-smol.git",
10
+ "url": "https://github.com/Effect-TS/effect.git",
11
11
  "directory": "packages/ai/openrouter"
12
12
  },
13
13
  "bugs": {
14
- "url": "https://github.com/Effect-TS/effect-smol/issues"
14
+ "url": "https://github.com/Effect-TS/effect/issues"
15
15
  },
16
16
  "tags": [
17
17
  "typescript",
@@ -43,15 +43,14 @@
43
43
  "provenance": true
44
44
  },
45
45
  "devDependencies": {
46
- "effect": "^4.0.0-beta.10"
46
+ "effect": "^4.0.0-beta.100"
47
47
  },
48
48
  "peerDependencies": {
49
- "effect": "^4.0.0-beta.10"
49
+ "effect": "^4.0.0-beta.100"
50
50
  },
51
51
  "scripts": {
52
52
  "codegen": "effect-utils codegen",
53
53
  "build": "tsc -b tsconfig.json && pnpm babel",
54
- "build:tsgo": "tsgo -b tsconfig.json && pnpm babel",
55
54
  "babel": "babel dist --plugins annotate-pure-calls --out-dir dist --source-maps",
56
55
  "check": "tsc -b tsconfig.json",
57
56
  "test": "vitest",
package/src/Generated.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
 
5
5
  import * as Data from "effect/Data"
@@ -8923,7 +8923,7 @@ export const make = (
8923
8923
  Type,
8924
8924
  DecodingServices
8925
8925
  >(
8926
- schema: Schema.Decoder<Type, DecodingServices>
8926
+ schema: Schema.ConstraintDecoder<Type, DecodingServices>
8927
8927
  ) =>
8928
8928
  (
8929
8929
  request: HttpClientRequest.HttpClientRequest
@@ -8939,10 +8939,10 @@ export const make = (
8939
8939
  Stream.pipeThroughChannel(Sse.decodeDataSchema(schema))
8940
8940
  )
8941
8941
  const decodeSuccess =
8942
- <Schema extends Schema.Top>(schema: Schema) => (response: HttpClientResponse.HttpClientResponse) =>
8942
+ <Schema extends Schema.Constraint>(schema: Schema) => (response: HttpClientResponse.HttpClientResponse) =>
8943
8943
  HttpClientResponse.schemaBodyJson(schema)(response)
8944
8944
  const decodeError =
8945
- <const Tag extends string, Schema extends Schema.Top>(tag: Tag, schema: Schema) =>
8945
+ <const Tag extends string, Schema extends Schema.Constraint>(tag: Tag, schema: Schema) =>
8946
8946
  (response: HttpClientResponse.HttpClientResponse) =>
8947
8947
  Effect.flatMap(
8948
8948
  HttpClientResponse.schemaBodyJson(schema)(response),
@@ -1,14 +1,19 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * The `OpenRouterClient` module provides an Effect service for calling
3
+ * OpenRouter's chat completions API. It wraps the generated OpenRouter HTTP
4
+ * client with Effect-native constructors, layers, authentication and optional
5
+ * site ranking headers, typed errors, and streaming support.
6
+ *
7
+ * @since 4.0.0
3
8
  */
4
9
  import type * as Config from "effect/Config"
10
+ import * as Context from "effect/Context"
5
11
  import * as Effect from "effect/Effect"
6
12
  import { identity } from "effect/Function"
7
13
  import * as Layer from "effect/Layer"
8
14
  import * as Predicate from "effect/Predicate"
9
15
  import type * as Redacted from "effect/Redacted"
10
16
  import * as Schema from "effect/Schema"
11
- import * as ServiceMap from "effect/ServiceMap"
12
17
  import * as Stream from "effect/Stream"
13
18
  import type * as AiError from "effect/unstable/ai/AiError"
14
19
  import * as Sse from "effect/unstable/encoding/Sse"
@@ -27,11 +32,13 @@ import { OpenRouterConfig } from "./OpenRouterConfig.ts"
27
32
  /**
28
33
  * The OpenRouter client service interface.
29
34
  *
35
+ * **Details**
36
+ *
30
37
  * Provides methods for interacting with OpenRouter's Chat Completions API,
31
38
  * including both synchronous and streaming message creation.
32
39
  *
33
- * @since 1.0.0
34
40
  * @category models
41
+ * @since 4.0.0
35
42
  */
36
43
  export interface Service {
37
44
  readonly client: Generated.OpenRouterClient
@@ -55,8 +62,15 @@ export interface Service {
55
62
  }
56
63
 
57
64
  /**
58
- * @since 1.0.0
59
- * @category Models
65
+ * Decoded `data` payload from an OpenRouter chat completion streaming chunk.
66
+ *
67
+ * **Details**
68
+ *
69
+ * The payload contains streamed choices, model metadata, optional usage, and may
70
+ * include an OpenRouter error object for a streamed response.
71
+ *
72
+ * @category models
73
+ * @since 4.0.0
60
74
  */
61
75
  export type ChatStreamingResponseChunkData = typeof Generated.ChatStreamingResponseChunk.fields.data.Type
62
76
 
@@ -65,12 +79,21 @@ export type ChatStreamingResponseChunkData = typeof Generated.ChatStreamingRespo
65
79
  // =============================================================================
66
80
 
67
81
  /**
68
- * Service identifier for the OpenRouter client.
82
+ * Service tag for the OpenRouter client.
83
+ *
84
+ * **When to use**
69
85
  *
70
- * @since 1.0.0
71
- * @category service
86
+ * Use when accessing or providing the OpenRouter client service through
87
+ * Effect's context.
88
+ *
89
+ * @see {@link make} for constructing an OpenRouter client effectfully
90
+ * @see {@link layer} for providing a client from explicit options
91
+ * @see {@link layerConfig} for providing a client from `Config`
92
+ *
93
+ * @category services
94
+ * @since 4.0.0
72
95
  */
73
- export class OpenRouterClient extends ServiceMap.Service<
96
+ export class OpenRouterClient extends Context.Service<
74
97
  OpenRouterClient,
75
98
  Service
76
99
  >()("@effect/ai-openrouter/OpenRouterClient") {}
@@ -80,10 +103,10 @@ export class OpenRouterClient extends ServiceMap.Service<
80
103
  // =============================================================================
81
104
 
82
105
  /**
83
- * Configuration options for creating an OpenRouter client.
106
+ * Configuration for creating an OpenRouter client.
84
107
  *
85
- * @since 1.0.0
86
- * @category models
108
+ * @category options
109
+ * @since 4.0.0
87
110
  */
88
111
  export type Options = {
89
112
  readonly apiKey?: Redacted.Redacted<string> | undefined
@@ -103,7 +126,9 @@ export type Options = {
103
126
  /**
104
127
  * Optional transformer for the underlying HTTP client.
105
128
  *
106
- * Use this to add middleware, logging, or custom request/response handling.
129
+ * **When to use**
130
+ *
131
+ * Use to add middleware, logging, or custom request/response handling.
107
132
  */
108
133
  readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined
109
134
  }
@@ -113,10 +138,30 @@ export type Options = {
113
138
  // =============================================================================
114
139
 
115
140
  /**
116
- * Creates an OpenRouter client service with the given options.
141
+ * Creates an OpenRouter client service from explicit options.
142
+ *
143
+ * **When to use**
144
+ *
145
+ * Use when you need the OpenRouter client service value inside an effect.
146
+ *
147
+ * **Details**
148
+ *
149
+ * The returned service uses the current `HttpClient`, prepends `apiUrl` or
150
+ * `https://openrouter.ai/api/v1`, adds the bearer token and optional
151
+ * `HTTP-Referer` and `X-Title` headers, accepts JSON responses, and applies
152
+ * `transformClient` when provided.
153
+ *
154
+ * **Gotchas**
155
+ *
156
+ * Scoped `OpenRouterConfig.withClientTransform` applies to generated client
157
+ * request methods. Streaming chat completion requests are sent directly by this
158
+ * module and do not read that scoped transform.
159
+ *
160
+ * @see {@link layer} for providing this client from explicit options
161
+ * @see {@link layerConfig} for loading client settings from `Config`
117
162
  *
118
- * @since 1.0.0
119
163
  * @category constructors
164
+ * @since 4.0.0
120
165
  */
121
166
  export const make = Effect.fnUntraced(
122
167
  function*(options: Options): Effect.fn.Return<Service, never, HttpClient.HttpClient> {
@@ -127,7 +172,7 @@ export const make = Effect.fnUntraced(
127
172
  request.pipe(
128
173
  HttpClientRequest.prependUrl(options.apiUrl ?? "https://openrouter.ai/api/v1"),
129
174
  options.apiKey ? HttpClientRequest.bearerToken(options.apiKey) : identity,
130
- options.siteReferrer ? HttpClientRequest.setHeader("HTTP-Referrer", options.siteReferrer) : identity,
175
+ options.siteReferrer ? HttpClientRequest.setHeader("HTTP-Referer", options.siteReferrer) : identity,
131
176
  options.siteTitle ? HttpClientRequest.setHeader("X-Title", options.siteTitle) : identity,
132
177
  HttpClientRequest.acceptJson
133
178
  )
@@ -212,24 +257,45 @@ export const make = Effect.fnUntraced(
212
257
  /**
213
258
  * Creates a layer for the OpenRouter client with the given options.
214
259
  *
215
- * @since 1.0.0
260
+ * **When to use**
261
+ *
262
+ * Use when you already have the OpenRouter client options in code and want to
263
+ * provide `OpenRouterClient` as a layer.
264
+ *
265
+ * @see {@link make} for constructing the client service effectfully
266
+ * @see {@link layerConfig} for loading client settings from `Config`
267
+ *
216
268
  * @category layers
269
+ * @since 4.0.0
217
270
  */
218
271
  export const layer = (options: Options): Layer.Layer<OpenRouterClient, never, HttpClient.HttpClient> =>
219
272
  Layer.effect(OpenRouterClient, make(options))
220
273
 
221
274
  /**
222
- * Creates a layer for the OpenRouter client, loading the requisite
223
- * configuration via Effect's `Config` module.
275
+ * Creates a layer for the OpenRouter client from provided `Config` values.
276
+ *
277
+ * **When to use**
278
+ *
279
+ * Use when you need client settings for OpenRouter to be read from Effect
280
+ * `Config` values while providing `OpenRouterClient` as a layer.
281
+ *
282
+ * **Details**
283
+ *
284
+ * Only config values supplied in `options` are loaded. Omitted fields are
285
+ * passed to `make` as `undefined`, and `transformClient` is forwarded as a
286
+ * plain option.
287
+ *
288
+ * @see {@link make} for constructing the client service effectfully
289
+ * @see {@link layer} for providing the client from already-resolved options
224
290
  *
225
- * @since 1.0.0
226
291
  * @category layers
292
+ * @since 4.0.0
227
293
  */
228
294
  export const layerConfig = (options?: {
229
295
  /**
230
296
  * The config value to load for the API key.
231
297
  */
232
- readonly apiKey?: Config.Config<Redacted.Redacted<string>> | undefined
298
+ readonly apiKey?: Config.Config<Redacted.Redacted<string> | undefined> | undefined
233
299
 
234
300
  /**
235
301
  * The config value to load for the API URL.
@@ -1,35 +1,57 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * The `OpenRouterConfig` module lets a workflow temporarily customize the HTTP
3
+ * client used by generated OpenRouter request methods. `OpenRouterClient` reads
4
+ * this scoped transform when generated client operations execute, so callers can
5
+ * add middleware or instrumentation without rebuilding the client layer.
6
+ *
7
+ * @since 4.0.0
3
8
  */
9
+ import * as Context from "effect/Context"
4
10
  import * as Effect from "effect/Effect"
5
11
  import { dual } from "effect/Function"
6
- import * as ServiceMap from "effect/ServiceMap"
7
12
  import type { HttpClient } from "effect/unstable/http/HttpClient"
8
13
 
9
14
  /**
10
- * @since 1.0.0
15
+ * Context service for scoped OpenRouter provider configuration used by client
16
+ * operations.
17
+ *
18
+ * **When to use**
19
+ *
20
+ * Use as the context service tag when manually providing or reading scoped
21
+ * OpenRouter provider configuration in an Effect context.
22
+ *
23
+ * @see {@link withClientTransform} for scoping an HTTP client transformation
24
+ *
11
25
  * @category services
26
+ * @since 4.0.0
12
27
  */
13
- export class OpenRouterConfig extends ServiceMap.Service<
28
+ export class OpenRouterConfig extends Context.Service<
14
29
  OpenRouterConfig,
15
30
  OpenRouterConfig.Service
16
31
  >()("@effect/ai-openrouter/OpenRouterConfig") {
17
32
  /**
18
- * @since 1.0.0
33
+ * Gets the configured OpenRouter service from the current context when present.
34
+ *
35
+ * @since 4.0.0
19
36
  */
20
37
  static readonly getOrUndefined: Effect.Effect<typeof OpenRouterConfig.Service | undefined> = Effect.map(
21
- Effect.services<never>(),
38
+ Effect.context<never>(),
22
39
  (services) => services.mapUnsafe.get(OpenRouterConfig.key)
23
40
  )
24
41
  }
25
42
 
26
43
  /**
27
- * @since 1.0.0
44
+ * Types associated with the `OpenRouterConfig` context service.
45
+ *
46
+ * @since 4.0.0
28
47
  */
29
48
  export declare namespace OpenRouterConfig {
30
49
  /**
31
- * @since 1.0.0
50
+ * Configuration values read by OpenRouter provider operations when resolving
51
+ * the generated HTTP client.
52
+ *
32
53
  * @category models
54
+ * @since 4.0.0
33
55
  */
34
56
  export interface Service {
35
57
  readonly transformClient?: ((client: HttpClient) => HttpClient) | undefined
@@ -37,18 +59,81 @@ export declare namespace OpenRouterConfig {
37
59
  }
38
60
 
39
61
  /**
40
- * @since 1.0.0
62
+ * Provides a scoped transform for the OpenRouter HTTP client used by provider
63
+ * operations.
64
+ *
65
+ * **When to use**
66
+ *
67
+ * Use when you need temporary OpenRouter HTTP client customization for a
68
+ * single effect or workflow without rebuilding the client layer.
69
+ *
70
+ * **Details**
71
+ *
72
+ * Supports both data-first and data-last forms. The transform is stored in the
73
+ * scoped `OpenRouterConfig` service and read by generated OpenRouter request
74
+ * operations while running the supplied effect.
75
+ *
76
+ * **Gotchas**
77
+ *
78
+ * If a transform is already present in the scoped config, this helper replaces
79
+ * it. Compose transforms manually when both should apply. Streaming chat
80
+ * completion requests are sent directly by `OpenRouterClient.make` and do not
81
+ * read this scoped transform.
82
+ *
41
83
  * @category configuration
84
+ * @since 4.0.0
42
85
  */
43
86
  export const withClientTransform: {
44
87
  /**
45
- * @since 1.0.0
88
+ * Provides a scoped transform for the OpenRouter HTTP client used by provider
89
+ * operations.
90
+ *
91
+ * **When to use**
92
+ *
93
+ * Use when you need temporary OpenRouter HTTP client customization for a
94
+ * single effect or workflow 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
+ *
46
109
  * @category configuration
110
+ * @since 4.0.0
47
111
  */
48
112
  (transform: (client: HttpClient) => HttpClient): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
49
113
  /**
50
- * @since 1.0.0
114
+ * Provides a scoped transform for the OpenRouter HTTP client used by provider
115
+ * operations.
116
+ *
117
+ * **When to use**
118
+ *
119
+ * Use when you need temporary OpenRouter HTTP client customization for a
120
+ * single effect or workflow 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
+ *
51
135
  * @category configuration
136
+ * @since 4.0.0
52
137
  */
53
138
  <A, E, R>(
54
139
  self: Effect.Effect<A, E, R>,
@@ -56,13 +141,55 @@ export const withClientTransform: {
56
141
  ): Effect.Effect<A, E, R>
57
142
  } = dual<
58
143
  /**
59
- * @since 1.0.0
144
+ * Provides a scoped transform for the OpenRouter HTTP client used by provider
145
+ * operations.
146
+ *
147
+ * **When to use**
148
+ *
149
+ * Use when you need temporary OpenRouter HTTP client customization for a
150
+ * single effect or workflow without rebuilding the client layer.
151
+ *
152
+ * **Details**
153
+ *
154
+ * Supports both data-first and data-last forms. The transform is stored in the
155
+ * scoped `OpenRouterConfig` service and read by generated OpenRouter request
156
+ * operations while running the supplied effect.
157
+ *
158
+ * **Gotchas**
159
+ *
160
+ * If a transform is already present in the scoped config, this helper replaces
161
+ * it. Compose transforms manually when both should apply. Streaming chat
162
+ * completion requests are sent directly by `OpenRouterClient.make` and do not
163
+ * read this scoped transform.
164
+ *
60
165
  * @category configuration
166
+ * @since 4.0.0
61
167
  */
62
168
  (transform: (client: HttpClient) => HttpClient) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,
63
169
  /**
64
- * @since 1.0.0
170
+ * Provides a scoped transform for the OpenRouter HTTP client used by provider
171
+ * operations.
172
+ *
173
+ * **When to use**
174
+ *
175
+ * Use when you need temporary OpenRouter HTTP client customization for a
176
+ * single effect or workflow 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
+ *
65
191
  * @category configuration
192
+ * @since 4.0.0
66
193
  */
67
194
  <A, E, R>(
68
195
  self: Effect.Effect<A, E, R>,