nolo-cli 0.8.0-alpha.20 → 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 (113) hide show
  1. package/{_executeModel-WRUCQIV5.js → _executeModel-YXTTYRXS.js} +45 -44
  2. package/{action-R4M4ORGA.js → action-QM2ONPYZ.js} +10 -10
  3. package/{addContentAction-UYFFTEWJ.js → addContentAction-UXY3GM53.js} +9 -9
  4. package/{addDialogAgentAction-OT4XZAVP.js → addDialogAgentAction-MUBYOG65.js} +11 -11
  5. package/{agentDeleteCommand-5DD2IM3J.js → agentDeleteCommand-4NO7Y6UI.js} +28 -27
  6. package/{agentEmailCommands-IASM2YBQ.js → agentEmailCommands-NPP5TGZV.js} +61 -59
  7. package/{agentListCommands-I6KZYCIG.js → agentListCommands-IP5BNB5W.js} +32 -30
  8. package/{agentMachineCommands-OUP3YQP7.js → agentMachineCommands-24NFTIKY.js} +27 -26
  9. package/{agentPullCommand-O2MTUAFR.js → agentPullCommand-N6UWRTVL.js} +3 -3
  10. package/{agentRecordCommands-QKGE2JTA.js → agentRecordCommands-7AWSR46F.js} +52 -50
  11. package/{agentRunCommand-TVZXUBQ5.js → agentRunCommand-P46WCJ6P.js} +56 -53
  12. package/{agentRunControl-K4VKNEHF.js → agentRunControl-S3G62M6C.js} +3 -3
  13. package/{agentRuntimeLocal-ZYEIPTY4.js → agentRuntimeLocal-V5UV7S4R.js} +14 -12
  14. package/{agentSlice-T4PMW7W6.js → agentSlice-3CVAZZOP.js} +10 -10
  15. package/{authCommand-EB5JSOX5.js → authCommand-B6P2XYLN.js} +11 -11
  16. package/{authCommands-XPEHTKSM.js → authCommands-4YKA4GTU.js} +7 -7
  17. package/{chunk-PMKQGGGM.js → chunk-2CVZSC5L.js} +1 -1
  18. package/{chunk-4FBRSEV4.js → chunk-4VA3UQRF.js} +9 -9
  19. package/{chunk-BCIOM4NZ.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-QJ7FZNYN.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-RGIM3WLT.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-XBROXIGL.js → chunk-DVRHHFEA.js} +11 -11
  34. package/{chunk-SDJDLO5W.js → chunk-EUN3SYY7.js} +5 -5
  35. package/{chunk-7T5PWAZN.js → chunk-HAC6GPRE.js} +2 -2
  36. package/{chunk-CKOJQDKR.js → chunk-JEMATI63.js} +1 -1
  37. package/{chunk-GLYVN7EQ.js → chunk-JTINRTBT.js} +2 -2
  38. package/{chunk-YPRZSPF3.js → chunk-KLOCUWKZ.js} +1 -1
  39. package/{chunk-TIMLUWQA.js → chunk-KTHLAJEY.js} +1 -1
  40. package/{chunk-TISCADJH.js → chunk-L3KWEH3V.js} +9 -9
  41. package/{chunk-O2ZNTTET.js → chunk-LBUTKV7S.js} +21 -12
  42. package/{chunk-FM5IVZXO.js → chunk-LFFATN2M.js} +2632 -1578
  43. package/{chunk-IJGXKGXW.js → chunk-LJCH34R2.js} +6 -6
  44. package/{chunk-Z6EKEXJW.js → chunk-LTH6AVG7.js} +4 -4
  45. package/{chunk-PFTAG6DY.js → chunk-LW6FJFCT.js} +46 -68
  46. package/{chunk-7KCUSYT2.js → chunk-MIQOUMSN.js} +7 -7
  47. package/{chunk-FVYY6MCS.js → chunk-O7VS7JLJ.js} +17 -17
  48. package/{chunk-WI4XWASA.js → chunk-OOSFSFMA.js} +82 -19
  49. package/{chunk-YN4XDB7B.js → chunk-P7GAHW32.js} +361 -90
  50. package/{chunk-ZDRZMLKO.js → chunk-PTT6KSYQ.js} +135 -85
  51. package/{chunk-4IJYA27C.js → chunk-PXZAAB4L.js} +4 -4
  52. package/{chunk-MNJDFJND.js → chunk-Q2WC4KGQ.js} +3 -3
  53. package/{chunk-4QEWT7KD.js → chunk-RBB43B5W.js} +367 -85
  54. package/chunk-RBCENBG7.js +36 -0
  55. package/{chunk-IWX4UW2E.js → chunk-RBCNBU2A.js} +88 -8
  56. package/{chunk-PP4S6RTL.js → chunk-RQPZX6KP.js} +3 -3
  57. package/{chunk-2EHX7F5G.js → chunk-RYMUT5JO.js} +24 -24
  58. package/{chunk-K6BPOQLF.js → chunk-UBSKX3LP.js} +7 -7
  59. package/{chunk-4ZDM73SD.js → chunk-V2J635L5.js} +1 -1
  60. package/{chunk-K777STIO.js → chunk-VBKJTOAW.js} +2 -2
  61. package/{chunk-5W3VUFOX.js → chunk-WESWWEVA.js} +1 -1
  62. package/{chunk-IHBCLYEE.js → chunk-ZAUDEKML.js} +259 -179
  63. package/{chunk-N54XAP77.js → chunk-ZJS64PZJ.js} +1 -1
  64. package/{createAgentAutomationAction-CCABEOM6.js → createAgentAutomationAction-DYQOGAVE.js} +26 -25
  65. package/{createDialogAction-YPKF5ITI.js → createDialogAction-ETB3KQQE.js} +26 -25
  66. package/{createPageAction-YEZ7EK5F.js → createPageAction-UF2RHA63.js} +26 -25
  67. package/{dbSlice-QPVZHBOE.js → dbSlice-R5EJKZBW.js} +8 -8
  68. package/{deleteFile-SV5MS23W.js → deleteFile-WPWVZE4B.js} +6 -6
  69. package/{dialogCommands-4IX4XIZE.js → dialogCommands-LYYC7XHF.js} +23 -22
  70. package/{dialogSlice-OVTO7QGW.js → dialogSlice-IFBZ4IT2.js} +25 -24
  71. package/{docCreateCommands-SIL3NPGT.js → docCreateCommands-I66OI374.js} +22 -21
  72. package/{docDeleteCommands-7IOMLUS4.js → docDeleteCommands-OVRBCHMF.js} +23 -22
  73. package/{docReadCommands-FNFXUA5L.js → docReadCommands-YLWUMEH7.js} +22 -21
  74. package/{docStore-ZAYLW2HN.js → docStore-65WO7U36.js} +25 -24
  75. package/{docUpdateCommands-X2HNDVUC.js → docUpdateCommands-NSICS4IN.js} +22 -21
  76. package/fetchMessages-KTNM7QAR.js +1 -1
  77. package/{getPricing-3E6UNPKL.js → getPricing-7PUT44ZS.js} +7 -3
  78. package/{handleSendMessageAction-TZMZ4EP5.js → handleSendMessageAction-T76HEDOP.js} +30 -29
  79. package/index.js +74 -74
  80. package/{localDialogRead-2VRI24F4.js → localDialogRead-YSKFFRTT.js} +1 -1
  81. package/{machineCommands-M4ZJZIMS.js → machineCommands-4HQY6UVZ.js} +58 -56
  82. package/{machineWsRunDispatch-TPJAUGLP.js → machineWsRunDispatch-7YW2M4FS.js} +50 -48
  83. package/{memoryCommands-O4MIPIWQ.js → memoryCommands-HG4WKTU7.js} +2 -2
  84. package/{models-4OPOOLFS.js → models-MFXNI3TF.js} +2 -2
  85. package/package.json +1 -2
  86. package/{read-EBMWX4Z6.js → read-5ZMY7FKP.js} +6 -6
  87. package/{readDocTool-2MWHSTQE.js → readDocTool-2NXDK32S.js} +1 -1
  88. package/{readlineWorkspace-OMCIU3WT.js → readlineWorkspace-FLQWOAUR.js} +760 -605
  89. package/{removeDialogAgentAction-SNZ662NP.js → removeDialogAgentAction-KOLQ2R5W.js} +14 -13
  90. package/{runAgentClientLoop-H6NGOUAM.js → runAgentClientLoop-IUV2TR3X.js} +44 -43
  91. package/{runtimeDoctorCommands-LRHLPDRC.js → runtimeDoctorCommands-UWR5UDSM.js} +5 -5
  92. package/{setDialogExtraReferencesAction-XDI2KM2N.js → setDialogExtraReferencesAction-OMTEO7X6.js} +11 -11
  93. package/{setPrimaryDialogAgentAction-PYEC4N4Z.js → setPrimaryDialogAgentAction-DOCIS6V4.js} +14 -13
  94. package/{settingSlice-NOWHY2FK.js → settingSlice-UWZJYDOA.js} +9 -9
  95. package/{spaceCommands-E7VOF4LO.js → spaceCommands-BDDAT4VU.js} +29 -28
  96. package/{spaceSlice-QHBPICA2.js → spaceSlice-HH633ZA4.js} +24 -23
  97. package/{streamAgentChatTurn-3XTBA2HN.js → streamAgentChatTurn-UBZOVFKV.js} +96 -73
  98. package/{tableCommands-R5UCM63M.js → tableCommands-M3DJUETS.js} +11 -11
  99. package/{toolApiClient-QI3YBNWB.js → toolApiClient-C7P7YSE4.js} +2 -2
  100. package/{tools-GHLZ3XD6.js → tools-OQZ34KCU.js} +32 -31
  101. package/{tuiSummaryLlmCaller-RV3THLZF.js → tuiSummaryLlmCaller-42AEL3LL.js} +8 -6
  102. package/{updateCommands-VOSPKXFF.js → updateCommands-TC5SX42Y.js} +3 -3
  103. package/{updateDialogTitleAction-XA2OZTLP.js → updateDialogTitleAction-A3OOMSDO.js} +28 -27
  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-4CQLVGRV.js → chunk-ID4G2MAR.js} +3 -3
  110. package/{chunk-5MIDPSSK.js → chunk-JK7VW2FN.js} +3 -3
  111. package/{chunk-TILFE6LV.js → chunk-YOCHZD7D.js} +3 -3
  112. package/{db-HCJ5PRB5.js → db-6QED3ZVO.js} +3 -3
  113. 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-4FBRSEV4.js";
18
+ } from "./chunk-4VA3UQRF.js";
19
19
  import {
20
20
  cleanupCliSessionForDialog
21
- } from "./chunk-Z6EKEXJW.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-RGIM3WLT.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-K6BPOQLF.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-TISCADJH.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-K777STIO.js";
140
+ } from "./chunk-VBKJTOAW.js";
141
141
  import {
142
142
  DEVICE_LOCAL_OWNER_ID,
143
143
  asyncThunkCreator,
@@ -158,38 +158,39 @@ import {
158
158
  selectIdentityToken,
159
159
  selectIdentityUserId,
160
160
  selectRuntimeSnapshot
161
- } from "./chunk-XBROXIGL.js";
161
+ } from "./chunk-DVRHHFEA.js";
162
162
  import {
163
+ createClientLogger,
163
164
  fetchFromServer,
164
165
  fetchWithTransientReadRetry,
165
166
  getAllServers,
166
167
  isAbortError,
167
168
  logger
168
- } from "./chunk-WI4XWASA.js";
169
+ } from "./chunk-OOSFSFMA.js";
169
170
  import {
170
171
  buildTombstoneRecord,
171
172
  isTombstoneRecord,
172
173
  shouldReplaceWithNextRecord
173
174
  } from "./chunk-GBRG75BQ.js";
174
- import {
175
- API_ENDPOINTS,
176
- API_VERSION
177
- } from "./chunk-LCBAMY2M.js";
178
175
  import {
179
176
  asTrimmedString
180
177
  } from "./chunk-3EUW3WEO.js";
181
178
  import {
182
179
  asOptionalPositiveFiniteNumber
183
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";
184
188
  import {
185
189
  normalizeServerOrigin
186
190
  } from "./chunk-CF7PE763.js";
187
191
  import {
188
192
  asOptionalTrimmedString
189
193
  } from "./chunk-G3SUCT4W.js";
190
- import {
191
- isRecord
192
- } from "./chunk-KUG52IAP.js";
193
194
  import {
194
195
  __commonJS,
195
196
  __require,
@@ -11157,7 +11158,7 @@ var estimateMissingUsage = ({
11157
11158
  Math.ceil(text.length / APPROX_CHARS_PER_TOKEN)
11158
11159
  );
11159
11160
  return {
11160
- input_tokens: 1,
11161
+ input_tokens: 0,
11161
11162
  output_tokens: estimatedOutputTokens,
11162
11163
  cache_creation_input_tokens: 0,
11163
11164
  cache_read_input_tokens: 0,
@@ -11815,7 +11816,7 @@ async function captureUnderstandingFromCompletedUiTurn(input) {
11815
11816
  if (!input.agentKey) return;
11816
11817
  const latestUserInput = getLatestUserInputFromMessages(input.messages);
11817
11818
  if (!latestUserInput) return;
11818
- const { captureUnderstandingMemoryFromDialog } = await import("./understanding-3CUQQ6SV.js");
11819
+ const { captureUnderstandingMemoryFromDialog } = await import("./understanding-ZOESBLF3.js");
11819
11820
  await captureUnderstandingMemoryFromDialog({
11820
11821
  db: input.db,
11821
11822
  userId: selectIdentityUserId(input.state),
@@ -12740,7 +12741,7 @@ var messageSlice = createSliceWithThunks({
12740
12741
  runtimeOptions: args.runtimeOptions
12741
12742
  });
12742
12743
  if (agentKeyToUse) {
12743
- const { streamAgentChatTurn } = await import("./agentSlice-T4PMW7W6.js");
12744
+ const { streamAgentChatTurn } = await import("./agentSlice-3CVAZZOP.js");
12744
12745
  await dispatch(
12745
12746
  streamAgentChatTurn({
12746
12747
  agentKey: agentKeyToUse,
@@ -12862,8 +12863,7 @@ var import_date_fns = __toESM(require_date_fns());
12862
12863
  import { ulid as ulid3 } from "ulid";
12863
12864
 
12864
12865
  // packages/ai/token/saveTokenRecord.ts
12865
- import { pino } from "pino";
12866
- var logger2 = pino({ name: "token-record", level: "info" });
12866
+ var logger2 = createClientLogger("token-record");
12867
12867
  var createTokenRecord = (data, { cost, inputPrice, outputPrice } = {}) => ({
12868
12868
  ...data,
12869
12869
  cost: cost || data.cost,
@@ -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
  {
@@ -12899,9 +12896,6 @@ var saveTokenRecord = async (tokenData, record, thunkApi) => {
12899
12896
  }
12900
12897
  };
12901
12898
 
12902
- // packages/chat/dialog/actions/updateTokensAction.ts
12903
- import { pino as pino2 } from "pino";
12904
-
12905
12899
  // packages/core/generateMainKey.ts
12906
12900
  import nacl from "tweetnacl";
12907
12901
  var generateUserIdV1 = (publicKey, username, language, extra = "") => {
@@ -14567,6 +14561,10 @@ var selectCurrentToken = (state3) => state3.auth.currentToken;
14567
14561
  var selectCurrentUserBalance = (state3) => state3.auth.currentUser?.balance;
14568
14562
 
14569
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
+ };
14570
14568
  var resolveModelPrice = (model, usage) => {
14571
14569
  let activePrice = { ...model.price };
14572
14570
  if (model.pricingStrategy?.type === "tiered_context") {
@@ -14842,7 +14840,7 @@ var calculatePrice = ({
14842
14840
  billingServiceTier
14843
14841
  );
14844
14842
  const pay2 = calculatePayDistribution(costs2, externalPrice, sharingLevel);
14845
- return { cost: Number(costs2.charge.toFixed(6)), pay: pay2 };
14843
+ return { cost: sanitizeCost(costs2.charge), pay: pay2 };
14846
14844
  }
14847
14845
  const costs = calculateBasicCost(
14848
14846
  model,
@@ -14863,7 +14861,7 @@ var calculatePrice = ({
14863
14861
  } : costs;
14864
14862
  const pay = calculatePayDistribution(adjustedCosts, externalPrice, sharingLevel);
14865
14863
  return {
14866
- cost: Number(adjustedCosts.charge.toFixed(6)),
14864
+ cost: sanitizeCost(adjustedCosts.charge),
14867
14865
  pay
14868
14866
  };
14869
14867
  };
@@ -14963,7 +14961,59 @@ var resolveBillingTarget = ({
14963
14961
  };
14964
14962
  };
14965
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
+
14966
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
+ }
14967
15017
  var prepareTokenUsageData = ({
14968
15018
  rawUsage,
14969
15019
  agentConfig,
@@ -14983,18 +15033,27 @@ var prepareTokenUsageData = ({
14983
15033
  const billedModel = billingTarget.model;
14984
15034
  const billedServiceTier = billingTarget.serviceTier;
14985
15035
  const recordProvider = billedProvider ?? agentConfig.provider ?? "unknown";
15036
+ const hasExternalPrice = agentConfig.inputPrice !== void 0 && agentConfig.inputPrice > 0 || agentConfig.outputPrice !== void 0 && agentConfig.outputPrice > 0;
14986
15037
  const { cost, pay } = calculatePrice({
14987
15038
  provider: billedProvider,
14988
15039
  modelName: billedModel,
14989
15040
  billingServiceTier: billedServiceTier,
14990
15041
  usage,
14991
- externalPrice: agentConfig.id ? {
15042
+ externalPrice: hasExternalPrice ? {
14992
15043
  input: agentConfig.inputPrice ?? 0,
14993
15044
  output: agentConfig.outputPrice ?? 0,
14994
- creatorId: agentConfig.userId ?? extractUserId(agentConfig.id)
15045
+ creatorId: agentConfig.userId ?? (agentConfig.id ? extractUserId(agentConfig.id) : "")
14995
15046
  } : void 0,
14996
15047
  sharingLevel: agentConfig.sharingLevel
14997
15048
  });
15049
+ const billable = resolveBillable({
15050
+ usage,
15051
+ userId,
15052
+ apiSource: agentConfig.apiSource,
15053
+ apiKeyRef: agentConfig.apiKeyRef,
15054
+ cost,
15055
+ hasExternalPrice
15056
+ });
14998
15057
  return {
14999
15058
  usage,
15000
15059
  billedProvider,
@@ -15012,13 +15071,68 @@ var prepareTokenUsageData = ({
15012
15071
  dialogId,
15013
15072
  cost,
15014
15073
  pay,
15015
- timestamp
15074
+ timestamp,
15075
+ billable
15016
15076
  }
15017
15077
  };
15018
15078
  };
15019
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
+
15020
15134
  // packages/chat/dialog/actions/updateTokensAction.ts
15021
- var logger3 = pino2({ name: "token-usage", level: "info" });
15135
+ var logger3 = createClientLogger("token-usage");
15022
15136
  var dialogTokenPatchQueue = /* @__PURE__ */ new Map();
15023
15137
  var queueDialogTokenPatch = async (dialogKey, task) => {
15024
15138
  const previousTask = dialogTokenPatchQueue.get(dialogKey) ?? Promise.resolve();
@@ -15036,53 +15150,26 @@ var queueDialogTokenPatch = async (dialogKey, task) => {
15036
15150
  }
15037
15151
  }
15038
15152
  };
15039
- var updateStatsCounter = (data, stats = { count: 0, tokens: { input: 0, output: 0 }, cost: 0 }) => ({
15040
- count: stats.count + 1,
15041
- tokens: {
15042
- input: stats.tokens.input + data.input_tokens,
15043
- output: stats.tokens.output + data.output_tokens
15044
- },
15045
- cost: stats.cost + data.cost
15046
- });
15047
15153
  var updateStats = async (data, existingStats, key, thunkApi) => {
15048
15154
  try {
15049
- const stats = existingStats ?? {
15050
- userId: data.userId,
15051
- period: "day",
15052
- timeKey: (0, import_date_fns.format)(Date.now(), "yyyy-MM-dd"),
15053
- total: { count: 0, tokens: { input: 0, output: 0 }, cost: 0 },
15054
- models: {},
15055
- providers: {}
15056
- };
15057
- const modelName = data.model || "unknown";
15058
- const providerName2 = data.provider || "unknown";
15059
- const cleanModels = Object.fromEntries(
15060
- Object.entries(stats.models).filter(
15061
- ([key2]) => !["unknown", "undefined"].includes(key2)
15062
- )
15063
- );
15064
- const updatedStats = {
15065
- ...stats,
15066
- total: updateStatsCounter(data, stats.total),
15067
- models: {
15068
- ...cleanModels,
15069
- [modelName]: updateStatsCounter(data, cleanModels[modelName])
15070
- },
15071
- providers: {
15072
- ...stats.providers,
15073
- [providerName2]: updateStatsCounter(data, stats.providers[providerName2])
15074
- }
15075
- };
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
+ });
15076
15165
  await thunkApi.dispatch(
15077
15166
  write({
15078
- data: { ...updatedStats, id: key, type: "token" /* TOKEN */ },
15167
+ data: { ...newStats, id: key, type: "token" /* TOKEN */ },
15079
15168
  customKey: key,
15080
- // Must stamp owner on writeConfig: writeAction overwrites data.userId
15081
- // from writeConfig.userId || currentUserId (empty when logged out).
15082
15169
  userId: data.userId
15083
15170
  })
15084
- );
15085
- return updatedStats;
15171
+ ).unwrap();
15172
+ return newStats;
15086
15173
  } catch (error) {
15087
15174
  logger3.error(
15088
15175
  { key, userId: data.userId, error: error.message },
@@ -15093,45 +15180,47 @@ var updateStats = async (data, existingStats, key, thunkApi) => {
15093
15180
  }
15094
15181
  };
15095
15182
  var saveTokenUsage = async (data, thunkApi) => {
15096
- 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");
15097
15184
  const tokenDayStatsKey = createTokenStatsKey(data.userId ?? "", dateKey);
15098
- try {
15099
- let currentStats = null;
15185
+ return runKeyed(tokenDayStatsKey, async () => {
15100
15186
  try {
15101
- currentStats = await thunkApi.dispatch(read({
15102
- dbKey: tokenDayStatsKey
15103
- })).unwrap();
15104
- } catch (err) {
15105
- 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;
15106
15222
  }
15107
- const updatedStats = await updateStats(
15108
- data,
15109
- currentStats,
15110
- tokenDayStatsKey,
15111
- thunkApi
15112
- );
15113
- return {
15114
- success: true,
15115
- id: ulid3(Date.now()),
15116
- record: updatedStats
15117
- };
15118
- } catch (error) {
15119
- logger3.error(
15120
- {
15121
- key: tokenDayStatsKey,
15122
- userId: data.userId,
15123
- error: error.message,
15124
- tokenData: {
15125
- input: data.input_tokens,
15126
- output: data.output_tokens,
15127
- model: data.model
15128
- }
15129
- },
15130
- "Failed to process token usage"
15131
- );
15132
- toast.error("Failed to process token usage");
15133
- throw error;
15134
- }
15223
+ });
15135
15224
  };
15136
15225
  var updateTokensAction = async ({ dialogId, dialogKey, usage: usageRaw, agentConfig }, thunkApi) => {
15137
15226
  const state3 = thunkApi.getState();
@@ -15172,7 +15261,7 @@ var updateTokensAction = async ({ dialogId, dialogKey, usage: usageRaw, agentCon
15172
15261
  });
15173
15262
  await saveTokenRecord(persistedTokenData, record, thunkApi);
15174
15263
  await saveTokenUsage(persistedTokenData, thunkApi);
15175
- if (result.cost > 0) {
15264
+ if (persistedTokenData.billable === true || persistedTokenData.billable === void 0 && result.cost > 0) {
15176
15265
  thunkApi.dispatch(deductBalance(result.cost));
15177
15266
  }
15178
15267
  if (dialogKey) {
@@ -15286,7 +15375,7 @@ var deleteOwnedDialogAttachments = async (args) => {
15286
15375
  metadataReadFailures
15287
15376
  });
15288
15377
  if (!plan.deleteCandidates.length) return plan;
15289
- const { deleteFileAction } = await import("./deleteFile-SV5MS23W.js");
15378
+ const { deleteFileAction } = await import("./deleteFile-WPWVZE4B.js");
15290
15379
  for (const candidate of plan.deleteCandidates) {
15291
15380
  if (candidate.fileDbKey) {
15292
15381
  await deleteFileAction(candidate.fileDbKey, args.thunkApi);
@@ -15348,7 +15437,7 @@ var deleteDialogThunk = async (payload, thunkApi) => {
15348
15437
  }
15349
15438
  if (isCurrentDialog) {
15350
15439
  await thunkApi.dispatch(resetMsgs());
15351
- const { clearPendingAttachments: clearPendingAttachments2 } = await import("./dialogSlice-OVTO7QGW.js");
15440
+ const { clearPendingAttachments: clearPendingAttachments2 } = await import("./dialogSlice-IFBZ4IT2.js");
15352
15441
  dispatch(clearPendingAttachments2());
15353
15442
  clearWorkflow();
15354
15443
  }
@@ -15357,35 +15446,35 @@ var deleteDialogThunk = async (payload, thunkApi) => {
15357
15446
 
15358
15447
  // packages/chat/dialog/dialogSlice.ts
15359
15448
  var runCreateDialogAction = async (args, thunkApi) => {
15360
- const { createDialogAction } = await import("./createDialogAction-YPKF5ITI.js");
15449
+ const { createDialogAction } = await import("./createDialogAction-ETB3KQQE.js");
15361
15450
  return createDialogAction(args, thunkApi);
15362
15451
  };
15363
15452
  var runCreateAgentAutomationAction = async (args, thunkApi) => {
15364
- const { createAgentAutomationAction } = await import("./createAgentAutomationAction-CCABEOM6.js");
15453
+ const { createAgentAutomationAction } = await import("./createAgentAutomationAction-DYQOGAVE.js");
15365
15454
  return createAgentAutomationAction(args, thunkApi);
15366
15455
  };
15367
15456
  var runUpdateDialogTitleAction = async (args, thunkApi) => {
15368
- const { updateDialogTitleAction } = await import("./updateDialogTitleAction-XA2OZTLP.js");
15457
+ const { updateDialogTitleAction } = await import("./updateDialogTitleAction-A3OOMSDO.js");
15369
15458
  return updateDialogTitleAction(args, thunkApi);
15370
15459
  };
15371
15460
  var runAddDialogAgentAction = async (args, thunkApi) => {
15372
- const { addDialogAgentAction } = await import("./addDialogAgentAction-OT4XZAVP.js");
15461
+ const { addDialogAgentAction } = await import("./addDialogAgentAction-MUBYOG65.js");
15373
15462
  return addDialogAgentAction(args, thunkApi);
15374
15463
  };
15375
15464
  var runRemoveDialogAgentAction = async (args, thunkApi) => {
15376
- const { removeDialogAgentAction } = await import("./removeDialogAgentAction-SNZ662NP.js");
15465
+ const { removeDialogAgentAction } = await import("./removeDialogAgentAction-KOLQ2R5W.js");
15377
15466
  return removeDialogAgentAction(args, thunkApi);
15378
15467
  };
15379
15468
  var runSetPrimaryDialogAgentAction = async (args, thunkApi) => {
15380
- const { setPrimaryDialogAgentAction } = await import("./setPrimaryDialogAgentAction-PYEC4N4Z.js");
15469
+ const { setPrimaryDialogAgentAction } = await import("./setPrimaryDialogAgentAction-DOCIS6V4.js");
15381
15470
  return setPrimaryDialogAgentAction(args, thunkApi);
15382
15471
  };
15383
15472
  var runSetDialogExtraReferencesAction = async (args, thunkApi) => {
15384
- const { setDialogExtraReferencesAction } = await import("./setDialogExtraReferencesAction-XDI2KM2N.js");
15473
+ const { setDialogExtraReferencesAction } = await import("./setDialogExtraReferencesAction-OMTEO7X6.js");
15385
15474
  return setDialogExtraReferencesAction(args, thunkApi);
15386
15475
  };
15387
15476
  var runHandleSendMessageAction = async (args, thunkApi) => {
15388
- const { handleSendMessageAction } = await import("./handleSendMessageAction-TZMZ4EP5.js");
15477
+ const { handleSendMessageAction } = await import("./handleSendMessageAction-T76HEDOP.js");
15389
15478
  return handleSendMessageAction(args, thunkApi);
15390
15479
  };
15391
15480
  function clearDialogState() {
@@ -15398,7 +15487,7 @@ var createPageAndAddReference = createAsyncThunk(
15398
15487
  async (payload, { dispatch, getState, rejectWithValue }) => {
15399
15488
  const { slateData, jsonData, title, type, fileId, groupId, dialogKey } = payload;
15400
15489
  try {
15401
- const { createDocState } = await import("./docStore-ZAYLW2HN.js");
15490
+ const { createDocState } = await import("./docStore-65WO7U36.js");
15402
15491
  const pageKey = await createDocState(
15403
15492
  { slateData, title },
15404
15493
  { dispatch, getState }
@@ -19355,11 +19444,11 @@ var ENTITY_DELETE_STRATEGIES = {
19355
19444
  await dispatch(deleteTable({ dbKey: key })).unwrap();
19356
19445
  },
19357
19446
  file: async (key, { thunkAPI }) => {
19358
- const { deleteFileAction } = await import("./deleteFile-SV5MS23W.js");
19447
+ const { deleteFileAction } = await import("./deleteFile-WPWVZE4B.js");
19359
19448
  await deleteFileAction(key, thunkAPI);
19360
19449
  },
19361
19450
  image: async (key, { thunkAPI }) => {
19362
- const { deleteFileAction } = await import("./deleteFile-SV5MS23W.js");
19451
+ const { deleteFileAction } = await import("./deleteFile-WPWVZE4B.js");
19363
19452
  await deleteFileAction(key, thunkAPI);
19364
19453
  },
19365
19454
  agent: async (key, { dispatch, userId, sourceServerOrigin }) => {
@@ -19455,12 +19544,7 @@ var deleteContentFromSpaceAction = async (input, thunkAPI) => {
19455
19544
  };
19456
19545
 
19457
19546
  // packages/create/space/content/moveContentAction.ts
19458
- import pino3 from "pino";
19459
- var logger4 = pino3({
19460
- level: "info"
19461
- // 或根据环境调整
19462
- // transport: { target: "pino-pretty" },
19463
- });
19547
+ var logger4 = createClientLogger("move-content");
19464
19548
  var moveContentAction = async (input, thunkAPI) => {
19465
19549
  const {
19466
19550
  contentKey,
@@ -19921,13 +20005,7 @@ var updateContentCategoryAction = async (input, thunkAPI) => {
19921
20005
  };
19922
20006
 
19923
20007
  // packages/create/space/content/deleteMultipleContentAction.ts
19924
- import pino4 from "pino";
19925
- var logger5 = pino4({
19926
- level: "info"
19927
- // transport: {
19928
- // target: "pino-pretty",
19929
- // },
19930
- });
20008
+ var logger5 = createClientLogger("delete-multiple-content");
19931
20009
  var deleteMultipleContentAction = async (input, thunkAPI) => {
19932
20010
  const { contentKeys, spaceId } = input;
19933
20011
  if (!contentKeys || contentKeys.length === 0) {
@@ -21538,7 +21616,7 @@ var fetchSpaceAction = async (input, thunkAPI) => {
21538
21616
  const spaceKey = createSpaceKey.space(spaceId);
21539
21617
  const readSpace = async (dbKey) => {
21540
21618
  try {
21541
- const { read: read2, readAndWait: readAndWait2 } = await import("./dbSlice-QPVZHBOE.js");
21619
+ const { read: read2, readAndWait: readAndWait2 } = await import("./dbSlice-R5EJKZBW.js");
21542
21620
  if (fresh) {
21543
21621
  return await dispatch(readAndWait2(dbKey)).unwrap();
21544
21622
  }
@@ -22209,6 +22287,7 @@ export {
22209
22287
  PERSONALIZATION_DIALOG_CATEGORY,
22210
22288
  buildPersonalizationDialogPolicyContext,
22211
22289
  resolveHandleSendMessageContext,
22290
+ estimateMissingUsage,
22212
22291
  selectCurrentDialogId,
22213
22292
  selectAllMsgs,
22214
22293
  selectMsgById,
@@ -22286,6 +22365,7 @@ export {
22286
22365
  selectViewMode,
22287
22366
  spaceSlice_default,
22288
22367
  selectCurrentUserBalance,
22368
+ shouldUseServerProxy,
22289
22369
  updateTokensAction,
22290
22370
  clearDialogState,
22291
22371
  createPageAndAddReference,