Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

892 B
Raw Blame
import {
  attachInputDeviceActionBridge,
  dispatchInputDeviceAction,
  subscribeInputDeviceAction,
  type InputDeviceActionHandler,
} from './inputDeviceActions';

export type WorkLouderCodexActionHandler = InputDeviceActionHandler;

let bridged = false;

/**
 * Codex Micro still owns the preload channel. The subscriber set is shared
 * so a later keyboard can attach another bridge without a second bus.
 */
export function subscribeWorkLouderCodexAction(handler: InputDeviceActionHandler): () => void {
  ensureCodexMicroBridge();
  return subscribeInputDeviceAction(handler);
}

function ensureCodexMicroBridge(): void {
  if (bridged) return;
  bridged = true;
  attachInputDeviceActionBridge(
    () =>
      window.electronAPI?.workLouderCodex?.onAction((action) => {
        if (action.type === 'keycap') return;
        dispatchInputDeviceAction(action);
      }) ?? null,
  );
}