@effect/ai-openai 4.0.0-beta.66 → 4.0.0-beta.67

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 (47) hide show
  1. package/dist/Generated.d.ts +1 -1
  2. package/dist/Generated.js +1 -1
  3. package/dist/OpenAiClient.d.ts +18 -11
  4. package/dist/OpenAiClient.d.ts.map +1 -1
  5. package/dist/OpenAiClient.js +10 -8
  6. package/dist/OpenAiClient.js.map +1 -1
  7. package/dist/OpenAiClientGenerated.d.ts +5 -5
  8. package/dist/OpenAiClientGenerated.js +5 -5
  9. package/dist/OpenAiConfig.d.ts +43 -8
  10. package/dist/OpenAiConfig.d.ts.map +1 -1
  11. package/dist/OpenAiConfig.js +28 -4
  12. package/dist/OpenAiConfig.js.map +1 -1
  13. package/dist/OpenAiEmbeddingModel.d.ts +13 -9
  14. package/dist/OpenAiEmbeddingModel.d.ts.map +1 -1
  15. package/dist/OpenAiEmbeddingModel.js +8 -6
  16. package/dist/OpenAiEmbeddingModel.js.map +1 -1
  17. package/dist/OpenAiError.d.ts +124 -3
  18. package/dist/OpenAiError.d.ts.map +1 -1
  19. package/dist/OpenAiError.js +1 -1
  20. package/dist/OpenAiLanguageModel.d.ts +160 -9
  21. package/dist/OpenAiLanguageModel.d.ts.map +1 -1
  22. package/dist/OpenAiLanguageModel.js +9 -7
  23. package/dist/OpenAiLanguageModel.js.map +1 -1
  24. package/dist/OpenAiSchema.d.ts +108 -35
  25. package/dist/OpenAiSchema.d.ts.map +1 -1
  26. package/dist/OpenAiSchema.js +55 -18
  27. package/dist/OpenAiSchema.js.map +1 -1
  28. package/dist/OpenAiTelemetry.d.ts +13 -10
  29. package/dist/OpenAiTelemetry.d.ts.map +1 -1
  30. package/dist/OpenAiTelemetry.js +2 -2
  31. package/dist/OpenAiTelemetry.js.map +1 -1
  32. package/dist/OpenAiTool.d.ts +11 -11
  33. package/dist/OpenAiTool.js +10 -10
  34. package/dist/index.d.ts +11 -11
  35. package/dist/index.js +11 -11
  36. package/package.json +3 -3
  37. package/src/Generated.ts +1 -1
  38. package/src/OpenAiClient.ts +19 -12
  39. package/src/OpenAiClientGenerated.ts +6 -6
  40. package/src/OpenAiConfig.ts +43 -8
  41. package/src/OpenAiEmbeddingModel.ts +15 -11
  42. package/src/OpenAiError.ts +124 -3
  43. package/src/OpenAiLanguageModel.ts +163 -12
  44. package/src/OpenAiSchema.ts +109 -36
  45. package/src/OpenAiTelemetry.ts +14 -11
  46. package/src/OpenAiTool.ts +11 -11
  47. package/src/index.ts +11 -11
@@ -1,5 +1,21 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * The `OpenAiConfig` module provides contextual configuration for the
3
+ * `@effect/ai-openai` integration. It is used to customize how OpenAI clients
4
+ * are built and interpreted without threading configuration through every API
5
+ * call manually.
6
+ *
7
+ * The primary use case is installing an HTTP client transform with
8
+ * {@link withClientTransform}. This lets applications adapt the underlying
9
+ * OpenAI HTTP client for cross-cutting concerns such as custom middleware,
10
+ * instrumentation, proxying, or request policy changes while keeping the
11
+ * OpenAI service APIs unchanged.
12
+ *
13
+ * Configuration is scoped through Effect's context, so transforms only apply to
14
+ * the effect they are provided to and anything evaluated inside that scope.
15
+ * When multiple transforms are needed, compose them into a single
16
+ * `HttpClient => HttpClient` function before providing the configuration.
17
+ *
18
+ * @since 4.0.0
3
19
  */
4
20
  import * as Context from "effect/Context"
5
21
  import * as Effect from "effect/Effect"
@@ -7,15 +23,20 @@ import { dual } from "effect/Function"
7
23
  import type { HttpClient } from "effect/unstable/http/HttpClient"
8
24
 
9
25
  /**
10
- * @since 1.0.0
26
+ * Context service carrying scoped OpenAI configuration for provider
27
+ * operations.
28
+ *
11
29
  * @category services
30
+ * @since 4.0.0
12
31
  */
13
32
  export class OpenAiConfig extends Context.Service<
14
33
  OpenAiConfig,
15
34
  OpenAiConfig.Service
16
35
  >()("@effect/ai-openai/OpenAiConfig") {
17
36
  /**
18
- * @since 1.0.0
37
+ * Gets the configured OpenAI service from the current context when present.
38
+ *
39
+ * @since 4.0.0
19
40
  */
20
41
  static readonly getOrUndefined: Effect.Effect<typeof OpenAiConfig.Service | undefined> = Effect.map(
21
42
  Effect.context<never>(),
@@ -24,12 +45,17 @@ export class OpenAiConfig extends Context.Service<
24
45
  }
25
46
 
26
47
  /**
27
- * @since 1.0.0
48
+ * Types used by the `OpenAiConfig` context service.
49
+ *
50
+ * @since 4.0.0
28
51
  */
29
52
  export declare namespace OpenAiConfig {
30
53
  /**
31
- * @since 1.0.
54
+ * Configuration values read by OpenAI provider operations when executing
55
+ * requests.
56
+ *
32
57
  * @category models
58
+ * @since 1.0.
33
59
  */
34
60
  export interface Service {
35
61
  readonly transformClient?: ((client: HttpClient) => HttpClient) | undefined
@@ -37,18 +63,27 @@ export declare namespace OpenAiConfig {
37
63
  }
38
64
 
39
65
  /**
40
- * @since 1.0.0
66
+ * Provides a scoped transform for the OpenAI HTTP client used by provider
67
+ * operations.
68
+ *
41
69
  * @category configuration
70
+ * @since 4.0.0
42
71
  */
43
72
  export const withClientTransform: {
44
73
  /**
45
- * @since 1.0.0
74
+ * Provides a scoped transform for the OpenAI HTTP client used by provider
75
+ * operations.
76
+ *
46
77
  * @category configuration
78
+ * @since 4.0.0
47
79
  */
48
80
  (transform: (client: HttpClient) => HttpClient): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
49
81
  /**
50
- * @since 1.0.0
82
+ * Provides a scoped transform for the OpenAI HTTP client used by provider
83
+ * operations.
84
+ *
51
85
  * @category configuration
86
+ * @since 4.0.0
52
87
  */
53
88
  <A, E, R>(
54
89
  self: Effect.Effect<A, E, R>,
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Provides an EmbeddingModel implementation for OpenAI's embeddings API.
5
5
  *
6
- * @since 1.0.0
6
+ * @since 4.0.0
7
7
  */
8
8
  import * as Context from "effect/Context"
9
9
  import * as Effect from "effect/Effect"
@@ -17,16 +17,18 @@ import { OpenAiClient } from "./OpenAiClient.ts"
17
17
  import type * as OpenAiSchema from "./OpenAiSchema.ts"
18
18
 
19
19
  /**
20
- * @since 1.0.0
20
+ * Model identifiers supported by OpenAI's embeddings API.
21
+ *
21
22
  * @category models
23
+ * @since 4.0.0
22
24
  */
23
25
  export type Model = "text-embedding-ada-002" | "text-embedding-3-small" | "text-embedding-3-large"
24
26
 
25
27
  /**
26
28
  * Service definition for OpenAI embedding model configuration.
27
29
  *
28
- * @since 1.0.0
29
30
  * @category services
31
+ * @since 4.0.0
30
32
  */
31
33
  export class Config extends Context.Service<
32
34
  Config,
@@ -44,8 +46,10 @@ export class Config extends Context.Service<
44
46
  >()("@effect/ai-openai/OpenAiEmbeddingModel/Config") {}
45
47
 
46
48
  /**
47
- * @since 1.0.0
49
+ * Creates an `AiModel` for an OpenAI embedding model with its configured vector dimensions.
50
+ *
48
51
  * @category constructors
52
+ * @since 4.0.0
49
53
  */
50
54
  export const model = (
51
55
  model: (string & {}) | Model,
@@ -72,8 +76,8 @@ export const model = (
72
76
  /**
73
77
  * Creates an OpenAI embedding model service.
74
78
  *
75
- * @since 1.0.0
76
79
  * @category constructors
80
+ * @since 4.0.0
77
81
  */
78
82
  export const make = Effect.fnUntraced(function*({ model, config: providerConfig }: {
79
83
  readonly model: (string & {}) | Model
@@ -98,8 +102,8 @@ export const make = Effect.fnUntraced(function*({ model, config: providerConfig
98
102
  /**
99
103
  * Creates a layer for the OpenAI embedding model.
100
104
  *
101
- * @since 1.0.0
102
105
  * @category layers
106
+ * @since 4.0.0
103
107
  */
104
108
  export const layer = (options: {
105
109
  readonly model: (string & {}) | Model
@@ -110,37 +114,37 @@ export const layer = (options: {
110
114
  /**
111
115
  * Provides config overrides for OpenAI embedding model operations.
112
116
  *
113
- * @since 1.0.0
114
117
  * @category configuration
118
+ * @since 4.0.0
115
119
  */
116
120
  export const withConfigOverride: {
117
121
  /**
118
122
  * Provides config overrides for OpenAI embedding model operations.
119
123
  *
120
- * @since 1.0.0
121
124
  * @category configuration
125
+ * @since 4.0.0
122
126
  */
123
127
  (overrides: typeof Config.Service): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>
124
128
  /**
125
129
  * Provides config overrides for OpenAI embedding model operations.
126
130
  *
127
- * @since 1.0.0
128
131
  * @category configuration
132
+ * @since 4.0.0
129
133
  */
130
134
  <A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service): Effect.Effect<A, E, Exclude<R, Config>>
131
135
  } = dual<
132
136
  /**
133
137
  * Provides config overrides for OpenAI embedding model operations.
134
138
  *
135
- * @since 1.0.0
136
139
  * @category configuration
140
+ * @since 4.0.0
137
141
  */
138
142
  (overrides: typeof Config.Service) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>,
139
143
  /**
140
144
  * Provides config overrides for OpenAI embedding model operations.
141
145
  *
142
- * @since 1.0.0
143
146
  * @category configuration
147
+ * @since 4.0.0
144
148
  */
145
149
  <A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service) => Effect.Effect<A, E, Exclude<R, Config>>
146
150
  >(2, (self, overrides) =>
@@ -4,14 +4,14 @@
4
4
  * Provides OpenAI-specific metadata fields for AI error types through module
5
5
  * augmentation, enabling typed access to OpenAI error details.
6
6
  *
7
- * @since 1.0.0
7
+ * @since 4.0.0
8
8
  */
9
9
 
10
10
  /**
11
11
  * OpenAI-specific error metadata fields.
12
12
  *
13
- * @since 1.0.0
14
13
  * @category models
14
+ * @since 4.0.0
15
15
  */
16
16
  export type OpenAiErrorMetadata = {
17
17
  /**
@@ -34,8 +34,8 @@ export type OpenAiErrorMetadata = {
34
34
  * Extends base error metadata with rate limit specific information from
35
35
  * OpenAI's rate limit headers.
36
36
  *
37
- * @since 1.0.0
38
37
  * @category models
38
+ * @since 4.0.0
39
39
  */
40
40
  export type OpenAiRateLimitMetadata = OpenAiErrorMetadata & {
41
41
  /**
@@ -57,43 +57,164 @@ export type OpenAiRateLimitMetadata = OpenAiErrorMetadata & {
57
57
  }
58
58
 
59
59
  declare module "effect/unstable/ai/AiError" {
60
+ /**
61
+ * OpenAI metadata attached to `RateLimitError` values.
62
+ *
63
+ * Captures OpenAI error details together with rate limit header information
64
+ * from responses where the provider rejected the request because a limit was
65
+ * reached.
66
+ *
67
+ * @category provider options
68
+ * @since 4.0.0
69
+ */
60
70
  export interface RateLimitErrorMetadata {
71
+ /**
72
+ * OpenAI-specific details for the rate limit response.
73
+ */
61
74
  readonly openai?: OpenAiRateLimitMetadata | null
62
75
  }
63
76
 
77
+ /**
78
+ * OpenAI metadata attached to `QuotaExhaustedError` values.
79
+ *
80
+ * Preserves provider error details for failures caused by exhausted account,
81
+ * billing, or usage quota.
82
+ *
83
+ * @category provider options
84
+ * @since 4.0.0
85
+ */
64
86
  export interface QuotaExhaustedErrorMetadata {
87
+ /**
88
+ * OpenAI-specific details for the quota exhaustion response.
89
+ */
65
90
  readonly openai?: OpenAiErrorMetadata | null
66
91
  }
67
92
 
93
+ /**
94
+ * OpenAI metadata attached to `AuthenticationError` values.
95
+ *
96
+ * Preserves provider error details for failed API key, authorization, or
97
+ * permission checks.
98
+ *
99
+ * @category provider options
100
+ * @since 4.0.0
101
+ */
68
102
  export interface AuthenticationErrorMetadata {
103
+ /**
104
+ * OpenAI-specific details for the authentication failure.
105
+ */
69
106
  readonly openai?: OpenAiErrorMetadata | null
70
107
  }
71
108
 
109
+ /**
110
+ * OpenAI metadata attached to `ContentPolicyError` values.
111
+ *
112
+ * Preserves provider error details when OpenAI rejects input or output because
113
+ * it violates a content policy.
114
+ *
115
+ * @category provider options
116
+ * @since 4.0.0
117
+ */
72
118
  export interface ContentPolicyErrorMetadata {
119
+ /**
120
+ * OpenAI-specific details for the content policy response.
121
+ */
73
122
  readonly openai?: OpenAiErrorMetadata | null
74
123
  }
75
124
 
125
+ /**
126
+ * OpenAI metadata attached to `InvalidRequestError` values.
127
+ *
128
+ * Preserves provider error details for malformed requests, unsupported
129
+ * parameters, or other request validation failures reported by OpenAI.
130
+ *
131
+ * @category provider options
132
+ * @since 4.0.0
133
+ */
76
134
  export interface InvalidRequestErrorMetadata {
135
+ /**
136
+ * OpenAI-specific details for the invalid request response.
137
+ */
77
138
  readonly openai?: OpenAiErrorMetadata | null
78
139
  }
79
140
 
141
+ /**
142
+ * OpenAI metadata attached to `InternalProviderError` values.
143
+ *
144
+ * Preserves provider error details for OpenAI-side failures such as transient
145
+ * server errors.
146
+ *
147
+ * @category provider options
148
+ * @since 4.0.0
149
+ */
80
150
  export interface InternalProviderErrorMetadata {
151
+ /**
152
+ * OpenAI-specific details for the internal provider response.
153
+ */
81
154
  readonly openai?: OpenAiErrorMetadata | null
82
155
  }
83
156
 
157
+ /**
158
+ * OpenAI metadata attached to `InvalidOutputError` values.
159
+ *
160
+ * Preserves provider error details when an OpenAI response cannot be parsed or
161
+ * validated as the expected output.
162
+ *
163
+ * @category provider options
164
+ * @since 4.0.0
165
+ */
84
166
  export interface InvalidOutputErrorMetadata {
167
+ /**
168
+ * OpenAI-specific details for the invalid output response.
169
+ */
85
170
  readonly openai?: OpenAiErrorMetadata | null
86
171
  }
87
172
 
173
+ /**
174
+ * OpenAI metadata attached to `StructuredOutputError` values.
175
+ *
176
+ * Preserves provider error details when OpenAI returns content that does not
177
+ * satisfy the requested structured output schema.
178
+ *
179
+ * @category provider options
180
+ * @since 4.0.0
181
+ */
88
182
  export interface StructuredOutputErrorMetadata {
183
+ /**
184
+ * OpenAI-specific details for the structured output failure.
185
+ */
89
186
  readonly openai?: OpenAiErrorMetadata | null
90
187
  }
91
188
 
189
+ /**
190
+ * OpenAI metadata attached to `UnsupportedSchemaError` values.
191
+ *
192
+ * Preserves provider error details when an unsupported schema failure is
193
+ * associated with an OpenAI response.
194
+ *
195
+ * @category provider options
196
+ * @since 4.0.0
197
+ */
92
198
  export interface UnsupportedSchemaErrorMetadata {
199
+ /**
200
+ * OpenAI-specific details for the unsupported schema failure.
201
+ */
93
202
  readonly openai?: OpenAiErrorMetadata | null
94
203
  }
95
204
 
205
+ /**
206
+ * OpenAI metadata attached to `UnknownError` values.
207
+ *
208
+ * Preserves provider error details for OpenAI failures that do not map cleanly
209
+ * to a more specific AI error category.
210
+ *
211
+ * @category provider options
212
+ * @since 4.0.0
213
+ */
96
214
  export interface UnknownErrorMetadata {
215
+ /**
216
+ * OpenAI-specific details for the unclassified provider failure.
217
+ */
97
218
  readonly openai?: OpenAiErrorMetadata | null
98
219
  }
99
220
  }