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.

2.6 KB
Raw Blame
/** Advertised agentSession.agents lists registered agents/capabilities before sessions exist. Drop unreadable rows individually; unknown capability arms degrade to the least authority. */

import { z } from 'zod'
import type { AgentSessionCapabilities } from '../agent-session-capabilities'
import { isStructuredAgentId } from '../agent-session-provider-handle-encoding'
import { openEnum } from '../zod-salvage'

export const AGENT_SESSION_AGENTS_METHOD = 'agentSession.agents'

export type AgentSessionRegisteredAgent = {
  agent: string
  capabilities: AgentSessionCapabilities
  /** Host-provided program needs no installed CLI; older hosts omit this and require CLI detection. */
  managedRuntime?: true
}

export type AgentSessionAgentsResult = {
  agents: AgentSessionRegisteredAgent[]
}

/** Bounds one reply; no host registers anywhere near this many agents. */
const MAX_REGISTERED_AGENTS = 128

// An absent flag is a capability the host did not claim.
const capabilityFlag = z.boolean().optional().default(false)

const registeredAgentSchema = z.object({
  agent: z.string().refine(isStructuredAgentId),
  capabilities: z.object({
    rewind: capabilityFlag,
    compact: capabilityFlag,
    threadGoal: capabilityFlag,
    contextUsage: capabilityFlag,
    imagePrompts: capabilityFlag,
    // Holding a follow-up until the turn ends never interrupts one the client cannot reason about.
    steering: openEnum(['inject', 'queue'] as const, 'queue')
      .optional()
      .default('queue'),
    // `orca` claims only that Orca answers the agent's requests, never that it confines the agent.
    approvalEnforcement: openEnum(['provider', 'orca'] as const, 'orca')
      .optional()
      .default('orca')
  }),
  // A false from a host reads as absent, so the row keeps the detection-based offer.
  managedRuntime: z.literal(true).optional().catch(undefined)
})

/** The host's agents as this build reads them, or null when the reply is not an agent list. */
export function decodeAgentSessionAgentsResult(
  value: unknown
): AgentSessionRegisteredAgent[] | null {
  if (typeof value !== 'object' || value === null || !('agents' in value)) {
    return null
  }
  const { agents } = value
  if (!Array.isArray(agents)) {
    return null
  }
  const seen = new Set<string>()
  const decoded: AgentSessionRegisteredAgent[] = []
  for (const row of agents.slice(0, MAX_REGISTERED_AGENTS)) {
    const parsed = registeredAgentSchema.safeParse(row)
    if (parsed.success && !seen.has(parsed.data.agent)) {
      seen.add(parsed.data.agent)
      decoded.push(parsed.data)
    }
  }
  return decoded
}