import type { CorpConfig } from "../../core/config/types.js"; import type { createSealClient } from "../../core/http/factory.js"; import { runTool } from "../helpers.js"; import { stringOption } from "../parser.js"; import { outputOptions } from "../printer.js"; import type { ParsedArgs } from "../types.js"; export async function handleDelegationCommand( action: string | undefined, maybeName: string | undefined, client: Awaited>, corp: CorpConfig, args: ParsedArgs ) { if (action === "list") { await runTool("seal_delegation_list", client, corp, {}, outputOptions(args.options)); return; } if (action === "create") { const note = stringOption(args.options.note) ?? (maybeName ? [maybeName, ...args.command.slice(2)].join(" ") : undefined); await runTool("seal_delegation_create", client, corp, { note }, outputOptions(args.options)); return; } if (action === "revoke") { const tokenId = maybeName ?? stringOption(args.options.tokenId); if (!tokenId) throw new Error("Usage: seal-home delegation revoke "); await runTool("seal_delegation_revoke", client, corp, { tokenId }, outputOptions(args.options)); return; } throw new Error(`Unknown delegation command: ${action ?? ""}. Run 'seal-home help' for available commands.`); }