moi-computer 0.0.3 → 0.1.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.
Files changed (216) hide show
  1. package/README.md +2 -2
  2. package/bunfig.toml +4 -0
  3. package/client/api/workspaces.ts +277 -6
  4. package/client/assets/mcp/agentation.png +0 -0
  5. package/client/assets/mcp/airtable.png +0 -0
  6. package/client/assets/mcp/apollo.png +0 -0
  7. package/client/assets/mcp/asana.png +0 -0
  8. package/client/assets/mcp/box.png +0 -0
  9. package/client/assets/mcp/chrome.svg +33 -0
  10. package/client/assets/mcp/clickup.png +0 -0
  11. package/client/assets/mcp/cloudflare.png +0 -0
  12. package/client/assets/mcp/context7.png +0 -0
  13. package/client/assets/mcp/datadog.png +0 -0
  14. package/client/assets/mcp/dropbox.png +0 -0
  15. package/client/assets/mcp/elevenlabs.png +0 -0
  16. package/client/assets/mcp/exa.png +0 -0
  17. package/client/assets/mcp/firecrawl.png +0 -0
  18. package/client/assets/mcp/gmail.png +0 -0
  19. package/client/assets/mcp/googlecalendar.png +0 -0
  20. package/client/assets/mcp/googledrive.png +0 -0
  21. package/client/assets/mcp/grafana.png +0 -0
  22. package/client/assets/mcp/huggingface.png +0 -0
  23. package/client/assets/mcp/intercom.png +0 -0
  24. package/client/assets/mcp/monday.png +0 -0
  25. package/client/assets/mcp/mongodb.png +0 -0
  26. package/client/assets/mcp/paper.png +0 -0
  27. package/client/assets/mcp/paypal.png +0 -0
  28. package/client/assets/mcp/perplexity.png +0 -0
  29. package/client/assets/mcp/postgresql.png +0 -0
  30. package/client/assets/mcp/posthog.png +0 -0
  31. package/client/assets/mcp/puppeteer.png +0 -0
  32. package/client/assets/mcp/railway.png +0 -0
  33. package/client/assets/mcp/redis.png +0 -0
  34. package/client/assets/mcp/salesforce.png +0 -0
  35. package/client/assets/mcp/shopify.png +0 -0
  36. package/client/assets/mcp/snowflake.png +0 -0
  37. package/client/assets/mcp/telegram.png +0 -0
  38. package/client/assets/mcp/twilio.png +0 -0
  39. package/client/assets/mcp/zapier.png +0 -0
  40. package/client/components/App.tsx +7 -1
  41. package/client/components/ChatInput.tsx +194 -13
  42. package/client/components/ChatPanel.tsx +116 -47
  43. package/client/components/ChatPopup.tsx +1 -1
  44. package/client/components/IconMcp.tsx +21 -0
  45. package/client/components/McpMenu.tsx +125 -0
  46. package/client/components/ModelPicker.tsx +147 -0
  47. package/client/components/Scratchpad.tsx +775 -0
  48. package/client/components/ShimmerText.tsx +20 -0
  49. package/client/components/ThreadSelector.tsx +2 -2
  50. package/client/components/TurnView.tsx +111 -531
  51. package/client/components/WidgetShell.tsx +1 -1
  52. package/client/components/WorkspacesPage.tsx +12 -4
  53. package/client/components/layout/SidebarLayout.tsx +18 -9
  54. package/client/components/playground/ToolCallsPage.tsx +81 -0
  55. package/client/components/routes/workspace/[id].tsx +534 -141
  56. package/client/components/routes/workspace/create.tsx +155 -0
  57. package/client/components/settings/IconPicker.tsx +590 -0
  58. package/client/components/settings/SettingsPages.tsx +307 -0
  59. package/client/components/settings/WorkspaceSettings.tsx +92 -0
  60. package/client/components/tool-group/CodeBlock.tsx +41 -0
  61. package/client/components/tool-group/Collapse.tsx +28 -0
  62. package/client/components/tool-group/ReadImagePreview.tsx +46 -0
  63. package/client/components/tool-group/SubagentCard.tsx +135 -0
  64. package/client/components/tool-group/TimelineRow.tsx +147 -0
  65. package/client/components/tool-group/ToolCallGroup.tsx +231 -0
  66. package/client/components/tool-group/ToolOutput.tsx +139 -0
  67. package/client/components/tool-group/detect.ts +93 -0
  68. package/client/components/tool-group/fixtures.ts +315 -0
  69. package/client/components/tool-group/format.ts +211 -0
  70. package/client/components/tool-group/index.ts +9 -0
  71. package/client/components/ui/dialog.tsx +58 -0
  72. package/client/components/ui/hover-card.tsx +44 -0
  73. package/client/components/ui/switch.tsx +23 -0
  74. package/client/components/ui/tooltip.tsx +54 -0
  75. package/client/externalize-react.ts +6 -0
  76. package/client/hooks/useApplet.ts +117 -0
  77. package/client/hooks/useChat.ts +162 -62
  78. package/client/hooks/useMeiEvents.ts +9 -2
  79. package/client/hooks/useStickToBottom.ts +86 -0
  80. package/client/hooks/useWorkspaceTheme.ts +8 -2
  81. package/client/index.css +48 -2
  82. package/client/index.html +9 -5
  83. package/client/index.tsx +29 -2
  84. package/client/lib/WorkspaceContext.tsx +5 -8
  85. package/client/lib/WorkspaceLayoutContext.tsx +30 -10
  86. package/client/lib/applet-cache.ts +54 -0
  87. package/client/lib/connection.ts +237 -0
  88. package/client/lib/flags.ts +10 -0
  89. package/client/lib/mcp-icons.ts +142 -10
  90. package/client/lib/preview-turn.ts +37 -0
  91. package/client/lib/render-icon.ts +173 -0
  92. package/client/lib/scratch-executor.ts +20 -0
  93. package/client/lib/uploads.ts +18 -0
  94. package/client/main.tsx +5 -0
  95. package/client/store/live.ts +282 -0
  96. package/client/structured-clone-shim.ts +14 -0
  97. package/client/theme.css +2 -2
  98. package/client/vendor/emojibase/en/data.json +1 -0
  99. package/client/vendor/emojibase/en/messages.json +1 -0
  100. package/client/vendor/react/development/_impl/react-dom-client.js +15871 -0
  101. package/client/vendor/react/development/_impl/react-dom.js +223 -0
  102. package/client/vendor/react/development/_impl/react-jsx-dev-runtime.js +256 -0
  103. package/client/vendor/react/development/_impl/react-jsx-runtime.js +260 -0
  104. package/client/vendor/react/development/_impl/react.js +863 -0
  105. package/client/vendor/react/development/react-dom-client.js +6 -0
  106. package/client/vendor/react/development/react-dom.js +17 -0
  107. package/client/vendor/react/development/react-jsx-dev-runtime.js +5 -0
  108. package/client/vendor/react/development/react-jsx-runtime.js +6 -0
  109. package/client/vendor/react/development/react.js +47 -0
  110. package/client/vendor/react/production/_impl/react-dom-client.js +10361 -0
  111. package/client/vendor/react/production/_impl/react-dom.js +184 -0
  112. package/client/vendor/react/production/_impl/react-jsx-dev-runtime.js +37 -0
  113. package/client/vendor/react/production/_impl/react-jsx-runtime.js +60 -0
  114. package/client/vendor/react/production/_impl/react.js +428 -0
  115. package/client/vendor/react/production/react-dom-client.js +6 -0
  116. package/client/vendor/react/production/react-dom.js +17 -0
  117. package/client/vendor/react/production/react-jsx-dev-runtime.js +5 -0
  118. package/client/vendor/react/production/react-jsx-runtime.js +6 -0
  119. package/client/vendor/react/production/react.js +47 -0
  120. package/dist/agentation-4s0nn45p.png +0 -0
  121. package/dist/airtable-hsa66v6q.png +0 -0
  122. package/dist/apollo-2ed5dy2d.png +0 -0
  123. package/dist/asana-tvgtwbx2.png +0 -0
  124. package/dist/box-w3n36t5g.png +0 -0
  125. package/dist/chrome-tspm94rw.svg +33 -0
  126. package/dist/chunk-kc6e9nd4.css +1 -0
  127. package/dist/chunk-yf3p7qg7.js +673 -0
  128. package/dist/clickup-qqrqqvqb.png +0 -0
  129. package/dist/cloudflare-j9p931v6.png +0 -0
  130. package/dist/context7-8ht0xjfy.png +0 -0
  131. package/dist/datadog-70ne3yzt.png +0 -0
  132. package/dist/dropbox-4m5s9mgr.png +0 -0
  133. package/dist/elevenlabs-2nzzej1t.png +0 -0
  134. package/dist/exa-qqj3vr0x.png +0 -0
  135. package/dist/firecrawl-w2t8nehx.png +0 -0
  136. package/dist/gmail-sg6a5v3x.png +0 -0
  137. package/dist/googlecalendar-nqhh2v7r.png +0 -0
  138. package/dist/googledrive-6s8xyab7.png +0 -0
  139. package/dist/grafana-1yfsnwr6.png +0 -0
  140. package/dist/huggingface-kxzaxj83.png +0 -0
  141. package/dist/index.html +10 -6
  142. package/dist/intercom-td763jt8.png +0 -0
  143. package/dist/monday-jdbs4wwf.png +0 -0
  144. package/dist/mongodb-emzxvhd5.png +0 -0
  145. package/dist/paper-zbt34fab.png +0 -0
  146. package/dist/paypal-kwwf7xsc.png +0 -0
  147. package/dist/perplexity-4y63rxvj.png +0 -0
  148. package/dist/postgresql-qsspbsr1.png +0 -0
  149. package/dist/posthog-sphppc4w.png +0 -0
  150. package/dist/puppeteer-2xjt1a9b.png +0 -0
  151. package/dist/railway-834de8d2.png +0 -0
  152. package/dist/redis-spm6w2m1.png +0 -0
  153. package/dist/salesforce-1mk56v4z.png +0 -0
  154. package/dist/shopify-90dadaav.png +0 -0
  155. package/dist/snowflake-hfpykpgy.png +0 -0
  156. package/dist/telegram-v6tjyrs7.png +0 -0
  157. package/dist/twilio-dpyjdwpj.png +0 -0
  158. package/dist/zapier-p67qfch0.png +0 -0
  159. package/lib/attachment-note.ts +48 -0
  160. package/lib/claude-adapter.ts +219 -29
  161. package/lib/format.ts +32 -0
  162. package/lib/types.ts +314 -6
  163. package/package.json +11 -5
  164. package/server/CLAUDE.md +4 -1
  165. package/server/agent.ts +25 -118
  166. package/server/api.ts +593 -0
  167. package/server/applets.ts +396 -0
  168. package/server/build-applet.ts +580 -0
  169. package/server/cc-session.ts +611 -0
  170. package/server/cli-colors.ts +17 -0
  171. package/server/cli-ui.ts +52 -0
  172. package/server/cli.ts +965 -73
  173. package/server/constants.ts +1 -1
  174. package/server/control.ts +166 -19
  175. package/server/debug.ts +10 -0
  176. package/server/events.ts +24 -0
  177. package/server/functions-worker.ts +18 -2
  178. package/server/functions.ts +59 -12
  179. package/server/icon.ts +13 -0
  180. package/server/layout.ts +25 -3
  181. package/server/mcp.ts +125 -0
  182. package/server/moi-scaffold.ts +85 -0
  183. package/server/openclaw-session.ts +41 -10
  184. package/server/openclaw.ts +22 -0
  185. package/server/preview.ts +70 -0
  186. package/server/registry.ts +32 -2
  187. package/server/scratchpad-executor.ts +380 -0
  188. package/server/scratchpad-relay.ts +45 -0
  189. package/server/scratchpad.ts +171 -0
  190. package/server/skill-version.ts +146 -0
  191. package/server/skills-template.ts +6 -1
  192. package/server/state.ts +22 -36
  193. package/server/static.ts +23 -0
  194. package/server/status.ts +94 -0
  195. package/server/thread-config.ts +125 -0
  196. package/server/uploads.ts +0 -0
  197. package/server/vendor.ts +63 -0
  198. package/server/views.ts +0 -0
  199. package/server/web.ts +108 -253
  200. package/server/widgets.ts +52 -142
  201. package/server/workspace-config.ts +37 -0
  202. package/server/workspace-env.ts +407 -0
  203. package/server/workspace-init.ts +66 -0
  204. package/workspace/.claude/skills/moi-workspace/DESIGN.md +109 -0
  205. package/workspace/.claude/skills/moi-workspace/SCRATCHPAD.md +57 -0
  206. package/workspace/.claude/skills/moi-workspace/SKILL.md +252 -0
  207. package/workspace/.claude/skills/moi-workspace/VIEW-DESIGN.md +22 -0
  208. package/client/hooks/useWidget.ts +0 -72
  209. package/client/hooks/useWidgetList.ts +0 -30
  210. package/client/lib/ws.ts +0 -129
  211. package/client/store/chat.tsx +0 -162
  212. package/dist/chunk-4615fa69.js +0 -67
  213. package/dist/chunk-582xmy05.css +0 -1
  214. package/server/build-widget.ts +0 -343
  215. package/workspace/.claude/skills/widgets/DESIGN.md +0 -630
  216. package/workspace/.claude/skills/widgets/SKILL.md +0 -176
@@ -0,0 +1,590 @@
1
+ import { useRef, useState } from 'react'
2
+
3
+ import type { Icon } from '@tabler/icons-react'
4
+ import {
5
+ IconActivity,
6
+ IconApi,
7
+ IconArrowsShuffle,
8
+ IconAtom,
9
+ IconBell,
10
+ IconBolt,
11
+ IconBook,
12
+ IconBrain,
13
+ IconBriefcase,
14
+ IconBug,
15
+ IconBulb,
16
+ IconCalendar,
17
+ IconCamera,
18
+ IconChartBar,
19
+ IconCheck,
20
+ IconChefHat,
21
+ IconCircleOff,
22
+ IconCloud,
23
+ IconCode,
24
+ IconCompass,
25
+ IconCpu,
26
+ IconCube,
27
+ IconDatabase,
28
+ IconDeviceGamepad2,
29
+ IconDiamond,
30
+ IconFeather,
31
+ IconFile,
32
+ IconFlame,
33
+ IconFlask,
34
+ IconFolder,
35
+ IconGhost,
36
+ IconGift,
37
+ IconGlobe,
38
+ IconHeart,
39
+ IconHexagon,
40
+ IconHome,
41
+ IconKey,
42
+ IconLeaf,
43
+ IconLoader2,
44
+ IconMail,
45
+ IconMap,
46
+ IconMessage,
47
+ IconMoodSad,
48
+ IconMoon,
49
+ IconMountain,
50
+ IconMusic,
51
+ IconPalette,
52
+ IconPaperclip,
53
+ IconPhoto,
54
+ IconPlanet,
55
+ IconPlug,
56
+ IconRobot,
57
+ IconRocket,
58
+ IconSettings,
59
+ IconShield,
60
+ IconShoppingCart,
61
+ IconSnowflake,
62
+ IconSparkles,
63
+ IconStar,
64
+ IconSun,
65
+ IconTarget,
66
+ IconTerminal2,
67
+ IconTool,
68
+ IconTrophy,
69
+ IconUpload,
70
+ IconUser,
71
+ IconWand,
72
+ IconWorld
73
+ } from '@tabler/icons-react'
74
+ import {
75
+ EmojiPicker,
76
+ type EmojiPickerListCategoryHeaderProps,
77
+ type EmojiPickerListEmojiProps,
78
+ type EmojiPickerListRowProps
79
+ } from 'frimousse'
80
+
81
+ import { useResetWorkspaceIcon, useSaveWorkspaceIcon } from '@/client/api/workspaces'
82
+ import { PROVIDER_ICON } from '@/client/components/layout/SidebarLayout'
83
+ import { Button } from '@/client/components/ui/button'
84
+ import { useWorkspaceLayoutCtx } from '@/client/lib/WorkspaceLayoutContext'
85
+ import { cn } from '@/client/lib/cn'
86
+ import {
87
+ GRADIENT_PRESETS,
88
+ type IconGradient,
89
+ gradientCss,
90
+ randomGradient,
91
+ renderEmojiIcon,
92
+ renderGlyphIcon
93
+ } from '@/client/lib/render-icon'
94
+
95
+ type Mode = 'emoji' | 'icon' | 'upload'
96
+
97
+ // A curated set of the 64 most common Tabler glyphs — enough variety to brand a
98
+ // workspace without a search box. `id` keys selection; `Icon` renders the glyph.
99
+ const ICON_CHOICES: { id: string; Icon: Icon }[] = [
100
+ { id: 'rocket', Icon: IconRocket },
101
+ { id: 'sparkles', Icon: IconSparkles },
102
+ { id: 'bolt', Icon: IconBolt },
103
+ { id: 'flame', Icon: IconFlame },
104
+ { id: 'star', Icon: IconStar },
105
+ { id: 'heart', Icon: IconHeart },
106
+ { id: 'diamond', Icon: IconDiamond },
107
+ { id: 'trophy', Icon: IconTrophy },
108
+ { id: 'target', Icon: IconTarget },
109
+ { id: 'bulb', Icon: IconBulb },
110
+ { id: 'brain', Icon: IconBrain },
111
+ { id: 'robot', Icon: IconRobot },
112
+ { id: 'wand', Icon: IconWand },
113
+ { id: 'atom', Icon: IconAtom },
114
+ { id: 'flask', Icon: IconFlask },
115
+ { id: 'cpu', Icon: IconCpu },
116
+ { id: 'code', Icon: IconCode },
117
+ { id: 'terminal', Icon: IconTerminal2 },
118
+ { id: 'api', Icon: IconApi },
119
+ { id: 'database', Icon: IconDatabase },
120
+ { id: 'cube', Icon: IconCube },
121
+ { id: 'hexagon', Icon: IconHexagon },
122
+ { id: 'plug', Icon: IconPlug },
123
+ { id: 'tool', Icon: IconTool },
124
+ { id: 'settings', Icon: IconSettings },
125
+ { id: 'bug', Icon: IconBug },
126
+ { id: 'activity', Icon: IconActivity },
127
+ { id: 'chart', Icon: IconChartBar },
128
+ { id: 'briefcase', Icon: IconBriefcase },
129
+ { id: 'folder', Icon: IconFolder },
130
+ { id: 'file', Icon: IconFile },
131
+ { id: 'book', Icon: IconBook },
132
+ { id: 'message', Icon: IconMessage },
133
+ { id: 'mail', Icon: IconMail },
134
+ { id: 'bell', Icon: IconBell },
135
+ { id: 'paperclip', Icon: IconPaperclip },
136
+ { id: 'key', Icon: IconKey },
137
+ { id: 'shield', Icon: IconShield },
138
+ { id: 'user', Icon: IconUser },
139
+ { id: 'home', Icon: IconHome },
140
+ { id: 'globe', Icon: IconGlobe },
141
+ { id: 'world', Icon: IconWorld },
142
+ { id: 'planet', Icon: IconPlanet },
143
+ { id: 'compass', Icon: IconCompass },
144
+ { id: 'map', Icon: IconMap },
145
+ { id: 'calendar', Icon: IconCalendar },
146
+ { id: 'cloud', Icon: IconCloud },
147
+ { id: 'sun', Icon: IconSun },
148
+ { id: 'moon', Icon: IconMoon },
149
+ { id: 'snowflake', Icon: IconSnowflake },
150
+ { id: 'leaf', Icon: IconLeaf },
151
+ { id: 'mountain', Icon: IconMountain },
152
+ { id: 'feather', Icon: IconFeather },
153
+ { id: 'ghost', Icon: IconGhost },
154
+ { id: 'music', Icon: IconMusic },
155
+ { id: 'camera', Icon: IconCamera },
156
+ { id: 'photo', Icon: IconPhoto },
157
+ { id: 'palette', Icon: IconPalette },
158
+ { id: 'gamepad', Icon: IconDeviceGamepad2 },
159
+ { id: 'gift', Icon: IconGift },
160
+ { id: 'cart', Icon: IconShoppingCart },
161
+ { id: 'chef', Icon: IconChefHat }
162
+ ]
163
+
164
+ // The staged background: a preset id (or 'shuffle'), and its gradient — null
165
+ // means transparent. Only the rasterized result is persisted, so this state
166
+ // lives and dies with the dialog.
167
+ type IconBg = { id: string; gradient: IconGradient | null }
168
+
169
+ // Force a color-emoji font: the default UI stack can fall back to monochrome
170
+ // outline glyphs (notably on Linux), while the canvas rasterizer already pins
171
+ // these families — this keeps the DOM preview true to the saved icon.
172
+ const EMOJI_FONT = 'font-[Apple_Color_Emoji,Segoe_UI_Emoji,Noto_Color_Emoji,sans-serif]'
173
+
174
+ // Hand-picked workspace-flavored emoji pinned above the full list — the full
175
+ // emojibase catalog opens with smileys, which are rarely what a project icon
176
+ // wants. Two rows of 13, matching the picker's column count.
177
+ const FAVORITE_EMOJI = [
178
+ '🚀',
179
+ '✨',
180
+ '🔥',
181
+ '⚡',
182
+ '💡',
183
+ '🧠',
184
+ '🤖',
185
+ '🪄',
186
+ '🧪',
187
+ '⚙️',
188
+ '🛠️',
189
+ '💻',
190
+ '📦',
191
+ '📊',
192
+ '📈',
193
+ '📝',
194
+ '📚',
195
+ '🎯',
196
+ '🏆',
197
+ '💎',
198
+ '🪐',
199
+ '🌍',
200
+ '🧭',
201
+ '🎨',
202
+ '🎮',
203
+ '☕'
204
+ ]
205
+
206
+ // ── Frimousse list parts (module-level so the virtualized list keeps stable
207
+ // component identities across re-renders) ───────────────────────────────────
208
+
209
+ function EmojiCategoryHeader({ category, ...props }: EmojiPickerListCategoryHeaderProps) {
210
+ return (
211
+ <div
212
+ className="bg-background px-2.5 pt-2.5 pb-1 text-xs font-medium text-muted-foreground"
213
+ {...props}
214
+ >
215
+ {category.label}
216
+ </div>
217
+ )
218
+ }
219
+
220
+ function EmojiRow({ children, ...props }: EmojiPickerListRowProps) {
221
+ return (
222
+ <div className="scroll-my-1 px-1.5" {...props}>
223
+ {children}
224
+ </div>
225
+ )
226
+ }
227
+
228
+ function EmojiButton({ emoji, ...props }: EmojiPickerListEmojiProps) {
229
+ return (
230
+ <button
231
+ className={cn(
232
+ 'flex size-9 items-center justify-center rounded-lg text-[22px] transition-colors duration-75 data-[active]:bg-muted',
233
+ EMOJI_FONT
234
+ )}
235
+ {...props}
236
+ >
237
+ {emoji.emoji}
238
+ </button>
239
+ )
240
+ }
241
+
242
+ type IconPickerProps = {
243
+ // The currently-saved icon data URL, or null to show the provider default.
244
+ icon: string | null
245
+ }
246
+
247
+ export function IconPicker({ icon }: IconPickerProps) {
248
+ const { workspaceId, provider } = useWorkspaceLayoutCtx()
249
+ const saveIcon = useSaveWorkspaceIcon(workspaceId)
250
+ const resetIcon = useResetWorkspaceIcon(workspaceId)
251
+
252
+ const [mode, setMode] = useState<Mode>('emoji')
253
+ const [bg, setBg] = useState<IconBg>({ id: 'sunrise', gradient: GRADIENT_PRESETS[0].gradient })
254
+ // The last shuffled gradient sticks around as its own swatch, so switching to
255
+ // a preset and back doesn't lose a roll you liked.
256
+ const [shuffled, setShuffled] = useState<IconGradient | null>(null)
257
+ const [emoji, setEmoji] = useState<string | null>(null)
258
+ // Mirrors the emoji search input so the pinned favorites hide while the list
259
+ // is showing filtered results.
260
+ const [emojiSearch, setEmojiSearch] = useState('')
261
+ const [iconId, setIconId] = useState<string | null>(null)
262
+ const [uploadPreview, setUploadPreview] = useState<string | null>(null)
263
+ const [dragOver, setDragOver] = useState(false)
264
+ const [error, setError] = useState<string | null>(null)
265
+
266
+ const fileRef = useRef<HTMLInputElement>(null)
267
+ const glyphRef = useRef<HTMLSpanElement>(null)
268
+ const uploadBlob = useRef<Blob | null>(null)
269
+
270
+ const selectedIcon = ICON_CHOICES.find(c => c.id === iconId)
271
+ const onGradient = bg.gradient !== null
272
+
273
+ // Whether the current tab has a selection ready to apply.
274
+ const hasSelection =
275
+ (mode === 'emoji' && !!emoji) ||
276
+ (mode === 'icon' && !!selectedIcon) ||
277
+ (mode === 'upload' && !!uploadBlob.current)
278
+
279
+ const saving = saveIcon.isPending || resetIcon.isPending
280
+
281
+ const shuffle = () => {
282
+ const gradient = randomGradient()
283
+ setShuffled(gradient)
284
+ setBg({ id: 'shuffle', gradient })
285
+ }
286
+
287
+ const onFile = (file: File) => {
288
+ setError(null)
289
+ uploadBlob.current = file
290
+ setMode('upload')
291
+ setUploadPreview(prev => {
292
+ if (prev) URL.revokeObjectURL(prev)
293
+ return URL.createObjectURL(file)
294
+ })
295
+ }
296
+
297
+ const apply = async () => {
298
+ setError(null)
299
+ try {
300
+ let blob: Blob
301
+ if (mode === 'upload') {
302
+ if (!uploadBlob.current) return
303
+ blob = uploadBlob.current
304
+ } else if (mode === 'emoji') {
305
+ if (!emoji) return
306
+ blob = await renderEmojiIcon(emoji, bg.gradient)
307
+ } else {
308
+ const svg = glyphRef.current?.querySelector('svg')
309
+ if (!svg) return
310
+ blob = await renderGlyphIcon(new XMLSerializer().serializeToString(svg), bg.gradient)
311
+ }
312
+ await saveIcon.mutateAsync(blob)
313
+ } catch (err) {
314
+ setError(err instanceof Error ? err.message : 'Failed to save icon')
315
+ }
316
+ }
317
+
318
+ // The live preview reflects the pending selection, falling back to the saved
319
+ // icon (or provider default) when nothing is staged on the current tab.
320
+ const previewKind: 'emoji' | 'glyph' | 'image' =
321
+ mode === 'emoji' && emoji ? 'emoji' : mode === 'icon' && selectedIcon ? 'glyph' : 'image'
322
+ const previewImage =
323
+ mode === 'upload' && uploadPreview
324
+ ? uploadPreview
325
+ : (icon ?? PROVIDER_ICON[provider ?? 'claude-code'])
326
+
327
+ return (
328
+ <div className="flex gap-6">
329
+ {/* Live preview */}
330
+ <div className="flex w-24 shrink-0 flex-col items-center gap-2.5">
331
+ <div
332
+ className={cn(
333
+ 'flex size-24 items-center justify-center overflow-hidden rounded-[24px] shadow-sm ring-1 ring-foreground/10',
334
+ // Checkerboard hints at transparency when no background is chosen.
335
+ previewKind !== 'image' &&
336
+ !onGradient &&
337
+ 'bg-[repeating-conic-gradient(#0000000d_0%_25%,transparent_0%_50%)] bg-[length:16px_16px]'
338
+ )}
339
+ // Gradient colors are generated at runtime (shuffle), so they can't be
340
+ // static Tailwind classes — set the composed background inline.
341
+ style={
342
+ previewKind !== 'image' && bg.gradient
343
+ ? { background: gradientCss(bg.gradient) }
344
+ : undefined
345
+ }
346
+ >
347
+ {previewKind === 'emoji' ? (
348
+ <span
349
+ className={cn('leading-none', EMOJI_FONT, onGradient ? 'text-[64px]' : 'text-[86px]')}
350
+ >
351
+ {emoji}
352
+ </span>
353
+ ) : previewKind === 'glyph' && selectedIcon ? (
354
+ <selectedIcon.Icon
355
+ stroke={1.75}
356
+ className={cn(onGradient ? 'size-14 text-white' : 'size-18 text-foreground')}
357
+ />
358
+ ) : (
359
+ <img src={previewImage} alt="" className="size-full object-cover" />
360
+ )}
361
+ </div>
362
+ <button
363
+ type="button"
364
+ onClick={() => resetIcon.mutate()}
365
+ disabled={saving}
366
+ className="text-xs text-muted-foreground transition-colors hover:text-foreground disabled:opacity-50"
367
+ >
368
+ Reset to default
369
+ </button>
370
+ </div>
371
+
372
+ {/* Controls */}
373
+ <div className="flex min-w-0 flex-1 flex-col gap-3">
374
+ {/* Mode tabs */}
375
+ <div className="flex gap-1 self-start rounded-lg bg-muted p-0.5">
376
+ {(['emoji', 'icon', 'upload'] as const).map(m => (
377
+ <button
378
+ key={m}
379
+ type="button"
380
+ onClick={() => setMode(m)}
381
+ className={cn(
382
+ 'rounded-md px-3.5 py-1 text-xs font-medium capitalize transition-colors',
383
+ mode === m
384
+ ? 'bg-background text-foreground shadow-sm'
385
+ : 'text-muted-foreground hover:text-foreground'
386
+ )}
387
+ >
388
+ {m}
389
+ </button>
390
+ ))}
391
+ </div>
392
+
393
+ {/* Background swatches — disabled (not hidden) on the upload tab so the
394
+ layout doesn't jump between tabs. */}
395
+ <div
396
+ className={cn(
397
+ 'flex items-center gap-2',
398
+ mode === 'upload' && 'pointer-events-none opacity-35'
399
+ )}
400
+ >
401
+ <span className="text-xs font-medium text-muted-foreground">Background</span>
402
+ <div className="flex items-center gap-2">
403
+ <button
404
+ type="button"
405
+ aria-label="No background"
406
+ onClick={() => setBg({ id: 'none', gradient: null })}
407
+ className={cn(
408
+ 'flex size-7 items-center justify-center rounded-full bg-muted ring-offset-2 ring-offset-card transition-shadow',
409
+ bg.id === 'none'
410
+ ? 'ring-2 ring-primary'
411
+ : 'ring-1 ring-border hover:ring-foreground/30'
412
+ )}
413
+ >
414
+ <IconCircleOff size={14} stroke={1.75} className="text-muted-foreground" />
415
+ </button>
416
+ {GRADIENT_PRESETS.map(preset => (
417
+ <button
418
+ key={preset.id}
419
+ type="button"
420
+ aria-label={`${preset.id} background`}
421
+ onClick={() => setBg({ id: preset.id, gradient: preset.gradient })}
422
+ // Preset colors live in data (shared with the canvas), so the
423
+ // swatch fill is inline rather than a per-preset class.
424
+ style={{ background: gradientCss(preset.gradient) }}
425
+ className={cn(
426
+ 'size-7 rounded-full ring-offset-2 ring-offset-card transition-shadow',
427
+ bg.id === preset.id
428
+ ? 'ring-2 ring-primary'
429
+ : 'hover:ring-2 hover:ring-foreground/25'
430
+ )}
431
+ />
432
+ ))}
433
+ <button
434
+ type="button"
435
+ aria-label="Random background"
436
+ title="Surprise me"
437
+ onClick={shuffle}
438
+ style={shuffled ? { background: gradientCss(shuffled) } : undefined}
439
+ className={cn(
440
+ 'flex size-7 items-center justify-center rounded-full ring-offset-2 ring-offset-card transition-shadow',
441
+ shuffled ? 'text-white' : 'bg-muted text-muted-foreground ring-1 ring-border',
442
+ bg.id === 'shuffle'
443
+ ? 'ring-2 ring-primary'
444
+ : 'hover:ring-2 hover:ring-foreground/25'
445
+ )}
446
+ >
447
+ <IconArrowsShuffle size={14} stroke={2} />
448
+ </button>
449
+ </div>
450
+ </div>
451
+
452
+ {/* Picker body — fixed height across tabs so the dialog never jumps. */}
453
+ {mode === 'emoji' ? (
454
+ <EmojiPicker.Root
455
+ onEmojiSelect={picked => setEmoji(picked.emoji)}
456
+ // Same-origin emojibase data (vendored under client/vendor/emojibase,
457
+ // served by server/vendor.ts) — the picker works fully offline.
458
+ emojibaseUrl="/vendor/emojibase"
459
+ columns={13}
460
+ className="isolate flex h-72 flex-col overflow-hidden rounded-lg border border-border bg-background"
461
+ >
462
+ <div className="flex items-center gap-1.5 p-1.5 pb-0">
463
+ <EmojiPicker.Search
464
+ placeholder="Search emoji…"
465
+ onChange={e => setEmojiSearch(e.target.value)}
466
+ className="h-8 min-w-0 flex-1 appearance-none rounded-md bg-muted px-2.5 text-sm outline-none placeholder:text-muted-foreground"
467
+ />
468
+ <EmojiPicker.SkinToneSelector className="size-8 shrink-0 rounded-md text-lg hover:bg-muted" />
469
+ </div>
470
+ <EmojiPicker.Viewport className="relative scrollbar-thin flex-1 overflow-y-auto outline-none">
471
+ <EmojiPicker.Loading className="absolute inset-0 flex items-center justify-center gap-2 text-xs text-muted-foreground">
472
+ <IconLoader2 size={16} stroke={1.75} className="animate-spin" />
473
+ Loading emoji…
474
+ </EmojiPicker.Loading>
475
+ {/* Pinned workspace favorites — rendered inside the scroll area so
476
+ they read as the first category; hidden while searching so
477
+ results stay on top. */}
478
+ {emojiSearch.trim() === '' && (
479
+ <div className="border-b border-dashed border-border pb-1.5">
480
+ <p className="px-2.5 pt-2.5 pb-1 text-xs font-medium text-muted-foreground">
481
+ Favorites
482
+ </p>
483
+ {/* Fixed 13 columns to mirror the frimousse rows below — the
484
+ 26 favorites always land as two clean rows. */}
485
+ <div className="grid grid-cols-13 justify-items-start px-1.5">
486
+ {FAVORITE_EMOJI.map(e => (
487
+ <button
488
+ key={e}
489
+ type="button"
490
+ onClick={() => setEmoji(e)}
491
+ className={cn(
492
+ 'flex size-9 items-center justify-center rounded-lg text-[22px] transition-colors duration-75',
493
+ EMOJI_FONT,
494
+ emoji === e ? 'bg-primary/10' : 'hover:bg-muted'
495
+ )}
496
+ >
497
+ {e}
498
+ </button>
499
+ ))}
500
+ </div>
501
+ </div>
502
+ )}
503
+ <EmojiPicker.Empty className="absolute inset-0 flex flex-col items-center justify-center gap-1 text-xs text-muted-foreground">
504
+ <IconMoodSad size={20} stroke={1.5} />
505
+ No emoji found
506
+ </EmojiPicker.Empty>
507
+ <EmojiPicker.List
508
+ className="pb-1.5 select-none"
509
+ components={{
510
+ CategoryHeader: EmojiCategoryHeader,
511
+ Row: EmojiRow,
512
+ Emoji: EmojiButton
513
+ }}
514
+ />
515
+ </EmojiPicker.Viewport>
516
+ </EmojiPicker.Root>
517
+ ) : mode === 'icon' ? (
518
+ <div className="grid scrollbar-thin h-72 grid-cols-[repeat(auto-fill,minmax(2.25rem,1fr))] content-start gap-1 overflow-y-auto rounded-lg border border-border bg-background p-1.5">
519
+ {ICON_CHOICES.map(({ id, Icon }) => (
520
+ <button
521
+ key={id}
522
+ type="button"
523
+ aria-label={id}
524
+ onClick={() => setIconId(id)}
525
+ className={cn(
526
+ 'flex aspect-square items-center justify-center rounded-lg text-muted-foreground transition-colors [&_svg]:size-5',
527
+ iconId === id
528
+ ? 'bg-primary/10 text-primary'
529
+ : 'hover:bg-muted hover:text-foreground'
530
+ )}
531
+ >
532
+ <Icon stroke={1.75} />
533
+ </button>
534
+ ))}
535
+ </div>
536
+ ) : (
537
+ <button
538
+ type="button"
539
+ onClick={() => fileRef.current?.click()}
540
+ onDragOver={e => {
541
+ e.preventDefault()
542
+ setDragOver(true)
543
+ }}
544
+ onDragLeave={() => setDragOver(false)}
545
+ onDrop={e => {
546
+ e.preventDefault()
547
+ setDragOver(false)
548
+ const file = e.dataTransfer.files?.[0]
549
+ if (file) onFile(file)
550
+ }}
551
+ className={cn(
552
+ 'flex h-72 flex-col items-center justify-center gap-2 rounded-lg border border-dashed transition-colors',
553
+ dragOver
554
+ ? 'border-primary bg-primary/5 text-primary'
555
+ : 'border-border text-muted-foreground hover:border-foreground/30 hover:text-foreground'
556
+ )}
557
+ >
558
+ <IconUpload size={22} stroke={1.5} />
559
+ <span className="text-xs font-medium">Click or drop an image</span>
560
+ <span className="text-[11px] text-muted-foreground/70">PNG, JPG, GIF, or WebP</span>
561
+ </button>
562
+ )}
563
+
564
+ <div className="flex items-center justify-between gap-3">
565
+ <p className={cn('text-xs text-destructive', !error && 'invisible')}>{error}</p>
566
+ <Button size="sm" onClick={apply} disabled={!hasSelection || saving}>
567
+ {saving ? <IconLoader2 className="animate-spin" /> : <IconCheck stroke={1.75} />}
568
+ Apply icon
569
+ </Button>
570
+ </div>
571
+ </div>
572
+
573
+ {/* Hidden file input + hidden glyph render used for rasterization. */}
574
+ <input
575
+ ref={fileRef}
576
+ type="file"
577
+ accept="image/png,image/jpeg,image/gif,image/webp"
578
+ className="hidden"
579
+ onChange={e => {
580
+ const file = e.target.files?.[0]
581
+ if (file) onFile(file)
582
+ e.target.value = ''
583
+ }}
584
+ />
585
+ <span ref={glyphRef} aria-hidden className="hidden">
586
+ {selectedIcon && <selectedIcon.Icon stroke={1.75} />}
587
+ </span>
588
+ </div>
589
+ )
590
+ }