任务执行完成后,将结果交付到消息渠道或 Webhook。

交付模式

mode说明触发条件
none不交付显式配置或默认
announce通过消息渠道发送结果配置 channel + to
webhookHTTP POST 到指定 URL配置 to 为 URL

交付计划解析(delivery-plan.ts)

显式交付

直接使用 CronDelivery 配置:

delivery:
  mode: announce
  channel: slack
  to: "#reports"
  threadId: "thread-123"

隐式交付推断

隔离 Agent 任务(sessionTarget = "isolated")自动推断 announce 交付:

  • 从 Agent 的默认渠道推断
  • 从最后一个活跃渠道推断(last)
  • 处理渠道前缀(如 feishu:xxx、slack:xxx)

渠道前缀处理

"feishu:channel-id"  → channel: "feishu", to: "channel-id"
"slack:#reports"     → channel: "slack",  to: "#reports"
"last"               → 使用最后一个活跃渠道

交付分发(isolated-agent/delivery-dispatch.ts)

执行流程

deliverCronResult(params)
  1. 解析交付计划(delivery-plan.ts)
  2. 格式化输出内容
  3. 选择交付目标(delivery-target.ts)
  4. 发送消息或 HTTP 请求
  5. 记录交付状态(delivered/not-delivered/unknown)

交付目标解析(delivery-target.ts)

将渠道标识符解析为具体的消息发送目标:

  • 渠道 ID → 渠道实例
  • 用户 ID → 私信目标
  • 群组 ID → 群组目标

失败通知

配置

type CronFailureAlert = {
  after?: number           // 连续失败次数阈值(默认 2)
  cooldownMs?: number      // 冷却时间(默认 1h)
  includeSkipped?: boolean // 是否计入跳过的运行
  destination?: CronFailureDestination
}

触发逻辑

consecutiveErrors >= failureAlert.after
&& now - lastFailureAlertAtMs > cooldownMs
→ 发送失败告警
→ 更新 lastFailureAlertAtMs

失败目标(CronFailureDestination)

独立于正常交付目标,可配置不同的渠道/接收人:

failureAlert:
  after: 3
  destination:
    channel: slack
    to: "#alerts"

Best-Effort 模式

delivery: {
  mode: "announce",
  bestEffort: true  // 交付失败不影响任务状态
}
  • bestEffort: true:交付失败记录为 not-delivered,不增加 consecutiveErrors
  • bestEffort: false(默认):交付失败视为任务失败

交付状态追踪

lastDeliveryStatus: "delivered" | "not-delivered" | "unknown" | "not-requested"
lastDelivered: boolean

存储在 jobs-state.json 中,可通过 CLI 查询。

交付预览(delivery-preview.ts)

在实际执行前预览交付计划,用于:

  • CLI 的 --dry-run 模式
  • 配置验证
  • 调试

Webhook 交付

delivery: {
  mode: "webhook",
  to: "https://example.com/webhook"
}

POST 请求体格式:

{
  "jobId": "job-123",
  "jobName": "Daily Report",
  "runId": "run-uuid",
  "status": "ok",
  "output": "Agent 输出内容",
  "completedAtMs": 1234567890000
}

Webhook URL 验证由 webhook-url.ts 处理,拒绝内网地址(SSRF 防护)。

相关页面