/** * Self-contained Bailian console login: the plugin drives the console's browser * login itself and persists what comes back, rather than shelling out to the * `bl` CLI. * * Driving the flow here lets it always request a freshly issued api key, so the * key and the workspace id both come from the account that just signed in, and * the values land straight in the dsh stores. * * Shape of the flow: bind a loopback-only port, open the console login page * pointed at that port, then accept one callback carrying the credentials as * query parameters or a JSON / form-encoded body. */ /** Credentials the console callback can carry. */ export interface ConsoleLoginCredentials { /** Freshly issued DashScope api key. */ apiKey?: string; /** Workspace id of the account that signed in. */ workspaceId?: string; } /** * Where the login flow stands. Deliberately carries no secret: the plain key * is handed to the completion callback and never retained here, so polling * this state from the browser cannot leak it. */ export type ConsoleLoginState = { phase: "idle"; } | { phase: "waiting"; loginUrl: string; } | { phase: "done"; fields: string[]; } | { phase: "failed"; reason: string; }; /** Read the current flow state (safe to expose to the panel). */ export declare function consoleLoginState(): ConsoleLoginState; /** * Parse a callback body as JSON (optionally wrapped in `data`) or as form * encoding. Content-type is a hint only: both shapes occur in practice, so both * are attempted. * @param raw - the raw request body. * @returns the flattened fields; an unparseable body yields no fields. */ export declare function parseCallbackBody(raw: string): Record; /** * Pick the api key and workspace id out of a callback's fields, query * parameters taking priority over the body. * @param query - the callback URL's query parameters. * @param body - the parsed callback body. * @returns the credentials found; fields are absent rather than blank. */ export declare function pickCallbackCredentials(query: Record, body: Record): ConsoleLoginCredentials; /** * Command that opens `target` with the OS default handler. * On Windows, `cmd.exe` splits an unquoted `&`, so `needapikey=true` never * reaches the browser. See `buildOpenInvocation` in the commands package. */ export declare function buildOpenInvocation(target: string, platform?: NodeJS.Platform): { command: string; args: string[]; windowsVerbatimArguments?: boolean; }; /** Outcome of asking the host to start a console login. */ export type ConsoleLoginStart = { status: "started"; loginUrl: string; } | { status: "already-running"; loginUrl: string; } | { status: "failed"; reason: string; }; /** * Start a console login on the host: binds a loopback listener, opens the * console login page in the host's default browser, and hands the credentials * from the callback to `onComplete` (which persists them). Fire-and-forget — * this resolves once the browser has been opened; poll {@link consoleLoginState} * for the outcome. * @param opts.site - console site, `domestic` (default) or `international`. * @param opts.onComplete - persists the received credentials; its resolved * field names become the `done` state's `fields`. * @returns whether the flow started, plus the URL to open manually if needed. */ export declare function startConsoleLogin(opts: { site?: string; onComplete: (credentials: ConsoleLoginCredentials) => Promise; }): Promise; /** Abandon an in-flight login (closes the listener). */ export declare function cancelConsoleLogin(): void;