{"version":3,"file":"auth.cjs","names":[],"sources":["../../src/types/auth.ts"],"sourcesContent":["/**\n * Wire vocabulary for provider authentication, shared by the hub routes and\n * the settings page.\n *\n * The hub keeps one Pi ModelRuntime over the same auth.json the sessions\n * read, so a login here is a login for every session on this machine. Prompt\n * and event shapes restate pi-ai's AuthPrompt and AuthEvent so neither the\n * flow service nor the page needs a pi import; the abort signal never leaves\n * the hub.\n */\n\n/** REST endpoint listing providers with their auth state; DELETE /:providerId signs out. */\nexport const AUTH_PROVIDERS_API_ROUTE = '/api/plugins/po/providers';\n/** REST endpoint for login flows: POST starts one, GET /:flowId polls it, POST /:flowId/answer answers its prompt, DELETE /:flowId cancels. */\nexport const AUTH_LOGINS_API_ROUTE = '/api/plugins/po/logins';\n\nexport type AuthMethodType = 'api_key' | 'oauth';\n\nexport interface ProviderAuthMethod {\n  type: AuthMethodType;\n  /** What the provider calls this method: \"Anthropic API key\", \"Anthropic (Claude Pro/Max)\". */\n  label: string;\n}\n\nexport interface ProviderAuthSummary {\n  id: string;\n  name: string;\n  /** Login methods the provider offers; ambient-only providers list none. */\n  methods: ProviderAuthMethod[];\n  /**\n   * Present once the provider has working auth: how, and where the credential\n   * comes from (\"stored\", or the environment variable that holds the key).\n   */\n  authenticated?: { type: AuthMethodType; source?: string };\n  /** Set for Po's own shared sign-in, which serves Po features rather than chat models. */\n  kind?: 'po-feature';\n}\n\nexport interface LoginSelectOption {\n  id: string;\n  label: string;\n  description?: string;\n}\n\n/** pi-ai's AuthPrompt, restated. `signal` cancels this one question, not the flow. */\nexport type LoginPrompt = { signal?: AbortSignal } & (\n  | { type: 'text'; message: string; placeholder?: string }\n  | { type: 'secret'; message: string; placeholder?: string }\n  | { type: 'select'; message: string; options: readonly LoginSelectOption[] }\n  | { type: 'manual_code'; message: string; placeholder?: string }\n);\n\n/** The question the page answers: a prompt with an id and without its signal. */\nexport interface LoginPromptView {\n  id: string;\n  type: LoginPrompt['type'];\n  message: string;\n  placeholder?: string;\n  /** Present for select prompts. */\n  options?: LoginSelectOption[];\n}\n\n/** pi-ai's AuthEvent, restated. */\nexport type LoginEvent =\n  | { type: 'info'; message: string; links?: readonly { url: string; label?: string }[] }\n  | { type: 'auth_url'; url: string; instructions?: string }\n  | {\n      type: 'device_code';\n      userCode: string;\n      verificationUri: string;\n      intervalSeconds?: number;\n      expiresInSeconds?: number;\n    }\n  | { type: 'progress'; message: string };\n\nexport type LoginFlowStatus = 'running' | 'succeeded' | 'failed' | 'cancelled';\n\nexport interface LoginFlowSnapshot {\n  id: string;\n  providerId: string;\n  providerName: string;\n  type: AuthMethodType;\n  status: LoginFlowStatus;\n  events: LoginEvent[];\n  /** The question the flow is waiting on, while there is one. */\n  prompt?: LoginPromptView;\n  /**\n   * The login was started from the tunnel. The page uses this to explain that\n   * the provider's redirect lands on a loopback address this browser cannot\n   * reach, so the code has to be pasted back.\n   */\n  remote?: boolean;\n  /** HTTP-only hosts request periodic reads; omitted when the hub pushes provider revisions. */\n  pollIntervalMs?: number;\n  /** Why the flow failed, once it has. */\n  error?: string;\n}\n\n/** pi-ai's AuthInteraction: what a provider's login needs from its host. */\nexport interface LoginInteraction {\n  signal: AbortSignal;\n  prompt(prompt: LoginPrompt): Promise<string>;\n  notify(event: LoginEvent): void;\n}\n\nexport interface AuthRuntimeProvider {\n  readonly id: string;\n  readonly name: string;\n  readonly auth: {\n    /** Absent `login` means ambient-only (env vars, AWS profiles): nothing to sign in to. */\n    apiKey?: { name: string; login?: unknown };\n    oauth?: { name: string; loginLabel?: string };\n  };\n}\n\n/**\n * The slice of Pi's ModelRuntime the hub relies on, so a test can stand in a\n * fake and the adapter never types against the whole agent.\n */\nexport interface AuthRuntime {\n  getProviders(): readonly AuthRuntimeProvider[];\n  getProviderAuthStatus(providerId: string): { configured: boolean; source?: string; label?: string };\n  /** Models the runtime already knows about, without touching the network. */\n  getAvailableSnapshot(): readonly { provider: string; id: string }[];\n  hasConfiguredAuth(providerId: string): boolean;\n  isUsingOAuth(providerId: string): boolean;\n  /** Re-reads models.json and every provider's auth state without touching the network. */\n  refresh(options: { allowNetwork: boolean }): Promise<unknown>;\n  login(providerId: string, type: AuthMethodType, interaction: LoginInteraction): Promise<unknown>;\n  logout(providerId: string, options?: { signal?: AbortSignal }): Promise<void>;\n}\n"],"mappings":";;;;;;;;;;;;AAYA,MAAa,2BAA2B;;AAExC,MAAa,wBAAwB"}