@aprovan/patchwork-chat 0.1.0-dev.ba8f277 → 0.1.0-dev.f456953
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/.turbo/turbo-build.log
CHANGED
|
@@ -157,18 +157,23 @@ computing gzip size...
|
|
|
157
157
|
[2mdist/[22m[2massets/[22m[36mbat-BkioyH1T.js [39m[1m[2m 12.89 kB[22m[1m[22m[2m │ gzip: 3.22 kB[22m
|
|
158
158
|
[2mdist/[22m[2massets/[22m[36mfish-BvzEVeQv.js [39m[1m[2m 13.04 kB[22m[1m[22m[2m │ gzip: 1.74 kB[22m
|
|
159
159
|
[2mdist/[22m[2massets/[22m[36mv-BcVCzyr7.js [39m[1m[2m 13.21 kB[22m[1m[22m[2m │ gzip: 2.74 kB[22m
|
|
160
|
+
[33m
|
|
160
161
|
[2mdist/[22m[2massets/[22m[36mvitesse-light-CVO1_9PV.js [39m[1m[2m 13.62 kB[22m[1m[22m[2m │ gzip: 3.04 kB[22m
|
|
162
|
+
(!) Some chunks are larger than 500 kB after minification. Consider:
|
|
161
163
|
[2mdist/[22m[2massets/[22m[36maurora-x-D-2ljcwZ.js [39m[1m[2m 13.66 kB[22m[1m[22m[2m │ gzip: 2.28 kB[22m
|
|
162
164
|
[2mdist/[22m[2massets/[22m[36mvitesse-black-Bkuqu6BP.js [39m[1m[2m 13.68 kB[22m[1m[22m[2m │ gzip: 3.06 kB[22m
|
|
163
165
|
[2mdist/[22m[2massets/[22m[36mvitesse-dark-D0r3Knsf.js [39m[1m[2m 13.76 kB[22m[1m[22m[2m │ gzip: 3.06 kB[22m
|
|
166
|
+
- Using dynamic import() to code-split the application
|
|
164
167
|
[2mdist/[22m[2massets/[22m[36mpug-CGlum2m_.js [39m[1m[2m 13.84 kB[22m[1m[22m[2m │ gzip: 2.58 kB[22m
|
|
165
168
|
[2mdist/[22m[2massets/[22m[36mluau-C-HG3fhB.js [39m[1m[2m 13.96 kB[22m[1m[22m[2m │ gzip: 3.18 kB[22m
|
|
169
|
+
- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks
|
|
166
170
|
[2mdist/[22m[2massets/[22m[36msynthwave-84-CbfX1IO0.js [39m[1m[2m 14.04 kB[22m[1m[22m[2m │ gzip: 2.87 kB[22m
|
|
167
171
|
[2mdist/[22m[2massets/[22m[36mgithub-light-default-D7oLnXFd.js [39m[1m[2m 14.16 kB[22m[1m[22m[2m │ gzip: 3.04 kB[22m
|
|
168
172
|
[2mdist/[22m[2massets/[22m[36mclarity-D53aC0YG.js [39m[1m[2m 14.28 kB[22m[1m[22m[2m │ gzip: 2.46 kB[22m
|
|
169
173
|
[2mdist/[22m[2massets/[22m[36mgithub-light-high-contrast-BfjtVDDH.js [39m[1m[2m 14.28 kB[22m[1m[22m[2m │ gzip: 3.02 kB[22m
|
|
170
174
|
[2mdist/[22m[2massets/[22m[36mgithub-dark-dimmed-DH5Ifo-i.js [39m[1m[2m 14.43 kB[22m[1m[22m[2m │ gzip: 3.13 kB[22m
|
|
171
175
|
[2mdist/[22m[2massets/[22m[36mgithub-dark-default-Cuk6v7N8.js [39m[1m[2m 14.44 kB[22m[1m[22m[2m │ gzip: 3.13 kB[22m
|
|
176
|
+
- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.[39m
|
|
172
177
|
[2mdist/[22m[2massets/[22m[36mgithub-dark-high-contrast-E3gJ1_iC.js [39m[1m[2m 14.60 kB[22m[1m[22m[2m │ gzip: 3.09 kB[22m
|
|
173
178
|
[2mdist/[22m[2massets/[22m[36mgnuplot-DdkO51Og.js [39m[1m[2m 14.78 kB[22m[1m[22m[2m │ gzip: 3.27 kB[22m
|
|
174
179
|
[2mdist/[22m[2massets/[22m[36mrust-B1yitclQ.js [39m[1m[2m 15.07 kB[22m[1m[22m[2m │ gzip: 2.72 kB[22m
|
|
@@ -310,10 +315,5 @@ computing gzip size...
|
|
|
310
315
|
[2mdist/[22m[2massets/[22m[36mwasm-CG6Dc4jp.js [39m[1m[33m 622.34 kB[39m[22m[2m │ gzip: 230.29 kB[22m
|
|
311
316
|
[2mdist/[22m[2massets/[22m[36mcpp-CofmeUqb.js [39m[1m[33m 626.08 kB[39m[22m[2m │ gzip: 44.82 kB[22m
|
|
312
317
|
[2mdist/[22m[2massets/[22m[36memacs-lisp-C9XAeP06.js [39m[1m[33m 779.85 kB[39m[22m[2m │ gzip: 196.03 kB[22m
|
|
313
|
-
[2mdist/[22m[2massets/[22m[36mindex-
|
|
314
|
-
[
|
|
315
|
-
(!) Some chunks are larger than 500 kB after minification. Consider:
|
|
316
|
-
- Using dynamic import() to code-split the application
|
|
317
|
-
- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks
|
|
318
|
-
- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.[39m
|
|
319
|
-
[32m✓ built in 7.93s[39m
|
|
318
|
+
[2mdist/[22m[2massets/[22m[36mindex-Cjs5j4Ri.js [39m[1m[33m1,450.90 kB[39m[22m[2m │ gzip: 444.73 kB[22m
|
|
319
|
+
[32m✓ built in 7.19s[39m
|
|
@@ -1487,4 +1487,4 @@ ${Mn}
|
|
|
1487
1487
|
|
|
1488
1488
|
Console errors:
|
|
1489
1489
|
${D.join(`
|
|
1490
|
-
`)}`:"";return{success:!1,error:j+Xe}}finally{console.error=U}},[me,t,n]),q=()=>{h(e),g(0)},ie=f!==e,le=T.useMemo(()=>me?b.jsx(Fx,{code:f,compiler:t,services:n,enabled:l&&!o}):te.category==="media"?b.jsx(eD,{content:f,mimeType:te.mimeType,fileName:X}):te.language==="markdown"?b.jsx("div",{className:"p-4 prose prose-sm dark:prose-invert max-w-none",children:b.jsx(qR,{value:f})}):b.jsx(Jc,{content:f,language:te.language}),[me,t,f,te,o,X,n,l]),oe=T.useCallback(async()=>{if(!s){a(!0);return}const he=await P(),D=M(),U=Lc(f,D,he);s({projectId:he,entryFile:D,filePath:r,initialCode:f,initialProject:U})},[s,P,M,f,r]);return b.jsxs(b.Fragment,{children:[b.jsxs("div",{className:"border rounded-lg overflow-hidden min-w-0",children:[b.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-muted/50 border-b rounded-t-lg",children:[b.jsx(R1,{className:"h-4 w-4 text-muted-foreground"}),m>0&&b.jsxs("span",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[b.jsx($9,{className:"h-3 w-3"}),m," edit",m!==1?"s":""]}),b.jsxs("div",{className:"ml-auto flex gap-1",children:[ie&&b.jsx("button",{onClick:q,className:"px-2 py-1 text-xs rounded flex items-center gap-1 hover:bg-muted text-muted-foreground",title:"Revert to original",children:b.jsx(xT,{className:"h-3 w-3"})}),b.jsx("button",{onClick:()=>void oe(),className:"px-2 py-1 text-xs rounded flex items-center gap-1 hover:bg-muted",title:"Edit component",children:b.jsx(ru,{className:"h-3 w-3"})}),b.jsx(ZR,{status:y,onClick:z,disabled:y==="saving",tone:"muted"}),b.jsxs("button",{onClick:()=>c(!l),className:`w-[5rem] px-2 py-1 text-xs rounded flex items-center gap-1 ${l?"bg-primary text-primary-foreground":"hover:bg-primary/20 text-primary"}`,children:[l?b.jsx(gT,{className:"h-3 w-3"}):b.jsx(R1,{className:"h-3 w-3"}),l?"Preview":"Code"]})]})]}),l?b.jsx("div",{className:"bg-white overflow-y-auto overflow-x-hidden max-h-[60vh]",children:le}):b.jsx("div",{className:"bg-muted/30 overflow-auto max-h-[60vh]",children:b.jsx(Jc,{content:f,language:te.language})})]}),b.jsx(tD,{isOpen:o,onClose:(he,D)=>{h(he),g(U=>U+D),a(!1),D>0&&(v("saving"),(async()=>{try{const U=await P(),re=M(),j=Lc(he,re,U);await QS(j),w(he),v("saved")}catch(U){console.warn("[VFS] Failed to save project:",U),v("error")}})())},originalCode:f,compile:K,renderPreview:he=>b.jsx(Fx,{code:he,compiler:t,services:n})})]})}function Lue({children:e,className:t=""}){return b.jsx("span",{className:`inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 ${t}`,children:e})}function jue({children:e,open:t,onOpenChange:n}){return t?b.jsx("div",{className:"fixed inset-0 z-50 bg-black/50",onClick:()=>n==null?void 0:n(!1),children:b.jsx("div",{className:"fixed left-1/2 top-1/2 z-50 w-full max-w-lg -translate-x-1/2 -translate-y-1/2 bg-background p-6 shadow-lg rounded-lg",onClick:r=>r.stopPropagation(),children:e})}):null}function zue({namespaces:e,services:t=[],BadgeComponent:n=Lue,DialogComponent:r=jue,DialogHeaderComponent:i=({children:a})=>b.jsx("div",{className:"flex justify-between items-center mb-4",children:a}),DialogContentComponent:s=({children:a,className:l=""})=>b.jsx("div",{className:l,children:a}),DialogCloseComponent:o=({onClose:a})=>b.jsx("button",{onClick:()=>a==null?void 0:a(),className:"text-muted-foreground hover:text-foreground",children:"×"})}){const[a,l]=T.useState(!1);if(e.length===0)return null;const c=t.reduce((f,h)=>{var m;return(f[m=h.namespace]??(f[m]=[])).push(h),f},{});return b.jsxs(b.Fragment,{children:[b.jsxs("button",{onClick:()=>l(!0),className:"flex items-center gap-2 hover:opacity-80 transition-opacity",children:[b.jsx(X9,{className:"h-4 w-4 text-muted-foreground"}),b.jsxs(n,{className:"text-xs",children:[e.length," service",e.length!==1?"s":""]})]}),b.jsxs(r,{open:a,onOpenChange:l,children:[b.jsxs(i,{children:[b.jsx("h2",{className:"text-lg font-semibold",children:"Available Services"}),b.jsx(o,{onClose:()=>l(!1)})]}),b.jsx(s,{className:"space-y-3 max-h-96 overflow-auto",children:e.map(f=>{var h;return b.jsxs("details",{open:e.length===1,children:[b.jsxs("summary",{className:"flex items-center gap-2 w-full p-2 rounded bg-muted/50 hover:bg-muted transition-colors cursor-pointer",children:[b.jsx(Wa,{className:"h-4 w-4 text-muted-foreground"}),b.jsx("span",{className:"font-medium text-sm",children:f}),c[f]&&b.jsxs(n,{className:"ml-auto text-xs",children:[c[f].length," tool",c[f].length!==1?"s":""]})]}),b.jsx("div",{className:"ml-6 mt-2 space-y-2",children:((h=c[f])==null?void 0:h.map(m=>b.jsxs("details",{children:[b.jsxs("summary",{className:"flex items-center gap-2 w-full text-left text-sm hover:text-foreground text-muted-foreground transition-colors cursor-pointer",children:[m.parameters&&b.jsx(Wa,{className:"h-3 w-3"}),b.jsx("code",{className:"font-mono text-xs",children:m.procedure}),b.jsx("span",{className:"truncate text-xs opacity-70",children:m.description})]}),m.parameters&&b.jsx("div",{className:"ml-5 mt-1 p-2 rounded border bg-muted/30 overflow-auto max-h-48",children:b.jsx("pre",{className:"text-xs font-mono whitespace-pre-wrap break-words m-0",children:JSON.stringify(m.parameters,null,2)})})]},m.name)))??b.jsx("p",{className:"text-xs text-muted-foreground",children:"No tool details available"})})]},f)})})]})]})}var Fue=/```([a-zA-Z0-9_+-]*)((?:\s+[a-zA-Z_][\w-]*="[^"]*")*)\s*\n([\s\S]*?)```/g,$ue=/```([a-zA-Z0-9_+-]*)((?:\s+[a-zA-Z_][\w-]*="[^"]*")*)\s*\n([\s\S]*)$/,Bue=/([a-zA-Z_][\w-]*)="([^"]*)"/g;function XS(e){const t={};if(!e)return t;const n=new RegExp(Bue.source,"g");let r;for(;(r=n.exec(e))!==null;){const i=r[1],s=r[2];i&&s!==void 0&&(t[i]=s)}return t}function Vue(e,t={}){var f,h;const{filterLanguages:n,includeUnclosed:r=!1}=t,i=[];let s=0;const o=[],a=new RegExp(Fue.source,"g");let l;for(;(l=a.exec(e))!==null;){const m=((f=l[1])==null?void 0:f.toLowerCase())||"",g=XS(l[2]||""),y=l[3]??"",v=!n||n.has(m);o.push({match:l,language:m,content:y,attributes:g,included:v})}for(const{match:m,language:g,content:y,attributes:v,included:k}of o){if(m.index>s){const w=e.slice(s,m.index);w.trim()&&i.push({type:"text",content:w})}s=m.index+m[0].length,k&&i.push({type:"code",content:y,language:g,attributes:v})}const c=e.slice(s);if(r&&c.includes("```")){const m=c.match($ue);if(m){const g=((h=m[1])==null?void 0:h.toLowerCase())||"",y=XS(m[2]||""),v=m[3]??"",k=!n||n.has(g),w=c.indexOf("```");if(w>0){const S=c.slice(0,w);S.trim()&&i.push({type:"text",content:S})}k&&i.push({type:"code",content:v,language:g,attributes:y}),s=e.length}}if(s<e.length){const m=e.slice(s);m.trim()&&i.push({type:"text",content:m})}return i.length===0&&i.push({type:"text",content:e}),i}const Uue="/vfs";let f1=null;function Eu(){if(!f1){const e=new W4({baseUrl:Uue});f1=new q4(e,{sync:!1})}return f1}function ii(e){return e.replace(/^\/+|\/+$/g,"")}function iD(e){const t=ii(e);return!t||!t.includes("/")?"":t.split("/").slice(0,-1).join("/")}function sD(e){const t=ii(e);if(!t)return"";const n=t.split("/");return n[n.length-1]??""}function Hue(e,t){const n=ii(e),r=ii(t);return n?r?`${n}/${r}`:n:r}function Wue(e){const t=ii(e);return t?`${t}/`:""}function que(e){return e.map(t=>({path:t,content:""}))}function Zue(e,t){if(!e)return ii(t);const n=ii(e),r=ii(t),i=`${n}/`;return r.startsWith(i)?r.slice(i.length):r}function Gue(e,t){const n=ii(e),r=ii(t);return n?Hue(n,r):r}async function Jue(e=""){const t=Eu(),n=ii(e);return(await t.readdir(n)).map(i=>({name:i.name,path:n?`${n}/${i.name}`:i.name,isDir:i.isDirectory()})).sort((i,s)=>i.isDir!==s.isDir?i.isDir?-1:1:i.name.localeCompare(s.name))}async function h1(){return Eu().listFiles()}async function e3(e){const t=Eu(),n=ii(e),r=Wue(n),s=(await t.listFiles(n)).filter(a=>r?a.startsWith(r):!0);if(s.length===0)return null;const o=new Map;return await Promise.all(s.map(async a=>{const l=await t.readFile(a),c=Zue(n,a);o.set(c,{path:c,content:l})})),{id:n,entry:O4(o),files:o}}async function p1(e){const t=Eu(),n=ii(e),r=sD(n),i=iD(n);try{const s=await t.readFile(n);return{id:i,entry:r,files:new Map([[r,{path:r,content:s}]])}}catch{return null}}function Kue(e,t){const n=ii(e),r=sD(n);return{id:iD(n),entry:r,files:new Map([[r,{path:r,content:t}]])}}async function Yue(e){const t=Eu();await Promise.all(Array.from(e.files.values()).map(n=>t.writeFile(Gue(e.id,n.path),n.content)))}function Que(e){return Eu().watch("",e)}const Wh="https://raw.githubusercontent.com/AprovanLabs/aprovan.com/main/docs/assets/social-labs.png",jv=T.createContext({compiler:null,namespaces:[]}),Xue=()=>T.useContext(jv).compiler,ece=()=>T.useContext(jv).namespaces;function tce(e){return{name:"preview",version:"1.0.0",platform:"browser",image:"@aprovan/patchwork-image-shadcn",services:e}}const oD=T.createContext(null),nce=()=>T.useContext(oD);function rce({text:e,isStreaming:t}){return b.jsxs(_A,{defaultOpen:t,children:[b.jsxs(EA,{className:"flex items-center gap-2 text-yellow-700 dark:text-yellow-400 hover:opacity-80 w-full",children:[b.jsx(w9,{className:"h-4 w-4"}),b.jsx("span",{className:"text-xs font-medium",children:"Thinking"}),t&&b.jsx(ni,{className:"h-3 w-3 animate-spin"}),b.jsx(Wa,{className:"h-3 w-3 ml-auto transition-transform [[data-state=open]>&]:rotate-180"})]}),b.jsx(CA,{children:b.jsx("div",{className:"mt-2 p-3 rounded border-l-4 border-yellow-500 bg-yellow-50 dark:bg-yellow-950/50",children:b.jsx("p",{className:"text-sm text-muted-foreground italic whitespace-pre-wrap",children:e})})})]})}function ice({toolName:e,state:t,input:n,output:r,errorText:i}){const s=t==="input-streaming"||t==="input-available",o=t==="output-error";return b.jsxs(_A,{className:"my-1 w-full",children:[b.jsxs(EA,{className:"inline-flex items-center gap-2 px-3 py-1 rounded-full border bg-muted/50 hover:bg-muted text-xs transition-colors",children:[b.jsx(oz,{className:"h-3 w-3 text-muted-foreground"}),b.jsx("span",{className:"font-mono",children:e}),b.jsxs("span",{className:"w-3 h-3 flex items-center justify-center",children:[s&&b.jsx(ni,{className:"h-3 w-3 animate-spin text-muted-foreground"}),o&&b.jsx(na,{className:"h-3 w-3 text-destructive"})]}),b.jsx(Wa,{className:"h-3 w-3 text-muted-foreground transition-transform [[data-state=open]>&]:rotate-180"})]}),b.jsxs(CA,{className:"mt-2 p-3 rounded-lg border bg-white space-y-2",children:[n!==void 0&&b.jsxs("div",{children:[b.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Input"}),b.jsx("div",{className:"mt-1 p-2 bg-muted/30 rounded text-xs overflow-auto max-h-48",children:b.jsx("pre",{className:"whitespace-pre-wrap break-words m-0",children:typeof n=="string"?n:JSON.stringify(n,null,2)})})]}),r!==void 0&&b.jsxs("div",{children:[b.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Output"}),b.jsx("div",{className:"mt-1 p-2 bg-muted/30 rounded text-xs overflow-auto max-h-48",children:b.jsx("pre",{className:"whitespace-pre-wrap break-words m-0",children:typeof r=="string"?r:JSON.stringify(r,null,2)})})]}),i&&b.jsxs("div",{className:"text-sm text-destructive flex items-center gap-2",children:[b.jsx(na,{className:"h-4 w-4 shrink-0"}),b.jsx("span",{className:"break-words",children:i})]})]})]})}function sce({message:e}){var r,i;const t=e.role==="user",n=(r=e.parts)==null?void 0:r.some(s=>"state"in s&&(s.state==="input-streaming"||s.state==="input-available"));return b.jsxs("div",{className:`flex gap-3 ${t?"justify-end":"justify-start"}`,children:[!t&&b.jsxs(lp,{className:"h-8 w-8 shrink-0",children:[b.jsx("img",{src:Wh,alt:"Assistant",className:"rounded-full"}),b.jsx(up,{className:"bg-primary text-primary-foreground",children:"A"})]}),b.jsxs("div",{className:`flex flex-col gap-1 max-w-[80%] min-w-0 ${t?"items-end":"items-start"}`,children:[b.jsxs("div",{className:"flex items-center gap-2 h-5",children:[b.jsx("span",{className:"text-xs text-muted-foreground capitalize",children:e.role}),n&&b.jsxs(J$,{variant:"outline",className:"text-xs",children:[b.jsx(ni,{className:"h-3 w-3 mr-1 animate-spin"}),"streaming"]})]}),b.jsx("div",{className:`rounded-lg px-4 py-2 overflow-hidden w-full ${t?"bg-primary text-primary-foreground":"bg-muted"}`,children:(i=e.parts)==null?void 0:i.map((s,o)=>{if(s.type==="text")return b.jsx(oce,{text:s.text,isUser:t},o);if(s.type==="reasoning")return b.jsx(rce,{text:s.text,isStreaming:s.state==="streaming"},o);if(s.type.startsWith("tool-")||s.type==="dynamic-tool"){const a=s,l=a.toolName??s.type.replace("tool-","");return b.jsx(ice,{toolName:l,state:a.state,input:a.input,output:a.output,errorText:a.errorText},o)}return null})})]}),t&&b.jsx(lp,{className:"h-8 w-8 shrink-0",children:b.jsx(up,{className:"bg-secondary",children:"U"})})]})}function oce({text:e,isUser:t}){const n=nce(),r=Xue(),i=ece();if(t)return b.jsx("div",{className:"prose prose-sm prose-invert prose-p:my-1 prose-headings:my-2 prose-ul:my-1 prose-ol:my-1 prose-li:my-0 prose-pre:my-2 prose-code:before:content-none prose-code:after:content-none",children:b.jsx(Mc,{remarkPlugins:[Oc],children:e})});const s=Vue(e);return b.jsx("div",{className:"prose prose-sm dark:prose-invert prose-p:my-1 prose-headings:my-2 prose-ul:my-1 prose-ol:my-1 prose-li:my-0 prose-pre:my-2 prose-code:before:content-none prose-code:after:content-none",children:s.map((o,a)=>{var l;return o.type==="code"?b.jsx(rD,{code:o.content,compiler:r,services:i,filePath:(l=o.attributes)==null?void 0:l.path,entrypoint:"main.tsx",onOpenEditSession:n??void 0},a):b.jsx(Mc,{remarkPlugins:[Oc],children:o.content},a)})})}const ace="/api/proxy",t3="@aprovan/patchwork-image-shadcn",lce="https://esm.sh",uce="https://esm.sh";function cce(e,t){const n=e.replace(/^\/+|\/+$/g,""),r=t.replace(/^\/+|\/+$/g,"");if(!n)return r;const i=`${n}/`;return r.startsWith(i)?r.slice(i.length):r}const aD="patchwork:open-tabs";function n3(){try{const e=localStorage.getItem(aD);if(!e)return{paths:[],activePath:null};const t=JSON.parse(e);return{paths:Array.isArray(t.paths)?t.paths:[],activePath:typeof t.activePath=="string"?t.activePath:null}}catch{return{paths:[],activePath:null}}}function dce(e,t){localStorage.setItem(aD,JSON.stringify({paths:e,activePath:t}))}function fce(){var Jn;const[e,t]=T.useState("What's the weather in Houston, Texas like?"),[n,r]=T.useState(null),[i,s]=T.useState([]),[o,a]=T.useState([]),[l,c]=T.useState([]),[f,h]=T.useState(""),[m,g]=T.useState(""),[y,v]=T.useState(0),[k,w]=T.useState(!1),[S,E]=T.useState(null),[N,I]=T.useState(null),[A,L]=T.useState(null),[P,M]=T.useState(()=>{const{paths:xe}=n3();return new Map(xe.map(ft=>[ft,{code:"",loading:!0,error:null}]))}),[z,X]=T.useState(()=>{const{paths:xe,activePath:ft}=n3();return ft&&xe.includes(ft)?ft:xe[0]??null}),[te,me]=T.useState(!1),K=T.useRef(null),q=T.useRef(new Map),[ie,le]=T.useState(()=>{try{const xe=localStorage.getItem("patchwork:pinned-paths");if(!xe)return new Map;const ft=JSON.parse(xe);return ft.length>0&&Array.isArray(ft[0])?new Map(ft):new Map(ft.map(at=>[at,!1]))}catch{return new Map}}),oe=T.useCallback((xe,ft)=>{le(at=>{const Et=new Map(at);return Et.has(xe)?Et.delete(xe):Et.set(xe,ft),localStorage.setItem("patchwork:pinned-paths",JSON.stringify(Array.from(Et))),Et})},[]),he=T.useCallback(async()=>{w(!0),E(null);try{if(m.trim()){const xe=await h1();c(xe)}v(xe=>xe+1)}catch(xe){E(xe instanceof Error?xe.message:"Failed to load workspace")}finally{w(!1)}},[m]);T.useEffect(()=>Que(()=>{v(xe=>xe+1),h1().then(xe=>{m.trim()&&c(xe);const ft=new Set(xe);M(at=>{let Et=!1;const Ut=new Map(at);for(const sn of Ut.keys())ft.has(sn)||(Ut.delete(sn),Et=!0);return Et?Ut:at})}).catch(()=>{})}),[m]),T.useEffect(()=>{m.trim()&&(w(!0),E(null),h1().then(c).catch(xe=>{E(xe instanceof Error?xe.message:"Failed to load workspace")}).finally(()=>w(!1)))},[m]),T.useEffect(()=>{fetch("/api/services").then(xe=>xe.json()).then(xe=>{s(xe.namespaces??[])}).catch(()=>{s([]),a([])}),SZ({image:t3,proxyUrl:ace,cdnBaseUrl:lce,widgetCdnBaseUrl:uce}).then(r).catch(console.error),he()},[]),T.useEffect(()=>{P.forEach((xe,ft)=>{if(!xe.loading)return;const at=(q.current.get(ft)??0)+1;q.current.set(ft,at),p1(ft).then(Et=>{if(q.current.get(ft)!==at)return;if(!Et){M(sn=>{const gn=new Map(sn);return gn.delete(ft),gn});return}const Ut=Et.files.get(Et.entry);M(sn=>{const gn=new Map(sn);return gn.set(ft,{code:(Ut==null?void 0:Ut.content)??"",loading:!1,error:null}),gn})}).catch(()=>{q.current.get(ft)===at&&M(Et=>{const Ut=new Map(Et);return Ut.delete(ft),Ut})})})},[]),T.useEffect(()=>{dce([...P.keys()],z)},[P,z]),T.useEffect(()=>{z!==null&&!P.has(z)&&X([...P.keys()][0]??null)},[P,z]);const D=T.useCallback(async xe=>{const{projectId:ft,filePath:at,entryFile:Et,initialCode:Ut,initialProject:sn}=xe,gn=await e3(ft),ir=at??`${ft}/${Et}`;if(gn){const Mn=cce(ft,ir);h(ir),L({project:gn,initialTreePath:Mn,initialActiveFile:Mn});return}const wi=ir,At=at?Kue(at,Ut):sn;h(wi),L({project:At,initialTreePath:At.entry,initialActiveFile:At.entry})},[]),U=T.useCallback(async(xe,ft)=>{const at=ft?await e3(xe):await p1(xe);at&&(h(xe),L({project:at,initialTreePath:at.entry,initialActiveFile:at.entry}))},[]),re=T.useCallback(xe=>{h(xe),X(xe),me(!1),M(at=>{if(at.has(xe))return at;const Et=new Map(at);return Et.set(xe,{code:"",loading:!0,error:null}),Et});const ft=(q.current.get(xe)??0)+1;q.current.set(xe,ft),p1(xe).then(at=>{if(q.current.get(xe)!==ft)return;if(!at){M(Ut=>{const sn=new Map(Ut);return sn.set(xe,{code:"",loading:!1,error:"Failed to load file preview"}),sn});return}const Et=at.files.get(at.entry);M(Ut=>{const sn=new Map(Ut);return sn.set(xe,{code:(Et==null?void 0:Et.content)??"",loading:!1,error:null}),sn})}).catch(at=>{q.current.get(xe)===ft&&M(Et=>{const Ut=new Map(Et);return Ut.set(xe,{code:"",loading:!1,error:at instanceof Error?at.message:"Failed to load file preview"}),Ut})})},[]),j=T.useCallback(xe=>{M(ft=>{const at=new Map(ft);return at.delete(xe),at}),X(ft=>{if(ft!==xe)return ft;const at=[...P.keys()],Et=at.indexOf(xe);return at.length<=1?null:at[Et>0?Et-1:Et+1]??null})},[P]),Xe=T.useCallback(()=>{M(new Map),X(null)},[]),F=T.useMemo(()=>{const xe=m.trim().toLowerCase();return xe?l.filter(ft=>ft.toLowerCase().includes(xe)):l},[l,m]),be=T.useMemo(()=>({compiler:n,namespaces:i}),[n,i]),Ie=T.useMemo(()=>new cT({body:()=>({metadata:{patchwork:{compilers:[t3]}}})}),[]),{messages:Oe,sendMessage:_e,status:Be,error:Rt}=m9({transport:Ie}),an=Be==="submitted"||Be==="streaming",Pn=T.useCallback(xe=>{xe==null||xe.preventDefault(),e.trim()&&(_e({text:e}),t(""))},[e,_e]);return T.useEffect(()=>{var xe;(xe=K.current)==null||xe.scrollTo({top:K.current.scrollHeight,behavior:"smooth"})},[Oe]),b.jsx(jv.Provider,{value:be,children:b.jsxs(oD.Provider,{value:D,children:[b.jsxs("div",{className:"flex flex-col h-screen max-w-6xl mx-auto p-4",ref:I,children:[b.jsxs(mA,{className:"flex-1 flex flex-col min-h-0 overflow-hidden border",children:[b.jsx(gA,{className:"border-b py-3",children:b.jsxs(yA,{className:"flex items-center gap-3",children:[b.jsx("img",{src:Wh,alt:"Aprovan",className:"h-8 w-8 rounded-full"}),b.jsx("span",{className:"text-lg",children:"patchwork"}),b.jsx(zue,{namespaces:i,services:o,DialogComponent:({open:xe,onOpenChange:ft,children:at})=>b.jsx(a7,{open:xe??!1,onOpenChange:ft??(()=>{}),children:at}),DialogHeaderComponent:l7,DialogContentComponent:u7,DialogCloseComponent:({onClose:xe})=>b.jsx(c7,{onClose:xe??(()=>{})})})]})}),b.jsxs(xA,{className:"flex-1 p-0 min-h-0 flex",children:[b.jsxs("div",{className:"w-64 border-r bg-muted/20 min-h-0 flex flex-col",children:[b.jsxs("div",{className:"px-3 py-2 border-b flex items-center gap-2 text-xs font-medium uppercase tracking-wide text-muted-foreground",children:[b.jsx("span",{children:"Workspace"}),b.jsx("button",{onClick:()=>void he(),className:"ml-auto p-1 rounded hover:bg-muted",title:"Refresh workspace",children:b.jsx(Z9,{className:`h-3 w-3 ${k?"animate-spin":""}`})})]}),b.jsx("div",{className:"p-2 border-b",children:b.jsx(UT,{value:m,onChange:xe=>g(xe.target.value),placeholder:"Filter files...",className:"h-8"})}),S?b.jsx("div",{className:"p-3 text-xs text-destructive",children:S}):m.trim()?b.jsx(zx,{files:que(F),activePath:f,onSelectFile:re,onSelectDirectory:h,onOpenInEditor:U,openInEditorMode:"all",openInEditorTitle:"Edit",pinnedPaths:ie,onTogglePin:oe,title:"Files"}):b.jsx(zx,{files:[],activePath:f,onSelectFile:re,onSelectDirectory:h,onOpenInEditor:U,openInEditorMode:"all",openInEditorTitle:"Edit",directoryLoader:Jue,pageSize:10,reloadToken:y,pinnedPaths:ie,onTogglePin:oe,title:"Files"})]}),b.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",children:[P.size>0&&b.jsxs("div",{className:"border-b bg-muted/10",children:[b.jsxs("div",{className:"flex items-center border-b bg-muted/30",children:[b.jsx("div",{className:"flex-1 flex items-center overflow-x-auto min-w-0",children:[...P.entries()].map(([xe])=>{const ft=xe.split("/").pop()??xe,at=xe===z;return b.jsxs("button",{onClick:()=>{X(xe),h(xe),me(!1)},className:`group relative flex items-center gap-1.5 px-3 py-1.5 text-xs border-r shrink-0 max-w-[180px] ${at?"bg-background text-foreground border-b-2 border-b-primary":"text-muted-foreground hover:bg-muted/50"}`,title:xe,children:[b.jsx("span",{className:"truncate",children:ft}),b.jsx("span",{role:"button",onClick:Et=>{Et.stopPropagation(),j(xe)},className:"shrink-0 p-0.5 rounded hover:bg-muted-foreground/20 opacity-0 group-hover:opacity-100 transition-opacity",title:"Close tab",children:b.jsx(ad,{className:"h-3 w-3"})})]},xe)})}),b.jsxs("div",{className:"flex items-center gap-0.5 px-1 shrink-0",children:[b.jsx("button",{onClick:()=>me(xe=>!xe),className:"p-1 rounded hover:bg-muted",title:te?"Expand preview":"Collapse preview",children:te?b.jsx(Wa,{className:"h-3.5 w-3.5"}):b.jsx(V9,{className:"h-3.5 w-3.5"})}),b.jsx("button",{onClick:Xe,className:"p-1 rounded hover:bg-muted",title:"Close all tabs",children:b.jsx(ad,{className:"h-3.5 w-3.5"})})]})]}),!te&&z&&P.has(z)&&(()=>{const xe=P.get(z);return b.jsx("div",{className:"bg-white min-h-24",children:xe.loading?b.jsxs("div",{className:"p-3 flex items-center gap-2 text-muted-foreground",children:[b.jsx(ni,{className:"h-4 w-4 animate-spin"}),b.jsx("span",{className:"text-sm",children:"Loading file preview..."})]}):xe.error?b.jsxs("div",{className:"p-3 text-sm text-destructive flex items-center gap-2",children:[b.jsx(na,{className:"h-4 w-4 shrink-0"}),b.jsx("span",{children:xe.error})]}):b.jsx(rD,{code:xe.code,compiler:n,services:i,filePath:z,onOpenEditSession:D})},z)})()]}),b.jsx(iA,{className:"h-full flex-1",ref:K,children:b.jsxs("div",{className:"p-4 space-y-4",children:[Oe.length===0?b.jsxs("div",{className:"text-center text-muted-foreground py-12",children:[b.jsx("img",{src:Wh,alt:"",className:"h-12 w-12 mx-auto mb-4 opacity-50 rounded-full"}),b.jsx("p",{children:"Start a conversation"})]}):Oe.map(xe=>b.jsx(sce,{message:xe},xe.id)),an&&((Jn=Oe[Oe.length-1])==null?void 0:Jn.role)!=="assistant"&&b.jsxs("div",{className:"flex gap-3 justify-start",children:[b.jsxs(lp,{className:"h-8 w-8 shrink-0",children:[b.jsx("img",{src:Wh,alt:"",className:"rounded-full"}),b.jsx(up,{children:"A"})]}),b.jsxs("div",{className:"flex flex-col gap-1",children:[b.jsx("div",{className:"h-5"}),b.jsx("div",{className:"bg-muted rounded-lg px-4 py-2",children:b.jsx(ni,{className:"h-4 w-4 animate-spin"})})]})]})]})})]})]}),Rt&&b.jsxs("div",{className:"px-4 py-2 bg-destructive/10 text-destructive text-sm flex items-center gap-2",children:[b.jsx(na,{className:"h-4 w-4"}),Rt.message]}),b.jsx("div",{className:"p-4 border-t",children:b.jsxs("form",{onSubmit:Pn,className:"flex gap-2 items-end",children:[b.jsx(WR,{value:e,onChange:t,onSubmit:()=>{!an&&e.trim()&&Pn()},placeholder:"Type a message... (Shift+Enter for new line)",disabled:an}),b.jsx(VT,{type:"submit",disabled:an||!e.trim(),className:"shrink-0",children:an?b.jsx(ni,{className:"h-4 w-4 animate-spin"}):b.jsx(bT,{className:"h-4 w-4"})})]})})]}),!A&&b.jsx(wT,{container:N,pillContainer:N,defaultActive:!1,showInspector:!0,onChanges:()=>{},exclude:[".bobbin-pill","[data-bobbin]"]})]}),A&&b.jsx(tD,{isOpen:!0,onClose:()=>L(null),onSaveProject:async xe=>{await Yue(xe),await he()},originalProject:A.project,initialActiveFile:A.initialActiveFile,initialTreePath:A.initialTreePath,apiEndpoint:"/api/edit",initialState:{showPreview:!0,showTree:!0},compile:async xe=>{if(!n)return{success:!0};try{return await n.compile(xe,tce(i),{typescript:!0}),{success:!0}}catch(ft){return{success:!1,error:ft instanceof Error?ft.message:"Compilation failed"}}},renderPreview:xe=>b.jsx(Fx,{code:xe,compiler:n,services:i}),previewLoading:!n})]})})}function hce(){return b.jsx(fce,{})}YP.createRoot(document.getElementById("root")).render(b.jsx(Xs.StrictMode,{children:b.jsx(hce,{})}));
|
|
1490
|
+
`)}`:"";return{success:!1,error:j+Xe}}finally{console.error=U}},[me,t,n]),q=()=>{h(e),g(0)},ie=f!==e,le=T.useMemo(()=>me?b.jsx(Fx,{code:f,compiler:t,services:n,enabled:l&&!o}):te.category==="media"?b.jsx(eD,{content:f,mimeType:te.mimeType,fileName:X}):te.language==="markdown"?b.jsx("div",{className:"p-4 prose prose-sm dark:prose-invert max-w-none",children:b.jsx(qR,{value:f})}):b.jsx(Jc,{content:f,language:te.language}),[me,t,f,te,o,X,n,l]),oe=T.useCallback(async()=>{if(!s){a(!0);return}const he=await P(),D=M(),U=Lc(f,D,he);s({projectId:he,entryFile:D,filePath:r,initialCode:f,initialProject:U})},[s,P,M,f,r]);return b.jsxs(b.Fragment,{children:[b.jsxs("div",{className:"border rounded-lg overflow-hidden min-w-0",children:[b.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-muted/50 border-b rounded-t-lg",children:[b.jsx(R1,{className:"h-4 w-4 text-muted-foreground"}),m>0&&b.jsxs("span",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[b.jsx($9,{className:"h-3 w-3"}),m," edit",m!==1?"s":""]}),b.jsxs("div",{className:"ml-auto flex gap-1",children:[ie&&b.jsx("button",{onClick:q,className:"px-2 py-1 text-xs rounded flex items-center gap-1 hover:bg-muted text-muted-foreground",title:"Revert to original",children:b.jsx(xT,{className:"h-3 w-3"})}),b.jsx("button",{onClick:()=>void oe(),className:"px-2 py-1 text-xs rounded flex items-center gap-1 hover:bg-muted",title:"Edit component",children:b.jsx(ru,{className:"h-3 w-3"})}),b.jsx(ZR,{status:y,onClick:z,disabled:y==="saving",tone:"muted"}),b.jsxs("button",{onClick:()=>c(!l),className:`w-[5rem] px-2 py-1 text-xs rounded flex items-center gap-1 ${l?"bg-primary text-primary-foreground":"hover:bg-primary/20 text-primary"}`,children:[l?b.jsx(gT,{className:"h-3 w-3"}):b.jsx(R1,{className:"h-3 w-3"}),l?"Preview":"Code"]})]})]}),l?b.jsx("div",{className:"bg-white overflow-y-auto overflow-x-hidden max-h-[60vh]",children:le}):b.jsx("div",{className:"bg-muted/30 overflow-auto max-h-[60vh]",children:b.jsx(Jc,{content:f,language:te.language})})]}),b.jsx(tD,{isOpen:o,onClose:(he,D)=>{h(he),g(U=>U+D),a(!1),D>0&&(v("saving"),(async()=>{try{const U=await P(),re=M(),j=Lc(he,re,U);await QS(j),w(he),v("saved")}catch(U){console.warn("[VFS] Failed to save project:",U),v("error")}})())},originalCode:f,compile:K,renderPreview:he=>b.jsx(Fx,{code:he,compiler:t,services:n})})]})}function Lue({children:e,className:t=""}){return b.jsx("span",{className:`inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 ${t}`,children:e})}function jue({children:e,open:t,onOpenChange:n}){return t?b.jsx("div",{className:"fixed inset-0 z-50 bg-black/50",onClick:()=>n==null?void 0:n(!1),children:b.jsx("div",{className:"fixed left-1/2 top-1/2 z-50 w-full max-w-lg -translate-x-1/2 -translate-y-1/2 bg-background p-6 shadow-lg rounded-lg",onClick:r=>r.stopPropagation(),children:e})}):null}function zue({namespaces:e,services:t=[],BadgeComponent:n=Lue,DialogComponent:r=jue,DialogHeaderComponent:i=({children:a})=>b.jsx("div",{className:"flex justify-between items-center mb-4",children:a}),DialogContentComponent:s=({children:a,className:l=""})=>b.jsx("div",{className:l,children:a}),DialogCloseComponent:o=({onClose:a})=>b.jsx("button",{onClick:()=>a==null?void 0:a(),className:"text-muted-foreground hover:text-foreground",children:"×"})}){const[a,l]=T.useState(!1);if(e.length===0)return null;const c=t.reduce((f,h)=>{var m;return(f[m=h.namespace]??(f[m]=[])).push(h),f},{});return b.jsxs(b.Fragment,{children:[b.jsxs("button",{onClick:()=>l(!0),className:"flex items-center gap-2 hover:opacity-80 transition-opacity",children:[b.jsx(X9,{className:"h-4 w-4 text-muted-foreground"}),b.jsxs(n,{className:"text-xs",children:[e.length," service",e.length!==1?"s":""]})]}),b.jsxs(r,{open:a,onOpenChange:l,children:[b.jsxs(i,{children:[b.jsx("h2",{className:"text-lg font-semibold",children:"Services"}),b.jsx(o,{onClose:()=>l(!1)})]}),b.jsx(s,{className:"space-y-3 max-h-96 overflow-auto",children:e.map(f=>{var h;return b.jsxs("details",{open:e.length===1,children:[b.jsxs("summary",{className:"flex items-center gap-2 w-full p-2 rounded bg-muted/50 hover:bg-muted transition-colors cursor-pointer",children:[b.jsx(Wa,{className:"h-4 w-4 text-muted-foreground"}),b.jsx("span",{className:"font-medium text-sm",children:f}),c[f]&&b.jsxs(n,{className:"ml-auto text-xs",children:[c[f].length," tool",c[f].length!==1?"s":""]})]}),b.jsx("div",{className:"ml-6 mt-2 space-y-2",children:((h=c[f])==null?void 0:h.map(m=>b.jsxs("details",{children:[b.jsxs("summary",{className:"flex items-center gap-2 w-full text-left text-sm hover:text-foreground text-muted-foreground transition-colors cursor-pointer",children:[m.parameters&&b.jsx(Wa,{className:"h-3 w-3"}),b.jsx("code",{className:"font-mono text-xs",children:m.procedure}),b.jsx("span",{className:"truncate text-xs opacity-70",children:m.description})]}),m.parameters&&b.jsx("div",{className:"ml-5 mt-1 p-2 rounded border bg-muted/30 overflow-auto max-h-48",children:b.jsx("pre",{className:"text-xs font-mono whitespace-pre-wrap break-words m-0",children:JSON.stringify(m.parameters,null,2)})})]},m.name)))??b.jsx("p",{className:"text-xs text-muted-foreground",children:"No tool details available"})})]},f)})})]})]})}var Fue=/```([a-zA-Z0-9_+-]*)((?:\s+[a-zA-Z_][\w-]*="[^"]*")*)\s*\n([\s\S]*?)```/g,$ue=/```([a-zA-Z0-9_+-]*)((?:\s+[a-zA-Z_][\w-]*="[^"]*")*)\s*\n([\s\S]*)$/,Bue=/([a-zA-Z_][\w-]*)="([^"]*)"/g;function XS(e){const t={};if(!e)return t;const n=new RegExp(Bue.source,"g");let r;for(;(r=n.exec(e))!==null;){const i=r[1],s=r[2];i&&s!==void 0&&(t[i]=s)}return t}function Vue(e,t={}){var f,h;const{filterLanguages:n,includeUnclosed:r=!1}=t,i=[];let s=0;const o=[],a=new RegExp(Fue.source,"g");let l;for(;(l=a.exec(e))!==null;){const m=((f=l[1])==null?void 0:f.toLowerCase())||"",g=XS(l[2]||""),y=l[3]??"",v=!n||n.has(m);o.push({match:l,language:m,content:y,attributes:g,included:v})}for(const{match:m,language:g,content:y,attributes:v,included:k}of o){if(m.index>s){const w=e.slice(s,m.index);w.trim()&&i.push({type:"text",content:w})}s=m.index+m[0].length,k&&i.push({type:"code",content:y,language:g,attributes:v})}const c=e.slice(s);if(r&&c.includes("```")){const m=c.match($ue);if(m){const g=((h=m[1])==null?void 0:h.toLowerCase())||"",y=XS(m[2]||""),v=m[3]??"",k=!n||n.has(g),w=c.indexOf("```");if(w>0){const S=c.slice(0,w);S.trim()&&i.push({type:"text",content:S})}k&&i.push({type:"code",content:v,language:g,attributes:y}),s=e.length}}if(s<e.length){const m=e.slice(s);m.trim()&&i.push({type:"text",content:m})}return i.length===0&&i.push({type:"text",content:e}),i}const Uue="/vfs";let f1=null;function Eu(){if(!f1){const e=new W4({baseUrl:Uue});f1=new q4(e,{sync:!1})}return f1}function ii(e){return e.replace(/^\/+|\/+$/g,"")}function iD(e){const t=ii(e);return!t||!t.includes("/")?"":t.split("/").slice(0,-1).join("/")}function sD(e){const t=ii(e);if(!t)return"";const n=t.split("/");return n[n.length-1]??""}function Hue(e,t){const n=ii(e),r=ii(t);return n?r?`${n}/${r}`:n:r}function Wue(e){const t=ii(e);return t?`${t}/`:""}function que(e){return e.map(t=>({path:t,content:""}))}function Zue(e,t){if(!e)return ii(t);const n=ii(e),r=ii(t),i=`${n}/`;return r.startsWith(i)?r.slice(i.length):r}function Gue(e,t){const n=ii(e),r=ii(t);return n?Hue(n,r):r}async function Jue(e=""){const t=Eu(),n=ii(e);return(await t.readdir(n)).map(i=>({name:i.name,path:n?`${n}/${i.name}`:i.name,isDir:i.isDirectory()})).sort((i,s)=>i.isDir!==s.isDir?i.isDir?-1:1:i.name.localeCompare(s.name))}async function h1(){return Eu().listFiles()}async function e3(e){const t=Eu(),n=ii(e),r=Wue(n),s=(await t.listFiles(n)).filter(a=>r?a.startsWith(r):!0);if(s.length===0)return null;const o=new Map;return await Promise.all(s.map(async a=>{const l=await t.readFile(a),c=Zue(n,a);o.set(c,{path:c,content:l})})),{id:n,entry:O4(o),files:o}}async function p1(e){const t=Eu(),n=ii(e),r=sD(n),i=iD(n);try{const s=await t.readFile(n);return{id:i,entry:r,files:new Map([[r,{path:r,content:s}]])}}catch{return null}}function Kue(e,t){const n=ii(e),r=sD(n);return{id:iD(n),entry:r,files:new Map([[r,{path:r,content:t}]])}}async function Yue(e){const t=Eu();await Promise.all(Array.from(e.files.values()).map(n=>t.writeFile(Gue(e.id,n.path),n.content)))}function Que(e){return Eu().watch("",e)}const Wh="https://raw.githubusercontent.com/AprovanLabs/aprovan.com/main/docs/assets/social-labs.png",jv=T.createContext({compiler:null,namespaces:[]}),Xue=()=>T.useContext(jv).compiler,ece=()=>T.useContext(jv).namespaces;function tce(e){return{name:"preview",version:"1.0.0",platform:"browser",image:"@aprovan/patchwork-image-shadcn",services:e}}const oD=T.createContext(null),nce=()=>T.useContext(oD);function rce({text:e,isStreaming:t}){return b.jsxs(_A,{defaultOpen:t,children:[b.jsxs(EA,{className:"flex items-center gap-2 text-yellow-700 dark:text-yellow-400 hover:opacity-80 w-full",children:[b.jsx(w9,{className:"h-4 w-4"}),b.jsx("span",{className:"text-xs font-medium",children:"Thinking"}),t&&b.jsx(ni,{className:"h-3 w-3 animate-spin"}),b.jsx(Wa,{className:"h-3 w-3 ml-auto transition-transform [[data-state=open]>&]:rotate-180"})]}),b.jsx(CA,{children:b.jsx("div",{className:"mt-2 p-3 rounded border-l-4 border-yellow-500 bg-yellow-50 dark:bg-yellow-950/50",children:b.jsx("p",{className:"text-sm text-muted-foreground italic whitespace-pre-wrap",children:e})})})]})}function ice({toolName:e,state:t,input:n,output:r,errorText:i}){const s=t==="input-streaming"||t==="input-available",o=t==="output-error";return b.jsxs(_A,{className:"my-1 w-full",children:[b.jsxs(EA,{className:"inline-flex items-center gap-2 px-3 py-1 rounded-full border bg-muted/50 hover:bg-muted text-xs transition-colors",children:[b.jsx(oz,{className:"h-3 w-3 text-muted-foreground"}),b.jsx("span",{className:"font-mono",children:e}),b.jsxs("span",{className:"w-3 h-3 flex items-center justify-center",children:[s&&b.jsx(ni,{className:"h-3 w-3 animate-spin text-muted-foreground"}),o&&b.jsx(na,{className:"h-3 w-3 text-destructive"})]}),b.jsx(Wa,{className:"h-3 w-3 text-muted-foreground transition-transform [[data-state=open]>&]:rotate-180"})]}),b.jsxs(CA,{className:"mt-2 p-3 rounded-lg border bg-white space-y-2",children:[n!==void 0&&b.jsxs("div",{children:[b.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Input"}),b.jsx("div",{className:"mt-1 p-2 bg-muted/30 rounded text-xs overflow-auto max-h-48",children:b.jsx("pre",{className:"whitespace-pre-wrap break-words m-0",children:typeof n=="string"?n:JSON.stringify(n,null,2)})})]}),r!==void 0&&b.jsxs("div",{children:[b.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Output"}),b.jsx("div",{className:"mt-1 p-2 bg-muted/30 rounded text-xs overflow-auto max-h-48",children:b.jsx("pre",{className:"whitespace-pre-wrap break-words m-0",children:typeof r=="string"?r:JSON.stringify(r,null,2)})})]}),i&&b.jsxs("div",{className:"text-sm text-destructive flex items-center gap-2",children:[b.jsx(na,{className:"h-4 w-4 shrink-0"}),b.jsx("span",{className:"break-words",children:i})]})]})]})}function sce({message:e}){var r,i;const t=e.role==="user",n=(r=e.parts)==null?void 0:r.some(s=>"state"in s&&(s.state==="input-streaming"||s.state==="input-available"));return b.jsxs("div",{className:`flex gap-3 ${t?"justify-end":"justify-start"}`,children:[!t&&b.jsxs(lp,{className:"h-8 w-8 shrink-0",children:[b.jsx("img",{src:Wh,alt:"Assistant",className:"rounded-full"}),b.jsx(up,{className:"bg-primary text-primary-foreground",children:"A"})]}),b.jsxs("div",{className:`flex flex-col gap-1 max-w-[80%] min-w-0 ${t?"items-end":"items-start"}`,children:[b.jsxs("div",{className:"flex items-center gap-2 h-5",children:[b.jsx("span",{className:"text-xs text-muted-foreground capitalize",children:e.role}),n&&b.jsxs(J$,{variant:"outline",className:"text-xs",children:[b.jsx(ni,{className:"h-3 w-3 mr-1 animate-spin"}),"streaming"]})]}),b.jsx("div",{className:`rounded-lg px-4 py-2 overflow-hidden w-full ${t?"bg-primary text-primary-foreground":"bg-muted"}`,children:(i=e.parts)==null?void 0:i.map((s,o)=>{if(s.type==="text")return b.jsx(oce,{text:s.text,isUser:t},o);if(s.type==="reasoning")return b.jsx(rce,{text:s.text,isStreaming:s.state==="streaming"},o);if(s.type.startsWith("tool-")||s.type==="dynamic-tool"){const a=s,l=a.toolName??s.type.replace("tool-","");return b.jsx(ice,{toolName:l,state:a.state,input:a.input,output:a.output,errorText:a.errorText},o)}return null})})]}),t&&b.jsx(lp,{className:"h-8 w-8 shrink-0",children:b.jsx(up,{className:"bg-secondary",children:"U"})})]})}function oce({text:e,isUser:t}){const n=nce(),r=Xue(),i=ece();if(t)return b.jsx("div",{className:"prose prose-sm prose-invert prose-p:my-1 prose-headings:my-2 prose-ul:my-1 prose-ol:my-1 prose-li:my-0 prose-pre:my-2 prose-code:before:content-none prose-code:after:content-none",children:b.jsx(Mc,{remarkPlugins:[Oc],children:e})});const s=Vue(e);return b.jsx("div",{className:"prose prose-sm dark:prose-invert prose-p:my-1 prose-headings:my-2 prose-ul:my-1 prose-ol:my-1 prose-li:my-0 prose-pre:my-2 prose-code:before:content-none prose-code:after:content-none",children:s.map((o,a)=>{var l;return o.type==="code"?b.jsx(rD,{code:o.content,compiler:r,services:i,filePath:(l=o.attributes)==null?void 0:l.path,entrypoint:"main.tsx",onOpenEditSession:n??void 0},a):b.jsx(Mc,{remarkPlugins:[Oc],children:o.content},a)})})}const ace="/api/proxy",t3="@aprovan/patchwork-image-shadcn",lce="https://esm.sh",uce="https://esm.sh";function cce(e,t){const n=e.replace(/^\/+|\/+$/g,""),r=t.replace(/^\/+|\/+$/g,"");if(!n)return r;const i=`${n}/`;return r.startsWith(i)?r.slice(i.length):r}const aD="patchwork:open-tabs";function n3(){try{const e=localStorage.getItem(aD);if(!e)return{paths:[],activePath:null};const t=JSON.parse(e);return{paths:Array.isArray(t.paths)?t.paths:[],activePath:typeof t.activePath=="string"?t.activePath:null}}catch{return{paths:[],activePath:null}}}function dce(e,t){localStorage.setItem(aD,JSON.stringify({paths:e,activePath:t}))}function fce(){var Jn;const[e,t]=T.useState("What's the weather in Houston, Texas like?"),[n,r]=T.useState(null),[i,s]=T.useState([]),[o,a]=T.useState([]),[l,c]=T.useState([]),[f,h]=T.useState(""),[m,g]=T.useState(""),[y,v]=T.useState(0),[k,w]=T.useState(!1),[S,E]=T.useState(null),[N,I]=T.useState(null),[A,L]=T.useState(null),[P,M]=T.useState(()=>{const{paths:xe}=n3();return new Map(xe.map(ft=>[ft,{code:"",loading:!0,error:null}]))}),[z,X]=T.useState(()=>{const{paths:xe,activePath:ft}=n3();return ft&&xe.includes(ft)?ft:xe[0]??null}),[te,me]=T.useState(!1),K=T.useRef(null),q=T.useRef(new Map),[ie,le]=T.useState(()=>{try{const xe=localStorage.getItem("patchwork:pinned-paths");if(!xe)return new Map;const ft=JSON.parse(xe);return ft.length>0&&Array.isArray(ft[0])?new Map(ft):new Map(ft.map(at=>[at,!1]))}catch{return new Map}}),oe=T.useCallback((xe,ft)=>{le(at=>{const Et=new Map(at);return Et.has(xe)?Et.delete(xe):Et.set(xe,ft),localStorage.setItem("patchwork:pinned-paths",JSON.stringify(Array.from(Et))),Et})},[]),he=T.useCallback(async()=>{w(!0),E(null);try{if(m.trim()){const xe=await h1();c(xe)}v(xe=>xe+1)}catch(xe){E(xe instanceof Error?xe.message:"Failed to load workspace")}finally{w(!1)}},[m]);T.useEffect(()=>Que(()=>{v(xe=>xe+1),h1().then(xe=>{m.trim()&&c(xe);const ft=new Set(xe);M(at=>{let Et=!1;const Ut=new Map(at);for(const sn of Ut.keys())ft.has(sn)||(Ut.delete(sn),Et=!0);return Et?Ut:at})}).catch(()=>{})}),[m]),T.useEffect(()=>{m.trim()&&(w(!0),E(null),h1().then(c).catch(xe=>{E(xe instanceof Error?xe.message:"Failed to load workspace")}).finally(()=>w(!1)))},[m]),T.useEffect(()=>{fetch("/api/services").then(xe=>xe.json()).then(xe=>{s(xe.namespaces??[])}).catch(()=>{s([]),a([])}),SZ({image:t3,proxyUrl:ace,cdnBaseUrl:lce,widgetCdnBaseUrl:uce}).then(r).catch(console.error),he()},[]),T.useEffect(()=>{P.forEach((xe,ft)=>{if(!xe.loading)return;const at=(q.current.get(ft)??0)+1;q.current.set(ft,at),p1(ft).then(Et=>{if(q.current.get(ft)!==at)return;if(!Et){M(sn=>{const gn=new Map(sn);return gn.delete(ft),gn});return}const Ut=Et.files.get(Et.entry);M(sn=>{const gn=new Map(sn);return gn.set(ft,{code:(Ut==null?void 0:Ut.content)??"",loading:!1,error:null}),gn})}).catch(()=>{q.current.get(ft)===at&&M(Et=>{const Ut=new Map(Et);return Ut.delete(ft),Ut})})})},[]),T.useEffect(()=>{dce([...P.keys()],z)},[P,z]),T.useEffect(()=>{z!==null&&!P.has(z)&&X([...P.keys()][0]??null)},[P,z]);const D=T.useCallback(async xe=>{const{projectId:ft,filePath:at,entryFile:Et,initialCode:Ut,initialProject:sn}=xe,gn=await e3(ft),ir=at??`${ft}/${Et}`;if(gn){const Mn=cce(ft,ir);h(ir),L({project:gn,initialTreePath:Mn,initialActiveFile:Mn});return}const wi=ir,At=at?Kue(at,Ut):sn;h(wi),L({project:At,initialTreePath:At.entry,initialActiveFile:At.entry})},[]),U=T.useCallback(async(xe,ft)=>{const at=ft?await e3(xe):await p1(xe);at&&(h(xe),L({project:at,initialTreePath:at.entry,initialActiveFile:at.entry}))},[]),re=T.useCallback(xe=>{h(xe),X(xe),me(!1),M(at=>{if(at.has(xe))return at;const Et=new Map(at);return Et.set(xe,{code:"",loading:!0,error:null}),Et});const ft=(q.current.get(xe)??0)+1;q.current.set(xe,ft),p1(xe).then(at=>{if(q.current.get(xe)!==ft)return;if(!at){M(Ut=>{const sn=new Map(Ut);return sn.set(xe,{code:"",loading:!1,error:"Failed to load file preview"}),sn});return}const Et=at.files.get(at.entry);M(Ut=>{const sn=new Map(Ut);return sn.set(xe,{code:(Et==null?void 0:Et.content)??"",loading:!1,error:null}),sn})}).catch(at=>{q.current.get(xe)===ft&&M(Et=>{const Ut=new Map(Et);return Ut.set(xe,{code:"",loading:!1,error:at instanceof Error?at.message:"Failed to load file preview"}),Ut})})},[]),j=T.useCallback(xe=>{M(ft=>{const at=new Map(ft);return at.delete(xe),at}),X(ft=>{if(ft!==xe)return ft;const at=[...P.keys()],Et=at.indexOf(xe);return at.length<=1?null:at[Et>0?Et-1:Et+1]??null})},[P]),Xe=T.useCallback(()=>{M(new Map),X(null)},[]),F=T.useMemo(()=>{const xe=m.trim().toLowerCase();return xe?l.filter(ft=>ft.toLowerCase().includes(xe)):l},[l,m]),be=T.useMemo(()=>({compiler:n,namespaces:i}),[n,i]),Ie=T.useMemo(()=>new cT({body:()=>({metadata:{patchwork:{compilers:[t3]}}})}),[]),{messages:Oe,sendMessage:_e,status:Be,error:Rt}=m9({transport:Ie}),an=Be==="submitted"||Be==="streaming",Pn=T.useCallback(xe=>{xe==null||xe.preventDefault(),e.trim()&&(_e({text:e}),t(""))},[e,_e]);return T.useEffect(()=>{var xe;(xe=K.current)==null||xe.scrollTo({top:K.current.scrollHeight,behavior:"smooth"})},[Oe]),b.jsx(jv.Provider,{value:be,children:b.jsxs(oD.Provider,{value:D,children:[b.jsxs("div",{className:"flex flex-col h-screen max-w-6xl mx-auto p-4",ref:I,children:[b.jsxs(mA,{className:"flex-1 flex flex-col min-h-0 overflow-hidden border",children:[b.jsx(gA,{className:"border-b py-3",children:b.jsxs(yA,{className:"flex items-center gap-3",children:[b.jsx("img",{src:Wh,alt:"Aprovan",className:"h-8 w-8 rounded-full"}),b.jsx("span",{className:"text-lg",children:"patchwork"}),b.jsx(zue,{namespaces:i,services:o,DialogComponent:({open:xe,onOpenChange:ft,children:at})=>b.jsx(a7,{open:xe??!1,onOpenChange:ft??(()=>{}),children:at}),DialogHeaderComponent:l7,DialogContentComponent:u7,DialogCloseComponent:({onClose:xe})=>b.jsx(c7,{onClose:xe??(()=>{})})})]})}),b.jsxs(xA,{className:"flex-1 p-0 min-h-0 flex",children:[b.jsxs("div",{className:"w-64 border-r bg-muted/20 min-h-0 flex flex-col",children:[b.jsxs("div",{className:"px-3 py-2 border-b flex items-center gap-2 text-xs font-medium uppercase tracking-wide text-muted-foreground",children:[b.jsx("span",{children:"Workspace"}),b.jsx("button",{onClick:()=>void he(),className:"ml-auto p-1 rounded hover:bg-muted",title:"Refresh workspace",children:b.jsx(Z9,{className:`h-3 w-3 ${k?"animate-spin":""}`})})]}),b.jsx("div",{className:"p-2 border-b",children:b.jsx(UT,{value:m,onChange:xe=>g(xe.target.value),placeholder:"Filter files...",className:"h-8"})}),S?b.jsx("div",{className:"p-3 text-xs text-destructive",children:S}):m.trim()?b.jsx(zx,{files:que(F),activePath:f,onSelectFile:re,onSelectDirectory:h,onOpenInEditor:U,openInEditorMode:"all",openInEditorTitle:"Edit",pinnedPaths:ie,onTogglePin:oe,title:"Files"}):b.jsx(zx,{files:[],activePath:f,onSelectFile:re,onSelectDirectory:h,onOpenInEditor:U,openInEditorMode:"all",openInEditorTitle:"Edit",directoryLoader:Jue,pageSize:10,reloadToken:y,pinnedPaths:ie,onTogglePin:oe,title:"Files"})]}),b.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",children:[P.size>0&&b.jsxs("div",{className:"border-b bg-muted/10",children:[b.jsxs("div",{className:"flex items-center border-b bg-muted/30",children:[b.jsx("div",{className:"flex-1 flex items-center overflow-x-auto min-w-0",children:[...P.entries()].map(([xe])=>{const ft=xe.split("/").pop()??xe,at=xe===z;return b.jsxs("button",{onClick:()=>{X(xe),h(xe),me(!1)},className:`group relative flex items-center gap-1.5 px-3 py-1.5 text-xs border-r shrink-0 max-w-[180px] ${at?"bg-background text-foreground border-b-2 border-b-primary":"text-muted-foreground hover:bg-muted/50"}`,title:xe,children:[b.jsx("span",{className:"truncate",children:ft}),b.jsx("span",{role:"button",onClick:Et=>{Et.stopPropagation(),j(xe)},className:"shrink-0 p-0.5 rounded hover:bg-muted-foreground/20 opacity-0 group-hover:opacity-100 transition-opacity",title:"Close tab",children:b.jsx(ad,{className:"h-3 w-3"})})]},xe)})}),b.jsxs("div",{className:"flex items-center gap-0.5 px-1 shrink-0",children:[b.jsx("button",{onClick:()=>me(xe=>!xe),className:"p-1 rounded hover:bg-muted",title:te?"Expand preview":"Collapse preview",children:te?b.jsx(Wa,{className:"h-3.5 w-3.5"}):b.jsx(V9,{className:"h-3.5 w-3.5"})}),b.jsx("button",{onClick:Xe,className:"p-1 rounded hover:bg-muted",title:"Close all tabs",children:b.jsx(ad,{className:"h-3.5 w-3.5"})})]})]}),!te&&z&&P.has(z)&&(()=>{const xe=P.get(z);return b.jsx("div",{className:"bg-white min-h-24",children:xe.loading?b.jsxs("div",{className:"p-3 flex items-center gap-2 text-muted-foreground",children:[b.jsx(ni,{className:"h-4 w-4 animate-spin"}),b.jsx("span",{className:"text-sm",children:"Loading file preview..."})]}):xe.error?b.jsxs("div",{className:"p-3 text-sm text-destructive flex items-center gap-2",children:[b.jsx(na,{className:"h-4 w-4 shrink-0"}),b.jsx("span",{children:xe.error})]}):b.jsx(rD,{code:xe.code,compiler:n,services:i,filePath:z,onOpenEditSession:D})},z)})()]}),b.jsx(iA,{className:"h-full flex-1",ref:K,children:b.jsxs("div",{className:"p-4 space-y-4",children:[Oe.length===0?b.jsxs("div",{className:"text-center text-muted-foreground py-12",children:[b.jsx("img",{src:Wh,alt:"",className:"h-12 w-12 mx-auto mb-4 opacity-50 rounded-full"}),b.jsx("p",{children:"Start a conversation"})]}):Oe.map(xe=>b.jsx(sce,{message:xe},xe.id)),an&&((Jn=Oe[Oe.length-1])==null?void 0:Jn.role)!=="assistant"&&b.jsxs("div",{className:"flex gap-3 justify-start",children:[b.jsxs(lp,{className:"h-8 w-8 shrink-0",children:[b.jsx("img",{src:Wh,alt:"",className:"rounded-full"}),b.jsx(up,{children:"A"})]}),b.jsxs("div",{className:"flex flex-col gap-1",children:[b.jsx("div",{className:"h-5"}),b.jsx("div",{className:"bg-muted rounded-lg px-4 py-2",children:b.jsx(ni,{className:"h-4 w-4 animate-spin"})})]})]})]})})]})]}),Rt&&b.jsxs("div",{className:"px-4 py-2 bg-destructive/10 text-destructive text-sm flex items-center gap-2",children:[b.jsx(na,{className:"h-4 w-4"}),Rt.message]}),b.jsx("div",{className:"p-4 border-t",children:b.jsxs("form",{onSubmit:Pn,className:"flex gap-2 items-end",children:[b.jsx(WR,{value:e,onChange:t,onSubmit:()=>{!an&&e.trim()&&Pn()},placeholder:"Type a message... (Shift+Enter for new line)",disabled:an}),b.jsx(VT,{type:"submit",disabled:an||!e.trim(),className:"shrink-0",children:an?b.jsx(ni,{className:"h-4 w-4 animate-spin"}):b.jsx(bT,{className:"h-4 w-4"})})]})})]}),!A&&b.jsx(wT,{container:N,pillContainer:N,defaultActive:!1,showInspector:!0,onChanges:()=>{},exclude:[".bobbin-pill","[data-bobbin]"]})]}),A&&b.jsx(tD,{isOpen:!0,onClose:()=>L(null),onSaveProject:async xe=>{await Yue(xe),await he()},originalProject:A.project,initialActiveFile:A.initialActiveFile,initialTreePath:A.initialTreePath,apiEndpoint:"/api/edit",initialState:{showPreview:!0,showTree:!0},compile:async xe=>{if(!n)return{success:!0};try{return await n.compile(xe,tce(i),{typescript:!0}),{success:!0}}catch(ft){return{success:!1,error:ft instanceof Error?ft.message:"Compilation failed"}}},renderPreview:xe=>b.jsx(Fx,{code:xe,compiler:n,services:i}),previewLoading:!n})]})})}function hce(){return b.jsx(fce,{})}YP.createRoot(document.getElementById("root")).render(b.jsx(Xs.StrictMode,{children:b.jsx(hce,{})}));
|
package/dist/index.html
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
href="https://raw.githubusercontent.com/AprovanLabs/aprovan.com/main/docs/assets/social-labs.png"
|
|
10
10
|
/>
|
|
11
11
|
<title>Patchwork Chat</title>
|
|
12
|
-
<script type="module" crossorigin src="/assets/index-
|
|
12
|
+
<script type="module" crossorigin src="/assets/index-Cjs5j4Ri.js"></script>
|
|
13
13
|
<link rel="stylesheet" crossorigin href="/assets/index-jHPB7pV3.css">
|
|
14
14
|
</head>
|
|
15
15
|
<body class="min-h-screen bg-background font-sans antialiased">
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aprovan/patchwork-chat",
|
|
3
|
-
"version": "0.1.0-dev.
|
|
3
|
+
"version": "0.1.0-dev.f456953",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@ai-sdk/react": "^3.0.69",
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"remark-gfm": "^4.0.1",
|
|
25
25
|
"tailwind-merge": "^3.4.0",
|
|
26
26
|
"tiptap-markdown": "^0.9.0",
|
|
27
|
-
"@aprovan/bobbin": "0.1.0-dev.
|
|
28
|
-
"@aprovan/patchwork-
|
|
29
|
-
"@aprovan/
|
|
30
|
-
"@aprovan/
|
|
27
|
+
"@aprovan/bobbin": "0.1.0-dev.f456953",
|
|
28
|
+
"@aprovan/patchwork-editor": "0.1.2-dev.f456953",
|
|
29
|
+
"@aprovan/stitchery": "0.1.0-dev.f456953",
|
|
30
|
+
"@aprovan/patchwork-compiler": "0.1.2-dev.f456953"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@aprovan/copilot-proxy": "0.1.0",
|