nolo-cli 0.8.0-alpha.21 → 0.8.0-alpha.24

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 (114) hide show
  1. package/{_executeModel-42U3VOVZ.js → _executeModel-2ZAPHFOX.js} +46 -43
  2. package/{action-TLI3V62L.js → action-QM2ONPYZ.js} +9 -9
  3. package/{addContentAction-57RSIIMR.js → addContentAction-UXY3GM53.js} +8 -8
  4. package/{addDialogAgentAction-G3VWEA6E.js → addDialogAgentAction-MUBYOG65.js} +10 -10
  5. package/{agentDeleteCommand-5DD2IM3J.js → agentDeleteCommand-5TFSII4Z.js} +28 -27
  6. package/{agentEmailCommands-6FACJBU4.js → agentEmailCommands-XMXWGUMZ.js} +62 -58
  7. package/{agentListCommands-I6KZYCIG.js → agentListCommands-OWEFQEY4.js} +119 -33
  8. package/{agentMachineCommands-VKLIGMZA.js → agentMachineCommands-DGHYBBFC.js} +27 -26
  9. package/{agentPullCommand-O2MTUAFR.js → agentPullCommand-N6UWRTVL.js} +3 -3
  10. package/{agentRecordCommands-7TZICYDT.js → agentRecordCommands-I433EE5F.js} +53 -49
  11. package/{agentRunCommand-L4OM23KV.js → agentRunCommand-UQSX3IGW.js} +57 -52
  12. package/{agentRunControl-K4VKNEHF.js → agentRunControl-S3G62M6C.js} +3 -3
  13. package/{agentRuntimeLocal-ZYEIPTY4.js → agentRuntimeLocal-73SVOC5U.js} +14 -12
  14. package/{agentSlice-BX7GXSNO.js → agentSlice-JQCS4LR3.js} +9 -9
  15. package/{authCommand-EB5JSOX5.js → authCommand-B6P2XYLN.js} +11 -11
  16. package/{authCommands-XPEHTKSM.js → authCommands-4YKA4GTU.js} +7 -7
  17. package/{chunk-AS4PVWA4.js → chunk-2CVZSC5L.js} +1 -1
  18. package/{chunk-JRKKFRAV.js → chunk-3HPUUWOR.js} +58 -8
  19. package/{chunk-5KLGBAAR.js → chunk-3KGTFX3T.js} +2 -13
  20. package/{chunk-IWX4UW2E.js → chunk-524BDL33.js} +89 -8
  21. package/chunk-6QFNUK2G.js +144 -0
  22. package/{chunk-4QEWT7KD.js → chunk-AISLHYDB.js} +367 -85
  23. package/{chunk-2FTTDCD4.js → chunk-AMJ7LA5D.js} +1 -1
  24. package/{chunk-I6XMPTMR.js → chunk-BFDWXLFF.js} +2 -2
  25. package/{chunk-RL776AGR.js → chunk-BKGNXJAM.js} +1 -1
  26. package/{chunk-RCSJFQPB.js → chunk-BQECZ3Q4.js} +361 -90
  27. package/{chunk-VVX233PH.js → chunk-BT37DVDA.js} +9 -9
  28. package/{chunk-ENOG22KJ.js → chunk-BT57QC5K.js} +18 -20
  29. package/chunk-BYXBJQAS.js +0 -0
  30. package/{chunk-O2ZNTTET.js → chunk-C4DZRHFJ.js} +24 -15
  31. package/{chunk-4XENYTF5.js → chunk-DS3VC4EA.js} +3 -3
  32. package/{chunk-N54XAP77.js → chunk-FVVST32H.js} +1 -1
  33. package/{chunk-P3PKED2I.js → chunk-FZ2G3I4B.js} +11 -13
  34. package/{chunk-AGFH73SK.js → chunk-G7KM6BBZ.js} +1 -1
  35. package/{chunk-2ECQG4YX.js → chunk-GROGNZOA.js} +264 -161
  36. package/chunk-IOQIOZNI.js +42 -0
  37. package/{chunk-AL2KDGR2.js → chunk-IPA2WQGY.js} +201 -98
  38. package/{chunk-7DAJ4AI4.js → chunk-IYMGQ3TN.js} +9 -2
  39. package/{chunk-CKOJQDKR.js → chunk-JEMATI63.js} +1 -1
  40. package/{chunk-7U44LYTR.js → chunk-JTINRTBT.js} +1 -1
  41. package/{chunk-4O3CARJ4.js → chunk-KTHLAJEY.js} +1 -1
  42. package/{chunk-URUUZLPA.js → chunk-L3KWEH3V.js} +8 -8
  43. package/{chunk-XBUBEFNX.js → chunk-L76QNLGU.js} +1 -1
  44. package/{chunk-UB6SN4NJ.js → chunk-LE6JAIXE.js} +6 -6
  45. package/{chunk-2JCXITPK.js → chunk-LRKEOCWY.js} +15 -15
  46. package/{chunk-5EFXE3O7.js → chunk-LTH6AVG7.js} +3 -3
  47. package/{chunk-YPRZSPF3.js → chunk-OCDEWRE2.js} +1 -1
  48. package/{chunk-6KHNO3SK.js → chunk-P2SPC3FT.js} +27 -23
  49. package/{chunk-4IJYA27C.js → chunk-PXZAAB4L.js} +4 -4
  50. package/{chunk-VUW5FBDB.js → chunk-Q7S2ORXX.js} +9 -9
  51. package/{chunk-C3RUNRHT.js → chunk-QWM7YWVT.js} +1 -1
  52. package/{chunk-25LCXTML.js → chunk-RQPZX6KP.js} +2 -2
  53. package/chunk-S3UTETIC.js +4885 -0
  54. package/{chunk-SDJDLO5W.js → chunk-SBVUZC2E.js} +5 -5
  55. package/{chunk-VX3SXJ3N.js → chunk-UBSKX3LP.js} +6 -6
  56. package/{chunk-4ZDM73SD.js → chunk-V2J635L5.js} +1 -1
  57. package/{chunk-DSZUWUYB.js → chunk-VBKJTOAW.js} +1 -1
  58. package/{chunk-FVYY6MCS.js → chunk-VUEXKW6U.js} +17 -17
  59. package/{chunk-7KCUSYT2.js → chunk-WKQGZJVI.js} +7 -7
  60. package/{chunk-GU3PEVGZ.js → chunk-WM7P5OWZ.js} +2639 -1579
  61. package/{chunk-7GNGZRLZ.js → chunk-WTBWWBSF.js} +150 -78
  62. package/{chunk-FSO5B7GH.js → chunk-WVS3GX3B.js} +2 -2
  63. package/chunk-Z3NEXVYE.js +33 -0
  64. package/{createAgentAutomationAction-RJF3N2QY.js → createAgentAutomationAction-GXZNLJZK.js} +26 -24
  65. package/{createDialogAction-DRSPS6CE.js → createDialogAction-KLW42ZGF.js} +26 -24
  66. package/{createPageAction-6B2WMNO3.js → createPageAction-IBJHE6MH.js} +26 -24
  67. package/{dbSlice-Q3TM2FJV.js → dbSlice-R5EJKZBW.js} +7 -7
  68. package/{deleteFile-OW53A6BX.js → deleteFile-WPWVZE4B.js} +5 -5
  69. package/{dialogCommands-4IX4XIZE.js → dialogCommands-7O5PUZRU.js} +23 -22
  70. package/{dialogSlice-3M7KX2TX.js → dialogSlice-GGV7PF53.js} +25 -23
  71. package/{docCreateCommands-SIL3NPGT.js → docCreateCommands-7ZO2NQQF.js} +22 -21
  72. package/{docDeleteCommands-7IOMLUS4.js → docDeleteCommands-YKIXZYBR.js} +23 -22
  73. package/{docReadCommands-FNFXUA5L.js → docReadCommands-5UDONBUL.js} +22 -21
  74. package/{docStore-SV7E34D4.js → docStore-VDWTATFH.js} +25 -23
  75. package/{docUpdateCommands-X2HNDVUC.js → docUpdateCommands-EPZIIQMY.js} +22 -21
  76. package/fetchMessages-KTNM7QAR.js +1 -1
  77. package/{getPricing-3E6UNPKL.js → getPricing-6TOZXPAU.js} +7 -3
  78. package/{handleSendMessageAction-JYETO5RZ.js → handleSendMessageAction-MMATC5V5.js} +30 -28
  79. package/index.js +74 -74
  80. package/{localDialogRead-2VRI24F4.js → localDialogRead-YSKFFRTT.js} +1 -1
  81. package/{machineCommands-RIO3RP5Q.js → machineCommands-PTHPKSIZ.js} +59 -55
  82. package/{machineWsRunDispatch-W7UYLGB5.js → machineWsRunDispatch-M5L2NVWJ.js} +51 -47
  83. package/{memoryCommands-O4MIPIWQ.js → memoryCommands-HG4WKTU7.js} +2 -2
  84. package/{models-4OPOOLFS.js → models-H524GH3U.js} +3 -2
  85. package/package.json +1 -1
  86. package/{read-GW7ZEI23.js → read-5ZMY7FKP.js} +5 -5
  87. package/{readDocTool-HUFU6OCT.js → readDocTool-2NXDK32S.js} +1 -1
  88. package/{readlineWorkspace-27JR7WPW.js → readlineWorkspace-4NXMEOHP.js} +835 -622
  89. package/{removeDialogAgentAction-CXKR4NJI.js → removeDialogAgentAction-KOLQ2R5W.js} +13 -12
  90. package/{runAgentClientLoop-HZFAPJHS.js → runAgentClientLoop-FGUYNGSA.js} +45 -42
  91. package/{runtimeDoctorCommands-LRHLPDRC.js → runtimeDoctorCommands-UWR5UDSM.js} +5 -5
  92. package/{setDialogExtraReferencesAction-6RKUSXHX.js → setDialogExtraReferencesAction-OMTEO7X6.js} +10 -10
  93. package/{setPrimaryDialogAgentAction-T3UTBEFG.js → setPrimaryDialogAgentAction-DOCIS6V4.js} +13 -12
  94. package/{settingSlice-IVKXJXMG.js → settingSlice-UWZJYDOA.js} +8 -8
  95. package/{spaceCommands-E7VOF4LO.js → spaceCommands-S3EB6TOS.js} +29 -28
  96. package/{spaceSlice-TSVROA5U.js → spaceSlice-RG2GSV7K.js} +24 -22
  97. package/{streamAgentChatTurn-3C5RQZJF.js → streamAgentChatTurn-X576C23M.js} +209 -86
  98. package/{tableCommands-O7O2LBEG.js → tableCommands-M3DJUETS.js} +10 -10
  99. package/{toolApiClient-QI3YBNWB.js → toolApiClient-C7P7YSE4.js} +2 -2
  100. package/{tools-EQDEKR6N.js → tools-HURZ2N4O.js} +33 -30
  101. package/{tuiSummaryLlmCaller-RV3THLZF.js → tuiSummaryLlmCaller-DG2LBTBX.js} +8 -6
  102. package/{updateCommands-VOSPKXFF.js → updateCommands-TC5SX42Y.js} +3 -3
  103. package/{updateDialogTitleAction-3XV7VWSZ.js → updateDialogTitleAction-62LVIAUZ.js} +28 -26
  104. package/chunk-BBYVOSU2.js +0 -792
  105. package/chunk-DCOA4QSN.js +0 -105
  106. package/{chunk-DZ3XJVET.js → chunk-3QAF2LTL.js} +3 -3
  107. package/{chunk-EHLHSX7R.js → chunk-5MMZUWSG.js} +3 -3
  108. package/{chunk-ISNCLGUZ.js → chunk-AVMJVOQY.js} +3 -3
  109. package/{chunk-UTLZINAP.js → chunk-DVRHHFEA.js} +10 -10
  110. package/{chunk-4CQLVGRV.js → chunk-ID4G2MAR.js} +3 -3
  111. package/{chunk-5MIDPSSK.js → chunk-JK7VW2FN.js} +3 -3
  112. package/{chunk-TILFE6LV.js → chunk-YOCHZD7D.js} +3 -3
  113. package/{db-HCJ5PRB5.js → db-6QED3ZVO.js} +3 -3
  114. package/{understanding-3CUQQ6SV.js → understanding-ZOESBLF3.js} +3 -3
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  BUILTIN_SUMMARY_LLM_CONFIG,
3
3
  buildBuiltinSummaryContent
4
- } from "./chunk-4ZDM73SD.js";
4
+ } from "./chunk-V2J635L5.js";
5
5
  import {
6
6
  authRoutes
7
7
  } from "./chunk-MRC4Q34M.js";
@@ -15,10 +15,10 @@ import {
15
15
  import {
16
16
  deleteServerSyncedCredential,
17
17
  runLlm
18
- } from "./chunk-VUW5FBDB.js";
18
+ } from "./chunk-Q7S2ORXX.js";
19
19
  import {
20
20
  cleanupCliSessionForDialog
21
- } from "./chunk-5EFXE3O7.js";
21
+ } from "./chunk-LTH6AVG7.js";
22
22
  import {
23
23
  getDialogAgentIds,
24
24
  getPrimaryDialogAgentId
@@ -26,6 +26,13 @@ import {
26
26
  import {
27
27
  require_date_fns
28
28
  } from "./chunk-M76ECQRD.js";
29
+ import {
30
+ isSystemAdmin,
31
+ nolotusId,
32
+ selectRemoteServer,
33
+ selectRemoteServers,
34
+ selectRemoteSyncServers
35
+ } from "./chunk-UBSKX3LP.js";
29
36
  import {
30
37
  fetchMessages
31
38
  } from "./chunk-SOTZ6RDN.js";
@@ -34,53 +41,11 @@ import {
34
41
  addContentAction,
35
42
  checkSpaceMembership,
36
43
  localSpaceAuthorityPatchStamp
37
- } from "./chunk-I6XMPTMR.js";
44
+ } from "./chunk-BFDWXLFF.js";
38
45
  import {
39
46
  createSpaceKey,
40
47
  normalizeSpaceId
41
48
  } from "./chunk-UAD2WT54.js";
42
- import {
43
- ALL_MODELS
44
- } from "./chunk-DCOA4QSN.js";
45
- import {
46
- MODEL_LOOKUP_MAP,
47
- findModelConfig,
48
- getModelConfig
49
- } from "./chunk-BBYVOSU2.js";
50
- import {
51
- createFileCredentialBroker
52
- } from "./chunk-5CS33IBL.js";
53
- import {
54
- extractCustomId,
55
- extractUserId
56
- } from "./chunk-DFFIZ25G.js";
57
- import {
58
- abortActiveControllers,
59
- addPageReferenceToRuntime,
60
- applyClearDialogStateRuntime,
61
- applyUpdateTokensFulfilled,
62
- clearActiveControllers,
63
- clearPendingAttachments,
64
- clearPendingUserInputQueue,
65
- deleteDialogRuntime,
66
- getActiveDialogKey,
67
- getDialogRuntimeTokens,
68
- require_react,
69
- resetDialogRuntimeSessionState,
70
- selectCurrentDialogKey,
71
- setActiveDialogKey,
72
- setDialogConfigError
73
- } from "./chunk-3ASDTTEI.js";
74
- import {
75
- toErrorMessage
76
- } from "./chunk-HNMXYYJR.js";
77
- import {
78
- isSystemAdmin,
79
- nolotusId,
80
- selectRemoteServer,
81
- selectRemoteServers,
82
- selectRemoteSyncServers
83
- } from "./chunk-VX3SXJ3N.js";
84
49
  import {
85
50
  patch,
86
51
  read,
@@ -93,10 +58,21 @@ import {
93
58
  uploadFileAction,
94
59
  upsertSSREntity,
95
60
  write
96
- } from "./chunk-URUUZLPA.js";
61
+ } from "./chunk-L3KWEH3V.js";
97
62
  import {
98
63
  resolveFileCategory
99
64
  } from "./chunk-AZPCASRE.js";
65
+ import {
66
+ ALL_MODELS
67
+ } from "./chunk-IOQIOZNI.js";
68
+ import {
69
+ MODEL_LOOKUP_MAP,
70
+ findModelConfig,
71
+ getModelConfig
72
+ } from "./chunk-S3UTETIC.js";
73
+ import {
74
+ createFileCredentialBroker
75
+ } from "./chunk-5CS33IBL.js";
100
76
  import {
101
77
  asRecordOrEmpty
102
78
  } from "./chunk-KX6YBIHG.js";
@@ -132,12 +108,36 @@ import {
132
108
  import {
133
109
  asOptionalFiniteNumber
134
110
  } from "./chunk-WWC7I6TA.js";
111
+ import {
112
+ extractCustomId,
113
+ extractUserId
114
+ } from "./chunk-DFFIZ25G.js";
115
+ import {
116
+ abortActiveControllers,
117
+ addPageReferenceToRuntime,
118
+ applyClearDialogStateRuntime,
119
+ applyUpdateTokensFulfilled,
120
+ clearActiveControllers,
121
+ clearPendingAttachments,
122
+ clearPendingUserInputQueue,
123
+ deleteDialogRuntime,
124
+ getActiveDialogKey,
125
+ getDialogRuntimeTokens,
126
+ require_react,
127
+ resetDialogRuntimeSessionState,
128
+ selectCurrentDialogKey,
129
+ setActiveDialogKey,
130
+ setDialogConfigError
131
+ } from "./chunk-3ASDTTEI.js";
135
132
  import {
136
133
  asTrimmedLowercaseString
137
134
  } from "./chunk-QSJ3HFEF.js";
135
+ import {
136
+ toErrorMessage
137
+ } from "./chunk-HNMXYYJR.js";
138
138
  import {
139
139
  readAction
140
- } from "./chunk-DSZUWUYB.js";
140
+ } from "./chunk-VBKJTOAW.js";
141
141
  import {
142
142
  DEVICE_LOCAL_OWNER_ID,
143
143
  asyncThunkCreator,
@@ -158,7 +158,7 @@ import {
158
158
  selectIdentityToken,
159
159
  selectIdentityUserId,
160
160
  selectRuntimeSnapshot
161
- } from "./chunk-UTLZINAP.js";
161
+ } from "./chunk-DVRHHFEA.js";
162
162
  import {
163
163
  createClientLogger,
164
164
  fetchFromServer,
@@ -172,25 +172,25 @@ import {
172
172
  isTombstoneRecord,
173
173
  shouldReplaceWithNextRecord
174
174
  } from "./chunk-GBRG75BQ.js";
175
- import {
176
- API_ENDPOINTS,
177
- API_VERSION
178
- } from "./chunk-LCBAMY2M.js";
179
175
  import {
180
176
  asTrimmedString
181
177
  } from "./chunk-3EUW3WEO.js";
182
178
  import {
183
179
  asOptionalPositiveFiniteNumber
184
180
  } from "./chunk-U6VC4MU4.js";
181
+ import {
182
+ isRecord
183
+ } from "./chunk-KUG52IAP.js";
184
+ import {
185
+ API_ENDPOINTS,
186
+ API_VERSION
187
+ } from "./chunk-LCBAMY2M.js";
185
188
  import {
186
189
  normalizeServerOrigin
187
190
  } from "./chunk-CF7PE763.js";
188
191
  import {
189
192
  asOptionalTrimmedString
190
193
  } from "./chunk-G3SUCT4W.js";
191
- import {
192
- isRecord
193
- } from "./chunk-KUG52IAP.js";
194
194
  import {
195
195
  __commonJS,
196
196
  __require,
@@ -11158,7 +11158,7 @@ var estimateMissingUsage = ({
11158
11158
  Math.ceil(text.length / APPROX_CHARS_PER_TOKEN)
11159
11159
  );
11160
11160
  return {
11161
- input_tokens: 1,
11161
+ input_tokens: 0,
11162
11162
  output_tokens: estimatedOutputTokens,
11163
11163
  cache_creation_input_tokens: 0,
11164
11164
  cache_read_input_tokens: 0,
@@ -11816,7 +11816,7 @@ async function captureUnderstandingFromCompletedUiTurn(input) {
11816
11816
  if (!input.agentKey) return;
11817
11817
  const latestUserInput = getLatestUserInputFromMessages(input.messages);
11818
11818
  if (!latestUserInput) return;
11819
- const { captureUnderstandingMemoryFromDialog } = await import("./understanding-3CUQQ6SV.js");
11819
+ const { captureUnderstandingMemoryFromDialog } = await import("./understanding-ZOESBLF3.js");
11820
11820
  await captureUnderstandingMemoryFromDialog({
11821
11821
  db: input.db,
11822
11822
  userId: selectIdentityUserId(input.state),
@@ -12741,7 +12741,7 @@ var messageSlice = createSliceWithThunks({
12741
12741
  runtimeOptions: args.runtimeOptions
12742
12742
  });
12743
12743
  if (agentKeyToUse) {
12744
- const { streamAgentChatTurn } = await import("./agentSlice-BX7GXSNO.js");
12744
+ const { streamAgentChatTurn } = await import("./agentSlice-JQCS4LR3.js");
12745
12745
  await dispatch(
12746
12746
  streamAgentChatTurn({
12747
12747
  agentKey: agentKeyToUse,
@@ -12879,12 +12879,9 @@ var saveTokenRecord = async (tokenData, record, thunkApi) => {
12879
12879
  write({
12880
12880
  data: { ...record, id: key, type: "token" /* TOKEN */, userId: ownerUserId },
12881
12881
  customKey: key,
12882
- // writeAction stamps record.userId from writeConfig.userId ||
12883
- // currentUserId; without this, logged-out local token rows lose
12884
- // the authoritative "local" owner before replication planning.
12885
12882
  userId: ownerUserId
12886
12883
  })
12887
- );
12884
+ ).unwrap();
12888
12885
  } catch (error) {
12889
12886
  logger2.error(
12890
12887
  {
@@ -14564,6 +14561,10 @@ var selectCurrentToken = (state3) => state3.auth.currentToken;
14564
14561
  var selectCurrentUserBalance = (state3) => state3.auth.currentUser?.balance;
14565
14562
 
14566
14563
  // packages/ai/token/calculatePrice.ts
14564
+ var sanitizeCost = (raw) => {
14565
+ const rounded = Number(raw.toFixed(6));
14566
+ return Number.isFinite(rounded) && rounded > 0 ? rounded : 0;
14567
+ };
14567
14568
  var resolveModelPrice = (model, usage) => {
14568
14569
  let activePrice = { ...model.price };
14569
14570
  if (model.pricingStrategy?.type === "tiered_context") {
@@ -14839,7 +14840,7 @@ var calculatePrice = ({
14839
14840
  billingServiceTier
14840
14841
  );
14841
14842
  const pay2 = calculatePayDistribution(costs2, externalPrice, sharingLevel);
14842
- return { cost: Number(costs2.charge.toFixed(6)), pay: pay2 };
14843
+ return { cost: sanitizeCost(costs2.charge), pay: pay2 };
14843
14844
  }
14844
14845
  const costs = calculateBasicCost(
14845
14846
  model,
@@ -14860,7 +14861,7 @@ var calculatePrice = ({
14860
14861
  } : costs;
14861
14862
  const pay = calculatePayDistribution(adjustedCosts, externalPrice, sharingLevel);
14862
14863
  return {
14863
- cost: Number(adjustedCosts.charge.toFixed(6)),
14864
+ cost: sanitizeCost(adjustedCosts.charge),
14864
14865
  pay
14865
14866
  };
14866
14867
  };
@@ -14960,16 +14961,75 @@ var resolveBillingTarget = ({
14960
14961
  };
14961
14962
  };
14962
14963
 
14964
+ // packages/agent-runtime/serverProxyPolicy.ts
14965
+ var OAUTH_APIKEY_REFS = /* @__PURE__ */ new Set([
14966
+ "antigravity",
14967
+ "xai",
14968
+ "chatgpt",
14969
+ "claude",
14970
+ "cursor"
14971
+ ]);
14972
+ function isGoogleFamilyProvider(provider) {
14973
+ const normalized = asTrimmedLowercaseString(provider);
14974
+ return normalized === "google" || normalized.startsWith("google-");
14975
+ }
14976
+ function isOAuthApiKeyRef(value) {
14977
+ const ref = asTrimmedLowercaseString(value);
14978
+ return ref.length > 0 && OAUTH_APIKEY_REFS.has(ref);
14979
+ }
14980
+ function shouldUseServerProxy(agentConfig, requestProvider) {
14981
+ const effectiveProvider = (requestProvider || agentConfig.provider || "").toLowerCase();
14982
+ if (isGoogleFamilyProvider(effectiveProvider)) {
14983
+ return true;
14984
+ }
14985
+ if (isOAuthApiKeyRef(agentConfig.apiKeyRef)) {
14986
+ return true;
14987
+ }
14988
+ if (agentConfig.apiSource === "custom" && isRemoteCustomEndpoint(agentConfig.customProviderUrl)) {
14989
+ return true;
14990
+ }
14991
+ return !!agentConfig.useServerProxy;
14992
+ }
14993
+ var LOCAL_HOSTS = /* @__PURE__ */ new Set(["127.0.0.1", "localhost", "::1", "0.0.0.0"]);
14994
+ function isRemoteCustomEndpoint(url) {
14995
+ if (typeof url !== "string") return false;
14996
+ try {
14997
+ const host = new URL(url).hostname.toLowerCase();
14998
+ return !LOCAL_HOSTS.has(host);
14999
+ } catch {
15000
+ return false;
15001
+ }
15002
+ }
15003
+
14963
15004
  // packages/ai/token/prepareTokenUsageData.ts
15005
+ function resolveBillable(input) {
15006
+ const uid = input.userId?.trim();
15007
+ if (!uid || uid === "local") return false;
15008
+ const apiSource = input.apiSource;
15009
+ if (apiSource === "cli") return false;
15010
+ if (isOAuthApiKeyRef(input.apiKeyRef)) return false;
15011
+ if (input.cost <= 0) return false;
15012
+ if (apiSource === "platform") return true;
15013
+ if (apiSource === "custom") return input.hasExternalPrice;
15014
+ if (apiSource == null || apiSource === "") return true;
15015
+ return false;
15016
+ }
14964
15017
  var prepareTokenUsageData = ({
14965
15018
  rawUsage,
14966
15019
  agentConfig,
14967
15020
  userId,
14968
15021
  username,
15022
+ agentId,
14969
15023
  cybotId,
14970
15024
  dialogId,
14971
15025
  timestamp = Date.now()
14972
15026
  }) => {
15027
+ const resolvedAgentId = typeof agentId === "string" && agentId.trim() || typeof cybotId === "string" && cybotId.trim() || "";
15028
+ if (!resolvedAgentId) {
15029
+ throw new Error(
15030
+ "prepareTokenUsageData requires a non-empty agentId or cybotId"
15031
+ );
15032
+ }
14973
15033
  const usage = normalizeUsage(rawUsage);
14974
15034
  const billingTarget = resolveBillingTarget({
14975
15035
  usage,
@@ -14980,18 +15040,27 @@ var prepareTokenUsageData = ({
14980
15040
  const billedModel = billingTarget.model;
14981
15041
  const billedServiceTier = billingTarget.serviceTier;
14982
15042
  const recordProvider = billedProvider ?? agentConfig.provider ?? "unknown";
15043
+ const hasExternalPrice = agentConfig.inputPrice !== void 0 && agentConfig.inputPrice > 0 || agentConfig.outputPrice !== void 0 && agentConfig.outputPrice > 0;
14983
15044
  const { cost, pay } = calculatePrice({
14984
15045
  provider: billedProvider,
14985
15046
  modelName: billedModel,
14986
15047
  billingServiceTier: billedServiceTier,
14987
15048
  usage,
14988
- externalPrice: agentConfig.id ? {
15049
+ externalPrice: hasExternalPrice ? {
14989
15050
  input: agentConfig.inputPrice ?? 0,
14990
15051
  output: agentConfig.outputPrice ?? 0,
14991
- creatorId: agentConfig.userId ?? extractUserId(agentConfig.id)
15052
+ creatorId: agentConfig.userId ?? (agentConfig.id ? extractUserId(agentConfig.id) : "")
14992
15053
  } : void 0,
14993
15054
  sharingLevel: agentConfig.sharingLevel
14994
15055
  });
15056
+ const billable = resolveBillable({
15057
+ usage,
15058
+ userId,
15059
+ apiSource: agentConfig.apiSource,
15060
+ apiKeyRef: agentConfig.apiKeyRef,
15061
+ cost,
15062
+ hasExternalPrice
15063
+ });
14995
15064
  return {
14996
15065
  usage,
14997
15066
  billedProvider,
@@ -15002,18 +15071,74 @@ var prepareTokenUsageData = ({
15002
15071
  ...usage,
15003
15072
  userId,
15004
15073
  username,
15005
- cybotId,
15074
+ agentId: resolvedAgentId,
15075
+ cybotId: resolvedAgentId,
15006
15076
  model: billedModel,
15007
15077
  provider: recordProvider,
15008
15078
  billing_service_tier: billedServiceTier,
15009
15079
  dialogId,
15010
15080
  cost,
15011
15081
  pay,
15012
- timestamp
15082
+ timestamp,
15083
+ billable
15013
15084
  }
15014
15085
  };
15015
15086
  };
15016
15087
 
15088
+ // packages/ai/token/applyTokenUsageToDayStats.ts
15089
+ var ZERO_STATS = { count: 0, tokens: { input: 0, output: 0 }, cost: 0 };
15090
+ function applyTokenUsageToDayStats(prev, delta) {
15091
+ const base = prev ?? {
15092
+ userId: delta.userId,
15093
+ period: "day",
15094
+ timeKey: delta.timeKey,
15095
+ total: { ...ZERO_STATS },
15096
+ models: {},
15097
+ providers: {}
15098
+ };
15099
+ const modelName = delta.model || "unknown";
15100
+ const providerName2 = delta.provider || "unknown";
15101
+ const inc = (s) => ({
15102
+ count: (s?.count ?? 0) + 1,
15103
+ tokens: {
15104
+ input: (s?.tokens.input ?? 0) + delta.input_tokens,
15105
+ output: (s?.tokens.output ?? 0) + delta.output_tokens
15106
+ },
15107
+ cost: Number(((s?.cost ?? 0) + delta.cost).toFixed(6))
15108
+ });
15109
+ return {
15110
+ ...base,
15111
+ total: inc(base.total),
15112
+ models: {
15113
+ ...base.models,
15114
+ [modelName]: inc(base.models[modelName])
15115
+ },
15116
+ providers: {
15117
+ ...base.providers,
15118
+ [providerName2]: inc(base.providers[providerName2])
15119
+ }
15120
+ };
15121
+ }
15122
+
15123
+ // packages/core/keyedTaskQueue.ts
15124
+ var queues = /* @__PURE__ */ new Map();
15125
+ async function runKeyed(key, task) {
15126
+ const previous = queues.get(key) ?? Promise.resolve();
15127
+ const next = previous.catch(() => void 0).then(task);
15128
+ const cleanup = next.then(
15129
+ () => void 0,
15130
+ () => void 0
15131
+ );
15132
+ queues.set(key, cleanup);
15133
+ try {
15134
+ return await next;
15135
+ } finally {
15136
+ if (queues.get(key) === cleanup) {
15137
+ queues.delete(key);
15138
+ }
15139
+ }
15140
+ }
15141
+
15017
15142
  // packages/chat/dialog/actions/updateTokensAction.ts
15018
15143
  var logger3 = createClientLogger("token-usage");
15019
15144
  var dialogTokenPatchQueue = /* @__PURE__ */ new Map();
@@ -15033,53 +15158,26 @@ var queueDialogTokenPatch = async (dialogKey, task) => {
15033
15158
  }
15034
15159
  }
15035
15160
  };
15036
- var updateStatsCounter = (data, stats = { count: 0, tokens: { input: 0, output: 0 }, cost: 0 }) => ({
15037
- count: stats.count + 1,
15038
- tokens: {
15039
- input: stats.tokens.input + data.input_tokens,
15040
- output: stats.tokens.output + data.output_tokens
15041
- },
15042
- cost: stats.cost + data.cost
15043
- });
15044
15161
  var updateStats = async (data, existingStats, key, thunkApi) => {
15045
15162
  try {
15046
- const stats = existingStats ?? {
15047
- userId: data.userId,
15048
- period: "day",
15049
- timeKey: (0, import_date_fns.format)(Date.now(), "yyyy-MM-dd"),
15050
- total: { count: 0, tokens: { input: 0, output: 0 }, cost: 0 },
15051
- models: {},
15052
- providers: {}
15053
- };
15054
- const modelName = data.model || "unknown";
15055
- const providerName2 = data.provider || "unknown";
15056
- const cleanModels = Object.fromEntries(
15057
- Object.entries(stats.models).filter(
15058
- ([key2]) => !["unknown", "undefined"].includes(key2)
15059
- )
15060
- );
15061
- const updatedStats = {
15062
- ...stats,
15063
- total: updateStatsCounter(data, stats.total),
15064
- models: {
15065
- ...cleanModels,
15066
- [modelName]: updateStatsCounter(data, cleanModels[modelName])
15067
- },
15068
- providers: {
15069
- ...stats.providers,
15070
- [providerName2]: updateStatsCounter(data, stats.providers[providerName2])
15071
- }
15072
- };
15163
+ const dateKey = (0, import_date_fns.format)(data.timestamp ?? Date.now(), "yyyy-MM-dd");
15164
+ const newStats = applyTokenUsageToDayStats(existingStats, {
15165
+ userId: data.userId ?? "",
15166
+ timeKey: dateKey,
15167
+ model: data.model || "unknown",
15168
+ provider: data.provider || "unknown",
15169
+ input_tokens: data.input_tokens,
15170
+ output_tokens: data.output_tokens,
15171
+ cost: data.cost
15172
+ });
15073
15173
  await thunkApi.dispatch(
15074
15174
  write({
15075
- data: { ...updatedStats, id: key, type: "token" /* TOKEN */ },
15175
+ data: { ...newStats, id: key, type: "token" /* TOKEN */ },
15076
15176
  customKey: key,
15077
- // Must stamp owner on writeConfig: writeAction overwrites data.userId
15078
- // from writeConfig.userId || currentUserId (empty when logged out).
15079
15177
  userId: data.userId
15080
15178
  })
15081
- );
15082
- return updatedStats;
15179
+ ).unwrap();
15180
+ return newStats;
15083
15181
  } catch (error) {
15084
15182
  logger3.error(
15085
15183
  { key, userId: data.userId, error: error.message },
@@ -15090,45 +15188,47 @@ var updateStats = async (data, existingStats, key, thunkApi) => {
15090
15188
  }
15091
15189
  };
15092
15190
  var saveTokenUsage = async (data, thunkApi) => {
15093
- const dateKey = (0, import_date_fns.format)(Date.now(), "yyyy-MM-dd");
15191
+ const dateKey = (0, import_date_fns.format)(data.timestamp ?? Date.now(), "yyyy-MM-dd");
15094
15192
  const tokenDayStatsKey = createTokenStatsKey(data.userId ?? "", dateKey);
15095
- try {
15096
- let currentStats = null;
15193
+ return runKeyed(tokenDayStatsKey, async () => {
15097
15194
  try {
15098
- currentStats = await thunkApi.dispatch(read({
15099
- dbKey: tokenDayStatsKey
15100
- })).unwrap();
15101
- } catch (err) {
15102
- logger3.warn({ tokenDayStatsKey }, "No existing stats found");
15195
+ let currentStats = null;
15196
+ try {
15197
+ currentStats = await thunkApi.dispatch(read({
15198
+ dbKey: tokenDayStatsKey
15199
+ })).unwrap();
15200
+ } catch (err) {
15201
+ logger3.warn({ tokenDayStatsKey }, "No existing stats found");
15202
+ }
15203
+ const updatedStats = await updateStats(
15204
+ data,
15205
+ currentStats,
15206
+ tokenDayStatsKey,
15207
+ thunkApi
15208
+ );
15209
+ return {
15210
+ success: true,
15211
+ id: ulid3(Date.now()),
15212
+ record: updatedStats
15213
+ };
15214
+ } catch (error) {
15215
+ logger3.error(
15216
+ {
15217
+ key: tokenDayStatsKey,
15218
+ userId: data.userId,
15219
+ error: error.message,
15220
+ tokenData: {
15221
+ input: data.input_tokens,
15222
+ output: data.output_tokens,
15223
+ model: data.model
15224
+ }
15225
+ },
15226
+ "Failed to process token usage"
15227
+ );
15228
+ toast.error("Failed to process token usage");
15229
+ throw error;
15103
15230
  }
15104
- const updatedStats = await updateStats(
15105
- data,
15106
- currentStats,
15107
- tokenDayStatsKey,
15108
- thunkApi
15109
- );
15110
- return {
15111
- success: true,
15112
- id: ulid3(Date.now()),
15113
- record: updatedStats
15114
- };
15115
- } catch (error) {
15116
- logger3.error(
15117
- {
15118
- key: tokenDayStatsKey,
15119
- userId: data.userId,
15120
- error: error.message,
15121
- tokenData: {
15122
- input: data.input_tokens,
15123
- output: data.output_tokens,
15124
- model: data.model
15125
- }
15126
- },
15127
- "Failed to process token usage"
15128
- );
15129
- toast.error("Failed to process token usage");
15130
- throw error;
15131
- }
15231
+ });
15132
15232
  };
15133
15233
  var updateTokensAction = async ({ dialogId, dialogKey, usage: usageRaw, agentConfig }, thunkApi) => {
15134
15234
  const state3 = thunkApi.getState();
@@ -15146,7 +15246,7 @@ var updateTokensAction = async ({ dialogId, dialogKey, usage: usageRaw, agentCon
15146
15246
  agentConfig,
15147
15247
  userId: ownerUserId,
15148
15248
  username: currentUser?.username,
15149
- cybotId: agentConfig.id,
15249
+ agentId: agentConfig.id,
15150
15250
  dialogId,
15151
15251
  timestamp
15152
15252
  });
@@ -15169,7 +15269,7 @@ var updateTokensAction = async ({ dialogId, dialogKey, usage: usageRaw, agentCon
15169
15269
  });
15170
15270
  await saveTokenRecord(persistedTokenData, record, thunkApi);
15171
15271
  await saveTokenUsage(persistedTokenData, thunkApi);
15172
- if (result.cost > 0) {
15272
+ if (persistedTokenData.billable === true || persistedTokenData.billable === void 0 && result.cost > 0) {
15173
15273
  thunkApi.dispatch(deductBalance(result.cost));
15174
15274
  }
15175
15275
  if (dialogKey) {
@@ -15283,7 +15383,7 @@ var deleteOwnedDialogAttachments = async (args) => {
15283
15383
  metadataReadFailures
15284
15384
  });
15285
15385
  if (!plan.deleteCandidates.length) return plan;
15286
- const { deleteFileAction } = await import("./deleteFile-OW53A6BX.js");
15386
+ const { deleteFileAction } = await import("./deleteFile-WPWVZE4B.js");
15287
15387
  for (const candidate of plan.deleteCandidates) {
15288
15388
  if (candidate.fileDbKey) {
15289
15389
  await deleteFileAction(candidate.fileDbKey, args.thunkApi);
@@ -15345,7 +15445,7 @@ var deleteDialogThunk = async (payload, thunkApi) => {
15345
15445
  }
15346
15446
  if (isCurrentDialog) {
15347
15447
  await thunkApi.dispatch(resetMsgs());
15348
- const { clearPendingAttachments: clearPendingAttachments2 } = await import("./dialogSlice-3M7KX2TX.js");
15448
+ const { clearPendingAttachments: clearPendingAttachments2 } = await import("./dialogSlice-GGV7PF53.js");
15349
15449
  dispatch(clearPendingAttachments2());
15350
15450
  clearWorkflow();
15351
15451
  }
@@ -15354,35 +15454,35 @@ var deleteDialogThunk = async (payload, thunkApi) => {
15354
15454
 
15355
15455
  // packages/chat/dialog/dialogSlice.ts
15356
15456
  var runCreateDialogAction = async (args, thunkApi) => {
15357
- const { createDialogAction } = await import("./createDialogAction-DRSPS6CE.js");
15457
+ const { createDialogAction } = await import("./createDialogAction-KLW42ZGF.js");
15358
15458
  return createDialogAction(args, thunkApi);
15359
15459
  };
15360
15460
  var runCreateAgentAutomationAction = async (args, thunkApi) => {
15361
- const { createAgentAutomationAction } = await import("./createAgentAutomationAction-RJF3N2QY.js");
15461
+ const { createAgentAutomationAction } = await import("./createAgentAutomationAction-GXZNLJZK.js");
15362
15462
  return createAgentAutomationAction(args, thunkApi);
15363
15463
  };
15364
15464
  var runUpdateDialogTitleAction = async (args, thunkApi) => {
15365
- const { updateDialogTitleAction } = await import("./updateDialogTitleAction-3XV7VWSZ.js");
15465
+ const { updateDialogTitleAction } = await import("./updateDialogTitleAction-62LVIAUZ.js");
15366
15466
  return updateDialogTitleAction(args, thunkApi);
15367
15467
  };
15368
15468
  var runAddDialogAgentAction = async (args, thunkApi) => {
15369
- const { addDialogAgentAction } = await import("./addDialogAgentAction-G3VWEA6E.js");
15469
+ const { addDialogAgentAction } = await import("./addDialogAgentAction-MUBYOG65.js");
15370
15470
  return addDialogAgentAction(args, thunkApi);
15371
15471
  };
15372
15472
  var runRemoveDialogAgentAction = async (args, thunkApi) => {
15373
- const { removeDialogAgentAction } = await import("./removeDialogAgentAction-CXKR4NJI.js");
15473
+ const { removeDialogAgentAction } = await import("./removeDialogAgentAction-KOLQ2R5W.js");
15374
15474
  return removeDialogAgentAction(args, thunkApi);
15375
15475
  };
15376
15476
  var runSetPrimaryDialogAgentAction = async (args, thunkApi) => {
15377
- const { setPrimaryDialogAgentAction } = await import("./setPrimaryDialogAgentAction-T3UTBEFG.js");
15477
+ const { setPrimaryDialogAgentAction } = await import("./setPrimaryDialogAgentAction-DOCIS6V4.js");
15378
15478
  return setPrimaryDialogAgentAction(args, thunkApi);
15379
15479
  };
15380
15480
  var runSetDialogExtraReferencesAction = async (args, thunkApi) => {
15381
- const { setDialogExtraReferencesAction } = await import("./setDialogExtraReferencesAction-6RKUSXHX.js");
15481
+ const { setDialogExtraReferencesAction } = await import("./setDialogExtraReferencesAction-OMTEO7X6.js");
15382
15482
  return setDialogExtraReferencesAction(args, thunkApi);
15383
15483
  };
15384
15484
  var runHandleSendMessageAction = async (args, thunkApi) => {
15385
- const { handleSendMessageAction } = await import("./handleSendMessageAction-JYETO5RZ.js");
15485
+ const { handleSendMessageAction } = await import("./handleSendMessageAction-MMATC5V5.js");
15386
15486
  return handleSendMessageAction(args, thunkApi);
15387
15487
  };
15388
15488
  function clearDialogState() {
@@ -15395,7 +15495,7 @@ var createPageAndAddReference = createAsyncThunk(
15395
15495
  async (payload, { dispatch, getState, rejectWithValue }) => {
15396
15496
  const { slateData, jsonData, title, type, fileId, groupId, dialogKey } = payload;
15397
15497
  try {
15398
- const { createDocState } = await import("./docStore-SV7E34D4.js");
15498
+ const { createDocState } = await import("./docStore-VDWTATFH.js");
15399
15499
  const pageKey = await createDocState(
15400
15500
  { slateData, title },
15401
15501
  { dispatch, getState }
@@ -19352,11 +19452,11 @@ var ENTITY_DELETE_STRATEGIES = {
19352
19452
  await dispatch(deleteTable({ dbKey: key })).unwrap();
19353
19453
  },
19354
19454
  file: async (key, { thunkAPI }) => {
19355
- const { deleteFileAction } = await import("./deleteFile-OW53A6BX.js");
19455
+ const { deleteFileAction } = await import("./deleteFile-WPWVZE4B.js");
19356
19456
  await deleteFileAction(key, thunkAPI);
19357
19457
  },
19358
19458
  image: async (key, { thunkAPI }) => {
19359
- const { deleteFileAction } = await import("./deleteFile-OW53A6BX.js");
19459
+ const { deleteFileAction } = await import("./deleteFile-WPWVZE4B.js");
19360
19460
  await deleteFileAction(key, thunkAPI);
19361
19461
  },
19362
19462
  agent: async (key, { dispatch, userId, sourceServerOrigin }) => {
@@ -21524,7 +21624,7 @@ var fetchSpaceAction = async (input, thunkAPI) => {
21524
21624
  const spaceKey = createSpaceKey.space(spaceId);
21525
21625
  const readSpace = async (dbKey) => {
21526
21626
  try {
21527
- const { read: read2, readAndWait: readAndWait2 } = await import("./dbSlice-Q3TM2FJV.js");
21627
+ const { read: read2, readAndWait: readAndWait2 } = await import("./dbSlice-R5EJKZBW.js");
21528
21628
  if (fresh) {
21529
21629
  return await dispatch(readAndWait2(dbKey)).unwrap();
21530
21630
  }
@@ -22195,6 +22295,7 @@ export {
22195
22295
  PERSONALIZATION_DIALOG_CATEGORY,
22196
22296
  buildPersonalizationDialogPolicyContext,
22197
22297
  resolveHandleSendMessageContext,
22298
+ estimateMissingUsage,
22198
22299
  selectCurrentDialogId,
22199
22300
  selectAllMsgs,
22200
22301
  selectMsgById,
@@ -22272,6 +22373,8 @@ export {
22272
22373
  selectViewMode,
22273
22374
  spaceSlice_default,
22274
22375
  selectCurrentUserBalance,
22376
+ API_REPORTED_COST_MULTIPLIER,
22377
+ shouldUseServerProxy,
22275
22378
  updateTokensAction,
22276
22379
  clearDialogState,
22277
22380
  createPageAndAddReference,