moi-computer 0.4.0 → 0.4.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 (123) hide show
  1. package/README.md +41 -5
  2. package/bin/moi.mjs +11 -0
  3. package/client/api/workspace-keys.ts +1 -0
  4. package/client/app/AppRouter.tsx +5 -1
  5. package/client/app/routes/WorkspaceRoute.tsx +9 -5
  6. package/client/app/shell/SidebarLayout.tsx +9 -7
  7. package/client/components/shared/BottomPanel.tsx +24 -5
  8. package/client/components/shared/Composer.tsx +1 -1
  9. package/client/components/shared/PanelHeader.tsx +1 -1
  10. package/client/components/ui/button.tsx +5 -5
  11. package/client/components/ui/dropdown-menu.tsx +6 -6
  12. package/client/components/ui/hover-card.tsx +1 -1
  13. package/client/components/ui/input.tsx +1 -1
  14. package/client/components/ui/popover.tsx +1 -1
  15. package/client/components/ui/skeleton.tsx +1 -1
  16. package/client/components/ui/textarea.tsx +1 -1
  17. package/client/components/ui/tooltip.tsx +1 -1
  18. package/client/features/applets/applet-cache.ts +20 -1
  19. package/client/features/applets/applet-log.ts +10 -30
  20. package/client/features/applets/applet-runtime.ts +272 -0
  21. package/client/features/applets/useApplet.ts +36 -10
  22. package/client/features/chat/ChatComposer.tsx +1 -1
  23. package/client/features/chat/ChatEmptyState.tsx +186 -0
  24. package/client/features/chat/ChatPanel.tsx +95 -54
  25. package/client/features/chat/ChatPopup.tsx +3 -13
  26. package/client/features/chat/ChatPromptBubbles.tsx +74 -0
  27. package/client/features/chat/MarkdownContent.tsx +15 -3
  28. package/client/features/chat/ModelPicker.tsx +1 -1
  29. package/client/features/chat/TurnView.tsx +6 -17
  30. package/client/features/chat/chat-send.ts +26 -1
  31. package/client/features/chat/tool-group/CodeBlock.tsx +1 -1
  32. package/client/features/chat/tool-group/ReadImagePreview.tsx +1 -1
  33. package/client/features/chat/tool-group/SubagentCard.tsx +1 -1
  34. package/client/features/chat/tool-group/TimelineRow.tsx +4 -4
  35. package/client/features/chat/tool-group/ToolCallGroup.tsx +12 -5
  36. package/client/features/chat/tool-group/ToolOutput.tsx +2 -2
  37. package/client/features/chat/tool-group/format.ts +3 -3
  38. package/client/features/chat/useAppletChatMessage.ts +69 -0
  39. package/client/features/chat/useChat.ts +49 -14
  40. package/client/features/chat/useStickToBottom.ts +11 -1
  41. package/client/features/connectors/McpServerCards.tsx +3 -3
  42. package/client/features/dev/HarnessDebugPage.tsx +4 -4
  43. package/client/features/dev/PixelPainter.tsx +1 -1
  44. package/client/features/dev/PlaygroundPage.tsx +1 -1
  45. package/client/features/dev/ToolCallsPage.tsx +2 -2
  46. package/client/features/home/HomePage.tsx +17 -14
  47. package/client/features/home/WorkspacePreview.tsx +12 -13
  48. package/client/features/home/api.ts +8 -5
  49. package/client/features/home/workspace-presentation.tsx +1 -1
  50. package/client/features/home/workspace-setup/CreateWorkspaceDialog.tsx +1 -1
  51. package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +21 -8
  52. package/client/features/scratchpad/Scratchpad.tsx +41 -2
  53. package/client/features/scratchpad/ScratchpadControls.tsx +13 -13
  54. package/client/features/scratchpad/useScratchpadSnapshot.tsx +1 -1
  55. package/client/features/settings/EnvironmentSettings.tsx +1 -1
  56. package/client/features/settings/IconPicker.tsx +11 -11
  57. package/client/features/settings/SettingsLayout.tsx +1 -1
  58. package/client/features/settings/WorkspaceSettings.tsx +2 -2
  59. package/client/features/settings/api.ts +33 -1
  60. package/client/features/widgets/HiddenPanel.tsx +4 -3
  61. package/client/features/widgets/Widgets.tsx +1 -0
  62. package/client/features/workspace/CustomizePanel.tsx +96 -82
  63. package/client/features/workspace/WorkspaceScreen.tsx +129 -107
  64. package/client/features/workspace/WorkspaceSkillUpdateBanner.tsx +91 -0
  65. package/client/features/workspace/WorkspaceTabs.tsx +1 -1
  66. package/client/features/workspace/api.ts +52 -0
  67. package/client/features/workspace/moi-context.ts +63 -17
  68. package/client/features/workspace/tab-resolution.ts +75 -0
  69. package/client/features/workspace/useWorkspaceNavigation.ts +128 -0
  70. package/client/features/workspace/useWorkspaceSkillUpdates.ts +160 -0
  71. package/client/index.css +10 -15
  72. package/client/lib/app-icon-registry.ts +77 -70
  73. package/client/lib/rate-limit.ts +77 -0
  74. package/client/runtime/useWorkspaceEvents.ts +15 -2
  75. package/client/runtime/workspace-theme.ts +115 -0
  76. package/client/store/ui.ts +42 -17
  77. package/client/theme.css +20 -15
  78. package/dist/{chunk-fh2mf6v9.js → chunk-3m1xe1j3.js} +94 -94
  79. package/dist/chunk-5vaevt8z.js +2 -0
  80. package/dist/{chunk-69nhbjhy.js → chunk-7bzpmtxp.js} +4 -4
  81. package/dist/chunk-h0hk61pm.js +9 -0
  82. package/dist/{chunk-35fq49qa.js → chunk-h3evrtyp.js} +1 -1
  83. package/dist/chunk-k5sjx9s5.js +1 -0
  84. package/dist/{chunk-2vaafjp4.js → chunk-m9qja0nx.js} +1 -1
  85. package/dist/chunk-s7za1qsv.css +1 -0
  86. package/dist/{chunk-72atbmh3.js → chunk-tcfa3vt3.js} +1 -1
  87. package/dist/chunk-v797g6ap.js +51 -0
  88. package/dist/chunk-xyrw8318.js +27 -0
  89. package/dist/index.html +1 -1
  90. package/lib/app-icons.ts +73 -0
  91. package/lib/moi-context.ts +104 -3
  92. package/lib/themes.ts +83 -45
  93. package/lib/types.ts +44 -9
  94. package/lib/workspace-tabs.ts +48 -0
  95. package/package.json +4 -1
  96. package/server/api.ts +57 -5
  97. package/server/app-settings.ts +65 -0
  98. package/server/applets.ts +132 -22
  99. package/server/bundler/build-applet.ts +74 -16
  100. package/server/cli.ts +144 -17
  101. package/server/control.ts +53 -7
  102. package/server/data-dir.ts +1 -1
  103. package/server/events.ts +1 -1
  104. package/server/functions-worker.ts +15 -1
  105. package/server/functions.ts +51 -6
  106. package/server/layout.ts +9 -14
  107. package/server/moi-scaffold.ts +37 -3
  108. package/server/registry.ts +1 -1
  109. package/server/skill-update.ts +47 -0
  110. package/server/skill-version.ts +2 -11
  111. package/server/tabs.ts +59 -0
  112. package/server/theme.ts +8 -14
  113. package/server/view-builders.ts +6 -2
  114. package/workspace/.claude/skills/moi-workspace/DESIGN.md +265 -107
  115. package/workspace/.claude/skills/moi-workspace/SKILL.md +85 -11
  116. package/client/features/workspace/useWorkspaceTheme.ts +0 -82
  117. package/dist/chunk-19g80zc9.css +0 -1
  118. package/dist/chunk-7mkv2gr0.js +0 -2
  119. package/dist/chunk-gt7n06ef.js +0 -1
  120. package/dist/chunk-jwmc32rp.js +0 -63
  121. package/dist/chunk-kh24bstm.js +0 -10
  122. package/dist/chunk-sfa4mbmx.js +0 -15
  123. package/workspace/.claude/skills/moi-workspace/VIEW-DESIGN.md +0 -22
@@ -41,6 +41,7 @@ import {
41
41
  IconMoon,
42
42
  IconMountain,
43
43
  IconMusic,
44
+ IconPiano,
44
45
  IconPalette,
45
46
  IconPaperclip,
46
47
  IconPhoto,
@@ -64,82 +65,88 @@ import {
64
65
  IconWorld
65
66
  } from '@tabler/icons-react'
66
67
 
68
+ import { APP_ICON_IDS, isAppIconId, type AppIconId } from '@/lib/app-icons'
69
+
67
70
  export type AppIconChoice = {
68
- id: string
71
+ id: AppIconId
69
72
  Icon: TablerIcon
70
73
  }
71
74
 
72
- // Shared by the workspace icon picker and view tabs. Add new app-level icon
73
- // choices here so both surfaces and the view-builder prompt stay in sync.
74
- export const APP_ICON_CHOICES: AppIconChoice[] = [
75
- { id: 'rocket', Icon: IconRocket },
76
- { id: 'sparkles', Icon: IconSparkles },
77
- { id: 'bolt', Icon: IconBolt },
78
- { id: 'flame', Icon: IconFlame },
79
- { id: 'star', Icon: IconStar },
80
- { id: 'heart', Icon: IconHeart },
81
- { id: 'diamond', Icon: IconDiamond },
82
- { id: 'trophy', Icon: IconTrophy },
83
- { id: 'target', Icon: IconTarget },
84
- { id: 'bulb', Icon: IconBulb },
85
- { id: 'brain', Icon: IconBrain },
86
- { id: 'robot', Icon: IconRobot },
87
- { id: 'wand', Icon: IconWand },
88
- { id: 'atom', Icon: IconAtom },
89
- { id: 'flask', Icon: IconFlask },
90
- { id: 'cpu', Icon: IconCpu },
91
- { id: 'code', Icon: IconCode },
92
- { id: 'terminal', Icon: IconTerminal2 },
93
- { id: 'api', Icon: IconApi },
94
- { id: 'database', Icon: IconDatabase },
95
- { id: 'cube', Icon: IconCube },
96
- { id: 'hexagon', Icon: IconHexagon },
97
- { id: 'plug', Icon: IconPlug },
98
- { id: 'tool', Icon: IconTool },
99
- { id: 'settings', Icon: IconSettings },
100
- { id: 'bug', Icon: IconBug },
101
- { id: 'activity', Icon: IconActivity },
102
- { id: 'chart', Icon: IconChartBar },
103
- { id: 'briefcase', Icon: IconBriefcase },
104
- { id: 'folder', Icon: IconFolder },
105
- { id: 'file', Icon: IconFile },
106
- { id: 'book', Icon: IconBook },
107
- { id: 'message', Icon: IconMessage },
108
- { id: 'mail', Icon: IconMail },
109
- { id: 'bell', Icon: IconBell },
110
- { id: 'paperclip', Icon: IconPaperclip },
111
- { id: 'key', Icon: IconKey },
112
- { id: 'shield', Icon: IconShield },
113
- { id: 'user', Icon: IconUser },
114
- { id: 'home', Icon: IconHome },
115
- { id: 'globe', Icon: IconGlobe },
116
- { id: 'world', Icon: IconWorld },
117
- { id: 'planet', Icon: IconPlanet },
118
- { id: 'compass', Icon: IconCompass },
119
- { id: 'map', Icon: IconMap },
120
- { id: 'calendar', Icon: IconCalendar },
121
- { id: 'cloud', Icon: IconCloud },
122
- { id: 'sun', Icon: IconSun },
123
- { id: 'moon', Icon: IconMoon },
124
- { id: 'snowflake', Icon: IconSnowflake },
125
- { id: 'leaf', Icon: IconLeaf },
126
- { id: 'mountain', Icon: IconMountain },
127
- { id: 'feather', Icon: IconFeather },
128
- { id: 'ghost', Icon: IconGhost },
129
- { id: 'music', Icon: IconMusic },
130
- { id: 'camera', Icon: IconCamera },
131
- { id: 'photo', Icon: IconPhoto },
132
- { id: 'palette', Icon: IconPalette },
133
- { id: 'gamepad', Icon: IconDeviceGamepad2 },
134
- { id: 'gift', Icon: IconGift },
135
- { id: 'cart', Icon: IconShoppingCart },
136
- { id: 'chef', Icon: IconChefHat }
137
- ]
75
+ // UI component for every shared app icon id. Record<> keeps this map in sync
76
+ // with the server-safe list used by builder and bundle validation.
77
+ const appIconById: Record<AppIconId, TablerIcon> = {
78
+ rocket: IconRocket,
79
+ sparkles: IconSparkles,
80
+ bolt: IconBolt,
81
+ flame: IconFlame,
82
+ star: IconStar,
83
+ heart: IconHeart,
84
+ diamond: IconDiamond,
85
+ trophy: IconTrophy,
86
+ target: IconTarget,
87
+ bulb: IconBulb,
88
+ brain: IconBrain,
89
+ robot: IconRobot,
90
+ wand: IconWand,
91
+ atom: IconAtom,
92
+ flask: IconFlask,
93
+ cpu: IconCpu,
94
+ code: IconCode,
95
+ terminal: IconTerminal2,
96
+ api: IconApi,
97
+ database: IconDatabase,
98
+ cube: IconCube,
99
+ hexagon: IconHexagon,
100
+ plug: IconPlug,
101
+ tool: IconTool,
102
+ settings: IconSettings,
103
+ bug: IconBug,
104
+ activity: IconActivity,
105
+ chart: IconChartBar,
106
+ briefcase: IconBriefcase,
107
+ folder: IconFolder,
108
+ file: IconFile,
109
+ book: IconBook,
110
+ message: IconMessage,
111
+ mail: IconMail,
112
+ bell: IconBell,
113
+ paperclip: IconPaperclip,
114
+ key: IconKey,
115
+ shield: IconShield,
116
+ user: IconUser,
117
+ home: IconHome,
118
+ globe: IconGlobe,
119
+ world: IconWorld,
120
+ planet: IconPlanet,
121
+ compass: IconCompass,
122
+ map: IconMap,
123
+ calendar: IconCalendar,
124
+ cloud: IconCloud,
125
+ sun: IconSun,
126
+ moon: IconMoon,
127
+ snowflake: IconSnowflake,
128
+ leaf: IconLeaf,
129
+ mountain: IconMountain,
130
+ feather: IconFeather,
131
+ ghost: IconGhost,
132
+ music: IconMusic,
133
+ piano: IconPiano,
134
+ camera: IconCamera,
135
+ photo: IconPhoto,
136
+ palette: IconPalette,
137
+ gamepad: IconDeviceGamepad2,
138
+ gift: IconGift,
139
+ cart: IconShoppingCart,
140
+ chef: IconChefHat
141
+ }
138
142
 
139
- export const APP_ICON_IDS = APP_ICON_CHOICES.map(choice => choice.id)
143
+ export const APP_ICON_CHOICES: AppIconChoice[] = APP_ICON_IDS.map(id => ({
144
+ id,
145
+ Icon: appIconById[id]
146
+ }))
140
147
 
141
- const appIconById = new Map(APP_ICON_CHOICES.map(choice => [choice.id, choice.Icon]))
148
+ export { APP_ICON_IDS }
142
149
 
143
150
  export function resolveAppIcon(id: string | undefined): TablerIcon | null {
144
- return id ? (appIconById.get(id) ?? null) : null
151
+ return id && isAppIconId(id) ? appIconById[id] : null
145
152
  }
@@ -0,0 +1,77 @@
1
+ // A two-tier limiter for calls that are cheap to make and expensive to serve —
2
+ // an applet firing chat messages, a crash loop POSTing to the error journal.
3
+ // Both tiers are needed, and neither substitutes for the other:
4
+ //
5
+ // • the per-key COOLDOWN collapses a repeat of the identical call (a render
6
+ // loop, a double-mounted bundle) into one;
7
+ // • the WINDOW cap bounds the total regardless of key, catching the loop that
8
+ // varies its key every call and would sail past a cooldown.
9
+ //
10
+ // The verdict says which tier refused, so callers can explain the drop rather
11
+ // than swallow it. Recording is a side effect of an `ok`, so `admit` is called
12
+ // once per attempt, never speculatively.
13
+ //
14
+ // `now` is injectable for tests; production passes nothing and reads the clock.
15
+
16
+ export type RateLimitVerdict = 'ok' | 'cooldown' | 'window'
17
+
18
+ export type RateLimiterOptions = {
19
+ // Minimum gap between two calls sharing a key.
20
+ cooldownMs: number
21
+ // Length of the window the cap applies to.
22
+ windowMs: number
23
+ // Admissions allowed per window, across all keys.
24
+ maxPerWindow: number
25
+ // Bound on remembered keys — half are dropped when exceeded, so a caller
26
+ // whose keys are unbounded (message text, ids) can't grow the map forever.
27
+ maxKeys?: number
28
+ now?: () => number
29
+ }
30
+
31
+ export type RateLimiter = {
32
+ admit: (key: string) => RateLimitVerdict
33
+ }
34
+
35
+ const DEFAULT_MAX_KEYS = 256
36
+
37
+ export function createRateLimiter({
38
+ cooldownMs,
39
+ windowMs,
40
+ maxPerWindow,
41
+ maxKeys = DEFAULT_MAX_KEYS,
42
+ now = Date.now
43
+ }: RateLimiterOptions): RateLimiter {
44
+ const lastAdmitted = new Map<string, number>()
45
+ // Zero, not `now()`: the first call should open a fresh window rather than
46
+ // land mid-way through one that started at construction time.
47
+ let windowStart = 0
48
+ let windowCount = 0
49
+
50
+ return {
51
+ admit(key) {
52
+ const at = now()
53
+
54
+ const last = lastAdmitted.get(key)
55
+ if (last !== undefined && at - last < cooldownMs) return 'cooldown'
56
+
57
+ if (at - windowStart >= windowMs) {
58
+ windowStart = at
59
+ windowCount = 0
60
+ }
61
+ if (windowCount >= maxPerWindow) return 'window'
62
+ windowCount++
63
+
64
+ lastAdmitted.set(key, at)
65
+ // Pruning by insertion order, not recency: `set` on an existing key keeps
66
+ // its original position. Good enough for a bound whose only job is to
67
+ // stop unbounded growth — the cost of dropping a still-hot key is one
68
+ // extra admitted call.
69
+ if (lastAdmitted.size > maxKeys) {
70
+ for (const stale of [...lastAdmitted.keys()].slice(0, Math.ceil(maxKeys / 2))) {
71
+ lastAdmitted.delete(stale)
72
+ }
73
+ }
74
+ return 'ok'
75
+ }
76
+ }
77
+ }
@@ -1,12 +1,14 @@
1
1
  import { useEffect, useRef } from 'react'
2
2
 
3
3
  import { wsUrl } from '@/client/lib/ws-url'
4
- import type { ViewBuilder, ViewInfo, WidgetInfo } from '@/lib/types'
4
+ import type { AppSettings, ViewBuilder, ViewInfo, WidgetInfo, WorkspaceTabId } from '@/lib/types'
5
5
 
6
6
  export type WorkspaceEvent =
7
7
  | { type: 'widget:updated'; name: string }
8
8
  | { type: 'widget-layout:updated'; widgets: WidgetInfo[] }
9
- | { type: 'widgets:refresh' }
9
+ // `moi refresh` — cache-bust and re-fetch applets without a rebuild. `only`
10
+ // narrows to one kind; absent means both widgets and views.
11
+ | { type: 'applets:refresh'; only?: 'widgets' | 'views' }
10
12
  | { type: 'view:updated'; name: string }
11
13
  | { type: 'view-layout:updated'; views: ViewInfo[] }
12
14
  | { type: 'view-builder:updated'; workspaceId: string; builder: ViewBuilder }
@@ -21,6 +23,17 @@ export type WorkspaceEvent =
21
23
  // The Scratchpad canvas for `workspaceId` was saved — open tabs reload from
22
24
  // disk. `origin` is the tab that wrote it, so that tab can skip its own echo.
23
25
  | { type: 'scratchpad:updated'; workspaceId: string; origin?: string }
26
+ // App settings changed (PATCH /api/settings from any client) — carries the
27
+ // new value so caches update without a refetch.
28
+ | { type: 'settings:updated'; settings: AppSettings }
29
+ // `moi tab focus` — every open client of `workspaceId` navigates (replace)
30
+ // to `tab`, delivering `params` to the target view via navigation state.
31
+ | {
32
+ type: 'tab:focus'
33
+ workspaceId: string
34
+ tab: WorkspaceTabId
35
+ params?: Record<string, unknown>
36
+ }
24
37
 
25
38
  type WorkspaceEventHandler = (event: WorkspaceEvent) => void
26
39
 
@@ -0,0 +1,115 @@
1
+ import { useEffect } from 'react'
2
+ import type { CSSProperties } from 'react'
3
+
4
+ import { FONT_THEMES, THEME_COLOR_TOKENS, deriveThemeColors } from '@/lib/themes'
5
+ import type { ThemeColorToken } from '@/lib/themes'
6
+ import type { WorkspaceLayout } from '@/lib/types'
7
+
8
+ const FONT_LINK_ID = 'mei-fonts'
9
+ const FONT_PREVIEW_LINK_ID = 'mei-font-previews'
10
+ const ALL_FONTS_QUERY = Object.values(FONT_THEMES)
11
+ .map(theme => theme.googleFontsQuery)
12
+ .filter(Boolean)
13
+ .join('&family=')
14
+ const WORKSPACE_FONT_PROPERTIES = [
15
+ ['sans', '--sans'],
16
+ ['mono', '--mono']
17
+ ] as const
18
+ const WORKSPACE_COLOR_PROPERTIES = THEME_COLOR_TOKENS.map(
19
+ token => [token, themeColorProperty(token)] as const
20
+ )
21
+ const WORKSPACE_THEME_PROPERTIES = [
22
+ ...WORKSPACE_FONT_PROPERTIES.map(([, property]) => property),
23
+ ...WORKSPACE_COLOR_PROPERTIES.map(([, property]) => property)
24
+ ]
25
+
26
+ type WorkspaceThemeStyle = CSSProperties & {
27
+ [property: `--${string}`]: string | undefined
28
+ }
29
+
30
+ function themeColorProperty(token: ThemeColorToken): `--${string}` {
31
+ const name = token.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`)
32
+ return `--${name}`
33
+ }
34
+
35
+ export function getWorkspaceThemeStyle(theme: WorkspaceLayout['theme']): WorkspaceThemeStyle {
36
+ const style: WorkspaceThemeStyle = {}
37
+ const font = FONT_THEMES[theme?.font ?? 'default'] ?? FONT_THEMES.default
38
+ const colors = theme?.primary ? deriveThemeColors(theme.primary) : undefined
39
+ for (const [token, property] of WORKSPACE_FONT_PROPERTIES) {
40
+ style[property] = font[token]
41
+ }
42
+ for (const [token, property] of WORKSPACE_COLOR_PROPERTIES) {
43
+ style[property] = colors?.[token]
44
+ }
45
+ return style
46
+ }
47
+
48
+ export function usePreloadWorkspaceFonts() {
49
+ useEffect(() => {
50
+ if (document.getElementById(FONT_PREVIEW_LINK_ID)) return
51
+
52
+ const link = document.createElement('link')
53
+ link.id = FONT_PREVIEW_LINK_ID
54
+ link.rel = 'stylesheet'
55
+ link.href = `https://fonts.googleapis.com/css2?family=${ALL_FONTS_QUERY}&display=swap`
56
+ document.head.appendChild(link)
57
+
58
+ return () => {
59
+ link.remove()
60
+ }
61
+ }, [])
62
+ }
63
+
64
+ function useDocumentWorkspaceThemeStyle(theme: WorkspaceLayout['theme']) {
65
+ useEffect(() => {
66
+ const element = document.documentElement
67
+ const style = getWorkspaceThemeStyle(theme)
68
+
69
+ for (const property of WORKSPACE_THEME_PROPERTIES) {
70
+ const value = style[property]
71
+ if (value) {
72
+ element.style.setProperty(property, value)
73
+ } else {
74
+ element.style.removeProperty(property)
75
+ }
76
+ }
77
+
78
+ return () => {
79
+ for (const property of WORKSPACE_THEME_PROPERTIES) {
80
+ element.style.removeProperty(property)
81
+ }
82
+ }
83
+ }, [theme])
84
+ }
85
+
86
+ // Applies the active workspace theme to the document root so the workspace,
87
+ // sidebar, and body-level portals all resolve the same tokens.
88
+ export function useWorkspaceTheme(theme: WorkspaceLayout['theme']) {
89
+ const font = theme?.font ?? 'default'
90
+ useDocumentWorkspaceThemeStyle(theme)
91
+
92
+ useEffect(() => {
93
+ const config = FONT_THEMES[font] ?? FONT_THEMES.default
94
+
95
+ const existing = document.getElementById(FONT_LINK_ID) as HTMLLinkElement | null
96
+ if (!config.googleFontsQuery) {
97
+ existing?.remove()
98
+ } else {
99
+ const url = `https://fonts.googleapis.com/css2?family=${config.googleFontsQuery}&display=swap`
100
+ if (existing) {
101
+ existing.href = url
102
+ } else {
103
+ const link = document.createElement('link')
104
+ link.id = FONT_LINK_ID
105
+ link.rel = 'stylesheet'
106
+ link.href = url
107
+ document.head.appendChild(link)
108
+ }
109
+ }
110
+
111
+ return () => {
112
+ document.getElementById(FONT_LINK_ID)?.remove()
113
+ }
114
+ }, [font])
115
+ }
@@ -1,25 +1,50 @@
1
1
  import { create } from 'zustand'
2
- import { persist } from 'zustand/middleware'
2
+ import { createJSONStorage, persist } from 'zustand/middleware'
3
+ import type { StateStorage } from 'zustand/middleware'
3
4
 
4
- // Global, device-local UI preferences — persisted to localStorage so they
5
- // survive reloads. Server-owned or per-workspace state does NOT belong here.
5
+ // Device-local UI preferences and onboarding markers, persisted to localStorage
6
+ // so they survive reloads. Server-owned workspace data does NOT belong here.
6
7
  type UiStore = {
7
- sidebarCollapsed: boolean
8
8
  discoveredWorkspacesOpen: boolean
9
- toggleSidebar: () => void
10
- setSidebarCollapsed: (collapsed: boolean) => void
9
+ hasSentMessageFromMoi: boolean
10
+ workspaceIdsPendingAnalysis: string[]
11
11
  setDiscoveredWorkspacesOpen: (open: boolean) => void
12
+ markWorkspacePendingAnalysis: (workspaceId: string) => void
13
+ markMessageSentFromMoi: (workspaceId: string) => void
12
14
  }
13
15
 
14
- export const useUiStore = create<UiStore>()(
15
- persist(
16
- set => ({
17
- sidebarCollapsed: false,
18
- discoveredWorkspacesOpen: true,
19
- toggleSidebar: () => set(s => ({ sidebarCollapsed: !s.sidebarCollapsed })),
20
- setSidebarCollapsed: collapsed => set({ sidebarCollapsed: collapsed }),
21
- setDiscoveredWorkspacesOpen: open => set({ discoveredWorkspacesOpen: open })
22
- }),
23
- { name: 'moi:ui' }
16
+ export const createUiStore = (storage?: StateStorage) =>
17
+ create<UiStore>()(
18
+ persist(
19
+ set => ({
20
+ discoveredWorkspacesOpen: true,
21
+ hasSentMessageFromMoi: false,
22
+ workspaceIdsPendingAnalysis: [],
23
+ setDiscoveredWorkspacesOpen: open => set({ discoveredWorkspacesOpen: open }),
24
+ markWorkspacePendingAnalysis: workspaceId =>
25
+ set(state => {
26
+ const workspaceIds = state.workspaceIdsPendingAnalysis ?? []
27
+ return {
28
+ workspaceIdsPendingAnalysis: workspaceIds.includes(workspaceId)
29
+ ? workspaceIds
30
+ : [...workspaceIds, workspaceId]
31
+ }
32
+ }),
33
+ markMessageSentFromMoi: workspaceId =>
34
+ set(state => ({
35
+ hasSentMessageFromMoi: true,
36
+ workspaceIdsPendingAnalysis: (state.workspaceIdsPendingAnalysis ?? []).filter(
37
+ id => id !== workspaceId
38
+ )
39
+ }))
40
+ }),
41
+ storage
42
+ ? {
43
+ name: 'moi:ui',
44
+ storage: createJSONStorage<UiStore>(() => storage)
45
+ }
46
+ : { name: 'moi:ui' }
47
+ )
24
48
  )
25
- )
49
+
50
+ export const useUiStore = createUiStore()
package/client/theme.css CHANGED
@@ -3,20 +3,25 @@
3
3
  * applet bundles (server/bundler/build-applet.ts emits an `@import` to this file
4
4
  * into the applet's synthetic CSS).
5
5
  *
6
- * The actual CSS variables (`--background`, `--foreground`, `--card`, etc.)
6
+ * The actual CSS variables (`--sans`, `--mono`, `--background`, etc.)
7
7
  * are owned by the host and declared on `:root` / `.dark` in
8
- * `client/index.css`. This file only maps Tailwind's `--color-*` /
9
- * `--radius-*` tokens onto those host-owned variables via `@theme inline`,
8
+ * `client/index.css`. This file only maps Tailwind's `--font-*` /
9
+ * `--color-*` / `--radius-*` tokens onto those host-owned variables via
10
+ * `@theme inline`,
10
11
  * which:
11
12
  * - generates utilities like `.bg-background { background-color: var(--background) }`
12
- * - does NOT emit `--color-background` or `--background` into the output
13
+ * - does NOT emit `--font-sans`, `--color-background`, or their source
14
+ * variables into the output
13
15
  *
14
- * Net effect: widgets compile classes like `bg-foreground/20`, `text-muted`,
15
- * `rounded-xl`, and pick up the host's runtime theme without redefining
16
- * any variable themselves.
16
+ * Net effect: applets compile classes like `font-sans`, `font-mono`,
17
+ * `bg-foreground/20`, and `rounded-xl`, then pick up the host's runtime theme
18
+ * without redefining any variable themselves.
17
19
  */
18
20
 
19
21
  @theme inline {
22
+ --font-sans: var(--sans);
23
+ --font-mono: var(--mono);
24
+
20
25
  --color-background: var(--background);
21
26
  --color-foreground: var(--foreground);
22
27
  --color-card: var(--card);
@@ -34,14 +39,14 @@
34
39
  --color-input: var(--input);
35
40
  --color-ring: var(--ring);
36
41
 
37
- --radius-xs: calc(var(--radius) * 0.5);
38
- --radius-sm: calc(var(--radius) * 0.625);
39
- --radius-md: calc(var(--radius) * 0.75);
40
- --radius-lg: calc(var(--radius) * 0.875);
41
- --radius-xl: var(--radius);
42
- --radius-2xl: calc(var(--radius) * 1.25);
43
- --radius-3xl: calc(var(--radius) * 1.5);
44
- --radius-4xl: calc(var(--radius) * 2);
42
+ --radius-xs: calc(var(--radius) * 0.4);
43
+ --radius-sm: calc(var(--radius) * 0.6);
44
+ --radius-md: calc(var(--radius) * 0.8);
45
+ --radius-lg: var(--radius);
46
+ --radius-xl: calc(var(--radius) * 1.4);
47
+ --radius-2xl: calc(var(--radius) * 1.8);
48
+ --radius-3xl: calc(var(--radius) * 2.4);
49
+ --radius-4xl: calc(var(--radius) * 2.8);
45
50
 
46
51
  --shadow-xs:
47
52
  0px 0px 0px 1px rgba(0, 0, 0, 0.06), 0px 1px 2px -1px rgba(0, 0, 0, 0.06),