nolo-cli 0.8.0-alpha.2 → 0.8.0-alpha.20

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 (188) hide show
  1. package/README.md +1 -1
  2. package/_executeModel-WRUCQIV5.js +205 -0
  3. package/action-R4M4ORGA.js +28 -0
  4. package/addContentAction-UYFFTEWJ.js +26 -0
  5. package/addDialogAgentAction-OT4XZAVP.js +68 -0
  6. package/agentDeleteCommand-5DD2IM3J.js +327 -0
  7. package/agentEmailCommands-IASM2YBQ.js +628 -0
  8. package/agentListCommands-I6KZYCIG.js +223 -0
  9. package/agentMachineCommands-OUP3YQP7.js +425 -0
  10. package/agentPullCommand-O2MTUAFR.js +122 -0
  11. package/agentRecordCommands-QKGE2JTA.js +96 -0
  12. package/agentRunCommand-TVZXUBQ5.js +114 -0
  13. package/agentRunControl-K4VKNEHF.js +57 -0
  14. package/agentRuntimeLocal-ZYEIPTY4.js +104 -0
  15. package/agentSlice-T4PMW7W6.js +42 -0
  16. package/authCommand-EB5JSOX5.js +581 -0
  17. package/authCommands-XPEHTKSM.js +35 -0
  18. package/chunk-2EHX7F5G.js +1948 -0
  19. package/chunk-2FTTDCD4.js +675 -0
  20. package/chunk-3ASDTTEI.js +1774 -0
  21. package/chunk-3EUW3WEO.js +8 -0
  22. package/chunk-3LY4F7SV.js +9293 -0
  23. package/chunk-4CQLVGRV.js +50 -0
  24. package/chunk-4FBRSEV4.js +573 -0
  25. package/chunk-4IJYA27C.js +342 -0
  26. package/chunk-4QEWT7KD.js +933 -0
  27. package/chunk-4SN6J65J.js +38 -0
  28. package/chunk-4VNS5WPM.js +42 -0
  29. package/chunk-4ZDM73SD.js +34 -0
  30. package/chunk-5CS33IBL.js +301 -0
  31. package/chunk-5KLGBAAR.js +386 -0
  32. package/chunk-5MIDPSSK.js +206 -0
  33. package/chunk-5MMAK75Q.js +15 -0
  34. package/chunk-5W3VUFOX.js +34 -0
  35. package/chunk-63W5N6P3.js +150 -0
  36. package/chunk-6HYVJV7B.js +102 -0
  37. package/chunk-6WD3OOJS.js +20 -0
  38. package/chunk-7DAJ4AI4.js +191 -0
  39. package/chunk-7KCUSYT2.js +354 -0
  40. package/chunk-7T5PWAZN.js +171 -0
  41. package/chunk-AFON4QUU.js +112 -0
  42. package/chunk-AGFH73SK.js +239 -0
  43. package/chunk-ATNTHIZI.js +13 -0
  44. package/chunk-AVMKZHBC.js +85 -0
  45. package/chunk-AZPCASRE.js +36 -0
  46. package/chunk-BBYVOSU2.js +792 -0
  47. package/chunk-BCIOM4NZ.js +1078 -0
  48. package/chunk-C3RUNRHT.js +51 -0
  49. package/chunk-C4FTUXVF.js +146 -0
  50. package/chunk-CF2WZF4N.js +134 -0
  51. package/chunk-CF7PE763.js +10 -0
  52. package/chunk-CKOJQDKR.js +198 -0
  53. package/chunk-CMKUBIGW.js +1550 -0
  54. package/chunk-CWMSB67P.js +34 -0
  55. package/chunk-DCOA4QSN.js +105 -0
  56. package/chunk-DFFIZ25G.js +30 -0
  57. package/chunk-DWLEOOGR.js +8 -0
  58. package/chunk-DZ3XJVET.js +231 -0
  59. package/chunk-EHLHSX7R.js +1433 -0
  60. package/chunk-FM5IVZXO.js +4723 -0
  61. package/chunk-FVYY6MCS.js +1447 -0
  62. package/chunk-G3SUCT4W.js +8 -0
  63. package/chunk-GAKEBQD6.js +30 -0
  64. package/chunk-GBRG75BQ.js +86 -0
  65. package/chunk-GLYVN7EQ.js +238 -0
  66. package/chunk-H33743XH.js +25 -0
  67. package/chunk-HNMXYYJR.js +12 -0
  68. package/chunk-HNW7IJSK.js +71 -0
  69. package/chunk-I42VC5KR.js +15 -0
  70. package/chunk-IDZTNRP2.js +85 -0
  71. package/chunk-IHBCLYEE.js +22310 -0
  72. package/chunk-IJGXKGXW.js +421 -0
  73. package/chunk-ISNCLGUZ.js +146 -0
  74. package/chunk-IWX4UW2E.js +548 -0
  75. package/chunk-JBTJAPUF.js +35 -0
  76. package/chunk-JEXVIMYZ.js +55 -0
  77. package/chunk-JRKKFRAV.js +537 -0
  78. package/chunk-JZPBVBIY.js +94 -0
  79. package/chunk-K6BPOQLF.js +2052 -0
  80. package/chunk-K777STIO.js +478 -0
  81. package/chunk-KKY4B2Q2.js +21 -0
  82. package/chunk-KQHGZWSV.js +63 -0
  83. package/chunk-KUG52IAP.js +8 -0
  84. package/chunk-KX6YBIHG.js +8 -0
  85. package/chunk-LCBAMY2M.js +60 -0
  86. package/chunk-LM6IYQ3F.js +16 -0
  87. package/chunk-LTRXGFMS.js +83 -0
  88. package/chunk-M76ECQRD.js +13658 -0
  89. package/chunk-MNJDFJND.js +222 -0
  90. package/chunk-MRC4Q34M.js +188 -0
  91. package/chunk-MTU75CZ2.js +91 -0
  92. package/chunk-N54XAP77.js +19 -0
  93. package/chunk-O2ZNTTET.js +3272 -0
  94. package/chunk-O4BU24WZ.js +3212 -0
  95. package/chunk-OLZBQWZU.js +6 -0
  96. package/chunk-OPZYGHUC.js +89 -0
  97. package/chunk-OWOHNGCN.js +50 -0
  98. package/chunk-P3PKED2I.js +962 -0
  99. package/chunk-PFTAG6DY.js +1939 -0
  100. package/chunk-PMKQGGGM.js +221 -0
  101. package/chunk-PP4S6RTL.js +175 -0
  102. package/chunk-QJ7FZNYN.js +939 -0
  103. package/chunk-QSJ3HFEF.js +8 -0
  104. package/chunk-RGIM3WLT.js +113 -0
  105. package/chunk-RL776AGR.js +190 -0
  106. package/chunk-ROWQEJRP.js +139 -0
  107. package/chunk-S7Z2HMCN.js +25 -0
  108. package/chunk-SDJDLO5W.js +628 -0
  109. package/chunk-SOTZ6RDN.js +69 -0
  110. package/chunk-TILFE6LV.js +381 -0
  111. package/chunk-TIMLUWQA.js +231 -0
  112. package/chunk-TISCADJH.js +807 -0
  113. package/chunk-U4TRT5V4.js +246 -0
  114. package/chunk-U6VC4MU4.js +8 -0
  115. package/chunk-UAD2WT54.js +64 -0
  116. package/chunk-VC6OZXO5.js +298 -0
  117. package/chunk-VF4K2QE6.js +21 -0
  118. package/chunk-VHBWHNVT.js +59 -0
  119. package/chunk-VIDPVFP3.js +20 -0
  120. package/chunk-VP4WJWKW.js +8882 -0
  121. package/chunk-VVX233PH.js +482 -0
  122. package/chunk-W4NVOSFF.js +37 -0
  123. package/chunk-WI4XWASA.js +208 -0
  124. package/chunk-WWC7I6TA.js +8 -0
  125. package/chunk-WZSRQNQG.js +2587 -0
  126. package/chunk-XBROXIGL.js +3066 -0
  127. package/chunk-XENYHRUE.js +104 -0
  128. package/chunk-Y5GCAMGP.js +9 -0
  129. package/chunk-YN4XDB7B.js +9036 -0
  130. package/chunk-YPRZSPF3.js +148 -0
  131. package/chunk-Z4NR32XR.js +50 -0
  132. package/chunk-Z6EKEXJW.js +138 -0
  133. package/chunk-ZDRZMLKO.js +27339 -0
  134. package/chunk-ZNFJWEN4.js +56 -0
  135. package/cliExecutor-K3F7DMRO.js +36 -0
  136. package/clipboardy-BVE3LVEH.js +12001 -0
  137. package/createAgentAutomationAction-CCABEOM6.js +866 -0
  138. package/createDialogAction-YPKF5ITI.js +55 -0
  139. package/createPageAction-YEZ7EK5F.js +172 -0
  140. package/db-HCJ5PRB5.js +271 -0
  141. package/dbSlice-QPVZHBOE.js +60 -0
  142. package/deleteFile-SV5MS23W.js +41 -0
  143. package/dialogCommands-4IX4XIZE.js +63 -0
  144. package/dialogSlice-OVTO7QGW.js +148 -0
  145. package/docCreateCommands-SIL3NPGT.js +220 -0
  146. package/docDeleteCommands-7IOMLUS4.js +181 -0
  147. package/docReadCommands-FNFXUA5L.js +134 -0
  148. package/docStore-ZAYLW2HN.js +98 -0
  149. package/docUpdateCommands-X2HNDVUC.js +318 -0
  150. package/fetchMessages-KTNM7QAR.js +17 -0
  151. package/getPricing-3E6UNPKL.js +30 -0
  152. package/handleSendMessageAction-TZMZ4EP5.js +185 -0
  153. package/index.js +188 -112958
  154. package/lib-FYYBQIXS.js +19839 -0
  155. package/localDialogRead-2VRI24F4.js +26 -0
  156. package/localFirstLog-DHNOY2NA.js +19 -0
  157. package/localRuntimeAuthority-TEGCOWX4.js +471 -0
  158. package/localRuntimeDb-LGDF6FQP.js +12 -0
  159. package/machineCommands-M4ZJZIMS.js +781 -0
  160. package/machineInfo-M6KB6HZN.js +10 -0
  161. package/machineWsRunDispatch-TPJAUGLP.js +112 -0
  162. package/memoryCommands-O4MIPIWQ.js +476 -0
  163. package/models-4OPOOLFS.js +9 -0
  164. package/offlineMarxistsAgentCommand-BCPJITJL.js +242 -0
  165. package/package.json +4 -23
  166. package/read-EBMWX4Z6.js +17 -0
  167. package/readDocTool-2MWHSTQE.js +16 -0
  168. package/readlineWorkspace-OMCIU3WT.js +5682 -0
  169. package/removeDialogAgentAction-SNZ662NP.js +73 -0
  170. package/runAgentClientLoop-H6NGOUAM.js +293 -0
  171. package/runtimeDoctorCommands-LRHLPDRC.js +289 -0
  172. package/setDialogExtraReferencesAction-XDI2KM2N.js +60 -0
  173. package/setPrimaryDialogAgentAction-PYEC4N4Z.js +80 -0
  174. package/settingSlice-NOWHY2FK.js +199 -0
  175. package/skillDiscovery-UGSQGX2U.js +16 -0
  176. package/skillSummaryMarker-42HKSXYY.js +9 -0
  177. package/slateToRenderMarkdown-Y5IYN73U.js +7 -0
  178. package/slateUtils-2M7MUTWX.js +19 -0
  179. package/spaceCommands-E7VOF4LO.js +450 -0
  180. package/spaceSlice-QHBPICA2.js +149 -0
  181. package/streamAgentChatTurn-3XTBA2HN.js +4510 -0
  182. package/tableCommands-R5UCM63M.js +1286 -0
  183. package/toolApiClient-QI3YBNWB.js +26 -0
  184. package/tools-GHLZ3XD6.js +87 -0
  185. package/tuiSummaryLlmCaller-RV3THLZF.js +78 -0
  186. package/understanding-3CUQQ6SV.js +271 -0
  187. package/updateCommands-VOSPKXFF.js +31 -0
  188. package/updateDialogTitleAction-XA2OZTLP.js +188 -0
@@ -0,0 +1,421 @@
1
+ import {
2
+ updateContentTitle
3
+ } from "./chunk-IHBCLYEE.js";
4
+ import {
5
+ require_date_fns
6
+ } from "./chunk-M76ECQRD.js";
7
+ import {
8
+ require_react
9
+ } from "./chunk-3ASDTTEI.js";
10
+ import {
11
+ toErrorMessage
12
+ } from "./chunk-HNMXYYJR.js";
13
+ import {
14
+ patch,
15
+ readAndWait
16
+ } from "./chunk-TISCADJH.js";
17
+ import {
18
+ asOptionalTrimmedString
19
+ } from "./chunk-G3SUCT4W.js";
20
+ import {
21
+ __toESM
22
+ } from "./chunk-4VNS5WPM.js";
23
+
24
+ // packages/render/page/docStore.ts
25
+ var import_react = __toESM(require_react(), 1);
26
+ var import_date_fns = __toESM(require_date_fns(), 1);
27
+ var createInitialState = () => ({
28
+ content: null,
29
+ slateData: null,
30
+ title: null,
31
+ dbSpaceId: null,
32
+ tags: null,
33
+ icon: null,
34
+ isReadOnly: true,
35
+ isLoading: false,
36
+ isInitialized: false,
37
+ error: null,
38
+ pageKey: null,
39
+ isSaving: false,
40
+ saveError: null,
41
+ lastSavedAt: null,
42
+ createdAt: null,
43
+ lastSavedSlateData: null,
44
+ lastSavedTitle: null,
45
+ lastSavedIcon: null,
46
+ justSaved: false,
47
+ tools: null,
48
+ meta: null,
49
+ id: null,
50
+ type: null,
51
+ creator: null,
52
+ focusContext: null,
53
+ externalUpdateSeq: 0
54
+ });
55
+ var listeners = /* @__PURE__ */ new Set();
56
+ var version = 0;
57
+ var state = createInitialState();
58
+ var notify = () => {
59
+ for (const listener of listeners) {
60
+ try {
61
+ listener();
62
+ } catch {
63
+ }
64
+ }
65
+ };
66
+ var bump = () => {
67
+ version += 1;
68
+ notify();
69
+ };
70
+ var setState = (updater) => {
71
+ state = typeof updater === "function" ? updater(state) : updater;
72
+ bump();
73
+ };
74
+ var deepEqualEditorContent = (a, b) => {
75
+ if (a === b) return true;
76
+ if (a == null || b == null) return false;
77
+ if (typeof a !== "object" || typeof b !== "object") return false;
78
+ const isArrayA = Array.isArray(a);
79
+ const isArrayB = Array.isArray(b);
80
+ if (isArrayA || isArrayB) {
81
+ if (!isArrayA || !isArrayB || a.length !== b.length) return false;
82
+ return a.every(
83
+ (item, index) => deepEqualEditorContent(item, b[index])
84
+ );
85
+ }
86
+ const keysA = Object.keys(a);
87
+ const keysB = Object.keys(b);
88
+ if (keysA.length !== keysB.length) return false;
89
+ return keysA.every(
90
+ (key) => Object.prototype.hasOwnProperty.call(b, key) && deepEqualEditorContent(a[key], b[key])
91
+ );
92
+ };
93
+ var hasSlateContentChanged = (newContent, oldContent) => {
94
+ if (newContent === oldContent) return false;
95
+ if (!newContent || !oldContent) return true;
96
+ if (newContent.length !== oldContent.length) return true;
97
+ return !deepEqualEditorContent(newContent, oldContent);
98
+ };
99
+ function getDocState() {
100
+ return state;
101
+ }
102
+ function getDocField(selector) {
103
+ return selector(state);
104
+ }
105
+ function getDocPageKey() {
106
+ return state.pageKey;
107
+ }
108
+ function getDocIsInitialized() {
109
+ return state.isInitialized;
110
+ }
111
+ function getDocIsReadOnly() {
112
+ return state.isReadOnly;
113
+ }
114
+ function getDocHasPendingChanges() {
115
+ if (!state.isInitialized || state.isReadOnly) return false;
116
+ return hasSlateContentChanged(state.slateData, state.lastSavedSlateData) || (state.title || "") !== (state.lastSavedTitle || "") || JSON.stringify(state.icon ?? null) !== JSON.stringify(state.lastSavedIcon ?? null);
117
+ }
118
+ function updateSlateDoc(value) {
119
+ if (!state.isInitialized || state.isReadOnly) return;
120
+ if (state.slateData === value) return;
121
+ setState((prev) => ({ ...prev, slateData: value, justSaved: false }));
122
+ }
123
+ function updateTitleDoc(title) {
124
+ if (!state.isInitialized || state.isReadOnly) return;
125
+ setState((prev) => ({ ...prev, title, justSaved: false }));
126
+ }
127
+ function updateIconDoc(icon) {
128
+ if (!state.isInitialized || state.isReadOnly) return;
129
+ setState((prev) => ({ ...prev, icon, justSaved: false }));
130
+ }
131
+ function resetJustSavedStatus() {
132
+ if (state.justSaved === false) return;
133
+ setState((prev) => ({ ...prev, justSaved: false }));
134
+ }
135
+ function setDocFocusContext(focusContext) {
136
+ setState((prev) => ({ ...prev, focusContext }));
137
+ }
138
+ function toggleReadOnlyDoc() {
139
+ setState((prev) => ({ ...prev, isReadOnly: !prev.isReadOnly }));
140
+ }
141
+ function setReadOnlyDoc(isReadOnly) {
142
+ setState((prev) => ({ ...prev, isReadOnly }));
143
+ }
144
+ function updateDocTags(tags) {
145
+ if (!state.isInitialized) return;
146
+ setState((prev) => ({ ...prev, tags }));
147
+ }
148
+ function resetDocState() {
149
+ setState(createInitialState());
150
+ }
151
+ function previewDocState(payload) {
152
+ const next = createInitialState();
153
+ next.isInitialized = true;
154
+ next.isLoading = false;
155
+ next.isReadOnly = true;
156
+ next.slateData = payload.slateData;
157
+ next.title = payload.title;
158
+ next.lastSavedTitle = payload.title;
159
+ next.pageKey = payload.dbKey;
160
+ next.id = payload.id;
161
+ next.type = payload.type || "page" /* DOC */;
162
+ next.lastSavedSlateData = payload.slateData;
163
+ next.tags = payload.tags || null;
164
+ next.icon = payload.icon || null;
165
+ next.lastSavedIcon = payload.icon || null;
166
+ next.dbSpaceId = payload.spaceId;
167
+ next.content = payload.content || null;
168
+ next.meta = payload.meta || null;
169
+ setState(next);
170
+ }
171
+ function applyExternalDocUpdate(payload) {
172
+ if (!state.isInitialized) return;
173
+ const { slateData, content, title, tools, meta, savedAt } = payload;
174
+ setState((prev) => {
175
+ const next = {
176
+ ...prev,
177
+ slateData,
178
+ lastSavedSlateData: slateData,
179
+ lastSavedAt: savedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
180
+ justSaved: true,
181
+ saveError: null,
182
+ externalUpdateSeq: prev.externalUpdateSeq + 1
183
+ };
184
+ if (content !== void 0) next.content = content;
185
+ if (title != null) {
186
+ next.title = title;
187
+ next.lastSavedTitle = title;
188
+ }
189
+ if (tools !== void 0) next.tools = tools;
190
+ if (meta !== void 0) next.meta = meta;
191
+ return next;
192
+ });
193
+ }
194
+ async function initDocState(args, { dispatch }) {
195
+ const { pageKey, isReadOnly } = args;
196
+ setState((prev) => ({
197
+ ...createInitialState(),
198
+ isLoading: true,
199
+ pageKey,
200
+ isReadOnly
201
+ }));
202
+ try {
203
+ const readAction = await dispatch(readAndWait(pageKey));
204
+ if (readAndWait.fulfilled.match(readAction) && readAction.payload) {
205
+ const data = readAction.payload;
206
+ if (data.type !== "page" /* DOC */) {
207
+ const msg = `\u52A0\u8F7D\u7684\u5185\u5BB9 ${pageKey} \u4E0D\u662F\u6587\u6863\u7C7B\u578B (${data.type})`;
208
+ setState((prev) => ({
209
+ ...prev,
210
+ isLoading: false,
211
+ isInitialized: true,
212
+ error: msg
213
+ }));
214
+ return;
215
+ }
216
+ const payload = data;
217
+ const lastSavedAt = payload.updatedAt || payload.updated_at || null;
218
+ const createdAt = typeof payload.created === "string" && payload.created || typeof payload.createdAt === "string" && payload.createdAt || lastSavedAt;
219
+ setState((prev) => ({
220
+ ...prev,
221
+ isLoading: false,
222
+ isInitialized: true,
223
+ error: null,
224
+ externalUpdateSeq: prev.externalUpdateSeq + 1,
225
+ content: payload.content || null,
226
+ slateData: payload.slateData || null,
227
+ lastSavedSlateData: payload.slateData || null,
228
+ title: payload.title || null,
229
+ lastSavedTitle: payload.title || null,
230
+ dbSpaceId: payload.spaceId || null,
231
+ tags: payload.tags || null,
232
+ icon: payload.icon || null,
233
+ lastSavedIcon: payload.icon || null,
234
+ isReadOnly: payload.isReadOnly,
235
+ pageKey: payload.dbKey,
236
+ id: payload.id,
237
+ type: payload.type,
238
+ lastSavedAt,
239
+ createdAt,
240
+ tools: payload.tools || null,
241
+ meta: payload.meta || null
242
+ }));
243
+ } else {
244
+ const msg = readAction.payload?.message || `\u65E0\u6CD5\u52A0\u8F7D\u6587\u6863 ${pageKey}`;
245
+ setState((prev) => ({
246
+ ...prev,
247
+ isLoading: false,
248
+ isInitialized: true,
249
+ error: msg
250
+ }));
251
+ }
252
+ } catch (e) {
253
+ setState((prev) => ({
254
+ ...prev,
255
+ isLoading: false,
256
+ isInitialized: true,
257
+ error: e?.message || `\u521D\u59CB\u5316\u6587\u6863 ${pageKey} \u65F6\u51FA\u9519`
258
+ }));
259
+ }
260
+ }
261
+ async function saveDocState(arg, { dispatch, getState }) {
262
+ const requestedPageKey = arg.pageKey;
263
+ const current = state;
264
+ const { pageKey, slateData, dbSpaceId, meta, icon } = current;
265
+ const triggerSource = arg.triggerSource ?? "unknown";
266
+ const hasPending = getDocHasPendingChanges();
267
+ if (typeof console !== "undefined") {
268
+ console.info("[saveDocState] triggered", {
269
+ triggerSource,
270
+ pageKey,
271
+ hasPendingChanges: hasPending,
272
+ lastSavedAt: current.lastSavedAt,
273
+ externalUpdateSeq: current.externalUpdateSeq
274
+ // 若 hasPending=false,说明 slateData===lastSavedSlateData,
275
+ // 此刻 save 仍被无条件触发 → 会用旧内容覆盖数据库(若数据库已有更新)
276
+ });
277
+ }
278
+ if (!pageKey || pageKey !== requestedPageKey) {
279
+ return;
280
+ }
281
+ if (!slateData) {
282
+ return;
283
+ }
284
+ if (!hasPending) {
285
+ if (typeof console !== "undefined") {
286
+ console.info("[saveDocState] skipped \u2014 no pending changes (protects external writes)", {
287
+ triggerSource,
288
+ pageKey,
289
+ externalUpdateSeq: current.externalUpdateSeq
290
+ });
291
+ }
292
+ return;
293
+ }
294
+ setState((prev) => ({
295
+ ...prev,
296
+ isSaving: true,
297
+ saveError: null,
298
+ justSaved: false
299
+ }));
300
+ try {
301
+ const [
302
+ { extractTitleFromSlate, extractMentionsFromSlate },
303
+ { slateToRenderMarkdown },
304
+ { buildSkillSummaryMarker }
305
+ ] = await Promise.all([
306
+ import("./slateUtils-2M7MUTWX.js"),
307
+ import("./slateToRenderMarkdown-Y5IYN73U.js"),
308
+ import("./skillSummaryMarker-42HKSXYY.js")
309
+ ]);
310
+ const title = asOptionalTrimmedString(current.title) || extractTitleFromSlate(slateData) || "\u672A\u547D\u540D\u9875\u9762";
311
+ const tools = extractMentionsFromSlate(slateData);
312
+ const skillSummary = buildSkillSummaryMarker(meta);
313
+ const content = slateToRenderMarkdown(slateData);
314
+ const now = /* @__PURE__ */ new Date();
315
+ const updatedAt = (0, import_date_fns.formatISO)(now);
316
+ await dispatch(
317
+ patch({
318
+ dbKey: pageKey,
319
+ changes: {
320
+ updatedAt,
321
+ slateData,
322
+ title,
323
+ tools,
324
+ content,
325
+ icon: icon ?? null,
326
+ ...meta ? { meta } : {}
327
+ }
328
+ })
329
+ ).unwrap();
330
+ if (dbSpaceId) {
331
+ try {
332
+ await dispatch(
333
+ updateContentTitle({
334
+ spaceId: dbSpaceId,
335
+ contentKey: pageKey,
336
+ title,
337
+ skillSummary
338
+ })
339
+ ).unwrap();
340
+ } catch (spaceSyncError) {
341
+ console.warn(
342
+ `[saveDoc] \u7A7A\u95F4\u6807\u9898\u540C\u6B65\u5931\u8D25\uFF08\u9875\u9762\u5DF2\u4FDD\u5B58\uFF09: ${toErrorMessage(spaceSyncError)}`
343
+ );
344
+ }
345
+ }
346
+ if (typeof window !== "undefined") {
347
+ window.dispatchEvent(new Event("nolo-user-data-updated"));
348
+ }
349
+ setState((prev) => ({
350
+ ...prev,
351
+ isSaving: false,
352
+ lastSavedAt: updatedAt,
353
+ title,
354
+ content,
355
+ lastSavedSlateData: slateData,
356
+ lastSavedTitle: title,
357
+ lastSavedIcon: prev.icon,
358
+ justSaved: true
359
+ }));
360
+ } catch (e) {
361
+ setState((prev) => ({
362
+ ...prev,
363
+ isSaving: false,
364
+ saveError: e?.message || "\u4FDD\u5B58\u5931\u8D25",
365
+ justSaved: false
366
+ }));
367
+ }
368
+ }
369
+ async function createDocState(args, thunkApi) {
370
+ const { createPageAction } = await import("./createPageAction-YEZ7EK5F.js");
371
+ return createPageAction(args, thunkApi);
372
+ }
373
+ function subscribe(listener) {
374
+ listeners.add(listener);
375
+ return () => {
376
+ listeners.delete(listener);
377
+ };
378
+ }
379
+ function getSnapshot() {
380
+ return version;
381
+ }
382
+ function useDocState() {
383
+ (0, import_react.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
384
+ return getDocState();
385
+ }
386
+ function useDocField(selector) {
387
+ (0, import_react.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
388
+ return selector(state);
389
+ }
390
+ function resetDocStoreForTests() {
391
+ state = createInitialState();
392
+ bump();
393
+ }
394
+
395
+ export {
396
+ getDocState,
397
+ getDocField,
398
+ getDocPageKey,
399
+ getDocIsInitialized,
400
+ getDocIsReadOnly,
401
+ getDocHasPendingChanges,
402
+ updateSlateDoc,
403
+ updateTitleDoc,
404
+ updateIconDoc,
405
+ resetJustSavedStatus,
406
+ setDocFocusContext,
407
+ toggleReadOnlyDoc,
408
+ setReadOnlyDoc,
409
+ updateDocTags,
410
+ resetDocState,
411
+ previewDocState,
412
+ applyExternalDocUpdate,
413
+ initDocState,
414
+ saveDocState,
415
+ createDocState,
416
+ subscribe,
417
+ getSnapshot,
418
+ useDocState,
419
+ useDocField,
420
+ resetDocStoreForTests
421
+ };
@@ -0,0 +1,146 @@
1
+ import {
2
+ DEFAULT_NOLO_SERVER_URL
3
+ } from "./chunk-OLZBQWZU.js";
4
+ import {
5
+ DEFAULT_LOCAL_API_ORIGIN
6
+ } from "./chunk-4SN6J65J.js";
7
+ import {
8
+ NOLO_CLUSTER_SERVERS
9
+ } from "./chunk-LCBAMY2M.js";
10
+ import {
11
+ normalizeServerOrigin
12
+ } from "./chunk-CF7PE763.js";
13
+ import {
14
+ asOptionalTrimmedString
15
+ } from "./chunk-G3SUCT4W.js";
16
+
17
+ // packages/cli/cliEnvHelpers.ts
18
+ import { dirname, extname, join } from "node:path";
19
+ import { fileURLToPath } from "node:url";
20
+ function resolveServerUrlFromEnv(env) {
21
+ return normalizeServerOrigin(
22
+ env.NOLO_SERVER || env.BASE_URL || DEFAULT_NOLO_SERVER_URL
23
+ );
24
+ }
25
+ function isCliArgs(value) {
26
+ return Array.isArray(value);
27
+ }
28
+ function buildServerCandidates(values) {
29
+ return [...new Set(
30
+ values.filter((value) => typeof value === "string" && value.trim().length > 0).map((value) => normalizeServerOrigin(value))
31
+ )];
32
+ }
33
+ function resolveServerUrl(input, env) {
34
+ if (isCliArgs(input)) {
35
+ const explicit = readOption(input, "--server-url") || readOption(input, "--server");
36
+ return normalizeServerOrigin(explicit) || resolveServerUrlFromEnv(env ?? {});
37
+ }
38
+ return resolveServerUrlFromEnv(input);
39
+ }
40
+ function resolveServerCandidates(input, envOrPreferred, preferred) {
41
+ if (isCliArgs(input)) {
42
+ const env2 = envOrPreferred ?? {};
43
+ const explicitServer = resolveServerUrl(input, env2);
44
+ return buildServerCandidates([
45
+ explicitServer,
46
+ preferred?.trim(),
47
+ env2.NOLO_SERVER,
48
+ env2.BASE_URL,
49
+ env2.NOLO_SERVER_URL,
50
+ DEFAULT_NOLO_SERVER_URL,
51
+ ...NOLO_CLUSTER_SERVERS
52
+ ]);
53
+ }
54
+ const env = input;
55
+ return buildServerCandidates([
56
+ asOptionalTrimmedString(envOrPreferred),
57
+ env.NOLO_SERVER,
58
+ env.BASE_URL,
59
+ env.NOLO_SERVER_URL,
60
+ DEFAULT_NOLO_SERVER_URL,
61
+ ...NOLO_CLUSTER_SERVERS
62
+ ]);
63
+ }
64
+ function resolveDeleteServerCandidatesFromEnv(env, ...preferredValues) {
65
+ return buildServerCandidates([
66
+ ...preferredValues,
67
+ env.NOLO_SERVER,
68
+ env.BASE_URL,
69
+ env.NOLO_SERVER_URL,
70
+ env.READ_DIALOG_BASE,
71
+ DEFAULT_NOLO_SERVER_URL,
72
+ ...NOLO_CLUSTER_SERVERS,
73
+ DEFAULT_LOCAL_API_ORIGIN
74
+ ]);
75
+ }
76
+ function resolveDeleteServerCandidates(input, envOrPreferred, preferred) {
77
+ if (isCliArgs(input)) {
78
+ const env2 = envOrPreferred ?? {};
79
+ const explicitServer = resolveServerUrl(input, env2);
80
+ return resolveDeleteServerCandidatesFromEnv(env2, explicitServer, preferred?.trim());
81
+ }
82
+ const env = input;
83
+ return resolveDeleteServerCandidatesFromEnv(
84
+ env,
85
+ asOptionalTrimmedString(envOrPreferred)
86
+ );
87
+ }
88
+ function resolveAuthTokenFromEnv(env, extraEnvKeys = []) {
89
+ for (const key of ["AUTH_TOKEN", "AUTH", ...extraEnvKeys]) {
90
+ const value = env[key];
91
+ if (typeof value === "string" && value.trim()) return value;
92
+ }
93
+ return "";
94
+ }
95
+ function resolveAuthToken(input, envOrExtraEnvKeys, extraEnvKeys = []) {
96
+ if (isCliArgs(input)) {
97
+ const env = envOrExtraEnvKeys ?? {};
98
+ return readOption(input, "--token") || readOption(input, "--machine-key") || resolveAuthTokenFromEnv(env, extraEnvKeys);
99
+ }
100
+ return resolveAuthTokenFromEnv(input, envOrExtraEnvKeys ?? []);
101
+ }
102
+ function parseUserIdFromAuthToken(token) {
103
+ const parts = token.trim().split(".").filter(Boolean);
104
+ const payloadCandidates = parts.length >= 3 ? [parts[1], parts[0]] : [parts[0]];
105
+ for (const payload of payloadCandidates) {
106
+ if (!payload) continue;
107
+ try {
108
+ const parsed = JSON.parse(Buffer.from(payload, "base64").toString("utf8"));
109
+ if (typeof parsed?.userId === "string") return parsed.userId;
110
+ } catch {
111
+ }
112
+ }
113
+ return "";
114
+ }
115
+ function readOption(args, flag) {
116
+ const index = args.indexOf(flag);
117
+ return index >= 0 ? args[index + 1] : void 0;
118
+ }
119
+ function isCompiledBinary() {
120
+ try {
121
+ const url = import.meta.url;
122
+ return url.startsWith("file:///$bunfs/root/") || url.startsWith("/$bunfs/root/");
123
+ } catch {
124
+ return false;
125
+ }
126
+ }
127
+ function resolveCliEntrypointPath(fromModuleUrl = import.meta.url) {
128
+ if (isCompiledBinary()) {
129
+ return process.execPath;
130
+ }
131
+ const sourcePath = fileURLToPath(fromModuleUrl);
132
+ const ext = extname(sourcePath) || ".ts";
133
+ return join(dirname(sourcePath), "..", `index${ext}`);
134
+ }
135
+
136
+ export {
137
+ resolveServerUrl,
138
+ resolveServerCandidates,
139
+ resolveDeleteServerCandidates,
140
+ resolveAuthTokenFromEnv,
141
+ resolveAuthToken,
142
+ parseUserIdFromAuthToken,
143
+ readOption,
144
+ isCompiledBinary,
145
+ resolveCliEntrypointPath
146
+ };