nolo-cli 0.227.0-alpha.1 → 0.228.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.
Files changed (199) hide show
  1. package/{_executeModel-JKQGZ3HU.js → _executeModel-VYCHHZVT.js} +78 -77
  2. package/{action-CK64LS6S.js → action-GDZDXPMB.js} +9 -9
  3. package/{addContentAction-CARFID6E.js → addContentAction-7RO4AMRI.js} +14 -14
  4. package/{addDialogAgentAction-APLZLFW5.js → addDialogAgentAction-EVYBGTXB.js} +16 -16
  5. package/{agentDeleteCommand-NVR2V2HH.js → agentDeleteCommand-QWQKT54A.js} +116 -115
  6. package/{agentEmailCommands-UCVOWD3S.js → agentEmailCommands-EISMBIRE.js} +119 -118
  7. package/{agentFavoriteCommands-4PDOP3GW.js → agentFavoriteCommands-7LOP3HUD.js} +6 -6
  8. package/{agentGrantCommands-FLCEXLUH.js → agentGrantCommands-L6O2HVJI.js} +7 -7
  9. package/{agentListCommands-C65UESYM.js → agentListCommands-4WLG32IW.js} +79 -470
  10. package/{agentMachineCommands-V3DGEJU4.js → agentMachineCommands-DC6NKWTU.js} +59 -57
  11. package/{agentProviderCommands-7QBFRFRK.js → agentProviderCommands-STI3DQ6A.js} +7 -7
  12. package/{agentPullCommand-E6JBGBVG.js → agentPullCommand-KHV4EELF.js} +6 -6
  13. package/{agentRecordCommands-6RCJS2EY.js → agentRecordCommands-IZYUVHME.js} +107 -106
  14. package/{agentRunCommand-P3GRKXKS.js → agentRunCommand-QM7ETUTX.js} +113 -112
  15. package/{agentRunControl-SNZZ5XP4.js → agentRunControl-MBG4U6SL.js} +23 -17
  16. package/{agentRuntimeLocal-GOX2DIY7.js → agentRuntimeLocal-HOXKWCYO.js} +46 -45
  17. package/{agentSlice-N7H2FRJA.js → agentSlice-UG76KEBH.js} +17 -17
  18. package/{appDeleteCommands-LZDN26FU.js → appDeleteCommands-WWCC6WA5.js} +54 -52
  19. package/{appDeployCommands-6IO6TTZH.js → appDeployCommands-AU4IUN33.js} +54 -52
  20. package/{appDeployStatusCommands-FG3LX24J.js → appDeployStatusCommands-STUW7WXL.js} +54 -52
  21. package/{appGetCommands-NAKVDVD4.js → appGetCommands-BGTLIQ4K.js} +54 -52
  22. package/{appListCommands-KL56RN73.js → appListCommands-CUCPRUXW.js} +54 -52
  23. package/{authCommand-AUN5MXV2.js → authCommand-OZ2KTP4Z.js} +30 -31
  24. package/{authCommands-D2IPS6ES.js → authCommands-55OGQGCR.js} +12 -13
  25. package/{builtinSkillRegistry-UQGLKRYP.js → builtinSkillRegistry-BAE2LDXF.js} +4 -4
  26. package/{chromeOpsCommands-UJWN5HWH.js → chromeOpsCommands-WAA45NCS.js} +8 -8
  27. package/{chunk-OB6DVWPF.js → chunk-262R3XNN.js} +16 -2
  28. package/{chunk-UN7HIYMH.js → chunk-2X7WFDT6.js} +1 -1
  29. package/{chunk-XI2BWJM5.js → chunk-324FWHUA.js} +20 -3
  30. package/{chunk-CVERLOJM.js → chunk-3QIYD3VM.js} +639 -513
  31. package/{chunk-RU6DULV4.js → chunk-3U44JB3O.js} +1 -1
  32. package/{chunk-IAJJYHIB.js → chunk-3VZLEKV2.js} +7 -7
  33. package/{chunk-JWXITTQB.js → chunk-42OKN2LI.js} +1 -1
  34. package/{chunk-UAPNPNSG.js → chunk-45CAVC35.js} +1072 -859
  35. package/{chunk-EUCFKKDM.js → chunk-4I2MXV5Q.js} +38 -10
  36. package/{chunk-SW6OD4KE.js → chunk-4QYJPWHH.js} +123 -12
  37. package/{chunk-PLPLH2XZ.js → chunk-4ZGPHFLE.js} +2 -2
  38. package/{chunk-NO3VBWTL.js → chunk-547ENH5T.js} +1 -1
  39. package/{chunk-CKT6QUE2.js → chunk-5YMA6DDZ.js} +1 -1
  40. package/chunk-5ZUOVCKT.js +32 -0
  41. package/{chunk-XZODOEKU.js → chunk-6QHKRARD.js} +2 -2
  42. package/{chunk-YGMBIXCF.js → chunk-6XRPBZRS.js} +4 -2
  43. package/{chunk-PVAWNHP5.js → chunk-7BCG67EI.js} +295 -102
  44. package/{chunk-VZW34YUL.js → chunk-7FEP5USX.js} +8 -5
  45. package/{chunk-VPAZ6BEN.js → chunk-7JGMNKKG.js} +18 -14
  46. package/{chunk-5HL4KC4A.js → chunk-ALAES342.js} +57 -86
  47. package/{chunk-VREDDN25.js → chunk-ATEKLSLR.js} +1 -1
  48. package/chunk-BIDSIRTS.js +307 -0
  49. package/chunk-BIWI5M4E.js +62 -0
  50. package/{chunk-UCFPVYP7.js → chunk-BP5ZJ6B4.js} +1 -1
  51. package/{chunk-2G3YSVO6.js → chunk-CBUZ6DKA.js} +3 -3
  52. package/{chunk-KYH7XW3K.js → chunk-CD3RU7XL.js} +16 -1
  53. package/{chunk-SFTTXGPM.js → chunk-CMMI3DAT.js} +16 -16
  54. package/{chunk-VIHDJ3FK.js → chunk-CNMY2XM6.js} +14 -14
  55. package/{chunk-UVUVQVZ6.js → chunk-DBUR22G5.js} +2 -2
  56. package/{chunk-G6HJUMST.js → chunk-DEA37IUY.js} +2 -2
  57. package/{chunk-5RKRXQ2H.js → chunk-DGYCDA6W.js} +2 -2
  58. package/{chunk-FKEZOMIF.js → chunk-DLXMMTGM.js} +523 -202
  59. package/{chunk-3HTP4WZQ.js → chunk-DUUDXSLX.js} +21 -7
  60. package/{chunk-KFHREHUQ.js → chunk-DXWGFL2Z.js} +89 -1
  61. package/{chunk-TOKPHZ55.js → chunk-EEOOBRA7.js} +5 -5
  62. package/{chunk-ZI5SZ3MV.js → chunk-EGHP7KOY.js} +20 -20
  63. package/{chunk-OXA5GWHU.js → chunk-F6Z6ZCUV.js} +2 -2
  64. package/{chunk-X2KRQP7V.js → chunk-FJSNBZXR.js} +1 -1
  65. package/{chunk-3VFYQH3I.js → chunk-FPBJM2BW.js} +17 -39
  66. package/{chunk-KRRE4A7D.js → chunk-G7IUT2V3.js} +3 -2
  67. package/{chunk-LXTC53TN.js → chunk-GAYNXB6T.js} +184 -153
  68. package/{chunk-45LZIYXB.js → chunk-HBRDSQ3M.js} +1 -1
  69. package/{chunk-GRXSJR2Z.js → chunk-HF7BLF3F.js} +21 -21
  70. package/{chunk-T5N6NHAT.js → chunk-HHFGE2WF.js} +3 -3
  71. package/{chunk-IX2BXN2K.js → chunk-HSSBDZLD.js} +3 -3
  72. package/{chunk-TINJKQSO.js → chunk-HXB4VDGK.js} +20 -20
  73. package/{chunk-MWHOH4RJ.js → chunk-HYLRQDEE.js} +4 -4
  74. package/{chunk-L5I543VB.js → chunk-JQZRSXS5.js} +23 -23
  75. package/{chunk-T2BEPTAG.js → chunk-L32W3PRP.js} +47 -17
  76. package/{chunk-LA7JYAKF.js → chunk-LYD6C7OU.js} +3 -3
  77. package/{chunk-PHOSZT3E.js → chunk-M3OZRQNH.js} +1 -1
  78. package/{chunk-M3Y4IBIR.js → chunk-M4SFKP5L.js} +4 -4
  79. package/{chunk-7Z3WUZ4Q.js → chunk-MJI3UAXN.js} +52 -28
  80. package/{chunk-YOT437BH.js → chunk-MNEZUL5S.js} +137 -118
  81. package/{chunk-GOLPOTG5.js → chunk-MZG5CETE.js} +3 -3
  82. package/{chunk-KJAAPGBE.js → chunk-OBIC6EG7.js} +6 -6
  83. package/{chunk-CLCXHIBS.js → chunk-OJ45MEEI.js} +1 -1
  84. package/{chunk-AXYH4734.js → chunk-OOJNQK6V.js} +13 -13
  85. package/{chunk-2SKTCNWO.js → chunk-OTKSESZR.js} +2 -2
  86. package/{chunk-XIEYGCN6.js → chunk-OWKNSIXL.js} +149 -48
  87. package/{chunk-6XIE5ZGI.js → chunk-PDCV7P5W.js} +1 -1
  88. package/{chunk-HOCHUZQ7.js → chunk-QJTZ76CP.js} +24 -6
  89. package/{chunk-YQETUZ5V.js → chunk-QRGDJA4B.js} +11 -11
  90. package/{chunk-ULAQPRHX.js → chunk-QYB23WUH.js} +1 -1
  91. package/{chunk-CSW7IPVD.js → chunk-R6Z5S5GA.js} +11 -11
  92. package/{chunk-MK2Q7ZJD.js → chunk-R7XWZDOH.js} +58 -24
  93. package/{chunk-GUVXQSFZ.js → chunk-RBPUNSG5.js} +1 -1
  94. package/{chunk-GOQ6ZVTN.js → chunk-RG2DGNL6.js} +3 -3
  95. package/{chunk-F5AY2UZL.js → chunk-RRDRQOEC.js} +515 -9
  96. package/{chunk-6EDAMVG6.js → chunk-RTHFJZ6M.js} +10 -10
  97. package/{chunk-WJP4TH6U.js → chunk-S6FDXXZV.js} +1 -1
  98. package/{chunk-LJSNEV7M.js → chunk-SRCCSTIM.js} +7 -7
  99. package/{chunk-KMRKZNGT.js → chunk-TCZ2VJZQ.js} +13 -12
  100. package/{chunk-AK5O76CC.js → chunk-TI2EPRHE.js} +2 -2
  101. package/{chunk-5LQDHFBN.js → chunk-TQEKUOTI.js} +14 -11
  102. package/{chunk-SRG5CNLC.js → chunk-TSPMLCWI.js} +6 -6
  103. package/{chunk-YGILMZ7N.js → chunk-TUSTONB3.js} +1 -1
  104. package/{chunk-YPPKC6FL.js → chunk-U2HBB7RS.js} +17 -17
  105. package/{chunk-HVUDBOQG.js → chunk-VMJVAJ6W.js} +9 -6
  106. package/{chunk-CQVGR3MX.js → chunk-VQ5N5GSV.js} +8 -8
  107. package/{chunk-ABGULE7H.js → chunk-WCFFRBL5.js} +12 -12
  108. package/{chunk-NAOO4PVX.js → chunk-WFDNADFX.js} +16 -16
  109. package/chunk-WFGNWWJI.js +326 -0
  110. package/{chunk-FIYSMXHY.js → chunk-WWTSEBDF.js} +1 -1
  111. package/{chunk-JHF6VLVL.js → chunk-X3E6EHJW.js} +32 -31
  112. package/{chunk-E2BESSAW.js → chunk-X4O7FJF5.js} +2 -0
  113. package/{chunk-C2B7M567.js → chunk-XAG3FWBE.js} +15 -4
  114. package/{chunk-4OKTPFNX.js → chunk-XFXFPUO7.js} +105 -37
  115. package/{chunk-HYKGIXNO.js → chunk-XSW4EXQV.js} +85 -21
  116. package/{chunk-ZADGPNTV.js → chunk-XTJKU3Z4.js} +29 -29
  117. package/{chunk-T43K75CK.js → chunk-YKY4OVOX.js} +15 -15
  118. package/{chunk-ZYA2YDB6.js → chunk-YVFH2MFB.js} +16 -16
  119. package/{chunk-L42CBKBZ.js → chunk-ZEVQHCLM.js} +3 -3
  120. package/{chunk-5RKUPJYL.js → chunk-ZH3KXFHS.js} +11 -3
  121. package/chunk-ZOHO6MOF.js +376 -0
  122. package/{chunk-PXKF5CV4.js → chunk-ZXF6D3I6.js} +10 -8
  123. package/{cliAgentConfigHelpers-QVSQYTKC.js → cliAgentConfigHelpers-BTRHMPW2.js} +14 -14
  124. package/{cliEnvHelpers-D6HMC46Z.js → cliEnvHelpers-CNMP3RDX.js} +2 -2
  125. package/{cliExecutor-4MAX3PZL.js → cliExecutor-K6FDZTQ2.js} +3 -1
  126. package/{cliLocalAgentRecordReader-SPKAJYME.js → cliLocalAgentRecordReader-H3HYQRRR.js} +48 -47
  127. package/{commandRegistry-TKR6OWXP.js → commandRegistry-FVYPE2IN.js} +93 -93
  128. package/{contentThunks-BQWRPCTM.js → contentThunks-GNFPG32S.js} +36 -35
  129. package/{cooldownCommands-FZYQOWI5.js → cooldownCommands-YB5H5BBK.js} +3 -3
  130. package/{createAgentAutomationAction-GFI6SJZV.js → createAgentAutomationAction-PB4QIFQ4.js} +36 -35
  131. package/{createDialogAction-MMBIHFFU.js → createDialogAction-EVTOPY7A.js} +37 -37
  132. package/{createPageAction-EEYUE5FB.js → createPageAction-2UYF2IDZ.js} +39 -38
  133. package/{db-CS4ZJQKV.js → db-M7FU2GNK.js} +9 -6
  134. package/{dbSlice-X4Z4E4QU.js → dbSlice-XRUZOGSU.js} +13 -13
  135. package/{deleteFile-QOOP2UK7.js → deleteFile-6URDHYRB.js} +9 -9
  136. package/{dialogCommands-OXBQ73DD.js → dialogCommands-6SZD4TYP.js} +58 -57
  137. package/{dialogNotifyCommand-VWS5G4OO.js → dialogNotifyCommand-SHGPCU22.js} +17 -17
  138. package/{dialogSlice-KGYIABDY.js → dialogSlice-5EQ2A6LY.js} +34 -33
  139. package/{dialogUsageCommand-FEWCN7IA.js → dialogUsageCommand-W2WCSGKF.js} +6 -6
  140. package/{docCreateCommands-LS32VKY3.js → docCreateCommands-25E6PGN3.js} +53 -51
  141. package/{docDeleteCommands-JTYR5RPH.js → docDeleteCommands-F7ZVGEHW.js} +55 -53
  142. package/{docReadCommands-E5LTVKWN.js → docReadCommands-JY2E5XEN.js} +53 -51
  143. package/{docStore-TVS2FNER.js → docStore-OKKIKLT3.js} +15 -15
  144. package/{docUpdateCommands-I3J3JDZ2.js → docUpdateCommands-OZ4CUSIQ.js} +53 -51
  145. package/{fetchMessages-Q3INLN5F.js → fetchMessages-TQEUZD7H.js} +3 -3
  146. package/{getPricing-VNGFM4PN.js → getPricing-LF5C4XSI.js} +6 -6
  147. package/{handleSendMessageAction-SSON36TJ.js → handleSendMessageAction-LNT7SZND.js} +68 -67
  148. package/{hostCredentialCreate-WTW4THJF.js → hostCredentialCreate-XUU2CSHI.js} +107 -106
  149. package/index.js +54 -16
  150. package/keys-RWF7UCB4.js +1 -1
  151. package/{localDialogRead-V36DX2Q2.js → localDialogRead-CCOCVGAP.js} +2 -2
  152. package/{localRuntimeAdapter-MI2JGXSF.js → localRuntimeAdapter-IBSTMSX7.js} +114 -113
  153. package/{machineCommands-3LROJZDK.js → machineCommands-HSQHDHOT.js} +135 -119
  154. package/{machineWsRunDispatch-BUUJRUUB.js → machineWsRunDispatch-L6H7J66T.js} +105 -104
  155. package/{memberThunks-CFEPHAND.js → memberThunks-7Y3OYSJQ.js} +17 -17
  156. package/{memoryCommands-JQMEJO7J.js → memoryCommands-BC6REPQB.js} +6 -6
  157. package/{overlay-THLKYIWY.js → overlay-BBQZXGYI.js} +5 -3
  158. package/package.json +1 -1
  159. package/{projectArchive-3X54XFVN.js → projectArchive-FQO654Z3.js} +44 -43
  160. package/{providerPresetApply-FO36N5TX.js → providerPresetApply-WHAMP2D5.js} +9 -9
  161. package/{providerRegistry-U2BSFE6K.js → providerRegistry-ZI2KORJ7.js} +9 -9
  162. package/{read-KA3L2V7O.js → read-TYMBGEXO.js} +9 -9
  163. package/{readDocTool-AMAZAPAW.js → readDocTool-SKQVHBLO.js} +1 -1
  164. package/{readlineWorkspace-Z3YUH4SX.js → readlineWorkspace-7U272DSA.js} +4398 -4165
  165. package/{removeDialogAgentAction-JQOJSUM7.js → removeDialogAgentAction-F5QE2O2B.js} +19 -19
  166. package/{runAgentClientLoop-4FCFLMDJ.js → runAgentClientLoop-AF4JQIJ7.js} +72 -71
  167. package/{runtimeDoctorCommands-CXOCVDPU.js → runtimeDoctorCommands-RRKPBGVO.js} +16 -16
  168. package/{secretCommands-GGUAWAE7.js → secretCommands-KZWBZIYS.js} +2 -2
  169. package/{setDialogExtraReferencesAction-YXQTGXIN.js → setDialogExtraReferencesAction-72L27ERM.js} +15 -15
  170. package/{setPrimaryDialogAgentAction-YNLB66WE.js → setPrimaryDialogAgentAction-GJJDUSGJ.js} +19 -19
  171. package/{settingThunks-E6N7RSSS.js → settingThunks-ZRGWVGZD.js} +18 -18
  172. package/{skillDiscovery-B5V23AXP.js → skillDiscovery-BHHPCUHZ.js} +3 -3
  173. package/{spaceCommands-DB5DKC2J.js → spaceCommands-5VNWMDBE.js} +55 -53
  174. package/{store-JRVN62NM.js → store-Z53ICFL3.js} +3 -1
  175. package/{streamAgentChatTurn-FCBGMD4D.js → streamAgentChatTurn-YSPEFY4K.js} +97 -95
  176. package/{switchDialogAgentAction-LAHLUECU.js → switchDialogAgentAction-IIJBPND3.js} +16 -16
  177. package/{tableCommands-VNSXHAMG.js → tableCommands-FTAOCBTX.js} +12 -12
  178. package/{tools-6JD36D6K.js → tools-M35PTIFB.js} +61 -60
  179. package/tuiRestart-2IL37YIB.js +41 -0
  180. package/{tuiSummaryLlmCaller-UHZIPGAX.js → tuiSummaryLlmCaller-W2QN4VAC.js} +21 -21
  181. package/{updateCommands-KZ54HCU5.js → updateCommands-CPATDG6J.js} +8 -6
  182. package/{updateDialogTitleAction-RV3EUEN3.js → updateDialogTitleAction-IMIRJRQQ.js} +36 -35
  183. package/{usageCommand-KFVV6UL3.js → usageCommand-2BF74MKF.js} +2 -2
  184. package/{usageRebuildCommand-HHFSNK46.js → usageRebuildCommand-UHB55BQM.js} +3 -3
  185. package/{windowsSelfUpdate-KERHIAB4.js → windowsSelfUpdate-ZFD6J5HF.js} +2 -2
  186. package/chunk-2WZXXAQD.js +0 -57
  187. package/chunk-BJF2MHJ3.js +0 -118
  188. package/chunk-KEPOVMF4.js +0 -91
  189. package/chunk-PMDVQBGA.js +0 -100
  190. package/chunk-WACI5I6V.js +0 -147
  191. package/{accountResolver-EK2S4PWF.js → accountResolver-QETKNC7T.js} +4 -4
  192. package/{chunk-AGP3YSEC.js → chunk-4N6G2CKP.js} +3 -3
  193. package/{chunk-VXL2FZTP.js → chunk-HXER7YJF.js} +3 -3
  194. package/{chunk-BLVSFYQ3.js → chunk-LISC7BD4.js} +3 -3
  195. package/{chunk-SSGTV4FC.js → chunk-USGHJSGO.js} +5 -5
  196. package/{chunk-IC2I373Q.js → chunk-VS276URX.js} +3 -3
  197. package/{chunk-AETZ7AD6.js → chunk-W6RFEDN4.js} +3 -3
  198. package/{offlineMarxistsAgentCommand-AGA2X5E4.js → offlineMarxistsAgentCommand-XVXUE6G5.js} +5 -5
  199. package/{workloadLifecycle-O2I3NZ2Q.js → workloadLifecycle-HFJIN5IZ.js} +8 -8
@@ -1,18 +1,35 @@
1
+ import {
2
+ resolveObservedSpeed
3
+ } from "./chunk-AMWMV56B.js";
1
4
  import {
2
5
  fnv1a32Hex
3
6
  } from "./chunk-UEILX4EV.js";
4
7
  import {
5
8
  compareAgentSelection,
6
9
  resolveModelTier
7
- } from "./chunk-YOT437BH.js";
10
+ } from "./chunk-MNEZUL5S.js";
8
11
  import {
9
12
  DEFAULT_PROVIDER_RETRY_MS,
10
13
  isAgentUnavailableNow,
11
14
  resolveAgentAvailability
12
- } from "./chunk-HOCHUZQ7.js";
15
+ } from "./chunk-QJTZ76CP.js";
16
+ import {
17
+ LIST_AGENTS_PAGE_BUDGET,
18
+ sanitizeToolOutputText,
19
+ scrubSecrets
20
+ } from "./chunk-WFGNWWJI.js";
13
21
  import {
14
22
  isOAuthApiKeyRef
15
23
  } from "./chunk-UKZX3NHN.js";
24
+ import {
25
+ isOwnedAgentKey,
26
+ ownedAgentKey,
27
+ publicAgentKey
28
+ } from "./chunk-M2EJHDJP.js";
29
+ import {
30
+ createKey,
31
+ createTokenKey
32
+ } from "./chunk-SYTHYBMI.js";
16
33
  import {
17
34
  getModelAbility
18
35
  } from "./chunk-62HXNQVV.js";
@@ -20,12 +37,7 @@ import {
20
37
  isAntigravityOAuthAgent,
21
38
  isSubscriptionEndpoint,
22
39
  isSubscriptionOAuthCredential
23
- } from "./chunk-VPAZ6BEN.js";
24
- import {
25
- isOwnedAgentKey,
26
- ownedAgentKey,
27
- publicAgentKey
28
- } from "./chunk-M2EJHDJP.js";
40
+ } from "./chunk-7JGMNKKG.js";
29
41
  import {
30
42
  asTrimmedLowercaseString
31
43
  } from "./chunk-QSJ3HFEF.js";
@@ -888,6 +900,7 @@ function buildAgentDiscoveryResult(options) {
888
900
  ...typeof limit === "number" ? { limit } : {},
889
901
  ...isTruncated ? { truncated: true } : {},
890
902
  unavailableCount,
903
+ availableCount: sortedAgents.length,
891
904
  agents: projectedAgents,
892
905
  planningRecommendation: recommendPlanning(
893
906
  sortedAgents,
@@ -902,6 +915,498 @@ function toDiscoverySafeAgentSummary(record, options) {
902
915
  return toSafeAgentSummary(record, mergedOptions);
903
916
  }
904
917
 
918
+ // packages/ai/agent/speedSampleCache.ts
919
+ var SPEED_SAMPLE_DISK_CACHE_TTL_MS = 10 * 6e4;
920
+ var SPEED_SAMPLE_SCAN_BUDGET_MS = 2500;
921
+ var SPEED_SAMPLE_CACHE_VERSION = 4;
922
+ var isFiniteNumber = (value) => typeof value === "number" && Number.isFinite(value);
923
+ var sanitizeSample = (value) => {
924
+ if (!value || typeof value !== "object") return null;
925
+ const sample = value;
926
+ const clean = {};
927
+ if (isFiniteNumber(sample.firstOutputMs)) clean.firstOutputMs = sample.firstOutputMs;
928
+ if (isFiniteNumber(sample.callDurationMs)) clean.callDurationMs = sample.callDurationMs;
929
+ if (isFiniteNumber(sample.output_tokens)) clean.output_tokens = sample.output_tokens;
930
+ if (isFiniteNumber(sample.t)) clean.t = sample.t;
931
+ return clean.firstOutputMs === void 0 && clean.callDurationMs === void 0 ? null : clean;
932
+ };
933
+ var SPEED_SAMPLE_STALE_SNAPSHOT_MAX_MS = 7 * 24 * 60 * 6e4;
934
+ async function parseCacheFile(cachePath, userId) {
935
+ try {
936
+ const fs = await import("node:fs/promises");
937
+ const raw = await fs.readFile(cachePath, "utf8");
938
+ const parsed = JSON.parse(raw);
939
+ if (!parsed || typeof parsed !== "object") return null;
940
+ const version = parsed.version;
941
+ if (version !== SPEED_SAMPLE_CACHE_VERSION) {
942
+ return null;
943
+ }
944
+ if (parsed.userId !== userId) return null;
945
+ if (!isFiniteNumber(parsed.at)) return null;
946
+ const source = parsed.samples;
947
+ if (!source || typeof source !== "object") return null;
948
+ const samples = /* @__PURE__ */ new Map();
949
+ for (const [model, list] of Object.entries(source)) {
950
+ if (!model || !Array.isArray(list)) continue;
951
+ const cleaned = [];
952
+ for (const entry of list) {
953
+ const sample = sanitizeSample(entry);
954
+ if (sample) cleaned.push(sample);
955
+ }
956
+ samples.set(model, cleaned);
957
+ }
958
+ const complete = parsed.complete === true;
959
+ const cursor = typeof parsed.cursor === "string" && parsed.cursor.length > 0 ? parsed.cursor : void 0;
960
+ return { samples, at: parsed.at, complete, cursor: complete ? void 0 : cursor };
961
+ } catch {
962
+ return null;
963
+ }
964
+ }
965
+ async function readSpeedSamplesSnapshot(cachePath, options) {
966
+ const maxAgeMs = isFiniteNumber(options.maxAgeMs) ? options.maxAgeMs : SPEED_SAMPLE_STALE_SNAPSHOT_MAX_MS;
967
+ const parsed = await parseCacheFile(cachePath, options.userId);
968
+ if (!parsed || !parsed.complete) return null;
969
+ const age = options.now - parsed.at;
970
+ if (age < 0 || age >= maxAgeMs) return null;
971
+ return { samples: parsed.samples, ageMs: age };
972
+ }
973
+ async function readSpeedSamplesProgress(cachePath, userId) {
974
+ const parsed = await parseCacheFile(cachePath, userId);
975
+ if (!parsed) return null;
976
+ return {
977
+ samples: parsed.samples,
978
+ at: parsed.at,
979
+ complete: parsed.complete,
980
+ ...parsed.cursor === void 0 ? {} : { cursor: parsed.cursor }
981
+ };
982
+ }
983
+ function resolveSpeedSamplesProgressPath(cachePath) {
984
+ return `${cachePath}.progress`;
985
+ }
986
+ async function writeSpeedSamplesCache(cachePath, payload) {
987
+ try {
988
+ const fs = await import("node:fs/promises");
989
+ const path = await import("node:path");
990
+ await fs.mkdir(path.dirname(cachePath), { recursive: true });
991
+ const tmpPath = `${cachePath}.tmp-${process.pid}-${Math.random().toString(36).slice(2, 8)}`;
992
+ await fs.writeFile(tmpPath, JSON.stringify(payload), "utf8");
993
+ await fs.rename(tmpPath, cachePath);
994
+ } catch {
995
+ }
996
+ }
997
+
998
+ // packages/ai/agent/candidateSpeedContext.ts
999
+ var OBSERVED_SPEED_WINDOW = 50;
1000
+ var MIN_OBSERVED_FIRST_OUTPUT_SAMPLES = 5;
1001
+ var SPEED_SAMPLES_CACHE_TTL_MS = 5 * 6e4;
1002
+ var SPEED_SAMPLES_CACHE_MAX_ENTRIES = 500;
1003
+ function normalizeSpeedModelName(raw) {
1004
+ const name = raw.trim().toLowerCase();
1005
+ const slash = name.lastIndexOf("/");
1006
+ return slash === -1 ? name : name.slice(slash + 1);
1007
+ }
1008
+ var isFiniteNumber2 = (value) => typeof value === "number" && Number.isFinite(value);
1009
+ var REASONING_EFFORT_SUFFIXES = ["minimal", "low", "medium", "high", "xhigh"];
1010
+ var REASONING_EFFORT_SUFFIX_RE = new RegExp(`-(?:${REASONING_EFFORT_SUFFIXES.join("|")})$`);
1011
+ function stripReasoningEffortSuffix(model) {
1012
+ const base = model.replace(REASONING_EFFORT_SUFFIX_RE, "");
1013
+ return base && base !== model ? base : null;
1014
+ }
1015
+ function resolveOneBare(model, samplesByModel) {
1016
+ const observed = resolveObservedSpeed(samplesByModel.get(model) ?? [], {
1017
+ limit: OBSERVED_SPEED_WINDOW
1018
+ });
1019
+ if (observed.firstOutputSampleCount >= MIN_OBSERVED_FIRST_OUTPUT_SAMPLES && observed.medianFirstOutputMs !== void 0) {
1020
+ return {
1021
+ source: "observed",
1022
+ firstOutputMs: observed.medianFirstOutputMs,
1023
+ ...observed.medianOutputTokensPerSecond !== void 0 ? { outputTps: observed.medianOutputTokensPerSecond } : {},
1024
+ firstOutputSamples: observed.firstOutputSampleCount,
1025
+ tpsSamples: observed.throughputSampleCount
1026
+ };
1027
+ }
1028
+ return null;
1029
+ }
1030
+ function resolveOne(model, samplesByModel) {
1031
+ const direct = resolveOneBare(model, samplesByModel);
1032
+ if (direct) return { model, ...direct };
1033
+ const base = stripReasoningEffortSuffix(model);
1034
+ if (!base) return null;
1035
+ const stripped = resolveOneBare(base, samplesByModel);
1036
+ return stripped ? { model, ...stripped } : null;
1037
+ }
1038
+ function resolveCandidateSpeedFacts(models, samplesByModel) {
1039
+ const unique = [
1040
+ ...new Set(
1041
+ models.filter((model) => typeof model === "string").map(normalizeSpeedModelName).filter(Boolean)
1042
+ )
1043
+ ];
1044
+ return unique.map((model) => resolveOne(model, samplesByModel)).filter((fact) => fact !== null);
1045
+ }
1046
+ var formatSeconds = (ms) => `${(ms / 1e3).toFixed(1)}s`;
1047
+ var formatTps = (tps) => String(Math.round(tps));
1048
+ 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):";
1049
+ function formatSnapshotAge(ageMs) {
1050
+ const minutes = Math.floor(ageMs / 6e4);
1051
+ if (minutes < 1) return "<1min";
1052
+ if (minutes < 60) return `${minutes}min`;
1053
+ const hours = Math.floor(minutes / 60);
1054
+ if (hours < 24) return `${hours}h`;
1055
+ return `${Math.floor(hours / 24)}d`;
1056
+ }
1057
+ function formatCandidateSpeedFacts(facts, options = {}) {
1058
+ if (facts.length === 0) return null;
1059
+ const lines = facts.map((fact) => {
1060
+ const tps = fact.outputTps !== void 0 ? formatTps(fact.outputTps) : "n/a";
1061
+ return ` ${fact.model}: firstOutput=${formatSeconds(fact.firstOutputMs ?? 0)} tps=${tps} [observed n=${fact.firstOutputSamples ?? 0} tpsN=${fact.tpsSamples ?? 0}]`;
1062
+ });
1063
+ const age = options.snapshotAgeMs;
1064
+ 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)` : "";
1065
+ return `${SPEED_CONTEXT_HEADER}${note}
1066
+ ${lines.join("\n")}`;
1067
+ }
1068
+ function buildCandidateSpeedContext(models, samplesByModel, options = {}) {
1069
+ return formatCandidateSpeedFacts(resolveCandidateSpeedFacts(models, samplesByModel), options);
1070
+ }
1071
+ var SPEED_SAMPLE_PAGE_SIZE = 2e3;
1072
+ var DISPATCH_ENTRY_PATH = "agent-run";
1073
+ var eventTime = (value) => {
1074
+ if (isFiniteNumber2(value.timestamp)) return value.timestamp;
1075
+ if (isFiniteNumber2(value.createdAt)) return value.createdAt;
1076
+ return 0;
1077
+ };
1078
+ function collectSample(collected, value) {
1079
+ if (typeof value.model !== "string") return;
1080
+ if (!isFiniteNumber2(value.firstOutputMs) && !isFiniteNumber2(value.callDurationMs)) return;
1081
+ const model = normalizeSpeedModelName(value.model);
1082
+ if (!model) return;
1083
+ const list = collected.get(model) ?? [];
1084
+ list.push({
1085
+ t: eventTime(value),
1086
+ firstOutputMs: value.firstOutputMs,
1087
+ callDurationMs: value.callDurationMs,
1088
+ output_tokens: value.output_tokens
1089
+ });
1090
+ collected.set(model, list);
1091
+ }
1092
+ function finalizeSamples(collected, keepTime = false) {
1093
+ const result = /* @__PURE__ */ new Map();
1094
+ for (const [model, list] of collected) {
1095
+ list.sort((a, b) => b.t - a.t);
1096
+ const window = list.slice(0, OBSERVED_SPEED_WINDOW);
1097
+ result.set(
1098
+ model,
1099
+ keepTime ? window : window.map(({ t: _t, ...sample }) => sample)
1100
+ );
1101
+ }
1102
+ return result;
1103
+ }
1104
+ async function collectRecentSpeedSamples(db, userId, options = {}) {
1105
+ const pageSize = isFiniteNumber2(options.pageSize) && options.pageSize > 0 ? Math.floor(options.pageSize) : SPEED_SAMPLE_PAGE_SIZE;
1106
+ const budgetMs = isFiniteNumber2(options.budgetMs) ? options.budgetMs : Number.POSITIVE_INFINITY;
1107
+ const { start, end } = createTokenKey.rangeOfUser(userId);
1108
+ const failedPrefix = createKey("token", userId, "failed-call", "");
1109
+ const dispatchRunCache = /* @__PURE__ */ new Map();
1110
+ const isDispatchSampleRecord = async (record, resolver, cache) => {
1111
+ if (record.entry_path !== DISPATCH_ENTRY_PATH && record.entry_path !== "cli-local") return false;
1112
+ const runId = typeof record.dialogId === "string" ? record.dialogId.trim() : "";
1113
+ if (!runId) return false;
1114
+ const cacheKey = `${record.entry_path}:${runId}`;
1115
+ const cached = cache.get(cacheKey);
1116
+ if (cached !== void 0) return cached;
1117
+ let dispatch = false;
1118
+ if (resolver) {
1119
+ try {
1120
+ dispatch = await resolver(runId, record.entry_path) === true;
1121
+ } catch {
1122
+ dispatch = false;
1123
+ }
1124
+ }
1125
+ cache.set(cacheKey, dispatch);
1126
+ return dispatch;
1127
+ };
1128
+ const collected = /* @__PURE__ */ new Map();
1129
+ const startedAt = Date.now();
1130
+ let lastKey = options.startAfter;
1131
+ let budgetExhausted = false;
1132
+ let scanned = 0;
1133
+ while (true) {
1134
+ if (Date.now() - startedAt >= budgetMs) {
1135
+ budgetExhausted = true;
1136
+ break;
1137
+ }
1138
+ const pageOptions = {
1139
+ ...lastKey === void 0 ? { gte: start } : { gt: lastKey },
1140
+ lte: end,
1141
+ limit: pageSize
1142
+ };
1143
+ let accepted = 0;
1144
+ let newestKey = lastKey;
1145
+ for await (const [key, raw] of db.iterator(pageOptions)) {
1146
+ if (typeof key !== "string") continue;
1147
+ if (lastKey !== void 0 && key <= lastKey) continue;
1148
+ accepted += 1;
1149
+ scanned += 1;
1150
+ newestKey = key;
1151
+ if (key.startsWith(failedPrefix)) continue;
1152
+ if (!raw || typeof raw !== "object") continue;
1153
+ const record = raw;
1154
+ const resolver = options.isDispatchRun ?? db.isDispatchRun;
1155
+ if (!await isDispatchSampleRecord(
1156
+ record,
1157
+ resolver ? (runId, entryPath) => resolver.call(db, runId, entryPath) : void 0,
1158
+ dispatchRunCache
1159
+ ))
1160
+ continue;
1161
+ collectSample(collected, record);
1162
+ }
1163
+ if (accepted === 0 || accepted < pageSize) break;
1164
+ lastKey = newestKey;
1165
+ }
1166
+ return {
1167
+ samples: finalizeSamples(collected, options.keepTime === true),
1168
+ budgetExhausted,
1169
+ scanned,
1170
+ ...budgetExhausted && lastKey !== void 0 ? { nextCursor: lastKey } : {}
1171
+ };
1172
+ }
1173
+ function mergeNewestSamples(into, from) {
1174
+ for (const [model, list] of from) {
1175
+ const merged = [...into.get(model) ?? [], ...list];
1176
+ merged.sort(
1177
+ (a, b) => (b.t ?? 0) - (a.t ?? 0)
1178
+ );
1179
+ into.set(model, merged.slice(0, OBSERVED_SPEED_WINDOW));
1180
+ }
1181
+ }
1182
+ async function loadSpeedSamplesWithDiskCache(db, userId, now, cache) {
1183
+ try {
1184
+ const ttlMs = isFiniteNumber2(cache.ttlMs) ? cache.ttlMs : SPEED_SAMPLE_DISK_CACHE_TTL_MS;
1185
+ const snapshot = await readSpeedSamplesSnapshot(cache.cachePath, { userId, now });
1186
+ if (snapshot && snapshot.ageMs < ttlMs) return { samples: snapshot.samples };
1187
+ const progressPath = resolveSpeedSamplesProgressPath(cache.cachePath);
1188
+ const progress = await readSpeedSamplesProgress(progressPath, userId);
1189
+ const resumable = progress && !progress.complete && progress.cursor ? progress : void 0;
1190
+ const collected = new Map(resumable?.samples ?? []);
1191
+ let step;
1192
+ try {
1193
+ step = await collectRecentSpeedSamples(db, userId, {
1194
+ pageSize: cache.pageSize,
1195
+ budgetMs: isFiniteNumber2(cache.budgetMs) ? cache.budgetMs : SPEED_SAMPLE_SCAN_BUDGET_MS,
1196
+ keepTime: true,
1197
+ ...resumable?.cursor ? { startAfter: resumable.cursor } : {}
1198
+ });
1199
+ } catch {
1200
+ return snapshot ? { samples: snapshot.samples, snapshotAgeMs: snapshot.ageMs } : { samples: /* @__PURE__ */ new Map() };
1201
+ }
1202
+ if (!resumable && step.scanned === 0 && !step.budgetExhausted) {
1203
+ return snapshot ? { samples: snapshot.samples, snapshotAgeMs: snapshot.ageMs } : { samples: /* @__PURE__ */ new Map() };
1204
+ }
1205
+ mergeNewestSamples(collected, step.samples);
1206
+ if (!step.budgetExhausted) {
1207
+ await writeSpeedSamplesCache(cache.cachePath, {
1208
+ version: SPEED_SAMPLE_CACHE_VERSION,
1209
+ userId,
1210
+ at: now,
1211
+ complete: true,
1212
+ samples: Object.fromEntries(collected)
1213
+ });
1214
+ await writeSpeedSamplesCache(progressPath, {
1215
+ version: SPEED_SAMPLE_CACHE_VERSION,
1216
+ userId,
1217
+ at: now,
1218
+ complete: true,
1219
+ samples: {}
1220
+ });
1221
+ return { samples: collected };
1222
+ }
1223
+ await writeSpeedSamplesCache(progressPath, {
1224
+ version: SPEED_SAMPLE_CACHE_VERSION,
1225
+ userId,
1226
+ // Progress keeps the cycle's collection start so a later stale label stays honest.
1227
+ at: resumable?.at ?? now,
1228
+ complete: false,
1229
+ samples: Object.fromEntries(collected),
1230
+ ...step.nextCursor ? { cursor: step.nextCursor } : {}
1231
+ });
1232
+ return snapshot ? { samples: snapshot.samples, snapshotAgeMs: snapshot.ageMs } : { samples: /* @__PURE__ */ new Map() };
1233
+ } catch {
1234
+ return { samples: /* @__PURE__ */ new Map() };
1235
+ }
1236
+ }
1237
+ var samplesCache = /* @__PURE__ */ new Map();
1238
+ function writeSamplesCache(userId, now, samples) {
1239
+ for (const [key, entry] of samplesCache) {
1240
+ if (now - entry.at >= SPEED_SAMPLES_CACHE_TTL_MS) samplesCache.delete(key);
1241
+ }
1242
+ samplesCache.delete(userId);
1243
+ samplesCache.set(userId, { at: now, samples });
1244
+ while (samplesCache.size > SPEED_SAMPLES_CACHE_MAX_ENTRIES) {
1245
+ const oldest = samplesCache.keys().next().value;
1246
+ if (oldest === void 0) break;
1247
+ samplesCache.delete(oldest);
1248
+ }
1249
+ }
1250
+ var SPEED_SAMPLE_REFRESH_BUDGET_MS = 6e4;
1251
+ var snapshotRefreshes = /* @__PURE__ */ new Map();
1252
+ function startSpeedSnapshotRefresh(db, userId, now = Date.now()) {
1253
+ const inFlight = snapshotRefreshes.get(userId);
1254
+ if (inFlight) return inFlight;
1255
+ const job = (async () => {
1256
+ try {
1257
+ const { samples, budgetExhausted } = await collectRecentSpeedSamples(db, userId, {
1258
+ budgetMs: SPEED_SAMPLE_REFRESH_BUDGET_MS
1259
+ });
1260
+ if (!budgetExhausted) writeSamplesCache(userId, now, samples);
1261
+ } catch {
1262
+ }
1263
+ })().finally(() => {
1264
+ snapshotRefreshes.delete(userId);
1265
+ });
1266
+ snapshotRefreshes.set(userId, job);
1267
+ return job;
1268
+ }
1269
+ async function loadCachedSpeedSamples(db, userId, now) {
1270
+ const hit = samplesCache.get(userId);
1271
+ if (hit) {
1272
+ const age = now - hit.at;
1273
+ if (age >= 0 && age < SPEED_SAMPLE_STALE_SNAPSHOT_MAX_MS) {
1274
+ if (age >= SPEED_SAMPLES_CACHE_TTL_MS) void startSpeedSnapshotRefresh(db, userId);
1275
+ return age >= SPEED_SAMPLES_CACHE_TTL_MS ? { samples: hit.samples, snapshotAgeMs: age } : { samples: hit.samples };
1276
+ }
1277
+ }
1278
+ void startSpeedSnapshotRefresh(db, userId);
1279
+ return { samples: /* @__PURE__ */ new Map() };
1280
+ }
1281
+ async function injectSpeedContextIntoListAgentsResult(result, options = {}) {
1282
+ try {
1283
+ let parsed;
1284
+ try {
1285
+ parsed = JSON.parse(result);
1286
+ } catch {
1287
+ return result;
1288
+ }
1289
+ if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.agents)) return result;
1290
+ const models = parsed.agents.map((agent) => agent?.model).filter((model) => typeof model === "string");
1291
+ if (models.length === 0 && !options.compactPage) return result;
1292
+ const now = options.now ?? Date.now();
1293
+ let samples = /* @__PURE__ */ new Map();
1294
+ let snapshotAgeMs;
1295
+ const userId = typeof options.userId === "string" ? options.userId.trim() : "";
1296
+ if (options.db && userId) {
1297
+ try {
1298
+ const loaded = options.diskCache ? await loadSpeedSamplesWithDiskCache(options.db, userId, now, options.diskCache) : await loadCachedSpeedSamples(options.db, userId, now);
1299
+ samples = loaded.samples;
1300
+ snapshotAgeMs = loaded.snapshotAgeMs;
1301
+ } catch {
1302
+ samples = /* @__PURE__ */ new Map();
1303
+ }
1304
+ }
1305
+ if (options.compactPage) {
1306
+ return await serializeCompactAgentPage(parsed, samples, snapshotAgeMs, options);
1307
+ }
1308
+ const speedContext = buildCandidateSpeedContext(models, samples, { snapshotAgeMs });
1309
+ return speedContext ? JSON.stringify({ ...parsed, speedContext }) : result;
1310
+ } catch {
1311
+ return options.compactPage ? JSON.stringify({ success: false, error: "LIST_AGENTS_PAGE_SERIALIZATION_FAILED" }) : result;
1312
+ }
1313
+ }
1314
+ async function serializeCompactAgentPage(parsed, samples, snapshotAgeMs, options) {
1315
+ const maxChars = LIST_AGENTS_PAGE_BUDGET;
1316
+ const maxBytes = LIST_AGENTS_PAGE_BUDGET;
1317
+ const fits = (page) => page.length <= maxChars && new TextEncoder().encode(page).length <= maxBytes;
1318
+ const offset = typeof parsed.offset === "number" ? parsed.offset : 0;
1319
+ const candidates = parsed.agents;
1320
+ const availableCount = typeof parsed.availableCount === "number" ? parsed.availableCount : parsed.total;
1321
+ const groups = Array.isArray(parsed.credentialGroups) ? parsed.credentialGroups : [];
1322
+ if (options.fragmentOffset !== void 0) {
1323
+ const fragmentOffset = Number(options.fragmentOffset);
1324
+ const agentKey2 = candidates[0]?.agentKey;
1325
+ if (typeof options.fragmentOffset !== "number" && (typeof options.fragmentOffset !== "string" || !/^\d+$/.test(options.fragmentOffset)) || !Number.isSafeInteger(fragmentOffset) || fragmentOffset < 0 || typeof agentKey2 !== "string" || agentKey2 !== options.fragmentAgentKey) {
1326
+ return JSON.stringify({ success: false, error: "LIST_AGENTS_FRAGMENT_INVALID", offset });
1327
+ }
1328
+ const agent = candidates[0];
1329
+ const speedContext = buildCandidateSpeedContext(typeof agent.model === "string" ? [agent.model] : [], samples, { snapshotAgeMs });
1330
+ const payload = { agent, credentialGroups: groups.filter((group) => group.credentialGroup === agent.credentialGroup), ...speedContext ? { speedContext } : {} };
1331
+ let keyCollision = false;
1332
+ const cleanText = (value) => scrubSecrets(sanitizeToolOutputText(value)).cleaned;
1333
+ const sanitize = (value) => {
1334
+ if (typeof value === "string") return cleanText(value);
1335
+ if (Array.isArray(value)) return value.map(sanitize);
1336
+ if (value && typeof value === "object") {
1337
+ const entries = [];
1338
+ const keys = /* @__PURE__ */ new Set();
1339
+ for (const [key, item] of Object.entries(value)) {
1340
+ const cleanedKey = cleanText(key);
1341
+ if (keys.has(cleanedKey)) keyCollision = true;
1342
+ keys.add(cleanedKey);
1343
+ entries.push([cleanedKey, sanitize(item)]);
1344
+ }
1345
+ return Object.fromEntries(entries);
1346
+ }
1347
+ return value;
1348
+ };
1349
+ const safePayload = sanitize(payload);
1350
+ if (keyCollision) return JSON.stringify({ success: false, error: "LIST_AGENTS_SANITIZED_KEY_COLLISION", offset });
1351
+ const serialized = JSON.stringify(safePayload);
1352
+ const bytes = new TextEncoder().encode(serialized);
1353
+ const hash = await globalThis.crypto.subtle.digest("SHA-256", bytes);
1354
+ const digest = Array.from(new Uint8Array(hash), (byte) => byte.toString(16).padStart(2, "0")).join("");
1355
+ if (fragmentOffset > 0 && !options.fragmentDigest || options.fragmentDigest && options.fragmentDigest !== digest) {
1356
+ return JSON.stringify({ success: false, error: "LIST_AGENTS_FRAGMENT_CHANGED", offset });
1357
+ }
1358
+ if (fragmentOffset >= serialized.length) return JSON.stringify({ success: false, error: "LIST_AGENTS_FRAGMENT_INVALID", offset });
1359
+ 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 });
1360
+ let end = Math.min(serialized.length, fragmentOffset + 3e3);
1361
+ if (end < serialized.length && /[\uD800-\uDBFF]/.test(serialized[end - 1]) && /[\uDC00-\uDFFF]/.test(serialized[end])) end--;
1362
+ const fragment = serialized.slice(fragmentOffset, end);
1363
+ const result = JSON.stringify({ success: true, agentKey: agentKey2, offset, digest, fragment, fragmentOffset, nextFragmentOffset: end, hasMoreFragments: end < serialized.length, nextOffset: offset + 1 });
1364
+ return fits(result) ? result : JSON.stringify({ success: false, error: "LIST_AGENTS_FRAGMENT_METADATA_TOO_LARGE", offset });
1365
+ }
1366
+ const makePage = (count) => {
1367
+ const agents = candidates.slice(0, count);
1368
+ const groupKeys = new Set(agents.map((agent) => agent.credentialGroup).filter(Boolean));
1369
+ const speedContext = buildCandidateSpeedContext(agents.map((agent) => agent.model).filter((model) => typeof model === "string"), samples, { snapshotAgeMs });
1370
+ const nextOffset = offset + count;
1371
+ const hasMore = nextOffset < availableCount;
1372
+ return JSON.stringify({
1373
+ ...parsed,
1374
+ offset,
1375
+ agents,
1376
+ credentialGroups: groups.filter((group) => groupKeys.has(group.credentialGroup)),
1377
+ hasMore,
1378
+ ...hasMore ? { nextOffset } : {},
1379
+ ...speedContext ? { speedContext } : {}
1380
+ });
1381
+ };
1382
+ if (!candidates.length) {
1383
+ const empty = makePage(0);
1384
+ if (fits(empty)) return empty;
1385
+ } else {
1386
+ let best;
1387
+ for (let count = 1; count <= candidates.length; count++) {
1388
+ const page = makePage(count);
1389
+ if (!fits(page)) break;
1390
+ best = page;
1391
+ }
1392
+ if (best) return best;
1393
+ }
1394
+ const agentKey = typeof candidates[0]?.agentKey === "string" ? candidates[0].agentKey : void 0;
1395
+ const error = {
1396
+ success: false,
1397
+ error: candidates.length ? "LIST_AGENTS_CANDIDATE_TOO_LARGE" : "LIST_AGENTS_PAGE_METADATA_TOO_LARGE",
1398
+ offset,
1399
+ ...agentKey ? { agentKey, recovery: {
1400
+ tool: "listAgents",
1401
+ arguments: { compact: true, offset, fragmentOffset: 0, fragmentAgentKey: agentKey },
1402
+ note: "Repeat with the same filters and returned digest and nextFragmentOffset; concatenate fragments and parse JSON before continuing at nextOffset."
1403
+ } } : {},
1404
+ ...candidates.length ? { nextOffset: offset + 1, truncated: parsed.truncated === true, poolComplete: parsed.planningRecommendation?.poolComplete === true, hasMore: offset + 1 < availableCount } : {}
1405
+ };
1406
+ const encoded = JSON.stringify(error);
1407
+ return fits(encoded) ? encoded : JSON.stringify({ success: false, error: "LIST_AGENTS_RECOVERY_ID_TOO_LARGE", offset });
1408
+ }
1409
+
905
1410
  export {
906
1411
  isGptProModel,
907
1412
  shouldBlockForGptPro,
@@ -913,5 +1418,6 @@ export {
913
1418
  resolvePaginationArgs,
914
1419
  matchesAgentQuery,
915
1420
  buildAgentDiscoveryResult,
916
- toDiscoverySafeAgentSummary
1421
+ toDiscoverySafeAgentSummary,
1422
+ injectSpeedContextIntoListAgentsResult
917
1423
  };
@@ -4,10 +4,19 @@ import {
4
4
  resolvePlatformHostedCredentialProvider,
5
5
  resolvePlatformProxyChatGatewayEndpoint,
6
6
  resolvePlatformResponsesEndpoint
7
- } from "./chunk-45LZIYXB.js";
7
+ } from "./chunk-HBRDSQ3M.js";
8
+ import {
9
+ asTrimmedString
10
+ } from "./chunk-3EUW3WEO.js";
8
11
  import {
9
12
  CLI_PROVIDER_VALUES
10
13
  } from "./chunk-JRTNUU5Z.js";
14
+ import {
15
+ asOptionalTrimmedString
16
+ } from "./chunk-G3SUCT4W.js";
17
+ import {
18
+ normalizeServerOrigin
19
+ } from "./chunk-CF7PE763.js";
11
20
  import {
12
21
  CLIENT_VERSION_TOO_OLD_CODE,
13
22
  buildClientVersionGateErrorDetail,
@@ -16,15 +25,6 @@ import {
16
25
  import {
17
26
  asTrimmedLowercaseString
18
27
  } from "./chunk-QSJ3HFEF.js";
19
- import {
20
- normalizeServerOrigin
21
- } from "./chunk-CF7PE763.js";
22
- import {
23
- asTrimmedString
24
- } from "./chunk-3EUW3WEO.js";
25
- import {
26
- asOptionalTrimmedString
27
- } from "./chunk-G3SUCT4W.js";
28
28
 
29
29
  // packages/agent-runtime/agentConfigOptions.ts
30
30
  function pickAgentRuntimeInferenceOptions(agentConfig) {
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-OQHIVPG4.js";
4
4
  import {
5
5
  t
6
- } from "./chunk-OB6DVWPF.js";
6
+ } from "./chunk-262R3XNN.js";
7
7
 
8
8
  // packages/core/secretsStore.ts
9
9
  import {
@@ -4,20 +4,20 @@ import {
4
4
  import {
5
5
  getApproxPricePerImage
6
6
  } from "./chunk-4JH2UMJR.js";
7
+ import {
8
+ asOptionalPositiveFiniteNumber
9
+ } from "./chunk-U6VC4MU4.js";
7
10
  import {
8
11
  getModelConfig
9
- } from "./chunk-KYH7XW3K.js";
12
+ } from "./chunk-CD3RU7XL.js";
13
+ import {
14
+ asOptionalFiniteNumber
15
+ } from "./chunk-WWC7I6TA.js";
10
16
  import {
11
17
  isPlatformHostedImageModel,
12
18
  isPlatformManagedProvider,
13
19
  resolvePlatformEffectiveModel
14
20
  } from "./chunk-OBSEKCVK.js";
15
- import {
16
- asOptionalPositiveFiniteNumber
17
- } from "./chunk-U6VC4MU4.js";
18
- import {
19
- asOptionalFiniteNumber
20
- } from "./chunk-WWC7I6TA.js";
21
21
 
22
22
  // packages/ai/llm/getPricing.ts
23
23
  var MAX_OUTPUT_TOKENS = 8192;
@@ -1,23 +1,24 @@
1
- import {
2
- buildLocalAgentLookupKeys
3
- } from "./chunk-CLCXHIBS.js";
4
- import {
5
- LOCAL_CODEX_AGENT_ID,
6
- LOCAL_CODEX_AGENT_KEY
7
- } from "./chunk-BR3GT6MR.js";
8
1
  import {
9
2
  applyPublicAgentCatalogOverride
10
- } from "./chunk-UVUVQVZ6.js";
3
+ } from "./chunk-DBUR22G5.js";
11
4
  import {
12
5
  applyBuiltinAgentRuntimeOverride,
13
6
  resolveBuiltinPlatformAgentConfig
14
7
  } from "./chunk-S6K5F3KP.js";
15
8
  import {
16
- localDialogMessageRecordToRuntimeMessage
17
- } from "./chunk-CVERLOJM.js";
9
+ buildLocalAgentLookupKeys
10
+ } from "./chunk-OJ45MEEI.js";
11
+ import {
12
+ LOCAL_CODEX_AGENT_ID,
13
+ LOCAL_CODEX_AGENT_KEY
14
+ } from "./chunk-BR3GT6MR.js";
15
+ import {
16
+ localDialogMessageRecordToRuntimeMessage,
17
+ orderDialogHistory
18
+ } from "./chunk-3QIYD3VM.js";
18
19
  import {
19
20
  resolveAgentRuntimeConfigFromRecord
20
- } from "./chunk-C2B7M567.js";
21
+ } from "./chunk-XAG3FWBE.js";
21
22
  import {
22
23
  dialogMessagePrefix,
23
24
  dialogMessageRange
@@ -86,7 +87,7 @@ async function readDialogMessages(args) {
86
87
  const message = localDialogMessageRecordToRuntimeMessage(entry.record);
87
88
  if (message) messages.push({ ...message, cliMessageId: entry.messageId });
88
89
  }
89
- return messages;
90
+ return orderDialogHistory(messages);
90
91
  }
91
92
 
92
93
  export {