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

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-42U3VOVZ.js +205 -0
  3. package/action-TLI3V62L.js +28 -0
  4. package/addContentAction-57RSIIMR.js +26 -0
  5. package/addDialogAgentAction-G3VWEA6E.js +68 -0
  6. package/agentDeleteCommand-5DD2IM3J.js +327 -0
  7. package/agentEmailCommands-6FACJBU4.js +628 -0
  8. package/agentListCommands-I6KZYCIG.js +223 -0
  9. package/agentMachineCommands-VKLIGMZA.js +425 -0
  10. package/agentPullCommand-O2MTUAFR.js +122 -0
  11. package/agentRecordCommands-7TZICYDT.js +96 -0
  12. package/agentRunCommand-L4OM23KV.js +114 -0
  13. package/agentRunControl-K4VKNEHF.js +57 -0
  14. package/agentRuntimeLocal-ZYEIPTY4.js +104 -0
  15. package/agentSlice-BX7GXSNO.js +42 -0
  16. package/authCommand-EB5JSOX5.js +581 -0
  17. package/authCommands-XPEHTKSM.js +35 -0
  18. package/chunk-25LCXTML.js +175 -0
  19. package/chunk-2ECQG4YX.js +22296 -0
  20. package/chunk-2FTTDCD4.js +675 -0
  21. package/chunk-2JCXITPK.js +1078 -0
  22. package/chunk-3ASDTTEI.js +1774 -0
  23. package/chunk-3EUW3WEO.js +8 -0
  24. package/chunk-3LY4F7SV.js +9293 -0
  25. package/chunk-4CQLVGRV.js +50 -0
  26. package/chunk-4IJYA27C.js +342 -0
  27. package/chunk-4O3CARJ4.js +231 -0
  28. package/chunk-4QEWT7KD.js +933 -0
  29. package/chunk-4SN6J65J.js +38 -0
  30. package/chunk-4VNS5WPM.js +42 -0
  31. package/chunk-4XENYTF5.js +222 -0
  32. package/chunk-4ZDM73SD.js +34 -0
  33. package/chunk-5CS33IBL.js +301 -0
  34. package/chunk-5EFXE3O7.js +138 -0
  35. package/chunk-5KLGBAAR.js +386 -0
  36. package/chunk-5MIDPSSK.js +206 -0
  37. package/chunk-5MMAK75Q.js +15 -0
  38. package/chunk-63W5N6P3.js +150 -0
  39. package/chunk-6HYVJV7B.js +102 -0
  40. package/chunk-6KHNO3SK.js +1948 -0
  41. package/chunk-6WD3OOJS.js +20 -0
  42. package/chunk-7DAJ4AI4.js +191 -0
  43. package/chunk-7GNGZRLZ.js +1939 -0
  44. package/chunk-7KCUSYT2.js +354 -0
  45. package/chunk-7U44LYTR.js +238 -0
  46. package/chunk-AFON4QUU.js +112 -0
  47. package/chunk-AGFH73SK.js +239 -0
  48. package/chunk-AL2KDGR2.js +27339 -0
  49. package/chunk-AS4PVWA4.js +221 -0
  50. package/chunk-ATNTHIZI.js +13 -0
  51. package/chunk-AVMKZHBC.js +85 -0
  52. package/chunk-AZPCASRE.js +36 -0
  53. package/chunk-BBYVOSU2.js +792 -0
  54. package/chunk-C3RUNRHT.js +51 -0
  55. package/chunk-C4FTUXVF.js +146 -0
  56. package/chunk-CF2WZF4N.js +134 -0
  57. package/chunk-CF7PE763.js +10 -0
  58. package/chunk-CKOJQDKR.js +198 -0
  59. package/chunk-CMKUBIGW.js +1550 -0
  60. package/chunk-CWMSB67P.js +34 -0
  61. package/chunk-DCOA4QSN.js +105 -0
  62. package/chunk-DFFIZ25G.js +30 -0
  63. package/chunk-DSZUWUYB.js +478 -0
  64. package/chunk-DWLEOOGR.js +8 -0
  65. package/chunk-DZ3XJVET.js +231 -0
  66. package/chunk-EHLHSX7R.js +1433 -0
  67. package/chunk-ENOG22KJ.js +939 -0
  68. package/chunk-FSO5B7GH.js +171 -0
  69. package/chunk-FVYY6MCS.js +1447 -0
  70. package/chunk-G3SUCT4W.js +8 -0
  71. package/chunk-GAKEBQD6.js +30 -0
  72. package/chunk-GBRG75BQ.js +86 -0
  73. package/chunk-GU3PEVGZ.js +4723 -0
  74. package/chunk-H33743XH.js +25 -0
  75. package/chunk-HNMXYYJR.js +12 -0
  76. package/chunk-HNW7IJSK.js +71 -0
  77. package/chunk-I42VC5KR.js +15 -0
  78. package/chunk-I6XMPTMR.js +113 -0
  79. package/chunk-IDZTNRP2.js +85 -0
  80. package/chunk-ISNCLGUZ.js +146 -0
  81. package/chunk-IWX4UW2E.js +548 -0
  82. package/chunk-JBTJAPUF.js +35 -0
  83. package/chunk-JEXVIMYZ.js +55 -0
  84. package/chunk-JRKKFRAV.js +537 -0
  85. package/chunk-JZPBVBIY.js +94 -0
  86. package/chunk-KKY4B2Q2.js +21 -0
  87. package/chunk-KQHGZWSV.js +63 -0
  88. package/chunk-KUG52IAP.js +8 -0
  89. package/chunk-KX6YBIHG.js +8 -0
  90. package/chunk-LCBAMY2M.js +60 -0
  91. package/chunk-LM6IYQ3F.js +16 -0
  92. package/chunk-LTRXGFMS.js +83 -0
  93. package/chunk-M76ECQRD.js +13658 -0
  94. package/chunk-MRC4Q34M.js +188 -0
  95. package/chunk-MTU75CZ2.js +91 -0
  96. package/chunk-N54XAP77.js +19 -0
  97. package/chunk-O2ZNTTET.js +3272 -0
  98. package/chunk-O4BU24WZ.js +3212 -0
  99. package/chunk-OLZBQWZU.js +6 -0
  100. package/chunk-OOSFSFMA.js +271 -0
  101. package/chunk-OPZYGHUC.js +89 -0
  102. package/chunk-OWOHNGCN.js +50 -0
  103. package/chunk-P3PKED2I.js +962 -0
  104. package/chunk-QSJ3HFEF.js +8 -0
  105. package/chunk-RCSJFQPB.js +9036 -0
  106. package/chunk-RL776AGR.js +190 -0
  107. package/chunk-ROWQEJRP.js +139 -0
  108. package/chunk-S7Z2HMCN.js +25 -0
  109. package/chunk-SDJDLO5W.js +628 -0
  110. package/chunk-SOTZ6RDN.js +69 -0
  111. package/chunk-TILFE6LV.js +381 -0
  112. package/chunk-U4TRT5V4.js +246 -0
  113. package/chunk-U6VC4MU4.js +8 -0
  114. package/chunk-UAD2WT54.js +64 -0
  115. package/chunk-UB6SN4NJ.js +421 -0
  116. package/chunk-URUUZLPA.js +807 -0
  117. package/chunk-UTLZINAP.js +3066 -0
  118. package/chunk-VC6OZXO5.js +298 -0
  119. package/chunk-VF4K2QE6.js +21 -0
  120. package/chunk-VHBWHNVT.js +59 -0
  121. package/chunk-VIDPVFP3.js +20 -0
  122. package/chunk-VP4WJWKW.js +8882 -0
  123. package/chunk-VUW5FBDB.js +573 -0
  124. package/chunk-VVX233PH.js +482 -0
  125. package/chunk-VX3SXJ3N.js +2052 -0
  126. package/chunk-W4NVOSFF.js +37 -0
  127. package/chunk-WWC7I6TA.js +8 -0
  128. package/chunk-WZSRQNQG.js +2587 -0
  129. package/chunk-XBUBEFNX.js +34 -0
  130. package/chunk-XENYHRUE.js +104 -0
  131. package/chunk-Y5GCAMGP.js +9 -0
  132. package/chunk-YPRZSPF3.js +148 -0
  133. package/chunk-Z4NR32XR.js +50 -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-RJF3N2QY.js +866 -0
  138. package/createDialogAction-DRSPS6CE.js +55 -0
  139. package/createPageAction-6B2WMNO3.js +172 -0
  140. package/db-HCJ5PRB5.js +271 -0
  141. package/dbSlice-Q3TM2FJV.js +60 -0
  142. package/deleteFile-OW53A6BX.js +41 -0
  143. package/dialogCommands-4IX4XIZE.js +63 -0
  144. package/dialogSlice-3M7KX2TX.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-SV7E34D4.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-JYETO5RZ.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-RIO3RP5Q.js +781 -0
  160. package/machineInfo-M6KB6HZN.js +10 -0
  161. package/machineWsRunDispatch-W7UYLGB5.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 -24
  166. package/read-GW7ZEI23.js +17 -0
  167. package/readDocTool-HUFU6OCT.js +16 -0
  168. package/readlineWorkspace-27JR7WPW.js +5682 -0
  169. package/removeDialogAgentAction-CXKR4NJI.js +73 -0
  170. package/runAgentClientLoop-HZFAPJHS.js +293 -0
  171. package/runtimeDoctorCommands-LRHLPDRC.js +289 -0
  172. package/setDialogExtraReferencesAction-6RKUSXHX.js +60 -0
  173. package/setPrimaryDialogAgentAction-T3UTBEFG.js +80 -0
  174. package/settingSlice-IVKXJXMG.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-TSVROA5U.js +149 -0
  181. package/streamAgentChatTurn-3C5RQZJF.js +4510 -0
  182. package/tableCommands-O7O2LBEG.js +1286 -0
  183. package/toolApiClient-QI3YBNWB.js +26 -0
  184. package/tools-EQDEKR6N.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-3XV7VWSZ.js +188 -0
@@ -0,0 +1,25 @@
1
+ import {
2
+ resolveNoloHome
3
+ } from "./chunk-LM6IYQ3F.js";
4
+
5
+ // packages/cli/localRuntimeDb.ts
6
+ import path from "node:path";
7
+ function resolveCliLocalRuntimeDbPath(options = {}) {
8
+ return path.join(resolveNoloHome(options), "data", "leveldb");
9
+ }
10
+ function buildCliLocalRuntimeDbEnv(env = process.env) {
11
+ return {
12
+ ...env,
13
+ NOLO_SERVER_DB_PATH: env.NOLO_SERVER_DB_PATH?.trim() || resolveCliLocalRuntimeDbPath({ env })
14
+ };
15
+ }
16
+ async function getDefaultCliLocalRuntimeDb(options = {}) {
17
+ const { getDefaultCliLocalRuntimeDb: getAuthorityBackedDb } = await import("./localRuntimeAuthority-TEGCOWX4.js");
18
+ return getAuthorityBackedDb(options);
19
+ }
20
+
21
+ export {
22
+ resolveCliLocalRuntimeDbPath,
23
+ buildCliLocalRuntimeDbEnv,
24
+ getDefaultCliLocalRuntimeDb
25
+ };
@@ -0,0 +1,12 @@
1
+ // packages/core/errorMessage.ts
2
+ function toErrorMessage(error) {
3
+ if (error instanceof Error) return error.message;
4
+ if (error !== null && typeof error === "object" && "message" in error && typeof error.message === "string") {
5
+ return error.message;
6
+ }
7
+ return String(error);
8
+ }
9
+
10
+ export {
11
+ toErrorMessage
12
+ };
@@ -0,0 +1,71 @@
1
+ import {
2
+ createMemoryKey,
3
+ createMemoryOwnerIndexKey,
4
+ createMemorySubjectKindIndexKey,
5
+ ulid
6
+ } from "./chunk-O4BU24WZ.js";
7
+
8
+ // packages/ai/memory/storeShared.ts
9
+ var createMemoryItem = (input) => {
10
+ const now = (/* @__PURE__ */ new Date()).toISOString();
11
+ return {
12
+ id: ulid(),
13
+ createdAt: now,
14
+ lastActivatedAt: now,
15
+ activationCount: 0,
16
+ ...input
17
+ };
18
+ };
19
+ var writeMemoryItemWithIndexesToDb = async (db, item) => {
20
+ const batch = db.batch();
21
+ batch.put(createMemoryKey(item.ownerType, item.ownerId, item.id), item);
22
+ batch.put(
23
+ createMemoryOwnerIndexKey(
24
+ item.ownerType,
25
+ item.ownerId,
26
+ item.createdAt,
27
+ item.id
28
+ ),
29
+ {
30
+ memoryKey: createMemoryKey(item.ownerType, item.ownerId, item.id),
31
+ ownerType: item.ownerType,
32
+ ownerId: item.ownerId,
33
+ memoryId: item.id
34
+ }
35
+ );
36
+ batch.put(
37
+ createMemorySubjectKindIndexKey(
38
+ item.subjectType,
39
+ item.subjectId,
40
+ item.kind,
41
+ item.createdAt,
42
+ item.id
43
+ ),
44
+ {
45
+ memoryKey: createMemoryKey(item.ownerType, item.ownerId, item.id),
46
+ subjectType: item.subjectType,
47
+ subjectId: item.subjectId,
48
+ kind: item.kind,
49
+ memoryId: item.id
50
+ }
51
+ );
52
+ await batch.write();
53
+ };
54
+ var touchMemoryItemsInDb = async (db, items, now = (/* @__PURE__ */ new Date()).toISOString()) => {
55
+ if (items.length === 0) return;
56
+ const batch = db.batch();
57
+ for (const item of items) {
58
+ batch.put(createMemoryKey(item.ownerType, item.ownerId, item.id), {
59
+ ...item,
60
+ lastActivatedAt: now,
61
+ activationCount: (item.activationCount ?? 0) + 1
62
+ });
63
+ }
64
+ await batch.write();
65
+ };
66
+
67
+ export {
68
+ createMemoryItem,
69
+ writeMemoryItemWithIndexesToDb,
70
+ touchMemoryItemsInDb
71
+ };
@@ -0,0 +1,15 @@
1
+ // packages/core/stringArray.ts
2
+ function asNonEmptyStringArray(value) {
3
+ if (!Array.isArray(value)) return [];
4
+ return value.filter(
5
+ (item) => typeof item === "string" && !!item.trim()
6
+ );
7
+ }
8
+ function asTrimmedNonEmptyStringArray(value) {
9
+ return asNonEmptyStringArray(value).map((item) => item.trim());
10
+ }
11
+
12
+ export {
13
+ asNonEmptyStringArray,
14
+ asTrimmedNonEmptyStringArray
15
+ };
@@ -0,0 +1,113 @@
1
+ import {
2
+ createSpaceKey
3
+ } from "./chunk-UAD2WT54.js";
4
+ import {
5
+ patch,
6
+ read
7
+ } from "./chunk-URUUZLPA.js";
8
+ import {
9
+ DEVICE_LOCAL_OWNER_ID,
10
+ isDeviceLocalSpaceBody,
11
+ selectIdentityUserId
12
+ } from "./chunk-UTLZINAP.js";
13
+
14
+ // packages/create/space/utils/permissions.ts
15
+ var checkSpaceMembership = (spaceData, userId) => {
16
+ if (!spaceData) {
17
+ console.error("[Permission Check] Space data is missing.");
18
+ throw new Error("\u65E0\u6CD5\u6267\u884C\u6743\u9650\u68C0\u67E5\uFF1A\u7A7A\u95F4\u6570\u636E\u7F3A\u5931\u3002");
19
+ }
20
+ if (isDeviceLocalSpaceBody(spaceData)) {
21
+ return;
22
+ }
23
+ if (!userId) {
24
+ console.error("[Permission Check] User ID is missing.");
25
+ throw new Error("\u65E0\u6CD5\u6267\u884C\u6743\u9650\u68C0\u67E5\uFF1A\u7528\u6237 ID \u7F3A\u5931\u3002");
26
+ }
27
+ if (!spaceData.members || !Array.isArray(spaceData.members) || !spaceData.members.includes(userId)) {
28
+ console.warn(
29
+ `[Permission Check] User ${userId} attempt to operate on space ${spaceData.id} without membership.`
30
+ );
31
+ throw new Error("\u5F53\u524D\u7528\u6237\u4E0D\u662F\u7A7A\u95F4\u6210\u5458");
32
+ }
33
+ };
34
+ var localSpaceAuthorityPatchStamp = (spaceData) => isDeviceLocalSpaceBody(spaceData) ? { userId: DEVICE_LOCAL_OWNER_ID } : {};
35
+
36
+ // packages/create/space/constants.ts
37
+ var UNCATEGORIZED_ID = "__uncategorized_container__";
38
+
39
+ // packages/create/space/content/addContentAction.ts
40
+ var addContentAction = async (input, thunkAPI) => {
41
+ const {
42
+ spaceId,
43
+ title,
44
+ type,
45
+ contentKey,
46
+ fileCategory,
47
+ mimeType,
48
+ fileSize,
49
+ originalName,
50
+ categoryId: rawCategoryId,
51
+ pinned = false,
52
+ order,
53
+ triggerType,
54
+ skillSummary
55
+ } = input;
56
+ const { dispatch, getState } = thunkAPI;
57
+ const userId = selectIdentityUserId(getState());
58
+ if (!contentKey || typeof contentKey !== "string" || contentKey.trim() === "")
59
+ throw new Error("Invalid contentKey provided.");
60
+ if (!title || typeof title !== "string" || title.trim() === "")
61
+ throw new Error("Invalid or empty title provided.");
62
+ if (!type || typeof type !== "string")
63
+ throw new Error("Invalid content type provided.");
64
+ const spaceKey = createSpaceKey.space(spaceId);
65
+ const spaceData = await dispatch(read({
66
+ dbKey: spaceKey
67
+ })).unwrap();
68
+ checkSpaceMembership(spaceData, userId);
69
+ if (spaceData.contents && spaceData.contents[contentKey]) {
70
+ throw new Error(`\u5185\u5BB9\u952E "${contentKey}" \u5DF2\u5B58\u5728\u3002`);
71
+ }
72
+ let categoryIdForStorage;
73
+ if (rawCategoryId && rawCategoryId !== "" && rawCategoryId !== UNCATEGORIZED_ID) {
74
+ if (spaceData.categories?.[rawCategoryId]) {
75
+ categoryIdForStorage = rawCategoryId;
76
+ }
77
+ }
78
+ const now = Date.now();
79
+ const newSpaceContent = {
80
+ title: title.trim(),
81
+ type,
82
+ contentKey,
83
+ ...fileCategory !== void 0 ? { fileCategory } : {},
84
+ ...mimeType !== void 0 ? { mimeType } : {},
85
+ ...fileSize !== void 0 ? { fileSize } : {},
86
+ ...originalName !== void 0 ? { originalName } : {},
87
+ ...categoryIdForStorage !== void 0 && {
88
+ categoryId: categoryIdForStorage
89
+ },
90
+ pinned,
91
+ createdAt: now,
92
+ updatedAt: now,
93
+ ...order !== void 0 && typeof order === "number" && { order },
94
+ ...triggerType !== void 0 && { triggerType },
95
+ ...skillSummary !== void 0 ? { skillSummary } : {}
96
+ };
97
+ const changes = {
98
+ contents: { [contentKey]: newSpaceContent },
99
+ updatedAt: now,
100
+ ...localSpaceAuthorityPatchStamp(spaceData)
101
+ };
102
+ const updatedSpaceData = await dispatch(
103
+ patch({ dbKey: spaceKey, changes })
104
+ ).unwrap();
105
+ return { spaceId, updatedSpaceData };
106
+ };
107
+
108
+ export {
109
+ checkSpaceMembership,
110
+ localSpaceAuthorityPatchStamp,
111
+ UNCATEGORIZED_ID,
112
+ addContentAction
113
+ };
@@ -0,0 +1,85 @@
1
+ // packages/cli/processSpawn.ts
2
+ import { spawn } from "node:child_process";
3
+ function spawnProcess(options) {
4
+ let [command, ...args] = options.cmd;
5
+ if (process.platform === "win32") {
6
+ const lower = command.toLowerCase();
7
+ if ((lower === "npm" || lower === "npx" || lower === "pnpm" || lower === "yarn" || lower === "nolo") && !lower.endsWith(".cmd") && !lower.endsWith(".exe") && !lower.endsWith(".bat")) {
8
+ command = `${command}.cmd`;
9
+ }
10
+ }
11
+ let child;
12
+ try {
13
+ child = spawn(command, args, {
14
+ cwd: options.cwd,
15
+ env: options.env,
16
+ stdio: [
17
+ options.stdin ?? "pipe",
18
+ options.stdout ?? "pipe",
19
+ options.stderr ?? "pipe"
20
+ ]
21
+ });
22
+ } catch {
23
+ return {
24
+ exited: Promise.resolve(127),
25
+ stdin: null,
26
+ stdout: null,
27
+ stderr: null
28
+ };
29
+ }
30
+ const exited = new Promise((resolve) => {
31
+ child.on("exit", (code) => resolve(code ?? 1));
32
+ child.on("error", () => resolve(127));
33
+ });
34
+ return {
35
+ exited,
36
+ stdin: child.stdin,
37
+ stdout: child.stdout,
38
+ stderr: child.stderr
39
+ };
40
+ }
41
+ async function readPipeText(stream) {
42
+ if (!stream) return "";
43
+ const anyStream = stream;
44
+ if (typeof anyStream.setEncoding !== "function" && typeof anyStream[Symbol.asyncIterator] === "function") {
45
+ const chunks = [];
46
+ for await (const chunk of anyStream) {
47
+ if (typeof chunk === "string") chunks.push(chunk);
48
+ else if (chunk instanceof Uint8Array) chunks.push(Buffer.from(chunk).toString("utf8"));
49
+ else if (Buffer.isBuffer(chunk)) chunks.push(chunk.toString("utf8"));
50
+ else chunks.push(String(chunk ?? ""));
51
+ }
52
+ return chunks.join("");
53
+ }
54
+ return new Promise((resolve) => {
55
+ let data = "";
56
+ let done = false;
57
+ const finish = () => {
58
+ if (done) return;
59
+ done = true;
60
+ resolve(data);
61
+ };
62
+ if (typeof anyStream.setEncoding === "function") {
63
+ anyStream.setEncoding("utf8");
64
+ }
65
+ stream.on("data", (chunk) => {
66
+ data += typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf8");
67
+ });
68
+ stream.on("end", finish);
69
+ stream.on("close", finish);
70
+ stream.on("error", finish);
71
+ });
72
+ }
73
+ function resolveDefaultSpawn() {
74
+ const bunSpawn = globalThis.Bun?.spawn;
75
+ if (typeof bunSpawn === "function") {
76
+ return bunSpawn;
77
+ }
78
+ return spawnProcess;
79
+ }
80
+
81
+ export {
82
+ spawnProcess,
83
+ readPipeText,
84
+ resolveDefaultSpawn
85
+ };
@@ -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
+ };