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.
- package/_executeModel-CPDNUUQV.js +198 -0
- package/action-PAXRPJJF.js +27 -0
- package/addContentAction-CZVWF3QZ.js +25 -0
- package/addDialogAgentAction-CCIDTPHC.js +67 -0
- package/agentDeleteCommand-OSUMJMZM.js +323 -0
- package/agentEmailCommands-OQTJIPQU.js +621 -0
- package/agentListCommands-FATQEUYT.js +219 -0
- package/agentMachineCommands-6LZWF4GL.js +421 -0
- package/agentPullCommand-O2MTUAFR.js +122 -0
- package/agentRecordCommands-TIHFU65Z.js +89 -0
- package/agentRunCommand-R64Y3HCH.js +102 -0
- package/agentRunControl-K4VKNEHF.js +57 -0
- package/agentRuntimeLocal-6PIWAHLQ.js +99 -0
- package/agentSlice-TP4VARJF.js +41 -0
- package/authCommand-WXMD3IPR.js +574 -0
- package/authCommands-X74AFDTC.js +26 -0
- package/chunk-2EISRLRC.js +238 -0
- package/chunk-2FTTDCD4.js +675 -0
- package/chunk-2MALU52L.js +51 -0
- package/chunk-2TPUKEU7.js +1078 -0
- package/chunk-3ASDTTEI.js +1774 -0
- package/chunk-3EUW3WEO.js +8 -0
- package/chunk-3LY4F7SV.js +9293 -0
- package/chunk-4CQLVGRV.js +50 -0
- package/chunk-4IJYA27C.js +342 -0
- package/chunk-4SN6J65J.js +38 -0
- package/chunk-4VNS5WPM.js +42 -0
- package/chunk-572EKYLF.js +792 -0
- package/chunk-5MIDPSSK.js +206 -0
- package/chunk-5MMAK75Q.js +15 -0
- package/chunk-5VV37AT4.js +222 -0
- package/chunk-63W5N6P3.js +150 -0
- package/chunk-6A5EF6IR.js +929 -0
- package/chunk-6HYVJV7B.js +102 -0
- package/chunk-6P2WX5IA.js +3631 -0
- package/chunk-6WD3OOJS.js +20 -0
- package/chunk-ATNTHIZI.js +13 -0
- package/chunk-AUGHVUFE.js +69 -0
- package/chunk-AVMKZHBC.js +85 -0
- package/chunk-AZPCASRE.js +36 -0
- package/chunk-BNMT7YY5.js +34 -0
- package/chunk-BR2WP3DF.js +548 -0
- package/chunk-BSTNFPHD.js +231 -0
- package/chunk-BU4OPIXC.js +171 -0
- package/chunk-CF2WZF4N.js +134 -0
- package/chunk-CF7PE763.js +10 -0
- package/chunk-CKOJQDKR.js +198 -0
- package/chunk-CM54RSSA.js +206 -0
- package/chunk-CWMSB67P.js +34 -0
- package/chunk-DA2OEKS6.js +27 -0
- package/chunk-DFFIZ25G.js +30 -0
- package/chunk-DWLEOOGR.js +8 -0
- package/chunk-DZ3XJVET.js +231 -0
- package/chunk-EHLHSX7R.js +1433 -0
- package/chunk-ELRRLDWI.js +478 -0
- package/chunk-EYEEHCU4.js +3066 -0
- package/chunk-FQZWM5YX.js +628 -0
- package/chunk-G3SUCT4W.js +8 -0
- package/chunk-G5H7RNFL.js +807 -0
- package/chunk-GAKEBQD6.js +30 -0
- package/chunk-GBRG75BQ.js +86 -0
- package/chunk-H2RMRZJE.js +113 -0
- package/chunk-H33743XH.js +25 -0
- package/chunk-HD63YREL.js +19 -0
- package/chunk-HEIIIZBX.js +104 -0
- package/chunk-HNMXYYJR.js +12 -0
- package/chunk-HOMYP7GZ.js +2152 -0
- package/chunk-HZFOMJRA.js +4300 -0
- package/chunk-IAXBCTTE.js +175 -0
- package/chunk-IDZTNRP2.js +85 -0
- package/chunk-IHHA5Y2S.js +9013 -0
- package/chunk-ISNCLGUZ.js +146 -0
- package/chunk-IYQV26RA.js +138 -0
- package/chunk-J4576WMJ.js +91 -0
- package/chunk-JBTJAPUF.js +35 -0
- package/chunk-JZPBVBIY.js +94 -0
- package/chunk-KQHGZWSV.js +63 -0
- package/chunk-KUG52IAP.js +8 -0
- package/chunk-KX6YBIHG.js +8 -0
- package/chunk-LCBAMY2M.js +60 -0
- package/chunk-LM25IZBJ.js +902 -0
- package/chunk-LM6IYQ3F.js +16 -0
- package/chunk-M76ECQRD.js +13658 -0
- package/chunk-MRC4Q34M.js +188 -0
- package/chunk-NEMRK4EK.js +944 -0
- package/chunk-NXZGF7F7.js +2878 -0
- package/chunk-OF5H3QWS.js +300 -0
- package/chunk-OLZBQWZU.js +6 -0
- package/chunk-OOYVBFM7.js +191 -0
- package/chunk-OWOHNGCN.js +50 -0
- package/chunk-PN7AFLOK.js +3401 -0
- package/chunk-POCFIDGQ.js +562 -0
- package/chunk-Q6WACBKB.js +1949 -0
- package/chunk-QFV2OAIM.js +421 -0
- package/chunk-QJ6V2NIN.js +1447 -0
- package/chunk-QSJ3HFEF.js +8 -0
- package/chunk-QUWDTOUP.js +190 -0
- package/chunk-QYXLLLGL.js +4519 -0
- package/chunk-ROWQEJRP.js +139 -0
- package/chunk-S7Z2HMCN.js +25 -0
- package/chunk-TDIQFT2F.js +301 -0
- package/chunk-TILFE6LV.js +381 -0
- package/chunk-TKOUBWBO.js +24674 -0
- package/chunk-TYH5JE6N.js +27158 -0
- package/chunk-U4TRT5V4.js +246 -0
- package/chunk-U6VC4MU4.js +8 -0
- package/chunk-UAD2WT54.js +64 -0
- package/chunk-USZMK5UT.js +105 -0
- package/chunk-VEJLAVTC.js +2052 -0
- package/chunk-VF4K2QE6.js +21 -0
- package/chunk-VHBWHNVT.js +59 -0
- package/chunk-VIDPVFP3.js +20 -0
- package/chunk-VP4WJWKW.js +8882 -0
- package/chunk-VQ2AJRGD.js +148 -0
- package/chunk-W4NVOSFF.js +37 -0
- package/chunk-WWC7I6TA.js +8 -0
- package/chunk-X7W4TNB4.js +1550 -0
- package/chunk-XDVAYP26.js +537 -0
- package/chunk-XKIMRZO2.js +221 -0
- package/chunk-Y5GCAMGP.js +9 -0
- package/chunk-YWPXYBY7.js +360 -0
- package/chunk-Z4NR32XR.js +50 -0
- package/chunk-ZNFJWEN4.js +56 -0
- package/cliExecutor-DNE7TCC4.js +36 -0
- package/clipboardy-BVE3LVEH.js +12001 -0
- package/createAgentAutomationAction-KLKS2HGU.js +864 -0
- package/createDialogAction-Z33JMBF5.js +52 -0
- package/createPageAction-AQVNOAAI.js +169 -0
- package/db-HCJ5PRB5.js +271 -0
- package/dbSlice-C4UJLRZP.js +59 -0
- package/deleteFile-4SKGPHOZ.js +41 -0
- package/dialogCommands-W5PD6MZU.js +59 -0
- package/dialogSlice-RBJYVSAR.js +146 -0
- package/docCreateCommands-MM34S4Z3.js +215 -0
- package/docDeleteCommands-JJTU722V.js +176 -0
- package/docReadCommands-GLYDMCTU.js +129 -0
- package/docStore-5TYME4DO.js +96 -0
- package/docUpdateCommands-ZCGQ7URR.js +313 -0
- package/fetchMessages-JOCYIFKL.js +16 -0
- package/getPricing-PWPJ6MNV.js +30 -0
- package/handleSendMessageAction-KA2MRW6E.js +183 -0
- package/index.js +184 -112254
- package/lib-FYYBQIXS.js +19839 -0
- package/localDialogRead-D3BELSTF.js +26 -0
- package/localFirstLog-DHNOY2NA.js +19 -0
- package/localRuntimeAuthority-TEGCOWX4.js +471 -0
- package/localRuntimeDb-LGDF6FQP.js +12 -0
- package/machineCommands-ZB5WUSPF.js +774 -0
- package/machineInfo-M6KB6HZN.js +10 -0
- package/machineWsRunDispatch-GWCAPPCM.js +105 -0
- package/memoryCommands-O4MIPIWQ.js +476 -0
- package/models-XLEOET3E.js +9 -0
- package/offlineMarxistsAgentCommand-BCPJITJL.js +242 -0
- package/package.json +3 -25
- package/read-RIJCIVKX.js +17 -0
- package/readDocTool-GZD2N3LO.js +16 -0
- package/readlineWorkspace-FEDY44AA.js +5357 -0
- package/removeDialogAgentAction-CXLST3N6.js +72 -0
- package/runAgentClientLoop-W4NKE64V.js +288 -0
- package/runtimeDoctorCommands-LRHLPDRC.js +289 -0
- package/setDialogExtraReferencesAction-LP6VYGU7.js +59 -0
- package/setPrimaryDialogAgentAction-D3GGH23T.js +79 -0
- package/settingSlice-J4I3Z5H7.js +198 -0
- package/skillSummaryMarker-42HKSXYY.js +9 -0
- package/slateToRenderMarkdown-Y5IYN73U.js +7 -0
- package/slateUtils-2M7MUTWX.js +19 -0
- package/spaceCommands-LC4FDAKE.js +450 -0
- package/spaceSlice-32XOGBEF.js +145 -0
- package/streamAgentChatTurn-YQW32AQH.js +4503 -0
- package/tableCommands-GOFP7QKA.js +1286 -0
- package/toolApiClient-QI3YBNWB.js +26 -0
- package/tools-XGTFRYD7.js +83 -0
- package/understanding-HCSFPE7R.js +318 -0
- package/updateCommands-VOSPKXFF.js +31 -0
- package/updateDialogTitleAction-4LHQDNHQ.js +185 -0
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyAgentSecretMigrationUpdates,
|
|
3
|
+
createFileCredentialBroker,
|
|
4
|
+
migrateAgentSecrets,
|
|
5
|
+
normalizeAgentRuntimeToolPolicy
|
|
6
|
+
} from "./chunk-TDIQFT2F.js";
|
|
7
|
+
import {
|
|
8
|
+
patch,
|
|
9
|
+
remove,
|
|
10
|
+
write
|
|
11
|
+
} from "./chunk-G5H7RNFL.js";
|
|
12
|
+
import {
|
|
13
|
+
asRecordOrEmpty
|
|
14
|
+
} from "./chunk-KX6YBIHG.js";
|
|
15
|
+
import {
|
|
16
|
+
createAgentKey,
|
|
17
|
+
require_index_umd,
|
|
18
|
+
toTrimmedString
|
|
19
|
+
} from "./chunk-PN7AFLOK.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/ai/agent/agentSlice.ts
|
|
80
|
+
var import_ulid = __toESM(require_index_umd());
|
|
81
|
+
var createAgentCredentialBroker = createFileCredentialBroker;
|
|
82
|
+
function setAgentCredentialBrokerFactoryForTests(factory) {
|
|
83
|
+
createAgentCredentialBroker = factory ?? createFileCredentialBroker;
|
|
84
|
+
}
|
|
85
|
+
var readNonEmptyApiKey = (value) => asTrimmedString(value);
|
|
86
|
+
var migrateRawApiKeyForAgent = async (args) => {
|
|
87
|
+
const broker = createAgentCredentialBroker();
|
|
88
|
+
const result = await migrateAgentSecrets({
|
|
89
|
+
agent: {
|
|
90
|
+
key: args.agentKey,
|
|
91
|
+
apiKey: args.apiKey,
|
|
92
|
+
apiKeyRef: args.apiKeyRef,
|
|
93
|
+
credentialRef: args.credentialRef
|
|
94
|
+
},
|
|
95
|
+
broker
|
|
96
|
+
});
|
|
97
|
+
const next = applyAgentSecretMigrationUpdates(args.record, result.updates);
|
|
98
|
+
if (readNonEmptyApiKey(next.apiKey)) {
|
|
99
|
+
throw new Error(
|
|
100
|
+
"Failed to migrate agent API key into the local credential broker. The raw key was not stripped."
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
return next;
|
|
104
|
+
};
|
|
105
|
+
var createSliceWithThunks = buildCreateSlice({
|
|
106
|
+
creators: { asyncThunk: asyncThunkCreator }
|
|
107
|
+
});
|
|
108
|
+
var initialState = {};
|
|
109
|
+
var normalizeAgentReferences = (references) => {
|
|
110
|
+
if (!Array.isArray(references)) return [];
|
|
111
|
+
return references.map((ref) => ({
|
|
112
|
+
dbKey: ref.dbKey || "",
|
|
113
|
+
title: ref.title || "",
|
|
114
|
+
type: ref.type === "page" ? "knowledge" : ref.type || "knowledge"
|
|
115
|
+
}));
|
|
116
|
+
};
|
|
117
|
+
var normalizeRuntimeToolPolicy = (value) => {
|
|
118
|
+
const policy = normalizeAgentRuntimeToolPolicy(value);
|
|
119
|
+
if (!policy) return void 0;
|
|
120
|
+
const hasPolicyContent = Boolean(
|
|
121
|
+
policy.agentTools?.length || policy.runtimeTools?.length || policy.workspace || policy.shell || policy.isolation || policy.git || policy.budget || policy.audit
|
|
122
|
+
);
|
|
123
|
+
return hasPolicyContent ? policy : void 0;
|
|
124
|
+
};
|
|
125
|
+
var processAgentCreateForm = (formData, userId) => {
|
|
126
|
+
const isPublic = !!formData.isPublic;
|
|
127
|
+
const machineId = asTrimmedString(formData.machineId);
|
|
128
|
+
const result = {
|
|
129
|
+
...formData,
|
|
130
|
+
// tags: "a, b" -> ["a", "b"]
|
|
131
|
+
tags: formData.tags ? formData.tags.split(",").map((s) => s.trim()).filter(Boolean) : [],
|
|
132
|
+
// 归一化 references
|
|
133
|
+
references: normalizeAgentReferences(formData.references || []),
|
|
134
|
+
// 非公开时,强制清空白名单,避免脏数据
|
|
135
|
+
whitelist: isPublic ? formData.whitelist || [] : [],
|
|
136
|
+
// allowFork 独立于公开:Space 内的私有 agent 也可被空间成员复制
|
|
137
|
+
allowFork: !!formData.allowFork
|
|
138
|
+
};
|
|
139
|
+
delete result.machineId;
|
|
140
|
+
result.runtimeToolPolicy = normalizeRuntimeToolPolicy(
|
|
141
|
+
formData.runtimeToolPolicy
|
|
142
|
+
);
|
|
143
|
+
if (!result.runtimeToolPolicy) {
|
|
144
|
+
delete result.runtimeToolPolicy;
|
|
145
|
+
}
|
|
146
|
+
if (formData.apiSource === "cli" && machineId) {
|
|
147
|
+
const binding = {
|
|
148
|
+
...asRecordOrEmpty(result.runtimeBinding),
|
|
149
|
+
machineId,
|
|
150
|
+
ownerUserId: userId
|
|
151
|
+
};
|
|
152
|
+
result.runtimeBinding = binding;
|
|
153
|
+
}
|
|
154
|
+
return result;
|
|
155
|
+
};
|
|
156
|
+
var processAgentUpdateChanges = (data, userId, previousAgent) => {
|
|
157
|
+
const changes = {};
|
|
158
|
+
if ("name" in data) {
|
|
159
|
+
changes.name = String(data.name ?? "").trim();
|
|
160
|
+
}
|
|
161
|
+
if ("model" in data) {
|
|
162
|
+
changes.model = (data.model ?? "").trim();
|
|
163
|
+
}
|
|
164
|
+
if ("provider" in data) {
|
|
165
|
+
changes.provider = (data.provider ?? "").trim();
|
|
166
|
+
}
|
|
167
|
+
if ("prompt" in data) {
|
|
168
|
+
changes.prompt = (data.prompt ?? "").trim();
|
|
169
|
+
}
|
|
170
|
+
if ("introduction" in data) {
|
|
171
|
+
changes.introduction = (data.introduction ?? "").trim();
|
|
172
|
+
}
|
|
173
|
+
if ("customProviderUrl" in data) {
|
|
174
|
+
changes.customProviderUrl = (data.customProviderUrl ?? "").trim();
|
|
175
|
+
}
|
|
176
|
+
if ("apiKey" in data) {
|
|
177
|
+
changes.apiKey = (data.apiKey ?? "").trim();
|
|
178
|
+
}
|
|
179
|
+
if ("hasVision" in data && data.hasVision !== void 0) {
|
|
180
|
+
changes.hasVision = !!data.hasVision;
|
|
181
|
+
}
|
|
182
|
+
if ("apiSource" in data && data.apiSource) {
|
|
183
|
+
changes.apiSource = data.apiSource;
|
|
184
|
+
}
|
|
185
|
+
if ("cliProvider" in data) {
|
|
186
|
+
changes.cliProvider = data.cliProvider || "";
|
|
187
|
+
}
|
|
188
|
+
if ("machineId" in data) {
|
|
189
|
+
const machineId = String(data.machineId ?? "").trim();
|
|
190
|
+
const effectiveApiSource = data.apiSource ?? previousAgent?.apiSource;
|
|
191
|
+
if (machineId) {
|
|
192
|
+
if (effectiveApiSource === "cli" || effectiveApiSource === void 0) {
|
|
193
|
+
const binding = {
|
|
194
|
+
...asRecordOrEmpty(changes.runtimeBinding),
|
|
195
|
+
machineId,
|
|
196
|
+
ownerUserId: userId
|
|
197
|
+
};
|
|
198
|
+
changes.runtimeBinding = binding;
|
|
199
|
+
}
|
|
200
|
+
} else {
|
|
201
|
+
if (effectiveApiSource === "cli" || effectiveApiSource === void 0) {
|
|
202
|
+
changes.runtimeBinding = null;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if ("useServerProxy" in data && data.useServerProxy !== void 0) {
|
|
207
|
+
changes.useServerProxy = !!data.useServerProxy;
|
|
208
|
+
}
|
|
209
|
+
if ("sharingLevel" in data) {
|
|
210
|
+
const sharingLevel = data.sharingLevel;
|
|
211
|
+
if (sharingLevel === "default" || sharingLevel === "split" || sharingLevel === "full") {
|
|
212
|
+
changes.sharingLevel = sharingLevel;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if ("greeting" in data) {
|
|
216
|
+
changes.greeting = data.greeting;
|
|
217
|
+
}
|
|
218
|
+
if ("tools" in data) {
|
|
219
|
+
changes.tools = Array.isArray(data.tools) ? data.tools.slice() : [];
|
|
220
|
+
}
|
|
221
|
+
if ("runtimeToolPolicy" in data) {
|
|
222
|
+
const rawRuntimeToolPolicy = data.runtimeToolPolicy;
|
|
223
|
+
changes.runtimeToolPolicy = rawRuntimeToolPolicy === null ? null : normalizeRuntimeToolPolicy(rawRuntimeToolPolicy) ?? null;
|
|
224
|
+
}
|
|
225
|
+
const numericKeys = [
|
|
226
|
+
"inputPrice",
|
|
227
|
+
"outputPrice",
|
|
228
|
+
"temperature",
|
|
229
|
+
"top_p",
|
|
230
|
+
"frequency_penalty",
|
|
231
|
+
"presence_penalty",
|
|
232
|
+
"max_tokens"
|
|
233
|
+
];
|
|
234
|
+
numericKeys.forEach((key) => {
|
|
235
|
+
if (key in data) {
|
|
236
|
+
const raw = data[key];
|
|
237
|
+
if (raw === void 0 || raw === null) {
|
|
238
|
+
changes[key] = raw;
|
|
239
|
+
} else {
|
|
240
|
+
const num = Number(raw);
|
|
241
|
+
changes[key] = Number.isNaN(num) ? raw : num;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
if ("reasoning_effort" in data) {
|
|
246
|
+
changes.reasoning_effort = data.reasoning_effort;
|
|
247
|
+
}
|
|
248
|
+
if ("tags" in data) {
|
|
249
|
+
const raw = data.tags;
|
|
250
|
+
let arr = [];
|
|
251
|
+
if (Array.isArray(raw)) {
|
|
252
|
+
arr = raw.map((s) => toTrimmedString(s)).filter(Boolean);
|
|
253
|
+
} else if (typeof raw === "string") {
|
|
254
|
+
arr = raw.split(",").map((s) => s.trim()).filter(Boolean);
|
|
255
|
+
}
|
|
256
|
+
changes.tags = arr;
|
|
257
|
+
}
|
|
258
|
+
if ("references" in data) {
|
|
259
|
+
changes.references = normalizeAgentReferences(
|
|
260
|
+
data.references || []
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
if ("whitelist" in data) {
|
|
264
|
+
changes.whitelist = data.whitelist || [];
|
|
265
|
+
}
|
|
266
|
+
if ("allowFork" in data) {
|
|
267
|
+
changes.allowFork = !!data.allowFork;
|
|
268
|
+
}
|
|
269
|
+
if ("avatarFileId" in data) {
|
|
270
|
+
const raw = data.avatarFileId;
|
|
271
|
+
changes.avatarFileId = raw ? String(raw).trim() : null;
|
|
272
|
+
}
|
|
273
|
+
if ("isPublic" in data) {
|
|
274
|
+
changes.isPublic = !!data.isPublic;
|
|
275
|
+
if (!changes.isPublic) {
|
|
276
|
+
changes.whitelist = [];
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return changes;
|
|
280
|
+
};
|
|
281
|
+
var slice = createSliceWithThunks({
|
|
282
|
+
name: "agent",
|
|
283
|
+
initialState,
|
|
284
|
+
reducers: (create) => ({
|
|
285
|
+
/**
|
|
286
|
+
* 通用 LLM 调用(不带 Agent 上下文 / 历史)
|
|
287
|
+
*/
|
|
288
|
+
runLlm: create.asyncThunk(async (args, thunkApi) => {
|
|
289
|
+
const overrides = {};
|
|
290
|
+
if (args.systemPromptOverride !== void 0) overrides.prompt = args.systemPromptOverride;
|
|
291
|
+
if (args.toolsOverride !== void 0) overrides.tools = args.toolsOverride;
|
|
292
|
+
const { _executeModel } = await import("./_executeModel-CPDNUUQV.js");
|
|
293
|
+
return _executeModel(
|
|
294
|
+
{
|
|
295
|
+
isStreaming: args.isStreaming ?? false,
|
|
296
|
+
withAgentContext: false,
|
|
297
|
+
withChatHistory: false,
|
|
298
|
+
agentConfigOverrides: Object.keys(overrides).length ? overrides : void 0
|
|
299
|
+
},
|
|
300
|
+
args,
|
|
301
|
+
thunkApi
|
|
302
|
+
);
|
|
303
|
+
}),
|
|
304
|
+
/**
|
|
305
|
+
* 通用 Agent 调用(带 Agent 上下文,多轮工具循环)
|
|
306
|
+
*
|
|
307
|
+
* 使用客户端 runAgentClientLoop:
|
|
308
|
+
* - 每轮调用 LLM(非流式)
|
|
309
|
+
* - 遇到 tool_calls 时通过 findToolExecutor 本地执行工具
|
|
310
|
+
* - 循环直到无工具调用或触发其他运行时停止条件
|
|
311
|
+
*/
|
|
312
|
+
runAgent: create.asyncThunk(async (args, thunkApi) => {
|
|
313
|
+
const { runAgentClientLoop } = await import("./runAgentClientLoop-W4NKE64V.js");
|
|
314
|
+
const { content: loopContent, toolCallCount } = await runAgentClientLoop(
|
|
315
|
+
{
|
|
316
|
+
agentKey: args.agentKey,
|
|
317
|
+
content: args.content,
|
|
318
|
+
parentMessageId: args.parentMessageId,
|
|
319
|
+
billingDialogKey: args.billingDialogKey
|
|
320
|
+
},
|
|
321
|
+
thunkApi
|
|
322
|
+
);
|
|
323
|
+
return loopContent;
|
|
324
|
+
}),
|
|
325
|
+
/**
|
|
326
|
+
* 聊天轮次流式 Agent 调用
|
|
327
|
+
*/
|
|
328
|
+
streamAgentChatTurn: create.asyncThunk(async (args, thunkApi) => {
|
|
329
|
+
const { streamAgentChatTurnHandler } = await import("./streamAgentChatTurn-YQW32AQH.js");
|
|
330
|
+
return streamAgentChatTurnHandler(args, thunkApi);
|
|
331
|
+
}),
|
|
332
|
+
/**
|
|
333
|
+
* 创建 Agent:
|
|
334
|
+
* - 写入用户私有路径
|
|
335
|
+
* - 如 isPublic=true,则同时写入公共路径
|
|
336
|
+
* - 返回完整 Agent 对象(包含 id / meta 字段)
|
|
337
|
+
*/
|
|
338
|
+
createAgent: create.asyncThunk(
|
|
339
|
+
async ({ userId, formData, spaceId }, thunkApi) => {
|
|
340
|
+
const effectiveUserId = asOptionalTrimmedString(userId) ?? "local";
|
|
341
|
+
const processed = processAgentCreateForm(formData, effectiveUserId);
|
|
342
|
+
const now = Date.now();
|
|
343
|
+
const id = (0, import_ulid.ulid)();
|
|
344
|
+
const privateKey = createAgentKey.private(effectiveUserId, id);
|
|
345
|
+
const publicKey = createAgentKey.public(id);
|
|
346
|
+
let agent = {
|
|
347
|
+
...processed,
|
|
348
|
+
id,
|
|
349
|
+
type: "agent" /* AGENT */,
|
|
350
|
+
userId: effectiveUserId,
|
|
351
|
+
createdAt: now,
|
|
352
|
+
updatedAt: now,
|
|
353
|
+
dialogCount: 0,
|
|
354
|
+
messageCount: 0,
|
|
355
|
+
tokenCount: 0,
|
|
356
|
+
spaceId
|
|
357
|
+
// 记录 spaceId
|
|
358
|
+
};
|
|
359
|
+
if (effectiveUserId === "local") {
|
|
360
|
+
agent.isPublic = false;
|
|
361
|
+
}
|
|
362
|
+
try {
|
|
363
|
+
const { localFirstLog } = await import("./localFirstLog-DHNOY2NA.js");
|
|
364
|
+
localFirstLog("agent.create.start", {
|
|
365
|
+
owner: effectiveUserId,
|
|
366
|
+
hasRawApiKey: Boolean(readNonEmptyApiKey(agent.apiKey)),
|
|
367
|
+
hasSpace: Boolean(spaceId)
|
|
368
|
+
});
|
|
369
|
+
} catch {
|
|
370
|
+
}
|
|
371
|
+
const createRawApiKey = readNonEmptyApiKey(agent.apiKey);
|
|
372
|
+
if (createRawApiKey) {
|
|
373
|
+
agent = await migrateRawApiKeyForAgent({
|
|
374
|
+
record: agent,
|
|
375
|
+
agentKey: privateKey,
|
|
376
|
+
apiKey: createRawApiKey,
|
|
377
|
+
apiKeyRef: agent.apiKeyRef,
|
|
378
|
+
credentialRef: agent.credentialRef
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
await thunkApi.dispatch(
|
|
382
|
+
write({
|
|
383
|
+
data: agent,
|
|
384
|
+
customKey: privateKey,
|
|
385
|
+
userId: effectiveUserId
|
|
386
|
+
})
|
|
387
|
+
).unwrap();
|
|
388
|
+
if (agent.isPublic) {
|
|
389
|
+
await thunkApi.dispatch(
|
|
390
|
+
write({
|
|
391
|
+
data: agent,
|
|
392
|
+
customKey: publicKey,
|
|
393
|
+
userId: effectiveUserId
|
|
394
|
+
})
|
|
395
|
+
).unwrap();
|
|
396
|
+
}
|
|
397
|
+
if (agent.credentialSynced && createRawApiKey) {
|
|
398
|
+
const ctx = getRuntimeServerContext(thunkApi.getState());
|
|
399
|
+
const credentialRef = agent.credentialRef;
|
|
400
|
+
if (ctx.currentToken && credentialRef) {
|
|
401
|
+
try {
|
|
402
|
+
await pushServerSyncedCredential(
|
|
403
|
+
{ currentServer: ctx.currentServer ?? "", authToken: ctx.currentToken },
|
|
404
|
+
credentialRef,
|
|
405
|
+
createRawApiKey
|
|
406
|
+
);
|
|
407
|
+
} catch {
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
try {
|
|
412
|
+
const { localFirstLog } = await import("./localFirstLog-DHNOY2NA.js");
|
|
413
|
+
localFirstLog("agent.create.done", {
|
|
414
|
+
owner: effectiveUserId,
|
|
415
|
+
key: privateKey,
|
|
416
|
+
hasCredentialRef: Boolean(
|
|
417
|
+
typeof agent.credentialRef === "string" && agent.credentialRef.trim()
|
|
418
|
+
),
|
|
419
|
+
hasRawApiKey: Boolean(readNonEmptyApiKey(agent.apiKey)),
|
|
420
|
+
isPublic: Boolean(agent.isPublic)
|
|
421
|
+
});
|
|
422
|
+
} catch {
|
|
423
|
+
}
|
|
424
|
+
return agent;
|
|
425
|
+
}
|
|
426
|
+
),
|
|
427
|
+
/**
|
|
428
|
+
* 更新 Agent(支持局部字段 patch):
|
|
429
|
+
* - patch 私有副本
|
|
430
|
+
* - 如提供 previousAgent,则同步更新 / 删除公共副本
|
|
431
|
+
*
|
|
432
|
+
* 注意:
|
|
433
|
+
* - Tool 场景下一般不提供 previousAgent,此时只保证私有副本被更新;
|
|
434
|
+
* 公共副本(应用市场)不做强一致保证。
|
|
435
|
+
*/
|
|
436
|
+
updateAgent: create.asyncThunk(
|
|
437
|
+
async ({ userId, agentId, formData, previousAgent }, thunkApi) => {
|
|
438
|
+
const effectiveUserId = asOptionalTrimmedString(userId) ?? "local";
|
|
439
|
+
const normalizedAgentId = (() => {
|
|
440
|
+
const raw = agentId.trim();
|
|
441
|
+
if (raw.startsWith("agent-")) {
|
|
442
|
+
const parts = raw.split("-");
|
|
443
|
+
if (parts.length >= 3) return parts.slice(2).join("-");
|
|
444
|
+
}
|
|
445
|
+
return raw;
|
|
446
|
+
})();
|
|
447
|
+
const privateKey = createAgentKey.private(effectiveUserId, normalizedAgentId);
|
|
448
|
+
const publicKey = createAgentKey.public(normalizedAgentId);
|
|
449
|
+
let changes = processAgentUpdateChanges(formData || {}, effectiveUserId, previousAgent);
|
|
450
|
+
const updateRawApiKey = readNonEmptyApiKey(changes.apiKey);
|
|
451
|
+
if (updateRawApiKey) {
|
|
452
|
+
const formAny = formData || {};
|
|
453
|
+
const migrated = await migrateRawApiKeyForAgent({
|
|
454
|
+
record: { ...changes },
|
|
455
|
+
agentKey: privateKey,
|
|
456
|
+
apiKey: updateRawApiKey,
|
|
457
|
+
apiKeyRef: formAny.apiKeyRef ?? previousAgent?.apiKeyRef ?? changes.apiKeyRef,
|
|
458
|
+
credentialRef: formAny.credentialRef ?? previousAgent?.credentialRef ?? changes.credentialRef
|
|
459
|
+
});
|
|
460
|
+
changes = migrated;
|
|
461
|
+
if (!readNonEmptyApiKey(changes.apiKey)) {
|
|
462
|
+
changes.apiKey = null;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
let localExists = false;
|
|
466
|
+
try {
|
|
467
|
+
const { db } = thunkApi.extra;
|
|
468
|
+
const localData = await db.get(privateKey);
|
|
469
|
+
localExists = !!localData;
|
|
470
|
+
} catch (e) {
|
|
471
|
+
}
|
|
472
|
+
if (localExists) {
|
|
473
|
+
await thunkApi.dispatch(
|
|
474
|
+
patch({
|
|
475
|
+
dbKey: privateKey,
|
|
476
|
+
changes
|
|
477
|
+
})
|
|
478
|
+
).unwrap();
|
|
479
|
+
} else if (previousAgent) {
|
|
480
|
+
const merged = {
|
|
481
|
+
...previousAgent,
|
|
482
|
+
...changes,
|
|
483
|
+
id: normalizedAgentId,
|
|
484
|
+
type: previousAgent.type || "agent" /* AGENT */,
|
|
485
|
+
userId: effectiveUserId
|
|
486
|
+
};
|
|
487
|
+
await thunkApi.dispatch(
|
|
488
|
+
write({
|
|
489
|
+
data: merged,
|
|
490
|
+
customKey: privateKey,
|
|
491
|
+
userId: effectiveUserId
|
|
492
|
+
})
|
|
493
|
+
).unwrap();
|
|
494
|
+
} else {
|
|
495
|
+
await thunkApi.dispatch(
|
|
496
|
+
patch({
|
|
497
|
+
dbKey: privateKey,
|
|
498
|
+
changes
|
|
499
|
+
})
|
|
500
|
+
).unwrap();
|
|
501
|
+
}
|
|
502
|
+
if (previousAgent && effectiveUserId !== "local") {
|
|
503
|
+
const wasPublic = !!previousAgent.isPublic;
|
|
504
|
+
const hasIsPublicChange = Object.prototype.hasOwnProperty.call(
|
|
505
|
+
changes,
|
|
506
|
+
"isPublic"
|
|
507
|
+
);
|
|
508
|
+
const nowPublic = hasIsPublicChange ? !!changes.isPublic : wasPublic;
|
|
509
|
+
if (nowPublic) {
|
|
510
|
+
const mergedPublic = {
|
|
511
|
+
...previousAgent,
|
|
512
|
+
...changes,
|
|
513
|
+
id: normalizedAgentId,
|
|
514
|
+
type: previousAgent.type || "agent" /* AGENT */,
|
|
515
|
+
userId: effectiveUserId
|
|
516
|
+
};
|
|
517
|
+
await thunkApi.dispatch(
|
|
518
|
+
write({
|
|
519
|
+
data: mergedPublic,
|
|
520
|
+
customKey: publicKey,
|
|
521
|
+
userId: effectiveUserId
|
|
522
|
+
})
|
|
523
|
+
).unwrap();
|
|
524
|
+
} else if (wasPublic && !nowPublic) {
|
|
525
|
+
await thunkApi.dispatch(remove(publicKey)).unwrap();
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
const base = previousAgent ?? {};
|
|
529
|
+
const mergedPrivate = {
|
|
530
|
+
...base,
|
|
531
|
+
...changes,
|
|
532
|
+
id: normalizedAgentId,
|
|
533
|
+
type: base.type || "agent" /* AGENT */,
|
|
534
|
+
userId: effectiveUserId
|
|
535
|
+
};
|
|
536
|
+
return mergedPrivate;
|
|
537
|
+
}
|
|
538
|
+
)
|
|
539
|
+
})
|
|
540
|
+
});
|
|
541
|
+
var {
|
|
542
|
+
runLlm,
|
|
543
|
+
runAgent,
|
|
544
|
+
streamAgentChatTurn,
|
|
545
|
+
createAgent,
|
|
546
|
+
updateAgent
|
|
547
|
+
} = slice.actions;
|
|
548
|
+
var agentReducer = slice.reducer;
|
|
549
|
+
var agentSlice_default = agentReducer;
|
|
550
|
+
|
|
551
|
+
export {
|
|
552
|
+
fetchServerSyncedCredential,
|
|
553
|
+
deleteServerSyncedCredential,
|
|
554
|
+
setAgentCredentialBrokerFactoryForTests,
|
|
555
|
+
slice,
|
|
556
|
+
runLlm,
|
|
557
|
+
runAgent,
|
|
558
|
+
streamAgentChatTurn,
|
|
559
|
+
createAgent,
|
|
560
|
+
updateAgent,
|
|
561
|
+
agentSlice_default
|
|
562
|
+
};
|