@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,5 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
  import * as Effect from "effect/Effect";
5
5
  import type { SchemaError } from "effect/Schema";
package/dist/Generated.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
  import * as Data from "effect/Data";
5
5
  import * as Effect from "effect/Effect";
@@ -1,5 +1,27 @@
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, typed errors, and streaming
5
+ * support.
6
+ *
7
+ * **Common tasks**
8
+ *
9
+ * - Build a client from explicit options with {@link make}
10
+ * - Provide the client to an application with {@link layer} or {@link layerConfig}
11
+ * - Create non-streaming chat completions with {@link Service.createChatCompletion}
12
+ * - Create server-sent event chat completion streams with
13
+ * {@link Service.createChatCompletionStream}
14
+ * - Customize authentication, base URL, OpenRouter ranking headers, or the
15
+ * underlying HTTP client through {@link Options}
16
+ *
17
+ * **Gotchas**
18
+ *
19
+ * - Streaming requests are sent directly to `/chat/completions` with `stream`
20
+ * and `stream_options.include_usage` enabled by this module.
21
+ * - OpenRouter API failures, HTTP client failures, and schema decoding failures
22
+ * are mapped into `AiError` values for the exported service methods.
23
+ *
24
+ * @since 4.0.0
3
25
  */
4
26
  import type * as Config from "effect/Config";
5
27
  import * as Context from "effect/Context";
@@ -17,8 +39,8 @@ import * as Generated from "./Generated.ts";
17
39
  * Provides methods for interacting with OpenRouter's Chat Completions API,
18
40
  * including both synchronous and streaming message creation.
19
41
  *
20
- * @since 1.0.0
21
42
  * @category models
43
+ * @since 4.0.0
22
44
  */
23
45
  export interface Service {
24
46
  readonly client: Generated.OpenRouterClient;
@@ -32,24 +54,31 @@ export interface Service {
32
54
  ], AiError.AiError>;
33
55
  }
34
56
  /**
35
- * @since 1.0.0
36
- * @category Models
57
+ * Decoded `data` payload from an OpenRouter chat completion streaming chunk.
58
+ *
59
+ * **Details**
60
+ *
61
+ * The payload contains streamed choices, model metadata, optional usage, and may
62
+ * include an OpenRouter error object for a streamed response.
63
+ *
64
+ * @category models
65
+ * @since 4.0.0
37
66
  */
38
67
  export type ChatStreamingResponseChunkData = typeof Generated.ChatStreamingResponseChunk.fields.data.Type;
39
68
  declare const OpenRouterClient_base: Context.ServiceClass<OpenRouterClient, "@effect/ai-openrouter/OpenRouterClient", Service>;
40
69
  /**
41
70
  * Service identifier for the OpenRouter client.
42
71
  *
43
- * @since 1.0.0
44
- * @category service
72
+ * @category services
73
+ * @since 4.0.0
45
74
  */
46
75
  export declare class OpenRouterClient extends OpenRouterClient_base {
47
76
  }
48
77
  /**
49
78
  * Configuration options for creating an OpenRouter client.
50
79
  *
51
- * @since 1.0.0
52
80
  * @category models
81
+ * @since 4.0.0
53
82
  */
54
83
  export type Options = {
55
84
  readonly apiKey?: Redacted.Redacted<string> | undefined;
@@ -72,23 +101,23 @@ export type Options = {
72
101
  /**
73
102
  * Creates an OpenRouter client service with the given options.
74
103
  *
75
- * @since 1.0.0
76
104
  * @category constructors
105
+ * @since 4.0.0
77
106
  */
78
107
  export declare const make: (options: Options) => Effect.Effect<Service, never, HttpClient.HttpClient>;
79
108
  /**
80
109
  * Creates a layer for the OpenRouter client with the given options.
81
110
  *
82
- * @since 1.0.0
83
111
  * @category layers
112
+ * @since 4.0.0
84
113
  */
85
114
  export declare const layer: (options: Options) => Layer.Layer<OpenRouterClient, never, HttpClient.HttpClient>;
86
115
  /**
87
116
  * Creates a layer for the OpenRouter client, loading the requisite
88
117
  * configuration via Effect's `Config` module.
89
118
  *
90
- * @since 1.0.0
91
119
  * @category layers
120
+ * @since 4.0.0
92
121
  */
93
122
  export declare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A;AAMD;;;;;GAKG;AACH,eAAO,MAAM,IAAI,4EAqFhB,CAAA;AAMD;;;;;GAKG;AACH,eAAO,MAAM,KAAK,GAAI,SAAS,OAAO,KAAG,KAAK,CAAC,KAAK,CAAC,gBAAgB,EAAE,KAAK,EAAE,UAAU,CAAC,UAAU,CACpD,CAAA;AAE/C;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,UAAU;IACpC;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,GAAG,SAAS,CAAA;IAElF;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,SAAS,CAAA;IAEnD;;OAEG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,SAAS,CAAA;IAEzD;;OAEG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,SAAS,CAAA;IAEtD;;OAEG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,UAAU,KAAK,UAAU,CAAC,UAAU,CAAC,GAAG,SAAS,CAAA;CAClG,KAAG,KAAK,CAAC,KAAK,CAAC,gBAAgB,EAAE,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,UAAU,CAwBxE,CAAA"}
@@ -18,8 +18,8 @@ import { OpenRouterConfig } from "./OpenRouterConfig.js";
18
18
  /**
19
19
  * Service identifier for the OpenRouter client.
20
20
  *
21
- * @since 1.0.0
22
- * @category service
21
+ * @category services
22
+ * @since 4.0.0
23
23
  */
24
24
  export class OpenRouterClient extends /*#__PURE__*/Context.Service()("@effect/ai-openrouter/OpenRouterClient") {}
25
25
  // =============================================================================
@@ -28,8 +28,8 @@ export class OpenRouterClient extends /*#__PURE__*/Context.Service()("@effect/ai
28
28
  /**
29
29
  * Creates an OpenRouter client service with the given options.
30
30
  *
31
- * @since 1.0.0
32
31
  * @category constructors
32
+ * @since 4.0.0
33
33
  */
34
34
  export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
35
35
  const baseClient = yield* HttpClient.HttpClient;
@@ -87,16 +87,16 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
87
87
  /**
88
88
  * Creates a layer for the OpenRouter client with the given options.
89
89
  *
90
- * @since 1.0.0
91
90
  * @category layers
91
+ * @since 4.0.0
92
92
  */
93
93
  export const layer = options => Layer.effect(OpenRouterClient, make(options));
94
94
  /**
95
95
  * Creates a layer for the OpenRouter client, loading the requisite
96
96
  * configuration via Effect's `Config` module.
97
97
  *
98
- * @since 1.0.0
99
98
  * @category layers
99
+ * @since 4.0.0
100
100
  */
101
101
  export const layerConfig = options => Layer.effect(OpenRouterClient, Effect.gen(function* () {
102
102
  const apiKey = Predicate.isNotUndefined(options?.apiKey) ? yield* options.apiKey : undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"OpenRouterClient.js","names":["Context","Effect","identity","Layer","Predicate","Schema","Stream","Sse","HttpBody","HttpClient","HttpClientRequest","Generated","Errors","OpenRouterConfig","OpenRouterClient","Service","make","fnUntraced","options","baseClient","httpClient","pipe","mapRequest","request","prependUrl","apiUrl","apiKey","bearerToken","siteReferrer","setHeader","siteTitle","acceptJson","transformClient","httpClientOk","filterStatusOk","client","config","getOrUndefined","isNotUndefined","createChatCompletion","payload","sendChatCompletionRequest","includeResponse","catchTags","SendChatCompletionRequest400","error","fail","mapClientError","SendChatCompletionRequest401","SendChatCompletionRequest429","SendChatCompletionRequest500","HttpClientError","mapHttpClientError","SchemaError","mapSchemaError","buildChatCompletionStream","response","stream","decodeText","pipeThroughChannel","decode","mapEffect","event","decodeChatCompletionSseData","data","takeWhile","Retry","die","fromEffect","createChatCompletionStream","execute","post","body","jsonUnsafe","stream_options","include_usage","map","catchTag","of","layer","effect","layerConfig","gen","undefined","ChatStreamingResponseChunkDataFromString","fromJsonString","ChatStreamingResponseChunk","fields","decodeChatStreamingResponseChunkData","decodeUnknownEffect","succeed"],"sources":["../src/OpenRouterClient.ts"],"sourcesContent":[null],"mappings":"AAIA,OAAO,KAAKA,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,SAASC,QAAQ,QAAQ,iBAAiB;AAC1C,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,SAAS,MAAM,kBAAkB;AAE7C,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,MAAM,MAAM,eAAe;AAEvC,OAAO,KAAKC,GAAG,MAAM,8BAA8B;AACnD,OAAO,KAAKC,QAAQ,MAAM,+BAA+B;AACzD,OAAO,KAAKC,UAAU,MAAM,iCAAiC;AAC7D,OAAO,KAAKC,iBAAiB,MAAM,wCAAwC;AAE3E,OAAO,KAAKC,SAAS,MAAM,gBAAgB;AAC3C,OAAO,KAAKC,MAAM,MAAM,sBAAsB;AAC9C,SAASC,gBAAgB,QAAQ,uBAAuB;AA0CxD;AACA;AACA;AAEA;;;;;;AAMA,OAAM,MAAOC,gBAAiB,sBAAQd,OAAO,CAACe,OAAO,EAGlD,CAAC,wCAAwC,CAAC;AAmC7C;AACA;AACA;AAEA;;;;;;AAMA,OAAO,MAAMC,IAAI,gBAAGf,MAAM,CAACgB,UAAU,CACnC,WAAUC,OAAgB;EACxB,MAAMC,UAAU,GAAG,OAAOV,UAAU,CAACA,UAAU;EAE/C,MAAMW,UAAU,GAAGD,UAAU,CAACE,IAAI,CAChCZ,UAAU,CAACa,UAAU,CAAEC,OAAO,IAC5BA,OAAO,CAACF,IAAI,CACVX,iBAAiB,CAACc,UAAU,CAACN,OAAO,CAACO,MAAM,IAAI,8BAA8B,CAAC,EAC9EP,OAAO,CAACQ,MAAM,GAAGhB,iBAAiB,CAACiB,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E,OAAOV,OAAO,CAACU,YAAY,GAC3BuD,SAAS;EACb,MAAMrD,SAAS,GAAG1B,SAAS,CAACkC,cAAc,CAACpB,OAAO,EAAEY,SAAS,CAAC,GAC1D,OAAOZ,OAAO,CAACY,SAAS,GACxBqD,SAAS;EACb,OAAO,OAAOnE,IAAI,CAAC;IACjBU,MAAM;IACND,MAAM;IACNG,YAAY;IACZE,SAAS;IACTE,eAAe,EAAEd,OAAO,EAAEc;GAC3B,CAAC;AACJ,CAAC,CAAC,CACH;AAEH;AACA;AACA;AAEA,MAAMoD,wCAAwC,gBAAG/E,MAAM,CAACgF,cAAc,CAAC1E,SAAS,CAAC2E,0BAA0B,CAACC,MAAM,CAACvB,IAAI,CAAC;AACxH,MAAMwB,oCAAoC,gBAAGnF,MAAM,CAACoF,mBAAmB,CAACL,wCAAwC,CAAC;AAEjH,MAAMrB,2BAA2B,GAC/BC,IAAY,IAEZA,IAAI,KAAK,QAAQ,GACb/D,MAAM,CAACyF,OAAO,CAAC1B,IAAI,CAAC,GACpBwB,oCAAoC,CAACxB,IAAI,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"OpenRouterClient.js","names":["Context","Effect","identity","Layer","Predicate","Schema","Stream","Sse","HttpBody","HttpClient","HttpClientRequest","Generated","Errors","OpenRouterConfig","OpenRouterClient","Service","make","fnUntraced","options","baseClient","httpClient","pipe","mapRequest","request","prependUrl","apiUrl","apiKey","bearerToken","siteReferrer","setHeader","siteTitle","acceptJson","transformClient","httpClientOk","filterStatusOk","client","config","getOrUndefined","isNotUndefined","createChatCompletion","payload","sendChatCompletionRequest","includeResponse","catchTags","SendChatCompletionRequest400","error","fail","mapClientError","SendChatCompletionRequest401","SendChatCompletionRequest429","SendChatCompletionRequest500","HttpClientError","mapHttpClientError","SchemaError","mapSchemaError","buildChatCompletionStream","response","stream","decodeText","pipeThroughChannel","decode","mapEffect","event","decodeChatCompletionSseData","data","takeWhile","Retry","die","fromEffect","createChatCompletionStream","execute","post","body","jsonUnsafe","stream_options","include_usage","map","catchTag","of","layer","effect","layerConfig","gen","undefined","ChatStreamingResponseChunkDataFromString","fromJsonString","ChatStreamingResponseChunk","fields","decodeChatStreamingResponseChunkData","decodeUnknownEffect","succeed"],"sources":["../src/OpenRouterClient.ts"],"sourcesContent":[null],"mappings":"AA0BA,OAAO,KAAKA,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,SAASC,QAAQ,QAAQ,iBAAiB;AAC1C,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,SAAS,MAAM,kBAAkB;AAE7C,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,MAAM,MAAM,eAAe;AAEvC,OAAO,KAAKC,GAAG,MAAM,8BAA8B;AACnD,OAAO,KAAKC,QAAQ,MAAM,+BAA+B;AACzD,OAAO,KAAKC,UAAU,MAAM,iCAAiC;AAC7D,OAAO,KAAKC,iBAAiB,MAAM,wCAAwC;AAE3E,OAAO,KAAKC,SAAS,MAAM,gBAAgB;AAC3C,OAAO,KAAKC,MAAM,MAAM,sBAAsB;AAC9C,SAASC,gBAAgB,QAAQ,uBAAuB;AAiDxD;AACA;AACA;AAEA;;;;;;AAMA,OAAM,MAAOC,gBAAiB,sBAAQd,OAAO,CAACe,OAAO,EAGlD,CAAC,wCAAwC,CAAC;AAmC7C;AACA;AACA;AAEA;;;;;;AAMA,OAAO,MAAMC,IAAI,gBAAGf,MAAM,CAACgB,UAAU,CACnC,WAAUC,OAAgB;EACxB,MAAMC,UAAU,GAAG,OAAOV,UAAU,CAACA,UAAU;EAE/C,MAAMW,UAAU,GAAGD,UAAU,CAACE,IAAI,CAChCZ,UAAU,CAACa,UAAU,CAAEC,OAAO,IAC5BA,OAAO,CAACF,IAAI,CACVX,iBAAiB,CAACc,UAAU,CAACN,OAAO,CAACO,MAAM,IAAI,8BAA8B,CAAC,EAC9EP,OAAO,CAACQ,MAAM,GAAGhB,iBAAiB,CA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,GAChE,OAAOV,OAAO,CAACU,YAAY,GAC3BuD,SAAS;EACb,MAAMrD,SAAS,GAAG1B,SAAS,CAACkC,cAAc,CAACpB,OAAO,EAAEY,SAAS,CAAC,GAC1D,OAAOZ,OAAO,CAACY,SAAS,GACxBqD,SAAS;EACb,OAAO,OAAOnE,IAAI,CAAC;IACjBU,MAAM;IACND,MAAM;IACNG,YAAY;IACZE,SAAS;IACTE,eAAe,EAAEd,OAAO,EAAEc;GAC3B,CAAC;AACJ,CAAC,CAAC,CACH;AAEH;AACA;AACA;AAEA,MAAMoD,wCAAwC,gBAAG/E,MAAM,CAACgF,cAAc,CAAC1E,SAAS,CAAC2E,0BAA0B,CAACC,MAAM,CAACvB,IAAI,CAAC;AACxH,MAAMwB,oCAAoC,gBAAGnF,MAAM,CAACoF,mBAAmB,CAACL,wCAAwC,CAAC;AAEjH,MAAMrB,2BAA2B,GAC/BC,IAAY,IAEZA,IAAI,KAAK,QAAQ,GACb/D,MAAM,CAACyF,OAAO,CAAC1B,IAAI,CAAC,GACpBwB,oCAAoC,CAACxB,IAAI,CAAC","ignoreList":[]}
@@ -1,45 +1,82 @@
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";
6
24
  import type { HttpClient } from "effect/unstable/http/HttpClient";
7
25
  declare const OpenRouterConfig_base: Context.ServiceClass<OpenRouterConfig, "@effect/ai-openrouter/OpenRouterConfig", OpenRouterConfig.Service>;
8
26
  /**
9
- * @since 1.0.0
27
+ * Context service carrying scoped OpenRouter provider configuration for client
28
+ * operations.
29
+ *
10
30
  * @category services
31
+ * @since 4.0.0
11
32
  */
12
33
  export declare class OpenRouterConfig extends OpenRouterConfig_base {
13
34
  /**
14
- * @since 1.0.0
35
+ * Gets the configured OpenRouter service from the current context when present.
36
+ *
37
+ * @since 4.0.0
15
38
  */
16
39
  static readonly getOrUndefined: Effect.Effect<typeof OpenRouterConfig.Service | undefined>;
17
40
  }
18
41
  /**
19
- * @since 1.0.0
42
+ * Types associated with the `OpenRouterConfig` context service.
43
+ *
44
+ * @since 4.0.0
20
45
  */
21
46
  export declare namespace OpenRouterConfig {
22
47
  /**
23
- * @since 1.0.0
48
+ * Configuration values read by OpenRouter provider operations when resolving
49
+ * the generated HTTP client.
50
+ *
24
51
  * @category models
52
+ * @since 4.0.0
25
53
  */
26
54
  interface Service {
27
55
  readonly transformClient?: ((client: HttpClient) => HttpClient) | undefined;
28
56
  }
29
57
  }
30
58
  /**
31
- * @since 1.0.0
59
+ * Provides a scoped transform for the OpenRouter HTTP client used by provider
60
+ * operations.
61
+ *
32
62
  * @category configuration
63
+ * @since 4.0.0
33
64
  */
34
65
  export declare const withClientTransform: {
35
66
  /**
36
- * @since 1.0.0
67
+ * Provides a scoped transform for the OpenRouter HTTP client used by provider
68
+ * operations.
69
+ *
37
70
  * @category configuration
71
+ * @since 4.0.0
38
72
  */
39
73
  (transform: (client: HttpClient) => HttpClient): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
40
74
  /**
41
- * @since 1.0.0
75
+ * Provides a scoped transform for the OpenRouter HTTP client used by provider
76
+ * operations.
77
+ *
42
78
  * @category configuration
79
+ * @since 4.0.0
43
80
  */
44
81
  <A, E, R>(self: Effect.Effect<A, E, R>, transform: (client: HttpClient) => HttpClient): Effect.Effect<A, E, R>;
45
82
  };
@@ -1 +1 @@
1
- {"version":3,"file":"OpenRouterConfig.d.ts","sourceRoot":"","sources":["../src/OpenRouterConfig.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;;AAEjE;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,qBAGO;IAC3C;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,gBAAgB,CAAC,OAAO,GAAG,SAAS,CAAC,CAGzF;CACF;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,WAAW,gBAAgB,CAAC;IACxC;;;OAGG;IACH,UAAiB,OAAO;QACtB,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,UAAU,KAAK,UAAU,CAAC,GAAG,SAAS,CAAA;KAC5E;CACF;AAED;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE;IAChC;;;OAGG;IACH,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,UAAU,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;IAClH;;;OAGG;IACH,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EACN,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC5B,SAAS,EAAE,CAAC,MAAM,EAA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EAC5B,SAAS,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,UAAU,GAC5C,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;CA4B1B,CAAA"}
@@ -1,22 +1,48 @@
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";
6
24
  import { dual } from "effect/Function";
7
25
  /**
8
- * @since 1.0.0
26
+ * Context service carrying scoped OpenRouter provider configuration for client
27
+ * operations.
28
+ *
9
29
  * @category services
30
+ * @since 4.0.0
10
31
  */
11
32
  export class OpenRouterConfig extends /*#__PURE__*/Context.Service()("@effect/ai-openrouter/OpenRouterConfig") {
12
33
  /**
13
- * @since 1.0.0
34
+ * Gets the configured OpenRouter service from the current context when present.
35
+ *
36
+ * @since 4.0.0
14
37
  */
15
38
  static getOrUndefined = /*#__PURE__*/Effect.map(/*#__PURE__*/Effect.context(), services => services.mapUnsafe.get(OpenRouterConfig.key));
16
39
  }
17
40
  /**
18
- * @since 1.0.0
41
+ * Provides a scoped transform for the OpenRouter HTTP client used by provider
42
+ * operations.
43
+ *
19
44
  * @category configuration
45
+ * @since 4.0.0
20
46
  */
21
47
  export const withClientTransform = /*#__PURE__*/dual(2, (self, transformClient) => Effect.flatMap(OpenRouterConfig.getOrUndefined, config => Effect.provideService(self, OpenRouterConfig, {
22
48
  ...config,
@@ -1 +1 @@
1
- {"version":3,"file":"OpenRouterConfig.js","names":["Context","Effect","dual","OpenRouterConfig","Service","getOrUndefined","map","context","services","mapUnsafe","get","key","withClientTransform","self","transformClient","flatMap","config","provideService"],"sources":["../src/OpenRouterConfig.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,SAASC,IAAI,QAAQ,iBAAiB;AAGtC;;;;AAIA,OAAM,MAAOC,gBAAiB,sBAAQH,OAAO,CAACI,OAAO,EAGlD,CAAC,wCAAwC,CAAC;EAC3C;;;EAGA,OAAgBC,cAAc,gBAA+DJ,MAAM,CAACK,GAAG,cACrGL,MAAM,CAACM,OAAO,EAAS,EACtBC,QAAQ,IAAKA,QAAQ,CAACC,SAAS,CAACC,GAAG,CAACP,gBAAgB,CAACQ,GAAG,CAAC,CAC3D;;AAgBH;;;;AAIA,OAAO,MAAMC,mBAAmB,gBAc5BV,IAAI,CAeN,CAAC,EACD,CAACW,IAAI,EAAEC,eAAe,KACpBb,MAAM,CAACc,OAAO,CACZZ,gBAAgB,CAACE,cAAc,EAC9BW,MAAM,IAAKf,MAAM,CAACgB,cAAc,CAACJ,IAAI,EAAEV,gBAAgB,EAAE;EAAE,GAAGa,MAAM;EAAEF;AAAe,CAAE,CAAC,CAC1F,CACJ","ignoreList":[]}
1
+ {"version":3,"file":"OpenRouterConfig.js","names":["Context","Effect","dual","OpenRouterConfig","Service","getOrUndefined","map","context","services","mapUnsafe","get","key","withClientTransform","self","transformClient","flatMap","config","provideService"],"sources":["../src/OpenRouterConfig.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;AAqBA,OAAO,KAAKA,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,SAASC,IAAI,QAAQ,iBAAiB;AAGtC;;;;;;;AAOA,OAAM,MAAOC,gBAAiB,sBAAQH,OAAO,CAACI,OAAO,EAGlD,CAAC,wCAAwC,CAAC;EAC3C;;;;;EAKA,OAAgBC,cAAc,gBAA+DJ,MAAM,CAACK,GAAG,cACrGL,MAAM,CAACM,OAAO,EAAS,EACtBC,QAAQ,IAAKA,QAAQ,CAACC,SAAS,CAACC,GAAG,CAACP,gBAAgB,CAACQ,GAAG,CAAC,CAC3D;;AAqBH;;;;;;;AAOA,OAAO,MAAMC,mBAAmB,gBAoB5BV,IAAI,CAqBN,CAAC,EACD,CAACW,IAAI,EAAEC,eAAe,KACpBb,MAAM,CAACc,OAAO,CACZZ,gBAAgB,CAACE,cAAc,EAC9BW,MAAM,IAAKf,MAAM,CAACgB,cAAc,CAACJ,IAAI,EAAEV,gBAAgB,EAAE;EAAE,GAAGa,MAAM;EAAEF;AAAe,CAAE,CAAC,CAC1F,CACJ","ignoreList":[]}
@@ -4,13 +4,13 @@
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
  * OpenRouter-specific error metadata fields.
11
11
  *
12
- * @since 1.0.0
13
12
  * @category models
13
+ * @since 4.0.0
14
14
  */
15
15
  export type OpenRouterErrorMetadata = {
16
16
  /**
@@ -29,8 +29,8 @@ export type OpenRouterErrorMetadata = {
29
29
  /**
30
30
  * OpenRouter-specific rate limit metadata fields.
31
31
  *
32
- * @since 1.0.0
33
32
  * @category models
33
+ * @since 4.0.0
34
34
  */
35
35
  export type OpenRouterRateLimitMetadata = OpenRouterErrorMetadata & {
36
36
  readonly limit: string | null;
@@ -39,34 +39,155 @@ export type OpenRouterRateLimitMetadata = OpenRouterErrorMetadata & {
39
39
  readonly resetTokens: string | null;
40
40
  };
41
41
  declare module "effect/unstable/ai/AiError" {
42
+ /**
43
+ * OpenRouter metadata attached to `RateLimitError` values.
44
+ *
45
+ * Captures OpenRouter error details together with rate limit header
46
+ * information from responses where the provider rejected the request because
47
+ * a limit was reached.
48
+ *
49
+ * @category configuration
50
+ * @since 4.0.0
51
+ */
42
52
  interface RateLimitErrorMetadata {
53
+ /**
54
+ * OpenRouter-specific details for the rate limit response.
55
+ */
43
56
  readonly openrouter?: OpenRouterRateLimitMetadata | null;
44
57
  }
58
+ /**
59
+ * OpenRouter metadata attached to `QuotaExhaustedError` values.
60
+ *
61
+ * Preserves provider error details for failures caused by exhausted account,
62
+ * billing, or usage quota.
63
+ *
64
+ * @category configuration
65
+ * @since 4.0.0
66
+ */
45
67
  interface QuotaExhaustedErrorMetadata {
68
+ /**
69
+ * OpenRouter-specific details for the quota exhaustion response.
70
+ */
46
71
  readonly openrouter?: OpenRouterErrorMetadata | null;
47
72
  }
73
+ /**
74
+ * OpenRouter metadata attached to `AuthenticationError` values.
75
+ *
76
+ * Preserves provider error details for failed API key, authorization, or
77
+ * permission checks.
78
+ *
79
+ * @category configuration
80
+ * @since 4.0.0
81
+ */
48
82
  interface AuthenticationErrorMetadata {
83
+ /**
84
+ * OpenRouter-specific details for the authentication failure.
85
+ */
49
86
  readonly openrouter?: OpenRouterErrorMetadata | null;
50
87
  }
88
+ /**
89
+ * OpenRouter metadata attached to `ContentPolicyError` values.
90
+ *
91
+ * Preserves provider error details when OpenRouter rejects input or output
92
+ * because it violates a content policy.
93
+ *
94
+ * @category configuration
95
+ * @since 4.0.0
96
+ */
51
97
  interface ContentPolicyErrorMetadata {
98
+ /**
99
+ * OpenRouter-specific details for the content policy response.
100
+ */
52
101
  readonly openrouter?: OpenRouterErrorMetadata | null;
53
102
  }
103
+ /**
104
+ * OpenRouter metadata attached to `InvalidRequestError` values.
105
+ *
106
+ * Preserves provider error details for malformed requests, unsupported
107
+ * parameters, or other request validation failures reported by OpenRouter.
108
+ *
109
+ * @category configuration
110
+ * @since 4.0.0
111
+ */
54
112
  interface InvalidRequestErrorMetadata {
113
+ /**
114
+ * OpenRouter-specific details for the invalid request response.
115
+ */
55
116
  readonly openrouter?: OpenRouterErrorMetadata | null;
56
117
  }
118
+ /**
119
+ * OpenRouter metadata attached to `InternalProviderError` values.
120
+ *
121
+ * Preserves provider error details for OpenRouter-side failures such as
122
+ * transient server errors or overload responses.
123
+ *
124
+ * @category configuration
125
+ * @since 4.0.0
126
+ */
57
127
  interface InternalProviderErrorMetadata {
128
+ /**
129
+ * OpenRouter-specific details for the internal provider response.
130
+ */
58
131
  readonly openrouter?: OpenRouterErrorMetadata | null;
59
132
  }
133
+ /**
134
+ * OpenRouter metadata attached to `InvalidOutputError` values.
135
+ *
136
+ * Preserves provider error details when an OpenRouter response cannot be
137
+ * parsed or validated as the expected output.
138
+ *
139
+ * @category configuration
140
+ * @since 4.0.0
141
+ */
60
142
  interface InvalidOutputErrorMetadata {
143
+ /**
144
+ * OpenRouter-specific details for the invalid output response.
145
+ */
61
146
  readonly openrouter?: OpenRouterErrorMetadata | null;
62
147
  }
148
+ /**
149
+ * OpenRouter metadata attached to `StructuredOutputError` values.
150
+ *
151
+ * Preserves provider error details when OpenRouter returns content that does
152
+ * not satisfy the requested structured output schema.
153
+ *
154
+ * @category configuration
155
+ * @since 4.0.0
156
+ */
63
157
  interface StructuredOutputErrorMetadata {
158
+ /**
159
+ * OpenRouter-specific details for the structured output failure.
160
+ */
64
161
  readonly openrouter?: OpenRouterErrorMetadata | null;
65
162
  }
163
+ /**
164
+ * OpenRouter metadata attached to `UnsupportedSchemaError` values.
165
+ *
166
+ * Preserves provider error details when an unsupported schema failure is
167
+ * associated with an OpenRouter response.
168
+ *
169
+ * @category configuration
170
+ * @since 4.0.0
171
+ */
66
172
  interface UnsupportedSchemaErrorMetadata {
173
+ /**
174
+ * OpenRouter-specific details for the unsupported schema failure.
175
+ */
67
176
  readonly openrouter?: OpenRouterErrorMetadata | null;
68
177
  }
178
+ /**
179
+ * OpenRouter metadata attached to `UnknownError` values.
180
+ *
181
+ * Preserves provider error details for OpenRouter failures that do not map
182
+ * cleanly to a more specific AI error category.
183
+ *
184
+ * @category configuration
185
+ * @since 4.0.0
186
+ */
69
187
  interface UnknownErrorMetadata {
188
+ /**
189
+ * OpenRouter-specific details for the unclassified provider failure.
190
+ */
70
191
  readonly openrouter?: OpenRouterErrorMetadata | null;
71
192
  }
72
193
  }
@@ -1 +1 @@
1
- {"version":3,"file":"OpenRouterError.d.ts","sourceRoot":"","sources":["../src/OpenRouterError.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IAC1C;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACjC;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;CAClC,CAAA;AAED;;;;;GAKG;AACH,MAAM,MAAM,2BAA2B,GAAG,uBAAuB,GAAG;IAClE,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACjC,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAA;IACrC,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;CACpC,CAAA;AAED,OAAO,QAAQ,4BAA4B,CAAC;IAC1C,UAAiB,sBAAsB;QACrC,QAAQ,CAAC,UAAU,CAAC,EAAE,2BAA2B,GAAG,IAAI,CAAA;KACzD;IAED,UAAiB,2BAA2B;QAC1C,QAAQ,CAAC,UAAU,CAAC,EAAE,uBAAuB,GAAG,IAAI,CAAA;KACrD;IAED,UAAiB,2BAA2B;QAC1C,QAAQ,CAAC,UAAU,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AAuB,GAAG,IAAI,CAAA;KACrD;IAED;;;;;;;;OAQG;IACH,UAAiB,oBAAoB;QACnC;;WAEG;QACH,QAAQ,CAAC,UAAU,CAAC,EAAE,uBAAuB,GAAG,IAAI,CAAA;KACrD;CACF"}
@@ -4,7 +4,7 @@
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
  export {};
10
10
  //# sourceMappingURL=OpenRouterError.js.map