mapigate 0.5.133 → 0.5.136
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/README.md +1 -1
- package/dist/core/adapters/anthropic/requestAnthropicToOpenAi.js +59 -11
- package/dist/core/adapters/anthropicAdapter.js +2 -2
- package/dist/providers/catalog/commandcode/converter.js +215 -0
- package/dist/providers/catalog/commandcode/executor.js +305 -0
- package/dist/providers/catalog/commandcode/headers.js +76 -0
- package/dist/providers/catalog/commandcode/metadata.js +4 -1
- package/dist/providers/catalog/commandcode/ndjson.js +161 -0
- package/dist/providers/catalog/commandcode/provider.js +18 -35
- package/dist/providers/catalog/commandcode/routes.js +75 -0
- package/dist/providers/catalog/opencode-go/metadata.js +4 -2
- package/dist/providers/catalog/opencode-go/models.js +1 -0
- package/dist/providers/catalog/opencode-go/provider.js +114 -0
- package/dist/providers/catalog/opencode-go/quota.js +106 -0
- package/dist/providers/catalog/opencode-go/responses.js +301 -0
- package/dist/providers/catalog/opencode-go/responsesPayload.js +228 -0
- package/dist/providers/catalog/sensenova/metadata.js +35 -0
- package/dist/providers/core/base/baseProvider.js +3 -0
- package/dist/providers/core/base/openAiProvider.js +3 -1
- package/dist/providers/generated/routesRegistry.generated.js +2 -0
- package/dist/providers/runtime/antigravity/schema.js +19 -1
- package/dist/providers/runtime/codebuddy/provider.js +21 -6
- package/dist/providers/runtime/kiro/executor.js +7 -4
- package/dist/providers/runtime/kiro/models.js +11 -0
- package/dist/providers/runtime/kiro/provider.js +7 -7
- package/dist/providers/runtime/opencode/tools.js +38 -16
- package/dist/server/proxy/proxyDispatcher.js +136 -17
- package/dist/server/proxy/singleModelExecutor.js +14 -2
- package/dist/shared/utils/dnsResolver.js +69 -27
- package/dist/web/assets/{CliToolsTab-D4DkK7Rn.js → CliToolsTab-CkzwuwaC.js} +1 -1
- package/dist/web/assets/{CombosTab-X1C_OmzI.js → CombosTab-C5RzRwwr.js} +1 -1
- package/dist/web/assets/{ConfirmModal-CuQ7ARxt.js → ConfirmModal-DGvcf0gB.js} +1 -1
- package/dist/web/assets/{ConsoleLogTab-B2sfhYZW.js → ConsoleLogTab-84Ens8T5.js} +1 -1
- package/dist/web/assets/{EditAccountModal-BusNJLvX.js → EditAccountModal-D-_omvev.js} +1 -1
- package/dist/web/assets/{EndpointTab-DQCezUA9.js → EndpointTab-7nBfEdYE.js} +1 -1
- package/dist/web/assets/{MitmTab-DxEuD0DW.js → MitmTab-CqS6mXHZ.js} +1 -1
- package/dist/web/assets/{ModelAutocompleteInput-CgJ2FlEf.js → ModelAutocompleteInput-B9syrV1O.js} +1 -1
- package/dist/web/assets/ProviderDetailPage-DGZceQ2d.js +6 -0
- package/dist/web/assets/{ProvidersTab-pZoM69s4.js → ProvidersTab-CiYbqRou.js} +1 -1
- package/dist/web/assets/{QuotaTab-CvXGyICr.js → QuotaTab-DFr0DWAU.js} +1 -1
- package/dist/web/assets/{SettingsTab-D7YF7rTP.js → SettingsTab-4c0ksNJa.js} +1 -1
- package/dist/web/assets/{UsageTab-B0YCftIJ.js → UsageTab-BQcPmvtQ.js} +1 -1
- package/dist/web/assets/{index-DTRst7wN.js → index-C4NTQZ40.js} +2 -2
- package/dist/web/assets/{index-BisuNW2y.css → index-HnsyZg0I.css} +1 -1
- package/dist/web/assets/metadataRegistry-B91sal4r.js +1 -0
- package/dist/web/assets/providersData-DkVCRBsJ.js +1 -0
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/dist/web/assets/ProviderDetailPage-DMA1DVSN.js +0 -6
- package/dist/web/assets/metadataRegistry-BPZSXiBy.js +0 -1
- package/dist/web/assets/providersData-Bsv7o5VV.js +0 -1
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { AnthropicAdapter } from "../../../core/adapters/anthropicAdapter.js";
|
|
2
|
+
import { executeUpstreamFetch } from "../../../server/proxy/proxyDispatcher.js";
|
|
3
|
+
import { ResponseLogger } from "../../../server/proxy/responseLogger.js";
|
|
4
|
+
import { SettingsRepository } from "../../../storage/repositories/settingsRepo.js";
|
|
5
|
+
import { logger, LogSymbol, formatDoneLine } from "../../../shared/logger.js";
|
|
6
|
+
import { OPENCODE_GO_RESPONSES_URL, isOpenCodeGoResponsesModel, buildOpenCodeGoResponsesPayload, } from "./responsesPayload.js";
|
|
7
|
+
export { OPENCODE_GO_RESPONSES_URL, isOpenCodeGoResponsesModel, buildOpenCodeGoResponsesPayload };
|
|
8
|
+
function recordResponsesSuccess(context, targetModel, usage, fullText, clientResponse) {
|
|
9
|
+
const { req, startTime, requestId, reqTag = "OCG" } = context;
|
|
10
|
+
const durationMs = Date.now() - startTime;
|
|
11
|
+
const inTok = usage?.prompt_tokens || context.rtkStats?.compressedTokens || 0;
|
|
12
|
+
const outTok = usage?.completion_tokens || Math.ceil(fullText.length / 4);
|
|
13
|
+
const calculatedCost = ResponseLogger.logSuccess({
|
|
14
|
+
requestId,
|
|
15
|
+
startTime,
|
|
16
|
+
durationMs,
|
|
17
|
+
clientTool: context.clientTool || "generic",
|
|
18
|
+
rawModel: context.rawModel || targetModel,
|
|
19
|
+
targetModel,
|
|
20
|
+
providerId: "opencode-go",
|
|
21
|
+
accountId: context.account?.id,
|
|
22
|
+
accountName: context.account?.name,
|
|
23
|
+
apiKeyId: context.apiKeyId,
|
|
24
|
+
apiKeyName: context.apiKeyName,
|
|
25
|
+
promptTokens: inTok,
|
|
26
|
+
completionTokens: outTok,
|
|
27
|
+
cachedTokens: 0,
|
|
28
|
+
cacheCreationTokens: 0,
|
|
29
|
+
reasoningTokens: 0,
|
|
30
|
+
tokensSavedByRtk: context.rtkStats?.tokensSaved || 0,
|
|
31
|
+
is1mContext: context.is1mContext,
|
|
32
|
+
requestHeaders: req?.headers || {},
|
|
33
|
+
requestBody: req?.body,
|
|
34
|
+
clientResponse,
|
|
35
|
+
});
|
|
36
|
+
const doneMsg = formatDoneLine({
|
|
37
|
+
durationMs,
|
|
38
|
+
promptTokens: inTok,
|
|
39
|
+
completionTokens: outTok,
|
|
40
|
+
tokensSaved: context.rtkStats?.tokensSaved || 0,
|
|
41
|
+
cost: calculatedCost,
|
|
42
|
+
});
|
|
43
|
+
logger.line(reqTag, LogSymbol.SUCCESS, `opencode-go/${targetModel} · ${doneMsg}`);
|
|
44
|
+
}
|
|
45
|
+
export async function executeOpenCodeGoResponses(context, targetUrl, baseHeaders) {
|
|
46
|
+
const { req, res, clientFormat, isPanel, requestId, targetModel } = context;
|
|
47
|
+
if (!res)
|
|
48
|
+
return { ok: false, status: 500, error: "Response object is required" };
|
|
49
|
+
const globalSettings = SettingsRepository.getEndpointSettings();
|
|
50
|
+
const headers = { ...baseHeaders };
|
|
51
|
+
if (globalSettings.customHeaders) {
|
|
52
|
+
for (const [k, v] of Object.entries(globalSettings.customHeaders)) {
|
|
53
|
+
if (!headers[k])
|
|
54
|
+
headers[k] = v;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const proxyUrl = (context.provider?.proxyUrl || "").trim() || (globalSettings.proxyUrl || "").trim();
|
|
58
|
+
const rawBody = context.body || req?.body || {};
|
|
59
|
+
const isStreaming = rawBody.stream !== false && !isPanel;
|
|
60
|
+
const payload = buildOpenCodeGoResponsesPayload(rawBody, targetModel, clientFormat);
|
|
61
|
+
const abortController = new AbortController();
|
|
62
|
+
const onClose = () => abortController.abort();
|
|
63
|
+
if (typeof res?.once === "function")
|
|
64
|
+
res.once("close", onClose);
|
|
65
|
+
try {
|
|
66
|
+
const upstreamRes = await executeUpstreamFetch(targetUrl, { method: "POST", headers, body: JSON.stringify(payload), signal: abortController.signal }, proxyUrl);
|
|
67
|
+
if (!upstreamRes.ok) {
|
|
68
|
+
const errText = await upstreamRes.text().catch(() => "");
|
|
69
|
+
return { ok: false, status: upstreamRes.status, error: errText || `OpenCode Go responses failed (${upstreamRes.status})` };
|
|
70
|
+
}
|
|
71
|
+
const reader = upstreamRes.body?.getReader();
|
|
72
|
+
if (!reader)
|
|
73
|
+
return { ok: false, status: 502, error: "Empty response stream from OpenCode Go" };
|
|
74
|
+
const decoder = new TextDecoder();
|
|
75
|
+
const responseId = `chatcmpl-${requestId}`;
|
|
76
|
+
const created = Math.floor(Date.now() / 1000);
|
|
77
|
+
const anthropicState = isStreaming && clientFormat === "anthropic"
|
|
78
|
+
? AnthropicAdapter.createStreamState(`msg_${requestId}`, rawBody.tools)
|
|
79
|
+
: undefined;
|
|
80
|
+
let headersSent = false;
|
|
81
|
+
const ensureSseHeaders = () => {
|
|
82
|
+
if (headersSent || res.writableEnded || res.destroyed)
|
|
83
|
+
return;
|
|
84
|
+
headersSent = true;
|
|
85
|
+
res.setHeader("Content-Type", "text/event-stream; charset=utf-8");
|
|
86
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
87
|
+
res.setHeader("Connection", "keep-alive");
|
|
88
|
+
res.flushHeaders?.();
|
|
89
|
+
if (clientFormat === "anthropic" && anthropicState && !anthropicState.messageStartSent) {
|
|
90
|
+
anthropicState.messageStartSent = true;
|
|
91
|
+
res.write(`event: message_start\ndata: ${JSON.stringify({
|
|
92
|
+
type: "message_start",
|
|
93
|
+
message: { id: `msg_${requestId}`, type: "message", role: "assistant", model: targetModel, content: [] },
|
|
94
|
+
})}\n\n`);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const emitOpenAiChunk = (chunk) => {
|
|
98
|
+
if (!isStreaming || res.writableEnded || res.destroyed)
|
|
99
|
+
return;
|
|
100
|
+
ensureSseHeaders();
|
|
101
|
+
if (clientFormat === "anthropic" && anthropicState) {
|
|
102
|
+
for (const ev of AnthropicAdapter.openAiChunkToAnthropicEvent(chunk, `msg_${requestId}`, anthropicState)) {
|
|
103
|
+
res.write(ev);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
res.write(`data: ${JSON.stringify(chunk)}\n\n`);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
let buffer = "";
|
|
111
|
+
let fullText = "";
|
|
112
|
+
let reasoningText = "";
|
|
113
|
+
let sentRole = false;
|
|
114
|
+
let toolIdx = 0;
|
|
115
|
+
const toolIndexByItemId = new Map();
|
|
116
|
+
const toolMetaByItemId = new Map();
|
|
117
|
+
let completedResponse = null;
|
|
118
|
+
let usage = undefined;
|
|
119
|
+
let upstreamError = null;
|
|
120
|
+
const handleEvent = (ev) => {
|
|
121
|
+
const t = ev?.type;
|
|
122
|
+
if (!t)
|
|
123
|
+
return;
|
|
124
|
+
if (t === "response.failed" || t === "error") {
|
|
125
|
+
const errObj = ev.response?.error || ev.error || ev;
|
|
126
|
+
const message = errObj?.message || (typeof errObj === "string" ? errObj : "OpenCode Go response failed");
|
|
127
|
+
const status = Number(errObj?.status || errObj?.statusCode || 502) || 502;
|
|
128
|
+
upstreamError = { status, message };
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (t === "response.output_text.delta" && typeof ev.delta === "string") {
|
|
132
|
+
fullText += ev.delta;
|
|
133
|
+
const delta = { content: ev.delta };
|
|
134
|
+
if (!sentRole) {
|
|
135
|
+
delta.role = "assistant";
|
|
136
|
+
sentRole = true;
|
|
137
|
+
}
|
|
138
|
+
emitOpenAiChunk({ id: responseId, object: "chat.completion.chunk", created, model: targetModel, choices: [{ index: 0, delta, finish_reason: null }] });
|
|
139
|
+
}
|
|
140
|
+
else if (t === "response.reasoning_summary_text.delta" && typeof ev.delta === "string") {
|
|
141
|
+
reasoningText += ev.delta;
|
|
142
|
+
const delta = { reasoning_content: ev.delta };
|
|
143
|
+
if (!sentRole) {
|
|
144
|
+
delta.role = "assistant";
|
|
145
|
+
sentRole = true;
|
|
146
|
+
}
|
|
147
|
+
emitOpenAiChunk({ id: responseId, object: "chat.completion.chunk", created, model: targetModel, choices: [{ index: 0, delta, finish_reason: null }] });
|
|
148
|
+
}
|
|
149
|
+
else if (t === "response.output_item.added" && ev.item?.type === "function_call") {
|
|
150
|
+
const itemId = ev.item.id || `item_${toolIdx}`;
|
|
151
|
+
const callId = ev.item.call_id || itemId;
|
|
152
|
+
const name = ev.item.name || "";
|
|
153
|
+
const idx = toolIndexByItemId.has(itemId) ? toolIndexByItemId.get(itemId) : toolIdx++;
|
|
154
|
+
toolIndexByItemId.set(itemId, idx);
|
|
155
|
+
toolMetaByItemId.set(itemId, { id: callId, name, args: "" });
|
|
156
|
+
const delta = { tool_calls: [{ index: idx, id: callId, type: "function", function: { name, arguments: "" } }] };
|
|
157
|
+
if (!sentRole) {
|
|
158
|
+
delta.role = "assistant";
|
|
159
|
+
sentRole = true;
|
|
160
|
+
}
|
|
161
|
+
emitOpenAiChunk({ id: responseId, object: "chat.completion.chunk", created, model: targetModel, choices: [{ index: 0, delta, finish_reason: null }] });
|
|
162
|
+
}
|
|
163
|
+
else if (t === "response.function_call_arguments.delta" && typeof ev.delta === "string") {
|
|
164
|
+
const idx = toolIndexByItemId.get(ev.item_id);
|
|
165
|
+
if (idx !== undefined) {
|
|
166
|
+
const meta = toolMetaByItemId.get(ev.item_id);
|
|
167
|
+
if (meta)
|
|
168
|
+
meta.args += ev.delta;
|
|
169
|
+
emitOpenAiChunk({
|
|
170
|
+
id: responseId,
|
|
171
|
+
object: "chat.completion.chunk",
|
|
172
|
+
created,
|
|
173
|
+
model: targetModel,
|
|
174
|
+
choices: [{ index: 0, delta: { tool_calls: [{ index: idx, function: { arguments: ev.delta } }] }, finish_reason: null }],
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
else if (t === "response.completed") {
|
|
179
|
+
completedResponse = ev.response || ev;
|
|
180
|
+
const u = completedResponse?.usage;
|
|
181
|
+
if (u) {
|
|
182
|
+
const inTok = u.input_tokens ?? 0;
|
|
183
|
+
const outTok = u.output_tokens ?? 0;
|
|
184
|
+
usage = { prompt_tokens: inTok, completion_tokens: outTok, total_tokens: inTok + outTok };
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
const processLine = (rawLine) => {
|
|
189
|
+
const line = rawLine.trim();
|
|
190
|
+
if (!line.startsWith("data:"))
|
|
191
|
+
return;
|
|
192
|
+
const dataStr = line.slice(5).trim();
|
|
193
|
+
if (!dataStr || dataStr === "[DONE]")
|
|
194
|
+
return;
|
|
195
|
+
try {
|
|
196
|
+
handleEvent(JSON.parse(dataStr));
|
|
197
|
+
}
|
|
198
|
+
catch { }
|
|
199
|
+
};
|
|
200
|
+
while (true) {
|
|
201
|
+
const { done, value } = await reader.read();
|
|
202
|
+
if (done)
|
|
203
|
+
break;
|
|
204
|
+
const chunkStr = decoder.decode(value, { stream: true });
|
|
205
|
+
buffer += chunkStr;
|
|
206
|
+
const lines = buffer.split("\n");
|
|
207
|
+
buffer = lines.pop() || "";
|
|
208
|
+
for (const rawLine of lines)
|
|
209
|
+
processLine(rawLine);
|
|
210
|
+
if (upstreamError)
|
|
211
|
+
break;
|
|
212
|
+
if (isStreaming && clientFormat === "responses") {
|
|
213
|
+
ensureSseHeaders();
|
|
214
|
+
if (!res.writableEnded && !res.destroyed)
|
|
215
|
+
res.write(chunkStr);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (!upstreamError && buffer.trim())
|
|
219
|
+
processLine(buffer);
|
|
220
|
+
if (upstreamError) {
|
|
221
|
+
const err = upstreamError;
|
|
222
|
+
if (headersSent && !res.writableEnded && !res.destroyed)
|
|
223
|
+
res.end();
|
|
224
|
+
return { ok: false, status: err.status, error: err.message };
|
|
225
|
+
}
|
|
226
|
+
if (isStreaming) {
|
|
227
|
+
if (clientFormat === "responses") {
|
|
228
|
+
if (!res.writableEnded && !res.destroyed)
|
|
229
|
+
res.end();
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
const finishReason = toolMetaByItemId.size > 0 ? "tool_calls" : "stop";
|
|
233
|
+
emitOpenAiChunk({
|
|
234
|
+
id: responseId,
|
|
235
|
+
object: "chat.completion.chunk",
|
|
236
|
+
created,
|
|
237
|
+
model: targetModel,
|
|
238
|
+
choices: [{ index: 0, delta: {}, finish_reason: finishReason }],
|
|
239
|
+
...(usage ? { usage } : {}),
|
|
240
|
+
});
|
|
241
|
+
if (!res.writableEnded && !res.destroyed) {
|
|
242
|
+
if (clientFormat === "anthropic" && anthropicState) {
|
|
243
|
+
for (const ev of AnthropicAdapter.finalizeStream(anthropicState))
|
|
244
|
+
res.write(ev);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
res.write("data: [DONE]\n\n");
|
|
248
|
+
}
|
|
249
|
+
res.end();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
recordResponsesSuccess(context, targetModel, usage, fullText, {
|
|
253
|
+
status: 200,
|
|
254
|
+
headers: { "content-type": "text/event-stream" },
|
|
255
|
+
body: { text: "Stream completed" },
|
|
256
|
+
});
|
|
257
|
+
return { ok: true, status: 200, logged: true, modelUsed: targetModel, text: fullText };
|
|
258
|
+
}
|
|
259
|
+
const toolCalls = Array.from(toolMetaByItemId.values()).map((tc) => ({
|
|
260
|
+
id: tc.id,
|
|
261
|
+
type: "function",
|
|
262
|
+
function: { name: tc.name, arguments: tc.args || "{}" },
|
|
263
|
+
}));
|
|
264
|
+
const openAiResp = {
|
|
265
|
+
id: responseId,
|
|
266
|
+
object: "chat.completion",
|
|
267
|
+
created,
|
|
268
|
+
model: targetModel,
|
|
269
|
+
choices: [{
|
|
270
|
+
index: 0,
|
|
271
|
+
message: {
|
|
272
|
+
role: "assistant",
|
|
273
|
+
content: fullText || null,
|
|
274
|
+
...(reasoningText ? { reasoning_content: reasoningText } : {}),
|
|
275
|
+
...(toolCalls.length > 0 ? { tool_calls: toolCalls } : {}),
|
|
276
|
+
},
|
|
277
|
+
finish_reason: toolCalls.length > 0 ? "tool_calls" : "stop",
|
|
278
|
+
}],
|
|
279
|
+
...(usage ? { usage } : {}),
|
|
280
|
+
};
|
|
281
|
+
if (isPanel) {
|
|
282
|
+
return { ok: true, status: 200, json: openAiResp, text: fullText, logged: false, modelUsed: targetModel };
|
|
283
|
+
}
|
|
284
|
+
const outBody = clientFormat === "responses" && completedResponse
|
|
285
|
+
? completedResponse
|
|
286
|
+
: clientFormat === "anthropic"
|
|
287
|
+
? AnthropicAdapter.openAiResponseToAnthropic(openAiResp)
|
|
288
|
+
: openAiResp;
|
|
289
|
+
res.status(200).json(outBody);
|
|
290
|
+
recordResponsesSuccess(context, targetModel, usage, fullText, {
|
|
291
|
+
status: 200,
|
|
292
|
+
headers: { "content-type": "application/json" },
|
|
293
|
+
body: outBody,
|
|
294
|
+
});
|
|
295
|
+
return { ok: true, status: 200, json: outBody, text: fullText, logged: true, modelUsed: targetModel };
|
|
296
|
+
}
|
|
297
|
+
finally {
|
|
298
|
+
if (typeof res?.removeListener === "function")
|
|
299
|
+
res.removeListener("close", onClose);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { AnthropicAdapter } from "../../../core/adapters/anthropicAdapter.js";
|
|
2
|
+
export const OPENCODE_GO_RESPONSES_URL = "https://opencode.ai/inference/go/openai/v1/responses";
|
|
3
|
+
const MAX_TOOL_NAME_LEN = 128;
|
|
4
|
+
const MAX_CALL_ID_LEN = 64;
|
|
5
|
+
const RESPONSES_ONLY_MODELS = new Set([
|
|
6
|
+
"grok-4.7",
|
|
7
|
+
"grok-4.6",
|
|
8
|
+
"grok-4.5",
|
|
9
|
+
"gpt-5.6-luna",
|
|
10
|
+
"gpt-6-luna",
|
|
11
|
+
"muse-spark-1.2-contributor",
|
|
12
|
+
"muse-spark-1.3-contributor",
|
|
13
|
+
]);
|
|
14
|
+
export function isOpenCodeGoResponsesModel(model) {
|
|
15
|
+
if (!model)
|
|
16
|
+
return false;
|
|
17
|
+
const clean = model.replace(/\([^()]+\)\s*$/, "").trim().toLowerCase();
|
|
18
|
+
return (RESPONSES_ONLY_MODELS.has(clean) ||
|
|
19
|
+
clean.startsWith("muse-spark-") ||
|
|
20
|
+
clean.startsWith("grok-4.") ||
|
|
21
|
+
clean.startsWith("gpt-6-luna") ||
|
|
22
|
+
clean.startsWith("gpt-5.6-luna"));
|
|
23
|
+
}
|
|
24
|
+
function clampCallId(id) {
|
|
25
|
+
const str = typeof id === "string" && id.trim() ? id.trim() : `call_${Date.now()}`;
|
|
26
|
+
return str.slice(0, MAX_CALL_ID_LEN);
|
|
27
|
+
}
|
|
28
|
+
function coerceOutput(output) {
|
|
29
|
+
if (typeof output === "string")
|
|
30
|
+
return output;
|
|
31
|
+
if (output == null)
|
|
32
|
+
return "";
|
|
33
|
+
try {
|
|
34
|
+
return JSON.stringify(output);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return String(output);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function coerceArgs(args) {
|
|
41
|
+
if (typeof args === "string")
|
|
42
|
+
return args || "{}";
|
|
43
|
+
if (args == null)
|
|
44
|
+
return "{}";
|
|
45
|
+
try {
|
|
46
|
+
return JSON.stringify(args);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return "{}";
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function normalizeTools(tools) {
|
|
53
|
+
const out = [];
|
|
54
|
+
for (const tool of tools) {
|
|
55
|
+
if (!tool || typeof tool !== "object" || Array.isArray(tool))
|
|
56
|
+
continue;
|
|
57
|
+
const fn = tool.function && typeof tool.function === "object" && !Array.isArray(tool.function) ? tool.function : null;
|
|
58
|
+
const name = String(typeof tool.name === "string" ? tool.name : fn?.name || "").trim();
|
|
59
|
+
if (!name)
|
|
60
|
+
continue;
|
|
61
|
+
const description = typeof tool.description === "string" ? tool.description : fn?.description;
|
|
62
|
+
let parameters = tool.parameters && typeof tool.parameters === "object" && !Array.isArray(tool.parameters)
|
|
63
|
+
? { ...tool.parameters }
|
|
64
|
+
: fn?.parameters && typeof fn.parameters === "object" && !Array.isArray(fn.parameters)
|
|
65
|
+
? { ...fn.parameters }
|
|
66
|
+
: { type: "object", properties: {} };
|
|
67
|
+
if (parameters.type === "object" && !parameters.properties) {
|
|
68
|
+
parameters.properties = {};
|
|
69
|
+
}
|
|
70
|
+
out.push({
|
|
71
|
+
type: "function",
|
|
72
|
+
name: name.slice(0, MAX_TOOL_NAME_LEN),
|
|
73
|
+
...(description ? { description } : {}),
|
|
74
|
+
parameters,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
function messagesToResponsesInput(messages) {
|
|
80
|
+
const sysParts = [];
|
|
81
|
+
const input = [];
|
|
82
|
+
for (const msg of messages) {
|
|
83
|
+
if (!msg || typeof msg !== "object")
|
|
84
|
+
continue;
|
|
85
|
+
if (msg.role === "system" || msg.role === "developer") {
|
|
86
|
+
const text = typeof msg.content === "string"
|
|
87
|
+
? msg.content
|
|
88
|
+
: Array.isArray(msg.content)
|
|
89
|
+
? msg.content.map((c) => (typeof c === "string" ? c : c?.text || "")).filter(Boolean).join("\n")
|
|
90
|
+
: "";
|
|
91
|
+
if (text)
|
|
92
|
+
sysParts.push(text);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (msg.role === "tool") {
|
|
96
|
+
input.push({
|
|
97
|
+
type: "function_call_output",
|
|
98
|
+
call_id: clampCallId(msg.tool_call_id),
|
|
99
|
+
output: coerceOutput(msg.content),
|
|
100
|
+
});
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (msg.role === "assistant") {
|
|
104
|
+
const text = typeof msg.content === "string"
|
|
105
|
+
? msg.content
|
|
106
|
+
: Array.isArray(msg.content)
|
|
107
|
+
? msg.content.map((c) => (typeof c === "string" ? c : c?.text || "")).filter(Boolean).join("\n")
|
|
108
|
+
: "";
|
|
109
|
+
if (text) {
|
|
110
|
+
input.push({ type: "message", role: "assistant", content: [{ type: "output_text", text }] });
|
|
111
|
+
}
|
|
112
|
+
if (Array.isArray(msg.tool_calls)) {
|
|
113
|
+
for (const tc of msg.tool_calls) {
|
|
114
|
+
const fn = tc?.function || {};
|
|
115
|
+
const name = String(fn.name || tc?.name || "").trim();
|
|
116
|
+
if (!name)
|
|
117
|
+
continue;
|
|
118
|
+
input.push({
|
|
119
|
+
type: "function_call",
|
|
120
|
+
call_id: clampCallId(tc.id),
|
|
121
|
+
name: name.slice(0, MAX_TOOL_NAME_LEN),
|
|
122
|
+
arguments: coerceArgs(fn.arguments ?? tc.arguments),
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const parts = [];
|
|
129
|
+
if (typeof msg.content === "string") {
|
|
130
|
+
if (msg.content)
|
|
131
|
+
parts.push({ type: "input_text", text: msg.content });
|
|
132
|
+
}
|
|
133
|
+
else if (Array.isArray(msg.content)) {
|
|
134
|
+
for (const part of msg.content) {
|
|
135
|
+
if (typeof part === "string") {
|
|
136
|
+
parts.push({ type: "input_text", text: part });
|
|
137
|
+
}
|
|
138
|
+
else if (part?.type === "text" || part?.type === "input_text") {
|
|
139
|
+
if (part.text)
|
|
140
|
+
parts.push({ type: "input_text", text: part.text });
|
|
141
|
+
}
|
|
142
|
+
else if (part?.type === "image_url" && part.image_url?.url) {
|
|
143
|
+
parts.push({ type: "input_image", image_url: part.image_url.url });
|
|
144
|
+
}
|
|
145
|
+
else if (part?.type === "input_image") {
|
|
146
|
+
parts.push(part);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (parts.length > 0) {
|
|
151
|
+
input.push({ type: "message", role: "user", content: parts });
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
instructions: sysParts.length > 0 ? sysParts.join("\n\n") : undefined,
|
|
156
|
+
input,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
export function buildOpenCodeGoResponsesPayload(rawBody, model, clientFormat) {
|
|
160
|
+
const baseBody = clientFormat === "anthropic" ? AnthropicAdapter.anthropicToOpenAi(rawBody) : { ...(rawBody || {}) };
|
|
161
|
+
let input = [];
|
|
162
|
+
let instructions = typeof baseBody.instructions === "string" ? baseBody.instructions : undefined;
|
|
163
|
+
if (Array.isArray(baseBody.input)) {
|
|
164
|
+
input = baseBody.input
|
|
165
|
+
.filter((item) => !(item && typeof item === "object" && item.type === "reasoning"))
|
|
166
|
+
.map((item) => {
|
|
167
|
+
if (!item || typeof item !== "object" || Array.isArray(item))
|
|
168
|
+
return item;
|
|
169
|
+
const copy = { ...item };
|
|
170
|
+
delete copy.encrypted_content;
|
|
171
|
+
delete copy.reasoning_encrypted_content;
|
|
172
|
+
if (copy.type === "function_call") {
|
|
173
|
+
if (!copy.name || typeof copy.name !== "string" || !copy.name.trim())
|
|
174
|
+
return null;
|
|
175
|
+
copy.name = copy.name.trim().slice(0, MAX_TOOL_NAME_LEN);
|
|
176
|
+
copy.call_id = clampCallId(copy.call_id);
|
|
177
|
+
copy.arguments = coerceArgs(copy.arguments);
|
|
178
|
+
}
|
|
179
|
+
else if (copy.type === "function_call_output") {
|
|
180
|
+
copy.call_id = clampCallId(copy.call_id);
|
|
181
|
+
copy.output = coerceOutput(copy.output);
|
|
182
|
+
}
|
|
183
|
+
return copy;
|
|
184
|
+
})
|
|
185
|
+
.filter(Boolean);
|
|
186
|
+
}
|
|
187
|
+
else if (typeof baseBody.input === "string") {
|
|
188
|
+
input = [{ type: "message", role: "user", content: [{ type: "input_text", text: baseBody.input || "..." }] }];
|
|
189
|
+
}
|
|
190
|
+
else if (Array.isArray(baseBody.messages)) {
|
|
191
|
+
const converted = messagesToResponsesInput(baseBody.messages);
|
|
192
|
+
input = converted.input;
|
|
193
|
+
if (!instructions && converted.instructions)
|
|
194
|
+
instructions = converted.instructions;
|
|
195
|
+
}
|
|
196
|
+
if (input.length === 0) {
|
|
197
|
+
input = [{ type: "message", role: "user", content: [{ type: "input_text", text: "..." }] }];
|
|
198
|
+
}
|
|
199
|
+
const out = { model, input, stream: true, store: false };
|
|
200
|
+
if (instructions)
|
|
201
|
+
out.instructions = instructions;
|
|
202
|
+
const maxOut = baseBody.max_output_tokens ?? baseBody.max_completion_tokens ?? baseBody.max_tokens;
|
|
203
|
+
if (maxOut !== undefined)
|
|
204
|
+
out.max_output_tokens = maxOut;
|
|
205
|
+
if (baseBody.temperature !== undefined)
|
|
206
|
+
out.temperature = baseBody.temperature;
|
|
207
|
+
if (baseBody.top_p !== undefined)
|
|
208
|
+
out.top_p = baseBody.top_p;
|
|
209
|
+
if (baseBody.reasoning && typeof baseBody.reasoning === "object" && !Array.isArray(baseBody.reasoning)) {
|
|
210
|
+
out.reasoning = { summary: "auto", ...baseBody.reasoning };
|
|
211
|
+
}
|
|
212
|
+
else if (baseBody.reasoning_effort !== undefined) {
|
|
213
|
+
out.reasoning = { effort: baseBody.reasoning_effort, summary: "auto" };
|
|
214
|
+
}
|
|
215
|
+
if (Array.isArray(baseBody.tools) && baseBody.tools.length > 0) {
|
|
216
|
+
const tools = normalizeTools(baseBody.tools);
|
|
217
|
+
if (tools.length > 0) {
|
|
218
|
+
out.tools = tools;
|
|
219
|
+
if (baseBody.tool_choice !== undefined) {
|
|
220
|
+
out.tool_choice =
|
|
221
|
+
typeof baseBody.tool_choice === "object" && baseBody.tool_choice?.function?.name
|
|
222
|
+
? { type: "function", name: baseBody.tool_choice.function.name }
|
|
223
|
+
: baseBody.tool_choice;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return out;
|
|
228
|
+
}
|
|
@@ -31,6 +31,41 @@ export const metadata = {
|
|
|
31
31
|
"name": "SenseNova Default",
|
|
32
32
|
"isDefault": true,
|
|
33
33
|
"contextLength": 128000
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"id": "sensenova-6.8-flash",
|
|
37
|
+
"name": "SenseNova 6.8 Flash",
|
|
38
|
+
"isDefault": false
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"id": "sensenova-6.8-flash-lite",
|
|
42
|
+
"name": "SenseNova 6.8 Flash Lite",
|
|
43
|
+
"isDefault": false
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"id": "deepseek-flash",
|
|
47
|
+
"name": "DeepSeek V4.1 Flash",
|
|
48
|
+
"isDefault": false
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"id": "deepseek-v4-flash",
|
|
52
|
+
"name": "DeepSeek V4 Flash",
|
|
53
|
+
"isDefault": false
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"id": "glm-5.3",
|
|
57
|
+
"name": "GLM-5.3",
|
|
58
|
+
"isDefault": false
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"id": "glm-5.2",
|
|
62
|
+
"name": "GLM-5.2",
|
|
63
|
+
"isDefault": false
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"id": "kimi-k3",
|
|
67
|
+
"name": "Kimi K3",
|
|
68
|
+
"isDefault": false
|
|
34
69
|
}
|
|
35
70
|
],
|
|
36
71
|
"passthroughModels": true
|
|
@@ -39,6 +39,9 @@ export class BaseProvider {
|
|
|
39
39
|
isLocal;
|
|
40
40
|
defaultBaseUrl;
|
|
41
41
|
streamType = "sse";
|
|
42
|
+
resolveTargetFormat(_targetModel, _clientFormat) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
42
45
|
resolveUpstreamModelId(context) {
|
|
43
46
|
const targetModel = context.targetModel || "";
|
|
44
47
|
if (!targetModel)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BaseProvider } from "./baseProvider.js";
|
|
2
2
|
import { AnthropicAdapter } from "../../../core/adapters/anthropicAdapter.js";
|
|
3
3
|
import { normalizeToolsToOpenAi } from "../../../core/adapters/helpers/toolSchemaNormalize.js";
|
|
4
|
+
import { shouldPreserveCacheControl } from "../../../core/caching/cacheControlPolicy.js";
|
|
4
5
|
export class OpenAiCompatibleProvider extends BaseProvider {
|
|
5
6
|
id;
|
|
6
7
|
name;
|
|
@@ -25,7 +26,8 @@ export class OpenAiCompatibleProvider extends BaseProvider {
|
|
|
25
26
|
transformRequestBody(context) {
|
|
26
27
|
let body = context.body;
|
|
27
28
|
if (context.clientFormat === "anthropic") {
|
|
28
|
-
|
|
29
|
+
const preserveCacheControl = shouldPreserveCacheControl(context.provider?.id || this.id, context.targetModel, context.targetFormat || this.defaultFormat);
|
|
30
|
+
body = AnthropicAdapter.anthropicToOpenAi(body, { preserveCacheControl });
|
|
29
31
|
}
|
|
30
32
|
const modelToUse = this.resolveUpstreamModelId(context);
|
|
31
33
|
const converted = { ...body, model: modelToUse };
|
|
@@ -3,6 +3,7 @@ import { registerRoutes as reg_claude } from "../runtime/claude/routes.js";
|
|
|
3
3
|
import { registerRoutes as reg_cline } from "../runtime/cline/routes.js";
|
|
4
4
|
import { registerRoutes as reg_codebuddy } from "../runtime/codebuddy/routes.js";
|
|
5
5
|
import { registerRoutes as reg_codex } from "../runtime/codex/routes.js";
|
|
6
|
+
import { registerRoutes as reg_commandcode } from "../catalog/commandcode/routes.js";
|
|
6
7
|
import { registerRoutes as reg_cursor } from "../runtime/cursor/routes.js";
|
|
7
8
|
import { registerRoutes as reg_gemini_cli } from "../runtime/gemini-cli/routes.js";
|
|
8
9
|
import { registerRoutes as reg_github } from "../runtime/github/routes.js";
|
|
@@ -25,6 +26,7 @@ export function registerAllProviderRoutes(router) {
|
|
|
25
26
|
reg_cline(router);
|
|
26
27
|
reg_codebuddy(router);
|
|
27
28
|
reg_codex(router);
|
|
29
|
+
reg_commandcode(router);
|
|
28
30
|
reg_cursor(router);
|
|
29
31
|
reg_gemini_cli(router);
|
|
30
32
|
reg_github(router);
|
|
@@ -523,6 +523,24 @@ export function cleanJSONSchemaForAntigravity(schema) {
|
|
|
523
523
|
enforceTypeConstraints(cleaned);
|
|
524
524
|
return cleaned;
|
|
525
525
|
}
|
|
526
|
+
export function remoteImageMimeType(url) {
|
|
527
|
+
let pathname;
|
|
528
|
+
try {
|
|
529
|
+
pathname = new URL(url).pathname.toLowerCase();
|
|
530
|
+
}
|
|
531
|
+
catch {
|
|
532
|
+
return "image/png";
|
|
533
|
+
}
|
|
534
|
+
if (pathname.endsWith(".jpg") || pathname.endsWith(".jpeg"))
|
|
535
|
+
return "image/jpeg";
|
|
536
|
+
if (pathname.endsWith(".webp"))
|
|
537
|
+
return "image/webp";
|
|
538
|
+
if (pathname.endsWith(".gif"))
|
|
539
|
+
return "image/gif";
|
|
540
|
+
if (pathname.endsWith(".bmp"))
|
|
541
|
+
return "image/bmp";
|
|
542
|
+
return "image/png";
|
|
543
|
+
}
|
|
526
544
|
/**
|
|
527
545
|
* Convert OpenAI content blocks (text or image_url) to Gemini parts
|
|
528
546
|
*/
|
|
@@ -555,7 +573,7 @@ export function convertOpenAIContentToParts(content) {
|
|
|
555
573
|
}
|
|
556
574
|
}
|
|
557
575
|
else {
|
|
558
|
-
parts.push({ fileData: { fileUri: url, mimeType:
|
|
576
|
+
parts.push({ fileData: { fileUri: url, mimeType: remoteImageMimeType(url) } });
|
|
559
577
|
}
|
|
560
578
|
}
|
|
561
579
|
}
|