@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, 06:00 UTC

main
ts 88 lines 2.79 KB
Raw
1 /**
2 * The `AnthropicConfig` module lets a workflow temporarily customize the HTTP
3 * client used by generated Anthropic requests. It is used by
4 * `AnthropicClient` when request helpers run, so code can add middleware,
5 * logging, or other client changes without rebuilding the client layer.
6 *
7 * @stability unstable
8 * @since 4.0.0
9 */
10 import * as Context from "effect/Context"
11 import * as Effect from "effect/Effect"
12 import { dual } from "effect/Function"
13 import type { HttpClient } from "effect/http/HttpClient"
14
15 /**
16 * Service tag for Anthropic client configuration overrides, such as transformations applied to the generated HTTP client.
17 *
18 * **When to use**
19 *
20 * Use when you need to provide or read Anthropic client configuration through
21 * Effect's context from a layer or integration.
22 *
23 * @see {@link withClientTransform} for scoping an HTTP client transformation
24 *
25 * @stability unstable
26 * @category services
27 * @since 4.0.0
28 */
29 export class AnthropicConfig extends Context.Service<
30 AnthropicConfig,
31 AnthropicConfig.Service
32 >()("@effect/ai-anthropic/AnthropicConfig") {
33 /**
34 * Gets the configured Anthropic service from the current context when present.
35 *
36 * @since 4.0.0
37 */
38 static readonly getOrUndefined: Effect.Effect<typeof AnthropicConfig.Service | undefined> = Effect.map(
39 Effect.context<never>(),
40 Context.getOrUndefined(AnthropicConfig)
41 )
42 }
43
44 /**
45 * Namespace containing types associated with the `AnthropicConfig` service.
46 *
47 * @stability unstable
48 * @since 4.0.0
49 */
50 export declare namespace AnthropicConfig {
51 /**
52 * Configuration provided through `AnthropicConfig`.
53 *
54 * **Details**
55 *
56 * Use `transformClient` to wrap or replace the `HttpClient` used by generated Anthropic API requests.
57 *
58 * @category services
59 * @since 4.0.0
60 */
61 export interface Service {
62 readonly transformClient?: ((client: HttpClient) => HttpClient) | undefined
63 }
64 }
65
66 /**
67 * Runs an effect with an `AnthropicConfig` override that transforms the underlying `HttpClient` used by generated Anthropic requests.
68 *
69 * **When to use**
70 *
71 * Use when you need to apply a temporary `HttpClient` transformation, such as adding middleware or logging, to a
72 * specific scope of an effectful program.
73 *
74 * @stability unstable
75 * @category configuration
76 * @since 4.0.0
77 */
78 export const withClientTransform: {
79 (transform: (client: HttpClient) => HttpClient): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
80 <A, E, R>(self: Effect.Effect<A, E, R>, transform: (client: HttpClient) => HttpClient): Effect.Effect<A, E, R>
81 } = dual(2, <A, E, R>(
82 self: Effect.Effect<A, E, R>,
83 transformClient: (client: HttpClient) => HttpClient
84 ) =>
85 Effect.flatMap(
86 AnthropicConfig.getOrUndefined,
87 (config) => Effect.provideService(self, AnthropicConfig, { ...config, transformClient })
88 ))