moi-computer 0.0.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/LICENSE +95 -0
- package/README.md +71 -0
- package/bin/moi.mjs +25 -0
- package/bunfig.toml +3 -0
- package/client/CLAUDE.md +12 -0
- package/client/api/workspaces.ts +158 -0
- package/client/assets/claude.svg +3 -0
- package/client/assets/favicon.png +0 -0
- package/client/assets/hermes-nous.png +0 -0
- package/client/assets/mcp/.gitkeep +0 -0
- package/client/assets/mcp/atlassian.png +0 -0
- package/client/assets/mcp/discord.png +0 -0
- package/client/assets/mcp/figma.png +0 -0
- package/client/assets/mcp/github.png +0 -0
- package/client/assets/mcp/gitlab.png +0 -0
- package/client/assets/mcp/granola.png +0 -0
- package/client/assets/mcp/hubspot.png +0 -0
- package/client/assets/mcp/linear.png +0 -0
- package/client/assets/mcp/neon.png +0 -0
- package/client/assets/mcp/notion.png +0 -0
- package/client/assets/mcp/sentry.png +0 -0
- package/client/assets/mcp/slack.png +0 -0
- package/client/assets/mcp/stripe.png +0 -0
- package/client/assets/mcp/supabase.png +0 -0
- package/client/assets/mcp/vercel.png +0 -0
- package/client/assets/moi-logo.svg +11 -0
- package/client/assets/openclaw.svg +22 -0
- package/client/components/App.tsx +35 -0
- package/client/components/BottomPanel.tsx +33 -0
- package/client/components/ChatInput.tsx +62 -0
- package/client/components/ChatPanel.tsx +206 -0
- package/client/components/ChatPopup.tsx +60 -0
- package/client/components/CustomizePanel.tsx +117 -0
- package/client/components/HiddenPanel.tsx +79 -0
- package/client/components/HomePage.tsx +17 -0
- package/client/components/MarkdownContent.tsx +41 -0
- package/client/components/ThreadSelector.tsx +88 -0
- package/client/components/TurnView.tsx +618 -0
- package/client/components/WidgetErrorBoundary.tsx +46 -0
- package/client/components/WidgetFrame.tsx +66 -0
- package/client/components/WidgetGrid.tsx +113 -0
- package/client/components/WidgetShell.tsx +44 -0
- package/client/components/Widgets.tsx +132 -0
- package/client/components/WorkspacePreview.tsx +48 -0
- package/client/components/WorkspacesPage.tsx +237 -0
- package/client/components/layout/SidebarLayout.tsx +260 -0
- package/client/components/playground/LedLogo.tsx +181 -0
- package/client/components/playground/PixelPainter.tsx +105 -0
- package/client/components/playground/PlaygroundPage.tsx +71 -0
- package/client/components/routes/workspace/[id].tsx +282 -0
- package/client/components/ui/button.tsx +48 -0
- package/client/components/ui/dropdown-menu.tsx +257 -0
- package/client/components/ui/input.tsx +21 -0
- package/client/components/ui/popover.tsx +79 -0
- package/client/components/ui/textarea.tsx +18 -0
- package/client/externalize-react.ts +29 -0
- package/client/hooks/useChat.ts +88 -0
- package/client/hooks/useFitsSidebar.ts +34 -0
- package/client/hooks/useGridReconcile.ts +73 -0
- package/client/hooks/useMeiEvents.ts +66 -0
- package/client/hooks/useScrollFade.ts +38 -0
- package/client/hooks/useWidget.ts +72 -0
- package/client/hooks/useWidgetList.ts +30 -0
- package/client/hooks/useWorkspaceTheme.ts +76 -0
- package/client/index.css +182 -0
- package/client/index.html +43 -0
- package/client/index.tsx +19 -0
- package/client/lib/WorkspaceContext.tsx +24 -0
- package/client/lib/WorkspaceLayoutContext.tsx +92 -0
- package/client/lib/cn.ts +6 -0
- package/client/lib/grid-pack.ts +35 -0
- package/client/lib/group-turns.ts +44 -0
- package/client/lib/mcp-icons.ts +53 -0
- package/client/lib/ws.ts +129 -0
- package/client/main.tsx +23 -0
- package/client/store/chat.tsx +162 -0
- package/client/store/ui.ts +21 -0
- package/client/theme.css +66 -0
- package/lib/claude-adapter.ts +602 -0
- package/lib/format.ts +212 -0
- package/lib/themes.ts +89 -0
- package/lib/types.ts +144 -0
- package/package.json +117 -0
- package/server/CLAUDE.md +6 -0
- package/server/agent.ts +132 -0
- package/server/build-widget.ts +343 -0
- package/server/cli.ts +632 -0
- package/server/constants.ts +3 -0
- package/server/control.ts +98 -0
- package/server/functions-worker.ts +89 -0
- package/server/functions.ts +171 -0
- package/server/layout.ts +83 -0
- package/server/openclaw-adapter.ts +242 -0
- package/server/openclaw-gateway.ts +255 -0
- package/server/openclaw-session.ts +485 -0
- package/server/openclaw-strip.ts +134 -0
- package/server/openclaw.ts +206 -0
- package/server/registry.ts +150 -0
- package/server/skills-template.ts +21 -0
- package/server/state.ts +87 -0
- package/server/theme.ts +55 -0
- package/server/web.ts +321 -0
- package/server/widgets.ts +254 -0
- package/tsconfig.json +21 -0
- package/workspace/.claude/skills/widgets/DESIGN.md +630 -0
- package/workspace/.claude/skills/widgets/SKILL.md +176 -0
package/client/index.css
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
@import 'tailwindcss';
|
|
2
|
+
@import 'tw-animate-css';
|
|
3
|
+
@import 'shadcn/tailwind.css';
|
|
4
|
+
|
|
5
|
+
@import 'highlight.js/styles/github.css';
|
|
6
|
+
|
|
7
|
+
.hljs {
|
|
8
|
+
background: transparent;
|
|
9
|
+
padding: 0;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@plugin "@tailwindcss/typography";
|
|
13
|
+
|
|
14
|
+
@custom-variant dark (&:is(.dark *));
|
|
15
|
+
|
|
16
|
+
:root {
|
|
17
|
+
--background: oklch(1 0 0);
|
|
18
|
+
--foreground: oklch(0.145 0 0);
|
|
19
|
+
--card: oklch(1 0 0);
|
|
20
|
+
--card-foreground: oklch(0.145 0 0);
|
|
21
|
+
--popover: oklch(1 0 0);
|
|
22
|
+
--popover-foreground: oklch(0.145 0 0);
|
|
23
|
+
--primary: oklch(0.205 0 0);
|
|
24
|
+
--primary-foreground: oklch(0.985 0 0);
|
|
25
|
+
--secondary: oklch(0.97 0 0);
|
|
26
|
+
--secondary-foreground: oklch(0.205 0 0);
|
|
27
|
+
--muted: oklch(0.97 0 0);
|
|
28
|
+
--muted-foreground: oklch(0.64 0 0);
|
|
29
|
+
--accent: oklch(0.97 0 0);
|
|
30
|
+
--accent-foreground: oklch(0.205 0 0);
|
|
31
|
+
--destructive: oklch(0.58 0.22 27);
|
|
32
|
+
--border: oklch(0.922 0 0);
|
|
33
|
+
--input: oklch(0.922 0 0);
|
|
34
|
+
--ring: oklch(0.708 0 0);
|
|
35
|
+
--radius: 1rem;
|
|
36
|
+
|
|
37
|
+
/* Workspace page layout — single source of truth for the widget/chat panel.
|
|
38
|
+
Read by routes/workspace/[id].tsx and useFitsSidebar.ts; don't hardcode
|
|
39
|
+
equivalents. (The app sidebar's own widths live in SidebarLayout.tsx.) */
|
|
40
|
+
--page-pad: 2rem; /* padding around the working area */
|
|
41
|
+
--column-w: 40rem; /* grid content width; also the widget area's min before the chat yields */
|
|
42
|
+
--chat-min: 400px; /* docked chat min width — narrower than this and it floats */
|
|
43
|
+
--chat-max: 520px; /* docked chat max width on wide screens */
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@media (max-width: 1024px) {
|
|
47
|
+
:root {
|
|
48
|
+
--page-pad: 1.5rem;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@media (max-width: 640px) {
|
|
53
|
+
:root {
|
|
54
|
+
--page-pad: 1rem;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.dark {
|
|
59
|
+
--background: oklch(0.145 0 0);
|
|
60
|
+
--foreground: oklch(0.985 0 0);
|
|
61
|
+
--card: oklch(0.205 0 0);
|
|
62
|
+
--card-foreground: oklch(0.985 0 0);
|
|
63
|
+
--popover: oklch(0.205 0 0);
|
|
64
|
+
--popover-foreground: oklch(0.985 0 0);
|
|
65
|
+
--primary: oklch(0.985 0 0);
|
|
66
|
+
--primary-foreground: oklch(0.205 0 0);
|
|
67
|
+
--secondary: oklch(0.269 0 0);
|
|
68
|
+
--secondary-foreground: oklch(0.985 0 0);
|
|
69
|
+
--muted: oklch(0.269 0 0);
|
|
70
|
+
--muted-foreground: oklch(0.708 0 0);
|
|
71
|
+
--accent: oklch(0.269 0 0);
|
|
72
|
+
--accent-foreground: oklch(0.985 0 0);
|
|
73
|
+
--destructive: oklch(0.58 0.22 27);
|
|
74
|
+
--border: oklch(0.35 0 0);
|
|
75
|
+
--input: oklch(0.35 0 0);
|
|
76
|
+
--ring: oklch(0.556 0 0);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* Font vars are NOT inline so Tailwind generates var(--font-*) references,
|
|
80
|
+
allowing runtime overrides via document.documentElement.style.setProperty */
|
|
81
|
+
@theme {
|
|
82
|
+
--font-sans: ui-sans-serif, system-ui, sans-serif;
|
|
83
|
+
--font-mono: ui-monospace, monospace;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/* Color/radius/shadow tokens — shared with widget bundles via theme.css */
|
|
87
|
+
@import './theme.css';
|
|
88
|
+
|
|
89
|
+
/* Lift all grid items so the placeholder (z-index: 0) stays behind them */
|
|
90
|
+
.react-grid-item:not(.react-grid-placeholder) {
|
|
91
|
+
z-index: 1;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/* Dragged card floats above all others */
|
|
95
|
+
.react-grid-item.react-draggable-dragging {
|
|
96
|
+
z-index: 10;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/* Drop placeholder shown while dragging a widget — matches card shape */
|
|
100
|
+
.react-grid-item.react-grid-placeholder {
|
|
101
|
+
background: var(--muted);
|
|
102
|
+
opacity: 0.75;
|
|
103
|
+
border-radius: var(--radius-2xl);
|
|
104
|
+
corner-shape: superellipse(1.2);
|
|
105
|
+
z-index: 0;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
@layer base {
|
|
109
|
+
* {
|
|
110
|
+
@apply border-border outline-ring/50;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/* Tailwind v4 dropped the default antialiasing from preflight; opt in
|
|
114
|
+
globally so text matches the lighter "modern web app" look. */
|
|
115
|
+
html {
|
|
116
|
+
-webkit-font-smoothing: antialiased;
|
|
117
|
+
-moz-osx-font-smoothing: grayscale;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
body {
|
|
121
|
+
@apply bg-background text-foreground;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@keyframes pulse-dot {
|
|
126
|
+
0%,
|
|
127
|
+
100% {
|
|
128
|
+
opacity: 0.2;
|
|
129
|
+
transform: scale(0.85);
|
|
130
|
+
}
|
|
131
|
+
50% {
|
|
132
|
+
opacity: 1;
|
|
133
|
+
transform: scale(1);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
@utility prose-inherit {
|
|
138
|
+
--tw-prose-body: inherit;
|
|
139
|
+
--tw-prose-headings: inherit;
|
|
140
|
+
--tw-prose-lead: inherit;
|
|
141
|
+
--tw-prose-links: inherit;
|
|
142
|
+
--tw-prose-bold: inherit;
|
|
143
|
+
--tw-prose-counters: inherit;
|
|
144
|
+
--tw-prose-bullets: inherit;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
@utility mask-fade-bottom {
|
|
148
|
+
mask-image: linear-gradient(black 0px, black calc(100% - 24px), transparent 100%);
|
|
149
|
+
mask-size: 100% 100%;
|
|
150
|
+
mask-position: 0px 0px;
|
|
151
|
+
mask-repeat: no-repeat;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
@utility mask-fade-top {
|
|
155
|
+
mask-image: linear-gradient(transparent 0%, black 24px);
|
|
156
|
+
mask-size: 100% 100%;
|
|
157
|
+
mask-position: 0px 0px;
|
|
158
|
+
mask-repeat: no-repeat;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
@utility mask-fade-y {
|
|
162
|
+
mask-image: linear-gradient(
|
|
163
|
+
transparent 0%,
|
|
164
|
+
black 24px,
|
|
165
|
+
black calc(100% - 24px),
|
|
166
|
+
transparent 100%
|
|
167
|
+
);
|
|
168
|
+
mask-size: 100% 100%;
|
|
169
|
+
mask-position: 0px 0px;
|
|
170
|
+
mask-repeat: no-repeat;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/* Tool details toggle */
|
|
174
|
+
details > summary {
|
|
175
|
+
list-style: none;
|
|
176
|
+
}
|
|
177
|
+
details > summary::-webkit-details-marker {
|
|
178
|
+
display: none;
|
|
179
|
+
}
|
|
180
|
+
details[open] > summary .chevron {
|
|
181
|
+
transform: rotate(90deg);
|
|
182
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>moi.computer</title>
|
|
7
|
+
<link rel="icon" type="image/png" href="./assets/favicon.png" />
|
|
8
|
+
<script type="importmap">
|
|
9
|
+
{
|
|
10
|
+
"imports": {
|
|
11
|
+
"react": "https://esm.sh/react@19?dev",
|
|
12
|
+
"react/jsx-runtime": "https://esm.sh/react@19/jsx-runtime?dev",
|
|
13
|
+
"react/jsx-dev-runtime": "https://esm.sh/react@19/jsx-dev-runtime?dev",
|
|
14
|
+
"react-dom": "https://esm.sh/react-dom@19?dev",
|
|
15
|
+
"react-dom/client": "https://esm.sh/react-dom@19/client?dev"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
</script>
|
|
19
|
+
<link rel="stylesheet" href="./index.css" />
|
|
20
|
+
</head>
|
|
21
|
+
<body>
|
|
22
|
+
<div id="root"></div>
|
|
23
|
+
<script type="module" src="./index.tsx"></script>
|
|
24
|
+
<script type="module">
|
|
25
|
+
const [react, jsxRuntime, jsxDevRuntime, reactDom, reactDomClient] = await Promise.all([
|
|
26
|
+
import("react"),
|
|
27
|
+
import("react/jsx-runtime"),
|
|
28
|
+
import("react/jsx-dev-runtime"),
|
|
29
|
+
import("react-dom"),
|
|
30
|
+
import("react-dom/client"),
|
|
31
|
+
]);
|
|
32
|
+
globalThis.__esm = {
|
|
33
|
+
"react": react,
|
|
34
|
+
"react/jsx-runtime": jsxRuntime,
|
|
35
|
+
"react/jsx-dev-runtime": jsxDevRuntime,
|
|
36
|
+
"react-dom": reactDom,
|
|
37
|
+
"react-dom/client": reactDomClient,
|
|
38
|
+
};
|
|
39
|
+
globalThis.__init(document.getElementById("root"));
|
|
40
|
+
//# sourceURL=react-preload.js
|
|
41
|
+
</script>
|
|
42
|
+
</body>
|
|
43
|
+
</html>
|
package/client/index.tsx
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import './index.css'
|
|
2
|
+
|
|
3
|
+
// React is externalized to esm.sh (see client/externalize-react.ts + the importmap
|
|
4
|
+
// in index.html), so Bun's bundled Fast Refresh runtime isn't bound to the React
|
|
5
|
+
// instance that actually renders the app: it registers component families but
|
|
6
|
+
// performReactRefresh() no-ops, leaving stale modules mounted after an edit.
|
|
7
|
+
// Downgrade HMR to plain live-reload — every hot update triggers a full page
|
|
8
|
+
// reload, which re-fetches a clean bundle. Dead-code-eliminated in production.
|
|
9
|
+
if (import.meta.hot) {
|
|
10
|
+
import.meta.hot.on('bun:beforeUpdate', () => location.reload())
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function init(el: HTMLElement) {
|
|
14
|
+
const { mount } = await import('./main')
|
|
15
|
+
mount(el)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Expose init globally so the preload script can call it
|
|
19
|
+
globalThis.__init = init
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ReactNode, createContext, useContext, useEffect } from 'react'
|
|
2
|
+
|
|
3
|
+
const WorkspaceContext = createContext<string>('default')
|
|
4
|
+
|
|
5
|
+
export function useWorkspaceId() {
|
|
6
|
+
return useContext(WorkspaceContext)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type WorkspaceProps = {
|
|
10
|
+
id: string
|
|
11
|
+
children: ReactNode
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Provides the active workspace id to the tree (read by chat + widget hooks).
|
|
15
|
+
// Data loading lives in React Query now (see WorkspaceLayoutProvider and the
|
|
16
|
+
// useWorkspace* query hooks) — this only carries the id.
|
|
17
|
+
export function Workspace({ id, children }: WorkspaceProps) {
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
// Expose to widget RPC bundles
|
|
20
|
+
;(window as unknown as Record<string, unknown>).__MEI_WS__ = id
|
|
21
|
+
}, [id])
|
|
22
|
+
|
|
23
|
+
return <WorkspaceContext value={id}>{children}</WorkspaceContext>
|
|
24
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { type ReactNode, createContext, useCallback, useContext, useRef } from 'react'
|
|
2
|
+
|
|
3
|
+
import { useQueryClient } from '@tanstack/react-query'
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
type WorkspaceLayoutResponse,
|
|
7
|
+
useSaveLayout,
|
|
8
|
+
useWorkspaceLayout,
|
|
9
|
+
workspaceKeys
|
|
10
|
+
} from '@/client/api/workspaces'
|
|
11
|
+
import type { WorkspaceLayout } from '@/lib/types'
|
|
12
|
+
|
|
13
|
+
const DEFAULT_LAYOUT: WorkspaceLayout = {
|
|
14
|
+
version: 1,
|
|
15
|
+
widgetGrid: [],
|
|
16
|
+
chatMode: 'sidebar'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type WorkspaceLayoutContextValue = {
|
|
20
|
+
// The persisted layout (widget grid, chat mode, theme). Falls back to an
|
|
21
|
+
// empty default while the query is still loading.
|
|
22
|
+
layout: WorkspaceLayout
|
|
23
|
+
// Merge a partial update into the layout: updates the query cache immediately
|
|
24
|
+
// (optimistic) then debounces a PUT to the server via the save mutation.
|
|
25
|
+
setLayout: (update: Partial<WorkspaceLayout>) => void
|
|
26
|
+
// Workspace metadata that rides along on the layout endpoint.
|
|
27
|
+
name: string | null
|
|
28
|
+
cwd: string | null
|
|
29
|
+
isLoading: boolean
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const WorkspaceLayoutContext = createContext<WorkspaceLayoutContextValue | null>(null)
|
|
33
|
+
|
|
34
|
+
export function useWorkspaceLayoutCtx(): WorkspaceLayoutContextValue {
|
|
35
|
+
const ctx = useContext(WorkspaceLayoutContext)
|
|
36
|
+
if (!ctx) throw new Error('useWorkspaceLayoutCtx must be used within <WorkspaceLayoutProvider>')
|
|
37
|
+
return ctx
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Strip the server-only metadata so what we PUT back (and expose as `layout`)
|
|
41
|
+
// is just the persisted `WorkspaceLayout`.
|
|
42
|
+
function stripMeta(data: WorkspaceLayoutResponse): WorkspaceLayout {
|
|
43
|
+
const { cwd: _cwd, name: _name, agentId: _agentId, ...layout } = data
|
|
44
|
+
return layout
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type WorkspaceLayoutProviderProps = {
|
|
48
|
+
id: string
|
|
49
|
+
children: ReactNode
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Owns the layout query + mutation for a workspace and hands the rest of the
|
|
53
|
+
// tree a store-like `{ layout, setLayout }` API backed by React Query.
|
|
54
|
+
export function WorkspaceLayoutProvider({ id, children }: WorkspaceLayoutProviderProps) {
|
|
55
|
+
const qc = useQueryClient()
|
|
56
|
+
const query = useWorkspaceLayout(id)
|
|
57
|
+
const save = useSaveLayout(id)
|
|
58
|
+
|
|
59
|
+
// `setLayout` must be referentially stable (it feeds effect deps in the grid
|
|
60
|
+
// reconcile), so reach the latest mutate via a ref instead of closing over it.
|
|
61
|
+
const saveRef = useRef(save.mutate)
|
|
62
|
+
saveRef.current = save.mutate
|
|
63
|
+
const timer = useRef<ReturnType<typeof setTimeout> | null>(null)
|
|
64
|
+
|
|
65
|
+
const setLayout = useCallback(
|
|
66
|
+
(update: Partial<WorkspaceLayout>) => {
|
|
67
|
+
const key = workspaceKeys.layout(id)
|
|
68
|
+
const prev = qc.getQueryData<WorkspaceLayoutResponse>(key)
|
|
69
|
+
if (!prev) return
|
|
70
|
+
// Optimistic: the grid/theme reflects the change before the PUT lands.
|
|
71
|
+
qc.setQueryData<WorkspaceLayoutResponse>(key, { ...prev, ...update })
|
|
72
|
+
|
|
73
|
+
if (timer.current) clearTimeout(timer.current)
|
|
74
|
+
timer.current = setTimeout(() => {
|
|
75
|
+
timer.current = null
|
|
76
|
+
const latest = qc.getQueryData<WorkspaceLayoutResponse>(key)
|
|
77
|
+
if (latest) saveRef.current(stripMeta(latest))
|
|
78
|
+
}, 600)
|
|
79
|
+
},
|
|
80
|
+
[id, qc]
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
const value: WorkspaceLayoutContextValue = {
|
|
84
|
+
layout: query.data ? stripMeta(query.data) : DEFAULT_LAYOUT,
|
|
85
|
+
setLayout,
|
|
86
|
+
name: query.data?.name ?? null,
|
|
87
|
+
cwd: query.data?.cwd ?? null,
|
|
88
|
+
isLoading: query.isLoading
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return <WorkspaceLayoutContext value={value}>{children}</WorkspaceLayoutContext>
|
|
92
|
+
}
|
package/client/lib/cn.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { LayoutItem } from 'react-grid-layout'
|
|
2
|
+
|
|
3
|
+
import type { GridItem } from '@/client/components/WidgetGrid'
|
|
4
|
+
|
|
5
|
+
export function findFreePosition(
|
|
6
|
+
existing: LayoutItem[],
|
|
7
|
+
w: number,
|
|
8
|
+
h: number,
|
|
9
|
+
cols: number
|
|
10
|
+
): { x: number; y: number } {
|
|
11
|
+
const maxY = existing.reduce((m, l) => Math.max(m, l.y + l.h), 0)
|
|
12
|
+
|
|
13
|
+
for (let y = 0; y <= maxY + h; y++) {
|
|
14
|
+
for (let x = 0; x <= cols - w; x++) {
|
|
15
|
+
const overlaps = existing.some(
|
|
16
|
+
l => !(x + w <= l.x || l.x + l.w <= x || y + h <= l.y || l.y + l.h <= y)
|
|
17
|
+
)
|
|
18
|
+
if (!overlaps) return { x, y }
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return { x: 0, y: maxY }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function packItems(items: GridItem[], existing: LayoutItem[] = [], cols = 4): LayoutItem[] {
|
|
26
|
+
const placed: LayoutItem[] = []
|
|
27
|
+
for (const item of items) {
|
|
28
|
+
const { x, y } =
|
|
29
|
+
item.x !== undefined && item.y !== undefined
|
|
30
|
+
? { x: item.x, y: item.y }
|
|
31
|
+
: findFreePosition([...existing, ...placed], item.w, item.h, cols)
|
|
32
|
+
placed.push({ i: item.id, x, y, w: item.w, h: item.h })
|
|
33
|
+
}
|
|
34
|
+
return placed
|
|
35
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Visual-grouping pass on top of the raw `view.turns` stream.
|
|
2
|
+
//
|
|
3
|
+
// Background (see `dev/turn-spacing.md`): some providers (OpenAI Codex,
|
|
4
|
+
// notably) serialize one assistant message per agent-loop step. A run that
|
|
5
|
+
// does Read → Write → Bash often arrives as four tool-only assistant turns
|
|
6
|
+
// with no text in between. Each turn renders as its own `<TurnView>` and
|
|
7
|
+
// inherits the wider inter-turn gap, which makes the chat feel sparse.
|
|
8
|
+
//
|
|
9
|
+
// This helper merges consecutive assistant turns into a single synthetic
|
|
10
|
+
// turn whenever they're "tool-only" — i.e. the joining turn has no `text`
|
|
11
|
+
// part. A turn that contains a `text` part *always* starts a new group.
|
|
12
|
+
// User turns, replays, and any non-assistant turn pass through unchanged.
|
|
13
|
+
//
|
|
14
|
+
// Key stability: the merged turn keeps the FIRST member's `id` (and `seq`,
|
|
15
|
+
// `timestamp`, `meta`, etc.). Live-stream upserts that update a member
|
|
16
|
+
// turn's parts (tool-result fold-in, optimistic-id rename) flow through
|
|
17
|
+
// without changing the merged group's key, so React's reconciliation
|
|
18
|
+
// updates in place. New turns appended later either join the same group
|
|
19
|
+
// (same key, more parts) or start a new one (their own id).
|
|
20
|
+
import type { Part, Turn } from '@/lib/types'
|
|
21
|
+
|
|
22
|
+
function hasText(parts: Part[]): boolean {
|
|
23
|
+
return parts.some(p => p.type === 'text')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function groupTurns(turns: Turn[]): Turn[] {
|
|
27
|
+
const out: Turn[] = []
|
|
28
|
+
for (const t of turns) {
|
|
29
|
+
if (t.role !== 'assistant') {
|
|
30
|
+
out.push(t)
|
|
31
|
+
continue
|
|
32
|
+
}
|
|
33
|
+
const last = out.length > 0 ? out[out.length - 1] : null
|
|
34
|
+
const canJoin = !hasText(t.parts) && last !== null && last.role === 'assistant'
|
|
35
|
+
if (canJoin) {
|
|
36
|
+
// Replace the last entry with a merged copy. Spread `last` first so
|
|
37
|
+
// its id/timestamp/meta/origin/seq survive; only `parts` is rebuilt.
|
|
38
|
+
out[out.length - 1] = { ...last, parts: [...last.parts, ...t.parts] }
|
|
39
|
+
} else {
|
|
40
|
+
out.push(t)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return out
|
|
44
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Icons for known MCP servers. Logos under `client/assets/mcp/` are pulled
|
|
2
|
+
// from logo.dev (free pk_ token) — drop a new `<server>.png` into the folder
|
|
3
|
+
// and add an import + map entry below.
|
|
4
|
+
//
|
|
5
|
+
// Server name lookup is case-insensitive so `Notion`, `notion`, and `NOTION`
|
|
6
|
+
// all resolve. Unknown servers fall back to a generic tabler icon — see
|
|
7
|
+
// `client/components/TurnView.tsx`.
|
|
8
|
+
import atlassianIcon from '@/client/assets/mcp/atlassian.png'
|
|
9
|
+
import discordIcon from '@/client/assets/mcp/discord.png'
|
|
10
|
+
import figmaIcon from '@/client/assets/mcp/figma.png'
|
|
11
|
+
import githubIcon from '@/client/assets/mcp/github.png'
|
|
12
|
+
import gitlabIcon from '@/client/assets/mcp/gitlab.png'
|
|
13
|
+
import granolaIcon from '@/client/assets/mcp/granola.png'
|
|
14
|
+
import hubspotIcon from '@/client/assets/mcp/hubspot.png'
|
|
15
|
+
import linearIcon from '@/client/assets/mcp/linear.png'
|
|
16
|
+
import neonIcon from '@/client/assets/mcp/neon.png'
|
|
17
|
+
import notionIcon from '@/client/assets/mcp/notion.png'
|
|
18
|
+
import sentryIcon from '@/client/assets/mcp/sentry.png'
|
|
19
|
+
import slackIcon from '@/client/assets/mcp/slack.png'
|
|
20
|
+
import stripeIcon from '@/client/assets/mcp/stripe.png'
|
|
21
|
+
import supabaseIcon from '@/client/assets/mcp/supabase.png'
|
|
22
|
+
import vercelIcon from '@/client/assets/mcp/vercel.png'
|
|
23
|
+
|
|
24
|
+
const ICONS: Record<string, string> = {
|
|
25
|
+
atlassian: atlassianIcon,
|
|
26
|
+
discord: discordIcon,
|
|
27
|
+
figma: figmaIcon,
|
|
28
|
+
github: githubIcon,
|
|
29
|
+
gitlab: gitlabIcon,
|
|
30
|
+
granola: granolaIcon,
|
|
31
|
+
hubspot: hubspotIcon,
|
|
32
|
+
linear: linearIcon,
|
|
33
|
+
neon: neonIcon,
|
|
34
|
+
notion: notionIcon,
|
|
35
|
+
sentry: sentryIcon,
|
|
36
|
+
slack: slackIcon,
|
|
37
|
+
stripe: stripeIcon,
|
|
38
|
+
supabase: supabaseIcon,
|
|
39
|
+
vercel: vercelIcon
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function getMcpIcon(server: string): string | undefined {
|
|
43
|
+
return ICONS[server.toLowerCase()]
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Title-case the server name for display: `notion` → `Notion`, `granola` → `Granola`.
|
|
47
|
+
// Names with hyphens or underscores stay readable: `my-server` → `My-Server`.
|
|
48
|
+
export function formatMcpServerName(server: string): string {
|
|
49
|
+
return server
|
|
50
|
+
.split(/([_-])/)
|
|
51
|
+
.map(part => (part.length > 1 ? part[0].toUpperCase() + part.slice(1) : part))
|
|
52
|
+
.join('')
|
|
53
|
+
}
|
package/client/lib/ws.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { ChatStoreApi } from '@/client/store/chat'
|
|
2
|
+
import type { ClientMessage, StreamEvent } from '@/lib/types'
|
|
3
|
+
|
|
4
|
+
let ws: WebSocket | null = null
|
|
5
|
+
let reconnectTimer: ReturnType<typeof setTimeout> | null = null
|
|
6
|
+
let currentWorkspaceId = ''
|
|
7
|
+
let hasConnectedBefore = false
|
|
8
|
+
// The chat store for the connected workspace. Passed in by `useChat` (the store
|
|
9
|
+
// is per-workspace now), so this non-React layer writes into the right instance
|
|
10
|
+
// instead of a global singleton.
|
|
11
|
+
let chatStore: ChatStoreApi | null = null
|
|
12
|
+
const queue: ClientMessage[] = []
|
|
13
|
+
|
|
14
|
+
export function connectWs(workspaceId: string, store: ChatStoreApi) {
|
|
15
|
+
// Reconnect if workspace changed
|
|
16
|
+
if (ws && currentWorkspaceId !== workspaceId) disconnectWs()
|
|
17
|
+
chatStore = store
|
|
18
|
+
if (ws) return
|
|
19
|
+
|
|
20
|
+
currentWorkspaceId = workspaceId
|
|
21
|
+
|
|
22
|
+
if (reconnectTimer) {
|
|
23
|
+
clearTimeout(reconnectTimer)
|
|
24
|
+
reconnectTimer = null
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const socket = new WebSocket(
|
|
28
|
+
`ws://${location.host}/ws?workspace=${encodeURIComponent(workspaceId)}`
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
socket.onopen = () => {
|
|
32
|
+
ws = socket
|
|
33
|
+
for (const msg of queue) socket.send(JSON.stringify(msg))
|
|
34
|
+
queue.length = 0
|
|
35
|
+
// Reconnect after a drop: re-pull events for the active session so we
|
|
36
|
+
// pick up any turns / status updates emitted while we were offline. The
|
|
37
|
+
// initial connect doesn't trigger this — `useChat` already loads events
|
|
38
|
+
// when activeSessionId becomes set.
|
|
39
|
+
if (hasConnectedBefore && chatStore) {
|
|
40
|
+
const activeSessionId = chatStore.getState().activeSessionId
|
|
41
|
+
if (activeSessionId) {
|
|
42
|
+
chatStore.getState().loadEvents(currentWorkspaceId, activeSessionId)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
hasConnectedBefore = true
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
socket.onmessage = e => {
|
|
49
|
+
const data = JSON.parse(e.data) as Record<string, unknown>
|
|
50
|
+
if (!chatStore) return
|
|
51
|
+
const store = chatStore.getState()
|
|
52
|
+
|
|
53
|
+
// Control frames first
|
|
54
|
+
if (data.type === 'status') {
|
|
55
|
+
store.setProcessing(data.sessionId as string, data.processing as boolean)
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
if (data.type === 'session_renamed') {
|
|
59
|
+
const from = data.from as string
|
|
60
|
+
const to = data.to as string
|
|
61
|
+
store.renameSession(from, to)
|
|
62
|
+
if (store.activeSessionId === from) store.setActiveSession(to)
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
if (data.type === 'workspace:switch') {
|
|
66
|
+
onWorkspaceSwitch?.(data.workspaceId as string)
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// StreamEvent frames are tagged by `kind` and carry a sessionId
|
|
71
|
+
const sid = data.sessionId as string | undefined
|
|
72
|
+
if (!sid) return
|
|
73
|
+
if (
|
|
74
|
+
data.kind === 'snapshot' ||
|
|
75
|
+
data.kind === 'turn' ||
|
|
76
|
+
data.kind === 'notice' ||
|
|
77
|
+
data.kind === 'result'
|
|
78
|
+
) {
|
|
79
|
+
store.append(sid, data as unknown as StreamEvent)
|
|
80
|
+
}
|
|
81
|
+
if (data.kind === 'error' && typeof data.content === 'string') {
|
|
82
|
+
store.setError(sid, data.content)
|
|
83
|
+
}
|
|
84
|
+
if (data.kind === 'stopped') {
|
|
85
|
+
// Server confirmed abort — make sure the spinner is cleared even if
|
|
86
|
+
// the trailing `status` frame is delayed or lost.
|
|
87
|
+
store.setProcessing(sid, false)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
socket.onclose = () => {
|
|
92
|
+
ws = null
|
|
93
|
+
reconnectTimer = setTimeout(() => {
|
|
94
|
+
if (chatStore) connectWs(currentWorkspaceId, chatStore)
|
|
95
|
+
}, 1000)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
socket.onerror = () => {
|
|
99
|
+
socket.close()
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function sendWs(msg: ClientMessage) {
|
|
104
|
+
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
105
|
+
ws.send(JSON.stringify(msg))
|
|
106
|
+
} else {
|
|
107
|
+
queue.push(msg)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function disconnectWs() {
|
|
112
|
+
if (reconnectTimer) {
|
|
113
|
+
clearTimeout(reconnectTimer)
|
|
114
|
+
reconnectTimer = null
|
|
115
|
+
}
|
|
116
|
+
if (ws) {
|
|
117
|
+
ws.close()
|
|
118
|
+
ws = null
|
|
119
|
+
}
|
|
120
|
+
queue.length = 0
|
|
121
|
+
hasConnectedBefore = false
|
|
122
|
+
chatStore = null
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
let onWorkspaceSwitch: ((workspaceId: string) => void) | null = null
|
|
126
|
+
|
|
127
|
+
export function setWorkspaceSwitchHandler(fn: ((workspaceId: string) => void) | null) {
|
|
128
|
+
onWorkspaceSwitch = fn
|
|
129
|
+
}
|
package/client/main.tsx
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
2
|
+
import { Agentation } from 'agentation'
|
|
3
|
+
import { createRoot } from 'react-dom/client'
|
|
4
|
+
import { Router } from 'wouter'
|
|
5
|
+
|
|
6
|
+
import { AppRouter } from './components/App'
|
|
7
|
+
|
|
8
|
+
const queryClient = new QueryClient()
|
|
9
|
+
|
|
10
|
+
export function mount(el: HTMLElement) {
|
|
11
|
+
function Root() {
|
|
12
|
+
return (
|
|
13
|
+
<QueryClientProvider client={queryClient}>
|
|
14
|
+
<Router>
|
|
15
|
+
<AppRouter />
|
|
16
|
+
</Router>
|
|
17
|
+
{process.env.NODE_ENV === 'development' && <Agentation />}
|
|
18
|
+
</QueryClientProvider>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
createRoot(el).render(<Root />)
|
|
23
|
+
}
|