moi-computer 0.9.0 → 0.9.1-next.1
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/api/app-config.ts +51 -0
- package/client/api/workspace-keys.ts +1 -0
- package/client/app/routes/WorkspaceRoute.tsx +4 -2
- 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/applets/api.ts +38 -0
- package/client/features/applets/applet-thumbnail.ts +208 -0
- package/client/features/chat/ChatEmptyState.tsx +30 -10
- package/client/features/chat/ChatPanel.tsx +67 -31
- package/client/features/chat/ChatPopup.tsx +3 -2
- package/client/features/chat/ChatPromptBubbles.tsx +1 -1
- package/client/features/chat/ChatSelector.tsx +29 -10
- package/client/features/chat/MarkdownContent.tsx +3 -3
- 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/drawings/DrawingLayer.tsx +49 -0
- package/client/features/drawings/DrawingToolbar.tsx +95 -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/HomePage.tsx +13 -0
- package/client/features/home/WorkspacePreview.tsx +10 -5
- package/client/features/home/workspace-presentation.tsx +6 -2
- package/client/features/home/workspace-setup/CreateWorkspaceDialog.tsx +9 -0
- package/client/features/home/workspace-setup/InstallMoiDialog.tsx +245 -0
- package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +13 -7
- package/client/features/home/workspace-setup/WorkspaceDialogContent.tsx +1 -1
- package/client/features/scratchpad/ScratchpadControls.tsx +19 -5
- package/client/features/views/ViewBuilder.tsx +238 -0
- package/client/features/views/ViewManager.tsx +18 -2
- 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/WidgetFrame.tsx +1 -1
- package/client/features/widgets/WidgetGrid.tsx +1 -1
- package/client/features/widgets/Widgets.tsx +39 -54
- package/client/features/workspace/CustomizePanel.tsx +30 -9
- package/client/features/workspace/WorkspaceScreen.tsx +158 -64
- package/client/features/workspace/WorkspaceTabs.tsx +3 -3
- package/client/features/workspace/useFitsSplitLayout.ts +14 -8
- package/client/index.css +8 -0
- package/client/index.tsx +6 -1
- package/client/runtime/useWorkspaceEvents.ts +17 -0
- package/client/runtime/workspace-theme.ts +29 -6
- package/client/store/ui.ts +19 -0
- package/client/theme.css +33 -8
- package/dist/chunk-5c19v3zr.js +10 -0
- package/dist/chunk-6wx91x8j.js +1 -0
- package/dist/chunk-8s41nd3g.js +1 -0
- package/dist/{chunk-kkj86722.js → chunk-a7fzp0z0.js} +78 -78
- package/dist/{chunk-2vaafjp4.js → chunk-b959mdkj.js} +1 -1
- package/dist/chunk-cagtq45k.js +1 -0
- package/dist/chunk-cva7jpt4.js +82 -0
- package/dist/chunk-sapvd7he.css +1 -0
- package/dist/{chunk-35fq49qa.js → chunk-zbeq02yc.js} +1 -1
- package/dist/chunk-zbt8emsw.js +2 -0
- package/dist/chunk-zfz3b4xg.js +2 -0
- package/dist/hermes-pznd63x9.png +0 -0
- package/dist/index.html +1 -1
- package/lib/format.ts +1 -1
- package/lib/themes.ts +8 -8
- package/lib/types.ts +68 -42
- package/lib/workspace-types.ts +2 -1
- package/package.json +2 -1
- package/server/api.ts +90 -33
- package/server/app-config.ts +144 -0
- package/server/applets.ts +17 -0
- package/server/cli.ts +235 -14
- package/server/harness/README.md +64 -17
- 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/registry.ts +3 -1
- package/server/layout.ts +40 -45
- package/server/moi-scaffold.ts +37 -1
- package/server/thumbnails.ts +197 -0
- package/server/view-builders.ts +4 -2
- package/server/views.ts +10 -1
- package/server/widgets.ts +4 -18
- package/server/workspace-import.ts +30 -1
- package/workspace/.claude/skills/moi-workspace/SKILL.md +13 -1
- package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +153 -253
- package/client/features/chat/tool-group/format.ts +0 -384
- package/client/features/views/ViewBuilderTab.tsx +0 -152
- package/client/features/widgets/api.ts +0 -47
- package/client/features/widgets/useWidgetThumbnails.ts +0 -107
- package/client/features/widgets/widget-snapshot.ts +0 -71
- package/dist/chunk-3b3rkjet.js +0 -1
- package/dist/chunk-gt7n06ef.js +0 -1
- package/dist/chunk-ty1sqbmn.js +0 -80
- package/dist/chunk-xeyxk7ep.js +0 -10
- package/dist/chunk-yz6wd5vc.css +0 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useSyncExternalStore } from 'react'
|
|
2
|
+
|
|
3
|
+
import type { ClientAppConfig } from '@/lib/types'
|
|
4
|
+
|
|
5
|
+
import { onWorkspaceEventsReconnect } from '@/client/runtime/useWorkspaceEvents'
|
|
6
|
+
|
|
7
|
+
import { requestJson } from './http'
|
|
8
|
+
|
|
9
|
+
// Startup config (GET /api/config): frozen for the server process lifetime,
|
|
10
|
+
// so it is fetched once before the app mounts (see init() in index.tsx) and
|
|
11
|
+
// read synchronously everywhere after that — no query, no loading states.
|
|
12
|
+
// The one thing that can change it is a server restart; the events socket
|
|
13
|
+
// reconnecting is that signal, so the store re-fetches there.
|
|
14
|
+
|
|
15
|
+
const DEFAULTS: ClientAppConfig = {
|
|
16
|
+
cloudDemo: false,
|
|
17
|
+
experiments: [],
|
|
18
|
+
demoInstallUrl: 'https://moi.computer'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let current: ClientAppConfig = DEFAULTS
|
|
22
|
+
const listeners = new Set<() => void>()
|
|
23
|
+
|
|
24
|
+
function subscribe(listener: () => void): () => void {
|
|
25
|
+
listeners.add(listener)
|
|
26
|
+
return () => {
|
|
27
|
+
listeners.delete(listener)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Failures keep the last known value (defaults on the very first fetch):
|
|
32
|
+
// non-demo is the safe presentation, and the server still enforces its gates.
|
|
33
|
+
async function fetchAppConfig(): Promise<void> {
|
|
34
|
+
try {
|
|
35
|
+
current = await requestJson<ClientAppConfig>('/api/config')
|
|
36
|
+
for (const listener of listeners) listener()
|
|
37
|
+
} catch {}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Called once from init() before the app mounts; never rejects, so a config
|
|
41
|
+
// hiccup cannot block the app from starting.
|
|
42
|
+
export async function loadAppConfig(): Promise<void> {
|
|
43
|
+
await fetchAppConfig()
|
|
44
|
+
onWorkspaceEventsReconnect(() => {
|
|
45
|
+
void fetchAppConfig()
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function useAppConfig(): ClientAppConfig {
|
|
50
|
+
return useSyncExternalStore(subscribe, () => current)
|
|
51
|
+
}
|
|
@@ -5,6 +5,7 @@ export const workspaceKeys = {
|
|
|
5
5
|
preview: (id: string) => ['workspaces', 'preview', id] as const,
|
|
6
6
|
layout: (id: string) => ['workspaces', 'layout', id] as const,
|
|
7
7
|
widgets: (id: string) => ['workspaces', 'widgets', id] as const,
|
|
8
|
+
appletThumbnails: (id: string) => ['workspaces', 'applet-thumbnails', id] as const,
|
|
8
9
|
views: (id: string) => ['workspaces', 'views', id] as const,
|
|
9
10
|
viewBuilders: (id: string) => ['workspaces', 'view-builders', id] as const,
|
|
10
11
|
sessions: (id: string) => ['workspaces', 'sessions', id] as const,
|
|
@@ -46,10 +46,12 @@ function WorkspaceLoader({ id }: WorkspaceRouteProps) {
|
|
|
46
46
|
if (event.type === 'theme:updated' || event.type === 'workspace:updated') {
|
|
47
47
|
queryClient.invalidateQueries({ queryKey: workspaceKeys.layout(id) })
|
|
48
48
|
} else if (event.type === 'widget-layout:updated' || event.type === 'widget:updated') {
|
|
49
|
-
// widget:updated too: a rebundle bumps the widget's content
|
|
49
|
+
// widget:updated too: a rebundle bumps the widget's content revision, and
|
|
50
50
|
// the thumbnail invalidation hook reads it off this query.
|
|
51
51
|
queryClient.invalidateQueries({ queryKey: workspaceKeys.widgets(id) })
|
|
52
|
-
} else if (event.type === 'view-layout:updated') {
|
|
52
|
+
} else if (event.type === 'view-layout:updated' || event.type === 'view:updated') {
|
|
53
|
+
// view:updated also bumps the built bundle revision used by thumbnail
|
|
54
|
+
// freshness checks.
|
|
53
55
|
queryClient.invalidateQueries({ queryKey: workspaceKeys.views(id) })
|
|
54
56
|
}
|
|
55
57
|
})
|
|
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"
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
2
|
+
|
|
3
|
+
import { jsonRequest, requestJson, requestVoid } from '@/client/api/http'
|
|
4
|
+
import { WORKSPACE_RESOURCE_OPTIONS } from '@/client/api/query-options'
|
|
5
|
+
import { workspaceKeys } from '@/client/api/workspace-keys'
|
|
6
|
+
import type { AppletThumbnail, AppletThumbnailBatch } from '@/lib/types'
|
|
7
|
+
|
|
8
|
+
// Freshness records only — image bytes stay server-side (`.moi/.cache`) and
|
|
9
|
+
// reach the UI as plain <img> URLs.
|
|
10
|
+
export function useAppletThumbnailRecords(workspaceId: string) {
|
|
11
|
+
return useQuery<AppletThumbnail[]>({
|
|
12
|
+
queryKey: workspaceKeys.appletThumbnails(workspaceId),
|
|
13
|
+
queryFn: async () =>
|
|
14
|
+
(
|
|
15
|
+
await requestJson<{ thumbnails: AppletThumbnail[] }>(
|
|
16
|
+
`/api/workspaces/${workspaceId}/applet-thumbnails`
|
|
17
|
+
)
|
|
18
|
+
).thumbnails,
|
|
19
|
+
...WORKSPACE_RESOURCE_OPTIONS
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function useSaveAppletThumbnails(workspaceId: string) {
|
|
24
|
+
const queryClient = useQueryClient()
|
|
25
|
+
|
|
26
|
+
return useMutation<void, Error, AppletThumbnailBatch>({
|
|
27
|
+
mutationFn: input =>
|
|
28
|
+
requestVoid(
|
|
29
|
+
`/api/workspaces/${workspaceId}/applet-thumbnails`,
|
|
30
|
+
jsonRequest('PUT', input),
|
|
31
|
+
'Failed to save applet thumbnails'
|
|
32
|
+
),
|
|
33
|
+
onSuccess: () => {
|
|
34
|
+
queryClient.invalidateQueries({ queryKey: workspaceKeys.appletThumbnails(workspaceId) })
|
|
35
|
+
queryClient.invalidateQueries({ queryKey: workspaceKeys.preview(workspaceId) })
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react'
|
|
2
|
+
|
|
3
|
+
import { useAppletThumbnailRecords, useSaveAppletThumbnails } from '@/client/features/applets/api'
|
|
4
|
+
import { useWorkspaceId } from '@/client/features/workspace/WorkspaceContext'
|
|
5
|
+
import type { AppletKind, AppletThumbnail, AppletThumbnailUpdate } from '@/lib/types'
|
|
6
|
+
|
|
7
|
+
export const THUMBNAIL_MAX_EDGE = 1_000
|
|
8
|
+
export const THUMBNAIL_PIXEL_RATIO = 3
|
|
9
|
+
export const THUMBNAIL_FRESH_MS = 3 * 60 * 60 * 1_000
|
|
10
|
+
// A capture that took this long janked the main thread (the DOM clone +
|
|
11
|
+
// style-inline walk is synchronous). Routine age-based re-captures of such a
|
|
12
|
+
// target are skipped; only a rebuilt bundle earns another attempt.
|
|
13
|
+
export const SLOW_CAPTURE_MS = 1_000
|
|
14
|
+
|
|
15
|
+
const THUMBNAIL_FORMAT_REVISION = '1000px-3x-webp-q80-v1'
|
|
16
|
+
const SETTLE_MS = 5_000
|
|
17
|
+
const ASSET_TIMEOUT_MS = 1_000
|
|
18
|
+
const CAPTURE_TIMEOUT_MS = 10_000
|
|
19
|
+
|
|
20
|
+
export type AppletThumbnailTarget = {
|
|
21
|
+
id: string
|
|
22
|
+
revision?: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type AppletThumbnailCaptureTarget = AppletThumbnailTarget & {
|
|
26
|
+
element: HTMLElement | null
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type UseAppletThumbnailsArgs = {
|
|
30
|
+
kind: AppletKind
|
|
31
|
+
enabled: boolean
|
|
32
|
+
targets: readonly AppletThumbnailTarget[]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
type CaptureThumbnail = (element: HTMLElement, stripHostChrome: boolean) => Promise<string | null>
|
|
36
|
+
|
|
37
|
+
export function thumbnailScale(element: HTMLElement): number {
|
|
38
|
+
return Math.min(
|
|
39
|
+
THUMBNAIL_PIXEL_RATIO,
|
|
40
|
+
THUMBNAIL_MAX_EDGE / Math.max(element.offsetWidth, element.offsetHeight)
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function appletThumbnailRevision(bundleRevision?: string): string {
|
|
45
|
+
return `${THUMBNAIL_FORMAT_REVISION}:${bundleRevision ?? ''}`
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function isAppletThumbnailStale(
|
|
49
|
+
record: AppletThumbnail | undefined,
|
|
50
|
+
revision: string,
|
|
51
|
+
now = Date.now()
|
|
52
|
+
): boolean {
|
|
53
|
+
if (!record || record.revision !== revision) return true
|
|
54
|
+
const capturedAt = Date.parse(record.capturedAt)
|
|
55
|
+
return !Number.isFinite(capturedAt) || now - capturedAt >= THUMBNAIL_FRESH_MS
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// A slow target is only worth re-capturing when its bundle changed: the new
|
|
59
|
+
// code deserves one measured attempt. A routine age-based refresh of the same
|
|
60
|
+
// bundle is not worth a >1s main-thread stall for a slightly fresher image.
|
|
61
|
+
export function shouldSkipSlowCapture(
|
|
62
|
+
record: AppletThumbnail | undefined,
|
|
63
|
+
revision: string
|
|
64
|
+
): boolean {
|
|
65
|
+
return (
|
|
66
|
+
record !== undefined &&
|
|
67
|
+
record.revision === revision &&
|
|
68
|
+
record.captureMs !== undefined &&
|
|
69
|
+
record.captureMs >= SLOW_CAPTURE_MS
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const timeoutNull = (ms: number) =>
|
|
74
|
+
new Promise<null>(resolve => {
|
|
75
|
+
setTimeout(() => resolve(null), ms)
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
async function captureThumbnail(
|
|
79
|
+
element: HTMLElement,
|
|
80
|
+
stripHostChrome: boolean
|
|
81
|
+
): Promise<string | null> {
|
|
82
|
+
const { createContext, destroyContext, domToDataUrl } = await import('modern-screenshot')
|
|
83
|
+
|
|
84
|
+
const run = async () => {
|
|
85
|
+
const context = await createContext(element, {
|
|
86
|
+
scale: thumbnailScale(element),
|
|
87
|
+
type: 'image/webp',
|
|
88
|
+
quality: 0.8,
|
|
89
|
+
backgroundColor: '#ffffff',
|
|
90
|
+
timeout: ASSET_TIMEOUT_MS,
|
|
91
|
+
...(stripHostChrome && {
|
|
92
|
+
onCreateForeignObjectSvg: (svg: SVGSVGElement) => {
|
|
93
|
+
const style = document.createElement('style')
|
|
94
|
+
style.textContent =
|
|
95
|
+
'[data-widget-chrome] { border-radius: 0 !important; box-shadow: none !important; }' +
|
|
96
|
+
'[data-widget-chrome]::after { display: none !important; }'
|
|
97
|
+
svg.append(style)
|
|
98
|
+
}
|
|
99
|
+
})
|
|
100
|
+
})
|
|
101
|
+
try {
|
|
102
|
+
return await domToDataUrl(context)
|
|
103
|
+
} finally {
|
|
104
|
+
destroyContext(context)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return Promise.race([run(), timeoutNull(CAPTURE_TIMEOUT_MS)])
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export async function collectAppletThumbnailUpdates(
|
|
112
|
+
kind: AppletKind,
|
|
113
|
+
records: readonly AppletThumbnail[],
|
|
114
|
+
targets: readonly AppletThumbnailCaptureTarget[],
|
|
115
|
+
isCancelled: () => boolean,
|
|
116
|
+
capture: CaptureThumbnail = captureThumbnail,
|
|
117
|
+
now = Date.now()
|
|
118
|
+
): Promise<AppletThumbnailUpdate[] | null> {
|
|
119
|
+
const updates: AppletThumbnailUpdate[] = []
|
|
120
|
+
|
|
121
|
+
for (const target of targets) {
|
|
122
|
+
if (isCancelled()) return null
|
|
123
|
+
const revision = appletThumbnailRevision(target.revision)
|
|
124
|
+
const record = records.find(item => item.kind === kind && item.id === target.id)
|
|
125
|
+
|
|
126
|
+
if (!isAppletThumbnailStale(record, revision, now)) {
|
|
127
|
+
updates.push({ id: target.id, revision })
|
|
128
|
+
continue
|
|
129
|
+
}
|
|
130
|
+
if (shouldSkipSlowCapture(record, revision)) {
|
|
131
|
+
updates.push({ id: target.id, revision })
|
|
132
|
+
continue
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (!target.element) {
|
|
136
|
+
updates.push({ id: target.id, revision, image: null })
|
|
137
|
+
continue
|
|
138
|
+
}
|
|
139
|
+
const started = performance.now()
|
|
140
|
+
const image = await capture(target.element, kind === 'widget').catch(() => null)
|
|
141
|
+
const captureMs = Math.round(performance.now() - started)
|
|
142
|
+
if (isCancelled()) return null
|
|
143
|
+
updates.push({ id: target.id, revision, image, captureMs })
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return updates
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Widgets provide every visible grid cell; a view provides only its active
|
|
150
|
+
// frame. The lifecycle and persistence stay identical for both kinds.
|
|
151
|
+
export function useAppletThumbnails({ kind, enabled, targets }: UseAppletThumbnailsArgs): void {
|
|
152
|
+
const workspaceId = useWorkspaceId()
|
|
153
|
+
const records = useAppletThumbnailRecords(workspaceId).data
|
|
154
|
+
const save = useSaveAppletThumbnails(workspaceId)
|
|
155
|
+
const targetsRef = useRef(targets)
|
|
156
|
+
targetsRef.current = targets
|
|
157
|
+
const recordsRef = useRef(records ?? [])
|
|
158
|
+
recordsRef.current = records ?? []
|
|
159
|
+
const saveRef = useRef(save.mutate)
|
|
160
|
+
saveRef.current = save.mutate
|
|
161
|
+
const targetKey = targets.map(target => `${target.id}@${target.revision ?? ''}`).join('\n')
|
|
162
|
+
// Hold the first pass until the stored records arrive — capturing against an
|
|
163
|
+
// unloaded store would re-screenshot everything on every page load.
|
|
164
|
+
const ready = records !== undefined
|
|
165
|
+
|
|
166
|
+
useEffect(() => {
|
|
167
|
+
if (!enabled || !ready || targetKey === '') return
|
|
168
|
+
|
|
169
|
+
let cancelled = false
|
|
170
|
+
let generation = 0
|
|
171
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
172
|
+
|
|
173
|
+
const schedule = () => {
|
|
174
|
+
generation += 1
|
|
175
|
+
const scheduledGeneration = generation
|
|
176
|
+
if (timer !== undefined) clearTimeout(timer)
|
|
177
|
+
if (document.visibilityState !== 'visible') return
|
|
178
|
+
|
|
179
|
+
timer = setTimeout(async () => {
|
|
180
|
+
timer = undefined
|
|
181
|
+
const thumbnails = await collectAppletThumbnailUpdates(
|
|
182
|
+
kind,
|
|
183
|
+
recordsRef.current,
|
|
184
|
+
targetsRef.current.map(target => ({
|
|
185
|
+
...target,
|
|
186
|
+
element: document.querySelector<HTMLElement>(
|
|
187
|
+
`[data-applet-thumbnail="${CSS.escape(`${kind}:${target.id}`)}"]`
|
|
188
|
+
)
|
|
189
|
+
})),
|
|
190
|
+
() =>
|
|
191
|
+
cancelled ||
|
|
192
|
+
generation !== scheduledGeneration ||
|
|
193
|
+
document.visibilityState !== 'visible'
|
|
194
|
+
)
|
|
195
|
+
if (!thumbnails || cancelled || document.visibilityState !== 'visible') return
|
|
196
|
+
saveRef.current({ kind, thumbnails })
|
|
197
|
+
}, SETTLE_MS)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
document.addEventListener('visibilitychange', schedule)
|
|
201
|
+
schedule()
|
|
202
|
+
return () => {
|
|
203
|
+
cancelled = true
|
|
204
|
+
if (timer !== undefined) clearTimeout(timer)
|
|
205
|
+
document.removeEventListener('visibilitychange', schedule)
|
|
206
|
+
}
|
|
207
|
+
}, [enabled, kind, ready, targetKey])
|
|
208
|
+
}
|
|
@@ -4,8 +4,10 @@ import {
|
|
|
4
4
|
IconFileSearch,
|
|
5
5
|
IconGhost,
|
|
6
6
|
IconLayout2,
|
|
7
|
+
IconMessages,
|
|
7
8
|
IconPiano,
|
|
8
9
|
IconSketching,
|
|
10
|
+
IconTableSpark,
|
|
9
11
|
IconUmbrella2,
|
|
10
12
|
type TablerIcon
|
|
11
13
|
} from '@tabler/icons-react'
|
|
@@ -79,23 +81,26 @@ export const WORKSPACE_ANALYSIS_PROMPT = {
|
|
|
79
81
|
icon: IconFileSearch
|
|
80
82
|
} satisfies ChatPrompt
|
|
81
83
|
|
|
82
|
-
export type ChatEmptyStateKind = 'chat-welcome' | 'workspace-welcome' | 'empty'
|
|
84
|
+
export type ChatEmptyStateKind = 'view-builder' | 'chat-welcome' | 'workspace-welcome' | 'empty'
|
|
83
85
|
|
|
84
86
|
type ResolveChatEmptyStateOptions = {
|
|
87
|
+
isViewBuilderDraft: boolean
|
|
85
88
|
hasSentMessageFromMoi: boolean
|
|
86
89
|
isWorkspacePendingAnalysis: boolean
|
|
87
90
|
}
|
|
88
91
|
|
|
89
92
|
export function resolveChatEmptyState({
|
|
93
|
+
isViewBuilderDraft,
|
|
90
94
|
hasSentMessageFromMoi,
|
|
91
95
|
isWorkspacePendingAnalysis
|
|
92
96
|
}: ResolveChatEmptyStateOptions): ChatEmptyStateKind {
|
|
97
|
+
if (isViewBuilderDraft) return 'view-builder'
|
|
93
98
|
if (!hasSentMessageFromMoi) return 'chat-welcome'
|
|
94
99
|
if (isWorkspacePendingAnalysis) return 'workspace-welcome'
|
|
95
100
|
return 'empty'
|
|
96
101
|
}
|
|
97
102
|
|
|
98
|
-
const EMPTY_STATE_STYLES = cn('flex flex-1 flex-col items-center justify-center')
|
|
103
|
+
const EMPTY_STATE_STYLES = cn('flex flex-1 flex-col items-center justify-center self-center')
|
|
99
104
|
|
|
100
105
|
type ChatEmptyStateProps = {
|
|
101
106
|
kind: ChatEmptyStateKind
|
|
@@ -104,13 +109,27 @@ type ChatEmptyStateProps = {
|
|
|
104
109
|
}
|
|
105
110
|
|
|
106
111
|
export function ChatEmptyState({ kind, disabled = false, onSelectPrompt }: ChatEmptyStateProps) {
|
|
107
|
-
|
|
108
|
-
|
|
112
|
+
switch (kind) {
|
|
113
|
+
case 'view-builder':
|
|
114
|
+
return <ViewBuilderChatEmptyState />
|
|
115
|
+
case 'chat-welcome':
|
|
116
|
+
return <ChatWelcome disabled={disabled} onSelectPrompt={onSelectPrompt} />
|
|
117
|
+
case 'workspace-welcome':
|
|
118
|
+
return <ChatWorkspaceWelcome disabled={disabled} onSelectPrompt={onSelectPrompt} />
|
|
119
|
+
case 'empty':
|
|
120
|
+
return <EmptyState />
|
|
109
121
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function ViewBuilderChatEmptyState() {
|
|
125
|
+
return (
|
|
126
|
+
<div className={cn(EMPTY_STATE_STYLES, 'gap-2 text-center text-muted-foreground')}>
|
|
127
|
+
<IconTableSpark size={56} stroke={0.5} />
|
|
128
|
+
<p className="mx-auto max-w-xs px-8 text-sm">
|
|
129
|
+
Describe the content, data, and key actions you need in the view
|
|
130
|
+
</p>
|
|
131
|
+
</div>
|
|
132
|
+
)
|
|
114
133
|
}
|
|
115
134
|
|
|
116
135
|
type WelcomeProps = {
|
|
@@ -161,8 +180,9 @@ export function ChatWorkspaceWelcome({ disabled = false, onSelectPrompt }: Welco
|
|
|
161
180
|
|
|
162
181
|
function EmptyState() {
|
|
163
182
|
return (
|
|
164
|
-
<div className={cn(EMPTY_STATE_STYLES, 'gap-
|
|
165
|
-
<
|
|
183
|
+
<div className={cn(EMPTY_STATE_STYLES, 'gap-2 text-center text-muted-foreground')}>
|
|
184
|
+
<IconMessages size={56} stroke={0.5} aria-hidden />
|
|
185
|
+
<p className="mx-auto max-w-sm px-8 text-sm">
|
|
166
186
|
Chat with your agent, create widgets and views, and manage your workspace context from here
|
|
167
187
|
</p>
|
|
168
188
|
</div>
|