@omnicross/core 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +7 -5
- package/dist/auth/GeminiCodeAssistProjectResolver.js +5 -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-3Z5BQZFM.cjs +52 -0
- package/dist/{chunk-4VAVYUZS.cjs → chunk-4VLRHHFE.cjs} +82 -40
- package/dist/{chunk-VACWOIRE.cjs → chunk-4VZX5F4T.cjs} +39 -15
- package/dist/{chunk-FTQ7IQUC.js → chunk-6CL5HTPQ.js} +52 -10
- package/dist/chunk-6QQG7YG3.cjs +153 -0
- package/dist/{chunk-SU2GCLAC.cjs → chunk-6VUQPOV3.cjs} +359 -60
- 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-7Y47UCF2.js → chunk-IFXJ2BG7.js} +5 -38
- package/dist/{chunk-46ZIFWYG.cjs → chunk-IIRPUVPH.cjs} +7 -1
- package/dist/{chunk-YGXJGRFI.cjs → chunk-KBM2W6UY.cjs} +111 -24
- package/dist/{chunk-OCEUVQHW.cjs → chunk-KCVJWJST.cjs} +73 -3
- package/dist/chunk-LB6EBS6Y.js +69 -0
- package/dist/{chunk-C7PSERMH.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-Z7Y2NPHY.js → chunk-N5T4M4GU.js} +1 -1
- package/dist/{chunk-TIER4SUC.js → chunk-OEWZUX4G.js} +346 -47
- package/dist/chunk-OF3BECU2.cjs +69 -0
- package/dist/{chunk-RSJ3TWJQ.cjs → chunk-OKMJLEXX.cjs} +5 -5
- package/dist/chunk-OPRS4IQZ.js +153 -0
- package/dist/{chunk-XK5CIRMQ.js → chunk-SIZQQD6T.js} +72 -2
- package/dist/{chunk-DKPXN34V.cjs → chunk-SQYVORNP.cjs} +1334 -510
- package/dist/chunk-SYQF7OIR.js +52 -0
- package/dist/{chunk-S4WBV25P.js → chunk-TOVPMMHM.js} +111 -24
- package/dist/{chunk-QYTT6GE3.js → chunk-UDCC7EMR.js} +1093 -269
- package/dist/{chunk-E3UCVHLP.cjs → chunk-UNWKG6EI.cjs} +5 -38
- package/dist/{chunk-ZLX3KGXX.js → chunk-UX7VWA46.js} +135 -23
- package/dist/{chunk-7YN22L2H.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 +27 -24
- package/dist/completion/CompletionService.d.cts +2 -1
- package/dist/completion/CompletionService.d.ts +2 -1
- package/dist/completion/CompletionService.js +26 -23
- package/dist/completion.cjs +27 -24
- package/dist/completion.d.cts +2 -1
- package/dist/completion.d.ts +2 -1
- package/dist/completion.js +26 -23
- package/dist/index.cjs +53 -29
- package/dist/index.d.cts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +56 -32
- package/dist/{keyPolicy-Cp0FntZl.d.cts → keyPolicy-zdWTu3CQ.d.cts} +1 -1
- package/dist/{keyPolicy-Cp0FntZl.d.ts → keyPolicy-zdWTu3CQ.d.ts} +1 -1
- package/dist/outbound-api/auditCapture.cjs +2 -2
- package/dist/outbound-api/auditCapture.d.cts +5 -3
- package/dist/outbound-api/auditCapture.d.ts +5 -3
- package/dist/outbound-api/auditCapture.js +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 +49 -25
- package/dist/outbound-api.d.cts +127 -85
- package/dist/outbound-api.d.ts +127 -85
- package/dist/outbound-api.js +52 -28
- 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 +4 -2
- package/dist/pipeline/upstreamFetch.d.cts +6 -0
- package/dist/pipeline/upstreamFetch.d.ts +6 -0
- package/dist/pipeline/upstreamFetch.js +3 -1
- 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/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 +27 -24
- package/dist/provider-proxy/ProviderProxy.d.cts +1 -0
- package/dist/provider-proxy/ProviderProxy.d.ts +1 -0
- package/dist/provider-proxy/ProviderProxy.js +26 -23
- package/dist/provider-proxy/ingress/providerProxyShared.cjs +31 -24
- package/dist/provider-proxy/ingress/providerProxyShared.d.cts +50 -5
- package/dist/provider-proxy/ingress/providerProxyShared.d.ts +50 -5
- package/dist/provider-proxy/ingress/providerProxyShared.js +30 -23
- 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 +27 -24
- package/dist/provider-proxy.d.cts +1 -0
- package/dist/provider-proxy.d.ts +1 -0
- package/dist/provider-proxy.js +26 -23
- 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 +11 -17
- package/dist/transformer/types.d.cts +17 -0
- package/dist/transformer/types.d.ts +17 -0
- package/dist/transformer.cjs +11 -12
- package/dist/transformer.d.cts +1 -2
- package/dist/transformer.d.ts +1 -2
- package/dist/transformer.js +11 -12
- 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-C72S6TTV.cjs +0 -49
- package/dist/chunk-DWKQZ2SK.cjs +0 -254
- package/dist/chunk-IAXWICZU.js +0 -69
- package/dist/chunk-QWBWGODS.cjs +0 -69
- package/dist/chunk-RGTR7CIO.cjs +0 -235
- package/dist/chunk-VPBAUQ2M.js +0 -235
- package/dist/chunk-YMFAJFQT.cjs +0 -173
- package/dist/chunk-Z7LUNECE.js +0 -49
- 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
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// src/pipeline/upstreamTrace.ts
|
|
2
|
+
import { appendFile, mkdir } from "fs/promises";
|
|
3
|
+
import { dirname } from "path";
|
|
4
|
+
var tracePath = null;
|
|
5
|
+
var SECRET_HEADER_NAMES = /* @__PURE__ */ new Set([
|
|
6
|
+
"authorization",
|
|
7
|
+
"api-key",
|
|
8
|
+
"x-api-key",
|
|
9
|
+
"x-goog-api-key"
|
|
10
|
+
]);
|
|
11
|
+
function setUpstreamTracePath(path) {
|
|
12
|
+
tracePath = typeof path === "string" && path.trim() ? path.trim() : null;
|
|
13
|
+
}
|
|
14
|
+
function getUpstreamTracePath() {
|
|
15
|
+
return tracePath;
|
|
16
|
+
}
|
|
17
|
+
function redactHeaders(headers) {
|
|
18
|
+
const out = {};
|
|
19
|
+
if (!headers) return out;
|
|
20
|
+
let entries;
|
|
21
|
+
if (Array.isArray(headers)) {
|
|
22
|
+
entries = headers;
|
|
23
|
+
} else if (typeof headers.entries === "function") {
|
|
24
|
+
entries = Array.from(headers.entries());
|
|
25
|
+
} else {
|
|
26
|
+
entries = Object.entries(headers);
|
|
27
|
+
}
|
|
28
|
+
for (const [key, value] of entries) {
|
|
29
|
+
out[key] = SECRET_HEADER_NAMES.has(key.toLowerCase()) ? "***REDACTED***" : String(value);
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
async function writeUpstreamTrace(record) {
|
|
34
|
+
const path = tracePath;
|
|
35
|
+
if (!path) return;
|
|
36
|
+
try {
|
|
37
|
+
await mkdir(dirname(path), { recursive: true });
|
|
38
|
+
await appendFile(path, JSON.stringify(record) + "\n", "utf8");
|
|
39
|
+
} catch {
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function __resetUpstreamTraceForTests() {
|
|
43
|
+
tracePath = null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export {
|
|
47
|
+
setUpstreamTracePath,
|
|
48
|
+
getUpstreamTracePath,
|
|
49
|
+
redactHeaders,
|
|
50
|
+
writeUpstreamTrace,
|
|
51
|
+
__resetUpstreamTraceForTests
|
|
52
|
+
};
|
|
@@ -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 = candidate.content?.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 (chunk.modelVersion?.includes("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,
|
|
@@ -790,6 +792,9 @@ function buildRequestBody(request) {
|
|
|
790
792
|
}
|
|
791
793
|
});
|
|
792
794
|
const generationConfig = {};
|
|
795
|
+
if (request.max_tokens !== void 0) {
|
|
796
|
+
generationConfig.maxOutputTokens = request.max_tokens;
|
|
797
|
+
}
|
|
793
798
|
if (request.reasoning?.effort && request.reasoning.effort !== "none") {
|
|
794
799
|
generationConfig.thinkingConfig = {
|
|
795
800
|
includeThoughts: true
|
|
@@ -841,7 +846,8 @@ function transformRequestOut(request) {
|
|
|
841
846
|
const contents = request.contents;
|
|
842
847
|
const tools = request.tools;
|
|
843
848
|
const model = request.model;
|
|
844
|
-
const
|
|
849
|
+
const generationConfig = request.generationConfig;
|
|
850
|
+
const maxTokens = generationConfig?.maxOutputTokens ?? request.max_tokens;
|
|
845
851
|
const temperature = request.temperature;
|
|
846
852
|
const stream = request.stream;
|
|
847
853
|
const toolChoice = request.tool_choice;
|
|
@@ -854,35 +860,116 @@ function transformRequestOut(request) {
|
|
|
854
860
|
tool_choice: toolChoice
|
|
855
861
|
};
|
|
856
862
|
if (Array.isArray(contents)) {
|
|
863
|
+
const toolCallIdsByName = /* @__PURE__ */ new Map();
|
|
857
864
|
for (const content of contents) {
|
|
858
865
|
if (typeof content === "string") {
|
|
859
|
-
unifiedRequest.messages.push({
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
} else if ("text" in content && typeof content.text === "string") {
|
|
866
|
+
unifiedRequest.messages.push({ role: "user", content });
|
|
867
|
+
continue;
|
|
868
|
+
}
|
|
869
|
+
if (content && typeof content === "object" && "text" in content && typeof content.text === "string" && !("parts" in content)) {
|
|
864
870
|
unifiedRequest.messages.push({
|
|
865
871
|
role: "user",
|
|
866
872
|
content: content.text || null
|
|
867
873
|
});
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
874
|
+
continue;
|
|
875
|
+
}
|
|
876
|
+
if (!content || typeof content !== "object" || !("role" in content)) {
|
|
877
|
+
continue;
|
|
878
|
+
}
|
|
879
|
+
const geminiContent = content;
|
|
880
|
+
const isModel = geminiContent.role === "model";
|
|
881
|
+
const role = isModel ? "assistant" : "user";
|
|
882
|
+
const parts = geminiContent.parts ?? [];
|
|
883
|
+
const functionResponses = [];
|
|
884
|
+
const functionCalls = [];
|
|
885
|
+
const textParts = [];
|
|
886
|
+
const contentParts = [];
|
|
887
|
+
let thinkingText = "";
|
|
888
|
+
let signature;
|
|
889
|
+
for (const part of parts) {
|
|
890
|
+
if ("thoughtSignature" in part) {
|
|
891
|
+
signature = part.thoughtSignature;
|
|
892
|
+
}
|
|
893
|
+
if ("functionResponse" in part) {
|
|
894
|
+
functionResponses.push(part);
|
|
895
|
+
} else if ("functionCall" in part) {
|
|
896
|
+
functionCalls.push(part);
|
|
897
|
+
} else if ("inlineData" in part || "file_data" in part) {
|
|
898
|
+
const inline = part.inlineData;
|
|
899
|
+
const fileData = part.file_data;
|
|
900
|
+
if (inline?.data) {
|
|
901
|
+
const mime = inline.mime_type || "image/png";
|
|
902
|
+
contentParts.push({
|
|
903
|
+
type: "image_url",
|
|
904
|
+
image_url: { url: `data:${mime};base64,${inline.data}` },
|
|
905
|
+
media_type: mime
|
|
906
|
+
});
|
|
907
|
+
} else if (fileData?.file_uri) {
|
|
908
|
+
contentParts.push({
|
|
909
|
+
type: "image_url",
|
|
910
|
+
image_url: { url: fileData.file_uri },
|
|
911
|
+
media_type: fileData.mime_type
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
} else if ("text" in part) {
|
|
915
|
+
if (part.thought === true) {
|
|
916
|
+
thinkingText += part.text ?? "";
|
|
917
|
+
} else {
|
|
918
|
+
textParts.push(part);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
for (const fr of functionResponses) {
|
|
923
|
+
const fnName = fr.functionResponse.name ?? "";
|
|
924
|
+
const queue = toolCallIdsByName.get(fnName);
|
|
925
|
+
const id = queue && queue.length > 0 ? queue.shift() : `tool_${Math.random().toString(36).substring(2, 15)}`;
|
|
926
|
+
const response = fr.functionResponse.response;
|
|
927
|
+
const result = response?.result;
|
|
928
|
+
const toolContent = typeof result === "string" ? result : result !== void 0 ? JSON.stringify(result) : response !== void 0 ? JSON.stringify(response) : "";
|
|
878
929
|
unifiedRequest.messages.push({
|
|
879
|
-
role: "
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
text: part.text || ""
|
|
883
|
-
})) || []
|
|
930
|
+
role: "tool",
|
|
931
|
+
tool_call_id: id,
|
|
932
|
+
content: toolContent
|
|
884
933
|
});
|
|
885
934
|
}
|
|
935
|
+
const toolCalls = functionCalls.map((p) => {
|
|
936
|
+
const id = p.functionCall.id || `tool_${Math.random().toString(36).substring(2, 15)}`;
|
|
937
|
+
if (p.functionCall.name) {
|
|
938
|
+
const arr = toolCallIdsByName.get(p.functionCall.name) ?? [];
|
|
939
|
+
arr.push(id);
|
|
940
|
+
toolCallIdsByName.set(p.functionCall.name, arr);
|
|
941
|
+
}
|
|
942
|
+
return {
|
|
943
|
+
id,
|
|
944
|
+
type: "function",
|
|
945
|
+
function: {
|
|
946
|
+
name: p.functionCall.name,
|
|
947
|
+
arguments: JSON.stringify(p.functionCall.args ?? {})
|
|
948
|
+
}
|
|
949
|
+
};
|
|
950
|
+
});
|
|
951
|
+
const onlyToolResults = functionResponses.length > 0 && textParts.length === 0 && functionCalls.length === 0 && contentParts.length === 0 && !thinkingText && !signature;
|
|
952
|
+
if (onlyToolResults) continue;
|
|
953
|
+
let messageContent;
|
|
954
|
+
if (contentParts.length > 0) {
|
|
955
|
+
messageContent = [
|
|
956
|
+
...textParts.map((p) => ({ type: "text", text: p.text })),
|
|
957
|
+
...contentParts
|
|
958
|
+
];
|
|
959
|
+
} else {
|
|
960
|
+
messageContent = textParts.map((p) => p.text).join("\n") || null;
|
|
961
|
+
}
|
|
962
|
+
const message = {
|
|
963
|
+
role,
|
|
964
|
+
content: messageContent
|
|
965
|
+
};
|
|
966
|
+
if (toolCalls.length > 0) {
|
|
967
|
+
message.tool_calls = toolCalls;
|
|
968
|
+
}
|
|
969
|
+
if (signature || thinkingText) {
|
|
970
|
+
message.thinking = { content: thinkingText || "", signature };
|
|
971
|
+
}
|
|
972
|
+
unifiedRequest.messages.push(message);
|
|
886
973
|
}
|
|
887
974
|
}
|
|
888
975
|
if (Array.isArray(tools)) {
|
|
@@ -895,7 +982,7 @@ function transformRequestOut(request) {
|
|
|
895
982
|
function: {
|
|
896
983
|
name: funcDecl.name,
|
|
897
984
|
description: funcDecl.description ?? "",
|
|
898
|
-
parameters: funcDecl.parameters ?? {}
|
|
985
|
+
parameters: funcDecl.parameters ?? funcDecl.parametersJsonSchema ?? {}
|
|
899
986
|
}
|
|
900
987
|
});
|
|
901
988
|
}
|