@rubytech/create-maxy-code 0.1.440 → 0.1.441
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.
- package/package.json +1 -1
- package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +28 -7
- package/payload/platform/plugins/cloudflare/skills/calendar-site/SKILL.md +15 -5
- package/payload/platform/plugins/cloudflare/skills/calendar-site/template/functions/api/calendar/free-busy.ts +152 -0
- package/payload/platform/plugins/cloudflare/skills/calendar-site/template/public/index.html +6 -3
- package/payload/platform/plugins/cloudflare/skills/calendar-site/template/schema.sql +11 -0
- package/payload/platform/plugins/docs/references/calendar-booking.md +1 -1
- package/payload/platform/plugins/docs/references/graph.md +19 -3
- package/payload/platform/plugins/docs/references/outlook-guide.md +7 -2
- package/payload/platform/plugins/outlook/.claude-plugin/plugin.json +1 -1
- package/payload/platform/plugins/outlook/PLUGIN.md +7 -3
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/account-register.test.js +100 -10
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/account-register.test.js.map +1 -1
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/mailbox-list.test.d.ts +2 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/mailbox-list.test.d.ts.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/mailbox-list.test.js +64 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/mailbox-list.test.js.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/mailbox-registry.test.d.ts +2 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/mailbox-registry.test.d.ts.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/mailbox-registry.test.js +193 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/mailbox-registry.test.js.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/token-store.test.js +58 -1
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/token-store.test.js.map +1 -1
- package/payload/platform/plugins/outlook/mcp/dist/auth/mailbox-registry.d.ts +81 -0
- package/payload/platform/plugins/outlook/mcp/dist/auth/mailbox-registry.d.ts.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/auth/mailbox-registry.js +171 -0
- package/payload/platform/plugins/outlook/mcp/dist/auth/mailbox-registry.js.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/auth/token-store.d.ts +16 -1
- package/payload/platform/plugins/outlook/mcp/dist/auth/token-store.d.ts.map +1 -1
- package/payload/platform/plugins/outlook/mcp/dist/auth/token-store.js +25 -3
- package/payload/platform/plugins/outlook/mcp/dist/auth/token-store.js.map +1 -1
- package/payload/platform/plugins/outlook/mcp/dist/index.js +118 -49
- package/payload/platform/plugins/outlook/mcp/dist/index.js.map +1 -1
- package/payload/platform/plugins/outlook/mcp/dist/lib/graph-client.js +1 -1
- package/payload/platform/plugins/outlook/mcp/dist/lib/graph-client.js.map +1 -1
- package/payload/platform/plugins/outlook/mcp/dist/tools/account-register.d.ts +8 -4
- package/payload/platform/plugins/outlook/mcp/dist/tools/account-register.d.ts.map +1 -1
- package/payload/platform/plugins/outlook/mcp/dist/tools/account-register.js +22 -3
- package/payload/platform/plugins/outlook/mcp/dist/tools/account-register.js.map +1 -1
- package/payload/platform/plugins/outlook/mcp/dist/tools/mailbox-list.d.ts +26 -0
- package/payload/platform/plugins/outlook/mcp/dist/tools/mailbox-list.d.ts.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/tools/mailbox-list.js +28 -0
- package/payload/platform/plugins/outlook/mcp/dist/tools/mailbox-list.js.map +1 -0
- package/payload/platform/plugins/outlook/references/auth.md +36 -8
- package/payload/platform/plugins/scheduling/mcp/dist/scripts/publish-availability.d.ts +27 -0
- package/payload/platform/plugins/scheduling/mcp/dist/scripts/publish-availability.d.ts.map +1 -0
- package/payload/platform/plugins/scheduling/mcp/dist/scripts/publish-availability.js +241 -0
- package/payload/platform/plugins/scheduling/mcp/dist/scripts/publish-availability.js.map +1 -0
- package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js +1 -0
- package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js.map +1 -1
- package/payload/platform/templates/specialists/agents/personal-assistant.md +1 -1
- package/payload/server/public/assets/{graph-NgQDY0Pb.js → graph-CboWM2_-.js} +1 -1
- package/payload/server/public/graph.html +1 -1
- package/payload/server/server.js +69 -0
|
@@ -48,4 +48,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
48
48
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var a,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||n.return==null||n.return()}finally{if(s)throw a}}}}function tE(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function nE(e){var t=function(){if(typeof Reflect>`u`||!sv||sv.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Boolean.prototype.valueOf.call(sv(Boolean,[],(function(){}))),!0}catch{return!1}}();return function(){var n,r=Vv(e);if(t){var i=Vv(this).constructor;n=sv(r,arguments,i)}else n=r.apply(this,arguments);return Rv(this,n)}}var rE=function(e){Lv(r,e);var n=nE(r);function r(e,i){var a;return t(this,r),Yu(W(a=n.call(this)),`_queue`,null),e&&!tm(e)&&(i=e,e=[]),a._options=i||{},a._data=new Cw,a.length=0,a._idProp=a._options.fieldId||`id`,e&&e.length&&a.add(e),a.setOptions(i),a}return Ju(r,[{key:`idProp`,get:function(){return this._idProp}},{key:`setOptions`,value:function(e){e&&e.queue!==void 0&&(!1===e.queue?this._queue&&=(this._queue.destroy(),null):(this._queue||=GT.extend(this,{replace:[`add`,`update`,`remove`]}),e.queue&&typeof e.queue==`object`&&this._queue.setOptions(e.queue)))}},{key:`add`,value:function(e,t){var n,r=this,i=[];if(tm(e)){var a=Wd(e).call(e,(function(e){return e[r._idProp]}));if(kw(a).call(a,(function(e){return r._data.has(e)})))throw Error(`A duplicate id was found in the parameter array.`);for(var o=0,s=e.length;o<s;o++)n=this._addItem(e[o]),i.push(n)}else{if(!e||typeof e!=`object`)throw Error(`Unknown dataType`);n=this._addItem(e),i.push(n)}return i.length&&this._trigger(`add`,{items:i},t),i}},{key:`update`,value:function(e,t){var n=this,r=[],i=[],a=[],o=[],s=this._idProp,c=function(e){var t=e[s];if(t!=null&&n._data.has(t)){var c=e,l=oh({},n._data.get(t)),u=n._updateItem(c);i.push(u),o.push(c),a.push(l)}else{var d=n._addItem(e);r.push(d)}};if(tm(e))for(var l=0,u=e.length;l<u;l++)e[l]&&typeof e[l]==`object`?c(e[l]):console.warn(`Ignoring input item, which is not an object at index `+l);else{if(!e||typeof e!=`object`)throw Error(`Unknown dataType`);c(e)}if(r.length&&this._trigger(`add`,{items:r},t),i.length){var d={items:i,oldData:a,data:o};this._trigger(`update`,d,t)}return Kp(r).call(r,i)}},{key:`updateOnly`,value:function(e,t){var n,r=this;tm(e)||(e=[e]);var i=Wd(n=Wd(e).call(e,(function(e){var t=r._data.get(e[r._idProp]);if(t==null)throw Error(`Updating non-existent items is not allowed.`);return{oldData:t,update:e}}))).call(n,(function(e){var t=e.oldData,n=e.update,i=t[r._idProp],a=function(e){for(var t,n=arguments.length,r=Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return L_.apply(void 0,Kp(t=[{},e]).call(t,r))}(t,n);return r._data.set(i,a),{id:i,oldData:t,updatedData:a}}));if(i.length){var a={items:Wd(i).call(i,(function(e){return e.id})),oldData:Wd(i).call(i,(function(e){return e.oldData})),data:Wd(i).call(i,(function(e){return e.updatedData}))};return this._trigger(`update`,a,t),a.items}return[]}},{key:`get`,value:function(e,t){var n=void 0,r=void 0,i=void 0;WT(e)?(n=e,i=t):tm(e)?(r=e,i=t):i=e;var a=i&&i.returnType===`Object`?`Object`:`Array`,o=i&&Rd(i),s=[],c=void 0,l=void 0,u=void 0;if(n!=null)(c=this._data.get(n))&&o&&!o(c)&&(c=void 0);else if(r!=null)for(var d=0,f=r.length;d<f;d++)(c=this._data.get(r[d]))==null||o&&!o(c)||s.push(c);else for(var p,m=0,h=(l=Bp(Lw(p=this._data).call(p))).length;m<h;m++)u=l[m],(c=this._data.get(u))==null||o&&!o(c)||s.push(c);if(i&&i.order&&n==null&&this._sort(s,i.order),i&&i.fields){var g=i.fields;if(n!=null&&c!=null)c=this._filterFields(c,g);else for(var _=0,v=s.length;_<v;_++)s[_]=this._filterFields(s[_],g)}if(a==`Object`){for(var y={},b=0,x=s.length;b<x;b++){var S=s[b];y[S[this._idProp]]=S}return y}return n==null?s:c??null}},{key:`getIds`,value:function(e){var t=this._data,n=e&&Rd(e),r=e&&e.order,i=Bp(Lw(t).call(t)),a=[];if(n)if(r){for(var o=[],s=0,c=i.length;s<c;s++){var l=i[s],u=this._data.get(l);u!=null&&n(u)&&o.push(u)}this._sort(o,r);for(var d=0,f=o.length;d<f;d++)a.push(o[d][this._idProp])}else for(var p=0,m=i.length;p<m;p++){var h=i[p],g=this._data.get(h);g!=null&&n(g)&&a.push(g[this._idProp])}else if(r){for(var _=[],v=0,y=i.length;v<y;v++){var b=i[v];_.push(t.get(b))}this._sort(_,r);for(var x=0,S=_.length;x<S;x++)a.push(_[x][this._idProp])}else for(var ee=0,C=i.length;ee<C;ee++){var te=i[ee],w=t.get(te);w!=null&&a.push(w[this._idProp])}return a}},{key:`getDataSet`,value:function(){return this}},{key:`forEach`,value:function(e,t){var n=t&&Rd(t),r=this._data,i=Bp(Lw(r).call(r));if(t&&t.order)for(var a=this.get(t),o=0,s=a.length;o<s;o++){var c=a[o];e(c,c[this._idProp])}else for(var l=0,u=i.length;l<u;l++){var d=i[l],f=this._data.get(d);f==null||n&&!n(f)||e(f,d)}}},{key:`map`,value:function(e,t){for(var n=t&&Rd(t),r=[],i=this._data,a=Bp(Lw(i).call(i)),o=0,s=a.length;o<s;o++){var c=a[o],l=this._data.get(c);l==null||n&&!n(l)||r.push(e(l,c))}return t&&t.order&&this._sort(r,t.order),r}},{key:`_filterFields`,value:function(e,t){var n;return e&&Md(n=tm(t)?t:im(t)).call(n,(function(t,n){return t[n]=e[n],t}),{})}},{key:`_sort`,value:function(e,t){if(typeof t==`string`){var n=t;bT(e).call(e,(function(e,t){var r=e[n],i=t[n];return r>i?1:r<i?-1:0}))}else{if(typeof t!=`function`)throw TypeError(`Order must be a function or a string`);bT(e).call(e,t)}}},{key:`remove`,value:function(e,t){for(var n=[],r=[],i=tm(e)?e:[e],a=0,o=i.length;a<o;a++){var s=this._remove(i[a]);if(s){var c=s[this._idProp];c!=null&&(n.push(c),r.push(s))}}return n.length&&this._trigger(`remove`,{items:n,oldData:r},t),n}},{key:`_remove`,value:function(e){var t;if(WT(e)?t=e:e&&typeof e==`object`&&(t=e[this._idProp]),t!=null&&this._data.has(t)){var n=this._data.get(t)||null;return this._data.delete(t),--this.length,n}return null}},{key:`clear`,value:function(e){for(var t,n=Bp(Lw(t=this._data).call(t)),r=[],i=0,a=n.length;i<a;i++)r.push(this._data.get(n[i]));return this._data.clear(),this.length=0,this._trigger(`remove`,{items:n,oldData:r},e),n}},{key:`max`,value:function(e){var t,n,r=null,i=null,a=eE(OT(t=this._data).call(t));try{for(a.s();!(n=a.n()).done;){var o=n.value,s=o[e];typeof s==`number`&&(i==null||s>i)&&(r=o,i=s)}}catch(e){a.e(e)}finally{a.f()}return r||null}},{key:`min`,value:function(e){var t,n,r=null,i=null,a=eE(OT(t=this._data).call(t));try{for(a.s();!(n=a.n()).done;){var o=n.value,s=o[e];typeof s==`number`&&(i==null||s<i)&&(r=o,i=s)}}catch(e){a.e(e)}finally{a.f()}return r||null}},{key:`distinct`,value:function(e){for(var t=this._data,n=Bp(Lw(t).call(t)),r=[],i=0,a=0,o=n.length;a<o;a++){for(var s=n[a],c=t.get(s)[e],l=!1,u=0;u<i;u++)if(r[u]==c){l=!0;break}l||c===void 0||(r[i]=c,i++)}return r}},{key:`_addItem`,value:function(e){var t=function(e,t){return e[t]??(e[t]=UT()),e}(e,this._idProp),n=t[this._idProp];if(this._data.has(n))throw Error(`Cannot add item: item with id `+n+` already exists`);return this._data.set(n,t),++this.length,n}},{key:`_updateItem`,value:function(e){var t=e[this._idProp];if(t==null)throw Error(`Cannot update item: item has no id (item: `+gh(e)+`)`);var n=this._data.get(t);if(!n)throw Error(`Cannot update item: no item with id `+t+` found`);return this._data.set(t,$T($T({},n),e)),t}},{key:`stream`,value:function(e){if(e){var t=this._data;return new ZT({[kT]:()=>vC.mark((function n(){var r,i,a,o;return vC.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:r=eE(e),n.prev=1,r.s();case 3:if((i=r.n()).done){n.next=11;break}if(a=i.value,(o=t.get(a))==null){n.next=9;break}return n.next=9,[a,o];case 9:n.next=3;break;case 11:n.next=16;break;case 13:n.prev=13,n.t0=n.catch(1),r.e(n.t0);case 16:return n.prev=16,r.f(),n.finish(16);case 19:case`end`:return n.stop()}}),n,null,[[1,13,16,19]])}))()})}var n;return new ZT({[kT]:gd(n=LT(this._data)).call(n,this._data)})}}]),r}(KT);function iE(e,t){var n=Vp!==void 0&&Zf(e)||e[`@@iterator`];if(!n){if(tm(e)||(n=function(e,t){var n;if(e){if(typeof e==`string`)return aE(e,t);var r=qp(n=Object.prototype.toString.call(e)).call(n,8,-1);if(r===`Object`&&e.constructor&&(r=e.constructor.name),r===`Map`||r===`Set`)return Jf(e);if(r===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return aE(e,t)}}(e))||t&&e&&typeof e.length==`number`){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw TypeError(`Invalid attempt to iterate non-iterable instance.
|
|
49
49
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var a,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||n.return==null||n.return()}finally{if(s)throw a}}}}function aE(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function oE(e){var t=function(){if(typeof Reflect>`u`||!sv||sv.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Boolean.prototype.valueOf.call(sv(Boolean,[],(function(){}))),!0}catch{return!1}}();return function(){var n,r=Vv(e);if(t){var i=Vv(this).constructor;n=sv(r,arguments,i)}else n=r.apply(this,arguments);return Rv(this,n)}}var sE=function(e){Lv(r,e);var n=oE(r);function r(e,i){var a,o;return t(this,r),Yu(W(o=n.call(this)),`length`,0),Yu(W(o),`_ids`,new qT),o._options=i||{},o._listener=gd(a=o._onEvent).call(a,W(o)),o.setData(e),o}return Ju(r,[{key:`idProp`,get:function(){return this.getDataSet().idProp}},{key:`setData`,value:function(e){if(this._data){this._data.off&&this._data.off(`*`,this._listener);var t=this._data.getIds({filter:Rd(this._options)}),n=this._data.get(t);this._ids.clear(),this.length=0,this._trigger(`remove`,{items:t,oldData:n})}if(e!=null){this._data=e;for(var r=this._data.getIds({filter:Rd(this._options)}),i=0,a=r.length;i<a;i++){var o=r[i];this._ids.add(o)}this.length=r.length,this._trigger(`add`,{items:r})}else this._data=new rE;this._data.on&&this._data.on(`*`,this._listener)}},{key:`refresh`,value:function(){for(var e=this._data.getIds({filter:Rd(this._options)}),t=Bp(this._ids),n={},r=[],i=[],a=[],o=0,s=e.length;o<s;o++){var c=e[o];n[c]=!0,this._ids.has(c)||(r.push(c),this._ids.add(c))}for(var l=0,u=t.length;l<u;l++){var d=t[l],f=this._data.get(d);f==null?console.error(`If you see this, report it please.`):n[d]||(i.push(d),a.push(f),this._ids.delete(d))}this.length+=r.length-i.length,r.length&&this._trigger(`add`,{items:r}),i.length&&this._trigger(`remove`,{items:i,oldData:a})}},{key:`get`,value:function(e,t){if(this._data==null)return null;var n,r=null;WT(e)||tm(e)?(r=e,n=t):n=e;var i=oh({},this._options,n),a=Rd(this._options),o=n&&Rd(n);return a&&o&&(i.filter=function(e){return a(e)&&o(e)}),r==null?this._data.get(i):this._data.get(r,i)}},{key:`getIds`,value:function(e){if(this._data.length){var t,n=Rd(this._options),r=e==null?null:Rd(e);return t=r?n?function(e){return n(e)&&r(e)}:r:n,this._data.getIds({filter:t,order:e&&e.order})}return[]}},{key:`forEach`,value:function(e,t){if(this._data){var n,r,i=Rd(this._options),a=t&&Rd(t);r=a?i?function(e){return i(e)&&a(e)}:a:i,hm(n=this._data).call(n,e,{filter:r,order:t&&t.order})}}},{key:`map`,value:function(e,t){if(this._data){var n,r,i=Rd(this._options),a=t&&Rd(t);return r=a?i?function(e){return i(e)&&a(e)}:a:i,Wd(n=this._data).call(n,e,{filter:r,order:t&&t.order})}return[]}},{key:`getDataSet`,value:function(){return this._data.getDataSet()}},{key:`stream`,value:function(e){var t;return this._data.stream(e||{[kT]:gd(t=Lw(this._ids)).call(t,this._ids)})}},{key:`dispose`,value:function(){var e;(e=this._data)!=null&&e.off&&this._data.off(`*`,this._listener);var t,n=`This data view has already been disposed of.`,i={get:function(){throw Error(n)},set:function(){throw Error(n)},configurable:!1},a=iE(em(r.prototype));try{for(a.s();!(t=a.n()).done;){var o=t.value;Av(this,o,i)}}catch(e){a.e(e)}finally{a.f()}}},{key:`_onEvent`,value:function(e,t,n){if(t&&t.items&&this._data){var r=t.items,i=[],a=[],o=[],s=[],c=[],l=[];switch(e){case`add`:for(var u=0,d=r.length;u<d;u++){var f=r[u];this.get(f)&&(this._ids.add(f),i.push(f))}break;case`update`:for(var p=0,m=r.length;p<m;p++){var h=r[p];this.get(h)?this._ids.has(h)?(a.push(h),c.push(t.data[p]),s.push(t.oldData[p])):(this._ids.add(h),i.push(h)):this._ids.has(h)&&(this._ids.delete(h),o.push(h),l.push(t.oldData[p]))}break;case`remove`:for(var g=0,_=r.length;g<_;g++){var v=r[g];this._ids.has(v)&&(this._ids.delete(v),o.push(v),l.push(t.oldData[g]))}}this.length+=i.length-o.length,i.length&&this._trigger(`add`,{items:i},n),a.length&&this._trigger(`update`,{items:a,oldData:s,data:c},n),o.length&&this._trigger(`remove`,{items:o,oldData:l},n)}}}]),r}(KT);function cE(e,t){return typeof t==`object`&&!!t&&e===t.idProp&&typeof t.add==`function`&&typeof t.clear==`function`&&typeof t.distinct==`function`&&typeof hm(t)==`function`&&typeof t.get==`function`&&typeof t.getDataSet==`function`&&typeof t.getIds==`function`&&typeof t.length==`number`&&typeof Wd(t)==`function`&&typeof t.max==`function`&&typeof t.min==`function`&&typeof t.off==`function`&&typeof t.on==`function`&&typeof t.remove==`function`&&typeof t.setOptions==`function`&&typeof t.stream==`function`&&typeof t.update==`function`&&typeof t.updateOnly==`function`}e.DELETE=I_,e.DataSet=rE,e.DataStream=ZT,e.DataView=sE,e.Queue=GT,e.createNewDataPipeFrom=function(e){return new cf(e)},e.isDataSetLike=cE,e.isDataViewLike=function(e,t){return typeof t==`object`&&!!t&&e===t.idProp&&typeof hm(t)==`function`&&typeof t.get==`function`&&typeof t.getDataSet==`function`&&typeof t.getIds==`function`&&typeof t.length==`number`&&typeof Wd(t)==`function`&&typeof t.off==`function`&&typeof t.on==`function`&&typeof t.stream==`function`&&cE(e,t.getDataSet())}}))}))(),A=re(),ae=d(),j=e(r(),1);function oe(e){let t=new URLSearchParams(e),n=t.get(`nodeId`);if(n)return{kind:`focus`,nodeId:n,nodeLabel:t.get(`label`)};let r=t.get(`label`);return r?{kind:`labels`,labels:[r]}:null}function se(e){return!e.inNeighbourhood&&!e.searchActive&&e.selectedLabelsCount===0&&e.topLevelTotal!==null&&e.nodeCount>0}function ce(e,t){let n=t===1?`node`:`nodes`;return`Showing ${e.toLocaleString()} of ${t.toLocaleString()} top-level ${n}`}function le(e,t){let n=`/api/admin/graph-subgraph`,r=t.includeAgentActions?`&includeAgentActions=1`:``;if(e.kind===`neighbourhood`){let i=t.search&&t.search.q?`&q=${encodeURIComponent(t.search.q)}&limit=${t.search.limit}`:``;return`${n}?mode=neighbourhood&elementId=${encodeURIComponent(e.rootElementId)}${r}${i}`}let i=e.includeTrashed?`&includeTrashed=1`:``;return e.selectedLabels.length===0?`${n}?mode=default&topLevel=1${i}${r}`:`${n}?mode=default&labels=${encodeURIComponent(e.selectedLabels.join(`,`))}${i}${r}`}function ue(e,t){return e.length<10?[...e,t]:[e[0],...e.slice(e.length-8),t]}function de(e){return e.length<=1?e:e.slice(0,-1)}function fe(e){return[e]}function pe(e){let t=e[e.length-1];return t.kind===`filter`?`f:${[...t.selectedLabels].sort().join(`,`)}:${t.includeTrashed?1:0}:${t.includeAgentActions?1:0}`:`n:${t.rootElementId}`}function me(e){let t=e[0];if(t.kind!==`filter`)throw Error(`view-stack invariant: root must be filter view`);return t}var he=`admin-sessions`;function ge(){if(typeof window>`u`)return null;if(typeof BroadcastChannel>`u`)return console.warn(`[admin-sessions/broadcast] unsupported — manual refresh only`),null;try{return new BroadcastChannel(he)}catch(e){return console.warn(`[admin-sessions/broadcast] ctor failed: ${e instanceof Error?e.message:String(e)} — manual refresh only`),null}}function _e(e){let t=ge();if(t)try{let n={type:`mutated`,reason:e};t.postMessage(n)}catch(e){console.warn(`[admin-sessions/broadcast] postMessage failed: ${e instanceof Error?e.message:String(e)}`)}finally{try{t.close()}catch{}}}function ve(e){return e.trashed===!0?`skip-trashed`:`pivot`}function ye(e,t,n,r){let i=[],a=[];for(let o of e){let e=t.get(o.nodeId);if(!e)continue;a.push(o.nodeId);let{colour:s}=n(e.labels),c=e.trashed?`${s}40`:s;i.push({id:o.nodeId,borderWidth:3,color:{background:c,border:r}})}return{updates:i,inWindow:a}}function be(e,t){let n=t.length>0?new Set(t):null,r=new Map,i=new Set,a=[];for(let t of e)n&&!t.labels.some(e=>n.has(e))||r.set(t.nodeId,{id:t.nodeId,labels:t.labels,properties:t.properties});for(let t of e)if(r.has(t.nodeId))for(let e of t.related){if(n&&!e.labels.some(e=>n.has(e)))continue;r.has(e.nodeId)||r.set(e.nodeId,{id:e.nodeId,labels:e.labels,properties:e.properties});let[o,s]=e.direction===`outgoing`?[t.nodeId,e.nodeId]:[e.nodeId,t.nodeId],c=`${o}|${s}|${e.relationship}`;i.has(c)||(i.add(c),a.push({id:c,from:o,to:s,type:e.relationship}))}return{nodes:[...r.values()],edges:a}}var xe=2e3;function Se(e){let t=typeof e==`number`?e:Number(e);return!Number.isFinite(t)||t<=0?100:Math.min(Math.max(Math.floor(t),1),xe)}function M(e,t,n,r){let i=encodeURIComponent(t.join(`,`));return`/api/admin/graph-search?q=${encodeURIComponent(e)}&labels=${i}&limit=${n}${r?`&threshold=0`:``}`}var N=ne(),P=new Set([`Conversation`,`AdminConversation`,`PublicConversation`]),Ce=/^(\d{4}-\d{2}-\d{2})T/,we=24;function Te(e){let t=e.match(Ce);return t?t[1]:null}function F(e,t){if(e.length===0)return``;let n=e.split(/\s+/).filter(e=>e.length>0);if(n.length===0)return``;if(n.length===1){let e=n[0];return e.length<=we?e:e.slice(0,we-1)+`…`}let r=[],i=0;for(;r.length<t&&i<n.length;){let e=``;for(;i<n.length;){let t=e.length===0?n[i]:`${e} ${n[i]}`;if(t.length<=we)e=t,i++;else break}e.length===0&&(e=n[i].slice(0,we-1)+`…`,i++),r.push(e)}if(i<n.length&&r.length>0){let e=n.slice(i).join(` `),t=r.length-1;r[t]=(r[t].length===0?e:`${r[t]} ${e}`).slice(0,we-1)+`…`}return r.join(`
|
|
50
50
|
`)}function I(e){return F(e,2)}function Ee(e,t){let n=e.labels[0];if(!n||!P.has(n)||t<.7)return(0,N.pickShortLabel)(e);let r=I((0,N.pickDisplayName)(e));if(t<1.3)return r;let i=e.properties,a=typeof i.createdAt==`string`?i.createdAt:``,o=typeof i.messageCount==`number`?i.messageCount:null;if(a.length===0||o===null)return r;let s=Te(a);return s===null?r:`${r}\n${s} · ${o} msgs`}var De=new Set([`Person`,`Organization`,`Concept`]),Oe=80;function ke(e,t){let n=(0,N.pickDisplayName)(e);if(t<1.3)return F(n,3);let r=n.length<=24?n:n.slice(0,23)+`…`,i=e.properties.compiledTruth;if(typeof i!=`string`||i.length===0)return F((0,N.pickDisplayName)(e),3);let a=F(i.length>Oe?i.slice(0,Oe-1)+`…`:i,2);return a.length===0?r:`${r}\n${a}`}function Ae(e,t){if(t<.7)return(0,N.pickShortLabel)(e);let n=e.labels[0];return n&&P.has(n)?Ee(e,t):n&&De.has(n)?ke(e,t):F((0,N.pickDisplayName)(e),3)}function je(e){let t=e.properties,n=typeof t.createdAt==`string`?t.createdAt:``,r=typeof t.updatedAt==`string`?t.updatedAt:``,i=e.labels.join(` · `);return[(0,N.pickDisplayName)(e),i,`id: ${e.id}`,n?`createdAt: ${n}`:``,r?`updatedAt: ${r}`:``].filter(e=>e.length>0).join(`
|
|
51
|
-
`)}var Me={solver:`forceAtlas2Based`,forceAtlas2Based:{gravitationalConstant:-50,centralGravity:.01,springLength:100,springConstant:.08,damping:.4,avoidOverlap:0},stabilization:{iterations:2e3}},Ne=220,Pe=3;function Fe(e){if(!(e.nodes.length<=5))return{physics:Me,nodePositions:new Map};let t=new Map,n=(Pe-1)*Ne/2,r=(Math.ceil(e.nodes.length/Pe)-1)*Ne/2;for(let i=0;i<e.nodes.length;i++){let a=i%Pe,o=Math.floor(i/Pe);t.set(e.nodes[i].id,{x:a*Ne-n,y:o*Ne-r})}return{physics:!1,nodePositions:t}}function Ie(e,t){let n=(t.t-e.t)/1e3;if(n<=0)return 0;let r=0,i=0;for(let n of Object.keys(t.positions)){let a=e.positions[n];if(!a)continue;let o=t.positions[n];r+=Math.hypot(o.x-a.x,o.y-a.y),i++}return i===0?0:r/i/n}function Le(e,t,n){if(t>n.threshold)return{belowCount:0,freeze:!1};let r=e+1;return{belowCount:r,freeze:r>=n.needed}}function Re(e,t){let n=Date.now(),r=null,i=0,a=null,o=()=>{a!==null&&(clearInterval(a),a=null)},s=(r,i,a)=>{o();try{e.setOptions({physics:!1})}catch{}t.report?.({avgMotion:r,settleMs:Date.now()-n,capped:a,nodeCount:i})};return a=setInterval(()=>{let t;try{t=e.getPositions()}catch{o();return}let a={t:Date.now(),positions:t},c=Object.keys(t).length;if(r){let e=Ie(r,a),t=Le(i,e,{threshold:5,needed:2});if(i=t.belowCount,t.freeze){s(e,c,!1);return}if(Date.now()-n>=3e4){s(e,c,!0);return}}r=a},250),o}var ze=`graph-side-panel-size`;function Be(e,t){let n=Math.max(320,t.maxWidth),r=Math.max(240,t.maxHeight),i=Math.min(Math.max(e.width,320),n),a=Math.min(Math.max(e.height,240),r);return{width:i,height:a,clampedW:i!==e.width,clampedH:a!==e.height}}function Ve(e){try{localStorage.setItem(ze,JSON.stringify({width:e.width,height:e.height}))}catch{}}function He(){try{let e=localStorage.getItem(ze);if(!e)return{size:null,source:`default`};let t=JSON.parse(e);return t&&typeof t==`object`&&typeof t.width==`number`&&typeof t.height==`number`&&Number.isFinite(t.width)&&Number.isFinite(t.height)?{size:{width:t.width,height:t.height},source:`storage`}:{size:null,source:`default`}}catch{return{size:null,source:`default`}}}function Ue(e){return typeof e==`string`?/^https?:\/\/\S+$/i.test(e.trim()):!1}function We(e){let t=t=>{let n=e[t];if(n&&typeof n==`object`&&`low`in n){let e=n.low;return typeof e==`number`?e:null}return null},n=t(`year`),r=t(`month`),i=t(`day`);if(n===null||r===null||i===null)return null;let a=`${String(n).padStart(4,`0`)}-${String(r).padStart(2,`0`)}-${String(i).padStart(2,`0`)}`;if(!(`hour`in e))return a;let o=t(`hour`),s=t(`minute`),c=t(`second`);return o===null||s===null||c===null?a:`${a} ${String(o).padStart(2,`0`)}:${String(s).padStart(2,`0`)}:${String(c).padStart(2,`0`)}`}function Ge(e){if(e==null)return``;if(Array.isArray(e))return e.length>8?`[${e.length} items]`:e.map(String).join(`, `);if(typeof e==`object`){if(`year`in e&&`month`in e&&`day`in e&&typeof e.year==`object`){let t=We(e);if(t)return t}return JSON.stringify(e)}return String(e)}var L=f(),Ke=76,qe=36,Je=16,Ye=520;function Xe(e){let t=e?.offsetParent??null,n=t?.clientWidth??0,r=t?.clientHeight??0;return{maxWidth:n-qe-Je,maxHeight:r-Ke-Je}}function Ze(e){return typeof e==`string`?e:Ge(e)}function Qe(e){return Ue(e)?(0,L.jsx)(`a`,{className:`graph-side-link`,href:e,target:`_blank`,rel:`noopener noreferrer`,children:e}):Ge(e)}function $e({value:e,label:t,field:n}){let{status:r,copy:i}=b({onResult:e=>{e?console.log(`[graph-panel] op=copy result=ok field=${n}`):console.warn(`[graph-panel] op=copy result=error field=${n} msg=clipboard-write-failed`)}}),a=r===`ok`?`Copied`:r===`fail`?`Copy failed`:`Copy ${t}`;return(0,L.jsxs)(`button`,{type:`button`,className:`graph-side-copy${r===`ok`?` graph-side-copy-ok`:``}${r===`fail`?` graph-side-copy-fail`:``}`,onClick:()=>i(e),"aria-label":a,title:a,children:[r===`ok`?(0,L.jsx)(c,{size:12}):(0,L.jsx)(y,{size:12}),r!==`idle`&&(0,L.jsx)(`span`,{className:`graph-side-copy-feedback`,children:r===`ok`?`Copied`:`Copy failed`})]})}function et({node:e,edges:t,nodesById:n,adminFetch:r,onClose:a,onRestored:s,onTrashed:c}){let u=Object.entries(e.properties).filter(([,e])=>e!=null),d=t.filter(t=>t.from===e.id||t.to===e.id),f=d.length>0,[p,h]=(0,j.useState)(!1),[g,_]=(0,j.useState)(null),[v,y]=(0,j.useState)(!1),[b,x]=(0,j.useState)(null),[S,ee]=(0,j.useState)(`properties`),te=m(`(max-width: 640px)`),w=(0,j.useRef)(null),ne=(0,j.useRef)(He()),[T,E]=(0,j.useState)(()=>ne.current.size??{width:320,height:Ye}),D=(0,j.useRef)(!1),O=(0,j.useRef)(null);(0,j.useEffect)(()=>()=>{O.current?.()},[]),(0,j.useEffect)(()=>{h(!1),_(null),y(!1),x(null),ee(`properties`)},[e.id]),(0,j.useLayoutEffect)(()=>{if(D.current)return;D.current=!0;let e=Xe(w.current),t=Be(ne.current.size??{width:320,height:Ye},e);E({width:t.width,height:t.height}),console.log(`[graph-panel] op=restore-size w=${t.width} h=${t.height} source=${ne.current.source}`)},[]);let k=(0,j.useCallback)(e=>{e.preventDefault();let t=e.clientX,n=e.clientY,r=T.width,i=T.height,a=Xe(w.current);try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}let o={width:r,height:i,clampedW:!1,clampedH:!1},s=e=>{o=Be({width:r+(t-e.clientX),height:i+(e.clientY-n)},a),E({width:o.width,height:o.height})},c=()=>{window.removeEventListener(`pointermove`,s),window.removeEventListener(`pointerup`,l),window.removeEventListener(`pointercancel`,l),O.current=null},l=()=>{c(),Ve({width:o.width,height:o.height}),console.log(`[graph-panel] op=resize w=${o.width} h=${o.height} clampedW=${o.clampedW} clampedH=${o.clampedH}`)};window.addEventListener(`pointermove`,s),window.addEventListener(`pointerup`,l),window.addEventListener(`pointercancel`,l),O.current=c},[T.width,T.height]),re=(0,j.useCallback)(()=>{h(!0),_(null),r(`/api/admin/graph-restore`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({elementId:e.id})}).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);s()}).catch(e=>{_(e instanceof Error?e.message:String(e)),h(!1)})},[e.id,s,r]),ie=(0,j.useCallback)(()=>{y(!0),x(null),r(`/api/admin/graph-delete`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({elementId:e.id,by:`graph-side-panel-trash`})}).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);c()}).catch(e=>{x(e instanceof Error?e.message:String(e)),y(!1)})},[e.id,c,r]),A=S===`connections`&&f?`connections`:`properties`,ae=te?void 0:{width:`${T.width}px`,height:`${T.height}px`};return(0,L.jsxs)(`aside`,{ref:w,className:`graph-side-panel${e.trashed?` graph-side-panel-trashed`:``}`,style:ae,children:[!te&&(0,L.jsx)(`div`,{className:`graph-side-resize-handle`,role:`separator`,"aria-label":`Resize panel`,"aria-orientation":`vertical`,onPointerDown:k}),(0,L.jsxs)(`header`,{className:`graph-side-header`,children:[(0,L.jsx)(`div`,{children:(()=>{if(e.labels.some(e=>P.has(e))){let t=(0,N.pickDisplayName)(e),n=e.properties.createdAt,r=typeof n==`string`?n:``,i=r?(0,N.formatRunTimestamp)(r):null,a=e.labels.join(` · `)+(e.trashed?` · Trashed`:``)+` · ${e.id}`;return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`h2`,{className:`graph-side-name`,title:t,children:t}),i&&(0,L.jsx)(`div`,{className:`graph-side-created`,children:i}),(0,L.jsxs)(`div`,{className:`graph-side-meta`,children:[(0,L.jsx)(`span`,{children:a}),(0,L.jsx)($e,{value:e.id,label:`id`,field:`id`})]})]})}return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`graph-side-labels`,children:[e.labels.join(` · `),e.trashed?` · Trashed`:``]}),(0,L.jsxs)(`div`,{className:`graph-side-id-row`,children:[(0,L.jsx)(`span`,{className:`graph-side-id`,children:e.id}),(0,L.jsx)($e,{value:e.id,label:`id`,field:`id`})]})]})})()}),(0,L.jsx)(`button`,{type:`button`,className:`graph-side-close`,onClick:a,"aria-label":`Close`,children:(0,L.jsx)(i,{size:14})})]}),e.trashed&&(0,L.jsxs)(`dl`,{className:`graph-side-props graph-side-trash-meta`,children:[(0,L.jsxs)(`div`,{className:`graph-side-prop`,children:[(0,L.jsx)(`dt`,{children:`trashedAt`}),(0,L.jsx)(`dd`,{children:Ge(e.properties.trashedAt)})]}),(0,L.jsxs)(`div`,{className:`graph-side-prop`,children:[(0,L.jsx)(`dt`,{children:`trashedBy`}),(0,L.jsx)(`dd`,{children:Ge(e.properties.trashedBy)})]})]}),(0,L.jsxs)(`div`,{className:`graph-side-tabs`,role:`tablist`,"aria-label":`Node detail sections`,children:[(0,L.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":A===`properties`,className:`graph-side-tab${A===`properties`?` graph-side-tab-on`:``}`,onClick:()=>ee(`properties`),children:`Properties`}),f&&(0,L.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":A===`connections`,className:`graph-side-tab${A===`connections`?` graph-side-tab-on`:``}`,onClick:()=>ee(`connections`),children:[`Connections (`,d.length,`)`]})]}),(0,L.jsxs)(`div`,{className:`graph-side-body`,children:[A===`properties`&&(0,L.jsxs)(`dl`,{className:`graph-side-props`,children:[u.length===0&&(0,L.jsx)(`div`,{className:`graph-side-empty`,children:`No properties.`}),u.map(([e,t])=>(0,L.jsxs)(`div`,{className:`graph-side-prop`,children:[(0,L.jsx)(`dt`,{children:e}),(0,L.jsxs)(`dd`,{children:[(0,L.jsx)(`span`,{className:`graph-side-prop-value`,children:Qe(t)}),(0,L.jsx)($e,{value:Ze(t),label:e,field:`prop`})]})]},e))]}),A===`connections`&&f&&(0,L.jsx)(`section`,{className:`graph-side-edges`,children:d.map(t=>{let r=t.from===e.id,i=r?t.to:t.from,a=n.get(i),o=a?(0,N.pickShortLabel)(a):i,s=r?`→`:`←`,c=Object.entries(t.properties??{}).filter(([,e])=>e!=null&&e!==``);return(0,L.jsxs)(`div`,{className:`graph-side-edge`,children:[(0,L.jsxs)(`div`,{className:`graph-side-edge-header`,children:[(0,L.jsx)(`span`,{className:`graph-side-edge-type`,children:t.type}),(0,L.jsx)(`span`,{className:`graph-side-edge-arrow`,children:s}),(0,L.jsx)(`span`,{className:`graph-side-edge-other`,title:o,children:o})]}),c.length>0&&(0,L.jsx)(`dl`,{className:`graph-side-edge-props`,children:c.map(([e,t])=>(0,L.jsxs)(`div`,{className:`graph-side-prop`,children:[(0,L.jsx)(`dt`,{children:e}),(0,L.jsxs)(`dd`,{children:[(0,L.jsx)(`span`,{className:`graph-side-prop-value`,children:Qe(t)}),(0,L.jsx)($e,{value:Ze(t),label:e,field:`edge-prop`})]})]},e))})]},t.id)})})]}),e.trashed&&(0,L.jsxs)(`footer`,{className:`graph-side-footer`,children:[!p&&!g&&(0,L.jsxs)(`button`,{type:`button`,className:`graph-side-restore`,onClick:re,children:[(0,L.jsx)(C,{size:14}),` Restore`]}),p&&(0,L.jsx)(`div`,{className:`graph-delete-confirm`,children:(0,L.jsxs)(`p`,{children:[(0,L.jsx)(o,{size:14,className:`spin`}),` Restoring…`]})}),g&&(0,L.jsxs)(`div`,{className:`graph-delete-confirm graph-delete-confirm-error`,children:[(0,L.jsxs)(`p`,{children:[`Restore failed: `,g]}),(0,L.jsxs)(`div`,{className:`graph-delete-confirm-buttons`,children:[(0,L.jsx)(`button`,{type:`button`,className:`graph-delete-confirm-cancel`,onClick:()=>{_(null)},children:`Close`}),(0,L.jsx)(`button`,{type:`button`,className:`graph-delete-confirm-do`,onClick:re,children:`Retry`})]})]})]}),!e.trashed&&(0,L.jsxs)(`footer`,{className:`graph-side-footer`,children:[!v&&!b&&(0,L.jsxs)(`button`,{type:`button`,className:`graph-side-trash`,onClick:ie,children:[(0,L.jsx)(l,{size:14}),` Trash`]}),v&&(0,L.jsx)(`div`,{className:`graph-delete-confirm`,children:(0,L.jsxs)(`p`,{children:[(0,L.jsx)(o,{size:14,className:`spin`}),` Trashing…`]})}),b&&(0,L.jsxs)(`div`,{className:`graph-delete-confirm graph-delete-confirm-error`,children:[(0,L.jsxs)(`p`,{children:[`Trash failed: `,b]}),(0,L.jsxs)(`div`,{className:`graph-delete-confirm-buttons`,children:[(0,L.jsx)(`button`,{type:`button`,className:`graph-delete-confirm-cancel`,onClick:()=>{x(null)},children:`Close`}),(0,L.jsx)(`button`,{type:`button`,className:`graph-delete-confirm-do`,onClick:ie,children:`Retry`})]})]})]})]})}var tt=`graph-shell`,nt=`graph-shell--fullscreen`;function rt(e,t){return t&&e?`${tt} ${nt}`:tt}function it(e){return e}function at(e){return e.isFullscreen&&!e.filterOpen}function ot(e){return e<.7?`compact`:e<1.3?`wrapped`:`detailed`}var st=150,ct=`#FBBF24`;function lt(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return t>>>0}var ut=`maxy-graph-search-limit-v1`,dt=250,ft=1200;function pt(){let[e,t]=(0,j.useState)(null),[n,r]=(0,j.useState)(!1),[i,s]=(0,j.useState)(void 0),[c,l]=(0,j.useState)(null),[d,f]=(0,j.useState)(void 0),[m,h]=(0,j.useState)(null),[_,v]=(0,j.useState)(null),y=(0,j.useMemo)(()=>typeof window>`u`?null:oe(window.location.search),[]),b=(0,j.useMemo)(()=>y?.kind===`focus`?{nodeId:y.nodeId,nodeLabel:y.nodeLabel}:null,[y]),x=(0,j.useMemo)(()=>y?.kind===`labels`?y.labels:null,[y]);(0,j.useEffect)(()=>{b&&_t(`deep-link`,{nodeId:b.nodeId.length>16?b.nodeId.slice(0,16)+`…`:b.nodeId,label:b.nodeLabel??``})},[b]),(0,j.useEffect)(()=>{!x||x.length===0||_t(`label-seed`,{label:x[0]})},[x]),(0,j.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!n){t(null),r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}if(i.ok)try{let e=await i.json();typeof e.businessName==`string`&&s(e.businessName),e.sessionId!==void 0&&l(e.sessionId??null),v(e.role??null),f(e.userName===void 0?null:e.userName),h(e.avatar??null)}catch{}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]);let S=(0,j.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]),[ee,C]=(0,j.useState)(!1),te=(0,j.useCallback)(async()=>{C(!0);try{let e=await p();if(e){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`}return e}finally{C(!1)}},[]);return n?e?(0,L.jsx)(u,{cacheKey:e,surface:`graph`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=graph`);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},children:(0,L.jsx)(g,{cacheKey:e,businessName:i,sessionId:c,onLogout:S,onDisconnect:te,disconnecting:ee,userName:d,userAvatar:m,role:_,children:(0,L.jsxs)(`div`,{className:`data-page graph-page`,children:[(0,L.jsx)(`header`,{className:`data-header`,children:(0,L.jsxs)(`h1`,{className:`data-title`,children:[(0,L.jsx)(a,{size:18}),` Graph`]})}),(0,L.jsx)(`main`,{className:`graph-main`,children:(0,L.jsx)(mt,{cacheKey:e,initialFocus:b,initialLabels:x,allowFullscreen:!0})})]})})}):(0,L.jsxs)(`div`,{className:`data-page`,children:[(0,L.jsx)(`header`,{className:`data-header`,children:(0,L.jsxs)(`h1`,{className:`data-title`,children:[(0,L.jsx)(a,{size:18}),` Graph`]})}),(0,L.jsxs)(`div`,{className:`data-empty`,children:[(0,L.jsx)(`p`,{children:`You are not signed in.`}),(0,L.jsxs)(`p`,{children:[`Open the `,(0,L.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})]}):(0,L.jsx)(`div`,{className:`data-page`,children:(0,L.jsxs)(`div`,{className:`data-loading`,children:[(0,L.jsx)(o,{size:18,className:`spin`}),` Loading…`]})})}function mt({cacheKey:e,initialFocus:t=null,initialLabels:r=null,allowFullscreen:a=!1}){let{adminFetch:s,cacheKey:c,sessionRefetchNonce:u}=n({initialCacheKey:e,surface:`graph`}),d=(0,j.useRef)(null),f=(0,j.useRef)(null),[p,m]=(0,j.useState)(!1),g=(0,j.useRef)(null),y=(0,j.useRef)(null),b=(0,j.useRef)(null),C=(0,j.useRef)(null),ne=(0,j.useRef)(new Map),k=(0,j.useRef)([]),re=(0,j.useRef)(null),ae=(0,j.useRef)(null),oe=(0,j.useRef)(null),he=(0,j.useRef)([]),ge=(0,j.useRef)(null),xe=(0,j.useRef)(null),N=(0,j.useRef)(null),P=(0,j.useRef)(null),[Ce,we]=(0,j.useState)([{kind:`filter`,selectedLabels:[],includeTrashed:!1,includeAgentActions:!1}]);(0,j.useEffect)(()=>{t?.nodeId&&we(e=>{let n=e[e.length-1];return n.kind===`neighbourhood`&&n.rootElementId===t.nodeId?e:[e[0],{kind:`neighbourhood`,rootElementId:t.nodeId,rootLabel:t.nodeLabel}]})},[t?.nodeId,t?.nodeLabel]);let Te=r&&r.length>0?[...r].sort().join(`,`):null;(0,j.useEffect)(()=>{Te&&(It.current=!0,we([{kind:`filter`,selectedLabels:Te.split(`,`),includeTrashed:!1,includeAgentActions:!1}]))},[Te]);let[F,I]=(0,j.useState)(!1),[Ee,De]=(0,j.useState)(null),[Oe,ke]=(0,j.useState)(null),[Me,Ne]=(0,j.useState)(0),[Pe,Ie]=(0,j.useState)(null),[Le,ze]=(0,j.useState)(null),[Be,Ve]=(0,j.useState)(!1),[He,Ue]=(0,j.useState)(!1),[We,Ge]=(0,j.useState)(null),[Ke,qe]=(0,j.useState)(``),[Je,Ye]=(0,j.useState)(``),[Xe,Ze]=(0,j.useState)(null),[Qe,$e]=(0,j.useState)(null),[tt,nt]=(0,j.useState)(()=>{if(typeof window>`u`)return 100;let e=window.localStorage.getItem(ut);return e?Se(e):100}),[pt,mt]=(0,j.useState)(tt),[vt,yt]=(0,j.useState)(`hybrid`),[bt,xt]=(0,j.useState)(0),[St,Ct]=(0,j.useState)(!1),[wt,Tt]=(0,j.useState)(0),[Et,Dt]=(0,j.useState)(0),[Ot,kt]=(0,j.useState)([]),[At,jt]=(0,j.useState)({labels:[],includeTrashed:!1}),[Mt,Nt]=(0,j.useState)(!1),[Pt,Ft]=(0,j.useState)(!1),It=(0,j.useRef)(!1),Lt=(0,j.useRef)(null),Rt=(0,j.useMemo)(()=>{let e=new Set;for(let t of ne.current.values()){let n=(0,w.pickDisplayLabel)(t.labels);n&&e.add(n)}return[...e].sort()},[Me]);(0,j.useEffect)(()=>{let e=!1,t=s(`/api/admin/graph-labels-in-graph`).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()}).catch(e=>{let t=e instanceof Error?e.message:String(e);try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-labels-in-graph`,msg:t}),keepalive:!0}).catch(()=>{})}catch{}return{labels:[]}}),n=s(`/api/admin/graph-default-view`).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()}).catch(e=>{let t=e instanceof Error?e.message:String(e);try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-default-view`,msg:t}),keepalive:!0}).catch(()=>{})}catch{}return{labels:[],includeTrashed:!1}});return Promise.all([t,n]).then(([t,n])=>{if(!e&&(kt(t.labels),jt(n),!It.current)){It.current=!0;let e=new Set(t.labels.map(e=>e.label)),r=n.labels.filter(t=>e.has(t));(r.length>0||n.includeTrashed)&&we(e=>[{kind:`filter`,selectedLabels:r,includeTrashed:n.includeTrashed,includeAgentActions:!1},...e.slice(1)])}}),()=>{e=!0}},[c,u,s]);let zt=Ce[0].kind===`filter`?Ce[0].includeAgentActions:!1;(0,j.useEffect)(()=>{if(!It.current)return;let e=!1;return s(`/api/admin/graph-labels-in-graph?includeAgentActions=${zt?`1`:`0`}`).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()}).then(t=>{e||kt(t.labels)}).catch(e=>{let t=e instanceof Error?e.message:String(e);try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-labels-in-graph-refetch`,msg:t}),keepalive:!0}).catch(()=>{})}catch{}}),()=>{e=!0}},[c,u,zt,Et,s]),(0,j.useEffect)(()=>{if(!Mt)return;let e=e=>{Lt.current&&(Lt.current.contains(e.target)||Nt(!1))},t=e=>{e.key===`Escape`&&Nt(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[Mt]);let Bt=(0,j.useCallback)((e,t)=>{try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:e,msg:t}),keepalive:!0}).catch(()=>{})}catch{}},[]),Vt=(0,j.useCallback)(e=>{console.log(`[graph-fullscreen] op=exit reason=${e}`),m(!1)},[]);(0,j.useEffect)(()=>{if(!a||!p)return;let e=e=>{e.key===`Escape`&&at({isFullscreen:p,filterOpen:Mt})&&Vt(`escape`)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[a,p,Mt,Vt]);let Ht=(0,j.useRef)(p);(0,j.useEffect)(()=>{if(!a)return;let e=Ht.current!==p;if(Ht.current=p,!e)return;let t=requestAnimationFrame(()=>{let e=f.current;try{e?.redraw()}catch{}if(!p)return;let t=g.current?.getBoundingClientRect(),n=window.innerWidth,r=window.innerHeight,i=t?Math.round(t.width):0,a=t?Math.round(t.height):0;console.log(`[graph-fullscreen] op=enter viewportW=${n} viewportH=${r} overlayW=${i} overlayH=${a}`),t&&(t.width<n-2||t.height<r-2)&&Bt(`graph-fullscreen-not-covering`,`op=enter viewportW=${n} viewportH=${r} overlayW=${i} overlayH=${a}`);try{let t=e?.canvas?.frame?.canvas,n=d.current;if(t&&n){let e=t.clientWidth,r=t.clientHeight,i=n.clientWidth,a=n.clientHeight;console.log(`[graph-fullscreen] op=resized canvasW=${e} canvasH=${r} containerW=${i} containerH=${a}`),(Math.abs(e-i)>2||Math.abs(r-a)>2)&&Bt(`graph-fullscreen-canvas-mismatch`,`canvasW=${e} canvasH=${r} containerW=${i} containerH=${a}`)}}catch{}});return()=>cancelAnimationFrame(t)},[a,p,Bt]);let Ut=(0,j.useCallback)(()=>{if(b.current)try{b.current.clear()}catch{}if(C.current)try{C.current.clear()}catch{}},[]),Wt=(0,j.useCallback)((e,t)=>{Ge(null),s(`/api/admin/graph-delete`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({elementId:e,by:`graph-drag-trash`})}).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);ze(null);try{f.current?.unselectAll()}catch{}we(e=>[me(e)]),Tt(e=>e+1),_e(`graph-trash`)}).catch(n=>{let r=n instanceof Error?n.message:String(n);Ge(`Failed to delete: ${r}`),Ue(!0),window.setTimeout(()=>Ue(!1),ft);try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-drag-delete`,elementId:e,label:t,msg:r}),keepalive:!0}).catch(()=>{})}catch{}})},[s]),Gt=(0,j.useCallback)(e=>{Ge(null);let t=e.length;Promise.allSettled(e.map(e=>s(`/api/admin/graph-delete`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({elementId:e,by:`graph-drag-trash`})}).then(async t=>{let n=await t.json().catch(()=>({error:`HTTP ${t.status}`}));if(!t.ok)throw Error(n.error??`HTTP ${t.status}`);return e}))).then(e=>{let n=e.filter(e=>e.status===`rejected`);ze(null);try{f.current?.unselectAll()}catch{}if(we(e=>[me(e)]),Tt(e=>e+1),_e(`graph-trash`),n.length>0){let e=t-n.length;Ge(e===0?`Failed to delete ${t} node${t===1?``:`s`}.`:`Deleted ${e} of ${t}; ${n.length} failed.`),Ue(!0),window.setTimeout(()=>Ue(!1),ft);try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-drag-delete-batch`,total:t,failed:n.length}),keepalive:!0}).catch(()=>{})}catch{}}})},[s]),Kt=Ce[Ce.length-1],qt=(0,j.useMemo)(()=>pe(Ce),[Ce]),Jt=(0,j.useRef)(qt);(0,j.useEffect)(()=>{Jt.current=qt},[qt]);let Yt=(0,j.useRef)(Ce);(0,j.useEffect)(()=>{Yt.current=Ce},[Ce]),(0,j.useEffect)(()=>{if(Je){re.current?.abort(),re.current=null;return}let e=window.setTimeout(()=>{re.current?.abort();let e=new AbortController;re.current=e,I(!0),De(null),ke(null),s(le(Kt,{includeAgentActions:me(Ce).includeAgentActions,search:null}),{signal:e.signal}).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(e.status===413)throw new ht(t);if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(t=>{e.signal.aborted||(ne.current=new Map(t.nodes.map(e=>[e.id,e])),Ne(t.nodes.length),Ie(typeof t.total==`number`?t.total:null),Xt(t.nodes,t.edges))}).catch(t=>{if(!e.signal.aborted){if(t instanceof ht){ke(t.body),Ne(0),ne.current=new Map,Ut();return}De(t instanceof Error?t.message:String(t))}}).finally(()=>{e.signal.aborted||I(!1)})},dt);return()=>{window.clearTimeout(e)}},[c,qt,wt,u,Je,pt]),(0,j.useEffect)(()=>()=>{re.current?.abort(),y.current?.(),y.current=null,f.current?.destroy(),f.current=null,P.current!==null&&(clearTimeout(P.current),P.current=null)},[]);let Xt=(0,j.useCallback)((e,t)=>{if(!d.current)return;k.current=t;let n=new Set([`Message`,`UserMessage`,`AssistantMessage`]),r=e=>e.labels.some(e=>n.has(e)),i=new Map,a=e.filter(r);if(a.length>0){let e=new Set(a.map(e=>e.id)),n=new Map,r=new Set;for(let i of t)i.type===`NEXT`&&e.has(i.from)&&e.has(i.to)&&(n.set(i.from,i.to),r.add(i.to));let o=[],s=new Set;for(let e of a){if(r.has(e.id))continue;let t=e.id;for(;t&&!s.has(t);)s.add(t),o.push(t),t=n.get(t)}for(let e of a)s.has(e.id)||(o.push(e.id),s.add(e.id));let c=d.current?.clientWidth??1200,l=Math.max(c-160,300),u=Math.max(Math.floor(l/150),2);o.forEach((e,t)=>{let n=t%u,r=Math.floor(t/u);i.set(e,{x:n*150,y:r*90})})}let o=e.map(e=>{let t=e.labels[0]??`Unknown`,n=(0,w.resolveNodeColour)(e.labels);n.displayLabel;let r=n.colour;n.driftCandidates;let a=i.get(e.id),o=a?{x:a.x,y:a.y,physics:!1}:{};return e.trashed?{id:e.id,label:Ae(e,1),title:je(e),color:{background:`${r}40`,border:r},borderWidth:2,shapeProperties:{borderDashes:[6,4]},group:t,...o}:{id:e.id,label:Ae(e,1),title:je(e),color:r,group:t,...o}}),s=new Set(o.map(e=>e.id)),c=t.filter(e=>e.type!==`PART_OF`||s.has(e.from)&&s.has(e.to)).map(e=>({id:e.id,from:e.from,to:e.to,label:e.type})),l=Fe({nodes:e,edges:t});b.current=new ie.DataSet(l.nodePositions.size>0?o.map(e=>{if(e.x!==void 0||e.y!==void 0)return e;let t=l.nodePositions.get(e.id);return t?{...e,x:t.x,y:t.y,physics:!1}:e}):o),C.current=new ie.DataSet(c);let u={autoResize:!0,layout:{improvedLayout:!1,randomSeed:lt(Jt.current)},physics:l.physics===!1?!1:{solver:l.physics.solver,forceAtlas2Based:l.physics.forceAtlas2Based,stabilization:l.physics.stabilization},nodes:{shape:`dot`,size:18,font:{color:`#1F2937`,size:12,face:`DM Sans, sans-serif`},scaling:{label:{enabled:!0,min:12,max:30,drawThreshold:0}},borderWidth:0,chosen:{node:e=>{e.size=20,e.borderWidth=3,e.borderColor=`#0F172A`,e.shadow=!0,e.shadowColor=`rgba(15, 23, 42, 0.55)`,e.shadowSize=8,e.shadowX=0,e.shadowY=0},label:e=>{e.size=14}}},edges:{arrows:{to:{enabled:!0,scaleFactor:.4}},color:{color:`#CBD5E1`,highlight:`#475569`},font:{color:`#64748B`,size:9,face:`DM Sans, sans-serif`,align:`middle`,strokeWidth:0},smooth:{enabled:!0,type:`continuous`,roundness:.4},width:1,chosen:{edge:!0,label:!1}},interaction:{hover:!0,tooltipDelay:150,multiselect:!0}};try{y.current?.(),y.current=null,f.current?.destroy(),P.current!==null&&(clearTimeout(P.current),P.current=null),N.current=null;let e=new A.Network(d.current,{nodes:b.current,edges:C.current},u);f.current=e,l.physics!==!1&&(y.current=Re(e,{report:({avgMotion:e,settleMs:t,capped:n,nodeCount:r})=>{try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`event`,source:`graph-settle`,avgMotion:Math.round(e*100)/100,settleMs:t,capped:n,nodeCount:r}),keepalive:!0}).catch(()=>{})}catch{}}})),e.on(`zoom`,()=>{P.current!==null&&clearTimeout(P.current),P.current=setTimeout(()=>{P.current=null;let e=f.current,t=b.current;if(!e||!t)return;let n;try{n=e.getScale()}catch{return}let r=ot(n);if(r===N.current)return;N.current=r;let i=[];for(let e of ne.current.values()){if(!e.labels[0])continue;let{colour:t}=(0,w.resolveNodeColour)(e.labels),r=e.trashed?{background:`${t}40`,border:t}:t;i.push({id:e.id,label:Ae(e,n),color:r})}i.length>0&&t.update(i),console.error(`[graph-page] zoom-tier scale=${n.toFixed(3)} tier=${r} nodes=${i.length}`)},st)}),e.on(`click`,e=>{let t=e.nodes[0];if(!t)return;let n=ne.current.get(t);if(!n)return;if(ve(n)===`skip-trashed`){ze(n);return}let r=Yt.current[Yt.current.length-1];if(r.kind===`neighbourhood`&&r.rootElementId===t){ze(e=>e?.id===t?null:n);return}ze(null);let i={kind:`neighbourhood`,rootElementId:t,rootLabel:n.labels[0]??null};we(e=>{let n=ue(e,i),r=n.length-1;return n.length>e.length&&_t(`nav-push`,{depth:r,kind:i.kind,rootElementId:t}),n.length===10&&e.length===10&&_t(`view-stack-cap-hit`,{depth:10,rootElementId:t}),n})}),e.on(`deselectNode`,()=>{ze(null)});let t=e=>{let t=d.current,n=ae.current;if(!t||!n)return!1;let r=t.getBoundingClientRect(),i=n.getBoundingClientRect(),a=r.left+e.x,o=r.top+e.y;return a>=i.left&&a<=i.right&&o>=i.top&&o<=i.bottom},n=d.current?.parentElement??null;e.on(`dragStart`,e=>{if(e.nodes.length===0){oe.current=null,he.current=[];return}he.current=[...e.nodes],oe.current=e.nodes[0],n?.classList.add(`graph-dragging`)}),e.on(`dragging`,e=>{if(he.current.length===0)return;let n=t(e.pointer.DOM);Ve(e=>e===n?e:n)}),e.on(`dragEnd`,e=>{let r=he.current;if(he.current=[],oe.current=null,Ve(!1),n?.classList.remove(`graph-dragging`),r.length!==0&&t(e.pointer.DOM))if(r.length===1){let e=ne.current.get(r[0])?.labels[0]??`Unknown`;Wt(r[0],e)}else Gt(r)})}catch(e){let t=e instanceof Error?e.message:String(e);De(`Visualisation failed to load: ${t}`);try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-render`,msg:t}),keepalive:!0}).catch(()=>{})}catch{}}},[]);(0,j.useEffect)(()=>{let e=d.current;if(!e)return;let t=t=>{let n=xe.current,r=ge.current,i=e.parentElement;if(!n||!r||!i)return;let a=i.getBoundingClientRect(),o=Math.min(n.clientX,t.clientX)-a.left,s=Math.min(n.clientY,t.clientY)-a.top,c=Math.max(n.clientX,t.clientX)-a.left,l=Math.max(n.clientY,t.clientY)-a.top;r.style.left=`${o}px`,r.style.top=`${s}px`,r.style.width=`${c-o}px`,r.style.height=`${l-s}px`},n=r=>{document.removeEventListener(`mousemove`,t,!0),document.removeEventListener(`mouseup`,n,!0);let i=xe.current;xe.current=null;let a=ge.current;a&&(a.style.display=`none`);let o=f.current;if(!i||!o)return;let s=e.getBoundingClientRect(),c=i.clientX-s.left,l=i.clientY-s.top,u=r.clientX-s.left,d=r.clientY-s.top,p=Math.min(c,u),m=Math.min(l,d),h=Math.max(c,u),g=Math.max(l,d);if(h-p<3&&g-m<3)return;let _=o.getPositions(),v=[];for(let[e,t]of Object.entries(_)){let n=o.canvasToDOM(t);n.x>=p&&n.x<=h&&n.y>=m&&n.y<=g&&v.push(e)}try{o.selectNodes(v,!1)}catch{}},r=r=>{if(!r.shiftKey||r.button!==0)return;let i=f.current,a=e.parentElement;if(!i||!a)return;let o=e.getBoundingClientRect(),s={x:r.clientX-o.left,y:r.clientY-o.top};if(i.getNodeAt(s))return;r.preventDefault(),r.stopImmediatePropagation(),xe.current={clientX:r.clientX,clientY:r.clientY};let c=ge.current,l=a.getBoundingClientRect();c&&(c.style.display=`block`,c.style.left=`${r.clientX-l.left}px`,c.style.top=`${r.clientY-l.top}px`,c.style.width=`0px`,c.style.height=`0px`),document.addEventListener(`mousemove`,t,!0),document.addEventListener(`mouseup`,n,!0)};return e.addEventListener(`mousedown`,r,!0),()=>{e.removeEventListener(`mousedown`,r,!0),document.removeEventListener(`mousemove`,t,!0),document.removeEventListener(`mouseup`,n,!0)}},[]),(0,j.useEffect)(()=>{let e=Ke.trim();if(!e){Ye(``),Ze(null),$e(null),yt(`hybrid`),xt(0),Ct(!1),f.current?.unselectAll();return}Ct(!1);let t=setTimeout(()=>Ye(e),300);return()=>clearTimeout(t)},[Ke]),(0,j.useEffect)(()=>{let e=setTimeout(()=>{let e=Se(tt);mt(e);try{window.localStorage.setItem(ut,String(e))}catch{}},200);return()=>clearTimeout(e)},[tt]);let Zt=(0,j.useCallback)(e=>{let t=f.current,n=b.current;if(!t||!n)return;let{updates:r,inWindow:i}=ye(e,ne.current,w.resolveNodeColour,ct);r.length>0&&(n.update(r),t.fit({nodes:i,animation:{duration:400,easingFunction:`easeInOutQuad`}}))},[]),Qt=me(Ce);(0,j.useEffect)(()=>{if(!Je)return;let e=!1;return $e(null),s(M(Je,Qt.selectedLabels,pt,St)).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(t=>{if(e)return;Ze(t.results);let n=t.mode===`bm25`?`bm25`:`hybrid`;if(yt(n),xt(typeof t.suppressed==`number`?t.suppressed:0),n===`bm25`)try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-page`,msg:`[graph-page] search-result-degraded mode=bm25 query="${Je}"`}),keepalive:!0}).catch(()=>{})}catch{}let{nodes:r,edges:i}=be(t.results,Qt.selectedLabels);ne.current=new Map(r.map(e=>[e.id,e])),Ne(r.length),ke(null),Xt(r,i),Zt(t.results),console.info(`[graph-page] search-applied view=${Kt.kind} q="${Je}" labels=${Qt.selectedLabels.join(`|`)} hits=${r.length}`)}).catch(t=>{e||$e(t instanceof Error?t.message:String(t))}),()=>{e=!0}},[Je,pt,c,u,s,Zt,Kt.kind,Qt.selectedLabels,Xt,St]);let $t=(0,j.useCallback)(e=>{we(t=>{let n=me(t),r=new Set(n.selectedLabels);return r.has(e)?r.delete(e):r.add(e),fe({kind:`filter`,selectedLabels:[...r].sort(),includeTrashed:n.includeTrashed,includeAgentActions:n.includeAgentActions})})},[]),en=(0,j.useCallback)(()=>{we(e=>{let t=me(e);return fe({...t,includeTrashed:!t.includeTrashed})})},[]),tn=(0,j.useCallback)(()=>{we(e=>{let t=me(e);return fe({...t,includeAgentActions:!t.includeAgentActions})})},[]),nn=(0,j.useCallback)(()=>{qe(``),Ye(``),Ze(null),$e(null),yt(`hybrid`),xt(0),Ct(!1);try{f.current?.unselectAll()}catch{}},[]),rn=(0,j.useCallback)(()=>{we(()=>fe({kind:`filter`,selectedLabels:[],includeTrashed:!1,includeAgentActions:!1}))},[]),an=(0,j.useCallback)(()=>{ze(null);try{f.current?.unselectAll()}catch{}we(e=>{let t=de(e);return t!==e&&_t(`nav-pop`,{depth:t.length-1}),t})},[]),on=(0,j.useCallback)(()=>{ze(null);try{f.current?.unselectAll()}catch{}we(e=>e.length<=1?e:(_t(`nav-home`,{depth:0,popped:e.length-1}),[me(e)]))},[]),sn=(0,j.useCallback)(()=>{let e=me(Ce),t={labels:[...e.selectedLabels].sort(),includeTrashed:e.includeTrashed};Ft(!0),s(`/api/admin/graph-default-view`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(t)}).then(async e=>{if(!e.ok){let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));throw Error(t.error??`HTTP ${e.status}`)}jt(t)}).catch(e=>{let t=e instanceof Error?e.message:String(e);try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-default-view-save`,msg:t}),keepalive:!0}).catch(()=>{})}catch{}}).finally(()=>Ft(!1))},[s,Ce]),cn=(0,j.useCallback)(()=>{ze(null);try{f.current?.unselectAll()}catch{}Tt(e=>e+1),_e(`graph-restore`)},[]),ln=(0,j.useCallback)(()=>{ze(null);try{f.current?.unselectAll()}catch{}we(e=>[me(e)]),Tt(e=>e+1),_e(`graph-trash`)},[]),un=(0,j.useCallback)(()=>{Tt(e=>e+1),Dt(e=>e+1)},[]),dn=Kt.kind===`neighbourhood`,fn=me(Ce),pn=fn.selectedLabels,mn=fn.includeTrashed,hn=fn.includeAgentActions,gn=(0,j.useMemo)(()=>{if(mn!==At.includeTrashed||pn.length!==At.labels.length)return!0;for(let e=0;e<pn.length;e++)if(pn[e]!==At.labels[e])return!0;return!1},[mn,pn,At]);return(0,L.jsxs)(`div`,{ref:g,className:rt(p,a),children:[(0,L.jsxs)(`div`,{className:`graph-toolbar`,children:[Ce.length>1&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`button`,{type:`button`,className:`graph-home-to-filter graph-home-desktop`,onClick:on,title:`Clear breadcrumb — return to filter root`,children:[(0,L.jsx)(E,{size:12}),` Home`]}),(0,L.jsx)(`button`,{type:`button`,className:`graph-home-to-filter graph-home-mobile`,onClick:on,"aria-label":`Home`,title:`Clear breadcrumb — return to filter root`,children:(0,L.jsx)(E,{size:14})}),(0,L.jsx)(`button`,{type:`button`,className:`graph-back-to-filter graph-back-desktop`,onClick:an,children:`← Back`}),(0,L.jsx)(`button`,{type:`button`,className:`graph-back-to-filter graph-back-mobile`,onClick:an,"aria-label":`Back`,children:(0,L.jsx)(v,{size:16})})]}),(0,L.jsxs)(`div`,{className:`data-search-input graph-search-input`,children:[(0,L.jsx)(te,{size:14}),(0,L.jsx)(`input`,{type:`text`,placeholder:`Search nodes…`,value:Ke,onChange:e=>qe(e.target.value),autoComplete:`off`,spellCheck:!1}),Je&&!Xe&&!Qe&&(0,L.jsx)(o,{size:14,className:`spin`}),Ke.length>0&&(0,L.jsx)(`button`,{type:`button`,className:`graph-search-clear`,onClick:nn,"aria-label":`Clear search`,title:`Clear search`,children:(0,L.jsx)(i,{size:14})})]}),Je&&(0,L.jsxs)(`div`,{className:`graph-search-limit`,title:`Show top ${tt} matches (1-2000)`,children:[(0,L.jsx)(`label`,{htmlFor:`graph-search-limit-input`,className:`graph-search-limit-label`,children:`Top`}),(0,L.jsx)(`button`,{type:`button`,className:`graph-search-limit-step`,onClick:()=>nt(Se(tt-1)),disabled:tt<=1,"aria-label":`Decrement search limit`,title:`Decrement`,children:(0,L.jsx)(O,{size:12})}),(0,L.jsx)(`input`,{id:`graph-search-limit-input`,type:`number`,min:1,max:2e3,step:1,value:tt,onChange:e=>nt(Se(e.target.value)),className:`graph-search-limit-number`,"aria-label":`Maximum search results to render`}),(0,L.jsx)(`button`,{type:`button`,className:`graph-search-limit-step`,onClick:()=>nt(Se(tt+1)),disabled:tt>=2e3,"aria-label":`Increment search limit`,title:`Increment`,children:(0,L.jsx)(S,{size:12})}),(0,L.jsx)(`input`,{id:`graph-search-limit-slider`,type:`range`,min:1,max:2e3,step:1,value:tt,onChange:e=>nt(Se(e.target.value)),"aria-label":`Maximum search results to render (drag for ballpark)`})]}),(0,L.jsx)(`button`,{type:`button`,className:`graph-refresh-button`,onClick:un,disabled:F,"aria-label":`Refresh graph`,title:`Refresh graph`,children:(0,L.jsx)(x,{size:14,className:F?`spin`:void 0})}),it(a)&&(0,L.jsx)(`button`,{type:`button`,className:`graph-fullscreen-toggle`,onClick:()=>{p?Vt(`button`):m(!0)},"aria-label":p?`Exit full screen`:`Full screen`,title:p?`Exit full screen`:`Full screen`,"aria-pressed":p,children:p?(0,L.jsx)(D,{size:14}):(0,L.jsx)(ee,{size:14})}),!dn&&(0,L.jsxs)(`div`,{className:`graph-filter-wrap`,ref:Lt,children:[(0,L.jsxs)(`button`,{type:`button`,className:`graph-filter-toggle${Mt?` is-open`:``}${pn.length>0||mn||hn?` has-selection`:``}`,onClick:()=>Nt(e=>!e),"aria-haspopup":`true`,"aria-expanded":Mt,"aria-label":`Filter node types`,children:[(0,L.jsx)(h,{size:14}),(0,L.jsx)(`span`,{children:`Filter`}),pn.length>0&&(0,L.jsx)(`span`,{className:`graph-filter-count`,children:pn.length})]}),Mt&&(0,L.jsxs)(`div`,{className:`graph-filter-popover`,role:`dialog`,"aria-label":`Node type filter`,children:[(0,L.jsxs)(`div`,{className:`graph-filter-popover-header`,children:[(0,L.jsxs)(`button`,{type:`button`,className:`graph-toggle-trashed${mn?` active`:``}`,onClick:en,"aria-pressed":mn,title:`Show trashed nodes — restored with Restore button on each node`,children:[(0,L.jsx)(T,{size:14}),` Show trashed`]}),(pn.length>0||mn||hn)&&(0,L.jsx)(`button`,{type:`button`,className:`graph-filter-clear`,onClick:rn,"aria-label":`Clear filter selection`,title:`Clear filter selection`,children:(0,L.jsx)(i,{size:14})})]}),(0,L.jsx)(`div`,{className:`graph-toggle-agent-actions`,title:`Hide ToolCall, StepResult, WorkflowStep, WorkflowRun — agent-execution telemetry. Flip on for audit/debug.`,children:(0,L.jsx)(_,{checked:hn,onChange:tn,label:`Include agent actions`})}),Ot.length===0&&(0,L.jsx)(`p`,{className:`graph-filter-popover-empty`,children:`No node types in your graph yet.`}),(0,L.jsx)(`div`,{className:`graph-filter-rows`,role:`group`,"aria-label":`Node type filter`,children:Ot.map(({label:e,nodeCount:t})=>{let n=pn.includes(e),r=(0,w.colourForLabel)(e);return(0,L.jsxs)(`button`,{type:`button`,className:`graph-filter-row${n?` active`:``}`,onClick:()=>$t(e),"aria-pressed":n,children:[(0,L.jsx)(`span`,{className:`graph-filter-row-swatch`,style:{backgroundColor:r}}),(0,L.jsx)(`span`,{className:`graph-filter-row-label`,children:e}),(0,L.jsx)(`span`,{className:`graph-filter-row-count`,children:t})]},e)})}),(0,L.jsx)(`div`,{className:`graph-filter-popover-footer`,children:(0,L.jsx)(`button`,{type:`button`,className:`graph-filter-set-default`,onClick:sn,disabled:!gn||Pt,children:Pt?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(o,{size:12,className:`spin`}),` Saving…`]}):`Set default view`})})]})]}),(0,L.jsx)(`div`,{className:`graph-meta`,children:se({inNeighbourhood:dn,searchActive:!!Je,selectedLabelsCount:pn.length,topLevelTotal:Pe,nodeCount:Me})?(0,L.jsx)(`span`,{className:`graph-meta-count`,children:ce(Me,Pe)}):Me>0&&(0,L.jsxs)(`span`,{className:`graph-meta-count`,children:[Me,` node`,Me===1?``:`s`]})})]}),Ce.length>1&&(0,L.jsx)(gt,{viewStack:Ce}),Je&&vt===`bm25`&&!Qe&&(0,L.jsx)(`div`,{className:`graph-error-banner graph-search-degraded`,role:`status`,children:`Vector ranking unavailable — showing keyword-only results.`}),Qe&&(0,L.jsxs)(`div`,{className:`data-error graph-error-banner`,children:[`Search unavailable: `,Qe]}),Je&&bt>0&&!St&&!Qe&&(0,L.jsxs)(`button`,{type:`button`,className:`graph-search-suppressed`,onClick:()=>Ct(!0),children:[bt,` low-confidence match`,bt===1?``:`es`,` hidden — show all`]}),Je&&St&&!Qe&&(0,L.jsx)(`button`,{type:`button`,className:`graph-search-suppressed`,onClick:()=>Ct(!1),children:`Showing all matches — hide low-confidence`}),Xe&&Xe.length===0&&!Qe&&(0,L.jsx)(`div`,{className:`graph-search-status`,children:`No matches in your graph.`}),(0,L.jsxs)(`div`,{className:`graph-canvas-wrap`,children:[F&&(0,L.jsxs)(`div`,{className:`graph-canvas-overlay`,children:[(0,L.jsx)(o,{size:20,className:`spin`}),` Loading your graph…`]}),Ee&&!F&&(0,L.jsxs)(`div`,{className:`graph-canvas-overlay graph-canvas-error`,children:[(0,L.jsx)(`p`,{children:Ee}),(0,L.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:()=>{De(null),Tt(e=>e+1)},children:`Retry`})]}),Oe&&!F&&(0,L.jsxs)(`div`,{className:`graph-canvas-overlay graph-canvas-error`,children:[(0,L.jsxs)(`p`,{children:[`Refine your filter — `,(0,L.jsx)(`strong`,{children:Oe.matched}),` matches exceed the 2000 cap.`]}),(0,L.jsx)(`p`,{className:`graph-canvas-hint`,children:`Pick a more specific label combination, or narrow your brand's data.`})]}),!F&&!Ee&&!Oe&&Me===0&&!dn&&pn.length===0&&(0,L.jsxs)(`div`,{className:`graph-canvas-overlay`,children:[(0,L.jsx)(h,{size:20}),(0,L.jsx)(`p`,{children:`No nodes in your graph yet.`})]}),!F&&!Ee&&!Oe&&Me===0&&!dn&&pn.length>0&&(0,L.jsx)(`div`,{className:`graph-canvas-overlay`,children:(0,L.jsxs)(`p`,{children:[`No `,pn.join(`, `),` nodes match this view.`]})}),(0,L.jsx)(`div`,{ref:d,className:`graph-canvas`}),(0,L.jsx)(`div`,{ref:ge,className:`graph-marquee`,"aria-hidden":`true`}),Me>0&&(0,L.jsx)(`div`,{ref:ae,className:`graph-trash-drop-zone${Be?` is-hover`:``}${He?` is-error`:``}`,"aria-hidden":`true`,children:(0,L.jsx)(l,{size:18})}),We&&(0,L.jsxs)(`div`,{className:`graph-drag-error-banner`,role:`alert`,children:[(0,L.jsx)(`span`,{children:We}),(0,L.jsx)(`button`,{type:`button`,className:`graph-drag-error-dismiss`,onClick:()=>Ge(null),"aria-label":`Dismiss`,children:(0,L.jsx)(i,{size:14})})]})]}),Le&&(0,L.jsx)(et,{node:Le,edges:k.current,nodesById:ne.current,adminFetch:s,onClose:()=>{ze(null);try{f.current?.unselectAll()}catch{}},onRestored:cn,onTrashed:ln}),Me>0&&Rt.length>0&&(0,L.jsx)(`div`,{className:`graph-legend`,children:Rt.map(e=>(0,L.jsxs)(`div`,{className:`graph-legend-item`,children:[(0,L.jsx)(`span`,{className:`graph-legend-swatch`,style:{backgroundColor:(0,w.colourForLabel)(e)}}),(0,L.jsx)(`span`,{children:e})]},e))})]})}var ht=class extends Error{body;constructor(e){super(e.error),this.body=e}};function gt({viewStack:e}){let t=e.map(e=>e.kind===`filter`?`Filter`:e.rootLabel??`Node`);return(0,L.jsx)(`div`,{className:`graph-breadcrumb`,role:`navigation`,"aria-label":`Graph navigation breadcrumb`,children:t.map((e,n)=>(0,L.jsxs)(`span`,{className:`graph-breadcrumb-item`,children:[n>0&&(0,L.jsx)(`span`,{className:`graph-breadcrumb-separator`,"aria-hidden":`true`,children:`›`}),(0,L.jsx)(`span`,{className:`graph-breadcrumb-label${n===t.length-1?` is-current`:``}`,children:e})]},n))})}function _t(e,t){let n=`[graph-page] ${e} ${Object.entries(t).map(([e,t])=>`${e}=${String(t)}`).join(` `)}`;try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-nav`,msg:n}),keepalive:!0}).catch(()=>{})}catch{}}(0,ae.createRoot)(document.getElementById(`root`)).render((0,L.jsx)(pt,{}));
|
|
51
|
+
`)}var Me={solver:`forceAtlas2Based`,forceAtlas2Based:{gravitationalConstant:-50,centralGravity:.01,springLength:100,springConstant:.08,damping:.4,avoidOverlap:0},stabilization:{iterations:2e3}},Ne=220,Pe=3;function Fe(e){if(!(e.nodes.length<=5))return{physics:Me,nodePositions:new Map};let t=new Map,n=(Pe-1)*Ne/2,r=(Math.ceil(e.nodes.length/Pe)-1)*Ne/2;for(let i=0;i<e.nodes.length;i++){let a=i%Pe,o=Math.floor(i/Pe);t.set(e.nodes[i].id,{x:a*Ne-n,y:o*Ne-r})}return{physics:!1,nodePositions:t}}function Ie(e,t){let n=(t.t-e.t)/1e3;if(n<=0)return 0;let r=0,i=0;for(let n of Object.keys(t.positions)){let a=e.positions[n];if(!a)continue;let o=t.positions[n];r+=Math.hypot(o.x-a.x,o.y-a.y),i++}return i===0?0:r/i/n}function Le(e,t,n){if(t>n.threshold)return{belowCount:0,freeze:!1};let r=e+1;return{belowCount:r,freeze:r>=n.needed}}function Re(e,t){let n=Date.now(),r=null,i=0,a=null,o=()=>{a!==null&&(clearInterval(a),a=null)},s=(r,i,a)=>{o();try{e.setOptions({physics:!1})}catch{}t.report?.({avgMotion:r,settleMs:Date.now()-n,capped:a,nodeCount:i})};return a=setInterval(()=>{let t;try{t=e.getPositions()}catch{o();return}let a={t:Date.now(),positions:t},c=Object.keys(t).length;if(r){let e=Ie(r,a),t=Le(i,e,{threshold:5,needed:2});if(i=t.belowCount,t.freeze){s(e,c,!1);return}if(Date.now()-n>=3e4){s(e,c,!0);return}}r=a},250),o}var ze=`graph-side-panel-size`;function Be(e,t){let n=Math.max(320,t.maxWidth),r=Math.max(240,t.maxHeight),i=Math.min(Math.max(e.width,320),n),a=Math.min(Math.max(e.height,240),r);return{width:i,height:a,clampedW:i!==e.width,clampedH:a!==e.height}}function Ve(e){try{localStorage.setItem(ze,JSON.stringify({width:e.width,height:e.height}))}catch{}}function He(){try{let e=localStorage.getItem(ze);if(!e)return{size:null,source:`default`};let t=JSON.parse(e);return t&&typeof t==`object`&&typeof t.width==`number`&&typeof t.height==`number`&&Number.isFinite(t.width)&&Number.isFinite(t.height)?{size:{width:t.width,height:t.height},source:`storage`}:{size:null,source:`default`}}catch{return{size:null,source:`default`}}}function Ue(e){return typeof e==`string`?/^https?:\/\/\S+$/i.test(e.trim()):!1}function We(e){let t=t=>{let n=e[t];if(n&&typeof n==`object`&&`low`in n){let e=n.low;return typeof e==`number`?e:null}return null},n=t(`year`),r=t(`month`),i=t(`day`);if(n===null||r===null||i===null)return null;let a=`${String(n).padStart(4,`0`)}-${String(r).padStart(2,`0`)}-${String(i).padStart(2,`0`)}`;if(!(`hour`in e))return a;let o=t(`hour`),s=t(`minute`),c=t(`second`);return o===null||s===null||c===null?a:`${a} ${String(o).padStart(2,`0`)}:${String(s).padStart(2,`0`)}:${String(c).padStart(2,`0`)}`}function Ge(e){if(e==null)return``;if(Array.isArray(e))return e.length>8?`[${e.length} items]`:e.map(String).join(`, `);if(typeof e==`object`){if(`year`in e&&`month`in e&&`day`in e&&typeof e.year==`object`){let t=We(e);if(t)return t}return JSON.stringify(e)}return String(e)}var L=f(),Ke=76,qe=36,Je=16,Ye=520;function Xe(e){let t=e?.offsetParent??null,n=t?.clientWidth??0,r=t?.clientHeight??0;return{maxWidth:n-qe-Je,maxHeight:r-Ke-Je}}function Ze(e){return typeof e==`string`?e:Ge(e)}function Qe(e){return Ue(e)?(0,L.jsx)(`a`,{className:`graph-side-link`,href:e,target:`_blank`,rel:`noopener noreferrer`,children:e}):Ge(e)}function $e({value:e,label:t,field:n}){let{status:r,copy:i}=b({onResult:e=>{e?console.log(`[graph-panel] op=copy result=ok field=${n}`):console.warn(`[graph-panel] op=copy result=error field=${n} msg=clipboard-write-failed`)}}),a=r===`ok`?`Copied`:r===`fail`?`Copy failed`:`Copy ${t}`;return(0,L.jsxs)(`button`,{type:`button`,className:`graph-side-copy${r===`ok`?` graph-side-copy-ok`:``}${r===`fail`?` graph-side-copy-fail`:``}`,onClick:()=>i(e),"aria-label":a,title:a,children:[r===`ok`?(0,L.jsx)(c,{size:12}):(0,L.jsx)(y,{size:12}),r!==`idle`&&(0,L.jsx)(`span`,{className:`graph-side-copy-feedback`,children:r===`ok`?`Copied`:`Copy failed`})]})}function et({node:e,edges:t,nodesById:n,adminFetch:r,onClose:a,onRestored:s,onTrashed:c}){let u=Object.entries(e.properties).filter(([,e])=>e!=null),d=t.filter(t=>t.from===e.id||t.to===e.id),f=d.length>0,[p,h]=(0,j.useState)(!1),[g,_]=(0,j.useState)(null),[v,y]=(0,j.useState)(!1),[b,x]=(0,j.useState)(null),[S,ee]=(0,j.useState)(`properties`),te=m(`(max-width: 640px)`),w=(0,j.useRef)(null),ne=(0,j.useRef)(He()),[T,E]=(0,j.useState)(()=>ne.current.size??{width:320,height:Ye}),D=(0,j.useRef)(!1),O=(0,j.useRef)(null);(0,j.useEffect)(()=>()=>{O.current?.()},[]),(0,j.useEffect)(()=>{h(!1),_(null),y(!1),x(null),ee(`properties`)},[e.id]),(0,j.useLayoutEffect)(()=>{if(D.current)return;D.current=!0;let e=Xe(w.current),t=Be(ne.current.size??{width:320,height:Ye},e);E({width:t.width,height:t.height}),console.log(`[graph-panel] op=restore-size w=${t.width} h=${t.height} source=${ne.current.source}`)},[]);let k=(0,j.useCallback)(e=>{e.preventDefault();let t=e.clientX,n=e.clientY,r=T.width,i=T.height,a=Xe(w.current);try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}let o={width:r,height:i,clampedW:!1,clampedH:!1},s=e=>{o=Be({width:r+(t-e.clientX),height:i+(e.clientY-n)},a),E({width:o.width,height:o.height})},c=()=>{window.removeEventListener(`pointermove`,s),window.removeEventListener(`pointerup`,l),window.removeEventListener(`pointercancel`,l),O.current=null},l=()=>{c(),Ve({width:o.width,height:o.height}),console.log(`[graph-panel] op=resize w=${o.width} h=${o.height} clampedW=${o.clampedW} clampedH=${o.clampedH}`)};window.addEventListener(`pointermove`,s),window.addEventListener(`pointerup`,l),window.addEventListener(`pointercancel`,l),O.current=c},[T.width,T.height]),re=(0,j.useCallback)(()=>{h(!0),_(null),r(`/api/admin/graph-restore`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({elementId:e.id})}).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);s()}).catch(e=>{_(e instanceof Error?e.message:String(e)),h(!1)})},[e.id,s,r]),ie=(0,j.useCallback)(()=>{y(!0),x(null),r(`/api/admin/graph-delete`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({elementId:e.id,by:`graph-side-panel-trash`})}).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);c()}).catch(e=>{x(e instanceof Error?e.message:String(e)),y(!1)})},[e.id,c,r]),A=S===`connections`&&f?`connections`:`properties`,ae=te?void 0:{width:`${T.width}px`,height:`${T.height}px`};return(0,L.jsxs)(`aside`,{ref:w,className:`graph-side-panel${e.trashed?` graph-side-panel-trashed`:``}`,style:ae,children:[!te&&(0,L.jsx)(`div`,{className:`graph-side-resize-handle`,role:`separator`,"aria-label":`Resize panel`,"aria-orientation":`vertical`,onPointerDown:k}),(0,L.jsxs)(`header`,{className:`graph-side-header`,children:[(0,L.jsx)(`div`,{children:(()=>{if(e.labels.some(e=>P.has(e))){let t=(0,N.pickDisplayName)(e),n=e.properties.createdAt,r=typeof n==`string`?n:``,i=r?(0,N.formatRunTimestamp)(r):null,a=e.labels.join(` · `)+(e.trashed?` · Trashed`:``)+` · ${e.id}`;return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`h2`,{className:`graph-side-name`,title:t,children:t}),i&&(0,L.jsx)(`div`,{className:`graph-side-created`,children:i}),(0,L.jsxs)(`div`,{className:`graph-side-meta`,children:[(0,L.jsx)(`span`,{children:a}),(0,L.jsx)($e,{value:e.id,label:`id`,field:`id`})]})]})}return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`graph-side-labels`,children:[e.labels.join(` · `),e.trashed?` · Trashed`:``]}),(0,L.jsxs)(`div`,{className:`graph-side-id-row`,children:[(0,L.jsx)(`span`,{className:`graph-side-id`,children:e.id}),(0,L.jsx)($e,{value:e.id,label:`id`,field:`id`})]})]})})()}),(0,L.jsx)(`button`,{type:`button`,className:`graph-side-close`,onClick:a,"aria-label":`Close`,children:(0,L.jsx)(i,{size:14})})]}),e.trashed&&(0,L.jsxs)(`dl`,{className:`graph-side-props graph-side-trash-meta`,children:[(0,L.jsxs)(`div`,{className:`graph-side-prop`,children:[(0,L.jsx)(`dt`,{children:`trashedAt`}),(0,L.jsx)(`dd`,{children:Ge(e.properties.trashedAt)})]}),(0,L.jsxs)(`div`,{className:`graph-side-prop`,children:[(0,L.jsx)(`dt`,{children:`trashedBy`}),(0,L.jsx)(`dd`,{children:Ge(e.properties.trashedBy)})]})]}),(0,L.jsxs)(`div`,{className:`graph-side-tabs`,role:`tablist`,"aria-label":`Node detail sections`,children:[(0,L.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":A===`properties`,className:`graph-side-tab${A===`properties`?` graph-side-tab-on`:``}`,onClick:()=>ee(`properties`),children:`Properties`}),f&&(0,L.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":A===`connections`,className:`graph-side-tab${A===`connections`?` graph-side-tab-on`:``}`,onClick:()=>ee(`connections`),children:[`Connections (`,d.length,`)`]})]}),(0,L.jsxs)(`div`,{className:`graph-side-body`,children:[A===`properties`&&(0,L.jsxs)(`dl`,{className:`graph-side-props`,children:[u.length===0&&(0,L.jsx)(`div`,{className:`graph-side-empty`,children:`No properties.`}),u.map(([e,t])=>(0,L.jsxs)(`div`,{className:`graph-side-prop`,children:[(0,L.jsx)(`dt`,{children:e}),(0,L.jsxs)(`dd`,{children:[(0,L.jsx)(`span`,{className:`graph-side-prop-value`,children:Qe(t)}),(0,L.jsx)($e,{value:Ze(t),label:e,field:`prop`})]})]},e))]}),A===`connections`&&f&&(0,L.jsx)(`section`,{className:`graph-side-edges`,children:d.map(t=>{let r=t.from===e.id,i=r?t.to:t.from,a=n.get(i),o=a?(0,N.pickShortLabel)(a):i,s=r?`→`:`←`,c=Object.entries(t.properties??{}).filter(([,e])=>e!=null&&e!==``);return(0,L.jsxs)(`div`,{className:`graph-side-edge`,children:[(0,L.jsxs)(`div`,{className:`graph-side-edge-header`,children:[(0,L.jsx)(`span`,{className:`graph-side-edge-type`,children:t.type}),(0,L.jsx)(`span`,{className:`graph-side-edge-arrow`,children:s}),(0,L.jsx)(`span`,{className:`graph-side-edge-other`,title:o,children:o})]}),c.length>0&&(0,L.jsx)(`dl`,{className:`graph-side-edge-props`,children:c.map(([e,t])=>(0,L.jsxs)(`div`,{className:`graph-side-prop`,children:[(0,L.jsx)(`dt`,{children:e}),(0,L.jsxs)(`dd`,{children:[(0,L.jsx)(`span`,{className:`graph-side-prop-value`,children:Qe(t)}),(0,L.jsx)($e,{value:Ze(t),label:e,field:`edge-prop`})]})]},e))})]},t.id)})})]}),e.trashed&&(0,L.jsxs)(`footer`,{className:`graph-side-footer`,children:[!p&&!g&&(0,L.jsxs)(`button`,{type:`button`,className:`graph-side-restore`,onClick:re,children:[(0,L.jsx)(C,{size:14}),` Restore`]}),p&&(0,L.jsx)(`div`,{className:`graph-delete-confirm`,children:(0,L.jsxs)(`p`,{children:[(0,L.jsx)(o,{size:14,className:`spin`}),` Restoring…`]})}),g&&(0,L.jsxs)(`div`,{className:`graph-delete-confirm graph-delete-confirm-error`,children:[(0,L.jsxs)(`p`,{children:[`Restore failed: `,g]}),(0,L.jsxs)(`div`,{className:`graph-delete-confirm-buttons`,children:[(0,L.jsx)(`button`,{type:`button`,className:`graph-delete-confirm-cancel`,onClick:()=>{_(null)},children:`Close`}),(0,L.jsx)(`button`,{type:`button`,className:`graph-delete-confirm-do`,onClick:re,children:`Retry`})]})]})]}),!e.trashed&&(0,L.jsxs)(`footer`,{className:`graph-side-footer`,children:[!v&&!b&&(0,L.jsxs)(`button`,{type:`button`,className:`graph-side-trash`,onClick:ie,children:[(0,L.jsx)(l,{size:14}),` Trash`]}),v&&(0,L.jsx)(`div`,{className:`graph-delete-confirm`,children:(0,L.jsxs)(`p`,{children:[(0,L.jsx)(o,{size:14,className:`spin`}),` Trashing…`]})}),b&&(0,L.jsxs)(`div`,{className:`graph-delete-confirm graph-delete-confirm-error`,children:[(0,L.jsxs)(`p`,{children:[`Trash failed: `,b]}),(0,L.jsxs)(`div`,{className:`graph-delete-confirm-buttons`,children:[(0,L.jsx)(`button`,{type:`button`,className:`graph-delete-confirm-cancel`,onClick:()=>{x(null)},children:`Close`}),(0,L.jsx)(`button`,{type:`button`,className:`graph-delete-confirm-do`,onClick:ie,children:`Retry`})]})]})]})]})}var tt=`graph-shell`,nt=`graph-shell--fullscreen`;function rt(e,t){return t&&e?`${tt} ${nt}`:tt}function it(e){return e}function at(e){return e.isFullscreen&&!e.filterOpen}function ot(e){return e<.7?`compact`:e<1.3?`wrapped`:`detailed`}var st=150,ct=`#FBBF24`;function lt(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return t>>>0}var ut=`maxy-graph-search-limit-v1`,dt=250,ft=1200;function pt(){let[e,t]=(0,j.useState)(null),[n,r]=(0,j.useState)(!1),[i,s]=(0,j.useState)(void 0),[c,l]=(0,j.useState)(null),[d,f]=(0,j.useState)(void 0),[m,h]=(0,j.useState)(null),[_,v]=(0,j.useState)(null),y=(0,j.useMemo)(()=>typeof window>`u`?null:oe(window.location.search),[]),b=(0,j.useMemo)(()=>y?.kind===`focus`?{nodeId:y.nodeId,nodeLabel:y.nodeLabel}:null,[y]),x=(0,j.useMemo)(()=>y?.kind===`labels`?y.labels:null,[y]);(0,j.useEffect)(()=>{b&&_t(`deep-link`,{nodeId:b.nodeId.length>16?b.nodeId.slice(0,16)+`…`:b.nodeId,label:b.nodeLabel??``})},[b]),(0,j.useEffect)(()=>{!x||x.length===0||_t(`label-seed`,{label:x[0]})},[x]),(0,j.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!n){t(null),r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}if(i.ok)try{let e=await i.json();typeof e.businessName==`string`&&s(e.businessName),e.sessionId!==void 0&&l(e.sessionId??null),v(e.role??null),f(e.userName===void 0?null:e.userName),h(e.avatar??null)}catch{}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]);let S=(0,j.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]),[ee,C]=(0,j.useState)(!1),te=(0,j.useCallback)(async()=>{C(!0);try{let e=await p();if(e){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`}return e}finally{C(!1)}},[]);return n?e?(0,L.jsx)(u,{cacheKey:e,surface:`graph`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=graph`);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},children:(0,L.jsx)(g,{cacheKey:e,businessName:i,sessionId:c,onLogout:S,onDisconnect:te,disconnecting:ee,userName:d,userAvatar:m,role:_,children:(0,L.jsxs)(`div`,{className:`data-page graph-page`,children:[(0,L.jsx)(`header`,{className:`data-header`,children:(0,L.jsxs)(`h1`,{className:`data-title`,children:[(0,L.jsx)(a,{size:18}),` Graph`]})}),(0,L.jsx)(`main`,{className:`graph-main`,children:(0,L.jsx)(mt,{cacheKey:e,initialFocus:b,initialLabels:x,allowFullscreen:!0})})]})})}):(0,L.jsxs)(`div`,{className:`data-page`,children:[(0,L.jsx)(`header`,{className:`data-header`,children:(0,L.jsxs)(`h1`,{className:`data-title`,children:[(0,L.jsx)(a,{size:18}),` Graph`]})}),(0,L.jsxs)(`div`,{className:`data-empty`,children:[(0,L.jsx)(`p`,{children:`You are not signed in.`}),(0,L.jsxs)(`p`,{children:[`Open the `,(0,L.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})]}):(0,L.jsx)(`div`,{className:`data-page`,children:(0,L.jsxs)(`div`,{className:`data-loading`,children:[(0,L.jsx)(o,{size:18,className:`spin`}),` Loading…`]})})}function mt({cacheKey:e,initialFocus:t=null,initialLabels:r=null,allowFullscreen:a=!1}){let{adminFetch:s,cacheKey:c,sessionRefetchNonce:u}=n({initialCacheKey:e,surface:`graph`}),d=(0,j.useRef)(null),f=(0,j.useRef)(null),[p,m]=(0,j.useState)(!1),g=(0,j.useRef)(null),y=(0,j.useRef)(null),b=(0,j.useRef)(null),C=(0,j.useRef)(null),ne=(0,j.useRef)(new Map),k=(0,j.useRef)([]),re=(0,j.useRef)(null),ae=(0,j.useRef)(null),oe=(0,j.useRef)(null),he=(0,j.useRef)([]),ge=(0,j.useRef)(null),xe=(0,j.useRef)(null),N=(0,j.useRef)(null),P=(0,j.useRef)(null),Ce=(0,j.useRef)(!1),[we,Te]=(0,j.useState)([{kind:`filter`,selectedLabels:[],includeTrashed:!1,includeAgentActions:!1}]);(0,j.useEffect)(()=>{t?.nodeId&&Te(e=>{let n=e[e.length-1];return n.kind===`neighbourhood`&&n.rootElementId===t.nodeId?e:[e[0],{kind:`neighbourhood`,rootElementId:t.nodeId,rootLabel:t.nodeLabel}]})},[t?.nodeId,t?.nodeLabel]);let F=r&&r.length>0?[...r].sort().join(`,`):null;(0,j.useEffect)(()=>{F&&(Lt.current=!0,Te([{kind:`filter`,selectedLabels:F.split(`,`),includeTrashed:!1,includeAgentActions:!1}]))},[F]);let[I,Ee]=(0,j.useState)(!1),[De,Oe]=(0,j.useState)(null),[ke,Me]=(0,j.useState)(null),[Ne,Pe]=(0,j.useState)(0),[Ie,Le]=(0,j.useState)(null),[ze,Be]=(0,j.useState)(null),[Ve,He]=(0,j.useState)(!1),[Ue,We]=(0,j.useState)(!1),[Ge,Ke]=(0,j.useState)(null),[qe,Je]=(0,j.useState)(``),[Ye,Xe]=(0,j.useState)(``),[Ze,Qe]=(0,j.useState)(null),[$e,tt]=(0,j.useState)(null),[nt,pt]=(0,j.useState)(()=>{if(typeof window>`u`)return 100;let e=window.localStorage.getItem(ut);return e?Se(e):100}),[mt,vt]=(0,j.useState)(nt),[yt,bt]=(0,j.useState)(`hybrid`),[xt,St]=(0,j.useState)(0),[Ct,wt]=(0,j.useState)(!1),[Tt,Et]=(0,j.useState)(0),[Dt,Ot]=(0,j.useState)(0),[kt,At]=(0,j.useState)([]),[jt,Mt]=(0,j.useState)({labels:[],includeTrashed:!1}),[Nt,Pt]=(0,j.useState)(!1),[Ft,It]=(0,j.useState)(!1),Lt=(0,j.useRef)(!1),Rt=(0,j.useRef)(null),zt=(0,j.useMemo)(()=>{let e=new Set;for(let t of ne.current.values()){let n=(0,w.pickDisplayLabel)(t.labels);n&&e.add(n)}return[...e].sort()},[Ne]);(0,j.useEffect)(()=>{let e=!1,t=s(`/api/admin/graph-labels-in-graph`).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()}).catch(e=>{let t=e instanceof Error?e.message:String(e);try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-labels-in-graph`,msg:t}),keepalive:!0}).catch(()=>{})}catch{}return{labels:[]}}),n=s(`/api/admin/graph-default-view`).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()}).catch(e=>{let t=e instanceof Error?e.message:String(e);try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-default-view`,msg:t}),keepalive:!0}).catch(()=>{})}catch{}return{labels:[],includeTrashed:!1}});return Promise.all([t,n]).then(([t,n])=>{if(!e&&(At(t.labels),Mt(n),!Lt.current)){Lt.current=!0;let e=new Set(t.labels.map(e=>e.label)),r=n.labels.filter(t=>e.has(t));(r.length>0||n.includeTrashed)&&Te(e=>[{kind:`filter`,selectedLabels:r,includeTrashed:n.includeTrashed,includeAgentActions:!1},...e.slice(1)])}}),()=>{e=!0}},[c,u,s]);let Bt=we[0].kind===`filter`?we[0].includeAgentActions:!1;(0,j.useEffect)(()=>{if(!Lt.current)return;let e=!1;return s(`/api/admin/graph-labels-in-graph?includeAgentActions=${Bt?`1`:`0`}`).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()}).then(t=>{e||At(t.labels)}).catch(e=>{let t=e instanceof Error?e.message:String(e);try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-labels-in-graph-refetch`,msg:t}),keepalive:!0}).catch(()=>{})}catch{}}),()=>{e=!0}},[c,u,Bt,Dt,s]),(0,j.useEffect)(()=>{if(!Nt)return;let e=e=>{Rt.current&&(Rt.current.contains(e.target)||Pt(!1))},t=e=>{e.key===`Escape`&&Pt(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[Nt]);let Vt=(0,j.useCallback)((e,t)=>{try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:e,msg:t}),keepalive:!0}).catch(()=>{})}catch{}},[]),Ht=(0,j.useCallback)(e=>{console.log(`[graph-fullscreen] op=exit reason=${e}`),m(!1)},[]);(0,j.useEffect)(()=>{if(!a||!p)return;let e=e=>{e.key===`Escape`&&at({isFullscreen:p,filterOpen:Nt})&&Ht(`escape`)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[a,p,Nt,Ht]);let Ut=(0,j.useRef)(p);(0,j.useEffect)(()=>{if(!a)return;let e=Ut.current!==p;if(Ut.current=p,!e)return;let t=requestAnimationFrame(()=>{let e=f.current;try{e?.redraw()}catch{}if(!p)return;let t=g.current?.getBoundingClientRect(),n=window.innerWidth,r=window.innerHeight,i=t?Math.round(t.width):0,a=t?Math.round(t.height):0;console.log(`[graph-fullscreen] op=enter viewportW=${n} viewportH=${r} overlayW=${i} overlayH=${a}`),t&&(t.width<n-2||t.height<r-2)&&Vt(`graph-fullscreen-not-covering`,`op=enter viewportW=${n} viewportH=${r} overlayW=${i} overlayH=${a}`);try{let t=e?.canvas?.frame?.canvas,n=d.current;if(t&&n){let e=t.clientWidth,r=t.clientHeight,i=n.clientWidth,a=n.clientHeight;console.log(`[graph-fullscreen] op=resized canvasW=${e} canvasH=${r} containerW=${i} containerH=${a}`),(Math.abs(e-i)>2||Math.abs(r-a)>2)&&Vt(`graph-fullscreen-canvas-mismatch`,`canvasW=${e} canvasH=${r} containerW=${i} containerH=${a}`)}}catch{}});return()=>cancelAnimationFrame(t)},[a,p,Vt]);let Wt=(0,j.useCallback)(()=>{if(b.current)try{b.current.clear()}catch{}if(C.current)try{C.current.clear()}catch{}},[]),Gt=(0,j.useCallback)((e,t)=>{Ke(null),s(`/api/admin/graph-delete`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({elementId:e,by:`graph-drag-trash`})}).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);Be(null);try{f.current?.unselectAll()}catch{}Te(e=>[me(e)]),Et(e=>e+1),_e(`graph-trash`)}).catch(n=>{let r=n instanceof Error?n.message:String(n);Ke(`Failed to delete: ${r}`),We(!0),window.setTimeout(()=>We(!1),ft);try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-drag-delete`,elementId:e,label:t,msg:r}),keepalive:!0}).catch(()=>{})}catch{}})},[s]),Kt=(0,j.useCallback)(e=>{Ke(null);let t=e.length;Promise.allSettled(e.map(e=>s(`/api/admin/graph-delete`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({elementId:e,by:`graph-drag-trash`})}).then(async t=>{let n=await t.json().catch(()=>({error:`HTTP ${t.status}`}));if(!t.ok)throw Error(n.error??`HTTP ${t.status}`);return e}))).then(e=>{let n=e.filter(e=>e.status===`rejected`);Be(null);try{f.current?.unselectAll()}catch{}if(Te(e=>[me(e)]),Et(e=>e+1),_e(`graph-trash`),n.length>0){let e=t-n.length;Ke(e===0?`Failed to delete ${t} node${t===1?``:`s`}.`:`Deleted ${e} of ${t}; ${n.length} failed.`),We(!0),window.setTimeout(()=>We(!1),ft);try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-drag-delete-batch`,total:t,failed:n.length}),keepalive:!0}).catch(()=>{})}catch{}}})},[s]),qt=we[we.length-1],Jt=(0,j.useMemo)(()=>pe(we),[we]),Yt=(0,j.useRef)(Jt);(0,j.useEffect)(()=>{Yt.current=Jt},[Jt]);let Xt=(0,j.useRef)(we);(0,j.useEffect)(()=>{Xt.current=we},[we]),(0,j.useEffect)(()=>{if(Ye){re.current?.abort(),re.current=null;return}let e=window.setTimeout(()=>{re.current?.abort();let e=new AbortController;re.current=e,Ee(!0),Oe(null),Me(null),s(le(qt,{includeAgentActions:me(we).includeAgentActions,search:null}),{signal:e.signal}).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(e.status===413)throw new ht(t);if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(t=>{e.signal.aborted||(ne.current=new Map(t.nodes.map(e=>[e.id,e])),Pe(t.nodes.length),Le(typeof t.total==`number`?t.total:null),Zt(t.nodes,t.edges))}).catch(t=>{if(!e.signal.aborted){if(t instanceof ht){Me(t.body),Pe(0),ne.current=new Map,Wt();return}Oe(t instanceof Error?t.message:String(t))}}).finally(()=>{e.signal.aborted||Ee(!1)})},dt);return()=>{window.clearTimeout(e)}},[c,Jt,Tt,u,Ye,mt]),(0,j.useEffect)(()=>()=>{re.current?.abort(),y.current?.(),y.current=null,f.current?.destroy(),f.current=null,P.current!==null&&(clearTimeout(P.current),P.current=null)},[]);let Zt=(0,j.useCallback)((e,t)=>{if(!d.current)return;k.current=t;let n=new Set([`Message`,`UserMessage`,`AssistantMessage`]),r=e=>e.labels.some(e=>n.has(e)),i=new Map,a=e.filter(r);if(a.length>0){let e=new Set(a.map(e=>e.id)),n=new Map,r=new Set;for(let i of t)i.type===`NEXT`&&e.has(i.from)&&e.has(i.to)&&(n.set(i.from,i.to),r.add(i.to));let o=[],s=new Set;for(let e of a){if(r.has(e.id))continue;let t=e.id;for(;t&&!s.has(t);)s.add(t),o.push(t),t=n.get(t)}for(let e of a)s.has(e.id)||(o.push(e.id),s.add(e.id));let c=d.current?.clientWidth??1200,l=Math.max(c-160,300),u=Math.max(Math.floor(l/150),2);o.forEach((e,t)=>{let n=t%u,r=Math.floor(t/u);i.set(e,{x:n*150,y:r*90})})}let o=e.map(e=>{let t=e.labels[0]??`Unknown`,n=(0,w.resolveNodeColour)(e.labels);n.displayLabel;let r=n.colour;n.driftCandidates;let a=i.get(e.id),o=a?{x:a.x,y:a.y,physics:!1}:{};return e.trashed?{id:e.id,label:Ce.current?Ae(e,1):``,title:je(e),color:{background:`${r}40`,border:r},borderWidth:2,shapeProperties:{borderDashes:[6,4]},group:t,...o}:{id:e.id,label:Ce.current?Ae(e,1):``,title:je(e),color:r,group:t,...o}}),s=new Set(o.map(e=>e.id)),c=t.filter(e=>e.type!==`PART_OF`||s.has(e.from)&&s.has(e.to)).map(e=>({id:e.id,from:e.from,to:e.to,label:e.type})),l=Fe({nodes:e,edges:t});b.current=new ie.DataSet(l.nodePositions.size>0?o.map(e=>{if(e.x!==void 0||e.y!==void 0)return e;let t=l.nodePositions.get(e.id);return t?{...e,x:t.x,y:t.y,physics:!1}:e}):o),C.current=new ie.DataSet(c);let u={autoResize:!0,layout:{improvedLayout:!1,randomSeed:lt(Yt.current)},physics:l.physics===!1?!1:{solver:l.physics.solver,forceAtlas2Based:l.physics.forceAtlas2Based,stabilization:l.physics.stabilization},nodes:{shape:`dot`,size:18,font:{color:`#1F2937`,size:12,face:`DM Sans, sans-serif`},scaling:{label:{enabled:!0,min:12,max:30,drawThreshold:0}},borderWidth:0,chosen:{node:e=>{e.size=20,e.borderWidth=3,e.borderColor=`#0F172A`,e.shadow=!0,e.shadowColor=`rgba(15, 23, 42, 0.55)`,e.shadowSize=8,e.shadowX=0,e.shadowY=0},label:e=>{e.size=14}}},edges:{arrows:{to:{enabled:!0,scaleFactor:.4}},color:{color:`#CBD5E1`,highlight:`#475569`},font:{color:`#64748B`,size:9,face:`DM Sans, sans-serif`,align:`middle`,strokeWidth:0},smooth:{enabled:!0,type:`continuous`,roundness:.4},width:1,chosen:{edge:!0,label:!1}},interaction:{hover:!0,tooltipDelay:150,multiselect:!0}};try{y.current?.(),y.current=null,f.current?.destroy(),P.current!==null&&(clearTimeout(P.current),P.current=null),N.current=null;let e=new A.Network(d.current,{nodes:b.current,edges:C.current},u);f.current=e,l.physics!==!1&&(y.current=Re(e,{report:({avgMotion:e,settleMs:t,capped:n,nodeCount:r})=>{try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`event`,source:`graph-settle`,avgMotion:Math.round(e*100)/100,settleMs:t,capped:n,nodeCount:r}),keepalive:!0}).catch(()=>{})}catch{}}})),e.on(`zoom`,()=>{P.current!==null&&clearTimeout(P.current),P.current=setTimeout(()=>{P.current=null;let e=f.current,t=b.current;if(!e||!t)return;let n;try{n=e.getScale()}catch{return}let r=ot(n);if(r===N.current)return;N.current=r;let i=[];for(let e of ne.current.values()){if(!e.labels[0])continue;let{colour:t}=(0,w.resolveNodeColour)(e.labels),r=e.trashed?{background:`${t}40`,border:t}:t,a=Ce.current?Ae(e,n):``;i.push({id:e.id,label:a,color:r})}i.length>0&&t.update(i),console.error(`[graph-page] zoom-tier scale=${n.toFixed(3)} tier=${r} nodes=${i.length}`)},st)}),e.on(`click`,e=>{let t=e.nodes[0];if(!t)return;let n=ne.current.get(t);if(!n)return;if(ve(n)===`skip-trashed`){Be(n);return}let r=Xt.current[Xt.current.length-1];if(r.kind===`neighbourhood`&&r.rootElementId===t){Be(e=>e?.id===t?null:n);return}Be(null);let i={kind:`neighbourhood`,rootElementId:t,rootLabel:n.labels[0]??null};Te(e=>{let n=ue(e,i),r=n.length-1;return n.length>e.length&&_t(`nav-push`,{depth:r,kind:i.kind,rootElementId:t}),n.length===10&&e.length===10&&_t(`view-stack-cap-hit`,{depth:10,rootElementId:t}),n})}),e.on(`deselectNode`,()=>{Be(null)});let t=e=>{let t=d.current,n=ae.current;if(!t||!n)return!1;let r=t.getBoundingClientRect(),i=n.getBoundingClientRect(),a=r.left+e.x,o=r.top+e.y;return a>=i.left&&a<=i.right&&o>=i.top&&o<=i.bottom},n=d.current?.parentElement??null;e.on(`dragStart`,e=>{if(e.nodes.length===0){oe.current=null,he.current=[];return}he.current=[...e.nodes],oe.current=e.nodes[0],n?.classList.add(`graph-dragging`)}),e.on(`dragging`,e=>{if(he.current.length===0)return;let n=t(e.pointer.DOM);He(e=>e===n?e:n)}),e.on(`dragEnd`,e=>{let r=he.current;if(he.current=[],oe.current=null,He(!1),n?.classList.remove(`graph-dragging`),r.length!==0&&t(e.pointer.DOM))if(r.length===1){let e=ne.current.get(r[0])?.labels[0]??`Unknown`;Gt(r[0],e)}else Kt(r)})}catch(e){let t=e instanceof Error?e.message:String(e);Oe(`Visualisation failed to load: ${t}`);try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-render`,msg:t}),keepalive:!0}).catch(()=>{})}catch{}}},[]),Qt=(0,j.useCallback)(()=>{let e=f.current,t=b.current;if(!e||!t)return;let n;try{n=e.getScale()}catch{return}let r=[];for(let e of ne.current.values()){if(!e.labels[0])continue;let{colour:t}=(0,w.resolveNodeColour)(e.labels),i=e.trashed?{background:`${t}40`,border:t}:t;r.push({id:e.id,label:Ce.current?Ae(e,n):``,color:i})}r.length>0&&t.update(r)},[]),$t=(0,j.useCallback)(()=>{Ce.current||(Ce.current=!0,Qt())},[Qt]);(0,j.useEffect)(()=>{let e=g.current;if(!e)return;let t=()=>$t();return e.addEventListener(`pointerdown`,t,!0),e.addEventListener(`wheel`,t,!0),e.addEventListener(`keydown`,t,!0),()=>{e.removeEventListener(`pointerdown`,t,!0),e.removeEventListener(`wheel`,t,!0),e.removeEventListener(`keydown`,t,!0)}},[$t]),(0,j.useEffect)(()=>{let e=d.current;if(!e)return;let t=t=>{let n=xe.current,r=ge.current,i=e.parentElement;if(!n||!r||!i)return;let a=i.getBoundingClientRect(),o=Math.min(n.clientX,t.clientX)-a.left,s=Math.min(n.clientY,t.clientY)-a.top,c=Math.max(n.clientX,t.clientX)-a.left,l=Math.max(n.clientY,t.clientY)-a.top;r.style.left=`${o}px`,r.style.top=`${s}px`,r.style.width=`${c-o}px`,r.style.height=`${l-s}px`},n=r=>{document.removeEventListener(`mousemove`,t,!0),document.removeEventListener(`mouseup`,n,!0);let i=xe.current;xe.current=null;let a=ge.current;a&&(a.style.display=`none`);let o=f.current;if(!i||!o)return;let s=e.getBoundingClientRect(),c=i.clientX-s.left,l=i.clientY-s.top,u=r.clientX-s.left,d=r.clientY-s.top,p=Math.min(c,u),m=Math.min(l,d),h=Math.max(c,u),g=Math.max(l,d);if(h-p<3&&g-m<3)return;let _=o.getPositions(),v=[];for(let[e,t]of Object.entries(_)){let n=o.canvasToDOM(t);n.x>=p&&n.x<=h&&n.y>=m&&n.y<=g&&v.push(e)}try{o.selectNodes(v,!1)}catch{}},r=r=>{if(!r.shiftKey||r.button!==0)return;let i=f.current,a=e.parentElement;if(!i||!a)return;let o=e.getBoundingClientRect(),s={x:r.clientX-o.left,y:r.clientY-o.top};if(i.getNodeAt(s))return;r.preventDefault(),r.stopImmediatePropagation(),xe.current={clientX:r.clientX,clientY:r.clientY};let c=ge.current,l=a.getBoundingClientRect();c&&(c.style.display=`block`,c.style.left=`${r.clientX-l.left}px`,c.style.top=`${r.clientY-l.top}px`,c.style.width=`0px`,c.style.height=`0px`),document.addEventListener(`mousemove`,t,!0),document.addEventListener(`mouseup`,n,!0)};return e.addEventListener(`mousedown`,r,!0),()=>{e.removeEventListener(`mousedown`,r,!0),document.removeEventListener(`mousemove`,t,!0),document.removeEventListener(`mouseup`,n,!0)}},[]),(0,j.useEffect)(()=>{let e=qe.trim();if(!e){Xe(``),Qe(null),tt(null),bt(`hybrid`),St(0),wt(!1),f.current?.unselectAll();return}wt(!1);let t=setTimeout(()=>Xe(e),300);return()=>clearTimeout(t)},[qe]),(0,j.useEffect)(()=>{let e=setTimeout(()=>{let e=Se(nt);vt(e);try{window.localStorage.setItem(ut,String(e))}catch{}},200);return()=>clearTimeout(e)},[nt]);let en=(0,j.useCallback)(e=>{let t=f.current,n=b.current;if(!t||!n)return;let{updates:r,inWindow:i}=ye(e,ne.current,w.resolveNodeColour,ct);r.length>0&&(n.update(r),t.fit({nodes:i,animation:{duration:400,easingFunction:`easeInOutQuad`}}))},[]),tn=me(we);(0,j.useEffect)(()=>{if(!Ye)return;let e=!1;return tt(null),s(M(Ye,tn.selectedLabels,mt,Ct)).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(t=>{if(e)return;Qe(t.results);let n=t.mode===`bm25`?`bm25`:`hybrid`;if(bt(n),St(typeof t.suppressed==`number`?t.suppressed:0),n===`bm25`)try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-page`,msg:`[graph-page] search-result-degraded mode=bm25 query="${Ye}"`}),keepalive:!0}).catch(()=>{})}catch{}let{nodes:r,edges:i}=be(t.results,tn.selectedLabels);ne.current=new Map(r.map(e=>[e.id,e])),Pe(r.length),Me(null),Zt(r,i),en(t.results),console.info(`[graph-page] search-applied view=${qt.kind} q="${Ye}" labels=${tn.selectedLabels.join(`|`)} hits=${r.length}`)}).catch(t=>{e||tt(t instanceof Error?t.message:String(t))}),()=>{e=!0}},[Ye,mt,c,u,s,en,qt.kind,tn.selectedLabels,Zt,Ct]);let nn=(0,j.useCallback)(e=>{Te(t=>{let n=me(t),r=new Set(n.selectedLabels);return r.has(e)?r.delete(e):r.add(e),fe({kind:`filter`,selectedLabels:[...r].sort(),includeTrashed:n.includeTrashed,includeAgentActions:n.includeAgentActions})})},[]),rn=(0,j.useCallback)(()=>{Te(e=>{let t=me(e);return fe({...t,includeTrashed:!t.includeTrashed})})},[]),an=(0,j.useCallback)(()=>{Te(e=>{let t=me(e);return fe({...t,includeAgentActions:!t.includeAgentActions})})},[]),on=(0,j.useCallback)(()=>{Je(``),Xe(``),Qe(null),tt(null),bt(`hybrid`),St(0),wt(!1);try{f.current?.unselectAll()}catch{}},[]),sn=(0,j.useCallback)(()=>{Te(()=>fe({kind:`filter`,selectedLabels:[],includeTrashed:!1,includeAgentActions:!1}))},[]),cn=(0,j.useCallback)(()=>{Be(null);try{f.current?.unselectAll()}catch{}Te(e=>{let t=de(e);return t!==e&&_t(`nav-pop`,{depth:t.length-1}),t})},[]),ln=(0,j.useCallback)(()=>{Be(null);try{f.current?.unselectAll()}catch{}Te(e=>e.length<=1?e:(_t(`nav-home`,{depth:0,popped:e.length-1}),[me(e)]))},[]),un=(0,j.useCallback)(()=>{let e=me(we),t={labels:[...e.selectedLabels].sort(),includeTrashed:e.includeTrashed};It(!0),s(`/api/admin/graph-default-view`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(t)}).then(async e=>{if(!e.ok){let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));throw Error(t.error??`HTTP ${e.status}`)}Mt(t)}).catch(e=>{let t=e instanceof Error?e.message:String(e);try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-default-view-save`,msg:t}),keepalive:!0}).catch(()=>{})}catch{}}).finally(()=>It(!1))},[s,we]),dn=(0,j.useCallback)(()=>{Be(null);try{f.current?.unselectAll()}catch{}Et(e=>e+1),_e(`graph-restore`)},[]),fn=(0,j.useCallback)(()=>{Be(null);try{f.current?.unselectAll()}catch{}Te(e=>[me(e)]),Et(e=>e+1),_e(`graph-trash`)},[]),pn=(0,j.useCallback)(()=>{Et(e=>e+1),Ot(e=>e+1)},[]),mn=qt.kind===`neighbourhood`,hn=me(we),gn=hn.selectedLabels,_n=hn.includeTrashed,vn=hn.includeAgentActions,yn=(0,j.useMemo)(()=>{if(_n!==jt.includeTrashed||gn.length!==jt.labels.length)return!0;for(let e=0;e<gn.length;e++)if(gn[e]!==jt.labels[e])return!0;return!1},[_n,gn,jt]);return(0,L.jsxs)(`div`,{ref:g,className:rt(p,a),children:[(0,L.jsxs)(`div`,{className:`graph-toolbar`,children:[we.length>1&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`button`,{type:`button`,className:`graph-home-to-filter graph-home-desktop`,onClick:ln,title:`Clear breadcrumb — return to filter root`,children:[(0,L.jsx)(E,{size:12}),` Home`]}),(0,L.jsx)(`button`,{type:`button`,className:`graph-home-to-filter graph-home-mobile`,onClick:ln,"aria-label":`Home`,title:`Clear breadcrumb — return to filter root`,children:(0,L.jsx)(E,{size:14})}),(0,L.jsx)(`button`,{type:`button`,className:`graph-back-to-filter graph-back-desktop`,onClick:cn,children:`← Back`}),(0,L.jsx)(`button`,{type:`button`,className:`graph-back-to-filter graph-back-mobile`,onClick:cn,"aria-label":`Back`,children:(0,L.jsx)(v,{size:16})})]}),(0,L.jsxs)(`div`,{className:`data-search-input graph-search-input`,children:[(0,L.jsx)(te,{size:14}),(0,L.jsx)(`input`,{type:`text`,placeholder:`Search nodes…`,value:qe,onChange:e=>Je(e.target.value),autoComplete:`off`,spellCheck:!1}),Ye&&!Ze&&!$e&&(0,L.jsx)(o,{size:14,className:`spin`}),qe.length>0&&(0,L.jsx)(`button`,{type:`button`,className:`graph-search-clear`,onClick:on,"aria-label":`Clear search`,title:`Clear search`,children:(0,L.jsx)(i,{size:14})})]}),Ye&&(0,L.jsxs)(`div`,{className:`graph-search-limit`,title:`Show top ${nt} matches (1-2000)`,children:[(0,L.jsx)(`label`,{htmlFor:`graph-search-limit-input`,className:`graph-search-limit-label`,children:`Top`}),(0,L.jsx)(`button`,{type:`button`,className:`graph-search-limit-step`,onClick:()=>pt(Se(nt-1)),disabled:nt<=1,"aria-label":`Decrement search limit`,title:`Decrement`,children:(0,L.jsx)(O,{size:12})}),(0,L.jsx)(`input`,{id:`graph-search-limit-input`,type:`number`,min:1,max:2e3,step:1,value:nt,onChange:e=>pt(Se(e.target.value)),className:`graph-search-limit-number`,"aria-label":`Maximum search results to render`}),(0,L.jsx)(`button`,{type:`button`,className:`graph-search-limit-step`,onClick:()=>pt(Se(nt+1)),disabled:nt>=2e3,"aria-label":`Increment search limit`,title:`Increment`,children:(0,L.jsx)(S,{size:12})}),(0,L.jsx)(`input`,{id:`graph-search-limit-slider`,type:`range`,min:1,max:2e3,step:1,value:nt,onChange:e=>pt(Se(e.target.value)),"aria-label":`Maximum search results to render (drag for ballpark)`})]}),(0,L.jsx)(`button`,{type:`button`,className:`graph-refresh-button`,onClick:pn,disabled:I,"aria-label":`Refresh graph`,title:`Refresh graph`,children:(0,L.jsx)(x,{size:14,className:I?`spin`:void 0})}),it(a)&&(0,L.jsx)(`button`,{type:`button`,className:`graph-fullscreen-toggle`,onClick:()=>{p?Ht(`button`):m(!0)},"aria-label":p?`Exit full screen`:`Full screen`,title:p?`Exit full screen`:`Full screen`,"aria-pressed":p,children:p?(0,L.jsx)(D,{size:14}):(0,L.jsx)(ee,{size:14})}),!mn&&(0,L.jsxs)(`div`,{className:`graph-filter-wrap`,ref:Rt,children:[(0,L.jsxs)(`button`,{type:`button`,className:`graph-filter-toggle${Nt?` is-open`:``}${gn.length>0||_n||vn?` has-selection`:``}`,onClick:()=>Pt(e=>!e),"aria-haspopup":`true`,"aria-expanded":Nt,"aria-label":`Filter node types`,children:[(0,L.jsx)(h,{size:14}),(0,L.jsx)(`span`,{children:`Filter`}),gn.length>0&&(0,L.jsx)(`span`,{className:`graph-filter-count`,children:gn.length})]}),Nt&&(0,L.jsxs)(`div`,{className:`graph-filter-popover`,role:`dialog`,"aria-label":`Node type filter`,children:[(0,L.jsxs)(`div`,{className:`graph-filter-popover-header`,children:[(0,L.jsxs)(`button`,{type:`button`,className:`graph-toggle-trashed${_n?` active`:``}`,onClick:rn,"aria-pressed":_n,title:`Show trashed nodes — restored with Restore button on each node`,children:[(0,L.jsx)(T,{size:14}),` Show trashed`]}),(gn.length>0||_n||vn)&&(0,L.jsx)(`button`,{type:`button`,className:`graph-filter-clear`,onClick:sn,"aria-label":`Clear filter selection`,title:`Clear filter selection`,children:(0,L.jsx)(i,{size:14})})]}),(0,L.jsx)(`div`,{className:`graph-toggle-agent-actions`,title:`Hide ToolCall, StepResult, WorkflowStep, WorkflowRun — agent-execution telemetry. Flip on for audit/debug.`,children:(0,L.jsx)(_,{checked:vn,onChange:an,label:`Include agent actions`})}),kt.length===0&&(0,L.jsx)(`p`,{className:`graph-filter-popover-empty`,children:`No node types in your graph yet.`}),(0,L.jsx)(`div`,{className:`graph-filter-rows`,role:`group`,"aria-label":`Node type filter`,children:kt.map(({label:e,nodeCount:t})=>{let n=gn.includes(e),r=(0,w.colourForLabel)(e);return(0,L.jsxs)(`button`,{type:`button`,className:`graph-filter-row${n?` active`:``}`,onClick:()=>nn(e),"aria-pressed":n,children:[(0,L.jsx)(`span`,{className:`graph-filter-row-swatch`,style:{backgroundColor:r}}),(0,L.jsx)(`span`,{className:`graph-filter-row-label`,children:e}),(0,L.jsx)(`span`,{className:`graph-filter-row-count`,children:t})]},e)})}),(0,L.jsx)(`div`,{className:`graph-filter-popover-footer`,children:(0,L.jsx)(`button`,{type:`button`,className:`graph-filter-set-default`,onClick:un,disabled:!yn||Ft,children:Ft?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(o,{size:12,className:`spin`}),` Saving…`]}):`Set default view`})})]})]}),(0,L.jsx)(`div`,{className:`graph-meta`,children:se({inNeighbourhood:mn,searchActive:!!Ye,selectedLabelsCount:gn.length,topLevelTotal:Ie,nodeCount:Ne})?(0,L.jsx)(`span`,{className:`graph-meta-count`,children:ce(Ne,Ie)}):Ne>0&&(0,L.jsxs)(`span`,{className:`graph-meta-count`,children:[Ne,` node`,Ne===1?``:`s`]})})]}),we.length>1&&(0,L.jsx)(gt,{viewStack:we}),Ye&&yt===`bm25`&&!$e&&(0,L.jsx)(`div`,{className:`graph-error-banner graph-search-degraded`,role:`status`,children:`Vector ranking unavailable — showing keyword-only results.`}),$e&&(0,L.jsxs)(`div`,{className:`data-error graph-error-banner`,children:[`Search unavailable: `,$e]}),Ye&&xt>0&&!Ct&&!$e&&(0,L.jsxs)(`button`,{type:`button`,className:`graph-search-suppressed`,onClick:()=>wt(!0),children:[xt,` low-confidence match`,xt===1?``:`es`,` hidden — show all`]}),Ye&&Ct&&!$e&&(0,L.jsx)(`button`,{type:`button`,className:`graph-search-suppressed`,onClick:()=>wt(!1),children:`Showing all matches — hide low-confidence`}),Ze&&Ze.length===0&&!$e&&(0,L.jsx)(`div`,{className:`graph-search-status`,children:`No matches in your graph.`}),(0,L.jsxs)(`div`,{className:`graph-canvas-wrap`,children:[I&&(0,L.jsxs)(`div`,{className:`graph-canvas-overlay`,children:[(0,L.jsx)(o,{size:20,className:`spin`}),` Loading your graph…`]}),De&&!I&&(0,L.jsxs)(`div`,{className:`graph-canvas-overlay graph-canvas-error`,children:[(0,L.jsx)(`p`,{children:De}),(0,L.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:()=>{Oe(null),Et(e=>e+1)},children:`Retry`})]}),ke&&!I&&(0,L.jsxs)(`div`,{className:`graph-canvas-overlay graph-canvas-error`,children:[(0,L.jsxs)(`p`,{children:[`Refine your filter — `,(0,L.jsx)(`strong`,{children:ke.matched}),` matches exceed the 2000 cap.`]}),(0,L.jsx)(`p`,{className:`graph-canvas-hint`,children:`Pick a more specific label combination, or narrow your brand's data.`})]}),!I&&!De&&!ke&&Ne===0&&!mn&&gn.length===0&&(0,L.jsxs)(`div`,{className:`graph-canvas-overlay`,children:[(0,L.jsx)(h,{size:20}),(0,L.jsx)(`p`,{children:`No nodes in your graph yet.`})]}),!I&&!De&&!ke&&Ne===0&&!mn&&gn.length>0&&(0,L.jsx)(`div`,{className:`graph-canvas-overlay`,children:(0,L.jsxs)(`p`,{children:[`No `,gn.join(`, `),` nodes match this view.`]})}),(0,L.jsx)(`div`,{ref:d,className:`graph-canvas`}),(0,L.jsx)(`div`,{ref:ge,className:`graph-marquee`,"aria-hidden":`true`}),Ne>0&&(0,L.jsx)(`div`,{ref:ae,className:`graph-trash-drop-zone${Ve?` is-hover`:``}${Ue?` is-error`:``}`,"aria-hidden":`true`,children:(0,L.jsx)(l,{size:18})}),Ge&&(0,L.jsxs)(`div`,{className:`graph-drag-error-banner`,role:`alert`,children:[(0,L.jsx)(`span`,{children:Ge}),(0,L.jsx)(`button`,{type:`button`,className:`graph-drag-error-dismiss`,onClick:()=>Ke(null),"aria-label":`Dismiss`,children:(0,L.jsx)(i,{size:14})})]})]}),ze&&(0,L.jsx)(et,{node:ze,edges:k.current,nodesById:ne.current,adminFetch:s,onClose:()=>{Be(null);try{f.current?.unselectAll()}catch{}},onRestored:dn,onTrashed:fn}),Ne>0&&zt.length>0&&(0,L.jsx)(`div`,{className:`graph-legend`,children:zt.map(e=>(0,L.jsxs)(`div`,{className:`graph-legend-item`,children:[(0,L.jsx)(`span`,{className:`graph-legend-swatch`,style:{backgroundColor:(0,w.colourForLabel)(e)}}),(0,L.jsx)(`span`,{children:e})]},e))})]})}var ht=class extends Error{body;constructor(e){super(e.error),this.body=e}};function gt({viewStack:e}){let t=e.map(e=>e.kind===`filter`?`Filter`:e.rootLabel??`Node`);return(0,L.jsx)(`div`,{className:`graph-breadcrumb`,role:`navigation`,"aria-label":`Graph navigation breadcrumb`,children:t.map((e,n)=>(0,L.jsxs)(`span`,{className:`graph-breadcrumb-item`,children:[n>0&&(0,L.jsx)(`span`,{className:`graph-breadcrumb-separator`,"aria-hidden":`true`,children:`›`}),(0,L.jsx)(`span`,{className:`graph-breadcrumb-label${n===t.length-1?` is-current`:``}`,children:e})]},n))})}function _t(e,t){let n=`[graph-page] ${e} ${Object.entries(t).map(([e,t])=>`${e}=${String(t)}`).join(` `)}`;try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-nav`,msg:n}),keepalive:!0}).catch(()=>{})}catch{}}(0,ae.createRoot)(document.getElementById(`root`)).render((0,L.jsx)(pt,{}));
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>Graph — Maxy</title>
|
|
7
7
|
<link rel="icon" href="/favicon.ico">
|
|
8
|
-
<script type="module" crossorigin src="/assets/graph-
|
|
8
|
+
<script type="module" crossorigin src="/assets/graph-CboWM2_-.js"></script>
|
|
9
9
|
<link rel="modulepreload" crossorigin href="/assets/chunk-Ck5AOu5v.js">
|
|
10
10
|
<link rel="modulepreload" crossorigin href="/assets/useSubAccountSwitcher-DLJFISqf.js">
|
|
11
11
|
<link rel="modulepreload" crossorigin href="/assets/graph-labels-B8YAdo3Z.js">
|
package/payload/server/server.js
CHANGED
|
@@ -8273,6 +8273,7 @@ function pickOwnerUserId(admins) {
|
|
|
8273
8273
|
function resolveOwnerUserId(accountId) {
|
|
8274
8274
|
try {
|
|
8275
8275
|
const account = listValidAccounts().find((a) => a.accountId === accountId);
|
|
8276
|
+
if (account?.config.role === "client") return null;
|
|
8276
8277
|
return pickOwnerUserId(account?.config.admins ?? []);
|
|
8277
8278
|
} catch {
|
|
8278
8279
|
return null;
|
|
@@ -8283,6 +8284,7 @@ function resolveAdminUserId(params) {
|
|
|
8283
8284
|
const users = readUsersFile(USERS_FILE);
|
|
8284
8285
|
if (!users) return null;
|
|
8285
8286
|
const account = listValidAccounts().find((a) => a.accountId === params.accountId);
|
|
8287
|
+
if (account?.config.role === "client") return null;
|
|
8286
8288
|
const admins = account?.config.admins ?? [];
|
|
8287
8289
|
const direct = pickAdminUserId(users, admins, params.senderPhone);
|
|
8288
8290
|
if (direct) return direct;
|
|
@@ -25921,6 +25923,73 @@ console.log(`${BRAND.productName} listening on http://${hostname}:${port}`);
|
|
|
25921
25923
|
const loop = setInterval(runReconcile, RECONCILE_INTERVAL_MS);
|
|
25922
25924
|
loop.unref();
|
|
25923
25925
|
}
|
|
25926
|
+
{
|
|
25927
|
+
const publishPlatformRoot = process.env.MAXY_PLATFORM_ROOT ?? join36(__dirname, "..");
|
|
25928
|
+
const publishScript = resolve33(publishPlatformRoot, "plugins/scheduling/mcp/dist/scripts/publish-availability.js");
|
|
25929
|
+
const PUBLISH_INTERVAL_MS = 3e5;
|
|
25930
|
+
const currentAccount = () => {
|
|
25931
|
+
try {
|
|
25932
|
+
return resolveAccount();
|
|
25933
|
+
} catch (err) {
|
|
25934
|
+
console.error(`[calendar-availability] op=publish result=error reason=account-resolve-failed err="${err.message}"`);
|
|
25935
|
+
return null;
|
|
25936
|
+
}
|
|
25937
|
+
};
|
|
25938
|
+
const spawnPublish = (account) => {
|
|
25939
|
+
if (!existsSync35(publishScript)) return;
|
|
25940
|
+
try {
|
|
25941
|
+
const child = spawn3(process.execPath, [publishScript], {
|
|
25942
|
+
env: {
|
|
25943
|
+
...process.env,
|
|
25944
|
+
PLATFORM_ROOT: publishPlatformRoot,
|
|
25945
|
+
PUBLISH_ACCOUNT_ID: account.accountId,
|
|
25946
|
+
PUBLISH_ACCOUNT_DIR: account.accountDir
|
|
25947
|
+
},
|
|
25948
|
+
stdio: "inherit"
|
|
25949
|
+
});
|
|
25950
|
+
child.unref();
|
|
25951
|
+
child.on("error", (err) => console.error(`[calendar-availability] op=publish result=error reason=spawn-failed err="${err.message}"`));
|
|
25952
|
+
} catch (err) {
|
|
25953
|
+
console.error(`[calendar-availability] op=publish result=error reason=spawn-failed err="${err.message}"`);
|
|
25954
|
+
}
|
|
25955
|
+
};
|
|
25956
|
+
const auditSnapshotAge = (account) => {
|
|
25957
|
+
const availPath = resolve33(account.accountDir, "calendar-availability.json");
|
|
25958
|
+
let hasBookingSite = false;
|
|
25959
|
+
try {
|
|
25960
|
+
if (existsSync35(availPath)) {
|
|
25961
|
+
const cfg = JSON.parse(readFileSync35(availPath, "utf-8"));
|
|
25962
|
+
hasBookingSite = typeof cfg.bookingDbName === "string" && cfg.bookingDbName.length > 0;
|
|
25963
|
+
}
|
|
25964
|
+
} catch {
|
|
25965
|
+
}
|
|
25966
|
+
if (!hasBookingSite) return;
|
|
25967
|
+
const statePath = resolve33(account.accountDir, "state", "booking-availability", "last-publish.json");
|
|
25968
|
+
let lastSuccessAt = null;
|
|
25969
|
+
if (existsSync35(statePath)) {
|
|
25970
|
+
try {
|
|
25971
|
+
const rec = JSON.parse(readFileSync35(statePath, "utf-8"));
|
|
25972
|
+
lastSuccessAt = rec.lastSuccessAt ?? null;
|
|
25973
|
+
} catch {
|
|
25974
|
+
console.error(`[calendar-availability] op=audit accountId=${account.accountId} snapshotAgeMs=na reason=bad-state-file`);
|
|
25975
|
+
return;
|
|
25976
|
+
}
|
|
25977
|
+
}
|
|
25978
|
+
const parsed = lastSuccessAt ? Date.parse(lastSuccessAt) : NaN;
|
|
25979
|
+
const ageMs = Number.isNaN(parsed) ? null : Date.now() - parsed;
|
|
25980
|
+
console.error(`[calendar-availability] op=audit accountId=${account.accountId} snapshotAgeMs=${ageMs ?? "na"}`);
|
|
25981
|
+
};
|
|
25982
|
+
const publishTick = () => {
|
|
25983
|
+
const account = currentAccount();
|
|
25984
|
+
if (!account) return;
|
|
25985
|
+
spawnPublish(account);
|
|
25986
|
+
auditSnapshotAge(account);
|
|
25987
|
+
};
|
|
25988
|
+
const firstPublish = setTimeout(publishTick, 2e4);
|
|
25989
|
+
firstPublish.unref();
|
|
25990
|
+
const publishLoop = setInterval(publishTick, PUBLISH_INTERVAL_MS);
|
|
25991
|
+
publishLoop.unref();
|
|
25992
|
+
}
|
|
25924
25993
|
startTimeEntryCensus(() => getSession());
|
|
25925
25994
|
{
|
|
25926
25995
|
const auditPlatformRoot = process.env.MAXY_PLATFORM_ROOT ?? join36(__dirname, "..");
|