moi-computer 0.0.3 → 0.1.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/bunfig.toml +4 -0
- package/client/api/workspaces.ts +277 -6
- package/client/assets/mcp/agentation.png +0 -0
- package/client/assets/mcp/airtable.png +0 -0
- package/client/assets/mcp/apollo.png +0 -0
- package/client/assets/mcp/asana.png +0 -0
- package/client/assets/mcp/box.png +0 -0
- package/client/assets/mcp/chrome.svg +33 -0
- package/client/assets/mcp/clickup.png +0 -0
- package/client/assets/mcp/cloudflare.png +0 -0
- package/client/assets/mcp/context7.png +0 -0
- package/client/assets/mcp/datadog.png +0 -0
- package/client/assets/mcp/dropbox.png +0 -0
- package/client/assets/mcp/elevenlabs.png +0 -0
- package/client/assets/mcp/exa.png +0 -0
- package/client/assets/mcp/firecrawl.png +0 -0
- package/client/assets/mcp/gmail.png +0 -0
- package/client/assets/mcp/googlecalendar.png +0 -0
- package/client/assets/mcp/googledrive.png +0 -0
- package/client/assets/mcp/grafana.png +0 -0
- package/client/assets/mcp/huggingface.png +0 -0
- package/client/assets/mcp/intercom.png +0 -0
- package/client/assets/mcp/monday.png +0 -0
- package/client/assets/mcp/mongodb.png +0 -0
- package/client/assets/mcp/paper.png +0 -0
- package/client/assets/mcp/paypal.png +0 -0
- package/client/assets/mcp/perplexity.png +0 -0
- package/client/assets/mcp/postgresql.png +0 -0
- package/client/assets/mcp/posthog.png +0 -0
- package/client/assets/mcp/puppeteer.png +0 -0
- package/client/assets/mcp/railway.png +0 -0
- package/client/assets/mcp/redis.png +0 -0
- package/client/assets/mcp/salesforce.png +0 -0
- package/client/assets/mcp/shopify.png +0 -0
- package/client/assets/mcp/snowflake.png +0 -0
- package/client/assets/mcp/telegram.png +0 -0
- package/client/assets/mcp/twilio.png +0 -0
- package/client/assets/mcp/zapier.png +0 -0
- package/client/components/App.tsx +7 -1
- package/client/components/ChatInput.tsx +194 -13
- package/client/components/ChatPanel.tsx +116 -47
- package/client/components/ChatPopup.tsx +1 -1
- package/client/components/IconMcp.tsx +21 -0
- package/client/components/McpMenu.tsx +125 -0
- package/client/components/ModelPicker.tsx +147 -0
- package/client/components/Scratchpad.tsx +775 -0
- package/client/components/ShimmerText.tsx +20 -0
- package/client/components/ThreadSelector.tsx +2 -2
- package/client/components/TurnView.tsx +111 -531
- package/client/components/WidgetShell.tsx +1 -1
- package/client/components/WorkspacesPage.tsx +12 -4
- package/client/components/layout/SidebarLayout.tsx +18 -9
- package/client/components/playground/ToolCallsPage.tsx +81 -0
- package/client/components/routes/workspace/[id].tsx +534 -141
- package/client/components/routes/workspace/create.tsx +155 -0
- package/client/components/settings/IconPicker.tsx +590 -0
- package/client/components/settings/SettingsPages.tsx +307 -0
- package/client/components/settings/WorkspaceSettings.tsx +92 -0
- package/client/components/tool-group/CodeBlock.tsx +41 -0
- package/client/components/tool-group/Collapse.tsx +28 -0
- package/client/components/tool-group/ReadImagePreview.tsx +46 -0
- package/client/components/tool-group/SubagentCard.tsx +135 -0
- package/client/components/tool-group/TimelineRow.tsx +147 -0
- package/client/components/tool-group/ToolCallGroup.tsx +231 -0
- package/client/components/tool-group/ToolOutput.tsx +139 -0
- package/client/components/tool-group/detect.ts +93 -0
- package/client/components/tool-group/fixtures.ts +315 -0
- package/client/components/tool-group/format.ts +211 -0
- package/client/components/tool-group/index.ts +9 -0
- package/client/components/ui/dialog.tsx +58 -0
- package/client/components/ui/hover-card.tsx +44 -0
- package/client/components/ui/switch.tsx +23 -0
- package/client/components/ui/tooltip.tsx +54 -0
- package/client/externalize-react.ts +6 -0
- package/client/hooks/useApplet.ts +117 -0
- package/client/hooks/useChat.ts +162 -62
- package/client/hooks/useMeiEvents.ts +9 -2
- package/client/hooks/useStickToBottom.ts +86 -0
- package/client/hooks/useWorkspaceTheme.ts +8 -2
- package/client/index.css +48 -2
- package/client/index.html +9 -5
- package/client/index.tsx +29 -2
- package/client/lib/WorkspaceContext.tsx +5 -8
- package/client/lib/WorkspaceLayoutContext.tsx +30 -10
- package/client/lib/applet-cache.ts +54 -0
- package/client/lib/connection.ts +237 -0
- package/client/lib/flags.ts +10 -0
- package/client/lib/mcp-icons.ts +142 -10
- package/client/lib/preview-turn.ts +37 -0
- package/client/lib/render-icon.ts +173 -0
- package/client/lib/scratch-executor.ts +20 -0
- package/client/lib/uploads.ts +18 -0
- package/client/main.tsx +5 -0
- package/client/store/live.ts +282 -0
- package/client/structured-clone-shim.ts +14 -0
- package/client/theme.css +2 -2
- package/client/vendor/emojibase/en/data.json +1 -0
- package/client/vendor/emojibase/en/messages.json +1 -0
- package/client/vendor/react/development/_impl/react-dom-client.js +15871 -0
- package/client/vendor/react/development/_impl/react-dom.js +223 -0
- package/client/vendor/react/development/_impl/react-jsx-dev-runtime.js +256 -0
- package/client/vendor/react/development/_impl/react-jsx-runtime.js +260 -0
- package/client/vendor/react/development/_impl/react.js +863 -0
- package/client/vendor/react/development/react-dom-client.js +6 -0
- package/client/vendor/react/development/react-dom.js +17 -0
- package/client/vendor/react/development/react-jsx-dev-runtime.js +5 -0
- package/client/vendor/react/development/react-jsx-runtime.js +6 -0
- package/client/vendor/react/development/react.js +47 -0
- package/client/vendor/react/production/_impl/react-dom-client.js +10361 -0
- package/client/vendor/react/production/_impl/react-dom.js +184 -0
- package/client/vendor/react/production/_impl/react-jsx-dev-runtime.js +37 -0
- package/client/vendor/react/production/_impl/react-jsx-runtime.js +60 -0
- package/client/vendor/react/production/_impl/react.js +428 -0
- package/client/vendor/react/production/react-dom-client.js +6 -0
- package/client/vendor/react/production/react-dom.js +17 -0
- package/client/vendor/react/production/react-jsx-dev-runtime.js +5 -0
- package/client/vendor/react/production/react-jsx-runtime.js +6 -0
- package/client/vendor/react/production/react.js +47 -0
- package/dist/agentation-4s0nn45p.png +0 -0
- package/dist/airtable-hsa66v6q.png +0 -0
- package/dist/apollo-2ed5dy2d.png +0 -0
- package/dist/asana-tvgtwbx2.png +0 -0
- package/dist/box-w3n36t5g.png +0 -0
- package/dist/chrome-tspm94rw.svg +33 -0
- package/dist/chunk-kc6e9nd4.css +1 -0
- package/dist/chunk-yf3p7qg7.js +673 -0
- package/dist/clickup-qqrqqvqb.png +0 -0
- package/dist/cloudflare-j9p931v6.png +0 -0
- package/dist/context7-8ht0xjfy.png +0 -0
- package/dist/datadog-70ne3yzt.png +0 -0
- package/dist/dropbox-4m5s9mgr.png +0 -0
- package/dist/elevenlabs-2nzzej1t.png +0 -0
- package/dist/exa-qqj3vr0x.png +0 -0
- package/dist/firecrawl-w2t8nehx.png +0 -0
- package/dist/gmail-sg6a5v3x.png +0 -0
- package/dist/googlecalendar-nqhh2v7r.png +0 -0
- package/dist/googledrive-6s8xyab7.png +0 -0
- package/dist/grafana-1yfsnwr6.png +0 -0
- package/dist/huggingface-kxzaxj83.png +0 -0
- package/dist/index.html +10 -6
- package/dist/intercom-td763jt8.png +0 -0
- package/dist/monday-jdbs4wwf.png +0 -0
- package/dist/mongodb-emzxvhd5.png +0 -0
- package/dist/paper-zbt34fab.png +0 -0
- package/dist/paypal-kwwf7xsc.png +0 -0
- package/dist/perplexity-4y63rxvj.png +0 -0
- package/dist/postgresql-qsspbsr1.png +0 -0
- package/dist/posthog-sphppc4w.png +0 -0
- package/dist/puppeteer-2xjt1a9b.png +0 -0
- package/dist/railway-834de8d2.png +0 -0
- package/dist/redis-spm6w2m1.png +0 -0
- package/dist/salesforce-1mk56v4z.png +0 -0
- package/dist/shopify-90dadaav.png +0 -0
- package/dist/snowflake-hfpykpgy.png +0 -0
- package/dist/telegram-v6tjyrs7.png +0 -0
- package/dist/twilio-dpyjdwpj.png +0 -0
- package/dist/zapier-p67qfch0.png +0 -0
- package/lib/attachment-note.ts +48 -0
- package/lib/claude-adapter.ts +219 -29
- package/lib/format.ts +32 -0
- package/lib/types.ts +314 -6
- package/package.json +10 -5
- package/server/CLAUDE.md +3 -0
- package/server/agent.ts +25 -118
- package/server/api.ts +593 -0
- package/server/applets.ts +396 -0
- package/server/build-applet.ts +580 -0
- package/server/cc-session.ts +611 -0
- package/server/cli-colors.ts +17 -0
- package/server/cli-ui.ts +52 -0
- package/server/cli.ts +964 -72
- package/server/control.ts +166 -19
- package/server/debug.ts +10 -0
- package/server/events.ts +24 -0
- package/server/functions-worker.ts +18 -2
- package/server/functions.ts +59 -12
- package/server/icon.ts +13 -0
- package/server/layout.ts +25 -3
- package/server/mcp.ts +125 -0
- package/server/moi-scaffold.ts +85 -0
- package/server/openclaw-session.ts +41 -10
- package/server/openclaw.ts +22 -0
- package/server/preview.ts +70 -0
- package/server/registry.ts +32 -2
- package/server/scratchpad-executor.ts +380 -0
- package/server/scratchpad-relay.ts +45 -0
- package/server/scratchpad.ts +171 -0
- package/server/skill-version.ts +146 -0
- package/server/skills-template.ts +6 -1
- package/server/state.ts +22 -36
- package/server/static.ts +23 -0
- package/server/status.ts +94 -0
- package/server/thread-config.ts +125 -0
- package/server/uploads.ts +0 -0
- package/server/vendor.ts +63 -0
- package/server/views.ts +0 -0
- package/server/web.ts +108 -253
- package/server/widgets.ts +52 -142
- package/server/workspace-config.ts +37 -0
- package/server/workspace-env.ts +407 -0
- package/server/workspace-init.ts +66 -0
- package/workspace/.claude/skills/moi-workspace/DESIGN.md +109 -0
- package/workspace/.claude/skills/moi-workspace/SCRATCHPAD.md +57 -0
- package/workspace/.claude/skills/moi-workspace/SKILL.md +252 -0
- package/workspace/.claude/skills/moi-workspace/VIEW-DESIGN.md +22 -0
- package/client/hooks/useWidget.ts +0 -72
- package/client/hooks/useWidgetList.ts +0 -30
- package/client/lib/ws.ts +0 -129
- package/client/store/chat.tsx +0 -162
- package/dist/chunk-4615fa69.js +0 -67
- package/dist/chunk-582xmy05.css +0 -1
- package/server/build-widget.ts +0 -343
- package/workspace/.claude/skills/widgets/DESIGN.md +0 -630
- package/workspace/.claude/skills/widgets/SKILL.md +0 -176
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { useStore } from 'zustand'
|
|
2
|
+
import { createStore } from 'zustand/vanilla'
|
|
3
|
+
|
|
4
|
+
import type { PreviewBlock, PreviewFrame, UploadInfo } from '@/lib/types'
|
|
5
|
+
|
|
6
|
+
// One composer attachment, tracked per thread until the message is sent. It is
|
|
7
|
+
// uploaded as soon as it's added (drop/paste/pick); `status` reflects that
|
|
8
|
+
// in-flight upload, and `upload` holds the server handle once ready. `previewUrl`
|
|
9
|
+
// is a local object URL for image thumbnails (revoked on remove/clear).
|
|
10
|
+
export type ChatAttachment = {
|
|
11
|
+
localId: string
|
|
12
|
+
name: string
|
|
13
|
+
mediaType: string
|
|
14
|
+
previewUrl?: string
|
|
15
|
+
status: 'uploading' | 'ready' | 'error'
|
|
16
|
+
upload?: UploadInfo
|
|
17
|
+
error?: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// App-level ephemeral chat state — the bits that are *pushed* from the server
|
|
21
|
+
// over the WebSocket and can't be re-fetched as request/response data:
|
|
22
|
+
// - which thread is active per workspace (a UI selection),
|
|
23
|
+
// - per-session `processing` (spinner) flags,
|
|
24
|
+
// - per-session error banners.
|
|
25
|
+
//
|
|
26
|
+
// The durable message transcripts live in the React Query cache (see
|
|
27
|
+
// useSessionView), which is also app-level — so nothing here needs to mirror
|
|
28
|
+
// them. This is a single module-singleton store (not React-context scoped), so
|
|
29
|
+
// it survives route navigation: leaving and re-entering a workspace keeps the
|
|
30
|
+
// active thread and any in-flight spinner intact.
|
|
31
|
+
//
|
|
32
|
+
// Per-session entries are keyed `${workspaceId}:${sessionId}`.
|
|
33
|
+
|
|
34
|
+
function key(workspaceId: string, sessionId: string): string {
|
|
35
|
+
return `${workspaceId}:${sessionId}`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Draft text is keyed per thread. A brand-new chat has no session id yet, so it
|
|
39
|
+
// gets a stable `'new'` sentinel; once `send` mints the real id the input reads
|
|
40
|
+
// the (empty) draft under the new key. Exported so `ChatInput` builds the same
|
|
41
|
+
// key it reads as the store writes.
|
|
42
|
+
export function draftKey(workspaceId: string, sessionId: string | null): string {
|
|
43
|
+
return key(workspaceId, sessionId ?? 'new')
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// A live streaming preview held in the store, keyed by API message id. Ephemeral
|
|
47
|
+
// and disposable — see PreviewFrame. `updatedAt` drives the TTL sweep that reaps
|
|
48
|
+
// any preview a clear signal somehow never reached.
|
|
49
|
+
export type LivePreview = {
|
|
50
|
+
workspaceId: string
|
|
51
|
+
sessionId: string
|
|
52
|
+
parentToolUseId: string | null
|
|
53
|
+
blocks: PreviewBlock[]
|
|
54
|
+
updatedAt: number
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type LiveStore = {
|
|
58
|
+
activeByWorkspace: Record<string, string | null>
|
|
59
|
+
processing: Record<string, boolean>
|
|
60
|
+
errors: Record<string, string | null>
|
|
61
|
+
// Live token-streaming previews, keyed by `messageId` (the API `msg_...` id)
|
|
62
|
+
// so concurrent streams never collide. Reconciled against the durable
|
|
63
|
+
// transcript: a preview is dropped the instant its finalized turn arrives.
|
|
64
|
+
previews: Record<string, LivePreview>
|
|
65
|
+
// Unsent composer text, keyed per thread (`${workspaceId}:${sessionId}`, with
|
|
66
|
+
// a `'new'` sentinel for a not-yet-created thread). Lives here — not in the
|
|
67
|
+
// chat component — so a keystroke re-renders only the composer (which alone
|
|
68
|
+
// subscribes), not the whole workspace, and the draft survives the chat
|
|
69
|
+
// panel's remounts on mode switch.
|
|
70
|
+
drafts: Record<string, string>
|
|
71
|
+
// Composer attachments, keyed per thread exactly like `drafts` (so they follow
|
|
72
|
+
// the active thread and survive composer remounts). Cleared on send.
|
|
73
|
+
attachments: Record<string, ChatAttachment[]>
|
|
74
|
+
|
|
75
|
+
setActive: (workspaceId: string, sessionId: string | null) => void
|
|
76
|
+
setProcessing: (workspaceId: string, sessionId: string, value: boolean) => void
|
|
77
|
+
// Authoritative reconcile from a server `status_snapshot`: exactly the listed
|
|
78
|
+
// sessions are processing; everything else is cleared (fixes a spinner whose
|
|
79
|
+
// terminal status was emitted while we were disconnected).
|
|
80
|
+
reconcileProcessing: (running: { workspaceId: string; sessionId: string }[]) => void
|
|
81
|
+
setError: (workspaceId: string, sessionId: string, message: string | null) => void
|
|
82
|
+
setDraft: (workspaceId: string, sessionId: string | null, value: string) => void
|
|
83
|
+
addAttachments: (workspaceId: string, sessionId: string | null, items: ChatAttachment[]) => void
|
|
84
|
+
updateAttachment: (
|
|
85
|
+
workspaceId: string,
|
|
86
|
+
sessionId: string | null,
|
|
87
|
+
localId: string,
|
|
88
|
+
patch: Partial<ChatAttachment>
|
|
89
|
+
) => void
|
|
90
|
+
removeAttachment: (workspaceId: string, sessionId: string | null, localId: string) => void
|
|
91
|
+
clearAttachments: (workspaceId: string, sessionId: string | null) => void
|
|
92
|
+
renameSession: (workspaceId: string, from: string, to: string) => void
|
|
93
|
+
|
|
94
|
+
// Upsert a preview snapshot (last write wins — blocks are cumulative).
|
|
95
|
+
setPreview: (frame: Omit<PreviewFrame, 'type'>) => void
|
|
96
|
+
// Drop one preview by message id — used the instant its real turn lands.
|
|
97
|
+
clearPreview: (messageId: string) => void
|
|
98
|
+
// Drop every preview for a session — belt for run end / stop / error, where a
|
|
99
|
+
// per-message clear might be missed (e.g. a turn without an apiMessageId).
|
|
100
|
+
clearPreviewsForSession: (workspaceId: string, sessionId: string) => void
|
|
101
|
+
// Drop everything — used on socket reconnect, where any in-flight preview is
|
|
102
|
+
// definitionally superseded by the /events refetch.
|
|
103
|
+
clearAllPreviews: () => void
|
|
104
|
+
// Reap previews older than `maxAgeMs` (TTL backstop against a missed clear).
|
|
105
|
+
sweepPreviews: (maxAgeMs: number, now: number) => void
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export const liveStore = createStore<LiveStore>()(set => ({
|
|
109
|
+
activeByWorkspace: {},
|
|
110
|
+
processing: {},
|
|
111
|
+
errors: {},
|
|
112
|
+
drafts: {},
|
|
113
|
+
previews: {},
|
|
114
|
+
attachments: {},
|
|
115
|
+
|
|
116
|
+
setActive: (workspaceId, sessionId) =>
|
|
117
|
+
set(s => ({ activeByWorkspace: { ...s.activeByWorkspace, [workspaceId]: sessionId } })),
|
|
118
|
+
|
|
119
|
+
setProcessing: (workspaceId, sessionId, value) =>
|
|
120
|
+
set(s => ({ processing: { ...s.processing, [key(workspaceId, sessionId)]: value } })),
|
|
121
|
+
|
|
122
|
+
reconcileProcessing: running =>
|
|
123
|
+
set(() => ({
|
|
124
|
+
processing: Object.fromEntries(running.map(r => [key(r.workspaceId, r.sessionId), true]))
|
|
125
|
+
})),
|
|
126
|
+
|
|
127
|
+
setError: (workspaceId, sessionId, message) =>
|
|
128
|
+
set(s => ({ errors: { ...s.errors, [key(workspaceId, sessionId)]: message } })),
|
|
129
|
+
|
|
130
|
+
setDraft: (workspaceId, sessionId, value) =>
|
|
131
|
+
set(s => ({ drafts: { ...s.drafts, [draftKey(workspaceId, sessionId)]: value } })),
|
|
132
|
+
|
|
133
|
+
setPreview: frame =>
|
|
134
|
+
set(s => ({
|
|
135
|
+
previews: {
|
|
136
|
+
...s.previews,
|
|
137
|
+
[frame.messageId]: {
|
|
138
|
+
workspaceId: frame.workspaceId,
|
|
139
|
+
sessionId: frame.sessionId,
|
|
140
|
+
parentToolUseId: frame.parentToolUseId,
|
|
141
|
+
blocks: frame.blocks,
|
|
142
|
+
updatedAt: Date.now()
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
})),
|
|
146
|
+
|
|
147
|
+
clearPreview: messageId =>
|
|
148
|
+
set(s => {
|
|
149
|
+
if (!(messageId in s.previews)) return s
|
|
150
|
+
const { [messageId]: _drop, ...rest } = s.previews
|
|
151
|
+
return { previews: rest }
|
|
152
|
+
}),
|
|
153
|
+
|
|
154
|
+
clearPreviewsForSession: (workspaceId, sessionId) =>
|
|
155
|
+
set(s => {
|
|
156
|
+
const rest: Record<string, LivePreview> = {}
|
|
157
|
+
let changed = false
|
|
158
|
+
for (const [id, p] of Object.entries(s.previews)) {
|
|
159
|
+
if (p.workspaceId === workspaceId && p.sessionId === sessionId) changed = true
|
|
160
|
+
else rest[id] = p
|
|
161
|
+
}
|
|
162
|
+
return changed ? { previews: rest } : s
|
|
163
|
+
}),
|
|
164
|
+
|
|
165
|
+
clearAllPreviews: () => set(s => (Object.keys(s.previews).length ? { previews: {} } : s)),
|
|
166
|
+
|
|
167
|
+
sweepPreviews: (maxAgeMs, now) =>
|
|
168
|
+
set(s => {
|
|
169
|
+
const rest: Record<string, LivePreview> = {}
|
|
170
|
+
let changed = false
|
|
171
|
+
for (const [id, p] of Object.entries(s.previews)) {
|
|
172
|
+
if (now - p.updatedAt > maxAgeMs) changed = true
|
|
173
|
+
else rest[id] = p
|
|
174
|
+
}
|
|
175
|
+
return changed ? { previews: rest } : s
|
|
176
|
+
}),
|
|
177
|
+
|
|
178
|
+
addAttachments: (workspaceId, sessionId, items) =>
|
|
179
|
+
set(s => {
|
|
180
|
+
const k = draftKey(workspaceId, sessionId)
|
|
181
|
+
return { attachments: { ...s.attachments, [k]: [...(s.attachments[k] ?? []), ...items] } }
|
|
182
|
+
}),
|
|
183
|
+
|
|
184
|
+
updateAttachment: (workspaceId, sessionId, localId, patch) =>
|
|
185
|
+
set(s => {
|
|
186
|
+
const k = draftKey(workspaceId, sessionId)
|
|
187
|
+
const list = s.attachments[k]
|
|
188
|
+
if (!list) return {}
|
|
189
|
+
return {
|
|
190
|
+
attachments: {
|
|
191
|
+
...s.attachments,
|
|
192
|
+
[k]: list.map(a => (a.localId === localId ? { ...a, ...patch } : a))
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}),
|
|
196
|
+
|
|
197
|
+
removeAttachment: (workspaceId, sessionId, localId) =>
|
|
198
|
+
set(s => {
|
|
199
|
+
const k = draftKey(workspaceId, sessionId)
|
|
200
|
+
const list = s.attachments[k]
|
|
201
|
+
if (!list) return {}
|
|
202
|
+
const target = list.find(a => a.localId === localId)
|
|
203
|
+
if (target?.previewUrl) URL.revokeObjectURL(target.previewUrl)
|
|
204
|
+
return { attachments: { ...s.attachments, [k]: list.filter(a => a.localId !== localId) } }
|
|
205
|
+
}),
|
|
206
|
+
|
|
207
|
+
clearAttachments: (workspaceId, sessionId) =>
|
|
208
|
+
set(s => {
|
|
209
|
+
const k = draftKey(workspaceId, sessionId)
|
|
210
|
+
for (const a of s.attachments[k] ?? []) {
|
|
211
|
+
if (a.previewUrl) URL.revokeObjectURL(a.previewUrl)
|
|
212
|
+
}
|
|
213
|
+
const next = { ...s.attachments }
|
|
214
|
+
delete next[k]
|
|
215
|
+
return { attachments: next }
|
|
216
|
+
}),
|
|
217
|
+
|
|
218
|
+
renameSession: (workspaceId, from, to) =>
|
|
219
|
+
set(s => {
|
|
220
|
+
const fromKey = key(workspaceId, from)
|
|
221
|
+
const toKey = key(workspaceId, to)
|
|
222
|
+
const processing = { ...s.processing }
|
|
223
|
+
const errors = { ...s.errors }
|
|
224
|
+
if (fromKey in processing) {
|
|
225
|
+
processing[toKey] = processing[fromKey]
|
|
226
|
+
delete processing[fromKey]
|
|
227
|
+
}
|
|
228
|
+
if (fromKey in errors) {
|
|
229
|
+
errors[toKey] = errors[fromKey]
|
|
230
|
+
delete errors[fromKey]
|
|
231
|
+
}
|
|
232
|
+
const activeByWorkspace =
|
|
233
|
+
s.activeByWorkspace[workspaceId] === from
|
|
234
|
+
? { ...s.activeByWorkspace, [workspaceId]: to }
|
|
235
|
+
: s.activeByWorkspace
|
|
236
|
+
// Retarget any in-flight previews from the temp id to the real one so a
|
|
237
|
+
// preview that arrived before the rename keeps routing to the thread.
|
|
238
|
+
let previews = s.previews
|
|
239
|
+
let previewsChanged = false
|
|
240
|
+
for (const [id, p] of Object.entries(s.previews)) {
|
|
241
|
+
if (p.workspaceId === workspaceId && p.sessionId === from) {
|
|
242
|
+
if (!previewsChanged) {
|
|
243
|
+
previews = { ...s.previews }
|
|
244
|
+
previewsChanged = true
|
|
245
|
+
}
|
|
246
|
+
previews[id] = { ...p, sessionId: to }
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return { processing, errors, activeByWorkspace, previews }
|
|
250
|
+
})
|
|
251
|
+
}))
|
|
252
|
+
|
|
253
|
+
// Select the live previews for a thread, split into the root (top-level
|
|
254
|
+
// assistant) stream and per-subagent streams. Takes the raw `previews` record
|
|
255
|
+
// (a stable store slice) so callers select that slice and run this inside a
|
|
256
|
+
// `useMemo` — never return a fresh object straight from a zustand selector.
|
|
257
|
+
// `null` sessionId yields empties.
|
|
258
|
+
export function selectPreviews(
|
|
259
|
+
previews: Record<string, LivePreview>,
|
|
260
|
+
workspaceId: string,
|
|
261
|
+
sessionId: string | null
|
|
262
|
+
): { root: LivePreview | null; byParent: Record<string, LivePreview> } {
|
|
263
|
+
if (!sessionId) return { root: null, byParent: {} }
|
|
264
|
+
let root: LivePreview | null = null
|
|
265
|
+
const byParent: Record<string, LivePreview> = {}
|
|
266
|
+
for (const p of Object.values(previews)) {
|
|
267
|
+
if (p.workspaceId !== workspaceId || p.sessionId !== sessionId) continue
|
|
268
|
+
if (p.parentToolUseId === null) {
|
|
269
|
+
// At most one root stream is active at a time; keep the freshest.
|
|
270
|
+
if (!root || p.updatedAt > root.updatedAt) root = p
|
|
271
|
+
} else {
|
|
272
|
+
const prev = byParent[p.parentToolUseId]
|
|
273
|
+
if (!prev || p.updatedAt > prev.updatedAt) byParent[p.parentToolUseId] = p
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return { root, byParent }
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Reactive selector hook bound to the singleton store.
|
|
280
|
+
export function useLive<T>(selector: (state: LiveStore) => T): T {
|
|
281
|
+
return useStore(liveStore, selector)
|
|
282
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Re-bind `globalThis.structuredClone` to the global object up front.
|
|
2
|
+
//
|
|
3
|
+
// Bun compiles `import { structuredClone } from '@tldraw/utils'; structuredClone(x)`
|
|
4
|
+
// into a namespace-member call — `utils.structuredClone(x)` — which invokes the
|
|
5
|
+
// native function with `this` set to the module namespace object. V8 brand-checks
|
|
6
|
+
// `structuredClone` against the global and throws "Illegal invocation", crashing
|
|
7
|
+
// tldraw on mount during its user-preferences init. tldraw captures
|
|
8
|
+
// `globalThis.structuredClone` once at module-eval time, so binding it here —
|
|
9
|
+
// imported before any tldraw module loads — makes the receiver irrelevant. Native
|
|
10
|
+
// structuredClone ignores `this` when called correctly, so this is transparent to
|
|
11
|
+
// every other caller.
|
|
12
|
+
if (typeof globalThis.structuredClone === 'function') {
|
|
13
|
+
globalThis.structuredClone = globalThis.structuredClone.bind(globalThis)
|
|
14
|
+
}
|
package/client/theme.css
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Shared design-token map for both the host app (client/index.css) and
|
|
3
|
-
*
|
|
4
|
-
* into the
|
|
3
|
+
* applet bundles (server/build-applet.ts emits an `@import` to this file
|
|
4
|
+
* into the applet's synthetic CSS).
|
|
5
5
|
*
|
|
6
6
|
* The actual CSS variables (`--background`, `--foreground`, `--card`, etc.)
|
|
7
7
|
* are owned by the host and declared on `:root` / `.dark` in
|