moi-computer 0.11.0 → 0.11.1-dev.be1ed10
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/AGENTS.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/button.tsx +1 -53
- package/client/components/ui/checkbox.tsx +1 -0
- package/client/components/ui/collapsible.tsx +1 -15
- package/client/components/ui/dialog.tsx +1 -58
- package/client/components/ui/dropdown-menu.tsx +1 -254
- package/client/components/ui/hover-card.tsx +1 -44
- package/client/components/ui/inline-input.tsx +84 -0
- package/client/components/ui/input.tsx +1 -21
- package/client/components/ui/popover.tsx +1 -88
- package/client/components/ui/resizable.tsx +1 -40
- package/client/components/ui/skeleton.tsx +1 -13
- package/client/components/ui/slider.tsx +1 -70
- package/client/components/ui/spinner.tsx +1 -18
- package/client/components/ui/switch.tsx +1 -23
- package/client/components/ui/tabs.tsx +1 -0
- package/client/components/ui/textarea.tsx +1 -18
- package/client/components/ui/toast.tsx +2 -2
- package/client/components/ui/tooltip.tsx +1 -51
- 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 +24 -15
- package/client/features/chat/ChatPopup.tsx +9 -5
- package/client/features/chat/applet-chat-intents.ts +170 -0
- package/client/features/chat/chat-send.ts +116 -64
- package/client/features/chat/chat-store.ts +51 -62
- package/client/features/chat/composer/ChatComposer.tsx +43 -128
- package/client/features/chat/composer/ModelPicker.tsx +47 -60
- 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/composer/banners/ErrorBanner.tsx +20 -12
- package/client/features/chat/composer/model-order.ts +15 -0
- package/client/features/chat/composer/useWorkspaceComposerState.tsx +15 -7
- package/client/features/chat/{chat-connection.ts → connection/chat-connection.ts} +1 -1
- package/client/features/chat/{chat-frames.ts → connection/chat-frames.ts} +10 -8
- 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} +27 -19
- package/client/features/chat/{group-turns.ts → messages/group-turns.ts} +12 -0
- package/client/features/chat/{interleave-notices.ts → messages/interleave-notices.ts} +7 -11
- 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 +2 -5
- package/client/features/chat/{tool-group → messages/tool-group}/format/codex.ts +4 -1
- package/client/features/chat/{ChatSelector.tsx → sessions/ChatSelector.tsx} +3 -3
- package/client/features/chat/{api.ts → sessions/api.ts} +5 -14
- package/client/features/chat/sessions/session-view.ts +53 -0
- package/client/features/chat/useChat.ts +42 -24
- package/client/features/dev/ChatStatesPage.tsx +8 -7
- package/client/features/dev/DevIndexPage.tsx +5 -0
- package/client/features/dev/DevRoutes.tsx +2 -0
- package/client/features/dev/HarnessDebugPage.tsx +11 -8
- package/client/features/dev/ToolCallsPage.tsx +1 -1
- package/client/features/dev/UiComponentPreviews.tsx +855 -0
- package/client/features/dev/UiComponentsPage.tsx +60 -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 +2 -2
- package/client/features/home/workspace-presentation.tsx +1 -11
- package/client/features/home/workspace-setup/DemoDialog.tsx +3 -2
- package/client/features/home/workspace-setup/ImportWorkspaceDialog.tsx +5 -8
- package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +2 -4
- package/client/features/home/workspace-setup/WorkspaceDialogContent.tsx +7 -20
- 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 +25 -17
- 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 +25 -22
- 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 +210 -162
- package/client/features/workspace/WorkspaceSplitLayout.tsx +7 -2
- package/client/features/workspace/WorkspaceTabs.tsx +2 -0
- package/client/features/workspace/api.ts +2 -30
- 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 +23 -30
- 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-tqd3pkg8.css → chunk-60q353jq.css} +1 -1
- package/dist/chunk-691pqsj6.js +2 -0
- package/dist/chunk-7a5nm4k9.css +1 -0
- package/dist/chunk-amb8y04y.js +1 -0
- package/dist/chunk-cf3pgy7j.js +546 -0
- package/dist/{chunk-11cab5dq.css → chunk-cq2r11fg.css} +1 -1
- package/dist/chunk-mzrgr577.js +5 -0
- package/dist/chunk-nf2wkvf9.js +14 -0
- package/dist/chunk-q6a0g26x.js +1 -0
- package/dist/chunk-twgdemkc.js +74 -0
- package/dist/chunk-x90k0f5c.js +2 -0
- package/dist/chunk-yq00csvd.js +2 -0
- 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 +67 -7
- 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/themes.ts +6 -6
- package/lib/types.ts +91 -34
- package/lib/workspace-icon.ts +20 -0
- package/lib/workspace-layout.ts +22 -2
- package/lib/workspace-tabs.ts +9 -33
- package/package.json +42 -32
- package/registry.json +656 -0
- package/server/AGENTS.md +2 -0
- package/server/agent.ts +1 -1
- package/server/api.ts +139 -66
- package/server/applet-typecheck.ts +95 -0
- package/server/applets/applet-css.ts +55 -0
- package/server/{bundler → applets}/build-applet.ts +13 -242
- package/server/applets/build-worker.ts +178 -0
- package/server/applets/config.ts +226 -0
- package/server/applets/dependencies.ts +206 -0
- package/server/{applets.ts → applets/index.ts} +44 -189
- 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-ui-components.ts +28 -33
- package/server/cli.ts +169 -108
- package/server/control.ts +63 -42
- package/server/data-dir.ts +1 -1
- package/server/harness/README.md +45 -50
- package/server/harness/acp/NOTES.md +426 -0
- package/server/harness/acp/adapter.ts +7 -21
- package/server/harness/acp/discovery.ts +27 -30
- package/server/harness/acp/model-state.ts +57 -0
- package/server/harness/acp/session.ts +49 -56
- package/server/harness/claude-code/NOTES.md +54 -13
- package/server/harness/claude-code/adapter.ts +8 -25
- package/server/harness/claude-code/cli.ts +40 -0
- package/server/harness/claude-code/index.ts +13 -5
- package/server/harness/claude-code/models.ts +72 -19
- package/server/harness/claude-code/session.ts +447 -343
- package/server/harness/claude-code/sessions.ts +9 -4
- package/server/harness/codex/NOTES.md +222 -350
- package/server/harness/codex/adapter.ts +102 -52
- package/server/harness/codex/auth.ts +1 -3
- package/server/harness/codex/client.ts +169 -249
- package/server/harness/codex/discovery.ts +9 -17
- package/server/harness/codex/index.ts +3 -1
- package/server/harness/codex/pagination.ts +24 -0
- package/server/harness/codex/permissions.ts +32 -8
- package/server/harness/codex/probe.ts +10 -13
- package/server/harness/codex/session.ts +567 -181
- package/server/harness/codex/transport.ts +184 -0
- package/server/harness/debug.ts +1 -1
- package/server/harness/hermes/NOTES.md +19 -1
- package/server/harness/hermes/discovery.ts +20 -0
- package/server/harness/hermes/index.ts +13 -0
- package/server/harness/hermes/models.ts +28 -8
- 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 +9 -5
- package/server/layout.ts +9 -14
- package/server/moi-scaffold.ts +22 -14
- package/server/navigation-relay.ts +110 -0
- package/server/preview.ts +3 -1
- package/server/registry.ts +71 -41
- package/server/scratchpad-executor.ts +79 -56
- package/server/scratchpad-shape-defaults.ts +82 -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/tldraw-package.d.ts +4 -0
- package/server/ui-components.ts +101 -434
- package/server/uploads.ts +0 -0
- package/server/view-builders.ts +20 -2
- package/server/views.ts +126 -6
- package/server/web.ts +46 -13
- package/server/widgets.ts +12 -5
- package/server/workspace-config.ts +13 -9
- package/server/workspace-env.ts +3 -2
- package/tsconfig.json +0 -1
- package/ui-components/accordion.tsx +71 -0
- package/ui-components/alert-dialog.tsx +165 -0
- package/ui-components/alert.tsx +68 -0
- package/ui-components/attachment.tsx +195 -0
- package/ui-components/avatar.tsx +90 -0
- package/ui-components/badge.tsx +49 -0
- package/ui-components/button-group.tsx +78 -0
- package/ui-components/button.tsx +55 -0
- package/ui-components/calendar.tsx +180 -0
- package/ui-components/card.tsx +84 -0
- package/ui-components/carousel.tsx +235 -0
- package/ui-components/chart.tsx +338 -0
- package/ui-components/checkbox.tsx +28 -0
- package/ui-components/collapsible.tsx +15 -0
- package/ui-components/combobox.tsx +267 -0
- package/ui-components/context-menu.tsx +244 -0
- package/ui-components/dialog.tsx +138 -0
- package/ui-components/docs/accordion.md +463 -0
- package/ui-components/docs/alert-dialog.md +481 -0
- package/ui-components/docs/alert.md +301 -0
- package/ui-components/docs/attachment.md +689 -0
- package/ui-components/docs/avatar.md +495 -0
- package/ui-components/docs/badge.md +258 -0
- package/ui-components/docs/button-group.md +879 -0
- package/ui-components/docs/button.md +26 -0
- package/ui-components/docs/calendar.md +862 -0
- package/ui-components/docs/card.md +265 -0
- package/ui-components/docs/carousel.md +627 -0
- package/ui-components/docs/chart.md +1256 -0
- package/ui-components/docs/checkbox.md +477 -0
- package/ui-components/docs/collapsible.md +446 -0
- package/ui-components/docs/combobox.md +1003 -0
- package/ui-components/docs/context-menu.md +860 -0
- package/ui-components/docs/data-table.md +1580 -0
- package/ui-components/docs/date-picker.md +614 -0
- package/ui-components/docs/dialog.md +414 -0
- package/ui-components/docs/drawer.md +51 -0
- package/ui-components/docs/dropdown-menu.md +1000 -0
- package/ui-components/docs/field.md +1192 -0
- package/ui-components/docs/hover-card.md +275 -0
- package/ui-components/docs/input-group.md +866 -0
- package/ui-components/docs/input.md +456 -0
- package/ui-components/docs/kbd.md +191 -0
- package/ui-components/docs/label.md +295 -0
- package/ui-components/docs/pagination.md +416 -0
- package/ui-components/docs/popover.md +348 -0
- package/ui-components/docs/progress.md +214 -0
- package/ui-components/docs/radio-group.md +389 -0
- package/ui-components/docs/resizable.md +265 -0
- package/ui-components/docs/select.md +616 -0
- package/ui-components/docs/separator.md +216 -0
- package/ui-components/docs/skeleton.md +205 -0
- package/ui-components/docs/slider.md +226 -0
- package/ui-components/docs/spinner.md +332 -0
- package/ui-components/docs/switch.md +236 -0
- package/ui-components/docs/table.md +551 -0
- package/ui-components/docs/tabs.md +379 -0
- package/ui-components/docs/textarea.md +187 -0
- package/ui-components/docs/toggle-group.md +370 -0
- package/ui-components/docs/toggle.md +91 -0
- package/ui-components/docs/tooltip.md +290 -0
- package/ui-components/drawer.tsx +213 -0
- package/ui-components/dropdown-menu.tsx +263 -0
- package/ui-components/field.tsx +224 -0
- package/ui-components/hover-card.tsx +46 -0
- package/ui-components/input-group.tsx +146 -0
- package/ui-components/input.tsx +20 -0
- package/ui-components/kbd.tsx +32 -0
- package/ui-components/label.tsx +17 -0
- package/ui-components/pagination.tsx +124 -0
- package/ui-components/popover.tsx +81 -0
- package/ui-components/progress.tsx +63 -0
- package/ui-components/radio-group.tsx +38 -0
- package/ui-components/resizable.tsx +40 -0
- package/ui-components/scoped-portal.tsx +31 -0
- package/ui-components/select.tsx +195 -0
- package/ui-components/separator.tsx +18 -0
- package/ui-components/skeleton.tsx +15 -0
- package/ui-components/slider.tsx +75 -0
- package/ui-components/spinner.tsx +20 -0
- package/ui-components/switch.tsx +27 -0
- package/ui-components/table.tsx +86 -0
- package/ui-components/tabs.tsx +75 -0
- package/ui-components/textarea.tsx +17 -0
- package/ui-components/toggle-group.tsx +85 -0
- package/ui-components/toggle.tsx +42 -0
- package/ui-components/tooltip.tsx +61 -0
- package/ui-components/utils.ts +8 -0
- package/workspace/.claude/skills/moi-workspace/SKILL.md +295 -248
- package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +100 -152
- package/workspace/.claude/skills/moi-workspace/references/INTENTS.md +156 -0
- package/workspace/.claude/skills/moi-workspace/references/UI-COMPONENTS.md +67 -203
- 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 -92
- 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 -264
- package/client/features/widgets/useGridReconcile.ts +0 -73
- package/dist/chunk-104m57qw.js +0 -2
- package/dist/chunk-59zf0m6n.js +0 -1
- package/dist/chunk-bj3akjs2.js +0 -1
- package/dist/chunk-c9pjqx9m.js +0 -14
- package/dist/chunk-j2w2vak4.js +0 -546
- package/dist/chunk-k2r9c95m.js +0 -10
- package/dist/chunk-kmbxhgwv.js +0 -1
- package/dist/chunk-p1yqa71k.js +0 -83
- package/dist/chunk-pcnahct1.js +0 -5
- package/dist/chunk-r5xrenjy.css +0 -1
- package/dist/chunk-tny85yt2.js +0 -2
- package/dist/chunk-v7wr1df4.js +0 -2
- package/server/bundler/applet-css.ts +0 -155
- /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/{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/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/{useSelectedSession.ts → sessions/useSelectedSession.ts} +0 -0
package/lib/format.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { AttachmentOrigin, DrawingPurpose, TextAttachment } from './types'
|
|
2
|
+
|
|
1
3
|
// Display-only conversation format. Agent-agnostic.
|
|
2
4
|
// Source: server/harness/README.md (format section; formerly claude-code-messages.md §14) (and the research PDF under dev/report).
|
|
3
5
|
// Built at ingest time from an agent's raw stream (today: Claude Agent SDK).
|
|
@@ -50,6 +52,7 @@ export type ToolCall = {
|
|
|
50
52
|
export type Citation = { url?: string; title?: string; quote?: string }
|
|
51
53
|
|
|
52
54
|
export type Part =
|
|
55
|
+
| ({ type: 'text-attachment' } & TextAttachment)
|
|
53
56
|
| { type: 'text'; text: string; citations?: Citation[] }
|
|
54
57
|
// `redacted` marks reasoning the backend acknowledges but won't hand over:
|
|
55
58
|
// Anthropic's `redacted_thinking`, and the codex app-server's `Reasoning`
|
|
@@ -63,7 +66,15 @@ export type Part =
|
|
|
63
66
|
durationMs?: number
|
|
64
67
|
}
|
|
65
68
|
| { type: 'tool-call'; call: ToolCall }
|
|
66
|
-
| {
|
|
69
|
+
| ({
|
|
70
|
+
type: 'file-attachment'
|
|
71
|
+
mediaType: string
|
|
72
|
+
label?: string
|
|
73
|
+
previewUrl?: string
|
|
74
|
+
path?: string
|
|
75
|
+
// Only present for drawing images.
|
|
76
|
+
purpose?: DrawingPurpose
|
|
77
|
+
} & Partial<AttachmentOrigin>)
|
|
67
78
|
| { type: 'source-url'; url: string; title?: string; sourceId: string }
|
|
68
79
|
| { type: 'source-document'; mediaType: string; title: string; sourceId: string }
|
|
69
80
|
| { type: 'data'; name: string; data: unknown }
|
|
@@ -97,8 +108,8 @@ export type TurnMeta = {
|
|
|
97
108
|
model?: string
|
|
98
109
|
provider?: string
|
|
99
110
|
stopReason?: string
|
|
100
|
-
// Agent-run duration.
|
|
101
|
-
//
|
|
111
|
+
// Agent-run duration. Prefer native duration when item timestamps cannot
|
|
112
|
+
// measure the run (Codex replay items can share one start timestamp).
|
|
102
113
|
durationMs?: number
|
|
103
114
|
usage?: { inputTokens?: number; outputTokens?: number; totalTokens?: number; costUsd?: number }
|
|
104
115
|
// The API message id (`msg_...`) that produced this assistant turn, when the
|
|
@@ -142,6 +153,7 @@ export type SessionSnapshot = {
|
|
|
142
153
|
}
|
|
143
154
|
|
|
144
155
|
export type SystemNotice =
|
|
156
|
+
| { id: string; kind: 'warning'; at: string; message: string }
|
|
145
157
|
| {
|
|
146
158
|
id: string
|
|
147
159
|
kind: 'rate-limit'
|
|
@@ -152,9 +164,9 @@ export type SystemNotice =
|
|
|
152
164
|
id: string
|
|
153
165
|
kind: 'api-retry'
|
|
154
166
|
at: string
|
|
155
|
-
attempt
|
|
156
|
-
maxRetries
|
|
157
|
-
delayMs
|
|
167
|
+
attempt?: number
|
|
168
|
+
maxRetries?: number
|
|
169
|
+
delayMs?: number
|
|
158
170
|
error?: string
|
|
159
171
|
}
|
|
160
172
|
| { id: string; kind: 'compact'; at: string; metadata?: unknown }
|
|
@@ -284,5 +296,53 @@ export function applyEvent(state: ViewState, ev: StreamEvent): ViewState {
|
|
|
284
296
|
}
|
|
285
297
|
|
|
286
298
|
export function applyEvents(events: StreamEvent[]): ViewState {
|
|
287
|
-
|
|
299
|
+
// Replay owns these arrays, so it can upsert in place instead of copying the
|
|
300
|
+
// entire transcript per event. The live single-event reducer stays immutable.
|
|
301
|
+
const state = emptyViewState()
|
|
302
|
+
const turnIndexes = new Map<string, number>()
|
|
303
|
+
const notices = new Map<string, SystemNotice>()
|
|
304
|
+
let maxSeq = -Infinity
|
|
305
|
+
|
|
306
|
+
for (const event of events) {
|
|
307
|
+
switch (event.kind) {
|
|
308
|
+
case 'snapshot':
|
|
309
|
+
state.snapshot = event.snapshot
|
|
310
|
+
break
|
|
311
|
+
case 'turn': {
|
|
312
|
+
const turn = event.turn
|
|
313
|
+
const seq = turn.seq
|
|
314
|
+
const existingIndex = turnIndexes.get(turn.id)
|
|
315
|
+
if (existingIndex !== undefined) {
|
|
316
|
+
state.turns[existingIndex] = turn
|
|
317
|
+
} else {
|
|
318
|
+
// Append is the common path, including ordered seq-bearing history.
|
|
319
|
+
// A late turn uses the same insertion rule as applyEvent.
|
|
320
|
+
const before =
|
|
321
|
+
seq !== undefined && seq < maxSeq
|
|
322
|
+
? state.turns.findIndex(t => t.seq !== undefined && t.seq > seq)
|
|
323
|
+
: -1
|
|
324
|
+
if (before < 0) {
|
|
325
|
+
turnIndexes.set(turn.id, state.turns.length)
|
|
326
|
+
state.turns.push(turn)
|
|
327
|
+
} else {
|
|
328
|
+
state.turns.splice(before, 0, turn)
|
|
329
|
+
for (let i = before; i < state.turns.length; i++) {
|
|
330
|
+
turnIndexes.set(state.turns[i].id, i)
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
// Keep an upper bound even if an upsert lowers/removes an earlier seq.
|
|
335
|
+
if (seq !== undefined) maxSeq = Math.max(maxSeq, seq)
|
|
336
|
+
break
|
|
337
|
+
}
|
|
338
|
+
case 'notice':
|
|
339
|
+
notices.set(event.notice.id, event.notice)
|
|
340
|
+
break
|
|
341
|
+
case 'result':
|
|
342
|
+
state.result = event.result
|
|
343
|
+
break
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
state.notices = [...notices.values()]
|
|
347
|
+
return state
|
|
288
348
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { isDrawingPurpose, isTextAttachments } from './moi-attachments'
|
|
2
|
+
|
|
3
|
+
import type { MessageAttachment } from './types'
|
|
4
|
+
|
|
5
|
+
export const MAX_MESSAGE_ATTACHMENTS = 10
|
|
6
|
+
|
|
7
|
+
export function messageAttachmentLimitError(value: readonly unknown[]): string | null {
|
|
8
|
+
return value.length > MAX_MESSAGE_ATTACHMENTS
|
|
9
|
+
? `A message can have at most ${MAX_MESSAGE_ATTACHMENTS} attachments.`
|
|
10
|
+
: null
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function isMessageAttachments(value: unknown): value is MessageAttachment[] {
|
|
14
|
+
if (!Array.isArray(value) || messageAttachmentLimitError(value)) return false
|
|
15
|
+
const texts: unknown[] = []
|
|
16
|
+
for (const item of value) {
|
|
17
|
+
if (!item || typeof item !== 'object') return false
|
|
18
|
+
if (item.type === 'upload') {
|
|
19
|
+
if (typeof item.uploadId !== 'string' || !item.uploadId) return false
|
|
20
|
+
if (item.source !== undefined && (typeof item.source !== 'string' || !item.source))
|
|
21
|
+
return false
|
|
22
|
+
if (item.purpose !== undefined && !isDrawingPurpose(item.purpose)) return false
|
|
23
|
+
} else if (item.type === 'text') {
|
|
24
|
+
texts.push(item)
|
|
25
|
+
} else return false
|
|
26
|
+
}
|
|
27
|
+
return isTextAttachments(texts)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Shared by browser validation and both server upload routes.
|
|
31
|
+
export const MAX_UPLOAD_BYTES = 32 * 1024 * 1024
|
|
32
|
+
|
|
33
|
+
export function isWorkspaceAttachmentPath(value: unknown): value is string {
|
|
34
|
+
return (
|
|
35
|
+
typeof value === 'string' &&
|
|
36
|
+
value.length > 0 &&
|
|
37
|
+
!/[\\:\0]/.test(value) &&
|
|
38
|
+
value.split('/').every(segment => segment.length > 0 && !segment.startsWith('.'))
|
|
39
|
+
)
|
|
40
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
// Durable, user-selected context. Unlike ambient moi context, this belongs to
|
|
2
|
+
// one message and is retained in the provider's transcript.
|
|
3
|
+
import type { Part } from './format'
|
|
4
|
+
import { isParamsRecord } from './workspace-tabs'
|
|
5
|
+
import { isAttachmentOnlyPlaceholder, splitAttachmentNote } from './attachment-note'
|
|
6
|
+
import { stripMoiContext } from './moi-context'
|
|
7
|
+
|
|
8
|
+
import type { DrawingPurpose, Attachment, TextAttachmentInput, TextAttachment } from './types'
|
|
9
|
+
export const MAX_TEXT_ATTACHMENT_CHARS = 5000
|
|
10
|
+
export const MAX_ATTACHMENT_LABEL_CHARS = 120
|
|
11
|
+
const OPEN = '<moi-attachments>'
|
|
12
|
+
const CLOSE = '</moi-attachments>'
|
|
13
|
+
|
|
14
|
+
// Copy the display label and immutable text when the user selects it.
|
|
15
|
+
export function snapshotTextAttachment(value: unknown): TextAttachmentInput | null {
|
|
16
|
+
if (!isParamsRecord(value) || typeof value.label !== 'string') return null
|
|
17
|
+
const label = value.label.trim()
|
|
18
|
+
if (
|
|
19
|
+
!label ||
|
|
20
|
+
label.length > MAX_ATTACHMENT_LABEL_CHARS ||
|
|
21
|
+
typeof value.text !== 'string' ||
|
|
22
|
+
!value.text.trim() ||
|
|
23
|
+
value.text.length > MAX_TEXT_ATTACHMENT_CHARS
|
|
24
|
+
)
|
|
25
|
+
return null
|
|
26
|
+
return { label, text: value.text }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function isTextAttachments(value: unknown): value is TextAttachment[] {
|
|
30
|
+
return (
|
|
31
|
+
Array.isArray(value) &&
|
|
32
|
+
value.every(
|
|
33
|
+
item =>
|
|
34
|
+
isParamsRecord(item) &&
|
|
35
|
+
item.purpose === undefined &&
|
|
36
|
+
(item.source === undefined ||
|
|
37
|
+
(typeof item.source === 'string' && item.source.length > 0)) &&
|
|
38
|
+
snapshotTextAttachment(item) !== null
|
|
39
|
+
)
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function isDrawingPurpose(value: unknown): value is DrawingPurpose {
|
|
44
|
+
return value === 'annotation' || value === 'sketch'
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function isResolvedAttachments(value: unknown): value is Attachment[] {
|
|
48
|
+
return (
|
|
49
|
+
Array.isArray(value) &&
|
|
50
|
+
value.every(item => {
|
|
51
|
+
if (!isParamsRecord(item)) return false
|
|
52
|
+
if (item.type === 'text') return isTextAttachments([item])
|
|
53
|
+
if (item.type !== 'file' && item.type !== 'image') return false
|
|
54
|
+
if (item.source !== undefined && (typeof item.source !== 'string' || !item.source))
|
|
55
|
+
return false
|
|
56
|
+
if (typeof item.mediaType !== 'string' || !item.mediaType) return false
|
|
57
|
+
if (
|
|
58
|
+
item.purpose !== undefined &&
|
|
59
|
+
(!isDrawingPurpose(item.purpose) || !item.mediaType.startsWith('image/'))
|
|
60
|
+
)
|
|
61
|
+
return false
|
|
62
|
+
const hasPath =
|
|
63
|
+
typeof item.path === 'string' &&
|
|
64
|
+
/^(\/|[A-Za-z]:[\\/])/.test(item.path) &&
|
|
65
|
+
!item.path.includes('\0')
|
|
66
|
+
if (item.type === 'file') return hasPath && item.label === undefined
|
|
67
|
+
return (
|
|
68
|
+
item.path === undefined &&
|
|
69
|
+
item.mediaType.startsWith('image/') &&
|
|
70
|
+
typeof item.label === 'string' &&
|
|
71
|
+
Boolean(item.label.trim())
|
|
72
|
+
)
|
|
73
|
+
})
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function appendAttachments(text: string, attachments: readonly Attachment[]): string {
|
|
78
|
+
if (!attachments.length) return text
|
|
79
|
+
if (!isResolvedAttachments(attachments)) throw new Error('Invalid attachments')
|
|
80
|
+
const json = JSON.stringify(attachments).replaceAll('<', '\\u003c')
|
|
81
|
+
return `${text}\n\n${OPEN}\n${json}\n${CLOSE}`.trim()
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Hide only recognized, complete blocks. Old development envelopes still read.
|
|
85
|
+
export function splitAttachments(text: string): {
|
|
86
|
+
text: string
|
|
87
|
+
attachments: Attachment[]
|
|
88
|
+
} {
|
|
89
|
+
const attachments: Attachment[] = []
|
|
90
|
+
let found = false
|
|
91
|
+
// Serialized JSON escapes '<', so a candidate cannot span another opening
|
|
92
|
+
// tag. A literal tag in the user's text must not swallow the saved block.
|
|
93
|
+
const cleaned = text.replace(
|
|
94
|
+
/<moi-attachments>([^<]*)<\/moi-attachments>/g,
|
|
95
|
+
(block: string, json: string) => {
|
|
96
|
+
try {
|
|
97
|
+
const parsed: unknown = JSON.parse(json)
|
|
98
|
+
const entries =
|
|
99
|
+
isParamsRecord(parsed) && parsed.version === 1 && Array.isArray(parsed.attachments)
|
|
100
|
+
? parsed.attachments.map(item =>
|
|
101
|
+
isParamsRecord(item)
|
|
102
|
+
? { type: 'text', source: item.source, label: item.label, text: item.text }
|
|
103
|
+
: item
|
|
104
|
+
)
|
|
105
|
+
: parsed
|
|
106
|
+
if (!isResolvedAttachments(entries)) return block
|
|
107
|
+
attachments.push(...entries)
|
|
108
|
+
found = true
|
|
109
|
+
return ''
|
|
110
|
+
} catch {
|
|
111
|
+
return block
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
)
|
|
115
|
+
return { text: found ? cleaned.trim() : text, attachments }
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function attachmentLabel(attachment: Attachment): string {
|
|
119
|
+
return attachment.type === 'file' ? attachment.path.split(/[\\/]/).at(-1)! : attachment.label
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function attachmentPart(attachment: Attachment, previewUrl?: string): Part {
|
|
123
|
+
const { source } = attachment
|
|
124
|
+
const label = attachmentLabel(attachment)
|
|
125
|
+
if (attachment.type === 'text') {
|
|
126
|
+
return {
|
|
127
|
+
type: 'text-attachment',
|
|
128
|
+
source: attachment.source,
|
|
129
|
+
label,
|
|
130
|
+
text: attachment.text
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
type: 'file-attachment',
|
|
135
|
+
label,
|
|
136
|
+
mediaType: attachment.mediaType,
|
|
137
|
+
source,
|
|
138
|
+
...(attachment.purpose ? { purpose: attachment.purpose } : {}),
|
|
139
|
+
// Filesystem-only images keep their identity and render as labelled chips.
|
|
140
|
+
previewUrl,
|
|
141
|
+
path: attachment.type === 'file' ? attachment.path : undefined
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Pair image descriptors with native image parts by order. Unclaimed native
|
|
146
|
+
// parts belong to older or external messages and keep their existing display.
|
|
147
|
+
export function attachmentParts(
|
|
148
|
+
attachments: readonly Attachment[],
|
|
149
|
+
nativeImages: readonly Part[] = []
|
|
150
|
+
): Part[] {
|
|
151
|
+
let imageIndex = 0
|
|
152
|
+
const parts: Part[] = attachments.map(attachment => {
|
|
153
|
+
const image = attachment.type === 'image' ? nativeImages[imageIndex++] : undefined
|
|
154
|
+
if (image?.type !== 'file-attachment') return attachmentPart(attachment)
|
|
155
|
+
const part = attachmentPart(attachment, image.previewUrl)
|
|
156
|
+
if (part.type === 'file-attachment') part.path ??= image.path
|
|
157
|
+
return part
|
|
158
|
+
})
|
|
159
|
+
return [...parts, ...nativeImages.slice(imageIndex)]
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Provider adapters first map native blocks to Parts, then share this replay
|
|
163
|
+
// step. File notes are read-only compatibility for published transcripts.
|
|
164
|
+
export function replayAttachmentParts(parts: readonly Part[]): Part[] {
|
|
165
|
+
const raw = parts
|
|
166
|
+
.filter(p => p.type === 'text')
|
|
167
|
+
.map(p => p.text)
|
|
168
|
+
.join('\n')
|
|
169
|
+
const parsed = splitAttachments(stripMoiContext(raw))
|
|
170
|
+
const legacy = splitAttachmentNote(parsed.text)
|
|
171
|
+
const nativeImages = parts.filter(
|
|
172
|
+
p => p.type === 'file-attachment' && p.mediaType.startsWith('image/')
|
|
173
|
+
)
|
|
174
|
+
const rest = parts.filter(p => p.type !== 'text' && !nativeImages.includes(p))
|
|
175
|
+
const displayed: Part[] = [
|
|
176
|
+
...attachmentParts(parsed.attachments, nativeImages),
|
|
177
|
+
...legacy.files.map(file => ({
|
|
178
|
+
type: 'file-attachment' as const,
|
|
179
|
+
label: file.filename,
|
|
180
|
+
mediaType: 'application/octet-stream',
|
|
181
|
+
path: file.path
|
|
182
|
+
})),
|
|
183
|
+
...rest
|
|
184
|
+
]
|
|
185
|
+
const text =
|
|
186
|
+
isAttachmentOnlyPlaceholder(legacy.text) && displayed.some(p => p.type === 'file-attachment')
|
|
187
|
+
? ''
|
|
188
|
+
: legacy.text
|
|
189
|
+
if (text) displayed.push({ type: 'text', text })
|
|
190
|
+
return displayed
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function stripAttachments(text: string): string {
|
|
194
|
+
return splitAttachments(text).text
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Truncated session previews may end halfway through the metadata block.
|
|
198
|
+
export function stripAttachmentsLoose(text: string): string {
|
|
199
|
+
const clean = stripAttachments(text)
|
|
200
|
+
const start = clean.search(/<moi-attachments>\s*(?:\[|\{"version":1,"attachments":\[)/)
|
|
201
|
+
// Only hide an unfinished block with our serialized prefix. Literal tags and
|
|
202
|
+
// complete malformed blocks still belong to the user's visible text.
|
|
203
|
+
return (start < 0 || clean.includes(CLOSE, start) ? clean : clean.slice(0, start)).trimEnd()
|
|
204
|
+
}
|
package/lib/moi-context.ts
CHANGED
|
@@ -39,9 +39,6 @@ const SYSTEM_REMINDER_CLOSE = '</system-reminder>'
|
|
|
39
39
|
// claim to be another one.
|
|
40
40
|
export type MoiAppletMessage = {
|
|
41
41
|
source: string
|
|
42
|
-
// The structured payload the applet attached to the call. JSON-plain, and
|
|
43
|
-
// dropped entirely when it doesn't survive serialization.
|
|
44
|
-
context?: Record<string, unknown>
|
|
45
42
|
}
|
|
46
43
|
|
|
47
44
|
// The structured form built at send time — by the client for chat sends, by
|
|
@@ -49,17 +46,17 @@ export type MoiAppletMessage = {
|
|
|
49
46
|
// `renderMoiContext`) when new ambient fields land.
|
|
50
47
|
export type MoiContext = {
|
|
51
48
|
// The workspace tab the user is on when they hit send — for a view-builder
|
|
52
|
-
// request that's the builder's own tab (`view-
|
|
49
|
+
// request that's the builder's own tab (`view-builders/<id>`).
|
|
53
50
|
activeTab: WorkspaceTabId
|
|
54
51
|
// UI label of the active tab when it differs from the id — a view's
|
|
55
|
-
// configured title (e.g. "Grading review" for `
|
|
52
|
+
// configured title (e.g. "Grading review" for `views/color-studio`), or a
|
|
56
53
|
// view builder's claimed title while the build runs. The tab bar falls
|
|
57
54
|
// back to the id when unset; so does the envelope.
|
|
58
55
|
tabTitle?: string
|
|
59
56
|
// The params the active view is rendering with right now, straight from
|
|
60
|
-
//
|
|
57
|
+
// URL query strings. The emitter side of the same contract (`navigate`) sets
|
|
61
58
|
// them, so the agent sees a view's addressable state in both directions.
|
|
62
|
-
// Absent for tabs that take no params (
|
|
59
|
+
// Absent for tabs that take no params (overview, scratchpad, agent).
|
|
63
60
|
tabParams?: Record<string, unknown>
|
|
64
61
|
// Set when this message came from applet UI instead of the composer.
|
|
65
62
|
applet?: MoiAppletMessage
|
|
@@ -68,14 +65,10 @@ export type MoiContext = {
|
|
|
68
65
|
directives?: string[]
|
|
69
66
|
}
|
|
70
67
|
|
|
71
|
-
// Cap on
|
|
72
|
-
|
|
73
|
-
// boundary rather than letting it ride the wire — the renderer's truncation is
|
|
74
|
-
// the backstop for anything that still gets through (e.g. a server-built
|
|
75
|
-
// context).
|
|
76
|
-
export const MAX_APPLET_CONTEXT_CHARS = 2000
|
|
68
|
+
// Cap on ambient view params rendered into the workspace envelope.
|
|
69
|
+
const MAX_TAB_PARAMS_CHARS = 2000
|
|
77
70
|
|
|
78
|
-
// Applet-authored strings (view titles, applet names,
|
|
71
|
+
// Applet-authored strings (view titles, applet names, view params) get
|
|
79
72
|
// interpolated into the envelope, and applet code is agent-authored — a
|
|
80
73
|
// crafted value containing `</moi-context>` would otherwise close the envelope
|
|
81
74
|
// early and forge sections the host never wrote. Escaping `<` defuses every
|
|
@@ -88,7 +81,7 @@ function escapeTags(text: string): string {
|
|
|
88
81
|
// Render an applet-authored record for the envelope, or null when there's
|
|
89
82
|
// nothing worth printing. Non-serializable values (cycles, BigInt) drop rather
|
|
90
83
|
// than throw mid-send.
|
|
91
|
-
function
|
|
84
|
+
function renderTabParams(value: Record<string, unknown>): string | null {
|
|
92
85
|
let json: string
|
|
93
86
|
try {
|
|
94
87
|
json = JSON.stringify(value)
|
|
@@ -97,8 +90,8 @@ function renderAppletJson(value: Record<string, unknown>): string | null {
|
|
|
97
90
|
}
|
|
98
91
|
if (!json || json === '{}') return null
|
|
99
92
|
const capped =
|
|
100
|
-
json.length >
|
|
101
|
-
? `${json.slice(0,
|
|
93
|
+
json.length > MAX_TAB_PARAMS_CHARS
|
|
94
|
+
? `${json.slice(0, MAX_TAB_PARAMS_CHARS)}… (truncated)`
|
|
102
95
|
: json
|
|
103
96
|
return escapeTags(capped)
|
|
104
97
|
}
|
|
@@ -128,16 +121,16 @@ function describeTab(tab: WorkspaceTabId, rawTitle?: string): string {
|
|
|
128
121
|
// other applet-authored string in here.
|
|
129
122
|
const title = rawTitle === undefined ? undefined : escapeTags(rawTitle)
|
|
130
123
|
if (tab === 'agent') return 'The user is on the "Agent" tab (full page chat).'
|
|
131
|
-
if (tab === '
|
|
124
|
+
if (tab === 'overview') return 'The user is on the "Overview" tab.'
|
|
132
125
|
if (tab === 'scratchpad') return 'The user is on the "Scratchpad" tab.'
|
|
133
|
-
if (tab.startsWith('view-
|
|
134
|
-
const id = tab.slice('view-
|
|
126
|
+
if (tab.startsWith('view-builders/')) {
|
|
127
|
+
const id = tab.slice('view-builders/'.length)
|
|
135
128
|
return title
|
|
136
129
|
? `The user is building a new view "${title}". Builder id "${id}".`
|
|
137
130
|
: `The user is building a new view. Builder id "${id}".`
|
|
138
131
|
}
|
|
139
|
-
if (tab.startsWith('
|
|
140
|
-
const id = tab.slice('
|
|
132
|
+
if (tab.startsWith('views/')) {
|
|
133
|
+
const id = tab.slice('views/'.length)
|
|
141
134
|
return `The user is on the "${title ?? id}" view tab (.moi/views/${id}.tsx).`
|
|
142
135
|
}
|
|
143
136
|
return `The user is on the "${tab}" tab.`
|
|
@@ -155,16 +148,13 @@ export function renderMoiContextBody(ctx: MoiContext): string {
|
|
|
155
148
|
'Read the **`moi-workspace` skill** before responding — even to a simple question — unless you already read it in this chat.'
|
|
156
149
|
].join('\n')
|
|
157
150
|
const tabLines = [describeTab(ctx.activeTab, ctx.tabTitle)]
|
|
158
|
-
const tabParams = ctx.tabParams ?
|
|
151
|
+
const tabParams = ctx.tabParams ? renderTabParams(ctx.tabParams) : null
|
|
159
152
|
if (tabParams) tabLines.push(`Params it is rendering with right now: ${tabParams}`)
|
|
160
153
|
const sections = [`# Active tab\n${tabLines.join('\n')}`]
|
|
161
154
|
if (ctx.applet) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const context = ctx.applet.context ? renderAppletJson(ctx.applet.context) : null
|
|
166
|
-
if (context) appletLines.push(`It attached this context: ${context}`)
|
|
167
|
-
sections.push(`# Applet message\n${appletLines.join('\n')}`)
|
|
155
|
+
sections.push(
|
|
156
|
+
`# Applet message\nThe message above was not typed by the user — the ${describeAppletSource(ctx.applet.source)} sent it when the user acted in its UI.`
|
|
157
|
+
)
|
|
168
158
|
}
|
|
169
159
|
if (ctx.directives?.length) {
|
|
170
160
|
sections.push(`# This message only\n${ctx.directives.join('\n')}`)
|
|
@@ -202,12 +192,7 @@ export function isMoiContext(value: unknown): value is MoiContext {
|
|
|
202
192
|
|
|
203
193
|
function isMoiAppletMessage(value: unknown): value is MoiAppletMessage {
|
|
204
194
|
if (!isParamsRecord(value)) return false
|
|
205
|
-
|
|
206
|
-
return (
|
|
207
|
-
typeof v.source === 'string' &&
|
|
208
|
-
v.source.length > 0 &&
|
|
209
|
-
(v.context === undefined || isParamsRecord(v.context))
|
|
210
|
-
)
|
|
195
|
+
return typeof value.source === 'string' && value.source.length > 0
|
|
211
196
|
}
|
|
212
197
|
|
|
213
198
|
// Claude Code: the envelope rides as its OWN text block wrapped in
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { WorkspaceTabId } from './types'
|
|
2
|
+
import { isWorkspaceTabId } from './workspace-tabs'
|
|
3
|
+
|
|
4
|
+
export type ViewParams = Record<string, string>
|
|
5
|
+
export type WorkspaceAddress = { tab: WorkspaceTabId; search: string }
|
|
6
|
+
|
|
7
|
+
// Public destinations deliberately exclude the current singleton chat and
|
|
8
|
+
// transient builders.
|
|
9
|
+
export function parseMoiHref(href: unknown): WorkspaceAddress {
|
|
10
|
+
if (typeof href !== 'string' || !href.startsWith('moi:/') || href.startsWith('moi://')) {
|
|
11
|
+
throw new Error('Expected a workspace address such as moi:/views/events?eventId=123')
|
|
12
|
+
}
|
|
13
|
+
const path = href.slice(5).split(/[?#]/, 1)[0]
|
|
14
|
+
if (href.includes('#') || /[\s\\]/.test(path)) throw new Error('Invalid workspace address')
|
|
15
|
+
const tab = tabFromPath(path)
|
|
16
|
+
if (!tab || tab === 'agent' || tab.startsWith('view-builders/')) {
|
|
17
|
+
throw new Error(`Unsupported workspace destination: ${path}`)
|
|
18
|
+
}
|
|
19
|
+
const query = href.indexOf('?')
|
|
20
|
+
const search = query < 0 ? '' : canonicalSearch(href.slice(query + 1))
|
|
21
|
+
return { tab, search }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function canonicalSearch(search: string): string {
|
|
25
|
+
// Sorting makes equivalent addresses a no-op instead of adding history entries.
|
|
26
|
+
const params = new URLSearchParams(search)
|
|
27
|
+
params.sort()
|
|
28
|
+
const result = params.toString()
|
|
29
|
+
return result ? `?${result}` : ''
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function readViewParams(search: string): ViewParams {
|
|
33
|
+
const params = new URLSearchParams(search)
|
|
34
|
+
return Object.fromEntries(Array.from(params.keys(), key => [key, params.get(key)!]))
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function tabFromPath(path: string): WorkspaceTabId | null {
|
|
38
|
+
try {
|
|
39
|
+
const tab = decodeURIComponent(path)
|
|
40
|
+
return isWorkspaceTabId(tab) ? tab : null
|
|
41
|
+
} catch {
|
|
42
|
+
return null
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Compatibility for old browser bookmarks only; saved tab state uses paths.
|
|
47
|
+
export function legacyTabFromPath(path: string): WorkspaceTabId | null {
|
|
48
|
+
const match = /^(view|view-builder):(.+)$/.exec(path)
|
|
49
|
+
return match ? tabFromPath(`${match[1]}s/${match[2]}`) : null
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function moiHref(tab: WorkspaceTabId, search = ''): string {
|
|
53
|
+
return `moi:/${tab}${canonicalSearch(search)}`
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Deployment-specific addressing is confined to this host adapter. Callers
|
|
57
|
+
// may supply the router base; portable links never contain it.
|
|
58
|
+
export function workspacePath(workspaceId: string, base = ''): string {
|
|
59
|
+
return `${base.replace(/\/$/, '')}/workspace/${encodeURIComponent(workspaceId)}`
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function addressPath(workspaceId: string, address: WorkspaceAddress, base = ''): string {
|
|
63
|
+
return `${workspacePath(workspaceId, base)}/${address.tab}${address.search}`
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function workspaceTabPath(workspaceId: string, tab: WorkspaceTabId): string {
|
|
67
|
+
return addressPath(workspaceId, { tab, search: '' })
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function resolveWorkspaceHref(workspaceId: string, href: string, base = ''): string {
|
|
71
|
+
if (href.startsWith('moi:')) return addressPath(workspaceId, parseMoiHref(href), base)
|
|
72
|
+
// Only explicit ordinary web addresses may leave the workspace through the
|
|
73
|
+
// imperative API. Native anchors keep their existing protocol policy.
|
|
74
|
+
const url = new URL(href)
|
|
75
|
+
if (url.protocol !== 'https:' && url.protocol !== 'http:') throw new Error('Unsupported URL')
|
|
76
|
+
return url.href
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export type NavigationRequest = {
|
|
80
|
+
type: 'navigation:request'
|
|
81
|
+
requestId: string
|
|
82
|
+
workspaceId: string
|
|
83
|
+
href: string
|
|
84
|
+
}
|
package/lib/themes.ts
CHANGED
|
@@ -119,11 +119,11 @@ const THEME_COLOR_DERIVATIONS = {
|
|
|
119
119
|
workspace: {
|
|
120
120
|
primary: primary => primary,
|
|
121
121
|
primaryForeground: primary => foregroundForPrimary(primary),
|
|
122
|
-
background: () => 'color-mix(in srgb, var(--primary)
|
|
122
|
+
background: () => 'color-mix(in srgb, var(--primary) 2%, oklch(1 0 0) 98%)',
|
|
123
123
|
foreground: () => 'color-mix(in srgb, var(--primary) 20%, oklch(0 0 0) 80%)',
|
|
124
|
-
muted: () => 'color-mix(in srgb, var(--background)
|
|
124
|
+
muted: () => 'color-mix(in srgb, var(--background) 95%, var(--foreground) 5%)',
|
|
125
125
|
mutedForeground: () => 'color-mix(in srgb, var(--background) 50%, var(--foreground) 50%)',
|
|
126
|
-
accent: () => 'color-mix(in srgb, var(--primary)
|
|
126
|
+
accent: () => 'color-mix(in srgb, var(--primary) 3%, var(--foreground) 4%)',
|
|
127
127
|
accentForeground: () => 'var(--foreground)',
|
|
128
128
|
border: () => 'color-mix(in srgb, var(--foreground) 7%, transparent)',
|
|
129
129
|
ring: () => 'color-mix(in srgb, var(--background) 50%, var(--primary) 50%)'
|
|
@@ -131,11 +131,11 @@ const THEME_COLOR_DERIVATIONS = {
|
|
|
131
131
|
widget: {
|
|
132
132
|
background: primary => primary,
|
|
133
133
|
foreground: primary => foregroundForPrimary(primary),
|
|
134
|
-
primary: () => 'color-mix(in srgb, var(--background)
|
|
134
|
+
primary: () => 'color-mix(in srgb, var(--background) 2%, oklch(1 0 0) 98%)',
|
|
135
135
|
primaryForeground: () => 'color-mix(in srgb, var(--background) 20%, oklch(0 0 0) 80%)',
|
|
136
|
-
muted: () => 'color-mix(in srgb, var(--background)
|
|
136
|
+
muted: () => 'color-mix(in srgb, var(--background) 95%, var(--foreground) 5%)',
|
|
137
137
|
mutedForeground: () => 'color-mix(in srgb, var(--background) 50%, var(--foreground) 50%)',
|
|
138
|
-
accent: () => 'color-mix(in srgb, var(--primary)
|
|
138
|
+
accent: () => 'color-mix(in srgb, var(--primary) 3%, var(--foreground) 4%)',
|
|
139
139
|
accentForeground: () => 'var(--foreground)',
|
|
140
140
|
border: () => 'color-mix(in srgb, var(--foreground) 15%, transparent)',
|
|
141
141
|
ring: () => 'color-mix(in srgb, var(--background) 50%, var(--primary) 50%)'
|