@effect/ai-anthropic 4.0.0-beta.8 → 4.0.0-beta.81
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 +93 -74
- 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 +114 -104
- 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,36 +13,23 @@ 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
|
-
readonly streamRequest: <
|
|
37
|
-
readonly id?: string | undefined;
|
|
38
|
-
readonly event: string;
|
|
39
|
-
readonly data: string;
|
|
40
|
-
}, DecodingServices>(schema: Schema.Decoder<Type, DecodingServices>) => (request: HttpClientRequest.HttpClientRequest) => Stream.Stream<Type, HttpClientError.HttpClientError | Schema.SchemaError | Sse.Retry, DecodingServices>;
|
|
30
|
+
readonly streamRequest: <S extends Sse.EventCodec>(schema: S) => (request: HttpClientRequest.HttpClientRequest) => Stream.Stream<S["Type"], HttpClientError.HttpClientError | Schema.SchemaError | Sse.Retry, S["DecodingServices"]>;
|
|
41
31
|
/**
|
|
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.
|
|
32
|
+
* Creates a message using the Anthropic Messages API and maps all errors to the unified `AiError` type.
|
|
46
33
|
*/
|
|
47
34
|
readonly createMessage: (options: {
|
|
48
35
|
readonly payload: typeof Generated.BetaCreateMessageParams.Encoded;
|
|
@@ -52,12 +39,12 @@ export interface Service {
|
|
|
52
39
|
response: HttpClientResponse.HttpClientResponse
|
|
53
40
|
], AiError.AiError>;
|
|
54
41
|
/**
|
|
55
|
-
* Creates a streaming message using the Anthropic Messages API.
|
|
42
|
+
* Creates a streaming message using the Anthropic Messages API and maps all errors to the unified `AiError` type.
|
|
43
|
+
*
|
|
44
|
+
* **Details**
|
|
56
45
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* when a `message_stop` event is received. All errors are mapped to the
|
|
60
|
-
* unified `AiError` type.
|
|
46
|
+
* The returned Effect yields the HTTP response and a stream of events as the model generates its response. The stream
|
|
47
|
+
* automatically terminates when a `message_stop` event is received.
|
|
61
48
|
*/
|
|
62
49
|
readonly createMessageStream: (options: {
|
|
63
50
|
readonly payload: Omit<typeof Generated.BetaCreateMessageParams.Encoded, "stream">;
|
|
@@ -68,8 +55,9 @@ export interface Service {
|
|
|
68
55
|
], AiError.AiError>;
|
|
69
56
|
}
|
|
70
57
|
/**
|
|
71
|
-
* Represents an event received from the Anthropic Messages API during a
|
|
72
|
-
*
|
|
58
|
+
* Represents an event received from the Anthropic Messages API during a streaming request.
|
|
59
|
+
*
|
|
60
|
+
* **Details**
|
|
73
61
|
*
|
|
74
62
|
* Events include:
|
|
75
63
|
* - `message_start`: Initial event containing message metadata
|
|
@@ -80,115 +68,146 @@ export interface Service {
|
|
|
80
68
|
* - `content_block_stop`: End of a content block
|
|
81
69
|
* - `error`: Error events with type and message
|
|
82
70
|
*
|
|
83
|
-
* @since 1.0.0
|
|
84
71
|
* @category models
|
|
72
|
+
* @since 4.0.0
|
|
85
73
|
*/
|
|
86
74
|
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:
|
|
75
|
+
declare const AnthropicClient_base: Context.ServiceClass<AnthropicClient, "@effect/ai-anthropic/AnthropicClient", Service>;
|
|
88
76
|
/**
|
|
89
|
-
* Service
|
|
77
|
+
* Service tag for the Anthropic client.
|
|
78
|
+
*
|
|
79
|
+
* **When to use**
|
|
80
|
+
*
|
|
81
|
+
* Use when accessing or providing the Anthropic client service through Effect's
|
|
82
|
+
* context.
|
|
83
|
+
*
|
|
84
|
+
* @see {@link make} for constructing an Anthropic client effectfully
|
|
85
|
+
* @see {@link layer} for providing a client from explicit options
|
|
86
|
+
* @see {@link layerConfig} for providing a client from `Config`
|
|
90
87
|
*
|
|
91
|
-
* @
|
|
92
|
-
* @
|
|
88
|
+
* @category services
|
|
89
|
+
* @since 4.0.0
|
|
93
90
|
*/
|
|
94
91
|
export declare class AnthropicClient extends AnthropicClient_base {
|
|
95
92
|
}
|
|
96
93
|
/**
|
|
97
|
-
* Configuration
|
|
94
|
+
* Configuration for creating an Anthropic client.
|
|
98
95
|
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
96
|
+
* **When to use**
|
|
97
|
+
*
|
|
98
|
+
* Use when the Anthropic client settings are already available as values and
|
|
99
|
+
* should be passed directly to `make` or `layer`.
|
|
100
|
+
*
|
|
101
|
+
* **Details**
|
|
102
|
+
*
|
|
103
|
+
* These options configure the base Anthropic URL, the `x-api-key`
|
|
104
|
+
* authentication header, the `anthropic-version` header, and an optional
|
|
105
|
+
* transformation of the underlying `HttpClient`.
|
|
106
|
+
*
|
|
107
|
+
* @see {@link make} for constructing an Anthropic client from explicit options
|
|
108
|
+
* @see {@link layer} for providing an Anthropic client from explicit options
|
|
109
|
+
* @see {@link layerConfig} for loading Anthropic client settings from `Config`
|
|
110
|
+
*
|
|
111
|
+
* @category options
|
|
112
|
+
* @since 4.0.0
|
|
101
113
|
*/
|
|
102
114
|
export type Options = {
|
|
103
115
|
/**
|
|
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).
|
|
116
|
+
* The Anthropic API key for authentication. Requests are made without authentication when this is omitted, which is
|
|
117
|
+
* useful for proxied setups or testing.
|
|
108
118
|
*/
|
|
109
119
|
readonly apiKey?: Redacted.Redacted<string> | undefined;
|
|
110
120
|
/**
|
|
111
|
-
* The base URL for the Anthropic API.
|
|
112
|
-
*
|
|
113
|
-
* Override this to use a proxy or a different API-compatible endpoint.
|
|
121
|
+
* The base URL for the Anthropic API. Override this to use a proxy or a different API-compatible endpoint.
|
|
114
122
|
*
|
|
115
123
|
* @default "https://api.anthropic.com"
|
|
116
124
|
*/
|
|
117
125
|
readonly apiUrl?: string | undefined;
|
|
118
126
|
/**
|
|
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.
|
|
127
|
+
* The Anthropic API version header value. This controls which version of the API to use.
|
|
123
128
|
*
|
|
124
129
|
* @default "2023-06-01"
|
|
125
130
|
*/
|
|
126
131
|
readonly apiVersion?: string | undefined;
|
|
127
132
|
/**
|
|
128
|
-
* Optional transformer for the underlying HTTP client
|
|
129
|
-
*
|
|
130
|
-
* Use this to add middleware, logging, or custom request/response handling.
|
|
133
|
+
* Optional transformer for the underlying HTTP client, such as middleware, logging, or custom request/response
|
|
134
|
+
* handling.
|
|
131
135
|
*/
|
|
132
136
|
readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined;
|
|
133
137
|
};
|
|
134
138
|
/**
|
|
135
139
|
* Creates an Anthropic client service with the given options.
|
|
136
140
|
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
141
|
+
* **When to use**
|
|
142
|
+
*
|
|
143
|
+
* Use when you have explicit configuration values and need an `Effect` that
|
|
144
|
+
* constructs the Anthropic client service, rather than providing it as a `Layer`.
|
|
145
|
+
*
|
|
146
|
+
* **Details**
|
|
142
147
|
*
|
|
143
|
-
*
|
|
148
|
+
* The client handles API key authentication via the `x-api-key` header, API versioning via the `anthropic-version`
|
|
149
|
+
* header, error mapping to the unified `AiError` type, and request/response transformations via `AnthropicConfig`. It
|
|
150
|
+
* requires an `HttpClient` in the context.
|
|
151
|
+
*
|
|
152
|
+
* @see {@link layer} for providing the client as a `Layer` from explicit options
|
|
153
|
+
* @see {@link layerConfig} for providing the client as a `Layer` with `Config`-based settings
|
|
144
154
|
*
|
|
145
|
-
* @since 1.0.0
|
|
146
155
|
* @category constructors
|
|
156
|
+
* @since 4.0.0
|
|
147
157
|
*/
|
|
148
158
|
export declare const make: (options: Options) => Effect.Effect<Service, never, HttpClient.HttpClient>;
|
|
149
159
|
/**
|
|
150
160
|
* Creates a layer for the Anthropic client with the given options.
|
|
151
161
|
*
|
|
152
|
-
*
|
|
162
|
+
* **When to use**
|
|
163
|
+
*
|
|
164
|
+
* Use when you already have explicit `Options` values, such as an API key or
|
|
165
|
+
* custom API URL, and want to provide `AnthropicClient` as a `Layer`.
|
|
166
|
+
*
|
|
167
|
+
* @see {@link make} for constructing the client service effectfully
|
|
168
|
+
* @see {@link layerConfig} for loading client settings from `Config`
|
|
169
|
+
*
|
|
153
170
|
* @category layers
|
|
171
|
+
* @since 4.0.0
|
|
154
172
|
*/
|
|
155
173
|
export declare const layer: (options: Options) => Layer.Layer<AnthropicClient, never, HttpClient.HttpClient>;
|
|
156
174
|
/**
|
|
157
175
|
* Creates a layer for the Anthropic client, loading the requisite configuration
|
|
158
176
|
* via Effect's `Config` module.
|
|
159
177
|
*
|
|
160
|
-
*
|
|
178
|
+
* **When to use**
|
|
179
|
+
*
|
|
180
|
+
* Use when you want to provide the Anthropic client as a `Layer` with
|
|
181
|
+
* configuration loaded from Effect's `Config` module, such as from environment
|
|
182
|
+
* variables or a secrets provider.
|
|
183
|
+
*
|
|
184
|
+
* @see {@link layer} for providing the client from explicit options instead of `Config`
|
|
185
|
+
* @see {@link make} for constructing the client service effectfully
|
|
186
|
+
*
|
|
161
187
|
* @category layers
|
|
188
|
+
* @since 4.0.0
|
|
162
189
|
*/
|
|
163
190
|
export declare const layerConfig: (options?: {
|
|
164
191
|
/**
|
|
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).
|
|
192
|
+
* The Anthropic API key for authentication. Requests are made without authentication when this is omitted, which is
|
|
193
|
+
* useful for proxied setups or testing.
|
|
169
194
|
*/
|
|
170
|
-
readonly apiKey?: Config.Config<Redacted.Redacted<string
|
|
195
|
+
readonly apiKey?: Config.Config<Redacted.Redacted<string> | undefined> | undefined;
|
|
171
196
|
/**
|
|
172
|
-
* The base URL for the Anthropic API.
|
|
173
|
-
*
|
|
174
|
-
* Override this to use a proxy or a different API-compatible endpoint.
|
|
197
|
+
* The base URL for the Anthropic API. Override this to use a proxy or a different API-compatible endpoint.
|
|
175
198
|
*
|
|
176
199
|
* @default "https://api.anthropic.com"
|
|
177
200
|
*/
|
|
178
201
|
readonly apiUrl?: Config.Config<string> | undefined;
|
|
179
202
|
/**
|
|
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.
|
|
203
|
+
* The Anthropic API version header value. This controls which version of the API to use.
|
|
184
204
|
*
|
|
185
205
|
* @default "2023-06-01"
|
|
186
206
|
*/
|
|
187
207
|
readonly apiVersion?: Config.Config<string> | undefined;
|
|
188
208
|
/**
|
|
189
|
-
* Optional transformer for the underlying HTTP client
|
|
190
|
-
*
|
|
191
|
-
* Use this to add middleware, logging, or custom request/response handling.
|
|
209
|
+
* Optional transformer for the underlying HTTP client, such as middleware, logging, or custom request/response
|
|
210
|
+
* handling.
|
|
192
211
|
*/
|
|
193
212
|
readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined;
|
|
194
213
|
}) => 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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nthropicClient.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;AAoF9C;AACA;AACA;AAEA;;;;;;;;;;;;;;;AAeA,OAAM,MAAOC,eAAgB,sBAAQh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,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":[]}
|