agent-loft 0.2.109 → 0.2.111

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-loft",
3
- "version": "0.2.109",
3
+ "version": "0.2.111",
4
4
  "type": "module",
5
5
  "description": "多个 agent 的工作台:把本机 Claude Code / Codex 放到一处统一管理,用飞书和 Web 页面随时驱动——会话、审批、模型切换都共用",
6
6
  "keywords": [
@@ -47,10 +47,11 @@ export class FeishuClient {
47
47
  }
48
48
  }
49
49
 
50
- async sendCard(chatId: string, card: unknown): Promise<string | undefined> {
50
+ /** idType 是 open_id 时 chatId 填用户的 open_id:直接发到和这个人的私聊 */
51
+ async sendCard(chatId: string, card: unknown, idType: "chat_id" | "open_id" = "chat_id"): Promise<string | undefined> {
51
52
  try {
52
53
  const res = await this.lark.im.v1.message.create({
53
- params: { receive_id_type: "chat_id" },
54
+ params: { receive_id_type: idType },
54
55
  data: { receive_id: chatId, msg_type: "interactive", content: JSON.stringify(card) },
55
56
  });
56
57
  const messageId = res.data?.message_id;
@@ -1,7 +1,12 @@
1
1
  // 飞书渠道:按配置拉起 / 停掉机器人。Web 上改了机器人配置,这里就地对账,不用重启进程。
2
2
  import { config, onConfigChange, type FeishuBotConfig } from "../../core/config.js";
3
+ import { listLinks } from "../../core/feishu-links.js";
4
+ import { hub, type TaskTurnEnd } from "../../core/hub.js";
3
5
  import { watchPairing } from "../../core/pairing.js";
6
+ import { getConversation } from "../../core/store.js";
7
+ import { findTask, taskPush } from "../../core/tasks.js";
4
8
  import { FeishuBot } from "./bot.js";
9
+ import { replyCard } from "./cards.js";
5
10
 
6
11
  const bots = new Map<string, FeishuBot>();
7
12
 
@@ -35,7 +40,27 @@ function reconcile(list: FeishuBotConfig[]): void {
35
40
  }
36
41
  }
37
42
 
43
+ /**
44
+ * 定时任务选了推送到飞书:把结果发到主人绑定的飞书私聊。
45
+ * 任务本来就发在飞书对话里的不用再发(那边已经显示了)。绑了多个机器人的,用任务指定的那个,没指定发第一个在线的。
46
+ */
47
+ function onTaskResult(e: TaskTurnEnd): void {
48
+ if (e.status !== "notified") return;
49
+ const task = findTask(e.taskId);
50
+ if (!task || !taskPush(task).includes("feishu")) return;
51
+ if (getConversation(e.key)?.channel === "feishu") return;
52
+ // 指定了机器人就只用它(它不在线就不发,不悄悄换成别的机器人);没指定用第一个在线的
53
+ const link = listLinks(task.owner).find((l) => bots.has(l.botId) && (!task.feishuBot || l.botId === task.feishuBot));
54
+ if (!link) {
55
+ console.warn(`[飞书] 定时任务「${task.title}」要推送到飞书,但${task.feishuBot ? "指定的机器人不在线或已解绑" : "主人没有绑定在线的飞书机器人"}`);
56
+ return;
57
+ }
58
+ void bots.get(link.botId)!.client.sendCard(link.openId, replyCard(`⏰ **${e.title}**\n\n${e.text}`), "open_id");
59
+ }
60
+
38
61
  export function startFeishu(): void {
62
+ hub.off("task", onTaskResult);
63
+ hub.on("task", onTaskResult);
39
64
  reconcile(config().feishu.bots);
40
65
  onConfigChange((next, prev) => {
41
66
  reconcile(next.feishu.bots);
@@ -55,6 +80,7 @@ export function startFeishu(): void {
55
80
  }
56
81
 
57
82
  export function stopFeishu(): void {
83
+ hub.off("task", onTaskResult);
58
84
  for (const bot of bots.values()) bot.stop();
59
85
  bots.clear();
60
86
  }
@@ -14,7 +14,7 @@ import { GLOBAL_ALWAYS_DENIED, hub, type EventEnvelope } from "../../core/hub.js
14
14
  import { interactions, type Interaction } from "../../core/interactions.js";
15
15
  import { weixinEvents } from "../weixin/events.js";
16
16
  import { getConversation } from "../../core/store.js";
17
- import { taskEvents } from "../../core/tasks.js";
17
+ import { findTask, taskEvents, taskPush } from "../../core/tasks.js";
18
18
  import { skillEvents } from "../../core/skills.js";
19
19
  import { expertEvents } from "../../core/experts.js";
20
20
  import { enforceTerminalAccess, killAllTerminals, terminalEvents, watchTerminalAccess } from "../../core/terminals.js";
@@ -414,9 +414,11 @@ function onWeixinUndelivered({ key, body }: { key: string; body: string }): void
414
414
  function pushEvent(env: EventEnvelope): void {
415
415
  const ev = env.ev;
416
416
  if (ev.type !== "result" && ev.type !== "error") return;
417
- if (!isWebConv(env.key)) return;
418
417
  // 定时任务这次判断不用提醒
419
418
  if (ev.type === "result" && ev.silent) return;
419
+ // 定时任务的结果按任务选的推送渠道:没选 Web 就不推;选了的话发到飞书 / 微信对话里的也推
420
+ const task = ev.type === "result" && ev.task ? findTask(ev.task.id) : undefined;
421
+ if (task ? !taskPush(task).includes("web") : !isWebConv(env.key)) return;
420
422
  const name = convName(env.key);
421
423
  const payload =
422
424
  ev.type === "result"
@@ -424,7 +426,7 @@ function pushEvent(env: EventEnvelope): void {
424
426
  ? { title: `⏰ ${ev.task.title}`, body: plainPreview(ev.text) || "(没有文字回复)" }
425
427
  : { title: `${name} · 回复完成`, body: plainPreview(ev.text) || "(没有文字回复)" }
426
428
  : { title: `${name} · 出错了`, body: plainPreview(ev.message) };
427
- notify(env.key, { ...payload, tag: `reply:${env.key}` });
429
+ deliverNotice(env.key, { ...payload, tag: `reply:${env.key}` });
428
430
  }
429
431
 
430
432
  function pushInteraction(i: Interaction): void {
@@ -8,7 +8,7 @@ import { memoryOwnerOf } from "../../core/personal.js";
8
8
  import { expertIdOf, getConversation } from "../../core/store.js";
9
9
  import { forgetTask, isTaskRunning, releaseTaskConv, runTaskNow } from "../../core/task-runner.js";
10
10
  import { serverTimeZone } from "../../core/task-schedule.js";
11
- import { createTask, deleteTask, getTask, listTasks, updateTask, viewOf, type Task, type TaskInput } from "../../core/tasks.js";
11
+ import { createTask, deleteTask, getTask, listTasks, pushOptions, updateTask, viewOf, type Task, type TaskInput } from "../../core/tasks.js";
12
12
  import type { User } from "../../core/users.js";
13
13
  import { HttpError, readJsonBody, sendJson } from "./http.js";
14
14
 
@@ -91,7 +91,9 @@ const bad = (err: unknown) => (err instanceof HttpError ? err : new HttpError(40
91
91
  export async function handleTasksApi(req: IncomingMessage, res: ServerResponse, p: string, user: User): Promise<boolean> {
92
92
  const method = req.method ?? "GET";
93
93
  if (p === "/api/tasks" && method === "GET") {
94
- sendJson(res, 200, { tasks: listTasks(user.id).map(view), tz: serverTimeZone(), now: Date.now() });
94
+ // 能推送到哪些渠道:飞书 / 微信要先绑定(设置里)
95
+ const channels = pushOptions(user.id);
96
+ sendJson(res, 200, { tasks: listTasks(user.id).map(view), tz: serverTimeZone(), now: Date.now(), channels });
95
97
  return true;
96
98
  }
97
99
  if (p === "/api/tasks" && method === "POST") {
@@ -409,6 +409,12 @@ export class WeixinBot {
409
409
 
410
410
  // ---------- 发消息 ----------
411
411
 
412
+ /** 别的对话里的定时任务选了推送到微信:把结果发过来 */
413
+ pushTaskResult(title: string, text: string): void {
414
+ const body = `⏰ ${title}\n\n${text}`;
415
+ if (text.trim()) this.reply(body);
416
+ }
417
+
412
418
  private remaining(): number {
413
419
  return SEND_LIMIT - this.account.sentSinceInbound;
414
420
  }
@@ -1,4 +1,6 @@
1
1
  // 微信渠道:按绑定拉起 / 停掉长轮询。扫码、解绑、停用用户后就地对账,不用重启进程。
2
+ import { hub, type TaskTurnEnd } from "../../core/hub.js";
3
+ import { findTask, taskPush } from "../../core/tasks.js";
2
4
  import { getUser, userEvents } from "../../core/users.js";
3
5
  import { listWeixinAccounts, weixinAccountEvents, type WeixinAccount } from "../../core/weixin-accounts.js";
4
6
  import { WeixinBot, type WeixinStatus } from "./bot.js";
@@ -30,9 +32,25 @@ function reconcile(): void {
30
32
  }
31
33
  }
32
34
 
35
+ /** 定时任务选了推送到微信:发到主人绑定的微信 */
36
+ function onTaskResult(e: TaskTurnEnd): void {
37
+ if (e.status !== "notified") return;
38
+ const task = findTask(e.taskId);
39
+ if (!task || !taskPush(task).includes("weixin")) return;
40
+ const bot = bots.get(task.owner);
41
+ if (!bot) {
42
+ console.warn(`[微信] 定时任务「${task.title}」要推送到微信,但主人没有绑定微信`);
43
+ return;
44
+ }
45
+ // 发在微信正接着的那条对话里:结果已经发过去了
46
+ if (e.key === bot.key) return;
47
+ bot.pushTaskResult(e.title, e.text);
48
+ }
49
+
33
50
  export function startWeixin(): void {
34
51
  if (started) return;
35
52
  started = true;
53
+ hub.on("task", onTaskResult);
36
54
  reconcile();
37
55
  weixinAccountEvents.on("changed", reconcile);
38
56
  userEvents.on("changed", reconcile);
@@ -40,6 +58,7 @@ export function startWeixin(): void {
40
58
 
41
59
  export function stopWeixin(): void {
42
60
  started = false;
61
+ hub.off("task", onTaskResult);
43
62
  weixinAccountEvents.off("changed", reconcile);
44
63
  userEvents.off("changed", reconcile);
45
64
  stopWeixinLogins();
@@ -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)) {
@@ -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
  },
@@ -7,8 +7,9 @@
7
7
  .album-hero { position: relative; background: #121315; }
8
8
  .album-track { display: flex; width: 100%; overflow-x: auto; scrollbar-width: none; scroll-snap-type: x mandatory; overscroll-behavior-x: contain; }
9
9
  .album-track::-webkit-scrollbar, .album-filmstrip::-webkit-scrollbar { display: none; }
10
- .album-slide { position: relative; display: grid; place-items: center; flex: 0 0 100%; min-width: 0; height: clamp(260px, 52vw, 480px); padding: 0; border: 0; border-radius: 0; background: radial-gradient(ellipse at 50% 40%, #292b30, #121315 85%); scroll-snap-align: start; cursor: zoom-in; }
11
- .md .album-slide img { display: block; width: 100%; height: 100%; max-width: 100%; max-height: 100%; margin: 0; border-radius: 0; object-fit: contain; user-select: none; -webkit-user-drag: none; }
10
+ .album-slide { position: relative; display: grid; place-items: center; flex: 0 0 100%; min-width: 0; overflow: hidden; height: clamp(260px, 52vw, 480px); padding: 0; border: 0; border-radius: 0; background: radial-gradient(ellipse at 50% 40%, #292b30, #121315 85%); scroll-snap-align: start; cursor: zoom-in; }
11
+ /* 绝对定位铺满整格再 contain:放在 grid 里用 height: 100% 时,行高跟着图片原始尺寸走,大照片会撑出去、被裁成「放大」的样子 */
12
+ .md .album-slide img { position: absolute; inset: 0; display: block; width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; border-radius: 0; object-fit: contain; user-select: none; -webkit-user-drag: none; }
12
13
  .album-slide-hint { position: absolute; right: 14px; top: 14px; display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px; color: #fff; background: rgb(0 0 0 / 38%); font-size: 11px; opacity: 0; transition: opacity 0.15s; }
13
14
  .album-slide:hover .album-slide-hint, .album-slide:focus-visible .album-slide-hint { opacity: 1; }
14
15
  .album-slide-hint svg, .album-open svg { width: 14px; height: 14px; }
package/web/css/tasks.css CHANGED
@@ -404,6 +404,11 @@ button.task-run:hover {
404
404
  }
405
405
 
406
406
  .task-weekly-heading,
407
+ /* 推送渠道:和星期同款的按钮,列数按显示几个渠道在 JS 里设 */
408
+ .task-push {
409
+ margin-top: 0;
410
+ }
411
+
407
412
  .task-clock-row {
408
413
  display: flex;
409
414
  align-items: center;
@@ -16,7 +16,16 @@ import { capOfAccess, FULL_WARNING, minPermission, PERMISSIONS, permissionsUpTo
16
16
  // 到点让 agent 按提示词干活,结果回到一条对话里;「有需要才提醒」时由 agent 判断这次要不要打扰你。
17
17
  // 列表只有自己的任务(服务端按人过滤)。任务有变化时服务端推 { t: "tasks" },这里重新拉一遍。
18
18
 
19
- const T = { list: [], tz: "", token: 0, reloadTimer: 0 };
19
+ const T = { list: [], tz: "", token: 0, reloadTimer: 0, channels: null };
20
+
21
+ /** 结果推送的渠道。飞书 / 微信要先在设置里绑定 */
22
+ const PUSH = [
23
+ ["web", "Web"],
24
+ ["feishu", "飞书"],
25
+ ["weixin", "微信"],
26
+ ];
27
+ const pushOf = (t) => t.push ?? ["web"];
28
+ const pushLabel = (push) => (push.length ? `推送到${push.map((c) => PUSH.find(([v]) => v === c)?.[1] ?? c).join("、")}` : "不推送");
20
29
 
21
30
  const STATUS = {
22
31
  running: { text: "运行中", cls: "run" },
@@ -111,6 +120,7 @@ async function reload() {
111
120
  if (my !== T.token || S.view !== "tasks") return;
112
121
  T.list = data.tasks;
113
122
  T.tz = data.tz;
123
+ T.channels = data.channels ?? null;
114
124
  render();
115
125
  } catch (err) {
116
126
  if (my === T.token && S.view === "tasks") fill(ui.msgInner, h("div", { class: "empty" }, err.message));
@@ -238,6 +248,7 @@ function taskCard(t) {
238
248
  h("span", {}, t.summary),
239
249
  h("span", {}, state),
240
250
  h("span", {}, t.notify === "smart" ? "有需要才提醒" : "每次都提醒"),
251
+ h("span", {}, pushLabel(pushOf(t))),
241
252
  h("span", {}, where),
242
253
  t.freshContext ? h("span", {}, "不带上下文") : null,
243
254
  t.target.kind === "dedicated" && t.permission ? h("span", { class: t.permission === "full" ? "task-perm-full" : "" }, PERMISSIONS[t.permission].label) : null,
@@ -416,6 +427,42 @@ export function openTaskForm(task, preset) {
416
427
  h("option", { value: "always", selected: src.notify === "always" }, "每次都提醒"),
417
428
  );
418
429
 
430
+ // ---- 推送渠道(可多选,默认 Web)。飞书 / 微信没绑定就不列出来 ----
431
+ let push = [...pushOf(src)];
432
+ let feishuBot = src.feishuBot ?? "";
433
+ const pushBox = h("div", { class: "task-weekdays task-push", role: "group", "aria-label": "推送渠道(可多选)" });
434
+ const botSelect = h("select", { class: "task-feishu-bot", "aria-label": "推送用的飞书机器人" });
435
+ botSelect.onchange = () => (feishuBot = botSelect.value);
436
+ const botField = field("飞书机器人", botSelect, "你绑定了多个飞书机器人,选一个来推送。选定的机器人不在线时不会改用别的。");
437
+ const pushHint = h("small", {});
438
+ const bound = (c) => c === "web" || (c === "feishu" ? !!T.channels?.feishu?.length : !!T.channels?.weixin);
439
+ const renderPush = () => {
440
+ const shown = PUSH.filter(([c]) => bound(c));
441
+ pushBox.style.gridTemplateColumns = `repeat(${shown.length}, minmax(0, 1fr))`;
442
+ fill(
443
+ pushBox,
444
+ shown.map(([c, label]) => {
445
+ const b = h("button", { type: "button", class: "task-weekday", "aria-pressed": String(push.includes(c)) }, label);
446
+ b.onclick = () => {
447
+ push = push.includes(c) ? push.filter((x) => x !== c) : [...push, c];
448
+ b.setAttribute("aria-pressed", String(push.includes(c)));
449
+ syncBot();
450
+ };
451
+ return b;
452
+ }),
453
+ );
454
+ const missing = PUSH.filter(([c]) => !bound(c)).map(([, label]) => label);
455
+ pushHint.textContent = `要提醒时推到哪里,都不选就只留在对话里。${missing.length ? `${missing.join("、")}要先在设置里绑定才能选。` : "飞书、微信发到你绑定的私聊。"}`;
456
+ const bots = T.channels?.feishu ?? [];
457
+ if (feishuBot && !bots.some((b) => b.id === feishuBot)) feishuBot = "";
458
+ fill(botSelect, h("option", { value: "", selected: !feishuBot }, "自动(第一个在线的)"), bots.map((b) => h("option", { value: b.id, selected: b.id === feishuBot }, b.name)));
459
+ syncBot();
460
+ };
461
+ const syncBot = () => (botField.hidden = !(push.includes("feishu") && (T.channels?.feishu?.length ?? 0) > 1));
462
+ renderPush();
463
+ // 不是从定时任务页打开的:还不知道绑定了什么,拉一下
464
+ if (!T.channels) void api("/api/tasks").then((d) => ((T.channels = d.channels ?? null), renderPush()), () => {});
465
+
419
466
  // ---- 结果发到哪 ----
420
467
  const currentTarget = task?.target?.kind === "conv" ? task.target.key : "dedicated";
421
468
  const target = h(
@@ -537,6 +584,8 @@ export function openTaskForm(task, preset) {
537
584
  field("频率", freq),
538
585
  field("执行时间", freqBox, freqHint),
539
586
  field("提醒", notify),
587
+ h("div", { class: "field" }, h("span", {}, "推送渠道"), pushBox, pushHint),
588
+ botField,
540
589
  field("结果发到", target),
541
590
  convBox,
542
591
  dedicatedBox,
@@ -594,6 +643,9 @@ export function openTaskForm(task, preset) {
594
643
  prompt: prompt.value,
595
644
  schedule,
596
645
  notify: notify.value,
646
+ // 之前勾过、后来解绑了的渠道不再提交(还没拿到绑定情况时原样提交,由服务端核)
647
+ push: PUSH.map(([c]) => c).filter((c) => push.includes(c) && (bound(c) || !T.channels)),
648
+ feishuBot: push.includes("feishu") ? feishuBot : "",
597
649
  target: dedicated ? { kind: "dedicated" } : { kind: "conv", key: target.value },
598
650
  freshContext: fresh,
599
651
  ...(dedicated ? { expert: expert.value, cwd: findExpert(expert.value)?.access === "web" ? "" : cwd, permission: level, model: models.model.value, effort: models.effort.value } : {}),