nolo-cli 0.6.1 → 0.8.0-alpha.10

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 (175) hide show
  1. package/_executeModel-CPDNUUQV.js +198 -0
  2. package/action-PAXRPJJF.js +27 -0
  3. package/addContentAction-CZVWF3QZ.js +25 -0
  4. package/addDialogAgentAction-CCIDTPHC.js +67 -0
  5. package/agentDeleteCommand-OSUMJMZM.js +323 -0
  6. package/agentEmailCommands-OQTJIPQU.js +621 -0
  7. package/agentListCommands-FATQEUYT.js +219 -0
  8. package/agentMachineCommands-6LZWF4GL.js +421 -0
  9. package/agentPullCommand-O2MTUAFR.js +122 -0
  10. package/agentRecordCommands-TIHFU65Z.js +89 -0
  11. package/agentRunCommand-R64Y3HCH.js +102 -0
  12. package/agentRunControl-K4VKNEHF.js +57 -0
  13. package/agentRuntimeLocal-6PIWAHLQ.js +99 -0
  14. package/agentSlice-TP4VARJF.js +41 -0
  15. package/authCommand-WXMD3IPR.js +574 -0
  16. package/authCommands-X74AFDTC.js +26 -0
  17. package/chunk-2EISRLRC.js +238 -0
  18. package/chunk-2FTTDCD4.js +675 -0
  19. package/chunk-2MALU52L.js +51 -0
  20. package/chunk-2TPUKEU7.js +1078 -0
  21. package/chunk-3ASDTTEI.js +1774 -0
  22. package/chunk-3EUW3WEO.js +8 -0
  23. package/chunk-3LY4F7SV.js +9293 -0
  24. package/chunk-4CQLVGRV.js +50 -0
  25. package/chunk-4IJYA27C.js +342 -0
  26. package/chunk-4SN6J65J.js +38 -0
  27. package/chunk-4VNS5WPM.js +42 -0
  28. package/chunk-572EKYLF.js +792 -0
  29. package/chunk-5MIDPSSK.js +206 -0
  30. package/chunk-5MMAK75Q.js +15 -0
  31. package/chunk-5VV37AT4.js +222 -0
  32. package/chunk-63W5N6P3.js +150 -0
  33. package/chunk-6A5EF6IR.js +929 -0
  34. package/chunk-6HYVJV7B.js +102 -0
  35. package/chunk-6P2WX5IA.js +3631 -0
  36. package/chunk-6WD3OOJS.js +20 -0
  37. package/chunk-ATNTHIZI.js +13 -0
  38. package/chunk-AUGHVUFE.js +69 -0
  39. package/chunk-AVMKZHBC.js +85 -0
  40. package/chunk-AZPCASRE.js +36 -0
  41. package/chunk-BNMT7YY5.js +34 -0
  42. package/chunk-BR2WP3DF.js +548 -0
  43. package/chunk-BSTNFPHD.js +231 -0
  44. package/chunk-BU4OPIXC.js +171 -0
  45. package/chunk-CF2WZF4N.js +134 -0
  46. package/chunk-CF7PE763.js +10 -0
  47. package/chunk-CKOJQDKR.js +198 -0
  48. package/chunk-CM54RSSA.js +206 -0
  49. package/chunk-CWMSB67P.js +34 -0
  50. package/chunk-DA2OEKS6.js +27 -0
  51. package/chunk-DFFIZ25G.js +30 -0
  52. package/chunk-DWLEOOGR.js +8 -0
  53. package/chunk-DZ3XJVET.js +231 -0
  54. package/chunk-EHLHSX7R.js +1433 -0
  55. package/chunk-ELRRLDWI.js +478 -0
  56. package/chunk-EYEEHCU4.js +3066 -0
  57. package/chunk-FQZWM5YX.js +628 -0
  58. package/chunk-G3SUCT4W.js +8 -0
  59. package/chunk-G5H7RNFL.js +807 -0
  60. package/chunk-GAKEBQD6.js +30 -0
  61. package/chunk-GBRG75BQ.js +86 -0
  62. package/chunk-H2RMRZJE.js +113 -0
  63. package/chunk-H33743XH.js +25 -0
  64. package/chunk-HD63YREL.js +19 -0
  65. package/chunk-HEIIIZBX.js +104 -0
  66. package/chunk-HNMXYYJR.js +12 -0
  67. package/chunk-HOMYP7GZ.js +2152 -0
  68. package/chunk-HZFOMJRA.js +4300 -0
  69. package/chunk-IAXBCTTE.js +175 -0
  70. package/chunk-IDZTNRP2.js +85 -0
  71. package/chunk-IHHA5Y2S.js +9013 -0
  72. package/chunk-ISNCLGUZ.js +146 -0
  73. package/chunk-IYQV26RA.js +138 -0
  74. package/chunk-J4576WMJ.js +91 -0
  75. package/chunk-JBTJAPUF.js +35 -0
  76. package/chunk-JZPBVBIY.js +94 -0
  77. package/chunk-KQHGZWSV.js +63 -0
  78. package/chunk-KUG52IAP.js +8 -0
  79. package/chunk-KX6YBIHG.js +8 -0
  80. package/chunk-LCBAMY2M.js +60 -0
  81. package/chunk-LM25IZBJ.js +902 -0
  82. package/chunk-LM6IYQ3F.js +16 -0
  83. package/chunk-M76ECQRD.js +13658 -0
  84. package/chunk-MRC4Q34M.js +188 -0
  85. package/chunk-NEMRK4EK.js +944 -0
  86. package/chunk-NXZGF7F7.js +2878 -0
  87. package/chunk-OF5H3QWS.js +300 -0
  88. package/chunk-OLZBQWZU.js +6 -0
  89. package/chunk-OOYVBFM7.js +191 -0
  90. package/chunk-OWOHNGCN.js +50 -0
  91. package/chunk-PN7AFLOK.js +3401 -0
  92. package/chunk-POCFIDGQ.js +562 -0
  93. package/chunk-Q6WACBKB.js +1949 -0
  94. package/chunk-QFV2OAIM.js +421 -0
  95. package/chunk-QJ6V2NIN.js +1447 -0
  96. package/chunk-QSJ3HFEF.js +8 -0
  97. package/chunk-QUWDTOUP.js +190 -0
  98. package/chunk-QYXLLLGL.js +4519 -0
  99. package/chunk-ROWQEJRP.js +139 -0
  100. package/chunk-S7Z2HMCN.js +25 -0
  101. package/chunk-TDIQFT2F.js +301 -0
  102. package/chunk-TILFE6LV.js +381 -0
  103. package/chunk-TKOUBWBO.js +24674 -0
  104. package/chunk-TYH5JE6N.js +27158 -0
  105. package/chunk-U4TRT5V4.js +246 -0
  106. package/chunk-U6VC4MU4.js +8 -0
  107. package/chunk-UAD2WT54.js +64 -0
  108. package/chunk-USZMK5UT.js +105 -0
  109. package/chunk-VEJLAVTC.js +2052 -0
  110. package/chunk-VF4K2QE6.js +21 -0
  111. package/chunk-VHBWHNVT.js +59 -0
  112. package/chunk-VIDPVFP3.js +20 -0
  113. package/chunk-VP4WJWKW.js +8882 -0
  114. package/chunk-VQ2AJRGD.js +148 -0
  115. package/chunk-W4NVOSFF.js +37 -0
  116. package/chunk-WWC7I6TA.js +8 -0
  117. package/chunk-X7W4TNB4.js +1550 -0
  118. package/chunk-XDVAYP26.js +537 -0
  119. package/chunk-XKIMRZO2.js +221 -0
  120. package/chunk-Y5GCAMGP.js +9 -0
  121. package/chunk-YWPXYBY7.js +360 -0
  122. package/chunk-Z4NR32XR.js +50 -0
  123. package/chunk-ZNFJWEN4.js +56 -0
  124. package/cliExecutor-DNE7TCC4.js +36 -0
  125. package/clipboardy-BVE3LVEH.js +12001 -0
  126. package/createAgentAutomationAction-KLKS2HGU.js +864 -0
  127. package/createDialogAction-Z33JMBF5.js +52 -0
  128. package/createPageAction-AQVNOAAI.js +169 -0
  129. package/db-HCJ5PRB5.js +271 -0
  130. package/dbSlice-C4UJLRZP.js +59 -0
  131. package/deleteFile-4SKGPHOZ.js +41 -0
  132. package/dialogCommands-W5PD6MZU.js +59 -0
  133. package/dialogSlice-RBJYVSAR.js +146 -0
  134. package/docCreateCommands-MM34S4Z3.js +215 -0
  135. package/docDeleteCommands-JJTU722V.js +176 -0
  136. package/docReadCommands-GLYDMCTU.js +129 -0
  137. package/docStore-5TYME4DO.js +96 -0
  138. package/docUpdateCommands-ZCGQ7URR.js +313 -0
  139. package/fetchMessages-JOCYIFKL.js +16 -0
  140. package/getPricing-PWPJ6MNV.js +30 -0
  141. package/handleSendMessageAction-KA2MRW6E.js +183 -0
  142. package/index.js +184 -112254
  143. package/lib-FYYBQIXS.js +19839 -0
  144. package/localDialogRead-D3BELSTF.js +26 -0
  145. package/localFirstLog-DHNOY2NA.js +19 -0
  146. package/localRuntimeAuthority-TEGCOWX4.js +471 -0
  147. package/localRuntimeDb-LGDF6FQP.js +12 -0
  148. package/machineCommands-ZB5WUSPF.js +774 -0
  149. package/machineInfo-M6KB6HZN.js +10 -0
  150. package/machineWsRunDispatch-GWCAPPCM.js +105 -0
  151. package/memoryCommands-O4MIPIWQ.js +476 -0
  152. package/models-XLEOET3E.js +9 -0
  153. package/offlineMarxistsAgentCommand-BCPJITJL.js +242 -0
  154. package/package.json +3 -25
  155. package/read-RIJCIVKX.js +17 -0
  156. package/readDocTool-GZD2N3LO.js +16 -0
  157. package/readlineWorkspace-FEDY44AA.js +5357 -0
  158. package/removeDialogAgentAction-CXLST3N6.js +72 -0
  159. package/runAgentClientLoop-W4NKE64V.js +288 -0
  160. package/runtimeDoctorCommands-LRHLPDRC.js +289 -0
  161. package/setDialogExtraReferencesAction-LP6VYGU7.js +59 -0
  162. package/setPrimaryDialogAgentAction-D3GGH23T.js +79 -0
  163. package/settingSlice-J4I3Z5H7.js +198 -0
  164. package/skillSummaryMarker-42HKSXYY.js +9 -0
  165. package/slateToRenderMarkdown-Y5IYN73U.js +7 -0
  166. package/slateUtils-2M7MUTWX.js +19 -0
  167. package/spaceCommands-LC4FDAKE.js +450 -0
  168. package/spaceSlice-32XOGBEF.js +145 -0
  169. package/streamAgentChatTurn-YQW32AQH.js +4503 -0
  170. package/tableCommands-GOFP7QKA.js +1286 -0
  171. package/toolApiClient-QI3YBNWB.js +26 -0
  172. package/tools-XGTFRYD7.js +83 -0
  173. package/understanding-HCSFPE7R.js +318 -0
  174. package/updateCommands-VOSPKXFF.js +31 -0
  175. package/updateDialogTitleAction-4LHQDNHQ.js +185 -0
@@ -0,0 +1,72 @@
1
+ import {
2
+ cleanupCliSessionForDialog
3
+ } from "./chunk-IYQV26RA.js";
4
+ import {
5
+ getPrimaryDialogAgentId,
6
+ removeDialogAgentId
7
+ } from "./chunk-Z4NR32XR.js";
8
+ import {
9
+ require_date_fns
10
+ } from "./chunk-M76ECQRD.js";
11
+ import {
12
+ getActiveDialogKey
13
+ } from "./chunk-3ASDTTEI.js";
14
+ import "./chunk-VEJLAVTC.js";
15
+ import "./chunk-Y5GCAMGP.js";
16
+ import {
17
+ patch,
18
+ selectById
19
+ } from "./chunk-G5H7RNFL.js";
20
+ import "./chunk-AZPCASRE.js";
21
+ import "./chunk-2EISRLRC.js";
22
+ import "./chunk-KX6YBIHG.js";
23
+ import "./chunk-PN7AFLOK.js";
24
+ import "./chunk-WWC7I6TA.js";
25
+ import "./chunk-QSJ3HFEF.js";
26
+ import "./chunk-ELRRLDWI.js";
27
+ import "./chunk-EYEEHCU4.js";
28
+ import "./chunk-QYXLLLGL.js";
29
+ import "./chunk-GBRG75BQ.js";
30
+ import "./chunk-4SN6J65J.js";
31
+ import "./chunk-LCBAMY2M.js";
32
+ import "./chunk-3EUW3WEO.js";
33
+ import "./chunk-U6VC4MU4.js";
34
+ import "./chunk-CF7PE763.js";
35
+ import "./chunk-G3SUCT4W.js";
36
+ import "./chunk-KUG52IAP.js";
37
+ import {
38
+ __toESM
39
+ } from "./chunk-4VNS5WPM.js";
40
+
41
+ // packages/chat/dialog/actions/removeDialogAgentAction.ts
42
+ var import_date_fns = __toESM(require_date_fns());
43
+ var removeDialogAgentAction = async (agentId, thunkApi) => {
44
+ const { dispatch, getState } = thunkApi;
45
+ const state = getState();
46
+ const currentDialogKey = getActiveDialogKey();
47
+ if (!currentDialogKey) {
48
+ throw new Error("No current dialog selected");
49
+ }
50
+ const dialogConfig = selectById(
51
+ state,
52
+ currentDialogKey
53
+ );
54
+ if (!dialogConfig) {
55
+ throw new Error("Dialog configuration not found");
56
+ }
57
+ if (getPrimaryDialogAgentId(dialogConfig) === agentId) {
58
+ await cleanupCliSessionForDialog({ dispatch, getState }, dialogConfig);
59
+ }
60
+ return await dispatch(
61
+ patch({
62
+ dbKey: currentDialogKey,
63
+ changes: {
64
+ cybots: removeDialogAgentId(dialogConfig.cybots || [], agentId),
65
+ updatedAt: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date())
66
+ }
67
+ })
68
+ ).unwrap();
69
+ };
70
+ export {
71
+ removeDialogAgentAction
72
+ };
@@ -0,0 +1,288 @@
1
+ import {
2
+ fetchAgentContexts
3
+ } from "./chunk-BNMT7YY5.js";
4
+ import {
5
+ generateRequestBody,
6
+ mergeReferences,
7
+ performFetchRequest
8
+ } from "./chunk-HOMYP7GZ.js";
9
+ import "./chunk-DA2OEKS6.js";
10
+ import "./chunk-2MALU52L.js";
11
+ import {
12
+ findToolExecutor,
13
+ getToolResultErrorData
14
+ } from "./chunk-TYH5JE6N.js";
15
+ import "./chunk-GAKEBQD6.js";
16
+ import "./chunk-KQHGZWSV.js";
17
+ import "./chunk-XKIMRZO2.js";
18
+ import "./chunk-3LY4F7SV.js";
19
+ import "./chunk-VP4WJWKW.js";
20
+ import "./chunk-63W5N6P3.js";
21
+ import "./chunk-QFV2OAIM.js";
22
+ import "./chunk-6A5EF6IR.js";
23
+ import "./chunk-NXZGF7F7.js";
24
+ import "./chunk-HEIIIZBX.js";
25
+ import {
26
+ updateTokensAction
27
+ } from "./chunk-TKOUBWBO.js";
28
+ import "./chunk-MRC4Q34M.js";
29
+ import "./chunk-J4576WMJ.js";
30
+ import "./chunk-CWMSB67P.js";
31
+ import "./chunk-POCFIDGQ.js";
32
+ import "./chunk-IYQV26RA.js";
33
+ import "./chunk-Z4NR32XR.js";
34
+ import "./chunk-M76ECQRD.js";
35
+ import "./chunk-AUGHVUFE.js";
36
+ import "./chunk-H2RMRZJE.js";
37
+ import "./chunk-UAD2WT54.js";
38
+ import "./chunk-USZMK5UT.js";
39
+ import "./chunk-XDVAYP26.js";
40
+ import {
41
+ canonicalizeToolName
42
+ } from "./chunk-LM25IZBJ.js";
43
+ import "./chunk-5MMAK75Q.js";
44
+ import {
45
+ getApiEndpoint
46
+ } from "./chunk-572EKYLF.js";
47
+ import "./chunk-TDIQFT2F.js";
48
+ import "./chunk-JZPBVBIY.js";
49
+ import "./chunk-BR2WP3DF.js";
50
+ import "./chunk-5MIDPSSK.js";
51
+ import {
52
+ extractCustomId
53
+ } from "./chunk-DFFIZ25G.js";
54
+ import "./chunk-3ASDTTEI.js";
55
+ import "./chunk-DWLEOOGR.js";
56
+ import "./chunk-HNMXYYJR.js";
57
+ import "./chunk-IAXBCTTE.js";
58
+ import {
59
+ selectCurrentServer
60
+ } from "./chunk-VEJLAVTC.js";
61
+ import "./chunk-Y5GCAMGP.js";
62
+ import {
63
+ read
64
+ } from "./chunk-G5H7RNFL.js";
65
+ import "./chunk-AZPCASRE.js";
66
+ import "./chunk-2EISRLRC.js";
67
+ import "./chunk-KX6YBIHG.js";
68
+ import "./chunk-PN7AFLOK.js";
69
+ import "./chunk-WWC7I6TA.js";
70
+ import "./chunk-QSJ3HFEF.js";
71
+ import "./chunk-ELRRLDWI.js";
72
+ import {
73
+ selectIdentityToken
74
+ } from "./chunk-EYEEHCU4.js";
75
+ import "./chunk-QYXLLLGL.js";
76
+ import "./chunk-GBRG75BQ.js";
77
+ import "./chunk-4SN6J65J.js";
78
+ import "./chunk-LCBAMY2M.js";
79
+ import "./chunk-3EUW3WEO.js";
80
+ import "./chunk-U6VC4MU4.js";
81
+ import "./chunk-CF7PE763.js";
82
+ import {
83
+ asOptionalTrimmedString
84
+ } from "./chunk-G3SUCT4W.js";
85
+ import {
86
+ isRecord
87
+ } from "./chunk-KUG52IAP.js";
88
+ import "./chunk-4VNS5WPM.js";
89
+
90
+ // packages/ai/agent/executeToolCall.ts
91
+ async function executeToolCall(tc, thunkApi, context) {
92
+ const toolName = tc.function?.name ?? "";
93
+ const toolArgs = (() => {
94
+ try {
95
+ return JSON.parse(tc.function?.arguments ?? "{}");
96
+ } catch {
97
+ return {};
98
+ }
99
+ })();
100
+ try {
101
+ const toolDefinition = findToolExecutor(toolName);
102
+ if (!toolDefinition) {
103
+ return `[\u5DE5\u5177 "${toolName}" \u672A\u627E\u5230]`;
104
+ }
105
+ const result = await toolDefinition.executor(toolArgs, thunkApi, {
106
+ parentMessageId: context?.parentMessageId ?? ""
107
+ });
108
+ const raw = result?.rawData ?? result;
109
+ return typeof raw === "string" ? raw : JSON.stringify(raw);
110
+ } catch (err) {
111
+ console.error(`[executeToolCall] tool "${toolName}" \u6267\u884C\u5931\u8D25:`, err);
112
+ const structured = getToolResultErrorData(err);
113
+ if (structured?.rawData !== void 0) {
114
+ const raw = structured.rawData;
115
+ return typeof raw === "string" ? raw : JSON.stringify(raw);
116
+ }
117
+ return `[\u5DE5\u5177 "${toolName}" \u6267\u884C\u5931\u8D25: ${err?.message ?? err}]`;
118
+ }
119
+ }
120
+
121
+ // packages/ai/agent/toolFailureGuard.ts
122
+ function parseToolResult(content) {
123
+ if (typeof content !== "string" || !content.trim()) return null;
124
+ try {
125
+ return JSON.parse(content);
126
+ } catch {
127
+ return null;
128
+ }
129
+ }
130
+ function pickString(value) {
131
+ return asOptionalTrimmedString(value) ?? null;
132
+ }
133
+ function getToolError(parsed) {
134
+ if (!parsed || typeof parsed !== "object") return null;
135
+ const error = pickString(parsed.error);
136
+ if (error) return error;
137
+ const message = pickString(parsed.message);
138
+ if (message && (parsed.ok === false || parsed.success === false || parsed.status === "error")) {
139
+ return message;
140
+ }
141
+ if (parsed.ok === false) return "tool returned ok=false";
142
+ if (parsed.success === false) return "tool returned success=false";
143
+ return null;
144
+ }
145
+ function stableStringify(value) {
146
+ if (Array.isArray(value)) {
147
+ return `[${value.map((item) => stableStringify(item)).join(",")}]`;
148
+ }
149
+ if (isRecord(value)) {
150
+ return `{${Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, item]) => `${JSON.stringify(key)}:${stableStringify(item)}`).join(",")}}`;
151
+ }
152
+ return JSON.stringify(value);
153
+ }
154
+ function normalizeToolArgumentsForFailureSignature(rawArguments) {
155
+ if (typeof rawArguments !== "string") return stableStringify(rawArguments ?? null);
156
+ const trimmed = rawArguments.trim();
157
+ if (!trimmed) return "";
158
+ try {
159
+ return stableStringify(JSON.parse(trimmed));
160
+ } catch {
161
+ return trimmed;
162
+ }
163
+ }
164
+ function recordConsecutiveToolFailure(guard, toolCall, toolResult, maxConsecutiveFailures = 3) {
165
+ const parsed = parseToolResult(toolResult);
166
+ const error = getToolError(parsed);
167
+ if (!error) {
168
+ guard.signature = null;
169
+ guard.count = 0;
170
+ return null;
171
+ }
172
+ const toolName = canonicalizeToolName(toolCall.function.name);
173
+ const signature = stableStringify({
174
+ toolName,
175
+ arguments: normalizeToolArgumentsForFailureSignature(toolCall.function.arguments),
176
+ error
177
+ });
178
+ if (signature === guard.signature) {
179
+ guard.count += 1;
180
+ } else {
181
+ guard.signature = signature;
182
+ guard.count = 1;
183
+ }
184
+ if (guard.count < maxConsecutiveFailures) return null;
185
+ return [
186
+ `\u5DF2\u505C\u6B62\u5DE5\u5177\u5FAA\u73AF\uFF1A${toolName} \u4F7F\u7528\u540C\u4E00\u7EC4\u53C2\u6570\u8FDE\u7EED ${guard.count} \u6B21\u8FD4\u56DE\u540C\u4E00\u4E2A\u9519\u8BEF\u3002`,
187
+ `\u9519\u8BEF\uFF1A${error}`,
188
+ "\u8BF7\u5148\u8C03\u6574\u53C2\u6570\u3001\u6362\u4E00\u79CD\u64CD\u4F5C\u8DEF\u5F84\uFF0C\u6216\u5411\u7528\u6237\u786E\u8BA4\u540E\u518D\u7EE7\u7EED\uFF1B\u4E0D\u8981\u7EE7\u7EED\u91CD\u590D\u540C\u4E00\u4E2A\u5931\u8D25\u8C03\u7528\u3002"
189
+ ].join("\n");
190
+ }
191
+
192
+ // packages/ai/agent/runAgentClientLoop.ts
193
+ async function runAgentClientLoop(args, thunkApi) {
194
+ const { agentKey, content, parentMessageId, billingDialogKey } = args;
195
+ const { getState, dispatch } = thunkApi;
196
+ const state = getState();
197
+ const agentConfig = await dispatch(read({ dbKey: agentKey })).unwrap();
198
+ const agentContexts = await fetchAgentContexts(
199
+ mergeReferences(agentConfig.references, args.extraReferences),
200
+ dispatch
201
+ );
202
+ const initialMessages = [{ role: "user", content }];
203
+ const body = generateRequestBody({
204
+ agentConfig,
205
+ messages: initialMessages,
206
+ userInput: typeof content === "string" ? content : JSON.stringify(content),
207
+ contexts: agentContexts
208
+ });
209
+ body.stream = false;
210
+ const messages = body.messages;
211
+ const api = getApiEndpoint(agentConfig);
212
+ const currentServer = selectCurrentServer(state);
213
+ const token = selectIdentityToken(state) ?? "";
214
+ let finalContent = "";
215
+ let toolCallCount = 0;
216
+ const toolFailureGuard = {
217
+ signature: null,
218
+ count: 0
219
+ };
220
+ loop:
221
+ for (; ; ) {
222
+ body.messages = messages;
223
+ const response = await performFetchRequest({
224
+ agentConfig,
225
+ api,
226
+ bodyData: body,
227
+ currentServer,
228
+ token,
229
+ dialogId: billingDialogKey ? extractCustomId(billingDialogKey) || void 0 : void 0
230
+ });
231
+ const data = await response.json();
232
+ const choice = data.choices?.[0];
233
+ if (billingDialogKey && data?.usage) {
234
+ await updateTokensAction(
235
+ {
236
+ dialogId: extractCustomId(billingDialogKey),
237
+ dialogKey: billingDialogKey,
238
+ usage: data.usage,
239
+ agentConfig
240
+ },
241
+ thunkApi
242
+ );
243
+ }
244
+ if (!choice) {
245
+ console.warn("[runAgentClientLoop] \u54CD\u5E94\u4E2D\u627E\u4E0D\u5230 choices[0]\uFF0C\u505C\u6B62");
246
+ break;
247
+ }
248
+ const assistantMsg = choice.message;
249
+ const finishReason = choice.finish_reason ?? "";
250
+ messages.push(assistantMsg);
251
+ if (typeof assistantMsg.content === "string" && assistantMsg.content) {
252
+ finalContent = assistantMsg.content;
253
+ }
254
+ if (!assistantMsg.tool_calls?.length || finishReason === "stop") {
255
+ break;
256
+ }
257
+ for (const tc of assistantMsg.tool_calls) {
258
+ toolCallCount++;
259
+ const toolResultContent = await executeToolCall(tc, thunkApi, {
260
+ parentMessageId,
261
+ agentKey
262
+ });
263
+ const stopReason = recordConsecutiveToolFailure(
264
+ toolFailureGuard,
265
+ tc,
266
+ toolResultContent
267
+ );
268
+ if (stopReason) {
269
+ finalContent = stopReason;
270
+ messages.push({
271
+ role: "tool",
272
+ tool_call_id: tc.id,
273
+ content: toolResultContent
274
+ });
275
+ break loop;
276
+ }
277
+ messages.push({
278
+ role: "tool",
279
+ tool_call_id: tc.id,
280
+ content: toolResultContent
281
+ });
282
+ }
283
+ }
284
+ return { content: finalContent, toolCallCount };
285
+ }
286
+ export {
287
+ runAgentClientLoop
288
+ };
@@ -0,0 +1,289 @@
1
+ import {
2
+ resolveAuthToken,
3
+ resolveServerUrl
4
+ } from "./chunk-ISNCLGUZ.js";
5
+ import "./chunk-OLZBQWZU.js";
6
+ import {
7
+ resolveAgentRuntimeDecision
8
+ } from "./chunk-ZNFJWEN4.js";
9
+ import {
10
+ createCliAuthorityBrokerClient,
11
+ createCliAuthorityBrokerSocketInvoker,
12
+ resolveCliAuthorityBrokerEndpoint,
13
+ resolveCliAuthorityBrokerHealthPath,
14
+ resolveCliAuthorityBrokerMetadataPath,
15
+ resolveCliAuthorityStoreDriver
16
+ } from "./chunk-U4TRT5V4.js";
17
+ import {
18
+ toErrorMessage
19
+ } from "./chunk-HNMXYYJR.js";
20
+ import "./chunk-LM6IYQ3F.js";
21
+ import "./chunk-4SN6J65J.js";
22
+ import "./chunk-LCBAMY2M.js";
23
+ import "./chunk-CF7PE763.js";
24
+ import "./chunk-G3SUCT4W.js";
25
+ import "./chunk-4VNS5WPM.js";
26
+
27
+ // packages/cli/cliAuthorityBrokerHealth.ts
28
+ import fs from "node:fs/promises";
29
+ var defaultCliAuthorityBrokerHealthDeps = {
30
+ async readJson(filePath) {
31
+ return JSON.parse(await fs.readFile(filePath, "utf8"));
32
+ },
33
+ isPidAlive(pid) {
34
+ try {
35
+ process.kill(pid, 0);
36
+ return true;
37
+ } catch (error) {
38
+ return error.code === "EPERM";
39
+ }
40
+ },
41
+ async openEndpoint(endpoint) {
42
+ const client = createCliAuthorityBrokerClient({
43
+ endpoint,
44
+ invoke: createCliAuthorityBrokerSocketInvoker({ endpoint })
45
+ });
46
+ await client.open();
47
+ }
48
+ };
49
+ function asBrokerHealthRecord(value) {
50
+ return typeof value === "object" && value !== null ? value : {};
51
+ }
52
+ async function probeCliAuthorityBrokerHealth(args) {
53
+ const deps = {
54
+ ...defaultCliAuthorityBrokerHealthDeps,
55
+ ...args.deps
56
+ };
57
+ let metadata;
58
+ let health;
59
+ try {
60
+ [metadata, health] = await Promise.all([
61
+ deps.readJson(args.metadataPath).then(asBrokerHealthRecord),
62
+ deps.readJson(args.healthPath).then(asBrokerHealthRecord)
63
+ ]);
64
+ } catch (error) {
65
+ return {
66
+ ok: false,
67
+ error: `authority broker health artifacts are unavailable: ${toErrorMessage(error)}`
68
+ };
69
+ }
70
+ if (health.ok !== true) {
71
+ return { ok: false, error: "authority broker health artifact is not ok" };
72
+ }
73
+ if (typeof metadata.endpoint !== "string" || metadata.endpoint !== args.endpoint || health.endpoint !== args.endpoint) {
74
+ return { ok: false, error: "authority broker endpoint metadata does not match" };
75
+ }
76
+ if (typeof metadata.pid !== "number" || !Number.isInteger(metadata.pid) || metadata.pid <= 0 || health.pid !== metadata.pid) {
77
+ return { ok: false, error: "authority broker pid metadata is invalid" };
78
+ }
79
+ if (!deps.isPidAlive(metadata.pid)) {
80
+ return {
81
+ ok: false,
82
+ error: `authority broker metadata pid ${metadata.pid} is not alive`
83
+ };
84
+ }
85
+ try {
86
+ await deps.openEndpoint(args.endpoint);
87
+ } catch (error) {
88
+ return {
89
+ ok: false,
90
+ error: `authority broker endpoint is unreachable: ${toErrorMessage(error)}`
91
+ };
92
+ }
93
+ return { ok: true };
94
+ }
95
+
96
+ // packages/cli/runtimeDoctorCommands.ts
97
+ function detectLocalAgentConfig(env) {
98
+ return Boolean(readLocalAgentKey(env) || env.NOLO_AGENT_CACHE_READY);
99
+ }
100
+ function readLocalAgentKey(env) {
101
+ return env.NOLO_LOCAL_AGENT_KEY || env.NOLO_AGENT || "";
102
+ }
103
+ function detectLocalProvider(env) {
104
+ return Boolean(
105
+ env.OPENAI_API_KEY || env.ANTHROPIC_API_KEY || env.GOOGLE_API_KEY || env.GEMINI_API_KEY || env.NOLO_LOCAL_OPENAI_BASE_URL || env.OLLAMA_BASE_URL
106
+ );
107
+ }
108
+ function detectProviderLabel(env) {
109
+ if (env.NOLO_LOCAL_OPENAI_BASE_URL) return `openai-compatible endpoint ${env.NOLO_LOCAL_OPENAI_BASE_URL}`;
110
+ if (env.OLLAMA_BASE_URL) return `ollama-compatible endpoint ${env.OLLAMA_BASE_URL}`;
111
+ if (env.OPENAI_API_KEY) return "openai via env OPENAI_API_KEY";
112
+ if (env.ANTHROPIC_API_KEY) return "anthropic via env ANTHROPIC_API_KEY";
113
+ if (env.GOOGLE_API_KEY) return "google via env GOOGLE_API_KEY";
114
+ if (env.GEMINI_API_KEY) return "google via env GEMINI_API_KEY";
115
+ return "missing";
116
+ }
117
+ async function defaultLocalRuntimeProbe(env, deps = {}) {
118
+ const { resolveCliLocalRuntimeDbPath } = await import("./localRuntimeDb-LGDF6FQP.js");
119
+ const dbPath = resolveCliLocalRuntimeDbPath({ env });
120
+ const authorityDriver = resolveCliAuthorityStoreDriver({ env });
121
+ const authorityEndpoint = resolveCliAuthorityBrokerEndpoint({ transport: "tcp", env });
122
+ const authorityMetadataPath = resolveCliAuthorityBrokerMetadataPath({ transport: "tcp", env });
123
+ const authorityHealthPath = resolveCliAuthorityBrokerHealthPath({ transport: "tcp", env });
124
+ const agentKey = readLocalAgentKey(env);
125
+ try {
126
+ const db = deps.getDb ? await deps.getDb() : await import("./localRuntimeDb-LGDF6FQP.js").then(
127
+ ({ getDefaultCliLocalRuntimeDb }) => getDefaultCliLocalRuntimeDb({ env })
128
+ );
129
+ const authorityHealth = await (deps.probeAuthorityHealth ?? probeCliAuthorityBrokerHealth)({
130
+ endpoint: authorityEndpoint,
131
+ metadataPath: authorityMetadataPath,
132
+ healthPath: authorityHealthPath
133
+ });
134
+ if (!authorityHealth.ok) {
135
+ return {
136
+ ok: true,
137
+ dbPath,
138
+ authorityDriver,
139
+ authorityEndpoint,
140
+ authorityMetadataPath,
141
+ authorityHealthPath,
142
+ authorityHealthy: false,
143
+ authorityError: authorityHealth.error,
144
+ agentFound: false,
145
+ ...agentKey ? { agentKey } : {}
146
+ };
147
+ }
148
+ if (!agentKey) {
149
+ return {
150
+ ok: true,
151
+ dbPath,
152
+ authorityDriver,
153
+ authorityEndpoint,
154
+ authorityMetadataPath,
155
+ authorityHealthPath,
156
+ authorityHealthy: true,
157
+ agentFound: false
158
+ };
159
+ }
160
+ try {
161
+ const record = await db.get(agentKey);
162
+ return {
163
+ ok: true,
164
+ dbPath,
165
+ authorityDriver,
166
+ authorityEndpoint,
167
+ authorityMetadataPath,
168
+ authorityHealthPath,
169
+ authorityHealthy: true,
170
+ agentFound: record != null,
171
+ agentKey
172
+ };
173
+ } catch {
174
+ return {
175
+ ok: true,
176
+ dbPath,
177
+ authorityDriver,
178
+ authorityEndpoint,
179
+ authorityMetadataPath,
180
+ authorityHealthPath,
181
+ authorityHealthy: true,
182
+ agentFound: false,
183
+ agentKey
184
+ };
185
+ }
186
+ } catch (error) {
187
+ const errorMessage = toErrorMessage(error);
188
+ return {
189
+ ok: false,
190
+ dbPath,
191
+ authorityDriver,
192
+ authorityEndpoint,
193
+ authorityMetadataPath,
194
+ authorityHealthPath,
195
+ authorityHealthy: false,
196
+ authorityError: errorMessage,
197
+ agentFound: false,
198
+ ...agentKey ? { agentKey } : {},
199
+ error: errorMessage
200
+ };
201
+ }
202
+ }
203
+ async function runDoctorRuntimeCommand(args, deps = {}) {
204
+ const env = deps.env ?? process.env;
205
+ const output = deps.output ?? process.stdout;
206
+ const authToken = resolveAuthToken(args, env);
207
+ const serverUrl = resolveServerUrl(args, env);
208
+ const localProbe = await (deps.localRuntimeProbe ?? defaultLocalRuntimeProbe)(env);
209
+ const hasLocalAgentConfig = detectLocalAgentConfig(env) && localProbe.ok && localProbe.agentFound;
210
+ const hasLocalProvider = detectLocalProvider(env);
211
+ const missingLocalCapabilities = [
212
+ ...localProbe.ok ? [] : ["leveldb"],
213
+ ...localProbe.authorityHealthy === false ? ["authority-broker"] : [],
214
+ ...hasLocalAgentConfig ? [] : ["agent-config"],
215
+ ...hasLocalProvider ? [] : ["provider"]
216
+ ];
217
+ const decision = resolveAgentRuntimeDecision({
218
+ requestedMode: "auto",
219
+ syncRequested: false,
220
+ host: "cli",
221
+ hasLocalAgentConfig,
222
+ hasLocalProvider,
223
+ hasLocalPersistence: true,
224
+ missingLocalCapabilities,
225
+ requiresServer: false,
226
+ serverFallbackAvailable: Boolean(
227
+ authToken || args.includes("--server") || args.includes("--server-url") || env.NOLO_SERVER || env.BASE_URL
228
+ )
229
+ });
230
+ output.write(`Runtime: ${decision.mode}
231
+ `);
232
+ output.write(`Reason: ${decision.reason}
233
+ `);
234
+ output.write(`LevelDB: ${localProbe.ok ? "ok" : "failed"}
235
+ `);
236
+ output.write(`DB path: ${localProbe.dbPath}
237
+ `);
238
+ output.write(`Authority driver: ${localProbe.authorityDriver ?? "unknown"}
239
+ `);
240
+ if (localProbe.authorityEndpoint) {
241
+ output.write(`Authority endpoint: ${localProbe.authorityEndpoint}
242
+ `);
243
+ }
244
+ if (localProbe.authorityMetadataPath) {
245
+ output.write(`Authority metadata: ${localProbe.authorityMetadataPath}
246
+ `);
247
+ }
248
+ if (localProbe.authorityHealthPath) {
249
+ output.write(`Authority health: ${localProbe.authorityHealthPath}
250
+ `);
251
+ }
252
+ output.write(
253
+ `Authority broker: ${localProbe.authorityHealthy === true ? "healthy" : localProbe.authorityHealthy === false ? "unhealthy" : "unknown"}
254
+ `
255
+ );
256
+ if (localProbe.authorityHealthy === false && localProbe.authorityError) {
257
+ output.write(`Authority error: ${localProbe.authorityError}
258
+ `);
259
+ }
260
+ if (!localProbe.ok && localProbe.error) {
261
+ output.write(`DB error: ${localProbe.error}
262
+ `);
263
+ }
264
+ if (localProbe.agentKey) {
265
+ output.write(`Agent config: ${localProbe.agentFound ? "found" : "missing"} (${localProbe.agentKey})
266
+ `);
267
+ } else {
268
+ output.write("Agent config: missing (no local agent key)\n");
269
+ }
270
+ output.write(`Provider: ${hasLocalProvider ? "available" : "missing"} (${detectProviderLabel(env)})
271
+ `);
272
+ output.write("Persistence: LevelDB local store\n");
273
+ output.write(`Sync: ${authToken ? "available" : "unavailable"}${authToken ? "" : " (not authenticated)"}
274
+ `);
275
+ output.write(`Server fallback: ${decision.runnable && decision.mode === "server" ? serverUrl : authToken || env.NOLO_SERVER || env.BASE_URL ? serverUrl : "unavailable"}
276
+ `);
277
+ if (decision.missingLocalCapabilities.length > 0) {
278
+ output.write("Missing local capabilities:\n");
279
+ for (const capability of decision.missingLocalCapabilities) {
280
+ output.write(`- ${capability}
281
+ `);
282
+ }
283
+ }
284
+ return decision.runnable ? 0 : 1;
285
+ }
286
+ export {
287
+ defaultLocalRuntimeProbe,
288
+ runDoctorRuntimeCommand
289
+ };
@@ -0,0 +1,59 @@
1
+ import {
2
+ require_date_fns
3
+ } from "./chunk-M76ECQRD.js";
4
+ import {
5
+ getActiveDialogKey
6
+ } from "./chunk-3ASDTTEI.js";
7
+ import {
8
+ patch,
9
+ selectById
10
+ } from "./chunk-G5H7RNFL.js";
11
+ import "./chunk-AZPCASRE.js";
12
+ import "./chunk-2EISRLRC.js";
13
+ import "./chunk-PN7AFLOK.js";
14
+ import "./chunk-WWC7I6TA.js";
15
+ import "./chunk-QSJ3HFEF.js";
16
+ import "./chunk-ELRRLDWI.js";
17
+ import "./chunk-EYEEHCU4.js";
18
+ import "./chunk-QYXLLLGL.js";
19
+ import "./chunk-GBRG75BQ.js";
20
+ import "./chunk-4SN6J65J.js";
21
+ import "./chunk-LCBAMY2M.js";
22
+ import "./chunk-3EUW3WEO.js";
23
+ import "./chunk-U6VC4MU4.js";
24
+ import "./chunk-CF7PE763.js";
25
+ import "./chunk-G3SUCT4W.js";
26
+ import "./chunk-KUG52IAP.js";
27
+ import {
28
+ __toESM
29
+ } from "./chunk-4VNS5WPM.js";
30
+
31
+ // packages/chat/dialog/actions/setDialogExtraReferencesAction.ts
32
+ var import_date_fns = __toESM(require_date_fns());
33
+ var setDialogExtraReferencesAction = async (extraReferences, thunkApi) => {
34
+ const { dispatch, getState } = thunkApi;
35
+ const state = getState();
36
+ const currentDialogKey = getActiveDialogKey();
37
+ if (!currentDialogKey) {
38
+ throw new Error("No current dialog selected");
39
+ }
40
+ const dialogConfig = selectById(
41
+ state,
42
+ currentDialogKey
43
+ );
44
+ if (!dialogConfig) {
45
+ throw new Error("Dialog configuration not found");
46
+ }
47
+ return await dispatch(
48
+ patch({
49
+ dbKey: currentDialogKey,
50
+ changes: {
51
+ extraReferences: extraReferences ?? [],
52
+ updatedAt: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date())
53
+ }
54
+ })
55
+ ).unwrap();
56
+ };
57
+ export {
58
+ setDialogExtraReferencesAction
59
+ };