(()=>{const t="intelligence",c="KNOWLEDGE SUBSTRATE",i="REGISTRY/RETRIEVAL",r="MARKETING/PLATFORM-WIDE",l=new Set(["overview","ask","graph","vault","notebooklm","kb","audit"]),s=window.AAAS_LEAF_MAPPING||[{from:"ops",fromId:"prompts",id:"prompt-registry",label:"Prompt registry",kind:"opsPrompts",bucket:i},{from:"ops",fromId:"kb",id:"kb-editor",label:"KB editor",kind:"opsKb",bucket:i},{from:"ops",fromId:"kg",id:"kg",label:"Knowledge graph",kind:"opsKg",bucket:i},{from:"ops",fromId:"retrieval",id:"retrieval",label:"Retrieval sandbox",kind:"opsRetrieval",bucket:i},{from:"ops",fromId:"embeddings",id:"embeddings",label:"Embedding index",kind:"opsEmbeddings",bucket:i},{from:"ops",fromId:"context-viewer",id:"context-viewer",label:"Context viewer",kind:"opsContextViewer",bucket:i},{from:"marketing",fromId:"seo",id:"seo",label:"SEO",kind:"mktSeo",bucket:r,od:"OD-1"},{from:"marketing",fromId:"citations",id:"citations",label:"AI citations",kind:"mktCitations",bucket:r,od:"OD-1"},{from:"marketing",fromId:"changelog",id:"changelog",label:"Changelog",kind:"mktChangelog",bucket:r,od:"OD-1"}];window.AAAS_LEAF_MAPPING=s,window.AAAS_PARKED_LEAVES=window.AAAS_PARKED_LEAVES||[{source:"manifest:intelligence.prompts",label:"Prompts",reason:"no source Kind implemented yet \u2014 park, do not stub-mount"},{source:"manifest:intelligence.closeout",label:"Closeout",reason:"no source Kind implemented yet \u2014 park, do not stub-mount"}];function u(e){const n=window.KIND_REGISTRY;if(!(!n||typeof n!="object"||Object.keys(n).length===0)&&!n[e.kind])throw new Error(`[streams-aaas.patch] mapping row ${e.from}.${e.fromId} names Kind "${e.kind}" which is not in window.KIND_REGISTRY \u2014 a \xA73.13 leaf without a real Kind must stay PARKED (window.AAAS_PARKED_LEAVES), not force-mounted.`)}const f=new Set(["ops.prompts","ops.kb","ops.kg","ops.retrieval","ops.embeddings","ops.context-viewer","marketing.seo","marketing.citations","marketing.changelog"]);function w(e){if((e.to||t)!==t)return;const o=`${e.from}.${e.fromId}`;if(!f.has(o))throw new Error(`[streams-aaas.patch] mapping row ${o} is not grounded under AaaS in docs/ia/canvas-ia-manifest.json \u2014 a resolvable Kind is not enough; no force-mount of an ungrounded leaf (IA-containment).`)}function g(e,n){e.subPages.some(o=>o&&o.id===n.id)||e.subPages.push({id:n.id,label:n.label,kind:n.kind,bucket:n.bucket})}function b(e){const n=window.STREAMS[e.to||t];if(!n||!Array.isArray(n.subPages))return;const o=window.STREAMS[e.from];if(o&&Array.isArray(o.subPages)){const A=o.subPages.findIndex(m=>m&&m.id===e.fromId);A>=0&&o.subPages.splice(A,1)}g(n,e)}function a(e){const n=window.STREAMS[e];if(!(!n||!Array.isArray(n.subPages)||n.subPages.length>0)&&(delete window.STREAMS[e],Array.isArray(window.OPS_STREAMS))){const o=window.OPS_STREAMS.indexOf(e);o>=0&&window.OPS_STREAMS.splice(o,1)}}function d(){if(!window.STREAMS)return!1;const e=window.STREAMS[t];if(!e||!Array.isArray(e.subPages))return!1;for(const o of e.subPages)o&&!o.bucket&&l.has(o.id)&&(o.bucket=c);const n=Array.isArray(window.AAAS_LEAF_MAPPING)?window.AAAS_LEAF_MAPPING:s;for(const o of n)u(o),w(o),b(o);return a("ops"),a("marketing"),!0}window.__ensureAaasStream=d,d()||console.warn("[streams-aaas.patch] window.STREAMS not ready \u2014 will retry via window.__ensureAaasStream() after mount.")})();
