@effect/ai-anthropic 0.22.0 → 4.0.0-beta.0

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.
Files changed (104) hide show
  1. package/dist/AnthropicClient.d.ts +196 -0
  2. package/dist/AnthropicClient.d.ts.map +1 -0
  3. package/dist/AnthropicClient.js +142 -0
  4. package/dist/AnthropicClient.js.map +1 -0
  5. package/dist/{dts/AnthropicConfig.d.ts → AnthropicConfig.d.ts} +9 -9
  6. package/dist/AnthropicConfig.d.ts.map +1 -0
  7. package/dist/{esm/AnthropicConfig.js → AnthropicConfig.js} +8 -5
  8. package/dist/AnthropicConfig.js.map +1 -0
  9. package/dist/AnthropicError.d.ts +102 -0
  10. package/dist/AnthropicError.d.ts.map +1 -0
  11. package/dist/AnthropicError.js +10 -0
  12. package/dist/AnthropicError.js.map +1 -0
  13. package/dist/AnthropicLanguageModel.d.ts +522 -0
  14. package/dist/AnthropicLanguageModel.d.ts.map +1 -0
  15. package/dist/AnthropicLanguageModel.js +2107 -0
  16. package/dist/AnthropicLanguageModel.js.map +1 -0
  17. package/dist/AnthropicTelemetry.d.ts +101 -0
  18. package/dist/AnthropicTelemetry.d.ts.map +1 -0
  19. package/dist/AnthropicTelemetry.js +35 -0
  20. package/dist/AnthropicTelemetry.js.map +1 -0
  21. package/dist/AnthropicTool.d.ts +2153 -0
  22. package/dist/AnthropicTool.d.ts.map +1 -0
  23. package/dist/AnthropicTool.js +1168 -0
  24. package/dist/AnthropicTool.js.map +1 -0
  25. package/dist/Generated.d.ts +25233 -0
  26. package/dist/Generated.d.ts.map +1 -0
  27. package/dist/Generated.js +7649 -0
  28. package/dist/Generated.js.map +1 -0
  29. package/dist/index.d.ts +53 -0
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +54 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/internal/errors.d.ts +2 -0
  34. package/dist/internal/errors.d.ts.map +1 -0
  35. package/dist/internal/errors.js +344 -0
  36. package/dist/internal/errors.js.map +1 -0
  37. package/dist/{dts/internal → internal}/utilities.d.ts.map +1 -1
  38. package/dist/internal/utilities.js.map +1 -0
  39. package/package.json +45 -81
  40. package/src/AnthropicClient.ts +327 -683
  41. package/src/AnthropicConfig.ts +20 -34
  42. package/src/AnthropicError.ts +111 -0
  43. package/src/AnthropicLanguageModel.ts +2039 -993
  44. package/src/AnthropicTelemetry.ts +138 -0
  45. package/src/AnthropicTool.ts +1500 -475
  46. package/src/Generated.ts +9798 -6359
  47. package/src/index.ts +38 -6
  48. package/src/internal/errors.ts +368 -0
  49. package/src/internal/utilities.ts +1 -1
  50. package/AnthropicClient/package.json +0 -6
  51. package/AnthropicConfig/package.json +0 -6
  52. package/AnthropicLanguageModel/package.json +0 -6
  53. package/AnthropicTokenizer/package.json +0 -6
  54. package/AnthropicTool/package.json +0 -6
  55. package/Generated/package.json +0 -6
  56. package/README.md +0 -5
  57. package/dist/cjs/AnthropicClient.js +0 -344
  58. package/dist/cjs/AnthropicClient.js.map +0 -1
  59. package/dist/cjs/AnthropicConfig.js +0 -30
  60. package/dist/cjs/AnthropicConfig.js.map +0 -1
  61. package/dist/cjs/AnthropicLanguageModel.js +0 -1322
  62. package/dist/cjs/AnthropicLanguageModel.js.map +0 -1
  63. package/dist/cjs/AnthropicTokenizer.js +0 -52
  64. package/dist/cjs/AnthropicTokenizer.js.map +0 -1
  65. package/dist/cjs/AnthropicTool.js +0 -461
  66. package/dist/cjs/AnthropicTool.js.map +0 -1
  67. package/dist/cjs/Generated.js +0 -6578
  68. package/dist/cjs/Generated.js.map +0 -1
  69. package/dist/cjs/index.js +0 -20
  70. package/dist/cjs/index.js.map +0 -1
  71. package/dist/cjs/internal/utilities.js +0 -29
  72. package/dist/cjs/internal/utilities.js.map +0 -1
  73. package/dist/dts/AnthropicClient.d.ts +0 -730
  74. package/dist/dts/AnthropicClient.d.ts.map +0 -1
  75. package/dist/dts/AnthropicConfig.d.ts.map +0 -1
  76. package/dist/dts/AnthropicLanguageModel.d.ts +0 -304
  77. package/dist/dts/AnthropicLanguageModel.d.ts.map +0 -1
  78. package/dist/dts/AnthropicTokenizer.d.ts +0 -13
  79. package/dist/dts/AnthropicTokenizer.d.ts.map +0 -1
  80. package/dist/dts/AnthropicTool.d.ts +0 -548
  81. package/dist/dts/AnthropicTool.d.ts.map +0 -1
  82. package/dist/dts/Generated.d.ts +0 -12504
  83. package/dist/dts/Generated.d.ts.map +0 -1
  84. package/dist/dts/index.d.ts +0 -25
  85. package/dist/dts/index.d.ts.map +0 -1
  86. package/dist/esm/AnthropicClient.js +0 -317
  87. package/dist/esm/AnthropicClient.js.map +0 -1
  88. package/dist/esm/AnthropicConfig.js.map +0 -1
  89. package/dist/esm/AnthropicLanguageModel.js +0 -1309
  90. package/dist/esm/AnthropicLanguageModel.js.map +0 -1
  91. package/dist/esm/AnthropicTokenizer.js +0 -44
  92. package/dist/esm/AnthropicTokenizer.js.map +0 -1
  93. package/dist/esm/AnthropicTool.js +0 -452
  94. package/dist/esm/AnthropicTool.js.map +0 -1
  95. package/dist/esm/Generated.js +0 -6247
  96. package/dist/esm/Generated.js.map +0 -1
  97. package/dist/esm/index.js +0 -25
  98. package/dist/esm/index.js.map +0 -1
  99. package/dist/esm/internal/utilities.js.map +0 -1
  100. package/dist/esm/package.json +0 -4
  101. package/index/package.json +0 -6
  102. package/src/AnthropicTokenizer.ts +0 -59
  103. /package/dist/{dts/internal → internal}/utilities.d.ts +0 -0
  104. /package/dist/{esm/internal → internal}/utilities.js +0 -0
@@ -0,0 +1,196 @@
1
+ import type * as Config from "effect/Config";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Layer from "effect/Layer";
4
+ import * as Redacted from "effect/Redacted";
5
+ import * as Schema from "effect/Schema";
6
+ import * as ServiceMap from "effect/ServiceMap";
7
+ import * as Stream from "effect/Stream";
8
+ import type * as AiError from "effect/unstable/ai/AiError";
9
+ import * as Sse from "effect/unstable/encoding/Sse";
10
+ import * as HttpClient from "effect/unstable/http/HttpClient";
11
+ import type * as HttpClientError from "effect/unstable/http/HttpClientError";
12
+ import * as HttpClientRequest from "effect/unstable/http/HttpClientRequest";
13
+ import type * as HttpClientResponse from "effect/unstable/http/HttpClientResponse";
14
+ import * as Generated from "./Generated.ts";
15
+ /**
16
+ * The Anthropic client service interface.
17
+ *
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
+ * @category models
23
+ */
24
+ export interface Service {
25
+ /**
26
+ * The underlying generated Anthropic client providing access to all API
27
+ * endpoints.
28
+ */
29
+ readonly client: Generated.AnthropicClient;
30
+ /**
31
+ * Low-level streaming request helper for custom SSE endpoints.
32
+ *
33
+ * Executes an HTTP request and decodes the Server-Sent Events response
34
+ * using the provided schema.
35
+ */
36
+ readonly streamRequest: <Type extends {
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>;
41
+ /**
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.
46
+ */
47
+ readonly createMessage: (options: {
48
+ readonly payload: typeof Generated.BetaCreateMessageParams.Encoded;
49
+ readonly params?: typeof Generated.BetaMessagesPostParams.Encoded | undefined;
50
+ }) => Effect.Effect<[
51
+ body: typeof Generated.BetaMessage.Type,
52
+ response: HttpClientResponse.HttpClientResponse
53
+ ], AiError.AiError>;
54
+ /**
55
+ * Creates a streaming message using the Anthropic Messages API.
56
+ *
57
+ * Returns an Effect that yields the HTTP response and a stream of events
58
+ * as the model generates its response. The stream automatically terminates
59
+ * when a `message_stop` event is received. All errors are mapped to the
60
+ * unified `AiError` type.
61
+ */
62
+ readonly createMessageStream: (options: {
63
+ readonly payload: Omit<typeof Generated.BetaCreateMessageParams.Encoded, "stream">;
64
+ readonly params?: typeof Generated.BetaMessagesPostParams.Encoded | undefined;
65
+ }) => Effect.Effect<[
66
+ response: HttpClientResponse.HttpClientResponse,
67
+ stream: Stream.Stream<MessageStreamEvent, AiError.AiError>
68
+ ], AiError.AiError>;
69
+ }
70
+ /**
71
+ * Represents an event received from the Anthropic Messages API during a
72
+ * streaming request.
73
+ *
74
+ * Events include:
75
+ * - `message_start`: Initial event containing message metadata
76
+ * - `message_delta`: Incremental updates to the message (e.g., stop reason)
77
+ * - `message_stop`: Final event indicating the message is complete
78
+ * - `content_block_start`: Start of a content block
79
+ * - `content_block_delta`: Incremental content updates (text, tool use, etc.)
80
+ * - `content_block_stop`: End of a content block
81
+ * - `error`: Error events with type and message
82
+ *
83
+ * @since 1.0.0
84
+ * @category models
85
+ */
86
+ 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: ServiceMap.ServiceClass<AnthropicClient, "@effect/ai-anthropic/AnthropicClient", Service>;
88
+ /**
89
+ * Service identifier for the Anthropic client.
90
+ *
91
+ * @since 1.0.0
92
+ * @category service
93
+ */
94
+ export declare class AnthropicClient extends AnthropicClient_base {
95
+ }
96
+ /**
97
+ * Configuration options for creating an Anthropic client.
98
+ *
99
+ * @since 1.0.0
100
+ * @category models
101
+ */
102
+ export type Options = {
103
+ /**
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).
108
+ */
109
+ readonly apiKey?: Redacted.Redacted<string> | undefined;
110
+ /**
111
+ * The base URL for the Anthropic API.
112
+ *
113
+ * Override this to use a proxy or a different API-compatible endpoint.
114
+ *
115
+ * @default "https://api.anthropic.com"
116
+ */
117
+ readonly apiUrl?: string | undefined;
118
+ /**
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.
123
+ *
124
+ * @default "2023-06-01"
125
+ */
126
+ readonly apiVersion?: string | undefined;
127
+ /**
128
+ * Optional transformer for the underlying HTTP client.
129
+ *
130
+ * Use this to add middleware, logging, or custom request/response handling.
131
+ */
132
+ readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined;
133
+ };
134
+ /**
135
+ * Creates an Anthropic client service with the given options.
136
+ *
137
+ * The client automatically handles:
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`
142
+ *
143
+ * Requires an `HttpClient` in the context.
144
+ *
145
+ * @since 1.0.0
146
+ * @category constructors
147
+ */
148
+ export declare const make: (options: Options) => Effect.Effect<Service, never, HttpClient.HttpClient>;
149
+ /**
150
+ * Creates a layer for the Anthropic client with the given options.
151
+ *
152
+ * @since 1.0.0
153
+ * @category layers
154
+ */
155
+ export declare const layer: (options: Options) => Layer.Layer<AnthropicClient, never, HttpClient.HttpClient>;
156
+ /**
157
+ * Creates a layer for the Anthropic client, loading the requisite configuration
158
+ * via Effect's `Config` module.
159
+ *
160
+ * @since 1.0.0
161
+ * @category layers
162
+ */
163
+ export declare const layerConfig: (options?: {
164
+ /**
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).
169
+ */
170
+ readonly apiKey?: Config.Config<Redacted.Redacted<string>> | undefined;
171
+ /**
172
+ * The base URL for the Anthropic API.
173
+ *
174
+ * Override this to use a proxy or a different API-compatible endpoint.
175
+ *
176
+ * @default "https://api.anthropic.com"
177
+ */
178
+ readonly apiUrl?: Config.Config<string> | undefined;
179
+ /**
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.
184
+ *
185
+ * @default "2023-06-01"
186
+ */
187
+ readonly apiVersion?: Config.Config<string> | undefined;
188
+ /**
189
+ * Optional transformer for the underlying HTTP client.
190
+ *
191
+ * Use this to add middleware, logging, or custom request/response handling.
192
+ */
193
+ readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined;
194
+ }) => Layer.Layer<AnthropicClient, Config.ConfigError, HttpClient.HttpClient>;
195
+ export {};
196
+ //# sourceMappingURL=AnthropicClient.d.ts.map
@@ -0,0 +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,UAAU,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,OAAO,MAAM,4BAA4B,CAAA;AAC1D,OAAO,KAAK,GAAG,MAAM,8BAA8B,CAAA;AAGnD,OAAO,KAAK,UAAU,MAAM,iCAAiC,CAAA;AAC7D,OAAO,KAAK,KAAK,eAAe,MAAM,sCAAsC,CAAA;AAC5E,OAAO,KAAK,iBAAiB,MAAM,wCAAwC,CAAA;AAC3E,OAAO,KAAK,KAAK,kBAAkB,MAAM,yCAAyC,CAAA;AAElF,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAO3C;;;;;;;;GAQG;AACH,MAAM,WAAW,OAAO;IACtB;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC,eAA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,UAAU,CAAC,UAAU,CACpD,CAAA;AAE9C;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,UAAU;IACpC;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAAA;IAEtE;;;;;;OAMG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,SAAS,CAAA;IAEnD;;;;;;;OAOG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,SAAS,CAAA;IAEvD;;;;OAIG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,UAAU,KAAK,UAAU,CAAC,UAAU,CAAC,GAAG,SAAS,CAAA;CAClG,KAAG,KAAK,CAAC,KAAK,CAAC,eAAe,EAAE,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,UAAU,CAoBvE,CAAA"}
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Anthropic Client module for interacting with Anthropic's API.
3
+ *
4
+ * Provides a type-safe, Effect-based client for Anthropic operations including
5
+ * messages and streaming responses.
6
+ *
7
+ * @since 1.0.0
8
+ */
9
+ import * as Array from "effect/Array";
10
+ import * as Effect from "effect/Effect";
11
+ import { identity } from "effect/Function";
12
+ import * as Layer from "effect/Layer";
13
+ import * as Predicate from "effect/Predicate";
14
+ import * as Redacted from "effect/Redacted";
15
+ import * as Schema from "effect/Schema";
16
+ import * as ServiceMap from "effect/ServiceMap";
17
+ import * as Stream from "effect/Stream";
18
+ import * as Sse from "effect/unstable/encoding/Sse";
19
+ import * as Headers from "effect/unstable/http/Headers";
20
+ import * as HttpBody from "effect/unstable/http/HttpBody";
21
+ import * as HttpClient from "effect/unstable/http/HttpClient";
22
+ import * as HttpClientRequest from "effect/unstable/http/HttpClientRequest";
23
+ import { AnthropicConfig } from "./AnthropicConfig.js";
24
+ import * as Generated from "./Generated.js";
25
+ import * as Errors from "./internal/errors.js";
26
+ // =============================================================================
27
+ // Service Identifier
28
+ // =============================================================================
29
+ /**
30
+ * Service identifier for the Anthropic client.
31
+ *
32
+ * @since 1.0.0
33
+ * @category service
34
+ */
35
+ export class AnthropicClient extends /*#__PURE__*/ServiceMap.Service()("@effect/ai-anthropic/AnthropicClient") {}
36
+ // =============================================================================
37
+ // Constructor
38
+ // =============================================================================
39
+ const RedactedAnthropicHeaders = {
40
+ AnthropicApiKey: "x-api-key"
41
+ };
42
+ /**
43
+ * Creates an Anthropic client service with the given options.
44
+ *
45
+ * The client automatically handles:
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`
50
+ *
51
+ * Requires an `HttpClient` in the context.
52
+ *
53
+ * @since 1.0.0
54
+ * @category constructors
55
+ */
56
+ export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
57
+ const baseClient = yield* HttpClient.HttpClient;
58
+ const apiVersion = options.apiVersion ?? "2023-06-01";
59
+ const httpClient = baseClient.pipe(HttpClient.mapRequest(request => request.pipe(HttpClientRequest.prependUrl(options.apiUrl ?? "https://api.anthropic.com"), Predicate.isNotUndefined(options.apiKey) ? HttpClientRequest.setHeader(RedactedAnthropicHeaders.AnthropicApiKey, Redacted.value(options.apiKey)) : identity, HttpClientRequest.setHeader("anthropic-version", apiVersion), HttpClientRequest.acceptJson)), Predicate.isNotUndefined(options.transformClient) ? options.transformClient : identity);
60
+ const client = Generated.make(httpClient, {
61
+ transformClient: Effect.fnUntraced(function* (client) {
62
+ const config = yield* AnthropicConfig.getOrUndefined;
63
+ if (Predicate.isNotUndefined(config?.transformClient)) {
64
+ return config.transformClient(client);
65
+ }
66
+ return client;
67
+ })
68
+ });
69
+ const httpClientOk = HttpClient.filterStatusOk(httpClient);
70
+ const streamRequest = schema => request => httpClientOk.execute(request).pipe(Effect.map(response => response.stream), Stream.unwrap, Stream.decodeText, Stream.pipeThroughChannel(Sse.decodeSchema(schema)));
71
+ const createMessage = options => client.betaMessagesPost({
72
+ ...options,
73
+ config: {
74
+ includeResponse: true
75
+ }
76
+ }).pipe(Effect.catchTags({
77
+ BetaMessagesPost4XX: error => Effect.fail(Errors.mapClientError(error, "createMessage")),
78
+ HttpClientError: error => Errors.mapHttpClientError(error, "createMessage"),
79
+ SchemaError: error => Effect.fail(Errors.mapSchemaError(error, "createMessage"))
80
+ }));
81
+ const PingEvent = Schema.Struct({
82
+ type: Schema.Literal("ping")
83
+ });
84
+ const MessageEvent = Schema.Union([PingEvent, Generated.BetaMessageStartEvent, Generated.BetaMessageDeltaEvent, Generated.BetaMessageStopEvent, Generated.BetaContentBlockStartEvent, Generated.BetaContentBlockDeltaEvent, Generated.BetaContentBlockStopEvent, Generated.BetaErrorResponse]);
85
+ const buildMessageStream = response => {
86
+ const stream = response.stream.pipe(Stream.decodeText, Stream.pipeThroughChannel(Sse.decodeDataSchema(MessageEvent)), Stream.takeUntil(event => event.data.type === "message_stop"), Stream.map(event => event.data), Stream.filter(event => event.type !== "ping"), Stream.catchTags({
87
+ // TODO: handle SSE retries
88
+ Retry: error => Stream.die(error),
89
+ HttpClientError: error => Stream.fromEffect(Errors.mapHttpClientError(error, "createMessageStream")),
90
+ SchemaError: error => Stream.fail(Errors.mapSchemaError(error, "createMessageStream"))
91
+ }));
92
+ return [response, stream];
93
+ };
94
+ const createMessageStream = options => {
95
+ const request = HttpClientRequest.post("/v1/messages", {
96
+ headers: Headers.fromInput({
97
+ "anthropic-beta": options.params?.["anthropic-beta"] ?? undefined,
98
+ "anthropic-version": options.params?.["anthropic-version"] ?? apiVersion
99
+ }),
100
+ body: HttpBody.jsonUnsafe({
101
+ ...options.payload,
102
+ stream: true
103
+ })
104
+ });
105
+ return httpClientOk.execute(request).pipe(Effect.map(buildMessageStream), Effect.catchTag("HttpClientError", error => Errors.mapHttpClientError(error, "createMessageStream")));
106
+ };
107
+ return AnthropicClient.of({
108
+ client,
109
+ streamRequest,
110
+ createMessage,
111
+ createMessageStream
112
+ });
113
+ }, /*#__PURE__*/Effect.updateService(Headers.CurrentRedactedNames, /*#__PURE__*/Array.appendAll(/*#__PURE__*/Object.values(RedactedAnthropicHeaders))));
114
+ // =============================================================================
115
+ // Layers
116
+ // =============================================================================
117
+ /**
118
+ * Creates a layer for the Anthropic client with the given options.
119
+ *
120
+ * @since 1.0.0
121
+ * @category layers
122
+ */
123
+ export const layer = options => Layer.effect(AnthropicClient, make(options));
124
+ /**
125
+ * Creates a layer for the Anthropic client, loading the requisite configuration
126
+ * via Effect's `Config` module.
127
+ *
128
+ * @since 1.0.0
129
+ * @category layers
130
+ */
131
+ export const layerConfig = options => Layer.effect(AnthropicClient, Effect.gen(function* () {
132
+ const apiKey = Predicate.isNotUndefined(options?.apiKey) ? yield* options.apiKey : undefined;
133
+ const apiUrl = Predicate.isNotUndefined(options?.apiUrl) ? yield* options.apiUrl : undefined;
134
+ const apiVersion = Predicate.isNotUndefined(options?.apiVersion) ? yield* options.apiVersion : undefined;
135
+ return yield* make({
136
+ apiKey,
137
+ apiUrl,
138
+ apiVersion,
139
+ transformClient: options?.transformClient
140
+ });
141
+ }));
142
+ //# sourceMappingURL=AnthropicClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnthropicClient.js","names":["Array","Effect","identity","Layer","Predicate","Redacted","Schema","ServiceMap","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,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,UAAU,MAAM,mBAAmB;AAC/C,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;AAmG9C;AACA;AACA;AAEA;;;;;;AAMA,OAAM,MAAOC,eAAgB,sBAAQV,UAAU,CAACW,OAAO,EAA4B,CACjF,sCAAsC,CACv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,GACpD,OAAOR,OAAO,CAACQ,MAAM,GACvB6D,SAAS;EACX,MAAMnE,UAAU,GAAGrB,SAAS,CAAC4B,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,13 +1,13 @@
1
1
  /**
2
2
  * @since 1.0.0
3
3
  */
4
- import type { HttpClient } from "@effect/platform/HttpClient";
5
- import * as Context from "effect/Context";
6
4
  import * as Effect from "effect/Effect";
7
- declare const AnthropicConfig_base: Context.TagClass<AnthropicConfig, "@effect/ai-anthropic/AnthropicConfig", AnthropicConfig.Service>;
5
+ import * as ServiceMap from "effect/ServiceMap";
6
+ import type { HttpClient } from "effect/unstable/http/HttpClient";
7
+ declare const AnthropicConfig_base: ServiceMap.ServiceClass<AnthropicConfig, "@effect/ai-anthropic/AnthropicConfig", AnthropicConfig.Service>;
8
8
  /**
9
9
  * @since 1.0.0
10
- * @category Context
10
+ * @category services
11
11
  */
12
12
  export declare class AnthropicConfig extends AnthropicConfig_base {
13
13
  /**
@@ -21,25 +21,25 @@ export declare class AnthropicConfig extends AnthropicConfig_base {
21
21
  export declare namespace AnthropicConfig {
22
22
  /**
23
23
  * @since 1.0.0
24
- * @category Models
24
+ * @category models
25
25
  */
26
26
  interface Service {
27
- readonly transformClient?: (client: HttpClient) => HttpClient;
27
+ readonly transformClient?: ((client: HttpClient) => HttpClient) | undefined;
28
28
  }
29
29
  }
30
30
  /**
31
31
  * @since 1.0.0
32
- * @category Configuration
32
+ * @category configuration
33
33
  */
34
34
  export declare const withClientTransform: {
35
35
  /**
36
36
  * @since 1.0.0
37
- * @category Configuration
37
+ * @category configuration
38
38
  */
39
39
  (transform: (client: HttpClient) => HttpClient): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
40
40
  /**
41
41
  * @since 1.0.0
42
- * @category Configuration
42
+ * @category configuration
43
43
  */
44
44
  <A, E, R>(self: Effect.Effect<A, E, R>, transform: (client: HttpClient) => HttpClient): Effect.Effect<A, E, R>;
45
45
  };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnthropicConfig.d.ts","sourceRoot":"","sources":["../src/AnthropicConfig.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;;AAEjE;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,oBAGM;IACzC;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,eAAe,CAAC,OAAO,GAAG,SAAS,CAAC,CAGxF;CACF;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,WAAW,eAAe,CAAC;IACvC;;;OAGG;IACH,UAAiB,OAAO;QACtB,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,UAAU,KAAK,UAAU,CAAC,GAAG,SAAS,CAAA;KAC5E;CACF;AAED;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE;IAChC;;;OAGG;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;;;OAGG;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"}
@@ -1,19 +1,22 @@
1
- import * as Context from "effect/Context";
1
+ /**
2
+ * @since 1.0.0
3
+ */
2
4
  import * as Effect from "effect/Effect";
3
5
  import { dual } from "effect/Function";
6
+ import * as ServiceMap from "effect/ServiceMap";
4
7
  /**
5
8
  * @since 1.0.0
6
- * @category Context
9
+ * @category services
7
10
  */
8
- export class AnthropicConfig extends /*#__PURE__*/Context.Tag("@effect/ai-anthropic/AnthropicConfig")() {
11
+ export class AnthropicConfig extends /*#__PURE__*/ServiceMap.Service()("@effect/ai-anthropic/AnthropicConfig") {
9
12
  /**
10
13
  * @since 1.0.0
11
14
  */
12
- static getOrUndefined = /*#__PURE__*/Effect.map(/*#__PURE__*/Effect.context(), context => context.unsafeMap.get(AnthropicConfig.key));
15
+ static getOrUndefined = /*#__PURE__*/Effect.map(/*#__PURE__*/Effect.services(), services => services.mapUnsafe.get(AnthropicConfig.key));
13
16
  }
14
17
  /**
15
18
  * @since 1.0.0
16
- * @category Configuration
19
+ * @category configuration
17
20
  */
18
21
  export const withClientTransform = /*#__PURE__*/dual(2, (self, transformClient) => Effect.flatMap(AnthropicConfig.getOrUndefined, config => Effect.provideService(self, AnthropicConfig, {
19
22
  ...config,
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnthropicConfig.js","names":["Effect","dual","ServiceMap","AnthropicConfig","Service","getOrUndefined","map","services","mapUnsafe","get","key","withClientTransform","self","transformClient","flatMap","config","provideService"],"sources":["../src/AnthropicConfig.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,MAAM,MAAM,eAAe;AACvC,SAASC,IAAI,QAAQ,iBAAiB;AACtC,OAAO,KAAKC,UAAU,MAAM,mBAAmB;AAG/C;;;;AAIA,OAAM,MAAOC,eAAgB,sBAAQD,UAAU,CAACE,OAAO,EAGpD,CAAC,sCAAsC,CAAC;EACzC;;;EAGA,OAAgBC,cAAc,gBAA8DL,MAAM,CAACM,GAAG,cACpGN,MAAM,CAACO,QAAQ,EAAS,EACvBA,QAAQ,IAAKA,QAAQ,CAACC,SAAS,CAACC,GAAG,CAACN,eAAe,CAACO,GAAG,CAAC,CAC1D;;AAgBH;;;;AAIA,OAAO,MAAMC,mBAAmB,gBAc5BV,IAAI,CAAC,CAAC,EAAE,CACVW,IAA4B,EAC5BC,eAAmD,KAEnDb,MAAM,CAACc,OAAO,CACZX,eAAe,CAACE,cAAc,EAC7BU,MAAM,IAAKf,MAAM,CAACgB,cAAc,CAACJ,IAAI,EAAET,eAAe,EAAE;EAAE,GAAGY,MAAM;EAAEF;AAAe,CAAE,CAAC,CACzF,CAAC","ignoreList":[]}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Anthropic error metadata augmentation.
3
+ *
4
+ * Provides Anthropic-specific metadata fields for AI error types through module
5
+ * augmentation, enabling typed access to Anthropic error details.
6
+ *
7
+ * @since 1.0.0
8
+ */
9
+ /**
10
+ * Anthropic-specific error metadata fields.
11
+ *
12
+ * @since 1.0.0
13
+ * @category models
14
+ */
15
+ export type AnthropicErrorMetadata = {
16
+ /**
17
+ * The Anthropic error type returned by the API.
18
+ */
19
+ readonly errorType: string | null;
20
+ /**
21
+ * The unique request ID for debugging with Anthropic support.
22
+ */
23
+ readonly requestId: string | null;
24
+ };
25
+ /**
26
+ * Anthropic-specific rate limit metadata fields.
27
+ *
28
+ * Extends base error metadata with rate limit specific information from
29
+ * Anthropic's rate limit headers.
30
+ *
31
+ * @since 1.0.0
32
+ * @category models
33
+ */
34
+ export type AnthropicRateLimitMetadata = AnthropicErrorMetadata & {
35
+ /**
36
+ * Number of requests allowed in the current period.
37
+ */
38
+ readonly requestsLimit: number | null;
39
+ /**
40
+ * Number of requests remaining in the current period.
41
+ */
42
+ readonly requestsRemaining: number | null;
43
+ /**
44
+ * Time when the request rate limit resets.
45
+ */
46
+ readonly requestsReset: string | null;
47
+ /**
48
+ * Number of tokens allowed in the current period.
49
+ */
50
+ readonly tokensLimit: number | null;
51
+ /**
52
+ * Number of tokens remaining in the current period.
53
+ */
54
+ readonly tokensRemaining: number | null;
55
+ /**
56
+ * Time when the token rate limit resets.
57
+ */
58
+ readonly tokensReset: string | null;
59
+ };
60
+ declare module "effect/unstable/ai/AiError" {
61
+ interface RateLimitError {
62
+ readonly metadata: {
63
+ readonly anthropic?: AnthropicRateLimitMetadata | null;
64
+ };
65
+ }
66
+ interface QuotaExhaustedError {
67
+ readonly metadata: {
68
+ readonly anthropic?: AnthropicErrorMetadata | null;
69
+ };
70
+ }
71
+ interface AuthenticationError {
72
+ readonly metadata: {
73
+ readonly anthropic?: AnthropicErrorMetadata | null;
74
+ };
75
+ }
76
+ interface ContentPolicyError {
77
+ readonly metadata: {
78
+ readonly anthropic?: AnthropicErrorMetadata | null;
79
+ };
80
+ }
81
+ interface InvalidRequestError {
82
+ readonly metadata: {
83
+ readonly anthropic?: AnthropicErrorMetadata | null;
84
+ };
85
+ }
86
+ interface InternalProviderError {
87
+ readonly metadata: {
88
+ readonly anthropic?: AnthropicErrorMetadata | null;
89
+ };
90
+ }
91
+ interface InvalidOutputError {
92
+ readonly metadata: {
93
+ readonly anthropic?: AnthropicErrorMetadata | null;
94
+ };
95
+ }
96
+ interface UnknownError {
97
+ readonly metadata: {
98
+ readonly anthropic?: AnthropicErrorMetadata | null;
99
+ };
100
+ }
101
+ }
102
+ //# sourceMappingURL=AnthropicError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnthropicError.d.ts","sourceRoot":"","sources":["../src/AnthropicError.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,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,CAAC,EAAE,sBAAsB,GAAG,IAAI,CAAA;SACnD,CAAA;KACF;IAED,UAAiB,qBAAqB;QACpC,QAAQ,CAAC,QAAQ,EAAE;YACjB,QAAQ,CAAC,SAAS,CAAC,EAAE,sBAAsB,GAAG,IAAI,CAAA;SACnD,CAAA;KACF;IAED,UAAiB,kBAAkB;QACjC,QAAQ,CAAC,QAAQ,EAAE;YACjB,QAAQ,CAAC,SAAS,CAAC,EAAE,sBAAsB,GAAG,IAAI,CAAA;SACnD,CAAA;KACF;IAED,UAAiB,YAAY;QAC3B,QAAQ,CAAC,QAAQ,EAAE;YACjB,QAAQ,CAAC,SAAS,CAAC,EAAE,sBAAsB,GAAG,IAAI,CAAA;SACnD,CAAA;KACF;CACF"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Anthropic error metadata augmentation.
3
+ *
4
+ * Provides Anthropic-specific metadata fields for AI error types through module
5
+ * augmentation, enabling typed access to Anthropic error details.
6
+ *
7
+ * @since 1.0.0
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=AnthropicError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnthropicError.js","names":[],"sources":["../src/AnthropicError.ts"],"sourcesContent":[null],"mappings":"AAAA","ignoreList":[]}