@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.
- package/dist/ApiConverter.cjs +2 -2
- package/dist/ApiConverter.js +1 -1
- package/dist/{CompletionService-DdWaAxq0.d.ts → CompletionService-C3BX0Ovy.d.ts} +4 -3
- package/dist/{CompletionService-D3a47vdU.d.cts → CompletionService-kNA17cfI.d.cts} +4 -3
- package/dist/auth/GeminiCodeAssistProjectResolver.cjs +6 -5
- package/dist/auth/GeminiCodeAssistProjectResolver.js +4 -3
- package/dist/{chunk-HRRYG2AX.js → chunk-23S5OPIO.js} +10 -1
- package/dist/chunk-25GXJCEZ.cjs +40 -0
- package/dist/chunk-2JYRIADS.js +40 -0
- package/dist/{chunk-4XMYPW46.cjs → chunk-4VLRHHFE.cjs} +75 -33
- package/dist/{chunk-VACWOIRE.cjs → chunk-4VZX5F4T.cjs} +39 -15
- package/dist/{chunk-C6OV7GCC.js → chunk-6CL5HTPQ.js} +44 -2
- package/dist/chunk-6QQG7YG3.cjs +153 -0
- package/dist/{chunk-3Q6Z6JTO.cjs → chunk-6VUQPOV3.cjs} +277 -86
- package/dist/chunk-7AK7B36B.cjs +44 -0
- package/dist/{chunk-5ZQBEOMD.js → chunk-AT7B7SOZ.js} +25 -2
- package/dist/{chunk-IK3KE3AU.js → chunk-DE2SRBFZ.js} +1 -1
- package/dist/chunk-DLXZEZWO.cjs +285 -0
- package/dist/{chunk-UHGVBFU3.js → chunk-EBLFCNPY.js} +38 -14
- package/dist/chunk-EJLH6NFT.cjs +166 -0
- package/dist/chunk-HVBBDBS3.cjs +350 -0
- package/dist/{chunk-46ZIFWYG.cjs → chunk-IIRPUVPH.cjs} +7 -1
- package/dist/{chunk-JWVTXXPX.cjs → chunk-KBM2W6UY.cjs} +8 -4
- package/dist/{chunk-PG7PS2NN.cjs → chunk-KCVJWJST.cjs} +14 -2
- package/dist/chunk-LB6EBS6Y.js +69 -0
- package/dist/{chunk-IWQAX3CS.js → chunk-LVUCAWMK.js} +1 -1
- package/dist/chunk-MKF46GNZ.js +350 -0
- package/dist/{chunk-HYN75H6G.cjs → chunk-MUHWHQVM.cjs} +1 -1
- package/dist/{chunk-MFZ5437A.js → chunk-N5T4M4GU.js} +1 -1
- package/dist/{chunk-BODMAL6G.js → chunk-OEWZUX4G.js} +262 -71
- package/dist/chunk-OF3BECU2.cjs +69 -0
- package/dist/{chunk-DDMRUL76.cjs → chunk-OKMJLEXX.cjs} +5 -5
- package/dist/chunk-OPRS4IQZ.js +153 -0
- package/dist/{chunk-D3TDKWRP.js → chunk-SIZQQD6T.js} +14 -2
- package/dist/{chunk-CGKLE6IW.cjs → chunk-SQYVORNP.cjs} +1219 -510
- package/dist/{chunk-6QZGDLL4.js → chunk-TOVPMMHM.js} +5 -1
- package/dist/{chunk-FH2P4OCD.js → chunk-UDCC7EMR.js} +976 -267
- package/dist/{chunk-ZLX3KGXX.js → chunk-UX7VWA46.js} +135 -23
- package/dist/{chunk-K52THW2C.cjs → chunk-V4TXMEJS.cjs} +5 -5
- package/dist/chunk-VRFBB5DB.js +44 -0
- package/dist/chunk-WB6PH56J.js +166 -0
- package/dist/{chunk-G2UTNSGU.js → chunk-WNKWAEUR.js} +7 -1
- package/dist/{chunk-SUEGJ75D.cjs → chunk-WYTEQ4Q5.cjs} +25 -2
- package/dist/{chunk-5ENKBSWO.js → chunk-YJVHCHQX.js} +42 -6
- package/dist/{chunk-VQY5W4YW.cjs → chunk-YK57NMIF.cjs} +44 -8
- package/dist/{chunk-KFI44N2R.cjs → chunk-YNJNTCSQ.cjs} +10 -1
- package/dist/completion/ApiKeyPoolService.cjs +12 -0
- package/dist/completion/ApiKeyPoolService.d.cts +6 -0
- package/dist/completion/ApiKeyPoolService.d.ts +6 -0
- package/dist/completion/ApiKeyPoolService.js +12 -0
- package/dist/completion/CompletionService.cjs +25 -23
- package/dist/completion/CompletionService.d.cts +2 -1
- package/dist/completion/CompletionService.d.ts +2 -1
- package/dist/completion/CompletionService.js +24 -22
- package/dist/completion.cjs +25 -23
- package/dist/completion.d.cts +2 -1
- package/dist/completion.d.ts +2 -1
- package/dist/completion.js +24 -22
- package/dist/index.cjs +49 -26
- package/dist/index.d.cts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +52 -29
- package/dist/{keyPolicy-Cp0FntZl.d.ts → keyPolicy-zdWTu3CQ.d.cts} +1 -1
- package/dist/{keyPolicy-Cp0FntZl.d.cts → keyPolicy-zdWTu3CQ.d.ts} +1 -1
- package/dist/outbound-api/quotaWarn.d.cts +1 -1
- package/dist/outbound-api/quotaWarn.d.ts +1 -1
- package/dist/outbound-api/routeResolver.cjs +2 -2
- package/dist/outbound-api/routeResolver.d.cts +4 -3
- package/dist/outbound-api/routeResolver.d.ts +4 -3
- package/dist/outbound-api/routeResolver.js +1 -1
- package/dist/outbound-api/subscriptionRegistryPort.d.cts +1 -0
- package/dist/outbound-api/subscriptionRegistryPort.d.ts +1 -0
- package/dist/outbound-api/types.d.cts +3 -2
- package/dist/outbound-api/types.d.ts +3 -2
- package/dist/outbound-api.cjs +47 -24
- package/dist/outbound-api.d.cts +127 -85
- package/dist/outbound-api.d.ts +127 -85
- package/dist/outbound-api.js +50 -27
- package/dist/pipeline/AccountAllowanceScheduling.cjs +15 -0
- package/dist/pipeline/AccountAllowanceScheduling.d.cts +90 -0
- package/dist/pipeline/AccountAllowanceScheduling.d.ts +90 -0
- package/dist/pipeline/AccountAllowanceScheduling.js +15 -0
- package/dist/pipeline/AccountAllowanceStore.cjs +20 -0
- package/dist/pipeline/AccountAllowanceStore.d.cts +77 -0
- package/dist/pipeline/AccountAllowanceStore.d.ts +77 -0
- package/dist/pipeline/AccountAllowanceStore.js +20 -0
- package/dist/pipeline/AuthSource.d.cts +11 -2
- package/dist/pipeline/AuthSource.d.ts +11 -2
- package/dist/pipeline/BoundAccountSelectionError.cjs +10 -0
- package/dist/pipeline/BoundAccountSelectionError.d.cts +28 -0
- package/dist/pipeline/BoundAccountSelectionError.d.ts +28 -0
- package/dist/pipeline/BoundAccountSelectionError.js +10 -0
- package/dist/pipeline/LlmConfigProviderAuth.d.cts +1 -0
- package/dist/pipeline/LlmConfigProviderAuth.d.ts +1 -0
- package/dist/pipeline/SubscriptionAccountHealth.cjs +4 -2
- package/dist/pipeline/SubscriptionAccountHealth.d.cts +34 -6
- package/dist/pipeline/SubscriptionAccountHealth.d.ts +34 -6
- package/dist/pipeline/SubscriptionAccountHealth.js +3 -1
- package/dist/pipeline/SubscriptionAuthSource.cjs +5 -2
- package/dist/pipeline/SubscriptionAuthSource.d.cts +1 -0
- package/dist/pipeline/SubscriptionAuthSource.d.ts +1 -0
- package/dist/pipeline/SubscriptionAuthSource.js +4 -1
- package/dist/pipeline/SubscriptionAuthStrategy.d.cts +8 -3
- package/dist/pipeline/SubscriptionAuthStrategy.d.ts +8 -3
- package/dist/pipeline/executeProviderCall.cjs +2 -2
- package/dist/pipeline/executeProviderCall.d.cts +8 -3
- package/dist/pipeline/executeProviderCall.d.ts +8 -3
- package/dist/pipeline/executeProviderCall.js +1 -1
- package/dist/pipeline/resolveProviderChain.d.cts +2 -3
- package/dist/pipeline/resolveProviderChain.d.ts +2 -3
- package/dist/pipeline/resolveSubscriptionChain.d.cts +1 -0
- package/dist/pipeline/resolveSubscriptionChain.d.ts +1 -0
- package/dist/pipeline/upstreamFetch.cjs +3 -2
- package/dist/pipeline/upstreamFetch.js +2 -1
- package/dist/ports/pricing-store.d.cts +4 -3
- package/dist/ports/pricing-store.d.ts +4 -3
- package/dist/ports.d.cts +4 -3
- package/dist/ports.d.ts +4 -3
- package/dist/provider-proxy/ProviderProxy.cjs +25 -23
- package/dist/provider-proxy/ProviderProxy.d.cts +1 -0
- package/dist/provider-proxy/ProviderProxy.d.ts +1 -0
- package/dist/provider-proxy/ProviderProxy.js +24 -22
- package/dist/provider-proxy/ingress/providerProxyShared.cjs +27 -23
- package/dist/provider-proxy/ingress/providerProxyShared.d.cts +34 -5
- package/dist/provider-proxy/ingress/providerProxyShared.d.ts +34 -5
- package/dist/provider-proxy/ingress/providerProxyShared.js +26 -22
- package/dist/provider-proxy/matchText.cjs +4 -2
- package/dist/provider-proxy/matchText.d.cts +41 -6
- package/dist/provider-proxy/matchText.d.ts +41 -6
- package/dist/provider-proxy/matchText.js +3 -1
- package/dist/provider-proxy/types.d.cts +30 -2
- package/dist/provider-proxy/types.d.ts +30 -2
- package/dist/provider-proxy.cjs +25 -23
- package/dist/provider-proxy.d.cts +1 -0
- package/dist/provider-proxy.d.ts +1 -0
- package/dist/provider-proxy.js +24 -22
- package/dist/{routeResolver-C4T7yClx.d.ts → routeResolver-CHTv_Bs5.d.ts} +1 -1
- package/dist/{routeResolver-CB3tvJKy.d.cts → routeResolver-kepxnfcC.d.cts} +1 -1
- package/dist/transformer/TransformerChainExecutor.cjs +2 -2
- package/dist/transformer/TransformerChainExecutor.js +1 -1
- package/dist/transformer/transformers/AnthropicTransformer.cjs +2 -2
- package/dist/transformer/transformers/AnthropicTransformer.js +1 -1
- package/dist/transformer/transformers/GeminiCodeAssistTransformer.cjs +3 -3
- package/dist/transformer/transformers/GeminiCodeAssistTransformer.js +2 -2
- package/dist/transformer/transformers/GeminiTransformer.cjs +3 -3
- package/dist/transformer/transformers/GeminiTransformer.js +2 -2
- package/dist/transformer/transformers/OpenAIResponseTransformer.cjs +2 -2
- package/dist/transformer/transformers/OpenAIResponseTransformer.d.cts +1 -1
- package/dist/transformer/transformers/OpenAIResponseTransformer.d.ts +1 -1
- package/dist/transformer/transformers/OpenAIResponseTransformer.js +1 -1
- package/dist/transformer/transformers/OpenAITransformer.cjs +6 -0
- package/dist/transformer/transformers/OpenAITransformer.d.cts +68 -0
- package/dist/transformer/transformers/OpenAITransformer.d.ts +68 -0
- package/dist/transformer/transformers/OpenAITransformer.js +6 -0
- package/dist/transformer/transformers.cjs +8 -14
- package/dist/transformer/transformers.d.cts +12 -48
- package/dist/transformer/transformers.d.ts +12 -48
- package/dist/transformer/transformers.js +12 -18
- package/dist/transformer/types.d.cts +17 -0
- package/dist/transformer/types.d.ts +17 -0
- package/dist/transformer.cjs +10 -11
- package/dist/transformer.d.cts +1 -2
- package/dist/transformer.d.ts +1 -2
- package/dist/transformer.js +9 -10
- package/dist/{types-B8Arpxn0.d.cts → types-H3wGZSOo.d.cts} +134 -7
- package/dist/{types-lgPYQuZS.d.ts → types-hsoKrVQS.d.ts} +134 -7
- package/dist/usage/pricing-engine.cjs +2 -2
- package/dist/usage/pricing-engine.d.cts +9 -1
- package/dist/usage/pricing-engine.d.ts +9 -1
- package/dist/usage/pricing-engine.js +1 -1
- package/dist/usage.cjs +2 -2
- package/dist/usage.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-7FEBOPJO.cjs +0 -50
- package/dist/chunk-DWKQZ2SK.cjs +0 -254
- package/dist/chunk-IAXWICZU.js +0 -69
- package/dist/chunk-IB3FDI4O.js +0 -50
- package/dist/chunk-OQWKZCXP.js +0 -242
- package/dist/chunk-QWBWGODS.cjs +0 -69
- package/dist/chunk-YMFAJFQT.cjs +0 -173
- package/dist/chunk-ZCIQ3L3R.cjs +0 -242
- package/dist/chunk-ZJZAOKI7.js +0 -254
- package/dist/transformer/transformers/OpenCodeGoTransformer.cjs +0 -6
- package/dist/transformer/transformers/OpenCodeGoTransformer.d.cts +0 -51
- package/dist/transformer/transformers/OpenCodeGoTransformer.d.ts +0 -51
- package/dist/transformer/transformers/OpenCodeGoTransformer.js +0 -6
- package/dist/transformer/transformers/ReasoningTransformer.cjs +0 -6
- package/dist/transformer/transformers/ReasoningTransformer.d.cts +0 -47
- package/dist/transformer/transformers/ReasoningTransformer.d.ts +0 -47
- package/dist/transformer/transformers/ReasoningTransformer.js +0 -6
|
@@ -104,24 +104,37 @@ var OpenAIResponseTransformer = (_class = class {constructor() { _class.prototyp
|
|
|
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
|
-
|
|
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 (
|
|
129
|
+
if (itemType === "custom_tool_call") {
|
|
119
130
|
const toolCall = {
|
|
120
131
|
id: (_nullishCoalesce(entry.call_id, () => ( entry.id))) || "",
|
|
121
132
|
type: "function",
|
|
122
133
|
function: {
|
|
123
134
|
name: entry.name || "",
|
|
124
|
-
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 = class {constructor() { _class.prototyp
|
|
|
132
145
|
}
|
|
133
146
|
continue;
|
|
134
147
|
}
|
|
135
|
-
|
|
136
|
-
if (role === "developer") {
|
|
148
|
+
if (itemType === "function_call_output") {
|
|
137
149
|
messages.push({
|
|
138
|
-
role: "
|
|
139
|
-
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: (_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 });
|
|
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 = class {constructor() { _class.prototyp
|
|
|
159
193
|
enabled: true
|
|
160
194
|
};
|
|
161
195
|
}
|
|
196
|
+
const tools = [];
|
|
162
197
|
if (_optionalChain([req, 'access', _9 => _9.tools, 'optionalAccess', _10 => _10.length])) {
|
|
163
|
-
|
|
164
|
-
type
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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 } : {}
|
|
169
220
|
}
|
|
170
|
-
}
|
|
221
|
+
};
|
|
171
222
|
}
|
|
172
223
|
return result;
|
|
173
224
|
}
|
|
@@ -208,13 +259,14 @@ var OpenAIResponseTransformer = (_class = class {constructor() { _class.prototyp
|
|
|
208
259
|
/**
|
|
209
260
|
* Transform OpenAI CC response → Response API format
|
|
210
261
|
*/
|
|
211
|
-
async transformResponseIn(response,
|
|
262
|
+
async transformResponseIn(response, context) {
|
|
212
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]);
|
|
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 = class {constructor() { _class.prototyp
|
|
|
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
|
}, _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
|
+
}
|
|
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.
|
|
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,9 +440,9 @@ 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
|
-
const message = _optionalChain([choices, 'optionalAccess',
|
|
445
|
+
const message = _optionalChain([choices, 'optionalAccess', _24 => _24[0], 'optionalAccess', _25 => _25.message]);
|
|
296
446
|
const output = [];
|
|
297
447
|
if (message) {
|
|
298
448
|
const contentParts = [];
|
|
@@ -303,16 +453,18 @@ function convertOpenAIJsonToResponseApi(data) {
|
|
|
303
453
|
output.push({ type: "message", role: "assistant", content: contentParts });
|
|
304
454
|
}
|
|
305
455
|
const toolCalls = message.tool_calls;
|
|
306
|
-
if (_optionalChain([toolCalls, 'optionalAccess',
|
|
456
|
+
if (_optionalChain([toolCalls, 'optionalAccess', _26 => _26.length])) {
|
|
307
457
|
for (const tc of toolCalls) {
|
|
308
458
|
const func = tc.function;
|
|
309
|
-
output.push(
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
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
|
+
);
|
|
316
468
|
}
|
|
317
469
|
}
|
|
318
470
|
}
|
|
@@ -346,7 +498,7 @@ function convertResponseApiStreamToOpenAI(responseApiStream) {
|
|
|
346
498
|
if (!isClosed) {
|
|
347
499
|
try {
|
|
348
500
|
controller.enqueue(encoder.encode(str));
|
|
349
|
-
} catch (
|
|
501
|
+
} catch (e4) {
|
|
350
502
|
isClosed = true;
|
|
351
503
|
}
|
|
352
504
|
}
|
|
@@ -378,7 +530,7 @@ function convertResponseApiStreamToOpenAI(responseApiStream) {
|
|
|
378
530
|
if (data === "[DONE]") continue;
|
|
379
531
|
try {
|
|
380
532
|
const event = JSON.parse(data);
|
|
381
|
-
model = event.model || _optionalChain([event, 'access',
|
|
533
|
+
model = event.model || _optionalChain([event, 'access', _29 => _29.response, 'optionalAccess', _30 => _30.model]) || model;
|
|
382
534
|
switch (event.type) {
|
|
383
535
|
case "response.output_text.delta":
|
|
384
536
|
if (event.delta) {
|
|
@@ -400,7 +552,7 @@ function convertResponseApiStreamToOpenAI(responseApiStream) {
|
|
|
400
552
|
break;
|
|
401
553
|
case "response.output_item.added": {
|
|
402
554
|
const item = event.item;
|
|
403
|
-
if (_optionalChain([item, 'optionalAccess',
|
|
555
|
+
if (_optionalChain([item, 'optionalAccess', _31 => _31.type]) !== "function_call") break;
|
|
404
556
|
if (!hasEmittedRole) {
|
|
405
557
|
emitChunk([{ index: 0, delta: { role: "assistant", content: null }, finish_reason: null }]);
|
|
406
558
|
hasEmittedRole = true;
|
|
@@ -436,7 +588,7 @@ function convertResponseApiStreamToOpenAI(responseApiStream) {
|
|
|
436
588
|
}
|
|
437
589
|
case "response.completed": {
|
|
438
590
|
const resp = event.response;
|
|
439
|
-
const respUsage = _optionalChain([resp, 'optionalAccess',
|
|
591
|
+
const respUsage = _optionalChain([resp, 'optionalAccess', _32 => _32.usage]);
|
|
440
592
|
const usage = respUsage ? {
|
|
441
593
|
prompt_tokens: respUsage.input_tokens || 0,
|
|
442
594
|
completion_tokens: respUsage.output_tokens || 0,
|
|
@@ -449,14 +601,14 @@ function convertResponseApiStreamToOpenAI(responseApiStream) {
|
|
|
449
601
|
case "error":
|
|
450
602
|
emitChunk([{
|
|
451
603
|
index: 0,
|
|
452
|
-
delta: { content: `[Error: ${_optionalChain([event, 'access',
|
|
604
|
+
delta: { content: `[Error: ${_optionalChain([event, 'access', _33 => _33.error, 'optionalAccess', _34 => _34.message]) || "Unknown error"}]` },
|
|
453
605
|
finish_reason: "stop"
|
|
454
606
|
}]);
|
|
455
607
|
break;
|
|
456
608
|
default:
|
|
457
609
|
break;
|
|
458
610
|
}
|
|
459
|
-
} catch (
|
|
611
|
+
} catch (e5) {
|
|
460
612
|
}
|
|
461
613
|
}
|
|
462
614
|
}
|
|
@@ -466,7 +618,7 @@ function convertResponseApiStreamToOpenAI(responseApiStream) {
|
|
|
466
618
|
if (!isClosed) {
|
|
467
619
|
try {
|
|
468
620
|
controller.close();
|
|
469
|
-
} catch (
|
|
621
|
+
} catch (e6) {
|
|
470
622
|
}
|
|
471
623
|
}
|
|
472
624
|
reader.releaseLock();
|
|
@@ -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;
|
|
@@ -492,7 +646,7 @@ function convertOpenAIStreamToResponseApi(openaiStream) {
|
|
|
492
646
|
if (!isClosed) {
|
|
493
647
|
try {
|
|
494
648
|
controller.enqueue(encoder.encode(str));
|
|
495
|
-
} catch (
|
|
649
|
+
} catch (e7) {
|
|
496
650
|
isClosed = true;
|
|
497
651
|
}
|
|
498
652
|
}
|
|
@@ -520,20 +674,40 @@ function convertOpenAIStreamToResponseApi(openaiStream) {
|
|
|
520
674
|
if (data === "[DONE]") continue;
|
|
521
675
|
try {
|
|
522
676
|
const chunk = JSON.parse(data);
|
|
523
|
-
const choice = _optionalChain([chunk, 'access',
|
|
677
|
+
const choice = _optionalChain([chunk, 'access', _35 => _35.choices, 'optionalAccess', _36 => _36[0]]);
|
|
524
678
|
model = chunk.model || model;
|
|
525
679
|
if (!choice) continue;
|
|
526
|
-
if (_optionalChain([choice, 'access',
|
|
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
|
+
}
|
|
527
695
|
accumulatedContent += choice.delta.content;
|
|
528
|
-
emitEvent({
|
|
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
|
-
|
|
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) {
|
|
531
705
|
emitEvent({
|
|
532
706
|
type: "response.reasoning_summary_text.delta",
|
|
533
|
-
delta:
|
|
707
|
+
delta: reasoningDelta
|
|
534
708
|
});
|
|
535
709
|
}
|
|
536
|
-
if (_optionalChain([choice, 'access',
|
|
710
|
+
if (_optionalChain([choice, 'access', _44 => _44.delta, 'optionalAccess', _45 => _45.tool_calls])) {
|
|
537
711
|
for (const tc of choice.delta.tool_calls) {
|
|
538
712
|
const tcIndex = typeof tc["index"] === "number" ? tc["index"] : 0;
|
|
539
713
|
const func = _nullishCoalesce(tc["function"], () => ( {}));
|
|
@@ -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 = {
|
|
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
|
+
};
|
|
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
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
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 (
|
|
577
|
-
|
|
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
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
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:
|
|
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({
|
|
@@ -618,7 +809,7 @@ function convertOpenAIStreamToResponseApi(openaiStream) {
|
|
|
618
809
|
}
|
|
619
810
|
});
|
|
620
811
|
}
|
|
621
|
-
} catch (
|
|
812
|
+
} catch (e8) {
|
|
622
813
|
}
|
|
623
814
|
}
|
|
624
815
|
}
|
|
@@ -628,7 +819,7 @@ function convertOpenAIStreamToResponseApi(openaiStream) {
|
|
|
628
819
|
if (!isClosed) {
|
|
629
820
|
try {
|
|
630
821
|
controller.close();
|
|
631
|
-
} catch (
|
|
822
|
+
} catch (e9) {
|
|
632
823
|
}
|
|
633
824
|
}
|
|
634
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;
|
|
@@ -59,6 +59,26 @@ function hasThinkingEnabled(request) {
|
|
|
59
59
|
}
|
|
60
60
|
return false;
|
|
61
61
|
}
|
|
62
|
+
function flattenToolResultContent(content) {
|
|
63
|
+
if (typeof content === "string") return content;
|
|
64
|
+
if (content == null) return "";
|
|
65
|
+
if (!Array.isArray(content)) return JSON.stringify(content);
|
|
66
|
+
const parts = [];
|
|
67
|
+
for (const block of content) {
|
|
68
|
+
if (typeof block === "string") {
|
|
69
|
+
parts.push(block);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (!block || typeof block !== "object") continue;
|
|
73
|
+
const typed = block;
|
|
74
|
+
if (typed.type === "image" || typed.type === "image_url") {
|
|
75
|
+
parts.push("[image omitted]");
|
|
76
|
+
} else if (typeof typed.text === "string") {
|
|
77
|
+
parts.push(typed.text);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return parts.filter((text) => text !== "").join("\n");
|
|
81
|
+
}
|
|
62
82
|
|
|
63
83
|
// src/api-converter/anthropic-to-openai.ts
|
|
64
84
|
function convertAnthropicToOpenAI(response) {
|
|
@@ -158,7 +178,7 @@ function convertAnthropicRequestToOpenAI(request) {
|
|
|
158
178
|
});
|
|
159
179
|
} else if (part.type === "tool_result") {
|
|
160
180
|
toolResultId = part.tool_use_id;
|
|
161
|
-
toolResultContent =
|
|
181
|
+
toolResultContent = flattenToolResultContent(part.content);
|
|
162
182
|
}
|
|
163
183
|
}
|
|
164
184
|
if (toolResultId && toolResultContent !== void 0) {
|
|
@@ -368,7 +388,10 @@ function convertOpenAIToAnthropic(request, config) {
|
|
|
368
388
|
const toolResult = {
|
|
369
389
|
type: "tool_result",
|
|
370
390
|
tool_use_id: msg.tool_call_id,
|
|
371
|
-
|
|
391
|
+
// An OpenAI tool message is normally a plain string, but a parts array
|
|
392
|
+
// must be flattened to text rather than stringified into a literal
|
|
393
|
+
// `[{"type":"text",…}]` envelope the model then has to read.
|
|
394
|
+
content: flattenToolResultContent(msg.content)
|
|
372
395
|
};
|
|
373
396
|
const lastMsg = messages[messages.length - 1];
|
|
374
397
|
if (lastMsg && lastMsg.role === "user" && Array.isArray(lastMsg.content)) {
|
|
@@ -28,7 +28,7 @@ async function executeProviderCall(ctx) {
|
|
|
28
28
|
}
|
|
29
29
|
const fetched = await fetchFn(url, headers, finalBody);
|
|
30
30
|
let response = fetched;
|
|
31
|
-
if (runResponseChain) {
|
|
31
|
+
if (runResponseChain && fetched.ok) {
|
|
32
32
|
response = await executor.executeResponseChain(
|
|
33
33
|
// Preserve the EXACT first arg each site passed: proxy → requestBody,
|
|
34
34
|
// unified ingresses → their pre-transform request. The caller supplies
|