xkzoom 1.5.2 → 1.5.4
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 +87 -43
- package/dist/{chunk-UANVP2AV.mjs → chunk-27BXVTXH.mjs} +1 -1
- package/dist/{chunk-PY7W2X6W.mjs → chunk-2DR5RT3I.mjs} +52 -45
- package/dist/{chunk-YILSXMZI.mjs → chunk-2IQAT3PE.mjs} +1 -1
- package/dist/{chunk-IXYH42YO.mjs → chunk-2VSERWT6.mjs} +1 -1
- package/dist/{chunk-BSQF7NF4.mjs → chunk-3KJHUTOO.mjs} +2 -2
- package/dist/{chunk-URF75O5Z.mjs → chunk-3VA3YDYL.mjs} +1 -1
- package/dist/{chunk-RTANSWHW.mjs → chunk-3ZH273T7.mjs} +27 -27
- package/dist/{chunk-EQNHKW6L.mjs → chunk-4JXTPCOE.mjs} +1 -1
- package/dist/{chunk-WJIY3BIA.mjs → chunk-5SE4JOKE.mjs} +38 -10
- package/dist/{chunk-JD5NPIMO.mjs → chunk-5YEFG7BF.mjs} +25 -25
- package/dist/{chunk-LTBQWMAJ.mjs → chunk-6W4W5JLG.mjs} +1 -1
- package/dist/{chunk-CDLS44GZ.mjs → chunk-76MFE24I.mjs} +1 -1
- package/dist/{chunk-IPIV4NGB.mjs → chunk-76TKUYY3.mjs} +2 -2
- package/dist/{chunk-T4LPE43H.mjs → chunk-7LEEVP5O.mjs} +1 -1
- package/dist/{chunk-A5DUSLHF.mjs → chunk-DCSERRXG.mjs} +1 -1
- package/dist/{chunk-ASIBETCT.mjs → chunk-E2TTUY6R.mjs} +2 -2
- package/dist/chunk-E5LABIPO.mjs +201 -0
- package/dist/{chunk-KYTJH3R3.mjs → chunk-EE3NRJLQ.mjs} +1 -1
- package/dist/{chunk-SIIEMWE3.mjs → chunk-F35EHL5U.mjs} +3 -3
- package/dist/{chunk-K4RHLREV.mjs → chunk-FG6QCRVN.mjs} +1 -1
- package/dist/{chunk-HJN232FK.mjs → chunk-FLVJABFP.mjs} +1 -1
- package/dist/{chunk-ZM23SMRO.mjs → chunk-GIC2RBVM.mjs} +1 -1
- package/dist/{chunk-HTU5W436.mjs → chunk-GZJMFCRG.mjs} +2 -2
- package/dist/{chunk-JG3EPJ32.mjs → chunk-HAI7DJD2.mjs} +3 -3
- package/dist/{chunk-OB4JJLDC.mjs → chunk-HYSOWPIC.mjs} +2 -2
- package/dist/{chunk-G5ZU7562.mjs → chunk-IDQ5B572.mjs} +6 -6
- package/dist/{chunk-GGWUDW5W.mjs → chunk-IGDJGBAI.mjs} +1 -1
- package/dist/{chunk-A23OTVH2.mjs → chunk-J5AXFEDQ.mjs} +18 -18
- package/dist/{chunk-4DYFM3EC.mjs → chunk-JBKRS62W.mjs} +3 -3
- package/dist/{chunk-OCQUSYRP.mjs → chunk-JFFBD5TV.mjs} +14 -14
- package/dist/{chunk-VPRVZWF3.mjs → chunk-JI67TW4E.mjs} +1 -1
- package/dist/{chunk-GBG4AJON.mjs → chunk-JJKRD5DL.mjs} +1 -1
- package/dist/{chunk-7AZVQS2H.mjs → chunk-JXDHNASC.mjs} +12 -12
- package/dist/{chunk-W4MKSQGZ.mjs → chunk-K7RZQIPZ.mjs} +1 -1
- package/dist/{chunk-J5HTLG3V.mjs → chunk-KPDVZFJY.mjs} +1 -1
- package/dist/{chunk-S7FQBXOO.mjs → chunk-L252ASZW.mjs} +1 -1
- package/dist/{chunk-Z7GTU7KF.mjs → chunk-LESS4N25.mjs} +1 -1
- package/dist/{chunk-5DMSAPS2.mjs → chunk-M3ISDSQP.mjs} +7 -7
- package/dist/{chunk-HR43WO4Q.mjs → chunk-M5IU6U3O.mjs} +2 -2
- package/dist/{chunk-BV76CMVR.mjs → chunk-MBOWNG3A.mjs} +1 -1
- package/dist/{chunk-CCCPWU2O.mjs → chunk-MDZUWIBH.mjs} +4 -4
- package/dist/{chunk-YAD4VG2K.mjs → chunk-MKYCBV3H.mjs} +36 -6
- package/dist/{chunk-CORUFGMR.mjs → chunk-MPGMU75K.mjs} +4 -4
- package/dist/{chunk-7FLALKSN.mjs → chunk-MQKREMOB.mjs} +2 -2
- package/dist/{chunk-H5TJYSTV.mjs → chunk-MRTQWCNC.mjs} +1 -1
- package/dist/{chunk-CNHOCDRM.mjs → chunk-NHICONJ3.mjs} +1 -1
- package/dist/{chunk-5JGUBBXN.mjs → chunk-NIU6GWKB.mjs} +2 -2
- package/dist/{chunk-Q6XX6X24.mjs → chunk-OBYPZT2S.mjs} +6 -6
- package/dist/{chunk-Y6SJUTY6.mjs → chunk-P262PAGZ.mjs} +15 -2
- package/dist/{chunk-YPAQRMUI.mjs → chunk-PETWGCGB.mjs} +1 -1
- package/dist/{chunk-Q4XUEIOE.mjs → chunk-PW3ULDNL.mjs} +1 -1
- package/dist/{chunk-EGWLJJY7.mjs → chunk-RKZ56GST.mjs} +2 -2
- package/dist/{chunk-QUXUHJZW.mjs → chunk-TADSGGK2.mjs} +7 -7
- package/dist/{chunk-ILROJZBI.mjs → chunk-TQBVFKCT.mjs} +37 -9
- package/dist/{chunk-M52HZV6R.mjs → chunk-TVH4LII3.mjs} +1 -1
- package/dist/{chunk-GUADF3KN.mjs → chunk-ULXTQSV6.mjs} +4 -0
- package/dist/{chunk-H5DIQHEQ.mjs → chunk-UXEZFEB3.mjs} +37 -8
- package/dist/{chunk-XHO73X2N.mjs → chunk-VNEPNUBZ.mjs} +13 -13
- package/dist/{chunk-NYG3IUXK.mjs → chunk-W75Z6CZR.mjs} +1 -1
- package/dist/{chunk-PG5CHH66.mjs → chunk-YPKHMAO4.mjs} +1 -1
- package/dist/index.js +336 -31
- package/dist/index.mjs +104 -103
- package/dist/mobile/action-planner.js +21 -1
- package/dist/mobile/action-planner.mjs +60 -59
- package/dist/mobile/agent-capabilities.js +21 -1
- package/dist/mobile/agent-capabilities.mjs +60 -59
- package/dist/mobile/anthropic-incremental-deliver.js +19 -0
- package/dist/mobile/anthropic-incremental-deliver.mjs +3 -2
- package/dist/mobile/anthropic-messages-turn-runner.js +224 -8
- package/dist/mobile/anthropic-messages-turn-runner.mjs +69 -68
- package/dist/mobile/anthropic-owned-tool-executor.js +21 -1
- package/dist/mobile/anthropic-owned-tool-executor.mjs +68 -67
- package/dist/mobile/api.mjs +31 -31
- package/dist/mobile/context-compact/compact-artifact-enrich.js +19 -0
- package/dist/mobile/context-compact/compact-artifact-enrich.mjs +8 -7
- package/dist/mobile/context-compact/compact-orchestrator.js +21 -1
- package/dist/mobile/context-compact/compact-orchestrator.mjs +12 -11
- package/dist/mobile/context-compact/compact-summarizer-engine-artifact.js +19 -0
- package/dist/mobile/context-compact/compact-summarizer-engine-artifact.mjs +8 -7
- package/dist/mobile/context-compact/compact-summarizer-llm-request.js +19 -0
- package/dist/mobile/context-compact/compact-summarizer-llm-request.mjs +5 -4
- package/dist/mobile/context-compact/compact-summarizer-llm.js +19 -0
- package/dist/mobile/context-compact/compact-summarizer-llm.mjs +6 -5
- package/dist/mobile/context-compact/compact-summarizer.js +19 -0
- package/dist/mobile/context-compact/compact-summarizer.mjs +7 -6
- package/dist/mobile/context-compact/context-budget-gate.js +14 -2
- package/dist/mobile/context-compact/context-budget-gate.mjs +2 -2
- package/dist/mobile/context-compact/runtime-compact-hook.js +33 -2
- package/dist/mobile/context-compact/runtime-compact-hook.mjs +64 -63
- package/dist/mobile/group/conductor-llm.js +19 -0
- package/dist/mobile/group/conductor-llm.mjs +7 -6
- package/dist/mobile/group/conductor-plan-llm.js +19 -0
- package/dist/mobile/group/conductor-plan-llm.mjs +7 -6
- package/dist/mobile/group/floor-scheduler.mjs +2 -2
- package/dist/mobile/group/group-api-handlers.mjs +21 -21
- package/dist/mobile/group/group-session.mjs +5 -5
- package/dist/mobile/group/index.mjs +16 -16
- package/dist/mobile/group/memory-supplement.mjs +4 -4
- package/dist/mobile/group/orchestrator.mjs +15 -15
- package/dist/mobile/group/plan-runtime.mjs +4 -4
- package/dist/mobile/group/relation-distill.mjs +3 -3
- package/dist/mobile/group/runtime-integration.mjs +19 -19
- package/dist/mobile/group/team-memory-runtime.mjs +3 -3
- package/dist/mobile/index.js +336 -31
- package/dist/mobile/index.mjs +101 -100
- package/dist/mobile/interrupted-turn.js +5 -0
- package/dist/mobile/interrupted-turn.mjs +3 -1
- package/dist/mobile/memory-contract-r1-prefetch.mjs +5 -5
- package/dist/mobile/memory-contract-r5-empty-result.mjs +6 -6
- package/dist/mobile/memory-runtime-v2/eval-runner.mjs +8 -8
- package/dist/mobile/memory-runtime-v2/evidence-plan.mjs +11 -11
- package/dist/mobile/memory-runtime-v2/index.mjs +31 -31
- package/dist/mobile/memory-runtime-v2/local-source-import.mjs +3 -3
- package/dist/mobile/memory-runtime-v2/memory-control-plane.mjs +11 -11
- package/dist/mobile/memory-runtime-v2/memory-readiness.mjs +11 -11
- package/dist/mobile/memory-runtime-v2/orchestrator.mjs +4 -4
- package/dist/mobile/memory-runtime-v2/project-tool-event.mjs +2 -2
- package/dist/mobile/memory-runtime-v2/public-api.mjs +12 -12
- package/dist/mobile/memory-runtime-v2/retrieval.mjs +2 -2
- package/dist/mobile/model-context-window-budget.js +16 -2
- package/dist/mobile/model-context-window-budget.mjs +3 -1
- package/dist/mobile/native-anthropic-messages-stream.js +223 -7
- package/dist/mobile/native-anthropic-messages-stream.mjs +4 -3
- package/dist/mobile/native-anthropic-turn-errors.mjs +2 -2
- package/dist/mobile/native-openai-text-stream.js +223 -6
- package/dist/mobile/native-openai-text-stream.mjs +2 -1
- package/dist/mobile/native-reply-route.js +19 -0
- package/dist/mobile/native-reply-route.mjs +5 -4
- package/dist/mobile/native-reply-system-prompt-layers.js +21 -1
- package/dist/mobile/native-reply-system-prompt-layers.mjs +61 -60
- package/dist/mobile/native-request-diagnostics.js +230 -0
- package/dist/mobile/native-request-diagnostics.mjs +17 -0
- package/dist/mobile/native-stream-block-emit.js +19 -0
- package/dist/mobile/native-stream-block-emit.mjs +2 -1
- package/dist/mobile/openai-completions-turn-runner.js +224 -8
- package/dist/mobile/openai-completions-turn-runner.mjs +69 -68
- package/dist/mobile/runtime.js +336 -31
- package/dist/mobile/runtime.mjs +100 -99
- package/dist/mobile/stream-inbound/mobile-text-stream-pipeline.mjs +4 -4
- package/dist/mobile/tool-use-input-normalize.js +21 -1
- package/dist/mobile/tool-use-input-normalize.mjs +63 -62
- package/dist/mobile/tools/mobile-compact-tool-bridge.js +21 -1
- package/dist/mobile/tools/mobile-compact-tool-bridge.mjs +63 -62
- package/dist/org/dept-context.mjs +2 -2
- package/dist/org/index.mjs +8 -8
- package/dist/owned-tools/ceo-confirm-requirements.mjs +3 -3
- package/dist/owned-tools/ceo-decision.mjs +4 -4
- package/dist/owned-tools/ceo-ops-brief.mjs +3 -3
- package/dist/owned-tools/ceo-redirect.mjs +20 -20
- package/dist/owned-tools/commit-stack-lesson.mjs +4 -4
- package/dist/owned-tools/compact/execute.js +21 -1
- package/dist/owned-tools/compact/execute.mjs +61 -60
- package/dist/owned-tools/compact/gateway-tool-factory.js +21 -1
- package/dist/owned-tools/compact/gateway-tool-factory.mjs +62 -61
- package/dist/owned-tools/compact/registry.js +21 -1
- package/dist/owned-tools/compact/registry.mjs +60 -59
- package/dist/owned-tools/context-compact.js +21 -1
- package/dist/owned-tools/context-compact.mjs +25 -24
- package/dist/owned-tools/handoff.mjs +3 -3
- package/dist/owned-tools/memory-control.mjs +13 -13
- package/dist/owned-tools/memory-runtime-eval.mjs +12 -12
- package/dist/owned-tools/register-owned-providers.mjs +3 -3
- package/dist/owned-tools/registry.js +21 -1
- package/dist/owned-tools/registry.mjs +59 -58
- package/dist/owned-tools/router.js +21 -1
- package/dist/owned-tools/router.mjs +60 -59
- package/dist/owned-tools/runtime-bridge.js +21 -1
- package/dist/owned-tools/runtime-bridge.mjs +61 -60
- package/dist/owned-tools/tool-contract-prompt.js +21 -1
- package/dist/owned-tools/tool-contract-prompt.mjs +60 -59
- package/dist/owned-tools/tool-result-envelope.js +21 -1
- package/dist/owned-tools/tool-result-envelope.mjs +62 -61
- package/dist/owned-tools/tool-usage-guide.js +21 -1
- package/dist/owned-tools/tool-usage-guide.mjs +59 -58
- package/dist/owned-tools/tts.mjs +2 -2
- package/dist/project-pipeline/handlers.mjs +20 -20
- package/dist/project-pipeline/index.mjs +20 -20
- package/dist/project-pipeline/post-close-skill-evolution.mjs +3 -3
- package/package.json +2 -2
- package/dist/{chunk-KCZIK3TH.mjs → chunk-2QCX6RPN.mjs} +3 -3
- package/dist/{chunk-2BGXTBZX.mjs → chunk-D3N7EHB2.mjs} +8 -8
- package/dist/{chunk-JIY7IOQ5.mjs → chunk-DRY7AJMM.mjs} +3 -3
- package/dist/{chunk-VS2URZFN.mjs → chunk-HWGRW6YP.mjs} +3 -3
- package/dist/{chunk-Q7NYATKS.mjs → chunk-UR6LPERL.mjs} +3 -3
- package/dist/{chunk-TAQQSDJN.mjs → chunk-WPMJCKI2.mjs} +3 -3
- package/dist/{chunk-2TBXT3PD.mjs → chunk-XNQJRIGR.mjs} +9 -9
- package/dist/{chunk-BHMWYAVS.mjs → chunk-YYDDQEY4.mjs} +3 -3
package/dist/mobile/index.js
CHANGED
|
@@ -36405,6 +36405,199 @@ function parseOpenAiCompletionsSseDataLine(line) {
|
|
|
36405
36405
|
}
|
|
36406
36406
|
}
|
|
36407
36407
|
|
|
36408
|
+
// src/mobile/native-request-diagnostics.ts
|
|
36409
|
+
function compactLogValue(value, maxLen = 180) {
|
|
36410
|
+
const text2 = String(value ?? "").replace(/\s+/g, " ").trim();
|
|
36411
|
+
if (!text2) {
|
|
36412
|
+
return "";
|
|
36413
|
+
}
|
|
36414
|
+
return text2.length > maxLen ? `${text2.slice(0, maxLen)}...` : text2;
|
|
36415
|
+
}
|
|
36416
|
+
function readErrorProp(value, key2) {
|
|
36417
|
+
return value && typeof value === "object" ? value[key2] : void 0;
|
|
36418
|
+
}
|
|
36419
|
+
function positiveInteger2(value) {
|
|
36420
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
36421
|
+
return void 0;
|
|
36422
|
+
}
|
|
36423
|
+
return Math.trunc(value);
|
|
36424
|
+
}
|
|
36425
|
+
function formatNativeFetchErrorForLog(error) {
|
|
36426
|
+
const parts = [];
|
|
36427
|
+
let current = error;
|
|
36428
|
+
for (let depth = 0; depth < 4 && current !== null && current !== void 0; depth += 1) {
|
|
36429
|
+
const prefix = depth === 0 ? "error" : `cause${depth}`;
|
|
36430
|
+
const name = compactLogValue(readErrorProp(current, "name"));
|
|
36431
|
+
const message = current instanceof Error ? compactLogValue(current.message) : compactLogValue(readErrorProp(current, "message") ?? current);
|
|
36432
|
+
const code = compactLogValue(readErrorProp(current, "code"));
|
|
36433
|
+
const errno = compactLogValue(readErrorProp(current, "errno"));
|
|
36434
|
+
if (name) parts.push(`${prefix}Name=${name}`);
|
|
36435
|
+
if (message) parts.push(`${prefix}Message=${message}`);
|
|
36436
|
+
if (code) parts.push(`${prefix}Code=${code}`);
|
|
36437
|
+
if (errno) parts.push(`${prefix}Errno=${errno}`);
|
|
36438
|
+
current = readErrorProp(current, "cause");
|
|
36439
|
+
}
|
|
36440
|
+
return parts.join(" ") || "error=unknown";
|
|
36441
|
+
}
|
|
36442
|
+
function applyConfiguredMaxTokens(requestBody, maxTokens) {
|
|
36443
|
+
const configured = positiveInteger2(maxTokens);
|
|
36444
|
+
if (configured === void 0) {
|
|
36445
|
+
return;
|
|
36446
|
+
}
|
|
36447
|
+
const existing = positiveInteger2(requestBody.max_tokens);
|
|
36448
|
+
requestBody.max_tokens = existing === void 0 ? configured : Math.min(existing, configured);
|
|
36449
|
+
}
|
|
36450
|
+
function stringifyJsonRequestBody(requestBody) {
|
|
36451
|
+
const bodyText = JSON.stringify(requestBody);
|
|
36452
|
+
return {
|
|
36453
|
+
bodyText,
|
|
36454
|
+
bodyBytes: Buffer.byteLength(bodyText, "utf8")
|
|
36455
|
+
};
|
|
36456
|
+
}
|
|
36457
|
+
function formatRequestShape(input) {
|
|
36458
|
+
const messageCount = Array.isArray(input.messages) ? input.messages.length : 0;
|
|
36459
|
+
const toolCount = Array.isArray(input.tools) ? input.tools.length : 0;
|
|
36460
|
+
const maxTokens = positiveInteger2(input.maxTokens);
|
|
36461
|
+
return `bodyBytes=${input.bodyBytes} messages=${messageCount} tools=${toolCount} max_tokens=${maxTokens ?? "n/a"}`;
|
|
36462
|
+
}
|
|
36463
|
+
var DEFAULT_PROVIDER_FETCH_MAX_ATTEMPTS = 2;
|
|
36464
|
+
var HARD_PROVIDER_FETCH_MAX_ATTEMPTS = 4;
|
|
36465
|
+
var DEFAULT_PROVIDER_FETCH_RETRY_BASE_MS = 350;
|
|
36466
|
+
var HARD_PROVIDER_FETCH_RETRY_BASE_MS = 5e3;
|
|
36467
|
+
var RETRYABLE_NATIVE_FETCH_RE = new RegExp(
|
|
36468
|
+
[
|
|
36469
|
+
"fetch failed",
|
|
36470
|
+
"UND_ERR_CONNECT_TIMEOUT",
|
|
36471
|
+
"UND_ERR_HEADERS_TIMEOUT",
|
|
36472
|
+
"UND_ERR_SOCKET",
|
|
36473
|
+
"ECONNRESET",
|
|
36474
|
+
"ETIMEDOUT",
|
|
36475
|
+
"ECONNREFUSED",
|
|
36476
|
+
"ENOTFOUND",
|
|
36477
|
+
"EAI_AGAIN",
|
|
36478
|
+
"socket hang up",
|
|
36479
|
+
"network connection lost",
|
|
36480
|
+
"network request failed"
|
|
36481
|
+
].join("|"),
|
|
36482
|
+
"i"
|
|
36483
|
+
);
|
|
36484
|
+
function readClampedPositiveEnvInt(env, key2, fallback, max) {
|
|
36485
|
+
const raw = (env[key2] ?? "").trim();
|
|
36486
|
+
const n = Number.parseInt(raw, 10);
|
|
36487
|
+
if (!Number.isFinite(n) || n <= 0) {
|
|
36488
|
+
return fallback;
|
|
36489
|
+
}
|
|
36490
|
+
return Math.min(Math.trunc(n), max);
|
|
36491
|
+
}
|
|
36492
|
+
function readClampedNonNegativeEnvInt(env, key2, fallback, max) {
|
|
36493
|
+
const raw = (env[key2] ?? "").trim();
|
|
36494
|
+
const n = Number.parseInt(raw, 10);
|
|
36495
|
+
if (!Number.isFinite(n) || n < 0) {
|
|
36496
|
+
return fallback;
|
|
36497
|
+
}
|
|
36498
|
+
return Math.min(Math.trunc(n), max);
|
|
36499
|
+
}
|
|
36500
|
+
function readProviderFetchMaxAttempts(env) {
|
|
36501
|
+
return readClampedPositiveEnvInt(
|
|
36502
|
+
env,
|
|
36503
|
+
"XKZOOM_NATIVE_PROVIDER_FETCH_MAX_ATTEMPTS",
|
|
36504
|
+
DEFAULT_PROVIDER_FETCH_MAX_ATTEMPTS,
|
|
36505
|
+
HARD_PROVIDER_FETCH_MAX_ATTEMPTS
|
|
36506
|
+
);
|
|
36507
|
+
}
|
|
36508
|
+
function readProviderFetchRetryBaseMs(env) {
|
|
36509
|
+
return readClampedNonNegativeEnvInt(
|
|
36510
|
+
env,
|
|
36511
|
+
"XKZOOM_NATIVE_PROVIDER_FETCH_RETRY_BASE_MS",
|
|
36512
|
+
DEFAULT_PROVIDER_FETCH_RETRY_BASE_MS,
|
|
36513
|
+
HARD_PROVIDER_FETCH_RETRY_BASE_MS
|
|
36514
|
+
);
|
|
36515
|
+
}
|
|
36516
|
+
function isAbortLikeFetchError(error) {
|
|
36517
|
+
const name = compactLogValue(readErrorProp(error, "name"));
|
|
36518
|
+
return name === "AbortError";
|
|
36519
|
+
}
|
|
36520
|
+
function collectFetchErrorText(error) {
|
|
36521
|
+
const parts = [];
|
|
36522
|
+
let current = error;
|
|
36523
|
+
for (let depth = 0; depth < 4 && current !== null && current !== void 0; depth += 1) {
|
|
36524
|
+
parts.push(
|
|
36525
|
+
compactLogValue(readErrorProp(current, "name")),
|
|
36526
|
+
current instanceof Error ? compactLogValue(current.message) : compactLogValue(readErrorProp(current, "message") ?? current),
|
|
36527
|
+
compactLogValue(readErrorProp(current, "code")),
|
|
36528
|
+
compactLogValue(readErrorProp(current, "errno"))
|
|
36529
|
+
);
|
|
36530
|
+
current = readErrorProp(current, "cause");
|
|
36531
|
+
}
|
|
36532
|
+
return parts.filter(Boolean).join(" ");
|
|
36533
|
+
}
|
|
36534
|
+
function isRetryableNativeProviderFetchError(error) {
|
|
36535
|
+
return !isAbortLikeFetchError(error) && RETRYABLE_NATIVE_FETCH_RE.test(collectFetchErrorText(error));
|
|
36536
|
+
}
|
|
36537
|
+
function formatProviderRetryContext(context) {
|
|
36538
|
+
const parts = [
|
|
36539
|
+
`provider=${context.providerId}`,
|
|
36540
|
+
`model=${context.model}`,
|
|
36541
|
+
context.adapter ? `adapter=${context.adapter}` : "",
|
|
36542
|
+
typeof context.iteration === "number" ? `iteration=${context.iteration}` : ""
|
|
36543
|
+
];
|
|
36544
|
+
return parts.filter(Boolean).join(" ");
|
|
36545
|
+
}
|
|
36546
|
+
function asAbortSignal(signal) {
|
|
36547
|
+
if (signal && typeof signal === "object" && "aborted" in signal) {
|
|
36548
|
+
return signal;
|
|
36549
|
+
}
|
|
36550
|
+
return void 0;
|
|
36551
|
+
}
|
|
36552
|
+
async function waitForProviderFetchRetryDelay(delayMs, signal) {
|
|
36553
|
+
if (delayMs <= 0) {
|
|
36554
|
+
return;
|
|
36555
|
+
}
|
|
36556
|
+
if (signal?.aborted) {
|
|
36557
|
+
throw new DOMException("Aborted", "AbortError");
|
|
36558
|
+
}
|
|
36559
|
+
await new Promise((resolve10, reject) => {
|
|
36560
|
+
const timer = setTimeout(() => {
|
|
36561
|
+
signal?.removeEventListener("abort", onAbort);
|
|
36562
|
+
resolve10();
|
|
36563
|
+
}, delayMs);
|
|
36564
|
+
const onAbort = () => {
|
|
36565
|
+
clearTimeout(timer);
|
|
36566
|
+
reject(new DOMException("Aborted", "AbortError"));
|
|
36567
|
+
};
|
|
36568
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
36569
|
+
});
|
|
36570
|
+
}
|
|
36571
|
+
async function fetchNativeProviderWithRetry(url, init, context, env = process.env) {
|
|
36572
|
+
const maxAttempts = readProviderFetchMaxAttempts(env);
|
|
36573
|
+
const retryBaseMs = readProviderFetchRetryBaseMs(env);
|
|
36574
|
+
const signal = asAbortSignal(init.signal);
|
|
36575
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
|
|
36576
|
+
try {
|
|
36577
|
+
return await fetch(url, init);
|
|
36578
|
+
} catch (error) {
|
|
36579
|
+
const retry = attempt < maxAttempts && !signal?.aborted && isRetryableNativeProviderFetchError(error);
|
|
36580
|
+
context.log(
|
|
36581
|
+
`[XKZOOM][native-reply][${context.label}] fetch_failed ${url} ${formatProviderRetryContext(context)} attempt=${attempt}/${maxAttempts} retry=${retry ? 1 : 0} ${formatRequestShape({
|
|
36582
|
+
bodyBytes: context.bodyBytes,
|
|
36583
|
+
messages: context.messages,
|
|
36584
|
+
tools: context.tools,
|
|
36585
|
+
maxTokens: context.maxTokens
|
|
36586
|
+
})} ${formatNativeFetchErrorForLog(error)}`
|
|
36587
|
+
);
|
|
36588
|
+
if (!retry) {
|
|
36589
|
+
throw error;
|
|
36590
|
+
}
|
|
36591
|
+
const delayMs = retryBaseMs * attempt;
|
|
36592
|
+
context.log(
|
|
36593
|
+
`[XKZOOM][native-reply][${context.label}] fetch_retry ${url} ${formatProviderRetryContext(context)} nextAttempt=${attempt + 1}/${maxAttempts} delayMs=${delayMs}`
|
|
36594
|
+
);
|
|
36595
|
+
await waitForProviderFetchRetryDelay(delayMs, signal);
|
|
36596
|
+
}
|
|
36597
|
+
}
|
|
36598
|
+
throw new Error(`native provider fetch retry exhausted: ${url}`);
|
|
36599
|
+
}
|
|
36600
|
+
|
|
36408
36601
|
// src/mobile/native-openai-text-stream.ts
|
|
36409
36602
|
var isRecord6 = isGatewayConfigRecord;
|
|
36410
36603
|
function resolveOpenAiCompletionsBodyExtras(provider, baseUrl) {
|
|
@@ -36625,12 +36818,36 @@ async function runNativeOpenAiTextStreamToDispatcher(params) {
|
|
|
36625
36818
|
if (params.providerAccelerationPlan || providerAcceleration.application.applied || providerAcceleration.application.warnings.length > 0) {
|
|
36626
36819
|
params.log(formatProviderAccelerationApplication(providerAcceleration.application));
|
|
36627
36820
|
}
|
|
36628
|
-
|
|
36629
|
-
|
|
36630
|
-
|
|
36631
|
-
|
|
36632
|
-
|
|
36633
|
-
|
|
36821
|
+
applyConfiguredMaxTokens(requestBody, cfg.maxTokens);
|
|
36822
|
+
const { bodyText, bodyBytes } = stringifyJsonRequestBody(requestBody);
|
|
36823
|
+
params.log(
|
|
36824
|
+
`[XKZOOM][native-reply][openai-completions] request_shape ${formatRequestShape({
|
|
36825
|
+
bodyBytes,
|
|
36826
|
+
messages: chatMessages,
|
|
36827
|
+
tools: toolsForRequest,
|
|
36828
|
+
maxTokens: requestBody.max_tokens
|
|
36829
|
+
})}`
|
|
36830
|
+
);
|
|
36831
|
+
const res = await fetchNativeProviderWithRetry(
|
|
36832
|
+
url,
|
|
36833
|
+
{
|
|
36834
|
+
method: "POST",
|
|
36835
|
+
headers: buildBearerOpenAiHeaders(cfg),
|
|
36836
|
+
body: bodyText,
|
|
36837
|
+
signal: params.signal
|
|
36838
|
+
},
|
|
36839
|
+
{
|
|
36840
|
+
label: "openai-completions",
|
|
36841
|
+
providerId: cfg.providerId,
|
|
36842
|
+
model: cfg.model,
|
|
36843
|
+
adapter: "openai-completions",
|
|
36844
|
+
bodyBytes,
|
|
36845
|
+
messages: chatMessages,
|
|
36846
|
+
tools: toolsForRequest,
|
|
36847
|
+
maxTokens: requestBody.max_tokens,
|
|
36848
|
+
log: params.log
|
|
36849
|
+
}
|
|
36850
|
+
);
|
|
36634
36851
|
if (!res.ok) {
|
|
36635
36852
|
const t = await res.text();
|
|
36636
36853
|
throw new Error(`native OpenAI HTTP ${res.status}: ${t.slice(0, 500)}`);
|
|
@@ -38087,7 +38304,8 @@ async function runNativeAnthropicMessagesStreamToDispatcher(params) {
|
|
|
38087
38304
|
if (params.providerAccelerationPlan || providerAcceleration.application.applied || providerAcceleration.application.warnings.length > 0) {
|
|
38088
38305
|
params.log(formatProviderAccelerationApplication2(providerAcceleration.application));
|
|
38089
38306
|
}
|
|
38090
|
-
const
|
|
38307
|
+
const adapter = selectAnthropicAdapterByBaseUrl(cfg.baseUrl);
|
|
38308
|
+
const thinkingForBody = adapter.resolveThinkingForBody({
|
|
38091
38309
|
reasoningMode: params.reasoningMode,
|
|
38092
38310
|
model: cfg.model,
|
|
38093
38311
|
configuredThinking: requestBody.thinking
|
|
@@ -38095,12 +38313,34 @@ async function runNativeAnthropicMessagesStreamToDispatcher(params) {
|
|
|
38095
38313
|
if (thinkingForBody !== void 0) {
|
|
38096
38314
|
requestBody.thinking = thinkingForBody;
|
|
38097
38315
|
}
|
|
38098
|
-
|
|
38099
|
-
|
|
38100
|
-
|
|
38101
|
-
|
|
38102
|
-
|
|
38103
|
-
|
|
38316
|
+
applyConfiguredMaxTokens(requestBody, cfg.maxTokens);
|
|
38317
|
+
const { bodyText, bodyBytes } = stringifyJsonRequestBody(requestBody);
|
|
38318
|
+
params.log(
|
|
38319
|
+
`[XKZOOM][native-reply][anthropic-messages] request_shape ${formatRequestShape({
|
|
38320
|
+
bodyBytes,
|
|
38321
|
+
messages: transcriptMessages,
|
|
38322
|
+
maxTokens: requestBody.max_tokens
|
|
38323
|
+
})}`
|
|
38324
|
+
);
|
|
38325
|
+
const res = await fetchNativeProviderWithRetry(
|
|
38326
|
+
url,
|
|
38327
|
+
{
|
|
38328
|
+
method: "POST",
|
|
38329
|
+
headers: buildNativeAnthropicRequestHeaders(cfg),
|
|
38330
|
+
body: bodyText,
|
|
38331
|
+
signal: params.signal
|
|
38332
|
+
},
|
|
38333
|
+
{
|
|
38334
|
+
label: "anthropic-messages",
|
|
38335
|
+
providerId: cfg.providerId,
|
|
38336
|
+
model: cfg.model,
|
|
38337
|
+
adapter: adapter.id,
|
|
38338
|
+
bodyBytes,
|
|
38339
|
+
messages: transcriptMessages,
|
|
38340
|
+
maxTokens: requestBody.max_tokens,
|
|
38341
|
+
log: params.log
|
|
38342
|
+
}
|
|
38343
|
+
);
|
|
38104
38344
|
if (!res.ok) {
|
|
38105
38345
|
const t = await res.text();
|
|
38106
38346
|
throw new Error(`native anthropic-messages HTTP ${res.status}: ${t.slice(0, 500)}`);
|
|
@@ -40242,15 +40482,27 @@ function buildSessionTranscriptMeterFromMessages(messages) {
|
|
|
40242
40482
|
var TRANSCRIPT_BUDGET_BYTES_PER_TOKEN = 4;
|
|
40243
40483
|
var TRANSCRIPT_CONTEXT_WINDOW_RATIO = 0.35;
|
|
40244
40484
|
var MIN_TRANSCRIPT_BUDGET_BYTES = 64 * 1024;
|
|
40245
|
-
var
|
|
40246
|
-
|
|
40485
|
+
var DEFAULT_MAX_NATIVE_TRANSCRIPT_BUDGET_BYTES = 128 * 1024;
|
|
40486
|
+
var HARD_MAX_TRANSCRIPT_BUDGET_BYTES = 4 * 1024 * 1024;
|
|
40487
|
+
function positiveInteger3(value) {
|
|
40247
40488
|
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
40248
40489
|
return void 0;
|
|
40249
40490
|
}
|
|
40250
40491
|
return Math.trunc(value);
|
|
40251
40492
|
}
|
|
40493
|
+
function readMaxTranscriptBudgetBytes(env = process.env) {
|
|
40494
|
+
const raw = env.XKZOOM_NATIVE_TRANSCRIPT_MAX_REQUEST_BYTES?.trim();
|
|
40495
|
+
if (!raw) {
|
|
40496
|
+
return DEFAULT_MAX_NATIVE_TRANSCRIPT_BUDGET_BYTES;
|
|
40497
|
+
}
|
|
40498
|
+
const parsed = Number.parseInt(raw, 10);
|
|
40499
|
+
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
40500
|
+
return DEFAULT_MAX_NATIVE_TRANSCRIPT_BUDGET_BYTES;
|
|
40501
|
+
}
|
|
40502
|
+
return Math.min(HARD_MAX_TRANSCRIPT_BUDGET_BYTES, Math.max(MIN_TRANSCRIPT_BUDGET_BYTES, parsed));
|
|
40503
|
+
}
|
|
40252
40504
|
function resolveTranscriptBudgetBytesForContextWindow(contextWindowTokens) {
|
|
40253
|
-
const tokens =
|
|
40505
|
+
const tokens = positiveInteger3(contextWindowTokens);
|
|
40254
40506
|
if (tokens === void 0) {
|
|
40255
40507
|
return void 0;
|
|
40256
40508
|
}
|
|
@@ -40258,7 +40510,7 @@ function resolveTranscriptBudgetBytesForContextWindow(contextWindowTokens) {
|
|
|
40258
40510
|
tokens * TRANSCRIPT_CONTEXT_WINDOW_RATIO * TRANSCRIPT_BUDGET_BYTES_PER_TOKEN
|
|
40259
40511
|
);
|
|
40260
40512
|
return Math.min(
|
|
40261
|
-
|
|
40513
|
+
readMaxTranscriptBudgetBytes(),
|
|
40262
40514
|
Math.max(MIN_TRANSCRIPT_BUDGET_BYTES, estimated)
|
|
40263
40515
|
);
|
|
40264
40516
|
}
|
|
@@ -54639,15 +54891,37 @@ async function runNativeOpenAiCompletionsTurnToDispatcher(params) {
|
|
|
54639
54891
|
if (params.providerAccelerationPlan || providerAcceleration.application.applied || providerAcceleration.application.warnings.length > 0) {
|
|
54640
54892
|
params.log(formatProviderAccelerationApplication3(providerAcceleration.application));
|
|
54641
54893
|
}
|
|
54894
|
+
applyConfiguredMaxTokens(requestBody, cfg.maxTokens);
|
|
54895
|
+
const { bodyText, bodyBytes } = stringifyJsonRequestBody(requestBody);
|
|
54642
54896
|
params.log(
|
|
54643
|
-
`[XKZOOM][native-reply][openai-turn] POST ${url} provider=${cfg.providerId} model=${cfg.model} adapter=${adapter.id} iteration=${iteration} tools=${toolsForRequest ? toolsForRequest.length : 0} tool_choice=${toolChoiceLog} transcriptTurns=${messages.filter((m) => m.role !== "system").length}`
|
|
54897
|
+
`[XKZOOM][native-reply][openai-turn] POST ${url} provider=${cfg.providerId} model=${cfg.model} adapter=${adapter.id} iteration=${iteration} tools=${toolsForRequest ? toolsForRequest.length : 0} tool_choice=${toolChoiceLog} transcriptTurns=${messages.filter((m) => m.role !== "system").length} ` + formatRequestShape({
|
|
54898
|
+
bodyBytes,
|
|
54899
|
+
messages,
|
|
54900
|
+
tools: toolsForRequest,
|
|
54901
|
+
maxTokens: requestBody.max_tokens
|
|
54902
|
+
})
|
|
54903
|
+
);
|
|
54904
|
+
const res = await fetchNativeProviderWithRetry(
|
|
54905
|
+
url,
|
|
54906
|
+
{
|
|
54907
|
+
method: "POST",
|
|
54908
|
+
headers: adapter.buildHeaders(cfg),
|
|
54909
|
+
body: bodyText,
|
|
54910
|
+
signal: params.signal
|
|
54911
|
+
},
|
|
54912
|
+
{
|
|
54913
|
+
label: "openai-turn",
|
|
54914
|
+
providerId: cfg.providerId,
|
|
54915
|
+
model: cfg.model,
|
|
54916
|
+
adapter: adapter.id,
|
|
54917
|
+
iteration,
|
|
54918
|
+
bodyBytes,
|
|
54919
|
+
messages,
|
|
54920
|
+
tools: toolsForRequest,
|
|
54921
|
+
maxTokens: requestBody.max_tokens,
|
|
54922
|
+
log: params.log
|
|
54923
|
+
}
|
|
54644
54924
|
);
|
|
54645
|
-
const res = await fetch(url, {
|
|
54646
|
-
method: "POST",
|
|
54647
|
-
headers: adapter.buildHeaders(cfg),
|
|
54648
|
-
body: JSON.stringify(requestBody),
|
|
54649
|
-
signal: params.signal
|
|
54650
|
-
});
|
|
54651
54925
|
if (!res.ok) {
|
|
54652
54926
|
const t = await res.text();
|
|
54653
54927
|
if (policyToolChoiceApplied && requestAttempt === 0 && isOpenAiToolChoiceCompatibilityHttpError(res.status, t)) {
|
|
@@ -55478,15 +55752,37 @@ function createFetchAnthropicTurnStreamFn(cfg, log, providerAccelerationPlan, pr
|
|
|
55478
55752
|
toolChoiceLog = `skipped(${policy.kind}:adapter-undefined)`;
|
|
55479
55753
|
}
|
|
55480
55754
|
}
|
|
55755
|
+
applyConfiguredMaxTokens(requestBody, cfg.maxTokens);
|
|
55756
|
+
const { bodyText, bodyBytes } = stringifyJsonRequestBody(requestBody);
|
|
55481
55757
|
log(
|
|
55482
|
-
`[XKZOOM][native-reply][anthropic-turn] POST ${url} adapter=${adapter.id} provider=${cfg.providerId} model=${cfg.model} iteration=${req.iteration} tools=${Array.isArray(req.tools) ? req.tools.length : 0} tool_choice=${toolChoiceLog}` + (requestBody.thinking !== void 0 && requestBody.thinking !== null ? ` thinking=${requestBody.thinking.type ?? "1"}` : " thinking=0")
|
|
55758
|
+
`[XKZOOM][native-reply][anthropic-turn] POST ${url} adapter=${adapter.id} provider=${cfg.providerId} model=${cfg.model} iteration=${req.iteration} tools=${Array.isArray(req.tools) ? req.tools.length : 0} tool_choice=${toolChoiceLog}` + (requestBody.thinking !== void 0 && requestBody.thinking !== null ? ` thinking=${requestBody.thinking.type ?? "1"}` : " thinking=0") + ` ${formatRequestShape({
|
|
55759
|
+
bodyBytes,
|
|
55760
|
+
messages: req.messages,
|
|
55761
|
+
tools: req.tools,
|
|
55762
|
+
maxTokens: requestBody.max_tokens
|
|
55763
|
+
})}`
|
|
55764
|
+
);
|
|
55765
|
+
const res = await fetchNativeProviderWithRetry(
|
|
55766
|
+
url,
|
|
55767
|
+
{
|
|
55768
|
+
method: "POST",
|
|
55769
|
+
headers,
|
|
55770
|
+
body: bodyText,
|
|
55771
|
+
signal
|
|
55772
|
+
},
|
|
55773
|
+
{
|
|
55774
|
+
label: "anthropic-turn",
|
|
55775
|
+
providerId: cfg.providerId,
|
|
55776
|
+
model: cfg.model,
|
|
55777
|
+
adapter: adapter.id,
|
|
55778
|
+
iteration: req.iteration,
|
|
55779
|
+
bodyBytes,
|
|
55780
|
+
messages: req.messages,
|
|
55781
|
+
tools: req.tools,
|
|
55782
|
+
maxTokens: requestBody.max_tokens,
|
|
55783
|
+
log
|
|
55784
|
+
}
|
|
55483
55785
|
);
|
|
55484
|
-
const res = await fetch(url, {
|
|
55485
|
-
method: "POST",
|
|
55486
|
-
headers,
|
|
55487
|
-
body: JSON.stringify(requestBody),
|
|
55488
|
-
signal
|
|
55489
|
-
});
|
|
55490
55786
|
if (!res.ok) {
|
|
55491
55787
|
const t = await res.text();
|
|
55492
55788
|
throw new Error(`native anthropic-turn HTTP ${res.status}: ${t.slice(0, 500)}`);
|
|
@@ -55736,6 +56032,9 @@ function createInterruptedTurnSnapshot(params) {
|
|
|
55736
56032
|
...clipText(errMessage, MAX_PREVIEW_CHARS) ? { errorMessage: clipText(errMessage, MAX_PREVIEW_CHARS) } : {}
|
|
55737
56033
|
};
|
|
55738
56034
|
}
|
|
56035
|
+
function hasInterruptedTurnRecoveryEvidence(snapshot) {
|
|
56036
|
+
return snapshot.visibleTextLength > 0 || Boolean(snapshot.assistantPartialText?.trim()) || Boolean(snapshot.toolCallSummaries?.length);
|
|
56037
|
+
}
|
|
55739
56038
|
function isInterruptedTurnResumeRequest(text2) {
|
|
55740
56039
|
const raw = typeof text2 === "string" ? text2.trim() : "";
|
|
55741
56040
|
if (!raw) {
|
|
@@ -59813,6 +60112,12 @@ ${inbound.bodyText}` : inbound.bodyText;
|
|
|
59813
60112
|
lastToolName: params.lastToolName ?? lastToolNameForInterruptedTurn,
|
|
59814
60113
|
error: params.error
|
|
59815
60114
|
});
|
|
60115
|
+
if (!hasInterruptedTurnRecoveryEvidence(snapshot)) {
|
|
60116
|
+
this.logInfo(
|
|
60117
|
+
`[XKZOOM][turn-timeout][snapshot] skipped session=${session.id} conversationId=${identity.conversationId ?? "none"} userMessage=${userMessage.id} targetMessage=${target.id} assistantMessage=${assistantMessage?.id ?? "none"} turn_timeout_kind=${snapshot.turn_timeout_kind} recoverableEvidence=0 visibleTextLength=${snapshot.visibleTextLength}`
|
|
60118
|
+
);
|
|
60119
|
+
return null;
|
|
60120
|
+
}
|
|
59816
60121
|
target.interruptedTurn = snapshot;
|
|
59817
60122
|
this.store.persistMessage(session.id, target.id);
|
|
59818
60123
|
this.logInfo(
|