| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- import type {
- createCodingPlanApiKeyResolver,
- createCliOAuthClient,
- BrowserOpenResult,
- CliOAuthInitData,
- CliOAuthPollData,
- CliOAuthUser,
- SharedZCodeCredentialStore,
- } from "@zcode/adapters";
- import type { EnvRecord } from "@zcode/adapters/model";
- export type CodingPlanProviderId = "bigmodel" | "zai";
- export interface LoginZCodeCliOptions {
- providerId?: CodingPlanProviderId;
- abortSignal?: AbortSignal;
- apiKeyResolver?: ReturnType<typeof createCodingPlanApiKeyResolver>;
- baseUrl?: string;
- credentialStore?: SharedZCodeCredentialStore;
- env?: EnvRecord;
- httpClient?: Parameters<typeof createCliOAuthClient>[0]["httpClient"];
- noBrowser?: boolean;
- now?: () => number;
- onAuthorizeUrl?: (data: CliOAuthInitData) => void | Promise<void>;
- onBrowserOpen?: (result: BrowserOpenResult) => void | Promise<void>;
- onPollStatus?: (data: CliOAuthPollData) => void | Promise<void>;
- openBrowser?: (url: string) => Promise<BrowserOpenResult>;
- pollToken?: string;
- sleep?: (ms: number) => Promise<void>;
- timeoutMs?: number;
- personalProviderConfigPath?: string;
- }
- export interface LoginZCodeCliResult {
- browser?: BrowserOpenResult;
- configPath: string;
- credentialsPath: string;
- model: string;
- providerId: CodingPlanProviderId;
- user: CliOAuthUser;
- }
- // BigModel 与 Z.ai 共用服务端轮询登录,只是 providerId 固定为 bigmodel。
- export type LoginBigmodelCodingPlanOptions = Omit<LoginZCodeCliOptions, "providerId">;
- export type LoginBigmodelCodingPlanResult = LoginZCodeCliResult & { providerId: "bigmodel" };
- export interface ConfigureCodingPlanApiKeyOptions {
- apiKey: string;
- credentialStore?: SharedZCodeCredentialStore;
- env?: EnvRecord;
- personalProviderConfigPath?: string;
- providerId: CodingPlanProviderId;
- }
- export interface ConfigureCodingPlanApiKeyResult {
- configPath: string;
- model: string;
- providerId: CodingPlanProviderId;
- }
- export interface LogoutZCodeCliOptions {
- credentialStore?: SharedZCodeCredentialStore;
- env?: EnvRecord;
- }
- export interface LogoutZCodeCliResult {
- credentialsPath: string;
- }
- export class ZCodeCliLoginError extends Error {
- readonly code:
- | "auth_failed"
- | "auth_timeout"
- | "config_update_failed"
- | "credential_write_failed";
- constructor(
- code: ZCodeCliLoginError["code"],
- message: string,
- options: { cause?: unknown } = {},
- ) {
- super(message, options);
- this.name = "ZCodeCliLoginError";
- this.code = code;
- }
- }
|