@cortex-agent/server 2026.5.25-1 → 2026.6.11
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/defaults/config/thread-templates.json +28 -1
- package/defaults/hooks/cortex-md-injector.mjs +47 -31
- package/defaults/hooks/post-task-hook.mjs +6 -0
- package/defaults/hooks/task-status-check.mjs +8 -0
- package/defaults/mcp-config-slack.json +11 -0
- package/defaults/plugins/cortex-stage-gate/skills/task/SKILL.md +18 -0
- package/defaults/plugins/cortex-system/skills/schedule/SKILL.md +5 -6
- package/defaults/prompts/directives/manager.md +67 -0
- package/dist/agent-adapter/claude/adapter-tui.d.ts +35 -3
- package/dist/agent-adapter/claude/adapter-tui.js +91 -12
- package/dist/agent-adapter/claude/adapter.js +11 -0
- package/dist/agent-adapter/claude/defaults.d.ts +30 -0
- package/dist/agent-adapter/claude/defaults.js +30 -0
- package/dist/agent-adapter/claude/jsonl-tail.d.ts +2 -2
- package/dist/agent-adapter/claude/jsonl-tail.js +25 -20
- package/dist/agent-adapter/claude/spawn-args.d.ts +11 -0
- package/dist/agent-adapter/claude/spawn-args.js +49 -7
- package/dist/agent-adapter/claude/tmux-control.d.ts +20 -0
- package/dist/agent-adapter/claude/tmux-control.js +54 -8
- package/dist/agent-adapter/codex/adapter.js +1 -1
- package/dist/agent-adapter/normalize/event-types.d.ts +1 -0
- package/dist/agent-adapter/pi/adapter.js +46 -19
- package/dist/agent-adapter/pi/agent-dir.d.ts +21 -0
- package/dist/agent-adapter/pi/agent-dir.js +53 -2
- package/dist/agent-adapter/pi/event-parser.js +13 -1
- package/dist/agent-adapter/pi/mcp-bridge.d.ts +12 -0
- package/dist/agent-adapter/pi/mcp-bridge.js +47 -9
- package/dist/agent-adapter/pi/tool-shims.d.ts +14 -0
- package/dist/agent-adapter/pi/tool-shims.js +167 -140
- package/dist/agent-adapter/types.d.ts +7 -2
- package/dist/core/atomic-write.js +21 -0
- package/dist/core/config-generator.d.ts +10 -0
- package/dist/core/config-generator.js +28 -0
- package/dist/core/gateway-generator.d.ts +77 -7
- package/dist/core/gateway-generator.js +301 -29
- package/dist/core/icons.d.ts +68 -0
- package/dist/core/icons.js +67 -0
- package/dist/core/profile-generator.d.ts +6 -0
- package/dist/core/profile-generator.js +35 -7
- package/dist/core/running-executions.d.ts +51 -41
- package/dist/core/running-executions.js +120 -73
- package/dist/core/status-format.js +3 -2
- package/dist/core/task-parser.d.ts +3 -0
- package/dist/core/task-parser.js +3 -1
- package/dist/core/types/thread-types.d.ts +54 -8
- package/dist/domain/agents/facade.d.ts +18 -0
- package/dist/domain/agents/facade.js +26 -3
- package/dist/domain/agents/profile-manager.d.ts +11 -0
- package/dist/domain/agents/profile-manager.js +21 -2
- package/dist/domain/costs/codex-usage-monitor.js +2 -1
- package/dist/domain/costs/rate-limit-throttle.js +14 -2
- package/dist/domain/executions/registry.d.ts +24 -0
- package/dist/domain/executions/registry.js +38 -0
- package/dist/domain/mcp/core-server.js +15 -3
- package/dist/domain/mcp/feishu/bitable.d.ts +3 -0
- package/dist/domain/mcp/feishu/bitable.js +168 -0
- package/dist/domain/mcp/feishu/block-types.d.ts +44 -0
- package/dist/domain/mcp/feishu/block-types.js +127 -0
- package/dist/domain/mcp/feishu/blocks-to-text.d.ts +19 -0
- package/dist/domain/mcp/feishu/blocks-to-text.js +43 -0
- package/dist/domain/mcp/feishu/client.d.ts +46 -0
- package/dist/domain/mcp/feishu/client.js +87 -0
- package/dist/domain/mcp/feishu/docx.d.ts +3 -0
- package/dist/domain/mcp/feishu/docx.js +163 -0
- package/dist/domain/mcp/feishu/drive.d.ts +23 -0
- package/dist/domain/mcp/feishu/drive.js +66 -0
- package/dist/domain/mcp/feishu/file.d.ts +14 -0
- package/dist/domain/mcp/feishu/file.js +107 -0
- package/dist/domain/mcp/feishu/index.d.ts +6 -0
- package/dist/domain/mcp/feishu/index.js +61 -0
- package/dist/domain/mcp/feishu/markdown-to-blocks.d.ts +40 -0
- package/dist/domain/mcp/feishu/markdown-to-blocks.js +191 -0
- package/dist/domain/mcp/feishu/sheets.d.ts +3 -0
- package/dist/domain/mcp/feishu/sheets.js +119 -0
- package/dist/domain/mcp/feishu/types.d.ts +26 -0
- package/dist/domain/mcp/feishu/types.js +38 -0
- package/dist/domain/mcp/feishu/user-auth.d.ts +140 -0
- package/dist/domain/mcp/feishu/user-auth.js +286 -0
- package/dist/domain/mcp/feishu/wiki.d.ts +3 -0
- package/dist/domain/mcp/feishu/wiki.js +77 -0
- package/dist/domain/mcp/feishu-server.d.ts +2 -0
- package/dist/domain/mcp/feishu-server.js +33 -0
- package/dist/domain/mcp/server.d.ts +0 -1
- package/dist/domain/mcp/server.js +6 -25
- package/dist/domain/mcp/slack-server.d.ts +3 -0
- package/dist/domain/mcp/slack-server.js +46 -0
- package/dist/domain/mcp/tools/context.js +1 -1
- package/dist/domain/mcp/tools/schedule.d.ts +1 -1
- package/dist/domain/mcp/tools/schedule.js +6 -20
- package/dist/domain/mcp/tools/slack.js +20 -7
- package/dist/domain/mcp/tools/thread-ops.d.ts +2 -0
- package/dist/domain/mcp/tools/thread-ops.js +121 -0
- package/dist/domain/mcp/tools/time.d.ts +2 -0
- package/dist/domain/mcp/tools/time.js +66 -0
- package/dist/domain/mcp/tools/tui-ask.js +1 -1
- package/dist/domain/mcp/tools/tui-plan.js +2 -2
- package/dist/domain/mcp/tui-server.js +1 -0
- package/dist/domain/monitor/disk-monitor.js +2 -1
- package/dist/domain/monitor/gpu-monitor.js +2 -1
- package/dist/domain/remote/client-hot-reload.js +3 -2
- package/dist/domain/remote/client-manager.js +8 -6
- package/dist/domain/scheduling/job-registry.d.ts +4 -0
- package/dist/domain/scheduling/job-registry.js +1 -0
- package/dist/domain/scheduling/jobs/_shared.js +2 -1
- package/dist/domain/scheduling/jobs/memory-index-regen.js +3 -2
- package/dist/domain/scheduling/jobs/scheduled-task.js +9 -23
- package/dist/domain/scheduling/jobs/sync-public.js +4 -3
- package/dist/domain/scheduling/jobs/target-dispatch.d.ts +1 -8
- package/dist/domain/scheduling/jobs/target-dispatch.js +0 -7
- package/dist/domain/scheduling/jobs/task-archive.js +3 -2
- package/dist/domain/scheduling/jobs/task-dispatch.js +120 -10
- package/dist/domain/scheduling/schedule-command.js +16 -15
- package/dist/domain/scheduling/scheduler.d.ts +1 -1
- package/dist/domain/scheduling/scheduler.js +2 -1
- package/dist/domain/sessions/session-hooks.d.ts +2 -2
- package/dist/domain/sessions/session-hooks.js +19 -18
- package/dist/domain/sessions/session-lifecycle.d.ts +38 -0
- package/dist/domain/sessions/session-lifecycle.js +44 -0
- package/dist/domain/system/install-cli.d.ts +7 -0
- package/dist/domain/system/install-cli.js +106 -0
- package/dist/domain/tasks/dispatch-utils.d.ts +58 -1
- package/dist/domain/tasks/dispatch-utils.js +53 -4
- package/dist/domain/tasks/dispatcher.js +26 -0
- package/dist/domain/tasks/lint.js +28 -0
- package/dist/domain/tasks/mutator.d.ts +16 -3
- package/dist/domain/tasks/mutator.js +41 -12
- package/dist/domain/tasks/pending-tracker.js +6 -5
- package/dist/domain/tasks/system/task-cli.d.ts +2 -0
- package/dist/domain/tasks/system/task-cli.js +37 -6
- package/dist/domain/tasks/system/task-lifecycle-edit.js +6 -1
- package/dist/domain/tasks/system/task-mutations.d.ts +41 -3
- package/dist/domain/tasks/system/task-mutations.js +166 -8
- package/dist/domain/threads/contract.d.ts +17 -0
- package/dist/domain/threads/contract.js +59 -0
- package/dist/domain/threads/hook-runner.js +7 -6
- package/dist/domain/threads/index.d.ts +2 -0
- package/dist/domain/threads/index.js +3 -1
- package/dist/domain/threads/prompt-builder.d.ts +15 -1
- package/dist/domain/threads/prompt-builder.js +41 -2
- package/dist/domain/threads/runner.d.ts +6 -5
- package/dist/domain/threads/runner.js +128 -79
- package/dist/domain/threads/state-machine.d.ts +23 -21
- package/dist/domain/threads/state-machine.js +113 -54
- package/dist/domain/threads/template-loader.js +3 -2
- package/dist/domain/threads/tree.d.ts +45 -0
- package/dist/domain/threads/tree.js +171 -0
- package/dist/domain/tui-session/index.d.ts +2 -0
- package/dist/domain/tui-session/index.js +3 -0
- package/dist/domain/tui-session/tui-session-service.d.ts +2 -0
- package/dist/domain/tui-session/tui-session-service.js +103 -0
- package/dist/domain/tui-session/types.d.ts +67 -0
- package/dist/domain/tui-session/types.js +4 -0
- package/dist/domain/ui-service/index.d.ts +5 -0
- package/dist/domain/ui-service/index.js +3 -0
- package/dist/domain/ui-service/mutate/executions.d.ts +4 -0
- package/dist/domain/ui-service/mutate/executions.js +15 -0
- package/dist/domain/ui-service/mutate/schedules.d.ts +10 -0
- package/dist/domain/ui-service/mutate/schedules.js +39 -0
- package/dist/domain/ui-service/mutate/tasks.d.ts +23 -0
- package/dist/domain/ui-service/mutate/tasks.js +59 -0
- package/dist/domain/ui-service/mutate/threads.d.ts +4 -0
- package/dist/domain/ui-service/mutate/threads.js +21 -0
- package/dist/domain/ui-service/query/cost.d.ts +3 -0
- package/dist/domain/ui-service/query/cost.js +6 -0
- package/dist/domain/ui-service/query/executions.d.ts +2 -0
- package/dist/domain/ui-service/query/executions.js +35 -0
- package/dist/domain/ui-service/query/projects.d.ts +2 -0
- package/dist/domain/ui-service/query/projects.js +30 -0
- package/dist/domain/ui-service/query/schedules.d.ts +2 -0
- package/dist/domain/ui-service/query/schedules.js +23 -0
- package/dist/domain/ui-service/query/sessions.d.ts +2 -0
- package/dist/domain/ui-service/query/sessions.js +35 -0
- package/dist/domain/ui-service/query/tasks.d.ts +2 -0
- package/dist/domain/ui-service/query/tasks.js +30 -0
- package/dist/domain/ui-service/query/threads.d.ts +2 -0
- package/dist/domain/ui-service/query/threads.js +27 -0
- package/dist/domain/ui-service/subscribe.d.ts +5 -0
- package/dist/domain/ui-service/subscribe.js +118 -0
- package/dist/domain/ui-service/types.d.ts +237 -0
- package/dist/domain/ui-service/types.js +5 -0
- package/dist/domain/ui-service/ui-service.d.ts +2 -0
- package/dist/domain/ui-service/ui-service.js +83 -0
- package/dist/entry/app.js +94 -5
- package/dist/entry/cli.d.ts +12 -0
- package/dist/entry/cli.js +122 -12
- package/dist/entry/feishu-login.d.ts +28 -0
- package/dist/entry/feishu-login.js +218 -0
- package/dist/entry/init.d.ts +25 -2
- package/dist/entry/init.js +211 -64
- package/dist/events/event-types.d.ts +14 -0
- package/dist/hooks/cortex-md-injector.mjs +47 -31
- package/dist/hooks/post-task-hook.mjs +6 -0
- package/dist/hooks/task-status-check.mjs +8 -0
- package/dist/orchestration/agent-runner.d.ts +2 -1
- package/dist/orchestration/agent-runner.js +55 -55
- package/dist/orchestration/conduit-queue.d.ts +18 -0
- package/dist/orchestration/conduit-queue.js +32 -0
- package/dist/orchestration/conversation-runner.d.ts +48 -0
- package/dist/orchestration/conversation-runner.js +109 -0
- package/dist/orchestration/dispatch-reconciler.js +8 -1
- package/dist/orchestration/interactions/ask-user-question.d.ts +1 -1
- package/dist/orchestration/interactions/ask-user-question.js +3 -3
- package/dist/orchestration/interactions/interaction-handlers.js +48 -17
- package/dist/orchestration/interactions/plan-handler.d.ts +2 -2
- package/dist/orchestration/interactions/plan-handler.js +4 -3
- package/dist/orchestration/interactions/update-prompt.d.ts +6 -0
- package/dist/orchestration/interactions/update-prompt.js +100 -0
- package/dist/orchestration/lifecycle.d.ts +4 -4
- package/dist/orchestration/lifecycle.js +24 -22
- package/dist/orchestration/orchestrator.d.ts +1 -1
- package/dist/orchestration/routing/commands/cancel.js +39 -47
- package/dist/orchestration/routing/commands/channel.js +24 -11
- package/dist/orchestration/routing/commands/cost.js +2 -1
- package/dist/orchestration/routing/commands/device.js +3 -2
- package/dist/orchestration/routing/commands/dispatch.js +6 -5
- package/dist/orchestration/routing/commands/index.d.ts +1 -1
- package/dist/orchestration/routing/commands/index.js +11 -10
- package/dist/orchestration/routing/commands/mode.js +19 -18
- package/dist/orchestration/routing/commands/nvtop.js +10 -9
- package/dist/orchestration/routing/commands/sendfile.js +7 -6
- package/dist/orchestration/routing/commands/session.d.ts +1 -1
- package/dist/orchestration/routing/commands/session.js +17 -33
- package/dist/orchestration/routing/commands/tail.js +4 -3
- package/dist/orchestration/routing/commands/task.js +4 -3
- package/dist/orchestration/routing/commands/thread-handlers.js +16 -6
- package/dist/orchestration/routing/edit-handler.js +8 -7
- package/dist/orchestration/routing/hook-bridge-subscribers.js +17 -1
- package/dist/orchestration/routing/message-router.d.ts +1 -1
- package/dist/orchestration/routing/message-router.js +9 -9
- package/dist/orchestration/routing/webhook.js +233 -2
- package/dist/orchestration/status-helpers.d.ts +5 -1
- package/dist/orchestration/status-helpers.js +7 -6
- package/dist/orchestration/thread-callback.d.ts +67 -0
- package/dist/orchestration/thread-callback.js +465 -0
- package/dist/orchestration/thread-executor.d.ts +22 -1
- package/dist/orchestration/thread-executor.js +85 -36
- package/dist/platform/adapter.d.ts +6 -2
- package/dist/platform/adapters/composite-adapter.d.ts +89 -0
- package/dist/platform/adapters/composite-adapter.js +318 -0
- package/dist/platform/adapters/feishu-output-stream.d.ts +26 -4
- package/dist/platform/adapters/feishu-output-stream.js +274 -36
- package/dist/platform/adapters/feishu.d.ts +50 -5
- package/dist/platform/adapters/feishu.js +370 -116
- package/dist/platform/adapters/index.d.ts +24 -3
- package/dist/platform/adapters/index.js +89 -11
- package/dist/platform/adapters/project-conduits.d.ts +9 -0
- package/dist/platform/adapters/project-conduits.js +42 -0
- package/dist/platform/adapters/slack-project-conduits.d.ts +1 -9
- package/dist/platform/adapters/slack-project-conduits.js +6 -40
- package/dist/platform/adapters/slack.d.ts +9 -2
- package/dist/platform/adapters/slack.js +83 -39
- package/dist/platform/adapters/tui/index.d.ts +9 -0
- package/dist/platform/adapters/tui/index.js +10 -0
- package/dist/platform/adapters/tui/ports.d.ts +20 -0
- package/dist/platform/adapters/tui/ports.js +4 -0
- package/dist/platform/adapters/tui/tui-conduit-state.d.ts +10 -0
- package/dist/platform/adapters/tui/tui-conduit-state.js +17 -0
- package/dist/platform/adapters/tui/tui-connection.d.ts +30 -0
- package/dist/platform/adapters/tui/tui-connection.js +53 -0
- package/dist/platform/adapters/tui/tui-gateway.d.ts +120 -0
- package/dist/platform/adapters/tui/tui-gateway.js +919 -0
- package/dist/platform/adapters/tui/tui-notifications.d.ts +12 -0
- package/dist/platform/adapters/tui/tui-notifications.js +60 -0
- package/dist/platform/adapters/tui/tui-output-stream.d.ts +36 -0
- package/dist/platform/adapters/tui/tui-output-stream.js +99 -0
- package/dist/platform/adapters/tui/tui-transcript.d.ts +8 -0
- package/dist/platform/adapters/tui/tui-transcript.js +56 -0
- package/dist/platform/index.d.ts +1 -0
- package/dist/platform/index.js +2 -1
- package/dist/platform/interactive-builder.js +3 -2
- package/dist/platform/output-stream.d.ts +5 -0
- package/dist/platform/testing.d.ts +7 -11
- package/dist/platform/testing.js +18 -15
- package/dist/platform/tool-trace.js +15 -5
- package/dist/platform/tui/protocol.d.ts +355 -0
- package/dist/platform/tui/protocol.js +199 -0
- package/dist/platform/types.d.ts +12 -3
- package/dist/store/execution-repo.d.ts +6 -1
- package/dist/store/execution-repo.js +13 -3
- package/dist/store/hook-sync.d.ts +18 -0
- package/dist/store/hook-sync.js +92 -0
- package/dist/store/outbound-queue.js +2 -2
- package/dist/store/profile-repo.js +3 -2
- package/dist/store/schedule-repo.d.ts +1 -8
- package/dist/store/session-registry-repo.d.ts +9 -1
- package/dist/store/session-registry-repo.js +19 -3
- package/dist/store/session-repo.d.ts +14 -0
- package/dist/store/session-repo.js +23 -0
- package/dist/store/thread-repo.d.ts +3 -0
- package/dist/store/thread-repo.js +49 -2
- package/dist/store/version-migrations.js +95 -0
- package/dist/tui/App.d.ts +27 -0
- package/dist/tui/App.js +219 -0
- package/dist/tui/components/AskUserModal.d.ts +11 -0
- package/dist/tui/components/AskUserModal.js +364 -0
- package/dist/tui/components/ConfirmModal.d.ts +12 -0
- package/dist/tui/components/ConfirmModal.js +31 -0
- package/dist/tui/components/Dashboard.d.ts +23 -0
- package/dist/tui/components/Dashboard.js +80 -0
- package/dist/tui/components/DashboardCostTab.d.ts +7 -0
- package/dist/tui/components/DashboardCostTab.js +16 -0
- package/dist/tui/components/DashboardExecutionsTab.d.ts +11 -0
- package/dist/tui/components/DashboardExecutionsTab.js +94 -0
- package/dist/tui/components/DashboardSchedulesTab.d.ts +11 -0
- package/dist/tui/components/DashboardSchedulesTab.js +124 -0
- package/dist/tui/components/DashboardTasksTab.d.ts +12 -0
- package/dist/tui/components/DashboardTasksTab.js +200 -0
- package/dist/tui/components/DashboardThreadsTab.d.ts +11 -0
- package/dist/tui/components/DashboardThreadsTab.js +81 -0
- package/dist/tui/components/Header.d.ts +11 -0
- package/dist/tui/components/Header.js +5 -0
- package/dist/tui/components/InputBox.d.ts +10 -0
- package/dist/tui/components/InputBox.js +19 -0
- package/dist/tui/components/MessageRow.d.ts +7 -0
- package/dist/tui/components/MessageRow.js +10 -0
- package/dist/tui/components/Notifications.d.ts +19 -0
- package/dist/tui/components/Notifications.js +72 -0
- package/dist/tui/components/PlanFeedbackModal.d.ts +11 -0
- package/dist/tui/components/PlanFeedbackModal.js +161 -0
- package/dist/tui/components/ProjectSwitcher.d.ts +18 -0
- package/dist/tui/components/ProjectSwitcher.js +43 -0
- package/dist/tui/components/SessionPicker.d.ts +14 -0
- package/dist/tui/components/SessionPicker.js +34 -0
- package/dist/tui/components/SidePanel.d.ts +19 -0
- package/dist/tui/components/SidePanel.js +8 -0
- package/dist/tui/components/StatusLine.d.ts +10 -0
- package/dist/tui/components/StatusLine.js +29 -0
- package/dist/tui/components/Transcript.d.ts +13 -0
- package/dist/tui/components/Transcript.js +56 -0
- package/dist/tui/hooks/useDashboardData.d.ts +32 -0
- package/dist/tui/hooks/useDashboardData.js +104 -0
- package/dist/tui/hooks/useKeybindings.d.ts +19 -0
- package/dist/tui/hooks/useKeybindings.js +87 -0
- package/dist/tui/hooks/useMutate.d.ts +22 -0
- package/dist/tui/hooks/useMutate.js +56 -0
- package/dist/tui/hooks/useNotifications.d.ts +28 -0
- package/dist/tui/hooks/useNotifications.js +70 -0
- package/dist/tui/hooks/useTranscript.d.ts +39 -0
- package/dist/tui/hooks/useTranscript.js +265 -0
- package/dist/tui/hooks/useWsClient.d.ts +29 -0
- package/dist/tui/hooks/useWsClient.js +69 -0
- package/dist/tui/index.d.ts +2 -0
- package/dist/tui/index.js +210 -0
- package/dist/tui/logic.d.ts +16 -0
- package/dist/tui/logic.js +49 -0
- package/dist/tui/render/markdown.d.ts +10 -0
- package/dist/tui/render/markdown.js +38 -0
- package/dist/tui/render/rich-blocks.d.ts +11 -0
- package/dist/tui/render/rich-blocks.js +24 -0
- package/dist/tui/ws-client.d.ts +44 -0
- package/dist/tui/ws-client.js +157 -0
- package/package.json +11 -3
- package/dist/orchestration/channel-queue.d.ts +0 -18
- package/dist/orchestration/channel-queue.js +0 -32
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import type { MessageRef, MessageContent, ActionElement, ModalDefinition, ModalFieldValue } from '../types.js';
|
|
2
|
+
export declare const PROTOCOL_VERSION = 1;
|
|
3
|
+
export declare const HANDSHAKE_HELLO = "handshake.hello";
|
|
4
|
+
export declare const HANDSHAKE_ACK = "handshake.ack";
|
|
5
|
+
export declare const SESSION_SWITCH = "session.switch";
|
|
6
|
+
export declare const SESSION_SWITCHED = "session.switched";
|
|
7
|
+
export declare const PING = "ping";
|
|
8
|
+
export declare const PONG = "pong";
|
|
9
|
+
export declare const CLOSE = "close";
|
|
10
|
+
export declare const CHAT_POST = "chat.post";
|
|
11
|
+
export declare const CHAT_UPDATE = "chat.update";
|
|
12
|
+
export declare const CHAT_DELETE = "chat.delete";
|
|
13
|
+
export declare const CHAT_MARK_QUEUED = "chat.markQueued";
|
|
14
|
+
export declare const MSG_USER = "msg.user";
|
|
15
|
+
export declare const MSG_EDIT = "msg.edit";
|
|
16
|
+
export declare const STREAM_TEXT = "stream.text";
|
|
17
|
+
export declare const STREAM_MUTABLE_OPEN = "stream.mutableOpen";
|
|
18
|
+
export declare const STREAM_MUTABLE_UPDATE = "stream.mutableUpdate";
|
|
19
|
+
export declare const STREAM_FLUSH = "stream.flush";
|
|
20
|
+
export declare const INTERACTIVE_POST = "interactive.post";
|
|
21
|
+
export declare const MODAL_OPEN = "modal.open";
|
|
22
|
+
export declare const MODAL_ACK = "modal.ack";
|
|
23
|
+
export declare const ACTION_CLICK = "action.click";
|
|
24
|
+
export declare const MODAL_SUBMIT = "modal.submit";
|
|
25
|
+
export declare const TRANSCRIPT_REPLAY = "transcript.replay";
|
|
26
|
+
export declare const NOTIFICATION = "notification";
|
|
27
|
+
export declare const UI_QUERY = "ui.query";
|
|
28
|
+
export declare const UI_QUERY_RESULT = "ui.queryResult";
|
|
29
|
+
export declare const UI_MUTATE = "ui.mutate";
|
|
30
|
+
export declare const UI_MUTATE_RESULT = "ui.mutateResult";
|
|
31
|
+
export declare const UI_SUBSCRIBE = "ui.subscribe";
|
|
32
|
+
export declare const UI_EVENT = "ui.event";
|
|
33
|
+
export declare const UI_UNSUBSCRIBE = "ui.unsubscribe";
|
|
34
|
+
export declare const ERROR = "error";
|
|
35
|
+
/** @direction client→server (first frame after WS open) */
|
|
36
|
+
export interface HandshakeHello {
|
|
37
|
+
type: typeof HANDSHAKE_HELLO;
|
|
38
|
+
protocolVersion: number;
|
|
39
|
+
clientName: string;
|
|
40
|
+
clientVersion: string;
|
|
41
|
+
resume?: {
|
|
42
|
+
sessionId: string;
|
|
43
|
+
} | null;
|
|
44
|
+
project?: string | null;
|
|
45
|
+
}
|
|
46
|
+
/** @direction server→client (response to handshake.hello) */
|
|
47
|
+
export interface HandshakeAck {
|
|
48
|
+
type: typeof HANDSHAKE_ACK;
|
|
49
|
+
protocolVersion: number;
|
|
50
|
+
serverVersion: string;
|
|
51
|
+
conduitId: string;
|
|
52
|
+
defaultProjectId: string;
|
|
53
|
+
seq: number;
|
|
54
|
+
}
|
|
55
|
+
/** @direction client→server (switch active session — fresh or attach existing) */
|
|
56
|
+
export interface SessionSwitch {
|
|
57
|
+
type: typeof SESSION_SWITCH;
|
|
58
|
+
id: string;
|
|
59
|
+
projectId: string;
|
|
60
|
+
/** null = create fresh session in projectId */
|
|
61
|
+
sessionId?: string | null;
|
|
62
|
+
}
|
|
63
|
+
/** @direction server→client (result of session.switch — id echoes request) */
|
|
64
|
+
export interface SessionSwitched {
|
|
65
|
+
type: typeof SESSION_SWITCHED;
|
|
66
|
+
id: string;
|
|
67
|
+
projectId: string;
|
|
68
|
+
sessionId: string;
|
|
69
|
+
sessionName: string;
|
|
70
|
+
isFresh: boolean;
|
|
71
|
+
seq: number;
|
|
72
|
+
}
|
|
73
|
+
/** @direction both (keepalive) */
|
|
74
|
+
export interface Ping {
|
|
75
|
+
type: typeof PING;
|
|
76
|
+
ts: number;
|
|
77
|
+
}
|
|
78
|
+
/** @direction both (keepalive — no seq; out-of-band) */
|
|
79
|
+
export interface Pong {
|
|
80
|
+
type: typeof PONG;
|
|
81
|
+
ts: number;
|
|
82
|
+
}
|
|
83
|
+
/** @direction client→server (explicit close; also fires implicitly on WS close) */
|
|
84
|
+
export interface Close {
|
|
85
|
+
type: typeof CLOSE;
|
|
86
|
+
reason?: string;
|
|
87
|
+
}
|
|
88
|
+
/** @direction server→client (post a new message into the conduit's transcript) */
|
|
89
|
+
export interface ChatPost {
|
|
90
|
+
type: typeof CHAT_POST;
|
|
91
|
+
ref: MessageRef;
|
|
92
|
+
content: MessageContent;
|
|
93
|
+
threadAnchorId?: string | null;
|
|
94
|
+
seq: number;
|
|
95
|
+
}
|
|
96
|
+
/** @direction server→client (update an existing message by ref) */
|
|
97
|
+
export interface ChatUpdate {
|
|
98
|
+
type: typeof CHAT_UPDATE;
|
|
99
|
+
ref: MessageRef;
|
|
100
|
+
content: MessageContent;
|
|
101
|
+
seq: number;
|
|
102
|
+
}
|
|
103
|
+
/** @direction server→client (delete a message by ref) */
|
|
104
|
+
export interface ChatDelete {
|
|
105
|
+
type: typeof CHAT_DELETE;
|
|
106
|
+
ref: MessageRef;
|
|
107
|
+
seq: number;
|
|
108
|
+
}
|
|
109
|
+
/** @direction server→client (inline backpressure marker — replaces Slack's hourglass) */
|
|
110
|
+
export interface ChatMarkQueued {
|
|
111
|
+
type: typeof CHAT_MARK_QUEUED;
|
|
112
|
+
ref: MessageRef;
|
|
113
|
+
seq: number;
|
|
114
|
+
}
|
|
115
|
+
/** @direction client→server (user submits a message in the active session) */
|
|
116
|
+
export interface MsgUser {
|
|
117
|
+
type: typeof MSG_USER;
|
|
118
|
+
id: string;
|
|
119
|
+
text: string;
|
|
120
|
+
threadAnchorId?: string | null;
|
|
121
|
+
attachments?: Array<{
|
|
122
|
+
path: string;
|
|
123
|
+
mimeType: string;
|
|
124
|
+
name: string;
|
|
125
|
+
}>;
|
|
126
|
+
}
|
|
127
|
+
/** @direction client→server (rare: user edits a previously sent message) */
|
|
128
|
+
export interface MsgEdit {
|
|
129
|
+
type: typeof MSG_EDIT;
|
|
130
|
+
id: string;
|
|
131
|
+
ref: MessageRef;
|
|
132
|
+
newText: string;
|
|
133
|
+
}
|
|
134
|
+
/** @direction server→client (commit a text segment to a stream) */
|
|
135
|
+
export interface StreamText {
|
|
136
|
+
type: typeof STREAM_TEXT;
|
|
137
|
+
streamId: string;
|
|
138
|
+
text: string;
|
|
139
|
+
seq: number;
|
|
140
|
+
}
|
|
141
|
+
/** @direction server→client (open a fresh mutable region inside a stream) */
|
|
142
|
+
export interface StreamMutableOpen {
|
|
143
|
+
type: typeof STREAM_MUTABLE_OPEN;
|
|
144
|
+
streamId: string;
|
|
145
|
+
regionId: string;
|
|
146
|
+
text: string;
|
|
147
|
+
seq: number;
|
|
148
|
+
}
|
|
149
|
+
/** @direction server→client (replace a mutable region's content) */
|
|
150
|
+
export interface StreamMutableUpdate {
|
|
151
|
+
type: typeof STREAM_MUTABLE_UPDATE;
|
|
152
|
+
streamId: string;
|
|
153
|
+
regionId: string;
|
|
154
|
+
text: string;
|
|
155
|
+
seq: number;
|
|
156
|
+
}
|
|
157
|
+
/** @direction server→client (optional flush marker — used by tests for ordering) */
|
|
158
|
+
export interface StreamFlush {
|
|
159
|
+
type: typeof STREAM_FLUSH;
|
|
160
|
+
streamId: string;
|
|
161
|
+
seq: number;
|
|
162
|
+
}
|
|
163
|
+
/** @direction server→client (post a message with action buttons) */
|
|
164
|
+
export interface InteractivePost {
|
|
165
|
+
type: typeof INTERACTIVE_POST;
|
|
166
|
+
ref: MessageRef;
|
|
167
|
+
content: MessageContent;
|
|
168
|
+
actions: ActionElement[];
|
|
169
|
+
threadAnchorId?: string | null;
|
|
170
|
+
seq: number;
|
|
171
|
+
}
|
|
172
|
+
/** @direction server→client (ask client to open a modal — AskUserQuestion / plan feedback) */
|
|
173
|
+
export interface ModalOpen {
|
|
174
|
+
type: typeof MODAL_OPEN;
|
|
175
|
+
triggerId: string;
|
|
176
|
+
modal: ModalDefinition;
|
|
177
|
+
seq: number;
|
|
178
|
+
}
|
|
179
|
+
/** @direction server→client (ack a modal submission; id echoes modal.submit) */
|
|
180
|
+
export interface ModalAck {
|
|
181
|
+
type: typeof MODAL_ACK;
|
|
182
|
+
id: string;
|
|
183
|
+
errors?: Record<string, string>;
|
|
184
|
+
seq: number;
|
|
185
|
+
}
|
|
186
|
+
/** @direction client→server (user clicked an action button) */
|
|
187
|
+
export interface ActionClick {
|
|
188
|
+
type: typeof ACTION_CLICK;
|
|
189
|
+
id: string;
|
|
190
|
+
actionId: string;
|
|
191
|
+
value: string;
|
|
192
|
+
triggerId: string;
|
|
193
|
+
messageRef?: MessageRef;
|
|
194
|
+
userId: string;
|
|
195
|
+
}
|
|
196
|
+
/** @direction client→server (user submitted a modal — values match ModalSubmitContext.values) */
|
|
197
|
+
export interface ModalSubmit {
|
|
198
|
+
type: typeof MODAL_SUBMIT;
|
|
199
|
+
id: string;
|
|
200
|
+
callbackId: string;
|
|
201
|
+
privateMetadata: string;
|
|
202
|
+
values: Record<string, Record<string, ModalFieldValue>>;
|
|
203
|
+
userId: string;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* @direction server→client (replay prior messages on session attach)
|
|
207
|
+
*
|
|
208
|
+
* Items are wire frames the client renders identically to live frames;
|
|
209
|
+
* they share the same seq space but are flagged via `isCatchUp` so the
|
|
210
|
+
* client suppresses notification side effects.
|
|
211
|
+
*
|
|
212
|
+
* Outer envelope carries no own `seq` — clients should use `seqEnd` as
|
|
213
|
+
* the high-water mark and expect the next live frame at `seqEnd + 1`.
|
|
214
|
+
*/
|
|
215
|
+
export interface TranscriptReplay {
|
|
216
|
+
type: typeof TRANSCRIPT_REPLAY;
|
|
217
|
+
sessionId: string;
|
|
218
|
+
items: Array<ChatPost | ChatUpdate | InteractivePost>;
|
|
219
|
+
seqStart: number;
|
|
220
|
+
seqEnd: number;
|
|
221
|
+
isCatchUp: boolean;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* @direction server→client
|
|
225
|
+
*
|
|
226
|
+
* Routed when a project-report / scheduled-report / thread-report destination
|
|
227
|
+
* lands on a TUI conduit whose active session ≠ the originating session.
|
|
228
|
+
* Renders as a corner badge, not inserted into the active chat.
|
|
229
|
+
*/
|
|
230
|
+
export interface Notification {
|
|
231
|
+
type: typeof NOTIFICATION;
|
|
232
|
+
kind: 'project-report' | 'system-notice' | 'thread-report';
|
|
233
|
+
projectId: string;
|
|
234
|
+
sessionId?: string | null;
|
|
235
|
+
title: string;
|
|
236
|
+
body: string;
|
|
237
|
+
ref?: MessageRef;
|
|
238
|
+
seq: number;
|
|
239
|
+
}
|
|
240
|
+
/** @direction client→server (read-only query into UiService) */
|
|
241
|
+
export interface UiQuery {
|
|
242
|
+
type: typeof UI_QUERY;
|
|
243
|
+
id: string;
|
|
244
|
+
scope: string;
|
|
245
|
+
params?: Record<string, unknown>;
|
|
246
|
+
}
|
|
247
|
+
/** @direction server→client (result of ui.query — id echoes request) */
|
|
248
|
+
export type UiQueryResult = {
|
|
249
|
+
type: typeof UI_QUERY_RESULT;
|
|
250
|
+
id: string;
|
|
251
|
+
ok: true;
|
|
252
|
+
data: unknown;
|
|
253
|
+
} | {
|
|
254
|
+
type: typeof UI_QUERY_RESULT;
|
|
255
|
+
id: string;
|
|
256
|
+
ok: false;
|
|
257
|
+
error: {
|
|
258
|
+
code: string;
|
|
259
|
+
message: string;
|
|
260
|
+
};
|
|
261
|
+
};
|
|
262
|
+
/** @direction client→server (audited write into UiService) */
|
|
263
|
+
export interface UiMutate {
|
|
264
|
+
type: typeof UI_MUTATE;
|
|
265
|
+
id: string;
|
|
266
|
+
op: string;
|
|
267
|
+
args: Record<string, unknown>;
|
|
268
|
+
}
|
|
269
|
+
/** @direction server→client (result of ui.mutate — id echoes request) */
|
|
270
|
+
export type UiMutateResult = {
|
|
271
|
+
type: typeof UI_MUTATE_RESULT;
|
|
272
|
+
id: string;
|
|
273
|
+
ok: true;
|
|
274
|
+
data?: unknown;
|
|
275
|
+
} | {
|
|
276
|
+
type: typeof UI_MUTATE_RESULT;
|
|
277
|
+
id: string;
|
|
278
|
+
ok: false;
|
|
279
|
+
error: {
|
|
280
|
+
code: string;
|
|
281
|
+
message: string;
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
/** @direction client→server (open an event subscription) */
|
|
285
|
+
export interface UiSubscribe {
|
|
286
|
+
type: typeof UI_SUBSCRIBE;
|
|
287
|
+
id: string;
|
|
288
|
+
filter: {
|
|
289
|
+
events: string[];
|
|
290
|
+
projectId?: string | null;
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
/** @direction server→client (streamed event for a subscription — id echoes subscribe) */
|
|
294
|
+
export interface UiEvent {
|
|
295
|
+
type: typeof UI_EVENT;
|
|
296
|
+
id: string;
|
|
297
|
+
event: {
|
|
298
|
+
type: string;
|
|
299
|
+
ts: string;
|
|
300
|
+
payload: unknown;
|
|
301
|
+
};
|
|
302
|
+
seq: number;
|
|
303
|
+
}
|
|
304
|
+
/** @direction client→server (close a subscription — id matches subscribe) */
|
|
305
|
+
export interface UiUnsubscribe {
|
|
306
|
+
type: typeof UI_UNSUBSCRIBE;
|
|
307
|
+
id: string;
|
|
308
|
+
}
|
|
309
|
+
/** @direction server→client */
|
|
310
|
+
export interface ErrorFrame {
|
|
311
|
+
type: typeof ERROR;
|
|
312
|
+
code: number;
|
|
313
|
+
message: string;
|
|
314
|
+
/** id of the client→server frame that caused this error, if applicable */
|
|
315
|
+
refId?: string;
|
|
316
|
+
closeAfter?: boolean;
|
|
317
|
+
}
|
|
318
|
+
export type TuiFrame = HandshakeHello | HandshakeAck | SessionSwitch | SessionSwitched | Ping | Pong | Close | ChatPost | ChatUpdate | ChatDelete | ChatMarkQueued | MsgUser | MsgEdit | StreamText | StreamMutableOpen | StreamMutableUpdate | StreamFlush | InteractivePost | ModalOpen | ModalAck | ActionClick | ModalSubmit | TranscriptReplay | Notification | UiQuery | UiQueryResult | UiMutate | UiMutateResult | UiSubscribe | UiEvent | UiUnsubscribe | ErrorFrame;
|
|
319
|
+
export declare function isHandshakeHello(f: TuiFrame): f is HandshakeHello;
|
|
320
|
+
export declare function isHandshakeAck(f: TuiFrame): f is HandshakeAck;
|
|
321
|
+
export declare function isSessionSwitch(f: TuiFrame): f is SessionSwitch;
|
|
322
|
+
export declare function isSessionSwitched(f: TuiFrame): f is SessionSwitched;
|
|
323
|
+
export declare function isPing(f: TuiFrame): f is Ping;
|
|
324
|
+
export declare function isPong(f: TuiFrame): f is Pong;
|
|
325
|
+
export declare function isClose(f: TuiFrame): f is Close;
|
|
326
|
+
export declare function isChatPost(f: TuiFrame): f is ChatPost;
|
|
327
|
+
export declare function isChatUpdate(f: TuiFrame): f is ChatUpdate;
|
|
328
|
+
export declare function isChatDelete(f: TuiFrame): f is ChatDelete;
|
|
329
|
+
export declare function isChatMarkQueued(f: TuiFrame): f is ChatMarkQueued;
|
|
330
|
+
export declare function isMsgUser(f: TuiFrame): f is MsgUser;
|
|
331
|
+
export declare function isMsgEdit(f: TuiFrame): f is MsgEdit;
|
|
332
|
+
export declare function isStreamText(f: TuiFrame): f is StreamText;
|
|
333
|
+
export declare function isStreamMutableOpen(f: TuiFrame): f is StreamMutableOpen;
|
|
334
|
+
export declare function isStreamMutableUpdate(f: TuiFrame): f is StreamMutableUpdate;
|
|
335
|
+
export declare function isStreamFlush(f: TuiFrame): f is StreamFlush;
|
|
336
|
+
export declare function isInteractivePost(f: TuiFrame): f is InteractivePost;
|
|
337
|
+
export declare function isModalOpen(f: TuiFrame): f is ModalOpen;
|
|
338
|
+
export declare function isModalAck(f: TuiFrame): f is ModalAck;
|
|
339
|
+
export declare function isActionClick(f: TuiFrame): f is ActionClick;
|
|
340
|
+
export declare function isModalSubmit(f: TuiFrame): f is ModalSubmit;
|
|
341
|
+
export declare function isTranscriptReplay(f: TuiFrame): f is TranscriptReplay;
|
|
342
|
+
export declare function isNotification(f: TuiFrame): f is Notification;
|
|
343
|
+
export declare function isUiQuery(f: TuiFrame): f is UiQuery;
|
|
344
|
+
export declare function isUiQueryResult(f: TuiFrame): f is UiQueryResult;
|
|
345
|
+
export declare function isUiMutate(f: TuiFrame): f is UiMutate;
|
|
346
|
+
export declare function isUiMutateResult(f: TuiFrame): f is UiMutateResult;
|
|
347
|
+
export declare function isUiSubscribe(f: TuiFrame): f is UiSubscribe;
|
|
348
|
+
export declare function isUiEvent(f: TuiFrame): f is UiEvent;
|
|
349
|
+
export declare function isUiUnsubscribe(f: TuiFrame): f is UiUnsubscribe;
|
|
350
|
+
export declare function isErrorFrame(f: TuiFrame): f is ErrorFrame;
|
|
351
|
+
export declare const ALL_FRAME_TYPES: readonly string[];
|
|
352
|
+
export declare const GUARD_BY_TYPE: Record<string, (f: TuiFrame) => boolean>;
|
|
353
|
+
export declare function parseFrame(raw: string): TuiFrame | null;
|
|
354
|
+
export declare function encodeFrame(f: TuiFrame): string;
|
|
355
|
+
export type { MessageRef, MessageContent, RichBlock, ActionElement, ModalDefinition, ModalField, ModalFieldValue, } from '../types.js';
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// input: platform/types.js (type-only)
|
|
2
|
+
// output: M4 TUI wire protocol — TuiFrame union + guards + parseFrame/encodeFrame
|
|
3
|
+
// pos: Contract between M1 (TUI gateway adapter) and M5 (Ink client)
|
|
4
|
+
// deps: zero runtime dependencies; only type-level imports from ../types.js
|
|
5
|
+
// >>> If I am updated, update the parent folder's CORTEX.md and ensure
|
|
6
|
+
// ALL_FRAME_TYPES + GUARD_BY_TYPE + REQUIRED_FIELDS stay in sync with TuiFrame. <<<
|
|
7
|
+
//
|
|
8
|
+
// Conventions:
|
|
9
|
+
// - Discriminator format: lowercase namespace + dot + camelCase verb
|
|
10
|
+
// (e.g. 'chat.markQueued', 'stream.mutableOpen', 'ui.queryResult')
|
|
11
|
+
// - Every server→client frame carries `seq: number` for ordering / dedup,
|
|
12
|
+
// except `pong` (keepalive) and `error` (out-of-band control).
|
|
13
|
+
// - Every client→server REQUEST frame carries `id: string` for correlation,
|
|
14
|
+
// except `handshake.hello` (first frame, no prior context), `ping`, `close`.
|
|
15
|
+
// - Response frames echo the request `id` AND carry their own server `seq`.
|
|
16
|
+
// ── Protocol Version ──
|
|
17
|
+
export const PROTOCOL_VERSION = 1;
|
|
18
|
+
// ── Discriminator String Constants ──
|
|
19
|
+
// Lifecycle
|
|
20
|
+
export const HANDSHAKE_HELLO = 'handshake.hello'; // C→S
|
|
21
|
+
export const HANDSHAKE_ACK = 'handshake.ack'; // S→C
|
|
22
|
+
export const SESSION_SWITCH = 'session.switch'; // C→S
|
|
23
|
+
export const SESSION_SWITCHED = 'session.switched'; // S→C
|
|
24
|
+
export const PING = 'ping'; // both
|
|
25
|
+
export const PONG = 'pong'; // both
|
|
26
|
+
export const CLOSE = 'close'; // C→S
|
|
27
|
+
// Chat outbound (S→C)
|
|
28
|
+
export const CHAT_POST = 'chat.post';
|
|
29
|
+
export const CHAT_UPDATE = 'chat.update';
|
|
30
|
+
export const CHAT_DELETE = 'chat.delete';
|
|
31
|
+
export const CHAT_MARK_QUEUED = 'chat.markQueued';
|
|
32
|
+
// Chat inbound (C→S)
|
|
33
|
+
export const MSG_USER = 'msg.user';
|
|
34
|
+
export const MSG_EDIT = 'msg.edit';
|
|
35
|
+
// Streaming (S→C)
|
|
36
|
+
export const STREAM_TEXT = 'stream.text';
|
|
37
|
+
export const STREAM_MUTABLE_OPEN = 'stream.mutableOpen';
|
|
38
|
+
export const STREAM_MUTABLE_UPDATE = 'stream.mutableUpdate';
|
|
39
|
+
export const STREAM_FLUSH = 'stream.flush';
|
|
40
|
+
// Interactive (S→C: interactive.post, modal.open, modal.ack; C→S: action.click, modal.submit)
|
|
41
|
+
export const INTERACTIVE_POST = 'interactive.post';
|
|
42
|
+
export const MODAL_OPEN = 'modal.open';
|
|
43
|
+
export const MODAL_ACK = 'modal.ack';
|
|
44
|
+
export const ACTION_CLICK = 'action.click';
|
|
45
|
+
export const MODAL_SUBMIT = 'modal.submit';
|
|
46
|
+
// Other (S→C)
|
|
47
|
+
export const TRANSCRIPT_REPLAY = 'transcript.replay';
|
|
48
|
+
export const NOTIFICATION = 'notification';
|
|
49
|
+
// UI side-channel
|
|
50
|
+
export const UI_QUERY = 'ui.query'; // C→S
|
|
51
|
+
export const UI_QUERY_RESULT = 'ui.queryResult'; // S→C
|
|
52
|
+
export const UI_MUTATE = 'ui.mutate'; // C→S
|
|
53
|
+
export const UI_MUTATE_RESULT = 'ui.mutateResult'; // S→C
|
|
54
|
+
export const UI_SUBSCRIBE = 'ui.subscribe'; // C→S
|
|
55
|
+
export const UI_EVENT = 'ui.event'; // S→C
|
|
56
|
+
export const UI_UNSUBSCRIBE = 'ui.unsubscribe'; // C→S
|
|
57
|
+
// Error (S→C)
|
|
58
|
+
export const ERROR = 'error';
|
|
59
|
+
// ── Guards ──
|
|
60
|
+
export function isHandshakeHello(f) { return f.type === HANDSHAKE_HELLO; }
|
|
61
|
+
export function isHandshakeAck(f) { return f.type === HANDSHAKE_ACK; }
|
|
62
|
+
export function isSessionSwitch(f) { return f.type === SESSION_SWITCH; }
|
|
63
|
+
export function isSessionSwitched(f) { return f.type === SESSION_SWITCHED; }
|
|
64
|
+
export function isPing(f) { return f.type === PING; }
|
|
65
|
+
export function isPong(f) { return f.type === PONG; }
|
|
66
|
+
export function isClose(f) { return f.type === CLOSE; }
|
|
67
|
+
export function isChatPost(f) { return f.type === CHAT_POST; }
|
|
68
|
+
export function isChatUpdate(f) { return f.type === CHAT_UPDATE; }
|
|
69
|
+
export function isChatDelete(f) { return f.type === CHAT_DELETE; }
|
|
70
|
+
export function isChatMarkQueued(f) { return f.type === CHAT_MARK_QUEUED; }
|
|
71
|
+
export function isMsgUser(f) { return f.type === MSG_USER; }
|
|
72
|
+
export function isMsgEdit(f) { return f.type === MSG_EDIT; }
|
|
73
|
+
export function isStreamText(f) { return f.type === STREAM_TEXT; }
|
|
74
|
+
export function isStreamMutableOpen(f) { return f.type === STREAM_MUTABLE_OPEN; }
|
|
75
|
+
export function isStreamMutableUpdate(f) { return f.type === STREAM_MUTABLE_UPDATE; }
|
|
76
|
+
export function isStreamFlush(f) { return f.type === STREAM_FLUSH; }
|
|
77
|
+
export function isInteractivePost(f) { return f.type === INTERACTIVE_POST; }
|
|
78
|
+
export function isModalOpen(f) { return f.type === MODAL_OPEN; }
|
|
79
|
+
export function isModalAck(f) { return f.type === MODAL_ACK; }
|
|
80
|
+
export function isActionClick(f) { return f.type === ACTION_CLICK; }
|
|
81
|
+
export function isModalSubmit(f) { return f.type === MODAL_SUBMIT; }
|
|
82
|
+
export function isTranscriptReplay(f) { return f.type === TRANSCRIPT_REPLAY; }
|
|
83
|
+
export function isNotification(f) { return f.type === NOTIFICATION; }
|
|
84
|
+
export function isUiQuery(f) { return f.type === UI_QUERY; }
|
|
85
|
+
export function isUiQueryResult(f) { return f.type === UI_QUERY_RESULT; }
|
|
86
|
+
export function isUiMutate(f) { return f.type === UI_MUTATE; }
|
|
87
|
+
export function isUiMutateResult(f) { return f.type === UI_MUTATE_RESULT; }
|
|
88
|
+
export function isUiSubscribe(f) { return f.type === UI_SUBSCRIBE; }
|
|
89
|
+
export function isUiEvent(f) { return f.type === UI_EVENT; }
|
|
90
|
+
export function isUiUnsubscribe(f) { return f.type === UI_UNSUBSCRIBE; }
|
|
91
|
+
export function isErrorFrame(f) { return f.type === ERROR; }
|
|
92
|
+
// ── Frame Type Inventory ──
|
|
93
|
+
export const ALL_FRAME_TYPES = [
|
|
94
|
+
HANDSHAKE_HELLO, HANDSHAKE_ACK, SESSION_SWITCH, SESSION_SWITCHED,
|
|
95
|
+
PING, PONG, CLOSE,
|
|
96
|
+
CHAT_POST, CHAT_UPDATE, CHAT_DELETE, CHAT_MARK_QUEUED,
|
|
97
|
+
MSG_USER, MSG_EDIT,
|
|
98
|
+
STREAM_TEXT, STREAM_MUTABLE_OPEN, STREAM_MUTABLE_UPDATE, STREAM_FLUSH,
|
|
99
|
+
INTERACTIVE_POST, MODAL_OPEN, MODAL_ACK, ACTION_CLICK, MODAL_SUBMIT,
|
|
100
|
+
TRANSCRIPT_REPLAY, NOTIFICATION,
|
|
101
|
+
UI_QUERY, UI_QUERY_RESULT, UI_MUTATE, UI_MUTATE_RESULT,
|
|
102
|
+
UI_SUBSCRIBE, UI_EVENT, UI_UNSUBSCRIBE,
|
|
103
|
+
ERROR,
|
|
104
|
+
];
|
|
105
|
+
export const GUARD_BY_TYPE = {
|
|
106
|
+
[HANDSHAKE_HELLO]: isHandshakeHello,
|
|
107
|
+
[HANDSHAKE_ACK]: isHandshakeAck,
|
|
108
|
+
[SESSION_SWITCH]: isSessionSwitch,
|
|
109
|
+
[SESSION_SWITCHED]: isSessionSwitched,
|
|
110
|
+
[PING]: isPing,
|
|
111
|
+
[PONG]: isPong,
|
|
112
|
+
[CLOSE]: isClose,
|
|
113
|
+
[CHAT_POST]: isChatPost,
|
|
114
|
+
[CHAT_UPDATE]: isChatUpdate,
|
|
115
|
+
[CHAT_DELETE]: isChatDelete,
|
|
116
|
+
[CHAT_MARK_QUEUED]: isChatMarkQueued,
|
|
117
|
+
[MSG_USER]: isMsgUser,
|
|
118
|
+
[MSG_EDIT]: isMsgEdit,
|
|
119
|
+
[STREAM_TEXT]: isStreamText,
|
|
120
|
+
[STREAM_MUTABLE_OPEN]: isStreamMutableOpen,
|
|
121
|
+
[STREAM_MUTABLE_UPDATE]: isStreamMutableUpdate,
|
|
122
|
+
[STREAM_FLUSH]: isStreamFlush,
|
|
123
|
+
[INTERACTIVE_POST]: isInteractivePost,
|
|
124
|
+
[MODAL_OPEN]: isModalOpen,
|
|
125
|
+
[MODAL_ACK]: isModalAck,
|
|
126
|
+
[ACTION_CLICK]: isActionClick,
|
|
127
|
+
[MODAL_SUBMIT]: isModalSubmit,
|
|
128
|
+
[TRANSCRIPT_REPLAY]: isTranscriptReplay,
|
|
129
|
+
[NOTIFICATION]: isNotification,
|
|
130
|
+
[UI_QUERY]: isUiQuery,
|
|
131
|
+
[UI_QUERY_RESULT]: isUiQueryResult,
|
|
132
|
+
[UI_MUTATE]: isUiMutate,
|
|
133
|
+
[UI_MUTATE_RESULT]: isUiMutateResult,
|
|
134
|
+
[UI_SUBSCRIBE]: isUiSubscribe,
|
|
135
|
+
[UI_EVENT]: isUiEvent,
|
|
136
|
+
[UI_UNSUBSCRIBE]: isUiUnsubscribe,
|
|
137
|
+
[ERROR]: isErrorFrame,
|
|
138
|
+
};
|
|
139
|
+
// ── Required Fields (for parseFrame validation) ──
|
|
140
|
+
const REQUIRED_FIELDS = {
|
|
141
|
+
[HANDSHAKE_HELLO]: ['protocolVersion', 'clientName', 'clientVersion'],
|
|
142
|
+
[HANDSHAKE_ACK]: ['protocolVersion', 'serverVersion', 'conduitId', 'defaultProjectId', 'seq'],
|
|
143
|
+
[SESSION_SWITCH]: ['id', 'projectId'],
|
|
144
|
+
[SESSION_SWITCHED]: ['id', 'projectId', 'sessionId', 'sessionName', 'isFresh', 'seq'],
|
|
145
|
+
[PING]: ['ts'],
|
|
146
|
+
[PONG]: ['ts'],
|
|
147
|
+
[CLOSE]: [],
|
|
148
|
+
[CHAT_POST]: ['ref', 'content', 'seq'],
|
|
149
|
+
[CHAT_UPDATE]: ['ref', 'content', 'seq'],
|
|
150
|
+
[CHAT_DELETE]: ['ref', 'seq'],
|
|
151
|
+
[CHAT_MARK_QUEUED]: ['ref', 'seq'],
|
|
152
|
+
[MSG_USER]: ['id', 'text'],
|
|
153
|
+
[MSG_EDIT]: ['id', 'ref', 'newText'],
|
|
154
|
+
[STREAM_TEXT]: ['streamId', 'text', 'seq'],
|
|
155
|
+
[STREAM_MUTABLE_OPEN]: ['streamId', 'regionId', 'text', 'seq'],
|
|
156
|
+
[STREAM_MUTABLE_UPDATE]: ['streamId', 'regionId', 'text', 'seq'],
|
|
157
|
+
[STREAM_FLUSH]: ['streamId', 'seq'],
|
|
158
|
+
[INTERACTIVE_POST]: ['ref', 'content', 'actions', 'seq'],
|
|
159
|
+
[MODAL_OPEN]: ['triggerId', 'modal', 'seq'],
|
|
160
|
+
[MODAL_ACK]: ['id', 'seq'],
|
|
161
|
+
[ACTION_CLICK]: ['id', 'actionId', 'value', 'triggerId', 'userId'],
|
|
162
|
+
[MODAL_SUBMIT]: ['id', 'callbackId', 'privateMetadata', 'values', 'userId'],
|
|
163
|
+
[TRANSCRIPT_REPLAY]: ['sessionId', 'items', 'seqStart', 'seqEnd', 'isCatchUp'],
|
|
164
|
+
[NOTIFICATION]: ['kind', 'projectId', 'title', 'body', 'seq'],
|
|
165
|
+
[UI_QUERY]: ['id', 'scope'],
|
|
166
|
+
[UI_QUERY_RESULT]: ['id', 'ok'],
|
|
167
|
+
[UI_MUTATE]: ['id', 'op', 'args'],
|
|
168
|
+
[UI_MUTATE_RESULT]: ['id', 'ok'],
|
|
169
|
+
[UI_SUBSCRIBE]: ['id', 'filter'],
|
|
170
|
+
[UI_EVENT]: ['id', 'event', 'seq'],
|
|
171
|
+
[UI_UNSUBSCRIBE]: ['id'],
|
|
172
|
+
[ERROR]: ['code', 'message'],
|
|
173
|
+
};
|
|
174
|
+
// ── Parse / Encode ──
|
|
175
|
+
export function parseFrame(raw) {
|
|
176
|
+
let parsed;
|
|
177
|
+
try {
|
|
178
|
+
parsed = JSON.parse(raw);
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
if (typeof parsed !== 'object' || parsed === null)
|
|
184
|
+
return null;
|
|
185
|
+
const p = parsed;
|
|
186
|
+
if (typeof p.type !== 'string')
|
|
187
|
+
return null;
|
|
188
|
+
const required = REQUIRED_FIELDS[p.type];
|
|
189
|
+
if (!required)
|
|
190
|
+
return null;
|
|
191
|
+
for (const field of required) {
|
|
192
|
+
if (p[field] === undefined || p[field] === null)
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
return parsed;
|
|
196
|
+
}
|
|
197
|
+
export function encodeFrame(f) {
|
|
198
|
+
return JSON.stringify(f);
|
|
199
|
+
}
|
package/dist/platform/types.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
/** Universal reference to a message on any platform.
|
|
2
2
|
* Replaces the Slack-specific (channel, ts, thread_ts) triplet. */
|
|
3
3
|
export interface MessageRef {
|
|
4
|
-
channel
|
|
4
|
+
/** Adapter-defined conduit identifier (Slack channel id; Feishu chat_id; TUI synthetic connection id) */
|
|
5
|
+
conduit: string;
|
|
5
6
|
messageId: string;
|
|
6
7
|
threadId?: string;
|
|
8
|
+
/** For composite (multi-platform) posts: the per-adapter sub-refs that this ref aggregates.
|
|
9
|
+
* Each entry carries that platform's own conduit + messageId, so a downstream consumer can
|
|
10
|
+
* pick the anchor that belongs to a given platform (messageIds are platform-specific:
|
|
11
|
+
* a Slack ts is not a valid Feishu open_message_id). Absent for single-adapter refs. */
|
|
12
|
+
parts?: MessageRef[];
|
|
7
13
|
}
|
|
8
14
|
export interface IncomingMessage {
|
|
9
15
|
ref: MessageRef;
|
|
@@ -12,7 +18,7 @@ export interface IncomingMessage {
|
|
|
12
18
|
isBot: boolean;
|
|
13
19
|
files?: PlatformFileRef[];
|
|
14
20
|
attachments?: IncomingAttachment[];
|
|
15
|
-
|
|
21
|
+
kind: 'user' | 'system' | 'file_share';
|
|
16
22
|
raw: unknown;
|
|
17
23
|
}
|
|
18
24
|
export interface IncomingAttachment {
|
|
@@ -26,6 +32,10 @@ export interface PlatformFileRef {
|
|
|
26
32
|
name: string;
|
|
27
33
|
mimetype: string;
|
|
28
34
|
url: string;
|
|
35
|
+
/** Prefixed conduit the file originated from (e.g. `slack:C0xxx`, `feishu:oc_xxx`,
|
|
36
|
+
* `tui-xxxx`). Lets CompositeAdapter route downloadFile to the owning adapter
|
|
37
|
+
* when multiple platforms are online. Optional for back-compat. */
|
|
38
|
+
conduit?: string;
|
|
29
39
|
raw: unknown;
|
|
30
40
|
}
|
|
31
41
|
export interface DownloadedFile {
|
|
@@ -147,7 +157,6 @@ export interface PlatformCapabilities {
|
|
|
147
157
|
messageEdit: boolean;
|
|
148
158
|
modals: boolean;
|
|
149
159
|
reactions: boolean;
|
|
150
|
-
ephemeral: boolean;
|
|
151
160
|
fileUpload: boolean;
|
|
152
161
|
richFormatting: boolean;
|
|
153
162
|
maxMessageLength: number;
|
|
@@ -154,9 +154,14 @@ declare class ExecutionRepo {
|
|
|
154
154
|
markMissingRunningExecutionsStale(keepRunning?: (record: ExecutionRecord) => boolean): Promise<string[]>;
|
|
155
155
|
/** Reconcile stale dispatch executions: mark dispatches that are no longer pending and too old as stale.
|
|
156
156
|
* Returns { count, staled } where count is reconciled count and staled is the list of affected IDs. */
|
|
157
|
-
reconcileStaleDispatches({ isTaskPending, maxAgeMs }: {
|
|
157
|
+
reconcileStaleDispatches({ isTaskPending, isLive, maxAgeMs, graceMs }: {
|
|
158
158
|
isTaskPending: (taskId: string) => boolean;
|
|
159
|
+
/** True if the execution is still live in the in-memory registry (in-process dispatch). */
|
|
160
|
+
isLive?: (executionId: string) => boolean;
|
|
161
|
+
/** Hard ceiling: reap even a "live" dispatch once this old (wedged). */
|
|
159
162
|
maxAgeMs: number;
|
|
163
|
+
/** Short grace for a not-pending, not-live dispatch (a crashed in-process orphan). */
|
|
164
|
+
graceMs?: number;
|
|
160
165
|
}): Promise<{
|
|
161
166
|
count: number;
|
|
162
167
|
staled: string[];
|
|
@@ -284,11 +284,13 @@ class ExecutionRepo {
|
|
|
284
284
|
}
|
|
285
285
|
/** Reconcile stale dispatch executions: mark dispatches that are no longer pending and too old as stale.
|
|
286
286
|
* Returns { count, staled } where count is reconciled count and staled is the list of affected IDs. */
|
|
287
|
-
async reconcileStaleDispatches({ isTaskPending, maxAgeMs }) {
|
|
287
|
+
async reconcileStaleDispatches({ isTaskPending, isLive, maxAgeMs, graceMs }) {
|
|
288
288
|
await this._pendingPersist;
|
|
289
289
|
return this.mutex.run(async () => {
|
|
290
290
|
const now = Date.now();
|
|
291
291
|
const timestamp = nowIso();
|
|
292
|
+
// Without an isLive signal, fall back to the blunt hard-ceiling behavior.
|
|
293
|
+
const orphanGraceMs = graceMs ?? maxAgeMs;
|
|
292
294
|
let reconciled = 0;
|
|
293
295
|
const staled = [];
|
|
294
296
|
for (const record of this.map.values()) {
|
|
@@ -298,9 +300,17 @@ class ExecutionRepo {
|
|
|
298
300
|
continue;
|
|
299
301
|
const taskId = record.dispatch?.taskId;
|
|
300
302
|
if (taskId && isTaskPending(taskId))
|
|
301
|
-
continue;
|
|
303
|
+
continue; // tracked remote dispatch — keep
|
|
302
304
|
const startedAt = record.runtime?.startedAt ? new Date(record.runtime.startedAt).getTime() : 0;
|
|
303
|
-
|
|
305
|
+
const age = now - startedAt;
|
|
306
|
+
// Only LOCAL in-process dispatch is observable via the in-memory registry. A remote
|
|
307
|
+
// dispatch (machine set) runs on another host and is never "live" here, so the short
|
|
308
|
+
// orphan grace must not apply to it — it stays on the hard ceiling and is governed by
|
|
309
|
+
// isTaskPending. The short grace targets a crashed local in-process orphan only.
|
|
310
|
+
const isLocal = !record.dispatch?.machine || record.dispatch.machine === 'local';
|
|
311
|
+
const live = isLocal && isLive ? isLive(record.id) : false;
|
|
312
|
+
const threshold = (isLocal && !live) ? orphanGraceMs : maxAgeMs;
|
|
313
|
+
if (age < threshold)
|
|
304
314
|
continue;
|
|
305
315
|
record.status = 'stale';
|
|
306
316
|
record.runtime.updatedAt = timestamp;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Parse the @cortex-hook-version stamp from hook source, or null if absent/malformed. */
|
|
2
|
+
export declare function parseHookVersion(src: string): string | null;
|
|
3
|
+
/**
|
|
4
|
+
* Keep version-stamped hooks in HOOKS_DIR in sync with the shipped defaults.
|
|
5
|
+
*
|
|
6
|
+
* A default hook that carries an `// @cortex-hook-version YYYY.M.D` stamp is (re)written into
|
|
7
|
+
* HOOKS_DIR whenever the shipped stamp is newer than the deployed one. A missing or unstamped
|
|
8
|
+
* deployed copy counts as oldest, so legacy installs are brought under management on first run.
|
|
9
|
+
* Unmanaged defaults (no stamp) are left to init's copy-if-missing (deployHooks/safeCopy) and are
|
|
10
|
+
* never touched here. Idempotent and crash-safe via atomicWrite.
|
|
11
|
+
*
|
|
12
|
+
* `opts` exists for tests; production calls it with no args (real DEFAULTS_DIR/HOOKS_DIR).
|
|
13
|
+
* Returns the list of hook filenames that were updated.
|
|
14
|
+
*/
|
|
15
|
+
export declare function syncManagedHooks(opts?: {
|
|
16
|
+
srcDir?: string;
|
|
17
|
+
dstDir?: string;
|
|
18
|
+
}): Promise<string[]>;
|