moi-computer 0.3.0-next.2 → 0.3.0
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 +1 -1
- package/client/AGENTS.md +2 -2
- package/client/api/http.ts +1 -1
- package/client/api/workspace-keys.ts +1 -0
- package/client/app/AppRouter.tsx +14 -5
- package/client/app/routes/HomeRoute.tsx +1 -1
- package/client/app/routes/WorkspaceRoute.tsx +8 -2
- package/client/app/shell/SidebarLayout.tsx +10 -5
- package/client/assets/openai.svg +3 -0
- package/client/components/shared/BottomPanel.tsx +2 -2
- package/client/components/ui/button.tsx +3 -2
- package/client/components/ui/input.tsx +1 -1
- package/client/features/applets/AppletMount.tsx +44 -0
- package/client/features/applets/WidgetShell.tsx +4 -1
- package/client/features/applets/applet-cache.ts +8 -0
- package/client/features/applets/applet-styles.ts +61 -0
- package/client/features/chat/ChatComposer.tsx +2 -2
- package/client/features/chat/ChatPanel.tsx +8 -25
- package/client/features/chat/ChatPopup.tsx +3 -3
- package/client/features/chat/{ThreadSelector.tsx → ChatSelector.tsx} +4 -4
- package/client/features/chat/TurnView.tsx +8 -9
- package/client/features/chat/api.ts +1 -1
- package/client/features/chat/chat-send.ts +57 -0
- package/client/features/chat/tool-group/ToolCallGroup.tsx +2 -1
- package/client/features/chat/tool-group/format.ts +117 -0
- package/client/features/chat/useChat.ts +10 -34
- package/client/features/connectors/McpMenu.tsx +4 -21
- package/client/features/dev/DevRoutes.tsx +18 -0
- package/client/features/dev/HarnessDebugPage.tsx +468 -0
- package/client/{components/playground → features/dev}/PlaygroundPage.tsx +1 -1
- package/client/features/home/CreateWorkspaceDialog.tsx +64 -158
- package/client/features/home/CreateWorkspaceDialogSteps.tsx +234 -0
- package/client/features/home/HomeLogo.tsx +344 -0
- package/client/features/home/HomePage.tsx +15 -21
- package/client/features/home/WorkspacePreview.tsx +12 -5
- package/client/features/home/api.ts +11 -3
- package/client/features/home/workspace-presentation.tsx +4 -4
- package/client/features/settings/GeneralSettings.tsx +3 -3
- package/client/features/settings/IconPicker.tsx +4 -3
- package/client/features/settings/icon-picker-options.ts +0 -131
- package/client/features/views/ViewBuilderTab.tsx +153 -0
- package/client/features/views/api.ts +124 -0
- package/client/features/views/useViewBuilderActions.ts +72 -0
- package/client/features/widgets/WidgetGrid.tsx +36 -20
- package/client/features/widgets/Widgets.tsx +140 -90
- package/client/features/workspace/WorkspaceLayoutContext.tsx +3 -9
- package/client/features/workspace/WorkspaceScreen.tsx +179 -40
- package/client/features/workspace/WorkspaceTabs.tsx +4 -4
- package/client/index.css +0 -35
- package/client/index.html +1 -1
- package/client/lib/app-icon-registry.ts +145 -0
- package/client/runtime/useWorkspaceEvents.ts +3 -1
- package/client/theme.css +1 -1
- package/dist/chunk-4vf1t6v1.js +10 -0
- package/dist/chunk-4z52b2av.css +1 -0
- package/dist/chunk-6c8cwpzc.js +1 -0
- package/dist/chunk-b4b276wx.js +15 -0
- package/dist/{chunk-c4j722at.js → chunk-cs8vbert.js} +2 -2
- package/dist/chunk-fjksw6xf.js +1 -0
- package/dist/chunk-kxmvv1ax.js +48 -0
- package/dist/{chunk-p68fnz3q.js → chunk-vkvb3hjm.js} +1 -1
- package/dist/chunk-y82s1jxm.js +61 -0
- package/dist/chunk-zpxrb1ce.js +2 -0
- package/dist/index.html +2 -2
- package/dist/openai-h13pza4b.svg +3 -0
- package/lib/format.ts +2 -2
- package/lib/types.ts +38 -2
- package/lib/view-builder-meta.ts +35 -0
- package/lib/workspace-layout.ts +14 -0
- package/package.json +2 -1
- package/server/AGENTS.md +3 -3
- package/server/api.ts +165 -51
- package/server/applets.ts +1 -1
- package/server/bundle-queue.ts +19 -0
- package/server/bundler/applet-css.ts +50 -0
- package/server/{build-applet.ts → bundler/build-applet.ts} +36 -26
- package/server/cli.ts +79 -2
- package/server/control.ts +106 -8
- package/server/env-apply.ts +2 -2
- package/server/harness/README.md +228 -0
- package/server/harness/claude-code/NOTES.md +578 -0
- package/{lib/claude-adapter.ts → server/harness/claude-code/adapter.ts} +67 -5
- package/server/harness/claude-code/index.ts +124 -0
- package/server/{mcp.ts → harness/claude-code/mcp.ts} +1 -1
- package/server/{cc-session.ts → harness/claude-code/session.ts} +42 -14
- package/server/harness/claude-code/sessions.ts +42 -0
- package/server/harness/codex/NOTES.md +326 -0
- package/server/harness/codex/adapter.ts +414 -0
- package/server/harness/codex/client.ts +343 -0
- package/server/harness/codex/index.ts +68 -0
- package/server/harness/codex/probe.ts +186 -0
- package/server/harness/codex/session.ts +617 -0
- package/server/harness/debug.ts +57 -0
- package/server/harness/openclaw/NOTES.md +316 -0
- package/server/{openclaw-adapter.ts → harness/openclaw/adapter.ts} +2 -2
- package/server/harness/openclaw/index.ts +93 -0
- package/server/{openclaw-session.ts → harness/openclaw/session.ts} +44 -9
- package/server/{openclaw-strip.ts → harness/openclaw/strip.ts} +3 -1
- package/server/harness/registry.ts +36 -0
- package/server/harness/types.ts +87 -0
- package/server/layout.ts +6 -12
- package/server/moi-scaffold.ts +1 -1
- package/server/registry.ts +14 -52
- package/server/state.ts +5 -38
- package/server/status.ts +7 -46
- package/server/vendor.ts +1 -1
- package/server/view-builders.ts +428 -0
- package/server/views.ts +0 -0
- package/server/web.ts +18 -40
- package/server/workspace-init.ts +6 -6
- package/workspace/.claude/skills/moi-workspace/DESIGN.md +1 -0
- package/workspace/.claude/skills/moi-workspace/SKILL.md +28 -7
- package/client/assets/hermes-nous.png +0 -0
- package/client/hooks/useScrollFade.ts +0 -38
- package/dist/chunk-23cgr1tz.css +0 -1
- package/dist/chunk-3hy3qy6d.js +0 -10
- package/dist/chunk-dyfaffyz.js +0 -119
- package/dist/chunk-kpe40hm8.js +0 -1
- package/dist/chunk-ty6dvda0.js +0 -1
- package/dist/hermes-nous-pznd63x9.png +0 -0
- /package/client/{components/playground → features/dev}/PixelPainter.tsx +0 -0
- /package/client/{components/playground → features/dev}/ToolCallsPage.tsx +0 -0
- /package/server/{agent.ts → harness/claude-code/models.ts} +0 -0
- /package/server/{openclaw.ts → harness/openclaw/discovery.ts} +0 -0
- /package/server/{openclaw-gateway.ts → harness/openclaw/gateway.ts} +0 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{dc as L0,ec as o,fc as r,ga as _0,hc as c,ia as v0,ic as n,kc as I0,lc as N1,mc as z0,nc as b0,oc as H1,pc as y0,qc as U0,rc as f,sc as N0,tc as G0,uc as J0,vc as D0}from"/chunk-4vf1t6v1.js";import{Ec as X0,Fc as A0}from"/chunk-vkvb3hjm.js";var D1=A0((t1,h0)=>{h0.exports=globalThis.__esm["react-dom/client"]});var w0=A0((qG,x0)=>{x0.exports=globalThis.__esm["react-dom"]});var E0=new Map;function e1(G,J){if(J)E0.set(G,J);else E0.delete(G)}function GG(G){return E0.get(G)}var V0=X0(_0(),1);var K0=new Set,t=null,H0=!1;function u0(){if(t||H0)return;H0=!0;let G=new WebSocket(v0("/api/workspaces/ws"));G.onopen=()=>{t=G,H0=!1},G.onmessage=(J)=>{try{let K=JSON.parse(J.data);for(let Q of K0)Q(K)}catch{}},G.onclose=()=>{if(t=null,H0=!1,K0.size>0)setTimeout(u0,2000)},G.onerror=()=>{G.close()}}function QG(G){let J=V0.useRef(G);J.current=G,V0.useEffect(()=>{let K=(Q)=>J.current(Q);return K0.add(K),u0(),()=>{if(K0.delete(K),K0.size===0&&t)t.close(),t=null}},[])}var m0=["top","right","bottom","left"];var{min:p,max:S,round:Z0,floor:q0}=Math,x=(G)=>({x:G,y:G}),b1={left:"right",right:"left",bottom:"top",top:"bottom"};function j0(G,J,K){return S(G,p(J,K))}function m(G,J){return typeof G==="function"?G(J):G}function d(G){return G.split("-")[0]}function i(G){return G.split("-")[1]}function Y0(G){return G==="x"?"y":"x"}function T0(G){return G==="y"?"height":"width"}function w(G){let J=G[0];return J==="t"||J==="b"?"y":"x"}function B0(G){return Y0(w(G))}function d0(G,J,K){if(K===void 0)K=!1;let Q=i(G),Z=B0(G),q=T0(Z),U=Z==="x"?Q===(K?"end":"start")?"right":"left":Q==="start"?"bottom":"top";if(J.reference[q]>J.floating[q])U=Q0(U);return[U,Q0(U)]}function c0(G){let J=Q0(G);return[W0(G),J,W0(J)]}function W0(G){return G.includes("start")?G.replace("start","end"):G.replace("end","start")}var g0=["left","right"],p0=["right","left"],y1=["top","bottom"],S1=["bottom","top"];function O1(G,J,K){switch(G){case"top":case"bottom":if(K)return J?p0:g0;return J?g0:p0;case"left":case"right":return J?y1:S1;default:return[]}}function f0(G,J,K,Q){let Z=i(G),q=O1(d(G),K==="start",Q);if(Z){if(q=q.map((U)=>U+"-"+Z),J)q=q.concat(q.map(W0))}return q}function Q0(G){let J=d(G);return b1[J]+G.slice(J.length)}function P1(G){return{top:0,right:0,bottom:0,left:0,...G}}function $0(G){return typeof G!=="number"?P1(G):{top:G,right:G,bottom:G,left:G}}function s(G){let{x:J,y:K,width:Q,height:Z}=G;return{width:Q,height:Z,top:K,left:J,right:J+Q,bottom:K+Z,x:J,y:K}}function r0(G,J,K){let{reference:Q,floating:Z}=G,q=w(J),U=B0(J),N=T0(U),V=d(J),j=q==="y",H=Q.x+Q.width/2-Z.width/2,W=Q.y+Q.height/2-Z.height/2,Y=Q[N]/2-Z[N]/2,X;switch(V){case"top":X={x:H,y:Q.y-Z.height};break;case"bottom":X={x:H,y:Q.y+Q.height};break;case"right":X={x:Q.x+Q.width,y:W};break;case"left":X={x:Q.x-Z.width,y:W};break;default:X={x:Q.x,y:Q.y}}switch(i(J)){case"start":X[U]-=Y*(K&&j?-1:1);break;case"end":X[U]+=Y*(K&&j?-1:1);break}return X}async function n0(G,J){var K;if(J===void 0)J={};let{x:Q,y:Z,platform:q,rects:U,elements:N,strategy:V}=G,{boundary:j="clippingAncestors",rootBoundary:H="viewport",elementContext:W="floating",altBoundary:Y=!1,padding:X=0}=m(J,G),T=$0(X),I=N[Y?W==="floating"?"reference":"floating":W],L=s(await q.getClippingRect({element:((K=await(q.isElement==null?void 0:q.isElement(I)))!=null?K:!0)?I:I.contextElement||await(q.getDocumentElement==null?void 0:q.getDocumentElement(N.floating)),boundary:j,rootBoundary:H,strategy:V})),M=W==="floating"?{x:Q,y:Z,width:U.floating.width,height:U.floating.height}:U.reference,F=await(q.getOffsetParent==null?void 0:q.getOffsetParent(N.floating)),z=await(q.isElement==null?void 0:q.isElement(F))?await(q.getScale==null?void 0:q.getScale(F))||{x:1,y:1}:{x:1,y:1},k=s(q.convertOffsetParentRelativeRectToViewportRelativeRect?await q.convertOffsetParentRelativeRectToViewportRelativeRect({elements:N,rect:M,offsetParent:F,strategy:V}):M);return{top:(L.top-k.top+T.top)/z.y,bottom:(k.bottom-L.bottom+T.bottom)/z.y,left:(L.left-k.left+T.left)/z.x,right:(k.right-L.right+T.right)/z.x}}var R1=50,i0=async(G,J,K)=>{let{placement:Q="bottom",strategy:Z="absolute",middleware:q=[],platform:U}=K,N=U.detectOverflow?U:{...U,detectOverflow:n0},V=await(U.isRTL==null?void 0:U.isRTL(J)),j=await U.getElementRects({reference:G,floating:J,strategy:Z}),{x:H,y:W}=r0(j,Q,V),Y=Q,X=0,T={};for(let B=0;B<q.length;B++){let I=q[B];if(!I)continue;let{name:L,fn:M}=I,{x:F,y:z,data:k,reset:E}=await M({x:H,y:W,initialPlacement:Q,placement:Y,strategy:Z,middlewareData:T,rects:j,platform:N,elements:{reference:G,floating:J}});if(H=F!=null?F:H,W=z!=null?z:W,T[L]={...T[L],...k},E&&X<R1){if(X++,typeof E==="object"){if(E.placement)Y=E.placement;if(E.rects)j=E.rects===!0?await U.getElementRects({reference:G,floating:J,strategy:Z}):E.rects;({x:H,y:W}=r0(j,Y,V))}B=-1}}return{x:H,y:W,placement:Y,strategy:Z,middlewareData:T}},s0=(G)=>({name:"arrow",options:G,async fn(J){let{x:K,y:Q,placement:Z,rects:q,platform:U,elements:N,middlewareData:V}=J,{element:j,padding:H=0}=m(G,J)||{};if(j==null)return{};let W=$0(H),Y={x:K,y:Q},X=B0(Z),T=T0(X),B=await U.getDimensions(j),I=X==="y",L=I?"top":"left",M=I?"bottom":"right",F=I?"clientHeight":"clientWidth",z=q.reference[T]+q.reference[X]-Y[X]-q.floating[T],k=Y[X]-q.reference[X],E=await(U.getOffsetParent==null?void 0:U.getOffsetParent(j)),$=E?E[F]:0;if(!$||!await(U.isElement==null?void 0:U.isElement(E)))$=N.floating[F]||q.floating[T];let O=z/2-k/2,v=$/2-B[T]/2-1,y=p(W[L],v),u=p(W[M],v),A=y,P=$-B[T]-u,D=$/2-B[T]/2+O,g=j0(A,D,P),b=!V.arrow&&i(Z)!=null&&D!==g&&q.reference[T]/2-(D<A?y:u)-B[T]/2<0,R=b?D<A?D-A:D-P:0;return{[X]:Y[X]+R,data:{[X]:g,centerOffset:D-g-R,...b&&{alignmentOffset:R}},reset:b}}});var a0=function(G){if(G===void 0)G={};return{name:"flip",options:G,async fn(J){var K,Q;let{placement:Z,middlewareData:q,rects:U,initialPlacement:N,platform:V,elements:j}=J,{mainAxis:H=!0,crossAxis:W=!0,fallbackPlacements:Y,fallbackStrategy:X="bestFit",fallbackAxisSideDirection:T="none",flipAlignment:B=!0,...I}=m(G,J);if((K=q.arrow)!=null&&K.alignmentOffset)return{};let L=d(Z),M=w(N),F=d(N)===N,z=await(V.isRTL==null?void 0:V.isRTL(j.floating)),k=Y||(F||!B?[Q0(N)]:c0(N)),E=T!=="none";if(!Y&&E)k.push(...f0(N,B,T,z));let $=[N,...k],O=await V.detectOverflow(J,I),v=[],y=((Q=q.flip)==null?void 0:Q.overflows)||[];if(H)v.push(O[L]);if(W){let D=d0(Z,U,z);v.push(O[D[0]],O[D[1]])}if(y=[...y,{placement:Z,overflows:v}],!v.every((D)=>D<=0)){var u,A;let D=(((u=q.flip)==null?void 0:u.index)||0)+1,g=$[D];if(g){if(!(W==="alignment"?M!==w(g):!1)||y.every((_)=>w(_.placement)===M?_.overflows[0]>0:!0))return{data:{index:D,overflows:y},reset:{placement:g}}}let b=(A=y.filter((R)=>R.overflows[0]<=0).sort((R,_)=>R.overflows[1]-_.overflows[1])[0])==null?void 0:A.placement;if(!b)switch(X){case"bestFit":{var P;let R=(P=y.filter((_)=>{if(E){let h=w(_.placement);return h===M||h==="y"}return!0}).map((_)=>[_.placement,_.overflows.filter((h)=>h>0).reduce((h,l)=>h+l,0)]).sort((_,h)=>_[1]-h[1])[0])==null?void 0:P[0];if(R)b=R;break}case"initialPlacement":b=N;break}if(Z!==b)return{reset:{placement:b}}}return{}}}};function l0(G,J){return{top:G.top-J.height,right:G.right-J.width,bottom:G.bottom-J.height,left:G.left-J.width}}function o0(G){return m0.some((J)=>G[J]>=0)}var t0=function(G){if(G===void 0)G={};return{name:"hide",options:G,async fn(J){let{rects:K,platform:Q}=J,{strategy:Z="referenceHidden",...q}=m(G,J);switch(Z){case"referenceHidden":{let U=await Q.detectOverflow(J,{...q,elementContext:"reference"}),N=l0(U,K.reference);return{data:{referenceHiddenOffsets:N,referenceHidden:o0(N)}}}case"escaped":{let U=await Q.detectOverflow(J,{...q,altBoundary:!0}),N=l0(U,K.floating);return{data:{escapedOffsets:N,escaped:o0(N)}}}default:return{}}}}};var e0=new Set(["left","top"]);async function A1(G,J){let{placement:K,platform:Q,elements:Z}=G,q=await(Q.isRTL==null?void 0:Q.isRTL(Z.floating)),U=d(K),N=i(K),V=w(K)==="y",j=e0.has(U)?-1:1,H=q&&V?-1:1,W=m(J,G),{mainAxis:Y,crossAxis:X,alignmentAxis:T}=typeof W==="number"?{mainAxis:W,crossAxis:0,alignmentAxis:null}:{mainAxis:W.mainAxis||0,crossAxis:W.crossAxis||0,alignmentAxis:W.alignmentAxis};if(N&&typeof T==="number")X=N==="end"?T*-1:T;return V?{x:X*H,y:Y*j}:{x:Y*j,y:X*H}}var G1=function(G){if(G===void 0)G=0;return{name:"offset",options:G,async fn(J){var K,Q;let{x:Z,y:q,placement:U,middlewareData:N}=J,V=await A1(J,G);if(U===((K=N.offset)==null?void 0:K.placement)&&(Q=N.arrow)!=null&&Q.alignmentOffset)return{};return{x:Z+V.x,y:q+V.y,data:{...V,placement:U}}}}},J1=function(G){if(G===void 0)G={};return{name:"shift",options:G,async fn(J){let{x:K,y:Q,placement:Z,platform:q}=J,{mainAxis:U=!0,crossAxis:N=!1,limiter:V={fn:(L)=>{let{x:M,y:F}=L;return{x:M,y:F}}},...j}=m(G,J),H={x:K,y:Q},W=await q.detectOverflow(J,j),Y=w(d(Z)),X=Y0(Y),T=H[X],B=H[Y];if(U){let L=X==="y"?"top":"left",M=X==="y"?"bottom":"right",F=T+W[L],z=T-W[M];T=j0(F,T,z)}if(N){let L=Y==="y"?"top":"left",M=Y==="y"?"bottom":"right",F=B+W[L],z=B-W[M];B=j0(F,B,z)}let I=V.fn({...J,[X]:T,[Y]:B});return{...I,data:{x:I.x-K,y:I.y-Q,enabled:{[X]:U,[Y]:N}}}}}},K1=function(G){if(G===void 0)G={};return{options:G,fn(J){let{x:K,y:Q,placement:Z,rects:q,middlewareData:U}=J,{offset:N=0,mainAxis:V=!0,crossAxis:j=!0}=m(G,J),H={x:K,y:Q},W=w(Z),Y=Y0(W),X=H[Y],T=H[W],B=m(N,J),I=typeof B==="number"?{mainAxis:B,crossAxis:0}:{mainAxis:0,crossAxis:0,...B};if(V){let F=Y==="y"?"height":"width",z=q.reference[Y]-q.floating[F]+I.mainAxis,k=q.reference[Y]+q.reference[F]-I.mainAxis;if(X<z)X=z;else if(X>k)X=k}if(j){var L,M;let F=Y==="y"?"width":"height",z=e0.has(d(Z)),k=q.reference[W]-q.floating[F]+(z?((L=U.offset)==null?void 0:L[W])||0:0)+(z?0:I.crossAxis),E=q.reference[W]+q.reference[F]+(z?0:((M=U.offset)==null?void 0:M[W])||0)-(z?I.crossAxis:0);if(T<k)T=k;else if(T>E)T=E}return{[Y]:X,[W]:T}}}},Q1=function(G){if(G===void 0)G={};return{name:"size",options:G,async fn(J){var K,Q;let{placement:Z,rects:q,platform:U,elements:N}=J,{apply:V=()=>{},...j}=m(G,J),H=await U.detectOverflow(J,j),W=d(Z),Y=i(Z),X=w(Z)==="y",{width:T,height:B}=q.floating,I,L;if(W==="top"||W==="bottom")I=W,L=Y===(await(U.isRTL==null?void 0:U.isRTL(N.floating))?"start":"end")?"left":"right";else L=W,I=Y==="end"?"top":"bottom";let M=B-H.top-H.bottom,F=T-H.left-H.right,z=p(B-H[I],M),k=p(T-H[L],F),E=!J.middlewareData.shift,$=z,O=k;if((K=J.middlewareData.shift)!=null&&K.enabled.x)O=F;if((Q=J.middlewareData.shift)!=null&&Q.enabled.y)$=M;if(E&&!Y){let y=S(H.left,0),u=S(H.right,0),A=S(H.top,0),P=S(H.bottom,0);if(X)O=T-2*(y!==0||u!==0?y+u:S(H.left,H.right));else $=B-2*(A!==0||P!==0?A+P:S(H.top,H.bottom))}await V({...J,availableWidth:O,availableHeight:$});let v=await U.getDimensions(N.floating);if(T!==v.width||B!==v.height)return{reset:{rects:!0}};return{}}}};function X1(G){let J=f(G),K=parseFloat(J.width)||0,Q=parseFloat(J.height)||0,Z=n(G),q=Z?G.offsetWidth:K,U=Z?G.offsetHeight:Q,N=Z0(K)!==q||Z0(Q)!==U;if(N)K=q,Q=U;return{width:K,height:Q,$:N}}function S0(G){return!c(G)?G.contextElement:G}function e(G){let J=S0(G);if(!n(J))return x(1);let K=J.getBoundingClientRect(),{width:Q,height:Z,$:q}=X1(J),U=(q?Z0(K.width):K.width)/Q,N=(q?Z0(K.height):K.height)/Z;if(!U||!Number.isFinite(U))U=1;if(!N||!Number.isFinite(N))N=1;return{x:U,y:N}}var h1=x(0);function V1(G){let J=o(G);if(!y0()||!J.visualViewport)return h1;return{x:J.visualViewport.offsetLeft,y:J.visualViewport.offsetTop}}function v1(G,J,K){if(J===void 0)J=!1;if(!K||J&&K!==o(G))return!1;return J}function a(G,J,K,Q){if(J===void 0)J=!1;if(K===void 0)K=!1;let Z=G.getBoundingClientRect(),q=S0(G),U=x(1);if(J)if(Q){if(c(Q))U=e(Q)}else U=e(G);let N=v1(q,K,Q)?V1(q):x(0),V=(Z.left+N.x)/U.x,j=(Z.top+N.y)/U.y,H=Z.width/U.x,W=Z.height/U.y;if(q){let Y=o(q),X=Q&&c(Q)?o(Q):Q,T=Y,B=D0(T);while(B&&Q&&X!==T){let I=e(B),L=B.getBoundingClientRect(),M=f(B),F=L.left+(B.clientLeft+parseFloat(M.paddingLeft))*I.x,z=L.top+(B.clientTop+parseFloat(M.paddingTop))*I.y;V*=I.x,j*=I.y,H*=I.x,W*=I.y,V+=F,j+=z,T=o(B),B=D0(T)}}return s({width:H,height:W,x:V,y:j})}function F0(G,J){let K=N0(G).scrollLeft;if(!J)return a(r(G)).left+K;return J.left+K}function W1(G,J){let K=G.getBoundingClientRect(),Q=K.left+J.scrollLeft-F0(G,K),Z=K.top+J.scrollTop;return{x:Q,y:Z}}function u1(G){let{elements:J,rect:K,offsetParent:Q,strategy:Z}=G,q=Z==="fixed",U=r(Q),N=J?z0(J.floating):!1;if(Q===U||N&&q)return K;let V={scrollLeft:0,scrollTop:0},j=x(1),H=x(0),W=n(Q);if(W||!W&&!q){if(L0(Q)!=="body"||I0(U))V=N0(Q);if(W){let X=a(Q);j=e(Q),H.x=X.x+Q.clientLeft,H.y=X.y+Q.clientTop}}let Y=U&&!W&&!q?W1(U,V):x(0);return{width:K.width*j.x,height:K.height*j.y,x:K.x*j.x-V.scrollLeft*j.x+H.x+Y.x,y:K.y*j.y-V.scrollTop*j.y+H.y+Y.y}}function x1(G){return Array.from(G.getClientRects())}function w1(G){let J=r(G),K=N0(G),Q=G.ownerDocument.body,Z=S(J.scrollWidth,J.clientWidth,Q.scrollWidth,Q.clientWidth),q=S(J.scrollHeight,J.clientHeight,Q.scrollHeight,Q.clientHeight),U=-K.scrollLeft+F0(G),N=-K.scrollTop;if(f(Q).direction==="rtl")U+=S(J.clientWidth,Q.clientWidth)-Z;return{width:Z,height:q,x:U,y:N}}var Z1=25;function g1(G,J){let K=o(G),Q=r(G),Z=K.visualViewport,q=Q.clientWidth,U=Q.clientHeight,N=0,V=0;if(Z){q=Z.width,U=Z.height;let H=y0();if(!H||H&&J==="fixed")N=Z.offsetLeft,V=Z.offsetTop}let j=F0(Q);if(j<=0){let H=Q.ownerDocument,W=H.body,Y=getComputedStyle(W),X=H.compatMode==="CSS1Compat"?parseFloat(Y.marginLeft)+parseFloat(Y.marginRight)||0:0,T=Math.abs(Q.clientWidth-W.clientWidth-X);if(T<=Z1)q-=T}else if(j<=Z1)q+=j;return{width:q,height:U,x:N,y:V}}function p1(G,J){let K=a(G,!0,J==="fixed"),Q=K.top+G.clientTop,Z=K.left+G.clientLeft,q=n(G)?e(G):x(1),U=G.clientWidth*q.x,N=G.clientHeight*q.y,V=Z*q.x,j=Q*q.y;return{width:U,height:N,x:V,y:j}}function q1(G,J,K){let Q;if(J==="viewport")Q=g1(G,K);else if(J==="document")Q=w1(r(G));else if(c(J))Q=p1(J,K);else{let Z=V1(G);Q={x:J.x-Z.x,y:J.y-Z.y,width:J.width,height:J.height}}return s(Q)}function j1(G,J){let K=G0(G);if(K===J||!c(K)||U0(K))return!1;return f(K).position==="fixed"||j1(K,J)}function m1(G,J){let K=J.get(G);if(K)return K;let Q=J0(G,[],!1).filter((N)=>c(N)&&L0(N)!=="body"),Z=null,q=f(G).position==="fixed",U=q?G0(G):G;while(c(U)&&!U0(U)){let N=f(U),V=b0(U);if(!V&&N.position==="fixed")Z=null;if(q?!V&&!Z:!V&&N.position==="static"&&!!Z&&(Z.position==="absolute"||Z.position==="fixed")||I0(U)&&!V&&j1(G,U))Q=Q.filter((H)=>H!==U);else Z=N;U=G0(U)}return J.set(G,Q),Q}function d1(G){let{element:J,boundary:K,rootBoundary:Q,strategy:Z}=G,U=[...K==="clippingAncestors"?z0(J)?[]:m1(J,this._c):[].concat(K),Q],N=q1(J,U[0],Z),V=N.top,j=N.right,H=N.bottom,W=N.left;for(let Y=1;Y<U.length;Y++){let X=q1(J,U[Y],Z);V=S(X.top,V),j=p(X.right,j),H=p(X.bottom,H),W=S(X.left,W)}return{width:j-W,height:H-V,x:W,y:V}}function c1(G){let{width:J,height:K}=X1(G);return{width:J,height:K}}function f1(G,J,K){let Q=n(J),Z=r(J),q=K==="fixed",U=a(G,!0,q,J),N={scrollLeft:0,scrollTop:0},V=x(0);function j(){V.x=F0(Z)}if(Q||!Q&&!q){if(L0(J)!=="body"||I0(Z))N=N0(J);if(Q){let X=a(J,!0,q,J);V.x=X.x+J.clientLeft,V.y=X.y+J.clientTop}else if(Z)j()}if(q&&!Q&&Z)j();let H=Z&&!Q&&!q?W1(Z,N):x(0),W=U.left+N.scrollLeft-V.x-H.x,Y=U.top+N.scrollTop-V.y-H.y;return{x:W,y:Y,width:U.width,height:U.height}}function C0(G){return f(G).position==="static"}function U1(G,J){if(!n(G)||f(G).position==="fixed")return null;if(J)return J(G);let K=G.offsetParent;if(r(G)===K)K=K.ownerDocument.body;return K}function Y1(G,J){let K=o(G);if(z0(G))return K;if(!n(G)){let Z=G0(G);while(Z&&!U0(Z)){if(c(Z)&&!C0(Z))return Z;Z=G0(Z)}return K}let Q=U1(G,J);while(Q&&N1(Q)&&C0(Q))Q=U1(Q,J);if(Q&&U0(Q)&&C0(Q)&&!b0(Q))return K;return Q||H1(G)||K}var r1=async function(G){let J=this.getOffsetParent||Y1,K=this.getDimensions,Q=await K(G.floating);return{reference:f1(G.reference,await J(G.floating),G.strategy),floating:{x:0,y:0,width:Q.width,height:Q.height}}};function l1(G){return f(G).direction==="rtl"}var T1={convertOffsetParentRelativeRectToViewportRelativeRect:u1,getDocumentElement:r,getClippingRect:d1,getOffsetParent:Y1,getElementRects:r1,getClientRects:x1,getDimensions:c1,getScale:e,isElement:c,isRTL:l1};function B1(G,J){return G.x===J.x&&G.y===J.y&&G.width===J.width&&G.height===J.height}function o1(G,J){let K=null,Q,Z=r(G);function q(){var N;clearTimeout(Q),(N=K)==null||N.disconnect(),K=null}function U(N,V){if(N===void 0)N=!1;if(V===void 0)V=1;q();let j=G.getBoundingClientRect(),{left:H,top:W,width:Y,height:X}=j;if(!N)J();if(!Y||!X)return;let T=q0(W),B=q0(Z.clientWidth-(H+Y)),I=q0(Z.clientHeight-(W+X)),L=q0(H),F={rootMargin:-T+"px "+-B+"px "+-I+"px "+-L+"px",threshold:S(0,p(1,V))||1},z=!0;function k(E){let $=E[0].intersectionRatio;if($!==V){if(!z)return U();if(!$)Q=setTimeout(()=>{U(!1,0.0000001)},1000);else U(!1,$)}if($===1&&!B1(j,G.getBoundingClientRect()))U();z=!1}try{K=new IntersectionObserver(k,{...F,root:Z.ownerDocument})}catch(E){K=new IntersectionObserver(k,F)}K.observe(G)}return U(!0),q}function n1(G,J,K,Q){if(Q===void 0)Q={};let{ancestorScroll:Z=!0,ancestorResize:q=!0,elementResize:U=typeof ResizeObserver==="function",layoutShift:N=typeof IntersectionObserver==="function",animationFrame:V=!1}=Q,j=S0(G),H=Z||q?[...j?J0(j):[],...J?J0(J):[]]:[];H.forEach((L)=>{Z&&L.addEventListener("scroll",K,{passive:!0}),q&&L.addEventListener("resize",K)});let W=j&&N?o1(j,K):null,Y=-1,X=null;if(U){if(X=new ResizeObserver((L)=>{let[M]=L;if(M&&M.target===j&&X&&J)X.unobserve(J),cancelAnimationFrame(Y),Y=requestAnimationFrame(()=>{var F;(F=X)==null||F.observe(J)});K()}),j&&!V)X.observe(j);if(J)X.observe(J)}let T,B=V?a(G):null;if(V)I();function I(){let L=a(G);if(B&&!B1(B,L))K();B=L,T=requestAnimationFrame(I)}return K(),()=>{var L;if(H.forEach((M)=>{Z&&M.removeEventListener("scroll",K),q&&M.removeEventListener("resize",K)}),W==null||W(),(L=X)==null||L.disconnect(),X=null,V)cancelAnimationFrame(T)}}var L1=G1;var I1=J1,z1=a0,F1=Q1,M1=t0,O0=s0;var k1=K1,P0=(G,J,K)=>{let Q=new Map,Z={platform:T1,...K},q={...Z.platform,_c:Q};return i0(G,J,{...Z,platform:q})};var C=X0(_0(),1),_1=X0(_0(),1),$1=X0(w0(),1),i1=typeof document<"u",s1=function(){},M0=i1?_1.useLayoutEffect:s1;function k0(G,J){if(G===J)return!0;if(typeof G!==typeof J)return!1;if(typeof G==="function"&&G.toString()===J.toString())return!0;let K,Q,Z;if(G&&J&&typeof G==="object"){if(Array.isArray(G)){if(K=G.length,K!==J.length)return!1;for(Q=K;Q--!==0;)if(!k0(G[Q],J[Q]))return!1;return!0}if(Z=Object.keys(G),K=Z.length,K!==Object.keys(J).length)return!1;for(Q=K;Q--!==0;)if(!{}.hasOwnProperty.call(J,Z[Q]))return!1;for(Q=K;Q--!==0;){let q=Z[Q];if(q==="_owner"&&G.$$typeof)continue;if(!k0(G[q],J[q]))return!1}return!0}return G!==G&&J!==J}function C1(G){if(typeof window>"u")return 1;return(G.ownerDocument.defaultView||window).devicePixelRatio||1}function E1(G,J){let K=C1(G);return Math.round(J*K)/K}function R0(G){let J=C.useRef(G);return M0(()=>{J.current=G}),J}function EG(G){if(G===void 0)G={};let{placement:J="bottom",strategy:K="absolute",middleware:Q=[],platform:Z,elements:{reference:q,floating:U}={},transform:N=!0,whileElementsMounted:V,open:j}=G,[H,W]=C.useState({x:0,y:0,strategy:K,placement:J,middlewareData:{},isPositioned:!1}),[Y,X]=C.useState(Q);if(!k0(Y,Q))X(Q);let[T,B]=C.useState(null),[I,L]=C.useState(null),M=C.useCallback((_)=>{if(_!==E.current)E.current=_,B(_)},[]),F=C.useCallback((_)=>{if(_!==$.current)$.current=_,L(_)},[]),z=q||T,k=U||I,E=C.useRef(null),$=C.useRef(null),O=C.useRef(H),v=V!=null,y=R0(V),u=R0(Z),A=R0(j),P=C.useCallback(()=>{if(!E.current||!$.current)return;let _={placement:J,strategy:K,middleware:Y};if(u.current)_.platform=u.current;P0(E.current,$.current,_).then((h)=>{let l={...h,isPositioned:A.current!==!1};if(D.current&&!k0(O.current,l))O.current=l,$1.flushSync(()=>{W(l)})})},[Y,J,K,u,A]);M0(()=>{if(j===!1&&O.current.isPositioned)O.current.isPositioned=!1,W((_)=>({..._,isPositioned:!1}))},[j]);let D=C.useRef(!1);M0(()=>{return D.current=!0,()=>{D.current=!1}},[]),M0(()=>{if(z)E.current=z;if(k)$.current=k;if(z&&k){if(y.current)return y.current(z,k,P);P()}},[z,k,P,y,v]);let g=C.useMemo(()=>({reference:E,floating:$,setReference:M,setFloating:F}),[M,F]),b=C.useMemo(()=>({reference:z,floating:k}),[z,k]),R=C.useMemo(()=>{let _={position:K,left:0,top:0};if(!b.floating)return _;let h=E1(b.floating,H.x),l=E1(b.floating,H.y);if(N)return{..._,transform:"translate("+h+"px, "+l+"px)",...C1(b.floating)>=1.5&&{willChange:"transform"}};return{position:K,left:h,top:l}},[K,N,b.floating,H.x,H.y]);return C.useMemo(()=>({...H,update:P,refs:g,elements:b,floatingStyles:R}),[H,P,g,b,R])}var a1=(G)=>{function J(K){return{}.hasOwnProperty.call(K,"current")}return{name:"arrow",options:G,fn(K){let{element:Q,padding:Z}=typeof G==="function"?G(K):G;if(Q&&J(Q)){if(Q.current!=null)return O0({element:Q.current,padding:Z}).fn(K);return{}}if(Q)return O0({element:Q,padding:Z}).fn(K);return{}}}},_G=(G,J)=>{let K=L1(G);return{name:K.name,fn:K.fn,options:[G,J]}},$G=(G,J)=>{let K=I1(G);return{name:K.name,fn:K.fn,options:[G,J]}},CG=(G,J)=>{return{fn:k1(G).fn,options:[G,J]}},DG=(G,J)=>{let K=z1(G);return{name:K.name,fn:K.fn,options:[G,J]}},bG=(G,J)=>{let K=F1(G);return{name:K.name,fn:K.fn,options:[G,J]}};var yG=(G,J)=>{let K=M1(G);return{name:K.name,fn:K.fn,options:[G,J]}};var SG=(G,J)=>{let K=a1(G);return{name:K.name,fn:K.fn,options:[G,J]}};
|
|
2
|
+
export{w0 as b,D1 as c,e1 as d,GG as e,Z0 as f,q0 as g,j0 as h,m as i,d as j,i as k,T0 as l,w as m,B0 as n,$0 as o,n1 as p,EG as q,_G as r,$G as s,CG as t,DG as u,bG as v,yG as w,SG as x,QG as y};
|
package/dist/index.html
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<title>moi</title>
|
|
7
7
|
<link rel="icon" type="image/png" href="/favicon-nbmyjfjh.png" />
|
|
8
8
|
<!-- React is vendored locally (client/vendor/react, generated by
|
|
9
|
-
scripts/build-vendor.ts) and served by the /vendor/react route, so
|
|
9
|
+
scripts/build-vendor.ts) and served by the /vendor/react route, so moi
|
|
10
10
|
runs fully offline — no CDN fetch. The server picks the development or
|
|
11
11
|
production build per environment behind these stable URLs. -->
|
|
12
12
|
<script type="importmap">
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
}
|
|
22
22
|
</script>
|
|
23
23
|
|
|
24
|
-
<link rel="stylesheet" crossorigin href="/chunk-
|
|
24
|
+
<link rel="stylesheet" crossorigin href="/chunk-4z52b2av.css"><script type="module" crossorigin src="/chunk-fjksw6xf.js"></script></head>
|
|
25
25
|
<body>
|
|
26
26
|
<div id="root"></div>
|
|
27
27
|
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path fill="#10A37F" d="M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.073zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.8956zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997z"/>
|
|
3
|
+
</svg>
|
package/lib/format.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Display-only conversation format. Agent-agnostic.
|
|
2
|
-
// Source:
|
|
2
|
+
// Source: server/harness/README.md (format section; formerly claude-code-messages.md §14) (and the research PDF under dev/report).
|
|
3
3
|
// Built at ingest time from an agent's raw stream (today: Claude Agent SDK).
|
|
4
4
|
|
|
5
5
|
export type ToolCaller = 'model' | 'server-tool' | 'mcp' | 'subagent'
|
|
@@ -36,7 +36,7 @@ export type ToolCall = {
|
|
|
36
36
|
// for the same canonical action (`read` vs `Read`, `exec` vs `Bash`).
|
|
37
37
|
// Adapters are responsible for setting it; UI defaults to a generic
|
|
38
38
|
// rendering when absent.
|
|
39
|
-
provider?: 'claude-code' | 'openclaw'
|
|
39
|
+
provider?: 'claude-code' | 'openclaw' | 'codex'
|
|
40
40
|
mcpServer?: string
|
|
41
41
|
state: ToolState
|
|
42
42
|
input: unknown
|
package/lib/types.ts
CHANGED
|
@@ -20,6 +20,8 @@ export type WidgetInfo = {
|
|
|
20
20
|
export type ViewConfig = {
|
|
21
21
|
// Nav tab label. Falls back to the file name when unset.
|
|
22
22
|
title?: string
|
|
23
|
+
// App icon registry id used by workspace tabs.
|
|
24
|
+
icon?: string
|
|
23
25
|
// Advisory env hints, same semantics as WidgetConfig.requiredEnv.
|
|
24
26
|
requiredEnv?: string[]
|
|
25
27
|
}
|
|
@@ -29,6 +31,35 @@ export type ViewInfo = {
|
|
|
29
31
|
config: ViewConfig
|
|
30
32
|
}
|
|
31
33
|
|
|
34
|
+
export type ViewBuilderStatus = 'draft' | 'building' | 'waiting' | 'ready'
|
|
35
|
+
|
|
36
|
+
// The kind of an applet — a custom UI unit embedded in a workspace. Shared by
|
|
37
|
+
// the bundler pipeline and the build-status records. On a builder record the
|
|
38
|
+
// field is absent for rows written before it existed; treat a missing kind as
|
|
39
|
+
// 'view' (only views surface in the UI — the view builder page is view-only).
|
|
40
|
+
export type AppletKind = 'view' | 'widget'
|
|
41
|
+
|
|
42
|
+
export type ViewBuilderInput = {
|
|
43
|
+
requirements: string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type ViewBuilder = {
|
|
47
|
+
id: string
|
|
48
|
+
kind?: AppletKind
|
|
49
|
+
status: ViewBuilderStatus
|
|
50
|
+
input: ViewBuilderInput
|
|
51
|
+
sessionId: string
|
|
52
|
+
viewId?: string
|
|
53
|
+
title?: string
|
|
54
|
+
icon?: string
|
|
55
|
+
error?: string
|
|
56
|
+
// Wall-clock ms when this builder last entered `building`. Used by reconcile
|
|
57
|
+
// to demote a build that has been running too long (a hung/abandoned turn).
|
|
58
|
+
buildingSince?: number
|
|
59
|
+
createdAt: number
|
|
60
|
+
updatedAt: number
|
|
61
|
+
}
|
|
62
|
+
|
|
32
63
|
// A Scratchpad draw/view operation issued by `moi scratch`. Mutations run
|
|
33
64
|
// server-side against a headless tldraw store; `view` relays to a live tab. The
|
|
34
65
|
// server assigns each add op a `name` (the `--id`, or a generated one) so the
|
|
@@ -274,7 +305,7 @@ export type WorkspaceSwitchMessage = {
|
|
|
274
305
|
workspaceId: string
|
|
275
306
|
}
|
|
276
307
|
|
|
277
|
-
export type WorkspaceType = 'claude-code' | 'openclaw' | '
|
|
308
|
+
export type WorkspaceType = 'claude-code' | 'openclaw' | 'codex'
|
|
278
309
|
|
|
279
310
|
// One MCP server's connection status, as surfaced by GET /api/workspaces/:id/mcp
|
|
280
311
|
// (a subset of the agent SDK's McpServerStatus — only what the UI renders).
|
|
@@ -352,7 +383,12 @@ export type LayoutGridItem = { i: string; x: number; y: number }
|
|
|
352
383
|
// split — Agent chat as a left column, workspace content on the right
|
|
353
384
|
export type LayoutMode = 'fullscreen' | 'split'
|
|
354
385
|
|
|
355
|
-
export type WorkspaceTabId =
|
|
386
|
+
export type WorkspaceTabId =
|
|
387
|
+
| 'agent'
|
|
388
|
+
| 'widgets'
|
|
389
|
+
| 'scratchpad'
|
|
390
|
+
| `view:${string}`
|
|
391
|
+
| `view-builder:${string}`
|
|
356
392
|
|
|
357
393
|
export type WorkspaceTabsState = {
|
|
358
394
|
open: WorkspaceTabId[]
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const VIEW_BUILDER_OPEN = '<moi>'
|
|
2
|
+
const VIEW_BUILDER_CLOSE = '</moi>'
|
|
3
|
+
const VIEW_BUILDER_MARKER = 'View builder request'
|
|
4
|
+
|
|
5
|
+
export function appendViewBuilderMeta(
|
|
6
|
+
requirements: string,
|
|
7
|
+
builderId: string,
|
|
8
|
+
availableIcons: string[]
|
|
9
|
+
): string {
|
|
10
|
+
const context = [
|
|
11
|
+
VIEW_BUILDER_OPEN,
|
|
12
|
+
VIEW_BUILDER_MARKER,
|
|
13
|
+
`Builder id: ${builderId}`,
|
|
14
|
+
`Available view icons: ${availableIcons.join(', ')}`,
|
|
15
|
+
'Your first action must be to infer a stable view id, sentence-case title, and relevant icon from the requirements, then run:',
|
|
16
|
+
`moi builder set <view-id> --builder ${builderId} --kind view --title "<title>" --icon <icon-id>`,
|
|
17
|
+
'Do this before reading files, planning, or writing code. Choose the icon id from the available view icons above.',
|
|
18
|
+
'Capitalize only the first word of the title.',
|
|
19
|
+
'Use the same icon id in the view config.',
|
|
20
|
+
'After building the view, run `moi bundle --only views`.',
|
|
21
|
+
VIEW_BUILDER_CLOSE
|
|
22
|
+
].join('\n')
|
|
23
|
+
return `${requirements.trim()}\n\n${context}`
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function stripViewBuilderMeta(text: string): string {
|
|
27
|
+
const start = text.lastIndexOf(VIEW_BUILDER_OPEN)
|
|
28
|
+
if (start === -1) return text
|
|
29
|
+
const end = text.indexOf(VIEW_BUILDER_CLOSE, start)
|
|
30
|
+
if (end === -1) return text
|
|
31
|
+
if (!text.slice(start, end).includes(VIEW_BUILDER_MARKER)) return text
|
|
32
|
+
const before = text.slice(0, start)
|
|
33
|
+
const after = text.slice(end + VIEW_BUILDER_CLOSE.length)
|
|
34
|
+
return `${before}${after}`.trim()
|
|
35
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { WorkspaceLayout, WorkspaceTabsState } from './types'
|
|
2
|
+
|
|
3
|
+
export function createDefaultWorkspaceTabs(): WorkspaceTabsState {
|
|
4
|
+
return { open: ['agent', 'widgets'], active: 'agent' }
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function createDefaultWorkspaceLayout(): WorkspaceLayout {
|
|
8
|
+
return {
|
|
9
|
+
version: 1,
|
|
10
|
+
widgetGrid: [],
|
|
11
|
+
layoutMode: 'fullscreen',
|
|
12
|
+
tabs: createDefaultWorkspaceTabs()
|
|
13
|
+
}
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "moi-computer",
|
|
3
|
-
"version": "0.3.0
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Local AI workspace powered by the Claude Agent SDK, Bun, React, and Tailwind. Requires Bun.",
|
|
5
5
|
"license": "Elastic-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -78,6 +78,7 @@
|
|
|
78
78
|
"motion": "^12.35.1",
|
|
79
79
|
"pathe": "^2.0.3",
|
|
80
80
|
"picocolors": "^1.1.1",
|
|
81
|
+
"postcss": "^8.5.19",
|
|
81
82
|
"react": "^19",
|
|
82
83
|
"react-dom": "^19",
|
|
83
84
|
"react-grid-layout": "^2.2.3",
|
package/server/AGENTS.md
CHANGED
|
@@ -3,7 +3,7 @@ Bun server on port 13337. Serves the client at `/`, upgrades `/ws` to WebSocket.
|
|
|
3
3
|
- `web.ts` owns the Bun fullstack surface only: the SPA HTML shell (dev bundler + HMR / prebuilt `dist/`), the two WebSocket channels (`/ws` chat, `/api/workspaces/ws` live events), and graceful shutdown. Every HTTP API request is delegated to the Hono app via `fetch`.
|
|
4
4
|
- `api.ts` is the Hono REST API (all `/api/*` routes). `withWorkspace` middleware resolves `:id` → workspace (404 if missing) and stashes it on the context, so handlers read `c.get('ws')`. Its catch-all serves the prebuilt client from `dist/` in prod via Hono's `serveStatic` (cached, traversal-safe).
|
|
5
5
|
- `static.ts` exposes the `dist/` location (`DIST_DIR`), the `prebuilt` flag, and the prod SPA `distShell`. `events.ts` holds `publishEvent` (server→client live-event broadcast over `/api/workspaces/ws`) decoupled from `web.ts` to avoid an import cycle; `web.ts` wires it via `setEventServer`.
|
|
6
|
-
- `state.ts` holds
|
|
7
|
-
- `
|
|
6
|
+
- `state.ts` holds the connected chat clients and `broadcast()` (which also feeds the harness debug tap).
|
|
7
|
+
- `harness/` holds every agent backend (Claude Code, OpenClaw, Codex): per-harness adapter + session + transport + protocol NOTES, colocated. Read `harness/README.md` for the message-type layers, the adapter contract, and the folder conventions before touching agent-backend code.
|
|
8
8
|
- WebSocket protocol: server sends `ServerMessage`, client sends `ClientMessage` — both defined in `lib/types.ts`.
|
|
9
|
-
-
|
|
9
|
+
- Agents run in the workspace directory with bypass permissions; each backend persists its own session history (see `harness/README.md`).
|
package/server/api.ts
CHANGED
|
@@ -4,19 +4,18 @@ import { createMiddleware } from 'hono/factory'
|
|
|
4
4
|
import { existsSync } from 'node:fs'
|
|
5
5
|
import { basename, join, resolve } from 'node:path'
|
|
6
6
|
|
|
7
|
-
import type { UploadInfo, WorkspaceEntry, WorkspaceModels
|
|
7
|
+
import type { UploadInfo, ViewBuilderInput, WorkspaceEntry, WorkspaceModels } from '@/lib/types'
|
|
8
|
+
import { appendViewBuilderMeta } from '@/lib/view-builder-meta'
|
|
8
9
|
|
|
9
|
-
import { getClaudeModels } from './agent'
|
|
10
10
|
import { apiBaseFor, parseAppletTail, serveWorkspaceFile } from './applets'
|
|
11
11
|
import { applyEnvChanged } from './env-apply'
|
|
12
|
+
import { publishEvent } from './events'
|
|
12
13
|
import { callFunction, parseFunctionPath } from './functions'
|
|
13
14
|
import { processIcon } from './icon'
|
|
14
15
|
import { getWorkspacePreview, loadLayout, mergeLayoutForSave, saveLayout } from './layout'
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import { toSessionInfo, toStreamEvents } from './openclaw-adapter'
|
|
19
|
-
import { ensureOpenClawSessionLive, getLiveOpenClawEvents } from './openclaw-session'
|
|
16
|
+
import { getUserMcpStatus } from './harness/claude-code/mcp'
|
|
17
|
+
import { getClientFrameLog, getWireLog } from './harness/debug'
|
|
18
|
+
import { allHarnesses, harnessFor, isHarnessType } from './harness/registry'
|
|
20
19
|
import {
|
|
21
20
|
discoverWorkspaces,
|
|
22
21
|
getWorkspace,
|
|
@@ -29,13 +28,21 @@ import {
|
|
|
29
28
|
import { loadScratchpadDoc, saveScratchpadDoc } from './scratchpad'
|
|
30
29
|
import { MAX_ASSET_BYTES, scratchpadAssetFile, storeScratchpadAsset } from './scratchpad-assets'
|
|
31
30
|
import { DIST_DIR, prebuilt } from './static'
|
|
32
|
-
import { getSessionEvents, getSessions } from './state'
|
|
33
31
|
import { getThreadConfig, saveThreadConfig } from './thread-config'
|
|
34
32
|
import type { ThreadConfigPatch } from './thread-config'
|
|
35
33
|
import { serveWorkspaceImagePreview } from './preview'
|
|
36
34
|
import { MAX_UPLOAD_BYTES, addUpload, getUpload } from './uploads'
|
|
37
35
|
import { requiredEnvFor } from './required-env'
|
|
38
|
-
import { listViews, serveView } from './views'
|
|
36
|
+
import { getViewList, listViews, serveView } from './views'
|
|
37
|
+
import {
|
|
38
|
+
ViewBuilderError,
|
|
39
|
+
beginViewBuilder,
|
|
40
|
+
createViewBuilder,
|
|
41
|
+
deleteViewBuilder,
|
|
42
|
+
markViewBuilderWaiting,
|
|
43
|
+
reconcileViewBuilders,
|
|
44
|
+
updateViewBuilderInput
|
|
45
|
+
} from './view-builders'
|
|
39
46
|
import { listWidgets, serveWidget } from './widgets'
|
|
40
47
|
import { getWorkspaceConfig, setWorkspaceConfig } from './workspace-config'
|
|
41
48
|
import {
|
|
@@ -121,6 +128,129 @@ one.get('/views/*', c => {
|
|
|
121
128
|
return serveView(name, file, c.get('ws').path, apiBaseFor(id), c.req.header('if-none-match'))
|
|
122
129
|
})
|
|
123
130
|
|
|
131
|
+
function viewBuilderError(err: unknown): { message: string; status: 400 | 404 | 409 } | null {
|
|
132
|
+
return err instanceof ViewBuilderError ? { message: err.message, status: err.status } : null
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function parseAvailableViewIcons(value: unknown): string[] | null {
|
|
136
|
+
if (!Array.isArray(value)) return null
|
|
137
|
+
const icons = value.filter(
|
|
138
|
+
(icon): icon is string =>
|
|
139
|
+
typeof icon === 'string' && /^[a-z0-9][a-z0-9-]*$/.test(icon) && icon.length <= 64
|
|
140
|
+
)
|
|
141
|
+
return icons.length > 0 ? [...new Set(icons)] : null
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
one.get('/view-builders', async c => {
|
|
145
|
+
const ws = c.get('ws')
|
|
146
|
+
const activeSessionIds = new Set(
|
|
147
|
+
allHarnesses()
|
|
148
|
+
.flatMap(h => h.runningSessions())
|
|
149
|
+
.filter(session => session.workspaceId === ws.id)
|
|
150
|
+
.map(session => session.sessionId)
|
|
151
|
+
)
|
|
152
|
+
const builders = await reconcileViewBuilders(
|
|
153
|
+
ws.id,
|
|
154
|
+
ws.path,
|
|
155
|
+
await getViewList(ws.path),
|
|
156
|
+
activeSessionIds
|
|
157
|
+
)
|
|
158
|
+
// Widget builders are record-only for now — reconciled server-side but kept
|
|
159
|
+
// out of the host's view-builder tab list until their UI lands.
|
|
160
|
+
return c.json({ builders: builders.filter(builder => builder.kind !== 'widget') })
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
one.post('/view-builders', async c => {
|
|
164
|
+
const ws = c.get('ws')
|
|
165
|
+
return c.json(await createViewBuilder(ws.id, ws.path), 201)
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
one.patch('/view-builders/:builderId', async c => {
|
|
169
|
+
const ws = c.get('ws')
|
|
170
|
+
const body = await c.req.json<{ input?: Partial<ViewBuilderInput> }>()
|
|
171
|
+
if (typeof body?.input?.requirements !== 'string') {
|
|
172
|
+
return c.text('Expected { input: { requirements: string } }', 400)
|
|
173
|
+
}
|
|
174
|
+
try {
|
|
175
|
+
return c.json(
|
|
176
|
+
await updateViewBuilderInput(
|
|
177
|
+
ws.id,
|
|
178
|
+
ws.path,
|
|
179
|
+
c.req.param('builderId'),
|
|
180
|
+
body.input.requirements
|
|
181
|
+
)
|
|
182
|
+
)
|
|
183
|
+
} catch (err) {
|
|
184
|
+
const known = viewBuilderError(err)
|
|
185
|
+
if (known) return c.text(known.message, known.status)
|
|
186
|
+
throw err
|
|
187
|
+
}
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
one.post('/view-builders/:builderId/submit', async c => {
|
|
191
|
+
const ws = c.get('ws')
|
|
192
|
+
const body = await c.req.json<{
|
|
193
|
+
input?: Partial<ViewBuilderInput>
|
|
194
|
+
optimisticId?: string
|
|
195
|
+
model?: string
|
|
196
|
+
effort?: string
|
|
197
|
+
stream?: boolean
|
|
198
|
+
availableIcons?: unknown
|
|
199
|
+
}>()
|
|
200
|
+
if (typeof body?.input?.requirements !== 'string') {
|
|
201
|
+
return c.text('Expected { input: { requirements: string } }', 400)
|
|
202
|
+
}
|
|
203
|
+
if (body.optimisticId !== undefined && typeof body.optimisticId !== 'string') {
|
|
204
|
+
return c.text('Invalid optimisticId', 400)
|
|
205
|
+
}
|
|
206
|
+
const availableIcons = parseAvailableViewIcons(body.availableIcons)
|
|
207
|
+
if (!availableIcons) return c.text('Available view icons are required', 400)
|
|
208
|
+
try {
|
|
209
|
+
const builder = await beginViewBuilder(
|
|
210
|
+
ws.id,
|
|
211
|
+
ws.path,
|
|
212
|
+
c.req.param('builderId'),
|
|
213
|
+
body.input.requirements
|
|
214
|
+
)
|
|
215
|
+
const content = appendViewBuilderMeta(builder.input.requirements, builder.id, availableIcons)
|
|
216
|
+
try {
|
|
217
|
+
await harnessFor(ws).sendMessage({
|
|
218
|
+
workspaceId: ws.id,
|
|
219
|
+
workspacePath: ws.path,
|
|
220
|
+
sessionId: builder.sessionId,
|
|
221
|
+
isNew: true,
|
|
222
|
+
content,
|
|
223
|
+
optimisticId: body.optimisticId,
|
|
224
|
+
model: typeof body.model === 'string' ? body.model : undefined,
|
|
225
|
+
effort: typeof body.effort === 'string' ? body.effort : undefined,
|
|
226
|
+
stream: body.stream === true ? true : undefined,
|
|
227
|
+
agentId: ws.agentId
|
|
228
|
+
})
|
|
229
|
+
} catch (err) {
|
|
230
|
+
const message = err instanceof Error ? err.message : 'Could not start view builder'
|
|
231
|
+
await markViewBuilderWaiting(ws.id, ws.path, builder.id, message)
|
|
232
|
+
return c.text(message, 500)
|
|
233
|
+
}
|
|
234
|
+
return c.json(builder)
|
|
235
|
+
} catch (err) {
|
|
236
|
+
const known = viewBuilderError(err)
|
|
237
|
+
if (known) return c.text(known.message, known.status)
|
|
238
|
+
throw err
|
|
239
|
+
}
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
one.delete('/view-builders/:builderId', async c => {
|
|
243
|
+
const ws = c.get('ws')
|
|
244
|
+
try {
|
|
245
|
+
await deleteViewBuilder(ws.id, ws.path, c.req.param('builderId'))
|
|
246
|
+
return c.body(null, 204)
|
|
247
|
+
} catch (err) {
|
|
248
|
+
const known = viewBuilderError(err)
|
|
249
|
+
if (known) return c.text(known.message, known.status)
|
|
250
|
+
throw err
|
|
251
|
+
}
|
|
252
|
+
})
|
|
253
|
+
|
|
124
254
|
// Workspace file stream — an applet's `fileUrl(path)` resolves here. Streams a
|
|
125
255
|
// media file from the workspace root (range-enabled). Guarded: traversal and
|
|
126
256
|
// dotfiles (`.env`, `.moi`, `.git`) are rejected and only media/asset extensions
|
|
@@ -215,41 +345,12 @@ one.get('/uploads/:uploadId', c => {
|
|
|
215
345
|
|
|
216
346
|
one.get('/sessions', async c => {
|
|
217
347
|
const ws = c.get('ws')
|
|
218
|
-
|
|
219
|
-
const rows = await getOpenClawSessions(ws.path, ws.agentId)
|
|
220
|
-
return c.json(rows.map(r => toSessionInfo(r, ws.path)))
|
|
221
|
-
}
|
|
222
|
-
return c.json(await getSessions(ws.path))
|
|
348
|
+
return c.json(await harnessFor(ws).listSessions(ws))
|
|
223
349
|
})
|
|
224
350
|
|
|
225
351
|
one.get('/sessions/:sessionId/events', async c => {
|
|
226
352
|
const ws = c.get('ws')
|
|
227
|
-
|
|
228
|
-
const sessionId = c.req.param('sessionId')
|
|
229
|
-
if (ws.type === 'openclaw') {
|
|
230
|
-
// Prefer the live view if we already hold one — keeps REST + WS in
|
|
231
|
-
// agreement for any reload that lands while a run is active. The first cold
|
|
232
|
-
// call also primes the live subscription so subsequent WS frames upsert into
|
|
233
|
-
// the same view.
|
|
234
|
-
const live = getLiveOpenClawEvents(id, sessionId)
|
|
235
|
-
if (live) return c.json(live)
|
|
236
|
-
if (ws.agentId) {
|
|
237
|
-
try {
|
|
238
|
-
const evs = await ensureOpenClawSessionLive({
|
|
239
|
-
workspaceId: id,
|
|
240
|
-
workspacePath: ws.path,
|
|
241
|
-
agentId: ws.agentId,
|
|
242
|
-
sessionId
|
|
243
|
-
})
|
|
244
|
-
return c.json(evs)
|
|
245
|
-
} catch {
|
|
246
|
-
// fall through to static path
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
const preview = await getOpenClawSessionMessages(sessionId, ws.path, ws.agentId)
|
|
250
|
-
return c.json(toStreamEvents(preview))
|
|
251
|
-
}
|
|
252
|
-
return c.json(await getSessionEvents(sessionId, ws.path))
|
|
353
|
+
return c.json(await harnessFor(ws).sessionEvents(ws, c.req.param('sessionId')))
|
|
253
354
|
})
|
|
254
355
|
|
|
255
356
|
// Per-thread agent settings (model + reasoning effort). GET returns the stored
|
|
@@ -279,7 +380,25 @@ one.put('/sessions/:sessionId/config', async c => {
|
|
|
279
380
|
})
|
|
280
381
|
|
|
281
382
|
one.get('/mcp', async c => {
|
|
282
|
-
|
|
383
|
+
const ws = c.get('ws')
|
|
384
|
+
return c.json((await harnessFor(ws).mcpStatus?.(ws)) ?? [])
|
|
385
|
+
})
|
|
386
|
+
|
|
387
|
+
// Harness debug tap for /playground/harness: the backend's native wire frames
|
|
388
|
+
// (Codex: app-server JSON-RPC, both directions; Claude Code: raw SDK messages
|
|
389
|
+
// + enqueued inputs) and the exact frames the server pushed to chat clients.
|
|
390
|
+
// `sinceWire`/`sinceBroadcast` are seq cursors so the page can poll deltas.
|
|
391
|
+
one.get('/harness/debug', async c => {
|
|
392
|
+
const ws = c.get('ws')
|
|
393
|
+
const harness = harnessFor(ws)
|
|
394
|
+
const sinceWire = Number(c.req.query('sinceWire') ?? 0) || 0
|
|
395
|
+
const sinceBroadcast = Number(c.req.query('sinceBroadcast') ?? 0) || 0
|
|
396
|
+
return c.json({
|
|
397
|
+
provider: harness.id,
|
|
398
|
+
process: (await harness.debugInfo?.(ws)) ?? null,
|
|
399
|
+
wire: getWireLog(harness.wireScope?.(ws) ?? ws.id, sinceWire),
|
|
400
|
+
broadcasts: getClientFrameLog(ws.id, sinceBroadcast)
|
|
401
|
+
})
|
|
283
402
|
})
|
|
284
403
|
|
|
285
404
|
// Per-workspace env vars. GET returns the effective view (discovered `.env` + UI
|
|
@@ -345,16 +464,11 @@ one.put('/env', async c => {
|
|
|
345
464
|
// account-wide Agent SDK model list.
|
|
346
465
|
one.get('/models', async c => {
|
|
347
466
|
const ws = c.get('ws')
|
|
348
|
-
const
|
|
349
|
-
const models =
|
|
350
|
-
provider === 'openclaw' ? await getOpenClawModels() : await getClaudeModels(ws.path)
|
|
351
|
-
// Claude Code streams live tokens via `includePartialMessages`; OpenClaw
|
|
352
|
-
// uses durable rows only (no token deltas), so it opts out.
|
|
353
|
-
const supportsStreaming = provider !== 'openclaw'
|
|
467
|
+
const harness = harnessFor(ws)
|
|
354
468
|
return c.json({
|
|
355
|
-
provider,
|
|
356
|
-
models,
|
|
357
|
-
supportsStreaming
|
|
469
|
+
provider: harness.id,
|
|
470
|
+
models: await harness.listModels(ws),
|
|
471
|
+
supportsStreaming: harness.capabilities.supportsStreaming
|
|
358
472
|
} satisfies WorkspaceModels)
|
|
359
473
|
})
|
|
360
474
|
|
|
@@ -538,7 +652,7 @@ workspaces.post('/', async c => {
|
|
|
538
652
|
const body = await c.req.json()
|
|
539
653
|
if (!body?.path) return c.text('Missing path', 400)
|
|
540
654
|
const rawType = body?.type
|
|
541
|
-
const type = rawType
|
|
655
|
+
const type = isHarnessType(rawType) ? rawType : undefined
|
|
542
656
|
const path = resolve(String(body.path))
|
|
543
657
|
// Importing IS initializing: lay down the bundled skills (in the backend's
|
|
544
658
|
// skills dir) and the `.moi/` scaffold, exactly like `moi init` — a workspace
|
package/server/applets.ts
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const bundleChains = new Map<string, Promise<unknown>>()
|
|
2
|
+
|
|
3
|
+
export function serializeWorkspaceBundle<T>(
|
|
4
|
+
workspacePath: string,
|
|
5
|
+
run: () => Promise<T>
|
|
6
|
+
): Promise<T> {
|
|
7
|
+
const previous = bundleChains.get(workspacePath) ?? Promise.resolve()
|
|
8
|
+
const current = previous.then(run, run)
|
|
9
|
+
bundleChains.set(workspacePath, current)
|
|
10
|
+
void current.then(
|
|
11
|
+
() => {
|
|
12
|
+
if (bundleChains.get(workspacePath) === current) bundleChains.delete(workspacePath)
|
|
13
|
+
},
|
|
14
|
+
() => {
|
|
15
|
+
if (bundleChains.get(workspacePath) === current) bundleChains.delete(workspacePath)
|
|
16
|
+
}
|
|
17
|
+
)
|
|
18
|
+
return current
|
|
19
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Scopes a compiled applet stylesheet to its mount container.
|
|
2
|
+
//
|
|
3
|
+
// Applet bundles compile with the full `@import 'tailwindcss'` — preflight,
|
|
4
|
+
// theme variables, utilities — and the result is injected into the host
|
|
5
|
+
// document at runtime. Unscoped, those rules are page-global: the widget's
|
|
6
|
+
// preflight resets host elements, its theme layer redefines variables on
|
|
7
|
+
// `:root`, and its utilities (arriving later in the document than the host
|
|
8
|
+
// stylesheet) win cascade ties against the host's — most visibly for
|
|
9
|
+
// media-query variants. Scoping pins every rule to the applet's own subtree.
|
|
10
|
+
//
|
|
11
|
+
// The transform prefixes each selector with `[data-applet="<scope>"]` — the
|
|
12
|
+
// attribute the client puts on the applet's mount container (see
|
|
13
|
+
// client/features/applets/AppletMount.tsx). Selectors that address the page
|
|
14
|
+
// root (`:root`, `:host`, `html`, `body`) are mapped onto the container
|
|
15
|
+
// itself, so theme variables and preflight inheritance (line-height, font)
|
|
16
|
+
// land there and inherit down. Rules inside `@keyframes` are left alone —
|
|
17
|
+
// keyframe step selectors (`0%`, `to`) aren't element selectors.
|
|
18
|
+
//
|
|
19
|
+
// The uniform `+1 attribute` specificity bump preserves the stylesheet's
|
|
20
|
+
// internal cascade and makes applet rules beat same-layer host rules inside
|
|
21
|
+
// the container — which is exactly the priority we want.
|
|
22
|
+
//
|
|
23
|
+
// Known limitation: content the applet portals outside its container
|
|
24
|
+
// (e.g. to document.body) escapes the scope and won't receive applet styles.
|
|
25
|
+
import postcss, { type Container, type Document } from 'postcss'
|
|
26
|
+
|
|
27
|
+
// A selector's leading page-root token, if any. `(?![\w-])` keeps `body` from
|
|
28
|
+
// matching an unrelated tag/class prefix like `bodycopy`.
|
|
29
|
+
const PAGE_ROOT_RE = /^(:root|:host|html|body)(?![\w-])/
|
|
30
|
+
|
|
31
|
+
function insideKeyframes(parent: Container | Document | undefined): boolean {
|
|
32
|
+
return parent?.type === 'atrule' && /keyframes$/i.test((parent as { name: string }).name)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function scopeAppletCss(css: string, scope: string): string {
|
|
36
|
+
const container = `[data-applet=${JSON.stringify(scope)}]`
|
|
37
|
+
const root = postcss.parse(css)
|
|
38
|
+
|
|
39
|
+
root.walkRules(rule => {
|
|
40
|
+
if (insideKeyframes(rule.parent)) return
|
|
41
|
+
rule.selectors = rule.selectors.map(selector => {
|
|
42
|
+
const s = selector.trim()
|
|
43
|
+
const rootToken = PAGE_ROOT_RE.exec(s)
|
|
44
|
+
if (rootToken) return container + s.slice(rootToken[0].length)
|
|
45
|
+
return `${container} ${s}`
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
return root.toString()
|
|
50
|
+
}
|