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
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  THE UI FOR YOUR AI
7
7
  ```
8
8
 
9
- [![npm version](https://img.shields.io/npm/v/moi-computer?label=npm&labelColor=555&color=E85D2A)](https://www.npmjs.com/package/moi-computer)  [![Discord](https://img.shields.io/badge/Discord-Join%20server-5865F2?logo=discord&logoColor=white&labelColor=555)](https://discord.gg/nydjacJrT)
9
+ [![npm version](https://img.shields.io/npm/v/moi-computer?label=npm&labelColor=555&color=E85D2A)](https://www.npmjs.com/package/moi-computer)  [![Discord](https://img.shields.io/badge/Discord-Join%20server-5865F2?logo=discord&logoColor=white&labelColor=555)](https://discord.gg/9kj3y9Pfk)
10
10
 
11
11
  An extendable visual workspace where your AI agents build their own UI.
12
12
  See [moi.computer](https://moi.computer) for what it is and how it works.
package/client/AGENTS.md CHANGED
@@ -7,8 +7,8 @@ Before editing host-app UI, read `../DESIGN.md` and the relevant rules in `../.a
7
7
  ## Entities
8
8
 
9
9
  - **Workspace** — Top-level container. Has a name and contains widgets and a chat. One workspace is active at a time.
10
- - **Widget** — A configurable card inside the workspace's main area. Displayed in a grid. When there are no widgets, the chat fills the whole panel.
11
- - **Chat** — The agent conversation. Contains a scrollable message list and an input. Always lives in the panel. Two modes: sidebar (a bounded pane beside the widgets, or the full panel when there are no widgets) and floating (popover). Floating only applies when there are widgets and they need the room.
10
+ - **Widget** — A configurable card inside Overview. Displayed in a grid.
11
+ - **Chat** — The agent conversation. Contains a scrollable message list and an input. Available on Overview, Scratchpad, and views through a docked sidebar or floating popup.
12
12
 
13
13
  ## Conventions
14
14
 
@@ -1,4 +1,4 @@
1
1
  export const appUiKeys = {
2
2
  all: ['app-ui'] as const,
3
- selectedSession: (workspaceId: string) => ['app-ui', 'selected-session', workspaceId] as const
3
+ sessionSelection: (workspaceId: string) => ['app-ui', 'session-selection', workspaceId] as const
4
4
  }
@@ -7,11 +7,9 @@ export const workspaceKeys = {
7
7
  widgets: (id: string) => ['workspaces', 'widgets', id] as const,
8
8
  appletThumbnails: (id: string) => ['workspaces', 'applet-thumbnails', id] as const,
9
9
  views: (id: string) => ['workspaces', 'views', id] as const,
10
- viewBuilders: (id: string) => ['workspaces', 'view-builders', id] as const,
11
10
  sessions: (id: string) => ['workspaces', 'sessions', id] as const,
12
11
  events: (id: string, sessionId: string) => ['workspaces', 'events', id, sessionId] as const,
13
- sessionConfig: (id: string, sessionId: string) =>
14
- ['workspaces', 'sessionConfig', id, sessionId] as const,
12
+ session: (id: string, sessionId: string) => ['workspaces', 'session', id, sessionId] as const,
15
13
  mcp: (id: string) => ['workspaces', 'mcp', id] as const,
16
14
  agent: (id: string) => ['workspaces', 'agent', id] as const,
17
15
  skills: (id: string) => ['workspaces', 'skills', id] as const,
@@ -13,7 +13,7 @@ import {
13
13
  useWorkspaceLayoutCtx
14
14
  } from '@/client/features/workspace/WorkspaceLayoutContext'
15
15
  import { WorkspaceScreen } from '@/client/features/workspace/WorkspaceScreen'
16
- import { useViewBuilders, useViews } from '@/client/features/views/api'
16
+ import { useViews } from '@/client/features/views/api'
17
17
  import { useWidgets } from '@/client/features/overview/api'
18
18
  import { useWorkspaceEvent } from '@/client/runtime/useWorkspaceEvents'
19
19
 
@@ -44,7 +44,6 @@ function WorkspaceContent({ id }: WorkspaceRouteProps) {
44
44
  const { isLoading: layoutLoading } = useWorkspaceLayoutCtx()
45
45
  const widgets = useWidgets(id)
46
46
  const views = useViews(id)
47
- const builders = useViewBuilders(id)
48
47
  useAppletCacheInvalidation()
49
48
 
50
49
  useWorkspaceEvent(event => {
@@ -62,11 +61,7 @@ function WorkspaceContent({ id }: WorkspaceRouteProps) {
62
61
  })
63
62
 
64
63
  const fresh =
65
- layoutLoading ||
66
- selectedSessionId === undefined ||
67
- widgets.isLoading ||
68
- views.isLoading ||
69
- builders.isLoading
64
+ layoutLoading || selectedSessionId === undefined || widgets.isLoading || views.isLoading
70
65
 
71
66
  return (
72
67
  <SidebarLayout>
@@ -81,7 +76,6 @@ function WorkspaceContent({ id }: WorkspaceRouteProps) {
81
76
  key={collabEnabled ? 'browser-tab' : 'shared'}
82
77
  widgets={widgets.data}
83
78
  views={views.data ?? []}
84
- builders={builders.data ?? []}
85
79
  />
86
80
  )}
87
81
  </SidebarLayout>
@@ -26,6 +26,7 @@ import type {
26
26
  AttachmentInput,
27
27
  AttachmentOrigin
28
28
  } from '@/lib/types'
29
+ import type { AppletContext } from '@/lib/moi-context'
29
30
  import { isWorkspaceAttachmentPath, MAX_UPLOAD_BYTES } from '@/lib/message-attachments'
30
31
  import { useEffect } from 'react'
31
32
 
@@ -36,7 +37,7 @@ import { toast } from '@/client/components/ui/toast'
36
37
  import { createRateLimiter, type RateLimiter } from '@/client/lib/rate-limit'
37
38
  import { useLatestRef } from '@/client/lib/use-latest-ref'
38
39
  import { isParamsRecord } from '@/lib/workspace-tabs'
39
- import { resolveUrl, workspacePath } from '@/lib/navigation'
40
+ import { resolveUrl } from '@/lib/navigation'
40
41
 
41
42
  type HostAppletBridge = SharedAppletBridge & {
42
43
  readonly collab: AppletCollabApi | undefined
@@ -47,12 +48,12 @@ export type AppletIdentity = { kind: AppletKind; name: string }
47
48
 
48
49
  export const appletSource = ({ kind, name }: AppletIdentity): string => `${kind}:${name}`
49
50
 
50
- // A chat message fired from applet UI. `source` is stamped from the identity
51
+ // A chat message fired from applet UI. `applet` is stamped from the identity
51
52
  // the bridge was attached with, so an applet can neither omit it nor claim to
52
53
  // be another applet.
53
54
  export type AppletChatMessage = {
54
55
  message: string
55
- source: string
56
+ applet: AppletContext
56
57
  attachments: (AttachmentInput & AttachmentOrigin)[]
57
58
  }
58
59
 
@@ -126,10 +127,6 @@ function createRuntime(workspaceId: string) {
126
127
  connect(identity: AppletIdentity, base = '') {
127
128
  let alive = true
128
129
  const source = appletSource(identity)
129
- const urlContext = {
130
- apiBase: `/api/workspaces/${encodeURIComponent(workspaceId)}`,
131
- workspacePath: workspacePath(workspaceId, base)
132
- }
133
130
  const bridge: HostAppletBridge = {
134
131
  get collab() {
135
132
  return alive ? appletCollabApi : undefined
@@ -148,17 +145,14 @@ function createRuntime(workspaceId: string) {
148
145
  navigate(url) {
149
146
  if (!alive) return
150
147
  try {
151
- if (typeof url !== 'string') throw new Error('Navigation needs a URL')
152
- resolveUrl(url, urlContext)
153
- emitter.emit('navigate', url)
148
+ emitter.emit('navigate', resolveUrl(url))
154
149
  } catch (error) {
155
150
  drop(identity, `navigate() was dropped: ${errorMessage(error)}`)
156
151
  }
157
152
  },
158
153
  resolveUrl(url) {
159
154
  if (!alive) return ''
160
- if (typeof url !== 'string') throw new Error('A URL is required')
161
- return resolveUrl(url, urlContext)
155
+ return resolveUrl(url, { workspaceId, base })
162
156
  },
163
157
  sendChatMessage(input, legacyContext) {
164
158
  if (!alive) return
@@ -191,7 +185,11 @@ function createRuntime(workspaceId: string) {
191
185
  snapshotAttachmentInput(item, source)
192
186
  )
193
187
  if (!admitChatMessage(identity, source, message)) return
194
- emitter.emit('sendChatMessage', { message, source, attachments })
188
+ emitter.emit('sendChatMessage', {
189
+ message,
190
+ applet: { kind: identity.kind, id: identity.name },
191
+ attachments
192
+ })
195
193
  } catch (error) {
196
194
  const message = errorMessage(error)
197
195
  toast.add({ title: 'Couldn’t send message', description: message, type: 'error' })
@@ -1,6 +1,10 @@
1
1
  import { useCallback, useEffect, useLayoutEffect, useMemo, useRef } from 'react'
2
+ import { useRouter } from 'wouter'
2
3
 
3
- import { IconChevronDown, IconChevronsRight, IconX } from '@tabler/icons-react'
4
+ import { IconArrowBackUp, IconChevronDown, IconChevronsRight, IconX } from '@tabler/icons-react'
5
+ import { draftSessionId } from '@/lib/session-drafts'
6
+ import { resolveUrl } from '@/lib/navigation'
7
+ import { useCurrentTabId } from './sessions/useSelectedSession'
4
8
 
5
9
  import { canSubmitComposerAction, focusComposer } from '@/client/components/shared/Composer'
6
10
  import { AgentBlobatar } from '@/client/components/shared/AgentBlobatar'
@@ -24,6 +28,7 @@ import {
24
28
  resolveChatEmptyState
25
29
  } from './messages/ChatEmptyState'
26
30
  import { ChatSelector } from './sessions/ChatSelector'
31
+ import { useWorkspaceSessions } from './sessions/api'
27
32
  import { TurnView } from './messages/TurnView'
28
33
  import { Button } from '@/client/components/ui/button'
29
34
  import { Tooltip, TooltipContent, TooltipTrigger } from '@/client/components/ui/tooltip'
@@ -31,19 +36,13 @@ import { cn } from '@/client/lib/cn'
31
36
  import type { AgentAvailability } from '@/client/lib/agent-availability'
32
37
  import { useUiStore } from '@/client/store/ui'
33
38
 
34
- export type ViewBuilderChatDraft = {
39
+ export type ViewChatDraft = {
35
40
  sessionId: string
36
- builderId: string
37
- // Server-saved requirements the composer falls back to; the live draft text
38
- // is subscribed from the UI store by builder id inside ChatComposer, so
39
- // typing never re-renders this panel or the screen hosting it.
40
- initialValue: string
41
- onChange: (value: string) => void
42
41
  onRemoveDrawing: (localId: string) => void
43
- onSubmit: (value: string) => Promise<void>
44
42
  }
45
43
 
46
44
  type ChatPanelProps = {
45
+ forkedFromSessionId?: string
47
46
  agent: AgentTheme
48
47
  active?: boolean
49
48
  focusRequest?: number
@@ -55,25 +54,23 @@ type ChatPanelProps = {
55
54
  // into the trailing assistant run so a thinking-only
56
55
  // preview folds into the current tool group. See client/lib/preview-turn.ts.
57
56
  previewTurn?: Turn | null
58
- // Selected session id — used only as the scroll reset key (jump to bottom on
59
- // session switch).
60
57
  sessionId?: string | null
61
58
  processing: boolean
62
59
  composerBanner?: ComposerBanner
63
60
  agentAvailability: AgentAvailability
64
61
  annotation?: ComposerAnnotationControls
65
- send: (text: string, options?: ChatSendOptions) => void
62
+ send: (text: string, options?: ChatSendOptions) => Promise<void>
66
63
  stop: () => void
67
64
  onNavigateFromWelcome: (destination: WelcomeDestination) => void
68
- // Chat on a separate tab doesn't have a close button
69
- onClose?: () => void
70
- builderDraft?: ViewBuilderChatDraft
65
+ onClose: () => void
66
+ viewDraft?: ViewChatDraft
71
67
  }
72
68
 
73
69
  const EMPTY_TURNS: Turn[] = []
74
70
  const EMPTY_NOTICES: SystemNotice[] = []
75
71
 
76
72
  export function ChatPanel({
73
+ forkedFromSessionId,
77
74
  agent,
78
75
  active = true,
79
76
  focusRequest = 0,
@@ -91,14 +88,18 @@ export function ChatPanel({
91
88
  stop,
92
89
  onNavigateFromWelcome,
93
90
  onClose,
94
- builderDraft
91
+ viewDraft
95
92
  }: ChatPanelProps) {
96
93
  const workspaceId = useWorkspaceId()
94
+ const { base } = useRouter()
95
+ const { data: sessions } = useWorkspaceSessions(workspaceId)
96
+ const sourceName = sessions?.find(session => session.sessionId === forkedFromSessionId)?.summary
97
+ const tabId = useCurrentTabId()
97
98
  const composerRef = useRef<HTMLTextAreaElement>(null)
98
99
  const scrollRef = useRef<HTMLDivElement>(null)
99
- const effectiveSessionId = builderDraft?.sessionId ?? sessionId ?? null
100
- const modelSessionId = builderDraft ? null : (sessionId ?? null)
101
- const turns = builderDraft ? EMPTY_TURNS : view.turns
100
+ const effectiveSessionId = viewDraft?.sessionId ?? sessionId ?? draftSessionId(tabId)
101
+ const modelSessionId = viewDraft ? null : (sessionId ?? null)
102
+ const turns = viewDraft ? EMPTY_TURNS : view.turns
102
103
  const hasSentMessageFromMoi = useUiStore(state => state.hasSentMessageFromMoi)
103
104
  const isWorkspacePendingAnalysis = useUiStore(state =>
104
105
  (state.workspaceIdsPendingAnalysis ?? []).includes(workspaceId)
@@ -108,14 +109,16 @@ export function ChatPanel({
108
109
  attachment => attachment.kind !== 'text' && attachment.status === 'uploading'
109
110
  )
110
111
  )
111
- const promptDisabled = !canSubmitComposerAction(true, attachmentsUploading, agentAvailability)
112
+ const chatReady = chatLoaded || !!viewDraft
113
+ const promptDisabled =
114
+ !chatReady || !canSubmitComposerAction(true, attachmentsUploading, agentAvailability)
112
115
  // Visual grouping: fold consecutive tool-only assistant turns into one
113
116
  // synthetic turn so OpenAI Codex–style traces (which serialize one
114
117
  // assistant message per agent step) don't render with the wider
115
118
  // inter-turn gap between every tool call. See `dev/turn-spacing.md`.
116
119
  // Group saved history once, then merge previews into just the trailing run.
117
- const effectivePreviewTurn = builderDraft ? null : previewTurn
118
- const notices = builderDraft ? EMPTY_NOTICES : view.notices
120
+ const effectivePreviewTurn = viewDraft ? null : previewTurn
121
+ const notices = viewDraft ? EMPTY_NOTICES : view.notices
119
122
  const savedGroups = useMemo(() => groupTurns(turns), [turns])
120
123
  const groupedTurns = useMemo(
121
124
  () => appendPreviewTurn(savedGroups, effectivePreviewTurn),
@@ -126,12 +129,14 @@ export function ChatPanel({
126
129
  // a notice never splits a tool-only run apart.
127
130
  const timeline = useMemo(() => interleaveNotices(groupedTurns, notices), [groupedTurns, notices])
128
131
  const lastTurnId = groupedTurns.length > 0 ? groupedTurns[groupedTurns.length - 1].id : null
129
- const effectiveProcessing = builderDraft ? false : processing
132
+ const effectiveProcessing = viewDraft ? false : processing
130
133
  const showEmptyState =
131
- !!builderDraft || (chatLoaded && timeline.length === 0 && !effectiveProcessing)
134
+ !!viewDraft ||
135
+ (!forkedFromSessionId && chatLoaded && timeline.length === 0 && !effectiveProcessing)
132
136
  const showTranscript = chatLoaded && !showEmptyState
133
137
  const emptyStateKind = resolveChatEmptyState({
134
- isViewBuilderDraft: !!builderDraft,
138
+ tabId,
139
+ isViewDraft: !!viewDraft,
135
140
  hasSentMessageFromMoi,
136
141
  isWorkspacePendingAnalysis
137
142
  })
@@ -140,7 +145,8 @@ export function ChatPanel({
140
145
  const { atBottom, scrollToBottom, scrollToTop } = useStickToBottom(scrollRef, effectiveSessionId)
141
146
 
142
147
  useLayoutEffect(() => {
143
- if (showEmptyState && emptyStateKind !== 'empty') scrollToTop()
148
+ if (showEmptyState && emptyStateKind !== 'overview-empty' && emptyStateKind !== 'tab-empty')
149
+ scrollToTop()
144
150
  }, [showEmptyState, emptyStateKind, scrollToTop])
145
151
 
146
152
  // The active chat surface owns initial focus. A monotonically increasing
@@ -153,11 +159,10 @@ export function ChatPanel({
153
159
  // they expect to see their message and the reply.
154
160
  const handleSend = useCallback(
155
161
  async (text: string, options?: ChatSendOptions) => {
156
- if (builderDraft) await builderDraft.onSubmit(text)
157
- else send(text, options)
162
+ await send(text, options)
158
163
  scrollToBottom()
159
164
  },
160
- [builderDraft, send, scrollToBottom]
165
+ [send, scrollToBottom]
161
166
  )
162
167
 
163
168
  const handlePromptSelect = useCallback(
@@ -170,23 +175,23 @@ export function ChatPanel({
170
175
 
171
176
  return (
172
177
  <div className="flex min-h-0 flex-1 flex-col pt-2 pb-3">
173
- <header className="mx-auto flex w-full max-w-[calc(var(--chat-max-container)+40px)] min-w-0 items-center justify-between pr-2 pb-2 pl-2">
174
- <div className="min-w-0 flex-1">
175
- <ChatSelector isViewBuilder={!!builderDraft} />
178
+ <header className="flex w-full min-w-0 items-center justify-between pr-2 pb-2 pl-2">
179
+ <div className="flex h-7 min-w-0 flex-1">
180
+ <ChatSelector className={cn('text-foreground', docked && 'text-muted-foreground')} />
176
181
  </div>
177
- {onClose && docked && (
182
+ {docked && (
178
183
  <Tooltip>
179
184
  <TooltipTrigger
180
185
  render={
181
- <Button variant="ghost" size="icon-sm" onClick={onClose} aria-label="Undock agent">
186
+ <Button variant="ghost" size="icon-sm" onClick={onClose} aria-label="Undock chat">
182
187
  <IconChevronsRight className="size-5! text-muted-foreground" stroke={1.5} />
183
188
  </Button>
184
189
  }
185
190
  />
186
- <TooltipContent>Undock agent</TooltipContent>
191
+ <TooltipContent>Undock chat</TooltipContent>
187
192
  </Tooltip>
188
193
  )}
189
- {!builderDraft && onClose && !docked && (
194
+ {!viewDraft && !docked && (
190
195
  <Button variant="ghost" size="icon-sm" onClick={onClose} aria-label="Close chat">
191
196
  <IconX stroke={2} />
192
197
  </Button>
@@ -199,6 +204,30 @@ export function ChatPanel({
199
204
  className="flex scrollbar-thin flex-1 scroll-fade flex-col overflow-y-auto overscroll-contain px-5 pt-4 pb-8 [--scroll-fade-reveal:8px]"
200
205
  >
201
206
  <div className="mx-auto flex w-full max-w-(--chat-max-container) flex-1 flex-col gap-6">
207
+ {forkedFromSessionId && (
208
+ <a
209
+ href={resolveUrl(`moi:/chats/${encodeURIComponent(forkedFromSessionId)}`, {
210
+ workspaceId,
211
+ base
212
+ })}
213
+ className="block text-sm outline-none focus-visible:ring-3 focus-visible:ring-ring/50"
214
+ >
215
+ <div className="flex items-center gap-3">
216
+ <IconArrowBackUp
217
+ size={20}
218
+ stroke={1.5}
219
+ aria-hidden="true"
220
+ className="shrink-0 text-muted-foreground"
221
+ />
222
+ <div className="flex min-w-0 flex-1 flex-col gap-0.5">
223
+ <span className="text-muted-foreground">Started from another chat</span>
224
+ <span className="truncate font-medium" title={sourceName}>
225
+ {sourceName || 'Another chat'}
226
+ </span>
227
+ </div>
228
+ </div>
229
+ </a>
230
+ )}
202
231
  {showEmptyState && (
203
232
  <ChatEmptyState
204
233
  agent={agent}
@@ -268,19 +297,11 @@ export function ChatPanel({
268
297
  sessionId={effectiveSessionId}
269
298
  modelSessionId={modelSessionId}
270
299
  availability={agentAvailability}
271
- annotation={builderDraft ? undefined : annotation}
272
- onRemoveDrawing={builderDraft?.onRemoveDrawing ?? annotation?.onRemove}
273
- allowFiles={!builderDraft}
274
- placeholder={builderDraft ? 'Drop in the details' : undefined}
275
- draft={
276
- builderDraft
277
- ? {
278
- id: builderDraft.builderId,
279
- initialValue: builderDraft.initialValue,
280
- onChange: builderDraft.onChange
281
- }
282
- : undefined
283
- }
300
+ chatReady={chatReady}
301
+ annotation={viewDraft ? undefined : annotation}
302
+ onRemoveDrawing={viewDraft?.onRemoveDrawing ?? annotation?.onRemove}
303
+ allowFiles={!viewDraft}
304
+ placeholder={viewDraft ? 'Drop in the details' : undefined}
284
305
  />
285
306
  </div>
286
307
  </div>
@@ -1,10 +1,13 @@
1
+ import { useCallback, useRef, useState } from 'react'
1
2
  import type { ComponentProps, ReactNode } from 'react'
2
3
 
3
4
  import { motion } from 'motion/react'
5
+ import { Resizable } from 'react-resizable'
4
6
 
5
7
  import { AgentBlobatar } from '@/client/components/shared/AgentBlobatar'
6
8
  import { Popover, PopoverContent, PopoverTrigger } from '@/client/components/ui/popover'
7
9
  import { cn } from '@/client/lib/cn'
10
+ import { useUiStore } from '@/client/store/ui'
8
11
  import type { AgentTheme } from '@/lib/types'
9
12
 
10
13
  type ChatPopupProps = {
@@ -24,6 +27,42 @@ export function ChatPopup({
24
27
  onOpenChangeComplete,
25
28
  children
26
29
  }: ChatPopupProps) {
30
+ const popupRef = useRef<HTMLDivElement>(null)
31
+ const popupChatWidth = useUiStore(state => state.popupChatWidth)
32
+ const setPopupChatWidth = useUiStore(state => state.setPopupChatWidth)
33
+ const [size, setSize] = useState({ width: popupChatWidth, min: 0, max: popupChatWidth })
34
+
35
+ const setPopupRef = useCallback(
36
+ (popup: HTMLDivElement | null) => {
37
+ popupRef.current = popup
38
+ if (!popup) return
39
+ popup.style.setProperty('--chat-popup-width', `${popupChatWidth}px`)
40
+ // Report the rendered width, including viewport clamping of the saved preference.
41
+ const observer = new ResizeObserver(([entry]) => {
42
+ if (!entry) return
43
+ const { minWidth, maxWidth } = getComputedStyle(popup)
44
+ setSize({
45
+ width: Math.round(entry.contentRect.width),
46
+ min: parseFloat(minWidth),
47
+ max: parseFloat(maxWidth)
48
+ })
49
+ })
50
+ observer.observe(popup)
51
+ return () => {
52
+ observer.disconnect()
53
+ popupRef.current = null
54
+ }
55
+ },
56
+ [popupChatWidth]
57
+ )
58
+
59
+ const resize = (width: number) => {
60
+ if (!popupRef.current) return
61
+ const { minWidth, maxWidth } = getComputedStyle(popupRef.current)
62
+ setPopupChatWidth(
63
+ Math.round(Math.min(parseFloat(maxWidth), Math.max(parseFloat(minWidth), width)))
64
+ )
65
+ }
27
66
  const onClose = () => onOpenChange(false)
28
67
  const handleOpenChange: NonNullable<ComponentProps<typeof Popover>['onOpenChange']> = (
29
68
  nextOpen,
@@ -84,15 +123,49 @@ export function ChatPopup({
84
123
  </div>
85
124
  }
86
125
  />
87
- <PopoverContent
88
- side="top"
89
- sideOffset={({ anchor }) => -anchor.height}
90
- align="end"
91
- className="flex h-[calc(100vh-2rem)] w-[min(440px,calc(100vw-1rem))] flex-col gap-0 rounded-3xl p-0 sm:h-[calc(100vh-8rem)] sm:w-[min(440px,calc(100vw-2rem))] sm:p-1"
92
- keepMounted
126
+ <Resizable
127
+ axis="x"
128
+ width={size.width}
129
+ height={0}
130
+ resizeHandles={['w']}
131
+ minConstraints={[size.min, 0]}
132
+ maxConstraints={[size.max, 0]}
133
+ onResize={(_event, { size }) => setPopupChatWidth(Math.round(size.width))}
134
+ handle={
135
+ <div
136
+ role="separator"
137
+ aria-label="Resize chat popup"
138
+ aria-orientation="vertical"
139
+ aria-valuemin={size.min}
140
+ aria-valuemax={size.max}
141
+ aria-valuenow={size.width}
142
+ aria-valuetext={`${size.width} pixels wide`}
143
+ tabIndex={0}
144
+ className="absolute inset-y-6 -left-1 w-2 cursor-ew-resize touch-none rounded-full outline-none focus-visible:ring-3 focus-visible:ring-ring/50"
145
+ onKeyDown={event => {
146
+ const width = popupRef.current?.offsetWidth ?? popupChatWidth
147
+ const step = event.shiftKey ? 32 : 16
148
+ if (event.key === 'ArrowLeft') resize(width + step)
149
+ else if (event.key === 'ArrowRight') resize(width - step)
150
+ else if (event.key === 'Home') resize(-Infinity)
151
+ else if (event.key === 'End') resize(Infinity)
152
+ else return
153
+ event.preventDefault()
154
+ }}
155
+ />
156
+ }
93
157
  >
94
- {children(onClose)}
95
- </PopoverContent>
158
+ <PopoverContent
159
+ ref={setPopupRef}
160
+ side="top"
161
+ sideOffset={({ anchor }) => -anchor.height}
162
+ align="end"
163
+ className="relative flex h-[calc(100vh-2rem)] w-(--chat-popup-width) max-w-[calc(100vw-1.5rem)] min-w-[min(440px,calc(100vw-1.5rem))] flex-col gap-0 rounded-3xl p-0 transition-[opacity,transform] sm:h-[calc(100vh-8rem)]"
164
+ keepMounted
165
+ >
166
+ {children(onClose)}
167
+ </PopoverContent>
168
+ </Resizable>
96
169
  </Popover>
97
170
  )
98
171
  }
@@ -13,14 +13,19 @@ import { prepareChatAttachments, type ChatSendOptions, type PreparedAttachments
13
13
  import { useLayoutEffect } from 'react'
14
14
  import { useQueryClient, type QueryClient } from '@tanstack/react-query'
15
15
  import { toast } from '@/client/components/ui/toast'
16
- import { selectedSessionKey } from '@/client/features/chat/sessions/useSelectedSession'
16
+ import {
17
+ selectedSessionForTab,
18
+ selectedSessionKey
19
+ } from '@/client/features/chat/sessions/useSelectedSession'
17
20
  import { useCollabEnabled } from '@/client/features/collab'
18
21
  import { useLatestRef } from '@/client/lib/use-latest-ref'
19
- import type { SelectedSessionScope, SelectedSessionState } from '@/lib/types'
22
+ import type { SelectedSessionScope, WorkspaceSessionSelection, WorkspaceTabId } from '@/lib/types'
23
+ import { useCurrentTabId } from './sessions/useSelectedSession'
20
24
  import { useWorkspaceId } from '@/client/features/workspace/WorkspaceContext'
21
25
  import type { AgentAvailability } from '@/client/lib/agent-availability'
22
26
 
23
27
  type UseAppletChatMessageOptions = {
28
+ tabId: WorkspaceTabId
24
29
  sessionId: string | null
25
30
  send: (draft: string, options?: ChatSendOptions) => void
26
31
  // Bring the chat on screen before the run starts. On a view tab in
@@ -57,9 +62,21 @@ export function createAppletMessageHandler(
57
62
  ) {
58
63
  const pending = new Set<() => void>()
59
64
  let disposed = false
60
- const selectedSession = () =>
61
- queryClient.getQueryData<SelectedSessionState>(selectedSessionKey(workspaceId, scope))
62
- ?.sessionId ?? null
65
+ const selectedSession = () => {
66
+ const state = queryClient.getQueryData<WorkspaceSessionSelection>(
67
+ selectedSessionKey(workspaceId, scope)
68
+ )
69
+ const shared = queryClient.getQueryData<WorkspaceSessionSelection>(
70
+ selectedSessionKey(workspaceId)
71
+ )
72
+ return (
73
+ selectedSessionForTab(
74
+ shared,
75
+ getOptions().tabId,
76
+ scope === 'browser-tab' ? state : undefined
77
+ ) ?? null
78
+ )
79
+ }
63
80
 
64
81
  async function handle(event: AppletChatMessage): Promise<void> {
65
82
  if (disposed) return
@@ -67,7 +84,7 @@ export function createAppletMessageHandler(
67
84
  toast.add({ title: 'Couldn’t send message', description: message, type: 'error' })
68
85
  reportAppletError(workspaceId, {
69
86
  source: 'runtime',
70
- message: `sendChatMessage() from ${event.source}: ${message}`
87
+ message: `sendChatMessage() from ${event.applet.kind}:${event.applet.id}: ${message}`
71
88
  })
72
89
  }
73
90
  const blocked = appletSendBlockedReason(getOptions().agentAvailability)
@@ -77,6 +94,7 @@ export function createAppletMessageHandler(
77
94
  }
78
95
 
79
96
  const sessionId = selectedSession()
97
+ const tabId = getOptions().tabId
80
98
  let active = true
81
99
  let loadingToast: string | undefined
82
100
  const finish = () => {
@@ -95,7 +113,7 @@ export function createAppletMessageHandler(
95
113
  })
96
114
  }
97
115
  const unsubscribe = queryClient.getQueryCache().subscribe(() => {
98
- if (selectedSession() !== sessionId) cancel()
116
+ if (selectedSession() !== sessionId || getOptions().tabId !== tabId) cancel()
99
117
  })
100
118
  pending.add(cancel)
101
119
  // A selection change can reach the cache before React has replaced the
@@ -116,7 +134,7 @@ export function createAppletMessageHandler(
116
134
  const options = getOptions()
117
135
  const blocked = appletSendBlockedReason(options.agentAvailability)
118
136
  if (blocked) throw new Error(blocked)
119
- if (options.sessionId !== sessionId) {
137
+ if (options.sessionId !== sessionId || options.tabId !== tabId) {
120
138
  cancel()
121
139
  return
122
140
  }
@@ -130,7 +148,7 @@ export function createAppletMessageHandler(
130
148
  // Stop watching before sending: a new chat gets its first session ID here.
131
149
  finish()
132
150
  try {
133
- getOptions().send(event.message, { applet: { source: event.source }, preparedAttachments })
151
+ getOptions().send(event.message, { applet: event.applet, preparedAttachments })
134
152
  } catch (error) {
135
153
  reportFailure(
136
154
  error instanceof Error ? error.message : 'Something went wrong while sending this message'
@@ -147,11 +165,12 @@ export function createAppletMessageHandler(
147
165
  }
148
166
  }
149
167
 
150
- export function useAppletChatMessage(options: UseAppletChatMessageOptions): void {
168
+ export function useAppletChatMessage(options: Omit<UseAppletChatMessageOptions, 'tabId'>): void {
151
169
  const workspaceId = useWorkspaceId()
152
170
  const queryClient = useQueryClient()
171
+ const tabId = useCurrentTabId()
153
172
  const collabEnabled = useCollabEnabled()
154
- const latest = useLatestRef(options)
173
+ const latest = useLatestRef({ ...options, tabId })
155
174
  useLayoutEffect(() => {
156
175
  const handler = createAppletMessageHandler(
157
176
  workspaceId,
@@ -166,7 +185,7 @@ export function useAppletChatMessage(options: UseAppletChatMessageOptions): void
166
185
  unsubscribe()
167
186
  handler.dispose()
168
187
  }
169
- }, [workspaceId, queryClient, latest, collabEnabled])
188
+ }, [workspaceId, queryClient, latest, tabId, collabEnabled])
170
189
  }
171
190
 
172
191
  export function useAppletChatAttachment(sessionId: string | null, revealChat: () => void): void {