nolo-cli 0.8.0 → 0.9.0

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 (183) hide show
  1. package/_executeModel-UD44KGZ4.js +203 -0
  2. package/action-ZJWE3Y5S.js +28 -0
  3. package/addContentAction-TVDBNJM5.js +26 -0
  4. package/addDialogAgentAction-EKH774VT.js +68 -0
  5. package/agentDeleteCommand-TCPEFJTF.js +327 -0
  6. package/agentEmailCommands-CZ3UILZ4.js +626 -0
  7. package/agentListCommands-SJKO2FFB.js +223 -0
  8. package/agentMachineCommands-PSNABISZ.js +425 -0
  9. package/agentPullCommand-O2MTUAFR.js +122 -0
  10. package/agentRecordCommands-MH2JKFHS.js +94 -0
  11. package/agentRunCommand-4KH6MIZR.js +110 -0
  12. package/agentRunControl-K4VKNEHF.js +57 -0
  13. package/agentRuntimeLocal-SKHJUWSS.js +104 -0
  14. package/agentSlice-3WXXN4VK.js +42 -0
  15. package/authCommand-PXFX6JDT.js +581 -0
  16. package/authCommands-356AYWEK.js +35 -0
  17. package/chunk-2EISRLRC.js +238 -0
  18. package/chunk-2FTTDCD4.js +675 -0
  19. package/chunk-2K2ECKSG.js +222 -0
  20. package/chunk-2PUGVR6E.js +19 -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-3TZDXYSF.js +71 -0
  25. package/chunk-3WYQEUBI.js +34 -0
  26. package/chunk-4CQLVGRV.js +50 -0
  27. package/chunk-4IJYA27C.js +342 -0
  28. package/chunk-4K2KKCSD.js +577 -0
  29. package/chunk-4SN6J65J.js +38 -0
  30. package/chunk-4VNS5WPM.js +42 -0
  31. package/chunk-4ZDM73SD.js +34 -0
  32. package/chunk-5CS33IBL.js +301 -0
  33. package/chunk-5KLGBAAR.js +386 -0
  34. package/chunk-5MIDPSSK.js +206 -0
  35. package/chunk-5MMAK75Q.js +15 -0
  36. package/chunk-5PJ3VWCS.js +360 -0
  37. package/chunk-63SLEOLK.js +175 -0
  38. package/chunk-63W5N6P3.js +150 -0
  39. package/chunk-6GANEXVO.js +231 -0
  40. package/chunk-6HYVJV7B.js +102 -0
  41. package/chunk-6WD3OOJS.js +20 -0
  42. package/chunk-7OOXPE3N.js +628 -0
  43. package/chunk-7QRKCBOP.js +1078 -0
  44. package/chunk-ATNTHIZI.js +13 -0
  45. package/chunk-AUQ747NZ.js +902 -0
  46. package/chunk-AVMKZHBC.js +85 -0
  47. package/chunk-AZPCASRE.js +36 -0
  48. package/chunk-BBYVOSU2.js +792 -0
  49. package/chunk-C3RUNRHT.js +51 -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-COMXDWNM.js +807 -0
  54. package/chunk-CPB2YM4D.js +171 -0
  55. package/chunk-CWMSB67P.js +34 -0
  56. package/chunk-DCOA4QSN.js +105 -0
  57. package/chunk-DFFIZ25G.js +30 -0
  58. package/chunk-DWLEOOGR.js +8 -0
  59. package/chunk-DZ3XJVET.js +231 -0
  60. package/chunk-EHLHSX7R.js +1433 -0
  61. package/chunk-ELRRLDWI.js +478 -0
  62. package/chunk-EXTIQUCI.js +482 -0
  63. package/chunk-EYEEHCU4.js +3066 -0
  64. package/chunk-G3SUCT4W.js +8 -0
  65. package/chunk-G43KEVSC.js +1447 -0
  66. package/chunk-GAKEBQD6.js +30 -0
  67. package/chunk-GBRG75BQ.js +86 -0
  68. package/chunk-GG4AJPSR.js +191 -0
  69. package/chunk-H33743XH.js +25 -0
  70. package/chunk-HNMXYYJR.js +12 -0
  71. package/chunk-I42VC5KR.js +15 -0
  72. package/chunk-IDZTNRP2.js +85 -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-KKY4B2Q2.js +21 -0
  80. package/chunk-KOCA5FCS.js +4750 -0
  81. package/chunk-KQHGZWSV.js +63 -0
  82. package/chunk-KTVVPRJS.js +138 -0
  83. package/chunk-KUG52IAP.js +8 -0
  84. package/chunk-KX6YBIHG.js +8 -0
  85. package/chunk-LARL2V6G.js +9017 -0
  86. package/chunk-LCBAMY2M.js +60 -0
  87. package/chunk-LM6IYQ3F.js +16 -0
  88. package/chunk-M76ECQRD.js +13658 -0
  89. package/chunk-MGOJ5R6J.js +113 -0
  90. package/chunk-MKMWT7SA.js +27196 -0
  91. package/chunk-MRC4Q34M.js +188 -0
  92. package/chunk-OLZBQWZU.js +6 -0
  93. package/chunk-OPZYGHUC.js +89 -0
  94. package/chunk-OWOHNGCN.js +50 -0
  95. package/chunk-PAKN26FP.js +239 -0
  96. package/chunk-PCWC3JTN.js +91 -0
  97. package/chunk-PG5PNA7Y.js +939 -0
  98. package/chunk-Q2YZULBH.js +104 -0
  99. package/chunk-QSJ3HFEF.js +8 -0
  100. package/chunk-QYXLLLGL.js +4519 -0
  101. package/chunk-ROWQEJRP.js +139 -0
  102. package/chunk-S7Z2HMCN.js +25 -0
  103. package/chunk-SBR32ZZS.js +1901 -0
  104. package/chunk-SH2CFQOH.js +3391 -0
  105. package/chunk-SL35K7AH.js +226 -0
  106. package/chunk-TILFE6LV.js +381 -0
  107. package/chunk-TSS3XJY4.js +2052 -0
  108. package/chunk-U4TRT5V4.js +246 -0
  109. package/chunk-U6VC4MU4.js +8 -0
  110. package/chunk-UAD2WT54.js +64 -0
  111. package/chunk-UUJDGGAK.js +421 -0
  112. package/chunk-VF4K2QE6.js +21 -0
  113. package/chunk-VHBWHNVT.js +59 -0
  114. package/chunk-VIDPVFP3.js +20 -0
  115. package/chunk-VP4WJWKW.js +8882 -0
  116. package/chunk-W4NVOSFF.js +37 -0
  117. package/chunk-WKM6FH35.js +190 -0
  118. package/chunk-WWC7I6TA.js +8 -0
  119. package/chunk-X7W4TNB4.js +1550 -0
  120. package/chunk-XE635NI4.js +1948 -0
  121. package/chunk-XKIMRZO2.js +221 -0
  122. package/chunk-XS466O7S.js +933 -0
  123. package/chunk-Y5GCAMGP.js +9 -0
  124. package/chunk-YBWOP46I.js +3272 -0
  125. package/chunk-YPRZSPF3.js +148 -0
  126. package/chunk-YYUCRDOK.js +69 -0
  127. package/chunk-Z4NR32XR.js +50 -0
  128. package/chunk-ZIG5LJ7X.js +24765 -0
  129. package/chunk-ZNFJWEN4.js +56 -0
  130. package/chunk-ZQ2UM4KG.js +2878 -0
  131. package/cliExecutor-DNE7TCC4.js +36 -0
  132. package/clipboardy-BVE3LVEH.js +12001 -0
  133. package/createAgentAutomationAction-63OIP6X5.js +866 -0
  134. package/createDialogAction-ZLYZDYBB.js +54 -0
  135. package/createPageAction-AL5FSDCK.js +171 -0
  136. package/db-HCJ5PRB5.js +271 -0
  137. package/dbSlice-PR44QPXY.js +60 -0
  138. package/deleteFile-4SKGPHOZ.js +41 -0
  139. package/dialogCommands-F6YI5742.js +63 -0
  140. package/dialogSlice-JSBNZRLR.js +148 -0
  141. package/docCreateCommands-4CTO7ERT.js +219 -0
  142. package/docDeleteCommands-VBWERDRG.js +180 -0
  143. package/docReadCommands-KNP4MFYB.js +133 -0
  144. package/docStore-ADP5VYY4.js +98 -0
  145. package/docUpdateCommands-4BCBJQHA.js +317 -0
  146. package/fetchMessages-U6ZHN56A.js +17 -0
  147. package/getPricing-3E6UNPKL.js +30 -0
  148. package/handleSendMessageAction-IJDQ6ARA.js +185 -0
  149. package/index.js +188 -112943
  150. package/lib-FYYBQIXS.js +19839 -0
  151. package/localDialogRead-Z5UTAJPU.js +26 -0
  152. package/localFirstLog-DHNOY2NA.js +19 -0
  153. package/localRuntimeAuthority-TEGCOWX4.js +471 -0
  154. package/localRuntimeDb-LGDF6FQP.js +12 -0
  155. package/machineCommands-EA3M4XTN.js +779 -0
  156. package/machineInfo-M6KB6HZN.js +10 -0
  157. package/machineWsRunDispatch-NAPKE5ZA.js +110 -0
  158. package/memoryCommands-O4MIPIWQ.js +476 -0
  159. package/models-4OPOOLFS.js +9 -0
  160. package/offlineMarxistsAgentCommand-BCPJITJL.js +242 -0
  161. package/package.json +3 -25
  162. package/read-RIJCIVKX.js +17 -0
  163. package/readDocTool-GZD2N3LO.js +16 -0
  164. package/readlineWorkspace-KMWT4T4S.js +5509 -0
  165. package/removeDialogAgentAction-GJQJNDW6.js +73 -0
  166. package/runAgentClientLoop-U5Q6NDTJ.js +291 -0
  167. package/runtimeDoctorCommands-LRHLPDRC.js +289 -0
  168. package/setDialogExtraReferencesAction-M7OQG54N.js +60 -0
  169. package/setPrimaryDialogAgentAction-46UNFJDL.js +80 -0
  170. package/settingSlice-FVUUH4JA.js +199 -0
  171. package/skillSummaryMarker-42HKSXYY.js +9 -0
  172. package/slateToRenderMarkdown-Y5IYN73U.js +7 -0
  173. package/slateUtils-2M7MUTWX.js +19 -0
  174. package/spaceCommands-E2CFRPZJ.js +454 -0
  175. package/spaceSlice-L3R6IMXE.js +147 -0
  176. package/streamAgentChatTurn-UBDAOQWE.js +4528 -0
  177. package/tableCommands-GOFP7QKA.js +1286 -0
  178. package/toolApiClient-QI3YBNWB.js +26 -0
  179. package/tools-TMJXZTCA.js +85 -0
  180. package/tuiSummaryLlmCaller-RV3THLZF.js +78 -0
  181. package/understanding-GQKNDDWM.js +271 -0
  182. package/updateCommands-VOSPKXFF.js +31 -0
  183. package/updateDialogTitleAction-ZTWRDXI2.js +188 -0
@@ -0,0 +1,577 @@
1
+ import {
2
+ applyAgentSecretMigrationUpdates,
3
+ createFileCredentialBroker,
4
+ migrateAgentSecrets,
5
+ normalizeAgentRuntimeToolPolicy
6
+ } from "./chunk-5CS33IBL.js";
7
+ import {
8
+ patch,
9
+ remove,
10
+ write
11
+ } from "./chunk-COMXDWNM.js";
12
+ import {
13
+ asRecordOrEmpty
14
+ } from "./chunk-KX6YBIHG.js";
15
+ import {
16
+ createAgentKey,
17
+ require_index_umd,
18
+ toTrimmedString
19
+ } from "./chunk-SH2CFQOH.js";
20
+ import {
21
+ asyncThunkCreator,
22
+ buildCreateSlice,
23
+ getRuntimeServerContext
24
+ } from "./chunk-EYEEHCU4.js";
25
+ import {
26
+ asTrimmedString
27
+ } from "./chunk-3EUW3WEO.js";
28
+ import {
29
+ asOptionalTrimmedString
30
+ } from "./chunk-G3SUCT4W.js";
31
+ import {
32
+ __toESM
33
+ } from "./chunk-4VNS5WPM.js";
34
+
35
+ // packages/ai/chat/agentCredentialSyncClient.ts
36
+ function buildUrl(currentServer, credentialRef) {
37
+ return `${currentServer}/api/agent-credentials/${encodeURIComponent(credentialRef)}`;
38
+ }
39
+ async function fetchServerSyncedCredential(ctx, credentialRef) {
40
+ try {
41
+ const res = await fetch(buildUrl(ctx.currentServer, credentialRef), {
42
+ method: "GET",
43
+ headers: { Authorization: `Bearer ${ctx.authToken}` }
44
+ });
45
+ if (!res.ok) return null;
46
+ const data = await res.json();
47
+ return data.apiKey ?? null;
48
+ } catch {
49
+ return null;
50
+ }
51
+ }
52
+ async function deleteServerSyncedCredential(ctx, credentialRef) {
53
+ try {
54
+ const res = await fetch(buildUrl(ctx.currentServer, credentialRef), {
55
+ method: "DELETE",
56
+ headers: { Authorization: `Bearer ${ctx.authToken}` }
57
+ });
58
+ return res.ok;
59
+ } catch {
60
+ return false;
61
+ }
62
+ }
63
+ async function pushServerSyncedCredential(ctx, credentialRef, apiKey) {
64
+ try {
65
+ const res = await fetch(buildUrl(ctx.currentServer, credentialRef), {
66
+ method: "POST",
67
+ headers: {
68
+ "Content-Type": "application/json",
69
+ Authorization: `Bearer ${ctx.authToken}`
70
+ },
71
+ body: JSON.stringify({ apiKey })
72
+ });
73
+ return res.ok;
74
+ } catch {
75
+ return false;
76
+ }
77
+ }
78
+
79
+ // packages/core/sanitizeModelString.ts
80
+ var sanitizeOptionalModelString = (value) => {
81
+ const s = typeof value === "string" ? value.trim() : "";
82
+ if (!s) return "";
83
+ const lower = s.toLowerCase();
84
+ if (lower === "undefined" || lower === "null" || lower === "nan") return "";
85
+ return s;
86
+ };
87
+
88
+ // packages/ai/agent/agentSlice.ts
89
+ var import_ulid = __toESM(require_index_umd());
90
+ var createAgentCredentialBroker = createFileCredentialBroker;
91
+ function setAgentCredentialBrokerFactoryForTests(factory) {
92
+ createAgentCredentialBroker = factory ?? createFileCredentialBroker;
93
+ }
94
+ var readNonEmptyApiKey = (value) => asTrimmedString(value);
95
+ var migrateRawApiKeyForAgent = async (args) => {
96
+ const broker = createAgentCredentialBroker();
97
+ const result = await migrateAgentSecrets({
98
+ agent: {
99
+ key: args.agentKey,
100
+ apiKey: args.apiKey,
101
+ apiKeyRef: args.apiKeyRef,
102
+ credentialRef: args.credentialRef
103
+ },
104
+ broker
105
+ });
106
+ const next = applyAgentSecretMigrationUpdates(args.record, result.updates);
107
+ if (readNonEmptyApiKey(next.apiKey)) {
108
+ throw new Error(
109
+ "Failed to migrate agent API key into the local credential broker. The raw key was not stripped."
110
+ );
111
+ }
112
+ return next;
113
+ };
114
+ var createSliceWithThunks = buildCreateSlice({
115
+ creators: { asyncThunk: asyncThunkCreator }
116
+ });
117
+ var initialState = {};
118
+ var normalizeAgentReferences = (references) => {
119
+ if (!Array.isArray(references)) return [];
120
+ return references.map((ref) => ({
121
+ dbKey: ref.dbKey || "",
122
+ title: ref.title || "",
123
+ type: ref.type === "page" ? "knowledge" : ref.type || "knowledge"
124
+ }));
125
+ };
126
+ var normalizeRuntimeToolPolicy = (value) => {
127
+ const policy = normalizeAgentRuntimeToolPolicy(value);
128
+ if (!policy) return void 0;
129
+ const hasPolicyContent = Boolean(
130
+ policy.agentTools?.length || policy.runtimeTools?.length || policy.workspace || policy.shell || policy.isolation || policy.git || policy.budget || policy.audit
131
+ );
132
+ return hasPolicyContent ? policy : void 0;
133
+ };
134
+ var processAgentCreateForm = (formData, userId) => {
135
+ const isPublic = !!formData.isPublic;
136
+ const machineId = asTrimmedString(formData.machineId);
137
+ const result = {
138
+ ...formData,
139
+ // tags: "a, b" -> ["a", "b"]
140
+ tags: formData.tags ? formData.tags.split(",").map((s) => s.trim()).filter(Boolean) : [],
141
+ // 归一化 references
142
+ references: normalizeAgentReferences(formData.references || []),
143
+ // 非公开时,强制清空白名单,避免脏数据
144
+ whitelist: isPublic ? formData.whitelist || [] : [],
145
+ // allowFork 独立于公开:Space 内的私有 agent 也可被空间成员复制
146
+ allowFork: !!formData.allowFork
147
+ };
148
+ delete result.machineId;
149
+ result.runtimeToolPolicy = normalizeRuntimeToolPolicy(
150
+ formData.runtimeToolPolicy
151
+ );
152
+ if (!result.runtimeToolPolicy) {
153
+ delete result.runtimeToolPolicy;
154
+ }
155
+ if (formData.apiSource === "cli" && machineId) {
156
+ const binding = {
157
+ ...asRecordOrEmpty(result.runtimeBinding),
158
+ machineId,
159
+ ownerUserId: userId
160
+ };
161
+ result.runtimeBinding = binding;
162
+ }
163
+ if ("model" in result) {
164
+ result.model = sanitizeOptionalModelString(result.model);
165
+ }
166
+ if ("provider" in result) {
167
+ result.provider = sanitizeOptionalModelString(result.provider);
168
+ }
169
+ return result;
170
+ };
171
+ var processAgentUpdateChanges = (data, userId, previousAgent) => {
172
+ const changes = {};
173
+ if ("name" in data) {
174
+ changes.name = String(data.name ?? "").trim();
175
+ }
176
+ if ("model" in data) {
177
+ changes.model = sanitizeOptionalModelString(data.model);
178
+ }
179
+ if ("provider" in data) {
180
+ changes.provider = sanitizeOptionalModelString(data.provider);
181
+ }
182
+ if ("prompt" in data) {
183
+ changes.prompt = (data.prompt ?? "").trim();
184
+ }
185
+ if ("introduction" in data) {
186
+ changes.introduction = (data.introduction ?? "").trim();
187
+ }
188
+ if ("customProviderUrl" in data) {
189
+ changes.customProviderUrl = (data.customProviderUrl ?? "").trim();
190
+ }
191
+ if ("apiKey" in data) {
192
+ changes.apiKey = (data.apiKey ?? "").trim();
193
+ }
194
+ if ("hasVision" in data && data.hasVision !== void 0) {
195
+ changes.hasVision = !!data.hasVision;
196
+ }
197
+ if ("apiSource" in data && data.apiSource) {
198
+ changes.apiSource = data.apiSource;
199
+ }
200
+ if ("cliProvider" in data) {
201
+ changes.cliProvider = data.cliProvider || "";
202
+ }
203
+ if ("machineId" in data) {
204
+ const machineId = String(data.machineId ?? "").trim();
205
+ const effectiveApiSource = data.apiSource ?? previousAgent?.apiSource;
206
+ if (machineId) {
207
+ if (effectiveApiSource === "cli" || effectiveApiSource === void 0) {
208
+ const binding = {
209
+ ...asRecordOrEmpty(changes.runtimeBinding),
210
+ machineId,
211
+ ownerUserId: userId
212
+ };
213
+ changes.runtimeBinding = binding;
214
+ }
215
+ } else {
216
+ if (effectiveApiSource === "cli" || effectiveApiSource === void 0) {
217
+ changes.runtimeBinding = null;
218
+ }
219
+ }
220
+ }
221
+ if ("useServerProxy" in data && data.useServerProxy !== void 0) {
222
+ changes.useServerProxy = !!data.useServerProxy;
223
+ }
224
+ if ("sharingLevel" in data) {
225
+ const sharingLevel = data.sharingLevel;
226
+ if (sharingLevel === "default" || sharingLevel === "split" || sharingLevel === "full") {
227
+ changes.sharingLevel = sharingLevel;
228
+ }
229
+ }
230
+ if ("greeting" in data) {
231
+ changes.greeting = data.greeting;
232
+ }
233
+ if ("tools" in data) {
234
+ changes.tools = Array.isArray(data.tools) ? data.tools.slice() : [];
235
+ }
236
+ if ("runtimeToolPolicy" in data) {
237
+ const rawRuntimeToolPolicy = data.runtimeToolPolicy;
238
+ changes.runtimeToolPolicy = rawRuntimeToolPolicy === null ? null : normalizeRuntimeToolPolicy(rawRuntimeToolPolicy) ?? null;
239
+ }
240
+ const numericKeys = [
241
+ "inputPrice",
242
+ "outputPrice",
243
+ "temperature",
244
+ "top_p",
245
+ "frequency_penalty",
246
+ "presence_penalty",
247
+ "max_tokens"
248
+ ];
249
+ numericKeys.forEach((key) => {
250
+ if (key in data) {
251
+ const raw = data[key];
252
+ if (raw === void 0 || raw === null) {
253
+ changes[key] = raw;
254
+ } else {
255
+ const num = Number(raw);
256
+ changes[key] = Number.isNaN(num) ? raw : num;
257
+ }
258
+ }
259
+ });
260
+ if ("reasoning_effort" in data) {
261
+ changes.reasoning_effort = data.reasoning_effort;
262
+ }
263
+ if ("tags" in data) {
264
+ const raw = data.tags;
265
+ let arr = [];
266
+ if (Array.isArray(raw)) {
267
+ arr = raw.map((s) => toTrimmedString(s)).filter(Boolean);
268
+ } else if (typeof raw === "string") {
269
+ arr = raw.split(",").map((s) => s.trim()).filter(Boolean);
270
+ }
271
+ changes.tags = arr;
272
+ }
273
+ if ("references" in data) {
274
+ changes.references = normalizeAgentReferences(
275
+ data.references || []
276
+ );
277
+ }
278
+ if ("whitelist" in data) {
279
+ changes.whitelist = data.whitelist || [];
280
+ }
281
+ if ("allowFork" in data) {
282
+ changes.allowFork = !!data.allowFork;
283
+ }
284
+ if ("avatarFileId" in data) {
285
+ const raw = data.avatarFileId;
286
+ changes.avatarFileId = raw ? String(raw).trim() : null;
287
+ }
288
+ if ("isPublic" in data) {
289
+ changes.isPublic = !!data.isPublic;
290
+ if (!changes.isPublic) {
291
+ changes.whitelist = [];
292
+ }
293
+ }
294
+ return changes;
295
+ };
296
+ var slice = createSliceWithThunks({
297
+ name: "agent",
298
+ initialState,
299
+ reducers: (create) => ({
300
+ /**
301
+ * 通用 LLM 调用(不带 Agent 上下文 / 历史)
302
+ */
303
+ runLlm: create.asyncThunk(async (args, thunkApi) => {
304
+ const overrides = {};
305
+ if (args.systemPromptOverride !== void 0) overrides.prompt = args.systemPromptOverride;
306
+ if (args.toolsOverride !== void 0) overrides.tools = args.toolsOverride;
307
+ const { _executeModel } = await import("./_executeModel-UD44KGZ4.js");
308
+ return _executeModel(
309
+ {
310
+ isStreaming: args.isStreaming ?? false,
311
+ withAgentContext: false,
312
+ withChatHistory: false,
313
+ agentConfigOverrides: Object.keys(overrides).length ? overrides : void 0
314
+ },
315
+ args,
316
+ thunkApi
317
+ );
318
+ }),
319
+ /**
320
+ * 通用 Agent 调用(带 Agent 上下文,多轮工具循环)
321
+ *
322
+ * 使用客户端 runAgentClientLoop:
323
+ * - 每轮调用 LLM(非流式)
324
+ * - 遇到 tool_calls 时通过 findToolExecutor 本地执行工具
325
+ * - 循环直到无工具调用或触发其他运行时停止条件
326
+ */
327
+ runAgent: create.asyncThunk(async (args, thunkApi) => {
328
+ const { runAgentClientLoop } = await import("./runAgentClientLoop-U5Q6NDTJ.js");
329
+ const { content: loopContent, toolCallCount } = await runAgentClientLoop(
330
+ {
331
+ agentKey: args.agentKey,
332
+ content: args.content,
333
+ parentMessageId: args.parentMessageId,
334
+ billingDialogKey: args.billingDialogKey
335
+ },
336
+ thunkApi
337
+ );
338
+ return loopContent;
339
+ }),
340
+ /**
341
+ * 聊天轮次流式 Agent 调用
342
+ */
343
+ streamAgentChatTurn: create.asyncThunk(async (args, thunkApi) => {
344
+ const { streamAgentChatTurnHandler } = await import("./streamAgentChatTurn-UBDAOQWE.js");
345
+ return streamAgentChatTurnHandler(args, thunkApi);
346
+ }),
347
+ /**
348
+ * 创建 Agent:
349
+ * - 写入用户私有路径
350
+ * - 如 isPublic=true,则同时写入公共路径
351
+ * - 返回完整 Agent 对象(包含 id / meta 字段)
352
+ */
353
+ createAgent: create.asyncThunk(
354
+ async ({ userId, formData, spaceId }, thunkApi) => {
355
+ const effectiveUserId = asOptionalTrimmedString(userId) ?? "local";
356
+ const processed = processAgentCreateForm(formData, effectiveUserId);
357
+ const now = Date.now();
358
+ const id = (0, import_ulid.ulid)();
359
+ const privateKey = createAgentKey.private(effectiveUserId, id);
360
+ const publicKey = createAgentKey.public(id);
361
+ let agent = {
362
+ ...processed,
363
+ id,
364
+ type: "agent" /* AGENT */,
365
+ userId: effectiveUserId,
366
+ createdAt: now,
367
+ updatedAt: now,
368
+ dialogCount: 0,
369
+ messageCount: 0,
370
+ tokenCount: 0,
371
+ spaceId
372
+ // 记录 spaceId
373
+ };
374
+ if (effectiveUserId === "local") {
375
+ agent.isPublic = false;
376
+ }
377
+ try {
378
+ const { localFirstLog } = await import("./localFirstLog-DHNOY2NA.js");
379
+ localFirstLog("agent.create.start", {
380
+ owner: effectiveUserId,
381
+ hasRawApiKey: Boolean(readNonEmptyApiKey(agent.apiKey)),
382
+ hasSpace: Boolean(spaceId)
383
+ });
384
+ } catch {
385
+ }
386
+ const createRawApiKey = readNonEmptyApiKey(agent.apiKey);
387
+ if (createRawApiKey) {
388
+ agent = await migrateRawApiKeyForAgent({
389
+ record: agent,
390
+ agentKey: privateKey,
391
+ apiKey: createRawApiKey,
392
+ apiKeyRef: agent.apiKeyRef,
393
+ credentialRef: agent.credentialRef
394
+ });
395
+ }
396
+ await thunkApi.dispatch(
397
+ write({
398
+ data: agent,
399
+ customKey: privateKey,
400
+ userId: effectiveUserId
401
+ })
402
+ ).unwrap();
403
+ if (agent.isPublic) {
404
+ await thunkApi.dispatch(
405
+ write({
406
+ data: agent,
407
+ customKey: publicKey,
408
+ userId: effectiveUserId
409
+ })
410
+ ).unwrap();
411
+ }
412
+ if (agent.credentialSynced && createRawApiKey) {
413
+ const ctx = getRuntimeServerContext(thunkApi.getState());
414
+ const credentialRef = agent.credentialRef;
415
+ if (ctx.currentToken && credentialRef) {
416
+ try {
417
+ await pushServerSyncedCredential(
418
+ { currentServer: ctx.currentServer ?? "", authToken: ctx.currentToken },
419
+ credentialRef,
420
+ createRawApiKey
421
+ );
422
+ } catch {
423
+ }
424
+ }
425
+ }
426
+ try {
427
+ const { localFirstLog } = await import("./localFirstLog-DHNOY2NA.js");
428
+ localFirstLog("agent.create.done", {
429
+ owner: effectiveUserId,
430
+ key: privateKey,
431
+ hasCredentialRef: Boolean(
432
+ typeof agent.credentialRef === "string" && agent.credentialRef.trim()
433
+ ),
434
+ hasRawApiKey: Boolean(readNonEmptyApiKey(agent.apiKey)),
435
+ isPublic: Boolean(agent.isPublic)
436
+ });
437
+ } catch {
438
+ }
439
+ return agent;
440
+ }
441
+ ),
442
+ /**
443
+ * 更新 Agent(支持局部字段 patch):
444
+ * - patch 私有副本
445
+ * - 如提供 previousAgent,则同步更新 / 删除公共副本
446
+ *
447
+ * 注意:
448
+ * - Tool 场景下一般不提供 previousAgent,此时只保证私有副本被更新;
449
+ * 公共副本(应用市场)不做强一致保证。
450
+ */
451
+ updateAgent: create.asyncThunk(
452
+ async ({ userId, agentId, formData, previousAgent }, thunkApi) => {
453
+ const effectiveUserId = asOptionalTrimmedString(userId) ?? "local";
454
+ const normalizedAgentId = (() => {
455
+ const raw = agentId.trim();
456
+ if (raw.startsWith("agent-")) {
457
+ const parts = raw.split("-");
458
+ if (parts.length >= 3) return parts.slice(2).join("-");
459
+ }
460
+ return raw;
461
+ })();
462
+ const privateKey = createAgentKey.private(effectiveUserId, normalizedAgentId);
463
+ const publicKey = createAgentKey.public(normalizedAgentId);
464
+ let changes = processAgentUpdateChanges(formData || {}, effectiveUserId, previousAgent);
465
+ const updateRawApiKey = readNonEmptyApiKey(changes.apiKey);
466
+ if (updateRawApiKey) {
467
+ const formAny = formData || {};
468
+ const migrated = await migrateRawApiKeyForAgent({
469
+ record: { ...changes },
470
+ agentKey: privateKey,
471
+ apiKey: updateRawApiKey,
472
+ apiKeyRef: formAny.apiKeyRef ?? previousAgent?.apiKeyRef ?? changes.apiKeyRef,
473
+ credentialRef: formAny.credentialRef ?? previousAgent?.credentialRef ?? changes.credentialRef
474
+ });
475
+ changes = migrated;
476
+ if (!readNonEmptyApiKey(changes.apiKey)) {
477
+ changes.apiKey = null;
478
+ }
479
+ }
480
+ let localExists = false;
481
+ try {
482
+ const { db } = thunkApi.extra;
483
+ const localData = await db.get(privateKey);
484
+ localExists = !!localData;
485
+ } catch (e) {
486
+ }
487
+ if (localExists) {
488
+ await thunkApi.dispatch(
489
+ patch({
490
+ dbKey: privateKey,
491
+ changes
492
+ })
493
+ ).unwrap();
494
+ } else if (previousAgent) {
495
+ const merged = {
496
+ ...previousAgent,
497
+ ...changes,
498
+ id: normalizedAgentId,
499
+ type: previousAgent.type || "agent" /* AGENT */,
500
+ userId: effectiveUserId
501
+ };
502
+ await thunkApi.dispatch(
503
+ write({
504
+ data: merged,
505
+ customKey: privateKey,
506
+ userId: effectiveUserId
507
+ })
508
+ ).unwrap();
509
+ } else {
510
+ await thunkApi.dispatch(
511
+ patch({
512
+ dbKey: privateKey,
513
+ changes
514
+ })
515
+ ).unwrap();
516
+ }
517
+ if (previousAgent && effectiveUserId !== "local") {
518
+ const wasPublic = !!previousAgent.isPublic;
519
+ const hasIsPublicChange = Object.prototype.hasOwnProperty.call(
520
+ changes,
521
+ "isPublic"
522
+ );
523
+ const nowPublic = hasIsPublicChange ? !!changes.isPublic : wasPublic;
524
+ if (nowPublic) {
525
+ const mergedPublic = {
526
+ ...previousAgent,
527
+ ...changes,
528
+ id: normalizedAgentId,
529
+ type: previousAgent.type || "agent" /* AGENT */,
530
+ userId: effectiveUserId
531
+ };
532
+ await thunkApi.dispatch(
533
+ write({
534
+ data: mergedPublic,
535
+ customKey: publicKey,
536
+ userId: effectiveUserId
537
+ })
538
+ ).unwrap();
539
+ } else if (wasPublic && !nowPublic) {
540
+ await thunkApi.dispatch(remove(publicKey)).unwrap();
541
+ }
542
+ }
543
+ const base = previousAgent ?? {};
544
+ const mergedPrivate = {
545
+ ...base,
546
+ ...changes,
547
+ id: normalizedAgentId,
548
+ type: base.type || "agent" /* AGENT */,
549
+ userId: effectiveUserId
550
+ };
551
+ return mergedPrivate;
552
+ }
553
+ )
554
+ })
555
+ });
556
+ var {
557
+ runLlm,
558
+ runAgent,
559
+ streamAgentChatTurn,
560
+ createAgent,
561
+ updateAgent
562
+ } = slice.actions;
563
+ var agentReducer = slice.reducer;
564
+ var agentSlice_default = agentReducer;
565
+
566
+ export {
567
+ fetchServerSyncedCredential,
568
+ deleteServerSyncedCredential,
569
+ setAgentCredentialBrokerFactoryForTests,
570
+ slice,
571
+ runLlm,
572
+ runAgent,
573
+ streamAgentChatTurn,
574
+ createAgent,
575
+ updateAgent,
576
+ agentSlice_default
577
+ };
@@ -0,0 +1,38 @@
1
+ // packages/core/localOrigins.ts
2
+ var DEFAULT_LOCAL_HOST = "127.0.0.1";
3
+ var DEFAULT_LOCAL_API_PORT = "38123";
4
+ var DEFAULT_LOCAL_API_ORIGIN = `http://${DEFAULT_LOCAL_HOST}:${DEFAULT_LOCAL_API_PORT}`;
5
+ var LOOPBACK_HOSTNAMES = /* @__PURE__ */ new Set([
6
+ "127.0.0.1",
7
+ "localhost",
8
+ "::1"
9
+ ]);
10
+ function isLoopbackHostname(hostname) {
11
+ if (typeof hostname !== "string") return false;
12
+ let normalized = hostname.trim().toLowerCase();
13
+ if (!normalized) return false;
14
+ if (normalized.startsWith("[") && normalized.endsWith("]")) {
15
+ normalized = normalized.slice(1, -1);
16
+ }
17
+ return LOOPBACK_HOSTNAMES.has(normalized);
18
+ }
19
+ function isLoopbackUrl(value) {
20
+ if (typeof value !== "string" || !value.trim()) return false;
21
+ try {
22
+ return isLoopbackHostname(new URL(value).hostname);
23
+ } catch {
24
+ return false;
25
+ }
26
+ }
27
+ var LOCAL_SERVER_URL_PATTERN = /^https?:\/\/(?:(?:\d{1,3}\.){3}\d{1,3}|localhost|nolotus\.local)(?::\d+)?$/i;
28
+ function isLocalServerUrl(value) {
29
+ if (typeof value !== "string") return false;
30
+ return LOCAL_SERVER_URL_PATTERN.test(value.trim());
31
+ }
32
+
33
+ export {
34
+ DEFAULT_LOCAL_API_ORIGIN,
35
+ isLoopbackHostname,
36
+ isLoopbackUrl,
37
+ isLocalServerUrl
38
+ };
@@ -0,0 +1,42 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
+ }) : x)(function(x) {
10
+ if (typeof require !== "undefined") return require.apply(this, arguments);
11
+ throw Error('Dynamic require of "' + x + '" is not supported');
12
+ });
13
+ var __commonJS = (cb, mod) => function __require2() {
14
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
15
+ };
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+
37
+ export {
38
+ __require,
39
+ __commonJS,
40
+ __export,
41
+ __toESM
42
+ };
@@ -0,0 +1,34 @@
1
+ // packages/chat/dialog/actions/builtinDialogLlm.ts
2
+ var BASE_BUILTIN_DIALOG_LLM_CONFIG = {
3
+ apiSource: "platform",
4
+ useServerProxy: true
5
+ };
6
+ var BUILTIN_TITLE_LLM_CONFIG = {
7
+ ...BASE_BUILTIN_DIALOG_LLM_CONFIG,
8
+ provider: "deepseek",
9
+ id: "builtin-dialog-title-llm",
10
+ name: "Builtin Dialog Title LLM",
11
+ model: "deepseek-v4-flash",
12
+ prompt: "You are a title generator for chat history. \u4F60\u53EA\u505A\u4E00\u4EF6\u4E8B\uFF1A\u6839\u636E\u5BF9\u8BDD\u5185\u5BB9\u8F93\u51FA\u6700\u7EC8\u6807\u9898\u3002\u786C\u6027\u89C4\u5219\uFF1A1) \u53EA\u8F93\u51FA\u6807\u9898\u8FD9\u4E00\u884C\uFF1B\u4E25\u7981\u8F93\u51FA\u63A8\u7406\u3001\u5206\u6790\u3001\u6B65\u9AA4\u3001\u89E3\u91CA\u3001\u524D\u8A00\u3001\u540E\u8BB0\u3001\u7FFB\u8BD1\u3001\u81F4\u6B49\u6216\u4EFB\u4F55\u989D\u5916\u8BF4\u660E\u30022) \u4E0D\u8981\u56DE\u7B54\u7528\u6237\u8BF7\u6C42\uFF0C\u4E0D\u8981\u5199\u6458\u8981\uFF0C\u53EA\u7ED9\u6807\u9898\u7ED3\u679C\u30023) \u6807\u9898\u5C3D\u91CF\u77ED\uFF1A\u901A\u5E38 2-5 \u4E2A\u8BCD\uFF0C\u82F1\u6587\u4E0D\u8D85\u8FC7 6 \u4E2A\u8BCD\u30024) \u4F7F\u7528\u5BF9\u8BDD\u4E3B\u8BED\u8A00\uFF1B\u6DF7\u5408\u8BED\u8A00\u65F6\u4F18\u5148\u7528\u6237\u4E3B\u8981\u8BED\u8A00\u30025) \u4F18\u5148\u590D\u7528\u5BF9\u8BDD\u4E2D\u7684\u5177\u4F53\u4E3B\u9898\u8BCD\uFF0C\u907F\u514D issue\u3001help\u3001discussion\u3001analysis\u3001update \u8FD9\u7C7B\u7A7A\u6CDB\u8BCD\u30026) \u5FFD\u7565 tool JSON\u3001\u51FD\u6570\u540D\u3001branch label\u3001agent \u540D\u3001\u7CFB\u7EDF\u6307\u4EE4\u548C\u7F16\u6392\u75D5\u8FF9\uFF08\u5982 GPT\u3001Claude\u3001Gemini\uFF09\uFF1B\u6807\u9898\u8981\u843D\u5728\u7528\u6237\u771F\u6B63\u8BA8\u8BBA\u7684\u5BF9\u8C61\u6216\u51B3\u7B56\u4E0A\u30027) \u66F4\u504F\u597D\u201C\u5BF9\u8C61 + \u52A8\u4F5C/\u5224\u65AD\u201D\u7684\u77ED\u6807\u9898\uFF0C\u4F8B\u5982\u201CAI \u90AE\u4EF6\u52A9\u624B\u53D6\u820D\u201D\u201C\u4E1C\u4EAC\u56DB\u65E5\u6162\u65C5\u884C\u201D\u201C\u91CD\u590D\u6263\u8D39\u9000\u6B3E\u201D\u30028) \u7EAF\u6587\u672C\uFF0C\u4E0D\u8981\u9879\u76EE\u7B26\u53F7\u3001\u7F16\u53F7\u3001markdown\u3001emoji\u3002\u6700\u7EC8\u53EA\u8FD4\u56DE\u6807\u9898\u6587\u672C\u3002 Output only the title text."
13
+ };
14
+ var BUILTIN_SUMMARY_LLM_CONFIG = {
15
+ ...BASE_BUILTIN_DIALOG_LLM_CONFIG,
16
+ provider: "deepseek",
17
+ id: "builtin-dialog-summary-llm",
18
+ name: "Builtin Dialog Summary LLM",
19
+ model: "deepseek-v4-pro",
20
+ prompt: "\u4F60\u662F\u4E00\u4E2A\u4E13\u4E1A\u7684\u5BF9\u8BDD\u8BB0\u5FC6\u52A9\u7406\u3002\u8BF7\u57FA\u4E8E\u3010\u73B0\u6709\u8BB0\u5FC6\u3011\u548C\u3010\u65B0\u589E\u5BF9\u8BDD\u3011\uFF0C\u8F93\u51FA\u4E00\u4EFD\u66F4\u65B0\u540E\u7684\u5BF9\u8BDD\u8BB0\u5FC6\u6863\u6848\u3002\u4E25\u683C\u53EA\u8F93\u51FA\u4E0B\u9762\u4E24\u90E8\u5206\uFF0C\u6807\u9898\u5FC5\u987B\u5B8C\u5168\u4E00\u81F4\uFF1A\n\u5173\u952E\u4E8B\u5B9E\u6863\u6848\n- ...\n\u5BF9\u8BDD\u5267\u60C5\u6458\u8981\n- ...\n\u8981\u6C42\uFF1A1) \u4F7F\u7528\u5BF9\u8BDD\u4E3B\u8BED\u8A00\uFF1B\u6DF7\u5408\u8BED\u8A00\u65F6\u4F18\u5148\u8DDF\u968F\u7528\u6237\u4E3B\u8981\u8BED\u8A00\uFF0C\u4E13\u6709\u540D\u8BCD\u4FDD\u7559\u539F\u6587\u30022) \u5173\u952E\u4E8B\u5B9E\u6863\u6848\u53EA\u4FDD\u7559\u4E4B\u540E\u7EE7\u7EED\u5BF9\u8BDD\u4ECD\u6709\u4EF7\u503C\u7684\u4FE1\u606F\uFF0C\u4F8B\u5982\u7528\u6237\u504F\u597D\u3001\u76EE\u6807\u3001\u7EA6\u675F\u3001\u6280\u672F\u6808\u3001\u786E\u5B9A\u7684\u6587\u4EF6\u540D/\u53D8\u91CF\u540D\u3001\u6838\u5FC3\u51B3\u7B56\u3001\u5F85\u529E\u4E8B\u9879\u30023) \u5BF9\u8BDD\u5267\u60C5\u6458\u8981\u5148\u6781\u7B80\u6982\u62EC\u65E7\u4E0A\u4E0B\u6587\uFF0C\u518D\u66F4\u8BE6\u7EC6\u8BB0\u5F55\u6700\u8FD1\u65B0\u589E\u7684\u8FDB\u5C55\u3001\u5206\u6B67\u3001\u7ED3\u8BBA\u548C\u4E0B\u4E00\u6B65\u30024) \u5FFD\u7565\u5BD2\u6684\u3001\u91CD\u590D\u5C1D\u8BD5\u3001\u5DF2\u653E\u5F03\u65B9\u6848\u548C\u65E0\u4EF7\u503C\u5E9F\u8BDD\u30025) \u4E0D\u8981\u7F16\u9020\u672A\u51FA\u73B0\u7684\u4FE1\u606F\uFF0C\u4E0D\u8981\u8F93\u51FA\u5F00\u573A\u767D\u3001\u7ED3\u675F\u8BED\u3001markdown \u4EE3\u7801\u5757\u6216\u989D\u5916\u7AE0\u8282\u3002"
21
+ };
22
+ var buildBuiltinSummaryContent = (previousSummary, messagesText) => `
23
+ \u3010\u73B0\u6709\u8BB0\u5FC6\u3011\uFF1A
24
+ ${previousSummary || "(\u65E0)"}
25
+
26
+ \u3010\u65B0\u589E\u5BF9\u8BDD\u3011\uFF1A
27
+ ${messagesText}
28
+ `.trim();
29
+
30
+ export {
31
+ BUILTIN_TITLE_LLM_CONFIG,
32
+ BUILTIN_SUMMARY_LLM_CONFIG,
33
+ buildBuiltinSummaryContent
34
+ };