@core-ai/openai 0.10.3 → 0.11.1

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.
@@ -63,128 +63,6 @@ function parseOpenAIImageProviderOptions(providerOptions) {
63
63
  var openaiResponsesProviderOptionsSchema = openaiResponsesGenerateProviderOptionsSchema;
64
64
  var openaiCompatProviderOptionsSchema = openaiCompatGenerateProviderOptionsSchema;
65
65
 
66
- // src/shared/provider-factory.ts
67
- import OpenAI from "openai";
68
-
69
- // src/openai-error.ts
70
- import { APIError, APIUserAbortError } from "openai";
71
- import { AbortedError, ProviderError } from "@core-ai/core-ai";
72
- function isOpenAIAbortError(error) {
73
- return error instanceof APIUserAbortError || error instanceof Error && error.name === "AbortError";
74
- }
75
- function wrapOpenAIError(error) {
76
- if (isOpenAIAbortError(error)) {
77
- return new AbortedError(error, "openai");
78
- }
79
- if (error instanceof APIError) {
80
- return new ProviderError(error.message, "openai", error.status, error);
81
- }
82
- return new ProviderError(
83
- error instanceof Error ? error.message : String(error),
84
- "openai",
85
- void 0,
86
- error
87
- );
88
- }
89
-
90
- // src/embedding-model.ts
91
- function createOpenAIEmbeddingModel(client, modelId) {
92
- return {
93
- provider: "openai",
94
- modelId,
95
- async embed(options) {
96
- try {
97
- const openaiOptions = parseOpenAIEmbedProviderOptions(
98
- options.providerOptions
99
- );
100
- const response = await client.embeddings.create({
101
- model: modelId,
102
- input: options.input,
103
- ...options.dimensions !== void 0 ? { dimensions: options.dimensions } : {},
104
- ...mapOpenAIEmbedProviderOptionsToRequestFields(
105
- openaiOptions
106
- )
107
- });
108
- return {
109
- embeddings: response.data.slice().sort((a, b) => a.index - b.index).map((item) => item.embedding),
110
- usage: {
111
- inputTokens: response.usage.prompt_tokens
112
- }
113
- };
114
- } catch (error) {
115
- throw wrapOpenAIError(error);
116
- }
117
- }
118
- };
119
- }
120
- function mapOpenAIEmbedProviderOptionsToRequestFields(options) {
121
- return {
122
- ...options?.encodingFormat !== void 0 ? { encoding_format: options.encodingFormat } : {},
123
- ...options?.user !== void 0 ? { user: options.user } : {}
124
- };
125
- }
126
-
127
- // src/image-model.ts
128
- function createOpenAIImageModel(client, modelId) {
129
- return {
130
- provider: "openai",
131
- modelId,
132
- async generate(options) {
133
- try {
134
- const openaiOptions = parseOpenAIImageProviderOptions(
135
- options.providerOptions
136
- );
137
- const request = {
138
- model: modelId,
139
- prompt: options.prompt,
140
- ...options.n !== void 0 ? { n: options.n } : {},
141
- ...options.size !== void 0 ? { size: options.size } : {},
142
- ...mapOpenAIImageProviderOptionsToRequestFields(
143
- openaiOptions
144
- )
145
- };
146
- const response = await client.images.generate(
147
- request
148
- );
149
- return {
150
- images: (response.data ?? []).map((image) => ({
151
- base64: image.b64_json ?? void 0,
152
- url: image.url ?? void 0,
153
- revisedPrompt: image.revised_prompt ?? void 0
154
- }))
155
- };
156
- } catch (error) {
157
- throw wrapOpenAIError(error);
158
- }
159
- }
160
- };
161
- }
162
- function mapOpenAIImageProviderOptionsToRequestFields(options) {
163
- return {
164
- ...options?.background !== void 0 ? { background: options.background } : {},
165
- ...options?.moderation !== void 0 ? { moderation: options.moderation } : {},
166
- ...options?.outputCompression !== void 0 ? { output_compression: options.outputCompression } : {},
167
- ...options?.outputFormat !== void 0 ? { output_format: options.outputFormat } : {},
168
- ...options?.quality !== void 0 ? { quality: options.quality } : {},
169
- ...options?.responseFormat !== void 0 ? { response_format: options.responseFormat } : {},
170
- ...options?.style !== void 0 ? { style: options.style } : {},
171
- ...options?.user !== void 0 ? { user: options.user } : {}
172
- };
173
- }
174
-
175
- // src/shared/provider-factory.ts
176
- function createOpenAIProvider(options, createChatModel) {
177
- const client = options.client ?? new OpenAI({
178
- apiKey: options.apiKey,
179
- baseURL: options.baseURL
180
- });
181
- return {
182
- chatModel: (modelId) => createChatModel(client, modelId),
183
- embeddingModel: (modelId) => createOpenAIEmbeddingModel(client, modelId),
184
- imageModel: (modelId) => createOpenAIImageModel(client, modelId)
185
- };
186
- }
187
-
188
66
  // src/shared/tools.ts
189
67
  import { zodSchemaToJsonSchema } from "@core-ai/core-ai";
190
68
  var DEFAULT_STRUCTURED_OUTPUT_TOOL_NAME = "core_ai_generate_object";
@@ -237,6 +115,32 @@ function createStructuredOutputOptions(options) {
237
115
  };
238
116
  }
239
117
 
118
+ // src/openai-error.ts
119
+ import { APIError, APIUserAbortError } from "openai";
120
+ import { AbortedError, ProviderError } from "@core-ai/core-ai";
121
+ function isOpenAIAbortError(error) {
122
+ return error instanceof APIUserAbortError || error instanceof Error && error.name === "AbortError";
123
+ }
124
+ function wrapOpenAIError(error, provider = "openai") {
125
+ if (isOpenAIAbortError(error)) {
126
+ return new AbortedError(error, provider);
127
+ }
128
+ if (error instanceof APIError) {
129
+ return new ProviderError(
130
+ error.message,
131
+ provider,
132
+ error.status,
133
+ error
134
+ );
135
+ }
136
+ return new ProviderError(
137
+ error instanceof Error ? error.message : String(error),
138
+ provider,
139
+ void 0,
140
+ error
141
+ );
142
+ }
143
+
240
144
  // src/shared/structured-output.ts
241
145
  import {
242
146
  StructuredOutputNoObjectGeneratedError,
@@ -395,10 +299,109 @@ function formatZodIssues(issues) {
395
299
  });
396
300
  }
397
301
 
302
+ // src/shared/provider-factory.ts
303
+ import OpenAI from "openai";
304
+
305
+ // src/embedding-model.ts
306
+ function createOpenAIEmbeddingModel(client, modelId) {
307
+ return {
308
+ provider: "openai",
309
+ modelId,
310
+ async embed(options) {
311
+ try {
312
+ const openaiOptions = parseOpenAIEmbedProviderOptions(
313
+ options.providerOptions
314
+ );
315
+ const response = await client.embeddings.create({
316
+ model: modelId,
317
+ input: options.input,
318
+ ...options.dimensions !== void 0 ? { dimensions: options.dimensions } : {},
319
+ ...mapOpenAIEmbedProviderOptionsToRequestFields(
320
+ openaiOptions
321
+ )
322
+ });
323
+ return {
324
+ embeddings: response.data.slice().sort((a, b) => a.index - b.index).map((item) => item.embedding),
325
+ usage: {
326
+ inputTokens: response.usage.prompt_tokens
327
+ }
328
+ };
329
+ } catch (error) {
330
+ throw wrapOpenAIError(error);
331
+ }
332
+ }
333
+ };
334
+ }
335
+ function mapOpenAIEmbedProviderOptionsToRequestFields(options) {
336
+ return {
337
+ ...options?.encodingFormat !== void 0 ? { encoding_format: options.encodingFormat } : {},
338
+ ...options?.user !== void 0 ? { user: options.user } : {}
339
+ };
340
+ }
341
+
342
+ // src/image-model.ts
343
+ function createOpenAIImageModel(client, modelId) {
344
+ return {
345
+ provider: "openai",
346
+ modelId,
347
+ async generate(options) {
348
+ try {
349
+ const openaiOptions = parseOpenAIImageProviderOptions(
350
+ options.providerOptions
351
+ );
352
+ const request = {
353
+ model: modelId,
354
+ prompt: options.prompt,
355
+ ...options.n !== void 0 ? { n: options.n } : {},
356
+ ...options.size !== void 0 ? { size: options.size } : {},
357
+ ...mapOpenAIImageProviderOptionsToRequestFields(
358
+ openaiOptions
359
+ )
360
+ };
361
+ const response = await client.images.generate(
362
+ request
363
+ );
364
+ return {
365
+ images: (response.data ?? []).map((image) => ({
366
+ base64: image.b64_json ?? void 0,
367
+ url: image.url ?? void 0,
368
+ revisedPrompt: image.revised_prompt ?? void 0
369
+ }))
370
+ };
371
+ } catch (error) {
372
+ throw wrapOpenAIError(error);
373
+ }
374
+ }
375
+ };
376
+ }
377
+ function mapOpenAIImageProviderOptionsToRequestFields(options) {
378
+ return {
379
+ ...options?.background !== void 0 ? { background: options.background } : {},
380
+ ...options?.moderation !== void 0 ? { moderation: options.moderation } : {},
381
+ ...options?.outputCompression !== void 0 ? { output_compression: options.outputCompression } : {},
382
+ ...options?.outputFormat !== void 0 ? { output_format: options.outputFormat } : {},
383
+ ...options?.quality !== void 0 ? { quality: options.quality } : {},
384
+ ...options?.responseFormat !== void 0 ? { response_format: options.responseFormat } : {},
385
+ ...options?.style !== void 0 ? { style: options.style } : {},
386
+ ...options?.user !== void 0 ? { user: options.user } : {}
387
+ };
388
+ }
389
+
390
+ // src/shared/provider-factory.ts
391
+ function createOpenAIProvider(options, createChatModel) {
392
+ const client = options.client ?? new OpenAI({
393
+ apiKey: options.apiKey,
394
+ baseURL: options.baseURL
395
+ });
396
+ return {
397
+ chatModel: (modelId) => createChatModel(client, modelId),
398
+ embeddingModel: (modelId) => createOpenAIEmbeddingModel(client, modelId),
399
+ imageModel: (modelId) => createOpenAIImageModel(client, modelId)
400
+ };
401
+ }
402
+
398
403
  // src/model-capabilities.ts
399
- import {
400
- stripModelDateSuffix
401
- } from "@core-ai/core-ai";
404
+ import { stripModelDateSuffix } from "@core-ai/core-ai";
402
405
  var DEFAULT_CAPABILITIES = {
403
406
  reasoning: {
404
407
  supportsEffort: true,
@@ -420,6 +423,20 @@ var GPT_5_MINIMAL_REASONING_CAPABILITIES = {
420
423
  restrictsSamplingParams: true
421
424
  }
422
425
  };
426
+ var GPT_5_PRO_REASONING_CAPABILITIES = {
427
+ reasoning: {
428
+ supportsEffort: true,
429
+ supportedRange: ["medium", "high", "max"],
430
+ restrictsSamplingParams: true
431
+ }
432
+ };
433
+ var GPT_5_HIGH_REASONING_CAPABILITIES = {
434
+ reasoning: {
435
+ supportsEffort: true,
436
+ supportedRange: ["high"],
437
+ restrictsSamplingParams: true
438
+ }
439
+ };
423
440
  var NO_REASONING_EFFORT_CAPABILITIES = {
424
441
  reasoning: {
425
442
  supportsEffort: false,
@@ -427,12 +444,27 @@ var NO_REASONING_EFFORT_CAPABILITIES = {
427
444
  restrictsSamplingParams: false
428
445
  }
429
446
  };
447
+ var O_SERIES_MAX_REASONING_CAPABILITIES = {
448
+ reasoning: {
449
+ supportsEffort: true,
450
+ supportedRange: ["low", "medium", "high", "max"],
451
+ restrictsSamplingParams: false
452
+ }
453
+ };
430
454
  var MODEL_CAPABILITIES = {
455
+ "gpt-5.5": GPT_5_MAX_REASONING_CAPABILITIES,
456
+ "gpt-5.5-pro": GPT_5_PRO_REASONING_CAPABILITIES,
431
457
  "gpt-5.4": GPT_5_MAX_REASONING_CAPABILITIES,
432
- "gpt-5.4-pro": GPT_5_MAX_REASONING_CAPABILITIES,
458
+ "gpt-5.4-pro": GPT_5_PRO_REASONING_CAPABILITIES,
459
+ "gpt-5.4-mini": GPT_5_MAX_REASONING_CAPABILITIES,
460
+ "gpt-5.4-nano": GPT_5_MAX_REASONING_CAPABILITIES,
461
+ "gpt-5.3-codex": GPT_5_MAX_REASONING_CAPABILITIES,
433
462
  "gpt-5.2": GPT_5_MAX_REASONING_CAPABILITIES,
434
463
  "gpt-5.2-codex": GPT_5_MAX_REASONING_CAPABILITIES,
435
464
  "gpt-5.2-pro": GPT_5_MAX_REASONING_CAPABILITIES,
465
+ "gpt-5.1-codex": GPT_5_MAX_REASONING_CAPABILITIES,
466
+ "gpt-5.1-codex-max": GPT_5_MAX_REASONING_CAPABILITIES,
467
+ "gpt-5.1-codex-mini": GPT_5_MAX_REASONING_CAPABILITIES,
436
468
  "gpt-5.1": {
437
469
  reasoning: {
438
470
  supportsEffort: true,
@@ -443,6 +475,9 @@ var MODEL_CAPABILITIES = {
443
475
  "gpt-5": GPT_5_MINIMAL_REASONING_CAPABILITIES,
444
476
  "gpt-5-mini": GPT_5_MINIMAL_REASONING_CAPABILITIES,
445
477
  "gpt-5-nano": GPT_5_MINIMAL_REASONING_CAPABILITIES,
478
+ "gpt-5-pro": GPT_5_HIGH_REASONING_CAPABILITIES,
479
+ "gpt-5-codex": GPT_5_MAX_REASONING_CAPABILITIES,
480
+ "o3-pro": O_SERIES_MAX_REASONING_CAPABILITIES,
446
481
  o3: {
447
482
  reasoning: {
448
483
  supportsEffort: true,
package/dist/compat.d.ts CHANGED
@@ -1,11 +1,29 @@
1
+ import { ChatModel } from '@core-ai/core-ai';
2
+ import OpenAI from 'openai';
1
3
  import { O as OpenAIProvider, a as OpenAIProviderBaseOptions } from './provider-options-DzqvHoId.js';
2
4
  export { b as OpenAICompatGenerateProviderOptions, c as OpenAICompatRequestOptions, o as openaiCompatGenerateProviderOptionsSchema, d as openaiCompatProviderOptionsSchema } from './provider-options-DzqvHoId.js';
3
- import 'openai';
4
- import '@core-ai/core-ai';
5
5
  import 'zod';
6
6
 
7
+ type OpenAIChatClient = {
8
+ chat: OpenAI['chat'];
9
+ };
10
+ declare function createOpenAICompatChatModel(client: OpenAIChatClient, modelId: string, providerId?: string): ChatModel;
11
+
7
12
  type OpenAICompatProviderOptions = OpenAIProviderBaseOptions;
8
13
  type OpenAICompatProvider = OpenAIProvider;
9
14
  declare function createOpenAICompat(options?: OpenAICompatProviderOptions): OpenAICompatProvider;
15
+ type OpenAICompatChatProviderOptions = {
16
+ apiKey?: string;
17
+ baseURL?: string;
18
+ client?: OpenAIChatClient;
19
+ };
20
+ type OpenAICompatChatProvider = {
21
+ chatModel(modelId: string): ChatModel;
22
+ };
23
+ /**
24
+ * Creates a chat-only OpenAI-compatible provider. Handles client construction
25
+ * internally so consumers do not need a direct dependency on the `openai` package.
26
+ */
27
+ declare function createOpenAICompatChatProvider(options?: OpenAICompatChatProviderOptions, providerId?: string): OpenAICompatChatProvider;
10
28
 
11
- export { type OpenAICompatProvider, type OpenAICompatProviderOptions, createOpenAICompat };
29
+ export { type OpenAIChatClient, type OpenAICompatChatProvider, type OpenAICompatChatProviderOptions, type OpenAICompatProvider, type OpenAICompatProviderOptions, createOpenAICompat, createOpenAICompatChatModel, createOpenAICompatChatProvider };
package/dist/compat.js CHANGED
@@ -15,7 +15,10 @@ import {
15
15
  transformStructuredOutputStream,
16
16
  validateOpenAIReasoningConfig,
17
17
  wrapOpenAIError
18
- } from "./chunk-6CVAAVYM.js";
18
+ } from "./chunk-RPCZTXZS.js";
19
+
20
+ // src/compat/provider.ts
21
+ import OpenAI from "openai";
19
22
 
20
23
  // src/compat/chat-model.ts
21
24
  import { createObjectStream, createChatStream } from "@core-ai/core-ai";
@@ -369,15 +372,15 @@ function extractTextContent(content) {
369
372
  }
370
373
 
371
374
  // src/compat/chat-model.ts
372
- function createOpenAICompatChatModel(client, modelId) {
373
- const provider = "openai";
375
+ function createOpenAICompatChatModel(client, modelId, providerId = "openai") {
376
+ const provider = providerId;
374
377
  async function callOpenAIChatCompletionsApi(request, signal) {
375
378
  try {
376
379
  return await client.chat.completions.create(request, {
377
380
  signal
378
381
  });
379
382
  } catch (error) {
380
- throw wrapOpenAIError(error);
383
+ throw wrapOpenAIError(error, provider);
381
384
  }
382
385
  }
383
386
  async function generateChat(options) {
@@ -438,8 +441,19 @@ function createOpenAICompatChatModel(client, modelId) {
438
441
  function createOpenAICompat(options = {}) {
439
442
  return createOpenAIProvider(options, createOpenAICompatChatModel);
440
443
  }
444
+ function createOpenAICompatChatProvider(options = {}, providerId = "openai") {
445
+ const client = options.client ?? new OpenAI({
446
+ apiKey: options.apiKey,
447
+ baseURL: options.baseURL
448
+ });
449
+ return {
450
+ chatModel: (modelId) => createOpenAICompatChatModel(client, modelId, providerId)
451
+ };
452
+ }
441
453
  export {
442
454
  createOpenAICompat,
455
+ createOpenAICompatChatModel,
456
+ createOpenAICompatChatProvider,
443
457
  openaiCompatGenerateProviderOptionsSchema,
444
458
  openaiCompatProviderOptionsSchema
445
459
  };
package/dist/index.js CHANGED
@@ -19,7 +19,7 @@ import {
19
19
  transformStructuredOutputStream,
20
20
  validateOpenAIReasoningConfig,
21
21
  wrapOpenAIError
22
- } from "./chunk-6CVAAVYM.js";
22
+ } from "./chunk-RPCZTXZS.js";
23
23
 
24
24
  // src/chat-model.ts
25
25
  import { createObjectStream, createChatStream } from "@core-ai/core-ai";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@core-ai/openai",
3
- "version": "0.10.3",
3
+ "version": "0.11.1",
4
4
  "description": "OpenAI provider package for @core-ai/core-ai",
5
5
  "license": "MIT",
6
6
  "author": "Omnifact (https://omnifact.ai)",
@@ -22,11 +22,15 @@
22
22
  "exports": {
23
23
  ".": {
24
24
  "types": "./dist/index.d.ts",
25
- "import": "./dist/index.js"
25
+ "import": "./dist/index.js",
26
+ "require": "./dist/index.js",
27
+ "default": "./dist/index.js"
26
28
  },
27
29
  "./compat": {
28
30
  "types": "./dist/compat.d.ts",
29
- "import": "./dist/compat.js"
31
+ "import": "./dist/compat.js",
32
+ "require": "./dist/compat.js",
33
+ "default": "./dist/compat.js"
30
34
  }
31
35
  },
32
36
  "files": [
@@ -46,7 +50,7 @@
46
50
  "test:watch": "vitest"
47
51
  },
48
52
  "dependencies": {
49
- "@core-ai/core-ai": "^0.10.3",
53
+ "@core-ai/core-ai": "^0.11.1",
50
54
  "openai": "^6.1.0"
51
55
  },
52
56
  "peerDependencies": {