@omnicross/core 0.1.3 → 0.1.5
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/LICENSE +21 -21
- package/NOTICE +57 -57
- package/README.md +15 -15
- package/dist/auth/GeminiCodeAssistProjectResolver.cjs +6 -5
- package/dist/auth/GeminiCodeAssistProjectResolver.js +6 -5
- package/dist/{chunk-2DCNB7DF.cjs → chunk-3Q6Z6JTO.cjs} +154 -26
- package/dist/chunk-3QFXFCHG.js +33 -0
- package/dist/chunk-3Z5BQZFM.cjs +52 -0
- package/dist/{chunk-4VAVYUZS.cjs → chunk-4XMYPW46.cjs} +9 -9
- package/dist/chunk-4YINUUKQ.cjs +33 -0
- package/dist/{chunk-S4WBV25P.js → chunk-6QZGDLL4.js} +106 -23
- package/dist/{chunk-C72S6TTV.cjs → chunk-7FEBOPJO.cjs} +5 -4
- package/dist/chunk-APYG5QD7.cjs +50 -0
- package/dist/{chunk-5HTVET6E.js → chunk-BODMAL6G.js} +143 -15
- package/dist/{chunk-CWM2ZDU5.js → chunk-BPKCU575.js} +3 -10
- package/dist/{chunk-2FMI2B6V.cjs → chunk-CGKLE6IW.cjs} +350 -461
- package/dist/{chunk-BO4RFWBR.js → chunk-D3TDKWRP.js} +84 -3
- package/dist/{chunk-RSJ3TWJQ.cjs → chunk-DDMRUL76.cjs} +5 -5
- package/dist/chunk-FCR77GYM.cjs +33 -0
- package/dist/{chunk-4DECIFU7.js → chunk-FH2P4OCD.js} +178 -289
- package/dist/{chunk-N5QFKSDO.js → chunk-HRRYG2AX.js} +2 -1
- package/dist/{chunk-KUU2RNG6.cjs → chunk-HYN75H6G.cjs} +3 -0
- package/dist/{chunk-Z7LUNECE.js → chunk-IB3FDI4O.js} +5 -4
- package/dist/chunk-IFXJ2BG7.js +109 -0
- package/dist/{chunk-JO5NLTLY.js → chunk-IK3KE3AU.js} +3 -0
- package/dist/{chunk-C7PSERMH.js → chunk-IWQAX3CS.js} +1 -1
- package/dist/{chunk-YGXJGRFI.cjs → chunk-JWVTXXPX.cjs} +106 -23
- package/dist/{chunk-7YN22L2H.cjs → chunk-K52THW2C.cjs} +5 -5
- package/dist/chunk-K5NM7VAH.js +33 -0
- package/dist/{chunk-Y6OM7EV7.cjs → chunk-KFI44N2R.cjs} +2 -1
- package/dist/{chunk-Z7Y2NPHY.js → chunk-MFZ5437A.js} +1 -1
- package/dist/chunk-OE6TDIWW.js +22 -0
- package/dist/{chunk-MQNDWYPN.js → chunk-OQWKZCXP.js} +13 -6
- package/dist/chunk-OZFM4X3S.js +18 -0
- package/dist/chunk-PG7PS2NN.cjs +170 -0
- package/dist/{chunk-3QOSDDNI.cjs → chunk-SNYBEXLB.cjs} +6 -13
- package/dist/chunk-SYQF7OIR.js +52 -0
- package/dist/{chunk-CZHZGRU7.js → chunk-UHGVBFU3.js} +2 -0
- package/dist/chunk-UIBD2YY5.cjs +22 -0
- package/dist/chunk-UNWKG6EI.cjs +109 -0
- package/dist/{chunk-SVXC36MU.cjs → chunk-VACWOIRE.cjs} +2 -0
- package/dist/chunk-WLYIIEAF.js +50 -0
- package/dist/chunk-XSVNC2UD.cjs +18 -0
- package/dist/{chunk-FFALUUZZ.cjs → chunk-ZCIQ3L3R.cjs} +18 -11
- package/dist/completion/CompletionService.cjs +26 -19
- package/dist/completion/CompletionService.js +25 -18
- package/dist/completion.cjs +28 -21
- package/dist/completion.js +27 -20
- package/dist/index.cjs +35 -25
- package/dist/index.d.cts +7 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.js +44 -34
- package/dist/keyPolicy-Cp0FntZl.d.cts +90 -0
- package/dist/keyPolicy-Cp0FntZl.d.ts +90 -0
- package/dist/outbound-api/auditCapture.cjs +9 -0
- package/dist/outbound-api/auditCapture.d.cts +54 -0
- package/dist/outbound-api/auditCapture.d.ts +54 -0
- package/dist/outbound-api/auditCapture.js +9 -0
- package/dist/outbound-api/auditRedact.cjs +8 -0
- package/dist/outbound-api/auditRedact.d.cts +30 -0
- package/dist/outbound-api/auditRedact.d.ts +30 -0
- package/dist/outbound-api/auditRedact.js +8 -0
- package/dist/outbound-api/billingCapture.cjs +8 -0
- package/dist/outbound-api/billingCapture.d.cts +61 -0
- package/dist/outbound-api/billingCapture.d.ts +61 -0
- package/dist/outbound-api/billingCapture.js +8 -0
- package/dist/outbound-api/quotaWarn.cjs +12 -0
- package/dist/outbound-api/quotaWarn.d.cts +43 -0
- package/dist/outbound-api/quotaWarn.d.ts +43 -0
- package/dist/outbound-api/quotaWarn.js +12 -0
- package/dist/outbound-api/routeResolver.cjs +2 -2
- package/dist/outbound-api/routeResolver.d.cts +3 -2
- package/dist/outbound-api/routeResolver.d.ts +3 -2
- package/dist/outbound-api/routeResolver.js +1 -1
- package/dist/outbound-api/types.d.cts +2 -1
- package/dist/outbound-api/types.d.ts +2 -1
- package/dist/outbound-api.cjs +33 -23
- package/dist/outbound-api.d.cts +9 -140
- package/dist/outbound-api.d.ts +9 -140
- package/dist/outbound-api.js +32 -22
- package/dist/pipeline/AuthSource.d.cts +6 -0
- package/dist/pipeline/AuthSource.d.ts +6 -0
- package/dist/pipeline/SubscriptionAuthSource.cjs +2 -2
- package/dist/pipeline/SubscriptionAuthSource.js +1 -1
- package/dist/pipeline/SubscriptionAuthStrategy.d.cts +6 -0
- package/dist/pipeline/SubscriptionAuthStrategy.d.ts +6 -0
- package/dist/pipeline/auditUsageStash.cjs +10 -0
- package/dist/pipeline/auditUsageStash.d.cts +37 -0
- package/dist/pipeline/auditUsageStash.d.ts +37 -0
- package/dist/pipeline/auditUsageStash.js +10 -0
- package/dist/pipeline/executeProviderCall.cjs +2 -2
- package/dist/pipeline/executeProviderCall.js +1 -1
- package/dist/pipeline/upstreamFetch.cjs +15 -0
- package/dist/pipeline/upstreamFetch.d.cts +89 -0
- package/dist/pipeline/upstreamFetch.d.ts +89 -0
- package/dist/pipeline/upstreamFetch.js +15 -0
- package/dist/pipeline/upstreamTrace.cjs +14 -0
- package/dist/pipeline/upstreamTrace.d.cts +85 -0
- package/dist/pipeline/upstreamTrace.d.ts +85 -0
- package/dist/pipeline/upstreamTrace.js +14 -0
- package/dist/pipeline/webhookEmit.cjs +10 -0
- package/dist/pipeline/webhookEmit.d.cts +36 -0
- package/dist/pipeline/webhookEmit.d.ts +36 -0
- package/dist/pipeline/webhookEmit.js +10 -0
- package/dist/ports.d.cts +2 -1
- package/dist/ports.d.ts +2 -1
- package/dist/provider-proxy/ProviderProxy.cjs +26 -19
- package/dist/provider-proxy/ProviderProxy.js +25 -18
- package/dist/provider-proxy/ingress/providerProxyShared.cjs +28 -19
- package/dist/provider-proxy/ingress/providerProxyShared.d.cts +17 -1
- package/dist/provider-proxy/ingress/providerProxyShared.d.ts +17 -1
- package/dist/provider-proxy/ingress/providerProxyShared.js +27 -18
- package/dist/provider-proxy/types.d.cts +7 -0
- package/dist/provider-proxy/types.d.ts +7 -0
- package/dist/provider-proxy.cjs +26 -19
- package/dist/provider-proxy.js +25 -18
- package/dist/{routeResolver-B1NglTfe.d.ts → routeResolver-C4T7yClx.d.ts} +1 -1
- package/dist/{routeResolver-CbG5uBgm.d.cts → routeResolver-CB3tvJKy.d.cts} +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.js +1 -1
- package/dist/transformer/transformers/OpenCodeGoTransformer.cjs +2 -2
- package/dist/transformer/transformers/OpenCodeGoTransformer.js +1 -1
- package/dist/transformer/transformers.cjs +8 -8
- package/dist/transformer/transformers.js +7 -7
- package/dist/transformer.cjs +8 -8
- package/dist/transformer.js +7 -7
- package/dist/{types-aBFFXoBz.d.cts → types-B8Arpxn0.d.cts} +14 -90
- package/dist/{types-6OUY_xfA.d.ts → types-lgPYQuZS.d.ts} +14 -90
- package/dist/usage/usage-recorder.cjs +3 -2
- package/dist/usage/usage-recorder.js +2 -1
- package/dist/usage.cjs +3 -2
- package/dist/usage.js +2 -1
- package/package.json +64 -64
- package/dist/chunk-S6JGLF3G.cjs +0 -89
- package/dist/{chunk-FTQ7IQUC.js → chunk-C6OV7GCC.js} +8 -8
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import {
|
|
2
|
+
redactAuditText
|
|
3
|
+
} from "./chunk-K5NM7VAH.js";
|
|
4
|
+
import {
|
|
5
|
+
getAuditCaptureConfig,
|
|
6
|
+
recordAudit
|
|
7
|
+
} from "./chunk-WNY4WMRF.js";
|
|
8
|
+
import {
|
|
9
|
+
readAuditUsage
|
|
10
|
+
} from "./chunk-OZFM4X3S.js";
|
|
11
|
+
|
|
12
|
+
// src/outbound-api/auditCapture.ts
|
|
13
|
+
import { randomUUID } from "crypto";
|
|
14
|
+
function resolveClientIp(req, trustForwardedFor) {
|
|
15
|
+
if (trustForwardedFor) {
|
|
16
|
+
const xff = req.headers["x-forwarded-for"];
|
|
17
|
+
const raw = Array.isArray(xff) ? xff[0] : xff;
|
|
18
|
+
if (typeof raw === "string" && raw.trim()) {
|
|
19
|
+
const first = raw.split(",")[0]?.trim();
|
|
20
|
+
if (first) return first;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return req.socket?.remoteAddress ?? void 0;
|
|
24
|
+
}
|
|
25
|
+
function beginAuditCapture(req, res, now) {
|
|
26
|
+
const config = getAuditCaptureConfig();
|
|
27
|
+
if (!config) return null;
|
|
28
|
+
let rawRequestBody;
|
|
29
|
+
const responseChunks = [];
|
|
30
|
+
let finished = false;
|
|
31
|
+
const ctx = {
|
|
32
|
+
setRequestBody(raw) {
|
|
33
|
+
if (config.captureBodies) rawRequestBody = raw;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
if (config.captureBodies) {
|
|
37
|
+
installResponseCapture(res, {
|
|
38
|
+
push(chunk) {
|
|
39
|
+
responseChunks.push(chunk);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const finalize = () => {
|
|
44
|
+
if (finished) return;
|
|
45
|
+
finished = true;
|
|
46
|
+
try {
|
|
47
|
+
const record = {
|
|
48
|
+
id: randomUUID(),
|
|
49
|
+
ts: now,
|
|
50
|
+
method: req.method ?? "",
|
|
51
|
+
path: (req.url ?? "").split("?")[0] ?? "",
|
|
52
|
+
status: res.statusCode,
|
|
53
|
+
latencyMs: Math.max(0, Date.now() - now)
|
|
54
|
+
};
|
|
55
|
+
if (ctx.keyId != null) record.keyId = ctx.keyId;
|
|
56
|
+
const ip = resolveClientIp(req, config.trustForwardedFor);
|
|
57
|
+
if (ip) record.ip = ip;
|
|
58
|
+
const ua = req.headers["user-agent"];
|
|
59
|
+
if (typeof ua === "string" && ua) record.ua = ua;
|
|
60
|
+
if (ctx.model) record.model = ctx.model;
|
|
61
|
+
if (ctx.provider) record.provider = ctx.provider;
|
|
62
|
+
const usage = readAuditUsage(res);
|
|
63
|
+
if (usage) {
|
|
64
|
+
if (typeof usage.inputTokens === "number") record.inputTokens = usage.inputTokens;
|
|
65
|
+
if (typeof usage.outputTokens === "number") record.outputTokens = usage.outputTokens;
|
|
66
|
+
if (typeof usage.costUsd === "number") record.costUsd = usage.costUsd;
|
|
67
|
+
if (!record.model && usage.model) record.model = usage.model;
|
|
68
|
+
if (!record.provider && usage.provider) record.provider = usage.provider;
|
|
69
|
+
}
|
|
70
|
+
if (ctx.error) record.error = redactAuditText(ctx.error);
|
|
71
|
+
if (config.captureBodies) {
|
|
72
|
+
if (rawRequestBody != null && rawRequestBody.length > 0) {
|
|
73
|
+
record.requestBody = redactAuditText(rawRequestBody);
|
|
74
|
+
}
|
|
75
|
+
if (responseChunks.length > 0) {
|
|
76
|
+
const body = Buffer.concat(responseChunks).toString("utf8");
|
|
77
|
+
record.responseBody = redactAuditText(body);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
recordAudit(record);
|
|
81
|
+
} catch {
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
res.once("close", finalize);
|
|
85
|
+
return ctx;
|
|
86
|
+
}
|
|
87
|
+
function installResponseCapture(res, sink) {
|
|
88
|
+
const capture = (chunk) => {
|
|
89
|
+
let buf = null;
|
|
90
|
+
if (Buffer.isBuffer(chunk)) buf = chunk;
|
|
91
|
+
else if (typeof chunk === "string") buf = Buffer.from(chunk, "utf8");
|
|
92
|
+
if (!buf || buf.length === 0) return;
|
|
93
|
+
sink.push(buf);
|
|
94
|
+
};
|
|
95
|
+
const originalWrite = res.write.bind(res);
|
|
96
|
+
const originalEnd = res.end.bind(res);
|
|
97
|
+
res.write = ((chunk, ...args) => {
|
|
98
|
+
if (chunk != null) capture(chunk);
|
|
99
|
+
return originalWrite(chunk, ...args);
|
|
100
|
+
});
|
|
101
|
+
res.end = ((chunk, ...args) => {
|
|
102
|
+
if (chunk != null && typeof chunk !== "function") capture(chunk);
|
|
103
|
+
return originalEnd(chunk, ...args);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export {
|
|
108
|
+
beginAuditCapture
|
|
109
|
+
};
|
|
@@ -23,6 +23,9 @@ async function executeProviderCall(ctx) {
|
|
|
23
23
|
const finalBody = prepareBody ? await prepareBody(requestBody, config) : requestBody;
|
|
24
24
|
const url = resolveUrl(config);
|
|
25
25
|
const headers = buildHeaders(config);
|
|
26
|
+
if (!headers["content-type"] && !headers["Content-Type"]) {
|
|
27
|
+
headers["content-type"] = "application/json";
|
|
28
|
+
}
|
|
26
29
|
const fetched = await fetchFn(url, headers, finalBody);
|
|
27
30
|
let response = fetched;
|
|
28
31
|
if (runResponseChain) {
|
|
@@ -321,6 +321,7 @@ function handleStreamResponse(response, providerName, logger) {
|
|
|
321
321
|
let pendingContent = "";
|
|
322
322
|
let contentIndex = 0;
|
|
323
323
|
let toolCallIndex = -1;
|
|
324
|
+
let textBuffered = false;
|
|
324
325
|
const stream = new ReadableStream({
|
|
325
326
|
async start(controller) {
|
|
326
327
|
const reader = response.body.getReader();
|
|
@@ -338,6 +339,7 @@ function handleStreamResponse(response, providerName, logger) {
|
|
|
338
339
|
}
|
|
339
340
|
const candidate = chunk.candidates[0];
|
|
340
341
|
const parts = _optionalChain([candidate, 'access', _59 => _59.content, 'optionalAccess', _60 => _60.parts]) || [];
|
|
342
|
+
textBuffered = false;
|
|
341
343
|
parts.filter((part) => part.text && part.thought === true).forEach((part) => {
|
|
342
344
|
hasThinkingContent = true;
|
|
343
345
|
const thinkingChunk = createChunk({
|
|
@@ -415,7 +417,7 @@ function handleStreamResponse(response, providerName, logger) {
|
|
|
415
417
|
if (hasThinkingContent && textContent && !signatureSent) {
|
|
416
418
|
if (_optionalChain([chunk, 'access', _70 => _70.modelVersion, 'optionalAccess', _71 => _71.includes, 'call', _72 => _72("3")])) {
|
|
417
419
|
pendingContent += textContent;
|
|
418
|
-
|
|
420
|
+
textBuffered = true;
|
|
419
421
|
} else {
|
|
420
422
|
const signatureChunk = createChunk({
|
|
421
423
|
responseId: chunk.responseId,
|
|
@@ -433,7 +435,7 @@ function handleStreamResponse(response, providerName, logger) {
|
|
|
433
435
|
signatureSent = true;
|
|
434
436
|
}
|
|
435
437
|
}
|
|
436
|
-
if (textContent) {
|
|
438
|
+
if (textContent && !textBuffered) {
|
|
437
439
|
if (!pendingContent) contentIndex++;
|
|
438
440
|
const contentChunk = createChunk({
|
|
439
441
|
responseId: chunk.responseId,
|
|
@@ -854,35 +856,116 @@ function transformRequestOut(request) {
|
|
|
854
856
|
tool_choice: toolChoice
|
|
855
857
|
};
|
|
856
858
|
if (Array.isArray(contents)) {
|
|
859
|
+
const toolCallIdsByName = /* @__PURE__ */ new Map();
|
|
857
860
|
for (const content of contents) {
|
|
858
861
|
if (typeof content === "string") {
|
|
859
|
-
unifiedRequest.messages.push({
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
} else if ("text" in content && typeof content.text === "string") {
|
|
862
|
+
unifiedRequest.messages.push({ role: "user", content });
|
|
863
|
+
continue;
|
|
864
|
+
}
|
|
865
|
+
if (content && typeof content === "object" && "text" in content && typeof content.text === "string" && !("parts" in content)) {
|
|
864
866
|
unifiedRequest.messages.push({
|
|
865
867
|
role: "user",
|
|
866
868
|
content: content.text || null
|
|
867
869
|
});
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
870
|
+
continue;
|
|
871
|
+
}
|
|
872
|
+
if (!content || typeof content !== "object" || !("role" in content)) {
|
|
873
|
+
continue;
|
|
874
|
+
}
|
|
875
|
+
const geminiContent = content;
|
|
876
|
+
const isModel = geminiContent.role === "model";
|
|
877
|
+
const role = isModel ? "assistant" : "user";
|
|
878
|
+
const parts = _nullishCoalesce(geminiContent.parts, () => ( []));
|
|
879
|
+
const functionResponses = [];
|
|
880
|
+
const functionCalls = [];
|
|
881
|
+
const textParts = [];
|
|
882
|
+
const contentParts = [];
|
|
883
|
+
let thinkingText = "";
|
|
884
|
+
let signature;
|
|
885
|
+
for (const part of parts) {
|
|
886
|
+
if ("thoughtSignature" in part) {
|
|
887
|
+
signature = part.thoughtSignature;
|
|
888
|
+
}
|
|
889
|
+
if ("functionResponse" in part) {
|
|
890
|
+
functionResponses.push(part);
|
|
891
|
+
} else if ("functionCall" in part) {
|
|
892
|
+
functionCalls.push(part);
|
|
893
|
+
} else if ("inlineData" in part || "file_data" in part) {
|
|
894
|
+
const inline = part.inlineData;
|
|
895
|
+
const fileData = part.file_data;
|
|
896
|
+
if (_optionalChain([inline, 'optionalAccess', _122 => _122.data])) {
|
|
897
|
+
const mime = inline.mime_type || "image/png";
|
|
898
|
+
contentParts.push({
|
|
899
|
+
type: "image_url",
|
|
900
|
+
image_url: { url: `data:${mime};base64,${inline.data}` },
|
|
901
|
+
media_type: mime
|
|
902
|
+
});
|
|
903
|
+
} else if (_optionalChain([fileData, 'optionalAccess', _123 => _123.file_uri])) {
|
|
904
|
+
contentParts.push({
|
|
905
|
+
type: "image_url",
|
|
906
|
+
image_url: { url: fileData.file_uri },
|
|
907
|
+
media_type: fileData.mime_type
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
} else if ("text" in part) {
|
|
911
|
+
if (part.thought === true) {
|
|
912
|
+
thinkingText += _nullishCoalesce(part.text, () => ( ""));
|
|
913
|
+
} else {
|
|
914
|
+
textParts.push(part);
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
for (const fr of functionResponses) {
|
|
919
|
+
const fnName = _nullishCoalesce(fr.functionResponse.name, () => ( ""));
|
|
920
|
+
const queue = toolCallIdsByName.get(fnName);
|
|
921
|
+
const id = queue && queue.length > 0 ? queue.shift() : `tool_${Math.random().toString(36).substring(2, 15)}`;
|
|
922
|
+
const response = fr.functionResponse.response;
|
|
923
|
+
const result = _optionalChain([response, 'optionalAccess', _124 => _124.result]);
|
|
924
|
+
const toolContent = typeof result === "string" ? result : result !== void 0 ? JSON.stringify(result) : response !== void 0 ? JSON.stringify(response) : "";
|
|
878
925
|
unifiedRequest.messages.push({
|
|
879
|
-
role: "
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
text: part.text || ""
|
|
883
|
-
}))]) || []
|
|
926
|
+
role: "tool",
|
|
927
|
+
tool_call_id: id,
|
|
928
|
+
content: toolContent
|
|
884
929
|
});
|
|
885
930
|
}
|
|
931
|
+
const toolCalls = functionCalls.map((p) => {
|
|
932
|
+
const id = p.functionCall.id || `tool_${Math.random().toString(36).substring(2, 15)}`;
|
|
933
|
+
if (p.functionCall.name) {
|
|
934
|
+
const arr = _nullishCoalesce(toolCallIdsByName.get(p.functionCall.name), () => ( []));
|
|
935
|
+
arr.push(id);
|
|
936
|
+
toolCallIdsByName.set(p.functionCall.name, arr);
|
|
937
|
+
}
|
|
938
|
+
return {
|
|
939
|
+
id,
|
|
940
|
+
type: "function",
|
|
941
|
+
function: {
|
|
942
|
+
name: p.functionCall.name,
|
|
943
|
+
arguments: JSON.stringify(_nullishCoalesce(p.functionCall.args, () => ( {})))
|
|
944
|
+
}
|
|
945
|
+
};
|
|
946
|
+
});
|
|
947
|
+
const onlyToolResults = functionResponses.length > 0 && textParts.length === 0 && functionCalls.length === 0 && contentParts.length === 0 && !thinkingText && !signature;
|
|
948
|
+
if (onlyToolResults) continue;
|
|
949
|
+
let messageContent;
|
|
950
|
+
if (contentParts.length > 0) {
|
|
951
|
+
messageContent = [
|
|
952
|
+
...textParts.map((p) => ({ type: "text", text: p.text })),
|
|
953
|
+
...contentParts
|
|
954
|
+
];
|
|
955
|
+
} else {
|
|
956
|
+
messageContent = textParts.map((p) => p.text).join("\n") || null;
|
|
957
|
+
}
|
|
958
|
+
const message = {
|
|
959
|
+
role,
|
|
960
|
+
content: messageContent
|
|
961
|
+
};
|
|
962
|
+
if (toolCalls.length > 0) {
|
|
963
|
+
message.tool_calls = toolCalls;
|
|
964
|
+
}
|
|
965
|
+
if (signature || thinkingText) {
|
|
966
|
+
message.thinking = { content: thinkingText || "", signature };
|
|
967
|
+
}
|
|
968
|
+
unifiedRequest.messages.push(message);
|
|
886
969
|
}
|
|
887
970
|
}
|
|
888
971
|
if (Array.isArray(tools)) {
|
|
@@ -895,7 +978,7 @@ function transformRequestOut(request) {
|
|
|
895
978
|
function: {
|
|
896
979
|
name: funcDecl.name,
|
|
897
980
|
description: _nullishCoalesce(funcDecl.description, () => ( "")),
|
|
898
|
-
parameters: _nullishCoalesce(funcDecl.parameters, () => ( {}))
|
|
981
|
+
parameters: _nullishCoalesce(_nullishCoalesce(funcDecl.parameters, () => ( funcDecl.parametersJsonSchema)), () => ( {}))
|
|
899
982
|
}
|
|
900
983
|
});
|
|
901
984
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkJWVTXXPXcjs = require('./chunk-JWVTXXPX.cjs');
|
|
7
7
|
|
|
8
8
|
// src/transformer/transformers/GeminiTransformer.ts
|
|
9
9
|
var GeminiTransformer = (_class = class {
|
|
@@ -44,7 +44,7 @@ var GeminiTransformer = (_class = class {
|
|
|
44
44
|
* Also builds the correct URL for the Gemini API
|
|
45
45
|
*/
|
|
46
46
|
async transformRequestIn(request, provider, _context) {
|
|
47
|
-
const body =
|
|
47
|
+
const body = _chunkJWVTXXPXcjs.buildRequestBody.call(void 0, request);
|
|
48
48
|
const action = request.stream ? "streamGenerateContent?alt=sse" : "generateContent";
|
|
49
49
|
const url = new URL(`./${request.model}:${action}`, provider.baseUrl);
|
|
50
50
|
const headers = {};
|
|
@@ -65,20 +65,20 @@ var GeminiTransformer = (_class = class {
|
|
|
65
65
|
* (For requests coming into the Gemini endpoint)
|
|
66
66
|
*/
|
|
67
67
|
async transformRequestOut(request, _context) {
|
|
68
|
-
return
|
|
68
|
+
return _chunkJWVTXXPXcjs.transformRequestOut.call(void 0, request);
|
|
69
69
|
}
|
|
70
70
|
/**
|
|
71
71
|
* Transform Gemini response to OpenAI-compatible format
|
|
72
72
|
*/
|
|
73
73
|
async transformResponseOut(response, _context) {
|
|
74
|
-
return
|
|
74
|
+
return _chunkJWVTXXPXcjs.transformResponseOut.call(void 0, response, this.name, this.logger);
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
77
|
* Transform OpenAI-compatible response back to Gemini format
|
|
78
78
|
* (For endpoint mode — returning Gemini-format responses to the client)
|
|
79
79
|
*/
|
|
80
80
|
async transformResponseIn(response, _context) {
|
|
81
|
-
return
|
|
81
|
+
return _chunkJWVTXXPXcjs.transformResponseIn.call(void 0, response, this.logger);
|
|
82
82
|
}
|
|
83
83
|
}, _class.__initStatic(), _class);
|
|
84
84
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/outbound-api/auditRedact.ts
|
|
2
|
+
var AUDIT_REDACTED = "***REDACTED***";
|
|
3
|
+
var RULES = [
|
|
4
|
+
// `sk-…` family (Anthropic sk-ant-, omnicross sk-omnicross-, OpenAI sk-proj-/sk-).
|
|
5
|
+
{ re: /\bsk-[A-Za-z0-9_-]{6,}/g, replace: AUDIT_REDACTED },
|
|
6
|
+
// Google API keys.
|
|
7
|
+
{ re: /\bAIza[A-Za-z0-9_-]{10,}/g, replace: AUDIT_REDACTED },
|
|
8
|
+
// `Bearer <token>` (auth headers echoed into a body / SSE error).
|
|
9
|
+
{ re: /\bBearer\s+[A-Za-z0-9._~+/=-]{6,}/gi, replace: `Bearer ${AUDIT_REDACTED}` },
|
|
10
|
+
// Inline `x-api-key` / `api-key` / `authorization` label followed by a value.
|
|
11
|
+
{
|
|
12
|
+
re: /\b(x-api-key|api[_-]?key|authorization)(["']?\s*[:=]\s*["']?)[A-Za-z0-9._~+/=-]{6,}/gi,
|
|
13
|
+
replace: `$1$2${AUDIT_REDACTED}`
|
|
14
|
+
},
|
|
15
|
+
// `x-goog-api-key` header echoed inline.
|
|
16
|
+
{
|
|
17
|
+
re: /\b(x-goog-api-key)(["']?\s*[:=]\s*["']?)[A-Za-z0-9._~+/=-]{6,}/gi,
|
|
18
|
+
replace: `$1$2${AUDIT_REDACTED}`
|
|
19
|
+
}
|
|
20
|
+
];
|
|
21
|
+
function redactAuditText(text) {
|
|
22
|
+
if (typeof text !== "string" || text.length === 0) return text ?? "";
|
|
23
|
+
let out = text;
|
|
24
|
+
for (const { re, replace } of RULES) {
|
|
25
|
+
out = out.replace(re, replace);
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
AUDIT_REDACTED,
|
|
32
|
+
redactAuditText
|
|
33
|
+
};
|
|
@@ -33,7 +33,8 @@ var SubscriptionAuthSource = class {
|
|
|
33
33
|
upstreamUrl: hints.upstreamUrl,
|
|
34
34
|
resolvedModel: hints.model,
|
|
35
35
|
sessionKey: hints.sessionKey,
|
|
36
|
-
reportSelection: hints.reportSelection
|
|
36
|
+
reportSelection: hints.reportSelection,
|
|
37
|
+
preferredAccountId: hints.preferredAccountId
|
|
37
38
|
});
|
|
38
39
|
} catch (err) {
|
|
39
40
|
console.warn("[SubscriptionAuthSource] authStrategy.applyHeaders threw:", _chunkSVNDB62Dcjs.serializeError.call(void 0, err));
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
transformRequestOut,
|
|
4
4
|
transformResponseIn,
|
|
5
5
|
transformResponseOut
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-6QZGDLL4.js";
|
|
7
7
|
|
|
8
8
|
// src/transformer/transformers/GeminiCodeAssistTransformer.ts
|
|
9
9
|
var DEFAULT_CODE_ASSIST_ENDPOINT = "https://cloudcode-pa.googleapis.com";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/pipeline/webhookEmit.ts
|
|
2
|
+
var sink = null;
|
|
3
|
+
function setWebhookSink(fn) {
|
|
4
|
+
sink = fn;
|
|
5
|
+
}
|
|
6
|
+
function emitWebhookEvent(event) {
|
|
7
|
+
const active = sink;
|
|
8
|
+
if (!active) return;
|
|
9
|
+
try {
|
|
10
|
+
active(event);
|
|
11
|
+
} catch {
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function __resetWebhookSinkForTests() {
|
|
15
|
+
sink = null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
setWebhookSink,
|
|
20
|
+
emitWebhookEvent,
|
|
21
|
+
__resetWebhookSinkForTests
|
|
22
|
+
};
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
OpenCodeGoTransformer
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-IB3FDI4O.js";
|
|
4
4
|
import {
|
|
5
5
|
ReasoningTransformer
|
|
6
6
|
} from "./chunk-ZJZAOKI7.js";
|
|
7
7
|
import {
|
|
8
8
|
AnthropicTransformer
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-C6OV7GCC.js";
|
|
10
10
|
import {
|
|
11
11
|
GeminiTransformer
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-IWQAX3CS.js";
|
|
13
13
|
import {
|
|
14
14
|
OpenAIResponseTransformer
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-BODMAL6G.js";
|
|
16
16
|
import {
|
|
17
17
|
GeminiCodeAssistTransformer
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-MFZ5437A.js";
|
|
19
19
|
|
|
20
20
|
// src/transformer/transformers/DeepseekTransformer.ts
|
|
21
21
|
var DeepseekTransformer = class {
|
|
@@ -32,7 +32,14 @@ var DeepseekTransformer = class {
|
|
|
32
32
|
this.logger?.debug("DeepSeek: Limiting max_tokens from %d to 8192", request.max_tokens);
|
|
33
33
|
request.max_tokens = 8192;
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
const sanitizedMessages = (request.messages ?? []).map((m) => {
|
|
36
|
+
const out = { role: m.role };
|
|
37
|
+
if (m.content !== void 0) out.content = m.content;
|
|
38
|
+
if (m.tool_calls) out.tool_calls = m.tool_calls;
|
|
39
|
+
if (m.tool_call_id) out.tool_call_id = m.tool_call_id;
|
|
40
|
+
return out;
|
|
41
|
+
});
|
|
42
|
+
return { ...request, messages: sanitizedMessages };
|
|
36
43
|
}
|
|
37
44
|
/**
|
|
38
45
|
* Transform response: convert reasoning_content to thinking blocks
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/pipeline/auditUsageStash.ts
|
|
2
|
+
var stash = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
function stashAuditUsage(key, detail) {
|
|
4
|
+
const existing = stash.get(key);
|
|
5
|
+
stash.set(key, existing ? { ...existing, ...detail } : { ...detail });
|
|
6
|
+
}
|
|
7
|
+
function readAuditUsage(key) {
|
|
8
|
+
return stash.get(key);
|
|
9
|
+
}
|
|
10
|
+
function __clearAuditUsageForTests(key) {
|
|
11
|
+
stash.delete(key);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
stashAuditUsage,
|
|
16
|
+
readAuditUsage,
|
|
17
|
+
__clearAuditUsageForTests
|
|
18
|
+
};
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var _chunk3Z5BQZFMcjs = require('./chunk-3Z5BQZFM.cjs');
|
|
6
|
+
|
|
7
|
+
// src/pipeline/upstreamFetch.ts
|
|
8
|
+
var _undici = require('undici');
|
|
9
|
+
var _socks = require('socks');
|
|
10
|
+
var resolver = null;
|
|
11
|
+
var generation = 0;
|
|
12
|
+
var cache = /* @__PURE__ */ new Map();
|
|
13
|
+
function setUpstreamProxyResolver(fn) {
|
|
14
|
+
resolver = fn;
|
|
15
|
+
bumpUpstreamProxyGeneration();
|
|
16
|
+
}
|
|
17
|
+
function bumpUpstreamProxyGeneration() {
|
|
18
|
+
generation += 1;
|
|
19
|
+
const old = cache;
|
|
20
|
+
cache = /* @__PURE__ */ new Map();
|
|
21
|
+
for (const dispatcher of old.values()) {
|
|
22
|
+
try {
|
|
23
|
+
void _optionalChain([dispatcher, 'access', _ => _.close, 'optionalCall', _2 => _2()]);
|
|
24
|
+
} catch (e) {
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function normalizeProxy(cfg) {
|
|
29
|
+
if ("url" in cfg) {
|
|
30
|
+
let u;
|
|
31
|
+
try {
|
|
32
|
+
u = new URL(cfg.url);
|
|
33
|
+
} catch (e2) {
|
|
34
|
+
return void 0;
|
|
35
|
+
}
|
|
36
|
+
const proto = u.protocol.replace(/:$/, "").toLowerCase();
|
|
37
|
+
const kind2 = proto === "socks5" || proto === "socks" ? "socks5" : proto === "https" ? "https" : "http";
|
|
38
|
+
const port = u.port ? Number(u.port) : kind2 === "https" ? 443 : kind2 === "socks5" ? 1080 : 80;
|
|
39
|
+
if (!u.hostname || !Number.isFinite(port)) return void 0;
|
|
40
|
+
return {
|
|
41
|
+
kind: kind2,
|
|
42
|
+
host: u.hostname,
|
|
43
|
+
port,
|
|
44
|
+
username: u.username ? decodeURIComponent(u.username) : void 0,
|
|
45
|
+
password: u.password ? decodeURIComponent(u.password) : void 0
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const kind = cfg.type === "socks5" ? "socks5" : cfg.type === "https" ? "https" : "http";
|
|
49
|
+
if (!cfg.host || !Number.isFinite(cfg.port)) return void 0;
|
|
50
|
+
return {
|
|
51
|
+
kind,
|
|
52
|
+
host: cfg.host,
|
|
53
|
+
port: cfg.port,
|
|
54
|
+
username: cfg.username || void 0,
|
|
55
|
+
password: cfg.password || void 0
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function proxyKey(p) {
|
|
59
|
+
return `${p.kind}://${_nullishCoalesce(p.username, () => ( ""))}:${_nullishCoalesce(p.password, () => ( ""))}@${p.host}:${p.port}`;
|
|
60
|
+
}
|
|
61
|
+
function socksConnector(p) {
|
|
62
|
+
const base = _undici.buildConnector.call(void 0, {});
|
|
63
|
+
return ((options, callback) => {
|
|
64
|
+
const destPort = Number(options.port) || (options.protocol === "https:" ? 443 : 80);
|
|
65
|
+
_socks.SocksClient.createConnection({
|
|
66
|
+
proxy: { host: p.host, port: p.port, type: 5, userId: p.username, password: p.password },
|
|
67
|
+
command: "connect",
|
|
68
|
+
destination: { host: options.hostname, port: destPort }
|
|
69
|
+
}).then(({ socket }) => {
|
|
70
|
+
base({ ...options, httpSocket: socket }, callback);
|
|
71
|
+
}).catch((err) => callback(err, null));
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function buildDispatcher(p) {
|
|
75
|
+
if (p.kind === "socks5") {
|
|
76
|
+
return new (0, _undici.Agent)({ connect: socksConnector(p) });
|
|
77
|
+
}
|
|
78
|
+
const auth = p.username != null ? `${encodeURIComponent(p.username)}:${encodeURIComponent(_nullishCoalesce(p.password, () => ( "")))}@` : "";
|
|
79
|
+
const uri = `${p.kind}://${auth}${p.host}:${p.port}`;
|
|
80
|
+
return new (0, _undici.ProxyAgent)({ uri });
|
|
81
|
+
}
|
|
82
|
+
function resolveUpstreamDispatcher(ctx) {
|
|
83
|
+
const active = resolver;
|
|
84
|
+
if (!active) return void 0;
|
|
85
|
+
let cfg;
|
|
86
|
+
try {
|
|
87
|
+
cfg = active(ctx);
|
|
88
|
+
} catch (e3) {
|
|
89
|
+
return void 0;
|
|
90
|
+
}
|
|
91
|
+
if (!cfg) return void 0;
|
|
92
|
+
const norm = normalizeProxy(cfg);
|
|
93
|
+
if (!norm) return void 0;
|
|
94
|
+
const key = `${generation}\0${proxyKey(norm)}`;
|
|
95
|
+
let dispatcher = cache.get(key);
|
|
96
|
+
if (!dispatcher) {
|
|
97
|
+
dispatcher = buildDispatcher(norm);
|
|
98
|
+
cache.set(key, dispatcher);
|
|
99
|
+
}
|
|
100
|
+
return dispatcher;
|
|
101
|
+
}
|
|
102
|
+
function fetchUpstream(url, init, ctx) {
|
|
103
|
+
const dispatcher = resolveUpstreamDispatcher({ ..._nullishCoalesce(ctx, () => ( {})), url });
|
|
104
|
+
const doFetch = dispatcher ? () => fetch(url, { ...init, dispatcher }) : () => fetch(url, init);
|
|
105
|
+
const tracePath = _chunk3Z5BQZFMcjs.getUpstreamTracePath.call(void 0, );
|
|
106
|
+
if (!tracePath || !_optionalChain([ctx, 'optionalAccess', _3 => _3.providerId])) return doFetch();
|
|
107
|
+
const startedAt = Date.now();
|
|
108
|
+
const method = typeof init.method === "string" ? init.method : "GET";
|
|
109
|
+
const requestHeaders = _chunk3Z5BQZFMcjs.redactHeaders.call(void 0,
|
|
110
|
+
init.headers
|
|
111
|
+
);
|
|
112
|
+
const requestBody = typeof init.body === "string" ? init.body : null;
|
|
113
|
+
const providerId = ctx.providerId;
|
|
114
|
+
const accountId = ctx.accountId;
|
|
115
|
+
return doFetch().then((res) => {
|
|
116
|
+
const clone = res.clone();
|
|
117
|
+
const status = res.status;
|
|
118
|
+
const statusText = res.statusText;
|
|
119
|
+
const responseHeaders = _chunk3Z5BQZFMcjs.redactHeaders.call(void 0, res.headers);
|
|
120
|
+
void clone.text().then((body) => {
|
|
121
|
+
_chunk3Z5BQZFMcjs.writeUpstreamTrace.call(void 0, {
|
|
122
|
+
ts: startedAt,
|
|
123
|
+
durationMs: Date.now() - startedAt,
|
|
124
|
+
providerId,
|
|
125
|
+
accountId,
|
|
126
|
+
url,
|
|
127
|
+
method,
|
|
128
|
+
requestHeaders,
|
|
129
|
+
requestBody,
|
|
130
|
+
status,
|
|
131
|
+
statusText,
|
|
132
|
+
responseHeaders,
|
|
133
|
+
responseBody: body,
|
|
134
|
+
responseBytes: Buffer.byteLength(body, "utf8")
|
|
135
|
+
});
|
|
136
|
+
}).catch(() => {
|
|
137
|
+
});
|
|
138
|
+
return res;
|
|
139
|
+
}).catch((err) => {
|
|
140
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
141
|
+
_chunk3Z5BQZFMcjs.writeUpstreamTrace.call(void 0, {
|
|
142
|
+
ts: startedAt,
|
|
143
|
+
durationMs: Date.now() - startedAt,
|
|
144
|
+
providerId,
|
|
145
|
+
accountId,
|
|
146
|
+
url,
|
|
147
|
+
method,
|
|
148
|
+
requestHeaders,
|
|
149
|
+
requestBody,
|
|
150
|
+
status: 0,
|
|
151
|
+
statusText: "",
|
|
152
|
+
responseHeaders: {},
|
|
153
|
+
responseBody: `<UPSTREAM FETCH ERROR: ${msg}>`,
|
|
154
|
+
responseBytes: 0
|
|
155
|
+
});
|
|
156
|
+
throw err;
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function __resetUpstreamProxyForTests() {
|
|
160
|
+
resolver = null;
|
|
161
|
+
bumpUpstreamProxyGeneration();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
exports.setUpstreamProxyResolver = setUpstreamProxyResolver; exports.bumpUpstreamProxyGeneration = bumpUpstreamProxyGeneration; exports.resolveUpstreamDispatcher = resolveUpstreamDispatcher; exports.fetchUpstream = fetchUpstream; exports.__resetUpstreamProxyForTests = __resetUpstreamProxyForTests;
|