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,573 @@
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-URUUZLPA.js";
12
+ import {
13
+ asRecordOrEmpty
14
+ } from "./chunk-KX6YBIHG.js";
15
+ import {
16
+ createAgentKey,
17
+ toTrimmedString
18
+ } from "./chunk-O4BU24WZ.js";
19
+ import {
20
+ asyncThunkCreator,
21
+ buildCreateSlice,
22
+ getRuntimeServerContext
23
+ } from "./chunk-UTLZINAP.js";
24
+ import {
25
+ asTrimmedString
26
+ } from "./chunk-3EUW3WEO.js";
27
+ import {
28
+ asOptionalTrimmedString
29
+ } from "./chunk-G3SUCT4W.js";
30
+
31
+ // packages/ai/chat/agentCredentialSyncClient.ts
32
+ function buildUrl(currentServer, credentialRef) {
33
+ return `${currentServer}/api/agent-credentials/${encodeURIComponent(credentialRef)}`;
34
+ }
35
+ async function fetchServerSyncedCredential(ctx, credentialRef) {
36
+ try {
37
+ const res = await fetch(buildUrl(ctx.currentServer, credentialRef), {
38
+ method: "GET",
39
+ headers: { Authorization: `Bearer ${ctx.authToken}` }
40
+ });
41
+ if (!res.ok) return null;
42
+ const data = await res.json();
43
+ return data.apiKey ?? null;
44
+ } catch {
45
+ return null;
46
+ }
47
+ }
48
+ async function deleteServerSyncedCredential(ctx, credentialRef) {
49
+ try {
50
+ const res = await fetch(buildUrl(ctx.currentServer, credentialRef), {
51
+ method: "DELETE",
52
+ headers: { Authorization: `Bearer ${ctx.authToken}` }
53
+ });
54
+ return res.ok;
55
+ } catch {
56
+ return false;
57
+ }
58
+ }
59
+ async function pushServerSyncedCredential(ctx, credentialRef, apiKey) {
60
+ try {
61
+ const res = await fetch(buildUrl(ctx.currentServer, credentialRef), {
62
+ method: "POST",
63
+ headers: {
64
+ "Content-Type": "application/json",
65
+ Authorization: `Bearer ${ctx.authToken}`
66
+ },
67
+ body: JSON.stringify({ apiKey })
68
+ });
69
+ return res.ok;
70
+ } catch {
71
+ return false;
72
+ }
73
+ }
74
+
75
+ // packages/core/sanitizeModelString.ts
76
+ var sanitizeOptionalModelString = (value) => {
77
+ const s = typeof value === "string" ? value.trim() : "";
78
+ if (!s) return "";
79
+ const lower = s.toLowerCase();
80
+ if (lower === "undefined" || lower === "null" || lower === "nan") return "";
81
+ return s;
82
+ };
83
+
84
+ // packages/ai/agent/agentSlice.ts
85
+ import { ulid } from "ulid";
86
+ var createAgentCredentialBroker = createFileCredentialBroker;
87
+ function setAgentCredentialBrokerFactoryForTests(factory) {
88
+ createAgentCredentialBroker = factory ?? createFileCredentialBroker;
89
+ }
90
+ var readNonEmptyApiKey = (value) => asTrimmedString(value);
91
+ var migrateRawApiKeyForAgent = async (args) => {
92
+ const broker = createAgentCredentialBroker();
93
+ const result = await migrateAgentSecrets({
94
+ agent: {
95
+ key: args.agentKey,
96
+ apiKey: args.apiKey,
97
+ apiKeyRef: args.apiKeyRef,
98
+ credentialRef: args.credentialRef
99
+ },
100
+ broker
101
+ });
102
+ const next = applyAgentSecretMigrationUpdates(args.record, result.updates);
103
+ if (readNonEmptyApiKey(next.apiKey)) {
104
+ throw new Error(
105
+ "Failed to migrate agent API key into the local credential broker. The raw key was not stripped."
106
+ );
107
+ }
108
+ return next;
109
+ };
110
+ var createSliceWithThunks = buildCreateSlice({
111
+ creators: { asyncThunk: asyncThunkCreator }
112
+ });
113
+ var initialState = {};
114
+ var normalizeAgentReferences = (references) => {
115
+ if (!Array.isArray(references)) return [];
116
+ return references.map((ref) => ({
117
+ dbKey: ref.dbKey || "",
118
+ title: ref.title || "",
119
+ type: ref.type === "page" ? "knowledge" : ref.type || "knowledge"
120
+ }));
121
+ };
122
+ var normalizeRuntimeToolPolicy = (value) => {
123
+ const policy = normalizeAgentRuntimeToolPolicy(value);
124
+ if (!policy) return void 0;
125
+ const hasPolicyContent = Boolean(
126
+ policy.agentTools?.length || policy.runtimeTools?.length || policy.workspace || policy.shell || policy.isolation || policy.git || policy.budget || policy.audit
127
+ );
128
+ return hasPolicyContent ? policy : void 0;
129
+ };
130
+ var processAgentCreateForm = (formData, userId) => {
131
+ const isPublic = !!formData.isPublic;
132
+ const machineId = asTrimmedString(formData.machineId);
133
+ const result = {
134
+ ...formData,
135
+ // tags: "a, b" -> ["a", "b"]
136
+ tags: formData.tags ? formData.tags.split(",").map((s) => s.trim()).filter(Boolean) : [],
137
+ // 归一化 references
138
+ references: normalizeAgentReferences(formData.references || []),
139
+ // 非公开时,强制清空白名单,避免脏数据
140
+ whitelist: isPublic ? formData.whitelist || [] : [],
141
+ // allowFork 独立于公开:Space 内的私有 agent 也可被空间成员复制
142
+ allowFork: !!formData.allowFork
143
+ };
144
+ delete result.machineId;
145
+ result.runtimeToolPolicy = normalizeRuntimeToolPolicy(
146
+ formData.runtimeToolPolicy
147
+ );
148
+ if (!result.runtimeToolPolicy) {
149
+ delete result.runtimeToolPolicy;
150
+ }
151
+ if (formData.apiSource === "cli" && machineId) {
152
+ const binding = {
153
+ ...asRecordOrEmpty(result.runtimeBinding),
154
+ machineId,
155
+ ownerUserId: userId
156
+ };
157
+ result.runtimeBinding = binding;
158
+ }
159
+ if ("model" in result) {
160
+ result.model = sanitizeOptionalModelString(result.model);
161
+ }
162
+ if ("provider" in result) {
163
+ result.provider = sanitizeOptionalModelString(result.provider);
164
+ }
165
+ return result;
166
+ };
167
+ var processAgentUpdateChanges = (data, userId, previousAgent) => {
168
+ const changes = {};
169
+ if ("name" in data) {
170
+ changes.name = String(data.name ?? "").trim();
171
+ }
172
+ if ("model" in data) {
173
+ changes.model = sanitizeOptionalModelString(data.model);
174
+ }
175
+ if ("provider" in data) {
176
+ changes.provider = sanitizeOptionalModelString(data.provider);
177
+ }
178
+ if ("prompt" in data) {
179
+ changes.prompt = (data.prompt ?? "").trim();
180
+ }
181
+ if ("introduction" in data) {
182
+ changes.introduction = (data.introduction ?? "").trim();
183
+ }
184
+ if ("customProviderUrl" in data) {
185
+ changes.customProviderUrl = (data.customProviderUrl ?? "").trim();
186
+ }
187
+ if ("apiKey" in data) {
188
+ changes.apiKey = (data.apiKey ?? "").trim();
189
+ }
190
+ if ("hasVision" in data && data.hasVision !== void 0) {
191
+ changes.hasVision = !!data.hasVision;
192
+ }
193
+ if ("apiSource" in data && data.apiSource) {
194
+ changes.apiSource = data.apiSource;
195
+ }
196
+ if ("cliProvider" in data) {
197
+ changes.cliProvider = data.cliProvider || "";
198
+ }
199
+ if ("machineId" in data) {
200
+ const machineId = String(data.machineId ?? "").trim();
201
+ const effectiveApiSource = data.apiSource ?? previousAgent?.apiSource;
202
+ if (machineId) {
203
+ if (effectiveApiSource === "cli" || effectiveApiSource === void 0) {
204
+ const binding = {
205
+ ...asRecordOrEmpty(changes.runtimeBinding),
206
+ machineId,
207
+ ownerUserId: userId
208
+ };
209
+ changes.runtimeBinding = binding;
210
+ }
211
+ } else {
212
+ if (effectiveApiSource === "cli" || effectiveApiSource === void 0) {
213
+ changes.runtimeBinding = null;
214
+ }
215
+ }
216
+ }
217
+ if ("useServerProxy" in data && data.useServerProxy !== void 0) {
218
+ changes.useServerProxy = !!data.useServerProxy;
219
+ }
220
+ if ("sharingLevel" in data) {
221
+ const sharingLevel = data.sharingLevel;
222
+ if (sharingLevel === "default" || sharingLevel === "split" || sharingLevel === "full") {
223
+ changes.sharingLevel = sharingLevel;
224
+ }
225
+ }
226
+ if ("greeting" in data) {
227
+ changes.greeting = data.greeting;
228
+ }
229
+ if ("tools" in data) {
230
+ changes.tools = Array.isArray(data.tools) ? data.tools.slice() : [];
231
+ }
232
+ if ("runtimeToolPolicy" in data) {
233
+ const rawRuntimeToolPolicy = data.runtimeToolPolicy;
234
+ changes.runtimeToolPolicy = rawRuntimeToolPolicy === null ? null : normalizeRuntimeToolPolicy(rawRuntimeToolPolicy) ?? null;
235
+ }
236
+ const numericKeys = [
237
+ "inputPrice",
238
+ "outputPrice",
239
+ "temperature",
240
+ "top_p",
241
+ "frequency_penalty",
242
+ "presence_penalty",
243
+ "max_tokens"
244
+ ];
245
+ numericKeys.forEach((key) => {
246
+ if (key in data) {
247
+ const raw = data[key];
248
+ if (raw === void 0 || raw === null) {
249
+ changes[key] = raw;
250
+ } else {
251
+ const num = Number(raw);
252
+ changes[key] = Number.isNaN(num) ? raw : num;
253
+ }
254
+ }
255
+ });
256
+ if ("reasoning_effort" in data) {
257
+ changes.reasoning_effort = data.reasoning_effort;
258
+ }
259
+ if ("tags" in data) {
260
+ const raw = data.tags;
261
+ let arr = [];
262
+ if (Array.isArray(raw)) {
263
+ arr = raw.map((s) => toTrimmedString(s)).filter(Boolean);
264
+ } else if (typeof raw === "string") {
265
+ arr = raw.split(",").map((s) => s.trim()).filter(Boolean);
266
+ }
267
+ changes.tags = arr;
268
+ }
269
+ if ("references" in data) {
270
+ changes.references = normalizeAgentReferences(
271
+ data.references || []
272
+ );
273
+ }
274
+ if ("whitelist" in data) {
275
+ changes.whitelist = data.whitelist || [];
276
+ }
277
+ if ("allowFork" in data) {
278
+ changes.allowFork = !!data.allowFork;
279
+ }
280
+ if ("avatarFileId" in data) {
281
+ const raw = data.avatarFileId;
282
+ changes.avatarFileId = raw ? String(raw).trim() : null;
283
+ }
284
+ if ("isPublic" in data) {
285
+ changes.isPublic = !!data.isPublic;
286
+ if (!changes.isPublic) {
287
+ changes.whitelist = [];
288
+ }
289
+ }
290
+ return changes;
291
+ };
292
+ var slice = createSliceWithThunks({
293
+ name: "agent",
294
+ initialState,
295
+ reducers: (create) => ({
296
+ /**
297
+ * 通用 LLM 调用(不带 Agent 上下文 / 历史)
298
+ */
299
+ runLlm: create.asyncThunk(async (args, thunkApi) => {
300
+ const overrides = {};
301
+ if (args.systemPromptOverride !== void 0) overrides.prompt = args.systemPromptOverride;
302
+ if (args.toolsOverride !== void 0) overrides.tools = args.toolsOverride;
303
+ const { _executeModel } = await import("./_executeModel-42U3VOVZ.js");
304
+ return _executeModel(
305
+ {
306
+ isStreaming: args.isStreaming ?? false,
307
+ withAgentContext: false,
308
+ withChatHistory: false,
309
+ agentConfigOverrides: Object.keys(overrides).length ? overrides : void 0
310
+ },
311
+ args,
312
+ thunkApi
313
+ );
314
+ }),
315
+ /**
316
+ * 通用 Agent 调用(带 Agent 上下文,多轮工具循环)
317
+ *
318
+ * 使用客户端 runAgentClientLoop:
319
+ * - 每轮调用 LLM(非流式)
320
+ * - 遇到 tool_calls 时通过 findToolExecutor 本地执行工具
321
+ * - 循环直到无工具调用或触发其他运行时停止条件
322
+ */
323
+ runAgent: create.asyncThunk(async (args, thunkApi) => {
324
+ const { runAgentClientLoop } = await import("./runAgentClientLoop-HZFAPJHS.js");
325
+ const { content: loopContent, toolCallCount } = await runAgentClientLoop(
326
+ {
327
+ agentKey: args.agentKey,
328
+ content: args.content,
329
+ parentMessageId: args.parentMessageId,
330
+ billingDialogKey: args.billingDialogKey
331
+ },
332
+ thunkApi
333
+ );
334
+ return loopContent;
335
+ }),
336
+ /**
337
+ * 聊天轮次流式 Agent 调用
338
+ */
339
+ streamAgentChatTurn: create.asyncThunk(async (args, thunkApi) => {
340
+ const { streamAgentChatTurnHandler } = await import("./streamAgentChatTurn-3C5RQZJF.js");
341
+ return streamAgentChatTurnHandler(args, thunkApi);
342
+ }),
343
+ /**
344
+ * 创建 Agent:
345
+ * - 写入用户私有路径
346
+ * - 如 isPublic=true,则同时写入公共路径
347
+ * - 返回完整 Agent 对象(包含 id / meta 字段)
348
+ */
349
+ createAgent: create.asyncThunk(
350
+ async ({ userId, formData, spaceId }, thunkApi) => {
351
+ const effectiveUserId = asOptionalTrimmedString(userId) ?? "local";
352
+ const processed = processAgentCreateForm(formData, effectiveUserId);
353
+ const now = Date.now();
354
+ const id = ulid();
355
+ const privateKey = createAgentKey.private(effectiveUserId, id);
356
+ const publicKey = createAgentKey.public(id);
357
+ let agent = {
358
+ ...processed,
359
+ id,
360
+ type: "agent" /* AGENT */,
361
+ userId: effectiveUserId,
362
+ createdAt: now,
363
+ updatedAt: now,
364
+ dialogCount: 0,
365
+ messageCount: 0,
366
+ tokenCount: 0,
367
+ spaceId
368
+ // 记录 spaceId
369
+ };
370
+ if (effectiveUserId === "local") {
371
+ agent.isPublic = false;
372
+ }
373
+ try {
374
+ const { localFirstLog } = await import("./localFirstLog-DHNOY2NA.js");
375
+ localFirstLog("agent.create.start", {
376
+ owner: effectiveUserId,
377
+ hasRawApiKey: Boolean(readNonEmptyApiKey(agent.apiKey)),
378
+ hasSpace: Boolean(spaceId)
379
+ });
380
+ } catch {
381
+ }
382
+ const createRawApiKey = readNonEmptyApiKey(agent.apiKey);
383
+ if (createRawApiKey) {
384
+ agent = await migrateRawApiKeyForAgent({
385
+ record: agent,
386
+ agentKey: privateKey,
387
+ apiKey: createRawApiKey,
388
+ apiKeyRef: agent.apiKeyRef,
389
+ credentialRef: agent.credentialRef
390
+ });
391
+ }
392
+ await thunkApi.dispatch(
393
+ write({
394
+ data: agent,
395
+ customKey: privateKey,
396
+ userId: effectiveUserId
397
+ })
398
+ ).unwrap();
399
+ if (agent.isPublic) {
400
+ await thunkApi.dispatch(
401
+ write({
402
+ data: agent,
403
+ customKey: publicKey,
404
+ userId: effectiveUserId
405
+ })
406
+ ).unwrap();
407
+ }
408
+ if (agent.credentialSynced && createRawApiKey) {
409
+ const ctx = getRuntimeServerContext(thunkApi.getState());
410
+ const credentialRef = agent.credentialRef;
411
+ if (ctx.currentToken && credentialRef) {
412
+ try {
413
+ await pushServerSyncedCredential(
414
+ { currentServer: ctx.currentServer ?? "", authToken: ctx.currentToken },
415
+ credentialRef,
416
+ createRawApiKey
417
+ );
418
+ } catch {
419
+ }
420
+ }
421
+ }
422
+ try {
423
+ const { localFirstLog } = await import("./localFirstLog-DHNOY2NA.js");
424
+ localFirstLog("agent.create.done", {
425
+ owner: effectiveUserId,
426
+ key: privateKey,
427
+ hasCredentialRef: Boolean(
428
+ typeof agent.credentialRef === "string" && agent.credentialRef.trim()
429
+ ),
430
+ hasRawApiKey: Boolean(readNonEmptyApiKey(agent.apiKey)),
431
+ isPublic: Boolean(agent.isPublic)
432
+ });
433
+ } catch {
434
+ }
435
+ return agent;
436
+ }
437
+ ),
438
+ /**
439
+ * 更新 Agent(支持局部字段 patch):
440
+ * - patch 私有副本
441
+ * - 如提供 previousAgent,则同步更新 / 删除公共副本
442
+ *
443
+ * 注意:
444
+ * - Tool 场景下一般不提供 previousAgent,此时只保证私有副本被更新;
445
+ * 公共副本(应用市场)不做强一致保证。
446
+ */
447
+ updateAgent: create.asyncThunk(
448
+ async ({ userId, agentId, formData, previousAgent }, thunkApi) => {
449
+ const effectiveUserId = asOptionalTrimmedString(userId) ?? "local";
450
+ const normalizedAgentId = (() => {
451
+ const raw = agentId.trim();
452
+ if (raw.startsWith("agent-")) {
453
+ const parts = raw.split("-");
454
+ if (parts.length >= 3) return parts.slice(2).join("-");
455
+ }
456
+ return raw;
457
+ })();
458
+ const privateKey = createAgentKey.private(effectiveUserId, normalizedAgentId);
459
+ const publicKey = createAgentKey.public(normalizedAgentId);
460
+ let changes = processAgentUpdateChanges(formData || {}, effectiveUserId, previousAgent);
461
+ const updateRawApiKey = readNonEmptyApiKey(changes.apiKey);
462
+ if (updateRawApiKey) {
463
+ const formAny = formData || {};
464
+ const migrated = await migrateRawApiKeyForAgent({
465
+ record: { ...changes },
466
+ agentKey: privateKey,
467
+ apiKey: updateRawApiKey,
468
+ apiKeyRef: formAny.apiKeyRef ?? previousAgent?.apiKeyRef ?? changes.apiKeyRef,
469
+ credentialRef: formAny.credentialRef ?? previousAgent?.credentialRef ?? changes.credentialRef
470
+ });
471
+ changes = migrated;
472
+ if (!readNonEmptyApiKey(changes.apiKey)) {
473
+ changes.apiKey = null;
474
+ }
475
+ }
476
+ let localExists = false;
477
+ try {
478
+ const { db } = thunkApi.extra;
479
+ const localData = await db.get(privateKey);
480
+ localExists = !!localData;
481
+ } catch (e) {
482
+ }
483
+ if (localExists) {
484
+ await thunkApi.dispatch(
485
+ patch({
486
+ dbKey: privateKey,
487
+ changes
488
+ })
489
+ ).unwrap();
490
+ } else if (previousAgent) {
491
+ const merged = {
492
+ ...previousAgent,
493
+ ...changes,
494
+ id: normalizedAgentId,
495
+ type: previousAgent.type || "agent" /* AGENT */,
496
+ userId: effectiveUserId
497
+ };
498
+ await thunkApi.dispatch(
499
+ write({
500
+ data: merged,
501
+ customKey: privateKey,
502
+ userId: effectiveUserId
503
+ })
504
+ ).unwrap();
505
+ } else {
506
+ await thunkApi.dispatch(
507
+ patch({
508
+ dbKey: privateKey,
509
+ changes
510
+ })
511
+ ).unwrap();
512
+ }
513
+ if (previousAgent && effectiveUserId !== "local") {
514
+ const wasPublic = !!previousAgent.isPublic;
515
+ const hasIsPublicChange = Object.prototype.hasOwnProperty.call(
516
+ changes,
517
+ "isPublic"
518
+ );
519
+ const nowPublic = hasIsPublicChange ? !!changes.isPublic : wasPublic;
520
+ if (nowPublic) {
521
+ const mergedPublic = {
522
+ ...previousAgent,
523
+ ...changes,
524
+ id: normalizedAgentId,
525
+ type: previousAgent.type || "agent" /* AGENT */,
526
+ userId: effectiveUserId
527
+ };
528
+ await thunkApi.dispatch(
529
+ write({
530
+ data: mergedPublic,
531
+ customKey: publicKey,
532
+ userId: effectiveUserId
533
+ })
534
+ ).unwrap();
535
+ } else if (wasPublic && !nowPublic) {
536
+ await thunkApi.dispatch(remove(publicKey)).unwrap();
537
+ }
538
+ }
539
+ const base = previousAgent ?? {};
540
+ const mergedPrivate = {
541
+ ...base,
542
+ ...changes,
543
+ id: normalizedAgentId,
544
+ type: base.type || "agent" /* AGENT */,
545
+ userId: effectiveUserId
546
+ };
547
+ return mergedPrivate;
548
+ }
549
+ )
550
+ })
551
+ });
552
+ var {
553
+ runLlm,
554
+ runAgent,
555
+ streamAgentChatTurn,
556
+ createAgent,
557
+ updateAgent
558
+ } = slice.actions;
559
+ var agentReducer = slice.reducer;
560
+ var agentSlice_default = agentReducer;
561
+
562
+ export {
563
+ fetchServerSyncedCredential,
564
+ deleteServerSyncedCredential,
565
+ setAgentCredentialBrokerFactoryForTests,
566
+ slice,
567
+ runLlm,
568
+ runAgent,
569
+ streamAgentChatTurn,
570
+ createAgent,
571
+ updateAgent,
572
+ agentSlice_default
573
+ };