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.

1.4 KB
Raw Blame
import { nativeChatApprovalAcceptKey } from './native-chat-agent-support'

/** The facts in a status row's `{ approval: { tool, summary } }` envelope; callers own labels. */
export type NativeChatApprovalEnvelope = {
  tool: string
  summary?: string
  /** Keys that answer the agent's default TUI approval prompt. */
  allowSend: string
  denySend: string
}

const ESCAPE = String.fromCharCode(27)

/** Read the approval envelope published in agentStatus.interactivePrompt on PermissionRequest. */
export function parseNativeChatApprovalEnvelope(
  interactivePrompt: string | undefined | null,
  agent?: string
): NativeChatApprovalEnvelope | null {
  if (!interactivePrompt) {
    return null
  }
  let parsed: unknown
  try {
    parsed = JSON.parse(interactivePrompt)
  } catch {
    return null
  }
  if (typeof parsed !== 'object' || parsed === null || !('approval' in parsed)) {
    return null
  }
  const approval = parsed.approval
  if (typeof approval !== 'object' || approval === null || !('tool' in approval)) {
    return null
  }
  const tool = approval.tool
  if (typeof tool !== 'string' || tool.length === 0) {
    return null
  }
  const summary = 'summary' in approval ? approval.summary : undefined
  return {
    tool,
    ...(typeof summary === 'string' && summary.length > 0 ? { summary } : {}),
    allowSend: nativeChatApprovalAcceptKey(agent),
    denySend: ESCAPE
  }
}