@core-ai/openai 0.19.0 → 0.20.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.
@@ -1395,6 +1395,8 @@ function resolveAdapterOptions(modelId, adapterOptions) {
1395
1395
  const capabilities = adapterOptions.capabilities ?? getOpenAIModelCapabilities(modelId);
1396
1396
  return {
1397
1397
  capabilities: toOpenAIResponsesCapabilities(capabilities),
1398
+ // Also the ownership key for encrypted reasoning metadata — Azure
1399
+ // (`azure-openai`) must not share the `openai` namespace.
1398
1400
  providerId: adapterOptions.providerId ?? DEFAULT_PROVIDER_ID
1399
1401
  };
1400
1402
  }
@@ -1403,11 +1405,12 @@ var REASONING_SUMMARY_SEPARATOR = "\n\n";
1403
1405
  var RESPONSES_AUDIO_REJECTION = "OpenAI Responses does not accept audio input; use provider.chat.chatModel() with an audio-capable Chat Completions model";
1404
1406
  function convertMessages2(messages, options = {}) {
1405
1407
  const includeReasoning = options.includeReasoning ?? true;
1408
+ const providerId = options.providerId ?? DEFAULT_PROVIDER_ID;
1406
1409
  return messages.flatMap(
1407
- (message) => convertMessage2(message, includeReasoning)
1410
+ (message) => convertMessage2(message, includeReasoning, providerId)
1408
1411
  );
1409
1412
  }
1410
- function convertMessage2(message, includeReasoning) {
1413
+ function convertMessage2(message, includeReasoning, providerId) {
1411
1414
  if (message.role === "system") {
1412
1415
  return [
1413
1416
  {
@@ -1425,7 +1428,11 @@ function convertMessage2(message, includeReasoning) {
1425
1428
  ];
1426
1429
  }
1427
1430
  if (message.role === "assistant") {
1428
- return convertAssistantMessage(message.parts, includeReasoning);
1431
+ return convertAssistantMessage(
1432
+ message.parts,
1433
+ includeReasoning,
1434
+ providerId
1435
+ );
1429
1436
  }
1430
1437
  return [
1431
1438
  {
@@ -1435,7 +1442,7 @@ function convertMessage2(message, includeReasoning) {
1435
1442
  }
1436
1443
  ];
1437
1444
  }
1438
- function convertAssistantMessage(parts, includeReasoning) {
1445
+ function convertAssistantMessage(parts, includeReasoning, providerId) {
1439
1446
  const items = [];
1440
1447
  const textParts = [];
1441
1448
  const flushTextBuffer = () => {
@@ -1456,7 +1463,7 @@ function convertAssistantMessage(parts, includeReasoning) {
1456
1463
  if (part.type === "reasoning") {
1457
1464
  if (!includeReasoning || getProviderMetadata2(
1458
1465
  part.providerMetadata,
1459
- "openai"
1466
+ providerId
1460
1467
  ) == null) {
1461
1468
  if (part.text.length > 0) {
1462
1469
  textParts.push(`<thinking>${part.text}</thinking>`);
@@ -1464,7 +1471,10 @@ function convertAssistantMessage(parts, includeReasoning) {
1464
1471
  continue;
1465
1472
  }
1466
1473
  flushTextBuffer();
1467
- const encryptedContent = getEncryptedReasoningContent(part);
1474
+ const encryptedContent = getEncryptedReasoningContent(
1475
+ part,
1476
+ providerId
1477
+ );
1468
1478
  items.push({
1469
1479
  type: "reasoning",
1470
1480
  summary: [
@@ -1488,13 +1498,20 @@ function convertAssistantMessage(parts, includeReasoning) {
1488
1498
  flushTextBuffer();
1489
1499
  return items;
1490
1500
  }
1491
- function getEncryptedReasoningContent(part) {
1501
+ function getEncryptedReasoningContent(part, providerId) {
1492
1502
  const { encryptedContent } = getProviderMetadata2(
1493
1503
  part.providerMetadata,
1494
- "openai"
1504
+ providerId
1495
1505
  ) ?? {};
1496
1506
  return typeof encryptedContent === "string" && encryptedContent.length > 0 ? encryptedContent : void 0;
1497
1507
  }
1508
+ function createReasoningProviderMetadata(providerId, encryptedContent) {
1509
+ return {
1510
+ [providerId]: {
1511
+ ...encryptedContent ? { encryptedContent } : {}
1512
+ }
1513
+ };
1514
+ }
1498
1515
  function convertUserContentPart2(part) {
1499
1516
  if (part.type === "text") {
1500
1517
  return {
@@ -1564,7 +1581,8 @@ function createRequestBase2(modelId, options, { capabilities, providerId }) {
1564
1581
  model: modelId,
1565
1582
  store: false,
1566
1583
  input: convertMessages2(options.messages, {
1567
- includeReasoning: capabilities.reasoning.mode !== "unsupported"
1584
+ includeReasoning: capabilities.reasoning.mode !== "unsupported",
1585
+ providerId
1568
1586
  }),
1569
1587
  ...options.tools && Object.keys(options.tools).length > 0 ? { tools: convertResponseTools(options.tools) } : {},
1570
1588
  ...options.toolChoice ? { tool_choice: convertResponseToolChoice(options.toolChoice) } : {},
@@ -1625,11 +1643,12 @@ function mapOpenAIProviderOptionsToRequestFields2(options) {
1625
1643
  ...options?.user !== void 0 ? { user: options.user } : {}
1626
1644
  };
1627
1645
  }
1628
- function mapGenerateResponse2(response) {
1646
+ function mapGenerateResponse2(response, adapterOptions = {}) {
1647
+ const providerId = adapterOptions.providerId ?? DEFAULT_PROVIDER_ID;
1629
1648
  const parts = [];
1630
1649
  for (const item of response.output) {
1631
1650
  if (isReasoningItem(item)) {
1632
- const reasoningPart = mapReasoningPart(item);
1651
+ const reasoningPart = mapReasoningPart(item, providerId);
1633
1652
  if (reasoningPart) {
1634
1653
  parts.push(reasoningPart);
1635
1654
  }
@@ -1662,7 +1681,7 @@ function mapGenerateResponse2(response) {
1662
1681
  usage: mapUsage(response.usage)
1663
1682
  };
1664
1683
  }
1665
- function mapReasoningPart(item) {
1684
+ function mapReasoningPart(item, providerId) {
1666
1685
  const text = getReasoningSummaryText(item.summary);
1667
1686
  const encryptedContent = typeof item.encrypted_content === "string" && item.encrypted_content.length > 0 ? item.encrypted_content : void 0;
1668
1687
  if (text.length === 0 && !encryptedContent) {
@@ -1671,9 +1690,10 @@ function mapReasoningPart(item) {
1671
1690
  return {
1672
1691
  type: "reasoning",
1673
1692
  text,
1674
- providerMetadata: {
1675
- openai: { ...encryptedContent ? { encryptedContent } : {} }
1676
- }
1693
+ providerMetadata: createReasoningProviderMetadata(
1694
+ providerId,
1695
+ encryptedContent
1696
+ )
1677
1697
  };
1678
1698
  }
1679
1699
  function getReasoningSummaryText(summary) {
@@ -1764,7 +1784,9 @@ function getReasoningEndTransition(reasoningStarted, providerMetadata) {
1764
1784
  }
1765
1785
  };
1766
1786
  }
1767
- async function* transformStream2(stream) {
1787
+ async function* transformStream2(stream, adapterOptions = {}) {
1788
+ const providerId = adapterOptions.providerId ?? DEFAULT_PROVIDER_ID;
1789
+ const emptyReasoningMetadata = createReasoningProviderMetadata(providerId);
1768
1790
  const bufferedToolCalls = /* @__PURE__ */ new Map();
1769
1791
  const emittedToolCalls = /* @__PURE__ */ new Set();
1770
1792
  const startedToolCalls = /* @__PURE__ */ new Set();
@@ -1870,7 +1892,9 @@ async function* transformStream2(stream) {
1870
1892
  continue;
1871
1893
  }
1872
1894
  if (event.type === "response.output_text.delta") {
1873
- const reasoningEndEvent2 = getNextReasoningEndEvent({ openai: {} });
1895
+ const reasoningEndEvent2 = getNextReasoningEndEvent(
1896
+ emptyReasoningMetadata
1897
+ );
1874
1898
  if (reasoningEndEvent2) {
1875
1899
  yield reasoningEndEvent2;
1876
1900
  }
@@ -1959,11 +1983,9 @@ async function* transformStream2(stream) {
1959
1983
  yield reasoningStartEvent;
1960
1984
  }
1961
1985
  }
1962
- const reasoningEndEvent2 = getNextReasoningEndEvent({
1963
- openai: {
1964
- ...encryptedContent ? { encryptedContent } : {}
1965
- }
1966
- });
1986
+ const reasoningEndEvent2 = getNextReasoningEndEvent(
1987
+ createReasoningProviderMetadata(providerId, encryptedContent)
1988
+ );
1967
1989
  if (reasoningEndEvent2) {
1968
1990
  yield reasoningEndEvent2;
1969
1991
  }
@@ -2002,7 +2024,9 @@ async function* transformStream2(stream) {
2002
2024
  if (event.type === "response.completed") {
2003
2025
  latestResponse = event.response;
2004
2026
  yield* closeText();
2005
- const reasoningEndEvent2 = getNextReasoningEndEvent({ openai: {} });
2027
+ const reasoningEndEvent2 = getNextReasoningEndEvent(
2028
+ emptyReasoningMetadata
2029
+ );
2006
2030
  if (reasoningEndEvent2) {
2007
2031
  yield reasoningEndEvent2;
2008
2032
  }
@@ -2031,9 +2055,7 @@ async function* transformStream2(stream) {
2031
2055
  return;
2032
2056
  }
2033
2057
  }
2034
- const reasoningEndEvent = getNextReasoningEndEvent({
2035
- openai: {}
2036
- });
2058
+ const reasoningEndEvent = getNextReasoningEndEvent(emptyReasoningMetadata);
2037
2059
  yield* closeText();
2038
2060
  if (reasoningEndEvent) {
2039
2061
  yield reasoningEndEvent;
@@ -2096,13 +2118,14 @@ function createOpenAIChatModel(client, modelId, capabilities, providerId = DEFAU
2096
2118
  request,
2097
2119
  options.signal
2098
2120
  );
2099
- return mapGenerateResponse2(response);
2121
+ return mapGenerateResponse2(response, { providerId: provider });
2100
2122
  }
2101
2123
  async function streamChat(options) {
2102
2124
  const request = createStreamRequest2(modelId, options, adapterOptions);
2103
2125
  return createChatStream2(
2104
2126
  async () => transformStream2(
2105
- await callOpenAIResponsesApi(request, options.signal)
2127
+ await callOpenAIResponsesApi(request, options.signal),
2128
+ { providerId: provider }
2106
2129
  ),
2107
2130
  { signal: options.signal }
2108
2131
  );
package/dist/compat.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  getOpenAIModelCapabilities,
5
5
  openaiCompatGenerateProviderOptionsSchema,
6
6
  openaiCompatProviderOptionsSchema
7
- } from "./chunk-UGCMGRDL.js";
7
+ } from "./chunk-MKAXZHMO.js";
8
8
 
9
9
  // src/compat/provider.ts
10
10
  import OpenAI from "openai";
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  openaiImageProviderOptionsSchema,
11
11
  openaiResponsesGenerateProviderOptionsSchema,
12
12
  openaiResponsesProviderOptionsSchema
13
- } from "./chunk-UGCMGRDL.js";
13
+ } from "./chunk-MKAXZHMO.js";
14
14
 
15
15
  // src/provider.ts
16
16
  function createOpenAI(options = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@core-ai/openai",
3
- "version": "0.19.0",
3
+ "version": "0.20.0",
4
4
  "description": "OpenAI provider package for @core-ai/core-ai",
5
5
  "license": "MIT",
6
6
  "author": "Omnifact (https://omnifact.ai)",
@@ -50,7 +50,7 @@
50
50
  "test:watch": "vitest"
51
51
  },
52
52
  "dependencies": {
53
- "@core-ai/core-ai": "^0.19.0",
53
+ "@core-ai/core-ai": "^0.20.0",
54
54
  "openai": "^6.46.0"
55
55
  },
56
56
  "peerDependencies": {