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.
- package/README.md +2 -2
- 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 +11 -5
- package/server/CLAUDE.md +4 -1
- 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 +965 -73
- package/server/constants.ts +1 -1
- 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,85 @@
|
|
|
1
|
+
// Scaffolding for a workspace's `.moi/` root, laid down by `moi init` (and
|
|
2
|
+
// `moi openclaw init`). Creates `.moi/widgets/`, writes the widget
|
|
3
|
+
// dependency manifest, and installs dependencies — so the agent never has to
|
|
4
|
+
// bootstrap the folder itself.
|
|
5
|
+
import { mkdir } from 'node:fs/promises'
|
|
6
|
+
import { join, resolve, sep } from 'node:path'
|
|
7
|
+
|
|
8
|
+
// Dependency set available to widgets. `react`/`react-dom` are stubs — at
|
|
9
|
+
// runtime they resolve to Moi's locally-vendored ESM via the browser importmap
|
|
10
|
+
// (/vendor/react); they're listed so editors pick up the correct types.
|
|
11
|
+
export const MOI_PACKAGE_JSON = {
|
|
12
|
+
name: 'widgets',
|
|
13
|
+
private: true,
|
|
14
|
+
dependencies: {
|
|
15
|
+
'@tabler/icons-react': '^3.40.0',
|
|
16
|
+
tailwindcss: '^4.0.0',
|
|
17
|
+
react: '^19.0.0',
|
|
18
|
+
'react-dom': '^19.0.0'
|
|
19
|
+
},
|
|
20
|
+
devDependencies: {
|
|
21
|
+
'@types/react': '^19.0.0',
|
|
22
|
+
'@types/react-dom': '^19.0.0'
|
|
23
|
+
}
|
|
24
|
+
} as const
|
|
25
|
+
|
|
26
|
+
// Ambient types for applets (widgets & views). Editor DX only — the moi
|
|
27
|
+
// bundler resolves the `moi` module and asset imports at build time without any
|
|
28
|
+
// declarations. Lives at `.moi/` root, NOT inside widgets/views, so it isn't
|
|
29
|
+
// picked up by the `.ts` build glob and compiled as an applet.
|
|
30
|
+
export const APPLET_ENV_DTS = `// Auto-generated by \`moi init\`. Ambient types for widgets & views.
|
|
31
|
+
// Editor/\`tsc\` only — the moi bundler needs no declarations.
|
|
32
|
+
|
|
33
|
+
declare module 'moi' {
|
|
34
|
+
// Absolute URL to a workspace file, streamed by the server. Pass a
|
|
35
|
+
// workspace-relative path (e.g. 'clips/001.mp4'). Media/asset files only.
|
|
36
|
+
export function fileUrl(path: string): string
|
|
37
|
+
export type WidgetConfig = {
|
|
38
|
+
rowSpan: 1 | 2 | 3 | 4
|
|
39
|
+
colSpan: 1 | 2 | 3 | 4
|
|
40
|
+
requiredEnv?: string[]
|
|
41
|
+
}
|
|
42
|
+
export type ViewConfig = { title?: string; requiredEnv?: string[] }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Bundled asset imports (\`import logo from './logo.png'\`) resolve to a URL string.
|
|
46
|
+
declare module '*.png' { const s: string; export default s }
|
|
47
|
+
declare module '*.jpg' { const s: string; export default s }
|
|
48
|
+
declare module '*.jpeg' { const s: string; export default s }
|
|
49
|
+
declare module '*.gif' { const s: string; export default s }
|
|
50
|
+
declare module '*.webp' { const s: string; export default s }
|
|
51
|
+
declare module '*.avif' { const s: string; export default s }
|
|
52
|
+
declare module '*.svg' { const s: string; export default s }
|
|
53
|
+
`
|
|
54
|
+
|
|
55
|
+
// Bootstraps `.moi/` ONLY when it doesn't exist yet. Re-running `moi init`
|
|
56
|
+
// on an existing workspace overwrites skills but must leave the user's
|
|
57
|
+
// `.moi/` (their deps, widgets, lockfile) completely untouched.
|
|
58
|
+
// Returns 'exists' when skipped, otherwise the `bun install` exit code.
|
|
59
|
+
export async function scaffoldMoiDir(workspacePath: string): Promise<'exists' | number> {
|
|
60
|
+
// Backstop against the nested-workspace bug: never scaffold a `.moi/` *inside*
|
|
61
|
+
// another workspace's `.moi/` (which produces the junk `.moi/.moi`). Callers
|
|
62
|
+
// (`moi init`) lift to the workspace root via `liftToWorkspaceRoot` first, so
|
|
63
|
+
// this only fires on a programmer error.
|
|
64
|
+
if (resolve(workspacePath).split(sep).includes('.moi')) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
`Refusing to scaffold a workspace inside a .moi directory: ${workspacePath}. ` +
|
|
67
|
+
'Run from the workspace root.'
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
const moiDir = join(workspacePath, '.moi')
|
|
71
|
+
if (await Bun.file(join(moiDir, 'package.json')).exists()) return 'exists'
|
|
72
|
+
// A bare `.moi/` dir without package.json counts as not-bootstrapped —
|
|
73
|
+
// fill in the missing pieces.
|
|
74
|
+
|
|
75
|
+
await mkdir(join(moiDir, 'widgets'), { recursive: true })
|
|
76
|
+
await Bun.write(join(moiDir, 'package.json'), JSON.stringify(MOI_PACKAGE_JSON, null, 2) + '\n')
|
|
77
|
+
await Bun.write(join(moiDir, 'applet-env.d.ts'), APPLET_ENV_DTS)
|
|
78
|
+
|
|
79
|
+
const install = Bun.spawn(['bun', 'install'], {
|
|
80
|
+
cwd: moiDir,
|
|
81
|
+
stdout: 'ignore',
|
|
82
|
+
stderr: 'inherit'
|
|
83
|
+
})
|
|
84
|
+
return await install.exited
|
|
85
|
+
}
|
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
// `session.message` rows only, per the design call).
|
|
12
12
|
// - Disk persistence — the gateway is the source of truth; we re-seed from
|
|
13
13
|
// `sessions.get` on cold start.
|
|
14
|
+
import { appendAttachmentNote } from '@/lib/attachment-note'
|
|
14
15
|
import { applyEvent, emptyViewState } from '@/lib/format'
|
|
15
|
-
import type {
|
|
16
|
+
import type { StreamEvent, ViewState } from '@/lib/types'
|
|
16
17
|
|
|
17
18
|
import {
|
|
18
19
|
type OpenClawMessage,
|
|
@@ -27,6 +28,7 @@ import {
|
|
|
27
28
|
} from './openclaw-adapter'
|
|
28
29
|
import { getGateway, onGatewayReconnected } from './openclaw-gateway'
|
|
29
30
|
import { broadcast } from './state'
|
|
31
|
+
import { materializeToPath, resolveUploads } from './uploads'
|
|
30
32
|
|
|
31
33
|
type OpenClawSessionKey = string // the gateway-side composite key, e.g. `agent:main:main`
|
|
32
34
|
|
|
@@ -80,12 +82,14 @@ function recKey(workspaceId: string, sessionId: string): string {
|
|
|
80
82
|
return `${workspaceId}:${sessionId}`
|
|
81
83
|
}
|
|
82
84
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
// All running OpenClaw sessions across every workspace, for the connect-time
|
|
86
|
+
// status snapshot. Key is `${workspaceId}:${sessionId}` (both are colon-free).
|
|
87
|
+
export function getOpenClawRunningSessions(): { workspaceId: string; sessionId: string }[] {
|
|
88
|
+
const out: { workspaceId: string; sessionId: string }[] = []
|
|
85
89
|
for (const [k, v] of openclawAgents) {
|
|
86
90
|
if (!v.processing) continue
|
|
87
|
-
|
|
88
|
-
out.push(k.slice(
|
|
91
|
+
const i = k.indexOf(':')
|
|
92
|
+
out.push({ workspaceId: k.slice(0, i), sessionId: k.slice(i + 1) })
|
|
89
93
|
}
|
|
90
94
|
return out
|
|
91
95
|
}
|
|
@@ -177,11 +181,7 @@ function emitTurn(rec: SessionRecord, msg: OpenClawMessage, idx: number): void {
|
|
|
177
181
|
}
|
|
178
182
|
}
|
|
179
183
|
rec.view = applyEvent(rec.view, { kind: 'turn', turn })
|
|
180
|
-
broadcast(rec.workspaceId, {
|
|
181
|
-
kind: 'turn',
|
|
182
|
-
turn,
|
|
183
|
-
sessionId: rec.sessionId
|
|
184
|
-
} as ServerMessage)
|
|
184
|
+
broadcast(rec.workspaceId, { kind: 'turn', turn, sessionId: rec.sessionId })
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
function ingest(rec: SessionRecord, msg: OpenClawMessage): void {
|
|
@@ -362,6 +362,37 @@ export function viewAsEvents(rec: SessionRecord): StreamEvent[] {
|
|
|
362
362
|
}
|
|
363
363
|
|
|
364
364
|
export async function sendOpenClawMessage(input: {
|
|
365
|
+
workspaceId: string
|
|
366
|
+
workspacePath: string
|
|
367
|
+
agentId: string
|
|
368
|
+
sessionId: string
|
|
369
|
+
isNew: boolean
|
|
370
|
+
content: string
|
|
371
|
+
// Upload ids. Basic support: the gateway's `sessions.send` only takes a string
|
|
372
|
+
// message, so we materialize each upload to a temp file and append the paths
|
|
373
|
+
// for the agent to read. Rich vision blocks await a gateway content-block API
|
|
374
|
+
// (see dev/file-uploads.md).
|
|
375
|
+
attachments?: string[]
|
|
376
|
+
optimisticId?: string
|
|
377
|
+
}): Promise<void> {
|
|
378
|
+
// Fold any attachments into the message text as file-path references.
|
|
379
|
+
let content = input.content
|
|
380
|
+
if (input.attachments?.length) {
|
|
381
|
+
const uploads = resolveUploads(input.workspaceId, input.attachments)
|
|
382
|
+
const files: { filename: string; path: string }[] = []
|
|
383
|
+
for (const u of uploads) {
|
|
384
|
+
const p = await materializeToPath(u)
|
|
385
|
+
if (p) files.push({ filename: u.filename, path: p })
|
|
386
|
+
}
|
|
387
|
+
content = appendAttachmentNote(input.content, files)
|
|
388
|
+
}
|
|
389
|
+
// Attachment-only send whose ids all expired → nothing to say; don't open a
|
|
390
|
+
// session for an empty message.
|
|
391
|
+
if (!content) return
|
|
392
|
+
return sendOpenClawMessageImpl({ ...input, content })
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
async function sendOpenClawMessageImpl(input: {
|
|
365
396
|
workspaceId: string
|
|
366
397
|
workspacePath: string
|
|
367
398
|
agentId: string
|
package/server/openclaw.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { readFile } from 'node:fs/promises'
|
|
|
2
2
|
import { homedir } from 'node:os'
|
|
3
3
|
import { join, resolve } from 'node:path'
|
|
4
4
|
|
|
5
|
+
import type { Model } from '@/lib/types'
|
|
6
|
+
|
|
5
7
|
export type OpenClawAgent = {
|
|
6
8
|
path: string
|
|
7
9
|
agentId: string
|
|
@@ -204,3 +206,23 @@ export async function getOpenClawSessionMessages(
|
|
|
204
206
|
})
|
|
205
207
|
return out ?? null
|
|
206
208
|
}
|
|
209
|
+
|
|
210
|
+
// One entry from the gateway's `models.list` catalog. The catalog is
|
|
211
|
+
// gateway-wide (no per-agent param) — the allowed model set filtered by config.
|
|
212
|
+
type OpenClawModelChoice = {
|
|
213
|
+
id: string
|
|
214
|
+
name: string
|
|
215
|
+
provider: string
|
|
216
|
+
alias?: string
|
|
217
|
+
contextWindow?: number
|
|
218
|
+
reasoning?: boolean
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export async function getOpenClawModels(): Promise<Model[]> {
|
|
222
|
+
const out = await withGatewayClient(async rpc => {
|
|
223
|
+
const res = await rpc<{ models: OpenClawModelChoice[] }>('models.list')
|
|
224
|
+
return res.models
|
|
225
|
+
})
|
|
226
|
+
// Map the gateway catalog onto the raw Model shape (value/displayName).
|
|
227
|
+
return (out ?? []).map(m => ({ value: m.id, displayName: m.name }))
|
|
228
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Downscaled image previews of workspace files.
|
|
2
|
+
//
|
|
3
|
+
// Backs GET /api/workspaces/:id/preview/<path>, used by the chat's expanded
|
|
4
|
+
// tool rows: when the agent `Read`s an image from the workspace, the row shows
|
|
5
|
+
// the actual picture instead of just the path. Same hard guards as the raw
|
|
6
|
+
// `/fs/` stream (resolveWorkspaceMediaFile), but scoped to image extensions and
|
|
7
|
+
// resized server-side so a huge screenshot doesn't ship megabytes to render a
|
|
8
|
+
// 300px-tall preview.
|
|
9
|
+
//
|
|
10
|
+
// Workspace files change under the agent, so responses are revalidated instead
|
|
11
|
+
// of cached blindly: ETag from (size, mtime) + `no-cache`, so an unchanged file
|
|
12
|
+
// costs a 304 and an edited one re-renders.
|
|
13
|
+
import { statSync } from 'node:fs'
|
|
14
|
+
|
|
15
|
+
import sharp from 'sharp'
|
|
16
|
+
|
|
17
|
+
import { resolveWorkspaceMediaFile } from './applets'
|
|
18
|
+
|
|
19
|
+
// Long edge of the rendered preview. 2× the ~300px display size keeps it crisp
|
|
20
|
+
// on retina without shipping the original.
|
|
21
|
+
const PREVIEW_MAX_EDGE = 800
|
|
22
|
+
|
|
23
|
+
// Everything sharp can decode gets resized + re-encoded to webp. SVG and GIF
|
|
24
|
+
// stream raw instead: SVG scales for free, and resizing a GIF would drop its
|
|
25
|
+
// animation.
|
|
26
|
+
const RESIZE_RE = /\.(png|jpe?g|webp|avif)$/i
|
|
27
|
+
const PASSTHROUGH_RE = /\.(gif|svg)$/i
|
|
28
|
+
|
|
29
|
+
export async function serveWorkspaceImagePreview(
|
|
30
|
+
workspaceRoot: string,
|
|
31
|
+
tail: string,
|
|
32
|
+
ifNoneMatch?: string | null
|
|
33
|
+
): Promise<Response> {
|
|
34
|
+
const resize = RESIZE_RE.test(tail)
|
|
35
|
+
if (!resize && !PASSTHROUGH_RE.test(tail)) {
|
|
36
|
+
return new Response('Not an image', { status: 415 })
|
|
37
|
+
}
|
|
38
|
+
const realTarget = resolveWorkspaceMediaFile(workspaceRoot, tail)
|
|
39
|
+
if (realTarget instanceof Response) return realTarget
|
|
40
|
+
|
|
41
|
+
let stat: ReturnType<typeof statSync>
|
|
42
|
+
try {
|
|
43
|
+
stat = statSync(realTarget)
|
|
44
|
+
} catch {
|
|
45
|
+
return new Response('Not found', { status: 404 })
|
|
46
|
+
}
|
|
47
|
+
const etag = `"${stat.size}-${Math.trunc(stat.mtimeMs)}${resize ? `-${PREVIEW_MAX_EDGE}` : ''}"`
|
|
48
|
+
const headers: Record<string, string> = { ETag: etag, 'Cache-Control': 'private, no-cache' }
|
|
49
|
+
if (ifNoneMatch === etag) return new Response(null, { status: 304, headers })
|
|
50
|
+
|
|
51
|
+
if (!resize) {
|
|
52
|
+
const file = Bun.file(realTarget)
|
|
53
|
+
return new Response(file, {
|
|
54
|
+
headers: { ...headers, 'Content-Type': file.type || 'application/octet-stream' }
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
const data = await sharp(realTarget)
|
|
60
|
+
.rotate()
|
|
61
|
+
.resize(PREVIEW_MAX_EDGE, PREVIEW_MAX_EDGE, { fit: 'inside', withoutEnlargement: true })
|
|
62
|
+
.webp({ quality: 80 })
|
|
63
|
+
.toBuffer()
|
|
64
|
+
return new Response(data, { headers: { ...headers, 'Content-Type': 'image/webp' } })
|
|
65
|
+
} catch {
|
|
66
|
+
// Undecodable (corrupt, or an unsupported codec despite the extension) —
|
|
67
|
+
// there's no preview to show; the client hides the <img> on error.
|
|
68
|
+
return new Response('Preview failed', { status: 415 })
|
|
69
|
+
}
|
|
70
|
+
}
|
package/server/registry.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import envPaths from 'env-paths'
|
|
2
2
|
import { mkdir } from 'node:fs/promises'
|
|
3
3
|
import { homedir } from 'node:os'
|
|
4
|
-
import { join, resolve } from 'path'
|
|
4
|
+
import { join, resolve, sep } from 'path'
|
|
5
5
|
|
|
6
6
|
import type { DiscoveredWorkspace, WorkspaceEntry, WorkspaceType } from '@/lib/types'
|
|
7
7
|
|
|
@@ -9,7 +9,7 @@ import { type OpenClawAgent, discoverOpenClawAgents } from './openclaw'
|
|
|
9
9
|
|
|
10
10
|
// Replace the home-dir prefix with `~` for display. Keeps the original
|
|
11
11
|
// absolute path in place; callers should put the result in `displayPath`.
|
|
12
|
-
function tildify(absPath: string): string {
|
|
12
|
+
export function tildify(absPath: string): string {
|
|
13
13
|
const home = homedir()
|
|
14
14
|
if (!home) return absPath
|
|
15
15
|
if (absPath === home) return '~'
|
|
@@ -93,6 +93,36 @@ export async function listWorkspaces(): Promise<WorkspaceEntry[]> {
|
|
|
93
93
|
return entries.map(withDisplayPath)
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
// Resolve a path to the registered workspace that *contains* it: the entry
|
|
97
|
+
// whose path equals `reqPath` or is its nearest ancestor (longest matching
|
|
98
|
+
// prefix, git-style). This lets workspace-scoped commands (e.g. `moi bundle`)
|
|
99
|
+
// run from `.moi/` or any subdirectory and still target the real root, instead
|
|
100
|
+
// of treating the CWD as a workspace and scaffolding a phantom nested `.moi/`.
|
|
101
|
+
// Returns null when the path is not inside any registered workspace.
|
|
102
|
+
export function findWorkspaceForPath<T extends { path: string }>(
|
|
103
|
+
workspaces: T[],
|
|
104
|
+
reqPath: string
|
|
105
|
+
): T | null {
|
|
106
|
+
const normal = resolve(reqPath)
|
|
107
|
+
const matches = workspaces.filter(w => normal === w.path || normal.startsWith(w.path + sep))
|
|
108
|
+
if (matches.length === 0) return null
|
|
109
|
+
return matches.reduce((best, w) => (w.path.length > best.path.length ? w : best))
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// If `p` lies inside a workspace's `.moi/` directory, return the workspace root
|
|
113
|
+
// (the directory that contains that `.moi`); otherwise return `p` unchanged.
|
|
114
|
+
// Cuts at the FIRST `.moi` segment, so an accidentally-nested `.moi/.moi/…`
|
|
115
|
+
// path lifts all the way back to the real root. Pure (no filesystem access) —
|
|
116
|
+
// `moi init` uses it so running from inside `.moi` never creates a nested
|
|
117
|
+
// workspace, and the command always targets the real workspace root.
|
|
118
|
+
export function liftToWorkspaceRoot(p: string): string {
|
|
119
|
+
const normal = resolve(p)
|
|
120
|
+
const segments = normal.split(sep)
|
|
121
|
+
const i = segments.indexOf('.moi')
|
|
122
|
+
if (i === -1) return normal
|
|
123
|
+
return segments.slice(0, i).join(sep) || sep
|
|
124
|
+
}
|
|
125
|
+
|
|
96
126
|
// Discover CC-active directories not yet in the registry
|
|
97
127
|
async function discoverFromCC(registeredPaths: Set<string>): Promise<string[]> {
|
|
98
128
|
try {
|