dsh-cyber-im-avatar 0.18.2 → 0.19.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 +26 -12
- package/lib/app.js +48 -1
- package/lib/client.js +263 -8
- package/lib/client.template.js +71 -0
- package/lib/duty.js +8 -0
- package/lib/index.js +97 -19
- package/lib/state.js +34 -2
- package/lib/turns.js +157 -26
- package/lib/workspaces.js +29 -0
- package/package.json +5 -2
- package/skill/SKILL.md +19 -3
- package/skill/references/troubleshooting.md +2 -1
- package/web/panel.js +192 -8
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
| 层 | 干什么 |
|
|
9
9
|
| --- | --- |
|
|
10
|
-
| 壳(本插件) | 按节奏拉取(耳朵)、命中唤醒绑定 DSH
|
|
10
|
+
| 壳(本插件) | 按节奏拉取(耳朵)、命中唤醒绑定 DSH 会话(嘴)、消息展示 / 发送方式 / 手动发送(脸) |
|
|
11
11
|
| skill | 闭环协议、平台差异、铁律、故障自愈 |
|
|
12
12
|
| agent 会话 | 被唤醒后全权处理:自己调 IM CLI 拉上下文、调研、起草、发送 |
|
|
13
13
|
|
|
@@ -172,7 +172,9 @@ agent 在这一轮里自己用 `lark-cli` 拉上下文、去绑定工作区核
|
|
|
172
172
|
写入初始 `policy.md`(缺/空才补,已有内容不覆盖)。每次判断**新建会话、无历史**,agent 只写
|
|
173
173
|
`decisions/<event_id>.json`,插件校验后执行。`trial_hours=0` 默认关(严格两段式);
|
|
174
174
|
`session_max_turns` 保留为兼容键但不再生效;`max_group_members=10`(0=不限)只数人;自动路径在起分诊会话前先查人数,超过/未知
|
|
175
|
-
直接 ignore,不花 token
|
|
175
|
+
直接 ignore,不花 token;手动可强制。判定为 watch / trial 后,首个值班会话沿用
|
|
176
|
+
「加入值守时绑定工作区」的默认(`config.join_workspace` → 最近在用 → DSH 默认),
|
|
177
|
+
与手动加入一致,之后轮换 / 重开沿用该绑定。
|
|
176
178
|
`GET /api/duty` 看候选,`POST /api/duty/triage` 手动重判。详细契约见
|
|
177
179
|
`docs/specs/contracts/01-api.md`、`02-storage.md`、`03-config.md`。
|
|
178
180
|
|
|
@@ -248,17 +250,17 @@ agent 在这一轮里自己用 `lark-cli` 拉上下文、去绑定工作区核
|
|
|
248
250
|
| 页签 | 内容 |
|
|
249
251
|
| --- | --- |
|
|
250
252
|
| 关注 | agent 写的每日摘要 `~/.im-standin/digest/YYYY-MM-DD.md` 原文;可切日期,超一天没更新会提示 |
|
|
251
|
-
| 分身 |
|
|
253
|
+
| 分身 | 值守中的实例:发送方式开关、工作区、DSH 会话、轮数、处理中状态、**去会话**、重开会话、屏蔽;上面是搜人/搜群与手动加入 |
|
|
252
254
|
| 服务对象 | 分「群聊 / 人物」两段:群聊=群的会话工作本(直接读、直接改),单聊没有工作本;人物=人物档案(列表、编辑、删除、从平台搜人新建),单聊的记忆就是这一份;不展示历史消息 |
|
|
253
255
|
| 体检 | 轮询节奏与范围、授权状态、DSH 运行时、skill 路径、最近事件、最近错误 |
|
|
254
|
-
| 设置 |
|
|
256
|
+
| 设置 | 新建值守默认发送方式、值守节奏(值守秒数 + 发现分钟 + 私聊取前 N 个 + 立即拉一轮)、值守范围 |
|
|
255
257
|
|
|
256
258
|
从分身卡片的「打开」或搜人 / 搜群结果进**会话详情**:最近 30 条消息、记忆文件摘要(单聊是
|
|
257
259
|
人物档案条;群是工作本 + 本群人物)与手动发送;收件箱页已去掉(spec 0032),消息在飞书 / 钉钉里本来就能看。
|
|
258
260
|
|
|
259
261
|
**去会话**:实例卡与会话详情头部的「去会话」直接调 DSH 客户端的
|
|
260
262
|
`uiWorkspace.openSession(sessionId)`(侧边栏点会话用的同一条路),把主界面切到
|
|
261
|
-
绑定的那个 DSH 会话——看 agent
|
|
263
|
+
绑定的那个 DSH 会话——看 agent 怎么调研、按当前发送方式处理,都在那边。
|
|
262
264
|
停靠态会顺手在目标会话的右侧栏补开值守面板,左边看会话、右边看面板;
|
|
263
265
|
老版本 DSH 没有这个服务时,退回复制会话 id,不假装跳成功。
|
|
264
266
|
|
|
@@ -267,16 +269,24 @@ agent 在这一轮里自己用 `lark-cli` 拉上下文、去绑定工作区核
|
|
|
267
269
|
不用等下一条新消息就能让它处理积压(只取最新 10 条)。agent 回复会由下一轮
|
|
268
270
|
拉取以「我」的消息出现,不需要面板再起草。
|
|
269
271
|
|
|
270
|
-
##
|
|
272
|
+
## 发送方式:每个值班单点,默认只管新建
|
|
271
273
|
|
|
272
|
-
|
|
274
|
+
发送方式是**值班单点配置**,写进 `state.json` 的 `chats[].send_mode`,不再靠会话里的口头约定:
|
|
273
275
|
|
|
274
|
-
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
-
|
|
276
|
+
- **每张值守卡片 / 会话详情**各有一个「草稿审批 / 全自动」开关。草稿审批把正文留在
|
|
277
|
+
DSH 会话、末尾标「草稿待确认」,你说「发」才发;全自动对「该回的消息」直接以你的身份
|
|
278
|
+
发出,不再逐条确认。同一轮都不会反问「要不要发」。
|
|
279
|
+
- **设置页只配「新建值守默认发送方式」**(`config.send_mode_default`)。新值班首次加入
|
|
280
|
+
值守时复制它;之后改默认不会覆盖已有值班。仓库默认 `draft`,你可以把自己的默认改成 `auto`。
|
|
281
|
+
- 两种模式都只改变发送动作,不改变唤醒范围;钱、合同、对外承诺、权限/凭据、外部群一律
|
|
282
|
+
停下等你确认(skill 铁律),任何模式都不替你承诺。
|
|
283
|
+
- 发送方式与关注程度只随首轮 / 开场与**切换后的第一轮**载荷声明;同一 DSH 会话里
|
|
284
|
+
没变的轮次不再复读,以会话里最后一次声明为准;会话被压缩后下一轮会重新声明一次。
|
|
285
|
+
切换对下一轮生效;正在跑的那一轮按原设置收尾。切到全自动需要二次确认,随时可切回。
|
|
286
|
+
- 面板里的手动发送永远可用,且不经过模型——手打的就是你本人。
|
|
278
287
|
|
|
279
|
-
|
|
288
|
+
> 升级迁移:存量已值守会话按旧全局值 / 当前默认补成显式值;未值守会话保持未设置,
|
|
289
|
+
> 首次加入值守时再取默认。未发布时的全局 `send_mode` 会自动迁成 `send_mode_default`。
|
|
280
290
|
|
|
281
291
|
## 在 DSH 里长什么样
|
|
282
292
|
|
|
@@ -308,6 +318,10 @@ agent 在这一轮里自己用 `lark-cli` 拉上下文、去绑定工作区核
|
|
|
308
318
|
所有「加入值守」入口都会带工作区,默认取「上次在面板里选过的」→「现有会话最近在用的」
|
|
309
319
|
→ DSH 默认,不用每次重选:
|
|
310
320
|
|
|
321
|
+
- **自动分诊同样跟随**:分诊判定 `watch` / `trial` 后,插件按同一默认(`config.join_workspace`
|
|
322
|
+
→ 最近在用 → DSH 默认)给新值班落 `chats[].workspace` 再开会话,不是一律回 DSH 默认;
|
|
323
|
+
已有显式绑定的群不覆盖。页面上的选择会同步到 `config.join_workspace`,刷新后仍是同一个默认。
|
|
324
|
+
|
|
311
325
|
- 下拉列表来自 DSH 自己的登记表(`~/.dsh/storages/workspace.json`),默认项标「默认」;
|
|
312
326
|
「跟随 DSH 默认」表示不显式绑定。
|
|
313
327
|
- 会话详情里的工作区行**常显**:还没值守也能先选,打开值守时一起生效。
|
package/lib/app.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* 这里不再有 Python 进程/SQLite;所有读写在 state.json + profiles/*.md,
|
|
5
5
|
* 在线正文走平台 CLI。
|
|
6
6
|
*/
|
|
7
|
-
import { publicConfig, normalizeConfig, SUPPORTED_PLATFORMS } from "./state.js";
|
|
7
|
+
import { publicConfig, normalizeConfig, SUPPORTED_PLATFORMS, SEND_MODES } from "./state.js";
|
|
8
8
|
import { isMention } from "./im.js";
|
|
9
9
|
import * as workspaces from "./workspaces.js";
|
|
10
10
|
import * as sessions from "./sessions.js";
|
|
@@ -50,6 +50,7 @@ export const POST_ROUTES = {
|
|
|
50
50
|
"/api/persons/profile": "personProfile",
|
|
51
51
|
"/api/chat/session/reset": "chatSessionReset",
|
|
52
52
|
"/api/chat/wake": "chatWake",
|
|
53
|
+
"/api/chat/send-mode": "chatSendMode",
|
|
53
54
|
"/api/duty/triage": "dutyTriage",
|
|
54
55
|
};
|
|
55
56
|
|
|
@@ -128,6 +129,17 @@ export class App {
|
|
|
128
129
|
this.im?.identity?.[platform]?.self_id || "";
|
|
129
130
|
}
|
|
130
131
|
|
|
132
|
+
/** 新建值守的默认发送方式;单点值存在 chats[].send_mode。 */
|
|
133
|
+
defaultSendMode() {
|
|
134
|
+
const v = this.state.data.config.send_mode_default;
|
|
135
|
+
return SEND_MODES.includes(v) ? v : "draft";
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** 首次成为值守时把默认值固化成显式值;之后改默认不会覆盖它。 */
|
|
139
|
+
applySendDefault(chat) {
|
|
140
|
+
if (chat && !chat.send_mode) chat.send_mode = this.defaultSendMode();
|
|
141
|
+
}
|
|
142
|
+
|
|
131
143
|
publicChat(chat) {
|
|
132
144
|
if (!chat) return null;
|
|
133
145
|
const out = { ...chat };
|
|
@@ -140,6 +152,8 @@ export class App {
|
|
|
140
152
|
out.last_wake_at = Number(chat.last_wake_at) || 0;
|
|
141
153
|
out.blocked = !!chat.blocked;
|
|
142
154
|
out.watching = !!chat.watching;
|
|
155
|
+
// 面板看的是实际生效值:未值守或老数据没有单点值时跟随新建默认。
|
|
156
|
+
out.send_mode = chat.send_mode || this.defaultSendMode();
|
|
143
157
|
out.pending = this.state.pendingCount(chat);
|
|
144
158
|
out.turn_state = ti.state;
|
|
145
159
|
out.last_ok = ti.last_ok;
|
|
@@ -375,6 +389,7 @@ export class App {
|
|
|
375
389
|
? this.turns.busy(platform, chatId)
|
|
376
390
|
: !!(typeof this.turns.isActive === "function" && this.turns.isActive(platform, chatId));
|
|
377
391
|
if (busy) return { ok: true, skipped: "running" };
|
|
392
|
+
this.applySendDefault(chat);
|
|
378
393
|
try {
|
|
379
394
|
await this.poller.pollChat(platform, chatId, {
|
|
380
395
|
name: chat.name, kind: chat.kind, force: true, wake: false,
|
|
@@ -417,6 +432,7 @@ export class App {
|
|
|
417
432
|
if (watching) {
|
|
418
433
|
if (Number(chat.timer) !== 1) chat.timer = 1;
|
|
419
434
|
if (chat.kind === "group" && chat.wake_mode !== "all") chat.wake_mode = "mention";
|
|
435
|
+
this.applySendDefault(chat);
|
|
420
436
|
}
|
|
421
437
|
// 加入值守即视为启用该平台:钉钉默认不开,避免没装 dws 的用户每轮白跑一次 whoami。
|
|
422
438
|
if (watching) {
|
|
@@ -523,6 +539,7 @@ export class App {
|
|
|
523
539
|
chat.wake_mode = mode === "all" ? "all" : "mention";
|
|
524
540
|
if (chat.wake_mode !== "all") chat.last_wake_at = 0;
|
|
525
541
|
chat.target = true;
|
|
542
|
+
this.applySendDefault(chat);
|
|
526
543
|
const enabled = this.state.data.config.platforms || [];
|
|
527
544
|
if (!enabled.includes(platform)) {
|
|
528
545
|
this.state.data.config.platforms =
|
|
@@ -543,6 +560,25 @@ export class App {
|
|
|
543
560
|
return { ok: true, chat: this.publicChat(chat), open, poll: this.poller.pollInfo() };
|
|
544
561
|
}
|
|
545
562
|
|
|
563
|
+
/** 值班单点发送方式:只改这一通会话,之后改全局默认也不会覆盖它。 */
|
|
564
|
+
async chatSendMode(q, body = {}) {
|
|
565
|
+
const platform = pick(q, body, "platform");
|
|
566
|
+
const chatId = pick(q, body, "chat_id");
|
|
567
|
+
const mode = String(pick(q, body, "mode") || "");
|
|
568
|
+
if (!platform || !chatId) return { ok: false, reason: "bad_request" };
|
|
569
|
+
if (!SEND_MODES.includes(mode)) {
|
|
570
|
+
return { ok: false, reason: "mode 必须是 draft / auto" };
|
|
571
|
+
}
|
|
572
|
+
if (!this.supported(platform)) return this.unsupported(platform);
|
|
573
|
+
const r = this.state.setChatSendMode(platform, chatId, mode);
|
|
574
|
+
if (!r.ok) return r;
|
|
575
|
+
this.state.save();
|
|
576
|
+
return {
|
|
577
|
+
ok: true, send_mode: r.chat.send_mode,
|
|
578
|
+
chat: this.publicChat(r.chat),
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
|
|
546
582
|
async chatTimer(q, body = {}) {
|
|
547
583
|
const platform = pick(q, body, "platform");
|
|
548
584
|
const chatId = pick(q, body, "chat_id");
|
|
@@ -661,6 +697,17 @@ export class App {
|
|
|
661
697
|
merged[k] = { ...(this.state.data.config[k] || {}), ...body[k] };
|
|
662
698
|
}
|
|
663
699
|
}
|
|
700
|
+
// 加入值守默认工作区:非空必须是真实存在的绝对路径,否则整次保存拒绝,不写坏值。
|
|
701
|
+
if (body && Object.prototype.hasOwnProperty.call(body, "join_workspace")) {
|
|
702
|
+
const raw = String(body.join_workspace || "").trim();
|
|
703
|
+
if (raw) {
|
|
704
|
+
const ws = workspaces.normalize(raw);
|
|
705
|
+
if (!ws) return { ok: false, reason: "工作区不存在或不是绝对路径:" + raw };
|
|
706
|
+
merged.join_workspace = ws;
|
|
707
|
+
} else {
|
|
708
|
+
merged.join_workspace = "";
|
|
709
|
+
}
|
|
710
|
+
}
|
|
664
711
|
const ignored = Array.isArray(body?.platforms)
|
|
665
712
|
? body.platforms.filter((p) => !SUPPORTED_PLATFORMS.includes(String(p)))
|
|
666
713
|
: [];
|
package/lib/client.js
CHANGED
|
@@ -201,6 +201,15 @@ window.__ModuleLoader__.load({
|
|
|
201
201
|
"font-size:12px;cursor:pointer;white-space:nowrap;min-width:0}",
|
|
202
202
|
".ims-seg-btn:hover{color:var(--fg);border-color:var(--line2)}",
|
|
203
203
|
".ims-seg-btn.on{border-color:var(--accent);color:var(--accent);background:color-mix(in srgb,var(--accent) 9%,transparent);font-weight:600}",
|
|
204
|
+
/* 发送方式:全局两段开关;自动档用 warn 色,和「已屏蔽/异常」区分开但仍醒目 */
|
|
205
|
+
".ims-mode{display:inline-flex;align-items:center;gap:2px;padding:2px;border:1px solid var(--line2);",
|
|
206
|
+
"border-radius:999px;background:var(--bg);flex:none}",
|
|
207
|
+
".ims-mode-btn{appearance:none;border:0;background:transparent;color:var(--fg3);font:inherit;",
|
|
208
|
+
"font-size:11.5px;line-height:1.4;padding:3px 9px;border-radius:999px;cursor:pointer;white-space:nowrap}",
|
|
209
|
+
".ims-mode-btn:hover{color:var(--fg)}",
|
|
210
|
+
".ims-mode-btn.on{background:var(--sunk);color:var(--fg);font-weight:620}",
|
|
211
|
+
".ims-mode-btn.on.auto{background:color-mix(in srgb,var(--warn) 14%,transparent);color:var(--warn)}",
|
|
212
|
+
".ims-mode-btn:focus-visible{outline:2px solid var(--blue);outline-offset:1px}",
|
|
204
213
|
".ims-pchip{padding:2px 9px;border-radius:999px;border:1px solid var(--line);background:var(--bg);color:var(--fg2);",
|
|
205
214
|
"font-size:11px;cursor:pointer;white-space:nowrap;max-width:22ch;overflow:hidden;text-overflow:ellipsis}",
|
|
206
215
|
".ims-pchip:hover{color:var(--fg);border-color:var(--line2)}",
|
|
@@ -378,6 +387,11 @@ window.__ModuleLoader__.load({
|
|
|
378
387
|
try { if (window.localStorage) window.localStorage.setItem(WS_MEM_KEY, v); }
|
|
379
388
|
catch (e) { /* ignore */ }
|
|
380
389
|
}
|
|
390
|
+
/** 显式选择「跟随 DSH 默认」时清掉本机记忆,避免下次加载又把它当默认值。 */
|
|
391
|
+
function clearWsMemory() {
|
|
392
|
+
try { if (window.localStorage) window.localStorage.removeItem(WS_MEM_KEY); }
|
|
393
|
+
catch (e) { /* ignore */ }
|
|
394
|
+
}
|
|
381
395
|
|
|
382
396
|
/**
|
|
383
397
|
* 右侧栏面板:只以停靠形态存在。宿主给一块高度,面板铺满;
|
|
@@ -433,6 +447,145 @@ window.__ModuleLoader__.load({
|
|
|
433
447
|
toastTimer = setTimeout(function () { toast.classList.remove("show"); }, 2600);
|
|
434
448
|
}
|
|
435
449
|
|
|
450
|
+
// ---- 发送方式:值班单点配置;全局只提供「新建值守默认」 ----
|
|
451
|
+
function defaultSendModeValue() {
|
|
452
|
+
return ((S.cfg || {}).send_mode_default === "auto") ? "auto" : "draft";
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
function chatSendModeValue(chat) {
|
|
456
|
+
if (chat && (chat.send_mode === "auto" || chat.send_mode === "draft")) {
|
|
457
|
+
return chat.send_mode;
|
|
458
|
+
}
|
|
459
|
+
return defaultSendModeValue();
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
function sendModeLabel(mode) {
|
|
463
|
+
return mode === "auto" ? "全自动" : "草稿审批";
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
function chatSendModeHint(chat) {
|
|
467
|
+
return chatSendModeValue(chat) === "auto"
|
|
468
|
+
? "这通值班直接发,不再逐条问你"
|
|
469
|
+
: "这通值班留草稿,等你说「发」";
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
function defaultSendModeHint() {
|
|
473
|
+
return defaultSendModeValue() === "auto"
|
|
474
|
+
? "之后新加入值守的会话默认直接发"
|
|
475
|
+
: "之后新加入值守的会话默认留草稿";
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
function applyChatSendMode(chat, next) {
|
|
479
|
+
var cur = chatSendModeValue(chat);
|
|
480
|
+
if (next !== "auto" && next !== "draft") return;
|
|
481
|
+
if (chat.send_mode === next) return;
|
|
482
|
+
if (next === "auto") {
|
|
483
|
+
var ok = typeof window === "undefined" || !window.confirm ||
|
|
484
|
+
window.confirm("把这通值班切成全自动?\n\n" +
|
|
485
|
+
"之后「" + (chat.name || "这个会话") + "」里 agent 认为该回的消息会直接以你的身份发出," +
|
|
486
|
+
"不再逐条确认。\n正在处理的那一轮按原设置跑完;切换对下一轮生效。\n" +
|
|
487
|
+
"涉及钱、合同、对外承诺、权限/凭据或外部群的,仍会停下等你确认。");
|
|
488
|
+
if (!ok) return;
|
|
489
|
+
}
|
|
490
|
+
api("/api/chat/send-mode", { body: {
|
|
491
|
+
platform: chat.platform, chat_id: chat.chat_id, mode: next,
|
|
492
|
+
} }).then(function (r) {
|
|
493
|
+
if (!r || r.ok === false) {
|
|
494
|
+
say("没保存:" + ((r && r.reason) || "本地服务没响应"));
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
chat.send_mode = r.send_mode || next;
|
|
498
|
+
var hit = chatOf(chat.platform, chat.chat_id);
|
|
499
|
+
if (hit) hit.send_mode = chat.send_mode;
|
|
500
|
+
if (S.detail && S.detail.chat &&
|
|
501
|
+
S.detail.chat.platform === chat.platform && S.detail.chat.chat_id === chat.chat_id) {
|
|
502
|
+
S.detail.chat.send_mode = chat.send_mode;
|
|
503
|
+
}
|
|
504
|
+
say("已把「" + (chat.name || "这个会话") + "」切成" + sendModeLabel(chat.send_mode));
|
|
505
|
+
paint();
|
|
506
|
+
}).catch(function (e) {
|
|
507
|
+
say("没保存:" + shortReason(e));
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
function applyDefaultSendMode(next) {
|
|
512
|
+
if (next !== "auto" && next !== "draft") return;
|
|
513
|
+
if (next === defaultSendModeValue()) return;
|
|
514
|
+
if (next === "auto") {
|
|
515
|
+
var ok = typeof window === "undefined" || !window.confirm ||
|
|
516
|
+
window.confirm("之后新加入值守的会话默认全自动?\n\n" +
|
|
517
|
+
"只影响还没加入的值守;已有值班各自的设置不会被覆盖。\n" +
|
|
518
|
+
"涉及钱、合同、对外承诺、权限/凭据或外部群的,仍会停下等你确认。");
|
|
519
|
+
if (!ok) return;
|
|
520
|
+
}
|
|
521
|
+
api("/api/config", { body: { send_mode_default: next } }).then(function (c) {
|
|
522
|
+
if (!c || c.error) {
|
|
523
|
+
say("没保存:" + ((c && c.error) || "本地服务没响应"));
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
S.cfg = c;
|
|
527
|
+
if (S.status && S.status.config) S.status.config.send_mode_default = c.send_mode_default;
|
|
528
|
+
say(next === "auto" ? "已设为新值班默认全自动" : "已设为新值班默认草稿审批");
|
|
529
|
+
paint();
|
|
530
|
+
}).catch(function (e) {
|
|
531
|
+
say("没保存:" + shortReason(e));
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
function modeControl(cur, onPick) {
|
|
536
|
+
var wrap = h("span", { class: "ims-mode", role: "group", "aria-label": "发送方式" });
|
|
537
|
+
[["draft", "草稿审批"], ["auto", "全自动"]].forEach(function (d) {
|
|
538
|
+
wrap.appendChild(h("button", {
|
|
539
|
+
class: "ims-mode-btn" + (cur === d[0] ? " on" : "") + (d[0] === "auto" ? " auto" : ""),
|
|
540
|
+
type: "button",
|
|
541
|
+
"aria-pressed": cur === d[0] ? "true" : "false",
|
|
542
|
+
title: d[0] === "auto"
|
|
543
|
+
? "全自动:agent 直接以你的身份发出;敏感内容仍会停下等确认"
|
|
544
|
+
: "草稿审批:回复留在会话里,等你说「发」",
|
|
545
|
+
onclick: function () { onPick(d[0]); }
|
|
546
|
+
}, d[1]));
|
|
547
|
+
});
|
|
548
|
+
return wrap;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
function sendModeControl(chat) {
|
|
552
|
+
return modeControl(chatSendModeValue(chat), function (mode) {
|
|
553
|
+
applyChatSendMode(chat, mode);
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
function defaultSendModeControl() {
|
|
558
|
+
return modeControl(defaultSendModeValue(), applyDefaultSendMode);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
function sendDefaultCard() {
|
|
562
|
+
var mode = defaultSendModeValue();
|
|
563
|
+
return h("div", { class: "ims-card" },
|
|
564
|
+
h("div", { class: "ims-card-h" },
|
|
565
|
+
h("span", { class: "ims-ico", html: icon("send", 15) }),
|
|
566
|
+
"新建值守默认发送方式",
|
|
567
|
+
h("span", { class: "ims-grow" }),
|
|
568
|
+
h("span", { class: "ims-tag",
|
|
569
|
+
style: "color:" + (mode === "auto" ? "var(--warn)" : "var(--fg3)"),
|
|
570
|
+
text: sendModeLabel(mode) })),
|
|
571
|
+
h("div", { class: "ims-rowline" },
|
|
572
|
+
defaultSendModeControl(),
|
|
573
|
+
h("span", { class: "ims-hint", text: defaultSendModeHint() }),
|
|
574
|
+
h("span", { class: "ims-grow" })),
|
|
575
|
+
h("div", { class: "ims-hint",
|
|
576
|
+
text: "只决定之后新加入值守的会话;已有值班在「分身」卡片上各自设置," +
|
|
577
|
+
"改这里不会覆盖它们。" }),
|
|
578
|
+
h("div", { class: "ims-hint",
|
|
579
|
+
text: "钱、合同、对外承诺、权限/凭据、外部群在两种模式下都会停下等你确认。" }));
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
// 上一轮结束后的提示:按这通值班自己的发送方式切换文案。
|
|
583
|
+
function afterTurnHint(chat) {
|
|
584
|
+
return chatSendModeValue(chat) === "auto"
|
|
585
|
+
? "上一轮已完成;全自动模式下 agent 会自己发出,去会话能看到发送结果。"
|
|
586
|
+
: "上一轮已完成;如果 agent 把草稿留在会话里,去会话确认后发送。";
|
|
587
|
+
}
|
|
588
|
+
|
|
436
589
|
// 手动拉一轮:不受 10 分钟间隔限制,拉完再把结果说出来
|
|
437
590
|
function syncNow(btn) {
|
|
438
591
|
var t0 = Date.now();
|
|
@@ -651,8 +804,12 @@ window.__ModuleLoader__.load({
|
|
|
651
804
|
S.chats = d.items || [];
|
|
652
805
|
S.chatsLoaded = true;
|
|
653
806
|
clearConnError("chats");
|
|
654
|
-
//
|
|
655
|
-
if (!S.
|
|
807
|
+
// 默认工作区以配置为准;本机升级前只有 localStorage 记忆时补一次同步。
|
|
808
|
+
if (!S.addWsPicked) {
|
|
809
|
+
var memWs = S.addWs || readWsMemory();
|
|
810
|
+
S.addWs = ((S.cfg && S.cfg.join_workspace) || lastUsedWs() || "");
|
|
811
|
+
if (memWs && !(S.cfg || {}).join_workspace) saveJoinWorkspace(memWs);
|
|
812
|
+
}
|
|
656
813
|
refreshFoot();
|
|
657
814
|
if (S.tab === "service") paintBody();
|
|
658
815
|
}).catch(function (e) {
|
|
@@ -807,7 +964,8 @@ window.__ModuleLoader__.load({
|
|
|
807
964
|
}
|
|
808
965
|
return h("div", { class: "ims-head" },
|
|
809
966
|
h("div", { style: "min-width:0" },
|
|
810
|
-
h("div", { class: "ims-title" },
|
|
967
|
+
h("div", { class: "ims-title" },
|
|
968
|
+
h("span", { class: "ims-dot", style: "background:" + dotColor }), "IM 值守"),
|
|
811
969
|
h("div", { class: "ims-sub", text: sub })),
|
|
812
970
|
h("span", { class: "ims-grow" }),
|
|
813
971
|
h("button", {
|
|
@@ -931,15 +1089,27 @@ window.__ModuleLoader__.load({
|
|
|
931
1089
|
return best;
|
|
932
1090
|
}
|
|
933
1091
|
|
|
934
|
-
/** 新加入值守时的默认工作区:面板记忆 → 最近在用 → DSH 默认。 */
|
|
1092
|
+
/** 新加入值守时的默认工作区:面板记忆 → 配置的加入默认 → 最近在用 → DSH 默认。 */
|
|
935
1093
|
function joinWorkspace() {
|
|
936
|
-
|
|
1094
|
+
var cfgWs = (S.cfg && S.cfg.join_workspace) || "";
|
|
1095
|
+
return S.addWs || cfgWs || lastUsedWs() || S.defaultWs || "";
|
|
937
1096
|
}
|
|
938
1097
|
|
|
939
1098
|
function rememberWs(v) {
|
|
940
1099
|
if (!v) return;
|
|
941
1100
|
S.addWs = v;
|
|
942
1101
|
writeWsMemory(v);
|
|
1102
|
+
saveJoinWorkspace(v);
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
/** 把「加入值守时绑定工作区」的选择同步到后端配置:自动分诊开值班时按它落工作区。 */
|
|
1106
|
+
function saveJoinWorkspace(v) {
|
|
1107
|
+
var val = String(v || "").trim();
|
|
1108
|
+
if (((S.cfg || {}).join_workspace || "") === val) return Promise.resolve(null);
|
|
1109
|
+
return api("/api/config", { body: { join_workspace: val } }).then(function (c) {
|
|
1110
|
+
if (c && !c.error) S.cfg = c;
|
|
1111
|
+
return c;
|
|
1112
|
+
}).catch(function () { return null; });
|
|
943
1113
|
}
|
|
944
1114
|
|
|
945
1115
|
/** 展示用:显式绑定优先,否则说明「跟随 DSH 默认」。 */
|
|
@@ -1276,6 +1446,11 @@ window.__ModuleLoader__.load({
|
|
|
1276
1446
|
text: (chat.session_turns || 0) + " 轮" }),
|
|
1277
1447
|
h("span", { class: "ims-grow" }),
|
|
1278
1448
|
newSessionBtn(d)));
|
|
1449
|
+
wrap.appendChild(h("div", { class: "ims-rowline", style: "padding:0 var(--pad) 6px" },
|
|
1450
|
+
h("span", { class: "ims-hint", text: "发送方式" }),
|
|
1451
|
+
sendModeControl(chat),
|
|
1452
|
+
h("span", { class: "ims-hint", text: chatSendModeHint(chat) }),
|
|
1453
|
+
h("span", { class: "ims-grow" })));
|
|
1279
1454
|
if (chat.last_warm_at || (chat.last_reset && chat.last_reset.at)) {
|
|
1280
1455
|
wrap.appendChild(h("div", { class: "ims-hint", style: "padding:0 var(--pad) 6px",
|
|
1281
1456
|
text: [
|
|
@@ -1297,7 +1472,7 @@ window.__ModuleLoader__.load({
|
|
|
1297
1472
|
text: "上一轮失败:" + (chat.last_reason || "未知原因") + ";下一轮有新消息会再喊。" }));
|
|
1298
1473
|
} else if ((chat.pending || 0) > 0 && sid) {
|
|
1299
1474
|
wrap.appendChild(h("div", { class: "ims-hint", style: "padding:0 var(--pad) 6px",
|
|
1300
|
-
text:
|
|
1475
|
+
text: afterTurnHint(chat) }));
|
|
1301
1476
|
}
|
|
1302
1477
|
}
|
|
1303
1478
|
|
|
@@ -1657,7 +1832,7 @@ window.__ModuleLoader__.load({
|
|
|
1657
1832
|
: (c.last_ok === false
|
|
1658
1833
|
? h("div", { class: "ims-hint ims-err", text: "上一轮失败:" + (c.last_reason || "未知原因") + ";下一轮有新消息会再喊。" })
|
|
1659
1834
|
: ((c.pending || 0) > 0 && c.dsh_session
|
|
1660
|
-
? h("div", { class: "ims-hint", text:
|
|
1835
|
+
? h("div", { class: "ims-hint", text: afterTurnHint(c) })
|
|
1661
1836
|
: null)),
|
|
1662
1837
|
prof ? h("div", { class: "ims-note" },
|
|
1663
1838
|
h("span", { class: "ims-ico", html: icon("note", 13) }),
|
|
@@ -1665,6 +1840,11 @@ window.__ModuleLoader__.load({
|
|
|
1665
1840
|
: h("div", { class: "ims-hint", text: c.kind === "group"
|
|
1666
1841
|
? "还没有会话工作本,去「服务对象 · 群聊」补一份;agent 起草时会按它对齐本群要求"
|
|
1667
1842
|
: "人物档案还是空的,去「服务对象 · 人物」写一份;单聊只有这一份记忆" }),
|
|
1843
|
+
h("div", { class: "ims-rowline" },
|
|
1844
|
+
h("span", { class: "ims-hint", text: "发送" }),
|
|
1845
|
+
sendModeControl(c),
|
|
1846
|
+
h("span", { class: "ims-hint", text: chatSendModeHint(c) }),
|
|
1847
|
+
h("span", { class: "ims-grow" })),
|
|
1668
1848
|
h("div", { class: "ims-rowline" },
|
|
1669
1849
|
modeSelect(c),
|
|
1670
1850
|
h("span", { class: "ims-grow" }),
|
|
@@ -1885,6 +2065,7 @@ window.__ModuleLoader__.load({
|
|
|
1885
2065
|
h("span", { class: "ims-hint", text: "加入值守时绑定工作区" }),
|
|
1886
2066
|
wsOptions(joinWorkspace(), function (v) {
|
|
1887
2067
|
S.addWs = v; S.addWsPicked = true; rememberWs(v);
|
|
2068
|
+
if (!v) { clearWsMemory(); saveJoinWorkspace(""); } // 显式「跟随 DSH 默认」要清干净
|
|
1888
2069
|
}, true)),
|
|
1889
2070
|
result,
|
|
1890
2071
|
wcForm,
|
|
@@ -2689,6 +2870,9 @@ window.__ModuleLoader__.load({
|
|
|
2689
2870
|
var st = S.status || {};
|
|
2690
2871
|
var scroll = h("div", { class: "ims-scroll" });
|
|
2691
2872
|
|
|
2873
|
+
// 新建值守的默认发送方式;单点值在各自的「分身」卡片上
|
|
2874
|
+
scroll.appendChild(sendDefaultCard());
|
|
2875
|
+
|
|
2692
2876
|
// 值守会话:模型/网关/凭据全部由 DSH 自己解析,插件不再有第二份配置
|
|
2693
2877
|
var resolved = cfg.resolved || {};
|
|
2694
2878
|
scroll.appendChild(h("div", { class: "ims-card" },
|
|
@@ -2746,7 +2930,7 @@ window.__ModuleLoader__.load({
|
|
|
2746
2930
|
});
|
|
2747
2931
|
}
|
|
2748
2932
|
}, (cfg.dsh || {}).ack_reaction === false ? "开启回执" : "关闭回执")),
|
|
2749
|
-
h("div", { class: "ims-hint", text: "命中值守会话的新消息 → 在绑定的 DSH 会话里跑一轮 agent,由它自己调 IM CLI
|
|
2933
|
+
h("div", { class: "ims-hint", text: "命中值守会话的新消息 → 在绑定的 DSH 会话里跑一轮 agent,由它自己调 IM CLI、查工作区、起草与发送。插件只负责拉取、唤醒、展示与发送方式设置。" })));
|
|
2750
2934
|
|
|
2751
2935
|
// 值守节奏:快车道(值守会话,秒级)+ 慢车道(发现新会话,分钟级)
|
|
2752
2936
|
var pcfg = cfg.poll || {};
|
|
@@ -3241,7 +3425,78 @@ window.__ModuleLoader__.load({
|
|
|
3241
3425
|
* immediately. The right-sidebar services are requested dynamically; if
|
|
3242
3426
|
* they never arrive the plugin stays as a seat that reports unavailable.
|
|
3243
3427
|
*/
|
|
3428
|
+
/**
|
|
3429
|
+
* 启动诊断(临时):把客户端半看到的这次启动写回宿主 `logs/client-boot.jsonl`。
|
|
3430
|
+
* 回答三件事:本插件那一行在不在页面拿到的 boot 图里、模块系统记了什么导入错误、
|
|
3431
|
+
* Loader 里各 entry 的 fiber 状态。
|
|
3432
|
+
*/
|
|
3433
|
+
function reportBoot(ctx) {
|
|
3434
|
+
const ID = "dsh-cyber-im-avatar";
|
|
3435
|
+
const read = (fn, fallback) => { try { return fn(); } catch (e) { return fallback; } };
|
|
3436
|
+
try {
|
|
3437
|
+
const boot = window.__DSH_BOOT__ || {};
|
|
3438
|
+
const rows = Array.isArray(boot.entries) ? boot.entries : [];
|
|
3439
|
+
const row = rows.find((r) => r.id === ID) || null;
|
|
3440
|
+
const loader = read(() => ctx && ctx.loader, null)
|
|
3441
|
+
|| read(() => ctx && ctx.root && ctx.root.loader, null)
|
|
3442
|
+
|| read(() => ctx && typeof ctx.get === "function" ? ctx.get("loader") : null, null)
|
|
3443
|
+
|| read(() => ctx && ctx.root && typeof ctx.root.get === "function" ? ctx.root.get("loader") : null, null);
|
|
3444
|
+
const modules = read(() => (loader && loader.internal)
|
|
3445
|
+
|| (ctx && (ctx.modules || (ctx.root && ctx.root.modules)))
|
|
3446
|
+
|| null, null);
|
|
3447
|
+
const entries = read(() => ctx && ctx.loader
|
|
3448
|
+
? [...ctx.loader.entries()].map((e) => ({
|
|
3449
|
+
name: e.options.name,
|
|
3450
|
+
fiber: !!e.fiber,
|
|
3451
|
+
state: e.fiber ? e.fiber.state : null
|
|
3452
|
+
}))
|
|
3453
|
+
: null, "unreadable");
|
|
3454
|
+
const snapshot = read(() => modules && modules.entries && modules.entries.state
|
|
3455
|
+
? modules.entries.state.getSnapshot() : null, "unreadable");
|
|
3456
|
+
const importError = read(() => {
|
|
3457
|
+
if (!modules || typeof modules.importError !== "function") return "no-api";
|
|
3458
|
+
const err = modules.importError(ID);
|
|
3459
|
+
return err ? String(err.message || err) : null;
|
|
3460
|
+
}, "unreadable");
|
|
3461
|
+
const has = (map) => read(() => !!(map && typeof map.has === "function" && map.has(ID)), "unreadable");
|
|
3462
|
+
const api = window.IM_STANDIN_API || "/plugins/im-standin";
|
|
3463
|
+
const token = window.IM_STANDIN_TOKEN || "";
|
|
3464
|
+
fetch(api + "/api/debug/boot", {
|
|
3465
|
+
method: "POST",
|
|
3466
|
+
headers: { "content-type": "application/json", "x-im-token": token },
|
|
3467
|
+
body: JSON.stringify({
|
|
3468
|
+
t: Math.round(performance.now()),
|
|
3469
|
+
ready: document.readyState,
|
|
3470
|
+
hasBoot: !!boot.entries,
|
|
3471
|
+
bootRev: boot.rev,
|
|
3472
|
+
bootRows: rows.length,
|
|
3473
|
+
hasRow: !!row,
|
|
3474
|
+
row: row && {
|
|
3475
|
+
url: row.url,
|
|
3476
|
+
rev: row.rev,
|
|
3477
|
+
immediately: row.immediately === true,
|
|
3478
|
+
inject: row.inject || []
|
|
3479
|
+
},
|
|
3480
|
+
modules: {
|
|
3481
|
+
hasLoader: !!loader,
|
|
3482
|
+
hasInternal: !!(loader && loader.internal),
|
|
3483
|
+
hasModules: !!modules,
|
|
3484
|
+
importError,
|
|
3485
|
+
hasFactory: has(modules && modules.factories),
|
|
3486
|
+
hasLoadCache: has(modules && modules.loadCache),
|
|
3487
|
+
graphRow: has(modules && modules.graphRows),
|
|
3488
|
+
entryFailures: snapshot && Array.isArray(snapshot.failures)
|
|
3489
|
+
? snapshot.failures.filter((f) => f && f.id === ID) : snapshot
|
|
3490
|
+
},
|
|
3491
|
+
entries: entries
|
|
3492
|
+
}),
|
|
3493
|
+
keepalive: true
|
|
3494
|
+
}).catch(() => {});
|
|
3495
|
+
} catch (e) { /* 诊断失败不影响主流程 */ }
|
|
3496
|
+
}
|
|
3497
|
+
|
|
3244
3498
|
function apply(ctx) {
|
|
3499
|
+
reportBoot(ctx);
|
|
3245
3500
|
if (window.IMStandinPanel) window.IMStandinPanel.openSession = makeJump(ctx);
|
|
3246
3501
|
|
|
3247
3502
|
mountSeatUI(ctx);
|
package/lib/client.template.js
CHANGED
|
@@ -180,7 +180,78 @@ window.__ModuleLoader__.load({
|
|
|
180
180
|
* immediately. The right-sidebar services are requested dynamically; if
|
|
181
181
|
* they never arrive the plugin stays as a seat that reports unavailable.
|
|
182
182
|
*/
|
|
183
|
+
/**
|
|
184
|
+
* 启动诊断(临时):把客户端半看到的这次启动写回宿主 `logs/client-boot.jsonl`。
|
|
185
|
+
* 回答三件事:本插件那一行在不在页面拿到的 boot 图里、模块系统记了什么导入错误、
|
|
186
|
+
* Loader 里各 entry 的 fiber 状态。
|
|
187
|
+
*/
|
|
188
|
+
function reportBoot(ctx) {
|
|
189
|
+
const ID = "dsh-cyber-im-avatar";
|
|
190
|
+
const read = (fn, fallback) => { try { return fn(); } catch (e) { return fallback; } };
|
|
191
|
+
try {
|
|
192
|
+
const boot = window.__DSH_BOOT__ || {};
|
|
193
|
+
const rows = Array.isArray(boot.entries) ? boot.entries : [];
|
|
194
|
+
const row = rows.find((r) => r.id === ID) || null;
|
|
195
|
+
const loader = read(() => ctx && ctx.loader, null)
|
|
196
|
+
|| read(() => ctx && ctx.root && ctx.root.loader, null)
|
|
197
|
+
|| read(() => ctx && typeof ctx.get === "function" ? ctx.get("loader") : null, null)
|
|
198
|
+
|| read(() => ctx && ctx.root && typeof ctx.root.get === "function" ? ctx.root.get("loader") : null, null);
|
|
199
|
+
const modules = read(() => (loader && loader.internal)
|
|
200
|
+
|| (ctx && (ctx.modules || (ctx.root && ctx.root.modules)))
|
|
201
|
+
|| null, null);
|
|
202
|
+
const entries = read(() => ctx && ctx.loader
|
|
203
|
+
? [...ctx.loader.entries()].map((e) => ({
|
|
204
|
+
name: e.options.name,
|
|
205
|
+
fiber: !!e.fiber,
|
|
206
|
+
state: e.fiber ? e.fiber.state : null
|
|
207
|
+
}))
|
|
208
|
+
: null, "unreadable");
|
|
209
|
+
const snapshot = read(() => modules && modules.entries && modules.entries.state
|
|
210
|
+
? modules.entries.state.getSnapshot() : null, "unreadable");
|
|
211
|
+
const importError = read(() => {
|
|
212
|
+
if (!modules || typeof modules.importError !== "function") return "no-api";
|
|
213
|
+
const err = modules.importError(ID);
|
|
214
|
+
return err ? String(err.message || err) : null;
|
|
215
|
+
}, "unreadable");
|
|
216
|
+
const has = (map) => read(() => !!(map && typeof map.has === "function" && map.has(ID)), "unreadable");
|
|
217
|
+
const api = window.IM_STANDIN_API || "/plugins/im-standin";
|
|
218
|
+
const token = window.IM_STANDIN_TOKEN || "";
|
|
219
|
+
fetch(api + "/api/debug/boot", {
|
|
220
|
+
method: "POST",
|
|
221
|
+
headers: { "content-type": "application/json", "x-im-token": token },
|
|
222
|
+
body: JSON.stringify({
|
|
223
|
+
t: Math.round(performance.now()),
|
|
224
|
+
ready: document.readyState,
|
|
225
|
+
hasBoot: !!boot.entries,
|
|
226
|
+
bootRev: boot.rev,
|
|
227
|
+
bootRows: rows.length,
|
|
228
|
+
hasRow: !!row,
|
|
229
|
+
row: row && {
|
|
230
|
+
url: row.url,
|
|
231
|
+
rev: row.rev,
|
|
232
|
+
immediately: row.immediately === true,
|
|
233
|
+
inject: row.inject || []
|
|
234
|
+
},
|
|
235
|
+
modules: {
|
|
236
|
+
hasLoader: !!loader,
|
|
237
|
+
hasInternal: !!(loader && loader.internal),
|
|
238
|
+
hasModules: !!modules,
|
|
239
|
+
importError,
|
|
240
|
+
hasFactory: has(modules && modules.factories),
|
|
241
|
+
hasLoadCache: has(modules && modules.loadCache),
|
|
242
|
+
graphRow: has(modules && modules.graphRows),
|
|
243
|
+
entryFailures: snapshot && Array.isArray(snapshot.failures)
|
|
244
|
+
? snapshot.failures.filter((f) => f && f.id === ID) : snapshot
|
|
245
|
+
},
|
|
246
|
+
entries: entries
|
|
247
|
+
}),
|
|
248
|
+
keepalive: true
|
|
249
|
+
}).catch(() => {});
|
|
250
|
+
} catch (e) { /* 诊断失败不影响主流程 */ }
|
|
251
|
+
}
|
|
252
|
+
|
|
183
253
|
function apply(ctx) {
|
|
254
|
+
reportBoot(ctx);
|
|
184
255
|
if (window.IMStandinPanel) window.IMStandinPanel.openSession = makeJump(ctx);
|
|
185
256
|
|
|
186
257
|
mountSeatUI(ctx);
|