agent-loft 0.2.110 → 0.2.112
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 +3 -1
- package/package.json +1 -1
- package/src/agents/codex/protocol.ts +10 -0
- package/src/agents/codex/session.ts +201 -5
- package/src/channels/feishu/client.ts +3 -2
- package/src/channels/feishu/index.ts +26 -0
- package/src/channels/web/experts-api.ts +1 -0
- package/src/channels/web/server.ts +33 -4
- package/src/channels/web/tasks-api.ts +4 -2
- package/src/channels/weixin/bot.ts +6 -0
- package/src/channels/weixin/index.ts +19 -0
- package/src/core/expert-prompt.ts +15 -0
- package/src/core/experts.ts +19 -0
- package/src/core/hub.ts +59 -2
- package/src/core/tasks-bridge.ts +19 -2
- package/src/core/tasks.ts +53 -0
- package/src/core/types.ts +19 -0
- package/src/mcp/tasks-server.ts +2 -0
- package/web/css/composer.css +164 -0
- package/web/css/experts.css +66 -0
- package/web/css/tasks.css +5 -0
- package/web/lib/ws.js +4 -0
- package/web/settings/experts.js +85 -16
- package/web/views/composer.js +2 -0
- package/web/views/messages.js +1 -1
- package/web/views/tasks.js +53 -1
- package/web/views/topbar.js +2 -0
- package/web/views/voice-call.js +293 -0
package/src/core/experts.ts
CHANGED
|
@@ -64,6 +64,8 @@ export type Expert = {
|
|
|
64
64
|
mcp: string[];
|
|
65
65
|
/** 子智能体:别的专家的 id。只有 Claude 支持 */
|
|
66
66
|
subagents: string[];
|
|
67
|
+
/** Codex 自带、专家默认关掉的能力,勾了才开(只有 Codex 专家)。老数据没有这一项 = 都不开 */
|
|
68
|
+
codexTools?: CodexTool[];
|
|
67
69
|
/** 带不带主人的个人记忆 */
|
|
68
70
|
memory: boolean;
|
|
69
71
|
/** 每存一次加一 */
|
|
@@ -74,6 +76,19 @@ export type Expert = {
|
|
|
74
76
|
|
|
75
77
|
export const BUILTIN_IDS: readonly Engine[] = ENGINES;
|
|
76
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Codex 专家可以单独打开的自带能力(agents/codex/session.ts 的 expertConfig 按它开 feature)。
|
|
81
|
+
* browser = browser_use + in_app_browser;apps = plugins + apps + 应用说明提示词。
|
|
82
|
+
*/
|
|
83
|
+
export const CODEX_TOOLS = ["image_generation", "multi_agent", "browser", "computer_use", "apps"] as const;
|
|
84
|
+
export type CodexTool = (typeof CODEX_TOOLS)[number];
|
|
85
|
+
/**
|
|
86
|
+
* 用的是这台机器上的东西:浏览器的登录状态、桌面、Codex 登录账号连的应用(邮箱、网盘……)。
|
|
87
|
+
* 和机器上的 MCP 一样只给管理员:只有管理员能勾,共享出去后别人用时也不开。
|
|
88
|
+
*/
|
|
89
|
+
export const CODEX_ADMIN_TOOLS: readonly CodexTool[] = ["browser", "computer_use", "apps"];
|
|
90
|
+
const isCodexTool = (t: string): t is CodexTool => (CODEX_TOOLS as readonly string[]).includes(t);
|
|
91
|
+
|
|
77
92
|
export function isBuiltin(id: string): id is Engine {
|
|
78
93
|
return (BUILTIN_IDS as readonly string[]).includes(id);
|
|
79
94
|
}
|
|
@@ -369,6 +384,7 @@ function validate(owner: string, input: ExpertInput, prev?: Expert, selfId?: str
|
|
|
369
384
|
skills,
|
|
370
385
|
mcp,
|
|
371
386
|
subagents,
|
|
387
|
+
codexTools: engine === "codex" ? ids(pick("codexTools")).filter(isCodexTool).filter((t) => admin || !CODEX_ADMIN_TOOLS.includes(t)) : [],
|
|
372
388
|
memory: pick("memory") !== false,
|
|
373
389
|
};
|
|
374
390
|
}
|
|
@@ -467,6 +483,8 @@ export type ExpertRuntime = {
|
|
|
467
483
|
/** 选中的机器上的 MCP 名字(Codex:除了这些,机器上的都关掉) */
|
|
468
484
|
machineMcp: string[];
|
|
469
485
|
subagents: SubagentRuntime[];
|
|
486
|
+
/** 要打开的 Codex 自带能力(只有 Codex 专家;本机能力只在用的人是管理员时给) */
|
|
487
|
+
codexTools: CodexTool[];
|
|
470
488
|
memory: boolean;
|
|
471
489
|
};
|
|
472
490
|
|
|
@@ -557,6 +575,7 @@ export function expertRuntime(expert: Expert, subPrompt: (sub: Expert, access: E
|
|
|
557
575
|
askMcp: ask,
|
|
558
576
|
machineMcp: machine,
|
|
559
577
|
subagents,
|
|
578
|
+
codexTools: expert.engine === "codex" ? (expert.codexTools ?? []).filter((t) => isCodexTool(t) && (admin || !CODEX_ADMIN_TOOLS.includes(t))) : [],
|
|
560
579
|
memory: expert.memory,
|
|
561
580
|
};
|
|
562
581
|
}
|
package/src/core/hub.ts
CHANGED
|
@@ -49,6 +49,7 @@ import type {
|
|
|
49
49
|
HistoryMessage,
|
|
50
50
|
InteractionSpec,
|
|
51
51
|
ModelInfo,
|
|
52
|
+
RealtimeEvent,
|
|
52
53
|
RuntimeInfo,
|
|
53
54
|
SessionSummary,
|
|
54
55
|
StepKind,
|
|
@@ -59,7 +60,7 @@ import type {
|
|
|
59
60
|
import { buildCatalog, expandCustomCommand, type AgentCommand, type CommandEntry, type CommandPrefs } from "./command-catalog.js";
|
|
60
61
|
import { helpText, type ParsedCommand } from "./commands.js";
|
|
61
62
|
import { listScheduled } from "./scheduled.js";
|
|
62
|
-
import { expertSystemPrompt, searchLabel, stripContext, wrapContext } from "./expert-prompt.js";
|
|
63
|
+
import { expertSystemPrompt, searchLabel, stripContext, VOICE_MARK, wrapContext } from "./expert-prompt.js";
|
|
63
64
|
import { availableExperts, avatarUrl, canUseExpert, expertEvents, expertToolEvents, expertRuntime, getExpert, isBuiltin, type ExpertRuntime } from "./experts.js";
|
|
64
65
|
import { builtinAgentDefaults, builtinAgentEvents, builtinAgentSession, defaultPermissionOf } from "./builtin-agents.js";
|
|
65
66
|
import { mcpEvents } from "./mcp.js";
|
|
@@ -289,7 +290,13 @@ function mergeSessionHistory(blocks: HistoryMessage[][], main: HistoryMessage[])
|
|
|
289
290
|
return out;
|
|
290
291
|
}
|
|
291
292
|
|
|
292
|
-
class Hub extends EventEmitter<{
|
|
293
|
+
class Hub extends EventEmitter<{
|
|
294
|
+
event: [EventEnvelope];
|
|
295
|
+
task: [TaskTurnEnd];
|
|
296
|
+
"project-deleted": [{ owner: string; path: string; keys: string[] }];
|
|
297
|
+
/** 实时语音对话的动静:只推给正看着这条对话的页面,不进会话记录 */
|
|
298
|
+
realtime: [{ key: string; ev: RealtimeEvent }];
|
|
299
|
+
}> {
|
|
293
300
|
private drivers = new Map<string, AgentDriver>();
|
|
294
301
|
private live = new Map<string, Live>();
|
|
295
302
|
/**
|
|
@@ -833,6 +840,12 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd]; "p
|
|
|
833
840
|
if (!alive()) return;
|
|
834
841
|
this.emitEvent(key, { type: "turn_start" });
|
|
835
842
|
},
|
|
843
|
+
onExternalTurn: (text, anchor) => {
|
|
844
|
+
if (!alive()) return;
|
|
845
|
+
this.externalTurn(key, text, anchor);
|
|
846
|
+
},
|
|
847
|
+
// 不看 alive:会话被换下去时发的「通话结束」也要让页面知道
|
|
848
|
+
onRealtime: (ev) => this.emit("realtime", { key, ev }),
|
|
836
849
|
onStep: (kind, text) => alive() && this.emitEvent(key, { type: "step", kind, text }),
|
|
837
850
|
onTodos: (todos) => alive() && this.emitEvent(key, { type: "todos", todos }),
|
|
838
851
|
onTextDelta: (text) => alive() && this.emitEvent(key, { type: "delta", text }),
|
|
@@ -2041,6 +2054,50 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd]; "p
|
|
|
2041
2054
|
}
|
|
2042
2055
|
}
|
|
2043
2056
|
|
|
2057
|
+
// ---------- 实时语音对话(只有 Codex) ----------
|
|
2058
|
+
|
|
2059
|
+
/** 开始通话:offer 是浏览器的 WebRTC SDP,返回对端 answer。会话没拉起来就按绑定拉起 */
|
|
2060
|
+
async realtimeStart(key: string, offer: string): Promise<string> {
|
|
2061
|
+
const conv = getConversation(key);
|
|
2062
|
+
if (!conv) throw new Error("会话不存在");
|
|
2063
|
+
if (conv.agent !== "codex") throw new Error("只有 Codex 的对话能语音对话");
|
|
2064
|
+
if (this.rewinding.has(key)) throw new Error("会话正在回退,请稍后再试");
|
|
2065
|
+
const session = this.session(key);
|
|
2066
|
+
if (!session.startRealtime) throw new Error("这个 agent 不支持语音对话");
|
|
2067
|
+
touchConversation(key);
|
|
2068
|
+
return session.startRealtime(offer);
|
|
2069
|
+
}
|
|
2070
|
+
|
|
2071
|
+
async realtimeStop(key: string): Promise<void> {
|
|
2072
|
+
await this.live.get(key)?.session.stopRealtime?.();
|
|
2073
|
+
}
|
|
2074
|
+
|
|
2075
|
+
/**
|
|
2076
|
+
* 语音对话转交给 Codex 的一轮:像收到一条用户消息那样记账 —— 显示说的话、进忙碌、排进轮次队列、拍改动快照。
|
|
2077
|
+
* 之后的 onResult / onError 照常收尾。
|
|
2078
|
+
*/
|
|
2079
|
+
private externalTurn(key: string, text: string, anchor?: string): void {
|
|
2080
|
+
const conv = getConversation(key);
|
|
2081
|
+
if (!conv) return;
|
|
2082
|
+
const id = crypto.randomUUID();
|
|
2083
|
+
touchConversation(key);
|
|
2084
|
+
const shown = stripContext(text);
|
|
2085
|
+
if (!conv.title && conv.titleAuto !== false && shown.trim()) {
|
|
2086
|
+
updateConversation(key, { title: shown.replace(VOICE_MARK, "").trim().replace(/\s+/g, " ").slice(0, 40), titleAuto: true });
|
|
2087
|
+
this.emitEvent(key, { type: "meta" });
|
|
2088
|
+
}
|
|
2089
|
+
this.emitEvent(key, { type: "user", text: shown, attachments: [], files: [], origin: { channel: "voice", channelId: "voice", name: "语音" }, id, queued: false });
|
|
2090
|
+
if (anchor) this.emitEvent(key, { type: "user_anchor", id, anchor });
|
|
2091
|
+
if (!this.isBusy(key)) void this.snapshotBeforeTurn(key).catch(() => {});
|
|
2092
|
+
this.setInflight(key, (this.inflight.get(key) ?? 0) + 1);
|
|
2093
|
+
const tags = this.turnTags.get(key) ?? [];
|
|
2094
|
+
tags.push(null);
|
|
2095
|
+
this.turnTags.set(key, tags);
|
|
2096
|
+
const fifo = this.turnFifo.get(key) ?? [];
|
|
2097
|
+
fifo.push({ id, input: { text: shown, attachments: [], id }, queued: false });
|
|
2098
|
+
this.turnFifo.set(key, fifo);
|
|
2099
|
+
}
|
|
2100
|
+
|
|
2044
2101
|
async stop(key: string): Promise<string> {
|
|
2045
2102
|
// 不进串行队列:停止要立刻生效。排队中还没送出的消息靠代次作废
|
|
2046
2103
|
this.stopGen.set(key, (this.stopGen.get(key) ?? 0) + 1);
|
package/src/core/tasks-bridge.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { expertIdOf, getConversation } from "./store.js";
|
|
|
18
18
|
import { forgetTask } from "./task-runner.js";
|
|
19
19
|
import { describeSchedule, formatDateTime, nextRun, normalizeSchedule, parseLocalDateTime, serverTimeZone, type TaskSchedule } from "./task-schedule.js";
|
|
20
20
|
import { TASK_TOOL_TIMEOUT_SEC, tasksSocketPath, verifyTaskCaller } from "./tasks-mcp.js";
|
|
21
|
-
import { createTask, deleteTask, getTask, listTasks, TASKS_PER_USER, updateTask, type Task, type TaskInput } from "./tasks.js";
|
|
21
|
+
import { createTask, DEFAULT_PUSH, deleteTask, getTask, listTasks, PUSH_CHANNELS, taskPush, TASKS_PER_USER, updateTask, type PushChannel, type Task, type TaskInput } from "./tasks.js";
|
|
22
22
|
import { getUser } from "./users.js";
|
|
23
23
|
import { SKILL_TOOL_NAMES, skillToolCall } from "./skills-bridge.js";
|
|
24
24
|
|
|
@@ -49,12 +49,24 @@ function whereText(task: Task, convKey: string): string {
|
|
|
49
49
|
return `对话「${getConversation(task.target.key)?.title ?? "未命名"}」`;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
const PUSH_NAME: Record<PushChannel, string> = { web: "Web", feishu: "飞书", weixin: "微信" };
|
|
53
|
+
|
|
54
|
+
function pushText(push: PushChannel[]): string {
|
|
55
|
+
return push.length ? push.map((c) => PUSH_NAME[c]).join("、") : "(不推送,只留在对话里)";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** agent 给的推送渠道:认识的留下 */
|
|
59
|
+
function pushArg(v: unknown): PushChannel[] | undefined {
|
|
60
|
+
return Array.isArray(v) ? PUSH_CHANNELS.filter((c) => v.includes(c)) : undefined;
|
|
61
|
+
}
|
|
62
|
+
|
|
52
63
|
function describeTask(task: Task, convKey: string): string {
|
|
53
64
|
const last = task.runs[0];
|
|
54
65
|
return [
|
|
55
66
|
`- [${task.id}]「${task.title}」${describeSchedule(task.schedule)}`,
|
|
56
67
|
task.enabled && task.nextRunAt ? `下次 ${formatDateTime(task.nextRunAt)}` : "已暂停",
|
|
57
68
|
task.notify === "smart" ? "有需要才提醒" : "每次都提醒",
|
|
69
|
+
`推送到${pushText(taskPush(task))}`,
|
|
58
70
|
`结果发到${whereText(task, convKey)}`,
|
|
59
71
|
...(task.freshContext ? ["每次运行不带之前的上下文"] : []),
|
|
60
72
|
...(last ? [`最近一次 ${formatDateTime(last.at)} ${STATUS[last.status] ?? last.status}${last.preview ? `:${last.preview}` : last.note ? `(${last.note})` : ""}`] : []),
|
|
@@ -88,7 +100,7 @@ function contextLine(task: { fresh: boolean; dedicated: boolean }): string {
|
|
|
88
100
|
return task.dedicated ? "不携带(每次都从头开始)" : "不携带(每次在独立的会话里运行,看不到聊天内容,结果仍显示在这条对话)";
|
|
89
101
|
}
|
|
90
102
|
|
|
91
|
-
function card(fields: { schedule?: TaskSchedule; notify?: string; where?: string; expert?: string; permission?: string; context?: string; prompt?: string; enabled?: boolean }, now: number): string {
|
|
103
|
+
function card(fields: { schedule?: TaskSchedule; notify?: string; push?: PushChannel[]; where?: string; expert?: string; permission?: string; context?: string; prompt?: string; enabled?: boolean }, now: number): string {
|
|
92
104
|
const lines: string[] = [];
|
|
93
105
|
if (fields.schedule) {
|
|
94
106
|
const next = nextRun(fields.schedule, now);
|
|
@@ -96,6 +108,7 @@ function card(fields: { schedule?: TaskSchedule; notify?: string; where?: string
|
|
|
96
108
|
if (next) lines.push(`**下次运行**:${formatDateTime(next)}`);
|
|
97
109
|
}
|
|
98
110
|
if (fields.notify) lines.push(`**提醒**:${fields.notify === "always" ? "每次都提醒" : "有需要才提醒(由 agent 判断)"}`);
|
|
111
|
+
if (fields.push) lines.push(`**推送到**:${pushText(fields.push)}`);
|
|
99
112
|
if (fields.where) lines.push(`**结果发到**:${fields.where}`);
|
|
100
113
|
if (fields.expert) lines.push(`**专家**:${fields.expert}`);
|
|
101
114
|
if (fields.permission) lines.push(`**权限**:${fields.permission}`);
|
|
@@ -142,6 +155,7 @@ async function call(userId: string, convKey: string, tool: string, args: Record<
|
|
|
142
155
|
prompt,
|
|
143
156
|
schedule,
|
|
144
157
|
notify: args.notify === "always" ? "always" : "smart",
|
|
158
|
+
...(pushArg(args.push) ? { push: pushArg(args.push) } : {}),
|
|
145
159
|
target: dedicated ? { kind: "dedicated" } : { kind: "conv", key: convKey },
|
|
146
160
|
expert: expertIdOf(conv),
|
|
147
161
|
cwd: conv.cwd,
|
|
@@ -155,6 +169,7 @@ async function call(userId: string, convKey: string, tool: string, args: Record<
|
|
|
155
169
|
{
|
|
156
170
|
schedule,
|
|
157
171
|
notify: String(input.notify),
|
|
172
|
+
push: (input.push as PushChannel[] | undefined) ?? DEFAULT_PUSH,
|
|
158
173
|
where: dedicated ? "单独开一条对话" : "这条对话",
|
|
159
174
|
...(dedicated ? { expert: expertName } : {}),
|
|
160
175
|
// agent 建的专用对话任务一律从默认开始,要放宽只能用户到页面上改
|
|
@@ -204,6 +219,7 @@ async function call(userId: string, convKey: string, tool: string, args: Record<
|
|
|
204
219
|
if (args.title !== undefined) patch.title = args.title;
|
|
205
220
|
if (args.prompt !== undefined) patch.prompt = args.prompt;
|
|
206
221
|
if (args.notify !== undefined) patch.notify = args.notify;
|
|
222
|
+
if (pushArg(args.push)) patch.push = pushArg(args.push);
|
|
207
223
|
if (args.enabled !== undefined) patch.enabled = args.enabled === true;
|
|
208
224
|
if (args.fresh_context !== undefined) patch.freshContext = args.fresh_context === true;
|
|
209
225
|
if (Object.keys(patch).length === 0) return fail("没有要改的字段。");
|
|
@@ -218,6 +234,7 @@ async function call(userId: string, convKey: string, tool: string, args: Record<
|
|
|
218
234
|
{
|
|
219
235
|
...(patch.schedule ? { schedule: patch.schedule as TaskSchedule } : {}),
|
|
220
236
|
...(patch.notify !== undefined ? { notify: String(patch.notify) } : {}),
|
|
237
|
+
...(patch.push !== undefined ? { push: patch.push as PushChannel[] } : {}),
|
|
221
238
|
permission: taskPermissionLine(task),
|
|
222
239
|
...(patch.freshContext !== undefined ? { context: contextLine({ fresh: patch.freshContext === true, dedicated: task.target.kind === "dedicated" }) } : {}),
|
|
223
240
|
...(patch.enabled !== undefined ? { enabled: patch.enabled === true } : {}),
|
package/src/core/tasks.ts
CHANGED
|
@@ -10,7 +10,10 @@ import path from "node:path";
|
|
|
10
10
|
import { EventEmitter } from "node:events";
|
|
11
11
|
import { dataDir, readJson, writeJsonAtomic } from "../home.js";
|
|
12
12
|
import { describeSchedule, nextRun, normalizeSchedule, type TaskSchedule } from "./task-schedule.js";
|
|
13
|
+
import { config } from "./config.js";
|
|
13
14
|
import { canUseExpert, getExpert, isBuiltin } from "./experts.js";
|
|
15
|
+
import { listLinks } from "./feishu-links.js";
|
|
16
|
+
import { getWeixinAccount } from "./weixin-accounts.js";
|
|
14
17
|
import { isPermissionLevel, type PermissionLevel } from "./permission.js";
|
|
15
18
|
|
|
16
19
|
/**
|
|
@@ -20,6 +23,11 @@ import { isPermissionLevel, type PermissionLevel } from "./permission.js";
|
|
|
20
23
|
*/
|
|
21
24
|
export type TaskTarget = { kind: "conv"; key: string } | { kind: "dedicated"; key?: string };
|
|
22
25
|
|
|
26
|
+
/** 结果推送到哪些渠道:web 是网页 / 桌面端的系统通知(Web Push),feishu / weixin 是发到主人绑定的飞书私聊 / 微信 */
|
|
27
|
+
export const PUSH_CHANNELS = ["web", "feishu", "weixin"] as const;
|
|
28
|
+
export type PushChannel = (typeof PUSH_CHANNELS)[number];
|
|
29
|
+
export const DEFAULT_PUSH: PushChannel[] = ["web"];
|
|
30
|
+
|
|
23
31
|
export type TaskRunStatus = "running" | "notified" | "silent" | "error" | "skipped" | "interrupted";
|
|
24
32
|
|
|
25
33
|
export type TaskRun = {
|
|
@@ -42,6 +50,10 @@ export type Task = {
|
|
|
42
50
|
schedule: TaskSchedule;
|
|
43
51
|
/** smart:只在需要时提醒(agent 判断);always:每次都提醒 */
|
|
44
52
|
notify: "smart" | "always";
|
|
53
|
+
/** 要提醒时推到哪些渠道。没有就是只推 Web(DEFAULT_PUSH);空数组表示哪都不推,只留在对话里 */
|
|
54
|
+
push?: PushChannel[];
|
|
55
|
+
/** 推送到飞书时用哪个机器人(主人绑定的那几个之一)。没有就用第一个在线的 */
|
|
56
|
+
feishuBot?: string;
|
|
45
57
|
target: TaskTarget;
|
|
46
58
|
/** 专用对话的设置(target 是 conv 时不用,以那条对话为准)。agent 是引擎;expert 是自定义专家的 id,没有就是内置专家 agent */
|
|
47
59
|
agent: string;
|
|
@@ -138,6 +150,8 @@ export type TaskInput = {
|
|
|
138
150
|
prompt?: unknown;
|
|
139
151
|
schedule?: unknown;
|
|
140
152
|
notify?: unknown;
|
|
153
|
+
push?: unknown;
|
|
154
|
+
feishuBot?: unknown;
|
|
141
155
|
target?: unknown;
|
|
142
156
|
/** 专家 id(内置的 claude / codex,或者自定义专家)。agent 是以前的叫法,照样认 */
|
|
143
157
|
expert?: unknown;
|
|
@@ -173,6 +187,38 @@ function cleanExpert(owner: string, v: unknown): { agent: string; expert?: strin
|
|
|
173
187
|
return { agent: getExpert(id)!.engine, expert: id };
|
|
174
188
|
}
|
|
175
189
|
|
|
190
|
+
/** 推送渠道:认识的留下、去重;不是数组就当没给 */
|
|
191
|
+
function cleanPush(v: unknown): PushChannel[] | undefined {
|
|
192
|
+
if (!Array.isArray(v)) return undefined;
|
|
193
|
+
return PUSH_CHANNELS.filter((c) => v.includes(c));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** 这个任务的结果推到哪些渠道 */
|
|
197
|
+
export function taskPush(t: Pick<Task, "push">): PushChannel[] {
|
|
198
|
+
return t.push ?? DEFAULT_PUSH;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** 这个人能推送到哪:飞书要在启用着的机器人上绑定过,微信要扫码绑定过 */
|
|
202
|
+
export type PushOptions = { feishu: { id: string; name: string }[]; weixin: boolean };
|
|
203
|
+
|
|
204
|
+
export function pushOptions(owner: string): PushOptions {
|
|
205
|
+
const bots = config().feishu.bots.filter((b) => b.enabled);
|
|
206
|
+
const linked = new Set(listLinks(owner).map((l) => l.botId));
|
|
207
|
+
return { feishu: bots.filter((b) => linked.has(b.id)).map((b) => ({ id: b.id, name: b.name })), weixin: !!getWeixinAccount(owner) };
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** 推送渠道和飞书机器人一起核:没绑定的渠道、不是自己绑的机器人都不收 */
|
|
211
|
+
function cleanPushFields(owner: string, pushIn: unknown, botIn: unknown, prev?: Pick<Task, "push" | "feishuBot">): { push?: PushChannel[]; feishuBot?: string } {
|
|
212
|
+
const push = (pushIn === undefined ? prev?.push : cleanPush(pushIn) ?? DEFAULT_PUSH) ?? DEFAULT_PUSH;
|
|
213
|
+
const opts = pushOptions(owner);
|
|
214
|
+
if (pushIn !== undefined && push.includes("feishu") && opts.feishu.length === 0) throw new Error("还没有绑定飞书,不能推送到飞书");
|
|
215
|
+
if (pushIn !== undefined && push.includes("weixin") && !opts.weixin) throw new Error("还没有绑定微信,不能推送到微信");
|
|
216
|
+
let bot = botIn === undefined ? prev?.feishuBot : str(botIn) || undefined;
|
|
217
|
+
if (bot && botIn !== undefined && !opts.feishu.some((b) => b.id === bot)) throw new Error("这个飞书机器人没有绑定你的飞书账号");
|
|
218
|
+
if (!push.includes("feishu")) bot = undefined;
|
|
219
|
+
return { ...(push.join() !== DEFAULT_PUSH.join() ? { push } : {}), ...(bot ? { feishuBot: bot } : {}) };
|
|
220
|
+
}
|
|
221
|
+
|
|
176
222
|
function cleanPermission(v: unknown): PermissionLevel | undefined {
|
|
177
223
|
const s = str(v);
|
|
178
224
|
if (!s) return undefined;
|
|
@@ -201,6 +247,7 @@ export function createTask(owner: string, input: TaskInput, by: "user" | "agent"
|
|
|
201
247
|
prompt,
|
|
202
248
|
schedule,
|
|
203
249
|
notify: input.notify === "always" ? "always" : "smart",
|
|
250
|
+
...cleanPushFields(owner, input.push, input.feishuBot),
|
|
204
251
|
target: cleanTarget(input.target),
|
|
205
252
|
...picked,
|
|
206
253
|
...(str(input.cwd) ? { cwd: str(input.cwd) } : {}),
|
|
@@ -230,6 +277,12 @@ export function updateTask(owner: string, id: string, patch: TaskInput, now = Da
|
|
|
230
277
|
if (patch.title !== undefined) next.title = cleanTitle(patch.title, next.prompt);
|
|
231
278
|
if (patch.schedule !== undefined) next.schedule = normalizeSchedule(patch.schedule, now);
|
|
232
279
|
if (patch.notify !== undefined) next.notify = patch.notify === "always" ? "always" : "smart";
|
|
280
|
+
if (patch.push !== undefined || patch.feishuBot !== undefined) {
|
|
281
|
+
const fields = cleanPushFields(owner, patch.push, patch.feishuBot, task);
|
|
282
|
+
delete next.push;
|
|
283
|
+
delete next.feishuBot;
|
|
284
|
+
Object.assign(next, fields);
|
|
285
|
+
}
|
|
233
286
|
if (patch.target !== undefined) next.target = cleanTarget(patch.target, task.target);
|
|
234
287
|
const pick = patch.expert ?? patch.agent;
|
|
235
288
|
if (pick !== undefined && str(pick)) {
|
package/src/core/types.ts
CHANGED
|
@@ -135,8 +135,23 @@ export type AgentEvents = {
|
|
|
135
135
|
* 否则是新增的量(Codex,每次模型请求报一次),由核心累加
|
|
136
136
|
*/
|
|
137
137
|
onUsage?: (usage: TokenUsage, cumulative?: boolean) => void;
|
|
138
|
+
/**
|
|
139
|
+
* 不是从这边发起的一轮开始了(Codex 语音对话把事情转交给它):text 是用户说的话,anchor 是轮次 id。
|
|
140
|
+
* 核心据此像收到一条用户消息那样记账(显示、忙碌、排队、改动快照),之后照常有 onResult / onError
|
|
141
|
+
*/
|
|
142
|
+
onExternalTurn?: (text: string, anchor?: string) => void;
|
|
143
|
+
/** 实时语音对话的动静(只有 Codex):字幕、开始、结束、出错 */
|
|
144
|
+
onRealtime?: (ev: RealtimeEvent) => void;
|
|
138
145
|
};
|
|
139
146
|
|
|
147
|
+
/** 实时语音对话的事件(Codex 的 thread/realtime/*) */
|
|
148
|
+
export type RealtimeEvent =
|
|
149
|
+
| { type: "started" }
|
|
150
|
+
| { type: "transcript"; role: "user" | "assistant"; delta: string }
|
|
151
|
+
| { type: "transcript_done"; role: "user" | "assistant"; text: string }
|
|
152
|
+
| { type: "error"; message: string }
|
|
153
|
+
| { type: "closed"; reason?: string };
|
|
154
|
+
|
|
140
155
|
/** 上下文窗口占用:used / window 都是 token 数,percent 是 0-100(可能略超 100) */
|
|
141
156
|
export type ContextUsage = { used: number; window: number; percent: number };
|
|
142
157
|
|
|
@@ -299,6 +314,10 @@ export interface AgentSession {
|
|
|
299
314
|
setPermission?(level: PermissionLevel | undefined): Promise<void>;
|
|
300
315
|
/** 开关计划模式。Claude 立即生效,Codex 下一轮生效 */
|
|
301
316
|
setPlan?(on: boolean): Promise<void>;
|
|
317
|
+
/** 开始实时语音对话(只有 Codex):offer 是浏览器的 WebRTC SDP,返回对端的 answer */
|
|
318
|
+
startRealtime?(offer: string): Promise<string>;
|
|
319
|
+
/** 挂断实时语音对话;没在通话就什么都不做 */
|
|
320
|
+
stopRealtime?(): Promise<void>;
|
|
302
321
|
}
|
|
303
322
|
|
|
304
323
|
export type Diagnosis = {
|
package/src/mcp/tasks-server.ts
CHANGED
|
@@ -61,6 +61,7 @@ const TOOLS = [
|
|
|
61
61
|
prompt: { type: "string", description: "到点时发给 agent 的完整指令" },
|
|
62
62
|
schedule: SCHEDULE,
|
|
63
63
|
notify: { type: "string", enum: ["smart", "always"], description: "smart:有需要才提醒(默认);always:每次都提醒" },
|
|
64
|
+
push: { type: "array", items: { type: "string", enum: ["web", "feishu", "weixin"] }, description: "要提醒时推送到哪些渠道:web(网页 / 桌面端系统通知,默认)、feishu(用户绑定的飞书私聊)、weixin(用户绑定的微信)。可多选;空数组表示只留在对话里不推送" },
|
|
64
65
|
reply_to: {
|
|
65
66
|
type: "string",
|
|
66
67
|
enum: ["this_conversation", "dedicated"],
|
|
@@ -87,6 +88,7 @@ const TOOLS = [
|
|
|
87
88
|
prompt: { type: "string" },
|
|
88
89
|
schedule: SCHEDULE,
|
|
89
90
|
notify: { type: "string", enum: ["smart", "always"] },
|
|
91
|
+
push: { type: "array", items: { type: "string", enum: ["web", "feishu", "weixin"] }, description: "要提醒时推送到哪些渠道:web(网页 / 桌面端系统通知,默认)、feishu(用户绑定的飞书私聊)、weixin(用户绑定的微信)。可多选;空数组表示只留在对话里不推送" },
|
|
90
92
|
enabled: { type: "boolean", description: "false 暂停,true 恢复" },
|
|
91
93
|
fresh_context: { type: "boolean", description: "true:每次运行不带之前的上下文;false:改回携带(之前不携带时运行的内容不会恢复)" },
|
|
92
94
|
},
|
package/web/css/composer.css
CHANGED
|
@@ -541,3 +541,167 @@ textarea.sending {
|
|
|
541
541
|
display: none;
|
|
542
542
|
}
|
|
543
543
|
}
|
|
544
|
+
|
|
545
|
+
/* ---- 语音对话:通话时输入框换成通话条(views/voice-call.js) ---- */
|
|
546
|
+
|
|
547
|
+
.call-btn[hidden] {
|
|
548
|
+
display: none;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
.call-panel {
|
|
552
|
+
background: var(--bg-input);
|
|
553
|
+
border: 1px solid color-mix(in srgb, var(--border) 85%, transparent);
|
|
554
|
+
border-radius: 22px;
|
|
555
|
+
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03), 0 4px 16px rgba(0, 0, 0, 0.05);
|
|
556
|
+
padding: 10px 10px 10px 16px;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
.call-main {
|
|
560
|
+
display: flex;
|
|
561
|
+
align-items: center;
|
|
562
|
+
gap: 14px;
|
|
563
|
+
min-width: 0;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
.call-wave {
|
|
567
|
+
display: flex;
|
|
568
|
+
align-items: center;
|
|
569
|
+
gap: 3px;
|
|
570
|
+
height: 28px;
|
|
571
|
+
flex-shrink: 0;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
.call-bar {
|
|
575
|
+
width: 4px;
|
|
576
|
+
height: 100%;
|
|
577
|
+
border-radius: 2px;
|
|
578
|
+
background: var(--fg);
|
|
579
|
+
transform: scaleY(0.2);
|
|
580
|
+
transition: transform 80ms linear;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
.call-panel.speaking .call-bar {
|
|
584
|
+
background: var(--accent);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
.call-panel.connecting .call-bar {
|
|
588
|
+
opacity: 0.45;
|
|
589
|
+
animation: call-wait 1.1s ease-in-out infinite;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
.call-panel.connecting .call-bar:nth-child(2) { animation-delay: 0.1s; }
|
|
593
|
+
.call-panel.connecting .call-bar:nth-child(3) { animation-delay: 0.2s; }
|
|
594
|
+
.call-panel.connecting .call-bar:nth-child(4) { animation-delay: 0.3s; }
|
|
595
|
+
.call-panel.connecting .call-bar:nth-child(5) { animation-delay: 0.4s; }
|
|
596
|
+
|
|
597
|
+
@keyframes call-wait {
|
|
598
|
+
0%, 100% { transform: scaleY(0.2); }
|
|
599
|
+
50% { transform: scaleY(0.6); }
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
.call-info {
|
|
603
|
+
flex: 1;
|
|
604
|
+
min-width: 0;
|
|
605
|
+
display: flex;
|
|
606
|
+
flex-direction: column;
|
|
607
|
+
gap: 2px;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
.call-line {
|
|
611
|
+
display: flex;
|
|
612
|
+
align-items: baseline;
|
|
613
|
+
gap: 8px;
|
|
614
|
+
font-size: 14px;
|
|
615
|
+
font-weight: 500;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
.call-time {
|
|
619
|
+
color: var(--fg-faint);
|
|
620
|
+
font-size: 12px;
|
|
621
|
+
font-variant-numeric: tabular-nums;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
.call-caption {
|
|
625
|
+
display: flex;
|
|
626
|
+
gap: 6px;
|
|
627
|
+
min-width: 0;
|
|
628
|
+
font-size: 13px;
|
|
629
|
+
color: var(--fg-faint);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
.call-panel.has-caption .call-caption {
|
|
633
|
+
color: var(--fg);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
.call-who {
|
|
637
|
+
flex-shrink: 0;
|
|
638
|
+
color: var(--fg-faint);
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
.call-who:empty {
|
|
642
|
+
display: none;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
/* 字幕只留最近两行:长句子往上滚走 */
|
|
646
|
+
.call-text {
|
|
647
|
+
min-width: 0;
|
|
648
|
+
display: -webkit-box;
|
|
649
|
+
-webkit-box-orient: vertical;
|
|
650
|
+
-webkit-line-clamp: 2;
|
|
651
|
+
overflow: hidden;
|
|
652
|
+
line-height: 1.45;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
.call-ctls {
|
|
656
|
+
display: flex;
|
|
657
|
+
align-items: center;
|
|
658
|
+
gap: 8px;
|
|
659
|
+
flex-shrink: 0;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
.call-ctl {
|
|
663
|
+
height: 36px;
|
|
664
|
+
min-width: 36px;
|
|
665
|
+
border-radius: 18px;
|
|
666
|
+
display: inline-grid;
|
|
667
|
+
place-items: center;
|
|
668
|
+
background: var(--bg-soft);
|
|
669
|
+
color: var(--fg);
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
.call-ctl svg {
|
|
673
|
+
width: 18px;
|
|
674
|
+
height: 18px;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
.call-ctl.on {
|
|
678
|
+
color: var(--danger);
|
|
679
|
+
background: color-mix(in srgb, var(--danger) 12%, transparent);
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
.call-ctl.call-end {
|
|
683
|
+
padding: 0 16px;
|
|
684
|
+
font-size: 14px;
|
|
685
|
+
font-weight: 500;
|
|
686
|
+
color: #fff;
|
|
687
|
+
background: var(--danger);
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
@media (max-width: 640px) {
|
|
691
|
+
.call-panel {
|
|
692
|
+
padding-left: 12px;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
.call-main {
|
|
696
|
+
gap: 10px;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
.call-ctl.call-end {
|
|
700
|
+
padding: 0 12px;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
/* 通话中输入框收起来,通话条顶上 */
|
|
705
|
+
.composer.in-call {
|
|
706
|
+
display: none;
|
|
707
|
+
}
|
package/web/css/experts.css
CHANGED
|
@@ -156,6 +156,72 @@
|
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
+
/* ---- 专家编辑框:按用途分组 ---- */
|
|
160
|
+
|
|
161
|
+
.expert-form {
|
|
162
|
+
gap: 18px;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.form-section {
|
|
166
|
+
display: flex;
|
|
167
|
+
flex-direction: column;
|
|
168
|
+
gap: 12px;
|
|
169
|
+
min-width: 0;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.form-section + .form-section {
|
|
173
|
+
padding-top: 16px;
|
|
174
|
+
border-top: 1px solid var(--border);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.form-section-title {
|
|
178
|
+
margin: 0;
|
|
179
|
+
font-size: 13px;
|
|
180
|
+
font-weight: 600;
|
|
181
|
+
color: var(--fg-faint);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/* 两列的勾选:说明另起一行,不截断(权限、Codex 扩展能力) */
|
|
185
|
+
.check-list.grid {
|
|
186
|
+
display: grid;
|
|
187
|
+
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
188
|
+
gap: 10px 16px;
|
|
189
|
+
max-height: none;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
.check-list.grid > .check-item {
|
|
193
|
+
flex-wrap: wrap;
|
|
194
|
+
align-items: center;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.check-list.grid > .check-item > small {
|
|
198
|
+
flex: 1 0 100%;
|
|
199
|
+
padding-left: 24px;
|
|
200
|
+
white-space: normal;
|
|
201
|
+
line-height: 1.45;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.check-item.disabled {
|
|
205
|
+
cursor: not-allowed;
|
|
206
|
+
opacity: 0.55;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.check-tag {
|
|
210
|
+
margin-left: 6px;
|
|
211
|
+
padding: 0 6px;
|
|
212
|
+
border-radius: 999px;
|
|
213
|
+
font-size: 11px;
|
|
214
|
+
font-style: normal;
|
|
215
|
+
color: var(--fg-faint);
|
|
216
|
+
background: var(--bg-soft);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
@media (max-width: 640px) {
|
|
220
|
+
.check-list.grid {
|
|
221
|
+
grid-template-columns: minmax(0, 1fr);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
159
225
|
/* 按类型切换的一组字段:和别的字段一样排(间距由 .task-form 给) */
|
|
160
226
|
.field-group {
|
|
161
227
|
display: contents;
|
package/web/css/tasks.css
CHANGED
package/web/lib/ws.js
CHANGED
|
@@ -11,6 +11,7 @@ import { setBusy } from "../views/composer.js";
|
|
|
11
11
|
import { SH, shownHere } from "./shell.js";
|
|
12
12
|
import { currentPushSub } from "./push.js";
|
|
13
13
|
import { renderScheduled } from "../views/schedule.js";
|
|
14
|
+
import { onRealtimeEvent } from "../views/voice-call.js";
|
|
14
15
|
import { reloadExperts } from "../views/experts.js";
|
|
15
16
|
|
|
16
17
|
// ---------- WebSocket ----------
|
|
@@ -245,6 +246,9 @@ function onWsMessage(msg) {
|
|
|
245
246
|
case "ev":
|
|
246
247
|
applyEvent(msg);
|
|
247
248
|
return;
|
|
249
|
+
case "rt":
|
|
250
|
+
onRealtimeEvent(msg);
|
|
251
|
+
return;
|
|
248
252
|
case "replay":
|
|
249
253
|
if (msg.key !== S.current) return;
|
|
250
254
|
if (msg.reset) {
|