Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

♻️ refactor(types): break circular dep between types and const packages (#13948)

Inneie990b08cc62c
diff --git a/apps/desktop/src/main/controllers/index.ts b/apps/desktop/src/main/controllers/index.ts
index 3817ee79b06..f84a9f85cac 100644
--- a/apps/desktop/src/main/controllers/index.ts
+++ b/apps/desktop/src/main/controllers/index.ts
@@ -1,4 +1,4 @@
-import type { DesktopHotkeyId } from '@lobechat/const/desktopGlobalShortcuts';
+import type { DesktopHotkeyId } from '@lobechat/types';
import type { App } from '@/core/App';
import { IoCContainer } from '@/core/infrastructure/IoCContainer';
diff --git a/apps/desktop/stubs/types/src/index.ts b/apps/desktop/stubs/types/src/index.ts
index e3ed5d9a1c7..90e73e10161 100644
--- a/apps/desktop/stubs/types/src/index.ts
+++ b/apps/desktop/stubs/types/src/index.ts
@@ -1,8 +1,19 @@
/**
* Desktop isolated workspace stub.
*
- * `@lobechat/types` is only consumed via `import type` in desktop code; those
- * specifiers are erased at build time, so this package needs no runtime
- * exports.
+ * `@lobechat/types` is only consumed via `import type` in desktop code and in
+ * the `@lobechat/const` entrypoints it reaches (currently `desktopGlobalShortcuts`).
+ * Those specifiers are erased at build time, so this package has no runtime
+ * exports — we only need to surface the types that reach the desktop tsgo
+ * project. Keep these in sync with `packages/types/src/hotkey.ts`.
*/
-export {};
+
+export type DesktopHotkeyId = 'openSettings' | 'showApp';
+
+export interface DesktopHotkeyItem {
+ id: DesktopHotkeyId;
+ keys: string;
+ nonEditable?: boolean;
+}
+
+export type DesktopHotkeyConfig = Record<DesktopHotkeyId, string>;
diff --git a/packages/const/src/desktop.ts b/packages/const/src/desktop.ts
index 27c6c71ebc3..af314c008b1 100644
--- a/packages/const/src/desktop.ts
+++ b/packages/const/src/desktop.ts
@@ -1,4 +1,6 @@
-import { DESKTOP_HOTKEYS_REGISTRATION, type DesktopHotkeyConfig } from './desktopGlobalShortcuts';
+import type { DesktopHotkeyConfig } from '@lobechat/types';
+
+import { DESKTOP_HOTKEYS_REGISTRATION } from './desktopGlobalShortcuts';
export const DESKTOP_USER_ID = 'DEFAULT_DESKTOP_USER';
diff --git a/packages/const/src/desktopGlobalShortcuts.ts b/packages/const/src/desktopGlobalShortcuts.ts
index 580c2579560..ddafb2060d6 100644
--- a/packages/const/src/desktopGlobalShortcuts.ts
+++ b/packages/const/src/desktopGlobalShortcuts.ts
@@ -1,19 +1,11 @@
+import type { DesktopHotkeyConfig, DesktopHotkeyId, DesktopHotkeyItem } from '@lobechat/types';
+
const combineKeys = (keys: string[]) => keys.join('+');
export const DesktopHotkeyEnum = {
OpenSettings: 'openSettings',
ShowApp: 'showApp',
-} as const;
-
-export type DesktopHotkeyId = (typeof DesktopHotkeyEnum)[keyof typeof DesktopHotkeyEnum];
-
-export interface DesktopHotkeyItem {
- id: DesktopHotkeyId;
- keys: string;
- nonEditable?: boolean;
-}
-
-export type DesktopHotkeyConfig = Record<DesktopHotkeyId, string>;
+} as const satisfies Record<string, DesktopHotkeyId>;
interface DesktopGlobalShortcutDefault {
/** Electron `globalShortcut` accelerator; empty string means unregistered. */
diff --git a/packages/const/src/hotkeys.ts b/packages/const/src/hotkeys.ts
index ae9b867e66b..cf9542331df 100644
--- a/packages/const/src/hotkeys.ts
+++ b/packages/const/src/hotkeys.ts
@@ -1,3 +1,5 @@
+import type { HotkeyGroupId, HotkeyId, HotkeyRegistration, HotkeyScopeId } from '@lobechat/types';
+
const combineKeys = (keys: string[]) => keys.join('+');
export const KeyEnum = {
@@ -56,33 +58,19 @@ export const HotkeyEnum = {
ToggleLeftPanel: 'toggleLeftPanel',
ToggleRightPanel: 'toggleRightPanel',
ToggleZenMode: 'toggleZenMode',
-} as const;
+} as const satisfies Record<string, HotkeyId>;
export const HotkeyGroupEnum = {
Conversation: 'conversation',
Essential: 'essential',
-} as const;
+} as const satisfies Record<string, HotkeyGroupId>;
export const HotkeyScopeEnum = {
Chat: 'chat',
Files: 'files',
Global: 'global',
Image: 'image',
-} as const;
-
-export type HotkeyId = (typeof HotkeyEnum)[keyof typeof HotkeyEnum];
-export type HotkeyGroupId = (typeof HotkeyGroupEnum)[keyof typeof HotkeyGroupEnum];
-export type HotkeyScopeId = (typeof HotkeyScopeEnum)[keyof typeof HotkeyScopeEnum];
-
-export interface HotkeyItem {
- group: HotkeyGroupId;
- id: HotkeyId;
- keys: string;
- nonEditable?: boolean;
- scopes?: HotkeyScopeId[];
-}
-
-export type HotkeyRegistration = HotkeyItem[];
+} as const satisfies Record<string, HotkeyScopeId>;
// mod is the command key on Mac, alt is the ctrl key on Windows
export const HOTKEYS_REGISTRATION: HotkeyRegistration = [
diff --git a/packages/const/src/settings/hotkey.ts b/packages/const/src/settings/hotkey.ts
index 2c461da9f1b..1148c913210 100644
--- a/packages/const/src/settings/hotkey.ts
+++ b/packages/const/src/settings/hotkey.ts
@@ -1,4 +1,6 @@
-import { type HotkeyId, HOTKEYS_REGISTRATION } from '../hotkeys';
+import type { HotkeyId } from '@lobechat/types';
+
+import { HOTKEYS_REGISTRATION } from '../hotkeys';
type UserHotkeyConfig = Record<HotkeyId, string>;
diff --git a/packages/types/package.json b/packages/types/package.json
index 5e2e74ceb87..5ecf9d39569 100644
--- a/packages/types/package.json
+++ b/packages/types/package.json
@@ -5,7 +5,6 @@
"type": "module",
"main": "./src/index.ts",
"dependencies": {
- "@lobechat/const": "workspace:*",
"@lobechat/python-interpreter": "workspace:*",
"@lobechat/web-crawler": "workspace:*",
"@lobehub/market-sdk": "0.32.2",
diff --git a/packages/types/src/hotkey.ts b/packages/types/src/hotkey.ts
index 3ef60ac1104..1f0deb33e9d 100644
--- a/packages/types/src/hotkey.ts
+++ b/packages/types/src/hotkey.ts
@@ -1,11 +1,46 @@
-import type { HotkeyId } from '@lobechat/const/hotkeys';
-
-export type {
- DesktopHotkeyConfig,
- DesktopHotkeyId,
- DesktopHotkeyItem,
-} from '@lobechat/const/desktopGlobalShortcuts';
-export type { HotkeyGroupId, HotkeyId, HotkeyItem, HotkeyScopeId } from '@lobechat/const/hotkeys';
+export type HotkeyId =
+ | 'addUserMessage'
+ | 'clearCurrentMessages'
+ | 'commandPalette'
+ | 'deleteAndRegenerateMessage'
+ | 'deleteLastMessage'
+ | 'editMessage'
+ | 'navigateToChat'
+ | 'openChatSettings'
+ | 'openHotkeyHelper'
+ | 'regenerateMessage'
+ | 'saveDocument'
+ | 'saveTopic'
+ | 'search'
+ | 'showApp'
+ | 'switchAgent'
+ | 'toggleLeftPanel'
+ | 'toggleRightPanel'
+ | 'toggleZenMode';
+
+export type HotkeyGroupId = 'conversation' | 'essential';
+
+export type HotkeyScopeId = 'chat' | 'files' | 'global' | 'image';
+
+export interface HotkeyItem {
+ group: HotkeyGroupId;
+ id: HotkeyId;
+ keys: string;
+ nonEditable?: boolean;
+ scopes?: HotkeyScopeId[];
+}
+
+export type HotkeyRegistration = HotkeyItem[];
+
+export type DesktopHotkeyId = 'openSettings' | 'showApp';
+
+export interface DesktopHotkeyItem {
+ id: DesktopHotkeyId;
+ keys: string;
+ nonEditable?: boolean;
+}
+
+export type DesktopHotkeyConfig = Record<DesktopHotkeyId, string>;
export type HotkeyI18nTranslations = Record<
HotkeyId,