@rubytech/create-maxy 1.0.744 → 1.0.745

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.
Files changed (26) hide show
  1. package/package.json +1 -1
  2. package/payload/platform/lib/graph-mcp/dist/cypher-rewrite-stamp.d.ts +37 -0
  3. package/payload/platform/lib/graph-mcp/dist/cypher-rewrite-stamp.d.ts.map +1 -0
  4. package/payload/platform/lib/graph-mcp/dist/cypher-rewrite-stamp.js +333 -0
  5. package/payload/platform/lib/graph-mcp/dist/cypher-rewrite-stamp.js.map +1 -0
  6. package/payload/platform/lib/graph-mcp/dist/cypher-shim-write.d.ts +71 -0
  7. package/payload/platform/lib/graph-mcp/dist/cypher-shim-write.d.ts.map +1 -0
  8. package/payload/platform/lib/graph-mcp/dist/cypher-shim-write.js +168 -0
  9. package/payload/platform/lib/graph-mcp/dist/cypher-shim-write.js.map +1 -0
  10. package/payload/platform/lib/graph-mcp/dist/index.js +146 -3
  11. package/payload/platform/lib/graph-mcp/dist/index.js.map +1 -1
  12. package/payload/platform/lib/graph-mcp/dist/schema-cache.d.ts +3 -6
  13. package/payload/platform/lib/graph-mcp/dist/schema-cache.d.ts.map +1 -1
  14. package/payload/platform/lib/graph-mcp/dist/schema-cache.js +30 -7
  15. package/payload/platform/lib/graph-mcp/dist/schema-cache.js.map +1 -1
  16. package/payload/platform/lib/graph-mcp/src/cypher-rewrite-stamp.ts +349 -0
  17. package/payload/platform/lib/graph-mcp/src/cypher-shim-write.ts +240 -0
  18. package/payload/platform/lib/graph-mcp/src/index.ts +216 -4
  19. package/payload/platform/lib/graph-mcp/src/schema-cache.ts +37 -7
  20. package/payload/platform/plugins/docs/references/deployment.md +2 -1
  21. package/payload/platform/templates/specialists/agents/database-operator.md +3 -22
  22. package/payload/server/chunk-SPTD7L7Z.js +9474 -0
  23. package/payload/server/maxy-edge.js +1 -1
  24. package/payload/server/public/assets/{graph-DhNy70eS.js → graph-BoSJpLG3.js} +1 -1
  25. package/payload/server/public/graph.html +1 -1
  26. package/payload/server/server.js +1 -1
@@ -16,7 +16,7 @@ import {
16
16
  sanitizeClientCorrId,
17
17
  streamActionEvents,
18
18
  vncLog
19
- } from "./chunk-2T4RRIJK.js";
19
+ } from "./chunk-SPTD7L7Z.js";
20
20
  import "./chunk-TXPEEAV6.js";
21
21
 
22
22
  // server/edge.ts
@@ -47,4 +47,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
47
47
  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 XT(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}var ZT=function(e){function n(e){t(this,n),this._pairs=e}return Yu(n,[{key:e,value:vC.mark((function e(){var t,n,r,i,a;return vC.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=YT(this._pairs),e.prev=1,t.s();case 3:if((n=t.n()).done){e.next=9;break}return r=Bp(n.value,2),i=r[0],a=r[1],e.next=7,[i,a];case 7:e.next=3;break;case 9:e.next=14;break;case 11:e.prev=11,e.t0=e.catch(1),t.e(e.t0);case 14:return e.prev=14,t.f(),e.finish(14);case 17:case`end`:return e.stop()}}),e,this,[[1,11,14,17]])}))},{key:`entries`,value:vC.mark((function e(){var t,n,r,i,a;return vC.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=YT(this._pairs),e.prev=1,t.s();case 3:if((n=t.n()).done){e.next=9;break}return r=Bp(n.value,2),i=r[0],a=r[1],e.next=7,[i,a];case 7:e.next=3;break;case 9:e.next=14;break;case 11:e.prev=11,e.t0=e.catch(1),t.e(e.t0);case 14:return e.prev=14,t.f(),e.finish(14);case 17:case`end`:return e.stop()}}),e,this,[[1,11,14,17]])}))},{key:`keys`,value:vC.mark((function e(){var t,n,r,i;return vC.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=YT(this._pairs),e.prev=1,t.s();case 3:if((n=t.n()).done){e.next=9;break}return r=Bp(n.value,1),i=r[0],e.next=7,i;case 7:e.next=3;break;case 9:e.next=14;break;case 11:e.prev=11,e.t0=e.catch(1),t.e(e.t0);case 14:return e.prev=14,t.f(),e.finish(14);case 17:case`end`:return e.stop()}}),e,this,[[1,11,14,17]])}))},{key:`values`,value:vC.mark((function e(){var t,n,r,i;return vC.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=YT(this._pairs),e.prev=1,t.s();case 3:if((n=t.n()).done){e.next=9;break}return r=Bp(n.value,2),i=r[1],e.next=7,i;case 7:e.next=3;break;case 9:e.next=14;break;case 11:e.prev=11,e.t0=e.catch(1),t.e(e.t0);case 14:return e.prev=14,t.f(),e.finish(14);case 17:case`end`:return e.stop()}}),e,this,[[1,11,14,17]])}))},{key:`toIdArray`,value:function(){var e;return Gd(e=Vp(this._pairs)).call(e,(function(e){return e[0]}))}},{key:`toItemArray`,value:function(){var e;return Gd(e=Vp(this._pairs)).call(e,(function(e){return e[1]}))}},{key:`toEntryArray`,value:function(){return Vp(this._pairs)}},{key:`toObjectMap`,value:function(){var e,t=mh(null),n=YT(this._pairs);try{for(n.s();!(e=n.n()).done;){var r=Bp(e.value,2),i=r[0];t[i]=r[1]}}catch(e){n.e(e)}finally{n.f()}return t}},{key:`toMap`,value:function(){return new Cw(this._pairs)}},{key:`toIdSet`,value:function(){return new qT(this.toIdArray())}},{key:`toItemSet`,value:function(){return new qT(this.toItemArray())}},{key:`cache`,value:function(){return new n(Vp(this._pairs))}},{key:`distinct`,value:function(e){var t,n=new qT,r=YT(this._pairs);try{for(r.s();!(t=r.n()).done;){var i=Bp(t.value,2),a=i[0],o=i[1];n.add(e(o,a))}}catch(e){r.e(e)}finally{r.f()}return n}},{key:`filter`,value:function(e){var t=this._pairs;return new n({[kT]:()=>vC.mark((function n(){var r,i,a,o,s;return vC.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:r=YT(t),n.prev=1,r.s();case 3:if((i=r.n()).done){n.next=10;break}if(a=Bp(i.value,2),o=a[0],s=a[1],!e(s,o)){n.next=8;break}return n.next=8,[o,s];case 8:n.next=3;break;case 10:n.next=15;break;case 12:n.prev=12,n.t0=n.catch(1),r.e(n.t0);case 15:return n.prev=15,r.f(),n.finish(15);case 18:case`end`:return n.stop()}}),n,null,[[1,12,15,18]])}))()})}},{key:`forEach`,value:function(e){var t,n=YT(this._pairs);try{for(n.s();!(t=n.n()).done;){var r=Bp(t.value,2),i=r[0];e(r[1],i)}}catch(e){n.e(e)}finally{n.f()}}},{key:`map`,value:function(e){var t=this._pairs;return new n({[kT]:()=>vC.mark((function n(){var r,i,a,o,s;return vC.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:r=YT(t),n.prev=1,r.s();case 3:if((i=r.n()).done){n.next=9;break}return a=Bp(i.value,2),o=a[0],s=a[1],n.next=7,[o,e(s,o)];case 7:n.next=3;break;case 9:n.next=14;break;case 11:n.prev=11,n.t0=n.catch(1),r.e(n.t0);case 14:return n.prev=14,r.f(),n.finish(14);case 17:case`end`:return n.stop()}}),n,null,[[1,11,14,17]])}))()})}},{key:`max`,value:function(e){var t=JT(this._pairs),n=t.next();if(n.done)return null;for(var r=n.value[1],i=e(n.value[1],n.value[0]);!(n=t.next()).done;){var a=Bp(n.value,2),o=a[0],s=a[1],c=e(s,o);c>i&&(i=c,r=s)}return r}},{key:`min`,value:function(e){var t=JT(this._pairs),n=t.next();if(n.done)return null;for(var r=n.value[1],i=e(n.value[1],n.value[0]);!(n=t.next()).done;){var a=Bp(n.value,2),o=a[0],s=a[1],c=e(s,o);c<i&&(i=c,r=s)}return r}},{key:`reduce`,value:function(e,t){var n,r=YT(this._pairs);try{for(r.s();!(n=r.n()).done;){var i=Bp(n.value,2),a=i[0];t=e(t,i[1],a)}}catch(e){r.e(e)}finally{r.f()}return t}},{key:`sort`,value:function(e){var t=this;return new n({[kT]:function(){var n;return JT(bT(n=Vp(t._pairs)).call(n,(function(t,n){var r=Bp(t,2),i=r[0],a=r[1],o=Bp(n,2),s=o[0],c=o[1];return e(a,c,i,s)})))}})}}]),n}(kT);function QT(e,t){var n=am(e);if(lv){var r=lv(e);t&&(r=zd(r).call(r,(function(t){return vv(e,t).enumerable}))),n.push.apply(n,r)}return n}function $T(e){for(var t=1;t<arguments.length;t++){var n,r,i=arguments[t]==null?{}:arguments[t];t%2?gm(n=QT(Object(i),!0)).call(n,(function(t){Xu(e,t,i[t])})):Cv?Av(e,Cv(i)):gm(r=QT(Object(i))).call(r,(function(t){jv(e,t,vv(i,t))}))}return e}function eE(e,t){var n=Hp!==void 0&&Qf(e)||e[`@@iterator`];if(!n){if(nm(e)||(n=function(e,t){var n;if(e){if(typeof e==`string`)return tE(e,t);var r=Jp(n=Object.prototype.toString.call(e)).call(n,8,-1);if(r===`Object`&&e.constructor&&(r=e.constructor.name),r===`Map`||r===`Set`)return Yf(e);if(r===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return tE(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.
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`||!cv||cv.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Boolean.prototype.valueOf.call(cv(Boolean,[],(function(){}))),!0}catch{return!1}}();return function(){var n,r=Hv(e);if(t){var i=Hv(this).constructor;n=cv(r,arguments,i)}else n=r.apply(this,arguments);return zv(this,n)}}var rE=function(e){Rv(r,e);var n=nE(r);function r(e,i){var a;return t(this,r),Xu(U(a=n.call(this)),`_queue`,null),e&&!nm(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 Yu(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(nm(e)){var a=Gd(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=sh({},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(nm(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 qp(r).call(r,i)}},{key:`updateOnly`,value:function(e,t){var n,r=this;nm(e)||(e=[e]);var i=Gd(n=Gd(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 R_.apply(void 0,qp(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:Gd(i).call(i,(function(e){return e.id})),oldData:Gd(i).call(i,(function(e){return e.oldData})),data:Gd(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):nm(e)?(r=e,i=t):i=e;var a=i&&i.returnType===`Object`?`Object`:`Array`,o=i&&zd(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=Vp(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&&zd(e),r=e&&e.order,i=Vp(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 w=i[ee],T=t.get(w);T!=null&&a.push(T[this._idProp])}return a}},{key:`getDataSet`,value:function(){return this}},{key:`forEach`,value:function(e,t){var n=t&&zd(t),r=this._data,i=Vp(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&&zd(t),r=[],i=this._data,a=Vp(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&&Nd(n=nm(t)?t:am(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=nm(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=Vp(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=Vp(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: `+_h(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]:_d(n=LT(this._data)).call(n,this._data)})}}]),r}(KT);function iE(e,t){var n=Hp!==void 0&&Qf(e)||e[`@@iterator`];if(!n){if(nm(e)||(n=function(e,t){var n;if(e){if(typeof e==`string`)return aE(e,t);var r=Jp(n=Object.prototype.toString.call(e)).call(n,8,-1);if(r===`Object`&&e.constructor&&(r=e.constructor.name),r===`Map`||r===`Set`)return Yf(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`||!cv||cv.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Boolean.prototype.valueOf.call(cv(Boolean,[],(function(){}))),!0}catch{return!1}}();return function(){var n,r=Hv(e);if(t){var i=Hv(this).constructor;n=cv(r,arguments,i)}else n=r.apply(this,arguments);return zv(this,n)}}var sE=function(e){Rv(r,e);var n=oE(r);function r(e,i){var a,o;return t(this,r),Xu(U(o=n.call(this)),`length`,0),Xu(U(o),`_ids`,new qT),o._options=i||{},o._listener=_d(a=o._onEvent).call(a,U(o)),o.setData(e),o}return Yu(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:zd(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:zd(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:zd(this._options)}),t=Vp(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)||nm(e)?(r=e,n=t):n=e;var i=sh({},this._options,n),a=zd(this._options),o=n&&zd(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=zd(this._options),r=e==null?null:zd(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=zd(this._options),a=t&&zd(t);r=a?i?function(e){return i(e)&&a(e)}:a:i,gm(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=zd(this._options),a=t&&zd(t);return r=a?i?function(e){return i(e)&&a(e)}:a:i,Gd(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]:_d(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(tm(r.prototype));try{for(a.s();!(t=a.n()).done;){var o=t.value;jv(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 gm(t)==`function`&&typeof t.get==`function`&&typeof t.getDataSet==`function`&&typeof t.getIds==`function`&&typeof t.length==`number`&&typeof Gd(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=L_,e.DataSet=rE,e.DataStream=ZT,e.DataView=sE,e.Queue=GT,e.createNewDataPipeFrom=function(e){return new lf(e)},e.isDataSetLike=cE,e.isDataViewLike=function(e,t){return typeof t==`object`&&!!t&&e===t.idProp&&typeof gm(t)==`function`&&typeof t.get==`function`&&typeof t.getDataSet==`function`&&typeof t.getIds==`function`&&typeof t.length==`number`&&typeof Gd(t)==`function`&&typeof t.off==`function`&&typeof t.on==`function`&&typeof t.stream==`function`&&cE(e,t.getDataSet())}}))}))(),ee=x(),C=n(),w=e(i(),1),T={LocalBusiness:`#2E5090`,Service:`#3A6BB0`,PriceSpecification:`#5B8DD0`,OpeningHoursSpecification:`#7AAFE8`,Organization:`#A16207`,Person:`#C2410C`,UserProfile:`#EA580C`,Preference:`#F97316`,AdminUser:`#9A3412`,AccessGrant:`#7C2D12`,KnowledgeDocument:`#16A34A`,Section:`#22C55E`,Chunk:`#4ADE80`,DigitalDocument:`#15803D`,CreativeWork:`#86EFAC`,Question:`#A7F3D0`,FAQPage:`#34D399`,DefinedTerm:`#10B981`,Review:`#059669`,ImageObject:`#6EE7B7`,Conversation:`#7C3AED`,AdminConversation:`#4338CA`,PublicConversation:`#A855F7`,Message:`#64748B`,UserMessage:`#F97316`,AssistantMessage:`#FACC15`,ToolCall:`#C4B5FD`,Task:`#DB2777`,Project:`#BE185D`,Event:`#EC4899`,Workflow:`#0891B2`,WorkflowStep:`#06B6D4`,WorkflowRun:`#22D3EE`,StepResult:`#67E8F9`,OnboardingState:`#8B5CF6`,Email:`#65A30D`,EmailAccount:`#84CC16`,ReviewAlert:`#DC2626`},te=`#94A3B8`;Object.freeze(Object.keys(T)),Object.freeze(new Set([`Chunk`,`GraphPreference`])),Object.freeze(new Set(`LocalBusiness.Service.PriceSpecification.OpeningHoursSpecification.Organization.Person.UserProfile.Preference.AdminUser.AccessGrant.KnowledgeDocument.DigitalDocument.CreativeWork.Question.FAQPage.DefinedTerm.Review.ImageObject.AdminConversation.PublicConversation.Task.Project.Event.Workflow.OnboardingState.Email.EmailAccount`.split(`.`))),Object.freeze(new Set([`ToolCall`,`StepResult`,`WorkflowStep`,`WorkflowRun`])),Object.freeze(new Set([`HAS_TOOL_CALL`,`RUN_OF`,`HAS_STEP`,`HAS_RESULT`]));function ne(e){for(let t=1;t<e.length;t++)if(Object.prototype.hasOwnProperty.call(T,e[t]))return e[t];return e[0]??null}function E(e){return T[e]??`#94A3B8`}function D(e){let t=ne(e),n=t?E(t):te,r=0;for(let t=1;t<e.length;t++)Object.prototype.hasOwnProperty.call(T,e[t])&&r++;return{displayLabel:t,colour:n,driftCandidates:r}}function O(e,t){return e.length<10?[...e,t]:[e[0],...e.slice(e.length-8),t]}function k(e){return e.length<=1?e:e.slice(0,-1)}function re(e){return[e]}function ie(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 A(e){let t=e[0];if(t.kind!==`filter`)throw Error(`view-stack invariant: root must be filter view`);return t}function ae(e){return e.trashed===!0?`skip-trashed`:`pivot`}function oe(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 se(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){r.has(e.nodeId)||r.set(e.nodeId,{id:e.nodeId,labels:e.labels,properties:e.properties});let[n,o]=e.direction===`outgoing`?[t.nodeId,e.nodeId]:[e.nodeId,t.nodeId],s=`${n}|${o}|${e.relationship}`;i.has(s)||(i.add(s),a.push({id:s,from:n,to:o,type:e.relationship}))}return{nodes:[...r.values()],edges:a}}var ce=2e3;function le(e){let t=typeof e==`number`?e:Number(e);return!Number.isFinite(t)||t<=0?100:Math.min(Math.max(Math.floor(t),1),ce)}var ue=new Set([`Conversation`,`AdminConversation`,`PublicConversation`]),de=/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2})/,fe=/^\d{4}-\d{2}-\d{2}T(\d{2}:\d{2}:\d{2})/,pe=/^(\d{4}-\d{2}-\d{2})T/,me=24;function he(e){let t=e.match(de);return t?`${t[1]} ${t[2]}`:null}function ge(e){let t=e.match(fe);return t?t[1]:null}function _e(e){let t=e.match(pe);return t?t[1]:null}function ve(e){let t=e.properties,n=e.labels[0];if(n===`ToolCall`){let e=t.toolName;if(typeof e==`string`&&e.length>0)return e.length>24?e.slice(0,24)+`…`:e}else if(n===`WorkflowRun`){let e=t.startedAt;if(typeof e==`string`&&e.length>0){let t=he(e);if(t)return t}}else if(n===`WorkflowStep`){let e=t.label;if(typeof e==`string`&&e.length>0)return e.length>24?e.slice(0,24)+`…`:e}else if(n===`Person`){let e=typeof t.name==`string`?t.name:``;if(e.length>0)return e.length>24?e.slice(0,24)+`…`:e;let n=[typeof t.givenName==`string`?t.givenName:``,typeof t.familyName==`string`?t.familyName:``].filter(e=>e.length>0).join(` `);if(n.length>0)return n.length>24?n.slice(0,24)+`…`:n}else if(n===`Message`){let e=typeof t.role==`string`?t.role:``,n=e===`user`?`user`:e===`assistant`?`asst`:e===`system`?`sys`:e===`tool`?`tool`:null,r=typeof t.createdAt==`string`?t.createdAt:``;if(n&&r){let e=ge(r);if(e)return`${n} ${e}`}}for(let e of[`name`,`title`,`summary`,`givenName`,`subject`,`text`]){let n=t[e];if(typeof n==`string`&&n.length>0)return n.length>24?n.slice(0,24)+`…`:n}if(n===`Conversation`){let e=typeof t.conversationId==`string`?t.conversationId:null;if(e)return`Conv ${e.slice(0,8)}`}return n??`…`}function ye(e){let t=e.properties,n=e.labels[0];if(n===`ToolCall`){let e=t.toolName;if(typeof e==`string`&&e.length>0)return e}else if(n===`WorkflowRun`){let e=t.startedAt;if(typeof e==`string`&&e.length>0){let t=he(e);if(t)return t}}else if(n===`WorkflowStep`){let e=t.label;if(typeof e==`string`&&e.length>0)return e}else if(n===`Person`){let e=typeof t.name==`string`?t.name:``;if(e.length>0)return e;let n=[typeof t.givenName==`string`?t.givenName:``,typeof t.familyName==`string`?t.familyName:``].filter(e=>e.length>0).join(` `);if(n.length>0)return n}for(let e of[`name`,`title`,`summary`,`givenName`,`subject`,`text`]){let n=t[e];if(typeof n==`string`&&n.length>0)return n}if(n===`Conversation`){let e=typeof t.conversationId==`string`?t.conversationId:null;if(e)return`Conv ${e.slice(0,8)}`}return n??`…`}function be(e){if(e.length===0)return``;let t=e.split(/\s+/).filter(e=>e.length>0);if(t.length===0)return``;if(t.length===1){let e=t[0];return e.length<=me?e:e.slice(0,me-1)+`…`}let n=``,r=0;for(;r<t.length;){let e=n.length===0?t[r]:`${n} ${t[r]}`;if(e.length<=me)n=e,r++;else break}if(n.length===0)return n=t[0].slice(0,me-1)+`…`,n;if(r>=t.length)return n;let i=``;for(;r<t.length;){let e=i.length===0?t[r]:`${i} ${t[r]}`;if(e.length<=me)i=e,r++;else break}if(r<t.length){let e=t.slice(r).join(` `);i=(i.length===0?e:`${i} ${e}`).slice(0,me-1)+`…`}return`${n}\n${i}`}function xe(e,t){let n=e.labels[0];if(!n||!ue.has(n)||t<.7)return ve(e);let r=be(ye(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=_e(a);return s===null?r:`${r}\n${s} · ${o} msgs`}function Se(e){let t=e.properties,n=typeof t.createdAt==`string`?t.createdAt:``,r=typeof t.updatedAt==`string`?t.updatedAt:``,i=e.labels.join(` · `);return[ye(e),i,`id: ${e.id}`,n?`createdAt: ${n}`:``,r?`updatedAt: ${r}`:``].filter(e=>e.length>0).join(`
50
- `)}var j=o();function M(e){return e<.7?`compact`:e<1.3?`wrapped`:`detailed`}var N=150,Ce=`#FBBF24`;function we(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 Te=`maxy-graph-search-limit-v1`,Ee=250,P=1200;function F(){let[e,t]=(0,w.useState)(null),[n,r]=(0,w.useState)(!1);return(0,w.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(i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]),n?e?(0,j.jsxs)(`div`,{className:`data-page graph-page`,children:[(0,j.jsxs)(`header`,{className:`data-header`,children:[(0,j.jsxs)(`h1`,{className:`data-title`,children:[(0,j.jsx)(f,{size:18}),` Graph`]}),(0,j.jsx)(I,{})]}),(0,j.jsx)(`main`,{className:`graph-main`,children:(0,j.jsx)(De,{sessionKey:e})})]}):(0,j.jsxs)(`div`,{className:`data-page`,children:[(0,j.jsx)(`header`,{className:`data-header`,children:(0,j.jsxs)(`h1`,{className:`data-title`,children:[(0,j.jsx)(f,{size:18}),` Graph`]})}),(0,j.jsxs)(`div`,{className:`data-empty`,children:[(0,j.jsx)(`p`,{children:`You are not signed in.`}),(0,j.jsxs)(`p`,{children:[`Open the `,(0,j.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})]}):(0,j.jsx)(`div`,{className:`data-page`,children:(0,j.jsxs)(`div`,{className:`data-loading`,children:[(0,j.jsx)(s,{size:18,className:`spin`}),` Loading…`]})})}function I(){let[e,t]=(0,w.useState)(!1),n=(0,w.useRef)(null);(0,w.useEffect)(()=>{if(!e)return;let r=e=>{n.current&&(n.current.contains(e.target)||t(!1))},i=e=>{e.key===`Escape`&&t(!1)};return document.addEventListener(`mousedown`,r),document.addEventListener(`keydown`,i),()=>{document.removeEventListener(`mousedown`,r),document.removeEventListener(`keydown`,i)}},[e]);let r=(0,w.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]);return(0,j.jsxs)(`div`,{className:`chat-burger-wrap`,ref:n,children:[(0,j.jsx)(`button`,{type:`button`,className:`chat-burger`,onClick:()=>t(e=>!e),"aria-label":`Menu`,"aria-haspopup":`true`,"aria-expanded":e,children:(0,j.jsx)(d,{size:20})}),e&&(0,j.jsxs)(`div`,{className:`chat-menu`,children:[(0,j.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{t(!1),window.location.href=`/`},children:[(0,j.jsx)(p,{size:14}),` Chat`]}),(0,j.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{t(!1),window.location.href=`/data`},children:[(0,j.jsx)(u,{size:14}),` Data`]}),(0,j.jsx)(`div`,{className:`chat-menu-divider`}),(0,j.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{t(!1),r()},children:[(0,j.jsx)(c,{size:14}),` Log out`]})]})]})}function De({sessionKey:e}){let t=(0,w.useRef)(null),n=(0,w.useRef)(null),i=(0,w.useRef)(null),a=(0,w.useRef)(null),o=(0,w.useRef)(new Map),c=(0,w.useRef)([]),u=(0,w.useRef)(null),d=(0,w.useRef)(null),f=(0,w.useRef)(null),p=(0,w.useRef)(null),m=(0,w.useRef)(null),[b,x]=(0,w.useState)([{kind:`filter`,selectedLabels:[],includeTrashed:!1,includeAgentActions:!1}]),[C,T]=(0,w.useState)(!1),[te,ce]=(0,w.useState)(null),[de,fe]=(0,w.useState)(null),[pe,me]=(0,w.useState)(0),[he,ge]=(0,w.useState)(null),[_e,ye]=(0,w.useState)(!1),[be,F]=(0,w.useState)(!1),[I,De]=(0,w.useState)(null),[Ne,Pe]=(0,w.useState)(``),[Fe,Ie]=(0,w.useState)(``),[Le,Re]=(0,w.useState)(null),[ze,Be]=(0,w.useState)(null),[Ve,He]=(0,w.useState)(()=>{if(typeof window>`u`)return 100;let e=window.localStorage.getItem(Te);return e?le(e):100}),[Ue,We]=(0,w.useState)(Ve),[Ge,Ke]=(0,w.useState)(`hybrid`),[qe,Je]=(0,w.useState)(0),[Ye,Xe]=(0,w.useState)([]),[Ze,Qe]=(0,w.useState)({labels:[],includeTrashed:!1}),[$e,et]=(0,w.useState)(!1),[tt,nt]=(0,w.useState)(!1),rt=(0,w.useRef)(!1),it=(0,w.useRef)(null),at=(0,w.useMemo)(()=>{let e=new Set;for(let t of o.current.values()){let n=ne(t.labels);n&&e.add(n)}return[...e].sort()},[pe]);(0,w.useEffect)(()=>{let t=!1,n=fetch(`/api/admin/graph-labels-in-graph?session_key=${encodeURIComponent(e)}`).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:[]}}),r=fetch(`/api/admin/graph-default-view?session_key=${encodeURIComponent(e)}`).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([n,r]).then(([e,n])=>{if(!t&&(Xe(e.labels),Qe(n),!rt.current)){rt.current=!0;let t=new Set(e.labels.map(e=>e.label)),r=n.labels.filter(e=>t.has(e));(r.length>0||n.includeTrashed)&&x([{kind:`filter`,selectedLabels:r,includeTrashed:n.includeTrashed,includeAgentActions:!1}])}}),()=>{t=!0}},[e]);let ot=b[0].kind===`filter`?b[0].includeAgentActions:!1;(0,w.useEffect)(()=>{if(!rt.current)return;let t=!1;return fetch(`/api/admin/graph-labels-in-graph?session_key=${encodeURIComponent(e)}&includeAgentActions=${ot?`1`:`0`}`).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()}).then(e=>{t||Xe(e.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{}}),()=>{t=!0}},[e,ot]),(0,w.useEffect)(()=>{if(!$e)return;let e=e=>{it.current&&(it.current.contains(e.target)||et(!1))},t=e=>{e.key===`Escape`&&et(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[$e]);let st=(0,w.useCallback)(()=>{if(i.current)try{i.current.clear()}catch{}if(a.current)try{a.current.clear()}catch{}},[]),ct=(0,w.useCallback)((t,r)=>{De(null),fetch(`/api/admin/graph-delete?session_key=${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({elementId:t,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}`);ge(null);try{n.current?.unselectAll()}catch{}x(e=>[A(e)]),Je(e=>e+1)}).catch(e=>{let n=e instanceof Error?e.message:String(e);De(`Failed to delete: ${n}`),F(!0),window.setTimeout(()=>F(!1),P);try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-drag-delete`,elementId:t,label:r,msg:n}),keepalive:!0}).catch(()=>{})}catch{}})},[e]),lt=b[b.length-1],ut=(0,w.useMemo)(()=>ie(b),[b]),dt=(0,w.useRef)(ut);(0,w.useEffect)(()=>{dt.current=ut},[ut]),(0,w.useEffect)(()=>{if(lt.kind===`filter`&&lt.selectedLabels.length===0){u.current?.abort(),u.current=null,T(!1),ce(null),fe(null),me(0),o.current=new Map,st();return}if(lt.kind===`filter`&&Fe)return;let t=window.setTimeout(()=>{u.current?.abort();let t=new AbortController;u.current=t,T(!0),ce(null),fe(null);let n=ke(e,lt,{includeAgentActions:A(b).includeAgentActions,search:null});fetch(n,{signal:t.signal}).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(e.status===413)throw new Ae(t);if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(e=>{t.signal.aborted||(o.current=new Map(e.nodes.map(e=>[e.id,e])),me(e.nodes.length),ft(e.nodes,e.edges))}).catch(e=>{if(!t.signal.aborted){if(e instanceof Ae){fe(e.body),me(0),o.current=new Map,st();return}ce(e instanceof Error?e.message:String(e))}}).finally(()=>{t.signal.aborted||T(!1)})},Ee);return()=>{window.clearTimeout(t)}},[e,ut,qe,Fe,Ue]),(0,w.useEffect)(()=>()=>{u.current?.abort(),n.current?.destroy(),n.current=null,m.current!==null&&(clearTimeout(m.current),m.current=null)},[]);let ft=(0,w.useCallback)((e,r)=>{if(!t.current)return;c.current=r;let s=new Set([`Message`,`UserMessage`,`AssistantMessage`]),l=e=>e.labels.some(e=>s.has(e)),u=new Map,h=e.filter(l);if(h.length>0){let e=new Set(h.map(e=>e.id)),n=new Map,i=new Set;for(let t of r)t.type===`NEXT`&&e.has(t.from)&&e.has(t.to)&&(n.set(t.from,t.to),i.add(t.to));let a=[],o=new Set;for(let e of h){if(i.has(e.id))continue;let t=e.id;for(;t&&!o.has(t);)o.add(t),a.push(t),t=n.get(t)}for(let e of h)o.has(e.id)||(a.push(e.id),o.add(e.id));let s=t.current?.clientWidth??1200,c=Math.max(s-160,300),l=Math.max(Math.floor(c/150),2);a.forEach((e,t)=>{let n=t%l,r=Math.floor(t/l);u.set(e,{x:n*150,y:r*90})})}let g=e.map(e=>{let t=e.labels[0]??`Unknown`,n=D(e.labels);n.displayLabel;let r=n.colour;n.driftCandidates;let i=u.get(e.id),a=i?{x:i.x,y:i.y,physics:!1}:{};return e.trashed?{id:e.id,label:ve(e),title:Se(e),color:{background:`${r}40`,border:r},borderWidth:2,shapeProperties:{borderDashes:[6,4]},group:t,...a}:{id:e.id,label:ve(e),title:Se(e),color:r,group:t,...a}}),_=r.filter(e=>e.type!==`PART_OF`).map(e=>({id:e.id,from:e.from,to:e.to,label:e.type}));i.current=new S.DataSet(g),a.current=new S.DataSet(_);let v={autoResize:!0,layout:{improvedLayout:!1,randomSeed:we(dt.current)},physics:{solver:`barnesHut`,barnesHut:{gravitationalConstant:-8e3,centralGravity:.12,springLength:170,springConstant:.04},stabilization:{iterations:200}},nodes:{shape:`dot`,size:14,font:{color:`#1F2937`,size:12,face:`DM Sans, sans-serif`},borderWidth:0,chosen:{node:e=>{e.size=20,e.borderWidth=3},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}};try{n.current?.destroy(),m.current!==null&&(clearTimeout(m.current),m.current=null),p.current=null;let e=new ee.Network(t.current,{nodes:i.current,edges:a.current},v);n.current=e,e.on(`zoom`,()=>{m.current!==null&&clearTimeout(m.current),m.current=setTimeout(()=>{m.current=null;let e=n.current,t=i.current;if(!e||!t)return;let r;try{r=e.getScale()}catch{return}let a=M(r);if(a===p.current)return;p.current=a;let s=[];for(let e of o.current.values()){let t=e.labels[0];if(!t||!ue.has(t))continue;let{colour:n}=D(e.labels),i=e.trashed?{background:`${n}40`,border:n}:n;s.push({id:e.id,label:xe(e,r),color:i})}s.length>0&&t.update(s),console.error(`[graph-page] zoom-tier scale=${r.toFixed(3)} tier=${a} conversations=${s.length}`)},N)}),e.on(`selectNode`,e=>{let t=e.nodes[0],n=o.current.get(t);if(!n||(ge(n),ae(n)===`skip-trashed`))return;let r={kind:`neighbourhood`,rootElementId:t,rootLabel:n.labels[0]??null};x(e=>{let n=O(e,r),i=n.length-1;return n.length>e.length&&Me(`nav-push`,{depth:i,kind:r.kind,rootElementId:t}),n.length===10&&e.length===10&&Me(`view-stack-cap-hit`,{depth:10,rootElementId:t}),n})}),e.on(`deselectNode`,()=>{ge(null)});let r=e=>{let n=t.current,r=d.current;if(!n||!r)return!1;let i=n.getBoundingClientRect(),a=r.getBoundingClientRect(),o=i.left+e.x,s=i.top+e.y;return o>=a.left&&o<=a.right&&s>=a.top&&s<=a.bottom},s=t.current?.parentElement??null;e.on(`dragStart`,e=>{let t=e.nodes[0];if(!t){f.current=null;return}f.current=t,s?.classList.add(`graph-dragging`)}),e.on(`dragging`,e=>{if(!f.current)return;let t=r(e.pointer.DOM);ye(e=>e===t?e:t)}),e.on(`dragEnd`,e=>{let t=f.current;f.current=null,ye(!1),s?.classList.remove(`graph-dragging`),t&&r(e.pointer.DOM)&&ct(t,o.current.get(t)?.labels[0]??`Unknown`)})}catch(e){let t=e instanceof Error?e.message:String(e);ce(`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,w.useEffect)(()=>{let e=Ne.trim();if(!e){Ie(``),Re(null),Be(null),Ke(`hybrid`),n.current?.unselectAll();return}let t=setTimeout(()=>Ie(e),300);return()=>clearTimeout(t)},[Ne]),(0,w.useEffect)(()=>{let e=setTimeout(()=>{let e=le(Ve);We(e);try{window.localStorage.setItem(Te,String(e))}catch{}},200);return()=>clearTimeout(e)},[Ve]);let pt=(0,w.useCallback)(e=>{let t=n.current,r=i.current;if(!t||!r)return;let{updates:a,inWindow:s}=oe(e,o.current,D,Ce);a.length>0&&(r.update(a),t.fit({nodes:s,animation:{duration:400,easingFunction:`easeInOutQuad`}}))},[]),mt=A(b);(0,w.useEffect)(()=>{if(!Fe||lt.kind!==`filter`)return;let t=!1;Be(null);let n=encodeURIComponent(mt.selectedLabels.join(`,`)),r=`/api/admin/graph-search?session_key=${encodeURIComponent(e)}&q=${encodeURIComponent(Fe)}&labels=${n}&limit=${Ue}`;return fetch(r).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(e=>{if(t)return;Re(e.results);let n=e.mode===`bm25`?`bm25`:`hybrid`;if(Ke(n),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="${Fe}"`}),keepalive:!0}).catch(()=>{})}catch{}let{nodes:r,edges:i}=se(e.results,mt.selectedLabels);o.current=new Map(r.map(e=>[e.id,e])),me(r.length),fe(null),ft(r,i),pt(e.results)}).catch(e=>{t||Be(e instanceof Error?e.message:String(e))}),()=>{t=!0}},[Fe,Ue,e,pt,lt.kind,mt.selectedLabels,ft]);let ht=(0,w.useCallback)(e=>{x(t=>{let n=A(t),r=new Set(n.selectedLabels);return r.has(e)?r.delete(e):r.add(e),re({kind:`filter`,selectedLabels:[...r].sort(),includeTrashed:n.includeTrashed,includeAgentActions:n.includeAgentActions})})},[]),gt=(0,w.useCallback)(()=>{x(e=>{let t=A(e);return re({...t,includeTrashed:!t.includeTrashed})})},[]),_t=(0,w.useCallback)(()=>{x(e=>{let t=A(e);return re({...t,includeAgentActions:!t.includeAgentActions})})},[]),vt=(0,w.useCallback)(()=>{Pe(``),Ie(``),Re(null),Be(null),Ke(`hybrid`);try{n.current?.unselectAll()}catch{}},[]),yt=(0,w.useCallback)(()=>{x(()=>re({kind:`filter`,selectedLabels:[],includeTrashed:!1,includeAgentActions:!1}))},[]),bt=(0,w.useCallback)(()=>{ge(null);try{n.current?.unselectAll()}catch{}x(e=>{let t=k(e);return t!==e&&Me(`nav-pop`,{depth:t.length-1}),t})},[]),xt=(0,w.useCallback)(()=>{let t=A(b),n={labels:[...t.selectedLabels].sort(),includeTrashed:t.includeTrashed};nt(!0),fetch(`/api/admin/graph-default-view?session_key=${encodeURIComponent(e)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}).then(async e=>{if(!e.ok){let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));throw Error(t.error??`HTTP ${e.status}`)}Qe(n)}).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(()=>nt(!1))},[e,b]),St=(0,w.useCallback)(()=>{ge(null);try{n.current?.unselectAll()}catch{}Je(e=>e+1)},[]),Ct=(0,w.useCallback)(()=>{ge(null);try{n.current?.unselectAll()}catch{}x(e=>[A(e)]),Je(e=>e+1)},[]),wt=lt.kind===`neighbourhood`,Tt=A(b),Et=Tt.selectedLabels,Dt=Tt.includeTrashed,Ot=Tt.includeAgentActions,kt=(0,w.useMemo)(()=>{if(Dt!==Ze.includeTrashed||Et.length!==Ze.labels.length)return!0;for(let e=0;e<Et.length;e++)if(Et[e]!==Ze.labels[e])return!0;return!1},[Dt,Et,Ze]);return(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`div`,{className:`graph-toolbar`,children:[(0,j.jsxs)(`div`,{className:`data-search-input graph-search-input`,children:[(0,j.jsx)(l,{size:14}),(0,j.jsx)(`input`,{type:`text`,placeholder:`Search nodes…`,value:Ne,onChange:e=>Pe(e.target.value),autoComplete:`off`,spellCheck:!1}),Fe&&!Le&&!ze&&(0,j.jsx)(s,{size:14,className:`spin`}),Ne.length>0&&(0,j.jsx)(`button`,{type:`button`,className:`graph-search-clear`,onClick:vt,"aria-label":`Clear search`,title:`Clear search`,children:(0,j.jsx)(h,{size:14})})]}),Fe&&!wt&&(0,j.jsxs)(`div`,{className:`graph-search-limit`,title:`Show top ${Ve} matches (1-2000)`,children:[(0,j.jsxs)(`label`,{htmlFor:`graph-search-limit-slider`,className:`graph-search-limit-label`,children:[`Top `,Ve]}),(0,j.jsx)(`input`,{id:`graph-search-limit-slider`,type:`range`,min:1,max:2e3,step:1,value:Ve,onChange:e=>He(le(e.target.value)),"aria-label":`Maximum search results to render`})]}),!wt&&(0,j.jsxs)(`div`,{className:`graph-filter-wrap`,ref:it,children:[(0,j.jsxs)(`button`,{type:`button`,className:`graph-filter-toggle${$e?` is-open`:``}${Et.length>0||Dt||Ot?` has-selection`:``}`,onClick:()=>et(e=>!e),"aria-haspopup":`true`,"aria-expanded":$e,"aria-label":`Filter node types`,children:[(0,j.jsx)(y,{size:14}),(0,j.jsx)(`span`,{children:`Filter`}),Et.length>0&&(0,j.jsx)(`span`,{className:`graph-filter-count`,children:Et.length})]}),$e&&(0,j.jsxs)(`div`,{className:`graph-filter-popover`,role:`dialog`,"aria-label":`Node type filter`,children:[(0,j.jsxs)(`div`,{className:`graph-filter-popover-header`,children:[(0,j.jsxs)(`button`,{type:`button`,className:`graph-toggle-trashed${Dt?` active`:``}`,onClick:gt,"aria-pressed":Dt,title:`Show trashed nodes — restored with Restore button on each node`,children:[(0,j.jsx)(v,{size:14}),` Show trashed`]}),(Et.length>0||Dt||Ot)&&(0,j.jsx)(`button`,{type:`button`,className:`graph-filter-clear`,onClick:yt,"aria-label":`Clear filter selection`,title:`Clear filter selection`,children:(0,j.jsx)(h,{size:14})})]}),(0,j.jsx)(`div`,{className:`graph-toggle-agent-actions`,title:`Hide ToolCall, StepResult, WorkflowStep, WorkflowRun — agent-execution telemetry. Flip on for audit/debug.`,children:(0,j.jsx)(g,{checked:Ot,onChange:_t,label:`Include agent actions`})}),Ye.length===0&&(0,j.jsx)(`p`,{className:`graph-filter-popover-empty`,children:`No node types in your graph yet.`}),(0,j.jsx)(`div`,{className:`graph-filter-rows`,role:`group`,"aria-label":`Node type filter`,children:Ye.map(({label:e,nodeCount:t})=>{let n=Et.includes(e),r=E(e);return(0,j.jsxs)(`button`,{type:`button`,className:`graph-filter-row${n?` active`:``}`,onClick:()=>ht(e),"aria-pressed":n,children:[(0,j.jsx)(`span`,{className:`graph-filter-row-swatch`,style:{backgroundColor:r}}),(0,j.jsx)(`span`,{className:`graph-filter-row-label`,children:e}),(0,j.jsx)(`span`,{className:`graph-filter-row-count`,children:t})]},e)})}),(0,j.jsx)(`div`,{className:`graph-filter-popover-footer`,children:(0,j.jsx)(`button`,{type:`button`,className:`graph-filter-set-default`,onClick:xt,disabled:!kt||tt,children:tt?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(s,{size:12,className:`spin`}),` Saving…`]}):`Set default view`})})]})]}),(0,j.jsxs)(`div`,{className:`graph-meta`,children:[b.length>1&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`button`,{type:`button`,className:`graph-back-to-filter graph-back-desktop`,onClick:bt,children:`← Back`}),(0,j.jsx)(`button`,{type:`button`,className:`graph-back-to-filter graph-back-mobile`,onClick:bt,"aria-label":`Back`,children:(0,j.jsx)(_,{size:16})})]}),pe>0&&(0,j.jsxs)(`span`,{className:`graph-meta-count`,children:[pe,` node`,pe===1?``:`s`]})]})]}),b.length>1&&(0,j.jsx)(je,{viewStack:b}),Fe&&Ge===`bm25`&&!ze&&(0,j.jsx)(`div`,{className:`graph-error-banner graph-search-degraded`,role:`status`,children:`Vector ranking unavailable — showing keyword-only results.`}),ze&&(0,j.jsxs)(`div`,{className:`data-error graph-error-banner`,children:[`Search unavailable: `,ze]}),Le&&Le.length===0&&!ze&&(0,j.jsx)(`div`,{className:`graph-search-status`,children:`No matches in your graph.`}),(0,j.jsxs)(`div`,{className:`graph-canvas-wrap`,children:[C&&(0,j.jsxs)(`div`,{className:`graph-canvas-overlay`,children:[(0,j.jsx)(s,{size:20,className:`spin`}),` Loading your graph…`]}),te&&!C&&(0,j.jsxs)(`div`,{className:`graph-canvas-overlay graph-canvas-error`,children:[(0,j.jsx)(`p`,{children:te}),(0,j.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:()=>window.location.reload(),children:`Retry`})]}),de&&!C&&(0,j.jsxs)(`div`,{className:`graph-canvas-overlay graph-canvas-error`,children:[(0,j.jsxs)(`p`,{children:[`Refine your filter — `,(0,j.jsx)(`strong`,{children:de.matched}),` matches exceed the 2000 cap.`]}),(0,j.jsx)(`p`,{className:`graph-canvas-hint`,children:`Pick a more specific label combination, or narrow your brand's data.`})]}),!C&&!te&&!de&&pe===0&&!wt&&Et.length===0&&(0,j.jsxs)(`div`,{className:`graph-canvas-overlay`,children:[(0,j.jsx)(y,{size:20}),(0,j.jsx)(`p`,{children:`Open Filter to pick a node type and see what's in your graph.`})]}),!C&&!te&&!de&&pe===0&&!wt&&Et.length>0&&(0,j.jsx)(`div`,{className:`graph-canvas-overlay`,children:(0,j.jsxs)(`p`,{children:[`No `,Et.join(`, `),` nodes in your graph yet.`]})}),(0,j.jsx)(`div`,{ref:t,className:`graph-canvas`}),pe>0&&(0,j.jsx)(`div`,{ref:d,className:`graph-trash-drop-zone${_e?` is-hover`:``}${be?` is-error`:``}`,"aria-hidden":`true`,children:(0,j.jsx)(r,{size:18})}),I&&(0,j.jsxs)(`div`,{className:`graph-drag-error-banner`,role:`alert`,children:[(0,j.jsx)(`span`,{children:I}),(0,j.jsx)(`button`,{type:`button`,className:`graph-drag-error-dismiss`,onClick:()=>De(null),"aria-label":`Dismiss`,children:(0,j.jsx)(h,{size:14})})]})]}),he&&(0,j.jsx)(Oe,{node:he,edges:c.current,nodesById:o.current,sessionKey:e,onClose:()=>{ge(null);try{n.current?.unselectAll()}catch{}},onRestored:St,onTrashed:Ct}),pe>0&&at.length>0&&(0,j.jsx)(`div`,{className:`graph-legend`,children:at.map(e=>(0,j.jsxs)(`div`,{className:`graph-legend-item`,children:[(0,j.jsx)(`span`,{className:`graph-legend-swatch`,style:{backgroundColor:E(e)}}),(0,j.jsx)(`span`,{children:e})]},e))})]})}function Oe({node:e,edges:t,nodesById:n,sessionKey:i,onClose:a,onRestored:o,onTrashed:c}){let l=Object.entries(e.properties).filter(([,e])=>e!=null),u=t.filter(t=>t.from===e.id||t.to===e.id),[d,f]=(0,w.useState)(!1),[p,g]=(0,w.useState)(null),[_,v]=(0,w.useState)(!1),[y,b]=(0,w.useState)(null);(0,w.useEffect)(()=>{f(!1),g(null),v(!1),b(null)},[e.id]);let x=(0,w.useCallback)(()=>{f(!0),g(null),fetch(`/api/admin/graph-restore?session_key=${encodeURIComponent(i)}`,{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}`);o()}).catch(e=>{g(e instanceof Error?e.message:String(e)),f(!1)})},[e.id,o,i]),S=(0,w.useCallback)(()=>{v(!0),b(null),fetch(`/api/admin/graph-delete?session_key=${encodeURIComponent(i)}`,{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=>{b(e instanceof Error?e.message:String(e)),v(!1)})},[e.id,c,i]);return(0,j.jsxs)(`aside`,{className:`graph-side-panel${e.trashed?` graph-side-panel-trashed`:``}`,children:[(0,j.jsxs)(`header`,{className:`graph-side-header`,children:[(0,j.jsx)(`div`,{children:(()=>{if(e.labels.some(e=>ue.has(e))){let t=ye(e),n=e.properties.createdAt,r=typeof n==`string`?n:``,i=r?he(r):null,a=e.labels.join(` · `)+(e.trashed?` · Trashed`:``)+` · ${e.id}`;return(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`h2`,{className:`graph-side-name`,title:t,children:t}),i&&(0,j.jsx)(`div`,{className:`graph-side-created`,children:i}),(0,j.jsx)(`div`,{className:`graph-side-meta`,children:a})]})}return(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`div`,{className:`graph-side-labels`,children:[e.labels.join(` · `),e.trashed?` · Trashed`:``]}),(0,j.jsx)(`div`,{className:`graph-side-id`,children:e.id})]})})()}),(0,j.jsx)(`button`,{type:`button`,className:`graph-side-close`,onClick:a,"aria-label":`Close`,children:(0,j.jsx)(h,{size:14})})]}),e.trashed&&(0,j.jsxs)(`dl`,{className:`graph-side-props graph-side-trash-meta`,children:[(0,j.jsxs)(`div`,{className:`graph-side-prop`,children:[(0,j.jsx)(`dt`,{children:`trashedAt`}),(0,j.jsx)(`dd`,{children:Pe(e.properties.trashedAt)})]}),(0,j.jsxs)(`div`,{className:`graph-side-prop`,children:[(0,j.jsx)(`dt`,{children:`trashedBy`}),(0,j.jsx)(`dd`,{children:Pe(e.properties.trashedBy)})]})]}),(0,j.jsxs)(`dl`,{className:`graph-side-props`,children:[l.length===0&&(0,j.jsx)(`div`,{className:`graph-side-empty`,children:`No properties.`}),l.map(([e,t])=>(0,j.jsxs)(`div`,{className:`graph-side-prop`,children:[(0,j.jsx)(`dt`,{children:e}),(0,j.jsx)(`dd`,{children:Pe(t)})]},e))]}),u.length>0&&(0,j.jsxs)(`section`,{className:`graph-side-edges`,children:[(0,j.jsxs)(`h3`,{className:`graph-side-edges-heading`,children:[`Connections (`,u.length,`)`]}),u.map(t=>{let r=t.from===e.id,i=r?t.to:t.from,a=n.get(i),o=a?ve(a):i,s=r?`→`:`←`,c=Object.entries(t.properties??{}).filter(([,e])=>e!=null&&e!==``);return(0,j.jsxs)(`div`,{className:`graph-side-edge`,children:[(0,j.jsxs)(`div`,{className:`graph-side-edge-header`,children:[(0,j.jsx)(`span`,{className:`graph-side-edge-type`,children:t.type}),(0,j.jsx)(`span`,{className:`graph-side-edge-arrow`,children:s}),(0,j.jsx)(`span`,{className:`graph-side-edge-other`,title:o,children:o})]}),c.length>0&&(0,j.jsx)(`dl`,{className:`graph-side-edge-props`,children:c.map(([e,t])=>(0,j.jsxs)(`div`,{className:`graph-side-prop`,children:[(0,j.jsx)(`dt`,{children:e}),(0,j.jsx)(`dd`,{children:Pe(t)})]},e))})]},t.id)})]}),e.trashed&&(0,j.jsxs)(`footer`,{className:`graph-side-footer`,children:[!d&&!p&&(0,j.jsxs)(`button`,{type:`button`,className:`graph-side-restore`,onClick:x,children:[(0,j.jsx)(m,{size:14}),` Restore`]}),d&&(0,j.jsx)(`div`,{className:`graph-delete-confirm`,children:(0,j.jsxs)(`p`,{children:[(0,j.jsx)(s,{size:14,className:`spin`}),` Restoring…`]})}),p&&(0,j.jsxs)(`div`,{className:`graph-delete-confirm graph-delete-confirm-error`,children:[(0,j.jsxs)(`p`,{children:[`Restore failed: `,p]}),(0,j.jsxs)(`div`,{className:`graph-delete-confirm-buttons`,children:[(0,j.jsx)(`button`,{type:`button`,className:`graph-delete-confirm-cancel`,onClick:()=>{g(null)},children:`Close`}),(0,j.jsx)(`button`,{type:`button`,className:`graph-delete-confirm-do`,onClick:x,children:`Retry`})]})]})]}),!e.trashed&&(0,j.jsxs)(`footer`,{className:`graph-side-footer`,children:[!_&&!y&&(0,j.jsxs)(`button`,{type:`button`,className:`graph-side-trash`,onClick:S,children:[(0,j.jsx)(r,{size:14}),` Trash`]}),_&&(0,j.jsx)(`div`,{className:`graph-delete-confirm`,children:(0,j.jsxs)(`p`,{children:[(0,j.jsx)(s,{size:14,className:`spin`}),` Trashing…`]})}),y&&(0,j.jsxs)(`div`,{className:`graph-delete-confirm graph-delete-confirm-error`,children:[(0,j.jsxs)(`p`,{children:[`Trash failed: `,y]}),(0,j.jsxs)(`div`,{className:`graph-delete-confirm-buttons`,children:[(0,j.jsx)(`button`,{type:`button`,className:`graph-delete-confirm-cancel`,onClick:()=>{b(null)},children:`Close`}),(0,j.jsx)(`button`,{type:`button`,className:`graph-delete-confirm-do`,onClick:S,children:`Retry`})]})]})]})]})}function ke(e,t,n){let r=`/api/admin/graph-subgraph?session_key=${encodeURIComponent(e)}`,i=n.includeAgentActions?`&includeAgentActions=1`:``;if(t.kind===`neighbourhood`){let e=n.search&&n.search.q?`&q=${encodeURIComponent(n.search.q)}&limit=${n.search.limit}`:``;return`${r}&mode=neighbourhood&elementId=${encodeURIComponent(t.rootElementId)}${i}${e}`}return`${r}&mode=default&labels=${encodeURIComponent(t.selectedLabels.join(`,`))}${t.includeTrashed?`&includeTrashed=1`:``}${i}`}var Ae=class extends Error{body;constructor(e){super(e.error),this.body=e}};function je({viewStack:e}){let t=e.map(e=>e.kind===`filter`?`Filter`:e.rootLabel??`Node`);return(0,j.jsx)(`div`,{className:`graph-breadcrumb`,role:`navigation`,"aria-label":`Graph navigation breadcrumb`,children:t.map((e,n)=>(0,j.jsxs)(`span`,{className:`graph-breadcrumb-item`,children:[n>0&&(0,j.jsx)(`span`,{className:`graph-breadcrumb-separator`,"aria-hidden":`true`,children:`›`}),(0,j.jsx)(`span`,{className:`graph-breadcrumb-label${n===t.length-1?` is-current`:``}`,children:e})]},n))})}function Me(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{}}function Ne(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 Pe(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=Ne(e);if(t)return t}return JSON.stringify(e)}return String(e)}(0,C.createRoot)(document.getElementById(`root`)).render((0,j.jsx)(F,{}));
50
+ `)}var j=o();function M(e){return e<.7?`compact`:e<1.3?`wrapped`:`detailed`}var N=150,Ce=`#FBBF24`;function we(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 Te=`maxy-graph-search-limit-v1`,Ee=250,P=1200;function F(){let[e,t]=(0,w.useState)(null),[n,r]=(0,w.useState)(!1);return(0,w.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(i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]),n?e?(0,j.jsxs)(`div`,{className:`data-page graph-page`,children:[(0,j.jsxs)(`header`,{className:`data-header`,children:[(0,j.jsxs)(`h1`,{className:`data-title`,children:[(0,j.jsx)(f,{size:18}),` Graph`]}),(0,j.jsx)(I,{})]}),(0,j.jsx)(`main`,{className:`graph-main`,children:(0,j.jsx)(De,{sessionKey:e})})]}):(0,j.jsxs)(`div`,{className:`data-page`,children:[(0,j.jsx)(`header`,{className:`data-header`,children:(0,j.jsxs)(`h1`,{className:`data-title`,children:[(0,j.jsx)(f,{size:18}),` Graph`]})}),(0,j.jsxs)(`div`,{className:`data-empty`,children:[(0,j.jsx)(`p`,{children:`You are not signed in.`}),(0,j.jsxs)(`p`,{children:[`Open the `,(0,j.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})]}):(0,j.jsx)(`div`,{className:`data-page`,children:(0,j.jsxs)(`div`,{className:`data-loading`,children:[(0,j.jsx)(s,{size:18,className:`spin`}),` Loading…`]})})}function I(){let[e,t]=(0,w.useState)(!1),n=(0,w.useRef)(null);(0,w.useEffect)(()=>{if(!e)return;let r=e=>{n.current&&(n.current.contains(e.target)||t(!1))},i=e=>{e.key===`Escape`&&t(!1)};return document.addEventListener(`mousedown`,r),document.addEventListener(`keydown`,i),()=>{document.removeEventListener(`mousedown`,r),document.removeEventListener(`keydown`,i)}},[e]);let r=(0,w.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]);return(0,j.jsxs)(`div`,{className:`chat-burger-wrap`,ref:n,children:[(0,j.jsx)(`button`,{type:`button`,className:`chat-burger`,onClick:()=>t(e=>!e),"aria-label":`Menu`,"aria-haspopup":`true`,"aria-expanded":e,children:(0,j.jsx)(d,{size:20})}),e&&(0,j.jsxs)(`div`,{className:`chat-menu`,children:[(0,j.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{t(!1),window.location.href=`/`},children:[(0,j.jsx)(p,{size:14}),` Chat`]}),(0,j.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{t(!1),window.location.href=`/data`},children:[(0,j.jsx)(u,{size:14}),` Data`]}),(0,j.jsx)(`div`,{className:`chat-menu-divider`}),(0,j.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{t(!1),r()},children:[(0,j.jsx)(c,{size:14}),` Log out`]})]})]})}function De({sessionKey:e}){let t=(0,w.useRef)(null),n=(0,w.useRef)(null),i=(0,w.useRef)(null),a=(0,w.useRef)(null),o=(0,w.useRef)(new Map),c=(0,w.useRef)([]),u=(0,w.useRef)(null),d=(0,w.useRef)(null),f=(0,w.useRef)(null),p=(0,w.useRef)(null),m=(0,w.useRef)(null),[b,x]=(0,w.useState)([{kind:`filter`,selectedLabels:[],includeTrashed:!1,includeAgentActions:!1}]),[C,T]=(0,w.useState)(!1),[te,ce]=(0,w.useState)(null),[de,fe]=(0,w.useState)(null),[pe,me]=(0,w.useState)(0),[he,ge]=(0,w.useState)(null),[_e,ye]=(0,w.useState)(!1),[be,F]=(0,w.useState)(!1),[I,De]=(0,w.useState)(null),[Ne,Pe]=(0,w.useState)(``),[Fe,Ie]=(0,w.useState)(``),[Le,Re]=(0,w.useState)(null),[ze,Be]=(0,w.useState)(null),[Ve,He]=(0,w.useState)(()=>{if(typeof window>`u`)return 100;let e=window.localStorage.getItem(Te);return e?le(e):100}),[Ue,We]=(0,w.useState)(Ve),[Ge,Ke]=(0,w.useState)(`hybrid`),[qe,Je]=(0,w.useState)(0),[Ye,Xe]=(0,w.useState)([]),[Ze,Qe]=(0,w.useState)({labels:[],includeTrashed:!1}),[$e,et]=(0,w.useState)(!1),[tt,nt]=(0,w.useState)(!1),rt=(0,w.useRef)(!1),it=(0,w.useRef)(null),at=(0,w.useMemo)(()=>{let e=new Set;for(let t of o.current.values()){let n=ne(t.labels);n&&e.add(n)}return[...e].sort()},[pe]);(0,w.useEffect)(()=>{let t=!1,n=fetch(`/api/admin/graph-labels-in-graph?session_key=${encodeURIComponent(e)}`).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:[]}}),r=fetch(`/api/admin/graph-default-view?session_key=${encodeURIComponent(e)}`).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([n,r]).then(([e,n])=>{if(!t&&(Xe(e.labels),Qe(n),!rt.current)){rt.current=!0;let t=new Set(e.labels.map(e=>e.label)),r=n.labels.filter(e=>t.has(e));(r.length>0||n.includeTrashed)&&x([{kind:`filter`,selectedLabels:r,includeTrashed:n.includeTrashed,includeAgentActions:!1}])}}),()=>{t=!0}},[e]);let ot=b[0].kind===`filter`?b[0].includeAgentActions:!1;(0,w.useEffect)(()=>{if(!rt.current)return;let t=!1;return fetch(`/api/admin/graph-labels-in-graph?session_key=${encodeURIComponent(e)}&includeAgentActions=${ot?`1`:`0`}`).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()}).then(e=>{t||Xe(e.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{}}),()=>{t=!0}},[e,ot]),(0,w.useEffect)(()=>{if(!$e)return;let e=e=>{it.current&&(it.current.contains(e.target)||et(!1))},t=e=>{e.key===`Escape`&&et(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[$e]);let st=(0,w.useCallback)(()=>{if(i.current)try{i.current.clear()}catch{}if(a.current)try{a.current.clear()}catch{}},[]),ct=(0,w.useCallback)((t,r)=>{De(null),fetch(`/api/admin/graph-delete?session_key=${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({elementId:t,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}`);ge(null);try{n.current?.unselectAll()}catch{}x(e=>[A(e)]),Je(e=>e+1)}).catch(e=>{let n=e instanceof Error?e.message:String(e);De(`Failed to delete: ${n}`),F(!0),window.setTimeout(()=>F(!1),P);try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-drag-delete`,elementId:t,label:r,msg:n}),keepalive:!0}).catch(()=>{})}catch{}})},[e]),lt=b[b.length-1],ut=(0,w.useMemo)(()=>ie(b),[b]),dt=(0,w.useRef)(ut);(0,w.useEffect)(()=>{dt.current=ut},[ut]),(0,w.useEffect)(()=>{if(lt.kind===`filter`&&lt.selectedLabels.length===0){u.current?.abort(),u.current=null,T(!1),ce(null),fe(null),me(0),o.current=new Map,st();return}if(lt.kind===`filter`&&Fe)return;let t=window.setTimeout(()=>{u.current?.abort();let t=new AbortController;u.current=t,T(!0),ce(null),fe(null);let n=ke(e,lt,{includeAgentActions:A(b).includeAgentActions,search:null});fetch(n,{signal:t.signal}).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(e.status===413)throw new Ae(t);if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(e=>{t.signal.aborted||(o.current=new Map(e.nodes.map(e=>[e.id,e])),me(e.nodes.length),ft(e.nodes,e.edges))}).catch(e=>{if(!t.signal.aborted){if(e instanceof Ae){fe(e.body),me(0),o.current=new Map,st();return}ce(e instanceof Error?e.message:String(e))}}).finally(()=>{t.signal.aborted||T(!1)})},Ee);return()=>{window.clearTimeout(t)}},[e,ut,qe,Fe,Ue]),(0,w.useEffect)(()=>()=>{u.current?.abort(),n.current?.destroy(),n.current=null,m.current!==null&&(clearTimeout(m.current),m.current=null)},[]);let ft=(0,w.useCallback)((e,r)=>{if(!t.current)return;c.current=r;let s=new Set([`Message`,`UserMessage`,`AssistantMessage`]),l=e=>e.labels.some(e=>s.has(e)),u=new Map,h=e.filter(l);if(h.length>0){let e=new Set(h.map(e=>e.id)),n=new Map,i=new Set;for(let t of r)t.type===`NEXT`&&e.has(t.from)&&e.has(t.to)&&(n.set(t.from,t.to),i.add(t.to));let a=[],o=new Set;for(let e of h){if(i.has(e.id))continue;let t=e.id;for(;t&&!o.has(t);)o.add(t),a.push(t),t=n.get(t)}for(let e of h)o.has(e.id)||(a.push(e.id),o.add(e.id));let s=t.current?.clientWidth??1200,c=Math.max(s-160,300),l=Math.max(Math.floor(c/150),2);a.forEach((e,t)=>{let n=t%l,r=Math.floor(t/l);u.set(e,{x:n*150,y:r*90})})}let g=e.map(e=>{let t=e.labels[0]??`Unknown`,n=D(e.labels);n.displayLabel;let r=n.colour;n.driftCandidates;let i=u.get(e.id),a=i?{x:i.x,y:i.y,physics:!1}:{};return e.trashed?{id:e.id,label:ve(e),title:Se(e),color:{background:`${r}40`,border:r},borderWidth:2,shapeProperties:{borderDashes:[6,4]},group:t,...a}:{id:e.id,label:ve(e),title:Se(e),color:r,group:t,...a}}),_=r.filter(e=>e.type!==`PART_OF`).map(e=>({id:e.id,from:e.from,to:e.to,label:e.type}));i.current=new S.DataSet(g),a.current=new S.DataSet(_);let v={autoResize:!0,layout:{improvedLayout:!1,randomSeed:we(dt.current)},physics:{solver:`barnesHut`,barnesHut:{gravitationalConstant:-8e3,centralGravity:.12,springLength:170,springConstant:.04},stabilization:{iterations:200}},nodes:{shape:`dot`,size:14,font:{color:`#1F2937`,size:12,face:`DM Sans, sans-serif`},scaling:{label:{enabled:!0,min:12,max:30,drawThreshold:6}},borderWidth:0,chosen:{node:e=>{e.size=20,e.borderWidth=3},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}};try{n.current?.destroy(),m.current!==null&&(clearTimeout(m.current),m.current=null),p.current=null;let e=new ee.Network(t.current,{nodes:i.current,edges:a.current},v);n.current=e,e.on(`zoom`,()=>{m.current!==null&&clearTimeout(m.current),m.current=setTimeout(()=>{m.current=null;let e=n.current,t=i.current;if(!e||!t)return;let r;try{r=e.getScale()}catch{return}let a=M(r);if(a===p.current)return;p.current=a;let s=[];for(let e of o.current.values()){let t=e.labels[0];if(!t||!ue.has(t))continue;let{colour:n}=D(e.labels),i=e.trashed?{background:`${n}40`,border:n}:n;s.push({id:e.id,label:xe(e,r),color:i})}s.length>0&&t.update(s),console.error(`[graph-page] zoom-tier scale=${r.toFixed(3)} tier=${a} conversations=${s.length}`)},N)}),e.on(`selectNode`,e=>{let t=e.nodes[0],n=o.current.get(t);if(!n||(ge(n),ae(n)===`skip-trashed`))return;let r={kind:`neighbourhood`,rootElementId:t,rootLabel:n.labels[0]??null};x(e=>{let n=O(e,r),i=n.length-1;return n.length>e.length&&Me(`nav-push`,{depth:i,kind:r.kind,rootElementId:t}),n.length===10&&e.length===10&&Me(`view-stack-cap-hit`,{depth:10,rootElementId:t}),n})}),e.on(`deselectNode`,()=>{ge(null)});let r=e=>{let n=t.current,r=d.current;if(!n||!r)return!1;let i=n.getBoundingClientRect(),a=r.getBoundingClientRect(),o=i.left+e.x,s=i.top+e.y;return o>=a.left&&o<=a.right&&s>=a.top&&s<=a.bottom},s=t.current?.parentElement??null;e.on(`dragStart`,e=>{let t=e.nodes[0];if(!t){f.current=null;return}f.current=t,s?.classList.add(`graph-dragging`)}),e.on(`dragging`,e=>{if(!f.current)return;let t=r(e.pointer.DOM);ye(e=>e===t?e:t)}),e.on(`dragEnd`,e=>{let t=f.current;f.current=null,ye(!1),s?.classList.remove(`graph-dragging`),t&&r(e.pointer.DOM)&&ct(t,o.current.get(t)?.labels[0]??`Unknown`)})}catch(e){let t=e instanceof Error?e.message:String(e);ce(`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,w.useEffect)(()=>{let e=Ne.trim();if(!e){Ie(``),Re(null),Be(null),Ke(`hybrid`),n.current?.unselectAll();return}let t=setTimeout(()=>Ie(e),300);return()=>clearTimeout(t)},[Ne]),(0,w.useEffect)(()=>{let e=setTimeout(()=>{let e=le(Ve);We(e);try{window.localStorage.setItem(Te,String(e))}catch{}},200);return()=>clearTimeout(e)},[Ve]);let pt=(0,w.useCallback)(e=>{let t=n.current,r=i.current;if(!t||!r)return;let{updates:a,inWindow:s}=oe(e,o.current,D,Ce);a.length>0&&(r.update(a),t.fit({nodes:s,animation:{duration:400,easingFunction:`easeInOutQuad`}}))},[]),mt=A(b);(0,w.useEffect)(()=>{if(!Fe||lt.kind!==`filter`)return;let t=!1;Be(null);let n=encodeURIComponent(mt.selectedLabels.join(`,`)),r=`/api/admin/graph-search?session_key=${encodeURIComponent(e)}&q=${encodeURIComponent(Fe)}&labels=${n}&limit=${Ue}`;return fetch(r).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(e=>{if(t)return;Re(e.results);let n=e.mode===`bm25`?`bm25`:`hybrid`;if(Ke(n),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="${Fe}"`}),keepalive:!0}).catch(()=>{})}catch{}let{nodes:r,edges:i}=se(e.results,mt.selectedLabels);o.current=new Map(r.map(e=>[e.id,e])),me(r.length),fe(null),ft(r,i),pt(e.results)}).catch(e=>{t||Be(e instanceof Error?e.message:String(e))}),()=>{t=!0}},[Fe,Ue,e,pt,lt.kind,mt.selectedLabels,ft]);let ht=(0,w.useCallback)(e=>{x(t=>{let n=A(t),r=new Set(n.selectedLabels);return r.has(e)?r.delete(e):r.add(e),re({kind:`filter`,selectedLabels:[...r].sort(),includeTrashed:n.includeTrashed,includeAgentActions:n.includeAgentActions})})},[]),gt=(0,w.useCallback)(()=>{x(e=>{let t=A(e);return re({...t,includeTrashed:!t.includeTrashed})})},[]),_t=(0,w.useCallback)(()=>{x(e=>{let t=A(e);return re({...t,includeAgentActions:!t.includeAgentActions})})},[]),vt=(0,w.useCallback)(()=>{Pe(``),Ie(``),Re(null),Be(null),Ke(`hybrid`);try{n.current?.unselectAll()}catch{}},[]),yt=(0,w.useCallback)(()=>{x(()=>re({kind:`filter`,selectedLabels:[],includeTrashed:!1,includeAgentActions:!1}))},[]),bt=(0,w.useCallback)(()=>{ge(null);try{n.current?.unselectAll()}catch{}x(e=>{let t=k(e);return t!==e&&Me(`nav-pop`,{depth:t.length-1}),t})},[]),xt=(0,w.useCallback)(()=>{let t=A(b),n={labels:[...t.selectedLabels].sort(),includeTrashed:t.includeTrashed};nt(!0),fetch(`/api/admin/graph-default-view?session_key=${encodeURIComponent(e)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}).then(async e=>{if(!e.ok){let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));throw Error(t.error??`HTTP ${e.status}`)}Qe(n)}).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(()=>nt(!1))},[e,b]),St=(0,w.useCallback)(()=>{ge(null);try{n.current?.unselectAll()}catch{}Je(e=>e+1)},[]),Ct=(0,w.useCallback)(()=>{ge(null);try{n.current?.unselectAll()}catch{}x(e=>[A(e)]),Je(e=>e+1)},[]),wt=lt.kind===`neighbourhood`,Tt=A(b),Et=Tt.selectedLabels,Dt=Tt.includeTrashed,Ot=Tt.includeAgentActions,kt=(0,w.useMemo)(()=>{if(Dt!==Ze.includeTrashed||Et.length!==Ze.labels.length)return!0;for(let e=0;e<Et.length;e++)if(Et[e]!==Ze.labels[e])return!0;return!1},[Dt,Et,Ze]);return(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`div`,{className:`graph-toolbar`,children:[(0,j.jsxs)(`div`,{className:`data-search-input graph-search-input`,children:[(0,j.jsx)(l,{size:14}),(0,j.jsx)(`input`,{type:`text`,placeholder:`Search nodes…`,value:Ne,onChange:e=>Pe(e.target.value),autoComplete:`off`,spellCheck:!1}),Fe&&!Le&&!ze&&(0,j.jsx)(s,{size:14,className:`spin`}),Ne.length>0&&(0,j.jsx)(`button`,{type:`button`,className:`graph-search-clear`,onClick:vt,"aria-label":`Clear search`,title:`Clear search`,children:(0,j.jsx)(h,{size:14})})]}),Fe&&!wt&&(0,j.jsxs)(`div`,{className:`graph-search-limit`,title:`Show top ${Ve} matches (1-2000)`,children:[(0,j.jsxs)(`label`,{htmlFor:`graph-search-limit-slider`,className:`graph-search-limit-label`,children:[`Top `,Ve]}),(0,j.jsx)(`input`,{id:`graph-search-limit-slider`,type:`range`,min:1,max:2e3,step:1,value:Ve,onChange:e=>He(le(e.target.value)),"aria-label":`Maximum search results to render`})]}),!wt&&(0,j.jsxs)(`div`,{className:`graph-filter-wrap`,ref:it,children:[(0,j.jsxs)(`button`,{type:`button`,className:`graph-filter-toggle${$e?` is-open`:``}${Et.length>0||Dt||Ot?` has-selection`:``}`,onClick:()=>et(e=>!e),"aria-haspopup":`true`,"aria-expanded":$e,"aria-label":`Filter node types`,children:[(0,j.jsx)(y,{size:14}),(0,j.jsx)(`span`,{children:`Filter`}),Et.length>0&&(0,j.jsx)(`span`,{className:`graph-filter-count`,children:Et.length})]}),$e&&(0,j.jsxs)(`div`,{className:`graph-filter-popover`,role:`dialog`,"aria-label":`Node type filter`,children:[(0,j.jsxs)(`div`,{className:`graph-filter-popover-header`,children:[(0,j.jsxs)(`button`,{type:`button`,className:`graph-toggle-trashed${Dt?` active`:``}`,onClick:gt,"aria-pressed":Dt,title:`Show trashed nodes — restored with Restore button on each node`,children:[(0,j.jsx)(v,{size:14}),` Show trashed`]}),(Et.length>0||Dt||Ot)&&(0,j.jsx)(`button`,{type:`button`,className:`graph-filter-clear`,onClick:yt,"aria-label":`Clear filter selection`,title:`Clear filter selection`,children:(0,j.jsx)(h,{size:14})})]}),(0,j.jsx)(`div`,{className:`graph-toggle-agent-actions`,title:`Hide ToolCall, StepResult, WorkflowStep, WorkflowRun — agent-execution telemetry. Flip on for audit/debug.`,children:(0,j.jsx)(g,{checked:Ot,onChange:_t,label:`Include agent actions`})}),Ye.length===0&&(0,j.jsx)(`p`,{className:`graph-filter-popover-empty`,children:`No node types in your graph yet.`}),(0,j.jsx)(`div`,{className:`graph-filter-rows`,role:`group`,"aria-label":`Node type filter`,children:Ye.map(({label:e,nodeCount:t})=>{let n=Et.includes(e),r=E(e);return(0,j.jsxs)(`button`,{type:`button`,className:`graph-filter-row${n?` active`:``}`,onClick:()=>ht(e),"aria-pressed":n,children:[(0,j.jsx)(`span`,{className:`graph-filter-row-swatch`,style:{backgroundColor:r}}),(0,j.jsx)(`span`,{className:`graph-filter-row-label`,children:e}),(0,j.jsx)(`span`,{className:`graph-filter-row-count`,children:t})]},e)})}),(0,j.jsx)(`div`,{className:`graph-filter-popover-footer`,children:(0,j.jsx)(`button`,{type:`button`,className:`graph-filter-set-default`,onClick:xt,disabled:!kt||tt,children:tt?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(s,{size:12,className:`spin`}),` Saving…`]}):`Set default view`})})]})]}),(0,j.jsxs)(`div`,{className:`graph-meta`,children:[b.length>1&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`button`,{type:`button`,className:`graph-back-to-filter graph-back-desktop`,onClick:bt,children:`← Back`}),(0,j.jsx)(`button`,{type:`button`,className:`graph-back-to-filter graph-back-mobile`,onClick:bt,"aria-label":`Back`,children:(0,j.jsx)(_,{size:16})})]}),pe>0&&(0,j.jsxs)(`span`,{className:`graph-meta-count`,children:[pe,` node`,pe===1?``:`s`]})]})]}),b.length>1&&(0,j.jsx)(je,{viewStack:b}),Fe&&Ge===`bm25`&&!ze&&(0,j.jsx)(`div`,{className:`graph-error-banner graph-search-degraded`,role:`status`,children:`Vector ranking unavailable — showing keyword-only results.`}),ze&&(0,j.jsxs)(`div`,{className:`data-error graph-error-banner`,children:[`Search unavailable: `,ze]}),Le&&Le.length===0&&!ze&&(0,j.jsx)(`div`,{className:`graph-search-status`,children:`No matches in your graph.`}),(0,j.jsxs)(`div`,{className:`graph-canvas-wrap`,children:[C&&(0,j.jsxs)(`div`,{className:`graph-canvas-overlay`,children:[(0,j.jsx)(s,{size:20,className:`spin`}),` Loading your graph…`]}),te&&!C&&(0,j.jsxs)(`div`,{className:`graph-canvas-overlay graph-canvas-error`,children:[(0,j.jsx)(`p`,{children:te}),(0,j.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:()=>window.location.reload(),children:`Retry`})]}),de&&!C&&(0,j.jsxs)(`div`,{className:`graph-canvas-overlay graph-canvas-error`,children:[(0,j.jsxs)(`p`,{children:[`Refine your filter — `,(0,j.jsx)(`strong`,{children:de.matched}),` matches exceed the 2000 cap.`]}),(0,j.jsx)(`p`,{className:`graph-canvas-hint`,children:`Pick a more specific label combination, or narrow your brand's data.`})]}),!C&&!te&&!de&&pe===0&&!wt&&Et.length===0&&(0,j.jsxs)(`div`,{className:`graph-canvas-overlay`,children:[(0,j.jsx)(y,{size:20}),(0,j.jsx)(`p`,{children:`Open Filter to pick a node type and see what's in your graph.`})]}),!C&&!te&&!de&&pe===0&&!wt&&Et.length>0&&(0,j.jsx)(`div`,{className:`graph-canvas-overlay`,children:(0,j.jsxs)(`p`,{children:[`No `,Et.join(`, `),` nodes in your graph yet.`]})}),(0,j.jsx)(`div`,{ref:t,className:`graph-canvas`}),pe>0&&(0,j.jsx)(`div`,{ref:d,className:`graph-trash-drop-zone${_e?` is-hover`:``}${be?` is-error`:``}`,"aria-hidden":`true`,children:(0,j.jsx)(r,{size:18})}),I&&(0,j.jsxs)(`div`,{className:`graph-drag-error-banner`,role:`alert`,children:[(0,j.jsx)(`span`,{children:I}),(0,j.jsx)(`button`,{type:`button`,className:`graph-drag-error-dismiss`,onClick:()=>De(null),"aria-label":`Dismiss`,children:(0,j.jsx)(h,{size:14})})]})]}),he&&(0,j.jsx)(Oe,{node:he,edges:c.current,nodesById:o.current,sessionKey:e,onClose:()=>{ge(null);try{n.current?.unselectAll()}catch{}},onRestored:St,onTrashed:Ct}),pe>0&&at.length>0&&(0,j.jsx)(`div`,{className:`graph-legend`,children:at.map(e=>(0,j.jsxs)(`div`,{className:`graph-legend-item`,children:[(0,j.jsx)(`span`,{className:`graph-legend-swatch`,style:{backgroundColor:E(e)}}),(0,j.jsx)(`span`,{children:e})]},e))})]})}function Oe({node:e,edges:t,nodesById:n,sessionKey:i,onClose:a,onRestored:o,onTrashed:c}){let l=Object.entries(e.properties).filter(([,e])=>e!=null),u=t.filter(t=>t.from===e.id||t.to===e.id),[d,f]=(0,w.useState)(!1),[p,g]=(0,w.useState)(null),[_,v]=(0,w.useState)(!1),[y,b]=(0,w.useState)(null);(0,w.useEffect)(()=>{f(!1),g(null),v(!1),b(null)},[e.id]);let x=(0,w.useCallback)(()=>{f(!0),g(null),fetch(`/api/admin/graph-restore?session_key=${encodeURIComponent(i)}`,{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}`);o()}).catch(e=>{g(e instanceof Error?e.message:String(e)),f(!1)})},[e.id,o,i]),S=(0,w.useCallback)(()=>{v(!0),b(null),fetch(`/api/admin/graph-delete?session_key=${encodeURIComponent(i)}`,{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=>{b(e instanceof Error?e.message:String(e)),v(!1)})},[e.id,c,i]);return(0,j.jsxs)(`aside`,{className:`graph-side-panel${e.trashed?` graph-side-panel-trashed`:``}`,children:[(0,j.jsxs)(`header`,{className:`graph-side-header`,children:[(0,j.jsx)(`div`,{children:(()=>{if(e.labels.some(e=>ue.has(e))){let t=ye(e),n=e.properties.createdAt,r=typeof n==`string`?n:``,i=r?he(r):null,a=e.labels.join(` · `)+(e.trashed?` · Trashed`:``)+` · ${e.id}`;return(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`h2`,{className:`graph-side-name`,title:t,children:t}),i&&(0,j.jsx)(`div`,{className:`graph-side-created`,children:i}),(0,j.jsx)(`div`,{className:`graph-side-meta`,children:a})]})}return(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`div`,{className:`graph-side-labels`,children:[e.labels.join(` · `),e.trashed?` · Trashed`:``]}),(0,j.jsx)(`div`,{className:`graph-side-id`,children:e.id})]})})()}),(0,j.jsx)(`button`,{type:`button`,className:`graph-side-close`,onClick:a,"aria-label":`Close`,children:(0,j.jsx)(h,{size:14})})]}),e.trashed&&(0,j.jsxs)(`dl`,{className:`graph-side-props graph-side-trash-meta`,children:[(0,j.jsxs)(`div`,{className:`graph-side-prop`,children:[(0,j.jsx)(`dt`,{children:`trashedAt`}),(0,j.jsx)(`dd`,{children:Pe(e.properties.trashedAt)})]}),(0,j.jsxs)(`div`,{className:`graph-side-prop`,children:[(0,j.jsx)(`dt`,{children:`trashedBy`}),(0,j.jsx)(`dd`,{children:Pe(e.properties.trashedBy)})]})]}),(0,j.jsxs)(`dl`,{className:`graph-side-props`,children:[l.length===0&&(0,j.jsx)(`div`,{className:`graph-side-empty`,children:`No properties.`}),l.map(([e,t])=>(0,j.jsxs)(`div`,{className:`graph-side-prop`,children:[(0,j.jsx)(`dt`,{children:e}),(0,j.jsx)(`dd`,{children:Pe(t)})]},e))]}),u.length>0&&(0,j.jsxs)(`section`,{className:`graph-side-edges`,children:[(0,j.jsxs)(`h3`,{className:`graph-side-edges-heading`,children:[`Connections (`,u.length,`)`]}),u.map(t=>{let r=t.from===e.id,i=r?t.to:t.from,a=n.get(i),o=a?ve(a):i,s=r?`→`:`←`,c=Object.entries(t.properties??{}).filter(([,e])=>e!=null&&e!==``);return(0,j.jsxs)(`div`,{className:`graph-side-edge`,children:[(0,j.jsxs)(`div`,{className:`graph-side-edge-header`,children:[(0,j.jsx)(`span`,{className:`graph-side-edge-type`,children:t.type}),(0,j.jsx)(`span`,{className:`graph-side-edge-arrow`,children:s}),(0,j.jsx)(`span`,{className:`graph-side-edge-other`,title:o,children:o})]}),c.length>0&&(0,j.jsx)(`dl`,{className:`graph-side-edge-props`,children:c.map(([e,t])=>(0,j.jsxs)(`div`,{className:`graph-side-prop`,children:[(0,j.jsx)(`dt`,{children:e}),(0,j.jsx)(`dd`,{children:Pe(t)})]},e))})]},t.id)})]}),e.trashed&&(0,j.jsxs)(`footer`,{className:`graph-side-footer`,children:[!d&&!p&&(0,j.jsxs)(`button`,{type:`button`,className:`graph-side-restore`,onClick:x,children:[(0,j.jsx)(m,{size:14}),` Restore`]}),d&&(0,j.jsx)(`div`,{className:`graph-delete-confirm`,children:(0,j.jsxs)(`p`,{children:[(0,j.jsx)(s,{size:14,className:`spin`}),` Restoring…`]})}),p&&(0,j.jsxs)(`div`,{className:`graph-delete-confirm graph-delete-confirm-error`,children:[(0,j.jsxs)(`p`,{children:[`Restore failed: `,p]}),(0,j.jsxs)(`div`,{className:`graph-delete-confirm-buttons`,children:[(0,j.jsx)(`button`,{type:`button`,className:`graph-delete-confirm-cancel`,onClick:()=>{g(null)},children:`Close`}),(0,j.jsx)(`button`,{type:`button`,className:`graph-delete-confirm-do`,onClick:x,children:`Retry`})]})]})]}),!e.trashed&&(0,j.jsxs)(`footer`,{className:`graph-side-footer`,children:[!_&&!y&&(0,j.jsxs)(`button`,{type:`button`,className:`graph-side-trash`,onClick:S,children:[(0,j.jsx)(r,{size:14}),` Trash`]}),_&&(0,j.jsx)(`div`,{className:`graph-delete-confirm`,children:(0,j.jsxs)(`p`,{children:[(0,j.jsx)(s,{size:14,className:`spin`}),` Trashing…`]})}),y&&(0,j.jsxs)(`div`,{className:`graph-delete-confirm graph-delete-confirm-error`,children:[(0,j.jsxs)(`p`,{children:[`Trash failed: `,y]}),(0,j.jsxs)(`div`,{className:`graph-delete-confirm-buttons`,children:[(0,j.jsx)(`button`,{type:`button`,className:`graph-delete-confirm-cancel`,onClick:()=>{b(null)},children:`Close`}),(0,j.jsx)(`button`,{type:`button`,className:`graph-delete-confirm-do`,onClick:S,children:`Retry`})]})]})]})]})}function ke(e,t,n){let r=`/api/admin/graph-subgraph?session_key=${encodeURIComponent(e)}`,i=n.includeAgentActions?`&includeAgentActions=1`:``;if(t.kind===`neighbourhood`){let e=n.search&&n.search.q?`&q=${encodeURIComponent(n.search.q)}&limit=${n.search.limit}`:``;return`${r}&mode=neighbourhood&elementId=${encodeURIComponent(t.rootElementId)}${i}${e}`}return`${r}&mode=default&labels=${encodeURIComponent(t.selectedLabels.join(`,`))}${t.includeTrashed?`&includeTrashed=1`:``}${i}`}var Ae=class extends Error{body;constructor(e){super(e.error),this.body=e}};function je({viewStack:e}){let t=e.map(e=>e.kind===`filter`?`Filter`:e.rootLabel??`Node`);return(0,j.jsx)(`div`,{className:`graph-breadcrumb`,role:`navigation`,"aria-label":`Graph navigation breadcrumb`,children:t.map((e,n)=>(0,j.jsxs)(`span`,{className:`graph-breadcrumb-item`,children:[n>0&&(0,j.jsx)(`span`,{className:`graph-breadcrumb-separator`,"aria-hidden":`true`,children:`›`}),(0,j.jsx)(`span`,{className:`graph-breadcrumb-label${n===t.length-1?` is-current`:``}`,children:e})]},n))})}function Me(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{}}function Ne(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 Pe(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=Ne(e);if(t)return t}return JSON.stringify(e)}return String(e)}(0,C.createRoot)(document.getElementById(`root`)).render((0,j.jsx)(F,{}));
@@ -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-DhNy70eS.js"></script>
8
+ <script type="module" crossorigin src="/assets/graph-BoSJpLG3.js"></script>
9
9
  <link rel="modulepreload" crossorigin href="/assets/chunk-DD-I1_y5.js">
10
10
  <link rel="modulepreload" crossorigin href="/assets/jsx-runtime-BkCc5_JK.js">
11
11
  <link rel="modulepreload" crossorigin href="/assets/Checkbox-B27PGbJv.js">
@@ -46,7 +46,7 @@ import {
46
46
  vncLog,
47
47
  waitForExit,
48
48
  writeChromiumWrapper
49
- } from "./chunk-2T4RRIJK.js";
49
+ } from "./chunk-SPTD7L7Z.js";
50
50
  import {
51
51
  GREETING_DIRECTIVE,
52
52
  HAIKU_MODEL,