nolo-cli 0.251.0-alpha.1 → 0.252.0-alpha.2
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/{_executeModel-55PHWQWB.js → _executeModel-RXHY2BDR.js} +47 -47
- package/{action-WZTKEF5H.js → action-4MADDU52.js} +5 -5
- package/{addContentAction-LBVAQUF7.js → addContentAction-F4XO3VRF.js} +8 -8
- package/{addDialogAgentAction-6WAUSUSZ.js → addDialogAgentAction-NSCVHTZJ.js} +7 -7
- package/{agentDeleteCommand-KEO3KDK3.js → agentDeleteCommand-EJAI2VTH.js} +69 -68
- package/{agentEmailCommands-RWJQQRNT.js → agentEmailCommands-YBKHZMMZ.js} +69 -68
- package/{agentListCommands-L3TLPLNH.js → agentListCommands-M2KYLAOB.js} +226 -39
- package/{agentMachineCommands-EZWWXWDH.js → agentMachineCommands-GLY6NJWZ.js} +31 -29
- package/{agentProviderCommands-C5T7C5KZ.js → agentProviderCommands-QLTABYR7.js} +2 -2
- package/{agentRecordCommands-7W2CGHJJ.js → agentRecordCommands-JANPX6XI.js} +68 -67
- package/{agentRunCommand-POL6B6BO.js → agentRunCommand-TNLAXLUU.js} +68 -67
- package/{agentRunControl-FKSXBUAF.js → agentRunControl-KNNDEEDI.js} +8 -6
- package/{agentRuntimeLocal-WSHWNIMF.js → agentRuntimeLocal-EOW6FFXL.js} +26 -25
- package/{agentSlice-3G2YLTA4.js → agentSlice-PVFGBJXB.js} +8 -8
- package/{appDeleteCommands-DZZQCVYH.js → appDeleteCommands-3VCRRWUX.js} +33 -31
- package/{appDeployCommands-NJJBVNH5.js → appDeployCommands-XN6IEMYK.js} +33 -31
- package/{appDeployStatusCommands-GBOAFEYG.js → appDeployStatusCommands-ZSJJXMVR.js} +33 -31
- package/{appGetCommands-GOOKYMKO.js → appGetCommands-DJ7YQCEE.js} +33 -31
- package/{appListCommands-OBCGUG3S.js → appListCommands-4KU5CV5H.js} +33 -31
- package/{authCommand-77CRN332.js → authCommand-5DC3ES4Q.js} +12 -12
- package/{builtinSkillRegistry-PFTTFPWW.js → builtinSkillRegistry-PQWEXSFW.js} +1 -1
- package/{chromeOpsCommands-6RLEBBJJ.js → chromeOpsCommands-AA555ANS.js} +1 -1
- package/{chunk-LOXR4TQN.js → chunk-25GCVHBZ.js} +2 -2
- package/{chunk-A55E2OCP.js → chunk-26KL6533.js} +639 -125
- package/{chunk-MAA42MMV.js → chunk-2FZVXOFX.js} +4 -4
- package/{chunk-CUYFRVJF.js → chunk-2HF6DINU.js} +6 -6
- package/{chunk-ESN4WNWU.js → chunk-2JHGUL5K.js} +2 -2
- package/{chunk-GMWZRXRM.js → chunk-3272HU62.js} +1 -1
- package/{chunk-43VT5PLM.js → chunk-3LL5HRIJ.js} +1 -1
- package/{chunk-ZQ6K57FJ.js → chunk-4YPH5KRA.js} +1 -1
- package/{chunk-T4V6C3J3.js → chunk-52M4RYVP.js} +1 -1
- package/{chunk-OQCAHPDQ.js → chunk-5QEOTC35.js} +4 -4
- package/{chunk-R7D5SRAZ.js → chunk-5UYDG6HP.js} +17 -0
- package/{chunk-Z7A2ZQ5X.js → chunk-64ACTEAE.js} +1 -1
- package/{chunk-CTWCZKNS.js → chunk-6SOWMEAY.js} +4 -4
- package/{chunk-UCMUXZJV.js → chunk-7XO73H5X.js} +111 -1
- package/{chunk-222CJNC2.js → chunk-BLBGVSLB.js} +3 -3
- package/{chunk-ZM5AZTQG.js → chunk-BTQU2PRC.js} +19 -7
- package/{chunk-QJ5YDTEF.js → chunk-BVCCRSGK.js} +42 -24
- package/{chunk-SX6AWTNK.js → chunk-BZLGPM5B.js} +3 -3
- package/chunk-CGSIW2KI.js +594 -0
- package/{chunk-LTVEOOZL.js → chunk-CIAV4WK2.js} +14 -1
- package/{chunk-Q5KZ6F55.js → chunk-CSTCYYCR.js} +19 -17
- package/{chunk-D3E5MYXO.js → chunk-CYGFNMCH.js} +1 -1
- package/{chunk-MZVCFV3T.js → chunk-D3WOFN6N.js} +3 -3
- package/{chunk-VUHKG4KS.js → chunk-DNNPARJK.js} +9 -5
- package/{chunk-MTS5DCL2.js → chunk-EG3JTV7H.js} +2 -2
- package/{chunk-6ASGEP5D.js → chunk-EJQE5HB7.js} +1 -1
- package/{chunk-D35TOEMM.js → chunk-EPBEZKYK.js} +137 -53
- package/{chunk-KJDN2YRH.js → chunk-EQJK6LSN.js} +4 -4
- package/{chunk-N3SEV3CG.js → chunk-F6GZFIGR.js} +79 -30
- package/{chunk-6UNJ6JGR.js → chunk-FJPVVLP3.js} +4 -4
- package/{chunk-L5HV76QT.js → chunk-FRC2DNTN.js} +1 -1
- package/{chunk-W3HSD32M.js → chunk-FXEPZKNJ.js} +2 -2
- package/{chunk-WWTSEBDF.js → chunk-GIXWVN2W.js} +1 -1
- package/{chunk-IFJ6OTI6.js → chunk-GJ4UTSAW.js} +33 -11
- package/{chunk-ZKKJZBNO.js → chunk-GUFTHWDO.js} +10 -10
- package/{chunk-KHVTT4WW.js → chunk-HF4C5WIU.js} +81 -542
- package/{chunk-W2N4OAKM.js → chunk-IQXMWBI6.js} +3 -3
- package/chunk-IVK2KT3H.js +209 -0
- package/{chunk-PLS2MJVW.js → chunk-J4KLOLYP.js} +4 -4
- package/{chunk-PQ63BDV3.js → chunk-JPXACKSW.js} +9 -1
- package/{chunk-CDIRKCPD.js → chunk-JX2IG37T.js} +153 -153
- package/{chunk-TGKAUEV3.js → chunk-K7RWY7JH.js} +14 -11
- package/{chunk-5IKKSJYX.js → chunk-KHYSFS3W.js} +76 -2
- package/{chunk-K5CIMK3R.js → chunk-KO6JNZCF.js} +115 -57
- package/{chunk-XJSEST7D.js → chunk-KQBGXCKM.js} +3 -3
- package/{chunk-HS7MLR74.js → chunk-KZ4A7EIV.js} +3 -5
- package/{chunk-QJTZ76CP.js → chunk-LS5KAVFQ.js} +1 -0
- package/{chunk-K26XPZRB.js → chunk-LVZVSLKO.js} +29 -9
- package/{chunk-HD5EKSLF.js → chunk-MDWHMQON.js} +3 -3
- package/{chunk-X337N4D6.js → chunk-MOAVLCCM.js} +4 -4
- package/{chunk-OARYOLF3.js → chunk-N2MDL5AZ.js} +12 -12
- package/{chunk-ZSRR6HCH.js → chunk-N2ZAY2DK.js} +1 -1
- package/{chunk-X3OZ655T.js → chunk-N7UXTVAR.js} +2 -2
- package/{chunk-KGOBJAWC.js → chunk-NJDOID7N.js} +207 -94
- package/{chunk-NTNX77FI.js → chunk-NRWZHHOB.js} +6 -6
- package/{chunk-3ZWJVKFB.js → chunk-NWZRCUHM.js} +84 -40
- package/{chunk-HQLCYPL4.js → chunk-OB4FBZXJ.js} +4 -4
- package/{chunk-CD2DK5JA.js → chunk-OKH74FML.js} +2 -1
- package/{chunk-IZWGO2ZS.js → chunk-OMIXG25B.js} +1 -1
- package/{chunk-CJ2BP6V7.js → chunk-OOV5JN25.js} +2 -2
- package/{chunk-3KWJPTVP.js → chunk-OQOXDQLB.js} +4 -4
- package/{chunk-LXKK7QFI.js → chunk-OTNPEE4G.js} +54 -24
- package/{chunk-LMMRWGGJ.js → chunk-OTOPQXP5.js} +2 -2
- package/{chunk-AS6L5KSD.js → chunk-P4R5KXU7.js} +2 -2
- package/{chunk-VTHWBTRE.js → chunk-PENRYZ4D.js} +1 -1
- package/{chunk-WZPG63Q4.js → chunk-PIVTQRX6.js} +43 -13
- package/{chunk-SLUZ6FBJ.js → chunk-Q5M27DUE.js} +1 -1
- package/{chunk-XC5RPSXK.js → chunk-QV32GSVO.js} +2 -2
- package/{chunk-WQDTSK5U.js → chunk-REINTCQF.js} +8 -2
- package/{chunk-IXAGRTAR.js → chunk-SBBSUBY3.js} +1 -1
- package/{chunk-MTM4LRVG.js → chunk-SCY2O7CU.js} +2 -2
- package/{chunk-FAFDIQJG.js → chunk-U3ZK2MXG.js} +3 -3
- package/{chunk-PKMDYRAM.js → chunk-UDQZ5JT7.js} +175 -241
- package/{chunk-UR4ZMRV3.js → chunk-UGHNYYOE.js} +2 -2
- package/{chunk-KZVRPCOR.js → chunk-UTFTXJU3.js} +4 -4
- package/{chunk-GX6DITLQ.js → chunk-UUCYUN6Y.js} +1 -1
- package/{chunk-U2OWDHDE.js → chunk-VH7AQEEF.js} +2 -2
- package/{chunk-QLGL43SI.js → chunk-VZWYP7LD.js} +2 -2
- package/{chunk-6XVPMGXK.js → chunk-W4S5FQWQ.js} +10 -4
- package/{chunk-KRAPKTAS.js → chunk-WJOC3AEM.js} +2 -2
- package/{chunk-2FK2KZSL.js → chunk-WLHUANWZ.js} +1 -1
- package/{chunk-JUYI2D7J.js → chunk-WNIBQBOR.js} +1 -1
- package/{chunk-BQ4CZEVZ.js → chunk-YWLMUFZ5.js} +1 -1
- package/{chunk-CD64YXRB.js → chunk-Z47UZT27.js} +1 -1
- package/{chunk-75TXQ4GY.js → chunk-ZMWDHPNG.js} +15 -29
- package/{chunk-CFDOIIOZ.js → chunk-ZMXO5G3E.js} +29 -23
- package/{cliAgentConfigHelpers-N6LTB7UY.js → cliAgentConfigHelpers-FKBPFPKR.js} +6 -6
- package/{cliLocalAgentRecordReader-NFNGYOOW.js → cliLocalAgentRecordReader-OHAC4JTY.js} +30 -29
- package/{commandRegistry-OM5DU4DS.js → commandRegistry-YQMAXCLP.js} +81 -81
- package/{contentThunks-7URM43ET.js → contentThunks-GSMUNWBA.js} +20 -20
- package/{cooldownCommands-JEEV75B7.js → cooldownCommands-PT5L4LNB.js} +3 -3
- package/{createAgentAutomationAction-GGEXIKMC.js → createAgentAutomationAction-RMADR4LG.js} +20 -20
- package/{createDialogAction-IXXEMFRQ.js → createDialogAction-CM5CBQVH.js} +21 -21
- package/{createPageAction-IXIVLIOO.js → createPageAction-JMGVMCTH.js} +21 -21
- package/{db-J5KE7XRI.js → db-VR74ADGC.js} +5 -1
- package/{dbSlice-IE4ADINL.js → dbSlice-Q637QR4L.js} +7 -7
- package/{deleteFile-ZCQESEEQ.js → deleteFile-TP6MKFUX.js} +10 -5
- package/{dialogCommands-RPBHOZB6.js → dialogCommands-ULWP5ASX.js} +35 -33
- package/{dialogNotifyCommand-ECKI5MMA.js → dialogNotifyCommand-JKYVSR6K.js} +7 -7
- package/{dialogSlice-5FQB2TNN.js → dialogSlice-ARQKXXTD.js} +18 -18
- package/{docCreateCommands-XJ2X57DW.js → docCreateCommands-ZJFHCZV4.js} +32 -30
- package/{docDeleteCommands-45WGFFEB.js → docDeleteCommands-LY5MF2BI.js} +33 -31
- package/{docReadCommands-LRRVDS46.js → docReadCommands-4X2DHCNZ.js} +32 -30
- package/{docStore-SUAVM24F.js → docStore-QWRVKIRI.js} +8 -8
- package/{docUpdateCommands-QUYX6BVR.js → docUpdateCommands-5TIT7DAJ.js} +32 -30
- package/{getPricing-FCHYVRJU.js → getPricing-5BLZRPTM.js} +3 -3
- package/{handleSendMessageAction-FDIWBQUB.js → handleSendMessageAction-TVR55KVT.js} +36 -36
- package/{hostCredentialCreate-CEXQHYT4.js → hostCredentialCreate-SIRXPUFR.js} +68 -67
- package/index.js +8 -8
- package/{localDialogRead-USDZXKIL.js → localDialogRead-BJJT3TF5.js} +1 -1
- package/{localRuntimeAdapter-O3JBRK6S.js → localRuntimeAdapter-VRB5EDDZ.js} +67 -66
- package/{machineCommands-I3YA7TNC.js → machineCommands-MG3BB6XM.js} +68 -67
- package/{machineWsRunDispatch-E5CIE2OJ.js → machineWsRunDispatch-3TOO3NCU.js} +68 -67
- package/{mcpLocalAuthorizeCommand-K5J2VMG6.js → mcpLocalAuthorizeCommand-LO7E4VQ5.js} +6 -6
- package/{memberThunks-T7EAZE6A.js → memberThunks-IGYRMEQC.js} +9 -9
- package/{models-EP7VG6N2.js → models-ZX2BYIMB.js} +2 -2
- package/package.json +1 -1
- package/{projectArchive-A7E65AZO.js → projectArchive-Q46BYZQ6.js} +21 -21
- package/{providerPresetApply-4H7YP5D7.js → providerPresetApply-NTJUINI6.js} +35 -16
- package/{providerRegistry-F3UPOTIY.js → providerRegistry-W45SLUV6.js} +5 -5
- package/{read-BRZHXUJ6.js → read-MPPXZHAO.js} +10 -5
- package/{readDocTool-N7RVFQEE.js → readDocTool-PKZ35PCR.js} +1 -1
- package/{readlineWorkspace-2O65NBFG.js → readlineWorkspace-RBH6PSE7.js} +613 -209
- package/{removeDialogAgentAction-GRT72HLK.js → removeDialogAgentAction-H6S7VLNA.js} +9 -9
- package/{runAgentClientLoop-NWCZIXCG.js → runAgentClientLoop-WZJ4HXOH.js} +44 -44
- package/{runtimeDoctorCommands-26HYHFTK.js → runtimeDoctorCommands-QGZSKNSE.js} +5 -5
- package/{secretCommands-XR72SHLK.js → secretCommands-BXAQEOES.js} +2 -2
- package/{setDialogExtraReferencesAction-CBG3X46B.js → setDialogExtraReferencesAction-CARUTAWS.js} +8 -8
- package/{setPrimaryDialogAgentAction-EWTDZOAX.js → setPrimaryDialogAgentAction-VRV56MLG.js} +9 -9
- package/{settingThunks-X4PT66J2.js → settingThunks-4FC4HXGN.js} +7 -7
- package/{spaceCommands-EVSNTGRS.js → spaceCommands-27Z5JAU3.js} +31 -29
- package/{streamAgentChatTurn-SYP3OEM5.js → streamAgentChatTurn-JKMBFM2O.js} +57 -53
- package/{switchDialogAgentAction-YHPZ7K6E.js → switchDialogAgentAction-O236K6HB.js} +7 -7
- package/{tableCommands-44GC4N6J.js → tableCommands-C3P2HHKK.js} +2 -2
- package/{tools-2AO2SK4L.js → tools-4RFLNHUW.js} +37 -37
- package/{tuiRestart-HBQDF4AE.js → tuiRestart-GF4DGAAN.js} +7 -7
- package/{tuiSummaryLlmCaller-Q2PNR63K.js → tuiSummaryLlmCaller-HROLGN4F.js} +12 -12
- package/{updateCommands-6SI7NWVC.js → updateCommands-BZ4YDHNM.js} +3 -3
- package/{updateDialogTitleAction-MWVMBIPZ.js → updateDialogTitleAction-F3ONQM3N.js} +20 -20
- package/{usageCommand-D44AOTMH.js → usageCommand-XVJ7ZUTM.js} +1 -1
- package/{usageRebuildCommand-IRIMKDI5.js → usageRebuildCommand-NK6S3D4J.js} +2 -2
- package/{windowsSelfUpdate-BJIJKKIS.js → windowsSelfUpdate-4BAXX7C3.js} +2 -2
- package/{workloadLifecycle-ZCSQCHG3.js → workloadLifecycle-DYX5ZMAT.js} +2 -2
- package/chunk-FGHEF6WI.js +0 -34
- package/{chunk-ANUP75N2.js → chunk-2E4BYAUE.js} +0 -0
- package/{chunk-YHNUDTU4.js → chunk-VYRTLHIT.js} +3 -3
- package/{dialogUsageCommand-TBIA2QAF.js → dialogUsageCommand-IHAXS7DW.js} +3 -3
|
@@ -0,0 +1,594 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveObservedSpeed
|
|
3
|
+
} from "./chunk-AMWMV56B.js";
|
|
4
|
+
import {
|
|
5
|
+
LIST_AGENTS_PAGE_BUDGET,
|
|
6
|
+
sanitizeToolOutputText,
|
|
7
|
+
scrubSecrets
|
|
8
|
+
} from "./chunk-JX2IG37T.js";
|
|
9
|
+
import {
|
|
10
|
+
createKey,
|
|
11
|
+
createTokenKey
|
|
12
|
+
} from "./chunk-SYTHYBMI.js";
|
|
13
|
+
import {
|
|
14
|
+
REASONING_EFFORT_OPTIONS,
|
|
15
|
+
resolveModelReasoningCapability
|
|
16
|
+
} from "./chunk-OKH74FML.js";
|
|
17
|
+
|
|
18
|
+
// packages/ai/agent/speedSampleCache.ts
|
|
19
|
+
var SPEED_SAMPLE_DISK_CACHE_TTL_MS = 10 * 6e4;
|
|
20
|
+
var SPEED_SAMPLE_SCAN_BUDGET_MS = 2500;
|
|
21
|
+
var SPEED_SAMPLE_CACHE_VERSION = 4;
|
|
22
|
+
var isFiniteNumber = (value) => typeof value === "number" && Number.isFinite(value);
|
|
23
|
+
var sanitizeSample = (value) => {
|
|
24
|
+
if (!value || typeof value !== "object") return null;
|
|
25
|
+
const sample = value;
|
|
26
|
+
const clean = {};
|
|
27
|
+
if (isFiniteNumber(sample.firstOutputMs)) clean.firstOutputMs = sample.firstOutputMs;
|
|
28
|
+
if (isFiniteNumber(sample.callDurationMs)) clean.callDurationMs = sample.callDurationMs;
|
|
29
|
+
if (isFiniteNumber(sample.output_tokens)) clean.output_tokens = sample.output_tokens;
|
|
30
|
+
if (isFiniteNumber(sample.t)) clean.t = sample.t;
|
|
31
|
+
return clean.firstOutputMs === void 0 && clean.callDurationMs === void 0 ? null : clean;
|
|
32
|
+
};
|
|
33
|
+
var SPEED_SAMPLE_STALE_SNAPSHOT_MAX_MS = 7 * 24 * 60 * 6e4;
|
|
34
|
+
async function parseCacheFile(cachePath, userId) {
|
|
35
|
+
try {
|
|
36
|
+
const fs = await import("node:fs/promises");
|
|
37
|
+
const raw = await fs.readFile(cachePath, "utf8");
|
|
38
|
+
const parsed = JSON.parse(raw);
|
|
39
|
+
if (!parsed || typeof parsed !== "object") return null;
|
|
40
|
+
const version = parsed.version;
|
|
41
|
+
if (version !== SPEED_SAMPLE_CACHE_VERSION) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
if (parsed.userId !== userId) return null;
|
|
45
|
+
if (!isFiniteNumber(parsed.at)) return null;
|
|
46
|
+
const source = parsed.samples;
|
|
47
|
+
if (!source || typeof source !== "object") return null;
|
|
48
|
+
const samples = /* @__PURE__ */ new Map();
|
|
49
|
+
for (const [model, list] of Object.entries(source)) {
|
|
50
|
+
if (!model || !Array.isArray(list)) continue;
|
|
51
|
+
const cleaned = [];
|
|
52
|
+
for (const entry of list) {
|
|
53
|
+
const sample = sanitizeSample(entry);
|
|
54
|
+
if (sample) cleaned.push(sample);
|
|
55
|
+
}
|
|
56
|
+
samples.set(model, cleaned);
|
|
57
|
+
}
|
|
58
|
+
const complete = parsed.complete === true;
|
|
59
|
+
const cursor = typeof parsed.cursor === "string" && parsed.cursor.length > 0 ? parsed.cursor : void 0;
|
|
60
|
+
return { samples, at: parsed.at, complete, cursor: complete ? void 0 : cursor };
|
|
61
|
+
} catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function readSpeedSamplesSnapshot(cachePath, options) {
|
|
66
|
+
const maxAgeMs = isFiniteNumber(options.maxAgeMs) ? options.maxAgeMs : SPEED_SAMPLE_STALE_SNAPSHOT_MAX_MS;
|
|
67
|
+
const parsed = await parseCacheFile(cachePath, options.userId);
|
|
68
|
+
if (!parsed || !parsed.complete) return null;
|
|
69
|
+
const age = options.now - parsed.at;
|
|
70
|
+
if (age < 0 || age >= maxAgeMs) return null;
|
|
71
|
+
return { samples: parsed.samples, ageMs: age };
|
|
72
|
+
}
|
|
73
|
+
async function readSpeedSamplesProgress(cachePath, userId) {
|
|
74
|
+
const parsed = await parseCacheFile(cachePath, userId);
|
|
75
|
+
if (!parsed) return null;
|
|
76
|
+
return {
|
|
77
|
+
samples: parsed.samples,
|
|
78
|
+
at: parsed.at,
|
|
79
|
+
complete: parsed.complete,
|
|
80
|
+
...parsed.cursor === void 0 ? {} : { cursor: parsed.cursor }
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function resolveSpeedSamplesProgressPath(cachePath) {
|
|
84
|
+
return `${cachePath}.progress`;
|
|
85
|
+
}
|
|
86
|
+
async function writeSpeedSamplesCache(cachePath, payload) {
|
|
87
|
+
try {
|
|
88
|
+
const fs = await import("node:fs/promises");
|
|
89
|
+
const path = await import("node:path");
|
|
90
|
+
await fs.mkdir(path.dirname(cachePath), { recursive: true });
|
|
91
|
+
const tmpPath = `${cachePath}.tmp-${process.pid}-${Math.random().toString(36).slice(2, 8)}`;
|
|
92
|
+
await fs.writeFile(tmpPath, JSON.stringify(payload), "utf8");
|
|
93
|
+
await fs.rename(tmpPath, cachePath);
|
|
94
|
+
} catch {
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// packages/ai/agent/candidateSpeedContext.ts
|
|
99
|
+
var OBSERVED_SPEED_WINDOW = 50;
|
|
100
|
+
var MIN_OBSERVED_FIRST_OUTPUT_SAMPLES = 5;
|
|
101
|
+
var SPEED_SAMPLES_CACHE_TTL_MS = 5 * 6e4;
|
|
102
|
+
var SPEED_SAMPLES_CACHE_MAX_ENTRIES = 500;
|
|
103
|
+
function normalizeSpeedModelName(raw) {
|
|
104
|
+
const name = raw.trim().toLowerCase();
|
|
105
|
+
const slash = name.lastIndexOf("/");
|
|
106
|
+
return slash === -1 ? name : name.slice(slash + 1);
|
|
107
|
+
}
|
|
108
|
+
var isFiniteNumber2 = (value) => typeof value === "number" && Number.isFinite(value);
|
|
109
|
+
var REASONING_EFFORT_SUFFIXES = ["minimal", "low", "medium", "high", "xhigh"];
|
|
110
|
+
var REASONING_EFFORT_SUFFIX_RE = new RegExp(`-(?:${REASONING_EFFORT_SUFFIXES.join("|")})$`);
|
|
111
|
+
function stripReasoningEffortSuffix(model) {
|
|
112
|
+
const base = model.replace(REASONING_EFFORT_SUFFIX_RE, "");
|
|
113
|
+
return base && base !== model ? base : null;
|
|
114
|
+
}
|
|
115
|
+
function resolveOneBare(model, samplesByModel) {
|
|
116
|
+
const observed = resolveObservedSpeed(samplesByModel.get(model) ?? [], {
|
|
117
|
+
limit: OBSERVED_SPEED_WINDOW
|
|
118
|
+
});
|
|
119
|
+
if (observed.firstOutputSampleCount >= MIN_OBSERVED_FIRST_OUTPUT_SAMPLES && observed.medianFirstOutputMs !== void 0) {
|
|
120
|
+
return {
|
|
121
|
+
source: "observed",
|
|
122
|
+
firstOutputMs: observed.medianFirstOutputMs,
|
|
123
|
+
...observed.medianOutputTokensPerSecond !== void 0 ? { outputTps: observed.medianOutputTokensPerSecond } : {},
|
|
124
|
+
firstOutputSamples: observed.firstOutputSampleCount,
|
|
125
|
+
tpsSamples: observed.throughputSampleCount
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
function resolveOne(model, samplesByModel) {
|
|
131
|
+
const direct = resolveOneBare(model, samplesByModel);
|
|
132
|
+
if (direct) return { model, ...direct };
|
|
133
|
+
const base = stripReasoningEffortSuffix(model);
|
|
134
|
+
if (!base) return null;
|
|
135
|
+
const stripped = resolveOneBare(base, samplesByModel);
|
|
136
|
+
return stripped ? { model, ...stripped } : null;
|
|
137
|
+
}
|
|
138
|
+
function resolveCandidateSpeedFacts(models, samplesByModel) {
|
|
139
|
+
const unique = [
|
|
140
|
+
...new Set(
|
|
141
|
+
models.filter((model) => typeof model === "string").map(normalizeSpeedModelName).filter(Boolean)
|
|
142
|
+
)
|
|
143
|
+
];
|
|
144
|
+
return unique.map((model) => resolveOne(model, samplesByModel)).filter((fact) => fact !== null);
|
|
145
|
+
}
|
|
146
|
+
var formatSeconds = (ms) => `${(ms / 1e3).toFixed(1)}s`;
|
|
147
|
+
var formatTps = (tps) => String(Math.round(tps));
|
|
148
|
+
var SPEED_CONTEXT_HEADER = "speed (observed=\u672C\u7528\u6237\u5B9E\u6D4B\u8C03\u7528\u4E2D\u4F4D\u6570, firstOutput \u542B\u63A8\u7406\u8F93\u51FA; tps=generation\uFF08\u4E0D\u542B\u7AEF\u5230\u7AEF\u53E3\u5F84\uFF09, tps=n/a \u8868\u793A\u65E0\u53EF\u4FE1\u541E\u5410\u6837\u672C\u3002\u672A\u5217\u51FA\u7684 model \u8868\u793A\u6CA1\u6709\u5B9E\u6D4B\u6837\u672C\uFF0C\u4E0D\u4EE3\u8868\u6162):";
|
|
149
|
+
function formatSnapshotAge(ageMs) {
|
|
150
|
+
const minutes = Math.floor(ageMs / 6e4);
|
|
151
|
+
if (minutes < 1) return "<1min";
|
|
152
|
+
if (minutes < 60) return `${minutes}min`;
|
|
153
|
+
const hours = Math.floor(minutes / 60);
|
|
154
|
+
if (hours < 24) return `${hours}h`;
|
|
155
|
+
return `${Math.floor(hours / 24)}d`;
|
|
156
|
+
}
|
|
157
|
+
function formatCandidateSpeedFacts(facts, options = {}) {
|
|
158
|
+
if (facts.length === 0) return null;
|
|
159
|
+
const lines = facts.map((fact) => {
|
|
160
|
+
const tps = fact.outputTps !== void 0 ? formatTps(fact.outputTps) : "n/a";
|
|
161
|
+
return ` ${fact.model}: firstOutput=${formatSeconds(fact.firstOutputMs ?? 0)} tps=${tps} [observed n=${fact.firstOutputSamples ?? 0} tpsN=${fact.tpsSamples ?? 0}]`;
|
|
162
|
+
});
|
|
163
|
+
const age = options.snapshotAgeMs;
|
|
164
|
+
const note = typeof age === "number" && age > 0 ? ` (snapshot=${formatSnapshotAge(age)}\u524D\u91C7\u96C6\u7684\u5B8C\u6574\u7A97\u53E3, \u975E\u672C\u6B21\u5B9E\u65F6\u626B\u63CF)` : "";
|
|
165
|
+
return `${SPEED_CONTEXT_HEADER}${note}
|
|
166
|
+
${lines.join("\n")}`;
|
|
167
|
+
}
|
|
168
|
+
function buildCandidateSpeedContext(models, samplesByModel, options = {}) {
|
|
169
|
+
return formatCandidateSpeedFacts(resolveCandidateSpeedFacts(models, samplesByModel), options);
|
|
170
|
+
}
|
|
171
|
+
var SPEED_SAMPLE_PAGE_SIZE = 2e3;
|
|
172
|
+
var DISPATCH_ENTRY_PATH = "agent-run";
|
|
173
|
+
var eventTime = (value) => {
|
|
174
|
+
if (isFiniteNumber2(value.timestamp)) return value.timestamp;
|
|
175
|
+
if (isFiniteNumber2(value.createdAt)) return value.createdAt;
|
|
176
|
+
return 0;
|
|
177
|
+
};
|
|
178
|
+
function collectSample(collected, value) {
|
|
179
|
+
if (typeof value.model !== "string") return;
|
|
180
|
+
if (!isFiniteNumber2(value.firstOutputMs) && !isFiniteNumber2(value.callDurationMs)) return;
|
|
181
|
+
const model = normalizeSpeedModelName(value.model);
|
|
182
|
+
if (!model) return;
|
|
183
|
+
const list = collected.get(model) ?? [];
|
|
184
|
+
list.push({
|
|
185
|
+
t: eventTime(value),
|
|
186
|
+
firstOutputMs: value.firstOutputMs,
|
|
187
|
+
callDurationMs: value.callDurationMs,
|
|
188
|
+
output_tokens: value.output_tokens
|
|
189
|
+
});
|
|
190
|
+
collected.set(model, list);
|
|
191
|
+
}
|
|
192
|
+
function finalizeSamples(collected, keepTime = false) {
|
|
193
|
+
const result = /* @__PURE__ */ new Map();
|
|
194
|
+
for (const [model, list] of collected) {
|
|
195
|
+
list.sort((a, b) => b.t - a.t);
|
|
196
|
+
const window = list.slice(0, OBSERVED_SPEED_WINDOW);
|
|
197
|
+
result.set(
|
|
198
|
+
model,
|
|
199
|
+
keepTime ? window : window.map(({ t: _t, ...sample }) => sample)
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
return result;
|
|
203
|
+
}
|
|
204
|
+
async function collectRecentSpeedSamples(db, userId, options = {}) {
|
|
205
|
+
const pageSize = isFiniteNumber2(options.pageSize) && options.pageSize > 0 ? Math.floor(options.pageSize) : SPEED_SAMPLE_PAGE_SIZE;
|
|
206
|
+
const budgetMs = isFiniteNumber2(options.budgetMs) ? options.budgetMs : Number.POSITIVE_INFINITY;
|
|
207
|
+
const { start, end } = createTokenKey.rangeOfUser(userId);
|
|
208
|
+
const failedPrefix = createKey("token", userId, "failed-call", "");
|
|
209
|
+
const dispatchRunCache = /* @__PURE__ */ new Map();
|
|
210
|
+
const isDispatchSampleRecord = async (record, resolver, cache) => {
|
|
211
|
+
if (record.entry_path !== DISPATCH_ENTRY_PATH && record.entry_path !== "cli-local") return false;
|
|
212
|
+
const runId = typeof record.dialogId === "string" ? record.dialogId.trim() : "";
|
|
213
|
+
if (!runId) return false;
|
|
214
|
+
const cacheKey = `${record.entry_path}:${runId}`;
|
|
215
|
+
const cached = cache.get(cacheKey);
|
|
216
|
+
if (cached !== void 0) return cached;
|
|
217
|
+
let dispatch = false;
|
|
218
|
+
if (resolver) {
|
|
219
|
+
try {
|
|
220
|
+
dispatch = await resolver(runId, record.entry_path) === true;
|
|
221
|
+
} catch {
|
|
222
|
+
dispatch = false;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
cache.set(cacheKey, dispatch);
|
|
226
|
+
return dispatch;
|
|
227
|
+
};
|
|
228
|
+
const collected = /* @__PURE__ */ new Map();
|
|
229
|
+
const startedAt = Date.now();
|
|
230
|
+
let lastKey = options.startAfter;
|
|
231
|
+
let budgetExhausted = false;
|
|
232
|
+
let scanned = 0;
|
|
233
|
+
while (true) {
|
|
234
|
+
if (Date.now() - startedAt >= budgetMs) {
|
|
235
|
+
budgetExhausted = true;
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
const pageOptions = {
|
|
239
|
+
...lastKey === void 0 ? { gte: start } : { gt: lastKey },
|
|
240
|
+
lte: end,
|
|
241
|
+
limit: pageSize
|
|
242
|
+
};
|
|
243
|
+
let accepted = 0;
|
|
244
|
+
let newestKey = lastKey;
|
|
245
|
+
for await (const [key, raw] of db.iterator(pageOptions)) {
|
|
246
|
+
if (typeof key !== "string") continue;
|
|
247
|
+
if (lastKey !== void 0 && key <= lastKey) continue;
|
|
248
|
+
accepted += 1;
|
|
249
|
+
scanned += 1;
|
|
250
|
+
newestKey = key;
|
|
251
|
+
if (key.startsWith(failedPrefix)) continue;
|
|
252
|
+
if (!raw || typeof raw !== "object") continue;
|
|
253
|
+
const record = raw;
|
|
254
|
+
const resolver = options.isDispatchRun ?? db.isDispatchRun;
|
|
255
|
+
if (!await isDispatchSampleRecord(
|
|
256
|
+
record,
|
|
257
|
+
resolver ? (runId, entryPath) => resolver.call(db, runId, entryPath) : void 0,
|
|
258
|
+
dispatchRunCache
|
|
259
|
+
))
|
|
260
|
+
continue;
|
|
261
|
+
collectSample(collected, record);
|
|
262
|
+
}
|
|
263
|
+
if (accepted === 0 || accepted < pageSize) break;
|
|
264
|
+
lastKey = newestKey;
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
samples: finalizeSamples(collected, options.keepTime === true),
|
|
268
|
+
budgetExhausted,
|
|
269
|
+
scanned,
|
|
270
|
+
...budgetExhausted && lastKey !== void 0 ? { nextCursor: lastKey } : {}
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
function mergeNewestSamples(into, from) {
|
|
274
|
+
for (const [model, list] of from) {
|
|
275
|
+
const merged = [...into.get(model) ?? [], ...list];
|
|
276
|
+
merged.sort(
|
|
277
|
+
(a, b) => (b.t ?? 0) - (a.t ?? 0)
|
|
278
|
+
);
|
|
279
|
+
into.set(model, merged.slice(0, OBSERVED_SPEED_WINDOW));
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
async function loadSpeedSamplesWithDiskCache(db, userId, now, cache) {
|
|
283
|
+
try {
|
|
284
|
+
const ttlMs = isFiniteNumber2(cache.ttlMs) ? cache.ttlMs : SPEED_SAMPLE_DISK_CACHE_TTL_MS;
|
|
285
|
+
const snapshot = await readSpeedSamplesSnapshot(cache.cachePath, { userId, now });
|
|
286
|
+
if (snapshot && snapshot.ageMs < ttlMs) return { samples: snapshot.samples };
|
|
287
|
+
const progressPath = resolveSpeedSamplesProgressPath(cache.cachePath);
|
|
288
|
+
const progress = await readSpeedSamplesProgress(progressPath, userId);
|
|
289
|
+
const resumable = progress && !progress.complete && progress.cursor ? progress : void 0;
|
|
290
|
+
const collected = new Map(resumable?.samples ?? []);
|
|
291
|
+
let step;
|
|
292
|
+
try {
|
|
293
|
+
step = await collectRecentSpeedSamples(db, userId, {
|
|
294
|
+
pageSize: cache.pageSize,
|
|
295
|
+
budgetMs: isFiniteNumber2(cache.budgetMs) ? cache.budgetMs : SPEED_SAMPLE_SCAN_BUDGET_MS,
|
|
296
|
+
keepTime: true,
|
|
297
|
+
...resumable?.cursor ? { startAfter: resumable.cursor } : {}
|
|
298
|
+
});
|
|
299
|
+
} catch {
|
|
300
|
+
return snapshot ? { samples: snapshot.samples, snapshotAgeMs: snapshot.ageMs } : { samples: /* @__PURE__ */ new Map() };
|
|
301
|
+
}
|
|
302
|
+
if (!resumable && step.scanned === 0 && !step.budgetExhausted) {
|
|
303
|
+
return snapshot ? { samples: snapshot.samples, snapshotAgeMs: snapshot.ageMs } : { samples: /* @__PURE__ */ new Map() };
|
|
304
|
+
}
|
|
305
|
+
mergeNewestSamples(collected, step.samples);
|
|
306
|
+
if (!step.budgetExhausted) {
|
|
307
|
+
await writeSpeedSamplesCache(cache.cachePath, {
|
|
308
|
+
version: SPEED_SAMPLE_CACHE_VERSION,
|
|
309
|
+
userId,
|
|
310
|
+
at: now,
|
|
311
|
+
complete: true,
|
|
312
|
+
samples: Object.fromEntries(collected)
|
|
313
|
+
});
|
|
314
|
+
await writeSpeedSamplesCache(progressPath, {
|
|
315
|
+
version: SPEED_SAMPLE_CACHE_VERSION,
|
|
316
|
+
userId,
|
|
317
|
+
at: now,
|
|
318
|
+
complete: true,
|
|
319
|
+
samples: {}
|
|
320
|
+
});
|
|
321
|
+
return { samples: collected };
|
|
322
|
+
}
|
|
323
|
+
await writeSpeedSamplesCache(progressPath, {
|
|
324
|
+
version: SPEED_SAMPLE_CACHE_VERSION,
|
|
325
|
+
userId,
|
|
326
|
+
// Progress keeps the cycle's collection start so a later stale label stays honest.
|
|
327
|
+
at: resumable?.at ?? now,
|
|
328
|
+
complete: false,
|
|
329
|
+
samples: Object.fromEntries(collected),
|
|
330
|
+
...step.nextCursor ? { cursor: step.nextCursor } : {}
|
|
331
|
+
});
|
|
332
|
+
return snapshot ? { samples: snapshot.samples, snapshotAgeMs: snapshot.ageMs } : { samples: /* @__PURE__ */ new Map() };
|
|
333
|
+
} catch {
|
|
334
|
+
return { samples: /* @__PURE__ */ new Map() };
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
var samplesCache = /* @__PURE__ */ new Map();
|
|
338
|
+
function writeSamplesCache(userId, now, samples) {
|
|
339
|
+
for (const [key, entry] of samplesCache) {
|
|
340
|
+
if (now - entry.at >= SPEED_SAMPLES_CACHE_TTL_MS) samplesCache.delete(key);
|
|
341
|
+
}
|
|
342
|
+
samplesCache.delete(userId);
|
|
343
|
+
samplesCache.set(userId, { at: now, samples });
|
|
344
|
+
while (samplesCache.size > SPEED_SAMPLES_CACHE_MAX_ENTRIES) {
|
|
345
|
+
const oldest = samplesCache.keys().next().value;
|
|
346
|
+
if (oldest === void 0) break;
|
|
347
|
+
samplesCache.delete(oldest);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
var SPEED_SAMPLE_REFRESH_BUDGET_MS = 6e4;
|
|
351
|
+
var snapshotRefreshes = /* @__PURE__ */ new Map();
|
|
352
|
+
function startSpeedSnapshotRefresh(db, userId, now = Date.now()) {
|
|
353
|
+
const inFlight = snapshotRefreshes.get(userId);
|
|
354
|
+
if (inFlight) return inFlight;
|
|
355
|
+
const job = (async () => {
|
|
356
|
+
try {
|
|
357
|
+
const { samples, budgetExhausted } = await collectRecentSpeedSamples(db, userId, {
|
|
358
|
+
budgetMs: SPEED_SAMPLE_REFRESH_BUDGET_MS
|
|
359
|
+
});
|
|
360
|
+
if (!budgetExhausted) writeSamplesCache(userId, now, samples);
|
|
361
|
+
} catch {
|
|
362
|
+
}
|
|
363
|
+
})().finally(() => {
|
|
364
|
+
snapshotRefreshes.delete(userId);
|
|
365
|
+
});
|
|
366
|
+
snapshotRefreshes.set(userId, job);
|
|
367
|
+
return job;
|
|
368
|
+
}
|
|
369
|
+
async function loadCachedSpeedSamples(db, userId, now) {
|
|
370
|
+
const hit = samplesCache.get(userId);
|
|
371
|
+
if (hit) {
|
|
372
|
+
const age = now - hit.at;
|
|
373
|
+
if (age >= 0 && age < SPEED_SAMPLE_STALE_SNAPSHOT_MAX_MS) {
|
|
374
|
+
if (age >= SPEED_SAMPLES_CACHE_TTL_MS) void startSpeedSnapshotRefresh(db, userId);
|
|
375
|
+
return age >= SPEED_SAMPLES_CACHE_TTL_MS ? { samples: hit.samples, snapshotAgeMs: age } : { samples: hit.samples };
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
void startSpeedSnapshotRefresh(db, userId);
|
|
379
|
+
return { samples: /* @__PURE__ */ new Map() };
|
|
380
|
+
}
|
|
381
|
+
async function injectSpeedContextIntoListAgentsResult(result, options = {}) {
|
|
382
|
+
try {
|
|
383
|
+
let parsed;
|
|
384
|
+
try {
|
|
385
|
+
parsed = JSON.parse(result);
|
|
386
|
+
} catch {
|
|
387
|
+
return result;
|
|
388
|
+
}
|
|
389
|
+
if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.agents)) return result;
|
|
390
|
+
const models = parsed.agents.map((agent) => agent?.model).filter((model) => typeof model === "string");
|
|
391
|
+
if (models.length === 0 && !options.compactPage) return result;
|
|
392
|
+
const now = options.now ?? Date.now();
|
|
393
|
+
let samples = /* @__PURE__ */ new Map();
|
|
394
|
+
let snapshotAgeMs;
|
|
395
|
+
const userId = typeof options.userId === "string" ? options.userId.trim() : "";
|
|
396
|
+
if (options.db && userId) {
|
|
397
|
+
try {
|
|
398
|
+
const loaded = options.diskCache ? await loadSpeedSamplesWithDiskCache(options.db, userId, now, options.diskCache) : await loadCachedSpeedSamples(options.db, userId, now);
|
|
399
|
+
samples = loaded.samples;
|
|
400
|
+
snapshotAgeMs = loaded.snapshotAgeMs;
|
|
401
|
+
} catch {
|
|
402
|
+
samples = /* @__PURE__ */ new Map();
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
if (options.compactPage) {
|
|
406
|
+
return await serializeCompactAgentPage(parsed, samples, snapshotAgeMs, options);
|
|
407
|
+
}
|
|
408
|
+
const speedContext = buildCandidateSpeedContext(models, samples, { snapshotAgeMs });
|
|
409
|
+
return speedContext ? JSON.stringify({ ...parsed, speedContext }) : result;
|
|
410
|
+
} catch {
|
|
411
|
+
return options.compactPage ? JSON.stringify({ success: false, error: "LIST_AGENTS_PAGE_SERIALIZATION_FAILED" }) : result;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
async function serializeCompactAgentPage(parsed, samples, snapshotAgeMs, options) {
|
|
415
|
+
const maxChars = LIST_AGENTS_PAGE_BUDGET;
|
|
416
|
+
const maxBytes = LIST_AGENTS_PAGE_BUDGET;
|
|
417
|
+
const fits = (page) => page.length <= maxChars && new TextEncoder().encode(page).length <= maxBytes;
|
|
418
|
+
const offset = typeof parsed.offset === "number" ? parsed.offset : 0;
|
|
419
|
+
const candidates = parsed.agents;
|
|
420
|
+
const availableCount = typeof parsed.availableCount === "number" ? parsed.availableCount : parsed.total;
|
|
421
|
+
const groups = Array.isArray(parsed.credentialGroups) ? parsed.credentialGroups : [];
|
|
422
|
+
if (options.fragmentOffset !== void 0) {
|
|
423
|
+
const fragmentOffset = Number(options.fragmentOffset);
|
|
424
|
+
const agentKey2 = candidates[0]?.agentKey;
|
|
425
|
+
if (typeof options.fragmentOffset !== "number" && (typeof options.fragmentOffset !== "string" || !/^\d+$/.test(options.fragmentOffset)) || !Number.isSafeInteger(fragmentOffset) || fragmentOffset < 0 || typeof agentKey2 !== "string" || agentKey2 !== options.fragmentAgentKey) {
|
|
426
|
+
return JSON.stringify({ success: false, error: "LIST_AGENTS_FRAGMENT_INVALID", offset });
|
|
427
|
+
}
|
|
428
|
+
const agent = candidates[0];
|
|
429
|
+
const speedContext = buildCandidateSpeedContext(typeof agent.model === "string" ? [agent.model] : [], samples, { snapshotAgeMs });
|
|
430
|
+
const payload = { agent, credentialGroups: groups.filter((group) => group.credentialGroup === agent.credentialGroup) };
|
|
431
|
+
let keyCollision = false;
|
|
432
|
+
const cleanText = (value) => scrubSecrets(sanitizeToolOutputText(value)).cleaned;
|
|
433
|
+
const sanitize = (value) => {
|
|
434
|
+
if (typeof value === "string") return cleanText(value);
|
|
435
|
+
if (Array.isArray(value)) return value.map(sanitize);
|
|
436
|
+
if (value && typeof value === "object") {
|
|
437
|
+
const entries = [];
|
|
438
|
+
const keys = /* @__PURE__ */ new Set();
|
|
439
|
+
for (const [key, item] of Object.entries(value)) {
|
|
440
|
+
const cleanedKey = cleanText(key);
|
|
441
|
+
if (keys.has(cleanedKey)) keyCollision = true;
|
|
442
|
+
keys.add(cleanedKey);
|
|
443
|
+
entries.push([cleanedKey, sanitize(item)]);
|
|
444
|
+
}
|
|
445
|
+
return Object.fromEntries(entries);
|
|
446
|
+
}
|
|
447
|
+
return value;
|
|
448
|
+
};
|
|
449
|
+
const safePayload = sanitize(payload);
|
|
450
|
+
if (keyCollision) return JSON.stringify({ success: false, error: "LIST_AGENTS_SANITIZED_KEY_COLLISION", offset });
|
|
451
|
+
const serialized = JSON.stringify(safePayload);
|
|
452
|
+
const bytes = new TextEncoder().encode(serialized);
|
|
453
|
+
const hash = await globalThis.crypto.subtle.digest("SHA-256", bytes);
|
|
454
|
+
const digest = Array.from(new Uint8Array(hash), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
455
|
+
if (fragmentOffset > 0 && !options.fragmentDigest || options.fragmentDigest && options.fragmentDigest !== digest) {
|
|
456
|
+
return JSON.stringify({ success: false, error: "LIST_AGENTS_FRAGMENT_CHANGED", offset });
|
|
457
|
+
}
|
|
458
|
+
if (fragmentOffset >= serialized.length) return JSON.stringify({ success: false, error: "LIST_AGENTS_FRAGMENT_INVALID", offset });
|
|
459
|
+
if (fragmentOffset > 0 && /[\uDC00-\uDFFF]/.test(serialized[fragmentOffset]) && /[\uD800-\uDBFF]/.test(serialized[fragmentOffset - 1])) return JSON.stringify({ success: false, error: "LIST_AGENTS_FRAGMENT_INVALID", offset });
|
|
460
|
+
let end = Math.min(serialized.length, fragmentOffset + 3e3);
|
|
461
|
+
if (end < serialized.length && /[\uD800-\uDBFF]/.test(serialized[end - 1]) && /[\uDC00-\uDFFF]/.test(serialized[end])) end--;
|
|
462
|
+
const fragment = serialized.slice(fragmentOffset, end);
|
|
463
|
+
const result = JSON.stringify({ success: true, agentKey: agentKey2, offset, digest, fragment, fragmentOffset, nextFragmentOffset: end, hasMoreFragments: end < serialized.length, nextOffset: offset + 1, ...speedContext ? { speedContext: cleanText(speedContext) } : {} });
|
|
464
|
+
return fits(result) ? result : JSON.stringify({ success: false, error: "LIST_AGENTS_FRAGMENT_METADATA_TOO_LARGE", offset });
|
|
465
|
+
}
|
|
466
|
+
const makePage = (count) => {
|
|
467
|
+
const agents = candidates.slice(0, count);
|
|
468
|
+
const groupKeys = new Set(agents.map((agent) => agent.credentialGroup).filter(Boolean));
|
|
469
|
+
const speedContext = buildCandidateSpeedContext(agents.map((agent) => agent.model).filter((model) => typeof model === "string"), samples, { snapshotAgeMs });
|
|
470
|
+
const nextOffset = offset + count;
|
|
471
|
+
const hasMore = nextOffset < availableCount;
|
|
472
|
+
return JSON.stringify({
|
|
473
|
+
...parsed,
|
|
474
|
+
offset,
|
|
475
|
+
agents,
|
|
476
|
+
credentialGroups: groups.filter((group) => groupKeys.has(group.credentialGroup)),
|
|
477
|
+
hasMore,
|
|
478
|
+
...hasMore ? { nextOffset } : {},
|
|
479
|
+
...speedContext ? { speedContext } : {}
|
|
480
|
+
});
|
|
481
|
+
};
|
|
482
|
+
if (!candidates.length) {
|
|
483
|
+
const empty = makePage(0);
|
|
484
|
+
if (fits(empty)) return empty;
|
|
485
|
+
} else {
|
|
486
|
+
let best;
|
|
487
|
+
for (let count = 1; count <= candidates.length; count++) {
|
|
488
|
+
const page = makePage(count);
|
|
489
|
+
if (!fits(page)) break;
|
|
490
|
+
best = page;
|
|
491
|
+
}
|
|
492
|
+
if (best) return best;
|
|
493
|
+
}
|
|
494
|
+
const agentKey = typeof candidates[0]?.agentKey === "string" ? candidates[0].agentKey : void 0;
|
|
495
|
+
const error = {
|
|
496
|
+
success: false,
|
|
497
|
+
error: candidates.length ? "LIST_AGENTS_CANDIDATE_TOO_LARGE" : "LIST_AGENTS_PAGE_METADATA_TOO_LARGE",
|
|
498
|
+
offset,
|
|
499
|
+
...agentKey ? { agentKey, recovery: {
|
|
500
|
+
tool: "listAgents",
|
|
501
|
+
arguments: { compact: true, offset, fragmentOffset: 0, fragmentAgentKey: agentKey },
|
|
502
|
+
note: "Repeat with the same filters and returned digest and nextFragmentOffset; concatenate fragments and parse JSON before continuing at nextOffset."
|
|
503
|
+
} } : {},
|
|
504
|
+
...candidates.length ? { nextOffset: offset + 1, truncated: parsed.truncated === true, poolComplete: parsed.planningRecommendation?.poolComplete === true, hasMore: offset + 1 < availableCount } : {}
|
|
505
|
+
};
|
|
506
|
+
const encoded = JSON.stringify(error);
|
|
507
|
+
return fits(encoded) ? encoded : JSON.stringify({ success: false, error: "LIST_AGENTS_RECOVERY_ID_TOO_LARGE", offset });
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// packages/ai/agent/defaultReasoningEffort.ts
|
|
511
|
+
var defaults = {
|
|
512
|
+
"gpt-6.2-sol": "medium",
|
|
513
|
+
"gpt-6.2-astra": "high",
|
|
514
|
+
"gpt-6.1-sol": "medium",
|
|
515
|
+
"gpt-6.1-terra": "medium",
|
|
516
|
+
"gpt-6-luna": "medium",
|
|
517
|
+
"gpt-6-astra": "high",
|
|
518
|
+
"claude-opus-5-5": "medium",
|
|
519
|
+
"claude-sonnet-5-5": "high",
|
|
520
|
+
"deepseek-flash": "high",
|
|
521
|
+
"deepseek-v4-flash": "high",
|
|
522
|
+
"deepseek-v4.1-flash": "high"
|
|
523
|
+
};
|
|
524
|
+
var deepseekChannels = /* @__PURE__ */ new Set(["opendesign", "ollama-cloud", "lithosai"]);
|
|
525
|
+
var providers = /* @__PURE__ */ new Set(["nolo", "openai", "openrouter", "anthropic", "deepseek", "commandcode", "opencode-go", "stepfun"]);
|
|
526
|
+
function resolveDefaultReasoningEffort(input) {
|
|
527
|
+
const provider = (input.provider ?? "").toLowerCase();
|
|
528
|
+
const model = (input.model ?? "").toLowerCase().split("/").pop() ?? "";
|
|
529
|
+
const isDeepseekFlash = ["deepseek-flash", "deepseek-v4-flash", "deepseek-v4.1-flash"].includes(model);
|
|
530
|
+
const effort = providers.has(provider) || deepseekChannels.has(provider) && isDeepseekFlash ? defaults[model] : void 0;
|
|
531
|
+
if (!effort) return input.fallback;
|
|
532
|
+
if (provider === "nolo" && model.startsWith("claude-") && input.model?.startsWith("anthropic/")) return effort;
|
|
533
|
+
if (provider === "anthropic" && model.startsWith("claude-")) return effort;
|
|
534
|
+
return resolveModelReasoningCapability(provider, input.model).efforts.includes(effort) ? effort : input.fallback;
|
|
535
|
+
}
|
|
536
|
+
function confirmedReasoningEfforts(provider, model) {
|
|
537
|
+
const capability = resolveModelReasoningCapability(provider, model);
|
|
538
|
+
if (capability.source === "provider-fallback") return void 0;
|
|
539
|
+
if (capability.efforts.length === 0) return void 0;
|
|
540
|
+
return capability.efforts;
|
|
541
|
+
}
|
|
542
|
+
var DISPATCH_EFFORT_PREFERENCES = {
|
|
543
|
+
easy: ["low", "minimal", "medium"],
|
|
544
|
+
normal: ["medium", "low", "high"],
|
|
545
|
+
complex: ["high", "medium"],
|
|
546
|
+
extreme: ["xhigh", "max", "high"]
|
|
547
|
+
};
|
|
548
|
+
var DISPATCH_DIFFICULTIES = /* @__PURE__ */ new Set(["easy", "normal", "complex", "extreme"]);
|
|
549
|
+
function normalizeDifficulty(difficulty) {
|
|
550
|
+
const normalized = (difficulty ?? "").trim().toLowerCase();
|
|
551
|
+
return DISPATCH_DIFFICULTIES.has(normalized) ? normalized : "normal";
|
|
552
|
+
}
|
|
553
|
+
function asValidAgentEffort(raw) {
|
|
554
|
+
const normalized = (raw ?? "").trim().toLowerCase();
|
|
555
|
+
return REASONING_EFFORT_OPTIONS.includes(normalized) ? normalized : void 0;
|
|
556
|
+
}
|
|
557
|
+
function hasReasoningEffortSuffix(model) {
|
|
558
|
+
const normalized = (model ?? "").trim().toLowerCase().split("/").pop() ?? "";
|
|
559
|
+
return REASONING_EFFORT_SUFFIXES.some((suffix) => normalized.endsWith(`-${suffix}`));
|
|
560
|
+
}
|
|
561
|
+
function resolveDispatchReasoningEffort(input) {
|
|
562
|
+
if (asValidAgentEffort(input.agentReasoningEffort)) return void 0;
|
|
563
|
+
if (hasReasoningEffortSuffix(input.model)) return void 0;
|
|
564
|
+
if (!(input.provider ?? "").trim() || !(input.model ?? "").trim()) return void 0;
|
|
565
|
+
const efforts = confirmedReasoningEfforts(input.provider, input.model);
|
|
566
|
+
if (!efforts) return void 0;
|
|
567
|
+
const preferences = DISPATCH_EFFORT_PREFERENCES[normalizeDifficulty(input.difficulty)];
|
|
568
|
+
return preferences.find((effort) => efforts.includes(effort));
|
|
569
|
+
}
|
|
570
|
+
function resolveEffectiveReasoningEffortOverride(input) {
|
|
571
|
+
const override = asValidAgentEffort(input.override);
|
|
572
|
+
if (!override) return void 0;
|
|
573
|
+
if (asValidAgentEffort(input.recordReasoningEffort)) return void 0;
|
|
574
|
+
if (hasReasoningEffortSuffix(input.model)) return void 0;
|
|
575
|
+
if (!(input.provider ?? "").trim() || !(input.model ?? "").trim()) return void 0;
|
|
576
|
+
const efforts = confirmedReasoningEfforts(input.provider, input.model);
|
|
577
|
+
return efforts?.includes(override) ? override : void 0;
|
|
578
|
+
}
|
|
579
|
+
function withReasoningEffortOverride(config, effort) {
|
|
580
|
+
if (!effort) return config;
|
|
581
|
+
return {
|
|
582
|
+
...config,
|
|
583
|
+
reasoning_effort: effort,
|
|
584
|
+
...config.rawRecord ? { rawRecord: { ...config.rawRecord, reasoning_effort: effort } } : {}
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
export {
|
|
589
|
+
injectSpeedContextIntoListAgentsResult,
|
|
590
|
+
resolveDefaultReasoningEffort,
|
|
591
|
+
resolveDispatchReasoningEffort,
|
|
592
|
+
resolveEffectiveReasoningEffortOverride,
|
|
593
|
+
withReasoningEffortOverride
|
|
594
|
+
};
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-5ZUL4CUO.js";
|
|
4
4
|
import {
|
|
5
5
|
getModelContextWindow
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-2FZVXOFX.js";
|
|
7
7
|
import {
|
|
8
8
|
isPageKey,
|
|
9
9
|
isTableMetaKey
|
|
@@ -23,6 +23,14 @@ import {
|
|
|
23
23
|
import {
|
|
24
24
|
asOptionalTrimmedString
|
|
25
25
|
} from "./chunk-G3SUCT4W.js";
|
|
26
|
+
import {
|
|
27
|
+
asTrimmedLowercaseString
|
|
28
|
+
} from "./chunk-QSJ3HFEF.js";
|
|
29
|
+
|
|
30
|
+
// packages/integrations/openai/responsesPromptLayout.ts
|
|
31
|
+
function isGpt62DeveloperPrefixModel(model) {
|
|
32
|
+
return /^gpt-6\.2-(astra|sol)$/.test(model);
|
|
33
|
+
}
|
|
26
34
|
|
|
27
35
|
// packages/agent-runtime/codexOAuthPure.ts
|
|
28
36
|
function isCodexOAuthAgent(agent) {
|
|
@@ -30,6 +38,9 @@ function isCodexOAuthAgent(agent) {
|
|
|
30
38
|
const ref = agent.apiKeyRef?.trim().toLowerCase();
|
|
31
39
|
return ref === "chatgpt";
|
|
32
40
|
}
|
|
41
|
+
function usesCodexDeveloperPrefix(agent, model) {
|
|
42
|
+
return !agent.customProviderUrl && isGpt62DeveloperPrefixModel(asTrimmedLowercaseString(model).replace(/^openai\//, ""));
|
|
43
|
+
}
|
|
33
44
|
|
|
34
45
|
// packages/agent-runtime/codexOAuthModelAliases.ts
|
|
35
46
|
var CODEX_OAUTH_MODEL_ALIASES = {
|
|
@@ -506,7 +517,9 @@ function resolveTruncatedReasoningTailLog(reason, reasoning_content) {
|
|
|
506
517
|
}
|
|
507
518
|
|
|
508
519
|
export {
|
|
520
|
+
isGpt62DeveloperPrefixModel,
|
|
509
521
|
isCodexOAuthAgent,
|
|
522
|
+
usesCodexDeveloperPrefix,
|
|
510
523
|
resolveCodexOAuthEffectiveModel,
|
|
511
524
|
CODEX_OAUTH_CATALOG_TTL_MS,
|
|
512
525
|
CODEX_OAUTH_CATALOG_RETRY_FLOOR_MS,
|