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.

914 B
Raw Blame
type RpcRequestBudgetOptions = {
  timeoutMs?: number
  budgetSpansConnect?: boolean
}

export type RpcRequestBudget = {
  startedAt: number
  timeoutMs?: number
  deadline: number | null
}

export const RPC_REQUEST_MIN_ACK_MS = 1_000

export function openRpcRequestBudget(
  options?: RpcRequestBudgetOptions,
  now = Date.now()
): RpcRequestBudget {
  const timeoutMs = options?.timeoutMs
  return {
    startedAt: now,
    ...(timeoutMs === undefined ? {} : { timeoutMs }),
    deadline: options?.budgetSpansConnect && timeoutMs !== undefined ? now + timeoutMs : null
  }
}

export function resolvePostConnectRequestTimeout(
  budget: RpcRequestBudget,
  fallbackMs: number,
  now = Date.now()
): number {
  if (budget.deadline === null) {
    return budget.timeoutMs ?? fallbackMs
  }
  return Math.max(
    Math.min(RPC_REQUEST_MIN_ACK_MS, budget.deadline - budget.startedAt),
    budget.deadline - now
  )
}