lemma-agent 1.1.1 → 1.1.3
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/dist/admin.js +79 -5
- package/dist/change-ops.js +84 -0
- package/dist/cli-runner.js +34 -0
- package/dist/config.js +44 -0
- package/dist/dispatch.js +15 -1
- package/dist/jobs.js +14 -0
- package/dist/main.js +64 -4
- package/dist/onboarding.js +428 -0
- package/dist/proxy.js +204 -67
- package/dist/terminal.js +59 -31
- package/dist/tools.js +1 -0
- package/package.json +1 -1
- package/web/js/editors.js +96 -0
- package/web/js/gitlens.js +178 -11
- package/web/js/views.js +32 -5
- package/web/style.css +71 -0
package/dist/tools.js
CHANGED
|
@@ -85,6 +85,7 @@ function createJobTask(deps, commands, onSettled) {
|
|
|
85
85
|
},
|
|
86
86
|
memo: (name, candidate) => (candidate === undefined ? runtime.memo(name, context) : runtime.memo(name, candidate, context)),
|
|
87
87
|
output: (chunk) => hub.output(input.job, chunk),
|
|
88
|
+
onRuntimeState: (state, detail) => hub.setRuntimeState(input.job, state, detail),
|
|
88
89
|
details: async (value) => {
|
|
89
90
|
await runtime.commit(async (tx) => {
|
|
90
91
|
const job = (await tx.doc(Jobs)).jobs[input.job];
|
package/package.json
CHANGED
package/web/js/editors.js
CHANGED
|
@@ -297,6 +297,102 @@ export function openAutonomyEditor(autonomy) {
|
|
|
297
297
|
});
|
|
298
298
|
}
|
|
299
299
|
|
|
300
|
+
export function openOnboardingWizard(state) {
|
|
301
|
+
const presets = state?.onboardingPresets ?? [];
|
|
302
|
+
const discovered = state?.proxyStatus?.discoveredAccounts ?? [];
|
|
303
|
+
const curOrch = state?.orchestrator ?? {};
|
|
304
|
+
const curProxy = state?.proxyStatus ?? {};
|
|
305
|
+
const budgetUsd = state?.budget?.perRunUsd ?? 3;
|
|
306
|
+
const accountsLine = discovered.length
|
|
307
|
+
? discovered.map((a) => `${a.detected ? "●" : "○"} ${esc(a.provider)}:${a.detected ? esc(a.authMode) : "无"}`).join(" · ")
|
|
308
|
+
: "未扫描本机账号";
|
|
309
|
+
|
|
310
|
+
openModal({
|
|
311
|
+
title: "首次配置引导 · 接入模型与本地网关",
|
|
312
|
+
submitText: "保存并启用",
|
|
313
|
+
bodyHtml: `
|
|
314
|
+
<p class="edit-note">本机已检测:${accountsLine}</p>
|
|
315
|
+
<div class="field-grid">
|
|
316
|
+
<label class="field"><span>接入模式</span><select name="mode">
|
|
317
|
+
<option value="byok"${curProxy.mode !== "relay" ? " selected" : ""}>自带 API Key / 多 Key 池 (BYOK)</option>
|
|
318
|
+
<option value="relay"${curProxy.mode === "relay" ? " selected" : ""}>云端托管中转 (Hosted Relay)</option>
|
|
319
|
+
<option value="native">保留本机已有登录态 / 环境变量</option>
|
|
320
|
+
</select></label>
|
|
321
|
+
<label class="field" data-sec="byok"><span>服务商预设</span><select name="preset">
|
|
322
|
+
${presets.map((p) => `<option value="${esc(p.id)}">${esc(p.label)}</option>`).join("")}
|
|
323
|
+
</select></label>
|
|
324
|
+
</div>
|
|
325
|
+
<div class="field-grid" data-sec="endpoint">
|
|
326
|
+
<label class="field"><span>协议类型</span><select name="type">
|
|
327
|
+
<option value="openai-compatible"${curOrch.type === "openai-compatible" ? " selected" : ""}>openai-compatible</option>
|
|
328
|
+
<option value="anthropic-compatible"${curOrch.type !== "openai-compatible" ? " selected" : ""}>anthropic-compatible</option>
|
|
329
|
+
</select></label>
|
|
330
|
+
<label class="field"><span>默认模型 ID</span><input name="modelId" value="${esc(curOrch.modelId ?? "")}" placeholder="如 deepseek-chat / claude-sonnet-5-5" /></label>
|
|
331
|
+
</div>
|
|
332
|
+
<label class="field" data-sec="byok-url"><span>API Base URL</span><input name="baseUrl" type="url" value="${esc(curOrch.baseUrl ?? presets[0]?.baseUrl ?? "")}" placeholder="https://api.deepseek.com" /></label>
|
|
333
|
+
<label class="field" data-sec="relay-url" hidden><span>云端 Relay 地址</span><input name="relayUrl" type="url" placeholder="https://relay.example.com" /></label>
|
|
334
|
+
<label class="field" data-sec="secret"><span>API Key / 平台 Token(支持逗号或换行填多把 Key,隐藏保存至 credentials.json)</span><textarea name="secret" rows="2" placeholder="sk-...(多把 Key 自动组成防 429 粘性池;留空保留现存凭据)" autocomplete="new-password"></textarea></label>
|
|
335
|
+
<div class="field-grid" data-sec="gateway">
|
|
336
|
+
<label class="field"><span>多渠道/多 Key 路由策略</span><select name="strategy">
|
|
337
|
+
<option value="rotate" selected>rotate(缓存粘性轮转)</option>
|
|
338
|
+
<option value="order">order(主备顺序容灾)</option>
|
|
339
|
+
</select></label>
|
|
340
|
+
<label class="field"><span>出站脱敏策略</span><select name="redactAction">
|
|
341
|
+
<option value="mask" selected>mask(确定性占位符脱敏)</option>
|
|
342
|
+
<option value="warn">warn(仅记录审计告警)</option>
|
|
343
|
+
<option value="block">block(命中敏感密钥拦截)</option>
|
|
344
|
+
</select></label>
|
|
345
|
+
<label class="field"><span>单轮预算上限(美元,留空不限)</span><input name="perRunUsd" type="number" min="0" step="0.1" value="${budgetUsd == null ? "" : esc(budgetUsd)}" /></label>
|
|
346
|
+
</div>
|
|
347
|
+
<label class="check-chip" data-sec="bridge"><input type="checkbox" name="enableBridge" /> 启用 Anthropic↔OpenAI 轻量桥接(用该 API 同步驱动 Claude CLI)</label>
|
|
348
|
+
`,
|
|
349
|
+
onMount(body) {
|
|
350
|
+
const modeEl = body.querySelector('[name="mode"]');
|
|
351
|
+
const presetEl = body.querySelector('[name="preset"]');
|
|
352
|
+
const typeEl = body.querySelector('[name="type"]');
|
|
353
|
+
const modelEl = body.querySelector('[name="modelId"]');
|
|
354
|
+
const baseEl = body.querySelector('[name="baseUrl"]');
|
|
355
|
+
const syncPreset = () => {
|
|
356
|
+
const p = presets.find((x) => x.id === presetEl?.value);
|
|
357
|
+
if (!p || p.id === "custom") return;
|
|
358
|
+
if (typeEl) typeEl.value = p.type;
|
|
359
|
+
if (baseEl) baseEl.value = p.baseUrl;
|
|
360
|
+
if (modelEl) modelEl.value = p.defaultModel;
|
|
361
|
+
};
|
|
362
|
+
const syncMode = () => {
|
|
363
|
+
const m = modeEl?.value;
|
|
364
|
+
body.querySelectorAll('[data-sec="byok"],[data-sec="byok-url"]').forEach((n) => (n.hidden = m !== "byok"));
|
|
365
|
+
body.querySelectorAll('[data-sec="relay-url"]').forEach((n) => (n.hidden = m !== "relay"));
|
|
366
|
+
body.querySelectorAll('[data-sec="endpoint"],[data-sec="secret"]').forEach((n) => (n.hidden = m === "native"));
|
|
367
|
+
body.querySelectorAll('[data-sec="bridge"]').forEach((n) => (n.hidden = m !== "byok"));
|
|
368
|
+
};
|
|
369
|
+
presetEl?.addEventListener("change", syncPreset);
|
|
370
|
+
modeEl?.addEventListener("change", syncMode);
|
|
371
|
+
if (presets[0] && !curOrch.baseUrl) syncPreset();
|
|
372
|
+
syncMode();
|
|
373
|
+
},
|
|
374
|
+
async onSubmit(body) {
|
|
375
|
+
const val = (n) => body.querySelector(`[name="${n}"]`)?.value ?? "";
|
|
376
|
+
const mode = val("mode");
|
|
377
|
+
const res = await post("/api/onboarding", {
|
|
378
|
+
mode,
|
|
379
|
+
preset: val("preset"),
|
|
380
|
+
type: val("type"),
|
|
381
|
+
baseUrl: val("baseUrl").trim(),
|
|
382
|
+
modelId: val("modelId").trim(),
|
|
383
|
+
relayUrl: val("relayUrl").trim(),
|
|
384
|
+
secret: val("secret"),
|
|
385
|
+
strategy: val("strategy"),
|
|
386
|
+
redactAction: val("redactAction"),
|
|
387
|
+
enableBridge: Boolean(body.querySelector('[name="enableBridge"]')?.checked),
|
|
388
|
+
enableProxy: true,
|
|
389
|
+
perRunUsd: val("perRunUsd").trim() === "" ? null : Number(val("perRunUsd")),
|
|
390
|
+
});
|
|
391
|
+
return res?.summary || "初始化配置已保存";
|
|
392
|
+
},
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
|
|
300
396
|
export function openOrchestratorEditor(orch) {
|
|
301
397
|
openModal({
|
|
302
398
|
title: "配置总控模型与接口",
|
package/web/js/gitlens.js
CHANGED
|
@@ -18,16 +18,49 @@ const CHANGE_LABEL = { running: "进行中", pending: "待合并", conflict: "
|
|
|
18
18
|
const CHANGE_PILL = { running: "running", pending: "pending", conflict: "error", applied: "done", empty: "aborted", dropped: "aborted" };
|
|
19
19
|
const GATE_ACTION_LABEL = { commit: "提交确认", push: "推送确认", force_push: "风险强推 / 分叉", pull: "分叉拉取" };
|
|
20
20
|
|
|
21
|
-
/** 统一差异 →
|
|
22
|
-
export function renderDiff(text) {
|
|
21
|
+
/** 统一差异 → 带行号的着色视图(先转义,不信任内容;支持可选行级批注) */
|
|
22
|
+
export function renderDiff(text, opts = {}) {
|
|
23
23
|
if (!text.trim()) return `<div class="empty-inline"><span class="dot"></span>没有差异</div>`;
|
|
24
24
|
const out = [];
|
|
25
25
|
let oldNo = 0;
|
|
26
26
|
let newNo = 0;
|
|
27
|
+
let currentFile = "";
|
|
28
|
+
const commentable = Boolean(opts.commentable && opts.changeId);
|
|
29
|
+
const comments = Array.isArray(opts.comments) ? opts.comments : [];
|
|
30
|
+
const active = opts.activeTarget;
|
|
31
|
+
|
|
32
|
+
const renderLineExtras = (file, line) => {
|
|
33
|
+
if (!commentable || !file || !line) return "";
|
|
34
|
+
const items = comments.filter((c) => c.file === file && Number(c.line) === Number(line));
|
|
35
|
+
const commentRows = items
|
|
36
|
+
.map(
|
|
37
|
+
(c) => `<div class="df-comment-row">
|
|
38
|
+
<span class="mono muted">${esc(c.file)}:${esc(String(c.line))}</span>
|
|
39
|
+
<span class="df-comment-text">${esc(c.note)}</span>
|
|
40
|
+
<button type="button" class="linkish tiny" data-del-comment="${esc(opts.changeId)}" data-comment-id="${esc(c.id)}">删除</button>
|
|
41
|
+
</div>`,
|
|
42
|
+
)
|
|
43
|
+
.join("");
|
|
44
|
+
const isEditing = active && active.changeId === opts.changeId && active.file === file && Number(active.line) === Number(line);
|
|
45
|
+
const editor = isEditing
|
|
46
|
+
? `<div class="df-comment-form" data-comment-box="${esc(opts.changeId)}">
|
|
47
|
+
<input type="text" class="df-comment-input" data-n="inlineCommentInput" placeholder="输入对该行 (${esc(file)}:${esc(String(line))}) 的修改批注,Enter 保存…" />
|
|
48
|
+
<button type="button" class="primary-btn tiny" data-save-comment="${esc(opts.changeId)}" data-file="${esc(file)}" data-line="${esc(String(line))}">保存批注</button>
|
|
49
|
+
<button type="button" class="ghost-btn tiny" data-cancel-comment="1">取消</button>
|
|
50
|
+
</div>`
|
|
51
|
+
: "";
|
|
52
|
+
return commentRows + editor;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const commentBtn = (file, line) =>
|
|
56
|
+
commentable && file && line
|
|
57
|
+
? `<button type="button" class="df-comment-btn" title="在此行添加批注" data-comment-line="${esc(opts.changeId)}" data-file="${esc(file)}" data-line="${esc(String(line))}">+</button>`
|
|
58
|
+
: "";
|
|
59
|
+
|
|
27
60
|
for (const line of text.split("\n")) {
|
|
28
61
|
if (line.startsWith("diff --git")) {
|
|
29
|
-
|
|
30
|
-
out.push(`<div class="df-file">${esc(
|
|
62
|
+
currentFile = line.replace(/^diff --git a\/(.+?) b\/.+$/, "$1");
|
|
63
|
+
out.push(`<div class="df-file">${esc(currentFile)}</div>`);
|
|
31
64
|
continue;
|
|
32
65
|
}
|
|
33
66
|
if (/^(index |--- |\+\+\+ |new file mode|deleted file mode|similarity|rename )/.test(line)) continue;
|
|
@@ -38,10 +71,22 @@ export function renderDiff(text) {
|
|
|
38
71
|
out.push(`<div class="df-hunk"><span></span><span></span><code>${esc(line)}</code></div>`);
|
|
39
72
|
continue;
|
|
40
73
|
}
|
|
41
|
-
if (line.startsWith("+"))
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
74
|
+
if (line.startsWith("+")) {
|
|
75
|
+
const ln = newNo++;
|
|
76
|
+
out.push(`<div class="df-line add${commentable ? " commentable" : ""}" data-diff-file="${esc(currentFile)}" data-diff-line="${ln}"><span></span><span>${ln}</span><code>${commentBtn(currentFile, ln)}${esc(line)}</code></div>`);
|
|
77
|
+
out.push(renderLineExtras(currentFile, ln));
|
|
78
|
+
} else if (line.startsWith("-")) {
|
|
79
|
+
const ln = oldNo++;
|
|
80
|
+
out.push(`<div class="df-line del${commentable ? " commentable" : ""}" data-diff-file="${esc(currentFile)}" data-diff-line="${ln}"><span>${ln}</span><span></span><code>${commentBtn(currentFile, ln)}${esc(line)}</code></div>`);
|
|
81
|
+
out.push(renderLineExtras(currentFile, ln));
|
|
82
|
+
} else if (line.startsWith("\\")) {
|
|
83
|
+
out.push(`<div class="df-line meta"><span></span><span></span><code>${esc(line)}</code></div>`);
|
|
84
|
+
} else if (line.length || oldNo) {
|
|
85
|
+
oldNo++;
|
|
86
|
+
const ln = newNo++;
|
|
87
|
+
out.push(`<div class="df-line${commentable ? " commentable" : ""}" data-diff-file="${esc(currentFile)}" data-diff-line="${ln}"><span>${oldNo - 1}</span><span>${ln}</span><code>${commentBtn(currentFile, ln)}${esc(line || " ")}</code></div>`);
|
|
88
|
+
out.push(renderLineExtras(currentFile, ln));
|
|
89
|
+
}
|
|
45
90
|
}
|
|
46
91
|
return `<div class="diff">${out.join("")}</div>`;
|
|
47
92
|
}
|
|
@@ -202,6 +247,9 @@ export function createChangesView() {
|
|
|
202
247
|
let loadingDetail = false;
|
|
203
248
|
let divergedPrompt = null; // { branch, remote, ahead, behind, error } | null
|
|
204
249
|
let lastGateSig = "";
|
|
250
|
+
const changeComments = new Map(); // changeId -> Array<{ id, file, line, note }>
|
|
251
|
+
let activeCommentTarget = null; // { changeId, file, line } | null
|
|
252
|
+
const changeDrafts = new Map(); // changeId -> ChangeDeliveryDraft
|
|
205
253
|
|
|
206
254
|
function renderGraphRowsHtml(laneRows, maxLanes, emptyMsg) {
|
|
207
255
|
return laneRows.length
|
|
@@ -552,13 +600,15 @@ export function createChangesView() {
|
|
|
552
600
|
}).join("") : `<div class="empty-inline"><span class="dot"></span>没有文件变更</div>`}
|
|
553
601
|
</div>
|
|
554
602
|
<h3 class="eyebrow">${selectedFile ? `Diff · ${esc(selectedFile)}` : "Diff 视图"}</h3>
|
|
555
|
-
<div data-n="diff">${d.diff ? renderDiff(d.diff) : `<div class="empty-inline"><span class="dot"></span>无文本差异(可能是二进制或未跟踪空文件)</div>`}${d.truncated ? `<p class="footnote">差异超过 350KB 已截断,可点击上方单个文件查看局部 Diff。</p>` : ""}</div>
|
|
603
|
+
<div data-n="diff">${d.diff ? renderDiff(d.diff, primaryChange ? { commentable: actionable, changeId: primaryChange.id, comments: changeComments.get(primaryChange.id) ?? [], activeTarget: activeCommentTarget } : {}) : `<div class="empty-inline"><span class="dot"></span>无文本差异(可能是二进制或未跟踪空文件)</div>`}${d.truncated ? `<p class="footnote">差异超过 350KB 已截断,可点击上方单个文件查看局部 Diff。</p>` : ""}</div>
|
|
556
604
|
</div>`;
|
|
557
605
|
bindInspectorEvents(box, primaryChange, d.isWorktree);
|
|
558
606
|
}
|
|
559
607
|
|
|
560
608
|
function renderLinkedChangeBanner(c, actionable, dispatch) {
|
|
561
609
|
const cmd = (verb) => `/${verb} ${c.id}`;
|
|
610
|
+
const comments = changeComments.get(c.id) ?? [];
|
|
611
|
+
const draft = changeDrafts.get(c.id);
|
|
562
612
|
return `<div class="change-msg gl-change-card">
|
|
563
613
|
<div class="gl-change-card-top">
|
|
564
614
|
<strong>Lemma 改动 #${esc(c.id)}</strong>
|
|
@@ -569,10 +619,25 @@ export function createChangesView() {
|
|
|
569
619
|
${c.message ? `<p>${esc(c.message)}</p>` : ""}
|
|
570
620
|
<div class="row-actions">
|
|
571
621
|
${actionable ? `<button type="button" class="primary-btn tiny" data-apply-change="${esc(c.id)}">合并到主目录</button>` : ""}
|
|
622
|
+
${actionable ? `<button type="button" class="ghost-btn tiny" data-revise-change="${esc(c.id)}">${comments.length ? `打回修改 (${comments.length} 条批注)` : "打回修改"}</button>` : ""}
|
|
623
|
+
${c.status !== "dropped" ? `<button type="button" class="ghost-btn tiny" data-draft-change="${esc(c.id)}">Commit / PR 草稿</button>` : ""}
|
|
572
624
|
${c.branch && c.status !== "dropped" ? `<button type="button" class="ghost-btn tiny" data-push-branch="${esc(c.branch)}">推送分支到远端</button>` : ""}
|
|
573
625
|
${actionable ? `<button type="button" class="ghost-btn tiny" data-drop-change="${esc(c.id)}">丢弃改动</button>` : ""}
|
|
574
626
|
${actionable ? `<button type="button" class="copy-cmd mono" data-copy="${cmd("apply")}">${cmd("apply")}</button>` : ""}
|
|
575
627
|
</div>
|
|
628
|
+
${
|
|
629
|
+
comments.length
|
|
630
|
+
? `<div class="gl-comment-summary"><span>待提交批注 ${comments.length} 条(点击 Diff 代码行左侧 + 可继续添加)</span><button type="button" class="linkish tiny" data-clear-comments="${esc(c.id)}">清空</button></div>`
|
|
631
|
+
: ""
|
|
632
|
+
}
|
|
633
|
+
${
|
|
634
|
+
draft
|
|
635
|
+
? `<div class="gl-draft-box">
|
|
636
|
+
<div class="gl-draft-head"><strong>交付草稿(Commit / PR)</strong><div class="row-actions"><button type="button" class="ghost-btn tiny" data-copy-draft="${esc(c.id)}" data-kind="commit">复制 Commit</button><button type="button" class="ghost-btn tiny" data-copy-draft="${esc(c.id)}" data-kind="pr">复制 PR</button><button type="button" class="ghost-btn tiny" data-copy-draft="${esc(c.id)}" data-kind="gh">复制 gh 命令</button></div></div>
|
|
637
|
+
<pre class="gl-draft-pre mono">${esc(draft.commitMessage)}</pre>
|
|
638
|
+
</div>`
|
|
639
|
+
: ""
|
|
640
|
+
}
|
|
576
641
|
${c.integration ? `<div class="gl-int-sub"><strong>联合集成 · ${esc(c.integration.status)}${c.integration.supersededBy ? `(已被 #${esc(c.integration.supersededBy)} 替代)` : ""}</strong><p>来源:${c.integration.sources.map((s) => `<a href="#/changes/${esc(s.id)}">#${esc(s.id)}</a>`).join(" + ")}</p>${(c.integration.reports ?? []).map((rp) => `<details><summary>${esc(rp.name)} · ${rp.passed ? "通过" : "失败"}</summary><pre>${esc(rp.output || "没有输出")}</pre></details>`).join("")}${!c.integration.supersededBy && !["applied", "dropped"].includes(c.status) ? `<div class="row-actions">${["conflict", "failed"].includes(c.integration.status) ? `<button type="button" class="primary-btn tiny" data-int-repair="${esc(c.id)}">派成员修复</button>` : ""}${!["preparing", "merging", "repairing", "testing"].includes(c.integration.status) ? `<button type="button" class="ghost-btn tiny" data-int-rerun="${esc(c.id)}">重跑集成检查</button>` : ""}</div>` : ""}</div>` : ""}
|
|
577
642
|
</div>`;
|
|
578
643
|
}
|
|
@@ -586,8 +651,8 @@ export function createChangesView() {
|
|
|
586
651
|
${renderLinkedChangeBanner(c, actionable, dispatch)}
|
|
587
652
|
<h3 class="eyebrow">改了哪些文件 <span class="eyebrow-note">${c.files.length} 个 · +${c.add} −${c.del}</span></h3>
|
|
588
653
|
<div class="file-list">${c.files.length ? c.files.map((f) => `<div class="file-row"><span class="mono">${esc(f.path)}</span>${diffBlocksHtml(f.add, f.del)}</div>`).join("") : `<div class="empty-inline"><span class="dot"></span>没有修改文件</div>`}</div>
|
|
589
|
-
<h3 class="eyebrow"
|
|
590
|
-
<div>${d.error ? `<div class="change-msg err">${esc(d.error)}</div>` : renderDiff(d.diff)}</div>
|
|
654
|
+
<h3 class="eyebrow">差异${actionable ? ` <span class="eyebrow-note">鼠标悬停代码行点击 + 可写行级批注</span>` : ""}</h3>
|
|
655
|
+
<div>${d.error ? `<div class="change-msg err">${esc(d.error)}</div>` : renderDiff(d.diff, { commentable: actionable, changeId: c.id, comments: changeComments.get(c.id) ?? [], activeTarget: activeCommentTarget })}</div>
|
|
591
656
|
</div>`;
|
|
592
657
|
}
|
|
593
658
|
|
|
@@ -802,6 +867,108 @@ export function createChangesView() {
|
|
|
802
867
|
const cid = repairBtn.dataset.intRepair;
|
|
803
868
|
const it = (store.state?.integrations ?? []).find((x) => x.id === cid) ?? store.changes.find((x) => x.id === cid)?.integration;
|
|
804
869
|
if (it) openRepairIntegrationDialog({ ...it, id: cid }, store.state?.agents ?? []);
|
|
870
|
+
return;
|
|
871
|
+
}
|
|
872
|
+
const addLineBtn = target.closest("[data-comment-line]");
|
|
873
|
+
if (addLineBtn) {
|
|
874
|
+
activeCommentTarget = {
|
|
875
|
+
changeId: addLineBtn.dataset.commentLine,
|
|
876
|
+
file: addLineBtn.dataset.file,
|
|
877
|
+
line: Number(addLineBtn.dataset.line),
|
|
878
|
+
};
|
|
879
|
+
renderInspector();
|
|
880
|
+
root.querySelector('[data-n="inlineCommentInput"]')?.focus();
|
|
881
|
+
return;
|
|
882
|
+
}
|
|
883
|
+
if (target.closest("[data-cancel-comment]")) {
|
|
884
|
+
activeCommentTarget = null;
|
|
885
|
+
renderInspector();
|
|
886
|
+
return;
|
|
887
|
+
}
|
|
888
|
+
const saveCommentBtn = target.closest("[data-save-comment]");
|
|
889
|
+
if (saveCommentBtn) {
|
|
890
|
+
const cid = saveCommentBtn.dataset.saveComment;
|
|
891
|
+
const inp = root.querySelector('[data-n="inlineCommentInput"]');
|
|
892
|
+
const noteText = inp?.value?.trim() ?? "";
|
|
893
|
+
if (!noteText) { inp?.focus(); return; }
|
|
894
|
+
const list = changeComments.get(cid) ?? [];
|
|
895
|
+
list.push({
|
|
896
|
+
id: `${Date.now()}-${Math.random().toString(36).slice(2, 6)}`,
|
|
897
|
+
file: saveCommentBtn.dataset.file,
|
|
898
|
+
line: Number(saveCommentBtn.dataset.line),
|
|
899
|
+
note: noteText,
|
|
900
|
+
});
|
|
901
|
+
changeComments.set(cid, list);
|
|
902
|
+
activeCommentTarget = null;
|
|
903
|
+
renderInspector();
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
906
|
+
const delCommentBtn = target.closest("[data-del-comment]");
|
|
907
|
+
if (delCommentBtn) {
|
|
908
|
+
const cid = delCommentBtn.dataset.delComment;
|
|
909
|
+
const commentId = delCommentBtn.dataset.commentId;
|
|
910
|
+
const nextList = (changeComments.get(cid) ?? []).filter((x) => x.id !== commentId);
|
|
911
|
+
if (nextList.length) changeComments.set(cid, nextList);
|
|
912
|
+
else changeComments.delete(cid);
|
|
913
|
+
renderInspector();
|
|
914
|
+
return;
|
|
915
|
+
}
|
|
916
|
+
const clearCommentsBtn = target.closest("[data-clear-comments]");
|
|
917
|
+
if (clearCommentsBtn) {
|
|
918
|
+
changeComments.delete(clearCommentsBtn.dataset.clearComments);
|
|
919
|
+
renderInspector();
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
const reviseBtn = target.closest("[data-revise-change]");
|
|
923
|
+
if (reviseBtn) {
|
|
924
|
+
const cid = reviseBtn.dataset.reviseChange;
|
|
925
|
+
const comments = changeComments.get(cid) ?? [];
|
|
926
|
+
let note = "";
|
|
927
|
+
if (!comments.length) {
|
|
928
|
+
note = window.prompt(`输入对改动 #${cid} 的修改意见(或在下方 Diff 行点击 + 添加行级批注):`) ?? "";
|
|
929
|
+
if (!note.trim()) return;
|
|
930
|
+
}
|
|
931
|
+
reviseBtn.disabled = true;
|
|
932
|
+
try {
|
|
933
|
+
const r = await post(`/api/changes/${encodeURIComponent(cid)}/revise`, { comments, note });
|
|
934
|
+
changeComments.delete(cid);
|
|
935
|
+
toast(`已将改动 #${cid} 打回修改(${r.commentCount ?? comments.length} 条批注)`);
|
|
936
|
+
renderInspector();
|
|
937
|
+
} catch (err) {
|
|
938
|
+
toast(err.message);
|
|
939
|
+
} finally {
|
|
940
|
+
reviseBtn.disabled = false;
|
|
941
|
+
}
|
|
942
|
+
return;
|
|
943
|
+
}
|
|
944
|
+
const draftBtn = target.closest("[data-draft-change]");
|
|
945
|
+
if (draftBtn) {
|
|
946
|
+
const cid = draftBtn.dataset.draftChange;
|
|
947
|
+
draftBtn.disabled = true;
|
|
948
|
+
try {
|
|
949
|
+
const draft = await getJson(`/api/changes/${encodeURIComponent(cid)}/draft`);
|
|
950
|
+
changeDrafts.set(cid, draft);
|
|
951
|
+
if (!commitMessageDraft && draft.commitMessage) commitMessageDraft = draft.commitMessage;
|
|
952
|
+
renderInspector();
|
|
953
|
+
} catch (err) {
|
|
954
|
+
toast(err.message);
|
|
955
|
+
} finally {
|
|
956
|
+
draftBtn.disabled = false;
|
|
957
|
+
}
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
const copyDraftBtn = target.closest("[data-copy-draft]");
|
|
961
|
+
if (copyDraftBtn) {
|
|
962
|
+
const draft = changeDrafts.get(copyDraftBtn.dataset.copyDraft);
|
|
963
|
+
if (!draft) return;
|
|
964
|
+
const kind = copyDraftBtn.dataset.kind;
|
|
965
|
+
copy(kind === "pr" ? draft.prBody : kind === "gh" ? draft.ghCommand : draft.commitMessage);
|
|
966
|
+
}
|
|
967
|
+
});
|
|
968
|
+
root.addEventListener("keydown", (e) => {
|
|
969
|
+
if (e.key === "Enter" && e.target instanceof HTMLInputElement && e.target.dataset.n === "inlineCommentInput") {
|
|
970
|
+
e.preventDefault();
|
|
971
|
+
root.querySelector("[data-save-comment]")?.click();
|
|
805
972
|
}
|
|
806
973
|
});
|
|
807
974
|
root.addEventListener("input", (e) => {
|
package/web/js/views.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// 后台各页面。每个页面:mount(root, params) 渲染,update(kind, payload) 响应数据变化,unmount() 清理。
|
|
2
2
|
import { openDispatch } from "./drawer.js";
|
|
3
3
|
import { bindDagPanelEvents, classifyTopology, renderReviewLoopPanel, renderScopeMatrix, renderTaskDag } from "./dag.js";
|
|
4
|
-
import { openAutonomyEditor, openCreateIntegrationDialog, openLimitsEditor, openMemberEditor, openOrchestratorEditor, openRecoverDialog, openRepairIntegrationDialog, openResolveOperationDialog, runControlAction } from "./editors.js";
|
|
4
|
+
import { openAutonomyEditor, openCreateIntegrationDialog, openLimitsEditor, openMemberEditor, openOnboardingWizard, openOrchestratorEditor, openRecoverDialog, openRepairIntegrationDialog, openResolveOperationDialog, runControlAction } from "./editors.js";
|
|
5
5
|
import { createChangesView } from "./gitlens.js";
|
|
6
6
|
import { METRICS, MODES, RANGES, Sankey } from "./sankey.js";
|
|
7
7
|
import { buildRuns, callInfo, dispatchRows, isDispatch, loadEarlier, pendingChanges, runningJobs, store } from "./store.js";
|
|
@@ -193,7 +193,13 @@ function overview() {
|
|
|
193
193
|
const strip = el("div", "ov-strip");
|
|
194
194
|
strip.dataset.n = "strip";
|
|
195
195
|
strip.hidden = true;
|
|
196
|
+
const onboardBanner = el("section", "card");
|
|
197
|
+
onboardBanner.dataset.n = "onboard";
|
|
198
|
+
onboardBanner.hidden = true;
|
|
199
|
+
onboardBanner.innerHTML = `<header class="card-head"><div class="card-heading"><h2 class="card-title">首次配置引导 · 接入模型与本地代理网关</h2><div class="card-sub">尚未配置总控模型密钥,可一键导入 DeepSeek/Anthropic/OpenAI 多 Key 轮转池、Cloud Relay 或本机已有方案。</div></div><button type="button" class="primary-btn" data-open-onboard="1">立即向导配置</button></header>`;
|
|
200
|
+
onboardBanner.querySelector("[data-open-onboard]").addEventListener("click", () => openOnboardingWizard(store.state));
|
|
196
201
|
root.prepend(strip);
|
|
202
|
+
root.prepend(onboardBanner);
|
|
197
203
|
root.append(routes);
|
|
198
204
|
const act = el("section", "card act-card");
|
|
199
205
|
act.innerHTML = `<header class="card-head"><div class="card-heading"><h2 class="card-title">派工活动</h2><div class="card-sub" data-n="actSum"></div></div><div class="act-legend" data-n="actLegend"></div></header><div class="card-body" data-n="act"></div>`;
|
|
@@ -219,6 +225,8 @@ function overview() {
|
|
|
219
225
|
},
|
|
220
226
|
update(kind) {
|
|
221
227
|
const q = (n) => root.querySelector(`[data-n="${n}"]`);
|
|
228
|
+
const onboard = q("onboard");
|
|
229
|
+
if (onboard) onboard.hidden = !(store.state?.needsOnboarding && store.state?.canEditSettings);
|
|
222
230
|
const strip = q("strip");
|
|
223
231
|
const wasHidden = strip?.hidden;
|
|
224
232
|
this.strip(strip);
|
|
@@ -250,14 +258,23 @@ function overview() {
|
|
|
250
258
|
const sync = store.live.tools
|
|
251
259
|
.filter((t) => t.status !== "done" && isDispatch(t.name))
|
|
252
260
|
.map((t) => ({ key: t.callId, agent: kindOf(t.name), task: callInfo(t.callId)?.task ?? "", since: slotStart.get(t.callId), last: String(t.output ?? "").trim().split("\n").at(-1) ?? "", tag: "" }));
|
|
253
|
-
const
|
|
261
|
+
const RT_BADGE = { waiting_input: "等待输入", auth_expired: "需重新登录", rate_limited: "触发限流" };
|
|
262
|
+
const jobs = runningJobs().map((j) => ({
|
|
263
|
+
key: j.callId,
|
|
264
|
+
agent: j.agent,
|
|
265
|
+
task: j.task,
|
|
266
|
+
since: j.startedAt,
|
|
267
|
+
last: (j.output ?? []).at(-1) ?? "",
|
|
268
|
+
tag: j.id,
|
|
269
|
+
rt: j.runtimeState && RT_BADGE[j.runtimeState] ? RT_BADGE[j.runtimeState] : "",
|
|
270
|
+
}));
|
|
254
271
|
const rows = [...sync, ...jobs];
|
|
255
272
|
box.hidden = !rows.length;
|
|
256
273
|
if (!rows.length) return;
|
|
257
274
|
box.innerHTML = `<span class="strip-head"><span class="pulse-dot"></span>正在执行 ${rows.length}</span>${rows
|
|
258
275
|
.map(
|
|
259
276
|
(r) => `<button type="button" class="strip-item" data-call="${esc(r.key)}" style="--c:${agentColor(r.agent)}">
|
|
260
|
-
<b>${esc(AGENT_LABEL[r.agent] ?? r.agent)}${r.tag ? ` · ${esc(r.tag)}` : ""}</b>
|
|
277
|
+
<b>${esc(AGENT_LABEL[r.agent] ?? r.agent)}${r.tag ? ` · ${esc(r.tag)}` : ""}${r.rt ? ` <span class="pill" data-s="pending">${esc(r.rt)}</span>` : ""}</b>
|
|
261
278
|
<span class="strip-task">${esc(short(r.task, 40))}</span>
|
|
262
279
|
<span class="strip-last">${esc(short(r.last, 50))}</span>
|
|
263
280
|
<time>${r.since ? duration(Date.now() - r.since) : ""}</time>
|
|
@@ -1348,6 +1365,7 @@ function usage() {
|
|
|
1348
1365
|
const ps = state.proxyStatus ?? null;
|
|
1349
1366
|
const psTotals = ps?.totals ?? { requests: 0, retries: 0, blocked: 0, redacted: 0 };
|
|
1350
1367
|
const psCooled = ps?.pool?.cooledKeys ?? [];
|
|
1368
|
+
const psChannels = ps?.pool?.channels ?? [];
|
|
1351
1369
|
const psAccounts = ps?.discoveredAccounts ?? [];
|
|
1352
1370
|
const psModels = ps?.models ?? [];
|
|
1353
1371
|
const psRedactions = ps?.recentRedactions ?? [];
|
|
@@ -1365,9 +1383,17 @@ function usage() {
|
|
|
1365
1383
|
<div class="kpis kpis-4">
|
|
1366
1384
|
<div class="kpi"><div class="kpi-top"><span class="kpi-label">网关请求</span></div><strong>${num(psTotals.requests)}</strong><span class="kpi-sub">故障切换 / 重试 ${num(psTotals.retries)} 次</span></div>
|
|
1367
1385
|
<div class="kpi"><div class="kpi-top"><span class="kpi-label">隐私脱敏</span></div><strong>${num(psTotals.redacted)}</strong><span class="kpi-sub">敏感拦截 ${num(psTotals.blocked)} 次</span></div>
|
|
1368
|
-
<div class="kpi"><div class="kpi-top"><span class="kpi-label">冷却密钥</span></div><strong>${num(psCooled.length)}</strong><span class="kpi-sub">${psCooled.length ? psCooled.map((k) => `${esc(k.poolId)} (${k.remainingSec}s)`).join(" · ") : "全部 Key 健康"}</span></div>
|
|
1386
|
+
<div class="kpi"><div class="kpi-top"><span class="kpi-label">冷却密钥</span></div><strong>${num(psCooled.length)}</strong><span class="kpi-sub">${psCooled.length ? psCooled.map((k) => `${esc(k.label || k.poolId)} (${k.remainingSec}s)`).join(" · ") : "全部 Key 健康"}</span></div>
|
|
1369
1387
|
<div class="kpi"><div class="kpi-top"><span class="kpi-label">本机已发现账号</span></div><strong>${num(psAccounts.filter((a) => a.detected).length)} / ${num(psAccounts.length)}</strong><span class="kpi-sub">${psAccounts.length ? psAccounts.map((a) => `${esc(a.provider)}:${a.detected ? esc(a.authMode) : "无"}`).join(" · ") : "已关闭扫描"}</span></div>
|
|
1370
1388
|
</div>
|
|
1389
|
+
${
|
|
1390
|
+
psChannels.length
|
|
1391
|
+
? `<div class="table-wrap" style="margin-top:12px"><table class="table">
|
|
1392
|
+
<thead><tr><th>通道池</th><th>目标</th><th>协议</th><th>健康状态</th><th class="num">成功</th><th class="num">限流/失败</th><th class="num">切流接管</th></tr></thead>
|
|
1393
|
+
<tbody>${psChannels.map((ch) => `<tr><td class="mono">${esc(ch.poolId)}</td><td>${esc(ch.label)}</td><td class="mono">${esc(ch.protocol)}</td><td>${ch.healthy ? `<span class="pill" data-s="done">健康</span>` : `<span class="pill" data-s="pending">冷却 ${ch.remainingSec}s</span>`}</td><td class="num mono">${num(ch.successes)}</td><td class="num mono">${num(ch.failures)}</td><td class="num mono">${num(ch.failovers)}</td></tr>`).join("")}</tbody>
|
|
1394
|
+
</table></div>`
|
|
1395
|
+
: ""
|
|
1396
|
+
}
|
|
1371
1397
|
${
|
|
1372
1398
|
psModels.length
|
|
1373
1399
|
? `<div class="table-wrap" style="margin-top:12px"><table class="table">
|
|
@@ -1458,6 +1484,7 @@ function config() {
|
|
|
1458
1484
|
const target = e.target instanceof Element ? e.target : null;
|
|
1459
1485
|
if (!target || !store.state) return;
|
|
1460
1486
|
if (target.closest("[data-edit-orch]")) openOrchestratorEditor(store.state.orchestrator);
|
|
1487
|
+
else if (target.closest("[data-open-onboard]")) openOnboardingWizard(store.state);
|
|
1461
1488
|
else if (target.closest("[data-edit-limits]")) openLimitsEditor(store.state);
|
|
1462
1489
|
else if (target.closest("[data-edit-autonomy]")) openAutonomyEditor(store.state.autonomy);
|
|
1463
1490
|
});
|
|
@@ -1484,7 +1511,7 @@ function config() {
|
|
|
1484
1511
|
["历史条目", num(s.entries)],
|
|
1485
1512
|
["进程", `pid ${s.pid} · 已运行 ${duration(Date.now() - s.startedAt)}`],
|
|
1486
1513
|
])}</div></section>
|
|
1487
|
-
<section class="card"><header class="card-head"><h2 class="card-title">总调度</h2>${canEdit ? `<button type="button" class="ghost-btn tiny" data-edit-orch="1">编辑总控</button>` : ""}</header>
|
|
1514
|
+
<section class="card"><header class="card-head"><h2 class="card-title">总调度</h2>${canEdit ? `<div style="display:flex;gap:8px"><button type="button" class="ghost-btn tiny" data-open-onboard="1">向导 / 网关一键配置</button><button type="button" class="ghost-btn tiny" data-edit-orch="1">编辑总控</button></div>` : ""}</header>
|
|
1488
1515
|
<div class="card-body">${dl([
|
|
1489
1516
|
["协议", code(o.type)],
|
|
1490
1517
|
["模型", code(o.modelId)],
|
package/web/style.css
CHANGED
|
@@ -5199,6 +5199,77 @@ pre {
|
|
|
5199
5199
|
align-items: center;
|
|
5200
5200
|
gap: 8px;
|
|
5201
5201
|
}
|
|
5202
|
+
.df-comment-btn {
|
|
5203
|
+
opacity: 0;
|
|
5204
|
+
border: 1px solid var(--line);
|
|
5205
|
+
background: var(--panel);
|
|
5206
|
+
color: var(--signal);
|
|
5207
|
+
border-radius: 4px;
|
|
5208
|
+
width: 16px;
|
|
5209
|
+
height: 16px;
|
|
5210
|
+
line-height: 14px;
|
|
5211
|
+
padding: 0;
|
|
5212
|
+
margin-right: 6px;
|
|
5213
|
+
cursor: pointer;
|
|
5214
|
+
font-size: 11px;
|
|
5215
|
+
}
|
|
5216
|
+
.df-line.commentable:hover .df-comment-btn,
|
|
5217
|
+
.df-comment-btn:focus-visible {
|
|
5218
|
+
opacity: 1;
|
|
5219
|
+
}
|
|
5220
|
+
.df-comment-row {
|
|
5221
|
+
display: flex;
|
|
5222
|
+
align-items: center;
|
|
5223
|
+
gap: 8px;
|
|
5224
|
+
padding: 4px 12px 4px 96px;
|
|
5225
|
+
background: color-mix(in srgb, var(--signal) 9%, var(--panel));
|
|
5226
|
+
border-left: 2px solid var(--signal);
|
|
5227
|
+
font-size: 12px;
|
|
5228
|
+
}
|
|
5229
|
+
.df-comment-text {
|
|
5230
|
+
flex: 1 1 auto;
|
|
5231
|
+
}
|
|
5232
|
+
.df-comment-form {
|
|
5233
|
+
display: flex;
|
|
5234
|
+
align-items: center;
|
|
5235
|
+
gap: 6px;
|
|
5236
|
+
padding: 6px 12px 6px 96px;
|
|
5237
|
+
background: var(--bg-soft, rgba(128, 128, 128, 0.08));
|
|
5238
|
+
}
|
|
5239
|
+
.df-comment-input {
|
|
5240
|
+
flex: 1 1 auto;
|
|
5241
|
+
min-width: 180px;
|
|
5242
|
+
}
|
|
5243
|
+
.gl-comment-summary {
|
|
5244
|
+
display: flex;
|
|
5245
|
+
align-items: center;
|
|
5246
|
+
justify-content: space-between;
|
|
5247
|
+
font-size: 12px;
|
|
5248
|
+
color: var(--signal);
|
|
5249
|
+
}
|
|
5250
|
+
.gl-draft-box {
|
|
5251
|
+
padding: 8px 10px;
|
|
5252
|
+
border: 1px solid var(--line);
|
|
5253
|
+
border-radius: 8px;
|
|
5254
|
+
background: var(--panel);
|
|
5255
|
+
display: grid;
|
|
5256
|
+
gap: 6px;
|
|
5257
|
+
}
|
|
5258
|
+
.gl-draft-head {
|
|
5259
|
+
display: flex;
|
|
5260
|
+
flex-wrap: wrap;
|
|
5261
|
+
align-items: center;
|
|
5262
|
+
justify-content: space-between;
|
|
5263
|
+
gap: 6px;
|
|
5264
|
+
font-size: 12px;
|
|
5265
|
+
}
|
|
5266
|
+
.gl-draft-pre {
|
|
5267
|
+
margin: 0;
|
|
5268
|
+
white-space: pre-wrap;
|
|
5269
|
+
font-size: 12px;
|
|
5270
|
+
max-height: 180px;
|
|
5271
|
+
overflow: auto;
|
|
5272
|
+
}
|
|
5202
5273
|
.gl-int-sub {
|
|
5203
5274
|
padding-top: 8px;
|
|
5204
5275
|
border-top: 1px dashed var(--line);
|