index.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. /**
  2. * Zustand Store —— 全局状态管理
  3. *
  4. * 需要跨窗口同步的状态通过 BroadcastService 广播。
  5. * 广播频道前缀 "state:" 表示状态同步类消息。
  6. */
  7. import { create } from "zustand";
  8. import type { IBroadcastService, BroadcastMessage } from "@zcode/services";
  9. import type { OAuthProviderId, UserInfo } from "@zcode/shared";
  10. import type { CodingPlanResetType } from "@zcode/shared";
  11. import type { CodePreviewSettings } from "@/lib/codePreviewSettings.js";
  12. import type {
  13. CodingPlanQuotaResetUiEntries,
  14. CodingPlanQuotaResetUiEntry,
  15. } from "@/lib/codingPlanQuotaResetUi.js";
  16. import {
  17. applyCodingPlanQuotaResetAutoPlayedBroadcast,
  18. createCodingPlanQuotaResetStoreActions,
  19. parseCodingPlanQuotaResetAutoPlayedBroadcastMessage,
  20. type CodingPlanQuotaResetAutomaticObservations,
  21. type CodingPlanQuotaResetAutoPlayReservation,
  22. type CodingPlanQuotaResetAutoPlayReservationAttempt,
  23. type CodingPlanQuotaResetAutoPlayedSlot,
  24. } from "@/store/codingPlanQuotaResetState.js";
  25. import { DEFAULT_CODE_PREVIEW_SETTINGS } from "@/lib/codePreviewSettings.js";
  26. import { readSafeLocalStorage, writeSafeLocalStorage } from "@/lib/browserEnvironment.js";
  27. import {
  28. applyUiFontSizePx,
  29. loadUiFontSizePx,
  30. normalizeUiFontSizePx,
  31. UI_FONT_SIZE_STORAGE_KEY,
  32. } from "@/lib/uiFontSize.js";
  33. import {
  34. isTaskNotificationEnabled,
  35. isTaskNotificationSoundPreferenceEnabled,
  36. persistTaskNotificationEnabled,
  37. persistTaskNotificationSoundEnabled,
  38. } from "@/lib/taskNotificationPreferences.js";
  39. import type { Theme } from "../useTheme.js";
  40. import { applyTheme, normalizeThemePreference, resolveTheme } from "../useTheme.js";
  41. import { applySkin, loadPersistedSkinId, normalizeSkinId, persistSkinId, resolveSkinBase } from "../skins/applySkin.js";
  42. import {
  43. INTERFACE_MODE_STORAGE_KEY,
  44. normalizeInterfaceMode,
  45. type InterfaceMode,
  46. } from "@/lib/interfaceMode.js";
  47. import { logger } from "@/logger.js";
  48. export type LoginEntryPurpose = "app-login";
  49. // v4 重构:类型与默认值下沉到 @/lib/codePreviewSettings.ts,
  50. // 让纯展示组件不依赖 store;这里保留 re-export 兼容既有 import 路径。
  51. export type { CodePreviewSettings } from "@/lib/codePreviewSettings.js";
  52. export { DEFAULT_CODE_PREVIEW_SETTINGS } from "@/lib/codePreviewSettings.js";
  53. export type LoginEntryAttemptStatus =
  54. | "requested"
  55. | "waiting"
  56. | "succeeded"
  57. | "cancelled"
  58. | "failed";
  59. export interface LoginEntryAttempt {
  60. id: number;
  61. providerId?: OAuthProviderId;
  62. purpose?: LoginEntryPurpose;
  63. status: LoginEntryAttemptStatus;
  64. }
  65. const CODE_PREVIEW_SETTINGS_KEY = "zcode-code-preview-settings";
  66. const PERFORMANCE_MODE_STORAGE_KEY = "zcode-performance-mode";
  67. function loadCodePreviewSettings(): CodePreviewSettings {
  68. try {
  69. const raw = readSafeLocalStorage(CODE_PREVIEW_SETTINGS_KEY);
  70. if (!raw) {
  71. return DEFAULT_CODE_PREVIEW_SETTINGS;
  72. }
  73. const parsed = JSON.parse(raw) as Partial<CodePreviewSettings>;
  74. return {
  75. ...DEFAULT_CODE_PREVIEW_SETTINGS,
  76. ...parsed,
  77. fontSizePx:
  78. typeof parsed.fontSizePx === "number"
  79. ? Math.min(20, Math.max(12, Math.round(parsed.fontSizePx)))
  80. : DEFAULT_CODE_PREVIEW_SETTINGS.fontSizePx,
  81. };
  82. } catch {
  83. return DEFAULT_CODE_PREVIEW_SETTINGS;
  84. }
  85. }
  86. function loadPerformanceMode(): boolean {
  87. return readSafeLocalStorage(PERFORMANCE_MODE_STORAGE_KEY) === "true";
  88. }
  89. // ============================================================================
  90. // State 定义
  91. // ============================================================================
  92. export interface ZCodeState {
  93. /** 展示详情偏好,不改变 Agent 权限或执行能力。 */
  94. interfaceMode: InterfaceMode;
  95. setInterfaceMode: (mode: InterfaceMode) => void;
  96. /** 当前主题 */
  97. theme: Theme;
  98. setTheme: (theme: Theme) => void;
  99. skinId: string | null;
  100. setSkin: (skinId: string | null) => void;
  101. /** 当前语言 */
  102. locale: string;
  103. setLocale: (locale: string) => void;
  104. /** 代码预览设置 */
  105. codePreviewSettings: CodePreviewSettings;
  106. setCodePreviewSettings: (patch: Partial<CodePreviewSettings>) => void;
  107. /** UI 根 rem 字号(px) */
  108. uiFontSizePx: number;
  109. setUiFontSizePx: (fontSizePx: number) => void;
  110. /** 是否启用性能模式 */
  111. performanceMode: boolean;
  112. setPerformanceMode: (enabled: boolean) => void;
  113. /** 是否启用任务通知(桌面通知;提示音由子开关控制) */
  114. notificationEnabled: boolean;
  115. setNotificationEnabled: (enabled: boolean) => void;
  116. /** 是否启用任务通知声音(依附于任务通知总开关) */
  117. notificationSoundEnabled: boolean;
  118. setNotificationSoundEnabled: (enabled: boolean) => void;
  119. /** 当前用户信息 */
  120. user: UserInfo | null;
  121. /** 用户由未登录进入登录态时递增;连接额外 provider 不会误判为重新登录。 */
  122. authSessionSeq: number;
  123. setUser: (user: UserInfo | null) => void;
  124. /** 启动阶段是否仍在恢复 OAuth 登录态 */
  125. isRestoringOAuthSession: boolean;
  126. setIsRestoringOAuthSession: (restoring: boolean) => void;
  127. /** OAuth 回调错误(Root 层写入,统一登录入口读取) */
  128. oauthError: string | null;
  129. setOAuthError: (error: string | null) => void;
  130. oauthPollingActive: boolean;
  131. setOAuthPollingActive: (active: boolean) => void;
  132. oauthSuccessSeq: number;
  133. lastOAuthSuccessProvider: OAuthProviderId | null;
  134. markOAuthSuccess: (provider?: OAuthProviderId) => void;
  135. apiKeyLoginSuccessSeq: number;
  136. lastApiKeyLoginModel: string | null;
  137. markApiKeyLoginSuccess: (preferredModel?: string | null) => void;
  138. /** 请求打开统一登录入口,可携带需要自动发起登录/连接的 provider */
  139. loginEntryRequest: {
  140. id: number;
  141. providerId?: OAuthProviderId;
  142. purpose?: LoginEntryPurpose;
  143. } | null;
  144. /** 当前统一登录尝试;购买等后续动作通过 id 只续接自己发起的 OAuth。 */
  145. loginEntryAttempt: LoginEntryAttempt | null;
  146. requestLoginEntry: (providerId?: OAuthProviderId, purpose?: LoginEntryPurpose) => number;
  147. clearLoginEntryRequest: (requestId?: number) => void;
  148. markLoginEntryAttemptStatus: (
  149. requestId: number,
  150. status: Exclude<LoginEntryAttemptStatus, "requested">,
  151. ) => void;
  152. /** Coding Plan 额度重置 UI 状态;entry/观察记录只在当前窗口内共享,不持久化。 */
  153. codingPlanQuotaResetUiBySource: Record<string, CodingPlanQuotaResetUiEntries>;
  154. /** 自动/运营完成首次被观察时所属的鉴权会话,用于区分同会话后挂载和重新登录。 */
  155. codingPlanQuotaResetAutomaticObservationsBySource: Record<
  156. string,
  157. CodingPlanQuotaResetAutomaticObservations
  158. >;
  159. /** 自动完成提示"多窗口只播一次"的已播 used_at 记录;窗口内存态,可被广播合并。 */
  160. codingPlanQuotaResetAutoPlayedBySource: Record<string, CodingPlanQuotaResetAutoPlayedSlot>;
  161. /** 写入服务端 status / 手动 use 对账后的状态;entry 为 null 表示清空该类型。 */
  162. setCodingPlanQuotaResetUiEntry: (
  163. sourceKey: string,
  164. resetType: CodingPlanResetType,
  165. entry: CodingPlanQuotaResetUiEntry | null,
  166. authSessionSeq: number,
  167. ) => void;
  168. /** Composer 展示前申请临时 reservation;此阶段不写 played。 */
  169. reserveCodingPlanQuotaResetAutoPlay: (
  170. sourceKey: string,
  171. resetType: CodingPlanResetType,
  172. completedAt: number,
  173. ) => Promise<CodingPlanQuotaResetAutoPlayReservationAttempt>;
  174. /** 组件仍有效且即将展示时提交 reservation、played 与广播。 */
  175. commitCodingPlanQuotaResetAutoPlay: (
  176. reservation: CodingPlanQuotaResetAutoPlayReservation,
  177. ) => boolean;
  178. /** 组件失效时释放尚未 commit 的 reservation。 */
  179. releaseCodingPlanQuotaResetAutoPlay: (
  180. reservation: CodingPlanQuotaResetAutoPlayReservation,
  181. ) => Promise<void>;
  182. /** 手动请求打开 onboarding 弹窗 */
  183. newUserOnboardingOpen: boolean;
  184. setNewUserOnboardingOpen: (open: boolean) => void;
  185. onboardingDialogRequested: boolean | "migration";
  186. requestOnboardingDialog: (entry?: "migration") => void;
  187. clearOnboardingDialogRequest: () => void;
  188. }
  189. // ============================================================================
  190. // 需要广播的字段 —— 只有这些字段的变更会发送给其他窗口
  191. // ============================================================================
  192. const BROADCAST_FIELDS = new Set(["theme", "locale", "uiFontSizePx", "interfaceMode", "skinId"]);
  193. type BroadcastField = "theme" | "locale" | "uiFontSizePx" | "interfaceMode" | "skinId";
  194. /** 广播频道名前缀 */
  195. const STATE_CHANNEL_PREFIX = "state:";
  196. // ============================================================================
  197. // Store 创建工厂
  198. // ============================================================================
  199. /**
  200. * 创建 Zustand store,连接广播服务实现跨窗口状态同步
  201. *
  202. * @param broadcastService - 广播服务。Desktop 走 RPC,Web 可传 no-op 实现
  203. */
  204. export function createZCodeStore(
  205. broadcastService: IBroadcastService,
  206. options: {
  207. initialIsRestoringOAuthSession?: boolean;
  208. } = {},
  209. ) {
  210. /** 标记:正在应用来自广播的更新,此时不再重复广播(防止循环) */
  211. let applyingBroadcast = false;
  212. let loginEntryRequestSeq = 0;
  213. let cleanupSystemThemeListener: (() => void) | null = null;
  214. let syncSystemThemeListener = (_theme: Theme) => {};
  215. const useStore = create<ZCodeState>()((set, get) => ({
  216. interfaceMode: normalizeInterfaceMode(readSafeLocalStorage(INTERFACE_MODE_STORAGE_KEY)),
  217. setInterfaceMode: (mode) => {
  218. const interfaceMode = normalizeInterfaceMode(mode);
  219. if (get().interfaceMode !== interfaceMode) {
  220. logger.debug("[InterfaceMode] 切换界面模式", {
  221. interfaceMode,
  222. source: applyingBroadcast ? "broadcast" : "local",
  223. });
  224. }
  225. writeSafeLocalStorage(INTERFACE_MODE_STORAGE_KEY, interfaceMode);
  226. set({ interfaceMode });
  227. },
  228. // 默认主题统一收敛到 Zai dark,避免首次启动时 store 与其他主题入口表现不一致。
  229. // 仍然优先尊重 localStorage 中已保存的用户选择,不覆盖已有偏好。
  230. theme: normalizeThemePreference((readSafeLocalStorage("zcode-theme") as Theme) || "zai-dark"),
  231. setTheme: (theme: Theme) => {
  232. const normalizedTheme = normalizeThemePreference(theme);
  233. writeSafeLocalStorage("zcode-theme", normalizedTheme);
  234. syncSystemThemeListener(normalizedTheme);
  235. applyTheme(normalizedTheme);
  236. // base(亮/暗)变化可能令皮肤失去兼容性(manifest.bases),皮肤 class 必须重放。
  237. applySkin(get().skinId, resolveSkinBase(normalizedTheme));
  238. set({ theme: normalizedTheme });
  239. },
  240. // 皮肤 id 与主题分桶持久化(zcode-skin:v1),语义上「换风格」不是「换主题」。
  241. skinId: loadPersistedSkinId(),
  242. setSkin: (skinId: string | null) => {
  243. const normalizedSkinId = normalizeSkinId(skinId);
  244. persistSkinId(normalizedSkinId);
  245. applySkin(normalizedSkinId, resolveSkinBase(get().theme));
  246. set({ skinId: normalizedSkinId });
  247. },
  248. locale: readSafeLocalStorage("zcode-locale") || "zh-CN",
  249. setLocale: (locale: string) => {
  250. writeSafeLocalStorage("zcode-locale", locale);
  251. set({ locale });
  252. },
  253. codePreviewSettings: loadCodePreviewSettings(),
  254. setCodePreviewSettings: (patch: Partial<CodePreviewSettings>) =>
  255. set((state) => {
  256. const next = {
  257. ...state.codePreviewSettings,
  258. ...patch,
  259. fontSizePx:
  260. typeof patch.fontSizePx === "number"
  261. ? Math.min(20, Math.max(12, Math.round(patch.fontSizePx)))
  262. : state.codePreviewSettings.fontSizePx,
  263. };
  264. writeSafeLocalStorage(CODE_PREVIEW_SETTINGS_KEY, JSON.stringify(next));
  265. return { codePreviewSettings: next };
  266. }),
  267. uiFontSizePx: loadUiFontSizePx(),
  268. setUiFontSizePx: (fontSizePx: number) => {
  269. const normalizedFontSizePx = normalizeUiFontSizePx(fontSizePx);
  270. writeSafeLocalStorage(UI_FONT_SIZE_STORAGE_KEY, String(normalizedFontSizePx));
  271. applyUiFontSizePx(normalizedFontSizePx);
  272. applySkin(get().skinId, resolveSkinBase(get().theme));
  273. set({ uiFontSizePx: normalizedFontSizePx });
  274. },
  275. performanceMode: loadPerformanceMode(),
  276. setPerformanceMode: (enabled: boolean) => {
  277. writeSafeLocalStorage(PERFORMANCE_MODE_STORAGE_KEY, enabled ? "true" : "false");
  278. set({ performanceMode: enabled });
  279. },
  280. notificationEnabled: isTaskNotificationEnabled(),
  281. setNotificationEnabled: (enabled: boolean) => {
  282. persistTaskNotificationEnabled(enabled);
  283. set({ notificationEnabled: enabled });
  284. },
  285. notificationSoundEnabled: isTaskNotificationSoundPreferenceEnabled(),
  286. setNotificationSoundEnabled: (enabled: boolean) => {
  287. persistTaskNotificationSoundEnabled(enabled);
  288. set({ notificationSoundEnabled: enabled });
  289. },
  290. user: null,
  291. authSessionSeq: 0,
  292. setUser: (user: UserInfo | null) =>
  293. set((state) => ({
  294. user,
  295. authSessionSeq:
  296. state.user === null && user !== null ? state.authSessionSeq + 1 : state.authSessionSeq,
  297. })),
  298. isRestoringOAuthSession: options.initialIsRestoringOAuthSession ?? false,
  299. setIsRestoringOAuthSession: (restoring: boolean) => set({ isRestoringOAuthSession: restoring }),
  300. oauthError: null,
  301. setOAuthError: (error: string | null) => set({ oauthError: error }),
  302. oauthPollingActive: false,
  303. setOAuthPollingActive: (active: boolean) => set({ oauthPollingActive: active }),
  304. oauthSuccessSeq: 0,
  305. lastOAuthSuccessProvider: null,
  306. markOAuthSuccess: (provider?: OAuthProviderId) =>
  307. set((state) => ({
  308. oauthSuccessSeq: state.oauthSuccessSeq + 1,
  309. lastOAuthSuccessProvider: provider ?? state.lastOAuthSuccessProvider,
  310. })),
  311. apiKeyLoginSuccessSeq: 0,
  312. lastApiKeyLoginModel: null,
  313. markApiKeyLoginSuccess: (preferredModel?: string | null) =>
  314. set((state) => ({
  315. apiKeyLoginSuccessSeq: state.apiKeyLoginSuccessSeq + 1,
  316. lastApiKeyLoginModel: preferredModel?.trim() || null,
  317. })),
  318. loginEntryRequest: null,
  319. loginEntryAttempt: null,
  320. requestLoginEntry: (providerId?: OAuthProviderId, purpose?: LoginEntryPurpose) => {
  321. const id = ++loginEntryRequestSeq;
  322. const attempt: LoginEntryAttempt = {
  323. id,
  324. providerId,
  325. purpose,
  326. status: "requested",
  327. };
  328. set({
  329. loginEntryRequest: {
  330. id,
  331. providerId,
  332. purpose,
  333. },
  334. loginEntryAttempt: attempt,
  335. });
  336. return id;
  337. },
  338. clearLoginEntryRequest: (requestId?: number) =>
  339. set((state) => {
  340. if (requestId !== undefined && state.loginEntryRequest?.id !== requestId) {
  341. return {};
  342. }
  343. return { loginEntryRequest: null };
  344. }),
  345. markLoginEntryAttemptStatus: (requestId, status) =>
  346. set((state) => {
  347. if (state.loginEntryAttempt?.id !== requestId) {
  348. return {};
  349. }
  350. return {
  351. loginEntryAttempt: {
  352. ...state.loginEntryAttempt,
  353. status,
  354. },
  355. };
  356. }),
  357. codingPlanQuotaResetUiBySource: {},
  358. codingPlanQuotaResetAutomaticObservationsBySource: {},
  359. codingPlanQuotaResetAutoPlayedBySource: {},
  360. ...createCodingPlanQuotaResetStoreActions({
  361. broadcastService,
  362. readState: get,
  363. writeState: (updater) => set((state) => updater(state)),
  364. }),
  365. newUserOnboardingOpen: false,
  366. setNewUserOnboardingOpen: (open) => set({ newUserOnboardingOpen: open }),
  367. onboardingDialogRequested: false,
  368. requestOnboardingDialog: (entry) => set({ onboardingDialogRequested: entry ?? true }),
  369. clearOnboardingDialogRequest: () => set({ onboardingDialogRequested: false }),
  370. }));
  371. syncSystemThemeListener = (theme: Theme) => {
  372. cleanupSystemThemeListener?.();
  373. cleanupSystemThemeListener = null;
  374. if (theme !== "system" || typeof window === "undefined") {
  375. return;
  376. }
  377. const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
  378. const handleSystemThemeChange = () => {
  379. if (useStore.getState().theme !== "system") {
  380. return;
  381. }
  382. // system 模式需要持续订阅系统亮暗变化,不能只在切换到 system 的瞬间应用一次。
  383. // 否则用户后续切系统主题时,DOM 上的 dark class 不会同步更新,看起来就像“跟随系统失效”。
  384. applyTheme("system");
  385. };
  386. if (typeof mediaQuery.addEventListener === "function") {
  387. mediaQuery.addEventListener("change", handleSystemThemeChange);
  388. cleanupSystemThemeListener = () => {
  389. mediaQuery.removeEventListener("change", handleSystemThemeChange);
  390. };
  391. return;
  392. }
  393. // 某些 Electron / Chromium 组合仍然只支持旧版 MediaQueryList listener API。
  394. // 如果这里只调用 addEventListener,system 模式切系统主题时会完全收不到通知。
  395. mediaQuery.addListener(handleSystemThemeChange);
  396. cleanupSystemThemeListener = () => {
  397. mediaQuery.removeListener(handleSystemThemeChange);
  398. };
  399. };
  400. // Zustand v5 的 setState 在 replace=true/false 上使用了不同重载,
  401. // 之前直接包一层并透传 replace,会在严格类型下落到互不兼容的签名分支。
  402. // 这里改成订阅状态变化后再广播,只比较真正需要跨窗口同步的字段,逻辑更直观,也避免重载冲突。
  403. useStore.subscribe((state, prevState) => {
  404. if (applyingBroadcast) {
  405. return;
  406. }
  407. for (const field of BROADCAST_FIELDS as Set<BroadcastField>) {
  408. if (state[field] === prevState[field]) {
  409. continue;
  410. }
  411. broadcastService.send({
  412. channel: `${STATE_CHANNEL_PREFIX}${field}`,
  413. payload: state[field],
  414. });
  415. }
  416. });
  417. // 监听来自其他窗口的广播
  418. broadcastService.onMessage((msg: BroadcastMessage) => {
  419. // 自动完成"多窗口只播一次"。其他窗口广播已播 used_at 后,本窗口合并
  420. // played 记录并收起正在播放的同 used_at 提示;本地回声已在解析阶段被忽略。
  421. const autoPlayed = parseCodingPlanQuotaResetAutoPlayedBroadcastMessage(msg);
  422. if (autoPlayed) {
  423. useStore.setState((state) => applyCodingPlanQuotaResetAutoPlayedBroadcast(state, autoPlayed));
  424. return;
  425. }
  426. if (!msg.channel.startsWith(STATE_CHANNEL_PREFIX)) return;
  427. const field = msg.channel.slice(STATE_CHANNEL_PREFIX.length) as BroadcastField;
  428. if (!BROADCAST_FIELDS.has(field)) return;
  429. applyingBroadcast = true;
  430. try {
  431. // 调用对应的 setter,确保副作用(localStorage、DOM)也执行
  432. const state = useStore.getState();
  433. if (field === "theme" && typeof msg.payload === "string") {
  434. state.setTheme(msg.payload as Theme);
  435. } else if (field === "skinId" && (msg.payload === null || typeof msg.payload === "string")) {
  436. state.setSkin(msg.payload as string | null);
  437. } else if (field === "locale" && typeof msg.payload === "string") {
  438. state.setLocale(msg.payload);
  439. } else if (
  440. field === "interfaceMode" &&
  441. (msg.payload === "office" || msg.payload === "coding")
  442. ) {
  443. state.setInterfaceMode(normalizeInterfaceMode(msg.payload));
  444. } else if (field === "uiFontSizePx" && typeof msg.payload === "number") {
  445. state.setUiFontSizePx(msg.payload);
  446. }
  447. } finally {
  448. applyingBroadcast = false;
  449. }
  450. });
  451. syncSystemThemeListener(useStore.getState().theme);
  452. applyTheme(useStore.getState().theme);
  453. applyUiFontSizePx(useStore.getState().uiFontSizePx);
  454. applySkin(useStore.getState().skinId, resolveSkinBase(useStore.getState().theme));
  455. document.documentElement.classList.toggle(
  456. "dark",
  457. resolveTheme(useStore.getState().theme) === "dark",
  458. );
  459. return useStore;
  460. }
  461. export type ZCodeStore = ReturnType<typeof createZCodeStore>;