@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 76 lines 2.36 KB
Raw
1 /**
2 * Scoped HTTP client customization for OpenRouter requests.
3 *
4 * @stability unstable
5 * @since 4.0.0
6 */
7 import * as Context from "effect/Context"
8 import * as Effect from "effect/Effect"
9 import { dual } from "effect/Function"
10 import type { HttpClient } from "effect/http/HttpClient"
11
12 /**
13 * Scoped configuration read when executing OpenRouter requests.
14 *
15 * @see {@link withClientTransform} for scoping an HTTP client transformation
16 *
17 * @stability unstable
18 * @category services
19 * @since 4.0.0
20 */
21 export class OpenRouterConfig extends Context.Service<
22 OpenRouterConfig,
23 OpenRouterConfig.Service
24 >()("@effect/ai-openrouter/OpenRouterConfig") {
25 /**
26 * Gets the configured OpenRouter service from the current context when present.
27 *
28 * @since 4.0.0
29 */
30 static readonly getOrUndefined: Effect.Effect<typeof OpenRouterConfig.Service | undefined> = Effect.map(
31 Effect.context<never>(),
32 Context.getOrUndefined(OpenRouterConfig)
33 )
34 }
35
36 /**
37 * Types associated with the `OpenRouterConfig` context service.
38 *
39 * @stability unstable
40 * @since 4.0.0
41 */
42 export declare namespace OpenRouterConfig {
43 /**
44 * HTTP client configuration for generated methods and alpha Decisions requests.
45 *
46 * @category services
47 * @since 4.0.0
48 */
49 export interface Service {
50 readonly transformClient?: ((client: HttpClient) => HttpClient) | undefined
51 }
52 }
53
54 /**
55 * Transforms the HTTP client for generated methods and alpha Decisions requests
56 * made by the supplied effect. Streaming chat completions ignore this transform.
57 * Replaces any existing scoped transform; compose them manually to apply both.
58 *
59 * @stability unstable
60 * @category configuration
61 * @since 4.0.0
62 */
63 export const withClientTransform: {
64 (transform: (client: HttpClient) => HttpClient): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
65 <A, E, R>(self: Effect.Effect<A, E, R>, transform: (client: HttpClient) => HttpClient): Effect.Effect<A, E, R>
66 } = dual<
67 (transform: (client: HttpClient) => HttpClient) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,
68 <A, E, R>(self: Effect.Effect<A, E, R>, transform: (client: HttpClient) => HttpClient) => Effect.Effect<A, E, R>
69 >(
70 2,
71 (self, transformClient) =>
72 Effect.flatMap(
73 OpenRouterConfig.getOrUndefined,
74 (config) => Effect.provideService(self, OpenRouterConfig, { ...config, transformClient })
75 )
76 )