@suifei/dsh-ai-team 0.4.119 → 0.4.121
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/CHANGELOG.md +26 -1
- package/client.js +316 -20
- package/index.js +43 -5
- package/lib/domain/rich-message.js +94 -0
- package/lib/host/attachment-routes.js +88 -0
- package/lib/host/service.js +10 -2
- package/lib/host/waker.js +26 -1
- package/lib/ledger/fold.js +4 -0
- package/lib/runtime/host-session-gate.js +9 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## 0.4.
|
|
3
|
+
## 0.4.121 - 2026-11-17
|
|
4
|
+
|
|
5
|
+
**主对话支持图片、文件与 @成员;文渊阁对话框与 DSH 标准会话同一套**(#65)
|
|
6
|
+
|
|
7
|
+
- #65:文渊阁对话框不能贴图、拖文件,@ 也点不到具体成员;DSH 标准会话(「文渊阁·PMO」)输入框能贴图,
|
|
8
|
+
但 0.4.119 转发时只取文字,图片和文件丢了;
|
|
9
|
+
- 一份实现 `lib/domain/rich-message.js`:附件只收 DSH 附件存储的持久引用(与官方 ImageBlock / FileBlock 同形),
|
|
10
|
+
@成员按花名册长名优先识别;
|
|
11
|
+
- 账本:`stream.post` 可带 `attachments`,只有附件没有文字也能发;Human 消息记下 `mentions`;
|
|
12
|
+
- 唤醒:Human 的话照常交给项目负责人,被 @ 的成员另行唤醒(`human_mention`);两边都把图片/文件块带进成员会话;
|
|
13
|
+
- DSH 标准会话:Human 在宿主会话里贴的图片、文件随文字一起转进主对话;
|
|
14
|
+
- 文渊阁对话框:粘贴、拖入或点回形针添加图片/文件,选中即上传进 DSH 附件存储(`POST /ai-team/api/attachments`,
|
|
15
|
+
图片走宿主的格式与尺寸校验,文件原样保存);输入 @ 弹出成员列表(方向键选择,Enter/Tab 插入);
|
|
16
|
+
主对话里显示缩略图(点开看原图)与可下载的文件条(`GET /ai-team/api/attachments/content`,只按账本里记下的引用读);
|
|
17
|
+
- 测试:`test/rich-message.test.js`、`test/client-composer-rich.test.js`,`test/host-session-gate.test.js` 补附件转发。
|
|
18
|
+
|
|
19
|
+
## 0.4.120 - 2026-11-17
|
|
20
|
+
|
|
21
|
+
**输入框随内容长高、可拖大;成员可一键复制**(#65 的前两项)
|
|
22
|
+
|
|
23
|
+
- #65:文渊阁主对话与任务回复的输入框只显示一两行,长文看不全也拉不大;想要两个「玄策」一起写代码只能手工重填一遍;
|
|
24
|
+
- 输入框:随内容自动长高,封顶为窗口高度的 45%(至少 160px),超出才出滚动条;可拖动右下角调高,
|
|
25
|
+
拖出来的高度记为下限,发送清空后仍保持(`fitTextarea` / `rememberTextareaDrag`,主对话与任务回复共用);
|
|
26
|
+
- 复制成员:成员资料里新增「复制成员」,按原成员预填新增表单——名字取「原名去尾部数字 + 最小未占用序号」(玄策 → 玄策2),
|
|
27
|
+
沿用角色、人格、运行配方、模型与推理档位、输出上限与技能;笔记、会话与任务不带(`copyMemberDraft`);
|
|
28
|
+
- 测试:`test/client-composer-copy.test.js`(长高与封顶、拖动下限、复制草稿与命名、界面接线)。
|
|
4
29
|
|
|
5
30
|
**在「文渊阁·PMO」会话里说话等于在文渊阁主对话里说话;宿主模型不再自己跑**
|
|
6
31
|
|
package/client.js
CHANGED
|
@@ -33,7 +33,14 @@ window.__ModuleLoader__.load({
|
|
|
33
33
|
boardTab: '看板',
|
|
34
34
|
tabSituation: '态势',
|
|
35
35
|
tabsAria: '项目视图',
|
|
36
|
-
composer: '写一条消息…',
|
|
36
|
+
composer: '写一条消息… @ 点名成员,可粘贴或拖入图片与文件',
|
|
37
|
+
attachAdd: '添加图片或文件',
|
|
38
|
+
attachRemove: '移除 {name}',
|
|
39
|
+
attachUploading: '附件还在上传,稍等再发送。',
|
|
40
|
+
attachFailed: '「{name}」上传失败:{message}',
|
|
41
|
+
attachDrop: '松开即可添加图片或文件',
|
|
42
|
+
attachTaskMode: '附件随讨论发送;建卡模式下不带附件。',
|
|
43
|
+
mentionList: '点名成员',
|
|
37
44
|
taskPlaceholder: '任务标题:要做什么',
|
|
38
45
|
taskDefinitionPlaceholder: '验收标准(必填):怎样算完成、拿什么证据',
|
|
39
46
|
taskDefinitionAria: 'Task 验收标准',
|
|
@@ -282,6 +289,8 @@ window.__ModuleLoader__.load({
|
|
|
282
289
|
memberNoModels: '该提供商暂无模型',
|
|
283
290
|
memberOwner: '设为 Project owner',
|
|
284
291
|
memberCreate: '创建并激活',
|
|
292
|
+
memberCopy: '复制成员',
|
|
293
|
+
memberCopyFrom: '复制自「{name}」:沿用角色、人格、运行配方、模型、输出上限与技能;笔记、会话与任务不带。',
|
|
285
294
|
memberAdding: '正在创建…',
|
|
286
295
|
memberAdded: '成员已创建并激活。',
|
|
287
296
|
cancel: '取消',
|
|
@@ -451,7 +460,14 @@ window.__ModuleLoader__.load({
|
|
|
451
460
|
boardTab: 'Board',
|
|
452
461
|
tabSituation: 'Situation',
|
|
453
462
|
tabsAria: 'Project views',
|
|
454
|
-
composer: 'Write a message…',
|
|
463
|
+
composer: 'Write a message… @ a member; paste or drop images and files',
|
|
464
|
+
attachAdd: 'Add images or files',
|
|
465
|
+
attachRemove: 'Remove {name}',
|
|
466
|
+
attachUploading: 'Attachments are still uploading; send again in a moment.',
|
|
467
|
+
attachFailed: 'Upload of “{name}” failed: {message}',
|
|
468
|
+
attachDrop: 'Drop to attach images or files',
|
|
469
|
+
attachTaskMode: 'Attachments go with discussion messages; task mode sends none.',
|
|
470
|
+
mentionList: 'Mention a member',
|
|
455
471
|
taskPlaceholder: 'Task title: what to do',
|
|
456
472
|
taskDefinitionPlaceholder: 'Definition of done (required): how it is accepted, with what evidence',
|
|
457
473
|
taskDefinitionAria: 'Definition of done',
|
|
@@ -701,6 +717,8 @@ window.__ModuleLoader__.load({
|
|
|
701
717
|
memberNoModels: 'No models for this provider',
|
|
702
718
|
memberOwner: 'Make Project owner',
|
|
703
719
|
memberCreate: 'Create and activate',
|
|
720
|
+
memberCopy: 'Duplicate member',
|
|
721
|
+
memberCopyFrom: 'Copy of “{name}”: keeps role, personality, recipe, model, output limit and skills; notes, session and tasks stay with the original.',
|
|
704
722
|
memberAdding: 'Creating…',
|
|
705
723
|
memberAdded: 'Member created and activated.',
|
|
706
724
|
cancel: 'Cancel',
|
|
@@ -1180,8 +1198,27 @@ window.__ModuleLoader__.load({
|
|
|
1180
1198
|
.at-box { min-width: 0; padding: 8px 9px; border: 1px solid var(--dsw-alias-border-l2); border-radius: var(--dsw-radius-md); background: var(--dsw-alias-bg-layer-2); }
|
|
1181
1199
|
.at-box:focus-within { border-color: var(--dsw-alias-state-business-primary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--dsw-alias-state-business-primary) 20%, transparent); }
|
|
1182
1200
|
.at-box.at-taskmode { border-color: color-mix(in srgb, var(--dsw-alias-state-business-primary) 20%, var(--dsw-alias-border-l2)); }
|
|
1183
|
-
.at-box textarea { display: block; width: 100%; min-height: 38px; max-height:
|
|
1201
|
+
.at-box textarea { display: block; width: 100%; box-sizing: border-box; min-height: 38px; max-height: 60vh; resize: vertical; padding: 2px; border: 0; background: transparent; color: var(--dsw-alias-label-primary); font: inherit; font-size: 13px; line-height: 21px; }
|
|
1184
1202
|
.at-barrow { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
|
|
1203
|
+
.at-box { position: relative; }
|
|
1204
|
+
.at-box.at-dropping { border-style: dashed; border-color: var(--dsw-alias-state-business-primary); }
|
|
1205
|
+
.at-drophint { position: absolute; inset: 0; z-index: 2; display: flex; align-items: center; justify-content: center; border-radius: inherit; background: color-mix(in srgb, var(--dsw-alias-bg-layer-2) 88%, transparent); color: var(--dsw-alias-label-secondary); font-size: 12px; pointer-events: none; }
|
|
1206
|
+
.at-mentions { position: absolute; left: 8px; bottom: calc(100% + 4px); z-index: 3; min-width: 180px; max-width: calc(100% - 16px); max-height: 240px; overflow-y: auto; margin: 0; padding: 4px; list-style: none; border: 1px solid var(--dsw-alias-border-l2); border-radius: var(--dsw-radius-md); background: var(--dsw-alias-bg-layer-2); box-shadow: 0 6px 20px rgba(0, 0, 0, .14); }
|
|
1207
|
+
.at-mention { display: flex; align-items: baseline; gap: 8px; padding: 5px 8px; border-radius: var(--dsw-radius-sm); font-size: 12px; cursor: pointer; }
|
|
1208
|
+
.at-mention span { min-width: 0; overflow: hidden; color: var(--dsw-alias-label-tertiary); text-overflow: ellipsis; white-space: nowrap; }
|
|
1209
|
+
.at-mention-on, .at-mention:hover { background: var(--dsw-alias-button-ghost-active-fill); }
|
|
1210
|
+
.at-attachrow, .at-msgfiles { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
|
|
1211
|
+
.at-attach, .at-msgfile { display: inline-flex; align-items: center; gap: 6px; max-width: 240px; min-height: 28px; padding: 3px 6px; border: 1px solid var(--dsw-alias-border-l2); border-radius: var(--dsw-radius-sm); background: var(--dsw-alias-bg-base); color: var(--dsw-alias-label-secondary); font-size: 11px; text-decoration: none; }
|
|
1212
|
+
.at-attach img { width: 28px; height: 28px; object-fit: cover; border-radius: 3px; }
|
|
1213
|
+
.at-attach-busy { opacity: .6; }
|
|
1214
|
+
.at-attach-error { border-color: var(--dsw-alias-state-danger-primary, #d33); }
|
|
1215
|
+
.at-attachname { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1216
|
+
.at-attachsize { flex: 0 0 auto; color: var(--dsw-alias-label-caption); }
|
|
1217
|
+
.at-attachx { flex: 0 0 auto; padding: 0 2px; border: 0; background: transparent; color: var(--dsw-alias-label-tertiary); font: inherit; font-size: 14px; line-height: 1; cursor: pointer; }
|
|
1218
|
+
.at-attachbtn { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 24px; padding: 0; border: 1px solid var(--dsw-alias-border-l2); border-radius: var(--dsw-radius-sm); background: transparent; color: var(--dsw-alias-label-tertiary); cursor: pointer; }
|
|
1219
|
+
.at-attachbtn:hover { color: var(--dsw-alias-label-primary); }
|
|
1220
|
+
.at-msgimg { display: block; line-height: 0; }
|
|
1221
|
+
.at-msgimg img { max-width: min(320px, 100%); max-height: 240px; width: auto; height: auto; border: 1px solid var(--dsw-alias-border-l2); border-radius: var(--dsw-radius-sm); object-fit: contain; background: var(--dsw-alias-bg-base); }
|
|
1185
1222
|
.at-mode { display: inline-flex; overflow: hidden; border: 1px solid var(--dsw-alias-border-l2); border-radius: var(--dsw-radius-sm); }
|
|
1186
1223
|
.at-mode button { min-height: 24px; padding: 0 8px; border: 0; background: transparent; color: var(--dsw-alias-label-tertiary); font: inherit; font-size: 11px; line-height: 16px; cursor: pointer; }
|
|
1187
1224
|
.at-mode button[aria-pressed="true"] { background: var(--dsw-alias-button-ghost-active-fill); color: var(--dsw-alias-label-primary); }
|
|
@@ -1421,6 +1458,8 @@ window.__ModuleLoader__.load({
|
|
|
1421
1458
|
if (name === 'inbox') return h('svg', common, h('path', { d: 'M2.5 9.5h3l1 1.5h3l1-1.5h3' }), h('path', { d: 'M2.5 9.5V4.5a1 1 0 0 1 1-1h9a1 1 0 0 1 1 1v5' }));
|
|
1422
1459
|
if (name === 'board') return h('svg', common, h('rect', { x: 2.5, y: 3.5, width: 11, height: 9, rx: 1.5 }), h('path', { d: 'M6 3.5v9M10 3.5v9' }));
|
|
1423
1460
|
if (name === 'plus') return h('svg', common, h('path', { d: 'M8 3v10M3 8h10' }));
|
|
1461
|
+
if (name === 'clip') return h('svg', common, h('path', { d: 'M10.5 5.5 6 10a1.4 1.4 0 0 0 2 2l5-5a2.8 2.8 0 0 0-4-4L4 8a4.2 4.2 0 0 0 6 6l3.5-3.5' }));
|
|
1462
|
+
if (name === 'file') return h('svg', common, h('path', { d: 'M4 2.5h5l3 3v8H4Z' }), h('path', { d: 'M9 2.5v3h3' }));
|
|
1424
1463
|
if (name === 'menu') return h('svg', common, h('path', { d: 'M3 4.5h10M3 8h10M3 11.5h10' }));
|
|
1425
1464
|
if (name === 'bell') return h('svg', common, h('path', { d: 'M4.5 7a3.5 3.5 0 0 1 7 0v3l1 1.5h-9L4.5 10V7Z' }), h('path', { d: 'M6.5 13a1.5 1.5 0 0 0 3 0' }));
|
|
1426
1465
|
if (name === 'bellOff') return h('svg', common, h('path', { d: 'M4.5 7a3.5 3.5 0 0 1 5.5-3' }), h('path', { d: 'M6.5 13a1.5 1.5 0 0 0 3 0' }), h('path', { d: 'M4.5 10l-1 1.5h9L11.5 10V8.5' }), h('path', { d: 'M3 3l10 10' }));
|
|
@@ -1586,10 +1625,23 @@ window.__ModuleLoader__.load({
|
|
|
1586
1625
|
agent && onChat ? h('button', { className: 'at-workspacebtn', type: 'button', title: t('routingHint'), onClick: () => onChat(agent) }, t('agentChat')) : null,
|
|
1587
1626
|
),
|
|
1588
1627
|
h('div', { className: 'at-msgt' }, item.body),
|
|
1628
|
+
Array.isArray(item.attachments) && item.attachments.length > 0 ? h(MessageAttachments, { item }) : null,
|
|
1589
1629
|
cards.length ? h(TaskGroup, { t, cards, tasks, selected, follows, onOpen, onToggleFollow }) : null,
|
|
1590
1630
|
));
|
|
1591
1631
|
}
|
|
1592
1632
|
|
|
1633
|
+
/** #65:主对话消息里的图片(缩略图,点开看原图)与文件(点击下载);按账本 seq + 序号读回。 */
|
|
1634
|
+
function MessageAttachments({ item }) {
|
|
1635
|
+
const src = (index) => '/ai-team/api/attachments/content?' + new URLSearchParams({ project: item.projectId ?? '', seq: String(item.seq), index: String(index) }).toString();
|
|
1636
|
+
return h('div', { className: 'at-msgfiles' }, item.attachments.map((block, index) => block.type === 'image'
|
|
1637
|
+
? h('a', { key: index, className: 'at-msgimg', href: src(index), target: '_blank', rel: 'noopener', title: block.attachment?.name ?? '' },
|
|
1638
|
+
h('img', { src: src(index), alt: block.attachment?.name ?? '', loading: 'lazy', width: block.attachment?.width, height: block.attachment?.height }))
|
|
1639
|
+
: h('a', { key: index, className: 'at-msgfile', href: src(index), download: block.attachment?.name ?? 'file' },
|
|
1640
|
+
h(Ico, { name: 'file' }),
|
|
1641
|
+
h('span', { className: 'at-attachname' }, block.attachment?.name ?? 'file'),
|
|
1642
|
+
h('span', { className: 'at-attachsize' }, fmtBytes(block.attachment?.bytes)))));
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1593
1645
|
function ToastStack({ t, toasts, onClose }) {
|
|
1594
1646
|
if (toasts.length === 0) return null;
|
|
1595
1647
|
return h('div', { className: 'at-toaststack', role: 'status', 'aria-live': 'polite' },
|
|
@@ -2257,6 +2309,7 @@ window.__ModuleLoader__.load({
|
|
|
2257
2309
|
count: entries.length,
|
|
2258
2310
|
tail: entries.length > 0 ? String(entries[entries.length - 1]?.seq ?? '') + '|' + task.status : task.status,
|
|
2259
2311
|
});
|
|
2312
|
+
useFitTextarea(replyRef, reply);
|
|
2260
2313
|
return h('aside', { className: 'at-right', role: 'complementary', 'aria-label': t('threadAria'), tabIndex: -1, ref: panelRef },
|
|
2261
2314
|
h('div', { className: 'at-rhead' },
|
|
2262
2315
|
h('div', { className: 'at-rh' },
|
|
@@ -2325,6 +2378,7 @@ window.__ModuleLoader__.load({
|
|
|
2325
2378
|
value: reply,
|
|
2326
2379
|
rows: 2,
|
|
2327
2380
|
ref: replyRef,
|
|
2381
|
+
onMouseUp: (event) => rememberTextareaDrag(event.currentTarget),
|
|
2328
2382
|
placeholder: t('reply'),
|
|
2329
2383
|
'aria-label': t('reply'),
|
|
2330
2384
|
onChange: (event) => onReplyChange(event.target.value),
|
|
@@ -2340,30 +2394,102 @@ window.__ModuleLoader__.load({
|
|
|
2340
2394
|
h('button', { className: 'at-send', type: 'button', disabled: !reply.trim(), onClick: onReplySend }, t('send'))))) : null);
|
|
2341
2395
|
}
|
|
2342
2396
|
|
|
2343
|
-
function Composer({ t, mode, draft, definition, qaChecklist, disabled, qaRequired, onQaRequired, onDefinition, onQaChecklist, onMode, onDraft, onSend, inputRef }) {
|
|
2397
|
+
function Composer({ t, mode, draft, definition, qaChecklist, disabled, qaRequired, onQaRequired, onDefinition, onQaChecklist, onMode, onDraft, onSend, inputRef, agents, attachments, onAttach, onRemoveAttachment }) {
|
|
2398
|
+
const pending = Array.isArray(attachments) ? attachments : [];
|
|
2399
|
+
const discuss = mode !== 'task';
|
|
2400
|
+
const ready = discuss && pending.some((item) => item.status === 'ready');
|
|
2401
|
+
const canSend = !disabled && (draft.trim() !== '' || ready)
|
|
2402
|
+
&& !(mode === 'task' && (!draft.trim() || !definition.trim() || (qaRequired && !qaChecklist.trim())));
|
|
2344
2403
|
const send = () => {
|
|
2345
|
-
if (!
|
|
2346
|
-
if (mode === 'task' && (!definition.trim() || (qaRequired && !qaChecklist.trim()))) return;
|
|
2404
|
+
if (!canSend) return;
|
|
2347
2405
|
onSend();
|
|
2348
2406
|
};
|
|
2407
|
+
const ownRef = React.useRef(null);
|
|
2408
|
+
const boxRef = inputRef ?? ownRef;
|
|
2409
|
+
const fileRef = React.useRef(null);
|
|
2410
|
+
const [mention, setMention] = React.useState(null);
|
|
2411
|
+
const [dragging, setDragging] = React.useState(false);
|
|
2412
|
+
useFitTextarea(boxRef, draft);
|
|
2413
|
+
const candidates = mention === null ? [] : mentionCandidates(agents, mention.query);
|
|
2414
|
+
const track = (el) => {
|
|
2415
|
+
const found = el ? mentionQuery(el.value, el.selectionStart ?? el.value.length) : null;
|
|
2416
|
+
setMention(found === null ? null : { ...found, caret: el.selectionStart ?? el.value.length, index: 0 });
|
|
2417
|
+
};
|
|
2418
|
+
const pick = (agent) => {
|
|
2419
|
+
if (mention === null || !agent) return;
|
|
2420
|
+
const next = applyMention(draft, mention.start, mention.caret, agent.name);
|
|
2421
|
+
onDraft(next.text);
|
|
2422
|
+
setMention(null);
|
|
2423
|
+
const el = boxRef.current;
|
|
2424
|
+
if (el) requestAnimationFrame(() => { el.focus(); el.setSelectionRange(next.caret, next.caret); });
|
|
2425
|
+
};
|
|
2426
|
+
const attach = (files) => {
|
|
2427
|
+
const list = Array.from(files ?? []);
|
|
2428
|
+
if (list.length > 0 && discuss && typeof onAttach === 'function') onAttach(list);
|
|
2429
|
+
};
|
|
2349
2430
|
return h('div', { className: 'at-composer' },
|
|
2350
2431
|
h('div', { className: 'at-composerinner' },
|
|
2351
|
-
h('div', {
|
|
2432
|
+
h('div', {
|
|
2433
|
+
className: cx('at-box', mode === 'task' && 'at-taskmode', dragging && 'at-dropping'),
|
|
2434
|
+
onDragOver: (event) => { if (discuss && event.dataTransfer?.types?.includes?.('Files')) { event.preventDefault(); setDragging(true); } },
|
|
2435
|
+
onDragLeave: () => setDragging(false),
|
|
2436
|
+
onDrop: (event) => { setDragging(false); if (!discuss) return; event.preventDefault(); attach(event.dataTransfer?.files); },
|
|
2437
|
+
},
|
|
2438
|
+
dragging ? h('div', { className: 'at-drophint', 'aria-hidden': 'true' }, t('attachDrop')) : null,
|
|
2439
|
+
candidates.length > 0 ? h('ul', { className: 'at-mentions', role: 'listbox', 'aria-label': t('mentionList') },
|
|
2440
|
+
candidates.map((agent, index) => h('li', {
|
|
2441
|
+
key: agent.id,
|
|
2442
|
+
role: 'option',
|
|
2443
|
+
'aria-selected': index === mention.index,
|
|
2444
|
+
className: cx('at-mention', index === mention.index && 'at-mention-on'),
|
|
2445
|
+
onMouseDown: (event) => { event.preventDefault(); pick(agent); },
|
|
2446
|
+
}, h('b', null, '@' + agent.name), agent.role ? h('span', null, agent.role) : null))) : null,
|
|
2352
2447
|
h('textarea', {
|
|
2353
|
-
ref:
|
|
2448
|
+
ref: boxRef,
|
|
2449
|
+
onMouseUp: (event) => rememberTextareaDrag(event.currentTarget),
|
|
2354
2450
|
value: draft,
|
|
2355
2451
|
rows: 2,
|
|
2356
2452
|
disabled,
|
|
2357
2453
|
placeholder: mode === 'task' ? t('taskPlaceholder') : t('composer'),
|
|
2358
2454
|
'aria-label': t('composerAria'),
|
|
2359
|
-
onChange: (event) => onDraft(event.target.value),
|
|
2455
|
+
onChange: (event) => { onDraft(event.target.value); track(event.target); },
|
|
2456
|
+
onClick: (event) => track(event.currentTarget),
|
|
2457
|
+
onBlur: () => setMention(null),
|
|
2458
|
+
onPaste: (event) => {
|
|
2459
|
+
const files = Array.from(event.clipboardData?.files ?? []);
|
|
2460
|
+
if (files.length > 0 && discuss) { event.preventDefault(); attach(files); }
|
|
2461
|
+
},
|
|
2360
2462
|
onKeyDown: (event) => {
|
|
2463
|
+
if (candidates.length > 0) {
|
|
2464
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
2465
|
+
event.preventDefault();
|
|
2466
|
+
const step = event.key === 'ArrowDown' ? 1 : candidates.length - 1;
|
|
2467
|
+
setMention({ ...mention, index: (mention.index + step) % candidates.length });
|
|
2468
|
+
return;
|
|
2469
|
+
}
|
|
2470
|
+
if ((event.key === 'Enter' && !event.metaKey && !event.ctrlKey) || event.key === 'Tab') {
|
|
2471
|
+
event.preventDefault();
|
|
2472
|
+
pick(candidates[mention.index] ?? candidates[0]);
|
|
2473
|
+
return;
|
|
2474
|
+
}
|
|
2475
|
+
if (event.key === 'Escape') { event.preventDefault(); setMention(null); return; }
|
|
2476
|
+
}
|
|
2361
2477
|
if ((event.metaKey || event.ctrlKey) && event.key === 'Enter') {
|
|
2362
2478
|
event.preventDefault();
|
|
2363
2479
|
send();
|
|
2364
2480
|
}
|
|
2365
2481
|
},
|
|
2366
2482
|
}),
|
|
2483
|
+
pending.length > 0 ? h('div', { className: 'at-attachrow' }, pending.map((item) => h('div', {
|
|
2484
|
+
key: item.id,
|
|
2485
|
+
className: cx('at-attach', item.status === 'error' && 'at-attach-error', item.status === 'uploading' && 'at-attach-busy'),
|
|
2486
|
+
title: item.status === 'error' ? item.error : item.name,
|
|
2487
|
+
},
|
|
2488
|
+
item.preview ? h('img', { src: item.preview, alt: item.name }) : h(Ico, { name: 'file' }),
|
|
2489
|
+
h('span', { className: 'at-attachname' }, item.name),
|
|
2490
|
+
h('span', { className: 'at-attachsize' }, item.status === 'uploading' ? '…' : fmtBytes(item.size)),
|
|
2491
|
+
h('button', { type: 'button', className: 'at-attachx', 'aria-label': tf(t, 'attachRemove', { name: item.name }), onClick: () => onRemoveAttachment?.(item.id) }, '×')))) : null,
|
|
2492
|
+
pending.length > 0 && !discuss ? h('div', { className: 'at-hint' }, t('attachTaskMode')) : null,
|
|
2367
2493
|
mode === 'task' ? h('div', { className: 'at-taskfields' },
|
|
2368
2494
|
h('textarea', {
|
|
2369
2495
|
className: 'at-taskdef',
|
|
@@ -2387,11 +2513,13 @@ window.__ModuleLoader__.load({
|
|
|
2387
2513
|
h('div', { className: 'at-mode', role: 'group', 'aria-label': t('modeAria') },
|
|
2388
2514
|
h('button', { type: 'button', 'aria-pressed': mode === 'discuss', onClick: () => onMode('discuss') }, t('discuss')),
|
|
2389
2515
|
h('button', { type: 'button', 'aria-pressed': mode === 'task', onClick: () => onMode('task') }, t('taskMode'))),
|
|
2516
|
+
discuss ? h('button', { className: 'at-attachbtn', type: 'button', title: t('attachAdd'), 'aria-label': t('attachAdd'), disabled, onClick: () => fileRef.current?.click() }, h(Ico, { name: 'clip' })) : null,
|
|
2517
|
+
h('input', { ref: fileRef, type: 'file', multiple: true, hidden: true, onChange: (event) => { attach(event.target.files); event.target.value = ''; } }),
|
|
2390
2518
|
mode === 'task' ? h('label', { className: 'at-qacheck' },
|
|
2391
2519
|
h('input', { type: 'checkbox', checked: qaRequired, onChange: (event) => onQaRequired(event.target.checked) }),
|
|
2392
2520
|
h('span', null, t('qaRequired'))) : null,
|
|
2393
2521
|
h('span', { className: 'at-hint' }, t('enterHint')),
|
|
2394
|
-
h('button', { className: 'at-send', type: 'button', disabled:
|
|
2522
|
+
h('button', { className: 'at-send', type: 'button', disabled: !canSend, onClick: send }, mode === 'task' ? t('createTask') : t('send'))))));
|
|
2395
2523
|
}
|
|
2396
2524
|
|
|
2397
2525
|
function QuadrantCard({ t, meta, quadrant, tasks, items, count, onItem, onViewAll }) {
|
|
@@ -2674,6 +2802,110 @@ window.__ModuleLoader__.load({
|
|
|
2674
2802
|
}
|
|
2675
2803
|
// </stream-follow>
|
|
2676
2804
|
|
|
2805
|
+
// <textarea-fit>
|
|
2806
|
+
/**
|
|
2807
|
+
* 输入框随内容长高(#65:输入框只显示一两行,长文看不全也拉不大)。
|
|
2808
|
+
* - 高度 = max(内容高度, 用户拖出来的高度),封顶 maxHeight,超出才出滚动条;
|
|
2809
|
+
* - 用户拖动右下角改过高度(与上次自适应结果不同)即记为下限,清空发送后保持;
|
|
2810
|
+
* 只读写传入元素的 style/dataset/scrollHeight/offsetHeight,便于单测。
|
|
2811
|
+
*/
|
|
2812
|
+
function fitTextarea(el, maxHeight) {
|
|
2813
|
+
if (el === null || el === undefined || el.style === undefined) return null;
|
|
2814
|
+
const floor = Number(el.dataset?.userHeight) || 0;
|
|
2815
|
+
el.style.height = 'auto';
|
|
2816
|
+
const want = Math.max(el.scrollHeight, floor);
|
|
2817
|
+
const height = Math.min(want, maxHeight);
|
|
2818
|
+
el.style.height = height + 'px';
|
|
2819
|
+
el.style.overflowY = want > maxHeight ? 'auto' : 'hidden';
|
|
2820
|
+
if (el.dataset) el.dataset.fitHeight = String(height);
|
|
2821
|
+
return height;
|
|
2822
|
+
}
|
|
2823
|
+
/** 拖动结束时调用:高度与自适应结果不同 = 用户手动调过,记为下限。 */
|
|
2824
|
+
function rememberTextareaDrag(el) {
|
|
2825
|
+
if (el === null || el === undefined || !el.dataset) return null;
|
|
2826
|
+
const fitted = Number(el.dataset.fitHeight) || 0;
|
|
2827
|
+
if (Math.abs(el.offsetHeight - fitted) <= 2) return null;
|
|
2828
|
+
el.dataset.userHeight = String(el.offsetHeight);
|
|
2829
|
+
return el.offsetHeight;
|
|
2830
|
+
}
|
|
2831
|
+
// </textarea-fit>
|
|
2832
|
+
|
|
2833
|
+
/** 输入框自适应的 React 接线(主对话与任务回复共用);封顶为窗口高度的 45%,至少 160px。 */
|
|
2834
|
+
function useFitTextarea(ref, value) {
|
|
2835
|
+
React.useLayoutEffect(() => {
|
|
2836
|
+
const viewport = Number(globalThis.innerHeight) || 800;
|
|
2837
|
+
fitTextarea(ref?.current, Math.max(160, Math.floor(viewport * 0.45)));
|
|
2838
|
+
}, [ref, value]);
|
|
2839
|
+
}
|
|
2840
|
+
|
|
2841
|
+
// <member-copy>
|
|
2842
|
+
/**
|
|
2843
|
+
* 复制成员(#65:想要两个「玄策」一起写代码,只能手工重填一遍)。
|
|
2844
|
+
* 沿用角色、人格、运行配方、模型、输出上限与技能;不带笔记、会话与任务(那是原成员自己的经历)。
|
|
2845
|
+
* 名字取「原名去掉尾部数字 + 最小未占用序号」:玄策 → 玄策2,再复制玄策2 → 玄策3。
|
|
2846
|
+
*/
|
|
2847
|
+
function copyMemberDraft(source, takenNames) {
|
|
2848
|
+
const taken = new Set((Array.isArray(takenNames) ? takenNames : []).map((name) => String(name ?? '').trim()));
|
|
2849
|
+
const base = String(source?.name ?? '').trim().replace(/\s*\d+$/, '') || 'agent';
|
|
2850
|
+
let n = 2;
|
|
2851
|
+
while (taken.has(base + n)) n += 1;
|
|
2852
|
+
const config = source?.config ?? {};
|
|
2853
|
+
const maxTokens = Number(config.maxTokens);
|
|
2854
|
+
return {
|
|
2855
|
+
name: base + n,
|
|
2856
|
+
role: typeof source?.role === 'string' ? source.role : '',
|
|
2857
|
+
personality: typeof source?.personality === 'string' ? source.personality : '',
|
|
2858
|
+
preset: config.preset ?? source?.preset ?? 'standard',
|
|
2859
|
+
provider: config.provider ?? '',
|
|
2860
|
+
model: config.model ?? '',
|
|
2861
|
+
reasoningEffort: config.reasoningEffort ?? '',
|
|
2862
|
+
maxTokens: Number.isSafeInteger(maxTokens) && maxTokens > 0 ? maxTokens : null,
|
|
2863
|
+
skills: (Array.isArray(source?.skills) ? source.skills : []).filter((skill) => typeof skill === 'string' && skill.trim() !== ''),
|
|
2864
|
+
sourceName: String(source?.name ?? ''),
|
|
2865
|
+
};
|
|
2866
|
+
}
|
|
2867
|
+
// </member-copy>
|
|
2868
|
+
|
|
2869
|
+
// <composer-rich>
|
|
2870
|
+
/**
|
|
2871
|
+
* 输入框里的 @ 与附件(#65)。纯函数,便于单测;服务端用同一份花名册规则识别 @(rich-message.js)。
|
|
2872
|
+
* mentionQuery:光标前最近的 @ 到光标之间没有空白、不超过 16 字时,返回 { start, query }。
|
|
2873
|
+
*/
|
|
2874
|
+
function mentionQuery(text, caret) {
|
|
2875
|
+
const before = String(text ?? '').slice(0, caret);
|
|
2876
|
+
const at = before.lastIndexOf('@');
|
|
2877
|
+
if (at === -1) return null;
|
|
2878
|
+
const query = before.slice(at + 1);
|
|
2879
|
+
if (/\s/.test(query) || query.length > 16) return null;
|
|
2880
|
+
return { start: at, query };
|
|
2881
|
+
}
|
|
2882
|
+
/** 在岗 agent 中名字以 query 开头的排前、包含的排后,最多 8 个。 */
|
|
2883
|
+
function mentionCandidates(agents, query) {
|
|
2884
|
+
const q = String(query ?? '').toLowerCase();
|
|
2885
|
+
const active = (Array.isArray(agents) ? agents : []).filter((agent) => agent?.status !== 'retired' && typeof agent?.name === 'string' && agent.name !== '');
|
|
2886
|
+
const starts = active.filter((agent) => agent.name.toLowerCase().startsWith(q));
|
|
2887
|
+
const contains = active.filter((agent) => !agent.name.toLowerCase().startsWith(q) && agent.name.toLowerCase().includes(q));
|
|
2888
|
+
return [...starts, ...contains].slice(0, 8);
|
|
2889
|
+
}
|
|
2890
|
+
/** 用「@名字 」替换 start..caret,返回新文本与新光标。 */
|
|
2891
|
+
function applyMention(text, start, caret, name) {
|
|
2892
|
+
const value = String(text ?? '');
|
|
2893
|
+
const inserted = '@' + name + ' ';
|
|
2894
|
+
return { text: value.slice(0, start) + inserted + value.slice(caret), caret: start + inserted.length };
|
|
2895
|
+
}
|
|
2896
|
+
const ATTACH_IMAGE_TYPES = ['image/png', 'image/jpeg', 'image/gif', 'image/webp'];
|
|
2897
|
+
/** 浏览器 File → 上传种类:宿主收的四种图片走 image(会规范化、给模型看),其余一律原样作为文件。 */
|
|
2898
|
+
function attachmentKind(file) {
|
|
2899
|
+
return ATTACH_IMAGE_TYPES.includes(file?.type) ? 'image' : 'file';
|
|
2900
|
+
}
|
|
2901
|
+
function fmtBytes(bytes) {
|
|
2902
|
+
const n = Number(bytes) || 0;
|
|
2903
|
+
if (n < 1024) return n + ' B';
|
|
2904
|
+
if (n < 1024 * 1024) return (n / 1024).toFixed(n < 10 * 1024 ? 1 : 0) + ' KB';
|
|
2905
|
+
return (n / 1024 / 1024).toFixed(1) + ' MB';
|
|
2906
|
+
}
|
|
2907
|
+
// </composer-rich>
|
|
2908
|
+
|
|
2677
2909
|
/**
|
|
2678
2910
|
* 滚动容器「跟随最新」的 React 接线(主对话、任务记录共用这一份)。
|
|
2679
2911
|
* key 变化即重置并贴底(切项目/标签/任务);
|
|
@@ -2755,6 +2987,7 @@ window.__ModuleLoader__.load({
|
|
|
2755
2987
|
const [acceptChecked, setAcceptChecked] = React.useState(false);
|
|
2756
2988
|
const [qaChecks, setQaChecks] = React.useState([]);
|
|
2757
2989
|
const [addOpen, setAddOpen] = React.useState(false);
|
|
2990
|
+
const [mCopy, setMCopy] = React.useState(null);
|
|
2758
2991
|
const [mName, setMName] = React.useState('');
|
|
2759
2992
|
const [mRole, setMRole] = React.useState('');
|
|
2760
2993
|
const [mPrompt, setMPrompt] = React.useState('');
|
|
@@ -2896,6 +3129,7 @@ window.__ModuleLoader__.load({
|
|
|
2896
3129
|
const jumpToLatest = mainFollow.jump;
|
|
2897
3130
|
// R-08 快捷键:composer 聚焦句柄 + `?` 帮助浮层开关。
|
|
2898
3131
|
const composerInputRef = React.useRef(null);
|
|
3132
|
+
const [pendingFiles, setPendingFiles] = React.useState([]);
|
|
2899
3133
|
const [shortcutsOpen, setShortcutsOpen] = React.useState(false);
|
|
2900
3134
|
const gPrefixRef = React.useRef(0);
|
|
2901
3135
|
// Latest-data mirror for effects that must react to `selected` alone,
|
|
@@ -3587,6 +3821,21 @@ window.__ModuleLoader__.load({
|
|
|
3587
3821
|
setMModel(defaults.model ?? '');
|
|
3588
3822
|
setMEffort(defaults.reasoningEffort ?? '');
|
|
3589
3823
|
setMOwner((data?.agents ?? []).length === 0);
|
|
3824
|
+
setMCopy(null);
|
|
3825
|
+
setMError('');
|
|
3826
|
+
setAddOpen(true);
|
|
3827
|
+
}
|
|
3828
|
+
/** #65:从成员资料「复制成员」——新增表单按原成员预填,人格/配方/上限/技能随创建一并写入。 */
|
|
3829
|
+
function openCopyAgent(source) {
|
|
3830
|
+
const draft = copyMemberDraft(source, (data?.agents ?? []).map((agent) => agent.name));
|
|
3831
|
+
setMName(draft.name);
|
|
3832
|
+
setMRole(draft.role);
|
|
3833
|
+
setMPrompt('');
|
|
3834
|
+
setMProvider(draft.provider);
|
|
3835
|
+
setMModel(draft.model);
|
|
3836
|
+
setMEffort(draft.reasoningEffort);
|
|
3837
|
+
setMOwner(false);
|
|
3838
|
+
setMCopy(draft);
|
|
3590
3839
|
setMError('');
|
|
3591
3840
|
setAddOpen(true);
|
|
3592
3841
|
}
|
|
@@ -3600,19 +3849,26 @@ window.__ModuleLoader__.load({
|
|
|
3600
3849
|
role: mRole.trim(),
|
|
3601
3850
|
kind: 'agent',
|
|
3602
3851
|
status: 'provisioning',
|
|
3852
|
+
...(mCopy?.personality ? { personality: mCopy.personality } : {}),
|
|
3603
3853
|
});
|
|
3604
3854
|
const memberId = added.member.id;
|
|
3605
|
-
|
|
3855
|
+
const patch = {
|
|
3856
|
+
...(mProvider.trim() ? { provider: mProvider.trim() } : {}),
|
|
3857
|
+
...(mModel.trim() ? { model: mModel.trim() } : {}),
|
|
3858
|
+
...(mEffort.trim() ? { reasoningEffort: mEffort.trim() } : {}),
|
|
3859
|
+
...(mCopy && mCopy.preset !== 'standard' ? { preset: mCopy.preset } : {}),
|
|
3860
|
+
...(mCopy?.maxTokens ? { maxTokens: mCopy.maxTokens } : {}),
|
|
3861
|
+
};
|
|
3862
|
+
if (Object.keys(patch).length > 0) {
|
|
3606
3863
|
await runCommand('member.config.update', {
|
|
3607
3864
|
memberId,
|
|
3608
|
-
patch
|
|
3609
|
-
|
|
3610
|
-
...(mModel.trim() ? { model: mModel.trim() } : {}),
|
|
3611
|
-
...(mEffort.trim() ? { reasoningEffort: mEffort.trim() } : {}),
|
|
3612
|
-
},
|
|
3613
|
-
reason: 'workbench add member',
|
|
3865
|
+
patch,
|
|
3866
|
+
reason: mCopy ? 'workbench copy member' : 'workbench add member',
|
|
3614
3867
|
});
|
|
3615
3868
|
}
|
|
3869
|
+
for (const skill of mCopy?.skills ?? []) {
|
|
3870
|
+
await runCommand('member.skill', { memberId, name: skill });
|
|
3871
|
+
}
|
|
3616
3872
|
await runCommand('member.activate', {
|
|
3617
3873
|
memberId,
|
|
3618
3874
|
prompt: mPrompt.trim() || (mOwner
|
|
@@ -3929,9 +4185,40 @@ window.__ModuleLoader__.load({
|
|
|
3929
4185
|
say(tf(t, 'sendFailed', { message: error?.message ?? String(error) }));
|
|
3930
4186
|
}
|
|
3931
4187
|
}
|
|
4188
|
+
/** #65:选中/粘贴/拖入的文件立即上传进 DSH 附件存储;发送时只带已上传好的块。 */
|
|
4189
|
+
function attachFiles(files) {
|
|
4190
|
+
for (const file of files) {
|
|
4191
|
+
const id = 'att-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2, 7);
|
|
4192
|
+
const kind = attachmentKind(file);
|
|
4193
|
+
const preview = kind === 'image' && typeof URL?.createObjectURL === 'function' ? URL.createObjectURL(file) : null;
|
|
4194
|
+
const name = file.name || (kind === 'image' ? 'image' : 'file');
|
|
4195
|
+
setPendingFiles((list) => [...list, { id, kind, name, size: file.size, preview, status: 'uploading', block: null, error: '' }]);
|
|
4196
|
+
const query = new URLSearchParams({ kind, name, ...(kind === 'image' ? { type: file.type } : {}) });
|
|
4197
|
+
fetch('/ai-team/api/attachments?' + query.toString(), { method: 'POST', headers: { 'content-type': 'application/octet-stream' }, body: file })
|
|
4198
|
+
.then(async (response) => {
|
|
4199
|
+
const body = await response.json().catch(() => null);
|
|
4200
|
+
if (!response.ok || !body?.block) throw new Error(body?.error?.message ?? ('HTTP ' + response.status));
|
|
4201
|
+
setPendingFiles((list) => list.map((item) => item.id === id ? { ...item, status: 'ready', block: body.block } : item));
|
|
4202
|
+
})
|
|
4203
|
+
.catch((error) => {
|
|
4204
|
+
const message = error?.message ?? String(error);
|
|
4205
|
+
setPendingFiles((list) => list.map((item) => item.id === id ? { ...item, status: 'error', error: message } : item));
|
|
4206
|
+
say(tf(t, 'attachFailed', { name, message }));
|
|
4207
|
+
});
|
|
4208
|
+
}
|
|
4209
|
+
}
|
|
4210
|
+
function removeAttachment(id) {
|
|
4211
|
+
setPendingFiles((list) => {
|
|
4212
|
+
const gone = list.find((item) => item.id === id);
|
|
4213
|
+
if (gone?.preview && typeof URL?.revokeObjectURL === 'function') URL.revokeObjectURL(gone.preview);
|
|
4214
|
+
return list.filter((item) => item.id !== id);
|
|
4215
|
+
});
|
|
4216
|
+
}
|
|
3932
4217
|
async function send() {
|
|
3933
4218
|
const text = draft.trim();
|
|
3934
|
-
|
|
4219
|
+
const withFiles = mode !== 'task' && pendingFiles.some((item) => item.status === 'ready');
|
|
4220
|
+
if (!text && !withFiles) return;
|
|
4221
|
+
if (mode !== 'task' && pendingFiles.some((item) => item.status === 'uploading')) { say(t('attachUploading')); return; }
|
|
3935
4222
|
if (sendingRef.current) return;
|
|
3936
4223
|
sendingRef.current = true;
|
|
3937
4224
|
try {
|
|
@@ -3963,7 +4250,10 @@ window.__ModuleLoader__.load({
|
|
|
3963
4250
|
setTaskDefinition('');
|
|
3964
4251
|
setQaChecklistText('');
|
|
3965
4252
|
} else {
|
|
3966
|
-
|
|
4253
|
+
const blocks = pendingFiles.filter((item) => item.status === 'ready').map((item) => item.block);
|
|
4254
|
+
await runCommand('stream.post', { body: text, ...(blocks.length > 0 ? { attachments: blocks } : {}) });
|
|
4255
|
+
for (const item of pendingFiles) if (item.preview && typeof URL?.revokeObjectURL === 'function') URL.revokeObjectURL(item.preview);
|
|
4256
|
+
setPendingFiles([]);
|
|
3967
4257
|
}
|
|
3968
4258
|
setDraft('');
|
|
3969
4259
|
say(mode === 'task' ? t('taskSent') : t('discussSent'));
|
|
@@ -4456,6 +4746,10 @@ window.__ModuleLoader__.load({
|
|
|
4456
4746
|
onDraft: setDraft,
|
|
4457
4747
|
onSend: send,
|
|
4458
4748
|
inputRef: composerInputRef,
|
|
4749
|
+
agents: (data?.agents ?? []).filter((agent) => agent.status !== 'retired'),
|
|
4750
|
+
attachments: pendingFiles,
|
|
4751
|
+
onAttach: attachFiles,
|
|
4752
|
+
onRemoveAttachment: removeAttachment,
|
|
4459
4753
|
}) : null),
|
|
4460
4754
|
threadOpen && selectedTask ? h(ThreadPanel, {
|
|
4461
4755
|
t,
|
|
@@ -4503,7 +4797,8 @@ window.__ModuleLoader__.load({
|
|
|
4503
4797
|
'aria-label': t('addAgentTitle'),
|
|
4504
4798
|
onSubmit: (event) => { event.preventDefault(); createAgent(); },
|
|
4505
4799
|
},
|
|
4506
|
-
h('h2', { className: 'at-modaltitle' }, t('addAgentTitle')),
|
|
4800
|
+
h('h2', { className: 'at-modaltitle' }, mCopy ? t('memberCopy') : t('addAgentTitle')),
|
|
4801
|
+
mCopy ? h('div', { className: 'at-modalmeta' }, tf(t, 'memberCopyFrom', { name: mCopy.sourceName })) : null,
|
|
4507
4802
|
h('label', { className: 'at-field' }, h('span', null, t('memberName')),
|
|
4508
4803
|
h('input', { value: mName, onChange: (event) => setMName(event.target.value), autoFocus: true })),
|
|
4509
4804
|
h('label', { className: 'at-field' }, h('span', null, t('memberRole')),
|
|
@@ -4613,6 +4908,7 @@ window.__ModuleLoader__.load({
|
|
|
4613
4908
|
h('button', { className: 'at-btn', type: 'button', onClick: () => setProfileAgent(null), disabled: pBusy }, t('cancel')),
|
|
4614
4909
|
h('button', { className: 'at-btn', type: 'button', onClick: () => { const target = profileAgent; setProfileAgent(null); openMemberView(target); } }, t('memberTasks')),
|
|
4615
4910
|
h('button', { className: 'at-btn', type: 'button', onClick: () => { const target = profileAgent; setProfileAgent(null); void openAgentChat(target); } }, t('agentChat')),
|
|
4911
|
+
h('button', { className: 'at-btn', type: 'button', onClick: () => { const source = profileAgent; setProfileAgent(null); openCopyAgent(source); }, disabled: pBusy }, t('memberCopy')),
|
|
4616
4912
|
h('button', { className: 'at-btn', type: 'button', onClick: leaveProfile, disabled: pBusy }, t('leaveTeam')),
|
|
4617
4913
|
profileAgent.status === 'failed' ? h('button', { className: 'at-btn', type: 'button', onClick: retryProfile, disabled: pBusy }, t('retry')) : null,
|
|
4618
4914
|
profileAgent.sessionId ? h('button', { className: 'at-btn', type: 'button', title: t('reseatConfirm'), onClick: reseatProfile, disabled: pBusy }, t('reseatSession')) : null,
|
package/index.js
CHANGED
|
@@ -68,6 +68,8 @@ import { aggregatePeople } from './lib/host/people-view.js';
|
|
|
68
68
|
import { riskView } from './lib/host/risk-view.js';
|
|
69
69
|
import { weeklyView } from './lib/host/weekly-view.js';
|
|
70
70
|
import { isInformationalThreadMention } from './lib/domain/inbox.js';
|
|
71
|
+
import { messageContent, normalizeAttachments } from './lib/domain/rich-message.js';
|
|
72
|
+
import { readAttachment, uploadAttachment } from './lib/host/attachment-routes.js';
|
|
71
73
|
import { createDiagLogger, defaultDiagDir, installDiagSink } from './lib/diaglog.js';
|
|
72
74
|
|
|
73
75
|
export const name = 'ai-team';
|
|
@@ -716,10 +718,11 @@ export function apply(ctx, config = {}) {
|
|
|
716
718
|
}
|
|
717
719
|
return null;
|
|
718
720
|
},
|
|
719
|
-
forwardHuman: (projectId, body) => {
|
|
721
|
+
forwardHuman: (projectId, body, attachments = []) => {
|
|
720
722
|
const runtime = projectRuntime(projectId);
|
|
721
723
|
if (runtime === null) return Promise.reject(new Error(`no Project runtime ${projectId}`));
|
|
722
|
-
|
|
724
|
+
const refs = normalizeAttachments(attachments);
|
|
725
|
+
return runtime.service.dispatch({ type: 'stream.post', payload: { body, ...(refs.length > 0 ? { attachments: refs } : {}) }, actor: { kind: 'human', memberId: HUMAN_ID }, projectId });
|
|
723
726
|
},
|
|
724
727
|
forwardMember: (projectId, senderSessionId, body) => {
|
|
725
728
|
const runtime = projectRuntime(projectId);
|
|
@@ -996,6 +999,8 @@ export function apply(ctx, config = {}) {
|
|
|
996
999
|
// personality, skills). A wake is only the Task delta; re-sending the
|
|
997
1000
|
// whole activation prompt caused the duplicated blocks users saw.
|
|
998
1001
|
const wakePrompt = async (plan, member, options = {}) => describeWake(plan, projectRuntime.service.state, options);
|
|
1002
|
+
// #65:Human 消息里的图片/文件随唤醒一起交给成员会话(文字块 + 附件块)。
|
|
1003
|
+
const wakeContent = async (plan, member, options = {}) => messageContent(await wakePrompt(plan, member, options), plan.attachments);
|
|
999
1004
|
for (const plan of plans) {
|
|
1000
1005
|
if (wakeKeys.has(plan.key)) continue;
|
|
1001
1006
|
let member = projectRuntime.service.state.members?.[plan.memberId];
|
|
@@ -1038,6 +1043,7 @@ export function apply(ctx, config = {}) {
|
|
|
1038
1043
|
memberId: member.id,
|
|
1039
1044
|
...(routeStale ? { force: true } : {}),
|
|
1040
1045
|
prompt: await wakePrompt(plan, member, { includeThread: true }),
|
|
1046
|
+
...(Array.isArray(plan.attachments) ? { attachments: plan.attachments } : {}),
|
|
1041
1047
|
},
|
|
1042
1048
|
}, projectRuntime))();
|
|
1043
1049
|
activationTasks.set(activationKey, activation);
|
|
@@ -1063,7 +1069,7 @@ export function apply(ctx, config = {}) {
|
|
|
1063
1069
|
const delivered = await runtime.wake(member, {
|
|
1064
1070
|
// 冷路径(会话不在线)才附 Thread 尾巴:成员靠它续跑,不必从零回忆;
|
|
1065
1071
|
// 热路径上下文已在会话里,附上去只是白烧 token。
|
|
1066
|
-
prompt: await
|
|
1072
|
+
prompt: await wakeContent(plan, member, { includeThread: sessions?.get?.(member.sessionId) === undefined }),
|
|
1067
1073
|
});
|
|
1068
1074
|
messageId = delivered.messageId ?? null;
|
|
1069
1075
|
// A cold session cannot be renamed before wake; retry once it is live.
|
|
@@ -2103,7 +2109,8 @@ export function apply(ctx, config = {}) {
|
|
|
2103
2109
|
cwd: effectiveDir,
|
|
2104
2110
|
});
|
|
2105
2111
|
const result = await runtime.activate(activationMember, {
|
|
2106
|
-
|
|
2112
|
+
// #65:激活时若带着 Human 消息的图片/文件,一并放进首条消息。
|
|
2113
|
+
prompt: messageContent(`${memberIdentity(activationMember)}\n\n${typeof body.payload?.prompt === 'string'
|
|
2107
2114
|
? body.payload.prompt
|
|
2108
2115
|
: '你被加入 AI Team。先读取项目简报与收件箱,再处理分配给你的任务。'}${await formatSkillCatalog(skillsService, { cwd: effectiveDir })}${await loadSkillContext(activationMember, [join(effectiveDir, '.dsh'), dshHome(), projectRuntime.dir], {
|
|
2109
2116
|
vars: {
|
|
@@ -2115,7 +2122,7 @@ export function apply(ctx, config = {}) {
|
|
|
2115
2122
|
// 按身份装配内置技能:项目主理人拿审查规程,验收拿复跑规程,其余拿执行规程。
|
|
2116
2123
|
ownerId: projectRuntime.service.state.projects?.[projectRuntime.id]?.ownerMemberId
|
|
2117
2124
|
?? projectRuntime.service.state.projects?.[projectRuntime.id]?.ownerId,
|
|
2118
|
-
})}`,
|
|
2125
|
+
})}`, body.payload?.attachments),
|
|
2119
2126
|
});
|
|
2120
2127
|
let bound;
|
|
2121
2128
|
try {
|
|
@@ -2365,6 +2372,37 @@ export function apply(ctx, config = {}) {
|
|
|
2365
2372
|
// 批量恢复入口:把「因运行时/提供方不可用而 failed」的成员按新运行时重建。
|
|
2366
2373
|
// 这类失败与任务无关,但 failed 成员被 waker 排除,不手动救就永远醒不过来
|
|
2367
2374
|
// (实机:rc.2 那次激活全挂,6 个成员一起变 failed)。
|
|
2375
|
+
// #65:图片/文件进 DSH 附件存储(与标准会话输入框同一份存储),返回可放进 stream.post 的块。
|
|
2376
|
+
if (req.method === 'POST' && url.pathname === '/ai-team/api/attachments') {
|
|
2377
|
+
try {
|
|
2378
|
+
const result = await uploadAttachment({ store: serviceOf(ctx, 'attachments'), req, url });
|
|
2379
|
+
if (result.status >= 400) diag?.append({ ev: 'attachment.upload.fail', code: result.body?.error?.code ?? null });
|
|
2380
|
+
return send(res, result.body, result.status);
|
|
2381
|
+
} catch (error) {
|
|
2382
|
+
diag?.append({ ev: 'attachment.upload.fail', code: error?.code ?? null, message: error?.message ?? String(error) });
|
|
2383
|
+
return send(res, { ok: false, error: { code: error?.code ?? 'E_ATTACHMENT', message: error?.message ?? String(error) } }, 400);
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
if (req.method === 'GET' && url.pathname === '/ai-team/api/attachments/content') {
|
|
2387
|
+
const requested = url.searchParams.get('project');
|
|
2388
|
+
const runtime = (requested === null ? null : projectRuntime(requested)) ?? currentRuntime();
|
|
2389
|
+
try {
|
|
2390
|
+
const result = await readAttachment({ store: serviceOf(ctx, 'attachments'), state: runtime?.service?.state, url });
|
|
2391
|
+
if (result.bytes === undefined) return send(res, result.body, result.status);
|
|
2392
|
+
res.statusCode = 200;
|
|
2393
|
+
res.setHeader('content-type', result.contentType);
|
|
2394
|
+
res.setHeader('cache-control', 'private, max-age=31536000, immutable');
|
|
2395
|
+
const disposition = result.contentType.startsWith('image/') ? 'inline' : 'attachment';
|
|
2396
|
+
res.setHeader('content-disposition', `${disposition}; filename*=UTF-8''${encodeURIComponent(result.name || 'file')}`);
|
|
2397
|
+
if (result.bytes instanceof Uint8Array) return res.end(Buffer.from(result.bytes));
|
|
2398
|
+
for await (const chunk of result.bytes) res.write(Buffer.from(chunk));
|
|
2399
|
+
return res.end();
|
|
2400
|
+
} catch (error) {
|
|
2401
|
+
diag?.append({ ev: 'attachment.read.fail', code: error?.code ?? null, message: error?.message ?? String(error) });
|
|
2402
|
+
if (res.headersSent) return res.destroy(error);
|
|
2403
|
+
return send(res, { ok: false, error: { code: error?.code ?? 'E_ATTACHMENT', message: error?.message ?? String(error) } }, 500);
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2368
2406
|
if (req.method === 'POST' && url.pathname === '/ai-team/api/members/retry') {
|
|
2369
2407
|
const body = await readJson(req);
|
|
2370
2408
|
const includeAll = body?.all === true;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 主对话「需求内容」:文字 + 图片/文件附件 + @成员(#65)。
|
|
3
|
+
*
|
|
4
|
+
* 文渊阁对话框与 DSH 标准会话(宿主会话转发)共用这一份:
|
|
5
|
+
* - 附件只收 DSH 附件存储已落盘的持久引用(ImageBlock / FileBlock 的 `attachment`),
|
|
6
|
+
* 形状与官方 `ImageAttachmentRef` / `FileAttachmentRef` 一致,原样交给成员会话;
|
|
7
|
+
* - @成员按项目花名册识别,长名优先(「玄策2」不被「玄策」截走);
|
|
8
|
+
* - 交给成员的内容 = 一段文字 + 附件块,顺序与 Human 提交时一致。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const IMAGE_TYPES = new Set(['image/png', 'image/jpeg', 'image/gif', 'image/webp']);
|
|
12
|
+
export const MAX_ATTACHMENTS = 10;
|
|
13
|
+
|
|
14
|
+
const isId = (value) => typeof value === 'string' && value.trim() !== '' && value.length <= 256;
|
|
15
|
+
const isCount = (value) => Number.isSafeInteger(value) && value >= 0;
|
|
16
|
+
|
|
17
|
+
/** 一个附件块 → 规范化块;形状不对返回 null(不猜、不补)。 */
|
|
18
|
+
export function normalizeAttachment(block) {
|
|
19
|
+
const ref = block?.attachment;
|
|
20
|
+
if (block?.type === 'image') {
|
|
21
|
+
if (!isId(ref?.attachmentId) || !IMAGE_TYPES.has(ref?.mediaType) || !isCount(ref?.bytes) || !isCount(ref?.width) || !isCount(ref?.height)) return null;
|
|
22
|
+
return {
|
|
23
|
+
type: 'image',
|
|
24
|
+
attachment: {
|
|
25
|
+
attachmentId: ref.attachmentId,
|
|
26
|
+
mediaType: ref.mediaType,
|
|
27
|
+
bytes: ref.bytes,
|
|
28
|
+
width: ref.width,
|
|
29
|
+
height: ref.height,
|
|
30
|
+
...(typeof ref.name === 'string' && ref.name !== '' ? { name: ref.name.slice(0, 200) } : {}),
|
|
31
|
+
...(isCount(ref.originalDimensions?.width) && isCount(ref.originalDimensions?.height)
|
|
32
|
+
? { originalDimensions: { width: ref.originalDimensions.width, height: ref.originalDimensions.height } }
|
|
33
|
+
: {}),
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (block?.type === 'file') {
|
|
38
|
+
if (!isId(ref?.attachmentId) || !isCount(ref?.bytes) || typeof ref?.name !== 'string') return null;
|
|
39
|
+
return { type: 'file', attachment: { attachmentId: ref.attachmentId, bytes: ref.bytes, name: ref.name.slice(0, 200) } };
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 附件列表 → 规范化列表(去掉坏块与重复,封顶 MAX_ATTACHMENTS)。 */
|
|
45
|
+
export function normalizeAttachments(list) {
|
|
46
|
+
const out = [];
|
|
47
|
+
const seen = new Set();
|
|
48
|
+
for (const block of Array.isArray(list) ? list : []) {
|
|
49
|
+
const normalized = normalizeAttachment(block);
|
|
50
|
+
if (normalized === null) continue;
|
|
51
|
+
const key = `${normalized.type}:${normalized.attachment.attachmentId}`;
|
|
52
|
+
if (seen.has(key)) continue;
|
|
53
|
+
seen.add(key);
|
|
54
|
+
out.push(normalized);
|
|
55
|
+
if (out.length >= MAX_ATTACHMENTS) break;
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 正文里 @ 到的成员 id(按出现顺序去重)。只认在岗的 agent 成员;长名优先匹配,
|
|
62
|
+
* 名字后面紧跟什么都行(中文里「@玄策看下」很常见)。
|
|
63
|
+
*/
|
|
64
|
+
export function findMentions(body, members) {
|
|
65
|
+
if (typeof body !== 'string' || !body.includes('@')) return [];
|
|
66
|
+
const roster = (Array.isArray(members) ? members : Object.values(members ?? {}))
|
|
67
|
+
.filter((member) => member?.kind === 'agent' && member.status !== 'retired' && typeof member.name === 'string' && member.name.trim() !== '')
|
|
68
|
+
.map((member) => ({ id: member.id, name: member.name.trim() }))
|
|
69
|
+
.sort((a, b) => b.name.length - a.name.length);
|
|
70
|
+
const ids = [];
|
|
71
|
+
for (let at = body.indexOf('@'); at !== -1; at = body.indexOf('@', at + 1)) {
|
|
72
|
+
const rest = body.slice(at + 1);
|
|
73
|
+
const hit = roster.find((member) => rest.startsWith(member.name));
|
|
74
|
+
if (hit !== undefined && !ids.includes(hit.id)) ids.push(hit.id);
|
|
75
|
+
}
|
|
76
|
+
return ids;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** 附件的一行文字说明(主对话摘要、提示词里给模型看清有几张图几个文件)。 */
|
|
80
|
+
export function describeAttachments(attachments) {
|
|
81
|
+
const list = Array.isArray(attachments) ? attachments : [];
|
|
82
|
+
const images = list.filter((block) => block.type === 'image').length;
|
|
83
|
+
const files = list.filter((block) => block.type === 'file').map((block) => block.attachment.name);
|
|
84
|
+
const parts = [];
|
|
85
|
+
if (images > 0) parts.push(`${images} 张图片`);
|
|
86
|
+
if (files.length > 0) parts.push(`${files.length} 个文件(${files.join('、')})`);
|
|
87
|
+
return parts.length === 0 ? '' : `附:${parts.join(',')}`;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** 交给成员会话的内容:没有附件时保持纯文字(与原唤醒路径一致),有附件时 = 文字块 + 附件块。 */
|
|
91
|
+
export function messageContent(text, attachments) {
|
|
92
|
+
const list = normalizeAttachments(attachments);
|
|
93
|
+
return list.length === 0 ? text : [{ type: 'text', text }, ...list];
|
|
94
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文渊阁对话框的图片/文件(#65):上传进 DSH 附件存储、按主对话消息读回。
|
|
3
|
+
*
|
|
4
|
+
* 只用官方 `ctx.attachments`(AttachmentStore)——与 DSH 标准会话输入框同一份存储与校验:
|
|
5
|
+
* - 上传 `POST /ai-team/api/attachments?kind=image|file&name=…&type=image/png`,请求体是原始字节;
|
|
6
|
+
* 图片走 `saveImages`(格式/尺寸/字节上限由宿主校验并规范化),文件走 `saveFile`(原样保存);
|
|
7
|
+
* 返回的块就是 DSH 消息里的 ImageBlock / FileBlock,可直接放进 `stream.post` 的 attachments;
|
|
8
|
+
* - 读回 `GET /ai-team/api/attachments/content?project=…&seq=…&index=…`:只按账本里那条消息记下的
|
|
9
|
+
* 引用读,不接受客户端自报引用(读到的一定是这个项目主对话里真发过的附件)。
|
|
10
|
+
*/
|
|
11
|
+
import { normalizeAttachment } from '../domain/rich-message.js';
|
|
12
|
+
|
|
13
|
+
const IMAGE_TYPES = new Set(['image/png', 'image/jpeg', 'image/gif', 'image/webp']);
|
|
14
|
+
const DEFAULT_IMAGE_BYTES = 20 * 1024 * 1024;
|
|
15
|
+
export const MAX_FILE_BYTES = 50 * 1024 * 1024;
|
|
16
|
+
|
|
17
|
+
function failure(status, code, message) {
|
|
18
|
+
return { status, body: { ok: false, error: { code, message } } };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function readBytes(req, limit) {
|
|
22
|
+
const chunks = [];
|
|
23
|
+
let size = 0;
|
|
24
|
+
for await (const chunk of req) {
|
|
25
|
+
size += chunk.length;
|
|
26
|
+
if (size > limit) return null;
|
|
27
|
+
chunks.push(chunk);
|
|
28
|
+
}
|
|
29
|
+
return new Uint8Array(Buffer.concat(chunks));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** 文件名只作显示:去掉路径部分与控制字符,封顶 200 字。 */
|
|
33
|
+
export function displayName(raw) {
|
|
34
|
+
const name = String(raw ?? '').split(/[\\/]/).at(-1).replace(/[\u0000-\u001f]/g, '').trim();
|
|
35
|
+
return name.slice(0, 200);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param {{ store: any, req: AsyncIterable<Uint8Array>, url: URL }} options
|
|
40
|
+
* @returns {Promise<{ status: number, body: object }>}
|
|
41
|
+
*/
|
|
42
|
+
export async function uploadAttachment({ store, req, url }) {
|
|
43
|
+
if (store === undefined || store === null) return failure(503, 'E_ATTACHMENTS_UNAVAILABLE', 'the Host has no attachment store');
|
|
44
|
+
const kind = url.searchParams.get('kind');
|
|
45
|
+
const name = displayName(url.searchParams.get('name'));
|
|
46
|
+
if (kind === 'image') {
|
|
47
|
+
const mediaType = url.searchParams.get('type');
|
|
48
|
+
if (!IMAGE_TYPES.has(mediaType)) return failure(415, 'E_UNSUPPORTED_IMAGE_TYPE', `image type ${String(mediaType)} is not accepted`);
|
|
49
|
+
const limit = Number(store.imageLimits?.maxImageBytes) || DEFAULT_IMAGE_BYTES;
|
|
50
|
+
const data = await readBytes(req, limit);
|
|
51
|
+
if (data === null) return failure(413, 'E_TOO_LARGE', `image is larger than ${limit} bytes`);
|
|
52
|
+
if (data.byteLength === 0) return failure(400, 'E_EMPTY', 'image is empty');
|
|
53
|
+
const [ref] = await store.saveImages([{ data, mediaType, ...(name !== '' ? { name } : {}) }]);
|
|
54
|
+
return { status: 200, body: { ok: true, block: normalizeAttachment({ type: 'image', attachment: ref }) } };
|
|
55
|
+
}
|
|
56
|
+
if (kind === 'file') {
|
|
57
|
+
const data = await readBytes(req, MAX_FILE_BYTES);
|
|
58
|
+
if (data === null) return failure(413, 'E_TOO_LARGE', `file is larger than ${MAX_FILE_BYTES} bytes`);
|
|
59
|
+
const ref = await store.saveFile({ data, name: name === '' ? 'file' : name });
|
|
60
|
+
return { status: 200, body: { ok: true, block: normalizeAttachment({ type: 'file', attachment: { ...ref, name: ref.name ?? name } }) } };
|
|
61
|
+
}
|
|
62
|
+
return failure(400, 'E_INVALID_ARGUMENT', 'kind must be image or file');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** 账本主对话里第 seq 条消息的第 index 个附件;没有返回 null。 */
|
|
66
|
+
export function attachmentAt(state, seq, index) {
|
|
67
|
+
const entry = (state?.stream ?? []).find((candidate) => candidate.seq === seq);
|
|
68
|
+
const block = Array.isArray(entry?.attachments) ? entry.attachments[index] : undefined;
|
|
69
|
+
return block === undefined ? null : normalizeAttachment(block);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @param {{ store: any, state: any, url: URL }} options
|
|
74
|
+
* @returns {Promise<{ status: number, body?: object, bytes?: Uint8Array | AsyncIterable<Uint8Array>, contentType?: string, name?: string }>}
|
|
75
|
+
*/
|
|
76
|
+
export async function readAttachment({ store, state, url }) {
|
|
77
|
+
if (store === undefined || store === null) return failure(503, 'E_ATTACHMENTS_UNAVAILABLE', 'the Host has no attachment store');
|
|
78
|
+
const seq = Number(url.searchParams.get('seq'));
|
|
79
|
+
const index = Number(url.searchParams.get('index'));
|
|
80
|
+
if (!Number.isSafeInteger(seq) || !Number.isSafeInteger(index) || index < 0) return failure(400, 'E_INVALID_ARGUMENT', 'seq and index are required');
|
|
81
|
+
const block = attachmentAt(state, seq, index);
|
|
82
|
+
if (block === null) return failure(404, 'E_NOT_FOUND', `no attachment ${index} on stream message ${seq}`);
|
|
83
|
+
if (block.type === 'image') {
|
|
84
|
+
const stored = await store.readImage(block.attachment);
|
|
85
|
+
return { status: 200, bytes: stored.data, contentType: block.attachment.mediaType, name: block.attachment.name ?? '' };
|
|
86
|
+
}
|
|
87
|
+
return { status: 200, bytes: store.readFileStream(block.attachment), contentType: 'application/octet-stream', name: block.attachment.name };
|
|
88
|
+
}
|
package/lib/host/service.js
CHANGED
|
@@ -26,6 +26,7 @@ import { MEMBER_STATUS, isBoardIdle } from '../ledger/fold.js';
|
|
|
26
26
|
|
|
27
27
|
const MEMBER_STATUS_VALUES = new Set(Object.values(MEMBER_STATUS));
|
|
28
28
|
import { checkPersonality, isQaMember, unfinishedTasksFor } from '../domain/member-profile.js';
|
|
29
|
+
import { describeAttachments, findMentions, normalizeAttachments } from '../domain/rich-message.js';
|
|
29
30
|
|
|
30
31
|
function mentionsHuman(body) {
|
|
31
32
|
return typeof body === 'string'
|
|
@@ -673,8 +674,11 @@ export class TeamService {
|
|
|
673
674
|
}
|
|
674
675
|
|
|
675
676
|
async postStream(command, payload) {
|
|
676
|
-
|
|
677
|
-
|
|
677
|
+
// #65:主对话消息可带图片/文件(DSH 附件存储的持久引用);只有附件没有文字也算一条消息。
|
|
678
|
+
const attachments = normalizeAttachments(payload.attachments);
|
|
679
|
+
const typed = typeof payload.body === 'string' ? payload.body.trim() : '';
|
|
680
|
+
if (typed === '' && attachments.length === 0) fail(ERRORS.INVALID_ARGUMENT, 'stream message body is required');
|
|
681
|
+
const body = typed === '' ? describeAttachments(attachments) : typed;
|
|
678
682
|
const author = this.state.members?.[command.actor.memberId];
|
|
679
683
|
if (author === undefined) fail(ERRORS.UNAUTHORIZED, 'actor must be a Team member');
|
|
680
684
|
// seq 由账本事件定(fold 用 event.seq;payload 里的幻影计数会被忽略,
|
|
@@ -685,12 +689,16 @@ export class TeamService {
|
|
|
685
689
|
const taskIds = Array.isArray(payload.taskIds)
|
|
686
690
|
? [...new Set(payload.taskIds.filter((id) => typeof id === 'string' && Object.hasOwn(this.state.tasks ?? {}, id)))]
|
|
687
691
|
: [];
|
|
692
|
+
// @成员只对 Human 的话生效(负责人照常收到,被点名者另行唤醒,见 waker)。
|
|
693
|
+
const mentions = command.actor.kind === 'human' ? findMentions(body, this.state.members) : [];
|
|
688
694
|
const entry = {
|
|
689
695
|
kind: command.actor.kind === 'human' ? 'human_message' : 'milestone',
|
|
690
696
|
authorId: author.id,
|
|
691
697
|
body,
|
|
692
698
|
at: this.now(),
|
|
693
699
|
...(taskIds.length > 0 ? { taskIds } : {}),
|
|
700
|
+
...(attachments.length > 0 ? { attachments } : {}),
|
|
701
|
+
...(mentions.length > 0 ? { mentions } : {}),
|
|
694
702
|
};
|
|
695
703
|
const event = await this.ledger.append({
|
|
696
704
|
type: 'stream/posted',
|
package/lib/host/waker.js
CHANGED
|
@@ -9,11 +9,16 @@
|
|
|
9
9
|
import { PERSONALITY_LIMIT, eligibleReviewers, isQaMember, unfinishedTasksFor } from '../domain/member-profile.js';
|
|
10
10
|
import { isReviewCandidate } from '../domain/policy.js';
|
|
11
11
|
import { isBoardIdle } from '../ledger/fold.js';
|
|
12
|
+
import { describeAttachments, normalizeAttachments } from '../domain/rich-message.js';
|
|
12
13
|
|
|
13
14
|
function text(value) {
|
|
14
15
|
return typeof value === 'string' ? value : '';
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
function stringIds(value) {
|
|
19
|
+
return Array.isArray(value) ? [...new Set(value.filter((id) => typeof id === 'string' && id !== ''))] : [];
|
|
20
|
+
}
|
|
21
|
+
|
|
17
22
|
function agentMember(state, memberId) {
|
|
18
23
|
if (typeof memberId !== 'string') return null;
|
|
19
24
|
const member = state.members?.[memberId];
|
|
@@ -243,13 +248,33 @@ export function planWakes(state, result, actor = {}, options = {}) {
|
|
|
243
248
|
.filter((member) => member.kind === 'agent' && member.status !== 'retired')
|
|
244
249
|
.map((member) => `${member.name}=${member.id}(${member.role || '成员'})`)
|
|
245
250
|
.join('、');
|
|
251
|
+
const attachments = normalizeAttachments(event.payload?.attachments);
|
|
252
|
+
const attachmentNote = attachments.length > 0 ? `(${describeAttachments(attachments)},就在这条消息里,先看再判断。)` : '';
|
|
253
|
+
const mentioned = stringIds(event.payload?.mentions).filter((id) => state.members?.[id]?.kind === 'agent' && state.members[id].status !== 'retired');
|
|
254
|
+
const mentionNames = mentioned.map((id) => state.members[id].name).join('、');
|
|
255
|
+
const mentionNote = mentioned.length > 0 ? `Human 点名了 ${mentionNames},他们也直接收到了这句话;安排时以他们为先。` : '';
|
|
256
|
+
const ownerName = state.members?.[project?.ownerMemberId]?.name ?? '负责人';
|
|
246
257
|
add(
|
|
247
258
|
project?.ownerMemberId,
|
|
248
259
|
null,
|
|
249
260
|
'human_message',
|
|
250
261
|
`human_message:${event.seq ?? event.payload?.seq}`,
|
|
251
|
-
`你是本项目的 PMO(Project owner)。Human 在主对话说:“${body.slice(0, 2000)}
|
|
262
|
+
`你是本项目的 PMO(Project owner)。Human 在主对话说:“${body.slice(0, 2000)}”。${attachmentNote}${mentionNote}Human 只看主对话,你是唯一在主对话回应 Human 的成员。先判断这句话是什么:\n- 打招呼、提问、确认、闲聊 → 直接用 team action=say 在主对话回答,不建卡。\n- 要团队完成的工作 → 先用 team action=members 看成员,再用 action=create 建卡(ownerId/assigneeId 用成员 id,resultDefinition 写可验证的验收标准,需要独立复跑时 qaRequired=true 并给 qaChecklist),然后用 action=say 在主对话告诉 Human 你的安排并用 taskIds 附上这些卡。需求很大或含糊时先建一张「澄清/拆解」卡,不要直接开始实现。\n只做 Human 要的范围,不要自行扩大。需要 Human 拍板的问题用 action=askHuman。可用成员:${roster || '无'}。`,
|
|
252
263
|
);
|
|
264
|
+
// #65:被 @ 的成员直接收到这句话(负责人照常收到并掌握全局)。
|
|
265
|
+
for (const memberId of mentioned) {
|
|
266
|
+
if (memberId === project?.ownerMemberId) continue;
|
|
267
|
+
add(
|
|
268
|
+
memberId,
|
|
269
|
+
null,
|
|
270
|
+
'human_mention',
|
|
271
|
+
`human_mention:${event.seq ?? event.payload?.seq}`,
|
|
272
|
+
`Human 在主对话点名你:“${body.slice(0, 2000)}”。${attachmentNote}项目负责人(${ownerName})也收到了这句话并统筹安排。先读 tasks 与主对话,再从你的岗位回应:要说明的用 team action=say 在主对话回复 Human;需要建卡、改派的交给负责人,不要自己另开一摊。`,
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
for (const plan of targets.values()) {
|
|
276
|
+
if (attachments.length > 0 && (plan.reason === 'human_message' || plan.reason === 'human_mention')) plan.attachments = attachments;
|
|
277
|
+
}
|
|
253
278
|
}
|
|
254
279
|
if (event?.type === 'pmo/review') {
|
|
255
280
|
const task = state.tasks?.[event.payload?.taskId];
|
package/lib/ledger/fold.js
CHANGED
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
|
|
33
33
|
import { GENESIS_HASH, isPlainObject } from './events.js';
|
|
34
34
|
import { isReviewCandidate } from '../domain/policy.js';
|
|
35
|
+
import { normalizeAttachments } from '../domain/rich-message.js';
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
38
|
* 投影状态版本;改动折叠语义时必须递增(03 §6.4)。
|
|
@@ -640,6 +641,9 @@ function applyStreamPosted(state, event, payload) {
|
|
|
640
641
|
taskIds: stringArray(payload.taskIds),
|
|
641
642
|
parentEventId: stringOrNull(payload.parentEventId),
|
|
642
643
|
at: event.at,
|
|
644
|
+
// #65:图片/文件引用与 @成员;旧事件没有这两个字段,投影里也不出现。
|
|
645
|
+
...(Array.isArray(payload.attachments) && payload.attachments.length > 0 ? { attachments: normalizeAttachments(payload.attachments) } : {}),
|
|
646
|
+
...(stringArray(payload.mentions).length > 0 ? { mentions: stringArray(payload.mentions) } : {}),
|
|
643
647
|
};
|
|
644
648
|
// 事件按 seq 递增到达(applyEvent 已挡住 seq <= lastSeq),直接追加即可;
|
|
645
649
|
// 只有手工构造的乱序回放才需要插入排序,用末尾比较识别。投影按
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* @param {{
|
|
23
23
|
* on?: (name: string, listener: Function) => (() => void),
|
|
24
24
|
* isHostSession: (sessionId: string) => ({ projectId: string } | null),
|
|
25
|
-
* forwardHuman: (projectId: string, text: string) => Promise<unknown>,
|
|
25
|
+
* forwardHuman: (projectId: string, text: string, attachments: object[]) => Promise<unknown>,
|
|
26
26
|
* forwardMember: (projectId: string, senderSessionId: string, text: string) => Promise<unknown>,
|
|
27
27
|
* diag?: { append?: (row: object) => void },
|
|
28
28
|
* }} options
|
|
@@ -36,6 +36,8 @@ export function registerHostSessionGate({ on, isHostSession, forwardHuman, forwa
|
|
|
36
36
|
.replace(/^Agent \S+ sent a message:\s*/, '')
|
|
37
37
|
.trim();
|
|
38
38
|
const kindOf = (message) => message?.source?.kind ?? null;
|
|
39
|
+
const attachmentsOf = (message) => (Array.isArray(message?.content) ? message.content : [])
|
|
40
|
+
.filter((block) => block?.type === 'image' || block?.type === 'file');
|
|
39
41
|
const preStep = async (payload, next) => {
|
|
40
42
|
const sessionId = payload?.agent?.session?.header?.id ?? payload?.agent?.session?.id ?? payload?.agent?.id;
|
|
41
43
|
if (payload?.step !== 1 || typeof sessionId !== 'string') return next();
|
|
@@ -43,10 +45,13 @@ export function registerHostSessionGate({ on, isHostSession, forwardHuman, forwa
|
|
|
43
45
|
if (host === null) return next();
|
|
44
46
|
const messages = Array.isArray(payload?.messages) ? payload.messages : [];
|
|
45
47
|
const row = { projectId: host.projectId, sessionId, turn: payload.turn ?? null };
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
// #65:Human 在 DSH 标准会话里贴的图片/文件(已落盘的附件引用)随文字一起转进主对话。
|
|
49
|
+
const human = messages.filter((message) => kindOf(message) === 'user')
|
|
50
|
+
.map((message) => ({ text: textOf(message), attachments: attachmentsOf(message) }))
|
|
51
|
+
.filter((said) => said.text !== '' || said.attachments.length > 0);
|
|
52
|
+
for (const { text, attachments } of human) {
|
|
48
53
|
try {
|
|
49
|
-
await forwardHuman(host.projectId, text);
|
|
54
|
+
await forwardHuman(host.projectId, text, attachments);
|
|
50
55
|
} catch (error) {
|
|
51
56
|
diag?.append?.({ ev: 'host.human.forward.fail', ...row, message: error?.message ?? String(error) });
|
|
52
57
|
return next();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@suifei/dsh-ai-team",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.121",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "文渊阁 (Wenyuan Pavilion) — AI Team mode for DeepSeek Harness: concurrent projects, owned tasks, threads, inbox and an append-only team ledger",
|
|
6
6
|
"license": "MIT",
|