@oyasmi/pipiclaw 0.9.5 → 0.9.6-beta.2
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.en.md +300 -142
- package/README.md +295 -140
- package/dist/agent/builtin-commands.d.ts +1 -1
- package/dist/agent/builtin-commands.js +1 -1
- package/dist/agent/channel-runner.d.ts +4 -3
- package/dist/agent/channel-runner.js +17 -28
- package/dist/agent/maintenance-context.js +2 -2
- package/dist/agent/prompt/builder.d.ts +1 -1
- package/dist/agent/prompt/builder.js +1 -1
- package/dist/agent/prompt/extension.d.ts +1 -1
- package/dist/agent/prompt/extension.js +1 -1
- package/dist/agent/prompt/manifest.d.ts +6 -1
- package/dist/agent/prompt/manifest.js +12 -5
- package/dist/agent/prompt/resources.d.ts +0 -3
- package/dist/agent/prompt/resources.js +0 -6
- package/dist/agent/prompt/sections.d.ts +2 -2
- package/dist/agent/prompt/sections.js +36 -26
- package/dist/agent/prompt/types.d.ts +3 -2
- package/dist/agent/runner-factory.js +1 -1
- package/dist/agent/session/command-extension.js +3 -1
- package/dist/agent/session/compaction-summary.js +3 -6
- package/dist/agent/session/compaction.d.ts +2 -0
- package/dist/agent/session/compaction.js +22 -14
- package/dist/agent/session/event-guards.d.ts +2 -1
- package/dist/agent/session/event-guards.js +6 -0
- package/dist/agent/session/model-selection.d.ts +2 -1
- package/dist/agent/session/model-selection.js +5 -5
- package/dist/agent/session/session-events.js +31 -4
- package/dist/agent/session/session-host.d.ts +5 -3
- package/dist/agent/session/session-host.js +20 -16
- package/dist/agent/status-render.js +3 -0
- package/dist/agent/stop-watchdog.js +5 -1
- package/dist/agent/turn/task-digest.d.ts +2 -5
- package/dist/agent/turn/task-digest.js +25 -45
- package/dist/agent/turn/turn-context.js +4 -6
- package/dist/agent/turn/turn-error.d.ts +1 -1
- package/dist/agent/turn/turn-error.js +9 -0
- package/dist/agent/turn/turn-pipeline.d.ts +10 -5
- package/dist/agent/turn/turn-pipeline.js +36 -7
- package/dist/agent/turn/turn-prompt.d.ts +2 -0
- package/dist/agent/turn/turn-prompt.js +2 -1
- package/dist/agent/turn/turn-recovery.js +4 -1
- package/dist/agent/turn/turn-state.d.ts +2 -0
- package/dist/agent/turn/turn-state.js +2 -1
- package/dist/agent/types.d.ts +23 -3
- package/dist/agent/types.js +2 -0
- package/dist/app/auth-command.d.ts +25 -0
- package/dist/app/auth-command.js +200 -67
- package/dist/app/home.d.ts +7 -8
- package/dist/app/home.js +143 -56
- package/dist/channel/attachments.d.ts +4 -0
- package/dist/channel/attachments.js +4 -0
- package/dist/channel/channel-context.d.ts +6 -0
- package/dist/channel/config.d.ts +3 -0
- package/dist/channel/config.js +11 -5
- package/dist/channel/store.d.ts +1 -1
- package/dist/commands/catalog.js +42 -10
- package/dist/commands/router.js +5 -1
- package/dist/desk/commands.d.ts +44 -5
- package/dist/desk/commands.js +162 -28
- package/dist/desk/paths.d.ts +6 -0
- package/dist/desk/paths.js +21 -1
- package/dist/desk/registry.d.ts +17 -2
- package/dist/desk/registry.js +122 -12
- package/dist/desk/types.d.ts +83 -1
- package/dist/dingtalk/bot.d.ts +1 -1
- package/dist/dingtalk/bot.js +4 -3
- package/dist/dingtalk/config.js +10 -10
- package/dist/dingtalk/delivery.js +15 -8
- package/dist/dingtalk/inbound-media.d.ts +36 -14
- package/dist/dingtalk/inbound-media.js +71 -12
- package/dist/dingtalk/inbound.d.ts +9 -2
- package/dist/dingtalk/inbound.js +17 -2
- package/dist/dingtalk/media.d.ts +4 -10
- package/dist/dingtalk/media.js +58 -32
- package/dist/events/commands.d.ts +2 -0
- package/dist/events/commands.js +13 -8
- package/dist/events/history.d.ts +9 -0
- package/dist/events/history.js +66 -0
- package/dist/events/parse.js +7 -3
- package/dist/events/types.d.ts +3 -0
- package/dist/events/watcher.d.ts +4 -8
- package/dist/events/watcher.js +53 -58
- package/dist/jobs/kill.d.ts +23 -0
- package/dist/jobs/kill.js +65 -0
- package/dist/jobs/manager.d.ts +19 -18
- package/dist/jobs/manager.js +36 -103
- package/dist/main.js +15 -3
- package/dist/memory/boundary-work.d.ts +2 -1
- package/dist/memory/boundary-work.js +1 -1
- package/dist/memory/lifecycle.d.ts +2 -1
- package/dist/memory/lifecycle.js +2 -2
- package/dist/memory/reflect-job.d.ts +2 -1
- package/dist/memory/reflect-job.js +1 -1
- package/dist/memory/reflect.d.ts +2 -1
- package/dist/memory/reflect.js +25 -4
- package/dist/memory/scheduler.d.ts +2 -1
- package/dist/memory/scheduler.js +1 -1
- package/dist/memory/session-corpus.d.ts +1 -1
- package/dist/memory/session-corpus.js +76 -1
- package/dist/memory/session-search.d.ts +2 -1
- package/dist/memory/session-search.js +14 -12
- package/dist/memory/sidecar-worker.d.ts +2 -1
- package/dist/memory/sidecar-worker.js +2 -4
- package/dist/memory/store.d.ts +2 -0
- package/dist/memory/store.js +19 -9
- package/dist/models/credential-work.d.ts +7 -0
- package/dist/models/credential-work.js +36 -0
- package/dist/models/login-ui.js +4 -4
- package/dist/models/provider-login.js +7 -6
- package/dist/models/requests.d.ts +8 -0
- package/dist/models/requests.js +69 -0
- package/dist/models/runtime.d.ts +3 -1
- package/dist/models/runtime.js +9 -2
- package/dist/playbooks/agent-delegation.md +20 -45
- package/dist/playbooks/background-jobs.md +1 -1
- package/dist/playbooks/catalog.js +1 -1
- package/dist/playbooks/delegation-inline.md +25 -0
- package/dist/playbooks/delegation-recovery.md +28 -0
- package/dist/playbooks/event-scheduling.md +18 -37
- package/dist/playbooks/event-sensors.md +26 -0
- package/dist/playbooks/event-task-template.md +22 -0
- package/dist/playbooks/learning-and-skills.md +26 -0
- package/dist/playbooks/memory-operations.md +36 -0
- package/dist/playbooks/outbound-media.md +2 -2
- package/dist/playbooks/runtime-files.md +29 -0
- package/dist/playbooks/runtime-operations.md +25 -0
- package/dist/playbooks/runtime-orientation.md +18 -53
- package/dist/playbooks/task-lead.md +22 -68
- package/dist/playbooks/task-manage.md +38 -0
- package/dist/playbooks/task-recovery.md +24 -0
- package/dist/playbooks/task-verify.md +22 -0
- package/dist/runtime/bootstrap.d.ts +10 -0
- package/dist/runtime/bootstrap.js +93 -29
- package/dist/runtime/daemon-lock.js +3 -3
- package/dist/runtime/desk-runtime.d.ts +40 -7
- package/dist/runtime/desk-runtime.js +330 -44
- package/dist/runtime/durable-dispatch.d.ts +14 -2
- package/dist/runtime/durable-dispatch.js +207 -65
- package/dist/runtime/ingress-busy.js +17 -8
- package/dist/runtime/ingress-commands.js +24 -4
- package/dist/runtime/ingress-deps.d.ts +4 -1
- package/dist/runtime/ingress.js +6 -1
- package/dist/runtime/request-execution.js +7 -6
- package/dist/runtime/shutdown.d.ts +4 -1
- package/dist/runtime/shutdown.js +88 -35
- package/dist/runtime/task-close.d.ts +1 -1
- package/dist/runtime/task-close.js +6 -3
- package/dist/runtime/task-control.d.ts +2 -3
- package/dist/runtime/task-control.js +38 -11
- package/dist/runtime/task-input.js +1 -1
- package/dist/runtime/task-lane-types.d.ts +12 -2
- package/dist/runtime/task-lane-types.js +9 -0
- package/dist/runtime/task-lane.d.ts +2 -0
- package/dist/runtime/task-lane.js +38 -20
- package/dist/runtime/task-step.d.ts +3 -3
- package/dist/runtime/task-step.js +34 -16
- package/dist/runtime/transports.js +6 -5
- package/dist/runtime/turn-run.js +103 -66
- package/dist/security/command-guard.d.ts +1 -1
- package/dist/security/command-guard.js +259 -314
- package/dist/security/path-guard.js +48 -7
- package/dist/security/shell-parse.d.ts +10 -0
- package/dist/security/shell-parse.js +224 -0
- package/dist/security/types.d.ts +2 -0
- package/dist/subagents/commands.d.ts +1 -1
- package/dist/subagents/commands.js +14 -5
- package/dist/subagents/completion-wake.js +6 -0
- package/dist/subagents/detached-discovery.d.ts +1 -1
- package/dist/subagents/discovery.d.ts +18 -199
- package/dist/subagents/discovery.js +35 -289
- package/dist/subagents/dispatch.d.ts +1 -2
- package/dist/subagents/dispatch.js +50 -29
- package/dist/subagents/external/antigravity-cli.d.ts +2 -0
- package/dist/subagents/external/antigravity-cli.js +517 -0
- package/dist/subagents/external/claude-code.js +8 -17
- package/dist/subagents/external/codex-cli.js +8 -18
- package/dist/subagents/external/cursor-cli.js +34 -31
- package/dist/subagents/external/dispatch.d.ts +21 -7
- package/dist/subagents/external/dispatch.js +146 -12
- package/dist/subagents/external/exec.js +3 -0
- package/dist/subagents/external/harness.d.ts +57 -33
- package/dist/subagents/external/harness.js +69 -40
- package/dist/subagents/external/reconciliation.js +1 -0
- package/dist/subagents/external/registry.js +4 -1
- package/dist/subagents/external/role-warnings.d.ts +4 -13
- package/dist/subagents/external/role-warnings.js +4 -28
- package/dist/subagents/external/run.d.ts +1 -2
- package/dist/subagents/external/run.js +16 -26
- package/dist/subagents/external/settlement.d.ts +2 -0
- package/dist/subagents/external/settlement.js +13 -3
- package/dist/subagents/format.d.ts +1 -1
- package/dist/subagents/format.js +1 -1
- package/dist/subagents/internal/outcome.d.ts +1 -2
- package/dist/subagents/internal/outcome.js +19 -12
- package/dist/subagents/internal/provider-retry.d.ts +1 -2
- package/dist/subagents/internal/provider-retry.js +2 -4
- package/dist/subagents/internal/run.d.ts +2 -3
- package/dist/subagents/internal/run.js +27 -4
- package/dist/subagents/internal/state.d.ts +2 -5
- package/dist/subagents/internal/state.js +1 -2
- package/dist/subagents/internal/worker.d.ts +1 -2
- package/dist/subagents/internal/worker.js +20 -10
- package/dist/subagents/resolve.d.ts +56 -0
- package/dist/subagents/resolve.js +202 -0
- package/dist/subagents/result.d.ts +6 -4
- package/dist/subagents/result.js +39 -6
- package/dist/subagents/run-record.d.ts +54 -2
- package/dist/subagents/run-record.js +7 -0
- package/dist/subagents/runs.d.ts +6 -31
- package/dist/subagents/runs.js +26 -31
- package/dist/subagents/task-envelope.d.ts +1 -2
- package/dist/subagents/task-envelope.js +13 -4
- package/dist/subagents/task-settlement.js +1 -0
- package/dist/subagents/types.d.ts +105 -6
- package/dist/subagents/types.js +16 -1
- package/dist/subagents/workspace-lease.d.ts +41 -24
- package/dist/subagents/workspace-lease.js +159 -24
- package/dist/subagents/worktree.d.ts +52 -0
- package/dist/subagents/worktree.js +363 -0
- package/dist/tasks/archive.js +4 -0
- package/dist/tasks/brief.d.ts +5 -1
- package/dist/tasks/brief.js +19 -5
- package/dist/tasks/commands.d.ts +6 -1
- package/dist/tasks/commands.js +32 -7
- package/dist/tasks/control.d.ts +11 -0
- package/dist/tasks/delivery.d.ts +2 -0
- package/dist/tasks/delivery.js +141 -21
- package/dist/tasks/loop-log.d.ts +12 -0
- package/dist/tasks/loop-log.js +10 -1
- package/dist/tasks/receipts.d.ts +7 -3
- package/dist/tasks/receipts.js +34 -5
- package/dist/tools/bash.d.ts +3 -0
- package/dist/tools/bash.js +29 -15
- package/dist/tools/contract/presentation.js +7 -5
- package/dist/tools/edit-diff.d.ts +11 -0
- package/dist/tools/edit-diff.js +148 -0
- package/dist/tools/edit-match.d.ts +18 -0
- package/dist/tools/edit-match.js +242 -0
- package/dist/tools/edit.d.ts +10 -2
- package/dist/tools/edit.js +91 -361
- package/dist/tools/event-manage.d.ts +2 -1
- package/dist/tools/event-manage.js +46 -39
- package/dist/tools/file-observations.d.ts +9 -0
- package/dist/tools/file-observations.js +50 -0
- package/dist/tools/glob-match.d.ts +3 -1
- package/dist/tools/glob-match.js +40 -17
- package/dist/tools/glob.d.ts +1 -0
- package/dist/tools/glob.js +39 -19
- package/dist/tools/grep-command.d.ts +13 -0
- package/dist/tools/grep-command.js +77 -0
- package/dist/tools/grep.js +96 -201
- package/dist/tools/index.d.ts +6 -2
- package/dist/tools/index.js +9 -4
- package/dist/tools/job.js +12 -11
- package/dist/tools/read.d.ts +2 -0
- package/dist/tools/read.js +10 -2
- package/dist/tools/registry.d.ts +16 -11
- package/dist/tools/registry.js +32 -12
- package/dist/tools/send-media.js +9 -5
- package/dist/tools/session-search.d.ts +2 -1
- package/dist/tools/session-search.js +15 -5
- package/dist/tools/skill.js +13 -12
- package/dist/tools/subagent-manage.d.ts +1 -1
- package/dist/tools/subagent-manage.js +25 -152
- package/dist/tools/subagent.d.ts +24 -2
- package/dist/tools/subagent.js +24 -18
- package/dist/tools/task-manage/control-tools.js +1 -1
- package/dist/tools/task-manage/factory.d.ts +2 -2
- package/dist/tools/task-manage/factory.js +40 -4
- package/dist/tools/task-manage/lifecycle.d.ts +3 -3
- package/dist/tools/task-manage/lifecycle.js +56 -13
- package/dist/tools/task-manage/schema.d.ts +4 -1
- package/dist/tools/task-manage/schema.js +4 -1
- package/dist/tools/task-manage/shared.d.ts +1 -1
- package/dist/tools/task-manage/types.d.ts +5 -1
- package/dist/tools/write-content.d.ts +7 -1
- package/dist/tools/write-content.js +18 -6
- package/dist/tools/write.d.ts +3 -0
- package/dist/tools/write.js +6 -2
- package/dist/tui/cli.d.ts +6 -6
- package/dist/tui/cli.js +120 -28
- package/dist/tui/client.d.ts +7 -0
- package/dist/tui/client.js +67 -16
- package/dist/tui/frontend.d.ts +2 -0
- package/dist/tui/pitui-frontend.d.ts +4 -0
- package/dist/tui/pitui-frontend.js +27 -0
- package/dist/tui/render.d.ts +1 -0
- package/dist/tui/render.js +5 -0
- package/dist/tui/session.js +6 -0
- package/dist/usage/ledger.d.ts +1 -1
- package/dist/usage/render.js +1 -1
- package/dist/web/client.d.ts +1 -0
- package/dist/web/client.js +11 -0
- package/dist/web/fetch.js +6 -3
- package/dist/webapi/auth.d.ts +0 -3
- package/dist/webapi/auth.js +3 -7
- package/dist/webapi/config.js +17 -14
- package/dist/webapi/key-command.js +41 -41
- package/dist/webapi/response-state.d.ts +7 -1
- package/dist/webapi/response-state.js +166 -3
- package/dist/webapi/routes/websocket.js +24 -1
- package/dist/webapi/server.d.ts +3 -1
- package/dist/webapi/server.js +32 -1
- package/dist/webapi/service.js +8 -0
- package/dist/webapi/transport.d.ts +2 -0
- package/dist/webapi/transport.js +11 -1
- package/examples/sub-agents/README.md +43 -75
- package/examples/sub-agents/agy-main.md +21 -0
- package/examples/sub-agents/claude-high.md +21 -0
- package/examples/sub-agents/claude-main.md +21 -0
- package/examples/sub-agents/codex-flash.md +21 -0
- package/examples/sub-agents/codex-high.md +21 -0
- package/examples/sub-agents/codex-main.md +21 -0
- package/examples/sub-agents/codex-review.md +20 -0
- package/examples/sub-agents/cursor-high.md +20 -0
- package/examples/sub-agents/cursor-main.md +20 -0
- package/examples/sub-agents/glm-flash.md +21 -0
- package/examples/sub-agents/glm-high.md +21 -0
- package/examples/sub-agents/pi-scout.md +20 -0
- package/package.json +11 -12
- package/dist/agent/session/request-tools.d.ts +0 -3
- package/dist/agent/session/request-tools.js +0 -20
- package/dist/models/api-keys.d.ts +0 -11
- package/dist/models/api-keys.js +0 -22
- package/dist/playbooks/memory-and-learning.md +0 -55
- package/examples/sub-agents/agents/claude-high.md +0 -23
- package/examples/sub-agents/agents/claude-main.md +0 -23
- package/examples/sub-agents/agents/codex-flash.md +0 -23
- package/examples/sub-agents/agents/codex-high.md +0 -23
- package/examples/sub-agents/agents/codex-main.md +0 -23
- package/examples/sub-agents/agents/codex-review.md +0 -23
- package/examples/sub-agents/agents/cursor-high.md +0 -22
- package/examples/sub-agents/agents/cursor-main.md +0 -22
- package/examples/sub-agents/agents/glm-flash.md +0 -23
- package/examples/sub-agents/agents/glm-high.md +0 -23
- package/examples/sub-agents/agents/scout.md +0 -30
- package/examples/sub-agents/roles/builder-hard.md +0 -34
- package/examples/sub-agents/roles/builder.md +0 -34
- package/examples/sub-agents/roles/explorer.md +0 -39
- package/examples/sub-agents/roles/git-committer.md +0 -43
- package/examples/sub-agents/roles/planner.md +0 -33
- package/examples/sub-agents/roles/reviewer.md +0 -33
- package/examples/sub-agents/roles/verifier.md +0 -35
- package/examples/sub-agents/roles/worker.md +0 -34
package/dist/dingtalk/config.js
CHANGED
|
@@ -26,37 +26,37 @@ function isPlaceholderString(value) {
|
|
|
26
26
|
function listChannelConfigIssues(config) {
|
|
27
27
|
const issues = [];
|
|
28
28
|
if (!config.clientId) {
|
|
29
|
-
issues.push("
|
|
29
|
+
issues.push("缺少必填项 `clientId`(如暂不接入钉钉,可将 `dingtalk.enabled` 设为 false)。");
|
|
30
30
|
}
|
|
31
31
|
else if (isPlaceholderString(config.clientId)) {
|
|
32
|
-
issues.push("
|
|
32
|
+
issues.push("请将 `clientId` 的占位值(your-*)替换为真实的钉钉应用 Client ID(如暂不接入钉钉,可将 `dingtalk.enabled` 设为 false)。");
|
|
33
33
|
}
|
|
34
34
|
if (!config.clientSecret) {
|
|
35
|
-
issues.push("
|
|
35
|
+
issues.push("缺少必填项 `clientSecret`。");
|
|
36
36
|
}
|
|
37
37
|
else if (isPlaceholderString(config.clientSecret)) {
|
|
38
|
-
issues.push("
|
|
38
|
+
issues.push("请将 `clientSecret` 的占位值(your-*)替换为真实的钉钉应用 Client Secret。");
|
|
39
39
|
}
|
|
40
40
|
if (config.robotCode && isPlaceholderString(config.robotCode)) {
|
|
41
|
-
issues.push(
|
|
41
|
+
issues.push('请替换 `robotCode` 的占位值,或将其设为空字符串 `""` 以自动复用 `clientId`。');
|
|
42
42
|
}
|
|
43
43
|
if (config.cardTemplateId && isPlaceholderString(config.cardTemplateId)) {
|
|
44
|
-
issues.push(
|
|
44
|
+
issues.push('请替换 `cardTemplateId` 的占位值,或将其设为空字符串 `""` 以暂不启用 AI Card 流式卡片。');
|
|
45
45
|
}
|
|
46
46
|
if (Array.isArray(config.allowFrom) && config.allowFrom.some((value) => isPlaceholderString(value))) {
|
|
47
|
-
issues.push("
|
|
47
|
+
issues.push("请替换 `allowFrom` 中的占位值,或设为空数组 `[]` 以允许应用可见范围内的成员使用。");
|
|
48
48
|
}
|
|
49
49
|
const busyMessageDefault = config.busyMessageDefault;
|
|
50
50
|
if (busyMessageDefault !== undefined && !isBusyMessageDefaultConfig(busyMessageDefault)) {
|
|
51
|
-
issues.push('
|
|
51
|
+
issues.push('`busyMessageDefault` 无效:仅支持 "steer"、"followUp" 或 "followup"。');
|
|
52
52
|
}
|
|
53
53
|
const responseMode = config.responseMode;
|
|
54
54
|
if (responseMode !== undefined && !isResponseModeConfig(responseMode)) {
|
|
55
|
-
issues.push('
|
|
55
|
+
issues.push('`responseMode` 无效:仅支持 "full_progress_then_plain_final"、"rolling_progress_then_plain_final" 或 "final_card_only"。');
|
|
56
56
|
}
|
|
57
57
|
const cardAutoLayout = config.cardAutoLayout;
|
|
58
58
|
if (cardAutoLayout !== undefined && typeof cardAutoLayout !== "boolean") {
|
|
59
|
-
issues.push("
|
|
59
|
+
issues.push("`cardAutoLayout` 无效:必须是布尔值(true 或 false)。");
|
|
60
60
|
}
|
|
61
61
|
return issues;
|
|
62
62
|
}
|
|
@@ -107,12 +107,14 @@ class ChannelDeliveryController {
|
|
|
107
107
|
await this.deliverCommentary(event.text, event.level);
|
|
108
108
|
return;
|
|
109
109
|
case "answer":
|
|
110
|
-
await this.deliverAnswer(event.text);
|
|
110
|
+
await this.deliverAnswer(event.text, event.title);
|
|
111
111
|
return;
|
|
112
112
|
case "compaction":
|
|
113
113
|
if (event.phase === "start")
|
|
114
114
|
await this.remember("正在压缩上下文…", "");
|
|
115
115
|
return;
|
|
116
|
+
case "reasoning.delta":
|
|
117
|
+
case "text.delta":
|
|
116
118
|
case "steer.applied":
|
|
117
119
|
return;
|
|
118
120
|
}
|
|
@@ -138,13 +140,13 @@ class ChannelDeliveryController {
|
|
|
138
140
|
return;
|
|
139
141
|
}
|
|
140
142
|
}
|
|
141
|
-
async deliverAnswer(text) {
|
|
143
|
+
async deliverAnswer(text, title) {
|
|
142
144
|
this.lastAnswer = text;
|
|
143
145
|
if (this.bot.finalDelivery === "card") {
|
|
144
|
-
await this.replaceWithFinal(text);
|
|
146
|
+
await this.replaceWithFinal(text, true);
|
|
145
147
|
}
|
|
146
148
|
else {
|
|
147
|
-
await this.sendFinal(text, true);
|
|
149
|
+
await this.sendFinal(text, true, title);
|
|
148
150
|
}
|
|
149
151
|
}
|
|
150
152
|
/** A standalone side message: not part of the progress, sent even when progress is off. */
|
|
@@ -187,7 +189,7 @@ class ChannelDeliveryController {
|
|
|
187
189
|
case "completed":
|
|
188
190
|
if (this.lastAnswer && !this.finalResponseDelivered) {
|
|
189
191
|
try {
|
|
190
|
-
await this.replaceWithFinal(this.lastAnswer);
|
|
192
|
+
await this.replaceWithFinal(this.lastAnswer, true);
|
|
191
193
|
}
|
|
192
194
|
catch (err) {
|
|
193
195
|
log.logWarn("delivery.final_reply.failed", "Final reply replacement failed", {
|
|
@@ -262,7 +264,7 @@ class ChannelDeliveryController {
|
|
|
262
264
|
}
|
|
263
265
|
return true;
|
|
264
266
|
}
|
|
265
|
-
async replaceWithFinal(text) {
|
|
267
|
+
async replaceWithFinal(text, shouldLog = false) {
|
|
266
268
|
if (this.closed || this.finalResponseDelivered || !this.isCurrent || !text.trim())
|
|
267
269
|
return;
|
|
268
270
|
this.ending = true;
|
|
@@ -270,8 +272,13 @@ class ChannelDeliveryController {
|
|
|
270
272
|
this.mode = "finalize-with-fallback";
|
|
271
273
|
this.bumpRevision(true);
|
|
272
274
|
await this.flush();
|
|
273
|
-
if (!this.finalResponseDelivered
|
|
274
|
-
|
|
275
|
+
if (!this.finalResponseDelivered) {
|
|
276
|
+
if (this.isCurrent)
|
|
277
|
+
throw new Error("最终答复发送失败,请稍后重试。");
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if (shouldLog) {
|
|
281
|
+
this.archiveBotResponse(text);
|
|
275
282
|
}
|
|
276
283
|
}
|
|
277
284
|
async silence() {
|
|
@@ -1,44 +1,66 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Pure parsing of DingTalk inbound
|
|
2
|
+
* Pure parsing of DingTalk inbound messages and attachments (spec 049 + audio/file/reply).
|
|
3
3
|
*
|
|
4
4
|
* Kept separate from `dingtalk.ts` — which owns the network calls (`downloadMessageFile`) and
|
|
5
5
|
* the per-channel serialization of the download — so the message-shape parsing rules can be unit tested without a `DingTalkBot` instance or any I/O.
|
|
6
6
|
*/
|
|
7
|
+
export interface InboundQuotedMessage {
|
|
8
|
+
msgType?: string;
|
|
9
|
+
content?: {
|
|
10
|
+
text?: string;
|
|
11
|
+
title?: string;
|
|
12
|
+
recognition?: string;
|
|
13
|
+
fileName?: string;
|
|
14
|
+
richText?: Array<Record<string, string>>;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
7
17
|
/** Structural subset of the raw DingTalk callback payload this module reads. */
|
|
8
18
|
export interface InboundMessagePayload {
|
|
9
19
|
msgtype?: string;
|
|
10
20
|
text?: {
|
|
11
21
|
content?: string;
|
|
22
|
+
isReplyMsg?: boolean;
|
|
23
|
+
repliedMsg?: InboundQuotedMessage;
|
|
12
24
|
};
|
|
25
|
+
repliedMsg?: InboundQuotedMessage;
|
|
13
26
|
content?: {
|
|
14
27
|
richText?: Array<Record<string, string>>;
|
|
15
|
-
/** Present on
|
|
28
|
+
/** Present on `picture`, `file` and `audio` messages; the credential `robot/messageFiles/download` needs. */
|
|
16
29
|
downloadCode?: string;
|
|
30
|
+
/** Present on `audio` messages when DingTalk Stream ASR transcribed the voice clip. */
|
|
31
|
+
recognition?: string;
|
|
32
|
+
audioType?: string;
|
|
33
|
+
/** Present on `file` messages. */
|
|
34
|
+
fileName?: string;
|
|
17
35
|
};
|
|
18
36
|
}
|
|
37
|
+
export interface InboundFileDescriptor {
|
|
38
|
+
downloadCode: string;
|
|
39
|
+
fileName: string;
|
|
40
|
+
}
|
|
19
41
|
export interface ParsedInboundMessage {
|
|
20
42
|
/**
|
|
21
|
-
* User text with `[图片N]` markers inserted
|
|
22
|
-
*
|
|
23
|
-
* neither text nor an
|
|
43
|
+
* User text with `[图片N]` / `[文件N]` markers inserted, `[语音转写]` for ASR audio, and optional
|
|
44
|
+
* `[引用消息:...]` prefix when replying to an earlier message. Empty when the message carries
|
|
45
|
+
* neither text nor an attachment — the caller drops or hints on that case.
|
|
24
46
|
*/
|
|
25
47
|
text: string;
|
|
26
48
|
/** In the same order as the `[图片N]` markers in `text`, one entry per image. */
|
|
27
49
|
downloadCodes: string[];
|
|
50
|
+
/** In the same order as the `[文件N]` markers in `text`; omitted when empty. */
|
|
51
|
+
files?: InboundFileDescriptor[];
|
|
28
52
|
}
|
|
29
53
|
/** Mirrors `MEDIA_UPLOAD_TIMEOUT_MS`: a multi-MB download over a slow link needs more than the
|
|
30
54
|
* 15s default HTTP timeout. */
|
|
31
55
|
export declare const MEDIA_DOWNLOAD_TIMEOUT_MS = 60000;
|
|
32
56
|
/**
|
|
33
|
-
* Parse one raw DingTalk callback payload into text + ordered
|
|
57
|
+
* Parse one raw DingTalk callback payload into text + ordered attachment credentials.
|
|
34
58
|
*
|
|
35
|
-
* - `text` messages:
|
|
36
|
-
* - `
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* - `
|
|
40
|
-
*
|
|
41
|
-
* a follow-up still resolves to the right attachment (D5), even though the SDK's `prompt()`
|
|
42
|
-
* itself appends every image after all text once the turn is actually sent.
|
|
59
|
+
* - `text` messages: text content (with `[引用消息:...]` when replying to a prior message).
|
|
60
|
+
* - `audio` messages: uses DingTalk's built-in `content.recognition` ASR transcript when present;
|
|
61
|
+
* falls back to downloading the voice file via `downloadCode` when ASR is empty.
|
|
62
|
+
* - `file` messages: synthetic `[文件1]` marker + `{ downloadCode, fileName }` descriptor.
|
|
63
|
+
* - `picture` messages: synthetic `[图片1]` marker + `downloadCode`.
|
|
64
|
+
* - `richText` messages: text and image credentials interleave in payload order.
|
|
43
65
|
*/
|
|
44
66
|
export declare function parseInboundMessage(data: InboundMessagePayload): ParsedInboundMessage;
|
|
@@ -1,25 +1,84 @@
|
|
|
1
1
|
/** Mirrors `MEDIA_UPLOAD_TIMEOUT_MS`: a multi-MB download over a slow link needs more than the
|
|
2
2
|
* 15s default HTTP timeout. */
|
|
3
3
|
export const MEDIA_DOWNLOAD_TIMEOUT_MS = 60_000;
|
|
4
|
+
const MAX_QUOTED_CHARS = 300;
|
|
5
|
+
function extractQuotedSummary(replied) {
|
|
6
|
+
if (!replied?.content)
|
|
7
|
+
return "";
|
|
8
|
+
const { content, msgType } = replied;
|
|
9
|
+
if (typeof content.text === "string" && content.text.trim()) {
|
|
10
|
+
return content.text.trim();
|
|
11
|
+
}
|
|
12
|
+
if (Array.isArray(content.richText)) {
|
|
13
|
+
const rich = content.richText
|
|
14
|
+
.map((item) => item.text || (item.downloadCode ? "[图片]" : ""))
|
|
15
|
+
.join("")
|
|
16
|
+
.trim();
|
|
17
|
+
if (rich)
|
|
18
|
+
return rich;
|
|
19
|
+
}
|
|
20
|
+
if (typeof content.recognition === "string" && content.recognition.trim()) {
|
|
21
|
+
return `[语音转写] ${content.recognition.trim()}`;
|
|
22
|
+
}
|
|
23
|
+
if (typeof content.title === "string" && content.title.trim()) {
|
|
24
|
+
return content.title.trim();
|
|
25
|
+
}
|
|
26
|
+
if (typeof content.fileName === "string" && content.fileName.trim()) {
|
|
27
|
+
return `[文件: ${content.fileName.trim()}]`;
|
|
28
|
+
}
|
|
29
|
+
if (msgType === "picture")
|
|
30
|
+
return "[图片]";
|
|
31
|
+
return "";
|
|
32
|
+
}
|
|
33
|
+
function withReplyContext(body, data) {
|
|
34
|
+
if (!body)
|
|
35
|
+
return "";
|
|
36
|
+
const rawQuote = extractQuotedSummary(data.text?.repliedMsg ?? data.repliedMsg);
|
|
37
|
+
if (!rawQuote)
|
|
38
|
+
return body;
|
|
39
|
+
const normalized = rawQuote.replace(/\s+/g, " ").trim();
|
|
40
|
+
const clipped = normalized.length > MAX_QUOTED_CHARS ? `${normalized.slice(0, MAX_QUOTED_CHARS)}…` : normalized;
|
|
41
|
+
return `[引用消息:${clipped}]\n${body}`;
|
|
42
|
+
}
|
|
4
43
|
/**
|
|
5
|
-
* Parse one raw DingTalk callback payload into text + ordered
|
|
44
|
+
* Parse one raw DingTalk callback payload into text + ordered attachment credentials.
|
|
6
45
|
*
|
|
7
|
-
* - `text` messages:
|
|
8
|
-
* - `
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* - `
|
|
12
|
-
*
|
|
13
|
-
* a follow-up still resolves to the right attachment (D5), even though the SDK's `prompt()`
|
|
14
|
-
* itself appends every image after all text once the turn is actually sent.
|
|
46
|
+
* - `text` messages: text content (with `[引用消息:...]` when replying to a prior message).
|
|
47
|
+
* - `audio` messages: uses DingTalk's built-in `content.recognition` ASR transcript when present;
|
|
48
|
+
* falls back to downloading the voice file via `downloadCode` when ASR is empty.
|
|
49
|
+
* - `file` messages: synthetic `[文件1]` marker + `{ downloadCode, fileName }` descriptor.
|
|
50
|
+
* - `picture` messages: synthetic `[图片1]` marker + `downloadCode`.
|
|
51
|
+
* - `richText` messages: text and image credentials interleave in payload order.
|
|
15
52
|
*/
|
|
16
53
|
export function parseInboundMessage(data) {
|
|
17
54
|
const textContent = (data.text?.content || "").trim();
|
|
18
55
|
if (textContent) {
|
|
19
|
-
return { text: textContent, downloadCodes: [] };
|
|
56
|
+
return { text: withReplyContext(textContent, data), downloadCodes: [] };
|
|
57
|
+
}
|
|
58
|
+
if (data.msgtype === "audio") {
|
|
59
|
+
const recognition = data.content?.recognition?.trim();
|
|
60
|
+
if (recognition) {
|
|
61
|
+
return { text: withReplyContext(`[语音转写] ${recognition}`, data), downloadCodes: [] };
|
|
62
|
+
}
|
|
63
|
+
if (data.content?.downloadCode) {
|
|
64
|
+
const ext = (data.content.audioType || "amr").replace(/[^a-z0-9]/gi, "").toLowerCase() || "amr";
|
|
65
|
+
return {
|
|
66
|
+
text: withReplyContext("[文件1]", data),
|
|
67
|
+
downloadCodes: [],
|
|
68
|
+
files: [{ downloadCode: data.content.downloadCode, fileName: `voice.${ext}` }],
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (data.msgtype === "file" && data.content?.downloadCode) {
|
|
73
|
+
const fileName = data.content.fileName?.trim() || "attachment.bin";
|
|
74
|
+
return {
|
|
75
|
+
text: withReplyContext("[文件1]", data),
|
|
76
|
+
downloadCodes: [],
|
|
77
|
+
files: [{ downloadCode: data.content.downloadCode, fileName }],
|
|
78
|
+
};
|
|
20
79
|
}
|
|
21
80
|
if (data.msgtype === "picture" && data.content?.downloadCode) {
|
|
22
|
-
return { text: "[图片1]", downloadCodes: [data.content.downloadCode] };
|
|
81
|
+
return { text: withReplyContext("[图片1]", data), downloadCodes: [data.content.downloadCode] };
|
|
23
82
|
}
|
|
24
83
|
if (data.content?.richText) {
|
|
25
84
|
const parts = [];
|
|
@@ -35,7 +94,7 @@ export function parseInboundMessage(data) {
|
|
|
35
94
|
}
|
|
36
95
|
const joined = parts.join("").trim();
|
|
37
96
|
if (joined) {
|
|
38
|
-
return { text: joined, downloadCodes };
|
|
97
|
+
return { text: withReplyContext(joined, data), downloadCodes };
|
|
39
98
|
}
|
|
40
99
|
}
|
|
41
100
|
return { text: "", downloadCodes: [] };
|
|
@@ -8,7 +8,7 @@ import type { DWClientDownStream } from "dingtalk-stream";
|
|
|
8
8
|
import type { InboundAttachment, Ingress } from "../channel/ingress.js";
|
|
9
9
|
import type { DingTalkConfig } from "./config.js";
|
|
10
10
|
import type { ConversationMetaStore } from "./conversation-meta.js";
|
|
11
|
-
import { type ParsedInboundMessage } from "./inbound-media.js";
|
|
11
|
+
import { type InboundQuotedMessage, type ParsedInboundMessage } from "./inbound-media.js";
|
|
12
12
|
interface DingTalkIncomingMessage {
|
|
13
13
|
msgId?: string;
|
|
14
14
|
senderStaffId?: string;
|
|
@@ -21,11 +21,17 @@ interface DingTalkIncomingMessage {
|
|
|
21
21
|
msgtype?: string;
|
|
22
22
|
text?: {
|
|
23
23
|
content?: string;
|
|
24
|
+
isReplyMsg?: boolean;
|
|
25
|
+
repliedMsg?: InboundQuotedMessage;
|
|
24
26
|
};
|
|
27
|
+
repliedMsg?: InboundQuotedMessage;
|
|
25
28
|
content?: {
|
|
26
29
|
richText?: Array<Record<string, string>>;
|
|
27
|
-
/** Present on
|
|
30
|
+
/** Present on `picture` / `file` / `audio` messages; see `inbound-media.ts`'s `parseInboundMessage`. */
|
|
28
31
|
downloadCode?: string;
|
|
32
|
+
recognition?: string;
|
|
33
|
+
audioType?: string;
|
|
34
|
+
fileName?: string;
|
|
29
35
|
};
|
|
30
36
|
}
|
|
31
37
|
/** What the DingTalk side needs from the runtime: the one door inbound messages go through. */
|
|
@@ -41,6 +47,7 @@ export interface InboundMessagesDeps {
|
|
|
41
47
|
text: string;
|
|
42
48
|
attachments: InboundAttachment[];
|
|
43
49
|
}>;
|
|
50
|
+
sendPlain?: (channelId: string, text: string) => Promise<boolean>;
|
|
44
51
|
}
|
|
45
52
|
export declare class InboundMessages {
|
|
46
53
|
private deps;
|
package/dist/dingtalk/inbound.js
CHANGED
|
@@ -74,8 +74,10 @@ export class InboundMessages {
|
|
|
74
74
|
const senderName = data.senderNick || "Unknown";
|
|
75
75
|
const conversationId = data.conversationId || "";
|
|
76
76
|
const conversationType = data.conversationType || "1";
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
const hasMedia = parsed.downloadCodes.length > 0 || (parsed.files?.length ?? 0) > 0;
|
|
78
|
+
const msgtype = typeof data.msgtype === "string" ? data.msgtype.trim() || "unknown" : "unknown";
|
|
79
|
+
const isUnsupportedMedia = !parsed.text && !hasMedia && msgtype !== "text" && msgtype !== "unknown";
|
|
80
|
+
if (!parsed.text && !hasMedia && !isUnsupportedMedia) {
|
|
79
81
|
log.logWarn("dingtalk.message.empty", "Empty message ignored", { fields: { msgtype } });
|
|
80
82
|
return;
|
|
81
83
|
}
|
|
@@ -89,6 +91,19 @@ export class InboundMessages {
|
|
|
89
91
|
}
|
|
90
92
|
// Determine channel ID
|
|
91
93
|
const channelId = conversationType === "2" ? dingtalkGroupChannelId(conversationId) : dingtalkDmChannelId(senderId);
|
|
94
|
+
if (isUnsupportedMedia) {
|
|
95
|
+
log.logWarn("dingtalk.message.unsupported", "Unsupported message type rejected", {
|
|
96
|
+
channelId,
|
|
97
|
+
fields: { msgtype },
|
|
98
|
+
});
|
|
99
|
+
this.deps.conversations.set(channelId, {
|
|
100
|
+
conversationId,
|
|
101
|
+
conversationType,
|
|
102
|
+
senderId,
|
|
103
|
+
});
|
|
104
|
+
await this.deps.sendPlain?.(channelId, `⚠️ 暂不支持直接解析 \`${msgtype}\` 类型消息,请改发文字、语音、图片或文件附件。`);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
92
107
|
// Parsing above is free; downloading image attachments below is a real network round-trip.
|
|
93
108
|
// Serialize the whole "download attachments → hand over" unit per channel (spec 049 D3):
|
|
94
109
|
// without this, a message needing a download can be overtaken, in delivery order, by a later
|
package/dist/dingtalk/media.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export interface DingTalkMediaDeps {
|
|
|
12
12
|
* The inbound file fetch used while resolving attachments. The bot supplies its own overridable
|
|
13
13
|
* `downloadMessageFile`, so the deterministic e2e harness can stub the network out.
|
|
14
14
|
*/
|
|
15
|
-
downloadMessageFile: (downloadCode: string) => Promise<{
|
|
15
|
+
downloadMessageFile: (downloadCode: string, maxBytes?: number) => Promise<{
|
|
16
16
|
data: Buffer;
|
|
17
17
|
} | null>;
|
|
18
18
|
}
|
|
@@ -44,18 +44,12 @@ export declare class DingTalkMedia {
|
|
|
44
44
|
* queued turn actually ran, a `downloadCode`/`downloadUrl` fetched only then could easily have
|
|
45
45
|
* already expired.
|
|
46
46
|
*/
|
|
47
|
-
downloadMessageFile(downloadCode: string): Promise<{
|
|
47
|
+
downloadMessageFile(downloadCode: string, maxBytes?: number): Promise<{
|
|
48
48
|
data: Buffer;
|
|
49
49
|
} | null>;
|
|
50
50
|
/**
|
|
51
|
-
* Download one parsed message's images and say, in the text, what became of
|
|
52
|
-
* not make it (spec 049 D8)
|
|
53
|
-
* `MAX_INBOUND_IMAGES_PER_MESSAGE` allows. A failure on one image never drops the rest of the
|
|
54
|
-
* message — only that one `[图片N]` marker changes. The bytes of the others go to the runtime as
|
|
55
|
-
* attachments (it persists them under the bound desk and settles the remaining markers).
|
|
56
|
-
*
|
|
57
|
-
* No-op (no network call at all) when the message carries no image credentials, so a plain
|
|
58
|
-
* text message never pays for this method's existence.
|
|
51
|
+
* Download one parsed message's images/files and say, in the text, what became of any that did
|
|
52
|
+
* not make it (spec 049 D8). No-op when the message carries no attachment credentials.
|
|
59
53
|
*/
|
|
60
54
|
collectInboundAttachments(parsed: ParsedInboundMessage): Promise<{
|
|
61
55
|
text: string;
|
package/dist/dingtalk/media.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* per-message attachment collection built on it (spec 049).
|
|
4
4
|
*/
|
|
5
5
|
import axios from "axios";
|
|
6
|
-
import { MAX_INBOUND_IMAGE_BYTES, MAX_INBOUND_IMAGES_PER_MESSAGE } from "../channel/attachments.js";
|
|
6
|
+
import { MAX_INBOUND_FILE_BYTES, MAX_INBOUND_FILES_PER_MESSAGE, MAX_INBOUND_IMAGE_BYTES, MAX_INBOUND_IMAGES_PER_MESSAGE, } from "../channel/attachments.js";
|
|
7
7
|
import * as log from "../log.js";
|
|
8
8
|
import { errorMessage } from "../shared/text-utils.js";
|
|
9
9
|
import { isRecord } from "../shared/type-guards.js";
|
|
@@ -125,7 +125,7 @@ export class DingTalkMedia {
|
|
|
125
125
|
* queued turn actually ran, a `downloadCode`/`downloadUrl` fetched only then could easily have
|
|
126
126
|
* already expired.
|
|
127
127
|
*/
|
|
128
|
-
async downloadMessageFile(downloadCode) {
|
|
128
|
+
async downloadMessageFile(downloadCode, maxBytes = MAX_INBOUND_IMAGE_BYTES) {
|
|
129
129
|
const token = await this.deps.getAccessToken();
|
|
130
130
|
if (!token)
|
|
131
131
|
return null;
|
|
@@ -142,7 +142,7 @@ export class DingTalkMedia {
|
|
|
142
142
|
const fileResp = await http.get(downloadUrl, {
|
|
143
143
|
responseType: "arraybuffer",
|
|
144
144
|
// Reject an oversized body before it fully lands in memory rather than after.
|
|
145
|
-
maxContentLength:
|
|
145
|
+
maxContentLength: maxBytes,
|
|
146
146
|
timeout: MEDIA_DOWNLOAD_TIMEOUT_MS,
|
|
147
147
|
});
|
|
148
148
|
return { data: Buffer.from(fileResp.data) };
|
|
@@ -161,41 +161,67 @@ export class DingTalkMedia {
|
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
164
|
-
* Download one parsed message's images and say, in the text, what became of
|
|
165
|
-
* not make it (spec 049 D8)
|
|
166
|
-
* `MAX_INBOUND_IMAGES_PER_MESSAGE` allows. A failure on one image never drops the rest of the
|
|
167
|
-
* message — only that one `[图片N]` marker changes. The bytes of the others go to the runtime as
|
|
168
|
-
* attachments (it persists them under the bound desk and settles the remaining markers).
|
|
169
|
-
*
|
|
170
|
-
* No-op (no network call at all) when the message carries no image credentials, so a plain
|
|
171
|
-
* text message never pays for this method's existence.
|
|
164
|
+
* Download one parsed message's images/files and say, in the text, what became of any that did
|
|
165
|
+
* not make it (spec 049 D8). No-op when the message carries no attachment credentials.
|
|
172
166
|
*/
|
|
173
167
|
async collectInboundAttachments(parsed) {
|
|
174
|
-
|
|
168
|
+
const files = parsed.files ?? [];
|
|
169
|
+
if (parsed.downloadCodes.length === 0 && files.length === 0) {
|
|
175
170
|
return { text: parsed.text, attachments: [] };
|
|
176
171
|
}
|
|
177
172
|
let text = parsed.text;
|
|
178
|
-
const
|
|
179
|
-
const
|
|
173
|
+
const imageAttachments = [];
|
|
174
|
+
const fileAttachments = [];
|
|
175
|
+
const replaceImageMarker = (index, replacement) => {
|
|
180
176
|
text = text.replace(`[图片${index + 1}]`, replacement);
|
|
181
177
|
};
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
178
|
+
const replaceFileMarker = (index, replacement) => {
|
|
179
|
+
text = text.replace(`[文件${index + 1}]`, replacement);
|
|
180
|
+
};
|
|
181
|
+
await Promise.all([
|
|
182
|
+
...parsed.downloadCodes.map(async (downloadCode, index) => {
|
|
183
|
+
const marker = index + 1;
|
|
184
|
+
if (index >= MAX_INBOUND_IMAGES_PER_MESSAGE) {
|
|
185
|
+
replaceImageMarker(index, `[图片${marker}:超出单条消息图片数量上限,已丢弃]`);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const downloaded = await this.deps.downloadMessageFile(downloadCode, MAX_INBOUND_IMAGE_BYTES);
|
|
189
|
+
if (!downloaded) {
|
|
190
|
+
replaceImageMarker(index, `[图片${marker}:接收失败]`);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (downloaded.data.byteLength > MAX_INBOUND_IMAGE_BYTES) {
|
|
194
|
+
replaceImageMarker(index, `[图片${marker}:文件过大(${formatSize(downloaded.data.byteLength)}),已丢弃]`);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
imageAttachments[index] = { kind: "image", index: marker, data: downloaded.data };
|
|
198
|
+
}),
|
|
199
|
+
...files.map(async (file, index) => {
|
|
200
|
+
const marker = index + 1;
|
|
201
|
+
if (index >= MAX_INBOUND_FILES_PER_MESSAGE) {
|
|
202
|
+
replaceFileMarker(index, `[文件${marker}:超出单条消息附件数量上限,已丢弃]`);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const downloaded = await this.deps.downloadMessageFile(file.downloadCode, MAX_INBOUND_FILE_BYTES);
|
|
206
|
+
if (!downloaded) {
|
|
207
|
+
replaceFileMarker(index, `[文件${marker}(${file.fileName}):接收失败]`);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (downloaded.data.byteLength > MAX_INBOUND_FILE_BYTES) {
|
|
211
|
+
replaceFileMarker(index, `[文件${marker}(${file.fileName}):文件过大(${formatSize(downloaded.data.byteLength)}),已丢弃]`);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
fileAttachments[index] = {
|
|
215
|
+
kind: "file",
|
|
216
|
+
index: marker,
|
|
217
|
+
data: downloaded.data,
|
|
218
|
+
fileName: file.fileName,
|
|
219
|
+
};
|
|
220
|
+
}),
|
|
221
|
+
]);
|
|
222
|
+
return {
|
|
223
|
+
text,
|
|
224
|
+
attachments: [...imageAttachments, ...fileAttachments].filter((attachment) => !!attachment),
|
|
225
|
+
};
|
|
200
226
|
}
|
|
201
227
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { ChannelDescription } from "../channel/channel-id.js";
|
|
2
|
+
import type { SecurityConfig } from "../security/types.js";
|
|
2
3
|
export interface HandleEventsCommandOptions {
|
|
3
4
|
args: string;
|
|
4
5
|
/** The asking channel's desk: its `events/` and its history records are the whole scope. */
|
|
5
6
|
desk: string;
|
|
6
7
|
deskDir: string;
|
|
7
8
|
historyPath: string;
|
|
9
|
+
commandGuardConfig?: SecurityConfig["commandGuard"];
|
|
8
10
|
/** Names a delivery channel and says whether it is still bound to this desk. */
|
|
9
11
|
describeChannel: (channelId: string) => ChannelDescription;
|
|
10
12
|
}
|
package/dist/events/commands.js
CHANGED
|
@@ -9,6 +9,7 @@ import { renderSubcommandUsage } from "../commands/catalog.js";
|
|
|
9
9
|
import { capReply } from "../commands/reply-limits.js";
|
|
10
10
|
import { normalizeSafeId, resolveSafeIdPath } from "../shared/safe-id.js";
|
|
11
11
|
import { errorMessage, eventNameFromFilename, clipText as sharedClipText } from "../shared/text-utils.js";
|
|
12
|
+
import { readEventHistoryLines } from "./history.js";
|
|
12
13
|
import { describeEventPayload, parseScheduledEventContent } from "./parse.js";
|
|
13
14
|
import { EventDefinitionError, validateScheduledEvent } from "./validation.js";
|
|
14
15
|
const EVENT_NAME_PATTERN = /^[A-Za-z0-9._-]+$/;
|
|
@@ -116,8 +117,14 @@ async function listEvents(options) {
|
|
|
116
117
|
const event = parseScheduledEventContent(await readFile(eventPath, "utf-8"), filename);
|
|
117
118
|
// The same definition rules the watcher applies, so "listed as fine" means "will run".
|
|
118
119
|
// The lead-time rule is creation-only (an overdue one-shot is a legitimate recovery).
|
|
119
|
-
validateScheduledEvent(event, {
|
|
120
|
-
|
|
120
|
+
validateScheduledEvent(event, {
|
|
121
|
+
enforceOneShotLead: false,
|
|
122
|
+
commandGuardConfig: options.commandGuardConfig,
|
|
123
|
+
});
|
|
124
|
+
const summary = formatEventSummary(name, event, options.describeChannel);
|
|
125
|
+
blocks.push(existsSync(`${eventPath}.error.txt`)
|
|
126
|
+
? `${summary}\n- ⚠️ 最近加载或触发失败,用 \`/events history ${name}\` 查看`
|
|
127
|
+
: summary);
|
|
121
128
|
}
|
|
122
129
|
catch (error) {
|
|
123
130
|
blocks.push(`**${name}**\n- ⚠️ 无效:${describeEventProblem(error, name)}`);
|
|
@@ -170,6 +177,7 @@ async function deleteEvent(options, name) {
|
|
|
170
177
|
// Unparseable content is still safe to delete; just skip the summary.
|
|
171
178
|
}
|
|
172
179
|
await unlink(eventPath);
|
|
180
|
+
await unlink(`${eventPath}.error.txt`).catch(() => undefined);
|
|
173
181
|
return summary ? `已删除事件:\n\n${summary}` : `已删除事件 \`${eventName}\`。`;
|
|
174
182
|
}
|
|
175
183
|
function parseHistoryLine(line) {
|
|
@@ -225,13 +233,10 @@ async function showHistory(options, name) {
|
|
|
225
233
|
const empty = eventName
|
|
226
234
|
? `暂无事件 \`${eventName}\` 的触发记录。\n事件触发后会记录在这里。`
|
|
227
235
|
: "暂无事件触发记录。\n事件触发后会记录在这里。";
|
|
228
|
-
|
|
236
|
+
const lines = await readEventHistoryLines(historyPath);
|
|
237
|
+
if (lines.length === 0)
|
|
229
238
|
return empty;
|
|
230
|
-
const
|
|
231
|
-
const records = raw
|
|
232
|
-
.split("\n")
|
|
233
|
-
.map((line) => line.trim())
|
|
234
|
-
.filter(Boolean)
|
|
239
|
+
const records = lines
|
|
235
240
|
.map(parseHistoryLine)
|
|
236
241
|
.filter((record) => !!record)
|
|
237
242
|
.filter((record) => belongsToDesk(record, options))
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type JsonlAppender } from "../shared/jsonl-appender.js";
|
|
2
|
+
export declare const EVENT_HISTORY_MAX_BYTES: number;
|
|
3
|
+
export declare function getEventHistoryAppender(path: string, maxSizeBytes?: number): JsonlAppender;
|
|
4
|
+
export declare function ensureEventHistoryFile(historyPath: string): void;
|
|
5
|
+
/**
|
|
6
|
+
* Read retained history shards from oldest to newest (`.2` → `.1` → active file) so `/events history`
|
|
7
|
+
* remains continuous right across a rotation boundary.
|
|
8
|
+
*/
|
|
9
|
+
export declare function readEventHistoryLines(historyPath: string): Promise<string[]>;
|