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.
Files changed (106) hide show
  1. package/LICENSE +95 -0
  2. package/README.md +71 -0
  3. package/bin/moi.mjs +25 -0
  4. package/bunfig.toml +3 -0
  5. package/client/CLAUDE.md +12 -0
  6. package/client/api/workspaces.ts +158 -0
  7. package/client/assets/claude.svg +3 -0
  8. package/client/assets/favicon.png +0 -0
  9. package/client/assets/hermes-nous.png +0 -0
  10. package/client/assets/mcp/.gitkeep +0 -0
  11. package/client/assets/mcp/atlassian.png +0 -0
  12. package/client/assets/mcp/discord.png +0 -0
  13. package/client/assets/mcp/figma.png +0 -0
  14. package/client/assets/mcp/github.png +0 -0
  15. package/client/assets/mcp/gitlab.png +0 -0
  16. package/client/assets/mcp/granola.png +0 -0
  17. package/client/assets/mcp/hubspot.png +0 -0
  18. package/client/assets/mcp/linear.png +0 -0
  19. package/client/assets/mcp/neon.png +0 -0
  20. package/client/assets/mcp/notion.png +0 -0
  21. package/client/assets/mcp/sentry.png +0 -0
  22. package/client/assets/mcp/slack.png +0 -0
  23. package/client/assets/mcp/stripe.png +0 -0
  24. package/client/assets/mcp/supabase.png +0 -0
  25. package/client/assets/mcp/vercel.png +0 -0
  26. package/client/assets/moi-logo.svg +11 -0
  27. package/client/assets/openclaw.svg +22 -0
  28. package/client/components/App.tsx +35 -0
  29. package/client/components/BottomPanel.tsx +33 -0
  30. package/client/components/ChatInput.tsx +62 -0
  31. package/client/components/ChatPanel.tsx +206 -0
  32. package/client/components/ChatPopup.tsx +60 -0
  33. package/client/components/CustomizePanel.tsx +117 -0
  34. package/client/components/HiddenPanel.tsx +79 -0
  35. package/client/components/HomePage.tsx +17 -0
  36. package/client/components/MarkdownContent.tsx +41 -0
  37. package/client/components/ThreadSelector.tsx +88 -0
  38. package/client/components/TurnView.tsx +618 -0
  39. package/client/components/WidgetErrorBoundary.tsx +46 -0
  40. package/client/components/WidgetFrame.tsx +66 -0
  41. package/client/components/WidgetGrid.tsx +113 -0
  42. package/client/components/WidgetShell.tsx +44 -0
  43. package/client/components/Widgets.tsx +132 -0
  44. package/client/components/WorkspacePreview.tsx +48 -0
  45. package/client/components/WorkspacesPage.tsx +237 -0
  46. package/client/components/layout/SidebarLayout.tsx +260 -0
  47. package/client/components/playground/LedLogo.tsx +181 -0
  48. package/client/components/playground/PixelPainter.tsx +105 -0
  49. package/client/components/playground/PlaygroundPage.tsx +71 -0
  50. package/client/components/routes/workspace/[id].tsx +282 -0
  51. package/client/components/ui/button.tsx +48 -0
  52. package/client/components/ui/dropdown-menu.tsx +257 -0
  53. package/client/components/ui/input.tsx +21 -0
  54. package/client/components/ui/popover.tsx +79 -0
  55. package/client/components/ui/textarea.tsx +18 -0
  56. package/client/externalize-react.ts +29 -0
  57. package/client/hooks/useChat.ts +88 -0
  58. package/client/hooks/useFitsSidebar.ts +34 -0
  59. package/client/hooks/useGridReconcile.ts +73 -0
  60. package/client/hooks/useMeiEvents.ts +66 -0
  61. package/client/hooks/useScrollFade.ts +38 -0
  62. package/client/hooks/useWidget.ts +72 -0
  63. package/client/hooks/useWidgetList.ts +30 -0
  64. package/client/hooks/useWorkspaceTheme.ts +76 -0
  65. package/client/index.css +182 -0
  66. package/client/index.html +43 -0
  67. package/client/index.tsx +19 -0
  68. package/client/lib/WorkspaceContext.tsx +24 -0
  69. package/client/lib/WorkspaceLayoutContext.tsx +92 -0
  70. package/client/lib/cn.ts +6 -0
  71. package/client/lib/grid-pack.ts +35 -0
  72. package/client/lib/group-turns.ts +44 -0
  73. package/client/lib/mcp-icons.ts +53 -0
  74. package/client/lib/ws.ts +129 -0
  75. package/client/main.tsx +23 -0
  76. package/client/store/chat.tsx +162 -0
  77. package/client/store/ui.ts +21 -0
  78. package/client/theme.css +66 -0
  79. package/lib/claude-adapter.ts +602 -0
  80. package/lib/format.ts +212 -0
  81. package/lib/themes.ts +89 -0
  82. package/lib/types.ts +144 -0
  83. package/package.json +117 -0
  84. package/server/CLAUDE.md +6 -0
  85. package/server/agent.ts +132 -0
  86. package/server/build-widget.ts +343 -0
  87. package/server/cli.ts +632 -0
  88. package/server/constants.ts +3 -0
  89. package/server/control.ts +98 -0
  90. package/server/functions-worker.ts +89 -0
  91. package/server/functions.ts +171 -0
  92. package/server/layout.ts +83 -0
  93. package/server/openclaw-adapter.ts +242 -0
  94. package/server/openclaw-gateway.ts +255 -0
  95. package/server/openclaw-session.ts +485 -0
  96. package/server/openclaw-strip.ts +134 -0
  97. package/server/openclaw.ts +206 -0
  98. package/server/registry.ts +150 -0
  99. package/server/skills-template.ts +21 -0
  100. package/server/state.ts +87 -0
  101. package/server/theme.ts +55 -0
  102. package/server/web.ts +321 -0
  103. package/server/widgets.ts +254 -0
  104. package/tsconfig.json +21 -0
  105. package/workspace/.claude/skills/widgets/DESIGN.md +630 -0
  106. package/workspace/.claude/skills/widgets/SKILL.md +176 -0
@@ -0,0 +1,162 @@
1
+ import { type ReactNode, createContext, useContext, useEffect, useRef } from 'react'
2
+
3
+ import { useStore } from 'zustand'
4
+ import { createStore } from 'zustand/vanilla'
5
+
6
+ import { applyEvent, emptyViewState } from '@/lib/format'
7
+ import type { StreamEvent, ViewState } from '@/lib/types'
8
+
9
+ // Per-workspace chat state: which thread is active, plus per-session
10
+ // events/views/status. One store instance per mounted workspace (created by
11
+ // ChatStoreProvider), so switching workspaces tears it down — nothing bleeds
12
+ // across workspaces and `activeSessionId` is naturally scoped to one.
13
+ //
14
+ // The session *list* is server data and lives in React Query
15
+ // (useWorkspaceSessions). This store holds only client-only state that can't be
16
+ // re-fetched: the live event stream, its materialized view, optimistic turns,
17
+ // processing flags, and errors. `events`/`views` are kept as a working copy
18
+ // (rather than derived from React Query) so live websocket frames fold in
19
+ // incrementally via applyEvent instead of re-reducing the whole log per frame.
20
+ export type ChatStore = {
21
+ // The agent's working directory (workspace path), shown in turn metadata.
22
+ cwd: string | null
23
+ setCwd: (cwd: string | null) => void
24
+
25
+ // The session/thread currently shown.
26
+ activeSessionId: string | null
27
+ setActiveSession: (sessionId: string | null) => void
28
+
29
+ // Per-session state, keyed by sessionId.
30
+ events: Record<string, StreamEvent[]>
31
+ views: Record<string, ViewState>
32
+ processing: Record<string, boolean>
33
+ // Last server-emitted error per session — surfaced as a dismissable banner
34
+ // above the chat. Cleared when the user types or stops the run.
35
+ errors: Record<string, string | null>
36
+
37
+ setEvents: (sessionId: string, evs: StreamEvent[]) => void
38
+ append: (sessionId: string, ev: StreamEvent) => void
39
+ setProcessing: (sessionId: string, value: boolean) => void
40
+ setError: (sessionId: string, message: string | null) => void
41
+ renameSession: (from: string, to: string) => void
42
+ loadEvents: (workspaceId: string, sessionId: string) => Promise<void>
43
+ }
44
+
45
+ async function fetchEvents(workspaceId: string, sessionId: string): Promise<StreamEvent[]> {
46
+ const res = await fetch(`/api/workspaces/${workspaceId}/sessions/${sessionId}/events`)
47
+ if (!res.ok) return []
48
+ return (await res.json()) as StreamEvent[]
49
+ }
50
+
51
+ function materialize(events: StreamEvent[]): ViewState {
52
+ return events.reduce(applyEvent, emptyViewState())
53
+ }
54
+
55
+ export function createChatStore(initial: { cwd: string | null }) {
56
+ return createStore<ChatStore>()(set => ({
57
+ cwd: initial.cwd,
58
+ setCwd: cwd => set({ cwd }),
59
+
60
+ activeSessionId: null,
61
+ setActiveSession: sessionId => set({ activeSessionId: sessionId }),
62
+
63
+ events: {},
64
+ views: {},
65
+ processing: {},
66
+ errors: {},
67
+
68
+ loadEvents: async (workspaceId: string, sessionId: string) => {
69
+ const evs = await fetchEvents(workspaceId, sessionId)
70
+ set(s => ({
71
+ events: { ...s.events, [sessionId]: evs },
72
+ views: { ...s.views, [sessionId]: materialize(evs) }
73
+ }))
74
+ },
75
+
76
+ setEvents: (sessionId, evs) =>
77
+ set(s => ({
78
+ events: { ...s.events, [sessionId]: evs },
79
+ views: { ...s.views, [sessionId]: materialize(evs) }
80
+ })),
81
+
82
+ append: (sessionId, ev) =>
83
+ set(s => {
84
+ const prior = s.events[sessionId] ?? []
85
+ const priorView = s.views[sessionId] ?? emptyViewState()
86
+ return {
87
+ events: { ...s.events, [sessionId]: [...prior, ev] },
88
+ views: { ...s.views, [sessionId]: applyEvent(priorView, ev) }
89
+ }
90
+ }),
91
+
92
+ setProcessing: (sessionId, value) =>
93
+ set(s => ({ processing: { ...s.processing, [sessionId]: value } })),
94
+
95
+ setError: (sessionId, message) => set(s => ({ errors: { ...s.errors, [sessionId]: message } })),
96
+
97
+ renameSession: (from, to) =>
98
+ set(s => {
99
+ const events = { ...s.events }
100
+ const views = { ...s.views }
101
+ const processing = { ...s.processing }
102
+ const errors = { ...s.errors }
103
+ if (from in events) {
104
+ events[to] = events[from]
105
+ delete events[from]
106
+ }
107
+ if (from in views) {
108
+ views[to] = views[from]
109
+ delete views[from]
110
+ }
111
+ if (from in processing) {
112
+ processing[to] = processing[from]
113
+ delete processing[from]
114
+ }
115
+ if (from in errors) {
116
+ errors[to] = errors[from]
117
+ delete errors[from]
118
+ }
119
+ return { events, views, processing, errors }
120
+ })
121
+ }))
122
+ }
123
+
124
+ export type ChatStoreApi = ReturnType<typeof createChatStore>
125
+
126
+ const ChatStoreContext = createContext<ChatStoreApi | null>(null)
127
+
128
+ type ChatStoreProviderProps = {
129
+ // Workspace path, threaded into the store so turn metadata can show it.
130
+ cwd: string | null
131
+ children: ReactNode
132
+ }
133
+
134
+ // Creates one chat store per mount and provides it to the subtree. Mount maps
135
+ // to a workspace, so unmounting (a workspace switch) discards all of its chat
136
+ // state cleanly.
137
+ export function ChatStoreProvider({ cwd, children }: ChatStoreProviderProps) {
138
+ const storeRef = useRef<ChatStoreApi | null>(null)
139
+ if (storeRef.current === null) storeRef.current = createChatStore({ cwd })
140
+
141
+ // Layout (and therefore cwd) resolves after mount; keep the store in sync.
142
+ useEffect(() => {
143
+ storeRef.current?.getState().setCwd(cwd)
144
+ }, [cwd])
145
+
146
+ return <ChatStoreContext value={storeRef.current}>{children}</ChatStoreContext>
147
+ }
148
+
149
+ // Reactive selector hook — re-renders when the selected slice changes.
150
+ export function useChatStore<T>(selector: (state: ChatStore) => T): T {
151
+ const store = useContext(ChatStoreContext)
152
+ if (!store) throw new Error('useChatStore must be used within a ChatStoreProvider')
153
+ return useStore(store, selector)
154
+ }
155
+
156
+ // The raw store handle — for imperative reads/writes (getState/setState) and
157
+ // for handing to the non-React websocket layer.
158
+ export function useChatStoreApi(): ChatStoreApi {
159
+ const store = useContext(ChatStoreContext)
160
+ if (!store) throw new Error('useChatStoreApi must be used within a ChatStoreProvider')
161
+ return store
162
+ }
@@ -0,0 +1,21 @@
1
+ import { create } from 'zustand'
2
+ import { persist } from 'zustand/middleware'
3
+
4
+ // Global, device-local UI preferences — persisted to localStorage so they
5
+ // survive reloads. Server-owned or per-workspace state does NOT belong here.
6
+ type UiStore = {
7
+ sidebarCollapsed: boolean
8
+ toggleSidebar: () => void
9
+ setSidebarCollapsed: (collapsed: boolean) => void
10
+ }
11
+
12
+ export const useUiStore = create<UiStore>()(
13
+ persist(
14
+ set => ({
15
+ sidebarCollapsed: false,
16
+ toggleSidebar: () => set(s => ({ sidebarCollapsed: !s.sidebarCollapsed })),
17
+ setSidebarCollapsed: collapsed => set({ sidebarCollapsed: collapsed })
18
+ }),
19
+ { name: 'moi:ui' }
20
+ )
21
+ )
@@ -0,0 +1,66 @@
1
+ /*
2
+ * Shared design-token map for both the host app (client/index.css) and
3
+ * widget bundles (server/build-widget.ts emits an `@import` to this file
4
+ * into the widget's synthetic CSS).
5
+ *
6
+ * The actual CSS variables (`--background`, `--foreground`, `--card`, etc.)
7
+ * are owned by the host and declared on `:root` / `.dark` in
8
+ * `client/index.css`. This file only maps Tailwind's `--color-*` /
9
+ * `--radius-*` tokens onto those host-owned variables via `@theme inline`,
10
+ * which:
11
+ * - generates utilities like `.bg-background { background-color: var(--background) }`
12
+ * - does NOT emit `--color-background` or `--background` into the output
13
+ *
14
+ * Net effect: widgets compile classes like `bg-foreground/20`, `text-muted`,
15
+ * `rounded-xl`, and pick up the host's runtime theme without redefining
16
+ * any variable themselves.
17
+ */
18
+
19
+ @theme inline {
20
+ --color-background: var(--background);
21
+ --color-foreground: var(--foreground);
22
+ --color-card: var(--card);
23
+ --color-card-foreground: var(--card-foreground);
24
+ --color-popover: var(--popover);
25
+ --color-popover-foreground: var(--popover-foreground);
26
+ --color-primary: var(--primary);
27
+ --color-primary-foreground: var(--primary-foreground);
28
+ --color-secondary: var(--secondary);
29
+ --color-secondary-foreground: var(--secondary-foreground);
30
+ --color-muted: var(--muted);
31
+ --color-muted-foreground: var(--muted-foreground);
32
+ --color-accent: var(--accent);
33
+ --color-accent-foreground: var(--accent-foreground);
34
+ --color-destructive: var(--destructive);
35
+ --color-border: var(--border);
36
+ --color-input: var(--input);
37
+ --color-ring: var(--ring);
38
+
39
+ --radius-xs: calc(var(--radius) * 0.5);
40
+ --radius-sm: calc(var(--radius) * 0.625);
41
+ --radius-md: calc(var(--radius) * 0.75);
42
+ --radius-lg: calc(var(--radius) * 0.875);
43
+ --radius-xl: var(--radius);
44
+ --radius-2xl: calc(var(--radius) * 1.25);
45
+ --radius-3xl: calc(var(--radius) * 1.5);
46
+ --radius-4xl: calc(var(--radius) * 2);
47
+
48
+ --shadow-xs:
49
+ 0px 0px 0px 1px rgba(0, 0, 0, 0.06), 0px 1px 2px -1px rgba(0, 0, 0, 0.06),
50
+ 0px 2px 4px 0px rgba(0, 0, 0, 0.04);
51
+ --shadow-sm:
52
+ 0px 0px 0px 1px rgba(0, 0, 0, 0.08), 0px 1px 2px -1px rgba(0, 0, 0, 0.08),
53
+ 0px 2px 4px 0px rgba(0, 0, 0, 0.06);
54
+ --shadow-md:
55
+ 0px 0px 0px 1px rgba(0, 0, 0, 0.06), 0px 2px 4px -1px rgba(0, 0, 0, 0.08),
56
+ 0px 6px 12px -2px rgba(0, 0, 0, 0.06);
57
+ --shadow-lg:
58
+ 0px 0px 0px 1px rgba(0, 0, 0, 0.05), 0px 3px 6px -1px rgba(0, 0, 0, 0.08),
59
+ 0px 10px 20px -4px rgba(0, 0, 0, 0.08);
60
+ --shadow-xl:
61
+ 0px 0px 0px 1px rgba(0, 0, 0, 0.04), 0px 4px 8px -2px rgba(0, 0, 0, 0.08),
62
+ 0px 16px 32px -6px rgba(0, 0, 0, 0.1);
63
+ --shadow-2xl:
64
+ 0px 0px 0px 1px rgba(0, 0, 0, 0.04), 0px 6px 12px -2px rgba(0, 0, 0, 0.08),
65
+ 0px 24px 48px -8px rgba(0, 0, 0, 0.12);
66
+ }