nolo-cli 0.32.0 → 0.33.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 (170) hide show
  1. package/README.md +6 -12
  2. package/{_executeModel-LTMSIBS4.js → _executeModel-RWPVI3YV.js} +76 -67
  3. package/{action-HI3VRQLP.js → action-SMLG6OTB.js} +17 -15
  4. package/{addContentAction-NCURJ6PK.js → addContentAction-SFO244QN.js} +14 -13
  5. package/{addDialogAgentAction-RCY4ECF4.js → addDialogAgentAction-W44ZCEHB.js} +14 -13
  6. package/{agentDeleteCommand-D3MYZK6E.js → agentDeleteCommand-KU2RXQPP.js} +42 -59
  7. package/{agentEmailCommands-6BXS574I.js → agentEmailCommands-MPCMDENS.js} +89 -80
  8. package/{agentGrantCommands-E7ZZFRHK.js → agentGrantCommands-2LEZDADN.js} +2 -2
  9. package/{agentListCommands-SF3HEUTT.js → agentListCommands-EPD4N6FX.js} +73 -78
  10. package/{agentMachineCommands-YARVXRR6.js → agentMachineCommands-AF7C3YRT.js} +40 -57
  11. package/{agentPullCommand-ARSIDNVC.js → agentPullCommand-YH5GEBK4.js} +5 -5
  12. package/agentRecordCommands-EYE6MZZG.js +112 -0
  13. package/agentRunCommand-LL22SGTN.js +130 -0
  14. package/{agentRuntimeLocal-ATGJY6WC.js → agentRuntimeLocal-JX34G47Z.js} +35 -50
  15. package/{agentSlice-4XWW344Y.js → agentSlice-TNMFQQOV.js} +15 -13
  16. package/{appDeleteCommands-63JO7RXS.js → appDeleteCommands-43K5VXQB.js} +38 -55
  17. package/{appDeployCommands-Y7EWYUGM.js → appDeployCommands-FEEJSVDZ.js} +38 -55
  18. package/{appDeployStatusCommands-ZBEY3DWB.js → appDeployStatusCommands-H76CG45R.js} +38 -55
  19. package/{appGetCommands-QSSOSEYL.js → appGetCommands-MDZYFTYZ.js} +38 -55
  20. package/{appListCommands-PH3XWNDX.js → appListCommands-TUJJXPWG.js} +38 -55
  21. package/{authCommand-BBDHMSO6.js → authCommand-T7UK4CWS.js} +18 -18
  22. package/{authCommands-4UDEKRE6.js → authCommands-EAPFGNHN.js} +8 -8
  23. package/chatQueueReduxAdapter-LVQXC4ZY.js +180 -0
  24. package/chunk-2H3XIBY4.js +239 -0
  25. package/{chunk-TEYN42N3.js → chunk-2IVEXF7P.js} +11 -4
  26. package/{chunk-WTGCTVJG.js → chunk-2QTEYCR7.js} +3 -6
  27. package/{chunk-DOISARTV.js → chunk-2UECQ7RE.js} +1 -1
  28. package/{chunk-SWYMCHM7.js → chunk-37V5LNEQ.js} +69 -1
  29. package/{chunk-E3APEOIM.js → chunk-3GZXL6FM.js} +4 -19
  30. package/{chunk-O3JR45Q2.js → chunk-3VAQHAXT.js} +44 -44
  31. package/{chunk-O5OMJPPF.js → chunk-3WXRAHCG.js} +6 -5
  32. package/{chunk-LAXMH7JY.js → chunk-57QJXIB6.js} +18 -15
  33. package/chunk-5CS33IBL.js +301 -0
  34. package/{chunk-3UGKATZQ.js → chunk-5SBK2MTI.js} +8 -369
  35. package/chunk-6PO2SYCS.js +1800 -0
  36. package/{chunk-TA6EA2A3.js → chunk-6SXC35F4.js} +182 -20
  37. package/{chunk-MXFQHRSS.js → chunk-6XIE5ZGI.js} +1 -1
  38. package/{chunk-3GZT3L6F.js → chunk-73GINUCW.js} +326 -481
  39. package/{chunk-VMWR7VNI.js → chunk-7E72JMBB.js} +7 -7
  40. package/{chunk-4PNU7W7K.js → chunk-AAGCMVFT.js} +106 -124
  41. package/chunk-ADLYMQB6.js +642 -0
  42. package/{chunk-ZWJOGMKH.js → chunk-AETZ7AD6.js} +1 -1
  43. package/{chunk-UDA3ZYLW.js → chunk-AFV4FOT2.js} +70 -24
  44. package/{chunk-BGTUGS3T.js → chunk-AOXVOC6D.js} +4 -30
  45. package/{chunk-2ZRP5RUG.js → chunk-B2BSG6QQ.js} +12 -11
  46. package/{chunk-44HACRCK.js → chunk-BANYWEYY.js} +4 -4
  47. package/{chunk-TOW4E763.js → chunk-BJIRLHJR.js} +2 -0
  48. package/{chunk-ZJ2WITOO.js → chunk-BQXOGBFN.js} +2 -2
  49. package/{chunk-G5GVZAXF.js → chunk-CLP2K7U4.js} +15 -19
  50. package/{chunk-2K4NDPT5.js → chunk-DFUPZE6V.js} +20 -12
  51. package/{chunk-YHGHADBQ.js → chunk-DPMBNHOJ.js} +4 -4
  52. package/chunk-EGRJC4ZN.js +91 -0
  53. package/{chunk-K6QEHQZ3.js → chunk-EKLRRZIN.js} +1 -1
  54. package/{chunk-XFG3BAKN.js → chunk-FMEVI5TG.js} +65 -0
  55. package/{chunk-RH53LMEJ.js → chunk-FSSX3XRY.js} +2 -4
  56. package/{chunk-VP4WJWKW.js → chunk-GM6PU7B6.js} +431 -345
  57. package/{chunk-EEF23OOK.js → chunk-GMXWYXAF.js} +7 -7
  58. package/{chunk-SFWZUTCI.js → chunk-GTYM4HKV.js} +1 -1
  59. package/{chunk-MITD7CON.js → chunk-HDKRSRYU.js} +1461 -301
  60. package/chunk-HS7MLR74.js +38 -0
  61. package/{chunk-3AUWC6EM.js → chunk-HUCT7HID.js} +5 -84
  62. package/{chunk-PTHDLIRB.js → chunk-I6N2UVVY.js} +1 -1
  63. package/chunk-IDAU4UFS.js +437 -0
  64. package/{chunk-Q76I4SXI.js → chunk-IHEC7VBF.js} +1 -1
  65. package/{chunk-OWHNFZNW.js → chunk-IL545V3E.js} +4 -4
  66. package/{chunk-3LY4F7SV.js → chunk-INZZJSQF.js} +348 -331
  67. package/{chunk-CF2WZF4N.js → chunk-J6WH4PYZ.js} +0 -8
  68. package/{chunk-2HXKAPH7.js → chunk-JMPYDFHY.js} +6 -6
  69. package/{chunk-V54H24CQ.js → chunk-JTSGWTYZ.js} +3 -3
  70. package/{chunk-ATK5WJOA.js → chunk-JZ5AMMXU.js} +4 -4
  71. package/chunk-KHCLMKZZ.js +3062 -0
  72. package/{chunk-WHLVPK32.js → chunk-KMSZPTM6.js} +27 -3
  73. package/{chunk-L3GCUVOH.js → chunk-KSRFVP36.js} +1 -1
  74. package/{chunk-DLWCWUNW.js → chunk-LOD75GOS.js} +336 -32
  75. package/{chunk-UOJRKY5J.js → chunk-M2YMQOLC.js} +44 -53
  76. package/chunk-M3JEW6N6.js +193 -0
  77. package/{chunk-XDHHF73Q.js → chunk-M4NC7NF6.js} +95 -95
  78. package/{chunk-3FCNXC2J.js → chunk-MPZJVZDC.js} +3735 -1394
  79. package/{chunk-IXZX5CJK.js → chunk-MQRZ5QUH.js} +1 -1
  80. package/{chunk-3ASDTTEI.js → chunk-MRWGHF56.js} +2 -0
  81. package/{chunk-D34RI6NI.js → chunk-NNWHHCVP.js} +75 -1
  82. package/{chunk-6YABCOFU.js → chunk-NUO3QFWD.js} +1 -1
  83. package/{chunk-GAF5X6B7.js → chunk-O6GEBMIY.js} +269 -309
  84. package/{chunk-CAENRKNJ.js → chunk-OR2HNLVO.js} +126 -88
  85. package/chunk-OW765XBU.js +10 -0
  86. package/chunk-PREQU5QV.js +231 -0
  87. package/{chunk-Q3CSL43H.js → chunk-Q5ITEGIN.js} +1 -1
  88. package/{chunk-7S54ZGF6.js → chunk-RAZOLMJR.js} +256 -12
  89. package/chunk-RCFIB45Q.js +28 -0
  90. package/chunk-RY57GLGW.js +188 -0
  91. package/{chunk-KGEVMUMI.js → chunk-TFPUAELY.js} +11 -11
  92. package/{chunk-ZJH3LKEW.js → chunk-UK5JGQVU.js} +94 -15
  93. package/chunk-URMS4XY2.js +10 -0
  94. package/{chunk-RXVX5LFR.js → chunk-VH2F7ZB6.js} +1 -1
  95. package/chunk-VIDPVFP3.js +20 -0
  96. package/{chunk-W367V5CH.js → chunk-WHD6BG7M.js} +400 -115
  97. package/{chunk-5RDLGLAP.js → chunk-WJSW43QZ.js} +4 -7
  98. package/{chunk-CF7S2RYZ.js → chunk-WLH5BAKX.js} +6 -6
  99. package/{chunk-VVEH6XUE.js → chunk-X2DAEZ3X.js} +1 -1
  100. package/{chunk-2IJAKBK2.js → chunk-X664KVEV.js} +426 -246
  101. package/{chunk-43EPBPZ2.js → chunk-XCCGU6QB.js} +2 -2
  102. package/chunk-Y5GCAMGP.js +9 -0
  103. package/{chunk-V42OE5HT.js → chunk-YDTYDA5W.js} +3 -3
  104. package/chunk-YYLHWIW6.js +48 -0
  105. package/{chunk-AOS5IN2I.js → chunk-ZHYK3N56.js} +1 -1
  106. package/{chunk-ODS2MVMU.js → chunk-ZJMME4DS.js} +19 -303
  107. package/{chunk-PJ2DDQQM.js → chunk-ZURFOV5J.js} +2 -2
  108. package/chunk-ZZ2MH7LE.js +84 -0
  109. package/{cliExecutor-BBUVQU4L.js → cliExecutor-DW3PHGEL.js} +2 -2
  110. package/{clipboardy-BVE3LVEH.js → clipboardy-MMBYVRLF.js} +166 -372
  111. package/{codingSkills-V35TRR4Y.js → codingSkills-DY5MINPG.js} +5 -4
  112. package/{createAgentAutomationAction-WLRNE7C4.js → createAgentAutomationAction-INQT23LX.js} +40 -31
  113. package/createDialogAction-LDCPDI73.js +60 -0
  114. package/{createPageAction-7YROVZ3W.js → createPageAction-5YXOG2M4.js} +56 -47
  115. package/{db-6DPSJ6WT.js → db-3H3JECGY.js} +45 -5
  116. package/{dbSlice-BBL3PEVW.js → dbSlice-3SD5L5H2.js} +13 -12
  117. package/{deleteFile-RJTEPOT4.js → deleteFile-XQXPBFFB.js} +7 -6
  118. package/dialogCommands-CHJO47AX.js +81 -0
  119. package/{dialogSlice-N4HPG6HM.js → dialogSlice-DOWKOILN.js} +36 -29
  120. package/{docCreateCommands-GRA5BHSA.js → docCreateCommands-OVZARUFX.js} +40 -55
  121. package/{docDeleteCommands-ONIJM5MD.js → docDeleteCommands-E2XJ62LD.js} +42 -57
  122. package/{docReadCommands-H55VQ2US.js → docReadCommands-I7OSREPJ.js} +40 -55
  123. package/{docStore-B5AHDNW5.js → docStore-UAWSKZ2Y.js} +39 -30
  124. package/{docUpdateCommands-ZQIQVGC2.js → docUpdateCommands-X4Z26VJM.js} +43 -58
  125. package/{fetchMessages-VPPQDDZ4.js → fetchMessages-7QRCCRYK.js} +3 -3
  126. package/{getPricing-QO5TYNCK.js → getPricing-L2ENXWHV.js} +7 -6
  127. package/{handleSendMessageAction-IN5XX5U7.js → handleSendMessageAction-C3TSDWKH.js} +38 -31
  128. package/index.js +67 -67
  129. package/{lib-FYYBQIXS.js → lib-2ZTNRXR4.js} +432 -183
  130. package/{localDialogRead-3DBXVYXS.js → localDialogRead-SLMPV5SK.js} +2 -2
  131. package/{localRuntimeAuthority-NDUA2D7Y.js → localRuntimeAuthority-E3R24J4T.js} +4 -2
  132. package/{localRuntimeDb-GKYRBWLQ.js → localRuntimeDb-DDZCJFQZ.js} +1 -1
  133. package/{machineCommands-H3UMKE76.js → machineCommands-BUOIYJAD.js} +93 -84
  134. package/{machineWsRunDispatch-HONRUK3R.js → machineWsRunDispatch-7CRWAA6O.js} +83 -74
  135. package/{models-WDUTTYFS.js → models-OX2S5C6Q.js} +2 -2
  136. package/{offlineMarxistsAgentCommand-E6LUG63A.js → offlineMarxistsAgentCommand-GEH6SNNA.js} +1 -1
  137. package/package.json +1 -4
  138. package/{read-64OQDO3I.js → read-6G73BMEY.js} +8 -7
  139. package/{readDocTool-MXM3T6PE.js → readDocTool-DK4EI2GA.js} +1 -2
  140. package/{readlineWorkspace-XVJZDCSC.js → readlineWorkspace-ZDWEASJV.js} +265 -428
  141. package/{removeDialogAgentAction-NEKVAMSH.js → removeDialogAgentAction-E7H557UO.js} +19 -17
  142. package/{runAgentClientLoop-H7U53QB6.js → runAgentClientLoop-U7HYA3O5.js} +72 -64
  143. package/{runtimeDoctorCommands-WI2YZUSJ.js → runtimeDoctorCommands-KIKM6BIO.js} +5 -5
  144. package/{setDialogExtraReferencesAction-WTOHQDIV.js → setDialogExtraReferencesAction-RMMGBR5F.js} +15 -14
  145. package/{setPrimaryDialogAgentAction-LDJOYC4F.js → setPrimaryDialogAgentAction-FWBKKLVA.js} +19 -17
  146. package/{settingSlice-4M37TN7V.js → settingSlice-73PV4KG4.js} +16 -14
  147. package/{skillDiscovery-5U6RYAHN.js → skillDiscovery-KLLKXPUO.js} +4 -4
  148. package/{slateUtils-2M7MUTWX.js → slateUtils-VO2FU36K.js} +1 -1
  149. package/{spaceCommands-7VVKJBDV.js → spaceCommands-GEWZXGHM.js} +43 -240
  150. package/{spaceSlice-T6YK6D34.js → spaceSlice-B6MOVY4N.js} +38 -61
  151. package/{streamAgentChatTurn-RQ63QFQ7.js → streamAgentChatTurn-T527EQTT.js} +1261 -150
  152. package/{switchDialogAgentAction-XVWGKR2Z.js → switchDialogAgentAction-US6QNL3N.js} +14 -13
  153. package/syncMapping-RK2MANUX.js +43 -0
  154. package/{tableCommands-RJZ3V4TF.js → tableCommands-QE47K72R.js} +8 -7
  155. package/{toolApiClient-ARGFDJAG.js → toolApiClient-B2MFXMEG.js} +3 -3
  156. package/tools-XMWCVMPM.js +98 -0
  157. package/{tuiSummaryLlmCaller-SRZ4QQUP.js → tuiSummaryLlmCaller-NCAJSVSD.js} +24 -21
  158. package/{updateDialogTitleAction-BBDSWHNG.js → updateDialogTitleAction-XPJZRJEL.js} +48 -38
  159. package/agentRecordCommands-JFZRQJQ4.js +0 -103
  160. package/agentRunCommand-NOX5FLKO.js +0 -121
  161. package/chunk-AYMOSAHE.js +0 -3158
  162. package/chunk-D2BPX6DQ.js +0 -1707
  163. package/chunk-DCDL3GC4.js +0 -171
  164. package/chunk-F3MP7CP6.js +0 -73
  165. package/chunk-WZSRQNQG.js +0 -2587
  166. package/createDialogAction-Y6YV64QB.js +0 -52
  167. package/dialogCommands-XLO5CAHZ.js +0 -95
  168. package/tools-KYZX3BGO.js +0 -90
  169. package/{chunk-Z5MXSEOJ.js → chunk-RQSOAMPJ.js} +2 -2
  170. package/{chunk-JDSUTNYY.js → chunk-SAQQLJZ5.js} +3 -3
@@ -1,22 +1,22 @@
1
1
  import {
2
- BUILTIN_SUMMARY_LLM_CONFIG,
3
- COMPACTION_SUMMARY_SYSTEM_PROMPT,
4
- buildCompactionMetricsFromPlan,
5
- buildCompactionUserContent,
6
- estimateTokenCount,
7
- formatCompactionMetricsLog,
8
- formatFileOperationsFromMessages,
9
- formatMessagesForSummaryWithTruncation,
10
- normalizeAssistantContentBuffer,
11
- planCompression,
12
- serializeMessageContent
13
- } from "./chunk-BGTUGS3T.js";
2
+ BUILTIN_SUMMARY_LLM_CONFIG
3
+ } from "./chunk-RCFIB45Q.js";
14
4
  import {
15
- cleanupCliSessionForDialog
16
- } from "./chunk-ATK5WJOA.js";
5
+ buildDialogAttachmentPlan,
6
+ extractFileContentIds
7
+ } from "./chunk-EGRJC4ZN.js";
8
+ import {
9
+ isOAuthApiKeyRef
10
+ } from "./chunk-YYLHWIW6.js";
11
+ import {
12
+ getApproxPricePerImage
13
+ } from "./chunk-CWMSB67P.js";
17
14
  import {
18
15
  runLlm
19
- } from "./chunk-ODS2MVMU.js";
16
+ } from "./chunk-ZJMME4DS.js";
17
+ import {
18
+ cleanupCliSessionForDialog
19
+ } from "./chunk-JZ5AMMXU.js";
20
20
  import {
21
21
  getActiveDialogAgentId,
22
22
  getDialogAgentIds,
@@ -26,8 +26,32 @@ import {
26
26
  require_date_fns
27
27
  } from "./chunk-M76ECQRD.js";
28
28
  import {
29
- toErrorMessage
30
- } from "./chunk-HNMXYYJR.js";
29
+ fetchMessages
30
+ } from "./chunk-KSRFVP36.js";
31
+ import {
32
+ DEFAULT_AUTO_EXECUTION_PROFILE,
33
+ DEFAULT_CONTEXT_WINDOW,
34
+ getModelContextWindow,
35
+ getModelInfo,
36
+ resolveAutoExecutionProfile,
37
+ resolveBuiltinPlatformAgentRecord
38
+ } from "./chunk-2H3XIBY4.js";
39
+ import {
40
+ COMPACTION_SUMMARY_SYSTEM_PROMPT,
41
+ buildCompactionMetricsFromPlan,
42
+ buildCompactionUserContent,
43
+ estimateTokenCount,
44
+ formatCompactionMetricsLog,
45
+ formatFileOperationsFromMessages,
46
+ formatMessagesForSummaryWithTruncation,
47
+ normalizeAssistantContentBuffer,
48
+ planCompression,
49
+ serializeMessageContent
50
+ } from "./chunk-AOXVOC6D.js";
51
+ import {
52
+ findModelConfig,
53
+ getModelConfig
54
+ } from "./chunk-DFUPZE6V.js";
31
55
  import {
32
56
  abortActiveControllers,
33
57
  addPageReferenceToRuntime,
@@ -42,25 +66,17 @@ import {
42
66
  selectCurrentDialogKey,
43
67
  setActiveDialogKey,
44
68
  setDialogConfigError
45
- } from "./chunk-3ASDTTEI.js";
69
+ } from "./chunk-MRWGHF56.js";
46
70
  import {
47
- ALL_MODELS
48
- } from "./chunk-WTGCTVJG.js";
49
- import {
50
- getApproxPricePerImage
51
- } from "./chunk-CWMSB67P.js";
52
- import {
53
- MODEL_LOOKUP_MAP,
54
- findModelConfig,
55
- getModelConfig
56
- } from "./chunk-2K4NDPT5.js";
71
+ toErrorMessage
72
+ } from "./chunk-HNMXYYJR.js";
57
73
  import {
58
74
  getPlatformHostedDeepSeekV4Price,
59
75
  isPlatformHostedDeepSeekV4Model
60
- } from "./chunk-CAENRKNJ.js";
76
+ } from "./chunk-OR2HNLVO.js";
61
77
  import {
62
78
  nolotusId
63
- } from "./chunk-G5GVZAXF.js";
79
+ } from "./chunk-CLP2K7U4.js";
64
80
  import {
65
81
  asRecordOrEmpty
66
82
  } from "./chunk-KX6YBIHG.js";
@@ -70,19 +86,27 @@ import {
70
86
  remove,
71
87
  selectById,
72
88
  write
73
- } from "./chunk-LAXMH7JY.js";
89
+ } from "./chunk-57QJXIB6.js";
74
90
  import {
75
- asTrimmedLowercaseString
76
- } from "./chunk-QSJ3HFEF.js";
91
+ buildDialogAgentListIndexDeleteOps,
92
+ createDialogMessageKeyAndId,
93
+ createKey,
94
+ createTokenKey,
95
+ createTokenStatsKey,
96
+ dialogMessageKey,
97
+ isDialogRecordKey,
98
+ isPageKey,
99
+ isTableMetaKey
100
+ } from "./chunk-KMSZPTM6.js";
77
101
  import {
78
- PUBLIC_DEEPSEEK_V4_FLASH_AGENT_KEY,
79
- builtinRuntimeFallbackEntries
80
- } from "./chunk-ZJH3LKEW.js";
102
+ asOptionalFiniteNumber
103
+ } from "./chunk-WWC7I6TA.js";
81
104
  import {
82
- extractCustomId,
83
- extractUserId,
84
- publicAgentKey
85
- } from "./chunk-TOW4E763.js";
105
+ asTrimmedNonEmptyStringArray
106
+ } from "./chunk-I42VC5KR.js";
107
+ import {
108
+ asTrimmedLowercaseString
109
+ } from "./chunk-QSJ3HFEF.js";
86
110
  import {
87
111
  asyncThunkCreator,
88
112
  buildCreateSlice,
@@ -93,28 +117,11 @@ import {
93
117
  parseOwnerUserIdFromDbKey,
94
118
  scheduleDeleteReplication,
95
119
  selectIdentityUserId
96
- } from "./chunk-2IJAKBK2.js";
120
+ } from "./chunk-X664KVEV.js";
97
121
  import {
98
122
  createClientLogger,
99
123
  isAbortError
100
- } from "./chunk-5RDLGLAP.js";
101
- import {
102
- fetchMessages
103
- } from "./chunk-L3GCUVOH.js";
104
- import {
105
- buildDialogAgentListIndexDeleteOps,
106
- createDialogMessageKeyAndId,
107
- createKey,
108
- createTokenKey,
109
- createTokenStatsKey,
110
- dialogMessageKey,
111
- isDialogRecordKey,
112
- isPageKey,
113
- isTableMetaKey
114
- } from "./chunk-WHLVPK32.js";
115
- import {
116
- asOptionalFiniteNumber
117
- } from "./chunk-WWC7I6TA.js";
124
+ } from "./chunk-WJSW43QZ.js";
118
125
  import {
119
126
  isTombstoneRecord,
120
127
  shouldReplaceWithNextRecord
@@ -122,12 +129,13 @@ import {
122
129
  import {
123
130
  asTrimmedString
124
131
  } from "./chunk-3EUW3WEO.js";
132
+ import {
133
+ extractCustomId,
134
+ extractUserId
135
+ } from "./chunk-BJIRLHJR.js";
125
136
  import {
126
137
  isRecord
127
138
  } from "./chunk-KUG52IAP.js";
128
- import {
129
- asTrimmedNonEmptyStringArray
130
- } from "./chunk-I42VC5KR.js";
131
139
  import {
132
140
  asOptionalTrimmedString
133
141
  } from "./chunk-G3SUCT4W.js";
@@ -1224,112 +1232,6 @@ var fetchAndCacheMessages = async (options) => {
1224
1232
  return remotePromise;
1225
1233
  };
1226
1234
 
1227
- // packages/ai/llm/getModelContextWindow.ts
1228
- var DEFAULT_CONTEXT_WINDOW = 256e3;
1229
- var QWEN_3_6_CONTEXT_WINDOW = 262144;
1230
- var GLM_5_2_CONTEXT_WINDOW = 1e6;
1231
- var ANTIGRAVITY_EFFORT_SUFFIXES = [
1232
- "-tiered",
1233
- "-extra-low",
1234
- "-low",
1235
- "-medium",
1236
- "-high"
1237
- ];
1238
- function stripEffortSuffix(model) {
1239
- for (const suffix of ANTIGRAVITY_EFFORT_SUFFIXES) {
1240
- if (model.endsWith(suffix) && model.length > suffix.length) {
1241
- return model.slice(0, -suffix.length);
1242
- }
1243
- }
1244
- return model;
1245
- }
1246
- function stripPreviewSuffix(model) {
1247
- const suffix = "-preview";
1248
- if (model.endsWith(suffix) && model.length > suffix.length) {
1249
- return model.slice(0, -suffix.length);
1250
- }
1251
- return model;
1252
- }
1253
- var fullModelMap = null;
1254
- var getFullModelMap = () => {
1255
- if (!fullModelMap) {
1256
- fullModelMap = /* @__PURE__ */ new Map();
1257
- for (const [provider, models] of Object.entries(MODEL_LOOKUP_MAP)) {
1258
- for (const model of models) {
1259
- const entry = { ...model, provider };
1260
- fullModelMap.set(model.name, entry);
1261
- if (model.displayName) {
1262
- fullModelMap.set(model.displayName.toLowerCase(), entry);
1263
- }
1264
- }
1265
- }
1266
- }
1267
- return fullModelMap;
1268
- };
1269
- var legacyModelMap = null;
1270
- var getLegacyModelMap = () => {
1271
- if (!legacyModelMap) {
1272
- legacyModelMap = /* @__PURE__ */ new Map();
1273
- for (const model of ALL_MODELS) {
1274
- legacyModelMap.set(model.name, model);
1275
- if (model.displayName) {
1276
- legacyModelMap.set(model.displayName.toLowerCase(), model);
1277
- }
1278
- }
1279
- }
1280
- return legacyModelMap;
1281
- };
1282
- function fuzzyContextWindow(normalizedName) {
1283
- if (normalizedName.includes("qwen-long") || normalizedName.includes("qwen3-long")) return 10485760;
1284
- if (normalizedName.includes("qwen-coder") || normalizedName.includes("qwen3-coder")) return 1048576;
1285
- if (normalizedName.includes("qwen3.8") || normalizedName.includes("qwen3p8")) return 1e6;
1286
- if (normalizedName.includes("minimax-m3") || normalizedName.includes("minimax_m3")) return 1e6;
1287
- if (normalizedName.includes("glm-5.2") || normalizedName.includes("glm5.2")) return GLM_5_2_CONTEXT_WINDOW;
1288
- if (normalizedName.includes("deepseek")) return 1e6;
1289
- if (normalizedName.includes("gpt-5") || normalizedName.includes("gpt-4.1")) return 1047576;
1290
- if (normalizedName.startsWith("cursor-grok-4.5")) return 1e6;
1291
- if (normalizedName.includes("claude-4.6")) return 1e6;
1292
- if (normalizedName.includes("gemini-3.1")) return 1e6;
1293
- if (normalizedName.includes("gemini")) return 1048576;
1294
- if (normalizedName.includes("qwen3.6") || normalizedName.includes("qwen3p6")) return QWEN_3_6_CONTEXT_WINDOW;
1295
- if (normalizedName.includes("qwen3.7") || normalizedName.includes("qwen3p7")) return 262144;
1296
- if (normalizedName.includes("minimax-m2") || normalizedName.includes("minimax_m2")) return 262144;
1297
- if (normalizedName.includes("claude")) return 2e5;
1298
- return void 0;
1299
- }
1300
- var getModelContextWindow = (modelName) => {
1301
- if (!modelName) return DEFAULT_CONTEXT_WINDOW;
1302
- const normalizedName = modelName.toLowerCase();
1303
- const map = getFullModelMap();
1304
- const candidates = [modelName, normalizedName];
1305
- const strippedEffort = stripEffortSuffix(modelName);
1306
- if (strippedEffort !== modelName) {
1307
- candidates.push(strippedEffort, strippedEffort.toLowerCase());
1308
- }
1309
- const strippedPreview = stripPreviewSuffix(modelName);
1310
- if (strippedPreview !== modelName) {
1311
- candidates.push(strippedPreview, strippedPreview.toLowerCase());
1312
- }
1313
- if (strippedEffort !== modelName) {
1314
- const strippedBoth = stripPreviewSuffix(strippedEffort);
1315
- if (strippedBoth !== strippedEffort) {
1316
- candidates.push(strippedBoth, strippedBoth.toLowerCase());
1317
- }
1318
- }
1319
- for (const candidate of candidates) {
1320
- const model = map.get(candidate);
1321
- if (model?.contextWindow) {
1322
- return typeof model.contextWindow === "number" ? model.contextWindow : DEFAULT_CONTEXT_WINDOW;
1323
- }
1324
- }
1325
- return fuzzyContextWindow(normalizedName) ?? DEFAULT_CONTEXT_WINDOW;
1326
- };
1327
- var getModelInfo = (modelName) => {
1328
- if (!modelName) return null;
1329
- const map = getLegacyModelMap();
1330
- return map.get(modelName) || map.get(modelName.toLowerCase()) || null;
1331
- };
1332
-
1333
1235
  // packages/chat/messages/parseJsonRecord.ts
1334
1236
  function asOptionalJsonRecord(value) {
1335
1237
  if (typeof value === "string") {
@@ -1741,84 +1643,6 @@ var buildPersonalizationDialogPolicyContext = () => [
1741
1643
  "\u9664\u975E\u7528\u6237\u660E\u786E\u8981\u6C42\uFF0C\u5426\u5219\u4E0D\u8981\u521B\u5EFA\u6587\u6863\uFF0C\u4E0D\u8981\u521B\u5EFA\u6216\u4FEE\u6539\u4EFB\u4F55 agent\u3002"
1742
1644
  ].join("\n");
1743
1645
 
1744
- // packages/agent-runtime/autoExecutionProfiles.ts
1745
- var createProfile = (input) => ({
1746
- id: input.id,
1747
- tier: input.tier,
1748
- legacyAgentKey: input.legacyAgentKey,
1749
- key: input.legacyAgentKey,
1750
- name: input.name,
1751
- provider: "nolo",
1752
- model: input.model,
1753
- apiSource: "platform",
1754
- useServerProxy: true,
1755
- rawRecord: {
1756
- dbKey: input.legacyAgentKey,
1757
- isPublic: true,
1758
- provider: "nolo",
1759
- model: input.model,
1760
- apiSource: "platform",
1761
- useServerProxy: true
1762
- }
1763
- });
1764
- var FLASH_PROFILE = createProfile({
1765
- id: "builtin:auto:deepseek-v4-flash",
1766
- tier: "flash",
1767
- legacyAgentKey: PUBLIC_DEEPSEEK_V4_FLASH_AGENT_KEY,
1768
- name: "DeepSeek V4 Flash",
1769
- model: "deepseek-v4-flash"
1770
- });
1771
- var AUTO_EXECUTION_PROFILES = {
1772
- flash: FLASH_PROFILE,
1773
- balanced: { ...FLASH_PROFILE, tier: "balanced" },
1774
- quality: { ...FLASH_PROFILE, tier: "quality" },
1775
- image: { ...FLASH_PROFILE, tier: "image" }
1776
- };
1777
- var DEFAULT_AUTO_EXECUTION_TIER = "flash";
1778
- var DEFAULT_AUTO_EXECUTION_PROFILE = AUTO_EXECUTION_PROFILES[DEFAULT_AUTO_EXECUTION_TIER];
1779
- var resolveAutoExecutionProfile = (tier) => AUTO_EXECUTION_PROFILES[tier ?? DEFAULT_AUTO_EXECUTION_TIER] ?? DEFAULT_AUTO_EXECUTION_PROFILE;
1780
-
1781
- // packages/agent-runtime/builtinPlatformAgentConfigs.ts
1782
- function buildConfig(e) {
1783
- const key = publicAgentKey(e.id);
1784
- const rawRecord = {
1785
- dbKey: key,
1786
- isPublic: true,
1787
- provider: e.provider,
1788
- model: e.model,
1789
- apiSource: e.apiSource ?? "platform",
1790
- useServerProxy: e.useServerProxy ?? true
1791
- };
1792
- if (e.hasImageOutput) rawRecord.hasImageOutput = true;
1793
- if (e.imageModel) rawRecord.imageModel = e.imageModel;
1794
- if (e.imageWorkflow) rawRecord.imageWorkflow = e.imageWorkflow;
1795
- if (e.imageConfig) rawRecord.imageConfig = e.imageConfig;
1796
- return {
1797
- key,
1798
- name: e.name,
1799
- provider: e.provider,
1800
- model: e.model,
1801
- apiSource: e.apiSource ?? "platform",
1802
- useServerProxy: e.useServerProxy ?? true,
1803
- rawRecord
1804
- };
1805
- }
1806
- var BUILTIN_PLATFORM_AGENT_CONFIGS = Object.fromEntries(
1807
- builtinRuntimeFallbackEntries().map((e) => [publicAgentKey(e.id), buildConfig(e)])
1808
- );
1809
- function resolveBuiltinPlatformAgentConfig(agentRef) {
1810
- return BUILTIN_PLATFORM_AGENT_CONFIGS[agentRef] ?? null;
1811
- }
1812
- function resolveBuiltinPlatformAgentRecord(agentRef) {
1813
- const config = resolveBuiltinPlatformAgentConfig(agentRef);
1814
- if (!config) return null;
1815
- return {
1816
- ...config.rawRecord,
1817
- dbKey: agentRef,
1818
- ...config.name ? { name: config.name } : {}
1819
- };
1820
- }
1821
-
1822
1646
  // packages/chat/dialog/dialogAgentPolicy.ts
1823
1647
  var resolveDialogAgentMode = (dialog) => {
1824
1648
  if (dialog?.agentMode === "auto") return "auto";
@@ -1882,13 +1706,13 @@ function assemblePersistedUserMessage(input) {
1882
1706
  dialogKey,
1883
1707
  currentAccountUserId
1884
1708
  });
1885
- const { key: messageDbKey2, messageId } = createDialogMessageKeyAndId(
1709
+ const { key: messageDbKey, messageId } = createDialogMessageKeyAndId(
1886
1710
  dialogId
1887
1711
  );
1888
1712
  const fullMessage = {
1889
1713
  ...message,
1890
1714
  id: messageId,
1891
- dbKey: messageDbKey2,
1715
+ dbKey: messageDbKey,
1892
1716
  userId
1893
1717
  };
1894
1718
  return { fullMessage, dialogId, dialogKey };
@@ -2589,6 +2413,60 @@ function resolveStreamEndPostWritePolicy(input) {
2589
2413
  };
2590
2414
  }
2591
2415
 
2416
+ // packages/chat/messages/messageStreamEndBillingDispatch.ts
2417
+ async function dispatchStreamEndBilling(input) {
2418
+ const {
2419
+ dispatch,
2420
+ updateTokensAction: updateTokensAction2,
2421
+ billingMode,
2422
+ billingUsageRecords,
2423
+ billedUsage,
2424
+ billedEstimatedUsage,
2425
+ dialogId,
2426
+ dialogKey,
2427
+ agentConfig
2428
+ } = input;
2429
+ try {
2430
+ if (billingMode === "reported") {
2431
+ const usageRecords = billingUsageRecords?.length ? billingUsageRecords : [{ callId: void 0, usage: billedUsage }];
2432
+ for (const usageRecord of usageRecords) {
2433
+ await dispatch(
2434
+ updateTokensAction2({
2435
+ dialogId,
2436
+ dialogKey,
2437
+ usageRecord,
2438
+ agentConfig
2439
+ })
2440
+ ).unwrap();
2441
+ }
2442
+ } else if (billingMode === "estimated") {
2443
+ await dispatch(
2444
+ updateTokensAction2({
2445
+ dialogId,
2446
+ dialogKey,
2447
+ usage: billedEstimatedUsage,
2448
+ agentConfig
2449
+ })
2450
+ ).unwrap();
2451
+ console.warn(
2452
+ "[billing] Missing usage at messageStreamEnd; using estimated token update",
2453
+ {
2454
+ dialogId,
2455
+ dialogKey,
2456
+ provider: agentConfig.provider,
2457
+ model: agentConfig.model,
2458
+ endpointKey: agentConfig.endpointKey
2459
+ }
2460
+ );
2461
+ }
2462
+ } catch (billingError) {
2463
+ console.error(
2464
+ "[billing] updateTokens failed (best-effort, message already saved):",
2465
+ billingError
2466
+ );
2467
+ }
2468
+ }
2469
+
2592
2470
  // packages/chat/messages/messageStreamEndPersistPrep.ts
2593
2471
  function prepareStreamEndPersistInputs(input) {
2594
2472
  const { totalUsage, agentConfig, messageMetadata } = input;
@@ -3370,35 +3248,17 @@ var messageSlice = createSliceWithThunks({
3370
3248
  textContent,
3371
3249
  toolCalls
3372
3250
  });
3373
- if (billingMode === "reported") {
3374
- const usageRecords = billingUsageRecords?.length ? billingUsageRecords : [{ callId: void 0, usage: billedUsage }];
3375
- for (const usageRecord of usageRecords) {
3376
- await dispatch(
3377
- updateTokens({
3378
- dialogId,
3379
- dialogKey,
3380
- usageRecord,
3381
- agentConfig
3382
- })
3383
- ).unwrap();
3384
- }
3385
- } else if (billingMode === "estimated") {
3386
- await dispatch(
3387
- updateTokens({
3388
- dialogId,
3389
- dialogKey,
3390
- usage: billedEstimatedUsage,
3391
- agentConfig
3392
- })
3393
- ).unwrap();
3394
- console.warn("[billing] Missing usage at messageStreamEnd; using estimated token update", {
3395
- dialogId,
3396
- dialogKey,
3397
- provider: agentConfig.provider,
3398
- model: agentConfig.model,
3399
- endpointKey: agentConfig.endpointKey
3400
- });
3401
- }
3251
+ await dispatchStreamEndBilling({
3252
+ dispatch,
3253
+ updateTokensAction: updateTokens,
3254
+ billingMode,
3255
+ billingUsageRecords,
3256
+ billedUsage,
3257
+ billedEstimatedUsage,
3258
+ dialogId,
3259
+ dialogKey,
3260
+ agentConfig
3261
+ });
3402
3262
  if (updateTitle) {
3403
3263
  dispatch(updateDialogTitle({ dialogKey, agentConfig }));
3404
3264
  }
@@ -3584,7 +3444,7 @@ var messageSlice = createSliceWithThunks({
3584
3444
  runtimeOptions: args.runtimeOptions
3585
3445
  });
3586
3446
  if (agentKeyToUse) {
3587
- const { streamAgentChatTurn } = await import("./agentSlice-4XWW344Y.js");
3447
+ const { streamAgentChatTurn } = await import("./agentSlice-TNMFQQOV.js");
3588
3448
  await dispatch(
3589
3449
  streamAgentChatTurn({
3590
3450
  agentKey: agentKeyToUse,
@@ -3977,7 +3837,7 @@ var calculateOpenRouterFallbackCost = (resolvedPrice, usage, externalPrice) => {
3977
3837
  }
3978
3838
  return calculateSimpleCost(resolvedPrice, usage, externalPrice);
3979
3839
  };
3980
- var API_REPORTED_COST_MULTIPLIER = 7;
3840
+ var API_REPORTED_COST_MULTIPLIER = 8;
3981
3841
  var zeroCostBreakdown = () => ({
3982
3842
  regular: 0,
3983
3843
  charge: 0,
@@ -4027,8 +3887,10 @@ var calculateBasicCost = (model, usage, provider, externalPrice, billingServiceT
4027
3887
  case "deepinfra":
4028
3888
  return calculateCacheBasedCost(resolvedPrice, usage, externalPrice);
4029
3889
  // nolo/crof: honor inputCacheHit only when the model defines it (K3 has
4030
- // inputCacheHit=2). Models without it (e.g. K2.6) keep simple full-price
4031
- // billing so cached tokens are not priced at 0.
3890
+ // inputCacheHit=2, K2.6 has 0.32 from its OpenRouter upstream). Models
3891
+ // without it keep simple full-price billing so cached tokens are not
3892
+ // priced at 0 — but a platform-hosted model用于 agentic 循环时必须补上
3893
+ // 这一项,否则每轮重放的上下文会被按 input 原价重复计费。
4032
3894
  case "nolo":
4033
3895
  case "crof":
4034
3896
  return typeof resolvedPrice.inputCacheHit === "number" ? calculateCacheBasedCost(resolvedPrice, usage, externalPrice) : calculateSimpleCost(resolvedPrice, usage, externalPrice);
@@ -4265,47 +4127,42 @@ var resolveBillingTarget = ({
4265
4127
  };
4266
4128
  };
4267
4129
 
4268
- // packages/agent-runtime/serverProxyPolicy.ts
4269
- var OAUTH_APIKEY_REFS = /* @__PURE__ */ new Set([
4270
- "antigravity",
4271
- "xai",
4272
- "chatgpt",
4273
- "claude",
4274
- "cursor"
4275
- ]);
4276
- function isGoogleFamilyProvider(provider) {
4277
- const normalized = asTrimmedLowercaseString(provider);
4278
- return normalized === "google" || normalized.startsWith("google-");
4279
- }
4280
- function isOAuthApiKeyRef(value) {
4281
- const ref = asTrimmedLowercaseString(value);
4282
- return ref.length > 0 && OAUTH_APIKEY_REFS.has(ref);
4283
- }
4284
- function shouldUseServerProxy(agentConfig, requestProvider) {
4285
- const effectiveProvider = (requestProvider || agentConfig.provider || "").toLowerCase();
4286
- if (isGoogleFamilyProvider(effectiveProvider)) {
4287
- return true;
4288
- }
4289
- if (isOAuthApiKeyRef(agentConfig.apiKeyRef)) {
4290
- return true;
4291
- }
4292
- if (agentConfig.apiSource === "custom" && isRemoteCustomEndpoint(agentConfig.customProviderUrl)) {
4293
- return true;
4294
- }
4295
- return !!agentConfig.useServerProxy;
4296
- }
4297
- var LOCAL_HOSTS = /* @__PURE__ */ new Set(["127.0.0.1", "localhost", "::1", "0.0.0.0"]);
4298
- function isRemoteCustomEndpoint(url) {
4299
- if (typeof url !== "string") return false;
4300
- try {
4301
- const host = new URL(url).hostname.toLowerCase();
4302
- return !LOCAL_HOSTS.has(host);
4303
- } catch {
4304
- return false;
4305
- }
4306
- }
4307
-
4308
4130
  // packages/ai/token/prepareTokenUsageData.ts
4131
+ function resolveTokenUsagePricing(args) {
4132
+ const { rawUsage, agentConfig, nowMs } = args;
4133
+ const usage = normalizeUsage(rawUsage);
4134
+ const billingTarget = resolveBillingTarget({
4135
+ usage,
4136
+ fallbackProvider: agentConfig.provider,
4137
+ fallbackModel: agentConfig.model
4138
+ });
4139
+ const billedProvider = billingTarget.provider;
4140
+ const billedModel = billingTarget.model;
4141
+ const billedServiceTier = billingTarget.serviceTier;
4142
+ const hasExternalPrice = agentConfig.inputPrice !== void 0 && agentConfig.inputPrice > 0 || agentConfig.outputPrice !== void 0 && agentConfig.outputPrice > 0;
4143
+ const { cost, pay } = calculatePrice({
4144
+ provider: billedProvider,
4145
+ modelName: billedModel,
4146
+ billingServiceTier: billedServiceTier,
4147
+ usage,
4148
+ externalPrice: hasExternalPrice ? {
4149
+ input: agentConfig.inputPrice ?? 0,
4150
+ output: agentConfig.outputPrice ?? 0,
4151
+ creatorId: agentConfig.userId ?? (agentConfig.id ? extractUserId(agentConfig.id) : "")
4152
+ } : void 0,
4153
+ sharingLevel: agentConfig.sharingLevel,
4154
+ nowMs
4155
+ });
4156
+ return {
4157
+ usage,
4158
+ billedProvider,
4159
+ billedModel,
4160
+ billedServiceTier,
4161
+ cost,
4162
+ pay,
4163
+ hasExternalPrice
4164
+ };
4165
+ }
4309
4166
  function resolveBillable(input) {
4310
4167
  const uid = input.userId?.trim();
4311
4168
  if (!uid || uid === "local") return false;
@@ -4318,6 +4175,18 @@ function resolveBillable(input) {
4318
4175
  if (apiSource == null || apiSource === "") return true;
4319
4176
  return false;
4320
4177
  }
4178
+ function resolveBillableForAgent(input) {
4179
+ const { usage, cost, userId, agentConfig } = input;
4180
+ const hasExternalPrice = input.hasExternalPrice ?? (agentConfig.inputPrice !== void 0 && agentConfig.inputPrice > 0 || agentConfig.outputPrice !== void 0 && agentConfig.outputPrice > 0);
4181
+ return resolveBillable({
4182
+ usage,
4183
+ userId,
4184
+ apiSource: agentConfig.apiSource,
4185
+ apiKeyRef: agentConfig.apiKeyRef,
4186
+ cost,
4187
+ hasExternalPrice
4188
+ });
4189
+ }
4321
4190
  var prepareTokenUsageData = ({
4322
4191
  rawUsage,
4323
4192
  agentConfig,
@@ -4337,36 +4206,17 @@ var prepareTokenUsageData = ({
4337
4206
  "prepareTokenUsageData requires a non-empty agentId or cybotId"
4338
4207
  );
4339
4208
  }
4340
- const usage = normalizeUsage(rawUsage);
4341
- const billingTarget = resolveBillingTarget({
4342
- usage,
4343
- fallbackProvider: agentConfig.provider,
4344
- fallbackModel: agentConfig.model
4345
- });
4346
- const billedProvider = billingTarget.provider;
4347
- const billedModel = billingTarget.model;
4348
- const billedServiceTier = billingTarget.serviceTier;
4349
- const recordProvider = billedProvider ?? agentConfig.provider ?? "unknown";
4350
- const hasExternalPrice = agentConfig.inputPrice !== void 0 && agentConfig.inputPrice > 0 || agentConfig.outputPrice !== void 0 && agentConfig.outputPrice > 0;
4351
- const { cost, pay } = calculatePrice({
4352
- provider: billedProvider,
4353
- modelName: billedModel,
4354
- billingServiceTier: billedServiceTier,
4355
- usage,
4356
- externalPrice: hasExternalPrice ? {
4357
- input: agentConfig.inputPrice ?? 0,
4358
- output: agentConfig.outputPrice ?? 0,
4359
- creatorId: agentConfig.userId ?? (agentConfig.id ? extractUserId(agentConfig.id) : "")
4360
- } : void 0,
4361
- sharingLevel: agentConfig.sharingLevel,
4209
+ const { usage, billedProvider, billedModel, billedServiceTier, cost, pay, hasExternalPrice } = resolveTokenUsagePricing({
4210
+ rawUsage,
4211
+ agentConfig,
4362
4212
  nowMs: timestamp
4363
4213
  });
4364
- const billable = resolveBillable({
4214
+ const recordProvider = billedProvider ?? agentConfig.provider ?? "unknown";
4215
+ const billable = resolveBillableForAgent({
4365
4216
  usage,
4366
- userId,
4367
- apiSource: agentConfig.apiSource,
4368
- apiKeyRef: agentConfig.apiKeyRef,
4369
4217
  cost,
4218
+ userId,
4219
+ agentConfig,
4370
4220
  hasExternalPrice
4371
4221
  });
4372
4222
  return {
@@ -4397,27 +4247,83 @@ var prepareTokenUsageData = ({
4397
4247
  };
4398
4248
 
4399
4249
  // packages/ai/token/applyTokenUsageToDayStats.ts
4400
- var ZERO_STATS = { count: 0, tokens: { input: 0, output: 0 }, cost: 0 };
4401
- function applyTokenUsageToDayStats(prev, delta) {
4402
- const base = prev ?? {
4403
- userId: delta.userId,
4404
- period: "day",
4405
- timeKey: delta.timeKey,
4406
- total: { ...ZERO_STATS },
4407
- models: {},
4408
- providers: {}
4409
- };
4410
- const modelName = delta.model || "unknown";
4411
- const providerName = delta.provider || "unknown";
4412
- const inc = (s) => ({
4413
- count: (s?.count ?? 0) + 1,
4250
+ var ZERO_STATS = {
4251
+ count: 0,
4252
+ tokens: { input: 0, output: 0, cacheRead: 0, cacheCreation: 0 },
4253
+ cost: 0,
4254
+ failedCount: 0
4255
+ };
4256
+ function normalizeStats(s) {
4257
+ if (!s) return { ...ZERO_STATS };
4258
+ const t = s.tokens;
4259
+ return {
4260
+ count: s.count ?? 0,
4414
4261
  tokens: {
4415
- input: (s?.tokens.input ?? 0) + delta.input_tokens,
4416
- output: (s?.tokens.output ?? 0) + delta.output_tokens
4262
+ input: t?.input ?? 0,
4263
+ output: t?.output ?? 0,
4264
+ cacheRead: t?.cacheRead ?? t?.cache_read ?? 0,
4265
+ cacheCreation: t?.cacheCreation ?? t?.cache_creation ?? 0
4417
4266
  },
4418
- cost: Number(((s?.cost ?? 0) + delta.cost).toFixed(6))
4419
- });
4267
+ cost: s.cost ?? 0,
4268
+ failedCount: s.failedCount ?? 0
4269
+ };
4270
+ }
4271
+ function normalizeDayStats(prev, userId, timeKey) {
4272
+ if (!prev) {
4273
+ return {
4274
+ userId,
4275
+ period: "day",
4276
+ timeKey,
4277
+ total: { ...ZERO_STATS },
4278
+ models: {},
4279
+ providers: {},
4280
+ agents: {},
4281
+ entryPaths: {}
4282
+ };
4283
+ }
4284
+ const normalizeMap = (m) => {
4285
+ if (!m) return {};
4286
+ const out = {};
4287
+ for (const [k, v] of Object.entries(m)) out[k] = normalizeStats(v);
4288
+ return out;
4289
+ };
4420
4290
  return {
4291
+ ...prev,
4292
+ total: normalizeStats(prev.total),
4293
+ models: normalizeMap(prev.models),
4294
+ providers: normalizeMap(prev.providers),
4295
+ agents: normalizeMap(prev.agents),
4296
+ entryPaths: normalizeMap(prev.entryPaths)
4297
+ };
4298
+ }
4299
+ function applyTokenUsageToDayStats(prev, delta) {
4300
+ const base = normalizeDayStats(prev, delta.userId, delta.timeKey);
4301
+ const modelName = delta.model || "unknown";
4302
+ const providerName = delta.provider || "unknown";
4303
+ const cacheRead = delta.cache_read_input_tokens ?? 0;
4304
+ const cacheCreation = delta.cache_creation_input_tokens ?? 0;
4305
+ const isFailed = delta.status === "failed";
4306
+ const inc = (s) => {
4307
+ const n = normalizeStats(s);
4308
+ if (isFailed) {
4309
+ return {
4310
+ ...n,
4311
+ failedCount: n.failedCount + 1
4312
+ };
4313
+ }
4314
+ return {
4315
+ count: n.count + 1,
4316
+ tokens: {
4317
+ input: n.tokens.input + delta.input_tokens,
4318
+ output: n.tokens.output + delta.output_tokens,
4319
+ cacheRead: n.tokens.cacheRead + cacheRead,
4320
+ cacheCreation: n.tokens.cacheCreation + cacheCreation
4321
+ },
4322
+ cost: Number((n.cost + delta.cost).toFixed(6)),
4323
+ failedCount: n.failedCount
4324
+ };
4325
+ };
4326
+ const result = {
4421
4327
  ...base,
4422
4328
  total: inc(base.total),
4423
4329
  models: {
@@ -4429,6 +4335,21 @@ function applyTokenUsageToDayStats(prev, delta) {
4429
4335
  [providerName]: inc(base.providers[providerName])
4430
4336
  }
4431
4337
  };
4338
+ if (delta.agentId !== void 0) {
4339
+ const agentKey = delta.agentId || "unknown";
4340
+ result.agents = {
4341
+ ...base.agents,
4342
+ [agentKey]: inc(base.agents[agentKey])
4343
+ };
4344
+ }
4345
+ if (delta.entry_path !== void 0) {
4346
+ const entryKey = delta.entry_path || "unknown";
4347
+ result.entryPaths = {
4348
+ ...base.entryPaths,
4349
+ [entryKey]: inc(base.entryPaths[entryKey])
4350
+ };
4351
+ }
4352
+ return result;
4432
4353
  }
4433
4354
 
4434
4355
  // packages/core/keyedTaskQueue.ts
@@ -4479,7 +4400,11 @@ var updateStats = async (data, existingStats, key, thunkApi) => {
4479
4400
  provider: data.provider || "unknown",
4480
4401
  input_tokens: data.input_tokens,
4481
4402
  output_tokens: data.output_tokens,
4482
- cost: data.cost
4403
+ cost: data.cost,
4404
+ cache_read_input_tokens: data.cache_read_input_tokens,
4405
+ cache_creation_input_tokens: data.cache_creation_input_tokens,
4406
+ agentId: data.agentId ?? data.cybotId,
4407
+ entry_path: data.entry_path
4483
4408
  });
4484
4409
  await thunkApi.dispatch(
4485
4410
  write({
@@ -4565,7 +4490,11 @@ var updateTokensAction = async ({ dialogId, dialogKey, usage: legacyUsage, usage
4565
4490
  agentConfig: callAgentConfig,
4566
4491
  userId: ownerUserId,
4567
4492
  username: currentUser?.username,
4568
- agentId: agentConfig.id,
4493
+ // agentConfig.id is the canonical ulid; dbKey (agent-<userId>-<id>) is
4494
+ // always present on db records. Quick-chat may construct agentConfig with
4495
+ // only dbKey, so fall back to keep billing working (matches serverTokenWriter
4496
+ // which passes agentKey = dbKey directly).
4497
+ agentId: agentConfig.id || agentConfig.dbKey,
4569
4498
  dialogId,
4570
4499
  timestamp,
4571
4500
  entry_path: "web-chat"
@@ -4634,83 +4563,6 @@ var mergeDialogTokenStats = (dialogConfig, runtimeTokens) => ({
4634
4563
  totalCost: (dialogConfig?.totalCost ?? 0) + runtimeTokens.totalCost
4635
4564
  });
4636
4565
 
4637
- // packages/core/chat/dialogAttachmentCleanup.ts
4638
- var FILE_CONTENT_RE = /(?:https?:\/\/[^/"'\s]+)?\/api\/v1\/db\/file\/content\/([^?#"'\s)]+)/g;
4639
- function extractFileContentIds(value) {
4640
- const ids = /* @__PURE__ */ new Set();
4641
- const visit = (input) => {
4642
- if (typeof input === "string") {
4643
- for (const match of input.matchAll(FILE_CONTENT_RE)) {
4644
- const fileId = decodeURIComponent(match[1] ?? "").trim();
4645
- if (fileId) ids.add(fileId);
4646
- }
4647
- return;
4648
- }
4649
- if (Array.isArray(input)) {
4650
- for (const item of input) visit(item);
4651
- return;
4652
- }
4653
- if (input && typeof input === "object") {
4654
- for (const item of Object.values(input)) visit(item);
4655
- }
4656
- };
4657
- visit(value);
4658
- return [...ids];
4659
- }
4660
- function messageDbKey(dialogId, message) {
4661
- const dbKey = asOptionalTrimmedString(message.dbKey);
4662
- if (dbKey) return dbKey;
4663
- const id = asOptionalTrimmedString(message.id);
4664
- if (id) return dialogMessageKey(dialogId, id);
4665
- return null;
4666
- }
4667
- function asText(value) {
4668
- return asOptionalTrimmedString(value) ?? null;
4669
- }
4670
- function buildDialogAttachmentPlan(args) {
4671
- const messageKeys = new Set(
4672
- args.messages.map((message) => messageDbKey(args.dialogId, message)).filter((key) => Boolean(key))
4673
- );
4674
- const referencedFileIds = [
4675
- ...new Set(args.messages.flatMap((message) => extractFileContentIds(message)))
4676
- ];
4677
- const candidates = referencedFileIds.map((fileId) => {
4678
- const metadata = args.metadataByFileId[fileId];
4679
- const ownerType = asText(metadata?.ownerType);
4680
- const ownerId = asText(metadata?.ownerId);
4681
- const ownerDbKey = asText(metadata?.ownerDbKey);
4682
- const fileDbKey = asText(metadata?.dbKey);
4683
- const source = asText(metadata?.source);
4684
- const ownedByDialog = ownerType === "dialog" && ownerId === args.dialogId;
4685
- const ownedByMessage = Boolean(ownerDbKey && messageKeys.has(ownerDbKey));
4686
- const userOwnedReferenced = args.includeUserOwnedReferenced === true && Boolean(args.ownerId) && ownerType === "user" && ownerId === args.ownerId;
4687
- const canDelete = Boolean(fileDbKey && (ownedByDialog || ownedByMessage || userOwnedReferenced));
4688
- return {
4689
- fileId,
4690
- fileDbKey,
4691
- size: asOptionalFiniteNumber(metadata?.size) ?? null,
4692
- ownerType,
4693
- ownerId,
4694
- ownerDbKey,
4695
- source,
4696
- status: canDelete ? "delete" : "retain",
4697
- reason: canDelete ? ownedByMessage ? "ownerDbKey matches a message in this dialog" : userOwnedReferenced ? "user-owned file is referenced by this dialog and explicit referenced-attachment deletion is enabled" : "ownerType/ownerId matches this dialog" : fileDbKey ? "file ownership is not exclusive to this dialog" : "file metadata not found"
4698
- };
4699
- });
4700
- const deleteCandidates = candidates.filter((candidate) => candidate.status === "delete");
4701
- const retainedCandidates = candidates.filter((candidate) => candidate.status === "retain");
4702
- return {
4703
- dialogId: args.dialogId,
4704
- messageCount: args.messages.length,
4705
- referencedFileIds,
4706
- candidates,
4707
- deleteCandidates,
4708
- retainedCandidates,
4709
- bytesToDelete: deleteCandidates.reduce((sum, candidate) => sum + (candidate.size ?? 0), 0),
4710
- metadataReadFailures: args.metadataReadFailures ?? []
4711
- };
4712
- }
4713
-
4714
4566
  // packages/chat/dialog/deleteDialogOrchestration.ts
4715
4567
  var collectKeys = async (prefix, db) => {
4716
4568
  const keys = [];
@@ -4789,7 +4641,7 @@ var deleteOwnedDialogAttachments = async (args) => {
4789
4641
  metadataReadFailures
4790
4642
  });
4791
4643
  if (!plan.deleteCandidates.length) return plan;
4792
- const { deleteFileAction } = await import("./deleteFile-RJTEPOT4.js");
4644
+ const { deleteFileAction } = await import("./deleteFile-XQXPBFFB.js");
4793
4645
  for (const candidate of plan.deleteCandidates) {
4794
4646
  if (candidate.fileDbKey) {
4795
4647
  await deleteFileAction(candidate.fileDbKey, args.thunkApi);
@@ -4851,7 +4703,7 @@ var deleteDialogThunk = async (payload, thunkApi) => {
4851
4703
  }
4852
4704
  if (isCurrentDialog) {
4853
4705
  await thunkApi.dispatch(resetMsgs());
4854
- const { clearPendingAttachments: clearPendingAttachments2 } = await import("./dialogSlice-N4HPG6HM.js");
4706
+ const { clearPendingAttachments: clearPendingAttachments2 } = await import("./dialogSlice-DOWKOILN.js");
4855
4707
  dispatch(clearPendingAttachments2());
4856
4708
  clearWorkflow();
4857
4709
  }
@@ -4860,39 +4712,39 @@ var deleteDialogThunk = async (payload, thunkApi) => {
4860
4712
 
4861
4713
  // packages/chat/dialog/dialogSlice.ts
4862
4714
  var runCreateDialogAction = async (args, thunkApi) => {
4863
- const { createDialogAction } = await import("./createDialogAction-Y6YV64QB.js");
4715
+ const { createDialogAction } = await import("./createDialogAction-LDCPDI73.js");
4864
4716
  return createDialogAction(args, thunkApi);
4865
4717
  };
4866
4718
  var runCreateAgentAutomationAction = async (args, thunkApi) => {
4867
- const { createAgentAutomationAction } = await import("./createAgentAutomationAction-WLRNE7C4.js");
4719
+ const { createAgentAutomationAction } = await import("./createAgentAutomationAction-INQT23LX.js");
4868
4720
  return createAgentAutomationAction(args, thunkApi);
4869
4721
  };
4870
4722
  var runUpdateDialogTitleAction = async (args, thunkApi) => {
4871
- const { updateDialogTitleAction } = await import("./updateDialogTitleAction-BBDSWHNG.js");
4723
+ const { updateDialogTitleAction } = await import("./updateDialogTitleAction-XPJZRJEL.js");
4872
4724
  return updateDialogTitleAction(args, thunkApi);
4873
4725
  };
4874
4726
  var runAddDialogAgentAction = async (args, thunkApi) => {
4875
- const { addDialogAgentAction } = await import("./addDialogAgentAction-RCY4ECF4.js");
4727
+ const { addDialogAgentAction } = await import("./addDialogAgentAction-W44ZCEHB.js");
4876
4728
  return addDialogAgentAction(args, thunkApi);
4877
4729
  };
4878
4730
  var runRemoveDialogAgentAction = async (args, thunkApi) => {
4879
- const { removeDialogAgentAction } = await import("./removeDialogAgentAction-NEKVAMSH.js");
4731
+ const { removeDialogAgentAction } = await import("./removeDialogAgentAction-E7H557UO.js");
4880
4732
  return removeDialogAgentAction(args, thunkApi);
4881
4733
  };
4882
4734
  var runSetPrimaryDialogAgentAction = async (args, thunkApi) => {
4883
- const { setPrimaryDialogAgentAction } = await import("./setPrimaryDialogAgentAction-LDJOYC4F.js");
4735
+ const { setPrimaryDialogAgentAction } = await import("./setPrimaryDialogAgentAction-FWBKKLVA.js");
4884
4736
  return setPrimaryDialogAgentAction(args, thunkApi);
4885
4737
  };
4886
4738
  var runSwitchDialogAgentAction = async (args, thunkApi) => {
4887
- const { switchDialogAgentAction } = await import("./switchDialogAgentAction-XVWGKR2Z.js");
4739
+ const { switchDialogAgentAction } = await import("./switchDialogAgentAction-US6QNL3N.js");
4888
4740
  return switchDialogAgentAction(args, thunkApi);
4889
4741
  };
4890
4742
  var runSetDialogExtraReferencesAction = async (args, thunkApi) => {
4891
- const { setDialogExtraReferencesAction } = await import("./setDialogExtraReferencesAction-WTOHQDIV.js");
4743
+ const { setDialogExtraReferencesAction } = await import("./setDialogExtraReferencesAction-RMMGBR5F.js");
4892
4744
  return setDialogExtraReferencesAction(args, thunkApi);
4893
4745
  };
4894
4746
  var runHandleSendMessageAction = async (args, thunkApi) => {
4895
- const { handleSendMessageAction } = await import("./handleSendMessageAction-IN5XX5U7.js");
4747
+ const { handleSendMessageAction } = await import("./handleSendMessageAction-C3TSDWKH.js");
4896
4748
  return handleSendMessageAction(args, thunkApi);
4897
4749
  };
4898
4750
  function clearDialogState() {
@@ -4905,7 +4757,7 @@ var createPageAndAddReference = createAsyncThunk(
4905
4757
  async (payload, { dispatch, getState, rejectWithValue }) => {
4906
4758
  const { slateData, jsonData, title, type, fileId, groupId, dialogKey } = payload;
4907
4759
  try {
4908
- const { createDocState } = await import("./docStore-B5AHDNW5.js");
4760
+ const { createDocState } = await import("./docStore-UAWSKZ2Y.js");
4909
4761
  const pageKey = await createDocState(
4910
4762
  { slateData, title },
4911
4763
  { dispatch, getState }
@@ -5066,41 +4918,24 @@ var selectCurrentDialogTokens = createSelector(
5066
4918
  var selectTotalDialogTokens = selectCurrentDialogTokens;
5067
4919
 
5068
4920
  export {
5069
- resolveBuiltinPlatformAgentConfig,
5070
- resolveBuiltinPlatformAgentRecord,
5071
- fetchAndCacheMessages,
5072
4921
  isAssistantToolStub,
5073
- isOAuthApiKeyRef,
5074
- shouldUseServerProxy,
5075
- setWorkflow,
5076
- updateStep,
5077
- incrementStepsExecuted,
5078
- incrementFailedSteps,
5079
- toast,
4922
+ fetchAndCacheMessages,
4923
+ extractReferenceKeysFromMessage,
4924
+ normalizeAppRouteId,
5080
4925
  uiAskChoiceFunctionSchema,
5081
4926
  uiAskChoiceFunc,
5082
4927
  parseUiAskChoiceContent,
5083
- resolveDialogRuntimeAgentKey,
5084
- normalizeAppRouteId,
5085
- DEFAULT_CONTEXT_WINDOW,
5086
- getModelContextWindow,
5087
- getModelInfo,
5088
- API_REPORTED_COST_MULTIPLIER,
5089
- normalizeUsage,
5090
- prepareTokenUsageData,
5091
- applyTokenUsageToDayStats,
5092
- runKeyed,
5093
- updateTokensAction,
5094
- extractReferenceKeysFromMessage,
5095
- estimateMissingUsage,
5096
4928
  PERSONALIZATION_DIALOG_CATEGORY,
5097
4929
  buildPersonalizationDialogPolicyContext,
4930
+ resolveDialogRuntimeAgentKey,
5098
4931
  resolveHandleSendMessageContext,
4932
+ estimateMissingUsage,
5099
4933
  selectCurrentDialogId,
5100
4934
  selectAllMsgs,
5101
4935
  selectMsgById,
5102
4936
  addUserMessage,
5103
4937
  messageStreaming,
4938
+ resetMsgs,
5104
4939
  removeTransientMessage,
5105
4940
  finalizeTransientMessageOnError,
5106
4941
  prepareAndPersistMessage,
@@ -5108,8 +4943,18 @@ export {
5108
4943
  messageStreamEnd,
5109
4944
  addToolMessage,
5110
4945
  updateToolMessage,
5111
- extractFileContentIds,
5112
- buildDialogAttachmentPlan,
4946
+ setWorkflow,
4947
+ updateStep,
4948
+ incrementStepsExecuted,
4949
+ incrementFailedSteps,
4950
+ clearWorkflow,
4951
+ toast,
4952
+ API_REPORTED_COST_MULTIPLIER,
4953
+ normalizeUsage,
4954
+ prepareTokenUsageData,
4955
+ applyTokenUsageToDayStats,
4956
+ runKeyed,
4957
+ updateTokensAction,
5113
4958
  clearDialogState,
5114
4959
  createPageAndAddReference,
5115
4960
  deleteDialog,