moi-computer 0.3.1-next.1 → 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.
- package/README.md +85 -12
- package/bin/moi.mjs +11 -0
- package/client/api/workspace-keys.ts +1 -0
- package/client/app/AppRouter.tsx +5 -1
- package/client/app/routes/WorkspaceRoute.tsx +9 -5
- package/client/app/shell/SidebarLayout.tsx +9 -7
- package/client/components/shared/BottomPanel.tsx +24 -5
- package/client/components/shared/Composer.tsx +1 -1
- package/client/components/shared/PanelHeader.tsx +1 -1
- package/client/components/ui/button.tsx +5 -5
- package/client/components/ui/dropdown-menu.tsx +6 -6
- package/client/components/ui/hover-card.tsx +1 -1
- package/client/components/ui/input.tsx +1 -1
- package/client/components/ui/popover.tsx +1 -1
- package/client/components/ui/skeleton.tsx +1 -1
- package/client/components/ui/textarea.tsx +1 -1
- package/client/components/ui/tooltip.tsx +1 -1
- package/client/features/applets/applet-cache.ts +20 -1
- package/client/features/applets/applet-log.ts +10 -30
- package/client/features/applets/applet-runtime.ts +272 -0
- package/client/features/applets/useApplet.ts +36 -10
- package/client/features/chat/ChatComposer.tsx +1 -1
- package/client/features/chat/ChatEmptyState.tsx +186 -0
- package/client/features/chat/ChatPanel.tsx +95 -54
- package/client/features/chat/ChatPopup.tsx +3 -13
- package/client/features/chat/ChatPromptBubbles.tsx +74 -0
- package/client/features/chat/MarkdownContent.tsx +15 -3
- package/client/features/chat/ModelPicker.tsx +1 -1
- package/client/features/chat/TurnView.tsx +6 -17
- package/client/features/chat/chat-send.ts +26 -1
- package/client/features/chat/tool-group/CodeBlock.tsx +1 -1
- package/client/features/chat/tool-group/ReadImagePreview.tsx +1 -1
- package/client/features/chat/tool-group/SubagentCard.tsx +1 -1
- package/client/features/chat/tool-group/TimelineRow.tsx +4 -4
- package/client/features/chat/tool-group/ToolCallGroup.tsx +12 -5
- package/client/features/chat/tool-group/ToolOutput.tsx +2 -2
- package/client/features/chat/tool-group/format.ts +25 -4
- package/client/features/chat/useAppletChatMessage.ts +69 -0
- package/client/features/chat/useChat.ts +49 -14
- package/client/features/chat/useStickToBottom.ts +11 -1
- package/client/features/connectors/McpServerCards.tsx +3 -3
- package/client/features/dev/HarnessDebugPage.tsx +213 -77
- package/client/features/dev/PixelPainter.tsx +1 -1
- package/client/features/dev/PlaygroundPage.tsx +1 -1
- package/client/features/dev/ToolCallsPage.tsx +2 -2
- package/client/features/home/HomePage.tsx +17 -14
- package/client/features/home/WorkspacePreview.tsx +12 -13
- package/client/features/home/api.ts +8 -5
- package/client/features/home/workspace-presentation.tsx +1 -1
- package/client/features/home/workspace-setup/CreateWorkspaceDialog.tsx +1 -1
- package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +21 -8
- package/client/features/scratchpad/Scratchpad.tsx +41 -2
- package/client/features/scratchpad/ScratchpadControls.tsx +13 -13
- package/client/features/scratchpad/useScratchpadSnapshot.tsx +1 -1
- package/client/features/settings/EnvironmentSettings.tsx +1 -1
- package/client/features/settings/IconPicker.tsx +11 -11
- package/client/features/settings/SettingsLayout.tsx +1 -1
- package/client/features/settings/WorkspaceSettings.tsx +2 -2
- package/client/features/settings/api.ts +33 -1
- package/client/features/widgets/HiddenPanel.tsx +4 -3
- package/client/features/widgets/Widgets.tsx +1 -0
- package/client/features/workspace/CustomizePanel.tsx +96 -82
- package/client/features/workspace/WorkspaceScreen.tsx +129 -107
- package/client/features/workspace/WorkspaceSkillUpdateBanner.tsx +91 -0
- package/client/features/workspace/WorkspaceTabs.tsx +1 -1
- package/client/features/workspace/api.ts +52 -0
- package/client/features/workspace/moi-context.ts +63 -17
- package/client/features/workspace/tab-resolution.ts +75 -0
- package/client/features/workspace/useWorkspaceNavigation.ts +128 -0
- package/client/features/workspace/useWorkspaceSkillUpdates.ts +160 -0
- package/client/index.css +10 -15
- package/client/lib/app-icon-registry.ts +77 -70
- package/client/lib/rate-limit.ts +77 -0
- package/client/main.tsx +10 -2
- package/client/runtime/useWorkspaceEvents.ts +15 -2
- package/client/runtime/workspace-theme.ts +115 -0
- package/client/store/ui.ts +42 -17
- package/client/theme.css +20 -15
- package/dist/{chunk-1dfbr7n2.js → chunk-3m1xe1j3.js} +94 -94
- package/dist/chunk-5vaevt8z.js +2 -0
- package/dist/chunk-7bzpmtxp.js +50 -0
- package/dist/chunk-h0hk61pm.js +9 -0
- package/dist/{chunk-vkvb3hjm.js → chunk-h3evrtyp.js} +1 -1
- package/dist/chunk-k5sjx9s5.js +1 -0
- package/dist/{chunk-jen6xcm1.js → chunk-m9qja0nx.js} +1 -1
- package/dist/chunk-s7za1qsv.css +1 -0
- package/dist/{chunk-sxbfh73c.js → chunk-tcfa3vt3.js} +1 -1
- package/dist/chunk-v797g6ap.js +51 -0
- package/dist/chunk-xyrw8318.js +27 -0
- package/dist/index.html +1 -1
- package/lib/app-icons.ts +73 -0
- package/lib/moi-context.ts +104 -3
- package/lib/themes.ts +83 -45
- package/lib/types.ts +44 -9
- package/lib/workspace-tabs.ts +48 -0
- package/package.json +4 -1
- package/server/api.ts +57 -5
- package/server/app-settings.ts +65 -0
- package/server/applets.ts +132 -22
- package/server/bundler/build-applet.ts +74 -16
- package/server/cli.ts +144 -17
- package/server/control.ts +53 -7
- package/server/data-dir.ts +1 -1
- package/server/events.ts +1 -1
- package/server/functions-worker.ts +15 -1
- package/server/functions.ts +51 -6
- package/server/harness/claude-code/index.ts +2 -1
- package/server/harness/codex/adapter.ts +100 -9
- package/server/harness/codex/client.ts +34 -1
- package/server/harness/codex/index.ts +2 -1
- package/server/harness/codex/session.ts +32 -8
- package/server/layout.ts +9 -14
- package/server/moi-scaffold.ts +37 -3
- package/server/registry.ts +1 -1
- package/server/skill-update.ts +47 -0
- package/server/skill-version.ts +2 -11
- package/server/tabs.ts +59 -0
- package/server/theme.ts +8 -14
- package/server/view-builders.ts +6 -2
- package/workspace/.claude/skills/moi-workspace/DESIGN.md +265 -107
- package/workspace/.claude/skills/moi-workspace/SKILL.md +85 -11
- package/client/features/workspace/useWorkspaceTheme.ts +0 -82
- package/dist/chunk-339jds4x.js +0 -15
- package/dist/chunk-3xsvsnhr.css +0 -1
- package/dist/chunk-6c8cwpzc.js +0 -1
- package/dist/chunk-anqmsbjt.js +0 -2
- package/dist/chunk-hbvfb6sk.js +0 -63
- package/dist/chunk-qwm5f6qk.js +0 -48
- package/dist/chunk-yp4srgqt.js +0 -10
- 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:
|
|
71
|
+
id: AppIconId
|
|
69
72
|
Icon: TablerIcon
|
|
70
73
|
}
|
|
71
74
|
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
|
143
|
+
export const APP_ICON_CHOICES: AppIconChoice[] = APP_ICON_IDS.map(id => ({
|
|
144
|
+
id,
|
|
145
|
+
Icon: appIconById[id]
|
|
146
|
+
}))
|
|
140
147
|
|
|
141
|
-
|
|
148
|
+
export { APP_ICON_IDS }
|
|
142
149
|
|
|
143
150
|
export function resolveAppIcon(id: string | undefined): TablerIcon | null {
|
|
144
|
-
return id
|
|
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
|
+
}
|
package/client/main.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
2
2
|
import { Agentation } from 'agentation'
|
|
3
3
|
import { createRoot } from 'react-dom/client'
|
|
4
|
-
import { Router } from 'wouter'
|
|
4
|
+
import { Router, useRoute } from 'wouter'
|
|
5
5
|
|
|
6
6
|
import { TooltipProvider } from '@/client/components/ui/tooltip'
|
|
7
7
|
import { installAppletErrorHook } from '@/client/features/applets/applet-log'
|
|
@@ -10,6 +10,14 @@ import { AppRouter } from './app/AppRouter'
|
|
|
10
10
|
|
|
11
11
|
const queryClient = new QueryClient()
|
|
12
12
|
|
|
13
|
+
// Agentation has no built-in route filter (checked v2.3.3 props), so gate the
|
|
14
|
+
// mount ourselves: the harness debug page is a raw log surface where the
|
|
15
|
+
// annotation toolbar just overlaps the panes.
|
|
16
|
+
function DevAgentation() {
|
|
17
|
+
const [onHarnessDebug] = useRoute('/dev/harness')
|
|
18
|
+
return onHarnessDebug ? null : <Agentation />
|
|
19
|
+
}
|
|
20
|
+
|
|
13
21
|
// Open the single app-wide chat WebSocket once and hand it the query client so
|
|
14
22
|
// live frames fold into the RQ transcript cache. Lives for the page's lifetime.
|
|
15
23
|
initConnection(queryClient)
|
|
@@ -27,7 +35,7 @@ export function mount(el: HTMLElement) {
|
|
|
27
35
|
<Router>
|
|
28
36
|
<AppRouter />
|
|
29
37
|
</Router>
|
|
30
|
-
{process.env.NODE_ENV === 'development' && <
|
|
38
|
+
{process.env.NODE_ENV === 'development' && <DevAgentation />}
|
|
31
39
|
</TooltipProvider>
|
|
32
40
|
</QueryClientProvider>
|
|
33
41
|
)
|
|
@@ -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
|
-
|
|
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
|
+
}
|
package/client/store/ui.ts
CHANGED
|
@@ -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
|
-
//
|
|
5
|
-
// survive reloads. Server-owned
|
|
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
|
-
|
|
10
|
-
|
|
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
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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 (`--
|
|
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 `--
|
|
9
|
-
* `--radius-*` tokens onto those host-owned variables via
|
|
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
|
|
13
|
+
* - does NOT emit `--font-sans`, `--color-background`, or their source
|
|
14
|
+
* variables into the output
|
|
13
15
|
*
|
|
14
|
-
* Net effect:
|
|
15
|
-
* `rounded-xl`,
|
|
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.
|
|
38
|
-
--radius-sm: calc(var(--radius) * 0.
|
|
39
|
-
--radius-md: calc(var(--radius) * 0.
|
|
40
|
-
--radius-lg:
|
|
41
|
-
--radius-xl: var(--radius);
|
|
42
|
-
--radius-2xl: calc(var(--radius) * 1.
|
|
43
|
-
--radius-3xl: calc(var(--radius) *
|
|
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),
|