moi-computer 0.1.4 → 0.3.0-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 +26 -52
- package/client/api/workspaces.ts +3 -5
- package/client/components/Scratchpad.tsx +169 -9
- package/client/components/layout/SidebarLayout.tsx +1 -12
- package/client/components/settings/SettingsPages.tsx +8 -60
- package/client/components/tool-group/fixtures.ts +60 -66
- package/client/hooks/useEnvVars.ts +20 -0
- package/client/hooks/useMeiEvents.ts +2 -0
- package/dist/chunk-07qf2tv1.css +1 -0
- package/dist/chunk-c3zjp9ez.js +672 -0
- package/dist/index.html +1 -1
- package/lib/scratchpad-skew.ts +64 -0
- package/lib/types.ts +5 -7
- package/package.json +3 -3
- package/server/api.ts +53 -54
- package/server/cc-session.ts +1 -1
- package/server/cli-colors.ts +6 -3
- package/server/cli-env.ts +237 -0
- package/server/cli-pc.ts +20 -0
- package/server/cli.ts +182 -3
- package/server/control.ts +11 -0
- package/server/data-dir.ts +9 -0
- package/server/env-apply.ts +16 -0
- package/server/functions-worker.ts +2 -0
- package/server/functions.ts +101 -3
- package/server/registry.ts +1 -2
- package/server/required-env.ts +19 -0
- package/server/scratchpad-assets.ts +223 -0
- package/server/scratchpad-executor.ts +88 -23
- package/server/scratchpad.ts +110 -20
- package/server/status.ts +54 -3
- package/server/thread-config.ts +2 -3
- package/server/vendor.ts +15 -8
- package/server/workspace-env.ts +69 -80
- package/workspace/.claude/skills/moi-workspace/SCRATCHPAD.md +5 -3
- package/workspace/.claude/skills/moi-workspace/SKILL.md +40 -6
- package/dist/chunk-kc6e9nd4.css +0 -1
- package/dist/chunk-yf3p7qg7.js +0 -673
- /package/client/{CLAUDE.md → AGENTS.md} +0 -0
- /package/server/{CLAUDE.md → AGENTS.md} +0 -0
package/README.md
CHANGED
|
@@ -1,71 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
> **Requires [Bun](https://bun.sh).** moi is Bun-only — it uses `Bun.serve`, the
|
|
8
|
-
> Bun bundler, and other Bun APIs. Running it under Node prints an install hint
|
|
9
|
-
> and exits.
|
|
1
|
+
```
|
|
2
|
+
██████████ ██████ ██
|
|
3
|
+
██░░██░░██ ██░░██ ██
|
|
4
|
+
██░░██░░██ ██████ ██
|
|
5
|
+
```
|
|
10
6
|
|
|
11
|
-
|
|
7
|
+
A local workspace where AI agents build their own UI.
|
|
8
|
+
See [moi.computer](https://moi.computer) for what it is and how it works.
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
`moi` from your workspaces, so this is the recommended setup:
|
|
10
|
+
Needs [Bun](https://bun.sh). The npm package is `moi-computer`, the command is `moi`:
|
|
15
11
|
|
|
16
12
|
```sh
|
|
17
13
|
bun i -g moi-computer
|
|
18
|
-
moi start
|
|
14
|
+
moi start # http://localhost:13337
|
|
19
15
|
```
|
|
20
16
|
|
|
21
|
-
|
|
17
|
+
Or paste this into Claude Code and it will set everything up for you:
|
|
22
18
|
|
|
23
|
-
```sh
|
|
24
|
-
curl -fsSL https://bun.sh/install | bash
|
|
25
19
|
```
|
|
26
|
-
|
|
27
|
-
You can also run it once without installing:
|
|
28
|
-
|
|
29
|
-
```sh
|
|
30
|
-
bunx moi-computer init [dir]
|
|
20
|
+
Set up the moi workspace for this project. Fetch https://moi.computer/CC-INSTALL.md, and follow the steps.
|
|
31
21
|
```
|
|
32
22
|
|
|
33
|
-
|
|
34
|
-
it prints a reminder to install globally.
|
|
35
|
-
|
|
36
|
-
## Usage
|
|
37
|
-
|
|
38
|
-
Initialize a workspace directory:
|
|
23
|
+
Hacking on it:
|
|
39
24
|
|
|
40
25
|
```sh
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
Start the web server:
|
|
46
|
-
|
|
47
|
-
```sh
|
|
48
|
-
moi start # http://localhost:13337
|
|
49
|
-
moi start --port=4000 # custom port
|
|
26
|
+
bun install
|
|
27
|
+
bun run dev
|
|
50
28
|
```
|
|
51
29
|
|
|
52
|
-
|
|
30
|
+
## OpenClaw (experimental)
|
|
53
31
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
moi theme [dir] # show or set font/color themes (--font=<key> --color=<key>)
|
|
58
|
-
moi status # show server status and registered workspaces
|
|
59
|
-
moi openclaw init # install moi skills into an OpenClaw agent workspace
|
|
60
|
-
```
|
|
32
|
+
moi also works with OpenClaw agents — `moi openclaw init` installs the moi
|
|
33
|
+
skills into an OpenClaw agent workspace. Integration notes live in
|
|
34
|
+
[docs/OPENCLAW.md](docs/OPENCLAW.md).
|
|
61
35
|
|
|
62
|
-
##
|
|
36
|
+
## No crypto token
|
|
63
37
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
38
|
+
moi has **no** cryptocurrency, token, coin, or NFT — official or otherwise —
|
|
39
|
+
on any chain, and never will. Any token using the moi name, logo, or the
|
|
40
|
+
maintainer's name (on pump.fun, Solana, or anywhere else) is an unauthorized
|
|
41
|
+
scam with no affiliation to, endorsement from, or benefit to this project.
|
|
42
|
+
The maintainer will never announce, endorse, or accept proceeds from a token.
|
|
43
|
+
Don't buy it, and report it to the platform where it's listed.
|
|
68
44
|
|
|
69
|
-
|
|
70
|
-
full-restarts the server on changes to `server/` or `lib/`. Do not run the
|
|
71
|
-
server with `bun --hot` — see `CLAUDE.md` for why.
|
|
45
|
+
License: [Elastic 2.0](LICENSE).
|
package/client/api/workspaces.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
|
3
3
|
import { applyEvents } from '@/lib/format'
|
|
4
4
|
import type {
|
|
5
5
|
DiscoveredWorkspace,
|
|
6
|
-
EnvScope,
|
|
7
6
|
McpServer,
|
|
8
7
|
SessionInfo,
|
|
9
8
|
StreamEvent,
|
|
@@ -242,7 +241,7 @@ export function useSaveLayout(workspaceId: string) {
|
|
|
242
241
|
})
|
|
243
242
|
}
|
|
244
243
|
|
|
245
|
-
// A workspace's effective env view (masked values +
|
|
244
|
+
// A workspace's effective env view (masked values + discovered `.env`).
|
|
246
245
|
export function useWorkspaceEnv(workspaceId: string) {
|
|
247
246
|
return useQuery<WorkspaceEnvView>({
|
|
248
247
|
queryKey: workspaceKeys.env(workspaceId),
|
|
@@ -251,12 +250,11 @@ export function useWorkspaceEnv(workspaceId: string) {
|
|
|
251
250
|
})
|
|
252
251
|
}
|
|
253
252
|
|
|
254
|
-
// Patch of a workspace's env: set/remove custom secrets,
|
|
255
|
-
//
|
|
253
|
+
// Patch of a workspace's env: set/remove custom secrets, or toggle `.env`
|
|
254
|
+
// inheritance. The PUT returns the fresh view (see useUpdateEnv).
|
|
256
255
|
export type EnvPatch = {
|
|
257
256
|
set?: Record<string, string>
|
|
258
257
|
remove?: string[]
|
|
259
|
-
scopes?: Record<string, EnvScope>
|
|
260
258
|
inheritDotenv?: boolean
|
|
261
259
|
}
|
|
262
260
|
|
|
@@ -3,12 +3,14 @@ import { Fragment, type ReactElement, useCallback, useEffect, useRef, useState }
|
|
|
3
3
|
import {
|
|
4
4
|
type Editor,
|
|
5
5
|
type StyleProp,
|
|
6
|
+
type TLAssetStore,
|
|
6
7
|
type TLComponents,
|
|
7
8
|
type TLDefaultColorStyle,
|
|
8
9
|
type TLDefaultDashStyle,
|
|
9
10
|
type TLDefaultFillStyle,
|
|
10
11
|
type TLDefaultSizeStyle,
|
|
11
12
|
type TLEditorSnapshot,
|
|
13
|
+
type TLStore,
|
|
12
14
|
type TLUiOverrides,
|
|
13
15
|
DefaultColorStyle,
|
|
14
16
|
DefaultDashStyle,
|
|
@@ -19,6 +21,9 @@ import {
|
|
|
19
21
|
DefaultVerticalAlignStyle,
|
|
20
22
|
GeoShapeGeoStyle,
|
|
21
23
|
Tldraw,
|
|
24
|
+
createTLStore,
|
|
25
|
+
defaultBindingUtils,
|
|
26
|
+
defaultShapeUtils,
|
|
22
27
|
getSnapshot,
|
|
23
28
|
loadSnapshot,
|
|
24
29
|
react
|
|
@@ -35,14 +40,16 @@ import {
|
|
|
35
40
|
IconSketching,
|
|
36
41
|
IconSquare,
|
|
37
42
|
IconSticker2,
|
|
38
|
-
IconTypography
|
|
43
|
+
IconTypography,
|
|
44
|
+
IconVersions
|
|
39
45
|
} from '@tabler/icons-react'
|
|
40
46
|
|
|
41
47
|
import { cn } from '@/client/lib/cn'
|
|
42
48
|
import { useWorkspaceId } from '@/client/lib/WorkspaceContext'
|
|
43
49
|
import { setScratchExecutor } from '@/client/lib/scratch-executor'
|
|
44
50
|
import { type MeiEvent, useMeiEvent } from '@/client/hooks/useMeiEvents'
|
|
45
|
-
import
|
|
51
|
+
import { describeNewerWriter, sequencesAhead } from '@/lib/scratchpad-skew'
|
|
52
|
+
import type { ScratchOp, ScratchOpResult, ScratchpadWriter } from '@/lib/types'
|
|
46
53
|
|
|
47
54
|
// Identifies this tab's writes so it can ignore the `scratchpad:updated` echo of
|
|
48
55
|
// its own save (see the MEI reload below). Per page load.
|
|
@@ -79,6 +86,34 @@ function makeExecutor(editor: Editor) {
|
|
|
79
86
|
}
|
|
80
87
|
}
|
|
81
88
|
|
|
89
|
+
// File-backed assets: without this, tldraw inlines every pasted/dropped image as
|
|
90
|
+
// a base64 data URL inside the document — megabytes re-serialized into
|
|
91
|
+
// `.moi/.scratchpad.json` on every autosave and shipped over every GET/PUT.
|
|
92
|
+
// Instead `upload` POSTs the bytes once and stores a tiny `asset:<file>` src on
|
|
93
|
+
// the record; `resolve` maps it back to the serving URL at render time. Legacy
|
|
94
|
+
// snapshots still holding data URLs pass through `resolve` untouched (the
|
|
95
|
+
// server extracts them to files on the next save). See server/scratchpad-assets.ts.
|
|
96
|
+
function makeAssetStore(workspaceId: string): TLAssetStore {
|
|
97
|
+
const base = `/api/workspaces/${workspaceId}/scratchpad/assets`
|
|
98
|
+
return {
|
|
99
|
+
async upload(_asset, file) {
|
|
100
|
+
const res = await fetch(base, {
|
|
101
|
+
method: 'POST',
|
|
102
|
+
headers: { 'Content-Type': file.type || 'application/octet-stream' },
|
|
103
|
+
body: file
|
|
104
|
+
})
|
|
105
|
+
if (!res.ok) throw new Error(`Upload failed: ${await res.text()}`)
|
|
106
|
+
const { src } = (await res.json()) as { src: string }
|
|
107
|
+
return { src }
|
|
108
|
+
},
|
|
109
|
+
resolve(asset) {
|
|
110
|
+
const src = asset.props.src
|
|
111
|
+
if (src?.startsWith('asset:')) return `${base}/${src.slice('asset:'.length)}`
|
|
112
|
+
return src
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
82
117
|
// --- Scratchpad UI shell --------------------------------------------------
|
|
83
118
|
// We replace tldraw's full UI with a curated subset (see docs/moi-scratchpad.md
|
|
84
119
|
// for the prioritization). Backbone v1: a custom vertical tool bar on the left,
|
|
@@ -122,6 +157,15 @@ const SCRATCH_OVERRIDES: TLUiOverrides = {
|
|
|
122
157
|
// One page only — disables the page selector and all multi-page UI.
|
|
123
158
|
const SCRATCH_OPTIONS = { maxPages: 1 }
|
|
124
159
|
|
|
160
|
+
// Browser drag/drop/paste limits (tldraw defaults: reject >10MB, no rescale). We
|
|
161
|
+
// accept larger drops and rescale big images to fit so a phone-sized photo lands
|
|
162
|
+
// as a lightweight asset instead of bloating the snapshot's sidecar files. The
|
|
163
|
+
// size check runs BEFORE the rescale, so a 32MB drop is admitted and then shrunk.
|
|
164
|
+
// (The agent's `moi scratch add image` path has its own presets — see the
|
|
165
|
+
// executor's IMAGE_PRESETS; this only governs what the browser accepts.)
|
|
166
|
+
const MAX_DROP_BYTES = 32 * 1024 * 1024
|
|
167
|
+
const MAX_IMAGE_DIMENSION = 2048
|
|
168
|
+
|
|
125
169
|
type IconC = typeof IconPointer2
|
|
126
170
|
|
|
127
171
|
// The curated left-bar entries, grouped by `sep` dividers. `tool` selects a
|
|
@@ -595,28 +639,86 @@ function ScratchStyleBar({ editor }: ScratchStyleBarProps) {
|
|
|
595
639
|
)
|
|
596
640
|
}
|
|
597
641
|
|
|
642
|
+
// --- Version-skew pre-flight ------------------------------------------------
|
|
643
|
+
// tldraw snapshots migrate forward only: a canvas saved by a newer tldraw can
|
|
644
|
+
// never load here, and handing it to <Tldraw> anyway lands on tldraw's crash
|
|
645
|
+
// screen — whose main button is a destructive "Reset data". So every fetched
|
|
646
|
+
// document is pre-flighted against this bundle's schema first; on failure we
|
|
647
|
+
// render a friendly read-only notice and never mount the editor, which is what
|
|
648
|
+
// guarantees this stale client can't autosave over the newer file. See
|
|
649
|
+
// lib/scratchpad-skew.ts and docs/moi-scratchpad.md § Version skew.
|
|
650
|
+
|
|
651
|
+
// What GET /api/workspaces/:id/scratchpad returns (see server/scratchpad.ts).
|
|
652
|
+
type ScratchpadFetch = {
|
|
653
|
+
document: TLEditorSnapshot['document'] | null
|
|
654
|
+
writer?: ScratchpadWriter
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// Why the canvas can't be shown: a newer writer (version skew) or a snapshot
|
|
658
|
+
// that fails to load for some other reason. Either way the file is left alone.
|
|
659
|
+
type ScratchpadSkew = { newer: boolean; writer?: ScratchpadWriter; detail: string }
|
|
660
|
+
|
|
661
|
+
// This bundle's schema, built once and lazily — the same store config the
|
|
662
|
+
// editor and the server executor use, so the pre-flight verdict matches what
|
|
663
|
+
// <Tldraw> would do.
|
|
664
|
+
let runtimeSchemaCache: TLStore['schema'] | null = null
|
|
665
|
+
function runtimeSchema(): TLStore['schema'] {
|
|
666
|
+
if (!runtimeSchemaCache) {
|
|
667
|
+
runtimeSchemaCache = createTLStore({
|
|
668
|
+
shapeUtils: defaultShapeUtils,
|
|
669
|
+
bindingUtils: defaultBindingUtils
|
|
670
|
+
}).schema
|
|
671
|
+
}
|
|
672
|
+
return runtimeSchemaCache
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// Dry-run the migration <Tldraw>/`loadSnapshot` would perform. Returns null when
|
|
676
|
+
// the document is safe to mount, else the skew to display.
|
|
677
|
+
function detectSkew(
|
|
678
|
+
document: NonNullable<TLEditorSnapshot['document']>,
|
|
679
|
+
writer: ScratchpadWriter | undefined
|
|
680
|
+
): ScratchpadSkew | null {
|
|
681
|
+
const schema = runtimeSchema()
|
|
682
|
+
try {
|
|
683
|
+
if (schema.migrateStoreSnapshot(document).type === 'success') return null
|
|
684
|
+
} catch {}
|
|
685
|
+
const ahead = sequencesAhead(document.schema, schema.serialize().sequences)
|
|
686
|
+
if (ahead.length > 0) return { newer: true, writer, detail: describeNewerWriter(writer, ahead) }
|
|
687
|
+
return { newer: false, writer, detail: 'The saved snapshot failed to load.' }
|
|
688
|
+
}
|
|
689
|
+
|
|
598
690
|
// Hydrate the saved canvas once per workspace from the REST snapshot endpoint.
|
|
599
691
|
// Returns a STABLE snapshot reference (held in a ref, never a fresh object per
|
|
600
692
|
// render): tldraw rebuilds its entire store whenever the `snapshot` prop identity
|
|
601
693
|
// changes, so handing it a new object each render loops it forever — remounting the
|
|
602
694
|
// store and re-fetching fonts/translations endlessly. `document: null` → empty
|
|
603
|
-
// canvas; `loaded` gates the placeholder until the fetch settles.
|
|
695
|
+
// canvas; `loaded` gates the placeholder until the fetch settles. A document that
|
|
696
|
+
// fails the pre-flight sets `skew` instead of the snapshot; `flagSkew` lets the
|
|
697
|
+
// remote-reload path flip the same state mid-session.
|
|
604
698
|
function useScratchpadSnapshot(workspaceId: string): {
|
|
605
699
|
loaded: boolean
|
|
606
700
|
snapshot: Partial<TLEditorSnapshot> | undefined
|
|
701
|
+
skew: ScratchpadSkew | null
|
|
702
|
+
flagSkew: (skew: ScratchpadSkew) => void
|
|
607
703
|
} {
|
|
608
704
|
const [loaded, setLoaded] = useState(false)
|
|
705
|
+
const [skew, setSkew] = useState<ScratchpadSkew | null>(null)
|
|
609
706
|
const snapshot = useRef<Partial<TLEditorSnapshot> | undefined>(undefined)
|
|
610
707
|
|
|
611
708
|
useEffect(() => {
|
|
612
709
|
let cancelled = false
|
|
613
710
|
setLoaded(false)
|
|
711
|
+
setSkew(null)
|
|
614
712
|
snapshot.current = undefined
|
|
615
713
|
fetch(`/api/workspaces/${workspaceId}/scratchpad`)
|
|
616
714
|
.then(r => r.json())
|
|
617
|
-
.then((d:
|
|
715
|
+
.then((d: ScratchpadFetch) => {
|
|
618
716
|
if (cancelled) return
|
|
619
|
-
if (d?.document)
|
|
717
|
+
if (d?.document) {
|
|
718
|
+
const found = detectSkew(d.document, d.writer)
|
|
719
|
+
if (found) setSkew(found)
|
|
720
|
+
else snapshot.current = { document: d.document }
|
|
721
|
+
}
|
|
620
722
|
setLoaded(true)
|
|
621
723
|
})
|
|
622
724
|
.catch(() => {
|
|
@@ -627,7 +729,41 @@ function useScratchpadSnapshot(workspaceId: string): {
|
|
|
627
729
|
}
|
|
628
730
|
}, [workspaceId])
|
|
629
731
|
|
|
630
|
-
return { loaded, snapshot: snapshot.current }
|
|
732
|
+
return { loaded, snapshot: snapshot.current, skew, flagSkew: setSkew }
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
type ScratchpadSkewNoticeProps = { skew: ScratchpadSkew }
|
|
736
|
+
|
|
737
|
+
// The read-only stand-in for an unloadable canvas. Deliberately mounts no
|
|
738
|
+
// editor and offers no "load anyway": with no store there is nothing to
|
|
739
|
+
// autosave, so the newer file on disk stays byte-for-byte intact.
|
|
740
|
+
function ScratchpadSkewNotice({ skew }: ScratchpadSkewNoticeProps) {
|
|
741
|
+
return (
|
|
742
|
+
<div className="flex min-h-0 flex-1 items-center justify-center bg-muted/40 bg-[radial-gradient(var(--color-border)_1px,transparent_1px)] [background-size:16px_16px] p-6">
|
|
743
|
+
<div className="flex max-w-md animate-in flex-col gap-3 rounded-md bg-background p-6 shadow-xs duration-200 fade-in-0 zoom-in-95">
|
|
744
|
+
<div className="flex items-center gap-2">
|
|
745
|
+
<IconVersions size={20} stroke={1.5} className="shrink-0 text-amber-600" />
|
|
746
|
+
<h2 className="font-medium text-foreground">
|
|
747
|
+
{skew.newer ? 'This canvas needs a newer moi' : 'This canvas couldn’t be loaded'}
|
|
748
|
+
</h2>
|
|
749
|
+
</div>
|
|
750
|
+
{skew.newer ? (
|
|
751
|
+
<>
|
|
752
|
+
<p className="text-sm text-pretty text-muted-foreground">
|
|
753
|
+
This scratchpad was saved by a newer version of moi
|
|
754
|
+
{skew.writer ? ` (v${skew.writer.moi})` : ''}.<br /> Please update moi and restart the
|
|
755
|
+
server:
|
|
756
|
+
</p>
|
|
757
|
+
<code className="self-start rounded bg-muted px-2 py-1 font-mono text-xs text-foreground">
|
|
758
|
+
bun install -g moi-computer@latest
|
|
759
|
+
</code>
|
|
760
|
+
</>
|
|
761
|
+
) : (
|
|
762
|
+
<p className="text-sm text-muted-foreground">{skew.detail}</p>
|
|
763
|
+
)}
|
|
764
|
+
</div>
|
|
765
|
+
</div>
|
|
766
|
+
)
|
|
631
767
|
}
|
|
632
768
|
|
|
633
769
|
// The Scratchpad surface: a real tldraw editor, hydrated from and autosaved to
|
|
@@ -649,7 +785,15 @@ export function Scratchpad() {
|
|
|
649
785
|
const applyingRemote = useRef(false)
|
|
650
786
|
// Reactive handle to the mounted editor, used to render the custom tool bar.
|
|
651
787
|
const [editor, setEditor] = useState<Editor | null>(null)
|
|
652
|
-
const { loaded, snapshot } = useScratchpadSnapshot(workspaceId)
|
|
788
|
+
const { loaded, snapshot, skew, flagSkew } = useScratchpadSnapshot(workspaceId)
|
|
789
|
+
// Stable identity per workspace, held in a ref rather than useMemo (which React
|
|
790
|
+
// may discard): a fresh `assets` identity makes <Tldraw> rebuild its store and
|
|
791
|
+
// remount the editor, dropping unsaved edits and resetting the camera.
|
|
792
|
+
const assetStoreRef = useRef<{ id: string; store: TLAssetStore } | null>(null)
|
|
793
|
+
if (assetStoreRef.current?.id !== workspaceId) {
|
|
794
|
+
assetStoreRef.current = { id: workspaceId, store: makeAssetStore(workspaceId) }
|
|
795
|
+
}
|
|
796
|
+
const assetStore = assetStoreRef.current.store
|
|
653
797
|
|
|
654
798
|
const save = useCallback(() => {
|
|
655
799
|
const editor = editorRef.current
|
|
@@ -668,16 +812,26 @@ export function Scratchpad() {
|
|
|
668
812
|
}, [workspaceId])
|
|
669
813
|
|
|
670
814
|
// A remote save (another tab, or an agent draw landing in another tab) — pull
|
|
671
|
-
// the new snapshot and load it into the live store. Skip our own echo.
|
|
815
|
+
// the new snapshot and load it into the live store. Skip our own echo. The
|
|
816
|
+
// fetched document is pre-flighted like the initial load: if the server was
|
|
817
|
+
// swapped for a newer moi mid-session, `loadSnapshot` here would throw — flip
|
|
818
|
+
// the skew notice instead (unmounting the editor, which also stops the
|
|
819
|
+
// autosave timer) so this stale tab can't save over the newer file.
|
|
672
820
|
useMeiEvent((e: MeiEvent) => {
|
|
673
821
|
if (e.type !== 'scratchpad:updated' || e.workspaceId !== workspaceId) return
|
|
674
822
|
if (e.origin && e.origin === ORIGIN_ID) return
|
|
675
823
|
if (!editorRef.current) return
|
|
676
824
|
fetch(`/api/workspaces/${workspaceId}/scratchpad`)
|
|
677
825
|
.then(r => r.json())
|
|
678
|
-
.then((d:
|
|
826
|
+
.then((d: ScratchpadFetch) => {
|
|
679
827
|
const editor = editorRef.current
|
|
680
828
|
if (!editor || !d?.document) return
|
|
829
|
+
const found = detectSkew(d.document, d.writer)
|
|
830
|
+
if (found) {
|
|
831
|
+
if (saveTimer.current) clearTimeout(saveTimer.current)
|
|
832
|
+
flagSkew(found)
|
|
833
|
+
return
|
|
834
|
+
}
|
|
681
835
|
applyingRemote.current = true
|
|
682
836
|
loadSnapshot(editor.store, { document: d.document })
|
|
683
837
|
})
|
|
@@ -750,17 +904,23 @@ export function Scratchpad() {
|
|
|
750
904
|
)
|
|
751
905
|
|
|
752
906
|
if (!loaded) return <div className="min-h-0 flex-1 bg-muted/40" />
|
|
907
|
+
if (skew) return <ScratchpadSkewNotice skew={skew} />
|
|
753
908
|
|
|
754
909
|
return (
|
|
755
910
|
<div ref={rootRef} className="relative min-h-0 flex-1 overflow-hidden">
|
|
756
911
|
<div className="absolute inset-0">
|
|
757
912
|
<Tldraw
|
|
758
913
|
snapshot={snapshot}
|
|
914
|
+
assets={assetStore}
|
|
759
915
|
licenseKey={LICENSE_KEY}
|
|
760
916
|
onMount={onMount}
|
|
761
917
|
components={SCRATCH_COMPONENTS}
|
|
762
918
|
overrides={SCRATCH_OVERRIDES}
|
|
763
919
|
options={SCRATCH_OPTIONS}
|
|
920
|
+
// Accept drops up to 32MB and rescale big images to fit (tldraw checks
|
|
921
|
+
// the size before rescaling, so a large photo is admitted then shrunk).
|
|
922
|
+
maxAssetSize={MAX_DROP_BYTES}
|
|
923
|
+
maxImageDimension={MAX_IMAGE_DIMENSION}
|
|
764
924
|
// Hand focus control entirely to us: tldraw's own `autoFocus` only seeds
|
|
765
925
|
// the `isFocused` flag (hotkeys would fire window-wide, even from the
|
|
766
926
|
// chat) without ever DOM-focusing the canvas. Instead onMount focuses
|
|
@@ -7,8 +7,7 @@ import {
|
|
|
7
7
|
IconLayoutSidebar,
|
|
8
8
|
IconLayoutSidebarLeftCollapse,
|
|
9
9
|
IconLayoutSidebarLeftExpand,
|
|
10
|
-
IconPlus
|
|
11
|
-
IconSettings
|
|
10
|
+
IconPlus
|
|
12
11
|
} from '@tabler/icons-react'
|
|
13
12
|
import { useQueryClient } from '@tanstack/react-query'
|
|
14
13
|
import { Link } from 'wouter'
|
|
@@ -216,16 +215,6 @@ function Sidebar({ collapsed, workspaces, logoEffect }: SidebarProps) {
|
|
|
216
215
|
|
|
217
216
|
{/* Footer */}
|
|
218
217
|
<div className="flex items-center justify-between gap-2 py-3">
|
|
219
|
-
<button
|
|
220
|
-
type="button"
|
|
221
|
-
className={cn(
|
|
222
|
-
'flex h-8 items-center gap-2 rounded-sm pl-1.5 text-sm text-foreground hover:bg-foreground/[0.05] hover:text-foreground',
|
|
223
|
-
collapsed ? 'pr-1.5' : 'pr-2.5'
|
|
224
|
-
)}
|
|
225
|
-
>
|
|
226
|
-
<IconSettings size={18} className="shrink-0" />
|
|
227
|
-
{!collapsed && <span>Settings</span>}
|
|
228
|
-
</button>
|
|
229
218
|
{/* Temporarily hidden */}
|
|
230
219
|
<button
|
|
231
220
|
type="button"
|
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
import { type ReactNode, useState } from 'react'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { IconLoader2, IconPlus, IconTrash } from '@tabler/icons-react'
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
DropdownMenu,
|
|
8
|
-
DropdownMenuContent,
|
|
9
|
-
DropdownMenuRadioGroup,
|
|
10
|
-
DropdownMenuRadioItem,
|
|
11
|
-
DropdownMenuTrigger
|
|
12
|
-
} from '@/client/components/ui/dropdown-menu'
|
|
5
|
+
import { useSaveWorkspaceName } from '@/client/api/workspaces'
|
|
6
|
+
import { useEnvVars } from '@/client/hooks/useEnvVars'
|
|
13
7
|
import { Button } from '@/client/components/ui/button'
|
|
14
8
|
import { Input } from '@/client/components/ui/input'
|
|
15
9
|
import { Switch } from '@/client/components/ui/switch'
|
|
16
10
|
import { useWorkspaceLayoutCtx } from '@/client/lib/WorkspaceLayoutContext'
|
|
17
11
|
import { cn } from '@/client/lib/cn'
|
|
18
|
-
import type {
|
|
12
|
+
import type { WorkspaceEnvVar } from '@/lib/types'
|
|
19
13
|
|
|
20
14
|
import { IconPicker } from './IconPicker'
|
|
21
15
|
|
|
@@ -123,12 +117,6 @@ export function GeneralSettings() {
|
|
|
123
117
|
|
|
124
118
|
// ── Environment ─────────────────────────────────────────────────────────────
|
|
125
119
|
|
|
126
|
-
const SCOPE_LABEL: Record<EnvScope, string> = {
|
|
127
|
-
widgets: 'Widgets',
|
|
128
|
-
agent: 'Agent',
|
|
129
|
-
both: 'Both'
|
|
130
|
-
}
|
|
131
|
-
|
|
132
120
|
// Source badge copy: where the key actually comes from.
|
|
133
121
|
const SOURCE_LABEL: Record<WorkspaceEnvVar['source'], string> = {
|
|
134
122
|
dotenv: '.env',
|
|
@@ -138,43 +126,12 @@ const SOURCE_LABEL: Record<WorkspaceEnvVar['source'], string> = {
|
|
|
138
126
|
|
|
139
127
|
const ENV_KEY_RE = /^[A-Za-z_][A-Za-z0-9_]*$/
|
|
140
128
|
|
|
141
|
-
type ScopeSelectProps = {
|
|
142
|
-
value: EnvScope
|
|
143
|
-
onChange: (scope: EnvScope) => void
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function ScopeSelect({ value, onChange }: ScopeSelectProps) {
|
|
147
|
-
return (
|
|
148
|
-
<DropdownMenu>
|
|
149
|
-
<DropdownMenuTrigger
|
|
150
|
-
render={
|
|
151
|
-
<Button variant="outline" size="sm" className="h-7 gap-1 px-2 font-normal">
|
|
152
|
-
{SCOPE_LABEL[value]}
|
|
153
|
-
<IconChevronDown stroke={1.75} className="text-muted-foreground" />
|
|
154
|
-
</Button>
|
|
155
|
-
}
|
|
156
|
-
/>
|
|
157
|
-
<DropdownMenuContent align="end" className="w-32">
|
|
158
|
-
<DropdownMenuRadioGroup value={value} onValueChange={v => onChange(v as EnvScope)}>
|
|
159
|
-
{(Object.keys(SCOPE_LABEL) as EnvScope[]).map(scope => (
|
|
160
|
-
<DropdownMenuRadioItem key={scope} value={scope}>
|
|
161
|
-
{SCOPE_LABEL[scope]}
|
|
162
|
-
</DropdownMenuRadioItem>
|
|
163
|
-
))}
|
|
164
|
-
</DropdownMenuRadioGroup>
|
|
165
|
-
</DropdownMenuContent>
|
|
166
|
-
</DropdownMenu>
|
|
167
|
-
)
|
|
168
|
-
}
|
|
169
|
-
|
|
170
129
|
export function EnvironmentSettings() {
|
|
171
130
|
const { workspaceId } = useWorkspaceLayoutCtx()
|
|
172
|
-
const env =
|
|
173
|
-
const update = useUpdateEnv(workspaceId)
|
|
131
|
+
const { env, update } = useEnvVars(workspaceId)
|
|
174
132
|
|
|
175
133
|
const [draftKey, setDraftKey] = useState('')
|
|
176
134
|
const [draftValue, setDraftValue] = useState('')
|
|
177
|
-
const [draftScope, setDraftScope] = useState<EnvScope>('both')
|
|
178
135
|
|
|
179
136
|
const keyValid = ENV_KEY_RE.test(draftKey)
|
|
180
137
|
const canAdd = keyValid && draftValue.length > 0 && !update.isPending
|
|
@@ -182,12 +139,11 @@ export function EnvironmentSettings() {
|
|
|
182
139
|
const addVar = () => {
|
|
183
140
|
if (!canAdd) return
|
|
184
141
|
update.mutate(
|
|
185
|
-
{ set: { [draftKey]: draftValue }
|
|
142
|
+
{ set: { [draftKey]: draftValue } },
|
|
186
143
|
{
|
|
187
144
|
onSuccess: () => {
|
|
188
145
|
setDraftKey('')
|
|
189
146
|
setDraftValue('')
|
|
190
|
-
setDraftScope('both')
|
|
191
147
|
}
|
|
192
148
|
}
|
|
193
149
|
)
|
|
@@ -230,15 +186,8 @@ export function EnvironmentSettings() {
|
|
|
230
186
|
>
|
|
231
187
|
{SOURCE_LABEL[v.source]}
|
|
232
188
|
</span>
|
|
233
|
-
{editable
|
|
234
|
-
<
|
|
235
|
-
value={v.scope ?? 'both'}
|
|
236
|
-
onChange={scope => update.mutate({ scopes: { [v.key]: scope } })}
|
|
237
|
-
/>
|
|
238
|
-
) : (
|
|
239
|
-
<span className="w-[60px] text-right text-[11px] text-muted-foreground/60">
|
|
240
|
-
from file
|
|
241
|
-
</span>
|
|
189
|
+
{!editable && (
|
|
190
|
+
<span className="text-right text-[11px] text-muted-foreground/60">from file</span>
|
|
242
191
|
)}
|
|
243
192
|
<button
|
|
244
193
|
type="button"
|
|
@@ -273,7 +222,6 @@ export function EnvironmentSettings() {
|
|
|
273
222
|
placeholder="value"
|
|
274
223
|
className="h-7 flex-1 text-xs"
|
|
275
224
|
/>
|
|
276
|
-
<ScopeSelect value={draftScope} onChange={setDraftScope} />
|
|
277
225
|
<Button variant="outline" size="sm" className="h-7" onClick={addVar} disabled={!canAdd}>
|
|
278
226
|
{update.isPending ? (
|
|
279
227
|
<IconLoader2 className="animate-spin" />
|