moi-computer 0.9.1-next.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/features/applets/api.ts +38 -0
- package/client/features/applets/applet-thumbnail.ts +208 -0
- package/client/features/chat/ChatEmptyState.tsx +5 -3
- package/client/features/chat/ChatPanel.tsx +2 -8
- package/client/features/chat/ChatSelector.tsx +29 -10
- package/client/features/chat/MarkdownContent.tsx +2 -2
- package/client/features/home/HomePage.tsx +13 -0
- package/client/features/home/WorkspacePreview.tsx +10 -5
- 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 +1 -1
- package/client/features/home/workspace-setup/WorkspaceDialogContent.tsx +1 -1
- package/client/features/views/ViewBuilder.tsx +18 -4
- package/client/features/views/ViewManager.tsx +18 -2
- package/client/features/widgets/WidgetFrame.tsx +1 -1
- package/client/features/widgets/WidgetGrid.tsx +1 -1
- package/client/features/widgets/Widgets.tsx +16 -15
- package/client/features/workspace/CustomizePanel.tsx +29 -8
- package/client/features/workspace/WorkspaceScreen.tsx +8 -14
- package/client/index.tsx +6 -1
- package/client/runtime/useWorkspaceEvents.ts +17 -0
- package/client/runtime/workspace-theme.ts +29 -6
- package/dist/chunk-5c19v3zr.js +10 -0
- package/dist/chunk-6wx91x8j.js +1 -0
- package/dist/chunk-8s41nd3g.js +1 -0
- package/dist/{chunk-6w6j9g4b.js → chunk-a7fzp0z0.js} +2 -2
- package/dist/{chunk-pp62fnxh.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-sxc24vfp.js → chunk-zbeq02yc.js} +1 -1
- package/dist/chunk-zbt8emsw.js +2 -0
- package/dist/chunk-zfz3b4xg.js +2 -0
- package/dist/index.html +1 -1
- package/lib/types.ts +60 -41
- package/package.json +1 -1
- package/server/api.ts +69 -31
- package/server/app-config.ts +144 -0
- package/server/applets.ts +17 -0
- package/server/cli.ts +47 -11
- package/server/layout.ts +40 -45
- package/server/moi-scaffold.ts +37 -1
- package/server/thumbnails.ts +197 -0
- package/server/views.ts +10 -1
- package/server/widgets.ts +4 -18
- package/workspace/.claude/skills/moi-workspace/SKILL.md +13 -1
- package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +153 -253
- package/client/features/drawings/annotation-availability.ts +0 -10
- 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-3becmq75.js +0 -81
- package/dist/chunk-8ew39cvq.js +0 -10
- package/dist/chunk-c8gtrjwp.js +0 -1
- package/dist/chunk-v964b5g7.js +0 -1
- package/dist/chunk-zx33ts9d.css +0 -1
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
import { useWorkspaceLayoutCtx } from '@/client/features/workspace/WorkspaceLayoutContext'
|
|
4
|
-
import { useSaveWidgetThumbnails } from '@/client/features/widgets/api'
|
|
5
|
-
import {
|
|
6
|
-
captureWidgetThumbnail,
|
|
7
|
-
widgetThumbnailsKey
|
|
8
|
-
} from '@/client/features/widgets/widget-snapshot'
|
|
9
|
-
import type { RefObject } from 'react'
|
|
10
|
-
import type { WidgetInfo } from '@/lib/types'
|
|
11
|
-
|
|
12
|
-
// Grace period between "the grid changed" and the capture pass — lets widget
|
|
13
|
-
// bundles mount and their data requests land so we don't snapshot skeletons.
|
|
14
|
-
const SETTLE_MS = 5_000
|
|
15
|
-
|
|
16
|
-
// Age-based invalidation: bundle tags only catch CODE changes, but widget
|
|
17
|
-
// DATA drifts on its own (a dashboard captured in January still shows
|
|
18
|
-
// January). A set older than this re-captures even with a matching key.
|
|
19
|
-
const MAX_AGE_MS = 3 * 60 * 60 * 1000
|
|
20
|
-
|
|
21
|
-
type UseWidgetThumbnailsArgs = {
|
|
22
|
-
// Scope for [data-snapshot-widget] cell lookups.
|
|
23
|
-
containerRef: RefObject<HTMLElement | null>
|
|
24
|
-
// Widgets query data — supplies each widget's bundle tag.
|
|
25
|
-
widgets: WidgetInfo[]
|
|
26
|
-
// Widget ids currently on the grid.
|
|
27
|
-
visibleIds: string[]
|
|
28
|
-
// Edit mode pauses capture (cells wiggle, cards can be mid-drag).
|
|
29
|
-
editing: boolean
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Keeps the workspace's widget thumbnails fresh while the Widgets tab is open.
|
|
33
|
-
//
|
|
34
|
-
// One-number invalidation: the grid state is fingerprinted into a single key
|
|
35
|
-
// (visible ids + bundle tags). When the stored key differs, ALL visible
|
|
36
|
-
// widgets are re-captured in one pass and saved through their own endpoint
|
|
37
|
-
// (PUT .../thumbnails) — the layout PUT never carries the base64 map. The
|
|
38
|
-
// key is stamped even if some captures fail, so a broken widget can't loop
|
|
39
|
-
// the pass; entries merge server-side and are never pruned.
|
|
40
|
-
export function useWidgetThumbnails({
|
|
41
|
-
containerRef,
|
|
42
|
-
widgets,
|
|
43
|
-
visibleIds,
|
|
44
|
-
editing
|
|
45
|
-
}: UseWidgetThumbnailsArgs) {
|
|
46
|
-
const { layout, workspaceId } = useWorkspaceLayoutCtx()
|
|
47
|
-
const save = useSaveWidgetThumbnails(workspaceId)
|
|
48
|
-
// Latest `mutate` without widening the effect deps (mirrors the saveRef
|
|
49
|
-
// pattern in WorkspaceLayoutProvider).
|
|
50
|
-
const saveRef = useRef(save.mutate)
|
|
51
|
-
saveRef.current = save.mutate
|
|
52
|
-
const busyRef = useRef(false)
|
|
53
|
-
const [pass, setPass] = useState(0)
|
|
54
|
-
|
|
55
|
-
const key = widgetThumbnailsKey(visibleIds, widgets)
|
|
56
|
-
// A missing/unparsable timestamp counts as expired.
|
|
57
|
-
const capturedAt = Date.parse(layout.widgetThumbnails?.at ?? '')
|
|
58
|
-
const expired = !Number.isFinite(capturedAt) || Date.now() - capturedAt > MAX_AGE_MS
|
|
59
|
-
const stale = key !== '' && (key !== layout.widgetThumbnails?.key || expired)
|
|
60
|
-
|
|
61
|
-
useEffect(() => {
|
|
62
|
-
if (!stale || editing) return
|
|
63
|
-
|
|
64
|
-
// Hidden tab: timers are throttled and the captured frame may be stale —
|
|
65
|
-
// wait for visibility instead, then re-run this effect.
|
|
66
|
-
if (document.visibilityState !== 'visible') {
|
|
67
|
-
const onVisible = () => setPass(p => p + 1)
|
|
68
|
-
document.addEventListener('visibilitychange', onVisible, { once: true })
|
|
69
|
-
return () => document.removeEventListener('visibilitychange', onVisible)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Set when the effect re-runs or unmounts mid-pass (grid changed, tab
|
|
73
|
-
// closed). A cancelled pass must not save: its captures are partial, and
|
|
74
|
-
// stamping `key` over them would mark the set fresh with images missing.
|
|
75
|
-
let cancelled = false
|
|
76
|
-
const timer = setTimeout(async () => {
|
|
77
|
-
if (busyRef.current) return
|
|
78
|
-
busyRef.current = true
|
|
79
|
-
try {
|
|
80
|
-
const captured: Record<string, string> = {}
|
|
81
|
-
for (const id of visibleIds) {
|
|
82
|
-
if (cancelled) return
|
|
83
|
-
const cell = containerRef.current?.querySelector<HTMLElement>(
|
|
84
|
-
`[data-snapshot-widget="${CSS.escape(id)}"]`
|
|
85
|
-
)
|
|
86
|
-
const image = cell ? await captureWidgetThumbnail(cell) : null
|
|
87
|
-
if (image) captured[id] = image
|
|
88
|
-
}
|
|
89
|
-
if (cancelled) return
|
|
90
|
-
// The mutation's onMutate stamps the key into the local layout cache;
|
|
91
|
-
// the PUT itself is best-effort (a failed save just means a
|
|
92
|
-
// re-capture after reload).
|
|
93
|
-
saveRef.current({ key, thumbnails: captured })
|
|
94
|
-
} finally {
|
|
95
|
-
busyRef.current = false
|
|
96
|
-
// Re-evaluate: a pass skipped on `busy`, or a key that moved while
|
|
97
|
-
// this pass ran, gets picked up next round; a fresh key is a no-op.
|
|
98
|
-
setPass(p => p + 1)
|
|
99
|
-
}
|
|
100
|
-
}, SETTLE_MS)
|
|
101
|
-
return () => {
|
|
102
|
-
cancelled = true
|
|
103
|
-
clearTimeout(timer)
|
|
104
|
-
}
|
|
105
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
106
|
-
}, [key, stale, editing, pass])
|
|
107
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
// Widget thumbnail capture: renders one live grid cell (tagged with
|
|
2
|
-
// `data-snapshot-widget` in WidgetGrid) to a WebP data URL via
|
|
3
|
-
// modern-screenshot — white background, the widget's own aspect ratio, frame
|
|
4
|
-
// chrome stripped. Shared by the automatic invalidation hook
|
|
5
|
-
// (useWidgetThumbnails).
|
|
6
|
-
import type { WidgetInfo } from '@/lib/types'
|
|
7
|
-
|
|
8
|
-
// Long edge of a stored thumbnail, in output px. Placeholder until the real
|
|
9
|
-
// target resolution is decided.
|
|
10
|
-
export const THUMB_MAX_EDGE = 400
|
|
11
|
-
|
|
12
|
-
// How long modern-screenshot waits per image/asset before rendering without
|
|
13
|
-
// it. The library default is 30s, which reads as a hang on any widget whose
|
|
14
|
-
// image never loads (lazy-loaded offscreen, CORS-blocked, dead URL).
|
|
15
|
-
const ASSET_TIMEOUT_MS = 1_000
|
|
16
|
-
|
|
17
|
-
// Hard cap for one widget's whole capture. If it blows past this, the capture
|
|
18
|
-
// resolves null and the caller moves on — a snapshot pass must never wedge.
|
|
19
|
-
const WIDGET_TIMEOUT_MS = 10_000
|
|
20
|
-
|
|
21
|
-
export const thumbnailScale = (cell: HTMLElement) =>
|
|
22
|
-
Math.min(1, THUMB_MAX_EDGE / Math.max(cell.offsetWidth, cell.offsetHeight))
|
|
23
|
-
|
|
24
|
-
// Fingerprint of the grid state a thumbnail set was captured from: which
|
|
25
|
-
// widgets are on the grid and which bundle build (`WidgetInfo.tag`) each one
|
|
26
|
-
// runs. Order-independent. Any change — add, remove, rebundle — changes the
|
|
27
|
-
// key and triggers a full re-capture.
|
|
28
|
-
export const widgetThumbnailsKey = (visibleIds: string[], widgets: WidgetInfo[]) => {
|
|
29
|
-
const tagById = new Map(widgets.map(w => [w.id, w.tag]))
|
|
30
|
-
return [...visibleIds]
|
|
31
|
-
.sort()
|
|
32
|
-
.map(id => `${id}@${tagById.get(id) ?? ''}`)
|
|
33
|
-
.join(' ')
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const timeoutNull = (ms: number) =>
|
|
37
|
-
new Promise<null>(resolve => {
|
|
38
|
-
setTimeout(() => resolve(null), ms)
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
export async function captureWidgetThumbnail(cell: HTMLElement): Promise<string | null> {
|
|
42
|
-
const { createContext, destroyContext, domToDataUrl } = await import('modern-screenshot')
|
|
43
|
-
|
|
44
|
-
const run = async () => {
|
|
45
|
-
const context = await createContext(cell, {
|
|
46
|
-
scale: thumbnailScale(cell),
|
|
47
|
-
type: 'image/webp',
|
|
48
|
-
quality: 0.8,
|
|
49
|
-
backgroundColor: '#ffffff',
|
|
50
|
-
timeout: ASSET_TIMEOUT_MS,
|
|
51
|
-
// Strip the frame chrome inside the capture only. Computed styles are
|
|
52
|
-
// inlined onto the clone, so a wrapper selector can't reach them — but a
|
|
53
|
-
// stylesheet injected into the generated SVG can: !important rules beat
|
|
54
|
-
// inline styles and the copied ::after.
|
|
55
|
-
onCreateForeignObjectSvg: svg => {
|
|
56
|
-
const style = document.createElement('style')
|
|
57
|
-
style.textContent =
|
|
58
|
-
'[data-widget-chrome] { border-radius: 0 !important; box-shadow: none !important; }' +
|
|
59
|
-
'[data-widget-chrome]::after { display: none !important; }'
|
|
60
|
-
svg.append(style)
|
|
61
|
-
}
|
|
62
|
-
})
|
|
63
|
-
try {
|
|
64
|
-
return await domToDataUrl(context)
|
|
65
|
-
} finally {
|
|
66
|
-
destroyContext(context)
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return Promise.race([run(), timeoutNull(WIDGET_TIMEOUT_MS)])
|
|
71
|
-
}
|