@maxhealth.tech/prefab 0.3.10 → 0.3.11

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.
@@ -13,4 +13,4 @@ ${n}
13
13
  ${St(e.dark," ")}
14
14
  }
15
15
  }`)}return t.join(`
16
- `)}function ye(e,t){e.setAttribute("data-theme",t),e.classList.toggle("dark",t==="dark"),e.classList.toggle("light",t==="light")}function Rt(e,t){if(!t)return;if(t.light)for(let[n,r]of Object.entries(t.light))e.style.setProperty(`--${Et(n)}`,At(r));if(t.dark){let r=document.getElementById("prefab-dark-theme");if(!r)r=document.createElement("style"),r.id="prefab-dark-theme",document.head.appendChild(r);r.textContent=Sn({dark:t.dark})}}function Tt(e,t){if(!e||typeof document>"u")return;let n=(r)=>{for(let[o,s]of Object.entries(e))if(ms(o,r))r.preventDefault(),t(s)};return document.addEventListener("keydown",n),()=>document.removeEventListener("keydown",n)}function ms(e,t){let n=e.toLowerCase().split("+").map((s)=>s.trim()),r=n[n.length-1],o=new Set(n.slice(0,-1));if(o.has("ctrl")!==(t.ctrlKey||t.metaKey))return!1;if(o.has("shift")!==t.shiftKey)return!1;if(o.has("alt")!==t.altKey)return!1;return t.key.toLowerCase()===r}var En='<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M12 3v2.25m6.364.386-1.591 1.591M21 12h-2.25m-.386 6.364-1.591-1.591M12 18.75V21m-4.773-4.227-1.591 1.591M5.25 12H3m4.227-4.773L5.636 5.636M15.75 12a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0Z"/></svg>',An='<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M21.752 15.002A9.72 9.72 0 0 1 18 15.75c-5.385 0-9.75-4.365-9.75-9.75 0-1.33.266-2.597.748-3.752A9.753 9.753 0 0 0 3 11.25C3 16.635 7.365 21 12.75 21a9.753 9.753 0 0 0 9.002-5.998Z"/></svg>',Rn={"top-right":"top: 8px; right: 8px;","top-left":"top: 8px; left: 8px;","bottom-right":"bottom: 8px; right: 8px;","bottom-left":"bottom: 8px; left: 8px;"};function gs(e,t){try{let r=localStorage.getItem(t);if(r==="light"||r==="dark")return r}catch{}let n=e.getAttribute("data-theme")??document.documentElement.getAttribute("data-theme");if(n==="light"||n==="dark")return n;if(typeof window<"u"&&window.matchMedia("(prefers-color-scheme: light)").matches)return"light";return"dark"}function Te(e,t){if(typeof document>"u")return()=>{};let n=t?.position??"top-right",r=t?.storageKey??"prefab-theme",o=t?.syncDocument??!0,s=getComputedStyle(e).position;if(s==="static"||s==="")e.style.position="relative";let i=document.createElement("button");i.className="pf-theme-toggle",i.setAttribute("aria-label","Toggle theme"),i.setAttribute("title","Toggle light/dark"),Object.assign(i.style,{position:"absolute",zIndex:"100",width:"28px",height:"28px",border:"1px solid var(--border, #e5e7eb)",borderRadius:"6px",background:"var(--card, rgba(255,255,255,0.8))",color:"var(--foreground, #333)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",padding:"0",opacity:"0.7",transition:"opacity 0.15s, border-color 0.15s"});let a=Rn[n]??Rn["top-right"];for(let d of a.split(";")){let[g,h]=d.split(":").map((y)=>y.trim());if(g&&h)i.style.setProperty(g,h)}i.addEventListener("mouseenter",()=>{i.style.opacity="1"}),i.addEventListener("mouseleave",()=>{i.style.opacity="0.7"});function l(d){if(ye(e,d),o)ye(document.documentElement,d);i.innerHTML=d==="dark"?An:En;try{localStorage.setItem(r,d)}catch{}}let c=gs(e,r);l(c),i.addEventListener("click",()=>{let d=e.getAttribute("data-theme")??"dark";l(d==="dark"?"light":"dark")}),e.appendChild(i);let u;if(o)u=new MutationObserver((d)=>{for(let g of d)if(g.type==="attributes"&&g.attributeName==="data-theme"){let h=document.documentElement.getAttribute("data-theme");if((h==="light"||h==="dark")&&h!==e.getAttribute("data-theme")){ye(e,h),i.innerHTML=h==="dark"?An:En;try{localStorage.setItem(r,h)}catch{}}}}),u.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});return()=>{u?.disconnect(),i.remove()}}function Qe(e){let t=e?.baseUrl??(typeof window<"u"?window.location.origin:""),n={"Content-Type":"application/json",...e?.headers},r=e?.fetch??globalThis.fetch.bind(globalThis);return{async callTool(o,s){let i=await r(`${t}/mcp/tools/call`,{method:"POST",headers:n,body:JSON.stringify({jsonrpc:"2.0",method:"tools/call",params:{name:o,arguments:s}})});if(!i.ok)throw Error(`MCP tool call failed: ${i.status} ${i.statusText}`);let a=await i.json();if(a.error)throw Error(a.error.message??"MCP tool call returned error");let l=a.result?.content??a.content??[];for(let c of l)if(c.type==="text"&&c.text!==void 0){try{let u=JSON.parse(c.text);if(typeof u==="object"&&u!==null&&"$prefab"in u)return u;return u}catch{}return c.text}return a.result??a},async sendMessage(o){await r(`${t}/mcp/messages`,{method:"POST",headers:n,body:JSON.stringify({message:o})})}}}function et(){return{callTool(e){return P.warn(`No MCP transport: callTool('${e}') ignored`),Promise.resolve(null)},sendMessage(e){return P.warn("No MCP transport: sendMessage ignored",e),Promise.resolve()}}}var Tn="0.3.10";function hs(e){return e!==null&&typeof e==="object"&&e.jsonrpc==="2.0"}class me{hostOrigin;listeners=new Map;protocol="prefab";cleanup;pending=new Map;callIdCounter=0;rpcPending=new Map;rpcIdCounter=0;sentRpcIds=new Set;postFn;_hostSupportsSubscriptions=!1;constructor(e="*"){this.hostOrigin=e}connect(){if(typeof window>"u")return;let e=Cs();if(e)this.postFn=(n)=>e.postMessage(n);let t=(n)=>{if(this.hostOrigin!=="*"&&n.origin!==this.hostOrigin)return;let r=n.data;if(hs(r)){this.handleJsonRpc(r);return}let o=r;if(!o?.type.startsWith("prefab:"))return;if(o.type==="prefab:tool-call-response"&&o.id){let i=this.pending.get(o.id);if(i){if(this.pending.delete(o.id),o.payload?.error!=null)i.reject(Error(o.payload.error));else i.resolve(o.payload?.result);return}}let s=this.listeners.get(o.type);if(s)for(let i of s)i(o.payload??{})};window.addEventListener("message",t),this.cleanup=()=>window.removeEventListener("message",t)}async initialize(e){try{return await Promise.any([this.initPrefab(e),this.initJsonRpc(e)])}catch(t){let n=t instanceof AggregateError?t.errors.map((r)=>r.message).join("; "):String(t);throw Error(`Bridge init failed — no host responded. Tried: ${n}`,{cause:t})}}createTransport(){if(this.protocol==="jsonrpc")return this.createJsonRpcTransport();return this.createPrefabTransport()}requestMode(e){if(this.protocol==="jsonrpc")this.sendRpcRequest("ui/request-display-mode",{mode:e});else this.sendPrefab("prefab:request-mode",{mode:e})}openLink(e,t){if(this.protocol==="jsonrpc")this.sendRpcRequest("ui/open-link",{url:e,target:t});else this.sendPrefab("prefab:open-link",{url:e,target:t})}updateContext(e){if(this.protocol==="jsonrpc")this.sendRpcRequest("ui/update-model-context",{structuredContent:e});else this.sendPrefab("prefab:update-context",{context:e})}setupAutoResize(e){if(typeof ResizeObserver>"u")return bs;let t=-1,n=-1,r=(i,a)=>{if(i===t&&a===n)return;if(t=i,n=a,this.protocol==="jsonrpc")this.sendRpcNotification("ui/notifications/size-changed",{width:i,height:a});else this.sendPrefab("prefab:size-changed",{width:i,height:a})},o=new ResizeObserver((i)=>{for(let a of i)if(a.borderBoxSize.length){let l=a.borderBoxSize[0];r(Math.ceil(l.inlineSize),Math.ceil(l.blockSize))}else{let l=a.target.getBoundingClientRect();r(Math.ceil(l.width),Math.ceil(l.height))}});o.observe(e);let s=e.getBoundingClientRect();return r(Math.ceil(s.width),Math.ceil(s.height)),()=>o.disconnect()}notifyPreferredSize(e){if(this.protocol==="jsonrpc")this.sendRpcNotification("ui/notifications/preferred-size",e);else this.sendPrefab("prefab:preferred-size",e)}subscribe(e,t){let n=(r)=>{if(r.uri!==e)return;t(r.contents??r.data??r)};if(this.protocol==="jsonrpc")this.on("prefab:resource-updated",n),this.sendRpcRequest("resources/subscribe",{uri:e});else this.on("prefab:resource-updated",n),this.sendPrefab("prefab:subscribe",{uri:e});return()=>{if(this.off("prefab:resource-updated",n),this.protocol==="jsonrpc")this.sendRpcRequest("resources/unsubscribe",{uri:e});else this.sendPrefab("prefab:unsubscribe",{uri:e})}}get supportsSubscriptions(){return this._hostSupportsSubscriptions}on(e,t){if(!this.listeners.has(e))this.listeners.set(e,new Set);let n=this.listeners.get(e);if(n)n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}disconnect(){this.cleanup?.(),this.listeners.clear();for(let[,e]of this.pending)e.reject(Error("Bridge disconnected"));this.pending.clear();for(let[,e]of this.rpcPending)e.reject(Error("Bridge disconnected"));this.rpcPending.clear(),this.sentRpcIds.clear()}get activeProtocol(){return this.protocol}initPrefab(e){return new Promise((t,n)=>{let r=!1,o=(s)=>{if(r)return;r=!0,this.off("prefab:init-response",o),this.protocol="prefab";let i=s.capabilities;this._hostSupportsSubscriptions=i?.subscriptions===!0,t(s)};this.on("prefab:init-response",o),this.sendPrefab("prefab:init",{capabilities:e}),setTimeout(()=>{if(!r)r=!0,this.off("prefab:init-response",o),n(Error("prefab:init timeout"))},2000)})}createPrefabTransport(){return{callTool:(e,t)=>{let n=`tc-${++this.callIdCounter}`;return new Promise((r,o)=>{this.pending.set(n,{resolve:r,reject:o}),this.sendPrefab("prefab:tool-call",{tool:e,arguments:t},n),setTimeout(()=>{if(this.pending.has(n))this.pending.delete(n),o(Error(`Tool call '${e}' timed out`))},30000)})},sendMessage:(e)=>(this.sendPrefab("prefab:send-message",{message:e}),Promise.resolve()),subscribe:(e,t)=>this.subscribe(e,t),capabilities:{subscriptions:this._hostSupportsSubscriptions}}}sendPrefab(e,t,n){if(typeof window>"u")return;let r=window.parent!==window?window.parent:window,o={type:e,payload:t,id:n};r.postMessage(o,this.hostOrigin)}handleJsonRpc(e){if(!("method"in e)){let r=this.rpcPending.get(e.id);if(r)if(this.rpcPending.delete(e.id),e.error)r.reject(Error(e.error.message));else r.resolve(e.result);return}let t=e.method,n=e.params??{};if(e.id!=null&&this.sentRpcIds.delete(e.id))return;if(e.id!=null)this.postJsonRpc({jsonrpc:"2.0",id:e.id,result:{}});switch(t){case"ui/notifications/tool-input":this.dispatch("prefab:tool-input",{args:n.arguments??n});break;case"ui/notifications/tool-input-partial":this.dispatch("prefab:tool-input-partial",{args:n.arguments??n});break;case"ui/notifications/tool-result":this.dispatch("prefab:tool-result",{result:n});break;case"ui/notifications/tool-cancelled":this.dispatch("prefab:tool-cancelled",n);break;case"ui/notifications/host-context-changed":{let r={};if(typeof n.theme==="string")r.colorScheme=n.theme;if(typeof n.styles==="object"&&n.styles!==null){let o=n.styles;if(o.variables)r.variables=o.variables;if(typeof o.css?.fonts==="string")r.fontCss=o.css.fonts}this.dispatch("prefab:theme-update",r),this.dispatch("prefab:host-context-changed",n);break}case"ui/resource-teardown":this.dispatch("prefab:teardown",n);break;case"ui/notifications/resource-updated":case"notifications/resources/updated":this.dispatch("prefab:resource-updated",n);break}}initJsonRpc(e){return new Promise((t,n)=>{let r=++this.rpcIdCounter,o=!1;this.rpcPending.set(r,{resolve:(s)=>{if(o)return;o=!0,this.protocol="jsonrpc";let i=s??{},a=i.hostInfo??{},l=i.hostContext??{},c=i.hostCapabilities??{},u;if(typeof l.theme==="string"||typeof l.styles==="object"){if(u={},typeof l.theme==="string")u.colorScheme=l.theme;if(typeof l.styles==="object"&&l.styles!==null){let g=l.styles;if(g.variables)u.variables=g.variables;if(typeof g.css?.fonts==="string")u.fontCss=g.css.fonts}}this.postJsonRpc({jsonrpc:"2.0",method:"ui/notifications/initialized",params:{}});let d=c.resources;this._hostSupportsSubscriptions=c.subscriptions===!0||d?.subscribe===!0,t({hostName:a.name,hostVersion:a.version,capabilities:{toast:!0,navigation:c.openLinks!=null,messaging:!0,displayModes:l.availableDisplayModes??[]},theme:u,toolInput:void 0,meta:l})},reject:(s)=>{if(o)return;o=!0,n(s)}}),this.postJsonRpc({jsonrpc:"2.0",id:r,method:"ui/initialize",params:{protocolVersion:"2026-01-26",appInfo:{name:"prefab",version:Tn},appCapabilities:{...e.displayModes&&{availableDisplayModes:e.displayModes}}}}),setTimeout(()=>{if(!o)o=!0,this.rpcPending.delete(r),n(Error("ui/initialize timeout"))},2000)})}createJsonRpcTransport(){return{callTool:(e,t)=>this.sendRpcRequest("tools/call",{name:e,arguments:t}),sendMessage:(e)=>this.sendRpcRequest("ui/message",{role:"user",content:{type:"text",text:e}}),subscribe:(e,t)=>this.subscribe(e,t),capabilities:{subscriptions:this._hostSupportsSubscriptions}}}sendRpcRequest(e,t){let n=++this.rpcIdCounter;return new Promise((r,o)=>{this.rpcPending.set(n,{resolve:r,reject:o}),this.postJsonRpc({jsonrpc:"2.0",id:n,method:e,params:t}),setTimeout(()=>{if(this.rpcPending.has(n))this.rpcPending.delete(n),o(Error(`JSON-RPC '${e}' timed out`))},30000)})}sendRpcNotification(e,t){this.postJsonRpc({jsonrpc:"2.0",method:e,params:t})}postJsonRpc(e){if(typeof window>"u")return;if(e.id!=null&&typeof e.method==="string")this.sentRpcIds.add(e.id);if(this.postFn)this.postFn(e);else(window.parent!==window?window.parent:window).postMessage(e,this.hostOrigin)}dispatch(e,t){let n=this.listeners.get(e);if(n)for(let r of n)r(t)}}var bs=()=>{};function Ne(e,t){if(t.variables)for(let[n,r]of Object.entries(t.variables))e.style.setProperty(n.startsWith("--")?n:`--${n}`,r);if(t.colorScheme&&t.colorScheme!=="auto")e.setAttribute("data-theme",t.colorScheme);if(t.fontCss)ys(t.fontCss)}function ys(e){if(document.getElementById("__prefab-host-fonts"))return;let n=document.createElement("style");n.id="__prefab-host-fonts",n.textContent=e,document.head.appendChild(n)}function Ce(){if(typeof window>"u")return!1;try{return window.self!==window.top}catch{return!0}}function Cs(){if(typeof window>"u")return;let e=window;if(typeof e.acquireVsCodeApi==="function")try{let t=e.acquireVsCodeApi();if(t!==null&&typeof t==="object"&&"postMessage"in t)return t}catch{return}return}async function tt(e){Ze();let t=e?.mode??"auto",n=t==="bridge"||t==="auto"&&Ce(),r,o,s={capabilities:{}};if(n)o=new me(e?.hostOrigin),o.connect(),s=await o.initialize(e?.capabilities??{toolInput:!0}),r=o.createTransport();else if(e?.transport)r=Qe(e.transport);else r=et();if(s.theme&&typeof document<"u")Ne(document.documentElement,s.theme);if(typeof document<"u"&&!o)ws();let i,a,l,c,u,d=s.toolInput,g;if(o)o.on("prefab:tool-input",(f)=>{let b=f.args??f;if(i)i(b);else d=b}),o.on("prefab:tool-result",(f)=>{let b=f.result??f;if(a)a(b);else g=b}),o.on("prefab:tool-cancelled",()=>{l?.()}),o.on("prefab:tool-input-partial",(f)=>{c?.(f.args??f)}),o.on("prefab:theme-update",(f)=>{if(typeof document<"u")Ne(document.documentElement,f)}),o.on("prefab:host-context-changed",(f)=>{u?.(f)});function h(f,...b){let w=Nt(f),S=new we,N={store:S,scope:{},transport:r,rerender:()=>k(),onToast:void 0};function k(){w.innerHTML="";for(let R of b)w.appendChild(J(R,N))}return k(),{rerender:k,store:S,destroy:()=>{w.innerHTML=""}}}return{callTool:(f,b={})=>r.callTool(f,b),sendMessage:(f)=>r.sendMessage(f),onToolInput:(f)=>{if(i=f,d){let b=d;d=void 0,queueMicrotask(()=>f(b))}},onToolResult:(f)=>{if(a=f,g!==void 0){let b=g;g=void 0,queueMicrotask(()=>f(b))}},onToolCancelled:(f)=>{l=f},onToolInputPartial:(f)=>{c=f},onHostContextChanged:(f)=>{u=f},render:h,mount:(f,b,w)=>{let S=Nt(f);return ne.mount(S,b,{transport:r,...w})},requestMode:(f)=>o?.requestMode(f),openLink:(f,b)=>{if(o)o.openLink(f,b);else if(typeof window<"u")window.open(f,b??"_blank")},updateContext:(f)=>{if(o)o.updateContext(f)},setupAutoResize:(f)=>{if(!o)return vs;let b=typeof f==="string"?Nt(f):f;return o.setupAutoResize(b)},notifyPreferredSize:(f)=>{if(o)o.notifyPreferredSize(f)},host:s,capabilities:s.capabilities,theme:s.theme,transport:r,destroy:()=>o?.disconnect()}}var vs=()=>{};function Nt(e){if(typeof e==="string"){if(typeof document>"u")throw Error("Cannot resolve selector outside browser");let t=document.querySelector(e);if(!t)throw Error(`Element not found: ${e}`);return t}return e}function ws(){function e(){let n=document.body.getAttribute("data-vscode-theme-kind");if(!n)return;let r=n.includes("light")?"light":"dark";document.documentElement.setAttribute("data-theme",r)}e(),new MutationObserver(e).observe(document.body,{attributes:!0,attributeFilter:["data-vscode-theme-kind"]})}var Nn=["Accordion","AccordionItem","Alert","AlertDescription","AlertTitle","AreaChart","Audio","Badge","BarChart","BlockQuote","Button","ButtonGroup","Calendar","Card","CardContent","CardDescription","CardFooter","CardHeader","CardTitle","Carousel","Checkbox","ChoiceCard","Code","Column","Combobox","ComboboxGroup","ComboboxLabel","ComboboxOption","ComboboxSeparator","Condition","Container","Dashboard","DashboardItem","DataTable","DatePicker","Define","Detail","Dialog","Div","Dot","DropZone","Elif","Else","Embed","ExpandableRow","Field","FieldContent","FieldDescription","FieldError","FieldTitle","ForEach","Form","Grid","GridItem","H1","H2","H3","H4","Heading","Histogram","HoverCard","Icon","If","Image","Input","Kbd","Label","Large","Lead","LineChart","Link","Loader","Markdown","MasterDetail","Mermaid","Metric","Muted","P","Page","Pages","PdfViewer","PieChart","Popover","Progress","RadarChart","RadialChart","Radio","RadioGroup","Ring","Row","ScatterChart","Select","SelectGroup","SelectLabel","SelectOption","SelectSeparator","Separator","Slider","Slot","Small","Span","Sparkline","Svg","Switch","Tab","Table","TableBody","TableCaption","TableCell","TableFooter","TableHead","TableHeader","TableRow","Tabs","Text","Textarea","Tooltip","Use","Video"];var Hn=new Set(Nn);function ve(e,t={}){let n=[],r=t.strict??!1;if(e==null||typeof e!=="object")return n.push({path:"$",message:"Wire data must be a non-null object"}),{valid:!1,errors:n};let o=e;if(o.$prefab==null||typeof o.$prefab!=="object")n.push({path:"$.$prefab",message:"Missing or invalid $prefab header"});else if(typeof o.$prefab.version!=="string")n.push({path:"$.$prefab.version",message:"version must be a string"});if(o.view==null)n.push({path:"$.view",message:'Missing required "view" field'});else Mt(o.view,"$.view",n,r);if(o.state!==void 0){if(o.state===null||typeof o.state!=="object"||Array.isArray(o.state))n.push({path:"$.state",message:"state must be a plain object"})}if(o.theme!==void 0)ks(o.theme,n);if(o.css!==void 0)Ln(o.css,"$.css",n);if(o.stylesheets!==void 0)Ln(o.stylesheets,"$.stylesheets",n);if(o.mode!==void 0&&o.mode!=="light"&&o.mode!=="dark")n.push({path:"$.mode",message:'mode must be "light" or "dark"'});if(o.defs!==void 0)if(o.defs===null||typeof o.defs!=="object"||Array.isArray(o.defs))n.push({path:"$.defs",message:"defs must be a plain object"});else for(let[s,i]of Object.entries(o.defs))Mt(i,`$.defs.${s}`,n,r);if(o.keyBindings!==void 0)if(o.keyBindings===null||typeof o.keyBindings!=="object"||Array.isArray(o.keyBindings))n.push({path:"$.keyBindings",message:"keyBindings must be a plain object"});else for(let[s,i]of Object.entries(o.keyBindings))Lt(i,`$.keyBindings.${s}`,n);return{valid:n.length===0,errors:n}}function Pn(e){return ve(e).valid}function Mt(e,t,n,r){if(e==null||typeof e!=="object"||Array.isArray(e)){n.push({path:t,message:"Component must be a plain object"});return}let o=e;if(typeof o.type!=="string"||o.type.length===0){n.push({path:`${t}.type`,message:'Component must have a non-empty "type" string'});return}if(r&&!Hn.has(o.type))n.push({path:`${t}.type`,message:`Unknown component type: "${o.type}"`});if(o.children!==void 0)if(!Array.isArray(o.children))n.push({path:`${t}.children`,message:"children must be an array"});else for(let i=0;i<o.children.length;i++)Mt(o.children[i],`${t}.children[${i}]`,n,r);let s=["onClick","on_click","onChange","on_change","onSubmit","on_submit","onMount","on_mount","onClose","on_close"];for(let i of s)if(o[i]!==void 0)Lt(o[i],`${t}.${i}`,n);for(let[i,a]of Object.entries(o)){if(i==="type"||xs.has(i)||s.includes(i))continue;if(Mn(a)||Array.isArray(a)&&a.some(Mn))n.push({path:`${t}.${i}`,message:`Components under "${i}" are ignored by the renderer; move them into "children"`})}}var xs=new Set(["children","fallback","trigger","empty","else","summary"]);function Mn(e){if(e==null||typeof e!=="object"||Array.isArray(e))return!1;let t=e.type;return typeof t==="string"&&Hn.has(t)}function Lt(e,t,n){if(Array.isArray(e)){for(let a=0;a<e.length;a++)Lt(e[a],`${t}[${a}]`,n);return}if(e==null||typeof e!=="object"){n.push({path:t,message:"Action must be an object or array of objects"});return}let r=e,o=typeof r.type==="string"&&r.type.length>0,s=typeof r.action==="string"&&r.action.length>0;if(!o&&!s){n.push({path:`${t}.type`,message:'Action must have a non-empty "type" or "action" string'});return}if((s?r.action:r.type).toLowerCase()==="showtoast"){if(typeof r.message!=="string"||r.message.length===0)n.push({path:`${t}.message`,message:'showToast requires a non-empty "message" string'})}}function Ln(e,t,n){if(!Array.isArray(e)){n.push({path:t,message:`${t} must be an array of strings`});return}for(let r=0;r<e.length;r++)if(typeof e[r]!=="string")n.push({path:`${t}[${r}]`,message:"must be a string"})}function ks(e,t){if(e===null||typeof e!=="object"||Array.isArray(e)){t.push({path:"$.theme",message:"theme must be a plain object"});return}let n=e;for(let r of["light","dark"])if(n[r]!==void 0){if(n[r]===null||typeof n[r]!=="object"||Array.isArray(n[r]))t.push({path:`$.theme.${r}`,message:`theme.${r} must be a plain object`})}}var ne={mount(e,t,n){if(Ze(),n?.validate!==!1)for(let b of ve(t).errors)P.warn(`wire validation ${b.path}: ${b.message}`);let r=t,o={tracked:[],evalBlocked:!1};if(r.pipes)for(let[b,w]of Object.entries(r.pipes))$n(b,w,o);let s=new we(r.state),i;if(n?.transport&&"callTool"in n.transport)i=n.transport;else if(n?.transport)i=Qe(n.transport);else i=et();let a=n?.onToast??As,l=new Se;function c(b){let w=b;if(r=w,w.state)s.merge(w.state);if(w.defs)u.defs=w.defs;if(w.theme)Rt(e,w.theme);if(w.mode)On(e,w.mode);if(w.pipes)for(let[S,N]of Object.entries(w.pipes))$n(S,N,o);for(let S of d)S.remove();if(d.length=0,d.push(...Dn(w.css,w.stylesheets)),jn(e,w.layout),g?.(),g=void 0,w.keyBindings)g=Tt(w.keyBindings,(S)=>{F(j(S,{store:s,transport:i,scope:{},rerender:()=>f(),remount:c,onToast:a}),"keyBinding")});f()}let u={store:s,scope:{},transport:i,rerender:()=>f(),remount:c,onToast:a,defs:r.defs,destroyRegistry:l};if(Rt(e,r.theme),r.mode)On(e,r.mode);jn(e,r.layout);let d=Dn(r.css,r.stylesheets),g;if(r.keyBindings)g=Tt(r.keyBindings,(b)=>{F(j(b,{store:s,transport:i,scope:{},rerender:()=>f(),remount:c,onToast:a}),"keyBinding")});let h,y=n?.themeToggle??!0;if(y!==!1)h=Te(e,typeof y==="object"?y:void 0);function f(){l.flush();let b=e.querySelector(".pf-theme-toggle");e.innerHTML="";let w=J(r.view,u);if(e.appendChild(w),b)e.appendChild(b)}return f(),{rerender:()=>f(),update(b){if(s.merge(b.update.state),f(),b.update.actions!=null)F(j(b.update.actions,u),"update action")},store:s,destroy(){l.flush(),h?.(),g?.(),Bt(),Jt();for(let b of d)b.remove();for(let b of o.tracked)ke(b);e.innerHTML=""}}},isPrefabData(e){return e!=null&&typeof e==="object"&&"$prefab"in e},isPrefabUpdate(e){return e!=null&&typeof e==="object"&&"$prefab"in e&&"update"in e}},Ss=new Set(["find","dot","length","upper","lower","truncate","join","first","last","abs","round","number","currency","percent","compact","date","time","datetime","pluralize","default","selectattr","rejectattr"]);function Es(e){if(e instanceof EvalError)return!0;return e instanceof Error&&/unsafe-eval|Content Security Policy|call to Function/i.test(e.message)}function $n(e,t,n){if(Ss.has(e)){P.warn(`wire pipe "${e}" ignored — shadows built-in`);return}if(He(e)!=null){P.debug(`wire pipe "${e}" — already registered, keeping local implementation`);return}if(n.evalBlocked)return;try{let r=Function("return ("+t+")")();if(typeof r!=="function"){P.warn(`wire pipe "${e}" — source did not evaluate to a function`);return}xe(e,r),n.tracked.push(e)}catch(r){if(Es(r)){n.evalBlocked=!0,P.warn("wire pipes cannot be hydrated — this host's CSP forbids eval. Pre-register them with "+"prefab.registerPipe() from a companion script (rendererHtml({ scripts })) and they are used as-is.");return}P.warn(`wire pipe "${e}" — failed to hydrate:`,r)}}function As(e){if(typeof document>"u")return;let t=Ts(),n=document.createElement("div"),r=e.variant??"default";n.className=`pf-toast${r!=="default"?` pf-toast--${r}`:""}`,n.setAttribute("data-variant",r),n.style.marginBottom="8px",n.style.transition="opacity 0.3s ease";let o=document.createElement("div");if(o.textContent=e.message,o.style.fontWeight="500",n.appendChild(o),e.description){let i=document.createElement("div");i.textContent=e.description,i.style.fontSize="14px",i.style.color="var(--muted-foreground, #6b7280)",n.appendChild(i)}t.appendChild(n);let s=e.duration??4000;setTimeout(()=>{n.style.opacity="0",setTimeout(()=>n.remove(),300)},s)}function On(e,t){if(ye(e,t),typeof document<"u")ye(document.documentElement,t)}function Rs(e){let t=e.trim();if(t.includes("{")||t.includes("}"))return!1;return/^(https?:)?\/\//i.test(t)||t.startsWith("/")||/\.css(\?|#|$)/i.test(t)}function Dn(e,t){let n=[];if(typeof document>"u")return n;for(let r of e??[]){let o=document.createElement("style");o.textContent=r,o.dataset.prefab="injected",document.head.appendChild(o),n.push(o)}for(let r of t??[])if(Rs(r)){let o=document.createElement("link");o.rel="stylesheet",o.href=r,o.dataset.prefab="injected",document.head.appendChild(o),n.push(o)}else{let o=document.createElement("style");o.textContent=r,o.dataset.prefab="injected",document.head.appendChild(o),n.push(o)}return n}function jn(e,t){if(e.style.height="",e.style.minHeight="",e.style.maxHeight="",e.style.overflow="",!t)return;if(t.preferredHeight!=null)e.style.height=`${t.preferredHeight}px`;if(t.minHeight!=null)e.style.minHeight=`${t.minHeight}px`;if(t.maxHeight!=null)e.style.maxHeight=`${t.maxHeight}px`,e.style.overflow="auto"}function Ts(){let t=document.getElementById("prefab-toast-container");if(!t)t=document.createElement("div"),t.id="prefab-toast-container",t.style.position="fixed",t.style.bottom="16px",t.style.right="16px",t.style.zIndex="9999",t.style.maxWidth="400px",document.body.appendChild(t);return t}if(typeof window<"u"){let e=window;e.PrefabRenderer=ne,e.prefab={app:tt,mount:ne.mount.bind(ne),isPrefabData:ne.isPrefabData.bind(ne),isPrefabUpdate:ne.isPrefabUpdate.bind(ne),Bridge:me,isIframe:Ce,registerPipe:xe,unregisterPipe:ke,listPipes:Le,registerComponent:p,createThemeToggle:Te,validateWireFormat:ve,setLogLevel:Me};let t=e.__PREFAB_DATA__;if(t!=null){let n=document.getElementById("prefab-root");if(n)ne.mount(n,t)}}})();
16
+ `)}function ye(e,t){e.setAttribute("data-theme",t),e.classList.toggle("dark",t==="dark"),e.classList.toggle("light",t==="light")}function Rt(e,t){if(!t)return;if(t.light)for(let[n,r]of Object.entries(t.light))e.style.setProperty(`--${Et(n)}`,At(r));if(t.dark){let r=document.getElementById("prefab-dark-theme");if(!r)r=document.createElement("style"),r.id="prefab-dark-theme",document.head.appendChild(r);r.textContent=Sn({dark:t.dark})}}function Tt(e,t){if(!e||typeof document>"u")return;let n=(r)=>{for(let[o,s]of Object.entries(e))if(ms(o,r))r.preventDefault(),t(s)};return document.addEventListener("keydown",n),()=>document.removeEventListener("keydown",n)}function ms(e,t){let n=e.toLowerCase().split("+").map((s)=>s.trim()),r=n[n.length-1],o=new Set(n.slice(0,-1));if(o.has("ctrl")!==(t.ctrlKey||t.metaKey))return!1;if(o.has("shift")!==t.shiftKey)return!1;if(o.has("alt")!==t.altKey)return!1;return t.key.toLowerCase()===r}var En='<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M12 3v2.25m6.364.386-1.591 1.591M21 12h-2.25m-.386 6.364-1.591-1.591M12 18.75V21m-4.773-4.227-1.591 1.591M5.25 12H3m4.227-4.773L5.636 5.636M15.75 12a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0Z"/></svg>',An='<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M21.752 15.002A9.72 9.72 0 0 1 18 15.75c-5.385 0-9.75-4.365-9.75-9.75 0-1.33.266-2.597.748-3.752A9.753 9.753 0 0 0 3 11.25C3 16.635 7.365 21 12.75 21a9.753 9.753 0 0 0 9.002-5.998Z"/></svg>',Rn={"top-right":"top: 8px; right: 8px;","top-left":"top: 8px; left: 8px;","bottom-right":"bottom: 8px; right: 8px;","bottom-left":"bottom: 8px; left: 8px;"};function gs(e,t){try{let r=localStorage.getItem(t);if(r==="light"||r==="dark")return r}catch{}let n=e.getAttribute("data-theme")??document.documentElement.getAttribute("data-theme");if(n==="light"||n==="dark")return n;if(typeof window<"u"&&window.matchMedia("(prefers-color-scheme: light)").matches)return"light";return"dark"}function Te(e,t){if(typeof document>"u")return()=>{};let n=t?.position??"top-right",r=t?.storageKey??"prefab-theme",o=t?.syncDocument??!0,s=getComputedStyle(e).position;if(s==="static"||s==="")e.style.position="relative";let i=document.createElement("button");i.className="pf-theme-toggle",i.setAttribute("aria-label","Toggle theme"),i.setAttribute("title","Toggle light/dark"),Object.assign(i.style,{position:"absolute",zIndex:"100",width:"28px",height:"28px",border:"1px solid var(--border, #e5e7eb)",borderRadius:"6px",background:"var(--card, rgba(255,255,255,0.8))",color:"var(--foreground, #333)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",padding:"0",opacity:"0.7",transition:"opacity 0.15s, border-color 0.15s"});let a=Rn[n]??Rn["top-right"];for(let d of a.split(";")){let[g,h]=d.split(":").map((y)=>y.trim());if(g&&h)i.style.setProperty(g,h)}i.addEventListener("mouseenter",()=>{i.style.opacity="1"}),i.addEventListener("mouseleave",()=>{i.style.opacity="0.7"});function l(d){if(ye(e,d),o)ye(document.documentElement,d);i.innerHTML=d==="dark"?An:En;try{localStorage.setItem(r,d)}catch{}}let c=gs(e,r);l(c),i.addEventListener("click",()=>{let d=e.getAttribute("data-theme")??"dark";l(d==="dark"?"light":"dark")}),e.appendChild(i);let u;if(o)u=new MutationObserver((d)=>{for(let g of d)if(g.type==="attributes"&&g.attributeName==="data-theme"){let h=document.documentElement.getAttribute("data-theme");if((h==="light"||h==="dark")&&h!==e.getAttribute("data-theme")){ye(e,h),i.innerHTML=h==="dark"?An:En;try{localStorage.setItem(r,h)}catch{}}}}),u.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});return()=>{u?.disconnect(),i.remove()}}function Qe(e){let t=e?.baseUrl??(typeof window<"u"?window.location.origin:""),n={"Content-Type":"application/json",...e?.headers},r=e?.fetch??globalThis.fetch.bind(globalThis);return{async callTool(o,s){let i=await r(`${t}/mcp/tools/call`,{method:"POST",headers:n,body:JSON.stringify({jsonrpc:"2.0",method:"tools/call",params:{name:o,arguments:s}})});if(!i.ok)throw Error(`MCP tool call failed: ${i.status} ${i.statusText}`);let a=await i.json();if(a.error)throw Error(a.error.message??"MCP tool call returned error");let l=a.result?.content??a.content??[];for(let c of l)if(c.type==="text"&&c.text!==void 0){try{let u=JSON.parse(c.text);if(typeof u==="object"&&u!==null&&"$prefab"in u)return u;return u}catch{}return c.text}return a.result??a},async sendMessage(o){await r(`${t}/mcp/messages`,{method:"POST",headers:n,body:JSON.stringify({message:o})})}}}function et(){return{callTool(e){return P.warn(`No MCP transport: callTool('${e}') ignored`),Promise.resolve(null)},sendMessage(e){return P.warn("No MCP transport: sendMessage ignored",e),Promise.resolve()}}}var Tn="0.3.11";function hs(e){return e!==null&&typeof e==="object"&&e.jsonrpc==="2.0"}class me{hostOrigin;listeners=new Map;protocol="prefab";cleanup;pending=new Map;callIdCounter=0;rpcPending=new Map;rpcIdCounter=0;sentRpcIds=new Set;postFn;_hostSupportsSubscriptions=!1;constructor(e="*"){this.hostOrigin=e}connect(){if(typeof window>"u")return;let e=Cs();if(e)this.postFn=(n)=>e.postMessage(n);let t=(n)=>{if(this.hostOrigin!=="*"&&n.origin!==this.hostOrigin)return;let r=n.data;if(hs(r)){this.handleJsonRpc(r);return}let o=r;if(!o?.type.startsWith("prefab:"))return;if(o.type==="prefab:tool-call-response"&&o.id){let i=this.pending.get(o.id);if(i){if(this.pending.delete(o.id),o.payload?.error!=null)i.reject(Error(o.payload.error));else i.resolve(o.payload?.result);return}}let s=this.listeners.get(o.type);if(s)for(let i of s)i(o.payload??{})};window.addEventListener("message",t),this.cleanup=()=>window.removeEventListener("message",t)}async initialize(e){try{return await Promise.any([this.initPrefab(e),this.initJsonRpc(e)])}catch(t){let n=t instanceof AggregateError?t.errors.map((r)=>r.message).join("; "):String(t);throw Error(`Bridge init failed — no host responded. Tried: ${n}`,{cause:t})}}createTransport(){if(this.protocol==="jsonrpc")return this.createJsonRpcTransport();return this.createPrefabTransport()}requestMode(e){if(this.protocol==="jsonrpc")this.sendRpcRequest("ui/request-display-mode",{mode:e});else this.sendPrefab("prefab:request-mode",{mode:e})}openLink(e,t){if(this.protocol==="jsonrpc")this.sendRpcRequest("ui/open-link",{url:e,target:t});else this.sendPrefab("prefab:open-link",{url:e,target:t})}updateContext(e){if(this.protocol==="jsonrpc")this.sendRpcRequest("ui/update-model-context",{structuredContent:e});else this.sendPrefab("prefab:update-context",{context:e})}setupAutoResize(e){if(typeof ResizeObserver>"u")return bs;let t=-1,n=-1,r=(i,a)=>{if(i===t&&a===n)return;if(t=i,n=a,this.protocol==="jsonrpc")this.sendRpcNotification("ui/notifications/size-changed",{width:i,height:a});else this.sendPrefab("prefab:size-changed",{width:i,height:a})},o=new ResizeObserver((i)=>{for(let a of i)if(a.borderBoxSize.length){let l=a.borderBoxSize[0];r(Math.ceil(l.inlineSize),Math.ceil(l.blockSize))}else{let l=a.target.getBoundingClientRect();r(Math.ceil(l.width),Math.ceil(l.height))}});o.observe(e);let s=e.getBoundingClientRect();return r(Math.ceil(s.width),Math.ceil(s.height)),()=>o.disconnect()}notifyPreferredSize(e){if(this.protocol==="jsonrpc")this.sendRpcNotification("ui/notifications/preferred-size",e);else this.sendPrefab("prefab:preferred-size",e)}subscribe(e,t){let n=(r)=>{if(r.uri!==e)return;t(r.contents??r.data??r)};if(this.protocol==="jsonrpc")this.on("prefab:resource-updated",n),this.sendRpcRequest("resources/subscribe",{uri:e});else this.on("prefab:resource-updated",n),this.sendPrefab("prefab:subscribe",{uri:e});return()=>{if(this.off("prefab:resource-updated",n),this.protocol==="jsonrpc")this.sendRpcRequest("resources/unsubscribe",{uri:e});else this.sendPrefab("prefab:unsubscribe",{uri:e})}}get supportsSubscriptions(){return this._hostSupportsSubscriptions}on(e,t){if(!this.listeners.has(e))this.listeners.set(e,new Set);let n=this.listeners.get(e);if(n)n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}disconnect(){this.cleanup?.(),this.listeners.clear();for(let[,e]of this.pending)e.reject(Error("Bridge disconnected"));this.pending.clear();for(let[,e]of this.rpcPending)e.reject(Error("Bridge disconnected"));this.rpcPending.clear(),this.sentRpcIds.clear()}get activeProtocol(){return this.protocol}initPrefab(e){return new Promise((t,n)=>{let r=!1,o=(s)=>{if(r)return;r=!0,this.off("prefab:init-response",o),this.protocol="prefab";let i=s.capabilities;this._hostSupportsSubscriptions=i?.subscriptions===!0,t(s)};this.on("prefab:init-response",o),this.sendPrefab("prefab:init",{capabilities:e}),setTimeout(()=>{if(!r)r=!0,this.off("prefab:init-response",o),n(Error("prefab:init timeout"))},2000)})}createPrefabTransport(){return{callTool:(e,t)=>{let n=`tc-${++this.callIdCounter}`;return new Promise((r,o)=>{this.pending.set(n,{resolve:r,reject:o}),this.sendPrefab("prefab:tool-call",{tool:e,arguments:t},n),setTimeout(()=>{if(this.pending.has(n))this.pending.delete(n),o(Error(`Tool call '${e}' timed out`))},30000)})},sendMessage:(e)=>(this.sendPrefab("prefab:send-message",{message:e}),Promise.resolve()),subscribe:(e,t)=>this.subscribe(e,t),capabilities:{subscriptions:this._hostSupportsSubscriptions}}}sendPrefab(e,t,n){if(typeof window>"u")return;let r=window.parent!==window?window.parent:window,o={type:e,payload:t,id:n};r.postMessage(o,this.hostOrigin)}handleJsonRpc(e){if(!("method"in e)){let r=this.rpcPending.get(e.id);if(r)if(this.rpcPending.delete(e.id),e.error)r.reject(Error(e.error.message));else r.resolve(e.result);return}let t=e.method,n=e.params??{};if(e.id!=null&&this.sentRpcIds.delete(e.id))return;if(e.id!=null)this.postJsonRpc({jsonrpc:"2.0",id:e.id,result:{}});switch(t){case"ui/notifications/tool-input":this.dispatch("prefab:tool-input",{args:n.arguments??n});break;case"ui/notifications/tool-input-partial":this.dispatch("prefab:tool-input-partial",{args:n.arguments??n});break;case"ui/notifications/tool-result":this.dispatch("prefab:tool-result",{result:n});break;case"ui/notifications/tool-cancelled":this.dispatch("prefab:tool-cancelled",n);break;case"ui/notifications/host-context-changed":{let r={};if(typeof n.theme==="string")r.colorScheme=n.theme;if(typeof n.styles==="object"&&n.styles!==null){let o=n.styles;if(o.variables)r.variables=o.variables;if(typeof o.css?.fonts==="string")r.fontCss=o.css.fonts}this.dispatch("prefab:theme-update",r),this.dispatch("prefab:host-context-changed",n);break}case"ui/resource-teardown":this.dispatch("prefab:teardown",n);break;case"ui/notifications/resource-updated":case"notifications/resources/updated":this.dispatch("prefab:resource-updated",n);break}}initJsonRpc(e){return new Promise((t,n)=>{let r=++this.rpcIdCounter,o=!1;this.rpcPending.set(r,{resolve:(s)=>{if(o)return;o=!0,this.protocol="jsonrpc";let i=s??{},a=i.hostInfo??{},l=i.hostContext??{},c=i.hostCapabilities??{},u;if(typeof l.theme==="string"||typeof l.styles==="object"){if(u={},typeof l.theme==="string")u.colorScheme=l.theme;if(typeof l.styles==="object"&&l.styles!==null){let g=l.styles;if(g.variables)u.variables=g.variables;if(typeof g.css?.fonts==="string")u.fontCss=g.css.fonts}}this.postJsonRpc({jsonrpc:"2.0",method:"ui/notifications/initialized",params:{}});let d=c.resources;this._hostSupportsSubscriptions=c.subscriptions===!0||d?.subscribe===!0,t({hostName:a.name,hostVersion:a.version,capabilities:{toast:!0,navigation:c.openLinks!=null,messaging:!0,displayModes:l.availableDisplayModes??[]},theme:u,toolInput:void 0,meta:l})},reject:(s)=>{if(o)return;o=!0,n(s)}}),this.postJsonRpc({jsonrpc:"2.0",id:r,method:"ui/initialize",params:{protocolVersion:"2026-01-26",appInfo:{name:"prefab",version:Tn},appCapabilities:{...e.displayModes&&{availableDisplayModes:e.displayModes}}}}),setTimeout(()=>{if(!o)o=!0,this.rpcPending.delete(r),n(Error("ui/initialize timeout"))},2000)})}createJsonRpcTransport(){return{callTool:(e,t)=>this.sendRpcRequest("tools/call",{name:e,arguments:t}),sendMessage:(e)=>this.sendRpcRequest("ui/message",{role:"user",content:{type:"text",text:e}}),subscribe:(e,t)=>this.subscribe(e,t),capabilities:{subscriptions:this._hostSupportsSubscriptions}}}sendRpcRequest(e,t){let n=++this.rpcIdCounter;return new Promise((r,o)=>{this.rpcPending.set(n,{resolve:r,reject:o}),this.postJsonRpc({jsonrpc:"2.0",id:n,method:e,params:t}),setTimeout(()=>{if(this.rpcPending.has(n))this.rpcPending.delete(n),o(Error(`JSON-RPC '${e}' timed out`))},30000)})}sendRpcNotification(e,t){this.postJsonRpc({jsonrpc:"2.0",method:e,params:t})}postJsonRpc(e){if(typeof window>"u")return;if(e.id!=null&&typeof e.method==="string")this.sentRpcIds.add(e.id);if(this.postFn)this.postFn(e);else(window.parent!==window?window.parent:window).postMessage(e,this.hostOrigin)}dispatch(e,t){let n=this.listeners.get(e);if(n)for(let r of n)r(t)}}var bs=()=>{};function Ne(e,t){if(t.variables)for(let[n,r]of Object.entries(t.variables))e.style.setProperty(n.startsWith("--")?n:`--${n}`,r);if(t.colorScheme&&t.colorScheme!=="auto")e.setAttribute("data-theme",t.colorScheme);if(t.fontCss)ys(t.fontCss)}function ys(e){if(document.getElementById("__prefab-host-fonts"))return;let n=document.createElement("style");n.id="__prefab-host-fonts",n.textContent=e,document.head.appendChild(n)}function Ce(){if(typeof window>"u")return!1;try{return window.self!==window.top}catch{return!0}}function Cs(){if(typeof window>"u")return;let e=window;if(typeof e.acquireVsCodeApi==="function")try{let t=e.acquireVsCodeApi();if(t!==null&&typeof t==="object"&&"postMessage"in t)return t}catch{return}return}async function tt(e){Ze();let t=e?.mode??"auto",n=t==="bridge"||t==="auto"&&Ce(),r,o,s={capabilities:{}};if(n)o=new me(e?.hostOrigin),o.connect(),s=await o.initialize(e?.capabilities??{toolInput:!0}),r=o.createTransport();else if(e?.transport)r=Qe(e.transport);else r=et();if(s.theme&&typeof document<"u")Ne(document.documentElement,s.theme);if(typeof document<"u"&&!o)ws();let i,a,l,c,u,d=s.toolInput,g;if(o)o.on("prefab:tool-input",(f)=>{let b=f.args??f;if(i)i(b);else d=b}),o.on("prefab:tool-result",(f)=>{let b=f.result??f;if(a)a(b);else g=b}),o.on("prefab:tool-cancelled",()=>{l?.()}),o.on("prefab:tool-input-partial",(f)=>{c?.(f.args??f)}),o.on("prefab:theme-update",(f)=>{if(typeof document<"u")Ne(document.documentElement,f)}),o.on("prefab:host-context-changed",(f)=>{u?.(f)});function h(f,...b){let w=Nt(f),S=new we,N={store:S,scope:{},transport:r,rerender:()=>k(),onToast:void 0};function k(){w.innerHTML="";for(let R of b)w.appendChild(J(R,N))}return k(),{rerender:k,store:S,destroy:()=>{w.innerHTML=""}}}return{callTool:(f,b={})=>r.callTool(f,b),sendMessage:(f)=>r.sendMessage(f),onToolInput:(f)=>{if(i=f,d){let b=d;d=void 0,queueMicrotask(()=>f(b))}},onToolResult:(f)=>{if(a=f,g!==void 0){let b=g;g=void 0,queueMicrotask(()=>f(b))}},onToolCancelled:(f)=>{l=f},onToolInputPartial:(f)=>{c=f},onHostContextChanged:(f)=>{u=f},render:h,mount:(f,b,w)=>{let S=Nt(f);return ne.mount(S,b,{transport:r,...w})},requestMode:(f)=>o?.requestMode(f),openLink:(f,b)=>{if(o)o.openLink(f,b);else if(typeof window<"u")window.open(f,b??"_blank")},updateContext:(f)=>{if(o)o.updateContext(f)},setupAutoResize:(f)=>{if(!o)return vs;let b=typeof f==="string"?Nt(f):f;return o.setupAutoResize(b)},notifyPreferredSize:(f)=>{if(o)o.notifyPreferredSize(f)},host:s,capabilities:s.capabilities,theme:s.theme,transport:r,destroy:()=>o?.disconnect()}}var vs=()=>{};function Nt(e){if(typeof e==="string"){if(typeof document>"u")throw Error("Cannot resolve selector outside browser");let t=document.querySelector(e);if(!t)throw Error(`Element not found: ${e}`);return t}return e}function ws(){function e(){let n=document.body.getAttribute("data-vscode-theme-kind");if(!n)return;let r=n.includes("light")?"light":"dark";document.documentElement.setAttribute("data-theme",r)}e(),new MutationObserver(e).observe(document.body,{attributes:!0,attributeFilter:["data-vscode-theme-kind"]})}var Nn=["Accordion","AccordionItem","Alert","AlertDescription","AlertTitle","AreaChart","Audio","Badge","BarChart","BlockQuote","Button","ButtonGroup","Calendar","Card","CardContent","CardDescription","CardFooter","CardHeader","CardTitle","Carousel","Checkbox","ChoiceCard","Code","Column","Combobox","ComboboxGroup","ComboboxLabel","ComboboxOption","ComboboxSeparator","Condition","Container","Dashboard","DashboardItem","DataTable","DatePicker","Define","Detail","Dialog","Div","Dot","DropZone","Elif","Else","Embed","ExpandableRow","Field","FieldContent","FieldDescription","FieldError","FieldTitle","ForEach","Form","Grid","GridItem","H1","H2","H3","H4","Heading","Histogram","HoverCard","Icon","If","Image","Input","Kbd","Label","Large","Lead","LineChart","Link","Loader","Markdown","MasterDetail","Mermaid","Metric","Muted","P","Page","Pages","PdfViewer","PieChart","Popover","Progress","RadarChart","RadialChart","Radio","RadioGroup","Ring","Row","ScatterChart","Select","SelectGroup","SelectLabel","SelectOption","SelectSeparator","Separator","Slider","Slot","Small","Span","Sparkline","Svg","Switch","Tab","Table","TableBody","TableCaption","TableCell","TableFooter","TableHead","TableHeader","TableRow","Tabs","Text","Textarea","Tooltip","Use","Video"];var Hn=new Set(Nn);function ve(e,t={}){let n=[],r=t.strict??!1;if(e==null||typeof e!=="object")return n.push({path:"$",message:"Wire data must be a non-null object"}),{valid:!1,errors:n};let o=e;if(o.$prefab==null||typeof o.$prefab!=="object")n.push({path:"$.$prefab",message:"Missing or invalid $prefab header"});else if(typeof o.$prefab.version!=="string")n.push({path:"$.$prefab.version",message:"version must be a string"});if(o.view==null)n.push({path:"$.view",message:'Missing required "view" field'});else Mt(o.view,"$.view",n,r);if(o.state!==void 0){if(o.state===null||typeof o.state!=="object"||Array.isArray(o.state))n.push({path:"$.state",message:"state must be a plain object"})}if(o.theme!==void 0)ks(o.theme,n);if(o.css!==void 0)Ln(o.css,"$.css",n);if(o.stylesheets!==void 0)Ln(o.stylesheets,"$.stylesheets",n);if(o.mode!==void 0&&o.mode!=="light"&&o.mode!=="dark")n.push({path:"$.mode",message:'mode must be "light" or "dark"'});if(o.defs!==void 0)if(o.defs===null||typeof o.defs!=="object"||Array.isArray(o.defs))n.push({path:"$.defs",message:"defs must be a plain object"});else for(let[s,i]of Object.entries(o.defs))Mt(i,`$.defs.${s}`,n,r);if(o.keyBindings!==void 0)if(o.keyBindings===null||typeof o.keyBindings!=="object"||Array.isArray(o.keyBindings))n.push({path:"$.keyBindings",message:"keyBindings must be a plain object"});else for(let[s,i]of Object.entries(o.keyBindings))Lt(i,`$.keyBindings.${s}`,n);return{valid:n.length===0,errors:n}}function Pn(e){return ve(e).valid}function Mt(e,t,n,r){if(e==null||typeof e!=="object"||Array.isArray(e)){n.push({path:t,message:"Component must be a plain object"});return}let o=e;if(typeof o.type!=="string"||o.type.length===0){n.push({path:`${t}.type`,message:'Component must have a non-empty "type" string'});return}if(r&&!Hn.has(o.type))n.push({path:`${t}.type`,message:`Unknown component type: "${o.type}"`});if(o.children!==void 0)if(!Array.isArray(o.children))n.push({path:`${t}.children`,message:"children must be an array"});else for(let i=0;i<o.children.length;i++)Mt(o.children[i],`${t}.children[${i}]`,n,r);let s=["onClick","on_click","onChange","on_change","onSubmit","on_submit","onMount","on_mount","onClose","on_close"];for(let i of s)if(o[i]!==void 0)Lt(o[i],`${t}.${i}`,n);for(let[i,a]of Object.entries(o)){if(i==="type"||xs.has(i)||s.includes(i))continue;if(Mn(a)||Array.isArray(a)&&a.some(Mn))n.push({path:`${t}.${i}`,message:`Components under "${i}" are ignored by the renderer; move them into "children"`})}}var xs=new Set(["children","fallback","trigger","empty","else","summary"]);function Mn(e){if(e==null||typeof e!=="object"||Array.isArray(e))return!1;let t=e.type;return typeof t==="string"&&Hn.has(t)}function Lt(e,t,n){if(Array.isArray(e)){for(let a=0;a<e.length;a++)Lt(e[a],`${t}[${a}]`,n);return}if(e==null||typeof e!=="object"){n.push({path:t,message:"Action must be an object or array of objects"});return}let r=e,o=typeof r.type==="string"&&r.type.length>0,s=typeof r.action==="string"&&r.action.length>0;if(!o&&!s){n.push({path:`${t}.type`,message:'Action must have a non-empty "type" or "action" string'});return}if((s?r.action:r.type).toLowerCase()==="showtoast"){if(typeof r.message!=="string"||r.message.length===0)n.push({path:`${t}.message`,message:'showToast requires a non-empty "message" string'})}}function Ln(e,t,n){if(!Array.isArray(e)){n.push({path:t,message:`${t} must be an array of strings`});return}for(let r=0;r<e.length;r++)if(typeof e[r]!=="string")n.push({path:`${t}[${r}]`,message:"must be a string"})}function ks(e,t){if(e===null||typeof e!=="object"||Array.isArray(e)){t.push({path:"$.theme",message:"theme must be a plain object"});return}let n=e;for(let r of["light","dark"])if(n[r]!==void 0){if(n[r]===null||typeof n[r]!=="object"||Array.isArray(n[r]))t.push({path:`$.theme.${r}`,message:`theme.${r} must be a plain object`})}}var ne={mount(e,t,n){if(Ze(),n?.validate!==!1)for(let b of ve(t).errors)P.warn(`wire validation ${b.path}: ${b.message}`);let r=t,o={tracked:[],evalBlocked:!1};if(r.pipes)for(let[b,w]of Object.entries(r.pipes))$n(b,w,o);let s=new we(r.state),i;if(n?.transport&&"callTool"in n.transport)i=n.transport;else if(n?.transport)i=Qe(n.transport);else i=et();let a=n?.onToast??As,l=new Se;function c(b){let w=b;if(r=w,w.state)s.merge(w.state);if(w.defs)u.defs=w.defs;if(w.theme)Rt(e,w.theme);if(w.mode)On(e,w.mode);if(w.pipes)for(let[S,N]of Object.entries(w.pipes))$n(S,N,o);for(let S of d)S.remove();if(d.length=0,d.push(...Dn(w.css,w.stylesheets)),jn(e,w.layout),g?.(),g=void 0,w.keyBindings)g=Tt(w.keyBindings,(S)=>{F(j(S,{store:s,transport:i,scope:{},rerender:()=>f(),remount:c,onToast:a}),"keyBinding")});f()}let u={store:s,scope:{},transport:i,rerender:()=>f(),remount:c,onToast:a,defs:r.defs,destroyRegistry:l};if(Rt(e,r.theme),r.mode)On(e,r.mode);jn(e,r.layout);let d=Dn(r.css,r.stylesheets),g;if(r.keyBindings)g=Tt(r.keyBindings,(b)=>{F(j(b,{store:s,transport:i,scope:{},rerender:()=>f(),remount:c,onToast:a}),"keyBinding")});let h,y=n?.themeToggle??!0;if(y!==!1)h=Te(e,typeof y==="object"?y:void 0);function f(){l.flush();let b=e.querySelector(".pf-theme-toggle");e.innerHTML="";let w=J(r.view,u);if(e.appendChild(w),b)e.appendChild(b)}return f(),{rerender:()=>f(),update(b){if(s.merge(b.update.state),f(),b.update.actions!=null)F(j(b.update.actions,u),"update action")},store:s,destroy(){l.flush(),h?.(),g?.(),Bt(),Jt();for(let b of d)b.remove();for(let b of o.tracked)ke(b);e.innerHTML=""}}},isPrefabData(e){return e!=null&&typeof e==="object"&&"$prefab"in e},isPrefabUpdate(e){return e!=null&&typeof e==="object"&&"$prefab"in e&&"update"in e}},Ss=new Set(["find","dot","length","upper","lower","truncate","join","first","last","abs","round","number","currency","percent","compact","date","time","datetime","pluralize","default","selectattr","rejectattr"]);function Es(e){if(e instanceof EvalError)return!0;return e instanceof Error&&/unsafe-eval|Content Security Policy|call to Function/i.test(e.message)}function $n(e,t,n){if(Ss.has(e)){P.warn(`wire pipe "${e}" ignored — shadows built-in`);return}if(He(e)!=null){P.debug(`wire pipe "${e}" — already registered, keeping local implementation`);return}if(n.evalBlocked)return;try{let r=Function("return ("+t+")")();if(typeof r!=="function"){P.warn(`wire pipe "${e}" — source did not evaluate to a function`);return}xe(e,r),n.tracked.push(e)}catch(r){if(Es(r)){n.evalBlocked=!0,P.warn("wire pipes cannot be hydrated — this host's CSP forbids eval. Pre-register them with "+"prefab.registerPipe() from a companion script (rendererHtml({ scripts })) and they are used as-is.");return}P.warn(`wire pipe "${e}" — failed to hydrate:`,r)}}function As(e){if(typeof document>"u")return;let t=Ts(),n=document.createElement("div"),r=e.variant??"default";n.className=`pf-toast${r!=="default"?` pf-toast--${r}`:""}`,n.setAttribute("data-variant",r),n.style.marginBottom="8px",n.style.transition="opacity 0.3s ease";let o=document.createElement("div");if(o.textContent=e.message,o.style.fontWeight="500",n.appendChild(o),e.description){let i=document.createElement("div");i.textContent=e.description,i.style.fontSize="14px",i.style.color="var(--muted-foreground, #6b7280)",n.appendChild(i)}t.appendChild(n);let s=e.duration??4000;setTimeout(()=>{n.style.opacity="0",setTimeout(()=>n.remove(),300)},s)}function On(e,t){if(ye(e,t),typeof document<"u")ye(document.documentElement,t)}function Rs(e){let t=e.trim();if(t.includes("{")||t.includes("}"))return!1;return/^(https?:)?\/\//i.test(t)||t.startsWith("/")||/\.css(\?|#|$)/i.test(t)}function Dn(e,t){let n=[];if(typeof document>"u")return n;for(let r of e??[]){let o=document.createElement("style");o.textContent=r,o.dataset.prefab="injected",document.head.appendChild(o),n.push(o)}for(let r of t??[])if(Rs(r)){let o=document.createElement("link");o.rel="stylesheet",o.href=r,o.dataset.prefab="injected",document.head.appendChild(o),n.push(o)}else{let o=document.createElement("style");o.textContent=r,o.dataset.prefab="injected",document.head.appendChild(o),n.push(o)}return n}function jn(e,t){if(e.style.height="",e.style.minHeight="",e.style.maxHeight="",e.style.overflow="",!t)return;if(t.preferredHeight!=null)e.style.height=`${t.preferredHeight}px`;if(t.minHeight!=null)e.style.minHeight=`${t.minHeight}px`;if(t.maxHeight!=null)e.style.maxHeight=`${t.maxHeight}px`,e.style.overflow="auto"}function Ts(){let t=document.getElementById("prefab-toast-container");if(!t)t=document.createElement("div"),t.id="prefab-toast-container",t.style.position="fixed",t.style.bottom="16px",t.style.right="16px",t.style.zIndex="9999",t.style.maxWidth="400px",document.body.appendChild(t);return t}if(typeof window<"u"){let e=window;e.PrefabRenderer=ne,e.prefab={app:tt,mount:ne.mount.bind(ne),isPrefabData:ne.isPrefabData.bind(ne),isPrefabUpdate:ne.isPrefabUpdate.bind(ne),Bridge:me,isIframe:Ce,registerPipe:xe,unregisterPipe:ke,listPipes:Le,registerComponent:p,createThemeToggle:Te,validateWireFormat:ve,setLogLevel:Me};let t=e.__PREFAB_DATA__;if(t!=null){let n=document.getElementById("prefab-root");if(n)ne.mount(n,t)}}})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maxhealth.tech/prefab",
3
- "version": "0.3.10",
3
+ "version": "0.3.11",
4
4
  "description": "TypeScript authoring for A2UI and MCP Apps. Build agent UIs server-side and emit either wire format.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -65,6 +65,7 @@
65
65
  "gen:skill": "bun run scripts/gen-skill-assets.ts",
66
66
  "gen:types": "bun run scripts/gen-component-types.ts",
67
67
  "check:docs": "bun run scripts/check-doc-examples.ts",
68
+ "check:changelog": "bun run scripts/check-changelog.ts",
68
69
  "docs:api": "typedoc && bun run scripts/fix-typedoc-vue.ts",
69
70
  "predocs:dev": "bun run docs:api",
70
71
  "docs:dev": "vitepress dev docs",