@vivix-labs/studio-chat-mcp 0.1.14 → 0.1.15

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.
@@ -16,6 +16,9 @@
16
16
  color: var(--color-text-primary, CanvasText);
17
17
  background: var(--color-background-primary, Canvas);
18
18
  }
19
+ :root[data-video-gallery] {
20
+ scrollbar-width: none;
21
+ }
19
22
  #summary {
20
23
  margin: 0 0 8px;
21
24
  white-space: pre-wrap;
@@ -151,8 +154,8 @@ Boolean requesting whether a visible border and background is provided by the ho
151
154
  - "model": Tool visible to and callable by the agent
152
155
  - "app": Tool callable by the app from this server only`),csp:h.never().optional(),permissions:h.never().optional()}),mU=h.object({mimeTypes:h.array(h.string()).optional().describe('Array of supported MIME types for UI resources.\nMust include `"text/html;profile=mcp-app"` for MCP Apps support.')}),pU=h.object({method:h.literal("ui/download-file"),params:h.object({contents:h.array(h.union([En,Cn])).describe("Resource contents to download \u2014 embedded (inline data) or linked (host fetches). Uses standard MCP resource types.")})}),fU=h.object({method:h.literal("ui/message"),params:h.object({role:h.literal("user").describe('Message role, currently only "user" is supported.'),content:h.array(Xt).describe("Message content blocks (text, image, etc.).")})}),hU=h.object({method:h.literal("ui/notifications/sandbox-resource-ready"),params:h.object({html:h.string().describe("HTML content to load into the inner iframe."),sandbox:h.string().optional().describe("Optional override for the inner iframe's sandbox attribute."),csp:Qv.optional().describe("CSP configuration from resource metadata."),permissions:e_.optional().describe("Sandbox permissions from resource metadata.")})}),XE=h.object({method:h.literal("ui/notifications/tool-result"),params:Zr.describe("Standard MCP tool execution result.")}),Iz=h.object({toolInfo:h.object({id:Tt.optional().describe("JSON-RPC id of the tools/call request."),tool:Vr.describe("Tool definition including name, inputSchema, etc.")}).optional().describe("Metadata of the tool call that instantiated this App."),theme:jE.optional().describe("Current color theme preference."),styles:HE.optional().describe("Style configuration for theming the app."),displayMode:Vc.optional().describe("How the UI is currently displayed."),availableDisplayModes:h.array(Vc).optional().describe("Display modes the host supports."),containerDimensions:h.union([h.object({height:h.number().describe("Fixed container height in pixels.")}),h.object({maxHeight:h.union([h.number(),h.undefined()]).optional().describe("Maximum container height in pixels.")})]).and(h.union([h.object({width:h.number().describe("Fixed container width in pixels.")}),h.object({maxWidth:h.union([h.number(),h.undefined()]).optional().describe("Maximum container width in pixels.")})])).optional().describe(`Container dimensions. Represents the dimensions of the iframe or other
153
156
  container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:h.string().optional().describe("User's language and region preference in BCP 47 format."),timeZone:h.string().optional().describe("User's timezone in IANA format."),userAgent:h.string().optional().describe("Host application identifier."),platform:h.union([h.literal("web"),h.literal("desktop"),h.literal("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:h.object({touch:h.boolean().optional().describe("Whether the device supports touch input."),hover:h.boolean().optional().describe("Whether the device supports hover interactions.")}).optional().describe("Device input capabilities."),safeAreaInsets:h.object({top:h.number().describe("Top safe area inset in pixels."),right:h.number().describe("Right safe area inset in pixels."),bottom:h.number().describe("Bottom safe area inset in pixels."),left:h.number().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough(),QE=h.object({method:h.literal("ui/notifications/host-context-changed"),params:Iz.describe("Partial context update containing only changed fields.")}),gU=h.object({method:h.literal("ui/update-model-context"),params:h.object({content:h.array(Xt).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:h.record(h.string(),h.unknown().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})}),vU=h.object({method:h.literal("ui/initialize"),params:h.object({appInfo:Wt.describe("App identification (name and version)."),appCapabilities:GE.describe("Features and capabilities this app provides."),protocolVersion:h.string().describe("Protocol version this app supports.")})}),eC=h.object({protocolVersion:h.string().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:Wt.describe("Host application identification and version."),hostCapabilities:KE.describe("Features and capabilities provided by the host."),hostContext:Iz.describe("Rich context about the host environment.")}).passthrough(),tC={target:"draft-2020-12"};async function kz(e,t){let n=e["~standard"];if(n.jsonSchema)return n.jsonSchema[t](tC);throw Error(`Schema (vendor: ${n.vendor}) does not implement Standard JSON Schema (~standard.jsonSchema). Use a library that does (zod v4, ArkType, Valibot) or wrap your schema accordingly.`)}async function xz(e,t,n=""){let o=await e["~standard"].validate(t);if(o.issues){let r=o.issues.map(i=>{let a=i.path?.map(s=>typeof s=="object"?s.key:s).join(".");return a?`${a}: ${i.message}`:i.message}).join("; ");throw Error(n+r)}return o.value}function rC(e,t){let n={...e,...t};return t.experimental!==void 0&&(n.experimental={...e.experimental,...t.experimental}),t.tools!==void 0&&(n.tools={...e.tools,...t.tools}),n}var Qd=class e extends Lc{_appInfo;_appCapabilities;options;_hostCapabilities;_hostInfo;_hostContext;_registeredTools={};_initializedSent=!1;_registeredEvents=new Set;_events=new Wv;_methods=new Yv;setRequestHandler=(...t)=>{let[n,...o]=zz("request",t)??t;this._methods.claim(n,"setRequestHandler"),super.setRequestHandler.call(this,n,...o)};setNotificationHandler=(...t)=>{let[n,...o]=zz("notification",t)??t;this._methods.claim(n,"setNotificationHandler"),super.setNotificationHandler.call(this,n,...o)};removeRequestHandler=t=>{this._methods.release(t),super.removeRequestHandler(t)};removeNotificationHandler=t=>{this._methods.release(t),super.removeNotificationHandler(t)};replaceRequestHandler=(t,...n)=>{this._methods.replace(t),super.setRequestHandler.call(this,t,...n)};_assertInitialized(t){if(this._initializedSent)return;let n=`[ext-apps] App.${t}() 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(n);console.warn(`${n}. This will throw in a future release.`)}eventSchemas={toolinput:qE,toolinputpartial:VE,toolresult:XE,toolcancelled:ZE,hostcontextchanged:QE};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(t,n){n&&this._assertHandlerTiming(t),this._ensureEventSlot(t),this._events.setHandler(t,n)}addEventListener(t,n){this._assertHandlerTiming(t),this._ensureEventSlot(t),this._events.addEventListener(t,n)}removeEventListener(t,n){this._events.removeEventListener(t,n)}_ensureEventSlot(t){if(this._registeredEvents.has(t))return;let n=this.eventSchemas[t];if(!n)throw Error(`Unknown event: ${String(t)}`);this.setNotificationHandler(n.shape.method.value,{params:n.shape.params},o=>{let r=o;t==="hostcontextchanged"&&(this._hostContext={...this._hostContext,...r}),this._events.dispatch(t,r)}),this._registeredEvents.add(t)}getEventHandler(t){return this._events.getHandler(t)}warnIfRequestHandlerReplaced(t,n,o){n&&o&&console.warn(`[MCP Apps] ${t} handler replaced. Previous handler will no longer be called.`)}constructor(t,n={},o={autoResize:!0}){super(o),this._appInfo=t,this._appCapabilities=n,this.options=o,this._methods.replace("notifications/cancelled"),this._methods.replace("notifications/progress"),!o.allowUnsafeEval&&h.config({jitless:!0}),this.replaceRequestHandler("ping",r=>(console.log("Received ping:",r.params),{})),this.setEventHandler("hostcontextchanged",void 0)}buildContext(t){return t}registerAppCapabilities(t){if(this.transport)throw Error("Cannot register capabilities after transport is established");this._appCapabilities=rC(this._appCapabilities,t)}registerTool(t,n,o){if(this._registeredTools[t])throw Error(`Tool ${t} is already registered`);let r=this,i=()=>{r._initializedSent&&r._appCapabilities.tools?.listChanged&&r.sendToolListChanged()},a=n.inputSchema!==void 0,s={title:n.title,description:n.description,inputSchema:n.inputSchema,outputSchema:n.outputSchema,annotations:n.annotations,_meta:n._meta,enabled:!0,enable(){this.enabled=!0,i()},disable(){this.enabled=!1,i()},update(c){Object.assign(this,c),i()},remove(){r._registeredTools[t]===s&&(delete r._registeredTools[t],i())},handler:async(c,u)=>{if(!s.enabled)throw Error(`Tool ${t} is disabled`);let d;if(a){let m=s.inputSchema,p=m?await xz(m,c??{},`Invalid input for tool ${t}: `):c??{};d=await o(p,u)}else d=await o(u);return s.outputSchema&&!d.isError&&(d.structuredContent=await xz(s.outputSchema,d.structuredContent,`Invalid output for tool ${t}: `)),d}};return this._registeredTools[t]=s,!this._appCapabilities.tools&&!this.transport&&this.registerAppCapabilities({tools:{listChanged:!0}}),this.ensureToolHandlersInitialized(),i(),s}_toolHandlersInitialized=!1;ensureToolHandlersInitialized(){this._toolHandlersInitialized||(this._toolHandlersInitialized=!0,this.oncalltool=async(t,n)=>{let o=this._registeredTools[t.name];if(!o)throw Error(`Tool ${t.name} not found`);return o.handler(t.arguments,n)},this.onlisttools=async(t,n)=>({tools:await Promise.all(Object.entries(this._registeredTools).filter(([o,r])=>r.enabled).map(async([o,r])=>{let i={name:o,title:r.title,description:r.description,inputSchema:r.inputSchema?await kz(r.inputSchema,"input"):{type:"object",properties:{}}};return r.outputSchema&&(i.outputSchema=await kz(r.outputSchema,"output")),r.annotations&&(i.annotations=r.annotations),r._meta&&(i._meta=r._meta),i}))}))}async sendToolListChanged(t={}){this._assertInitialized("sendToolListChanged"),await this.notification({method:"notifications/tools/list_changed",params:t})}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}get ontoolinput(){return this.getEventHandler("toolinput")}set ontoolinput(t){this.setEventHandler("toolinput",t)}get ontoolinputpartial(){return this.getEventHandler("toolinputpartial")}set ontoolinputpartial(t){this.setEventHandler("toolinputpartial",t)}get ontoolresult(){return this.getEventHandler("toolresult")}set ontoolresult(t){this.setEventHandler("toolresult",t)}get ontoolcancelled(){return this.getEventHandler("toolcancelled")}set ontoolcancelled(t){this.setEventHandler("toolcancelled",t)}get onhostcontextchanged(){return this.getEventHandler("hostcontextchanged")}set onhostcontextchanged(t){this.setEventHandler("hostcontextchanged",t)}_onteardown;get onteardown(){return this._onteardown}set onteardown(t){this.warnIfRequestHandlerReplaced("onteardown",this._onteardown,t),this._onteardown=t,this.replaceRequestHandler("ui/resource-teardown",{params:JE.shape.params,result:BE},(n,o)=>{if(!this._onteardown)throw Error("No onteardown handler set");return this._onteardown(n,o)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(t){this.warnIfRequestHandlerReplaced("oncalltool",this._oncalltool,t),this._oncalltool=t,this.replaceRequestHandler("tools/call",(n,o)=>{if(!this._oncalltool)throw Error("No oncalltool handler set");return this._oncalltool(n.params,o)})}_onlisttools;get onlisttools(){return this._onlisttools}set onlisttools(t){this.warnIfRequestHandlerReplaced("onlisttools",this._onlisttools,t),this._onlisttools=t,this.replaceRequestHandler("tools/list",(n,o)=>{if(!this._onlisttools)throw Error("No onlisttools handler set");return this._onlisttools(n.params,o)})}assertCapabilityForMethod(t){switch(t){case"sampling/createMessage":if(!this._hostCapabilities?.sampling)throw Error(`Host does not support sampling (required for ${t})`);break}}assertRequestHandlerCapability(t){switch(t){case"tools/call":case"tools/list":if(!this._appCapabilities.tools)throw Error(`Client does not support tool capability (required for ${t})`);return;default:return}}assertNotificationCapability(t){}async callServerTool(t,n){if(this._assertInitialized("callServerTool"),typeof t=="string")throw Error(`callServerTool() expects an object as its first argument, but received a string ("${t}"). Did you mean: callServerTool({ name: "${t}", arguments: { ... } })?`);return await this.request({method:"tools/call",params:t},{onprogress:()=>{},resetTimeoutOnProgress:!0,...n})}async readServerResource(t,n){return this._assertInitialized("readServerResource"),await this.request({method:"resources/read",params:t},n)}async listServerResources(t,n){return this._assertInitialized("listServerResources"),await this.request({method:"resources/list",params:t},n)}async createSamplingMessage(t,n){return this._assertInitialized("createSamplingMessage"),await this.request({method:"sampling/createMessage",params:t},n)}sendMessage(t,n){return this._assertInitialized("sendMessage"),this.request({method:"ui/message",params:t},LE,n)}sendLog(t){return this.notification({method:"notifications/message",params:t})}updateModelContext(t,n){return this._assertInitialized("updateModelContext"),this.request({method:"ui/update-model-context",params:t},Lr,n)}openLink(t,n){return this._assertInitialized("openLink"),this.request({method:"ui/open-link",params:t},DE,n)}sendOpenLink=this.openLink;downloadFile(t,n){return this._assertInitialized("downloadFile"),this.request({method:"ui/download-file",params:t},ME,n)}requestTeardown(t={}){return this.notification({method:"ui/notifications/request-teardown",params:t})}requestDisplayMode(t,n){return this._assertInitialized("requestDisplayMode"),this.request({method:"ui/request-display-mode",params:t},WE,n)}sendSizeChanged(t){return this.notification({method:"ui/notifications/size-changed",params:t})}setupSizeChangedNotifications(){let t=!1,n=0,o=0,r=()=>{t||(t=!0,requestAnimationFrame(()=>{t=!1;let a=document.documentElement,s=a.style.height;a.style.height="max-content";let c=Math.ceil(a.getBoundingClientRect().height);a.style.height=s;let u=Math.ceil(window.innerWidth);(u!==n||c!==o)&&(n=u,o=c,this.sendSizeChanged({width:u,height:c}))}))};r();let i=new ResizeObserver(r);return i.observe(document.documentElement),i.observe(document.body),()=>i.disconnect()}async connect(t=new Xv(window.parent,window.parent),n){if(this.transport)throw Error("App is already connected. Call close() before connecting again.");this._initializedSent=!1;try{await super.connect(t);let o=await this.request({method:"ui/initialize",params:{appCapabilities:this._appCapabilities,appInfo:this._appInfo,protocolVersion:OE}},eC,n);if(o===void 0)throw Error(`Server sent invalid initialize result: ${o}`);this._hostCapabilities=o.hostCapabilities,this._hostInfo=o.hostInfo,this._hostContext=o.hostContext,await this.notification({method:"ui/notifications/initialized"}),this._initializedSent=!0,this.options?.autoResize&&this.setupSizeChangedNotifications()}catch(o){throw this.close(),o}}};var r_="studio.chat.component.v1";function se(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function Zc(e){return{content:e.content,structuredContent:se(e.structuredContent)?e.structuredContent:void 0,_meta:e._meta,isError:e.isError===!0}}function Rz(e){let t=e.content;if(e.isError||e.structuredContent||e._meta?.["studio/view"]||t?.length!==1)return e;let n=t[0]?.text;if(t[0]?.type!=="text"||!n?.startsWith('{"content":')||!n.includes('"studio/view"'))return e;try{let o=JSON.parse(n);if(se(o)&&Array.isArray(o.content)&&se(o.structuredContent)&&se(o._meta)){let r=o._meta["studio/view"];if(se(r)&&se(r.ui)){let i={content:o.content,structuredContent:o.structuredContent,_meta:{"studio/view":{...r,ui:{format:r.ui.format,sha256:r.ui.sha256}}}};if(n_(i))return i}}}catch{}return{isError:!0,content:[{type:"text",text:"The saved Studio card could not be read."}]}}function Pz(e){let t=e.structuredContent,n=t&&{...t,bindings:t.bindings??$t(e).bindings};if(!(!n||n.protocolVersion!==1||!se(n.bindings)||Object.entries(n.bindings).some(([o,r])=>!/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(o)||typeof r!="string"||!r)||typeof n.component!="string"||!/^[a-zA-Z0-9._/-]+@[1-9]\d*$/.test(n.component)||typeof n.projectId!="string"||!n.projectId||n.scope!==void 0&&(!se(n.scope)||!["user","project"].includes(String(n.scope.kind))||n.scope.id!==n.projectId||n.scope.kind==="user"&&n.scope.id!=="user")||!se(n.target)||typeof n.target.instanceId!="string"||!n.target.instanceId||typeof n.target.operationId!="string"||!n.target.operationId))return{component:n.component,bindings:n.bindings,projectId:n.projectId,...n.scope!==void 0&&{scope:n.scope},target:{instanceId:n.target.instanceId,operationId:n.target.operationId}}}function t_(e,t){return se(e)&&Object.keys(e).length===Object.keys(t).length&&Object.entries(t).every(([n,o])=>e[n]===o)}function $t(e){let t=e._meta?.["studio/view"];return se(t)?t:{}}function Tz(e,t,n){let o=$t(e),r=new URL(t);if(r.protocol!=="https:"||r.username||r.password||!Array.isArray(o.mediaOrigins)||!o.mediaOrigins.includes(r.origin))throw Error("This media source is not available for download.");let i=a=>Array.isArray(a)?a.some(i):se(a)?Object.entries(a).some(([s,c])=>(s==="src"||s==="downloadUrl")&&c===t||i(c)):!1;if(!i(o.props))throw Error("This media is not part of the current card.");return{type:"resource_link",uri:t,name:n.replace(/[\\/:*?"<>|\x00-\x1f]/g,"_").slice(0,200)||"Media"}}function n_(e){let t=$t(e),n=Pz(e),o=t.ui;if(!(!n||t.protocolVersion!==1||t.component!==n.component||!t_(t.bindings,n.bindings)||t.projectId!==n.projectId||n.scope!==void 0&&(!se(t.scope)||t.scope.kind!==n.scope.kind||t.scope.id!==n.scope.id)||!se(t.target)||t.target.instanceId!==n.target.instanceId||t.target.operationId!==n.target.operationId||!se(t.props)||!se(o)||o.format!=="iife"||o.javascript!==void 0&&(typeof o.javascript!="string"||!o.javascript.trim())||typeof o.sha256!="string"||!/^[a-f0-9]{64}$/.test(o.sha256)))return{id:n.component,...typeof o.javascript=="string"&&{javascript:o.javascript},sha256:o.sha256}}async function nC(e){if(!e.javascript)return!1;let t=new TextEncoder().encode(e.javascript),n=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(n),r=>r.toString(16).padStart(2,"0")).join("")===e.sha256}async function Ez(e,t,n){let o=se(e)&&Array.isArray(e.contents)?e.contents.find(a=>se(a)&&a.uri===t&&a.mimeType==="text/javascript"):void 0,r=se(o?._meta)?o._meta["studio/component"]:void 0;if(!se(o)||typeof o.text!="string"||!se(r)||r.id!==n||r.format!=="iife"||typeof r.sha256!="string"||!/^[a-f0-9]{64}$/.test(r.sha256))throw new Error("The compatible Studio card renderer is invalid.");let i={id:n,javascript:o.text,sha256:r.sha256};if(!await nC(i))throw new Error("The Studio card script failed verification.");return i}function Cz(e){let t=e.scope??{kind:"project",id:e.projectId};return"studio://chat-bundles/"+[t.kind,t.id,e.target.instanceId,e.target.operationId,"components",e.component].map(encodeURIComponent).join("/")}function Un(e){return(e.content??[]).filter(t=>t.type==="text"&&typeof t.text=="string").map(t=>t.text).join(`
154
- `)}function tm(e){let{ui:t,...n}=$t(e);return{text:Un(e),structuredContent:e.structuredContent,view:n,isError:e.isError===!0}}function fo(e,t){return!e||typeof e!="object"?!1:se(e)&&["image","audio","video"].includes(String(e.kind))&&e.path===t?!0:Object.values(e).some(n=>fo(n,t))}var em=class{constructor(t,n){this.callTool=t;this.sendMessage=n}callTool;sendMessage;result={};identity;pending=!1;lastRequest;receive(t){let n=Pz(t);if(this.identity){let o=t.structuredContent??{};if(o.scope!==void 0){let s=this.identity.scope??{kind:"project",id:this.identity.projectId};if(!se(o.scope)||o.scope.kind!==s.kind||o.scope.id!==s.id)throw new Error("The reply changed the card scope. Reopen the original card.")}for(let s of["projectId","component"])if(o[s]!==void 0&&o[s]!==this.identity[s])throw new Error("The reply belongs to another card. Reopen the original card.");if(o.target!==void 0&&(!se(o.target)||o.target.instanceId!==this.identity.target.instanceId||o.target.operationId!==this.identity.target.operationId))throw new Error("The reply changed the source operation. Reopen the original card.");if(o.bindings!==void 0&&!t_(o.bindings,this.identity.bindings)||n!==void 0&&!t_(n.bindings,this.identity.bindings))throw new Error("The reply changed the action bindings. Reopen the original card.");let r=this.result,{error:i,...a}=r.structuredContent??{};this.result={...r,...t,isError:t.isError===!0,structuredContent:{...a,...o},_meta:{...r._meta,...t._meta,"studio/view":{...$t(r),...$t(t)}}}}else this.result=t,this.identity=n}async action(t,n={},o={}){if(!this.identity)throw new Error("Reopen the operation before using this card.");if(this.pending)throw new Error("Wait for the current card action to finish.");if(!/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(t))throw new Error("Invalid card action.");if(!Object.hasOwn(this.identity.bindings,t))throw new Error("This card does not declare that action.");if(Object.keys(o).some(i=>!["requestKey","approval"].includes(i)))throw new Error("Invalid card invocation options.");let r={...this.identity.scope?.kind==="user"?{scope:this.identity.scope}:{projectId:this.identity.projectId},target:this.identity.target,binding:this.identity.bindings[t],action:t,input:n,requestKey:o.requestKey??`card:${crypto.randomUUID()}`,...o.approval===void 0?{}:{approval:o.approval}};this.lastRequest=r,this.pending=!0;try{let i=await this.callTool({name:"studio_card_action",arguments:r}),a=i._meta?.["studio/message"],{["studio/message"]:s,...c}=i._meta??{},u={...i,_meta:c};if(this.receive(u),a!==void 0&&!i.isError){if(!se(a)||typeof a.intent!="string"||!a.intent.trim()||!se(a.data))throw Error("The adapter returned an invalid prepared message. Your draft is retained.");let d=this.sendMessage?await this.sendMessage(r.requestKey,{intent:a.intent,data:a.data}):{status:"failed",message:"This chat client does not support follow-up messages. Your draft is retained."},m=d.status==="sent",p={...u,content:[{type:"text",text:m?"Sent to this conversation. Business changes are not yet confirmed.":d.message}],isError:!m,structuredContent:{...u.structuredContent,...m?{}:{error:{code:d.status==="unknown"?"PROMPT_MESSAGE_UNKNOWN":"PROMPT_MESSAGE_FAILED"}}}};return this.receive(p),p}return u}finally{this.pending=!1}}};function Oz(e,t){let n=t.mediaOrigins??[];if(!Array.isArray(n)||n.some(i=>{if(typeof i!="string")return!0;try{let a=new URL(i);return a.protocol!=="https:"||a.origin!==i||a.hostname.includes("*")||/["';]/.test(i)}catch{return!0}}))throw new Error("The card declared invalid HTTPS media origins.");let o=["data:","blob:",...[...new Set(n)].sort()].join(" ");return`<!doctype html><meta http-equiv="Content-Security-Policy" content="${`default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; font-src data:; img-src ${o}; media-src ${o}; connect-src 'none'; frame-src 'none'; object-src 'none'; base-uri 'none'; form-action 'none'`}"><meta name="referrer" content="no-referrer"><meta name="color-scheme" content="light dark"><div id="root"></div><script>${e.replace(/<\/script/gi,"<\\/script")}<\/script>`}function Nz(){let e="studio.chat.component.v1",t=new Map,n,o=0,r=!1,i,a,s=p=>p==="light"||p==="dark"?p:void 0,c=p=>parent.postMessage({channel:e,...p},"*"),u=(p,f={},g={})=>new Promise((_,z)=>{let E=String(++o);t.set(E,{resolve:_,reject:z}),c({type:"action",id:E,action:p,input:f,options:g})}),d=p=>({data:p.view.props,projectId:p.view.projectId,target:p.view.target,...i&&{theme:i},action:u,...r&&{download:f=>new Promise((g,_)=>{let z=String(++o);t.set(z,{resolve:()=>g(),reject:_}),c({type:"download",id:z,uri:f.uri,name:f.name})})},readMedia:f=>new Promise((g,_)=>{let z=String(++o);t.set(z,{resolve:g,reject:_}),c({type:"read-media",id:z,input:f})})});window.addEventListener("message",p=>{if(p.source!==parent||p.data?.channel!==e)return;let f=p.data;try{if(f.type==="initialize"&&!n){r=f.downloadsAvailable===!0,i=s(f.theme),a=f.result;let g=document.createElement("script");g.textContent=f.javascript,document.head.append(g);let _=globalThis,z=_.StudioComponent??_.StudioChatCard;if(typeof z?.mount!="function")throw new Error("The registered card has no mount export.");if(n=z.mount(document.querySelector("#root"),d(f.result)),!n||typeof n.update!="function"||typeof n.dispose!="function")throw new Error("The registered card returned an invalid mount.")}else if(f.type==="result"&&n)a=f.result,n.update(d(f.result));else if(f.type==="theme-change"&&n&&a){let g=s(f.theme);g!==i&&(i=g,n.update(d(a)))}else f.type==="action-result"||f.type==="download-result"?(t.get(f.id)?.resolve(f.result),t.delete(f.id)):f.type==="media-result"?(t.get(f.id)?.resolve(f.value),t.delete(f.id)):f.type==="media-error"?(t.get(f.id)?.reject(new Error(f.message)),t.delete(f.id)):(f.type==="action-error"||f.type==="download-error")&&(t.get(f.id)?.reject(Object.assign(new Error(f.error.message),f.error)),t.delete(f.id))}catch(g){c({type:"component-error",message:g instanceof Error?g.message:"Card failed."})}}),window.addEventListener("error",()=>c({type:"component-error",message:"The registered card could not render."})),window.addEventListener("unhandledrejection",()=>c({type:"component-error",message:"The registered card could not update."})),document.addEventListener("securitypolicyviolation",p=>{if(!["media-src","img-src"].includes(p.effectiveDirective))return;let f="the media source";try{f=new URL(p.blockedURI).origin}catch{}c({type:"component-error",message:`This chat blocked ${f} (${p.effectiveDirective}). Refreshing the URL alone will not change its resource policy.`})});let m=document.body;new ResizeObserver(()=>{let{marginTop:p,marginBottom:f}=getComputedStyle(m),g=m.getBoundingClientRect().height+parseFloat(p)+parseFloat(f);c({type:"resize",height:Math.ceil(g)})}).observe(m),window.addEventListener("pagehide",()=>n?.dispose()),c({type:"ready"})}async function jz(e,t,n,o){if(!fo($t(e).props,t))throw Error("This file is not declared by the original card.");let r=0,i=1,a="",s="",c;for(;r<i;){let m=await o({path:t,offset:r,...c&&{expected:c}});if(!m||!Number.isSafeInteger(m.totalBytes)||m.totalBytes<=0||m.totalBytes>2147483648||!Number.isSafeInteger(m.nextOffset)||m.nextOffset<=r||m.nextOffset>m.totalBytes||!m.snapshot||m.snapshot.sizeBytes!==m.totalBytes||!/^(?:audio\/|video\/|image\/(?:png|jpeg|webp)$)/.test(m.mimeType)||c&&(m.totalBytes!==i||m.mimeType!==a||JSON.stringify(m.snapshot)!==JSON.stringify(c)))throw Error("The media reply is incomplete or the file changed during download.");let p=atob(m.base64);if(p.length!==m.nextOffset-r)throw Error("The media download chunk is incomplete.");s+=p,r=m.nextOffset,i=m.totalBytes,a=m.mimeType,c=m.snapshot}let u=t.match(/\.[a-z0-9]{1,10}$/i)?.[0]??"",d=Array.from(n.replace(/[\\/:*?"<>|\x00-\x1f]/g,"_")).slice(0,180).join("").replace(/[\ud800-\udfff]/gu,"\uFFFD")||"Media";return u&&!d.toLowerCase().endsWith(u.toLowerCase())&&(d+=u),{type:"resource",resource:{uri:`file:///${encodeURIComponent(d)}`,mimeType:a,blob:btoa(s)}}}var Ge=new Qd({name:"Vivix Studio card",version:"1.0.0"},{},{strict:!0,autoResize:!0}),iC=new cu(Ge),Me=new em(async e=>Zc(await Ge.callServerTool(e)),(e,t)=>iC.send(e,t)),go=document.querySelector("#summary"),ho=document.querySelector("#status"),oC=document.querySelector("#card"),$e,Fc,rm,Az,zt=!1,vr,Uz,i_=0;function _r(e){$e?.contentWindow?.postMessage({channel:r_,...e},"*")}function Hc(e){let t=e instanceof Error?e.message:"Studio could not update this card.",n=Me.lastRequest?.requestKey??Uz;ho.textContent=`${t}${n?`
155
- Request key: ${String(n)}`:""}`}function Dz(){let e=Ge.getHostContext()?.theme;return e==="light"||e==="dark"?e:void 0}Ge.addEventListener("hostcontextchanged",()=>{zt&&_r({type:"theme-change",theme:Dz()})});async function Mz(){let e=++i_,t=Me.result,n=Un(t);go.textContent=n,go.hidden=!n,ho.textContent=t.isError?Un(t)||"Studio rejected the card action.":"";let o=n_(t);if(!Me.identity||!o){vr&&clearTimeout(vr),$e?.remove(),$e=void 0,Fc=void 0,rm=void 0,zt=!1,t.isError||(ho.textContent="The registered card could not load. Reopen the original operation.");return}let r=Oz(`(${Nz.toString()})();`,$t(t)),i=Cz(Me.identity);if($e&&rm===i&&Az===r){go.hidden=!n||zt&&!t.isError,zt&&_r({type:"result",result:tm(t)});return}let a;try{let s=await Ge.readServerResource({uri:i});a=(await Ez(s,i,Me.identity.component)).javascript}catch{if(e!==i_)return;ho.textContent="A compatible Studio card renderer could not be loaded or verified. Reopen the card.",$e?.remove(),$e=void 0,Fc=void 0,rm=void 0,zt=!1;return}e===i_&&(vr&&clearTimeout(vr),$e?.remove(),zt=!1,Fc=a,rm=i,Az=r,$e=document.createElement("iframe"),$e.id="component",$e.title="Studio card",$e.setAttribute("sandbox","allow-scripts"),$e.setAttribute("referrerpolicy","no-referrer"),$e.srcdoc=r,oC.replaceChildren($e),vr=setTimeout(()=>{zt||(ho.textContent="The card did not initialize. Reopen the original operation.")},1e4))}async function aC(e,t,n,o){try{let i=await Me.action(e,t,n);await Mz(),o&&_r({type:"action-result",id:o,result:tm(i)})}catch(r){Hc(r),o&&_r({type:"action-error",id:o,error:{code:"CARD_ACTION_FAILED",message:r instanceof Error?r.message:"Card action failed.",requestKey:Me.lastRequest?.requestKey}})}}async function sC(e,t,n){try{if(!Ge.getHostCapabilities()?.downloadFile)throw Error("Downloads are unavailable in this chat.");let o=fo($t(Me.result).props,e)?await jz(Me.result,e,t,async i=>{let a=await Ge.callServerTool({name:"read_local_media",arguments:{...i}});if(a.isError)throw Error(Un(Zc(a))||"Local media could not be read.");return a._meta?.["studio/media"]}):Tz(Me.result,e,t);if((await Ge.downloadFile({contents:[o]})).isError)throw Error("The download was declined by this chat.");_r({type:"download-result",id:n})}catch(o){_r({type:"download-error",id:n,error:{message:o instanceof Error?o.message:"Download failed."}})}}window.addEventListener("message",e=>{if(!$e||e.source!==$e.contentWindow||!se(e.data))return;let t=e.data;if(t.channel===r_)if(t.type==="ready"){zt=!0,vr&&clearTimeout(vr);let n=Un(Me.result);go.hidden=!Me.result.isError||!n,ho.textContent=Me.result.isError?n:"",Fc&&_r({type:"initialize",javascript:Fc,result:tm(Me.result),downloadsAvailable:!!Ge.getHostCapabilities()?.downloadFile,theme:Dz()})}else if(t.type==="component-error"&&typeof t.message=="string")Hc(new Error(t.message));else if(zt&&t.type==="resize"&&typeof t.height=="number"&&Number.isFinite(t.height))$e.style.height=`${Math.max(120,Math.min(2e3,t.height))}px`;else if(zt&&t.type==="download"&&typeof t.id=="string"&&t.id.length>0&&typeof t.uri=="string"&&typeof t.name=="string")sC(t.uri,t.name,t.id);else if(zt&&t.type==="read-media"&&typeof t.id=="string"&&se(t.input)){let n=$e,o=t.input;(async()=>{try{if(typeof o.path!="string"||!fo($t(Me.result).props,o.path))throw Error("This media path does not belong to the original card.");let r=await Ge.callServerTool({name:"read_local_media",arguments:o});if(r.isError)throw Error(Un(Zc(r))||"Local media could not be read.");let i=r._meta?.["studio/media"];if(!se(i))throw Error("The local media reply is incomplete.");$e===n&&_r({type:"media-result",id:t.id,value:i})}catch(r){$e===n&&_r({type:"media-error",id:t.id,message:r instanceof Error?r.message:"Local media could not be read."})}})()}else zt&&t.type==="action"&&typeof t.id=="string"&&t.id.length>0&&typeof t.action=="string"&&(t.input===void 0||se(t.input))&&(t.options===void 0||se(t.options))&&aC(t.action,t.input??{},t.options??{},t.id)});Ge.ontoolinput=({arguments:e})=>{Uz=typeof e?.requestKey=="string"?e.requestKey:void 0};Ge.ontoolresult=async e=>{try{Me.receive(Rz(Zc(e))),await Mz()}catch(t){Hc(t)}};Ge.ontoolcancelled=()=>{Hc(new Error("The tool was cancelled. Recover with the original request to check whether it was accepted."))};Ge.onteardown=async()=>(vr&&clearTimeout(vr),$e?.remove(),{});Ge.connect().catch(e=>{go.textContent="Studio could not connect to this chat.",go.hidden=!1,Hc(e)});})();
157
+ `)}function tm(e){let{ui:t,...n}=$t(e);return{text:Un(e),structuredContent:e.structuredContent,view:n,isError:e.isError===!0}}function fo(e,t){return!e||typeof e!="object"?!1:se(e)&&["image","audio","video"].includes(String(e.kind))&&e.path===t?!0:Object.values(e).some(n=>fo(n,t))}var em=class{constructor(t,n){this.callTool=t;this.sendMessage=n}callTool;sendMessage;result={};identity;pending=!1;lastRequest;receive(t){let n=Pz(t);if(this.identity){let o=t.structuredContent??{};if(o.scope!==void 0){let s=this.identity.scope??{kind:"project",id:this.identity.projectId};if(!se(o.scope)||o.scope.kind!==s.kind||o.scope.id!==s.id)throw new Error("The reply changed the card scope. Reopen the original card.")}for(let s of["projectId","component"])if(o[s]!==void 0&&o[s]!==this.identity[s])throw new Error("The reply belongs to another card. Reopen the original card.");if(o.target!==void 0&&(!se(o.target)||o.target.instanceId!==this.identity.target.instanceId||o.target.operationId!==this.identity.target.operationId))throw new Error("The reply changed the source operation. Reopen the original card.");if(o.bindings!==void 0&&!t_(o.bindings,this.identity.bindings)||n!==void 0&&!t_(n.bindings,this.identity.bindings))throw new Error("The reply changed the action bindings. Reopen the original card.");let r=this.result,{error:i,...a}=r.structuredContent??{};this.result={...r,...t,isError:t.isError===!0,structuredContent:{...a,...o},_meta:{...r._meta,...t._meta,"studio/view":{...$t(r),...$t(t)}}}}else this.result=t,this.identity=n}async action(t,n={},o={}){if(!this.identity)throw new Error("Reopen the operation before using this card.");if(this.pending)throw new Error("Wait for the current card action to finish.");if(!/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(t))throw new Error("Invalid card action.");if(!Object.hasOwn(this.identity.bindings,t))throw new Error("This card does not declare that action.");if(Object.keys(o).some(i=>!["requestKey","approval"].includes(i)))throw new Error("Invalid card invocation options.");let r={...this.identity.scope?.kind==="user"?{scope:this.identity.scope}:{projectId:this.identity.projectId},target:this.identity.target,binding:this.identity.bindings[t],action:t,input:n,requestKey:o.requestKey??`card:${crypto.randomUUID()}`,...o.approval===void 0?{}:{approval:o.approval}};this.lastRequest=r,this.pending=!0;try{let i=await this.callTool({name:"studio_card_action",arguments:r}),a=i._meta?.["studio/message"],{["studio/message"]:s,...c}=i._meta??{},u={...i,_meta:c};if(this.receive(u),a!==void 0&&!i.isError){if(!se(a)||typeof a.intent!="string"||!a.intent.trim()||!se(a.data))throw Error("The adapter returned an invalid prepared message. Your draft is retained.");let d=this.sendMessage?await this.sendMessage(r.requestKey,{intent:a.intent,data:a.data}):{status:"failed",message:"This chat client does not support follow-up messages. Your draft is retained."},m=d.status==="sent",p={...u,content:[{type:"text",text:m?"Sent to this conversation. Business changes are not yet confirmed.":d.message}],isError:!m,structuredContent:{...u.structuredContent,...m?{}:{error:{code:d.status==="unknown"?"PROMPT_MESSAGE_UNKNOWN":"PROMPT_MESSAGE_FAILED"}}}};return this.receive(p),p}return u}finally{this.pending=!1}}};function Oz(e,t,n=!1){let o=t.mediaOrigins??[];if(!Array.isArray(o)||o.some(s=>{if(typeof s!="string")return!0;try{let c=new URL(s);return c.protocol!=="https:"||c.origin!==s||c.hostname.includes("*")||/["';]/.test(s)}catch{return!0}}))throw new Error("The card declared invalid HTTPS media origins.");let r=["data:","blob:",...[...new Set(o)].sort()].join(" ");return`<!doctype html><meta http-equiv="Content-Security-Policy" content="${`default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; font-src data:; img-src ${r}; media-src ${r}; connect-src 'none'; frame-src 'none'; object-src 'none'; base-uri 'none'; form-action 'none'`}"><meta name="referrer" content="no-referrer"><meta name="color-scheme" content="light dark">${n?"<style>html{scrollbar-width:none}body{margin-block:0}</style>":""}<div id="root"></div><script>${e.replace(/<\/script/gi,"<\\/script")}<\/script>`}function Nz(){let e="studio.chat.component.v1",t=new Map,n,o=0,r=!1,i,a,s=p=>p==="light"||p==="dark"?p:void 0,c=p=>parent.postMessage({channel:e,...p},"*"),u=(p,f={},g={})=>new Promise((_,z)=>{let E=String(++o);t.set(E,{resolve:_,reject:z}),c({type:"action",id:E,action:p,input:f,options:g})}),d=p=>({data:p.view.props,projectId:p.view.projectId,target:p.view.target,...i&&{theme:i},action:u,...r&&{download:f=>new Promise((g,_)=>{let z=String(++o);t.set(z,{resolve:()=>g(),reject:_}),c({type:"download",id:z,uri:f.uri,name:f.name})})},readMedia:f=>new Promise((g,_)=>{let z=String(++o);t.set(z,{resolve:g,reject:_}),c({type:"read-media",id:z,input:f})})});window.addEventListener("message",p=>{if(p.source!==parent||p.data?.channel!==e)return;let f=p.data;try{if(f.type==="initialize"&&!n){r=f.downloadsAvailable===!0,i=s(f.theme),a=f.result;let g=document.createElement("script");g.textContent=f.javascript,document.head.append(g);let _=globalThis,z=_.StudioComponent??_.StudioChatCard;if(typeof z?.mount!="function")throw new Error("The registered card has no mount export.");if(n=z.mount(document.querySelector("#root"),d(f.result)),!n||typeof n.update!="function"||typeof n.dispose!="function")throw new Error("The registered card returned an invalid mount.")}else if(f.type==="result"&&n)a=f.result,n.update(d(f.result));else if(f.type==="theme-change"&&n&&a){let g=s(f.theme);g!==i&&(i=g,n.update(d(a)))}else f.type==="action-result"||f.type==="download-result"?(t.get(f.id)?.resolve(f.result),t.delete(f.id)):f.type==="media-result"?(t.get(f.id)?.resolve(f.value),t.delete(f.id)):f.type==="media-error"?(t.get(f.id)?.reject(new Error(f.message)),t.delete(f.id)):(f.type==="action-error"||f.type==="download-error")&&(t.get(f.id)?.reject(Object.assign(new Error(f.error.message),f.error)),t.delete(f.id))}catch(g){c({type:"component-error",message:g instanceof Error?g.message:"Card failed."})}}),window.addEventListener("error",()=>c({type:"component-error",message:"The registered card could not render."})),window.addEventListener("unhandledrejection",()=>c({type:"component-error",message:"The registered card could not update."})),document.addEventListener("securitypolicyviolation",p=>{if(!["media-src","img-src"].includes(p.effectiveDirective))return;let f="the media source";try{f=new URL(p.blockedURI).origin}catch{}c({type:"component-error",message:`This chat blocked ${f} (${p.effectiveDirective}). Refreshing the URL alone will not change its resource policy.`})});let m=document.body;new ResizeObserver(()=>{let{marginTop:p,marginBottom:f}=getComputedStyle(m),g=m.getBoundingClientRect().height+parseFloat(p)+parseFloat(f);c({type:"resize",height:Math.ceil(g)})}).observe(m),window.addEventListener("pagehide",()=>n?.dispose()),c({type:"ready"})}async function jz(e,t,n,o){if(!fo($t(e).props,t))throw Error("This file is not declared by the original card.");let r=0,i=1,a="",s="",c;for(;r<i;){let m=await o({path:t,offset:r,...c&&{expected:c}});if(!m||!Number.isSafeInteger(m.totalBytes)||m.totalBytes<=0||m.totalBytes>2147483648||!Number.isSafeInteger(m.nextOffset)||m.nextOffset<=r||m.nextOffset>m.totalBytes||!m.snapshot||m.snapshot.sizeBytes!==m.totalBytes||!/^(?:audio\/|video\/|image\/(?:png|jpeg|webp)$)/.test(m.mimeType)||c&&(m.totalBytes!==i||m.mimeType!==a||JSON.stringify(m.snapshot)!==JSON.stringify(c)))throw Error("The media reply is incomplete or the file changed during download.");let p=atob(m.base64);if(p.length!==m.nextOffset-r)throw Error("The media download chunk is incomplete.");s+=p,r=m.nextOffset,i=m.totalBytes,a=m.mimeType,c=m.snapshot}let u=t.match(/\.[a-z0-9]{1,10}$/i)?.[0]??"",d=Array.from(n.replace(/[\\/:*?"<>|\x00-\x1f]/g,"_")).slice(0,180).join("").replace(/[\ud800-\udfff]/gu,"\uFFFD")||"Media";return u&&!d.toLowerCase().endsWith(u.toLowerCase())&&(d+=u),{type:"resource",resource:{uri:`file:///${encodeURIComponent(d)}`,mimeType:a,blob:btoa(s)}}}var Ge=new Qd({name:"Vivix Studio card",version:"1.0.0"},{},{strict:!0,autoResize:!0}),iC=new cu(Ge),Me=new em(async e=>Zc(await Ge.callServerTool(e)),(e,t)=>iC.send(e,t)),go=document.querySelector("#summary"),ho=document.querySelector("#status"),oC=document.querySelector("#card"),$e,Fc,rm,Az,zt=!1,vr,Uz,i_=0;function _r(e){$e?.contentWindow?.postMessage({channel:r_,...e},"*")}function Hc(e){let t=e instanceof Error?e.message:"Studio could not update this card.",n=Me.lastRequest?.requestKey??Uz;ho.textContent=`${t}${n?`
158
+ Request key: ${String(n)}`:""}`}function Dz(){let e=Ge.getHostContext()?.theme;return e==="light"||e==="dark"?e:void 0}Ge.addEventListener("hostcontextchanged",()=>{zt&&_r({type:"theme-change",theme:Dz()})});async function Mz(){let e=++i_,t=Me.result,n=Un(t);go.textContent=n,go.hidden=!n,ho.textContent=t.isError?Un(t)||"Studio rejected the card action.":"";let o=n_(t),r=!!o&&t.structuredContent?.componentId==="video-gallery@1";if(document.documentElement.toggleAttribute("data-video-gallery",r),!Me.identity||!o){vr&&clearTimeout(vr),$e?.remove(),$e=void 0,Fc=void 0,rm=void 0,zt=!1,t.isError||(ho.textContent="The registered card could not load. Reopen the original operation.");return}let i=Oz(`(${Nz.toString()})();`,$t(t),r),a=Cz(Me.identity);if($e&&rm===a&&Az===i){go.hidden=!n||zt&&!t.isError,zt&&_r({type:"result",result:tm(t)});return}let s;try{let c=await Ge.readServerResource({uri:a});s=(await Ez(c,a,Me.identity.component)).javascript}catch{if(e!==i_)return;ho.textContent="A compatible Studio card renderer could not be loaded or verified. Reopen the card.",$e?.remove(),$e=void 0,Fc=void 0,rm=void 0,zt=!1;return}e===i_&&(vr&&clearTimeout(vr),$e?.remove(),zt=!1,Fc=s,rm=a,Az=i,$e=document.createElement("iframe"),$e.id="component",$e.title="Studio card",$e.setAttribute("sandbox","allow-scripts"),$e.setAttribute("referrerpolicy","no-referrer"),$e.srcdoc=i,oC.replaceChildren($e),vr=setTimeout(()=>{zt||(ho.textContent="The card did not initialize. Reopen the original operation.")},1e4))}async function aC(e,t,n,o){try{let i=await Me.action(e,t,n);await Mz(),o&&_r({type:"action-result",id:o,result:tm(i)})}catch(r){Hc(r),o&&_r({type:"action-error",id:o,error:{code:"CARD_ACTION_FAILED",message:r instanceof Error?r.message:"Card action failed.",requestKey:Me.lastRequest?.requestKey}})}}async function sC(e,t,n){try{if(!Ge.getHostCapabilities()?.downloadFile)throw Error("Downloads are unavailable in this chat.");let o=fo($t(Me.result).props,e)?await jz(Me.result,e,t,async i=>{let a=await Ge.callServerTool({name:"read_local_media",arguments:{...i}});if(a.isError)throw Error(Un(Zc(a))||"Local media could not be read.");return a._meta?.["studio/media"]}):Tz(Me.result,e,t);if((await Ge.downloadFile({contents:[o]})).isError)throw Error("The download was declined by this chat.");_r({type:"download-result",id:n})}catch(o){_r({type:"download-error",id:n,error:{message:o instanceof Error?o.message:"Download failed."}})}}window.addEventListener("message",e=>{if(!$e||e.source!==$e.contentWindow||!se(e.data))return;let t=e.data;if(t.channel===r_)if(t.type==="ready"){zt=!0,vr&&clearTimeout(vr);let n=Un(Me.result);go.hidden=!Me.result.isError||!n,ho.textContent=Me.result.isError?n:"",Fc&&_r({type:"initialize",javascript:Fc,result:tm(Me.result),downloadsAvailable:!!Ge.getHostCapabilities()?.downloadFile,theme:Dz()})}else if(t.type==="component-error"&&typeof t.message=="string")Hc(new Error(t.message));else if(zt&&t.type==="resize"&&typeof t.height=="number"&&Number.isFinite(t.height))$e.style.height=`${Math.max(120,Math.min(2e3,t.height))}px`;else if(zt&&t.type==="download"&&typeof t.id=="string"&&t.id.length>0&&typeof t.uri=="string"&&typeof t.name=="string")sC(t.uri,t.name,t.id);else if(zt&&t.type==="read-media"&&typeof t.id=="string"&&se(t.input)){let n=$e,o=t.input;(async()=>{try{if(typeof o.path!="string"||!fo($t(Me.result).props,o.path))throw Error("This media path does not belong to the original card.");let r=await Ge.callServerTool({name:"read_local_media",arguments:o});if(r.isError)throw Error(Un(Zc(r))||"Local media could not be read.");let i=r._meta?.["studio/media"];if(!se(i))throw Error("The local media reply is incomplete.");$e===n&&_r({type:"media-result",id:t.id,value:i})}catch(r){$e===n&&_r({type:"media-error",id:t.id,message:r instanceof Error?r.message:"Local media could not be read."})}})()}else zt&&t.type==="action"&&typeof t.id=="string"&&t.id.length>0&&typeof t.action=="string"&&(t.input===void 0||se(t.input))&&(t.options===void 0||se(t.options))&&aC(t.action,t.input??{},t.options??{},t.id)});Ge.ontoolinput=({arguments:e})=>{Uz=typeof e?.requestKey=="string"?e.requestKey:void 0};Ge.ontoolresult=async e=>{try{Me.receive(Rz(Zc(e))),await Mz()}catch(t){Hc(t)}};Ge.ontoolcancelled=()=>{Hc(new Error("The tool was cancelled. Recover with the original request to check whether it was accepted."))};Ge.onteardown=async()=>(vr&&clearTimeout(vr),$e?.remove(),{});Ge.connect().catch(e=>{go.textContent="Studio could not connect to this chat.",go.hidden=!1,Hc(e)});})();
156
159
  /*! Bundled license information:
157
160
 
158
161
  @modelcontextprotocol/client/dist/src-CeKsbNLO.mjs:
package/dist/server.js CHANGED
@@ -29429,7 +29429,7 @@ data:
29429
29429
  // package.json
29430
29430
  var package_default = {
29431
29431
  name: "@vivix-labs/studio-chat-mcp",
29432
- version: "0.1.14",
29432
+ version: "0.1.15",
29433
29433
  type: "module",
29434
29434
  engines: {
29435
29435
  node: ">=22.12.0"
@@ -38485,7 +38485,7 @@ async function resolveChatMedia(host, scope, ref, fileId) {
38485
38485
  }
38486
38486
 
38487
38487
  // src/chat-server.ts
38488
- var chatResourceUri = "ui://studio/chat/v12.html";
38488
+ var chatResourceUri = "ui://studio/chat/v13.html";
38489
38489
  var historicalChatResourceUris = [
38490
38490
  "ui://studio/chat/v1.html",
38491
38491
  "ui://studio/chat/v2.html",
@@ -38497,7 +38497,8 @@ var historicalChatResourceUris = [
38497
38497
  "ui://studio/chat/v8.html",
38498
38498
  "ui://studio/chat/v9.html",
38499
38499
  "ui://studio/chat/v10.html",
38500
- "ui://studio/chat/v11.html"
38500
+ "ui://studio/chat/v11.html",
38501
+ "ui://studio/chat/v12.html"
38501
38502
  ];
38502
38503
  var chatMimeType = "text/html;profile=mcp-app";
38503
38504
  var defaultResourceDomains = ["https://static.vivi-x.ai"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vivix-labs/studio-chat-mcp",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=22.12.0"