@effect/ai-openai 4.0.0-beta.7 → 4.0.0-beta.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/dist/Generated.d.ts +66734 -37723
  2. package/dist/Generated.d.ts.map +1 -1
  3. package/dist/Generated.js +1 -1
  4. package/dist/Generated.js.map +1 -1
  5. package/dist/OpenAiClient.d.ts +81 -25
  6. package/dist/OpenAiClient.d.ts.map +1 -1
  7. package/dist/OpenAiClient.js +220 -39
  8. package/dist/OpenAiClient.js.map +1 -1
  9. package/dist/OpenAiClientGenerated.d.ts +91 -0
  10. package/dist/OpenAiClientGenerated.d.ts.map +1 -0
  11. package/dist/OpenAiClientGenerated.js +84 -0
  12. package/dist/OpenAiClientGenerated.js.map +1 -0
  13. package/dist/OpenAiConfig.d.ts +45 -10
  14. package/dist/OpenAiConfig.d.ts.map +1 -1
  15. package/dist/OpenAiConfig.js +31 -7
  16. package/dist/OpenAiConfig.js.map +1 -1
  17. package/dist/OpenAiEmbeddingModel.d.ts +89 -0
  18. package/dist/OpenAiEmbeddingModel.d.ts.map +1 -0
  19. package/dist/OpenAiEmbeddingModel.js +121 -0
  20. package/dist/OpenAiEmbeddingModel.js.map +1 -0
  21. package/dist/OpenAiError.d.ts +168 -35
  22. package/dist/OpenAiError.d.ts.map +1 -1
  23. package/dist/OpenAiError.js +1 -1
  24. package/dist/OpenAiLanguageModel.d.ts +250 -57
  25. package/dist/OpenAiLanguageModel.d.ts.map +1 -1
  26. package/dist/OpenAiLanguageModel.js +311 -160
  27. package/dist/OpenAiLanguageModel.js.map +1 -1
  28. package/dist/OpenAiSchema.d.ts +2029 -0
  29. package/dist/OpenAiSchema.d.ts.map +1 -0
  30. package/dist/OpenAiSchema.js +591 -0
  31. package/dist/OpenAiSchema.js.map +1 -0
  32. package/dist/OpenAiTelemetry.d.ts +31 -18
  33. package/dist/OpenAiTelemetry.d.ts.map +1 -1
  34. package/dist/OpenAiTelemetry.js +6 -4
  35. package/dist/OpenAiTelemetry.js.map +1 -1
  36. package/dist/OpenAiTool.d.ts +56 -67
  37. package/dist/OpenAiTool.d.ts.map +1 -1
  38. package/dist/OpenAiTool.js +33 -44
  39. package/dist/OpenAiTool.js.map +1 -1
  40. package/dist/index.d.ts +42 -8
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +42 -8
  43. package/dist/index.js.map +1 -1
  44. package/dist/internal/errors.js +4 -4
  45. package/dist/internal/errors.js.map +1 -1
  46. package/package.json +3 -3
  47. package/src/Generated.ts +9858 -5044
  48. package/src/OpenAiClient.ts +396 -90
  49. package/src/OpenAiClientGenerated.ts +202 -0
  50. package/src/OpenAiConfig.ts +46 -11
  51. package/src/OpenAiEmbeddingModel.ts +207 -0
  52. package/src/OpenAiError.ts +170 -35
  53. package/src/OpenAiLanguageModel.ts +633 -157
  54. package/src/OpenAiSchema.ts +984 -0
  55. package/src/OpenAiTelemetry.ts +32 -19
  56. package/src/OpenAiTool.ts +34 -45
  57. package/src/index.ts +45 -8
  58. package/src/internal/errors.ts +6 -4
@@ -5,7 +5,7 @@
5
5
  * semantic conventions, extending the base GenAI attributes with OpenAI-specific
6
6
  * request and response metadata.
7
7
  *
8
- * @since 1.0.0
8
+ * @since 4.0.0
9
9
  */
10
10
  import { dual } from "effect/Function"
11
11
  import * as String from "effect/String"
@@ -17,10 +17,10 @@ import * as Telemetry from "effect/unstable/ai/Telemetry"
17
17
  * The attributes used to describe telemetry in the context of Generative
18
18
  * Artificial Intelligence (GenAI) Models requests and responses.
19
19
  *
20
- * {@see https://opentelemetry.io/docs/specs/semconv/attributes-registry/gen-ai/}
20
+ * @see https://opentelemetry.io/docs/specs/semconv/attributes-registry/gen-ai/
21
21
  *
22
- * @since 1.0.0
23
22
  * @category models
23
+ * @since 4.0.0
24
24
  */
25
25
  export type OpenAiTelemetryAttributes = Simplify<
26
26
  & Telemetry.GenAITelemetryAttributes
@@ -32,8 +32,8 @@ export type OpenAiTelemetryAttributes = Simplify<
32
32
  * All telemetry attributes which are part of the GenAI specification,
33
33
  * including the OpenAi-specific attributes.
34
34
  *
35
- * @since 1.0.0
36
35
  * @category models
36
+ * @since 4.0.0
37
37
  */
38
38
  export type AllAttributes = Telemetry.AllAttributes & RequestAttributes & ResponseAttributes
39
39
 
@@ -41,8 +41,8 @@ export type AllAttributes = Telemetry.AllAttributes & RequestAttributes & Respon
41
41
  * Telemetry attributes which are part of the GenAI specification and are
42
42
  * namespaced by `gen_ai.openai.request`.
43
43
  *
44
- * @since 1.0.0
45
44
  * @category models
45
+ * @since 4.0.0
46
46
  */
47
47
  export interface RequestAttributes {
48
48
  /**
@@ -59,8 +59,8 @@ export interface RequestAttributes {
59
59
  * Telemetry attributes which are part of the GenAI specification and are
60
60
  * namespaced by `gen_ai.openai.response`.
61
61
  *
62
- * @since 1.0.0
63
62
  * @category models
63
+ * @since 4.0.0
64
64
  */
65
65
  export interface ResponseAttributes {
66
66
  /**
@@ -78,11 +78,13 @@ export interface ResponseAttributes {
78
78
  * The `gen_ai.openai.request.response_format` attribute has the following
79
79
  * list of well-known values.
80
80
  *
81
+ * **Details**
82
+ *
81
83
  * If one of them applies, then the respective value **MUST** be used;
82
84
  * otherwise, a custom value **MAY** be used.
83
85
  *
84
- * @since 1.0.0
85
86
  * @category models
87
+ * @since 4.0.0
86
88
  */
87
89
  export type WellKnownResponseFormat = "json_object" | "json_schema" | "text"
88
90
 
@@ -90,17 +92,22 @@ export type WellKnownResponseFormat = "json_object" | "json_schema" | "text"
90
92
  * The `gen_ai.openai.request.service_tier` attribute has the following
91
93
  * list of well-known values.
92
94
  *
95
+ * **Details**
96
+ *
93
97
  * If one of them applies, then the respective value **MUST** be used;
94
98
  * otherwise, a custom value **MAY** be used.
95
99
  *
96
- * @since 1.0.0
97
100
  * @category models
101
+ * @since 4.0.0
98
102
  */
99
103
  export type WellKnownServiceTier = "auto" | "default"
100
104
 
101
105
  /**
102
- * @since 1.0.0
103
- * @since models
106
+ * Options accepted by `addGenAIAnnotations`, combining standard GenAI
107
+ * telemetry attributes with optional OpenAI request and response attributes.
108
+ *
109
+ * @category models
110
+ * @since 4.0.0
104
111
  */
105
112
  export type OpenAiTelemetryAttributeOptions = Telemetry.GenAITelemetryAttributeOptions & {
106
113
  openai?: {
@@ -120,30 +127,36 @@ const addOpenAiResponseAttributes = Telemetry.addSpanAttributes("gen_ai.openai.r
120
127
  * Applies the specified OpenAi GenAI telemetry attributes to the provided
121
128
  * `Span`.
122
129
  *
123
- * **NOTE**: This method will mutate the `Span` **in-place**.
130
+ * **Gotchas**
124
131
  *
125
- * @since 1.0.0
126
- * @since utilities
132
+ * This method will mutate the `Span` **in-place**.
133
+ *
134
+ * @category tracing
135
+ * @since 4.0.0
127
136
  */
128
137
  export const addGenAIAnnotations: {
129
138
  /**
130
139
  * Applies the specified OpenAi GenAI telemetry attributes to the provided
131
140
  * `Span`.
132
141
  *
133
- * **NOTE**: This method will mutate the `Span` **in-place**.
142
+ * **Gotchas**
143
+ *
144
+ * This method will mutate the `Span` **in-place**.
134
145
  *
135
- * @since 1.0.0
136
- * @since utilities
146
+ * @category tracing
147
+ * @since 4.0.0
137
148
  */
138
149
  (options: OpenAiTelemetryAttributeOptions): (span: Span) => void
139
150
  /**
140
151
  * Applies the specified OpenAi GenAI telemetry attributes to the provided
141
152
  * `Span`.
142
153
  *
143
- * **NOTE**: This method will mutate the `Span` **in-place**.
154
+ * **Gotchas**
155
+ *
156
+ * This method will mutate the `Span` **in-place**.
144
157
  *
145
- * @since 1.0.0
146
- * @since utilities
158
+ * @category tracing
159
+ * @since 4.0.0
147
160
  */
148
161
  (span: Span, options: OpenAiTelemetryAttributeOptions): void
149
162
  } = dual(2, (span: Span, options: OpenAiTelemetryAttributeOptions) => {
package/src/OpenAiTool.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * Provides tools that are natively supported by OpenAI's API, including
5
5
  * code interpreter, file search, and web search functionality.
6
6
  *
7
- * @since 1.0.0
7
+ * @since 4.0.0
8
8
  */
9
9
  import * as Schema from "effect/Schema"
10
10
  import * as Tool from "effect/unstable/ai/Tool"
@@ -13,8 +13,8 @@ import * as Generated from "./Generated.ts"
13
13
  /**
14
14
  * Union of all OpenAI provider-defined tools.
15
15
  *
16
- * @since 1.0.0
17
16
  * @category models
17
+ * @since 4.0.0
18
18
  */
19
19
  export type OpenAiTool =
20
20
  | ReturnType<typeof ApplyPatch>
@@ -28,14 +28,12 @@ export type OpenAiTool =
28
28
  | ReturnType<typeof WebSearchPreview>
29
29
 
30
30
  /**
31
- * OpenAI Apply Patch tool.
31
+ * OpenAI Apply Patch tool that allows the model to apply diffs by creating,
32
+ * deleting, or updating files. This local tool runs in your environment and
33
+ * requires a handler to execute file operations.
32
34
  *
33
- * Allows the model to apply diffs by creating, deleting, or updating files.
34
- * This is a local tool that runs in your environment and requires a handler
35
- * to execute file operations.
36
- *
37
- * @since 1.0.0
38
35
  * @category tools
36
+ * @since 4.0.0
39
37
  */
40
38
  export const ApplyPatch = Tool.providerDefined({
41
39
  id: "openai.apply_patch",
@@ -53,12 +51,11 @@ export const ApplyPatch = Tool.providerDefined({
53
51
  })
54
52
 
55
53
  /**
56
- * OpenAI Code Interpreter tool.
57
- *
58
- * Allows the model to execute Python code in a sandboxed environment.
54
+ * OpenAI Code Interpreter tool that allows the model to execute Python code in
55
+ * a sandboxed environment.
59
56
  *
60
- * @since 1.0.0
61
57
  * @category tools
58
+ * @since 4.0.0
62
59
  */
63
60
  export const CodeInterpreter = Tool.providerDefined({
64
61
  id: "openai.code_interpreter",
@@ -77,12 +74,11 @@ export const CodeInterpreter = Tool.providerDefined({
77
74
  })
78
75
 
79
76
  /**
80
- * OpenAI File Search tool.
81
- *
82
- * Enables the model to search through uploaded files and vector stores.
77
+ * OpenAI File Search tool that enables the model to search through uploaded
78
+ * files and vector stores.
83
79
  *
84
- * @since 1.0.0
85
80
  * @category tools
81
+ * @since 4.0.0
86
82
  */
87
83
  export const FileSearch = Tool.providerDefined({
88
84
  id: "openai.file_search",
@@ -102,12 +98,11 @@ export const FileSearch = Tool.providerDefined({
102
98
  })
103
99
 
104
100
  /**
105
- * OpenAI Image Generation tool.
101
+ * OpenAI Image Generation tool that enables the model to generate images using
102
+ * the GPT image models.
106
103
  *
107
- * Enables the model to generate images using the GPT image models.
108
- *
109
- * @since 1.0.0
110
104
  * @category tools
105
+ * @since 4.0.0
111
106
  */
112
107
  export const ImageGeneration = Tool.providerDefined({
113
108
  id: "openai.image_generation",
@@ -131,13 +126,12 @@ export const ImageGeneration = Tool.providerDefined({
131
126
  })
132
127
 
133
128
  /**
134
- * OpenAI Local Shell tool.
135
- *
136
- * Enables the model to run a command with a local shell. This is a local tool
137
- * that runs in your environment and requires a handler to execute commands.
129
+ * OpenAI Local Shell tool that enables the model to run a command with a local
130
+ * shell. This local tool runs in your environment and requires a handler to
131
+ * execute commands.
138
132
  *
139
- * @since 1.0.0
140
133
  * @category tools
134
+ * @since 4.0.0
141
135
  */
142
136
  export const LocalShell = Tool.providerDefined({
143
137
  id: "openai.local_shell",
@@ -153,13 +147,11 @@ export const LocalShell = Tool.providerDefined({
153
147
  })
154
148
 
155
149
  /**
156
- * OpenAI MCP tool.
150
+ * OpenAI MCP tool that gives the model access to additional tools via remote
151
+ * Model Context Protocol (MCP) servers.
157
152
  *
158
- * Gives the model access to additional tools via remote Model Context Protocol
159
- * (MCP) servers
160
- *
161
- * @since 1.0.0
162
153
  * @category tools
154
+ * @since 4.0.0
163
155
  */
164
156
  export const Mcp = Tool.providerDefined({
165
157
  id: "openai.mcp",
@@ -174,6 +166,7 @@ export const Mcp = Tool.providerDefined({
174
166
  server_label: Generated.MCPTool.fields.server_label,
175
167
  server_url: Generated.MCPTool.fields.server_url
176
168
  }),
169
+ parameters: Schema.Unknown,
177
170
  success: Schema.Struct({
178
171
  type: Generated.MCPToolCall.fields.type,
179
172
  name: Generated.MCPToolCall.fields.name,
@@ -185,14 +178,12 @@ export const Mcp = Tool.providerDefined({
185
178
  })
186
179
 
187
180
  /**
188
- * OpenAI Function Shell tool.
189
- *
190
- * Enables the model to execute one or more shell commands in a managed
191
- * environment. This is a local tool that runs in your environment and requires
192
- * a handler to execute commands.
181
+ * OpenAI Function Shell tool that enables the model to execute one or more shell
182
+ * commands in a managed environment. This local tool runs in your environment
183
+ * and requires a handler to execute commands.
193
184
  *
194
- * @since 1.0.0
195
185
  * @category tools
186
+ * @since 4.0.0
196
187
  */
197
188
  export const Shell = Tool.providerDefined({
198
189
  id: "openai.shell",
@@ -203,17 +194,16 @@ export const Shell = Tool.providerDefined({
203
194
  action: Generated.FunctionShellCall.fields.action
204
195
  }),
205
196
  success: Schema.Struct({
206
- output: Generated.FunctionShellCallOutputItemParam.fields.output
197
+ output: Generated.FunctionShellCallOutput.fields.output
207
198
  })
208
199
  })
209
200
 
210
201
  /**
211
- * OpenAI Web Search tool.
202
+ * OpenAI Web Search tool that enables the model to search the web for
203
+ * information.
212
204
  *
213
- * Enables the model to search the web for information.
214
- *
215
- * @since 1.0.0
216
205
  * @category tools
206
+ * @since 4.0.0
217
207
  */
218
208
  export const WebSearch = Tool.providerDefined({
219
209
  id: "openai.web_search",
@@ -234,12 +224,11 @@ export const WebSearch = Tool.providerDefined({
234
224
  })
235
225
 
236
226
  /**
237
- * OpenAI Web Search Preview tool.
238
- *
239
- * Preview version of the web search tool with additional features.
227
+ * OpenAI Web Search Preview tool, a preview version of the web search tool with
228
+ * additional features.
240
229
  *
241
- * @since 1.0.0
242
230
  * @category tools
231
+ * @since 4.0.0
243
232
  */
244
233
  export const WebSearchPreview = Tool.providerDefined({
245
234
  id: "openai.web_search_preview",
package/src/index.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
 
5
5
  // @barrel: Auto-generated exports. Do not edit manually.
6
6
 
7
7
  /**
8
- * @since 1.0.0
8
+ * @since 4.0.0
9
9
  */
10
10
  export * as Generated from "./Generated.ts"
11
11
 
@@ -15,22 +15,52 @@ export * as Generated from "./Generated.ts"
15
15
  * Provides a type-safe, Effect-based client for OpenAI operations including
16
16
  * completions, embeddings, and streaming responses.
17
17
  *
18
- * @since 1.0.0
18
+ * @since 4.0.0
19
19
  */
20
20
  export * as OpenAiClient from "./OpenAiClient.ts"
21
21
 
22
22
  /**
23
- * @since 1.0.0
23
+ * @since 4.0.0
24
+ */
25
+ export * as OpenAiClientGenerated from "./OpenAiClientGenerated.ts"
26
+
27
+ /**
28
+ * The `OpenAiConfig` module provides contextual configuration for the
29
+ * `@effect/ai-openai` integration. It is used to customize how OpenAI clients
30
+ * are built and interpreted without threading configuration through every API
31
+ * call manually.
32
+ *
33
+ * The primary use case is installing an HTTP client transform with
34
+ * {@link withClientTransform}. This lets applications adapt the underlying
35
+ * OpenAI HTTP client for cross-cutting concerns such as custom middleware,
36
+ * instrumentation, proxying, or request policy changes while keeping the
37
+ * OpenAI service APIs unchanged.
38
+ *
39
+ * Configuration is scoped through Effect's context, so transforms only apply to
40
+ * the effect they are provided to and anything evaluated inside that scope.
41
+ * When multiple transforms are needed, compose them into a single
42
+ * `HttpClient => HttpClient` function before providing the configuration.
43
+ *
44
+ * @since 4.0.0
24
45
  */
25
46
  export * as OpenAiConfig from "./OpenAiConfig.ts"
26
47
 
48
+ /**
49
+ * OpenAI Embedding Model implementation.
50
+ *
51
+ * Provides an EmbeddingModel implementation for OpenAI's embeddings API.
52
+ *
53
+ * @since 4.0.0
54
+ */
55
+ export * as OpenAiEmbeddingModel from "./OpenAiEmbeddingModel.ts"
56
+
27
57
  /**
28
58
  * OpenAI error metadata augmentation.
29
59
  *
30
60
  * Provides OpenAI-specific metadata fields for AI error types through module
31
61
  * augmentation, enabling typed access to OpenAI error details.
32
62
  *
33
- * @since 1.0.0
63
+ * @since 4.0.0
34
64
  */
35
65
  export * as OpenAiError from "./OpenAiError.ts"
36
66
 
@@ -40,10 +70,17 @@ export * as OpenAiError from "./OpenAiError.ts"
40
70
  * Provides a LanguageModel implementation for OpenAI's responses API,
41
71
  * supporting text generation, structured output, tool calling, and streaming.
42
72
  *
43
- * @since 1.0.0
73
+ * @since 4.0.0
44
74
  */
45
75
  export * as OpenAiLanguageModel from "./OpenAiLanguageModel.ts"
46
76
 
77
+ /**
78
+ * Minimal local OpenAI schemas used by the handwritten Responses client path.
79
+ *
80
+ * @since 4.0.0
81
+ */
82
+ export * as OpenAiSchema from "./OpenAiSchema.ts"
83
+
47
84
  /**
48
85
  * OpenAI telemetry attributes for OpenTelemetry integration.
49
86
  *
@@ -51,7 +88,7 @@ export * as OpenAiLanguageModel from "./OpenAiLanguageModel.ts"
51
88
  * semantic conventions, extending the base GenAI attributes with OpenAI-specific
52
89
  * request and response metadata.
53
90
  *
54
- * @since 1.0.0
91
+ * @since 4.0.0
55
92
  */
56
93
  export * as OpenAiTelemetry from "./OpenAiTelemetry.ts"
57
94
 
@@ -61,6 +98,6 @@ export * as OpenAiTelemetry from "./OpenAiTelemetry.ts"
61
98
  * Provides tools that are natively supported by OpenAI's API, including
62
99
  * code interpreter, file search, and web search functionality.
63
100
  *
64
- * @since 1.0.0
101
+ * @since 4.0.0
65
102
  */
66
103
  export * as OpenAiTool from "./OpenAiTool.ts"
@@ -161,12 +161,14 @@ export const parseRateLimitHeaders = (headers: Record<string, string>) => {
161
161
  let retryAfter: Duration.Duration | undefined
162
162
  if (Predicate.isNotUndefined(retryAfterRaw)) {
163
163
  const parsed = Number.parse(retryAfterRaw)
164
- if (Predicate.isNotUndefined(parsed)) {
165
- retryAfter = Duration.seconds(parsed)
164
+ if (Option.isSome(parsed)) {
165
+ retryAfter = Duration.seconds(parsed.value)
166
166
  }
167
167
  }
168
168
  const remainingRaw = headers["x-ratelimit-remaining-requests"]
169
- const remaining = Predicate.isNotUndefined(remainingRaw) ? Number.parse(remainingRaw) ?? null : null
169
+ const remaining = Predicate.isNotUndefined(remainingRaw)
170
+ ? Option.getOrNull(Number.parse(remainingRaw))
171
+ : null
170
172
  return {
171
173
  retryAfter,
172
174
  limit: headers["x-ratelimit-limit-requests"] ?? null,
@@ -187,7 +189,7 @@ export const buildHttpRequestDetails = (
187
189
  method: request.method,
188
190
  url: request.url,
189
191
  urlParams: Array.from(request.urlParams),
190
- hash: request.hash,
192
+ hash: Option.getOrUndefined(request.hash),
191
193
  headers: Redactable.redact(request.headers) as Record<string, string>
192
194
  })
193
195