Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

4.2 KB
Raw Blame
import { ipcRenderer } from 'electron'
import type {
  AgentStatusCacheIdentity,
  AgentStatusClearIpcPayload,
  AgentStatusIpcPayload,
  MigrationUnsupportedPtyEntry
} from '../../shared/agent-status-types'
import type { AgentInterruptInferenceRequest } from '../../shared/agent-interrupt-intent'
import type { AgentQuestionAnsweredInferenceRequest } from '../../shared/agent-question-answered-intent'
import type { PreloadApi } from '../api-types'

export const agentStatusApi = {
  onSet: (callback: (data: AgentStatusIpcPayload) => void): (() => void) => {
    const listener = (_event: Electron.IpcRendererEvent, data: AgentStatusIpcPayload) =>
      callback(data)
    ipcRenderer.on('agentStatus:set', listener)
    return () => ipcRenderer.removeListener('agentStatus:set', listener)
  },
  onClear: (callback: (data: AgentStatusClearIpcPayload) => void): (() => void) => {
    const listener = (_event: Electron.IpcRendererEvent, data: AgentStatusClearIpcPayload) =>
      callback(data)
    ipcRenderer.on('agentStatus:clear', listener)
    return () => ipcRenderer.removeListener('agentStatus:clear', listener)
  },
  getSnapshot: (): Promise<AgentStatusIpcPayload[]> =>
    ipcRenderer.invoke('agentStatus:getSnapshot'),
  inferInterrupt: (request: AgentInterruptInferenceRequest): Promise<boolean> =>
    ipcRenderer.invoke('agentStatus:inferInterrupt', request),
  hasVerifiableAgentProcess: (paneKey: string): Promise<boolean> =>
    ipcRenderer.invoke('agentStatus:hasVerifiableAgentProcess', paneKey),
  inferQuestionAnswered: (request: AgentQuestionAnsweredInferenceRequest): Promise<boolean> =>
    ipcRenderer.invoke('agentStatus:inferQuestionAnswered', request),
  onMigrationUnsupported: (
    callback: (entry: MigrationUnsupportedPtyEntry) => void
  ): (() => void) => {
    const listener = (_event: Electron.IpcRendererEvent, entry: MigrationUnsupportedPtyEntry) =>
      callback(entry)
    ipcRenderer.on('agentStatus:migrationUnsupported', listener)
    return () => ipcRenderer.removeListener('agentStatus:migrationUnsupported', listener)
  },
  onMigrationUnsupportedClear: (callback: (data: { ptyId: string }) => void): (() => void) => {
    const listener = (_event: Electron.IpcRendererEvent, data: { ptyId: string }) => callback(data)
    ipcRenderer.on('agentStatus:migrationUnsupportedClear', listener)
    return () => ipcRenderer.removeListener('agentStatus:migrationUnsupportedClear', listener)
  },
  onLegacyWorkerTerminalRecovery: (
    callback: (data: {
      paneKey: string
      resolution: 'adopted' | 'exited' | 'rolled_back'
      ptyId?: string
    }) => void
  ): (() => void) => {
    const listener = (
      _event: Electron.IpcRendererEvent,
      data: {
        paneKey: string
        resolution: 'adopted' | 'exited' | 'rolled_back'
        ptyId?: string
      }
    ) => callback(data)
    ipcRenderer.on('agentStatus:legacyWorkerTerminalRecovery', listener)
    return () => ipcRenderer.removeListener('agentStatus:legacyWorkerTerminalRecovery', listener)
  },
  getMigrationUnsupportedSnapshot: (): Promise<MigrationUnsupportedPtyEntry[]> =>
    ipcRenderer.invoke('agentStatus:getMigrationUnsupportedSnapshot'),
  drop: (paneKey: string): void => {
    ipcRenderer.send('agentStatus:drop', paneKey)
  },
  dropPersisted: (identity: AgentStatusCacheIdentity): void => {
    ipcRenderer.send('agentStatus:dropPersisted', identity)
  },
  dropPersistedBatch: (identities: readonly AgentStatusCacheIdentity[]): void => {
    ipcRenderer.send('agentStatus:dropPersistedBatch', identities)
  },
  reconcileEndedProcess: (paneKey: string): void => {
    ipcRenderer.send('agentStatus:reconcileEndedProcess', paneKey)
  },
  dropByTabPrefix: (tabId: string): void => {
    ipcRenderer.send('agentStatus:dropByTabPrefix', tabId)
  },
  retirePaneAuthority: (paneKey: string, retirementId?: string): void => {
    ipcRenderer.send('agentStatus:retirePaneAuthority', paneKey, retirementId)
  },
  restorePaneAuthority: (paneKey: string): void => {
    ipcRenderer.send('agentStatus:restorePaneAuthority', paneKey)
  },
  transferPaneAuthority: (args: {
    fromPaneKey: string
    toPaneKey: string
    ptyId?: string
  }): void => {
    ipcRenderer.send('agentStatus:transferPaneAuthority', args)
  }
} satisfies PreloadApi['agentStatus']