@effect/ai-openrouter 4.0.0-beta.7 → 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.
- package/dist/Generated.d.ts +171 -92
- package/dist/Generated.d.ts.map +1 -1
- package/dist/Generated.js +60 -31
- package/dist/Generated.js.map +1 -1
- package/dist/OpenRouterClient.d.ts +101 -17
- package/dist/OpenRouterClient.d.ts.map +1 -1
- package/dist/OpenRouterClient.js +62 -11
- package/dist/OpenRouterClient.js.map +1 -1
- package/dist/OpenRouterConfig.d.ts +121 -10
- package/dist/OpenRouterConfig.d.ts.map +1 -1
- package/dist/OpenRouterConfig.js +71 -7
- package/dist/OpenRouterConfig.js.map +1 -1
- package/dist/OpenRouterError.d.ts +166 -35
- package/dist/OpenRouterError.d.ts.map +1 -1
- package/dist/OpenRouterError.js +1 -1
- package/dist/OpenRouterLanguageModel.d.ts +368 -20
- package/dist/OpenRouterLanguageModel.d.ts.map +1 -1
- package/dist/OpenRouterLanguageModel.js +344 -241
- package/dist/OpenRouterLanguageModel.js.map +1 -1
- package/dist/index.d.ts +6 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -11
- package/dist/index.js.map +1 -1
- package/dist/internal/errors.js +4 -4
- package/dist/internal/errors.js.map +1 -1
- package/dist/internal/utilities.js +0 -1
- package/dist/internal/utilities.js.map +1 -1
- package/package.json +3 -3
- package/src/Generated.ts +123 -53
- package/src/OpenRouterClient.ts +102 -18
- package/src/OpenRouterConfig.ts +166 -13
- package/src/OpenRouterError.ts +168 -35
- package/src/OpenRouterLanguageModel.ts +644 -246
- package/src/index.ts +6 -11
- package/src/internal/errors.ts +6 -4
- package/src/internal/utilities.ts +0 -1
|
@@ -1,11 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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";
|
|
27
|
+
import * as Context from "effect/Context";
|
|
5
28
|
import * as Effect from "effect/Effect";
|
|
6
29
|
import * as Layer from "effect/Layer";
|
|
7
30
|
import type * as Redacted from "effect/Redacted";
|
|
8
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
9
31
|
import * as Stream from "effect/Stream";
|
|
10
32
|
import type * as AiError from "effect/unstable/ai/AiError";
|
|
11
33
|
import * as HttpClient from "effect/unstable/http/HttpClient";
|
|
@@ -14,11 +36,13 @@ import * as Generated from "./Generated.ts";
|
|
|
14
36
|
/**
|
|
15
37
|
* The OpenRouter client service interface.
|
|
16
38
|
*
|
|
39
|
+
* **Details**
|
|
40
|
+
*
|
|
17
41
|
* Provides methods for interacting with OpenRouter's Chat Completions API,
|
|
18
42
|
* including both synchronous and streaming message creation.
|
|
19
43
|
*
|
|
20
|
-
* @since 1.0.0
|
|
21
44
|
* @category models
|
|
45
|
+
* @since 4.0.0
|
|
22
46
|
*/
|
|
23
47
|
export interface Service {
|
|
24
48
|
readonly client: Generated.OpenRouterClient;
|
|
@@ -32,24 +56,40 @@ export interface Service {
|
|
|
32
56
|
], AiError.AiError>;
|
|
33
57
|
}
|
|
34
58
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
59
|
+
* Decoded `data` payload from an OpenRouter chat completion streaming chunk.
|
|
60
|
+
*
|
|
61
|
+
* **Details**
|
|
62
|
+
*
|
|
63
|
+
* The payload contains streamed choices, model metadata, optional usage, and may
|
|
64
|
+
* include an OpenRouter error object for a streamed response.
|
|
65
|
+
*
|
|
66
|
+
* @category models
|
|
67
|
+
* @since 4.0.0
|
|
37
68
|
*/
|
|
38
69
|
export type ChatStreamingResponseChunkData = typeof Generated.ChatStreamingResponseChunk.fields.data.Type;
|
|
39
|
-
declare const OpenRouterClient_base:
|
|
70
|
+
declare const OpenRouterClient_base: Context.ServiceClass<OpenRouterClient, "@effect/ai-openrouter/OpenRouterClient", Service>;
|
|
40
71
|
/**
|
|
41
72
|
* Service identifier for the OpenRouter client.
|
|
42
73
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
74
|
+
* **When to use**
|
|
75
|
+
*
|
|
76
|
+
* Use when accessing or providing the OpenRouter client service through
|
|
77
|
+
* Effect's context.
|
|
78
|
+
*
|
|
79
|
+
* @see {@link make} for constructing an OpenRouter client effectfully
|
|
80
|
+
* @see {@link layer} for providing a client from explicit options
|
|
81
|
+
* @see {@link layerConfig} for providing a client from `Config`
|
|
82
|
+
*
|
|
83
|
+
* @category services
|
|
84
|
+
* @since 4.0.0
|
|
45
85
|
*/
|
|
46
86
|
export declare class OpenRouterClient extends OpenRouterClient_base {
|
|
47
87
|
}
|
|
48
88
|
/**
|
|
49
89
|
* Configuration options for creating an OpenRouter client.
|
|
50
90
|
*
|
|
51
|
-
* @since 1.0.0
|
|
52
91
|
* @category models
|
|
92
|
+
* @since 4.0.0
|
|
53
93
|
*/
|
|
54
94
|
export type Options = {
|
|
55
95
|
readonly apiKey?: Redacted.Redacted<string> | undefined;
|
|
@@ -65,36 +105,80 @@ export type Options = {
|
|
|
65
105
|
/**
|
|
66
106
|
* Optional transformer for the underlying HTTP client.
|
|
67
107
|
*
|
|
68
|
-
*
|
|
108
|
+
* **When to use**
|
|
109
|
+
*
|
|
110
|
+
* Use to add middleware, logging, or custom request/response handling.
|
|
69
111
|
*/
|
|
70
112
|
readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined;
|
|
71
113
|
};
|
|
72
114
|
/**
|
|
73
|
-
* Creates an OpenRouter client service
|
|
115
|
+
* Creates an OpenRouter client service from explicit options.
|
|
116
|
+
*
|
|
117
|
+
* **When to use**
|
|
118
|
+
*
|
|
119
|
+
* Use to construct the OpenRouter client service inside an effect when you need
|
|
120
|
+
* the service value directly.
|
|
121
|
+
*
|
|
122
|
+
* **Details**
|
|
123
|
+
*
|
|
124
|
+
* The returned service uses the current `HttpClient`, prepends `apiUrl` or
|
|
125
|
+
* `https://openrouter.ai/api/v1`, adds the bearer token and optional
|
|
126
|
+
* `HTTP-Referer` and `X-Title` headers, accepts JSON responses, and applies
|
|
127
|
+
* `transformClient` when provided.
|
|
128
|
+
*
|
|
129
|
+
* **Gotchas**
|
|
130
|
+
*
|
|
131
|
+
* Scoped `OpenRouterConfig.withClientTransform` applies to generated client
|
|
132
|
+
* request methods. Streaming chat completion requests are sent directly by this
|
|
133
|
+
* module and do not read that scoped transform.
|
|
134
|
+
*
|
|
135
|
+
* @see {@link layer} for providing this client from explicit options
|
|
136
|
+
* @see {@link layerConfig} for loading client settings from `Config`
|
|
74
137
|
*
|
|
75
|
-
* @since 1.0.0
|
|
76
138
|
* @category constructors
|
|
139
|
+
* @since 4.0.0
|
|
77
140
|
*/
|
|
78
141
|
export declare const make: (options: Options) => Effect.Effect<Service, never, HttpClient.HttpClient>;
|
|
79
142
|
/**
|
|
80
143
|
* Creates a layer for the OpenRouter client with the given options.
|
|
81
144
|
*
|
|
82
|
-
*
|
|
145
|
+
* **When to use**
|
|
146
|
+
*
|
|
147
|
+
* Use when you already have the OpenRouter client options in code and want to
|
|
148
|
+
* provide `OpenRouterClient` as a layer.
|
|
149
|
+
*
|
|
150
|
+
* @see {@link make} for constructing the client service effectfully
|
|
151
|
+
* @see {@link layerConfig} for loading client settings from `Config`
|
|
152
|
+
*
|
|
83
153
|
* @category layers
|
|
154
|
+
* @since 4.0.0
|
|
84
155
|
*/
|
|
85
156
|
export declare const layer: (options: Options) => Layer.Layer<OpenRouterClient, never, HttpClient.HttpClient>;
|
|
86
157
|
/**
|
|
87
|
-
* Creates a layer for the OpenRouter client
|
|
88
|
-
*
|
|
158
|
+
* Creates a layer for the OpenRouter client from provided `Config` values.
|
|
159
|
+
*
|
|
160
|
+
* **When to use**
|
|
161
|
+
*
|
|
162
|
+
* Use when OpenRouter client settings should be read from Effect `Config`
|
|
163
|
+
* values while providing `OpenRouterClient` as a layer.
|
|
164
|
+
*
|
|
165
|
+
* **Details**
|
|
166
|
+
*
|
|
167
|
+
* Only config values supplied in `options` are loaded. Omitted fields are
|
|
168
|
+
* passed to `make` as `undefined`, and `transformClient` is forwarded as a
|
|
169
|
+
* plain option.
|
|
170
|
+
*
|
|
171
|
+
* @see {@link make} for constructing the client service effectfully
|
|
172
|
+
* @see {@link layer} for providing the client from already-resolved options
|
|
89
173
|
*
|
|
90
|
-
* @since 1.0.0
|
|
91
174
|
* @category layers
|
|
175
|
+
* @since 4.0.0
|
|
92
176
|
*/
|
|
93
177
|
export declare const layerConfig: (options?: {
|
|
94
178
|
/**
|
|
95
179
|
* The config value to load for the API key.
|
|
96
180
|
*/
|
|
97
|
-
readonly apiKey?: Config.Config<Redacted.Redacted<string
|
|
181
|
+
readonly apiKey?: Config.Config<Redacted.Redacted<string> | undefined> | undefined;
|
|
98
182
|
/**
|
|
99
183
|
* The config value to load for the API URL.
|
|
100
184
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenRouterClient.d.ts","sourceRoot":"","sources":["../src/OpenRouterClient.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"OpenRouterClient.d.ts","sourceRoot":"","sources":["../src/OpenRouterClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,KAAK,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAEhD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,OAAO,MAAM,4BAA4B,CAAA;AAG1D,OAAO,KAAK,UAAU,MAAM,iCAAiC,CAAA;AAE7D,OAAO,KAAK,KAAK,kBAAkB,MAAM,yCAAyC,CAAA;AAClF,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAQ3C;;;;;;;;;;GAUG;AACH,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC,gBAAgB,CAAA;IAE3C,QAAQ,CAAC,oBAAoB,EAAE,CAC7B,OAAO,EAAE,OAAO,SAAS,CAAC,oBAAoB,CAAC,OAAO,KACnD,MAAM,CAAC,MAAM,CAChB;QAAC,IAAI,EAAE,OAAO,SAAS,CAAC,4BAA4B,CAAC,IAAI;QAAE,QAAQ,EAAE,kBAAkB,CAAC,kBAAkB;KAAC,EAC3G,OAAO,CAAC,OAAO,CAChB,CAAA;IAED,QAAQ,CAAC,0BAA0B,EAAE,CACnC,OAAO,EAAE,IAAI,CAAC,OAAO,SAAS,CAAC,oBAAoB,CAAC,OAAO,EAAE,QAAQ,GAAG,gBAAgB,CAAC,KACtF,MAAM,CAAC,MAAM,CAChB;QACE,QAAQ,E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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"}
|
package/dist/OpenRouterClient.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import * as Context from "effect/Context";
|
|
1
2
|
import * as Effect from "effect/Effect";
|
|
2
3
|
import { identity } from "effect/Function";
|
|
3
4
|
import * as Layer from "effect/Layer";
|
|
4
5
|
import * as Predicate from "effect/Predicate";
|
|
5
6
|
import * as Schema from "effect/Schema";
|
|
6
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
7
7
|
import * as Stream from "effect/Stream";
|
|
8
8
|
import * as Sse from "effect/unstable/encoding/Sse";
|
|
9
9
|
import * as HttpBody from "effect/unstable/http/HttpBody";
|
|
@@ -18,22 +18,52 @@ import { OpenRouterConfig } from "./OpenRouterConfig.js";
|
|
|
18
18
|
/**
|
|
19
19
|
* Service identifier for the OpenRouter client.
|
|
20
20
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
21
|
+
* **When to use**
|
|
22
|
+
*
|
|
23
|
+
* Use when accessing or providing the OpenRouter client service through
|
|
24
|
+
* Effect's context.
|
|
25
|
+
*
|
|
26
|
+
* @see {@link make} for constructing an OpenRouter client effectfully
|
|
27
|
+
* @see {@link layer} for providing a client from explicit options
|
|
28
|
+
* @see {@link layerConfig} for providing a client from `Config`
|
|
29
|
+
*
|
|
30
|
+
* @category services
|
|
31
|
+
* @since 4.0.0
|
|
23
32
|
*/
|
|
24
|
-
export class OpenRouterClient extends /*#__PURE__*/
|
|
33
|
+
export class OpenRouterClient extends /*#__PURE__*/Context.Service()("@effect/ai-openrouter/OpenRouterClient") {}
|
|
25
34
|
// =============================================================================
|
|
26
35
|
// Constructor
|
|
27
36
|
// =============================================================================
|
|
28
37
|
/**
|
|
29
|
-
* Creates an OpenRouter client service
|
|
38
|
+
* Creates an OpenRouter client service from explicit options.
|
|
39
|
+
*
|
|
40
|
+
* **When to use**
|
|
41
|
+
*
|
|
42
|
+
* Use to construct the OpenRouter client service inside an effect when you need
|
|
43
|
+
* the service value directly.
|
|
44
|
+
*
|
|
45
|
+
* **Details**
|
|
46
|
+
*
|
|
47
|
+
* The returned service uses the current `HttpClient`, prepends `apiUrl` or
|
|
48
|
+
* `https://openrouter.ai/api/v1`, adds the bearer token and optional
|
|
49
|
+
* `HTTP-Referer` and `X-Title` headers, accepts JSON responses, and applies
|
|
50
|
+
* `transformClient` when provided.
|
|
51
|
+
*
|
|
52
|
+
* **Gotchas**
|
|
53
|
+
*
|
|
54
|
+
* Scoped `OpenRouterConfig.withClientTransform` applies to generated client
|
|
55
|
+
* request methods. Streaming chat completion requests are sent directly by this
|
|
56
|
+
* module and do not read that scoped transform.
|
|
57
|
+
*
|
|
58
|
+
* @see {@link layer} for providing this client from explicit options
|
|
59
|
+
* @see {@link layerConfig} for loading client settings from `Config`
|
|
30
60
|
*
|
|
31
|
-
* @since 1.0.0
|
|
32
61
|
* @category constructors
|
|
62
|
+
* @since 4.0.0
|
|
33
63
|
*/
|
|
34
64
|
export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
|
|
35
65
|
const baseClient = yield* HttpClient.HttpClient;
|
|
36
|
-
const httpClient = baseClient.pipe(HttpClient.mapRequest(request => request.pipe(HttpClientRequest.prependUrl(options.apiUrl ?? "https://openrouter.ai/api/v1"), options.apiKey ? HttpClientRequest.bearerToken(options.apiKey) : identity, options.siteReferrer ? HttpClientRequest.setHeader("HTTP-
|
|
66
|
+
const httpClient = baseClient.pipe(HttpClient.mapRequest(request => request.pipe(HttpClientRequest.prependUrl(options.apiUrl ?? "https://openrouter.ai/api/v1"), options.apiKey ? HttpClientRequest.bearerToken(options.apiKey) : identity, options.siteReferrer ? HttpClientRequest.setHeader("HTTP-Referer", options.siteReferrer) : identity, options.siteTitle ? HttpClientRequest.setHeader("X-Title", options.siteTitle) : identity, HttpClientRequest.acceptJson)), options.transformClient ?? identity);
|
|
37
67
|
const httpClientOk = HttpClient.filterStatusOk(httpClient);
|
|
38
68
|
const client = Generated.make(httpClient, {
|
|
39
69
|
transformClient: Effect.fnUntraced(function* (client) {
|
|
@@ -87,16 +117,37 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
|
|
|
87
117
|
/**
|
|
88
118
|
* Creates a layer for the OpenRouter client with the given options.
|
|
89
119
|
*
|
|
90
|
-
*
|
|
120
|
+
* **When to use**
|
|
121
|
+
*
|
|
122
|
+
* Use when you already have the OpenRouter client options in code and want to
|
|
123
|
+
* provide `OpenRouterClient` as a layer.
|
|
124
|
+
*
|
|
125
|
+
* @see {@link make} for constructing the client service effectfully
|
|
126
|
+
* @see {@link layerConfig} for loading client settings from `Config`
|
|
127
|
+
*
|
|
91
128
|
* @category layers
|
|
129
|
+
* @since 4.0.0
|
|
92
130
|
*/
|
|
93
131
|
export const layer = options => Layer.effect(OpenRouterClient, make(options));
|
|
94
132
|
/**
|
|
95
|
-
* Creates a layer for the OpenRouter client
|
|
96
|
-
*
|
|
133
|
+
* Creates a layer for the OpenRouter client from provided `Config` values.
|
|
134
|
+
*
|
|
135
|
+
* **When to use**
|
|
136
|
+
*
|
|
137
|
+
* Use when OpenRouter client settings should be read from Effect `Config`
|
|
138
|
+
* values while providing `OpenRouterClient` as a layer.
|
|
139
|
+
*
|
|
140
|
+
* **Details**
|
|
141
|
+
*
|
|
142
|
+
* Only config values supplied in `options` are loaded. Omitted fields are
|
|
143
|
+
* passed to `make` as `undefined`, and `transformClient` is forwarded as a
|
|
144
|
+
* plain option.
|
|
145
|
+
*
|
|
146
|
+
* @see {@link make} for constructing the client service effectfully
|
|
147
|
+
* @see {@link layer} for providing the client from already-resolved options
|
|
97
148
|
*
|
|
98
|
-
* @since 1.0.0
|
|
99
149
|
* @category layers
|
|
150
|
+
* @since 4.0.0
|
|
100
151
|
*/
|
|
101
152
|
export const layerConfig = options => Layer.effect(OpenRouterClient, Effect.gen(function* () {
|
|
102
153
|
const apiKey = Predicate.isNotUndefined(options?.apiKey) ? yield* options.apiKey : undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenRouterClient.js","names":["Effect","identity","Layer","Predicate","Schema","
|
|
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;AAmDxD;AACA;AACA;AAEA;;;;;;;;;;;;;;;AAeA,OAAM,MAAOC,gBAAiB,sBAAQd,OAAO,CAACe,OAAO,EAGlD,CAAC,wCAAwC,CAAC;AAqC7C;AACA;AACA;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,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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xB,SAAS,CAACkC,cAAc,CAACpB,OAAO,EAAEU,YAAY,CAAC,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,156 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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.
|
|
6
|
+
*
|
|
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
|
|
22
|
+
*
|
|
23
|
+
* **Gotchas**
|
|
24
|
+
*
|
|
25
|
+
* - Each {@link withClientTransform} call replaces the current scoped
|
|
26
|
+
* transform for the supplied effect; compose transforms manually when both
|
|
27
|
+
* behaviors should apply
|
|
28
|
+
* - The transform receives and returns an `HttpClient`, so it should preserve
|
|
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
|
|
32
|
+
*
|
|
33
|
+
* @since 4.0.0
|
|
3
34
|
*/
|
|
35
|
+
import * as Context from "effect/Context";
|
|
4
36
|
import * as Effect from "effect/Effect";
|
|
5
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
6
37
|
import type { HttpClient } from "effect/unstable/http/HttpClient";
|
|
7
|
-
declare const OpenRouterConfig_base:
|
|
38
|
+
declare const OpenRouterConfig_base: Context.ServiceClass<OpenRouterConfig, "@effect/ai-openrouter/OpenRouterConfig", OpenRouterConfig.Service>;
|
|
8
39
|
/**
|
|
9
|
-
*
|
|
40
|
+
* Context service carrying scoped OpenRouter provider configuration for client
|
|
41
|
+
* operations.
|
|
42
|
+
*
|
|
43
|
+
* **When to use**
|
|
44
|
+
*
|
|
45
|
+
* Use as the context service tag when manually providing or reading scoped
|
|
46
|
+
* OpenRouter provider configuration in an Effect context.
|
|
47
|
+
*
|
|
48
|
+
* @see {@link withClientTransform} for scoping an HTTP client transformation
|
|
49
|
+
*
|
|
10
50
|
* @category services
|
|
51
|
+
* @since 4.0.0
|
|
11
52
|
*/
|
|
12
53
|
export declare class OpenRouterConfig extends OpenRouterConfig_base {
|
|
13
54
|
/**
|
|
14
|
-
*
|
|
55
|
+
* Gets the configured OpenRouter service from the current context when present.
|
|
56
|
+
*
|
|
57
|
+
* @since 4.0.0
|
|
15
58
|
*/
|
|
16
59
|
static readonly getOrUndefined: Effect.Effect<typeof OpenRouterConfig.Service | undefined>;
|
|
17
60
|
}
|
|
18
61
|
/**
|
|
19
|
-
*
|
|
62
|
+
* Types associated with the `OpenRouterConfig` context service.
|
|
63
|
+
*
|
|
64
|
+
* @since 4.0.0
|
|
20
65
|
*/
|
|
21
66
|
export declare namespace OpenRouterConfig {
|
|
22
67
|
/**
|
|
23
|
-
*
|
|
68
|
+
* Configuration values read by OpenRouter provider operations when resolving
|
|
69
|
+
* the generated HTTP client.
|
|
70
|
+
*
|
|
24
71
|
* @category models
|
|
72
|
+
* @since 4.0.0
|
|
25
73
|
*/
|
|
26
74
|
interface Service {
|
|
27
75
|
readonly transformClient?: ((client: HttpClient) => HttpClient) | undefined;
|
|
28
76
|
}
|
|
29
77
|
}
|
|
30
78
|
/**
|
|
31
|
-
*
|
|
79
|
+
* Provides a scoped transform for the OpenRouter HTTP client used by provider
|
|
80
|
+
* operations.
|
|
81
|
+
*
|
|
82
|
+
* **When to use**
|
|
83
|
+
*
|
|
84
|
+
* Use when a single effect or workflow needs temporary OpenRouter HTTP client
|
|
85
|
+
* customization without rebuilding the client layer.
|
|
86
|
+
*
|
|
87
|
+
* **Details**
|
|
88
|
+
*
|
|
89
|
+
* Supports both data-first and data-last forms. The transform is stored in the
|
|
90
|
+
* scoped `OpenRouterConfig` service and read by generated OpenRouter request
|
|
91
|
+
* operations while running the supplied effect.
|
|
92
|
+
*
|
|
93
|
+
* **Gotchas**
|
|
94
|
+
*
|
|
95
|
+
* If a transform is already present in the scoped config, this helper replaces
|
|
96
|
+
* it. Compose transforms manually when both should apply. Streaming chat
|
|
97
|
+
* completion requests are sent directly by `OpenRouterClient.make` and do not
|
|
98
|
+
* read this scoped transform.
|
|
99
|
+
*
|
|
32
100
|
* @category configuration
|
|
101
|
+
* @since 4.0.0
|
|
33
102
|
*/
|
|
34
103
|
export declare const withClientTransform: {
|
|
35
104
|
/**
|
|
36
|
-
*
|
|
105
|
+
* Provides a scoped transform for the OpenRouter HTTP client used by provider
|
|
106
|
+
* operations.
|
|
107
|
+
*
|
|
108
|
+
* **When to use**
|
|
109
|
+
*
|
|
110
|
+
* Use when a single effect or workflow needs temporary OpenRouter HTTP client
|
|
111
|
+
* customization without rebuilding the client layer.
|
|
112
|
+
*
|
|
113
|
+
* **Details**
|
|
114
|
+
*
|
|
115
|
+
* Supports both data-first and data-last forms. The transform is stored in the
|
|
116
|
+
* scoped `OpenRouterConfig` service and read by generated OpenRouter request
|
|
117
|
+
* operations while running the supplied effect.
|
|
118
|
+
*
|
|
119
|
+
* **Gotchas**
|
|
120
|
+
*
|
|
121
|
+
* If a transform is already present in the scoped config, this helper replaces
|
|
122
|
+
* it. Compose transforms manually when both should apply. Streaming chat
|
|
123
|
+
* completion requests are sent directly by `OpenRouterClient.make` and do not
|
|
124
|
+
* read this scoped transform.
|
|
125
|
+
*
|
|
37
126
|
* @category configuration
|
|
127
|
+
* @since 4.0.0
|
|
38
128
|
*/
|
|
39
129
|
(transform: (client: HttpClient) => HttpClient): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
40
130
|
/**
|
|
41
|
-
*
|
|
131
|
+
* Provides a scoped transform for the OpenRouter HTTP client used by provider
|
|
132
|
+
* operations.
|
|
133
|
+
*
|
|
134
|
+
* **When to use**
|
|
135
|
+
*
|
|
136
|
+
* Use when a single effect or workflow needs temporary OpenRouter HTTP client
|
|
137
|
+
* customization without rebuilding the client layer.
|
|
138
|
+
*
|
|
139
|
+
* **Details**
|
|
140
|
+
*
|
|
141
|
+
* Supports both data-first and data-last forms. The transform is stored in the
|
|
142
|
+
* scoped `OpenRouterConfig` service and read by generated OpenRouter request
|
|
143
|
+
* operations while running the supplied effect.
|
|
144
|
+
*
|
|
145
|
+
* **Gotchas**
|
|
146
|
+
*
|
|
147
|
+
* If a transform is already present in the scoped config, this helper replaces
|
|
148
|
+
* it. Compose transforms manually when both should apply. Streaming chat
|
|
149
|
+
* completion requests are sent directly by `OpenRouterClient.make` and do not
|
|
150
|
+
* read this scoped transform.
|
|
151
|
+
*
|
|
42
152
|
* @category configuration
|
|
153
|
+
* @since 4.0.0
|
|
43
154
|
*/
|
|
44
155
|
<A, E, R>(self: Effect.Effect<A, E, R>, transform: (client: HttpClient) => HttpClient): Effect.Effect<A, E, R>;
|
|
45
156
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenRouterConfig.d.ts","sourceRoot":"","sources":["../src/OpenRouterConfig.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"OpenRouterConfig.d.ts","sourceRoot":"","sources":["../src/OpenRouterConfig.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;;AAEjE;;;;;;;;;;;;;GAaG;AACH,qBAAa,gBAAiB,SAAQ,qBAGO;IAC3C;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,gBAAgB,CAAC,OAAO,GAAG,SAAS,CAAC,CAGzF;CACF;AAED;;;;GAIG;AACH,MAAM,CAAC,OAAO,WAAW,gBAAgB,CAAC;IACxC;;;;;;OAMG;IACH,UAAiB,OAAO;QACtB,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,UAAU,KAAK,UAAU,CAAC,GAAG,SAAS,CAAA;KAC5E;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,mBAAmB,EAAE;IAChC;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;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;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;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,EAAE,UAAU,KAAK,UAAU,GAC5C,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;CAgE1B,CAAA"}
|
package/dist/OpenRouterConfig.js
CHANGED
|
@@ -1,22 +1,86 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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.
|
|
6
|
+
*
|
|
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
|
|
22
|
+
*
|
|
23
|
+
* **Gotchas**
|
|
24
|
+
*
|
|
25
|
+
* - Each {@link withClientTransform} call replaces the current scoped
|
|
26
|
+
* transform for the supplied effect; compose transforms manually when both
|
|
27
|
+
* behaviors should apply
|
|
28
|
+
* - The transform receives and returns an `HttpClient`, so it should preserve
|
|
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
|
|
32
|
+
*
|
|
33
|
+
* @since 4.0.0
|
|
3
34
|
*/
|
|
35
|
+
import * as Context from "effect/Context";
|
|
4
36
|
import * as Effect from "effect/Effect";
|
|
5
37
|
import { dual } from "effect/Function";
|
|
6
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
7
38
|
/**
|
|
8
|
-
*
|
|
39
|
+
* Context service carrying scoped OpenRouter provider configuration for client
|
|
40
|
+
* operations.
|
|
41
|
+
*
|
|
42
|
+
* **When to use**
|
|
43
|
+
*
|
|
44
|
+
* Use as the context service tag when manually providing or reading scoped
|
|
45
|
+
* OpenRouter provider configuration in an Effect context.
|
|
46
|
+
*
|
|
47
|
+
* @see {@link withClientTransform} for scoping an HTTP client transformation
|
|
48
|
+
*
|
|
9
49
|
* @category services
|
|
50
|
+
* @since 4.0.0
|
|
10
51
|
*/
|
|
11
|
-
export class OpenRouterConfig extends /*#__PURE__*/
|
|
52
|
+
export class OpenRouterConfig extends /*#__PURE__*/Context.Service()("@effect/ai-openrouter/OpenRouterConfig") {
|
|
12
53
|
/**
|
|
13
|
-
*
|
|
54
|
+
* Gets the configured OpenRouter service from the current context when present.
|
|
55
|
+
*
|
|
56
|
+
* @since 4.0.0
|
|
14
57
|
*/
|
|
15
|
-
static getOrUndefined = /*#__PURE__*/Effect.map(/*#__PURE__*/Effect.
|
|
58
|
+
static getOrUndefined = /*#__PURE__*/Effect.map(/*#__PURE__*/Effect.context(), services => services.mapUnsafe.get(OpenRouterConfig.key));
|
|
16
59
|
}
|
|
17
60
|
/**
|
|
18
|
-
*
|
|
61
|
+
* Provides a scoped transform for the OpenRouter HTTP client used by provider
|
|
62
|
+
* operations.
|
|
63
|
+
*
|
|
64
|
+
* **When to use**
|
|
65
|
+
*
|
|
66
|
+
* Use when a single effect or workflow needs temporary OpenRouter HTTP client
|
|
67
|
+
* customization without rebuilding the client layer.
|
|
68
|
+
*
|
|
69
|
+
* **Details**
|
|
70
|
+
*
|
|
71
|
+
* Supports both data-first and data-last forms. The transform is stored in the
|
|
72
|
+
* scoped `OpenRouterConfig` service and read by generated OpenRouter request
|
|
73
|
+
* operations while running the supplied effect.
|
|
74
|
+
*
|
|
75
|
+
* **Gotchas**
|
|
76
|
+
*
|
|
77
|
+
* If a transform is already present in the scoped config, this helper replaces
|
|
78
|
+
* it. Compose transforms manually when both should apply. Streaming chat
|
|
79
|
+
* completion requests are sent directly by `OpenRouterClient.make` and do not
|
|
80
|
+
* read this scoped transform.
|
|
81
|
+
*
|
|
19
82
|
* @category configuration
|
|
83
|
+
* @since 4.0.0
|
|
20
84
|
*/
|
|
21
85
|
export const withClientTransform = /*#__PURE__*/dual(2, (self, transformClient) => Effect.flatMap(OpenRouterConfig.getOrUndefined, config => Effect.provideService(self, OpenRouterConfig, {
|
|
22
86
|
...config,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenRouterConfig.js","names":["
|
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,OAAO,KAAKA,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,SAASC,IAAI,QAAQ,iBAAiB;AAGtC;;;;;;;;;;;;;;AAcA,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;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,OAAO,MAAMC,mBAAmB,gBAwD5BV,IAAI,CAyDN,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":[]}
|