const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/docx-preview-DAkAGQCn.js","assets/jszip.min-Ck-YHtwS.js","assets/vendor-mini-lit-CpUQub-j.js","assets/vendor-lit-B2r-dKc0.js","assets/vendor-lucide-B9Yl1Gez.js","assets/vendor-marked-_iteVaMm.js"])))=>i.map(i=>d[i]);
import{i as K,b as a,r as A,a as m,t as T,e as M,n as w,c as ge,o as j}from"./vendor-lit-B2r-dKc0.js";import{e as L,i as c,a as k,H as g,j as ve,t as _e,p as be,f as xe,g as we,x as ye,h as Ee,k as $e,P as se,C as Y,B as fe,l as J}from"./vendor-mini-lit-CpUQub-j.js";import{_ as Ae,O as ee,S as q}from"./ident-CvQrffF1.js";import{U as Te}from"./unsafe-qoGQrK2y.js";import{av as Ce,aw as Re,ax as Pe,ay as Oe,az as Le,aA as De,aB as Ie,aC as ke,aD as O,aE as F}from"./app-session-runtime-CeFJDILJ.js";import{_ as l}from"./app-review-C3CmcSYC.js";import"./SandboxedIframe-B6fsNF9g.js";import{e as Me,aa as je,aj as Ne,au as Fe,av as Ve,X as He,C as Se,b as Ue,a9 as b}from"./vendor-lucide-B9Yl1Gez.js";import{h as Be,a as qe}from"./index-DV9GoJhq.js";import"./vendor-marked-_iteVaMm.js";import"./app-routing-C_r2pdnC.js";import"./app-message-reducer-wATqnZGf.js";import"./vendor-sortable-B1o3v0Qs.js";import"./app-inbox-CaZD85aD.js";import"./app-panel-workspace-C3XDRCgE.js";import"./app-pr-walkthrough-WipZACSB.js";class D extends K{constructor(){super(...arguments),this.filename=""}createRenderRoot(){return this}}var We=Object.defineProperty,ze=Object.getOwnPropertyDescriptor,oe=(e,t,n,r)=>{for(var i=r>1?void 0:r?ze(t,n):t,s=e.length-1,o;s>=0;s--)(o=e[s])&&(i=(r?o(t,n,i):o(i))||i);return r&&i&&We(t,n,i),i};let te=null;async function Ge(){return te||(te=l(()=>import("./docx-preview-DAkAGQCn.js"),__vite__mapDeps([0,1,2,3,4,5]))),te}let V=class extends D{constructor(){super(...arguments),this._content="",this.error=null}get content(){return this._content}set content(e){this._content=e,this.error=null,this.requestUpdate()}createRenderRoot(){return this}connectedCallback(){super.connectedCallback(),this.style.display="block",this.style.height="100%"}base64ToArrayBuffer(e){let t=e;if(e.startsWith("data:")){const i=e.match(/base64,(.+)/);i&&(t=i[1])}const n=atob(t),r=new Uint8Array(n.length);for(let i=0;i<n.length;i++)r[i]=n.charCodeAt(i);return r.buffer}decodeBase64(){let e=this._content;if(this._content.startsWith("data:")){const r=this._content.match(/base64,(.+)/);r&&(e=r[1])}const t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return n}getHeaderButtons(){return a`
			<div class="flex items-center gap-1">
				${L({content:this.decodeBase64(),filename:this.filename,mimeType:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",title:c("Download")})}
			</div>
		`}async updated(e){super.updated(e),e.has("_content")&&this._content&&!this.error&&await this.renderDocx()}async renderDocx(){const e=this.querySelector("#docx-container");if(!(!e||!this._content))try{const{renderAsync:t}=await Ge(),n=this.base64ToArrayBuffer(this._content);e.innerHTML="";const r=document.createElement("div");r.className="docx-wrapper-custom",e.appendChild(r),await t(n,r,void 0,{className:"docx",inWrapper:!0,ignoreWidth:!0,ignoreHeight:!1,ignoreFonts:!1,breakPages:!0,ignoreLastRenderedPageBreak:!0,experimental:!1,trimXmlDeclaration:!0,useBase64URL:!1,renderHeaders:!0,renderFooters:!0,renderFootnotes:!0,renderEndnotes:!0});const i=document.createElement("style");i.textContent=`
				#docx-container {
					padding: 0;
				}

				#docx-container .docx-wrapper-custom {
					max-width: 100%;
					overflow-x: auto;
				}

				#docx-container .docx-wrapper {
					max-width: 100% !important;
					margin: 0 !important;
					background: transparent !important;
					padding: 0em !important;
				}

				#docx-container .docx-wrapper > section.docx {
					box-shadow: none !important;
					border: none !important;
					border-radius: 0 !important;
					margin: 0 !important;
					padding: 2em !important;
					background: white !important;
					color: black !important;
					max-width: 100% !important;
					width: 100% !important;
					min-width: 0 !important;
					overflow-x: auto !important;
				}

				/* Fix tables and wide content */
				#docx-container table {
					max-width: 100% !important;
					width: auto !important;
					overflow-x: auto !important;
					display: block !important;
				}

				#docx-container img {
					max-width: 100% !important;
					height: auto !important;
				}

				/* Fix paragraphs and text */
				#docx-container p,
				#docx-container span,
				#docx-container div {
					max-width: 100% !important;
					word-wrap: break-word !important;
					overflow-wrap: break-word !important;
				}

				/* Hide page breaks in web view */
				#docx-container .docx-page-break {
					display: none !important;
				}
			`,e.appendChild(i)}catch(t){console.error("Error rendering DOCX:",t),this.error=t?.message||c("Failed to load document")}}render(){return this.error?a`
				<div class="h-full flex items-center justify-center bg-background p-4">
					<div class="bg-destructive/10 border border-destructive text-destructive p-4 rounded-lg max-w-2xl">
						<div class="font-medium mb-1">${c("Error loading document")}</div>
						<div class="text-sm opacity-90">${this.error}</div>
					</div>
				</div>
			`:a`
			<div class="h-full flex flex-col bg-background overflow-auto">
				<div id="docx-container" class="flex-1 overflow-auto"></div>
			</div>
		`}};oe([m({type:String})],V.prototype,"_content",2);oe([A()],V.prototype,"error",2);V=oe([T("docx-artifact")],V);var Ze=Object.defineProperty,Ke=Object.getOwnPropertyDescriptor,ue=(e,t,n,r)=>{for(var i=r>1?void 0:r?Ke(t,n):t,s=e.length-1,o;s>=0;s--)(o=e[s])&&(i=(r?o(t,n,i):o(i))||i);return r&&i&&Ze(t,n,i),i};let z=class extends D{constructor(){super(...arguments),this._content=""}get content(){return this._content}set content(e){this._content=e,this.requestUpdate()}createRenderRoot(){return this}connectedCallback(){super.connectedCallback(),this.style.display="block",this.style.height="100%"}decodeBase64(){let e=this._content;if(this._content.startsWith("data:")){const r=this._content.match(/base64,(.+)/);r&&(e=r[1])}const t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return n}getMimeType(){const e=this.filename.split(".").pop()?.toLowerCase();return{pdf:"application/pdf",zip:"application/zip",tar:"application/x-tar",gz:"application/gzip",rar:"application/vnd.rar","7z":"application/x-7z-compressed",mp3:"audio/mpeg",mp4:"video/mp4",avi:"video/x-msvideo",mov:"video/quicktime",wav:"audio/wav",ogg:"audio/ogg",json:"application/json",xml:"application/xml",bin:"application/octet-stream"}[e||""]||"application/octet-stream"}getHeaderButtons(){return a`
			<div class="flex items-center gap-1">
				${L({content:this.decodeBase64(),filename:this.filename,mimeType:this.getMimeType(),title:c("Download")})}
			</div>
		`}render(){return a`
			<div class="h-full flex items-center justify-center bg-background p-8">
				<div class="text-center max-w-md">
					<div class="text-muted-foreground text-lg mb-4">
						<svg
							xmlns="http://www.w3.org/2000/svg"
							class="h-16 w-16 mx-auto mb-4 text-muted-foreground/50"
							fill="none"
							viewBox="0 0 24 24"
							stroke="currentColor"
						>
							<path
								stroke-linecap="round"
								stroke-linejoin="round"
								stroke-width="1.5"
								d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"
							/>
						</svg>
						<div class="font-medium text-foreground mb-2">${this.filename}</div>
						<p class="text-sm">
							${c("Preview not available for this file type.")} ${c("Click the download button above to view it on your computer.")}
						</p>
					</div>
				</div>
			</div>
		`}};ue([m({type:String})],z.prototype,"_content",2);z=ue([T("generic-artifact")],z);var Ye=Object.defineProperty,Xe=Object.getOwnPropertyDescriptor,X=(e,t,n,r)=>{for(var i=r>1?void 0:r?Xe(t,n):t,s=e.length-1,o;s>=0;s--)(o=e[s])&&(i=(r?o(t,n,i):o(i))||i);return r&&i&&Ye(t,n,i),i};let H=class extends K{constructor(){super(...arguments),this.logs=[],this.expanded=!1,this.autoscroll=!0,this.logsContainerRef=M()}createRenderRoot(){return this}updated(){this.autoscroll&&this.expanded&&this.logsContainerRef.value&&(this.logsContainerRef.value.scrollTop=this.logsContainerRef.value.scrollHeight)}getLogsText(){return this.logs.map(e=>`[${e.type}] ${e.text}`).join(`
`)}render(){const e=this.logs.filter(n=>n.type==="error").length,t=e>0?`${c("console")} (${e} ${e===1?"error":"errors"})`:`${c("console")} (${this.logs.length})`;return a`
			<div class="border-t border-border p-2">
				<div class="flex items-center gap-2 w-full">
					<button
						@click=${()=>{this.expanded=!this.expanded}}
						class="flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground transition-colors flex-1 text-left"
					>
						${k(this.expanded?Me:je,"sm")}
						<span>${t}</span>
					</button>
					${this.expanded?a`
							<button
								@click=${()=>{this.autoscroll=!this.autoscroll}}
								class="p-1 rounded transition-colors ${this.autoscroll?"bg-accent text-accent-foreground":"hover:bg-muted"}"
								title=${this.autoscroll?c("Autoscroll enabled"):c("Autoscroll disabled")}
							>
								${k(this.autoscroll?Ne:Fe,"sm")}
							</button>
							<copy-button .text=${this.getLogsText()} title=${c("Copy logs")} .showText=${!1} class="!bg-transparent hover:!bg-accent"></copy-button>
						`:""}
				</div>
				${this.expanded?a`
						<div class="max-h-48 overflow-y-auto space-y-1 mt-2" ${w(this.logsContainerRef)}>
							${ge(this.logs,(n,r)=>r,n=>a`
									<div class="text-xs font-mono ${n.type==="error"?"text-destructive":"text-muted-foreground"}">
										[${n.type}] ${n.text}
									</div>
								`)}
						</div>
					`:""}
			</div>
		`}};X([m({attribute:!1})],H.prototype,"logs",2);X([A()],H.prototype,"expanded",2);X([A()],H.prototype,"autoscroll",2);H=X([T("artifact-console")],H);function Qe(e){const t=e.regex,n={begin:/<\/?[A-Za-z_]/,end:">",subLanguage:"xml",relevance:0},r={begin:"^[-\\*]{3,}",end:"$"},i={className:"code",variants:[{begin:"(`{3,})[^`](.|\\n)*?\\1`*[ ]*"},{begin:"(~{3,})[^~](.|\\n)*?\\1~*[ ]*"},{begin:"```",end:"```+[ ]*$"},{begin:"~~~",end:"~~~+[ ]*$"},{begin:"`.+?`"},{begin:"(?=^( {4}|\\t))",contains:[{begin:"^( {4}|\\t)",end:"(\\n)$"}],relevance:0}]},s={className:"bullet",begin:"^[ 	]*([*+-]|(\\d+\\.))(?=\\s+)",end:"\\s+",excludeEnd:!0},o={begin:/^\[[^\n]+\]:/,returnBegin:!0,contains:[{className:"symbol",begin:/\[/,end:/\]/,excludeBegin:!0,excludeEnd:!0},{className:"link",begin:/:\s*/,end:/$/,excludeBegin:!0}]},p=/[A-Za-z][A-Za-z0-9+.-]*/,u={variants:[{begin:/\[.+?\]\[.*?\]/,relevance:0},{begin:/\[.+?\]\(((data|javascript|mailto):|(?:http|ftp)s?:\/\/).*?\)/,relevance:2},{begin:t.concat(/\[.+?\]\(/,p,/:\/\/.*?\)/),relevance:2},{begin:/\[.+?\]\([./?&#].*?\)/,relevance:1},{begin:/\[.*?\]\(.*?\)/,relevance:0}],returnBegin:!0,contains:[{match:/\[(?=\])/},{className:"string",relevance:0,begin:"\\[",end:"\\]",excludeBegin:!0,returnEnd:!0},{className:"link",relevance:0,begin:"\\]\\(",end:"\\)",excludeBegin:!0,excludeEnd:!0},{className:"symbol",relevance:0,begin:"\\]\\[",end:"\\]",excludeBegin:!0,excludeEnd:!0}]},d={className:"strong",contains:[],variants:[{begin:/_{2}(?!\s)/,end:/_{2}/},{begin:/\*{2}(?!\s)/,end:/\*{2}/}]},f={className:"emphasis",contains:[],variants:[{begin:/\*(?![*\s])/,end:/\*/},{begin:/_(?![_\s])/,end:/_/,relevance:0}]},x=e.inherit(d,{contains:[]}),E=e.inherit(f,{contains:[]});d.contains.push(E),f.contains.push(x);let h=[n,u];return[d,f,x,E].forEach(P=>{P.contains=P.contains.concat(h)}),h=h.concat(d,f),{name:"Markdown",aliases:["md","mkdown","mkd"],contains:[{className:"section",variants:[{begin:"^#{1,6}",end:"$",contains:h},{begin:"(?=^.+?\\n[=-]{2,}$)",contains:[{begin:"^[=-]*$"},{begin:"^",end:"\\n",contains:h}]}]},n,s,d,f,{className:"quote",begin:"^>\\s+",contains:h,end:"$"},i,r,u,o,{scope:"literal",match:/&([a-zA-Z0-9]+|#[0-9]{1,7}|#[Xx][0-9a-fA-F]{1,6});/}]}}function Je(e){const t="true false yes no null",n="[\\w#;/?:@&=+$,.~*'()[\\]]+",r={className:"attr",variants:[{begin:/[\w*@][\w*@ :()\./-]*:(?=[ \t]|$)/},{begin:/"[\w*@][\w*@ :()\./-]*":(?=[ \t]|$)/},{begin:/'[\w*@][\w*@ :()\./-]*':(?=[ \t]|$)/}]},i={className:"template-variable",variants:[{begin:/\{\{/,end:/\}\}/},{begin:/%\{/,end:/\}/}]},s={className:"string",relevance:0,begin:/'/,end:/'/,contains:[{match:/''/,scope:"char.escape",relevance:0}]},o={className:"string",relevance:0,variants:[{begin:/"/,end:/"/},{begin:/\S+/}],contains:[e.BACKSLASH_ESCAPE,i]},p=e.inherit(o,{variants:[{begin:/'/,end:/'/,contains:[{begin:/''/,relevance:0}]},{begin:/"/,end:/"/},{begin:/[^\s,{}[\]]+/}]}),E={className:"number",begin:"\\b"+"[0-9]{4}(-[0-9][0-9]){0,2}"+"([Tt \\t][0-9][0-9]?(:[0-9][0-9]){2})?"+"(\\.[0-9]*)?"+"([ \\t])*(Z|[-+][0-9][0-9]?(:[0-9][0-9])?)?"+"\\b"},h={end:",",endsWithParent:!0,excludeEnd:!0,keywords:t,relevance:0},v={begin:/\{/,end:/\}/,contains:[h],illegal:"\\n",relevance:0},_={begin:"\\[",end:"\\]",contains:[h],illegal:"\\n",relevance:0},R=[r,{className:"meta",begin:"^---\\s*$",relevance:10},{className:"string",begin:"[\\|>]([1-9]?[+-])?[ ]*\\n( +)[^ ][^\\n]*\\n(\\2[^\\n]+\\n?)*"},{begin:"<%[%=-]?",end:"[%-]?%>",subLanguage:"ruby",excludeBegin:!0,excludeEnd:!0,relevance:0},{className:"type",begin:"!\\w+!"+n},{className:"type",begin:"!<"+n+">"},{className:"type",begin:"!"+n},{className:"type",begin:"!!"+n},{className:"meta",begin:"&"+e.UNDERSCORE_IDENT_RE+"$"},{className:"meta",begin:"\\*"+e.UNDERSCORE_IDENT_RE+"$"},{className:"bullet",begin:"-(?=[ ]|$)",relevance:0},e.HASH_COMMENT_MODE,{beginKeywords:t,keywords:{literal:t}},E,{className:"number",begin:e.C_NUMBER_RE+"\\b",relevance:0},v,_,s,o],P=[...R];return P.pop(),P.push(p),h.contains=P,{name:"YAML",case_insensitive:!0,aliases:["yml"],contains:R}}g.registerLanguage("javascript",ve);g.registerLanguage("typescript",_e);g.registerLanguage("python",be);g.registerLanguage("bash",xe);g.registerLanguage("json",we);g.registerLanguage("yaml",Je);g.registerLanguage("xml",ye);g.registerLanguage("css",Ee);g.registerLanguage("markdown",Qe);g.registerLanguage("sql",$e);g.registerAliases(["html"],{languageName:"xml"});const et={c:()=>l(()=>import("./c-D2F1sQUL.js"),[]),cpp:()=>l(()=>import("./cpp-Bm3ii6kY.js"),[]),batch:()=>l(()=>import("./dos-BTl-L7Ml.js"),[]),dos:()=>l(()=>import("./dos-BTl-L7Ml.js"),[]),csharp:()=>l(()=>import("./csharp-BNpuYZMG.js"),[]),diff:()=>l(()=>import("./diff-DiTmLxSS.js"),[]),django:()=>l(()=>import("./django-BJKGRTHq.js"),[]),dockerfile:()=>l(()=>import("./dockerfile-Co-AyC30.js"),[]),elixir:()=>l(()=>import("./elixir-DLGFH_Et.js"),[]),elm:()=>l(()=>import("./elm-3GArE9D5.js"),[]),erlang:()=>l(()=>import("./erlang-CnxNE6gd.js"),[]),fsharp:()=>l(()=>import("./fsharp-5RlFyxH8.js"),[]),go:()=>l(()=>import("./go-BPx_y7j8.js"),[]),gradle:()=>l(()=>import("./gradle-CtZu4a3z.js"),[]),graphql:()=>l(()=>import("./graphql-DPQANhhf.js"),[]),groovy:()=>l(()=>import("./groovy-DVpOnIQ7.js"),[]),haskell:()=>l(()=>import("./haskell-DGfXQlJ3.js"),[]),ini:()=>l(()=>import("./ini-B3BVgEsG.js"),[]),java:()=>l(()=>import("./java-B5VKqtH2.js"),[]),kotlin:()=>l(()=>import("./kotlin-Cw-eF_bm.js"),[]),latex:()=>l(()=>import("./latex-lHs7bxnR.js"),[]),less:()=>l(()=>import("./less-DfF15LUi.js"),[]),lua:()=>l(()=>import("./lua-mmu39Jmf.js"),[]),makefile:()=>l(()=>import("./makefile-BoJC05FH.js"),[]),nginx:()=>l(()=>import("./nginx-CwEijJ2O.js"),[]),objectivec:()=>l(()=>import("./objectivec-BI0B0W2W.js"),[]),ocaml:()=>l(()=>import("./ocaml-D3nKyFNx.js"),[]),perl:()=>l(()=>import("./perl-BWtAWCfC.js"),[]),php:()=>l(()=>import("./php-CRdd4dfS.js"),[]),plaintext:()=>l(()=>import("./plaintext-CPM70vnn.js"),[]),powershell:()=>l(()=>import("./powershell-BTRu8Ib4.js"),[]),prolog:()=>l(()=>import("./prolog-BuZcL2r6.js"),[]),properties:()=>l(()=>import("./properties-CZgCE6EI.js"),[]),protobuf:()=>l(()=>import("./protobuf-C6VLidOE.js"),[]),puppet:()=>l(()=>import("./puppet-CJHFDVnx.js"),[]),r:()=>l(()=>import("./r-DWz4c2Y4.js"),[]),ruby:()=>l(()=>import("./ruby-7T4ktxyv.js"),[]),rust:()=>l(()=>import("./rust-HC3MBUhY.js"),[]),scala:()=>l(()=>import("./scala-CTk4KSn7.js"),[]),scheme:()=>l(()=>import("./scheme-Dlczz2HB.js"),[]),scss:()=>l(()=>import("./scss-DZLA7YXz.js"),[]),smalltalk:()=>l(()=>import("./smalltalk-Cdx5PrwE.js"),[]),swift:()=>l(()=>import("./swift-Dn8kKO_1.js"),[]),tcl:()=>l(()=>import("./tcl-BdSax8nO.js"),[]),toml:()=>l(()=>import("./ini-B3BVgEsG.js"),[]),twig:()=>l(()=>import("./twig-CO1mxmAv.js"),[]),vala:()=>l(()=>import("./vala-BPN8917S.js"),[]),verilog:()=>l(()=>import("./verilog-B1GjPiYW.js"),[]),vbnet:()=>l(()=>import("./vbnet-BqSgWHyS.js"),[]),vbscript:()=>l(()=>import("./vbscript-CenSoNQX.js"),[])},ne=new Map,ie=new Set;async function tt(e){if(!e)return!1;if(g.getLanguage(e))return!0;if(ie.has(e))return!1;const t=et[e.toLowerCase()];if(!t)return ie.add(e),!1;let n=ne.get(e);return n||(n=(async()=>{try{const r=await t();return g.registerLanguage(e,r.default),!0}catch{return ie.add(e),!1}finally{ne.delete(e)}})(),ne.set(e,n)),n}function nt(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}var it=Object.defineProperty,rt=Object.getOwnPropertyDescriptor,N=(e,t,n,r)=>{for(var i=r>1?void 0:r?rt(t,n):t,s=e.length-1,o;s>=0;s--)(o=e[s])&&(i=(r?o(t,n,i):o(i))||i);return r&&i&&it(t,n,i),i};let y=class extends D{constructor(){super(...arguments),this.filename="",this.runtimeProviders=[],this._content="",this.logs=[],this.sandboxIframeRef=M(),this.consoleRef=M(),this.viewMode="preview",this._loading=!1}setViewMode(e){this.viewMode=e}getHeaderButtons(){const e=new se;e.mode=this.viewMode,e.addEventListener("mode-change",s=>{this.setViewMode(s.detail)});const t=new Y;t.text=this._content,t.title=c("Copy HTML"),t.showText=!1;const n=this.sandboxIframeRef.value,r=`artifact-${this.filename}`,i=n?.prepareHtmlDocument(r,this._content,this.runtimeProviders||[],{isHtmlArtifact:!0,isStandalone:!0})||this._content;return a`
			<div class="flex items-center gap-2">
				${e}
				${fe({variant:"ghost",size:"sm",onClick:()=>{this.logs=[],this.executeContent(this._content)},title:c("Reload HTML"),children:k(Ve,"sm")})}
				${t}
				${L({content:i,filename:this.filename,mimeType:"text/html",title:c("Download HTML")})}
			</div>
		`}set content(e){const t=this._content;this._content=e,t!==e&&(this.logs=[],this.sandboxIframeRef.value&&e?(this._loading=!0,this.requestUpdate(),this.updateComplete.then(()=>{this.executeContent(e)})):this.requestUpdate())}executeContent(e){const t=this.sandboxIframeRef.value;if(!t)return;this.sandboxUrlProvider&&(t.sandboxUrlProvider=this.sandboxUrlProvider);const n=`artifact-${this.filename}`;this._loadingFallbackTimer&&clearTimeout(this._loadingFallbackTimer);const r={handleMessage:async s=>{s.type==="console"?(this.logs=[...this.logs,{type:s.method==="error"?"error":"log",text:s.text}],this.requestUpdate()):(s.type==="execution-complete"||s.type==="execution-error")&&(this._loading=!1)}};this._loadingFallbackTimer=setTimeout(()=>{this._loading=!1},5e3);let i=e;i.includes("</html>")?i=i.replace("</html>","<script>if (window.complete) window.complete();<\/script></html>"):i+="<script>if (window.complete) window.complete();<\/script>",t.loadContent(n,i,this.runtimeProviders,[r])}get content(){return this._content}firstUpdated(){this._content&&this.sandboxIframeRef.value&&this.executeContent(this._content)}updated(e){super.updated(e),this._content&&this.sandboxIframeRef.value&&this.logs.length===0&&this.executeContent(this._content)}getLogs(){return this.logs.length===0?c("No logs for {filename}").replace("{filename}",this.filename):this.logs.map(e=>`[${e.type}] ${e.text}`).join(`
`)}disconnectedCallback(){super.disconnectedCallback(),this._loadingFallbackTimer&&clearTimeout(this._loadingFallbackTimer);const e=`artifact-${this.filename}`;Ce.unregisterSandbox(e)}render(){return a`
			<div class="h-full flex flex-col">
				<div class="flex-1 overflow-hidden relative">
					<!-- Preview container - always in DOM, just hidden when not active -->
					<div class="absolute inset-0 flex flex-col" style="display: ${this.viewMode==="preview"?"flex":"none"}">
						<sandbox-iframe class="flex-1" ${w(this.sandboxIframeRef)}></sandbox-iframe>
						${this._loading?a`<div style="
								position: absolute; inset: 0; z-index: 10;
								background: rgba(15, 15, 25, 0.85);
								display: flex; align-items: center; justify-content: center;
								pointer-events: none;
							">
								<div style="
									width: 20px; height: 20px;
									border: 2px solid rgba(255,255,255,0.15);
									border-top-color: rgba(255,255,255,0.6);
									border-radius: 50%;
									animation: html-artifact-spin 0.7s linear infinite;
								"></div>
							</div>
							<style>
								@keyframes html-artifact-spin {
									to { transform: rotate(360deg); }
								}
							</style>`:""}
						${this.logs.length>0?a`<artifact-console .logs=${this.logs} ${w(this.consoleRef)}></artifact-console>`:""}
					</div>

					<!-- Code view - always in DOM, just hidden when not active -->
					<div class="absolute inset-0 overflow-auto bg-background" style="display: ${this.viewMode==="code"?"block":"none"}">
						<pre class="m-0 p-4 text-xs"><code class="hljs language-html">${j(g.highlight(this._content,{language:"html"}).value)}</code></pre>
					</div>
				</div>
			</div>
		`}};N([m()],y.prototype,"filename",2);N([m({attribute:!1})],y.prototype,"runtimeProviders",2);N([m({attribute:!1})],y.prototype,"sandboxUrlProvider",2);N([A()],y.prototype,"viewMode",2);N([A()],y.prototype,"_loading",2);y=N([T("html-artifact")],y);var st=Object.defineProperty,ot=Object.getOwnPropertyDescriptor,pe=(e,t,n,r)=>{for(var i=r>1?void 0:r?ot(t,n):t,s=e.length-1,o;s>=0;s--)(o=e[s])&&(i=(r?o(t,n,i):o(i))||i);return r&&i&&st(t,n,i),i};let G=class extends D{constructor(){super(...arguments),this._content=""}get content(){return this._content}set content(e){this._content=e,this.requestUpdate()}createRenderRoot(){return this}connectedCallback(){super.connectedCallback(),this.style.display="block",this.style.height="100%"}getMimeType(){const e=this.filename.split(".").pop()?.toLowerCase();return e==="jpg"||e==="jpeg"?"image/jpeg":e==="gif"?"image/gif":e==="webp"?"image/webp":e==="svg"?"image/svg+xml":e==="bmp"?"image/bmp":e==="ico"?"image/x-icon":"image/png"}getImageUrl(){return this._content.startsWith("data:")?this._content:`data:${this.getMimeType()};base64,${this._content}`}decodeBase64(){let e;if(this._content.startsWith("data:")){const r=this._content.match(/base64,(.+)/);if(r)e=r[1];else return new Uint8Array(0)}else e=this._content;const t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return n}getHeaderButtons(){return a`
			<div class="flex items-center gap-1">
				${L({content:this.decodeBase64(),filename:this.filename,mimeType:this.getMimeType(),title:c("Download")})}
			</div>
		`}render(){return a`
			<div class="h-full flex flex-col bg-background overflow-auto">
				<div class="flex-1 flex items-center justify-center p-4">
					<img
						src="${this.getImageUrl()}"
						alt="${this.filename}"
						class="max-w-full max-h-full object-contain"
						@error=${e=>{const t=e.target;t.src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Ctext x='50' y='50' text-anchor='middle' dominant-baseline='middle' fill='%23999'%3EImage Error%3C/text%3E%3C/svg%3E"}}
					/>
				</div>
			</div>
		`}};pe([m({type:String})],G.prototype,"_content",2);G=pe([T("image-artifact")],G);var at=Object.defineProperty,ct=Object.getOwnPropertyDescriptor,ae=(e,t,n,r)=>{for(var i=r>1?void 0:r?ct(t,n):t,s=e.length-1,o;s>=0;s--)(o=e[s])&&(i=(r?o(t,n,i):o(i))||i);return r&&i&&at(t,n,i),i};let S=class extends D{constructor(){super(...arguments),this.filename="",this._content="",this.viewMode="preview"}get content(){return this._content}set content(e){this._content=e,this.requestUpdate()}createRenderRoot(){return this}setViewMode(e){this.viewMode=e}getHeaderButtons(){const e=new se;e.mode=this.viewMode,e.addEventListener("mode-change",n=>{this.setViewMode(n.detail)});const t=new Y;return t.text=this._content,t.title=c("Copy Markdown"),t.showText=!1,a`
			<div class="flex items-center gap-2">
				${e}
				${t}
				${L({content:this._content,filename:this.filename,mimeType:"text/markdown",title:c("Download Markdown")})}
			</div>
		`}render(){return Re(),a`
			<div class="h-full flex flex-col">
				<div class="flex-1 overflow-auto">
					${this.viewMode==="preview"?a`<div class="p-4"><markdown-block .content=${this.content}></markdown-block></div>`:a`<pre class="m-0 p-4 text-xs whitespace-pre-wrap break-words"><code class="hljs language-markdown">${j(g.highlight(this.content,{language:"markdown",ignoreIllegals:!0}).value)}</code></pre>`}
				</div>
			</div>
		`}};ae([m()],S.prototype,"filename",2);ae([A()],S.prototype,"viewMode",2);S=ae([T("markdown-artifact")],S);var lt=Object.defineProperty,dt=Object.getOwnPropertyDescriptor,ce=(e,t,n,r)=>{for(var i=r>1?void 0:r?dt(t,n):t,s=e.length-1,o;s>=0;s--)(o=e[s])&&(i=(r?o(t,n,i):o(i))||i);return r&&i&&lt(t,n,i),i};let re=null;async function ft(){return re||(re=l(()=>import("./pdf-D9qYOnN8.js"),[]).then(e=>(e.GlobalWorkerOptions.workerSrc=new URL("/assets/pdf.worker.min-Cpi8b8z3.mjs",import.meta.url).toString(),e))),re}let U=class extends D{constructor(){super(...arguments),this._content="",this.error=null,this.currentLoadingTask=null}get content(){return this._content}set content(e){this._content=e,this.error=null,this.requestUpdate()}createRenderRoot(){return this}connectedCallback(){super.connectedCallback(),this.style.display="block",this.style.height="100%"}disconnectedCallback(){super.disconnectedCallback(),this.cleanup()}cleanup(){this.currentLoadingTask&&(this.currentLoadingTask.destroy(),this.currentLoadingTask=null)}base64ToArrayBuffer(e){let t=e;if(e.startsWith("data:")){const i=e.match(/base64,(.+)/);i&&(t=i[1])}const n=atob(t),r=new Uint8Array(n.length);for(let i=0;i<n.length;i++)r[i]=n.charCodeAt(i);return r.buffer}decodeBase64(){let e=this._content;if(this._content.startsWith("data:")){const r=this._content.match(/base64,(.+)/);r&&(e=r[1])}const t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return n}getHeaderButtons(){return a`
			<div class="flex items-center gap-1">
				${L({content:this.decodeBase64(),filename:this.filename,mimeType:"application/pdf",title:c("Download")})}
			</div>
		`}async updated(e){super.updated(e),e.has("_content")&&this._content&&!this.error&&await this.renderPdf()}async renderPdf(){const e=this.querySelector("#pdf-container");if(!e||!this._content)return;let t=null;try{const n=await ft(),r=this.base64ToArrayBuffer(this._content);this.currentLoadingTask&&this.currentLoadingTask.destroy(),this.currentLoadingTask=n.getDocument({data:r}),t=await this.currentLoadingTask.promise,this.currentLoadingTask=null,e.innerHTML="";const i=document.createElement("div");i.className="p-4",e.appendChild(i);for(let s=1;s<=t.numPages;s++){const o=await t.getPage(s),p=document.createElement("div");p.className="mb-4 last:mb-0";const u=document.createElement("canvas"),d=u.getContext("2d"),f=o.getViewport({scale:1.5});if(u.height=f.height,u.width=f.width,u.className="w-full max-w-full h-auto block mx-auto bg-white rounded shadow-sm border border-border",d&&(d.fillStyle="white",d.fillRect(0,0,u.width,u.height)),await o.render({canvasContext:d,viewport:f,canvas:u}).promise,p.appendChild(u),s<t.numPages){const x=document.createElement("div");x.className="h-px bg-border my-4",p.appendChild(x)}i.appendChild(p)}}catch(n){console.error("Error rendering PDF:",n),this.error=n?.message||c("Failed to load PDF")}finally{t&&t.destroy()}}render(){return this.error?a`
				<div class="h-full flex items-center justify-center bg-background p-4">
					<div class="bg-destructive/10 border border-destructive text-destructive p-4 rounded-lg max-w-2xl">
						<div class="font-medium mb-1">${c("Error loading PDF")}</div>
						<div class="text-sm opacity-90">${this.error}</div>
					</div>
				</div>
			`:a`
			<div class="h-full flex flex-col bg-background overflow-auto">
				<div id="pdf-container" class="flex-1 overflow-auto"></div>
			</div>
		`}};ce([m({type:String})],U.prototype,"_content",2);ce([A()],U.prototype,"error",2);U=ce([T("pdf-artifact")],U);var ut=Object.defineProperty,pt=Object.getOwnPropertyDescriptor,le=(e,t,n,r)=>{for(var i=r>1?void 0:r?pt(t,n):t,s=e.length-1,o;s>=0;s--)(o=e[s])&&(i=(r?o(t,n,i):o(i))||i);return r&&i&&ut(t,n,i),i};let B=class extends D{constructor(){super(...arguments),this.filename="",this._content="",this.viewMode="preview"}get content(){return this._content}set content(e){this._content=e,this.requestUpdate()}createRenderRoot(){return this}setViewMode(e){this.viewMode=e}getHeaderButtons(){const e=new se;e.mode=this.viewMode,e.addEventListener("mode-change",n=>{this.setViewMode(n.detail)});const t=new Y;return t.text=this._content,t.title=c("Copy SVG"),t.showText=!1,a`
			<div class="flex items-center gap-2">
				${e}
				${t}
				${L({content:this._content,filename:this.filename,mimeType:"image/svg+xml",title:c("Download SVG")})}
			</div>
		`}render(){return a`
			<div class="h-full flex flex-col">
				<div class="flex-1 overflow-auto">
					${this.viewMode==="preview"?a`<div class="h-full flex items-center justify-center">
								${j(this.content.replace(/<svg(\s|>)/i,(e,t)=>`<svg class="w-full h-full"${t}`))}
							</div>`:a`<pre class="m-0 p-4 text-xs"><code class="hljs language-xml">${j(g.highlight(this.content,{language:"xml",ignoreIllegals:!0}).value)}</code></pre>`}
				</div>
			</div>
		`}};le([m()],B.prototype,"filename",2);le([A()],B.prototype,"viewMode",2);B=le([T("svg-artifact")],B);var ht=Object.defineProperty,mt=Object.getOwnPropertyDescriptor,he=(e,t,n,r)=>{for(var i=r>1?void 0:r?mt(t,n):t,s=e.length-1,o;s>=0;s--)(o=e[s])&&(i=(r?o(t,n,i):o(i))||i);return r&&i&&ht(t,n,i),i};const gt=["js","javascript","ts","typescript","jsx","tsx","py","python","java","c","cpp","cs","php","rb","ruby","go","rust","swift","kotlin","scala","dart","html","css","scss","sass","less","json","xml","yaml","yml","toml","sql","sh","bash","ps1","bat","r","matlab","julia","lua","perl","vue","svelte"];let Z=class extends D{constructor(){super(...arguments),this.filename="",this._content="",this._grammarFetched=new Set}get content(){return this._content}set content(e){this._content=e,this.requestUpdate()}createRenderRoot(){return this}highlightOrEscape(e,t){return g.getLanguage(t)?g.highlight(e,{language:t,ignoreIllegals:!0}).value:(this._grammarFetched.has(t)||(this._grammarFetched.add(t),tt(t).then(n=>{n&&this.requestUpdate()})),nt(e))}isCode(){const e=this.filename.split(".").pop()?.toLowerCase()||"";return gt.includes(e)}getLanguageFromExtension(e){return{js:"javascript",ts:"typescript",py:"python",rb:"ruby",yml:"yaml",ps1:"powershell",bat:"batch"}[e]||e}getMimeType(){const e=this.filename.split(".").pop()?.toLowerCase()||"";return e==="svg"?"image/svg+xml":e==="md"||e==="markdown"?"text/markdown":"text/plain"}getHeaderButtons(){const e=new Y;return e.text=this.content,e.title=c("Copy"),e.showText=!1,a`
			<div class="flex items-center gap-1">
				${e}
				${L({content:this.content,filename:this.filename,mimeType:this.getMimeType(),title:c("Download")})}
			</div>
		`}render(){const e=this.isCode(),t=this.filename.split(".").pop()||"";return a`
			<div class="h-full flex flex-col">
				<div class="flex-1 overflow-auto">
					${e?(()=>{const n=this.getLanguageFromExtension(t.toLowerCase());return a`
									<pre class="m-0 p-4 text-xs"><code class="hljs language-${n}">${j(this.highlightOrEscape(this.content,n))}</code></pre>
								`})():a` <pre class="m-0 p-4 text-xs font-mono">${this.content}</pre> `}
				</div>
			</div>
		`}};he([m()],Z.prototype,"filename",2);Z=he([T("text-artifact")],Z);var vt=Object.defineProperty,_t=Object.getOwnPropertyDescriptor,C=(e,t,n,r)=>{for(var i=r>1?void 0:r?_t(t,n):t,s=e.length-1,o;s>=0;s--)(o=e[s])&&(i=(r?o(t,n,i):o(i))||i);return r&&i&&vt(t,n,i),i};function bt(e,t){return Te({type:"string",enum:e,...t?.description&&{description:t.description},...t?.default&&{default:t.default}})}const xt=Ae({command:bt(["create","update","rewrite","get","delete","logs"],{description:"The operation to perform"}),filename:q({description:"Filename including extension (e.g., 'index.html', 'script.js')"}),content:ee(q({description:"File content"})),old_str:ee(q({description:"String to replace (for update command)"})),new_str:ee(q({description:"Replacement string (for update command)"}))});let $=class extends K{constructor(){super(...arguments),this._artifacts=new Map,this._activeFilename=null,this.artifactElements=new Map,this.contentRef=M(),this.collapsed=!1,this.overlay=!1}get artifacts(){return this._artifacts}getHtmlArtifactRuntimeProviders(){const e=[];if(this.agent){const t=[];for(const n of this.agent.state.messages)n.role==="user-with-attachments"&&n.attachments&&t.push(...n.attachments);t.length>0&&e.push(new Pe(t))}return e.push(new Oe(this,this.agent,!1)),e}createRenderRoot(){return this}connectedCallback(){super.connectedCallback(),this.style.display="block",this.style.height="100%",requestAnimationFrame(()=>{const e=this.contentRef.value;e&&(!this._activeFilename&&this._artifacts.size>0&&(this._activeFilename=Array.from(this._artifacts.keys())[0]),this.artifactElements.forEach((t,n)=>{t.parentElement||e.appendChild(t),t.style.display=n===this._activeFilename?"block":"none"}))})}disconnectedCallback(){super.disconnectedCallback()}getFileType(e){const t=e.split(".").pop()?.toLowerCase();return t==="html"?"html":t==="svg"?"svg":t==="md"||t==="markdown"?"markdown":t==="pdf"?"pdf":t==="docx"?"docx":t==="png"||t==="jpg"||t==="jpeg"||t==="gif"||t==="webp"||t==="bmp"||t==="ico"?"image":t==="txt"||t==="json"||t==="xml"||t==="yaml"||t==="yml"||t==="csv"||t==="js"||t==="ts"||t==="jsx"||t==="tsx"||t==="py"||t==="java"||t==="c"||t==="cpp"||t==="h"||t==="css"||t==="scss"||t==="sass"||t==="less"||t==="sh"?"text":"generic"}getOrCreateArtifactElement(e,t){let n=this.artifactElements.get(e);if(n)n.content=t,n instanceof y&&(n.runtimeProviders=this.getHtmlArtifactRuntimeProviders());else{const r=this.getFileType(e);r==="html"?(n=new y,n.runtimeProviders=this.getHtmlArtifactRuntimeProviders(),this.sandboxUrlProvider&&(n.sandboxUrlProvider=this.sandboxUrlProvider)):r==="svg"?n=new B:r==="markdown"?n=new S:r==="image"?n=new G:r==="pdf"?n=new U:r==="docx"?n=new V:r==="text"?n=new Z:n=new z,n.filename=e,n.content=t,n.style.display="none",n.style.height="100%",this.artifactElements.set(e,n);const i=n;this.contentRef.value?this.contentRef.value.appendChild(i):requestAnimationFrame(()=>{this.contentRef.value&&!i.parentElement&&this.contentRef.value.appendChild(i)})}return n}showArtifact(e){requestAnimationFrame(()=>{this.artifactElements.forEach((t,n)=>{this.contentRef.value&&!t.parentElement&&this.contentRef.value.appendChild(t),t.style.display=n===e?"block":"none"})}),this._activeFilename=e,this.requestUpdate(),requestAnimationFrame(()=>{const t=this.querySelector(`button[data-filename="${e}"]`);t&&t.scrollIntoView({behavior:"smooth",block:"nearest",inline:"center"})})}openArtifact(e){this._artifacts.has(e)&&(this.showArtifact(e),this.onOpen?.())}get tool(){return{label:"Artifacts",name:"artifacts",get description(){return Le([De,Ie])},parameters:xt,execute:async(e,t,n)=>({content:[{type:"text",text:await this.executeCommand(t)}],details:void 0})}}async reconstructFromMessages(e){const t=new Map,n="artifacts";for(const s of e)if(s.role==="assistant")for(const o of s.content)o.type==="toolCall"&&o.name===n&&t.set(o.id,o);const r=[];for(const s of e)if(s.role==="artifact"){const o=s;switch(o.action){case"create":r.push({command:"create",filename:o.filename,content:o.content});break;case"update":r.push({command:"rewrite",filename:o.filename,content:o.content});break;case"delete":r.push({command:"delete",filename:o.filename});break}}else if(s.role==="toolResult"&&s.toolName===n&&!s.isError){const o=s.toolCallId,p=t.get(o);if(!p)continue;const u=p.arguments;if(u.command==="get"||u.command==="logs")continue;r.push(u)}const i=new Map;for(const s of r){const o=s.filename;switch(s.command){case"create":{s.content&&i.set(o,s.content);break}case"rewrite":{s.content&&i.set(o,s.content);break}case"update":{let p=i.get(o);if(!p)break;s.old_str!==void 0&&s.new_str!==void 0&&(p=p.replace(s.old_str,s.new_str),i.set(o,p));break}case"delete":{i.delete(o);break}}}this._artifacts.clear(),this.artifactElements.forEach(s=>{s.remove()}),this.artifactElements.clear(),this._activeFilename=null,this._artifacts=new Map(this._artifacts);for(const[s,o]of i.entries()){const p={command:"create",filename:s,content:o};try{await this.createArtifact(p,{skipWait:!0,silent:!0})}catch{}}!this._activeFilename&&this._artifacts.size>0&&this.showArtifact(Array.from(this._artifacts.keys())[0]),this.onArtifactsChange?.(),this.requestUpdate()}async executeCommand(e,t={}){switch(e.command){case"create":return await this.createArtifact(e,t);case"update":return await this.updateArtifact(e,t);case"rewrite":return await this.rewriteArtifact(e,t);case"get":return this.getArtifact(e);case"delete":return this.deleteArtifact(e);case"logs":return this.getLogs(e);default:return`Error: Unknown command ${e.command}`}}async waitForHtmlExecution(e){const t=this.artifactElements.get(e);return t instanceof y?new Promise(n=>{setTimeout(()=>{const r=t.getLogs();n(r)},1500)}):""}reloadAllHtmlArtifacts(){this.artifactElements.forEach(e=>{e instanceof y&&e.sandboxIframeRef.value&&(e.runtimeProviders=this.getHtmlArtifactRuntimeProviders(),e.executeContent(e.content))})}async createArtifact(e,t={}){if(!e.filename||!e.content)return"Error: create command requires filename and content";if(this._artifacts.has(e.filename))return`Error: File ${e.filename} already exists`;const n={filename:e.filename,content:e.content,createdAt:new Date,updatedAt:new Date};this._artifacts.set(e.filename,n),this._artifacts=new Map(this._artifacts),this.getOrCreateArtifactElement(e.filename,e.content),t.silent||(this.showArtifact(e.filename),this.onArtifactsChange?.(),this.requestUpdate()),this.reloadAllHtmlArtifacts();let r=`Created file ${e.filename}`;if(this.getFileType(e.filename)==="html"&&!t.skipWait){const i=await this.waitForHtmlExecution(e.filename);r+=`
${i}`}return r}async updateArtifact(e,t={}){const n=this._artifacts.get(e.filename);if(!n){const i=Array.from(this._artifacts.keys());return i.length===0?`Error: File ${e.filename} not found. No files have been created yet.`:`Error: File ${e.filename} not found. Available files: ${i.join(", ")}`}if(!e.old_str||e.new_str===void 0)return"Error: update command requires old_str and new_str";if(!n.content.includes(e.old_str))return`Error: String not found in file. Here is the full content:

${n.content}`;n.content=n.content.replace(e.old_str,e.new_str),n.updatedAt=new Date,this._artifacts.set(e.filename,n),this.getOrCreateArtifactElement(e.filename,n.content),t.silent||(this.onArtifactsChange?.(),this.requestUpdate()),this.showArtifact(e.filename),this.reloadAllHtmlArtifacts();let r=`Updated file ${e.filename}`;if(this.getFileType(e.filename)==="html"&&!t.skipWait){const i=await this.waitForHtmlExecution(e.filename);r+=`
${i}`}return r}async rewriteArtifact(e,t={}){const n=this._artifacts.get(e.filename);if(!n){const i=Array.from(this._artifacts.keys());return i.length===0?`Error: File ${e.filename} not found. No files have been created yet.`:`Error: File ${e.filename} not found. Available files: ${i.join(", ")}`}if(!e.content)return"Error: rewrite command requires content";n.content=e.content,n.updatedAt=new Date,this._artifacts.set(e.filename,n),this.getOrCreateArtifactElement(e.filename,n.content),t.silent||this.onArtifactsChange?.(),this.showArtifact(e.filename),this.reloadAllHtmlArtifacts();let r="";if(this.getFileType(e.filename)==="html"&&!t.skipWait){const i=await this.waitForHtmlExecution(e.filename);r+=`
${i}`}return r}getArtifact(e){const t=this._artifacts.get(e.filename);if(!t){const n=Array.from(this._artifacts.keys());return n.length===0?`Error: File ${e.filename} not found. No files have been created yet.`:`Error: File ${e.filename} not found. Available files: ${n.join(", ")}`}return t.content}deleteArtifact(e){if(!this._artifacts.get(e.filename)){const r=Array.from(this._artifacts.keys());return r.length===0?`Error: File ${e.filename} not found. No files have been created yet.`:`Error: File ${e.filename} not found. Available files: ${r.join(", ")}`}this._artifacts.delete(e.filename),this._artifacts=new Map(this._artifacts);const n=this.artifactElements.get(e.filename);if(n&&(n.remove(),this.artifactElements.delete(e.filename)),this._activeFilename===e.filename){const r=Array.from(this._artifacts.keys());r.length>0?this.showArtifact(r[0]):(this._activeFilename=null,this.requestUpdate())}return this.onArtifactsChange?.(),this.requestUpdate(),this.reloadAllHtmlArtifacts(),`Deleted file ${e.filename}`}getLogs(e){const t=this.artifactElements.get(e.filename);if(!t){const n=Array.from(this._artifacts.keys());return n.length===0?`Error: File ${e.filename} not found. No files have been created yet.`:`Error: File ${e.filename} not found. Available files: ${n.join(", ")}`}return t instanceof y?t.getLogs():`Error: File ${e.filename} is not an HTML file. Logs are only available for HTML files.`}render(){const e=Array.from(this._artifacts.values()),t=e.length>0&&!this.collapsed;return a`
			<div
				class="${t?"":"hidden"} ${this.overlay?"fixed inset-0 z-40 pointer-events-auto backdrop-blur-sm bg-background/95":"relative"} h-full flex flex-col bg-background text-card-foreground ${this.overlay?"":"border-l border-border"} overflow-hidden shadow-xl"
			>
				<!-- Tab bar (always shown when there are artifacts) -->
				<div class="flex items-center justify-between border-b border-border bg-background">
					<div class="flex overflow-x-auto">
						${e.map(n=>{const i=n.filename===this._activeFilename?"border-primary text-primary":"border-transparent text-muted-foreground hover:text-foreground";return a`
								<button
									class="px-3 py-2 whitespace-nowrap border-b-2 ${i}"
									data-filename="${n.filename}"
									@click=${()=>this.showArtifact(n.filename)}
								>
									<span class="font-mono text-xs">${n.filename}</span>
								</button>
							`})}
					</div>
					<div class="flex items-center gap-1 px-2">
						${(()=>{const n=this._activeFilename?this.artifactElements.get(this._activeFilename):void 0;return n?n.getHeaderButtons():""})()}
						${fe({variant:"ghost",size:"sm",onClick:()=>this.onClose?.(),title:c("Close artifacts"),children:k(He,"sm")})}
					</div>
				</div>

				<!-- Content area where artifact elements are added programmatically -->
				<div class="flex-1 overflow-hidden" ${w(this.contentRef)}></div>
			</div>
		`}};C([A()],$.prototype,"_artifacts",2);C([A()],$.prototype,"_activeFilename",2);C([m({attribute:!1})],$.prototype,"agent",2);C([m({attribute:!1})],$.prototype,"sandboxUrlProvider",2);C([m({attribute:!1})],$.prototype,"onArtifactsChange",2);C([m({attribute:!1})],$.prototype,"onClose",2);C([m({attribute:!1})],$.prototype,"onOpen",2);C([m({type:Boolean})],$.prototype,"collapsed",2);C([m({type:Boolean})],$.prototype,"overlay",2);$=C([T("artifacts-panel")],$);var wt=Object.defineProperty,de=(e,t,n,r)=>{for(var i=void 0,s=e.length-1,o;s>=0;s--)(o=e[s])&&(i=o(t,n,i)||i);return i&&wt(t,n,i),i};class Q extends K{constructor(){super(...arguments),this.content="",this.variant="default",this.copied=!1}createRenderRoot(){return this}connectedCallback(){super.connectedCallback(),this.style.display="block"}async copy(){try{await navigator.clipboard.writeText(this.content||""),this.copied=!0,setTimeout(()=>{this.copied=!1},1500)}catch(t){console.error("Copy failed",t)}}updated(){const t=this.querySelector(".console-scroll");t&&(t.scrollTop=t.scrollHeight)}render(){const n=this.variant==="error"?"text-destructive":"text-foreground";return a`
			<div class="border border-border rounded-lg overflow-hidden">
				<div class="flex items-center justify-between px-3 py-1.5 bg-muted border-b border-border">
					<span class="text-xs text-muted-foreground font-mono">${c("console")}</span>
					<button
						@click=${()=>this.copy()}
						class="flex items-center gap-1 px-2 py-0.5 text-xs rounded hover:bg-accent text-muted-foreground hover:text-accent-foreground transition-colors"
						title="${c("Copy output")}"
					>
						${this.copied?k(Se,"sm"):k(Ue,"sm")}
						${this.copied?a`<span>${c("Copied!")}</span>`:""}
					</button>
				</div>
				<div class="console-scroll overflow-auto max-h-64">
					${Be(this.content||"")?a`<pre class="!bg-background !border-0 !rounded-none m-0 p-3 text-xs ${n} font-mono whitespace-pre">${j(qe(this.content||""))}</pre>`:a`<pre class="!bg-background !border-0 !rounded-none m-0 p-3 text-xs ${n} font-mono whitespace-pre">
${this.content||""}</pre
					>`}
				</div>
			</div>
		`}}de([m()],Q.prototype,"content");de([m()],Q.prototype,"variant");de([A()],Q.prototype,"copied");customElements.get("console-block")||customElements.define("console-block",Q);function yt(e,t){return a`
		<span
			class="inline-flex items-center gap-1 px-2 py-0.5 text-xs bg-muted/50 border border-border rounded ${t?"cursor-pointer hover:bg-muted transition-colors":""}"
			@click=${t?r=>{t&&(r.preventDefault(),r.stopPropagation(),t.openArtifact(e))}:null}
		>
			${k(b,"sm")}
			<span class="text-foreground">${e}</span>
		</span>
	`}function I(e){return e&&e.content?.filter(t=>t.type==="text").map(t=>t.text).join(`
`)||""}function W(e){if(!e)return"text";const t=e.split(".").pop()?.toLowerCase();return{js:"javascript",jsx:"javascript",ts:"typescript",tsx:"typescript",html:"html",css:"css",scss:"scss",json:"json",py:"python",md:"markdown",svg:"xml",xml:"xml",yaml:"yaml",yml:"yaml",sh:"bash",bash:"bash",sql:"sql",java:"java",c:"c",cpp:"cpp",cs:"csharp",go:"go",rs:"rust",php:"php",rb:"ruby",swift:"swift",kt:"kotlin",r:"r"}[t||""]||"text"}class Vt{constructor(t){this.artifactsPanel=t}render(t,n,r){const i=ke(n,r),s=M(),o=M(),p=d=>({create:{streaming:c("Creating artifact"),complete:c("Created artifact")},update:{streaming:c("Updating artifact"),complete:c("Updated artifact")},rewrite:{streaming:c("Rewriting artifact"),complete:c("Rewrote artifact")},get:{streaming:c("Getting artifact"),complete:c("Got artifact")},delete:{streaming:c("Deleting artifact"),complete:c("Deleted artifact")},logs:{streaming:c("Getting logs"),complete:c("Got logs")}})[d]||{streaming:c("Processing artifact"),complete:c("Processed artifact")},u=(d,f)=>f?a`<span>${d} ${yt(f,this.artifactsPanel)}</span>`:a`<span>${d}</span>`;if(n?.isError){const d=t?.command,f=t?.filename,E=(d?p(d):{streaming:c("Processing artifact"),complete:c("Processed artifact")}).streaming;if(d==="create"||d==="update"||d==="rewrite"){const h=t?.content||"",{old_str:v,new_str:_}=t||{},R=d==="update",P=v!==void 0&&_!==void 0?J({oldText:v,newText:_}):"",me=f?.endsWith(".html");return{content:a`
					<div>
						${O(i,b,u(E,f),s,o,!1)}
						<div ${w(s)} class="max-h-0 overflow-hidden transition-all duration-300 space-y-3">
							${R?P:h?a`<code-block .code=${h} language=${W(f)}></code-block>`:""}
							${me?a`<console-block .content=${I(n)||c("An error occurred")} variant="error"></console-block>`:a`<div class="text-sm text-destructive">${I(n)||c("An error occurred")}</div>`}
						</div>
					</div>
				`,isCustom:!1}}return{content:a`
				<div class="space-y-3">
					${F(i,b,E)}
					<div class="text-sm text-destructive">${I(n)||c("An error occurred")}</div>
				</div>
			`,isCustom:!1}}if(n&&t){const{command:d,filename:f,content:x}=t,h=(d?p(d):{streaming:c("Processing artifact"),complete:c("Processed artifact")}).complete;if(d==="get"){const v=I(n)||c("(no output)");return{content:a`
					<div>
						${O(i,b,u(h,f),s,o,!1)}
						<div ${w(s)} class="max-h-0 overflow-hidden transition-all duration-300">
							<code-block .code=${v} language=${W(f)}></code-block>
						</div>
					</div>
				`,isCustom:!1}}if(d==="logs"){const v=I(n)||c("(no output)");return{content:a`
					<div>
						${O(i,b,u(h,f),s,o,!1)}
						<div ${w(s)} class="max-h-0 overflow-hidden transition-all duration-300">
							<console-block .content=${v}></console-block>
						</div>
					</div>
				`,isCustom:!1}}if(d==="create"||d==="rewrite"){const v=x||"",_=f?.endsWith(".html"),R=I(n)||"";return{content:a`
					<div>
						${O(i,b,u(h,f),s,o,!1)}
						<div ${w(s)} class="max-h-0 overflow-hidden transition-all duration-300 space-y-3">
							${v?a`<code-block .code=${v} language=${W(f)}></code-block>`:""}
							${_&&R?a`<console-block .content=${R}></console-block>`:""}
						</div>
					</div>
				`,isCustom:!1}}if(d==="update"){const v=f?.endsWith(".html"),_=I(n)||"";return{content:a`
					<div>
						${O(i,b,u(h,f),s,o,!1)}
						<div ${w(s)} class="max-h-0 overflow-hidden transition-all duration-300 space-y-3">
							${J({oldText:t.old_str||"",newText:t.new_str||""})}
							${v&&_?a`<console-block .content=${_}></console-block>`:""}
						</div>
					</div>
				`,isCustom:!1}}return{content:a`
				<div class="space-y-3">
					${F(i,b,u(h,f))}
				</div>
			`,isCustom:!1}}if(t){const{command:d,filename:f,content:x,old_str:E,new_str:h}=t;if(!d)return{content:F(i,b,c("Preparing artifact...")),isCustom:!1};const _=p(d).streaming;switch(d){case"create":case"rewrite":return{content:a`
						<div>
							${O(i,b,u(_,f),s,o,!1)}
							<div ${w(s)} class="max-h-0 overflow-hidden transition-all duration-300">
								${x?a`<code-block .code=${x} language=${W(f)}></code-block>`:""}
							</div>
						</div>
					`,isCustom:!1};case"update":return{content:a`
						<div>
							${O(i,b,u(_,f),s,o,!1)}
							<div ${w(s)} class="max-h-0 overflow-hidden transition-all duration-300">
								${E!==void 0&&h!==void 0?J({oldText:E,newText:h}):""}
							</div>
						</div>
					`,isCustom:!1};case"get":case"logs":return{content:a`
						<div>
							${O(i,b,u(_,f),s,o,!1)}
							<div ${w(s)} class="max-h-0 overflow-hidden transition-all duration-300"></div>
						</div>
					`,isCustom:!1};default:return{content:a`
						<div>
							${F(i,b,u(_,f))}
						</div>
					`,isCustom:!1}}}return{content:F(i,b,c("Preparing artifact...")),isCustom:!1}}}export{D as ArtifactElement,$ as ArtifactsPanel,Vt as ArtifactsToolRenderer,y as HtmlArtifact,S as MarkdownArtifact,B as SvgArtifact,Z as TextArtifact};
