@effect/ai-anthropic 4.0.0-beta.8 → 4.0.0-beta.80
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 +92 -69
- package/dist/AnthropicClient.d.ts.map +1 -1
- package/dist/AnthropicClient.js +51 -19
- package/dist/AnthropicClient.js.map +1 -1
- package/dist/AnthropicConfig.d.ts +55 -10
- package/dist/AnthropicConfig.d.ts.map +1 -1
- package/dist/AnthropicConfig.js +30 -7
- package/dist/AnthropicConfig.js.map +1 -1
- package/dist/AnthropicError.d.ts +136 -37
- package/dist/AnthropicError.d.ts.map +1 -1
- package/dist/AnthropicError.js +1 -1
- package/dist/AnthropicLanguageModel.d.ts +362 -52
- package/dist/AnthropicLanguageModel.d.ts.map +1 -1
- package/dist/AnthropicLanguageModel.js +88 -21
- package/dist/AnthropicLanguageModel.js.map +1 -1
- package/dist/AnthropicTelemetry.d.ts +43 -16
- package/dist/AnthropicTelemetry.d.ts.map +1 -1
- package/dist/AnthropicTelemetry.js +15 -9
- package/dist/AnthropicTelemetry.js.map +1 -1
- package/dist/AnthropicTool.d.ts +1223 -289
- package/dist/AnthropicTool.d.ts.map +1 -1
- package/dist/AnthropicTool.js +859 -201
- package/dist/AnthropicTool.js.map +1 -1
- package/dist/Generated.d.ts +1 -1
- package/dist/Generated.js +1 -1
- package/dist/index.d.ts +8 -29
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -29
- 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 +97 -74
- package/src/AnthropicConfig.ts +56 -11
- package/src/AnthropicError.ts +138 -37
- package/src/AnthropicLanguageModel.ts +395 -43
- package/src/AnthropicTelemetry.ts +48 -22
- package/src/AnthropicTool.ts +1216 -282
- package/src/Generated.ts +1 -1
- package/src/index.ts +8 -29
- 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,146 @@ 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
|
-
* Service
|
|
81
|
+
* Service tag for the Anthropic client.
|
|
82
|
+
*
|
|
83
|
+
* **When to use**
|
|
84
|
+
*
|
|
85
|
+
* Use when accessing or providing the Anthropic client service through Effect's
|
|
86
|
+
* context.
|
|
87
|
+
*
|
|
88
|
+
* @see {@link make} for constructing an Anthropic client effectfully
|
|
89
|
+
* @see {@link layer} for providing a client from explicit options
|
|
90
|
+
* @see {@link layerConfig} for providing a client from `Config`
|
|
90
91
|
*
|
|
91
|
-
* @
|
|
92
|
-
* @
|
|
92
|
+
* @category services
|
|
93
|
+
* @since 4.0.0
|
|
93
94
|
*/
|
|
94
95
|
export declare class AnthropicClient extends AnthropicClient_base {
|
|
95
96
|
}
|
|
96
97
|
/**
|
|
97
|
-
* Configuration
|
|
98
|
+
* Configuration for creating an Anthropic client.
|
|
98
99
|
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
100
|
+
* **When to use**
|
|
101
|
+
*
|
|
102
|
+
* Use when the Anthropic client settings are already available as values and
|
|
103
|
+
* should be passed directly to `make` or `layer`.
|
|
104
|
+
*
|
|
105
|
+
* **Details**
|
|
106
|
+
*
|
|
107
|
+
* These options configure the base Anthropic URL, the `x-api-key`
|
|
108
|
+
* authentication header, the `anthropic-version` header, and an optional
|
|
109
|
+
* transformation of the underlying `HttpClient`.
|
|
110
|
+
*
|
|
111
|
+
* @see {@link make} for constructing an Anthropic client from explicit options
|
|
112
|
+
* @see {@link layer} for providing an Anthropic client from explicit options
|
|
113
|
+
* @see {@link layerConfig} for loading Anthropic client settings from `Config`
|
|
114
|
+
*
|
|
115
|
+
* @category options
|
|
116
|
+
* @since 4.0.0
|
|
101
117
|
*/
|
|
102
118
|
export type Options = {
|
|
103
119
|
/**
|
|
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).
|
|
120
|
+
* The Anthropic API key for authentication. Requests are made without authentication when this is omitted, which is
|
|
121
|
+
* useful for proxied setups or testing.
|
|
108
122
|
*/
|
|
109
123
|
readonly apiKey?: Redacted.Redacted<string> | undefined;
|
|
110
124
|
/**
|
|
111
|
-
* The base URL for the Anthropic API.
|
|
112
|
-
*
|
|
113
|
-
* Override this to use a proxy or a different API-compatible endpoint.
|
|
125
|
+
* The base URL for the Anthropic API. Override this to use a proxy or a different API-compatible endpoint.
|
|
114
126
|
*
|
|
115
127
|
* @default "https://api.anthropic.com"
|
|
116
128
|
*/
|
|
117
129
|
readonly apiUrl?: string | undefined;
|
|
118
130
|
/**
|
|
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.
|
|
131
|
+
* The Anthropic API version header value. This controls which version of the API to use.
|
|
123
132
|
*
|
|
124
133
|
* @default "2023-06-01"
|
|
125
134
|
*/
|
|
126
135
|
readonly apiVersion?: string | undefined;
|
|
127
136
|
/**
|
|
128
|
-
* Optional transformer for the underlying HTTP client
|
|
129
|
-
*
|
|
130
|
-
* Use this to add middleware, logging, or custom request/response handling.
|
|
137
|
+
* Optional transformer for the underlying HTTP client, such as middleware, logging, or custom request/response
|
|
138
|
+
* handling.
|
|
131
139
|
*/
|
|
132
140
|
readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined;
|
|
133
141
|
};
|
|
134
142
|
/**
|
|
135
143
|
* Creates an Anthropic client service with the given options.
|
|
136
144
|
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
145
|
+
* **When to use**
|
|
146
|
+
*
|
|
147
|
+
* Use when you have explicit configuration values and need an `Effect` that
|
|
148
|
+
* constructs the Anthropic client service, rather than providing it as a `Layer`.
|
|
149
|
+
*
|
|
150
|
+
* **Details**
|
|
142
151
|
*
|
|
143
|
-
*
|
|
152
|
+
* The client handles API key authentication via the `x-api-key` header, API versioning via the `anthropic-version`
|
|
153
|
+
* header, error mapping to the unified `AiError` type, and request/response transformations via `AnthropicConfig`. It
|
|
154
|
+
* requires an `HttpClient` in the context.
|
|
155
|
+
*
|
|
156
|
+
* @see {@link layer} for providing the client as a `Layer` from explicit options
|
|
157
|
+
* @see {@link layerConfig} for providing the client as a `Layer` with `Config`-based settings
|
|
144
158
|
*
|
|
145
|
-
* @since 1.0.0
|
|
146
159
|
* @category constructors
|
|
160
|
+
* @since 4.0.0
|
|
147
161
|
*/
|
|
148
162
|
export declare const make: (options: Options) => Effect.Effect<Service, never, HttpClient.HttpClient>;
|
|
149
163
|
/**
|
|
150
164
|
* Creates a layer for the Anthropic client with the given options.
|
|
151
165
|
*
|
|
152
|
-
*
|
|
166
|
+
* **When to use**
|
|
167
|
+
*
|
|
168
|
+
* Use when you already have explicit `Options` values, such as an API key or
|
|
169
|
+
* custom API URL, and want to provide `AnthropicClient` as a `Layer`.
|
|
170
|
+
*
|
|
171
|
+
* @see {@link make} for constructing the client service effectfully
|
|
172
|
+
* @see {@link layerConfig} for loading client settings from `Config`
|
|
173
|
+
*
|
|
153
174
|
* @category layers
|
|
175
|
+
* @since 4.0.0
|
|
154
176
|
*/
|
|
155
177
|
export declare const layer: (options: Options) => Layer.Layer<AnthropicClient, never, HttpClient.HttpClient>;
|
|
156
178
|
/**
|
|
157
179
|
* Creates a layer for the Anthropic client, loading the requisite configuration
|
|
158
180
|
* via Effect's `Config` module.
|
|
159
181
|
*
|
|
160
|
-
*
|
|
182
|
+
* **When to use**
|
|
183
|
+
*
|
|
184
|
+
* Use when you want to provide the Anthropic client as a `Layer` with
|
|
185
|
+
* configuration loaded from Effect's `Config` module, such as from environment
|
|
186
|
+
* variables or a secrets provider.
|
|
187
|
+
*
|
|
188
|
+
* @see {@link layer} for providing the client from explicit options instead of `Config`
|
|
189
|
+
* @see {@link make} for constructing the client service effectfully
|
|
190
|
+
*
|
|
161
191
|
* @category layers
|
|
192
|
+
* @since 4.0.0
|
|
162
193
|
*/
|
|
163
194
|
export declare const layerConfig: (options?: {
|
|
164
195
|
/**
|
|
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).
|
|
196
|
+
* The Anthropic API key for authentication. Requests are made without authentication when this is omitted, which is
|
|
197
|
+
* useful for proxied setups or testing.
|
|
169
198
|
*/
|
|
170
|
-
readonly apiKey?: Config.Config<Redacted.Redacted<string
|
|
199
|
+
readonly apiKey?: Config.Config<Redacted.Redacted<string> | undefined> | undefined;
|
|
171
200
|
/**
|
|
172
|
-
* The base URL for the Anthropic API.
|
|
173
|
-
*
|
|
174
|
-
* Override this to use a proxy or a different API-compatible endpoint.
|
|
201
|
+
* The base URL for the Anthropic API. Override this to use a proxy or a different API-compatible endpoint.
|
|
175
202
|
*
|
|
176
203
|
* @default "https://api.anthropic.com"
|
|
177
204
|
*/
|
|
178
205
|
readonly apiUrl?: Config.Config<string> | undefined;
|
|
179
206
|
/**
|
|
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.
|
|
207
|
+
* The Anthropic API version header value. This controls which version of the API to use.
|
|
184
208
|
*
|
|
185
209
|
* @default "2023-06-01"
|
|
186
210
|
*/
|
|
187
211
|
readonly apiVersion?: Config.Config<string> | undefined;
|
|
188
212
|
/**
|
|
189
|
-
* Optional transformer for the underlying HTTP client
|
|
190
|
-
*
|
|
191
|
-
* Use this to add middleware, logging, or custom request/response handling.
|
|
213
|
+
* Optional transformer for the underlying HTTP client, such as middleware, logging, or custom request/response
|
|
214
|
+
* handling.
|
|
192
215
|
*/
|
|
193
216
|
readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined;
|
|
194
217
|
}) => 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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,UAAU,CAoBvE,CAAA"}
|
package/dist/AnthropicClient.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The `AnthropicClient` module defines the low-level Effect service for
|
|
3
|
+
* Anthropic's Messages API. It builds a generated Anthropic HTTP client with
|
|
4
|
+
* authentication headers, API version headers, response decoding, and error
|
|
5
|
+
* mapping, then exposes helpers for regular and streaming message requests.
|
|
3
6
|
*
|
|
4
|
-
*
|
|
5
|
-
* messages and streaming responses.
|
|
6
|
-
*
|
|
7
|
-
* @since 1.0.0
|
|
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";
|
|
@@ -27,12 +27,21 @@ import * as Errors from "./internal/errors.js";
|
|
|
27
27
|
// Service Identifier
|
|
28
28
|
// =============================================================================
|
|
29
29
|
/**
|
|
30
|
-
* Service
|
|
30
|
+
* Service tag for the Anthropic client.
|
|
31
|
+
*
|
|
32
|
+
* **When to use**
|
|
33
|
+
*
|
|
34
|
+
* Use when accessing or providing the Anthropic client service through Effect's
|
|
35
|
+
* context.
|
|
36
|
+
*
|
|
37
|
+
* @see {@link make} for constructing an Anthropic client effectfully
|
|
38
|
+
* @see {@link layer} for providing a client from explicit options
|
|
39
|
+
* @see {@link layerConfig} for providing a client from `Config`
|
|
31
40
|
*
|
|
32
|
-
* @
|
|
33
|
-
* @
|
|
41
|
+
* @category services
|
|
42
|
+
* @since 4.0.0
|
|
34
43
|
*/
|
|
35
|
-
export class AnthropicClient extends /*#__PURE__*/
|
|
44
|
+
export class AnthropicClient extends /*#__PURE__*/Context.Service()("@effect/ai-anthropic/AnthropicClient") {}
|
|
36
45
|
// =============================================================================
|
|
37
46
|
// Constructor
|
|
38
47
|
// =============================================================================
|
|
@@ -42,16 +51,22 @@ const RedactedAnthropicHeaders = {
|
|
|
42
51
|
/**
|
|
43
52
|
* Creates an Anthropic client service with the given options.
|
|
44
53
|
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
54
|
+
* **When to use**
|
|
55
|
+
*
|
|
56
|
+
* Use when you have explicit configuration values and need an `Effect` that
|
|
57
|
+
* constructs the Anthropic client service, rather than providing it as a `Layer`.
|
|
58
|
+
*
|
|
59
|
+
* **Details**
|
|
60
|
+
*
|
|
61
|
+
* The client handles API key authentication via the `x-api-key` header, API versioning via the `anthropic-version`
|
|
62
|
+
* header, error mapping to the unified `AiError` type, and request/response transformations via `AnthropicConfig`. It
|
|
63
|
+
* requires an `HttpClient` in the context.
|
|
50
64
|
*
|
|
51
|
-
*
|
|
65
|
+
* @see {@link layer} for providing the client as a `Layer` from explicit options
|
|
66
|
+
* @see {@link layerConfig} for providing the client as a `Layer` with `Config`-based settings
|
|
52
67
|
*
|
|
53
|
-
* @since 1.0.0
|
|
54
68
|
* @category constructors
|
|
69
|
+
* @since 4.0.0
|
|
55
70
|
*/
|
|
56
71
|
export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
|
|
57
72
|
const baseClient = yield* HttpClient.HttpClient;
|
|
@@ -117,16 +132,33 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
|
|
|
117
132
|
/**
|
|
118
133
|
* Creates a layer for the Anthropic client with the given options.
|
|
119
134
|
*
|
|
120
|
-
*
|
|
135
|
+
* **When to use**
|
|
136
|
+
*
|
|
137
|
+
* Use when you already have explicit `Options` values, such as an API key or
|
|
138
|
+
* custom API URL, and want to provide `AnthropicClient` as a `Layer`.
|
|
139
|
+
*
|
|
140
|
+
* @see {@link make} for constructing the client service effectfully
|
|
141
|
+
* @see {@link layerConfig} for loading client settings from `Config`
|
|
142
|
+
*
|
|
121
143
|
* @category layers
|
|
144
|
+
* @since 4.0.0
|
|
122
145
|
*/
|
|
123
146
|
export const layer = options => Layer.effect(AnthropicClient, make(options));
|
|
124
147
|
/**
|
|
125
148
|
* Creates a layer for the Anthropic client, loading the requisite configuration
|
|
126
149
|
* via Effect's `Config` module.
|
|
127
150
|
*
|
|
128
|
-
*
|
|
151
|
+
* **When to use**
|
|
152
|
+
*
|
|
153
|
+
* Use when you want to provide the Anthropic client as a `Layer` with
|
|
154
|
+
* configuration loaded from Effect's `Config` module, such as from environment
|
|
155
|
+
* variables or a secrets provider.
|
|
156
|
+
*
|
|
157
|
+
* @see {@link layer} for providing the client from explicit options instead of `Config`
|
|
158
|
+
* @see {@link make} for constructing the client service effectfully
|
|
159
|
+
*
|
|
129
160
|
* @category layers
|
|
161
|
+
* @since 4.0.0
|
|
130
162
|
*/
|
|
131
163
|
export const layerConfig = options => Layer.effect(AnthropicClient, Effect.gen(function* () {
|
|
132
164
|
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;;;;;;;;;;;;;;;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,CAACU,MAAM,GACvB2D,SAAS;EACX,MAAM7D,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,90 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
|
+
* @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 AnthropicConfig_base:
|
|
12
|
+
declare const AnthropicConfig_base: Context.ServiceClass<AnthropicConfig, "@effect/ai-anthropic/AnthropicConfig", AnthropicConfig.Service>;
|
|
8
13
|
/**
|
|
9
|
-
*
|
|
14
|
+
* Service tag for Anthropic client configuration overrides, such as transformations applied to the generated HTTP client.
|
|
15
|
+
*
|
|
16
|
+
* **When to use**
|
|
17
|
+
*
|
|
18
|
+
* Use when you need to provide or read Anthropic client configuration through
|
|
19
|
+
* Effect's context from a layer or integration.
|
|
20
|
+
*
|
|
21
|
+
* @see {@link withClientTransform} for scoping an HTTP client transformation
|
|
22
|
+
*
|
|
10
23
|
* @category services
|
|
24
|
+
* @since 4.0.0
|
|
11
25
|
*/
|
|
12
26
|
export declare class AnthropicConfig extends AnthropicConfig_base {
|
|
13
27
|
/**
|
|
14
|
-
*
|
|
28
|
+
* Gets the configured Anthropic service from the current context when present.
|
|
29
|
+
*
|
|
30
|
+
* @since 4.0.0
|
|
15
31
|
*/
|
|
16
32
|
static readonly getOrUndefined: Effect.Effect<typeof AnthropicConfig.Service | undefined>;
|
|
17
33
|
}
|
|
18
34
|
/**
|
|
19
|
-
*
|
|
35
|
+
* Namespace containing types associated with the `AnthropicConfig` service.
|
|
36
|
+
*
|
|
37
|
+
* @since 4.0.0
|
|
20
38
|
*/
|
|
21
39
|
export declare namespace AnthropicConfig {
|
|
22
40
|
/**
|
|
23
|
-
*
|
|
41
|
+
* Configuration provided through `AnthropicConfig`.
|
|
42
|
+
*
|
|
43
|
+
* **Details**
|
|
44
|
+
*
|
|
45
|
+
* Use `transformClient` to wrap or replace the `HttpClient` used by generated Anthropic API requests.
|
|
46
|
+
*
|
|
24
47
|
* @category models
|
|
48
|
+
* @since 4.0.0
|
|
25
49
|
*/
|
|
26
50
|
interface Service {
|
|
27
51
|
readonly transformClient?: ((client: HttpClient) => HttpClient) | undefined;
|
|
28
52
|
}
|
|
29
53
|
}
|
|
30
54
|
/**
|
|
31
|
-
*
|
|
55
|
+
* Runs an effect with an `AnthropicConfig` override that transforms the underlying `HttpClient` used by generated Anthropic requests.
|
|
56
|
+
*
|
|
57
|
+
* **When to use**
|
|
58
|
+
*
|
|
59
|
+
* Use when you need to apply a temporary `HttpClient` transformation, such as adding middleware or logging, to a
|
|
60
|
+
* specific scope of an effectful program.
|
|
61
|
+
*
|
|
32
62
|
* @category configuration
|
|
63
|
+
* @since 4.0.0
|
|
33
64
|
*/
|
|
34
65
|
export declare const withClientTransform: {
|
|
35
66
|
/**
|
|
36
|
-
*
|
|
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
|
+
*
|
|
37
74
|
* @category configuration
|
|
75
|
+
* @since 4.0.0
|
|
38
76
|
*/
|
|
39
77
|
(transform: (client: HttpClient) => HttpClient): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
40
78
|
/**
|
|
41
|
-
*
|
|
79
|
+
* Runs an effect with an `AnthropicConfig` override that transforms the underlying `HttpClient` used by generated Anthropic requests.
|
|
80
|
+
*
|
|
81
|
+
* **When to use**
|
|
82
|
+
*
|
|
83
|
+
* Use when you need to apply a temporary `HttpClient` transformation, such as adding middleware or logging, to a
|
|
84
|
+
* specific scope of an effectful program.
|
|
85
|
+
*
|
|
42
86
|
* @category configuration
|
|
87
|
+
* @since 4.0.0
|
|
43
88
|
*/
|
|
44
89
|
<A, E, R>(self: Effect.Effect<A, E, R>, transform: (client: HttpClient) => HttpClient): Effect.Effect<A, E, R>;
|
|
45
90
|
};
|
|
@@ -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;;;;;;;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;;;;;;;;;;;;GAYG;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;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,EAAE;IAChC;;;;;;;;;;OAUG;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;;;;;;;;;;OAUG;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,45 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
|
+
* @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
|
+
* Service tag for Anthropic client configuration overrides, such as transformations applied to the generated HTTP client.
|
|
14
|
+
*
|
|
15
|
+
* **When to use**
|
|
16
|
+
*
|
|
17
|
+
* Use when you need to provide or read Anthropic client configuration through
|
|
18
|
+
* Effect's context from a layer or integration.
|
|
19
|
+
*
|
|
20
|
+
* @see {@link withClientTransform} for scoping an HTTP client transformation
|
|
21
|
+
*
|
|
9
22
|
* @category services
|
|
23
|
+
* @since 4.0.0
|
|
10
24
|
*/
|
|
11
|
-
export class AnthropicConfig extends /*#__PURE__*/
|
|
25
|
+
export class AnthropicConfig extends /*#__PURE__*/Context.Service()("@effect/ai-anthropic/AnthropicConfig") {
|
|
12
26
|
/**
|
|
13
|
-
*
|
|
27
|
+
* Gets the configured Anthropic service from the current context when present.
|
|
28
|
+
*
|
|
29
|
+
* @since 4.0.0
|
|
14
30
|
*/
|
|
15
|
-
static getOrUndefined = /*#__PURE__*/Effect.map(/*#__PURE__*/Effect.
|
|
31
|
+
static getOrUndefined = /*#__PURE__*/Effect.map(/*#__PURE__*/Effect.context(), services => services.mapUnsafe.get(AnthropicConfig.key));
|
|
16
32
|
}
|
|
17
33
|
/**
|
|
18
|
-
*
|
|
34
|
+
* Runs an effect with an `AnthropicConfig` override that transforms the underlying `HttpClient` used by generated Anthropic requests.
|
|
35
|
+
*
|
|
36
|
+
* **When to use**
|
|
37
|
+
*
|
|
38
|
+
* Use when you need to apply a temporary `HttpClient` transformation, such as adding middleware or logging, to a
|
|
39
|
+
* specific scope of an effectful program.
|
|
40
|
+
*
|
|
19
41
|
* @category configuration
|
|
42
|
+
* @since 4.0.0
|
|
20
43
|
*/
|
|
21
44
|
export const withClientTransform = /*#__PURE__*/dual(2, (self, transformClient) => Effect.flatMap(AnthropicConfig.getOrUndefined, config => Effect.provideService(self, AnthropicConfig, {
|
|
22
45
|
...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;;;;;;;;AAQA,OAAO,KAAKA,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,SAASC,IAAI,QAAQ,iBAAiB;AAGtC;;;;;;;;;;;;;AAaA,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;;;;;;;;;;;AAWA,OAAO,MAAMC,mBAAmB,gBA4B5BV,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":[]}
|