moi-computer 0.11.1-next.5 → 0.12.1-next.0

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 (141) hide show
  1. package/README.md +1 -1
  2. package/client/AGENTS.md +2 -2
  3. package/client/api/app-ui-keys.ts +1 -1
  4. package/client/api/workspace-keys.ts +1 -3
  5. package/client/app/routes/WorkspaceRoute.tsx +2 -8
  6. package/client/features/applets/applet-runtime.ts +11 -13
  7. package/client/features/chat/ChatPanel.tsx +70 -49
  8. package/client/features/chat/ChatPopup.tsx +81 -8
  9. package/client/features/chat/applet-chat-intents.ts +31 -12
  10. package/client/features/chat/chat-send.ts +33 -1
  11. package/client/features/chat/chat-store.ts +10 -0
  12. package/client/features/chat/composer/ChatComposer.tsx +24 -27
  13. package/client/features/chat/composer/ModelPicker.tsx +3 -3
  14. package/client/features/chat/composer/attachments/draft-attachments.ts +21 -4
  15. package/client/features/chat/composer/useWorkspaceComposerState.tsx +3 -3
  16. package/client/features/chat/connection/chat-frames.ts +14 -7
  17. package/client/features/chat/messages/ChatEmptyState.tsx +33 -19
  18. package/client/features/chat/messages/MarkdownContent.tsx +3 -3
  19. package/client/features/chat/messages/fork-history.ts +14 -0
  20. package/client/features/chat/sessions/ChatSelector.tsx +138 -79
  21. package/client/features/chat/sessions/api.ts +109 -19
  22. package/client/features/chat/sessions/browser-tab-state.ts +30 -7
  23. package/client/features/chat/sessions/useSelectedSession.ts +217 -51
  24. package/client/features/chat/useChat.ts +43 -45
  25. package/client/features/collab/client.ts +10 -11
  26. package/client/features/collab/hooks.tsx +6 -11
  27. package/client/features/collab/host-state.ts +57 -128
  28. package/client/features/collab/provider.tsx +3 -3
  29. package/client/features/collab/testing/fake-engine.ts +6 -27
  30. package/client/features/collab/workspace-users-menu.tsx +3 -7
  31. package/client/features/drawings/{useViewBuilderSketch.ts → useViewSketch.ts} +7 -7
  32. package/client/features/home/HomePage.tsx +2 -2
  33. package/client/features/overview/Overview.tsx +3 -6
  34. package/client/features/overview/default/ViewsWidget.tsx +5 -12
  35. package/client/features/overview/default/registry.tsx +2 -4
  36. package/client/features/views/PendingViewScreen.tsx +279 -0
  37. package/client/features/views/ViewManager.tsx +10 -10
  38. package/client/features/views/api.ts +63 -130
  39. package/client/features/views/useViewActions.ts +151 -0
  40. package/client/features/views/useViewDrafts.ts +79 -0
  41. package/client/features/views/view-presentation.ts +4 -5
  42. package/client/features/views/view-submission.ts +88 -0
  43. package/client/features/workspace/WorkspaceMenu.tsx +63 -0
  44. package/client/features/workspace/WorkspaceScreen.tsx +180 -375
  45. package/client/features/workspace/browser-tab-state.ts +16 -9
  46. package/client/features/workspace/moi-context.ts +13 -15
  47. package/client/features/workspace/tab-resolution.ts +16 -29
  48. package/client/features/workspace/useWorkspaceNavigation.ts +146 -104
  49. package/client/index.tsx +5 -1
  50. package/client/runtime/useWorkspaceEvents.ts +7 -6
  51. package/client/store/ui.ts +25 -29
  52. package/dist/chunk-1zhnhy00.js +1 -0
  53. package/dist/chunk-27501vke.js +1 -0
  54. package/dist/{chunk-jf6czgrz.js → chunk-9xtv6djt.js} +2 -2
  55. package/dist/chunk-am1x230f.js +2 -0
  56. package/dist/{chunk-nez8sdta.js → chunk-darpsw65.js} +1 -1
  57. package/dist/{chunk-97eg9mjn.js → chunk-gps4qc38.js} +1 -1
  58. package/dist/{chunk-3a48fyf7.js → chunk-hzwr8dp8.js} +4 -4
  59. package/dist/{chunk-efdyz6xp.js → chunk-j905va8r.js} +1 -1
  60. package/dist/chunk-n33w9y38.js +10 -0
  61. package/dist/chunk-r63ks44z.js +68 -0
  62. package/dist/{chunk-vfpsc75k.js → chunk-vqpkqtdr.js} +1 -1
  63. package/dist/chunk-wd46nk26.css +1 -0
  64. package/dist/chunk-xgt7vxt9.js +1 -0
  65. package/dist/{chunk-z3byfve5.js → chunk-yvzhwtfa.js} +2 -2
  66. package/dist/index.html +1 -1
  67. package/lib/ids.ts +2 -5
  68. package/lib/moi-context.ts +100 -73
  69. package/lib/navigation.ts +48 -87
  70. package/lib/session-drafts.ts +10 -0
  71. package/lib/types.ts +64 -31
  72. package/lib/view-build-directives.ts +12 -0
  73. package/lib/workspace-layout.ts +1 -1
  74. package/lib/workspace-tabs.ts +12 -7
  75. package/package.json +3 -1
  76. package/server/agent-launcher.ts +27 -0
  77. package/server/api.ts +119 -209
  78. package/server/app-config.ts +21 -2
  79. package/server/applets/build-worker.ts +2 -1
  80. package/server/applets/view-source.ts +7 -1
  81. package/server/cli-env.ts +72 -50
  82. package/server/cli.ts +127 -70
  83. package/server/control.ts +82 -63
  84. package/server/data-dir.ts +13 -0
  85. package/server/functions.ts +2 -1
  86. package/server/harness/README.md +8 -0
  87. package/server/harness/acp/adapter.ts +2 -2
  88. package/server/harness/acp/client.ts +2 -1
  89. package/server/harness/acp/discovery.ts +3 -3
  90. package/server/harness/acp/session.ts +6 -9
  91. package/server/harness/claude-code/adapter.ts +13 -8
  92. package/server/harness/claude-code/auth.ts +3 -2
  93. package/server/harness/claude-code/cli.ts +3 -1
  94. package/server/harness/claude-code/git-worktree.ts +5 -2
  95. package/server/harness/claude-code/index.ts +5 -0
  96. package/server/harness/claude-code/mcp.ts +2 -0
  97. package/server/harness/claude-code/models.ts +2 -0
  98. package/server/harness/claude-code/session.ts +5 -34
  99. package/server/harness/claude-code/sessions.ts +8 -12
  100. package/server/harness/codex/NOTES.md +23 -4
  101. package/server/harness/codex/adapter.ts +5 -3
  102. package/server/harness/codex/client.ts +13 -21
  103. package/server/harness/codex/index.ts +18 -0
  104. package/server/harness/codex/session.ts +6 -14
  105. package/server/harness/codex/thread-list.ts +74 -0
  106. package/server/harness/fork.ts +12 -0
  107. package/server/harness/openclaw/adapter.ts +3 -3
  108. package/server/harness/openclaw/session.ts +2 -30
  109. package/server/harness/session-title.ts +12 -3
  110. package/server/harness/types.ts +8 -3
  111. package/server/moi-scaffold.ts +53 -20
  112. package/server/pending-views.ts +164 -0
  113. package/server/registry.ts +14 -4
  114. package/server/selected-session.ts +91 -44
  115. package/server/service.ts +16 -2
  116. package/server/session-archive.ts +32 -0
  117. package/server/session-config.ts +16 -111
  118. package/server/session-lifecycle.ts +17 -0
  119. package/server/session-store.ts +127 -0
  120. package/server/status.ts +3 -1
  121. package/server/tabs.ts +7 -10
  122. package/server/view-sessions.ts +267 -0
  123. package/server/views.ts +30 -41
  124. package/server/web.ts +47 -45
  125. package/server/workspace-env.ts +27 -0
  126. package/server/workspace-init.ts +12 -5
  127. package/workspace/.claude/skills/moi-workspace/SKILL.md +49 -20
  128. package/workspace/.claude/skills/moi-workspace/references/COLLAB.md +2 -5
  129. package/client/features/views/ViewBuilder.tsx +0 -239
  130. package/client/features/views/useViewBuilderActions.ts +0 -103
  131. package/client/features/views/useViewBuilderDrafts.ts +0 -68
  132. package/dist/chunk-2jncyq65.js +0 -1
  133. package/dist/chunk-9zpvdws4.js +0 -68
  134. package/dist/chunk-h2kj1ysj.js +0 -1
  135. package/dist/chunk-hvj7tp3y.js +0 -1
  136. package/dist/chunk-nzwgm8vc.css +0 -1
  137. package/dist/chunk-ryg9z3kn.js +0 -10
  138. package/dist/chunk-tpn177bt.js +0 -2
  139. package/lib/view-builder-directives.ts +0 -16
  140. package/server/chat-selection.ts +0 -22
  141. package/server/view-builders.ts +0 -453
@@ -0,0 +1,151 @@
1
+ import { useUiStore } from '@/client/store/ui'
2
+ import { draftSessionId, composerDraftKey } from '@/lib/session-drafts'
3
+ import { useQueryClient } from '@tanstack/react-query'
4
+
5
+ import {
6
+ prepareOptimisticSend,
7
+ moveChatDraft,
8
+ finishComposerSend,
9
+ attachmentsForSend,
10
+ resolveChatRunOptions,
11
+ startOptimisticSession
12
+ } from '@/client/features/chat/chat-send'
13
+ import {
14
+ optimisticallySetSelectedSession,
15
+ renameSelectedSessionInCache,
16
+ usePinnedSession
17
+ } from '@/client/features/chat/sessions/useSelectedSession'
18
+ import { workspaceKeys } from '@/client/api/workspace-keys'
19
+ import { useCollabEnabled } from '@/client/features/collab'
20
+ import { useWorkspaceAgent } from '@/client/features/workspace/api'
21
+ import { useWorkspaceLayoutCtx } from '@/client/features/workspace/WorkspaceLayoutContext'
22
+ import {
23
+ useCreateView,
24
+ useDiscardView,
25
+ useSaveViewDraft,
26
+ useSubmitView
27
+ } from '@/client/features/views/api'
28
+ import { recoverViewSubmission } from './view-submission'
29
+ import type { PendingView, SessionRecord, ViewInfo } from '@/lib/types'
30
+ import { viewTabId } from '@/lib/workspace-tabs'
31
+
32
+ export function useViewActions() {
33
+ const queryClient = useQueryClient()
34
+ const collabEnabled = useCollabEnabled()
35
+ const selectionScope = collabEnabled ? 'browser-tab' : 'shared'
36
+ const { workspaceId, layout } = useWorkspaceLayoutCtx()
37
+ const { pinnedSessionId } = usePinnedSession()
38
+ const modelData = useWorkspaceAgent(workspaceId).data
39
+ const createMutation = useCreateView(workspaceId)
40
+ const saveMutation = useSaveViewDraft(workspaceId)
41
+ const submitMutation = useSubmitView(workspaceId)
42
+ const discardMutation = useDiscardView(workspaceId)
43
+
44
+ const create = () => createMutation.mutateAsync()
45
+
46
+ const save = (viewId: string, requirements: string) =>
47
+ saveMutation.mutateAsync({ viewId, requirements })
48
+
49
+ const submit = async (pendingView: PendingView, requirements: string) => {
50
+ const text = requirements.trim()
51
+ const draftId = pinnedSessionId ?? draftSessionId(viewTabId(pendingView.id))
52
+ const sessionId = pinnedSessionId ?? crypto.randomUUID()
53
+ const attachments = attachmentsForSend(workspaceId, draftId)
54
+ if (!text && attachments.length === 0) return
55
+
56
+ if (!pinnedSessionId)
57
+ startOptimisticSession({
58
+ tabId: viewTabId(pendingView.id),
59
+ queryClient,
60
+ workspaceId,
61
+ sessionId,
62
+ text,
63
+ filenames: attachments.map(attachment => attachment.label)
64
+ })
65
+ if (!pinnedSessionId) {
66
+ moveChatDraft(workspaceId, draftId, sessionId)
67
+ optimisticallySetSelectedSession(
68
+ queryClient,
69
+ workspaceId,
70
+ sessionId,
71
+ viewTabId(pendingView.id),
72
+ selectionScope
73
+ )
74
+ }
75
+ const prepared = prepareOptimisticSend(
76
+ { queryClient, workspaceId, sessionId, text },
77
+ attachments
78
+ )
79
+
80
+ const config = queryClient.getQueryData<SessionRecord>(
81
+ workspaceKeys.session(workspaceId, sessionId)
82
+ )?.config
83
+ const { model, effort, fastMode, stream } = resolveChatRunOptions(
84
+ modelData,
85
+ config?.model ?? layout.selectedModel,
86
+ config?.effort ?? layout.selectedEffort,
87
+ config?.fastMode ?? layout.selectedFastMode
88
+ )
89
+
90
+ queryClient.setQueryData<ViewInfo[]>(workspaceKeys.views(workspaceId), views =>
91
+ views?.map(view =>
92
+ view.id === pendingView.id && view.status === 'draft'
93
+ ? { ...view, status: 'starting', requirements: text, executionSessionId: sessionId }
94
+ : view
95
+ )
96
+ )
97
+
98
+ try {
99
+ const result = await submitMutation.mutateAsync({
100
+ viewId: pendingView.id,
101
+ sessionId,
102
+ requirements: text,
103
+ optimisticId: prepared.optimisticId,
104
+ selectedSessionScope: selectionScope,
105
+ ...(attachments.length > 0
106
+ ? {
107
+ attachments: prepared.attachments
108
+ }
109
+ : {}),
110
+ model,
111
+ effort,
112
+ fastMode,
113
+ stream
114
+ })
115
+ moveChatDraft(workspaceId, sessionId, result.sessionId)
116
+ renameSelectedSessionInCache(queryClient, workspaceId, sessionId, result.sessionId)
117
+ if (!pinnedSessionId)
118
+ optimisticallySetSelectedSession(
119
+ queryClient,
120
+ workspaceId,
121
+ result.sessionId,
122
+ viewTabId(pendingView.id),
123
+ selectionScope
124
+ )
125
+ finishComposerSend(workspaceId, attachments)
126
+ const draftKey = composerDraftKey(workspaceId, result.sessionId)
127
+ const ui = useUiStore.getState()
128
+ if (ui.composerDrafts[draftKey]?.trim() === text) ui.setComposerDraft(draftKey, null)
129
+ } catch (error) {
130
+ await recoverViewSubmission(
131
+ queryClient,
132
+ workspaceId,
133
+ pendingView.id,
134
+ sessionId,
135
+ text,
136
+ !!pinnedSessionId,
137
+ selectionScope
138
+ )
139
+ throw error
140
+ }
141
+ }
142
+
143
+ const discard = (viewId: string) => discardMutation.mutateAsync(viewId)
144
+
145
+ return {
146
+ create,
147
+ save,
148
+ submit,
149
+ discard
150
+ }
151
+ }
@@ -0,0 +1,79 @@
1
+ import { useCallback, useEffect, useRef } from 'react'
2
+ import { toast } from '@/client/components/ui/toast'
3
+ import { useLatestRef } from '@/client/lib/use-latest-ref'
4
+ import { useUiStore } from '@/client/store/ui'
5
+ import { composerDraftKey, draftSessionId } from '@/lib/session-drafts'
6
+ import { viewTabId } from '@/lib/workspace-tabs'
7
+ import type { PendingView } from '@/lib/types'
8
+
9
+ type UseViewDraftsOptions = {
10
+ workspaceId: string
11
+ pendingViews: PendingView[]
12
+ onSave: (viewId: string, requirements: string) => Promise<unknown>
13
+ }
14
+
15
+ // The composer owns local text. This hook seeds server-saved requirements and
16
+ // autosaves changes without subscribing the workspace screen to keystrokes.
17
+ export function useViewDrafts({ workspaceId, pendingViews, onSave }: UseViewDraftsOptions) {
18
+ const initializedRef = useRef(new Set<string>())
19
+ const timersRef = useRef(new Map<string, ReturnType<typeof setTimeout>>())
20
+ const pendingViewsRef = useLatestRef(pendingViews)
21
+ const onSaveRef = useLatestRef(onSave)
22
+ const clear = useCallback(
23
+ (viewId: string) => {
24
+ clearTimeout(timersRef.current.get(viewId))
25
+ timersRef.current.delete(viewId)
26
+ useUiStore
27
+ .getState()
28
+ .setComposerDraft(composerDraftKey(workspaceId, draftSessionId(viewTabId(viewId))), null)
29
+ },
30
+ [workspaceId]
31
+ )
32
+
33
+ useEffect(() => {
34
+ for (const view of pendingViews) {
35
+ const draftId = draftSessionId(viewTabId(view.id))
36
+ const key = composerDraftKey(workspaceId, draftId)
37
+ useUiStore.getState().moveComposerDraft(draftId, key)
38
+ if (view.status !== 'draft') clear(view.id)
39
+ else if (!initializedRef.current.has(key)) {
40
+ initializedRef.current.add(key)
41
+ if (useUiStore.getState().composerDrafts[key] === undefined)
42
+ useUiStore.getState().setComposerDraft(key, view.requirements)
43
+ }
44
+ }
45
+ }, [workspaceId, pendingViews, clear])
46
+
47
+ useEffect(() => {
48
+ const timers = timersRef.current
49
+ const unsubscribe = useUiStore.subscribe((state, previous) => {
50
+ for (const view of pendingViewsRef.current) {
51
+ if (view.status !== 'draft') continue
52
+ const key = composerDraftKey(workspaceId, draftSessionId(viewTabId(view.id)))
53
+ const value = state.composerDrafts[key]
54
+ if (value === previous.composerDrafts[key]) continue
55
+ clearTimeout(timers.get(view.id))
56
+ timers.delete(view.id)
57
+ if (value === undefined) continue
58
+ timers.set(
59
+ view.id,
60
+ setTimeout(() => {
61
+ timers.delete(view.id)
62
+ if (pendingViewsRef.current.find(item => item.id === view.id)?.status !== 'draft')
63
+ return
64
+ void onSaveRef.current(view.id, value).catch(() => {
65
+ toast.add({ title: 'Couldn’t save view description', type: 'error' })
66
+ })
67
+ }, 500)
68
+ )
69
+ }
70
+ })
71
+ return () => {
72
+ unsubscribe()
73
+ for (const timer of timers.values()) clearTimeout(timer)
74
+ timers.clear()
75
+ }
76
+ }, [workspaceId, pendingViewsRef, onSaveRef])
77
+
78
+ return { clear }
79
+ }
@@ -1,13 +1,12 @@
1
1
  import { IconArticle, type TablerIcon } from '@tabler/icons-react'
2
2
 
3
3
  import { resolveAppIcon } from '@/client/lib/app-icon-registry'
4
- import type { ViewBuilder, ViewInfo } from '@/lib/types'
4
+ import type { ViewInfo } from '@/lib/types'
5
5
 
6
6
  export function getViewLabel(view: ViewInfo): string {
7
- return view.config.title || view.id
7
+ return view.title || (view.status === 'compiled' ? view.id : 'New view')
8
8
  }
9
9
 
10
- export function getViewIcon(view: ViewInfo, builders: readonly ViewBuilder[]): TablerIcon {
11
- const builder = builders.find(candidate => candidate.viewId === view.id)
12
- return resolveAppIcon(view.config.icon) ?? resolveAppIcon(builder?.icon) ?? IconArticle
10
+ export function getViewIcon(view: ViewInfo): TablerIcon {
11
+ return resolveAppIcon(view.icon) ?? IconArticle
13
12
  }
@@ -0,0 +1,88 @@
1
+ import type { QueryClient } from '@tanstack/react-query'
2
+ import { requestJson } from '@/client/api/http'
3
+ import { workspaceKeys } from '@/client/api/workspace-keys'
4
+ import { appUiKeys } from '@/client/api/app-ui-keys'
5
+ import {
6
+ readSelectedSession,
7
+ writeSelectedSession
8
+ } from '@/client/features/chat/sessions/browser-tab-state'
9
+ import { selectedSessionKey } from '@/client/features/chat/sessions/useSelectedSession'
10
+ import { moveChatDraft } from '@/client/features/chat/chat-send'
11
+ import { liveStore } from '@/client/features/chat/chat-store'
12
+ import { useUiStore } from '@/client/store/ui'
13
+ import { composerDraftKey, draftSessionId } from '@/lib/session-drafts'
14
+ import { viewTabId } from '@/lib/workspace-tabs'
15
+ import type {
16
+ PendingView,
17
+ SelectedSessionScope,
18
+ SessionInfo,
19
+ ViewInfo,
20
+ WorkspaceSessionSelection
21
+ } from '@/lib/types'
22
+
23
+ function pendingView(view: ViewInfo | undefined): PendingView | undefined {
24
+ return view?.status === 'compiled' ? undefined : view
25
+ }
26
+
27
+ // A failed HTTP response does not prove startup failed. Refresh the server's
28
+ // state before restoring the fresh composer; never replay the request.
29
+ export async function recoverViewSubmission(
30
+ queryClient: QueryClient,
31
+ workspaceId: string,
32
+ viewId: string,
33
+ sessionId: string,
34
+ text: string,
35
+ pinned: boolean,
36
+ selectionScope: SelectedSessionScope = 'shared'
37
+ ) {
38
+ const cachedView = pendingView(
39
+ queryClient
40
+ .getQueryData<ViewInfo[]>(workspaceKeys.views(workspaceId))
41
+ ?.find(view => view.id === viewId)
42
+ )
43
+ let target = cachedView?.executionSessionId ?? sessionId
44
+ try {
45
+ const [{ views }, selection] = await Promise.all([
46
+ requestJson<{ views: ViewInfo[] }>(`/api/workspaces/${workspaceId}/views`),
47
+ requestJson<WorkspaceSessionSelection>(`/api/workspaces/${workspaceId}/selected-session`)
48
+ ])
49
+ const view = pendingView(views.find(view => view.id === viewId))
50
+ if (!pinned && view?.status === 'draft') {
51
+ target = draftSessionId(viewTabId(viewId))
52
+ queryClient.setQueryData<SessionInfo[]>(workspaceKeys.sessions(workspaceId), sessions =>
53
+ sessions?.filter(session => session.sessionId !== sessionId)
54
+ )
55
+ queryClient.removeQueries({ queryKey: workspaceKeys.events(workspaceId, sessionId) })
56
+ } else {
57
+ target =
58
+ view?.executionSessionId ??
59
+ (pinned ? selection.pinned : selection.selected[viewTabId(viewId)]) ??
60
+ sessionId
61
+ }
62
+ moveChatDraft(workspaceId, sessionId, target)
63
+ if (view?.status === 'draft' || view?.status === 'failed')
64
+ liveStore.getState().setActivity(workspaceId, target, 'idle')
65
+ queryClient.setQueryData(workspaceKeys.views(workspaceId), views)
66
+ queryClient.setQueryData(appUiKeys.sessionSelection(workspaceId), selection)
67
+ if (selectionScope === 'browser-tab' && !pinned) {
68
+ const local =
69
+ queryClient.getQueryData<WorkspaceSessionSelection>(
70
+ selectedSessionKey(workspaceId, 'browser-tab')
71
+ ) ?? readSelectedSession(workspaceId)
72
+ const selected = { ...local.selected }
73
+ if (view?.status === 'draft') delete selected[viewTabId(viewId)]
74
+ else selected[viewTabId(viewId)] = target
75
+ const next = { selected, pinned: null }
76
+ queryClient.setQueryData(selectedSessionKey(workspaceId, 'browser-tab'), next)
77
+ writeSelectedSession(workspaceId, next)
78
+ }
79
+ } catch {
80
+ moveChatDraft(workspaceId, sessionId, target)
81
+ // Offline: retain the draft at its current identity until state can refresh.
82
+ void queryClient.invalidateQueries({ queryKey: workspaceKeys.views(workspaceId) })
83
+ void queryClient.invalidateQueries({ queryKey: appUiKeys.sessionSelection(workspaceId) })
84
+ }
85
+ const draftKey = composerDraftKey(workspaceId, target)
86
+ const ui = useUiStore.getState()
87
+ ui.setComposerDraft(draftKey, ui.composerDrafts[draftKey] ?? text)
88
+ }
@@ -0,0 +1,63 @@
1
+ import { useState } from 'react'
2
+
3
+ import { IconLetterCase, IconSettings } from '@tabler/icons-react'
4
+
5
+ import { WorkspaceIcon } from '@/client/components/shared/WorkspaceIcon'
6
+ import {
7
+ DropdownMenu,
8
+ DropdownMenuContent,
9
+ DropdownMenuGroup,
10
+ DropdownMenuItem,
11
+ DropdownMenuTrigger
12
+ } from '@/client/components/ui/dropdown-menu'
13
+ import {
14
+ WorkspaceSettingsDialog,
15
+ WorkspaceSettingsDialogTrigger
16
+ } from '@/client/features/settings/WorkspaceSettingsDialog'
17
+ import { useWorkspaceLayoutCtx } from './WorkspaceLayoutContext'
18
+
19
+ type WorkspaceMenuProps = {
20
+ onOpenTheme: () => void
21
+ }
22
+
23
+ export function WorkspaceMenu({ onOpenTheme }: WorkspaceMenuProps) {
24
+ const { layout, name, provider } = useWorkspaceLayoutCtx()
25
+ const [iconHovered, setIconHovered] = useState(false)
26
+
27
+ return (
28
+ <WorkspaceSettingsDialog>
29
+ <DropdownMenu>
30
+ <DropdownMenuTrigger
31
+ className="flex min-w-0 cursor-pointer items-center gap-2 rounded-sm outline-none focus-visible:ring-3 focus-visible:ring-ring/50"
32
+ aria-label={`${name ?? 'Workspace'} menu`}
33
+ onPointerEnter={() => setIconHovered(true)}
34
+ onPointerLeave={() => setIconHovered(false)}
35
+ >
36
+ <WorkspaceIcon
37
+ icon={iconHovered ? { ...layout.icon, type: 'glyph', value: 'dots' } : layout.icon}
38
+ workspaceType={provider}
39
+ workspaceTheme={layout.theme}
40
+ className="size-5 rounded-sm"
41
+ />
42
+ {name && <span className="truncate text-sm font-medium text-foreground">{name}</span>}
43
+ </DropdownMenuTrigger>
44
+ <DropdownMenuContent align="start" sideOffset={6} className="w-36">
45
+ <DropdownMenuGroup>
46
+ <DropdownMenuItem onClick={onOpenTheme}>
47
+ <IconLetterCase stroke={1.75} />
48
+ Theme
49
+ </DropdownMenuItem>
50
+ <DropdownMenuItem
51
+ nativeButton
52
+ render={<WorkspaceSettingsDialogTrigger />}
53
+ className="w-full"
54
+ >
55
+ <IconSettings stroke={1.75} />
56
+ Settings
57
+ </DropdownMenuItem>
58
+ </DropdownMenuGroup>
59
+ </DropdownMenuContent>
60
+ </DropdownMenu>
61
+ </WorkspaceSettingsDialog>
62
+ )
63
+ }