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

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/src/index.ts CHANGED
@@ -1,21 +1,61 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
 
5
5
  // @barrel: Auto-generated exports. Do not edit manually.
6
6
 
7
7
  /**
8
- * @since 1.0.0
8
+ * @since 4.0.0
9
9
  */
10
10
  export * as Generated from "./Generated.ts"
11
11
 
12
12
  /**
13
- * @since 1.0.0
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
+ * @since 4.0.0
14
36
  */
15
37
  export * as OpenRouterClient from "./OpenRouterClient.ts"
16
38
 
17
39
  /**
18
- * @since 1.0.0
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
+ * @since 4.0.0
19
59
  */
20
60
  export * as OpenRouterConfig from "./OpenRouterConfig.ts"
21
61
 
@@ -25,11 +65,31 @@ export * as OpenRouterConfig from "./OpenRouterConfig.ts"
25
65
  * Provides OpenRouter-specific metadata fields for AI error types through
26
66
  * module augmentation, enabling typed access to OpenRouter error details.
27
67
  *
28
- * @since 1.0.0
68
+ * @since 4.0.0
29
69
  */
30
70
  export * as OpenRouterError from "./OpenRouterError.ts"
31
71
 
32
72
  /**
33
- * @since 1.0.0
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
+ * @since 4.0.0
34
94
  */
35
95
  export * as OpenRouterLanguageModel from "./OpenRouterLanguageModel.ts"
@@ -192,12 +192,14 @@ export const parseRateLimitHeaders = (headers: Record<string, string>) => {
192
192
  let retryAfter: Duration.Duration | undefined
193
193
  if (Predicate.isNotUndefined(retryAfterRaw)) {
194
194
  const parsed = Number.parse(retryAfterRaw)
195
- if (Predicate.isNotUndefined(parsed)) {
196
- retryAfter = Duration.seconds(parsed)
195
+ if (Option.isSome(parsed)) {
196
+ retryAfter = Duration.seconds(parsed.value)
197
197
  }
198
198
  }
199
199
  const remainingRaw = headers["x-ratelimit-remaining-requests"]
200
- const remaining = Predicate.isNotUndefined(remainingRaw) ? Number.parse(remainingRaw) ?? null : null
200
+ const remaining = Predicate.isNotUndefined(remainingRaw)
201
+ ? Option.getOrNull(Number.parse(remainingRaw))
202
+ : null
201
203
  return {
202
204
  retryAfter,
203
205
  limit: headers["x-ratelimit-limit-requests"] ?? null,
@@ -218,7 +220,7 @@ export const buildHttpRequestDetails = (
218
220
  method: request.method,
219
221
  url: request.url,
220
222
  urlParams: Array.from(request.urlParams),
221
- hash: request.hash,
223
+ hash: Option.getOrUndefined(request.hash),
222
224
  headers: Redactable.redact(request.headers) as Record<string, string>
223
225
  })
224
226
 
@@ -41,7 +41,6 @@ export class ReasoningDetailsDuplicateTracker {
41
41
  /**
42
42
  * Attempts to track a detail.
43
43
  *
44
- * @returns `true` if this is a NEW detail (not seen before and has valid key),
45
44
  * or `false` if it was skipped (no valid key) or already seen (duplicate).
46
45
  */
47
46
  upsert(detail: ReasoningDetails[number]): boolean {