Skip to content

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode,DeepSeek Harness and more. Only official website: ccswitch.io

2.1 KB
Raw Blame
import { invoke } from "@tauri-apps/api/core";

export interface DshAccountProfile {
  id: string | null;
  name: string | null;
  /** 平台返回的脱敏手机号或邮箱 */
  contact: string | null;
  avatarUrl: string | null;
}

export interface DshWallet {
  currency: "CNY" | "USD" | string;
  /** 十进制字符串,原样来自平台 */
  balance: string;
}

/**
 * DeepSeek 账号(OAuth)登录:存在 `$DSH_HOME/.credentials.yaml`,DeepSeek Harness 的
 * Web 和 Desktop 共用同一份,任一端登录 / 退出两端同时生效。
 */
export interface DshAccountStatus {
  signedIn: boolean;
  /** 平台拒绝了保存的登录(已过期),DeepSeek Harness 下次请求账号时会清掉 */
  expired: boolean;
  issuer: string | null;
  /** SHA-256 of the stored token; issuer is only the platform origin. */
  grantFingerprint: string | null;
  profile: DshAccountProfile | null;
  /** 充值余额 */
  wallets: DshWallet[];
  /** 赠金余额(只列大于 0 的) */
  bonusWallets: DshWallet[];
  usageUrl: string | null;
  topUpUrl: string | null;
  /** 资料或余额没查到;登录本身还在 */
  error: string | null;
  /** 这次去平台查了资料和余额;false 时只读了本机登录(只手动查询) */
  queried: boolean;
}

export interface DshLoginStart {
  flowId: string;
  /** Platform 的授权页(`https://platform.deepseek.com/dsh/authorize?...`) */
  authUrl: string;
  expiresIn: number;
}

export const dshApi = {
  /** `remote` 为 false 时不联网,只读本机登录 */
  accountStatus: (remote: boolean) =>
    invoke<DshAccountStatus>("dsh_account_status", { remote }),
  /** Web 和 Desktop 同时退出 */
  accountSignOut: () => invoke<void>("dsh_account_sign_out"),
  /** 和 DeepSeek Harness Web 同一套浏览器登录;登录写进 Web 与 Desktop 共用的凭据文件 */
  loginStart: () => invoke<DshLoginStart>("dsh_account_login_start"),
  /** 还在等浏览器时是 false,登录已保存时是 true */
  loginPoll: (flowId: string) =>
    invoke<boolean>("dsh_account_login_poll", { flowId }),
  loginCancel: (flowId: string) =>
    invoke<void>("dsh_account_login_cancel", { flowId }),
};