@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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PlatformAdapter } from '../adapter.js';
|
|
2
2
|
import type { SlackAdapterConfig } from './slack.js';
|
|
3
3
|
import type { FeishuAdapterConfig } from './feishu.js';
|
|
4
|
-
export type PlatformType = 'slack' | 'discord' | 'telegram' | 'feishu' | 'test';
|
|
4
|
+
export type PlatformType = 'slack' | 'discord' | 'telegram' | 'feishu' | 'tui' | 'test';
|
|
5
5
|
export interface AdapterConfig {
|
|
6
6
|
platform: PlatformType;
|
|
7
7
|
slack?: SlackAdapterConfig;
|
|
@@ -11,8 +11,29 @@ export declare function createAdapter(config: AdapterConfig): PlatformAdapter;
|
|
|
11
11
|
/** Options injected from the composition root for capabilities that cross layer boundaries. */
|
|
12
12
|
export interface AdapterOverrides {
|
|
13
13
|
}
|
|
14
|
-
/**
|
|
15
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Detect and create all primary (Slack / Feishu / test) adapters from
|
|
16
|
+
* environment variables. `CORTEX_PLATFORM` is a comma-separated list (e.g.
|
|
17
|
+
* `slack,feishu`); a single value is fully back-compatible. Platforms whose
|
|
18
|
+
* credentials are missing are silently skipped. Returns an empty array when no
|
|
19
|
+
* primary platform is configured — the caller falls back to TUI-only mode.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createPrimaryAdaptersFromEnv(): PlatformAdapter[];
|
|
22
|
+
/**
|
|
23
|
+
* Back-compat shim: return the first configured primary adapter, or null.
|
|
24
|
+
* Prefer createPrimaryAdaptersFromEnv() for multi-platform support.
|
|
25
|
+
*/
|
|
26
|
+
export declare function createPrimaryAdapterFromEnv(): PlatformAdapter | null;
|
|
27
|
+
/**
|
|
28
|
+
* Create a PlatformAdapter from environment variables.
|
|
29
|
+
*
|
|
30
|
+
* Assembles all configured primary adapters (Slack/Feishu/test, per the
|
|
31
|
+
* comma-separated `CORTEX_PLATFORM`) plus an optional TUI gateway:
|
|
32
|
+
* no adapters → throw
|
|
33
|
+
* exactly one adapter → return it directly
|
|
34
|
+
* two or more adapters → CompositeAdapter([...])
|
|
35
|
+
*/
|
|
36
|
+
export declare function createAdapterFromEnv(): PlatformAdapter;
|
|
16
37
|
export { SlackAdapter } from './slack.js';
|
|
17
38
|
export type { SlackAdapterConfig } from './slack.js';
|
|
18
39
|
export { FeishuAdapter } from './feishu.js';
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
// input: ../adapter.js, ./slack.js, ./feishu.js, ../testing.js
|
|
2
|
-
// output: PlatformType + AdapterConfig + createAdapter factory
|
|
3
|
-
// pos: Select
|
|
1
|
+
// input: ../adapter.js, ./slack.js, ./feishu.js, ../testing.js, ./tui/index.js, ./composite-adapter.js
|
|
2
|
+
// output: PlatformType + AdapterConfig + createAdapter factory + createAdapterFromEnv + createPrimaryAdapters(FromEnv)
|
|
3
|
+
// pos: Select & compose adapters based on CORTEX_PLATFORM (comma list) / CORTEX_TUI
|
|
4
4
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
5
|
import { SlackAdapter } from './slack.js';
|
|
6
6
|
import { FeishuAdapter } from './feishu.js';
|
|
7
7
|
import { MockAdapter } from '../testing.js';
|
|
8
|
+
import { TuiGatewayAdapter } from './tui/index.js';
|
|
9
|
+
import { CompositeAdapter } from './composite-adapter.js';
|
|
8
10
|
export function createAdapter(config) {
|
|
9
11
|
switch (config.platform) {
|
|
10
12
|
case 'slack':
|
|
@@ -24,42 +26,118 @@ export function createAdapter(config) {
|
|
|
24
26
|
throw new Error(`Unknown platform: ${config.platform}`);
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
// ─── Primary adapter from env (existing detection logic factored out) ───
|
|
30
|
+
/**
|
|
31
|
+
* Build a single primary adapter by platform name from environment variables.
|
|
32
|
+
* Returns `null` when that platform's credentials are not configured.
|
|
33
|
+
*/
|
|
34
|
+
function buildPrimaryAdapter(platform) {
|
|
30
35
|
if (platform === 'slack') {
|
|
31
36
|
const botToken = process.env.SLACK_BOT_TOKEN;
|
|
32
37
|
const signingSecret = process.env.SLACK_SIGNING_SECRET;
|
|
33
38
|
const appToken = process.env.SLACK_APP_TOKEN;
|
|
34
39
|
if (!botToken || !signingSecret || !appToken) {
|
|
35
|
-
|
|
40
|
+
return null;
|
|
36
41
|
}
|
|
37
42
|
return new SlackAdapter({
|
|
38
43
|
botToken,
|
|
39
44
|
signingSecret,
|
|
40
45
|
appToken,
|
|
41
|
-
adminChannel: process.env.CORTEX_ADMIN_CHANNEL || undefined,
|
|
46
|
+
adminChannel: process.env.SLACK_ADMIN_CHANNEL || process.env.CORTEX_ADMIN_CHANNEL || undefined,
|
|
42
47
|
});
|
|
43
48
|
}
|
|
44
49
|
if (platform === 'feishu') {
|
|
45
50
|
const appId = process.env.FEISHU_APP_ID;
|
|
46
51
|
const appSecret = process.env.FEISHU_APP_SECRET;
|
|
47
52
|
if (!appId || !appSecret) {
|
|
48
|
-
|
|
53
|
+
return null;
|
|
49
54
|
}
|
|
50
55
|
return new FeishuAdapter({
|
|
51
56
|
appId,
|
|
52
57
|
appSecret,
|
|
53
58
|
encryptKey: process.env.FEISHU_ENCRYPT_KEY || undefined,
|
|
54
59
|
verificationToken: process.env.FEISHU_VERIFICATION_TOKEN || undefined,
|
|
55
|
-
|
|
60
|
+
// Feishu must NOT inherit CORTEX_ADMIN_CHANNEL (that is a Slack channel id).
|
|
61
|
+
// The admin/DM channel is auto-detected from the first p2p message and
|
|
62
|
+
// persisted as FEISHU_ADMIN_CHANNEL (see FeishuAdapter.handleIncomingMessage).
|
|
63
|
+
adminChannel: process.env.FEISHU_ADMIN_CHANNEL || undefined,
|
|
56
64
|
domain: process.env.FEISHU_DOMAIN || undefined,
|
|
57
65
|
});
|
|
58
66
|
}
|
|
59
67
|
if (platform === 'test') {
|
|
60
68
|
return new MockAdapter({ adminChannel: process.env.CORTEX_ADMIN_CHANNEL || 'test-admin' });
|
|
61
69
|
}
|
|
62
|
-
return
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Detect and create all primary (Slack / Feishu / test) adapters from
|
|
74
|
+
* environment variables. `CORTEX_PLATFORM` is a comma-separated list (e.g.
|
|
75
|
+
* `slack,feishu`); a single value is fully back-compatible. Platforms whose
|
|
76
|
+
* credentials are missing are silently skipped. Returns an empty array when no
|
|
77
|
+
* primary platform is configured — the caller falls back to TUI-only mode.
|
|
78
|
+
*/
|
|
79
|
+
export function createPrimaryAdaptersFromEnv() {
|
|
80
|
+
const raw = process.env.CORTEX_PLATFORM || 'slack';
|
|
81
|
+
const names = raw.split(',').map(s => s.trim().toLowerCase()).filter(Boolean);
|
|
82
|
+
const adapters = [];
|
|
83
|
+
const seen = new Set();
|
|
84
|
+
for (const name of names) {
|
|
85
|
+
if (seen.has(name))
|
|
86
|
+
continue;
|
|
87
|
+
seen.add(name);
|
|
88
|
+
const adapter = buildPrimaryAdapter(name);
|
|
89
|
+
if (adapter)
|
|
90
|
+
adapters.push(adapter);
|
|
91
|
+
}
|
|
92
|
+
return adapters;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Back-compat shim: return the first configured primary adapter, or null.
|
|
96
|
+
* Prefer createPrimaryAdaptersFromEnv() for multi-platform support.
|
|
97
|
+
*/
|
|
98
|
+
export function createPrimaryAdapterFromEnv() {
|
|
99
|
+
return createPrimaryAdaptersFromEnv()[0] ?? null;
|
|
100
|
+
}
|
|
101
|
+
// ─── TUI auto-enable logic ─────────────────────────────────────────────
|
|
102
|
+
/**
|
|
103
|
+
* Decide whether to enable the TUI gateway.
|
|
104
|
+
* - CORTEX_TUI='1' → enabled
|
|
105
|
+
* - CORTEX_TUI='0' → disabled
|
|
106
|
+
* - unset → enabled (auto; EADDRINUSE soft-fails cheaply)
|
|
107
|
+
*/
|
|
108
|
+
function decideTuiEnabled() {
|
|
109
|
+
const flag = process.env.CORTEX_TUI;
|
|
110
|
+
if (flag === '1')
|
|
111
|
+
return true;
|
|
112
|
+
if (flag === '0')
|
|
113
|
+
return false;
|
|
114
|
+
return true; // auto: default enabled
|
|
115
|
+
}
|
|
116
|
+
/** Return the configured TUI port (default 3003). */
|
|
117
|
+
function tuiPort() {
|
|
118
|
+
return Number(process.env.CORTEX_TUI_PORT) || 3003;
|
|
119
|
+
}
|
|
120
|
+
// ─── createAdapterFromEnv (rewritten with 4-branch logic) ──────────────
|
|
121
|
+
/**
|
|
122
|
+
* Create a PlatformAdapter from environment variables.
|
|
123
|
+
*
|
|
124
|
+
* Assembles all configured primary adapters (Slack/Feishu/test, per the
|
|
125
|
+
* comma-separated `CORTEX_PLATFORM`) plus an optional TUI gateway:
|
|
126
|
+
* no adapters → throw
|
|
127
|
+
* exactly one adapter → return it directly
|
|
128
|
+
* two or more adapters → CompositeAdapter([...])
|
|
129
|
+
*/
|
|
130
|
+
export function createAdapterFromEnv() {
|
|
131
|
+
const primaries = createPrimaryAdaptersFromEnv();
|
|
132
|
+
const tui = decideTuiEnabled() ? new TuiGatewayAdapter({ port: tuiPort() }) : null;
|
|
133
|
+
const all = [...primaries, ...(tui ? [tui] : [])];
|
|
134
|
+
if (all.length === 0) {
|
|
135
|
+
throw new Error('No platform configured. Set Slack/Feishu environment variables or enable CORTEX_TUI=1.');
|
|
136
|
+
}
|
|
137
|
+
if (all.length === 1) {
|
|
138
|
+
return all[0];
|
|
139
|
+
}
|
|
140
|
+
return new CompositeAdapter(all);
|
|
63
141
|
}
|
|
64
142
|
export { SlackAdapter } from './slack.js';
|
|
65
143
|
export { FeishuAdapter } from './feishu.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class ProjectConduitsStore {
|
|
2
|
+
private readonly _repo;
|
|
3
|
+
constructor(filePath?: string);
|
|
4
|
+
get(projectId: string): Promise<string | null>;
|
|
5
|
+
set(projectId: string, conduit: string): Promise<void>;
|
|
6
|
+
remove(projectId: string): Promise<void>;
|
|
7
|
+
getAll(): Promise<Record<string, string>>;
|
|
8
|
+
flush(): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// input: JsonRepository + STORE_DIR
|
|
2
|
+
// output: ProjectConduitsStore (projectId → conduit file-backed store)
|
|
3
|
+
// pos: Platform-agnostic file-backed project→conduit mapping. Slack defaults to
|
|
4
|
+
// channel-registry.json (backward compat); other adapters pass a distinct
|
|
5
|
+
// filePath (e.g. Feishu → feishu-channel-registry.json).
|
|
6
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
import { JsonRepository } from '../../core/json-repository.js';
|
|
9
|
+
import { STORE_DIR } from '../../core/paths.js';
|
|
10
|
+
const CHANNEL_REGISTRY_FILE = path.join(STORE_DIR, 'channel-registry.json');
|
|
11
|
+
export class ProjectConduitsStore {
|
|
12
|
+
_repo;
|
|
13
|
+
constructor(filePath) {
|
|
14
|
+
this._repo = new JsonRepository({
|
|
15
|
+
filePath: filePath ?? CHANNEL_REGISTRY_FILE,
|
|
16
|
+
defaultValue: () => ({}),
|
|
17
|
+
migrate: (raw) => (typeof raw === 'object' && raw !== null ? raw : ({})),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
async get(projectId) {
|
|
21
|
+
const data = await this._repo.read();
|
|
22
|
+
return data[projectId] ?? null;
|
|
23
|
+
}
|
|
24
|
+
async set(projectId, conduit) {
|
|
25
|
+
await this._repo.mutate((data) => {
|
|
26
|
+
data[projectId] = conduit;
|
|
27
|
+
return { next: data, result: undefined };
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async remove(projectId) {
|
|
31
|
+
await this._repo.mutate((data) => {
|
|
32
|
+
delete data[projectId];
|
|
33
|
+
return { next: data, result: undefined };
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
async getAll() {
|
|
37
|
+
return { ...(await this._repo.read()) };
|
|
38
|
+
}
|
|
39
|
+
flush() {
|
|
40
|
+
return this._repo.flush();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -1,9 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
private readonly _repo;
|
|
3
|
-
constructor(filePath?: string);
|
|
4
|
-
get(projectId: string): Promise<string | null>;
|
|
5
|
-
set(projectId: string, conduit: string): Promise<void>;
|
|
6
|
-
remove(projectId: string): Promise<void>;
|
|
7
|
-
getAll(): Promise<Record<string, string>>;
|
|
8
|
-
flush(): Promise<void>;
|
|
9
|
-
}
|
|
1
|
+
export { ProjectConduitsStore as SlackProjectConduitsStore } from './project-conduits.js';
|
|
@@ -1,40 +1,6 @@
|
|
|
1
|
-
// input:
|
|
2
|
-
// output: SlackProjectConduitsStore (
|
|
3
|
-
// pos:
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import { STORE_DIR } from '../../core/paths.js';
|
|
8
|
-
const CHANNEL_REGISTRY_FILE = path.join(STORE_DIR, 'channel-registry.json');
|
|
9
|
-
export class SlackProjectConduitsStore {
|
|
10
|
-
_repo;
|
|
11
|
-
constructor(filePath) {
|
|
12
|
-
this._repo = new JsonRepository({
|
|
13
|
-
filePath: filePath ?? CHANNEL_REGISTRY_FILE,
|
|
14
|
-
defaultValue: () => ({}),
|
|
15
|
-
migrate: (raw) => (typeof raw === 'object' && raw !== null ? raw : ({})),
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
async get(projectId) {
|
|
19
|
-
const data = await this._repo.read();
|
|
20
|
-
return data[projectId] ?? null;
|
|
21
|
-
}
|
|
22
|
-
async set(projectId, conduit) {
|
|
23
|
-
await this._repo.mutate((data) => {
|
|
24
|
-
data[projectId] = conduit;
|
|
25
|
-
return { next: data, result: undefined };
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
async remove(projectId) {
|
|
29
|
-
await this._repo.mutate((data) => {
|
|
30
|
-
delete data[projectId];
|
|
31
|
-
return { next: data, result: undefined };
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
async getAll() {
|
|
35
|
-
return { ...(await this._repo.read()) };
|
|
36
|
-
}
|
|
37
|
-
flush() {
|
|
38
|
-
return this._repo.flush();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
1
|
+
// input: ./project-conduits.js
|
|
2
|
+
// output: SlackProjectConduitsStore (backward-compat alias of ProjectConduitsStore)
|
|
3
|
+
// pos: Compat shim — the store is now platform-agnostic (project-conduits.ts).
|
|
4
|
+
// Kept so existing Slack imports resolve unchanged.
|
|
5
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
6
|
+
export { ProjectConduitsStore as SlackProjectConduitsStore } from './project-conduits.js';
|
|
@@ -31,6 +31,13 @@ export declare class SlackAdapter implements PlatformAdapter {
|
|
|
31
31
|
private rateLimiter;
|
|
32
32
|
constructor(config: SlackAdapterConfig);
|
|
33
33
|
private _envNum;
|
|
34
|
+
private static readonly PREFIX;
|
|
35
|
+
/** Add the `slack:` prefix (idempotent; passes through empty strings). */
|
|
36
|
+
private _wrap;
|
|
37
|
+
/** Strip the `slack:` prefix (tolerates already-bare values for back-compat). */
|
|
38
|
+
private _unwrap;
|
|
39
|
+
/** True if this conduit belongs to the Slack adapter. */
|
|
40
|
+
ownsConduit(conduit: string): boolean;
|
|
34
41
|
start(): Promise<void>;
|
|
35
42
|
stop(): Promise<void>;
|
|
36
43
|
onMessage(handler: (ctx: MessageContext) => Promise<void>): void;
|
|
@@ -71,11 +78,11 @@ export declare class SlackAdapter implements PlatformAdapter {
|
|
|
71
78
|
actions: ActionElement[];
|
|
72
79
|
}, opts?: PostMessageOpts): Promise<MessageRef>;
|
|
73
80
|
openModal(triggerId: string, modal: ModalDefinition): Promise<void>;
|
|
74
|
-
|
|
81
|
+
private _addHourglassReaction;
|
|
82
|
+
markQueued(ref: MessageRef): Promise<void>;
|
|
75
83
|
uploadFile(destination: Destination, filePath: string, opts?: FileUploadOpts): Promise<void>;
|
|
76
84
|
downloadFile(fileRef: PlatformFileRef, destDir: string): Promise<DownloadedFile>;
|
|
77
85
|
getPermalink(ref: MessageRef): Promise<string | null>;
|
|
78
|
-
postEphemeral(channel: string, userId: string, text: string): Promise<void>;
|
|
79
86
|
/** Write CORTEX_ADMIN_CHANNEL to the .env file for persistence across restarts. */
|
|
80
87
|
private _persistAdminChannel;
|
|
81
88
|
/** Expose the rate limiter for sharing with MCP tools and testing. */
|
|
@@ -33,7 +33,6 @@ export class SlackAdapter {
|
|
|
33
33
|
messageEdit: true,
|
|
34
34
|
modals: true,
|
|
35
35
|
reactions: true,
|
|
36
|
-
ephemeral: true,
|
|
37
36
|
fileUpload: true,
|
|
38
37
|
richFormatting: true,
|
|
39
38
|
maxMessageLength: 3000,
|
|
@@ -79,6 +78,32 @@ export class SlackAdapter {
|
|
|
79
78
|
const v = process.env[key];
|
|
80
79
|
return v ? Number(v) : def;
|
|
81
80
|
}
|
|
81
|
+
// --- Conduit prefixing ---
|
|
82
|
+
// The `slack:` prefix is this adapter's canonical external form for conduits.
|
|
83
|
+
// Outbound conduits (MessageRef.conduit, getProjectConduits values, incoming
|
|
84
|
+
// file conduits, triggerId) carry the prefix; inbound conduits (Destination,
|
|
85
|
+
// ref passed to update/delete, bindProjectConduit hint, triggerId) are
|
|
86
|
+
// unwrapped before calling the Slack SDK or reading/writing the bare-id
|
|
87
|
+
// registry. This lets multiple platform adapters coexist behind CompositeAdapter.
|
|
88
|
+
static PREFIX = 'slack:';
|
|
89
|
+
/** Add the `slack:` prefix (idempotent; passes through empty strings). */
|
|
90
|
+
_wrap(bare) {
|
|
91
|
+
if (!bare)
|
|
92
|
+
return bare;
|
|
93
|
+
return bare.startsWith(SlackAdapter.PREFIX) ? bare : SlackAdapter.PREFIX + bare;
|
|
94
|
+
}
|
|
95
|
+
/** Strip the `slack:` prefix (tolerates already-bare values for back-compat). */
|
|
96
|
+
_unwrap(prefixed) {
|
|
97
|
+
if (!prefixed)
|
|
98
|
+
return prefixed;
|
|
99
|
+
return prefixed.startsWith(SlackAdapter.PREFIX)
|
|
100
|
+
? prefixed.slice(SlackAdapter.PREFIX.length)
|
|
101
|
+
: prefixed;
|
|
102
|
+
}
|
|
103
|
+
/** True if this conduit belongs to the Slack adapter. */
|
|
104
|
+
ownsConduit(conduit) {
|
|
105
|
+
return conduit.startsWith(SlackAdapter.PREFIX);
|
|
106
|
+
}
|
|
82
107
|
// --- Lifecycle ---
|
|
83
108
|
async start() {
|
|
84
109
|
await this.app.start();
|
|
@@ -100,7 +125,7 @@ export class SlackAdapter {
|
|
|
100
125
|
if (editedMsg.text === previousMsg.text)
|
|
101
126
|
return;
|
|
102
127
|
await this.editHandler({
|
|
103
|
-
originalRef: {
|
|
128
|
+
originalRef: { conduit: this._wrap(msg.channel), messageId: editedMsg.ts },
|
|
104
129
|
newText: editedMsg.text || '',
|
|
105
130
|
raw: msg,
|
|
106
131
|
});
|
|
@@ -122,7 +147,7 @@ export class SlackAdapter {
|
|
|
122
147
|
}).catch(e => log.warn(`Failed to send admin auto-detect notification: ${e.message}`));
|
|
123
148
|
}
|
|
124
149
|
const ref = {
|
|
125
|
-
|
|
150
|
+
conduit: this._wrap(msg.channel),
|
|
126
151
|
messageId: msg.ts,
|
|
127
152
|
threadId: msg.thread_ts || undefined,
|
|
128
153
|
};
|
|
@@ -131,6 +156,7 @@ export class SlackAdapter {
|
|
|
131
156
|
name: f.name,
|
|
132
157
|
mimetype: f.mimetype,
|
|
133
158
|
url: f.url_private,
|
|
159
|
+
conduit: this._wrap(msg.channel),
|
|
134
160
|
raw: f,
|
|
135
161
|
}));
|
|
136
162
|
const attachments = msg.attachments?.map((att) => ({
|
|
@@ -139,6 +165,9 @@ export class SlackAdapter {
|
|
|
139
165
|
url: att.from_url,
|
|
140
166
|
isForwarded: !!(att.is_msg_unfurl || att.author_name || att.from_url),
|
|
141
167
|
}));
|
|
168
|
+
const kind = msg.subtype === undefined ? 'user'
|
|
169
|
+
: msg.subtype === 'file_share' ? 'file_share'
|
|
170
|
+
: 'system';
|
|
142
171
|
const incoming = {
|
|
143
172
|
ref,
|
|
144
173
|
text: msg.text || '',
|
|
@@ -146,14 +175,14 @@ export class SlackAdapter {
|
|
|
146
175
|
isBot: !!msg.bot_id,
|
|
147
176
|
files,
|
|
148
177
|
attachments,
|
|
149
|
-
|
|
178
|
+
kind,
|
|
150
179
|
raw: msg,
|
|
151
180
|
};
|
|
152
181
|
const adapter = this;
|
|
153
182
|
await handler({
|
|
154
183
|
message: incoming,
|
|
155
184
|
async reply(content, opts) {
|
|
156
|
-
return adapter.postMessage({ type: 'interactive-reply', conduit: ref.
|
|
185
|
+
return adapter.postMessage({ type: 'interactive-reply', conduit: ref.conduit, sessionId: '' }, content, {
|
|
157
186
|
threadId: opts?.threadId || ref.threadId,
|
|
158
187
|
});
|
|
159
188
|
},
|
|
@@ -169,13 +198,13 @@ export class SlackAdapter {
|
|
|
169
198
|
await handler({
|
|
170
199
|
actionId,
|
|
171
200
|
value: action.value,
|
|
172
|
-
triggerId: body.trigger_id,
|
|
201
|
+
triggerId: this._wrap(body.trigger_id),
|
|
173
202
|
messageRef: body.message?.ts ? {
|
|
174
|
-
|
|
203
|
+
conduit: this._wrap(body.channel?.id || ''),
|
|
175
204
|
messageId: body.message.ts,
|
|
176
205
|
} : undefined,
|
|
177
206
|
userId: body.user?.id || '',
|
|
178
|
-
channelId: body.channel?.id || '',
|
|
207
|
+
channelId: this._wrap(body.channel?.id || ''),
|
|
179
208
|
});
|
|
180
209
|
});
|
|
181
210
|
}
|
|
@@ -231,7 +260,7 @@ export class SlackAdapter {
|
|
|
231
260
|
async postMessage(destination, content, opts) {
|
|
232
261
|
const resolved = await this.resolveDestination(destination);
|
|
233
262
|
if (!resolved.channel) {
|
|
234
|
-
return {
|
|
263
|
+
return { conduit: '', messageId: '' };
|
|
235
264
|
}
|
|
236
265
|
const blocks = content.richBlocks ? this.richBlocksToSlack(content.richBlocks) : undefined;
|
|
237
266
|
const payload = {
|
|
@@ -242,7 +271,7 @@ export class SlackAdapter {
|
|
|
242
271
|
};
|
|
243
272
|
const result = await this.rateLimitedCall('chat.postMessage', resolved.channel, () => this.client.chat.postMessage(payload));
|
|
244
273
|
return {
|
|
245
|
-
|
|
274
|
+
conduit: this._wrap(resolved.channel),
|
|
246
275
|
messageId: result.ts,
|
|
247
276
|
threadId: opts?.threadId,
|
|
248
277
|
};
|
|
@@ -263,7 +292,8 @@ export class SlackAdapter {
|
|
|
263
292
|
* instead of recursing, which avoids coalescing confusion.
|
|
264
293
|
*/
|
|
265
294
|
async updateMessage(ref, content) {
|
|
266
|
-
const
|
|
295
|
+
const channel = this._unwrap(ref.conduit);
|
|
296
|
+
const key = `${channel}:${ref.messageId}`;
|
|
267
297
|
const existing = this.pendingEdits.get(key);
|
|
268
298
|
if (existing) {
|
|
269
299
|
// ── Coalesce ──
|
|
@@ -285,7 +315,7 @@ export class SlackAdapter {
|
|
|
285
315
|
// whether new content arrived during the send.
|
|
286
316
|
while (this.pendingEdits.has(key)) {
|
|
287
317
|
try {
|
|
288
|
-
await this.rateLimiter.acquire('chat.update',
|
|
318
|
+
await this.rateLimiter.acquire('chat.update', channel);
|
|
289
319
|
const entry = this.pendingEdits.get(key);
|
|
290
320
|
if (!entry) {
|
|
291
321
|
resolve();
|
|
@@ -294,7 +324,7 @@ export class SlackAdapter {
|
|
|
294
324
|
const snapshot = entry.content;
|
|
295
325
|
const blocks = snapshot.richBlocks ? this.richBlocksToSlack(snapshot.richBlocks) : undefined;
|
|
296
326
|
await this.client.chat.update({
|
|
297
|
-
channel
|
|
327
|
+
channel,
|
|
298
328
|
ts: ref.messageId,
|
|
299
329
|
text: snapshot.text,
|
|
300
330
|
...(blocks && { blocks }),
|
|
@@ -311,7 +341,7 @@ export class SlackAdapter {
|
|
|
311
341
|
catch (e) {
|
|
312
342
|
const retryAfterSec = Number(e?.retryAfter ?? e?.headers?.['retry-after']);
|
|
313
343
|
if (Number.isFinite(retryAfterSec) && retryAfterSec > 0) {
|
|
314
|
-
this.rateLimiter.reportThrottled('chat.update',
|
|
344
|
+
this.rateLimiter.reportThrottled('chat.update', channel, retryAfterSec);
|
|
315
345
|
// Entry stays in the map with latest coalesced content — just loop.
|
|
316
346
|
continue;
|
|
317
347
|
}
|
|
@@ -340,14 +370,15 @@ export class SlackAdapter {
|
|
|
340
370
|
async deleteMessage(ref) {
|
|
341
371
|
// Clean up any pending edit for this message so coalescing doesn't
|
|
342
372
|
// try to update a deleted message.
|
|
343
|
-
const
|
|
373
|
+
const channel = this._unwrap(ref.conduit);
|
|
374
|
+
const key = `${channel}:${ref.messageId}`;
|
|
344
375
|
const pending = this.pendingEdits.get(key);
|
|
345
376
|
if (pending) {
|
|
346
377
|
this.pendingEdits.delete(key);
|
|
347
378
|
pending.resolve();
|
|
348
379
|
}
|
|
349
|
-
await this.rateLimitedCall('chat.delete',
|
|
350
|
-
channel
|
|
380
|
+
await this.rateLimitedCall('chat.delete', channel, () => this.client.chat.delete({
|
|
381
|
+
channel,
|
|
351
382
|
ts: ref.messageId,
|
|
352
383
|
}));
|
|
353
384
|
}
|
|
@@ -355,7 +386,7 @@ export class SlackAdapter {
|
|
|
355
386
|
async postInteractive(destination, content, opts) {
|
|
356
387
|
const resolved = await this.resolveDestination(destination);
|
|
357
388
|
if (!resolved.channel) {
|
|
358
|
-
return {
|
|
389
|
+
return { conduit: '', messageId: '' };
|
|
359
390
|
}
|
|
360
391
|
const blocks = [
|
|
361
392
|
...(content.richBlocks ? this.richBlocksToSlack(content.richBlocks) : []),
|
|
@@ -371,7 +402,7 @@ export class SlackAdapter {
|
|
|
371
402
|
...(opts?.threadId && { thread_ts: opts.threadId }),
|
|
372
403
|
}));
|
|
373
404
|
return {
|
|
374
|
-
|
|
405
|
+
conduit: this._wrap(resolved.channel),
|
|
375
406
|
messageId: result.ts,
|
|
376
407
|
threadId: opts?.threadId,
|
|
377
408
|
};
|
|
@@ -379,18 +410,22 @@ export class SlackAdapter {
|
|
|
379
410
|
// --- Modals ---
|
|
380
411
|
async openModal(triggerId, modal) {
|
|
381
412
|
await this.rateLimitedCall('views.open', undefined, () => this.client.views.open({
|
|
382
|
-
trigger_id: triggerId,
|
|
413
|
+
trigger_id: this._unwrap(triggerId),
|
|
383
414
|
view: this.modalToSlack(modal),
|
|
384
415
|
}));
|
|
385
416
|
}
|
|
386
|
-
// ---
|
|
387
|
-
async
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
417
|
+
// --- Queue backpressure ---
|
|
418
|
+
async _addHourglassReaction(ref) {
|
|
419
|
+
const channel = this._unwrap(ref.conduit);
|
|
420
|
+
await this.rateLimitedCall('reactions.add', channel, () => this.client.reactions.add({
|
|
421
|
+
channel,
|
|
422
|
+
name: 'hourglass',
|
|
391
423
|
timestamp: ref.messageId,
|
|
392
424
|
}));
|
|
393
425
|
}
|
|
426
|
+
async markQueued(ref) {
|
|
427
|
+
await this._addHourglassReaction(ref);
|
|
428
|
+
}
|
|
394
429
|
// --- Files ---
|
|
395
430
|
async uploadFile(destination, filePath, opts) {
|
|
396
431
|
const resolved = await this.resolveDestination(destination);
|
|
@@ -458,7 +493,7 @@ export class SlackAdapter {
|
|
|
458
493
|
async getPermalink(ref) {
|
|
459
494
|
try {
|
|
460
495
|
const result = await this.client.chat.getPermalink({
|
|
461
|
-
channel: ref.
|
|
496
|
+
channel: this._unwrap(ref.conduit),
|
|
462
497
|
message_ts: ref.messageId,
|
|
463
498
|
});
|
|
464
499
|
return result?.permalink || null;
|
|
@@ -467,9 +502,6 @@ export class SlackAdapter {
|
|
|
467
502
|
return null;
|
|
468
503
|
}
|
|
469
504
|
}
|
|
470
|
-
async postEphemeral(channel, userId, text) {
|
|
471
|
-
await this.rateLimitedCall('chat.postEphemeral', channel, () => this.client.chat.postEphemeral({ channel, user: userId, text }));
|
|
472
|
-
}
|
|
473
505
|
/** Write CORTEX_ADMIN_CHANNEL to the .env file for persistence across restarts. */
|
|
474
506
|
async _persistAdminChannel(channel) {
|
|
475
507
|
const envPath = path.join(CONFIG_DIR, '.env');
|
|
@@ -506,18 +538,22 @@ export class SlackAdapter {
|
|
|
506
538
|
}
|
|
507
539
|
// --- Project conduit mapping ---
|
|
508
540
|
async bindProjectConduit(projectId, conduitHint) {
|
|
509
|
-
|
|
541
|
+
// Registry stores bare ids; strip the prefix before persisting.
|
|
542
|
+
await this._getConduitsStore().set(projectId, this._unwrap(conduitHint));
|
|
510
543
|
}
|
|
511
544
|
async unbindProjectConduit(projectId) {
|
|
512
545
|
await this._getConduitsStore().remove(projectId);
|
|
513
546
|
}
|
|
514
547
|
async getProjectConduits() {
|
|
515
|
-
|
|
548
|
+
// Registry stores bare ids; expose prefixed conduits externally.
|
|
549
|
+
const all = await this._getConduitsStore().getAll();
|
|
550
|
+
return Object.fromEntries(Object.entries(all).map(([project, ch]) => [project, this._wrap(ch)]));
|
|
516
551
|
}
|
|
517
552
|
async resolveInboundProject(conduit) {
|
|
553
|
+
const bare = this._unwrap(conduit);
|
|
518
554
|
const conduits = await this._getConduitsStore().getAll();
|
|
519
555
|
for (const [project, ch] of Object.entries(conduits)) {
|
|
520
|
-
if (ch ===
|
|
556
|
+
if (ch === bare)
|
|
521
557
|
return project;
|
|
522
558
|
}
|
|
523
559
|
return null;
|
|
@@ -537,15 +573,23 @@ export class SlackAdapter {
|
|
|
537
573
|
async resolveDestination(dest) {
|
|
538
574
|
switch (dest.type) {
|
|
539
575
|
case 'interactive-reply':
|
|
540
|
-
return { channel: dest.conduit, kind: 'interactive-reply' };
|
|
576
|
+
return { channel: this._unwrap(dest.conduit), kind: 'interactive-reply' };
|
|
541
577
|
case 'project-report': {
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
return { channel
|
|
578
|
+
// Read bare ids directly from the store (getProjectConduits wraps for
|
|
579
|
+
// external callers; the SDK needs the bare channel).
|
|
580
|
+
const channel = await this._getConduitsStore().get(dest.projectId);
|
|
581
|
+
if (channel) {
|
|
582
|
+
return { channel, kind: 'project-report' };
|
|
583
|
+
}
|
|
584
|
+
// Unbound project: fall back to this platform's admin DM so the report
|
|
585
|
+
// still surfaces here instead of being silently dropped. Each platform
|
|
586
|
+
// falls back independently (a project bound on another platform but not
|
|
587
|
+
// this one still reaches this platform's DM).
|
|
588
|
+
if (this.config.adminChannel) {
|
|
589
|
+
return { channel: this.config.adminChannel, kind: 'project-report-dm' };
|
|
547
590
|
}
|
|
548
|
-
|
|
591
|
+
log.warn(`No conduit or admin channel for project "${dest.projectId}"; dropping project-report`);
|
|
592
|
+
return { channel: null, kind: 'project-report-noop' };
|
|
549
593
|
}
|
|
550
594
|
case 'system-notice':
|
|
551
595
|
if (!this.config.adminChannel) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { TuiGatewayAdapter } from './tui-gateway.js';
|
|
2
|
+
export type { TuiAdapterControls } from './tui-gateway.js';
|
|
3
|
+
export { TuiConnection } from './tui-connection.js';
|
|
4
|
+
export { TuiOutputStream } from './tui-output-stream.js';
|
|
5
|
+
export { tuiConduitStates, getConduitState, setConduitState, deleteConduitState, hasConduitState, } from './tui-conduit-state.js';
|
|
6
|
+
export type { TuiConduitState } from './tui-conduit-state.js';
|
|
7
|
+
export { sendProjectReport, sendSystemNotice } from './tui-notifications.js';
|
|
8
|
+
export { buildTranscriptReplay } from './tui-transcript.js';
|
|
9
|
+
export type { TranscriptTurn, TranscriptData } from './ports.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// input: all tui/ modules
|
|
2
|
+
// output: barrel — TuiGatewayAdapter + TuiConnection + helpers
|
|
3
|
+
// pos: TUI adapter public API
|
|
4
|
+
// >>> If I am updated, update the folder's CORTEX.md <<<
|
|
5
|
+
export { TuiGatewayAdapter } from './tui-gateway.js';
|
|
6
|
+
export { TuiConnection } from './tui-connection.js';
|
|
7
|
+
export { TuiOutputStream } from './tui-output-stream.js';
|
|
8
|
+
export { tuiConduitStates, getConduitState, setConduitState, deleteConduitState, hasConduitState, } from './tui-conduit-state.js';
|
|
9
|
+
export { sendProjectReport, sendSystemNotice } from './tui-notifications.js';
|
|
10
|
+
export { buildTranscriptReplay } from './tui-transcript.js';
|