bingocode 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -7
- package/desktop/README.md +0 -30
- package/desktop/bunfig.toml +0 -1
- package/desktop/index.html +0 -17
- package/desktop/package.json +0 -55
- package/desktop/pnpm-lock.yaml +0 -3832
- package/desktop/public/app-icon.jpg +0 -0
- package/desktop/public/fonts/inter-latin-ext.woff2 +0 -0
- package/desktop/public/fonts/inter-latin.woff2 +0 -0
- package/desktop/public/fonts/jetbrains-mono-latin-ext.woff2 +0 -0
- package/desktop/public/fonts/jetbrains-mono-latin.woff2 +0 -0
- package/desktop/public/fonts/manrope-latin-ext.woff2 +0 -0
- package/desktop/public/fonts/manrope-latin.woff2 +0 -0
- package/desktop/public/fonts/material-symbols-outlined.woff2 +0 -0
- package/desktop/public/icons/bilibili.svg +0 -1
- package/desktop/public/icons/douyin.svg +0 -1
- package/desktop/public/icons/github.svg +0 -3
- package/desktop/public/icons/xiaohongshu.svg +0 -1
- package/desktop/scripts/build-macos-arm64.sh +0 -270
- package/desktop/scripts/build-sidecars.ts +0 -183
- package/desktop/scripts/build-windows-x64.ps1 +0 -295
- package/desktop/scripts/scan-missing-imports.ts +0 -235
- package/desktop/sidecars/claude-sidecar.ts +0 -156
- package/desktop/src/App.tsx +0 -5
- package/desktop/src/__tests__/agentsSettings.test.tsx +0 -349
- package/desktop/src/__tests__/pages.test.tsx +0 -290
- package/desktop/src/__tests__/skillsSettings.test.tsx +0 -205
- package/desktop/src/api/adapters.ts +0 -12
- package/desktop/src/api/agents.ts +0 -36
- package/desktop/src/api/cliTasks.ts +0 -28
- package/desktop/src/api/client.ts +0 -63
- package/desktop/src/api/computerUse.ts +0 -76
- package/desktop/src/api/filesystem.ts +0 -30
- package/desktop/src/api/hahaOAuth.ts +0 -38
- package/desktop/src/api/models.ts +0 -28
- package/desktop/src/api/providers.ts +0 -63
- package/desktop/src/api/search.ts +0 -29
- package/desktop/src/api/sessions.ts +0 -56
- package/desktop/src/api/settings.ts +0 -20
- package/desktop/src/api/skills.ts +0 -19
- package/desktop/src/api/tasks.ts +0 -36
- package/desktop/src/api/teams.ts +0 -44
- package/desktop/src/api/websocket.ts +0 -164
- package/desktop/src/components/chat/AskUserQuestion.tsx +0 -268
- package/desktop/src/components/chat/AssistantMessage.tsx +0 -29
- package/desktop/src/components/chat/AttachmentGallery.tsx +0 -113
- package/desktop/src/components/chat/ChatInput.tsx +0 -622
- package/desktop/src/components/chat/CodeViewer.tsx +0 -161
- package/desktop/src/components/chat/ComputerUsePermissionModal.test.tsx +0 -174
- package/desktop/src/components/chat/ComputerUsePermissionModal.tsx +0 -311
- package/desktop/src/components/chat/DiffViewer.tsx +0 -157
- package/desktop/src/components/chat/FileSearchMenu.tsx +0 -198
- package/desktop/src/components/chat/ImageGalleryModal.tsx +0 -91
- package/desktop/src/components/chat/InlineImageGallery.tsx +0 -106
- package/desktop/src/components/chat/InlineTaskSummary.tsx +0 -60
- package/desktop/src/components/chat/MermaidRenderer.test.tsx +0 -98
- package/desktop/src/components/chat/MermaidRenderer.tsx +0 -361
- package/desktop/src/components/chat/MessageActionBar.tsx +0 -27
- package/desktop/src/components/chat/MessageList.test.tsx +0 -313
- package/desktop/src/components/chat/MessageList.tsx +0 -249
- package/desktop/src/components/chat/PermissionDialog.tsx +0 -262
- package/desktop/src/components/chat/SessionTaskBar.test.tsx +0 -99
- package/desktop/src/components/chat/SessionTaskBar.tsx +0 -159
- package/desktop/src/components/chat/StreamingIndicator.tsx +0 -41
- package/desktop/src/components/chat/TerminalChrome.tsx +0 -35
- package/desktop/src/components/chat/ThinkingBlock.tsx +0 -87
- package/desktop/src/components/chat/ToolCallBlock.tsx +0 -247
- package/desktop/src/components/chat/ToolCallGroup.tsx +0 -617
- package/desktop/src/components/chat/ToolResultBlock.tsx +0 -107
- package/desktop/src/components/chat/UserMessage.tsx +0 -38
- package/desktop/src/components/chat/chatBlocks.test.tsx +0 -136
- package/desktop/src/components/chat/clipboard.ts +0 -25
- package/desktop/src/components/chat/composerUtils.test.ts +0 -55
- package/desktop/src/components/chat/composerUtils.ts +0 -149
- package/desktop/src/components/controls/ModelSelector.tsx +0 -156
- package/desktop/src/components/controls/PermissionModeSelector.tsx +0 -229
- package/desktop/src/components/layout/AppShell.tsx +0 -107
- package/desktop/src/components/layout/ContentRouter.tsx +0 -27
- package/desktop/src/components/layout/ProjectFilter.tsx +0 -126
- package/desktop/src/components/layout/Sidebar.test.tsx +0 -158
- package/desktop/src/components/layout/Sidebar.tsx +0 -384
- package/desktop/src/components/layout/StatusBar.tsx +0 -31
- package/desktop/src/components/layout/TabBar.test.tsx +0 -136
- package/desktop/src/components/layout/TabBar.tsx +0 -318
- package/desktop/src/components/layout/TitleBar.tsx +0 -96
- package/desktop/src/components/layout/WindowControls.test.tsx +0 -69
- package/desktop/src/components/layout/WindowControls.tsx +0 -89
- package/desktop/src/components/markdown/MarkdownRenderer.test.tsx +0 -100
- package/desktop/src/components/markdown/MarkdownRenderer.tsx +0 -229
- package/desktop/src/components/settings/ClaudeOfficialLogin.tsx +0 -107
- package/desktop/src/components/shared/Button.tsx +0 -63
- package/desktop/src/components/shared/CopyButton.tsx +0 -58
- package/desktop/src/components/shared/DirectoryPicker.tsx +0 -316
- package/desktop/src/components/shared/Dropdown.tsx +0 -91
- package/desktop/src/components/shared/Input.tsx +0 -38
- package/desktop/src/components/shared/Modal.tsx +0 -65
- package/desktop/src/components/shared/ProjectContextChip.tsx +0 -30
- package/desktop/src/components/shared/Spinner.tsx +0 -30
- package/desktop/src/components/shared/Textarea.tsx +0 -38
- package/desktop/src/components/shared/Toast.tsx +0 -47
- package/desktop/src/components/shared/UpdateChecker.tsx +0 -90
- package/desktop/src/components/skills/SkillDetail.test.tsx +0 -89
- package/desktop/src/components/skills/SkillDetail.tsx +0 -403
- package/desktop/src/components/skills/SkillList.tsx +0 -254
- package/desktop/src/components/tasks/DayOfWeekPicker.tsx +0 -57
- package/desktop/src/components/tasks/NewTaskModal.tsx +0 -407
- package/desktop/src/components/tasks/PromptEditor.tsx +0 -74
- package/desktop/src/components/tasks/TaskEmptyState.tsx +0 -30
- package/desktop/src/components/tasks/TaskList.tsx +0 -46
- package/desktop/src/components/tasks/TaskRow.tsx +0 -253
- package/desktop/src/components/tasks/TaskRunsPanel.tsx +0 -195
- package/desktop/src/components/teams/TeamStatusBar.tsx +0 -147
- package/desktop/src/config/providerPresets.ts +0 -78
- package/desktop/src/config/spinnerVerbs.ts +0 -193
- package/desktop/src/hooks/useKeyboardShortcuts.ts +0 -60
- package/desktop/src/i18n/index.ts +0 -54
- package/desktop/src/i18n/locales/en.ts +0 -670
- package/desktop/src/i18n/locales/zh.ts +0 -670
- package/desktop/src/lib/__tests__/cronDescribe.test.ts +0 -93
- package/desktop/src/lib/cronDescribe.ts +0 -188
- package/desktop/src/lib/desktopRuntime.ts +0 -54
- package/desktop/src/lib/parseRunOutput.ts +0 -79
- package/desktop/src/main.tsx +0 -13
- package/desktop/src/mocks/data.ts +0 -202
- package/desktop/src/pages/ActiveSession.test.tsx +0 -181
- package/desktop/src/pages/ActiveSession.tsx +0 -219
- package/desktop/src/pages/AdapterSettings.tsx +0 -375
- package/desktop/src/pages/AgentTeams.tsx +0 -200
- package/desktop/src/pages/ComputerUseSettings.tsx +0 -420
- package/desktop/src/pages/EmptySession.tsx +0 -518
- package/desktop/src/pages/NewTaskModal.tsx +0 -346
- package/desktop/src/pages/ScheduledTasks.tsx +0 -66
- package/desktop/src/pages/ScheduledTasksEmpty.tsx +0 -152
- package/desktop/src/pages/ScheduledTasksList.tsx +0 -416
- package/desktop/src/pages/SessionControls.tsx +0 -460
- package/desktop/src/pages/Settings.tsx +0 -1448
- package/desktop/src/pages/ToolInspection.tsx +0 -235
- package/desktop/src/stores/adapterStore.ts +0 -106
- package/desktop/src/stores/agentStore.ts +0 -34
- package/desktop/src/stores/chatStore.test.ts +0 -505
- package/desktop/src/stores/chatStore.ts +0 -850
- package/desktop/src/stores/cliTaskStore.ts +0 -152
- package/desktop/src/stores/hahaOAuthStore.test.ts +0 -77
- package/desktop/src/stores/hahaOAuthStore.ts +0 -97
- package/desktop/src/stores/providerStore.ts +0 -101
- package/desktop/src/stores/sessionStore.test.ts +0 -63
- package/desktop/src/stores/sessionStore.ts +0 -102
- package/desktop/src/stores/settingsStore.ts +0 -120
- package/desktop/src/stores/skillStore.ts +0 -51
- package/desktop/src/stores/tabStore.ts +0 -169
- package/desktop/src/stores/taskStore.ts +0 -68
- package/desktop/src/stores/teamStore.ts +0 -344
- package/desktop/src/stores/uiStore.ts +0 -100
- package/desktop/src/stores/updateStore.test.ts +0 -71
- package/desktop/src/stores/updateStore.ts +0 -221
- package/desktop/src/theme/globals.css +0 -465
- package/desktop/src/types/adapter.ts +0 -33
- package/desktop/src/types/chat.ts +0 -152
- package/desktop/src/types/cliTask.ts +0 -24
- package/desktop/src/types/provider.ts +0 -62
- package/desktop/src/types/session.ts +0 -27
- package/desktop/src/types/settings.ts +0 -22
- package/desktop/src/types/skill.ts +0 -38
- package/desktop/src/types/task.ts +0 -56
- package/desktop/src/types/team.ts +0 -38
- package/desktop/src-tauri/Cargo.lock +0 -5549
- package/desktop/src-tauri/Cargo.toml +0 -20
- package/desktop/src-tauri/app-icon.svg +0 -13
- package/desktop/src-tauri/build.rs +0 -3
- package/desktop/src-tauri/capabilities/default.json +0 -106
- package/desktop/src-tauri/icons/android/mipmap-anydpi-v26/ic_launcher.xml +0 -5
- package/desktop/src-tauri/icons/android/values/ic_launcher_background.xml +0 -4
- package/desktop/src-tauri/icons/icon.icns +0 -0
- package/desktop/src-tauri/icons/icon.ico +0 -0
- package/desktop/src-tauri/src/lib.rs +0 -408
- package/desktop/src-tauri/src/main.rs +0 -6
- package/desktop/src-tauri/tauri.conf.json +0 -78
- package/desktop/src-tauri/tauri.macos.conf.json +0 -18
- package/desktop/src-tauri/tauri.release-ci.json +0 -5
- package/desktop/src-tauri/tauri.windows.conf.json +0 -16
- package/desktop/src-tauri/windows-installer-hooks.nsh +0 -17
- package/desktop/tsconfig.json +0 -25
- package/desktop/vite.config.ts +0 -26
- package/desktop/vitest.config.ts +0 -18
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
const SPINNER_VERBS = [
|
|
2
|
-
'Accomplishing',
|
|
3
|
-
'Actioning',
|
|
4
|
-
'Actualizing',
|
|
5
|
-
'Architecting',
|
|
6
|
-
'Baking',
|
|
7
|
-
'Beaming',
|
|
8
|
-
"Beboppin'",
|
|
9
|
-
'Befuddling',
|
|
10
|
-
'Billowing',
|
|
11
|
-
'Blanching',
|
|
12
|
-
'Bloviating',
|
|
13
|
-
'Boogieing',
|
|
14
|
-
'Boondoggling',
|
|
15
|
-
'Booping',
|
|
16
|
-
'Bootstrapping',
|
|
17
|
-
'Brewing',
|
|
18
|
-
'Bunning',
|
|
19
|
-
'Burrowing',
|
|
20
|
-
'Calculating',
|
|
21
|
-
'Canoodling',
|
|
22
|
-
'Caramelizing',
|
|
23
|
-
'Cascading',
|
|
24
|
-
'Catapulting',
|
|
25
|
-
'Cerebrating',
|
|
26
|
-
'Channeling',
|
|
27
|
-
'Channelling',
|
|
28
|
-
'Choreographing',
|
|
29
|
-
'Churning',
|
|
30
|
-
'Clauding',
|
|
31
|
-
'Coalescing',
|
|
32
|
-
'Cogitating',
|
|
33
|
-
'Combobulating',
|
|
34
|
-
'Composing',
|
|
35
|
-
'Computing',
|
|
36
|
-
'Concocting',
|
|
37
|
-
'Considering',
|
|
38
|
-
'Contemplating',
|
|
39
|
-
'Cooking',
|
|
40
|
-
'Crafting',
|
|
41
|
-
'Creating',
|
|
42
|
-
'Crunching',
|
|
43
|
-
'Crystallizing',
|
|
44
|
-
'Cultivating',
|
|
45
|
-
'Deciphering',
|
|
46
|
-
'Deliberating',
|
|
47
|
-
'Determining',
|
|
48
|
-
'Dilly-dallying',
|
|
49
|
-
'Discombobulating',
|
|
50
|
-
'Doing',
|
|
51
|
-
'Doodling',
|
|
52
|
-
'Drizzling',
|
|
53
|
-
'Ebbing',
|
|
54
|
-
'Effecting',
|
|
55
|
-
'Elucidating',
|
|
56
|
-
'Embellishing',
|
|
57
|
-
'Enchanting',
|
|
58
|
-
'Envisioning',
|
|
59
|
-
'Evaporating',
|
|
60
|
-
'Fermenting',
|
|
61
|
-
'Fiddle-faddling',
|
|
62
|
-
'Finagling',
|
|
63
|
-
'Flambéing',
|
|
64
|
-
'Flibbertigibbeting',
|
|
65
|
-
'Flowing',
|
|
66
|
-
'Flummoxing',
|
|
67
|
-
'Fluttering',
|
|
68
|
-
'Forging',
|
|
69
|
-
'Forming',
|
|
70
|
-
'Frolicking',
|
|
71
|
-
'Frosting',
|
|
72
|
-
'Gallivanting',
|
|
73
|
-
'Galloping',
|
|
74
|
-
'Garnishing',
|
|
75
|
-
'Generating',
|
|
76
|
-
'Gesticulating',
|
|
77
|
-
'Germinating',
|
|
78
|
-
'Gitifying',
|
|
79
|
-
'Grooving',
|
|
80
|
-
'Gusting',
|
|
81
|
-
'Harmonizing',
|
|
82
|
-
'Hashing',
|
|
83
|
-
'Hatching',
|
|
84
|
-
'Herding',
|
|
85
|
-
'Honking',
|
|
86
|
-
'Hullaballooing',
|
|
87
|
-
'Hyperspacing',
|
|
88
|
-
'Ideating',
|
|
89
|
-
'Imagining',
|
|
90
|
-
'Improvising',
|
|
91
|
-
'Incubating',
|
|
92
|
-
'Inferring',
|
|
93
|
-
'Infusing',
|
|
94
|
-
'Ionizing',
|
|
95
|
-
'Jitterbugging',
|
|
96
|
-
'Julienning',
|
|
97
|
-
'Kneading',
|
|
98
|
-
'Leavening',
|
|
99
|
-
'Levitating',
|
|
100
|
-
'Lollygagging',
|
|
101
|
-
'Manifesting',
|
|
102
|
-
'Marinating',
|
|
103
|
-
'Meandering',
|
|
104
|
-
'Metamorphosing',
|
|
105
|
-
'Misting',
|
|
106
|
-
'Moonwalking',
|
|
107
|
-
'Moseying',
|
|
108
|
-
'Mulling',
|
|
109
|
-
'Mustering',
|
|
110
|
-
'Musing',
|
|
111
|
-
'Nebulizing',
|
|
112
|
-
'Nesting',
|
|
113
|
-
'Newspapering',
|
|
114
|
-
'Noodling',
|
|
115
|
-
'Nucleating',
|
|
116
|
-
'Orbiting',
|
|
117
|
-
'Orchestrating',
|
|
118
|
-
'Osmosing',
|
|
119
|
-
'Perambulating',
|
|
120
|
-
'Percolating',
|
|
121
|
-
'Perusing',
|
|
122
|
-
'Philosophising',
|
|
123
|
-
'Photosynthesizing',
|
|
124
|
-
'Pollinating',
|
|
125
|
-
'Pondering',
|
|
126
|
-
'Pontificating',
|
|
127
|
-
'Pouncing',
|
|
128
|
-
'Precipitating',
|
|
129
|
-
'Prestidigitating',
|
|
130
|
-
'Processing',
|
|
131
|
-
'Proofing',
|
|
132
|
-
'Propagating',
|
|
133
|
-
'Puttering',
|
|
134
|
-
'Puzzling',
|
|
135
|
-
'Quantumizing',
|
|
136
|
-
'Razzle-dazzling',
|
|
137
|
-
'Razzmatazzing',
|
|
138
|
-
'Recombobulating',
|
|
139
|
-
'Reticulating',
|
|
140
|
-
'Roosting',
|
|
141
|
-
'Ruminating',
|
|
142
|
-
'Sautéing',
|
|
143
|
-
'Scampering',
|
|
144
|
-
'Schlepping',
|
|
145
|
-
'Scurrying',
|
|
146
|
-
'Seasoning',
|
|
147
|
-
'Shenaniganing',
|
|
148
|
-
'Shimmying',
|
|
149
|
-
'Simmering',
|
|
150
|
-
'Skedaddling',
|
|
151
|
-
'Sketching',
|
|
152
|
-
'Slithering',
|
|
153
|
-
'Smooshing',
|
|
154
|
-
'Sock-hopping',
|
|
155
|
-
'Spelunking',
|
|
156
|
-
'Spinning',
|
|
157
|
-
'Sprouting',
|
|
158
|
-
'Stewing',
|
|
159
|
-
'Sublimating',
|
|
160
|
-
'Swirling',
|
|
161
|
-
'Swooping',
|
|
162
|
-
'Symbioting',
|
|
163
|
-
'Synthesizing',
|
|
164
|
-
'Tempering',
|
|
165
|
-
'Thinking',
|
|
166
|
-
'Thundering',
|
|
167
|
-
'Tinkering',
|
|
168
|
-
'Tomfoolering',
|
|
169
|
-
'Topsy-turvying',
|
|
170
|
-
'Transfiguring',
|
|
171
|
-
'Transmuting',
|
|
172
|
-
'Twisting',
|
|
173
|
-
'Undulating',
|
|
174
|
-
'Unfurling',
|
|
175
|
-
'Unravelling',
|
|
176
|
-
'Vibing',
|
|
177
|
-
'Waddling',
|
|
178
|
-
'Wandering',
|
|
179
|
-
'Warping',
|
|
180
|
-
'Whatchamacalliting',
|
|
181
|
-
'Whirlpooling',
|
|
182
|
-
'Whirring',
|
|
183
|
-
'Whisking',
|
|
184
|
-
'Wibbling',
|
|
185
|
-
'Working',
|
|
186
|
-
'Wrangling',
|
|
187
|
-
'Zesting',
|
|
188
|
-
'Zigzagging',
|
|
189
|
-
]
|
|
190
|
-
|
|
191
|
-
export function randomSpinnerVerb(): string {
|
|
192
|
-
return SPINNER_VERBS[Math.floor(Math.random() * SPINNER_VERBS.length)] ?? 'Thinking'
|
|
193
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef } from 'react'
|
|
2
|
-
import { useSessionStore } from '../stores/sessionStore'
|
|
3
|
-
import { useChatStore } from '../stores/chatStore'
|
|
4
|
-
import { useTabStore } from '../stores/tabStore'
|
|
5
|
-
import { useUIStore } from '../stores/uiStore'
|
|
6
|
-
|
|
7
|
-
export function useKeyboardShortcuts() {
|
|
8
|
-
const setActiveSession = useSessionStore((s) => s.setActiveSession)
|
|
9
|
-
const setActiveView = useUIStore((s) => s.setActiveView)
|
|
10
|
-
const closeModal = useUIStore((s) => s.closeModal)
|
|
11
|
-
const activeModal = useUIStore((s) => s.activeModal)
|
|
12
|
-
const stopGeneration = useChatStore((s) => s.stopGeneration)
|
|
13
|
-
const activeTabId = useTabStore((s) => s.activeTabId)
|
|
14
|
-
const chatState = useChatStore((s) => activeTabId ? s.sessions[activeTabId]?.chatState ?? 'idle' : 'idle')
|
|
15
|
-
|
|
16
|
-
const activeModalRef = useRef(activeModal)
|
|
17
|
-
activeModalRef.current = activeModal
|
|
18
|
-
const chatStateRef = useRef(chatState)
|
|
19
|
-
chatStateRef.current = chatState
|
|
20
|
-
const activeTabIdRef = useRef(activeTabId)
|
|
21
|
-
activeTabIdRef.current = activeTabId
|
|
22
|
-
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
const handler = (e: KeyboardEvent) => {
|
|
25
|
-
const meta = e.metaKey || e.ctrlKey
|
|
26
|
-
|
|
27
|
-
// Cmd+N — New session
|
|
28
|
-
if (meta && e.key === 'n') {
|
|
29
|
-
e.preventDefault()
|
|
30
|
-
setActiveSession(null)
|
|
31
|
-
setActiveView('code')
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Cmd+K — Focus search (sidebar search input)
|
|
35
|
-
if (meta && e.key === 'k') {
|
|
36
|
-
e.preventDefault()
|
|
37
|
-
const searchInput = document.querySelector('aside input[type="text"]') as HTMLInputElement
|
|
38
|
-
searchInput?.focus()
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Escape — Close modal or clear state
|
|
42
|
-
if (e.key === 'Escape') {
|
|
43
|
-
if (activeModalRef.current) {
|
|
44
|
-
closeModal()
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Cmd+. — Stop generation
|
|
49
|
-
if (meta && e.key === '.') {
|
|
50
|
-
if (chatStateRef.current !== 'idle' && activeTabIdRef.current) {
|
|
51
|
-
e.preventDefault()
|
|
52
|
-
stopGeneration(activeTabIdRef.current)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
document.addEventListener('keydown', handler)
|
|
58
|
-
return () => document.removeEventListener('keydown', handler)
|
|
59
|
-
}, [closeModal, setActiveSession, setActiveView, stopGeneration])
|
|
60
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { useSettingsStore } from '../stores/settingsStore'
|
|
2
|
-
import { en, type TranslationKey } from './locales/en'
|
|
3
|
-
import { zh } from './locales/zh'
|
|
4
|
-
|
|
5
|
-
export type Locale = 'en' | 'zh'
|
|
6
|
-
|
|
7
|
-
const translations: Record<Locale, Record<string, string>> = { en, zh }
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Translate a key with optional interpolation params.
|
|
11
|
-
* Falls back to the key itself if no translation is found.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* translate('en', 'settings.providers.connected', { latency: '42' })
|
|
15
|
-
* // => "Connected (42ms)"
|
|
16
|
-
*/
|
|
17
|
-
export function translate(
|
|
18
|
-
locale: Locale,
|
|
19
|
-
key: TranslationKey,
|
|
20
|
-
params?: Record<string, string | number>,
|
|
21
|
-
): string {
|
|
22
|
-
let text = translations[locale]?.[key] ?? translations.en[key] ?? key
|
|
23
|
-
if (params) {
|
|
24
|
-
for (const [k, v] of Object.entries(params)) {
|
|
25
|
-
text = text.replace(new RegExp(`\\{${k}\\}`, 'g'), String(v))
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return text
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* React hook that returns a `t()` function bound to the current locale.
|
|
33
|
-
* Re-renders when the locale changes.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* const t = useTranslation()
|
|
37
|
-
* t('sidebar.newSession') // => "New session" or "新建会话"
|
|
38
|
-
*/
|
|
39
|
-
export function useTranslation() {
|
|
40
|
-
const locale = useSettingsStore((s) => s.locale)
|
|
41
|
-
return (key: TranslationKey, params?: Record<string, string | number>) =>
|
|
42
|
-
translate(locale, key, params)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Get a translation outside of React (e.g. in stores).
|
|
47
|
-
* Reads the current locale from the Zustand store directly.
|
|
48
|
-
*/
|
|
49
|
-
export function t(key: TranslationKey, params?: Record<string, string | number>): string {
|
|
50
|
-
const locale = useSettingsStore.getState().locale
|
|
51
|
-
return translate(locale, key, params)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export type { TranslationKey }
|