Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

872 B
Raw Blame
import type { CandidateDestination, Destination } from "../types.ts";
import type { CapabilityClaims } from "../auth/capability-token.ts";

const stripCandidate = (c: CandidateDestination): Destination => ({
  type: c.type,
  target: c.target,
  ...(c.audienceScopeId ? { audienceScopeId: c.audienceScopeId } : {}),
});

export function resolveCapabilityDestination(
  cap: CapabilityClaims,
  destinationKey: string | undefined,
): { ok: true; destination: Destination | undefined } | { ok: false } {
  if (destinationKey !== undefined) {
    const chosen = cap.destinations?.find((d) => d.key === destinationKey);
    return chosen ? { ok: true, destination: stripCandidate(chosen) } : { ok: false };
  }
  const def = cap.destinations?.find((d) => d.key === cap.defaultDestinationKey);
  return { ok: true, destination: def ? stripCandidate(def) : cap.destination };
}