manager.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import type { PluginInput } from '@opencode-ai/plugin';
  2. import type { PluginConfig } from '../config';
  3. import { DEFAULT_DASHBOARD_PORT } from './dashboard';
  4. import { createDashboardManager } from './dashboard-manager';
  5. import { createPerSessionInterviewServer } from './session-server';
  6. export function createInterviewManager(
  7. ctx: PluginInput,
  8. config: PluginConfig,
  9. ): {
  10. registerCommand: (config: Record<string, unknown>) => void;
  11. handleCommandExecuteBefore: (
  12. input: { command: string; sessionID: string; arguments: string },
  13. output: { parts: Array<{ type: string; text?: string }> },
  14. ) => Promise<void>;
  15. handleEvent: (input: {
  16. event: { type: string; properties?: Record<string, unknown> };
  17. }) => Promise<void>;
  18. } {
  19. const interviewConfig = config.interview;
  20. const effectivePort = interviewConfig?.port ?? 0;
  21. const dashboardEnabled =
  22. interviewConfig?.dashboard === true || effectivePort > 0;
  23. const outputFolder = interviewConfig?.outputFolder ?? 'interview';
  24. // ─── Per-session mode (upstream behavior) ───────────────────────
  25. if (!dashboardEnabled) {
  26. return createPerSessionInterviewServer(ctx, interviewConfig, outputFolder);
  27. }
  28. // ─── Dashboard mode ─────────────────────────────────────────────
  29. const dashboardPort =
  30. effectivePort > 0 ? effectivePort : DEFAULT_DASHBOARD_PORT;
  31. return createDashboardManager(ctx, config, dashboardPort, outputFolder);
  32. }