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.
Files changed (184) hide show
  1. package/package.json +3 -7
  2. package/desktop/README.md +0 -30
  3. package/desktop/bunfig.toml +0 -1
  4. package/desktop/index.html +0 -17
  5. package/desktop/package.json +0 -55
  6. package/desktop/pnpm-lock.yaml +0 -3832
  7. package/desktop/public/app-icon.jpg +0 -0
  8. package/desktop/public/fonts/inter-latin-ext.woff2 +0 -0
  9. package/desktop/public/fonts/inter-latin.woff2 +0 -0
  10. package/desktop/public/fonts/jetbrains-mono-latin-ext.woff2 +0 -0
  11. package/desktop/public/fonts/jetbrains-mono-latin.woff2 +0 -0
  12. package/desktop/public/fonts/manrope-latin-ext.woff2 +0 -0
  13. package/desktop/public/fonts/manrope-latin.woff2 +0 -0
  14. package/desktop/public/fonts/material-symbols-outlined.woff2 +0 -0
  15. package/desktop/public/icons/bilibili.svg +0 -1
  16. package/desktop/public/icons/douyin.svg +0 -1
  17. package/desktop/public/icons/github.svg +0 -3
  18. package/desktop/public/icons/xiaohongshu.svg +0 -1
  19. package/desktop/scripts/build-macos-arm64.sh +0 -270
  20. package/desktop/scripts/build-sidecars.ts +0 -183
  21. package/desktop/scripts/build-windows-x64.ps1 +0 -295
  22. package/desktop/scripts/scan-missing-imports.ts +0 -235
  23. package/desktop/sidecars/claude-sidecar.ts +0 -156
  24. package/desktop/src/App.tsx +0 -5
  25. package/desktop/src/__tests__/agentsSettings.test.tsx +0 -349
  26. package/desktop/src/__tests__/pages.test.tsx +0 -290
  27. package/desktop/src/__tests__/skillsSettings.test.tsx +0 -205
  28. package/desktop/src/api/adapters.ts +0 -12
  29. package/desktop/src/api/agents.ts +0 -36
  30. package/desktop/src/api/cliTasks.ts +0 -28
  31. package/desktop/src/api/client.ts +0 -63
  32. package/desktop/src/api/computerUse.ts +0 -76
  33. package/desktop/src/api/filesystem.ts +0 -30
  34. package/desktop/src/api/hahaOAuth.ts +0 -38
  35. package/desktop/src/api/models.ts +0 -28
  36. package/desktop/src/api/providers.ts +0 -63
  37. package/desktop/src/api/search.ts +0 -29
  38. package/desktop/src/api/sessions.ts +0 -56
  39. package/desktop/src/api/settings.ts +0 -20
  40. package/desktop/src/api/skills.ts +0 -19
  41. package/desktop/src/api/tasks.ts +0 -36
  42. package/desktop/src/api/teams.ts +0 -44
  43. package/desktop/src/api/websocket.ts +0 -164
  44. package/desktop/src/components/chat/AskUserQuestion.tsx +0 -268
  45. package/desktop/src/components/chat/AssistantMessage.tsx +0 -29
  46. package/desktop/src/components/chat/AttachmentGallery.tsx +0 -113
  47. package/desktop/src/components/chat/ChatInput.tsx +0 -622
  48. package/desktop/src/components/chat/CodeViewer.tsx +0 -161
  49. package/desktop/src/components/chat/ComputerUsePermissionModal.test.tsx +0 -174
  50. package/desktop/src/components/chat/ComputerUsePermissionModal.tsx +0 -311
  51. package/desktop/src/components/chat/DiffViewer.tsx +0 -157
  52. package/desktop/src/components/chat/FileSearchMenu.tsx +0 -198
  53. package/desktop/src/components/chat/ImageGalleryModal.tsx +0 -91
  54. package/desktop/src/components/chat/InlineImageGallery.tsx +0 -106
  55. package/desktop/src/components/chat/InlineTaskSummary.tsx +0 -60
  56. package/desktop/src/components/chat/MermaidRenderer.test.tsx +0 -98
  57. package/desktop/src/components/chat/MermaidRenderer.tsx +0 -361
  58. package/desktop/src/components/chat/MessageActionBar.tsx +0 -27
  59. package/desktop/src/components/chat/MessageList.test.tsx +0 -313
  60. package/desktop/src/components/chat/MessageList.tsx +0 -249
  61. package/desktop/src/components/chat/PermissionDialog.tsx +0 -262
  62. package/desktop/src/components/chat/SessionTaskBar.test.tsx +0 -99
  63. package/desktop/src/components/chat/SessionTaskBar.tsx +0 -159
  64. package/desktop/src/components/chat/StreamingIndicator.tsx +0 -41
  65. package/desktop/src/components/chat/TerminalChrome.tsx +0 -35
  66. package/desktop/src/components/chat/ThinkingBlock.tsx +0 -87
  67. package/desktop/src/components/chat/ToolCallBlock.tsx +0 -247
  68. package/desktop/src/components/chat/ToolCallGroup.tsx +0 -617
  69. package/desktop/src/components/chat/ToolResultBlock.tsx +0 -107
  70. package/desktop/src/components/chat/UserMessage.tsx +0 -38
  71. package/desktop/src/components/chat/chatBlocks.test.tsx +0 -136
  72. package/desktop/src/components/chat/clipboard.ts +0 -25
  73. package/desktop/src/components/chat/composerUtils.test.ts +0 -55
  74. package/desktop/src/components/chat/composerUtils.ts +0 -149
  75. package/desktop/src/components/controls/ModelSelector.tsx +0 -156
  76. package/desktop/src/components/controls/PermissionModeSelector.tsx +0 -229
  77. package/desktop/src/components/layout/AppShell.tsx +0 -107
  78. package/desktop/src/components/layout/ContentRouter.tsx +0 -27
  79. package/desktop/src/components/layout/ProjectFilter.tsx +0 -126
  80. package/desktop/src/components/layout/Sidebar.test.tsx +0 -158
  81. package/desktop/src/components/layout/Sidebar.tsx +0 -384
  82. package/desktop/src/components/layout/StatusBar.tsx +0 -31
  83. package/desktop/src/components/layout/TabBar.test.tsx +0 -136
  84. package/desktop/src/components/layout/TabBar.tsx +0 -318
  85. package/desktop/src/components/layout/TitleBar.tsx +0 -96
  86. package/desktop/src/components/layout/WindowControls.test.tsx +0 -69
  87. package/desktop/src/components/layout/WindowControls.tsx +0 -89
  88. package/desktop/src/components/markdown/MarkdownRenderer.test.tsx +0 -100
  89. package/desktop/src/components/markdown/MarkdownRenderer.tsx +0 -229
  90. package/desktop/src/components/settings/ClaudeOfficialLogin.tsx +0 -107
  91. package/desktop/src/components/shared/Button.tsx +0 -63
  92. package/desktop/src/components/shared/CopyButton.tsx +0 -58
  93. package/desktop/src/components/shared/DirectoryPicker.tsx +0 -316
  94. package/desktop/src/components/shared/Dropdown.tsx +0 -91
  95. package/desktop/src/components/shared/Input.tsx +0 -38
  96. package/desktop/src/components/shared/Modal.tsx +0 -65
  97. package/desktop/src/components/shared/ProjectContextChip.tsx +0 -30
  98. package/desktop/src/components/shared/Spinner.tsx +0 -30
  99. package/desktop/src/components/shared/Textarea.tsx +0 -38
  100. package/desktop/src/components/shared/Toast.tsx +0 -47
  101. package/desktop/src/components/shared/UpdateChecker.tsx +0 -90
  102. package/desktop/src/components/skills/SkillDetail.test.tsx +0 -89
  103. package/desktop/src/components/skills/SkillDetail.tsx +0 -403
  104. package/desktop/src/components/skills/SkillList.tsx +0 -254
  105. package/desktop/src/components/tasks/DayOfWeekPicker.tsx +0 -57
  106. package/desktop/src/components/tasks/NewTaskModal.tsx +0 -407
  107. package/desktop/src/components/tasks/PromptEditor.tsx +0 -74
  108. package/desktop/src/components/tasks/TaskEmptyState.tsx +0 -30
  109. package/desktop/src/components/tasks/TaskList.tsx +0 -46
  110. package/desktop/src/components/tasks/TaskRow.tsx +0 -253
  111. package/desktop/src/components/tasks/TaskRunsPanel.tsx +0 -195
  112. package/desktop/src/components/teams/TeamStatusBar.tsx +0 -147
  113. package/desktop/src/config/providerPresets.ts +0 -78
  114. package/desktop/src/config/spinnerVerbs.ts +0 -193
  115. package/desktop/src/hooks/useKeyboardShortcuts.ts +0 -60
  116. package/desktop/src/i18n/index.ts +0 -54
  117. package/desktop/src/i18n/locales/en.ts +0 -670
  118. package/desktop/src/i18n/locales/zh.ts +0 -670
  119. package/desktop/src/lib/__tests__/cronDescribe.test.ts +0 -93
  120. package/desktop/src/lib/cronDescribe.ts +0 -188
  121. package/desktop/src/lib/desktopRuntime.ts +0 -54
  122. package/desktop/src/lib/parseRunOutput.ts +0 -79
  123. package/desktop/src/main.tsx +0 -13
  124. package/desktop/src/mocks/data.ts +0 -202
  125. package/desktop/src/pages/ActiveSession.test.tsx +0 -181
  126. package/desktop/src/pages/ActiveSession.tsx +0 -219
  127. package/desktop/src/pages/AdapterSettings.tsx +0 -375
  128. package/desktop/src/pages/AgentTeams.tsx +0 -200
  129. package/desktop/src/pages/ComputerUseSettings.tsx +0 -420
  130. package/desktop/src/pages/EmptySession.tsx +0 -518
  131. package/desktop/src/pages/NewTaskModal.tsx +0 -346
  132. package/desktop/src/pages/ScheduledTasks.tsx +0 -66
  133. package/desktop/src/pages/ScheduledTasksEmpty.tsx +0 -152
  134. package/desktop/src/pages/ScheduledTasksList.tsx +0 -416
  135. package/desktop/src/pages/SessionControls.tsx +0 -460
  136. package/desktop/src/pages/Settings.tsx +0 -1448
  137. package/desktop/src/pages/ToolInspection.tsx +0 -235
  138. package/desktop/src/stores/adapterStore.ts +0 -106
  139. package/desktop/src/stores/agentStore.ts +0 -34
  140. package/desktop/src/stores/chatStore.test.ts +0 -505
  141. package/desktop/src/stores/chatStore.ts +0 -850
  142. package/desktop/src/stores/cliTaskStore.ts +0 -152
  143. package/desktop/src/stores/hahaOAuthStore.test.ts +0 -77
  144. package/desktop/src/stores/hahaOAuthStore.ts +0 -97
  145. package/desktop/src/stores/providerStore.ts +0 -101
  146. package/desktop/src/stores/sessionStore.test.ts +0 -63
  147. package/desktop/src/stores/sessionStore.ts +0 -102
  148. package/desktop/src/stores/settingsStore.ts +0 -120
  149. package/desktop/src/stores/skillStore.ts +0 -51
  150. package/desktop/src/stores/tabStore.ts +0 -169
  151. package/desktop/src/stores/taskStore.ts +0 -68
  152. package/desktop/src/stores/teamStore.ts +0 -344
  153. package/desktop/src/stores/uiStore.ts +0 -100
  154. package/desktop/src/stores/updateStore.test.ts +0 -71
  155. package/desktop/src/stores/updateStore.ts +0 -221
  156. package/desktop/src/theme/globals.css +0 -465
  157. package/desktop/src/types/adapter.ts +0 -33
  158. package/desktop/src/types/chat.ts +0 -152
  159. package/desktop/src/types/cliTask.ts +0 -24
  160. package/desktop/src/types/provider.ts +0 -62
  161. package/desktop/src/types/session.ts +0 -27
  162. package/desktop/src/types/settings.ts +0 -22
  163. package/desktop/src/types/skill.ts +0 -38
  164. package/desktop/src/types/task.ts +0 -56
  165. package/desktop/src/types/team.ts +0 -38
  166. package/desktop/src-tauri/Cargo.lock +0 -5549
  167. package/desktop/src-tauri/Cargo.toml +0 -20
  168. package/desktop/src-tauri/app-icon.svg +0 -13
  169. package/desktop/src-tauri/build.rs +0 -3
  170. package/desktop/src-tauri/capabilities/default.json +0 -106
  171. package/desktop/src-tauri/icons/android/mipmap-anydpi-v26/ic_launcher.xml +0 -5
  172. package/desktop/src-tauri/icons/android/values/ic_launcher_background.xml +0 -4
  173. package/desktop/src-tauri/icons/icon.icns +0 -0
  174. package/desktop/src-tauri/icons/icon.ico +0 -0
  175. package/desktop/src-tauri/src/lib.rs +0 -408
  176. package/desktop/src-tauri/src/main.rs +0 -6
  177. package/desktop/src-tauri/tauri.conf.json +0 -78
  178. package/desktop/src-tauri/tauri.macos.conf.json +0 -18
  179. package/desktop/src-tauri/tauri.release-ci.json +0 -5
  180. package/desktop/src-tauri/tauri.windows.conf.json +0 -16
  181. package/desktop/src-tauri/windows-installer-hooks.nsh +0 -17
  182. package/desktop/tsconfig.json +0 -25
  183. package/desktop/vite.config.ts +0 -26
  184. package/desktop/vitest.config.ts +0 -18
@@ -1,152 +0,0 @@
1
- import { create } from 'zustand'
2
- import { cliTasksApi } from '../api/cliTasks'
3
- import type { CLITask, TaskStatus } from '../types/cliTask'
4
-
5
- type TodoItem = {
6
- content: string
7
- status: string
8
- activeForm?: string
9
- }
10
-
11
- type CLITaskStore = {
12
- /** Current session ID being tracked */
13
- sessionId: string | null
14
- /** Tasks for the current session */
15
- tasks: CLITask[]
16
- /** Whether the task bar is expanded */
17
- expanded: boolean
18
- /** True when all tasks completed and the user already continued chatting.
19
- * Set during history load so the sticky bar is suppressed on page refresh. */
20
- completedAndDismissed: boolean
21
- /** Snapshot of the completed task set that was dismissed */
22
- dismissedCompletionKey: string | null
23
-
24
- /** Fetch tasks for a given session (uses sessionId as taskListId) */
25
- fetchSessionTasks: (sessionId: string) => Promise<void>
26
- /** Refresh tasks for the currently tracked session */
27
- refreshTasks: () => Promise<void>
28
- /** Update tasks from TodoWrite V1 tool input (in-memory, no disk read needed) */
29
- setTasksFromTodos: (todos: TodoItem[]) => void
30
- /** Mark that completed tasks were already dismissed (conversation continued) */
31
- markCompletedAndDismissed: () => void
32
- /** Clear task tracking state */
33
- clearTasks: () => void
34
- /** Toggle expanded state */
35
- toggleExpanded: () => void
36
- }
37
-
38
- function buildCompletedTaskKey(tasks: CLITask[]): string | null {
39
- if (tasks.length === 0 || tasks.some((task) => task.status !== 'completed')) return null
40
-
41
- return tasks
42
- .map((task) => [
43
- task.taskListId,
44
- task.id,
45
- task.subject,
46
- task.status,
47
- task.activeForm ?? '',
48
- task.owner ?? '',
49
- ].join('::'))
50
- .join('|')
51
- }
52
-
53
- function resolveDismissState(tasks: CLITask[], dismissedCompletionKey: string | null) {
54
- const completionKey = buildCompletedTaskKey(tasks)
55
- const keepDismissed = completionKey !== null && completionKey === dismissedCompletionKey
56
-
57
- return {
58
- completedAndDismissed: keepDismissed,
59
- dismissedCompletionKey: keepDismissed ? completionKey : null,
60
- }
61
- }
62
-
63
- function mapTodosToTasks(todos: TodoItem[], sessionId: string | null): CLITask[] {
64
- return todos.map((todo, index) => ({
65
- id: String(index + 1),
66
- subject: todo.content,
67
- description: '',
68
- activeForm: todo.activeForm,
69
- status: (['pending', 'in_progress', 'completed'].includes(todo.status)
70
- ? todo.status
71
- : 'pending') as TaskStatus,
72
- blocks: [],
73
- blockedBy: [],
74
- taskListId: sessionId || '',
75
- }))
76
- }
77
-
78
- export const useCLITaskStore = create<CLITaskStore>((set, get) => ({
79
- sessionId: null,
80
- tasks: [],
81
- expanded: false,
82
- completedAndDismissed: false,
83
- dismissedCompletionKey: null,
84
-
85
- fetchSessionTasks: async (sessionId) => {
86
- set({ sessionId })
87
- try {
88
- const { tasks } = await cliTasksApi.getTasksForList(sessionId)
89
- // Only update if still tracking the same session
90
- if (get().sessionId === sessionId) {
91
- set((state) => ({
92
- tasks,
93
- ...resolveDismissState(tasks, state.dismissedCompletionKey),
94
- }))
95
- }
96
- } catch {
97
- // No tasks for this session — that's fine
98
- if (get().sessionId === sessionId) {
99
- set({ tasks: [], completedAndDismissed: false, dismissedCompletionKey: null })
100
- }
101
- }
102
- },
103
-
104
- refreshTasks: async () => {
105
- const { sessionId } = get()
106
- if (!sessionId) return
107
- try {
108
- const { tasks } = await cliTasksApi.getTasksForList(sessionId)
109
- if (get().sessionId === sessionId) {
110
- set((state) => ({
111
- tasks,
112
- ...resolveDismissState(tasks, state.dismissedCompletionKey),
113
- }))
114
- }
115
- } catch {
116
- // ignore
117
- }
118
- },
119
-
120
- setTasksFromTodos: (todos) => {
121
- const tasks = mapTodosToTasks(todos, get().sessionId)
122
- set((state) => ({
123
- tasks,
124
- ...resolveDismissState(tasks, state.dismissedCompletionKey),
125
- }))
126
- },
127
-
128
- markCompletedAndDismissed: () => {
129
- const completionKey = buildCompletedTaskKey(get().tasks)
130
- if (!completionKey) return
131
-
132
- set({
133
- completedAndDismissed: true,
134
- dismissedCompletionKey: completionKey,
135
- expanded: false,
136
- })
137
- },
138
-
139
- clearTasks: () => {
140
- set({
141
- sessionId: null,
142
- tasks: [],
143
- completedAndDismissed: false,
144
- dismissedCompletionKey: null,
145
- expanded: false,
146
- })
147
- },
148
-
149
- toggleExpanded: () => {
150
- set((s) => ({ expanded: !s.expanded }))
151
- },
152
- }))
@@ -1,77 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2
-
3
- const { startMock, statusMock, logoutMock } = vi.hoisted(() => ({
4
- startMock: vi.fn(),
5
- statusMock: vi.fn(),
6
- logoutMock: vi.fn(),
7
- }))
8
-
9
- vi.mock('../api/hahaOAuth', () => ({
10
- hahaOAuthApi: {
11
- start: startMock,
12
- status: statusMock,
13
- logout: logoutMock,
14
- },
15
- }))
16
-
17
- import { useHahaOAuthStore } from './hahaOAuthStore'
18
-
19
- const initialState = useHahaOAuthStore.getState()
20
-
21
- describe('hahaOAuthStore', () => {
22
- beforeEach(() => {
23
- vi.useFakeTimers()
24
- startMock.mockReset()
25
- statusMock.mockReset()
26
- logoutMock.mockReset()
27
- useHahaOAuthStore.setState({
28
- ...initialState,
29
- status: null,
30
- isPolling: false,
31
- isLoading: false,
32
- error: null,
33
- })
34
- })
35
-
36
- afterEach(() => {
37
- useHahaOAuthStore.getState().stopPolling()
38
- useHahaOAuthStore.setState(initialState)
39
- vi.useRealTimers()
40
- })
41
-
42
- it('login does not start polling until the browser launch succeeds', async () => {
43
- startMock.mockResolvedValue({
44
- authorizeUrl: 'http://localhost:3456/api/haha-oauth/callback',
45
- state: 'state-123',
46
- })
47
-
48
- const result = await useHahaOAuthStore.getState().login()
49
-
50
- expect(result.authorizeUrl).toContain('/api/haha-oauth/callback')
51
- expect(useHahaOAuthStore.getState().isPolling).toBe(false)
52
- })
53
-
54
- it('startPolling stops after the status becomes logged in', async () => {
55
- statusMock
56
- .mockResolvedValueOnce({ loggedIn: false })
57
- .mockResolvedValueOnce({
58
- loggedIn: true,
59
- expiresAt: Date.now() + 60_000,
60
- scopes: ['user:inference'],
61
- subscriptionType: 'max',
62
- })
63
-
64
- useHahaOAuthStore.getState().startPolling()
65
- expect(useHahaOAuthStore.getState().isPolling).toBe(true)
66
-
67
- await vi.advanceTimersByTimeAsync(2_000)
68
- expect(useHahaOAuthStore.getState().isPolling).toBe(true)
69
-
70
- await vi.advanceTimersByTimeAsync(2_000)
71
- expect(useHahaOAuthStore.getState().status).toMatchObject({
72
- loggedIn: true,
73
- subscriptionType: 'max',
74
- })
75
- expect(useHahaOAuthStore.getState().isPolling).toBe(false)
76
- })
77
- })
@@ -1,97 +0,0 @@
1
- // desktop/src/stores/hahaOAuthStore.ts
2
-
3
- import { create } from 'zustand'
4
- import { hahaOAuthApi, type HahaOAuthStatus } from '../api/hahaOAuth'
5
-
6
- const POLL_INTERVAL_MS = 2_000
7
-
8
- type HahaOAuthState = {
9
- status: HahaOAuthStatus | null
10
- isPolling: boolean
11
- isLoading: boolean
12
- error: string | null
13
-
14
- fetchStatus: () => Promise<void>
15
- login: () => Promise<{ authorizeUrl: string }>
16
- logout: () => Promise<void>
17
- startPolling: () => void
18
- stopPolling: () => void
19
- }
20
-
21
- export const useHahaOAuthStore = create<HahaOAuthState>((set, get) => {
22
- let pollTimer: ReturnType<typeof setTimeout> | null = null
23
-
24
- return {
25
- status: null,
26
- isPolling: false,
27
- isLoading: false,
28
- error: null,
29
-
30
- fetchStatus: async () => {
31
- try {
32
- const status = await hahaOAuthApi.status()
33
- set({ status, error: null })
34
- } catch (err) {
35
- set({ error: err instanceof Error ? err.message : String(err) })
36
- }
37
- },
38
-
39
- login: async () => {
40
- set({ isLoading: true, error: null })
41
- try {
42
- const res = await hahaOAuthApi.start()
43
- set({ isLoading: false })
44
- return { authorizeUrl: res.authorizeUrl }
45
- } catch (err) {
46
- set({
47
- isLoading: false,
48
- error: err instanceof Error ? err.message : String(err),
49
- })
50
- throw err
51
- }
52
- },
53
-
54
- logout: async () => {
55
- get().stopPolling()
56
- set({ isLoading: true })
57
- try {
58
- await hahaOAuthApi.logout()
59
- set({ status: { loggedIn: false }, isLoading: false })
60
- } catch (err) {
61
- set({
62
- isLoading: false,
63
- error: err instanceof Error ? err.message : String(err),
64
- })
65
- throw err
66
- }
67
- },
68
-
69
- startPolling: () => {
70
- if (pollTimer) return
71
- set({ isPolling: true })
72
-
73
- const scheduleNext = () => {
74
- pollTimer = setTimeout(async () => {
75
- await get().fetchStatus()
76
- const cur = get().status
77
- if (cur && cur.loggedIn) {
78
- get().stopPolling()
79
- return
80
- }
81
- if (get().isPolling) {
82
- scheduleNext()
83
- }
84
- }, POLL_INTERVAL_MS)
85
- }
86
- scheduleNext()
87
- },
88
-
89
- stopPolling: () => {
90
- if (pollTimer) {
91
- clearTimeout(pollTimer)
92
- pollTimer = null
93
- }
94
- set({ isPolling: false })
95
- },
96
- }
97
- })
@@ -1,101 +0,0 @@
1
- // desktop/src/stores/providerStore.ts
2
-
3
- import { create } from 'zustand'
4
- import { providersApi } from '../api/providers'
5
- import { useSettingsStore } from './settingsStore'
6
- import type {
7
- SavedProvider,
8
- CreateProviderInput,
9
- UpdateProviderInput,
10
- TestProviderConfigInput,
11
- ProviderTestResult,
12
- } from '../types/provider'
13
-
14
- // 与后端 src/server/api/models.ts 的 DEFAULT_MODEL 保持一致:
15
- // 切回"官方"时把聊天页的 currentModel 重置到这个,避免残留第三方 provider
16
- // 的 model id 在官方模型列表里找不到、ModelSelector 显示但不选中的状态。
17
- const OFFICIAL_DEFAULT_MODEL_ID = 'claude-opus-4-7'
18
-
19
- type ProviderStore = {
20
- providers: SavedProvider[]
21
- activeId: string | null
22
- isLoading: boolean
23
- error: string | null
24
-
25
- fetchProviders: () => Promise<void>
26
- createProvider: (input: CreateProviderInput) => Promise<SavedProvider>
27
- updateProvider: (id: string, input: UpdateProviderInput) => Promise<SavedProvider>
28
- deleteProvider: (id: string) => Promise<void>
29
- activateProvider: (id: string) => Promise<void>
30
- activateOfficial: () => Promise<void>
31
- testProvider: (id: string, overrides?: { baseUrl?: string; modelId?: string; apiFormat?: string }) => Promise<ProviderTestResult>
32
- testConfig: (input: TestProviderConfigInput) => Promise<ProviderTestResult>
33
- }
34
-
35
- export const useProviderStore = create<ProviderStore>((set, get) => ({
36
- providers: [],
37
- activeId: null,
38
- isLoading: false,
39
- error: null,
40
-
41
- fetchProviders: async () => {
42
- set({ isLoading: true, error: null })
43
- try {
44
- const { providers, activeId } = await providersApi.list()
45
- set({ providers, activeId, isLoading: false })
46
- } catch (err) {
47
- set({ isLoading: false, error: err instanceof Error ? err.message : String(err) })
48
- }
49
- },
50
-
51
- createProvider: async (input) => {
52
- const { provider } = await providersApi.create(input)
53
- await get().fetchProviders()
54
- return provider
55
- },
56
-
57
- updateProvider: async (id, input) => {
58
- const { provider } = await providersApi.update(id, input)
59
- await get().fetchProviders()
60
- return provider
61
- },
62
-
63
- deleteProvider: async (id) => {
64
- await providersApi.delete(id)
65
- await get().fetchProviders()
66
- },
67
-
68
- activateProvider: async (id) => {
69
- await providersApi.activate(id)
70
- await get().fetchProviders()
71
- // 联动聊天页:把 currentModel 重置到新 provider 的 main model。
72
- // 不这么做的话,用户在切换前手动选过的 model id (写进了 settings.json 的
73
- // `model` 字段) 会继续被后端当作 explicit 返回,但新 provider 的模型列表
74
- // 里没这个 id, ModelSelector 会卡在"显示旧名字 + radio 不选中"。
75
- const provider = get().providers.find((p) => p.id === id)
76
- if (provider) {
77
- const settings = useSettingsStore.getState()
78
- await settings.setModel(provider.models.main)
79
- await settings.fetchAll()
80
- }
81
- },
82
-
83
- activateOfficial: async () => {
84
- await providersApi.activateOfficial()
85
- await get().fetchProviders()
86
- // 切回官方时同样重置 currentModel,避免残留第三方 model id。
87
- const settings = useSettingsStore.getState()
88
- await settings.setModel(OFFICIAL_DEFAULT_MODEL_ID)
89
- await settings.fetchAll()
90
- },
91
-
92
- testProvider: async (id, overrides?) => {
93
- const { result } = await providersApi.test(id, overrides)
94
- return result
95
- },
96
-
97
- testConfig: async (input) => {
98
- const { result } = await providersApi.testConfig(input)
99
- return result
100
- },
101
- }))
@@ -1,63 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2
-
3
- const { createMock, listMock } = vi.hoisted(() => ({
4
- createMock: vi.fn(),
5
- listMock: vi.fn(),
6
- }))
7
-
8
- vi.mock('../api/sessions', () => ({
9
- sessionsApi: {
10
- create: createMock,
11
- list: listMock,
12
- delete: vi.fn(),
13
- rename: vi.fn(),
14
- },
15
- }))
16
-
17
- import { useSessionStore } from './sessionStore'
18
-
19
- const initialState = useSessionStore.getState()
20
-
21
- function delay(ms: number) {
22
- return new Promise((resolve) => setTimeout(resolve, ms))
23
- }
24
-
25
- describe('sessionStore', () => {
26
- beforeEach(() => {
27
- createMock.mockReset()
28
- listMock.mockReset()
29
- useSessionStore.setState({
30
- ...initialState,
31
- sessions: [],
32
- activeSessionId: null,
33
- isLoading: false,
34
- error: null,
35
- selectedProjects: [],
36
- availableProjects: [],
37
- })
38
- })
39
-
40
- afterEach(() => {
41
- useSessionStore.setState(initialState)
42
- })
43
-
44
- it('returns a new session id before the background refresh completes', async () => {
45
- createMock.mockResolvedValue({ sessionId: 'session-optimistic-1' })
46
- listMock.mockImplementation(() => new Promise(() => {}))
47
-
48
- const result = await Promise.race([
49
- useSessionStore.getState().createSession('D:/workspace/code/myself_code/cc-haha'),
50
- delay(100).then(() => 'timed-out'),
51
- ])
52
-
53
- expect(result).toBe('session-optimistic-1')
54
- expect(useSessionStore.getState().activeSessionId).toBe('session-optimistic-1')
55
- expect(useSessionStore.getState().sessions[0]).toMatchObject({
56
- id: 'session-optimistic-1',
57
- title: 'New Session',
58
- workDir: 'D:/workspace/code/myself_code/cc-haha',
59
- workDirExists: true,
60
- })
61
- expect(listMock).toHaveBeenCalledOnce()
62
- })
63
- })
@@ -1,102 +0,0 @@
1
- import { create } from 'zustand'
2
- import { sessionsApi } from '../api/sessions'
3
- import type { SessionListItem } from '../types/session'
4
-
5
- type SessionStore = {
6
- sessions: SessionListItem[]
7
- activeSessionId: string | null
8
- isLoading: boolean
9
- error: string | null
10
- selectedProjects: string[]
11
- availableProjects: string[]
12
-
13
- fetchSessions: (project?: string) => Promise<void>
14
- createSession: (workDir?: string) => Promise<string>
15
- deleteSession: (id: string) => Promise<void>
16
- renameSession: (id: string, title: string) => Promise<void>
17
- updateSessionTitle: (id: string, title: string) => void
18
- setActiveSession: (id: string | null) => void
19
- setSelectedProjects: (projects: string[]) => void
20
- }
21
-
22
- export const useSessionStore = create<SessionStore>((set, get) => ({
23
- sessions: [],
24
- activeSessionId: null,
25
- isLoading: false,
26
- error: null,
27
- selectedProjects: [],
28
- availableProjects: [],
29
-
30
- fetchSessions: async (project?: string) => {
31
- set({ isLoading: true, error: null })
32
- try {
33
- const { sessions: raw } = await sessionsApi.list({ project, limit: 100 })
34
- // Deduplicate by session ID — keep the most recently modified entry
35
- const byId = new Map<string, SessionListItem>()
36
- for (const s of raw) {
37
- const existing = byId.get(s.id)
38
- if (!existing || new Date(s.modifiedAt) > new Date(existing.modifiedAt)) {
39
- byId.set(s.id, s)
40
- }
41
- }
42
- const sessions = [...byId.values()]
43
- const availableProjects = [...new Set(sessions.map((s) => s.projectPath).filter(Boolean))].sort()
44
- set({ sessions, availableProjects, isLoading: false })
45
- } catch (err) {
46
- set({ error: (err as Error).message, isLoading: false })
47
- }
48
- },
49
-
50
- createSession: async (workDir?: string) => {
51
- const { sessionId: id } = await sessionsApi.create(workDir || undefined)
52
- const now = new Date().toISOString()
53
- const optimisticSession: SessionListItem = {
54
- id,
55
- title: 'New Session',
56
- createdAt: now,
57
- modifiedAt: now,
58
- messageCount: 0,
59
- projectPath: '',
60
- workDir: workDir ?? null,
61
- workDirExists: true,
62
- }
63
-
64
- set((state) => ({
65
- sessions: state.sessions.some((session) => session.id === id)
66
- ? state.sessions
67
- : [optimisticSession, ...state.sessions],
68
- activeSessionId: id,
69
- }))
70
-
71
- void get().fetchSessions()
72
- return id
73
- },
74
-
75
- deleteSession: async (id: string) => {
76
- await sessionsApi.delete(id)
77
- set((s) => ({
78
- sessions: s.sessions.filter((session) => session.id !== id),
79
- activeSessionId: s.activeSessionId === id ? null : s.activeSessionId,
80
- }))
81
- },
82
-
83
- renameSession: async (id: string, title: string) => {
84
- await sessionsApi.rename(id, title)
85
- set((s) => ({
86
- sessions: s.sessions.map((session) =>
87
- session.id === id ? { ...session, title } : session,
88
- ),
89
- }))
90
- },
91
-
92
- updateSessionTitle: (id, title) => {
93
- set((s) => ({
94
- sessions: s.sessions.map((session) =>
95
- session.id === id ? { ...session, title } : session,
96
- ),
97
- }))
98
- },
99
-
100
- setActiveSession: (id) => set({ activeSessionId: id }),
101
- setSelectedProjects: (projects) => set({ selectedProjects: projects }),
102
- }))