moi-computer 0.8.1-next.0 → 0.9.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.
- package/client/assets/hermes.png +0 -0
- package/client/components/shared/IconGhost.tsx +15 -18
- package/client/components/ui/button.tsx +2 -2
- package/client/components/ui/hover-card.tsx +1 -1
- package/client/components/ui/popover.tsx +3 -1
- package/client/features/chat/ChatEmptyState.tsx +25 -7
- package/client/features/chat/ChatPanel.tsx +70 -28
- package/client/features/chat/ChatPopup.tsx +3 -2
- package/client/features/chat/ChatPromptBubbles.tsx +1 -1
- package/client/features/chat/MarkdownContent.tsx +1 -1
- package/client/features/chat/attachment-staging.ts +153 -0
- package/client/features/chat/chat-send.ts +55 -0
- package/client/features/chat/chat-store.ts +32 -8
- package/client/features/chat/composer/ChatComposer.tsx +190 -77
- package/client/features/chat/{ModelPicker.tsx → composer/ModelPicker.tsx} +29 -25
- package/client/features/chat/composer/banners/ComposerBanner.tsx +1 -1
- package/client/features/chat/composer/banners/WorkspaceAgentAvailabilityBanner.tsx +4 -13
- package/client/features/chat/{model-order.ts → composer/model-order.ts} +16 -0
- package/client/features/chat/composer/useWorkspaceComposerState.tsx +9 -4
- package/client/features/chat/tool-group/format/claude.ts +48 -0
- package/client/features/chat/tool-group/format/codex.ts +126 -0
- package/client/features/chat/tool-group/format/hermes.ts +68 -0
- package/client/features/chat/tool-group/format/index.ts +34 -0
- package/client/features/chat/tool-group/format/mcp.ts +64 -0
- package/client/features/chat/tool-group/format/openclaw.ts +116 -0
- package/client/features/chat/tool-group/format/shared.ts +49 -0
- package/client/features/chat/useChat.ts +5 -10
- package/client/features/dev/ChatStatesPage.tsx +40 -2
- package/client/features/drawings/DrawingLayer.tsx +49 -0
- package/client/features/drawings/DrawingToolbar.tsx +95 -0
- package/client/features/drawings/annotation-availability.ts +10 -0
- package/client/features/drawings/capture-element.ts +45 -0
- package/client/features/drawings/useChatAnnotation.ts +222 -0
- package/client/features/drawings/useDrawingLayer.ts +758 -0
- package/client/features/drawings/useViewBuilderSketch.ts +151 -0
- package/client/features/home/workspace-presentation.tsx +6 -2
- package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +12 -6
- package/client/features/scratchpad/ScratchpadControls.tsx +19 -5
- package/client/features/views/ViewBuilder.tsx +224 -0
- package/client/features/views/api.ts +1 -0
- package/client/features/views/useViewBuilderActions.ts +24 -3
- package/client/features/views/useViewBuilderDrafts.ts +66 -0
- package/client/features/widgets/Widgets.tsx +23 -39
- package/client/features/workspace/CustomizePanel.tsx +1 -1
- package/client/features/workspace/WorkspaceScreen.tsx +157 -57
- package/client/features/workspace/WorkspaceTabs.tsx +3 -3
- package/client/features/workspace/useFitsSplitLayout.ts +14 -8
- package/client/index.css +8 -0
- package/client/store/ui.ts +19 -0
- package/client/theme.css +33 -8
- package/dist/chunk-3becmq75.js +81 -0
- package/dist/{chunk-kkj86722.js → chunk-6w6j9g4b.js} +78 -78
- package/dist/{chunk-xeyxk7ep.js → chunk-8ew39cvq.js} +4 -4
- package/dist/chunk-c8gtrjwp.js +1 -0
- package/dist/{chunk-2vaafjp4.js → chunk-pp62fnxh.js} +1 -1
- package/dist/{chunk-35fq49qa.js → chunk-sxc24vfp.js} +1 -1
- package/dist/{chunk-xzx7c9hq.js → chunk-v964b5g7.js} +1 -1
- package/dist/chunk-zx33ts9d.css +1 -0
- package/dist/hermes-pznd63x9.png +0 -0
- package/dist/index.html +1 -1
- package/lib/format.ts +21 -7
- package/lib/themes.ts +8 -8
- package/lib/types.ts +8 -1
- package/lib/workspace-types.ts +2 -1
- package/package.json +6 -4
- package/server/api.ts +21 -2
- package/server/bundler/build-applet.ts +35 -44
- package/server/cli-env.ts +2 -2
- package/server/cli.ts +227 -56
- package/server/constants.ts +8 -0
- package/server/control-client.ts +124 -0
- package/server/control.ts +2 -2
- package/server/harness/README.md +74 -23
- package/server/harness/acp/adapter.ts +220 -0
- package/server/harness/acp/archived.ts +88 -0
- package/server/harness/acp/client.ts +328 -0
- package/server/harness/acp/discovery.ts +130 -0
- package/server/harness/acp/run-durations.ts +68 -0
- package/server/harness/acp/session.ts +788 -0
- package/server/harness/acp/wire.ts +132 -0
- package/server/harness/executable.ts +15 -1
- package/server/harness/hermes/NOTES.md +815 -0
- package/server/harness/hermes/discovery.ts +155 -0
- package/server/harness/hermes/index.ts +155 -0
- package/server/harness/hermes/models.ts +79 -0
- package/server/harness/openclaw/NOTES.md +196 -94
- package/server/harness/openclaw/adapter.ts +28 -55
- package/server/harness/openclaw/compat.ts +4 -8
- package/server/harness/openclaw/session.ts +257 -238
- package/server/harness/openclaw/strip.ts +10 -34
- package/server/harness/openclaw/thinking.ts +5 -53
- package/server/harness/registry.ts +3 -1
- package/server/service.ts +2 -2
- package/server/view-builders.ts +4 -2
- package/server/workspace-import.ts +30 -1
- package/workspace/.claude/skills/moi-workspace/SKILL.md +6 -6
- package/client/features/chat/tool-group/format.ts +0 -359
- package/client/features/views/ViewBuilderTab.tsx +0 -152
- package/dist/chunk-gny990qx.css +0 -1
- package/dist/chunk-gt7n06ef.js +0 -1
- package/dist/chunk-n7pga5x3.js +0 -80
- /package/workspace/.claude/skills/moi-workspace/{DESIGN.md → references/DESIGN.md} +0 -0
- /package/workspace/.claude/skills/moi-workspace/{SCRATCHPAD.md → references/SCRATCHPAD.md} +0 -0
|
Binary file
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Ref } from 'react'
|
|
2
2
|
|
|
3
3
|
import { motion, useReducedMotion } from 'motion/react'
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import type { IconProps } from '@tabler/icons-react'
|
|
6
6
|
|
|
7
7
|
import { cn } from '@/client/lib/cn'
|
|
8
8
|
|
|
9
9
|
type IconGhostProps = IconProps & {
|
|
10
10
|
animated?: boolean
|
|
11
|
+
ref?: Ref<SVGSVGElement>
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
type Point = {
|
|
@@ -76,19 +77,17 @@ function bodyPathAt(progress: number): string {
|
|
|
76
77
|
|
|
77
78
|
const animatedBodyPaths = Array.from({ length: 17 }, (_, index) => bodyPathAt(index / 16))
|
|
78
79
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
ref
|
|
91
|
-
) {
|
|
80
|
+
function IconGhost({
|
|
81
|
+
animated = false,
|
|
82
|
+
color = 'currentColor',
|
|
83
|
+
size = 24,
|
|
84
|
+
stroke = 2,
|
|
85
|
+
title,
|
|
86
|
+
className,
|
|
87
|
+
children,
|
|
88
|
+
ref,
|
|
89
|
+
...props
|
|
90
|
+
}: IconGhostProps) {
|
|
92
91
|
const prefersReducedMotion = useReducedMotion()
|
|
93
92
|
const shouldAnimate = animated && !prefersReducedMotion
|
|
94
93
|
|
|
@@ -123,8 +122,6 @@ const IconGhost = forwardRef<SVGSVGElement, IconGhostProps>(function IconGhost(
|
|
|
123
122
|
{children}
|
|
124
123
|
</svg>
|
|
125
124
|
)
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
IconGhost.displayName = TablerIconGhost.displayName
|
|
125
|
+
}
|
|
129
126
|
|
|
130
127
|
export { IconGhost }
|
|
@@ -9,9 +9,9 @@ const buttonVariants = cva(
|
|
|
9
9
|
variants: {
|
|
10
10
|
variant: {
|
|
11
11
|
default:
|
|
12
|
-
'bg-primary text-primary-foreground hover:bg-primary/90 disabled:bg-accent disabled:text-muted-foreground disabled:opacity-100',
|
|
12
|
+
'bg-primary text-primary-foreground inset-shadow-[0_0_8px_color-mix(in_oklab,var(--color-white)_20%,transparent)] hover:bg-primary/90 disabled:bg-accent disabled:text-muted-foreground disabled:opacity-100 disabled:shadow-none',
|
|
13
13
|
secondary:
|
|
14
|
-
'bg-accent text-foreground hover:bg-[color-mix(
|
|
14
|
+
'bg-accent text-foreground hover:bg-[color-mix(var(--accent),var(--foreground)_3%)] hover:text-accent-foreground',
|
|
15
15
|
outline: 'bg-background shadow-xs hover:text-accent-foreground hover:shadow-sm',
|
|
16
16
|
ghost: 'hover:bg-accent hover:text-accent-foreground',
|
|
17
17
|
destructive:
|
|
@@ -15,7 +15,7 @@ function HoverCardContent({
|
|
|
15
15
|
side = 'bottom',
|
|
16
16
|
sideOffset = 4,
|
|
17
17
|
align = 'center',
|
|
18
|
-
alignOffset =
|
|
18
|
+
alignOffset = 0,
|
|
19
19
|
...props
|
|
20
20
|
}: PreviewCardPrimitive.Popup.Props &
|
|
21
21
|
Pick<PreviewCardPrimitive.Positioner.Props, 'align' | 'alignOffset' | 'side' | 'sideOffset'>) {
|
|
@@ -15,7 +15,7 @@ function PopoverTrigger({ ...props }: PopoverPrimitive.Trigger.Props) {
|
|
|
15
15
|
type PopoverContentProps = PopoverPrimitive.Popup.Props &
|
|
16
16
|
Pick<
|
|
17
17
|
PopoverPrimitive.Positioner.Props,
|
|
18
|
-
'align' | 'alignOffset' | 'disableAnchorTracking' | 'side' | 'sideOffset'
|
|
18
|
+
'align' | 'alignOffset' | 'disableAnchorTracking' | 'positionMethod' | 'side' | 'sideOffset'
|
|
19
19
|
> &
|
|
20
20
|
Pick<PopoverPrimitive.Portal.Props, 'keepMounted' | 'container'>
|
|
21
21
|
|
|
@@ -24,6 +24,7 @@ function PopoverContent({
|
|
|
24
24
|
align = 'center',
|
|
25
25
|
alignOffset = 0,
|
|
26
26
|
disableAnchorTracking = false,
|
|
27
|
+
positionMethod = 'absolute',
|
|
27
28
|
side = 'bottom',
|
|
28
29
|
sideOffset = 4,
|
|
29
30
|
keepMounted = false,
|
|
@@ -36,6 +37,7 @@ function PopoverContent({
|
|
|
36
37
|
align={align}
|
|
37
38
|
alignOffset={alignOffset}
|
|
38
39
|
disableAnchorTracking={disableAnchorTracking}
|
|
40
|
+
positionMethod={positionMethod}
|
|
39
41
|
side={side}
|
|
40
42
|
sideOffset={sideOffset}
|
|
41
43
|
className="isolate z-50"
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
IconLayout2,
|
|
7
7
|
IconPiano,
|
|
8
8
|
IconSketching,
|
|
9
|
+
IconTableSpark,
|
|
9
10
|
IconUmbrella2,
|
|
10
11
|
type TablerIcon
|
|
11
12
|
} from '@tabler/icons-react'
|
|
@@ -79,17 +80,20 @@ export const WORKSPACE_ANALYSIS_PROMPT = {
|
|
|
79
80
|
icon: IconFileSearch
|
|
80
81
|
} satisfies ChatPrompt
|
|
81
82
|
|
|
82
|
-
export type ChatEmptyStateKind = 'chat-welcome' | 'workspace-welcome' | 'empty'
|
|
83
|
+
export type ChatEmptyStateKind = 'view-builder' | 'chat-welcome' | 'workspace-welcome' | 'empty'
|
|
83
84
|
|
|
84
85
|
type ResolveChatEmptyStateOptions = {
|
|
86
|
+
isViewBuilderDraft: boolean
|
|
85
87
|
hasSentMessageFromMoi: boolean
|
|
86
88
|
isWorkspacePendingAnalysis: boolean
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
export function resolveChatEmptyState({
|
|
92
|
+
isViewBuilderDraft,
|
|
90
93
|
hasSentMessageFromMoi,
|
|
91
94
|
isWorkspacePendingAnalysis
|
|
92
95
|
}: ResolveChatEmptyStateOptions): ChatEmptyStateKind {
|
|
96
|
+
if (isViewBuilderDraft) return 'view-builder'
|
|
93
97
|
if (!hasSentMessageFromMoi) return 'chat-welcome'
|
|
94
98
|
if (isWorkspacePendingAnalysis) return 'workspace-welcome'
|
|
95
99
|
return 'empty'
|
|
@@ -104,13 +108,27 @@ type ChatEmptyStateProps = {
|
|
|
104
108
|
}
|
|
105
109
|
|
|
106
110
|
export function ChatEmptyState({ kind, disabled = false, onSelectPrompt }: ChatEmptyStateProps) {
|
|
107
|
-
|
|
108
|
-
|
|
111
|
+
switch (kind) {
|
|
112
|
+
case 'view-builder':
|
|
113
|
+
return <ViewBuilderChatEmptyState />
|
|
114
|
+
case 'chat-welcome':
|
|
115
|
+
return <ChatWelcome disabled={disabled} onSelectPrompt={onSelectPrompt} />
|
|
116
|
+
case 'workspace-welcome':
|
|
117
|
+
return <ChatWorkspaceWelcome disabled={disabled} onSelectPrompt={onSelectPrompt} />
|
|
118
|
+
case 'empty':
|
|
119
|
+
return <EmptyState />
|
|
109
120
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function ViewBuilderChatEmptyState() {
|
|
124
|
+
return (
|
|
125
|
+
<div className={cn(EMPTY_STATE_STYLES, 'gap-2 text-center text-muted-foreground')}>
|
|
126
|
+
<IconTableSpark size={56} stroke={0.5} />
|
|
127
|
+
<p className="mx-auto max-w-xs px-8 text-sm">
|
|
128
|
+
Describe the content, data, and key actions you need in the view
|
|
129
|
+
</p>
|
|
130
|
+
</div>
|
|
131
|
+
)
|
|
114
132
|
}
|
|
115
133
|
|
|
116
134
|
type WelcomeProps = {
|
|
@@ -17,7 +17,7 @@ import { useWorkspaceId } from '@/client/features/workspace/WorkspaceContext'
|
|
|
17
17
|
import type { SystemNotice, Turn, ViewState } from '@/lib/types'
|
|
18
18
|
|
|
19
19
|
import type { ComposerBanner } from './composer/banners/ComposerBanner'
|
|
20
|
-
import { ChatComposer } from './composer/ChatComposer'
|
|
20
|
+
import { ChatComposer, type ComposerAnnotationControls } from './composer/ChatComposer'
|
|
21
21
|
import { ChatEmptyState, resolveChatEmptyState } from './ChatEmptyState'
|
|
22
22
|
import { ChatSelector } from './ChatSelector'
|
|
23
23
|
import { ThinkingIndicator, TurnView } from './TurnView'
|
|
@@ -26,6 +26,18 @@ import { Tooltip, TooltipContent, TooltipTrigger } from '@/client/components/ui/
|
|
|
26
26
|
import { cn } from '@/client/lib/cn'
|
|
27
27
|
import { useUiStore } from '@/client/store/ui'
|
|
28
28
|
|
|
29
|
+
export type ViewBuilderChatDraft = {
|
|
30
|
+
sessionId: string
|
|
31
|
+
builderId: string
|
|
32
|
+
// Server-saved requirements the composer falls back to; the live draft text
|
|
33
|
+
// is subscribed from the UI store by builder id inside ChatComposer, so
|
|
34
|
+
// typing never re-renders this panel or the screen hosting it.
|
|
35
|
+
initialValue: string
|
|
36
|
+
onChange: (value: string) => void
|
|
37
|
+
onRemoveDrawing: (localId: string) => void
|
|
38
|
+
onSubmit: (value: string) => Promise<void>
|
|
39
|
+
}
|
|
40
|
+
|
|
29
41
|
type ChatPanelProps = {
|
|
30
42
|
active?: boolean
|
|
31
43
|
focusRequest?: number
|
|
@@ -42,13 +54,18 @@ type ChatPanelProps = {
|
|
|
42
54
|
processing: boolean
|
|
43
55
|
composerBanner?: ComposerBanner
|
|
44
56
|
composerAvailability: ComposerAvailability
|
|
57
|
+
annotation?: ComposerAnnotationControls
|
|
45
58
|
send: (text: string, options?: ChatSendOptions) => void
|
|
46
59
|
stop: () => void
|
|
47
60
|
onSelectSession: (sessionId: string | null) => void
|
|
48
61
|
// Chat on a separate tab doesn't have a close button
|
|
49
62
|
onClose?: () => void
|
|
63
|
+
builderDraft?: ViewBuilderChatDraft
|
|
50
64
|
}
|
|
51
65
|
|
|
66
|
+
const EMPTY_TURNS: Turn[] = []
|
|
67
|
+
const EMPTY_NOTICES: SystemNotice[] = []
|
|
68
|
+
|
|
52
69
|
export function ChatPanel({
|
|
53
70
|
active = true,
|
|
54
71
|
focusRequest = 0,
|
|
@@ -60,21 +77,25 @@ export function ChatPanel({
|
|
|
60
77
|
processing,
|
|
61
78
|
composerBanner,
|
|
62
79
|
composerAvailability,
|
|
80
|
+
annotation,
|
|
63
81
|
send,
|
|
64
82
|
stop,
|
|
65
83
|
onSelectSession,
|
|
66
|
-
onClose
|
|
84
|
+
onClose,
|
|
85
|
+
builderDraft
|
|
67
86
|
}: ChatPanelProps) {
|
|
68
87
|
const workspaceId = useWorkspaceId()
|
|
69
88
|
const composerRef = useRef<HTMLTextAreaElement>(null)
|
|
70
89
|
const scrollRef = useRef<HTMLDivElement>(null)
|
|
71
|
-
const
|
|
90
|
+
const effectiveSessionId = builderDraft?.sessionId ?? sessionId ?? null
|
|
91
|
+
const modelSessionId = builderDraft ? null : (sessionId ?? null)
|
|
92
|
+
const turns = builderDraft ? EMPTY_TURNS : view.turns
|
|
72
93
|
const hasSentMessageFromMoi = useUiStore(state => state.hasSentMessageFromMoi)
|
|
73
94
|
const isWorkspacePendingAnalysis = useUiStore(state =>
|
|
74
95
|
(state.workspaceIdsPendingAnalysis ?? []).includes(workspaceId)
|
|
75
96
|
)
|
|
76
97
|
const attachmentsUploading = useLive(state =>
|
|
77
|
-
(state.attachments[attachmentKey(workspaceId,
|
|
98
|
+
(state.attachments[attachmentKey(workspaceId, effectiveSessionId)] ?? []).some(
|
|
78
99
|
attachment => attachment.status === 'uploading'
|
|
79
100
|
)
|
|
80
101
|
)
|
|
@@ -85,30 +106,32 @@ export function ChatPanel({
|
|
|
85
106
|
// inter-turn gap between every tool call. See `dev/turn-spacing.md`.
|
|
86
107
|
// The live preview turn is appended before grouping, so a thinking-only
|
|
87
108
|
// preview merges into the trailing tool group exactly like its finalized form.
|
|
109
|
+
const effectivePreviewTurn = builderDraft ? null : previewTurn
|
|
110
|
+
const notices = builderDraft ? EMPTY_NOTICES : view.notices
|
|
88
111
|
const groupedTurns = useMemo(
|
|
89
|
-
() => groupTurns(
|
|
90
|
-
[turns,
|
|
112
|
+
() => groupTurns(effectivePreviewTurn ? [...turns, effectivePreviewTurn] : turns),
|
|
113
|
+
[turns, effectivePreviewTurn]
|
|
91
114
|
)
|
|
92
115
|
// Grouped turns plus the renderable notices (compaction, model changes)
|
|
93
116
|
// woven in at the moment they happened. Interleaving runs AFTER grouping so
|
|
94
117
|
// a notice never splits a tool-only run apart.
|
|
95
|
-
const timeline = useMemo(
|
|
96
|
-
() => interleaveNotices(groupedTurns, view.notices),
|
|
97
|
-
[groupedTurns, view.notices]
|
|
98
|
-
)
|
|
118
|
+
const timeline = useMemo(() => interleaveNotices(groupedTurns, notices), [groupedTurns, notices])
|
|
99
119
|
const lastTurnId = groupedTurns.length > 0 ? groupedTurns[groupedTurns.length - 1].id : null
|
|
100
|
-
const
|
|
120
|
+
const effectiveProcessing = builderDraft ? false : processing
|
|
121
|
+
const showEmptyState =
|
|
122
|
+
!!builderDraft || (chatLoaded && timeline.length === 0 && !effectiveProcessing)
|
|
101
123
|
const emptyStateKind = resolveChatEmptyState({
|
|
124
|
+
isViewBuilderDraft: !!builderDraft,
|
|
102
125
|
hasSentMessageFromMoi,
|
|
103
126
|
isWorkspacePendingAnalysis
|
|
104
127
|
})
|
|
105
128
|
|
|
106
129
|
// Stick to the bottom while pinned; respect scroll-up; jump on session switch.
|
|
107
|
-
const { atBottom, scrollToBottom, scrollToTop } = useStickToBottom(scrollRef,
|
|
130
|
+
const { atBottom, scrollToBottom, scrollToTop } = useStickToBottom(scrollRef, effectiveSessionId)
|
|
108
131
|
|
|
109
132
|
useLayoutEffect(() => {
|
|
110
|
-
if (
|
|
111
|
-
}, [
|
|
133
|
+
if (showEmptyState && emptyStateKind !== 'empty') scrollToTop()
|
|
134
|
+
}, [showEmptyState, emptyStateKind, scrollToTop])
|
|
112
135
|
|
|
113
136
|
// The active chat surface owns initial focus. A monotonically increasing
|
|
114
137
|
// request also refocuses an already-visible composer after intent actions.
|
|
@@ -119,11 +142,12 @@ export function ChatPanel({
|
|
|
119
142
|
// Sending always returns the user to the bottom, even if they'd scrolled up —
|
|
120
143
|
// they expect to see their message and the reply.
|
|
121
144
|
const handleSend = useCallback(
|
|
122
|
-
(text: string, options?: ChatSendOptions) => {
|
|
123
|
-
|
|
145
|
+
async (text: string, options?: ChatSendOptions) => {
|
|
146
|
+
if (builderDraft) await builderDraft.onSubmit(text)
|
|
147
|
+
else send(text, options)
|
|
124
148
|
scrollToBottom()
|
|
125
149
|
},
|
|
126
|
-
[send, scrollToBottom]
|
|
150
|
+
[builderDraft, send, scrollToBottom]
|
|
127
151
|
)
|
|
128
152
|
|
|
129
153
|
const handlePromptSelect = useCallback(
|
|
@@ -137,7 +161,11 @@ export function ChatPanel({
|
|
|
137
161
|
return (
|
|
138
162
|
<div className="flex min-h-0 flex-1 flex-col pt-2 pb-3">
|
|
139
163
|
<header className="mx-auto flex w-full max-w-[calc(var(--chat-max-container)+40px)] items-center justify-between pr-2 pb-2 pl-2">
|
|
140
|
-
|
|
164
|
+
{builderDraft ? (
|
|
165
|
+
<div className="flex h-7 items-center px-2.5 text-sm font-medium">Build a new view</div>
|
|
166
|
+
) : (
|
|
167
|
+
<ChatSelector selectedSessionId={sessionId ?? null} onSelectSession={onSelectSession} />
|
|
168
|
+
)}
|
|
141
169
|
{onClose && docked && (
|
|
142
170
|
<Tooltip>
|
|
143
171
|
<TooltipTrigger
|
|
@@ -150,7 +178,7 @@ export function ChatPanel({
|
|
|
150
178
|
<TooltipContent>Undock agent</TooltipContent>
|
|
151
179
|
</Tooltip>
|
|
152
180
|
)}
|
|
153
|
-
{onClose && !docked && (
|
|
181
|
+
{!builderDraft && onClose && !docked && (
|
|
154
182
|
<Button variant="ghost" size="icon-sm" onClick={onClose} aria-label="Close chat">
|
|
155
183
|
<IconX stroke={2} />
|
|
156
184
|
</Button>
|
|
@@ -160,10 +188,10 @@ export function ChatPanel({
|
|
|
160
188
|
<div className="relative flex min-h-0 flex-1 flex-col">
|
|
161
189
|
<div
|
|
162
190
|
ref={scrollRef}
|
|
163
|
-
className="flex scrollbar-thin flex-1 scroll-fade flex-col overflow-y-auto overscroll-contain px-5 pt-4 pb-
|
|
191
|
+
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]"
|
|
164
192
|
>
|
|
165
193
|
<div className="mx-auto flex w-full max-w-(--chat-max-container) flex-1 flex-col items-center gap-6">
|
|
166
|
-
{
|
|
194
|
+
{showEmptyState && (
|
|
167
195
|
<ChatEmptyState
|
|
168
196
|
kind={emptyStateKind}
|
|
169
197
|
disabled={promptDisabled}
|
|
@@ -177,13 +205,13 @@ export function ChatPanel({
|
|
|
177
205
|
<TurnView
|
|
178
206
|
key={item.turn.id}
|
|
179
207
|
turn={item.turn}
|
|
180
|
-
processing={
|
|
208
|
+
processing={effectiveProcessing && item.turn.id === lastTurnId}
|
|
181
209
|
/>
|
|
182
210
|
)
|
|
183
211
|
)}
|
|
184
212
|
{/* Pulsing dots only before the first token — once the preview has
|
|
185
213
|
visible content it renders as a (possibly merged) grouped turn. */}
|
|
186
|
-
{
|
|
214
|
+
{effectiveProcessing && !effectivePreviewTurn && <ThinkingIndicator />}
|
|
187
215
|
</div>
|
|
188
216
|
</div>
|
|
189
217
|
|
|
@@ -207,9 +235,9 @@ export function ChatPanel({
|
|
|
207
235
|
<div
|
|
208
236
|
className={cn(
|
|
209
237
|
'@container flex w-full flex-col transition-[padding]',
|
|
210
|
-
composerBanner && 'gap-2 rounded-t-
|
|
211
|
-
composerBanner?.tone === '
|
|
212
|
-
composerBanner?.tone === '
|
|
238
|
+
composerBanner && 'gap-2 rounded-t-lg rounded-b-2xl p-2',
|
|
239
|
+
composerBanner?.tone === 'default' && 'bg-accent',
|
|
240
|
+
composerBanner?.tone === 'error' && 'bg-destructive/10'
|
|
213
241
|
)}
|
|
214
242
|
>
|
|
215
243
|
{composerBanner?.content}
|
|
@@ -217,9 +245,23 @@ export function ChatPanel({
|
|
|
217
245
|
composerRef={composerRef}
|
|
218
246
|
onSend={handleSend}
|
|
219
247
|
onStop={stop}
|
|
220
|
-
processing={
|
|
221
|
-
sessionId={
|
|
248
|
+
processing={effectiveProcessing}
|
|
249
|
+
sessionId={effectiveSessionId}
|
|
250
|
+
modelSessionId={modelSessionId}
|
|
222
251
|
availability={composerAvailability}
|
|
252
|
+
annotation={builderDraft ? undefined : annotation}
|
|
253
|
+
onRemoveDrawing={builderDraft?.onRemoveDrawing ?? annotation?.onRemove}
|
|
254
|
+
allowFiles={!builderDraft}
|
|
255
|
+
placeholder={builderDraft ? 'Drop in the details' : undefined}
|
|
256
|
+
draft={
|
|
257
|
+
builderDraft
|
|
258
|
+
? {
|
|
259
|
+
id: builderDraft.builderId,
|
|
260
|
+
initialValue: builderDraft.initialValue,
|
|
261
|
+
onChange: builderDraft.onChange
|
|
262
|
+
}
|
|
263
|
+
: undefined
|
|
264
|
+
}
|
|
223
265
|
/>
|
|
224
266
|
</div>
|
|
225
267
|
</div>
|
|
@@ -39,6 +39,8 @@ export function ChatPopup({
|
|
|
39
39
|
onOpenChange={handleOpenChange}
|
|
40
40
|
onOpenChangeComplete={onOpenChangeComplete}
|
|
41
41
|
>
|
|
42
|
+
{/* Floating over a themed workspace — use the card pair so it stays
|
|
43
|
+
legible regardless of the active theme background. */}
|
|
42
44
|
<PopoverTrigger
|
|
43
45
|
render={
|
|
44
46
|
<div className="fixed right-4 bottom-4 sm:right-6 sm:bottom-6">
|
|
@@ -52,8 +54,6 @@ export function ChatPopup({
|
|
|
52
54
|
animate={open ? 'invisible' : 'to'}
|
|
53
55
|
transition={{ type: 'spring', duration: 0.3, delay: 0.2, bounce: 0 }}
|
|
54
56
|
>
|
|
55
|
-
{/* Floating over a themed workspace — use the card pair so it
|
|
56
|
-
stays legible regardless of the active theme background. */}
|
|
57
57
|
<Button
|
|
58
58
|
variant="outline"
|
|
59
59
|
size="icon-lg"
|
|
@@ -67,6 +67,7 @@ export function ChatPopup({
|
|
|
67
67
|
}
|
|
68
68
|
/>
|
|
69
69
|
<PopoverContent
|
|
70
|
+
positionMethod="fixed"
|
|
70
71
|
side="top"
|
|
71
72
|
sideOffset={-48}
|
|
72
73
|
align="end"
|
|
@@ -25,7 +25,7 @@ const components = {
|
|
|
25
25
|
},
|
|
26
26
|
pre({ children }: ComponentProps<'pre'>) {
|
|
27
27
|
return (
|
|
28
|
-
<div className="not-prose my-2 rounded-lg border border-border bg-
|
|
28
|
+
<div className="not-prose my-2 rounded-lg border border-border bg-accent px-3 py-2.5">
|
|
29
29
|
<pre className="overflow-auto font-mono text-xs leading-relaxed whitespace-pre text-foreground [&>code]:rounded-none [&>code]:bg-transparent [&>code]:p-0">
|
|
30
30
|
{children}
|
|
31
31
|
</pre>
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type { WorkspaceTabId } from '@/lib/types'
|
|
2
|
+
|
|
3
|
+
import { attachmentKey, type ChatAttachment, type DrawingPurpose, liveStore } from './chat-store'
|
|
4
|
+
import { uploadFiles } from './uploads'
|
|
5
|
+
|
|
6
|
+
type ComposerTarget = {
|
|
7
|
+
workspaceId: string
|
|
8
|
+
sessionId: string | null
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function stageComposerFiles(
|
|
12
|
+
{ workspaceId, sessionId }: ComposerTarget,
|
|
13
|
+
files: File[]
|
|
14
|
+
): void {
|
|
15
|
+
if (files.length === 0) return
|
|
16
|
+
|
|
17
|
+
const items: ChatAttachment[] = files.map(file => ({
|
|
18
|
+
kind: 'file',
|
|
19
|
+
localId: crypto.randomUUID(),
|
|
20
|
+
name: file.name || 'file',
|
|
21
|
+
mediaType: file.type || 'application/octet-stream',
|
|
22
|
+
previewUrl: file.type.startsWith('image/') ? URL.createObjectURL(file) : undefined,
|
|
23
|
+
status: 'uploading'
|
|
24
|
+
}))
|
|
25
|
+
liveStore.getState().addAttachments(workspaceId, sessionId, items)
|
|
26
|
+
|
|
27
|
+
items.forEach((item, index) => {
|
|
28
|
+
uploadFiles(workspaceId, [files[index]])
|
|
29
|
+
.then(([upload]) => {
|
|
30
|
+
liveStore.getState().updateAttachment(workspaceId, sessionId, item.localId, {
|
|
31
|
+
status: 'ready',
|
|
32
|
+
upload,
|
|
33
|
+
mediaType: upload.mediaType
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
.catch((error: unknown) => {
|
|
37
|
+
liveStore.getState().updateAttachment(workspaceId, sessionId, item.localId, {
|
|
38
|
+
status: 'error',
|
|
39
|
+
error: error instanceof Error ? error.message : 'Upload failed'
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
type StageDrawingDraftInput = ComposerTarget & {
|
|
46
|
+
localId: string
|
|
47
|
+
purpose: DrawingPurpose
|
|
48
|
+
sourceTab: WorkspaceTabId
|
|
49
|
+
blob: Blob
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Local-only staging while the user is still drawing: the chip shows the
|
|
53
|
+
// latest composite as its preview, but nothing is uploaded until the drawing
|
|
54
|
+
// session ends (stageDrawing).
|
|
55
|
+
export function stageDrawingDraft({
|
|
56
|
+
workspaceId,
|
|
57
|
+
sessionId,
|
|
58
|
+
localId,
|
|
59
|
+
purpose,
|
|
60
|
+
sourceTab,
|
|
61
|
+
blob
|
|
62
|
+
}: StageDrawingDraftInput): void {
|
|
63
|
+
const label = purpose === 'sketch' ? 'Sketch' : 'Annotation'
|
|
64
|
+
const previewUrl = URL.createObjectURL(blob)
|
|
65
|
+
const store = liveStore.getState()
|
|
66
|
+
const existing = store.attachments[attachmentKey(workspaceId, sessionId)]?.some(
|
|
67
|
+
attachment => attachment.localId === localId
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
if (existing) {
|
|
71
|
+
store.updateAttachment(workspaceId, sessionId, localId, {
|
|
72
|
+
previewUrl,
|
|
73
|
+
status: 'draft',
|
|
74
|
+
upload: undefined,
|
|
75
|
+
error: undefined
|
|
76
|
+
})
|
|
77
|
+
} else {
|
|
78
|
+
store.addAttachments(workspaceId, sessionId, [
|
|
79
|
+
{
|
|
80
|
+
kind: 'drawing',
|
|
81
|
+
purpose,
|
|
82
|
+
localId,
|
|
83
|
+
sourceTab,
|
|
84
|
+
name: `${label}.png`,
|
|
85
|
+
mediaType: 'image/png',
|
|
86
|
+
previewUrl,
|
|
87
|
+
status: 'draft'
|
|
88
|
+
}
|
|
89
|
+
])
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
type StageDrawingInput = StageDrawingDraftInput & {
|
|
94
|
+
isCurrent: () => boolean
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Upload a drawing once its editing session ends (finish, send, or an
|
|
98
|
+
// implicit cancel that keeps the attachment). `isCurrent` guards the result:
|
|
99
|
+
// a stale upload must not resurrect an attachment the user has removed.
|
|
100
|
+
export async function stageDrawing({
|
|
101
|
+
workspaceId,
|
|
102
|
+
sessionId,
|
|
103
|
+
localId,
|
|
104
|
+
purpose,
|
|
105
|
+
sourceTab,
|
|
106
|
+
blob,
|
|
107
|
+
isCurrent
|
|
108
|
+
}: StageDrawingInput): Promise<void> {
|
|
109
|
+
const label = purpose === 'sketch' ? 'Sketch' : 'Annotation'
|
|
110
|
+
const previewUrl = URL.createObjectURL(blob)
|
|
111
|
+
const store = liveStore.getState()
|
|
112
|
+
const existing = store.attachments[attachmentKey(workspaceId, sessionId)]?.some(
|
|
113
|
+
attachment => attachment.localId === localId
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
if (existing) {
|
|
117
|
+
store.updateAttachment(workspaceId, sessionId, localId, {
|
|
118
|
+
previewUrl,
|
|
119
|
+
status: 'uploading',
|
|
120
|
+
upload: undefined,
|
|
121
|
+
error: undefined
|
|
122
|
+
})
|
|
123
|
+
} else {
|
|
124
|
+
store.addAttachments(workspaceId, sessionId, [
|
|
125
|
+
{
|
|
126
|
+
kind: 'drawing',
|
|
127
|
+
purpose,
|
|
128
|
+
localId,
|
|
129
|
+
sourceTab,
|
|
130
|
+
name: `${label}.png`,
|
|
131
|
+
mediaType: 'image/png',
|
|
132
|
+
previewUrl,
|
|
133
|
+
status: 'uploading'
|
|
134
|
+
}
|
|
135
|
+
])
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
try {
|
|
139
|
+
const [upload] = await uploadFiles(workspaceId, [
|
|
140
|
+
new File([blob], `${label}.png`, { type: 'image/png' })
|
|
141
|
+
])
|
|
142
|
+
if (!isCurrent()) return
|
|
143
|
+
liveStore.getState().updateAttachment(workspaceId, sessionId, localId, {
|
|
144
|
+
status: 'ready',
|
|
145
|
+
upload,
|
|
146
|
+
mediaType: upload.mediaType,
|
|
147
|
+
error: undefined
|
|
148
|
+
})
|
|
149
|
+
} catch {
|
|
150
|
+
if (!isCurrent()) return
|
|
151
|
+
liveStore.getState().removeAttachment(workspaceId, sessionId, localId)
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -32,6 +32,61 @@ export function attachmentsForSend(
|
|
|
32
32
|
return pending.filter(a => a.status === 'ready' && a.upload)
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
export function attachmentPartsForOptimisticTurn(attachments: readonly ChatAttachment[]): Part[] {
|
|
36
|
+
return attachments.map(attachment => {
|
|
37
|
+
if (attachment.upload?.kind === 'image' && attachment.previewUrl) {
|
|
38
|
+
return {
|
|
39
|
+
type: 'file',
|
|
40
|
+
mediaType: attachment.mediaType,
|
|
41
|
+
url: attachment.previewUrl,
|
|
42
|
+
filename: attachment.name
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
type: 'file',
|
|
47
|
+
mediaType: attachment.mediaType,
|
|
48
|
+
url: '',
|
|
49
|
+
filename: attachment.name
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function withAttachmentDirectives(
|
|
55
|
+
options: ChatSendOptions | undefined,
|
|
56
|
+
attachments: readonly ChatAttachment[]
|
|
57
|
+
): ChatSendOptions | undefined {
|
|
58
|
+
if (!ownsComposerAttachments(options)) return options
|
|
59
|
+
const annotations: string[] = []
|
|
60
|
+
const sketches: string[] = []
|
|
61
|
+
let imagePosition = 0
|
|
62
|
+
for (const attachment of attachments) {
|
|
63
|
+
if (attachment.upload?.kind !== 'image') continue
|
|
64
|
+
imagePosition += 1
|
|
65
|
+
if (attachment.kind === 'drawing' && attachment.purpose === 'annotation') {
|
|
66
|
+
annotations.push(`${imagePosition}. ${JSON.stringify(attachment.sourceTab)}`)
|
|
67
|
+
}
|
|
68
|
+
if (attachment.kind === 'drawing' && attachment.purpose === 'sketch') {
|
|
69
|
+
sketches.push(`${imagePosition}. ${JSON.stringify(attachment.sourceTab)}`)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (annotations.length === 0 && sketches.length === 0) return options
|
|
73
|
+
|
|
74
|
+
const directives = [...(options?.directives ?? [])]
|
|
75
|
+
if (annotations.length > 0) {
|
|
76
|
+
directives.push(`Annotation attachment sources in attachment order: ${annotations.join('; ')}.`)
|
|
77
|
+
}
|
|
78
|
+
if (sketches.length > 0) {
|
|
79
|
+
directives.push(
|
|
80
|
+
`Sketch attachment sources in attachment order: ${sketches.join('; ')}. Each sketch shows the intended layout of a new view.`
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
...options,
|
|
86
|
+
directives
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
35
90
|
type StartOptimisticTurnInput = {
|
|
36
91
|
queryClient: QueryClient
|
|
37
92
|
workspaceId: string
|