@oyasmi/pipiclaw 0.9.4-beta.2 → 0.9.5-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 +28 -22
- package/README.md +27 -21
- package/dist/agent/builtin-commands.d.ts +7 -2
- package/dist/agent/builtin-commands.js +19 -23
- package/dist/agent/channel-runner.d.ts +13 -13
- package/dist/agent/channel-runner.js +93 -76
- package/dist/agent/maintenance-context.d.ts +6 -5
- package/dist/agent/maintenance-context.js +15 -15
- package/dist/agent/prompt/manifest.js +1 -1
- package/dist/agent/prompt/resources.d.ts +1 -1
- package/dist/agent/prompt/resources.js +1 -1
- package/dist/agent/prompt/sections.js +4 -4
- package/dist/agent/runner-factory.d.ts +6 -6
- package/dist/agent/runner-factory.js +6 -7
- package/dist/agent/session/compaction-input.d.ts +6 -0
- package/dist/agent/session/compaction-input.js +75 -0
- package/dist/agent/session/compaction-snapshot.d.ts +30 -0
- package/dist/agent/session/compaction-snapshot.js +154 -0
- package/dist/agent/session/compaction-summary.d.ts +39 -0
- package/dist/agent/session/compaction-summary.js +158 -0
- package/dist/agent/session/compaction.d.ts +35 -0
- package/dist/agent/session/compaction.js +294 -0
- package/dist/agent/session/context-input.d.ts +15 -0
- package/dist/agent/session/context-input.js +82 -0
- package/dist/agent/session/context-snapshot.d.ts +11 -0
- package/dist/agent/session/context-snapshot.js +72 -0
- package/dist/agent/session/event-guards.d.ts +2 -0
- package/dist/agent/session/event-guards.js +4 -0
- package/dist/agent/session/request-tools.d.ts +3 -0
- package/dist/agent/session/request-tools.js +20 -0
- package/dist/agent/session/session-adapter.d.ts +2 -1
- package/dist/agent/session/session-adapter.js +6 -3
- package/dist/agent/session/session-events.d.ts +5 -4
- package/dist/agent/session/session-events.js +46 -59
- package/dist/agent/session/session-host.d.ts +29 -41
- package/dist/agent/session/session-host.js +86 -69
- package/dist/agent/session/settings-diagnostics.d.ts +5 -0
- package/dist/agent/session/settings-diagnostics.js +21 -0
- package/dist/agent/status-render.js +5 -2
- package/dist/{runtime → agent}/stop-watchdog.d.ts +3 -1
- package/dist/{runtime → agent}/stop-watchdog.js +7 -3
- package/dist/agent/turn/progress-formatter.d.ts +1 -3
- package/dist/agent/turn/progress-formatter.js +3 -22
- package/dist/agent/turn/task-digest.d.ts +4 -2
- package/dist/agent/turn/task-digest.js +7 -4
- package/dist/agent/turn/turn-context.d.ts +11 -7
- package/dist/agent/turn/turn-context.js +26 -18
- package/dist/agent/turn/turn-finish.d.ts +17 -5
- package/dist/agent/turn/turn-finish.js +51 -77
- package/dist/agent/turn/turn-input.d.ts +2 -2
- package/dist/agent/turn/turn-input.js +4 -3
- package/dist/agent/turn/turn-output.d.ts +19 -0
- package/dist/agent/turn/turn-output.js +41 -0
- package/dist/agent/turn/turn-pipeline.d.ts +11 -8
- package/dist/agent/turn/turn-pipeline.js +54 -55
- package/dist/agent/turn/turn-prompt.d.ts +1 -1
- package/dist/agent/turn/turn-recovery.d.ts +11 -10
- package/dist/agent/turn/turn-recovery.js +14 -29
- package/dist/agent/types.d.ts +31 -12
- package/dist/agent/types.js +2 -1
- package/dist/app/auth-command.js +1 -1
- package/dist/app/home.js +31 -15
- package/dist/channel/active-session-store.d.ts +14 -12
- package/dist/channel/active-session-store.js +29 -25
- package/dist/channel/attachments.d.ts +25 -0
- package/dist/channel/attachments.js +56 -0
- package/dist/channel/channel-context.d.ts +87 -96
- package/dist/channel/channel-context.js +1 -66
- package/dist/channel/channel-event.d.ts +51 -41
- package/dist/channel/channel-event.js +6 -11
- package/dist/channel/channel-id.d.ts +22 -0
- package/dist/channel/channel-id.js +13 -0
- package/dist/channel/channel-index.d.ts +17 -34
- package/dist/channel/channel-index.js +41 -80
- package/dist/channel/config.d.ts +10 -0
- package/dist/channel/config.js +55 -0
- package/dist/channel/ingress.d.ts +101 -0
- package/dist/channel/ingress.js +5 -0
- package/dist/channel/store.d.ts +13 -15
- package/dist/channel/store.js +21 -25
- package/dist/channel/transport.d.ts +99 -0
- package/dist/channel/turn-context.d.ts +23 -0
- package/dist/channel/turn-context.js +1 -0
- package/dist/commands/catalog.d.ts +4 -7
- package/dist/commands/catalog.js +24 -31
- package/dist/commands/router.d.ts +23 -12
- package/dist/commands/router.js +22 -24
- package/dist/config/settings.d.ts +5 -4
- package/dist/desk/bindings.d.ts +6 -0
- package/dist/desk/bindings.js +105 -0
- package/dist/desk/commands.d.ts +81 -0
- package/dist/desk/commands.js +145 -0
- package/dist/desk/default.d.ts +4 -0
- package/dist/desk/default.js +11 -0
- package/dist/desk/paths.d.ts +41 -0
- package/dist/desk/paths.js +81 -0
- package/dist/desk/registry.d.ts +17 -0
- package/dist/desk/registry.js +191 -0
- package/dist/desk/startup-error.d.ts +4 -0
- package/dist/desk/startup-error.js +7 -0
- package/dist/desk/types.d.ts +72 -0
- package/dist/desk/types.js +7 -0
- package/dist/dingtalk/bot.d.ts +18 -35
- package/dist/dingtalk/bot.js +21 -204
- package/dist/dingtalk/channel-ids.d.ts +15 -0
- package/dist/dingtalk/channel-ids.js +39 -0
- package/dist/dingtalk/config.d.ts +6 -3
- package/dist/dingtalk/config.js +13 -25
- package/dist/dingtalk/connection.d.ts +1 -0
- package/dist/dingtalk/connection.js +5 -4
- package/dist/dingtalk/conversation-meta.d.ts +10 -5
- package/dist/dingtalk/conversation-meta.js +72 -50
- package/dist/dingtalk/delivery.d.ts +30 -14
- package/dist/dingtalk/delivery.js +189 -62
- package/dist/dingtalk/inbound-media.d.ts +2 -18
- package/dist/dingtalk/inbound-media.js +0 -53
- package/dist/dingtalk/inbound.d.ts +10 -11
- package/dist/dingtalk/inbound.js +12 -19
- package/dist/dingtalk/media.d.ts +9 -11
- package/dist/dingtalk/media.js +18 -31
- package/dist/dingtalk/progress.d.ts +8 -0
- package/dist/dingtalk/progress.js +20 -0
- package/dist/dingtalk/response-mode.d.ts +13 -0
- package/dist/dingtalk/response-mode.js +31 -0
- package/dist/dingtalk/transport.d.ts +47 -0
- package/dist/dingtalk/transport.js +71 -0
- package/dist/events/commands.d.ts +7 -2
- package/dist/events/commands.js +40 -22
- package/dist/events/pre-action-error.d.ts +10 -0
- package/dist/events/pre-action-error.js +10 -0
- package/dist/events/types.d.ts +20 -2
- package/dist/events/watcher.d.ts +14 -7
- package/dist/events/watcher.js +49 -26
- package/dist/index.d.ts +4 -2
- package/dist/jobs/completion-wake.d.ts +14 -0
- package/dist/jobs/completion-wake.js +36 -0
- package/dist/jobs/manager.d.ts +27 -22
- package/dist/jobs/manager.js +58 -91
- package/dist/jobs/record.d.ts +2 -0
- package/dist/jobs/record.js +2 -0
- package/dist/log.d.ts +0 -1
- package/dist/log.js +1 -1
- package/dist/main.js +10 -3
- package/dist/memory/boundary-work.d.ts +17 -0
- package/dist/memory/boundary-work.js +162 -0
- package/dist/memory/commands.d.ts +4 -3
- package/dist/memory/commands.js +16 -16
- package/dist/memory/desk-memory-queue.d.ts +18 -0
- package/dist/memory/desk-memory-queue.js +33 -0
- package/dist/memory/index-budget.d.ts +3 -3
- package/dist/memory/index-budget.js +3 -3
- package/dist/memory/journal.d.ts +6 -6
- package/dist/memory/journal.js +14 -14
- package/dist/memory/lifecycle.d.ts +14 -21
- package/dist/memory/lifecycle.js +73 -103
- package/dist/memory/maintenance-state.d.ts +14 -15
- package/dist/memory/maintenance-state.js +43 -42
- package/dist/memory/reflect-job.d.ts +5 -4
- package/dist/memory/reflect-job.js +21 -15
- package/dist/memory/reflect.d.ts +2 -1
- package/dist/memory/reflect.js +13 -12
- package/dist/memory/render.d.ts +1 -1
- package/dist/memory/render.js +2 -2
- package/dist/memory/review-log.d.ts +4 -4
- package/dist/memory/review-log.js +5 -5
- package/dist/memory/scheduler.d.ts +12 -19
- package/dist/memory/scheduler.js +28 -64
- package/dist/memory/session-corpus.d.ts +4 -1
- package/dist/memory/session-corpus.js +70 -29
- package/dist/memory/session-search.d.ts +11 -3
- package/dist/memory/session-search.js +14 -11
- package/dist/memory/sidecar-worker.d.ts +1 -0
- package/dist/memory/sidecar-worker.js +57 -76
- package/dist/memory/source-window.d.ts +0 -6
- package/dist/memory/source-window.js +0 -20
- package/dist/memory/store.d.ts +12 -12
- package/dist/memory/store.js +44 -44
- package/dist/paths.d.ts +2 -0
- package/dist/paths.js +2 -0
- package/dist/playbooks/agent-delegation.md +16 -16
- package/dist/playbooks/background-jobs.md +5 -3
- package/dist/playbooks/event-scheduling.md +7 -5
- package/dist/playbooks/memory-and-learning.md +16 -12
- package/dist/playbooks/outbound-media.md +1 -1
- package/dist/playbooks/runtime-orientation.md +35 -23
- package/dist/playbooks/task-lead.md +13 -11
- package/dist/runtime/bootstrap.d.ts +36 -13
- package/dist/runtime/bootstrap.js +310 -138
- package/dist/runtime/channel-queue.d.ts +23 -0
- package/dist/{dingtalk → runtime}/channel-queue.js +20 -9
- package/dist/runtime/daemon-lock.d.ts +12 -0
- package/dist/runtime/daemon-lock.js +28 -0
- package/dist/runtime/desk-runtime.d.ts +131 -0
- package/dist/runtime/desk-runtime.js +402 -0
- package/dist/runtime/durable-dispatch.d.ts +11 -5
- package/dist/runtime/durable-dispatch.js +20 -8
- package/dist/runtime/inbound-images.d.ts +32 -10
- package/dist/runtime/inbound-images.js +95 -21
- package/dist/runtime/ingress-busy.d.ts +26 -0
- package/dist/runtime/ingress-busy.js +211 -0
- package/dist/runtime/ingress-commands.d.ts +7 -0
- package/dist/runtime/ingress-commands.js +162 -0
- package/dist/runtime/ingress-deps.d.ts +62 -0
- package/dist/runtime/ingress-deps.js +1 -0
- package/dist/runtime/ingress.d.ts +22 -0
- package/dist/runtime/ingress.js +376 -0
- package/dist/runtime/request-execution.d.ts +19 -0
- package/dist/runtime/request-execution.js +88 -0
- package/dist/runtime/shutdown.d.ts +13 -5
- package/dist/runtime/shutdown.js +10 -4
- package/dist/runtime/task-driver.d.ts +38 -22
- package/dist/runtime/task-driver.js +142 -116
- package/dist/runtime/task-spawn.d.ts +4 -4
- package/dist/runtime/task-spawn.js +6 -5
- package/dist/runtime/task-wake.d.ts +6 -4
- package/dist/runtime/task-wake.js +7 -7
- package/dist/runtime/transports.d.ts +32 -0
- package/dist/runtime/transports.js +101 -0
- package/dist/runtime/turn-run.d.ts +18 -9
- package/dist/runtime/turn-run.js +302 -71
- package/dist/runtime/wake-coalescing.d.ts +11 -3
- package/dist/runtime/wake-coalescing.js +10 -0
- package/dist/security/config.js +5 -10
- package/dist/security/logger.js +1 -1
- package/dist/security/path-guard.js +7 -63
- package/dist/security/types.d.ts +27 -30
- package/dist/security/types.js +0 -1
- package/dist/shared/atomic-file.d.ts +2 -0
- package/dist/shared/atomic-file.js +14 -1
- package/dist/shared/file-lock.d.ts +35 -0
- package/dist/shared/file-lock.js +195 -0
- package/dist/shared/with-timeout.d.ts +2 -0
- package/dist/shared/with-timeout.js +21 -0
- package/dist/skills/loader.d.ts +1 -1
- package/dist/skills/loader.js +2 -2
- package/dist/skills/workspace.js +2 -2
- package/dist/subagents/completion-wake.d.ts +11 -2
- package/dist/subagents/completion-wake.js +22 -9
- package/dist/subagents/discovery.js +1 -1
- package/dist/subagents/dispatch.d.ts +0 -10
- package/dist/subagents/dispatch.js +10 -28
- package/dist/subagents/external/dispatch.js +1 -1
- package/dist/subagents/external/run.d.ts +1 -1
- package/dist/subagents/external/run.js +3 -3
- package/dist/subagents/internal/run.js +1 -1
- package/dist/subagents/internal/worker.js +6 -14
- package/dist/subagents/run-archive.d.ts +11 -0
- package/dist/subagents/run-archive.js +49 -0
- package/dist/subagents/run-record.d.ts +9 -8
- package/dist/subagents/run-record.js +3 -3
- package/dist/subagents/run-registry.d.ts +5 -3
- package/dist/subagents/run-registry.js +22 -45
- package/dist/subagents/runs.d.ts +23 -13
- package/dist/subagents/runs.js +75 -82
- package/dist/subagents/task-envelope.js +9 -11
- package/dist/subagents/types.d.ts +6 -5
- package/dist/tasks/board.d.ts +1 -1
- package/dist/tasks/board.js +2 -2
- package/dist/tasks/bound-work.d.ts +2 -2
- package/dist/tasks/bound-work.js +7 -7
- package/dist/tasks/brief.d.ts +1 -1
- package/dist/tasks/brief.js +9 -9
- package/dist/tasks/commands.d.ts +11 -2
- package/dist/tasks/commands.js +66 -41
- package/dist/tasks/contract.d.ts +0 -2
- package/dist/tasks/contract.js +1 -3
- package/dist/tasks/create.d.ts +3 -1
- package/dist/tasks/create.js +10 -4
- package/dist/tasks/frontmatter.d.ts +6 -2
- package/dist/tasks/frontmatter.js +10 -10
- package/dist/tasks/loop-log.d.ts +7 -13
- package/dist/tasks/loop-log.js +14 -17
- package/dist/tasks/mutation-lock.d.ts +7 -5
- package/dist/tasks/mutation-lock.js +32 -9
- package/dist/tasks/session-path.d.ts +3 -3
- package/dist/tasks/session-path.js +5 -5
- package/dist/tasks/steer.d.ts +5 -5
- package/dist/tasks/steer.js +42 -40
- package/dist/tasks/store.d.ts +11 -11
- package/dist/tasks/store.js +32 -29
- package/dist/tools/bash.d.ts +5 -5
- package/dist/tools/bash.js +19 -18
- package/dist/tools/contract/names.d.ts +7 -0
- package/dist/tools/contract/names.js +22 -0
- package/dist/tools/edit.js +1 -1
- package/dist/tools/event-manage.d.ts +3 -1
- package/dist/tools/event-manage.js +34 -33
- package/dist/tools/glob.js +5 -5
- package/dist/tools/grep.js +2 -2
- package/dist/tools/index.d.ts +9 -8
- package/dist/tools/index.js +12 -16
- package/dist/tools/job.d.ts +4 -2
- package/dist/tools/job.js +11 -8
- package/dist/tools/memory-manage.d.ts +5 -3
- package/dist/tools/memory-manage.js +24 -24
- package/dist/tools/read.js +1 -1
- package/dist/tools/registry.d.ts +12 -8
- package/dist/tools/registry.js +13 -9
- package/dist/tools/send-media.d.ts +2 -2
- package/dist/tools/send-media.js +3 -3
- package/dist/tools/session-search.d.ts +3 -1
- package/dist/tools/session-search.js +8 -6
- package/dist/tools/subagent-manage.d.ts +2 -8
- package/dist/tools/subagent-manage.js +19 -15
- package/dist/tools/subagent.js +1 -1
- package/dist/tools/task-manage/create.js +1 -1
- package/dist/tools/task-manage/factory.js +2 -2
- package/dist/tools/task-manage/lifecycle.js +3 -1
- 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 +8 -3
- package/dist/tools/web-cache.d.ts +3 -3
- package/dist/tools/web-cache.js +12 -12
- package/dist/tools/web-fetch.d.ts +2 -2
- package/dist/tools/web-fetch.js +7 -7
- package/dist/tools/write-content.js +1 -1
- package/dist/tui/cli.d.ts +17 -5
- package/dist/tui/cli.js +90 -27
- package/dist/tui/client.d.ts +26 -0
- package/dist/tui/client.js +157 -0
- package/dist/tui/colors.d.ts +0 -1
- package/dist/tui/colors.js +0 -1
- package/dist/tui/commands.d.ts +10 -51
- package/dist/tui/commands.js +16 -39
- package/dist/tui/frontend.d.ts +2 -2
- package/dist/tui/frontend.js +2 -2
- package/dist/tui/pitui-frontend.d.ts +0 -2
- package/dist/tui/pitui-frontend.js +1 -6
- package/dist/tui/render.d.ts +62 -0
- package/dist/tui/render.js +123 -0
- package/dist/tui/session.d.ts +92 -0
- package/dist/tui/session.js +317 -0
- package/dist/usage/ledger.d.ts +5 -0
- package/dist/usage/ledger.js +2 -0
- package/dist/usage/render.d.ts +6 -1
- package/dist/usage/render.js +18 -13
- package/dist/webapi/auth.d.ts +13 -0
- package/dist/webapi/auth.js +29 -0
- package/dist/webapi/config.d.ts +29 -0
- package/dist/webapi/config.js +100 -0
- package/dist/webapi/errors.d.ts +39 -0
- package/dist/webapi/errors.js +32 -0
- package/dist/webapi/http.d.ts +25 -0
- package/dist/webapi/http.js +4 -0
- package/dist/webapi/ids.d.ts +9 -0
- package/dist/webapi/ids.js +20 -0
- package/dist/webapi/input.d.ts +17 -0
- package/dist/webapi/input.js +229 -0
- package/dist/webapi/items.d.ts +37 -0
- package/dist/webapi/items.js +48 -0
- package/dist/webapi/key-command.d.ts +2 -0
- package/dist/webapi/key-command.js +110 -0
- package/dist/webapi/limits.d.ts +47 -0
- package/dist/webapi/limits.js +48 -0
- package/dist/webapi/request-policy.d.ts +17 -0
- package/dist/webapi/request-policy.js +160 -0
- package/dist/webapi/response-record.d.ts +68 -0
- package/dist/webapi/response-record.js +58 -0
- package/dist/webapi/response-state.d.ts +90 -0
- package/dist/webapi/response-state.js +347 -0
- package/dist/webapi/routes/conversations.d.ts +8 -0
- package/dist/webapi/routes/conversations.js +80 -0
- package/dist/webapi/routes/models.d.ts +3 -0
- package/dist/webapi/routes/models.js +12 -0
- package/dist/webapi/routes/responses.d.ts +8 -0
- package/dist/webapi/routes/responses.js +118 -0
- package/dist/webapi/routes/websocket.d.ts +9 -0
- package/dist/webapi/routes/websocket.js +328 -0
- package/dist/webapi/server.d.ts +24 -0
- package/dist/webapi/server.js +229 -0
- package/dist/webapi/service.d.ts +130 -0
- package/dist/webapi/service.js +588 -0
- package/dist/webapi/store.d.ts +46 -0
- package/dist/webapi/store.js +245 -0
- package/dist/webapi/stream.d.ts +13 -0
- package/dist/webapi/stream.js +76 -0
- package/dist/webapi/transport.d.ts +43 -0
- package/dist/webapi/transport.js +100 -0
- package/package.json +9 -2
- package/dist/channel/channel-paths.d.ts +0 -16
- package/dist/channel/channel-paths.js +0 -53
- package/dist/channel/commands.d.ts +0 -32
- package/dist/channel/commands.js +0 -109
- package/dist/channel/project-scope-store.d.ts +0 -51
- package/dist/channel/project-scope-store.js +0 -112
- package/dist/dingtalk/channel-queue.d.ts +0 -19
- package/dist/dingtalk/handler.d.ts +0 -90
- package/dist/memory/channel-maintenance-queue.d.ts +0 -5
- package/dist/memory/channel-maintenance-queue.js +0 -8
- package/dist/runtime/task-migration.d.ts +0 -30
- package/dist/runtime/task-migration.js +0 -465
- package/dist/runtime/turn-handler.d.ts +0 -47
- package/dist/runtime/turn-handler.js +0 -318
- package/dist/security/project-scope.d.ts +0 -45
- package/dist/security/project-scope.js +0 -105
- package/dist/tui/app.d.ts +0 -16
- package/dist/tui/app.js +0 -166
- package/dist/tui/terminal-context.d.ts +0 -27
- package/dist/tui/terminal-context.js +0 -84
- package/dist/tui/terminal-media-sender.d.ts +0 -9
- package/dist/tui/terminal-media-sender.js +0 -15
- package/dist/tui/turn-controller.d.ts +0 -64
- package/dist/tui/turn-controller.js +0 -311
- /package/dist/{dingtalk/handler.js → channel/transport.js} +0 -0
|
@@ -4,14 +4,14 @@ import { SessionManager } from "@earendil-works/pi-coding-agent";
|
|
|
4
4
|
import { writeFileAtomically } from "../shared/atomic-file.js";
|
|
5
5
|
const REF_FILENAME = "active-session.json";
|
|
6
6
|
const DEFAULT_SESSION_FILENAME = "context.jsonl";
|
|
7
|
-
export function getActiveSessionRefPath(
|
|
8
|
-
return join(
|
|
7
|
+
export function getActiveSessionRefPath(conversationDir) {
|
|
8
|
+
return join(conversationDir, REF_FILENAME);
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
* The ref's `file` is opened for append under `
|
|
11
|
+
* The ref's `file` is opened for append under `conversationDir`, and the ref itself lives in a
|
|
12
12
|
* directory a chat participant can otherwise influence the contents of. Reject anything that
|
|
13
13
|
* isn't a plain, single-segment `.jsonl` name so this can never be used to open or create a file
|
|
14
|
-
* outside the
|
|
14
|
+
* outside the conversation directory.
|
|
15
15
|
*/
|
|
16
16
|
export function isValidSessionRefBasename(file) {
|
|
17
17
|
return (typeof file === "string" &&
|
|
@@ -23,8 +23,8 @@ export function isValidSessionRefBasename(file) {
|
|
|
23
23
|
file !== "." &&
|
|
24
24
|
file !== "..");
|
|
25
25
|
}
|
|
26
|
-
function readActiveSessionRef(
|
|
27
|
-
const refPath = getActiveSessionRefPath(
|
|
26
|
+
function readActiveSessionRef(conversationDir) {
|
|
27
|
+
const refPath = getActiveSessionRefPath(conversationDir);
|
|
28
28
|
if (!existsSync(refPath)) {
|
|
29
29
|
return undefined;
|
|
30
30
|
}
|
|
@@ -52,23 +52,27 @@ function readActiveSessionRef(channelDir) {
|
|
|
52
52
|
* that doesn't exist yet. Materializing this before `SessionManager.open()` closes the delay
|
|
53
53
|
* window described in spec 043 F4/D1.2 without touching SDK internals.
|
|
54
54
|
*/
|
|
55
|
-
function materializeSessionFile(
|
|
56
|
-
const target = join(
|
|
55
|
+
function materializeSessionFile(conversationDir, file) {
|
|
56
|
+
const target = join(conversationDir, file);
|
|
57
57
|
if (!existsSync(target)) {
|
|
58
58
|
closeSync(openSync(target, "a"));
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
-
* Resolves which session file a
|
|
63
|
-
*
|
|
62
|
+
* Resolves which session file a conversation should open (runner construction / restart), migrating a
|
|
63
|
+
* conversation with no ref to `context.jsonl` and materializing that file. Never writes the ref
|
|
64
64
|
* itself — a missing ref stays missing until a session-topology operation commits one.
|
|
65
65
|
*/
|
|
66
|
-
export function resolveActiveSessionFile(
|
|
67
|
-
const ref = readActiveSessionRef(
|
|
66
|
+
export function resolveActiveSessionFile(conversationDir) {
|
|
67
|
+
const ref = readActiveSessionRef(conversationDir);
|
|
68
68
|
const file = ref?.file ?? DEFAULT_SESSION_FILENAME;
|
|
69
|
-
materializeSessionFile(
|
|
69
|
+
materializeSessionFile(conversationDir, file);
|
|
70
70
|
return file;
|
|
71
71
|
}
|
|
72
|
+
/** The session file a conversation would open, without creating anything — for read-only background work. */
|
|
73
|
+
export function peekActiveSessionFile(conversationDir) {
|
|
74
|
+
return readActiveSessionRef(conversationDir)?.file ?? DEFAULT_SESSION_FILENAME;
|
|
75
|
+
}
|
|
72
76
|
/**
|
|
73
77
|
* Commits the active-session ref for a session a topology operation (`/new`, fork, switch) has
|
|
74
78
|
* already created/opened. The SDK writes that session's durable header synchronously before
|
|
@@ -77,15 +81,15 @@ export function resolveActiveSessionFile(channelDir) {
|
|
|
77
81
|
* until this resolves (spec 043, D1.3) — on throw, nothing is written and the old ref (and thus
|
|
78
82
|
* the old session) remains authoritative.
|
|
79
83
|
*/
|
|
80
|
-
export async function commitActiveSessionRef(
|
|
84
|
+
export async function commitActiveSessionRef(conversationDir, session) {
|
|
81
85
|
const sessionFile = session.getSessionFile();
|
|
82
86
|
if (!sessionFile) {
|
|
83
87
|
throw new Error("Cannot commit active-session ref: session has no backing file (not persisted).");
|
|
84
88
|
}
|
|
85
|
-
const resolvedDir = resolve(
|
|
89
|
+
const resolvedDir = resolve(conversationDir);
|
|
86
90
|
const resolvedFile = resolve(sessionFile);
|
|
87
91
|
if (dirname(resolvedFile) !== resolvedDir) {
|
|
88
|
-
throw new Error(`Session file must live directly under the
|
|
92
|
+
throw new Error(`Session file must live directly under the conversation directory: ${sessionFile}`);
|
|
89
93
|
}
|
|
90
94
|
const file = basename(resolvedFile);
|
|
91
95
|
if (!isValidSessionRefBasename(file)) {
|
|
@@ -97,10 +101,10 @@ export async function commitActiveSessionRef(channelDir, session) {
|
|
|
97
101
|
sessionId: session.getSessionId(),
|
|
98
102
|
updatedAt: new Date().toISOString(),
|
|
99
103
|
};
|
|
100
|
-
await writeFileAtomically(getActiveSessionRefPath(
|
|
104
|
+
await writeFileAtomically(getActiveSessionRefPath(conversationDir), `${JSON.stringify(ref, null, 2)}\n`);
|
|
101
105
|
}
|
|
102
106
|
/**
|
|
103
|
-
* Create a durable empty session and atomically make it active for a
|
|
107
|
+
* Create a durable empty session and atomically make it active for a conversation.
|
|
104
108
|
*
|
|
105
109
|
* This deliberately does not touch a live AgentSession. It is the transport-level `/new`
|
|
106
110
|
* primitive: a wedged provider request or compaction in the old runner cannot delay the
|
|
@@ -108,19 +112,19 @@ export async function commitActiveSessionRef(channelDir, session) {
|
|
|
108
112
|
* the active ref points at it, preserving the same file-before-pointer ordering as normal SDK
|
|
109
113
|
* topology changes.
|
|
110
114
|
*/
|
|
111
|
-
export async function createFreshActiveSession(
|
|
112
|
-
const provisional = SessionManager.create(cwd,
|
|
115
|
+
export async function createFreshActiveSession(conversationDir, cwd) {
|
|
116
|
+
const provisional = SessionManager.create(cwd, conversationDir);
|
|
113
117
|
const sessionFile = provisional.getSessionFile();
|
|
114
118
|
if (!sessionFile) {
|
|
115
119
|
throw new Error("Cannot create a new session: the SDK did not allocate a backing file.");
|
|
116
120
|
}
|
|
117
|
-
const resolvedDir = resolve(
|
|
121
|
+
const resolvedDir = resolve(conversationDir);
|
|
118
122
|
const resolvedFile = resolve(sessionFile);
|
|
119
123
|
if (dirname(resolvedFile) !== resolvedDir) {
|
|
120
|
-
throw new Error(`New session file must live directly under the
|
|
124
|
+
throw new Error(`New session file must live directly under the conversation directory: ${sessionFile}`);
|
|
121
125
|
}
|
|
122
|
-
materializeSessionFile(
|
|
123
|
-
const durable = SessionManager.open(resolvedFile,
|
|
124
|
-
await commitActiveSessionRef(
|
|
126
|
+
materializeSessionFile(conversationDir, basename(resolvedFile));
|
|
127
|
+
const durable = SessionManager.open(resolvedFile, conversationDir, cwd);
|
|
128
|
+
await commitActiveSessionRef(conversationDir, durable);
|
|
125
129
|
return { sessionId: durable.getSessionId() };
|
|
126
130
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What every transport shares about inbound attachments (spec 061, D5): the size and count limits,
|
|
3
|
+
* and magic-byte identification of image bytes. A transport only downloads or decodes bytes and
|
|
4
|
+
* checks these limits; persisting them under the bound desk's `inbox/` is the runtime's job.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Inbound has no transport-imposed size contract the way outbound does. This is the limit a user's
|
|
8
|
+
* picture is accepted under, deliberately above `tools/truncate.ts`'s `MAX_INLINE_BINARY_BYTES`
|
|
9
|
+
* (what `read` inlines from disk): a sent photo is the user's own input, and today's vision models
|
|
10
|
+
* accept it. Lives in `channel/` because both a transport (rejecting an oversized
|
|
11
|
+
* download) and `agent/` (skipping an oversized file before base64-encoding it) need the same
|
|
12
|
+
* number, and `agent/` never imports from `runtime/` (spec 049).
|
|
13
|
+
*/
|
|
14
|
+
export declare const MAX_INBOUND_IMAGE_BYTES: number;
|
|
15
|
+
/** Defensive hard cap on how many images one inbound message can carry. */
|
|
16
|
+
export declare const MAX_INBOUND_IMAGES_PER_MESSAGE = 10;
|
|
17
|
+
/**
|
|
18
|
+
* Identify a downloaded file's real format from its magic bytes rather than trusting the
|
|
19
|
+
* `Content-Type` DingTalk's CDN happens to answer with (spec 049 D8) — the four formats `read`
|
|
20
|
+
* and outbound `send_media` already treat as images. `null` means "downloaded fine, but not a
|
|
21
|
+
* recognized image format"; the caller still persists the bytes but never hands them to a model.
|
|
22
|
+
*/
|
|
23
|
+
export declare function sniffImageMimeType(data: Buffer): string | null;
|
|
24
|
+
/** File extension to persist a downloaded attachment under, from its sniffed MIME type. */
|
|
25
|
+
export declare function extensionForMimeType(mimeType: string | null): string;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What every transport shares about inbound attachments (spec 061, D5): the size and count limits,
|
|
3
|
+
* and magic-byte identification of image bytes. A transport only downloads or decodes bytes and
|
|
4
|
+
* checks these limits; persisting them under the bound desk's `inbox/` is the runtime's job.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Inbound has no transport-imposed size contract the way outbound does. This is the limit a user's
|
|
8
|
+
* picture is accepted under, deliberately above `tools/truncate.ts`'s `MAX_INLINE_BINARY_BYTES`
|
|
9
|
+
* (what `read` inlines from disk): a sent photo is the user's own input, and today's vision models
|
|
10
|
+
* accept it. Lives in `channel/` because both a transport (rejecting an oversized
|
|
11
|
+
* download) and `agent/` (skipping an oversized file before base64-encoding it) need the same
|
|
12
|
+
* number, and `agent/` never imports from `runtime/` (spec 049).
|
|
13
|
+
*/
|
|
14
|
+
export const MAX_INBOUND_IMAGE_BYTES = 10 * 1024 * 1024;
|
|
15
|
+
/** Defensive hard cap on how many images one inbound message can carry. */
|
|
16
|
+
export const MAX_INBOUND_IMAGES_PER_MESSAGE = 10;
|
|
17
|
+
/**
|
|
18
|
+
* Identify a downloaded file's real format from its magic bytes rather than trusting the
|
|
19
|
+
* `Content-Type` DingTalk's CDN happens to answer with (spec 049 D8) — the four formats `read`
|
|
20
|
+
* and outbound `send_media` already treat as images. `null` means "downloaded fine, but not a
|
|
21
|
+
* recognized image format"; the caller still persists the bytes but never hands them to a model.
|
|
22
|
+
*/
|
|
23
|
+
export function sniffImageMimeType(data) {
|
|
24
|
+
if (data.length >= 3 && data[0] === 0xff && data[1] === 0xd8 && data[2] === 0xff) {
|
|
25
|
+
return "image/jpeg";
|
|
26
|
+
}
|
|
27
|
+
if (data.length >= 8 && data.subarray(0, 8).equals(Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]))) {
|
|
28
|
+
return "image/png";
|
|
29
|
+
}
|
|
30
|
+
if (data.length >= 6) {
|
|
31
|
+
const header = data.subarray(0, 6).toString("latin1");
|
|
32
|
+
if (header === "GIF87a" || header === "GIF89a")
|
|
33
|
+
return "image/gif";
|
|
34
|
+
}
|
|
35
|
+
if (data.length >= 12 &&
|
|
36
|
+
data.subarray(0, 4).toString("latin1") === "RIFF" &&
|
|
37
|
+
data.subarray(8, 12).toString("latin1") === "WEBP") {
|
|
38
|
+
return "image/webp";
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
/** File extension to persist a downloaded attachment under, from its sniffed MIME type. */
|
|
43
|
+
export function extensionForMimeType(mimeType) {
|
|
44
|
+
switch (mimeType) {
|
|
45
|
+
case "image/jpeg":
|
|
46
|
+
return "jpg";
|
|
47
|
+
case "image/png":
|
|
48
|
+
return "png";
|
|
49
|
+
case "image/gif":
|
|
50
|
+
return "gif";
|
|
51
|
+
case "image/webp":
|
|
52
|
+
return "webp";
|
|
53
|
+
default:
|
|
54
|
+
return "bin";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -1,109 +1,100 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The per-turn output port (spec 061, D7): what one turn writes to its channel.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* transport.
|
|
10
|
-
*
|
|
11
|
-
* These declarations previously lived in `dingtalk/bot.ts` under the name
|
|
12
|
-
* `DingTalkContext`; they were lifted out (and renamed) so a second transport
|
|
13
|
-
* can implement the contract without importing anything DingTalk-specific. They
|
|
14
|
-
* live in `src/channel/` rather than `src/runtime/` because a port belongs with
|
|
15
|
-
* the domain it describes, not with one of its adapters: `agent`, `tools` and
|
|
16
|
-
* `tui` all depend on this file, and none of them should be reading anything out
|
|
17
|
-
* of the DingTalk transport's directory to get it.
|
|
18
|
-
*/
|
|
19
|
-
import type { InboundImage } from "./channel-event.js";
|
|
20
|
-
/**
|
|
21
|
-
* How progress is surfaced during a run. Derived from the transport's response
|
|
22
|
-
* mode so callers never branch on the raw enum string.
|
|
4
|
+
* A turn reports what happened as structured `TurnEvent`s; how that looks is each transport's
|
|
5
|
+
* business — DingTalk renders progress lines into an AI Card, the Web API turns them into output
|
|
6
|
+
* items. Nothing here is pre-rendered text, and nothing model-facing travels through it: a tool
|
|
7
|
+
* call carries its name and raw arguments, and the transport builds the user label itself
|
|
8
|
+
* (`tools/contract/presentation.ts`'s `describeToolCall`).
|
|
23
9
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
10
|
+
import type { UsageTotals } from "../usage/totals.js";
|
|
11
|
+
export interface ChannelContext {
|
|
12
|
+
/** Called in order of occurrence and never blocks; a transport serializes its own delivery. */
|
|
13
|
+
emit(event: TurnEvent): void;
|
|
14
|
+
/** Called once when the turn ends; the transport closes its card or settles its response here. */
|
|
15
|
+
finish(outcome: TurnOutcome): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export type TurnEvent = {
|
|
18
|
+
type: "tool.start";
|
|
19
|
+
callId: string;
|
|
20
|
+
tool: string;
|
|
21
|
+
args: unknown;
|
|
22
|
+
} | {
|
|
23
|
+
type: "tool.update";
|
|
24
|
+
callId: string;
|
|
25
|
+
text: string;
|
|
26
|
+
}
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
28
|
+
* `output` is the tool's result text (clipped). `failure` is present only when the user should
|
|
29
|
+
* see this call as an error line, already worded for them; a call the model recovers from by
|
|
30
|
+
* itself (a rejected argument) is `ok: false` with no `failure`.
|
|
31
31
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
export declare function isResponseModeConfig(value: unknown): value is ResponseMode;
|
|
36
|
-
export declare function normalizeResponseMode(value: unknown): ResponseMode;
|
|
37
|
-
/**
|
|
38
|
-
* A file the agent wants to push to a channel as a native attachment (image or
|
|
39
|
-
* downloadable file), as opposed to text/markdown in the transcript.
|
|
40
|
-
*
|
|
41
|
-
* Bytes travel in-band (`data`) rather than as a path so the sender is decoupled
|
|
42
|
-
* from where the file physically lives — the `send_media` tool reads the file
|
|
43
|
-
* through its `Executor` (which may be remote) and hands over the bytes, exactly
|
|
44
|
-
* as `read` does for images.
|
|
45
|
-
*/
|
|
46
|
-
export interface OutboundMedia {
|
|
47
|
-
/** Raw file contents. */
|
|
48
|
-
data: Buffer;
|
|
49
|
-
/** Display name shown to the recipient (e.g. "report.pdf"). */
|
|
50
|
-
fileName: string;
|
|
51
|
-
/** `image` renders inline; `file` is a downloadable attachment. */
|
|
52
|
-
kind: "image" | "file";
|
|
53
|
-
}
|
|
54
|
-
export interface MediaSendResult {
|
|
32
|
+
| {
|
|
33
|
+
type: "tool.end";
|
|
34
|
+
callId: string;
|
|
55
35
|
ok: boolean;
|
|
56
|
-
|
|
57
|
-
|
|
36
|
+
output: string;
|
|
37
|
+
failure?: string;
|
|
38
|
+
} | {
|
|
39
|
+
type: "reasoning";
|
|
40
|
+
text: string;
|
|
58
41
|
}
|
|
59
42
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
43
|
+
* A line of the turn's narrative that is not the answer. Without a `level` it is the model's
|
|
44
|
+
* own text between tool calls. `level` marks runtime-authored text:
|
|
45
|
+
* - `"error"` — a failure line inside the progress (a tool or compaction error); dropped when
|
|
46
|
+
* the transport shows no progress;
|
|
47
|
+
* - `"warning"` — the same, but it must not be lost: shown as progress, or as a standalone
|
|
48
|
+
* notice when the transport shows no progress (a model fallback switch);
|
|
49
|
+
* - `"notice"` — a standalone side notice, never part of the progress (a skill update, a
|
|
50
|
+
* clipped input, a compaction hint).
|
|
66
51
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
52
|
+
| {
|
|
53
|
+
type: "commentary";
|
|
54
|
+
text: string;
|
|
55
|
+
level?: "error" | "warning" | "notice";
|
|
69
56
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
userName?: string;
|
|
76
|
-
channel: string;
|
|
77
|
-
ts: string;
|
|
78
|
-
/** Images the user sent alongside this message (spec 049). Empty on transports (TUI) that
|
|
79
|
-
* do not yet produce inbound attachments — the field stays optional for them. */
|
|
80
|
-
images?: InboundImage[];
|
|
81
|
-
};
|
|
82
|
-
channelName?: string;
|
|
83
|
-
respond: (text: string, shouldLog?: boolean) => Promise<void>;
|
|
84
|
-
/** `title` names the reply in transports that show one (e.g. DingTalk's conversation list); ignored where there isn't one. */
|
|
85
|
-
respondPlain: (text: string, shouldLog?: boolean, title?: string) => Promise<boolean>;
|
|
86
|
-
replaceMessage: (text: string) => Promise<void>;
|
|
87
|
-
respondInThread: (text: string) => Promise<void>;
|
|
88
|
-
setTyping: (isTyping: boolean) => Promise<void>;
|
|
89
|
-
setWorking: (working: boolean) => Promise<void>;
|
|
90
|
-
/** End without a final answer. Transports may preserve already-visible progress. */
|
|
91
|
-
deleteMessage: () => Promise<void>;
|
|
92
|
-
primeCard: (delayMs: number) => void;
|
|
93
|
-
flush: () => Promise<void>;
|
|
94
|
-
close: () => Promise<void>;
|
|
95
|
-
progressStyle: ProgressStyle;
|
|
96
|
-
finalDelivery: FinalDelivery;
|
|
57
|
+
/** A final answer. `title` names it where the transport shows one (DingTalk's conversation list). */
|
|
58
|
+
| {
|
|
59
|
+
type: "answer";
|
|
60
|
+
text: string;
|
|
61
|
+
title?: string;
|
|
97
62
|
}
|
|
63
|
+
/** The SDK injected a steering or follow-up message into this turn. */
|
|
64
|
+
| {
|
|
65
|
+
type: "steer.applied";
|
|
66
|
+
} | {
|
|
67
|
+
type: "compaction";
|
|
68
|
+
phase: "start" | "end";
|
|
69
|
+
ok?: boolean;
|
|
70
|
+
};
|
|
98
71
|
/**
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* the channel. v3 asked the model to say `[SILENT]` and treated the request as advisory; muting
|
|
103
|
-
* the transport instead makes silence the structural default, and a step that genuinely has
|
|
104
|
-
* something to say routes it through `task_step_end`'s `notify` — which the runtime delivers on
|
|
105
|
-
* the real context after the step ends.
|
|
106
|
-
*
|
|
107
|
-
* Lifecycle calls pass through for cleanup; card priming is a visible write and is muted too.
|
|
72
|
+
* Where a turn's context lives once it has ended: the session file and the entry the turn left it
|
|
73
|
+
* at. A session file is append-only, so the context at that entry can be rebuilt later, when a
|
|
74
|
+
* caller asks to continue from this turn, instead of being copied out after every turn.
|
|
108
75
|
*/
|
|
109
|
-
export
|
|
76
|
+
export interface ContextRef {
|
|
77
|
+
sessionFile: string;
|
|
78
|
+
leafId: string;
|
|
79
|
+
}
|
|
80
|
+
export interface TurnOutcome {
|
|
81
|
+
/**
|
|
82
|
+
* Machine-only, never user copy. A request-scoped generation (an in-memory session that is gone
|
|
83
|
+
* when it ends) hands over its context itself; a channel turn names where its context stays.
|
|
84
|
+
*/
|
|
85
|
+
continuation?: import("./turn-context.js").ContextMessage[];
|
|
86
|
+
contextRef?: ContextRef;
|
|
87
|
+
/** The context's owning desk; not user-visible copy. */
|
|
88
|
+
executionDesk?: string;
|
|
89
|
+
/**
|
|
90
|
+
* - `completed` — the turn ended normally (it may have no answer);
|
|
91
|
+
* - `silent` — the model answered `[SILENT]` or nothing: end without a message;
|
|
92
|
+
* - `failed` — it ended in error with no answer; `message` says why;
|
|
93
|
+
* - `cancelled` — the user stopped it, or its generation was retired.
|
|
94
|
+
*/
|
|
95
|
+
kind: "completed" | "silent" | "failed" | "cancelled";
|
|
96
|
+
/** `failed` only: the reason, already written for the user. */
|
|
97
|
+
message?: string;
|
|
98
|
+
/** Everything the turn's LLM calls cost, up to the moment it ended. */
|
|
99
|
+
usage: UsageTotals;
|
|
100
|
+
}
|
|
@@ -1,66 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Transport-neutral delivery contract.
|
|
3
|
-
*
|
|
4
|
-
* `ChannelContext` is the surface a `ChannelRunner` turn writes to: progress
|
|
5
|
-
* updates, the final answer, side notices, and lifecycle hooks. The DingTalk
|
|
6
|
-
* transport implements it via AI Card streaming (`dingtalk/delivery.ts`); the
|
|
7
|
-
* terminal TUI implements it by rendering to the console (`tui/`). The runner
|
|
8
|
-
* and `session-events` depend only on this interface, never on a concrete
|
|
9
|
-
* transport.
|
|
10
|
-
*
|
|
11
|
-
* These declarations previously lived in `dingtalk/bot.ts` under the name
|
|
12
|
-
* `DingTalkContext`; they were lifted out (and renamed) so a second transport
|
|
13
|
-
* can implement the contract without importing anything DingTalk-specific. They
|
|
14
|
-
* live in `src/channel/` rather than `src/runtime/` because a port belongs with
|
|
15
|
-
* the domain it describes, not with one of its adapters: `agent`, `tools` and
|
|
16
|
-
* `tui` all depend on this file, and none of them should be reading anything out
|
|
17
|
-
* of the DingTalk transport's directory to get it.
|
|
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
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* A context whose user-visible writes are dropped (spec 051, D3).
|
|
48
|
-
*
|
|
49
|
-
* Task loop steps are silent by default: a twelve-step cycle should not narrate twelve times into
|
|
50
|
-
* the channel. v3 asked the model to say `[SILENT]` and treated the request as advisory; muting
|
|
51
|
-
* the transport instead makes silence the structural default, and a step that genuinely has
|
|
52
|
-
* something to say routes it through `task_step_end`'s `notify` — which the runtime delivers on
|
|
53
|
-
* the real context after the step ends.
|
|
54
|
-
*
|
|
55
|
-
* Lifecycle calls pass through for cleanup; card priming is a visible write and is muted too.
|
|
56
|
-
*/
|
|
57
|
-
export function muteChannelContext(ctx) {
|
|
58
|
-
return {
|
|
59
|
-
...ctx,
|
|
60
|
-
respond: async () => undefined,
|
|
61
|
-
respondPlain: async () => true,
|
|
62
|
-
replaceMessage: async () => undefined,
|
|
63
|
-
respondInThread: async () => undefined,
|
|
64
|
-
primeCard: () => undefined,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
1
|
+
export {};
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Inbound has no DingTalk-imposed size contract the way outbound does (`dingtalk.ts`'s
|
|
3
|
-
* `MAX_IMAGE_BYTES` mirrors the *send* limit); this instead mirrors `tools/truncate.ts`'s
|
|
4
|
-
* `MAX_INLINE_BINARY_BYTES` — the same ceiling `read` already applies to an on-disk image — so
|
|
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 `dingtalk/inbound-media.ts`, because both the
|
|
7
|
-
* transport (rejecting an oversized download) and `agent/channel-runner.ts` (skipping an
|
|
8
|
-
* oversized file before base64-encoding it) need the same number, and `agent/` never imports
|
|
9
|
-
* from `runtime/` (spec 049).
|
|
10
|
-
*/
|
|
11
|
-
export declare const MAX_INBOUND_IMAGE_BYTES: number;
|
|
12
1
|
/**
|
|
13
2
|
* A user-sent image already downloaded to local disk (spec 049).
|
|
14
3
|
*
|
|
@@ -20,7 +9,7 @@ export declare const MAX_INBOUND_IMAGE_BYTES: number;
|
|
|
20
9
|
* happened.
|
|
21
10
|
*/
|
|
22
11
|
export interface InboundImage {
|
|
23
|
-
/** Absolute path under
|
|
12
|
+
/** Absolute path under the bound desk's `inbox/`. */
|
|
24
13
|
path: string;
|
|
25
14
|
/**
|
|
26
15
|
* Sniffed MIME type ("image/jpeg", …), or `"application/octet-stream"` when magic-byte
|
|
@@ -36,35 +25,50 @@ export interface InboundImage {
|
|
|
36
25
|
unsupportedFormat?: boolean;
|
|
37
26
|
}
|
|
38
27
|
/**
|
|
39
|
-
* A message or wake, from any producer
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* since it has no DingTalk conversation to route into. `conversationType` is not DingTalk-specific
|
|
44
|
-
* in practice — every producer, real or synthetic, can derive "1"/"2" from the channelId prefix —
|
|
45
|
-
* so it stays required.
|
|
28
|
+
* A message or a wake, from any producer (spec 061, D8). `source` is the discriminator: a `human`
|
|
29
|
+
* event is a real person's message that came through a transport; a `wake` is synthesized in
|
|
30
|
+
* process (scheduled events, the task driver, job and delegation completions) and is admitted only
|
|
31
|
+
* while its channel is still bound to the desk it was produced for.
|
|
46
32
|
*/
|
|
47
|
-
export
|
|
48
|
-
|
|
33
|
+
export type ChannelEvent = HumanEvent | WakeEvent;
|
|
34
|
+
interface EventBase {
|
|
49
35
|
channelId: string;
|
|
50
36
|
ts: string;
|
|
51
|
-
user: string;
|
|
52
|
-
userName: string;
|
|
53
37
|
text: string;
|
|
54
38
|
/** Images the user sent alongside `text` (spec 049), already downloaded and persisted. */
|
|
55
39
|
images?: InboundImage[];
|
|
56
|
-
/**
|
|
57
|
-
|
|
58
|
-
|
|
40
|
+
/** Runtime-owned durable-dispatch record, absent for normal inbound messages. */
|
|
41
|
+
dispatchId?: string;
|
|
42
|
+
}
|
|
43
|
+
export interface HumanEvent extends EventBase {
|
|
44
|
+
context?: import("./turn-context.js").TurnContext;
|
|
45
|
+
source: "human";
|
|
46
|
+
user: string;
|
|
47
|
+
userName: string;
|
|
59
48
|
/**
|
|
60
|
-
* Human-readable channel name: the group title, or the peer's nickname for a DM. Absent
|
|
61
|
-
*
|
|
49
|
+
* Human-readable channel name: the group title, or the peer's nickname for a DM. Absent when
|
|
50
|
+
* the transport has none.
|
|
62
51
|
*/
|
|
63
52
|
channelName?: string;
|
|
64
|
-
/**
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
*
|
|
53
|
+
/** The transport's own correlation reference for this message (`InboundMessage.ref`). */
|
|
54
|
+
ref?: string;
|
|
55
|
+
/**
|
|
56
|
+
* The desks the sender may use (`InboundMessage.allowedDesks`); absent means any. Carried to
|
|
57
|
+
* execution because a queued message can outlive the binding it was admitted under.
|
|
58
|
+
*/
|
|
59
|
+
allowedDesks?: readonly string[];
|
|
60
|
+
}
|
|
61
|
+
export interface WakeEvent extends EventBase {
|
|
62
|
+
source: "wake";
|
|
63
|
+
/** Producer tag: JOB, TASK_DRIVER, SUBAGENT, EVENT, … Shown to the model as the sender. */
|
|
64
|
+
producer: string;
|
|
65
|
+
/**
|
|
66
|
+
* The desk this wake was produced for (spec 058, D7). Every in-process producer must set it;
|
|
67
|
+
* durable dispatch refuses a wake without it, and admission drops a wake whose channel is no
|
|
68
|
+
* longer bound to this desk.
|
|
69
|
+
*/
|
|
70
|
+
desk: string;
|
|
71
|
+
/** Structured wake provenance created only by in-process producers; user text cannot manufacture it. */
|
|
68
72
|
internalWake?: {
|
|
69
73
|
kind: "job" | "subagent";
|
|
70
74
|
resourceId: string;
|
|
@@ -72,19 +76,25 @@ export interface ChannelEvent {
|
|
|
72
76
|
dispatchId: string;
|
|
73
77
|
};
|
|
74
78
|
/**
|
|
75
|
-
* Purely a display hint: `"awaited"` marks a
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
79
|
+
* Purely a display hint: `"awaited"` marks a wake a human is actually waiting on (a delegation
|
|
80
|
+
* or background job finishing), as opposed to an autonomous check-in (task-driver polling, a
|
|
81
|
+
* scheduled event) that normally has nothing to say. All wakes deliver only their result; this
|
|
82
|
+
* metadata does not enable progress cards or gate task activation. Trust decisions stay on
|
|
83
|
+
* `internalWake` alone.
|
|
80
84
|
*/
|
|
81
85
|
presentation?: "awaited";
|
|
82
86
|
}
|
|
87
|
+
/** Who the model is told wrote this event: the person, or the producer tag of a wake. */
|
|
88
|
+
export declare function senderOf(event: ChannelEvent): {
|
|
89
|
+
user: string;
|
|
90
|
+
userName: string;
|
|
91
|
+
};
|
|
83
92
|
/**
|
|
84
|
-
* The one thing in-process producers (scheduled events, durable dispatch) need from
|
|
85
|
-
* hand it a
|
|
86
|
-
*
|
|
93
|
+
* The one thing in-process producers (scheduled events, durable dispatch) need from the runtime:
|
|
94
|
+
* hand it a wake for its per-channel queue. `false` means the queue rejected it (full or
|
|
95
|
+
* stopped), so the caller keeps ownership and may retry. Implemented by the runtime's `Ingress`.
|
|
87
96
|
*/
|
|
88
97
|
export interface ChannelEventSink {
|
|
89
|
-
enqueueEvent(event:
|
|
98
|
+
enqueueEvent(event: WakeEvent): boolean;
|
|
90
99
|
}
|
|
100
|
+
export {};
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* transport (rejecting an oversized download) and `agent/channel-runner.ts` (skipping an
|
|
8
|
-
* oversized file before base64-encoding it) need the same number, and `agent/` never imports
|
|
9
|
-
* from `runtime/` (spec 049).
|
|
10
|
-
*/
|
|
11
|
-
export const MAX_INBOUND_IMAGE_BYTES = 5 * 1024 * 1024;
|
|
1
|
+
/** Who the model is told wrote this event: the person, or the producer tag of a wake. */
|
|
2
|
+
export function senderOf(event) {
|
|
3
|
+
return event.source === "wake"
|
|
4
|
+
? { user: event.producer, userName: event.producer }
|
|
5
|
+
: { user: event.user, userName: event.userName };
|
|
6
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The format of a channel id — the one place it is defined (spec 061, D10). A channel id is an
|
|
3
|
+
* address only: a JSON key, a record field, a log field. It is never a path segment (INV-3).
|
|
4
|
+
*
|
|
5
|
+
* `<transport>:<native>`: everything before the first colon names the transport, everything after
|
|
6
|
+
* it is the transport's own address and is never interpreted here. A DingTalk conversation id is
|
|
7
|
+
* base64 and routinely contains `/`, `+`, `=` and can even contain `:`, which is why only the
|
|
8
|
+
* first colon is ever split.
|
|
9
|
+
*/
|
|
10
|
+
export interface ParsedChannelId {
|
|
11
|
+
/** The text before the first colon; not validated against the known transports (a stale record may name a retired one). */
|
|
12
|
+
transport: string;
|
|
13
|
+
native: string;
|
|
14
|
+
}
|
|
15
|
+
/** `dingtalk:dm:abc` → `{ transport: "dingtalk", native: "dm:abc" }`; `undefined` when either side is empty or there is no colon. */
|
|
16
|
+
export declare function parseChannelId(channelId: string): ParsedChannelId | undefined;
|
|
17
|
+
export declare function transportOf(channelId: string): string | undefined;
|
|
18
|
+
/** What a report needs to say about a delivery channel: its label, and whether it is still bound to this desk. */
|
|
19
|
+
export interface ChannelDescription {
|
|
20
|
+
label: string;
|
|
21
|
+
boundHere: boolean;
|
|
22
|
+
}
|