mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-10-05 20:44:07 +08:00
41 lines
2.4 KiB
TypeScript
41 lines
2.4 KiB
TypeScript
import { createContext, useContext, type ReactNode } from "react";
|
|
import { useAppStore } from "../../store/appStore";
|
|
import controls from "../ui/Controls.module.scss";
|
|
import styles from "./CursorSettings.module.scss";
|
|
|
|
const CaReady = createContext(false);
|
|
const ModelsReady = createContext(false);
|
|
|
|
export function CursorCaProvider({ children }: { children: ReactNode }) {
|
|
const { cursorHarness } = useAppStore();
|
|
return <CaReady.Provider value={cursorHarness?.ca === "ready"}>{children}</CaReady.Provider>;
|
|
}
|
|
|
|
export function CursorCaGate({ busy, waitingForRefresh, onInitialize, onRefresh, children }: { busy: boolean; waitingForRefresh: boolean; onInitialize: () => void; onRefresh: () => void; children: ReactNode }) {
|
|
const ready = useContext(CaReady);
|
|
const { cursorHarness } = useAppStore();
|
|
if (ready) return children;
|
|
const unsupported = cursorHarness?.ca === "unsupported";
|
|
const installedLocally = cursorHarness?.ca === "untrusted";
|
|
return <div className={styles.gate}>
|
|
<strong>{unsupported ? t("当前系统暂不支持安装 CA") : installedLocally ? t("需要在系统中信任本地 CA") : t("需要先初始化本地 CA")}</strong>
|
|
<span>{unsupported ? t("请使用 macOS 或 Windows。") : installedLocally ? t("请在终端中粘贴授权命令并输入密码,完成后点击下方按钮") : t("CA 仅保存在本机,用于安全解析 Cursor 的 HTTPS 请求。")}</span>
|
|
{!unsupported && <button className={controls.primary} disabled={busy} onClick={waitingForRefresh ? onRefresh : onInitialize}>{busy ? t("刷新中…") : waitingForRefresh ? t("我已初始化,刷新") : installedLocally ? t("打开终端安装 CA") : t("初始化 CA")}</button>}
|
|
</div>;
|
|
}
|
|
|
|
export function CursorModelProvider({ children }: { children: ReactNode }) {
|
|
const { models } = useAppStore();
|
|
return <ModelsReady.Provider value={models.length > 0}>{children}</ModelsReady.Provider>;
|
|
}
|
|
|
|
export function CursorModelGate({ onAdd, children }: { onAdd: () => void; children: ReactNode }) {
|
|
const ready = useContext(ModelsReady);
|
|
if (ready) return children;
|
|
return <div className={styles.gate}>
|
|
<strong>{t("还没有可供 Cursor 使用的模型")}</strong>
|
|
<span>{t("Cursor 接管已生效;添加上游及其模型配置后即可使用 BYOK 模型。")}</span>
|
|
<button className={controls.primary} onClick={onAdd}>{t("添加模型")}</button>
|
|
</div>;
|
|
}
|