@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,20 @@
|
|
|
1
|
+
export interface TranscriptTurn {
|
|
2
|
+
userMessageTs: string;
|
|
3
|
+
userMessageText: string;
|
|
4
|
+
responseMessageTimestamps: string[];
|
|
5
|
+
status: 'processing' | 'completed' | 'superseded';
|
|
6
|
+
}
|
|
7
|
+
export interface TranscriptData {
|
|
8
|
+
sessionId: string;
|
|
9
|
+
channel: string;
|
|
10
|
+
turns: TranscriptTurn[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Per-conduit serial work queue port. The concrete impl (app.ts) wraps the shared
|
|
14
|
+
* @orch/conduit-queue singletons so TUI message work serializes with the rest of
|
|
15
|
+
* the pipeline on the same conduit key.
|
|
16
|
+
*/
|
|
17
|
+
export interface ConduitQueuePort {
|
|
18
|
+
enqueue(conduitId: string, fn: () => Promise<void>): boolean;
|
|
19
|
+
remove(conduitId: string): void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface TuiConduitState {
|
|
2
|
+
sessionId: string | null;
|
|
3
|
+
projectId: string;
|
|
4
|
+
backend: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const tuiConduitStates: Map<string, TuiConduitState>;
|
|
7
|
+
export declare function getConduitState(conduitId: string): TuiConduitState | undefined;
|
|
8
|
+
export declare function setConduitState(conduitId: string, state: TuiConduitState): void;
|
|
9
|
+
export declare function deleteConduitState(conduitId: string): boolean;
|
|
10
|
+
export declare function hasConduitState(conduitId: string): boolean;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// input: nothing (leaf module)
|
|
2
|
+
// output: In-memory Map<conduitId, TuiConduitState> + helpers
|
|
3
|
+
// pos: TUI adapter — per-conduit session/project/backend binding
|
|
4
|
+
// >>> If I am updated, update the folder's CORTEX.md <<<
|
|
5
|
+
export const tuiConduitStates = new Map();
|
|
6
|
+
export function getConduitState(conduitId) {
|
|
7
|
+
return tuiConduitStates.get(conduitId);
|
|
8
|
+
}
|
|
9
|
+
export function setConduitState(conduitId, state) {
|
|
10
|
+
tuiConduitStates.set(conduitId, state);
|
|
11
|
+
}
|
|
12
|
+
export function deleteConduitState(conduitId) {
|
|
13
|
+
return tuiConduitStates.delete(conduitId);
|
|
14
|
+
}
|
|
15
|
+
export function hasConduitState(conduitId) {
|
|
16
|
+
return tuiConduitStates.has(conduitId);
|
|
17
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { WebSocket } from 'ws';
|
|
2
|
+
import type { TuiFrame } from '../../tui/protocol.js';
|
|
3
|
+
export declare class TuiConnection {
|
|
4
|
+
readonly conduitId: string;
|
|
5
|
+
readonly ws: WebSocket;
|
|
6
|
+
activeSessionId: string | null;
|
|
7
|
+
activeProjectId: string;
|
|
8
|
+
uiSubscriptions: Set<string>;
|
|
9
|
+
/** Active UiService subscription handles — closed on cleanup */
|
|
10
|
+
activeSubscriptions: Map<string, {
|
|
11
|
+
close(): void;
|
|
12
|
+
}>;
|
|
13
|
+
/** pending actions keyed by action id (triggerId suffix) */
|
|
14
|
+
pendingActions: Map<string, {
|
|
15
|
+
actionId: string;
|
|
16
|
+
value: string;
|
|
17
|
+
}>;
|
|
18
|
+
/** pending modal acks keyed by modal submit id */
|
|
19
|
+
pendingModalAcks: Map<string, {
|
|
20
|
+
callbackId: string;
|
|
21
|
+
}>;
|
|
22
|
+
private _closed;
|
|
23
|
+
constructor(conduitId: string, ws: WebSocket, projectId: string);
|
|
24
|
+
/** Encode and send a TuiFrame over the WebSocket. No-op if already closed. */
|
|
25
|
+
send(frame: TuiFrame): void;
|
|
26
|
+
/** Close the WebSocket connection with an optional close code and reason. */
|
|
27
|
+
close(code?: number, reason?: string): void;
|
|
28
|
+
/** True if the connection has been closed. */
|
|
29
|
+
get closed(): boolean;
|
|
30
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// input: WebSocket, TuiFrame from protocol.ts
|
|
2
|
+
// output: TuiConnection — per-WS connection wrapper
|
|
3
|
+
// pos: TUI adapter — owns WS lifecycle, send/close, subscriptions
|
|
4
|
+
// >>> If I am updated, update the folder's CORTEX.md <<<
|
|
5
|
+
import { encodeFrame } from '../../tui/protocol.js';
|
|
6
|
+
import { createLogger } from '../../../core/log.js';
|
|
7
|
+
const log = createLogger('tui-conn');
|
|
8
|
+
export class TuiConnection {
|
|
9
|
+
conduitId;
|
|
10
|
+
ws;
|
|
11
|
+
activeSessionId = null;
|
|
12
|
+
activeProjectId;
|
|
13
|
+
uiSubscriptions = new Set();
|
|
14
|
+
/** Active UiService subscription handles — closed on cleanup */
|
|
15
|
+
activeSubscriptions = new Map();
|
|
16
|
+
/** pending actions keyed by action id (triggerId suffix) */
|
|
17
|
+
pendingActions = new Map();
|
|
18
|
+
/** pending modal acks keyed by modal submit id */
|
|
19
|
+
pendingModalAcks = new Map();
|
|
20
|
+
_closed = false;
|
|
21
|
+
constructor(conduitId, ws, projectId) {
|
|
22
|
+
this.conduitId = conduitId;
|
|
23
|
+
this.ws = ws;
|
|
24
|
+
this.activeProjectId = projectId;
|
|
25
|
+
}
|
|
26
|
+
/** Encode and send a TuiFrame over the WebSocket. No-op if already closed. */
|
|
27
|
+
send(frame) {
|
|
28
|
+
if (this._closed)
|
|
29
|
+
return;
|
|
30
|
+
try {
|
|
31
|
+
this.ws.send(encodeFrame(frame));
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
log.warn(`Failed to send frame to conduit ${this.conduitId}:`, err?.message || err);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** Close the WebSocket connection with an optional close code and reason. */
|
|
38
|
+
close(code, reason) {
|
|
39
|
+
if (this._closed)
|
|
40
|
+
return;
|
|
41
|
+
this._closed = true;
|
|
42
|
+
try {
|
|
43
|
+
this.ws.close(code, reason);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// already closing
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** True if the connection has been closed. */
|
|
50
|
+
get closed() {
|
|
51
|
+
return this._closed;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type { PlatformAdapter } from '../../adapter.js';
|
|
2
|
+
import type { MessageRef, MessageContent, MessageContext, MessageEditContext, ActionContext, ModalSubmitContext, ModalDefinition, PlatformCapabilities, PlatformFileRef, DownloadedFile, Destination, PostMessageOpts, FileUploadOpts, ActionElement } from '../../types.js';
|
|
3
|
+
import type { OutputStream, OpenOutputStreamOpts } from '../../output-stream.js';
|
|
4
|
+
import { TuiConnection } from './tui-connection.js';
|
|
5
|
+
import type { TranscriptData, ConduitQueuePort } from './ports.js';
|
|
6
|
+
import type { EventBus } from '../../../events/index.js';
|
|
7
|
+
interface TuiHandshakeResult {
|
|
8
|
+
sessionId: string;
|
|
9
|
+
sessionName: string;
|
|
10
|
+
projectId: string;
|
|
11
|
+
isFresh: boolean;
|
|
12
|
+
emitNotFoundError: boolean;
|
|
13
|
+
transcript: TranscriptData | null;
|
|
14
|
+
}
|
|
15
|
+
interface TuiSwitchResult {
|
|
16
|
+
sessionId: string;
|
|
17
|
+
sessionName: string;
|
|
18
|
+
projectId: string;
|
|
19
|
+
isFresh: boolean;
|
|
20
|
+
transcript: TranscriptData | null;
|
|
21
|
+
}
|
|
22
|
+
interface TuiSessionServiceHandle {
|
|
23
|
+
resolveHandshake(opts: {
|
|
24
|
+
conduitId: string;
|
|
25
|
+
projectId: string;
|
|
26
|
+
resumeSessionId?: string | null;
|
|
27
|
+
}): Promise<TuiHandshakeResult>;
|
|
28
|
+
switchSession(opts: {
|
|
29
|
+
conduitId: string;
|
|
30
|
+
projectId: string;
|
|
31
|
+
sessionId?: string | null;
|
|
32
|
+
}): Promise<TuiSwitchResult>;
|
|
33
|
+
}
|
|
34
|
+
export interface TuiAdapterControls {
|
|
35
|
+
setBus(bus: EventBus): void;
|
|
36
|
+
setUiService(service: unknown): void;
|
|
37
|
+
setSessionService(service: TuiSessionServiceHandle): void;
|
|
38
|
+
setConduitQueue(queue: ConduitQueuePort): void;
|
|
39
|
+
}
|
|
40
|
+
export declare class TuiGatewayAdapter implements PlatformAdapter, TuiAdapterControls {
|
|
41
|
+
readonly name = "tui";
|
|
42
|
+
readonly capabilities: PlatformCapabilities;
|
|
43
|
+
private _wss;
|
|
44
|
+
private _port;
|
|
45
|
+
private _host;
|
|
46
|
+
private _noopOutbound;
|
|
47
|
+
private _connections;
|
|
48
|
+
private _bus;
|
|
49
|
+
private _uiService;
|
|
50
|
+
private _sessionService;
|
|
51
|
+
private _conduitQueue;
|
|
52
|
+
private _busSubscriptions;
|
|
53
|
+
private _messageHandler;
|
|
54
|
+
private _editHandler;
|
|
55
|
+
private _actionHandlers;
|
|
56
|
+
private _modalHandlers;
|
|
57
|
+
constructor(opts?: {
|
|
58
|
+
port?: number;
|
|
59
|
+
host?: string;
|
|
60
|
+
});
|
|
61
|
+
setBus(bus: EventBus): void;
|
|
62
|
+
setUiService(service: unknown): void;
|
|
63
|
+
setSessionService(service: TuiSessionServiceHandle): void;
|
|
64
|
+
setConduitQueue(queue: ConduitQueuePort): void;
|
|
65
|
+
/**
|
|
66
|
+
* Resolve in-memory session/project binding for a TUI conduit. Registered as a
|
|
67
|
+
* conduit provider by app.ts so session lookups can resolve ephemeral TUI conduits.
|
|
68
|
+
*/
|
|
69
|
+
lookupConduit(conduitId: string): {
|
|
70
|
+
sessionId: string;
|
|
71
|
+
projectId: string;
|
|
72
|
+
} | null;
|
|
73
|
+
start(): Promise<void>;
|
|
74
|
+
stop(): Promise<void>;
|
|
75
|
+
onMessage(handler: (ctx: MessageContext) => Promise<void>): void;
|
|
76
|
+
onMessageEdit(handler: (ctx: MessageEditContext) => Promise<void>): void;
|
|
77
|
+
onAction(actionId: string, handler: (ctx: ActionContext) => Promise<void>): void;
|
|
78
|
+
onModalSubmit(callbackId: string, handler: (ctx: ModalSubmitContext) => Promise<void>): void;
|
|
79
|
+
postMessage(destination: Destination, content: MessageContent, opts?: PostMessageOpts): Promise<MessageRef>;
|
|
80
|
+
updateMessage(ref: MessageRef, content: MessageContent): Promise<void>;
|
|
81
|
+
deleteMessage(ref: MessageRef): Promise<void>;
|
|
82
|
+
postInteractive(destination: Destination, content: MessageContent & {
|
|
83
|
+
actions: ActionElement[];
|
|
84
|
+
}, opts?: PostMessageOpts): Promise<MessageRef>;
|
|
85
|
+
openModal(triggerId: string, modal: ModalDefinition): Promise<void>;
|
|
86
|
+
markQueued(ref: MessageRef): Promise<void>;
|
|
87
|
+
uploadFile(destination: Destination, filePath: string, _opts?: FileUploadOpts): Promise<void>;
|
|
88
|
+
downloadFile(fileRef: PlatformFileRef, destDir: string): Promise<DownloadedFile>;
|
|
89
|
+
getPermalink(ref: MessageRef): Promise<string | null>;
|
|
90
|
+
openOutputStream(destination: Destination, opts?: OpenOutputStreamOpts): OutputStream;
|
|
91
|
+
private _createNoopOutputStream;
|
|
92
|
+
bindProjectConduit(projectId: string, conduitHint: string): Promise<void>;
|
|
93
|
+
unbindProjectConduit(projectId: string): Promise<void>;
|
|
94
|
+
getProjectConduits(): Promise<Record<string, string>>;
|
|
95
|
+
resolveInboundProject(conduit: string): Promise<string | null>;
|
|
96
|
+
/** TUI conduits are `tui-<uuid>` and triggerIds are `tui:<conduitId>:<uuid>`. */
|
|
97
|
+
ownsConduit(conduit: string): boolean;
|
|
98
|
+
/** Expose connections for testing and notification routing. */
|
|
99
|
+
get connections(): Map<string, TuiConnection>;
|
|
100
|
+
/** Expose noop flag for testing. */
|
|
101
|
+
get noopOutbound(): boolean;
|
|
102
|
+
private _handleConnection;
|
|
103
|
+
private _dispatchInboundFrame;
|
|
104
|
+
private _handleHandshake;
|
|
105
|
+
private _handleSessionSwitch;
|
|
106
|
+
private _handleMsgUser;
|
|
107
|
+
private _handleMsgEdit;
|
|
108
|
+
private _handleActionClick;
|
|
109
|
+
private _handleModalSubmit;
|
|
110
|
+
private _handleUiQuery;
|
|
111
|
+
private _handleUiMutate;
|
|
112
|
+
private _handleUiSubscribe;
|
|
113
|
+
private _forwardSubscriptionEvents;
|
|
114
|
+
private _handleUiUnsubscribe;
|
|
115
|
+
private _resolveTargetConnections;
|
|
116
|
+
private _findConnectionBySessionId;
|
|
117
|
+
private _resolveConnectionByTriggerId;
|
|
118
|
+
private _cleanupConnection;
|
|
119
|
+
}
|
|
120
|
+
export {};
|