@effect/ai-anthropic 4.0.0-beta.7 → 4.0.0-beta.70
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/AnthropicClient.d.ts +40 -66
- package/dist/AnthropicClient.d.ts.map +1 -1
- package/dist/AnthropicClient.js +12 -14
- package/dist/AnthropicClient.js.map +1 -1
- package/dist/AnthropicConfig.d.ts +46 -10
- package/dist/AnthropicConfig.d.ts.map +1 -1
- package/dist/AnthropicConfig.js +31 -7
- package/dist/AnthropicConfig.js.map +1 -1
- package/dist/AnthropicError.d.ts +128 -37
- package/dist/AnthropicError.d.ts.map +1 -1
- package/dist/AnthropicError.js +1 -1
- package/dist/AnthropicLanguageModel.d.ts +281 -66
- package/dist/AnthropicLanguageModel.d.ts.map +1 -1
- package/dist/AnthropicLanguageModel.js +50 -14
- package/dist/AnthropicLanguageModel.js.map +1 -1
- package/dist/AnthropicTelemetry.d.ts +23 -16
- package/dist/AnthropicTelemetry.d.ts.map +1 -1
- package/dist/AnthropicTelemetry.js +6 -4
- package/dist/AnthropicTelemetry.js.map +1 -1
- package/dist/AnthropicTool.d.ts +298 -138
- package/dist/AnthropicTool.d.ts.map +1 -1
- package/dist/AnthropicTool.js +141 -87
- package/dist/AnthropicTool.js.map +1 -1
- package/dist/Generated.d.ts +11661 -5260
- package/dist/Generated.d.ts.map +1 -1
- package/dist/Generated.js +2318 -915
- package/dist/Generated.js.map +1 -1
- package/dist/index.d.ts +52 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +52 -8
- package/dist/index.js.map +1 -1
- package/dist/internal/errors.js +7 -7
- package/dist/internal/errors.js.map +1 -1
- package/package.json +3 -3
- package/src/AnthropicClient.ts +41 -67
- package/src/AnthropicConfig.ts +47 -11
- package/src/AnthropicError.ts +130 -37
- package/src/AnthropicLanguageModel.ts +274 -33
- package/src/AnthropicTelemetry.ts +24 -17
- package/src/AnthropicTool.ts +293 -133
- package/src/Generated.ts +3751 -1815
- package/src/index.ts +52 -8
- package/src/internal/errors.ts +9 -7
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type * as Config from "effect/Config";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
2
3
|
import * as Effect from "effect/Effect";
|
|
3
4
|
import * as Layer from "effect/Layer";
|
|
4
5
|
import * as Redacted from "effect/Redacted";
|
|
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 type * as AiError from "effect/unstable/ai/AiError";
|
|
9
9
|
import * as Sse from "effect/unstable/encoding/Sse";
|
|
@@ -13,25 +13,19 @@ import * as HttpClientRequest from "effect/unstable/http/HttpClientRequest";
|
|
|
13
13
|
import type * as HttpClientResponse from "effect/unstable/http/HttpClientResponse";
|
|
14
14
|
import * as Generated from "./Generated.ts";
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* Represents the Anthropic client service with methods for the Messages API, including regular and streaming message
|
|
17
|
+
* creation.
|
|
17
18
|
*
|
|
18
|
-
* Provides methods for interacting with Anthropic's Messages API, including
|
|
19
|
-
* both synchronous and streaming message creation.
|
|
20
|
-
*
|
|
21
|
-
* @since 1.0.0
|
|
22
19
|
* @category models
|
|
20
|
+
* @since 4.0.0
|
|
23
21
|
*/
|
|
24
22
|
export interface Service {
|
|
25
23
|
/**
|
|
26
|
-
* The underlying generated Anthropic client
|
|
27
|
-
* endpoints.
|
|
24
|
+
* The underlying generated Anthropic client that exposes all API endpoints.
|
|
28
25
|
*/
|
|
29
26
|
readonly client: Generated.AnthropicClient;
|
|
30
27
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* Executes an HTTP request and decodes the Server-Sent Events response
|
|
34
|
-
* using the provided schema.
|
|
28
|
+
* Executes a low-level streaming HTTP request and decodes the Server-Sent Events response using the provided schema.
|
|
35
29
|
*/
|
|
36
30
|
readonly streamRequest: <Type extends {
|
|
37
31
|
readonly id?: string | undefined;
|
|
@@ -39,10 +33,7 @@ export interface Service {
|
|
|
39
33
|
readonly data: string;
|
|
40
34
|
}, DecodingServices>(schema: Schema.Decoder<Type, DecodingServices>) => (request: HttpClientRequest.HttpClientRequest) => Stream.Stream<Type, HttpClientError.HttpClientError | Schema.SchemaError | Sse.Retry, DecodingServices>;
|
|
41
35
|
/**
|
|
42
|
-
* Creates a message using the Anthropic Messages API.
|
|
43
|
-
*
|
|
44
|
-
* Sends a structured list of input messages and returns the model's
|
|
45
|
-
* generated response. All errors are mapped to the unified `AiError` type.
|
|
36
|
+
* Creates a message using the Anthropic Messages API and maps all errors to the unified `AiError` type.
|
|
46
37
|
*/
|
|
47
38
|
readonly createMessage: (options: {
|
|
48
39
|
readonly payload: typeof Generated.BetaCreateMessageParams.Encoded;
|
|
@@ -52,12 +43,12 @@ export interface Service {
|
|
|
52
43
|
response: HttpClientResponse.HttpClientResponse
|
|
53
44
|
], AiError.AiError>;
|
|
54
45
|
/**
|
|
55
|
-
* Creates a streaming message using the Anthropic Messages API.
|
|
46
|
+
* Creates a streaming message using the Anthropic Messages API and maps all errors to the unified `AiError` type.
|
|
47
|
+
*
|
|
48
|
+
* **Details**
|
|
56
49
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* when a `message_stop` event is received. All errors are mapped to the
|
|
60
|
-
* unified `AiError` type.
|
|
50
|
+
* The returned Effect yields the HTTP response and a stream of events as the model generates its response. The stream
|
|
51
|
+
* automatically terminates when a `message_stop` event is received.
|
|
61
52
|
*/
|
|
62
53
|
readonly createMessageStream: (options: {
|
|
63
54
|
readonly payload: Omit<typeof Generated.BetaCreateMessageParams.Encoded, "stream">;
|
|
@@ -68,8 +59,9 @@ export interface Service {
|
|
|
68
59
|
], AiError.AiError>;
|
|
69
60
|
}
|
|
70
61
|
/**
|
|
71
|
-
* Represents an event received from the Anthropic Messages API during a
|
|
72
|
-
*
|
|
62
|
+
* Represents an event received from the Anthropic Messages API during a streaming request.
|
|
63
|
+
*
|
|
64
|
+
* **Details**
|
|
73
65
|
*
|
|
74
66
|
* Events include:
|
|
75
67
|
* - `message_start`: Initial event containing message metadata
|
|
@@ -80,115 +72,97 @@ export interface Service {
|
|
|
80
72
|
* - `content_block_stop`: End of a content block
|
|
81
73
|
* - `error`: Error events with type and message
|
|
82
74
|
*
|
|
83
|
-
* @since 1.0.0
|
|
84
75
|
* @category models
|
|
76
|
+
* @since 4.0.0
|
|
85
77
|
*/
|
|
86
78
|
export type MessageStreamEvent = typeof Generated.BetaMessageStartEvent.Type | typeof Generated.BetaMessageDeltaEvent.Type | typeof Generated.BetaMessageStopEvent.Type | typeof Generated.BetaContentBlockStartEvent.Type | typeof Generated.BetaContentBlockDeltaEvent.Type | typeof Generated.BetaContentBlockStopEvent.Type | typeof Generated.BetaErrorResponse.Type;
|
|
87
|
-
declare const AnthropicClient_base:
|
|
79
|
+
declare const AnthropicClient_base: Context.ServiceClass<AnthropicClient, "@effect/ai-anthropic/AnthropicClient", Service>;
|
|
88
80
|
/**
|
|
89
81
|
* Service identifier for the Anthropic client.
|
|
90
82
|
*
|
|
91
|
-
* @
|
|
92
|
-
* @
|
|
83
|
+
* @category services
|
|
84
|
+
* @since 4.0.0
|
|
93
85
|
*/
|
|
94
86
|
export declare class AnthropicClient extends AnthropicClient_base {
|
|
95
87
|
}
|
|
96
88
|
/**
|
|
97
89
|
* Configuration options for creating an Anthropic client.
|
|
98
90
|
*
|
|
99
|
-
* @since 1.0.0
|
|
100
91
|
* @category models
|
|
92
|
+
* @since 4.0.0
|
|
101
93
|
*/
|
|
102
94
|
export type Options = {
|
|
103
95
|
/**
|
|
104
|
-
* The Anthropic API key for authentication.
|
|
105
|
-
*
|
|
106
|
-
* If not provided, requests will be made without authentication (useful for
|
|
107
|
-
* proxied setups or testing).
|
|
96
|
+
* The Anthropic API key for authentication. Requests are made without authentication when this is omitted, which is
|
|
97
|
+
* useful for proxied setups or testing.
|
|
108
98
|
*/
|
|
109
99
|
readonly apiKey?: Redacted.Redacted<string> | undefined;
|
|
110
100
|
/**
|
|
111
|
-
* The base URL for the Anthropic API.
|
|
112
|
-
*
|
|
113
|
-
* Override this to use a proxy or a different API-compatible endpoint.
|
|
101
|
+
* The base URL for the Anthropic API. Override this to use a proxy or a different API-compatible endpoint.
|
|
114
102
|
*
|
|
115
103
|
* @default "https://api.anthropic.com"
|
|
116
104
|
*/
|
|
117
105
|
readonly apiUrl?: string | undefined;
|
|
118
106
|
/**
|
|
119
|
-
* The Anthropic API version header value.
|
|
120
|
-
*
|
|
121
|
-
* Controls which version of the API to use. See Anthropic's versioning
|
|
122
|
-
* documentation for available versions and their features.
|
|
107
|
+
* The Anthropic API version header value. This controls which version of the API to use.
|
|
123
108
|
*
|
|
124
109
|
* @default "2023-06-01"
|
|
125
110
|
*/
|
|
126
111
|
readonly apiVersion?: string | undefined;
|
|
127
112
|
/**
|
|
128
|
-
* Optional transformer for the underlying HTTP client
|
|
129
|
-
*
|
|
130
|
-
* Use this to add middleware, logging, or custom request/response handling.
|
|
113
|
+
* Optional transformer for the underlying HTTP client, such as middleware, logging, or custom request/response
|
|
114
|
+
* handling.
|
|
131
115
|
*/
|
|
132
116
|
readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined;
|
|
133
117
|
};
|
|
134
118
|
/**
|
|
135
119
|
* Creates an Anthropic client service with the given options.
|
|
136
120
|
*
|
|
137
|
-
*
|
|
138
|
-
* - API key authentication via the `x-api-key` header
|
|
139
|
-
* - API versioning via the `anthropic-version` header
|
|
140
|
-
* - Error mapping to the unified `AiError` type
|
|
141
|
-
* - Request/response transformations via `AnthropicConfig`
|
|
121
|
+
* **Details**
|
|
142
122
|
*
|
|
143
|
-
*
|
|
123
|
+
* The client handles API key authentication via the `x-api-key` header, API versioning via the `anthropic-version`
|
|
124
|
+
* header, error mapping to the unified `AiError` type, and request/response transformations via `AnthropicConfig`. It
|
|
125
|
+
* requires an `HttpClient` in the context.
|
|
144
126
|
*
|
|
145
|
-
* @since 1.0.0
|
|
146
127
|
* @category constructors
|
|
128
|
+
* @since 4.0.0
|
|
147
129
|
*/
|
|
148
130
|
export declare const make: (options: Options) => Effect.Effect<Service, never, HttpClient.HttpClient>;
|
|
149
131
|
/**
|
|
150
132
|
* Creates a layer for the Anthropic client with the given options.
|
|
151
133
|
*
|
|
152
|
-
* @since 1.0.0
|
|
153
134
|
* @category layers
|
|
135
|
+
* @since 4.0.0
|
|
154
136
|
*/
|
|
155
137
|
export declare const layer: (options: Options) => Layer.Layer<AnthropicClient, never, HttpClient.HttpClient>;
|
|
156
138
|
/**
|
|
157
139
|
* Creates a layer for the Anthropic client, loading the requisite configuration
|
|
158
140
|
* via Effect's `Config` module.
|
|
159
141
|
*
|
|
160
|
-
* @since 1.0.0
|
|
161
142
|
* @category layers
|
|
143
|
+
* @since 4.0.0
|
|
162
144
|
*/
|
|
163
145
|
export declare const layerConfig: (options?: {
|
|
164
146
|
/**
|
|
165
|
-
* The Anthropic API key for authentication.
|
|
166
|
-
*
|
|
167
|
-
* If not provided, requests will be made without authentication (useful for
|
|
168
|
-
* proxied setups or testing).
|
|
147
|
+
* The Anthropic API key for authentication. Requests are made without authentication when this is omitted, which is
|
|
148
|
+
* useful for proxied setups or testing.
|
|
169
149
|
*/
|
|
170
|
-
readonly apiKey?: Config.Config<Redacted.Redacted<string
|
|
150
|
+
readonly apiKey?: Config.Config<Redacted.Redacted<string> | undefined> | undefined;
|
|
171
151
|
/**
|
|
172
|
-
* The base URL for the Anthropic API.
|
|
173
|
-
*
|
|
174
|
-
* Override this to use a proxy or a different API-compatible endpoint.
|
|
152
|
+
* The base URL for the Anthropic API. Override this to use a proxy or a different API-compatible endpoint.
|
|
175
153
|
*
|
|
176
154
|
* @default "https://api.anthropic.com"
|
|
177
155
|
*/
|
|
178
156
|
readonly apiUrl?: Config.Config<string> | undefined;
|
|
179
157
|
/**
|
|
180
|
-
* The Anthropic API version header value.
|
|
181
|
-
*
|
|
182
|
-
* Controls which version of the API to use. See Anthropic's versioning
|
|
183
|
-
* documentation for available versions and their features.
|
|
158
|
+
* The Anthropic API version header value. This controls which version of the API to use.
|
|
184
159
|
*
|
|
185
160
|
* @default "2023-06-01"
|
|
186
161
|
*/
|
|
187
162
|
readonly apiVersion?: Config.Config<string> | undefined;
|
|
188
163
|
/**
|
|
189
|
-
* Optional transformer for the underlying HTTP client
|
|
190
|
-
*
|
|
191
|
-
* Use this to add middleware, logging, or custom request/response handling.
|
|
164
|
+
* Optional transformer for the underlying HTTP client, such as middleware, logging, or custom request/response
|
|
165
|
+
* handling.
|
|
192
166
|
*/
|
|
193
167
|
readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined;
|
|
194
168
|
}) => Layer.Layer<AnthropicClient, Config.ConfigError, HttpClient.HttpClient>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnthropicClient.d.ts","sourceRoot":"","sources":["../src/AnthropicClient.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"AnthropicClient.d.ts","sourceRoot":"","sources":["../src/AnthropicClient.ts"],"names":[],"mappings":"AASA,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,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAA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Anthropic operations including
|
|
5
5
|
* messages and streaming responses.
|
|
6
6
|
*
|
|
7
|
-
* @since
|
|
7
|
+
* @since 4.0.0
|
|
8
8
|
*/
|
|
9
9
|
import * as Array from "effect/Array";
|
|
10
|
+
import * as Context from "effect/Context";
|
|
10
11
|
import * as Effect from "effect/Effect";
|
|
11
12
|
import { identity } from "effect/Function";
|
|
12
13
|
import * as Layer from "effect/Layer";
|
|
13
14
|
import * as Predicate from "effect/Predicate";
|
|
14
15
|
import * as Redacted from "effect/Redacted";
|
|
15
16
|
import * as Schema from "effect/Schema";
|
|
16
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
17
17
|
import * as Stream from "effect/Stream";
|
|
18
18
|
import * as Sse from "effect/unstable/encoding/Sse";
|
|
19
19
|
import * as Headers from "effect/unstable/http/Headers";
|
|
@@ -29,10 +29,10 @@ import * as Errors from "./internal/errors.js";
|
|
|
29
29
|
/**
|
|
30
30
|
* Service identifier for the Anthropic client.
|
|
31
31
|
*
|
|
32
|
-
* @
|
|
33
|
-
* @
|
|
32
|
+
* @category services
|
|
33
|
+
* @since 4.0.0
|
|
34
34
|
*/
|
|
35
|
-
export class AnthropicClient extends /*#__PURE__*/
|
|
35
|
+
export class AnthropicClient extends /*#__PURE__*/Context.Service()("@effect/ai-anthropic/AnthropicClient") {}
|
|
36
36
|
// =============================================================================
|
|
37
37
|
// Constructor
|
|
38
38
|
// =============================================================================
|
|
@@ -42,16 +42,14 @@ const RedactedAnthropicHeaders = {
|
|
|
42
42
|
/**
|
|
43
43
|
* Creates an Anthropic client service with the given options.
|
|
44
44
|
*
|
|
45
|
-
*
|
|
46
|
-
* - API key authentication via the `x-api-key` header
|
|
47
|
-
* - API versioning via the `anthropic-version` header
|
|
48
|
-
* - Error mapping to the unified `AiError` type
|
|
49
|
-
* - Request/response transformations via `AnthropicConfig`
|
|
45
|
+
* **Details**
|
|
50
46
|
*
|
|
51
|
-
*
|
|
47
|
+
* The client handles API key authentication via the `x-api-key` header, API versioning via the `anthropic-version`
|
|
48
|
+
* header, error mapping to the unified `AiError` type, and request/response transformations via `AnthropicConfig`. It
|
|
49
|
+
* requires an `HttpClient` in the context.
|
|
52
50
|
*
|
|
53
|
-
* @since 1.0.0
|
|
54
51
|
* @category constructors
|
|
52
|
+
* @since 4.0.0
|
|
55
53
|
*/
|
|
56
54
|
export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
|
|
57
55
|
const baseClient = yield* HttpClient.HttpClient;
|
|
@@ -117,16 +115,16 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
|
|
|
117
115
|
/**
|
|
118
116
|
* Creates a layer for the Anthropic client with the given options.
|
|
119
117
|
*
|
|
120
|
-
* @since 1.0.0
|
|
121
118
|
* @category layers
|
|
119
|
+
* @since 4.0.0
|
|
122
120
|
*/
|
|
123
121
|
export const layer = options => Layer.effect(AnthropicClient, make(options));
|
|
124
122
|
/**
|
|
125
123
|
* Creates a layer for the Anthropic client, loading the requisite configuration
|
|
126
124
|
* via Effect's `Config` module.
|
|
127
125
|
*
|
|
128
|
-
* @since 1.0.0
|
|
129
126
|
* @category layers
|
|
127
|
+
* @since 4.0.0
|
|
130
128
|
*/
|
|
131
129
|
export const layerConfig = options => Layer.effect(AnthropicClient, Effect.gen(function* () {
|
|
132
130
|
const apiKey = Predicate.isNotUndefined(options?.apiKey) ? yield* options.apiKey : undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnthropicClient.js","names":["Array","Effect","identity","Layer","Predicate","Redacted","Schema","
|
|
1
|
+
{"version":3,"file":"AnthropicClient.js","names":["Array","Context","Effect","identity","Layer","Predicate","Redacted","Schema","Stream","Sse","Headers","HttpBody","HttpClient","HttpClientRequest","AnthropicConfig","Generated","Errors","AnthropicClient","Service","RedactedAnthropicHeaders","AnthropicApiKey","make","fnUntraced","options","baseClient","apiVersion","httpClient","pipe","mapRequest","request","prependUrl","apiUrl","isNotUndefined","apiKey","setHeader","value","acceptJson","transformClient","client","config","getOrUndefined","httpClientOk","filterStatusOk","streamRequest","schema","execute","map","response","stream","unwrap","decodeText","pipeThroughChannel","decodeSchema","createMessage","betaMessagesPost","includeResponse","catchTags","BetaMessagesPost4XX","error","fail","mapClientError","HttpClientError","mapHttpClientError","SchemaError","mapSchemaError","PingEvent","Struct","type","Literal","MessageEvent","Union","BetaMessageStartEvent","BetaMessageDeltaEvent","BetaMessageStopEvent","BetaContentBlockStartEvent","BetaContentBlockDeltaEvent","BetaContentBlockStopEvent","BetaErrorResponse","buildMessageStream","decodeDataSchema","takeUntil","event","data","filter","Retry","die","fromEffect","createMessageStream","post","headers","fromInput","params","undefined","body","jsonUnsafe","payload","catchTag","of","updateService","CurrentRedactedNames","appendAll","Object","values","layer","effect","layerConfig","gen"],"sources":["../src/AnthropicClient.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;AAQA,OAAO,KAAKA,KAAK,MAAM,cAAc;AAErC,OAAO,KAAKC,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;AAC7C,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,MAAM,MAAM,eAAe;AAEvC,OAAO,KAAKC,GAAG,MAAM,8BAA8B;AACnD,OAAO,KAAKC,OAAO,MAAM,8BAA8B;AACvD,OAAO,KAAKC,QAAQ,MAAM,+BAA+B;AACzD,OAAO,KAAKC,UAAU,MAAM,iCAAiC;AAE7D,OAAO,KAAKC,iBAAiB,MAAM,wCAAwC;AAE3E,SAASC,eAAe,QAAQ,sBAAsB;AACtD,OAAO,KAAKC,SAAS,MAAM,gBAAgB;AAC3C,OAAO,KAAKC,MAAM,MAAM,sBAAsB;AA2F9C;AACA;AACA;AAEA;;;;;;AA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AM7D,MAAM,GAAG1B,SAAS,CAAC2B,cAAc,CAACT,OAAO,EAAEQ,MAAM,CAAC,GACpD,OAAOR,OAAO,CAACQ,MAAM,GACvB6D,SAAS;EACX,MAAMnE,UAAU,GAAGpB,SAAS,CAAC2B,cAAc,CAACT,OAAO,EAAEE,UAAU,CAAC,GAC5D,OAAOF,OAAO,CAACE,UAAU,GAC3BmE,SAAS;EACX,OAAO,OAAOvE,IAAI,CAAC;IACjBY,MAAM;IACNF,MAAM;IACNN,UAAU;IACVY,eAAe,EAAEd,OAAO,EAAEc;GAC3B,CAAC;AACJ,CAAC,CAAC,CACH","ignoreList":[]}
|
|
@@ -1,45 +1,81 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The `AnthropicConfig` module provides contextual configuration for the
|
|
3
|
+
* Anthropic AI provider integration. It is used to customize the generated
|
|
4
|
+
* Anthropic HTTP client without changing individual request code.
|
|
5
|
+
*
|
|
6
|
+
* **Common tasks**
|
|
7
|
+
*
|
|
8
|
+
* - Provide a shared `HttpClient` transformation for Anthropic requests
|
|
9
|
+
* - Add provider-specific concerns such as request instrumentation, proxying,
|
|
10
|
+
* retries, or header manipulation
|
|
11
|
+
* - Scope a client transformation to a single effect with {@link withClientTransform}
|
|
12
|
+
*
|
|
13
|
+
* **Gotchas**
|
|
14
|
+
*
|
|
15
|
+
* - Configuration is read from the Effect context, so overrides only apply to
|
|
16
|
+
* effects run inside the configured scope
|
|
17
|
+
* - `withClientTransform` replaces the current `transformClient` value while
|
|
18
|
+
* preserving any other Anthropic configuration fields
|
|
19
|
+
*
|
|
20
|
+
* @since 4.0.0
|
|
3
21
|
*/
|
|
22
|
+
import * as Context from "effect/Context";
|
|
4
23
|
import * as Effect from "effect/Effect";
|
|
5
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
6
24
|
import type { HttpClient } from "effect/unstable/http/HttpClient";
|
|
7
|
-
declare const AnthropicConfig_base:
|
|
25
|
+
declare const AnthropicConfig_base: Context.ServiceClass<AnthropicConfig, "@effect/ai-anthropic/AnthropicConfig", AnthropicConfig.Service>;
|
|
8
26
|
/**
|
|
9
|
-
*
|
|
27
|
+
* Service tag for Anthropic client configuration overrides, such as transformations applied to the generated HTTP client.
|
|
28
|
+
*
|
|
10
29
|
* @category services
|
|
30
|
+
* @since 4.0.0
|
|
11
31
|
*/
|
|
12
32
|
export declare class AnthropicConfig extends AnthropicConfig_base {
|
|
13
33
|
/**
|
|
14
|
-
*
|
|
34
|
+
* Gets the configured Anthropic service from the current context when present.
|
|
35
|
+
*
|
|
36
|
+
* @since 4.0.0
|
|
15
37
|
*/
|
|
16
38
|
static readonly getOrUndefined: Effect.Effect<typeof AnthropicConfig.Service | undefined>;
|
|
17
39
|
}
|
|
18
40
|
/**
|
|
19
|
-
*
|
|
41
|
+
* Namespace containing types associated with the `AnthropicConfig` service.
|
|
42
|
+
*
|
|
43
|
+
* @since 4.0.0
|
|
20
44
|
*/
|
|
21
45
|
export declare namespace AnthropicConfig {
|
|
22
46
|
/**
|
|
23
|
-
*
|
|
47
|
+
* Configuration provided through `AnthropicConfig`.
|
|
48
|
+
*
|
|
49
|
+
* **Details**
|
|
50
|
+
*
|
|
51
|
+
* Use `transformClient` to wrap or replace the `HttpClient` used by generated Anthropic API requests.
|
|
52
|
+
*
|
|
24
53
|
* @category models
|
|
54
|
+
* @since 4.0.0
|
|
25
55
|
*/
|
|
26
56
|
interface Service {
|
|
27
57
|
readonly transformClient?: ((client: HttpClient) => HttpClient) | undefined;
|
|
28
58
|
}
|
|
29
59
|
}
|
|
30
60
|
/**
|
|
31
|
-
*
|
|
61
|
+
* Runs an effect with an `AnthropicConfig` override that transforms the underlying `HttpClient` used by generated Anthropic requests.
|
|
62
|
+
*
|
|
32
63
|
* @category configuration
|
|
64
|
+
* @since 4.0.0
|
|
33
65
|
*/
|
|
34
66
|
export declare const withClientTransform: {
|
|
35
67
|
/**
|
|
36
|
-
*
|
|
68
|
+
* Runs an effect with an `AnthropicConfig` override that transforms the underlying `HttpClient` used by generated Anthropic requests.
|
|
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
|
-
*
|
|
75
|
+
* Runs an effect with an `AnthropicConfig` override that transforms the underlying `HttpClient` used by generated Anthropic requests.
|
|
76
|
+
*
|
|
42
77
|
* @category configuration
|
|
78
|
+
* @since 4.0.0
|
|
43
79
|
*/
|
|
44
80
|
<A, E, R>(self: Effect.Effect<A, E, R>, transform: (client: HttpClient) => HttpClient): Effect.Effect<A, E, R>;
|
|
45
81
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnthropicConfig.d.ts","sourceRoot":"","sources":["../src/AnthropicConfig.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"AnthropicConfig.d.ts","sourceRoot":"","sources":["../src/AnthropicConfig.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;;AAEjE;;;;;GAKG;AACH,qBAAa,eAAgB,SAAQ,oBAGM;IACzC;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,eAAe,CAAC,OAAO,GAAG,SAAS,CAAC,CAGxF;CACF;AAED;;;;GAIG;AACH,MAAM,CAAC,OAAO,WAAW,eAAe,CAAC;IACvC;;;;;;;;;OASG;IACH,UAAiB,OAAO;QACtB,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,UAAU,KAAK,UAAU,CAAC,GAAG,SAAS,CAAA;KAC5E;CACF;AAED;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE;IAChC;;;;;OAKG;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;;;;;OAKG;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;CAQvB,CAAA"}
|
package/dist/AnthropicConfig.js
CHANGED
|
@@ -1,22 +1,46 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The `AnthropicConfig` module provides contextual configuration for the
|
|
3
|
+
* Anthropic AI provider integration. It is used to customize the generated
|
|
4
|
+
* Anthropic HTTP client without changing individual request code.
|
|
5
|
+
*
|
|
6
|
+
* **Common tasks**
|
|
7
|
+
*
|
|
8
|
+
* - Provide a shared `HttpClient` transformation for Anthropic requests
|
|
9
|
+
* - Add provider-specific concerns such as request instrumentation, proxying,
|
|
10
|
+
* retries, or header manipulation
|
|
11
|
+
* - Scope a client transformation to a single effect with {@link withClientTransform}
|
|
12
|
+
*
|
|
13
|
+
* **Gotchas**
|
|
14
|
+
*
|
|
15
|
+
* - Configuration is read from the Effect context, so overrides only apply to
|
|
16
|
+
* effects run inside the configured scope
|
|
17
|
+
* - `withClientTransform` replaces the current `transformClient` value while
|
|
18
|
+
* preserving any other Anthropic configuration fields
|
|
19
|
+
*
|
|
20
|
+
* @since 4.0.0
|
|
3
21
|
*/
|
|
22
|
+
import * as Context from "effect/Context";
|
|
4
23
|
import * as Effect from "effect/Effect";
|
|
5
24
|
import { dual } from "effect/Function";
|
|
6
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
7
25
|
/**
|
|
8
|
-
*
|
|
26
|
+
* Service tag for Anthropic client configuration overrides, such as transformations applied to the generated HTTP client.
|
|
27
|
+
*
|
|
9
28
|
* @category services
|
|
29
|
+
* @since 4.0.0
|
|
10
30
|
*/
|
|
11
|
-
export class AnthropicConfig extends /*#__PURE__*/
|
|
31
|
+
export class AnthropicConfig extends /*#__PURE__*/Context.Service()("@effect/ai-anthropic/AnthropicConfig") {
|
|
12
32
|
/**
|
|
13
|
-
*
|
|
33
|
+
* Gets the configured Anthropic service from the current context when present.
|
|
34
|
+
*
|
|
35
|
+
* @since 4.0.0
|
|
14
36
|
*/
|
|
15
|
-
static getOrUndefined = /*#__PURE__*/Effect.map(/*#__PURE__*/Effect.
|
|
37
|
+
static getOrUndefined = /*#__PURE__*/Effect.map(/*#__PURE__*/Effect.context(), services => services.mapUnsafe.get(AnthropicConfig.key));
|
|
16
38
|
}
|
|
17
39
|
/**
|
|
18
|
-
*
|
|
40
|
+
* Runs an effect with an `AnthropicConfig` override that transforms the underlying `HttpClient` used by generated Anthropic requests.
|
|
41
|
+
*
|
|
19
42
|
* @category configuration
|
|
43
|
+
* @since 4.0.0
|
|
20
44
|
*/
|
|
21
45
|
export const withClientTransform = /*#__PURE__*/dual(2, (self, transformClient) => Effect.flatMap(AnthropicConfig.getOrUndefined, config => Effect.provideService(self, AnthropicConfig, {
|
|
22
46
|
...config,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnthropicConfig.js","names":["
|
|
1
|
+
{"version":3,"file":"AnthropicConfig.js","names":["Context","Effect","dual","AnthropicConfig","Service","getOrUndefined","map","context","services","mapUnsafe","get","key","withClientTransform","self","transformClient","flatMap","config","provideService"],"sources":["../src/AnthropicConfig.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;AAqBA,OAAO,KAAKA,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,SAASC,IAAI,QAAQ,iBAAiB;AAGtC;;;;;;AAMA,OAAM,MAAOC,eAAgB,sBAAQH,OAAO,CAACI,OAAO,EAGjD,CAAC,sCAAsC,CAAC;EACzC;;;;;EAKA,OAAgBC,cAAc,gBAA8DJ,MAAM,CAACK,GAAG,cACpGL,MAAM,CAACM,OAAO,EAAS,EACtBC,QAAQ,IAAKA,QAAQ,CAACC,SAAS,CAACC,GAAG,CAACP,eAAe,CAACQ,GAAG,CAAC,CAC1D;;AAwBH;;;;;;AAMA,OAAO,MAAMC,mBAAmB,gBAkB5BV,IAAI,CAAC,CAAC,EAAE,CACVW,IAA4B,EAC5BC,eAAmD,KAEnDb,MAAM,CAACc,OAAO,CACZZ,eAAe,CAACE,cAAc,EAC7BW,MAAM,IAAKf,MAAM,CAACgB,cAAc,CAACJ,IAAI,EAAEV,eAAe,EAAE;EAAE,GAAGa,MAAM;EAAEF;AAAe,CAAE,CAAC,CACzF,CAAC","ignoreList":[]}
|