agent-loft 0.2.47 → 0.2.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -12
- package/package.json +1 -1
- package/src/agents/claude/driver.ts +11 -9
- package/src/agents/claude/session.ts +162 -46
- package/src/agents/claude/todos.ts +124 -0
- package/src/agents/codex/driver.ts +1 -1
- package/src/agents/codex/session.ts +104 -58
- package/src/channels/feishu/bot.ts +1 -3
- package/src/channels/feishu/cards.ts +2 -2
- package/src/channels/web/api.ts +24 -17
- package/src/channels/web/experts-api.ts +185 -0
- package/src/channels/web/skills-api.ts +1 -7
- package/src/channels/web/tasks-api.ts +9 -5
- package/src/core/command-catalog.ts +4 -6
- package/src/core/commands.ts +6 -11
- package/src/core/expert-prompt.ts +119 -0
- package/src/core/experts.ts +416 -0
- package/src/core/hub.ts +138 -102
- package/src/core/mcp.ts +253 -0
- package/src/core/memory-curator.ts +8 -9
- package/src/core/memory.ts +11 -4
- package/src/core/personal.ts +5 -1
- package/src/core/skill-runtime.ts +11 -114
- package/src/core/store.ts +30 -11
- package/src/core/task-prompt.ts +1 -1
- package/src/core/task-runner.ts +24 -11
- package/src/core/tasks-bridge.ts +7 -7
- package/src/core/tasks.ts +49 -14
- package/src/core/types.ts +11 -7
- package/src/core/uploads.ts +7 -7
- package/src/mcp/tasks-server.ts +1 -2
- package/web/css/experts.css +103 -0
- package/web/css/messages.css +193 -19
- package/web/css/overlay.css +12 -0
- package/web/css/sidebar.css +3 -2
- package/web/css/skills.css +0 -11
- package/web/css/todos.css +144 -0
- package/web/css/topbar.css +2 -2
- package/web/index.html +2 -0
- package/web/settings/experts.js +444 -0
- package/web/settings/index.js +3 -0
- package/web/settings/memory.js +21 -5
- package/web/settings/skills.js +3 -3
- package/web/state.js +5 -2
- package/web/views/composer.js +9 -17
- package/web/views/conv-actions.js +7 -9
- package/web/views/experts.js +73 -0
- package/web/views/interaction.js +65 -19
- package/web/views/layout.js +4 -3
- package/web/views/messages.js +52 -11
- package/web/views/sidebar.js +2 -2
- package/web/views/tasks.js +21 -36
- package/web/views/todos.js +71 -0
- package/web/views/topbar.js +43 -74
- package/src/core/chat-mode.ts +0 -62
- package/web/views/mention.js +0 -202
package/web/views/composer.js
CHANGED
|
@@ -6,11 +6,10 @@ import { agentLabel, renderSidebar } from "./sidebar.js";
|
|
|
6
6
|
import { draftPick, renderContext, renderTopbar, sentKeys, updateCtxVisibility } from "./topbar.js";
|
|
7
7
|
import { addItem, openConversation, openLightbox, renderEmpty, scrollToBottom } from "./messages.js";
|
|
8
8
|
import { renderScheduled } from "./schedule.js";
|
|
9
|
+
import { renderTodos } from "./todos.js";
|
|
9
10
|
import { cancelVoice, SpeechRec, toggleVoice } from "./voice.js";
|
|
10
11
|
import { closeSlashMenu, commandUsage, oneLine, slashKeydown, updateSlashMenu } from "./slash.js";
|
|
11
|
-
import { attachMention } from "./mention.js";
|
|
12
12
|
import { doAction, openModelPicker, openSessions } from "./conv-actions.js";
|
|
13
|
-
import { openSettings } from "./layout.js";
|
|
14
13
|
|
|
15
14
|
// ---------- 输入框 ----------
|
|
16
15
|
|
|
@@ -25,23 +24,21 @@ export function hideKeyboardForMenu() {
|
|
|
25
24
|
ui.input.blur();
|
|
26
25
|
}
|
|
27
26
|
document.addEventListener("pointerdown", (e) => {
|
|
28
|
-
if (!keepMenus || [ui.input, ui.slashMenu
|
|
27
|
+
if (!keepMenus || [ui.input, ui.slashMenu].some((el) => el?.contains(e.target))) return;
|
|
29
28
|
keepMenus = false;
|
|
30
29
|
closeSlashMenu();
|
|
31
|
-
ui.mention?.close();
|
|
32
30
|
});
|
|
33
31
|
|
|
34
32
|
export function renderComposer() {
|
|
35
33
|
cancelVoice();
|
|
36
34
|
ui.input = h("textarea", {
|
|
37
35
|
rows: 1,
|
|
38
|
-
placeholder: "
|
|
36
|
+
placeholder: "随心输入",
|
|
39
37
|
oninput: () => {
|
|
40
38
|
// 识别过程中用户自己动了输入框,以用户为准,停掉识别
|
|
41
39
|
cancelVoice();
|
|
42
40
|
autosize();
|
|
43
41
|
void updateSlashMenu();
|
|
44
|
-
void ui.mention.update();
|
|
45
42
|
},
|
|
46
43
|
onfocus: () => (keepMenus = false),
|
|
47
44
|
onblur: () =>
|
|
@@ -49,10 +46,9 @@ export function renderComposer() {
|
|
|
49
46
|
// 为了让出地方收起的键盘(见 hideKeyboardForMenu):菜单留着;点回输入框也不关
|
|
50
47
|
if (keepMenus || document.activeElement === ui.input) return;
|
|
51
48
|
closeSlashMenu();
|
|
52
|
-
ui.mention.close();
|
|
53
49
|
}, 150),
|
|
54
50
|
onkeydown: (e) => {
|
|
55
|
-
if (slashKeydown(e)
|
|
51
|
+
if (slashKeydown(e)) {
|
|
56
52
|
e.preventDefault();
|
|
57
53
|
return;
|
|
58
54
|
}
|
|
@@ -88,12 +84,8 @@ export function renderComposer() {
|
|
|
88
84
|
ui.ctxRing = h("span", { class: "ctx-ring-slot" });
|
|
89
85
|
ui.chips = h("div", { class: "chips" });
|
|
90
86
|
ui.schedBar = h("div", { class: "sched-bar", hidden: true });
|
|
87
|
+
ui.todoBar = h("div", { class: "todo-bar", hidden: true });
|
|
91
88
|
ui.slashMenu = h("div", { class: "slash-menu", hidden: true });
|
|
92
|
-
ui.mentionMenu = h("div", { class: "slash-menu", hidden: true });
|
|
93
|
-
ui.mention = attachMention(ui.input, ui.mentionMenu, {
|
|
94
|
-
onEmpty: () => openSettings("技能"),
|
|
95
|
-
onShown: hideKeyboardForMenu,
|
|
96
|
-
});
|
|
97
89
|
ui.composer = h(
|
|
98
90
|
"div",
|
|
99
91
|
{
|
|
@@ -110,7 +102,6 @@ export function renderComposer() {
|
|
|
110
102
|
},
|
|
111
103
|
},
|
|
112
104
|
ui.slashMenu,
|
|
113
|
-
ui.mentionMenu,
|
|
114
105
|
ui.chips,
|
|
115
106
|
ui.input,
|
|
116
107
|
h(
|
|
@@ -127,12 +118,13 @@ export function renderComposer() {
|
|
|
127
118
|
);
|
|
128
119
|
fill(ui.composerWrap,
|
|
129
120
|
ui.toBottom,
|
|
130
|
-
h("div", { class: "composer-box" }, ui.schedBar, ui.ctxBar, ui.composer),
|
|
121
|
+
h("div", { class: "composer-box" }, ui.todoBar, ui.schedBar, ui.ctxBar, ui.composer),
|
|
131
122
|
);
|
|
132
123
|
ui.input.addEventListener("input", updateSendBtn);
|
|
133
124
|
updateSendBtn();
|
|
134
125
|
renderContext();
|
|
135
126
|
renderScheduled();
|
|
127
|
+
renderTodos();
|
|
136
128
|
}
|
|
137
129
|
|
|
138
130
|
export function autosize() {
|
|
@@ -162,6 +154,7 @@ export function updateSendBtn() {
|
|
|
162
154
|
export function setBusy(busy) {
|
|
163
155
|
S.busy = !!busy;
|
|
164
156
|
updateSendBtn();
|
|
157
|
+
renderTodos();
|
|
165
158
|
}
|
|
166
159
|
|
|
167
160
|
export function renderChips() {
|
|
@@ -200,7 +193,7 @@ export async function ensureConversation() {
|
|
|
200
193
|
try {
|
|
201
194
|
info = await api("/api/conversations", {
|
|
202
195
|
method: "POST",
|
|
203
|
-
body: {
|
|
196
|
+
body: { expert: S.draftExpert ?? S.draftAgent, cwd: S.draftCwd ?? undefined },
|
|
204
197
|
});
|
|
205
198
|
} catch (err) {
|
|
206
199
|
// 选的目录没了(被删、或工作区改了):退回根目录,让用户重新确认
|
|
@@ -286,7 +279,6 @@ export async function sendMessage() {
|
|
|
286
279
|
return;
|
|
287
280
|
}
|
|
288
281
|
closeSlashMenu();
|
|
289
|
-
ui.mention.close();
|
|
290
282
|
let key;
|
|
291
283
|
let res;
|
|
292
284
|
setSending(true);
|
|
@@ -6,6 +6,7 @@ import { agentLabel, convTitle, renderSidebar } from "./sidebar.js";
|
|
|
6
6
|
import { agentCatalog, baseName, catalogDefaults, draftPick, modelName, renderContext, renderTopbar, saveDraftPick, visibleModels } from "./topbar.js";
|
|
7
7
|
import { closeMenu, confirmDialog, modal, placePopover, showPopover } from "../lib/overlay.js";
|
|
8
8
|
import { newDraft, openConversation, renderEmpty } from "./messages.js";
|
|
9
|
+
import { setDraftExpert } from "./experts.js";
|
|
9
10
|
|
|
10
11
|
// ---------- 会话操作 ----------
|
|
11
12
|
|
|
@@ -42,15 +43,12 @@ export async function forkConversation(anchor, key = S.current) {
|
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
await doAction("agent", id);
|
|
46
|
+
/** 新对话里选专家(进了对话就不能换了:要换专家新建对话) */
|
|
47
|
+
export function switchAgent(id) {
|
|
48
|
+
if (S.current) return;
|
|
49
|
+
setDraftExpert(id);
|
|
50
|
+
renderTopbar();
|
|
51
|
+
renderEmpty();
|
|
54
52
|
}
|
|
55
53
|
|
|
56
54
|
/** 模型 / 思考程度选择:已有会话直接切,新对话先记下,发第一条消息时带过去 */
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { agentIcon, h } from "../lib/dom.js";
|
|
2
|
+
import { api } from "../lib/api.js";
|
|
3
|
+
import { S } from "../state.js";
|
|
4
|
+
import { agentLabel } from "./sidebar.js";
|
|
5
|
+
|
|
6
|
+
// ---------- 专家:新对话、定时任务里选 ----------
|
|
7
|
+
// 内置专家就是能用的 agent(Claude Code / Codex),自定义专家在「设置 → 专家」里建。
|
|
8
|
+
// 对话从头到尾一个专家:只有新对话里能选,进了对话只显示。
|
|
9
|
+
|
|
10
|
+
/** 能用的 agent(启用了、装好登录了的;一个都没有时退回全部启用的) */
|
|
11
|
+
function usableEngines() {
|
|
12
|
+
const enabled = S.agents.filter((a) => a.enabled);
|
|
13
|
+
const usable = enabled.filter((a) => a.available !== false);
|
|
14
|
+
return (usable.length ? usable : enabled).map((a) => a.id);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** 能选的专家:内置的在前,再是自己的(引擎能用的) */
|
|
18
|
+
export function expertChoices() {
|
|
19
|
+
const engines = usableEngines();
|
|
20
|
+
return [
|
|
21
|
+
...engines.map((id) => ({ id, name: agentLabel(id), engine: id, builtin: true })),
|
|
22
|
+
...S.experts.filter((e) => engines.includes(e.engine)),
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function findExpert(id) {
|
|
27
|
+
return expertChoices().find((e) => e.id === id) ?? null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** 选的专家还在不在:不在(删了、引擎关了)就退回第一个能用的。引擎跟着专家 */
|
|
31
|
+
export function syncDraftExpert() {
|
|
32
|
+
const choices = expertChoices();
|
|
33
|
+
let e = choices.find((x) => x.id === S.draftExpert);
|
|
34
|
+
// 以前只记了 agent
|
|
35
|
+
if (!e && !S.draftExpert && S.draftAgent) e = choices.find((x) => x.id === S.draftAgent);
|
|
36
|
+
e ??= choices[0] ?? null;
|
|
37
|
+
S.draftExpert = e?.id ?? null;
|
|
38
|
+
S.draftAgent = e?.engine ?? null;
|
|
39
|
+
return e;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function setDraftExpert(id) {
|
|
43
|
+
S.draftExpert = id;
|
|
44
|
+
localStorage.setItem("aim.expert", id);
|
|
45
|
+
const e = syncDraftExpert();
|
|
46
|
+
if (e) localStorage.setItem("aim.agent", e.engine);
|
|
47
|
+
// 换了专家:默认工作目录跟着专家走(没设就是工作区根目录)
|
|
48
|
+
S.draftCwd = e?.cwd || null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** 专家的图标:自定义专家有 emoji 就用 emoji,否则用引擎的图标 */
|
|
52
|
+
export function expertIcon(e, cls = "agent-icon") {
|
|
53
|
+
if (e?.icon) return h("span", { class: `${cls} expert-emoji` }, e.icon);
|
|
54
|
+
return agentIcon(e?.engine ?? e?.id, cls);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** 对话的专家(服务端给的 c.expert)配上引擎,给 expertIcon 用 */
|
|
58
|
+
export function convExpert(c) {
|
|
59
|
+
const badge = c?.expert ?? { id: c?.agent, name: agentLabel(c?.agent ?? ""), builtin: true };
|
|
60
|
+
return { ...badge, engine: c?.agent };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** 设置里改了专家:重新拉一遍 */
|
|
64
|
+
export async function reloadExperts() {
|
|
65
|
+
try {
|
|
66
|
+
const d = await api("/api/experts/brief");
|
|
67
|
+
S.experts = d.experts ?? [];
|
|
68
|
+
} catch {
|
|
69
|
+
// 拉不到就先用旧的
|
|
70
|
+
}
|
|
71
|
+
syncDraftExpert();
|
|
72
|
+
document.dispatchEvent(new CustomEvent("aim:experts"));
|
|
73
|
+
}
|
package/web/views/interaction.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { h, toast } from "../lib/dom.js";
|
|
1
|
+
import { h, icon, isTouch, toast } from "../lib/dom.js";
|
|
2
2
|
import { renderMarkdown } from "../lib/markdown.js";
|
|
3
3
|
import { desktop, isAdmin, S } from "../state.js";
|
|
4
4
|
import { WS } from "../lib/ws.js";
|
|
@@ -106,32 +106,43 @@ export function renderInteraction(item) {
|
|
|
106
106
|
),
|
|
107
107
|
);
|
|
108
108
|
}
|
|
109
|
-
//
|
|
109
|
+
// 提问:选项是一排按钮,第一个(Claude 会把推荐的放第一个)是黑色主按钮,⌘↵ 直接选它
|
|
110
110
|
const needsSubmit = spec.questions.some((q) => q.multiSelect);
|
|
111
|
+
const shortcut = settled ? null : primaryAction(ix);
|
|
111
112
|
return h(
|
|
112
113
|
"div",
|
|
113
114
|
{ class: `ix-card ask${settled ? " settled" : ""}` },
|
|
114
|
-
|
|
115
|
+
settled
|
|
116
|
+
? null
|
|
117
|
+
: h("button", { class: "icon-btn ix-close", title: "跳过,让 Claude 按它的判断继续", onclick: () => ixOp(ix.id, "skip") }, icon("x")),
|
|
115
118
|
spec.questions.map((q, qi) => {
|
|
116
119
|
const picked = ix.selections[qi] ?? [];
|
|
117
120
|
const free = ix.freeText?.[qi];
|
|
121
|
+
// 单选还没答:第一个是主按钮;答过了就只有选中的那个是黑的
|
|
122
|
+
const lead = !settled && !q.multiSelect && picked.length === 0 && !free ? 0 : -1;
|
|
118
123
|
return h(
|
|
119
124
|
"div",
|
|
120
125
|
{ class: "ix-q" },
|
|
121
|
-
h("div", { class: "q-
|
|
122
|
-
q.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
126
|
+
q.header ? h("div", { class: "q-header" }, q.header) : null,
|
|
127
|
+
h("div", { class: "q-text" }, q.question, q.multiSelect ? h("span", { class: "q-hint" }, "(可多选)") : null),
|
|
128
|
+
h(
|
|
129
|
+
"div",
|
|
130
|
+
// 带说明的选项竖着排,一行一个,说明才放得下
|
|
131
|
+
{ class: `q-opts${q.options.some((o) => o.description) ? " stack" : ""}` },
|
|
132
|
+
q.options.map((opt, oi) => {
|
|
133
|
+
const on = picked.includes(oi);
|
|
134
|
+
return h(
|
|
135
|
+
"button",
|
|
136
|
+
{
|
|
137
|
+
class: `opt${on ? " on" : oi === lead ? " primary" : ""}`,
|
|
138
|
+
disabled: !!settled,
|
|
139
|
+
onclick: () => ixOp(ix.id, "select", { q: qi, o: oi, v: q.multiSelect ? !on : true }),
|
|
140
|
+
},
|
|
141
|
+
h("span", { class: "opt-label" }, q.multiSelect && on ? "✓ " : "", opt.label, shortcut?.q === qi && shortcut.o === oi ? kbdHint() : null),
|
|
142
|
+
opt.description ? h("small", {}, opt.description) : null,
|
|
143
|
+
);
|
|
144
|
+
}),
|
|
145
|
+
),
|
|
135
146
|
free ? h("div", { class: "ix-meta" }, `→ ${free}`) : null,
|
|
136
147
|
);
|
|
137
148
|
}),
|
|
@@ -140,9 +151,44 @@ export function renderInteraction(item) {
|
|
|
140
151
|
: h(
|
|
141
152
|
"div",
|
|
142
153
|
{ class: "ix-buttons" },
|
|
143
|
-
needsSubmit ? h("button", { class: "
|
|
144
|
-
h("button", { class: "btn", onclick: () => ixOp(ix.id, "skip") }, "跳过"),
|
|
154
|
+
needsSubmit ? h("button", { class: "opt primary", onclick: () => ixOp(ix.id, "submit") }, h("span", { class: "opt-label" }, "提交", shortcut?.submit ? kbdHint() : null)) : null,
|
|
145
155
|
h("span", { class: "ix-meta" }, "都不合适?直接在下面输入框里回答"),
|
|
146
156
|
),
|
|
147
157
|
);
|
|
148
158
|
}
|
|
159
|
+
|
|
160
|
+
// ---------- ⌘↵ / Ctrl+↵:选主按钮 ----------
|
|
161
|
+
|
|
162
|
+
const isMac = /Mac|iPhone|iPad/.test(navigator.platform);
|
|
163
|
+
|
|
164
|
+
function kbdHint() {
|
|
165
|
+
if (isTouch) return null;
|
|
166
|
+
return h("span", { class: "kbd-hint" }, h("kbd", {}, isMac ? "⌘" : "Ctrl"), h("kbd", {}, "↵"));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** 这张卡按 ⌘↵ 做什么:有多选就是提交,否则选第一个还没答的问题的第一个选项 */
|
|
170
|
+
function primaryAction(ix) {
|
|
171
|
+
const qs = ix.spec.questions;
|
|
172
|
+
if (qs.some((q) => q.multiSelect)) return { submit: true };
|
|
173
|
+
const qi = qs.findIndex((_, i) => !(ix.selections[i]?.length) && !ix.freeText?.[i]);
|
|
174
|
+
return qi < 0 ? null : { q: qi, o: 0 };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
document.addEventListener(
|
|
178
|
+
"keydown",
|
|
179
|
+
(e) => {
|
|
180
|
+
if (e.key !== "Enter" || !(e.metaKey || e.ctrlKey) || e.shiftKey || e.altKey || e.isComposing) return;
|
|
181
|
+
// 正在输入框里打字:那是要发消息(直接在输入框里回答也算作答),不抢
|
|
182
|
+
const el = document.activeElement;
|
|
183
|
+
if (el && (el.tagName === "TEXTAREA" || el.tagName === "INPUT" || el.isContentEditable) && el.value?.trim()) return;
|
|
184
|
+
// 当前对话里最新的一张没处理的提问卡
|
|
185
|
+
const item = S.items.findLast((i) => i.type === "ix" && i.ix.spec.kind === "question" && !i.ix.settled);
|
|
186
|
+
const act = item && primaryAction(item.ix);
|
|
187
|
+
if (!act) return;
|
|
188
|
+
e.preventDefault();
|
|
189
|
+
e.stopPropagation();
|
|
190
|
+
if (act.submit) void ixOp(item.ix.id, "submit");
|
|
191
|
+
else void ixOp(item.ix.id, "select", { q: act.q, o: act.o, v: true });
|
|
192
|
+
},
|
|
193
|
+
true,
|
|
194
|
+
);
|
package/web/views/layout.js
CHANGED
|
@@ -19,7 +19,8 @@ import {
|
|
|
19
19
|
stopMarquee,
|
|
20
20
|
} from "./sidebar.js";
|
|
21
21
|
import { applyDesktopQuota, loadQuota, renderQuota } from "./quota.js";
|
|
22
|
-
import { openBotConversations, openConvContextMenu, runDesktopMenu
|
|
22
|
+
import { openBotConversations, openConvContextMenu, runDesktopMenu } from "./topbar.js";
|
|
23
|
+
import { syncDraftExpert } from "./experts.js";
|
|
23
24
|
import { confirmDialog, showMenu } from "../lib/overlay.js";
|
|
24
25
|
import { applyShellInfo, handleAllowEmbed, HOME, mountSwitcher, refreshShellPush, routeToServer, shellBooted, switchServer } from "../lib/shell.js";
|
|
25
26
|
import { bindScrollWatch, newDraft, openConversation, scrollToBottom } from "./messages.js";
|
|
@@ -141,8 +142,8 @@ export async function boot() {
|
|
|
141
142
|
applyShellInfo(data.servers, srv || history.state?.loftServer || (location.hash.length > 1 ? HOME : undefined));
|
|
142
143
|
applyBootstrap(data);
|
|
143
144
|
S.pending = new Map(data.pending.map((i) => [i.id, i]));
|
|
144
|
-
|
|
145
|
-
|
|
145
|
+
S.experts = data.experts ?? [];
|
|
146
|
+
syncDraftExpert();
|
|
146
147
|
renderLayout();
|
|
147
148
|
reportDesktop();
|
|
148
149
|
WS.connect();
|
package/web/views/messages.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fill, h, icon, starsLoader } from "../lib/dom.js";
|
|
2
2
|
import { api } from "../lib/api.js";
|
|
3
3
|
import { clockTime, liveDuration, serverNow, setServerTime, tidyFooter } from "../lib/time.js";
|
|
4
4
|
import { copyText, patchMarkdown, renderMarkdown } from "../lib/markdown.js";
|
|
@@ -12,6 +12,8 @@ import { renderScheduled } from "./schedule.js";
|
|
|
12
12
|
import { changeCwd, doAction, forkConversation } from "./conv-actions.js";
|
|
13
13
|
import { scheduleNav } from "./msg-nav.js";
|
|
14
14
|
import { linkReplyFiles } from "./file-preview.js";
|
|
15
|
+
import { setTodos } from "./todos.js";
|
|
16
|
+
import { expertIcon, findExpert } from "./experts.js";
|
|
15
17
|
|
|
16
18
|
// ---------- 打开会话 ----------
|
|
17
19
|
|
|
@@ -35,6 +37,7 @@ export function newDraft() {
|
|
|
35
37
|
S.pinNext = false;
|
|
36
38
|
ui.pinEl = null;
|
|
37
39
|
ui.follow = true;
|
|
40
|
+
setTodos(null);
|
|
38
41
|
setBusy(false);
|
|
39
42
|
renderScheduled();
|
|
40
43
|
history.replaceState(history.state, "", location.pathname);
|
|
@@ -50,25 +53,57 @@ export function newDraft() {
|
|
|
50
53
|
export function renderEmpty() {
|
|
51
54
|
const enabled = usableAgents();
|
|
52
55
|
const cwd = S.draftCwd ?? S.workspaceRoot ?? "";
|
|
56
|
+
const expert = findExpert(S.draftExpert);
|
|
57
|
+
// 自定义专家:有欢迎语就用它;只能联网的专家不碰目录,不问「在哪个目录里」
|
|
58
|
+
const custom = expert && !expert.builtin;
|
|
59
|
+
const dirTitle = h(
|
|
60
|
+
"h2",
|
|
61
|
+
{},
|
|
62
|
+
"你想让我们在 ",
|
|
63
|
+
h("button", { class: "hero-dir", title: `${cwd}\n点击切换工作目录`, onclick: () => changeCwd() }, baseName(cwd) || "工作区"),
|
|
64
|
+
" 中构建什么?",
|
|
65
|
+
);
|
|
66
|
+
const fillPrompt = (text) => {
|
|
67
|
+
if (!ui.input) return;
|
|
68
|
+
ui.input.value = text;
|
|
69
|
+
ui.input.dispatchEvent(new Event("input"));
|
|
70
|
+
ui.input.focus();
|
|
71
|
+
// 填空题(___):把光标放到空上
|
|
72
|
+
const blank = text.indexOf("___");
|
|
73
|
+
if (blank >= 0) ui.input.setSelectionRange(blank, blank + 3);
|
|
74
|
+
};
|
|
53
75
|
fill(ui.msgInner,
|
|
54
76
|
h(
|
|
55
77
|
"div",
|
|
56
78
|
{ class: "empty hero" },
|
|
57
|
-
|
|
58
|
-
enabled.length
|
|
59
|
-
? h(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
79
|
+
expertIcon(expert ?? { id: S.draftAgent }, "hero-logo"),
|
|
80
|
+
!enabled.length
|
|
81
|
+
? [h("h2", {}, "有什么可以帮你?"), h("div", {}, "还没有启用任何 agent,先去设置里启用。")]
|
|
82
|
+
: custom
|
|
83
|
+
? [
|
|
84
|
+
expert.welcome ? h("h2", {}, expert.welcome) : expert.access === "web" ? h("h2", {}, `我是${expert.name},有什么可以帮你?`) : dirTitle,
|
|
85
|
+
expert.welcome && expert.access !== "web" ? h("div", { class: "hero-sub" }, "工作目录:", h("button", { class: "hero-dir", title: `${cwd}\n点击切换工作目录`, onclick: () => changeCwd() }, baseName(cwd) || "工作区")) : null,
|
|
86
|
+
expert.quickPrompts?.length
|
|
87
|
+
? h(
|
|
88
|
+
"div",
|
|
89
|
+
{ class: "hero-prompts" },
|
|
90
|
+
expert.quickPrompts.map((q) => h("button", { class: "hero-prompt", title: q.prompt, onclick: () => fillPrompt(q.prompt) }, q.title)),
|
|
91
|
+
)
|
|
92
|
+
: null,
|
|
93
|
+
]
|
|
94
|
+
: dirTitle,
|
|
67
95
|
),
|
|
68
96
|
);
|
|
69
97
|
renderContext();
|
|
70
98
|
}
|
|
71
99
|
|
|
100
|
+
// 设置里改了专家:新对话页上的专家、欢迎语跟着变
|
|
101
|
+
document.addEventListener("aim:experts", () => {
|
|
102
|
+
if (S.current || S.view) return;
|
|
103
|
+
renderTopbar();
|
|
104
|
+
renderEmpty();
|
|
105
|
+
});
|
|
106
|
+
|
|
72
107
|
export async function openConversation(key) {
|
|
73
108
|
leaveTasksView();
|
|
74
109
|
const token = ++S.loadToken;
|
|
@@ -81,6 +116,7 @@ export async function openConversation(key) {
|
|
|
81
116
|
S.pinNext = false;
|
|
82
117
|
ui.pinEl = null;
|
|
83
118
|
ui.follow = true;
|
|
119
|
+
setTodos(null);
|
|
84
120
|
renderChips();
|
|
85
121
|
renderScheduled();
|
|
86
122
|
history.replaceState(history.state, "", `#${encodeURIComponent(key)}`);
|
|
@@ -128,6 +164,8 @@ export async function openConversation(key) {
|
|
|
128
164
|
else if (m.role === "question") addItem({ type: "ix", id: m.question.id, ix: historyQuestion(key, m) });
|
|
129
165
|
else addItem({ type: "ai", steps: m.steps ?? [], committed: m.text, partial: "", done: true, footer: m.footer, at: m.ts, anchor: m.anchor, segment: m.segment });
|
|
130
166
|
}
|
|
167
|
+
// 任务清单:最后改过的那一份(进行中这一轮又改了的话,下面重放 todos 事件时换成新的)
|
|
168
|
+
setTodos(data.messages.findLast((m) => m.todos)?.todos ?? null);
|
|
131
169
|
S.seq.set(key, 0);
|
|
132
170
|
// 进行中这一轮弹过的卡(含已处理的):重放到 ix 事件时放回原位
|
|
133
171
|
replayCards = new Map((data.interactions ?? []).map((ix) => [ix.id, ix]));
|
|
@@ -645,6 +683,9 @@ export function applyEvent(env) {
|
|
|
645
683
|
updateItem(ai);
|
|
646
684
|
return;
|
|
647
685
|
}
|
|
686
|
+
case "todos":
|
|
687
|
+
setTodos(ev.todos);
|
|
688
|
+
return;
|
|
648
689
|
case "delta": {
|
|
649
690
|
const ai = currentAi(env.ts);
|
|
650
691
|
ai.partial += ev.text;
|
package/web/views/sidebar.js
CHANGED
|
@@ -439,8 +439,8 @@ export function renderSidebar() {
|
|
|
439
439
|
orphan ? h("span", { class: "brand-icon lead fork-mark", html: ICON.fork }) : null,
|
|
440
440
|
// 定时任务的专用对话
|
|
441
441
|
c.taskId ? h("span", { class: "brand-icon lead task-mark", title: "定时任务的对话", html: ICON.clock }) : null,
|
|
442
|
-
//
|
|
443
|
-
c.
|
|
442
|
+
// 自定义专家的对话:前面挂专家的 emoji
|
|
443
|
+
c.expert?.icon && !c.expert.builtin ? h("span", { class: "brand-icon lead expert-mark", title: `专家:${c.expert.name}` }, c.expert.icon) : null,
|
|
444
444
|
h("span", { class: "title" }, convTitle(c)),
|
|
445
445
|
status([c.key]),
|
|
446
446
|
);
|
package/web/views/tasks.js
CHANGED
|
@@ -5,10 +5,10 @@ import { confirmDialog, modal, showMenu } from "../lib/overlay.js";
|
|
|
5
5
|
import { S, ui } from "../state.js";
|
|
6
6
|
import { WS } from "../lib/ws.js";
|
|
7
7
|
import { agentLabel, closeSide, renderSidebar } from "./sidebar.js";
|
|
8
|
-
import { baseName, renderTopbar
|
|
8
|
+
import { baseName, renderTopbar } from "./topbar.js";
|
|
9
9
|
import { openConversation } from "./messages.js";
|
|
10
10
|
import { changeCwd } from "./conv-actions.js";
|
|
11
|
-
import {
|
|
11
|
+
import { expertChoices, findExpert } from "./experts.js";
|
|
12
12
|
|
|
13
13
|
// ---------- 定时任务页 ----------
|
|
14
14
|
// 到点让 agent 按提示词干活,结果回到一条对话里;「有需要才提醒」时由 agent 判断这次要不要打扰你。
|
|
@@ -41,21 +41,20 @@ const EXAMPLES = [
|
|
|
41
41
|
prompt: "查一下 npm 上 agent-loft 的最新版本(https://www.npmjs.com/package/agent-loft),和当前服务端版本比较。有新版本就告诉我新版本号和主要更新内容。",
|
|
42
42
|
schedule: { kind: "daily", time: "09:00" },
|
|
43
43
|
notify: "smart",
|
|
44
|
-
mode: "chat",
|
|
45
44
|
},
|
|
46
45
|
{
|
|
47
46
|
title: "科技新闻早报",
|
|
48
47
|
prompt: "搜一下过去 24 小时最重要的科技新闻,挑 5 条,每条用一两句话说明为什么值得关注,附上链接。",
|
|
49
48
|
schedule: { kind: "daily", time: "08:30" },
|
|
50
49
|
notify: "always",
|
|
51
|
-
mode: "chat",
|
|
52
50
|
},
|
|
53
51
|
{
|
|
54
52
|
title: "下班前看看改了什么",
|
|
55
53
|
prompt: "用 git status 和 git log --since=midnight 看看这个目录今天改了什么,帮我列一个简短的日报草稿。今天没有任何改动的话就不用提醒我。",
|
|
56
54
|
schedule: { kind: "weekdays", time: "18:00" },
|
|
57
55
|
notify: "smart",
|
|
58
|
-
|
|
56
|
+
// 要跑 git 命令:用能执行命令的内置专家
|
|
57
|
+
expert: "claude",
|
|
59
58
|
},
|
|
60
59
|
];
|
|
61
60
|
|
|
@@ -199,7 +198,7 @@ function taskCard(t) {
|
|
|
199
198
|
const where =
|
|
200
199
|
t.target.kind === "conv"
|
|
201
200
|
? `发到「${t.convTitle || "对话"}」`
|
|
202
|
-
: `${
|
|
201
|
+
: `${findExpert(t.expert ?? t.agent)?.name ?? (t.expert ? "(已删除的专家)" : agentLabel(t.agent))}${t.cwd ? ` · ${baseName(t.cwd)}` : ""}`;
|
|
203
202
|
const toggle = h("input", { type: "checkbox", checked: t.enabled, title: t.enabled ? "暂停" : "启用" });
|
|
204
203
|
toggle.onchange = async () => {
|
|
205
204
|
try {
|
|
@@ -282,18 +281,10 @@ const WEEK_NAME = ["日", "一", "二", "三", "四", "五", "六"];
|
|
|
282
281
|
/** task:编辑这个;preset:新建时预填(例子) */
|
|
283
282
|
export function openTaskForm(task, preset) {
|
|
284
283
|
const src = task ?? preset ?? {};
|
|
285
|
-
const
|
|
284
|
+
const experts = expertChoices();
|
|
286
285
|
const title = h("input", { value: src.title ?? "", maxlength: "60", placeholder: "比如:检查 agent-loft 更新" });
|
|
287
|
-
const prompt = h("textarea", { rows: 5, maxlength: "4000", placeholder: "到点让 agent
|
|
286
|
+
const prompt = h("textarea", { rows: 5, maxlength: "4000", placeholder: "到点让 agent 做什么。写成完整的指令:那时你多半不在,它没法再问你。" });
|
|
288
287
|
prompt.value = src.prompt ?? "";
|
|
289
|
-
// @ 技能:和输入框一样,到点时服务端认提示词里的 @name
|
|
290
|
-
const mentionMenu = h("div", { class: "slash-menu below", hidden: true });
|
|
291
|
-
const mention = attachMention(prompt, mentionMenu);
|
|
292
|
-
prompt.addEventListener("input", () => void mention.update());
|
|
293
|
-
prompt.addEventListener("blur", () => setTimeout(mention.close, 150));
|
|
294
|
-
prompt.addEventListener("keydown", (e) => {
|
|
295
|
-
if (mention.keydown(e)) e.preventDefault();
|
|
296
|
-
});
|
|
297
288
|
|
|
298
289
|
// ---- 频率 ----
|
|
299
290
|
const sch = { kind: "daily", time: "09:00", days: [1], day: 1, every: 2, minute: 0, expr: "0 9 * * *", at: Date.now() + 3600_000, ...(src.schedule ?? {}) };
|
|
@@ -369,16 +360,14 @@ export function openTaskForm(task, preset) {
|
|
|
369
360
|
h("option", { value: "dedicated" }, "专用对话(单独开一条)"),
|
|
370
361
|
)
|
|
371
362
|
: null;
|
|
372
|
-
const
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
);
|
|
377
|
-
const mode = h(
|
|
363
|
+
const picked = src.expert ?? src.agent ?? S.draftExpert;
|
|
364
|
+
// 任务用的专家被删了:列表里没有它,留一项占位,免得一打开就悄悄换成别的
|
|
365
|
+
const missing = task && !experts.some((e) => e.id === picked);
|
|
366
|
+
const expert = h(
|
|
378
367
|
"select",
|
|
379
368
|
{},
|
|
380
|
-
h("option", { value: "
|
|
381
|
-
h("option", { value:
|
|
369
|
+
missing ? h("option", { value: "", selected: true, disabled: true }, "(专家已删除,选一个)") : null,
|
|
370
|
+
experts.map((e) => h("option", { value: e.id, selected: !missing && e.id === picked }, `${e.icon ? `${e.icon} ` : ""}${e.name}`)),
|
|
382
371
|
);
|
|
383
372
|
let cwd = src.cwd || "";
|
|
384
373
|
const cwdBtn = h("button", { type: "button", class: "btn task-cwd" });
|
|
@@ -395,20 +384,15 @@ export function openTaskForm(task, preset) {
|
|
|
395
384
|
showCwd();
|
|
396
385
|
},
|
|
397
386
|
});
|
|
398
|
-
const cwdField = field("工作目录", cwdBtn, "
|
|
399
|
-
const dedicatedBox = h(
|
|
400
|
-
"div",
|
|
401
|
-
{ class: "task-dedicated" },
|
|
402
|
-
agents.length > 1 ? field("Agent", agent) : null,
|
|
403
|
-
field("模式", mode),
|
|
404
|
-
cwdField,
|
|
405
|
-
);
|
|
387
|
+
const cwdField = field("工作目录", cwdBtn, "专家在这个目录里干活。需要授权时会推送给你,没人处理就按拒绝。没选就用专家默认的目录。");
|
|
388
|
+
const dedicatedBox = h("div", { class: "task-dedicated" }, field("专家", expert, "到点由这个专家来做。要联网、读文件还是跑命令,看专家的权限(设置 → 专家)。"), cwdField);
|
|
406
389
|
const syncVisibility = () => {
|
|
407
390
|
const dedicated = !target || target.value === "dedicated";
|
|
408
391
|
dedicatedBox.hidden = !dedicated;
|
|
409
|
-
|
|
392
|
+
// 只能联网的专家不碰目录
|
|
393
|
+
cwdField.hidden = findExpert(expert.value)?.access === "web";
|
|
410
394
|
};
|
|
411
|
-
|
|
395
|
+
expert.onchange = syncVisibility;
|
|
412
396
|
if (target) target.onchange = syncVisibility;
|
|
413
397
|
syncVisibility();
|
|
414
398
|
|
|
@@ -416,7 +400,7 @@ export function openTaskForm(task, preset) {
|
|
|
416
400
|
"div",
|
|
417
401
|
{ class: "modal-body task-form" },
|
|
418
402
|
field("名称", title),
|
|
419
|
-
field("要做的事",
|
|
403
|
+
field("要做的事", prompt, "需要对比的写清楚怎么判断,比如「和上次的结果比」「版本号比当前的新才算更新」。"),
|
|
420
404
|
field("频率", h("div", { class: "task-freq-row" }, freq, freqBox), freqHint),
|
|
421
405
|
field("提醒", notify),
|
|
422
406
|
target ? field("结果发到", target) : field("结果发到", h("div", { class: "task-static" }, task?.convKey ? `专用对话「${task.convTitle || "对话"}」` : "专用对话(第一次运行时新建,之后都发到这条)")),
|
|
@@ -442,13 +426,14 @@ export function openTaskForm(task, preset) {
|
|
|
442
426
|
: { kind: "cron", expr: sch.expr };
|
|
443
427
|
if (schedule.kind === "once" && !(schedule.at > Date.now())) return toast("运行时间要在现在之后");
|
|
444
428
|
const dedicated = !target || target.value === "dedicated";
|
|
429
|
+
if (dedicated && !expert.value) return toast("选一个专家");
|
|
445
430
|
const payload = {
|
|
446
431
|
title: title.value,
|
|
447
432
|
prompt: prompt.value,
|
|
448
433
|
schedule,
|
|
449
434
|
notify: notify.value,
|
|
450
435
|
target: dedicated ? { kind: "dedicated" } : { kind: "conv", key: task.target.key },
|
|
451
|
-
...(dedicated ? {
|
|
436
|
+
...(dedicated ? { expert: expert.value, cwd: findExpert(expert.value)?.access === "web" ? "" : cwd } : {}),
|
|
452
437
|
};
|
|
453
438
|
save.disabled = true;
|
|
454
439
|
try {
|