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
package/lib/types.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import type { StreamEvent } from './format'
|
|
1
|
+
import type { PreviewBlock, StreamEvent } from './format'
|
|
2
2
|
|
|
3
3
|
export type WidgetConfig = {
|
|
4
4
|
rowSpan: 1 | 2 | 3 | 4
|
|
5
5
|
colSpan: 1 | 2 | 3 | 4
|
|
6
|
+
// Env vars this widget's `.server.ts` expects (e.g. `ELEVENLABS_API_KEY`).
|
|
7
|
+
// Purely advisory: it lets the UI surface a "missing key" hint. It never
|
|
8
|
+
// blocks loading — the server function still just reads `process.env`.
|
|
9
|
+
requiredEnv?: string[]
|
|
6
10
|
}
|
|
7
11
|
|
|
8
12
|
export type WidgetInfo = {
|
|
@@ -10,19 +14,152 @@ export type WidgetInfo = {
|
|
|
10
14
|
config: WidgetConfig
|
|
11
15
|
}
|
|
12
16
|
|
|
13
|
-
//
|
|
17
|
+
// A view is a full-screen, agent-authored "app" (`.moi/views/<name>.tsx`),
|
|
18
|
+
// shown one-at-a-time in the workspace nav. Same build/RPC machinery as a
|
|
19
|
+
// widget, minus the grid: no sizing, the view owns its own layout and scroll.
|
|
20
|
+
export type ViewConfig = {
|
|
21
|
+
// Nav tab label. Falls back to the file name when unset.
|
|
22
|
+
title?: string
|
|
23
|
+
// Advisory env hints, same semantics as WidgetConfig.requiredEnv.
|
|
24
|
+
requiredEnv?: string[]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type ViewInfo = {
|
|
28
|
+
id: string
|
|
29
|
+
config: ViewConfig
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// A Scratchpad draw/view operation issued by `moi scratch`. Mutations run
|
|
33
|
+
// server-side against a headless tldraw store; `view` relays to a live tab. The
|
|
34
|
+
// server assigns each add op a `name` (the `--id`, or a generated one) so the
|
|
35
|
+
// derived tldraw shape id is deterministic and addressable later. Arrow endpoints
|
|
36
|
+
// bind to a shape (by name) or sit at a free point. See docs/moi-scratchpad.md.
|
|
37
|
+
export type ScratchPoint = { x: number; y: number }
|
|
38
|
+
export type ScratchArrowEnd = { name: string } | ScratchPoint
|
|
39
|
+
|
|
40
|
+
// The Scratchpad's color palette — the same six swatches the UI toolbar offers,
|
|
41
|
+
// so the agent can only paint what the user can. The CLI also accepts an arbitrary
|
|
42
|
+
// hex and snaps it to the nearest of these (tldraw shapes hold a palette color, not
|
|
43
|
+
// free hex).
|
|
44
|
+
export type ScratchColor = 'black' | 'grey' | 'blue' | 'green' | 'yellow' | 'red'
|
|
45
|
+
|
|
46
|
+
// tldraw's DefaultSizeStyle, exposed under two friendlier CLI names for the two
|
|
47
|
+
// shapes that use it: arrows take `--stroke small|large` (line weight), text &
|
|
48
|
+
// notes take `--font-size regular|big` (label size). Both map onto the same
|
|
49
|
+
// underlying tldraw size — `small`/`regular` → 'm', `large`/`big` → 'xl'.
|
|
50
|
+
export type ScratchSize = 'm' | 'xl'
|
|
51
|
+
|
|
52
|
+
// Fill style for rectangles — the UI toolbar's four options. The CLI takes
|
|
53
|
+
// `none|semi|pattern|solid`; ops carry the tldraw DefaultFillStyle value. Note the
|
|
54
|
+
// tldraw quirk (see defaultFills / FILL_OPTIONS in client/components/Scratchpad.tsx):
|
|
55
|
+
// fill value 'solid' paints the lighter "semi" color, while 'fill' paints the true
|
|
56
|
+
// solid (body === border). Keep the names in sync with that client list.
|
|
57
|
+
export type ScratchFill = 'none' | 'solid' | 'pattern' | 'fill'
|
|
58
|
+
|
|
59
|
+
// Optional styling carried by every add op. Omitted fields fall back to the
|
|
60
|
+
// shape's tldraw default. `size` is set from `--stroke` (arrows) or `--font-size`
|
|
61
|
+
// (text/notes); `fill` from `--fill` (rectangles).
|
|
62
|
+
export type ScratchStyle = { color?: ScratchColor; size?: ScratchSize; fill?: ScratchFill }
|
|
63
|
+
|
|
64
|
+
// Resize preset for `add image`: 'lo' caps the long side smaller (default, keeps
|
|
65
|
+
// the canvas light), 'hi' allows more pixels when detail matters.
|
|
66
|
+
export type ScratchImageQuality = 'lo' | 'hi'
|
|
67
|
+
|
|
68
|
+
export type ScratchOp =
|
|
69
|
+
| ({ kind: 'add-text'; name: string; x: number; y: number; text: string } & ScratchStyle)
|
|
70
|
+
| ({
|
|
71
|
+
kind: 'add-rect'
|
|
72
|
+
name: string
|
|
73
|
+
x: number
|
|
74
|
+
y: number
|
|
75
|
+
w: number
|
|
76
|
+
h: number
|
|
77
|
+
text?: string
|
|
78
|
+
} & ScratchStyle)
|
|
79
|
+
| ({ kind: 'add-note'; name: string; x: number; y: number; text: string } & ScratchStyle)
|
|
80
|
+
// Add an image from a local file `path` — the server resizes it to fit the
|
|
81
|
+
// canvas and embeds it (color/stroke don't apply, so no ScratchStyle).
|
|
82
|
+
// `quality` picks the resize preset: 'lo' (default, smaller) or 'hi' (sharper).
|
|
83
|
+
| {
|
|
84
|
+
kind: 'add-image'
|
|
85
|
+
name: string
|
|
86
|
+
x: number
|
|
87
|
+
y: number
|
|
88
|
+
path: string
|
|
89
|
+
quality?: ScratchImageQuality
|
|
90
|
+
}
|
|
91
|
+
| ({
|
|
92
|
+
kind: 'add-arrow'
|
|
93
|
+
name: string
|
|
94
|
+
from: ScratchArrowEnd
|
|
95
|
+
to: ScratchArrowEnd
|
|
96
|
+
// Right-angle (orthogonal) routing for clean diagrams; default is a curved arc.
|
|
97
|
+
elbow?: boolean
|
|
98
|
+
} & ScratchStyle)
|
|
99
|
+
| { kind: 'move'; name: string; x: number; y: number }
|
|
100
|
+
| { kind: 'set'; name: string; text: string }
|
|
101
|
+
| { kind: 'delete'; name: string }
|
|
102
|
+
| { kind: 'clear' }
|
|
103
|
+
| { kind: 'view' }
|
|
104
|
+
|
|
105
|
+
// What a tab returns after running an op: a shape's `name` for add ops, a PNG
|
|
106
|
+
// data URL for `view`, or a bare ack for mutations.
|
|
107
|
+
export type ScratchOpResult = { name: string } | { image: string } | { ok: true }
|
|
108
|
+
|
|
109
|
+
// An attachment uploaded ahead of a chat message. The bytes live server-side in
|
|
110
|
+
// an in-memory upload store (see server/uploads.ts); a chat frame references it
|
|
111
|
+
// by `id`. `kind` splits the two delivery paths: an `image` is inlined as a
|
|
112
|
+
// base64 vision block in the agent message, a `file` is written to a temp path
|
|
113
|
+
// the agent can `Read`. Returned by POST /api/workspaces/:id/uploads.
|
|
114
|
+
export type UploadKind = 'image' | 'file'
|
|
115
|
+
export type UploadInfo = {
|
|
116
|
+
id: string
|
|
117
|
+
kind: UploadKind
|
|
118
|
+
// Normalized media type (images are re-encoded to a vision-safe type).
|
|
119
|
+
mediaType: string
|
|
120
|
+
filename: string
|
|
121
|
+
size: number
|
|
122
|
+
// Pixel dimensions, for images only — lets the composer reserve space.
|
|
123
|
+
width?: number
|
|
124
|
+
height?: number
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Client → Server messages.
|
|
128
|
+
// The chat WebSocket is app-wide (one socket for the whole client, not scoped to
|
|
129
|
+
// a workspace), so every message carries the `workspaceId` it targets.
|
|
14
130
|
export type ClientMessage =
|
|
15
131
|
| {
|
|
16
132
|
type: 'chat'
|
|
133
|
+
workspaceId: string
|
|
17
134
|
content: string
|
|
18
135
|
sessionId: string
|
|
19
136
|
isNew: boolean
|
|
137
|
+
// Upload ids (from POST .../uploads) to attach to this turn. The server
|
|
138
|
+
// resolves each from its upload store and turns it into a vision block
|
|
139
|
+
// (image) or a temp-file path reference (other files). Order is preserved.
|
|
140
|
+
attachments?: string[]
|
|
20
141
|
// Client-chosen stable id for the user's turn. The server tells the
|
|
21
142
|
// adapter to use this id when the SDK echoes the user input back, so
|
|
22
143
|
// the optimistic bubble the client rendered gets upserted in place.
|
|
23
144
|
optimisticId?: string
|
|
145
|
+
// Model id to run this turn with (from the picker / `supportedModels()`
|
|
146
|
+
// `value`). Omitted means the server's default. Applied per turn, so it
|
|
147
|
+
// can change between messages in the same session.
|
|
148
|
+
model?: string
|
|
149
|
+
// Reasoning effort for this turn (one of the model's `supportedEffortLevels`).
|
|
150
|
+
// Omitted means the SDK default. Unlike model, the SDK has no live setter,
|
|
151
|
+
// so a change forces the live session to resume (see server/cc-session.ts).
|
|
152
|
+
effort?: string
|
|
153
|
+
// Opt into live token-by-token streaming for this turn. Omitted/false runs
|
|
154
|
+
// the current whole-block behavior. Only honored for providers that report
|
|
155
|
+
// `supportsStreaming` (Claude Code); ignored otherwise. Like effort, a
|
|
156
|
+
// change forces the live session to rebuild.
|
|
157
|
+
stream?: boolean
|
|
24
158
|
}
|
|
25
|
-
| { type: 'stop'; sessionId: string }
|
|
159
|
+
| { type: 'stop'; workspaceId: string; sessionId: string }
|
|
160
|
+
// Reply to a relayed Scratchpad op (see ScratchpadOpMessage). Carries the
|
|
161
|
+
// op's correlation id so the server settles the right pending CLI request.
|
|
162
|
+
| { type: 'scratchpad:op-result'; opId: string; result?: ScratchOpResult; error?: string }
|
|
26
163
|
|
|
27
164
|
// Session info returned by list endpoint
|
|
28
165
|
export type SessionInfo = {
|
|
@@ -32,13 +169,25 @@ export type SessionInfo = {
|
|
|
32
169
|
cwd?: string
|
|
33
170
|
}
|
|
34
171
|
|
|
172
|
+
// Per-thread agent settings, persisted server-side in one global file in moi's
|
|
173
|
+
// data dir (NOT in the workspace), exposed via GET/PUT
|
|
174
|
+
// /api/workspaces/:id/sessions/:sessionId/config. A thread reopens with the same
|
|
175
|
+
// model/effort it last ran with; a brand-new thread is seeded from the workspace
|
|
176
|
+
// defaults (`WorkspaceLayout.selectedModel`/`selectedEffort`).
|
|
177
|
+
export type ThreadConfig = {
|
|
178
|
+
model?: string
|
|
179
|
+
effort?: string
|
|
180
|
+
}
|
|
181
|
+
|
|
35
182
|
// Re-export the display format
|
|
36
183
|
export type {
|
|
37
184
|
Citation,
|
|
38
185
|
Part,
|
|
186
|
+
PreviewBlock,
|
|
39
187
|
ResultSummary,
|
|
40
188
|
SessionSnapshot,
|
|
41
189
|
StreamEvent,
|
|
190
|
+
StreamPreview,
|
|
42
191
|
SubagentRecord,
|
|
43
192
|
SubagentStatus,
|
|
44
193
|
SystemNotice,
|
|
@@ -52,15 +201,68 @@ export type {
|
|
|
52
201
|
} from './format'
|
|
53
202
|
|
|
54
203
|
// Server → Client messages.
|
|
55
|
-
//
|
|
56
|
-
//
|
|
204
|
+
// The chat socket is app-wide, so every conversation frame carries both a
|
|
205
|
+
// `workspaceId` and a `sessionId` — the client routes each frame to the right
|
|
206
|
+
// `(workspaceId, sessionId)` slice of its cache.
|
|
57
207
|
export type ServerMessage =
|
|
58
|
-
| (StreamEvent & { sessionId: string })
|
|
208
|
+
| (StreamEvent & { sessionId: string; workspaceId: string })
|
|
209
|
+
| PreviewFrame
|
|
59
210
|
| StatusMessage
|
|
60
211
|
| SessionRenamedMessage
|
|
61
212
|
| WorkspaceSwitchMessage
|
|
62
213
|
| ErrorFrame
|
|
63
214
|
| StoppedFrame
|
|
215
|
+
| StatusSnapshotMessage
|
|
216
|
+
| ScratchpadOpMessage
|
|
217
|
+
|
|
218
|
+
// A live token-by-token snapshot of an assistant message still being generated.
|
|
219
|
+
// Ephemeral: it is NOT a StreamEvent, never persisted, and never folded into the
|
|
220
|
+
// durable transcript (React Query cache). The client keeps it in a separate
|
|
221
|
+
// ephemeral store and discards it the instant the real `turn` for `messageId`
|
|
222
|
+
// lands. `blocks[].text` is CUMULATIVE, so a lost/reordered/duplicated frame is
|
|
223
|
+
// simply overwritten by the next one — it can never corrupt the transcript.
|
|
224
|
+
export type PreviewFrame = {
|
|
225
|
+
type: 'preview'
|
|
226
|
+
workspaceId: string
|
|
227
|
+
sessionId: string
|
|
228
|
+
// API message id (`msg_...`), globally unique — the accumulator key, so
|
|
229
|
+
// concurrent streams (parallel subagents) never collide. Matches the eventual
|
|
230
|
+
// turn's `meta.apiMessageId`, which is how the client clears this preview.
|
|
231
|
+
messageId: string
|
|
232
|
+
// null = top-level assistant; a tool_use id = a subagent's nested stream.
|
|
233
|
+
parentToolUseId: string | null
|
|
234
|
+
blocks: PreviewBlock[]
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// A Scratchpad op relayed to the tab(s) showing `workspaceId`'s canvas. Only
|
|
238
|
+
// `view` travels this way now (rendering needs the browser); mutations run
|
|
239
|
+
// server-side. The tab with a live editor for that workspace executes it and
|
|
240
|
+
// replies with a matching `scratchpad:op-result` (correlated by `opId`).
|
|
241
|
+
export type ScratchpadOpMessage = {
|
|
242
|
+
type: 'scratchpad:op'
|
|
243
|
+
workspaceId: string
|
|
244
|
+
opId: string
|
|
245
|
+
op: ScratchOp
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Frame as constructed by callers of `broadcast(workspaceId, frame)` — the
|
|
249
|
+
// `workspaceId` is stamped on by `broadcast`, so callers omit it.
|
|
250
|
+
export type BroadcastFrame =
|
|
251
|
+
| (StreamEvent & { sessionId: string })
|
|
252
|
+
| Omit<PreviewFrame, 'workspaceId'>
|
|
253
|
+
| Omit<StatusMessage, 'workspaceId'>
|
|
254
|
+
| Omit<SessionRenamedMessage, 'workspaceId'>
|
|
255
|
+
| Omit<ErrorFrame, 'workspaceId'>
|
|
256
|
+
| Omit<StoppedFrame, 'workspaceId'>
|
|
257
|
+
|
|
258
|
+
// Sent to a client right after it connects: the authoritative set of currently
|
|
259
|
+
// running sessions across all workspaces. The client treats it as ground truth —
|
|
260
|
+
// any session NOT listed is marked not-processing — which clears a spinner whose
|
|
261
|
+
// terminal `status:false` was emitted while the client was disconnected.
|
|
262
|
+
export type StatusSnapshotMessage = {
|
|
263
|
+
type: 'status_snapshot'
|
|
264
|
+
running: { workspaceId: string; sessionId: string }[]
|
|
265
|
+
}
|
|
64
266
|
|
|
65
267
|
export type WorkspaceSwitchMessage = {
|
|
66
268
|
type: 'workspace:switch'
|
|
@@ -69,6 +271,15 @@ export type WorkspaceSwitchMessage = {
|
|
|
69
271
|
|
|
70
272
|
export type WorkspaceType = 'claude-code' | 'openclaw' | 'hermes'
|
|
71
273
|
|
|
274
|
+
// One MCP server's connection status, as surfaced by GET /api/workspaces/:id/mcp
|
|
275
|
+
// (a subset of the agent SDK's McpServerStatus — only what the UI renders).
|
|
276
|
+
export type McpServerState = 'connected' | 'failed' | 'needs-auth' | 'pending' | 'disabled'
|
|
277
|
+
|
|
278
|
+
export type McpServer = {
|
|
279
|
+
name: string
|
|
280
|
+
status: McpServerState
|
|
281
|
+
}
|
|
282
|
+
|
|
72
283
|
export type WorkspaceEntry = {
|
|
73
284
|
id: string
|
|
74
285
|
path: string
|
|
@@ -76,7 +287,11 @@ export type WorkspaceEntry = {
|
|
|
76
287
|
type?: WorkspaceType
|
|
77
288
|
// Display name captured at add time (e.g. OpenClaw IDENTITY.md "Name:" or
|
|
78
289
|
// basename). Persisted so we don't re-probe the gateway for each listing.
|
|
290
|
+
// The list endpoint overrides this with the live layout `name` when set.
|
|
79
291
|
name?: string
|
|
292
|
+
// Workspace icon override (base64 data URL), merged in from the layout by the
|
|
293
|
+
// list endpoint. Undefined → the sidebar uses the provider icon.
|
|
294
|
+
icon?: string
|
|
80
295
|
// Home-relative rendering of `path` (e.g. "~/.openclaw/workspace"). Set by
|
|
81
296
|
// the server on the wire — clients render it as-is.
|
|
82
297
|
displayPath?: string
|
|
@@ -99,23 +314,27 @@ export type DiscoveredWorkspace = {
|
|
|
99
314
|
|
|
100
315
|
export type SessionRenamedMessage = {
|
|
101
316
|
type: 'session_renamed'
|
|
317
|
+
workspaceId: string
|
|
102
318
|
from: string
|
|
103
319
|
to: string
|
|
104
320
|
}
|
|
105
321
|
|
|
106
322
|
export type ErrorFrame = {
|
|
107
323
|
kind: 'error'
|
|
324
|
+
workspaceId: string
|
|
108
325
|
sessionId: string
|
|
109
326
|
content: string
|
|
110
327
|
}
|
|
111
328
|
|
|
112
329
|
export type StoppedFrame = {
|
|
113
330
|
kind: 'stopped'
|
|
331
|
+
workspaceId: string
|
|
114
332
|
sessionId: string
|
|
115
333
|
}
|
|
116
334
|
|
|
117
335
|
export type StatusMessage = {
|
|
118
336
|
type: 'status'
|
|
337
|
+
workspaceId: string
|
|
119
338
|
sessionId: string
|
|
120
339
|
processing: boolean
|
|
121
340
|
}
|
|
@@ -123,14 +342,38 @@ export type StatusMessage = {
|
|
|
123
342
|
// Workspace layout persistence
|
|
124
343
|
export type LayoutGridItem = { i: string; x: number; y: number }
|
|
125
344
|
|
|
345
|
+
// Persisted chat dock position. Fullscreen is NOT a position — it's a transient
|
|
346
|
+
// local view (the "Chat" tab) that overrides the position, so it isn't stored.
|
|
126
347
|
export type ChatMode = 'sidebar' | 'floating'
|
|
127
348
|
|
|
349
|
+
// How the chat is actually shown: its persisted position, or fullscreen while
|
|
350
|
+
// the chat view is active.
|
|
351
|
+
export type ChatDisplay = ChatMode | 'fullscreen'
|
|
352
|
+
|
|
128
353
|
export type { FontTheme, ColorTheme } from './themes'
|
|
129
354
|
|
|
130
355
|
export type WorkspaceLayout = {
|
|
131
356
|
version: 1
|
|
132
357
|
widgetGrid: LayoutGridItem[]
|
|
133
358
|
chatMode: ChatMode
|
|
359
|
+
// User-set display-name override. When empty/undefined the API falls back to
|
|
360
|
+
// the workspace folder name, so the resolved name always comes from the API.
|
|
361
|
+
name?: string
|
|
362
|
+
// Workspace icon override — a base64 data URL (128×128 transparent WebP,
|
|
363
|
+
// produced by the server). Undefined falls back to the provider icon.
|
|
364
|
+
icon?: string
|
|
365
|
+
// Model id chosen in the composer picker (`supportedModels()` `value`, an
|
|
366
|
+
// alias like `sonnet`). Persisted so the choice survives a reload. Sent with
|
|
367
|
+
// each chat frame; undefined means the agent runs on the SDK default. Note
|
|
368
|
+
// the transcript records the *resolved* id (e.g. `claude-sonnet-4-6`), which
|
|
369
|
+
// doesn't map back to these aliases — hence we persist the pick here.
|
|
370
|
+
//
|
|
371
|
+
// This (and `selectedEffort`) is the *workspace default*: the value the picker
|
|
372
|
+
// edits when no thread is open, and the seed a brand-new thread copies. Once a
|
|
373
|
+
// thread exists it carries its own per-thread override (see `ThreadConfig`).
|
|
374
|
+
selectedModel?: string
|
|
375
|
+
// Reasoning-effort default for new threads (a `supportedEffortLevels` value).
|
|
376
|
+
selectedEffort?: string
|
|
134
377
|
theme?: {
|
|
135
378
|
font: import('./themes').FontTheme
|
|
136
379
|
background?: string
|
|
@@ -142,3 +385,68 @@ export type WorkspacePreview = {
|
|
|
142
385
|
cols: number
|
|
143
386
|
items: { x: number; y: number; w: number; h: number }[]
|
|
144
387
|
}
|
|
388
|
+
|
|
389
|
+
// Where a custom secret is allowed to flow: the widget function workers, the
|
|
390
|
+
// agent's Bash, or both. Lets a key meant for a widget stay out of the agent's
|
|
391
|
+
// (bypass-permissions) environment, and vice versa.
|
|
392
|
+
export type EnvScope = 'widgets' | 'agent' | 'both'
|
|
393
|
+
|
|
394
|
+
// One effective env var, as surfaced by GET /api/workspaces/:id/env. Values are
|
|
395
|
+
// NEVER returned — the API masks both `.env` and custom secrets, so editing is
|
|
396
|
+
// write-only. Presence in the list (with `source`) is all the UI needs.
|
|
397
|
+
export type WorkspaceEnvVar = {
|
|
398
|
+
key: string
|
|
399
|
+
// `dotenv`: only from a `.env` file. `custom`: only a UI-managed secret.
|
|
400
|
+
// `both`: a custom secret shadowing a `.env` value (custom wins).
|
|
401
|
+
source: 'dotenv' | 'custom' | 'both'
|
|
402
|
+
// Sink scope — present for custom/both (UI-managed) keys.
|
|
403
|
+
scope?: EnvScope
|
|
404
|
+
// The `.env` files that declare this key (when dotenv-sourced).
|
|
405
|
+
files?: string[]
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// GET /api/workspaces/:id/env payload — the env view for the settings UI.
|
|
409
|
+
export type WorkspaceEnvView = {
|
|
410
|
+
vars: WorkspaceEnvVar[]
|
|
411
|
+
// Discovered `.env` files with how many keys each holds (values masked).
|
|
412
|
+
files: { file: string; count: number }[]
|
|
413
|
+
inheritDotenv: boolean
|
|
414
|
+
// Where custom secrets are stored: the OS keychain (Bun.secrets) when
|
|
415
|
+
// available, else a 0600 file fallback. Surfaced so the UI can warn.
|
|
416
|
+
backend: 'keychain' | 'file'
|
|
417
|
+
// Keys declared via widget `config.requiredEnv`, with whether they're visible
|
|
418
|
+
// to widgets in the effective env and which widgets asked for them.
|
|
419
|
+
required: { key: string; satisfied: boolean; widgets: string[] }[]
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// Normalized capability flags shared across backends. An absent flag means
|
|
423
|
+
// "unknown / not reported by this backend", not "unsupported".
|
|
424
|
+
// A model a workspace's agent backend can run — the raw shape from the Claude
|
|
425
|
+
// Agent SDK's supportedModels(), passed through as-is (server/agent.ts). OpenClaw
|
|
426
|
+
// maps its catalog onto value/displayName.
|
|
427
|
+
export type Model = {
|
|
428
|
+
// Id used to select the model (Claude `value`; OpenClaw catalog id).
|
|
429
|
+
value: string
|
|
430
|
+
// Human-readable label (Claude `displayName`; OpenClaw `name`).
|
|
431
|
+
displayName: string
|
|
432
|
+
// " · "-joined blurb (Claude): "<headline> · <tagline> · …". Absent for OpenClaw.
|
|
433
|
+
description?: string
|
|
434
|
+
// Effort/reasoning support (Claude). `supportedEffortLevels` can include values
|
|
435
|
+
// the SDK under-types (e.g. 'xhigh'), so it stays string[].
|
|
436
|
+
supportsEffort?: boolean
|
|
437
|
+
supportedEffortLevels?: string[]
|
|
438
|
+
supportsAdaptiveThinking?: boolean
|
|
439
|
+
supportsFastMode?: boolean
|
|
440
|
+
supportsAutoMode?: boolean
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// GET /api/workspaces/:id/models payload.
|
|
444
|
+
export type WorkspaceModels = {
|
|
445
|
+
// The agent backend that produced this list — matches the workspace provider.
|
|
446
|
+
provider: WorkspaceType
|
|
447
|
+
models: Model[]
|
|
448
|
+
// Whether this provider supports live token-by-token streaming (the picker
|
|
449
|
+
// shows the "Live typing" toggle only when true). Provider-wide, not per-model
|
|
450
|
+
// — Claude Code streams uniformly via `includePartialMessages`.
|
|
451
|
+
supportsStreaming?: boolean
|
|
452
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "moi-computer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Local AI workspace powered by the Claude Agent SDK, Bun, React, and Tailwind. Requires Bun.",
|
|
5
5
|
"license": "Elastic-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -41,11 +41,12 @@
|
|
|
41
41
|
"!server/test",
|
|
42
42
|
"!workspace/.env",
|
|
43
43
|
"!workspace/.claude/settings.local.json",
|
|
44
|
-
"!workspace/.
|
|
44
|
+
"!workspace/.moi"
|
|
45
45
|
],
|
|
46
46
|
"scripts": {
|
|
47
47
|
"dev": "bun server/cli.ts start --dev",
|
|
48
48
|
"build:client": "bun scripts/build-client.ts",
|
|
49
|
+
"vendor:react": "bun scripts/build-vendor.ts",
|
|
49
50
|
"prepack": "bun scripts/build-client.ts",
|
|
50
51
|
"lint": "oxlint",
|
|
51
52
|
"lint:fix": "oxlint --fix",
|
|
@@ -54,10 +55,11 @@
|
|
|
54
55
|
"prepare": "git config core.hooksPath .githooks"
|
|
55
56
|
},
|
|
56
57
|
"dependencies": {
|
|
57
|
-
"@anthropic-ai/claude-agent-sdk": "^0.
|
|
58
|
+
"@anthropic-ai/claude-agent-sdk": "^0.3.197",
|
|
59
|
+
"@anthropic-ai/sdk": "^0.109.1",
|
|
58
60
|
"@base-ui/react": "^1.2.0",
|
|
59
61
|
"@dnd-kit/core": "^6.3.1",
|
|
60
|
-
"@tabler/icons-react": "^3.
|
|
62
|
+
"@tabler/icons-react": "^3.44.0",
|
|
61
63
|
"@tailwindcss/typography": "^0.5.19",
|
|
62
64
|
"@tanstack/react-query": "^5.100.1",
|
|
63
65
|
"@typescript-eslint/typescript-estree": "^8.57.2",
|
|
@@ -65,11 +67,12 @@
|
|
|
65
67
|
"bun-plugin-tailwind": "^0.1.2",
|
|
66
68
|
"citty": "^0.2.1",
|
|
67
69
|
"class-variance-authority": "^0.7.1",
|
|
68
|
-
"cli-table3": "^0.6.5",
|
|
69
70
|
"clsx": "^2.1.1",
|
|
70
71
|
"devalue": "^5.6.4",
|
|
71
72
|
"env-paths": "^4.0.0",
|
|
73
|
+
"frimousse": "^0.3.0",
|
|
72
74
|
"highlight.js": "^10.7.3",
|
|
75
|
+
"hono": "^4.12.26",
|
|
73
76
|
"lru-cache": "^11.3.5",
|
|
74
77
|
"motion": "^12.35.1",
|
|
75
78
|
"pathe": "^2.0.3",
|
|
@@ -82,8 +85,11 @@
|
|
|
82
85
|
"rehype-highlight": "^7.0.2",
|
|
83
86
|
"remark-gfm": "^4.0.1",
|
|
84
87
|
"shadcn": "^4.0.2",
|
|
88
|
+
"sharp": "^0.35.1",
|
|
89
|
+
"sugar-high": "^1.2.1",
|
|
85
90
|
"tailwind-merge": "^3.5.0",
|
|
86
91
|
"tailwindcss": "^4.1.11",
|
|
92
|
+
"tldraw": "^5.1.1",
|
|
87
93
|
"tw-animate-css": "^1.4.0",
|
|
88
94
|
"typescript": "^5.9.3",
|
|
89
95
|
"wouter": "^3.9.0",
|
package/server/CLAUDE.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
Bun server on port
|
|
1
|
+
Bun server on port 13337. Serves the client at `/`, upgrades `/ws` to WebSocket.
|
|
2
2
|
|
|
3
|
+
- `web.ts` owns the Bun fullstack surface only: the SPA HTML shell (dev bundler + HMR / prebuilt `dist/`), the two WebSocket channels (`/ws` chat, `/api/workspaces/ws` live events), and graceful shutdown. Every HTTP API request is delegated to the Hono app via `fetch`.
|
|
4
|
+
- `api.ts` is the Hono REST API (all `/api/*` routes). `withWorkspace` middleware resolves `:id` → workspace (404 if missing) and stashes it on the context, so handlers read `c.get('ws')`. Its catch-all serves the prebuilt client from `dist/` in prod via Hono's `serveStatic` (cached, traversal-safe).
|
|
5
|
+
- `static.ts` exposes the `dist/` location (`DIST_DIR`), the `prebuilt` flag, and the prod SPA `distShell`. `events.ts` holds `publishEvent` (server→client live-event broadcast over `/api/workspaces/ws`) decoupled from `web.ts` to avoid an import cycle; `web.ts` wires it via `setEventServer`.
|
|
3
6
|
- `state.ts` holds global mutable state (messages, session, connected clients). `record()` appends, persists, and broadcasts.
|
|
4
7
|
- `agent.ts` sends prompts to Claude via `query()` from the agent SDK. Streams responses back as typed messages. Sessions are resumable.
|
|
5
8
|
- WebSocket protocol: server sends `ServerMessage`, client sends `ClientMessage` — both defined in `lib/types.ts`.
|
package/server/agent.ts
CHANGED
|
@@ -1,132 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
1
|
+
import { query } from '@anthropic-ai/claude-agent-sdk'
|
|
2
|
+
import type { ModelInfo } from '@anthropic-ai/claude-agent-sdk'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// Chat runs live in `cc-session.ts` (streaming-input sessions held per thread).
|
|
5
|
+
// MCP status probing lives in `mcp.ts`. This module now only probes the agent
|
|
6
|
+
// backend for the model list — spins up a throwaway `query()` and reads metadata.
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return 'Unknown error'
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export async function handleChat(
|
|
14
|
-
content: string,
|
|
15
|
-
sessionId: string,
|
|
16
|
-
isNew: boolean,
|
|
17
|
-
workspaceId: string,
|
|
18
|
-
workspacePath: string,
|
|
19
|
-
optimisticId?: string
|
|
20
|
-
) {
|
|
21
|
-
const agent = getAgent(sessionId)
|
|
22
|
-
|
|
23
|
-
if (agent.processing) {
|
|
24
|
-
broadcast(workspaceId, {
|
|
25
|
-
kind: 'error',
|
|
26
|
-
sessionId,
|
|
27
|
-
content: 'Already processing a message'
|
|
28
|
-
})
|
|
29
|
-
return
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const ctrl = new AbortController()
|
|
33
|
-
agent.processing = true
|
|
34
|
-
agent.abortController = ctrl
|
|
35
|
-
broadcast(workspaceId, { type: 'status', sessionId, processing: true })
|
|
36
|
-
|
|
37
|
-
let currentId = sessionId
|
|
38
|
-
const adapter = new ClaudeAdapter()
|
|
39
|
-
if (optimisticId) adapter.expectUserEcho(optimisticId, content)
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
const options: Options = {
|
|
43
|
-
abortController: ctrl,
|
|
44
|
-
maxTurns: 50,
|
|
45
|
-
cwd: workspacePath,
|
|
46
|
-
model: 'sonnet',
|
|
47
|
-
allowedTools: [
|
|
48
|
-
'Bash',
|
|
49
|
-
'Read',
|
|
50
|
-
'Write',
|
|
51
|
-
'Edit',
|
|
52
|
-
'MultiEdit',
|
|
53
|
-
'Glob',
|
|
54
|
-
'Grep',
|
|
55
|
-
'WebSearch',
|
|
56
|
-
'WebFetch'
|
|
57
|
-
],
|
|
58
|
-
permissionMode: 'bypassPermissions',
|
|
59
|
-
allowDangerouslySkipPermissions: true,
|
|
60
|
-
settingSources: ['user', 'project'],
|
|
61
|
-
env: { ...process.env, CLAUDECODE: undefined },
|
|
62
|
-
stderr: (data: string) => console.error('[SDK stderr]', data)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (!isNew) options.resume = sessionId
|
|
66
|
-
|
|
67
|
-
const q = query({ prompt: content, options })
|
|
68
|
-
|
|
69
|
-
for await (const msg of q) {
|
|
70
|
-
if (msg.type === 'system' && msg.subtype === 'init') {
|
|
71
|
-
const realId = msg.session_id
|
|
72
|
-
if (isNew && realId !== currentId) {
|
|
73
|
-
renameAgent(currentId, realId)
|
|
74
|
-
broadcast(workspaceId, { type: 'session_renamed', from: currentId, to: realId })
|
|
75
|
-
currentId = realId
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
for (const ev of adapter.ingest(msg)) {
|
|
80
|
-
broadcast(workspaceId, { ...ev, sessionId: currentId })
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
} catch (err: unknown) {
|
|
84
|
-
if (!(err instanceof Error && err.name === 'AbortError')) {
|
|
85
|
-
broadcast(workspaceId, {
|
|
86
|
-
kind: 'error',
|
|
87
|
-
sessionId: currentId,
|
|
88
|
-
content: getErrorMessage(err)
|
|
89
|
-
})
|
|
90
|
-
}
|
|
91
|
-
} finally {
|
|
92
|
-
const finalAgent = getAgent(currentId)
|
|
93
|
-
finalAgent.processing = false
|
|
94
|
-
finalAgent.abortController = null
|
|
95
|
-
broadcast(workspaceId, { type: 'status', sessionId: currentId, processing: false })
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export function stopChat(sessionId: string, workspaceId: string) {
|
|
100
|
-
const agent = getAgent(sessionId)
|
|
101
|
-
if (agent.abortController) {
|
|
102
|
-
agent.abortController.abort()
|
|
103
|
-
broadcast(workspaceId, { kind: 'stopped', sessionId })
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Per-workspace MCP cache
|
|
108
|
-
const mcpCache = new Map<string, McpServerStatus[]>()
|
|
109
|
-
|
|
110
|
-
async function fetchMcpStatus(workspacePath: string): Promise<McpServerStatus[]> {
|
|
8
|
+
// Claude's available models come from the account/CLI, not the workspace, so
|
|
9
|
+
// the list is identical everywhere. We still need a `cwd` to spin up a probe
|
|
10
|
+
// query, but cache the result process-wide.
|
|
11
|
+
async function fetchClaudeModels(cwd: string): Promise<ModelInfo[]> {
|
|
111
12
|
const q = query({
|
|
112
13
|
prompt: '',
|
|
113
14
|
options: {
|
|
114
|
-
cwd
|
|
15
|
+
cwd,
|
|
115
16
|
persistSession: false,
|
|
116
17
|
settingSources: ['user', 'project'],
|
|
117
18
|
env: { ...process.env, CLAUDECODE: undefined }
|
|
118
19
|
}
|
|
119
20
|
})
|
|
120
|
-
const
|
|
21
|
+
const models = await q.supportedModels()
|
|
121
22
|
await q.close()
|
|
122
|
-
|
|
123
|
-
return
|
|
23
|
+
// Raw SDK shape, passed through to the client as-is.
|
|
24
|
+
return models
|
|
124
25
|
}
|
|
125
26
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
27
|
+
// One in-flight/settled promise shared across all callers. On failure we clear
|
|
28
|
+
// it so a later request can retry instead of caching the rejection forever.
|
|
29
|
+
let claudeModelsPromise: Promise<ModelInfo[]> | null = null
|
|
30
|
+
|
|
31
|
+
export function getClaudeModels(cwd: string): Promise<ModelInfo[]> {
|
|
32
|
+
if (!claudeModelsPromise) {
|
|
33
|
+
claudeModelsPromise = fetchClaudeModels(cwd).catch(err => {
|
|
34
|
+
claudeModelsPromise = null
|
|
35
|
+
throw err
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
return claudeModelsPromise
|
|
132
39
|
}
|