dsh-wecom-bot 0.5.0 → 1.0.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.
- package/README.md +53 -310
- package/dist/client.js +1501 -1364
- package/dist/host/bridge/commands.js +62 -17
- package/dist/host/bridge/commands.js.map +1 -1
- package/dist/host/bridge/directory.js +6 -8
- package/dist/host/bridge/directory.js.map +1 -1
- package/dist/host/bridge/index.js +113 -51
- package/dist/host/bridge/index.js.map +1 -1
- package/dist/host/bridge/interactions.js +61 -25
- package/dist/host/bridge/interactions.js.map +1 -1
- package/dist/host/bridge/notices.js +70 -3
- package/dist/host/bridge/notices.js.map +1 -1
- package/dist/host/bridge/outbox.js +11 -0
- package/dist/host/bridge/outbox.js.map +1 -1
- package/dist/host/bridge/policy.js +3 -4
- package/dist/host/bridge/policy.js.map +1 -1
- package/dist/host/bridge/selection.js +7 -0
- package/dist/host/bridge/selection.js.map +1 -1
- package/dist/host/catalog.js +24 -11
- package/dist/host/catalog.js.map +1 -1
- package/dist/host/groups-view.js +369 -156
- package/dist/host/groups-view.js.map +1 -1
- package/dist/host/interaction-transport.js +170 -0
- package/dist/host/interaction-transport.js.map +1 -0
- package/dist/host/journal.js +10 -3
- package/dist/host/journal.js.map +1 -1
- package/dist/host/routes.js +3 -0
- package/dist/host/routes.js.map +1 -1
- package/dist/host/routing.js +25 -12
- package/dist/host/routing.js.map +1 -1
- package/dist/host/runtime.js +84 -25
- package/dist/host/runtime.js.map +1 -1
- package/dist/host/sessions.js +33 -6
- package/dist/host/sessions.js.map +1 -1
- package/dist/host/store.js +107 -19
- package/dist/host/store.js.map +1 -1
- package/dist/host/turns.js +5 -0
- package/dist/host/turns.js.map +1 -1
- package/package.json +1 -1
package/dist/host/groups-view.js
CHANGED
|
@@ -19,6 +19,8 @@ async function memberView(deps, binding) {
|
|
|
19
19
|
sessionContext = described.context;
|
|
20
20
|
}
|
|
21
21
|
const seen = deps.observations?.stats(binding.kind, binding.id);
|
|
22
|
+
const group = deps.store.group(binding.groupId);
|
|
23
|
+
const sessionSelection = binding.sessionSelection ?? (group ? deps.provisioner.desired(group) : undefined);
|
|
22
24
|
return {
|
|
23
25
|
key,
|
|
24
26
|
kind: binding.kind,
|
|
@@ -31,6 +33,7 @@ async function memberView(deps, binding) {
|
|
|
31
33
|
sessionState,
|
|
32
34
|
sessionRunning,
|
|
33
35
|
...(sessionModel ? { sessionModel } : {}),
|
|
36
|
+
...(binding.sessionId && sessionSelection ? { sessionSelection } : {}),
|
|
34
37
|
...(sessionPreset ? { sessionPreset } : {}),
|
|
35
38
|
...(sessionContext ? { sessionContext } : {}),
|
|
36
39
|
messages: seen?.messages ?? 0,
|
|
@@ -174,16 +177,72 @@ export function validateSettingsPatch(patch) {
|
|
|
174
177
|
}
|
|
175
178
|
return clean;
|
|
176
179
|
}
|
|
177
|
-
/**
|
|
180
|
+
/**
|
|
181
|
+
* Decide, before a group change is committed, whether that group's remembered
|
|
182
|
+
* Session may be restored.
|
|
183
|
+
*
|
|
184
|
+
* The store restores the candidate as part of the move itself, so an unusable
|
|
185
|
+
* candidate has to be dropped from the history *first*: validating after the
|
|
186
|
+
* write leaves it routable while the check awaits, and a failed check would
|
|
187
|
+
* leave it bound for good. An unreadable Workspace or catalog also refuses the
|
|
188
|
+
* move instead of silently discarding a Session the operator still owns.
|
|
189
|
+
*/
|
|
190
|
+
async function prepareRestore(deps, key, binding, groupId) {
|
|
191
|
+
const memory = binding.sessionsByGroup?.[groupId];
|
|
192
|
+
if (!memory)
|
|
193
|
+
return undefined;
|
|
194
|
+
const group = deps.store.group(groupId);
|
|
195
|
+
if (!group)
|
|
196
|
+
return `分组不存在:${groupId}`;
|
|
197
|
+
deps.catalogs.invalidate?.();
|
|
198
|
+
let workspacePath;
|
|
199
|
+
try {
|
|
200
|
+
workspacePath = (await deps.workspaces.describe(group.workspace)).path;
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
return `无法读取分组「${group.name}」的 Workspace:${error instanceof Error ? error.message : String(error)}`;
|
|
204
|
+
}
|
|
205
|
+
if (deps.store.get(key) !== binding || deps.store.group(groupId) !== group)
|
|
206
|
+
return '成员信息已变化,请刷新后重试。';
|
|
207
|
+
let state;
|
|
208
|
+
let sessionPath;
|
|
209
|
+
try {
|
|
210
|
+
const described = await deps.provisioner.describe(memory.sessionId);
|
|
211
|
+
state = described.state;
|
|
212
|
+
sessionPath = described.workspacePath;
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
return '暂时无法确认旧会话的状态,请稍后重试。';
|
|
216
|
+
}
|
|
217
|
+
if (deps.store.get(key) !== binding || deps.store.group(groupId) !== group)
|
|
218
|
+
return '成员信息已变化,请刷新后重试。';
|
|
219
|
+
if (['bound', 'blank'].includes(state) && sessionPath === workspacePath)
|
|
220
|
+
return undefined;
|
|
221
|
+
// Unusable in this group: forget the candidate before the move so nothing is bound.
|
|
222
|
+
await deps.store.forgetSession(key, groupId);
|
|
223
|
+
if (deps.store.get(key)?.groupId !== binding.groupId)
|
|
224
|
+
return '成员信息已变化,请刷新后重试。';
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
/** Apply settings-page edits; the first failing op stops the rest. */
|
|
178
228
|
export async function applyStoreOps(deps, ops) {
|
|
229
|
+
await deps.store.load();
|
|
230
|
+
const initialBindings = new Map(deps.store.bindings().map(binding => [bindingKey(binding.kind, binding.id), binding]));
|
|
231
|
+
const initialAdmins = new Set(deps.store.settings().adminUserIds);
|
|
179
232
|
let changed = 0;
|
|
180
233
|
let settingsChanged = false;
|
|
181
234
|
let createdGroupId;
|
|
182
|
-
|
|
235
|
+
let failure;
|
|
236
|
+
/** Newly authorized principals, keyed by binding key (a later move replaces this). */
|
|
237
|
+
const authorized = new Map();
|
|
238
|
+
/** Principals whose group changed, keyed the same way so one batch notifies once. */
|
|
239
|
+
const assigned = new Map();
|
|
240
|
+
/** Administrators this batch added; a person already on the list is not promoted again. */
|
|
241
|
+
const promotedAdmins = new Set();
|
|
183
242
|
// A model edit is only worth accepting against the real catalog; read it
|
|
184
243
|
// once when the page has never asked for it on this process yet.
|
|
185
|
-
const touchesModel = ops.some(op => op.op === 'group.update'
|
|
186
|
-
&& (op.patch.provider !== undefined || op.patch.model !== undefined));
|
|
244
|
+
const touchesModel = ops.some(op => op.op === 'member.model' || (op.op === 'group.update'
|
|
245
|
+
&& (op.patch.provider !== undefined || op.patch.model !== undefined)));
|
|
187
246
|
if (touchesModel && !deps.models.snapshot()) {
|
|
188
247
|
try {
|
|
189
248
|
await deps.models.load();
|
|
@@ -205,175 +264,310 @@ export async function applyStoreOps(deps, ops) {
|
|
|
205
264
|
}
|
|
206
265
|
const modelChanged = new Set();
|
|
207
266
|
for (const op of ops.slice(0, 200)) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
createdGroupId = created.id;
|
|
216
|
-
changed++;
|
|
217
|
-
}
|
|
218
|
-
catch (error) {
|
|
219
|
-
return { ok: false, error: `无法新增分组:${error instanceof Error ? error.message : String(error)}`, changed };
|
|
220
|
-
}
|
|
221
|
-
break;
|
|
222
|
-
}
|
|
223
|
-
case 'group.update': {
|
|
224
|
-
const group = deps.store.group(op.id);
|
|
225
|
-
if (!group)
|
|
226
|
-
return { ok: false, error: `分组不存在:${op.id}`, changed };
|
|
227
|
-
const patch = op.patch;
|
|
228
|
-
if (patch.workspace !== undefined && patch.workspace.trim()) {
|
|
267
|
+
try {
|
|
268
|
+
switch (op.op) {
|
|
269
|
+
case 'group.add': {
|
|
270
|
+
if (deps.store.groups().length >= MAX_GROUPS) {
|
|
271
|
+
failure = `最多只能有 ${MAX_GROUPS} 个分组。`;
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
229
274
|
try {
|
|
230
|
-
await deps.
|
|
275
|
+
const created = await deps.store.createGroup(op.name);
|
|
276
|
+
createdGroupId = created.id;
|
|
277
|
+
changed++;
|
|
231
278
|
}
|
|
232
279
|
catch (error) {
|
|
233
|
-
|
|
280
|
+
failure = `无法新增分组:${error instanceof Error ? error.message : String(error)}`;
|
|
234
281
|
}
|
|
282
|
+
break;
|
|
235
283
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
284
|
+
case 'group.update': {
|
|
285
|
+
const group = deps.store.group(op.id);
|
|
286
|
+
if (!group) {
|
|
287
|
+
failure = `分组不存在:${op.id}`;
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
const patch = op.patch;
|
|
291
|
+
const fields = new Set(['name', 'workspace', 'provider', 'model', 'reasoningEffort', 'preset']);
|
|
292
|
+
if (Object.entries(patch).some(([key, value]) => !fields.has(key) || typeof value !== 'string')) {
|
|
293
|
+
failure = '分组设置只能包含名称、Workspace、模型、effort 与 preset,且必须是文本。';
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
if (patch.workspace !== undefined && patch.workspace.trim()) {
|
|
297
|
+
try {
|
|
298
|
+
await deps.workspaces.resolve(patch.workspace);
|
|
299
|
+
}
|
|
300
|
+
catch (error) {
|
|
301
|
+
failure = error instanceof Error ? error.message : String(error);
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
const nextProvider = (patch.provider ?? group.provider).trim();
|
|
306
|
+
const nextModel = (patch.model ?? group.model).trim();
|
|
307
|
+
if (Boolean(nextProvider) !== Boolean(nextModel)) {
|
|
308
|
+
failure = '请同时选择服务商与模型,或都留空以跟随 DSH 默认模型。';
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
if (nextProvider && nextModel && !deps.models.known({ provider: nextProvider, model: nextModel })) {
|
|
312
|
+
failure = `DSH 当前没有模型 ${nextProvider}/${nextModel},请重新选择。`;
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
const nextPreset = (patch.preset ?? group.preset).trim();
|
|
316
|
+
// Without a preset service there is nothing to validate against.
|
|
317
|
+
if (nextPreset && deps.presets && !deps.presets.known(nextPreset)) {
|
|
318
|
+
failure = `DSH 当前没有 preset ${nextPreset},请重新选择。`;
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
const updated = await deps.store.updateGroup(op.id, patch);
|
|
322
|
+
if (!updated) {
|
|
323
|
+
failure = `分组不存在:${op.id}`;
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
changed++;
|
|
327
|
+
if (patch.provider !== undefined || patch.model !== undefined || patch.reasoningEffort !== undefined) {
|
|
328
|
+
modelChanged.add(op.id);
|
|
329
|
+
}
|
|
330
|
+
// A group's Workspace defines where its Sessions live, so moving the
|
|
331
|
+
// group must not leave members pointing at Sessions of the old one.
|
|
332
|
+
if (updated.workspace !== group.workspace) {
|
|
333
|
+
for (const member of deps.store.inGroup(op.id)) {
|
|
334
|
+
// Replace even an empty row: provisioning may currently be creating
|
|
335
|
+
// its first Session in the old Workspace and must fail its CAS.
|
|
336
|
+
await deps.store.update(bindingKey(member.kind, member.id), { sessionId: '' });
|
|
337
|
+
changed++;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
break;
|
|
248
341
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
342
|
+
case 'group.delete': {
|
|
343
|
+
if (op.id === DEFAULT_GROUP_ID) {
|
|
344
|
+
failure = '默认分组不能删除。';
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
const result = await deps.store.removeGroup(op.id);
|
|
348
|
+
if (!result.ok) {
|
|
349
|
+
failure = `分组不存在:${op.id}`;
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
changed += 1 + result.removed;
|
|
353
|
+
break;
|
|
255
354
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
355
|
+
case 'member.add': {
|
|
356
|
+
const id = typeof op.id === 'string' ? op.id.trim() : '';
|
|
357
|
+
if ((op.kind !== 'user' && op.kind !== 'group') || !validBindingId(id)) {
|
|
358
|
+
failure = '需要有效的企微 userid(个人)或 chatid(群聊)。';
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
if (!deps.store.group(op.groupId)) {
|
|
362
|
+
failure = `分组不存在:${op.groupId}`;
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
try {
|
|
366
|
+
const previous = deps.store.get(bindingKey(op.kind, id));
|
|
367
|
+
if (previous && previous.groupId !== op.groupId) {
|
|
368
|
+
const restoreError = await prepareRestore(deps, bindingKey(op.kind, id), previous, op.groupId);
|
|
369
|
+
if (restoreError) {
|
|
370
|
+
failure = restoreError;
|
|
371
|
+
break;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
await deps.store.create(op.kind, id, {
|
|
375
|
+
groupId: op.groupId, ...(op.label === undefined ? {} : { label: op.label }),
|
|
376
|
+
});
|
|
263
377
|
changed++;
|
|
264
378
|
}
|
|
379
|
+
catch (error) {
|
|
380
|
+
failure = `无法加入分组:${error instanceof Error ? error.message : String(error)}`;
|
|
381
|
+
}
|
|
382
|
+
break;
|
|
265
383
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
384
|
+
case 'member.update': {
|
|
385
|
+
const parsed = parseBindingKey(op.key);
|
|
386
|
+
if (!parsed) {
|
|
387
|
+
failure = `无法识别的成员 id:${op.key}`;
|
|
388
|
+
break;
|
|
389
|
+
}
|
|
390
|
+
const key = bindingKey(parsed.kind, parsed.id);
|
|
391
|
+
const existing = deps.store.get(key);
|
|
392
|
+
if (!existing) {
|
|
393
|
+
failure = `成员不存在:${op.key}`;
|
|
394
|
+
break;
|
|
395
|
+
}
|
|
396
|
+
if (Object.entries(op.patch).some(([key, value]) => !['groupId', 'sessionId'].includes(key) || typeof value !== 'string')) {
|
|
397
|
+
failure = '成员设置只能包含文本形式的分组或会话 ID。';
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
if (op.patch.groupId !== undefined && !deps.store.group(op.patch.groupId)) {
|
|
401
|
+
failure = `分组不存在:${op.patch.groupId}`;
|
|
402
|
+
break;
|
|
403
|
+
}
|
|
404
|
+
if (op.patch.groupId !== undefined && op.patch.groupId !== existing.groupId) {
|
|
405
|
+
const restoreError = await prepareRestore(deps, key, existing, op.patch.groupId);
|
|
406
|
+
if (restoreError) {
|
|
407
|
+
failure = restoreError;
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
const updated = await deps.store.update(key, op.patch);
|
|
412
|
+
if (!updated) {
|
|
413
|
+
failure = `成员不存在:${op.key}`;
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
287
416
|
changed++;
|
|
417
|
+
break;
|
|
288
418
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
419
|
+
case 'member.model': {
|
|
420
|
+
const parsed = parseBindingKey(op.key);
|
|
421
|
+
if (!parsed) {
|
|
422
|
+
failure = `无法识别的成员 id:${op.key}`;
|
|
423
|
+
break;
|
|
424
|
+
}
|
|
425
|
+
const key = bindingKey(parsed.kind, parsed.id);
|
|
426
|
+
const binding = deps.store.get(key);
|
|
427
|
+
if (!binding || !binding.sessionId || binding.sessionId !== op.sessionId) {
|
|
428
|
+
failure = '成员的绑定会话已变化,请刷新后重试。';
|
|
429
|
+
break;
|
|
430
|
+
}
|
|
431
|
+
const raw = op.selection;
|
|
432
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)
|
|
433
|
+
|| Object.entries(raw).some(([key, value]) => !['provider', 'model', 'reasoningEffort'].includes(key) || typeof value !== 'string')
|
|
434
|
+
|| !raw.provider?.trim() || !raw.model?.trim()) {
|
|
435
|
+
failure = '请选择有效的服务商、模型与 effort。';
|
|
436
|
+
break;
|
|
437
|
+
}
|
|
438
|
+
const selection = {
|
|
439
|
+
provider: raw.provider.trim(), model: raw.model.trim(),
|
|
440
|
+
...(raw.reasoningEffort?.trim() ? { reasoningEffort: raw.reasoningEffort.trim() } : {}),
|
|
441
|
+
};
|
|
442
|
+
const catalog = deps.models.snapshot();
|
|
443
|
+
const choice = catalog?.choices.find(item => item.provider === selection.provider && item.model === selection.model);
|
|
444
|
+
if (!choice || !deps.models.known(selection)) {
|
|
445
|
+
failure = 'DSH 当前没有这个模型,请重新选择。';
|
|
446
|
+
break;
|
|
447
|
+
}
|
|
448
|
+
if (selection.reasoningEffort && !choice.efforts?.some(item => item.id === selection.reasoningEffort)) {
|
|
449
|
+
failure = '这个模型不支持所选的 effort,请重新选择。';
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
const described = await deps.provisioner.describe(binding.sessionId);
|
|
453
|
+
if (!['bound', 'blank'].includes(described.state)) {
|
|
454
|
+
failure = '绑定的会话已不可用,请先发送消息创建新会话。';
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
457
|
+
if (deps.store.get(key) !== binding) {
|
|
458
|
+
failure = '成员的绑定会话已变化,请刷新后重试。';
|
|
459
|
+
break;
|
|
460
|
+
}
|
|
461
|
+
const selected = await deps.provisioner.applyModel(binding.sessionId, selection);
|
|
462
|
+
const updated = await deps.store.update(key, { sessionSelection: selected }, binding);
|
|
463
|
+
if (!updated) {
|
|
464
|
+
failure = '成员的绑定会话已变化,模型未保存到新绑定,请刷新后重试。';
|
|
465
|
+
break;
|
|
466
|
+
}
|
|
467
|
+
deps.catalogs.invalidate?.();
|
|
468
|
+
changed++;
|
|
469
|
+
break;
|
|
319
470
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
471
|
+
case 'label.set': {
|
|
472
|
+
const parsed = parseBindingKey(op.key);
|
|
473
|
+
if (!parsed) {
|
|
474
|
+
failure = `无法识别的人员 id:${op.key}`;
|
|
475
|
+
break;
|
|
476
|
+
}
|
|
477
|
+
const key = bindingKey(parsed.kind, parsed.id);
|
|
478
|
+
if (typeof op.label !== 'string') {
|
|
479
|
+
failure = '备注必须是文本。';
|
|
480
|
+
break;
|
|
481
|
+
}
|
|
482
|
+
if (op.label.trim() && !normalizeLabel(op.label)) {
|
|
483
|
+
failure = '备注只能是单行文本。';
|
|
484
|
+
break;
|
|
485
|
+
}
|
|
486
|
+
await deps.store.setLabel(key, op.label);
|
|
487
|
+
changed++;
|
|
488
|
+
break;
|
|
338
489
|
}
|
|
339
|
-
|
|
340
|
-
|
|
490
|
+
case 'member.archive': {
|
|
491
|
+
const parsed = parseBindingKey(op.key);
|
|
492
|
+
if (!parsed) {
|
|
493
|
+
failure = `无法识别的成员 id:${op.key}`;
|
|
494
|
+
break;
|
|
495
|
+
}
|
|
496
|
+
const key = bindingKey(parsed.kind, parsed.id);
|
|
497
|
+
const binding = deps.store.get(key);
|
|
498
|
+
if (!binding) {
|
|
499
|
+
failure = `成员不存在:${op.key}`;
|
|
500
|
+
break;
|
|
501
|
+
}
|
|
502
|
+
if (!binding.sessionId) {
|
|
503
|
+
failure = '这个成员还没有会话可以归档。';
|
|
504
|
+
break;
|
|
505
|
+
}
|
|
506
|
+
if (!deps.ops) {
|
|
507
|
+
failure = '当前 DSH 不支持归档会话。';
|
|
508
|
+
break;
|
|
509
|
+
}
|
|
510
|
+
try {
|
|
511
|
+
await deps.ops.archive(binding.sessionId);
|
|
512
|
+
}
|
|
513
|
+
catch (error) {
|
|
514
|
+
failure = error instanceof Error ? error.message : String(error);
|
|
515
|
+
break;
|
|
516
|
+
}
|
|
517
|
+
// Clearing the binding is what makes the next message create a fresh
|
|
518
|
+
// Session from the group's current Workspace/model/preset.
|
|
519
|
+
await deps.store.update(key, { sessionId: '' });
|
|
520
|
+
changed++;
|
|
521
|
+
break;
|
|
341
522
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
changed++;
|
|
356
|
-
break;
|
|
357
|
-
}
|
|
358
|
-
case 'settings.set': {
|
|
359
|
-
if (!op.patch || typeof op.patch !== 'object')
|
|
360
|
-
return { ok: false, error: '设置内容不正确。', changed };
|
|
361
|
-
const validated = validateSettingsPatch(op.patch);
|
|
362
|
-
if (typeof validated === 'string')
|
|
363
|
-
return { ok: false, error: validated, changed };
|
|
364
|
-
try {
|
|
365
|
-
await deps.store.setSettings(validated);
|
|
523
|
+
case 'member.remove': {
|
|
524
|
+
const parsed = parseBindingKey(op.key);
|
|
525
|
+
if (!parsed) {
|
|
526
|
+
failure = `无法识别的成员 id:${op.key}`;
|
|
527
|
+
break;
|
|
528
|
+
}
|
|
529
|
+
const removed = await deps.store.remove(bindingKey(parsed.kind, parsed.id));
|
|
530
|
+
if (!removed) {
|
|
531
|
+
failure = `成员不存在:${op.key}`;
|
|
532
|
+
break;
|
|
533
|
+
}
|
|
534
|
+
changed++;
|
|
535
|
+
break;
|
|
366
536
|
}
|
|
367
|
-
|
|
368
|
-
|
|
537
|
+
case 'settings.set': {
|
|
538
|
+
if (!op.patch || typeof op.patch !== 'object') {
|
|
539
|
+
failure = '设置内容不正确。';
|
|
540
|
+
break;
|
|
541
|
+
}
|
|
542
|
+
const validated = validateSettingsPatch(op.patch);
|
|
543
|
+
if (typeof validated === 'string') {
|
|
544
|
+
failure = validated;
|
|
545
|
+
break;
|
|
546
|
+
}
|
|
547
|
+
try {
|
|
548
|
+
await deps.store.setSettings(validated);
|
|
549
|
+
}
|
|
550
|
+
catch (error) {
|
|
551
|
+
failure = `无法保存设置:${error instanceof Error ? error.message : String(error)}`;
|
|
552
|
+
break;
|
|
553
|
+
}
|
|
554
|
+
settingsChanged = true;
|
|
555
|
+
changed++;
|
|
556
|
+
break;
|
|
369
557
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
558
|
+
default:
|
|
559
|
+
failure = '未知的修改类型。';
|
|
560
|
+
break;
|
|
373
561
|
}
|
|
374
|
-
default:
|
|
375
|
-
return { ok: false, error: '未知的修改类型。', changed };
|
|
376
562
|
}
|
|
563
|
+
catch (error) {
|
|
564
|
+
failure = `无法应用修改:${error instanceof Error ? error.message : String(error)}`;
|
|
565
|
+
}
|
|
566
|
+
// Earlier ops stay applied even when this one failed; the result reports
|
|
567
|
+
// both, so the runtime can adopt the settings and notify the people they
|
|
568
|
+
// authorized before the failure. Only the rest of the batch is skipped.
|
|
569
|
+
if (failure)
|
|
570
|
+
break;
|
|
377
571
|
}
|
|
378
572
|
// A group's model applies to every Session it already owns.
|
|
379
573
|
for (const id of modelChanged) {
|
|
@@ -384,11 +578,30 @@ export async function applyStoreOps(deps, ops) {
|
|
|
384
578
|
deps.log?.warn(`WeCom could not apply the group model: ${error instanceof Error ? error.message : String(error)}`);
|
|
385
579
|
}
|
|
386
580
|
}
|
|
581
|
+
// Notifications describe the final effective assignment, not transient
|
|
582
|
+
// states within a batch (including a successful prefix of a failed batch).
|
|
583
|
+
for (const binding of deps.store.bindings()) {
|
|
584
|
+
const key = bindingKey(binding.kind, binding.id);
|
|
585
|
+
const previous = initialBindings.get(key);
|
|
586
|
+
const entry = { kind: binding.kind, id: binding.id, groupId: binding.groupId };
|
|
587
|
+
if (!previous)
|
|
588
|
+
authorized.set(key, entry);
|
|
589
|
+
else if (previous.groupId !== binding.groupId)
|
|
590
|
+
assigned.set(key, { ...entry, previousGroupId: previous.groupId });
|
|
591
|
+
}
|
|
592
|
+
for (const id of deps.store.settings().adminUserIds)
|
|
593
|
+
if (!initialAdmins.has(id))
|
|
594
|
+
promotedAdmins.add(id);
|
|
595
|
+
const assignedList = [...assigned.values()];
|
|
387
596
|
return {
|
|
388
|
-
ok:
|
|
597
|
+
ok: failure === undefined,
|
|
598
|
+
...(failure ? { error: failure } : {}),
|
|
599
|
+
changed,
|
|
389
600
|
...(settingsChanged ? { settingsChanged } : {}),
|
|
390
601
|
...(createdGroupId ? { createdGroupId } : {}),
|
|
391
|
-
...(authorized.
|
|
602
|
+
...(authorized.size ? { authorized: [...authorized.values()] } : {}),
|
|
603
|
+
...(assignedList.length ? { assigned: assignedList } : {}),
|
|
604
|
+
...(promotedAdmins.size ? { promotedAdmins: [...promotedAdmins] } : {}),
|
|
392
605
|
};
|
|
393
606
|
}
|
|
394
607
|
//# sourceMappingURL=groups-view.js.map
|