moi-computer 0.11.1-next.2 → 0.11.1-next.3
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 +1 -1
- 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-1pp135b4.js +1 -0
- package/dist/chunk-2gs8jjx4.css +1 -0
- package/dist/chunk-94m3q9ce.js +1 -0
- package/dist/chunk-azkjzc7a.js +68 -0
- package/dist/{chunk-w482ew2c.js → chunk-brr0zbeh.js} +73 -73
- 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 +79 -24
- 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,4 +1,4 @@
|
|
|
1
|
-
import"/chunk-
|
|
1
|
+
import"/chunk-tzz101ea.js";function t(z,Q){return z[13]=1,z[14]=Q>>8,z[15]=Q&255,z[16]=Q>>8,z[17]=Q&255,z}var e=112,zz=72,Qz=89,Zz=115,p;function Nz(){let z=new Int32Array(256);for(let Q=0;Q<256;Q++){let Z=Q;for(let $=0;$<8;$++)Z=Z&1?3988292384^Z>>>1:Z>>>1;z[Q]=Z}return z}function Iz(z){let Q=-1;if(!p)p=Nz();for(let Z=0;Z<z.length;Z++)Q=p[(Q^z[Z])&255]^Q>>>8;return Q^-1}function Uz(z){let Q=z.length-1;for(let Z=Q;Z>=4;Z--)if(z[Z-4]===9&&z[Z-3]===e&&z[Z-2]===zz&&z[Z-1]===Qz&&z[Z]===Zz)return Z-3;return 0}function $z(z,Q,Z=!1){let $=new Uint8Array(13);Q*=39.3701,$[0]=e,$[1]=zz,$[2]=Qz,$[3]=Zz,$[4]=Q>>>24,$[5]=Q>>>16,$[6]=Q>>>8,$[7]=Q&255,$[8]=$[4],$[9]=$[5],$[10]=$[6],$[11]=$[7],$[12]=1;let Y=Iz($),K=new Uint8Array(4);if(K[0]=Y>>>24,K[1]=Y>>>16,K[2]=Y>>>8,K[3]=Y&255,Z){let X=Uz(z);return z.set($,X),z.set(K,X+13),z}else{let X=new Uint8Array(4);X[0]=0,X[1]=0,X[2]=0,X[3]=9;let J=new Uint8Array(54);return J.set(z,0),J.set(X,33),J.set($,37),J.set(K,50),J}}var Dz="AAlwSFlz",Fz="AAAJcEhZ",Rz="AAAACXBI";function wz(z){let Q=z.indexOf(Dz);if(Q===-1)Q=z.indexOf(Fz);if(Q===-1)Q=z.indexOf(Rz);return Q}var Jz="[modern-screenshot]",D=typeof window<"u",Ez=D&&"Worker"in window,Kz=D&&"atob"in window,Cz=D&&"btoa"in window,x=D?window.navigator?.userAgent:"",Yz=x.includes("Chrome"),S=x.includes("AppleWebKit")&&!Yz,u=x.includes("Firefox"),fz=(z)=>z&&("__CONTEXT__"in z),Tz=(z)=>z.constructor.name==="CSSFontFaceRule",bz=(z)=>z.constructor.name==="CSSImportRule",Sz=(z)=>z.constructor.name==="CSSLayerBlockRule",k=(z)=>z.nodeType===1,f=(z)=>typeof z.className==="object",Xz=(z)=>z.tagName==="image",hz=(z)=>z.tagName==="use",w=(z)=>k(z)&&typeof z.style<"u"&&!f(z),gz=(z)=>z.nodeType===8,vz=(z)=>z.nodeType===3,R=(z)=>z.tagName==="IMG",h=(z)=>z.tagName==="VIDEO",pz=(z)=>z.tagName==="CANVAS",yz=(z)=>z.tagName==="TEXTAREA",mz=(z)=>z.tagName==="INPUT",xz=(z)=>z.tagName==="STYLE",uz=(z)=>z.tagName==="SCRIPT",iz=(z)=>z.tagName==="SELECT",cz=(z)=>z.tagName==="SLOT",dz=(z)=>z.tagName==="IFRAME",az=(...z)=>console.warn(Jz,...z);function lz(z){let Q=z?.createElement?.("canvas");if(Q)Q.height=Q.width=1;return Boolean(Q)&&"toDataURL"in Q&&Boolean(Q.toDataURL("image/webp").includes("image/webp"))}var y=(z)=>z.startsWith("data:");function Gz(z,Q){if(z.match(/^[a-z]+:\/\//i))return z;if(D&&z.match(/^\/\//))return window.location.protocol+z;if(z.match(/^[a-z]+:/i))return z;if(!D)return z;let Z=g().implementation.createHTMLDocument(),$=Z.createElement("base"),Y=Z.createElement("a");if(Z.head.appendChild($),Z.body.appendChild(Y),Q)$.href=Q;return Y.href=z,Y.href}function g(z){return(z&&k(z)?z?.ownerDocument:z)??window.document}var v="http://www.w3.org/2000/svg";function jz(z,Q,Z){let $=g(Z).createElementNS(v,"svg");return $.setAttributeNS(null,"width",z.toString()),$.setAttributeNS(null,"height",Q.toString()),$.setAttributeNS(null,"viewBox",`0 0 ${z} ${Q}`),$}function Vz(z,Q){let Z=new XMLSerializer().serializeToString(z);if(Q)Z=Z.replace(/[\u0000-\u0008\v\f\u000E-\u001F\uD800-\uDFFF\uFFFE\uFFFF]/gu,"");return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(Z)}`}async function sz(z,Q="image/png",Z=1){try{return await new Promise(($,Y)=>{z.toBlob((K)=>{if(K)$(K);else Y(Error("Blob is null"))},Q,Z)})}catch($){if(Kz)return rz(z.toDataURL(Q,Z));throw $}}function rz(z){let[Q,Z]=z.split(","),$=Q.match(/data:(.+);/)?.[1]??void 0,Y=window.atob(Z),K=Y.length,X=new Uint8Array(K);for(let J=0;J<K;J+=1)X[J]=Y.charCodeAt(J);return new Blob([X],{type:$})}function Hz(z,Q){return new Promise((Z,$)=>{let Y=new FileReader;if(Y.onload=()=>Z(Y.result),Y.onerror=()=>$(Y.error),Y.onabort=()=>$(Error(`Failed read blob to ${Q}`)),Q==="dataUrl")Y.readAsDataURL(z);else if(Q==="arrayBuffer")Y.readAsArrayBuffer(z)})}var nz=(z)=>Hz(z,"dataUrl"),oz=(z)=>Hz(z,"arrayBuffer");function F(z,Q){let Z=g(Q).createElement("img");return Z.decoding="sync",Z.loading="eager",Z.src=z,Z}function E(z,Q){return new Promise((Z)=>{let{timeout:$,ownerDocument:Y,onError:K,onWarn:X}=Q??{},J=typeof z==="string"?F(z,g(Y)):z,V=null,j=null;function G(){Z(J),V&&clearTimeout(V),j?.()}if($)V=setTimeout(G,$);if(h(J)){let M=J.currentSrc||J.src;if(!M){if(J.poster)return E(J.poster,Q).then(Z);return G()}if(J.readyState>=2)return G();let B=G,q=(W)=>{X?.("Failed video load",M,W),K?.(W),G()};j=()=>{J.removeEventListener("loadeddata",B),J.removeEventListener("error",q)},J.addEventListener("loadeddata",B,{once:!0}),J.addEventListener("error",q,{once:!0})}else{let M=Xz(J)?J.href.baseVal:J.currentSrc||J.src;if(!M)return G();let B=async()=>{if(R(J)&&"decode"in J)try{await J.decode()}catch(W){X?.("Failed to decode image, trying to render anyway",J.dataset.originalSrc||M,W)}G()},q=(W)=>{X?.("Failed image load",J.dataset.originalSrc||M,W),G()};if(R(J)&&J.complete)return B();j=()=>{J.removeEventListener("load",B),J.removeEventListener("error",q)},J.addEventListener("load",B,{once:!0}),J.addEventListener("error",q,{once:!0})}})}async function tz(z,Q){if(w(z))if(R(z)||h(z))await E(z,Q);else await Promise.all(["img","video"].flatMap((Z)=>{return Array.from(z.querySelectorAll(Z)).map(($)=>E($,Q))}))}var Bz=function(){let Q=0,Z=()=>`0000${(Math.random()*1679616<<0).toString(36)}`.slice(-4);return()=>{return Q+=1,`u${Z()}${Q}`}}();function Mz(z){return z?.split(",").map((Q)=>Q.trim().replace(/"|'/g,"").toLowerCase()).filter(Boolean)}var a=0;function ez(z){let Q=`${Jz}[#${a}]`;return a++,{time:(Z)=>z&&console.time(`${Q} ${Z}`),timeEnd:(Z)=>z&&console.timeEnd(`${Q} ${Z}`),warn:(...Z)=>z&&az(...Z)}}function zQ(z){return{cache:z?"no-cache":"force-cache"}}async function N(z,Q){return fz(z)?z:QQ(z,{...Q,autoDestruct:!0})}async function QQ(z,Q){let{scale:Z=1,workerUrl:$,workerNumber:Y=1}=Q||{},K=Boolean(Q?.debug),X=Q?.features??!0,J=z.ownerDocument??(D?window.document:void 0),V=z.ownerDocument?.defaultView??(D?window:void 0),j=new Map,G={width:0,height:0,quality:1,type:"image/png",scale:Z,backgroundColor:null,style:null,filter:null,maximumCanvasSize:0,timeout:30000,progress:null,debug:K,fetch:{requestInit:zQ(Q?.fetch?.bypassingCache),placeholderImage:"data:image/png;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",bypassingCache:!1,...Q?.fetch},fetchFn:null,font:{},drawImageInterval:100,workerUrl:null,workerNumber:Y,onCloneEachNode:null,onCloneNode:null,onEmbedNode:null,onCreateForeignObjectSvg:null,includeStyleProperties:null,autoDestruct:!1,...Q,__CONTEXT__:!0,log:ez(K),node:z,ownerDocument:J,ownerWindow:V,dpi:Z===1?null:96*Z,svgStyleElement:qz(J),svgDefsElement:J?.createElementNS(v,"defs"),svgStyles:new Map,defaultComputedStyles:new Map,workers:[...Array.from({length:Ez&&$&&Y?Y:0})].map(()=>{try{let q=new Worker($);return q.onmessage=async(W)=>{let{url:H,result:L}=W.data;if(L)j.get(H)?.resolve?.(L);else j.get(H)?.reject?.(Error(`Error receiving message from worker: ${H}`))},q.onmessageerror=(W)=>{let{url:H}=W.data;j.get(H)?.reject?.(Error(`Error receiving message from worker: ${H}`))},q}catch(q){return G.log.warn("Failed to new Worker",q),null}}).filter(Boolean),fontFamilies:new Map,fontCssTexts:new Map,acceptOfImage:`${[lz(J)&&"image/webp","image/svg+xml","image/*","*/*"].filter(Boolean).join(",")};q=0.8`,requests:j,drawImageCount:0,tasks:[],features:X,isEnable:(q)=>{if(q==="restoreScrollPosition")return typeof X==="boolean"?!1:X[q]??!1;if(typeof X==="boolean")return X;return X[q]??!0},shadowRoots:[]};G.log.time("wait until load"),await tz(z,{timeout:G.timeout,onWarn:G.log.warn}),G.log.timeEnd("wait until load");let{width:M,height:B}=ZQ(z,G);return G.width=M,G.height=B,G}function qz(z){if(!z)return;let Q=z.createElement("style"),Z=Q.ownerDocument.createTextNode(`
|
|
2
2
|
.______background-clip--text {
|
|
3
3
|
background-clip: text;
|
|
4
4
|
-webkit-background-clip: text;
|
package/dist/index.html
CHANGED
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
}
|
|
37
37
|
</script>
|
|
38
38
|
|
|
39
|
-
<link rel="stylesheet" crossorigin href="/chunk-
|
|
39
|
+
<link rel="stylesheet" crossorigin href="/chunk-2gs8jjx4.css"><script type="module" crossorigin src="/chunk-1pp135b4.js"></script></head>
|
|
40
40
|
<body>
|
|
41
41
|
<div id="root"></div>
|
|
42
42
|
|
package/lib/app-icons.ts
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type AppletSegment = 'widgets' | 'views'
|
|
2
|
+
export type AppletSelector = AppletSegment | `${AppletSegment}/${string}`
|
|
3
|
+
|
|
4
|
+
export type ParsedAppletSelector = {
|
|
5
|
+
segment: AppletSegment
|
|
6
|
+
id?: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const APPLET_SELECTOR_RE = /^(widgets|views)(?:\/([a-z0-9][a-z0-9_-]*))?$/
|
|
10
|
+
|
|
11
|
+
export function parseAppletSelector(value: string): ParsedAppletSelector | null {
|
|
12
|
+
const match = value.match(APPLET_SELECTOR_RE)
|
|
13
|
+
if (!match) return null
|
|
14
|
+
return { segment: match[1] as AppletSegment, ...(match[2] ? { id: match[2] } : {}) }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function appletSelectorMatches(
|
|
18
|
+
selector: AppletSelector,
|
|
19
|
+
segment: AppletSegment,
|
|
20
|
+
id: string
|
|
21
|
+
): boolean {
|
|
22
|
+
const [selectedSegment, selectedId] = selector.split('/')
|
|
23
|
+
return selectedSegment === segment && (!selectedId || selectedId === id)
|
|
24
|
+
}
|
package/lib/chat-title.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import { attachmentLabel, splitAttachments, stripAttachmentsLoose } from './moi-attachments'
|
|
1
2
|
const MAX_CHAT_TITLE_LENGTH = 64
|
|
2
3
|
|
|
3
4
|
export function formatChatTitle(text: string, filenames: readonly string[] = []): string {
|
|
4
|
-
const
|
|
5
|
+
const split = splitAttachments(text)
|
|
6
|
+
const attachmentLabels = split.attachments.map(attachmentLabel)
|
|
7
|
+
const source =
|
|
8
|
+
stripAttachmentsLoose(split.text).trim() ||
|
|
9
|
+
(attachmentLabels.length ? attachmentLabels : filenames).filter(Boolean).join(', ')
|
|
5
10
|
return source.replace(/\s+/gu, ' ').trim().slice(0, MAX_CHAT_TITLE_LENGTH).trimEnd()
|
|
6
11
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { LayoutGridItem, WidgetInfo } from './types'
|
|
2
|
+
|
|
3
|
+
export type DefaultWidgetDefinition = WidgetInfo & {
|
|
4
|
+
defaultPosition: Omit<LayoutGridItem, 'i'>
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const DEFAULT_VIEWS_WIDGET = {
|
|
8
|
+
id: '_moi_views',
|
|
9
|
+
config: { colSpan: 4, rowSpan: 1 },
|
|
10
|
+
defaultPosition: { x: 0, y: 0 }
|
|
11
|
+
} as const satisfies DefaultWidgetDefinition
|
|
12
|
+
|
|
13
|
+
export const DEFAULT_WIDGETS = [
|
|
14
|
+
DEFAULT_VIEWS_WIDGET
|
|
15
|
+
] as const satisfies readonly DefaultWidgetDefinition[]
|
|
16
|
+
|
|
17
|
+
export type DefaultWidgetId = (typeof DEFAULT_WIDGETS)[number]['id']
|
|
18
|
+
|
|
19
|
+
const DEFAULT_WIDGET_IDS = new Set<string>(DEFAULT_WIDGETS.map(widget => widget.id))
|
|
20
|
+
|
|
21
|
+
export function isDefaultWidget(id: string): id is DefaultWidgetId {
|
|
22
|
+
return DEFAULT_WIDGET_IDS.has(id)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Registry order seeds defaults and the hidden panel; saved positions control visible order.
|
|
26
|
+
export function withDefaultWidgets(widgets: readonly WidgetInfo[]): WidgetInfo[] {
|
|
27
|
+
return [...DEFAULT_WIDGETS, ...widgets]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function createDefaultWidgetGrid(): LayoutGridItem[] {
|
|
31
|
+
return DEFAULT_WIDGETS.map(widget => ({ i: widget.id, ...widget.defaultPosition }))
|
|
32
|
+
}
|
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 }
|
|
@@ -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
|
+
}
|