nolo-cli 0.251.0-alpha.1 → 0.252.0-alpha.1
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-D6G3B45S.js} +44 -44
- package/{action-WZTKEF5H.js → action-QQOQ2LP3.js} +3 -3
- package/{addContentAction-LBVAQUF7.js → addContentAction-MB22YIDV.js} +6 -6
- package/{addDialogAgentAction-6WAUSUSZ.js → addDialogAgentAction-KNTBVVGY.js} +5 -5
- package/{agentDeleteCommand-KEO3KDK3.js → agentDeleteCommand-YCWDGJSF.js} +66 -65
- package/{agentEmailCommands-RWJQQRNT.js → agentEmailCommands-DTWD5FWC.js} +66 -65
- package/{agentListCommands-L3TLPLNH.js → agentListCommands-JTOONLYL.js} +224 -37
- package/{agentMachineCommands-EZWWXWDH.js → agentMachineCommands-25X7OTLQ.js} +29 -27
- package/{agentProviderCommands-C5T7C5KZ.js → agentProviderCommands-QLTABYR7.js} +2 -2
- package/{agentRecordCommands-7W2CGHJJ.js → agentRecordCommands-SXE3WV2X.js} +65 -64
- package/{agentRunCommand-POL6B6BO.js → agentRunCommand-QSIED54S.js} +65 -64
- package/{agentRunControl-FKSXBUAF.js → agentRunControl-KNNDEEDI.js} +8 -6
- package/{agentRuntimeLocal-WSHWNIMF.js → agentRuntimeLocal-HVJJMB4W.js} +24 -23
- package/{agentSlice-3G2YLTA4.js → agentSlice-NBUJJVRI.js} +6 -6
- package/{appDeleteCommands-DZZQCVYH.js → appDeleteCommands-YU6TT6VN.js} +31 -29
- package/{appDeployCommands-NJJBVNH5.js → appDeployCommands-4DEIX7YP.js} +31 -29
- package/{appDeployStatusCommands-GBOAFEYG.js → appDeployStatusCommands-3VKS6GBQ.js} +31 -29
- package/{appGetCommands-GOOKYMKO.js → appGetCommands-22FNNROT.js} +31 -29
- package/{appListCommands-OBCGUG3S.js → appListCommands-FVGMLHVU.js} +31 -29
- package/{authCommand-77CRN332.js → authCommand-5DC3ES4Q.js} +12 -12
- package/{chromeOpsCommands-6RLEBBJJ.js → chromeOpsCommands-AA555ANS.js} +1 -1
- package/{chunk-MAA42MMV.js → chunk-2FZVXOFX.js} +4 -4
- package/chunk-2GAUJDA5.js +594 -0
- package/{chunk-ESN4WNWU.js → chunk-2JHGUL5K.js} +2 -2
- package/{chunk-222CJNC2.js → chunk-2LANL4B5.js} +3 -3
- package/{chunk-PKMDYRAM.js → chunk-2PB653F5.js} +171 -237
- package/{chunk-GMWZRXRM.js → chunk-3272HU62.js} +1 -1
- package/{chunk-3ZWJVKFB.js → chunk-3N3JPQBQ.js} +82 -38
- package/{chunk-LXKK7QFI.js → chunk-4HAOOY6G.js} +53 -23
- package/{chunk-ZQ6K57FJ.js → chunk-4YPH5KRA.js} +1 -1
- package/{chunk-T4V6C3J3.js → chunk-52M4RYVP.js} +1 -1
- package/{chunk-6UNJ6JGR.js → chunk-5IN2NBDX.js} +4 -4
- 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-N3SEV3CG.js → chunk-7ZOVFB2H.js} +79 -30
- package/{chunk-UR4ZMRV3.js → chunk-A5F6DYP2.js} +1 -1
- package/{chunk-FAFDIQJG.js → chunk-A6VIMCWI.js} +3 -3
- package/{chunk-SX6AWTNK.js → chunk-BZLGPM5B.js} +3 -3
- package/{chunk-LTVEOOZL.js → chunk-CIAV4WK2.js} +14 -1
- package/{chunk-IFJ6OTI6.js → chunk-CO2NXG2J.js} +32 -10
- 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-PLS2MJVW.js → chunk-DU3DJYVA.js} +4 -4
- package/{chunk-MTS5DCL2.js → chunk-EG3JTV7H.js} +2 -2
- package/{chunk-6ASGEP5D.js → chunk-EJQE5HB7.js} +1 -1
- package/{chunk-CD64YXRB.js → chunk-F6Q64KRV.js} +1 -1
- package/{chunk-L5HV76QT.js → chunk-FRC2DNTN.js} +1 -1
- package/{chunk-W3HSD32M.js → chunk-FXEPZKNJ.js} +2 -2
- package/{chunk-D35TOEMM.js → chunk-FZI2P64R.js} +137 -53
- package/{chunk-WWTSEBDF.js → chunk-GIXWVN2W.js} +1 -1
- package/{chunk-CUYFRVJF.js → chunk-GO7UC5VH.js} +5 -5
- package/{chunk-KZVRPCOR.js → chunk-GVH2IP2M.js} +4 -4
- package/{chunk-KGOBJAWC.js → chunk-GWS2X7TX.js} +206 -93
- package/{chunk-KHVTT4WW.js → chunk-HF4C5WIU.js} +81 -542
- package/{chunk-Q5KZ6F55.js → chunk-HMREADP6.js} +19 -17
- package/{chunk-X337N4D6.js → chunk-ITCOQAHS.js} +3 -3
- package/{chunk-BQ4CZEVZ.js → chunk-ITMBFT35.js} +1 -1
- package/chunk-IVK2KT3H.js +209 -0
- package/{chunk-IXAGRTAR.js → chunk-JAYPSNGR.js} +1 -1
- package/{chunk-LOXR4TQN.js → chunk-JF5QT3YY.js} +2 -2
- package/{chunk-QLGL43SI.js → chunk-JKALGWDL.js} +2 -2
- package/{chunk-PQ63BDV3.js → chunk-JPXACKSW.js} +9 -1
- package/{chunk-HS7MLR74.js → chunk-KZ4A7EIV.js} +3 -5
- package/{chunk-3KWJPTVP.js → chunk-LAQC5FAP.js} +4 -4
- package/{chunk-NTNX77FI.js → chunk-LNIA5JVX.js} +6 -6
- package/{chunk-QJTZ76CP.js → chunk-LS5KAVFQ.js} +1 -0
- package/{chunk-K26XPZRB.js → chunk-LVZVSLKO.js} +29 -9
- package/{chunk-ZSRR6HCH.js → chunk-N2ZAY2DK.js} +1 -1
- package/{chunk-MTM4LRVG.js → chunk-NNUIVAC2.js} +1 -1
- package/{chunk-HD5EKSLF.js → chunk-NPUHKEOB.js} +2 -2
- package/{chunk-OARYOLF3.js → chunk-O6LPLIRS.js} +11 -11
- 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-AS6L5KSD.js → chunk-P4R5KXU7.js} +2 -2
- package/{chunk-K5CIMK3R.js → chunk-P6HMEKLL.js} +114 -56
- package/{chunk-VTHWBTRE.js → chunk-PENRYZ4D.js} +1 -1
- package/{chunk-WZPG63Q4.js → chunk-PIVTQRX6.js} +43 -13
- package/{chunk-KJDN2YRH.js → chunk-QMKWSKWA.js} +4 -4
- package/{chunk-XC5RPSXK.js → chunk-QV32GSVO.js} +2 -2
- package/{chunk-XJSEST7D.js → chunk-SMCKJJXI.js} +2 -2
- package/{chunk-KRAPKTAS.js → chunk-SMZFWEMX.js} +1 -1
- package/{chunk-43VT5PLM.js → chunk-T4VVQHSE.js} +1 -1
- package/{chunk-W2N4OAKM.js → chunk-TDI7ARZO.js} +3 -3
- package/{chunk-TGKAUEV3.js → chunk-TDLZA6LJ.js} +13 -10
- package/{chunk-LMMRWGGJ.js → chunk-TTUIM3PJ.js} +2 -2
- package/{chunk-5IKKSJYX.js → chunk-TTWNTFTO.js} +35 -2
- package/{chunk-ZM5AZTQG.js → chunk-U7BP25PE.js} +18 -6
- package/{chunk-X3OZ655T.js → chunk-UI3Z3HDK.js} +1 -1
- package/{chunk-GX6DITLQ.js → chunk-UUCYUN6Y.js} +1 -1
- package/{chunk-U2OWDHDE.js → chunk-VH7AQEEF.js} +2 -2
- package/{chunk-ZKKJZBNO.js → chunk-WAOHK3NJ.js} +9 -9
- package/{chunk-2FK2KZSL.js → chunk-WLHUANWZ.js} +1 -1
- package/{chunk-JUYI2D7J.js → chunk-WNIBQBOR.js} +1 -1
- package/{chunk-SLUZ6FBJ.js → chunk-XBCADGK2.js} +1 -1
- package/{chunk-6XVPMGXK.js → chunk-YB5D2GK4.js} +9 -3
- package/{chunk-QJ5YDTEF.js → chunk-YQYYYATY.js} +42 -24
- package/{chunk-WQDTSK5U.js → chunk-ZMFA2TLE.js} +1 -1
- package/{chunk-CFDOIIOZ.js → chunk-ZMXO5G3E.js} +29 -23
- package/{chunk-A55E2OCP.js → chunk-ZNOXY73P.js} +632 -124
- package/{cliAgentConfigHelpers-N6LTB7UY.js → cliAgentConfigHelpers-FKBPFPKR.js} +6 -6
- package/{cliLocalAgentRecordReader-NFNGYOOW.js → cliLocalAgentRecordReader-DWU3LBO2.js} +28 -27
- package/{commandRegistry-OM5DU4DS.js → commandRegistry-7FVATZS2.js} +70 -70
- package/{contentThunks-7URM43ET.js → contentThunks-25XCB7VY.js} +18 -18
- package/{cooldownCommands-JEEV75B7.js → cooldownCommands-PT5L4LNB.js} +3 -3
- package/{createAgentAutomationAction-GGEXIKMC.js → createAgentAutomationAction-FC5RI2LW.js} +18 -18
- package/{createDialogAction-IXXEMFRQ.js → createDialogAction-IL3ISSQQ.js} +19 -19
- package/{createPageAction-IXIVLIOO.js → createPageAction-RVYBEYZV.js} +19 -19
- package/{db-J5KE7XRI.js → db-JMGVD4TB.js} +2 -1
- package/{dbSlice-IE4ADINL.js → dbSlice-WG3ZG6PZ.js} +5 -5
- package/{deleteFile-ZCQESEEQ.js → deleteFile-4TIG54YN.js} +3 -3
- package/{dialogCommands-RPBHOZB6.js → dialogCommands-VUJISJZF.js} +33 -31
- package/{dialogNotifyCommand-ECKI5MMA.js → dialogNotifyCommand-JKYVSR6K.js} +7 -7
- package/{dialogSlice-5FQB2TNN.js → dialogSlice-UMP55UAW.js} +16 -16
- package/{docCreateCommands-XJ2X57DW.js → docCreateCommands-S46F6GKP.js} +30 -28
- package/{docDeleteCommands-45WGFFEB.js → docDeleteCommands-LJG4NK6J.js} +31 -29
- package/{docReadCommands-LRRVDS46.js → docReadCommands-YPAYGHNM.js} +30 -28
- package/{docStore-SUAVM24F.js → docStore-VK3MVJ5Q.js} +6 -6
- package/{docUpdateCommands-QUYX6BVR.js → docUpdateCommands-MPTM6267.js} +30 -28
- package/{getPricing-FCHYVRJU.js → getPricing-5BLZRPTM.js} +3 -3
- package/{handleSendMessageAction-FDIWBQUB.js → handleSendMessageAction-VPKVNKBU.js} +33 -33
- package/{hostCredentialCreate-CEXQHYT4.js → hostCredentialCreate-K56HWPNY.js} +65 -64
- package/index.js +8 -8
- package/{localDialogRead-USDZXKIL.js → localDialogRead-NXILOV3T.js} +1 -1
- package/{localRuntimeAdapter-O3JBRK6S.js → localRuntimeAdapter-KVU72FWT.js} +64 -63
- package/{machineCommands-I3YA7TNC.js → machineCommands-C3O5RKNJ.js} +65 -64
- package/{machineWsRunDispatch-E5CIE2OJ.js → machineWsRunDispatch-ZLART7ZA.js} +65 -64
- package/{mcpLocalAuthorizeCommand-K5J2VMG6.js → mcpLocalAuthorizeCommand-LO7E4VQ5.js} +6 -6
- package/{memberThunks-T7EAZE6A.js → memberThunks-7DNR6DRD.js} +7 -7
- package/{models-EP7VG6N2.js → models-ZX2BYIMB.js} +2 -2
- package/package.json +1 -1
- package/{projectArchive-A7E65AZO.js → projectArchive-UBJFYRL7.js} +19 -19
- package/{providerPresetApply-4H7YP5D7.js → providerPresetApply-NTJUINI6.js} +35 -16
- package/{providerRegistry-F3UPOTIY.js → providerRegistry-W45SLUV6.js} +5 -5
- package/{read-BRZHXUJ6.js → read-Z2JOK6F6.js} +3 -3
- package/{readDocTool-N7RVFQEE.js → readDocTool-3QYSVWBT.js} +1 -1
- package/{readlineWorkspace-2O65NBFG.js → readlineWorkspace-TSIYF7C6.js} +610 -206
- package/{removeDialogAgentAction-GRT72HLK.js → removeDialogAgentAction-LRKDU4RI.js} +7 -7
- package/{runAgentClientLoop-NWCZIXCG.js → runAgentClientLoop-YAHGOWXN.js} +41 -41
- package/{runtimeDoctorCommands-26HYHFTK.js → runtimeDoctorCommands-QGZSKNSE.js} +5 -5
- package/{secretCommands-XR72SHLK.js → secretCommands-BXAQEOES.js} +2 -2
- package/{setDialogExtraReferencesAction-CBG3X46B.js → setDialogExtraReferencesAction-KIITOCFP.js} +6 -6
- package/{setPrimaryDialogAgentAction-EWTDZOAX.js → setPrimaryDialogAgentAction-Y36PKFFB.js} +7 -7
- package/{settingThunks-X4PT66J2.js → settingThunks-YQNG5L6K.js} +5 -5
- package/{spaceCommands-EVSNTGRS.js → spaceCommands-P644AAZZ.js} +29 -27
- package/{streamAgentChatTurn-SYP3OEM5.js → streamAgentChatTurn-5CSYAUAY.js} +54 -50
- package/{switchDialogAgentAction-YHPZ7K6E.js → switchDialogAgentAction-U2VLPPVO.js} +5 -5
- package/{tools-2AO2SK4L.js → tools-UZ3CDIR2.js} +34 -34
- 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-53XCCDK2.js} +18 -18
- 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-CDIRKCPD.js → chunk-6HL6E7ZD.js} +152 -152
- package/{dialogUsageCommand-TBIA2QAF.js → dialogUsageCommand-IHAXS7DW.js} +3 -3
|
@@ -1,30 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
resolveObservedSpeed
|
|
3
|
-
} from "./chunk-AMWMV56B.js";
|
|
4
1
|
import {
|
|
5
2
|
fnv1a32Hex
|
|
6
3
|
} from "./chunk-UEILX4EV.js";
|
|
7
4
|
import {
|
|
5
|
+
DISPATCH_TIER_RANK,
|
|
8
6
|
compareAgentSelection,
|
|
7
|
+
resolveAgentSelectionPriority,
|
|
9
8
|
resolveModelTier
|
|
10
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-ZMXO5G3E.js";
|
|
11
10
|
import {
|
|
12
11
|
DEFAULT_PROVIDER_RETRY_MS,
|
|
13
12
|
isAgentUnavailableNow,
|
|
13
|
+
isSubscriptionPeriodWindow,
|
|
14
14
|
resolveAgentAvailability
|
|
15
|
-
} from "./chunk-
|
|
16
|
-
import {
|
|
17
|
-
LIST_AGENTS_PAGE_BUDGET,
|
|
18
|
-
sanitizeToolOutputText,
|
|
19
|
-
scrubSecrets
|
|
20
|
-
} from "./chunk-CDIRKCPD.js";
|
|
15
|
+
} from "./chunk-LS5KAVFQ.js";
|
|
21
16
|
import {
|
|
22
17
|
isOAuthApiKeyRef
|
|
23
18
|
} from "./chunk-UKZX3NHN.js";
|
|
24
|
-
import {
|
|
25
|
-
createKey,
|
|
26
|
-
createTokenKey
|
|
27
|
-
} from "./chunk-SYTHYBMI.js";
|
|
28
19
|
import {
|
|
29
20
|
isOwnedAgentKey,
|
|
30
21
|
ownedAgentKey,
|
|
@@ -34,7 +25,7 @@ import {
|
|
|
34
25
|
isAntigravityOAuthAgent,
|
|
35
26
|
isSubscriptionEndpoint,
|
|
36
27
|
isSubscriptionOAuthCredential
|
|
37
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-6SOWMEAY.js";
|
|
38
29
|
import {
|
|
39
30
|
asTrimmedLowercaseString
|
|
40
31
|
} from "./chunk-QSJ3HFEF.js";
|
|
@@ -431,6 +422,15 @@ function isOwnedAgentRecord(record2, userId) {
|
|
|
431
422
|
(key) => isOwnedAgentKey(key, userId)
|
|
432
423
|
);
|
|
433
424
|
}
|
|
425
|
+
function subscriptionQuotaChannel(source) {
|
|
426
|
+
if (typeof source !== "string") return void 0;
|
|
427
|
+
const id = source.toLowerCase();
|
|
428
|
+
if (id.includes("fetchavailablemodels:pool:")) return "antigravity";
|
|
429
|
+
const probe = id.match(/(?:^|[^a-z0-9-])(antigravity|codex|anthropic|claude|cursor|devin|xai)-oauth(?=$|[^a-z0-9-])/)?.[1];
|
|
430
|
+
if (probe === "codex") return "chatgpt";
|
|
431
|
+
if (probe === "anthropic") return "claude";
|
|
432
|
+
return probe;
|
|
433
|
+
}
|
|
434
434
|
function toSafeAgentSummary(record2, options) {
|
|
435
435
|
const rawId = parseAgentRecordId(
|
|
436
436
|
typeof record2?.privateKey === "string" ? record2.privateKey : record2?.dbKey,
|
|
@@ -448,6 +448,9 @@ function toSafeAgentSummary(record2, options) {
|
|
|
448
448
|
const name = typeof record2?.name === "string" && record2.name ? record2.name : "(unnamed)";
|
|
449
449
|
const handle = typeof record2?.handle === "string" && record2.handle ? record2.handle : null;
|
|
450
450
|
const introduction = typeof record2?.introduction === "string" && record2.introduction ? record2.introduction : typeof record2?.description === "string" && record2.description ? record2.description : null;
|
|
451
|
+
const roleText = typeof record2?.introduction === "string" ? record2.introduction.trim().replace(/\s+/g, " ") : "";
|
|
452
|
+
const roleChars = Array.from(roleText);
|
|
453
|
+
const roleHint = roleChars.length > 60 ? `${roleChars.slice(0, 59).join("")}\u2026` : roleText;
|
|
451
454
|
const model = typeof record2?.model === "string" && record2.model ? record2.model : null;
|
|
452
455
|
const provider = typeof record2?.provider === "string" && record2.provider ? record2.provider : typeof record2?.apiSource === "string" && record2.apiSource ? record2.apiSource : null;
|
|
453
456
|
const apiSource = typeof record2?.apiSource === "string" && record2.apiSource ? record2.apiSource : null;
|
|
@@ -459,9 +462,6 @@ function toSafeAgentSummary(record2, options) {
|
|
|
459
462
|
const isPublic = record2?.isPublic === true || record2?.isPublicFlag === true || record2?.publicRecordExists === true;
|
|
460
463
|
const updatedAt = safeTimestamp(record2?.updatedAt ?? record2?.createdAt ?? record2?.created);
|
|
461
464
|
const nextAvailableAt = typeof record2?.nextAvailableAt === "number" && Number.isFinite(record2.nextAvailableAt) ? record2.nextAvailableAt : void 0;
|
|
462
|
-
const quotaExhaustion = record2?.quotaExhaustion && typeof record2.quotaExhaustion.observedAt === "number" && Number.isFinite(record2.quotaExhaustion.observedAt) ? { observedAt: record2.quotaExhaustion.observedAt } : void 0;
|
|
463
|
-
const rawQuota = record2?.quota;
|
|
464
|
-
const quota = rawQuota && typeof rawQuota === "object" && Array.isArray(rawQuota.windows) && typeof rawQuota.observedAt === "number" && Number.isFinite(rawQuota.observedAt) ? rawQuota : void 0;
|
|
465
465
|
const currentUserId = options?.userId;
|
|
466
466
|
const ownedKey = currentUserId ? [record2?.dbKey, record2?.privateKey].find(
|
|
467
467
|
(key) => isOwnedAgentKey(key, currentUserId)
|
|
@@ -500,8 +500,24 @@ function toSafeAgentSummary(record2, options) {
|
|
|
500
500
|
const credInfo = deriveCredentialGroup(record2?.credentialGroup ?? rawCredRef);
|
|
501
501
|
const credentialGroup = record2?.credentialGroup ?? credInfo?.credentialGroup;
|
|
502
502
|
const credentialKind = record2?.credentialKind ?? credInfo?.credentialKind;
|
|
503
|
+
const rawQuota = record2?.quota;
|
|
504
|
+
const snapshot = rawQuota && Array.isArray(rawQuota.windows) && Number.isFinite(rawQuota.observedAt) ? rawQuota : void 0;
|
|
505
|
+
const ref = typeof rawCredRef === "string" ? rawCredRef.trim().toLowerCase() : void 0;
|
|
506
|
+
const group = typeof credentialGroup === "string" ? credentialGroup.trim().toLowerCase() : void 0;
|
|
507
|
+
const oauthChannel = isOAuthApiKeyRef(ref) ? ref : isOAuthApiKeyRef(group) ? group : void 0;
|
|
508
|
+
const providerId = provider?.trim().toLowerCase();
|
|
509
|
+
const channel = oauthChannel ?? (providerId === "google-antigravity" ? "antigravity" : providerId);
|
|
510
|
+
const platformChannel = apiSource === "platform" || providerId === "nolo" && !oauthChannel && apiSource !== "custom";
|
|
511
|
+
const windows = snapshot?.windows.filter((window) => {
|
|
512
|
+
const origin = subscriptionQuotaChannel(window?.source);
|
|
513
|
+
return !origin || !platformChannel && (!channel || origin === channel);
|
|
514
|
+
});
|
|
515
|
+
const foreignOnly = Boolean(snapshot?.windows.length && windows?.length === 0);
|
|
516
|
+
const quota = snapshot && windows && !foreignOnly ? { ...snapshot, windows } : void 0;
|
|
517
|
+
const observedAt = record2?.quotaExhaustion?.observedAt;
|
|
518
|
+
const quotaExhaustion = !foreignOnly && typeof observedAt === "number" && Number.isFinite(observedAt) ? { observedAt } : void 0;
|
|
503
519
|
const availability = resolveAgentAvailability(
|
|
504
|
-
{ nextAvailableAt, quota, quotaExhaustion },
|
|
520
|
+
{ nextAvailableAt, quota, quotaExhaustion, model },
|
|
505
521
|
options?.now ?? Date.now()
|
|
506
522
|
);
|
|
507
523
|
return {
|
|
@@ -511,6 +527,7 @@ function toSafeAgentSummary(record2, options) {
|
|
|
511
527
|
name,
|
|
512
528
|
handle,
|
|
513
529
|
introduction,
|
|
530
|
+
...roleHint ? { roleHint } : {},
|
|
514
531
|
model,
|
|
515
532
|
modelTier: resolveModelTier(model),
|
|
516
533
|
provider,
|
|
@@ -550,7 +567,7 @@ function toSafeAgentSummary(record2, options) {
|
|
|
550
567
|
function sortSafeAgentSummaries(agents) {
|
|
551
568
|
return [...agents].sort(compareAgentSelection);
|
|
552
569
|
}
|
|
553
|
-
var
|
|
570
|
+
var AGENT_SUMMARY_FIELDS = [
|
|
554
571
|
// —— 派发决策必需(短字段,必须排最前)——
|
|
555
572
|
// agentKey 是唯一不可推导、必须逐字复制的字段;截断时它首先被保住。
|
|
556
573
|
"agentKey",
|
|
@@ -560,7 +577,6 @@ var COMPACT_AGENT_SUMMARY_FIELDS = [
|
|
|
560
577
|
"billingSource",
|
|
561
578
|
// 扣费授权判据:listAgents 默认走 compact 投影,缺了它模型在默认派发
|
|
562
579
|
// 流程里读不到「派它之前要先问用户」(2026-11-15 事故成因)。
|
|
563
|
-
// 与 ULTRA_COMPACT 白名单必须同时保留——两处任何一处缺失都等于该字段不存在。
|
|
564
580
|
"requiresPaidApproval",
|
|
565
581
|
"availabilityStatus",
|
|
566
582
|
"credentialGroup",
|
|
@@ -581,11 +597,18 @@ var COMPACT_AGENT_SUMMARY_FIELDS = [
|
|
|
581
597
|
// —— 体积大的说明性字段(排在每条记录最后,截断时先牺牲它们)——
|
|
582
598
|
// Phase 2A economics 快照(period/multipliers/changesAt 等小对象)。
|
|
583
599
|
// 只对 DeepSeek API / BigModel GLM Coding Plan 存在;不含完整 policy/windows。
|
|
584
|
-
"economics"
|
|
600
|
+
"economics"
|
|
601
|
+
];
|
|
602
|
+
var AGENT_SUMMARY_TRAILING_FIELDS = [
|
|
585
603
|
"tools",
|
|
586
604
|
// 额度快照(windows 数组,体积最大):只有上游真上报过窗口的 agent 才带。
|
|
587
605
|
"quota"
|
|
588
606
|
];
|
|
607
|
+
var COMPACT_AGENT_SUMMARY_FIELDS = [
|
|
608
|
+
...AGENT_SUMMARY_FIELDS,
|
|
609
|
+
"roleHint",
|
|
610
|
+
...AGENT_SUMMARY_TRAILING_FIELDS
|
|
611
|
+
];
|
|
589
612
|
function omitNullishAgentSummaryFields(summary) {
|
|
590
613
|
const result = {};
|
|
591
614
|
for (const [key, value] of Object.entries(summary)) {
|
|
@@ -606,30 +629,8 @@ function toCompactAgentSummary(summary) {
|
|
|
606
629
|
return compact;
|
|
607
630
|
}
|
|
608
631
|
var ULTRA_COMPACT_AGENT_SUMMARY_FIELDS = [
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
"name",
|
|
612
|
-
"model",
|
|
613
|
-
"modelTier",
|
|
614
|
-
"billingSource",
|
|
615
|
-
// 扣费授权判据必须随投影一起走:精简投影里没有它,模型就看不到
|
|
616
|
-
// 「派它之前要先问用户」,等于该字段不存在(2026-11-15 事故的直接成因)。
|
|
617
|
-
"requiresPaidApproval",
|
|
618
|
-
"availabilityStatus",
|
|
619
|
-
"credentialGroup",
|
|
620
|
-
"isFavorite",
|
|
621
|
-
"isOAuth",
|
|
622
|
-
"isOwned",
|
|
623
|
-
"isPublic",
|
|
624
|
-
"provider",
|
|
625
|
-
"apiSource",
|
|
626
|
-
"credentialKind",
|
|
627
|
-
"credentialed",
|
|
628
|
-
"nextAvailableAt",
|
|
629
|
-
"availabilityReason",
|
|
630
|
-
"economics",
|
|
631
|
-
"tools",
|
|
632
|
-
"quota"
|
|
632
|
+
...AGENT_SUMMARY_FIELDS,
|
|
633
|
+
...AGENT_SUMMARY_TRAILING_FIELDS
|
|
633
634
|
];
|
|
634
635
|
function toUltraCompactAgentSummary(summary) {
|
|
635
636
|
const compact = {};
|
|
@@ -751,10 +752,9 @@ function recommendPlanning(agents, caller, poolComplete) {
|
|
|
751
752
|
if (!callerKey) return { ...base, reason: "caller_unknown" };
|
|
752
753
|
if (currentTier === "unknown") return { ...base, reason: "caller_tier_unknown" };
|
|
753
754
|
if (!poolComplete) return { ...base, reason: "pool_incomplete" };
|
|
754
|
-
const
|
|
755
|
-
const higher = agents.filter((a) => a.agentKey && a.agentKey !== callerKey && a.modelTier !== "unknown" && ranks[a.modelTier] > ranks[currentTier]);
|
|
755
|
+
const higher = agents.filter((a) => a.agentKey && a.agentKey !== callerKey && a.modelTier !== "unknown" && DISPATCH_TIER_RANK[a.modelTier] > DISPATCH_TIER_RANK[currentTier]);
|
|
756
756
|
const free = higher.filter((a) => a.requiresPaidApproval === false);
|
|
757
|
-
free.sort((a, b) =>
|
|
757
|
+
free.sort((a, b) => DISPATCH_TIER_RANK[b.modelTier] - DISPATCH_TIER_RANK[a.modelTier]);
|
|
758
758
|
const best = free[0];
|
|
759
759
|
if (best) return {
|
|
760
760
|
...base,
|
|
@@ -836,6 +836,23 @@ function matchesAgentQuery(agent, query) {
|
|
|
836
836
|
];
|
|
837
837
|
return candidates.some((text) => typeof text === "string" && text.toLowerCase().includes(q));
|
|
838
838
|
}
|
|
839
|
+
function nearestFundedSubscriptionReset(agent, now) {
|
|
840
|
+
let nearest = Infinity;
|
|
841
|
+
if (agent.billingSource !== "user_subscription") return nearest;
|
|
842
|
+
for (const window of agent.quota?.windows ?? []) {
|
|
843
|
+
const { resetAt, remaining, utilization } = window;
|
|
844
|
+
if (typeof resetAt === "number" && resetAt > now && resetAt < nearest && isSubscriptionPeriodWindow(window) && (typeof remaining === "number" && remaining > 0 || typeof utilization === "number" && utilization < 0.95)) {
|
|
845
|
+
nearest = resetAt;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
return nearest;
|
|
849
|
+
}
|
|
850
|
+
function meteredUnitPrice(agent) {
|
|
851
|
+
if (agent.billingSource === "user_subscription" || agent.billingSource === "owner_subscription") return Infinity;
|
|
852
|
+
const input = agent.inputPrice !== null && Number.isFinite(agent.inputPrice) ? agent.inputPrice : 0;
|
|
853
|
+
const output = agent.outputPrice !== null && Number.isFinite(agent.outputPrice) ? agent.outputPrice : 0;
|
|
854
|
+
return input > 0 || output > 0 ? input + output : Infinity;
|
|
855
|
+
}
|
|
839
856
|
function buildAgentDiscoveryResult(options) {
|
|
840
857
|
const scope = resolveDiscoveryScope({
|
|
841
858
|
scope: options.scope,
|
|
@@ -897,6 +914,20 @@ function buildAgentDiscoveryResult(options) {
|
|
|
897
914
|
(offset ?? 0) + (limit ?? sortedAgents.length)
|
|
898
915
|
) : sortedAgents;
|
|
899
916
|
const projectedAgents = options.verbose === true ? pagedAgents.map(omitNullishAgentSummaryFields) : options.compact === true ? pagedAgents.map(toUltraCompactAgentSummary) : pagedAgents.map(toCompactAgentSummary);
|
|
917
|
+
const tierHints = {};
|
|
918
|
+
const tierHintPreferences = /* @__PURE__ */ new Map();
|
|
919
|
+
for (const agent of sortedAgents) {
|
|
920
|
+
const { agentKey, name, model, modelTier, requiresPaidApproval, availabilityStatus } = agent;
|
|
921
|
+
if (!agentKey || requiresPaidApproval !== false || modelTier === "unknown" || availabilityStatus === "quota_exhausted" || availabilityStatus === "rate_limited") continue;
|
|
922
|
+
const priority = resolveAgentSelectionPriority(agent);
|
|
923
|
+
const current = tierHintPreferences.get(modelTier);
|
|
924
|
+
if (current && current.priority !== priority) continue;
|
|
925
|
+
const resetAt = nearestFundedSubscriptionReset(agent, now);
|
|
926
|
+
const price = resetAt === Infinity ? meteredUnitPrice(agent) : Infinity;
|
|
927
|
+
if (current && (resetAt > current.resetAt || resetAt === current.resetAt && price >= current.price)) continue;
|
|
928
|
+
tierHintPreferences.set(modelTier, { priority, resetAt, price });
|
|
929
|
+
tierHints[modelTier] = { agentKey, name, model };
|
|
930
|
+
}
|
|
900
931
|
return {
|
|
901
932
|
total,
|
|
902
933
|
...typeof offset === "number" ? { offset } : {},
|
|
@@ -910,6 +941,7 @@ function buildAgentDiscoveryResult(options) {
|
|
|
910
941
|
options.caller,
|
|
911
942
|
!isTruncated && scope === "all" && !hasQuery && !options.poolRestricted
|
|
912
943
|
),
|
|
944
|
+
...Object.keys(tierHints).length > 0 ? { tierHints } : {},
|
|
913
945
|
credentialGroups
|
|
914
946
|
};
|
|
915
947
|
}
|
|
@@ -918,498 +950,6 @@ function toDiscoverySafeAgentSummary(record2, options) {
|
|
|
918
950
|
return toSafeAgentSummary(record2, mergedOptions);
|
|
919
951
|
}
|
|
920
952
|
|
|
921
|
-
// packages/ai/agent/speedSampleCache.ts
|
|
922
|
-
var SPEED_SAMPLE_DISK_CACHE_TTL_MS = 10 * 6e4;
|
|
923
|
-
var SPEED_SAMPLE_SCAN_BUDGET_MS = 2500;
|
|
924
|
-
var SPEED_SAMPLE_CACHE_VERSION = 4;
|
|
925
|
-
var isFiniteNumber = (value) => typeof value === "number" && Number.isFinite(value);
|
|
926
|
-
var sanitizeSample = (value) => {
|
|
927
|
-
if (!value || typeof value !== "object") return null;
|
|
928
|
-
const sample = value;
|
|
929
|
-
const clean = {};
|
|
930
|
-
if (isFiniteNumber(sample.firstOutputMs)) clean.firstOutputMs = sample.firstOutputMs;
|
|
931
|
-
if (isFiniteNumber(sample.callDurationMs)) clean.callDurationMs = sample.callDurationMs;
|
|
932
|
-
if (isFiniteNumber(sample.output_tokens)) clean.output_tokens = sample.output_tokens;
|
|
933
|
-
if (isFiniteNumber(sample.t)) clean.t = sample.t;
|
|
934
|
-
return clean.firstOutputMs === void 0 && clean.callDurationMs === void 0 ? null : clean;
|
|
935
|
-
};
|
|
936
|
-
var SPEED_SAMPLE_STALE_SNAPSHOT_MAX_MS = 7 * 24 * 60 * 6e4;
|
|
937
|
-
async function parseCacheFile(cachePath, userId) {
|
|
938
|
-
try {
|
|
939
|
-
const fs = await import("node:fs/promises");
|
|
940
|
-
const raw = await fs.readFile(cachePath, "utf8");
|
|
941
|
-
const parsed = JSON.parse(raw);
|
|
942
|
-
if (!parsed || typeof parsed !== "object") return null;
|
|
943
|
-
const version = parsed.version;
|
|
944
|
-
if (version !== SPEED_SAMPLE_CACHE_VERSION) {
|
|
945
|
-
return null;
|
|
946
|
-
}
|
|
947
|
-
if (parsed.userId !== userId) return null;
|
|
948
|
-
if (!isFiniteNumber(parsed.at)) return null;
|
|
949
|
-
const source = parsed.samples;
|
|
950
|
-
if (!source || typeof source !== "object") return null;
|
|
951
|
-
const samples = /* @__PURE__ */ new Map();
|
|
952
|
-
for (const [model, list] of Object.entries(source)) {
|
|
953
|
-
if (!model || !Array.isArray(list)) continue;
|
|
954
|
-
const cleaned = [];
|
|
955
|
-
for (const entry of list) {
|
|
956
|
-
const sample = sanitizeSample(entry);
|
|
957
|
-
if (sample) cleaned.push(sample);
|
|
958
|
-
}
|
|
959
|
-
samples.set(model, cleaned);
|
|
960
|
-
}
|
|
961
|
-
const complete = parsed.complete === true;
|
|
962
|
-
const cursor = typeof parsed.cursor === "string" && parsed.cursor.length > 0 ? parsed.cursor : void 0;
|
|
963
|
-
return { samples, at: parsed.at, complete, cursor: complete ? void 0 : cursor };
|
|
964
|
-
} catch {
|
|
965
|
-
return null;
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
async function readSpeedSamplesSnapshot(cachePath, options) {
|
|
969
|
-
const maxAgeMs = isFiniteNumber(options.maxAgeMs) ? options.maxAgeMs : SPEED_SAMPLE_STALE_SNAPSHOT_MAX_MS;
|
|
970
|
-
const parsed = await parseCacheFile(cachePath, options.userId);
|
|
971
|
-
if (!parsed || !parsed.complete) return null;
|
|
972
|
-
const age = options.now - parsed.at;
|
|
973
|
-
if (age < 0 || age >= maxAgeMs) return null;
|
|
974
|
-
return { samples: parsed.samples, ageMs: age };
|
|
975
|
-
}
|
|
976
|
-
async function readSpeedSamplesProgress(cachePath, userId) {
|
|
977
|
-
const parsed = await parseCacheFile(cachePath, userId);
|
|
978
|
-
if (!parsed) return null;
|
|
979
|
-
return {
|
|
980
|
-
samples: parsed.samples,
|
|
981
|
-
at: parsed.at,
|
|
982
|
-
complete: parsed.complete,
|
|
983
|
-
...parsed.cursor === void 0 ? {} : { cursor: parsed.cursor }
|
|
984
|
-
};
|
|
985
|
-
}
|
|
986
|
-
function resolveSpeedSamplesProgressPath(cachePath) {
|
|
987
|
-
return `${cachePath}.progress`;
|
|
988
|
-
}
|
|
989
|
-
async function writeSpeedSamplesCache(cachePath, payload) {
|
|
990
|
-
try {
|
|
991
|
-
const fs = await import("node:fs/promises");
|
|
992
|
-
const path = await import("node:path");
|
|
993
|
-
await fs.mkdir(path.dirname(cachePath), { recursive: true });
|
|
994
|
-
const tmpPath = `${cachePath}.tmp-${process.pid}-${Math.random().toString(36).slice(2, 8)}`;
|
|
995
|
-
await fs.writeFile(tmpPath, JSON.stringify(payload), "utf8");
|
|
996
|
-
await fs.rename(tmpPath, cachePath);
|
|
997
|
-
} catch {
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1000
|
-
|
|
1001
|
-
// packages/ai/agent/candidateSpeedContext.ts
|
|
1002
|
-
var OBSERVED_SPEED_WINDOW = 50;
|
|
1003
|
-
var MIN_OBSERVED_FIRST_OUTPUT_SAMPLES = 5;
|
|
1004
|
-
var SPEED_SAMPLES_CACHE_TTL_MS = 5 * 6e4;
|
|
1005
|
-
var SPEED_SAMPLES_CACHE_MAX_ENTRIES = 500;
|
|
1006
|
-
function normalizeSpeedModelName(raw) {
|
|
1007
|
-
const name = raw.trim().toLowerCase();
|
|
1008
|
-
const slash = name.lastIndexOf("/");
|
|
1009
|
-
return slash === -1 ? name : name.slice(slash + 1);
|
|
1010
|
-
}
|
|
1011
|
-
var isFiniteNumber2 = (value) => typeof value === "number" && Number.isFinite(value);
|
|
1012
|
-
var REASONING_EFFORT_SUFFIXES = ["minimal", "low", "medium", "high", "xhigh"];
|
|
1013
|
-
var REASONING_EFFORT_SUFFIX_RE = new RegExp(`-(?:${REASONING_EFFORT_SUFFIXES.join("|")})$`);
|
|
1014
|
-
function stripReasoningEffortSuffix(model) {
|
|
1015
|
-
const base = model.replace(REASONING_EFFORT_SUFFIX_RE, "");
|
|
1016
|
-
return base && base !== model ? base : null;
|
|
1017
|
-
}
|
|
1018
|
-
function resolveOneBare(model, samplesByModel) {
|
|
1019
|
-
const observed = resolveObservedSpeed(samplesByModel.get(model) ?? [], {
|
|
1020
|
-
limit: OBSERVED_SPEED_WINDOW
|
|
1021
|
-
});
|
|
1022
|
-
if (observed.firstOutputSampleCount >= MIN_OBSERVED_FIRST_OUTPUT_SAMPLES && observed.medianFirstOutputMs !== void 0) {
|
|
1023
|
-
return {
|
|
1024
|
-
source: "observed",
|
|
1025
|
-
firstOutputMs: observed.medianFirstOutputMs,
|
|
1026
|
-
...observed.medianOutputTokensPerSecond !== void 0 ? { outputTps: observed.medianOutputTokensPerSecond } : {},
|
|
1027
|
-
firstOutputSamples: observed.firstOutputSampleCount,
|
|
1028
|
-
tpsSamples: observed.throughputSampleCount
|
|
1029
|
-
};
|
|
1030
|
-
}
|
|
1031
|
-
return null;
|
|
1032
|
-
}
|
|
1033
|
-
function resolveOne(model, samplesByModel) {
|
|
1034
|
-
const direct = resolveOneBare(model, samplesByModel);
|
|
1035
|
-
if (direct) return { model, ...direct };
|
|
1036
|
-
const base = stripReasoningEffortSuffix(model);
|
|
1037
|
-
if (!base) return null;
|
|
1038
|
-
const stripped = resolveOneBare(base, samplesByModel);
|
|
1039
|
-
return stripped ? { model, ...stripped } : null;
|
|
1040
|
-
}
|
|
1041
|
-
function resolveCandidateSpeedFacts(models, samplesByModel) {
|
|
1042
|
-
const unique = [
|
|
1043
|
-
...new Set(
|
|
1044
|
-
models.filter((model) => typeof model === "string").map(normalizeSpeedModelName).filter(Boolean)
|
|
1045
|
-
)
|
|
1046
|
-
];
|
|
1047
|
-
return unique.map((model) => resolveOne(model, samplesByModel)).filter((fact) => fact !== null);
|
|
1048
|
-
}
|
|
1049
|
-
var formatSeconds = (ms) => `${(ms / 1e3).toFixed(1)}s`;
|
|
1050
|
-
var formatTps = (tps) => String(Math.round(tps));
|
|
1051
|
-
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):";
|
|
1052
|
-
function formatSnapshotAge(ageMs) {
|
|
1053
|
-
const minutes = Math.floor(ageMs / 6e4);
|
|
1054
|
-
if (minutes < 1) return "<1min";
|
|
1055
|
-
if (minutes < 60) return `${minutes}min`;
|
|
1056
|
-
const hours = Math.floor(minutes / 60);
|
|
1057
|
-
if (hours < 24) return `${hours}h`;
|
|
1058
|
-
return `${Math.floor(hours / 24)}d`;
|
|
1059
|
-
}
|
|
1060
|
-
function formatCandidateSpeedFacts(facts, options = {}) {
|
|
1061
|
-
if (facts.length === 0) return null;
|
|
1062
|
-
const lines = facts.map((fact) => {
|
|
1063
|
-
const tps = fact.outputTps !== void 0 ? formatTps(fact.outputTps) : "n/a";
|
|
1064
|
-
return ` ${fact.model}: firstOutput=${formatSeconds(fact.firstOutputMs ?? 0)} tps=${tps} [observed n=${fact.firstOutputSamples ?? 0} tpsN=${fact.tpsSamples ?? 0}]`;
|
|
1065
|
-
});
|
|
1066
|
-
const age = options.snapshotAgeMs;
|
|
1067
|
-
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)` : "";
|
|
1068
|
-
return `${SPEED_CONTEXT_HEADER}${note}
|
|
1069
|
-
${lines.join("\n")}`;
|
|
1070
|
-
}
|
|
1071
|
-
function buildCandidateSpeedContext(models, samplesByModel, options = {}) {
|
|
1072
|
-
return formatCandidateSpeedFacts(resolveCandidateSpeedFacts(models, samplesByModel), options);
|
|
1073
|
-
}
|
|
1074
|
-
var SPEED_SAMPLE_PAGE_SIZE = 2e3;
|
|
1075
|
-
var DISPATCH_ENTRY_PATH = "agent-run";
|
|
1076
|
-
var eventTime = (value) => {
|
|
1077
|
-
if (isFiniteNumber2(value.timestamp)) return value.timestamp;
|
|
1078
|
-
if (isFiniteNumber2(value.createdAt)) return value.createdAt;
|
|
1079
|
-
return 0;
|
|
1080
|
-
};
|
|
1081
|
-
function collectSample(collected, value) {
|
|
1082
|
-
if (typeof value.model !== "string") return;
|
|
1083
|
-
if (!isFiniteNumber2(value.firstOutputMs) && !isFiniteNumber2(value.callDurationMs)) return;
|
|
1084
|
-
const model = normalizeSpeedModelName(value.model);
|
|
1085
|
-
if (!model) return;
|
|
1086
|
-
const list = collected.get(model) ?? [];
|
|
1087
|
-
list.push({
|
|
1088
|
-
t: eventTime(value),
|
|
1089
|
-
firstOutputMs: value.firstOutputMs,
|
|
1090
|
-
callDurationMs: value.callDurationMs,
|
|
1091
|
-
output_tokens: value.output_tokens
|
|
1092
|
-
});
|
|
1093
|
-
collected.set(model, list);
|
|
1094
|
-
}
|
|
1095
|
-
function finalizeSamples(collected, keepTime = false) {
|
|
1096
|
-
const result = /* @__PURE__ */ new Map();
|
|
1097
|
-
for (const [model, list] of collected) {
|
|
1098
|
-
list.sort((a, b) => b.t - a.t);
|
|
1099
|
-
const window = list.slice(0, OBSERVED_SPEED_WINDOW);
|
|
1100
|
-
result.set(
|
|
1101
|
-
model,
|
|
1102
|
-
keepTime ? window : window.map(({ t: _t, ...sample }) => sample)
|
|
1103
|
-
);
|
|
1104
|
-
}
|
|
1105
|
-
return result;
|
|
1106
|
-
}
|
|
1107
|
-
async function collectRecentSpeedSamples(db, userId, options = {}) {
|
|
1108
|
-
const pageSize = isFiniteNumber2(options.pageSize) && options.pageSize > 0 ? Math.floor(options.pageSize) : SPEED_SAMPLE_PAGE_SIZE;
|
|
1109
|
-
const budgetMs = isFiniteNumber2(options.budgetMs) ? options.budgetMs : Number.POSITIVE_INFINITY;
|
|
1110
|
-
const { start, end } = createTokenKey.rangeOfUser(userId);
|
|
1111
|
-
const failedPrefix = createKey("token", userId, "failed-call", "");
|
|
1112
|
-
const dispatchRunCache = /* @__PURE__ */ new Map();
|
|
1113
|
-
const isDispatchSampleRecord = async (record2, resolver, cache) => {
|
|
1114
|
-
if (record2.entry_path !== DISPATCH_ENTRY_PATH && record2.entry_path !== "cli-local") return false;
|
|
1115
|
-
const runId = typeof record2.dialogId === "string" ? record2.dialogId.trim() : "";
|
|
1116
|
-
if (!runId) return false;
|
|
1117
|
-
const cacheKey = `${record2.entry_path}:${runId}`;
|
|
1118
|
-
const cached = cache.get(cacheKey);
|
|
1119
|
-
if (cached !== void 0) return cached;
|
|
1120
|
-
let dispatch = false;
|
|
1121
|
-
if (resolver) {
|
|
1122
|
-
try {
|
|
1123
|
-
dispatch = await resolver(runId, record2.entry_path) === true;
|
|
1124
|
-
} catch {
|
|
1125
|
-
dispatch = false;
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
|
-
cache.set(cacheKey, dispatch);
|
|
1129
|
-
return dispatch;
|
|
1130
|
-
};
|
|
1131
|
-
const collected = /* @__PURE__ */ new Map();
|
|
1132
|
-
const startedAt = Date.now();
|
|
1133
|
-
let lastKey = options.startAfter;
|
|
1134
|
-
let budgetExhausted = false;
|
|
1135
|
-
let scanned = 0;
|
|
1136
|
-
while (true) {
|
|
1137
|
-
if (Date.now() - startedAt >= budgetMs) {
|
|
1138
|
-
budgetExhausted = true;
|
|
1139
|
-
break;
|
|
1140
|
-
}
|
|
1141
|
-
const pageOptions = {
|
|
1142
|
-
...lastKey === void 0 ? { gte: start } : { gt: lastKey },
|
|
1143
|
-
lte: end,
|
|
1144
|
-
limit: pageSize
|
|
1145
|
-
};
|
|
1146
|
-
let accepted = 0;
|
|
1147
|
-
let newestKey = lastKey;
|
|
1148
|
-
for await (const [key, raw] of db.iterator(pageOptions)) {
|
|
1149
|
-
if (typeof key !== "string") continue;
|
|
1150
|
-
if (lastKey !== void 0 && key <= lastKey) continue;
|
|
1151
|
-
accepted += 1;
|
|
1152
|
-
scanned += 1;
|
|
1153
|
-
newestKey = key;
|
|
1154
|
-
if (key.startsWith(failedPrefix)) continue;
|
|
1155
|
-
if (!raw || typeof raw !== "object") continue;
|
|
1156
|
-
const record2 = raw;
|
|
1157
|
-
const resolver = options.isDispatchRun ?? db.isDispatchRun;
|
|
1158
|
-
if (!await isDispatchSampleRecord(
|
|
1159
|
-
record2,
|
|
1160
|
-
resolver ? (runId, entryPath) => resolver.call(db, runId, entryPath) : void 0,
|
|
1161
|
-
dispatchRunCache
|
|
1162
|
-
))
|
|
1163
|
-
continue;
|
|
1164
|
-
collectSample(collected, record2);
|
|
1165
|
-
}
|
|
1166
|
-
if (accepted === 0 || accepted < pageSize) break;
|
|
1167
|
-
lastKey = newestKey;
|
|
1168
|
-
}
|
|
1169
|
-
return {
|
|
1170
|
-
samples: finalizeSamples(collected, options.keepTime === true),
|
|
1171
|
-
budgetExhausted,
|
|
1172
|
-
scanned,
|
|
1173
|
-
...budgetExhausted && lastKey !== void 0 ? { nextCursor: lastKey } : {}
|
|
1174
|
-
};
|
|
1175
|
-
}
|
|
1176
|
-
function mergeNewestSamples(into, from) {
|
|
1177
|
-
for (const [model, list] of from) {
|
|
1178
|
-
const merged = [...into.get(model) ?? [], ...list];
|
|
1179
|
-
merged.sort(
|
|
1180
|
-
(a, b) => (b.t ?? 0) - (a.t ?? 0)
|
|
1181
|
-
);
|
|
1182
|
-
into.set(model, merged.slice(0, OBSERVED_SPEED_WINDOW));
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
|
-
async function loadSpeedSamplesWithDiskCache(db, userId, now, cache) {
|
|
1186
|
-
try {
|
|
1187
|
-
const ttlMs = isFiniteNumber2(cache.ttlMs) ? cache.ttlMs : SPEED_SAMPLE_DISK_CACHE_TTL_MS;
|
|
1188
|
-
const snapshot = await readSpeedSamplesSnapshot(cache.cachePath, { userId, now });
|
|
1189
|
-
if (snapshot && snapshot.ageMs < ttlMs) return { samples: snapshot.samples };
|
|
1190
|
-
const progressPath = resolveSpeedSamplesProgressPath(cache.cachePath);
|
|
1191
|
-
const progress = await readSpeedSamplesProgress(progressPath, userId);
|
|
1192
|
-
const resumable = progress && !progress.complete && progress.cursor ? progress : void 0;
|
|
1193
|
-
const collected = new Map(resumable?.samples ?? []);
|
|
1194
|
-
let step;
|
|
1195
|
-
try {
|
|
1196
|
-
step = await collectRecentSpeedSamples(db, userId, {
|
|
1197
|
-
pageSize: cache.pageSize,
|
|
1198
|
-
budgetMs: isFiniteNumber2(cache.budgetMs) ? cache.budgetMs : SPEED_SAMPLE_SCAN_BUDGET_MS,
|
|
1199
|
-
keepTime: true,
|
|
1200
|
-
...resumable?.cursor ? { startAfter: resumable.cursor } : {}
|
|
1201
|
-
});
|
|
1202
|
-
} catch {
|
|
1203
|
-
return snapshot ? { samples: snapshot.samples, snapshotAgeMs: snapshot.ageMs } : { samples: /* @__PURE__ */ new Map() };
|
|
1204
|
-
}
|
|
1205
|
-
if (!resumable && step.scanned === 0 && !step.budgetExhausted) {
|
|
1206
|
-
return snapshot ? { samples: snapshot.samples, snapshotAgeMs: snapshot.ageMs } : { samples: /* @__PURE__ */ new Map() };
|
|
1207
|
-
}
|
|
1208
|
-
mergeNewestSamples(collected, step.samples);
|
|
1209
|
-
if (!step.budgetExhausted) {
|
|
1210
|
-
await writeSpeedSamplesCache(cache.cachePath, {
|
|
1211
|
-
version: SPEED_SAMPLE_CACHE_VERSION,
|
|
1212
|
-
userId,
|
|
1213
|
-
at: now,
|
|
1214
|
-
complete: true,
|
|
1215
|
-
samples: Object.fromEntries(collected)
|
|
1216
|
-
});
|
|
1217
|
-
await writeSpeedSamplesCache(progressPath, {
|
|
1218
|
-
version: SPEED_SAMPLE_CACHE_VERSION,
|
|
1219
|
-
userId,
|
|
1220
|
-
at: now,
|
|
1221
|
-
complete: true,
|
|
1222
|
-
samples: {}
|
|
1223
|
-
});
|
|
1224
|
-
return { samples: collected };
|
|
1225
|
-
}
|
|
1226
|
-
await writeSpeedSamplesCache(progressPath, {
|
|
1227
|
-
version: SPEED_SAMPLE_CACHE_VERSION,
|
|
1228
|
-
userId,
|
|
1229
|
-
// Progress keeps the cycle's collection start so a later stale label stays honest.
|
|
1230
|
-
at: resumable?.at ?? now,
|
|
1231
|
-
complete: false,
|
|
1232
|
-
samples: Object.fromEntries(collected),
|
|
1233
|
-
...step.nextCursor ? { cursor: step.nextCursor } : {}
|
|
1234
|
-
});
|
|
1235
|
-
return snapshot ? { samples: snapshot.samples, snapshotAgeMs: snapshot.ageMs } : { samples: /* @__PURE__ */ new Map() };
|
|
1236
|
-
} catch {
|
|
1237
|
-
return { samples: /* @__PURE__ */ new Map() };
|
|
1238
|
-
}
|
|
1239
|
-
}
|
|
1240
|
-
var samplesCache = /* @__PURE__ */ new Map();
|
|
1241
|
-
function writeSamplesCache(userId, now, samples) {
|
|
1242
|
-
for (const [key, entry] of samplesCache) {
|
|
1243
|
-
if (now - entry.at >= SPEED_SAMPLES_CACHE_TTL_MS) samplesCache.delete(key);
|
|
1244
|
-
}
|
|
1245
|
-
samplesCache.delete(userId);
|
|
1246
|
-
samplesCache.set(userId, { at: now, samples });
|
|
1247
|
-
while (samplesCache.size > SPEED_SAMPLES_CACHE_MAX_ENTRIES) {
|
|
1248
|
-
const oldest = samplesCache.keys().next().value;
|
|
1249
|
-
if (oldest === void 0) break;
|
|
1250
|
-
samplesCache.delete(oldest);
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
var SPEED_SAMPLE_REFRESH_BUDGET_MS = 6e4;
|
|
1254
|
-
var snapshotRefreshes = /* @__PURE__ */ new Map();
|
|
1255
|
-
function startSpeedSnapshotRefresh(db, userId, now = Date.now()) {
|
|
1256
|
-
const inFlight = snapshotRefreshes.get(userId);
|
|
1257
|
-
if (inFlight) return inFlight;
|
|
1258
|
-
const job = (async () => {
|
|
1259
|
-
try {
|
|
1260
|
-
const { samples, budgetExhausted } = await collectRecentSpeedSamples(db, userId, {
|
|
1261
|
-
budgetMs: SPEED_SAMPLE_REFRESH_BUDGET_MS
|
|
1262
|
-
});
|
|
1263
|
-
if (!budgetExhausted) writeSamplesCache(userId, now, samples);
|
|
1264
|
-
} catch {
|
|
1265
|
-
}
|
|
1266
|
-
})().finally(() => {
|
|
1267
|
-
snapshotRefreshes.delete(userId);
|
|
1268
|
-
});
|
|
1269
|
-
snapshotRefreshes.set(userId, job);
|
|
1270
|
-
return job;
|
|
1271
|
-
}
|
|
1272
|
-
async function loadCachedSpeedSamples(db, userId, now) {
|
|
1273
|
-
const hit = samplesCache.get(userId);
|
|
1274
|
-
if (hit) {
|
|
1275
|
-
const age = now - hit.at;
|
|
1276
|
-
if (age >= 0 && age < SPEED_SAMPLE_STALE_SNAPSHOT_MAX_MS) {
|
|
1277
|
-
if (age >= SPEED_SAMPLES_CACHE_TTL_MS) void startSpeedSnapshotRefresh(db, userId);
|
|
1278
|
-
return age >= SPEED_SAMPLES_CACHE_TTL_MS ? { samples: hit.samples, snapshotAgeMs: age } : { samples: hit.samples };
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
void startSpeedSnapshotRefresh(db, userId);
|
|
1282
|
-
return { samples: /* @__PURE__ */ new Map() };
|
|
1283
|
-
}
|
|
1284
|
-
async function injectSpeedContextIntoListAgentsResult(result, options = {}) {
|
|
1285
|
-
try {
|
|
1286
|
-
let parsed;
|
|
1287
|
-
try {
|
|
1288
|
-
parsed = JSON.parse(result);
|
|
1289
|
-
} catch {
|
|
1290
|
-
return result;
|
|
1291
|
-
}
|
|
1292
|
-
if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.agents)) return result;
|
|
1293
|
-
const models = parsed.agents.map((agent) => agent?.model).filter((model) => typeof model === "string");
|
|
1294
|
-
if (models.length === 0 && !options.compactPage) return result;
|
|
1295
|
-
const now = options.now ?? Date.now();
|
|
1296
|
-
let samples = /* @__PURE__ */ new Map();
|
|
1297
|
-
let snapshotAgeMs;
|
|
1298
|
-
const userId = typeof options.userId === "string" ? options.userId.trim() : "";
|
|
1299
|
-
if (options.db && userId) {
|
|
1300
|
-
try {
|
|
1301
|
-
const loaded = options.diskCache ? await loadSpeedSamplesWithDiskCache(options.db, userId, now, options.diskCache) : await loadCachedSpeedSamples(options.db, userId, now);
|
|
1302
|
-
samples = loaded.samples;
|
|
1303
|
-
snapshotAgeMs = loaded.snapshotAgeMs;
|
|
1304
|
-
} catch {
|
|
1305
|
-
samples = /* @__PURE__ */ new Map();
|
|
1306
|
-
}
|
|
1307
|
-
}
|
|
1308
|
-
if (options.compactPage) {
|
|
1309
|
-
return await serializeCompactAgentPage(parsed, samples, snapshotAgeMs, options);
|
|
1310
|
-
}
|
|
1311
|
-
const speedContext = buildCandidateSpeedContext(models, samples, { snapshotAgeMs });
|
|
1312
|
-
return speedContext ? JSON.stringify({ ...parsed, speedContext }) : result;
|
|
1313
|
-
} catch {
|
|
1314
|
-
return options.compactPage ? JSON.stringify({ success: false, error: "LIST_AGENTS_PAGE_SERIALIZATION_FAILED" }) : result;
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
async function serializeCompactAgentPage(parsed, samples, snapshotAgeMs, options) {
|
|
1318
|
-
const maxChars = LIST_AGENTS_PAGE_BUDGET;
|
|
1319
|
-
const maxBytes = LIST_AGENTS_PAGE_BUDGET;
|
|
1320
|
-
const fits = (page) => page.length <= maxChars && new TextEncoder().encode(page).length <= maxBytes;
|
|
1321
|
-
const offset = typeof parsed.offset === "number" ? parsed.offset : 0;
|
|
1322
|
-
const candidates = parsed.agents;
|
|
1323
|
-
const availableCount = typeof parsed.availableCount === "number" ? parsed.availableCount : parsed.total;
|
|
1324
|
-
const groups = Array.isArray(parsed.credentialGroups) ? parsed.credentialGroups : [];
|
|
1325
|
-
if (options.fragmentOffset !== void 0) {
|
|
1326
|
-
const fragmentOffset = Number(options.fragmentOffset);
|
|
1327
|
-
const agentKey2 = candidates[0]?.agentKey;
|
|
1328
|
-
if (typeof options.fragmentOffset !== "number" && (typeof options.fragmentOffset !== "string" || !/^\d+$/.test(options.fragmentOffset)) || !Number.isSafeInteger(fragmentOffset) || fragmentOffset < 0 || typeof agentKey2 !== "string" || agentKey2 !== options.fragmentAgentKey) {
|
|
1329
|
-
return JSON.stringify({ success: false, error: "LIST_AGENTS_FRAGMENT_INVALID", offset });
|
|
1330
|
-
}
|
|
1331
|
-
const agent = candidates[0];
|
|
1332
|
-
const speedContext = buildCandidateSpeedContext(typeof agent.model === "string" ? [agent.model] : [], samples, { snapshotAgeMs });
|
|
1333
|
-
const payload = { agent, credentialGroups: groups.filter((group) => group.credentialGroup === agent.credentialGroup) };
|
|
1334
|
-
let keyCollision = false;
|
|
1335
|
-
const cleanText = (value) => scrubSecrets(sanitizeToolOutputText(value)).cleaned;
|
|
1336
|
-
const sanitize = (value) => {
|
|
1337
|
-
if (typeof value === "string") return cleanText(value);
|
|
1338
|
-
if (Array.isArray(value)) return value.map(sanitize);
|
|
1339
|
-
if (value && typeof value === "object") {
|
|
1340
|
-
const entries = [];
|
|
1341
|
-
const keys = /* @__PURE__ */ new Set();
|
|
1342
|
-
for (const [key, item] of Object.entries(value)) {
|
|
1343
|
-
const cleanedKey = cleanText(key);
|
|
1344
|
-
if (keys.has(cleanedKey)) keyCollision = true;
|
|
1345
|
-
keys.add(cleanedKey);
|
|
1346
|
-
entries.push([cleanedKey, sanitize(item)]);
|
|
1347
|
-
}
|
|
1348
|
-
return Object.fromEntries(entries);
|
|
1349
|
-
}
|
|
1350
|
-
return value;
|
|
1351
|
-
};
|
|
1352
|
-
const safePayload = sanitize(payload);
|
|
1353
|
-
if (keyCollision) return JSON.stringify({ success: false, error: "LIST_AGENTS_SANITIZED_KEY_COLLISION", offset });
|
|
1354
|
-
const serialized = JSON.stringify(safePayload);
|
|
1355
|
-
const bytes = new TextEncoder().encode(serialized);
|
|
1356
|
-
const hash = await globalThis.crypto.subtle.digest("SHA-256", bytes);
|
|
1357
|
-
const digest = Array.from(new Uint8Array(hash), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
1358
|
-
if (fragmentOffset > 0 && !options.fragmentDigest || options.fragmentDigest && options.fragmentDigest !== digest) {
|
|
1359
|
-
return JSON.stringify({ success: false, error: "LIST_AGENTS_FRAGMENT_CHANGED", offset });
|
|
1360
|
-
}
|
|
1361
|
-
if (fragmentOffset >= serialized.length) return JSON.stringify({ success: false, error: "LIST_AGENTS_FRAGMENT_INVALID", offset });
|
|
1362
|
-
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 });
|
|
1363
|
-
let end = Math.min(serialized.length, fragmentOffset + 3e3);
|
|
1364
|
-
if (end < serialized.length && /[\uD800-\uDBFF]/.test(serialized[end - 1]) && /[\uDC00-\uDFFF]/.test(serialized[end])) end--;
|
|
1365
|
-
const fragment = serialized.slice(fragmentOffset, end);
|
|
1366
|
-
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) } : {} });
|
|
1367
|
-
return fits(result) ? result : JSON.stringify({ success: false, error: "LIST_AGENTS_FRAGMENT_METADATA_TOO_LARGE", offset });
|
|
1368
|
-
}
|
|
1369
|
-
const makePage = (count) => {
|
|
1370
|
-
const agents = candidates.slice(0, count);
|
|
1371
|
-
const groupKeys = new Set(agents.map((agent) => agent.credentialGroup).filter(Boolean));
|
|
1372
|
-
const speedContext = buildCandidateSpeedContext(agents.map((agent) => agent.model).filter((model) => typeof model === "string"), samples, { snapshotAgeMs });
|
|
1373
|
-
const nextOffset = offset + count;
|
|
1374
|
-
const hasMore = nextOffset < availableCount;
|
|
1375
|
-
return JSON.stringify({
|
|
1376
|
-
...parsed,
|
|
1377
|
-
offset,
|
|
1378
|
-
agents,
|
|
1379
|
-
credentialGroups: groups.filter((group) => groupKeys.has(group.credentialGroup)),
|
|
1380
|
-
hasMore,
|
|
1381
|
-
...hasMore ? { nextOffset } : {},
|
|
1382
|
-
...speedContext ? { speedContext } : {}
|
|
1383
|
-
});
|
|
1384
|
-
};
|
|
1385
|
-
if (!candidates.length) {
|
|
1386
|
-
const empty = makePage(0);
|
|
1387
|
-
if (fits(empty)) return empty;
|
|
1388
|
-
} else {
|
|
1389
|
-
let best;
|
|
1390
|
-
for (let count = 1; count <= candidates.length; count++) {
|
|
1391
|
-
const page = makePage(count);
|
|
1392
|
-
if (!fits(page)) break;
|
|
1393
|
-
best = page;
|
|
1394
|
-
}
|
|
1395
|
-
if (best) return best;
|
|
1396
|
-
}
|
|
1397
|
-
const agentKey = typeof candidates[0]?.agentKey === "string" ? candidates[0].agentKey : void 0;
|
|
1398
|
-
const error = {
|
|
1399
|
-
success: false,
|
|
1400
|
-
error: candidates.length ? "LIST_AGENTS_CANDIDATE_TOO_LARGE" : "LIST_AGENTS_PAGE_METADATA_TOO_LARGE",
|
|
1401
|
-
offset,
|
|
1402
|
-
...agentKey ? { agentKey, recovery: {
|
|
1403
|
-
tool: "listAgents",
|
|
1404
|
-
arguments: { compact: true, offset, fragmentOffset: 0, fragmentAgentKey: agentKey },
|
|
1405
|
-
note: "Repeat with the same filters and returned digest and nextFragmentOffset; concatenate fragments and parse JSON before continuing at nextOffset."
|
|
1406
|
-
} } : {},
|
|
1407
|
-
...candidates.length ? { nextOffset: offset + 1, truncated: parsed.truncated === true, poolComplete: parsed.planningRecommendation?.poolComplete === true, hasMore: offset + 1 < availableCount } : {}
|
|
1408
|
-
};
|
|
1409
|
-
const encoded = JSON.stringify(error);
|
|
1410
|
-
return fits(encoded) ? encoded : JSON.stringify({ success: false, error: "LIST_AGENTS_RECOVERY_ID_TOO_LARGE", offset });
|
|
1411
|
-
}
|
|
1412
|
-
|
|
1413
953
|
// packages/ai/agent/dispatchSpeedProvenance.ts
|
|
1414
954
|
var record = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
1415
955
|
function isServerDispatchSpeedSource(value, dialogId, userId) {
|
|
@@ -1435,7 +975,6 @@ export {
|
|
|
1435
975
|
matchesAgentQuery,
|
|
1436
976
|
buildAgentDiscoveryResult,
|
|
1437
977
|
toDiscoverySafeAgentSummary,
|
|
1438
|
-
injectSpeedContextIntoListAgentsResult,
|
|
1439
978
|
isServerDispatchSpeedSource,
|
|
1440
979
|
isLocalDispatchSpeedSource
|
|
1441
980
|
};
|