@vpxa/aikit 0.1.265 → 0.1.267

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.
@@ -282,7 +282,7 @@ None.`:`### Stale Lessons\n${l.map(e=>`- **${e.title}** (\`${e.path}\`) — effe
282
282
  { path: 'docs/api.md', title: 'API Reference', status: 'stale' },
283
283
  ],
284
284
  },
285
- }`},{type:`text`,category:`content`,description:`Plain text content rendered through the markdown parser.`,valueShape:`string`},{type:`heading`,category:`content`,description:`Single heading with configurable level from h1 to h6.`,valueShape:`string`},{type:`paragraph`,category:`content`,description:`Single paragraph rendered inside a p tag.`,valueShape:`string`},{type:`separator`,category:`layout`,description:`Horizontal rule used to separate adjacent blocks.`,valueShape:`undefined`},{type:`actions`,category:`layout`,description:`Action bar containing button and select action definitions.`,valueShape:`Array<{ type: string; id: string; label: string; variant?: string; options?: Array<string | { label: string; value: string }> }>`}].map(e=>[e.type,{...e}]));function Yp(){let e={};for(let[t,n]of Jp)n.vendorScripts?.length&&(e[t]=n.vendorScripts);return e}const Xp=1024,Zp=new Set([`user-closed`,`host-dismissed`,`replaced`]);function Qp(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function $p(e,t,n){let r={code:e,message:t};return n!==void 0&&(r.details=n),{kind:`error`,error:r}}function em(e,t,n,r){e.writeHead(t,{"Content-Type":`application/json`,"Access-Control-Allow-Origin":r??`null`}),e.end(JSON.stringify(n))}async function tm(e){return await new Promise((t,n)=>{let r=[],i=0;e.on(`data`,t=>{if(i+=t.length,i>65536){n(Error(`Callback payload exceeds 64KB limit`)),e.destroy();return}r.push(t)}),e.on(`end`,()=>t(Buffer.concat(r).toString(`utf8`))),e.on(`error`,n)})}function nm(e,t){if(typeof e!=`string`||e.length!==t.length)return!1;let n=Buffer.from(e,`utf8`),r=Buffer.from(t,`utf8`);return n.length===r.length?ce(n,r):!1}function rm(e,t){let n=e.headers.origin;if(n!=null)return n===t;let r=e.headers.referer;return r==null?!1:r.startsWith(t)}function im(e){return(e.headers[`content-type`]??``).startsWith(`application/json`)}function am(e){for(let[t,n]of Object.entries(e)){let e=typeof n==`string`?n:JSON.stringify(n);if(Buffer.byteLength(e,`utf8`)>8192)return`Form field "${t}" exceeds 8KB limit`}return null}function om(e){return Array.isArray(e)&&e.length>Xp?`Selection exceeds ${Xp} items (got ${e.length})`:null}function sm(e,t,n){let r=typeof e.actionId==`string`?e.actionId:``,i=n.find(e=>e.id===r);if(!i)return $p(`INVALID_ACTION`,`Unknown actionId: ${r||`(missing)`}`);let a=typeof e.selection==`string`||Array.isArray(e.selection)?e.selection:void 0,o=Qp(e.formData)?e.formData:void 0,s={surfaceId:t,actionId:i.id,actionType:i.type,timestamp:typeof e.timestamp==`string`?e.timestamp:new Date().toISOString(),sourceTransport:`browser`};return e.value!==void 0&&(s.value=e.value),a!==void 0&&(s.selection=a),o!==void 0&&(s.formData=o),typeof e.label==`string`?s.label=e.label:i.label&&(s.label=i.label),{kind:`result`,result:s}}function cm(e,t){let n=oe(16).toString(`hex`),r=!1,i=!1,a,o,s=new Promise(e=>{o=e}),c=e=>r?a??e:(r=!0,a=e,o?.(e),e);return{nonce:n,promise:s,settleTimeout(e){return c({kind:`timeout`,waitedMs:e})},settleCancelled(e){return c({kind:`cancelled`,reason:e})},settleError(e,t,n){return c($p(e,t,n))},async handle(r,a,o){if(!im(r)){let e=c($p(`INVALID_CONTENT_TYPE`,`Content-Type must be application/json`));return em(a,415,{ok:!1,error:`unsupported-media-type`},o),e}if(!rm(r,o)){let e=c($p(`INVALID_ORIGIN`,`Unexpected callback origin: ${r.headers.origin??r.headers.referer??`(missing)`}`));return em(a,403,{ok:!1,error:`invalid-origin`},o),e}let s=``;try{s=await tm(r)}catch(e){let t=c($p(`INVALID_PAYLOAD`,e instanceof Error?e.message:`Unable to read callback payload`));return em(a,413,{ok:!1,error:`payload-too-large`},o),t}let l;try{let e=JSON.parse(s);if(!Qp(e))throw Error(`Callback payload must be an object`);l=e}catch(e){let t=c($p(`INVALID_PAYLOAD`,e instanceof Error?e.message:`Malformed callback payload`));return em(a,400,{ok:!1,error:`invalid-json`},o),t}if(i){let e=$p(`NONCE_CONSUMED`,`Nonce has already been used`);return em(a,403,{ok:!1,error:`nonce-consumed`},o),e}if(!nm(typeof l.nonce==`string`?l.nonce:``,n)){let e=c($p(`INVALID_NONCE`,`Callback nonce did not match`));return em(a,403,{ok:!1,error:`invalid-nonce`},o),e}i=!0;let u=om(l.selection);if(u){let e=c($p(`SELECTION_TOO_LARGE`,u));return em(a,413,{ok:!1,error:`selection-too-large`},o),e}if(Qp(l.formData)){let e=am(l.formData);if(e){let t=c($p(`PAYLOAD_FIELD_TOO_LARGE`,e));return em(a,413,{ok:!1,error:`field-too-large`},o),t}}if(l.kind===`cancelled`){let e=typeof l.reason==`string`?l.reason:``;if(!Zp.has(e)){let t=c($p(`INVALID_CANCEL_REASON`,`Unsupported cancel reason: ${e||`(missing)`}`));return em(a,400,{ok:!1,error:`invalid-cancel-reason`},o),t}let t=c({kind:`cancelled`,reason:e});return em(a,200,{ok:!0,kind:`cancelled`},o),t}let d=c(sm(l,e,t));return em(a,d.kind===`error`?400:200,{ok:d.kind!==`error`,kind:d.kind},o),d}}}const lm=new Map;function um(e){return e.replace(/[|\\{}()[\]^$+*?.]/g,`\\$&`)}function dm(e){let t=`(?=[^>]*\\bid=['"]${um(e)}['"])`;return RegExp(`(<script\\b(?=[^>]*\\btype=['"]application\\/json['"])${t}[^>]*>)[\\s\\S]*?(<\/script>)`,`i`)}function fm(e){lm.has(e.id)&&console.warn(`[viewer-registry] Overwriting viewer template "${e.id}"`),lm.set(e.id,e)}function pm(e){return lm.get(e)}function mm(e){return typeof e==`string`&&lm.has(e)}function hm(){return[...lm.values()]}function gm(e,t,n,r){let i=dm(n);if(!i.test(e))throw Error(`No <script type="application/json" id="${n}"> found in template`);let a=r?r(t):t,o=JSON.stringify(a??null).replace(/<\/script/gi,`<\\/script`).replace(/<script/gi,`\\u003Cscript`).replace(/-->/g,`--\\u003E`).replace(/<!--/g,`\\u003C!--`);return e.replace(i,`$1\n${o}\n$2`)}const _m=import.meta.dirname??ge(be(import.meta.url)),vm={type:`object`,properties:{title:{type:`string`},description:{type:`string`},layout:{type:`object`,properties:{direction:{type:`string`},spacing:{type:`number`},layerSpacing:{type:`number`}}},nodes:{type:`array`,items:{type:`object`,properties:{id:{type:`string`},type:{type:`string`,enum:[`person`,`system`,`container`,`component`,`database`,`queue`,`external`,`boundary`]},label:{type:`string`},technology:{type:`string`},icon:{type:`string`},description:{type:`string`}},required:[`id`,`type`,`label`]}},edges:{type:`array`,items:{type:`object`,properties:{source:{type:`string`},target:{type:`string`},label:{type:`string`},style:{type:`string`,enum:[`sync`,`async`,`dashed`,`dotted`,`solid`]}},required:[`source`,`target`]},default:[]}},required:[`nodes`]},ym={type:`object`,properties:{nodes:{type:`array`,items:{type:`object`,properties:{id:{type:`string`},label:{type:`string`},type:{type:`string`,enum:[`start-end`,`manual`,`automated`,`integration`,`decision`,`prerequisite`]},description:{type:`string`}},required:[`id`,`label`]}},edges:{type:`array`,items:{type:`object`,properties:{source:{type:`string`},target:{type:`string`},label:{type:`string`},type:{type:`string`,enum:[`standard`,`loop-back`,`exception`]}},required:[`source`,`target`]}}},required:[`nodes`]},bm={type:`object`,properties:{title:{type:`string`},description:{type:`string`},phases:{type:`array`,items:{type:`object`,properties:{id:{type:`string`},label:{type:`string`},outcome:{type:`string`},batches:{type:`array`,items:{type:`object`,properties:{id:{type:`string`},order:{type:`number`},parallel:{type:`boolean`},label:{type:`string`},tasks:{type:`array`,items:{type:`object`,properties:{id:{type:`string`},title:{type:`string`},agent:{type:`string`},files:{type:`array`,items:{type:`string`},default:[]},status:{type:`string`,enum:[`pending`,`in-progress`,`done`,`blocked`]},dependsOn:{type:`array`,items:{type:`string`},default:[]}},required:[`id`,`title`]},default:[]}},required:[`id`,`tasks`]},default:[]}},required:[`id`,`label`,`batches`]}}},required:[`phases`]};function xm(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Sm(e,t){return xm(t)?{...t,kind:e}:{kind:e}}function Cm(e){let t=e===`canvas.html`?[P(_m,`..`,`..`,`..`,`..`,`..`,`scaffold`,`general`,`viewers`,`src`,`canvas`,`index.html`),P(_m,`..`,`..`,`scaffold`,`general`,`viewers`,`src`,`canvas`,`index.html`)]:[],n=S(`server`,[P(`viewers`,`dist`,e),P(`viewers`,e)]),r=[...t,...n?[n]:[],P(_m,`..`,`..`,`..`,`viewers`,e),P(_m,`..`,`..`,`..`,`..`,`..`,`scaffold`,`general`,`viewers`,`src`,`static`,e),P(_m,`..`,`..`,`..`,`..`,`..`,`scaffold`,`general`,`viewers`,`dist`,e),P(_m,`..`,`..`,`..`,`..`,`..`,`scaffold`,`general`,`viewers`,e),P(_m,`..`,`..`,`scaffold`,`general`,`viewers`,`dist`,e),P(_m,`..`,`..`,`scaffold`,`general`,`viewers`,e),P(_m,`..`,`viewers`,`dist`,e),P(_m,`..`,`viewers`,e)];for(let e of r)try{return N(e,`utf8`)}catch{}throw Error(`Viewer HTML not found: ${e}. Searched: ${r.join(`, `)}`)}let wm,Tm,Em,Dm,Om,km;function Am(){return wm??=Cm(`c4-viewer.html`),wm}function jm(){return Tm??=Cm(`tour-viewer.html`),Tm}function Mm(){return Em??=Cm(`canvas.html`),Em}function Nm(){return Dm??=Cm(`architecture-static.html`),Dm}function Pm(){return Om??=Cm(`process-flow-static.html`),Om}function Fm(){return km??=Cm(`task-plan-static.html`),km}function Im(){fm({id:`c4@1`,label:`C4 Architecture Diagram`,description:`Interactive C4 architecture diagram with zoom, pan, and ELK auto-layout`,inputSchema:vm,injectId:`diagram-data`,supportedTransports:[`browser`],resolveHtml:Am}),fm({id:`c4-static@1`,label:`C4 Architecture Diagram (Static)`,description:`Static SVG architecture diagram for inline rendering`,inputSchema:vm,injectId:`diagram-data`,supportedTransports:[`mcp-app`],resolveHtml:Nm}),fm({id:`tour@1`,label:`Code Tour Viewer`,description:`Interactive code tour with step navigation and dependency graph`,inputSchema:{type:`object`,properties:{title:{type:`string`},description:{type:`string`},estimatedTime:{type:`string`},steps:{type:`array`,items:{type:`object`,properties:{stepNumber:{type:`number`},id:{type:`string`},title:{type:`string`},file:{type:`string`},explanation:{type:`string`},description:{type:`string`},learnsConcept:{type:`string`},duration:{type:`string`},line:{type:`number`},code:{type:`string`}},required:[`id`,`title`]}},dependencies:{type:`array`,items:{type:`object`,properties:{source:{type:`string`},target:{type:`string`}},required:[`source`,`target`]},default:[]}},required:[`steps`]},injectId:`tour-data`,supportedTransports:[`browser`],resolveHtml:jm}),fm({id:`process-flow-static@1`,label:`Process Flow Diagram (Static)`,description:`Static SVG process flow diagram for inline rendering`,inputSchema:ym,injectId:`diagram-data`,supportedTransports:[`mcp-app`],resolveHtml:Pm}),fm({id:`task-plan-static@1`,label:`Task Execution Plan (Static)`,description:`Static SVG task execution plan for inline rendering`,inputSchema:bm,injectId:`diagram-data`,supportedTransports:[`mcp-app`],resolveHtml:Fm}),fm({id:`task-plan@1`,label:`Task Execution Plan (Interactive)`,description:`Interactive task execution plan with ReactFlow, phase grouping, and dependency edges`,inputSchema:bm,injectId:`diagram-data`,supportedTransports:[`browser`],resolveHtml:Mm,transformData:e=>Sm(`task-plan`,e)}),fm({id:`process-flow@1`,label:`Process Flow Diagram (Interactive)`,description:`Interactive process flow diagram with ReactFlow`,inputSchema:ym,injectId:`diagram-data`,supportedTransports:[`browser`],resolveHtml:Mm,transformData:e=>Sm(`process-flow`,e)})}function Lm(){let e=new Cr;for(let t of Er.list())e.register(t);return e.register(Tr),e.register(Ar),e.register(jr),e.register(Dr),e}function Rm(e,t){return e?.supportedTransports.includes(t)??!1}const zm=Lm();function Bm(e){if(e.template)return zm.get(e.template)}function Vm(e){if((e.actions?.length??0)>0)return!0;if(e.template&&mm(e.template)){let t=pm(e.template);return t?.supportedTransports.includes(`browser`)===!0&&!t.supportedTransports.includes(`mcp-app`)}let t=Bm(e);return Rm(t,`browser`)&&!Rm(t,`mcp-app`)}Im();const Hm=String.raw`(function(){
285
+ }`},{type:`text`,category:`content`,description:`Plain text content rendered through the markdown parser.`,valueShape:`string`},{type:`heading`,category:`content`,description:`Single heading with configurable level from h1 to h6.`,valueShape:`string`},{type:`paragraph`,category:`content`,description:`Single paragraph rendered inside a p tag.`,valueShape:`string`},{type:`separator`,category:`layout`,description:`Horizontal rule used to separate adjacent blocks.`,valueShape:`undefined`},{type:`actions`,category:`layout`,description:`Action bar containing button and select action definitions.`,valueShape:`Array<{ type: string; id: string; label: string; variant?: string; options?: Array<string | { label: string; value: string }> }>`}].map(e=>[e.type,{...e}]));function Yp(){let e={};for(let[t,n]of Jp)n.vendorScripts?.length&&(e[t]=n.vendorScripts);return e}const Xp=1024,Zp=new Set([`user-closed`,`host-dismissed`,`replaced`]);function Qp(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function $p(e,t,n){let r={code:e,message:t};return n!==void 0&&(r.details=n),{kind:`error`,error:r}}function em(e,t,n,r){e.writeHead(t,{"Content-Type":`application/json`,"Access-Control-Allow-Origin":r??`null`}),e.end(JSON.stringify(n))}async function tm(e){return await new Promise((t,n)=>{let r=[],i=0;e.on(`data`,t=>{if(i+=t.length,i>65536){n(Error(`Callback payload exceeds 64KB limit`)),e.destroy();return}r.push(t)}),e.on(`end`,()=>t(Buffer.concat(r).toString(`utf8`))),e.on(`error`,n)})}function nm(e,t){if(typeof e!=`string`||e.length!==t.length)return!1;let n=Buffer.from(e,`utf8`),r=Buffer.from(t,`utf8`);return n.length===r.length?ce(n,r):!1}function rm(e,t){let n=e.headers.origin;if(n!=null)return n===t;let r=e.headers.referer;return r==null?!1:r.startsWith(t)}function im(e){return(e.headers[`content-type`]??``).startsWith(`application/json`)}function am(e){for(let[t,n]of Object.entries(e)){let e=typeof n==`string`?n:JSON.stringify(n);if(Buffer.byteLength(e,`utf8`)>8192)return`Form field "${t}" exceeds 8KB limit`}return null}function om(e){return Array.isArray(e)&&e.length>Xp?`Selection exceeds ${Xp} items (got ${e.length})`:null}function sm(e,t,n){let r=typeof e.actionId==`string`?e.actionId:``,i=n.find(e=>e.id===r);if(!i)return $p(`INVALID_ACTION`,`Unknown actionId: ${r||`(missing)`}`);let a=typeof e.selection==`string`||Array.isArray(e.selection)?e.selection:void 0,o=Qp(e.formData)?e.formData:void 0,s={surfaceId:t,actionId:i.id,actionType:i.type,timestamp:typeof e.timestamp==`string`?e.timestamp:new Date().toISOString(),sourceTransport:`browser`};return e.value!==void 0&&(s.value=e.value),a!==void 0&&(s.selection=a),o!==void 0&&(s.formData=o),typeof e.label==`string`?s.label=e.label:i.label&&(s.label=i.label),{kind:`result`,result:s}}function cm(e,t){let n=oe(16).toString(`hex`),r=!1,i=!1,a,o,s=new Promise(e=>{o=e}),c=e=>r?a??e:(r=!0,a=e,o?.(e),e);return{nonce:n,promise:s,settleTimeout(e){return c({kind:`timeout`,waitedMs:e})},settleCancelled(e){return c({kind:`cancelled`,reason:e})},settleError(e,t,n){return c($p(e,t,n))},async handle(r,a,o){if(!im(r)){let e=c($p(`INVALID_CONTENT_TYPE`,`Content-Type must be application/json`));return em(a,415,{ok:!1,error:`unsupported-media-type`},o),e}if(!rm(r,o)){let e=c($p(`INVALID_ORIGIN`,`Unexpected callback origin: ${r.headers.origin??r.headers.referer??`(missing)`}`));return em(a,403,{ok:!1,error:`invalid-origin`},o),e}let s=``;try{s=await tm(r)}catch(e){let t=c($p(`INVALID_PAYLOAD`,e instanceof Error?e.message:`Unable to read callback payload`));return em(a,413,{ok:!1,error:`payload-too-large`},o),t}let l;try{let e=JSON.parse(s);if(!Qp(e))throw Error(`Callback payload must be an object`);l=e}catch(e){let t=c($p(`INVALID_PAYLOAD`,e instanceof Error?e.message:`Malformed callback payload`));return em(a,400,{ok:!1,error:`invalid-json`},o),t}if(i){let e=$p(`NONCE_CONSUMED`,`Nonce has already been used`);return em(a,403,{ok:!1,error:`nonce-consumed`},o),e}if(!nm(typeof l.nonce==`string`?l.nonce:``,n)){let e=c($p(`INVALID_NONCE`,`Callback nonce did not match`));return em(a,403,{ok:!1,error:`invalid-nonce`},o),e}i=!0;let u=om(l.selection);if(u){let e=c($p(`SELECTION_TOO_LARGE`,u));return em(a,413,{ok:!1,error:`selection-too-large`},o),e}if(Qp(l.formData)){let e=am(l.formData);if(e){let t=c($p(`PAYLOAD_FIELD_TOO_LARGE`,e));return em(a,413,{ok:!1,error:`field-too-large`},o),t}}if(l.kind===`cancelled`){let e=typeof l.reason==`string`?l.reason:``;if(!Zp.has(e)){let t=c($p(`INVALID_CANCEL_REASON`,`Unsupported cancel reason: ${e||`(missing)`}`));return em(a,400,{ok:!1,error:`invalid-cancel-reason`},o),t}let t=c({kind:`cancelled`,reason:e});return em(a,200,{ok:!0,kind:`cancelled`},o),t}let d=c(sm(l,e,t));return em(a,d.kind===`error`?400:200,{ok:d.kind!==`error`,kind:d.kind},o),d}}}const lm=`Install AI Kit with <code>${Y(`npx -y @vpxa/aikit@latest init --user`)}</code>.`,um=new Map;function dm(e){return e.replace(/[|\\{}()[\]^$+*?.]/g,`\\$&`)}function fm(e){let t=`(?=[^>]*\\bid=['"]${dm(e)}['"])`;return RegExp(`(<script\\b(?=[^>]*\\btype=['"]application\\/json['"])${t}[^>]*>)[\\s\\S]*?(<\/script>)`,`i`)}function pm(e){um.has(e.id)&&console.warn(`[viewer-registry] Overwriting viewer template "${e.id}"`),um.set(e.id,e)}function mm(e){return um.get(e)}function hm(e){return typeof e==`string`&&um.has(e)}function gm(){return[...um.values()]}function _m(e,t,n,r){let i=fm(n);if(!i.test(e))throw Error(`No <script type="application/json" id="${n}"> found in template`);let a=r?r(t):t,o=JSON.stringify(a??null).replace(/<\/script/gi,`<\\/script`).replace(/<script/gi,`\\u003Cscript`).replace(/-->/g,`--\\u003E`).replace(/<!--/g,`\\u003C!--`);return e.replace(i,`$1\n${o}\n$2`)}const vm=import.meta.dirname??ge(be(import.meta.url)),ym={type:`object`,properties:{title:{type:`string`},description:{type:`string`},layout:{type:`object`,properties:{direction:{type:`string`},spacing:{type:`number`},layerSpacing:{type:`number`}}},nodes:{type:`array`,items:{type:`object`,properties:{id:{type:`string`},type:{type:`string`,enum:[`person`,`system`,`container`,`component`,`database`,`queue`,`external`,`boundary`]},label:{type:`string`},technology:{type:`string`},icon:{type:`string`},description:{type:`string`}},required:[`id`,`type`,`label`]}},edges:{type:`array`,items:{type:`object`,properties:{source:{type:`string`},target:{type:`string`},label:{type:`string`},style:{type:`string`,enum:[`sync`,`async`,`dashed`,`dotted`,`solid`]}},required:[`source`,`target`]},default:[]}},required:[`nodes`]},bm={type:`object`,properties:{nodes:{type:`array`,items:{type:`object`,properties:{id:{type:`string`},label:{type:`string`},type:{type:`string`,enum:[`start-end`,`manual`,`automated`,`integration`,`decision`,`prerequisite`]},description:{type:`string`}},required:[`id`,`label`]}},edges:{type:`array`,items:{type:`object`,properties:{source:{type:`string`},target:{type:`string`},label:{type:`string`},type:{type:`string`,enum:[`standard`,`loop-back`,`exception`]}},required:[`source`,`target`]}}},required:[`nodes`]},xm={type:`object`,properties:{title:{type:`string`},description:{type:`string`},phases:{type:`array`,items:{type:`object`,properties:{id:{type:`string`},label:{type:`string`},outcome:{type:`string`},batches:{type:`array`,items:{type:`object`,properties:{id:{type:`string`},order:{type:`number`},parallel:{type:`boolean`},label:{type:`string`},tasks:{type:`array`,items:{type:`object`,properties:{id:{type:`string`},title:{type:`string`},agent:{type:`string`},files:{type:`array`,items:{type:`string`},default:[]},status:{type:`string`,enum:[`pending`,`in-progress`,`done`,`blocked`]},dependsOn:{type:`array`,items:{type:`string`},default:[]}},required:[`id`,`title`]},default:[]}},required:[`id`,`tasks`]},default:[]}},required:[`id`,`label`,`batches`]}}},required:[`phases`]};function Sm(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Cm(e,t){return Sm(t)?{...t,kind:e}:{kind:e}}function wm(e){let t=e===`canvas.html`?[P(vm,`..`,`..`,`..`,`..`,`..`,`scaffold`,`general`,`viewers`,`src`,`canvas`,`index.html`),P(vm,`..`,`..`,`scaffold`,`general`,`viewers`,`src`,`canvas`,`index.html`)]:[],n=S(`server`,[P(`viewers`,`dist`,e),P(`viewers`,e)]),r=[...t,...n?[n]:[],P(vm,`..`,`..`,`..`,`viewers`,e),P(vm,`..`,`..`,`..`,`..`,`..`,`scaffold`,`general`,`viewers`,`src`,`static`,e),P(vm,`..`,`..`,`..`,`..`,`..`,`scaffold`,`general`,`viewers`,`dist`,e),P(vm,`..`,`..`,`..`,`..`,`..`,`scaffold`,`general`,`viewers`,e),P(vm,`..`,`..`,`scaffold`,`general`,`viewers`,`dist`,e),P(vm,`..`,`..`,`scaffold`,`general`,`viewers`,e),P(vm,`..`,`viewers`,`dist`,e),P(vm,`..`,`viewers`,e)];for(let e of r)try{return N(e,`utf8`)}catch{}throw Error(`Viewer HTML not found: ${e}. Searched: ${r.join(`, `)}`)}let Tm,Em,Dm,Om,km,Am;function jm(){return Tm??=wm(`c4-viewer.html`),Tm}function Mm(){return Em??=wm(`tour-viewer.html`),Em}function Nm(){return Dm??=wm(`canvas.html`),Dm}function Pm(){return Om??=wm(`architecture-static.html`),Om}function Fm(){return km??=wm(`process-flow-static.html`),km}function Im(){return Am??=wm(`task-plan-static.html`),Am}function Lm(){pm({id:`c4@1`,label:`C4 Architecture Diagram`,description:`Interactive C4 architecture diagram with zoom, pan, and ELK auto-layout`,inputSchema:ym,injectId:`diagram-data`,supportedTransports:[`browser`],resolveHtml:jm}),pm({id:`c4-static@1`,label:`C4 Architecture Diagram (Static)`,description:`Static SVG architecture diagram for inline rendering`,inputSchema:ym,injectId:`diagram-data`,supportedTransports:[`mcp-app`],resolveHtml:Pm}),pm({id:`tour@1`,label:`Code Tour Viewer`,description:`Interactive code tour with step navigation and dependency graph`,inputSchema:{type:`object`,properties:{title:{type:`string`},description:{type:`string`},estimatedTime:{type:`string`},steps:{type:`array`,items:{type:`object`,properties:{stepNumber:{type:`number`},id:{type:`string`},title:{type:`string`},file:{type:`string`},explanation:{type:`string`},description:{type:`string`},learnsConcept:{type:`string`},duration:{type:`string`},line:{type:`number`},code:{type:`string`}},required:[`id`,`title`]}},dependencies:{type:`array`,items:{type:`object`,properties:{source:{type:`string`},target:{type:`string`}},required:[`source`,`target`]},default:[]}},required:[`steps`]},injectId:`tour-data`,supportedTransports:[`browser`],resolveHtml:Mm}),pm({id:`process-flow-static@1`,label:`Process Flow Diagram (Static)`,description:`Static SVG process flow diagram for inline rendering`,inputSchema:bm,injectId:`diagram-data`,supportedTransports:[`mcp-app`],resolveHtml:Fm}),pm({id:`task-plan-static@1`,label:`Task Execution Plan (Static)`,description:`Static SVG task execution plan for inline rendering`,inputSchema:xm,injectId:`diagram-data`,supportedTransports:[`mcp-app`],resolveHtml:Im}),pm({id:`task-plan@1`,label:`Task Execution Plan (Interactive)`,description:`Interactive task execution plan with ReactFlow, phase grouping, and dependency edges`,inputSchema:xm,injectId:`diagram-data`,supportedTransports:[`browser`],resolveHtml:Nm,transformData:e=>Cm(`task-plan`,e)}),pm({id:`process-flow@1`,label:`Process Flow Diagram (Interactive)`,description:`Interactive process flow diagram with ReactFlow`,inputSchema:bm,injectId:`diagram-data`,supportedTransports:[`browser`],resolveHtml:Nm,transformData:e=>Cm(`process-flow`,e)})}function Rm(){let e=new Cr;for(let t of Er.list())e.register(t);return e.register(Tr),e.register(Ar),e.register(jr),e.register(Dr),e}function zm(e,t){return e?.supportedTransports.includes(t)??!1}const Bm=Rm();function Vm(e){if(e.template)return Bm.get(e.template)}function Hm(e){if((e.actions?.length??0)>0)return!0;if(e.template&&hm(e.template)){let t=mm(e.template);return t?.supportedTransports.includes(`browser`)===!0&&!t.supportedTransports.includes(`mcp-app`)}let t=Vm(e);return zm(t,`browser`)&&!zm(t,`mcp-app`)}Lm();const Um=String.raw`(function(){
286
286
  'use strict';
287
287
 
288
288
  var SVG_NS = 'http://www.w3.org/2000/svg';
@@ -2658,7 +2658,7 @@ None.`:`### Stale Lessons\n${l.map(e=>`- **${e.title}** (\`${e.path}\`) — effe
2658
2658
  };
2659
2659
 
2660
2660
  init();
2661
- })();`;function Um(){let e;return()=>{if(e!==void 0)return e;try{e=N(ae(import.meta.url).resolve(`mermaid/dist/mermaid.min.js`),`utf-8`)}catch{e=``}return e}}const Wm={id:`mermaid`,cdn:`https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.min.js`,inlineSource:Hm,initScript:`window.__aikit_initMermaid = function() {
2661
+ })();`;function Wm(){let e;return()=>{if(e!==void 0)return e;try{e=N(ae(import.meta.url).resolve(`mermaid/dist/mermaid.min.js`),`utf-8`)}catch{e=``}return e}}const Gm={id:`mermaid`,cdn:`https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.min.js`,inlineSource:Um,initScript:`window.__aikit_initMermaid = function() {
2662
2662
  if (typeof mermaid === 'undefined') return;
2663
2663
  if (document.readyState === 'loading') {
2664
2664
  document.addEventListener('DOMContentLoaded', window.__aikit_initMermaid);
@@ -2671,7 +2671,7 @@ None.`:`### Stale Lessons\n${l.map(e=>`- **${e.title}** (\`${e.path}\`) — effe
2671
2671
  }
2672
2672
  mermaid.initialize({ startOnLoad: false, theme: theme });
2673
2673
  mermaid.run();
2674
- };`,onload:`window.__aikit_initMermaid&&window.__aikit_initMermaid()`,local:{route:`/vendor/mermaid.min.js`,getSource:Um()}},Gm=new Map([[`mermaid`,Wm]]);function Km(e,t){if(!e?.length)return;let n=[];for(let r of e){let e=Gm.get(r);if(e){if(t===`browser`){n.push({inlineSource:e.inlineSource,onload:e.onload});continue}if(t===`mcp-app`){n.push({inlineSource:e.inlineSource,onload:e.onload});continue}n.push({src:e.cdn,initScript:e.initScript,onload:e.onload})}}return n.length>0?n:void 0}function qm(){let e=[];for(let t of Gm.values())t.local&&e.push({route:t.local.route,getSource:t.local.getSource,cdn:t.cdn});return e}const Jm=300*1e3,Ym=15*1e3;let X=null,Xm;process.on(`exit`,()=>{let e=X;if(e){try{e.close()}catch{}X=null}});function Zm(e,t){return e.length===0?``:`
2674
+ };`,onload:`window.__aikit_initMermaid&&window.__aikit_initMermaid()`,local:{route:`/vendor/mermaid.min.js`,getSource:Wm()}},Km=new Map([[`mermaid`,Gm]]);function qm(e,t){if(!e?.length)return;let n=[];for(let r of e){let e=Km.get(r);if(e){if(t===`browser`){n.push({inlineSource:e.inlineSource,onload:e.onload});continue}if(t===`mcp-app`){n.push({inlineSource:e.inlineSource,onload:e.onload});continue}n.push({src:e.cdn,initScript:e.initScript,onload:e.onload})}}return n.length>0?n:void 0}function Jm(){let e=[];for(let t of Km.values())t.local&&e.push({route:t.local.route,getSource:t.local.getSource,cdn:t.cdn});return e}const Ym=300*1e3,Xm=15*1e3;let X=null,Zm;process.on(`exit`,()=>{let e=X;if(e){try{e.close()}catch{}X=null}});function Qm(e,t){return e.length===0?``:`
2675
2675
  <section class="present-surface-actions">
2676
2676
  <div class="present-action-bar">${e.map(e=>{let t=Y(e.id),n=Y(e.label);if(e.type===`select`||e.type===`multi-select`)return`<label class="present-action-field"><span>${n}</span><select data-action-id="${t}"${e.type===`multi-select`?` multiple`:``}>${(e.options??[]).map(e=>`<option value="${Y(e.value)}">${Y(e.label)}</option>`).join(``)}</select></label>`;if(e.type===`text-submit`)return`<label class="present-action-field"><span>${n}</span><div class="present-text-submit"><input type="text" class="present-text-input" data-action-id="${t}" data-action-label="${n}" placeholder="${n}" /><button type="button" class="present-action-btn present-action-primary present-submit-btn" data-submit-for="${t}">Send</button></div></label>`;if(e.type===`form-submit`){let r=e.schema;if(r)return`<form class="present-form" data-action-id="${t}" data-action-label="${n}">${Object.entries(r).map(([e,t])=>{let n=Y(t.description??e);return`<label class="present-action-field"><span>${n}</span><input type="${t.type===`number`?`number`:t.type===`boolean`?`checkbox`:`text`}" class="present-text-input" name="${Y(e)}" placeholder="${n}" /></label>`}).join(``)}<button type="submit" class="present-action-btn present-action-primary">${n}</button></form>`}return`<button type="button" class="present-action-btn present-action-${Y(e.variant??`default`)}" data-action-id="${t}" data-action-label="${n}">${n}</button>`}).join(``)}</div>
2677
2677
  <p id="present-action-status" class="present-action-status" aria-live="polite"></p>
@@ -2876,8 +2876,8 @@ None.`:`### Stale Lessons\n${l.map(e=>`- **${e.title}** (\`${e.path}\`) — effe
2876
2876
  navigator.sendBeacon('/callback', new Blob([body], { type: 'application/json' }));
2877
2877
  });
2878
2878
  })();
2879
- <\/script>`}function Qm(e){try{if(process.platform===`win32`){xr(`cmd`,[`/c`,`start`,``,e],{windowsHide:!0});return}if(process.platform===`darwin`){xr(`open`,[e]);return}xr(`xdg-open`,[e])}catch{}}async function $m(e){try{let t=Kn();return await t.launch(`ui`),t.resetIdleTimer(),await(await t.getContext().newPage()).goto(e,{waitUntil:`domcontentloaded`}),!0}catch{return Qm(e),!1}}function eh(e,t,n){let r=[e.title];return e.description&&r.push(e.description),r.push(``,`Opened in browser at ${t}`,n),r.join(`
2880
- `)}function th(e){return e.some(e=>e.id!==`__dismiss`)}function nh(){return Xm===void 0&&(Xm=C(`blocks-interactive`)),Xm}function rh(e){let t=e?.split(`?`)[0];if(!t?.startsWith(`/@aikit/blocks-interactive/dist/`))return;let n=nh();if(n)return P(n,`dist`,t.slice(32))}function ih(e){return e.replace(`</head>`,`<style>
2879
+ <\/script>`}function $m(e){try{if(process.platform===`win32`){xr(`cmd`,[`/c`,`start`,``,e],{windowsHide:!0});return}if(process.platform===`darwin`){xr(`open`,[e]);return}xr(`xdg-open`,[e])}catch{}}async function eh(e){try{let t=Kn();return await t.launch(`ui`),t.resetIdleTimer(),await(await t.getContext().newPage()).goto(e,{waitUntil:`domcontentloaded`}),!0}catch{return $m(e),!1}}function th(e,t,n){let r=[e.title];return e.description&&r.push(e.description),r.push(``,`Opened in browser at ${t}`,n),r.join(`
2880
+ `)}function nh(e){return e.some(e=>e.id!==`__dismiss`)}function rh(){return Zm===void 0&&(Zm=C(`blocks-interactive`)),Zm}function ih(e){let t=e?.split(`?`)[0];if(!t?.startsWith(`/@aikit/blocks-interactive/dist/`))return;let n=rh();if(n)return P(n,`dist`,t.slice(32))}function ah(e){return e.replace(`</head>`,`<style>
2881
2881
  .toolbar, .badge, body > header, body > footer { display: none !important; }
2882
2882
  body { padding-top: 0 !important; margin-top: 0 !important; }
2883
2883
  </style>
@@ -2888,8 +2888,8 @@ window.addEventListener('message', function(e) {
2888
2888
  }
2889
2889
  });
2890
2890
  <\/script>
2891
- </body>`)}function ah(){let e=X;e&&(X=null,setTimeout(()=>{try{e.close()}catch{}},2e3))}function oh(e){if(!e.headersSent)try{e.writeHead(500,{"Content-Type":`text/plain`}),e.end(`Internal Server Error`)}catch{try{e.end()}catch{}}}async function sh(e){let t=Kn();t.isLaunched()||await t.launch(`headless`),t.resetIdleTimer();let n=await t.getContext().newPage();try{return await n.goto(e,{waitUntil:`domcontentloaded`}),await n.waitForLoadState(`networkidle`,{timeout:2e3}).catch(()=>{}),await n.screenshot({fullPage:!0,type:`png`})}finally{await n.close().catch(()=>{})}}async function ch(e,t){if(!t){e.writeHead(503,{"Content-Type":`text/plain; charset=utf-8`}),e.end(`Screenshot target is not ready.`);return}try{let n=await sh(t);e.writeHead(200,{"Content-Type":`image/png`,"Cache-Control":`no-store`}),e.end(n)}catch{oh(e)}}async function lh(e,t){if(Ch(`<html><body style="font-family:system-ui;padding:2rem;color:#888;text-align:center"><p>Content opened in browser window.</p></body></html>`),e.data!=null&&t.inputSchema){let n=ln({data:e.data,schema:t.inputSchema});if(!n.valid){let e=n.errors.map(e=>` ${e.path}: ${e.message}${e.expected?` (expected: ${e.expected}, got: ${e.received})`:``}`).join(`
2892
- `);return{content:[{type:`text`,text:`[ERROR:VALIDATION] Template "${t.id}" data validation failed:\n${e}\n\nExpected schema: ${JSON.stringify(t.inputSchema,null,2)}`}],structuredContent:{kind:`error`,error:{code:`VIEWER_DATA_INVALID`,message:`Template "${t.id}" data validation failed:\n${e}\n\nExpected schema: ${JSON.stringify(t.inputSchema,null,2)}`}},isError:!0}}}let n=ih(gm(t.resolveHtml(),e.data??null,t.injectId,t.transformData)),r=wr({title:e.title,subtitle:e.description,html:[`<div class="present-viewer-container">`,` <iframe class="present-viewer-iframe" src="/viewer" sandbox="allow-scripts allow-same-origin"></iframe>`,` <script>
2891
+ </body>`)}function oh(){let e=X;e&&(X=null,setTimeout(()=>{try{e.close()}catch{}},2e3))}function sh(e){if(!e.headersSent)try{e.writeHead(500,{"Content-Type":`text/plain`}),e.end(`Internal Server Error`)}catch{try{e.end()}catch{}}}async function ch(e){let t=Kn();t.isLaunched()||await t.launch(`headless`),t.resetIdleTimer();let n=await t.getContext().newPage();try{return await n.goto(e,{waitUntil:`domcontentloaded`}),await n.waitForLoadState(`networkidle`,{timeout:2e3}).catch(()=>{}),await n.screenshot({fullPage:!0,type:`png`})}finally{await n.close().catch(()=>{})}}async function lh(e,t){if(!t){e.writeHead(503,{"Content-Type":`text/plain; charset=utf-8`}),e.end(`Screenshot target is not ready.`);return}try{let n=await ch(t);e.writeHead(200,{"Content-Type":`image/png`,"Cache-Control":`no-store`}),e.end(n)}catch{sh(e)}}async function uh(e,t){if(Ch(`<html><body style="font-family:system-ui;padding:2rem;color:#888;text-align:center"><p>Content opened in browser window.</p></body></html>`),e.data!=null&&t.inputSchema){let n=ln({data:e.data,schema:t.inputSchema});if(!n.valid){let e=n.errors.map(e=>` ${e.path}: ${e.message}${e.expected?` (expected: ${e.expected}, got: ${e.received})`:``}`).join(`
2892
+ `);return{content:[{type:`text`,text:`[ERROR:VALIDATION] Template "${t.id}" data validation failed:\n${e}\n\nExpected schema: ${JSON.stringify(t.inputSchema,null,2)}`}],structuredContent:{kind:`error`,error:{code:`VIEWER_DATA_INVALID`,message:`Template "${t.id}" data validation failed:\n${e}\n\nExpected schema: ${JSON.stringify(t.inputSchema,null,2)}`}},isError:!0}}}let n=ah(_m(t.resolveHtml(),e.data??null,t.injectId,t.transformData)),r=wr({title:e.title,subtitle:e.description,html:[`<div class="present-viewer-container">`,` <iframe class="present-viewer-iframe" src="/viewer" sandbox="allow-scripts allow-same-origin"></iframe>`,` <script>
2893
2893
  (function() {
2894
2894
  const iframe = document.querySelector('.present-viewer-iframe');
2895
2895
  if (!iframe) return;
@@ -2905,10 +2905,10 @@ window.addEventListener('message', function(e) {
2905
2905
  })();
2906
2906
  <\/script>`,`</div>`].join(`
2907
2907
  `),css:[[`.present-viewer-container {`,` flex: 1;`,` min-height: calc(100vh - 12rem);`,` position: relative;`,` border-radius: 0.75rem;`,` overflow: hidden;`,` border: none;`,`}`,`.present-viewer-iframe {`,` border: none;`,` width: 100%;`,` height: 100%;`,` position: absolute;`,` inset: 0;`,` border-radius: inherit;`,`}`].join(`
2908
- `)],islands:[],payload:void 0,nonce:``,generatedAt:new Date().toISOString(),colorScheme:e.colorScheme,lang:e.lang,dir:e.dir,transport:`browser`,exportPolicy:`local-interactive`}),i=``;try{ah(),i=await new Promise((e,t)=>{let a=Nr((e,t)=>{try{if(e.url?.startsWith(`/__aikit_screenshot.png`)){ch(t,i);return}if(e.url===`/viewer`){t.writeHead(200,{"Content-Type":`text/html; charset=utf-8`}),t.end(n);return}t.writeHead(200,{"Content-Type":`text/html; charset=utf-8`}),t.end(r)}catch{oh(t)}});a.listen(0,`127.0.0.1`,()=>{let n=a.address();if(typeof n!=`object`||!n){t(Error(`Failed to resolve local browser address`));return}X=a,e(`http://127.0.0.1:${n.port}`)})})}catch(t){return{content:[{type:`text`,text:`${e.title}\n\nUnable to start local browser transport.`}],structuredContent:{kind:`error`,error:{code:`BROWSER_START_FAILED`,message:t instanceof Error?t.message:`Unable to start browser transport`}},isError:!0}}await $m(i);let a=X;return a&&setTimeout(()=>{X===a&&(a.close(),X=null)},Jm),{content:[{type:`text`,text:eh(e,i,`Rendered.`)}],structuredContent:{kind:`rendered`,reason:`no-response-required`}}}async function uh(e){Ch(`<html><body style="font-family:system-ui;padding:2rem;color:#888;text-align:center"><p>Content opened in browser window.</p></body></html>`);let t=Mr(e,{transport:`browser`,registry:zm,blockVendorScripts:Yp()}),n=cm(t.surfaceId,t.actions),r=Km(t.vendorScripts,`browser`),i=qm(),a=wr({title:e.title,subtitle:e.description,html:[t.html,Zm(t.actions,n.nonce)].filter(Boolean).join(`
2909
- `),css:t.css,islands:t.islands,payload:t.payload,nonce:t.nonce,generatedAt:new Date().toISOString(),colorScheme:e.colorScheme,lang:e.lang,dir:e.dir,transport:`browser`,exportPolicy:t.exportPolicy,headScripts:r}),o=``,s=``,c=!1;try{let e=X;e&&(e.close(),X=null),o=await new Promise((e,t)=>{let r=Nr((e,t)=>{try{if(c=!0,e.method===`OPTIONS`){t.writeHead(204,{"Access-Control-Allow-Origin":s||`*`,"Access-Control-Allow-Methods":`POST`,"Access-Control-Allow-Headers":`Content-Type`}),t.end();return}if(e.method===`POST`&&e.url===`/callback`){n.handle(e,t,s).catch(()=>{oh(t)});return}if(e.url?.startsWith(`/__aikit_screenshot.png`)){ch(t,o||s);return}let r=i.find(t=>e.url===t.route);if(r){let e=r.getSource();if(e){t.writeHead(200,{"Content-Type":`application/javascript; charset=utf-8`,"Cache-Control":`public, max-age=86400`}),t.end(e);return}t.writeHead(302,{Location:r.cdn}),t.end();return}let l=rh(e.url);if(l)try{let e=N(l,`utf8`);t.writeHead(200,{"Content-Type":`application/javascript; charset=utf-8`}),t.end(e);return}catch{}t.writeHead(200,{"Content-Type":`text/html; charset=utf-8`}),t.end(a)}catch{oh(t)}});r.listen(0,`127.0.0.1`,()=>{let n=r.address();if(typeof n!=`object`||!n){t(Error(`Failed to resolve local browser address`));return}X=r,s=`http://127.0.0.1:${n.port}`,e(s)})})}catch(t){return{content:[{type:`text`,text:`${e.title}\n\nUnable to start local browser transport.`}],structuredContent:n.settleError(`BROWSER_START_FAILED`,t instanceof Error?t.message:`Unable to start browser transport`),isError:!0}}let l=await $m(o);if(!th(t.actions)){let t=X;return t&&(n.promise.finally(()=>{X===t&&(t.close(),X=null)}),setTimeout(()=>{X===t&&(t.close(),X=null)},Jm)),{content:[{type:`text`,text:eh(e,o,`Rendered.`)}],structuredContent:{kind:`rendered`,reason:`no-response-required`}}}let u=await Promise.race([n.promise,new Promise(e=>{setTimeout(()=>{c||(ah(),e(n.settleError(`BROWSER_CONNECT_TIMEOUT`,l?`No browser client connected within ${Ym}ms.`:`Fell back to system browser, but no browser client connected within ${Ym}ms.`)))},Ym)}),new Promise(e=>{setTimeout(()=>e(n.settleTimeout(Jm)),Jm)})]),d=X;d&&setTimeout(()=>{X===d&&(d.close(),X=null)},Jm);let f=u.kind===`result`?`Selected action: ${u.result.actionId}`:u.kind===`timeout`?`Timed out after ${u.waitedMs}ms.`:u.kind===`cancelled`?`Cancelled: ${u.reason}.`:u.kind===`error`?`Error: ${u.error.message}`:`Rendered.`;return{content:[{type:`text`,text:eh(e,o,f)}],structuredContent:u,isError:u.kind===`error`}}const dh=`openai/outputTemplate`,fh=`ui/resourceUri`,ph={connectDomains:[],resourceDomains:[]},mh={connect_domains:[],resource_domains:[]};function hh(e){return{ui:{resourceUri:e,visibility:[`model`,`app`]},[fh]:e,[dh]:e,"openai/widgetAccessible":!0}}function gh(){return{ui:{prefersBorder:!1,csp:ph},"openai/widgetDescription":`AI Kit renders structured visual surfaces such as dashboards, charts, reports, and diagrams.`,"openai/widgetPrefersBorder":!1,"openai/widgetCSP":mh}}function _h(e){return{ui:{resourceUri:e},[fh]:e,[dh]:e}}function vh(e){return{...e,schemaVersion:1}}const yh=`ui://aikit/present.html`,bh=`Install AI Kit with <code>${Y(`npx -y @vpxa/aikit@latest init --user`)}</code>.`;let xh=``;function Sh(){return xh}function Ch(e){xh=e}function wh(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const Th=/\\u[0-9a-fA-F]{4}/,Eh=/^\s*\|(?:[^|\r\n]+\|){2,}\s*$/,Dh=/^\s*\|?(?:\s*:?-{3,}:?\s*\|){2,}\s*$/,Oh=/\b(cli|terminal|tty|console|command(?:-|\s)?line)\b/i;function kh(e){let t=[e.value,e.markdown,e.text,e.content];for(let e of t)if(typeof e==`string`&&e.trim().length>0)return e}function Ah(e){let t=e.split(/\r?\n/);for(let e=0;e<t.length-1;e+=1)if(Eh.test(t[e])&&Dh.test(t[e+1]))return!0;return!1}function jh(e){let t=e.trim().split(`|`),n=+(t[0]?.trim()===``),r=t.at(-1)?.trim()===``?t.length-1:t.length;return t.slice(n,r).map(e=>e.trim())}function Mh(e,t){if(t<2)return!1;let n=e.trim();return n.startsWith(`|`)?jh(n).length===t:!1}function Nh(e){let t=e.split(/\r?\n/),n=[],r=[],i=()=>{r.length!==0&&(n.push({type:`text`,content:r.join(`
2910
- `)}),r.length=0)},a=0;for(;a<t.length;){let e=t[a],o=t[a+1];if(o!==void 0&&Eh.test(e)&&Dh.test(o)){let r=jh(e),o=[];i();let s=a+2;for(;s<t.length&&Mh(t[s],r.length);)o.push(jh(t[s])),s+=1;n.push({type:`table`,headers:r,rows:o}),a=s;continue}r.push(e),a+=1}return i(),n}function Ph(e){let t=kh(e);return!t||!Ah(t)?[e]:Nh(t).flatMap(e=>{if(e.type===`text`){let t=e.content.trim();return t.length>0?[{type:`markdown`,value:t}]:[]}return[{type:`table`,value:{headers:e.headers,rows:e.rows}}]})}function Fh(e){if(typeof e==`string`)return Oh.test(e);if(Array.isArray(e))return e.some(e=>Fh(e));if(!wh(e))return!1;let t=[`client`,`clientInfo`,`host`,`source`,`mode`,`name`,`title`,`channel`];return Object.entries(e).some(([e,n])=>t.includes(e)?Fh(n):!1)}function Ih(e,t){return{preferBrowser:[t,e._meta,wh(e.metadata)?e.metadata.source:void 0].some(e=>Fh(e))}}function Lh(e){if(!e.template)return!0;let t=pm(e.template);return t?t.supportedTransports.includes(`browser`):Bm(e)?.supportedTransports.includes(`browser`)??!1}function Rh(e,t,n={}){let r=n.includeSurfaceHeader??!0,i=r?[e.title]:[];return r&&e.description&&i.push(e.description),kr(t)?i.push(``,`Selected action: ${t.result.actionId}`):Or(t)?i.push(``,`Error: ${t.error.message}`):t.kind===`timeout`?i.push(``,`Timed out after ${t.waitedMs}ms.`):t.kind===`cancelled`?i.push(``,`Cancelled: ${t.reason}.`):r||i.push(`Rendered inline.`),i.join(`
2911
- `)}const zh={id:`__dismiss`,type:`button`,label:`Done`,variant:`default`};function Bh(e){if((e.actions?.length??0)>0||!e.template)return e;let t=Bm(e);return t?.supportedTransports.includes(`browser`)===!0&&!t.supportedTransports.includes(`mcp-app`)?{...e,actions:[zh]}:e}function Vh(e){return e.replace(`</head>`,`<style>
2908
+ `)],islands:[],payload:void 0,nonce:``,generatedAt:new Date().toISOString(),colorScheme:e.colorScheme,lang:e.lang,dir:e.dir,transport:`browser`,exportPolicy:`local-interactive`,footerContentHtml:lm}),i=``;try{oh(),i=await new Promise((e,t)=>{let a=Nr((e,t)=>{try{if(e.url?.startsWith(`/__aikit_screenshot.png`)){lh(t,i);return}if(e.url===`/viewer`){t.writeHead(200,{"Content-Type":`text/html; charset=utf-8`}),t.end(n);return}t.writeHead(200,{"Content-Type":`text/html; charset=utf-8`}),t.end(r)}catch{sh(t)}});a.listen(0,`127.0.0.1`,()=>{let n=a.address();if(typeof n!=`object`||!n){t(Error(`Failed to resolve local browser address`));return}X=a,e(`http://127.0.0.1:${n.port}`)})})}catch(t){return{content:[{type:`text`,text:`${e.title}\n\nUnable to start local browser transport.`}],structuredContent:{kind:`error`,error:{code:`BROWSER_START_FAILED`,message:t instanceof Error?t.message:`Unable to start browser transport`}},isError:!0}}await eh(i);let a=X;return a&&setTimeout(()=>{X===a&&(a.close(),X=null)},Ym),{content:[{type:`text`,text:th(e,i,`Rendered.`)}],structuredContent:{kind:`rendered`,reason:`no-response-required`}}}async function dh(e){Ch(`<html><body style="font-family:system-ui;padding:2rem;color:#888;text-align:center"><p>Content opened in browser window.</p></body></html>`);let t=Mr(e,{transport:`browser`,registry:Bm,blockVendorScripts:Yp()}),n=cm(t.surfaceId,t.actions),r=qm(t.vendorScripts,`browser`),i=Jm(),a=wr({title:e.title,subtitle:e.description,html:[t.html,Qm(t.actions,n.nonce)].filter(Boolean).join(`
2909
+ `),css:t.css,islands:t.islands,payload:t.payload,nonce:t.nonce,generatedAt:new Date().toISOString(),colorScheme:e.colorScheme,lang:e.lang,dir:e.dir,transport:`browser`,exportPolicy:t.exportPolicy,footerContentHtml:lm,headScripts:r}),o=``,s=``,c=!1;try{let e=X;e&&(e.close(),X=null),o=await new Promise((e,t)=>{let r=Nr((e,t)=>{try{if(c=!0,e.method===`OPTIONS`){t.writeHead(204,{"Access-Control-Allow-Origin":s||`*`,"Access-Control-Allow-Methods":`POST`,"Access-Control-Allow-Headers":`Content-Type`}),t.end();return}if(e.method===`POST`&&e.url===`/callback`){n.handle(e,t,s).catch(()=>{sh(t)});return}if(e.url?.startsWith(`/__aikit_screenshot.png`)){lh(t,o||s);return}let r=i.find(t=>e.url===t.route);if(r){let e=r.getSource();if(e){t.writeHead(200,{"Content-Type":`application/javascript; charset=utf-8`,"Cache-Control":`public, max-age=86400`}),t.end(e);return}t.writeHead(302,{Location:r.cdn}),t.end();return}let l=ih(e.url);if(l)try{let e=N(l,`utf8`);t.writeHead(200,{"Content-Type":`application/javascript; charset=utf-8`}),t.end(e);return}catch{}t.writeHead(200,{"Content-Type":`text/html; charset=utf-8`}),t.end(a)}catch{sh(t)}});r.listen(0,`127.0.0.1`,()=>{let n=r.address();if(typeof n!=`object`||!n){t(Error(`Failed to resolve local browser address`));return}X=r,s=`http://127.0.0.1:${n.port}`,e(s)})})}catch(t){return{content:[{type:`text`,text:`${e.title}\n\nUnable to start local browser transport.`}],structuredContent:n.settleError(`BROWSER_START_FAILED`,t instanceof Error?t.message:`Unable to start browser transport`),isError:!0}}let l=await eh(o);if(!nh(t.actions)){let t=X;return t&&(n.promise.finally(()=>{X===t&&(t.close(),X=null)}),setTimeout(()=>{X===t&&(t.close(),X=null)},Ym)),{content:[{type:`text`,text:th(e,o,`Rendered.`)}],structuredContent:{kind:`rendered`,reason:`no-response-required`}}}let u=await Promise.race([n.promise,new Promise(e=>{setTimeout(()=>{c||(oh(),e(n.settleError(`BROWSER_CONNECT_TIMEOUT`,l?`No browser client connected within ${Xm}ms.`:`Fell back to system browser, but no browser client connected within ${Xm}ms.`)))},Xm)}),new Promise(e=>{setTimeout(()=>e(n.settleTimeout(Ym)),Ym)})]),d=X;d&&setTimeout(()=>{X===d&&(d.close(),X=null)},Ym);let f=u.kind===`result`?`Selected action: ${u.result.actionId}`:u.kind===`timeout`?`Timed out after ${u.waitedMs}ms.`:u.kind===`cancelled`?`Cancelled: ${u.reason}.`:u.kind===`error`?`Error: ${u.error.message}`:`Rendered.`;return{content:[{type:`text`,text:th(e,o,f)}],structuredContent:u,isError:u.kind===`error`}}const fh=`openai/outputTemplate`,ph=`ui/resourceUri`,mh={connectDomains:[],resourceDomains:[]},hh={connect_domains:[],resource_domains:[]};function gh(e){return{ui:{resourceUri:e,visibility:[`model`,`app`]},[ph]:e,[fh]:e,"openai/widgetAccessible":!0}}function _h(){return{ui:{prefersBorder:!1,csp:mh},"openai/widgetDescription":`AI Kit renders structured visual surfaces such as dashboards, charts, reports, and diagrams.`,"openai/widgetPrefersBorder":!1,"openai/widgetCSP":hh}}function vh(e){return{ui:{resourceUri:e},[ph]:e,[fh]:e}}function yh(e){return{...e,schemaVersion:1}}const bh=`ui://aikit/present.html`;let xh=``;function Sh(){return xh}function Ch(e){xh=e}function wh(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const Th=/\\u[0-9a-fA-F]{4}/,Eh=/^\s*\|(?:[^|\r\n]+\|){2,}\s*$/,Dh=/^\s*\|?(?:\s*:?-{3,}:?\s*\|){2,}\s*$/,Oh=/\b(cli|terminal|tty|console|command(?:-|\s)?line)\b/i;function kh(e){let t=[e.value,e.markdown,e.text,e.content];for(let e of t)if(typeof e==`string`&&e.trim().length>0)return e}function Ah(e){let t=e.split(/\r?\n/);for(let e=0;e<t.length-1;e+=1)if(Eh.test(t[e])&&Dh.test(t[e+1]))return!0;return!1}function jh(e){let t=e.trim().split(`|`),n=+(t[0]?.trim()===``),r=t.at(-1)?.trim()===``?t.length-1:t.length;return t.slice(n,r).map(e=>e.trim())}function Mh(e,t){if(t<2)return!1;let n=e.trim();return n.startsWith(`|`)?jh(n).length===t:!1}function Nh(e){let t=e.split(/\r?\n/),n=[],r=[],i=()=>{r.length!==0&&(n.push({type:`text`,content:r.join(`
2910
+ `)}),r.length=0)},a=0;for(;a<t.length;){let e=t[a],o=t[a+1];if(o!==void 0&&Eh.test(e)&&Dh.test(o)){let r=jh(e),o=[];i();let s=a+2;for(;s<t.length&&Mh(t[s],r.length);)o.push(jh(t[s])),s+=1;n.push({type:`table`,headers:r,rows:o}),a=s;continue}r.push(e),a+=1}return i(),n}function Ph(e){let t=kh(e);return!t||!Ah(t)?[e]:Nh(t).flatMap(e=>{if(e.type===`text`){let t=e.content.trim();return t.length>0?[{type:`markdown`,value:t}]:[]}return[{type:`table`,value:{headers:e.headers,rows:e.rows}}]})}function Fh(e){if(typeof e==`string`)return Oh.test(e);if(Array.isArray(e))return e.some(e=>Fh(e));if(!wh(e))return!1;let t=[`client`,`clientInfo`,`host`,`source`,`mode`,`name`,`title`,`channel`];return Object.entries(e).some(([e,n])=>t.includes(e)?Fh(n):!1)}function Ih(e,t){return{preferBrowser:[t,e._meta,wh(e.metadata)?e.metadata.source:void 0].some(e=>Fh(e))}}function Lh(e){if(!e.template)return!0;let t=mm(e.template);return t?t.supportedTransports.includes(`browser`):Vm(e)?.supportedTransports.includes(`browser`)??!1}function Rh(e,t,n={}){let r=n.includeSurfaceHeader??!0,i=r?[e.title]:[];return r&&e.description&&i.push(e.description),kr(t)?i.push(``,`Selected action: ${t.result.actionId}`):Or(t)?i.push(``,`Error: ${t.error.message}`):t.kind===`timeout`?i.push(``,`Timed out after ${t.waitedMs}ms.`):t.kind===`cancelled`?i.push(``,`Cancelled: ${t.reason}.`):r||i.push(`Rendered inline.`),i.join(`
2911
+ `)}const zh={id:`__dismiss`,type:`button`,label:`Done`,variant:`default`};function Bh(e){if((e.actions?.length??0)>0||!e.template)return e;let t=Vm(e);return t?.supportedTransports.includes(`browser`)===!0&&!t.supportedTransports.includes(`mcp-app`)?{...e,actions:[zh]}:e}function Vh(e){return e.replace(`</head>`,`<style>
2912
2912
  .toolbar, .badge, body > header, body > footer { display: none !important; }
2913
2913
  body { padding-top: 0 !important; margin-top: 0 !important; }
2914
2914
  </style>
@@ -2942,8 +2942,8 @@ window.addEventListener('message', function(e) {
2942
2942
  else{setInterval(notify,500)}
2943
2943
  })();
2944
2944
  <\/script>`;return e.includes(`</body>`)?e.replace(`</body>`,`${t}</body>`):`${e}${t}`}function Uh(e,t){return[`<!DOCTYPE html>`,`<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">`,`<title>Error — ${Y(e)}</title>`,`<style>`,` * { box-sizing: border-box; margin: 0; padding: 0; }`,` body { font-family: system-ui, -apple-system, sans-serif; min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 2rem; background: #fafafa; color: #333; }`,` .error-card { max-width: 560px; width: 100%; padding: 2.5rem; border-radius: 1rem; background: #fff; border: 1px solid #e5e7eb; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }`,` .error-badge { display: inline-block; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: #dc2626; background: #fef2f2; border: 1px solid #fecaca; border-radius: 0.375rem; padding: 0.25rem 0.625rem; margin-bottom: 1rem; }`,` .error-title { font-size: 1.25rem; font-weight: 600; margin-bottom: 0.75rem; color: #111; }`,` .error-message { font-size: 0.875rem; line-height: 1.6; color: #6b7280; white-space: pre-wrap; word-break: break-word; }`,`</style></head><body>`,`<div class="error-card">`,` <span class="error-badge">Render Error</span>`,` <h1 class="error-title">${Y(e)}</h1>`,` <p class="error-message">${Y(t)}</p>`,`</div>`,`</body></html>`].join(`
2945
- `)}function Wh(e,t,n,r){return Ch(Uh(r??`Present`,t)),{content:[{type:`text`,text:`[ERROR:VALIDATION] ${t}`}],isError:!0}}function Gh(e,t){if(!wh(e)||!(`schemaVersion`in e))return{ok:!1,response:Wh(`INVALID_CHANNEL_SURFACE`,`present expects a ChannelSurface object with schemaVersion: 1`)};if(e.schemaVersion!==1)return{ok:!1,response:Wh(`UNSUPPORTED_SCHEMA_VERSION`,`Unsupported ChannelSurface schemaVersion: ${String(e.schemaVersion)}`)};if(typeof e.title==`string`&&Th.test(e.title))return{ok:!1,response:Wh(`TITLE_UNICODE_ESCAPE_NOT_ALLOWED`,`Use actual Unicode characters in title, not escape sequences.`)};let n=Array.isArray(e.blocks)?{...e,blocks:e.blocks.flatMap(e=>{if(!wh(e)||e.type!==`markdown`)return[e];let t=kh(e);return!t||!Ah(t)?[e]:Ph(e)})}:e;return{ok:!0,surface:n,options:Ih(n,t)}}async function Kh(e,t={}){let n=Bh(e);if(e.template){let r=pm(e.template);if(r)return await qh(n,r,t)}return Vm(n)||t.preferBrowser&&Lh(n)?await uh(n):Jh(n)}async function qh(e,t,n={}){if(e.data!=null&&t.inputSchema){let n=ln({data:e.data,schema:t.inputSchema});if(!n.valid){let r=n.errors.map(e=>` ${e.path}: ${e.message}${e.expected?` (expected: ${e.expected}, got: ${e.received})`:``}`).join(`
2946
- `);return Wh(`VIEWER_DATA_INVALID`,`Template "${t.id}" data validation failed:\n${r}\n\nExpected schema: ${JSON.stringify(t.inputSchema,null,2)}`,void 0,e.title)}}let r=t.supportedTransports.includes(`browser`),i=t.supportedTransports.includes(`mcp-app`);if(n.preferBrowser&&r||r&&!i)return await lh(e,t);if(!i)return Wh(`VIEWER_TRANSPORT_UNSUPPORTED`,`Viewer template "${t.id}" does not support an available transport`,void 0,e.title);try{let n=Vh(gm(t.resolveHtml(),e.data??null,t.injectId,t.transformData)).replace(/&/g,`&amp;`).replace(/"/g,`&quot;`);return Ch(Hh(wr({title:e.title,subtitle:e.description,html:[`<div class="present-viewer-container">`,` <iframe class="present-viewer-iframe" srcdoc="${n}" sandbox="allow-scripts allow-same-origin"></iframe>`,` <script>
2945
+ `)}function Wh(e,t,n,r){return Ch(Uh(r??`Present`,t)),{content:[{type:`text`,text:`[ERROR:VALIDATION] ${t}`}],isError:!0}}function Gh(e,t){if(!wh(e)||!(`schemaVersion`in e))return{ok:!1,response:Wh(`INVALID_CHANNEL_SURFACE`,`present expects a ChannelSurface object with schemaVersion: 1`)};if(e.schemaVersion!==1)return{ok:!1,response:Wh(`UNSUPPORTED_SCHEMA_VERSION`,`Unsupported ChannelSurface schemaVersion: ${String(e.schemaVersion)}`)};if(typeof e.title==`string`&&Th.test(e.title))return{ok:!1,response:Wh(`TITLE_UNICODE_ESCAPE_NOT_ALLOWED`,`Use actual Unicode characters in title, not escape sequences.`)};let n=Array.isArray(e.blocks)?{...e,blocks:e.blocks.flatMap(e=>{if(!wh(e)||e.type!==`markdown`)return[e];let t=kh(e);return!t||!Ah(t)?[e]:Ph(e)})}:e;return{ok:!0,surface:n,options:Ih(n,t)}}async function Kh(e,t={}){let n=Bh(e);if(e.template){let r=mm(e.template);if(r)return await qh(n,r,t)}return Hm(n)||t.preferBrowser&&Lh(n)?await dh(n):Jh(n)}async function qh(e,t,n={}){if(e.data!=null&&t.inputSchema){let n=ln({data:e.data,schema:t.inputSchema});if(!n.valid){let r=n.errors.map(e=>` ${e.path}: ${e.message}${e.expected?` (expected: ${e.expected}, got: ${e.received})`:``}`).join(`
2946
+ `);return Wh(`VIEWER_DATA_INVALID`,`Template "${t.id}" data validation failed:\n${r}\n\nExpected schema: ${JSON.stringify(t.inputSchema,null,2)}`,void 0,e.title)}}let r=t.supportedTransports.includes(`browser`),i=t.supportedTransports.includes(`mcp-app`);if(n.preferBrowser&&r||r&&!i)return await uh(e,t);if(!i)return Wh(`VIEWER_TRANSPORT_UNSUPPORTED`,`Viewer template "${t.id}" does not support an available transport`,void 0,e.title);try{let n=Vh(_m(t.resolveHtml(),e.data??null,t.injectId,t.transformData)).replace(/&/g,`&amp;`).replace(/"/g,`&quot;`);return Ch(Hh(wr({title:e.title,subtitle:e.description,html:[`<div class="present-viewer-container">`,` <iframe class="present-viewer-iframe" srcdoc="${n}" sandbox="allow-scripts allow-same-origin"></iframe>`,` <script>
2947
2947
  (function() {
2948
2948
  const iframe = document.querySelector('.present-viewer-iframe');
2949
2949
  if (!iframe) return;
@@ -2966,8 +2966,8 @@ window.addEventListener('message', function(e) {
2966
2966
  });
2967
2967
  <\/script>`,`</div>`].join(`
2968
2968
  `),css:[[`.present-viewer-container {`,` flex: 1;`,` min-height: 640px;`,` position: relative;`,` border-radius: 0.75rem;`,` overflow: hidden;`,` border: none;`,`}`,`.present-viewer-iframe {`,` border: none;`,` width: 100%;`,` height: 100%;`,` position: absolute;`,` inset: 0;`,` border-radius: inherit;`,`}`].join(`
2969
- `)],islands:[],payload:void 0,nonce:``,generatedAt:new Date().toISOString(),footerContentHtml:bh,colorScheme:e.colorScheme,lang:e.lang,dir:e.dir,transport:`mcp-app`,exportPolicy:`local-interactive`}))),{content:[{type:`text`,text:Rh(e,{kind:`rendered`,reason:`no-response-required`},{includeSurfaceHeader:!1})}],structuredContent:vh(e),_meta:_h(yh),ui:{type:`resource`,uri:yh}}}catch(t){return Wh(`VIEWER_RENDER_FAILED`,t instanceof Error?t.message:`Failed to render viewer template`,void 0,e.title)}}function Jh(e){try{let t=Mr(e,{transport:`mcp-app`,registry:zm,blockVendorScripts:Yp()}),n=Km(t.vendorScripts,`mcp-app`);return xh=Hh(wr({title:e.title,subtitle:e.description,html:t.html,css:t.css,islands:t.islands,payload:t.payload,nonce:t.nonce,colorScheme:e.colorScheme,lang:e.lang,dir:e.dir,transport:`mcp-app`,exportPolicy:t.exportPolicy,footerContentHtml:bh,headScripts:n})),{content:[{type:`text`,text:Rh(e,{kind:`rendered`,reason:`no-response-required`},{includeSurfaceHeader:!1})}],structuredContent:vh(e),_meta:_h(yh),ui:{type:`resource`,uri:yh}}}catch(t){return Wh(`RENDER_FAILED`,t instanceof Error?t.message:`Failed to render ChannelSurface`,void 0,e.title)}}const Yh=z.object({label:z.string(),value:z.string(),description:z.string().optional()}),Xh=z.object({id:z.string().describe(`Unique action identifier`),type:z.enum([`button`,`select`,`multi-select`,`form-submit`,`text-submit`,`confirm`,`custom`]).describe(`Interactive action type`),label:z.string().describe(`Visible action label`),variant:z.enum([`primary`,`danger`,`default`]).optional(),options:z.array(Yh).optional(),schema:z.record(z.string(),z.unknown()).optional()}),Zh=z.object({type:z.string(),title:z.string().optional(),value:z.unknown().optional(),language:z.string().optional()}).catchall(z.unknown()),Qh={schemaVersion:z.literal(1).describe(`ChannelSurface schema version. Must be 1.`),title:z.string().describe(`Surface title shown to the user.`),description:z.string().optional().describe(`Optional supporting copy for the surface.`),template:z.string().optional().describe(`Optional template id such as report@1.`),layout:z.object({maxWidth:z.string().optional(),padding:z.string().optional(),columns:z.number().optional()}).optional(),blocks:z.array(Zh).optional().describe(`Typed block content for the surface.`),data:z.unknown().optional().describe(`Template data payload, if the template expands data.`),actions:z.array(Xh).optional().describe(`Interactive actions. Presence triggers browser transport.`),response:z.object({timeout:z.number().optional(),required:z.boolean().optional()}).optional(),metadata:z.object({surfaceId:z.string().optional(),createdAt:z.string().optional(),source:z.string().optional()}).optional(),colorScheme:z.enum([`light`,`dark`,`auto`]).optional(),lang:z.string().optional(),dir:z.enum([`ltr`,`rtl`,`auto`]).optional()};z.object({surfaceId:z.string(),actionId:z.string(),actionType:z.enum([`button`,`select`,`multi-select`,`form-submit`,`text-submit`,`confirm`,`custom`]),value:z.unknown().optional(),formData:z.record(z.string(),z.unknown()).optional(),selection:z.union([z.string(),z.array(z.string())]).optional(),label:z.string().optional(),timestamp:z.string(),sourceTransport:z.enum([`mcp-app`,`browser`,`export`])});function $h(e){let t=e.server?.getClientCapabilities?.();if(!t)return`unknown`;let n=fr(t);return!n||Array.isArray(n.mimeTypes)&&n.mimeTypes.length>0&&!n.mimeTypes.includes(dr)?`unsupported`:`supported`}function eg(e,t){let n=W(`present`),r=[`Render a ChannelSurface for the user.`,`Quick ref:`,`- Full schema: aikit://schemas/channel-surface`,`- Required: schemaVersion: 1, title`,`- Content: blocks[] for direct rendering, or template + data for registry-backed rendering`,`- Actions: actions[] of SurfaceAction; interactive surfaces use browser transport and return ChannelOutcome`,`- Optional fields: description, layout, response, metadata, colorScheme, lang, dir`,`- Transports: mcp-app, browser, export`,`- Use schema resource for block enums and action details.`].join(`
2970
- `);mr(e,`present`,{title:n.title,description:r,inputSchema:Qh,annotations:n.annotations,_meta:hh(yh)},J(`present`,async(t,n)=>{let r=Gh(t,n);if(!r.ok)return r.response;let i=$h(e);return await Kh(r.surface,{...r.options,preferBrowser:r.options.preferBrowser||i===`unsupported`})}));try{pr(e,`Present View`,yh,{description:`AI Kit present tool viewer`,_meta:gh()},async()=>({contents:[{uri:yh,mimeType:dr,_meta:gh(),text:Sh()||`<html><body><p>No content generated yet. Call the present tool first.</p></body></html>`}]}))}catch{}try{e.registerResource(`present-templates`,`aikit://present/templates`,{description:`List all registered present viewer templates with their input schemas`},async()=>{let e=hm().map(e=>({id:e.id,label:e.label,description:e.description,transports:e.supportedTransports,inputSchema:e.inputSchema}));return{contents:[{uri:`aikit://present/templates`,mimeType:`application/json`,text:JSON.stringify(e,null,2)}]}})}catch{}}const tg=I(`tools`);function ng(e,t){let n=new Qn({structure:new er,dependencies:new Yn,symbols:new tr,patterns:new $n,entryPoints:new Zn,diagrams:new Xn}),r=W(`produce_knowledge`);e.registerTool(`produce_knowledge`,{title:r.title,description:`Run automated codebase analysis and produce synthesis instructions. Executes Tier 1 deterministic analyzers, then returns structured baselines and instructions for you to synthesize knowledge using remember.`,inputSchema:{scope:z.string().optional().describe(`Root path to analyze (defaults to workspace root)`),aspects:z.array(z.enum([`all`,`structure`,`dependencies`,`symbols`,`patterns`,`entry-points`,`diagrams`])).default([`all`]).describe(`Which analysis aspects to run`)},annotations:r.annotations},J(`produce_knowledge`,async({scope:e,aspects:r},i)=>{let a;try{a=zc(i).createTask(`Produce Knowledge`,3),a.progress(0,`Running analyzers`);let o=e??`.`;tg.info(`Running knowledge production`,{rootPath:o,aspects:r});let s=await n.runExtraction(o,r);try{let e=t?.onboardDir??``;if(!e)throw tg.warn(`onboardDir not configured — skipping artifact persistence.`),Error(`skip`);M(e,{recursive:!0});let n=`<!-- Generated by produce_knowledge at ${new Date().toISOString()} -->\n\n`;for(let[t,r]of Object.entries(s))r&&typeof r==`string`&&me(P(e,`${t}.md`),n+r,`utf-8`);tg.info(`Knowledge persisted to .ai/context/`,{files:Object.keys(s).length})}catch(e){tg.warn(`Failed to persist knowledge to .ai/context/`,{error:L(e)})}a.progress(1,`Synthesizing results`);let c=n.buildSynthesisInstructions(s,r);return a.complete(`Knowledge production complete`),{content:[{type:`text`,text:c+`
2969
+ `)],islands:[],payload:void 0,nonce:``,generatedAt:new Date().toISOString(),footerContentHtml:lm,colorScheme:e.colorScheme,lang:e.lang,dir:e.dir,transport:`mcp-app`,exportPolicy:`local-interactive`}))),{content:[{type:`text`,text:Rh(e,{kind:`rendered`,reason:`no-response-required`},{includeSurfaceHeader:!1})}],structuredContent:yh(e),_meta:vh(bh),ui:{type:`resource`,uri:bh}}}catch(t){return Wh(`VIEWER_RENDER_FAILED`,t instanceof Error?t.message:`Failed to render viewer template`,void 0,e.title)}}function Jh(e){try{let t=Mr(e,{transport:`mcp-app`,registry:Bm,blockVendorScripts:Yp()}),n=qm(t.vendorScripts,`mcp-app`);return xh=Hh(wr({title:e.title,subtitle:e.description,html:t.html,css:t.css,islands:t.islands,payload:t.payload,nonce:t.nonce,colorScheme:e.colorScheme,lang:e.lang,dir:e.dir,transport:`mcp-app`,exportPolicy:t.exportPolicy,footerContentHtml:lm,headScripts:n})),{content:[{type:`text`,text:Rh(e,{kind:`rendered`,reason:`no-response-required`},{includeSurfaceHeader:!1})}],structuredContent:yh(e),_meta:vh(bh),ui:{type:`resource`,uri:bh}}}catch(t){return Wh(`RENDER_FAILED`,t instanceof Error?t.message:`Failed to render ChannelSurface`,void 0,e.title)}}const Yh=z.object({label:z.string(),value:z.string(),description:z.string().optional()}),Xh=z.object({id:z.string().describe(`Unique action identifier`),type:z.enum([`button`,`select`,`multi-select`,`form-submit`,`text-submit`,`confirm`,`custom`]).describe(`Interactive action type`),label:z.string().describe(`Visible action label`),variant:z.enum([`primary`,`danger`,`default`]).optional(),options:z.array(Yh).optional(),schema:z.record(z.string(),z.unknown()).optional()}),Zh=z.object({type:z.string(),title:z.string().optional(),value:z.unknown().optional(),language:z.string().optional()}).catchall(z.unknown()),Qh={schemaVersion:z.literal(1).describe(`ChannelSurface schema version. Must be 1.`),title:z.string().describe(`Surface title shown to the user.`),description:z.string().optional().describe(`Optional supporting copy for the surface.`),template:z.string().optional().describe(`Optional template id such as report@1.`),layout:z.object({maxWidth:z.string().optional(),padding:z.string().optional(),columns:z.number().optional()}).optional(),blocks:z.array(Zh).optional().describe(`Typed block content for the surface.`),data:z.unknown().optional().describe(`Template data payload, if the template expands data.`),actions:z.array(Xh).optional().describe(`Interactive actions. Presence triggers browser transport.`),response:z.object({timeout:z.number().optional(),required:z.boolean().optional()}).optional(),metadata:z.object({surfaceId:z.string().optional(),createdAt:z.string().optional(),source:z.string().optional()}).optional(),colorScheme:z.enum([`light`,`dark`,`auto`]).optional(),lang:z.string().optional(),dir:z.enum([`ltr`,`rtl`,`auto`]).optional()};z.object({surfaceId:z.string(),actionId:z.string(),actionType:z.enum([`button`,`select`,`multi-select`,`form-submit`,`text-submit`,`confirm`,`custom`]),value:z.unknown().optional(),formData:z.record(z.string(),z.unknown()).optional(),selection:z.union([z.string(),z.array(z.string())]).optional(),label:z.string().optional(),timestamp:z.string(),sourceTransport:z.enum([`mcp-app`,`browser`,`export`])});function $h(e){let t=e.server?.getClientCapabilities?.();if(!t)return`unknown`;let n=fr(t);return!n||Array.isArray(n.mimeTypes)&&n.mimeTypes.length>0&&!n.mimeTypes.includes(dr)?`unsupported`:`supported`}function eg(e,t){let n=W(`present`),r=[`Render a ChannelSurface for the user.`,`Quick ref:`,`- Full schema: aikit://schemas/channel-surface`,`- Required: schemaVersion: 1, title`,`- Content: blocks[] for direct rendering, or template + data for registry-backed rendering`,`- Actions: actions[] of SurfaceAction; interactive surfaces use browser transport and return ChannelOutcome`,`- Optional fields: description, layout, response, metadata, colorScheme, lang, dir`,`- Transports: mcp-app, browser, export`,`- Use schema resource for block enums and action details.`].join(`
2970
+ `);mr(e,`present`,{title:n.title,description:r,inputSchema:Qh,annotations:n.annotations,_meta:gh(bh)},J(`present`,async(t,n)=>{let r=Gh(t,n);if(!r.ok)return r.response;let i=$h(e);return await Kh(r.surface,{...r.options,preferBrowser:r.options.preferBrowser||i===`unsupported`})}));try{pr(e,`Present View`,bh,{description:`AI Kit present tool viewer`,_meta:_h()},async()=>({contents:[{uri:bh,mimeType:dr,_meta:_h(),text:Sh()||`<html><body><p>No content generated yet. Call the present tool first.</p></body></html>`}]}))}catch{}try{e.registerResource(`present-templates`,`aikit://present/templates`,{description:`List all registered present viewer templates with their input schemas`},async()=>{let e=gm().map(e=>({id:e.id,label:e.label,description:e.description,transports:e.supportedTransports,inputSchema:e.inputSchema}));return{contents:[{uri:`aikit://present/templates`,mimeType:`application/json`,text:JSON.stringify(e,null,2)}]}})}catch{}}const tg=I(`tools`);function ng(e,t){let n=new Qn({structure:new er,dependencies:new Yn,symbols:new tr,patterns:new $n,entryPoints:new Zn,diagrams:new Xn}),r=W(`produce_knowledge`);e.registerTool(`produce_knowledge`,{title:r.title,description:`Run automated codebase analysis and produce synthesis instructions. Executes Tier 1 deterministic analyzers, then returns structured baselines and instructions for you to synthesize knowledge using remember.`,inputSchema:{scope:z.string().optional().describe(`Root path to analyze (defaults to workspace root)`),aspects:z.array(z.enum([`all`,`structure`,`dependencies`,`symbols`,`patterns`,`entry-points`,`diagrams`])).default([`all`]).describe(`Which analysis aspects to run`)},annotations:r.annotations},J(`produce_knowledge`,async({scope:e,aspects:r},i)=>{let a;try{a=zc(i).createTask(`Produce Knowledge`,3),a.progress(0,`Running analyzers`);let o=e??`.`;tg.info(`Running knowledge production`,{rootPath:o,aspects:r});let s=await n.runExtraction(o,r);try{let e=t?.onboardDir??``;if(!e)throw tg.warn(`onboardDir not configured — skipping artifact persistence.`),Error(`skip`);M(e,{recursive:!0});let n=`<!-- Generated by produce_knowledge at ${new Date().toISOString()} -->\n\n`;for(let[t,r]of Object.entries(s))r&&typeof r==`string`&&me(P(e,`${t}.md`),n+r,`utf-8`);tg.info(`Knowledge persisted to .ai/context/`,{files:Object.keys(s).length})}catch(e){tg.warn(`Failed to persist knowledge to .ai/context/`,{error:L(e)})}a.progress(1,`Synthesizing results`);let c=n.buildSynthesisInstructions(s,r);return a.complete(`Knowledge production complete`),{content:[{type:`text`,text:c+`
2971
2971
 
2972
2972
  ---
2973
2973
  _Next: Review the baselines above and use \`remember\` to store synthesized knowledge entries._`}]}}catch(e){return a?.fail?.(`Production failed`),tg.error(`Knowledge production failed`,L(e)),q(`INTERNAL`,`Knowledge production failed: ${e instanceof Error?e.message:String(e)}`)}}))}const rg=I(`tools`);function ig(e,t,n,r,i,a,o){let s=W(`reindex`);e.registerTool(`reindex`,{title:s.title,description:`Trigger re-indexing of the AI Kit index. Can do incremental (only changed files) or full re-index. When smart indexing is active, use force: true to override the automatic trickle indexer.`,inputSchema:{full:z.boolean().default(!1).describe(`If true, force full re-index ignoring file hashes`),force:z.boolean().default(!1).describe(`If true, override smart indexing guard and run reindex anyway`)},annotations:s.annotations},J(`reindex`,async({full:e,force:s},c)=>{try{if(t.isIndexing)return{content:[{type:`text`,text:`## Reindex Already in Progress