@omnicross/core 0.1.4 → 0.1.6

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 (204) hide show
  1. package/dist/ApiConverter.cjs +2 -2
  2. package/dist/ApiConverter.js +1 -1
  3. package/dist/{CompletionService-DdWaAxq0.d.ts → CompletionService-C3BX0Ovy.d.ts} +4 -3
  4. package/dist/{CompletionService-D3a47vdU.d.cts → CompletionService-kNA17cfI.d.cts} +4 -3
  5. package/dist/auth/GeminiCodeAssistProjectResolver.cjs +7 -5
  6. package/dist/auth/GeminiCodeAssistProjectResolver.js +5 -3
  7. package/dist/{chunk-HRRYG2AX.js → chunk-23S5OPIO.js} +10 -1
  8. package/dist/chunk-25GXJCEZ.cjs +40 -0
  9. package/dist/chunk-2JYRIADS.js +40 -0
  10. package/dist/chunk-3Z5BQZFM.cjs +52 -0
  11. package/dist/{chunk-4VAVYUZS.cjs → chunk-4VLRHHFE.cjs} +82 -40
  12. package/dist/{chunk-VACWOIRE.cjs → chunk-4VZX5F4T.cjs} +39 -15
  13. package/dist/{chunk-FTQ7IQUC.js → chunk-6CL5HTPQ.js} +52 -10
  14. package/dist/chunk-6QQG7YG3.cjs +153 -0
  15. package/dist/{chunk-SU2GCLAC.cjs → chunk-6VUQPOV3.cjs} +359 -60
  16. package/dist/chunk-7AK7B36B.cjs +44 -0
  17. package/dist/{chunk-5ZQBEOMD.js → chunk-AT7B7SOZ.js} +25 -2
  18. package/dist/{chunk-IK3KE3AU.js → chunk-DE2SRBFZ.js} +1 -1
  19. package/dist/chunk-DLXZEZWO.cjs +285 -0
  20. package/dist/{chunk-UHGVBFU3.js → chunk-EBLFCNPY.js} +38 -14
  21. package/dist/chunk-EJLH6NFT.cjs +166 -0
  22. package/dist/chunk-HVBBDBS3.cjs +350 -0
  23. package/dist/{chunk-7Y47UCF2.js → chunk-IFXJ2BG7.js} +5 -38
  24. package/dist/{chunk-46ZIFWYG.cjs → chunk-IIRPUVPH.cjs} +7 -1
  25. package/dist/{chunk-YGXJGRFI.cjs → chunk-KBM2W6UY.cjs} +111 -24
  26. package/dist/{chunk-OCEUVQHW.cjs → chunk-KCVJWJST.cjs} +73 -3
  27. package/dist/chunk-LB6EBS6Y.js +69 -0
  28. package/dist/{chunk-C7PSERMH.js → chunk-LVUCAWMK.js} +1 -1
  29. package/dist/chunk-MKF46GNZ.js +350 -0
  30. package/dist/{chunk-HYN75H6G.cjs → chunk-MUHWHQVM.cjs} +1 -1
  31. package/dist/{chunk-Z7Y2NPHY.js → chunk-N5T4M4GU.js} +1 -1
  32. package/dist/{chunk-TIER4SUC.js → chunk-OEWZUX4G.js} +346 -47
  33. package/dist/chunk-OF3BECU2.cjs +69 -0
  34. package/dist/{chunk-RSJ3TWJQ.cjs → chunk-OKMJLEXX.cjs} +5 -5
  35. package/dist/chunk-OPRS4IQZ.js +153 -0
  36. package/dist/{chunk-XK5CIRMQ.js → chunk-SIZQQD6T.js} +72 -2
  37. package/dist/{chunk-DKPXN34V.cjs → chunk-SQYVORNP.cjs} +1334 -510
  38. package/dist/chunk-SYQF7OIR.js +52 -0
  39. package/dist/{chunk-S4WBV25P.js → chunk-TOVPMMHM.js} +111 -24
  40. package/dist/{chunk-QYTT6GE3.js → chunk-UDCC7EMR.js} +1093 -269
  41. package/dist/{chunk-E3UCVHLP.cjs → chunk-UNWKG6EI.cjs} +5 -38
  42. package/dist/{chunk-ZLX3KGXX.js → chunk-UX7VWA46.js} +135 -23
  43. package/dist/{chunk-7YN22L2H.cjs → chunk-V4TXMEJS.cjs} +5 -5
  44. package/dist/chunk-VRFBB5DB.js +44 -0
  45. package/dist/chunk-WB6PH56J.js +166 -0
  46. package/dist/{chunk-G2UTNSGU.js → chunk-WNKWAEUR.js} +7 -1
  47. package/dist/{chunk-SUEGJ75D.cjs → chunk-WYTEQ4Q5.cjs} +25 -2
  48. package/dist/{chunk-5ENKBSWO.js → chunk-YJVHCHQX.js} +42 -6
  49. package/dist/{chunk-VQY5W4YW.cjs → chunk-YK57NMIF.cjs} +44 -8
  50. package/dist/{chunk-KFI44N2R.cjs → chunk-YNJNTCSQ.cjs} +10 -1
  51. package/dist/completion/ApiKeyPoolService.cjs +12 -0
  52. package/dist/completion/ApiKeyPoolService.d.cts +6 -0
  53. package/dist/completion/ApiKeyPoolService.d.ts +6 -0
  54. package/dist/completion/ApiKeyPoolService.js +12 -0
  55. package/dist/completion/CompletionService.cjs +27 -24
  56. package/dist/completion/CompletionService.d.cts +2 -1
  57. package/dist/completion/CompletionService.d.ts +2 -1
  58. package/dist/completion/CompletionService.js +26 -23
  59. package/dist/completion.cjs +27 -24
  60. package/dist/completion.d.cts +2 -1
  61. package/dist/completion.d.ts +2 -1
  62. package/dist/completion.js +26 -23
  63. package/dist/index.cjs +53 -29
  64. package/dist/index.d.cts +8 -8
  65. package/dist/index.d.ts +8 -8
  66. package/dist/index.js +56 -32
  67. package/dist/{keyPolicy-Cp0FntZl.d.cts → keyPolicy-zdWTu3CQ.d.cts} +1 -1
  68. package/dist/{keyPolicy-Cp0FntZl.d.ts → keyPolicy-zdWTu3CQ.d.ts} +1 -1
  69. package/dist/outbound-api/auditCapture.cjs +2 -2
  70. package/dist/outbound-api/auditCapture.d.cts +5 -3
  71. package/dist/outbound-api/auditCapture.d.ts +5 -3
  72. package/dist/outbound-api/auditCapture.js +1 -1
  73. package/dist/outbound-api/quotaWarn.d.cts +1 -1
  74. package/dist/outbound-api/quotaWarn.d.ts +1 -1
  75. package/dist/outbound-api/routeResolver.cjs +2 -2
  76. package/dist/outbound-api/routeResolver.d.cts +4 -3
  77. package/dist/outbound-api/routeResolver.d.ts +4 -3
  78. package/dist/outbound-api/routeResolver.js +1 -1
  79. package/dist/outbound-api/subscriptionRegistryPort.d.cts +1 -0
  80. package/dist/outbound-api/subscriptionRegistryPort.d.ts +1 -0
  81. package/dist/outbound-api/types.d.cts +3 -2
  82. package/dist/outbound-api/types.d.ts +3 -2
  83. package/dist/outbound-api.cjs +49 -25
  84. package/dist/outbound-api.d.cts +127 -85
  85. package/dist/outbound-api.d.ts +127 -85
  86. package/dist/outbound-api.js +52 -28
  87. package/dist/pipeline/AccountAllowanceScheduling.cjs +15 -0
  88. package/dist/pipeline/AccountAllowanceScheduling.d.cts +90 -0
  89. package/dist/pipeline/AccountAllowanceScheduling.d.ts +90 -0
  90. package/dist/pipeline/AccountAllowanceScheduling.js +15 -0
  91. package/dist/pipeline/AccountAllowanceStore.cjs +20 -0
  92. package/dist/pipeline/AccountAllowanceStore.d.cts +77 -0
  93. package/dist/pipeline/AccountAllowanceStore.d.ts +77 -0
  94. package/dist/pipeline/AccountAllowanceStore.js +20 -0
  95. package/dist/pipeline/AuthSource.d.cts +11 -2
  96. package/dist/pipeline/AuthSource.d.ts +11 -2
  97. package/dist/pipeline/BoundAccountSelectionError.cjs +10 -0
  98. package/dist/pipeline/BoundAccountSelectionError.d.cts +28 -0
  99. package/dist/pipeline/BoundAccountSelectionError.d.ts +28 -0
  100. package/dist/pipeline/BoundAccountSelectionError.js +10 -0
  101. package/dist/pipeline/LlmConfigProviderAuth.d.cts +1 -0
  102. package/dist/pipeline/LlmConfigProviderAuth.d.ts +1 -0
  103. package/dist/pipeline/SubscriptionAccountHealth.cjs +4 -2
  104. package/dist/pipeline/SubscriptionAccountHealth.d.cts +34 -6
  105. package/dist/pipeline/SubscriptionAccountHealth.d.ts +34 -6
  106. package/dist/pipeline/SubscriptionAccountHealth.js +3 -1
  107. package/dist/pipeline/SubscriptionAuthSource.cjs +5 -2
  108. package/dist/pipeline/SubscriptionAuthSource.d.cts +1 -0
  109. package/dist/pipeline/SubscriptionAuthSource.d.ts +1 -0
  110. package/dist/pipeline/SubscriptionAuthSource.js +4 -1
  111. package/dist/pipeline/SubscriptionAuthStrategy.d.cts +8 -3
  112. package/dist/pipeline/SubscriptionAuthStrategy.d.ts +8 -3
  113. package/dist/pipeline/executeProviderCall.cjs +2 -2
  114. package/dist/pipeline/executeProviderCall.d.cts +8 -3
  115. package/dist/pipeline/executeProviderCall.d.ts +8 -3
  116. package/dist/pipeline/executeProviderCall.js +1 -1
  117. package/dist/pipeline/resolveProviderChain.d.cts +2 -3
  118. package/dist/pipeline/resolveProviderChain.d.ts +2 -3
  119. package/dist/pipeline/resolveSubscriptionChain.d.cts +1 -0
  120. package/dist/pipeline/resolveSubscriptionChain.d.ts +1 -0
  121. package/dist/pipeline/upstreamFetch.cjs +4 -2
  122. package/dist/pipeline/upstreamFetch.d.cts +6 -0
  123. package/dist/pipeline/upstreamFetch.d.ts +6 -0
  124. package/dist/pipeline/upstreamFetch.js +3 -1
  125. package/dist/pipeline/upstreamTrace.cjs +14 -0
  126. package/dist/pipeline/upstreamTrace.d.cts +85 -0
  127. package/dist/pipeline/upstreamTrace.d.ts +85 -0
  128. package/dist/pipeline/upstreamTrace.js +14 -0
  129. package/dist/ports/pricing-store.d.cts +4 -3
  130. package/dist/ports/pricing-store.d.ts +4 -3
  131. package/dist/ports.d.cts +4 -3
  132. package/dist/ports.d.ts +4 -3
  133. package/dist/provider-proxy/ProviderProxy.cjs +27 -24
  134. package/dist/provider-proxy/ProviderProxy.d.cts +1 -0
  135. package/dist/provider-proxy/ProviderProxy.d.ts +1 -0
  136. package/dist/provider-proxy/ProviderProxy.js +26 -23
  137. package/dist/provider-proxy/ingress/providerProxyShared.cjs +31 -24
  138. package/dist/provider-proxy/ingress/providerProxyShared.d.cts +50 -5
  139. package/dist/provider-proxy/ingress/providerProxyShared.d.ts +50 -5
  140. package/dist/provider-proxy/ingress/providerProxyShared.js +30 -23
  141. package/dist/provider-proxy/matchText.cjs +4 -2
  142. package/dist/provider-proxy/matchText.d.cts +41 -6
  143. package/dist/provider-proxy/matchText.d.ts +41 -6
  144. package/dist/provider-proxy/matchText.js +3 -1
  145. package/dist/provider-proxy/types.d.cts +30 -2
  146. package/dist/provider-proxy/types.d.ts +30 -2
  147. package/dist/provider-proxy.cjs +27 -24
  148. package/dist/provider-proxy.d.cts +1 -0
  149. package/dist/provider-proxy.d.ts +1 -0
  150. package/dist/provider-proxy.js +26 -23
  151. package/dist/{routeResolver-C4T7yClx.d.ts → routeResolver-CHTv_Bs5.d.ts} +1 -1
  152. package/dist/{routeResolver-CB3tvJKy.d.cts → routeResolver-kepxnfcC.d.cts} +1 -1
  153. package/dist/transformer/TransformerChainExecutor.cjs +2 -2
  154. package/dist/transformer/TransformerChainExecutor.js +1 -1
  155. package/dist/transformer/transformers/AnthropicTransformer.cjs +2 -2
  156. package/dist/transformer/transformers/AnthropicTransformer.js +1 -1
  157. package/dist/transformer/transformers/GeminiCodeAssistTransformer.cjs +3 -3
  158. package/dist/transformer/transformers/GeminiCodeAssistTransformer.js +2 -2
  159. package/dist/transformer/transformers/GeminiTransformer.cjs +3 -3
  160. package/dist/transformer/transformers/GeminiTransformer.js +2 -2
  161. package/dist/transformer/transformers/OpenAIResponseTransformer.cjs +2 -2
  162. package/dist/transformer/transformers/OpenAIResponseTransformer.d.cts +1 -1
  163. package/dist/transformer/transformers/OpenAIResponseTransformer.d.ts +1 -1
  164. package/dist/transformer/transformers/OpenAIResponseTransformer.js +1 -1
  165. package/dist/transformer/transformers/OpenAITransformer.cjs +6 -0
  166. package/dist/transformer/transformers/OpenAITransformer.d.cts +68 -0
  167. package/dist/transformer/transformers/OpenAITransformer.d.ts +68 -0
  168. package/dist/transformer/transformers/OpenAITransformer.js +6 -0
  169. package/dist/transformer/transformers.cjs +8 -14
  170. package/dist/transformer/transformers.d.cts +12 -48
  171. package/dist/transformer/transformers.d.ts +12 -48
  172. package/dist/transformer/transformers.js +11 -17
  173. package/dist/transformer/types.d.cts +17 -0
  174. package/dist/transformer/types.d.ts +17 -0
  175. package/dist/transformer.cjs +11 -12
  176. package/dist/transformer.d.cts +1 -2
  177. package/dist/transformer.d.ts +1 -2
  178. package/dist/transformer.js +11 -12
  179. package/dist/{types-B8Arpxn0.d.cts → types-H3wGZSOo.d.cts} +134 -7
  180. package/dist/{types-lgPYQuZS.d.ts → types-hsoKrVQS.d.ts} +134 -7
  181. package/dist/usage/pricing-engine.cjs +2 -2
  182. package/dist/usage/pricing-engine.d.cts +9 -1
  183. package/dist/usage/pricing-engine.d.ts +9 -1
  184. package/dist/usage/pricing-engine.js +1 -1
  185. package/dist/usage.cjs +2 -2
  186. package/dist/usage.js +1 -1
  187. package/package.json +1 -1
  188. package/dist/chunk-C72S6TTV.cjs +0 -49
  189. package/dist/chunk-DWKQZ2SK.cjs +0 -254
  190. package/dist/chunk-IAXWICZU.js +0 -69
  191. package/dist/chunk-QWBWGODS.cjs +0 -69
  192. package/dist/chunk-RGTR7CIO.cjs +0 -235
  193. package/dist/chunk-VPBAUQ2M.js +0 -235
  194. package/dist/chunk-YMFAJFQT.cjs +0 -173
  195. package/dist/chunk-Z7LUNECE.js +0 -49
  196. package/dist/chunk-ZJZAOKI7.js +0 -254
  197. package/dist/transformer/transformers/OpenCodeGoTransformer.cjs +0 -6
  198. package/dist/transformer/transformers/OpenCodeGoTransformer.d.cts +0 -51
  199. package/dist/transformer/transformers/OpenCodeGoTransformer.d.ts +0 -51
  200. package/dist/transformer/transformers/OpenCodeGoTransformer.js +0 -6
  201. package/dist/transformer/transformers/ReasoningTransformer.cjs +0 -6
  202. package/dist/transformer/transformers/ReasoningTransformer.d.cts +0 -47
  203. package/dist/transformer/transformers/ReasoningTransformer.d.ts +0 -47
  204. package/dist/transformer/transformers/ReasoningTransformer.js +0 -6
@@ -45,10 +45,12 @@ var OpenAIResponseTransformer = (_class = class {constructor() { _class.prototyp
45
45
  if (msg.role === "assistant" && _optionalChain([msg, 'access', _ => _.tool_calls, 'optionalAccess', _2 => _2.length])) {
46
46
  input.push(entry);
47
47
  for (const tc of msg.tool_calls) {
48
+ const callId = tc.id;
49
+ const itemId = callId.startsWith("fc_") ? callId : `fc_${callId.replace(/^(call_|fc_)/, "")}`;
48
50
  input.push({
49
51
  type: "function_call",
50
- id: tc.id,
51
- call_id: tc.id,
52
+ id: itemId,
53
+ call_id: callId,
52
54
  name: tc.function.name,
53
55
  arguments: tc.function.arguments
54
56
  });
@@ -61,7 +63,11 @@ var OpenAIResponseTransformer = (_class = class {constructor() { _class.prototyp
61
63
  const body = {
62
64
  model: request.model,
63
65
  input,
64
- stream: _nullishCoalesce(request.stream, () => ( false)),
66
+ // codex's backend REQUIRES `stream:true` (it 400s with "Stream must be
67
+ // set to true" otherwise). Always force it; a non-streaming CLIENT is
68
+ // served by aggregating the SSE upstream of the wire (the ingress buffers
69
+ // it into a single message), not by asking codex for a non-streaming reply.
70
+ stream: true,
65
71
  // `store:false` is required by the codex backend and accepted by the
66
72
  // public Responses API (which defaults to store:true). Always set it so
67
73
  // codex relays (no discoverable url token) work without configuration.
@@ -98,24 +104,37 @@ var OpenAIResponseTransformer = (_class = class {constructor() { _class.prototyp
98
104
  async transformRequestOut(request, _context) {
99
105
  const req = request;
100
106
  const messages = [];
107
+ let codexTools = null;
108
+ const instructions = typeof req.instructions === "string" ? req.instructions.trim() : "";
109
+ if (instructions) {
110
+ messages.push({ role: "system", content: instructions });
111
+ }
101
112
  if (req.input) {
102
113
  for (const item of req.input) {
103
114
  const entry = item;
104
- if (entry.type === "function_call_output") {
115
+ const itemType = typeof entry.type === "string" ? entry.type : void 0;
116
+ if (itemType && SKIPPED_INPUT_ITEM_TYPES.has(itemType)) continue;
117
+ if (itemType === "additional_tools") {
118
+ codexTools = collectCodexTools(entry);
119
+ continue;
120
+ }
121
+ if (itemType === "custom_tool_call_output") {
105
122
  messages.push({
106
123
  role: "tool",
107
- content: entry.output || "",
124
+ content: flattenContent(entry.output),
108
125
  tool_call_id: entry.call_id || void 0
109
126
  });
110
127
  continue;
111
128
  }
112
- if (entry.type === "function_call") {
129
+ if (itemType === "custom_tool_call") {
113
130
  const toolCall = {
114
131
  id: (_nullishCoalesce(entry.call_id, () => ( entry.id))) || "",
115
132
  type: "function",
116
133
  function: {
117
134
  name: entry.name || "",
118
- arguments: typeof entry.arguments === "string" ? entry.arguments : ""
135
+ arguments: JSON.stringify({
136
+ input: typeof entry.input === "string" ? entry.input : ""
137
+ })
119
138
  }
120
139
  };
121
140
  const last = messages[messages.length - 1];
@@ -126,17 +145,38 @@ var OpenAIResponseTransformer = (_class = class {constructor() { _class.prototyp
126
145
  }
127
146
  continue;
128
147
  }
129
- const role = entry.role;
130
- if (role === "developer") {
148
+ if (itemType === "function_call_output") {
131
149
  messages.push({
132
- role: "system",
133
- content: typeof entry.content === "string" ? entry.content : JSON.stringify(entry.content)
150
+ role: "tool",
151
+ content: flattenContent(entry.output),
152
+ tool_call_id: entry.call_id || void 0
134
153
  });
154
+ continue;
155
+ }
156
+ if (itemType === "function_call") {
157
+ const toolCall = {
158
+ id: (_nullishCoalesce(entry.call_id, () => ( entry.id))) || "",
159
+ type: "function",
160
+ function: {
161
+ name: entry.name || "",
162
+ arguments: typeof entry.arguments === "string" ? entry.arguments : ""
163
+ }
164
+ };
165
+ const last = messages[messages.length - 1];
166
+ if (last && last.role === "assistant") {
167
+ (last.tool_calls ??= []).push(toolCall);
168
+ } else {
169
+ messages.push({ role: "assistant", content: null, tool_calls: [toolCall] });
170
+ }
171
+ continue;
172
+ }
173
+ const role = entry.role;
174
+ const text = flattenContent(entry.content);
175
+ if (!text) continue;
176
+ if (role === "developer" || role === "system") {
177
+ messages.push({ role: "system", content: text });
135
178
  } else if (role === "user" || role === "assistant") {
136
- messages.push({
137
- role,
138
- content: typeof entry.content === "string" ? entry.content : JSON.stringify(entry.content)
139
- });
179
+ messages.push({ role, content: text });
140
180
  }
141
181
  }
142
182
  }
@@ -153,15 +193,32 @@ var OpenAIResponseTransformer = (_class = class {constructor() { _class.prototyp
153
193
  enabled: true
154
194
  };
155
195
  }
196
+ const tools = [];
156
197
  if (_optionalChain([req, 'access', _9 => _9.tools, 'optionalAccess', _10 => _10.length])) {
157
- result.tools = req.tools.filter((t) => t.type === "function").map((t) => ({
158
- type: "function",
159
- function: {
160
- name: t.name || "",
161
- description: t.description || "",
162
- parameters: t.parameters || {}
198
+ tools.push(
199
+ ...req.tools.filter((t) => t.type === "function").map((t) => ({
200
+ type: "function",
201
+ function: {
202
+ name: t.name || "",
203
+ description: t.description || "",
204
+ parameters: t.parameters || {}
205
+ }
206
+ }))
207
+ );
208
+ }
209
+ if (_optionalChain([codexTools, 'optionalAccess', _11 => _11.tools, 'access', _12 => _12.length])) {
210
+ const declared = new Set(tools.map((t) => t.function.name));
211
+ tools.push(...codexTools.tools.filter((t) => !declared.has(t.function.name)));
212
+ }
213
+ if (tools.length) result.tools = tools;
214
+ if (_optionalChain([codexTools, 'optionalAccess', _13 => _13.customToolNames, 'access', _14 => _14.length]) || Object.keys(_nullishCoalesce(_optionalChain([codexTools, 'optionalAccess', _15 => _15.toolNamespaces]), () => ( {}))).length) {
215
+ result.meta = {
216
+ ...result.meta,
217
+ codexTools: {
218
+ ...codexTools.customToolNames.length ? { customToolNames: codexTools.customToolNames } : {},
219
+ ...Object.keys(codexTools.toolNamespaces).length ? { toolNamespaces: codexTools.toolNamespaces } : {}
163
220
  }
164
- }));
221
+ };
165
222
  }
166
223
  return result;
167
224
  }
@@ -202,13 +259,14 @@ var OpenAIResponseTransformer = (_class = class {constructor() { _class.prototyp
202
259
  /**
203
260
  * Transform OpenAI CC response → Response API format
204
261
  */
205
- async transformResponseIn(response, _context) {
262
+ async transformResponseIn(response, context) {
206
263
  const contentType = _nullishCoalesce(response.headers.get("Content-Type"), () => ( ""));
264
+ const codexTools = _optionalChain([context, 'optionalAccess', _16 => _16.req, 'optionalAccess', _17 => _17.meta, 'optionalAccess', _18 => _18.codexTools]);
207
265
  if (contentType.includes("text/event-stream")) {
208
266
  if (!response.body) {
209
267
  throw new Error("Stream response body is null");
210
268
  }
211
- return new Response(convertOpenAIStreamToResponseApi(response.body), {
269
+ return new Response(convertOpenAIStreamToResponseApi(response.body, codexTools), {
212
270
  headers: {
213
271
  "Content-Type": "text/event-stream",
214
272
  "Cache-Control": "no-cache",
@@ -217,16 +275,114 @@ var OpenAIResponseTransformer = (_class = class {constructor() { _class.prototyp
217
275
  });
218
276
  }
219
277
  const data = await response.json();
220
- return new Response(JSON.stringify(convertOpenAIJsonToResponseApi(data)), {
278
+ return new Response(JSON.stringify(convertOpenAIJsonToResponseApi(data, codexTools)), {
221
279
  headers: { "Content-Type": "application/json" }
222
280
  });
223
281
  }
224
282
  }, _class.__initStatic(), _class);
283
+ var TEXT_PART_TYPES = /* @__PURE__ */ new Set(["text", "input_text", "output_text", "summary_text"]);
284
+ var SKIPPED_INPUT_ITEM_TYPES = /* @__PURE__ */ new Set(["reasoning", "agent_message"]);
285
+ var CUSTOM_TOOL_PARAMETERS = {
286
+ type: "object",
287
+ properties: {
288
+ input: {
289
+ type: "string",
290
+ description: "The complete free-form input for this tool, passed through verbatim."
291
+ }
292
+ },
293
+ required: ["input"]
294
+ };
295
+ function unwrapCustomToolInput(argumentsJson) {
296
+ try {
297
+ const parsed = JSON.parse(argumentsJson);
298
+ if (parsed && typeof parsed === "object" && typeof parsed.input === "string") {
299
+ return parsed.input;
300
+ }
301
+ } catch (e3) {
302
+ }
303
+ return argumentsJson;
304
+ }
305
+ function encodeToolCallItem(callId, name, argumentsJson, status, codexTools) {
306
+ const bareId = callId.replace(/^(call_|fc_|ctc_)/, "");
307
+ if (_optionalChain([codexTools, 'optionalAccess', _19 => _19.customToolNames, 'optionalAccess', _20 => _20.includes, 'call', _21 => _21(name)])) {
308
+ return {
309
+ id: `ctc_${bareId}`,
310
+ type: "custom_tool_call",
311
+ status,
312
+ call_id: callId,
313
+ name,
314
+ input: unwrapCustomToolInput(argumentsJson)
315
+ };
316
+ }
317
+ const namespace = _optionalChain([codexTools, 'optionalAccess', _22 => _22.toolNamespaces, 'optionalAccess', _23 => _23[name]]);
318
+ return {
319
+ id: callId.startsWith("fc_") ? callId : `fc_${bareId}`,
320
+ type: "function_call",
321
+ status,
322
+ call_id: callId,
323
+ name,
324
+ ...namespace ? { namespace } : {},
325
+ arguments: argumentsJson
326
+ };
327
+ }
328
+ function collectCodexTools(entry) {
329
+ const result = { tools: [], customToolNames: [], toolNamespaces: {} };
330
+ const visit = (declarations, namespace) => {
331
+ if (!Array.isArray(declarations)) return;
332
+ for (const raw of declarations) {
333
+ if (!raw || typeof raw !== "object") continue;
334
+ const tool = raw;
335
+ const name = typeof tool.name === "string" ? tool.name : "";
336
+ if (!name) continue;
337
+ const description = typeof tool.description === "string" ? tool.description : "";
338
+ if (tool.type === "namespace") {
339
+ visit(tool.tools, name);
340
+ continue;
341
+ }
342
+ if (tool.type === "custom") {
343
+ result.customToolNames.push(name);
344
+ result.tools.push({
345
+ type: "function",
346
+ function: {
347
+ name,
348
+ description,
349
+ parameters: CUSTOM_TOOL_PARAMETERS
350
+ }
351
+ });
352
+ } else if (tool.type === "function") {
353
+ result.tools.push({
354
+ type: "function",
355
+ function: {
356
+ name,
357
+ description,
358
+ parameters: tool.parameters || {}
359
+ }
360
+ });
361
+ } else {
362
+ continue;
363
+ }
364
+ if (namespace) result.toolNamespaces[name] = namespace;
365
+ }
366
+ };
367
+ visit(entry.tools);
368
+ return result;
369
+ }
225
370
  function flattenContent(content) {
226
371
  if (typeof content === "string") return content;
227
372
  if (!content) return "";
228
373
  if (Array.isArray(content)) {
229
- return content.filter((c) => c.type === "text").map((c) => c.text || "").join("\n");
374
+ return content.map((part) => {
375
+ if (typeof part === "string") return part;
376
+ if (!part || typeof part !== "object") return "";
377
+ const c = part;
378
+ if (typeof c.type === "string" && !TEXT_PART_TYPES.has(c.type)) return "";
379
+ return typeof c.text === "string" ? c.text : "";
380
+ }).filter((text) => text !== "").join("\n");
381
+ }
382
+ if (typeof content === "object") {
383
+ const obj = content;
384
+ if (typeof obj.text === "string") return obj.text;
385
+ if (Array.isArray(obj.content)) return flattenContent(obj.content);
230
386
  }
231
387
  return "";
232
388
  }
@@ -284,9 +440,9 @@ function convertResponseApiJsonToOpenAI(data) {
284
440
  } : void 0
285
441
  };
286
442
  }
287
- function convertOpenAIJsonToResponseApi(data) {
443
+ function convertOpenAIJsonToResponseApi(data, codexTools) {
288
444
  const choices = data.choices;
289
- const message = _optionalChain([choices, 'optionalAccess', _11 => _11[0], 'optionalAccess', _12 => _12.message]);
445
+ const message = _optionalChain([choices, 'optionalAccess', _24 => _24[0], 'optionalAccess', _25 => _25.message]);
290
446
  const output = [];
291
447
  if (message) {
292
448
  const contentParts = [];
@@ -297,16 +453,18 @@ function convertOpenAIJsonToResponseApi(data) {
297
453
  output.push({ type: "message", role: "assistant", content: contentParts });
298
454
  }
299
455
  const toolCalls = message.tool_calls;
300
- if (_optionalChain([toolCalls, 'optionalAccess', _13 => _13.length])) {
456
+ if (_optionalChain([toolCalls, 'optionalAccess', _26 => _26.length])) {
301
457
  for (const tc of toolCalls) {
302
458
  const func = tc.function;
303
- output.push({
304
- type: "function_call",
305
- id: tc.id,
306
- call_id: tc.id,
307
- name: _optionalChain([func, 'optionalAccess', _14 => _14.name]),
308
- arguments: _optionalChain([func, 'optionalAccess', _15 => _15.arguments])
309
- });
459
+ output.push(
460
+ encodeToolCallItem(
461
+ tc.id || "",
462
+ _optionalChain([func, 'optionalAccess', _27 => _27.name]) || "",
463
+ typeof _optionalChain([func, 'optionalAccess', _28 => _28.arguments]) === "string" ? func.arguments : "",
464
+ "completed",
465
+ codexTools
466
+ )
467
+ );
310
468
  }
311
469
  }
312
470
  }
@@ -335,11 +493,12 @@ function convertResponseApiStreamToOpenAI(responseApiStream) {
335
493
  const messageId = `chatcmpl-${Date.now()}`;
336
494
  let model = "unknown";
337
495
  let hasEmittedRole = false;
496
+ let hasToolCalls = false;
338
497
  const safeEnqueue = (str) => {
339
498
  if (!isClosed) {
340
499
  try {
341
500
  controller.enqueue(encoder.encode(str));
342
- } catch (e3) {
501
+ } catch (e4) {
343
502
  isClosed = true;
344
503
  }
345
504
  }
@@ -371,7 +530,7 @@ function convertResponseApiStreamToOpenAI(responseApiStream) {
371
530
  if (data === "[DONE]") continue;
372
531
  try {
373
532
  const event = JSON.parse(data);
374
- model = event.model || _optionalChain([event, 'access', _16 => _16.response, 'optionalAccess', _17 => _17.model]) || model;
533
+ model = event.model || _optionalChain([event, 'access', _29 => _29.response, 'optionalAccess', _30 => _30.model]) || model;
375
534
  switch (event.type) {
376
535
  case "response.output_text.delta":
377
536
  if (event.delta) {
@@ -391,29 +550,65 @@ function convertResponseApiStreamToOpenAI(responseApiStream) {
391
550
  }]);
392
551
  }
393
552
  break;
553
+ case "response.output_item.added": {
554
+ const item = event.item;
555
+ if (_optionalChain([item, 'optionalAccess', _31 => _31.type]) !== "function_call") break;
556
+ if (!hasEmittedRole) {
557
+ emitChunk([{ index: 0, delta: { role: "assistant", content: null }, finish_reason: null }]);
558
+ hasEmittedRole = true;
559
+ }
560
+ hasToolCalls = true;
561
+ emitChunk([{
562
+ index: 0,
563
+ delta: {
564
+ tool_calls: [{
565
+ index: _nullishCoalesce(event.output_index, () => ( 0)),
566
+ id: item.call_id,
567
+ type: "function",
568
+ function: { name: item.name, arguments: "" }
569
+ }]
570
+ },
571
+ finish_reason: null
572
+ }]);
573
+ break;
574
+ }
575
+ case "response.function_call_arguments.delta": {
576
+ hasToolCalls = true;
577
+ emitChunk([{
578
+ index: 0,
579
+ delta: {
580
+ tool_calls: [{
581
+ index: _nullishCoalesce(event.output_index, () => ( 0)),
582
+ function: { arguments: _nullishCoalesce(event.delta, () => ( "")) }
583
+ }]
584
+ },
585
+ finish_reason: null
586
+ }]);
587
+ break;
588
+ }
394
589
  case "response.completed": {
395
590
  const resp = event.response;
396
- const respUsage = _optionalChain([resp, 'optionalAccess', _18 => _18.usage]);
591
+ const respUsage = _optionalChain([resp, 'optionalAccess', _32 => _32.usage]);
397
592
  const usage = respUsage ? {
398
593
  prompt_tokens: respUsage.input_tokens || 0,
399
594
  completion_tokens: respUsage.output_tokens || 0,
400
595
  total_tokens: (respUsage.input_tokens || 0) + (respUsage.output_tokens || 0)
401
596
  } : void 0;
402
- emitChunk([{ index: 0, delta: {}, finish_reason: "stop" }], usage);
597
+ emitChunk([{ index: 0, delta: {}, finish_reason: hasToolCalls ? "tool_calls" : "stop" }], usage);
403
598
  safeEnqueue("data: [DONE]\n\n");
404
599
  break;
405
600
  }
406
601
  case "error":
407
602
  emitChunk([{
408
603
  index: 0,
409
- delta: { content: `[Error: ${_optionalChain([event, 'access', _19 => _19.error, 'optionalAccess', _20 => _20.message]) || "Unknown error"}]` },
604
+ delta: { content: `[Error: ${_optionalChain([event, 'access', _33 => _33.error, 'optionalAccess', _34 => _34.message]) || "Unknown error"}]` },
410
605
  finish_reason: "stop"
411
606
  }]);
412
607
  break;
413
608
  default:
414
609
  break;
415
610
  }
416
- } catch (e4) {
611
+ } catch (e5) {
417
612
  }
418
613
  }
419
614
  }
@@ -423,7 +618,7 @@ function convertResponseApiStreamToOpenAI(responseApiStream) {
423
618
  if (!isClosed) {
424
619
  try {
425
620
  controller.close();
426
- } catch (e5) {
621
+ } catch (e6) {
427
622
  }
428
623
  }
429
624
  reader.releaseLock();
@@ -431,7 +626,7 @@ function convertResponseApiStreamToOpenAI(responseApiStream) {
431
626
  }
432
627
  });
433
628
  }
434
- function convertOpenAIStreamToResponseApi(openaiStream) {
629
+ function convertOpenAIStreamToResponseApi(openaiStream, codexTools) {
435
630
  const decoder = new TextDecoder();
436
631
  const encoder = new TextEncoder();
437
632
  return new ReadableStream({
@@ -442,11 +637,16 @@ function convertOpenAIStreamToResponseApi(openaiStream) {
442
637
  let accumulatedContent = "";
443
638
  let model = "unknown";
444
639
  const responseId = `resp_${Date.now()}`;
640
+ const messageId = `msg_${Date.now()}`;
641
+ let messageItemAdded = false;
642
+ const toolCalls = /* @__PURE__ */ new Map();
643
+ const toolOutputIndex = /* @__PURE__ */ new Map();
644
+ let nextOutputIndex = 1;
445
645
  const safeEnqueue = (str) => {
446
646
  if (!isClosed) {
447
647
  try {
448
648
  controller.enqueue(encoder.encode(str));
449
- } catch (e6) {
649
+ } catch (e7) {
450
650
  isClosed = true;
451
651
  }
452
652
  }
@@ -474,34 +674,133 @@ function convertOpenAIStreamToResponseApi(openaiStream) {
474
674
  if (data === "[DONE]") continue;
475
675
  try {
476
676
  const chunk = JSON.parse(data);
477
- const choice = _optionalChain([chunk, 'access', _21 => _21.choices, 'optionalAccess', _22 => _22[0]]);
677
+ const choice = _optionalChain([chunk, 'access', _35 => _35.choices, 'optionalAccess', _36 => _36[0]]);
478
678
  model = chunk.model || model;
479
679
  if (!choice) continue;
480
- if (_optionalChain([choice, 'access', _23 => _23.delta, 'optionalAccess', _24 => _24.content])) {
680
+ if (_optionalChain([choice, 'access', _37 => _37.delta, 'optionalAccess', _38 => _38.content])) {
681
+ if (!messageItemAdded) {
682
+ messageItemAdded = true;
683
+ emitEvent({
684
+ type: "response.output_item.added",
685
+ output_index: 0,
686
+ item: {
687
+ id: messageId,
688
+ type: "message",
689
+ role: "assistant",
690
+ status: "in_progress",
691
+ content: []
692
+ }
693
+ });
694
+ }
481
695
  accumulatedContent += choice.delta.content;
482
- emitEvent({ type: "response.output_text.delta", delta: choice.delta.content });
696
+ emitEvent({
697
+ type: "response.output_text.delta",
698
+ output_index: 0,
699
+ content_index: 0,
700
+ delta: choice.delta.content
701
+ });
483
702
  }
484
- if (_optionalChain([choice, 'access', _25 => _25.delta, 'optionalAccess', _26 => _26.thinking, 'optionalAccess', _27 => _27.content])) {
703
+ const reasoningDelta = _nullishCoalesce(_optionalChain([choice, 'access', _39 => _39.delta, 'optionalAccess', _40 => _40.thinking, 'optionalAccess', _41 => _41.content]), () => ( _optionalChain([choice, 'access', _42 => _42.delta, 'optionalAccess', _43 => _43.reasoning_content])));
704
+ if (reasoningDelta) {
485
705
  emitEvent({
486
706
  type: "response.reasoning_summary_text.delta",
487
- delta: choice.delta.thinking.content
707
+ delta: reasoningDelta
488
708
  });
489
709
  }
710
+ if (_optionalChain([choice, 'access', _44 => _44.delta, 'optionalAccess', _45 => _45.tool_calls])) {
711
+ for (const tc of choice.delta.tool_calls) {
712
+ const tcIndex = typeof tc["index"] === "number" ? tc["index"] : 0;
713
+ const func = _nullishCoalesce(tc["function"], () => ( {}));
714
+ let entry = toolCalls.get(tcIndex);
715
+ if (!entry) {
716
+ const callId = typeof tc["id"] === "string" ? tc["id"] : `call_${Date.now()}_${tcIndex}`;
717
+ const name = typeof func["name"] === "string" ? func["name"] : "";
718
+ entry = {
719
+ callId,
720
+ name,
721
+ arguments: "",
722
+ isCustom: _nullishCoalesce(_optionalChain([codexTools, 'optionalAccess', _46 => _46.customToolNames, 'optionalAccess', _47 => _47.includes, 'call', _48 => _48(name)]), () => ( false))
723
+ };
724
+ toolCalls.set(tcIndex, entry);
725
+ const outIdx = nextOutputIndex++;
726
+ toolOutputIndex.set(tcIndex, outIdx);
727
+ emitEvent({
728
+ type: "response.output_item.added",
729
+ output_index: outIdx,
730
+ item: encodeToolCallItem(callId, name, "", "in_progress", codexTools)
731
+ });
732
+ }
733
+ const argsFragment = typeof func["arguments"] === "string" ? func["arguments"] : "";
734
+ if (argsFragment) {
735
+ entry.arguments += argsFragment;
736
+ if (!entry.isCustom) {
737
+ emitEvent({
738
+ type: "response.function_call_arguments.delta",
739
+ output_index: toolOutputIndex.get(tcIndex),
740
+ delta: argsFragment
741
+ });
742
+ }
743
+ }
744
+ }
745
+ }
490
746
  if (choice.finish_reason) {
491
- emitEvent({ type: "response.output_text.done", text: accumulatedContent });
747
+ const output = [];
748
+ if (messageItemAdded) {
749
+ emitEvent({
750
+ type: "response.output_text.done",
751
+ output_index: 0,
752
+ content_index: 0,
753
+ text: accumulatedContent
754
+ });
755
+ const messageItem = {
756
+ id: messageId,
757
+ type: "message",
758
+ role: "assistant",
759
+ status: "completed",
760
+ content: [{ type: "output_text", text: accumulatedContent }]
761
+ };
762
+ emitEvent({
763
+ type: "response.output_item.done",
764
+ output_index: 0,
765
+ item: messageItem
766
+ });
767
+ output.push(messageItem);
768
+ }
769
+ for (const [tcIndex, entry] of toolCalls) {
770
+ const outIdx = toolOutputIndex.get(tcIndex);
771
+ const item = encodeToolCallItem(
772
+ entry.callId,
773
+ entry.name,
774
+ entry.arguments,
775
+ "completed",
776
+ codexTools
777
+ );
778
+ if (entry.isCustom) {
779
+ emitEvent({
780
+ type: "response.custom_tool_call_input.delta",
781
+ output_index: outIdx,
782
+ delta: item.input
783
+ });
784
+ emitEvent({
785
+ type: "response.custom_tool_call_input.done",
786
+ output_index: outIdx,
787
+ input: item.input
788
+ });
789
+ }
790
+ output.push(item);
791
+ emitEvent({
792
+ type: "response.output_item.done",
793
+ output_index: outIdx,
794
+ item
795
+ });
796
+ }
492
797
  emitEvent({
493
798
  type: "response.completed",
494
799
  response: {
495
800
  id: responseId,
496
801
  status: "completed",
497
802
  model,
498
- output: [
499
- {
500
- type: "message",
501
- role: "assistant",
502
- content: [{ type: "output_text", text: accumulatedContent }]
503
- }
504
- ],
803
+ output,
505
804
  usage: chunk.usage ? {
506
805
  input_tokens: chunk.usage.prompt_tokens || 0,
507
806
  output_tokens: chunk.usage.completion_tokens || 0,
@@ -510,7 +809,7 @@ function convertOpenAIStreamToResponseApi(openaiStream) {
510
809
  }
511
810
  });
512
811
  }
513
- } catch (e7) {
812
+ } catch (e8) {
514
813
  }
515
814
  }
516
815
  }
@@ -520,7 +819,7 @@ function convertOpenAIStreamToResponseApi(openaiStream) {
520
819
  if (!isClosed) {
521
820
  try {
522
821
  controller.close();
523
- } catch (e8) {
822
+ } catch (e9) {
524
823
  }
525
824
  }
526
825
  reader.releaseLock();
@@ -0,0 +1,44 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkV4TXMEJScjs = require('./chunk-V4TXMEJS.cjs');
4
+
5
+
6
+ var _chunk6VUQPOV3cjs = require('./chunk-6VUQPOV3.cjs');
7
+
8
+
9
+ var _chunkOF3BECU2cjs = require('./chunk-OF3BECU2.cjs');
10
+
11
+
12
+ var _chunk4VLRHHFEcjs = require('./chunk-4VLRHHFE.cjs');
13
+
14
+
15
+ var _chunkOKMJLEXXcjs = require('./chunk-OKMJLEXX.cjs');
16
+
17
+ // src/transformer/transformers/index.ts
18
+ var BuiltinTransformers = {
19
+ OpenAITransformer: _chunkOF3BECU2cjs.OpenAITransformer,
20
+ GeminiTransformer: _chunkV4TXMEJScjs.GeminiTransformer,
21
+ GeminiCodeAssistTransformer: _chunkOKMJLEXXcjs.GeminiCodeAssistTransformer,
22
+ AnthropicTransformer: _chunk4VLRHHFEcjs.AnthropicTransformer,
23
+ OpenAIResponseTransformer: _chunk6VUQPOV3cjs.OpenAIResponseTransformer
24
+ };
25
+ function getBuiltinTransformers() {
26
+ return BuiltinTransformers;
27
+ }
28
+ var BUILTIN_TRANSFORMER_NAMES = [
29
+ "openai",
30
+ "gemini",
31
+ "gemini-code-assist",
32
+ "anthropic",
33
+ "openai-response"
34
+ ];
35
+ async function registerBuiltinTransformers(service) {
36
+ await service.initialize(getBuiltinTransformers());
37
+ }
38
+
39
+
40
+
41
+
42
+
43
+
44
+ exports.BuiltinTransformers = BuiltinTransformers; exports.getBuiltinTransformers = getBuiltinTransformers; exports.BUILTIN_TRANSFORMER_NAMES = BUILTIN_TRANSFORMER_NAMES; exports.registerBuiltinTransformers = registerBuiltinTransformers;