@oyasmi/pipiclaw 0.9.4-beta.1 → 0.9.4-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/dist/agent/builtin-commands.d.ts +19 -0
- package/dist/agent/builtin-commands.js +80 -0
- package/dist/agent/channel-runner.d.ts +20 -208
- package/dist/agent/channel-runner.js +148 -1245
- package/dist/agent/maintenance-context.d.ts +1 -1
- package/dist/agent/maintenance-context.js +1 -1
- package/dist/agent/prompt/resources.d.ts +3 -0
- package/dist/agent/prompt/resources.js +7 -1
- package/dist/agent/runner-factory.d.ts +1 -43
- package/dist/agent/{command-extension.d.ts → session/command-extension.d.ts} +4 -0
- package/dist/agent/{command-extension.js → session/command-extension.js} +5 -5
- package/dist/agent/{type-guards.d.ts → session/event-guards.d.ts} +2 -2
- package/dist/agent/{type-guards.js → session/event-guards.js} +5 -1
- package/dist/agent/session/model-selection.d.ts +47 -0
- package/dist/agent/session/model-selection.js +99 -0
- package/dist/agent/{session-adapter.d.ts → session/session-adapter.d.ts} +21 -1
- package/dist/agent/{session-adapter.js → session/session-adapter.js} +83 -1
- package/dist/agent/{session-events.d.ts → session/session-events.d.ts} +9 -5
- package/dist/agent/{session-events.js → session/session-events.js} +10 -10
- package/dist/agent/session/session-host.d.ts +200 -0
- package/dist/agent/session/session-host.js +621 -0
- package/dist/agent/{session-resource-gate.js → session/session-resource-gate.js} +2 -2
- package/dist/agent/{context-budget.js → turn/context-budget.js} +5 -1
- package/dist/agent/{progress-formatter.d.ts → turn/progress-formatter.d.ts} +4 -1
- package/dist/agent/{run-queue.d.ts → turn/run-queue.d.ts} +1 -1
- package/dist/agent/{run-queue.js → turn/run-queue.js} +3 -3
- package/dist/{memory → agent/turn}/task-digest.js +4 -4
- package/dist/agent/turn/turn-context.d.ts +14 -0
- package/dist/agent/turn/turn-context.js +64 -0
- package/dist/agent/turn/turn-finish.d.ts +50 -0
- package/dist/agent/turn/turn-finish.js +188 -0
- package/dist/agent/turn/turn-input.d.ts +43 -0
- package/dist/agent/turn/turn-input.js +79 -0
- package/dist/agent/turn/turn-pipeline.d.ts +68 -0
- package/dist/agent/turn/turn-pipeline.js +257 -0
- package/dist/agent/{turn-prompt.d.ts → turn/turn-prompt.d.ts} +2 -2
- package/dist/agent/{turn-prompt.js → turn/turn-prompt.js} +6 -2
- package/dist/agent/{turn-recovery.js → turn/turn-recovery.js} +1 -1
- package/dist/agent/{turn-state.d.ts → turn/turn-state.d.ts} +1 -1
- package/dist/agent/types.d.ts +43 -2
- package/dist/agent/types.js +1 -1
- package/dist/{models/auth-cli.d.ts → app/auth-command.d.ts} +1 -1
- package/dist/{models/auth-cli.js → app/auth-command.js} +11 -8
- package/dist/{runtime/app-home.d.ts → app/home.d.ts} +0 -2
- package/dist/{runtime/app-home.js → app/home.js} +4 -75
- package/dist/{app-services.d.ts → app/services.d.ts} +5 -5
- package/dist/{app-services.js → app/services.js} +10 -10
- package/dist/channel/channel-context.d.ts +12 -2
- package/dist/channel/channel-context.js +29 -2
- package/dist/channel/channel-event.d.ts +10 -2
- package/dist/channel/channel-event.js +1 -1
- package/dist/{runtime/project-commands.d.ts → channel/commands.d.ts} +1 -1
- package/dist/{runtime/project-commands.js → channel/commands.js} +1 -1
- package/dist/channel/store.js +4 -0
- package/dist/commands/catalog.d.ts +3 -3
- package/dist/commands/catalog.js +3 -3
- package/dist/{runtime/report-commands.d.ts → commands/router.d.ts} +10 -3
- package/dist/{runtime/report-commands.js → commands/router.js} +5 -5
- package/dist/{settings.d.ts → config/settings.d.ts} +7 -8
- package/dist/{settings.js → config/settings.js} +7 -10
- package/dist/{tools/config.d.ts → config/tools.d.ts} +1 -2
- package/dist/{tools/config.js → config/tools.js} +5 -2
- package/dist/dingtalk/access-token.d.ts +12 -0
- package/dist/dingtalk/access-token.js +51 -0
- package/dist/dingtalk/api.d.ts +19 -0
- package/dist/dingtalk/api.js +67 -0
- package/dist/dingtalk/bot.d.ts +97 -0
- package/dist/dingtalk/bot.js +389 -0
- package/dist/dingtalk/cards.d.ts +56 -0
- package/dist/dingtalk/cards.js +318 -0
- package/dist/{runtime → dingtalk}/channel-queue.js +3 -0
- package/dist/dingtalk/config.d.ts +19 -0
- package/dist/dingtalk/config.js +95 -0
- package/dist/dingtalk/connection.d.ts +57 -0
- package/dist/dingtalk/connection.js +356 -0
- package/dist/dingtalk/conversation-meta.d.ts +16 -0
- package/dist/dingtalk/conversation-meta.js +77 -0
- package/dist/{runtime → dingtalk}/delivery.d.ts +6 -2
- package/dist/dingtalk/handler.d.ts +90 -0
- package/dist/dingtalk/handler.js +1 -0
- package/dist/dingtalk/inbound.d.ts +66 -0
- package/dist/dingtalk/inbound.js +137 -0
- package/dist/dingtalk/media.d.ts +66 -0
- package/dist/dingtalk/media.js +214 -0
- package/dist/events/{event-commands.js → commands.js} +6 -2
- package/dist/events/parse.d.ts +14 -0
- package/dist/events/parse.js +114 -0
- package/dist/events/types.d.ts +93 -0
- package/dist/events/types.js +1 -0
- package/dist/events/{event-validation.d.ts → validation.d.ts} +1 -1
- package/dist/events/watcher.d.ts +67 -0
- package/dist/events/{events.js → watcher.js} +6 -109
- package/dist/index.d.ts +6 -4
- package/dist/index.js +2 -2
- package/dist/jobs/launch.d.ts +42 -0
- package/dist/jobs/launch.js +118 -0
- package/dist/{agent/job-manager.d.ts → jobs/manager.d.ts} +1 -67
- package/dist/{agent/job-manager.js → jobs/manager.js} +3 -146
- package/dist/jobs/record.d.ts +55 -0
- package/dist/jobs/record.js +36 -0
- package/dist/main.js +2 -2
- package/dist/memory/maintenance-gates.d.ts +2 -2
- package/dist/memory/maintenance-tuning.d.ts +15 -0
- package/dist/memory/maintenance-tuning.js +3 -0
- package/dist/memory/reflect-job.d.ts +2 -2
- package/dist/memory/reflect-job.js +4 -2
- package/dist/memory/scheduler.d.ts +3 -3
- package/dist/memory/scheduler.js +2 -1
- package/dist/memory/sidecar-worker.js +1 -1
- package/dist/memory/transcript.js +1 -1
- package/dist/{agent/model-fallback.d.ts → models/fallback.d.ts} +6 -6
- package/dist/{agent/model-fallback.js → models/fallback.js} +15 -28
- package/dist/models/login-identity.d.ts +2 -0
- package/dist/models/login-identity.js +83 -0
- package/dist/models/provider-login.d.ts +3 -1
- package/dist/models/provider-login.js +8 -2
- package/dist/models/reference.d.ts +20 -0
- package/dist/models/{utils.js → reference.js} +0 -48
- package/dist/models/{utils.d.ts → runtime.d.ts} +1 -16
- package/dist/models/runtime.js +52 -0
- package/dist/playbooks/catalog.d.ts +6 -2
- package/dist/playbooks/catalog.js +9 -6
- package/dist/runtime/bootstrap.d.ts +7 -17
- package/dist/runtime/bootstrap.js +37 -755
- package/dist/runtime/durable-dispatch.d.ts +17 -4
- package/dist/runtime/durable-dispatch.js +60 -18
- package/dist/runtime/inbound-images.d.ts +18 -0
- package/dist/runtime/inbound-images.js +51 -0
- package/dist/runtime/shutdown.d.ts +39 -0
- package/dist/runtime/shutdown.js +120 -0
- package/dist/runtime/stop-watchdog.d.ts +16 -0
- package/dist/runtime/stop-watchdog.js +32 -0
- package/dist/runtime/task-driver.d.ts +2 -2
- package/dist/runtime/task-driver.js +3 -3
- package/dist/runtime/task-migration.js +2 -2
- package/dist/runtime/task-spawn.d.ts +1 -1
- package/dist/runtime/task-spawn.js +1 -1
- package/dist/runtime/turn-handler.d.ts +47 -0
- package/dist/runtime/turn-handler.js +318 -0
- package/dist/runtime/turn-run.d.ts +52 -0
- package/dist/runtime/turn-run.js +318 -0
- package/dist/security/command-guard.js +4 -0
- package/dist/security/network.js +4 -0
- package/dist/security/path-guard.js +4 -0
- package/dist/security/types.d.ts +1 -2
- package/dist/security/types.js +1 -2
- package/dist/shared/exact-keys.d.ts +1 -1
- package/dist/shared/host-process.js +1 -1
- package/dist/shared/wake-claim.d.ts +1 -1
- package/dist/{runtime/skill-commands.d.ts → skills/commands.d.ts} +2 -2
- package/dist/{runtime/skill-commands.js → skills/commands.js} +1 -1
- package/dist/{agent/workspace-resources.js → skills/loader.js} +1 -1
- package/dist/{tools/skill-security.js → skills/validation.js} +4 -0
- package/dist/skills/workspace.d.ts +33 -0
- package/dist/skills/workspace.js +116 -0
- package/dist/{runtime/subagent-commands.d.ts → subagents/commands.d.ts} +4 -3
- package/dist/{runtime/subagent-commands.js → subagents/commands.js} +2 -2
- package/dist/subagents/completion-wake.d.ts +17 -0
- package/dist/subagents/completion-wake.js +76 -0
- package/dist/subagents/detached-discovery.js +1 -1
- package/dist/subagents/discovery.d.ts +1 -1
- package/dist/subagents/discovery.js +2 -2
- package/dist/subagents/dispatch.d.ts +33 -0
- package/dist/subagents/dispatch.js +190 -0
- package/dist/subagents/external/dispatch.d.ts +25 -0
- package/dist/subagents/external/dispatch.js +90 -0
- package/dist/subagents/external/harness.d.ts +1 -1
- package/dist/subagents/external/progress-tail.d.ts +1 -1
- package/dist/subagents/external/run.d.ts +2 -1
- package/dist/subagents/external/run.js +2 -2
- package/dist/subagents/external/settlement.d.ts +1 -1
- package/dist/subagents/format.d.ts +1 -1
- package/dist/subagents/grace.d.ts +24 -0
- package/dist/subagents/grace.js +57 -0
- package/dist/subagents/internal/outcome.d.ts +24 -0
- package/dist/subagents/internal/outcome.js +149 -0
- package/dist/subagents/internal/provider-retry.d.ts +19 -0
- package/dist/subagents/internal/provider-retry.js +83 -0
- package/dist/subagents/internal/run.d.ts +31 -0
- package/dist/subagents/internal/run.js +240 -0
- package/dist/subagents/internal/state.d.ts +43 -0
- package/dist/subagents/internal/state.js +48 -0
- package/dist/subagents/internal/worker.d.ts +51 -0
- package/dist/subagents/internal/worker.js +167 -0
- package/dist/subagents/result.d.ts +62 -0
- package/dist/subagents/result.js +103 -0
- package/dist/subagents/run-record.d.ts +222 -0
- package/dist/subagents/run-record.js +101 -0
- package/dist/subagents/run-registry.d.ts +9 -0
- package/dist/subagents/run-registry.js +125 -0
- package/dist/subagents/runs.d.ts +7 -243
- package/dist/subagents/runs.js +8 -291
- package/dist/subagents/task-envelope.d.ts +36 -0
- package/dist/subagents/task-envelope.js +168 -0
- package/dist/subagents/types.d.ts +154 -0
- package/dist/subagents/types.js +1 -0
- package/dist/subagents/verification-outcome.d.ts +1 -1
- package/dist/tasks/board.d.ts +2 -2
- package/dist/tasks/board.js +2 -2
- package/dist/tasks/{work-log.d.ts → bound-work.d.ts} +1 -1
- package/dist/tasks/{work-log.js → bound-work.js} +1 -1
- package/dist/tasks/brief.js +1 -1
- package/dist/{runtime/task-commands.d.ts → tasks/commands.d.ts} +1 -1
- package/dist/{runtime/task-commands.js → tasks/commands.js} +12 -8
- package/dist/tasks/contract-input.d.ts +1 -1
- package/dist/tasks/contract-input.js +1 -1
- package/dist/tasks/create.js +1 -1
- package/dist/tasks/{log.js → loop-log.js} +1 -1
- package/dist/tasks/mutation-lock.js +1 -1
- package/dist/tasks/session-path.js +1 -1
- package/dist/tasks/steer.js +1 -1
- package/dist/tasks/store.js +2 -2
- package/dist/tools/bash.d.ts +1 -1
- package/dist/tools/{tool-details.d.ts → contract/details.d.ts} +2 -2
- package/dist/tools/{tool-details.js → contract/details.js} +4 -4
- package/dist/tools/{presentation.js → contract/presentation.js} +3 -3
- package/dist/tools/event-manage.d.ts +1 -1
- package/dist/tools/event-manage.js +4 -4
- package/dist/tools/index.d.ts +3 -3
- package/dist/tools/index.js +7 -6
- package/dist/tools/job.d.ts +1 -1
- package/dist/tools/registry.d.ts +7 -7
- package/dist/tools/registry.js +6 -6
- package/dist/tools/session-search.d.ts +1 -1
- package/dist/tools/skill.d.ts +2 -34
- package/dist/tools/skill.js +8 -116
- package/dist/tools/subagent-manage.js +4 -3
- package/dist/tools/subagent.d.ts +46 -0
- package/dist/tools/subagent.js +127 -0
- package/dist/tools/{task-manage.d.ts → task-manage/factory.d.ts} +7 -3
- package/dist/tools/{task-manage.js → task-manage/factory.js} +7 -7
- package/dist/tools/task-manage/lifecycle.js +2 -2
- package/dist/tools/task-manage/log-view.js +2 -2
- package/dist/tools/task-manage/shared.js +3 -3
- package/dist/tools/task-manage/step-end.js +3 -3
- package/dist/tools/task-manage/types.d.ts +1 -1
- package/dist/tools/web-fetch.d.ts +1 -1
- package/dist/tools/web-search.d.ts +1 -1
- package/dist/tui/app.d.ts +1 -1
- package/dist/tui/app.js +6 -6
- package/dist/tui/cli.d.ts +1 -1
- package/dist/tui/cli.js +1 -1
- package/dist/tui/frontend.d.ts +44 -0
- package/dist/tui/frontend.js +13 -0
- package/dist/tui/pitui-frontend.d.ts +1 -1
- package/dist/tui/plain-frontend.d.ts +1 -1
- package/dist/tui/renderer.d.ts +3 -42
- package/dist/tui/terminal-context.d.ts +2 -2
- package/dist/tui/terminal-media-sender.d.ts +1 -1
- package/dist/tui/turn-controller.d.ts +1 -1
- package/dist/usage/ledger.js +4 -0
- package/dist/{shared/types.d.ts → usage/totals.d.ts} +3 -0
- package/dist/web/client.d.ts +5 -1
- package/dist/web/client.js +4 -0
- package/dist/web/config.d.ts +1 -1
- package/dist/web/fetch.d.ts +1 -1
- package/dist/web/search-providers.d.ts +1 -1
- package/dist/web/search.d.ts +1 -1
- package/package.json +9 -7
- package/dist/events/events.d.ts +0 -159
- package/dist/runtime/dingtalk.d.ts +0 -272
- package/dist/runtime/dingtalk.js +0 -1470
- package/dist/subagents/tool.d.ts +0 -213
- package/dist/subagents/tool.js +0 -1282
- /package/dist/{runtime → agent/prompt}/workspace-templates.d.ts +0 -0
- /package/dist/{runtime → agent/prompt}/workspace-templates.js +0 -0
- /package/dist/agent/{session-resource-gate.d.ts → session/session-resource-gate.d.ts} +0 -0
- /package/dist/agent/{context-budget.d.ts → turn/context-budget.d.ts} +0 -0
- /package/dist/agent/{progress-formatter.js → turn/progress-formatter.js} +0 -0
- /package/dist/{memory → agent/turn}/task-digest.d.ts +0 -0
- /package/dist/agent/{turn-error.d.ts → turn/turn-error.d.ts} +0 -0
- /package/dist/agent/{turn-error.js → turn/turn-error.js} +0 -0
- /package/dist/agent/{turn-recovery.d.ts → turn/turn-recovery.d.ts} +0 -0
- /package/dist/agent/{turn-state.js → turn/turn-state.js} +0 -0
- /package/dist/{runtime → app}/proxy.d.ts +0 -0
- /package/dist/{runtime → app}/proxy.js +0 -0
- /package/dist/{runtime → dingtalk}/channel-queue.d.ts +0 -0
- /package/dist/{runtime → dingtalk}/delivery.js +0 -0
- /package/dist/{runtime → dingtalk}/inbound-media.d.ts +0 -0
- /package/dist/{runtime → dingtalk}/inbound-media.js +0 -0
- /package/dist/events/{event-commands.d.ts → commands.d.ts} +0 -0
- /package/dist/events/{event-validation.js → validation.js} +0 -0
- /package/dist/{agent/workspace-resources.d.ts → skills/loader.d.ts} +0 -0
- /package/dist/{tools/skill-security.d.ts → skills/validation.d.ts} +0 -0
- /package/dist/tasks/{ledger.d.ts → contract.d.ts} +0 -0
- /package/dist/tasks/{ledger.js → contract.js} +0 -0
- /package/dist/tasks/{log.d.ts → loop-log.d.ts} +0 -0
- /package/dist/tools/{subagent-tool-names.d.ts → contract/names.d.ts} +0 -0
- /package/dist/tools/{subagent-tool-names.js → contract/names.js} +0 -0
- /package/dist/tools/{presentation.d.ts → contract/presentation.d.ts} +0 -0
- /package/dist/{shared/types.js → usage/totals.js} +0 -0
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
*
|
|
4
4
|
* `ChannelContext` is the surface a `ChannelRunner` turn writes to: progress
|
|
5
5
|
* updates, the final answer, side notices, and lifecycle hooks. The DingTalk
|
|
6
|
-
* transport implements it via AI Card streaming (`
|
|
6
|
+
* transport implements it via AI Card streaming (`dingtalk/delivery.ts`); the
|
|
7
7
|
* terminal TUI implements it by rendering to the console (`tui/`). The runner
|
|
8
8
|
* and `session-events` depend only on this interface, never on a concrete
|
|
9
9
|
* transport.
|
|
10
10
|
*
|
|
11
|
-
* These declarations previously lived in `
|
|
11
|
+
* These declarations previously lived in `dingtalk/bot.ts` under the name
|
|
12
12
|
* `DingTalkContext`; they were lifted out (and renamed) so a second transport
|
|
13
13
|
* can implement the contract without importing anything DingTalk-specific. They
|
|
14
14
|
* live in `src/channel/` rather than `src/runtime/` because a port belongs with
|
|
@@ -16,6 +16,33 @@
|
|
|
16
16
|
* `tui` all depend on this file, and none of them should be reading anything out
|
|
17
17
|
* of the DingTalk transport's directory to get it.
|
|
18
18
|
*/
|
|
19
|
+
const RESPONSE_MODE_VALUES = [
|
|
20
|
+
"full_progress_then_plain_final",
|
|
21
|
+
"rolling_progress_then_plain_final",
|
|
22
|
+
"final_card_only",
|
|
23
|
+
];
|
|
24
|
+
export function progressStyleOf(mode) {
|
|
25
|
+
if (mode === "final_card_only")
|
|
26
|
+
return "none";
|
|
27
|
+
if (mode === "rolling_progress_then_plain_final")
|
|
28
|
+
return "rolling";
|
|
29
|
+
return "full";
|
|
30
|
+
}
|
|
31
|
+
export function finalDeliveryOf(mode) {
|
|
32
|
+
return mode === "final_card_only" ? "card" : "plain";
|
|
33
|
+
}
|
|
34
|
+
export function isResponseModeConfig(value) {
|
|
35
|
+
return typeof value === "string" && RESPONSE_MODE_VALUES.includes(value);
|
|
36
|
+
}
|
|
37
|
+
export function normalizeResponseMode(value) {
|
|
38
|
+
if (value === undefined) {
|
|
39
|
+
return "full_progress_then_plain_final";
|
|
40
|
+
}
|
|
41
|
+
if (isResponseModeConfig(value)) {
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
throw new Error('Invalid `responseMode`: expected "full_progress_then_plain_final", "rolling_progress_then_plain_final", or "final_card_only".');
|
|
45
|
+
}
|
|
19
46
|
/**
|
|
20
47
|
* A context whose user-visible writes are dropped (spec 051, D3).
|
|
21
48
|
*
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* `MAX_IMAGE_BYTES` mirrors the *send* limit); this instead mirrors `tools/truncate.ts`'s
|
|
4
4
|
* `MAX_INLINE_BINARY_BYTES` — the same ceiling `read` already applies to an on-disk image — so
|
|
5
5
|
* "a picture the user sent" and "a picture `read` loads from disk" behave identically for the
|
|
6
|
-
* model. Lives here, not in the DingTalk-specific `
|
|
6
|
+
* model. Lives here, not in the DingTalk-specific `dingtalk/inbound-media.ts`, because both the
|
|
7
7
|
* transport (rejecting an oversized download) and `agent/channel-runner.ts` (skipping an
|
|
8
8
|
* oversized file before base64-encoding it) need the same number, and `agent/` never imports
|
|
9
9
|
* from `runtime/` (spec 049).
|
|
@@ -39,7 +39,7 @@ export interface InboundImage {
|
|
|
39
39
|
* A message or wake, from any producer: a real inbound DingTalk message, a scheduled event, a
|
|
40
40
|
* task-driver wake, or a job/subagent completion. `conversationId` is the one field genuinely
|
|
41
41
|
* DingTalk-specific (needed to reply into the right conversation); every synthetic producer
|
|
42
|
-
* (
|
|
42
|
+
* (jobs/manager, task-driver, events, subagents/runs) leaves it unset rather than faking a value,
|
|
43
43
|
* since it has no DingTalk conversation to route into. `conversationType` is not DingTalk-specific
|
|
44
44
|
* in practice — every producer, real or synthetic, can derive "1"/"2" from the channelId prefix —
|
|
45
45
|
* so it stays required.
|
|
@@ -80,3 +80,11 @@ export interface ChannelEvent {
|
|
|
80
80
|
*/
|
|
81
81
|
presentation?: "awaited";
|
|
82
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* The one thing in-process producers (scheduled events, durable dispatch) need from a transport:
|
|
85
|
+
* hand it a synthetic event for its per-channel queue. `false` means the queue rejected it (full
|
|
86
|
+
* or stopped), so the caller keeps ownership and may retry. Implemented by `DingTalkBot`.
|
|
87
|
+
*/
|
|
88
|
+
export interface ChannelEventSink {
|
|
89
|
+
enqueueEvent(event: ChannelEvent): boolean;
|
|
90
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* `MAX_IMAGE_BYTES` mirrors the *send* limit); this instead mirrors `tools/truncate.ts`'s
|
|
4
4
|
* `MAX_INLINE_BINARY_BYTES` — the same ceiling `read` already applies to an on-disk image — so
|
|
5
5
|
* "a picture the user sent" and "a picture `read` loads from disk" behave identically for the
|
|
6
|
-
* model. Lives here, not in the DingTalk-specific `
|
|
6
|
+
* model. Lives here, not in the DingTalk-specific `dingtalk/inbound-media.ts`, because both the
|
|
7
7
|
* transport (rejecting an oversized download) and `agent/channel-runner.ts` (skipping an
|
|
8
8
|
* oversized file before base64-encoding it) need the same number, and `agent/` never imports
|
|
9
9
|
* from `runtime/` (spec 049).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `/project` — the human control path for a channel's project scope (spec 043, D7). Mirrors
|
|
3
|
-
* `
|
|
3
|
+
* `tasks/commands.ts`/`subagents/commands.ts`'s shape: pure-ish functions returning markdown, no
|
|
4
4
|
* bot/event coupling. Mutations never reach the model.
|
|
5
5
|
*/
|
|
6
6
|
type ProjectCommand = {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { commitProjectSelection, readProjectSelection } from "../channel/project-scope-store.js";
|
|
2
1
|
import { renderSubcommandUsage } from "../commands/catalog.js";
|
|
3
2
|
import { loadSecurityConfigWithDiagnostics } from "../security/config.js";
|
|
4
3
|
import { currentProjectSandboxStatus, isWithinAllowedRoots, resolveExistingDirectory, resolveProjectAccessPolicy, } from "../security/project-scope.js";
|
|
5
4
|
import { errorMessage } from "../shared/text-utils.js";
|
|
5
|
+
import { commitProjectSelection, readProjectSelection } from "./project-scope-store.js";
|
|
6
6
|
function usage() {
|
|
7
7
|
return renderSubcommandUsage("project");
|
|
8
8
|
}
|
package/dist/channel/store.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-channel message archive (`log.jsonl`): inbound messages, bot responses and delegation records,
|
|
3
|
+
* with de-duplication, size rotation and a debounced flush.
|
|
4
|
+
*/
|
|
1
5
|
import { existsSync, mkdirSync } from "fs";
|
|
2
6
|
import { writeFile } from "fs/promises";
|
|
3
7
|
import { basename, dirname, join } from "path";
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* `/skills`), the agent session (`/model`, `/compact`, `/new`) and memory (`/memory`) — and is read
|
|
8
8
|
* by all of them plus the TUI. Only the catalog and the reply shape are shared: each *handler*
|
|
9
9
|
* still lives in the layer that owns the state it touches (`runtime/*-commands.ts`,
|
|
10
|
-
* `memory/commands.ts`, `agent/command-extension.ts`). This file has no imports at all, so nothing
|
|
10
|
+
* `memory/commands.ts`, `agent/session/command-extension.ts`). This file has no imports at all, so nothing
|
|
11
11
|
* here can drag a layer into another one.
|
|
12
12
|
*
|
|
13
13
|
* The user-facing copy conventions these commands follow are recorded in AGENTS.md; `reply-limits.ts`
|
|
@@ -98,8 +98,8 @@ export declare function isRunnerBuiltInCommand(command: BuiltInCommand): command
|
|
|
98
98
|
*/
|
|
99
99
|
export declare function formatBusyHint(): string;
|
|
100
100
|
/**
|
|
101
|
-
* Renders a command's subcommand table as its `usage()` text — the single source `
|
|
102
|
-
* `
|
|
101
|
+
* Renders a command's subcommand table as its `usage()` text — the single source `tasks/commands.ts`,
|
|
102
|
+
* `events/commands.ts`, `subagents/commands.ts`, `channel/commands.ts`, and `memory/commands.ts` call
|
|
103
103
|
* on a parse error, replacing five hand-written `usage()` bodies (review 2026-08-24 §3.1).
|
|
104
104
|
*/
|
|
105
105
|
export declare function renderSubcommandUsage(name: string): string;
|
package/dist/commands/catalog.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* `/skills`), the agent session (`/model`, `/compact`, `/new`) and memory (`/memory`) — and is read
|
|
8
8
|
* by all of them plus the TUI. Only the catalog and the reply shape are shared: each *handler*
|
|
9
9
|
* still lives in the layer that owns the state it touches (`runtime/*-commands.ts`,
|
|
10
|
-
* `memory/commands.ts`, `agent/command-extension.ts`). This file has no imports at all, so nothing
|
|
10
|
+
* `memory/commands.ts`, `agent/session/command-extension.ts`). This file has no imports at all, so nothing
|
|
11
11
|
* here can drag a layer into another one.
|
|
12
12
|
*
|
|
13
13
|
* The user-facing copy conventions these commands follow are recorded in AGENTS.md; `reply-limits.ts`
|
|
@@ -325,8 +325,8 @@ export function formatBusyHint() {
|
|
|
325
325
|
return `当前已有回合在运行。运行中可用:${commandList(whileBusy)}。${commandList(idleOnly)} 需要等空闲后再用。`;
|
|
326
326
|
}
|
|
327
327
|
/**
|
|
328
|
-
* Renders a command's subcommand table as its `usage()` text — the single source `
|
|
329
|
-
* `
|
|
328
|
+
* Renders a command's subcommand table as its `usage()` text — the single source `tasks/commands.ts`,
|
|
329
|
+
* `events/commands.ts`, `subagents/commands.ts`, `channel/commands.ts`, and `memory/commands.ts` call
|
|
330
330
|
* on a parse error, replacing five hand-written `usage()` bodies (review 2026-08-24 §3.1).
|
|
331
331
|
*/
|
|
332
332
|
export function renderSubcommandUsage(name) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { AgentRunner } from "../agent/types.js";
|
|
2
|
-
import type { RuntimeCommandName } from "../commands/catalog.js";
|
|
3
2
|
import type { SubAgentRunManager } from "../subagents/runs.js";
|
|
4
|
-
import type {
|
|
3
|
+
import type { RuntimeCommandName } from "./catalog.js";
|
|
5
4
|
/**
|
|
6
5
|
* The stateless report commands (`/events /tasks /status /usage /context /subagents /project
|
|
7
6
|
* /skills`) as one transport-neutral handler. The DingTalk runtime and the terminal TUI both route
|
|
@@ -9,9 +8,17 @@ import type { BootstrapPaths } from "./app-home.js";
|
|
|
9
8
|
* transport supplies only what is genuinely its own (how to find its runner, how to rebuild one
|
|
10
9
|
* after `/project`, whether a task can be woken immediately).
|
|
11
10
|
*/
|
|
11
|
+
/** The path fields the reports read; structurally satisfied by the app's `BootstrapPaths`. */
|
|
12
|
+
export interface ReportCommandPaths {
|
|
13
|
+
workspaceDir: string;
|
|
14
|
+
appHomeDir: string;
|
|
15
|
+
eventHistoryPath: string;
|
|
16
|
+
authConfigPath: string;
|
|
17
|
+
modelsConfigPath: string;
|
|
18
|
+
}
|
|
12
19
|
export interface ReportCommandContext {
|
|
13
20
|
channelId: string;
|
|
14
|
-
paths:
|
|
21
|
+
paths: ReportCommandPaths;
|
|
15
22
|
actor: "dingtalk-command" | "tui-command";
|
|
16
23
|
version: string;
|
|
17
24
|
startedAt: number;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { renderStatus } from "../agent/status-render.js";
|
|
2
2
|
import { getChannelDir } from "../channel/channel-paths.js";
|
|
3
|
-
import {
|
|
3
|
+
import { handleProjectCommand } from "../channel/commands.js";
|
|
4
|
+
import { handleEventsCommand } from "../events/commands.js";
|
|
5
|
+
import { handleSkillsCommand } from "../skills/commands.js";
|
|
6
|
+
import { handleSubagentsCommand } from "../subagents/commands.js";
|
|
4
7
|
import { loadDetachedSubAgentDiscovery } from "../subagents/detached-discovery.js";
|
|
8
|
+
import { handleTasksCommand } from "../tasks/commands.js";
|
|
5
9
|
import { getUsageLedger } from "../usage/ledger.js";
|
|
6
10
|
import { parseUsageMode, renderUsageReport } from "../usage/render.js";
|
|
7
|
-
import { handleProjectCommand } from "./project-commands.js";
|
|
8
|
-
import { handleSkillsCommand } from "./skill-commands.js";
|
|
9
|
-
import { handleSubagentsCommand } from "./subagent-commands.js";
|
|
10
|
-
import { handleTasksCommand } from "./task-commands.js";
|
|
11
11
|
export async function runReportCommand(context, name, args) {
|
|
12
12
|
const { channelId, paths } = context;
|
|
13
13
|
const channelDir = getChannelDir(paths.workspaceDir, channelId);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/** Settings management for pipiclaw: `settings.json` (product intent only) and the code constants that replaced the retired knobs. */
|
|
2
2
|
import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
5
|
-
import type { ConfigDiagnostic } from "./shared/config-diagnostic.js";
|
|
3
|
+
import type { ResponseMode } from "../channel/channel-context.js";
|
|
4
|
+
import type { ConfigDiagnostic } from "../shared/config-diagnostic.js";
|
|
6
5
|
type SettingsError = {
|
|
7
6
|
scope: "global" | "project";
|
|
8
7
|
error: Error;
|
|
@@ -27,9 +26,10 @@ export interface PipiclawTaskDriverSettings {
|
|
|
27
26
|
/** Cap on idle sleep between scans; also the upper bound on how late a manual edit is noticed. */
|
|
28
27
|
maxSleepMinutes: number;
|
|
29
28
|
}
|
|
30
|
-
|
|
29
|
+
/** Only the on/off switch is a setting; cadence constants live in `memory/maintenance-tuning.ts`. */
|
|
30
|
+
export interface PipiclawMemoryMaintenanceSettings {
|
|
31
31
|
enabled: boolean;
|
|
32
|
-
}
|
|
32
|
+
}
|
|
33
33
|
export interface PipiclawLoggingSettings {
|
|
34
34
|
level: "debug" | "info" | "warn" | "error";
|
|
35
35
|
file: {
|
|
@@ -100,9 +100,8 @@ export interface PipiclawSettings {
|
|
|
100
100
|
delegation?: Partial<PipiclawDelegationSettings>;
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
103
|
-
* Every top-level `settings.json` key
|
|
104
|
-
*
|
|
105
|
-
* list from drifting out of sync with `PipiclawSettings` itself: `satisfies` rejects an extra or
|
|
103
|
+
* Every top-level `settings.json` key. The two lines below keep this list from drifting out of
|
|
104
|
+
* sync with `PipiclawSettings` itself: `satisfies` rejects an extra or
|
|
106
105
|
* misspelled entry, and the `AssertNoMissingKeys` check rejects an interface field with no entry
|
|
107
106
|
* here — both at `npm run typecheck`, not by trusting a human to update two places together.
|
|
108
107
|
*/
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
/** Settings management for pipiclaw: `settings.json` (product intent only) and the code constants that replaced the retired knobs. */
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync } from "fs";
|
|
3
3
|
import { dirname, join } from "path";
|
|
4
|
-
import * as log from "
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { fileStamp } from "./shared/format.js";
|
|
4
|
+
import * as log from "../log.js";
|
|
5
|
+
import { writeFileAtomicallySync } from "../shared/atomic-file.js";
|
|
6
|
+
import { fileStamp } from "../shared/format.js";
|
|
8
7
|
/**
|
|
9
|
-
* Every top-level `settings.json` key
|
|
10
|
-
*
|
|
11
|
-
* list from drifting out of sync with `PipiclawSettings` itself: `satisfies` rejects an extra or
|
|
8
|
+
* Every top-level `settings.json` key. The two lines below keep this list from drifting out of
|
|
9
|
+
* sync with `PipiclawSettings` itself: `satisfies` rejects an extra or
|
|
12
10
|
* misspelled entry, and the `AssertNoMissingKeys` check rejects an interface field with no entry
|
|
13
11
|
* here — both at `npm run typecheck`, not by trusting a human to update two places together.
|
|
14
12
|
*/
|
|
@@ -163,8 +161,8 @@ function findRetiredSettingsKeys(parsed) {
|
|
|
163
161
|
* means an unrecognized value is dropped so the documented default applies, and the operator is
|
|
164
162
|
* told which key was ignored.
|
|
165
163
|
*
|
|
166
|
-
* The value lists are literal rather than imported: `
|
|
167
|
-
*
|
|
164
|
+
* The value lists are literal rather than imported: `config` may depend on `channel` for types
|
|
165
|
+
* only (a value import would tie settings loading to the channel module's runtime graph). The
|
|
168
166
|
* `satisfies` clauses keep them honest against the unions they mirror.
|
|
169
167
|
*/
|
|
170
168
|
const ENUM_SETTINGS = [
|
|
@@ -332,7 +330,6 @@ export class PipiclawSettingsManager {
|
|
|
332
330
|
}
|
|
333
331
|
getMemoryMaintenanceSettings() {
|
|
334
332
|
return {
|
|
335
|
-
...getMemoryMaintenanceTuning(),
|
|
336
333
|
enabled: this.settings.memoryMaintenance?.enabled ?? DEFAULT_MEMORY_MAINTENANCE_ENABLED,
|
|
337
334
|
};
|
|
338
335
|
}
|
|
@@ -52,8 +52,7 @@ export interface LoadedToolsConfig {
|
|
|
52
52
|
diagnostics: ConfigDiagnostic[];
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
|
-
* Every `tools.<key>` section in `tools.json
|
|
56
|
-
* to check that `docs/configuration-reference.md` still mentions each one. Kept in sync with
|
|
55
|
+
* Every `tools.<key>` section in `tools.json`. Kept in sync with
|
|
57
56
|
* `PipiclawToolsConfig["tools"]` by `satisfies` (rejects an extra/misspelled entry) and
|
|
58
57
|
* `AssertNoMissingKeys` (rejects a section with no entry here) — both at `npm run typecheck`.
|
|
59
58
|
*/
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `tools.json`: the web, rtk, task and inline-delegation tool settings — their types, defaults, the
|
|
3
|
+
* loader with diagnostics, and the path of the file.
|
|
4
|
+
*/
|
|
1
5
|
import { join } from "node:path";
|
|
2
6
|
import { APP_HOME_DIR } from "../paths.js";
|
|
3
7
|
import { loadJsonConfig, pushConfigWarning } from "../shared/config-diagnostic.js";
|
|
4
8
|
import { clampInteger } from "../shared/format.js";
|
|
5
9
|
import { isRecord } from "../shared/type-guards.js";
|
|
6
10
|
/**
|
|
7
|
-
* Every `tools.<key>` section in `tools.json
|
|
8
|
-
* to check that `docs/configuration-reference.md` still mentions each one. Kept in sync with
|
|
11
|
+
* Every `tools.<key>` section in `tools.json`. Kept in sync with
|
|
9
12
|
* `PipiclawToolsConfig["tools"]` by `satisfies` (rejects an extra/misspelled entry) and
|
|
10
13
|
* `AssertNoMissingKeys` (rejects a section with no entry here) — both at `npm run typecheck`.
|
|
11
14
|
*/
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class AccessTokenProvider {
|
|
2
|
+
private credentials;
|
|
3
|
+
private accessToken;
|
|
4
|
+
private tokenExpiry;
|
|
5
|
+
private tokenRefreshPromise;
|
|
6
|
+
constructor(credentials: {
|
|
7
|
+
clientId: string;
|
|
8
|
+
clientSecret: string;
|
|
9
|
+
});
|
|
10
|
+
get(): Promise<string | null>;
|
|
11
|
+
private refresh;
|
|
12
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** App access token cache: one token shared by every DingTalk host, refreshed on demand. */
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import * as log from "../log.js";
|
|
4
|
+
import { errorMessage } from "../shared/text-utils.js";
|
|
5
|
+
import { DINGTALK_API, http } from "./api.js";
|
|
6
|
+
export class AccessTokenProvider {
|
|
7
|
+
constructor(credentials) {
|
|
8
|
+
this.credentials = credentials;
|
|
9
|
+
this.accessToken = null;
|
|
10
|
+
this.tokenExpiry = 0;
|
|
11
|
+
this.tokenRefreshPromise = null;
|
|
12
|
+
}
|
|
13
|
+
async get() {
|
|
14
|
+
if (this.accessToken && Date.now() / 1000 < this.tokenExpiry) {
|
|
15
|
+
return this.accessToken;
|
|
16
|
+
}
|
|
17
|
+
// Coalesce concurrent refresh requests into a single HTTP call
|
|
18
|
+
if (!this.tokenRefreshPromise) {
|
|
19
|
+
this.tokenRefreshPromise = this.refresh().finally(() => {
|
|
20
|
+
this.tokenRefreshPromise = null;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return this.tokenRefreshPromise;
|
|
24
|
+
}
|
|
25
|
+
async refresh() {
|
|
26
|
+
try {
|
|
27
|
+
const resp = await http.post(`${DINGTALK_API}/v1.0/oauth2/accessToken`, {
|
|
28
|
+
appKey: this.credentials.clientId,
|
|
29
|
+
appSecret: this.credentials.clientSecret,
|
|
30
|
+
}, {
|
|
31
|
+
headers: { "Content-Type": "application/json" },
|
|
32
|
+
});
|
|
33
|
+
const data = resp.data;
|
|
34
|
+
this.accessToken = data.accessToken || null;
|
|
35
|
+
this.tokenExpiry = Date.now() / 1000 + (data.expireIn || 7200) - 60;
|
|
36
|
+
return this.accessToken;
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
if (axios.isAxiosError(err) && err.response) {
|
|
40
|
+
log.logWarn("dingtalk.token.failed", "Access token request failed", {
|
|
41
|
+
reason: JSON.stringify(err.response.data),
|
|
42
|
+
fields: { status: err.response.status },
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
log.logWarn("dingtalk.token.failed", "Access token request failed", { reason: errorMessage(err) });
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DingTalkConfig } from "./config.js";
|
|
2
|
+
export declare const DINGTALK_API = "https://api.dingtalk.com";
|
|
3
|
+
export declare const DINGTALK_OAPI = "https://oapi.dingtalk.com";
|
|
4
|
+
export declare const http: import("axios").AxiosInstance;
|
|
5
|
+
/** Where a channel's messages go: enough to pick the DM-vs-group endpoint and the recipient. */
|
|
6
|
+
export interface ConversationMeta {
|
|
7
|
+
conversationId: string;
|
|
8
|
+
conversationType: string;
|
|
9
|
+
senderId: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* POST a robot message with an arbitrary msgKey/msgParam, routing DM vs group
|
|
13
|
+
* to the correct endpoint. The single outbound path for every non-card message:
|
|
14
|
+
* plain text/markdown, images, and files.
|
|
15
|
+
*/
|
|
16
|
+
export declare function sendRobotMessage(deps: {
|
|
17
|
+
config: DingTalkConfig;
|
|
18
|
+
getAccessToken: () => Promise<string | null>;
|
|
19
|
+
}, meta: ConversationMeta, msgKey: string, msgParam: string): Promise<boolean>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Low-level DingTalk HTTP: the shared axios instance, the two API hosts, and the one POST that
|
|
3
|
+
* delivers every non-card robot message (plain text/markdown, images, files).
|
|
4
|
+
*/
|
|
5
|
+
import axios from "axios";
|
|
6
|
+
import * as log from "../log.js";
|
|
7
|
+
import { errorMessage } from "../shared/text-utils.js";
|
|
8
|
+
export const DINGTALK_API = "https://api.dingtalk.com";
|
|
9
|
+
// Media upload lives on the legacy oapi host, not the v1.0 api host. It returns a
|
|
10
|
+
// reusable `media_id` that the v1.0 robot send endpoints reference (photoURL /
|
|
11
|
+
// mediaId). The `access_token` query param is the same app access token minted by
|
|
12
|
+
// `/v1.0/oauth2/accessToken` — DingTalk unified the internal-app token across both
|
|
13
|
+
// hosts — so the one `AccessTokenProvider` is reused rather than fetching a second token.
|
|
14
|
+
export const DINGTALK_OAPI = "https://oapi.dingtalk.com";
|
|
15
|
+
// Bound every outbound DingTalk HTTP call. Without this, axios waits forever on a
|
|
16
|
+
// hung connection, and a stalled card-streaming request would wedge the delivery
|
|
17
|
+
// sync loop (never resolving flush()), leaving the whole channel permanently busy.
|
|
18
|
+
// A timeout turns "hang" into a normal failure that the existing fallback paths
|
|
19
|
+
// (bounded snapshot replay / sendPlain) already handle.
|
|
20
|
+
const DINGTALK_HTTP_TIMEOUT_MS = 15_000;
|
|
21
|
+
export const http = axios.create({ timeout: DINGTALK_HTTP_TIMEOUT_MS });
|
|
22
|
+
/**
|
|
23
|
+
* POST a robot message with an arbitrary msgKey/msgParam, routing DM vs group
|
|
24
|
+
* to the correct endpoint. The single outbound path for every non-card message:
|
|
25
|
+
* plain text/markdown, images, and files.
|
|
26
|
+
*/
|
|
27
|
+
export async function sendRobotMessage(deps, meta, msgKey, msgParam) {
|
|
28
|
+
const token = await deps.getAccessToken();
|
|
29
|
+
if (!token)
|
|
30
|
+
return false;
|
|
31
|
+
const robotCode = deps.config.robotCode || deps.config.clientId;
|
|
32
|
+
const isGroup = meta.conversationType === "2";
|
|
33
|
+
const url = isGroup
|
|
34
|
+
? `${DINGTALK_API}/v1.0/robot/groupMessages/send`
|
|
35
|
+
: `${DINGTALK_API}/v1.0/robot/oToMessages/batchSend`;
|
|
36
|
+
const body = { robotCode, msgKey, msgParam };
|
|
37
|
+
if (isGroup) {
|
|
38
|
+
body.openConversationId = meta.conversationId;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
body.userIds = [meta.senderId];
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
await http.post(url, body, {
|
|
45
|
+
headers: {
|
|
46
|
+
"x-acs-dingtalk-access-token": token,
|
|
47
|
+
"Content-Type": "application/json",
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
if (axios.isAxiosError(err) && err.response) {
|
|
54
|
+
log.logWarn("dingtalk.send.failed", "Message send failed", {
|
|
55
|
+
reason: JSON.stringify(err.response.data),
|
|
56
|
+
fields: { msgKey, status: err.response.status },
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
log.logWarn("dingtalk.send.failed", "Message send failed", {
|
|
61
|
+
reason: errorMessage(err),
|
|
62
|
+
fields: { msgKey },
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DingTalk transport facade: owns the per-channel queues and the public surface the runtime and the
|
|
3
|
+
* delivery controller call. The Stream socket, access token, AI cards, media and inbound parsing
|
|
4
|
+
* are separate collaborators (`connection.ts`, `access-token.ts`, `cards.ts`, `media.ts`,
|
|
5
|
+
* `inbound.ts`) that this class wires together and forwards to.
|
|
6
|
+
*/
|
|
7
|
+
import { type FinalDelivery, type MediaSender, type MediaSendResult, type OutboundMedia, type ProgressStyle, type ResponseMode } from "../channel/channel-context.js";
|
|
8
|
+
import type { ChannelEventSink } from "../channel/channel-event.js";
|
|
9
|
+
import { type BusyMessageMode, type DingTalkConfig } from "./config.js";
|
|
10
|
+
import type { DingTalkBotPort, DingTalkEvent, DingTalkHandler } from "./handler.js";
|
|
11
|
+
export declare class DingTalkBot implements MediaSender, ChannelEventSink, DingTalkBotPort {
|
|
12
|
+
private handler;
|
|
13
|
+
private config;
|
|
14
|
+
private tokens;
|
|
15
|
+
private conversations;
|
|
16
|
+
private cards;
|
|
17
|
+
private media;
|
|
18
|
+
private inbound;
|
|
19
|
+
private connection;
|
|
20
|
+
private channelLastActiveAt;
|
|
21
|
+
private queues;
|
|
22
|
+
private channelCacheSweepTimer;
|
|
23
|
+
private isStopped;
|
|
24
|
+
constructor(handler: DingTalkHandler, config: DingTalkConfig);
|
|
25
|
+
get busyMessageDefault(): BusyMessageMode;
|
|
26
|
+
get responseMode(): ResponseMode;
|
|
27
|
+
get progressStyle(): ProgressStyle;
|
|
28
|
+
get finalDelivery(): FinalDelivery;
|
|
29
|
+
start(): Promise<void>;
|
|
30
|
+
stop(): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Enqueue an event for processing.
|
|
33
|
+
* Returns true if enqueued, false if queue is full (max 5).
|
|
34
|
+
*/
|
|
35
|
+
enqueueEvent(event: DingTalkEvent): boolean;
|
|
36
|
+
private enqueueStreamMessage;
|
|
37
|
+
/** Capture the current turn's identity; close, /stop and /new invalidate it. */
|
|
38
|
+
getCardGeneration(channelId: string): symbol;
|
|
39
|
+
isCardGenerationCurrent(channelId: string, generation: symbol): boolean;
|
|
40
|
+
/** Get or create an AI card without joining an earlier turn's in-flight creation. */
|
|
41
|
+
ensureCard(channelId: string, generation?: symbol): Promise<void>;
|
|
42
|
+
/** Replace the active card content with a full snapshot. */
|
|
43
|
+
replaceCard(channelId: string, content: string, finalize?: boolean, failed?: boolean, generation?: symbol): Promise<boolean>;
|
|
44
|
+
/** Append a delta to the active card transcript. */
|
|
45
|
+
appendToCard(channelId: string, content: string, finalize?: boolean, failed?: boolean, generation?: symbol): Promise<boolean>;
|
|
46
|
+
/** Finalize and remove the active card for a channel. */
|
|
47
|
+
finalizeCard(channelId: string, content: string, generation?: symbol): Promise<boolean>;
|
|
48
|
+
/** Finish progress only: never create a card or send a fallback chat message. */
|
|
49
|
+
finalizeExistingCard(channelId: string, content: string, generation?: symbol): Promise<boolean>;
|
|
50
|
+
/** Invalidate this turn's local state. This is not a remote message deletion. */
|
|
51
|
+
discardCard(channelId: string, generation?: symbol): void;
|
|
52
|
+
/**
|
|
53
|
+
* Send a normal message natively mapping DM and Group to correct endpoints (fallback when no card).
|
|
54
|
+
*
|
|
55
|
+
* Only the message shape is decided here; the DM-vs-group routing and the POST itself belong to
|
|
56
|
+
* `sendRobotMessage`, which every other outbound message type already goes through.
|
|
57
|
+
*
|
|
58
|
+
* `opts` lets a caller that already knows what it produced (a command reply) state the format
|
|
59
|
+
* and a real title instead of the regex guess below, which exists only for callers — free-form
|
|
60
|
+
* notices, `replaceWithFinal` — that do not know their own content ahead of time (review
|
|
61
|
+
* 2026-08-24 §1.3c).
|
|
62
|
+
*/
|
|
63
|
+
sendPlain(channelId: string, text: string, opts?: {
|
|
64
|
+
title?: string;
|
|
65
|
+
markdown?: boolean;
|
|
66
|
+
}): Promise<boolean>;
|
|
67
|
+
sendMedia(channelId: string, media: OutboundMedia): Promise<MediaSendResult>;
|
|
68
|
+
/**
|
|
69
|
+
* Inbound file fetch used while resolving attachments (`media.ts`). `protected` so the
|
|
70
|
+
* deterministic e2e harness can override it and run the inbound path with zero network, the
|
|
71
|
+
* same pattern `HarnessDingTalkBot` already uses for outbound calls.
|
|
72
|
+
*/
|
|
73
|
+
protected downloadMessageFile(downloadCode: string): Promise<{
|
|
74
|
+
data: Buffer;
|
|
75
|
+
} | null>;
|
|
76
|
+
/**
|
|
77
|
+
* Command / busy / `/new` routing for one inbound event, ending in `enqueueStreamMessage`
|
|
78
|
+
* for a normal message. Split out of `onStreamMessage` so the deterministic e2e harness
|
|
79
|
+
* (spec 048) can exercise the real transport queue and busy semantics without a socket.
|
|
80
|
+
*/
|
|
81
|
+
routeInboundEvent(event: DingTalkEvent): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Drop queued-but-not-started messages for a channel (e.g. on /stop) so they
|
|
84
|
+
* do not run after the user halts the current task. Returns dropped count.
|
|
85
|
+
*/
|
|
86
|
+
clearPendingMessages(channelId: string): number;
|
|
87
|
+
/**
|
|
88
|
+
* Detach all queued work from the previous session generation. The in-flight callback may
|
|
89
|
+
* still unwind on its old queue object, while subsequent messages get a fresh queue.
|
|
90
|
+
*/
|
|
91
|
+
resetChannelQueue(channelId: string): number;
|
|
92
|
+
/** Test seam (spec 048): true when no channel queue has pending or in-flight work. */
|
|
93
|
+
allChannelQueuesIdle(): boolean;
|
|
94
|
+
private getQueue;
|
|
95
|
+
private touchChannel;
|
|
96
|
+
private cleanupIdleChannelCaches;
|
|
97
|
+
}
|