Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Keep every desktop import working through re-exports, and move the app frame's JSON-RPC types into the package
milind-sonidd12afb29063
diff --git a/packages/phone-protocol/src/app-rpc.ts b/packages/phone-protocol/src/app-rpc.tsnew file mode 100644index 0000000000..3d447f8743--- /dev/null+++ b/packages/phone-protocol/src/app-rpc.ts@@ -0,0 +1,22 @@+// JSON-RPC between an MCP app frame and its host (io.modelcontextprotocol/ui, stable 2026-01-26).+export type JsonRpcId = string | number;++export interface JsonRpcError {+ code: number;+ message: string;+ data?: unknown;+}++export type JsonRpcMessage =+ | { jsonrpc: "2.0"; id: JsonRpcId; method: string; params?: Record<string, unknown> }+ | { jsonrpc: "2.0"; method: string; params?: Record<string, unknown> }+ | { jsonrpc: "2.0"; id: JsonRpcId; result: unknown }+ | { jsonrpc: "2.0"; id: JsonRpcId; error: JsonRpcError };++/** The only methods an app frame may ask its server for; the server refuses any other with 400. */+export const APP_RPC_METHODS = ["tools/call", "tools/list", "resources/read", "resources/list"] as const;+export type AppRpcMethod = (typeof APP_RPC_METHODS)[number];++export const RPC_METHOD_NOT_FOUND = -32601;+export const RPC_INVALID_PARAMS = -32602;+export const RPC_HOST_REFUSED = -32000;diff --git a/scripts/sync-phone-protocol.test.mjs b/scripts/sync-phone-protocol.test.mjsindex 1bb881d69a..e0f68acf8c 100644--- a/scripts/sync-phone-protocol.test.mjs+++ b/scripts/sync-phone-protocol.test.mjs@@ -44,7 +44,9 @@ describe("sync-phone-protocol", () => {expect(readFileSync(join(out, "SOURCE"), "utf8")).toBe(`${head}\n`);const sources = git("ls-tree", "-r", "--name-only", "HEAD", "--", "packages/phone-protocol/src").split("\n").filter((path) => !path.endsWith(".test.ts"));- expect(sources).toContain("packages/phone-protocol/src/wire.ts");+ for (const name of ["wire", "app-rpc", "cursor-face-data", "failed-turn", "mention-boundary", "upload-limits"]) {+ expect(sources).toContain(`packages/phone-protocol/src/${name}.ts`);+ }expect(Object.keys(tree(out)).sort()).toEqual(["SOURCE", "app-host.html", "package.json", "vectors/v1.json",...sources.map((path) => path.slice("packages/phone-protocol/".length)),diff --git a/shared/app-frame/app-host.html b/shared/app-frame/app-host.htmlindex e1da33244c..62abfe266c 100644--- a/shared/app-frame/app-host.html+++ b/shared/app-frame/app-host.html@@ -1,10 +1,10 @@-<!-- mausbot app-host v1 sha256:6bc90d3b2061859f31f678bb4f9d6fb8c6de71428c81319d44b5a4f45817759c -->+<!-- mausbot app-host v1 sha256:77ffbb379886c92991db4d92d8638215c54818cef02c9a6993c5dcd454808068 --><!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"><meta name="color-scheme" content="light dark"><title>App</title><style>html,body{margin:0;padding:0;background:transparent;overflow:hidden}iframe{display:block;width:100%;border:0;background:transparent}</style></head><body>-<script id="mausbot-app-host">(()=>{var E="2026-01-26";var S={htmlBytes:262144,title:80,fallback:1500,fallbackExcerpt:600,heightMin:80,heightMax:720,messageText:4e3,contextText:4e3,doneText:300,mcpHtmlBytes:2097152,rpcArgumentsBytes:65536,rpcResourceBytes:8388608,messagesPerHour:20,rpcPerMinute:60};var T="In a room, pages, apps and widgets are view-only: they cannot send messages or tell a bot what anyone sees.";function B(e){let n=0;for(let s=0;s<e.length;s+=1){let c=e.charCodeAt(s);if(c<128)n+=1;else if(c<2048)n+=2;else if(c>=55296&&c<=56319&&s+1<e.length){let a=e.charCodeAt(s+1);a>=56320&&a<=57343?(n+=4,s+=1):n+=3}else n+=3}return n}var K=["tools/call","tools/list","resources/read","resources/list"],D=-32601,I=-32602,y=-32e3,d={messageBytes:1e6,minHeight:48,defaultHeight:160,maxHeight:720,linkChars:2048,teardownMs:1e3,engagedTouchMs:1e4,contextCoalesceMs:1e3,logsPerMinute:50,rates:{message:[[3e3,1],[6e5,10]],openLink:[[2e3,1]],rpc:[[1e4,10],[6e5,120]]}};function X(e){let n=J(e);return{...e.can.openLinks?{openLinks:{}}:{},logging:{},...e.can.modelContext?{updateModelContext:{text:{},structuredContent:{}}}:{},...e.can.message?{message:{text:{}}}:{},...n&&e.can.serverTools?{serverTools:{}}:{},...n&&e.can.serverResources?{serverResources:{}}:{},sandbox:{permissions:{},csp:{connectDomains:[...e.network.connect],resourceDomains:[...e.network.resources]}}}}function J(e){return!!e.tool}function H(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function $(e){return typeof e=="string"&&e.length<=200||typeof e=="number"&&Number.isFinite(e)}function Z(e){let n;try{n=JSON.stringify(e)}catch{return null}return n===void 0?null:n.length*3<=d.messageBytes?n.length:B(n)}function Q(e){if(!H(e)||e.jsonrpc!=="2.0")return null;let n=Z(e);return n===null||n>d.messageBytes||e.params!==void 0&&!H(e.params)?null:typeof e.method=="string"?!e.method||e.method.length>200||"id"in e&&!$(e.id)?null:e:e.method!==void 0||!$(e.id)?null:"result"in e||H(e.error)&&typeof e.error.code=="number"&&typeof e.error.message=="string"?e:null}function _(e,n){let s=[],c=Math.max(...e.map(([a])=>a));return{take(){let a=n();for(;s.length&&a-s[0]>=c;)s.shift();for(let[f,u]of e)if(s.filter(w=>a-w<f).length>=u)return!1;return s.push(a),!0}}}function L(e){return H(e)&&typeof e.code=="number"&&Number.isInteger(e.code)?{code:e.code,message:typeof e.message=="string"&&e.message?e.message:"The host refused this."}:{code:y,message:e instanceof Error&&e.message?e.message:"The host could not do that."}}function ee(e){if(typeof e!="string"||!e||e.length>d.linkChars)return null;let n;try{n=new URL(e)}catch{return null}return n.protocol!=="http:"&&n.protocol!=="https:"||n.username||n.password?null:n.href.length<=d.linkChars?n.href:null}function te(e){if(!e||e.role!=="user"||!Array.isArray(e.content)||e.content.length===0)return null;let n=[];for(let c of e.content){if(!H(c)||c.type!=="text"||typeof c.text!="string")return null;n.push(c.text)}let s=n.join(`-`).trim();return s&&s.length<=S.messageText?s:null}function F(e){let{doc:n,adapter:s}=e,c=J(n),a=e.timers??{set:(t,l)=>setTimeout(t,l),clear:t=>clearTimeout(t)},f=()=>s.now(),u={...e.hostContext,...c&&n.tool?{toolInfo:{tool:n.tool}}:{}},w=null,C=!1,h=!1,x=!1,M=!1,P=0,v=new Map,k={message:_(d.rates.message,f),openLink:_(d.rates.openLink,f),rpc:_(d.rates.rpc,f),log:_([[6e4,d.logsPerMinute]],f)},b=null,r=null,p=-1/0,g=t=>{if(!x)try{s.post(t)}catch{}},A=(t,l)=>g({jsonrpc:"2.0",id:t,result:l}),i=(t,l,o)=>g({jsonrpc:"2.0",id:t,error:{code:l,message:o}}),j=()=>{let t=e.limits?.maxHeight,l=u.containerDimensions?.maxHeight,o=typeof t=="number"&&t>0?t:typeof l=="number"&&l>0?l:d.maxHeight;return Math.max(d.minHeight,o)},O=()=>{if(r=null,x||!b)return;let t=b;b=null,p=f(),Promise.resolve().then(()=>s.setContext(t)).catch(()=>{})},V=async()=>{if(r===null||!b)return;a.clear(r),r=null;let t=b;b=null,p=f();try{await s.setContext(t)}catch{}},q=()=>{if(c&&!M&&(M=!0,g({jsonrpc:"2.0",method:"ui/notifications/tool-input",params:{arguments:n.toolInput??{}}}),g({jsonrpc:"2.0",method:"ui/notifications/tool-result",params:n.toolResult??{content:[]}})),w){let t=w;w=null,g({jsonrpc:"2.0",method:"ui/notifications/host-context-changed",params:t})}},W=async(t,l,o)=>{if(!c)return i(t,D,"Method not found");if(!(l.startsWith("tools/")?n.can.serverTools:n.can.serverResources))return i(t,y,n.room?T:n.blocked?.text??"This app cannot reach its server right now.");if(l==="tools/call"&&(typeof o.name!="string"||!o.name||o.arguments!==void 0&&!H(o.arguments)))return i(t,I,"tools/call needs {name, arguments?}.");if(l==="resources/read"&&typeof o.uri!="string")return i(t,I,"resources/read needs {uri}.");if(!k.rpc.take())return i(t,y,"Too many calls from this app. Wait a moment.");try{let R=await s.callRpc(l,o);A(t,R??{})}catch(R){let N=L(R);i(t,N.code,N.message)}},Y=async(t,l,o)=>{if(l==="ui/initialize")return C=!0,A(t,{protocolVersion:E,hostInfo:{name:"mausbot",version:e.hostVersion},hostCapabilities:X(n),hostContext:u});if(h)switch(l){case"ping":return A(t,{});case"ui/request-display-mode":return A(t,{mode:"inline"});case"ui/open-link":{if(!n.can.openLinks)return i(t,y,"This app cannot open links here.");if(!s.engaged())return i(t,y,"Links open only after the person clicks in the app.");let m=ee(o?.url);if(!m)return i(t,I,"Only http and https links of at most 2,048 characters, without a user name or password, can be opened.");if(!k.openLink.take())return i(t,y,"Too many links from this app. Wait a moment.");try{return await s.openLink(m),A(t,{})}catch(R){return i(t,y,L(R).message)}}case"ui/message":{if(!n.can.message)return i(t,y,n.room?T:"This app cannot send messages here.");if(!s.engaged())return i(t,y,"Messages are sent only after the person clicks in the app.");let m=te(o);if(m===null)return i(t,I,`Only text messages of 1 to ${S.messageText} characters can be sent.`);if(!k.message.take())return i(t,y,"Too many messages from this app. Wait a moment.");try{return await V(),await s.sendMessage(m),A(t,{})}catch(R){return i(t,y,L(R).message)}}case"ui/update-model-context":{if(!n.can.modelContext)return i(t,y,n.room?T:"This app cannot update the model's context here.");if(o?.content!==void 0&&!Array.isArray(o.content)||o?.structuredContent!==void 0&&!H(o.structuredContent))return i(t,I,"ui/update-model-context takes {content?, structuredContent?}.");if(b={...Array.isArray(o?.content)?{content:o.content}:{},...H(o?.structuredContent)?{structuredContent:o.structuredContent}:{}},r===null){let m=p+d.contextCoalesceMs-f();m<=0?O():r=a.set(O,m)}return A(t,{})}default:return K.includes(l)?W(t,l,o??{}):i(t,D,"Method not found")}},G=(t,l)=>{if(t==="ui/notifications/initialized"){if(!C||h)return;h=!0,q();return}if(h)switch(t){case"ui/notifications/size-changed":{let o=l?.height;if(typeof o!="number"||!Number.isFinite(o))return;s.resize(Math.round(Math.min(j(),Math.max(d.minHeight,o))));return}case"notifications/message":e.log&&k.log.take()&&e.log(l);return;case"ui/notifications/request-teardown":s.teardownRequested();return;default:}};return{get initialized(){return h},handleMessage(t){if(x)return;let l=e.source();if(l==null||t.source!==l)return;let o=Q(t.data);if(!o)return;if("method"in o){"id"in o?Y(o.id,o.method,o.params):G(o.method,o.params);return}let m=v.get(o.id);m&&(v.delete(o.id),m(o))},contextChanged(t){x||(u={...u,...t},h?g({jsonrpc:"2.0",method:"ui/notifications/host-context-changed",params:t}):C&&(w={...w,...t}))},teardown(){return x||!h?Promise.resolve():new Promise(t=>{let l=`host:${++P}`,o=!1,m=()=>{o||(o=!0,v.delete(l),a.clear(R),t())},R=a.set(m,d.teardownMs);v.set(l,m),g({jsonrpc:"2.0",id:l,method:"ui/resource-teardown",params:{}})})},dispose(){x=!0,r!==null&&a.clear(r),r=null;for(let t of v.values())t({jsonrpc:"2.0",id:"",result:{}});v.clear()}}}var z=1;function ne(e){let s=e.webkit?.messageHandlers?.appHost;if(s&&typeof s.postMessage=="function")return{send:a=>s.postMessage(a)};let c=e.appHost;return c&&typeof c.postMessage=="function"?{send:a=>c.postMessage(JSON.stringify(a)),listen:a=>{c.onmessage=f=>{if(typeof f.data!="string")return;let u;try{u=JSON.parse(f.data)}catch{return}u&&typeof u=="object"&&u.v===z&&a(u)}}}:null}function re(e,n){let s=n??ne(e);if(!s)return null;let c=e.document,a=null,f=null,u=0,w=!1,C=0,h=new Map,x=r=>{try{s.send(r)}catch{}},M=(r,p)=>new Promise((g,A)=>{let i=`c${++C}`;h.set(i,{resolve:g,reject:A}),x({v:1,type:"call",callId:i,op:r,params:p})}),P=()=>{for(let r of h.values())r.reject({code:-32e3,message:"This app was closed."});h.clear()};e.addEventListener("message",r=>{a&&(a.handleMessage({source:r.source,data:r.data}),!w&&a.initialized&&(w=!0,x({v:1,type:"initialized"})))});let v=()=>{a?.dispose(),a=null,f?.remove(),f=null,w=!1,P()},k={load(r){if(!r||r.v!==z||!r.doc||typeof r.doc.srcdoc!="string")return;v(),typeof r.engagedAt=="number"&&(u=r.engagedAt);let p=c.createElement("iframe");p.setAttribute("sandbox","allow-scripts allow-forms"),p.setAttribute("referrerpolicy","no-referrer"),p.setAttribute("title","App");let g=Math.max(d.minHeight,Math.round(r.limits?.height??d.defaultHeight));p.style.height=`${g}px`,a=F({doc:r.doc,hostContext:r.hostContext??{},hostVersion:r.hostVersion??"phone",...r.limits?.maxHeight?{limits:{maxHeight:r.limits.maxHeight}}:{},source:()=>p.contentWindow,adapter:{post:i=>p.contentWindow?.postMessage(i,"*"),callRpc:(i,j)=>M("rpc",{method:i,params:j}),sendMessage:async i=>{await M("message",{text:i})},openLink:async i=>{await M("open-link",{url:i})},setContext:async i=>{await M("context",{...i})},resize:i=>{p.style.height=`${i}px`,x({v:1,type:"size",height:i})},engaged:()=>Date.now()-u<=d.engagedTouchMs,teardownRequested:()=>x({v:1,type:"teardown-request"}),now:()=>Date.now()}}),f=p,p.srcdoc=r.doc.srcdoc,c.body.appendChild(p)},contextChanged(r){a?.contextChanged(r??{})},engaged(r){typeof r=="number"&&Number.isFinite(r)&&(u=Math.max(u,r))},async teardown(){a&&await a.teardown(),v(),x({v:1,type:"torn-down"})},reply(r,p){let g=h.get(r);g&&(h.delete(r),p&&"error"in p&&p.error?g.reject(p.error):g.resolve(p&&"result"in p?p.result:void 0))}};s.listen?.(r=>{switch(r.call){case"load":return k.load(r.args[0]);case"contextChanged":return k.contextChanged(r.args[0]);case"engaged":return k.engaged(r.args[0]);case"teardown":return void k.teardown();case"reply":return k.reply(r.args[0],r.args[1])}});let b=e;return b.appHost&&typeof b.appHost.postMessage=="function"||(b.appHost=k),b.mausbotAppHost=k,x({v:1,type:"ready"}),k}function U(){typeof window<"u"&&re(window)}U();})();</script>+<script id="mausbot-app-host">(()=>{var N="2026-01-26";var j={htmlBytes:262144,title:80,fallback:1500,fallbackExcerpt:600,heightMin:80,heightMax:720,messageText:4e3,contextText:4e3,doneText:300,mcpHtmlBytes:2097152,rpcArgumentsBytes:65536,rpcResourceBytes:8388608,messagesPerHour:20,rpcPerMinute:60};var _="In a room, pages, apps and widgets are view-only: they cannot send messages or tell a bot what anyone sees.";function D(e){let n=0;for(let s=0;s<e.length;s+=1){let c=e.charCodeAt(s);if(c<128)n+=1;else if(c<2048)n+=2;else if(c>=55296&&c<=56319&&s+1<e.length){let a=e.charCodeAt(s+1);a>=56320&&a<=57343?(n+=4,s+=1):n+=3}else n+=3}return n}var B=["tools/call","tools/list","resources/read","resources/list"];var d={messageBytes:1e6,minHeight:48,defaultHeight:160,maxHeight:720,linkChars:2048,teardownMs:1e3,engagedTouchMs:1e4,contextCoalesceMs:1e3,logsPerMinute:50,rates:{message:[[3e3,1],[6e5,10]],openLink:[[2e3,1]],rpc:[[1e4,10],[6e5,120]]}};function X(e){let n=F(e);return{...e.can.openLinks?{openLinks:{}}:{},logging:{},...e.can.modelContext?{updateModelContext:{text:{},structuredContent:{}}}:{},...e.can.message?{message:{text:{}}}:{},...n&&e.can.serverTools?{serverTools:{}}:{},...n&&e.can.serverResources?{serverResources:{}}:{},sandbox:{permissions:{},csp:{connectDomains:[...e.network.connect],resourceDomains:[...e.network.resources]}}}}function F(e){return!!e.tool}function M(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function $(e){return typeof e=="string"&&e.length<=200||typeof e=="number"&&Number.isFinite(e)}function Z(e){let n;try{n=JSON.stringify(e)}catch{return null}return n===void 0?null:n.length*3<=d.messageBytes?n.length:D(n)}function Q(e){if(!M(e)||e.jsonrpc!=="2.0")return null;let n=Z(e);return n===null||n>d.messageBytes||e.params!==void 0&&!M(e.params)?null:typeof e.method=="string"?!e.method||e.method.length>200||"id"in e&&!$(e.id)?null:e:e.method!==void 0||!$(e.id)?null:"result"in e||M(e.error)&&typeof e.error.code=="number"&&typeof e.error.message=="string"?e:null}function T(e,n){let s=[],c=Math.max(...e.map(([a])=>a));return{take(){let a=n();for(;s.length&&a-s[0]>=c;)s.shift();for(let[f,u]of e)if(s.filter(A=>a-A<f).length>=u)return!1;return s.push(a),!0}}}function O(e){return M(e)&&typeof e.code=="number"&&Number.isInteger(e.code)?{code:e.code,message:typeof e.message=="string"&&e.message?e.message:"The host refused this."}:{code:-32e3,message:e instanceof Error&&e.message?e.message:"The host could not do that."}}function ee(e){if(typeof e!="string"||!e||e.length>d.linkChars)return null;let n;try{n=new URL(e)}catch{return null}return n.protocol!=="http:"&&n.protocol!=="https:"||n.username||n.password?null:n.href.length<=d.linkChars?n.href:null}function te(e){if(!e||e.role!=="user"||!Array.isArray(e.content)||e.content.length===0)return null;let n=[];for(let c of e.content){if(!M(c)||c.type!=="text"||typeof c.text!="string")return null;n.push(c.text)}let s=n.join(`+`).trim();return s&&s.length<=j.messageText?s:null}function z(e){let{doc:n,adapter:s}=e,c=F(n),a=e.timers??{set:(t,l)=>setTimeout(t,l),clear:t=>clearTimeout(t)},f=()=>s.now(),u={...e.hostContext,...c&&n.tool?{toolInfo:{tool:n.tool}}:{}},A=null,C=!1,h=!1,x=!1,H=!1,P=0,R=new Map,k={message:T(d.rates.message,f),openLink:T(d.rates.openLink,f),rpc:T(d.rates.rpc,f),log:T([[6e4,d.logsPerMinute]],f)},b=null,r=null,p=-1/0,g=t=>{if(!x)try{s.post(t)}catch{}},w=(t,l)=>g({jsonrpc:"2.0",id:t,result:l}),i=(t,l,o)=>g({jsonrpc:"2.0",id:t,error:{code:l,message:o}}),S=()=>{let t=e.limits?.maxHeight,l=u.containerDimensions?.maxHeight,o=typeof t=="number"&&t>0?t:typeof l=="number"&&l>0?l:d.maxHeight;return Math.max(d.minHeight,o)},E=()=>{if(r=null,x||!b)return;let t=b;b=null,p=f(),Promise.resolve().then(()=>s.setContext(t)).catch(()=>{})},q=async()=>{if(r===null||!b)return;a.clear(r),r=null;let t=b;b=null,p=f();try{await s.setContext(t)}catch{}},W=()=>{if(c&&!H&&(H=!0,g({jsonrpc:"2.0",method:"ui/notifications/tool-input",params:{arguments:n.toolInput??{}}}),g({jsonrpc:"2.0",method:"ui/notifications/tool-result",params:n.toolResult??{content:[]}})),A){let t=A;A=null,g({jsonrpc:"2.0",method:"ui/notifications/host-context-changed",params:t})}},Y=async(t,l,o)=>{if(!c)return i(t,-32601,"Method not found");if(!(l.startsWith("tools/")?n.can.serverTools:n.can.serverResources))return i(t,-32e3,n.room?_:n.blocked?.text??"This app cannot reach its server right now.");if(l==="tools/call"&&(typeof o.name!="string"||!o.name||o.arguments!==void 0&&!M(o.arguments)))return i(t,-32602,"tools/call needs {name, arguments?}.");if(l==="resources/read"&&typeof o.uri!="string")return i(t,-32602,"resources/read needs {uri}.");if(!k.rpc.take())return i(t,-32e3,"Too many calls from this app. Wait a moment.");try{let v=await s.callRpc(l,o);w(t,v??{})}catch(v){let L=O(v);i(t,L.code,L.message)}},G=async(t,l,o)=>{if(l==="ui/initialize")return C=!0,w(t,{protocolVersion:N,hostInfo:{name:"mausbot",version:e.hostVersion},hostCapabilities:X(n),hostContext:u});if(h)switch(l){case"ping":return w(t,{});case"ui/request-display-mode":return w(t,{mode:"inline"});case"ui/open-link":{if(!n.can.openLinks)return i(t,-32e3,"This app cannot open links here.");if(!s.engaged())return i(t,-32e3,"Links open only after the person clicks in the app.");let m=ee(o?.url);if(!m)return i(t,-32602,"Only http and https links of at most 2,048 characters, without a user name or password, can be opened.");if(!k.openLink.take())return i(t,-32e3,"Too many links from this app. Wait a moment.");try{return await s.openLink(m),w(t,{})}catch(v){return i(t,-32e3,O(v).message)}}case"ui/message":{if(!n.can.message)return i(t,-32e3,n.room?_:"This app cannot send messages here.");if(!s.engaged())return i(t,-32e3,"Messages are sent only after the person clicks in the app.");let m=te(o);if(m===null)return i(t,-32602,`Only text messages of 1 to ${j.messageText} characters can be sent.`);if(!k.message.take())return i(t,-32e3,"Too many messages from this app. Wait a moment.");try{return await q(),await s.sendMessage(m),w(t,{})}catch(v){return i(t,-32e3,O(v).message)}}case"ui/update-model-context":{if(!n.can.modelContext)return i(t,-32e3,n.room?_:"This app cannot update the model's context here.");if(o?.content!==void 0&&!Array.isArray(o.content)||o?.structuredContent!==void 0&&!M(o.structuredContent))return i(t,-32602,"ui/update-model-context takes {content?, structuredContent?}.");if(b={...Array.isArray(o?.content)?{content:o.content}:{},...M(o?.structuredContent)?{structuredContent:o.structuredContent}:{}},r===null){let m=p+d.contextCoalesceMs-f();m<=0?E():r=a.set(E,m)}return w(t,{})}default:return B.includes(l)?Y(t,l,o??{}):i(t,-32601,"Method not found")}},K=(t,l)=>{if(t==="ui/notifications/initialized"){if(!C||h)return;h=!0,W();return}if(h)switch(t){case"ui/notifications/size-changed":{let o=l?.height;if(typeof o!="number"||!Number.isFinite(o))return;s.resize(Math.round(Math.min(S(),Math.max(d.minHeight,o))));return}case"notifications/message":e.log&&k.log.take()&&e.log(l);return;case"ui/notifications/request-teardown":s.teardownRequested();return;default:}};return{get initialized(){return h},handleMessage(t){if(x)return;let l=e.source();if(l==null||t.source!==l)return;let o=Q(t.data);if(!o)return;if("method"in o){"id"in o?G(o.id,o.method,o.params):K(o.method,o.params);return}let m=R.get(o.id);m&&(R.delete(o.id),m(o))},contextChanged(t){x||(u={...u,...t},h?g({jsonrpc:"2.0",method:"ui/notifications/host-context-changed",params:t}):C&&(A={...A,...t}))},teardown(){return x||!h?Promise.resolve():new Promise(t=>{let l=`host:${++P}`,o=!1,m=()=>{o||(o=!0,R.delete(l),a.clear(v),t())},v=a.set(m,d.teardownMs);R.set(l,m),g({jsonrpc:"2.0",id:l,method:"ui/resource-teardown",params:{}})})},dispose(){x=!0,r!==null&&a.clear(r),r=null;for(let t of R.values())t({jsonrpc:"2.0",id:"",result:{}});R.clear()}}}var U=1;function ne(e){let s=e.webkit?.messageHandlers?.appHost;if(s&&typeof s.postMessage=="function")return{send:a=>s.postMessage(a)};let c=e.appHost;return c&&typeof c.postMessage=="function"?{send:a=>c.postMessage(JSON.stringify(a)),listen:a=>{c.onmessage=f=>{if(typeof f.data!="string")return;let u;try{u=JSON.parse(f.data)}catch{return}u&&typeof u=="object"&&u.v===U&&a(u)}}}:null}function re(e,n){let s=n??ne(e);if(!s)return null;let c=e.document,a=null,f=null,u=0,A=!1,C=0,h=new Map,x=r=>{try{s.send(r)}catch{}},H=(r,p)=>new Promise((g,w)=>{let i=`c${++C}`;h.set(i,{resolve:g,reject:w}),x({v:1,type:"call",callId:i,op:r,params:p})}),P=()=>{for(let r of h.values())r.reject({code:-32e3,message:"This app was closed."});h.clear()};e.addEventListener("message",r=>{a&&(a.handleMessage({source:r.source,data:r.data}),!A&&a.initialized&&(A=!0,x({v:1,type:"initialized"})))});let R=()=>{a?.dispose(),a=null,f?.remove(),f=null,A=!1,P()},k={load(r){if(!r||r.v!==U||!r.doc||typeof r.doc.srcdoc!="string")return;R(),typeof r.engagedAt=="number"&&(u=r.engagedAt);let p=c.createElement("iframe");p.setAttribute("sandbox","allow-scripts allow-forms"),p.setAttribute("referrerpolicy","no-referrer"),p.setAttribute("title","App");let g=Math.max(d.minHeight,Math.round(r.limits?.height??d.defaultHeight));p.style.height=`${g}px`,a=z({doc:r.doc,hostContext:r.hostContext??{},hostVersion:r.hostVersion??"phone",...r.limits?.maxHeight?{limits:{maxHeight:r.limits.maxHeight}}:{},source:()=>p.contentWindow,adapter:{post:i=>p.contentWindow?.postMessage(i,"*"),callRpc:(i,S)=>H("rpc",{method:i,params:S}),sendMessage:async i=>{await H("message",{text:i})},openLink:async i=>{await H("open-link",{url:i})},setContext:async i=>{await H("context",{...i})},resize:i=>{p.style.height=`${i}px`,x({v:1,type:"size",height:i})},engaged:()=>Date.now()-u<=d.engagedTouchMs,teardownRequested:()=>x({v:1,type:"teardown-request"}),now:()=>Date.now()}}),f=p,p.srcdoc=r.doc.srcdoc,c.body.appendChild(p)},contextChanged(r){a?.contextChanged(r??{})},engaged(r){typeof r=="number"&&Number.isFinite(r)&&(u=Math.max(u,r))},async teardown(){a&&await a.teardown(),R(),x({v:1,type:"torn-down"})},reply(r,p){let g=h.get(r);g&&(h.delete(r),p&&"error"in p&&p.error?g.reject(p.error):g.resolve(p&&"result"in p?p.result:void 0))}};s.listen?.(r=>{switch(r.call){case"load":return k.load(r.args[0]);case"contextChanged":return k.contextChanged(r.args[0]);case"engaged":return k.engaged(r.args[0]);case"teardown":return void k.teardown();case"reply":return k.reply(r.args[0],r.args[1])}});let b=e;return b.appHost&&typeof b.appHost.postMessage=="function"||(b.appHost=k),b.mausbotAppHost=k,x({v:1,type:"ready"}),k}function V(){typeof window<"u"&&re(window)}V();})();</script></body></html>diff --git a/shared/app-frame/bridge.ts b/shared/app-frame/bridge.tsindex f7e4965950..aef7da12b5 100644--- a/shared/app-frame/bridge.ts+++ b/shared/app-frame/bridge.ts@@ -2,27 +2,18 @@// runs in the desktop renderer and, bundled, in the phones' web views, so it never touches a window: a platform// hands it each `message` event and an adapter for the rest.import { APP_LIMITS, APP_PROTOCOL_VERSION, ROOM_VIEW_ONLY, utf8Bytes, type AppDocument } from "../app.ts";+import {+ APP_RPC_METHODS,+ RPC_HOST_REFUSED,+ RPC_INVALID_PARAMS,+ RPC_METHOD_NOT_FOUND,+ type AppRpcMethod,+ type JsonRpcError,+ type JsonRpcId,+ type JsonRpcMessage,+} from "../../packages/phone-protocol/src/app-rpc.ts";-export type JsonRpcId = string | number;--export interface JsonRpcError {- code: number;- message: string;- data?: unknown;-}--export type JsonRpcMessage =- | { jsonrpc: "2.0"; id: JsonRpcId; method: string; params?: Record<string, unknown> }- | { jsonrpc: "2.0"; method: string; params?: Record<string, unknown> }- | { jsonrpc: "2.0"; id: JsonRpcId; result: unknown }- | { jsonrpc: "2.0"; id: JsonRpcId; error: JsonRpcError };--export const APP_RPC_METHODS = ["tools/call", "tools/list", "resources/read", "resources/list"] as const;-export type AppRpcMethod = (typeof APP_RPC_METHODS)[number];--export const RPC_METHOD_NOT_FOUND = -32601;-export const RPC_INVALID_PARAMS = -32602;-export const RPC_HOST_REFUSED = -32000;+export * from "../../packages/phone-protocol/src/app-rpc.ts";export const APP_FRAME_LIMITS = {messageBytes: 1_000_000,diff --git a/shared/bot-limit.ts b/shared/bot-limit.tsnew file mode 100644index 0000000000..e5c706f8e7--- /dev/null+++ b/shared/bot-limit.ts@@ -0,0 +1 @@+export * from "../packages/phone-protocol/src/bot-limit.ts";diff --git a/shared/cloud-hints.ts b/shared/cloud-hints.tsnew file mode 100644index 0000000000..905e4ff20c--- /dev/null+++ b/shared/cloud-hints.ts@@ -0,0 +1 @@+export * from "../packages/phone-protocol/src/cloud-hints.ts";diff --git a/shared/codex-usage-limit.ts b/shared/codex-usage-limit.tsnew file mode 100644index 0000000000..8c07f2868e--- /dev/null+++ b/shared/codex-usage-limit.ts@@ -0,0 +1 @@+export * from "../packages/phone-protocol/src/codex-usage-limit.ts";diff --git a/shared/failed-turn.ts b/shared/failed-turn.tsnew file mode 100644index 0000000000..1fdcd21993--- /dev/null+++ b/shared/failed-turn.ts@@ -0,0 +1 @@+export * from "../packages/phone-protocol/src/failed-turn.ts";diff --git a/shared/markdown-plain-paths.ts b/shared/markdown-plain-paths.tsnew file mode 100644index 0000000000..1cc134873f--- /dev/null+++ b/shared/markdown-plain-paths.ts@@ -0,0 +1 @@+export * from "../packages/phone-protocol/src/markdown-plain-paths.ts";diff --git a/shared/mention-boundary.ts b/shared/mention-boundary.tsnew file mode 100644index 0000000000..d698e7acec--- /dev/null+++ b/shared/mention-boundary.ts@@ -0,0 +1 @@+export * from "../packages/phone-protocol/src/mention-boundary.ts";diff --git a/shared/upload-limits.ts b/shared/upload-limits.tsnew file mode 100644index 0000000000..50420560b1--- /dev/null+++ b/shared/upload-limits.ts@@ -0,0 +1 @@+export * from "../packages/phone-protocol/src/upload-limits.ts";diff --git a/shared/waits.ts b/shared/waits.tsnew file mode 100644index 0000000000..1f843d0ae5--- /dev/null+++ b/shared/waits.ts@@ -0,0 +1 @@+export * from "../packages/phone-protocol/src/waits.ts";diff --git a/src/components/cursor-face-data.ts b/src/components/cursor-face-data.tsnew file mode 100644index 0000000000..c2a1e76439--- /dev/null+++ b/src/components/cursor-face-data.ts@@ -0,0 +1 @@+export * from "../../packages/phone-protocol/src/cursor-face-data.ts";