moi-computer 0.12.0 → 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 (140) 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/useWorkspaceComposerState.tsx +3 -3
  15. package/client/features/chat/connection/chat-frames.ts +14 -7
  16. package/client/features/chat/messages/ChatEmptyState.tsx +33 -19
  17. package/client/features/chat/messages/MarkdownContent.tsx +3 -3
  18. package/client/features/chat/messages/fork-history.ts +14 -0
  19. package/client/features/chat/sessions/ChatSelector.tsx +138 -79
  20. package/client/features/chat/sessions/api.ts +109 -19
  21. package/client/features/chat/sessions/browser-tab-state.ts +30 -7
  22. package/client/features/chat/sessions/useSelectedSession.ts +217 -51
  23. package/client/features/chat/useChat.ts +43 -45
  24. package/client/features/collab/client.ts +10 -11
  25. package/client/features/collab/hooks.tsx +6 -11
  26. package/client/features/collab/host-state.ts +57 -128
  27. package/client/features/collab/provider.tsx +3 -3
  28. package/client/features/collab/testing/fake-engine.ts +6 -27
  29. package/client/features/collab/workspace-users-menu.tsx +3 -7
  30. package/client/features/drawings/{useViewBuilderSketch.ts → useViewSketch.ts} +7 -7
  31. package/client/features/home/HomePage.tsx +2 -2
  32. package/client/features/overview/Overview.tsx +3 -6
  33. package/client/features/overview/default/ViewsWidget.tsx +5 -12
  34. package/client/features/overview/default/registry.tsx +2 -4
  35. package/client/features/views/PendingViewScreen.tsx +279 -0
  36. package/client/features/views/ViewManager.tsx +10 -10
  37. package/client/features/views/api.ts +63 -130
  38. package/client/features/views/useViewActions.ts +151 -0
  39. package/client/features/views/useViewDrafts.ts +79 -0
  40. package/client/features/views/view-presentation.ts +4 -5
  41. package/client/features/views/view-submission.ts +88 -0
  42. package/client/features/workspace/WorkspaceMenu.tsx +63 -0
  43. package/client/features/workspace/WorkspaceScreen.tsx +180 -375
  44. package/client/features/workspace/browser-tab-state.ts +16 -9
  45. package/client/features/workspace/moi-context.ts +13 -15
  46. package/client/features/workspace/tab-resolution.ts +16 -29
  47. package/client/features/workspace/useWorkspaceNavigation.ts +146 -104
  48. package/client/index.tsx +5 -1
  49. package/client/runtime/useWorkspaceEvents.ts +7 -6
  50. package/client/store/ui.ts +25 -29
  51. package/dist/chunk-1zhnhy00.js +1 -0
  52. package/dist/chunk-27501vke.js +1 -0
  53. package/dist/{chunk-jf6czgrz.js → chunk-9xtv6djt.js} +2 -2
  54. package/dist/chunk-am1x230f.js +2 -0
  55. package/dist/{chunk-nez8sdta.js → chunk-darpsw65.js} +1 -1
  56. package/dist/{chunk-97eg9mjn.js → chunk-gps4qc38.js} +1 -1
  57. package/dist/{chunk-3a48fyf7.js → chunk-hzwr8dp8.js} +4 -4
  58. package/dist/{chunk-efdyz6xp.js → chunk-j905va8r.js} +1 -1
  59. package/dist/chunk-n33w9y38.js +10 -0
  60. package/dist/chunk-r63ks44z.js +68 -0
  61. package/dist/{chunk-vfpsc75k.js → chunk-vqpkqtdr.js} +1 -1
  62. package/dist/chunk-wd46nk26.css +1 -0
  63. package/dist/chunk-xgt7vxt9.js +1 -0
  64. package/dist/{chunk-z3byfve5.js → chunk-yvzhwtfa.js} +2 -2
  65. package/dist/index.html +1 -1
  66. package/lib/ids.ts +2 -5
  67. package/lib/moi-context.ts +100 -73
  68. package/lib/navigation.ts +48 -87
  69. package/lib/session-drafts.ts +10 -0
  70. package/lib/types.ts +64 -31
  71. package/lib/view-build-directives.ts +12 -0
  72. package/lib/workspace-layout.ts +1 -1
  73. package/lib/workspace-tabs.ts +12 -7
  74. package/package.json +3 -1
  75. package/server/agent-launcher.ts +27 -0
  76. package/server/api.ts +119 -209
  77. package/server/app-config.ts +21 -2
  78. package/server/applets/build-worker.ts +2 -1
  79. package/server/applets/view-source.ts +7 -1
  80. package/server/cli-env.ts +72 -50
  81. package/server/cli.ts +101 -64
  82. package/server/control.ts +82 -63
  83. package/server/data-dir.ts +13 -0
  84. package/server/functions.ts +2 -1
  85. package/server/harness/README.md +8 -0
  86. package/server/harness/acp/adapter.ts +2 -2
  87. package/server/harness/acp/client.ts +2 -1
  88. package/server/harness/acp/discovery.ts +3 -3
  89. package/server/harness/acp/session.ts +6 -9
  90. package/server/harness/claude-code/adapter.ts +13 -8
  91. package/server/harness/claude-code/auth.ts +3 -2
  92. package/server/harness/claude-code/cli.ts +3 -1
  93. package/server/harness/claude-code/git-worktree.ts +5 -2
  94. package/server/harness/claude-code/index.ts +5 -0
  95. package/server/harness/claude-code/mcp.ts +2 -0
  96. package/server/harness/claude-code/models.ts +2 -0
  97. package/server/harness/claude-code/session.ts +5 -34
  98. package/server/harness/claude-code/sessions.ts +8 -12
  99. package/server/harness/codex/NOTES.md +23 -4
  100. package/server/harness/codex/adapter.ts +5 -3
  101. package/server/harness/codex/client.ts +13 -21
  102. package/server/harness/codex/index.ts +18 -0
  103. package/server/harness/codex/session.ts +6 -14
  104. package/server/harness/codex/thread-list.ts +74 -0
  105. package/server/harness/fork.ts +12 -0
  106. package/server/harness/openclaw/adapter.ts +3 -3
  107. package/server/harness/openclaw/session.ts +2 -30
  108. package/server/harness/session-title.ts +12 -3
  109. package/server/harness/types.ts +8 -3
  110. package/server/moi-scaffold.ts +2 -1
  111. package/server/pending-views.ts +164 -0
  112. package/server/registry.ts +14 -4
  113. package/server/selected-session.ts +91 -44
  114. package/server/service.ts +16 -2
  115. package/server/session-archive.ts +32 -0
  116. package/server/session-config.ts +16 -111
  117. package/server/session-lifecycle.ts +17 -0
  118. package/server/session-store.ts +127 -0
  119. package/server/status.ts +3 -1
  120. package/server/tabs.ts +7 -10
  121. package/server/view-sessions.ts +267 -0
  122. package/server/views.ts +30 -41
  123. package/server/web.ts +47 -45
  124. package/server/workspace-env.ts +27 -0
  125. package/server/workspace-init.ts +6 -2
  126. package/workspace/.claude/skills/moi-workspace/SKILL.md +49 -20
  127. package/workspace/.claude/skills/moi-workspace/references/COLLAB.md +2 -5
  128. package/client/features/views/ViewBuilder.tsx +0 -239
  129. package/client/features/views/useViewBuilderActions.ts +0 -103
  130. package/client/features/views/useViewBuilderDrafts.ts +0 -68
  131. package/dist/chunk-2jncyq65.js +0 -1
  132. package/dist/chunk-e2q5ken7.js +0 -68
  133. package/dist/chunk-h2kj1ysj.js +0 -1
  134. package/dist/chunk-nzwgm8vc.css +0 -1
  135. package/dist/chunk-ph0h6h86.js +0 -1
  136. package/dist/chunk-ryg9z3kn.js +0 -10
  137. package/dist/chunk-tpn177bt.js +0 -2
  138. package/lib/view-builder-directives.ts +0 -16
  139. package/server/chat-selection.ts +0 -22
  140. package/server/view-builders.ts +0 -453
@@ -8,10 +8,12 @@ import type {
8
8
  } from '@/lib/types'
9
9
  import { uploadChatFile } from './composer/attachments/uploads'
10
10
  import { attachmentPart } from '@/lib/moi-attachments'
11
+ import { composerDraftKey } from '@/lib/session-drafts'
11
12
  import type { QueryClient } from '@tanstack/react-query'
12
13
 
13
14
  import { workspaceKeys } from '@/client/api/workspace-keys'
14
15
  import { attachmentKey, liveStore } from '@/client/features/chat/chat-store'
16
+ import { useUiStore } from '@/client/store/ui'
15
17
  import type { StagedAttachment } from '@/client/features/chat/composer/attachments/types'
16
18
  import { resolveSelectedModel } from '@/client/features/chat/composer/model-order'
17
19
  import type { MoiUserMessageOptions } from '@/client/features/workspace/moi-context'
@@ -161,6 +163,7 @@ export function startOptimisticTurn({
161
163
  }
162
164
 
163
165
  type StartOptimisticSessionInput = {
166
+ tabId?: SessionInfo['tabId']
164
167
  queryClient: QueryClient
165
168
  workspaceId: string
166
169
  sessionId: string
@@ -169,6 +172,7 @@ type StartOptimisticSessionInput = {
169
172
  }
170
173
 
171
174
  export function startOptimisticSession({
175
+ tabId,
172
176
  queryClient,
173
177
  workspaceId,
174
178
  sessionId,
@@ -178,7 +182,7 @@ export function startOptimisticSession({
178
182
  const summary = formatChatTitle(text, filenames)
179
183
  if (!summary) return
180
184
  queryClient.setQueryData<SessionInfo[]>(workspaceKeys.sessions(workspaceId), current => [
181
- { sessionId, summary, lastModified: Date.now() },
185
+ { sessionId, summary, lastModified: Date.now(), ...(tabId ? { tabId } : {}) },
182
186
  ...(current ?? []).filter(session => session.sessionId !== sessionId)
183
187
  ])
184
188
  }
@@ -221,3 +225,31 @@ export function resolveChatRunOptions(
221
225
  stream
222
226
  }
223
227
  }
228
+
229
+ export function moveChatDraft(workspaceId: string, from: string, to: string) {
230
+ liveStore.getState().renameSession(workspaceId, from, to)
231
+ useUiStore
232
+ .getState()
233
+ .moveComposerDraft(composerDraftKey(workspaceId, from), composerDraftKey(workspaceId, to))
234
+ }
235
+
236
+ export function prepareOptimisticSend(
237
+ input: Omit<StartOptimisticTurnInput, 'parts'> & { text: string },
238
+ ready: readonly StagedAttachment[],
239
+ prepared = prepareDraftAttachments(ready)
240
+ ) {
241
+ const parts: Part[] = [...prepared.parts]
242
+ if (input.text) parts.push({ type: 'text', text: input.text })
243
+ return {
244
+ attachments: prepared.attachments,
245
+ optimisticId: startOptimisticTurn({ ...input, parts })
246
+ }
247
+ }
248
+
249
+ export function finishComposerSend(workspaceId: string, sent: readonly StagedAttachment[]) {
250
+ // Local IDs survive native session renames. Remove only this send's snapshot,
251
+ // preserving files staged while an HTTP submission was in flight.
252
+ for (const attachment of sent)
253
+ liveStore.getState().removeAttachment(workspaceId, attachment.localId)
254
+ useUiStore.getState().markMessageSentFromMoi(workspaceId)
255
+ }
@@ -247,6 +247,16 @@ export const liveStore = createStore<LiveStore>()(set => ({
247
247
  set(s => {
248
248
  const fromKey = attachmentKey(workspaceId, from)
249
249
  const toKey = key(workspaceId, to)
250
+ if (fromKey === toKey) return s
251
+ if (
252
+ !(fromKey in s.activity) &&
253
+ !(fromKey in s.errors) &&
254
+ !(fromKey in s.attachments) &&
255
+ !Object.values(s.previews).some(
256
+ preview => preview.workspaceId === workspaceId && preview.sessionId === from
257
+ )
258
+ )
259
+ return s
250
260
  const activity = { ...s.activity }
251
261
  const errors = { ...s.errors }
252
262
  if (fromKey in activity) {
@@ -1,7 +1,10 @@
1
+ import { toast } from '@/client/components/ui/toast'
1
2
  import { TextAttachmentChip } from './attachments/TextAttachmentChip'
2
3
  import { DrawingAttachmentChip } from './attachments/DrawingAttachmentChip'
3
4
  import { FileAttachmentChip } from './attachments/FileAttachmentChip'
4
- import { type RefObject, useRef, useState } from 'react'
5
+ import { type RefObject, useEffect, useRef, useState } from 'react'
6
+ import { draftSessionId, composerDraftKey } from '@/lib/session-drafts'
7
+ import { useCurrentTabId } from '../sessions/useSelectedSession'
5
8
 
6
9
  import { IconPaperclip, IconPlayerStopFilled, IconScribble } from '@tabler/icons-react'
7
10
 
@@ -32,15 +35,6 @@ export type ComposerAnnotationControls = {
32
35
  onRemove: (localId: string) => void
33
36
  }
34
37
 
35
- type ChatComposerDraft = {
36
- // The UI-store key the composer subscribes to for live text; `initialValue`
37
- // is the builder's server-saved requirements, used until a local draft
38
- // exists.
39
- id: string
40
- initialValue: string
41
- onChange: (value: string) => void
42
- }
43
-
44
38
  type ChatComposerProps = {
45
39
  composerRef: RefObject<HTMLTextAreaElement | null>
46
40
  onSend: (text: string) => void | Promise<void>
@@ -49,16 +43,14 @@ type ChatComposerProps = {
49
43
  sessionId: string | null
50
44
  modelSessionId: string | null
51
45
  availability: AgentAvailability
46
+ chatReady: boolean
52
47
  annotation?: ComposerAnnotationControls
53
48
  onRemoveDrawing?: (localId: string) => void
54
49
  allowFiles?: boolean
55
50
  placeholder?: string
56
- draft?: ChatComposerDraft
57
51
  }
58
52
 
59
- // Draft text is persisted per workspace (or per view builder, when the
60
- // composer is fronting one), while attachments remain ephemeral and follow the
61
- // selected chat. Both stores are subscribed here so a keystroke or upload
53
+ // Draft text is persisted per chat or fresh tab, while attachments remain ephemeral. Both stores are subscribed here so a keystroke or upload
62
54
  // re-renders only the composer.
63
55
  export function ChatComposer({
64
56
  composerRef,
@@ -68,17 +60,20 @@ export function ChatComposer({
68
60
  sessionId,
69
61
  modelSessionId,
70
62
  availability,
63
+ chatReady,
71
64
  annotation,
72
65
  onRemoveDrawing,
73
66
  allowFiles = true,
74
- placeholder,
75
- draft
67
+ placeholder
76
68
  }: ChatComposerProps) {
77
69
  const fileRef = useRef<HTMLInputElement>(null)
78
70
  const workspaceId = useWorkspaceId()
79
- const workspaceDraft = useUiStore(s => s.composerDrafts[workspaceId] ?? '')
80
- const builderDraft = useUiStore(s => (draft ? (s.viewBuilderDrafts ?? {})[draft.id] : undefined))
81
- const value = draft ? (builderDraft ?? draft.initialValue) : workspaceDraft
71
+ const tabId = useCurrentTabId()
72
+ const draftKey = composerDraftKey(workspaceId, sessionId ?? draftSessionId(tabId))
73
+ const value = useUiStore(s => s.composerDrafts[draftKey] ?? '')
74
+ useEffect(() => {
75
+ if (tabId === 'overview') useUiStore.getState().moveComposerDraft(workspaceId, draftKey)
76
+ }, [tabId, workspaceId, draftKey])
82
77
  const valueRef = useLatestRef(value)
83
78
  const attachments = useLive(s => s.attachments[attachmentKey(workspaceId, sessionId)] ?? EMPTY)
84
79
  const [dragOver, setDragOver] = useState(false)
@@ -90,12 +85,11 @@ export function ChatComposer({
90
85
  a => a.kind === 'text' || a.status === 'ready' || a.status === 'draft'
91
86
  )
92
87
  const hasContent = value.trim().length > 0 || hasSendable
93
- const canSend = canSubmitComposerAction(hasContent, uploading, availability)
88
+ const canSend = chatReady && canSubmitComposerAction(hasContent, uploading, availability)
94
89
 
95
90
  const onChange = (next: string) => {
96
91
  valueRef.current = next
97
- if (draft) draft.onChange(next)
98
- else useUiStore.getState().setComposerDraft(workspaceId, next)
92
+ useUiStore.getState().setComposerDraft(draftKey, next)
99
93
  }
100
94
 
101
95
  const addFiles = (files: File[]) => {
@@ -121,10 +115,13 @@ export function ChatComposer({
121
115
  try {
122
116
  await annotation?.finish()
123
117
  await onSend(valueRef.current)
124
- if (!draft) {
125
- valueRef.current = ''
126
- useUiStore.getState().setComposerDraft(workspaceId, '')
127
- }
118
+ valueRef.current = ''
119
+ useUiStore.getState().setComposerDraft(draftKey, null)
120
+ } catch (error) {
121
+ toast.add({
122
+ title: error instanceof Error ? error.message : 'Couldn’t send message',
123
+ type: 'error'
124
+ })
128
125
  } finally {
129
126
  sendingRef.current = false
130
127
  }
@@ -275,7 +272,7 @@ export function ChatComposer({
275
272
  <ComposerSubmitButton
276
273
  label="Send message"
277
274
  hasContent={hasContent}
278
- busy={uploading}
275
+ busy={uploading || !chatReady}
279
276
  availability={availability}
280
277
  />
281
278
  )}
@@ -4,7 +4,7 @@ import { AnimatePresence, motion } from 'motion/react'
4
4
 
5
5
  import { IconBolt, IconBoltFilled } from '@tabler/icons-react'
6
6
 
7
- import { useSaveSessionConfig, useSessionConfig } from '../sessions/api'
7
+ import { useSaveSessionConfig, useSession } from '../sessions/api'
8
8
  import { useWorkspaceAgent } from '@/client/features/workspace/api'
9
9
  import {
10
10
  groupModels,
@@ -279,7 +279,7 @@ type ModelPickerProps = {
279
279
  // Model selector for composer surfaces. The workspace's available models come
280
280
  // from `/api/workspaces/:id/agent`; effort options follow the selected model.
281
281
  // A session id targets that chat's stored config. Null targets the workspace
282
- // defaults that seed new chats such as the view builder.
282
+ // defaults that seed new chats such as the pending view.
283
283
  export const ModelPicker = memo(function ModelPicker({ sessionId }: ModelPickerProps) {
284
284
  const { workspaceId, layout, setLayout } = useWorkspaceLayoutCtx()
285
285
  const { data } = useWorkspaceAgent(workspaceId)
@@ -295,7 +295,7 @@ export const ModelPicker = memo(function ModelPicker({ sessionId }: ModelPickerP
295
295
  )
296
296
  : []
297
297
 
298
- const sessionConfig = useSessionConfig(workspaceId, sessionId).data
298
+ const sessionConfig = useSession(workspaceId, sessionId).data?.config
299
299
  const saveSessionConfig = useSaveSessionConfig(workspaceId)
300
300
 
301
301
  const selectedModel = (sessionId ? sessionConfig?.model : undefined) ?? layout.selectedModel
@@ -16,7 +16,7 @@ type WorkspaceComposerStateOptions = {
16
16
 
17
17
  type WorkspaceComposerState = {
18
18
  composerBanner?: ComposerBanner
19
- builderComposerBanner?: ComposerBanner
19
+ viewDraftComposerBanner?: ComposerBanner
20
20
  agentAvailability: AgentAvailability
21
21
  }
22
22
 
@@ -68,10 +68,10 @@ export function useWorkspaceComposerState(
68
68
  chatError: chatErrorBanner,
69
69
  skillUpdate
70
70
  })
71
- const builderComposerBanner = resolveComposerBanner({
71
+ const viewDraftComposerBanner = resolveComposerBanner({
72
72
  agentUnavailable: agentUnavailableBanner,
73
73
  skillUpdate
74
74
  })
75
75
 
76
- return { agentAvailability, composerBanner, builderComposerBanner }
76
+ return { agentAvailability, composerBanner, viewDraftComposerBanner }
77
77
  }
@@ -5,13 +5,14 @@ import { getScratchExecutor } from '@/client/features/scratchpad/scratch-executo
5
5
  import { liveStore } from '@/client/features/chat/chat-store'
6
6
  import { bufferSessionEvent } from '@/client/features/chat/sessions/session-view'
7
7
  import { renameSelectedSessionInCache } from '@/client/features/chat/sessions/useSelectedSession'
8
+ import { applyArchivedSession } from '@/client/features/chat/sessions/api'
8
9
  import { applyEvent } from '@/lib/format'
9
10
  import type {
10
11
  ClientMessage,
11
12
  PreviewFrame,
12
13
  ScratchOp,
13
14
  SessionActivity,
14
- SessionConfig,
15
+ SessionRecord,
15
16
  SessionInfo,
16
17
  StreamEvent,
17
18
  ViewState
@@ -88,12 +89,12 @@ export function reduceChatFrame(data: Record<string, unknown>, context: ChatFram
88
89
  queryClient?.removeQueries({ queryKey: workspaceKeys.events(workspaceId, from) })
89
90
  }
90
91
 
91
- const previousConfig = queryClient?.getQueryData<SessionConfig>(
92
- workspaceKeys.sessionConfig(workspaceId, from)
92
+ const previousSession = queryClient?.getQueryData<SessionRecord>(
93
+ workspaceKeys.session(workspaceId, from)
93
94
  )
94
- if (previousConfig !== undefined) {
95
- queryClient?.setQueryData(workspaceKeys.sessionConfig(workspaceId, to), previousConfig)
96
- queryClient?.removeQueries({ queryKey: workspaceKeys.sessionConfig(workspaceId, from) })
95
+ if (previousSession !== undefined) {
96
+ queryClient?.setQueryData(workspaceKeys.session(workspaceId, to), previousSession)
97
+ queryClient?.removeQueries({ queryKey: workspaceKeys.session(workspaceId, from) })
97
98
  }
98
99
  if (!cachedSession) {
99
100
  queryClient?.invalidateQueries({ queryKey: sessionsKey })
@@ -101,11 +102,17 @@ export function reduceChatFrame(data: Record<string, unknown>, context: ChatFram
101
102
  queryClient?.invalidateQueries({ queryKey: workspaceKeys.preview(workspaceId) })
102
103
  return
103
104
  }
104
- if (data.type === 'sessions_changed') {
105
+ if (data.type === 'sessions_changed' || data.type === 'session_archived') {
105
106
  const workspaceId = data.workspaceId as string
107
+ if (queryClient && data.type === 'session_archived' && typeof data.sessionId === 'string')
108
+ applyArchivedSession(queryClient, workspaceId, data.sessionId)
106
109
  const sessionsKey = workspaceKeys.sessions(workspaceId)
107
110
  queryClient?.invalidateQueries({ queryKey: sessionsKey })
108
111
  queryClient?.invalidateQueries({ queryKey: workspaceKeys.preview(workspaceId) })
112
+ if (typeof data.sessionId === 'string')
113
+ queryClient?.invalidateQueries({
114
+ queryKey: workspaceKeys.session(workspaceId, data.sessionId)
115
+ })
109
116
  return
110
117
  }
111
118
  if (data.type === 'workspace:switch') {
@@ -4,7 +4,6 @@ import {
4
4
  IconArticle,
5
5
  IconFileSearch,
6
6
  IconLayout2,
7
- IconMessages,
8
7
  IconPiano,
9
8
  IconSketching,
10
9
  IconUmbrella2,
@@ -19,7 +18,7 @@ import {
19
18
  type ChatPromptBubble as ChatPrompt
20
19
  } from '@/client/features/chat/messages/ChatPromptBubbles'
21
20
  import { cn } from '@/client/lib/cn'
22
- import type { AgentTheme } from '@/lib/types'
21
+ import type { AgentTheme, WorkspaceTabId } from '@/lib/types'
23
22
 
24
23
  const ONBOARDING_HANDOFF_DIRECTIVE =
25
24
  'Keep the final reply brief and user-facing. Do not include file or storage links, file paths, or bundle, test, and runtime-log summaries.'
@@ -83,24 +82,31 @@ export const WORKSPACE_ANALYSIS_PROMPT = {
83
82
  icon: IconFileSearch
84
83
  } satisfies ChatPrompt
85
84
 
86
- export type ChatEmptyStateKind = 'view-builder' | 'welcome' | 'explore-workspace' | 'empty'
87
- export type WelcomeDestination = 'agent' | 'overview' | 'views' | 'scratchpad'
85
+ export type ChatEmptyStateKind =
86
+ | 'view-draft'
87
+ | 'welcome'
88
+ | 'explore-workspace'
89
+ | 'overview-empty'
90
+ | 'tab-empty'
91
+ export type WelcomeDestination = 'overview' | 'views' | 'scratchpad'
88
92
 
89
93
  type ResolveChatEmptyStateOptions = {
90
- isViewBuilderDraft: boolean
94
+ tabId: WorkspaceTabId
95
+ isViewDraft: boolean
91
96
  hasSentMessageFromMoi: boolean
92
97
  isWorkspacePendingAnalysis: boolean
93
98
  }
94
99
 
95
100
  export function resolveChatEmptyState({
96
- isViewBuilderDraft,
101
+ tabId,
102
+ isViewDraft,
97
103
  hasSentMessageFromMoi,
98
104
  isWorkspacePendingAnalysis
99
105
  }: ResolveChatEmptyStateOptions): ChatEmptyStateKind {
100
- if (isViewBuilderDraft) return 'view-builder'
106
+ if (isViewDraft) return 'view-draft'
101
107
  if (!hasSentMessageFromMoi) return 'welcome'
102
108
  if (isWorkspacePendingAnalysis) return 'explore-workspace'
103
- return 'empty'
109
+ return tabId === 'overview' ? 'overview-empty' : 'tab-empty'
104
110
  }
105
111
 
106
112
  type ChatEmptyStateProps = {
@@ -121,8 +127,8 @@ export function ChatEmptyState({
121
127
  onNavigate
122
128
  }: ChatEmptyStateProps) {
123
129
  switch (kind) {
124
- case 'view-builder':
125
- return <ViewBuilderState agent={agent} />
130
+ case 'view-draft':
131
+ return <ViewDraftState agent={agent} />
126
132
  case 'welcome':
127
133
  return (
128
134
  <WelcomeState
@@ -137,8 +143,10 @@ export function ChatEmptyState({
137
143
  return (
138
144
  <ExploreWorkspaceState agent={agent} disabled={disabled} onSelectPrompt={onSelectPrompt} />
139
145
  )
140
- case 'empty':
141
- return <EmptyState agent={agent} />
146
+ case 'overview-empty':
147
+ return <OverviewEmptyState agent={agent} />
148
+ case 'tab-empty':
149
+ return <TabEmptyState agent={agent} />
142
150
  }
143
151
  }
144
152
 
@@ -162,7 +170,7 @@ type AgentStateProps = {
162
170
  agent: AgentTheme
163
171
  }
164
172
 
165
- function ViewBuilderState({ agent }: AgentStateProps) {
173
+ function ViewDraftState({ agent }: AgentStateProps) {
166
174
  return (
167
175
  <EmptyStateFrame agent={agent} className="text-center text-muted-foreground">
168
176
  <p className="mx-auto max-w-xs px-8 text-sm">
@@ -199,11 +207,7 @@ function WelcomeState({
199
207
  needs.
200
208
  </p>
201
209
  <p>
202
- Ask the{' '}
203
- <WelcomeTerm Icon={IconMessages} destination="agent" onNavigate={onNavigate}>
204
- Agent
205
- </WelcomeTerm>{' '}
206
- to build widgets on the{' '}
210
+ Ask the agent to build widgets on the{' '}
207
211
  <WelcomeTerm Icon={IconLayout2} destination="overview" onNavigate={onNavigate}>
208
212
  Overview
209
213
  </WelcomeTerm>{' '}
@@ -251,7 +255,7 @@ function ExploreWorkspaceState({ agent, disabled = false, onSelectPrompt }: Prom
251
255
  )
252
256
  }
253
257
 
254
- function EmptyState({ agent }: AgentStateProps) {
258
+ function OverviewEmptyState({ agent }: AgentStateProps) {
255
259
  return (
256
260
  <EmptyStateFrame agent={agent} className="text-center text-muted-foreground">
257
261
  <p className="mx-auto max-w-sm px-8 text-sm">
@@ -261,6 +265,16 @@ function EmptyState({ agent }: AgentStateProps) {
261
265
  )
262
266
  }
263
267
 
268
+ function TabEmptyState({ agent }: AgentStateProps) {
269
+ return (
270
+ <EmptyStateFrame agent={agent} className="text-center text-muted-foreground">
271
+ <p className="mx-auto max-w-sm px-8 text-sm">
272
+ Chat with your agent and manage the view from here
273
+ </p>
274
+ </EmptyStateFrame>
275
+ )
276
+ }
277
+
264
278
  type WelcomeTermProps = {
265
279
  children: string
266
280
  destination: WelcomeDestination
@@ -6,7 +6,7 @@ import rehypeHighlight from 'rehype-highlight'
6
6
  import remarkGfm from 'remark-gfm'
7
7
 
8
8
  import { useWorkspaceId } from '@/client/features/workspace/WorkspaceContext'
9
- import { resolveUrl, workspacePath } from '@/lib/navigation'
9
+ import { resolveUrl } from '@/lib/navigation'
10
10
  import { cn } from '@/client/lib/cn'
11
11
 
12
12
  const remarkPlugins = [remarkGfm]
@@ -64,8 +64,8 @@ export function MarkdownContent({ size = 'sm', content }: MarkdownContentProps)
64
64
  if (node.tagName === 'a' && key === 'href' && url.startsWith('moi:')) {
65
65
  try {
66
66
  return resolveUrl(url, {
67
- apiBase: `/api/workspaces/${encodeURIComponent(workspaceId)}`,
68
- workspacePath: workspacePath(workspaceId, base)
67
+ workspaceId,
68
+ base
69
69
  })
70
70
  } catch {
71
71
  return ''
@@ -0,0 +1,14 @@
1
+ import type { SessionRecord, ViewState } from '@/lib/types'
2
+
3
+ export function visibleForkHistory(view: ViewState, session?: SessionRecord): ViewState {
4
+ if (!session?.forkedFromSessionId || !session.forkedThroughMessageId) return view
5
+ const cutoff = session.forkedThroughMessageId
6
+ const index = view.turns.findIndex(turn => turn.id === cutoff)
7
+ if (index < 0) return view
8
+ const forkedNoticeIds = new Set(session.forkedNoticeIds)
9
+ return {
10
+ ...view,
11
+ turns: view.turns.slice(index + 1),
12
+ notices: view.notices.filter(notice => !forkedNoticeIds.has(notice.id))
13
+ }
14
+ }