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

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 (112) hide show
  1. package/{_executeModel-42U3VOVZ.js → _executeModel-YXTTYRXS.js} +44 -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-4NO7Y6UI.js} +28 -27
  6. package/{agentEmailCommands-6FACJBU4.js → agentEmailCommands-NPP5TGZV.js} +60 -58
  7. package/{agentListCommands-I6KZYCIG.js → agentListCommands-IP5BNB5W.js} +32 -30
  8. package/{agentMachineCommands-VKLIGMZA.js → agentMachineCommands-24NFTIKY.js} +27 -26
  9. package/{agentPullCommand-O2MTUAFR.js → agentPullCommand-N6UWRTVL.js} +3 -3
  10. package/{agentRecordCommands-7TZICYDT.js → agentRecordCommands-7AWSR46F.js} +51 -49
  11. package/{agentRunCommand-L4OM23KV.js → agentRunCommand-P46WCJ6P.js} +55 -52
  12. package/{agentRunControl-K4VKNEHF.js → agentRunControl-S3G62M6C.js} +3 -3
  13. package/{agentRuntimeLocal-ZYEIPTY4.js → agentRuntimeLocal-V5UV7S4R.js} +14 -12
  14. package/{agentSlice-BX7GXSNO.js → agentSlice-3CVAZZOP.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-VUW5FBDB.js → chunk-4VA3UQRF.js} +9 -9
  19. package/{chunk-2JCXITPK.js → chunk-5NYGMN4O.js} +15 -15
  20. package/{chunk-AGFH73SK.js → chunk-6KRA6AWI.js} +1 -1
  21. package/{chunk-P3PKED2I.js → chunk-6OHYC4BY.js} +9 -12
  22. package/{chunk-5KLGBAAR.js → chunk-6UUD2WES.js} +1 -1
  23. package/{chunk-ENOG22KJ.js → chunk-A4MYG3TR.js} +18 -20
  24. package/{chunk-2FTTDCD4.js → chunk-AMJ7LA5D.js} +1 -1
  25. package/chunk-AOKWJZ5N.js +4884 -0
  26. package/{chunk-JRKKFRAV.js → chunk-AWY2AFHN.js} +9 -5
  27. package/{chunk-RL776AGR.js → chunk-BB2PII22.js} +1 -1
  28. package/{chunk-I6XMPTMR.js → chunk-BFDWXLFF.js} +2 -2
  29. package/{chunk-VVX233PH.js → chunk-BT37DVDA.js} +9 -9
  30. package/chunk-BYXBJQAS.js +0 -0
  31. package/{chunk-C3RUNRHT.js → chunk-D55DXHXL.js} +1 -1
  32. package/{chunk-7DAJ4AI4.js → chunk-DSNLHTP3.js} +2 -2
  33. package/{chunk-SDJDLO5W.js → chunk-EUN3SYY7.js} +5 -5
  34. package/{chunk-FSO5B7GH.js → chunk-HAC6GPRE.js} +2 -2
  35. package/{chunk-CKOJQDKR.js → chunk-JEMATI63.js} +1 -1
  36. package/{chunk-7U44LYTR.js → chunk-JTINRTBT.js} +1 -1
  37. package/{chunk-YPRZSPF3.js → chunk-KLOCUWKZ.js} +1 -1
  38. package/{chunk-4O3CARJ4.js → chunk-KTHLAJEY.js} +1 -1
  39. package/{chunk-URUUZLPA.js → chunk-L3KWEH3V.js} +8 -8
  40. package/{chunk-O2ZNTTET.js → chunk-LBUTKV7S.js} +21 -12
  41. package/{chunk-GU3PEVGZ.js → chunk-LFFATN2M.js} +2632 -1578
  42. package/{chunk-UB6SN4NJ.js → chunk-LJCH34R2.js} +6 -6
  43. package/{chunk-5EFXE3O7.js → chunk-LTH6AVG7.js} +3 -3
  44. package/{chunk-7GNGZRLZ.js → chunk-LW6FJFCT.js} +45 -67
  45. package/{chunk-7KCUSYT2.js → chunk-MIQOUMSN.js} +7 -7
  46. package/{chunk-FVYY6MCS.js → chunk-O7VS7JLJ.js} +17 -17
  47. package/{chunk-RCSJFQPB.js → chunk-P7GAHW32.js} +361 -90
  48. package/{chunk-AL2KDGR2.js → chunk-PTT6KSYQ.js} +134 -84
  49. package/{chunk-4IJYA27C.js → chunk-PXZAAB4L.js} +4 -4
  50. package/{chunk-4XENYTF5.js → chunk-Q2WC4KGQ.js} +3 -3
  51. package/{chunk-4QEWT7KD.js → chunk-RBB43B5W.js} +367 -85
  52. package/chunk-RBCENBG7.js +36 -0
  53. package/{chunk-IWX4UW2E.js → chunk-RBCNBU2A.js} +88 -8
  54. package/{chunk-25LCXTML.js → chunk-RQPZX6KP.js} +2 -2
  55. package/{chunk-6KHNO3SK.js → chunk-RYMUT5JO.js} +23 -23
  56. package/{chunk-VX3SXJ3N.js → chunk-UBSKX3LP.js} +6 -6
  57. package/{chunk-4ZDM73SD.js → chunk-V2J635L5.js} +1 -1
  58. package/{chunk-DSZUWUYB.js → chunk-VBKJTOAW.js} +1 -1
  59. package/{chunk-XBUBEFNX.js → chunk-WESWWEVA.js} +1 -1
  60. package/{chunk-2ECQG4YX.js → chunk-ZAUDEKML.js} +253 -159
  61. package/{chunk-N54XAP77.js → chunk-ZJS64PZJ.js} +1 -1
  62. package/{createAgentAutomationAction-RJF3N2QY.js → createAgentAutomationAction-DYQOGAVE.js} +25 -24
  63. package/{createDialogAction-DRSPS6CE.js → createDialogAction-ETB3KQQE.js} +25 -24
  64. package/{createPageAction-6B2WMNO3.js → createPageAction-UF2RHA63.js} +25 -24
  65. package/{dbSlice-Q3TM2FJV.js → dbSlice-R5EJKZBW.js} +7 -7
  66. package/{deleteFile-OW53A6BX.js → deleteFile-WPWVZE4B.js} +5 -5
  67. package/{dialogCommands-4IX4XIZE.js → dialogCommands-LYYC7XHF.js} +23 -22
  68. package/{dialogSlice-3M7KX2TX.js → dialogSlice-IFBZ4IT2.js} +24 -23
  69. package/{docCreateCommands-SIL3NPGT.js → docCreateCommands-I66OI374.js} +22 -21
  70. package/{docDeleteCommands-7IOMLUS4.js → docDeleteCommands-OVRBCHMF.js} +23 -22
  71. package/{docReadCommands-FNFXUA5L.js → docReadCommands-YLWUMEH7.js} +22 -21
  72. package/{docStore-SV7E34D4.js → docStore-65WO7U36.js} +24 -23
  73. package/{docUpdateCommands-X2HNDVUC.js → docUpdateCommands-NSICS4IN.js} +22 -21
  74. package/fetchMessages-KTNM7QAR.js +1 -1
  75. package/{getPricing-3E6UNPKL.js → getPricing-7PUT44ZS.js} +7 -3
  76. package/{handleSendMessageAction-JYETO5RZ.js → handleSendMessageAction-T76HEDOP.js} +29 -28
  77. package/index.js +74 -74
  78. package/{localDialogRead-2VRI24F4.js → localDialogRead-YSKFFRTT.js} +1 -1
  79. package/{machineCommands-RIO3RP5Q.js → machineCommands-4HQY6UVZ.js} +57 -55
  80. package/{machineWsRunDispatch-W7UYLGB5.js → machineWsRunDispatch-7YW2M4FS.js} +49 -47
  81. package/{memoryCommands-O4MIPIWQ.js → memoryCommands-HG4WKTU7.js} +2 -2
  82. package/{models-4OPOOLFS.js → models-MFXNI3TF.js} +2 -2
  83. package/package.json +1 -1
  84. package/{read-GW7ZEI23.js → read-5ZMY7FKP.js} +5 -5
  85. package/{readDocTool-HUFU6OCT.js → readDocTool-2NXDK32S.js} +1 -1
  86. package/{readlineWorkspace-27JR7WPW.js → readlineWorkspace-FLQWOAUR.js} +759 -604
  87. package/{removeDialogAgentAction-CXKR4NJI.js → removeDialogAgentAction-KOLQ2R5W.js} +13 -12
  88. package/{runAgentClientLoop-HZFAPJHS.js → runAgentClientLoop-IUV2TR3X.js} +43 -42
  89. package/{runtimeDoctorCommands-LRHLPDRC.js → runtimeDoctorCommands-UWR5UDSM.js} +5 -5
  90. package/{setDialogExtraReferencesAction-6RKUSXHX.js → setDialogExtraReferencesAction-OMTEO7X6.js} +10 -10
  91. package/{setPrimaryDialogAgentAction-T3UTBEFG.js → setPrimaryDialogAgentAction-DOCIS6V4.js} +13 -12
  92. package/{settingSlice-IVKXJXMG.js → settingSlice-UWZJYDOA.js} +8 -8
  93. package/{spaceCommands-E7VOF4LO.js → spaceCommands-BDDAT4VU.js} +29 -28
  94. package/{spaceSlice-TSVROA5U.js → spaceSlice-HH633ZA4.js} +23 -22
  95. package/{streamAgentChatTurn-3C5RQZJF.js → streamAgentChatTurn-UBZOVFKV.js} +95 -72
  96. package/{tableCommands-O7O2LBEG.js → tableCommands-M3DJUETS.js} +10 -10
  97. package/{toolApiClient-QI3YBNWB.js → toolApiClient-C7P7YSE4.js} +2 -2
  98. package/{tools-EQDEKR6N.js → tools-OQZ34KCU.js} +31 -30
  99. package/{tuiSummaryLlmCaller-RV3THLZF.js → tuiSummaryLlmCaller-42AEL3LL.js} +8 -6
  100. package/{updateCommands-VOSPKXFF.js → updateCommands-TC5SX42Y.js} +3 -3
  101. package/{updateDialogTitleAction-3XV7VWSZ.js → updateDialogTitleAction-A3OOMSDO.js} +27 -26
  102. package/chunk-BBYVOSU2.js +0 -792
  103. package/chunk-DCOA4QSN.js +0 -105
  104. package/{chunk-DZ3XJVET.js → chunk-3QAF2LTL.js} +3 -3
  105. package/{chunk-EHLHSX7R.js → chunk-5MMZUWSG.js} +3 -3
  106. package/{chunk-ISNCLGUZ.js → chunk-AVMJVOQY.js} +3 -3
  107. package/{chunk-UTLZINAP.js → chunk-DVRHHFEA.js} +10 -10
  108. package/{chunk-4CQLVGRV.js → chunk-ID4G2MAR.js} +3 -3
  109. package/{chunk-5MIDPSSK.js → chunk-JK7VW2FN.js} +3 -3
  110. package/{chunk-TILFE6LV.js → chunk-YOCHZD7D.js} +3 -3
  111. package/{db-HCJ5PRB5.js → db-6QED3ZVO.js} +3 -3
  112. 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-4VA3UQRF.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-RBCENBG7.js";
68
+ import {
69
+ MODEL_LOOKUP_MAP,
70
+ findModelConfig,
71
+ getModelConfig
72
+ } from "./chunk-AOKWJZ5N.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-3CVAZZOP.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,7 +14961,59 @@ 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,
@@ -14980,18 +15033,27 @@ var prepareTokenUsageData = ({
14980
15033
  const billedModel = billingTarget.model;
14981
15034
  const billedServiceTier = billingTarget.serviceTier;
14982
15035
  const recordProvider = billedProvider ?? agentConfig.provider ?? "unknown";
15036
+ const hasExternalPrice = agentConfig.inputPrice !== void 0 && agentConfig.inputPrice > 0 || agentConfig.outputPrice !== void 0 && agentConfig.outputPrice > 0;
14983
15037
  const { cost, pay } = calculatePrice({
14984
15038
  provider: billedProvider,
14985
15039
  modelName: billedModel,
14986
15040
  billingServiceTier: billedServiceTier,
14987
15041
  usage,
14988
- externalPrice: agentConfig.id ? {
15042
+ externalPrice: hasExternalPrice ? {
14989
15043
  input: agentConfig.inputPrice ?? 0,
14990
15044
  output: agentConfig.outputPrice ?? 0,
14991
- creatorId: agentConfig.userId ?? extractUserId(agentConfig.id)
15045
+ creatorId: agentConfig.userId ?? (agentConfig.id ? extractUserId(agentConfig.id) : "")
14992
15046
  } : void 0,
14993
15047
  sharingLevel: agentConfig.sharingLevel
14994
15048
  });
15049
+ const billable = resolveBillable({
15050
+ usage,
15051
+ userId,
15052
+ apiSource: agentConfig.apiSource,
15053
+ apiKeyRef: agentConfig.apiKeyRef,
15054
+ cost,
15055
+ hasExternalPrice
15056
+ });
14995
15057
  return {
14996
15058
  usage,
14997
15059
  billedProvider,
@@ -15009,11 +15071,66 @@ var prepareTokenUsageData = ({
15009
15071
  dialogId,
15010
15072
  cost,
15011
15073
  pay,
15012
- timestamp
15074
+ timestamp,
15075
+ billable
15013
15076
  }
15014
15077
  };
15015
15078
  };
15016
15079
 
15080
+ // packages/ai/token/applyTokenUsageToDayStats.ts
15081
+ var ZERO_STATS = { count: 0, tokens: { input: 0, output: 0 }, cost: 0 };
15082
+ function applyTokenUsageToDayStats(prev, delta) {
15083
+ const base = prev ?? {
15084
+ userId: delta.userId,
15085
+ period: "day",
15086
+ timeKey: delta.timeKey,
15087
+ total: { ...ZERO_STATS },
15088
+ models: {},
15089
+ providers: {}
15090
+ };
15091
+ const modelName = delta.model || "unknown";
15092
+ const providerName2 = delta.provider || "unknown";
15093
+ const inc = (s) => ({
15094
+ count: (s?.count ?? 0) + 1,
15095
+ tokens: {
15096
+ input: (s?.tokens.input ?? 0) + delta.input_tokens,
15097
+ output: (s?.tokens.output ?? 0) + delta.output_tokens
15098
+ },
15099
+ cost: Number(((s?.cost ?? 0) + delta.cost).toFixed(6))
15100
+ });
15101
+ return {
15102
+ ...base,
15103
+ total: inc(base.total),
15104
+ models: {
15105
+ ...base.models,
15106
+ [modelName]: inc(base.models[modelName])
15107
+ },
15108
+ providers: {
15109
+ ...base.providers,
15110
+ [providerName2]: inc(base.providers[providerName2])
15111
+ }
15112
+ };
15113
+ }
15114
+
15115
+ // packages/core/keyedTaskQueue.ts
15116
+ var queues = /* @__PURE__ */ new Map();
15117
+ async function runKeyed(key, task) {
15118
+ const previous = queues.get(key) ?? Promise.resolve();
15119
+ const next = previous.catch(() => void 0).then(task);
15120
+ const cleanup = next.then(
15121
+ () => void 0,
15122
+ () => void 0
15123
+ );
15124
+ queues.set(key, cleanup);
15125
+ try {
15126
+ return await next;
15127
+ } finally {
15128
+ if (queues.get(key) === cleanup) {
15129
+ queues.delete(key);
15130
+ }
15131
+ }
15132
+ }
15133
+
15017
15134
  // packages/chat/dialog/actions/updateTokensAction.ts
15018
15135
  var logger3 = createClientLogger("token-usage");
15019
15136
  var dialogTokenPatchQueue = /* @__PURE__ */ new Map();
@@ -15033,53 +15150,26 @@ var queueDialogTokenPatch = async (dialogKey, task) => {
15033
15150
  }
15034
15151
  }
15035
15152
  };
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
15153
  var updateStats = async (data, existingStats, key, thunkApi) => {
15045
15154
  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
- };
15155
+ const dateKey = (0, import_date_fns.format)(data.timestamp ?? Date.now(), "yyyy-MM-dd");
15156
+ const newStats = applyTokenUsageToDayStats(existingStats, {
15157
+ userId: data.userId ?? "",
15158
+ timeKey: dateKey,
15159
+ model: data.model || "unknown",
15160
+ provider: data.provider || "unknown",
15161
+ input_tokens: data.input_tokens,
15162
+ output_tokens: data.output_tokens,
15163
+ cost: data.cost
15164
+ });
15073
15165
  await thunkApi.dispatch(
15074
15166
  write({
15075
- data: { ...updatedStats, id: key, type: "token" /* TOKEN */ },
15167
+ data: { ...newStats, id: key, type: "token" /* TOKEN */ },
15076
15168
  customKey: key,
15077
- // Must stamp owner on writeConfig: writeAction overwrites data.userId
15078
- // from writeConfig.userId || currentUserId (empty when logged out).
15079
15169
  userId: data.userId
15080
15170
  })
15081
- );
15082
- return updatedStats;
15171
+ ).unwrap();
15172
+ return newStats;
15083
15173
  } catch (error) {
15084
15174
  logger3.error(
15085
15175
  { key, userId: data.userId, error: error.message },
@@ -15090,45 +15180,47 @@ var updateStats = async (data, existingStats, key, thunkApi) => {
15090
15180
  }
15091
15181
  };
15092
15182
  var saveTokenUsage = async (data, thunkApi) => {
15093
- const dateKey = (0, import_date_fns.format)(Date.now(), "yyyy-MM-dd");
15183
+ const dateKey = (0, import_date_fns.format)(data.timestamp ?? Date.now(), "yyyy-MM-dd");
15094
15184
  const tokenDayStatsKey = createTokenStatsKey(data.userId ?? "", dateKey);
15095
- try {
15096
- let currentStats = null;
15185
+ return runKeyed(tokenDayStatsKey, async () => {
15097
15186
  try {
15098
- currentStats = await thunkApi.dispatch(read({
15099
- dbKey: tokenDayStatsKey
15100
- })).unwrap();
15101
- } catch (err) {
15102
- logger3.warn({ tokenDayStatsKey }, "No existing stats found");
15187
+ let currentStats = null;
15188
+ try {
15189
+ currentStats = await thunkApi.dispatch(read({
15190
+ dbKey: tokenDayStatsKey
15191
+ })).unwrap();
15192
+ } catch (err) {
15193
+ logger3.warn({ tokenDayStatsKey }, "No existing stats found");
15194
+ }
15195
+ const updatedStats = await updateStats(
15196
+ data,
15197
+ currentStats,
15198
+ tokenDayStatsKey,
15199
+ thunkApi
15200
+ );
15201
+ return {
15202
+ success: true,
15203
+ id: ulid3(Date.now()),
15204
+ record: updatedStats
15205
+ };
15206
+ } catch (error) {
15207
+ logger3.error(
15208
+ {
15209
+ key: tokenDayStatsKey,
15210
+ userId: data.userId,
15211
+ error: error.message,
15212
+ tokenData: {
15213
+ input: data.input_tokens,
15214
+ output: data.output_tokens,
15215
+ model: data.model
15216
+ }
15217
+ },
15218
+ "Failed to process token usage"
15219
+ );
15220
+ toast.error("Failed to process token usage");
15221
+ throw error;
15103
15222
  }
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
- }
15223
+ });
15132
15224
  };
15133
15225
  var updateTokensAction = async ({ dialogId, dialogKey, usage: usageRaw, agentConfig }, thunkApi) => {
15134
15226
  const state3 = thunkApi.getState();
@@ -15169,7 +15261,7 @@ var updateTokensAction = async ({ dialogId, dialogKey, usage: usageRaw, agentCon
15169
15261
  });
15170
15262
  await saveTokenRecord(persistedTokenData, record, thunkApi);
15171
15263
  await saveTokenUsage(persistedTokenData, thunkApi);
15172
- if (result.cost > 0) {
15264
+ if (persistedTokenData.billable === true || persistedTokenData.billable === void 0 && result.cost > 0) {
15173
15265
  thunkApi.dispatch(deductBalance(result.cost));
15174
15266
  }
15175
15267
  if (dialogKey) {
@@ -15283,7 +15375,7 @@ var deleteOwnedDialogAttachments = async (args) => {
15283
15375
  metadataReadFailures
15284
15376
  });
15285
15377
  if (!plan.deleteCandidates.length) return plan;
15286
- const { deleteFileAction } = await import("./deleteFile-OW53A6BX.js");
15378
+ const { deleteFileAction } = await import("./deleteFile-WPWVZE4B.js");
15287
15379
  for (const candidate of plan.deleteCandidates) {
15288
15380
  if (candidate.fileDbKey) {
15289
15381
  await deleteFileAction(candidate.fileDbKey, args.thunkApi);
@@ -15345,7 +15437,7 @@ var deleteDialogThunk = async (payload, thunkApi) => {
15345
15437
  }
15346
15438
  if (isCurrentDialog) {
15347
15439
  await thunkApi.dispatch(resetMsgs());
15348
- const { clearPendingAttachments: clearPendingAttachments2 } = await import("./dialogSlice-3M7KX2TX.js");
15440
+ const { clearPendingAttachments: clearPendingAttachments2 } = await import("./dialogSlice-IFBZ4IT2.js");
15349
15441
  dispatch(clearPendingAttachments2());
15350
15442
  clearWorkflow();
15351
15443
  }
@@ -15354,35 +15446,35 @@ var deleteDialogThunk = async (payload, thunkApi) => {
15354
15446
 
15355
15447
  // packages/chat/dialog/dialogSlice.ts
15356
15448
  var runCreateDialogAction = async (args, thunkApi) => {
15357
- const { createDialogAction } = await import("./createDialogAction-DRSPS6CE.js");
15449
+ const { createDialogAction } = await import("./createDialogAction-ETB3KQQE.js");
15358
15450
  return createDialogAction(args, thunkApi);
15359
15451
  };
15360
15452
  var runCreateAgentAutomationAction = async (args, thunkApi) => {
15361
- const { createAgentAutomationAction } = await import("./createAgentAutomationAction-RJF3N2QY.js");
15453
+ const { createAgentAutomationAction } = await import("./createAgentAutomationAction-DYQOGAVE.js");
15362
15454
  return createAgentAutomationAction(args, thunkApi);
15363
15455
  };
15364
15456
  var runUpdateDialogTitleAction = async (args, thunkApi) => {
15365
- const { updateDialogTitleAction } = await import("./updateDialogTitleAction-3XV7VWSZ.js");
15457
+ const { updateDialogTitleAction } = await import("./updateDialogTitleAction-A3OOMSDO.js");
15366
15458
  return updateDialogTitleAction(args, thunkApi);
15367
15459
  };
15368
15460
  var runAddDialogAgentAction = async (args, thunkApi) => {
15369
- const { addDialogAgentAction } = await import("./addDialogAgentAction-G3VWEA6E.js");
15461
+ const { addDialogAgentAction } = await import("./addDialogAgentAction-MUBYOG65.js");
15370
15462
  return addDialogAgentAction(args, thunkApi);
15371
15463
  };
15372
15464
  var runRemoveDialogAgentAction = async (args, thunkApi) => {
15373
- const { removeDialogAgentAction } = await import("./removeDialogAgentAction-CXKR4NJI.js");
15465
+ const { removeDialogAgentAction } = await import("./removeDialogAgentAction-KOLQ2R5W.js");
15374
15466
  return removeDialogAgentAction(args, thunkApi);
15375
15467
  };
15376
15468
  var runSetPrimaryDialogAgentAction = async (args, thunkApi) => {
15377
- const { setPrimaryDialogAgentAction } = await import("./setPrimaryDialogAgentAction-T3UTBEFG.js");
15469
+ const { setPrimaryDialogAgentAction } = await import("./setPrimaryDialogAgentAction-DOCIS6V4.js");
15378
15470
  return setPrimaryDialogAgentAction(args, thunkApi);
15379
15471
  };
15380
15472
  var runSetDialogExtraReferencesAction = async (args, thunkApi) => {
15381
- const { setDialogExtraReferencesAction } = await import("./setDialogExtraReferencesAction-6RKUSXHX.js");
15473
+ const { setDialogExtraReferencesAction } = await import("./setDialogExtraReferencesAction-OMTEO7X6.js");
15382
15474
  return setDialogExtraReferencesAction(args, thunkApi);
15383
15475
  };
15384
15476
  var runHandleSendMessageAction = async (args, thunkApi) => {
15385
- const { handleSendMessageAction } = await import("./handleSendMessageAction-JYETO5RZ.js");
15477
+ const { handleSendMessageAction } = await import("./handleSendMessageAction-T76HEDOP.js");
15386
15478
  return handleSendMessageAction(args, thunkApi);
15387
15479
  };
15388
15480
  function clearDialogState() {
@@ -15395,7 +15487,7 @@ var createPageAndAddReference = createAsyncThunk(
15395
15487
  async (payload, { dispatch, getState, rejectWithValue }) => {
15396
15488
  const { slateData, jsonData, title, type, fileId, groupId, dialogKey } = payload;
15397
15489
  try {
15398
- const { createDocState } = await import("./docStore-SV7E34D4.js");
15490
+ const { createDocState } = await import("./docStore-65WO7U36.js");
15399
15491
  const pageKey = await createDocState(
15400
15492
  { slateData, title },
15401
15493
  { dispatch, getState }
@@ -19352,11 +19444,11 @@ var ENTITY_DELETE_STRATEGIES = {
19352
19444
  await dispatch(deleteTable({ dbKey: key })).unwrap();
19353
19445
  },
19354
19446
  file: async (key, { thunkAPI }) => {
19355
- const { deleteFileAction } = await import("./deleteFile-OW53A6BX.js");
19447
+ const { deleteFileAction } = await import("./deleteFile-WPWVZE4B.js");
19356
19448
  await deleteFileAction(key, thunkAPI);
19357
19449
  },
19358
19450
  image: async (key, { thunkAPI }) => {
19359
- const { deleteFileAction } = await import("./deleteFile-OW53A6BX.js");
19451
+ const { deleteFileAction } = await import("./deleteFile-WPWVZE4B.js");
19360
19452
  await deleteFileAction(key, thunkAPI);
19361
19453
  },
19362
19454
  agent: async (key, { dispatch, userId, sourceServerOrigin }) => {
@@ -21524,7 +21616,7 @@ var fetchSpaceAction = async (input, thunkAPI) => {
21524
21616
  const spaceKey = createSpaceKey.space(spaceId);
21525
21617
  const readSpace = async (dbKey) => {
21526
21618
  try {
21527
- const { read: read2, readAndWait: readAndWait2 } = await import("./dbSlice-Q3TM2FJV.js");
21619
+ const { read: read2, readAndWait: readAndWait2 } = await import("./dbSlice-R5EJKZBW.js");
21528
21620
  if (fresh) {
21529
21621
  return await dispatch(readAndWait2(dbKey)).unwrap();
21530
21622
  }
@@ -22195,6 +22287,7 @@ export {
22195
22287
  PERSONALIZATION_DIALOG_CATEGORY,
22196
22288
  buildPersonalizationDialogPolicyContext,
22197
22289
  resolveHandleSendMessageContext,
22290
+ estimateMissingUsage,
22198
22291
  selectCurrentDialogId,
22199
22292
  selectAllMsgs,
22200
22293
  selectMsgById,
@@ -22272,6 +22365,7 @@ export {
22272
22365
  selectViewMode,
22273
22366
  spaceSlice_default,
22274
22367
  selectCurrentUserBalance,
22368
+ shouldUseServerProxy,
22275
22369
  updateTokensAction,
22276
22370
  clearDialogState,
22277
22371
  createPageAndAddReference,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  buildAgentRuntimeAgentLookupKeys,
3
3
  shouldFetchAgentRuntimeRecordRemotely
4
- } from "./chunk-O2ZNTTET.js";
4
+ } from "./chunk-LBUTKV7S.js";
5
5
 
6
6
  // packages/cli/client/localAgentRecords.ts
7
7
  var buildLocalAgentLookupKeys = buildAgentRuntimeAgentLookupKeys;