moi-computer 0.11.1-next.2 → 0.11.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.
- package/README.md +2 -2
- package/client/app/AppRouter.tsx +2 -2
- package/client/app/routes/WorkspaceRoute.tsx +7 -9
- package/client/app/shell/SidebarLayout.tsx +18 -15
- package/client/components/shared/BottomPanel.tsx +26 -14
- package/client/components/shared/PanelHeader.tsx +1 -1
- package/client/components/shared/ReorderableList.tsx +7 -2
- package/client/components/shared/WorkspaceIcon.tsx +92 -0
- package/client/components/ui/alert-dialog.tsx +1 -0
- package/client/components/ui/checkbox.tsx +1 -0
- package/client/components/ui/inline-input.tsx +84 -0
- package/client/components/ui/toast.tsx +2 -2
- package/client/features/applets/AppletMount.tsx +1 -1
- package/client/features/applets/applet-cache.ts +3 -3
- package/client/features/applets/applet-runtime.ts +147 -108
- package/client/features/applets/applet-styles.ts +2 -2
- package/client/features/applets/applet-thumbnail.ts +6 -8
- package/client/features/applets/useApplet.ts +10 -9
- package/client/features/chat/ChatPanel.tsx +19 -10
- package/client/features/chat/ChatPopup.tsx +7 -2
- package/client/features/chat/applet-chat-intents.ts +170 -0
- package/client/features/chat/chat-send.ts +103 -62
- package/client/features/chat/chat-store.ts +50 -59
- package/client/features/chat/composer/ChatComposer.tsx +43 -132
- package/client/features/chat/composer/ModelPicker.tsx +3 -16
- package/client/features/chat/composer/attachments/AttachmentChip.tsx +99 -0
- package/client/features/chat/composer/attachments/DrawingAttachmentChip.tsx +37 -0
- package/client/features/chat/composer/attachments/FileAttachmentChip.tsx +22 -0
- package/client/features/chat/composer/attachments/TextAttachmentChip.tsx +11 -0
- package/client/features/chat/composer/attachments/draft-attachments.ts +168 -0
- package/client/features/chat/composer/attachments/types.ts +25 -0
- package/client/features/chat/composer/attachments/uploads.ts +26 -0
- package/client/features/chat/{chat-connection.ts → connection/chat-connection.ts} +1 -1
- package/client/features/chat/{chat-frames.ts → connection/chat-frames.ts} +2 -2
- package/client/features/chat/{ChatEmptyState.tsx → messages/ChatEmptyState.tsx} +16 -11
- package/client/features/chat/{MarkdownContent.tsx → messages/MarkdownContent.tsx} +16 -1
- package/client/features/chat/{TurnView.tsx → messages/TurnView.tsx} +22 -15
- package/client/features/chat/{tool-group → messages/tool-group}/SubagentCard.tsx +1 -1
- package/client/features/chat/{tool-group → messages/tool-group}/TimelineRow.tsx +2 -2
- package/client/features/chat/{tool-group → messages/tool-group}/ToolCallGroup.tsx +1 -1
- package/client/features/chat/{ChatSelector.tsx → sessions/ChatSelector.tsx} +3 -3
- package/client/features/chat/{api.ts → sessions/api.ts} +1 -1
- package/client/features/chat/useChat.ts +32 -15
- package/client/features/dev/ChatStatesPage.tsx +5 -6
- package/client/features/dev/HarnessDebugPage.tsx +10 -7
- package/client/features/dev/ToolCallsPage.tsx +1 -1
- package/client/features/dev/UiComponentPreviews.tsx +21 -0
- package/client/features/dev/chat-states-fixtures.ts +13 -2
- package/client/features/drawings/useChatAnnotation.ts +17 -17
- package/client/features/drawings/useDrawingLayer.ts +7 -9
- package/client/features/drawings/useViewBuilderSketch.ts +18 -15
- package/client/features/home/HomePage.tsx +8 -7
- package/client/features/home/WorkspacePreview.tsx +1 -1
- package/client/features/home/workspace-presentation.tsx +1 -11
- package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +2 -4
- package/client/features/overview/HiddenPanel.tsx +109 -0
- package/client/features/overview/Overview.tsx +302 -0
- package/client/features/overview/WidgetCanvas.tsx +164 -0
- package/client/features/{widgets → overview}/WidgetFrame.tsx +24 -16
- package/client/features/overview/WorkspaceName.tsx +60 -0
- package/client/features/overview/api.ts +30 -0
- package/client/features/overview/default/ViewsWidget.tsx +252 -0
- package/client/features/overview/default/registry.tsx +36 -0
- package/client/features/{widgets → overview}/grid.ts +36 -0
- package/client/features/overview/useGridReconcile.ts +94 -0
- package/client/features/scratchpad/Scratchpad.tsx +7 -8
- package/client/features/scratchpad/ScratchpadControls.tsx +0 -1
- package/client/features/scratchpad/useScratchpadSnapshot.tsx +23 -13
- package/client/features/settings/GeneralSettings.tsx +55 -58
- package/client/features/settings/SettingsLayout.tsx +2 -2
- package/client/features/settings/WorkspaceIconPicker.tsx +318 -0
- package/client/features/settings/WorkspaceSettingsDialog.tsx +65 -0
- package/client/features/settings/api.ts +48 -24
- package/client/features/views/ViewBuilder.tsx +5 -4
- package/client/features/views/ViewManager.tsx +11 -13
- package/client/features/views/api.ts +36 -2
- package/client/features/views/useViewBuilderActions.ts +8 -5
- package/client/features/views/useViewBuilderDrafts.ts +23 -21
- package/client/features/views/view-presentation.ts +13 -0
- package/client/features/workspace/{CustomizePanel.tsx → ThemePanel.tsx} +26 -31
- package/client/features/workspace/UnavailablePage.tsx +21 -0
- package/client/features/workspace/WorkspaceLayoutContext.tsx +4 -7
- package/client/features/workspace/WorkspaceScreen.tsx +205 -161
- package/client/features/workspace/WorkspaceSplitLayout.tsx +1 -1
- package/client/features/workspace/WorkspaceTabs.tsx +2 -0
- package/client/features/workspace/api.ts +0 -26
- package/client/features/workspace/moi-context.ts +8 -9
- package/client/features/workspace/tab-resolution.ts +10 -33
- package/client/features/workspace/useWorkspaceNavigation.ts +164 -101
- package/client/index.css +1 -1
- package/client/lib/app-icon-registry.ts +2 -0
- package/client/lib/use-latest-ref.ts +11 -0
- package/client/main.tsx +1 -1
- package/client/runtime/useWorkspaceEvents.ts +59 -14
- package/client/theme.css +5 -5
- package/dist/chunk-2gs8jjx4.css +1 -0
- package/dist/chunk-7vvg5fyz.js +68 -0
- package/dist/chunk-94m3q9ce.js +1 -0
- package/dist/{chunk-w482ew2c.js → chunk-brr0zbeh.js} +73 -73
- package/dist/chunk-by2wqgak.js +1 -0
- package/dist/chunk-m1fvqssh.js +2 -0
- package/dist/chunk-p34hvqt3.js +1 -0
- package/dist/{chunk-4s15axjs.js → chunk-p83f0jnj.js} +2 -2
- package/dist/{chunk-j3wvxjr7.js → chunk-tzz101ea.js} +1 -1
- package/dist/chunk-xg01f6pn.js +10 -0
- package/dist/{chunk-53a7pxcz.js → chunk-zs4mte79.js} +1 -1
- package/dist/index.html +1 -1
- package/lib/app-icons.ts +1 -0
- package/lib/applet-selector.ts +24 -0
- package/lib/chat-title.ts +6 -1
- package/lib/default-widgets.ts +32 -0
- package/lib/format.ts +12 -1
- package/lib/message-attachments.ts +40 -0
- package/lib/moi-attachments.ts +204 -0
- package/lib/moi-context.ts +20 -35
- package/lib/navigation.ts +84 -0
- package/lib/types.ts +81 -25
- package/lib/workspace-icon.ts +20 -0
- package/lib/workspace-layout.ts +22 -2
- package/lib/workspace-tabs.ts +9 -33
- package/package.json +27 -27
- package/registry.json +13 -0
- package/server/AGENTS.md +1 -0
- package/server/api.ts +114 -37
- package/server/applet-typecheck.ts +95 -0
- package/server/{bundler → applets}/build-applet.ts +13 -246
- package/server/applets/config.ts +226 -0
- package/server/applets/dependencies.ts +206 -0
- package/server/{applets.ts → applets/index.ts} +15 -161
- package/server/applets/runtime/base.ts +4 -0
- package/server/applets/runtime/moi.ts +42 -0
- package/server/applets/runtime/rpc.ts +17 -0
- package/server/applets/view-source.ts +67 -0
- package/server/attachment-message.ts +95 -0
- package/server/cli.ts +163 -97
- package/server/control.ts +63 -42
- package/server/harness/README.md +4 -2
- package/server/harness/acp/adapter.ts +7 -21
- package/server/harness/acp/session.ts +31 -50
- package/server/harness/claude-code/NOTES.md +8 -2
- package/server/harness/claude-code/adapter.ts +8 -25
- package/server/harness/claude-code/index.ts +2 -0
- package/server/harness/claude-code/session.ts +42 -47
- package/server/harness/claude-code/sessions.ts +9 -4
- package/server/harness/codex/adapter.ts +8 -7
- package/server/harness/codex/index.ts +1 -0
- package/server/harness/codex/permissions.ts +1 -1
- package/server/harness/codex/session.ts +20 -47
- package/server/harness/hermes/NOTES.md +1 -1
- package/server/harness/hermes/index.ts +4 -0
- package/server/harness/openclaw/NOTES.md +1 -1
- package/server/harness/openclaw/adapter.ts +22 -4
- package/server/harness/openclaw/gateway.ts +5 -3
- package/server/harness/openclaw/session.ts +27 -27
- package/server/harness/types.ts +5 -3
- package/server/layout.ts +9 -14
- package/server/moi-scaffold.ts +21 -13
- package/server/navigation-relay.ts +110 -0
- package/server/registry.ts +8 -0
- package/server/selected-session.ts +24 -4
- package/server/skill-update.ts +5 -3
- package/server/skill-version.ts +4 -7
- package/server/skills-template.ts +48 -9
- package/server/tabs.ts +19 -33
- package/server/uploads.ts +0 -0
- package/server/view-builders.ts +18 -1
- package/server/views.ts +126 -6
- package/server/web.ts +35 -9
- package/server/widgets.ts +12 -5
- package/server/workspace-config.ts +13 -9
- package/ui-components/button.tsx +2 -2
- package/ui-components/docs/kbd.md +191 -0
- package/ui-components/dropdown-menu.tsx +1 -1
- package/ui-components/kbd.tsx +32 -0
- package/ui-components/slider.tsx +1 -1
- package/ui-components/switch.tsx +1 -1
- package/ui-components/tabs.tsx +1 -1
- package/workspace/.claude/skills/moi-workspace/SKILL.md +284 -228
- package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +100 -153
- package/workspace/.claude/skills/moi-workspace/references/INTENTS.md +156 -0
- package/client/features/chat/attachment-staging.ts +0 -153
- package/client/features/chat/uploads.ts +0 -18
- package/client/features/chat/useAppletChatMessage.ts +0 -68
- package/client/features/settings/IconPicker.tsx +0 -442
- package/client/features/settings/WorkspaceSettings.tsx +0 -95
- package/client/features/settings/render-icon.ts +0 -173
- package/client/features/widgets/HiddenPanel.tsx +0 -80
- package/client/features/widgets/WidgetGrid.tsx +0 -123
- package/client/features/widgets/Widgets.tsx +0 -262
- package/client/features/widgets/useGridReconcile.ts +0 -73
- package/dist/chunk-245wt82v.css +0 -1
- package/dist/chunk-87thzbtw.js +0 -2
- package/dist/chunk-a6jad1a6.js +0 -1
- package/dist/chunk-dghwstd2.js +0 -9
- package/dist/chunk-eg120aca.js +0 -1
- package/dist/chunk-j7hh2ab4.js +0 -70
- package/dist/chunk-y8eyahwx.js +0 -1
- /package/client/features/chat/{ChatPromptBubbles.tsx → messages/ChatPromptBubbles.tsx} +0 -0
- /package/client/features/chat/{ShimmerText.tsx → messages/ShimmerText.tsx} +0 -0
- /package/client/features/chat/{group-turns.ts → messages/group-turns.ts} +0 -0
- /package/client/features/chat/{interleave-notices.ts → messages/interleave-notices.ts} +0 -0
- /package/client/features/chat/{preview-turn.ts → messages/preview-turn.ts} +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/CodeBlock.tsx +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/Collapse.tsx +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/ReadImagePreview.tsx +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/ToolOutput.tsx +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/detect.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/fixtures.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/format/claude.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/format/codex.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/format/hermes.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/format/index.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/format/mcp.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/format/openclaw.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/format/shared.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/format/shell.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/index.ts +0 -0
- /package/client/features/chat/{useStickToBottom.ts → messages/useStickToBottom.ts} +0 -0
- /package/client/features/chat/{session-view.ts → sessions/session-view.ts} +0 -0
- /package/client/features/chat/{useSelectedSession.ts → sessions/useSelectedSession.ts} +0 -0
- /package/server/{bundler → applets}/applet-css.ts +0 -0
- /package/server/{bundler → applets}/build-worker.ts +0 -0
|
@@ -1,28 +1,38 @@
|
|
|
1
1
|
// The workspace applet runtime — the host side of the applet `moi` module.
|
|
2
2
|
//
|
|
3
|
-
// Every applet bundle inlines its own copy of the `moi`
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
3
|
+
// Every applet bundle inlines its own copy of the `moi` runtime module (see
|
|
4
|
+
// server/applets/runtime/moi.ts), so each loaded module instance holds a
|
|
5
|
+
// private `bridge` slot. Right after the dynamic import, the host connects that
|
|
6
|
+
// instance to the workspace's runtime by attaching a thin
|
|
7
7
|
// bridge (`attachAppletBridge`); invalidation disposes it (`disposeAppletBridge`),
|
|
8
8
|
// leaving a stale module instance — old timers, old listeners — inert instead
|
|
9
9
|
// of steering the app. One runtime per workspace id.
|
|
10
10
|
//
|
|
11
11
|
// Applet calls surface as runtime EVENTS: the bridge validates the untrusted
|
|
12
12
|
// args, then emits, and each host feature subscribes to its own concern with
|
|
13
|
-
// `useAppletEvent` (navigation owns `
|
|
13
|
+
// `useAppletEvent` (navigation owns `navigate`; chat will own `sendChatMessage`)
|
|
14
14
|
// — no central handlers object assembled by the screen. Applet → host only;
|
|
15
15
|
// if a host → applet direction is ever added (`moi.on(...)`), `dispose` must
|
|
16
16
|
// also unbind those listeners or a disposed module leaks.
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
MAX_ATTACHMENT_LABEL_CHARS,
|
|
19
|
+
MAX_TEXT_ATTACHMENT_CHARS,
|
|
20
|
+
snapshotTextAttachment
|
|
21
|
+
} from '@/lib/moi-attachments'
|
|
22
|
+
import type { AppletBridge, AppletKind, AttachmentInput, AttachmentOrigin } from '@/lib/types'
|
|
23
|
+
import { isWorkspaceAttachmentPath, MAX_UPLOAD_BYTES } from '@/lib/message-attachments'
|
|
24
|
+
import { useEffect } from 'react'
|
|
18
25
|
|
|
19
26
|
import { createNanoEvents } from 'nanoevents'
|
|
20
27
|
|
|
21
28
|
import { reportAppletError } from '@/client/features/applets/applet-log'
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import
|
|
25
|
-
import { isParamsRecord
|
|
29
|
+
import { toast } from '@/client/components/ui/toast'
|
|
30
|
+
import { createRateLimiter, type RateLimiter } from '@/client/lib/rate-limit'
|
|
31
|
+
import { useLatestRef } from '@/client/lib/use-latest-ref'
|
|
32
|
+
import { isParamsRecord } from '@/lib/workspace-tabs'
|
|
33
|
+
import { resolveWorkspaceHref } from '@/lib/navigation'
|
|
34
|
+
|
|
35
|
+
export type { AppletBridge } from '@/lib/types'
|
|
26
36
|
|
|
27
37
|
// Which applet a bridge belongs to, supplied by the host at attach time.
|
|
28
38
|
export type AppletIdentity = { kind: AppletKind; name: string }
|
|
@@ -35,39 +45,24 @@ export const appletSource = ({ kind, name }: AppletIdentity): string => `${kind}
|
|
|
35
45
|
export type AppletChatMessage = {
|
|
36
46
|
message: string
|
|
37
47
|
source: string
|
|
38
|
-
|
|
48
|
+
attachments: (AttachmentInput & AttachmentOrigin)[]
|
|
39
49
|
}
|
|
40
50
|
|
|
41
51
|
// Events a workspace runtime emits — already validated, typed for host code.
|
|
42
52
|
export type AppletEvents = {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
// (history state is structured-cloned).
|
|
46
|
-
focusTab: (tab: WorkspaceTabId, params?: Record<string, unknown>) => void
|
|
53
|
+
addChatAttachment: (attachment: AttachmentInput & AttachmentOrigin) => void
|
|
54
|
+
navigate: (href: string) => void
|
|
47
55
|
// A message for the workspace's active chat, sent as if the user typed
|
|
48
|
-
// `message
|
|
56
|
+
// `message`, with attachments prepared before the send.
|
|
49
57
|
sendChatMessage: (message: AppletChatMessage) => void
|
|
50
58
|
}
|
|
51
59
|
|
|
52
|
-
// What a bundle's `moi` module calls. Args are `unknown` on purpose: they
|
|
53
|
-
// cross the trust boundary from agent-authored code, and the runtime narrows
|
|
54
|
-
// them before emitting.
|
|
55
|
-
export type AppletBridge = {
|
|
56
|
-
focusTab: (tab: unknown, params?: unknown) => void
|
|
57
|
-
sendChatMessage: (message: unknown, context?: unknown) => void
|
|
58
|
-
}
|
|
59
|
-
|
|
60
60
|
// A message longer than this is a bug, not a chat message — it would land in
|
|
61
61
|
// a bubble verbatim.
|
|
62
62
|
const MAX_MESSAGE_CHARS = 1000
|
|
63
63
|
|
|
64
|
-
//
|
|
65
|
-
//
|
|
66
|
-
// render, and the bridge is per BUNDLE, so two simultaneous mounts of one
|
|
67
|
-
// applet double every call. The cooldown collapses identical messages (which
|
|
68
|
-
// also absorbs the double-mount); the window cap bounds everything else,
|
|
69
|
-
// including a loop that varies its text. Limits are per workspace runtime, so
|
|
70
|
-
// one runaway applet can't mute another workspace.
|
|
64
|
+
// Chat messages start an agent run. The cooldown collapses identical calls and
|
|
65
|
+
// the window cap bounds loops that vary their payload.
|
|
71
66
|
const CHAT_LIMITS = { cooldownMs: 2_000, windowMs: 60_000, maxPerWindow: 10, maxKeys: 64 }
|
|
72
67
|
|
|
73
68
|
function createRuntime(workspaceId: string) {
|
|
@@ -88,26 +83,27 @@ function createRuntime(workspaceId: string) {
|
|
|
88
83
|
})
|
|
89
84
|
}
|
|
90
85
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
86
|
+
const admit = (
|
|
87
|
+
limiter: RateLimiter,
|
|
88
|
+
identity: AppletIdentity,
|
|
89
|
+
key: string,
|
|
90
|
+
cooldownReason: string,
|
|
91
|
+
windowReason: string
|
|
92
|
+
): boolean => {
|
|
93
|
+
const verdict = limiter.admit(key)
|
|
94
|
+
if (verdict === 'ok') return true
|
|
95
|
+
drop(identity, verdict === 'cooldown' ? cooldownReason : windowReason)
|
|
96
|
+
return false
|
|
97
|
+
}
|
|
98
|
+
|
|
94
99
|
const admitChatMessage = (identity: AppletIdentity, source: string, text: string): boolean => {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
)
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
if (verdict === 'window') {
|
|
104
|
-
drop(
|
|
105
|
-
identity,
|
|
106
|
-
`sendChatMessage("${text}") was dropped: more than ${CHAT_LIMITS.maxPerWindow} messages in a minute from this workspace. Each one starts an agent run, so send only on a real user action.`
|
|
107
|
-
)
|
|
108
|
-
return false
|
|
109
|
-
}
|
|
110
|
-
return true
|
|
100
|
+
return admit(
|
|
101
|
+
chatLimiter,
|
|
102
|
+
identity,
|
|
103
|
+
`${source}\0${text}`,
|
|
104
|
+
`sendChatMessage() for "${text}" was dropped: the same message was already sent less than ${CHAT_LIMITS.cooldownMs / 1000}s ago. Call it from an event handler, not during render.`,
|
|
105
|
+
`sendChatMessage() for "${text}" was dropped: more than ${CHAT_LIMITS.maxPerWindow} messages in a minute from this workspace. Each one starts an agent run, so send only on a real user action.`
|
|
106
|
+
)
|
|
111
107
|
}
|
|
112
108
|
|
|
113
109
|
return {
|
|
@@ -115,39 +111,77 @@ function createRuntime(workspaceId: string) {
|
|
|
115
111
|
return emitter.on(event, cb)
|
|
116
112
|
},
|
|
117
113
|
// One connection per loaded module instance. The bridge validates every
|
|
118
|
-
// call — a malformed
|
|
114
|
+
// call — a malformed address or chat input from applet code drops the
|
|
119
115
|
// call instead of being emitted — and `dispose` flips the connection dead
|
|
120
116
|
// so a disposed module can never act again. Emitting with no subscribers
|
|
121
117
|
// (workspace screen unmounted) is a no-op by nanoevents semantics.
|
|
122
|
-
connect(identity: AppletIdentity) {
|
|
118
|
+
connect(identity: AppletIdentity, base = '') {
|
|
123
119
|
let alive = true
|
|
124
120
|
const source = appletSource(identity)
|
|
125
121
|
const bridge: AppletBridge = {
|
|
126
|
-
|
|
122
|
+
addChatAttachment(input) {
|
|
127
123
|
if (!alive) return
|
|
128
|
-
|
|
129
|
-
|
|
124
|
+
try {
|
|
125
|
+
const attachment = snapshotAttachmentInput(input, source)
|
|
126
|
+
emitter.emit('addChatAttachment', attachment)
|
|
127
|
+
} catch (error) {
|
|
128
|
+
const message = errorMessage(error)
|
|
129
|
+
toast.add({ title: 'Couldn’t add attachment', description: message, type: 'error' })
|
|
130
|
+
drop(identity, `addChatAttachment() was dropped: ${message}`)
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
navigate(href) {
|
|
134
|
+
if (!alive) return
|
|
135
|
+
try {
|
|
136
|
+
if (typeof href !== 'string') throw new Error('Navigation needs a URL')
|
|
137
|
+
resolveWorkspaceHref(workspaceId, href, base)
|
|
138
|
+
emitter.emit('navigate', href)
|
|
139
|
+
} catch (error) {
|
|
140
|
+
drop(identity, `navigate() was dropped: ${errorMessage(error)}`)
|
|
141
|
+
}
|
|
130
142
|
},
|
|
131
|
-
|
|
143
|
+
resolveHref(href) {
|
|
144
|
+
if (!alive) return ''
|
|
145
|
+
if (typeof href !== 'string') throw new Error('A URL is required')
|
|
146
|
+
return resolveWorkspaceHref(workspaceId, href, base)
|
|
147
|
+
},
|
|
148
|
+
sendChatMessage(input, legacyContext) {
|
|
132
149
|
if (!alive) return
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
150
|
+
try {
|
|
151
|
+
// Runtime compatibility for older bundles. Both forms use the same
|
|
152
|
+
// attachment validation and send path; only the object API is public.
|
|
153
|
+
if (typeof input === 'string') {
|
|
154
|
+
input = {
|
|
155
|
+
message: input,
|
|
156
|
+
attachments:
|
|
157
|
+
legacyContext === undefined
|
|
158
|
+
? []
|
|
159
|
+
: [{ type: 'text', label: 'Context', text: JSON.stringify(legacyContext) }]
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (!isParamsRecord(input) || typeof input.message !== 'string') {
|
|
163
|
+
throw new Error('This message uses an unsupported format')
|
|
164
|
+
}
|
|
165
|
+
if ('context' in input) {
|
|
166
|
+
throw new Error('This message uses an outdated format')
|
|
167
|
+
}
|
|
168
|
+
const message = input.message.trim()
|
|
169
|
+
if (!message) throw new Error('The message is empty')
|
|
170
|
+
if (message.length > MAX_MESSAGE_CHARS)
|
|
171
|
+
throw new Error('Messages can be up to 1,000 characters')
|
|
172
|
+
if (input.attachments !== undefined && !Array.isArray(input.attachments)) {
|
|
173
|
+
throw new Error('The attachments use an unsupported format')
|
|
174
|
+
}
|
|
175
|
+
const attachments = Array.from(input.attachments ?? [], item =>
|
|
176
|
+
snapshotAttachmentInput(item, source)
|
|
140
177
|
)
|
|
141
|
-
return
|
|
178
|
+
if (!admitChatMessage(identity, source, message)) return
|
|
179
|
+
emitter.emit('sendChatMessage', { message, source, attachments })
|
|
180
|
+
} catch (error) {
|
|
181
|
+
const message = errorMessage(error)
|
|
182
|
+
toast.add({ title: 'Couldn’t send message', description: message, type: 'error' })
|
|
183
|
+
drop(identity, `sendChatMessage() was dropped: ${message}`)
|
|
142
184
|
}
|
|
143
|
-
if (!admitChatMessage(identity, source, text)) return
|
|
144
|
-
emitter.emit('sendChatMessage', {
|
|
145
|
-
message: text,
|
|
146
|
-
source,
|
|
147
|
-
...(context !== undefined
|
|
148
|
-
? { context: narrowChatContext(identity, context, drop) }
|
|
149
|
-
: {})
|
|
150
|
-
})
|
|
151
185
|
}
|
|
152
186
|
}
|
|
153
187
|
return {
|
|
@@ -160,37 +194,42 @@ function createRuntime(workspaceId: string) {
|
|
|
160
194
|
}
|
|
161
195
|
}
|
|
162
196
|
|
|
163
|
-
//
|
|
164
|
-
//
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
197
|
+
// Copy the caller's fields now so later applet mutations cannot change a send
|
|
198
|
+
// or staged attachment. File contents are immutable and can be retained as-is.
|
|
199
|
+
function snapshotAttachmentInput(
|
|
200
|
+
input: unknown,
|
|
201
|
+
source: string
|
|
202
|
+
): AttachmentInput & AttachmentOrigin {
|
|
203
|
+
if (!isParamsRecord(input)) throw new Error('This attachment isn’t supported')
|
|
204
|
+
if (input.type === 'text') {
|
|
205
|
+
const snapshot = snapshotTextAttachment(input)
|
|
206
|
+
if (snapshot) return { type: 'text', ...snapshot, source }
|
|
207
|
+
if (typeof input.label !== 'string' || !input.label.trim())
|
|
208
|
+
throw new Error('Add a label to this text attachment')
|
|
209
|
+
if (input.label.trim().length > MAX_ATTACHMENT_LABEL_CHARS)
|
|
210
|
+
throw new Error(`Attachment labels can be up to ${MAX_ATTACHMENT_LABEL_CHARS} characters`)
|
|
211
|
+
if (typeof input.text !== 'string' || !input.text.trim())
|
|
212
|
+
throw new Error('Add some text to this attachment')
|
|
213
|
+
if (input.text.length > MAX_TEXT_ATTACHMENT_CHARS)
|
|
214
|
+
throw new Error(
|
|
215
|
+
`Text attachments can be up to ${MAX_TEXT_ATTACHMENT_CHARS.toLocaleString('en-US')} characters`
|
|
216
|
+
)
|
|
217
|
+
} else if (input.type === 'file') {
|
|
218
|
+
if (input.file instanceof File && input.path === undefined) {
|
|
219
|
+
if (input.file.size > MAX_UPLOAD_BYTES) throw new Error('Files can be up to 32 MB')
|
|
220
|
+
return { type: 'file', file: input.file, source }
|
|
221
|
+
}
|
|
222
|
+
if (typeof input.path === 'string' && input.file === undefined) {
|
|
223
|
+
if (!isWorkspaceAttachmentPath(input.path))
|
|
224
|
+
throw new Error('Choose a file from this workspace')
|
|
225
|
+
return { type: 'file', path: input.path, source }
|
|
226
|
+
}
|
|
192
227
|
}
|
|
193
|
-
|
|
228
|
+
throw new Error('This attachment isn’t supported')
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function errorMessage(error: unknown): string {
|
|
232
|
+
return error instanceof Error ? error.message : String(error)
|
|
194
233
|
}
|
|
195
234
|
|
|
196
235
|
type AppletRuntime = ReturnType<typeof createRuntime>
|
|
@@ -215,8 +254,7 @@ export function useAppletEvent<K extends keyof AppletEvents>(
|
|
|
215
254
|
event: K,
|
|
216
255
|
handler: AppletEvents[K]
|
|
217
256
|
): void {
|
|
218
|
-
const latest =
|
|
219
|
-
latest.current = handler
|
|
257
|
+
const latest = useLatestRef(handler)
|
|
220
258
|
|
|
221
259
|
useEffect(() => {
|
|
222
260
|
// TS can't call a generic indexed function type with its own Parameters
|
|
@@ -224,11 +262,11 @@ export function useAppletEvent<K extends keyof AppletEvents>(
|
|
|
224
262
|
const forward = ((...args: unknown[]) =>
|
|
225
263
|
(latest.current as (...forwarded: unknown[]) => void)(...args)) as AppletEvents[K]
|
|
226
264
|
return appletRuntime(workspaceId).on(event, forward)
|
|
227
|
-
}, [workspaceId, event])
|
|
265
|
+
}, [workspaceId, event, latest])
|
|
228
266
|
}
|
|
229
267
|
|
|
230
268
|
// The shape of the host wiring every bundle entry re-exports (see the entry
|
|
231
|
-
// plugin in server/
|
|
269
|
+
// plugin in server/applets/build-applet.ts).
|
|
232
270
|
type BridgeModule = {
|
|
233
271
|
__attachBridge?: (bridge: AppletBridge) => void
|
|
234
272
|
}
|
|
@@ -249,14 +287,15 @@ export function attachAppletBridge(
|
|
|
249
287
|
mod: unknown,
|
|
250
288
|
workspaceId: string,
|
|
251
289
|
key: string,
|
|
252
|
-
identity: AppletIdentity
|
|
290
|
+
identity: AppletIdentity,
|
|
291
|
+
base = ''
|
|
253
292
|
): void {
|
|
254
293
|
const attach = (mod as BridgeModule).__attachBridge
|
|
255
294
|
if (typeof attach !== 'function') return
|
|
256
295
|
// A key is re-attached only after invalidation disposed it, but never leave
|
|
257
296
|
// a live orphan connection behind if that ordering ever changes.
|
|
258
297
|
connections.get(key)?.()
|
|
259
|
-
const { bridge, dispose } = appletRuntime(workspaceId).connect(identity)
|
|
298
|
+
const { bridge, dispose } = appletRuntime(workspaceId).connect(identity, base)
|
|
260
299
|
connections.set(key, dispose)
|
|
261
300
|
attach(bridge)
|
|
262
301
|
}
|
|
@@ -5,7 +5,7 @@ import { useInsertionEffect } from 'react'
|
|
|
5
5
|
// re-evaluated, let alone disposed). Instead its module side effect registers
|
|
6
6
|
// the compiled, container-scoped CSS on `window.__moiAppletCss`, keyed by the
|
|
7
7
|
// bundle-dir path (`/api/workspaces/<id>/<segment>/<name>` — see injectCss in
|
|
8
|
-
// server/
|
|
8
|
+
// server/applets/build-applet.ts and `appletStyleKey`). The host injects a <style> for
|
|
9
9
|
// that key while at least one instance of the applet is mounted, and removes it
|
|
10
10
|
// when the last one unmounts.
|
|
11
11
|
declare global {
|
|
@@ -55,7 +55,7 @@ export function acquireAppletStyle(key: string): () => void {
|
|
|
55
55
|
// Move an applet's <style> to the end of <head>. Everything in an applet sheet
|
|
56
56
|
// is scoped to its `[data-applet]` container and so can't collide — except the
|
|
57
57
|
// names of global at-rules (`@keyframes`, `@property`, `@font-face`), which the
|
|
58
|
-
// scoper leaves alone because they aren't selectors (server/
|
|
58
|
+
// scoper leaves alone because they aren't selectors (server/applets/applet-css.ts).
|
|
59
59
|
// Two applets defining `@keyframes pulse` differently therefore share one
|
|
60
60
|
// document-global name, and the last definition wins for both. Raising the
|
|
61
61
|
// applet the user is looking at makes the winner the one on screen.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { useEffect
|
|
1
|
+
import { useEffect } from 'react'
|
|
2
2
|
|
|
3
3
|
import { useAppletThumbnailRecords, useSaveAppletThumbnails } from '@/client/features/applets/api'
|
|
4
4
|
import { useWorkspaceId } from '@/client/features/workspace/WorkspaceContext'
|
|
5
|
+
import { useLatestRef } from '@/client/lib/use-latest-ref'
|
|
5
6
|
import type { AppletKind, AppletThumbnail, AppletThumbnailUpdate } from '@/lib/types'
|
|
6
7
|
|
|
7
8
|
export const THUMBNAIL_MAX_EDGE = 1_000
|
|
@@ -239,12 +240,9 @@ export function useAppletThumbnails({ kind, enabled, targets }: UseAppletThumbna
|
|
|
239
240
|
const workspaceId = useWorkspaceId()
|
|
240
241
|
const records = useAppletThumbnailRecords(workspaceId).data
|
|
241
242
|
const save = useSaveAppletThumbnails(workspaceId)
|
|
242
|
-
const targetsRef =
|
|
243
|
-
|
|
244
|
-
const
|
|
245
|
-
recordsRef.current = records ?? []
|
|
246
|
-
const saveRef = useRef(save.mutate)
|
|
247
|
-
saveRef.current = save.mutate
|
|
243
|
+
const targetsRef = useLatestRef(targets)
|
|
244
|
+
const recordsRef = useLatestRef(records ?? [])
|
|
245
|
+
const saveRef = useLatestRef(save.mutate)
|
|
248
246
|
const targetKey = targets.map(target => `${target.id}@${target.revision ?? ''}`).join('\n')
|
|
249
247
|
// Hold the first pass until the stored records arrive — capturing against an
|
|
250
248
|
// unloaded store would re-screenshot everything on every page load.
|
|
@@ -291,5 +289,5 @@ export function useAppletThumbnails({ kind, enabled, targets }: UseAppletThumbna
|
|
|
291
289
|
if (timer !== undefined) clearTimeout(timer)
|
|
292
290
|
document.removeEventListener('visibilitychange', schedule)
|
|
293
291
|
}
|
|
294
|
-
}, [enabled, kind, ready, targetKey])
|
|
292
|
+
}, [enabled, kind, ready, recordsRef, saveRef, targetKey, targetsRef])
|
|
295
293
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ComponentType } from 'react'
|
|
2
|
+
import { useRouter } from 'wouter'
|
|
2
3
|
import { useCallback, useEffect, useState } from 'react'
|
|
3
4
|
|
|
4
5
|
import {
|
|
@@ -16,12 +17,10 @@ import { useWorkspaceId } from '@/client/features/workspace/WorkspaceContext'
|
|
|
16
17
|
import { type WorkspaceEvent, useWorkspaceEvent } from '@/client/runtime/useWorkspaceEvents'
|
|
17
18
|
import type { AppletKind } from '@/lib/types'
|
|
18
19
|
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
// history entry — see ViewApp in WorkspaceScreen.tsx); widgets are mounted
|
|
22
|
-
// bare, so the applet must render sensibly with `params` absent.
|
|
20
|
+
// Views receive URL query params. Widgets mount without params; applets must
|
|
21
|
+
// render sensibly with missing fields.
|
|
23
22
|
export type AppletComponentProps = {
|
|
24
|
-
params?: Record<string,
|
|
23
|
+
params?: Record<string, string>
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
export type AppletState =
|
|
@@ -59,7 +58,8 @@ const VIEW_KIND: AppletKindSpec = {
|
|
|
59
58
|
function loadApplet(
|
|
60
59
|
kind: AppletKindSpec,
|
|
61
60
|
workspaceId: string,
|
|
62
|
-
name: string
|
|
61
|
+
name: string,
|
|
62
|
+
base: string
|
|
63
63
|
): Promise<ComponentType<AppletComponentProps>> {
|
|
64
64
|
const { segment } = kind
|
|
65
65
|
const key = appletKey(segment, workspaceId, name)
|
|
@@ -75,7 +75,7 @@ function loadApplet(
|
|
|
75
75
|
// runtime — the only moment the namespace is in hand, before React renders
|
|
76
76
|
// the component. Disposal rides invalidateApplet (same key). The identity
|
|
77
77
|
// passed here is what the applet's chat messages are attributed to.
|
|
78
|
-
attachAppletBridge(mod, workspaceId, key, { kind: kind.kind, name })
|
|
78
|
+
attachAppletBridge(mod, workspaceId, key, { kind: kind.kind, name }, base)
|
|
79
79
|
return mod.default as ComponentType<AppletComponentProps>
|
|
80
80
|
})
|
|
81
81
|
|
|
@@ -85,11 +85,12 @@ function loadApplet(
|
|
|
85
85
|
|
|
86
86
|
function useApplet(kind: AppletKindSpec, name: string): AppletState {
|
|
87
87
|
const workspaceId = useWorkspaceId()
|
|
88
|
+
const { base } = useRouter()
|
|
88
89
|
const [state, setState] = useState<AppletState>({ status: 'loading', version: 0 })
|
|
89
90
|
|
|
90
91
|
const load = useCallback(() => {
|
|
91
92
|
setState(prev => ({ status: 'loading', version: prev.version }))
|
|
92
|
-
loadApplet(kind, workspaceId, name)
|
|
93
|
+
loadApplet(kind, workspaceId, name, base)
|
|
93
94
|
.then(Component =>
|
|
94
95
|
setState(prev => ({ status: 'ready', Component, version: prev.version + 1 }))
|
|
95
96
|
)
|
|
@@ -105,7 +106,7 @@ function useApplet(kind: AppletKindSpec, name: string): AppletState {
|
|
|
105
106
|
})
|
|
106
107
|
setState(prev => ({ status: 'error', error: String(err), version: prev.version + 1 }))
|
|
107
108
|
})
|
|
108
|
-
}, [kind, workspaceId, name])
|
|
109
|
+
}, [base, kind, workspaceId, name])
|
|
109
110
|
|
|
110
111
|
useEffect(() => {
|
|
111
112
|
load()
|
|
@@ -4,20 +4,27 @@ import { IconChevronDown, IconChevronsRight, IconX } from '@tabler/icons-react'
|
|
|
4
4
|
|
|
5
5
|
import { canSubmitComposerAction, focusComposer } from '@/client/components/shared/Composer'
|
|
6
6
|
import { AgentBlobatar } from '@/client/components/shared/AgentBlobatar'
|
|
7
|
-
import { useStickToBottom } from '@/client/features/chat/useStickToBottom'
|
|
8
|
-
import { appendPreviewTurn, groupTurns } from '@/client/features/chat/group-turns'
|
|
9
|
-
import {
|
|
7
|
+
import { useStickToBottom } from '@/client/features/chat/messages/useStickToBottom'
|
|
8
|
+
import { appendPreviewTurn, groupTurns } from '@/client/features/chat/messages/group-turns'
|
|
9
|
+
import {
|
|
10
|
+
chatNoticeLabel,
|
|
11
|
+
interleaveNotices
|
|
12
|
+
} from '@/client/features/chat/messages/interleave-notices'
|
|
10
13
|
import { attachmentKey, useLive } from '@/client/features/chat/chat-store'
|
|
11
|
-
import type { ChatPromptBubble } from '@/client/features/chat/ChatPromptBubbles'
|
|
14
|
+
import type { ChatPromptBubble } from '@/client/features/chat/messages/ChatPromptBubbles'
|
|
12
15
|
import type { ChatSendOptions } from '@/client/features/chat/chat-send'
|
|
13
16
|
import { useWorkspaceId } from '@/client/features/workspace/WorkspaceContext'
|
|
14
17
|
import type { AgentTheme, SystemNotice, Turn, ViewState } from '@/lib/types'
|
|
15
18
|
|
|
16
19
|
import type { ComposerBanner } from './composer/banners/ComposerBanner'
|
|
17
20
|
import { ChatComposer, type ComposerAnnotationControls } from './composer/ChatComposer'
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
import {
|
|
22
|
+
ChatEmptyState,
|
|
23
|
+
type WelcomeDestination,
|
|
24
|
+
resolveChatEmptyState
|
|
25
|
+
} from './messages/ChatEmptyState'
|
|
26
|
+
import { ChatSelector } from './sessions/ChatSelector'
|
|
27
|
+
import { TurnView } from './messages/TurnView'
|
|
21
28
|
import { Button } from '@/client/components/ui/button'
|
|
22
29
|
import { Tooltip, TooltipContent, TooltipTrigger } from '@/client/components/ui/tooltip'
|
|
23
30
|
import { cn } from '@/client/lib/cn'
|
|
@@ -98,7 +105,7 @@ export function ChatPanel({
|
|
|
98
105
|
)
|
|
99
106
|
const attachmentsUploading = useLive(state =>
|
|
100
107
|
(state.attachments[attachmentKey(workspaceId, effectiveSessionId)] ?? []).some(
|
|
101
|
-
attachment => attachment.status === 'uploading'
|
|
108
|
+
attachment => attachment.kind !== 'text' && attachment.status === 'uploading'
|
|
102
109
|
)
|
|
103
110
|
)
|
|
104
111
|
const promptDisabled = !canSubmitComposerAction(true, attachmentsUploading, agentAvailability)
|
|
@@ -163,8 +170,10 @@ export function ChatPanel({
|
|
|
163
170
|
|
|
164
171
|
return (
|
|
165
172
|
<div className="flex min-h-0 flex-1 flex-col pt-2 pb-3">
|
|
166
|
-
<header className="mx-auto flex w-full max-w-[calc(var(--chat-max-container)+40px)] items-center justify-between pr-2 pb-2 pl-2">
|
|
167
|
-
<
|
|
173
|
+
<header className="mx-auto flex w-full max-w-[calc(var(--chat-max-container)+40px)] min-w-0 items-center justify-between pr-2 pb-2 pl-2">
|
|
174
|
+
<div className="min-w-0 flex-1">
|
|
175
|
+
<ChatSelector isViewBuilder={!!builderDraft} />
|
|
176
|
+
</div>
|
|
168
177
|
{onClose && docked && (
|
|
169
178
|
<Tooltip>
|
|
170
179
|
<TooltipTrigger
|
|
@@ -29,7 +29,12 @@ export function ChatPopup({
|
|
|
29
29
|
nextOpen,
|
|
30
30
|
eventDetails
|
|
31
31
|
) => {
|
|
32
|
-
|
|
32
|
+
// Applet actions move focus outside before their click handler runs.
|
|
33
|
+
// Keep chat open so adding context only refocuses the existing composer.
|
|
34
|
+
if (
|
|
35
|
+
!nextOpen &&
|
|
36
|
+
(eventDetails.reason === 'outside-press' || eventDetails.reason === 'focus-out')
|
|
37
|
+
) {
|
|
33
38
|
eventDetails.cancel()
|
|
34
39
|
return
|
|
35
40
|
}
|
|
@@ -59,7 +64,7 @@ export function ChatPopup({
|
|
|
59
64
|
>
|
|
60
65
|
<button
|
|
61
66
|
type="button"
|
|
62
|
-
className="group block cursor-pointer
|
|
67
|
+
className="group block cursor-pointer p-0 drop-shadow-[0_0_4px_var(--background)] outline-none focus-visible:ring-3 focus-visible:ring-ring/50"
|
|
63
68
|
aria-label="Agent"
|
|
64
69
|
>
|
|
65
70
|
<AgentBlobatar
|