meshy-node 0.10.5 → 0.10.7
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/dashboard/assets/DashboardPage-B8aG_22p.js +176 -0
- package/dashboard/assets/{DashboardShared-vm6Ua9h6.js → DashboardShared-BUUqTMMG.js} +9 -9
- package/dashboard/assets/{DiffTab-Bz1OAlIg.js → DiffTab-BJ-QDAVa.js} +2 -2
- package/dashboard/assets/FilesTab-CXyf-FqN.js +11 -0
- package/dashboard/assets/{MarkdownPreviewFrame-CrujIEck.js → MarkdownPreviewFrame-CFCsFLMN.js} +1 -1
- package/dashboard/assets/PreviewTab-hYU-Sg4s.js +21 -0
- package/dashboard/assets/{SharedConversationPage-D86sReze.js → SharedConversationPage-Bb7cY7t7.js} +2 -2
- package/dashboard/assets/{file-CBXlsD1A.js → file-Ct6iLy28.js} +1 -1
- package/dashboard/assets/index-0SJFGvhq.js +346 -0
- package/dashboard/assets/index-Br15-PXW.css +1 -0
- package/dashboard/index.html +2 -2
- package/main.cjs +1015 -1222
- package/package.json +1 -1
- package/runtime-metadata.json +4 -4
- package/dashboard/assets/DashboardPage-CuNReQ9k.js +0 -166
- package/dashboard/assets/FilesTab-BlJn83X5.js +0 -11
- package/dashboard/assets/PreviewTab-C7vB52yS.js +0 -21
- package/dashboard/assets/index-B21dpk5D.js +0 -346
- package/dashboard/assets/index-Bd5ODKX4.css +0 -1
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import{c as he,r as i,bS as ye,bT as je,bU as ke,j as t,l as oe,B as L,x as ie,X as Ne,n as Se,d as x,t as Ce}from"./index-B21dpk5D.js";import{M as Fe,L as Ee}from"./MarkdownPreviewFrame-CrujIEck.js";import{G as B,H as Pe,J as De,K as Te,N as _e,O as Oe,P as Re}from"./DashboardShared-vm6Ua9h6.js";import{F as ze}from"./file-CBXlsD1A.js";/**
|
|
2
|
-
* @license lucide-react v1.7.0 - ISC
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the ISC license.
|
|
5
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const $e=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],le=he("arrow-left",$e);/**
|
|
7
|
-
* @license lucide-react v1.7.0 - ISC
|
|
8
|
-
*
|
|
9
|
-
* This source code is licensed under the ISC license.
|
|
10
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const Ae=[["path",{d:"M12 15V3",key:"m9g1x1"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["path",{d:"m7 10 5 5 5-5",key:"brsn70"}]],Be=he("download",Ae),Le="save_dashboard_download";function fe(e=me()){const n=e?.__TAURI__?.core?.invoke;return typeof n=="function"?n:null}function Me(e){const d=(e.trim().replace(/\\/g,"/").split("/").filter(Boolean).pop()??"").replace(/[<>:"/\\|?*\x00-\x1f]/g,"_").replace(/^[ .]+|[ .]+$/g,"");return d.length>0?d:"download"}async function Ue({href:e,filePath:n,currentWindow:l=me(),fetchImpl:d=fetch}){const o=fe(l);if(!o)return!1;const u=await d(e,{cache:"no-store"});if(!u.ok)throw new Error(`Failed to download file (${u.status})`);const N=await u.blob(),E=await He(N),p=await o(Le,{fileName:Me(n),contentBase64:E});return!Ke(p)||p.saved!==!1}async function He(e){const n=new Uint8Array(await e.arrayBuffer()),l=[],d=32768;for(let o=0;o<n.length;o+=d){const u=n.subarray(o,o+d);l.push(String.fromCharCode(...u))}return btoa(l.join(""))}function me(){return typeof window>"u"?null:window}function Ke(e){return!!(e&&typeof e=="object"&&"saved"in e)}const Je={getOutput:ke,getOutputTree:je,getOutputContent:ye},de=120,Qe=1200;function et({taskId:e,api:n=Je,requestedFilePath:l=null,requestedFileRequestId:d=0}){const[o,u]=i.useState(null),[N,E]=i.useState([]),[p,Y]=i.useState({}),[S,P]=i.useState(new Set),[M,U]=i.useState(new Set),[b,D]=i.useState("."),[h,C]=i.useState(null),[pe,v]=i.useState(!1),[j,w]=i.useState(""),[Z,T]=i.useState([]),[q,_]=i.useState(!1),[ee,O]=i.useState(null),[H,R]=i.useState(!0),[te,f]=i.useState(null),re=i.useRef(null),K=i.useRef(null),m=o?.summary?.rootPath??o?.effectiveProjectPath??null,J=j.trim(),y=J.length>0,g=pe||j.length>0,ae=i.useCallback(async()=>{f(null),R(!0),D("."),E([]),Y({}),P(new Set),U(new Set),C(null),v(!1),w(""),T([]),O(null),K.current=null;try{const a=await n.getOutput(e);if(u(a),!a.available){R(!1);return}const r=await n.getOutputTree(e,".");E(r.entries),R(!1)}catch(a){f(a instanceof Error?a.message:"Failed to load output"),R(!1)}},[n,e]);i.useEffect(()=>{ae()},[ae]);const z=i.useCallback(async a=>{const r=B(a,m);if(!r)return f("Invalid directory path"),[];if(p[r])return p[r];f(null),U(s=>new Set(s).add(r));try{const s=await n.getOutputTree(e,r);return Y(c=>({...c,[r]:s.entries})),s.entries}catch(s){return f(s instanceof Error?s.message:"Failed to load directory"),[]}finally{U(s=>{const c=new Set(s);return c.delete(r),c})}},[n,p,m,e]),$=i.useCallback(async a=>{const r=a.filter(s=>s!==".");if(r.length!==0){P(s=>{const c=new Set(s);for(const F of r)c.add(F);return c});for(const s of r)await z(s)}},[z]),Q=i.useCallback(async a=>{const r=B(a,m);if(!r){f("Invalid directory path");return}v(!1),w(""),D(r),C(null),r!=="."&&await $(We(r))},[$,m]),ge=i.useCallback(async a=>{const r=B(a,m);if(!r){f("Invalid directory path");return}if(D(r),C(null),S.has(r)){P(s=>{const c=new Set(s);return c.delete(r),c});return}P(s=>new Set(s).add(r)),await z(r)},[S,z,m]),A=i.useCallback(async a=>{const r=B(a,m);if(!r){f("Invalid file path");return}f(null);try{const s=Pe(r);v(!1),w(""),await $(De(r));const c=await n.getOutputContent(e,r);D(s),C(c)}catch(s){f(s instanceof Error?s.message:"Failed to load file")}},[n,$,m,e]),be=i.useCallback(()=>{if(b===".")return;const a=b.split("/");a.pop();const r=a.length===0?".":a.join("/");Q(r)},[b,Q]);i.useEffect(()=>{if(!l||!o?.available||H)return;const a=`${d}:${l}`;K.current!==a&&(K.current=a,w(""),A(l))},[H,A,o?.available,l,d]),i.useEffect(()=>{g&&re.current?.focus()},[g]),i.useEffect(()=>{if(!y||!o?.available){_(!1),T([]),O(null);return}let a=!1;async function r(){_(!0),O(null);const s=["."],c=new Set,F=[];let ne=0;try{for(;s.length>0&&ne<Qe&&F.length<de;){const k=s.shift()??".";if(c.has(k))continue;c.add(k);const V=await n.getOutputTree(e,k);if(a)return;ne+=V.entries.length,F.push(...Oe(V.entries,J));for(const W of V.entries)W.type==="directory"&&!c.has(W.path)&&s.push(W.path)}a||(T(F.slice(0,de)),_(!1))}catch(k){a||(T([]),O(k instanceof Error?k.message:"Failed to search files"),_(!1))}}return r(),()=>{a=!0}},[n,J,o?.available,y,e]);const ve=i.useMemo(()=>Te(N,p,S,M),[p,N,S,M]),X=y?Z.map(a=>({entry:a,depth:_e(a.path),expanded:a.type==="directory"&&S.has(a.path),loading:a.type==="directory"&&M.has(a.path)})):ve;if(H)return t.jsx(G,{tone:"muted",children:"Loading files..."});if(te)return t.jsx(G,{tone:"destructive",children:te});if(!o?.available)return t.jsx(G,{tone:"muted",children:"Task output is not available yet. The task may not have started."});const se=(o.summary?.htmlEntries.length??0)+(o.summary?.markdownEntries?.length??0),we=y?`${Z.length}${q?"+":""} matches`:`${o.summary?.fileCount??N.length} files`;return t.jsxs("div",{className:"grid h-full min-h-0 grid-cols-1 lg:grid-cols-[16rem_minmax(0,1fr)] lg:pl-5",children:[t.jsxs("aside",{className:x("flex min-h-0 flex-col bg-card/25 lg:border-r lg:border-border/50",h&&"hidden lg:flex"),children:[t.jsxs("div",{className:"shrink-0 bg-card/20 px-2 py-1.5",children:[t.jsxs("div",{className:"flex items-start gap-1.5",children:[t.jsx("div",{className:"mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-sm bg-primary/10 text-primary",children:t.jsx(oe,{className:"h-3.5 w-3.5"})}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"truncate text-[12px] font-semibold leading-4 text-foreground",children:o.summary?.rootName??"Artifacts"}),t.jsxs("div",{className:"text-[10px] leading-4 text-muted-foreground",children:[we,se>0&&` · ${se} previews`]})]}),t.jsx(L,{type:"button",variant:g?"secondary":"ghost",size:"icon","aria-expanded":g,"aria-label":g&&j.length===0?"Hide file search":"Search files",title:g&&j.length===0?"Hide file search":"Search files",className:"h-6 w-6 shrink-0 rounded-sm",onClick:()=>{g&&j.length===0?v(!1):v(!0)},children:t.jsx(ie,{className:"h-3.5 w-3.5"})})]}),t.jsxs("div",{className:"mt-1 flex min-h-5 items-center gap-1 rounded-sm bg-muted/35 px-1.5 py-0",children:[b!=="."&&t.jsx(L,{variant:"ghost",size:"icon",className:"h-5 w-5 rounded-sm",onClick:be,children:t.jsx(le,{className:"h-3 w-3"})}),t.jsx("span",{className:"truncate font-mono text-[10px] leading-4 text-muted-foreground",children:b==="."?o.summary?.rootPath??o.summary?.rootName??"/":b})]}),g&&t.jsxs("div",{className:"mt-1 flex items-center gap-1 rounded-sm bg-muted/35 px-1.5 py-0",children:[t.jsx(ie,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),t.jsx("input",{ref:re,value:j,onChange:a=>w(a.target.value),onKeyDown:a=>{a.key==="Escape"&&(w(""),v(!1))},placeholder:"Search files and folders",className:"h-5 min-w-0 flex-1 bg-transparent text-[10px] leading-4 text-foreground outline-none placeholder:text-muted-foreground/70"}),t.jsx("button",{type:"button",onClick:()=>{w(""),v(!1)},className:"flex h-4 w-4 shrink-0 items-center justify-center rounded-sm text-muted-foreground hover:bg-muted/70 hover:text-foreground","aria-label":"Close file search",children:t.jsx(Ne,{className:"h-3 w-3"})})]})]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-1",children:q&&X.length===0?t.jsx("div",{className:"flex h-full items-center justify-center rounded-sm border border-dashed border-border/70 bg-background/35 px-3 text-center text-[11px] text-muted-foreground",children:"Searching files..."}):ee?t.jsx("div",{className:"flex h-full items-center justify-center rounded-sm border border-dashed border-destructive/35 bg-destructive/10 px-3 text-center text-[11px] text-destructive",children:ee}):X.length>0?t.jsx("div",{className:"space-y-0",children:X.map(a=>{const r=a.entry,s=h?.path===r.path||!h&&r.type==="directory"&&b===r.path;return t.jsxs("button",{type:"button","aria-current":s?"page":void 0,style:{"--tree-depth":a.depth,paddingLeft:`${4+a.depth*11}px`},onClick:()=>{r.type==="directory"?y?Q(r.path):ge(r.path):A(r.path)},className:x("animate-task-row-reveal group relative flex min-h-5 w-full items-center gap-1 rounded-sm py-0 text-left transition-all duration-150",s?'bg-primary/10 text-foreground before:absolute before:left-0 before:top-1/2 before:h-1/2 before:w-[2px] before:-translate-y-1/2 before:rounded-full before:bg-primary before:content-[""]':"text-foreground hover:bg-muted/40"),children:[r.type==="directory"?t.jsx(Se,{className:x("h-3 w-3 shrink-0 text-muted-foreground transition-transform",s&&"text-primary",a.expanded&&"rotate-90")}):t.jsx("span",{className:"h-3 w-3 shrink-0"}),r.type==="directory"?t.jsx(oe,{className:x("h-3 w-3 shrink-0 text-muted-foreground group-hover:text-foreground",s&&"text-primary")}):t.jsx(ze,{className:x("h-3 w-3 shrink-0 text-muted-foreground group-hover:text-foreground",s&&"text-primary")}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-[10px] font-medium leading-4",children:y?r.path:r.name}),t.jsx("span",{className:x("max-w-[5.75rem] shrink-0 truncate text-right text-[9px] leading-4",s?"text-primary/75":"text-muted-foreground"),children:a.loading?"loading":Ve(r)})]},r.path)})}):t.jsx("div",{className:"flex h-full items-center justify-center rounded-sm border border-dashed border-border/70 bg-background/35 px-3 text-center text-[11px] text-muted-foreground",children:y?"No matching files or folders":"Empty directory"})})]}),t.jsx("section",{className:x("min-h-0 flex flex-col bg-card/15",!h&&"hidden lg:flex"),children:h?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"shrink-0 px-3 py-1.5",children:t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[t.jsx(L,{variant:"ghost",size:"icon","aria-label":"Back to file list",title:"Back to file list",className:"h-6 w-6 shrink-0 rounded-sm text-muted-foreground hover:bg-muted/55 hover:text-foreground",onClick:()=>C(null),children:t.jsx(le,{className:"h-3 w-3"})}),t.jsx("div",{className:"min-w-0 truncate font-mono text-[10px] leading-5 text-muted-foreground",children:h.path})]}),h.downloadUrl&&t.jsx(I,{href:h.downloadUrl,filePath:h.path,iconOnly:!0})]})}),t.jsx("div",{className:"min-h-0 flex-1 overflow-auto px-2.5 pb-2.5 pt-1",children:t.jsx(Xe,{content:h,rootPath:m,onOpenFile:A})})]}):t.jsx("div",{className:"flex h-full items-center justify-center p-4",children:t.jsxs("div",{className:"max-w-md rounded-lg border border-border/60 bg-background/55 px-4 py-4 text-center",children:[t.jsx("div",{className:"text-[12px] font-medium text-foreground",children:"Select a file to inspect"}),t.jsx("p",{className:"mt-1 text-[11px] leading-5 text-muted-foreground",children:"Preview source files, generated assets, or exported documents from this task."})]})})})]})}function Xe({content:e,rootPath:n,onOpenFile:l}){const d=e.downloadUrl;if(e.truncated&&!e.content)return t.jsx(xe,{title:"File is too large to preview inline",description:e.path,action:d?t.jsx(I,{href:d,filePath:e.path}):void 0});if(e.kind==="image"){const o=e.content?`data:${e.mimeType};base64,${e.content}`:d;return o?t.jsx("div",{className:"flex h-full min-h-[16rem] items-center justify-center rounded-sm bg-background/55 p-3",children:t.jsx("img",{src:o,alt:e.path,className:"max-h-full max-w-full rounded-sm object-contain shadow-[0_24px_90px_-52px_rgba(0,0,0,0.65)]"})}):t.jsx(ue,{content:e})}if(e.kind==="pdf"&&d)return t.jsx("div",{className:"h-full min-h-[20rem] overflow-hidden rounded-sm bg-background/55",children:t.jsx("iframe",{src:d,title:e.path,className:"h-full w-full border-0"})});if(e.kind==="json"){let o=e.content;try{o=JSON.stringify(JSON.parse(e.content),null,2)}catch{}return t.jsx(ce,{content:o,truncated:e.truncated})}return e.kind==="markdown"?t.jsx(Fe,{content:e.content,truncated:e.truncated,resolveFileLink:o=>Re(o,n,{allowRootRelative:!0,baseFilePath:e.path}),onOpenFileLink:l}):e.kind==="text"||e.kind==="html"?t.jsx(ce,{content:e.content,truncated:e.truncated}):t.jsx(ue,{content:e})}function ce({content:e,truncated:n}){return t.jsxs("div",{className:"rounded-sm bg-background/55",children:[t.jsx(Ee,{content:e}),n&&t.jsx("div",{className:"bg-muted/30 px-3 py-1.5 text-[10px] text-muted-foreground",children:"Content truncated. Download the file to inspect the full artifact."})]})}function ue({content:e}){return t.jsx(xe,{title:`${e.kind} file`,description:e.path,action:e.downloadUrl?t.jsx(I,{href:e.downloadUrl,filePath:e.path}):void 0})}function I({href:e,filePath:n,iconOnly:l=!1}){const d=i.useCallback(o=>{fe()&&(o.preventDefault(),Ue({href:e,filePath:n}).catch(u=>{Ce.error(u instanceof Error?u.message:"Failed to save file")}))},[n,e]);return t.jsx(L,{asChild:!0,variant:"ghost",size:l?"icon":"sm",className:x("rounded-sm text-primary shadow-none hover:bg-primary/10 hover:text-primary",l?"h-6 w-6 shrink-0 bg-transparent":"h-7 bg-primary/10 px-2.5 text-[11px] hover:bg-primary/15"),children:t.jsxs("a",{href:e,download:!0,"aria-label":l?"Download file":void 0,title:l?"Download file":void 0,onClick:d,children:[t.jsx(Be,{className:"h-3.5 w-3.5"}),!l&&"Download"]})})}function xe({title:e,description:n,action:l}){return t.jsx("div",{className:"flex h-full min-h-[14rem] items-center justify-center rounded-sm bg-background/35 p-4 text-center",children:t.jsxs("div",{className:"max-w-sm",children:[t.jsx("div",{className:"text-[12px] font-medium text-foreground",children:e}),t.jsx("div",{className:"mt-1 break-all font-mono text-[10px] text-muted-foreground",children:n}),l&&t.jsx("div",{className:"mt-2.5 flex justify-center",children:l})]})})}function G({children:e,tone:n}){return t.jsx("div",{className:x("flex h-48 items-center justify-center text-[12px]",n==="muted"?"text-muted-foreground":"text-destructive"),children:e})}function Ve(e){return e.type==="directory"?"dir":e.size===void 0?e.kind??"file":`${e.kind??"file"} · ${Ge(e.size)}`}function We(e){if(e===".")return[];const n=e.split("/").filter(Boolean);return n.map((l,d)=>n.slice(0,d+1).join("/"))}function Ge(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}export{et as FilesTab};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import{c as O,j as e,I as re,B as p,aE as D,ay as K,r as i,bV as te,bU as ne,aD as T,G as ae,H as ie,J as le,bW as oe,y as ce,C as de}from"./index-B21dpk5D.js";/**
|
|
2
|
-
* @license lucide-react v1.7.0 - ISC
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the ISC license.
|
|
5
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const ue=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]],xe=O("maximize-2",ue);/**
|
|
7
|
-
* @license lucide-react v1.7.0 - ISC
|
|
8
|
-
*
|
|
9
|
-
* This source code is licensed under the ISC license.
|
|
10
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const me=[["path",{d:"m14 10 7-7",key:"oa77jy"}],["path",{d:"M20 10h-6V4",key:"mjg0md"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M4 14h6v6",key:"rmj7iw"}]],he=O("minimize-2",me);/**
|
|
12
|
-
* @license lucide-react v1.7.0 - ISC
|
|
13
|
-
*
|
|
14
|
-
* This source code is licensed under the ISC license.
|
|
15
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/const fe=[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]],pe=O("play",fe);/**
|
|
17
|
-
* @license lucide-react v1.7.0 - ISC
|
|
18
|
-
*
|
|
19
|
-
* This source code is licensed under the ISC license.
|
|
20
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
-
*/const ve=[["path",{d:"M14 17H5",key:"gfn3mx"}],["path",{d:"M19 7h-9",key:"6i9tg"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}],["circle",{cx:"7",cy:"7",r:"3",key:"dfmy0x"}]],we=O("settings-2",ve),_="8314",be={getOutput:ne,createPreviewSession:te};function ge({taskId:s,api:t=be,allowPortPreview:l=!1}){const[a,w]=i.useState(null),[n,u]=i.useState(null),[d,x]=i.useState(null),[m,h]=i.useState(_),[j,b]=i.useState(!1),[P,S]=i.useState(!0),[v,c]=i.useState(null),[Z,F]=i.useState(!1),[U,f]=i.useState(!1),L=i.useCallback(async()=>{S(!0),c(null),w(null),u(null),x(null),f(!1);try{const r=await t.getOutput(s);w(r),S(!1)}catch(r){c(r instanceof Error?r.message:"Failed to load output"),S(!1)}},[t,s]);i.useEffect(()=>{L()},[L]);const N=i.useCallback(async r=>{c(null);try{const o=await t.createPreviewSession(s,r?.path?{path:r.path}:void 0);u(o),b(!1),f(!1),r&&x(r),T("preview.created",{result:"success",previewType:r?.kind??"file"})}catch(o){c(o instanceof Error?o.message:"Failed to create preview session"),T("preview.failed",{result:"failed",previewType:r?.kind??"file"})}},[t,s]),M=i.useCallback(async r=>{const o=r??Number.parseInt(m.trim()||_,10);if(!Number.isInteger(o)||o<1||o>65535){c("Enter a port between 1 and 65535");return}c(null);try{const C=await t.createPreviewSession(s,{port:o});u(C),x(null),h(String(o)),b(!0),f(!1),T("preview.created",{result:"success",previewType:"service-port"})}catch(C){c(C instanceof Error?C.message:"Failed to create preview session"),T("preview.failed",{result:"failed",previewType:"service-port"})}},[t,m,s]),y=i.useMemo(()=>G(a),[a]);i.useEffect(()=>{if(j||!a?.available||y.length===0||n&&n.kind!=="service")return;const r=d??y[0];r&&N(r)},[d,a,y,j,n,N]);const g=i.useCallback(()=>{if(n?.kind==="service"&&typeof n.port=="number"){M(n.port);return}u(null);const r=d??G(a)[0];r&&N(r)},[d,a,n,M,N]);if(i.useEffect(()=>{if(!n)return;const r=n.expiresAt-Date.now()-5e3;if(r<=0){g();return}const o=window.setTimeout(g,r);return()=>window.clearTimeout(o)},[g,n]),P)return e.jsx(E,{children:"Loading preview..."});const k=l&&j;if(v&&n&&!k)return e.jsx(E,{children:e.jsxs("div",{className:"space-y-4 text-center",children:[e.jsx("div",{className:"text-[11px] text-destructive",children:v}),e.jsx("div",{className:"flex justify-center",children:e.jsxs(p,{variant:"outline",size:"sm",onClick:g,className:"rounded-sm",children:[e.jsx(D,{className:"h-3.5 w-3.5"}),"Retry"]})})]})});const H=!!a?.available;if(!H&&!l)return e.jsx(E,{children:"Task output is not available yet."});if(!n)return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx("div",{className:"shrink-0 border-b border-border/60 px-3 py-1.5",children:e.jsx(A,{session:null,serviceModeOpen:k,allowPortPreview:l,servicePort:m,previewEntries:y,activeEntry:d,filesMenuOpen:U,onRefresh:g,onFullscreen:()=>F(!0),onServiceModeToggle:()=>{f(!1),b(r=>!r)},onServicePortChange:h,onServiceStart:()=>{M()},onFileMenuToggle:()=>f(r=>!r),onEntrySelect:r=>{f(!1),N(r)}})}),k?e.jsx(R,{serviceSession:null,error:v}):e.jsx(E,{children:v?e.jsx("span",{className:"text-[11px] text-destructive",children:v}):H?y.length>0?"Starting preview session...":"No HTML or Markdown files were found in this task output.":"Task output is not available yet."})]});const V=Y(n),ee=z(n),B=Q(n),W=X(n),$=n.kind==="service"?n:null,se=k?$:n,q=e.jsx("iframe",{src:B,className:"h-full w-full border-0",sandbox:W,title:"Task Preview"});return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx("div",{className:"shrink-0 border-b border-border/60 px-3 py-1.5",children:e.jsx(A,{session:se,serviceModeOpen:k,allowPortPreview:l,servicePort:m,previewEntries:y,activeEntry:d,filesMenuOpen:U,onRefresh:g,onFullscreen:()=>F(!0),onServiceModeToggle:()=>{f(!1),b(r=>!r)},onServicePortChange:h,onServiceStart:()=>{M()},onFileMenuToggle:()=>f(r=>!r),onEntrySelect:r=>{f(!1),N(r)}})}),k?e.jsx(R,{serviceSession:$,error:v,children:$?q:null}):e.jsx("div",{className:"min-h-0 flex-1 p-2",children:e.jsx("div",{className:"h-full overflow-hidden rounded-sm border border-border/60 bg-white shadow-none",children:q})}),e.jsx(ae,{open:Z,onOpenChange:F,children:e.jsxs(ie,{className:"flex h-[95vh] max-w-[95vw] flex-col gap-0 overflow-hidden p-0",children:[e.jsxs(le,{className:"sr-only",children:["Preview: ",V]}),e.jsxs("div",{className:"flex shrink-0 items-center justify-between border-b border-border/60 px-3 py-1.5",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate text-[12px] font-semibold text-foreground",children:V}),e.jsx("span",{className:"text-xs text-muted-foreground",children:I(n.expiresAt)})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(p,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-sm",onClick:g,title:"Refresh",children:e.jsx(D,{className:"h-3.5 w-3.5"})}),e.jsx(p,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-sm",asChild:!0,title:"Open in new tab",children:e.jsx("a",{href:ee,target:"_blank",rel:"noopener noreferrer",children:e.jsx(K,{className:"h-3.5 w-3.5"})})}),e.jsx(oe,{asChild:!0,children:e.jsxs(p,{variant:"outline",size:"sm",className:"h-6 rounded-sm px-2 text-[11px]",title:"Exit fullscreen",children:[e.jsx(he,{className:"h-3.5 w-3.5"}),"Exit fullscreen"]})})]})]}),e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx("iframe",{src:B,className:"h-full w-full border-0",sandbox:W,title:"Task Preview Fullscreen"})})]})})]})}function G(s){const t=s?.summary?.htmlEntries??[],l=s?.summary?.markdownEntries??[];return[...t.map(a=>({...a,kind:"html"})),...l.map(a=>({...a,kind:"markdown"}))]}function je({entries:s,activeEntry:t,open:l,onToggle:a,onEntrySelect:w}){const n=s[0];if(!n)return null;const u=t??n,d=J(u);return e.jsxs("div",{className:"relative min-w-0",children:[e.jsxs("button",{type:"button","aria-expanded":l,"aria-haspopup":"menu","aria-label":"Preview files",onClick:a,className:"flex h-6 max-w-[min(24rem,calc(100vw-7rem))] items-center gap-1.5 rounded-sm px-1.5 text-left text-[12px] font-semibold text-foreground transition-colors hover:bg-background/70",children:[e.jsx("span",{className:"truncate",children:u.label}),e.jsx(ce,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"})]}),l&&e.jsx("div",{role:"menu","aria-label":"Preview files",className:"absolute left-0 top-full z-30 mt-1 max-h-64 min-w-[14rem] max-w-[min(28rem,calc(100vw-4rem))] overflow-y-auto rounded-sm border border-border/70 bg-popover/95 p-1 text-popover-foreground shadow-[0_16px_48px_-34px_rgba(0,0,0,0.45)] backdrop-blur-xl",children:s.map(x=>{const m=J(x),h=m===d;return e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":h,onClick:()=>w(x),className:"flex w-full items-center gap-2 rounded-sm px-2 py-1 text-left text-[11px] leading-4 text-foreground transition-colors hover:bg-accent/75 hover:text-accent-foreground",children:[e.jsx("span",{className:"w-3.5 shrink-0 text-primary",children:h?e.jsx(de,{className:"h-3.5 w-3.5"}):null}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:x.label})]},m)})})]})}function J(s){return`${s.kind}:${s.path}`}function A({session:s,serviceModeOpen:t,allowPortPreview:l,servicePort:a,previewEntries:w=[],activeEntry:n=null,filesMenuOpen:u=!1,onRefresh:d,onFullscreen:x,onServiceModeToggle:m,onServicePortChange:h,onServiceStart:j,onFileMenuToggle:b,onEntrySelect:P}){const S=s?z(s):null,v=!t&&w.length>0&&b&&P;return e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"flex min-w-0 items-center gap-2",children:t&&h&&j?e.jsxs("form",{className:"flex min-w-0 items-center gap-1.5",onSubmit:c=>{c.preventDefault(),j()},children:[e.jsx("span",{className:"shrink-0 text-[12px] font-semibold text-foreground",children:"Preview service"}),e.jsxs("label",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground",children:["Port",e.jsx(re,{type:"text",min:1,max:65535,inputMode:"numeric",value:a??"",onChange:c=>h(c.target.value),placeholder:_,"aria-label":"Service preview port",className:"h-6 w-20 rounded-sm border-0 bg-muted/55 px-2 text-[11px] shadow-none focus:bg-muted/55 focus:outline-none focus-visible:border-0 focus-visible:bg-muted/55 focus-visible:ring-0 focus-visible:ring-offset-0"})]}),e.jsxs(p,{type:"submit",variant:"ghost",size:"sm",className:"h-6 rounded-sm border-0 bg-primary/10 px-2 text-[11px] text-primary shadow-none hover:bg-primary/15 hover:text-primary",children:[e.jsx(pe,{className:"h-3.5 w-3.5"}),"Preview"]}),s&&e.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:I(s.expiresAt)})]}):e.jsxs(e.Fragment,{children:[v?e.jsx(je,{entries:w,activeEntry:n,open:u,onToggle:b,onEntrySelect:P}):e.jsx("span",{className:"truncate text-[12px] font-semibold text-foreground",children:s?Y(s):"Preview"}),s&&e.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:I(s.expiresAt)})]})}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s&&e.jsxs(e.Fragment,{children:[e.jsx(p,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-sm",onClick:d,title:"Refresh",children:e.jsx(D,{className:"h-3.5 w-3.5"})}),e.jsx(p,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-sm",asChild:!0,title:"Open in new tab",children:e.jsx("a",{href:S??s.previewUrl,target:"_blank",rel:"noopener noreferrer",children:e.jsx(K,{className:"h-3.5 w-3.5"})})}),e.jsx(p,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-sm",onClick:x,title:"Fullscreen",children:e.jsx(xe,{className:"h-3.5 w-3.5"})})]}),l&&e.jsxs(p,{type:"button",variant:t?"secondary":"ghost",size:"sm","aria-pressed":t,onClick:m,className:"h-6 shrink-0 rounded-sm px-2 text-[11px]",children:[e.jsx(we,{className:"h-3.5 w-3.5"}),"Advanced"]})]})]})}function R({serviceSession:s,error:t,children:l}){return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[t&&e.jsx("div",{className:"shrink-0 border-b border-destructive/20 bg-destructive/5 px-4 py-2 text-xs text-destructive",children:t}),e.jsx("div",{className:"min-h-0 flex-1 p-2",children:s&&l?e.jsx("div",{className:"h-full overflow-hidden rounded-sm border border-border/60 bg-white shadow-none",children:l}):e.jsx(E,{children:"No service preview running."})})]})}function z(s){return s.openUrl??s.previewUrl}function Q(s){return s.kind==="service"?z(s):s.previewUrl}function X(s){return s.kind==="service"?void 0:"allow-scripts allow-same-origin"}function Y(s){if(s.kind==="service"&&typeof s.port=="number"){const t=s.entryPath?`/${s.entryPath.replace(/^\/+/,"")}`:"";return`127.0.0.1:${s.port}${t}`}return s.entryPath}function E({children:s}){return e.jsx("div",{className:"flex h-64 items-center justify-center text-muted-foreground",children:s})}function I(s){const t=Math.max(0,Math.round((s-Date.now())/1e3));if(t<60)return`${t}s`;const l=Math.floor(t/60),a=t%60;return`${l}m ${a}s`}const ye=Object.freeze(Object.defineProperty({__proto__:null,DEFAULT_SERVICE_PREVIEW_PORT:_,PreviewHeader:A,PreviewServicePanel:R,PreviewTab:ge,getPreviewIframeSandbox:X,getPreviewIframeSrc:Q,getPreviewOpenUrl:z},Symbol.toStringTag,{value:"Module"}));export{_ as D,pe as P,X as a,Q as b,ye as c,z as g};
|