1package mcp23// viewScript is the view's side of both hosts' protocols. With4// window.openai (the Apps SDK) it draws toolResponseMetadata's view, takes the5// theme, maxHeight and displayMode from it and from openai:set_globals6// events, and reports its height with notifyIntrinsicHeight. Otherwise7// it speaks MCP Apps over postMessage: ui/initialize with its info and8// display modes, then ui/notifications/initialized; it draws the9// view in the _meta of ui/notifications/tool-result, follows the10// hostContext's theme, containerDimensions and displayMode as they11// change, answers ping and ui/resource-teardown, and sends12// ui/notifications/size-changed as its content's size changes,13// measured as the extension's SDK measures it.14//15// The grid scrolls inside the room it's given: inline, at most 48016// pixels, less when the host's maximum height less the panel's is17// smaller, so a view in a conversation stays a glance; the whole frame18// when the host fixes its height or shows it full screen. A smaller19// range takes only its own height.20const viewScript = `(function(){21var doc=document.documentElement,view=document.getElementById("o12-view"),oai=window.openai;22var room=0,fill=false,shown=null,next=1,lastW=0,lastH=0,sizing=false;23function theme(t){doc.classList.remove("dark","light");if(t==="dark"||t==="light")doc.classList.add(t)}24function send(m){window.parent.postMessage(Object.assign({jsonrpc:"2.0"},m),"*")}25function fit(){26 var sh=view.querySelector(".sheet"),p=document.querySelector(".panel");if(!sh)return;27 var top=p?p.offsetHeight:0,h=fill?window.innerHeight-top:Math.min(room>0?room-top:480,480);28 sh.style.maxHeight=Math.max(h,84)+"px";29}30function measure(){31 var old=doc.style.height;doc.style.height="max-content";32 var h=Math.ceil(doc.getBoundingClientRect().height);doc.style.height=old;return h;33}34function size(){35 if(sizing)return;sizing=true;36 requestAnimationFrame(function(){37 sizing=false;var w=Math.ceil(window.innerWidth),h=measure();38 if(w===lastW&&h===lastH)return;lastW=w;lastH=h;39 if(oai){if(typeof oai.notifyIntrinsicHeight==="function")oai.notifyIntrinsicHeight(h)}40 else send({method:"ui/notifications/size-changed",params:{width:w,height:h}});41 });42}43function show(v){44 if(!v||typeof v.html!=="string"||v===shown)return;45 shown=v;view.innerHTML=v.html;46 var b=document.querySelector(".panel .book"),c=document.getElementById("o12-context"),n=document.getElementById("o12-name");47 if(b)b.textContent=v.title||"";if(c)c.textContent=v.where||"";if(n)n.textContent=v.name||"";48 var first=view.querySelector("td[data-a]");if(first&&window.o12point)window.o12point(first);49 fit();size();50}51function viewOf(meta){return meta&&meta["o12/view"]}52function context(hc){53 if(!hc)return;if(hc.theme)theme(hc.theme);54 var d=hc.containerDimensions;55 if(d){fill=typeof d.height==="number";room=typeof d.maxHeight==="number"?d.maxHeight:0}56 if(hc.displayMode)fill=fill||hc.displayMode==="fullscreen";57 fit();size();58}59function globals(g){60 if(!g)return;if(g.theme)theme(g.theme);61 if(typeof g.maxHeight==="number")room=g.maxHeight;62 if(g.displayMode)fill=g.displayMode==="fullscreen";63 if(g.toolResponseMetadata)show(viewOf(g.toolResponseMetadata));64 fit();size();65}66window.addEventListener("message",function(e){67 var m=e.data;if(!m||m.jsonrpc!=="2.0"||oai)return;68 if(m.id===1&&(m.result||m.error)){if(m.result)context(m.result.hostContext);send({method:"ui/notifications/initialized",params:{}});return}69 switch(m.method){70 case "ui/notifications/tool-result":show(viewOf(m.params&&m.params._meta));break;71 case "ui/notifications/host-context-changed":context(m.params);break;72 case "ui/resource-teardown":case "ping":send({id:m.id,result:{}});break;73 }74});75window.addEventListener("openai:set_globals",function(e){if(e.detail)globals(e.detail.globals)});76window.addEventListener("resize",function(){fit();size()});77new ResizeObserver(size).observe(document.body);78if(oai)globals(oai);79else send({id:next++,method:"ui/initialize",params:{protocolVersion:"2026-01-26",appInfo:{name:"012",version:"1"},appCapabilities:{availableDisplayModes:["inline","fullscreen"]}}});80size();81})();82`