@omnicross/core 0.1.5 → 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 (190) 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 +6 -5
  6. package/dist/auth/GeminiCodeAssistProjectResolver.js +4 -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-4XMYPW46.cjs → chunk-4VLRHHFE.cjs} +75 -33
  11. package/dist/{chunk-VACWOIRE.cjs → chunk-4VZX5F4T.cjs} +39 -15
  12. package/dist/{chunk-C6OV7GCC.js → chunk-6CL5HTPQ.js} +44 -2
  13. package/dist/chunk-6QQG7YG3.cjs +153 -0
  14. package/dist/{chunk-3Q6Z6JTO.cjs → chunk-6VUQPOV3.cjs} +277 -86
  15. package/dist/chunk-7AK7B36B.cjs +44 -0
  16. package/dist/{chunk-5ZQBEOMD.js → chunk-AT7B7SOZ.js} +25 -2
  17. package/dist/{chunk-IK3KE3AU.js → chunk-DE2SRBFZ.js} +1 -1
  18. package/dist/chunk-DLXZEZWO.cjs +285 -0
  19. package/dist/{chunk-UHGVBFU3.js → chunk-EBLFCNPY.js} +38 -14
  20. package/dist/chunk-EJLH6NFT.cjs +166 -0
  21. package/dist/chunk-HVBBDBS3.cjs +350 -0
  22. package/dist/{chunk-46ZIFWYG.cjs → chunk-IIRPUVPH.cjs} +7 -1
  23. package/dist/{chunk-JWVTXXPX.cjs → chunk-KBM2W6UY.cjs} +8 -4
  24. package/dist/{chunk-PG7PS2NN.cjs → chunk-KCVJWJST.cjs} +14 -2
  25. package/dist/chunk-LB6EBS6Y.js +69 -0
  26. package/dist/{chunk-IWQAX3CS.js → chunk-LVUCAWMK.js} +1 -1
  27. package/dist/chunk-MKF46GNZ.js +350 -0
  28. package/dist/{chunk-HYN75H6G.cjs → chunk-MUHWHQVM.cjs} +1 -1
  29. package/dist/{chunk-MFZ5437A.js → chunk-N5T4M4GU.js} +1 -1
  30. package/dist/{chunk-BODMAL6G.js → chunk-OEWZUX4G.js} +262 -71
  31. package/dist/chunk-OF3BECU2.cjs +69 -0
  32. package/dist/{chunk-DDMRUL76.cjs → chunk-OKMJLEXX.cjs} +5 -5
  33. package/dist/chunk-OPRS4IQZ.js +153 -0
  34. package/dist/{chunk-D3TDKWRP.js → chunk-SIZQQD6T.js} +14 -2
  35. package/dist/{chunk-CGKLE6IW.cjs → chunk-SQYVORNP.cjs} +1219 -510
  36. package/dist/{chunk-6QZGDLL4.js → chunk-TOVPMMHM.js} +5 -1
  37. package/dist/{chunk-FH2P4OCD.js → chunk-UDCC7EMR.js} +976 -267
  38. package/dist/{chunk-ZLX3KGXX.js → chunk-UX7VWA46.js} +135 -23
  39. package/dist/{chunk-K52THW2C.cjs → chunk-V4TXMEJS.cjs} +5 -5
  40. package/dist/chunk-VRFBB5DB.js +44 -0
  41. package/dist/chunk-WB6PH56J.js +166 -0
  42. package/dist/{chunk-G2UTNSGU.js → chunk-WNKWAEUR.js} +7 -1
  43. package/dist/{chunk-SUEGJ75D.cjs → chunk-WYTEQ4Q5.cjs} +25 -2
  44. package/dist/{chunk-5ENKBSWO.js → chunk-YJVHCHQX.js} +42 -6
  45. package/dist/{chunk-VQY5W4YW.cjs → chunk-YK57NMIF.cjs} +44 -8
  46. package/dist/{chunk-KFI44N2R.cjs → chunk-YNJNTCSQ.cjs} +10 -1
  47. package/dist/completion/ApiKeyPoolService.cjs +12 -0
  48. package/dist/completion/ApiKeyPoolService.d.cts +6 -0
  49. package/dist/completion/ApiKeyPoolService.d.ts +6 -0
  50. package/dist/completion/ApiKeyPoolService.js +12 -0
  51. package/dist/completion/CompletionService.cjs +25 -23
  52. package/dist/completion/CompletionService.d.cts +2 -1
  53. package/dist/completion/CompletionService.d.ts +2 -1
  54. package/dist/completion/CompletionService.js +24 -22
  55. package/dist/completion.cjs +25 -23
  56. package/dist/completion.d.cts +2 -1
  57. package/dist/completion.d.ts +2 -1
  58. package/dist/completion.js +24 -22
  59. package/dist/index.cjs +49 -26
  60. package/dist/index.d.cts +8 -8
  61. package/dist/index.d.ts +8 -8
  62. package/dist/index.js +52 -29
  63. package/dist/{keyPolicy-Cp0FntZl.d.ts → keyPolicy-zdWTu3CQ.d.cts} +1 -1
  64. package/dist/{keyPolicy-Cp0FntZl.d.cts → keyPolicy-zdWTu3CQ.d.ts} +1 -1
  65. package/dist/outbound-api/quotaWarn.d.cts +1 -1
  66. package/dist/outbound-api/quotaWarn.d.ts +1 -1
  67. package/dist/outbound-api/routeResolver.cjs +2 -2
  68. package/dist/outbound-api/routeResolver.d.cts +4 -3
  69. package/dist/outbound-api/routeResolver.d.ts +4 -3
  70. package/dist/outbound-api/routeResolver.js +1 -1
  71. package/dist/outbound-api/subscriptionRegistryPort.d.cts +1 -0
  72. package/dist/outbound-api/subscriptionRegistryPort.d.ts +1 -0
  73. package/dist/outbound-api/types.d.cts +3 -2
  74. package/dist/outbound-api/types.d.ts +3 -2
  75. package/dist/outbound-api.cjs +47 -24
  76. package/dist/outbound-api.d.cts +127 -85
  77. package/dist/outbound-api.d.ts +127 -85
  78. package/dist/outbound-api.js +50 -27
  79. package/dist/pipeline/AccountAllowanceScheduling.cjs +15 -0
  80. package/dist/pipeline/AccountAllowanceScheduling.d.cts +90 -0
  81. package/dist/pipeline/AccountAllowanceScheduling.d.ts +90 -0
  82. package/dist/pipeline/AccountAllowanceScheduling.js +15 -0
  83. package/dist/pipeline/AccountAllowanceStore.cjs +20 -0
  84. package/dist/pipeline/AccountAllowanceStore.d.cts +77 -0
  85. package/dist/pipeline/AccountAllowanceStore.d.ts +77 -0
  86. package/dist/pipeline/AccountAllowanceStore.js +20 -0
  87. package/dist/pipeline/AuthSource.d.cts +11 -2
  88. package/dist/pipeline/AuthSource.d.ts +11 -2
  89. package/dist/pipeline/BoundAccountSelectionError.cjs +10 -0
  90. package/dist/pipeline/BoundAccountSelectionError.d.cts +28 -0
  91. package/dist/pipeline/BoundAccountSelectionError.d.ts +28 -0
  92. package/dist/pipeline/BoundAccountSelectionError.js +10 -0
  93. package/dist/pipeline/LlmConfigProviderAuth.d.cts +1 -0
  94. package/dist/pipeline/LlmConfigProviderAuth.d.ts +1 -0
  95. package/dist/pipeline/SubscriptionAccountHealth.cjs +4 -2
  96. package/dist/pipeline/SubscriptionAccountHealth.d.cts +34 -6
  97. package/dist/pipeline/SubscriptionAccountHealth.d.ts +34 -6
  98. package/dist/pipeline/SubscriptionAccountHealth.js +3 -1
  99. package/dist/pipeline/SubscriptionAuthSource.cjs +5 -2
  100. package/dist/pipeline/SubscriptionAuthSource.d.cts +1 -0
  101. package/dist/pipeline/SubscriptionAuthSource.d.ts +1 -0
  102. package/dist/pipeline/SubscriptionAuthSource.js +4 -1
  103. package/dist/pipeline/SubscriptionAuthStrategy.d.cts +8 -3
  104. package/dist/pipeline/SubscriptionAuthStrategy.d.ts +8 -3
  105. package/dist/pipeline/executeProviderCall.cjs +2 -2
  106. package/dist/pipeline/executeProviderCall.d.cts +8 -3
  107. package/dist/pipeline/executeProviderCall.d.ts +8 -3
  108. package/dist/pipeline/executeProviderCall.js +1 -1
  109. package/dist/pipeline/resolveProviderChain.d.cts +2 -3
  110. package/dist/pipeline/resolveProviderChain.d.ts +2 -3
  111. package/dist/pipeline/resolveSubscriptionChain.d.cts +1 -0
  112. package/dist/pipeline/resolveSubscriptionChain.d.ts +1 -0
  113. package/dist/pipeline/upstreamFetch.cjs +3 -2
  114. package/dist/pipeline/upstreamFetch.js +2 -1
  115. package/dist/ports/pricing-store.d.cts +4 -3
  116. package/dist/ports/pricing-store.d.ts +4 -3
  117. package/dist/ports.d.cts +4 -3
  118. package/dist/ports.d.ts +4 -3
  119. package/dist/provider-proxy/ProviderProxy.cjs +25 -23
  120. package/dist/provider-proxy/ProviderProxy.d.cts +1 -0
  121. package/dist/provider-proxy/ProviderProxy.d.ts +1 -0
  122. package/dist/provider-proxy/ProviderProxy.js +24 -22
  123. package/dist/provider-proxy/ingress/providerProxyShared.cjs +27 -23
  124. package/dist/provider-proxy/ingress/providerProxyShared.d.cts +34 -5
  125. package/dist/provider-proxy/ingress/providerProxyShared.d.ts +34 -5
  126. package/dist/provider-proxy/ingress/providerProxyShared.js +26 -22
  127. package/dist/provider-proxy/matchText.cjs +4 -2
  128. package/dist/provider-proxy/matchText.d.cts +41 -6
  129. package/dist/provider-proxy/matchText.d.ts +41 -6
  130. package/dist/provider-proxy/matchText.js +3 -1
  131. package/dist/provider-proxy/types.d.cts +30 -2
  132. package/dist/provider-proxy/types.d.ts +30 -2
  133. package/dist/provider-proxy.cjs +25 -23
  134. package/dist/provider-proxy.d.cts +1 -0
  135. package/dist/provider-proxy.d.ts +1 -0
  136. package/dist/provider-proxy.js +24 -22
  137. package/dist/{routeResolver-C4T7yClx.d.ts → routeResolver-CHTv_Bs5.d.ts} +1 -1
  138. package/dist/{routeResolver-CB3tvJKy.d.cts → routeResolver-kepxnfcC.d.cts} +1 -1
  139. package/dist/transformer/TransformerChainExecutor.cjs +2 -2
  140. package/dist/transformer/TransformerChainExecutor.js +1 -1
  141. package/dist/transformer/transformers/AnthropicTransformer.cjs +2 -2
  142. package/dist/transformer/transformers/AnthropicTransformer.js +1 -1
  143. package/dist/transformer/transformers/GeminiCodeAssistTransformer.cjs +3 -3
  144. package/dist/transformer/transformers/GeminiCodeAssistTransformer.js +2 -2
  145. package/dist/transformer/transformers/GeminiTransformer.cjs +3 -3
  146. package/dist/transformer/transformers/GeminiTransformer.js +2 -2
  147. package/dist/transformer/transformers/OpenAIResponseTransformer.cjs +2 -2
  148. package/dist/transformer/transformers/OpenAIResponseTransformer.d.cts +1 -1
  149. package/dist/transformer/transformers/OpenAIResponseTransformer.d.ts +1 -1
  150. package/dist/transformer/transformers/OpenAIResponseTransformer.js +1 -1
  151. package/dist/transformer/transformers/OpenAITransformer.cjs +6 -0
  152. package/dist/transformer/transformers/OpenAITransformer.d.cts +68 -0
  153. package/dist/transformer/transformers/OpenAITransformer.d.ts +68 -0
  154. package/dist/transformer/transformers/OpenAITransformer.js +6 -0
  155. package/dist/transformer/transformers.cjs +8 -14
  156. package/dist/transformer/transformers.d.cts +12 -48
  157. package/dist/transformer/transformers.d.ts +12 -48
  158. package/dist/transformer/transformers.js +12 -18
  159. package/dist/transformer/types.d.cts +17 -0
  160. package/dist/transformer/types.d.ts +17 -0
  161. package/dist/transformer.cjs +10 -11
  162. package/dist/transformer.d.cts +1 -2
  163. package/dist/transformer.d.ts +1 -2
  164. package/dist/transformer.js +9 -10
  165. package/dist/{types-B8Arpxn0.d.cts → types-H3wGZSOo.d.cts} +134 -7
  166. package/dist/{types-lgPYQuZS.d.ts → types-hsoKrVQS.d.ts} +134 -7
  167. package/dist/usage/pricing-engine.cjs +2 -2
  168. package/dist/usage/pricing-engine.d.cts +9 -1
  169. package/dist/usage/pricing-engine.d.ts +9 -1
  170. package/dist/usage/pricing-engine.js +1 -1
  171. package/dist/usage.cjs +2 -2
  172. package/dist/usage.js +1 -1
  173. package/package.json +1 -1
  174. package/dist/chunk-7FEBOPJO.cjs +0 -50
  175. package/dist/chunk-DWKQZ2SK.cjs +0 -254
  176. package/dist/chunk-IAXWICZU.js +0 -69
  177. package/dist/chunk-IB3FDI4O.js +0 -50
  178. package/dist/chunk-OQWKZCXP.js +0 -242
  179. package/dist/chunk-QWBWGODS.cjs +0 -69
  180. package/dist/chunk-YMFAJFQT.cjs +0 -173
  181. package/dist/chunk-ZCIQ3L3R.cjs +0 -242
  182. package/dist/chunk-ZJZAOKI7.js +0 -254
  183. package/dist/transformer/transformers/OpenCodeGoTransformer.cjs +0 -6
  184. package/dist/transformer/transformers/OpenCodeGoTransformer.d.cts +0 -51
  185. package/dist/transformer/transformers/OpenCodeGoTransformer.d.ts +0 -51
  186. package/dist/transformer/transformers/OpenCodeGoTransformer.js +0 -6
  187. package/dist/transformer/transformers/ReasoningTransformer.cjs +0 -6
  188. package/dist/transformer/transformers/ReasoningTransformer.d.cts +0 -47
  189. package/dist/transformer/transformers/ReasoningTransformer.d.ts +0 -47
  190. package/dist/transformer/transformers/ReasoningTransformer.js +0 -6
@@ -104,24 +104,37 @@ var OpenAIResponseTransformer = class {
104
104
  async transformRequestOut(request, _context) {
105
105
  const req = request;
106
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
+ }
107
112
  if (req.input) {
108
113
  for (const item of req.input) {
109
114
  const entry = item;
110
- 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") {
111
122
  messages.push({
112
123
  role: "tool",
113
- content: entry.output || "",
124
+ content: flattenContent(entry.output),
114
125
  tool_call_id: entry.call_id || void 0
115
126
  });
116
127
  continue;
117
128
  }
118
- if (entry.type === "function_call") {
129
+ if (itemType === "custom_tool_call") {
119
130
  const toolCall = {
120
131
  id: (entry.call_id ?? entry.id) || "",
121
132
  type: "function",
122
133
  function: {
123
134
  name: entry.name || "",
124
- arguments: typeof entry.arguments === "string" ? entry.arguments : ""
135
+ arguments: JSON.stringify({
136
+ input: typeof entry.input === "string" ? entry.input : ""
137
+ })
125
138
  }
126
139
  };
127
140
  const last = messages[messages.length - 1];
@@ -132,17 +145,38 @@ var OpenAIResponseTransformer = class {
132
145
  }
133
146
  continue;
134
147
  }
135
- const role = entry.role;
136
- if (role === "developer") {
148
+ if (itemType === "function_call_output") {
137
149
  messages.push({
138
- role: "system",
139
- 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
140
153
  });
154
+ continue;
155
+ }
156
+ if (itemType === "function_call") {
157
+ const toolCall = {
158
+ id: (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 });
141
178
  } else if (role === "user" || role === "assistant") {
142
- messages.push({
143
- role,
144
- content: typeof entry.content === "string" ? entry.content : JSON.stringify(entry.content)
145
- });
179
+ messages.push({ role, content: text });
146
180
  }
147
181
  }
148
182
  }
@@ -159,15 +193,32 @@ var OpenAIResponseTransformer = class {
159
193
  enabled: true
160
194
  };
161
195
  }
196
+ const tools = [];
162
197
  if (req.tools?.length) {
163
- result.tools = req.tools.filter((t) => t.type === "function").map((t) => ({
164
- type: "function",
165
- function: {
166
- name: t.name || "",
167
- description: t.description || "",
168
- 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 (codexTools?.tools.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 (codexTools?.customToolNames.length || Object.keys(codexTools?.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 } : {}
169
220
  }
170
- }));
221
+ };
171
222
  }
172
223
  return result;
173
224
  }
@@ -208,13 +259,14 @@ var OpenAIResponseTransformer = class {
208
259
  /**
209
260
  * Transform OpenAI CC response → Response API format
210
261
  */
211
- async transformResponseIn(response, _context) {
262
+ async transformResponseIn(response, context) {
212
263
  const contentType = response.headers.get("Content-Type") ?? "";
264
+ const codexTools = context?.req?.meta?.codexTools;
213
265
  if (contentType.includes("text/event-stream")) {
214
266
  if (!response.body) {
215
267
  throw new Error("Stream response body is null");
216
268
  }
217
- return new Response(convertOpenAIStreamToResponseApi(response.body), {
269
+ return new Response(convertOpenAIStreamToResponseApi(response.body, codexTools), {
218
270
  headers: {
219
271
  "Content-Type": "text/event-stream",
220
272
  "Cache-Control": "no-cache",
@@ -223,16 +275,114 @@ var OpenAIResponseTransformer = class {
223
275
  });
224
276
  }
225
277
  const data = await response.json();
226
- return new Response(JSON.stringify(convertOpenAIJsonToResponseApi(data)), {
278
+ return new Response(JSON.stringify(convertOpenAIJsonToResponseApi(data, codexTools)), {
227
279
  headers: { "Content-Type": "application/json" }
228
280
  });
229
281
  }
230
282
  };
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 {
302
+ }
303
+ return argumentsJson;
304
+ }
305
+ function encodeToolCallItem(callId, name, argumentsJson, status, codexTools) {
306
+ const bareId = callId.replace(/^(call_|fc_|ctc_)/, "");
307
+ if (codexTools?.customToolNames?.includes(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 = codexTools?.toolNamespaces?.[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
+ }
231
370
  function flattenContent(content) {
232
371
  if (typeof content === "string") return content;
233
372
  if (!content) return "";
234
373
  if (Array.isArray(content)) {
235
- 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);
236
386
  }
237
387
  return "";
238
388
  }
@@ -290,7 +440,7 @@ function convertResponseApiJsonToOpenAI(data) {
290
440
  } : void 0
291
441
  };
292
442
  }
293
- function convertOpenAIJsonToResponseApi(data) {
443
+ function convertOpenAIJsonToResponseApi(data, codexTools) {
294
444
  const choices = data.choices;
295
445
  const message = choices?.[0]?.message;
296
446
  const output = [];
@@ -306,13 +456,15 @@ function convertOpenAIJsonToResponseApi(data) {
306
456
  if (toolCalls?.length) {
307
457
  for (const tc of toolCalls) {
308
458
  const func = tc.function;
309
- output.push({
310
- type: "function_call",
311
- id: tc.id,
312
- call_id: tc.id,
313
- name: func?.name,
314
- arguments: func?.arguments
315
- });
459
+ output.push(
460
+ encodeToolCallItem(
461
+ tc.id || "",
462
+ func?.name || "",
463
+ typeof func?.arguments === "string" ? func.arguments : "",
464
+ "completed",
465
+ codexTools
466
+ )
467
+ );
316
468
  }
317
469
  }
318
470
  }
@@ -474,7 +626,7 @@ function convertResponseApiStreamToOpenAI(responseApiStream) {
474
626
  }
475
627
  });
476
628
  }
477
- function convertOpenAIStreamToResponseApi(openaiStream) {
629
+ function convertOpenAIStreamToResponseApi(openaiStream, codexTools) {
478
630
  const decoder = new TextDecoder();
479
631
  const encoder = new TextEncoder();
480
632
  return new ReadableStream({
@@ -485,6 +637,8 @@ function convertOpenAIStreamToResponseApi(openaiStream) {
485
637
  let accumulatedContent = "";
486
638
  let model = "unknown";
487
639
  const responseId = `resp_${Date.now()}`;
640
+ const messageId = `msg_${Date.now()}`;
641
+ let messageItemAdded = false;
488
642
  const toolCalls = /* @__PURE__ */ new Map();
489
643
  const toolOutputIndex = /* @__PURE__ */ new Map();
490
644
  let nextOutputIndex = 1;
@@ -524,13 +678,33 @@ function convertOpenAIStreamToResponseApi(openaiStream) {
524
678
  model = chunk.model || model;
525
679
  if (!choice) continue;
526
680
  if (choice.delta?.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
+ }
527
695
  accumulatedContent += choice.delta.content;
528
- 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
+ });
529
702
  }
530
- if (choice.delta?.thinking?.content) {
703
+ const reasoningDelta = choice.delta?.thinking?.content ?? choice.delta?.reasoning_content;
704
+ if (reasoningDelta) {
531
705
  emitEvent({
532
706
  type: "response.reasoning_summary_text.delta",
533
- delta: choice.delta.thinking.content
707
+ delta: reasoningDelta
534
708
  });
535
709
  }
536
710
  if (choice.delta?.tool_calls) {
@@ -541,66 +715,83 @@ function convertOpenAIStreamToResponseApi(openaiStream) {
541
715
  if (!entry) {
542
716
  const callId = typeof tc["id"] === "string" ? tc["id"] : `call_${Date.now()}_${tcIndex}`;
543
717
  const name = typeof func["name"] === "string" ? func["name"] : "";
544
- entry = { callId, name, arguments: "" };
718
+ entry = {
719
+ callId,
720
+ name,
721
+ arguments: "",
722
+ isCustom: codexTools?.customToolNames?.includes(name) ?? false
723
+ };
545
724
  toolCalls.set(tcIndex, entry);
546
725
  const outIdx = nextOutputIndex++;
547
726
  toolOutputIndex.set(tcIndex, outIdx);
548
- const itemId = callId.startsWith("fc_") ? callId : `fc_${callId.replace(/^(call_|fc_)/, "")}`;
549
727
  emitEvent({
550
728
  type: "response.output_item.added",
551
729
  output_index: outIdx,
552
- item: {
553
- id: itemId,
554
- type: "function_call",
555
- status: "in_progress",
556
- call_id: callId,
557
- name,
558
- arguments: ""
559
- }
730
+ item: encodeToolCallItem(callId, name, "", "in_progress", codexTools)
560
731
  });
561
732
  }
562
733
  const argsFragment = typeof func["arguments"] === "string" ? func["arguments"] : "";
563
734
  if (argsFragment) {
564
735
  entry.arguments += argsFragment;
565
- emitEvent({
566
- type: "response.function_call_arguments.delta",
567
- output_index: toolOutputIndex.get(tcIndex),
568
- delta: argsFragment
569
- });
736
+ if (!entry.isCustom) {
737
+ emitEvent({
738
+ type: "response.function_call_arguments.delta",
739
+ output_index: toolOutputIndex.get(tcIndex),
740
+ delta: argsFragment
741
+ });
742
+ }
570
743
  }
571
744
  }
572
745
  }
573
746
  if (choice.finish_reason) {
574
- emitEvent({ type: "response.output_text.done", text: accumulatedContent });
575
747
  const output = [];
576
- if (accumulatedContent) {
577
- output.push({
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,
578
757
  type: "message",
579
758
  role: "assistant",
759
+ status: "completed",
580
760
  content: [{ type: "output_text", text: accumulatedContent }]
761
+ };
762
+ emitEvent({
763
+ type: "response.output_item.done",
764
+ output_index: 0,
765
+ item: messageItem
581
766
  });
767
+ output.push(messageItem);
582
768
  }
583
769
  for (const [tcIndex, entry] of toolCalls) {
584
- const itemId = entry.callId.startsWith("fc_") ? entry.callId : `fc_${entry.callId.replace(/^(call_|fc_)/, "")}`;
585
- output.push({
586
- id: itemId,
587
- type: "function_call",
588
- status: "completed",
589
- call_id: entry.callId,
590
- name: entry.name,
591
- arguments: entry.arguments
592
- });
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);
593
791
  emitEvent({
594
792
  type: "response.output_item.done",
595
- output_index: toolOutputIndex.get(tcIndex),
596
- item: {
597
- id: itemId,
598
- type: "function_call",
599
- status: "completed",
600
- call_id: entry.callId,
601
- name: entry.name,
602
- arguments: entry.arguments
603
- }
793
+ output_index: outIdx,
794
+ item
604
795
  });
605
796
  }
606
797
  emitEvent({
@@ -0,0 +1,69 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// src/transformer/transformers/OpenAITransformer.ts
2
+ var FOREIGN_MESSAGE_KEYS = ["cache_control", "thinking"];
3
+ var FOREIGN_BODY_KEYS = ["meta", "reasoning", "thinking"];
4
+ function normalizeContent(content) {
5
+ if (!Array.isArray(content)) return content;
6
+ const cleaned = content.map((block) => {
7
+ if (block && typeof block === "object" && "cache_control" in block) {
8
+ const { cache_control: _dropped, ...rest } = block;
9
+ return rest;
10
+ }
11
+ return block;
12
+ });
13
+ if (cleaned.length === 1) {
14
+ const only = cleaned[0];
15
+ if (_optionalChain([only, 'optionalAccess', _ => _.type]) === "text" && typeof only.text === "string") return only.text;
16
+ }
17
+ return cleaned;
18
+ }
19
+ var OpenAITransformer = (_class = class {constructor() { _class.prototype.__init.call(this);_class.prototype.__init2.call(this); }
20
+ static __initStatic() {this.TransformerName = "openai"}
21
+ __init() {this.name = "openai"}
22
+ __init2() {this.endPoint = "/v1/chat/completions"}
23
+
24
+ /**
25
+ * Unified → OpenAI Chat Completions.
26
+ */
27
+ async transformRequestIn(request, _provider, _context) {
28
+ const source = request;
29
+ const out = {};
30
+ for (const key of Object.keys(source)) {
31
+ if (FOREIGN_BODY_KEYS.includes(key)) continue;
32
+ out[key] = source[key];
33
+ }
34
+ if (Array.isArray(request.messages)) {
35
+ out.messages = request.messages.map((message) => {
36
+ const src = message;
37
+ const encoded = {};
38
+ for (const key of Object.keys(src)) {
39
+ if (FOREIGN_MESSAGE_KEYS.includes(key)) continue;
40
+ encoded[key] = src[key];
41
+ }
42
+ if (message.content !== void 0) {
43
+ encoded.content = normalizeContent(message.content);
44
+ }
45
+ const thinkingContent = _optionalChain([message, 'access', _2 => _2.thinking, 'optionalAccess', _3 => _3.content]);
46
+ if (typeof thinkingContent === "string" && thinkingContent.length > 0) {
47
+ encoded.reasoning_content = thinkingContent;
48
+ }
49
+ return encoded;
50
+ });
51
+ }
52
+ const effort = _optionalChain([request, 'access', _4 => _4.reasoning, 'optionalAccess', _5 => _5.effort]);
53
+ if (typeof effort === "string" && effort !== "none") {
54
+ out.reasoning_effort = effort;
55
+ }
56
+ return out;
57
+ }
58
+ /**
59
+ * OpenAI Chat Completions → Unified. Identity — see the module JSDoc for why
60
+ * `reasoning_content` is NOT rewritten here.
61
+ */
62
+ async transformResponseOut(response, _context) {
63
+ return response;
64
+ }
65
+ }, _class.__initStatic(), _class);
66
+
67
+
68
+
69
+ exports.OpenAITransformer = OpenAITransformer;
@@ -3,7 +3,7 @@
3
3
 
4
4
 
5
5
 
6
- var _chunkJWVTXXPXcjs = require('./chunk-JWVTXXPX.cjs');
6
+ var _chunkKBM2W6UYcjs = require('./chunk-KBM2W6UY.cjs');
7
7
 
8
8
  // src/transformer/transformers/GeminiCodeAssistTransformer.ts
9
9
  var DEFAULT_CODE_ASSIST_ENDPOINT = "https://cloudcode-pa.googleapis.com";
@@ -117,7 +117,7 @@ var GeminiCodeAssistTransformer = (_class = class {constructor() { _class.protot
117
117
  * openaiResponsesIngress). `undefined` is the valid fresh free-tier value.
118
118
  */
119
119
  async transformRequestIn(request, provider, _context) {
120
- const inner = _chunkJWVTXXPXcjs.buildRequestBody.call(void 0, request);
120
+ const inner = _chunkKBM2W6UYcjs.buildRequestBody.call(void 0, request);
121
121
  const envelope = {
122
122
  model: request.model,
123
123
  project: provider.geminiProject,
@@ -147,7 +147,7 @@ var GeminiCodeAssistTransformer = (_class = class {constructor() { _class.protot
147
147
  if (inner && typeof inner === "object" && !("model" in inner) && "model" in r) {
148
148
  inner.model = r.model;
149
149
  }
150
- return _chunkJWVTXXPXcjs.transformRequestOut.call(void 0, inner);
150
+ return _chunkKBM2W6UYcjs.transformRequestOut.call(void 0, inner);
151
151
  }
152
152
  /**
153
153
  * Code Assist response → OpenAI-compatible. PEEL the `.response` envelope from
@@ -155,7 +155,7 @@ var GeminiCodeAssistTransformer = (_class = class {constructor() { _class.protot
155
155
  */
156
156
  async transformResponseOut(response, _context) {
157
157
  const unwrapped = await unwrapCodeAssistResponse(response);
158
- return _chunkJWVTXXPXcjs.transformResponseOut.call(void 0, unwrapped, this.name, this.logger);
158
+ return _chunkKBM2W6UYcjs.transformResponseOut.call(void 0, unwrapped, this.name, this.logger);
159
159
  }
160
160
  /**
161
161
  * OpenAI-compatible response → Code Assist (endpoint-encode parity). Re-wraps
@@ -164,7 +164,7 @@ var GeminiCodeAssistTransformer = (_class = class {constructor() { _class.protot
164
164
  * `transformResponseOut`'s peel.
165
165
  */
166
166
  async transformResponseIn(response, _context) {
167
- const geminiResponse = await _chunkJWVTXXPXcjs.transformResponseIn.call(void 0, response, this.logger);
167
+ const geminiResponse = await _chunkKBM2W6UYcjs.transformResponseIn.call(void 0, response, this.logger);
168
168
  const contentType = _nullishCoalesce(geminiResponse.headers.get("Content-Type"), () => ( ""));
169
169
  if (contentType.includes("text/event-stream")) {
170
170
  return geminiResponse;