Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

704 B
Raw Blame
import type { QuestionControlHost } from '../facets/questionControl.js'
import { questionControlEnvelope, type QuestionControlAction } from './questionControlProtocol.js'

export function createQuestionControlHost(ask: (action: QuestionControlAction) => Promise<Record<string, unknown>>): QuestionControlHost {
  const call = async (action: QuestionControlAction) => {
    const reply = await ask(action)
    if (!questionControlEnvelope(reply, ['value', 'error']) || reply.error !== undefined || typeof reply.value !== 'boolean') throw new Error('question control unavailable')
    return reply.value
  }
  return { key: key => call({ kind: 'key', key }), text: text => call({ kind: 'text', text }) }
}