moi-computer 0.13.1-next.3 → 0.13.1-next.4

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 (82) hide show
  1. package/client/app/app-provider.tsx +14 -20
  2. package/client/app/app-router.tsx +5 -8
  3. package/client/app/routes/workspace-route.tsx +28 -11
  4. package/client/app/shell/sidebar-layout.tsx +5 -10
  5. package/client/features/app-settings/api.ts +3 -3
  6. package/client/features/applets/applet-cache.ts +1 -2
  7. package/client/features/applets/use-applet.ts +18 -20
  8. package/client/features/chat/chat-store.ts +1 -1
  9. package/client/features/chat/connection/chat-connection.ts +25 -68
  10. package/client/features/chat/connection/chat-frames.ts +20 -32
  11. package/client/features/chat/sessions/api.ts +2 -2
  12. package/client/features/collab/presence/client.ts +63 -83
  13. package/client/features/collab/presence/provider.tsx +8 -2
  14. package/client/features/dev/chat-states-page.tsx +1 -1
  15. package/client/features/dev/harness-debug-page.tsx +2 -2
  16. package/client/features/scratchpad/scratchpad.tsx +29 -20
  17. package/client/features/views/api.ts +5 -6
  18. package/client/features/workspace/api.ts +6 -11
  19. package/client/features/workspace/harness-transition.ts +3 -5
  20. package/client/features/workspace/remote.ts +9 -0
  21. package/client/features/workspace/settings/use-env-vars.ts +4 -4
  22. package/client/features/workspace/use-workspace-navigation.ts +1 -1
  23. package/client/features/workspace/use-workspace-socket.ts +51 -0
  24. package/client/features/workspace/workspace-content.tsx +3 -7
  25. package/client/features/workspace/workspace-layout-context.tsx +6 -13
  26. package/client/features/workspace/workspace-state.ts +17 -6
  27. package/client/runtime/app-context.ts +2 -2
  28. package/client/runtime/app-events.ts +75 -0
  29. package/client/runtime/reconnecting-socket.ts +115 -0
  30. package/client/runtime/{use-workspace-events.ts → use-client-events.ts} +9 -10
  31. package/dist/{chunk-f44cs6mw.js → chunk-0t8m1ehd.js} +2 -2
  32. package/dist/chunk-851bx8ss.js +72 -0
  33. package/dist/{chunk-xj1pjhng.js → chunk-c8g5x288.js} +1 -1
  34. package/dist/chunk-cty37f3v.js +1 -0
  35. package/dist/chunk-dy6f6h3e.js +5 -0
  36. package/dist/chunk-j6928pwm.js +1 -0
  37. package/dist/{chunk-r95acex1.js → chunk-k32585ne.js} +70 -70
  38. package/dist/chunk-qtkv7hp8.js +2 -0
  39. package/dist/chunk-rh58dc0y.js +2 -0
  40. package/dist/{chunk-a865c7x4.js → chunk-wjbejzek.js} +1 -1
  41. package/dist/index.html +1 -1
  42. package/lib/events.ts +61 -0
  43. package/lib/ids.ts +2 -8
  44. package/lib/types.ts +12 -15
  45. package/package.json +1 -1
  46. package/server/AGENTS.md +3 -3
  47. package/server/README.md +29 -15
  48. package/server/api/index.ts +54 -35
  49. package/server/applets/views.ts +15 -14
  50. package/server/applets/widgets.ts +4 -3
  51. package/server/cli/commands/refresh.ts +2 -5
  52. package/server/control.ts +24 -33
  53. package/server/events.ts +14 -13
  54. package/server/harness/README.md +7 -7
  55. package/server/harness/acp/session.ts +9 -5
  56. package/server/harness/auth.ts +7 -30
  57. package/server/harness/claude-code/session.ts +8 -4
  58. package/server/harness/codex/NOTES.md +1 -1
  59. package/server/harness/codex/session.ts +18 -10
  60. package/server/harness/hermes/NOTES.md +3 -3
  61. package/server/harness/openclaw/session.ts +9 -5
  62. package/server/onboarding/jobs.ts +7 -7
  63. package/server/operations/commands.ts +1 -1
  64. package/server/scratchpad/executor.ts +2 -2
  65. package/server/scratchpad/relay.ts +3 -3
  66. package/server/sessions/archive.ts +1 -1
  67. package/server/sessions/lifecycle.ts +1 -1
  68. package/server/sessions/pending-views.ts +17 -11
  69. package/server/web.ts +40 -30
  70. package/server/workspace-state/index.ts +15 -4
  71. package/server/workspaces/config.ts +14 -13
  72. package/server/workspaces/env-apply.ts +1 -1
  73. package/server/workspaces/layout.ts +40 -7
  74. package/server/workspaces/shared.ts +1 -1
  75. package/client/features/scratchpad/scratch-executor.ts +0 -20
  76. package/client/runtime/workspace-events.ts +0 -168
  77. package/dist/chunk-0h4zypgf.js +0 -1
  78. package/dist/chunk-1tksq43z.js +0 -72
  79. package/dist/chunk-6gxf0xr8.js +0 -5
  80. package/dist/chunk-h3qag4a6.js +0 -2
  81. package/dist/chunk-q2tpy0h7.js +0 -2
  82. package/dist/chunk-w5h9grdr.js +0 -1
@@ -1,168 +0,0 @@
1
- import type { NavigationRequest } from '@/lib/navigation'
2
- import type {
3
- AppSettings,
4
- CompiledView,
5
- HarnessAvailability,
6
- HarnessStatus,
7
- WidgetInfo,
8
- HarnessType,
9
- WorkspaceState
10
- } from '@/lib/types'
11
-
12
- export type WorkspaceEvent =
13
- | { type: 'connection:opened' }
14
- | {
15
- type: 'harness-status:changed'
16
- harness: HarnessType
17
- status: HarnessStatus
18
- }
19
- | { type: 'workspace-harness:switched'; workspaceId: string; harness: HarnessType }
20
- | { type: 'widget:updated'; workspaceId?: string; name: string }
21
- | { type: 'widget-layout:updated'; workspaceId: string; widgets: WidgetInfo[] }
22
- // `moi refresh` — cache-bust and re-fetch applets without a rebuild. `only`
23
- // narrows to one kind; absent means both widgets and views.
24
- | { type: 'applets:refresh'; workspaceId?: string; only?: 'widgets' | 'views' }
25
- | { type: 'view:updated'; workspaceId?: string; name: string }
26
- | { type: 'view-layout:updated'; workspaceId: string; views: CompiledView[] }
27
- | { type: 'view:deleted'; workspaceId: string; name: string }
28
- // A workspace's chat state changed (pin, selection, chat settings, views
29
- // being built). Carries the whole state, so caches update without a refetch.
30
- | { type: 'state:changed'; workspaceId: string; state: WorkspaceState }
31
- // `origin` on an event is the browser tab whose write caused it (absent for
32
- // CLI and agent changes), so that tab can skip its own echo. See
33
- // client/lib/browser-tab-id.ts.
34
- | { type: 'theme:updated'; workspaceId: string; origin?: string }
35
- | { type: 'workspace:updated'; workspaceId: string; origin?: string }
36
- // The registry list changed (reorder, create) without touching any open
37
- // workspace's layout — clients refetch just the sidebar list.
38
- | { type: 'workspaces-list:updated'; origin?: string }
39
- // A workspace's env changed outside the UI — refetch the env view.
40
- | { type: 'env:updated'; workspaceId: string }
41
- // Workspace readiness changed. Patch its cache without a refetch.
42
- | {
43
- type: 'harness:updated'
44
- workspaceId: string
45
- availability: HarnessAvailability
46
- }
47
- // The Scratchpad canvas for `workspaceId` was saved — open tabs reload from
48
- // disk. `origin` is the tab that wrote it, so that tab can skip its own echo.
49
- | { type: 'scratchpad:updated'; workspaceId: string; origin?: string }
50
- // App settings changed (PATCH /api/settings from any client) — carries the
51
- // new value so caches update without a refetch.
52
- | { type: 'settings:updated'; settings: AppSettings }
53
- | NavigationRequest
54
-
55
- export type WorkspaceEventHandler = (event: WorkspaceEvent) => void
56
-
57
- export type WorkspaceEventsClientOptions = {
58
- // Delay before reopening after a drop. It doubles on repeated drops, up to
59
- // the max, so a downed server isn't hammered; it resets once a socket opens.
60
- reconnectBaseDelayMs?: number
61
- reconnectMaxDelayMs?: number
62
- }
63
-
64
- // The page's workspace events socket. `AppProvider` opens it when the app
65
- // mounts and closes it when the app unmounts; subscribers come and go freely
66
- // in between without touching the connection. A dropped socket reopens on its
67
- // own. Framework-free, so the connection logic is testable without React.
68
- export class WorkspaceEventsClient {
69
- private readonly listeners = new Set<WorkspaceEventHandler>()
70
- private readonly baseDelayMs: number
71
- private readonly maxDelayMs: number
72
- // The socket being opened or open; undefined while disconnected.
73
- private socket: WebSocket | undefined
74
- private closed = true
75
- private reconnectAttempt = 0
76
- private reconnectTimer: ReturnType<typeof setTimeout> | undefined
77
- private shownWorkspace: string | undefined
78
-
79
- constructor(
80
- private readonly url: string,
81
- options: WorkspaceEventsClientOptions = {}
82
- ) {
83
- this.baseDelayMs = options.reconnectBaseDelayMs ?? 1000
84
- this.maxDelayMs = options.reconnectMaxDelayMs ?? 30_000
85
- }
86
-
87
- connect() {
88
- this.closed = false
89
- this.open()
90
- }
91
-
92
- // Shut the connection down for good; no reconnect follows.
93
- close() {
94
- this.closed = true
95
- clearTimeout(this.reconnectTimer)
96
- const socket = this.socket
97
- this.socket = undefined
98
- socket?.close()
99
- }
100
-
101
- subscribe(handler: WorkspaceEventHandler): () => void {
102
- this.listeners.add(handler)
103
- return () => {
104
- this.listeners.delete(handler)
105
- }
106
- }
107
-
108
- send(message: object) {
109
- if (this.socket?.readyState !== WebSocket.OPEN) return
110
- this.socket.send(JSON.stringify(message))
111
- }
112
-
113
- // The workspace this tab shows, for the server's navigation relay. Sent now
114
- // and again on every reconnect.
115
- get navigationWorkspace(): string | undefined {
116
- return this.shownWorkspace
117
- }
118
-
119
- setNavigationWorkspace(workspaceId: string | undefined) {
120
- this.shownWorkspace = workspaceId
121
- this.sendNavigationPresence()
122
- }
123
-
124
- sendNavigationPresence() {
125
- this.send({
126
- type: 'navigation:presence',
127
- // The wire format uses `null` for "no workspace".
128
- workspaceId: this.shownWorkspace ?? null,
129
- focused: document.visibilityState === 'visible' && document.hasFocus()
130
- })
131
- }
132
-
133
- private open() {
134
- if (this.closed || this.socket) return
135
- const socket = new WebSocket(this.url)
136
- this.socket = socket
137
-
138
- socket.onopen = () => {
139
- this.reconnectAttempt = 0
140
- this.sendNavigationPresence()
141
- for (const handler of this.listeners) handler({ type: 'connection:opened' })
142
- }
143
-
144
- socket.onmessage = event => {
145
- try {
146
- const data = JSON.parse(event.data) as WorkspaceEvent
147
- for (const handler of this.listeners) handler(data)
148
- } catch {}
149
- }
150
-
151
- socket.onclose = () => {
152
- // A socket this client already let go of (closed or replaced).
153
- if (this.socket !== socket) return
154
- this.socket = undefined
155
- if (!this.closed) this.scheduleReconnect()
156
- }
157
-
158
- socket.onerror = () => {
159
- socket.close()
160
- }
161
- }
162
-
163
- private scheduleReconnect() {
164
- const delay = Math.min(this.baseDelayMs * 2 ** this.reconnectAttempt, this.maxDelayMs)
165
- this.reconnectAttempt++
166
- this.reconnectTimer = setTimeout(() => this.open(), delay)
167
- }
168
- }
@@ -1 +0,0 @@
1
- import{Qn}from"/chunk-xj1pjhng.js";export{Qn as sanitizeSvg};