@effect/ai-openrouter 4.0.0-beta.9 → 4.0.0-beta.90
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 +1 -1
- package/dist/Generated.js +1 -1
- package/dist/Generated.js.map +1 -1
- package/dist/OpenRouterClient.d.ts +86 -20
- package/dist/OpenRouterClient.d.ts.map +1 -1
- package/dist/OpenRouterClient.js +62 -12
- package/dist/OpenRouterClient.js.map +1 -1
- package/dist/OpenRouterConfig.d.ts +95 -10
- package/dist/OpenRouterConfig.d.ts.map +1 -1
- package/dist/OpenRouterConfig.js +45 -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 +364 -23
- package/dist/OpenRouterLanguageModel.d.ts.map +1 -1
- package/dist/OpenRouterLanguageModel.js +148 -14
- 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 +4 -4
- package/src/OpenRouterClient.ts +87 -21
- package/src/OpenRouterConfig.ts +140 -13
- package/src/OpenRouterError.ts +168 -35
- package/src/OpenRouterLanguageModel.ts +463 -24
- package/src/index.ts +6 -11
- package/src/internal/errors.ts +6 -4
- package/src/internal/utilities.ts +0 -1
|
@@ -1,11 +1,16 @@
|
|
|
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, 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 * as Layer from "effect/Layer";
|
|
7
13
|
import type * as Redacted from "effect/Redacted";
|
|
8
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
9
14
|
import * as Stream from "effect/Stream";
|
|
10
15
|
import type * as AiError from "effect/unstable/ai/AiError";
|
|
11
16
|
import * as HttpClient from "effect/unstable/http/HttpClient";
|
|
@@ -14,11 +19,13 @@ import * as Generated from "./Generated.ts";
|
|
|
14
19
|
/**
|
|
15
20
|
* The OpenRouter client service interface.
|
|
16
21
|
*
|
|
22
|
+
* **Details**
|
|
23
|
+
*
|
|
17
24
|
* Provides methods for interacting with OpenRouter's Chat Completions API,
|
|
18
25
|
* including both synchronous and streaming message creation.
|
|
19
26
|
*
|
|
20
|
-
* @since 1.0.0
|
|
21
27
|
* @category models
|
|
28
|
+
* @since 4.0.0
|
|
22
29
|
*/
|
|
23
30
|
export interface Service {
|
|
24
31
|
readonly client: Generated.OpenRouterClient;
|
|
@@ -32,24 +39,40 @@ export interface Service {
|
|
|
32
39
|
], AiError.AiError>;
|
|
33
40
|
}
|
|
34
41
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
42
|
+
* Decoded `data` payload from an OpenRouter chat completion streaming chunk.
|
|
43
|
+
*
|
|
44
|
+
* **Details**
|
|
45
|
+
*
|
|
46
|
+
* The payload contains streamed choices, model metadata, optional usage, and may
|
|
47
|
+
* include an OpenRouter error object for a streamed response.
|
|
48
|
+
*
|
|
49
|
+
* @category models
|
|
50
|
+
* @since 4.0.0
|
|
37
51
|
*/
|
|
38
52
|
export type ChatStreamingResponseChunkData = typeof Generated.ChatStreamingResponseChunk.fields.data.Type;
|
|
39
|
-
declare const OpenRouterClient_base:
|
|
53
|
+
declare const OpenRouterClient_base: Context.ServiceClass<OpenRouterClient, "@effect/ai-openrouter/OpenRouterClient", Service>;
|
|
40
54
|
/**
|
|
41
|
-
* Service
|
|
55
|
+
* Service tag for the OpenRouter client.
|
|
56
|
+
*
|
|
57
|
+
* **When to use**
|
|
42
58
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
59
|
+
* Use when accessing or providing the OpenRouter client service through
|
|
60
|
+
* Effect's context.
|
|
61
|
+
*
|
|
62
|
+
* @see {@link make} for constructing an OpenRouter client effectfully
|
|
63
|
+
* @see {@link layer} for providing a client from explicit options
|
|
64
|
+
* @see {@link layerConfig} for providing a client from `Config`
|
|
65
|
+
*
|
|
66
|
+
* @category services
|
|
67
|
+
* @since 4.0.0
|
|
45
68
|
*/
|
|
46
69
|
export declare class OpenRouterClient extends OpenRouterClient_base {
|
|
47
70
|
}
|
|
48
71
|
/**
|
|
49
|
-
* Configuration
|
|
72
|
+
* Configuration for creating an OpenRouter client.
|
|
50
73
|
*
|
|
51
|
-
* @
|
|
52
|
-
* @
|
|
74
|
+
* @category options
|
|
75
|
+
* @since 4.0.0
|
|
53
76
|
*/
|
|
54
77
|
export type Options = {
|
|
55
78
|
readonly apiKey?: Redacted.Redacted<string> | undefined;
|
|
@@ -65,36 +88,79 @@ export type Options = {
|
|
|
65
88
|
/**
|
|
66
89
|
* Optional transformer for the underlying HTTP client.
|
|
67
90
|
*
|
|
68
|
-
*
|
|
91
|
+
* **When to use**
|
|
92
|
+
*
|
|
93
|
+
* Use to add middleware, logging, or custom request/response handling.
|
|
69
94
|
*/
|
|
70
95
|
readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined;
|
|
71
96
|
};
|
|
72
97
|
/**
|
|
73
|
-
* Creates an OpenRouter client service
|
|
98
|
+
* Creates an OpenRouter client service from explicit options.
|
|
99
|
+
*
|
|
100
|
+
* **When to use**
|
|
101
|
+
*
|
|
102
|
+
* Use when you need the OpenRouter client service value inside an effect.
|
|
103
|
+
*
|
|
104
|
+
* **Details**
|
|
105
|
+
*
|
|
106
|
+
* The returned service uses the current `HttpClient`, prepends `apiUrl` or
|
|
107
|
+
* `https://openrouter.ai/api/v1`, adds the bearer token and optional
|
|
108
|
+
* `HTTP-Referer` and `X-Title` headers, accepts JSON responses, and applies
|
|
109
|
+
* `transformClient` when provided.
|
|
110
|
+
*
|
|
111
|
+
* **Gotchas**
|
|
112
|
+
*
|
|
113
|
+
* Scoped `OpenRouterConfig.withClientTransform` applies to generated client
|
|
114
|
+
* request methods. Streaming chat completion requests are sent directly by this
|
|
115
|
+
* module and do not read that scoped transform.
|
|
116
|
+
*
|
|
117
|
+
* @see {@link layer} for providing this client from explicit options
|
|
118
|
+
* @see {@link layerConfig} for loading client settings from `Config`
|
|
74
119
|
*
|
|
75
|
-
* @since 1.0.0
|
|
76
120
|
* @category constructors
|
|
121
|
+
* @since 4.0.0
|
|
77
122
|
*/
|
|
78
123
|
export declare const make: (options: Options) => Effect.Effect<Service, never, HttpClient.HttpClient>;
|
|
79
124
|
/**
|
|
80
125
|
* Creates a layer for the OpenRouter client with the given options.
|
|
81
126
|
*
|
|
82
|
-
*
|
|
127
|
+
* **When to use**
|
|
128
|
+
*
|
|
129
|
+
* Use when you already have the OpenRouter client options in code and want to
|
|
130
|
+
* provide `OpenRouterClient` as a layer.
|
|
131
|
+
*
|
|
132
|
+
* @see {@link make} for constructing the client service effectfully
|
|
133
|
+
* @see {@link layerConfig} for loading client settings from `Config`
|
|
134
|
+
*
|
|
83
135
|
* @category layers
|
|
136
|
+
* @since 4.0.0
|
|
84
137
|
*/
|
|
85
138
|
export declare const layer: (options: Options) => Layer.Layer<OpenRouterClient, never, HttpClient.HttpClient>;
|
|
86
139
|
/**
|
|
87
|
-
* Creates a layer for the OpenRouter client
|
|
88
|
-
*
|
|
140
|
+
* Creates a layer for the OpenRouter client from provided `Config` values.
|
|
141
|
+
*
|
|
142
|
+
* **When to use**
|
|
143
|
+
*
|
|
144
|
+
* Use when you need client settings for OpenRouter to be read from Effect
|
|
145
|
+
* `Config` values while providing `OpenRouterClient` as a layer.
|
|
146
|
+
*
|
|
147
|
+
* **Details**
|
|
148
|
+
*
|
|
149
|
+
* Only config values supplied in `options` are loaded. Omitted fields are
|
|
150
|
+
* passed to `make` as `undefined`, and `transformClient` is forwarded as a
|
|
151
|
+
* plain option.
|
|
152
|
+
*
|
|
153
|
+
* @see {@link make} for constructing the client service effectfully
|
|
154
|
+
* @see {@link layer} for providing the client from already-resolved options
|
|
89
155
|
*
|
|
90
|
-
* @since 1.0.0
|
|
91
156
|
* @category layers
|
|
157
|
+
* @since 4.0.0
|
|
92
158
|
*/
|
|
93
159
|
export declare const layerConfig: (options?: {
|
|
94
160
|
/**
|
|
95
161
|
* The config value to load for the API key.
|
|
96
162
|
*/
|
|
97
|
-
readonly apiKey?: Config.Config<Redacted.Redacted<string
|
|
163
|
+
readonly apiKey?: Config.Config<Redacted.Redacted<string> | undefined> | undefined;
|
|
98
164
|
/**
|
|
99
165
|
* The config value to load for the API URL.
|
|
100
166
|
*/
|
|
@@ -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;;;;;;;GAOG;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,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AAC,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";
|
|
@@ -16,24 +16,53 @@ import { OpenRouterConfig } from "./OpenRouterConfig.js";
|
|
|
16
16
|
// Service Identifier
|
|
17
17
|
// =============================================================================
|
|
18
18
|
/**
|
|
19
|
-
* Service
|
|
19
|
+
* Service tag 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 when you need the OpenRouter client service value inside an effect.
|
|
43
|
+
*
|
|
44
|
+
* **Details**
|
|
45
|
+
*
|
|
46
|
+
* The returned service uses the current `HttpClient`, prepends `apiUrl` or
|
|
47
|
+
* `https://openrouter.ai/api/v1`, adds the bearer token and optional
|
|
48
|
+
* `HTTP-Referer` and `X-Title` headers, accepts JSON responses, and applies
|
|
49
|
+
* `transformClient` when provided.
|
|
50
|
+
*
|
|
51
|
+
* **Gotchas**
|
|
52
|
+
*
|
|
53
|
+
* Scoped `OpenRouterConfig.withClientTransform` applies to generated client
|
|
54
|
+
* request methods. Streaming chat completion requests are sent directly by this
|
|
55
|
+
* module and do not read that scoped transform.
|
|
56
|
+
*
|
|
57
|
+
* @see {@link layer} for providing this client from explicit options
|
|
58
|
+
* @see {@link layerConfig} for loading client settings from `Config`
|
|
30
59
|
*
|
|
31
|
-
* @since 1.0.0
|
|
32
60
|
* @category constructors
|
|
61
|
+
* @since 4.0.0
|
|
33
62
|
*/
|
|
34
63
|
export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
|
|
35
64
|
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-
|
|
65
|
+
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
66
|
const httpClientOk = HttpClient.filterStatusOk(httpClient);
|
|
38
67
|
const client = Generated.make(httpClient, {
|
|
39
68
|
transformClient: Effect.fnUntraced(function* (client) {
|
|
@@ -87,16 +116,37 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
|
|
|
87
116
|
/**
|
|
88
117
|
* Creates a layer for the OpenRouter client with the given options.
|
|
89
118
|
*
|
|
90
|
-
*
|
|
119
|
+
* **When to use**
|
|
120
|
+
*
|
|
121
|
+
* Use when you already have the OpenRouter client options in code and want to
|
|
122
|
+
* provide `OpenRouterClient` as a layer.
|
|
123
|
+
*
|
|
124
|
+
* @see {@link make} for constructing the client service effectfully
|
|
125
|
+
* @see {@link layerConfig} for loading client settings from `Config`
|
|
126
|
+
*
|
|
91
127
|
* @category layers
|
|
128
|
+
* @since 4.0.0
|
|
92
129
|
*/
|
|
93
130
|
export const layer = options => Layer.effect(OpenRouterClient, make(options));
|
|
94
131
|
/**
|
|
95
|
-
* Creates a layer for the OpenRouter client
|
|
96
|
-
*
|
|
132
|
+
* Creates a layer for the OpenRouter client from provided `Config` values.
|
|
133
|
+
*
|
|
134
|
+
* **When to use**
|
|
135
|
+
*
|
|
136
|
+
* Use when you need client settings for OpenRouter to be read from Effect
|
|
137
|
+
* `Config` values while providing `OpenRouterClient` as a layer.
|
|
138
|
+
*
|
|
139
|
+
* **Details**
|
|
140
|
+
*
|
|
141
|
+
* Only config values supplied in `options` are loaded. Omitted fields are
|
|
142
|
+
* passed to `make` as `undefined`, and `transformClient` is forwarded as a
|
|
143
|
+
* plain option.
|
|
144
|
+
*
|
|
145
|
+
* @see {@link make} for constructing the client service effectfully
|
|
146
|
+
* @see {@link layer} for providing the client from already-resolved options
|
|
97
147
|
*
|
|
98
|
-
* @since 1.0.0
|
|
99
148
|
* @category layers
|
|
149
|
+
* @since 4.0.0
|
|
100
150
|
*/
|
|
101
151
|
export const layerConfig = options => Layer.effect(OpenRouterClient, Effect.gen(function* () {
|
|
102
152
|
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":"AASA,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,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MwB,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,130 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
6
11
|
import type { HttpClient } from "effect/unstable/http/HttpClient";
|
|
7
|
-
declare const OpenRouterConfig_base:
|
|
12
|
+
declare const OpenRouterConfig_base: Context.ServiceClass<OpenRouterConfig, "@effect/ai-openrouter/OpenRouterConfig", OpenRouterConfig.Service>;
|
|
8
13
|
/**
|
|
9
|
-
*
|
|
14
|
+
* Context service for scoped OpenRouter provider configuration used by client
|
|
15
|
+
* operations.
|
|
16
|
+
*
|
|
17
|
+
* **When to use**
|
|
18
|
+
*
|
|
19
|
+
* Use as the context service tag when manually providing or reading scoped
|
|
20
|
+
* OpenRouter provider configuration in an Effect context.
|
|
21
|
+
*
|
|
22
|
+
* @see {@link withClientTransform} for scoping an HTTP client transformation
|
|
23
|
+
*
|
|
10
24
|
* @category services
|
|
25
|
+
* @since 4.0.0
|
|
11
26
|
*/
|
|
12
27
|
export declare class OpenRouterConfig extends OpenRouterConfig_base {
|
|
13
28
|
/**
|
|
14
|
-
*
|
|
29
|
+
* Gets the configured OpenRouter service from the current context when present.
|
|
30
|
+
*
|
|
31
|
+
* @since 4.0.0
|
|
15
32
|
*/
|
|
16
33
|
static readonly getOrUndefined: Effect.Effect<typeof OpenRouterConfig.Service | undefined>;
|
|
17
34
|
}
|
|
18
35
|
/**
|
|
19
|
-
*
|
|
36
|
+
* Types associated with the `OpenRouterConfig` context service.
|
|
37
|
+
*
|
|
38
|
+
* @since 4.0.0
|
|
20
39
|
*/
|
|
21
40
|
export declare namespace OpenRouterConfig {
|
|
22
41
|
/**
|
|
23
|
-
*
|
|
42
|
+
* Configuration values read by OpenRouter provider operations when resolving
|
|
43
|
+
* the generated HTTP client.
|
|
44
|
+
*
|
|
24
45
|
* @category models
|
|
46
|
+
* @since 4.0.0
|
|
25
47
|
*/
|
|
26
48
|
interface Service {
|
|
27
49
|
readonly transformClient?: ((client: HttpClient) => HttpClient) | undefined;
|
|
28
50
|
}
|
|
29
51
|
}
|
|
30
52
|
/**
|
|
31
|
-
*
|
|
53
|
+
* Provides a scoped transform for the OpenRouter HTTP client used by provider
|
|
54
|
+
* operations.
|
|
55
|
+
*
|
|
56
|
+
* **When to use**
|
|
57
|
+
*
|
|
58
|
+
* Use when you need temporary OpenRouter HTTP client customization for a
|
|
59
|
+
* single effect or workflow without rebuilding the client layer.
|
|
60
|
+
*
|
|
61
|
+
* **Details**
|
|
62
|
+
*
|
|
63
|
+
* Supports both data-first and data-last forms. The transform is stored in the
|
|
64
|
+
* scoped `OpenRouterConfig` service and read by generated OpenRouter request
|
|
65
|
+
* operations while running the supplied effect.
|
|
66
|
+
*
|
|
67
|
+
* **Gotchas**
|
|
68
|
+
*
|
|
69
|
+
* If a transform is already present in the scoped config, this helper replaces
|
|
70
|
+
* it. Compose transforms manually when both should apply. Streaming chat
|
|
71
|
+
* completion requests are sent directly by `OpenRouterClient.make` and do not
|
|
72
|
+
* read this scoped transform.
|
|
73
|
+
*
|
|
32
74
|
* @category configuration
|
|
75
|
+
* @since 4.0.0
|
|
33
76
|
*/
|
|
34
77
|
export declare const withClientTransform: {
|
|
35
78
|
/**
|
|
36
|
-
*
|
|
79
|
+
* Provides a scoped transform for the OpenRouter HTTP client used by provider
|
|
80
|
+
* operations.
|
|
81
|
+
*
|
|
82
|
+
* **When to use**
|
|
83
|
+
*
|
|
84
|
+
* Use when you need temporary OpenRouter HTTP client customization for a
|
|
85
|
+
* single effect or workflow 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
|
+
*
|
|
37
100
|
* @category configuration
|
|
101
|
+
* @since 4.0.0
|
|
38
102
|
*/
|
|
39
103
|
(transform: (client: HttpClient) => HttpClient): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
40
104
|
/**
|
|
41
|
-
*
|
|
105
|
+
* Provides a scoped transform for the OpenRouter HTTP client used by provider
|
|
106
|
+
* operations.
|
|
107
|
+
*
|
|
108
|
+
* **When to use**
|
|
109
|
+
*
|
|
110
|
+
* Use when you need temporary OpenRouter HTTP client customization for a
|
|
111
|
+
* single effect or workflow 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
|
+
*
|
|
42
126
|
* @category configuration
|
|
127
|
+
* @since 4.0.0
|
|
43
128
|
*/
|
|
44
129
|
<A, E, R>(self: Effect.Effect<A, E, R>, transform: (client: HttpClient) => HttpClient): Effect.Effect<A, E, R>;
|
|
45
130
|
};
|
|
@@ -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;;;;;;;GAOG;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,60 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
|
/**
|
|
8
|
-
*
|
|
13
|
+
* Context service for scoped OpenRouter provider configuration used by client
|
|
14
|
+
* operations.
|
|
15
|
+
*
|
|
16
|
+
* **When to use**
|
|
17
|
+
*
|
|
18
|
+
* Use as the context service tag when manually providing or reading scoped
|
|
19
|
+
* OpenRouter provider configuration in an Effect context.
|
|
20
|
+
*
|
|
21
|
+
* @see {@link withClientTransform} for scoping an HTTP client transformation
|
|
22
|
+
*
|
|
9
23
|
* @category services
|
|
24
|
+
* @since 4.0.0
|
|
10
25
|
*/
|
|
11
|
-
export class OpenRouterConfig extends /*#__PURE__*/
|
|
26
|
+
export class OpenRouterConfig extends /*#__PURE__*/Context.Service()("@effect/ai-openrouter/OpenRouterConfig") {
|
|
12
27
|
/**
|
|
13
|
-
*
|
|
28
|
+
* Gets the configured OpenRouter service from the current context when present.
|
|
29
|
+
*
|
|
30
|
+
* @since 4.0.0
|
|
14
31
|
*/
|
|
15
|
-
static getOrUndefined = /*#__PURE__*/Effect.map(/*#__PURE__*/Effect.
|
|
32
|
+
static getOrUndefined = /*#__PURE__*/Effect.map(/*#__PURE__*/Effect.context(), services => services.mapUnsafe.get(OpenRouterConfig.key));
|
|
16
33
|
}
|
|
17
34
|
/**
|
|
18
|
-
*
|
|
35
|
+
* Provides a scoped transform for the OpenRouter HTTP client used by provider
|
|
36
|
+
* operations.
|
|
37
|
+
*
|
|
38
|
+
* **When to use**
|
|
39
|
+
*
|
|
40
|
+
* Use when you need temporary OpenRouter HTTP client customization for a
|
|
41
|
+
* single effect or workflow without rebuilding the client layer.
|
|
42
|
+
*
|
|
43
|
+
* **Details**
|
|
44
|
+
*
|
|
45
|
+
* Supports both data-first and data-last forms. The transform is stored in the
|
|
46
|
+
* scoped `OpenRouterConfig` service and read by generated OpenRouter request
|
|
47
|
+
* operations while running the supplied effect.
|
|
48
|
+
*
|
|
49
|
+
* **Gotchas**
|
|
50
|
+
*
|
|
51
|
+
* If a transform is already present in the scoped config, this helper replaces
|
|
52
|
+
* it. Compose transforms manually when both should apply. Streaming chat
|
|
53
|
+
* completion requests are sent directly by `OpenRouterClient.make` and do not
|
|
54
|
+
* read this scoped transform.
|
|
55
|
+
*
|
|
19
56
|
* @category configuration
|
|
57
|
+
* @since 4.0.0
|
|
20
58
|
*/
|
|
21
59
|
export const withClientTransform = /*#__PURE__*/dual(2, (self, transformClient) => Effect.flatMap(OpenRouterConfig.getOrUndefined, config => Effect.provideService(self, OpenRouterConfig, {
|
|
22
60
|
...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;;;;;;;;AAQA,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":[]}
|