@womp/mcp-ui 0.2.1 → 0.2.2

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.
@@ -1780,7 +1780,7 @@ Boolean requesting whether a visible border and background is provided by the ho
1780
1780
  - omitted: host decides border`)}),G({method:J(`ui/request-display-mode`),params:G({mode:ix.describe(`The display mode being requested.`)})}),xx=G({mode:ix.describe(`The display mode that was actually set. May differ from requested if not supported.`)}).passthrough(),Sx=K([J(`model`),J(`app`)]).describe(`Tool visibility scope - who can access the tool.`),G({resourceUri:B().optional(),visibility:W(Sx).optional().describe(`Who can access this tool. Default: ["model", "app"]
1781
1781
  - "model": Tool visible to and callable by the agent
1782
1782
  - "app": Tool callable by the app from this server only`),csp:Ym().optional(),permissions:Ym().optional()}),G({mimeTypes:W(B()).optional().describe('Array of supported MIME types for UI resources.\nMust include `"text/html;profile=mcp-app"` for MCP Apps support.')}),G({method:J(`ui/download-file`),params:G({contents:W(K([Wv,Gv])).describe(`Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.`)})}),G({method:J(`ui/message`),params:G({role:J(`user`).describe(`Message role, currently only "user" is supported.`),content:W(Kv).describe(`Message content blocks (text, image, etc.).`)})}),G({method:J(`ui/notifications/sandbox-resource-ready`),params:G({html:B().describe(`HTML content to load into the inner iframe.`),sandbox:B().optional().describe(`Optional override for the inner iframe's sandbox attribute.`),csp:ux.optional().describe(`CSP configuration from resource metadata.`),permissions:dx.optional().describe(`Sandbox permissions from resource metadata.`)})}),Cx=G({method:J(`ui/notifications/tool-result`),params:ty.describe(`Standard MCP tool execution result.`)}),wx=G({toolInfo:G({id:y_.optional().describe(`JSON-RPC id of the tools/call request.`),tool:Qv.describe(`Tool definition including name, inputSchema, etc.`)}).optional().describe(`Metadata of the tool call that instantiated this App.`),theme:rx.optional().describe(`Current color theme preference.`),styles:gx.optional().describe(`Style configuration for theming the app.`),displayMode:ix.optional().describe(`How the UI is currently displayed.`),availableDisplayModes:W(ix).optional().describe(`Display modes the host supports.`),containerDimensions:K([G({height:V().describe(`Fixed container height in pixels.`)}),G({maxHeight:K([V(),Km()]).optional().describe(`Maximum container height in pixels.`)})]).and(K([G({width:V().describe(`Fixed container width in pixels.`)}),G({maxWidth:K([V(),Km()]).optional().describe(`Maximum container width in pixels.`)})])).optional().describe(`Container dimensions. Represents the dimensions of the iframe or other
1783
- container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:B().optional().describe(`User's language and region preference in BCP 47 format.`),timeZone:B().optional().describe(`User's timezone in IANA format.`),userAgent:B().optional().describe(`Host application identifier.`),platform:K([J(`web`),J(`desktop`),J(`mobile`)]).optional().describe(`Platform type for responsive design decisions.`),deviceCapabilities:G({touch:H().optional().describe(`Whether the device supports touch input.`),hover:H().optional().describe(`Whether the device supports hover interactions.`)}).optional().describe(`Device input capabilities.`),safeAreaInsets:G({top:V().describe(`Top safe area inset in pixels.`),right:V().describe(`Right safe area inset in pixels.`),bottom:V().describe(`Bottom safe area inset in pixels.`),left:V().describe(`Left safe area inset in pixels.`)}).optional().describe(`Mobile safe area boundaries in pixels.`)}).passthrough(),Tx=G({method:J(`ui/notifications/host-context-changed`),params:wx.describe(`Partial context update containing only changed fields.`)}),G({method:J(`ui/update-model-context`),params:G({content:W(Kv).optional().describe(`Context content blocks (text, image, etc.).`),structuredContent:q(B(),U().describe(`Structured content for machine-readable context data.`)).optional().describe(`Structured content for machine-readable context data.`)})}),G({method:J(`ui/initialize`),params:G({appInfo:F_.describe(`App identification (name and version).`),appCapabilities:bx.describe(`Features and capabilities this app provides.`),protocolVersion:B().describe(`Protocol version this app supports.`)})}),Ex=G({protocolVersion:B().describe(`Negotiated protocol version string (e.g., "2025-11-21").`),hostInfo:F_.describe(`Host application identification and version.`),hostCapabilities:yx.describe(`Features and capabilities provided by the host.`),hostContext:wx.describe(`Rich context about the host environment.`)}).passthrough(),Dx={target:`draft-2020-12`},Ox=class e extends ex{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;_registeredTools={};_initializedSent=!1;_assertInitialized(e){if(this._initializedSent)return;let t=`[ext-apps] App.${e}() called before connect() completed the ui/initialize handshake. Await app.connect() before calling this method, or move data loading to an ontoolresult handler.`;if(this.options?.strict)throw Error(t);console.warn(`${t}. This will throw in a future release.`)}eventSchemas={toolinput:fx,toolinputpartial:px,toolresult:Cx,toolcancelled:mx,hostcontextchanged:Tx};static ONE_SHOT_EVENTS=new Set([`toolinput`,`toolinputpartial`,`toolresult`,`toolcancelled`]);_everHadListener=new Set;_assertHandlerTiming(t){if(!e.ONE_SHOT_EVENTS.has(t)||this._everHadListener.has(t)||(this._everHadListener.add(t),!this._initializedSent))return;let n=`[ext-apps] "${String(t)}" handler registered after connect() completed the ui/initialize handshake. The host may have already sent this notification. Register handlers before calling app.connect().`;if(this.options?.strict)throw Error(n);console.warn(n)}setEventHandler(e,t){t&&this._assertHandlerTiming(e),super.setEventHandler(e,t)}addEventListener(e,t){this._assertHandlerTiming(e),super.addEventListener(e,t)}onEventDispatch(e,t){e===`hostcontextchanged`&&(this._hostContext={...this._hostContext,...t})}constructor(e,t={},n={autoResize:!0}){super(n),this._appInfo=e,this._capabilities=t,this.options=n,n.allowUnsafeEval||Wi({jitless:!0}),this.setRequestHandler(K_,e=>(console.log(`Received ping:`,e.params),{})),this.setEventHandler(`hostcontextchanged`,void 0)}registerCapabilities(e){if(this.transport)throw Error(`Cannot register capabilities after transport is established`);this._capabilities=Hb(this._capabilities,e)}registerTool(e,t,n){if(this._registeredTools[e])throw Error(`Tool ${e} is already registered`);let r=this,i=()=>{r._initializedSent&&r._capabilities.tools?.listChanged&&r.sendToolListChanged()},a=t.inputSchema!==void 0,o={title:t.title,description:t.description,inputSchema:t.inputSchema,outputSchema:t.outputSchema,annotations:t.annotations,_meta:t._meta,enabled:!0,enable(){this.enabled=!0,i()},disable(){this.enabled=!1,i()},update(e){Object.assign(this,e),i()},remove(){r._registeredTools[e]===o&&(delete r._registeredTools[e],i())},handler:async(t,r)=>{if(!o.enabled)throw Error(`Tool ${e} is disabled`);let i;if(a){let a=o.inputSchema;i=await n(a?await Zb(a,t??{},`Invalid input for tool ${e}: `):t??{},r)}else i=await n(r);return o.outputSchema&&!i.isError&&(i.structuredContent=await Zb(o.outputSchema,i.structuredContent,`Invalid output for tool ${e}: `)),i}};return this._registeredTools[e]=o,!this._capabilities.tools&&!this.transport&&this.registerCapabilities({tools:{listChanged:!0}}),this.ensureToolHandlersInitialized(),i(),o}_toolHandlersInitialized=!1;ensureToolHandlersInitialized(){this._toolHandlersInitialized||(this._toolHandlersInitialized=!0,this.oncalltool=async(e,t)=>{let n=this._registeredTools[e.name];if(!n)throw Error(`Tool ${e.name} not found`);return n.handler(e.arguments,t)},this.onlisttools=async(e,t)=>({tools:await Promise.all(Object.entries(this._registeredTools).filter(([e,t])=>t.enabled).map(async([e,t])=>{let n={name:e,title:t.title,description:t.description,inputSchema:t.inputSchema?await Xb(t.inputSchema,`input`):{type:`object`,properties:{}}};return t.outputSchema&&(n.outputSchema=await Xb(t.outputSchema,`output`)),t.annotations&&(n.annotations=t.annotations),t._meta&&(n._meta=t._meta),n}))}))}async sendToolListChanged(e={}){this._assertInitialized(`sendToolListChanged`),await this.notification({method:`notifications/tools/list_changed`,params:e})}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}get ontoolinput(){return this.getEventHandler(`toolinput`)}set ontoolinput(e){this.setEventHandler(`toolinput`,e)}get ontoolinputpartial(){return this.getEventHandler(`toolinputpartial`)}set ontoolinputpartial(e){this.setEventHandler(`toolinputpartial`,e)}get ontoolresult(){return this.getEventHandler(`toolresult`)}set ontoolresult(e){this.setEventHandler(`toolresult`,e)}get ontoolcancelled(){return this.getEventHandler(`toolcancelled`)}set ontoolcancelled(e){this.setEventHandler(`toolcancelled`,e)}get onhostcontextchanged(){return this.getEventHandler(`hostcontextchanged`)}set onhostcontextchanged(e){this.setEventHandler(`hostcontextchanged`,e)}_onteardown;get onteardown(){return this._onteardown}set onteardown(e){this.warnIfRequestHandlerReplaced(`onteardown`,this._onteardown,e),this._onteardown=e,this.replaceRequestHandler(_x,(e,t)=>{if(!this._onteardown)throw Error(`No onteardown handler set`);return this._onteardown(e.params,t)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(e){this.warnIfRequestHandlerReplaced(`oncalltool`,this._oncalltool,e),this._oncalltool=e,this.replaceRequestHandler(ry,(e,t)=>{if(!this._oncalltool)throw Error(`No oncalltool handler set`);return this._oncalltool(e.params,t)})}_onlisttools;get onlisttools(){return this._onlisttools}set onlisttools(e){this.warnIfRequestHandlerReplaced(`onlisttools`,this._onlisttools,e),this._onlisttools=e,this.replaceRequestHandler($v,(e,t)=>{if(!this._onlisttools)throw Error(`No onlisttools handler set`);return this._onlisttools(e.params,t)})}assertCapabilityForMethod(e){if(e===`sampling/createMessage`&&!this._hostCapabilities?.sampling)throw Error(`Host does not support sampling (required for ${e})`)}assertRequestHandlerCapability(e){switch(e){case`tools/call`:case`tools/list`:if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${e})`);return;case`ping`:case`ui/resource-teardown`:return;default:throw Error(`No handler for method ${e} registered`)}}assertNotificationCapability(e){}assertTaskCapability(e){throw Error(`Tasks are not supported in MCP Apps`)}assertTaskHandlerCapability(e){throw Error(`Task handlers are not supported in MCP Apps`)}async callServerTool(e,t){if(this._assertInitialized(`callServerTool`),typeof e==`string`)throw Error(`callServerTool() expects an object as its first argument, but received a string ("${e}"). Did you mean: callServerTool({ name: "${e}", arguments: { ... } })?`);return await this.request({method:`tools/call`,params:e},ty,{onprogress:()=>{},resetTimeoutOnProgress:!0,...t})}async readServerResource(e,t){return this._assertInitialized(`readServerResource`),await this.request({method:`resources/read`,params:e},Ev,t)}async listServerResources(e,t){return this._assertInitialized(`listServerResources`),await this.request({method:`resources/list`,params:e},bv,t)}async createSamplingMessage(e,t){this._assertInitialized(`createSamplingMessage`);let n=e.tools?by:yy;return await this.request({method:`sampling/createMessage`,params:e},n,t)}sendMessage(e,t){return this._assertInitialized(`sendMessage`),this.request({method:`ui/message`,params:e},lx,t)}sendLog(e){return this.notification({method:`notifications/message`,params:e})}updateModelContext(e,t){return this._assertInitialized(`updateModelContext`),this.request({method:`ui/update-model-context`,params:e},k_,t)}openLink(e,t){return this._assertInitialized(`openLink`),this.request({method:`ui/open-link`,params:e},sx,t)}sendOpenLink=this.openLink;downloadFile(e,t){return this._assertInitialized(`downloadFile`),this.request({method:`ui/download-file`,params:e},cx,t)}requestTeardown(e={}){return this.notification({method:`ui/notifications/request-teardown`,params:e})}requestDisplayMode(e,t){return this._assertInitialized(`requestDisplayMode`),this.request({method:`ui/request-display-mode`,params:e},xx,t)}sendSizeChanged(e){return this.notification({method:`ui/notifications/size-changed`,params:e})}setupSizeChangedNotifications(){let e=!1,t=0,n=0,r=()=>{e||(e=!0,requestAnimationFrame(()=>{e=!1;let r=document.documentElement,i=r.style.height;r.style.height=`max-content`;let a=Math.ceil(r.getBoundingClientRect().height);r.style.height=i;let o=Math.ceil(window.innerWidth);(o!==t||a!==n)&&(t=o,n=a,this.sendSizeChanged({width:o,height:a}))}))};r();let i=new ResizeObserver(r);return i.observe(document.documentElement),i.observe(document.body),()=>i.disconnect()}async connect(e=new nx(window.parent,window.parent),t){if(this.transport)throw Error(`App is already connected. Call close() before connecting again.`);this._initializedSent=!1,await super.connect(e);try{let e=await this.request({method:`ui/initialize`,params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:tx}},Ex,t);if(e===void 0)throw Error(`Server sent invalid initialize result: ${e}`);this._hostCapabilities=e.hostCapabilities,this._hostInfo=e.hostInfo,this._hostContext=e.hostContext,await this.notification({method:`ui/notifications/initialized`}),this._initializedSent=!0,this.options?.autoResize&&this.setupSizeChangedNotifications()}catch(e){throw this.close(),e}}}}));function Ax(e,t){let n,r=0,i,a=()=>{n!==void 0&&(clearTimeout(n),n=void 0)},o=new Ox({name:e,version:`0.0.1`},{}),s=async e=>{let t=await o.request({method:`tools/call`,params:{name:`get_generation`,arguments:{operationId:e}}},ty);if(!t.isError)return t.structuredContent},c=(e,o)=>{n=window.setTimeout(async()=>{if(Date.now()-r>Rx){t.onTimeout?.();return}try{let n=await s(e);if(n?.status===`complete`){a(),i=n,t.onResult(n);return}}catch{}c(e,Math.min(o*1.5,Lx))},o)},l=e=>{e&&(a(),i=e,t.onResult(e),e.status===`running`&&e.operationId!==void 0&&(r=Date.now(),c(e.operationId,Ix)))};return o.ontoolinput=e=>{t.onInput?.(e?.arguments||{}),t.onResult({status:`running`})},o.ontoolresult=e=>l(e?.structuredContent),o.onhostcontextchanged=e=>{if(e?.theme&&Qb(e.theme),e?.styles?.variables&&$b(e.styles.variables),e?.displayMode&&(document.documentElement.dataset.displayMode=e.displayMode),e?.safeAreaInsets){let{top:t=0,right:n=0,bottom:r=0,left:i=0}=e.safeAreaInsets;document.body.style.padding=`${t}px ${n}px ${r}px ${i}px`}},o.onteardown=async()=>(a(),t.onTeardown?.(),{}),o.connect(new nx(window.parent,window.parent)).catch(()=>{}),{app:o,current:()=>i}}async function jx(e,t,n){return e.request({method:`tools/call`,params:{name:t,arguments:n}},ty)}async function Mx(e,t){if(e.getHostCapabilities()?.updateModelContext)try{await e.updateModelContext({content:[{type:`text`,text:t}]})}catch{}}function Nx(e){let t=document.documentElement.dataset.displayMode===`fullscreen`;return e.requestDisplayMode({mode:t?`inline`:`fullscreen`}).then(e=>{e?.mode&&(document.documentElement.dataset.displayMode=e.mode)})}async function Px(e,t){let n=zx();if(n?.openExternal){await n.openExternal({href:t,redirectUrl:!1});return}await e.openLink({url:t})}var Fx,Ix,Lx,Rx,zx,Bx=t((()=>{kx(),Xy(),Fx=e=>document.getElementById(e),Ix=2e3,Lx=1e4,Rx=36e4,zx=()=>window.openai}));n((()=>{Ui(),Bx();var e=[`shell`,`button`],t={shell:`Body`,button:`Shutter button`},n=3,r=`<svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14"/><path d="m13 6 6 6-6 6"/></svg>`,i={shell:90,button:0},a=window.EyeDropper,o=`card-${Math.random().toString(36).slice(2,10)}`,s=Fx(`canvas`),c=Fx(`fallback`),l,u=0,d,f,p=0,m,h,g,_,v=Date.now(),ee,y=`shell`,te={shell:0,button:0};function b(e,t){clearTimeout(ee),Fx(`status`).textContent=e,t&&(ee=window.setTimeout(()=>Fx(`status`).textContent=``,t))}var{app:x}=Ax(`Camera`,{onInput:()=>b(`Setting up your camera…`),onResult:e=>{let t=e;typeof t.designId==`string`&&ne(t)},onTeardown:()=>{clearTimeout(_),se()}});function ne(e){let t=e.designId!==l?.designId;l=e,C(),t?(ie(),he(2500)):e.rev>u&&ie()}async function re(){let e=navigator.gpu;if(!e)return!1;try{return!!await e.requestAdapter()}catch{return!1}}async function ie(e){if(l){if(h===void 0&&(b(`Checking 3D support…`),h=await re(),Me(h?`webgpu-available`:`webgpu-missing`)),u=l.rev,!h){S(),b(``);return}d&&f===l.designId?await ae(d,l.sceneUrl,e):await oe(e)}}async function ae(e,t,n){b(n??`Updating the 3D view…`);try{if(!await e.setScene(t)||e!==d)return;m=de(e.getScripts()),b(``)}catch{e===d&&await oe(n)}}async function oe(e){if(!l)return;let t=l,n=++p;se(),s.hidden=!1,ce(!1),b(e??`Loading the 3D viewer…`);let r=!1;try{let e=await Wt(s,{sceneUrl:t.sceneUrl,onProgress:({built:e,total:t})=>{r||n!==p||(r=e===t,r&&(c.hidden=!0,b(``)))},onError:e=>{e.code===`device-lost`&&(S(),b(`The 3D view stopped. Reopen the card to restart it.`)),Me(`viewer-${e.code}`,e.message)}});if(n!==p){e.destroy();return}d=e,f=t.designId,m=de(e.getScripts()),Me(`viewer-ready`)}catch(e){if(n!==p)return;let t=e;se(),t.code===`no-webgpu`&&(h=!1),S(),b(t.code===`no-webgpu`?``:`The 3D view couldn't load. You can still change the design and order it.`),Me(`viewer-${t.code??`failed`}`,String(t.message??t))}}function se(){d?.destroy(),d=void 0,f=void 0,m=void 0}function S(){l&&(s.hidden=!0,ce(!0))}function ce(e){if(l&&(c.hidden=!1,c.style.opacity=``,c.innerHTML=ue(l),e)){let e=document.createElement(`p`);e.textContent=`3D preview isn't available here. Colours still update.`,c.append(e)}}function le(e,t,n){let r=t.colors[e].map(_e);if(r.length<2)return r[0];let a=(i[e]-t.gradientAngles[e]+360)%360*Math.PI/180,o=Math.cos(a)/2,s=Math.sin(a)/2,c=r.map((e,t)=>`<stop offset="${t/(r.length-1)}" stop-color="${e}"/>`).join(``);return n.push(`<linearGradient id="g-${e}" x1="${.5-o}" y1="${.5-s}" x2="${.5+o}" y2="${.5+s}">${c}</linearGradient>`),`url(#g-${e})`}function ue(e){let t=[],n=le(`shell`,e,t),r=le(`button`,e,t);return`<svg viewBox="0 0 220 160" role="img" aria-label="Your camera: ${xe(`shell`,e)} body, ${xe(`button`,e)} shutter button"><defs>${t.join(``)}</defs><rect x="150" y="12" width="40" height="22" rx="8" fill="${r}" stroke="rgba(0,0,0,.18)"/><circle cx="34" cy="38" r="14" fill="none" stroke="rgba(0,0,0,.28)" stroke-width="6"/><rect x="10" y="28" width="200" height="124" rx="30" fill="${n}" stroke="rgba(0,0,0,.16)"/><rect x="10" y="28" width="200" height="124" rx="30" fill="url(#shine)" opacity=".5"/><circle cx="120" cy="92" r="40" fill="#1d1d20"/><circle cx="120" cy="92" r="30" fill="#2c2c33" stroke="#47474f" stroke-width="2"/><circle cx="120" cy="92" r="14" fill="#101014"/><circle cx="110" cy="82" r="5" fill="#ffffff" opacity=".55"/><circle cx="184" cy="54" r="5" fill="#ff4d4d"/><linearGradient id="shine" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".45" stop-color="#fff" stop-opacity="0"/></linearGradient></svg>`}function de(e){let t={};for(let n of e)for(let e of n.params)typeof e.value==`number`&&Number.isFinite(e.value)&&(t[e.name]=e.value);return t}async function fe(e){for(;g;)await g;if(!l)return;let t=l.rev;g=(async()=>{try{let n=await jx(x,`sync_camera_design`,{designId:l.designId,baseRev:t,writer:o,params:m??{},...e}),r=n.structuredContent;if(n.isError||!r){b(`Couldn't save that change.`);return}if(l=r,C(),r.rev===t){b(``);return}let i=r.rev>t+1;i||e?ie(i?`Merged with a change from the chat…`:`Applying colour…`):u=r.rev,!i&&!e&&b(`Saved`,1500),Mx(x,me(r))}catch{b(`Couldn't save that change.`)}})();try{await g}finally{g=void 0}}function pe(e,t=0){return e.length<2?e[0]:`${e.join(` → `)} gradient${t?` turned ${t}°`:``}`}var me=e=>`The user adjusted their camera in the card. Design ${e.designId}, revision ${e.rev}: shell ${pe(e.colors.shell,e.gradientAngles.shell)}, button ${pe(e.colors.button,e.gradientAngles.button)}; `+e.options.map(e=>`${e.label} ${e.display}`).join(`, `)+`.`;function he(e){clearTimeout(_),_=window.setTimeout(ge,e)}async function ge(){let e=Date.now()-v;try{if(l&&document.visibilityState===`visible`&&!g){let e=await jx(x,`get_camera_design`,{designId:l.designId}),t=e.structuredContent;!e.isError&&t&&t.rev>l.rev&&(v=Date.now(),l=t,C(),t.rev>u&&ie(`Updated from the chat…`))}}catch{}he(e<12e4?2500:e<6e5?8e3:2e4)}function _e(e){return l?.palette.find(t=>t.name===e)?.hex??e}var ve=e=>e.length>1?`Gradient`:e[0].startsWith(`#`)?`Custom`:e[0][0].toUpperCase()+e[0].slice(1);function C(){if(!l)return;Fx(`card`).dataset.ready=``;let n=document.documentElement.dataset.displayMode===`fullscreen`;for(let r of e){let e=l.colors[r],i=e.length>1;te[r]=Math.min(te[r],e.length-1);let o=i&&!n?void 0:e[te[r]];Fx(`note-${r}`).textContent=ve(e),Fx(`dot-${r}`).style.background=e.length>1?`linear-gradient(135deg, ${e.map(_e).join(`, `)})`:_e(e[0]),Fx(`tab-${r}`).setAttribute(`aria-selected`,String(r===y)),Fx(`group-${r}`).hidden=r!==y,Fx(`solid-${r}`).setAttribute(`aria-pressed`,String(!i)),Fx(`gradient-${r}`).setAttribute(`aria-pressed`,String(i)),T(r,e);let s=Fx(`sw-${r}`);s.textContent=``;let c=[...l.palette];for(let t of[...new Set(e)].reverse())t.startsWith(`#`)&&!c.some(e=>e.name===t)&&c.unshift({name:t,hex:t});for(let e of c){let i=document.createElement(`button`);i.type=`button`,i.className=e.name===`clear`?`swatch clear`:`swatch`,i.style.background=e.hex,i.title=e.name,i.setAttribute(`aria-label`,`${t[r]} colour: ${e.name}`),i.setAttribute(`aria-pressed`,String(o===e.name)),i.addEventListener(`click`,()=>void(n?E(r,e.name):ke(r,[e.name]))),s.append(i)}let u=document.createElement(`label`);u.className=`pick`,u.title=`Any colour`;let d=document.createElement(`input`);if(d.type=`color`,d.setAttribute(`aria-label`,`${t[r]}: any colour`),d.value=Oe(_e(o??e[0])),d.addEventListener(`change`,()=>{let e=d.value.toLowerCase();n?E(r,e):ke(r,[e])}),u.append(d),s.append(u),a&&n){let e=Ee(``,`${t[r]}: pick a colour from the screen`,!1,async()=>{try{let{sRGBHex:e}=await new a().open();await E(r,Oe(e))}catch{}});e.innerHTML=ye,e.classList.add(`tool`),s.append(e)}}Se(),Fx(`price`).textContent=l.price.label,Fx(`price-inline`).textContent=l.price.label,c.hidden||ce(s.hidden)}var ye=`<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m2 22 1-1h3l9-9"/><path d="M3 21v-3l9-9"/><path d="m15 6 3.4-3.4a2.1 2.1 0 1 1 3 3L18 9l.4.4a2.1 2.1 0 1 1-3 3l-3.8-3.8a2.1 2.1 0 1 1 3-3l.4.4Z"/></svg>`,be={shape:`Shape`,loop:`Strap loop`,button:`Shutter button`},w;function xe(e,t){let n=t.colors[e];return n.length>1?n.join(` to `):ve(n).toLowerCase()}function Se(){let e=Fx(`knobs`);if(!l||w)return;let t=l.options.filter(e=>e.kind===`choice`?e.choices?.length:e.kind===`number`);e.hidden=t.length===0;let n=new Set([...e.querySelectorAll(`details[open]`)].map(e=>e.dataset.group));e.textContent=``;let r=new Map;for(let e of t){let t=e.group&&be[e.group]?e.group:`other`;r.set(t,[...r.get(t)??[],e])}let i=[...Object.keys(be),`other`].filter(e=>r.has(e));for(let t of i){let i=document.createElement(`section`);i.className=`section`;let a=document.createElement(`h3`);a.textContent=be[t]??`More`,i.append(a);let[o,...s]=r.get(t);if(i.append(we(o)),s.length){let e=document.createElement(`details`);e.className=`more`,e.dataset.group=t,e.open=n.has(t);let r=document.createElement(`summary`);r.textContent=`More ${(be[t]??`options`).toLowerCase()} options`;let a=document.createElement(`div`);for(let e of s)a.append(we(e));e.append(r,a),i.append(e)}e.append(i)}}function Ce(e,t){if(e.kind===`choice`)return e.choices?.find(e=>e.value===t)?.label??String(t);let n=e.step&&e.step<1?Math.min(2,String(e.step).split(`.`)[1]?.length??1):0;return`${t.toFixed(n)}${e.unit?e.unit===`°`?`°`:` ${e.unit}`:``}`}function we(e){let t=document.createElement(`div`);t.className=`knob`;let n=document.createElement(`div`);n.className=`knob-head`;let r=document.createElement(`span`);if(r.textContent=e.label,e.hint&&(r.title=e.hint),n.append(r),t.append(n),e.kind===`choice`){r.id=`knob-${e.name}`;let n=document.createElement(`div`);n.className=`segmented`,n.setAttribute(`role`,`group`),n.setAttribute(`aria-labelledby`,r.id);for(let t of e.choices??[]){let r=document.createElement(`button`);r.type=`button`,r.textContent=t.label,r.setAttribute(`aria-pressed`,String(t.value===e.value)),r.addEventListener(`click`,()=>void Te(e.name,t.value)),n.append(r)}return t.append(n),t}let i=document.createElement(`output`);i.textContent=Ce(e,e.value),n.append(i);let a=document.createElement(`input`);a.type=`range`,a.min=String(e.min),a.max=String(e.max),a.step=String(e.step??1),a.value=String(e.value),a.setAttribute(`aria-label`,e.label);let o=()=>a.style.setProperty(`--fill`,`${(Number(a.value)-e.min)/(e.max-e.min||1)*100}%`);return o(),a.addEventListener(`input`,()=>{w=e.name,i.textContent=Ce(e,Number(a.value)),o()}),a.addEventListener(`change`,()=>{w=void 0,Te(e.name,Number(a.value))}),t.append(a),t}async function Te(e,t){l&&(v=Date.now(),l={...l,options:l.options.map(n=>n.name===e?{...n,value:t}:n)},C(),b(`Saving…`),m={...m??{},[e]:t},d?(d.setParams({[e]:t}),await fe()):await fe({}))}function T(e,a){let o=Fx(`stops-${e}`);if(o.hidden=a.length<2,o.textContent=``,a.length<2)return;let s=document.createElement(`div`);s.className=`track`,s.style.background=`linear-gradient(90deg, ${a.map(_e).join(`, `)})`,a.forEach((n,r)=>{let i=document.createElement(`button`);i.type=`button`,i.className=`stop`,i.style.left=`calc(11px + (100% - 22px) * ${r/(a.length-1)})`,i.style.background=_e(n),i.title=n,i.setAttribute(`aria-label`,`${t[e]} gradient colour ${r+1} of ${a.length}: ${n}`),i.setAttribute(`aria-pressed`,String(r===te[e])),i.addEventListener(`click`,()=>{te[e]=r,C()}),s.append(i)});let c=Ee(`+`,`${t[e]}: add a gradient colour`,a.length>=n,()=>{te[e]=a.length,ke(e,[...a,De(a[a.length-1])])}),u=Ee(`−`,`${t[e]}: remove the selected gradient colour`,a.length<=2,()=>{ke(e,a.filter((t,n)=>n!==te[e]))}),d=l?.gradientAngles[e]??0,f=Ee(``,`${t[e]}: turn the gradient 45° (now ${d}°)`,!1,()=>void Ae(e,(d+45)%360));f.innerHTML=r,f.style.transform=`rotate(${i[e]-d}deg)`,o.append(f,s,c,u)}function Ee(e,t,n,r){let i=document.createElement(`button`);return i.type=`button`,i.className=`icon-button`,i.textContent=e,i.title=t,i.setAttribute(`aria-label`,t),i.disabled=n,i.addEventListener(`click`,r),i}function De(e){return e===`violet`?`sky`:`violet`}function Oe(e){let t=/^rgba?\((\d+),\s*(\d+),\s*(\d+)/.exec(e);return t?`#${t.slice(1,4).map(e=>Number(e).toString(16).padStart(2,`0`)).join(``)}`:e.toLowerCase()}async function E(e,t){if(!l)return;let n=[...l.colors[e]];n[te[e]]=t,await ke(e,n)}async function ke(e,t){if(!l)return;let n=l.colors[e];t.length===n.length&&t.every((e,t)=>e===n[t])||(v=Date.now(),l={...l,colors:{...l.colors,[e]:t}},C(),b(`Saving…`),await fe({colors:{[e]:t}}))}async function Ae(e,t){!l||l.gradientAngles[e]===t||(v=Date.now(),l={...l,gradientAngles:{...l.gradientAngles,[e]:t}},C(),b(`Saving…`),await fe({gradientAngles:{[e]:t}}))}for(let t of e)Fx(`solid-${t}`).addEventListener(`click`,()=>{if(!l||l.colors[t].length<2)return;let e=l.colors[t][te[t]];te[t]=0,ke(t,[e])}),Fx(`gradient-${t}`).addEventListener(`click`,()=>{if(!l||l.colors[t].length>1)return;let[e]=l.colors[t];te[t]=1,ke(t,[e,De(e)])});var D=!1;async function je(){if(!l||D)return;D=!0,v=Date.now();let e=Fx(`order`);e.disabled=!0,b(`Opening checkout…`);try{await g;let e=await jx(x,`checkout_camera`,{designId:l.designId}),t=e.structuredContent;if(e.isError||typeof t?.checkoutUrl!=`string`){b(`Couldn't open checkout. Ask in the chat to order it.`);return}await Px(x,t.checkoutUrl),b(`Checkout is open in your browser. Your design and price carry over.`,6e3),Mx(x,`The user pressed Order on camera design ${l.designId} and opened its checkout page for revision ${t.rev} on the web: ${t.checkoutUrl} . They enter their address, see shipping and pay there. If they ask to order or for the link again, call checkout_camera: the design may have changed since.`)}catch{b(`Couldn't open checkout. Ask in the chat to order it.`)}finally{D=!1,e.disabled=!1}}Fx(`customize`).addEventListener(`click`,()=>{v=Date.now(),Nx(x).then(C)});for(let t of e)Fx(`tab-${t}`).addEventListener(`click`,()=>{y=t,C()});Fx(`close`).addEventListener(`click`,()=>void Nx(x).then(C)),Fx(`order`).addEventListener(`click`,()=>void je()),new MutationObserver(()=>C()).observe(document.documentElement,{attributes:!0,attributeFilter:[`data-display-mode`]});function Me(e,t){jx(x,`report_viewer_status`,{...l?{designId:l.designId}:{},writer:o,event:e,...h===void 0?{}:{webgpu:h},...t?{detail:t}:{},userAgent:navigator.userAgent.slice(0,300),displayMode:document.documentElement.dataset.displayMode??`inline`}).catch(()=>{})}c.hidden=!1,c.innerHTML=ue({colors:{shell:[`#e4e4e7`],button:[`#c4c4c8`]},gradientAngles:{shell:0,button:0}}),c.style.opacity=`0.6`}))();</script>
1783
+ container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:B().optional().describe(`User's language and region preference in BCP 47 format.`),timeZone:B().optional().describe(`User's timezone in IANA format.`),userAgent:B().optional().describe(`Host application identifier.`),platform:K([J(`web`),J(`desktop`),J(`mobile`)]).optional().describe(`Platform type for responsive design decisions.`),deviceCapabilities:G({touch:H().optional().describe(`Whether the device supports touch input.`),hover:H().optional().describe(`Whether the device supports hover interactions.`)}).optional().describe(`Device input capabilities.`),safeAreaInsets:G({top:V().describe(`Top safe area inset in pixels.`),right:V().describe(`Right safe area inset in pixels.`),bottom:V().describe(`Bottom safe area inset in pixels.`),left:V().describe(`Left safe area inset in pixels.`)}).optional().describe(`Mobile safe area boundaries in pixels.`)}).passthrough(),Tx=G({method:J(`ui/notifications/host-context-changed`),params:wx.describe(`Partial context update containing only changed fields.`)}),G({method:J(`ui/update-model-context`),params:G({content:W(Kv).optional().describe(`Context content blocks (text, image, etc.).`),structuredContent:q(B(),U().describe(`Structured content for machine-readable context data.`)).optional().describe(`Structured content for machine-readable context data.`)})}),G({method:J(`ui/initialize`),params:G({appInfo:F_.describe(`App identification (name and version).`),appCapabilities:bx.describe(`Features and capabilities this app provides.`),protocolVersion:B().describe(`Protocol version this app supports.`)})}),Ex=G({protocolVersion:B().describe(`Negotiated protocol version string (e.g., "2025-11-21").`),hostInfo:F_.describe(`Host application identification and version.`),hostCapabilities:yx.describe(`Features and capabilities provided by the host.`),hostContext:wx.describe(`Rich context about the host environment.`)}).passthrough(),Dx={target:`draft-2020-12`},Ox=class e extends ex{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;_registeredTools={};_initializedSent=!1;_assertInitialized(e){if(this._initializedSent)return;let t=`[ext-apps] App.${e}() called before connect() completed the ui/initialize handshake. Await app.connect() before calling this method, or move data loading to an ontoolresult handler.`;if(this.options?.strict)throw Error(t);console.warn(`${t}. This will throw in a future release.`)}eventSchemas={toolinput:fx,toolinputpartial:px,toolresult:Cx,toolcancelled:mx,hostcontextchanged:Tx};static ONE_SHOT_EVENTS=new Set([`toolinput`,`toolinputpartial`,`toolresult`,`toolcancelled`]);_everHadListener=new Set;_assertHandlerTiming(t){if(!e.ONE_SHOT_EVENTS.has(t)||this._everHadListener.has(t)||(this._everHadListener.add(t),!this._initializedSent))return;let n=`[ext-apps] "${String(t)}" handler registered after connect() completed the ui/initialize handshake. The host may have already sent this notification. Register handlers before calling app.connect().`;if(this.options?.strict)throw Error(n);console.warn(n)}setEventHandler(e,t){t&&this._assertHandlerTiming(e),super.setEventHandler(e,t)}addEventListener(e,t){this._assertHandlerTiming(e),super.addEventListener(e,t)}onEventDispatch(e,t){e===`hostcontextchanged`&&(this._hostContext={...this._hostContext,...t})}constructor(e,t={},n={autoResize:!0}){super(n),this._appInfo=e,this._capabilities=t,this.options=n,n.allowUnsafeEval||Wi({jitless:!0}),this.setRequestHandler(K_,e=>(console.log(`Received ping:`,e.params),{})),this.setEventHandler(`hostcontextchanged`,void 0)}registerCapabilities(e){if(this.transport)throw Error(`Cannot register capabilities after transport is established`);this._capabilities=Hb(this._capabilities,e)}registerTool(e,t,n){if(this._registeredTools[e])throw Error(`Tool ${e} is already registered`);let r=this,i=()=>{r._initializedSent&&r._capabilities.tools?.listChanged&&r.sendToolListChanged()},a=t.inputSchema!==void 0,o={title:t.title,description:t.description,inputSchema:t.inputSchema,outputSchema:t.outputSchema,annotations:t.annotations,_meta:t._meta,enabled:!0,enable(){this.enabled=!0,i()},disable(){this.enabled=!1,i()},update(e){Object.assign(this,e),i()},remove(){r._registeredTools[e]===o&&(delete r._registeredTools[e],i())},handler:async(t,r)=>{if(!o.enabled)throw Error(`Tool ${e} is disabled`);let i;if(a){let a=o.inputSchema;i=await n(a?await Zb(a,t??{},`Invalid input for tool ${e}: `):t??{},r)}else i=await n(r);return o.outputSchema&&!i.isError&&(i.structuredContent=await Zb(o.outputSchema,i.structuredContent,`Invalid output for tool ${e}: `)),i}};return this._registeredTools[e]=o,!this._capabilities.tools&&!this.transport&&this.registerCapabilities({tools:{listChanged:!0}}),this.ensureToolHandlersInitialized(),i(),o}_toolHandlersInitialized=!1;ensureToolHandlersInitialized(){this._toolHandlersInitialized||(this._toolHandlersInitialized=!0,this.oncalltool=async(e,t)=>{let n=this._registeredTools[e.name];if(!n)throw Error(`Tool ${e.name} not found`);return n.handler(e.arguments,t)},this.onlisttools=async(e,t)=>({tools:await Promise.all(Object.entries(this._registeredTools).filter(([e,t])=>t.enabled).map(async([e,t])=>{let n={name:e,title:t.title,description:t.description,inputSchema:t.inputSchema?await Xb(t.inputSchema,`input`):{type:`object`,properties:{}}};return t.outputSchema&&(n.outputSchema=await Xb(t.outputSchema,`output`)),t.annotations&&(n.annotations=t.annotations),t._meta&&(n._meta=t._meta),n}))}))}async sendToolListChanged(e={}){this._assertInitialized(`sendToolListChanged`),await this.notification({method:`notifications/tools/list_changed`,params:e})}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}get ontoolinput(){return this.getEventHandler(`toolinput`)}set ontoolinput(e){this.setEventHandler(`toolinput`,e)}get ontoolinputpartial(){return this.getEventHandler(`toolinputpartial`)}set ontoolinputpartial(e){this.setEventHandler(`toolinputpartial`,e)}get ontoolresult(){return this.getEventHandler(`toolresult`)}set ontoolresult(e){this.setEventHandler(`toolresult`,e)}get ontoolcancelled(){return this.getEventHandler(`toolcancelled`)}set ontoolcancelled(e){this.setEventHandler(`toolcancelled`,e)}get onhostcontextchanged(){return this.getEventHandler(`hostcontextchanged`)}set onhostcontextchanged(e){this.setEventHandler(`hostcontextchanged`,e)}_onteardown;get onteardown(){return this._onteardown}set onteardown(e){this.warnIfRequestHandlerReplaced(`onteardown`,this._onteardown,e),this._onteardown=e,this.replaceRequestHandler(_x,(e,t)=>{if(!this._onteardown)throw Error(`No onteardown handler set`);return this._onteardown(e.params,t)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(e){this.warnIfRequestHandlerReplaced(`oncalltool`,this._oncalltool,e),this._oncalltool=e,this.replaceRequestHandler(ry,(e,t)=>{if(!this._oncalltool)throw Error(`No oncalltool handler set`);return this._oncalltool(e.params,t)})}_onlisttools;get onlisttools(){return this._onlisttools}set onlisttools(e){this.warnIfRequestHandlerReplaced(`onlisttools`,this._onlisttools,e),this._onlisttools=e,this.replaceRequestHandler($v,(e,t)=>{if(!this._onlisttools)throw Error(`No onlisttools handler set`);return this._onlisttools(e.params,t)})}assertCapabilityForMethod(e){if(e===`sampling/createMessage`&&!this._hostCapabilities?.sampling)throw Error(`Host does not support sampling (required for ${e})`)}assertRequestHandlerCapability(e){switch(e){case`tools/call`:case`tools/list`:if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${e})`);return;case`ping`:case`ui/resource-teardown`:return;default:throw Error(`No handler for method ${e} registered`)}}assertNotificationCapability(e){}assertTaskCapability(e){throw Error(`Tasks are not supported in MCP Apps`)}assertTaskHandlerCapability(e){throw Error(`Task handlers are not supported in MCP Apps`)}async callServerTool(e,t){if(this._assertInitialized(`callServerTool`),typeof e==`string`)throw Error(`callServerTool() expects an object as its first argument, but received a string ("${e}"). Did you mean: callServerTool({ name: "${e}", arguments: { ... } })?`);return await this.request({method:`tools/call`,params:e},ty,{onprogress:()=>{},resetTimeoutOnProgress:!0,...t})}async readServerResource(e,t){return this._assertInitialized(`readServerResource`),await this.request({method:`resources/read`,params:e},Ev,t)}async listServerResources(e,t){return this._assertInitialized(`listServerResources`),await this.request({method:`resources/list`,params:e},bv,t)}async createSamplingMessage(e,t){this._assertInitialized(`createSamplingMessage`);let n=e.tools?by:yy;return await this.request({method:`sampling/createMessage`,params:e},n,t)}sendMessage(e,t){return this._assertInitialized(`sendMessage`),this.request({method:`ui/message`,params:e},lx,t)}sendLog(e){return this.notification({method:`notifications/message`,params:e})}updateModelContext(e,t){return this._assertInitialized(`updateModelContext`),this.request({method:`ui/update-model-context`,params:e},k_,t)}openLink(e,t){return this._assertInitialized(`openLink`),this.request({method:`ui/open-link`,params:e},sx,t)}sendOpenLink=this.openLink;downloadFile(e,t){return this._assertInitialized(`downloadFile`),this.request({method:`ui/download-file`,params:e},cx,t)}requestTeardown(e={}){return this.notification({method:`ui/notifications/request-teardown`,params:e})}requestDisplayMode(e,t){return this._assertInitialized(`requestDisplayMode`),this.request({method:`ui/request-display-mode`,params:e},xx,t)}sendSizeChanged(e){return this.notification({method:`ui/notifications/size-changed`,params:e})}setupSizeChangedNotifications(){let e=!1,t=0,n=0,r=()=>{e||(e=!0,requestAnimationFrame(()=>{e=!1;let r=document.documentElement,i=r.style.height;r.style.height=`max-content`;let a=Math.ceil(r.getBoundingClientRect().height);r.style.height=i;let o=Math.ceil(window.innerWidth);(o!==t||a!==n)&&(t=o,n=a,this.sendSizeChanged({width:o,height:a}))}))};r();let i=new ResizeObserver(r);return i.observe(document.documentElement),i.observe(document.body),()=>i.disconnect()}async connect(e=new nx(window.parent,window.parent),t){if(this.transport)throw Error(`App is already connected. Call close() before connecting again.`);this._initializedSent=!1,await super.connect(e);try{let e=await this.request({method:`ui/initialize`,params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:tx}},Ex,t);if(e===void 0)throw Error(`Server sent invalid initialize result: ${e}`);this._hostCapabilities=e.hostCapabilities,this._hostInfo=e.hostInfo,this._hostContext=e.hostContext,await this.notification({method:`ui/notifications/initialized`}),this._initializedSent=!0,this.options?.autoResize&&this.setupSizeChangedNotifications()}catch(e){throw this.close(),e}}}}));function Ax(e,t){let n,r=0,i,a=()=>{n!==void 0&&(clearTimeout(n),n=void 0)},o=new Ox({name:e,version:`0.0.1`},{}),s=async e=>{let t=await o.request({method:`tools/call`,params:{name:`get_generation`,arguments:{operationId:e}}},ty);if(!t.isError)return t.structuredContent},c=(e,o)=>{n=window.setTimeout(async()=>{if(Date.now()-r>Hx){t.onTimeout?.();return}try{let n=await s(e);if(n?.status===`complete`){a(),i=n,t.onResult(n);return}}catch{}c(e,Math.min(o*1.5,Vx))},o)},l=e=>{e&&(a(),i=e,t.onResult(e),e.status===`running`&&e.operationId!==void 0&&(r=Date.now(),c(e.operationId,Bx)))};return o.ontoolinput=e=>{t.onInput?.(e?.arguments||{}),t.onResult({status:`running`})},o.ontoolresult=e=>{let t=Gx(e?._meta)??Px();l(t??e?.structuredContent),t||Fx(e=>l(e))},o.onhostcontextchanged=e=>{if(e?.theme&&Qb(e.theme),e?.styles?.variables&&$b(e.styles.variables),e?.displayMode&&(document.documentElement.dataset.displayMode=e.displayMode),e?.safeAreaInsets){let{top:t=0,right:n=0,bottom:r=0,left:i=0}=e.safeAreaInsets;document.body.style.padding=`${t}px ${n}px ${r}px ${i}px`}},o.onteardown=async()=>(a(),t.onTeardown?.(),{}),o.connect(new nx(window.parent,window.parent)).catch(()=>{}),{app:o,current:()=>i}}async function jx(e,t,n){return e.request({method:`tools/call`,params:{name:t,arguments:n}},ty)}async function Mx(e,t){if(e.getHostCapabilities()?.updateModelContext)try{await e.updateModelContext({content:[{type:`text`,text:t}]})}catch{}}function Nx(e){let t=document.documentElement.dataset.displayMode===`fullscreen`;return e.requestDisplayMode({mode:t?`inline`:`fullscreen`}).then(e=>{e?.mode&&(document.documentElement.dataset.displayMode=e.mode)})}function Px(){let e=Ux()?.toolResponseMetadata;if(!(!e||typeof e!=`object`))return Gx(e)??Gx(e.mcp_tool_result?._meta)??Gx(e.call_tool_result?._meta)}function Fx(e){if(!Ux())return;let t=()=>window.removeEventListener(`openai:set_globals`,n),n=()=>{let n=Px();n!==void 0&&(t(),e(n))};window.addEventListener(`openai:set_globals`,n),setTimeout(t,Kx)}function Ix(e){return Gx(e._meta)??e.structuredContent}async function Lx(e,t){let n=Ux();if(n?.openExternal){await n.openExternal({href:t,redirectUrl:!1});return}await e.openLink({url:t})}async function Rx(e,t){if(e.getHostCapabilities()?.message)return!(await e.sendMessage({role:`user`,content:[{type:`text`,text:t}]})).isError;let n=Ux();return n?.sendFollowUpMessage?(await n.sendFollowUpMessage({prompt:t}),!0):!1}var zx,Bx,Vx,Hx,Ux,Wx,Gx,Kx,qx=t((()=>{kx(),Xy(),zx=e=>document.getElementById(e),Bx=2e3,Vx=1e4,Hx=36e4,Ux=()=>window.openai,Wx=`openai-mcp/card`,Gx=e=>e&&typeof e==`object`?e[Wx]:void 0,Kx=1e4}));n((()=>{Ui(),qx();var e=[`shell`,`button`],t={shell:`Body`,button:`Shutter button`},n=3,r=`<svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14"/><path d="m13 6 6 6-6 6"/></svg>`,i={shell:90,button:0},a=window.EyeDropper,o=`card-${Math.random().toString(36).slice(2,10)}`,s=zx(`canvas`),c=zx(`fallback`),l,u=0,d,f,p=0,m,h,g,_,v=Date.now(),ee,y=`shell`,te={shell:0,button:0};function b(e,t){clearTimeout(ee),zx(`status`).textContent=e,t&&(ee=window.setTimeout(()=>zx(`status`).textContent=``,t))}var{app:x}=Ax(`Camera`,{onInput:()=>b(`Setting up your camera…`),onResult:e=>{let t=e;typeof t.designId==`string`&&ne(t)},onTeardown:()=>{clearTimeout(_),se()}});function ne(e){let t=e.designId!==l?.designId;l=e,C(),t?(ie(),he(2500)):e.rev>u&&ie()}async function re(){let e=navigator.gpu;if(!e)return!1;try{return!!await e.requestAdapter()}catch{return!1}}async function ie(e){if(l){if(h===void 0&&(b(`Checking 3D support…`),h=await re(),Me(h?`webgpu-available`:`webgpu-missing`)),u=l.rev,!h){S(),b(``);return}d&&f===l.designId?await ae(d,l.sceneUrl,e):await oe(e)}}async function ae(e,t,n){b(n??`Updating the 3D view…`);try{if(!await e.setScene(t)||e!==d)return;m=de(e.getScripts()),b(``)}catch{e===d&&await oe(n)}}async function oe(e){if(!l)return;let t=l,n=++p;se(),s.hidden=!1,ce(!1),b(e??`Loading the 3D viewer…`);let r=!1;try{let e=await Wt(s,{sceneUrl:t.sceneUrl,onProgress:({built:e,total:t})=>{r||n!==p||(r=e===t,r&&(c.hidden=!0,b(``)))},onError:e=>{e.code===`device-lost`&&(S(),b(`The 3D view stopped. Reopen the card to restart it.`)),Me(`viewer-${e.code}`,e.message)}});if(n!==p){e.destroy();return}d=e,f=t.designId,m=de(e.getScripts()),Me(`viewer-ready`)}catch(e){if(n!==p)return;let t=e;se(),t.code===`no-webgpu`&&(h=!1),S(),b(t.code===`no-webgpu`?``:`The 3D view couldn't load. You can still change the design and order it.`),Me(`viewer-${t.code??`failed`}`,String(t.message??t))}}function se(){d?.destroy(),d=void 0,f=void 0,m=void 0}function S(){l&&(s.hidden=!0,ce(!0))}function ce(e){if(l&&(c.hidden=!1,c.style.opacity=``,c.innerHTML=ue(l),e)){let e=document.createElement(`p`);e.textContent=`3D preview isn't available here. Colours still update.`,c.append(e)}}function le(e,t,n){let r=t.colors[e].map(_e);if(r.length<2)return r[0];let a=(i[e]-t.gradientAngles[e]+360)%360*Math.PI/180,o=Math.cos(a)/2,s=Math.sin(a)/2,c=r.map((e,t)=>`<stop offset="${t/(r.length-1)}" stop-color="${e}"/>`).join(``);return n.push(`<linearGradient id="g-${e}" x1="${.5-o}" y1="${.5-s}" x2="${.5+o}" y2="${.5+s}">${c}</linearGradient>`),`url(#g-${e})`}function ue(e){let t=[],n=le(`shell`,e,t),r=le(`button`,e,t);return`<svg viewBox="0 0 220 160" role="img" aria-label="Your camera: ${xe(`shell`,e)} body, ${xe(`button`,e)} shutter button"><defs>${t.join(``)}</defs><rect x="150" y="12" width="40" height="22" rx="8" fill="${r}" stroke="rgba(0,0,0,.18)"/><circle cx="34" cy="38" r="14" fill="none" stroke="rgba(0,0,0,.28)" stroke-width="6"/><rect x="10" y="28" width="200" height="124" rx="30" fill="${n}" stroke="rgba(0,0,0,.16)"/><rect x="10" y="28" width="200" height="124" rx="30" fill="url(#shine)" opacity=".5"/><circle cx="120" cy="92" r="40" fill="#1d1d20"/><circle cx="120" cy="92" r="30" fill="#2c2c33" stroke="#47474f" stroke-width="2"/><circle cx="120" cy="92" r="14" fill="#101014"/><circle cx="110" cy="82" r="5" fill="#ffffff" opacity=".55"/><circle cx="184" cy="54" r="5" fill="#ff4d4d"/><linearGradient id="shine" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".45" stop-color="#fff" stop-opacity="0"/></linearGradient></svg>`}function de(e){let t={};for(let n of e)for(let e of n.params)typeof e.value==`number`&&Number.isFinite(e.value)&&(t[e.name]=e.value);return t}async function fe(e){for(;g;)await g;if(!l)return;let t=l.rev;g=(async()=>{try{let n=await jx(x,`sync_camera_design`,{designId:l.designId,baseRev:t,writer:o,params:m??{},...e}),r=n.structuredContent;if(n.isError||!r){b(`Couldn't save that change.`);return}if(l=r,C(),r.rev===t){b(``);return}let i=r.rev>t+1;i||e?ie(i?`Merged with a change from the chat…`:`Applying colour…`):u=r.rev,!i&&!e&&b(`Saved`,1500),Mx(x,me(r))}catch{b(`Couldn't save that change.`)}})();try{await g}finally{g=void 0}}function pe(e,t=0){return e.length<2?e[0]:`${e.join(` → `)} gradient${t?` turned ${t}°`:``}`}var me=e=>`The user adjusted their camera in the card. Design ${e.designId}, revision ${e.rev}: shell ${pe(e.colors.shell,e.gradientAngles.shell)}, button ${pe(e.colors.button,e.gradientAngles.button)}; `+e.options.map(e=>`${e.label} ${e.display}`).join(`, `)+`.`;function he(e){clearTimeout(_),_=window.setTimeout(ge,e)}async function ge(){let e=Date.now()-v;try{if(l&&document.visibilityState===`visible`&&!g){let e=await jx(x,`get_camera_design`,{designId:l.designId}),t=e.structuredContent;!e.isError&&t&&t.rev>l.rev&&(v=Date.now(),l=t,C(),t.rev>u&&ie(`Updated from the chat…`))}}catch{}he(e<12e4?2500:e<6e5?8e3:2e4)}function _e(e){return l?.palette.find(t=>t.name===e)?.hex??e}var ve=e=>e.length>1?`Gradient`:e[0].startsWith(`#`)?`Custom`:e[0][0].toUpperCase()+e[0].slice(1);function C(){if(!l)return;zx(`card`).dataset.ready=``;let n=document.documentElement.dataset.displayMode===`fullscreen`;for(let r of e){let e=l.colors[r],i=e.length>1;te[r]=Math.min(te[r],e.length-1);let o=i&&!n?void 0:e[te[r]];zx(`note-${r}`).textContent=ve(e),zx(`dot-${r}`).style.background=e.length>1?`linear-gradient(135deg, ${e.map(_e).join(`, `)})`:_e(e[0]),zx(`tab-${r}`).setAttribute(`aria-selected`,String(r===y)),zx(`group-${r}`).hidden=r!==y,zx(`solid-${r}`).setAttribute(`aria-pressed`,String(!i)),zx(`gradient-${r}`).setAttribute(`aria-pressed`,String(i)),T(r,e);let s=zx(`sw-${r}`);s.textContent=``;let c=[...l.palette];for(let t of[...new Set(e)].reverse())t.startsWith(`#`)&&!c.some(e=>e.name===t)&&c.unshift({name:t,hex:t});for(let e of c){let i=document.createElement(`button`);i.type=`button`,i.className=e.name===`clear`?`swatch clear`:`swatch`,i.style.background=e.hex,i.title=e.name,i.setAttribute(`aria-label`,`${t[r]} colour: ${e.name}`),i.setAttribute(`aria-pressed`,String(o===e.name)),i.addEventListener(`click`,()=>void(n?E(r,e.name):ke(r,[e.name]))),s.append(i)}let u=document.createElement(`label`);u.className=`pick`,u.title=`Any colour`;let d=document.createElement(`input`);if(d.type=`color`,d.setAttribute(`aria-label`,`${t[r]}: any colour`),d.value=Oe(_e(o??e[0])),d.addEventListener(`change`,()=>{let e=d.value.toLowerCase();n?E(r,e):ke(r,[e])}),u.append(d),s.append(u),a&&n){let e=Ee(``,`${t[r]}: pick a colour from the screen`,!1,async()=>{try{let{sRGBHex:e}=await new a().open();await E(r,Oe(e))}catch{}});e.innerHTML=ye,e.classList.add(`tool`),s.append(e)}}Se(),zx(`price`).textContent=l.price.label,zx(`price-inline`).textContent=l.price.label,c.hidden||ce(s.hidden)}var ye=`<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m2 22 1-1h3l9-9"/><path d="M3 21v-3l9-9"/><path d="m15 6 3.4-3.4a2.1 2.1 0 1 1 3 3L18 9l.4.4a2.1 2.1 0 1 1-3 3l-3.8-3.8a2.1 2.1 0 1 1 3-3l.4.4Z"/></svg>`,be={shape:`Shape`,loop:`Strap loop`,button:`Shutter button`},w;function xe(e,t){let n=t.colors[e];return n.length>1?n.join(` to `):ve(n).toLowerCase()}function Se(){let e=zx(`knobs`);if(!l||w)return;let t=l.options.filter(e=>e.kind===`choice`?e.choices?.length:e.kind===`number`);e.hidden=t.length===0;let n=new Set([...e.querySelectorAll(`details[open]`)].map(e=>e.dataset.group));e.textContent=``;let r=new Map;for(let e of t){let t=e.group&&be[e.group]?e.group:`other`;r.set(t,[...r.get(t)??[],e])}let i=[...Object.keys(be),`other`].filter(e=>r.has(e));for(let t of i){let i=document.createElement(`section`);i.className=`section`;let a=document.createElement(`h3`);a.textContent=be[t]??`More`,i.append(a);let[o,...s]=r.get(t);if(i.append(we(o)),s.length){let e=document.createElement(`details`);e.className=`more`,e.dataset.group=t,e.open=n.has(t);let r=document.createElement(`summary`);r.textContent=`More ${(be[t]??`options`).toLowerCase()} options`;let a=document.createElement(`div`);for(let e of s)a.append(we(e));e.append(r,a),i.append(e)}e.append(i)}}function Ce(e,t){if(e.kind===`choice`)return e.choices?.find(e=>e.value===t)?.label??String(t);let n=e.step&&e.step<1?Math.min(2,String(e.step).split(`.`)[1]?.length??1):0;return`${t.toFixed(n)}${e.unit?e.unit===`°`?`°`:` ${e.unit}`:``}`}function we(e){let t=document.createElement(`div`);t.className=`knob`;let n=document.createElement(`div`);n.className=`knob-head`;let r=document.createElement(`span`);if(r.textContent=e.label,e.hint&&(r.title=e.hint),n.append(r),t.append(n),e.kind===`choice`){r.id=`knob-${e.name}`;let n=document.createElement(`div`);n.className=`segmented`,n.setAttribute(`role`,`group`),n.setAttribute(`aria-labelledby`,r.id);for(let t of e.choices??[]){let r=document.createElement(`button`);r.type=`button`,r.textContent=t.label,r.setAttribute(`aria-pressed`,String(t.value===e.value)),r.addEventListener(`click`,()=>void Te(e.name,t.value)),n.append(r)}return t.append(n),t}let i=document.createElement(`output`);i.textContent=Ce(e,e.value),n.append(i);let a=document.createElement(`input`);a.type=`range`,a.min=String(e.min),a.max=String(e.max),a.step=String(e.step??1),a.value=String(e.value),a.setAttribute(`aria-label`,e.label);let o=()=>a.style.setProperty(`--fill`,`${(Number(a.value)-e.min)/(e.max-e.min||1)*100}%`);return o(),a.addEventListener(`input`,()=>{w=e.name,i.textContent=Ce(e,Number(a.value)),o()}),a.addEventListener(`change`,()=>{w=void 0,Te(e.name,Number(a.value))}),t.append(a),t}async function Te(e,t){l&&(v=Date.now(),l={...l,options:l.options.map(n=>n.name===e?{...n,value:t}:n)},C(),b(`Saving…`),m={...m??{},[e]:t},d?(d.setParams({[e]:t}),await fe()):await fe({}))}function T(e,a){let o=zx(`stops-${e}`);if(o.hidden=a.length<2,o.textContent=``,a.length<2)return;let s=document.createElement(`div`);s.className=`track`,s.style.background=`linear-gradient(90deg, ${a.map(_e).join(`, `)})`,a.forEach((n,r)=>{let i=document.createElement(`button`);i.type=`button`,i.className=`stop`,i.style.left=`calc(11px + (100% - 22px) * ${r/(a.length-1)})`,i.style.background=_e(n),i.title=n,i.setAttribute(`aria-label`,`${t[e]} gradient colour ${r+1} of ${a.length}: ${n}`),i.setAttribute(`aria-pressed`,String(r===te[e])),i.addEventListener(`click`,()=>{te[e]=r,C()}),s.append(i)});let c=Ee(`+`,`${t[e]}: add a gradient colour`,a.length>=n,()=>{te[e]=a.length,ke(e,[...a,De(a[a.length-1])])}),u=Ee(`−`,`${t[e]}: remove the selected gradient colour`,a.length<=2,()=>{ke(e,a.filter((t,n)=>n!==te[e]))}),d=l?.gradientAngles[e]??0,f=Ee(``,`${t[e]}: turn the gradient 45° (now ${d}°)`,!1,()=>void Ae(e,(d+45)%360));f.innerHTML=r,f.style.transform=`rotate(${i[e]-d}deg)`,o.append(f,s,c,u)}function Ee(e,t,n,r){let i=document.createElement(`button`);return i.type=`button`,i.className=`icon-button`,i.textContent=e,i.title=t,i.setAttribute(`aria-label`,t),i.disabled=n,i.addEventListener(`click`,r),i}function De(e){return e===`violet`?`sky`:`violet`}function Oe(e){let t=/^rgba?\((\d+),\s*(\d+),\s*(\d+)/.exec(e);return t?`#${t.slice(1,4).map(e=>Number(e).toString(16).padStart(2,`0`)).join(``)}`:e.toLowerCase()}async function E(e,t){if(!l)return;let n=[...l.colors[e]];n[te[e]]=t,await ke(e,n)}async function ke(e,t){if(!l)return;let n=l.colors[e];t.length===n.length&&t.every((e,t)=>e===n[t])||(v=Date.now(),l={...l,colors:{...l.colors,[e]:t}},C(),b(`Saving…`),await fe({colors:{[e]:t}}))}async function Ae(e,t){!l||l.gradientAngles[e]===t||(v=Date.now(),l={...l,gradientAngles:{...l.gradientAngles,[e]:t}},C(),b(`Saving…`),await fe({gradientAngles:{[e]:t}}))}for(let t of e)zx(`solid-${t}`).addEventListener(`click`,()=>{if(!l||l.colors[t].length<2)return;let e=l.colors[t][te[t]];te[t]=0,ke(t,[e])}),zx(`gradient-${t}`).addEventListener(`click`,()=>{if(!l||l.colors[t].length>1)return;let[e]=l.colors[t];te[t]=1,ke(t,[e,De(e)])});var D=!1;async function je(){if(!l||D)return;D=!0,v=Date.now();let e=zx(`order`);e.disabled=!0,b(`Opening checkout…`);try{await g;let e=await jx(x,`checkout_camera`,{designId:l.designId}),t=Ix(e);if(e.isError||typeof t?.checkoutUrl!=`string`){if(!e.isError&&await Rx(x,`Order it`)){b(`Getting your quote in the chat…`,6e3);return}b(`Couldn't open checkout. Ask in the chat to order it.`);return}await Lx(x,t.checkoutUrl),b(`Checkout is open in your browser. Your design and price carry over.`,6e3),Mx(x,`The user pressed Order on camera design ${l.designId} and opened its checkout page for revision ${t.rev} on the web: ${t.checkoutUrl} . They enter their address, see shipping and pay there. If they ask to order or for the link again, call checkout_camera: the design may have changed since.`)}catch{b(`Couldn't open checkout. Ask in the chat to order it.`)}finally{D=!1,e.disabled=!1}}zx(`customize`).addEventListener(`click`,()=>{v=Date.now(),Nx(x).then(C)});for(let t of e)zx(`tab-${t}`).addEventListener(`click`,()=>{y=t,C()});zx(`close`).addEventListener(`click`,()=>void Nx(x).then(C)),zx(`order`).addEventListener(`click`,()=>void je()),new MutationObserver(()=>C()).observe(document.documentElement,{attributes:!0,attributeFilter:[`data-display-mode`]});function Me(e,t){jx(x,`report_viewer_status`,{...l?{designId:l.designId}:{},writer:o,event:e,...h===void 0?{}:{webgpu:h},...t?{detail:t}:{},userAgent:navigator.userAgent.slice(0,300),displayMode:document.documentElement.dataset.displayMode??`inline`}).catch(()=>{})}c.hidden=!1,c.innerHTML=ue({colors:{shell:[`#e4e4e7`],button:[`#c4c4c8`]},gradientAngles:{shell:0,button:0}}),c.style.opacity=`0.6`}))();</script>
1784
1784
  </head>
1785
1785
  <body>
1786
1786
  <div class="card" id="card">
@@ -183,7 +183,7 @@ Boolean requesting whether a visible border and background is provided by the ho
183
183
  - omitted: host decides border`)}),F({method:B(`ui/request-display-mode`),params:F({mode:Uh.describe(`The display mode being requested.`)})}),og=F({mode:Uh.describe(`The display mode that was actually set. May differ from requested if not supported.`)}).passthrough(),sg=L([B(`model`),B(`app`)]).describe(`Tool visibility scope - who can access the tool.`),F({resourceUri:A().optional(),visibility:P(sg).optional().describe(`Who can access this tool. Default: ["model", "app"]
184
184
  - "model": Tool visible to and callable by the agent
185
185
  - "app": Tool callable by the app from this server only`),csp:Hl().optional(),permissions:Hl().optional()}),F({mimeTypes:P(A()).optional().describe('Array of supported MIME types for UI resources.\nMust include `"text/html;profile=mcp-app"` for MCP Apps support.')}),F({method:B(`ui/download-file`),params:F({contents:P(L([kp,Ap])).describe(`Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.`)})}),F({method:B(`ui/message`),params:F({role:B(`user`).describe(`Message role, currently only "user" is supported.`),content:P(jp).describe(`Message content blocks (text, image, etc.).`)})}),F({method:B(`ui/notifications/sandbox-resource-ready`),params:F({html:A().describe(`HTML content to load into the inner iframe.`),sandbox:A().optional().describe(`Optional override for the inner iframe's sandbox attribute.`),csp:Yh.optional().describe(`CSP configuration from resource metadata.`),permissions:Xh.optional().describe(`Sandbox permissions from resource metadata.`)})}),cg=F({method:B(`ui/notifications/tool-result`),params:Bp.describe(`Standard MCP tool execution result.`)}),lg=F({toolInfo:F({id:rf.optional().describe(`JSON-RPC id of the tools/call request.`),tool:Lp.describe(`Tool definition including name, inputSchema, etc.`)}).optional().describe(`Metadata of the tool call that instantiated this App.`),theme:Hh.optional().describe(`Current color theme preference.`),styles:tg.optional().describe(`Style configuration for theming the app.`),displayMode:Uh.optional().describe(`How the UI is currently displayed.`),availableDisplayModes:P(Uh).optional().describe(`Display modes the host supports.`),containerDimensions:L([F({height:j().describe(`Fixed container height in pixels.`)}),F({maxHeight:L([j(),zl()]).optional().describe(`Maximum container height in pixels.`)})]).and(L([F({width:j().describe(`Fixed container width in pixels.`)}),F({maxWidth:L([j(),zl()]).optional().describe(`Maximum container width in pixels.`)})])).optional().describe(`Container dimensions. Represents the dimensions of the iframe or other
186
- container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:A().optional().describe(`User's language and region preference in BCP 47 format.`),timeZone:A().optional().describe(`User's timezone in IANA format.`),userAgent:A().optional().describe(`Host application identifier.`),platform:L([B(`web`),B(`desktop`),B(`mobile`)]).optional().describe(`Platform type for responsive design decisions.`),deviceCapabilities:F({touch:M().optional().describe(`Whether the device supports touch input.`),hover:M().optional().describe(`Whether the device supports hover interactions.`)}).optional().describe(`Device input capabilities.`),safeAreaInsets:F({top:j().describe(`Top safe area inset in pixels.`),right:j().describe(`Right safe area inset in pixels.`),bottom:j().describe(`Bottom safe area inset in pixels.`),left:j().describe(`Left safe area inset in pixels.`)}).optional().describe(`Mobile safe area boundaries in pixels.`)}).passthrough(),ug=F({method:B(`ui/notifications/host-context-changed`),params:lg.describe(`Partial context update containing only changed fields.`)}),F({method:B(`ui/update-model-context`),params:F({content:P(jp).optional().describe(`Context content blocks (text, image, etc.).`),structuredContent:R(A(),N().describe(`Structured content for machine-readable context data.`)).optional().describe(`Structured content for machine-readable context data.`)})}),F({method:B(`ui/initialize`),params:F({appInfo:bf.describe(`App identification (name and version).`),appCapabilities:ag.describe(`Features and capabilities this app provides.`),protocolVersion:A().describe(`Protocol version this app supports.`)})}),dg=F({protocolVersion:A().describe(`Negotiated protocol version string (e.g., "2025-11-21").`),hostInfo:bf.describe(`Host application identification and version.`),hostCapabilities:ig.describe(`Features and capabilities provided by the host.`),hostContext:lg.describe(`Rich context about the host environment.`)}).passthrough(),fg={target:`draft-2020-12`},pg=class e extends zh{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;_registeredTools={};_initializedSent=!1;_assertInitialized(e){if(this._initializedSent)return;let t=`[ext-apps] App.${e}() called before connect() completed the ui/initialize handshake. Await app.connect() before calling this method, or move data loading to an ontoolresult handler.`;if(this.options?.strict)throw Error(t);console.warn(`${t}. This will throw in a future release.`)}eventSchemas={toolinput:Zh,toolinputpartial:Qh,toolresult:cg,toolcancelled:$h,hostcontextchanged:ug};static ONE_SHOT_EVENTS=new Set([`toolinput`,`toolinputpartial`,`toolresult`,`toolcancelled`]);_everHadListener=new Set;_assertHandlerTiming(t){if(!e.ONE_SHOT_EVENTS.has(t)||this._everHadListener.has(t)||(this._everHadListener.add(t),!this._initializedSent))return;let n=`[ext-apps] "${String(t)}" handler registered after connect() completed the ui/initialize handshake. The host may have already sent this notification. Register handlers before calling app.connect().`;if(this.options?.strict)throw Error(n);console.warn(n)}setEventHandler(e,t){t&&this._assertHandlerTiming(e),super.setEventHandler(e,t)}addEventListener(e,t){this._assertHandlerTiming(e),super.addEventListener(e,t)}onEventDispatch(e,t){e===`hostcontextchanged`&&(this._hostContext={...this._hostContext,...t})}constructor(e,t={},n={autoResize:!0}){super(n),this._appInfo=e,this._capabilities=t,this.options=n,n.allowUnsafeEval||o({jitless:!0}),this.setRequestHandler(jf,e=>(console.log(`Received ping:`,e.params),{})),this.setEventHandler(`hostcontextchanged`,void 0)}registerCapabilities(e){if(this.transport)throw Error(`Cannot register capabilities after transport is established`);this._capabilities=Dh(this._capabilities,e)}registerTool(e,t,n){if(this._registeredTools[e])throw Error(`Tool ${e} is already registered`);let r=this,i=()=>{r._initializedSent&&r._capabilities.tools?.listChanged&&r.sendToolListChanged()},a=t.inputSchema!==void 0,o={title:t.title,description:t.description,inputSchema:t.inputSchema,outputSchema:t.outputSchema,annotations:t.annotations,_meta:t._meta,enabled:!0,enable(){this.enabled=!0,i()},disable(){this.enabled=!1,i()},update(e){Object.assign(this,e),i()},remove(){r._registeredTools[e]===o&&(delete r._registeredTools[e],i())},handler:async(t,r)=>{if(!o.enabled)throw Error(`Tool ${e} is disabled`);let i;if(a){let a=o.inputSchema;i=await n(a?await Ih(a,t??{},`Invalid input for tool ${e}: `):t??{},r)}else i=await n(r);return o.outputSchema&&!i.isError&&(i.structuredContent=await Ih(o.outputSchema,i.structuredContent,`Invalid output for tool ${e}: `)),i}};return this._registeredTools[e]=o,!this._capabilities.tools&&!this.transport&&this.registerCapabilities({tools:{listChanged:!0}}),this.ensureToolHandlersInitialized(),i(),o}_toolHandlersInitialized=!1;ensureToolHandlersInitialized(){this._toolHandlersInitialized||(this._toolHandlersInitialized=!0,this.oncalltool=async(e,t)=>{let n=this._registeredTools[e.name];if(!n)throw Error(`Tool ${e.name} not found`);return n.handler(e.arguments,t)},this.onlisttools=async(e,t)=>({tools:await Promise.all(Object.entries(this._registeredTools).filter(([e,t])=>t.enabled).map(async([e,t])=>{let n={name:e,title:t.title,description:t.description,inputSchema:t.inputSchema?await Fh(t.inputSchema,`input`):{type:`object`,properties:{}}};return t.outputSchema&&(n.outputSchema=await Fh(t.outputSchema,`output`)),t.annotations&&(n.annotations=t.annotations),t._meta&&(n._meta=t._meta),n}))}))}async sendToolListChanged(e={}){this._assertInitialized(`sendToolListChanged`),await this.notification({method:`notifications/tools/list_changed`,params:e})}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}get ontoolinput(){return this.getEventHandler(`toolinput`)}set ontoolinput(e){this.setEventHandler(`toolinput`,e)}get ontoolinputpartial(){return this.getEventHandler(`toolinputpartial`)}set ontoolinputpartial(e){this.setEventHandler(`toolinputpartial`,e)}get ontoolresult(){return this.getEventHandler(`toolresult`)}set ontoolresult(e){this.setEventHandler(`toolresult`,e)}get ontoolcancelled(){return this.getEventHandler(`toolcancelled`)}set ontoolcancelled(e){this.setEventHandler(`toolcancelled`,e)}get onhostcontextchanged(){return this.getEventHandler(`hostcontextchanged`)}set onhostcontextchanged(e){this.setEventHandler(`hostcontextchanged`,e)}_onteardown;get onteardown(){return this._onteardown}set onteardown(e){this.warnIfRequestHandlerReplaced(`onteardown`,this._onteardown,e),this._onteardown=e,this.replaceRequestHandler(ng,(e,t)=>{if(!this._onteardown)throw Error(`No onteardown handler set`);return this._onteardown(e.params,t)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(e){this.warnIfRequestHandlerReplaced(`oncalltool`,this._oncalltool,e),this._oncalltool=e,this.replaceRequestHandler(Hp,(e,t)=>{if(!this._oncalltool)throw Error(`No oncalltool handler set`);return this._oncalltool(e.params,t)})}_onlisttools;get onlisttools(){return this._onlisttools}set onlisttools(e){this.warnIfRequestHandlerReplaced(`onlisttools`,this._onlisttools,e),this._onlisttools=e,this.replaceRequestHandler(Rp,(e,t)=>{if(!this._onlisttools)throw Error(`No onlisttools handler set`);return this._onlisttools(e.params,t)})}assertCapabilityForMethod(e){if(e===`sampling/createMessage`&&!this._hostCapabilities?.sampling)throw Error(`Host does not support sampling (required for ${e})`)}assertRequestHandlerCapability(e){switch(e){case`tools/call`:case`tools/list`:if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${e})`);return;case`ping`:case`ui/resource-teardown`:return;default:throw Error(`No handler for method ${e} registered`)}}assertNotificationCapability(e){}assertTaskCapability(e){throw Error(`Tasks are not supported in MCP Apps`)}assertTaskHandlerCapability(e){throw Error(`Task handlers are not supported in MCP Apps`)}async callServerTool(e,t){if(this._assertInitialized(`callServerTool`),typeof e==`string`)throw Error(`callServerTool() expects an object as its first argument, but received a string ("${e}"). Did you mean: callServerTool({ name: "${e}", arguments: { ... } })?`);return await this.request({method:`tools/call`,params:e},Bp,{onprogress:()=>{},resetTimeoutOnProgress:!0,...t})}async readServerResource(e,t){return this._assertInitialized(`readServerResource`),await this.request({method:`resources/read`,params:e},dp,t)}async listServerResources(e,t){return this._assertInitialized(`listServerResources`),await this.request({method:`resources/list`,params:e},ap,t)}async createSamplingMessage(e,t){this._assertInitialized(`createSamplingMessage`);let n=e.tools?am:im;return await this.request({method:`sampling/createMessage`,params:e},n,t)}sendMessage(e,t){return this._assertInitialized(`sendMessage`),this.request({method:`ui/message`,params:e},Jh,t)}sendLog(e){return this.notification({method:`notifications/message`,params:e})}updateModelContext(e,t){return this._assertInitialized(`updateModelContext`),this.request({method:`ui/update-model-context`,params:e},mf,t)}openLink(e,t){return this._assertInitialized(`openLink`),this.request({method:`ui/open-link`,params:e},Kh,t)}sendOpenLink=this.openLink;downloadFile(e,t){return this._assertInitialized(`downloadFile`),this.request({method:`ui/download-file`,params:e},qh,t)}requestTeardown(e={}){return this.notification({method:`ui/notifications/request-teardown`,params:e})}requestDisplayMode(e,t){return this._assertInitialized(`requestDisplayMode`),this.request({method:`ui/request-display-mode`,params:e},og,t)}sendSizeChanged(e){return this.notification({method:`ui/notifications/size-changed`,params:e})}setupSizeChangedNotifications(){let e=!1,t=0,n=0,r=()=>{e||(e=!0,requestAnimationFrame(()=>{e=!1;let r=document.documentElement,i=r.style.height;r.style.height=`max-content`;let a=Math.ceil(r.getBoundingClientRect().height);r.style.height=i;let o=Math.ceil(window.innerWidth);(o!==t||a!==n)&&(t=o,n=a,this.sendSizeChanged({width:o,height:a}))}))};r();let i=new ResizeObserver(r);return i.observe(document.documentElement),i.observe(document.body),()=>i.disconnect()}async connect(e=new Vh(window.parent,window.parent),t){if(this.transport)throw Error(`App is already connected. Call close() before connecting again.`);this._initializedSent=!1,await super.connect(e);try{let e=await this.request({method:`ui/initialize`,params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:Bh}},dg,t);if(e===void 0)throw Error(`Server sent invalid initialize result: ${e}`);this._hostCapabilities=e.hostCapabilities,this._hostInfo=e.hostInfo,this._hostContext=e.hostContext,await this.notification({method:`ui/notifications/initialized`}),this._initializedSent=!0,this.options?.autoResize&&this.setupSizeChangedNotifications()}catch(e){throw this.close(),e}}}}));function hg(e,t){let n,r=0,i,a=()=>{n!==void 0&&(clearTimeout(n),n=void 0)},o=new pg({name:e,version:`0.0.1`},{}),s=async e=>{let t=await o.request({method:`tools/call`,params:{name:`get_generation`,arguments:{operationId:e}}},Bp);if(!t.isError)return t.structuredContent},c=(e,o)=>{n=window.setTimeout(async()=>{if(Date.now()-r>yg){t.onTimeout?.();return}try{let n=await s(e);if(n?.status===`complete`){a(),i=n,t.onResult(n);return}}catch{}c(e,Math.min(o*1.5,vg))},o)},l=e=>{e&&(a(),i=e,t.onResult(e),e.status===`running`&&e.operationId!==void 0&&(r=Date.now(),c(e.operationId,_g)))};return o.ontoolinput=e=>{t.onInput?.(e?.arguments||{}),t.onResult({status:`running`})},o.ontoolresult=e=>l(e?.structuredContent),o.onhostcontextchanged=e=>{if(e?.theme&&Lh(e.theme),e?.styles?.variables&&Rh(e.styles.variables),e?.displayMode&&(document.documentElement.dataset.displayMode=e.displayMode),e?.safeAreaInsets){let{top:t=0,right:n=0,bottom:r=0,left:i=0}=e.safeAreaInsets;document.body.style.padding=`${t}px ${n}px ${r}px ${i}px`}},o.onteardown=async()=>(a(),t.onTeardown?.(),{}),o.connect(new Vh(window.parent,window.parent)).catch(()=>{}),{app:o,current:()=>i}}async function gg(e,t){let n=bg();if(n?.openExternal){await n.openExternal({href:t,redirectUrl:!1});return}await e.openLink({url:t})}var $,_g,vg,yg,bg,xg=t((()=>{mg(),Fm(),$=e=>document.getElementById(e),_g=2e3,vg=1e4,yg=36e4,bg=()=>window.openai}));n((()=>{xg();var e=[`paid`,`printing`,`shipped`,`delivered`],t,n,r=e=>{$(`status`).textContent=e},i=e=>e.length>1?`linear-gradient(180deg, ${e.join(`, `)})`:e[0]||`transparent`;function a(e){let t=new Date(e);return t.toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,timeZone:`UTC`,...t.getUTCFullYear()===new Date().getUTCFullYear()?{}:{year:`numeric`}})}function o(e){try{return new URL(e).hostname.replace(/^www\./,``)}catch{return`the web`}}function s(){$(`head`).hidden=!1,$(`thumb`).style.background=``,$(`cap`).removeAttribute(`style`),$(`title`).textContent=t===void 0?`No order yet`:`No order #${t} here`,$(`line`).textContent=`Orders paid for from this chat's checkout links show up here.`,$(`tracker`).hidden=!0,$(`track`).hidden=!0,r(``)}function c(t){let n=t.items[0];$(`thumb`).style.background=n?i(n.swatches.shell):``,n?$(`cap`).style.background=i(n.swatches.button):$(`cap`).removeAttribute(`style`),$(`title`).textContent=t.step===`printing`?`Printing now`:t.statusLabel;let s=t.step===`canceled`||!t.timeline?``:t.step===`delivered`?` · Delivered ${a(t.timeline.deliveredAt)}`:` · Arrives around ${a(t.timeline.deliveredAt)}`;$(`line`).textContent=`Order #${t.id}${s}`,$(`head`).hidden=!1;let c=e.indexOf(t.step);$(`tracker`).hidden=c<0;for(let t of Array.from($(`tracker`).children)){let n=e.indexOf(t.dataset.step);t.classList.toggle(`done`,n<=c),t.classList.toggle(`now`,n===c),n===c?t.setAttribute(`aria-current`,`step`):t.removeAttribute(`aria-current`)}let l=$(`track`);l.hidden=!t.statusUrl,t.statusUrl&&(l.textContent=`Track on ${o(t.statusUrl)} ↗`),r(``)}var l=hg(`Order`,{onInput:e=>{t=typeof e.orderId==`number`?e.orderId:void 0,r(`Checking your order…`)},onResult:e=>{let t=e;Array.isArray(t.orders)&&(n=t.order,n?c(n):s())}});$(`track`).addEventListener(`click`,async()=>{if(n?.statusUrl)try{await gg(l.app,n.statusUrl)}catch{r(`Couldn't open it here. Ask in the chat for the order's status page.`)}})}))();</script>
186
+ container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:A().optional().describe(`User's language and region preference in BCP 47 format.`),timeZone:A().optional().describe(`User's timezone in IANA format.`),userAgent:A().optional().describe(`Host application identifier.`),platform:L([B(`web`),B(`desktop`),B(`mobile`)]).optional().describe(`Platform type for responsive design decisions.`),deviceCapabilities:F({touch:M().optional().describe(`Whether the device supports touch input.`),hover:M().optional().describe(`Whether the device supports hover interactions.`)}).optional().describe(`Device input capabilities.`),safeAreaInsets:F({top:j().describe(`Top safe area inset in pixels.`),right:j().describe(`Right safe area inset in pixels.`),bottom:j().describe(`Bottom safe area inset in pixels.`),left:j().describe(`Left safe area inset in pixels.`)}).optional().describe(`Mobile safe area boundaries in pixels.`)}).passthrough(),ug=F({method:B(`ui/notifications/host-context-changed`),params:lg.describe(`Partial context update containing only changed fields.`)}),F({method:B(`ui/update-model-context`),params:F({content:P(jp).optional().describe(`Context content blocks (text, image, etc.).`),structuredContent:R(A(),N().describe(`Structured content for machine-readable context data.`)).optional().describe(`Structured content for machine-readable context data.`)})}),F({method:B(`ui/initialize`),params:F({appInfo:bf.describe(`App identification (name and version).`),appCapabilities:ag.describe(`Features and capabilities this app provides.`),protocolVersion:A().describe(`Protocol version this app supports.`)})}),dg=F({protocolVersion:A().describe(`Negotiated protocol version string (e.g., "2025-11-21").`),hostInfo:bf.describe(`Host application identification and version.`),hostCapabilities:ig.describe(`Features and capabilities provided by the host.`),hostContext:lg.describe(`Rich context about the host environment.`)}).passthrough(),fg={target:`draft-2020-12`},pg=class e extends zh{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;_registeredTools={};_initializedSent=!1;_assertInitialized(e){if(this._initializedSent)return;let t=`[ext-apps] App.${e}() called before connect() completed the ui/initialize handshake. Await app.connect() before calling this method, or move data loading to an ontoolresult handler.`;if(this.options?.strict)throw Error(t);console.warn(`${t}. This will throw in a future release.`)}eventSchemas={toolinput:Zh,toolinputpartial:Qh,toolresult:cg,toolcancelled:$h,hostcontextchanged:ug};static ONE_SHOT_EVENTS=new Set([`toolinput`,`toolinputpartial`,`toolresult`,`toolcancelled`]);_everHadListener=new Set;_assertHandlerTiming(t){if(!e.ONE_SHOT_EVENTS.has(t)||this._everHadListener.has(t)||(this._everHadListener.add(t),!this._initializedSent))return;let n=`[ext-apps] "${String(t)}" handler registered after connect() completed the ui/initialize handshake. The host may have already sent this notification. Register handlers before calling app.connect().`;if(this.options?.strict)throw Error(n);console.warn(n)}setEventHandler(e,t){t&&this._assertHandlerTiming(e),super.setEventHandler(e,t)}addEventListener(e,t){this._assertHandlerTiming(e),super.addEventListener(e,t)}onEventDispatch(e,t){e===`hostcontextchanged`&&(this._hostContext={...this._hostContext,...t})}constructor(e,t={},n={autoResize:!0}){super(n),this._appInfo=e,this._capabilities=t,this.options=n,n.allowUnsafeEval||o({jitless:!0}),this.setRequestHandler(jf,e=>(console.log(`Received ping:`,e.params),{})),this.setEventHandler(`hostcontextchanged`,void 0)}registerCapabilities(e){if(this.transport)throw Error(`Cannot register capabilities after transport is established`);this._capabilities=Dh(this._capabilities,e)}registerTool(e,t,n){if(this._registeredTools[e])throw Error(`Tool ${e} is already registered`);let r=this,i=()=>{r._initializedSent&&r._capabilities.tools?.listChanged&&r.sendToolListChanged()},a=t.inputSchema!==void 0,o={title:t.title,description:t.description,inputSchema:t.inputSchema,outputSchema:t.outputSchema,annotations:t.annotations,_meta:t._meta,enabled:!0,enable(){this.enabled=!0,i()},disable(){this.enabled=!1,i()},update(e){Object.assign(this,e),i()},remove(){r._registeredTools[e]===o&&(delete r._registeredTools[e],i())},handler:async(t,r)=>{if(!o.enabled)throw Error(`Tool ${e} is disabled`);let i;if(a){let a=o.inputSchema;i=await n(a?await Ih(a,t??{},`Invalid input for tool ${e}: `):t??{},r)}else i=await n(r);return o.outputSchema&&!i.isError&&(i.structuredContent=await Ih(o.outputSchema,i.structuredContent,`Invalid output for tool ${e}: `)),i}};return this._registeredTools[e]=o,!this._capabilities.tools&&!this.transport&&this.registerCapabilities({tools:{listChanged:!0}}),this.ensureToolHandlersInitialized(),i(),o}_toolHandlersInitialized=!1;ensureToolHandlersInitialized(){this._toolHandlersInitialized||(this._toolHandlersInitialized=!0,this.oncalltool=async(e,t)=>{let n=this._registeredTools[e.name];if(!n)throw Error(`Tool ${e.name} not found`);return n.handler(e.arguments,t)},this.onlisttools=async(e,t)=>({tools:await Promise.all(Object.entries(this._registeredTools).filter(([e,t])=>t.enabled).map(async([e,t])=>{let n={name:e,title:t.title,description:t.description,inputSchema:t.inputSchema?await Fh(t.inputSchema,`input`):{type:`object`,properties:{}}};return t.outputSchema&&(n.outputSchema=await Fh(t.outputSchema,`output`)),t.annotations&&(n.annotations=t.annotations),t._meta&&(n._meta=t._meta),n}))}))}async sendToolListChanged(e={}){this._assertInitialized(`sendToolListChanged`),await this.notification({method:`notifications/tools/list_changed`,params:e})}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}get ontoolinput(){return this.getEventHandler(`toolinput`)}set ontoolinput(e){this.setEventHandler(`toolinput`,e)}get ontoolinputpartial(){return this.getEventHandler(`toolinputpartial`)}set ontoolinputpartial(e){this.setEventHandler(`toolinputpartial`,e)}get ontoolresult(){return this.getEventHandler(`toolresult`)}set ontoolresult(e){this.setEventHandler(`toolresult`,e)}get ontoolcancelled(){return this.getEventHandler(`toolcancelled`)}set ontoolcancelled(e){this.setEventHandler(`toolcancelled`,e)}get onhostcontextchanged(){return this.getEventHandler(`hostcontextchanged`)}set onhostcontextchanged(e){this.setEventHandler(`hostcontextchanged`,e)}_onteardown;get onteardown(){return this._onteardown}set onteardown(e){this.warnIfRequestHandlerReplaced(`onteardown`,this._onteardown,e),this._onteardown=e,this.replaceRequestHandler(ng,(e,t)=>{if(!this._onteardown)throw Error(`No onteardown handler set`);return this._onteardown(e.params,t)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(e){this.warnIfRequestHandlerReplaced(`oncalltool`,this._oncalltool,e),this._oncalltool=e,this.replaceRequestHandler(Hp,(e,t)=>{if(!this._oncalltool)throw Error(`No oncalltool handler set`);return this._oncalltool(e.params,t)})}_onlisttools;get onlisttools(){return this._onlisttools}set onlisttools(e){this.warnIfRequestHandlerReplaced(`onlisttools`,this._onlisttools,e),this._onlisttools=e,this.replaceRequestHandler(Rp,(e,t)=>{if(!this._onlisttools)throw Error(`No onlisttools handler set`);return this._onlisttools(e.params,t)})}assertCapabilityForMethod(e){if(e===`sampling/createMessage`&&!this._hostCapabilities?.sampling)throw Error(`Host does not support sampling (required for ${e})`)}assertRequestHandlerCapability(e){switch(e){case`tools/call`:case`tools/list`:if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${e})`);return;case`ping`:case`ui/resource-teardown`:return;default:throw Error(`No handler for method ${e} registered`)}}assertNotificationCapability(e){}assertTaskCapability(e){throw Error(`Tasks are not supported in MCP Apps`)}assertTaskHandlerCapability(e){throw Error(`Task handlers are not supported in MCP Apps`)}async callServerTool(e,t){if(this._assertInitialized(`callServerTool`),typeof e==`string`)throw Error(`callServerTool() expects an object as its first argument, but received a string ("${e}"). Did you mean: callServerTool({ name: "${e}", arguments: { ... } })?`);return await this.request({method:`tools/call`,params:e},Bp,{onprogress:()=>{},resetTimeoutOnProgress:!0,...t})}async readServerResource(e,t){return this._assertInitialized(`readServerResource`),await this.request({method:`resources/read`,params:e},dp,t)}async listServerResources(e,t){return this._assertInitialized(`listServerResources`),await this.request({method:`resources/list`,params:e},ap,t)}async createSamplingMessage(e,t){this._assertInitialized(`createSamplingMessage`);let n=e.tools?am:im;return await this.request({method:`sampling/createMessage`,params:e},n,t)}sendMessage(e,t){return this._assertInitialized(`sendMessage`),this.request({method:`ui/message`,params:e},Jh,t)}sendLog(e){return this.notification({method:`notifications/message`,params:e})}updateModelContext(e,t){return this._assertInitialized(`updateModelContext`),this.request({method:`ui/update-model-context`,params:e},mf,t)}openLink(e,t){return this._assertInitialized(`openLink`),this.request({method:`ui/open-link`,params:e},Kh,t)}sendOpenLink=this.openLink;downloadFile(e,t){return this._assertInitialized(`downloadFile`),this.request({method:`ui/download-file`,params:e},qh,t)}requestTeardown(e={}){return this.notification({method:`ui/notifications/request-teardown`,params:e})}requestDisplayMode(e,t){return this._assertInitialized(`requestDisplayMode`),this.request({method:`ui/request-display-mode`,params:e},og,t)}sendSizeChanged(e){return this.notification({method:`ui/notifications/size-changed`,params:e})}setupSizeChangedNotifications(){let e=!1,t=0,n=0,r=()=>{e||(e=!0,requestAnimationFrame(()=>{e=!1;let r=document.documentElement,i=r.style.height;r.style.height=`max-content`;let a=Math.ceil(r.getBoundingClientRect().height);r.style.height=i;let o=Math.ceil(window.innerWidth);(o!==t||a!==n)&&(t=o,n=a,this.sendSizeChanged({width:o,height:a}))}))};r();let i=new ResizeObserver(r);return i.observe(document.documentElement),i.observe(document.body),()=>i.disconnect()}async connect(e=new Vh(window.parent,window.parent),t){if(this.transport)throw Error(`App is already connected. Call close() before connecting again.`);this._initializedSent=!1,await super.connect(e);try{let e=await this.request({method:`ui/initialize`,params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:Bh}},dg,t);if(e===void 0)throw Error(`Server sent invalid initialize result: ${e}`);this._hostCapabilities=e.hostCapabilities,this._hostInfo=e.hostInfo,this._hostContext=e.hostContext,await this.notification({method:`ui/notifications/initialized`}),this._initializedSent=!0,this.options?.autoResize&&this.setupSizeChangedNotifications()}catch(e){throw this.close(),e}}}}));function hg(e,t){let n,r=0,i,a=()=>{n!==void 0&&(clearTimeout(n),n=void 0)},o=new pg({name:e,version:`0.0.1`},{}),s=async e=>{let t=await o.request({method:`tools/call`,params:{name:`get_generation`,arguments:{operationId:e}}},Bp);if(!t.isError)return t.structuredContent},c=(e,o)=>{n=window.setTimeout(async()=>{if(Date.now()-r>xg){t.onTimeout?.();return}try{let n=await s(e);if(n?.status===`complete`){a(),i=n,t.onResult(n);return}}catch{}c(e,Math.min(o*1.5,bg))},o)},l=e=>{e&&(a(),i=e,t.onResult(e),e.status===`running`&&e.operationId!==void 0&&(r=Date.now(),c(e.operationId,yg)))};return o.ontoolinput=e=>{t.onInput?.(e?.arguments||{}),t.onResult({status:`running`})},o.ontoolresult=e=>{let t=wg(e?._meta)??gg();l(t??e?.structuredContent),t||_g(e=>l(e))},o.onhostcontextchanged=e=>{if(e?.theme&&Lh(e.theme),e?.styles?.variables&&Rh(e.styles.variables),e?.displayMode&&(document.documentElement.dataset.displayMode=e.displayMode),e?.safeAreaInsets){let{top:t=0,right:n=0,bottom:r=0,left:i=0}=e.safeAreaInsets;document.body.style.padding=`${t}px ${n}px ${r}px ${i}px`}},o.onteardown=async()=>(a(),t.onTeardown?.(),{}),o.connect(new Vh(window.parent,window.parent)).catch(()=>{}),{app:o,current:()=>i}}function gg(){let e=Sg()?.toolResponseMetadata;if(!(!e||typeof e!=`object`))return wg(e)??wg(e.mcp_tool_result?._meta)??wg(e.call_tool_result?._meta)}function _g(e){if(!Sg())return;let t=()=>window.removeEventListener(`openai:set_globals`,n),n=()=>{let n=gg();n!==void 0&&(t(),e(n))};window.addEventListener(`openai:set_globals`,n),setTimeout(t,Tg)}async function vg(e,t){let n=Sg();if(n?.openExternal){await n.openExternal({href:t,redirectUrl:!1});return}await e.openLink({url:t})}var $,yg,bg,xg,Sg,Cg,wg,Tg,Eg=t((()=>{mg(),Fm(),$=e=>document.getElementById(e),yg=2e3,bg=1e4,xg=36e4,Sg=()=>window.openai,Cg=`openai-mcp/card`,wg=e=>e&&typeof e==`object`?e[Cg]:void 0,Tg=1e4}));n((()=>{Eg();var e=[`paid`,`printing`,`shipped`,`delivered`],t,n,r=e=>{$(`status`).textContent=e},i=e=>e.length>1?`linear-gradient(180deg, ${e.join(`, `)})`:e[0]||`transparent`;function a(e){let t=new Date(e);return t.toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,timeZone:`UTC`,...t.getUTCFullYear()===new Date().getUTCFullYear()?{}:{year:`numeric`}})}function o(e){try{return new URL(e).hostname.replace(/^www\./,``)}catch{return`the web`}}function s(){$(`head`).hidden=!1,$(`thumb`).style.background=``,$(`cap`).removeAttribute(`style`),$(`title`).textContent=t===void 0?`No order yet`:`No order #${t} here`,$(`line`).textContent=`Orders paid for from this chat's checkout links show up here.`,$(`tracker`).hidden=!0,$(`track`).hidden=!0,r(``)}function c(t){let n=t.items[0];$(`thumb`).style.background=n?i(n.swatches.shell):``,n?$(`cap`).style.background=i(n.swatches.button):$(`cap`).removeAttribute(`style`),$(`title`).textContent=t.step===`printing`?`Printing now`:t.statusLabel;let s=t.step===`canceled`||!t.timeline?``:t.step===`delivered`?` · Delivered ${a(t.timeline.deliveredAt)}`:` · Arrives around ${a(t.timeline.deliveredAt)}`;$(`line`).textContent=`Order #${t.id}${s}`,$(`head`).hidden=!1;let c=e.indexOf(t.step);$(`tracker`).hidden=c<0;for(let t of Array.from($(`tracker`).children)){let n=e.indexOf(t.dataset.step);t.classList.toggle(`done`,n<=c),t.classList.toggle(`now`,n===c),n===c?t.setAttribute(`aria-current`,`step`):t.removeAttribute(`aria-current`)}let l=$(`track`);l.hidden=!t.statusUrl,t.statusUrl&&(l.textContent=`Track on ${o(t.statusUrl)} ↗`),r(``)}var l=hg(`Order`,{onInput:e=>{t=typeof e.orderId==`number`?e.orderId:void 0,r(`Checking your order…`)},onResult:e=>{let t=e;if(Array.isArray(t.orders)){if(t.order&&!Array.isArray(t.order.items)){let e=t.order.id;window.setTimeout(()=>{n?.id!==e&&r(`Couldn't show the order here. Ask in the chat where it is again.`)},1e4);return}n=t.order,n?c(n):s()}}});$(`track`).addEventListener(`click`,async()=>{if(n?.statusUrl)try{await vg(l.app,n.statusUrl)}catch{r(`Couldn't open it here. Ask in the chat for the order's status page.`)}})}))();</script>
187
187
  </head>
188
188
  <body>
189
189
  <div class="card">
@@ -193,7 +193,7 @@ Boolean requesting whether a visible border and background is provided by the ho
193
193
  - omitted: host decides border`)}),F({method:B(`ui/request-display-mode`),params:F({mode:Uh.describe(`The display mode being requested.`)})}),og=F({mode:Uh.describe(`The display mode that was actually set. May differ from requested if not supported.`)}).passthrough(),sg=L([B(`model`),B(`app`)]).describe(`Tool visibility scope - who can access the tool.`),F({resourceUri:A().optional(),visibility:P(sg).optional().describe(`Who can access this tool. Default: ["model", "app"]
194
194
  - "model": Tool visible to and callable by the agent
195
195
  - "app": Tool callable by the app from this server only`),csp:Hl().optional(),permissions:Hl().optional()}),F({mimeTypes:P(A()).optional().describe('Array of supported MIME types for UI resources.\nMust include `"text/html;profile=mcp-app"` for MCP Apps support.')}),F({method:B(`ui/download-file`),params:F({contents:P(L([kp,Ap])).describe(`Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.`)})}),F({method:B(`ui/message`),params:F({role:B(`user`).describe(`Message role, currently only "user" is supported.`),content:P(jp).describe(`Message content blocks (text, image, etc.).`)})}),F({method:B(`ui/notifications/sandbox-resource-ready`),params:F({html:A().describe(`HTML content to load into the inner iframe.`),sandbox:A().optional().describe(`Optional override for the inner iframe's sandbox attribute.`),csp:Yh.optional().describe(`CSP configuration from resource metadata.`),permissions:Xh.optional().describe(`Sandbox permissions from resource metadata.`)})}),cg=F({method:B(`ui/notifications/tool-result`),params:Bp.describe(`Standard MCP tool execution result.`)}),lg=F({toolInfo:F({id:rf.optional().describe(`JSON-RPC id of the tools/call request.`),tool:Lp.describe(`Tool definition including name, inputSchema, etc.`)}).optional().describe(`Metadata of the tool call that instantiated this App.`),theme:Hh.optional().describe(`Current color theme preference.`),styles:tg.optional().describe(`Style configuration for theming the app.`),displayMode:Uh.optional().describe(`How the UI is currently displayed.`),availableDisplayModes:P(Uh).optional().describe(`Display modes the host supports.`),containerDimensions:L([F({height:j().describe(`Fixed container height in pixels.`)}),F({maxHeight:L([j(),zl()]).optional().describe(`Maximum container height in pixels.`)})]).and(L([F({width:j().describe(`Fixed container width in pixels.`)}),F({maxWidth:L([j(),zl()]).optional().describe(`Maximum container width in pixels.`)})])).optional().describe(`Container dimensions. Represents the dimensions of the iframe or other
196
- container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:A().optional().describe(`User's language and region preference in BCP 47 format.`),timeZone:A().optional().describe(`User's timezone in IANA format.`),userAgent:A().optional().describe(`Host application identifier.`),platform:L([B(`web`),B(`desktop`),B(`mobile`)]).optional().describe(`Platform type for responsive design decisions.`),deviceCapabilities:F({touch:M().optional().describe(`Whether the device supports touch input.`),hover:M().optional().describe(`Whether the device supports hover interactions.`)}).optional().describe(`Device input capabilities.`),safeAreaInsets:F({top:j().describe(`Top safe area inset in pixels.`),right:j().describe(`Right safe area inset in pixels.`),bottom:j().describe(`Bottom safe area inset in pixels.`),left:j().describe(`Left safe area inset in pixels.`)}).optional().describe(`Mobile safe area boundaries in pixels.`)}).passthrough(),ug=F({method:B(`ui/notifications/host-context-changed`),params:lg.describe(`Partial context update containing only changed fields.`)}),F({method:B(`ui/update-model-context`),params:F({content:P(jp).optional().describe(`Context content blocks (text, image, etc.).`),structuredContent:R(A(),N().describe(`Structured content for machine-readable context data.`)).optional().describe(`Structured content for machine-readable context data.`)})}),F({method:B(`ui/initialize`),params:F({appInfo:bf.describe(`App identification (name and version).`),appCapabilities:ag.describe(`Features and capabilities this app provides.`),protocolVersion:A().describe(`Protocol version this app supports.`)})}),dg=F({protocolVersion:A().describe(`Negotiated protocol version string (e.g., "2025-11-21").`),hostInfo:bf.describe(`Host application identification and version.`),hostCapabilities:ig.describe(`Features and capabilities provided by the host.`),hostContext:lg.describe(`Rich context about the host environment.`)}).passthrough(),fg={target:`draft-2020-12`},pg=class e extends zh{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;_registeredTools={};_initializedSent=!1;_assertInitialized(e){if(this._initializedSent)return;let t=`[ext-apps] App.${e}() called before connect() completed the ui/initialize handshake. Await app.connect() before calling this method, or move data loading to an ontoolresult handler.`;if(this.options?.strict)throw Error(t);console.warn(`${t}. This will throw in a future release.`)}eventSchemas={toolinput:Zh,toolinputpartial:Qh,toolresult:cg,toolcancelled:$h,hostcontextchanged:ug};static ONE_SHOT_EVENTS=new Set([`toolinput`,`toolinputpartial`,`toolresult`,`toolcancelled`]);_everHadListener=new Set;_assertHandlerTiming(t){if(!e.ONE_SHOT_EVENTS.has(t)||this._everHadListener.has(t)||(this._everHadListener.add(t),!this._initializedSent))return;let n=`[ext-apps] "${String(t)}" handler registered after connect() completed the ui/initialize handshake. The host may have already sent this notification. Register handlers before calling app.connect().`;if(this.options?.strict)throw Error(n);console.warn(n)}setEventHandler(e,t){t&&this._assertHandlerTiming(e),super.setEventHandler(e,t)}addEventListener(e,t){this._assertHandlerTiming(e),super.addEventListener(e,t)}onEventDispatch(e,t){e===`hostcontextchanged`&&(this._hostContext={...this._hostContext,...t})}constructor(e,t={},n={autoResize:!0}){super(n),this._appInfo=e,this._capabilities=t,this.options=n,n.allowUnsafeEval||o({jitless:!0}),this.setRequestHandler(jf,e=>(console.log(`Received ping:`,e.params),{})),this.setEventHandler(`hostcontextchanged`,void 0)}registerCapabilities(e){if(this.transport)throw Error(`Cannot register capabilities after transport is established`);this._capabilities=Dh(this._capabilities,e)}registerTool(e,t,n){if(this._registeredTools[e])throw Error(`Tool ${e} is already registered`);let r=this,i=()=>{r._initializedSent&&r._capabilities.tools?.listChanged&&r.sendToolListChanged()},a=t.inputSchema!==void 0,o={title:t.title,description:t.description,inputSchema:t.inputSchema,outputSchema:t.outputSchema,annotations:t.annotations,_meta:t._meta,enabled:!0,enable(){this.enabled=!0,i()},disable(){this.enabled=!1,i()},update(e){Object.assign(this,e),i()},remove(){r._registeredTools[e]===o&&(delete r._registeredTools[e],i())},handler:async(t,r)=>{if(!o.enabled)throw Error(`Tool ${e} is disabled`);let i;if(a){let a=o.inputSchema;i=await n(a?await Ih(a,t??{},`Invalid input for tool ${e}: `):t??{},r)}else i=await n(r);return o.outputSchema&&!i.isError&&(i.structuredContent=await Ih(o.outputSchema,i.structuredContent,`Invalid output for tool ${e}: `)),i}};return this._registeredTools[e]=o,!this._capabilities.tools&&!this.transport&&this.registerCapabilities({tools:{listChanged:!0}}),this.ensureToolHandlersInitialized(),i(),o}_toolHandlersInitialized=!1;ensureToolHandlersInitialized(){this._toolHandlersInitialized||(this._toolHandlersInitialized=!0,this.oncalltool=async(e,t)=>{let n=this._registeredTools[e.name];if(!n)throw Error(`Tool ${e.name} not found`);return n.handler(e.arguments,t)},this.onlisttools=async(e,t)=>({tools:await Promise.all(Object.entries(this._registeredTools).filter(([e,t])=>t.enabled).map(async([e,t])=>{let n={name:e,title:t.title,description:t.description,inputSchema:t.inputSchema?await Fh(t.inputSchema,`input`):{type:`object`,properties:{}}};return t.outputSchema&&(n.outputSchema=await Fh(t.outputSchema,`output`)),t.annotations&&(n.annotations=t.annotations),t._meta&&(n._meta=t._meta),n}))}))}async sendToolListChanged(e={}){this._assertInitialized(`sendToolListChanged`),await this.notification({method:`notifications/tools/list_changed`,params:e})}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}get ontoolinput(){return this.getEventHandler(`toolinput`)}set ontoolinput(e){this.setEventHandler(`toolinput`,e)}get ontoolinputpartial(){return this.getEventHandler(`toolinputpartial`)}set ontoolinputpartial(e){this.setEventHandler(`toolinputpartial`,e)}get ontoolresult(){return this.getEventHandler(`toolresult`)}set ontoolresult(e){this.setEventHandler(`toolresult`,e)}get ontoolcancelled(){return this.getEventHandler(`toolcancelled`)}set ontoolcancelled(e){this.setEventHandler(`toolcancelled`,e)}get onhostcontextchanged(){return this.getEventHandler(`hostcontextchanged`)}set onhostcontextchanged(e){this.setEventHandler(`hostcontextchanged`,e)}_onteardown;get onteardown(){return this._onteardown}set onteardown(e){this.warnIfRequestHandlerReplaced(`onteardown`,this._onteardown,e),this._onteardown=e,this.replaceRequestHandler(ng,(e,t)=>{if(!this._onteardown)throw Error(`No onteardown handler set`);return this._onteardown(e.params,t)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(e){this.warnIfRequestHandlerReplaced(`oncalltool`,this._oncalltool,e),this._oncalltool=e,this.replaceRequestHandler(Hp,(e,t)=>{if(!this._oncalltool)throw Error(`No oncalltool handler set`);return this._oncalltool(e.params,t)})}_onlisttools;get onlisttools(){return this._onlisttools}set onlisttools(e){this.warnIfRequestHandlerReplaced(`onlisttools`,this._onlisttools,e),this._onlisttools=e,this.replaceRequestHandler(Rp,(e,t)=>{if(!this._onlisttools)throw Error(`No onlisttools handler set`);return this._onlisttools(e.params,t)})}assertCapabilityForMethod(e){if(e===`sampling/createMessage`&&!this._hostCapabilities?.sampling)throw Error(`Host does not support sampling (required for ${e})`)}assertRequestHandlerCapability(e){switch(e){case`tools/call`:case`tools/list`:if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${e})`);return;case`ping`:case`ui/resource-teardown`:return;default:throw Error(`No handler for method ${e} registered`)}}assertNotificationCapability(e){}assertTaskCapability(e){throw Error(`Tasks are not supported in MCP Apps`)}assertTaskHandlerCapability(e){throw Error(`Task handlers are not supported in MCP Apps`)}async callServerTool(e,t){if(this._assertInitialized(`callServerTool`),typeof e==`string`)throw Error(`callServerTool() expects an object as its first argument, but received a string ("${e}"). Did you mean: callServerTool({ name: "${e}", arguments: { ... } })?`);return await this.request({method:`tools/call`,params:e},Bp,{onprogress:()=>{},resetTimeoutOnProgress:!0,...t})}async readServerResource(e,t){return this._assertInitialized(`readServerResource`),await this.request({method:`resources/read`,params:e},dp,t)}async listServerResources(e,t){return this._assertInitialized(`listServerResources`),await this.request({method:`resources/list`,params:e},ap,t)}async createSamplingMessage(e,t){this._assertInitialized(`createSamplingMessage`);let n=e.tools?am:im;return await this.request({method:`sampling/createMessage`,params:e},n,t)}sendMessage(e,t){return this._assertInitialized(`sendMessage`),this.request({method:`ui/message`,params:e},Jh,t)}sendLog(e){return this.notification({method:`notifications/message`,params:e})}updateModelContext(e,t){return this._assertInitialized(`updateModelContext`),this.request({method:`ui/update-model-context`,params:e},mf,t)}openLink(e,t){return this._assertInitialized(`openLink`),this.request({method:`ui/open-link`,params:e},Kh,t)}sendOpenLink=this.openLink;downloadFile(e,t){return this._assertInitialized(`downloadFile`),this.request({method:`ui/download-file`,params:e},qh,t)}requestTeardown(e={}){return this.notification({method:`ui/notifications/request-teardown`,params:e})}requestDisplayMode(e,t){return this._assertInitialized(`requestDisplayMode`),this.request({method:`ui/request-display-mode`,params:e},og,t)}sendSizeChanged(e){return this.notification({method:`ui/notifications/size-changed`,params:e})}setupSizeChangedNotifications(){let e=!1,t=0,n=0,r=()=>{e||(e=!0,requestAnimationFrame(()=>{e=!1;let r=document.documentElement,i=r.style.height;r.style.height=`max-content`;let a=Math.ceil(r.getBoundingClientRect().height);r.style.height=i;let o=Math.ceil(window.innerWidth);(o!==t||a!==n)&&(t=o,n=a,this.sendSizeChanged({width:o,height:a}))}))};r();let i=new ResizeObserver(r);return i.observe(document.documentElement),i.observe(document.body),()=>i.disconnect()}async connect(e=new Vh(window.parent,window.parent),t){if(this.transport)throw Error(`App is already connected. Call close() before connecting again.`);this._initializedSent=!1,await super.connect(e);try{let e=await this.request({method:`ui/initialize`,params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:Bh}},dg,t);if(e===void 0)throw Error(`Server sent invalid initialize result: ${e}`);this._hostCapabilities=e.hostCapabilities,this._hostInfo=e.hostInfo,this._hostContext=e.hostContext,await this.notification({method:`ui/notifications/initialized`}),this._initializedSent=!0,this.options?.autoResize&&this.setupSizeChangedNotifications()}catch(e){throw this.close(),e}}}}));function hg(e,t){let n,r=0,i,a=()=>{n!==void 0&&(clearTimeout(n),n=void 0)},o=new pg({name:e,version:`0.0.1`},{}),s=async e=>{let t=await o.request({method:`tools/call`,params:{name:`get_generation`,arguments:{operationId:e}}},Bp);if(!t.isError)return t.structuredContent},c=(e,o)=>{n=window.setTimeout(async()=>{if(Date.now()-r>xg){t.onTimeout?.();return}try{let n=await s(e);if(n?.status===`complete`){a(),i=n,t.onResult(n);return}}catch{}c(e,Math.min(o*1.5,bg))},o)},l=e=>{e&&(a(),i=e,t.onResult(e),e.status===`running`&&e.operationId!==void 0&&(r=Date.now(),c(e.operationId,yg)))};return o.ontoolinput=e=>{t.onInput?.(e?.arguments||{}),t.onResult({status:`running`})},o.ontoolresult=e=>l(e?.structuredContent),o.onhostcontextchanged=e=>{if(e?.theme&&Lh(e.theme),e?.styles?.variables&&Rh(e.styles.variables),e?.displayMode&&(document.documentElement.dataset.displayMode=e.displayMode),e?.safeAreaInsets){let{top:t=0,right:n=0,bottom:r=0,left:i=0}=e.safeAreaInsets;document.body.style.padding=`${t}px ${n}px ${r}px ${i}px`}},o.onteardown=async()=>(a(),t.onTeardown?.(),{}),o.connect(new Vh(window.parent,window.parent)).catch(()=>{}),{app:o,current:()=>i}}async function gg(e,t){if(e.getHostCapabilities()?.updateModelContext)try{await e.updateModelContext({content:[{type:`text`,text:t}]})}catch{}}async function _g(e,t){let n=Sg();if(n?.openExternal){await n.openExternal({href:t,redirectUrl:!1});return}await e.openLink({url:t})}async function vg(e,t){if(e.getHostCapabilities()?.message)return!(await e.sendMessage({role:`user`,content:[{type:`text`,text:t}]})).isError;let n=Sg();return n?.sendFollowUpMessage?(await n.sendFollowUpMessage({prompt:t}),!0):!1}var $,yg,bg,xg,Sg,Cg=t((()=>{mg(),Fm(),$=e=>document.getElementById(e),yg=2e3,bg=1e4,xg=36e4,Sg=()=>window.openai}));n((()=>{Cg();var e,t=e=>{$(`status`).textContent=e},n=e=>e.length>1?`linear-gradient(180deg, ${e.join(`, `)})`:e[0]||`transparent`;function r(e){let[t,n,r]=e.split(`-`).map(Number);return new Date(t,n-1,r).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,...t===new Date().getFullYear()?{}:{year:`numeric`}})}function i(e){try{return new URL(e).hostname.replace(/^www\./,``)}catch{return`the web`}}var a=e=>Date.parse(e.expiresAt)<=Date.now();function o(e){let o=t=>new Intl.NumberFormat(`en-US`,{style:`currency`,currency:e.currency}).format(t);$(`thumb`).style.background=n(e.swatches.shell),$(`cap`).style.background=n(e.swatches.button),$(`title`).textContent=e.title,$(`summary`).textContent=e.summary,$(`item-label`).textContent=e.item.label,$(`item-amount`).textContent=o(e.item.amount),$(`total`).textContent=o(e.total),$(`lines`).hidden=!1;let s=`Printed and assembled by Womp`;$(`note`).textContent=e.shipsBy?`Ships by ${r(e.shipsBy)} · ${s}`:s,$(`note`).hidden=!1;let c=$(`checkout`);c.textContent=`Checkout on ${i(e.checkoutUrl)} ↗`,c.disabled=a(e),$(`foot`).hidden=!1,t(a(e)?`This quote has expired. Ask in the chat for a new one.`:``)}var s=hg(`Quote`,{onInput:()=>t(`Getting your quote…`),onResult:t=>{let n=t;typeof n.checkoutUrl==`string`&&typeof n.designId==`string`&&(e=n,o(e))}});$(`checkout`).addEventListener(`click`,async()=>{if(e){if(a(e)){o(e);return}try{await _g(s.app,e.checkoutUrl),t(`Checkout is open in your browser. Your design and total carry over.`),gg(s.app,`The user opened checkout for camera design ${e.designId}, revision ${e.rev}. They enter their address and pay on that page.`)}catch{t(`Couldn't open checkout here. Ask in the chat for the checkout link.`)}}}),$(`edit`).addEventListener(`click`,async()=>{try{await vg(s.app,`Reopen the camera designer so I can change this design`)||t(`Ask in the chat to change the design.`)}catch{t(`Ask in the chat to change the design.`)}})}))();</script>
196
+ container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:A().optional().describe(`User's language and region preference in BCP 47 format.`),timeZone:A().optional().describe(`User's timezone in IANA format.`),userAgent:A().optional().describe(`Host application identifier.`),platform:L([B(`web`),B(`desktop`),B(`mobile`)]).optional().describe(`Platform type for responsive design decisions.`),deviceCapabilities:F({touch:M().optional().describe(`Whether the device supports touch input.`),hover:M().optional().describe(`Whether the device supports hover interactions.`)}).optional().describe(`Device input capabilities.`),safeAreaInsets:F({top:j().describe(`Top safe area inset in pixels.`),right:j().describe(`Right safe area inset in pixels.`),bottom:j().describe(`Bottom safe area inset in pixels.`),left:j().describe(`Left safe area inset in pixels.`)}).optional().describe(`Mobile safe area boundaries in pixels.`)}).passthrough(),ug=F({method:B(`ui/notifications/host-context-changed`),params:lg.describe(`Partial context update containing only changed fields.`)}),F({method:B(`ui/update-model-context`),params:F({content:P(jp).optional().describe(`Context content blocks (text, image, etc.).`),structuredContent:R(A(),N().describe(`Structured content for machine-readable context data.`)).optional().describe(`Structured content for machine-readable context data.`)})}),F({method:B(`ui/initialize`),params:F({appInfo:bf.describe(`App identification (name and version).`),appCapabilities:ag.describe(`Features and capabilities this app provides.`),protocolVersion:A().describe(`Protocol version this app supports.`)})}),dg=F({protocolVersion:A().describe(`Negotiated protocol version string (e.g., "2025-11-21").`),hostInfo:bf.describe(`Host application identification and version.`),hostCapabilities:ig.describe(`Features and capabilities provided by the host.`),hostContext:lg.describe(`Rich context about the host environment.`)}).passthrough(),fg={target:`draft-2020-12`},pg=class e extends zh{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;_registeredTools={};_initializedSent=!1;_assertInitialized(e){if(this._initializedSent)return;let t=`[ext-apps] App.${e}() called before connect() completed the ui/initialize handshake. Await app.connect() before calling this method, or move data loading to an ontoolresult handler.`;if(this.options?.strict)throw Error(t);console.warn(`${t}. This will throw in a future release.`)}eventSchemas={toolinput:Zh,toolinputpartial:Qh,toolresult:cg,toolcancelled:$h,hostcontextchanged:ug};static ONE_SHOT_EVENTS=new Set([`toolinput`,`toolinputpartial`,`toolresult`,`toolcancelled`]);_everHadListener=new Set;_assertHandlerTiming(t){if(!e.ONE_SHOT_EVENTS.has(t)||this._everHadListener.has(t)||(this._everHadListener.add(t),!this._initializedSent))return;let n=`[ext-apps] "${String(t)}" handler registered after connect() completed the ui/initialize handshake. The host may have already sent this notification. Register handlers before calling app.connect().`;if(this.options?.strict)throw Error(n);console.warn(n)}setEventHandler(e,t){t&&this._assertHandlerTiming(e),super.setEventHandler(e,t)}addEventListener(e,t){this._assertHandlerTiming(e),super.addEventListener(e,t)}onEventDispatch(e,t){e===`hostcontextchanged`&&(this._hostContext={...this._hostContext,...t})}constructor(e,t={},n={autoResize:!0}){super(n),this._appInfo=e,this._capabilities=t,this.options=n,n.allowUnsafeEval||o({jitless:!0}),this.setRequestHandler(jf,e=>(console.log(`Received ping:`,e.params),{})),this.setEventHandler(`hostcontextchanged`,void 0)}registerCapabilities(e){if(this.transport)throw Error(`Cannot register capabilities after transport is established`);this._capabilities=Dh(this._capabilities,e)}registerTool(e,t,n){if(this._registeredTools[e])throw Error(`Tool ${e} is already registered`);let r=this,i=()=>{r._initializedSent&&r._capabilities.tools?.listChanged&&r.sendToolListChanged()},a=t.inputSchema!==void 0,o={title:t.title,description:t.description,inputSchema:t.inputSchema,outputSchema:t.outputSchema,annotations:t.annotations,_meta:t._meta,enabled:!0,enable(){this.enabled=!0,i()},disable(){this.enabled=!1,i()},update(e){Object.assign(this,e),i()},remove(){r._registeredTools[e]===o&&(delete r._registeredTools[e],i())},handler:async(t,r)=>{if(!o.enabled)throw Error(`Tool ${e} is disabled`);let i;if(a){let a=o.inputSchema;i=await n(a?await Ih(a,t??{},`Invalid input for tool ${e}: `):t??{},r)}else i=await n(r);return o.outputSchema&&!i.isError&&(i.structuredContent=await Ih(o.outputSchema,i.structuredContent,`Invalid output for tool ${e}: `)),i}};return this._registeredTools[e]=o,!this._capabilities.tools&&!this.transport&&this.registerCapabilities({tools:{listChanged:!0}}),this.ensureToolHandlersInitialized(),i(),o}_toolHandlersInitialized=!1;ensureToolHandlersInitialized(){this._toolHandlersInitialized||(this._toolHandlersInitialized=!0,this.oncalltool=async(e,t)=>{let n=this._registeredTools[e.name];if(!n)throw Error(`Tool ${e.name} not found`);return n.handler(e.arguments,t)},this.onlisttools=async(e,t)=>({tools:await Promise.all(Object.entries(this._registeredTools).filter(([e,t])=>t.enabled).map(async([e,t])=>{let n={name:e,title:t.title,description:t.description,inputSchema:t.inputSchema?await Fh(t.inputSchema,`input`):{type:`object`,properties:{}}};return t.outputSchema&&(n.outputSchema=await Fh(t.outputSchema,`output`)),t.annotations&&(n.annotations=t.annotations),t._meta&&(n._meta=t._meta),n}))}))}async sendToolListChanged(e={}){this._assertInitialized(`sendToolListChanged`),await this.notification({method:`notifications/tools/list_changed`,params:e})}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}get ontoolinput(){return this.getEventHandler(`toolinput`)}set ontoolinput(e){this.setEventHandler(`toolinput`,e)}get ontoolinputpartial(){return this.getEventHandler(`toolinputpartial`)}set ontoolinputpartial(e){this.setEventHandler(`toolinputpartial`,e)}get ontoolresult(){return this.getEventHandler(`toolresult`)}set ontoolresult(e){this.setEventHandler(`toolresult`,e)}get ontoolcancelled(){return this.getEventHandler(`toolcancelled`)}set ontoolcancelled(e){this.setEventHandler(`toolcancelled`,e)}get onhostcontextchanged(){return this.getEventHandler(`hostcontextchanged`)}set onhostcontextchanged(e){this.setEventHandler(`hostcontextchanged`,e)}_onteardown;get onteardown(){return this._onteardown}set onteardown(e){this.warnIfRequestHandlerReplaced(`onteardown`,this._onteardown,e),this._onteardown=e,this.replaceRequestHandler(ng,(e,t)=>{if(!this._onteardown)throw Error(`No onteardown handler set`);return this._onteardown(e.params,t)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(e){this.warnIfRequestHandlerReplaced(`oncalltool`,this._oncalltool,e),this._oncalltool=e,this.replaceRequestHandler(Hp,(e,t)=>{if(!this._oncalltool)throw Error(`No oncalltool handler set`);return this._oncalltool(e.params,t)})}_onlisttools;get onlisttools(){return this._onlisttools}set onlisttools(e){this.warnIfRequestHandlerReplaced(`onlisttools`,this._onlisttools,e),this._onlisttools=e,this.replaceRequestHandler(Rp,(e,t)=>{if(!this._onlisttools)throw Error(`No onlisttools handler set`);return this._onlisttools(e.params,t)})}assertCapabilityForMethod(e){if(e===`sampling/createMessage`&&!this._hostCapabilities?.sampling)throw Error(`Host does not support sampling (required for ${e})`)}assertRequestHandlerCapability(e){switch(e){case`tools/call`:case`tools/list`:if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${e})`);return;case`ping`:case`ui/resource-teardown`:return;default:throw Error(`No handler for method ${e} registered`)}}assertNotificationCapability(e){}assertTaskCapability(e){throw Error(`Tasks are not supported in MCP Apps`)}assertTaskHandlerCapability(e){throw Error(`Task handlers are not supported in MCP Apps`)}async callServerTool(e,t){if(this._assertInitialized(`callServerTool`),typeof e==`string`)throw Error(`callServerTool() expects an object as its first argument, but received a string ("${e}"). Did you mean: callServerTool({ name: "${e}", arguments: { ... } })?`);return await this.request({method:`tools/call`,params:e},Bp,{onprogress:()=>{},resetTimeoutOnProgress:!0,...t})}async readServerResource(e,t){return this._assertInitialized(`readServerResource`),await this.request({method:`resources/read`,params:e},dp,t)}async listServerResources(e,t){return this._assertInitialized(`listServerResources`),await this.request({method:`resources/list`,params:e},ap,t)}async createSamplingMessage(e,t){this._assertInitialized(`createSamplingMessage`);let n=e.tools?am:im;return await this.request({method:`sampling/createMessage`,params:e},n,t)}sendMessage(e,t){return this._assertInitialized(`sendMessage`),this.request({method:`ui/message`,params:e},Jh,t)}sendLog(e){return this.notification({method:`notifications/message`,params:e})}updateModelContext(e,t){return this._assertInitialized(`updateModelContext`),this.request({method:`ui/update-model-context`,params:e},mf,t)}openLink(e,t){return this._assertInitialized(`openLink`),this.request({method:`ui/open-link`,params:e},Kh,t)}sendOpenLink=this.openLink;downloadFile(e,t){return this._assertInitialized(`downloadFile`),this.request({method:`ui/download-file`,params:e},qh,t)}requestTeardown(e={}){return this.notification({method:`ui/notifications/request-teardown`,params:e})}requestDisplayMode(e,t){return this._assertInitialized(`requestDisplayMode`),this.request({method:`ui/request-display-mode`,params:e},og,t)}sendSizeChanged(e){return this.notification({method:`ui/notifications/size-changed`,params:e})}setupSizeChangedNotifications(){let e=!1,t=0,n=0,r=()=>{e||(e=!0,requestAnimationFrame(()=>{e=!1;let r=document.documentElement,i=r.style.height;r.style.height=`max-content`;let a=Math.ceil(r.getBoundingClientRect().height);r.style.height=i;let o=Math.ceil(window.innerWidth);(o!==t||a!==n)&&(t=o,n=a,this.sendSizeChanged({width:o,height:a}))}))};r();let i=new ResizeObserver(r);return i.observe(document.documentElement),i.observe(document.body),()=>i.disconnect()}async connect(e=new Vh(window.parent,window.parent),t){if(this.transport)throw Error(`App is already connected. Call close() before connecting again.`);this._initializedSent=!1,await super.connect(e);try{let e=await this.request({method:`ui/initialize`,params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:Bh}},dg,t);if(e===void 0)throw Error(`Server sent invalid initialize result: ${e}`);this._hostCapabilities=e.hostCapabilities,this._hostInfo=e.hostInfo,this._hostContext=e.hostContext,await this.notification({method:`ui/notifications/initialized`}),this._initializedSent=!0,this.options?.autoResize&&this.setupSizeChangedNotifications()}catch(e){throw this.close(),e}}}}));function hg(e,t){let n,r=0,i,a=()=>{n!==void 0&&(clearTimeout(n),n=void 0)},o=new pg({name:e,version:`0.0.1`},{}),s=async e=>{let t=await o.request({method:`tools/call`,params:{name:`get_generation`,arguments:{operationId:e}}},Bp);if(!t.isError)return t.structuredContent},c=(e,o)=>{n=window.setTimeout(async()=>{if(Date.now()-r>Cg){t.onTimeout?.();return}try{let n=await s(e);if(n?.status===`complete`){a(),i=n,t.onResult(n);return}}catch{}c(e,Math.min(o*1.5,Sg))},o)},l=e=>{e&&(a(),i=e,t.onResult(e),e.status===`running`&&e.operationId!==void 0&&(r=Date.now(),c(e.operationId,xg)))};return o.ontoolinput=e=>{t.onInput?.(e?.arguments||{}),t.onResult({status:`running`})},o.ontoolresult=e=>{let t=Eg(e?._meta)??_g();l(t??e?.structuredContent),t||vg(e=>l(e))},o.onhostcontextchanged=e=>{if(e?.theme&&Lh(e.theme),e?.styles?.variables&&Rh(e.styles.variables),e?.displayMode&&(document.documentElement.dataset.displayMode=e.displayMode),e?.safeAreaInsets){let{top:t=0,right:n=0,bottom:r=0,left:i=0}=e.safeAreaInsets;document.body.style.padding=`${t}px ${n}px ${r}px ${i}px`}},o.onteardown=async()=>(a(),t.onTeardown?.(),{}),o.connect(new Vh(window.parent,window.parent)).catch(()=>{}),{app:o,current:()=>i}}async function gg(e,t){if(e.getHostCapabilities()?.updateModelContext)try{await e.updateModelContext({content:[{type:`text`,text:t}]})}catch{}}function _g(){let e=wg()?.toolResponseMetadata;if(!(!e||typeof e!=`object`))return Eg(e)??Eg(e.mcp_tool_result?._meta)??Eg(e.call_tool_result?._meta)}function vg(e){if(!wg())return;let t=()=>window.removeEventListener(`openai:set_globals`,n),n=()=>{let n=_g();n!==void 0&&(t(),e(n))};window.addEventListener(`openai:set_globals`,n),setTimeout(t,Dg)}async function yg(e,t){let n=wg();if(n?.openExternal){await n.openExternal({href:t,redirectUrl:!1});return}await e.openLink({url:t})}async function bg(e,t){if(e.getHostCapabilities()?.message)return!(await e.sendMessage({role:`user`,content:[{type:`text`,text:t}]})).isError;let n=wg();return n?.sendFollowUpMessage?(await n.sendFollowUpMessage({prompt:t}),!0):!1}var $,xg,Sg,Cg,wg,Tg,Eg,Dg,Og=t((()=>{mg(),Fm(),$=e=>document.getElementById(e),xg=2e3,Sg=1e4,Cg=36e4,wg=()=>window.openai,Tg=`openai-mcp/card`,Eg=e=>e&&typeof e==`object`?e[Tg]:void 0,Dg=1e4}));n((()=>{Og();var e,t=e=>{$(`status`).textContent=e},n=e=>e.length>1?`linear-gradient(180deg, ${e.join(`, `)})`:e[0]||`transparent`;function r(e){let[t,n,r]=e.split(`-`).map(Number);return new Date(t,n-1,r).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,...t===new Date().getFullYear()?{}:{year:`numeric`}})}function i(e){try{return new URL(e).hostname.replace(/^www\./,``)}catch{return`the web`}}var a=e=>Date.parse(e.expiresAt)<=Date.now();function o(e){let o=t=>new Intl.NumberFormat(`en-US`,{style:`currency`,currency:e.currency}).format(t);$(`thumb`).style.background=n(e.swatches.shell),$(`cap`).style.background=n(e.swatches.button),$(`title`).textContent=e.title,$(`summary`).textContent=e.summary,$(`item-label`).textContent=e.item.label,$(`item-amount`).textContent=o(e.item.amount),$(`total`).textContent=o(e.total),$(`lines`).hidden=!1;let s=`Printed and assembled by Womp`;$(`note`).textContent=e.shipsBy?`Ships by ${r(e.shipsBy)} · ${s}`:s,$(`note`).hidden=!1;let c=$(`checkout`);c.textContent=`Checkout on ${i(e.checkoutUrl)} ↗`,c.disabled=a(e),$(`foot`).hidden=!1,t(a(e)?`This quote has expired. Ask in the chat for a new one.`:``)}var s=hg(`Quote`,{onInput:()=>t(`Getting your quote…`),onResult:n=>{let r=n;if(typeof r.designId==`string`){if(typeof r.checkoutUrl!=`string`){window.setTimeout(()=>{e||t(`Couldn't show the quote here. Ask in the chat to order it again.`)},1e4);return}e=r,o(e)}}});$(`checkout`).addEventListener(`click`,async()=>{if(e){if(a(e)){o(e);return}try{await yg(s.app,e.checkoutUrl),t(`Checkout is open in your browser. Your design and total carry over.`),gg(s.app,`The user opened checkout for camera design ${e.designId}, revision ${e.rev}. They enter their address and pay on that page.`)}catch{t(`Couldn't open checkout here. Ask in the chat for the checkout link.`)}}}),$(`edit`).addEventListener(`click`,async()=>{try{await bg(s.app,`Reopen the camera designer so I can change this design`)||t(`Ask in the chat to change the design.`)}catch{t(`Ask in the chat to change the design.`)}})}))();</script>
197
197
  </head>
198
198
  <body>
199
199
  <div class="card">
@@ -175,7 +175,7 @@ Boolean requesting whether a visible border and background is provided by the ho
175
175
  - omitted: host decides border`)}),F({method:B(`ui/request-display-mode`),params:F({mode:Hh.describe(`The display mode being requested.`)})}),ag=F({mode:Hh.describe(`The display mode that was actually set. May differ from requested if not supported.`)}).passthrough(),og=L([B(`model`),B(`app`)]).describe(`Tool visibility scope - who can access the tool.`),F({resourceUri:A().optional(),visibility:P(og).optional().describe(`Who can access this tool. Default: ["model", "app"]
176
176
  - "model": Tool visible to and callable by the agent
177
177
  - "app": Tool callable by the app from this server only`),csp:Hl().optional(),permissions:Hl().optional()}),F({mimeTypes:P(A()).optional().describe('Array of supported MIME types for UI resources.\nMust include `"text/html;profile=mcp-app"` for MCP Apps support.')}),F({method:B(`ui/download-file`),params:F({contents:P(L([Op,kp])).describe(`Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.`)})}),F({method:B(`ui/message`),params:F({role:B(`user`).describe(`Message role, currently only "user" is supported.`),content:P(Ap).describe(`Message content blocks (text, image, etc.).`)})}),F({method:B(`ui/notifications/sandbox-resource-ready`),params:F({html:A().describe(`HTML content to load into the inner iframe.`),sandbox:A().optional().describe(`Optional override for the inner iframe's sandbox attribute.`),csp:Jh.optional().describe(`CSP configuration from resource metadata.`),permissions:Yh.optional().describe(`Sandbox permissions from resource metadata.`)})}),sg=F({method:B(`ui/notifications/tool-result`),params:zp.describe(`Standard MCP tool execution result.`)}),cg=F({toolInfo:F({id:nf.optional().describe(`JSON-RPC id of the tools/call request.`),tool:Ip.describe(`Tool definition including name, inputSchema, etc.`)}).optional().describe(`Metadata of the tool call that instantiated this App.`),theme:Vh.optional().describe(`Current color theme preference.`),styles:eg.optional().describe(`Style configuration for theming the app.`),displayMode:Hh.optional().describe(`How the UI is currently displayed.`),availableDisplayModes:P(Hh).optional().describe(`Display modes the host supports.`),containerDimensions:L([F({height:j().describe(`Fixed container height in pixels.`)}),F({maxHeight:L([j(),zl()]).optional().describe(`Maximum container height in pixels.`)})]).and(L([F({width:j().describe(`Fixed container width in pixels.`)}),F({maxWidth:L([j(),zl()]).optional().describe(`Maximum container width in pixels.`)})])).optional().describe(`Container dimensions. Represents the dimensions of the iframe or other
178
- container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:A().optional().describe(`User's language and region preference in BCP 47 format.`),timeZone:A().optional().describe(`User's timezone in IANA format.`),userAgent:A().optional().describe(`Host application identifier.`),platform:L([B(`web`),B(`desktop`),B(`mobile`)]).optional().describe(`Platform type for responsive design decisions.`),deviceCapabilities:F({touch:M().optional().describe(`Whether the device supports touch input.`),hover:M().optional().describe(`Whether the device supports hover interactions.`)}).optional().describe(`Device input capabilities.`),safeAreaInsets:F({top:j().describe(`Top safe area inset in pixels.`),right:j().describe(`Right safe area inset in pixels.`),bottom:j().describe(`Bottom safe area inset in pixels.`),left:j().describe(`Left safe area inset in pixels.`)}).optional().describe(`Mobile safe area boundaries in pixels.`)}).passthrough(),lg=F({method:B(`ui/notifications/host-context-changed`),params:cg.describe(`Partial context update containing only changed fields.`)}),F({method:B(`ui/update-model-context`),params:F({content:P(Ap).optional().describe(`Context content blocks (text, image, etc.).`),structuredContent:R(A(),N().describe(`Structured content for machine-readable context data.`)).optional().describe(`Structured content for machine-readable context data.`)})}),F({method:B(`ui/initialize`),params:F({appInfo:yf.describe(`App identification (name and version).`),appCapabilities:ig.describe(`Features and capabilities this app provides.`),protocolVersion:A().describe(`Protocol version this app supports.`)})}),ug=F({protocolVersion:A().describe(`Negotiated protocol version string (e.g., "2025-11-21").`),hostInfo:yf.describe(`Host application identification and version.`),hostCapabilities:rg.describe(`Features and capabilities provided by the host.`),hostContext:cg.describe(`Rich context about the host environment.`)}).passthrough(),dg={target:`draft-2020-12`},fg=class e extends Rh{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;_registeredTools={};_initializedSent=!1;_assertInitialized(e){if(this._initializedSent)return;let t=`[ext-apps] App.${e}() called before connect() completed the ui/initialize handshake. Await app.connect() before calling this method, or move data loading to an ontoolresult handler.`;if(this.options?.strict)throw Error(t);console.warn(`${t}. This will throw in a future release.`)}eventSchemas={toolinput:Xh,toolinputpartial:Zh,toolresult:sg,toolcancelled:Qh,hostcontextchanged:lg};static ONE_SHOT_EVENTS=new Set([`toolinput`,`toolinputpartial`,`toolresult`,`toolcancelled`]);_everHadListener=new Set;_assertHandlerTiming(t){if(!e.ONE_SHOT_EVENTS.has(t)||this._everHadListener.has(t)||(this._everHadListener.add(t),!this._initializedSent))return;let n=`[ext-apps] "${String(t)}" handler registered after connect() completed the ui/initialize handshake. The host may have already sent this notification. Register handlers before calling app.connect().`;if(this.options?.strict)throw Error(n);console.warn(n)}setEventHandler(e,t){t&&this._assertHandlerTiming(e),super.setEventHandler(e,t)}addEventListener(e,t){this._assertHandlerTiming(e),super.addEventListener(e,t)}onEventDispatch(e,t){e===`hostcontextchanged`&&(this._hostContext={...this._hostContext,...t})}constructor(e,t={},n={autoResize:!0}){super(n),this._appInfo=e,this._capabilities=t,this.options=n,n.allowUnsafeEval||o({jitless:!0}),this.setRequestHandler(Af,e=>(console.log(`Received ping:`,e.params),{})),this.setEventHandler(`hostcontextchanged`,void 0)}registerCapabilities(e){if(this.transport)throw Error(`Cannot register capabilities after transport is established`);this._capabilities=Eh(this._capabilities,e)}registerTool(e,t,n){if(this._registeredTools[e])throw Error(`Tool ${e} is already registered`);let r=this,i=()=>{r._initializedSent&&r._capabilities.tools?.listChanged&&r.sendToolListChanged()},a=t.inputSchema!==void 0,o={title:t.title,description:t.description,inputSchema:t.inputSchema,outputSchema:t.outputSchema,annotations:t.annotations,_meta:t._meta,enabled:!0,enable(){this.enabled=!0,i()},disable(){this.enabled=!1,i()},update(e){Object.assign(this,e),i()},remove(){r._registeredTools[e]===o&&(delete r._registeredTools[e],i())},handler:async(t,r)=>{if(!o.enabled)throw Error(`Tool ${e} is disabled`);let i;if(a){let a=o.inputSchema;i=await n(a?await Fh(a,t??{},`Invalid input for tool ${e}: `):t??{},r)}else i=await n(r);return o.outputSchema&&!i.isError&&(i.structuredContent=await Fh(o.outputSchema,i.structuredContent,`Invalid output for tool ${e}: `)),i}};return this._registeredTools[e]=o,!this._capabilities.tools&&!this.transport&&this.registerCapabilities({tools:{listChanged:!0}}),this.ensureToolHandlersInitialized(),i(),o}_toolHandlersInitialized=!1;ensureToolHandlersInitialized(){this._toolHandlersInitialized||(this._toolHandlersInitialized=!0,this.oncalltool=async(e,t)=>{let n=this._registeredTools[e.name];if(!n)throw Error(`Tool ${e.name} not found`);return n.handler(e.arguments,t)},this.onlisttools=async(e,t)=>({tools:await Promise.all(Object.entries(this._registeredTools).filter(([e,t])=>t.enabled).map(async([e,t])=>{let n={name:e,title:t.title,description:t.description,inputSchema:t.inputSchema?await Ph(t.inputSchema,`input`):{type:`object`,properties:{}}};return t.outputSchema&&(n.outputSchema=await Ph(t.outputSchema,`output`)),t.annotations&&(n.annotations=t.annotations),t._meta&&(n._meta=t._meta),n}))}))}async sendToolListChanged(e={}){this._assertInitialized(`sendToolListChanged`),await this.notification({method:`notifications/tools/list_changed`,params:e})}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}get ontoolinput(){return this.getEventHandler(`toolinput`)}set ontoolinput(e){this.setEventHandler(`toolinput`,e)}get ontoolinputpartial(){return this.getEventHandler(`toolinputpartial`)}set ontoolinputpartial(e){this.setEventHandler(`toolinputpartial`,e)}get ontoolresult(){return this.getEventHandler(`toolresult`)}set ontoolresult(e){this.setEventHandler(`toolresult`,e)}get ontoolcancelled(){return this.getEventHandler(`toolcancelled`)}set ontoolcancelled(e){this.setEventHandler(`toolcancelled`,e)}get onhostcontextchanged(){return this.getEventHandler(`hostcontextchanged`)}set onhostcontextchanged(e){this.setEventHandler(`hostcontextchanged`,e)}_onteardown;get onteardown(){return this._onteardown}set onteardown(e){this.warnIfRequestHandlerReplaced(`onteardown`,this._onteardown,e),this._onteardown=e,this.replaceRequestHandler(tg,(e,t)=>{if(!this._onteardown)throw Error(`No onteardown handler set`);return this._onteardown(e.params,t)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(e){this.warnIfRequestHandlerReplaced(`oncalltool`,this._oncalltool,e),this._oncalltool=e,this.replaceRequestHandler(Vp,(e,t)=>{if(!this._oncalltool)throw Error(`No oncalltool handler set`);return this._oncalltool(e.params,t)})}_onlisttools;get onlisttools(){return this._onlisttools}set onlisttools(e){this.warnIfRequestHandlerReplaced(`onlisttools`,this._onlisttools,e),this._onlisttools=e,this.replaceRequestHandler(Lp,(e,t)=>{if(!this._onlisttools)throw Error(`No onlisttools handler set`);return this._onlisttools(e.params,t)})}assertCapabilityForMethod(e){if(e===`sampling/createMessage`&&!this._hostCapabilities?.sampling)throw Error(`Host does not support sampling (required for ${e})`)}assertRequestHandlerCapability(e){switch(e){case`tools/call`:case`tools/list`:if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${e})`);return;case`ping`:case`ui/resource-teardown`:return;default:throw Error(`No handler for method ${e} registered`)}}assertNotificationCapability(e){}assertTaskCapability(e){throw Error(`Tasks are not supported in MCP Apps`)}assertTaskHandlerCapability(e){throw Error(`Task handlers are not supported in MCP Apps`)}async callServerTool(e,t){if(this._assertInitialized(`callServerTool`),typeof e==`string`)throw Error(`callServerTool() expects an object as its first argument, but received a string ("${e}"). Did you mean: callServerTool({ name: "${e}", arguments: { ... } })?`);return await this.request({method:`tools/call`,params:e},zp,{onprogress:()=>{},resetTimeoutOnProgress:!0,...t})}async readServerResource(e,t){return this._assertInitialized(`readServerResource`),await this.request({method:`resources/read`,params:e},up,t)}async listServerResources(e,t){return this._assertInitialized(`listServerResources`),await this.request({method:`resources/list`,params:e},ip,t)}async createSamplingMessage(e,t){this._assertInitialized(`createSamplingMessage`);let n=e.tools?im:rm;return await this.request({method:`sampling/createMessage`,params:e},n,t)}sendMessage(e,t){return this._assertInitialized(`sendMessage`),this.request({method:`ui/message`,params:e},qh,t)}sendLog(e){return this.notification({method:`notifications/message`,params:e})}updateModelContext(e,t){return this._assertInitialized(`updateModelContext`),this.request({method:`ui/update-model-context`,params:e},pf,t)}openLink(e,t){return this._assertInitialized(`openLink`),this.request({method:`ui/open-link`,params:e},Gh,t)}sendOpenLink=this.openLink;downloadFile(e,t){return this._assertInitialized(`downloadFile`),this.request({method:`ui/download-file`,params:e},Kh,t)}requestTeardown(e={}){return this.notification({method:`ui/notifications/request-teardown`,params:e})}requestDisplayMode(e,t){return this._assertInitialized(`requestDisplayMode`),this.request({method:`ui/request-display-mode`,params:e},ag,t)}sendSizeChanged(e){return this.notification({method:`ui/notifications/size-changed`,params:e})}setupSizeChangedNotifications(){let e=!1,t=0,n=0,r=()=>{e||(e=!0,requestAnimationFrame(()=>{e=!1;let r=document.documentElement,i=r.style.height;r.style.height=`max-content`;let a=Math.ceil(r.getBoundingClientRect().height);r.style.height=i;let o=Math.ceil(window.innerWidth);(o!==t||a!==n)&&(t=o,n=a,this.sendSizeChanged({width:o,height:a}))}))};r();let i=new ResizeObserver(r);return i.observe(document.documentElement),i.observe(document.body),()=>i.disconnect()}async connect(e=new Bh(window.parent,window.parent),t){if(this.transport)throw Error(`App is already connected. Call close() before connecting again.`);this._initializedSent=!1,await super.connect(e);try{let e=await this.request({method:`ui/initialize`,params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:zh}},ug,t);if(e===void 0)throw Error(`Server sent invalid initialize result: ${e}`);this._hostCapabilities=e.hostCapabilities,this._hostInfo=e.hostInfo,this._hostContext=e.hostContext,await this.notification({method:`ui/notifications/initialized`}),this._initializedSent=!0,this.options?.autoResize&&this.setupSizeChangedNotifications()}catch(e){throw this.close(),e}}}}));function mg(e,t){let n,r=0,i,a=()=>{n!==void 0&&(clearTimeout(n),n=void 0)},o=new fg({name:e,version:`0.0.1`},{}),s=async e=>{let t=await o.request({method:`tools/call`,params:{name:`get_generation`,arguments:{operationId:e}}},zp);if(!t.isError)return t.structuredContent},c=(e,o)=>{n=window.setTimeout(async()=>{if(Date.now()-r>vg){t.onTimeout?.();return}try{let n=await s(e);if(n?.status===`complete`){a(),i=n,t.onResult(n);return}}catch{}c(e,Math.min(o*1.5,_g))},o)},l=e=>{e&&(a(),i=e,t.onResult(e),e.status===`running`&&e.operationId!==void 0&&(r=Date.now(),c(e.operationId,gg)))};return o.ontoolinput=e=>{t.onInput?.(e?.arguments||{}),t.onResult({status:`running`})},o.ontoolresult=e=>l(e?.structuredContent),o.onhostcontextchanged=e=>{if(e?.theme&&Ih(e.theme),e?.styles?.variables&&Lh(e.styles.variables),e?.displayMode&&(document.documentElement.dataset.displayMode=e.displayMode),e?.safeAreaInsets){let{top:t=0,right:n=0,bottom:r=0,left:i=0}=e.safeAreaInsets;document.body.style.padding=`${t}px ${n}px ${r}px ${i}px`}},o.onteardown=async()=>(a(),t.onTeardown?.(),{}),o.connect(new Bh(window.parent,window.parent)).catch(()=>{}),{app:o,current:()=>i}}var hg,gg,_g,vg,yg=t((()=>{pg(),Pm(),hg=e=>document.getElementById(e),gg=2e3,_g=1e4,vg=36e4}));n((()=>{yg();var e=e=>`$${e.toFixed(2)}`;function t(e){let t=e.toLowerCase();return t.includes(`pending`)||t.includes(`review`)||t.includes(`action`)?`wait`:t.includes(`printing`)||t.includes(`processing`)||t.includes(`way`)||t.includes(`returning`)?`move`:t.includes(`delivered`)?`done`:t.includes(`canceled`)?`stop`:``}function n(n){let r=document.createElement(`div`);r.className=`order`;let i=document.createElement(`div`);i.className=`order-head`;let a=document.createElement(`div`);a.className=`order-id`,a.textContent=`Order #${n.orderId}`;let o=document.createElement(`span`);o.className=`chip ${t(n.status)}`.trim(),o.textContent=n.status,i.append(a,o),r.append(i);let s=document.createElement(`div`);s.className=`lines`,(n.items||[]).forEach(e=>{let t=document.createElement(`div`);t.textContent=`${e.quantity}x ${e.title} (${e.materialName})`,s.append(t)}),r.append(s);let c=document.createElement(`div`);c.className=`total-row`;let l=document.createElement(`span`);l.textContent=n.discount>0?`Total (after ${e(n.discount)} discount)`:`Total`;let u=document.createElement(`b`);if(u.textContent=e(n.totalCost),c.append(l,u),r.append(c),(n.tracking||[]).forEach(e=>{let t=document.createElement(`div`);t.className=`tracking`,t.textContent=`Tracking: ${e.carrier?`${e.carrier} `:``}${e.trackingNumber}`,r.append(t)}),n.actionRequired){let t=document.createElement(`div`);t.className=`action`,t.textContent=`Action required: the measured piece costs ${e(n.actionRequired.amount)} more than quoted. Approve the adjustment on womp.com under Profile -> Orders to unblock production.`,r.append(t)}return r}function r(e){let t=e.orders??(e.orderId?[e]:[]),r=hg(`orders`);r.textContent=``,t.forEach(e=>r.append(n(e))),hg(`empty`).hidden=t.length>0,hg(`status`).textContent=``}mg(`Womp orders`,{onResult:e=>{let t=e;if(t.status===`running`){hg(`status`).textContent=`Loading…`;return}r(t)}})}))();</script>
178
+ container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:A().optional().describe(`User's language and region preference in BCP 47 format.`),timeZone:A().optional().describe(`User's timezone in IANA format.`),userAgent:A().optional().describe(`Host application identifier.`),platform:L([B(`web`),B(`desktop`),B(`mobile`)]).optional().describe(`Platform type for responsive design decisions.`),deviceCapabilities:F({touch:M().optional().describe(`Whether the device supports touch input.`),hover:M().optional().describe(`Whether the device supports hover interactions.`)}).optional().describe(`Device input capabilities.`),safeAreaInsets:F({top:j().describe(`Top safe area inset in pixels.`),right:j().describe(`Right safe area inset in pixels.`),bottom:j().describe(`Bottom safe area inset in pixels.`),left:j().describe(`Left safe area inset in pixels.`)}).optional().describe(`Mobile safe area boundaries in pixels.`)}).passthrough(),lg=F({method:B(`ui/notifications/host-context-changed`),params:cg.describe(`Partial context update containing only changed fields.`)}),F({method:B(`ui/update-model-context`),params:F({content:P(Ap).optional().describe(`Context content blocks (text, image, etc.).`),structuredContent:R(A(),N().describe(`Structured content for machine-readable context data.`)).optional().describe(`Structured content for machine-readable context data.`)})}),F({method:B(`ui/initialize`),params:F({appInfo:yf.describe(`App identification (name and version).`),appCapabilities:ig.describe(`Features and capabilities this app provides.`),protocolVersion:A().describe(`Protocol version this app supports.`)})}),ug=F({protocolVersion:A().describe(`Negotiated protocol version string (e.g., "2025-11-21").`),hostInfo:yf.describe(`Host application identification and version.`),hostCapabilities:rg.describe(`Features and capabilities provided by the host.`),hostContext:cg.describe(`Rich context about the host environment.`)}).passthrough(),dg={target:`draft-2020-12`},fg=class e extends Rh{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;_registeredTools={};_initializedSent=!1;_assertInitialized(e){if(this._initializedSent)return;let t=`[ext-apps] App.${e}() called before connect() completed the ui/initialize handshake. Await app.connect() before calling this method, or move data loading to an ontoolresult handler.`;if(this.options?.strict)throw Error(t);console.warn(`${t}. This will throw in a future release.`)}eventSchemas={toolinput:Xh,toolinputpartial:Zh,toolresult:sg,toolcancelled:Qh,hostcontextchanged:lg};static ONE_SHOT_EVENTS=new Set([`toolinput`,`toolinputpartial`,`toolresult`,`toolcancelled`]);_everHadListener=new Set;_assertHandlerTiming(t){if(!e.ONE_SHOT_EVENTS.has(t)||this._everHadListener.has(t)||(this._everHadListener.add(t),!this._initializedSent))return;let n=`[ext-apps] "${String(t)}" handler registered after connect() completed the ui/initialize handshake. The host may have already sent this notification. Register handlers before calling app.connect().`;if(this.options?.strict)throw Error(n);console.warn(n)}setEventHandler(e,t){t&&this._assertHandlerTiming(e),super.setEventHandler(e,t)}addEventListener(e,t){this._assertHandlerTiming(e),super.addEventListener(e,t)}onEventDispatch(e,t){e===`hostcontextchanged`&&(this._hostContext={...this._hostContext,...t})}constructor(e,t={},n={autoResize:!0}){super(n),this._appInfo=e,this._capabilities=t,this.options=n,n.allowUnsafeEval||o({jitless:!0}),this.setRequestHandler(Af,e=>(console.log(`Received ping:`,e.params),{})),this.setEventHandler(`hostcontextchanged`,void 0)}registerCapabilities(e){if(this.transport)throw Error(`Cannot register capabilities after transport is established`);this._capabilities=Eh(this._capabilities,e)}registerTool(e,t,n){if(this._registeredTools[e])throw Error(`Tool ${e} is already registered`);let r=this,i=()=>{r._initializedSent&&r._capabilities.tools?.listChanged&&r.sendToolListChanged()},a=t.inputSchema!==void 0,o={title:t.title,description:t.description,inputSchema:t.inputSchema,outputSchema:t.outputSchema,annotations:t.annotations,_meta:t._meta,enabled:!0,enable(){this.enabled=!0,i()},disable(){this.enabled=!1,i()},update(e){Object.assign(this,e),i()},remove(){r._registeredTools[e]===o&&(delete r._registeredTools[e],i())},handler:async(t,r)=>{if(!o.enabled)throw Error(`Tool ${e} is disabled`);let i;if(a){let a=o.inputSchema;i=await n(a?await Fh(a,t??{},`Invalid input for tool ${e}: `):t??{},r)}else i=await n(r);return o.outputSchema&&!i.isError&&(i.structuredContent=await Fh(o.outputSchema,i.structuredContent,`Invalid output for tool ${e}: `)),i}};return this._registeredTools[e]=o,!this._capabilities.tools&&!this.transport&&this.registerCapabilities({tools:{listChanged:!0}}),this.ensureToolHandlersInitialized(),i(),o}_toolHandlersInitialized=!1;ensureToolHandlersInitialized(){this._toolHandlersInitialized||(this._toolHandlersInitialized=!0,this.oncalltool=async(e,t)=>{let n=this._registeredTools[e.name];if(!n)throw Error(`Tool ${e.name} not found`);return n.handler(e.arguments,t)},this.onlisttools=async(e,t)=>({tools:await Promise.all(Object.entries(this._registeredTools).filter(([e,t])=>t.enabled).map(async([e,t])=>{let n={name:e,title:t.title,description:t.description,inputSchema:t.inputSchema?await Ph(t.inputSchema,`input`):{type:`object`,properties:{}}};return t.outputSchema&&(n.outputSchema=await Ph(t.outputSchema,`output`)),t.annotations&&(n.annotations=t.annotations),t._meta&&(n._meta=t._meta),n}))}))}async sendToolListChanged(e={}){this._assertInitialized(`sendToolListChanged`),await this.notification({method:`notifications/tools/list_changed`,params:e})}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}get ontoolinput(){return this.getEventHandler(`toolinput`)}set ontoolinput(e){this.setEventHandler(`toolinput`,e)}get ontoolinputpartial(){return this.getEventHandler(`toolinputpartial`)}set ontoolinputpartial(e){this.setEventHandler(`toolinputpartial`,e)}get ontoolresult(){return this.getEventHandler(`toolresult`)}set ontoolresult(e){this.setEventHandler(`toolresult`,e)}get ontoolcancelled(){return this.getEventHandler(`toolcancelled`)}set ontoolcancelled(e){this.setEventHandler(`toolcancelled`,e)}get onhostcontextchanged(){return this.getEventHandler(`hostcontextchanged`)}set onhostcontextchanged(e){this.setEventHandler(`hostcontextchanged`,e)}_onteardown;get onteardown(){return this._onteardown}set onteardown(e){this.warnIfRequestHandlerReplaced(`onteardown`,this._onteardown,e),this._onteardown=e,this.replaceRequestHandler(tg,(e,t)=>{if(!this._onteardown)throw Error(`No onteardown handler set`);return this._onteardown(e.params,t)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(e){this.warnIfRequestHandlerReplaced(`oncalltool`,this._oncalltool,e),this._oncalltool=e,this.replaceRequestHandler(Vp,(e,t)=>{if(!this._oncalltool)throw Error(`No oncalltool handler set`);return this._oncalltool(e.params,t)})}_onlisttools;get onlisttools(){return this._onlisttools}set onlisttools(e){this.warnIfRequestHandlerReplaced(`onlisttools`,this._onlisttools,e),this._onlisttools=e,this.replaceRequestHandler(Lp,(e,t)=>{if(!this._onlisttools)throw Error(`No onlisttools handler set`);return this._onlisttools(e.params,t)})}assertCapabilityForMethod(e){if(e===`sampling/createMessage`&&!this._hostCapabilities?.sampling)throw Error(`Host does not support sampling (required for ${e})`)}assertRequestHandlerCapability(e){switch(e){case`tools/call`:case`tools/list`:if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${e})`);return;case`ping`:case`ui/resource-teardown`:return;default:throw Error(`No handler for method ${e} registered`)}}assertNotificationCapability(e){}assertTaskCapability(e){throw Error(`Tasks are not supported in MCP Apps`)}assertTaskHandlerCapability(e){throw Error(`Task handlers are not supported in MCP Apps`)}async callServerTool(e,t){if(this._assertInitialized(`callServerTool`),typeof e==`string`)throw Error(`callServerTool() expects an object as its first argument, but received a string ("${e}"). Did you mean: callServerTool({ name: "${e}", arguments: { ... } })?`);return await this.request({method:`tools/call`,params:e},zp,{onprogress:()=>{},resetTimeoutOnProgress:!0,...t})}async readServerResource(e,t){return this._assertInitialized(`readServerResource`),await this.request({method:`resources/read`,params:e},up,t)}async listServerResources(e,t){return this._assertInitialized(`listServerResources`),await this.request({method:`resources/list`,params:e},ip,t)}async createSamplingMessage(e,t){this._assertInitialized(`createSamplingMessage`);let n=e.tools?im:rm;return await this.request({method:`sampling/createMessage`,params:e},n,t)}sendMessage(e,t){return this._assertInitialized(`sendMessage`),this.request({method:`ui/message`,params:e},qh,t)}sendLog(e){return this.notification({method:`notifications/message`,params:e})}updateModelContext(e,t){return this._assertInitialized(`updateModelContext`),this.request({method:`ui/update-model-context`,params:e},pf,t)}openLink(e,t){return this._assertInitialized(`openLink`),this.request({method:`ui/open-link`,params:e},Gh,t)}sendOpenLink=this.openLink;downloadFile(e,t){return this._assertInitialized(`downloadFile`),this.request({method:`ui/download-file`,params:e},Kh,t)}requestTeardown(e={}){return this.notification({method:`ui/notifications/request-teardown`,params:e})}requestDisplayMode(e,t){return this._assertInitialized(`requestDisplayMode`),this.request({method:`ui/request-display-mode`,params:e},ag,t)}sendSizeChanged(e){return this.notification({method:`ui/notifications/size-changed`,params:e})}setupSizeChangedNotifications(){let e=!1,t=0,n=0,r=()=>{e||(e=!0,requestAnimationFrame(()=>{e=!1;let r=document.documentElement,i=r.style.height;r.style.height=`max-content`;let a=Math.ceil(r.getBoundingClientRect().height);r.style.height=i;let o=Math.ceil(window.innerWidth);(o!==t||a!==n)&&(t=o,n=a,this.sendSizeChanged({width:o,height:a}))}))};r();let i=new ResizeObserver(r);return i.observe(document.documentElement),i.observe(document.body),()=>i.disconnect()}async connect(e=new Bh(window.parent,window.parent),t){if(this.transport)throw Error(`App is already connected. Call close() before connecting again.`);this._initializedSent=!1,await super.connect(e);try{let e=await this.request({method:`ui/initialize`,params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:zh}},ug,t);if(e===void 0)throw Error(`Server sent invalid initialize result: ${e}`);this._hostCapabilities=e.hostCapabilities,this._hostInfo=e.hostInfo,this._hostContext=e.hostContext,await this.notification({method:`ui/notifications/initialized`}),this._initializedSent=!0,this.options?.autoResize&&this.setupSizeChangedNotifications()}catch(e){throw this.close(),e}}}}));function mg(e,t){let n,r=0,i,a=()=>{n!==void 0&&(clearTimeout(n),n=void 0)},o=new fg({name:e,version:`0.0.1`},{}),s=async e=>{let t=await o.request({method:`tools/call`,params:{name:`get_generation`,arguments:{operationId:e}}},zp);if(!t.isError)return t.structuredContent},c=(e,o)=>{n=window.setTimeout(async()=>{if(Date.now()-r>bg){t.onTimeout?.();return}try{let n=await s(e);if(n?.status===`complete`){a(),i=n,t.onResult(n);return}}catch{}c(e,Math.min(o*1.5,yg))},o)},l=e=>{e&&(a(),i=e,t.onResult(e),e.status===`running`&&e.operationId!==void 0&&(r=Date.now(),c(e.operationId,vg)))};return o.ontoolinput=e=>{t.onInput?.(e?.arguments||{}),t.onResult({status:`running`})},o.ontoolresult=e=>{let t=Cg(e?._meta)??hg();l(t??e?.structuredContent),t||gg(e=>l(e))},o.onhostcontextchanged=e=>{if(e?.theme&&Ih(e.theme),e?.styles?.variables&&Lh(e.styles.variables),e?.displayMode&&(document.documentElement.dataset.displayMode=e.displayMode),e?.safeAreaInsets){let{top:t=0,right:n=0,bottom:r=0,left:i=0}=e.safeAreaInsets;document.body.style.padding=`${t}px ${n}px ${r}px ${i}px`}},o.onteardown=async()=>(a(),t.onTeardown?.(),{}),o.connect(new Bh(window.parent,window.parent)).catch(()=>{}),{app:o,current:()=>i}}function hg(){let e=xg()?.toolResponseMetadata;if(!(!e||typeof e!=`object`))return Cg(e)??Cg(e.mcp_tool_result?._meta)??Cg(e.call_tool_result?._meta)}function gg(e){if(!xg())return;let t=()=>window.removeEventListener(`openai:set_globals`,n),n=()=>{let n=hg();n!==void 0&&(t(),e(n))};window.addEventListener(`openai:set_globals`,n),setTimeout(t,wg)}var _g,vg,yg,bg,xg,Sg,Cg,wg,Tg=t((()=>{pg(),Pm(),_g=e=>document.getElementById(e),vg=2e3,yg=1e4,bg=36e4,xg=()=>window.openai,Sg=`openai-mcp/card`,Cg=e=>e&&typeof e==`object`?e[Sg]:void 0,wg=1e4}));n((()=>{Tg();var e=e=>`$${e.toFixed(2)}`;function t(e){let t=e.toLowerCase();return t.includes(`pending`)||t.includes(`review`)||t.includes(`action`)?`wait`:t.includes(`printing`)||t.includes(`processing`)||t.includes(`way`)||t.includes(`returning`)?`move`:t.includes(`delivered`)?`done`:t.includes(`canceled`)?`stop`:``}function n(n){let r=document.createElement(`div`);r.className=`order`;let i=document.createElement(`div`);i.className=`order-head`;let a=document.createElement(`div`);a.className=`order-id`,a.textContent=`Order #${n.orderId}`;let o=document.createElement(`span`);o.className=`chip ${t(n.status)}`.trim(),o.textContent=n.status,i.append(a,o),r.append(i);let s=document.createElement(`div`);s.className=`lines`,(n.items||[]).forEach(e=>{let t=document.createElement(`div`);t.textContent=`${e.quantity}x ${e.title} (${e.materialName})`,s.append(t)}),r.append(s);let c=document.createElement(`div`);c.className=`total-row`;let l=document.createElement(`span`);l.textContent=n.discount>0?`Total (after ${e(n.discount)} discount)`:`Total`;let u=document.createElement(`b`);if(u.textContent=e(n.totalCost),c.append(l,u),r.append(c),(n.tracking||[]).forEach(e=>{let t=document.createElement(`div`);t.className=`tracking`,t.textContent=`Tracking: ${e.carrier?`${e.carrier} `:``}${e.trackingNumber}`,r.append(t)}),n.actionRequired){let t=document.createElement(`div`);t.className=`action`,t.textContent=`Action required: the measured piece costs ${e(n.actionRequired.amount)} more than quoted. Approve the adjustment on womp.com under Profile -> Orders to unblock production.`,r.append(t)}return r}function r(e){let t=e.orders??(e.orderId?[e]:[]),r=_g(`orders`);r.textContent=``,t.forEach(e=>r.append(n(e))),_g(`empty`).hidden=t.length>0,_g(`status`).textContent=``}mg(`Womp orders`,{onResult:e=>{let t=e;if(t.status===`running`){_g(`status`).textContent=`Loading…`;return}r(t)}})}))();</script>
179
179
  </head>
180
180
  <body>
181
181
  <div class="card" id="card">