@astrale-os/cli 1.0.0-beta.2 → 1.0.0-beta.3
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/dist/astrale.js +57 -53
- package/dist/public/connect-core.js +9 -9
- package/dist/public/keys/index.js +1 -1
- package/dist/public/paths/index.js +1 -1
- package/package.json +4 -4
- package/viewer/dist/main.js +1 -1
package/viewer/dist/main.js
CHANGED
|
@@ -94,4 +94,4 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
94
94
|
`)-1&&t.runes[2]===T.CODES.get(`
|
|
95
95
|
`)+1&&t.runes[3]===re.MAX_RUNE)t.runes=[],t.op=E.Op.ANY_CHAR_NOT_NL}}collapse(t,r){if(t.length===1)return t[0];let i=0;for(let a of t)i+=a.op===r?a.subs.length:1;let n=Array(i).fill(null),o=0;for(let a of t)if(a.op===r){for(let c=0;c<a.subs.length;c++)n[o++]=a.subs[c];this.reuse(a)}else n[o++]=a;let s=this.newRegexp(r);if(s.subs=n,r===E.Op.ALTERNATE){if(s.subs=this.factor(s.subs),s.subs.length===1){let a=s;s=s.subs[0],this.reuse(a)}}return s}factor(t){if(t.length<2)return t;let r=0,i=t.length,n=0,o=null,s=0,a=0,c=0;for(let l=0;l<=i;l++){let d=null,f=0,m=0;if(l<i){let B=t[r+l];if(B.op===E.Op.CONCAT&&B.subs.length>0)B=B.subs[0];if(B.op===E.Op.LITERAL)d=B.runes,f=B.runes.length,m=B.flags&j.FOLD_CASE;if(m===a){let h=0;while(h<s&&h<f&&o[h]===d[h])h++;if(h>0){s=h;continue}}}if(l===c);else if(l===c+1)t[n++]=t[r+c];else{let B=this.newRegexp(E.Op.LITERAL);B.flags=a,B.runes=o.slice(0,s);for(let w=c;w<l;w++)t[r+w]=this.removeLeadingString(t[r+w],s),this.checkLimits(t[r+w]);let h=this.collapse(t.slice(r+c,r+l),E.Op.ALTERNATE),g=this.newRegexp(E.Op.CONCAT);g.subs=[B,h],t[n++]=g}c=l,o=d,s=f,a=m}i=n,r=0,c=0,n=0;let u=null;for(let l=0;l<=i;l++){let d=null;if(l<i){if(d=e.leadingRegexp(t[r+l]),u!==null&&u.equals(d)&&(e.isCharClass(u)||u.op===E.Op.REPEAT&&u.min===u.max&&e.isCharClass(u.subs[0])))continue}if(l===c);else if(l===c+1)t[n++]=t[r+c];else{let f=u;for(let h=c;h<l;h++){let g=h!==c;t[r+h]=this.removeLeadingRegexp(t[r+h],g),this.checkLimits(t[r+h])}let m=this.collapse(t.slice(r+c,r+l),E.Op.ALTERNATE),B=this.newRegexp(E.Op.CONCAT);B.subs=[f,m],t[n++]=B}c=l,u=d}i=n,r=0,c=0,n=0;for(let l=0;l<=i;l++){if(l<i&&e.isCharClass(t[r+l]))continue;if(l===c);else if(l===c+1)t[n++]=t[r+c];else{let d=c;for(let m=c+1;m<l;m++){let B=t[r+d],h=t[r+m];if(B.op<h.op||B.op===h.op&&(B.runes!==null?B.runes.length:0)<(h.runes!==null?h.runes.length:0))d=m}let f=t[r+c];t[r+c]=t[r+d],t[r+d]=f;for(let m=c+1;m<l;m++)e.mergeCharClass(t[r+c],t[r+m]),this.reuse(t[r+m]);this.cleanAlt(t[r+c]),t[n++]=t[r+c]}if(l<i)t[n++]=t[r+l];c=l+1}i=n,r=0,c=0,n=0;for(let l=0;l<i;++l){if(l+1<i&&t[r+l].op===E.Op.EMPTY_MATCH&&t[r+l+1].op===E.Op.EMPTY_MATCH)continue;t[n++]=t[r+l]}return i=n,r=0,t.slice(r,i)}removeLeadingString(t,r){if(t.op===E.Op.CONCAT&&t.subs.length>0){let i=this.removeLeadingString(t.subs[0],r);if(t.subs[0]=i,i.op===E.Op.EMPTY_MATCH)switch(this.reuse(i),t.subs.length){case 0:case 1:t.op=E.Op.EMPTY_MATCH,t.subs=E.emptySubs();break;case 2:{let n=t;t=t.subs[1],this.reuse(n);break}default:t.subs=t.subs.slice(1,t.subs.length);break}return t}if(t.op===E.Op.LITERAL){if(t.runes=t.runes.slice(r,t.runes.length),t.runes.length===0)t.op=E.Op.EMPTY_MATCH}return t}removeLeadingRegexp(t,r){if(t.op===E.Op.CONCAT&&t.subs.length>0){if(r)this.reuse(t.subs[0]);switch(t.subs=t.subs.slice(1,t.subs.length),t.subs.length){case 0:t.op=E.Op.EMPTY_MATCH,t.subs=E.emptySubs();break;case 1:{let i=t;t=t.subs[0],this.reuse(i);break}}return t}if(r)this.reuse(t);return this.newRegexp(E.Op.EMPTY_MATCH)}parseInternal(){if((this.flags&j.LITERAL)!==0)return e.literalRegexp(this.wholeRegexp,this.flags);let t=-1,r=-1,i=-1,n=new D4(this.wholeRegexp);while(n.more()){let o=-1;e:switch(n.peek()){case T.CODES.get("("):if((this.flags&j.LOOKBEHIND)!==0){if(n.lookingAt("(?<=")){this.parsePosLookBehind(),n.skip(4);break}if(n.lookingAt("(?<!")){this.parseNegLookBehind(),n.skip(4);break}}if((this.flags&j.PERL_X)!==0&&n.lookingAt("(?")){this.parsePerlFlags(n);break}this.op(E.Op.LEFT_PAREN).cap=++this.numCap,n.skip(1);break;case T.CODES.get("|"):this.parseVerticalBar(),n.skip(1);break;case T.CODES.get(")"):this.parseRightParen(),n.skip(1);break;case T.CODES.get("^"):if((this.flags&j.ONE_LINE)!==0)this.op(E.Op.BEGIN_TEXT);else this.op(E.Op.BEGIN_LINE);n.skip(1);break;case T.CODES.get("$"):if((this.flags&j.ONE_LINE)!==0)this.op(E.Op.END_TEXT).flags|=j.WAS_DOLLAR;else this.op(E.Op.END_LINE);n.skip(1);break;case T.CODES.get("."):if((this.flags&j.DOT_NL)!==0)this.op(E.Op.ANY_CHAR);else this.op(E.Op.ANY_CHAR_NOT_NL);n.skip(1);break;case T.CODES.get("["):this.parseClass(n);break;case T.CODES.get("*"):case T.CODES.get("+"):case T.CODES.get("?"):{o=n.pos();let s=null;switch(n.pop()){case T.CODES.get("*"):s=E.Op.STAR;break;case T.CODES.get("+"):s=E.Op.PLUS;break;case T.CODES.get("?"):s=E.Op.QUEST;break}this.repeat(s,r,i,o,n,t);break}case T.CODES.get("{"):{o=n.pos();let s=e.parseRepeat(n);if(s<0){n.rewindTo(o),this.literal(n.pop());break}r=s>>16,i=(s&re.MAX_BMP)<<16>>16,this.repeat(E.Op.REPEAT,r,i,o,n,t);break}case T.CODES.get("\\"):{let s=n.pos();if(n.skip(1),(this.flags&j.PERL_X)!==0&&n.more())switch(n.pop()){case T.CODES.get("A"):this.op(E.Op.BEGIN_TEXT);break e;case T.CODES.get("b"):this.op(E.Op.WORD_BOUNDARY);break e;case T.CODES.get("B"):this.op(E.Op.NO_WORD_BOUNDARY);break e;case T.CODES.get("C"):throw new ut(e.ERR_INVALID_ESCAPE,"\\C");case T.CODES.get("Q"):{let u=n.rest(),l=u.indexOf("\\E");if(l>=0)u=u.substring(0,l),n.skipString(u),n.skipString("\\E");else n.skipString(u);let d=0;while(d<u.length){let f=u.codePointAt(d);this.literal(f),d+=ce.charCount(f)}break e}case T.CODES.get("z"):this.op(E.Op.END_TEXT);break e;default:n.rewindTo(s);break}else n.rewindTo(s);let a=this.newRegexp(E.Op.CHAR_CLASS);if(a.flags=this.flags,n.lookingAt("\\p")||n.lookingAt("\\P")){let u=new Mi;if(this.parseUnicodeClass(n,u)){a.runes=u.toArray(),this.push(a);break e}}let c=new Mi;if(this.parsePerlClassEscape(n,c)){a.runes=c.toArray(),this.push(a);break e}n.rewindTo(s),this.reuse(a),this.literal(e.parseEscape(n));break}default:this.literal(n.pop());break}t=o}if(this.concat(),this.swapVerticalBar())this.pop();if(this.alternate(),this.stack.length!==1)throw new ut(e.ERR_MISSING_PAREN,this.wholeRegexp);return this.stack[0].namedGroups=this.namedGroups,this.stack[0]}parsePerlFlags(t){let r=t.pos(),i=t.rest();if(i.startsWith("(?P<")||i.startsWith("(?<")){let a=i.charAt(2)==="P"?4:3,c=i.indexOf(">");if(c<0)throw new ut(e.ERR_INVALID_NAMED_CAPTURE,i);let u=i.substring(a,c);if(t.skipString(u),t.skip(a+1),!e.isValidCaptureName(u))throw new ut(e.ERR_INVALID_NAMED_CAPTURE,i.substring(0,c+1));let l=this.op(E.Op.LEFT_PAREN);if(l.cap=++this.numCap,this.namedGroups[u])throw new ut(e.ERR_DUPLICATE_NAMED_CAPTURE,u);this.namedGroups[u]=this.numCap,l.name=u;return}t.skip(2);let n=this.flags,o=1,s=!1;e:while(t.more()){let a=t.pop();switch(a){case T.CODES.get("i"):n|=j.FOLD_CASE,s=!0;break;case T.CODES.get("m"):n&=~j.ONE_LINE,s=!0;break;case T.CODES.get("s"):n|=j.DOT_NL,s=!0;break;case T.CODES.get("U"):n|=j.NON_GREEDY,s=!0;break;case T.CODES.get("-"):if(o<0)break e;o=-1,n=~n,s=!1;break;case T.CODES.get(":"):case T.CODES.get(")"):if(o<0){if(!s)break e;n=~n}if(a===T.CODES.get(":"))this.op(E.Op.LEFT_PAREN);this.flags=n;return;default:break e}}throw new ut(e.ERR_INVALID_PERL_OP,t.from(r))}parsePosLookBehind(){let t=this.newRegexp(E.Op.LEFT_PAREN);return t.flags=this.flags,t.lb=++this.nlb,this.push(t)}parseNegLookBehind(){let t=this.newRegexp(E.Op.LEFT_PAREN);return t.flags=this.flags,t.lb=-++this.nlb,this.push(t)}parseVerticalBar(){if(this.concat(),!this.swapVerticalBar())this.op(E.Op.VERTICAL_BAR)}swapVerticalBar(){let t=this.stack.length;if(t>=3&&this.stack[t-2].op===E.Op.VERTICAL_BAR&&e.isCharClass(this.stack[t-1])&&e.isCharClass(this.stack[t-3])){let r=this.stack[t-1],i=this.stack[t-3];if(r.op>i.op){let n=i;i=r,r=n,this.stack[t-3]=i}return e.mergeCharClass(i,r),this.reuse(r),this.pop(),!0}if(t>=2){let r=this.stack[t-1],i=this.stack[t-2];if(i.op===E.Op.VERTICAL_BAR){if(t>=3)this.cleanAlt(this.stack[t-3]);return this.stack[t-2]=r,this.stack[t-1]=i,!0}}return!1}parseRightParen(){if(this.concat(),this.swapVerticalBar())this.pop();if(this.alternate(),this.stack.length<2)throw new ut(e.ERR_UNEXPECTED_PAREN,this.wholeRegexp);let t=this.pop(),r=this.pop();if(r.op!==E.Op.LEFT_PAREN)throw new ut(e.ERR_UNEXPECTED_PAREN,this.wholeRegexp);if(this.flags=r.flags,r.lb!==0){if(e.hasCapture(t))throw new ut(e.ERR_INVALID_CAPTURE_IN_LOOKBEHIND,this.wholeRegexp);if(r.lb>0)r.op=E.Op.PLB;else r.op=E.Op.NLB;r.subs=[t],this.push(r);return}if(r.cap===0)this.push(t);else r.op=E.Op.CAPTURE,r.subs=[t],this.push(r)}parsePerlClassEscape(t,r){let i=t.pos();if((this.flags&j.PERL_X)===0||!t.more()||t.pop()!==T.CODES.get("\\")||!t.more())return!1;t.pop();let n=t.from(i),o=uS.has(n)?uS.get(n):null;if(o===null)return!1;return r.appendGroup(o,(this.flags&j.FOLD_CASE)!==0),!0}parseNamedClass(t,r){let i=t.rest(),n=i.indexOf(":]");if(n<0)return!1;let o=i.substring(0,n+2);t.skipString(o);let s=wS.has(o)?wS.get(o):null;if(s===null)throw new ut(e.ERR_INVALID_CHAR_RANGE,o);return r.appendGroup(s,(this.flags&j.FOLD_CASE)!==0),!0}parseUnicodeClass(t,r){let i=t.pos();if((this.flags&j.UNICODE_GROUPS)===0||!t.lookingAt("\\p")&&!t.lookingAt("\\P"))return!1;t.skip(1);let n=1,o=t.pop();if(o===T.CODES.get("P"))n=-1;if(!t.more())throw t.rewindTo(i),new ut(e.ERR_INVALID_CHAR_RANGE,t.rest());o=t.pop();let s;if(o!==T.CODES.get("{"))s=ce.runeToString(o);else{let l=t.rest(),d=l.indexOf("}");if(d<0)throw t.rewindTo(i),new ut(e.ERR_INVALID_CHAR_RANGE,t.rest());s=l.substring(0,d),t.skipString(s),t.skip(1)}if(s.length!==0&&s.codePointAt(0)===T.CODES.get("^"))n=0-n,s=s.substring(1);let a=e.unicodeTable(s);if(a===null)throw new ut(e.ERR_INVALID_CHAR_RANGE,t.from(i));if(a.sign<0)n=0-n;let{tab:c,fold:u}=a;if((this.flags&j.FOLD_CASE)===0||u===null)r.appendTableWithSign(c,n);else{let l=new Mi().appendTable(c).appendTable(u).cleanClass().toArray();r.appendClassWithSign(l,n)}return!0}parseClass(t){let r=t.pos();t.skip(1);let i=this.newRegexp(E.Op.CHAR_CLASS);i.flags=this.flags;let n=new Mi,o=1;if(t.more()&&t.lookingAt("^")){if(o=-1,t.skip(1),(this.flags&j.CLASS_NL)===0)n.appendRange(T.CODES.get(`
|
|
96
96
|
`),T.CODES.get(`
|
|
97
|
-
`))}let s=!0;while(!t.more()||t.peek()!==T.CODES.get("]")||s){if(t.more()&&t.lookingAt("-")&&(this.flags&j.PERL_X)===0&&!s){let l=t.rest();if(l==="-"||!l.startsWith("-]"))throw t.rewindTo(r),new ut(e.ERR_INVALID_CHAR_RANGE,t.rest())}s=!1;let a=t.pos();if(t.lookingAt("[:")){if(this.parseNamedClass(t,n))continue;t.rewindTo(a)}if(this.parseUnicodeClass(t,n))continue;if(this.parsePerlClassEscape(t,n))continue;t.rewindTo(a);let c=e.parseClassChar(t,r),u=c;if(t.more()&&t.lookingAt("-")){if(t.skip(1),t.more()&&t.lookingAt("]"))t.skip(-1);else if(u=e.parseClassChar(t,r),u<c)throw new ut(e.ERR_INVALID_CHAR_RANGE,t.from(a))}if((this.flags&j.FOLD_CASE)===0)n.appendRange(c,u);else n.appendFoldedRange(c,u)}if(t.skip(1),n.cleanClass(),o<0)n.negateClass();i.runes=n.toArray(),this.push(i)}},_4=class e{static initTest(t){let r=e.compile(t),i=new e(r.expr,r.prog,r.numSubexp,r.longest);return i.cond=r.cond,i.prefix=r.prefix,i.prefixUTF8=r.prefixUTF8,i.prefixComplete=r.prefixComplete,i.prefixRune=r.prefixRune,i.prefilter=r.prefilter,i}static compile(t){return e.compileImpl(t,j.PERL,!1)}static compilePOSIX(t){return e.compileImpl(t,j.POSIX,!0)}static compileImpl(t,r,i){let n=NS.parse(t,r),o=n.maxCap();n=TS.simplify(n);let s=I4.build(n),a=$S.compileRegexp(n),c=new e(t,a,o,i);c.prefilter=s.type===Me.Type.NONE?null:s;let[u,l]=a.prefix();if(c.prefixComplete=u,c.prefix=l,c.prefixUTF8=ce.stringToUtf8ByteArray(c.prefix),c.prefix.length>0)c.prefixRune=c.prefix.codePointAt(0);return c.namedGroups=n.namedGroups,c}static match(t,r){return e.compile(t).match(r)}constructor(t,r,i=0,n=0){this.expr=t,this.prog=r,this.numSubexp=i,this.longest=n,this.cond=r.startCond(),this.prefix=null,this.prefixUTF8=null,this.prefixComplete=!1,this.prefixRune=0,this.machinePool=[],this.dfa=new AS(this.prog),this.onepass=iS.compile(this.prog),this.prefilter=null}matchPrefixComplete(t,r,i,n){if((i===j.ANCHOR_START||i===j.ANCHOR_BOTH)&&r!==0)return null;let o=-1,s=-1,a=t.prefixLength(this);if(i===j.UNANCHORED){let c=t.index(this,r);if(c<0)return null;o=r+c,s=o+a}else if(i===j.ANCHOR_BOTH){if(t.endPos()!==a)return null;if(t.index(this,0)!==0)return null;o=0,s=a}else if(i===j.ANCHOR_START){if(t.index(this,0)!==0)return null;o=0,s=a}if(o<0)return null;if(n>0){let c=new Int32Array(n).fill(-1);return c[0]=o,c[1]=s,Array.from(c)}return[]}executeEngine(t,r,i,n){if(this.prefixComplete&&(n===0||this.numSubexp===0))return this.matchPrefixComplete(t,r,i,n);if(this.prefilter!==null&&i===j.UNANCHORED){if(!this.prefilter.eval(t,r))return null}if(this.onepass!==null)return iS.execute(this,t,r,i,n);if(n>0){if(this.prog.numLb===0&&t.endPos()<=Mf.maxBitStateLen(this.prog))return Mf.execute(this,t,r,i,n);return this.doExecuteNFA(t,r,i,n)}if(this.prog.numLb===0){let o=this.dfa.match(t,r,i);if(o!==null)return o?[]:null;if(t.endPos()<=Mf.maxBitStateLen(this.prog))return Mf.execute(this,t,r,i,n)}return this.doExecuteNFA(t,r,i,n)}numberOfCapturingGroups(){return this.numSubexp}numberOfInstructions(){return this.prog.numInst()}get(){return this.machinePool.length>0?this.machinePool.pop():null}reset(){this.machinePool.length=0}put(t){this.machinePool.push(t)}toString(){return this.expr}doExecuteNFA(t,r,i,n){let o=this.get();if(!o)o=SS.fromRE2(this);o.init(n);let s=o.match(t,r,i)?o.submatches():null;return this.put(o),s}match(t){return this.executeEngine(nt.fromUTF16(t),0,j.UNANCHORED,0)!==null}matchWithGroup(t,r,i,n,o){if(!(t instanceof Ao))if(ce.isByteArray(t))t=So.utf8(t);else t=So.utf16(t);return this.matchMachineInput(t,r,i,n,o)}matchMachineInput(t,r,i,n,o){if(r>i)return[!1,null];let s=t.isUTF16Encoding()?nt.fromUTF16(t.asCharSequence(),0,i):nt.fromUTF8(t.asBytes(),0,i),a=this.executeEngine(s,r,n,2*o);if(a===null)return[!1,null];return[!0,a]}matchUTF8(t){return this.executeEngine(nt.fromUTF8(t),0,j.UNANCHORED,0)!==null}replaceAll(t,r){return this.replaceAllFunc(t,()=>r,2*t.length+1)}replaceFirst(t,r){return this.replaceAllFunc(t,()=>r,1)}replaceAllFunc(t,r,i){let n=0,o=0,s="",a=nt.fromUTF16(t),c=0;while(o<=t.length){let u=this.executeEngine(a,o,j.UNANCHORED,2);if(u===null||u.length===0)break;if(s+=t.substring(n,u[0]),u[1]>n||u[0]===0)s+=r(t.substring(u[0],u[1])),c++;n=u[1];let l=a.step(o)&7;if(o+l>u[1])o+=l;else if(o+1>u[1])o++;else o=u[1];if(c>=i)break}return s+=t.substring(n),s}pad(t){if(t===null)return null;let r=(1+this.numSubexp)*2;if(t.length<r){let i=Array(r).fill(-1);for(let n=0;n<t.length;n++)i[n]=t[n];t=i}return t}allMatches(t,r,i=(n)=>n){let n=[],o=t.endPos();if(r<0)r=o+1;let s=0,a=0,c=-1;while(a<r&&s<=o){let u=this.executeEngine(t,s,j.UNANCHORED,this.prog.numCap);if(u===null||u.length===0)break;let l=!0;if(u[1]===s){if(u[0]===c)l=!1;let d=t.step(s);if(d<0)s=o+1;else s+=d&7}else s=u[1];if(c=u[1],l)n.push(i(this.pad(u))),a++}return n}findUTF8(t){let r=this.executeEngine(nt.fromUTF8(t),0,j.UNANCHORED,2);if(r===null)return null;return t.slice(r[0],r[1])}findUTF8Index(t){let r=this.executeEngine(nt.fromUTF8(t),0,j.UNANCHORED,2);if(r===null)return null;return r.slice(0,2)}find(t){let r=this.executeEngine(nt.fromUTF16(t),0,j.UNANCHORED,2);if(r===null)return"";return t.substring(r[0],r[1])}findIndex(t){return this.executeEngine(nt.fromUTF16(t),0,j.UNANCHORED,2)}findUTF8Submatch(t){let r=this.executeEngine(nt.fromUTF8(t),0,j.UNANCHORED,this.prog.numCap);if(r===null)return null;let i=Array(1+this.numSubexp).fill(null);for(let n=0;n<i.length;n++)if(2*n<r.length&&r[2*n]>=0)i[n]=t.slice(r[2*n],r[2*n+1]);return i}findUTF8SubmatchIndex(t){return this.pad(this.executeEngine(nt.fromUTF8(t),0,j.UNANCHORED,this.prog.numCap))}findSubmatch(t){let r=this.executeEngine(nt.fromUTF16(t),0,j.UNANCHORED,this.prog.numCap);if(r===null)return null;let i=Array(1+this.numSubexp).fill(null);for(let n=0;n<i.length;n++)if(2*n<r.length&&r[2*n]>=0)i[n]=t.substring(r[2*n],r[2*n+1]);return i}findSubmatchIndex(t){return this.pad(this.executeEngine(nt.fromUTF16(t),0,j.UNANCHORED,this.prog.numCap))}findAllUTF8(t,r){let i=this.allMatches(nt.fromUTF8(t),r,(n)=>t.slice(n[0],n[1]));if(i.length===0)return null;return i}findAllUTF8Index(t,r){let i=this.allMatches(nt.fromUTF8(t),r,(n)=>n.slice(0,2));if(i.length===0)return null;return i}findAll(t,r){let i=this.allMatches(nt.fromUTF16(t),r,(n)=>t.substring(n[0],n[1]));if(i.length===0)return null;return i}findAllIndex(t,r){let i=this.allMatches(nt.fromUTF16(t),r,(n)=>n.slice(0,2));if(i.length===0)return null;return i}findAllUTF8Submatch(t,r){let i=this.allMatches(nt.fromUTF8(t),r,(n)=>{let o=Array(n.length/2|0).fill(null);for(let s=0;s<o.length;s++)if(n[2*s]>=0)o[s]=t.slice(n[2*s],n[2*s+1]);return o});if(i.length===0)return null;return i}findAllUTF8SubmatchIndex(t,r){let i=this.allMatches(nt.fromUTF8(t),r);if(i.length===0)return null;return i}findAllSubmatch(t,r){let i=this.allMatches(nt.fromUTF16(t),r,(n)=>{let o=Array(n.length/2|0).fill(null);for(let s=0;s<o.length;s++)if(n[2*s]>=0)o[s]=t.substring(n[2*s],n[2*s+1]);return o});if(i.length===0)return null;return i}findAllSubmatchIndex(t,r){let i=this.allMatches(nt.fromUTF16(t),r);if(i.length===0)return null;return i}},RQ=class e{static UNANCHORED=j.UNANCHORED;static ANCHOR_START=j.ANCHOR_START;static ANCHOR_BOTH=j.ANCHOR_BOTH;constructor(t=e.UNANCHORED,r=0,i=8388608){this.anchor=t,this.jsFlags=r,this.maxMem=i;let n=j.PERL;if((r&mn.DISABLE_UNICODE_GROUPS)!==0)n&=~j.UNICODE_GROUPS;if((r&mn.LOOKBEHINDS)!==0)n|=j.LOOKBEHIND;this.re2Flags=n,this.regexps=[],this.prog=null,this.dfa=null,this.dummyRe2=null}add(t){if(this.prog)throw new kS("Cannot add patterns after compile");let r=t;if((this.jsFlags&mn.CASE_INSENSITIVE)!==0)r=`(?i)${r}`;if((this.jsFlags&mn.DOTALL)!==0)r=`(?s)${r}`;if((this.jsFlags&mn.MULTILINE)!==0)r=`(?m)${r}`;let i=NS.parse(r,this.re2Flags);return this.regexps.push(TS.simplify(i)),this.regexps.length-1}compile(){if(this.prog)return;this.prog=$S.compileSet(this.regexps),this.dfa=new AS(this.prog,this.maxMem),this.dummyRe2={prog:this.prog,cond:this.prog.startCond(),prefix:"",prefixRune:0,longest:!1}}match(t){if(!this.prog)this.compile();let r=ce.isByteArray(t)?nt.fromUTF8(t):nt.fromUTF16(t),i=j.UNANCHORED;if(this.anchor===e.ANCHOR_START)i=j.ANCHOR_START;else if(this.anchor===e.ANCHOR_BOTH)i=j.ANCHOR_BOTH;let n=this.dfa.matchSet(r,0,i);if(n!==null)return n;let o=SS.fromRE2(this.dummyRe2);return o.init(0),o.matchSet(r,0,i)}},k4=class e{static isHexadecimal(t){return"0"<=t&&t<="9"||"A"<=t&&t<="F"||"a"<=t&&t<="f"}static translate(t){let r="";if(t instanceof RegExp){if(t.ignoreCase)r+="i";if(t.multiline)r+="m";if(t.dotAll)r+="s";t=t.source}if(typeof t!=="string")return t;let i="",n=!1,o=t.length;if(o===0)i="(?:)",n=!0;let s=!1,a=0;while(a<o){let u=t[a];if(u==="\\"){if(a+1<o)switch(u=t[a+1],u){case"\\":i+="\\\\",a+=2;continue;case"c":if(a+2<o){let f=t[a+2].charCodeAt(0);if(f>=65&&f<=90||f>=97&&f<=122){let m=f%32;i+="\\x",i+=(m>>4).toString(16).toUpperCase(),i+=(m&15).toString(16).toUpperCase(),a+=3,n=!0;continue}}i+="c",a+=2,n=!0;continue;case"u":if(a+2<o){if(t[a+2]==="{"){let f=a+3,m=!1,B=!1;while(f<o){let h=t[f];if(h==="}"){B=!0;break}if(!e.isHexadecimal(h))break;m=!0,f++}if(B&&m){i+="\\x",a+=2,n=!0;continue}}else if(a+5<o){let f=!0;for(let m=0;m<4;m++)if(!e.isHexadecimal(t[a+2+m])){f=!1;break}if(f){i+="\\x{"+t.substring(a+2,a+6)+"}",a+=6,n=!0;continue}}}i+="u",a+=2,n=!0;continue;case"x":{let f=!1;if(a+2<o&&t[a+2]==="{"){let m=a+3,B=!1,h=!1;while(m<o){let g=t[m];if(g==="}"){h=!0;break}if(!e.isHexadecimal(g))break;B=!0,m++}if(h&&B)f=!0}else if(a+3<o&&e.isHexadecimal(t[a+2])&&e.isHexadecimal(t[a+3]))f=!0;if(f)i+="\\x",a+=2;else i+="x",a+=2,n=!0;continue}case"n":case"r":case"t":case"a":case"f":case"v":case"d":case"D":case"s":case"S":case"w":case"W":case"b":case"B":case"p":case"P":case"A":case"z":case"Q":case"E":case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":i+="\\"+u,a+=2;continue;default:{let f=t.codePointAt(a+1);if(f>=48&&f<=57||f>=65&&f<=90||f>=97&&f<=122){let m=ce.charCount(f);i+=t.substring(a+1,a+1+m),a+=m+1,n=!0}else{i+="\\";let m=ce.charCount(f);i+=t.substring(a+1,a+1+m),a+=m+1}continue}}}else if(u==="/"){i+="\\/",a+=1,n=!0;continue}else if(u==="[")s=!0;else if(u==="]")s=!1;else if(!s&&u==="("&&a+2<o&&t[a+1]==="?"&&t[a+2]==="<"){if(a+3<o&&!"=!>)".includes(t[a+3])){i+="(?P<",a+=3,n=!0;continue}}let l=t.codePointAt(a),d=ce.charCount(l);i+=t.substring(a,a+d),a+=d}let c=n?i:t;if(r.length>0)return`(?${r})${c}`;return c}},Ff=class e{static CASE_INSENSITIVE=mn.CASE_INSENSITIVE;static DOTALL=mn.DOTALL;static MULTILINE=mn.MULTILINE;static DISABLE_UNICODE_GROUPS=mn.DISABLE_UNICODE_GROUPS;static LONGEST_MATCH=mn.LONGEST_MATCH;static LOOKBEHINDS=mn.LOOKBEHINDS;static quote(t){return ce.quoteMeta(t)}static quoteReplacement(t,r=!1){return eS.quoteReplacement(t,r)}static translateRegExp(t){return k4.translate(t)}static compile(t,r=0){let i=t;if((r&e.CASE_INSENSITIVE)!==0)i=`(?i)${i}`;if((r&e.DOTALL)!==0)i=`(?s)${i}`;if((r&e.MULTILINE)!==0)i=`(?m)${i}`;if((r&~(e.MULTILINE|e.DOTALL|e.CASE_INSENSITIVE|e.DISABLE_UNICODE_GROUPS|e.LONGEST_MATCH|e.LOOKBEHINDS))!==0)throw new p4("Flags should only be a combination of MULTILINE, DOTALL, CASE_INSENSITIVE, DISABLE_UNICODE_GROUPS, LONGEST_MATCH, LOOKBEHINDS");let n=j.PERL;if((r&e.DISABLE_UNICODE_GROUPS)!==0)n&=~j.UNICODE_GROUPS;if((r&e.LOOKBEHINDS)!==0)n|=j.LOOKBEHIND;let o=new e(t,r);return o.re2Input=_4.compileImpl(i,n,(r&e.LONGEST_MATCH)!==0),o}static matches(t,r){return e.compile(t).testExact(r)}static initTest(t,r,i){if(t==null)throw Error("pattern is null");if(i==null)throw Error("re2 is null");let n=new e(t,r);return n.re2Input=i,n}constructor(t,r){this.patternInput=t,this.flagsInput=r,this.re2Input=null}reset(){this.re2Input.reset()}flags(){return this.flagsInput}pattern(){return this.patternInput}re2(){return this.re2Input}matches(t){return this.testExact(t)}matcher(t){if(ce.isByteArray(t))t=So.utf8(t);return new eS(this,t)}test(t){if(ce.isByteArray(t))return this.re2Input.matchUTF8(t);return this.re2Input.match(t)}testExact(t){let r=ce.isByteArray(t)?nt.fromUTF8(t):nt.fromUTF16(t);return this.re2Input.executeEngine(r,0,j.ANCHOR_BOTH,0)!==null}exec(t){let r=this.matcher(t);if(!r.find())return null;let i=[r.group(0)];for(let o=1;o<=r.groupCount();o++){let s=r.group(o);i.push(s===null?void 0:s)}i.index=r.start(0),i.input=t;let n=this.namedGroups();if(Object.keys(n).length>0){let o=r.getNamedGroups();for(let s in o)if(o[s]===null)o[s]=void 0;i.groups=o}else i.groups=void 0;return i}split(t,r=0){let i=this.matcher(t),n=[],o=0,s=0;while(i.find()){if(s===0&&i.end()===0){s=i.end();continue}if(r>0&&n.length===r-1)break;if(s===i.start()){if(r===0){o+=1,s=i.end();continue}}else while(o>0)n.push(""),o-=1;n.push(i.substring(s,i.start())),s=i.end()}if(r===0&&s!==i.inputLength()){while(o>0)n.push(""),o-=1;n.push(i.substring(s,i.inputLength()))}if(r!==0||n.length===0&&!(s===i.inputLength()&&s>0))n.push(i.substring(s,i.inputLength()));return n}*matchAll(t){let r=this.matcher(t);while(r.find()){let i=[r.group(0)];for(let o=1;o<=r.groupCount();o++){let s=r.group(o);i.push(s===null?void 0:s)}i.index=r.start(0),i.input=t;let n=this.namedGroups();if(Object.keys(n).length>0){let o=r.getNamedGroups();for(let s in o)if(o[s]===null)o[s]=void 0;i.groups=o}else i.groups=void 0;yield i}}toString(){return this.patternInput}programSize(){return this.re2Input.numberOfInstructions()}groupCount(){return this.re2Input.numberOfCapturingGroups()}namedGroups(){return this.re2Input.namedGroups}equals(t){if(this===t)return!0;if(t===null||this.constructor!==t.constructor)return!1;return this.flagsInput===t.flagsInput&&this.patternInput===t.patternInput}};function Gf(e){let t="",r=!1,i=!1;for(let n of Array.from(e)){if(r){t+=n,r=!1;continue}if(n==="\\"){t+=n,r=!0;continue}if(n==="["){i=!0,t+=n;continue}if(n==="]"){i=!1,t+=n;continue}if(!i&&n==="."){t+="[^\\n\\r]";continue}if(!i&&(n==="^"||n==="$")){t+=`\\${n}`;continue}t+=n}return t}var mX=Object.assign((e,t)=>Ff.compile(e),{code:'((pattern) => require("re2js").RE2JS.compile(pattern))'});function RS(e){try{return Ff.compile(e),!0}catch{return!1}}function Hf(e){return Ff.compile(Gf(e))}var S4=/^(?:L[lmotu]?|M[cen]?|N[dlo]?|P[cdfios]?|Z[lps]?|S[ckmo]?|C[cfno]?)$/u,A4=4096,$4=32,_v=1000;function Ui(e){if(!N4(e)||e==="[^]")return!1;let t=Array.from(e);if(t.length>A4)return!1;if(!new jS(t).parse())return!1;return RS(Gf(e))}class jS{chars;index=0;constructor(e){this.chars=e}parse(){return this.parseExpression(void 0,0)&&this.index===this.chars.length}parseExpression(e,t){if(t>$4||!this.parseBranch(e,t))return!1;while(this.peek()==="|")if(this.index++,!this.parseBranch(e,t))return!1;return!0}parseBranch(e,t){while(this.index<this.chars.length){let r=this.peek();if(r==="|"||r===e)return!0;if(!this.parsePiece(t))return!1}return e===void 0}parsePiece(e){if(!this.parseAtom(e))return!1;let t=this.peek();if(t==="*"||t==="+"||t==="?")return this.index++,!0;if(t==="{")return this.parseRangeQuantifier();return!0}parseAtom(e){let t=this.peek();if(t===void 0)return!1;if(t==="("){if(this.index++,!this.parseExpression(")",e+1)||this.peek()!==")")return!1;return this.index++,!0}if(t===".")return this.index++,!0;if(t==="[")return this.parseCharacterClass();if(t==="\\")return this.parseEscape(!0);if(!T4(t))return!1;return this.index++,!0}parseRangeQuantifier(){this.index++;let e=this.consumeInteger();if(e===void 0||e>_v)return!1;let t=e;if(this.peek()===",")this.index++,t=this.consumeInteger()??_v;if(t>_v||t<e||this.peek()!=="}")return!1;return this.index++,!0}parseCharacterClass(){let e=this.index;if(this.index++,this.peek()==="^")this.index++;if(this.peek()===void 0||this.peek()==="]")return!1;if(this.peek()==="-")this.index++;else if(!this.parseCharacterClassEntry())return!1;while(this.peek()!=="]"){if(this.peek()===void 0)return!1;if(this.peek()==="-"&&this.peek(1)==="]"){this.index++;break}if(!this.parseCharacterClassEntry())return!1}if(this.peek()!=="]")return!1;return this.index++,this.chars.slice(e,this.index).join("")!=="[^]"}parseCharacterClassEntry(){if(this.peek()==="\\"&&(this.peek(1)==="p"||this.peek(1)==="P"))return this.parseCategoryEscape();if(!this.parseClassCharacter())return!1;if(this.peek()==="-"&&this.peek(1)!=="]"){if(this.index++,!this.parseClassCharacter())return!1}return!0}parseClassCharacter(){let e=this.peek();if(e==="\\")return this.parseEscape(!1);if(e===void 0||e==="-"||e==="["||e==="]"||e==="\\")return!1;return this.index++,!0}parseEscape(e){if(e&&(this.peek(1)==="p"||this.peek(1)==="P"))return this.parseCategoryEscape();if(this.peek()!=="\\")return!1;let t=this.peek(1);if(t===void 0||!"()*+-.?[\\]^nrt{}".includes(t))return!1;return this.index+=2,!0}parseCategoryEscape(){if(this.peek()!=="\\"||this.peek(1)!=="p"&&this.peek(1)!=="P"||this.peek(2)!=="{")return!1;this.index+=3;let e="";while(this.peek()!=="}"&&this.peek()!==void 0)e+=this.peek(),this.index++;if(this.peek()!=="}"||!S4.test(e))return!1;return this.index++,!0}consumeInteger(){let e=this.index;while(/^[0-9]$/u.test(this.peek()??""))this.index++;if(this.index===e)return;let t=Number(this.chars.slice(e,this.index).join(""));return Number.isSafeInteger(t)?t:void 0}peek(e=0){return this.chars[this.index+e]}}function T4(e){let t=e.codePointAt(0);if(t===void 0)return!1;return t>=0&&t<=39||t===44||t===45||t>=47&&t<=62||t>=64&&t<=90||t>=94&&t<=122||t>=126&&t<=55295||t>=57344&&t<=1114111}function N4(e){for(let t=0;t<e.length;t++){let r=e.charCodeAt(t);if(r<55296||r>57343)continue;if(r>56319||t+1>=e.length)return!1;let i=e.charCodeAt(++t);if(i<56320||i>57343)return!1}return!0}var PS=new WeakMap;function en(e){if(!Ui(e))ie("BUILDER_FULL_MATCH_INVALID","/fullMatch","fullMatch(...) requires a complete RFC 9485 I-Regexp source.");let t=Hf(e),r=p.refine((i)=>t.matches(i),{error:`String must fully match I-Regexp ${JSON.stringify(e)}.`});return PS.set(r,e),r}function kv(e){return e!==null&&typeof e==="object"?PS.get(e):void 0}var R4=new WeakMap;function LS(e){return R4.get(e)}var MS=Object.freeze({allOf:(...e)=>zS("allOf",e),anyOf:(...e)=>zS("anyOf",e)});function US(e){let t=0,r=Object.freeze({kind:"subject"}),i=Object.freeze({kind:"object"}),n=Object.freeze({kind:"source"}),o=Object.freeze({kind:"target"});return Object.freeze({subject:r,object:i,source:n,target:o,edge(a){if(Ve(a,["source","class","target","repeat"]),a.repeat!==void 0)Ve(a.repeat,["min","max"]);return{source:a.source,class:e.resolveEdgeClass(a.class,`${e.pointer}/match/class`),target:a.target,...a.repeat===void 0?{}:{repeat:{...a.repeat}}}},exists(a){let c=[],u=a({node(l){let d=Object.freeze({kind:"variable",id:t++});return c.push({variable:d,class:e.resolveNodeClass(l,`${e.pointer}/match/exists/nodes`)}),d}});if(c.length===0)ie("BUILDER_POLICY_EMPTY_EXISTS",`${e.pointer}/match/exists/nodes`,"exists(...) must declare at least one variable Node.");return{exists:{nodes:c,where:u}}},allOf(...a){return Sv(a,`${e.pointer}/match/allOf`),{allOf:a}},anyOf(...a){return Sv(a,`${e.pointer}/match/anyOf`),{anyOf:a}}})}function zS(e,t){return Sv(t,`/${e}`),Vt("policy-composition",{operator:e,policies:[...t]})}function Sv(e,t){if(e.length===0)ie("BUILDER_POLICY_EMPTY_COMPOSITION",t,"Policy composition must be non-empty.")}function qe(e,t){let r=t??{};return Ve(r,["visibility","required"]),Vt("property",{schema:e,visibility:r.visibility??"public",...r.required===void 0?{}:{required:r.required}})}function ou(e,t){if(nr(e,"auto"))ie("BUILDER_AUTO_NESTED","","auto(...) cannot wrap another automatic Property.");Ve(t,["on","set"]);let r=Array.isArray(t.on)?t.on:[t.on];if(r.length===0)ie("BUILDER_AUTO_EVENT_INVALID","/on","auto(...) requires an event.");let i=[...new Set(r)];if(i.some((n)=>n!=="create"&&n!=="update"))ie("BUILDER_AUTO_EVENT_INVALID","/on","Automatic events are create or update.");if(t.set!=="instant")ie("BUILDER_AUTO_SET_INVALID","/set","The automatic setter must be instant.");if(i.sort((n,o)=>n===o?0:n==="create"?-1:1),e.required===!0&&!i.includes("create"))ie("BUILDER_AUTO_EVENT_INVALID","/on","A required automatic Property must run on create.");return Vt("auto",{property:e,options:{on:Object.freeze(i),set:t.set}})}var kr=/^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/u,Sr=/^[A-Za-z][A-Za-z0-9_]*$/u,Fi=/^[a-z][a-z0-9-]{0,99}$/u,ii=/^sha256:[0-9a-f]{64}$/u;var FS=new RegExp("^(?:([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?:(class|interface)\\.[A-Za-z][A-Za-z0-9_]*\\.property\\.[A-Za-z][A-Za-z0-9_]*)$","u"),Av=Object.freeze({coreSlug:Fi,memberName:Sr,origin:kr,propertyKey:FS,propertyKeyFullMatch:"([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?:(class|interface)\\.[A-Za-z][A-Za-z0-9_]*\\.property\\.[A-Za-z][A-Za-z0-9_]*",revision:ii});function Vf(e){if(!Sr.test(e))throw TypeError(`Invalid member name: ${JSON.stringify(e)}.`)}var j4=/^(class|interface|function|policy|view|type)\.([A-Za-z][A-Za-z0-9_]*)$/u,$v=/^(class|interface)\.([A-Za-z][A-Za-z0-9_]*)\.(property|method)\.([A-Za-z][A-Za-z0-9_]*)$/u;function ne(e){if(!HS(e))throw TypeError(`Invalid Ref: ${JSON.stringify(e)}.`);return e}(function(e){function t(B,h){return Vf(h),`${B}.${h}`}e.definition=t;function r(B){if(!Fi.test(B))throw TypeError(`Invalid Core member name: ${JSON.stringify(B)}.`);return`core.${B}`}e.core=r;function i(B,h){return GS(B,"Property"),Vf(h),`${B}.property.${h}`}e.property=i;function n(B,h){return GS(B,"Method"),Vf(h),`${B}.method.${h}`}e.method=n;function o(B){return B.kind==="core"?e.core(B.name):e.definition(B.kind,B.name)}e.fromSchema=o;function s(B){return e(B).slice(0,B.indexOf("."))}e.namespace=s;function a(B){return e(B).split(".")[1]}e.member=a;function c(B){return e(B).split(".")[2]}e.discriminator=c;function u(B){return e(B).split(".")[3]}e.child=u;function l(B){return HS(B)}e.is=l;function d(B){return typeof B==="string"&&Tv(B)}e.isDefinition=d;function f(B){return typeof B==="string"&&$v.exec(B)?.[3]==="property"}e.isProperty=f;function m(B){return typeof B==="string"&&$v.exec(B)?.[3]==="method"}e.isMethod=m})(ne||(ne={}));function Tv(e){return j4.test(e)}function HS(e){if(typeof e!=="string")return!1;if(Tv(e))return!0;if(e.startsWith("core."))return Fi.test(e.slice(5));return $v.exec(e)!==null}function GS(e,t){if(!e.startsWith("class.")&&!e.startsWith("interface.")||!Tv(e))P4(e,t)}function P4(e,t){throw TypeError(`${t} owner must be a Class or Interface Ref; received ${JSON.stringify(e)}.`)}var VS=(e)=>{let t=e.indexOf(":");if(t<0||!kr.test(e.slice(0,t))||!ne.is(e.slice(t+1)))throw TypeError(`Invalid Key: ${JSON.stringify(e)}.`);return e};function Z(e){return VS(e)}(function(e){function t(s,a){if(!kr.test(s))throw TypeError(`Invalid Domain origin: ${JSON.stringify(s)}.`);return`${s}:${ne(a)}`}e.of=t;function r(s){return e.of(s.origin,ne.fromSchema(s))}e.fromSchema=r;function i(s){return e(s).slice(0,s.indexOf(":"))}e.origin=i;function n(s){return e(s).slice(s.indexOf(":")+1)}e.ref=n;function o(s){if(typeof s!=="string")return!1;try{return VS(s),!0}catch{return!1}}e.is=o})(Z||(Z={}));function Pe(e){if(!Pe.is(e))throw TypeError(`Invalid canonical PropertyKey: ${JSON.stringify(e)}.`);return e}(function(e){function t(...i){let n;if(i.length===3){let[o,s,a]=i;n=Z.of(o,ne.property(s,a))}else{let[o,s]=i,a=ne.fromSchema(o);n=Z.of(o.origin,ne.property(a,s))}return n}e.of=t;function r(i){return Z.is(i)&&ne.isProperty(Z.ref(i))}e.is=r})(Pe||(Pe={}));var ca="astrale.dsl",ua="v1";function Q(e){return`${e.origin}\x00${e.kind}\x00${e.name}`}function Ue(e,t){return lt(e.origin,t.origin)||lt(e.kind,t.kind)||lt(e.name,t.name)}function lt(e,t){let r=Array.from(e,(o)=>o.codePointAt(0)??0),i=Array.from(t,(o)=>o.codePointAt(0)??0),n=Math.min(r.length,i.length);for(let o=0;o<n;o++)if(r[o]!==i[o])return(r[o]??0)-(i[o]??0);return r.length-i.length}function Bn(e,t){return`urn:astrale:dsl:v1:${encodeURIComponent(e)}:type:${encodeURIComponent(t)}`}function Be(e){return`${e.origin}:${e.kind}.${e.name}`}var qS=new TextEncoder;function To(e){if("match"in e)return Nv(e,{match:Pv(e.match)});if("allOf"in e)return Nv(e,{allOf:ZS(e.allOf)});return Nv(e,{anyOf:ZS(e.anyOf)})}function Pv(e){let t=Kf(e,L4(e));return qf(t)}function Nn(e){if("check"in e)return e;if("allOf"in e){let r=e.allOf.flatMap((i)=>{let n=Nn(i);return"allOf"in n?n.allOf:[n]});return{allOf:JS(Yf(r))}}let t=e.anyOf.flatMap((r)=>{let i=Nn(r);return"anyOf"in i?i.anyOf:[i]});return{anyOf:JS(Yf(t))}}function JS(e){return e}function qf(e){if(su(e)){let r=e.repeat;if(r?.min===1&&r.max===1){let{repeat:i,...n}=e;return n}return e}if("exists"in e)return{exists:{nodes:[...e.exists.nodes].sort((r,i)=>r.variable.id-i.variable.id),where:qf(e.exists.where)}};if("allOf"in e){let r=e.allOf.flatMap((i)=>{let n=qf(i);return"allOf"in n?n.allOf:[n]});return{allOf:Yf(r)}}let t=e.anyOf.flatMap((r)=>{let i=qf(r);return"anyOf"in i?i.anyOf:[i]});return{anyOf:Yf(t)}}function L4(e){let t=new Map;Jf(e,t);let r=new Map(t);for(let o=0;o<t.size+1;o++){let s=new Map;for(let a of t.keys()){let c=[];Rv(e,a,r,c),c.sort($o),s.set(a,`${t.get(a)??""}|${c.join("|")}`)}if([...s].every(([a,c])=>r.get(a)===c))break;r.clear();for(let[a,c]of s)r.set(a,c)}let i=new Map;jv(e,r,i);let n=[...t.keys()].sort((o,s)=>{let a=$o(r.get(o)??"",r.get(s)??"");if(a!==0)return a;let c=$o(i.get(o)??"",i.get(s)??"");if(c!==0)return c;return o-s});return new Map(n.map((o,s)=>[o,s]))}function Jf(e,t){if("exists"in e){for(let r of e.exists.nodes)t.set(r.variable.id,Q(r.class));Jf(e.exists.where,t);return}if("allOf"in e)for(let r of e.allOf)Jf(r,t);if("anyOf"in e)for(let r of e.anyOf)Jf(r,t)}function Rv(e,t,r,i){if(su(e)){if(e.source.kind==="variable"&&e.source.id===t)i.push(`s:${Q(e.class)}:${Zf(e.target,r)}`);if(e.target.kind==="variable"&&e.target.id===t)i.push(`t:${Q(e.class)}:${Zf(e.source,r)}`);return}if("exists"in e)return Rv(e.exists.where,t,r,i);let n="allOf"in e?e.allOf:e.anyOf;for(let o of n)Rv(o,t,r,i)}function Zf(e,t){if(e.kind==="variable")return`variable:${t.get(e.id)??"?"}`;return e.kind}function jv(e,t,r,i="$"){if(su(e)){for(let[a,c]of[["source",e.source],["target",e.target]])if(c.kind==="variable"){let u=`${i}:${Q(e.class)}:${a}`,l=r.get(c.id);if(l===void 0||u<l)r.set(c.id,u)}return}if("exists"in e){jv(e.exists.where,t,r,`${i}:exists`);return}let n="allOf"in e?"allOf":"anyOf";[..."allOf"in e?e.allOf:e.anyOf].sort((a,c)=>$o(Wf(a,t),Wf(c,t))).forEach((a,c)=>jv(a,t,r,`${i}:${n}:${c}`))}function Wf(e,t){if(su(e))return`edge:${Q(e.class)}:${Zf(e.source,t)}:${Zf(e.target,t)}:${e.repeat?.min??1}:${e.repeat?.max??1}`;if("exists"in e)return`exists:${e.exists.nodes.map((n)=>t.get(n.variable.id)??"").sort($o).join(",")}:${Wf(e.exists.where,t)}`;let r="allOf"in e?"allOf":"anyOf",i="allOf"in e?e.allOf:e.anyOf;return`${r}:${i.map((n)=>Wf(n,t)).sort($o).join("|")}`}function Kf(e,t){if(su(e))return{...e,source:KS(e.source,t),target:KS(e.target,t)};if("exists"in e)return{exists:{nodes:e.exists.nodes.map((r)=>({variable:{kind:"variable",id:t.get(r.variable.id)??r.variable.id},class:r.class})),where:Kf(e.exists.where,t)}};if("allOf"in e)return{allOf:e.allOf.map((r)=>Kf(r,t))};return{anyOf:e.anyOf.map((r)=>Kf(r,t))}}function KS(e,t){return e.kind==="variable"?{kind:"variable",id:t.get(e.id)??e.id}:e}function ZS(e){return[...new Map(e.map((r)=>[Q(r),r])).values()].sort(Ue)}function Yf(e){return[...new Map(e.map((r)=>[te.serialize(r),r])).entries()].sort(([r],[i])=>$o(r,i)).map(([,r])=>r)}function $o(e,t){let r=qS.encode(e),i=qS.encode(t),n=Math.min(r.length,i.length);for(let o=0;o<n;o++)if(r[o]!==i[o])return(r[o]??0)-(i[o]??0);return r.length-i.length}function Nv(e,t){return e.description===void 0?t:{description:e.description,...t}}function su(e){return"source"in e}var Gi=new Set(["allOf","anyOf","oneOf","prefixItems"]),Hi=new Set(["$defs","dependentSchemas","patternProperties","properties"]),Vi=new Set(["additionalProperties","contains","contentSchema","else","if","items","not","propertyNames","then","unevaluatedItems","unevaluatedProperties"]);function ye(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}var z4=["null","boolean","integer","number","string","array","object"],WS=new Map(z4.map((e,t)=>[e,t])),YS=new TextEncoder;function Kt(e,t,r){return Qf(e,!0,t)}function Qf(e,t,r){if(typeof e==="boolean")return e;let i={};for(let n of Object.keys(e).sort()){if(t&&n==="$schema")continue;if(t&&r==="named-type"&&n==="$id")continue;let o=e[n];if(n==="required"&&Array.isArray(o))au(o,String,"required"),i[n]=[...o].sort((s,a)=>lt(String(s),String(a)));else if(n==="type"&&Array.isArray(o))au(o,String,"type"),i[n]=[...o].sort((s,a)=>(WS.get(String(s))??Number.MAX_SAFE_INTEGER)-(WS.get(String(a))??Number.MAX_SAFE_INTEGER));else if(n==="enum"&&Array.isArray(o)){let s=o.map(oi);au(s,te.serialize,"enum"),i[n]=s.sort(F4)}else if(n==="dependentRequired"&&ye(o))i[n]=M4(o);else if(n==="x-astrale-path"&&ye(o))i[n]=U4(o);else if(Vi.has(n)&&Lv(o))i[n]=Qf(o,!1,r);else if(Gi.has(n)&&Array.isArray(o))i[n]=o.map((s)=>Lv(s)?Qf(s,!1,r):oi(s));else if(Hi.has(n)&&ye(o)){let s={};for(let a of Object.keys(o).sort()){let c=o[a];s[a]=Lv(c)?Qf(c,!1,r):oi(c)}i[n]=s}else i[n]=oi(o)}return i}function M4(e){let t={};for(let r of Object.keys(e).sort()){let i=e[r];if(!Array.isArray(i)){t[r]=oi(i);continue}au(i,String,`dependentRequired.${r}`),t[r]=[...i].sort((n,o)=>lt(String(n),String(o)))}return t}function U4(e){let t={};for(let r of Object.keys(e).sort()){let i=e[r];if(r==="accepts"&&Array.isArray(i)){let n=i.map(oi);au(n,te.serialize,"x-astrale-path.accepts"),t[r]=n.sort((o,s)=>Ue(o,s))}else t[r]=oi(i)}return t}function oi(e){if(e===null||typeof e==="boolean"||typeof e==="string")return e;if(typeof e==="number"){if(!Number.isFinite(e))throw TypeError("Cannot canonicalize a non-finite number.");if(Object.is(e,-0))throw TypeError("Cannot canonicalize negative zero.");return e}if(Array.isArray(e))return e.map(oi);if(!ye(e))throw TypeError("Cannot canonicalize a non-JSON value.");let t={};for(let r of Object.keys(e).sort())t[r]=oi(e[r]);return t}function F4(e,t){let r=YS.encode(te.serialize(e)),i=YS.encode(te.serialize(t)),n=Math.min(r.length,i.length);for(let o=0;o<n;o++)if(r[o]!==i[o])return(r[o]??0)-(i[o]??0);return r.length-i.length}function au(e,t,r){let i=new Set;for(let n of e){let o=t(n);if(i.has(o))throw TypeError(`${r} contains a duplicate value.`);i.add(o)}}function Lv(e){return typeof e==="boolean"||ye(e)}function Xf(e){let t=si(e.classes,V4),r=new Map(Object.entries(t).filter((n)=>n[1].family==="edge").map(([n,o])=>[n,o.orientation])),i={format:"astrale.dsl",version:"v1",origin:e.origin,dependencies:[...e.dependencies].sort((n,o)=>lt(n.origin,o.origin)),types:si(e.types,(n)=>Kt(n,"named-type")),interfaces:si(e.interfaces,H4),classes:t,functions:si(e.functions,QS),policies:si(e.policies,To),views:si(e.views,G4),core:{nodes:si(e.core.nodes,(n)=>({class:n.class,properties:cu(n.properties)})),edges:e.core.edges.map((n)=>J4(n,e.origin,r)).sort(K4)}};return cu(i)}function G4(e){return{...ep(e),target:e.target.kind==="domain"?{kind:"domain"}:{kind:"definition",definitions:[...e.target.definitions].sort(Ue)},auth:e.auth}}function H4(e){let t={...ep(e),family:e.family,extends:[...e.extends].sort(Ue),properties:eA(e.properties),propertyMetadata:tA(e.propertyMetadata)};if(e.family==="both")return t;if(e.family==="node")return{...t,methods:si(e.methods,XS),...e.data===void 0?{}:{data:{mediaType:e.data.mediaType}}};return e.orientation==="directed"?{...t,orientation:"directed",endpoints:rA(e.endpoints),constraints:e.constraints}:{...t,orientation:"undirected",endpoints:nA(e.endpoints),constraints:e.constraints}}function V4(e){let t={...ep(e),family:e.family,implements:[...e.implements].sort(Ue),properties:eA(e.properties),propertyMetadata:tA(e.propertyMetadata)};if(e.family==="node")return{...t,methods:si(e.methods,XS),...e.data===void 0?{}:{data:{mediaType:e.data.mediaType}},...e.icon===void 0?{}:{icon:e.icon},policies:e.policies};return e.orientation==="directed"?{...t,orientation:"directed",endpoints:rA(e.endpoints),policies:e.policies,constraints:e.constraints}:{...t,orientation:"undirected",endpoints:nA(e.endpoints),policies:e.policies,constraints:e.constraints}}function QS(e){return{...ep(e),input:Kt(e.input,"callable-input"),output:q4(e.output),auth:e.auth,...e.policy===void 0?{}:{policy:Nn(e.policy)}}}function XS(e){return{...QS(e),static:e.static,inheritance:e.inheritance}}function q4(e){switch(e.mode){case"value":return{mode:"value",schema:Kt(e.schema,"callable-output")};case"stream":return{mode:"stream",item:Kt(e.item,"callable-output")};case"binary":return{mode:"binary"}}}function eA(e){return Kt(e,"property-facet")}function tA(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t.visibility==="private"||t.auto!==void 0).map(([t,r])=>[t,r.auto===void 0?{visibility:r.visibility}:{visibility:r.visibility,auto:{on:[...new Set(r.auto.on)].sort(lt),set:r.auto.set}}]).sort(([t],[r])=>lt(t,r)))}function rA(e){return{...e,source:{...e.source,accepts:[...e.source.accepts].sort(Ue)},target:{...e.target,accepts:[...e.target.accepts].sort(Ue)}}}function nA(e){return[{...e[0],accepts:[...e[0].accepts].sort(Ue)},{...e[1],accepts:[...e[1].accepts].sort(Ue)}]}function J4(e,t,r){let n=e.class.origin===t&&r.get(e.class.name)==="undirected",[o,s]=n&&zv(e.source,e.target)>0?[e.target,e.source]:[e.source,e.target];return{class:e.class,source:o,target:s,properties:cu(e.properties)}}function K4(e,t){return Ue(e.class,t.class)||zv(e.source,t.source)||zv(e.target,t.target)||Z4(te.serialize(e.properties),te.serialize(t.properties))}function zv(e,t){if(e.kind==="domain")return t.kind==="domain"?0:-1;if(t.kind==="domain")return 1;return Ue(e,t)}function Z4(e,t){let r=new TextEncoder,i=r.encode(e),n=r.encode(t),o=Math.min(i.length,n.length);for(let s=0;s<o;s++)if(i[s]!==n[s])return(i[s]??0)-(n[s]??0);return i.length-n.length}function si(e,t){return Object.fromEntries(Object.entries(e).sort(([r],[i])=>lt(r,i)).map(([r,i])=>[r,t(i,r)]))}function ep(e){return e.description===void 0?{}:{description:e.description}}function cu(e){if(typeof e==="number"){if(Object.is(e,-0))throw TypeError("Cannot canonicalize negative zero.");return e}if(e===null||typeof e!=="object")return e;if(Array.isArray(e))return e.map((t)=>cu(t));return Object.fromEntries(Object.entries(e).map(([t,r])=>[t,cu(r)]))}function No(e){if(e===null||typeof e!=="object"||Object.isFrozen(e))return e;for(let t of Object.values(e))No(t);return Object.freeze(e)}function tp(e){let t="";for(let r of Is(e))t+=r.toString(16).padStart(2,"0");return`sha256:${t}`}function iA(e){return No(e)}function W4(e){return uu(e)}function uu(e){let t=iA(Xf(e)),r=te.encode(t),i=tp(r);return Object.freeze({schema:t,bytes:r,revision:i})}function mt(e){return W4(e).revision}class Ro{#e=new Map;constructor(e=[]){for(let t of e)this.set(t)}get(e,t){return this.#e.get(oA(e,t))}set(e){let{revision:t,schema:r}=e,i=mt(r);if(t!==i)throw Error(`Schema lookup revision ${t} disagrees with ${r.origin}@${i}`);let n=oA(r.origin,t),o=this.#e.get(n);if(o!==void 0&&o!==r)throw Error(`Schema lookup entry ${r.origin}@${t} is already bound`);return this.#e.set(n,r),this}}function rp(){return{get:()=>{return}}}function oA(e,t){return`${e}\x00${t}`}function It(e,t){let r=String(t).replaceAll("~","~0").replaceAll("/","~1");return`${e}/${r}`}function lu(e){if(!e.startsWith("#"))return;let t;try{t=decodeURIComponent(e.slice(1))}catch{return}if(t==="")return[];if(!t.startsWith("/"))return;let r=[];for(let i of t.slice(1).split("/")){if(/~(?:[^01]|$)/u.test(i))return;r.push(i.replaceAll("~1","/").replaceAll("~0","~"))}return r}function sA(e){return e.reduce((t,r)=>It(t,r),"")}function aA(e,t){let r=e;for(let i of t){if(Array.isArray(r)){if(!/^(?:0|[1-9][0-9]*)$/u.test(i))return;let n=Number(i);if(!Number.isSafeInteger(n)||n>=r.length||!(n in r))return;r=r[n];continue}if(!ye(r)||!Object.hasOwn(r,i))return;r=r[i]}return r}function Pr(e,t,r=""){let i=new Set;function n(o,s,a,c){if(typeof o==="object"&&o!==null){if(i.has(o))return;i.add(o)}try{if(t({schema:o,pointer:s,depth:a,parentKeyword:c}),!ye(o))return;for(let[u,l]of Object.entries(o)){let d=It(s,u);if(Vi.has(u)&&jo(l)){n(l,d,a+1,u);continue}if(Gi.has(u)&&Array.isArray(l)){l.forEach((f,m)=>{if(jo(f))n(f,It(d,m),a+1,u)});continue}if(Hi.has(u)&&ye(l)){for(let[f,m]of Object.entries(l))if(jo(m))n(m,It(d,f),a+1,u)}}}finally{if(typeof o==="object"&&o!==null)i.delete(o)}}n(e,r,0)}function cA(e){let t=new Set;return Pr(e,({pointer:r})=>t.add(r)),t}function jo(e){return typeof e==="boolean"||ye(e)}var np="https://json-schema.org/draft/2020-12/schema",Po="https://schemas.astrale.ai/dsl/v1/value-schema",uA="https://schemas.astrale.ai/dsl/v1/value-schema/vocabulary";var jt="https://schemas.astrale.ai/graph/1/node-path",ip=Object.freeze({$schema:np,$id:jt,title:"Astrale graph NodePath",description:"Canonical serialized exact-one locator for one logical graph Node. Full admission requires the astrale-node-path-v1 graph codec; JSON Schema format remains an annotation.",type:"string",minLength:1,format:"astrale-node-path-v1"});function lA(e){return ye(e)&&e.$ref===jt&&Object.hasOwn(e,"x-astrale-path")}function op(e,t){let r=[],i=new Map;i.set(e.current.origin,e.current),dA(e.current,`${t}/registry/current`,!1,r),[...e.directDependencies.map((s)=>({domain:s,lane:"directDependencies"})),...e.transitiveDependencies.map((s)=>({domain:s,lane:"transitiveDependencies"}))].forEach(({domain:s,lane:a},c)=>{let u=`${t}/registry/${a}/${c}`;if(dA(s,u,!0,r),s.origin===e.current.origin||i.has(s.origin)){r.push(_("VS_REFERENCE_RESOLUTION",u,`Registry origin ${s.origin} is duplicated in the exact closure.`));return}i.set(s.origin,s)});let o=new Map;for(let s of i.values()){let a=new Map(s.dependencies.map((c)=>[c.origin,c.revision]));o.set(s.origin,a);for(let c of s.dependencies){let u=i.get(c.origin);if(u===void 0||u.revision!==c.revision)r.push(_("VS_REFERENCE_RESOLUTION",`${t}/registry/${s.origin}/dependencies`,`Registry closure is missing exact ${c.origin}@${c.revision} required by ${s.origin}.`))}}return Y4(e.graphNodePath,`${t}/registry/graphNodePath`,r),{index:{registry:e,domains:i,dependenciesByOwner:o},diagnostics:r}}function sp(e,t,r=""){let i=/(?:^|\/)types\/([^/]+)$/u.exec(r);if(i!==null){let s=(i[1]??"").replaceAll("~1","/").replaceAll("~0","~");if(t.registry.current.types[s]===e)return{origin:t.registry.current.origin,name:s}}let n=[];for(let o of t.domains.values())for(let[s,a]of Object.entries(o.types))if(a===e)n.push({origin:o.origin,name:s});if(n.length===1)return n[0];if(ye(e)&&typeof e.$id==="string"){for(let o of t.domains.values())for(let s of Object.keys(o.types))if(e.$id===Bn(o.origin,s))return{origin:o.origin,name:s}}return}function fA(e,t,r){return e.domains.get(t)?.types[r]}function Mv(e,t,r){return t===r||e.dependenciesByOwner.get(t)?.has(r)===!0}function pA(e,t,r){if(!Mv(e,r,t.origin))return!1;return e.domains.get(t.origin)?.nodeDefinitions.some((i)=>Q(i)===Q(t))===!0}function dA(e,t,r,i){if(!kr.test(e.origin))i.push(_("VS_REFERENCE_RESOLUTION",`${t}/origin`,"Registry origin is invalid."));if(r&&e.revision===void 0||e.revision!==void 0&&!ii.test(e.revision))i.push(_("VS_REFERENCE_RESOLUTION",`${t}/revision`,"A dependency-closure registry entry requires its exact sha256 revision."));for(let n of Object.keys(e.types))if(!Sr.test(n))i.push(_("VS_REFERENCE_RESOLUTION",`${t}/types`,`Named type ${n} does not satisfy the V1 member-name grammar.`));for(let n of e.nodeDefinitions)if(n.origin!==e.origin)i.push(_("VS_REFERENCE_RESOLUTION",`${t}/nodeDefinitions`,"A registry domain can list only its own Node Definitions."))}function Y4(e,t,r){if(!ye(e)||e.$schema!==np||e.$id!==jt||e.type!=="string"||e.minLength!==1||e.format!=="astrale-node-path-v1")r.push(_("VS_REFERENCE_RESOLUTION",t,`The graph NodePath artifact must be preloaded under exact id ${jt}.`,jt))}function BA(e,t,r,i,n){if(e===jt){if(!n)return{diagnostic:_("VS_REFERENCE_FORM",i,"The graph NodePath schema may be referenced only beside a valid x-astrale-path annotation.",e)};return{resolved:{resource:{key:jt,schema:r.registry.graphNodePath,ownerOrigin:t.ownerOrigin},pointer:""}}}if(e.startsWith("#")){let s=lu(e);if(s===void 0)return{diagnostic:_("VS_REFERENCE_FORM",i,"A local $ref must be a JSON Pointer fragment; anchors are forbidden.",e)};return mA(t,s,i,e)}let o=Uv(e);if(o!==void 0){if(r.domains.get(o.origin)===void 0||!Mv(r,t.ownerOrigin,o.origin))return{diagnostic:_("VS_REFERENCE_RESOLUTION",i,`Named type origin ${o.origin} is not ${t.ownerOrigin} or one of its exact direct dependencies.`,e)};let a=fA(r,o.origin,o.name);if(a===void 0)return{diagnostic:_("VS_REFERENCE_RESOLUTION",i,`Named type ${o.origin}:${o.name} is absent from the exact registry.`,e)};return mA({key:Bn(o.origin,o.name),schema:a,ownerOrigin:o.origin,origin:o.origin,name:o.name},o.pointer,i,e)}return{diagnostic:_("VS_REFERENCE_FORM",i,"A $ref must be a local JSON Pointer, an exact current/direct named-type URI, or the graph NodePath id.",e)}}function mA(e,t,r,i){let n=aA(e.schema,t),o=sA(t);if(n===void 0||!cA(e.schema).has(o))return{diagnostic:_("VS_REFERENCE_RESOLUTION",r,"The $ref does not resolve to an exact schema location in the registry.",i)};return{resolved:{resource:e,pointer:o}}}function Uv(e){let t=/^urn:astrale:dsl:v1:([^:]+):type:([^#]+)(#.*)?$/u.exec(e);if(t===null)return;let r,i;try{r=decodeURIComponent(t[1]??""),i=decodeURIComponent(t[2]??"")}catch{return}if(!kr.test(r)||!Sr.test(i))return;if(Bn(r,i)!==`urn:astrale:dsl:v1:${t[1]}:type:${t[2]}`)return;let n=lu(t[3]??"#");if(n===void 0)return;return{origin:r,name:i,pointer:n}}function ap(e,t,r,i,n){let o=[],s=new Map,a=new Map,c={key:n===void 0?`urn:astrale:dsl:v1:embedded:${t}`:Bn(n.origin,n.name),schema:e,ownerOrigin:n?.origin??r.registry.current.origin,...n===void 0?{}:n,diagnosticPointer:i};s.set(c.key,c);let u=[c];while(u.length>0){let l=u.shift();if(l===void 0)break;Pr(l.schema,(d)=>{if(!ye(d.schema)||!Object.hasOwn(d.schema,"$ref"))return;let f=`${l.diagnosticPointer??i}${d.pointer}/$ref`;if(typeof d.schema.$ref!=="string"){o.push(_("VS_REFERENCE_FORM",f,"$ref must be a string URI-reference."));return}let m=BA(d.schema.$ref,l,r,f,lA(d.schema));if(m.diagnostic!==void 0)o.push(m.diagnostic);if(m.resolved===void 0)return;a.set(yr(l.key,d.pointer),m.resolved);let B=m.resolved.resource;if(s.has(B.key))return;let h=B.key===jt?`${i}/registry/graphNodePath`:`${i}/registry/${hA(B.origin??"")}/types/${hA(B.name??"")}`,g={...B,diagnosticPointer:h};s.set(B.key,g),u.push(g)})}return{resources:s,resolutions:a,diagnostics:o}}function yr(e,t){return`${e}\x00${t}`}function hA(e){return e.replaceAll("~","~0").replaceAll("/","~1")}function cp(e,t,r){let i=op(t,r);if(i.diagnostics.length>0)return gA(i.diagnostics);let n=sp(e,i.index,r),o=ap(e,n===void 0?"callable-input":"named-type",i.index,r,n);if(o.diagnostics.length>0)return gA(o.diagnostics);let s=new Map,a=new Map;for(let l of o.resources.values())Pr(l.schema,(d)=>{let f=yr(l.key,d.pointer);if(s.set(f,{key:f,pointer:d.pointer,resource:l,schema:d.schema}),!ye(d.schema))return;if(Fv(a,d.schema.pattern),Fv(a,d.schema.fullMatch),ye(d.schema.patternProperties))for(let m of Object.keys(d.schema.patternProperties))Fv(a,m)});let c=o.resources.values().next().value,u=c===void 0?void 0:s.get(yr(c.key,""));if(u===void 0)return{compiled:!1,message:"The root value schema is absent from its closure."};return{compiled:!0,value:{root:u,locations:s,resolutions:o.resolutions,matcher(l){let d=a.get(l);if(d===void 0)throw TypeError("Value schema uses an unprepared I-Regexp source.");return d}}}}function Fv(e,t){if(typeof t==="string"&&!e.has(t))e.set(t,Hf(t))}function gA(e){return{compiled:!1,message:e.map(({code:t,message:r})=>`${t}: ${r}`).join("; ")}}var yA=Object.freeze({type:"string","x-astrale-value-kind":"instant"}),Q4=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.(\d{3})Z$/u;function CA(e){if(typeof e!=="string")return!1;let t=Q4.exec(e);if(t===null)return!1;let r=Number(t[1]),i=Number(t[2]),n=Number(t[3]),o=Number(t[4]),s=Number(t[5]),a=Number(t[6]);return i>=1&&i<=12&&n>=1&&n<=X4(r,i)&&o<=23&&s<=59&&a<=59}function X4(e,t){if(t===2)return e2(e)?29:28;return t===4||t===6||t===9||t===11?30:31}function e2(e){return e%4===0&&(e%100!==0||e%400===0)}function Gv(e,t){switch(e){case"null":return t===null;case"boolean":case"number":case"string":return typeof t===e;case"integer":return typeof t==="number"&&Number.isInteger(t);case"array":return Array.isArray(t);case"object":return ye(t);default:return!1}}function Hv(e,t){return Nr(e,t)}function vA(e){let t=new Set;for(let r of e){let i=te.serialize(r);if(t.has(i))return!1;t.add(i)}return!0}function xA(e,t){if(!(t>0))return!1;let r=bA(e),i=bA(t),n=Math.min(r.exponent,i.exponent),o=r.coefficient*EA(r.exponent-n),s=i.coefficient*EA(i.exponent-n);return o%s===0n}function bA(e){let t=e.toString().toLowerCase(),[r="",i="0"]=t.split("e"),n=r.startsWith("-"),o=n?r.slice(1):r,s=o.indexOf("."),a=s===-1?0:o.length-s-1,c=o.replace(".","");return{coefficient:BigInt(`${n?"-":""}${c}`),exponent:Number(i)-a}}function EA(e){return 10n**BigInt(e)}function up(e=[],t=new Set,r=new Set){return{valid:e.length===0,failures:e,properties:t,items:r}}function Lo(e,t,r){for(let i of r.properties)e.add(i);for(let i of r.items)t.add(i)}function wA(e,t){return new IA(e).evaluate(e.root,t,"")}class IA{compiled;active=new Set;constructor(e){this.compiled=e}evaluate(e,t,r){let i=`${e.key}\x00${r}`;if(this.active.has(i))throw TypeError("Admitted value schema entered a non-productive evaluation cycle.");this.active.add(i);try{if(e.schema===!0)return up();if(e.schema===!1)return up([dt(r,"false","The false schema rejects every value.")]);return this.evaluateObjectSchema(e,e.schema,t,r)}finally{this.active.delete(i)}}evaluateObjectSchema(e,t,r,i){let n=[],o=new Set,s=new Set,a=(c)=>{if(c.valid)Lo(o,s,c);else n.push(...c.failures)};if(Object.hasOwn(t,"$ref")){let c=this.compiled.resolutions.get(e.key);if(c===void 0)throw TypeError("Admitted value schema reference has no prepared resolution.");let u=this.compiled.locations.get(yr(c.resource.key,c.pointer));if(u===void 0)throw TypeError("Prepared value schema reference target is absent.");a(this.evaluate(u,r,i))}if(this.evaluateCompositions(e,t,r,i,n,o,s),this.evaluateCommonAssertions(t,r,i,n),typeof r==="number")this.evaluateNumberAssertions(t,r,i,n);if(typeof r==="string")this.evaluateStringAssertions(t,r,i,n);if(Array.isArray(r))this.evaluateArray(e,t,r,i,n,o,s);else if(ye(r))this.evaluateObject(e,t,r,i,n,o,s);return up(n,o,s)}evaluateCompositions(e,t,r,i,n,o,s){let a=(d)=>{if(d.valid)Lo(o,s,d);else n.push(...d.failures)};lp(t.allOf)?.forEach((d,f)=>{a(this.evaluate(this.child(e,"allOf",f),r,i))});let u=lp(t.anyOf);if(u!==void 0){let f=u.map((m,B)=>this.evaluate(this.child(e,"anyOf",B),r,i)).filter(({valid:m})=>m);if(f.length===0)n.push(dt(i,"anyOf","Value satisfies no anyOf branch."));else f.forEach((m)=>Lo(o,s,m))}let l=lp(t.oneOf);if(l!==void 0){let d=l.map((f,m)=>this.evaluate(this.child(e,"oneOf",m),r,i)).filter(({valid:f})=>f);if(d.length!==1)n.push(dt(i,"oneOf","Value must satisfy exactly one oneOf branch."));else Lo(o,s,d[0])}if(ai(t.not)){if(this.evaluate(this.child(e,"not"),r,i).valid)n.push(dt(i,"not","Value satisfies not."))}if(ai(t.if)){let d=this.evaluate(this.child(e,"if"),r,i);if(d.valid)Lo(o,s,d);let f=d.valid?"then":"else";if(ai(t[f]))a(this.evaluate(this.child(e,f),r,i))}}evaluateCommonAssertions(e,t,r,i){if(e["x-astrale-value-kind"]==="instant"&&!CA(t))i.push(dt(r,"x-astrale-value-kind","Value is not an exact UTC millisecond Instant."));if(typeof e.type==="string"){if(!Gv(e.type,t))i.push(dt(r,"type",`Value is not of type ${e.type}.`))}else if(Array.isArray(e.type)&&!e.type.some((n)=>typeof n==="string"?Gv(n,t):!1))i.push(dt(r,"type","Value matches none of the admitted types."));if(Object.hasOwn(e,"const")&&!Hv(t,e.const))i.push(dt(r,"const","Value differs from const."));if(Array.isArray(e.enum)&&!e.enum.some((n)=>Hv(t,n)))i.push(dt(r,"enum","Value is absent from enum."))}evaluateNumberAssertions(e,t,r,i){if(typeof e.multipleOf==="number"&&!xA(t,e.multipleOf))i.push(dt(r,"multipleOf","Number is not an exact multiple."));if(typeof e.maximum==="number"&&t>e.maximum)i.push(dt(r,"maximum","Number exceeds maximum."));if(typeof e.exclusiveMaximum==="number"&&t>=e.exclusiveMaximum)i.push(dt(r,"exclusiveMaximum","Number reaches exclusiveMaximum."));if(typeof e.minimum==="number"&&t<e.minimum)i.push(dt(r,"minimum","Number is below minimum."));if(typeof e.exclusiveMinimum==="number"&&t<=e.exclusiveMinimum)i.push(dt(r,"exclusiveMinimum","Number reaches exclusiveMinimum."))}evaluateStringAssertions(e,t,r,i){let n=Array.from(t).length;if(typeof e.maxLength==="number"&&n>e.maxLength)i.push(dt(r,"maxLength","String exceeds maxLength."));if(typeof e.minLength==="number"&&n<e.minLength)i.push(dt(r,"minLength","String is below minLength."));if(typeof e.pattern==="string"&&!this.compiled.matcher(e.pattern).test(t))i.push(dt(r,"pattern","String does not match pattern."));if(typeof e.fullMatch==="string"&&!this.compiled.matcher(e.fullMatch).matches(t))i.push(dt(r,"fullMatch","String does not match fullMatch."))}evaluateArray(e,t,r,i,n,o,s){if(typeof t.maxItems==="number"&&r.length>t.maxItems)n.push(dt(i,"maxItems","Array exceeds maxItems."));if(typeof t.minItems==="number"&&r.length<t.minItems)n.push(dt(i,"minItems","Array is below minItems."));if(t.uniqueItems===!0&&!vA(r))n.push(dt(i,"uniqueItems","Array items are not unique."));let a=lp(t.prefixItems)??[],c=Math.min(a.length,r.length),u=!0;for(let l=0;l<c;l++){let d=this.evaluate(this.child(e,"prefixItems",l),r[l],It(i,l));if(!d.valid)u=!1,n.push(...d.failures)}if(u)for(let l=0;l<c;l++)s.add(l);if(ai(t.items)){let l=!0,d=[];for(let f=a.length;f<r.length;f++){let m=this.evaluate(this.child(e,"items"),r[f],It(i,f));if(m.valid)d.push(f);else l=!1,n.push(...m.failures)}if(l)d.forEach((f)=>s.add(f))}if(ai(t.contains)){let l=[];for(let m=0;m<r.length;m++)if(this.evaluate(this.child(e,"contains"),r[m],It(i,m)).valid)l.push(m);let d=typeof t.minContains==="number"?t.minContains:1,f=typeof t.maxContains==="number"?t.maxContains:Number.POSITIVE_INFINITY;if(l.length<d||l.length>f)n.push(dt(i,"contains","Array has an invalid number of contains matches."));else l.forEach((m)=>s.add(m))}if(ai(t.unevaluatedItems)){let l=!0,d=[];for(let f=0;f<r.length;f++){if(s.has(f))continue;let m=this.evaluate(this.child(e,"unevaluatedItems"),r[f],It(i,f));if(m.valid)d.push(f);else l=!1,n.push(...m.failures)}if(l)d.forEach((f)=>s.add(f))}}evaluateObject(e,t,r,i,n,o,s){let a=Object.keys(r);if(typeof t.maxProperties==="number"&&a.length>t.maxProperties)n.push(dt(i,"maxProperties","Object exceeds maxProperties."));if(typeof t.minProperties==="number"&&a.length<t.minProperties)n.push(dt(i,"minProperties","Object is below minProperties."));if(Array.isArray(t.required)){for(let B of t.required)if(typeof B==="string"&&!Object.hasOwn(r,B))n.push(dt(i,"required",`Object is missing required property ${B}.`))}if(ye(t.dependentRequired))for(let[B,h]of Object.entries(t.dependentRequired)){if(!Object.hasOwn(r,B)||!Array.isArray(h))continue;for(let g of h)if(typeof g==="string"&&!Object.hasOwn(r,g))n.push(dt(i,"dependentRequired",`Property ${B} requires property ${g}.`))}let c=ye(t.properties)?t.properties:{},u=Object.keys(c).filter((B)=>Object.hasOwn(r,B)),l=!0;for(let B of u){let h=this.evaluate(this.child(e,"properties",B),r[B],It(i,B));if(!h.valid)l=!1,n.push(...h.failures)}if(l)u.forEach((B)=>o.add(B));let d=ye(t.patternProperties)?t.patternProperties:{},f=new Set,m=!0;for(let B of Object.keys(d)){let h=this.compiled.matcher(B);for(let g of a){if(!h.test(g))continue;f.add(g);let w=this.evaluate(this.child(e,"patternProperties",B),r[g],It(i,g));if(!w.valid)m=!1,n.push(...w.failures)}}if(m)f.forEach((B)=>o.add(B));if(ai(t.additionalProperties)){let B=a.filter((g)=>!Object.hasOwn(c,g)&&!f.has(g)),h=!0;for(let g of B){let w=this.evaluate(this.child(e,"additionalProperties"),r[g],It(i,g));if(!w.valid)h=!1,n.push(...w.failures)}if(h)B.forEach((g)=>o.add(g))}if(ai(t.propertyNames))for(let B of a){let h=this.evaluate(this.child(e,"propertyNames"),B,It(i,B));if(!h.valid)n.push(...h.failures)}if(ye(t.dependentSchemas))for(let B of Object.keys(t.dependentSchemas)){if(!Object.hasOwn(r,B))continue;let h=this.evaluate(this.child(e,"dependentSchemas",B),r,i);if(h.valid)Lo(o,new Set,h);else n.push(...h.failures)}if(ai(t.unevaluatedProperties)){let B=a.filter((w)=>!o.has(w)),h=!0,g=[];for(let w of B){let b=this.evaluate(this.child(e,"unevaluatedProperties"),r[w],It(i,w));if(b.valid)g.push(w);else h=!1,n.push(...b.failures)}if(h)g.forEach((w)=>o.add(w))}}child(e,t,r){let i=It(e.pointer,t),n=r===void 0?i:It(i,r),o=this.compiled.locations.get(yr(e.resource.key,n));if(o===void 0)throw TypeError(`Admitted value schema child ${n} is absent from its closure.`);return o}}function lp(e){return Array.isArray(e)?e:void 0}function ai(e){return typeof e==="boolean"||ye(e)}function dt(e,t,r){return{instancePointer:e,keyword:t,message:r}}function du(e,t){try{return se(e),[]}catch(r){if(r instanceof he)return[_("VS_NUMBER_DOMAIN",`${t}${r.pointer}`,r.message)];return[_("VS_META_SCHEMA",t,"Value is outside the JSON data model.")]}}var OA=new WeakMap;function dp(e,t,r,i=""){let n=[...du(t,i)];if(n.length>0)return n;let o=t2(e,r,i);if(o.kind==="error")return[_("VS_REFERENCE_RESOLUTION",i,`Value validation failed closed while preparing exact schema resources: ${o.message}.`)];let s=wA(o.compiled,t);if(s.valid)return[];return s.failures.map((a)=>_("VALUE_SCHEMA_INSTANCE_INVALID",`${i}${a.instancePointer}`,`Value does not satisfy its complete V1 schema at ${a.keyword}: ${a.message}`))}function t2(e,t,r){let i=OA.get(t);if(i===void 0)i=new Map,OA.set(t,i);let n=i.get(e);if(n!==void 0)return n;let o=cp(e,t,r),s=o.compiled?{kind:"validator",compiled:o.value}:{kind:"error",message:o.message};return i.set(e,s),s}function kA(e,t,r){let i=[],n=r2(e,t,r,i),o=n2(e,t,r,n,i);return i2(e,o,n,i),Object.freeze(i)}function r2(e,t,r,i){let n=new Map;for(let[o,s]of Object.entries(e.candidate.core.nodes)){let a=`/core/nodes/${$A(o)}`,c=e.resolve(s.class);if(s.class.origin!==e.candidate.origin||c===void 0||c.ref.kind!=="class"||c.family!=="node"){i.push(_("DV_CORE_NODE_CLASS",`${a}/class`,`Core Node Class ${Be(s.class)} must resolve to a local concrete Node Class.`,Be(s.class)));continue}let u=t.definitions.get(Q(s.class));if(u===void 0)continue;SA(u,s.properties,r,"DV_CORE_NODE_PROPERTIES",`${a}/properties`,i);let l={origin:e.candidate.origin,kind:"core",name:o},d=Q(l);n.set(d,{kind:"core",slug:o,ref:l,key:d,classRef:s.class,analysis:u})}return n}function n2(e,t,r,i,n){let o=[];for(let[s,a]of e.candidate.core.edges.entries()){let c=`/core/edges/${s}`,u=DA(a.source,`${c}/source`,i,n),l=DA(a.target,`${c}/target`,i,n),d=e.resolve(a.class);if(a.class.origin!==e.candidate.origin||d===void 0||d.ref.kind!=="class"||d.family!=="edge"){n.push(_("DV_CORE_EDGE_CLASS",`${c}/class`,`Core Edge Class ${Be(a.class)} must resolve to a local concrete Edge Class.`,Be(a.class)));continue}let f=t.definitions.get(Q(a.class));if(f===void 0)continue;SA(f,a.properties,r,"DV_CORE_EDGE_PROPERTIES",`${c}/properties`,n);let m=d.declaration;if(u===void 0||l===void 0)continue;if(!(m.orientation==="directed"?la(e,u,m.endpoints.source.accepts)&&la(e,l,m.endpoints.target.accepts):la(e,u,m.endpoints[0].accepts)&&la(e,l,m.endpoints[1].accepts)||la(e,u,m.endpoints[1].accepts)&&la(e,l,m.endpoints[0].accepts))){n.push(_("DV_CORE_EDGE_CLASS",c,`Core Edge endpoints do not satisfy ${Be(a.class)}.`,Be(a.class)));continue}o.push({source:u,target:l,declaration:m,value:a,pointer:c})}return o}function DA(e,t,r,i){if(e.kind==="domain")return{kind:"domain",ref:e,key:"domain"};let n=r.get(Q(e));if(n===void 0)i.push(_("DV_CORE_REF",t,`Core endpoint ${Be(e)} does not name a declared local Core Node.`,Be(e)));return n}function la(e,t,r){return t.kind==="domain"||fu(e,t.classRef,r)}function SA(e,t,r,i,n,o){let s={type:"object",properties:Object.fromEntries([...e.properties].map(([a,c])=>[a,c.schema])),required:[...e.properties].filter(([,a])=>a.required).map(([a])=>a).sort(lt),additionalProperties:!1};for(let a of dp(s,t,r,n))o.push(_(i,a.pointer,a.message,a.ref))}function i2(e,t,r,i){let n=new Map,o=new Map;for(let[s,a]of Object.entries(e.candidate.classes)){if(a.family!=="edge")continue;let c={origin:e.candidate.origin,kind:"class",name:s},u=e.resolve(c);if(u===void 0||u.ref.kind!=="class"||u.family!=="edge")continue;o.set(Q(c),{declaration:u.declaration,edges:[]})}for(let s of t){let a=Q(s.value.class),[c,u]=s.declaration.orientation==="undirected"&<(s.source.key,s.target.key)>0?[s.target.key,s.source.key]:[s.source.key,s.target.key],l=`${a}\x00${c}\x00${u}`,d=n.get(l);if(d!==void 0)i.push(_("DV_CORE_EDGE_KEY",s.pointer,`Core Edge duplicates the normalized EdgeKey declared at ${d}.`));else n.set(l,s.pointer);let f=o.get(a)??{declaration:s.declaration,edges:[]};if(f.edges.push(s),o.set(a,f),s.declaration.constraints.noSelf===!0&&s.source.key===s.target.key)i.push(_("DV_CORE_EDGE_CONSTRAINTS",s.pointer,"Core Edge violates noSelf."))}for(let{declaration:s,edges:a}of o.values()){if(s.constraints.acyclic===!0&&c2(a))i.push(_("DV_CORE_EDGE_CONSTRAINTS","/core/edges","Core Edge set violates exact-Class acyclicity."));o2(e,s,a,r,i)}}function o2(e,t,r,i,n){if(t.orientation==="undirected"){let[o,s]=t.endpoints;for(let a of i.values()){let c=fu(e,a.classRef,o.accepts),u=fu(e,a.classRef,s.accepts);if(!c&&!u)continue;let l=r.filter((d)=>d.source.key===a.key||d.target.key===a.key).length;if(c)_A(o,l,a,n);if(u&&!s2(o,s))_A(s,l,a,n)}return}for(let o of i.values()){if(fu(e,o.classRef,t.endpoints.source.accepts)){let s=r.filter((a)=>a.source.key===o.key).length;Vv(t.endpoints.source,t.endpoints.source.outgoing,s,o,n)}if(fu(e,o.classRef,t.endpoints.target.accepts)){let s=r.filter((a)=>a.target.key===o.key).length;Vv(t.endpoints.target,t.endpoints.target.incoming,s,o,n)}}}function Vv(e,t,r,i,n){let[o,s]=a2(t);if(r>=o&&r<=s)return;n.push(_("DV_CORE_EDGE_CONSTRAINTS",`/core/nodes/${$A(i.slug)}`,`Core degree ${r} violates ${e.role} Edge count ${t}.`))}function _A(e,t,r,i){Vv(e,e.incident,t,r,i)}function s2(e,t){return e.incident===t.incident&&e.accepts.length===t.accepts.length&&e.accepts.every((r,i)=>Q(r)===Q(t.accepts[i]))}function a2(e){switch(e){case"0..*":return[0,Number.POSITIVE_INFINITY];case"1..*":return[1,Number.POSITIVE_INFINITY];case"0..1":return[0,1];case"1":return[1,1]}}function c2(e){let t=new Map;for(let o of e){let s=t.get(o.source.key)??[];s.push(o.target.key),t.set(o.source.key,s)}let r=new Set,i=new Set,n=(o)=>{if(r.has(o))return!0;if(i.has(o))return!1;r.add(o);for(let s of t.get(o)??[])if(n(s))return!0;return r.delete(o),i.add(o),!1};return[...t.keys()].some(n)}function fu(e,t,r){if(r.some((n)=>Q(n)===Q(t)))return!0;let i=e.resolveAny(t);if(i===void 0||i.ref.kind!=="class"||i.family!=="node")return!1;return AA(e,i.declaration.implements,r,new Set)}function AA(e,t,r,i){let n=new Set(r.map(Q));for(let o of t){let s=Q(o);if(n.has(s))return!0;if(i.has(s))continue;i.add(s);let a=e.resolveAny(o);if(a!==void 0&&a.ref.kind==="interface"&&(a.family==="node"||a.family==="both")&&AA(e,a.declaration.extends,r,i))return!0}return!1}function $A(e){return e.replaceAll("~","~0").replaceAll("/","~1")}function fp(e){let t=[],r=new Map,i=new Set,n=(o)=>{let s=Q(o),a=r.get(s);if(a!==void 0)return a;if(i.has(s)){t.push(_("DV_INTERFACE_ACYCLIC","",`Inheritance cycle reaches ${Be(o)}.`,Be(o)));return}let c=e.resolveAny(o);if(c===void 0)return;i.add(s);let u=c.declaration,d=u2(u,o.kind).flatMap((g)=>{let w=e.resolveAny(g);if(w===void 0)return t.push(_("DV_REF_RESOLVES","",`Inheritance ref ${Be(g)} does not resolve.`,Be(g))),[];let b=n(w.ref);return b===void 0?[]:[b]}),f=d2(d.map((g)=>g.properties),l2(o,u)),m=f2(o,u,d,t),B=p2(o,u,d,t),h={ref:o,declaration:u,properties:f,...m===void 0?{}:{data:m},methods:B};return r.set(s,h),i.delete(s),h};for(let o of e.definitions.values())n(o.ref);return Object.freeze({definitions:r,diagnostics:Object.freeze(t)})}function u2(e,t){if(t==="interface")return e.extends;return e.implements}function l2(e,t){let r=t.properties,i=new Set(r.required),n=new Map;for(let[o,s]of Object.entries(r.properties)){let a=Pe.of(e,o),c=t.propertyMetadata[o];n.set(a,{identity:a,owner:e,name:o,schema:s,required:i.has(o),visibility:c?.visibility==="private"?"private":"public",...c?.auto===void 0?{}:{auto:c.auto}})}return n}function d2(e,t){let r=new Map;for(let i of e)for(let[n,o]of i)if(!r.has(n))r.set(n,o);for(let[i,n]of t)r.set(i,n);return r}function f2(e,t,r,i){let n;for(let s of r){if(s.data===void 0)continue;if(n===void 0){n=s.data;continue}if(n.identity!==s.data.identity)i.push(_("DV_DATA_COMPOSITION","",`Data has distinct declaring owners ${Be(n.owner)} and ${Be(s.data.owner)}.`))}let o="data"in t?t.data:void 0;if(o===void 0)return n;if(n!==void 0)i.push(_("DV_DATA_COMPOSITION","",`Data redeclares the inherited contract from ${Be(n.owner)}.`));return{identity:`${Q(e)}\x00data`,owner:e,declaration:o}}function p2(e,t,r,i){if(!("methods"in t))return new Map;let n=new Map;for(let s of r)for(let[a,c]of s.methods){let u=n.get(a)??[];if(!u.some((l)=>l.identity===c.identity))u.push(c);n.set(a,u)}let o=new Map;for(let[s,a]of n)if(a.length===1)o.set(s,a[0]);for(let[s,a]of Object.entries(t.methods)){let c=n.get(s)??[];for(let u of c){if(u.declaration.inheritance==="sealed")i.push(_("DV_METHOD_COMPOSITION","",`Method ${s} cannot override sealed ${Be(u.owner)}.${s}.`));if(!m2(a,u.declaration))i.push(_("DV_METHOD_COMPOSITION","",`Method ${s} does not exactly preserve its inherited signature.`));if(u.declaration.inheritance!=="abstract"&&NA(u.declaration.policy)!==NA(a.policy))i.push(_("DV_METHOD_COMPOSITION","",`Method ${s} changes an executable inherited Policy.`))}o.set(s,{identity:`${Q(e)}\x00method\x00${s}`,owner:e,name:s,declaration:a}),n.delete(s)}for(let[s,a]of n)if(a.length>1)i.push(_("DV_METHOD_COMPOSITION","",`Inherited method ${s} is ambiguous and has no local override.`));if(e.kind==="class"&&t.family==="node"){for(let[s,a]of o)if(a.declaration.inheritance==="abstract")i.push(_("DV_METHOD_COMPOSITION","",`Concrete Class ${e.name} leaves method ${s} abstract.`))}return o}function m2(e,t){return te.serialize(Kt(e.input,"callable-input"))===te.serialize(Kt(t.input,"callable-input"))&&TA(e)===TA(t)&&e.auth===t.auth&&e.static===t.static}function TA(e){switch(e.output.mode){case"value":return`value:${te.serialize(Kt(e.output.schema,"callable-output"))}`;case"stream":return`stream:${te.serialize(Kt(e.output.item,"callable-output"))}`;case"binary":return"binary"}}function NA(e){return te.serialize(e===void 0?null:Nn(e))}var RA=new WeakMap;function jA(e,t){let r=new Map;for(let i of t){let n=mt(i);r.set(qv(i.origin,n),{revision:n,schema:i})}RA.set(e,LA(r.values()))}function B2(e){return RA.get(e)}function da(e){let t=B2(e);if(t!==void 0)return t;throw new xe([_("DV_ACCEPTANCE_CONTEXT","",`DomainSchema ${e.origin} has no retained acceptance context; accept it again against its exact lookup.`)])}function pp(e){return new Ro(da(e))}function PA(e){let t=new Map;for(let r of e){let i=mt(r);t.set(qv(r.origin,i),{schema:r,revision:i});for(let n of da(r))t.set(qv(n.schema.origin,n.revision),n)}return LA(t.values())}function LA(e){return Object.freeze([...e].map(({revision:t,schema:r})=>Object.freeze({revision:t,schema:r})).sort((t,r)=>lt(t.schema.origin,r.schema.origin)||lt(t.revision,r.revision)))}function qv(e,t){return`${e}\x00${t}`}function Jv(e){let t=new Map;for(let[r,i]of Object.entries(e.interfaces)){let n={origin:e.origin,kind:"interface",name:r};t.set(Q(n),{ref:n,family:i.family,owner:e,declaration:i})}for(let[r,i]of Object.entries(e.classes)){let n={origin:e.origin,kind:"class",name:r};t.set(Q(n),{ref:n,family:i.family,owner:e,declaration:i})}return t}function mp(e){return new Set(h2(e).filter((t)=>t.origin!==e.origin).map((t)=>t.origin))}function h2(e){let t=new Map,r=(i)=>{t.set(Q(i),i)};for(let i of Object.values(e.types))hn(i,r);for(let i of Object.values(e.interfaces))Bp(i,r);for(let i of Object.values(e.classes))hp(i,r);for(let i of Object.values(e.functions))qi(i,r);for(let i of Object.values(e.policies))gp(i,r);for(let i of Object.values(e.views))if(i.target.kind==="definition")i.target.definitions.forEach(r);for(let i of Object.values(e.core.nodes))r(i.class);for(let i of e.core.edges)r(i.class);return Object.freeze([...t.values()].sort(Ue))}function Bp(e,t){if(e.extends.forEach(t),hn(e.properties,t),"methods"in e)Object.values(e.methods).forEach((r)=>qi(r,t));if(e.family==="edge")zA(e,t)}function hp(e,t){if(e.implements.forEach(t),hn(e.properties,t),e.family==="edge"){zA(e,t);return}if(Object.values(e.methods).forEach((r)=>qi(r,t)),e.policies.read!==void 0)t(e.policies.read)}function zA(e,t){let r=e.orientation==="directed"?[e.endpoints.source,e.endpoints.target]:e.endpoints;r[0].accepts.forEach(t),r[1].accepts.forEach(t)}function qi(e,t){if(hn(e.input,t),e.output.mode==="value")hn(e.output.schema,t);if(e.output.mode==="stream")hn(e.output.item,t);if(e.policy!==void 0)MA(e.policy,t)}function gp(e,t){if("match"in e){Kv(e.match,t);return}("allOf"in e?e.allOf:e.anyOf).forEach(t)}function Kv(e,t){if("source"in e){t(e.class);return}if("exists"in e){e.exists.nodes.forEach((i)=>t(i.class)),Kv(e.exists.where,t);return}("allOf"in e?e.allOf:e.anyOf).forEach((i)=>Kv(i,t))}function MA(e,t){if("check"in e){if(t(e.check),e.object.kind==="ref")t(e.object.ref);return}("allOf"in e?e.allOf:e.anyOf).forEach((i)=>MA(i,t))}function hn(e,t){Pr(e,({schema:r})=>{if(!ye(r))return;if(typeof r.$ref==="string"){let n=Uv(r.$ref);if(n!==void 0){let o={origin:n.origin,kind:"type",name:n.name};t(o)}}let i=r["x-astrale-path"];if(!ye(i)||!Array.isArray(i.accepts))return;for(let n of i.accepts)if(ye(n)&&typeof n.origin==="string"&&typeof n.kind==="string"&&typeof n.name==="string")t(n)})}function fa(e,t){let r=[],i=new Map,n=new Map,o=new Set;for(let[s,a]of e.dependencies.entries()){let c=`/dependencies/${s}`;if(!ii.test(a.revision))continue;if(a.origin===e.origin){r.push(_("DV_DEPENDENCY_UNIQUE",`${c}/origin`,"A Domain cannot depend on itself."));continue}if(o.has(a.origin)){r.push(_("DV_DEPENDENCY_UNIQUE",`${c}/origin`,`Dependency origin ${a.origin} is declared more than once.`));continue}o.add(a.origin);let u=t.get(a.origin,a.revision);if(u===void 0){r.push(_("DV_DEPENDENCY_EXACT",c,`Schema lookup has no exact ${a.origin}@${a.revision}.`));continue}if(u.origin!==a.origin){r.push(_("DV_DEPENDENCY_EXACT",c,`Schema lookup value origin ${u.origin} disagrees with ${a.origin}.`));continue}let l=mt(u);if(l!==a.revision){r.push(_("DV_DEPENDENCY_EXACT",c,`Schema lookup content revision is ${l}, not ${a.revision}.`));continue}i.set(u.origin,u)}g2(e,i,t,r);for(let[s,a]of Jv(e))n.set(s,a);for(let s of i.values())for(let[a,c]of Jv(s))n.set(a,c);return y2(e,o,r),Object.freeze({candidate:e,dependencies:i,definitions:n,diagnostics:Object.freeze(r),resolve(s){if(s.origin!==e.origin&&!o.has(s.origin))return;return n.get(Q(s))},resolveAny(s){return n.get(Q(s))},resolvePolicy(s){if(s.origin!==e.origin)return;return e.policies[s.name]}})}function g2(e,t,r,i){let n=new Map,o=new Set,s=new Set,a=(c,u)=>{if(o.has(u)){i.push(_("DV_DEPENDENCY_ACYCLIC","/dependencies",`Dependency cycle reaches ${c.origin}.`));return}if(s.has(u))return;o.add(u);for(let l of c.dependencies){if(l.origin===e.origin){i.push(_("DV_DEPENDENCY_ACYCLIC","/dependencies",`Dependency cycle returns to ${e.origin}.`));continue}let d=n.get(l.origin);if(d!==void 0&&d!==l.revision)i.push(_("DV_DEPENDENCY_REVISION_COHERENCE","/dependencies",`Closure contains ${l.origin} at both ${d} and ${l.revision}.`));else n.set(l.origin,l.revision);let f=t.get(l.origin)??r.get(l.origin,l.revision);if(f===void 0){i.push(_("DV_DEPENDENCY_EXACT","/dependencies",`Dependency closure is missing ${l.origin}@${l.revision}.`));continue}if(f.origin!==l.origin){i.push(_("DV_DEPENDENCY_EXACT","/dependencies",`Schema lookup value origin ${f.origin} disagrees with ${l.origin}.`));continue}if(mt(f)!==l.revision){i.push(_("DV_DEPENDENCY_EXACT","/dependencies",`Schema lookup content for ${l.origin} disagrees with ${l.revision}.`));continue}t.set(f.origin,f),a(f,`${l.origin}\x00${l.revision}`)}o.delete(u),s.add(u)};a(e,`${e.origin}\x00candidate`)}function y2(e,t,r){let i=mp(e);for(let n of i)if(!t.has(n))r.push(_("DV_DEPENDENCY_DIRECT","",`Foreign origin ${n} is referenced without an exact direct dependency.`));for(let n of t)if(!i.has(n))r.push(_("DV_DEPENDENCY_USED","/dependencies",`Dependency ${n} is not referenced by the Domain.`))}function FA(e,t=pp(e)){return pu(fa(e,t))}function pu(e){let t=[],r=[],i=new Set(e.candidate.dependencies.map(({origin:n})=>n));for(let n of e.dependencies.values()){let o={...UA(n),revision:mt(n)};if(i.has(n.origin))t.push(o);else r.push(o)}return Object.freeze({current:UA(e.candidate),directDependencies:Object.freeze(t),transitiveDependencies:Object.freeze(r),graphNodePath:ip})}function UA(e){let t=[...Object.entries(e.interfaces).filter(([,r])=>r.family==="node").map(([r])=>({origin:e.origin,kind:"interface",name:r})),...Object.entries(e.classes).filter(([,r])=>r.family==="node").map(([r])=>({origin:e.origin,kind:"class",name:r}))];return Object.freeze({origin:e.origin,dependencies:e.dependencies,types:e.types,nodeDefinitions:Object.freeze(t)})}var Zv=new Set(["null","boolean","number","string","array","object"]);function yp(e,t){let r=cp(e,t,"");if(!r.compiled)return;let i=new qA(r.value).classify(r.value.root);if(i.size!==1)return;let[n]=i;return n==="boolean"||n==="number"||n==="string"||n==="instant"?n:void 0}class qA{compiled;active=new Set;cache=new Map;constructor(e){this.compiled=e}classify(e){let t=this.cache.get(e.key);if(t!==void 0)return t;if(this.active.has(e.key))return Zv;this.active.add(e.key);try{let r=this.classifySchema(e);return this.cache.set(e.key,r),r}finally{this.active.delete(e.key)}}classifySchema(e){if(e.schema===!1)return new Set;if(e.schema===!0)return Zv;let t=e.schema,r=Zv;if(Object.hasOwn(t,"x-astrale-value-kind")){if(t["x-astrale-value-kind"]!=="instant"||t.type!=="string")return new Set;r=zo(r,new Set(["instant"]))}let i=C2(t.type);if(i!==void 0)r=zo(r,i);if(Object.hasOwn(t,"const"))r=zo(r,new Set([HA(t.const)]));if(Array.isArray(t.enum))r=zo(r,Wv(new Set(t.enum.map(HA))));if(Object.hasOwn(t,"$ref")){let o=this.compiled.resolutions.get(e.key);if(o===void 0)return new Set;let s=this.compiled.locations.get(yr(o.resource.key,o.pointer));if(s===void 0)return new Set;r=zo(r,this.classify(s))}let n=VA(t.allOf);if(n!==void 0)for(let o=0;o<n.length;o+=1)r=zo(r,this.classify(this.child(e,"allOf",o)));for(let o of["anyOf","oneOf"]){let s=VA(t[o]);if(s===void 0)continue;let a=new Set;for(let c=0;c<s.length;c+=1)a=b2(a,this.classify(this.child(e,o,c)));r=zo(r,a)}return r}child(e,t,r){let i=r===void 0?`/${t}`:`/${t}/${r}`,n=this.compiled.locations.get(`${e.key}${i}`);if(n===void 0)throw TypeError("Prepared value schema child is absent from its closure.");return n}}function C2(e){if(typeof e==="string")return GA([e]);if(Array.isArray(e)){let t=e.filter((r)=>typeof r==="string");return GA(t)}return}function GA(e){let t=new Set;for(let r of e)if(r==="integer"||r==="number")t.add("number");else if(r==="null"||r==="boolean"||r==="string"||r==="array"||r==="object")t.add(r);return t}function HA(e){if(e===null)return"null";if(Array.isArray(e))return"array";if(typeof e==="object")return"object";if(typeof e==="boolean")return"boolean";if(typeof e==="number")return"number";return"string"}function zo(e,t){let r=new Set;for(let i of e)for(let n of t)if(i===n)r.add(i);else if(i==="string"&&n==="instant"||i==="instant"&&n==="string")r.add("instant");return Wv(r)}function b2(e,t){return Wv(new Set([...e,...t]))}function Wv(e){if(e.has("string"))e.delete("instant");return e}function VA(e){return Array.isArray(e)?e:void 0}function e$(e,t){let r=[...t.diagnostics],i=e.candidate;for(let[n,o]of Object.entries(i.interfaces)){let s=XA(i.origin,"interfaces",n);if(JA(e,o,`/interfaces/${pa(n)}`,r),KA(e,s,o.family,o.extends,r),o.family==="edge")ZA(e,s,o,r)}for(let[n,o]of Object.entries(i.classes)){let s=XA(i.origin,"classes",n);if(JA(e,o,`/classes/${pa(n)}`,r),KA(e,s,o.family,o.implements,r),o.family==="edge")ZA(e,s,o,r)}return E2(e,r),Object.freeze(r)}function JA(e,t,r,i){let n=new Set(Object.keys(t.properties.properties));for(let[a,c]of t.properties.required.entries())if(!n.has(c))i.push(_("DV_PROPERTY_FACET",`${r}/properties/required/${a}`,`Required property ${c} is not directly declared.`));for(let a of Object.keys(t.propertyMetadata))if(!n.has(a))i.push(_("DV_PROPERTY_FACET",`${r}/propertyMetadata/${pa(a)}`,`Metadata cannot create hidden property ${a}.`));let o=new Set(t.properties.required),s=pu(e);for(let[a,c]of Object.entries(t.propertyMetadata)){if(c.auto===void 0)continue;let u=`${r}/propertyMetadata/${pa(a)}/auto`;if(o.has(a)&&!c.auto.on.includes("create"))i.push(_("DV_PROPERTY_AUTO",`${u}/on`,"A required automatic Property must run on create."));let l=t.properties.properties[a];if(l!==void 0&&c.auto.set==="instant"&&yp(l,s)!=="instant")i.push(_("DV_PROPERTY_AUTO",`${u}/set`,"The instant setter requires an Instant value schema."))}if("methods"in t)for(let[a,c]of Object.entries(t.methods)){let u=`${r}/methods/${pa(a)}`;if(c.inheritance==="abstract"&&c.policy!==void 0)i.push(_("DV_METHOD_ABSTRACT",`${u}/policy`,"Abstract Methods cannot have a Policy."));if(!("implements"in t));else if(c.inheritance==="abstract")i.push(_("DV_METHOD_ABSTRACT",`${u}/inheritance`,"A Node Class cannot declare an abstract Method."))}}function KA(e,t,r,i,n){for(let[o,s]of i.entries()){let a=e.resolve(s);if(a===void 0){n.push(_("DV_REF_RESOLVES",`/${t.kind==="class"?"classes":"interfaces"}/${pa(t.name)}/${t.kind==="class"?"implements":"extends"}/${o}`,`Parent ${Be(s)} does not resolve exactly.`,Be(s)));continue}if(!(a.ref.kind==="interface"&&(r==="both"?a.family==="both":a.family===r||a.family==="both")))n.push(_("DV_INTERFACE_KIND","",`${Be(t)} cannot inherit ${Be(s)}.`))}}function ZA(e,t,r,i){let n=r.orientation==="directed"?[r.endpoints.source,r.endpoints.target]:r.endpoints;if(n[0].role===n[1].role)i.push(_("DV_EDGE_ROLE","",`${Be(t)} has equal source and target roles.`));if(WA(e,t,n[0],r.orientation==="directed"?"source":"first endpoint",i),WA(e,t,n[1],r.orientation==="directed"?"target":"second endpoint",i),r.orientation==="undirected"){if(!v2(r.endpoints[0],r.endpoints[1])&&x2(e,r.endpoints))i.push(_("DV_EDGE_UNDIRECTED","",`${Be(t)} has unequal undirected endpoint contracts whose accepted Node families overlap.`));if(r.constraints.acyclic===!0)i.push(_("DV_EDGE_CONSTRAINT","","acyclic is valid only for directed Edge contracts."))}}function WA(e,t,r,i,n){let o=new Set;for(let s of r.accepts){let a=Q(s);if(o.has(a))n.push(_("DV_EDGE_ACCEPTS","",`${Be(t)} ${i} repeats ${Be(s)}.`));o.add(a);let c=e.resolve(s);if(c===void 0||c.family!=="node")n.push(_("DV_EDGE_ACCEPTS","",`${Be(t)} ${i} ref ${Be(s)} does not resolve to a Node Definition.`))}}function E2(e,t){for(let r of e.definitions.values()){if(r.family!=="edge")continue;let i=r.declaration,n=r.ref.kind==="interface"?i.extends:i.implements;for(let o of n){let s=e.resolveAny(o);if(s===void 0||s.ref.kind!=="interface"||s.family!=="edge")continue;let a=s.declaration,c={endpoints:YA(i.endpoints),orientation:i.orientation,constraints:i.constraints},u={endpoints:YA(a.endpoints),orientation:a.orientation,constraints:a.constraints};if(te.serialize(c)!==te.serialize(u))t.push(_("DV_EDGE_INTERFACE_COMPOSITION","",`${Be(r.ref)} does not exactly preserve ${Be(o)}.`))}}}function YA(e){if(Array.isArray(e))return[{...e[0],accepts:[...e[0].accepts].sort(Ue)},{...e[1],accepts:[...e[1].accepts].sort(Ue)}];let t=e;return{source:{...t.source,accepts:[...t.source.accepts].sort(Ue)},target:{...t.target,accepts:[...t.target.accepts].sort(Ue)}}}function v2(e,t){if(e.incident!==t.incident)return!1;let r=[...e.accepts].map(Q).sort(),i=[...t.accepts].map(Q).sort();return r.length===i.length&&r.every((n,o)=>n===i[o])}function x2(e,t){for(let r of e.definitions.values()){if(r.ref.kind!=="class"||r.family!=="node")continue;let i=r.ref;if(QA(e,i,t[0].accepts)&&QA(e,i,t[1].accepts))return!0}return!1}function QA(e,t,r){if(r.some((o)=>Q(o)===Q(t)))return!0;let i=e.resolveAny(t);if(i===void 0||i.ref.kind!=="class"||i.family!=="node")return!1;let n=i.declaration;return t$(e,n.implements,r,new Set)}function t$(e,t,r,i){let n=new Set(r.map(Q));for(let o of t){let s=Q(o);if(n.has(s))return!0;if(i.has(s))continue;i.add(s);let a=e.resolveAny(o);if(a!==void 0&&a.ref.kind==="interface"&&(a.family==="node"||a.family==="both")&&t$(e,a.declaration.extends,r,i))return!0}return!1}function XA(e,t,r){return{origin:e,kind:t==="classes"?"class":"interface",name:r}}function pa(e){return e.replaceAll("~","~0").replaceAll("/","~1")}class Yv{environment;analysis;diagnostics=[];normalized=new Map;allNodeClasses;#e=new Set;constructor(e,t){this.environment=e,this.analysis=t,this.allNodeClasses=[...e.definitions.values()].filter((r)=>r.ref.kind==="class"&&r.family==="node").map((r)=>r.ref)}resolveNodeClass(e,t){let r=this.environment.resolve(e);if(r===void 0||r.ref.kind!=="class"||r.family!=="node"){this.add("PL_REF",t,`${Be(e)} does not resolve to an owning/direct-dependency Node Class.`,Be(e));return}return r}resolveEdge(e,t){let r=this.environment.resolve(e);if(r===void 0||r.ref.kind!=="class"||r.family!=="edge"){this.add("PL_REF",t,`${Be(e)} does not resolve to an owning/direct-dependency Edge Class.`,Be(e));return}return r}resolvePolicy(e,t){let r=`${t}\x00${Q(e)}`;if(this.#e.has(r))return!1;let i=this.environment.resolvePolicy(e);if(e.origin!==this.environment.candidate.origin||e.kind!=="policy"||i===void 0)return this.#e.add(r),this.add("PL_REF",t,`${Be(e)} is not an exact local named Policy ref.`,Be(e)),!1;return!0}isLocalPolicy(e){return e.origin===this.environment.candidate.origin&&e.kind==="policy"&&this.environment.candidate.policies[e.name]!==void 0}edgeDeclaration(e){let t=this.environment.resolve(e);if(t===void 0||t.ref.kind!=="class"||t.family!=="edge")return;let r=t.declaration;return r.family==="edge"?r:void 0}classImplements(e,t){let r=this.environment.resolveAny(e);if(r===void 0||r.ref.kind!=="class"||r.family!=="node")return!1;let i=r.declaration;if(i.family!=="node")return!1;return i.implements.some((n)=>this.interfaceExtends(n,t))}interfaceExtends(e,t){if(Q(e)===Q(t))return!0;let r=new Set,i=(n)=>{let o=Q(n);if(o===Q(t))return!0;if(r.has(o))return!1;r.add(o);let s=this.environment.resolveAny(n);if(s===void 0||s.ref.kind!=="interface"||s.family!=="node"&&s.family!=="both")return!1;return s.declaration.extends.some(i)};return i(e)}add(e,t,r,i){this.diagnostics.push(_(e,t,r,i))}}function Ar(e){return e.replaceAll("~","~0").replaceAll("/","~1")}var r$=4,ma=8,Xv=4,n$=6,mu=3,i$=4,ex=4,tx=8,ci=ma+1;function o$(e){for(let t of Object.keys(e.environment.candidate.policies)){let r=s$(e,t,new Set);if(r===void 0)continue;let i=`/policies/${Ar(t)}`;if(r.depth>r$)e.add("PL_BUDGET",i,`Expanded Pattern depth ${r.depth} exceeds ${r$}.`);if(r.edgeCounts.length>ma)e.add("PL_BUDGET",i,`Expanded Pattern has more than ${ma} normalized branches.`);let n=Math.max(0,...r.edgeCounts);if(n>n$)e.add("PL_BUDGET",i,`A normalized branch contains ${n} Edge predicates; the maximum is ${n$}.`);if(r.domains.size>i$)e.add("PL_BUDGET",i,`Expanded Pattern references ${r.domains.size} Domains; the maximum is ${i$}.`)}}function rx(e){if("check"in e)return{depth:1,branches:1,leaves:1};let{key:t,values:r}=O2(e),i=r.map(rx),n=t==="allOf"?i.reduce((o,s)=>w2(o,s.branches),1):i.reduce((o,s)=>Math.min(ci,o+s.branches),0);return{depth:1+Math.max(0,...i.map((o)=>o.depth)),branches:n,leaves:i.reduce((o,s)=>o+s.leaves,0)}}function s$(e,t,r){if(r.has(t))return;let i=e.normalized.get(t);if(i===void 0)return;let n=new Set(r);if(n.add(t),"match"in i)return Qv(i.match,e.environment.candidate.origin);let o="allOf"in i?i.allOf:i.anyOf,s=o.flatMap((a)=>{if(!e.isLocalPolicy(a))return[];let c=s$(e,a.name,n);return c===void 0?[]:[c]});if(s.length!==o.length||s.length===0)return;return a$("allOf"in i?"allOf":"anyOf",s)}function Qv(e,t){if(D2(e))return{depth:1,edgeCounts:[1],domains:new Set([t,e.class.origin])};if("exists"in e){let n=Qv(e.exists.where,t);return{depth:n.depth+1,edgeCounts:n.edgeCounts,domains:new Set([...n.domains,...e.exists.nodes.map((o)=>o.class.origin)])}}let{key:r,values:i}=I2(e);return a$(r,i.map((n)=>Qv(n,t)))}function a$(e,t){let r=1+Math.max(0,...t.map((o)=>o.depth)),i=new Set(t.flatMap((o)=>[...o.domains]));if(e==="anyOf")return{depth:r,edgeCounts:t.flatMap((o)=>o.edgeCounts).slice(0,ci),domains:i};let n=[0];for(let o of t){let s=[];for(let a of n){for(let c of o.edgeCounts)if(s.push(a+c),s.length>=ci)break;if(s.length>=ci)break}n=s}return{depth:r,edgeCounts:n,domains:i}}function w2(e,t){return Math.min(ci,e*t)}function I2(e){return"allOf"in e?{key:"allOf",values:e.allOf}:{key:"anyOf",values:e.anyOf}}function O2(e){return"allOf"in e?{key:"allOf",values:e.allOf}:{key:"anyOf",values:e.anyOf}}function D2(e){return"source"in e}function Cp(e,t){let r=S2(e,t);return nx(e,t,r)}function ix(e){let t=[_2()];for(let r of e){let i=[];for(let n of t)for(let o of r)if(i.push(k2(n,o)),i.length>=ci)return i;t=i}return t}function ox(e){return e.length<=ci?e:e.slice(0,ci)}function c$(e){let t=Ba(e);if(t===void 0)return!1;let r=new Set(t==="object"?["subject","object"]:["subject","source","target"]);for(let o of e.requiredVariables)r.add(o);let i=new u$(r);for(let o of e.edges){let s=Mo(o.pattern.source,o.namespace),a=Mo(o.pattern.target,o.namespace);i.add(s),i.add(a),i.join(s,a)}let n=i.find("subject");return[...r].every((o)=>i.find(o)===n)}function Ba(e){let t=!1,r=!1,i=!1;for(let n of e.edges)for(let o of[n.pattern.source,n.pattern.target])t||=o.kind==="object",r||=o.kind==="source",i||=o.kind==="target";if(t&&!r&&!i)return"object";if(!t&&r&&i)return"edge";return}function Mo(e,t){return e.kind==="variable"?sx(t,e.id):e.kind}function nx(e,t,r){if($2(e))return[{edges:[{pattern:e,namespace:t}],variables:r,requiredVariables:new Set,namespace:t}];if("exists"in e){let s=new Set(e.exists.nodes.map((a)=>sx(t,a.variable.id)));return nx(e.exists.where,t,r).map((a)=>({...a,requiredVariables:new Set([...a.requiredVariables,...s])}))}let{key:i,values:n}=A2(e),o=n.map((s)=>nx(s,t,r));return i==="allOf"?ix(o):ox(o.flat())}function _2(){return{edges:[],variables:new Map,requiredVariables:new Set,namespace:"$"}}function k2(e,t){return{edges:[...e.edges,...t.edges],variables:new Map([...e.variables,...t.variables]),requiredVariables:new Set([...e.requiredVariables,...t.requiredVariables]),namespace:`${e.namespace}&${t.namespace}`}}function S2(e,t){let r=new Map,i=(n)=>{if("exists"in n){for(let o of n.exists.nodes)r.set(sx(t,o.variable.id),o.class);i(n.exists.where)}else if("allOf"in n)n.allOf.forEach(i);else if("anyOf"in n)n.anyOf.forEach(i)};return i(e),r}function sx(e,t){return`variable:${e}:${t}`}function A2(e){return"allOf"in e?{key:"allOf",values:e.allOf}:{key:"anyOf",values:e.anyOf}}function $2(e){return"source"in e}class u${#e=new Map;constructor(e){for(let t of e)this.add(t)}add(e){if(!this.#e.has(e))this.#e.set(e,e)}find(e){this.add(e);let t=this.#e.get(e);if(t===e)return e;let r=this.find(t);return this.#e.set(e,r),r}join(e,t){let r=this.find(e),i=this.find(t);if(r!==i)this.#e.set(i,r)}}function d$(e){for(let[t,r]of Object.entries(e.environment.candidate.policies)){let i=`/policies/${Ar(t)}`;if(e.normalized.set(t,To(r)),"match"in r)T2(e,t,r.match,i);else N2(e,r,i)}R2(e)}function T2(e,t,r,i){let n=new Map,o=new Map;ax(e,r,`${i}/match`,new Set,n,o);for(let[c,u]of n)if((o.get(c)??0)===0)e.add("PL_VARIABLE_SCOPE",u.pointer,`Variable ${c} is declared but never used.`);let s=Pv(r),a=Cp(s,t);for(let[c,u]of a.entries()){let l=Ba(u);if(l===void 0){e.add("PL_TARGET",`${i}/match`,`Normalized branch ${c} must use object or both source and target, without mixing target modes.`);continue}if(!c$(u))e.add("PL_CONNECTIVITY",`${i}/match`,`Normalized ${l} branch ${c} does not connect subject, its target terms, and every scoped term.`)}}function ax(e,t,r,i,n,o){if(P2(t)){if(e.resolveEdge(t.class,`${r}/class`),l$(e,t.source,`${r}/source`,i,o),l$(e,t.target,`${r}/target`,i,o),t.repeat!==void 0){let{min:c,max:u}=t.repeat;if(!Number.isInteger(c)||!Number.isInteger(u)||c<0||u<c||u>mu)e.add("PL_REPEAT",`${r}/repeat`,`Repeat requires integral bounds 0 <= min <= max <= ${mu}.`)}return}if("exists"in t){if(t.exists.nodes.length>Xv)e.add("PL_BUDGET",`${r}/exists/nodes`,`An exists expression declares ${t.exists.nodes.length} variables; the maximum is ${Xv}.`);let c=new Set(i);for(let[u,l]of t.exists.nodes.entries()){let d=l.variable.id,f=`${r}/exists/nodes/${u}`;if(n.has(d))e.add("PL_VARIABLE_SCOPE",`${f}/variable/id`,`Variable ${d} is declared more than once; variable IDs are globally unique.`);else n.set(d,{ref:l.class,pointer:f});if(c.has(d))e.add("PL_VARIABLE_SCOPE",`${f}/variable/id`,`Variable ${d} shadows an enclosing variable.`);c.add(d),e.resolveNodeClass(l.class,`${f}/class`)}ax(e,t.exists.where,`${r}/exists/where`,c,n,o);return}let{key:s,values:a}=j2(t);if(a.length===0)e.add("PL_COMPOSITION",`${r}/${s}`,`${s} must be non-empty.`);a.forEach((c,u)=>ax(e,c,`${r}/${s}/${u}`,i,n,o))}function l$(e,t,r,i,n){if(t.kind==="variable")if(!i.has(t.id))e.add("PL_VARIABLE_SCOPE",r,`Variable ${t.id} is free, escaped, or outside its defining exists scope.`);else n.set(t.id,(n.get(t.id)??0)+1)}function N2(e,t,r){let i="allOf"in t?"allOf":"anyOf",n="allOf"in t?t.allOf:t.anyOf;if(n.length===0)e.add("PL_COMPOSITION",`${r}/${i}`,`${i} must be non-empty.`);n.forEach((o,s)=>e.resolvePolicy(o,`${r}/${i}/${s}`))}function R2(e){let t=new Set,r=new Set,i=(n,o)=>{if(t.has(n)){e.add("PL_COMPOSITION",`/policies/${Ar(n)}`,`Named Policy composition cycle: ${[...o,n].join(" -> ")}.`);return}if(r.has(n))return;t.add(n);let s=e.environment.candidate.policies[n];if(s!==void 0&&!("match"in s)){let a="allOf"in s?s.allOf:s.anyOf;for(let c of a)if(c.origin===e.environment.candidate.origin&&c.kind==="policy")i(c.name,[...o,n])}t.delete(n),r.add(n)};for(let n of Object.keys(e.environment.candidate.policies))i(n,[])}function j2(e){return"allOf"in e?{key:"allOf",values:e.allOf}:{key:"anyOf",values:e.anyOf}}function P2(e){return"source"in e}var f$={origin:"kernel.astrale.ai",kind:"interface",name:"Identity"};class cx{context;constructor(e){this.context=e}validatePolicies(){for(let e of Object.keys(this.context.environment.candidate.policies)){let t=this.#e(e,new Set,`$${e}`);if(t===void 0)continue;for(let[r,i]of t.entries()){let n=Ba(i);if(n===void 0){if(!("match"in this.context.environment.candidate.policies[e]))this.context.add("PL_TARGET",`/policies/${Ar(e)}`,`Expanded normalized branch ${r} must use object or both source and target, without mixing target modes.`);continue}let o=n==="object"?{kind:"object",object:{kind:"default"}}:{kind:"edge",source:{kind:"default"},target:{kind:"default"}};if(!this.#t(i,o))this.context.add("PL_TYPING",`/policies/${Ar(e)}`,`Expanded normalized branch ${r} has contradictory endpoint or repeat contracts.`)}}}policyAccepts(e,t){let r=this.#e(e,new Set,`$use:${e}`),i={kind:"object",object:t};return r!==void 0&&r.every((n)=>this.#t(n,i))}policyAcceptsEdge(e,t,r){let i=this.#e(e,new Set,`$edge-use:${e}`),n={kind:"edge",source:t,target:r};return i!==void 0&&i.every((o)=>this.#t(o,n))}concreteEndpointClasses(e){return this.context.allNodeClasses.filter((t)=>this.#c(t,e))}endpointsOverlap(e,t){let r=[{kind:"open",requirements:[]}],i=this.#s(r,e);return this.#s(i,t).length>0}#e(e,t,r){if(t.has(e))return;let i=this.context.normalized.get(e);if(i===void 0)return;if("match"in i)return Cp(i.match,r);let n=new Set(t);n.add(e);let o="allOf"in i?i.allOf:i.anyOf,s=[];for(let[a,c]of o.entries()){if(!this.context.isLocalPolicy(c))return;let u=this.#e(c.name,n,`${r}/${a}:${c.name}`);if(u===void 0)return;s.push(u)}return"allOf"in i?ix(s):ox(s.flat())}#t(e,t){if(Ba(e)!==t.kind)return!1;return L2(e.edges,this).some((i)=>this.#r(e,i,t))}#r(e,t,r){let i=new Set(r.kind==="object"?["subject","object"]:["subject","source","target"]);for(let a of e.variables.keys())i.add(a);for(let a of e.edges)i.add(Mo(a.pattern.source,a.namespace)),i.add(Mo(a.pattern.target,a.namespace));let n=new g$(i);for(let a of t)for(let[c,u]of a.equalities)n.join(c,u);let o=new Map;for(let a of t)for(let[c,u]of a.constraints){let l=n.find(c),d=o.get(l)??[];d.push(u),o.set(l,d)}let s=new Map;for(let a of i){let c=n.find(a),u=s.get(c)??[];u.push(a),s.set(c,u)}for(let[a,c]of s){let u=o.get(a)??[],l=c.map((f)=>({member:f,contract:p$(f,r)})).find((f)=>f.contract?.kind==="universal-interface");if(l!==void 0){if(!this.#n(c,u,l.member,l.contract.ref,e))return!1;continue}let d=[{kind:"open",requirements:[]}];for(let f of c)if(d=this.#i(d,f,e,r),d.length===0)return!1;for(let f of u)if(d=this.#s(d,f),d.length===0)return!1}return!0}#n(e,t,r,i,n){for(let o of e){if(o===r)continue;if(o==="subject"){if(!this.context.interfaceExtends(i,f$))return!1;continue}if(this.#a(o,n)!==void 0)return!1}return t.every((o)=>o.some((s)=>s.kind==="interface"&&this.context.interfaceExtends(i,s)))}#i(e,t,r,i){if(t==="subject")return this.#u(e,f$);let n=p$(t,i);if(n!==void 0){if(n.kind==="exact")return this.#o(e,n.ref);if(n.kind==="default")return bp(this.context.allNodeClasses.flatMap((s)=>this.#o(e,s)));return e}let o=this.#a(t,r);return o===void 0?[]:this.#o(e,o)}#a(e,t){return t.variables.get(e)}#o(e,t){let r=[];for(let i of e)if(i.kind==="exact"){if(Q(i.ref)===Q(t))r.push(i)}else if(i.requirements.every((n)=>this.context.classImplements(t,n)))r.push({kind:"exact",ref:t});return bp(r)}#u(e,t){return bp(e.flatMap((r)=>{if(r.kind==="exact")return this.context.classImplements(r.ref,t)?[r]:[];return[{kind:"open",requirements:h$([...r.requirements,t])}]}))}#s(e,t){let r=[];for(let i of e){if(i.kind==="exact"){if(this.#c(i.ref,t))r.push(i);continue}for(let n of t)if(n.kind==="interface")r.push({kind:"open",requirements:h$([...i.requirements,n])});else if(i.requirements.every((o)=>this.context.classImplements(n,o)))r.push({kind:"exact",ref:n})}return bp(r)}#c(e,t){return t.some((r)=>r.kind==="class"&&Q(r)===Q(e)||r.kind==="interface"&&this.context.classImplements(e,r))}}function p$(e,t){if(t.kind==="object")return e==="object"?t.object:void 0;if(e==="source")return t.source;if(e==="target")return t.target;return}function Ep(e){return e.kind==="class"?{kind:"exact",ref:e}:{kind:"universal-interface",ref:e}}function L2(e,t){let r=[[]];for(let i of e){let n=z2(i,t);if(n.length===0)return[];let o=[];for(let s of r)for(let a of n)o.push([...s,a]);r=o}return r}function z2(e,t){let r=e.pattern,i=t.context.edgeDeclaration(r.class);if(i===void 0)return[];let n=i.orientation==="directed"?[i.endpoints.source,i.endpoints.target]:i.endpoints,o=r.repeat??{min:1,max:1};if(!Number.isInteger(o.min)||!Number.isInteger(o.max)||o.min<0||o.max<o.min||o.max>mu)return[];let s=Mo(r.source,e.namespace),a=Mo(r.target,e.namespace),c=[];for(let u=o.min;u<=o.max;u++){if(u===0){c.push({constraints:[],equalities:[[s,a]]});continue}let l=i.orientation==="undirected"?2**u:1;for(let d=0;d<l;d++){let f=Array.from({length:u},(g,w)=>i.orientation==="undirected"&&(d&1<<w)!==0),m=!0;for(let g=0;g+1<u;g++){let w=B$(n,f[g]??!1),b=m$(n,f[g+1]??!1);if(!t.endpointsOverlap(w.accepts,b.accepts)){m=!1;break}}if(!m)continue;let B=m$(n,f[0]??!1),h=B$(n,f[u-1]??!1);c.push({constraints:[[s,B.accepts],[a,h.accepts]],equalities:[]})}}return M2(c)}function m$(e,t){return t?e[1]:e[0]}function B$(e,t){return t?e[0]:e[1]}function M2(e){let t=new Map;for(let r of e){let i=`${r.constraints.map(([n,o])=>`${n}:${o.map(Q).sort().join(",")}`).join("|")}=${r.equalities.map(([n,o])=>`${n}:${o}`).join("|")}`;t.set(i,r)}return[...t.values()]}function bp(e){let t=new Map;for(let r of e){let i=r.kind==="exact"?`exact:${Q(r.ref)}`:`open:${r.requirements.map(Q).sort().join("|")}`;t.set(i,r)}return[...t.values()]}function h$(e){return[...new Map(e.map((t)=>[Q(t),t])).values()]}class g${#e=new Map;constructor(e){for(let t of e)this.add(t)}add(e){if(!this.#e.has(e))this.#e.set(e,e)}find(e){this.add(e);let t=this.#e.get(e);if(t===e)return e;let r=this.find(t);return this.#e.set(e,r),r}join(e,t){let r=this.find(e),i=this.find(t);if(r!==i)this.#e.set(i,r)}}var U2="kernel.astrale.ai",F2=hu("Class"),G2=hu("Function"),H2=hu("Interface"),V2=hu("Policy"),q2=hu("View");function b$(e,t){for(let[r,i]of Object.entries(e.environment.candidate.classes)){if(i.family!=="node"||i.policies.read===void 0)continue;let n=`/classes/${Ar(r)}/policies/read`,o=i.policies.read;if(!e.resolvePolicy(o,n))continue;let s={kind:"exact",ref:{origin:e.environment.candidate.origin,kind:"class",name:r}};if(!t.policyAccepts(o.name,s))e.add("PL_USE",n,`${Be(o)} is not valid for every normalized branch of protected Class ${r}.`,Be(o))}}function E$(e,t){for(let[r,i]of Object.entries(e.environment.candidate.classes)){let n=i.policies.traverse;if(n===void 0)continue;let o=`/classes/${Ar(r)}/policies/traverse`;if(!e.resolvePolicy(n,o))continue;if(i.family==="node"){let l={kind:"exact",ref:{origin:e.environment.candidate.origin,kind:"class",name:r}};if(!t.policyAccepts(n.name,l))e.add("PL_USE",o,`${Be(n)} is not valid for every normalized branch of traversed Node Class ${r}.`,Be(n));continue}let s=i.orientation==="directed"?[i.endpoints.source,i.endpoints.target]:i.endpoints,a=t.concreteEndpointClasses(s[0].accepts),c=t.concreteEndpointClasses(s[1].accepts),u=!0;for(let l of a){for(let d of c)if(!t.policyAcceptsEdge(n.name,{kind:"exact",ref:l},{kind:"exact",ref:d})){u=!1;break}if(!u)break}if(!u)e.add("PL_USE",o,`${Be(n)} is not valid for every concrete source/target pair of traversed Edge Class ${r}.`,Be(n))}}function v$(e,t){for(let[r,i]of Object.entries(e.environment.candidate.functions)){if(i.policy===void 0)continue;x$(e,t,i.policy,{pointer:`/functions/${Ar(r)}/policy`,input:i.input,instanceMethod:!1})}for(let[r,i]of Object.entries(e.environment.candidate.interfaces)){if(i.family!=="node")continue;y$(e,t,"interfaces",r,i.methods,{origin:e.environment.candidate.origin,kind:"interface",name:r})}for(let[r,i]of Object.entries(e.environment.candidate.classes)){if(i.family!=="node")continue;y$(e,t,"classes",r,i.methods,{origin:e.environment.candidate.origin,kind:"class",name:r})}}function y$(e,t,r,i,n,o){let s=e.analysis.definitions.get(Q(o));for(let[a,c]of Object.entries(n)){if(c.policy===void 0)continue;if(s!==void 0&&!s.methods.has(a))continue;x$(e,t,c.policy,{pointer:`/${r}/${Ar(i)}/methods/${Ar(a)}/policy`,input:c.input,receiver:o,instanceMethod:!c.static})}}function x$(e,t,r,i){let n=Nn(r),o=rx(n);if(o.depth>ex||o.branches>ma||o.leaves>tx)e.add("PL_BUDGET",i.pointer,`Callable checks require depth <= ${ex}, branches <= ${ma}, and leaves <= ${tx}; got ${o.depth}, ${o.branches}, ${o.leaves}.`);w$(e,t,n,i,i.pointer)}function w$(e,t,r,i,n){if("check"in r){if(!e.resolvePolicy(r.check,`${n}/check`))return;let a=`${n}/object`,c=r.object.kind==="self"?K2(e,i,a):r.object.kind==="input"?Z2(e,i,r.object.field,a):J2(e,r.object.ref,a);if(c===void 0)return;for(let u of c)if(!t.policyAccepts(r.check.name,u)){e.add("PL_USE",n,`${Be(r.check)} is incompatible with the callable object contract.`,Be(r.check));break}return}let{key:o,values:s}=Y2(r);if(s.length===0)e.add("PL_COMPOSITION",`${n}/${o}`,`${o} must be non-empty.`);s.forEach((a,c)=>w$(e,t,a,i,`${n}/${o}/${c}`))}function J2(e,t,r){let i=e.environment.candidate;if(t.origin!==i.origin)return Uo(e,t,r);switch(t.kind){case"interface":return e.environment.resolve(t)?.ref.kind===t.kind?[{kind:"exact",ref:H2}]:Uo(e,t,r);case"class":return e.environment.resolve(t)?.ref.kind===t.kind?[{kind:"exact",ref:F2}]:Uo(e,t,r);case"function":return i.functions[t.name]===void 0?Uo(e,t,r):[{kind:"exact",ref:G2}];case"policy":return i.policies[t.name]===void 0?Uo(e,t,r):[{kind:"exact",ref:V2}];case"view":return i.views[t.name]===void 0?Uo(e,t,r):[{kind:"exact",ref:q2}];case"core":{let n=i.core.nodes[t.name];if(n===void 0)return Uo(e,t,r);let o=e.environment.resolve(n.class),s=e.analysis.definitions.get(Q(n.class));if(n.class.origin!==i.origin||o?.ref.kind!=="class"||o.family!=="node"||s===void 0)return;return[Ep(n.class)]}}}function Uo(e,t,r){e.add("PL_REF",`${r}/ref`,`${Be(t)} is not an exact local projected Policy object.`,Be(t));return}function K2(e,t,r){if(!t.instanceMethod||t.receiver===void 0){e.add("PL_USE",r,"self is valid only for a Node instance Method.");return}return[Ep(t.receiver)]}function Z2(e,t,r,i){let n=Bu(t.input),o=Bu(n?.properties),s=Bu(o?.[r]),a=n?.required,c=n?.type==="object"&&o!==void 0&&Array.isArray(a)&&a.includes(r)&&n.additionalProperties===!1&&!C$(n),u=Bu(s?.["x-astrale-path"]);if(!(c&&s?.$ref===jt&&!C$(s)&&u?.target==="node"&&u.cardinality==="one"&&Array.isArray(u.accepts)&&u.accepts.length>0)){e.add("PL_USE",i,`input.${r} must be one direct required single-Node x-astrale-path field of a closed object input.`);return}let d=[];for(let f of u.accepts){if(!W2(f)){e.add("PL_USE",i,`input.${r} has a non-Node acceptance ref.`);return}let m=e.environment.resolve(f);if(m===void 0||m.family!=="node"){e.add("PL_USE",i,`input.${r} ref ${Be(f)} does not resolve as an allowed Node Definition.`,Be(f));return}d.push(Ep(f))}return d}function Bu(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)?e:void 0}function C$(e){return["allOf","anyOf","oneOf","not","if","then","else"].some((t)=>Object.hasOwn(e,t))}function W2(e){let t=Bu(e);return t!==void 0&&typeof t.origin==="string"&&(t.kind==="class"||t.kind==="interface")&&typeof t.name==="string"}function Y2(e){return"allOf"in e?{key:"allOf",values:e.allOf}:{key:"anyOf",values:e.anyOf}}function hu(e){return{origin:U2,kind:"class",name:e}}function I$(e,t){let r=new Yv(e,t);d$(r),o$(r);let i=new cx(r);return i.validatePolicies(),b$(r,i),E$(r,i),v$(r,i),Object.freeze(r.diagnostics)}function O$(e,t,r,i){let n=[];return Pr(e,(o)=>{if(!ye(o.schema)||!Object.hasOwn(o.schema,"x-astrale-path"))return;let s=`${r}${o.pointer}/x-astrale-path`,a=lu(`#${o.pointer}`),c=a?.length===2&&a[0]==="properties"?a[1]:void 0,u=ye(e)?e:void 0;if(!(t==="callable-input"&&u?.type==="object"&&o.depth===1&&o.parentKeyword==="properties"&&c!==void 0&&Array.isArray(u?.required)&&u.required.includes(c)))n.push(_("VS_PATH_EXTENSION",s,"x-astrale-path is allowed only on a direct required property schema at a callable-input object root."));if(Object.keys(o.schema).length!==2||!Object.hasOwn(o.schema,"$ref")||o.schema.$ref!==jt)n.push(_("VS_PATH_EXTENSION",`${r}${o.pointer}`,`A Path field schema contains exactly $ref ${jt} and x-astrale-path.`,jt));let f=o.schema["x-astrale-path"];if(!ye(f)){n.push(_("VS_PATH_EXTENSION",s,"x-astrale-path must be a closed annotation object."));return}if(!D$(f,["target","cardinality","accepts"]))n.push(_("VS_PATH_EXTENSION",s,"x-astrale-path contains exactly target, cardinality, and accepts."));if(f.target!=="node"||f.cardinality!=="one")n.push(_("VS_PATH_EXTENSION",s,"A V1 Path field resolves exactly one Node."));if(!Array.isArray(f.accepts)||f.accepts.length===0){n.push(_("VS_PATH_EXTENSION",`${s}/accepts`,"x-astrale-path.accepts must be a non-empty Node Definition ref set."));return}let m=new Set;f.accepts.forEach((B,h)=>{let g=`${s}/accepts/${h}`;if(!Q2(B)){n.push(_("VS_PATH_EXTENSION",g,"Path acceptance entries are exact node-family class or interface refs."));return}let w=Q(B);if(m.has(w))n.push(_("VS_PATH_EXTENSION",g,"x-astrale-path.accepts rejects duplicate Definition refs."));if(m.add(w),!i(B))n.push(_("VS_REFERENCE_RESOLUTION",g,"Path acceptance Definition is absent from the current/direct exact registry."))})}),n}function Q2(e){return ye(e)&&D$(e,["origin","kind","name"])&&typeof e.origin==="string"&&kr.test(e.origin)&&(e.kind==="interface"||e.kind==="class")&&typeof e.name==="string"&&Sr.test(e.name)}function D$(e,t){return Object.keys(e).length===t.length&&t.every((i)=>Object.hasOwn(e,i))}var X2=new Set(["$defs","allOf","anyOf","dependentSchemas","else","if","not","oneOf","then"]);function _$(e,t){let r=new Map,i=new Map;for(let s of e.values())Pr(s.schema,(a)=>{let c=yr(s.key,a.pointer);i.set(c,`${s.diagnosticPointer??""}${a.pointer}`);let u=r.get(c)??new Set;if(r.set(c,u),!ye(a.schema))return;let l=t.get(c);if(l!==void 0)u.add(yr(l.resource.key,l.pointer));for(let[d,f]of Object.entries(a.schema)){if(!X2.has(d))continue;let m=It(a.pointer,d);if(Vi.has(d)&&jo(f)){u.add(yr(s.key,m));continue}if(Gi.has(d)&&Array.isArray(f)){f.forEach((B,h)=>{if(jo(B))u.add(yr(s.key,It(m,h)))});continue}if(Hi.has(d)&&ye(f)){for(let[B,h]of Object.entries(f))if(jo(h))u.add(yr(s.key,It(m,B)))}}});let n=new Set,o=new Set;for(let s of r.keys()){let a=k$(s,r,n,o);if(a!==void 0)return[_("VS_RECURSION_PRODUCTIVE",i.get(a)??"","Every recursive cycle must cross an instance-consuming schema edge.")]}return[]}function k$(e,t,r,i){if(r.has(e))return e;if(i.has(e))return;r.add(e);for(let n of t.get(e)??[]){let o=k$(n,t,r,i);if(o!==void 0)return o}r.delete(e),i.add(e);return}var A$=vp;var e6={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/schema",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/core":!0,"https://json-schema.org/draft/2020-12/vocab/applicator":!0,"https://json-schema.org/draft/2020-12/vocab/unevaluated":!0,"https://json-schema.org/draft/2020-12/vocab/validation":!0,"https://json-schema.org/draft/2020-12/vocab/meta-data":!0,"https://json-schema.org/draft/2020-12/vocab/format-annotation":!0,"https://json-schema.org/draft/2020-12/vocab/content":!0},$dynamicAnchor:"meta",title:"Core and Validation specifications meta-schema",allOf:[{$ref:"meta/core"},{$ref:"meta/applicator"},{$ref:"meta/unevaluated"},{$ref:"meta/validation"},{$ref:"meta/meta-data"},{$ref:"meta/format-annotation"},{$ref:"meta/content"}],type:["object","boolean"],$comment:"This meta-schema also defines keywords that have appeared in previous drafts in order to prevent incompatible extensions as they remain in common use.",properties:{definitions:{$comment:'"definitions" has been replaced by "$defs".',type:"object",additionalProperties:{$dynamicRef:"#meta"},deprecated:!0,default:{}},dependencies:{$comment:'"dependencies" has been split and replaced by "dependentSchemas" and "dependentRequired" in order to serve their differing semantics.',type:"object",additionalProperties:{anyOf:[{$dynamicRef:"#meta"},{$ref:"meta/validation#/$defs/stringArray"}]},deprecated:!0,default:{}},$recursiveAnchor:{$comment:'"$recursiveAnchor" has been replaced by "$dynamicAnchor".',$ref:"meta/core#/$defs/anchorString",deprecated:!0},$recursiveRef:{$comment:'"$recursiveRef" has been replaced by "$dynamicRef".',$ref:"meta/core#/$defs/uriReferenceString",deprecated:!0}}};var t6={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/core",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/core":!0},$dynamicAnchor:"meta",title:"Core vocabulary meta-schema",type:["object","boolean"],properties:{$id:{$ref:"#/$defs/uriReferenceString",$comment:"Non-empty fragments not allowed.",pattern:"^[^#]*#?$"},$schema:{$ref:"#/$defs/uriString"},$ref:{$ref:"#/$defs/uriReferenceString"},$anchor:{$ref:"#/$defs/anchorString"},$dynamicRef:{$ref:"#/$defs/uriReferenceString"},$dynamicAnchor:{$ref:"#/$defs/anchorString"},$vocabulary:{type:"object",propertyNames:{$ref:"#/$defs/uriString"},additionalProperties:{type:"boolean"}},$comment:{type:"string"},$defs:{type:"object",additionalProperties:{$dynamicRef:"#meta"}}},$defs:{anchorString:{type:"string",pattern:"^[A-Za-z_][-A-Za-z0-9._]*$"},uriString:{type:"string",format:"uri"},uriReferenceString:{type:"string",format:"uri-reference"}}};var r6=new RegExp("^[^#]*#?$","u"),ux=new RegExp("^[A-Za-z_][-A-Za-z0-9._]*$","u");function tn(e,{instancePath:t="",parentData:r,parentDataProperty:i,rootData:n=e,dynamicAnchors:o={}}={}){let s=null,a=0,c=tn.evaluated;if(c.dynamicProps)c.props=void 0;if(c.dynamicItems)c.items=void 0;if(!(e&&typeof e=="object"&&!Array.isArray(e))&&typeof e!=="boolean"){let B={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:t6.type},message:"must be object,boolean"};if(s===null)s=[B];else s.push(B);a++}if(!o.meta)o.meta=tn;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.$id!==void 0){let B=e.$id;if(typeof B!=="string"){let h={instancePath:t+"/$id",schemaPath:"#/$defs/uriReferenceString/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[h];else s.push(h);a++}if(typeof B==="string"){if(!r6.test(B)){let h={instancePath:t+"/$id",schemaPath:"#/properties/%24id/pattern",keyword:"pattern",params:{pattern:"^[^#]*#?$"},message:'must match pattern "^[^#]*#?$"'};if(s===null)s=[h];else s.push(h);a++}}}if(e.$schema!==void 0){if(typeof e.$schema!=="string"){let B={instancePath:t+"/$schema",schemaPath:"#/$defs/uriString/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[B];else s.push(B);a++}}if(e.$ref!==void 0){if(typeof e.$ref!=="string"){let B={instancePath:t+"/$ref",schemaPath:"#/$defs/uriReferenceString/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[B];else s.push(B);a++}}if(e.$anchor!==void 0){let B=e.$anchor;if(typeof B==="string"){if(!ux.test(B)){let h={instancePath:t+"/$anchor",schemaPath:"#/$defs/anchorString/pattern",keyword:"pattern",params:{pattern:"^[A-Za-z_][-A-Za-z0-9._]*$"},message:'must match pattern "^[A-Za-z_][-A-Za-z0-9._]*$"'};if(s===null)s=[h];else s.push(h);a++}}else{let h={instancePath:t+"/$anchor",schemaPath:"#/$defs/anchorString/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[h];else s.push(h);a++}}if(e.$dynamicRef!==void 0){if(typeof e.$dynamicRef!=="string"){let B={instancePath:t+"/$dynamicRef",schemaPath:"#/$defs/uriReferenceString/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[B];else s.push(B);a++}}if(e.$dynamicAnchor!==void 0){let B=e.$dynamicAnchor;if(typeof B==="string"){if(!ux.test(B)){let h={instancePath:t+"/$dynamicAnchor",schemaPath:"#/$defs/anchorString/pattern",keyword:"pattern",params:{pattern:"^[A-Za-z_][-A-Za-z0-9._]*$"},message:'must match pattern "^[A-Za-z_][-A-Za-z0-9._]*$"'};if(s===null)s=[h];else s.push(h);a++}}else{let h={instancePath:t+"/$dynamicAnchor",schemaPath:"#/$defs/anchorString/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[h];else s.push(h);a++}}if(e.$vocabulary!==void 0){let B=e.$vocabulary;if(B&&typeof B=="object"&&!Array.isArray(B)){for(let h in B){let g=a;if(typeof h!=="string"){let w={instancePath:t+"/$vocabulary",schemaPath:"#/$defs/uriString/type",keyword:"type",params:{type:"string"},message:"must be string",propertyName:h};if(s===null)s=[w];else s.push(w);a++}var u=g===a;if(!u){let w={instancePath:t+"/$vocabulary",schemaPath:"#/properties/%24vocabulary/propertyNames",keyword:"propertyNames",params:{propertyName:h},message:"property name must be valid"};if(s===null)s=[w];else s.push(w);a++}}for(let h in B)if(typeof B[h]!=="boolean"){let g={instancePath:t+"/$vocabulary/"+h.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/%24vocabulary/additionalProperties/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};if(s===null)s=[g];else s.push(g);a++}}else{let h={instancePath:t+"/$vocabulary",schemaPath:"#/properties/%24vocabulary/type",keyword:"type",params:{type:"object"},message:"must be object"};if(s===null)s=[h];else s.push(h);a++}}if(e.$comment!==void 0){if(typeof e.$comment!=="string"){let B={instancePath:t+"/$comment",schemaPath:"#/properties/%24comment/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[B];else s.push(B);a++}}if(e.$defs!==void 0){let B=e.$defs;if(B&&typeof B=="object"&&!Array.isArray(B))for(let h in B){let g=B[h],w=o.meta;if(w)if(!w(g,{instancePath:t+"/$defs/"+h.replace(/~/g,"~0").replace(/\//g,"~1"),parentData:B,parentDataProperty:h,rootData:n,dynamicAnchors:o}))s=s===null?w.errors:s.concat(w.errors),a=s.length;else var l=w.evaluated.props,d=w.evaluated.items;else if(!tn(g,{instancePath:t+"/$defs/"+h.replace(/~/g,"~0").replace(/\//g,"~1"),parentData:B,parentDataProperty:h,rootData:n,dynamicAnchors:o}))s=s===null?tn.errors:s.concat(tn.errors),a=s.length;else{var f=tn.evaluated.props;if(l!==!0&&f!==void 0)if(f===!0)l=!0;else l=l||{},Object.assign(l,f);var m=tn.evaluated.items;if(d!==!0&&m!==void 0)d=m===!0?!0:d>m?d:m}}else{let h={instancePath:t+"/$defs",schemaPath:"#/properties/%24defs/type",keyword:"type",params:{type:"object"},message:"must be object"};if(s===null)s=[h];else s.push(h);a++}}}return tn.errors=s,a===0}tn.evaluated={props:{$id:!0,$schema:!0,$ref:!0,$anchor:!0,$dynamicRef:!0,$dynamicAnchor:!0,$vocabulary:!0,$comment:!0,$defs:!0},dynamicProps:!1,dynamicItems:!1};var n6={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/applicator",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/applicator":!0},$dynamicAnchor:"meta",title:"Applicator vocabulary meta-schema",type:["object","boolean"],properties:{prefixItems:{$ref:"#/$defs/schemaArray"},items:{$dynamicRef:"#meta"},contains:{$dynamicRef:"#meta"},additionalProperties:{$dynamicRef:"#meta"},properties:{type:"object",additionalProperties:{$dynamicRef:"#meta"},default:{}},patternProperties:{type:"object",additionalProperties:{$dynamicRef:"#meta"},propertyNames:{format:"regex"},default:{}},dependentSchemas:{type:"object",additionalProperties:{$dynamicRef:"#meta"},default:{}},propertyNames:{$dynamicRef:"#meta"},if:{$dynamicRef:"#meta"},then:{$dynamicRef:"#meta"},else:{$dynamicRef:"#meta"},allOf:{$ref:"#/$defs/schemaArray"},anyOf:{$ref:"#/$defs/schemaArray"},oneOf:{$ref:"#/$defs/schemaArray"},not:{$dynamicRef:"#meta"}},$defs:{schemaArray:{type:"array",minItems:1,items:{$dynamicRef:"#meta"}}}};function St(e,{instancePath:t="",parentData:r,parentDataProperty:i,rootData:n=e,dynamicAnchors:o={}}={}){let s=null,a=0,c=St.evaluated;if(c.dynamicProps)c.props=void 0;if(c.dynamicItems)c.items=void 0;if(Array.isArray(e)){if(e.length<1){let B={instancePath:t,schemaPath:"#/minItems",keyword:"minItems",params:{limit:1},message:"must NOT have fewer than 1 items"};if(s===null)s=[B];else s.push(B);a++}let m=e.length;for(let B=0;B<m;B++){let h=e[B],g=o.meta;if(g)if(!g(h,{instancePath:t+"/"+B,parentData:e,parentDataProperty:B,rootData:n,dynamicAnchors:o}))s=s===null?g.errors:s.concat(g.errors),a=s.length;else var u=g.evaluated.props,l=g.evaluated.items;else if(!St(h,{instancePath:t+"/"+B,parentData:e,parentDataProperty:B,rootData:n,dynamicAnchors:o}))s=s===null?St.errors:s.concat(St.errors),a=s.length;else{var d=St.evaluated.props;if(u!==!0&&d!==void 0)if(d===!0)u=!0;else u=u||{},Object.assign(u,d);var f=St.evaluated.items;if(l!==!0&&f!==void 0)l=f===!0?!0:l>f?l:f}}}else{let m={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"array"},message:"must be array"};if(s===null)s=[m];else s.push(m);a++}return St.errors=s,a===0}St.evaluated={items:!0,dynamicProps:!1,dynamicItems:!1};function ae(e,{instancePath:t="",parentData:r,parentDataProperty:i,rootData:n=e,dynamicAnchors:o={}}={}){let s=null,a=0,c=ae.evaluated;if(c.dynamicProps)c.props=void 0;if(c.dynamicItems)c.items=void 0;if(!(e&&typeof e=="object"&&!Array.isArray(e))&&typeof e!=="boolean"){let Ce={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:n6.type},message:"must be object,boolean"};if(s===null)s=[Ce];else s.push(Ce);a++}if(!o.meta)o.meta=ae;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.prefixItems!==void 0){if(!St(e.prefixItems,{instancePath:t+"/prefixItems",parentData:e,parentDataProperty:"prefixItems",rootData:n,dynamicAnchors:o}))s=s===null?St.errors:s.concat(St.errors),a=s.length}if(e.items!==void 0){let Ce=e.items,J=o.meta;if(J)if(!J(Ce,{instancePath:t+"/items",parentData:e,parentDataProperty:"items",rootData:n,dynamicAnchors:o}))s=s===null?J.errors:s.concat(J.errors),a=s.length;else var u=J.evaluated.props,l=J.evaluated.items;else if(!ae(Ce,{instancePath:t+"/items",parentData:e,parentDataProperty:"items",rootData:n,dynamicAnchors:o}))s=s===null?ae.errors:s.concat(ae.errors),a=s.length;else{var d=ae.evaluated.props;if(u!==!0&&d!==void 0)if(d===!0)u=!0;else u=u||{},Object.assign(u,d);var f=ae.evaluated.items;if(l!==!0&&f!==void 0)l=f===!0?!0:l>f?l:f}}if(e.contains!==void 0){let Ce=e.contains,J=o.meta;if(J)if(!J(Ce,{instancePath:t+"/contains",parentData:e,parentDataProperty:"contains",rootData:n,dynamicAnchors:o}))s=s===null?J.errors:s.concat(J.errors),a=s.length;else var m=J.evaluated.props,B=J.evaluated.items;else if(!ae(Ce,{instancePath:t+"/contains",parentData:e,parentDataProperty:"contains",rootData:n,dynamicAnchors:o}))s=s===null?ae.errors:s.concat(ae.errors),a=s.length;else{var h=ae.evaluated.props;if(m!==!0&&h!==void 0)if(h===!0)m=!0;else m=m||{},Object.assign(m,h);var g=ae.evaluated.items;if(B!==!0&&g!==void 0)B=g===!0?!0:B>g?B:g}}if(e.additionalProperties!==void 0){let Ce=e.additionalProperties,J=o.meta;if(J)if(!J(Ce,{instancePath:t+"/additionalProperties",parentData:e,parentDataProperty:"additionalProperties",rootData:n,dynamicAnchors:o}))s=s===null?J.errors:s.concat(J.errors),a=s.length;else var w=J.evaluated.props,b=J.evaluated.items;else if(!ae(Ce,{instancePath:t+"/additionalProperties",parentData:e,parentDataProperty:"additionalProperties",rootData:n,dynamicAnchors:o}))s=s===null?ae.errors:s.concat(ae.errors),a=s.length;else{var O=ae.evaluated.props;if(w!==!0&&O!==void 0)if(O===!0)w=!0;else w=w||{},Object.assign(w,O);var k=ae.evaluated.items;if(b!==!0&&k!==void 0)b=k===!0?!0:b>k?b:k}}if(e.properties!==void 0){let Ce=e.properties;if(Ce&&typeof Ce=="object"&&!Array.isArray(Ce))for(let J in Ce){let Qn=Ce[J],Bt=o.meta;if(Bt)if(!Bt(Qn,{instancePath:t+"/properties/"+J.replace(/~/g,"~0").replace(/\//g,"~1"),parentData:Ce,parentDataProperty:J,rootData:n,dynamicAnchors:o}))s=s===null?Bt.errors:s.concat(Bt.errors),a=s.length;else var G=Bt.evaluated.props,oe=Bt.evaluated.items;else if(!ae(Qn,{instancePath:t+"/properties/"+J.replace(/~/g,"~0").replace(/\//g,"~1"),parentData:Ce,parentDataProperty:J,rootData:n,dynamicAnchors:o}))s=s===null?ae.errors:s.concat(ae.errors),a=s.length;else{var V=ae.evaluated.props;if(G!==!0&&V!==void 0)if(V===!0)G=!0;else G=G||{},Object.assign(G,V);var _e=ae.evaluated.items;if(oe!==!0&&_e!==void 0)oe=_e===!0?!0:oe>_e?oe:_e}}else{let J={instancePath:t+"/properties",schemaPath:"#/properties/properties/type",keyword:"type",params:{type:"object"},message:"must be object"};if(s===null)s=[J];else s.push(J);a++}}if(e.patternProperties!==void 0){let Ce=e.patternProperties;if(Ce&&typeof Ce=="object"&&!Array.isArray(Ce)){for(let J in Ce){var Mt=a===a;if(!Mt){let Bt={instancePath:t+"/patternProperties",schemaPath:"#/properties/patternProperties/propertyNames",keyword:"propertyNames",params:{propertyName:J},message:"property name must be valid"};if(s===null)s=[Bt];else s.push(Bt);a++}}for(let J in Ce){let Qn=Ce[J],Bt=o.meta;if(Bt)if(!Bt(Qn,{instancePath:t+"/patternProperties/"+J.replace(/~/g,"~0").replace(/\//g,"~1"),parentData:Ce,parentDataProperty:J,rootData:n,dynamicAnchors:o}))s=s===null?Bt.errors:s.concat(Bt.errors),a=s.length;else var pt=Bt.evaluated.props,Rt=Bt.evaluated.items;else if(!ae(Qn,{instancePath:t+"/patternProperties/"+J.replace(/~/g,"~0").replace(/\//g,"~1"),parentData:Ce,parentDataProperty:J,rootData:n,dynamicAnchors:o}))s=s===null?ae.errors:s.concat(ae.errors),a=s.length;else{var xr=ae.evaluated.props;if(pt!==!0&&xr!==void 0)if(xr===!0)pt=!0;else pt=pt||{},Object.assign(pt,xr);var D=ae.evaluated.items;if(Rt!==!0&&D!==void 0)Rt=D===!0?!0:Rt>D?Rt:D}}}else{let J={instancePath:t+"/patternProperties",schemaPath:"#/properties/patternProperties/type",keyword:"type",params:{type:"object"},message:"must be object"};if(s===null)s=[J];else s.push(J);a++}}if(e.dependentSchemas!==void 0){let Ce=e.dependentSchemas;if(Ce&&typeof Ce=="object"&&!Array.isArray(Ce))for(let J in Ce){let Qn=Ce[J],Bt=o.meta;if(Bt)if(!Bt(Qn,{instancePath:t+"/dependentSchemas/"+J.replace(/~/g,"~0").replace(/\//g,"~1"),parentData:Ce,parentDataProperty:J,rootData:n,dynamicAnchors:o}))s=s===null?Bt.errors:s.concat(Bt.errors),a=s.length;else var P=Bt.evaluated.props,R=Bt.evaluated.items;else if(!ae(Qn,{instancePath:t+"/dependentSchemas/"+J.replace(/~/g,"~0").replace(/\//g,"~1"),parentData:Ce,parentDataProperty:J,rootData:n,dynamicAnchors:o}))s=s===null?ae.errors:s.concat(ae.errors),a=s.length;else{var F=ae.evaluated.props;if(P!==!0&&F!==void 0)if(F===!0)P=!0;else P=P||{},Object.assign(P,F);var M=ae.evaluated.items;if(R!==!0&&M!==void 0)R=M===!0?!0:R>M?R:M}}else{let J={instancePath:t+"/dependentSchemas",schemaPath:"#/properties/dependentSchemas/type",keyword:"type",params:{type:"object"},message:"must be object"};if(s===null)s=[J];else s.push(J);a++}}if(e.propertyNames!==void 0){let Ce=e.propertyNames,J=o.meta;if(J)if(!J(Ce,{instancePath:t+"/propertyNames",parentData:e,parentDataProperty:"propertyNames",rootData:n,dynamicAnchors:o}))s=s===null?J.errors:s.concat(J.errors),a=s.length;else var de=J.evaluated.props,fe=J.evaluated.items;else if(!ae(Ce,{instancePath:t+"/propertyNames",parentData:e,parentDataProperty:"propertyNames",rootData:n,dynamicAnchors:o}))s=s===null?ae.errors:s.concat(ae.errors),a=s.length;else{var le=ae.evaluated.props;if(de!==!0&&le!==void 0)if(le===!0)de=!0;else de=de||{},Object.assign(de,le);var Ie=ae.evaluated.items;if(fe!==!0&&Ie!==void 0)fe=Ie===!0?!0:fe>Ie?fe:Ie}}if(e.if!==void 0){let Ce=e.if,J=o.meta;if(J)if(!J(Ce,{instancePath:t+"/if",parentData:e,parentDataProperty:"if",rootData:n,dynamicAnchors:o}))s=s===null?J.errors:s.concat(J.errors),a=s.length;else var Se=J.evaluated.props,wt=J.evaluated.items;else if(!ae(Ce,{instancePath:t+"/if",parentData:e,parentDataProperty:"if",rootData:n,dynamicAnchors:o}))s=s===null?ae.errors:s.concat(ae.errors),a=s.length;else{var rr=ae.evaluated.props;if(Se!==!0&&rr!==void 0)if(rr===!0)Se=!0;else Se=Se||{},Object.assign(Se,rr);var Ht=ae.evaluated.items;if(wt!==!0&&Ht!==void 0)wt=Ht===!0?!0:wt>Ht?wt:Ht}}if(e.then!==void 0){let Ce=e.then,J=o.meta;if(J)if(!J(Ce,{instancePath:t+"/then",parentData:e,parentDataProperty:"then",rootData:n,dynamicAnchors:o}))s=s===null?J.errors:s.concat(J.errors),a=s.length;else var Oi=J.evaluated.props,Di=J.evaluated.items;else if(!ae(Ce,{instancePath:t+"/then",parentData:e,parentDataProperty:"then",rootData:n,dynamicAnchors:o}))s=s===null?ae.errors:s.concat(ae.errors),a=s.length;else{var vs=ae.evaluated.props;if(Oi!==!0&&vs!==void 0)if(vs===!0)Oi=!0;else Oi=Oi||{},Object.assign(Oi,vs);var xs=ae.evaluated.items;if(Di!==!0&&xs!==void 0)Di=xs===!0?!0:Di>xs?Di:xs}}if(e.else!==void 0){let Ce=e.else,J=o.meta;if(J)if(!J(Ce,{instancePath:t+"/else",parentData:e,parentDataProperty:"else",rootData:n,dynamicAnchors:o}))s=s===null?J.errors:s.concat(J.errors),a=s.length;else var yo=J.evaluated.props,ct=J.evaluated.items;else if(!ae(Ce,{instancePath:t+"/else",parentData:e,parentDataProperty:"else",rootData:n,dynamicAnchors:o}))s=s===null?ae.errors:s.concat(ae.errors),a=s.length;else{var Yr=ae.evaluated.props;if(yo!==!0&&Yr!==void 0)if(Yr===!0)yo=!0;else yo=yo||{},Object.assign(yo,Yr);var Hl=ae.evaluated.items;if(ct!==!0&&Hl!==void 0)ct=Hl===!0?!0:ct>Hl?ct:Hl}}if(e.allOf!==void 0){if(!St(e.allOf,{instancePath:t+"/allOf",parentData:e,parentDataProperty:"allOf",rootData:n,dynamicAnchors:o}))s=s===null?St.errors:s.concat(St.errors),a=s.length}if(e.anyOf!==void 0){if(!St(e.anyOf,{instancePath:t+"/anyOf",parentData:e,parentDataProperty:"anyOf",rootData:n,dynamicAnchors:o}))s=s===null?St.errors:s.concat(St.errors),a=s.length}if(e.oneOf!==void 0){if(!St(e.oneOf,{instancePath:t+"/oneOf",parentData:e,parentDataProperty:"oneOf",rootData:n,dynamicAnchors:o}))s=s===null?St.errors:s.concat(St.errors),a=s.length}if(e.not!==void 0){let Ce=e.not,J=o.meta;if(J)if(!J(Ce,{instancePath:t+"/not",parentData:e,parentDataProperty:"not",rootData:n,dynamicAnchors:o}))s=s===null?J.errors:s.concat(J.errors),a=s.length;else var pc=J.evaluated.props,Vl=J.evaluated.items;else if(!ae(Ce,{instancePath:t+"/not",parentData:e,parentDataProperty:"not",rootData:n,dynamicAnchors:o}))s=s===null?ae.errors:s.concat(ae.errors),a=s.length;else{var ih=ae.evaluated.props;if(pc!==!0&&ih!==void 0)if(ih===!0)pc=!0;else pc=pc||{},Object.assign(pc,ih);var ql=ae.evaluated.items;if(Vl!==!0&&ql!==void 0)Vl=ql===!0?!0:Vl>ql?Vl:ql}}}return ae.errors=s,a===0}ae.evaluated={props:{prefixItems:!0,items:!0,contains:!0,additionalProperties:!0,properties:!0,patternProperties:!0,dependentSchemas:!0,propertyNames:!0,if:!0,then:!0,else:!0,allOf:!0,anyOf:!0,oneOf:!0,not:!0},dynamicProps:!1,dynamicItems:!1};var i6={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/unevaluated",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/unevaluated":!0},$dynamicAnchor:"meta",title:"Unevaluated applicator vocabulary meta-schema",type:["object","boolean"],properties:{unevaluatedItems:{$dynamicRef:"#meta"},unevaluatedProperties:{$dynamicRef:"#meta"}}};function Zt(e,{instancePath:t="",parentData:r,parentDataProperty:i,rootData:n=e,dynamicAnchors:o={}}={}){let s=null,a=0,c=Zt.evaluated;if(c.dynamicProps)c.props=void 0;if(c.dynamicItems)c.items=void 0;if(!(e&&typeof e=="object"&&!Array.isArray(e))&&typeof e!=="boolean"){let w={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:i6.type},message:"must be object,boolean"};if(s===null)s=[w];else s.push(w);a++}if(!o.meta)o.meta=Zt;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.unevaluatedItems!==void 0){let w=e.unevaluatedItems,b=o.meta;if(b)if(!b(w,{instancePath:t+"/unevaluatedItems",parentData:e,parentDataProperty:"unevaluatedItems",rootData:n,dynamicAnchors:o}))s=s===null?b.errors:s.concat(b.errors),a=s.length;else var u=b.evaluated.props,l=b.evaluated.items;else if(!Zt(w,{instancePath:t+"/unevaluatedItems",parentData:e,parentDataProperty:"unevaluatedItems",rootData:n,dynamicAnchors:o}))s=s===null?Zt.errors:s.concat(Zt.errors),a=s.length;else{var d=Zt.evaluated.props;if(u!==!0&&d!==void 0)if(d===!0)u=!0;else u=u||{},Object.assign(u,d);var f=Zt.evaluated.items;if(l!==!0&&f!==void 0)l=f===!0?!0:l>f?l:f}}if(e.unevaluatedProperties!==void 0){let w=e.unevaluatedProperties,b=o.meta;if(b)if(!b(w,{instancePath:t+"/unevaluatedProperties",parentData:e,parentDataProperty:"unevaluatedProperties",rootData:n,dynamicAnchors:o}))s=s===null?b.errors:s.concat(b.errors),a=s.length;else var m=b.evaluated.props,B=b.evaluated.items;else if(!Zt(w,{instancePath:t+"/unevaluatedProperties",parentData:e,parentDataProperty:"unevaluatedProperties",rootData:n,dynamicAnchors:o}))s=s===null?Zt.errors:s.concat(Zt.errors),a=s.length;else{var h=Zt.evaluated.props;if(m!==!0&&h!==void 0)if(h===!0)m=!0;else m=m||{},Object.assign(m,h);var g=Zt.evaluated.items;if(B!==!0&&g!==void 0)B=g===!0?!0:B>g?B:g}}}return Zt.errors=s,a===0}Zt.evaluated={props:{unevaluatedItems:!0,unevaluatedProperties:!0},dynamicProps:!1,dynamicItems:!1};var o6={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/validation",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/validation":!0},$dynamicAnchor:"meta",title:"Validation vocabulary meta-schema",type:["object","boolean"],properties:{type:{anyOf:[{$ref:"#/$defs/simpleTypes"},{type:"array",items:{$ref:"#/$defs/simpleTypes"},minItems:1,uniqueItems:!0}]},const:!0,enum:{type:"array",items:!0},multipleOf:{type:"number",exclusiveMinimum:0},maximum:{type:"number"},exclusiveMaximum:{type:"number"},minimum:{type:"number"},exclusiveMinimum:{type:"number"},maxLength:{$ref:"#/$defs/nonNegativeInteger"},minLength:{$ref:"#/$defs/nonNegativeIntegerDefault0"},pattern:{type:"string",format:"regex"},maxItems:{$ref:"#/$defs/nonNegativeInteger"},minItems:{$ref:"#/$defs/nonNegativeIntegerDefault0"},uniqueItems:{type:"boolean",default:!1},maxContains:{$ref:"#/$defs/nonNegativeInteger"},minContains:{$ref:"#/$defs/nonNegativeInteger",default:1},maxProperties:{$ref:"#/$defs/nonNegativeInteger"},minProperties:{$ref:"#/$defs/nonNegativeIntegerDefault0"},required:{$ref:"#/$defs/stringArray"},dependentRequired:{type:"object",additionalProperties:{$ref:"#/$defs/stringArray"}}},$defs:{nonNegativeInteger:{type:"integer",minimum:0},nonNegativeIntegerDefault0:{$ref:"#/$defs/nonNegativeInteger",default:0},simpleTypes:{enum:["array","boolean","integer","null","number","object","string"]},stringArray:{type:"array",items:{type:"string"},uniqueItems:!0,default:[]}}},S$={enum:["array","boolean","integer","null","number","object","string"]};function Fo(e,{instancePath:t="",parentData:r,parentDataProperty:i,rootData:n=e,dynamicAnchors:o={}}={}){let s=null,a=0,c=Fo.evaluated;if(c.dynamicProps)c.props=void 0;if(c.dynamicItems)c.items=void 0;if(!(e&&typeof e=="object"&&!Array.isArray(e))&&typeof e!=="boolean"){let l={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:o6.type},message:"must be object,boolean"};if(s===null)s=[l];else s.push(l);a++}if(!o.meta)o.meta=Fo;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.type!==void 0){let l=e.type,d=a,f=!1,m=a;if(!(l==="array"||l==="boolean"||l==="integer"||l==="null"||l==="number"||l==="object"||l==="string")){let h={instancePath:t+"/type",schemaPath:"#/$defs/simpleTypes/enum",keyword:"enum",params:{allowedValues:S$.enum},message:"must be equal to one of the allowed values"};if(s===null)s=[h];else s.push(h);a++}var u=m===a;f=f||u;let B=a;if(Array.isArray(l)){if(l.length<1){let b={instancePath:t+"/type",schemaPath:"#/properties/type/anyOf/1/minItems",keyword:"minItems",params:{limit:1},message:"must NOT have fewer than 1 items"};if(s===null)s=[b];else s.push(b);a++}let h=l.length;for(let b=0;b<h;b++){let O=l[b];if(!(O==="array"||O==="boolean"||O==="integer"||O==="null"||O==="number"||O==="object"||O==="string")){let k={instancePath:t+"/type/"+b,schemaPath:"#/$defs/simpleTypes/enum",keyword:"enum",params:{allowedValues:S$.enum},message:"must be equal to one of the allowed values"};if(s===null)s=[k];else s.push(k);a++}}let g=l.length,w;if(g>1){e:for(;g--;)for(w=g;w--;)if(Nr(l[g],l[w])){let b={instancePath:t+"/type",schemaPath:"#/properties/type/anyOf/1/uniqueItems",keyword:"uniqueItems",params:{i:g,j:w},message:"must NOT have duplicate items (items ## "+w+" and "+g+" are identical)"};if(s===null)s=[b];else s.push(b);a++;break e}}}else{let h={instancePath:t+"/type",schemaPath:"#/properties/type/anyOf/1/type",keyword:"type",params:{type:"array"},message:"must be array"};if(s===null)s=[h];else s.push(h);a++}var u=B===a;if(f=f||u,!f){let h={instancePath:t+"/type",schemaPath:"#/properties/type/anyOf",keyword:"anyOf",params:{},message:"must match a schema in anyOf"};if(s===null)s=[h];else s.push(h);a++}else if(a=d,s!==null)if(d)s.length=d;else s=null}if(e.enum!==void 0){if(!Array.isArray(e.enum)){let l={instancePath:t+"/enum",schemaPath:"#/properties/enum/type",keyword:"type",params:{type:"array"},message:"must be array"};if(s===null)s=[l];else s.push(l);a++}}if(e.multipleOf!==void 0){let l=e.multipleOf;if(typeof l=="number"){if(l<=0||isNaN(l)){let d={instancePath:t+"/multipleOf",schemaPath:"#/properties/multipleOf/exclusiveMinimum",keyword:"exclusiveMinimum",params:{comparison:">",limit:0},message:"must be > 0"};if(s===null)s=[d];else s.push(d);a++}}else{let d={instancePath:t+"/multipleOf",schemaPath:"#/properties/multipleOf/type",keyword:"type",params:{type:"number"},message:"must be number"};if(s===null)s=[d];else s.push(d);a++}}if(e.maximum!==void 0){if(typeof e.maximum!="number"){let l={instancePath:t+"/maximum",schemaPath:"#/properties/maximum/type",keyword:"type",params:{type:"number"},message:"must be number"};if(s===null)s=[l];else s.push(l);a++}}if(e.exclusiveMaximum!==void 0){if(typeof e.exclusiveMaximum!="number"){let l={instancePath:t+"/exclusiveMaximum",schemaPath:"#/properties/exclusiveMaximum/type",keyword:"type",params:{type:"number"},message:"must be number"};if(s===null)s=[l];else s.push(l);a++}}if(e.minimum!==void 0){if(typeof e.minimum!="number"){let l={instancePath:t+"/minimum",schemaPath:"#/properties/minimum/type",keyword:"type",params:{type:"number"},message:"must be number"};if(s===null)s=[l];else s.push(l);a++}}if(e.exclusiveMinimum!==void 0){if(typeof e.exclusiveMinimum!="number"){let l={instancePath:t+"/exclusiveMinimum",schemaPath:"#/properties/exclusiveMinimum/type",keyword:"type",params:{type:"number"},message:"must be number"};if(s===null)s=[l];else s.push(l);a++}}if(e.maxLength!==void 0){let l=e.maxLength;if(!(typeof l=="number"&&(!(l%1)&&!isNaN(l)))){let d={instancePath:t+"/maxLength",schemaPath:"#/$defs/nonNegativeInteger/type",keyword:"type",params:{type:"integer"},message:"must be integer"};if(s===null)s=[d];else s.push(d);a++}if(typeof l=="number"){if(l<0||isNaN(l)){let d={instancePath:t+"/maxLength",schemaPath:"#/$defs/nonNegativeInteger/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};if(s===null)s=[d];else s.push(d);a++}}}if(e.minLength!==void 0){let l=e.minLength;if(!(typeof l=="number"&&(!(l%1)&&!isNaN(l)))){let d={instancePath:t+"/minLength",schemaPath:"#/$defs/nonNegativeIntegerDefault0/type",keyword:"type",params:{type:"integer"},message:"must be integer"};if(s===null)s=[d];else s.push(d);a++}if(typeof l=="number"){if(l<0||isNaN(l)){let d={instancePath:t+"/minLength",schemaPath:"#/$defs/nonNegativeIntegerDefault0/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};if(s===null)s=[d];else s.push(d);a++}}}if(e.pattern!==void 0){if(typeof e.pattern!=="string"){let l={instancePath:t+"/pattern",schemaPath:"#/properties/pattern/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[l];else s.push(l);a++}}if(e.maxItems!==void 0){let l=e.maxItems;if(!(typeof l=="number"&&(!(l%1)&&!isNaN(l)))){let d={instancePath:t+"/maxItems",schemaPath:"#/$defs/nonNegativeInteger/type",keyword:"type",params:{type:"integer"},message:"must be integer"};if(s===null)s=[d];else s.push(d);a++}if(typeof l=="number"){if(l<0||isNaN(l)){let d={instancePath:t+"/maxItems",schemaPath:"#/$defs/nonNegativeInteger/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};if(s===null)s=[d];else s.push(d);a++}}}if(e.minItems!==void 0){let l=e.minItems;if(!(typeof l=="number"&&(!(l%1)&&!isNaN(l)))){let d={instancePath:t+"/minItems",schemaPath:"#/$defs/nonNegativeIntegerDefault0/type",keyword:"type",params:{type:"integer"},message:"must be integer"};if(s===null)s=[d];else s.push(d);a++}if(typeof l=="number"){if(l<0||isNaN(l)){let d={instancePath:t+"/minItems",schemaPath:"#/$defs/nonNegativeIntegerDefault0/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};if(s===null)s=[d];else s.push(d);a++}}}if(e.uniqueItems!==void 0){if(typeof e.uniqueItems!=="boolean"){let l={instancePath:t+"/uniqueItems",schemaPath:"#/properties/uniqueItems/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};if(s===null)s=[l];else s.push(l);a++}}if(e.maxContains!==void 0){let l=e.maxContains;if(!(typeof l=="number"&&(!(l%1)&&!isNaN(l)))){let d={instancePath:t+"/maxContains",schemaPath:"#/$defs/nonNegativeInteger/type",keyword:"type",params:{type:"integer"},message:"must be integer"};if(s===null)s=[d];else s.push(d);a++}if(typeof l=="number"){if(l<0||isNaN(l)){let d={instancePath:t+"/maxContains",schemaPath:"#/$defs/nonNegativeInteger/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};if(s===null)s=[d];else s.push(d);a++}}}if(e.minContains!==void 0){let l=e.minContains;if(!(typeof l=="number"&&(!(l%1)&&!isNaN(l)))){let d={instancePath:t+"/minContains",schemaPath:"#/$defs/nonNegativeInteger/type",keyword:"type",params:{type:"integer"},message:"must be integer"};if(s===null)s=[d];else s.push(d);a++}if(typeof l=="number"){if(l<0||isNaN(l)){let d={instancePath:t+"/minContains",schemaPath:"#/$defs/nonNegativeInteger/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};if(s===null)s=[d];else s.push(d);a++}}}if(e.maxProperties!==void 0){let l=e.maxProperties;if(!(typeof l=="number"&&(!(l%1)&&!isNaN(l)))){let d={instancePath:t+"/maxProperties",schemaPath:"#/$defs/nonNegativeInteger/type",keyword:"type",params:{type:"integer"},message:"must be integer"};if(s===null)s=[d];else s.push(d);a++}if(typeof l=="number"){if(l<0||isNaN(l)){let d={instancePath:t+"/maxProperties",schemaPath:"#/$defs/nonNegativeInteger/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};if(s===null)s=[d];else s.push(d);a++}}}if(e.minProperties!==void 0){let l=e.minProperties;if(!(typeof l=="number"&&(!(l%1)&&!isNaN(l)))){let d={instancePath:t+"/minProperties",schemaPath:"#/$defs/nonNegativeIntegerDefault0/type",keyword:"type",params:{type:"integer"},message:"must be integer"};if(s===null)s=[d];else s.push(d);a++}if(typeof l=="number"){if(l<0||isNaN(l)){let d={instancePath:t+"/minProperties",schemaPath:"#/$defs/nonNegativeIntegerDefault0/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};if(s===null)s=[d];else s.push(d);a++}}}if(e.required!==void 0){let l=e.required;if(Array.isArray(l)){let d=l.length;for(let B=0;B<d;B++)if(typeof l[B]!=="string"){let h={instancePath:t+"/required/"+B,schemaPath:"#/$defs/stringArray/items/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[h];else s.push(h);a++}let f=l.length,m;if(f>1){let B={};for(;f--;){let h=l[f];if(typeof h!=="string")continue;if(typeof B[h]=="number"){m=B[h];let g={instancePath:t+"/required",schemaPath:"#/$defs/stringArray/uniqueItems",keyword:"uniqueItems",params:{i:f,j:m},message:"must NOT have duplicate items (items ## "+m+" and "+f+" are identical)"};if(s===null)s=[g];else s.push(g);a++;break}B[h]=f}}}else{let d={instancePath:t+"/required",schemaPath:"#/$defs/stringArray/type",keyword:"type",params:{type:"array"},message:"must be array"};if(s===null)s=[d];else s.push(d);a++}}if(e.dependentRequired!==void 0){let l=e.dependentRequired;if(l&&typeof l=="object"&&!Array.isArray(l))for(let d in l){let f=l[d];if(Array.isArray(f)){let m=f.length;for(let g=0;g<m;g++)if(typeof f[g]!=="string"){let w={instancePath:t+"/dependentRequired/"+d.replace(/~/g,"~0").replace(/\//g,"~1")+"/"+g,schemaPath:"#/$defs/stringArray/items/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[w];else s.push(w);a++}let B=f.length,h;if(B>1){let g={};for(;B--;){let w=f[B];if(typeof w!=="string")continue;if(typeof g[w]=="number"){h=g[w];let b={instancePath:t+"/dependentRequired/"+d.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/$defs/stringArray/uniqueItems",keyword:"uniqueItems",params:{i:B,j:h},message:"must NOT have duplicate items (items ## "+h+" and "+B+" are identical)"};if(s===null)s=[b];else s.push(b);a++;break}g[w]=B}}}else{let m={instancePath:t+"/dependentRequired/"+d.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/$defs/stringArray/type",keyword:"type",params:{type:"array"},message:"must be array"};if(s===null)s=[m];else s.push(m);a++}}else{let d={instancePath:t+"/dependentRequired",schemaPath:"#/properties/dependentRequired/type",keyword:"type",params:{type:"object"},message:"must be object"};if(s===null)s=[d];else s.push(d);a++}}}return Fo.errors=s,a===0}Fo.evaluated={props:{type:!0,const:!0,enum:!0,multipleOf:!0,maximum:!0,exclusiveMaximum:!0,minimum:!0,exclusiveMinimum:!0,maxLength:!0,minLength:!0,pattern:!0,maxItems:!0,minItems:!0,uniqueItems:!0,maxContains:!0,minContains:!0,maxProperties:!0,minProperties:!0,required:!0,dependentRequired:!0},dynamicProps:!1,dynamicItems:!1};var s6={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/meta-data",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/meta-data":!0},$dynamicAnchor:"meta",title:"Meta-data vocabulary meta-schema",type:["object","boolean"],properties:{title:{type:"string"},description:{type:"string"},default:!0,deprecated:{type:"boolean",default:!1},readOnly:{type:"boolean",default:!1},writeOnly:{type:"boolean",default:!1},examples:{type:"array",items:!0}}};function Go(e,{instancePath:t="",parentData:r,parentDataProperty:i,rootData:n=e,dynamicAnchors:o={}}={}){let s=null,a=0,c=Go.evaluated;if(c.dynamicProps)c.props=void 0;if(c.dynamicItems)c.items=void 0;if(!(e&&typeof e=="object"&&!Array.isArray(e))&&typeof e!=="boolean"){let u={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:s6.type},message:"must be object,boolean"};if(s===null)s=[u];else s.push(u);a++}if(!o.meta)o.meta=Go;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.title!==void 0){if(typeof e.title!=="string"){let u={instancePath:t+"/title",schemaPath:"#/properties/title/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[u];else s.push(u);a++}}if(e.description!==void 0){if(typeof e.description!=="string"){let u={instancePath:t+"/description",schemaPath:"#/properties/description/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[u];else s.push(u);a++}}if(e.deprecated!==void 0){if(typeof e.deprecated!=="boolean"){let u={instancePath:t+"/deprecated",schemaPath:"#/properties/deprecated/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};if(s===null)s=[u];else s.push(u);a++}}if(e.readOnly!==void 0){if(typeof e.readOnly!=="boolean"){let u={instancePath:t+"/readOnly",schemaPath:"#/properties/readOnly/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};if(s===null)s=[u];else s.push(u);a++}}if(e.writeOnly!==void 0){if(typeof e.writeOnly!=="boolean"){let u={instancePath:t+"/writeOnly",schemaPath:"#/properties/writeOnly/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};if(s===null)s=[u];else s.push(u);a++}}if(e.examples!==void 0){if(!Array.isArray(e.examples)){let u={instancePath:t+"/examples",schemaPath:"#/properties/examples/type",keyword:"type",params:{type:"array"},message:"must be array"};if(s===null)s=[u];else s.push(u);a++}}}return Go.errors=s,a===0}Go.evaluated={props:{title:!0,description:!0,default:!0,deprecated:!0,readOnly:!0,writeOnly:!0,examples:!0},dynamicProps:!1,dynamicItems:!1};var a6={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/format-annotation",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/format-annotation":!0},$dynamicAnchor:"meta",title:"Format vocabulary meta-schema for annotation results",type:["object","boolean"],properties:{format:{type:"string"}}};function Ho(e,{instancePath:t="",parentData:r,parentDataProperty:i,rootData:n=e,dynamicAnchors:o={}}={}){let s=null,a=0,c=Ho.evaluated;if(c.dynamicProps)c.props=void 0;if(c.dynamicItems)c.items=void 0;if(!(e&&typeof e=="object"&&!Array.isArray(e))&&typeof e!=="boolean"){let u={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:a6.type},message:"must be object,boolean"};if(s===null)s=[u];else s.push(u);a++}if(!o.meta)o.meta=Ho;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.format!==void 0){if(typeof e.format!=="string"){let u={instancePath:t+"/format",schemaPath:"#/properties/format/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[u];else s.push(u);a++}}}return Ho.errors=s,a===0}Ho.evaluated={props:{format:!0},dynamicProps:!1,dynamicItems:!1};var c6={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/content",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/content":!0},$dynamicAnchor:"meta",title:"Content vocabulary meta-schema",type:["object","boolean"],properties:{contentEncoding:{type:"string"},contentMediaType:{type:"string"},contentSchema:{$dynamicRef:"#meta"}}};function rn(e,{instancePath:t="",parentData:r,parentDataProperty:i,rootData:n=e,dynamicAnchors:o={}}={}){let s=null,a=0,c=rn.evaluated;if(c.dynamicProps)c.props=void 0;if(c.dynamicItems)c.items=void 0;if(!(e&&typeof e=="object"&&!Array.isArray(e))&&typeof e!=="boolean"){let m={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:c6.type},message:"must be object,boolean"};if(s===null)s=[m];else s.push(m);a++}if(!o.meta)o.meta=rn;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.contentEncoding!==void 0){if(typeof e.contentEncoding!=="string"){let m={instancePath:t+"/contentEncoding",schemaPath:"#/properties/contentEncoding/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[m];else s.push(m);a++}}if(e.contentMediaType!==void 0){if(typeof e.contentMediaType!=="string"){let m={instancePath:t+"/contentMediaType",schemaPath:"#/properties/contentMediaType/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[m];else s.push(m);a++}}if(e.contentSchema!==void 0){let m=e.contentSchema,B=o.meta;if(B)if(!B(m,{instancePath:t+"/contentSchema",parentData:e,parentDataProperty:"contentSchema",rootData:n,dynamicAnchors:o}))s=s===null?B.errors:s.concat(B.errors),a=s.length;else var u=B.evaluated.props,l=B.evaluated.items;else if(!rn(m,{instancePath:t+"/contentSchema",parentData:e,parentDataProperty:"contentSchema",rootData:n,dynamicAnchors:o}))s=s===null?rn.errors:s.concat(rn.errors),a=s.length;else{var d=rn.evaluated.props;if(u!==!0&&d!==void 0)if(d===!0)u=!0;else u=u||{},Object.assign(u,d);var f=rn.evaluated.items;if(l!==!0&&f!==void 0)l=f===!0?!0:l>f?l:f}}}return rn.errors=s,a===0}rn.evaluated={props:{contentEncoding:!0,contentMediaType:!0,contentSchema:!0},dynamicProps:!1,dynamicItems:!1};function Wt(e,{instancePath:t="",parentData:r,parentDataProperty:i,rootData:n=e,dynamicAnchors:o={}}={}){let s=null,a=0,c=Wt.evaluated;if(c.dynamicProps)c.props=void 0;if(c.dynamicItems)c.items=void 0;if(!(e&&typeof e=="object"&&!Array.isArray(e))&&typeof e!=="boolean"){let b={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:e6.type},message:"must be object,boolean"};if(s===null)s=[b];else s.push(b);a++}if(!o.meta)o.meta=Wt;if(!tn(e,{instancePath:t,parentData:r,parentDataProperty:i,rootData:n,dynamicAnchors:o}))s=s===null?tn.errors:s.concat(tn.errors),a=s.length;if(!ae(e,{instancePath:t,parentData:r,parentDataProperty:i,rootData:n,dynamicAnchors:o}))s=s===null?ae.errors:s.concat(ae.errors),a=s.length;if(!Zt(e,{instancePath:t,parentData:r,parentDataProperty:i,rootData:n,dynamicAnchors:o}))s=s===null?Zt.errors:s.concat(Zt.errors),a=s.length;if(!Fo(e,{instancePath:t,parentData:r,parentDataProperty:i,rootData:n,dynamicAnchors:o}))s=s===null?Fo.errors:s.concat(Fo.errors),a=s.length;if(!Go(e,{instancePath:t,parentData:r,parentDataProperty:i,rootData:n,dynamicAnchors:o}))s=s===null?Go.errors:s.concat(Go.errors),a=s.length;if(!Ho(e,{instancePath:t,parentData:r,parentDataProperty:i,rootData:n,dynamicAnchors:o}))s=s===null?Ho.errors:s.concat(Ho.errors),a=s.length;if(!rn(e,{instancePath:t,parentData:r,parentDataProperty:i,rootData:n,dynamicAnchors:o}))s=s===null?rn.errors:s.concat(rn.errors),a=s.length;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.definitions!==void 0){let b=e.definitions;if(b&&typeof b=="object"&&!Array.isArray(b))for(let O in b){let k=b[O],G=o.meta;if(G)if(!G(k,{instancePath:t+"/definitions/"+O.replace(/~/g,"~0").replace(/\//g,"~1"),parentData:b,parentDataProperty:O,rootData:n,dynamicAnchors:o}))s=s===null?G.errors:s.concat(G.errors),a=s.length;else var u=G.evaluated.props,l=G.evaluated.items;else if(!Wt(k,{instancePath:t+"/definitions/"+O.replace(/~/g,"~0").replace(/\//g,"~1"),parentData:b,parentDataProperty:O,rootData:n,dynamicAnchors:o}))s=s===null?Wt.errors:s.concat(Wt.errors),a=s.length;else{var d=Wt.evaluated.props;if(u!==!0&&d!==void 0)if(d===!0)u=!0;else u=u||{},Object.assign(u,d);var f=Wt.evaluated.items;if(l!==!0&&f!==void 0)l=f===!0?!0:l>f?l:f}}else{let O={instancePath:t+"/definitions",schemaPath:"#/properties/definitions/type",keyword:"type",params:{type:"object"},message:"must be object"};if(s===null)s=[O];else s.push(O);a++}}if(e.dependencies!==void 0){let b=e.dependencies;if(b&&typeof b=="object"&&!Array.isArray(b))for(let O in b){let k=b[O],G=a,oe=!1,V=a,_e=o.meta;if(_e)if(!_e(k,{instancePath:t+"/dependencies/"+O.replace(/~/g,"~0").replace(/\//g,"~1"),parentData:b,parentDataProperty:O,rootData:n,dynamicAnchors:o}))s=s===null?_e.errors:s.concat(_e.errors),a=s.length;else var m=_e.evaluated.props,B=_e.evaluated.items;else if(!Wt(k,{instancePath:t+"/dependencies/"+O.replace(/~/g,"~0").replace(/\//g,"~1"),parentData:b,parentDataProperty:O,rootData:n,dynamicAnchors:o}))s=s===null?Wt.errors:s.concat(Wt.errors),a=s.length;else{var h=Wt.evaluated.props;if(m!==!0&&h!==void 0)if(h===!0)m=!0;else m=m||{},Object.assign(m,h);var g=Wt.evaluated.items;if(B!==!0&&g!==void 0)B=g===!0?!0:B>g?B:g}var w=V===a;oe=oe||w;let Mt=a;if(Array.isArray(k)){let pt=k.length;for(let D=0;D<pt;D++)if(typeof k[D]!=="string"){let P={instancePath:t+"/dependencies/"+O.replace(/~/g,"~0").replace(/\//g,"~1")+"/"+D,schemaPath:"meta/validation#/$defs/stringArray/items/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[P];else s.push(P);a++}let Rt=k.length,xr;if(Rt>1){let D={};for(;Rt--;){let P=k[Rt];if(typeof P!=="string")continue;if(typeof D[P]=="number"){xr=D[P];let R={instancePath:t+"/dependencies/"+O.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"meta/validation#/$defs/stringArray/uniqueItems",keyword:"uniqueItems",params:{i:Rt,j:xr},message:"must NOT have duplicate items (items ## "+xr+" and "+Rt+" are identical)"};if(s===null)s=[R];else s.push(R);a++;break}D[P]=Rt}}}else{let pt={instancePath:t+"/dependencies/"+O.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"meta/validation#/$defs/stringArray/type",keyword:"type",params:{type:"array"},message:"must be array"};if(s===null)s=[pt];else s.push(pt);a++}var w=Mt===a;if(oe=oe||w,w){if(B!==!0)B=!0}if(!oe){let pt={instancePath:t+"/dependencies/"+O.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/dependencies/additionalProperties/anyOf",keyword:"anyOf",params:{},message:"must match a schema in anyOf"};if(s===null)s=[pt];else s.push(pt);a++}else if(a=G,s!==null)if(G)s.length=G;else s=null}else{let O={instancePath:t+"/dependencies",schemaPath:"#/properties/dependencies/type",keyword:"type",params:{type:"object"},message:"must be object"};if(s===null)s=[O];else s.push(O);a++}}if(e.$recursiveAnchor!==void 0){let b=e.$recursiveAnchor;if(typeof b==="string"){if(!ux.test(b)){let O={instancePath:t+"/$recursiveAnchor",schemaPath:"meta/core#/$defs/anchorString/pattern",keyword:"pattern",params:{pattern:"^[A-Za-z_][-A-Za-z0-9._]*$"},message:'must match pattern "^[A-Za-z_][-A-Za-z0-9._]*$"'};if(s===null)s=[O];else s.push(O);a++}}else{let O={instancePath:t+"/$recursiveAnchor",schemaPath:"meta/core#/$defs/anchorString/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[O];else s.push(O);a++}}if(e.$recursiveRef!==void 0){if(typeof e.$recursiveRef!=="string"){let b={instancePath:t+"/$recursiveRef",schemaPath:"meta/core#/$defs/uriReferenceString/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[b];else s.push(b);a++}}}return Wt.errors=s,a===0}Wt.evaluated={props:{definitions:!0,dependencies:!0,$recursiveAnchor:!0,$recursiveRef:!0,contentEncoding:!0,contentMediaType:!0,contentSchema:!0,format:!0,title:!0,description:!0,default:!0,deprecated:!0,readOnly:!0,writeOnly:!0,examples:!0,type:!0,const:!0,enum:!0,multipleOf:!0,maximum:!0,exclusiveMaximum:!0,minimum:!0,exclusiveMinimum:!0,maxLength:!0,minLength:!0,pattern:!0,maxItems:!0,minItems:!0,uniqueItems:!0,maxContains:!0,minContains:!0,maxProperties:!0,minProperties:!0,required:!0,dependentRequired:!0,unevaluatedItems:!0,unevaluatedProperties:!0,prefixItems:!0,items:!0,contains:!0,additionalProperties:!0,properties:!0,patternProperties:!0,dependentSchemas:!0,propertyNames:!0,if:!0,then:!0,else:!0,allOf:!0,anyOf:!0,oneOf:!0,not:!0,$id:!0,$schema:!0,$ref:!0,$anchor:!0,$dynamicRef:!0,$dynamicAnchor:!0,$vocabulary:!0,$comment:!0,$defs:!0},dynamicProps:!1,dynamicItems:!1};function vp(e,{instancePath:t="",parentData:r,parentDataProperty:i,rootData:n=e,dynamicAnchors:o={}}={}){let s=null,a=0,c=vp.evaluated;if(c.dynamicProps)c.props=void 0;if(c.dynamicItems)c.items=void 0;if(!Wt(e,{instancePath:t,parentData:r,parentDataProperty:i,rootData:n,dynamicAnchors:o}))s=s===null?Wt.errors:s.concat(Wt.errors),a=s.length;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.fullMatch!==void 0){if(typeof e.fullMatch!=="string"){let u={instancePath:t+"/fullMatch",schemaPath:"#/properties/fullMatch/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[u];else s.push(u);a++}}if(e["x-astrale-path"]!==void 0){let u=e["x-astrale-path"];if(!(u&&typeof u=="object"&&!Array.isArray(u))){let l={instancePath:t+"/x-astrale-path",schemaPath:"#/properties/x-astrale-path/type",keyword:"type",params:{type:"object"},message:"must be object"};if(s===null)s=[l];else s.push(l);a++}}}return vp.errors=s,a===0}vp.evaluated={props:{fullMatch:!0,"x-astrale-path":!0,definitions:!0,dependencies:!0,$recursiveAnchor:!0,$recursiveRef:!0,contentEncoding:!0,contentMediaType:!0,contentSchema:!0,format:!0,title:!0,description:!0,default:!0,deprecated:!0,readOnly:!0,writeOnly:!0,examples:!0,type:!0,const:!0,enum:!0,multipleOf:!0,maximum:!0,exclusiveMaximum:!0,minimum:!0,exclusiveMinimum:!0,maxLength:!0,minLength:!0,pattern:!0,maxItems:!0,minItems:!0,uniqueItems:!0,maxContains:!0,minContains:!0,maxProperties:!0,minProperties:!0,required:!0,dependentRequired:!0,unevaluatedItems:!0,unevaluatedProperties:!0,prefixItems:!0,items:!0,contains:!0,additionalProperties:!0,properties:!0,patternProperties:!0,dependentSchemas:!0,propertyNames:!0,if:!0,then:!0,else:!0,allOf:!0,anyOf:!0,oneOf:!0,not:!0,$id:!0,$schema:!0,$ref:!0,$anchor:!0,$dynamicRef:!0,$dynamicAnchor:!0,$vocabulary:!0,$comment:!0,$defs:!0},dynamicProps:!1,dynamicItems:!1};var $$=A$;function T$(e,t){try{if($$(e))return[];return($$.errors??[]).map((r)=>_("VS_META_SCHEMA",`${t}${r.instancePath}`,`Astrale V1 value-schema meta-schema rejected the schema: ${r.message??r.keyword}.`))}catch(r){return[_("VS_META_SCHEMA",t,`Astrale V1 value-schema meta-schema validation failed closed: ${u6(r)}.`)]}}function u6(e){return e instanceof Error?e.message:String(e)}var N$=new Set(["$anchor","$comment","$defs","$dynamicAnchor","$dynamicRef","$id","$ref","$schema","$vocabulary","additionalProperties","allOf","anyOf","const","contains","contentEncoding","contentMediaType","contentSchema","default","dependentRequired","dependentSchemas","deprecated","description","else","enum","examples","exclusiveMaximum","exclusiveMinimum","format","fullMatch","if","items","maxContains","maximum","maxItems","maxLength","maxProperties","minContains","minimum","minItems","minLength","minProperties","multipleOf","not","oneOf","pattern","patternProperties","prefixItems","properties","propertyNames","readOnly","required","then","title","type","unevaluatedItems","unevaluatedProperties","uniqueItems","writeOnly","x-astrale-path","x-astrale-value-kind"]),R$=new Set(["$anchor","$dynamicAnchor","$dynamicRef","$vocabulary"]);function j$(e,t,r,i){let n=[];if(t==="named-type"&&i===void 0)n.push(_("VS_RESOURCE_ID",r,"A named-type schema must have one exact identity in the supplied registry."));if(Pr(e,(o)=>{if(!ye(o.schema))return;let s=`${r}${o.pointer}`;for(let a of Object.keys(o.schema)){if(!N$.has(a))n.push(_("VS_KEYWORD_CLOSED",`${s}/${gu(a)}`,`Keyword ${a} is outside the closed V1 Draft 2020-12 vocabulary.`));if(R$.has(a))n.push(_("VS_DYNAMIC_FORBIDDEN",`${s}/${gu(a)}`,`Keyword ${a} is forbidden by V1.`))}if(Object.hasOwn(o.schema,"$schema")){if(o.depth!==0||o.schema.$schema!==Po)n.push(_("VS_DIALECT",`${s}/$schema`,`Embedded-root $schema is optional, but when present must equal ${Po}.`))}if(Object.hasOwn(o.schema,"$id")){let a=o.depth===0&&t==="named-type"&&i!==void 0?Bn(i.origin,i.name):void 0;if(a===void 0||o.schema.$id!==a)n.push(_("VS_RESOURCE_ID",`${s}/$id`,a===void 0?"$id is forbidden outside a named-type embedded root.":`Named-type $id must be absent or equal ${a}.`))}d6(o.schema,s,n),l6(o.schema,s,n),f6(o.schema,s,n)}),t==="property-facet")p6(e,r,n);return n}function l6(e,t,r){if(!Object.hasOwn(e,"x-astrale-value-kind"))return;if(e["x-astrale-value-kind"]!=="instant"||e.type!=="string")r.push(_("VS_VALUE_KIND",`${t}/x-astrale-value-kind`,"x-astrale-value-kind is exactly instant and requires type string at the same schema location."))}function d6(e,t,r){if(Array.isArray(e.type))lx(e.type,`${t}/type`,"type",r);if(Array.isArray(e.required))lx(e.required,`${t}/required`,"required",r);if(Array.isArray(e.enum))m6(e.enum,`${t}/enum`,"enum",r);if(ye(e.dependentRequired)){for(let[i,n]of Object.entries(e.dependentRequired))if(Array.isArray(n))lx(n,`${t}/dependentRequired/${gu(i)}`,"dependentRequired",r)}}function f6(e,t,r){if(Object.hasOwn(e,"fullMatch")&&typeof e.fullMatch!=="string")r.push(_("VS_META_SCHEMA",`${t}/fullMatch`,"fullMatch must be an I-Regexp source string."));if(typeof e.fullMatch==="string"&&!Ui(e.fullMatch))r.push(_("VS_REGEX_PORTABLE",`${t}/fullMatch`,"fullMatch must satisfy the complete RFC 9485 I-Regexp syntax."));if(typeof e.pattern==="string"&&!Ui(e.pattern))r.push(_("VS_REGEX_PORTABLE",`${t}/pattern`,"pattern must satisfy the complete RFC 9485 I-Regexp syntax."));if(ye(e.patternProperties)){for(let i of Object.keys(e.patternProperties))if(!Ui(i))r.push(_("VS_REGEX_PORTABLE",`${t}/patternProperties/${gu(i)}`,"patternProperties keys must satisfy RFC 9485 I-Regexp syntax."))}}function p6(e,t,r){if(!ye(e)){r.push(_("VS_PROPERTY_FACET",t,"A property facet is an object schema."));return}let i=Object.keys(e),n=["type","properties","required","additionalProperties"];if(i.length!==n.length||!n.every((s)=>Object.hasOwn(e,s)))r.push(_("VS_PROPERTY_FACET",t,"A property facet root contains exactly type, properties, required, and additionalProperties."));if(e.type!=="object"||e.additionalProperties!==!1||!ye(e.properties)||!Array.isArray(e.required)){r.push(_("VS_PROPERTY_FACET",t,"Facet constants are type object and additionalProperties false, with properties and required collections."));return}let o=new Set(Object.keys(e.properties));for(let s of o)if(!Sr.test(s))r.push(_("VS_PROPERTY_FACET",`${t}/properties/${gu(s)}`,`Property name ${s} violates the V1 member-name grammar.`));for(let s of e.required)if(typeof s==="string"&&!o.has(s))r.push(_("VS_PROPERTY_FACET",`${t}/required`,`Required member ${s} has no declared property schema.`))}function lx(e,t,r,i){let n=new Set;for(let o of e){if(n.has(o)){i.push(_("VS_META_SCHEMA",t,`${r} is a duplicate-free semantic set.`));return}n.add(o)}}function m6(e,t,r,i){let n=new Set;for(let o of e){let s;try{s=te.serialize(o)}catch{continue}if(n.has(s)){i.push(_("VS_META_SCHEMA",t,`${r} rejects canonically equal duplicates.`));return}n.add(s)}}function gu(e){return e.replaceAll("~","~0").replaceAll("/","~1")}function ha(e,t,r,i=""){let n=[];n.push(...du(e,i));let o=op(r,i);n.push(...o.diagnostics);let s=t==="named-type"?sp(e,o.index,i):void 0,a=ap(e,t,o.index,i,s);n.push(...a.diagnostics);for(let c of a.resources.values()){if(c.key===jt)continue;let u=c.diagnosticPointer??i,l=c===a.resources.values().next().value?t:"named-type",d=c.origin===void 0||c.name===void 0?l==="named-type"?s:void 0:{origin:c.origin,name:c.name};n.push(...T$(c.schema,u)),n.push(...du(c.schema,u)),n.push(...j$(c.schema,l,u,d)),n.push(...O$(c.schema,l,u,(f)=>pA(o.index,f,c.ownerOrigin)))}return n.push(..._$(a.resources,a.resolutions)),B6(n)}function B6(e){let t=new Map;for(let r of e)t.set(`${r.pointer}\x00${r.code}\x00${r.ref??""}\x00${r.message}`,r);return[...t.values()].sort((r,i)=>r.pointer.localeCompare(i.pointer)||r.code.localeCompare(i.code)||r.message.localeCompare(i.message))}function L$(e,t){let r=[];for(let[i,n]of Object.entries(e.types))Cu(n,"named-type",`/types/${yu(i)}`,t,r);for(let[i,n]of Object.entries(e.interfaces))P$(n,`/interfaces/${yu(i)}`,t,r);for(let[i,n]of Object.entries(e.classes))P$(n,`/classes/${yu(i)}`,t,r);for(let[i,n]of Object.entries(e.functions))z$(n,`/functions/${yu(i)}`,t,r);return Object.freeze(r)}function P$(e,t,r,i){if(Cu(e.properties,"property-facet",`${t}/properties`,r,i),"methods"in e)for(let[n,o]of Object.entries(e.methods))z$(o,`${t}/methods/${yu(n)}`,r,i)}function z$(e,t,r,i){if(Cu(e.input,"callable-input",`${t}/input`,r,i),e.output.mode==="value")Cu(e.output.schema,"callable-output",`${t}/output/schema`,r,i);else if(e.output.mode==="stream")Cu(e.output.item,"callable-output",`${t}/output/item`,r,i)}function Cu(e,t,r,i,n){for(let o of ha(e,t,i,r))n.push(_("DV_VALUE_SCHEMA",o.pointer,`[${o.code}] ${o.message}`,o.ref))}function yu(e){return e.replaceAll("~","~0").replaceAll("/","~1")}function M$(e){let t=[];for(let[r,i]of Object.entries(e.candidate.views)){let n=`/views/${g6(r)}`;if(i.target.kind==="definition")i.target.definitions.forEach((o,s)=>h6(e,o,`${n}/target/definitions/${s}`,t))}return Object.freeze(t)}function h6(e,t,r,i){let n=e.resolve(t);if(n===void 0||n.family!=="node")i.push(_("DV_VIEW_TARGET",r,`Definition target ${Be(t)} does not resolve to a Node Definition.`,Be(t)))}function g6(e){return e.replaceAll("~","~0").replaceAll("/","~1")}function xp(e,t){let r=fa(e,t),i=fp(r),n=pu(r),o=[...r.diagnostics,...L$(e,n),...e$(r,i),...I$(r,i),...M$(r),...kA(r,i,n)];return Object.freeze({context:r,analysis:i,diagnostics:Object.freeze(y6(o))})}function y6(e){let t=new Map;for(let r of e)t.set(`${r.pointer}\x00${r.code}\x00${r.ref??""}\x00${r.message}`,r);return[...t.values()].sort((r,i)=>r.pointer.localeCompare(i.pointer)||r.code.localeCompare(i.code)||r.message.localeCompare(i.message))}var U$=/^[a-z0-9][a-z0-9!#$&^_.+-]{0,126}\/[a-z0-9][a-z0-9!#$&^_.+-]{0,126}$/u;var Op={};ze(Op,{description:()=>wp,icon:()=>Ip});var wp=Object.freeze({type:"string",minLength:1,maxLength:1000}),Ip=Object.freeze({type:"string",minLength:1,maxLength:8000});var _p=p.string().min(3).max(253).regex(kr),Lr=p.string().regex(Sr),q$=p.string().refine(Pe.is,"Expected a canonical PropertyKey."),J$=p.string().min(1).max(100).regex(Fi),C6=p.string().regex(ii),Rn=p.string().min(wp.minLength).max(wp.maxLength),b6=p.string().min(Ip.minLength).max(Ip.maxLength),bu=p.lazy(()=>p.union([p.null(),p.boolean(),p.number(),p.string(),p.array(bu),p.record(p.string(),bu)])),E6=p.record(p.string(),bu),Eu=p.union([p.boolean(),E6]),v6=p.record(Lr,Eu),x6=ui(Lr),vu=p.strictObject({type:p.literal("object"),properties:v6,required:x6,additionalProperties:p.literal(!1)}),K$=p.strictObject({mediaType:p.string().regex(U$)}),w6=p.strictObject({visibility:p.enum(["public","private"]),auto:p.strictObject({on:ui(p.enum(["create","update"])).min(1),set:p.literal("instant")}).optional()}),xu=p.record(Lr,w6),I6=p.strictObject({origin:_p,revision:C6}),qo=wu("interface"),ga=wu("class"),O6=wu("function"),Vo=wu("policy"),D6=wu("view"),Z$=p.strictObject({origin:_p,kind:p.literal("core"),name:J$}),_6=p.strictObject({kind:p.literal("domain")}),F$=p.discriminatedUnion("kind",[Z$,_6]),W$=p.discriminatedUnion("kind",[qo,ga]),k6=p.discriminatedUnion("kind",[qo,ga,O6,Vo,D6,Z$]),dx={role:Lr,accepts:ui(W$).min(1)},fx=p.enum(["0..*","1..*","0..1","1"]),Y$=p.strictObject({source:p.strictObject({...dx,outgoing:fx}),target:p.strictObject({...dx,incoming:fx})}),G$=p.strictObject({...dx,incident:fx}),Q$=p.tuple([G$,G$]),X$=p.strictObject({noSelf:p.literal(!0).optional(),acyclic:p.literal(!0).optional()}),S6=p.strictObject({kind:p.literal("subject")}),A6=p.strictObject({kind:p.literal("object")}),$6=p.strictObject({kind:p.literal("source")}),T6=p.strictObject({kind:p.literal("target")}),eT=p.strictObject({kind:p.literal("variable"),id:p.number().int().min(0)}),H$=p.discriminatedUnion("kind",[S6,A6,$6,T6,eT]),N6=p.strictObject({variable:eT,class:ga}),R6=p.strictObject({min:p.number().int().min(0).max(3),max:p.number().int().min(0).max(3)}),Dp=p.lazy(()=>p.union([p.strictObject({source:H$,class:ga,target:H$,repeat:R6.optional()}),p.strictObject({exists:p.strictObject({nodes:p.array(N6).min(1).max(4),where:Dp})}),p.strictObject({allOf:p.array(Dp).min(1)}),p.strictObject({anyOf:p.array(Dp).min(1)})])),j6=p.discriminatedUnion("kind",[p.strictObject({kind:p.literal("self")}),p.strictObject({kind:p.literal("input"),field:Lr}),p.strictObject({kind:p.literal("ref"),ref:k6})]),px=p.lazy(()=>p.union([p.strictObject({check:Vo,object:j6}),p.strictObject({allOf:p.array(px).min(1)}),p.strictObject({anyOf:p.array(px).min(1)})])),P6=p.discriminatedUnion("mode",[p.strictObject({mode:p.literal("value"),schema:Eu}),p.strictObject({mode:p.literal("stream"),item:Eu}),p.strictObject({mode:p.literal("binary")})]),tT={description:Rn.optional(),input:Eu,output:P6,auth:p.enum(["anonymous","authenticated","authorized"]),policy:px.optional()},L6=p.strictObject({...tT,static:p.boolean(),inheritance:p.enum(["abstract","default","sealed"])}).superRefine((e,t)=>{if(e.inheritance==="abstract"&&e.policy!==void 0)t.addIssue({code:"custom",path:["policy"],message:"An abstract method cannot declare a policy.",params:{structureCode:"STRUCTURE_ABSTRACT_POLICY"}});if(e.auth!=="authorized"&&e.policy!==void 0)t.addIssue({code:"custom",path:["policy"],message:"Only an authorized method may declare a policy.",params:{structureCode:"STRUCTURE_CALLABLE_POLICY_AUTH"}})}),rT=p.record(Lr,L6),z6=p.strictObject({read:Vo.optional(),traverse:Vo.optional()}),M6=p.strictObject({traverse:Vo.optional()}),U6=p.strictObject({family:p.literal("both"),description:Rn.optional(),extends:ui(qo),properties:vu,propertyMetadata:xu}),F6=p.strictObject({family:p.literal("node"),description:Rn.optional(),extends:ui(qo),properties:vu,propertyMetadata:xu,methods:rT,data:K$.optional()}),G6={family:p.literal("edge"),description:Rn.optional(),extends:ui(qo),properties:vu,propertyMetadata:xu,constraints:X$},H6=p.strictObject({...G6,orientation:p.enum(["directed","undirected"]),endpoints:p.union([Y$,Q$])}).superRefine(nT),V6=p.discriminatedUnion("family",[U6,F6,H6]),q6=p.strictObject({family:p.literal("node"),description:Rn.optional(),implements:ui(qo),properties:vu,propertyMetadata:xu,methods:rT,data:K$.optional(),icon:b6.optional(),policies:z6}),J6={family:p.literal("edge"),description:Rn.optional(),implements:ui(qo),properties:vu,propertyMetadata:xu,policies:M6,constraints:X$},K6=p.strictObject({...J6,orientation:p.enum(["directed","undirected"]),endpoints:p.union([Y$,Q$])}).superRefine(nT),Z6=p.discriminatedUnion("family",[q6,K6]);function nT(e,t){if(e.orientation==="undirected"===Array.isArray(e.endpoints))return;t.addIssue({code:"custom",path:["endpoints"],message:`${e.orientation} Edge endpoints have the wrong structural shape.`,params:{structureCode:"STRUCTURE_EDGE_ORIENTATION"}})}var W6=p.strictObject(tT).superRefine((e,t)=>{if(e.auth!=="authorized"&&e.policy!==void 0)t.addIssue({code:"custom",path:["policy"],message:"Only an authorized function may declare a policy.",params:{structureCode:"STRUCTURE_CALLABLE_POLICY_AUTH"}})}),Y6=p.union([p.strictObject({description:Rn.optional(),match:Dp}),p.strictObject({description:Rn.optional(),allOf:p.array(Vo).min(1)}),p.strictObject({description:Rn.optional(),anyOf:p.array(Vo).min(1)})]),Q6=p.discriminatedUnion("kind",[p.strictObject({kind:p.literal("domain")}),p.strictObject({kind:p.literal("definition"),definitions:ui(W$).min(1)})]),X6=p.strictObject({description:Rn.optional(),target:Q6,auth:p.enum(["required","optional","public"])}),eG=p.strictObject({class:ga,properties:p.record(q$,bu)}),tG=p.strictObject({class:ga,source:F$,target:F$,properties:p.record(q$,bu)}),rG=p.strictObject({nodes:p.record(J$,eG),edges:p.array(tG)}),nG=p.strictObject({format:p.literal(ca),version:p.literal(ua),origin:_p,dependencies:p.array(I6),types:p.record(Lr,Eu),interfaces:p.record(Lr,V6),classes:p.record(Lr,Z6),functions:p.record(Lr,W6),policies:p.record(Lr,Y6),views:p.record(Lr,X6),core:rG}),iG=nG;function ya(e){let t=iG.safeParse(e);if(t.success)return t.data;throw new xe(t.error.issues.flatMap((r)=>oG(r,e)))}function wu(e){return p.strictObject({origin:_p,kind:p.literal(e),name:Lr})}function ui(e){return p.array(e).superRefine((t,r)=>{let i=new Map;t.forEach((n,o)=>{let s=mx(n),a=i.get(s);if(a===void 0){i.set(s,o);return}r.addIssue({code:"custom",path:[o],message:`Array item duplicates item ${a}.`,params:{structureCode:"STRUCTURE_DUPLICATE_ITEM"}})})})}function mx(e){if(e===null||typeof e!=="object")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(mx).join(",")}]`;return`{${Object.entries(e).sort(([t],[r])=>t<r?-1:t>r?1:0).map(([t,r])=>`${JSON.stringify(t)}:${mx(r)}`).join(",")}}`}function oG(e,t){if(e.code==="unrecognized_keys")return e.keys.map((i)=>_("STRUCTURE_UNKNOWN_FIELD",V$([...e.path,i]),`Unknown field ${JSON.stringify(i)}.`));let r=e.code==="custom"&&typeof e.params?.structureCode==="string"?e.params.structureCode:void 0;return[_(r??sG(e,t),V$(e.path),aG(e,t))]}function sG(e,t){switch(e.code){case"invalid_type":return iT(t,e.path)===void 0?"STRUCTURE_REQUIRED":"STRUCTURE_TYPE";case"invalid_value":return"STRUCTURE_VALUE";case"invalid_format":return"STRUCTURE_FORMAT";case"invalid_union":return"STRUCTURE_UNION";case"invalid_key":return"STRUCTURE_KEY";case"too_small":return"STRUCTURE_MINIMUM";case"too_big":return"STRUCTURE_MAXIMUM";case"not_multiple_of":return"STRUCTURE_MULTIPLE";default:return"STRUCTURE_INVALID"}}function aG(e,t){if(e.code==="invalid_type"&&iT(t,e.path)===void 0)return"Required value is missing.";if(e.code==="invalid_union")return"Value does not match any allowed structural variant.";if(e.code==="invalid_key")return"Record member name is invalid.";return e.message}function iT(e,t){let r=e;for(let i of t){if(typeof r!=="object"||r===null)return;r=Reflect.get(r,i)}return r}function V$(e){if(e.length===0)return"";return`/${e.map((t)=>cG(String(t))).join("/")}`}function cG(e){return e.replaceAll("~","~0").replaceAll("/","~1")}var uG=new Map([[ca,new Map([[ua,ya]])]]);function Ca(e){if(!lG(e))return ya(e);let t=uG.get(oT(e.format));if(t===void 0)aT("UNSUPPORTED_DOCUMENT_FORMAT","/format",`Unsupported Domain Schema document format ${sT(e.format)}.`);let r=t.get(oT(e.version));if(r===void 0)aT("UNSUPPORTED_DSL_VERSION","/version",`Unsupported Domain Schema DSL version ${sT(e.version)}.`);return r(e)}function lG(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}function oT(e){return typeof e==="string"?e:""}function sT(e){return e===void 0?"(missing)":JSON.stringify(e)}function aT(e,t,r){throw new xe([_(e,t,r)])}function Ji(e,t=rp()){let r;try{r=se(e)}catch(s){if(s instanceof he)throw new xe([_("DV_JSON_VALUE",s.pointer,s.message)]);throw s}let i=Ca(r),n=xp(i,t);if(n.diagnostics.length>0)throw new xe(n.diagnostics);let o=uu(i).schema;return jA(o,n.context.dependencies.values()),o}class Bx{context;values;constructor(e,t){this.context=e,this.values=t}compile(e,t){let r=e.config;if(r.auth!=="anonymous"&&r.auth!=="authenticated"&&r.auth!=="authorized")ie("BUILDER_CALLABLE_AUTH",`${t.pointer}/auth`,"Function authentication must be anonymous, authenticated, or authorized.");let i=r.auth;if(i!=="authorized"&&r.policy!==void 0)ie("BUILDER_CALLABLE_POLICY_AUTH",`${t.pointer}/policy`,"Only an authorized Function or Method may declare a Policy check.");let n=t.kind!=="function";if(!n&&(r.static!==void 0||r.inheritance!==void 0))ie("BUILDER_CALLABLE_PLACEMENT",t.pointer,"A standalone Function cannot declare Method staticness or inheritance.");let o=n?r.static??!1:void 0,s=n?r.inheritance??(t.kind==="node-interface-method"?"abstract":"default"):void 0;if(s==="abstract"&&r.policy!==void 0)ie("BUILDER_ABSTRACT_POLICY",`${t.pointer}/policy`,"An abstract Method cannot declare a Policy check.");let a=this.values.schema(r.input,"callable-input",`${t.pointer}/input`),c=this.compileOutput(r.output,`${t.pointer}/output`),u=r.policy===void 0?void 0:Nn(r.policy(this.policyContext(a,t,o??!1))),l={...r.description===void 0?{}:{description:r.description},input:a,output:c,auth:i,...u===void 0?{}:{policy:u}};if(!n)return l;return{...l,static:o,inheritance:s}}compileOutput(e,t){if(!q_(e))return{mode:"value",schema:this.values.schema(e,"callable-output",t)};if(e.mode==="binary")return{mode:"binary"};return{mode:"stream",item:this.values.schema(e.item,"callable-output",`${t}/item`)}}policyContext(e,t,r){let i=new Proxy(Object.create(null),{get(o,s){return typeof s==="string"?G_(s):void 0}}),n=H_();return Object.freeze({input:i,self:n,ref:(o)=>xh(this.context.resolvePolicyObject(o,`${t.pointer}/policy/ref`)),check:(o,s)=>{let a=V_(s),c=a;if(a.kind==="self"){if(t.kind==="function"||r)ie("BUILDER_POLICY_SELF",`${t.pointer}/policy`,"self is available only to a non-static Node Method.")}else if(a.kind==="input")if(dG(e,a.field));else ie("BUILDER_POLICY_INPUT",`${t.pointer}/policy`,`input.${a.field} is not one direct required single-Node path field.`);else c=xh(this.context.resolvePolicyObject(a.ref,`${t.pointer}/policy/ref`));return{check:this.context.resolvePolicy(o,`${t.pointer}/policy/check`),object:c}},allOf:(...o)=>(cT(o,`${t.pointer}/policy/allOf`),{allOf:o}),anyOf:(...o)=>(cT(o,`${t.pointer}/policy/anyOf`),{anyOf:o})})}}function dG(e,t){if(e===null||typeof e!=="object"||Array.isArray(e))return!1;if(e.type!=="object"||e.additionalProperties!==!1||!Array.isArray(e.required)||!e.required.includes(t)||e.properties===null||typeof e.properties!=="object"||Array.isArray(e.properties))return!1;let r=e.properties[t];return r!==null&&typeof r==="object"&&!Array.isArray(r)&&r.$ref==="https://schemas.astrale.ai/graph/1/node-path"&&Object.hasOwn(r,"x-astrale-path")}function cT(e,t){if(e.length===0)ie("BUILDER_POLICY_EMPTY_COMPOSITION",t,"Policy check composition must be non-empty.")}function lT(e,t){for(let[r,i]of Object.entries(e?.nodes??{})){if(!nr(i,"core-node"))ie("BUILDER_CORE_NODE",`/core/nodes/${Te(r)}`,"core.nodes entries are created by node(...).");t.captureCoreNode(i,r,`/core/nodes/${Te(r)}`)}}function dT(e,t){let r=Object.fromEntries(Object.entries(e?.nodes??{}).map(([n,o])=>[n,fG(o,t,`/core/nodes/${Te(n)}`)])),i=(e?.edges??[]).map((n,o)=>pG(n,t,`/core/edges/${o}`));return{nodes:r,edges:i}}function fG(e,t,r){let i=t.resolveNodeClass(e.class,`${r}/class`);if(i.origin!==t.origin)ie("BUILDER_CORE_CLASS",`${r}/class`,"A Core Node Class must be local to the owning Domain.");return{class:i,properties:e.properties}}function pG(e,t,r){if(!nr(e,"core-edge"))ie("BUILDER_CORE_EDGE",r,"core.edges entries are created by edge(...).");let i=t.resolveEdgeClass(e.class,`${r}/class`);if(i.origin!==t.origin)ie("BUILDER_CORE_CLASS",`${r}/class`,"A Core Edge Class must be local to the owning Domain.");return{class:i,source:uT(e.source,t,`${r}/source`),target:uT(e.target,t,`${r}/target`),properties:e.properties}}function uT(e,t,r){return t.resolveCoreEndpoint(e,r)}function pT(e,t){let r=fp(fa(e,t)).definitions,i=Object.fromEntries(Object.entries(e.core.nodes).map(([o,s])=>{let a=r.get(Q(s.class));if(a===void 0)ie("BUILDER_CORE_PROPERTY",`/core/nodes/${Te(o)}/class`,"Core property shorthand requires a resolvable concrete Class.");return[o,{...s,properties:fT(s.properties,a,`/core/nodes/${Te(o)}/properties`)}]})),n=e.core.edges.map((o,s)=>{let a=r.get(Q(o.class));if(a===void 0)ie("BUILDER_CORE_PROPERTY",`/core/edges/${s}/class`,"Core property shorthand requires a resolvable concrete Class.");return{...o,properties:fT(o.properties,a,`/core/edges/${s}/properties`)}});return{nodes:i,edges:n}}function fT(e,t,r){let i=new Map;for(let[s,a]of t.properties){let c=i.get(a.name)??[];c.push(s),i.set(a.name,c)}let n={},o=new Map;for(let[s,a]of Object.entries(e)){let c=mG(s,t,i,`${r}/${Te(s)}`),u=o.get(c);if(u!==void 0)ie("BUILDER_CORE_PROPERTY",`${r}/${Te(s)}`,`Property is supplied twice through ${JSON.stringify(u)} and ${JSON.stringify(s)}.`);o.set(c,s),n[c]=a}return n}function mG(e,t,r,i){if(Pe.is(e)){let o=Pe(e);if(!t.properties.has(o))ie("BUILDER_CORE_PROPERTY",i,`Property ${e} is not present on the Core Class.`);return o}let n=r.get(e)??[];if(n.length===1)return n[0];if(n.length===0)ie("BUILDER_CORE_PROPERTY",i,`Property ${JSON.stringify(e)} does not exist.`);ie("BUILDER_CORE_PROPERTY",i,`Property ${JSON.stringify(e)} is ambiguous; use one of: ${n.join(", ")}.`)}class hx{context;values;callables;policies;constructor(e,t,r,i){this.context=e,this.values=t,this.callables=r,this.policies=i}compileInterface(e,t){if(e.definitionKind==="interface"){if(e.config.family==="both")return this.bothInterface(e,t);if(e.config.family==="node")return this.nodeInterface(e,t);return this.edgeInterface(e,t)}ie("BUILDER_DEFINITION_PLACEMENT",t,`${e.definitionKind} belongs in classes, not interfaces.`)}compileClass(e,t){if(e.definitionKind==="node-class")return this.nodeClass(e,t);if(e.definitionKind==="edge-class")return this.edgeClass(e,t);ie("BUILDER_DEFINITION_PLACEMENT",t,`${e.definitionKind} belongs in interfaces, not classes.`)}bothInterface(e,t){let r=e.config;if(r.family!=="both")ie("BUILDER_DEFINITION_PLACEMENT",t,"Expected both family.");let i=this.values.properties(r.properties,`${t}/properties`);return{family:"both",...r.description===void 0?{}:{description:r.description},extends:this.parents(r.extends,["both"],`${t}/extends`),...i}}nodeInterface(e,t){let r=e.config;if(r.family!=="node")ie("BUILDER_DEFINITION_PLACEMENT",t,"Expected node family.");let i=this.values.properties(r.properties,`${t}/properties`),n=mT(r.data);return{family:"node",...r.description===void 0?{}:{description:r.description},extends:this.parents(r.extends,["node","both"],`${t}/extends`),...i,methods:this.methods(r.methods,"node-interface-method",`${t}/methods`),...n===void 0?{}:{data:n}}}edgeInterface(e,t){let r=e.config;if(r.family!=="edge")ie("BUILDER_DEFINITION_PLACEMENT",t,"Expected edge family.");let i=this.values.properties(r.properties,`${t}/properties`),n=this.interfaceEdgeContract(r,`${t}/endpoints`);return{family:"edge",...r.description===void 0?{}:{description:r.description},extends:this.parents(r.extends,["edge","both"],`${t}/extends`),...i,...n,constraints:BT(r)}}nodeClass(e,t){let r=this.values.properties(e.config.properties,`${t}/properties`),i=mT(e.config.data);return{family:"node",...e.config.description===void 0?{}:{description:e.config.description},implements:this.parents(e.config.implements,["node","both"],`${t}/implements`),...r,methods:this.methods(e.config.methods,"node-class-method",`${t}/methods`),...i===void 0?{}:{data:i},...e.config.icon===void 0?{}:{icon:e.config.icon},policies:{...e.config.policies?.read===void 0?{}:{read:this.policies.ref(e.config.policies.read,`${t}/policies/read`)},...e.config.policies?.traverse===void 0?{}:{traverse:this.policies.ref(e.config.policies.traverse,`${t}/policies/traverse`)}}}}edgeClass(e,t){let r=this.values.properties(e.options.properties,`${t}/properties`),i=e.orientation==="directed"?{orientation:"directed",endpoints:{source:this.directedSource(e.source,`${t}/endpoints/source`),target:this.directedTarget(e.target,`${t}/endpoints/target`)}}:{orientation:"undirected",endpoints:[this.incidentEndpoint(e.endpoints[0],`${t}/endpoints/0`),this.incidentEndpoint(e.endpoints[1],`${t}/endpoints/1`)]};return{family:"edge",...e.options.description===void 0?{}:{description:e.options.description},implements:this.parents(e.options.implements,["edge","both"],`${t}/implements`),...r,...i,policies:e.options.policies?.traverse===void 0?{}:{traverse:this.policies.ref(e.options.policies.traverse,`${t}/policies/traverse`)},constraints:BT(e.options)}}interfaceEdgeContract(e,t){if(e.orientation==="undirected")return{orientation:"undirected",endpoints:[this.incidentFromLegacyEndpoint(e.source,`${t}/0`),this.incidentFromLegacyEndpoint(e.target,`${t}/1`)]};return{orientation:"directed",endpoints:{source:this.directedSourceFromLegacyEndpoint(e.source,`${t}/source`),target:this.directedTargetFromLegacyEndpoint(e.target,`${t}/target`)}}}endpointBase(e,t){return{role:e.as,accepts:e.accepts.map((r,i)=>this.context.resolveNodeDefinition(r,`${t}/accepts/${i}`)).sort(Ue)}}directedSource(e,t){return{...this.endpointBase(e,t),outgoing:e.outgoing}}directedTarget(e,t){return{...this.endpointBase(e,t),incoming:e.incoming}}incidentEndpoint(e,t){return{...this.endpointBase(e,t),incident:e.incident}}directedSourceFromLegacyEndpoint(e,t){return{...this.endpointBase(e,t),outgoing:e.cardinality??"0..*"}}directedTargetFromLegacyEndpoint(e,t){return{...this.endpointBase(e,t),incoming:e.cardinality??"0..*"}}incidentFromLegacyEndpoint(e,t){return{...this.endpointBase(e,t),incident:e.cardinality??"0..*"}}parents(e,t,r){return(e??[]).map((i,n)=>this.context.resolveInterface(i,t,`${r}/${n}`)).sort(Ue)}methods(e,t,r){return Object.fromEntries(Object.entries(e??{}).map(([i,n])=>[i,this.callables.compile(n,{kind:t,pointer:`${r}/${Te(i)}`})]))}}function mT(e){return e===void 0?void 0:{mediaType:e}}function BT(e){return{...e.constraints?.noSelf===!0?{noSelf:!0}:{},...e.constraints?.acyclic===!0?{acyclic:!0}:{}}}class gx{context;constructor(e){this.context=e}ref(e,t){return this.context.resolvePolicy(e,t)}compile(e,t){let r=e.input;if("operator"in r){let n=r.policies.map((o,s)=>this.context.resolvePolicy(o,`${t}/${r.operator}/${s}`));return To(r.operator==="allOf"?{allOf:n}:{anyOf:n})}let i=r.match(US({resolveEdgeClass:(n,o)=>this.context.resolveEdgeClass(n,o),resolveNodeClass:(n,o)=>this.context.resolveNodeClass(n,o),pointer:t}));return To({...r.description===void 0?{}:{description:r.description},match:i})}}function hT(e,t){let r=new Set,i=new Set,n=(o)=>{if(r.has(o))ie("BUILDER_POLICY_CYCLE",`/policies/${o}`,`Policy composition cycle reaches ${t}:policy.${o}.`);if(i.has(o))return;r.add(o);let s=e[o],a=s!==void 0&&"allOf"in s?s.allOf:s!==void 0&&("anyOf"in s)?s.anyOf:[];for(let c of a)if(c.origin===t)n(c.name);r.delete(o),i.add(o)};for(let o of Object.keys(e))n(o)}function kp(e,t){let r=e,i=new Set;while(typeof r==="function"){if(i.has(r))ie("BUILDER_REFERENCE_CYCLE",t,"A lazy reference resolves cyclically.");i.add(r),r=r()}return r}var gT=new WeakMap,yT=new WeakMap;class yx{#e=new Map;#t=new Map;captureDefinition(e,t,r){this.capture(e,`${t.origin}:${t.kind}.${t.name}`,r),this.#e.set(e,t)}capture(e,t,r){let i=this.#t.get(e),n=yT.get(e),o=i??n;if(o!==void 0&&o!==t)ie("BUILDER_AMBIGUOUS_OWNERSHIP",r,`One detached builder value cannot be owned by both ${o} and ${t}.`);this.#t.set(e,t)}definition(e){return this.#e.get(e)??gT.get(e)}commit(){for(let[e,t]of this.#t)yT.set(e,t);for(let[e,t]of this.#e)gT.set(e,t)}}class Iu{origin;ownership=new yx;localDefinitions=new Map;localDefinitionFamilies=new Map;policies=new Map;coreNodes=new Map;policyObjects=new Map;policyObjectRefs=new Set;usedForeignOrigins=new Set;#e=new Map;constructor(e,t){this.origin=e;for(let r of t){let i={origin:r.origin,revision:mt(r)},n=this.#e.get(r.origin);if(n!==void 0&&n.dependency.revision!==i.revision)ie("BUILDER_DEPENDENCY_CONFLICT","/dependencies",`Dependency ${r.origin} was supplied at two different revisions.`);this.#e.set(r.origin,{schema:r,dependency:i})}}captureDefinition(e,t,r){let i=Q(t);if(this.localDefinitions.has(i))ie("BUILDER_DUPLICATE_MEMBER",r,`Definition ${t.kind}.${t.name} is duplicated.`);this.localDefinitions.set(i,t),this.localDefinitionFamilies.set(i,bG(e)),this.ownership.captureDefinition(e,t,r),this.capturePolicyObject(e,t)}capturePolicy(e,t,r){this.ownership.capture(e,`${t.origin}:policy.${t.name}`,r),this.policies.set(e,t),this.capturePolicyObject(e,t)}captureCoreNode(e,t,r){this.ownership.capture(e,`${this.origin}:core.${t}`,r);let i={origin:this.origin,kind:"core",name:t};this.coreNodes.set(e,i),this.capturePolicyObject(e,i)}captureFunction(e,t,r){this.ownership.capture(e,`${t.origin}:function.${t.name}`,r),this.capturePolicyObject(e,t)}captureView(e,t,r){this.ownership.capture(e,`${t.origin}:view.${t.name}`,r),this.capturePolicyObject(e,t)}resolveDefinition(e,t,r,i){let n=kp(e,i),o=hG(n)?n:typeof n==="object"&&n!==null?this.ownership.definition(n):void 0;if(o===void 0)ie("BUILDER_UNOWNED_REFERENCE",i,"Definition reference has no captured Domain owner.");if(!t.includes(o.kind))ie("BUILDER_REFERENCE_KIND",i,`Expected ${t.join(" or ")}, received ${o.kind}.`);let s=this.definitionFamily(o);if(s===void 0||!r.includes(s))ie("BUILDER_REFERENCE_KIND",i,`Expected ${r.join(" or ")} family, received ${s??"an unresolved family"}.`);return this.assertVisible(o,i),{...o}}resolveNodeDefinition(e,t){return this.resolveDefinition(e,["interface","class"],["node"],t)}resolveNodeClass(e,t){return this.resolveDefinition(e,["class"],["node"],t)}resolveEdgeClass(e,t){return this.resolveDefinition(e,["class"],["edge"],t)}resolveInterface(e,t,r){return this.resolveDefinition(e,["interface"],t,r)}resolvePolicy(e,t){let r=kp(e,t);if(typeof r!=="object"||r===null)ie("BUILDER_UNOWNED_REFERENCE",t,"Policy reference has no captured local owner.");let i=this.policies.get(r);if(i===void 0)ie("BUILDER_FOREIGN_POLICY",t,"V1 Policy references must name a local Policy.");return{...i}}resolvePolicyObject(e,t){let r=kp(e,t),i=yG(r)?r:typeof r==="object"&&r!==null?this.policyObjects.get(r):void 0;if(i===void 0||i.origin!==this.origin||!this.policyObjectRefs.has(Q(i)))ie("BUILDER_POLICY_REF",t,"Policy ref(...) must name one registered local Definition, Function, Policy, View, or Core Node.");return{...i}}resolveCoreEndpoint(e,t){if(BG(e))return{kind:"domain"};let r=gG(e)?e:this.coreNodes.get(e);if(r===void 0||r.origin!==this.origin)ie("BUILDER_CORE_REF",t,"A Core reference must name a registered local Core Node.");return{...r}}dependencies(){return[...this.usedForeignOrigins].map((e)=>{let t=this.#e.get(e);if(t===void 0)ie("BUILDER_DEPENDENCY_DIRECT","/dependencies",`Foreign origin ${e} is not supplied as an exact direct dependency.`);return t.dependency}).sort((e,t)=>e.origin.localeCompare(t.origin))}valueRegistry(e){let t=new Set(this.#e.keys()),r=new Map;for(let{schema:n}of this.#e.values())for(let o of da(n))if(!t.has(o.schema.origin))r.set(o.schema.origin,o.schema);let i=(n,o)=>({origin:n.origin,...o===void 0?{}:{revision:o},dependencies:n.dependencies,types:n.types,nodeDefinitions:CG(n)});return{current:{origin:this.origin,dependencies:[...this.#e.values()].map(({dependency:n})=>n),types:e,nodeDefinitions:[...this.localDefinitions.values()].filter((n)=>this.localDefinitionFamilies.get(Q(n))==="node").sort(Ue)},directDependencies:[...this.#e.values()].map(({schema:n,dependency:o})=>({...i(n,o.revision)})),transitiveDependencies:[...r.values()].map((n)=>i(n,mt(n))),graphNodePath:ip}}noteDomainReferences(e){for(let t of mp(e))this.usedForeignOrigins.add(t)}assertVisible(e,t){if(e.origin===this.origin){if(!this.localDefinitions.has(Q(e)))ie("BUILDER_REFERENCE_MISSING",t,`Local Definition ${e.kind}.${e.name} is not declared.`);return}if(!this.#e.has(e.origin))ie("BUILDER_DEPENDENCY_DIRECT",t,`Foreign Definition ${e.origin}:${e.kind}.${e.name} is not in a direct dependency.`);this.usedForeignOrigins.add(e.origin)}definitionFamily(e){if(e.origin===this.origin)return this.localDefinitionFamilies.get(Q(e));let t=this.#e.get(e.origin)?.schema;if(t===void 0)return;return e.kind==="class"?t.classes[e.name]?.family:t.interfaces[e.name]?.family}capturePolicyObject(e,t){this.policyObjects.set(e,t),this.policyObjectRefs.add(Q(t))}}function BG(e){if(typeof e!=="object"||e===null)return!1;let t=e;return t.kind==="domain"&&Object.keys(t).length===1}function hG(e){if(typeof e!=="object"||e===null)return!1;let t=e;return typeof t.origin==="string"&&typeof t.name==="string"&&(t.kind==="interface"||t.kind==="class")}function gG(e){if(typeof e!=="object"||e===null)return!1;let t=e;return typeof t.origin==="string"&&t.kind==="core"&&typeof t.name==="string"}function yG(e){if(typeof e!=="object"||e===null)return!1;let t=e;return typeof t.origin==="string"&&typeof t.name==="string"&&(t.kind==="interface"||t.kind==="class"||t.kind==="function"||t.kind==="policy"||t.kind==="view"||t.kind==="core")}function CG(e){let t=[];for(let[r,i]of Object.entries(e.interfaces))if(i.family==="node")t.push({origin:e.origin,kind:"interface",name:r});for(let[r,i]of Object.entries(e.classes))if(i.family==="node")t.push({origin:e.origin,kind:"class",name:r});return t.sort(Ue)}function bG(e){if(e.definitionKind==="interface")return e.config.family;return e.definitionKind==="node-class"?"node":"edge"}function Cx(e,t){EG(e.interfaces??{},e.classes??{},t),vG(e.policies??{},t),xG(e,t),lT(e.core,t)}function ET(e,t){let r=new Iu(t,e.dependencies??[]);Cx(e,r),r.ownership.commit()}function EG(e,t,r){for(let[i,n]of Object.entries(e)){if(CT(n,`/interfaces/${Te(i)}`),n.definitionKind!=="interface")ie("BUILDER_DEFINITION_PLACEMENT",`/interfaces/${Te(i)}`,`${n.definitionKind} belongs in classes.`);r.captureDefinition(n,{origin:r.origin,kind:"interface",name:i},`/interfaces/${Te(i)}`)}for(let[i,n]of Object.entries(t)){if(CT(n,`/classes/${Te(i)}`),n.definitionKind!=="node-class"&&n.definitionKind!=="edge-class")ie("BUILDER_DEFINITION_PLACEMENT",`/classes/${Te(i)}`,`${n.definitionKind} belongs in interfaces.`);r.captureDefinition(n,{origin:r.origin,kind:"class",name:i},`/classes/${Te(i)}`)}}function vG(e,t){for(let[r,i]of Object.entries(e)){if(!nr(i,"policy"))ie("BUILDER_POLICY",`/policies/${Te(r)}`,"Policies are created by definePolicy(...).");t.capturePolicy(i,{origin:t.origin,kind:"policy",name:r},`/policies/${Te(r)}`)}}function xG(e,t){for(let[r,i]of Object.entries(e.functions??{})){let n=`/functions/${Te(r)}`;bT(i,n),t.captureFunction(i,{origin:t.origin,kind:"function",name:r},n)}for(let[r,i]of[["interfaces",e.interfaces??{}],["classes",e.classes??{}]])for(let[n,o]of Object.entries(i)){if(!(o.definitionKind==="interface"&&o.config.family==="node"||o.definitionKind==="node-class"))continue;let s=o.definitionKind==="node-class"?o.config.methods:o.definitionKind==="interface"&&o.config.family==="node"?o.config.methods:void 0;for(let[a,c]of Object.entries(s??{})){let u=`/${r}/${Te(n)}/methods/${Te(a)}`;bT(c,u),t.ownership.capture(c,`${t.origin}:${o.definitionKind==="interface"?"interface":"class"}.${n}.method.${a}`,u)}}for(let[r,i]of Object.entries(e.views??{})){let n=`/views/${Te(r)}`;if(!nr(i,"view"))ie("BUILDER_VIEW",n,"Views are created by view(...).");t.captureView(i,{origin:t.origin,kind:"view",name:r},n)}}function CT(e,t){if(!nr(e,"definition"))ie("BUILDER_DEFINITION",t,"Definitions are created by a V1 Definition builder.")}function bT(e,t){if(!nr(e,"function"))ie("BUILDER_FUNCTION",t,"Functions and Methods are created by fn(...).")}function vT(e,t,r){let i=LS(e.zodSchema);if(i===void 0)return;let n=e.path.reduce((o,s)=>`${o}/${wG(String(s))}`,r);for(let o of Object.keys(e.jsonSchema))delete e.jsonSchema[o];Object.assign(e.jsonSchema,{$ref:"https://schemas.astrale.ai/graph/1/node-path","x-astrale-path":{target:"node",cardinality:"one",accepts:t(i,n)}})}function wG(e){return e.replaceAll("~","~0").replaceAll("/","~1")}function wT(e,t,r,i="",n={}){let o=IG(e,i,n.position??"value");if(o.length>0)return{ok:!1,diagnostics:o};let s;try{let a=p.toJSONSchema(e,{target:"draft-2020-12",unrepresentable:"throw",io:"input",cycles:"ref",reused:"inline",override:({zodSchema:c,jsonSchema:u,path:l})=>{if(c instanceof p.ZodObject)u.required=Object.entries(c.shape).filter(([,d])=>!Ex(d)).map(([d])=>d);if(c instanceof p.ZodType)OG(c,u),n.override?.({jsonSchema:u,path:l,zodSchema:c})}});if(s=bx(a),s!==null&&typeof s==="object"&&!Array.isArray(s))s={...s,$schema:Po}}catch(a){return{ok:!1,diagnostics:[_("ZOD_SCHEMA_NOT_LOSSLESS",i,`Zod cannot represent this contract exactly as Draft 2020-12: ${TG(a)}.`)]}}if(n.validate!==!1){let a=ha(s,t,r,i);if(a.length>0)return{ok:!1,diagnostics:a}}return{ok:!0,schema:Kt(s,t,r),diagnostics:[]}}function bx(e){if(e===null||["boolean","number","string"].includes(typeof e))return e;if(Array.isArray(e))return e.map(bx);if(e===null||typeof e!=="object")throw TypeError("Zod emitted a non-JSON schema value.");let t={};for(let r of Reflect.ownKeys(e)){if(typeof r==="symbol")throw TypeError("Zod emitted symbol-keyed schema metadata.");let i=Object.getOwnPropertyDescriptor(e,r);if(i===void 0)continue;if(!i.enumerable){if(r==="~standard")continue;throw TypeError(`Zod emitted unexpected non-enumerable schema member ${r}.`)}if(!("value"in i))throw TypeError(`Zod emitted accessor schema member ${r}.`);t[r]=bx(i.value)}return t}function Ex(e){return ba(e,new Set)}function IG(e,t,r){let i=[],n=new WeakMap;function o(s,a,c,u){let l=`${c}:${String(u)}`,d=n.get(s)??new Set;if(d.has(l))return;d.add(l),n.set(s,d);let f=Sp(s);if(f===void 0){i.push(_("ZOD_SCHEMA_NOT_LOSSLESS",a,"Zod schema has no inspectable v4 definition."));return}if(u&&c==="value"&&ba(s,new Set))i.push(_("ZOD_SCHEMA_NOT_LOSSLESS",a,"Zod optional() accepts JavaScript undefined, which V1 can represent only as absence of a containing object property."));let m=typeof f.type==="string"?f.type:"unknown";if($G.has(m))i.push(_("ZOD_SCHEMA_NOT_LOSSLESS",a,`Zod ${m} semantics cannot be represented losslessly in the V1 JSON value domain.`));if(f.coerce===!0)i.push(_("ZOD_SCHEMA_NOT_LOSSLESS",a,"Zod coercion changes the accepted input domain and is not serializable as JSON Schema."));if(xT(f,a,i),Array.isArray(f.checks))f.checks.forEach((B,h)=>{if(kv(B)!==void 0)return;let g=kG(B);if(g!==void 0)xT(g,`${a}/checks/${h}`,i)});for(let B of DG(f,a,c))o(B.schema,B.pointer,B.position,B.boundary)}return o(e,t,r,!0),i}function OG(e,t){let r=Sp(e)?.checks;if(!Array.isArray(r))return;let i=r.flatMap((o)=>{let s=kv(o);return s===void 0?[]:[s]});if(i.length===0)return;if(i.length===1){t.fullMatch=i[0];return}let n=Array.isArray(t.allOf)?t.allOf:[];t.allOf=[...n,...i.map((o)=>({fullMatch:o}))]}function xT(e,t,r){if(e.check==="custom"||e.check==="overwrite"){r.push(_("ZOD_SCHEMA_NOT_LOSSLESS",t,`Zod ${String(e.check)} checks are executable semantics with no lossless JSON Schema form.`));return}if(e.check==="string_format"&&e.format!=="regex"){r.push(_("ZOD_SCHEMA_NOT_LOSSLESS",t,`Zod format ${String(e.format)} asserts acceptance, while V1 format is annotation-only.`));return}if(e.check==="string_format"&&e.format==="regex"&&e.pattern instanceof RegExp){if(!AG(e.pattern))r.push(_("ZOD_SCHEMA_NOT_LOSSLESS",t,"Zod RegExp flags, anchors, dot semantics, or syntax cannot be preserved as a V1 I-Regexp substring pattern."))}}function DG(e,t,r){let i=[],n=(s,a=t)=>{if(Ki(s))i.push({boundary:!1,pointer:a,position:r,schema:s})},o=(s,a)=>{if(Ki(s))i.push({boundary:!0,pointer:a,position:"value",schema:s})};switch(e.type){case"array":o(e.element,`${t}/items`);break;case"intersection":n(e.left,`${t}/allOf/0`),n(e.right,`${t}/allOf/1`);break;case"lazy":if(typeof e.getter==="function")n(e.getter());break;case"object":if(vx(e.shape)){for(let[s,a]of Object.entries(e.shape))if(Ki(a))i.push({boundary:!0,pointer:`${t}/properties/${SG(s)}`,position:"object-property",schema:a})}o(e.catchall,`${t}/additionalProperties`);break;case"record":o(e.keyType,`${t}/propertyNames`),o(e.valueType,`${t}/additionalProperties`);break;case"tuple":if(Array.isArray(e.items))e.items.forEach((s,a)=>o(s,`${t}/prefixItems/${a}`));o(e.rest,`${t}/items`);break;case"union":if(Array.isArray(e.options))e.options.forEach((s,a)=>n(s,`${t}/anyOf/${a}`));break;default:n(e.innerType)}return i}function ba(e,t){if(t.has(e))return!1;t.add(e);let r=Sp(e);if(r===void 0)return t.delete(e),!1;let i=!1;switch(r.type){case"optional":i=!0;break;case"default":case"lazy":case"nullable":{let n=_G(r);i=n!==void 0&&ba(n,t);break}case"intersection":{let n=Ki(r.left)&&ba(r.left,t),o=Ki(r.right)&&ba(r.right,t);i=n&&o;break}case"union":i=Array.isArray(r.options)&&r.options.some((n)=>Ki(n)&&ba(n,t));break;default:i=!1}return t.delete(e),i}function _G(e){let t=e.type==="lazy"&&typeof e.getter==="function"?e.getter():e.innerType;return Ki(t)?t:void 0}function Sp(e){return vx(e.def)?e.def:void 0}function kG(e){if(Ki(e))return Sp(e);if(e===null||typeof e!=="object")return;let t=e._zod;return vx(t?.def)?t.def:void 0}function Ki(e){return e instanceof p.ZodType}function SG(e){return e.replaceAll("~","~0").replaceAll("/","~1")}function vx(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}function AG(e){if(e.flags!==""&&e.flags!=="u")return!1;if(!Ui(e.source))return!1;let t=!1,r=!1;for(let i of Array.from(e.source)){if(t){t=!1;continue}if(i==="\\"){t=!0;continue}if(i==="[")r=!0;else if(i==="]")r=!1;else if(!r&&(i==="^"||i==="$"||i==="."))return!1}return!0}var $G=new Set(["bigint","catch","custom","date","file","function","map","nan","pipe","prefault","promise","readonly","set","symbol","transform","undefined","void"]);function TG(e){return e instanceof Error?e.message:String(e)}class xx{context;types;registry;constructor(e,t){this.context=t;let r={};this.registry=t.valueRegistry(r);for(let[i,n]of Object.entries(e))r[i]=this.lower(n,"callable-output",`/types/${Te(i)}`);for(let[i,n]of Object.entries(r))this.assertValid(n,"named-type",`/types/${Te(i)}`),r[i]=Kt(n,"named-type",this.registry);this.types=r}schema(e,t,r){let i=this.lower(e,"callable-output",r);return this.assertValid(i,t,r),Kt(i,t,this.registry)}properties(e,t){let r=e??{},i=this.facet(r,"property-facet",t),n={};for(let[o,s]of Object.entries(r)){let a=OT(s)?s:void 0,c=a?.property??(IT(s)?s:void 0);if(c!==void 0&&(c.visibility==="private"||a!==void 0))n[o]={visibility:c.visibility,...a===void 0?{}:{auto:a.options}}}return{properties:i,propertyMetadata:n}}facet(e,t,r){let i={},n=[];for(let[s,a]of Object.entries(e)){let c=`${r}/properties/${Te(s)}`,l=(OT(a)?a:void 0)?.property??(IT(a)?a:void 0),d=l===void 0?a:l.schema;if(i[s]=this.lower(d,"callable-output",c,"object-property"),l?.required??NG(d))n.push(s)}let o={type:"object",properties:i,required:n,additionalProperties:!1};return this.assertValid(o,t,r),Kt(o,t,this.registry)}lower(e,t,r,i="value"){let n;if(e instanceof p.ZodType){let o=wT(e,t,this.registry,r,{position:i,validate:!1,override:(s)=>vT(s,(a,c)=>this.resolvePathAccepts(a,c),r)});if(!o.ok)throw new xe(o.diagnostics);n=Ap(o.schema)}else n=se(e);return n}resolvePathAccepts(e,t){let r=e.map((n,o)=>this.context.resolveNodeDefinition(n,`${t}/x-astrale-path/accepts/${o}`)),i=new Set;for(let n of r){let o=`${n.origin}\x00${n.kind}\x00${n.name}`;if(i.has(o))ie("BUILDER_PATH_DUPLICATE",`${t}/x-astrale-path/accepts`,"path(...) repeats one Node Definition.");i.add(o)}return r.sort(Ue)}assertValid(e,t,r){let i=ha(e,t,this.registry,r);if(i.length>0)throw new xe(i)}}function Ap(e){if(e===null||typeof e!=="object"||Array.isArray(e))return e;let t={...e};for(let r of["$defs","dependentSchemas","patternProperties","properties"]){let i=t[r];if(i===null||typeof i!=="object"||Array.isArray(i))continue;t[r]=Object.fromEntries(Object.entries(i).map(([n,o])=>[n,Ap(o)]))}for(let r of["allOf","anyOf","oneOf","prefixItems"]){let i=t[r];if(Array.isArray(i))t[r]=i.map((n)=>Ap(n))}for(let r of["additionalProperties","contains","contentSchema","else","if","items","not","propertyNames","then","unevaluatedItems","unevaluatedProperties"]){let i=t[r];if(typeof i==="boolean"||i!==null&&typeof i==="object"&&!Array.isArray(i))t[r]=Ap(i)}if(t.type==="object"&&t.properties!==null&&typeof t.properties==="object"&&!Array.isArray(t.properties)&&!Object.hasOwn(t,"additionalProperties"))t.additionalProperties=!1;return t}function IT(e){return nr(e,"property")}function OT(e){return nr(e,"auto")}function NG(e){if(!(e instanceof p.ZodType))return!0;return!Ex(e)}class wx{context;constructor(e){this.context=e}compile(e,t){let r=e.config,i=r.target;return{...r.description===void 0?{}:{description:r.description},target:i===void 0||i==="domain"?{kind:"domain"}:{kind:"definition",definitions:(RG(i)?i:[i]).map((n,o)=>this.context.resolveNodeDefinition(n,`${t}/target/definitions/${o}`)).sort(Ue)},auth:r.auth??"required"}}}function RG(e){return Array.isArray(e)}function DT(e,t){let r=new Ro(PA(t.dependencies??[])),i=jG(e,t,r),n=Ji(i,r);return ET(t,e),n}function jG(e,t,r){if(Ve(t,["dependencies","types","interfaces","classes","functions","policies","views","core"]),t.core!==void 0)Ve(t.core,["nodes","edges"],"/core");let i=new Iu(e,t.dependencies??[]);Cx(t,i);let n=new xx(t.types??{},i),o=new gx(i),s=new Bx(i,n),a=new hx(i,n,s,o),c=new wx(i),u=Ou(t.interfaces??{},(k,G)=>a.compileInterface(k,`/interfaces/${Te(G)}`)),l=Ou(t.classes??{},(k,G)=>a.compileClass(k,`/classes/${Te(G)}`)),d=Ou(t.functions??{},(k,G)=>s.compile(k,{kind:"function",pointer:`/functions/${Te(G)}`})),f=Ou(t.policies??{},(k,G)=>o.compile(k,`/policies/${Te(G)}`));hT(f,e);let m=Ou(t.views??{},(k,G)=>c.compile(k,`/views/${Te(G)}`)),B=dT(t.core,i),h={format:"astrale.dsl",version:"v1",origin:e,dependencies:[],types:n.types,interfaces:u,classes:l,functions:d,policies:f,views:m,core:B};i.noteDomainReferences(h);let g={...h,dependencies:i.dependencies()},w={...g,core:pT(g,r)},b=ya(w),O=ya(Xf(b));return No(O)}function Ou(e,t){return Object.fromEntries(Object.entries(e).map(([r,i])=>[r,t(i,r)]))}function $p(e,t){return DT(e,t)}var Y={};ze(Y,{Error:()=>xe,FORMAT:()=>ca,VERSION:()=>ua,accept:()=>Ji,compareDependencyMeaning:()=>$T,compareMemberMeaning:()=>TT,decode:()=>_T,encode:()=>ST,metadata:()=>Op,patterns:()=>Av,readHeader:()=>FT,resolve:()=>jn,revision:()=>mt,serialize:()=>kT,typeUri:()=>Bn,values:()=>_x});function _T(e,t=rp()){try{return Ji(te.decode(e),t)}catch(r){if(r instanceof te.DecodeError)throw new xe([_("DV_JSON_VALUE","",r.message)]);throw r}}function kT(e){return te.serialize(e)}function ST(e){return te.encode(e)}var AT=new WeakMap;function jn(e){let t=AT.get(e);if(t!==void 0)return t;let r=HG(e,pp(e));return AT.set(e,r),r}function HG(e,t){let r=xp(e,t);if(r.diagnostics.length>0)throw new xe(r.diagnostics);let i=Object.freeze({definitions:r.context.definitions,effectiveDefinitions:r.analysis.definitions,definition:(n)=>r.context.resolve(n),effective:(n)=>r.analysis.definitions.get(Q(n))});return Object.freeze({$:Object.freeze({schema:e,revision:mt(e),closure:Object.freeze([...r.context.dependencies.values()].sort((n,o)=>lt(n.origin,o.origin))),refs:i})})}var VG=new Set(["$comment","contentEncoding","contentMediaType","contentSchema","default","deprecated","description","examples","format","readOnly","title","writeOnly"]);function $T(e,t){let r=jn(e),i=r.$.closure.find((s)=>s.origin===t.origin);if(i===void 0)throw new xe([_("DM_DEPENDENCY_NOT_RETAINED","/target/origin",`Domain ${e.origin} was not admitted with a dependency at ${t.origin}.`)]);let n=new Map([[e.origin,e],...r.$.closure.map((s)=>[s.origin,s])]),o=qG(e,i.origin,n);return NT(i,t,o)}function TT(e,t,r){if(e.origin!==t.origin)throw new xe([_("DM_MEMBER_ORIGIN_MISMATCH","/target/origin",`Member comparison target ${t.origin} does not match source ${e.origin}.`)]);if(!Array.isArray(r)||r.length===0||new Set(r).size!==r.length)throw new xe([_("DM_MEMBER_ROOT_INVALID","/roots","Member comparison roots must be one non-empty duplicate-free Key set.")]);let i=jn(e),n=new Map([[e.origin,e],...i.$.closure.map((a)=>[a.origin,a])]),o=r.map((a,c)=>tH(e,a,c)),s=RT(o,e.origin,n);return NT(e,t,s)}function NT(e,t,r){jn(t);let i=Object.freeze([...r.keys()].sort(lt)),n=[],o=[];for(let l of i){let d=r.get(l),f=Rp(t,d.coordinate),m=f===void 0?void 0:Ox(f);if(o.push([l,d.fingerprint,m??null]),m===void 0)n.push(Object.freeze({key:l,kind:"missing",sourceFingerprint:d.fingerprint}));else if(m!==d.fingerprint)n.push(Object.freeze({key:l,kind:"changed",sourceFingerprint:d.fingerprint,targetFingerprint:m}))}let s=mt(e),a=mt(t),c=Object.freeze(n),u=Ox({version:1,dependency:e.origin,source:s,target:a,coordinates:o});return Object.freeze({version:1,dependency:e.origin,source:s,target:a,footprint:i,changes:c,fingerprint:u})}function qG(e,t,r){return RT(ZG(e).map(jp),t,r)}function RT(e,t,r){let i=new Map,n=[],o=new Set;for(let s of e){if(s.kind==="member"){n.push(s.ref);continue}let a=r.get(Z.origin(s.key)),c=a===void 0?void 0:Rp(a,s);if(a===void 0||c===void 0)throw new xe([_("DM_MEMBER_ROOT_INVALID","/roots",`Member comparison root ${s.key} does not exist in its source context.`,s.key)]);Np(i,t,s,c),JG(a,s,(u)=>n.push(Tp(u)))}for(let s=0;s<n.length;s+=1){let a=n[s],c=Q(a);if(o.has(c))continue;o.add(c);let u=r.get(a.origin);if(u===void 0)throw new xe([_("DM_DEPENDENCY_CONTEXT_INVALID","",`Retained acceptance context cannot resolve ${Z.fromSchema(a)}.`,String(Z.fromSchema(a)))]);let l=jp(a),d=Rp(u,l);if(d===void 0)throw new xe([_("DM_DEPENDENCY_CONTEXT_INVALID","",`Retained acceptance context has no meaning for ${l.key}.`,l.key)]);if(Np(i,t,l,d),WG(u,a,(m)=>n.push(Tp(m))),!nH(a))continue;let f=jn(u).$.refs.effective(a);if(f===void 0)continue;KG(f,t,i,(m)=>n.push(Tp(m)))}return i}function JG(e,t,r){let i=jn(e).$.refs.effective(t.owner);if(i===void 0)return;if(t.kind==="property"){let o=i.properties.get(t.key);if(o!==void 0)hn(zr(o.schema),r);return}let n=[...i.methods.values()].find((o)=>zp(o.owner,o.name)===t.key);if(n!==void 0)qi(Lp(n.declaration),r)}function KG(e,t,r,i){for(let n of e.properties.values()){let o=zT(n.owner,n.name);Np(r,t,o,jT(n)),i(n.owner),hn(zr(n.schema),i)}for(let n of e.methods.values()){let o=MT(n.owner,n.name);Np(r,t,o,PT(n)),i(n.owner),qi(Lp(n.declaration),i)}}function Np(e,t,r,i){if(Z.origin(r.key)!==t)return;let n=Ox(i),o=e.get(r.key);if(o!==void 0&&o.fingerprint!==n)throw new xe([_("DM_MEANING_INCONSISTENT","",`Semantic coordinate ${r.key} produced inconsistent effective meaning.`,r.key)]);e.set(r.key,Object.freeze({coordinate:r,fingerprint:n}))}function ZG(e){let t=new Map,r=(i)=>{let n=Tp(i);t.set(Q(n),n)};for(let i of Object.values(e.types))hn(zr(i),r);for(let i of Object.values(e.interfaces))Bp(Du(i),r);for(let i of Object.values(e.classes))hp(Du(i),r);for(let i of Object.values(e.functions))qi(Pp(i),r);for(let i of Object.values(e.policies))gp(Dx(i),r);for(let i of Object.values(e.views))if(i.target.kind==="definition")i.target.definitions.forEach(r);for(let i of Object.values(e.core.nodes))r(i.class);for(let i of e.core.edges){if(r(i.class),i.source.kind!=="domain")r(i.source);if(i.target.kind!=="domain")r(i.target)}return[...t.values()].sort(Ue)}function WG(e,t,r){switch(t.kind){case"type":{let i=e.types[t.name];if(i!==void 0)hn(zr(i),r);return}case"interface":{let i=e.interfaces[t.name];if(i!==void 0)Bp(Du(i),r);return}case"class":{let i=e.classes[t.name];if(i!==void 0)hp(Du(i),r);return}case"function":{let i=e.functions[t.name];if(i!==void 0)qi(Pp(i),r);return}case"policy":{let i=e.policies[t.name];if(i!==void 0)gp(Dx(i),r);return}case"view":{let i=e.views[t.name];if(i?.target.kind==="definition")i.target.definitions.forEach(r);return}case"core":{let i=e.core.nodes[t.name];if(i===void 0)return;r(i.class);for(let n of UT(e,t.name)){if(r(n.class),n.source.kind!=="domain")r(n.source);if(n.target.kind!=="domain")r(n.target)}}}}function Rp(e,t){if(Z.origin(t.key)!==e.origin)return;if(t.kind==="member")return YG(e,t.ref);let r=jn(e).$.refs.effective(t.owner);if(r===void 0)return;if(t.kind==="property"){let n=r.properties.get(t.key);return n===void 0?void 0:jT(n)}let i=[...r.methods.values()].find((n)=>zp(n.owner,n.name)===t.key);return i===void 0?void 0:PT(i)}function YG(e,t){if(t.origin!==e.origin)return;switch(t.kind){case"type":{let r=e.types[t.name];return r===void 0?void 0:{kind:t.kind,schema:zr(r)}}case"interface":case"class":return QG(e,t);case"function":{let r=e.functions[t.name];return r===void 0?void 0:{kind:t.kind,declaration:Pp(r)}}case"policy":{let r=e.policies[t.name];return r===void 0?void 0:{kind:t.kind,declaration:Dx(r)}}case"view":{let r=e.views[t.name];return r===void 0?void 0:{kind:t.kind,declaration:eH(r)}}case"core":{let r=e.core.nodes[t.name];return r===void 0?void 0:{kind:t.kind,node:r,edges:UT(e,t.name)}}}}function QG(e,t){let r=jn(e),i=r.$.refs.definition(t),n=r.$.refs.effective(t);if(i===void 0||n===void 0||i.owner!==e)return;return{kind:t.kind,declaration:Du(i.declaration),effective:{properties:[...n.properties.keys()].sort(lt),methods:[...n.methods.values()].map((o)=>zp(o.owner,o.name)).sort(lt),...n.data===void 0?{}:{data:{owner:Z.fromSchema(n.data.owner),declaration:n.data.declaration}}}}}function jT(e){return{kind:"property",owner:Z.fromSchema(e.owner),name:e.name,schema:zr(e.schema),required:e.required,visibility:e.visibility}}function PT(e){return{kind:"method",owner:Z.fromSchema(e.owner),name:e.name,declaration:Lp(e.declaration)}}function Du(e){let{description:t,...r}=e,i={...r,properties:zr(e.properties)};if("methods"in e)i.methods=Object.fromEntries(Object.entries(e.methods).map(([n,o])=>[n,Lp(o)]));return i}function Pp(e){let{description:t,...r}=e;return{...r,input:zr(e.input),output:XG(e.output)}}function Lp(e){return{...Pp(e),static:e.static,inheritance:e.inheritance}}function XG(e){switch(e.mode){case"value":return{mode:"value",schema:zr(e.schema)};case"stream":return{mode:"stream",item:zr(e.item)};case"binary":return{mode:"binary"}}}function Dx(e){let{description:t,...r}=e;return r}function eH(e){let{description:t,...r}=e;return r}function zr(e){if(typeof e==="boolean")return e;let t={};for(let[r,i]of Object.entries(e)){if(VG.has(r))continue;if(Vi.has(r)&&Ix(i))t[r]=zr(i);else if(Gi.has(r)&&Array.isArray(i))t[r]=i.map((n)=>Ix(n)?zr(n):n);else if(Hi.has(r)&&ye(i))t[r]=Object.fromEntries(Object.entries(i).map(([n,o])=>[n,Ix(o)?zr(o):o]));else t[r]=i}return t}function tH(e,t,r){let i;try{i=Z(t)}catch{return Ea(t,r,"is not a canonical semantic Key")}if(Z.origin(i)!==e.origin)return Ea(i,r,`belongs to ${Z.origin(i)}, not source ${e.origin}`);let n=Z.ref(i),o;if(ne.isProperty(n)||ne.isMethod(n)){let s=LT(e,ne.namespace(n),ne.member(n)),a=ne.child(n);if(s===void 0||a===void 0)return Ea(i,r,"has no exact owning Definition");o=ne.isProperty(n)?zT(s,a):MT(s,a)}else if(ne.isDefinition(n)){let s=rH(e,n);if(s===void 0)return Ea(i,r,"does not exist in the source");o=jp(s)}else if(n.startsWith("core."))o=jp({origin:e.origin,kind:"core",name:ne.member(n)});else return Ea(i,r,"is not an independently comparable V1 member");if(Rp(e,o)===void 0)return Ea(i,r,"does not exist in the source");return o}function rH(e,t){let r=ne.namespace(t),i=ne.member(t),n=LT(e,r,i);if(n!==void 0)return n;switch(r){case"type":return e.types[i]===void 0?void 0:{origin:e.origin,kind:"type",name:i};case"function":return e.functions[i]===void 0?void 0:{origin:e.origin,kind:"function",name:i};case"policy":return e.policies[i]===void 0?void 0:{origin:e.origin,kind:"policy",name:i};case"view":return e.views[i]===void 0?void 0:{origin:e.origin,kind:"view",name:i};default:return}}function LT(e,t,r){if(t==="class")return e.classes[r]===void 0?void 0:{origin:e.origin,kind:"class",name:r};if(t==="interface")return e.interfaces[r]===void 0?void 0:{origin:e.origin,kind:"interface",name:r};return}function Ea(e,t,r){throw new xe([_("DM_MEMBER_ROOT_INVALID",`/roots/${t}`,`Member comparison root ${JSON.stringify(e)} ${r}.`,typeof e==="string"?e:void 0)])}function jp(e){return Object.freeze({kind:"member",key:Z.fromSchema(e),ref:e})}function zT(e,t){return Object.freeze({kind:"property",key:Pe.of(e,t),owner:e,name:t})}function MT(e,t){return Object.freeze({kind:"method",key:zp(e,t),owner:e,name:t})}function zp(e,t){return Z.of(e.origin,ne.method(ne.fromSchema(e),t))}function UT(e,t){return e.core.edges.filter((r)=>r.source.kind==="core"&&r.source.name===t||r.target.kind==="core"&&r.target.name===t)}function Ox(e){return tp(te.encode(e))}function nH(e){switch(e.kind){case"interface":case"class":return!0;default:return!1}}function Tp(e){switch(e.kind){case"type":case"interface":case"class":case"function":case"policy":case"view":case"core":return e;default:throw new xe([_("DM_DEPENDENCY_CONTEXT_INVALID","",`Semantic reference kind ${JSON.stringify(e.kind)} is outside V1.`)])}}function Ix(e){return typeof e==="boolean"||ye(e)}function FT(e){let t;try{t=se(e)}catch(i){if(i instanceof he)throw new xe([_("DV_JSON_VALUE",i.pointer,i.message)]);throw i}let r=Ca(t);return Object.freeze({dependencies:Object.freeze([...r.dependencies]),origin:r.origin})}var _x={};ze(_x,{DIALECT:()=>Po,VOCABULARY:()=>uA,classifyOrdering:()=>oH,instant:()=>yA,validate:()=>iH});var GT=new WeakMap;function iH(e,t,r,i=""){return dp(t,r,HT(e),i)}function oH(e,t){return yp(t,HT(e))}function HT(e){let t=GT.get(e);if(t===void 0)t=FA(e),GT.set(e,t);return t}var Mr={};ze(Mr,{FORMAT:()=>_u,VERSION:()=>ku,accept:()=>lH,create:()=>uH,decode:()=>dH,encode:()=>fH,serialize:()=>pH});var _u="astrale.dsl.bundle",ku="v1";function VT(e){return kx(e,da(e).map(({schema:t})=>t))}function kx(e,t){return No({format:_u,version:ku,root:e,closure:[...t]})}function KT(e){if(!sH(e))throw new xe([_("BUNDLE_STRUCTURE","","DomainSchemaBundle must be an object.")]);let t=[],r=new Set(["format","version","root","closure"]);for(let o of Object.keys(e))if(!r.has(o))t.push(_("BUNDLE_STRUCTURE",`/${aH(o)}`,`Unknown bundle field ${o}.`));for(let o of r)if(!(o in e))t.push(_("BUNDLE_STRUCTURE",`/${o}`,`Missing bundle field ${o}.`));if(e.format!==_u)t.push(_("UNSUPPORTED_BUNDLE_FORMAT","/format",`Unsupported DomainSchemaBundle format ${JT(e.format)}.`));if(e.version!==ku)t.push(_("UNSUPPORTED_BUNDLE_VERSION","/version",`Unsupported DomainSchemaBundle version ${JT(e.version)}.`));let i=qT(e.root,"/root",t),n=[];if(!Array.isArray(e.closure))t.push(_("BUNDLE_STRUCTURE","/closure","DomainSchemaBundle closure must be an array."));else for(let[o,s]of e.closure.entries()){let a=qT(s,`/closure/${o}`,t);if(a!==void 0)n.push(a)}if(t.length>0)throw new xe(t);if(i===void 0)throw new xe([_("BUNDLE_STRUCTURE","/root","DomainSchemaBundle root is missing.")]);return Object.freeze({root:i,closure:Object.freeze(n)})}function qT(e,t,r){if(e===void 0)return;try{return Ca(e)}catch(i){if(!(i instanceof xe))throw i;r.push(...i.diagnostics.map((n)=>_(n.code,`${t}${n.pointer}`,n.message,n.ref)));return}}function sH(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}function JT(e){return e===void 0?"(missing)":JSON.stringify(e)}function aH(e){return e.replaceAll("~","~0").replaceAll("/","~1")}function WT(e){let t;try{t=se(e)}catch(r){if(r instanceof he)throw new xe([_("DV_JSON_VALUE",r.pointer,r.message)]);throw r}return eN(t)}function YT(e){try{return eN(te.decode(e))}catch(t){if(t instanceof te.DecodeError)throw new xe([_("DV_JSON_VALUE","",t.message)]);throw t}}function QT(e){return te.serialize(e)}function XT(e){return te.encode(e)}function eN(e){let t=KT(e),r=ZT(t.root,"/root"),i=t.closure.map((d,f)=>ZT(d,`/closure/${f}`)),n=[],o=new Map;for(let d of i){if(d.key===r.key){n.push(_("BUNDLE_ROOT_DUPLICATED",d.pointer,"The root schema must not also appear in the bundle closure."));continue}let f=o.get(d.key);if(f!==void 0){n.push(_("BUNDLE_SCHEMA_DUPLICATED",d.pointer,`Schema ${d.schema.origin}@${d.revision} duplicates ${f.pointer}.`));continue}o.set(d.key,d)}let s=new Set;tN(r,r,o,s,new Set,new Map,n);for(let d of o.values())if(!s.has(d.key))n.push(_("BUNDLE_CLOSURE_EXTRA",d.pointer,`Schema ${d.schema.origin}@${d.revision} is not reachable from the root.`));if(n.length>0)throw new xe(n);let a=new Map,c=(d)=>{let f=a.get(d.key);if(f!==void 0)return f.schema;for(let m of d.schema.dependencies){let B=o.get(Sx(m.origin,m.revision));if(B!==void 0)c(B)}try{let m=Ji(d.schema,new Ro([...a.values()])),B=mt(m);if(B!==d.revision)throw new xe([_("BUNDLE_SCHEMA_REVISION","",`Accepted schema revision ${B} differs from indexed revision ${d.revision}.`)]);return a.set(d.key,{schema:m,revision:B}),m}catch(m){if(!(m instanceof xe))throw m;throw new xe(m.diagnostics.map((B)=>_(B.code,`${d.pointer}${B.pointer}`,B.message,B.ref)))}};for(let d of o.values())if(s.has(d.key))c(d);let u=c(r),l=[...s].map((d)=>a.get(d)?.schema).filter((d)=>d!==void 0).sort(cH);return kx(u,l)}function ZT(e,t){let r=uu(e);return{schema:e,revision:r.revision,key:Sx(e.origin,r.revision),pointer:t}}function tN(e,t,r,i,n,o,s){if(n.has(e.key)){s.push(_("BUNDLE_CLOSURE_CYCLE",e.pointer,`Bundle dependency cycle reaches ${e.schema.origin}@${e.revision}.`));return}n.add(e.key);for(let[a,c]of e.schema.dependencies.entries()){let u=`${e.pointer}/dependencies/${a}`,l=Sx(c.origin,c.revision);if(l===t.key){s.push(_("BUNDLE_CLOSURE_CYCLE",u,"Bundle dependency closure returns to its root."));continue}let d=o.get(c.origin);if(d!==void 0&&d!==c.revision)s.push(_("BUNDLE_REVISION_COHERENCE",u,`Bundle requires ${c.origin} at both ${d} and ${c.revision}.`));else o.set(c.origin,c.revision);let f=r.get(l);if(f===void 0){s.push(_("BUNDLE_CLOSURE_MISSING",u,`Bundle has no exact ${c.origin}@${c.revision}.`));continue}i.add(f.key),tN(f,t,r,i,n,o,s)}n.delete(e.key)}function cH(e,t){return lt(e.origin,t.origin)||lt(mt(e),mt(t))}function Sx(e,t){return`${e}\x00${t}`}function uH(e){return VT(e)}function lH(e){return WT(e)}function dH(e){return YT(e)}function fH(e){return XT(e)}function pH(e){return QT(e)}var mH=255,BH=/[^A-Za-z0-9._-]/u,rN="NodeId must be 1-255 ASCII characters drawn from [A-Za-z0-9._-].";class Mp extends TypeError{input;code="NODE_ID_INVALID";constructor(e){super(rN);this.input=e,this.name="NodeIdError"}}function Fe(e){if(!nn(e))throw new Mp(e);return e}function nn(e){return typeof e==="string"&&e.length>0&&e.length<=mH&&!BH.test(e)}var cae=p.string().refine(nn,rN).transform((e)=>e);var nN=new TextEncoder;function At(e,t){let r=nN.encode(e),i=nN.encode(t),n=Math.min(r.length,i.length);for(let o=0;o<n;o++){let s=r[o]-i[o];if(s!==0)return Math.sign(s)}return Math.sign(r.length-i.length)}function Su(e){return Object.freeze({id:e.id,class:e.class,props:e.props})}var Vp={};ze(Vp,{accept:()=>Fp,acceptUnresolved:()=>zx,canonicalize:()=>Gp,limits:()=>Lx,self:()=>Rx});var va=32,on=64;function Up(e){try{return Au(se(e),"",0)}catch(t){if(t instanceof be)throw t;throw new be("AUTH_GRANT_INVALID","Expected a resolved Identity expression","",{cause:t})}}function Tx(e,t,r){return Au(e,t,r)}function Au(e,t,r){if(r>va)li(t,"Identity expression exceeds its depth limit");let i=hH(e,t);switch(i.kind){case"identity":if(Ax(i,["id","kind"],t),typeof i.id!=="string")li(`${t}/id`,"Expected a NodeId");return Object.freeze({kind:"identity",id:Fe(i.id)});case"union":case"intersect":{Ax(i,["kind","operands"],t);let n=oN(i.operands,`${t}/operands`,2),o=i.kind,s=iN(n.map((a,c)=>Au(a,`${t}/operands/${c}`,r+1)).flatMap((a)=>a.kind===o?a.operands:[a]));if(s.length>on)li(`${t}/operands`,`Expected 2-${on} operands`);return s.length===1?s[0]:Object.freeze({kind:o,operands:Object.freeze(s)})}case"exclude":{Ax(i,["base","excluded","kind"],t);let n=iN(oN(i.excluded,`${t}/excluded`,1).map((o,s)=>Au(o,`${t}/excluded/${s}`,r+1)).flatMap((o)=>o.kind==="union"?o.operands:[o]));if(n.length>on)li(`${t}/excluded`,`Expected 1-${on} operands`);return Object.freeze({kind:"exclude",base:Au(gH(i.base,`${t}/base`),`${t}/base`,r+1),excluded:Object.freeze(n)})}default:li(`${t}/kind`,"Expected identity, union, intersect, or exclude")}}function iN(e){let t=e.map((r)=>({expr:r,key:te.serialize(r)})).sort((r,i)=>$x(r.key,i.key));return t.filter((r,i)=>i===0||r.key!==t[i-1].key).map((r)=>r.expr)}function hH(e,t){if(e===null||Array.isArray(e)||typeof e!=="object")li(t,"Expected an object");return e}function oN(e,t,r){if(!Array.isArray(e)||e.length<r||e.length>on)li(t,`Expected ${r}-${on} operands`);return e}function gH(e,t){if(e===void 0)li(t,"Expected a value");return e}function Ax(e,t,r){let i=Object.keys(e).sort($x),n=[...t].sort($x);if(i.length!==n.length||i.some((o,s)=>o!==n[s]))li(r,`Expected exactly ${t.join(", ")}`)}function $x(e,t){return e<t?-1:e>t?1:0}function li(e,t){throw new be("AUTH_GRANT_INVALID",t,e)}function Fp(e){try{let t=se(e);if(t===null||Array.isArray(t)||typeof t!=="object")Nx("","Expected a Grant object");let r=t;if(CH(r,["expr"],""),r.expr===void 0)Nx("/expr","Expected a resolved Identity expression");return Object.freeze({expr:Tx(r.expr,"/expr",0)})}catch(t){if(t instanceof be)throw t;throw new be("AUTH_GRANT_INVALID","Expected a canonical resolved Grant","",{cause:t})}}function Gp(e){return Object.freeze({expr:Up(e.expr)})}function CH(e,t,r){let i=Object.keys(e).sort(sN),n=[...t].sort(sN);if(i.length!==n.length||i.some((o,s)=>o!==n[s]))Nx(r,`Expected exactly ${t.join(", ")}`)}function sN(e,t){return e<t?-1:e>t?1:0}function Nx(e,t){throw new be("AUTH_GRANT_INVALID",t,e)}function Rx(e){return Object.freeze({expr:Object.freeze({kind:"identity",id:Fe(e)})})}var jx=3,Px=65536,Lx=Object.freeze({expressionDepth:va,operandsPerExpression:on,credentialNestingDepth:jx});function zx(e){try{let t=lN(e,"");if($u(t,["expr","v"],""),Zi(t,"v","/v")!==1)sr("/v","Unsupported unresolved Grant version");return Object.freeze({v:1,expr:Hp(Zi(t,"expr","/expr"),"/expr",0,0,new WeakSet)})}catch(t){if(t instanceof be)throw t;throw new be("AUTH_GRANT_INVALID","Expected a bounded unresolved Grant","",{cause:t})}}function Hp(e,t,r,i,n){if(r>va)sr(t,"Identity expression exceeds its depth limit");let o=lN(e,t);if(n.has(o))sr(t,"Cyclic Identity expressions are not supported");n.add(o);try{let s=Zi(o,"kind",`${t}/kind`);switch(s){case"identity":{let a=aN(o,"self"),c=aN(o,"credential");if(a===c)sr(t,"Expected exactly one unresolved Identity leaf");if(a){if($u(o,["kind","self"],t),Zi(o,"self",`${t}/self`)!==!0)sr(`${t}/self`,"Expected true");return Object.freeze({kind:"identity",self:!0})}if($u(o,["credential","kind"],t),i>=jx)sr(`${t}/credential`,"Credential nesting exceeds its limit");return Object.freeze({kind:"identity",credential:bH(Zi(o,"credential",`${t}/credential`),`${t}/credential`)})}case"union":case"intersect":{$u(o,["kind","operands"],t);let a=cN(Zi(o,"operands",`${t}/operands`),`${t}/operands`,2);return Object.freeze({kind:s,operands:Object.freeze(a.map((c,u)=>Hp(c,`${t}/operands/${u}`,r+1,i,n)))})}case"exclude":{$u(o,["base","excluded","kind"],t);let a=cN(Zi(o,"excluded",`${t}/excluded`),`${t}/excluded`,1);return Object.freeze({kind:"exclude",base:Hp(Zi(o,"base",`${t}/base`),`${t}/base`,r+1,i,n),excluded:Object.freeze(a.map((c,u)=>Hp(c,`${t}/excluded/${u}`,r+1,i,n)))})}default:sr(`${t}/kind`,"Expected identity, union, intersect, or exclude")}}finally{n.delete(o)}}function bH(e,t){if(typeof e==="string"){if(e.length===0||new TextEncoder().encode(e).byteLength>Px)sr(t,"Credential size is outside its supported budget");return e}if(!(e instanceof Uint8Array)||e.byteLength===0||e.byteLength>Px)sr(t,"Expected non-empty credential text or bytes");return e.slice()}function lN(e,t){if(typeof e!=="object"||e===null||Array.isArray(e))sr(t,"Expected an object");let r=Object.getPrototypeOf(e);if(r!==null&&Object.getPrototypeOf(r)!==null)sr(t,"Expected a plain record-like object");return e}function Zi(e,t,r){let i=Object.getOwnPropertyDescriptor(e,t);if(i===void 0||!i.enumerable||!("value"in i))sr(r,"Expected an enumerable data property");return i.value}function aN(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function $u(e,t,r){let i=Reflect.ownKeys(e);if(i.some((s)=>typeof s!=="string"))sr(r,"Symbol fields are not supported");let n=i.sort(uN),o=[...t].sort(uN);if(n.length!==o.length||n.some((s,a)=>s!==o[a]))sr(r,`Expected exactly ${t.join(", ")}`)}function cN(e,t,r){if(!Array.isArray(e)||e.length<r||e.length>on)sr(t,`Expected ${r}-${on} operands`);if(Object.keys(e).length!==e.length)sr(t,"Expected a dense array");return e}function uN(e,t){return e<t?-1:e>t?1:0}function sr(e,t){throw new be("AUTH_GRANT_INVALID",t,e)}var qp=Object.freeze({expressionDepth:64,operandsPerExpression:512,localsPerExpression:64,repeatMaximum:16}),Kae=qp.operandsPerExpression;var Kp={};ze(Kp,{MAX_REQUIRED_CLAIMS:()=>Tu,matches:()=>Nu,verifyRequired:()=>Jp});var Tu=64;function Nu(e,t){let r=t[e.claim];switch(e.op){case"exists":return Object.hasOwn(t,e.claim);case"eq":return r!==void 0&&pN(r,e.value);case"contains":return Array.isArray(r)&&r.some((i)=>pN(i,e.value))}}function pN(e,t){return te.serialize(e)===te.serialize(t)}function Jp(e,t){for(let r=0;r<e.length;r++)if(!Nu(e[r],t))throw TypeError(`Verified claims do not satisfy required constraint ${r}.`)}var Lce=new TextDecoder("utf-8",{fatal:!0});var ht={};ze(ht,{accept:()=>Wi,is:()=>Ux});var OH=/^(?=.{1,253}$)(?:(?!-)[a-z0-9-]{1,63}(?<!-)\.)+(?:(?!-)[a-z0-9-]{2,63}(?<!-))$/i,DH=/^([a-z][a-z0-9+.-]*):(.*)$/i,_H=Object.freeze({http:"80",https:"443"});function Wi(e){if(typeof e!=="string")AH();try{return kH(e)}catch(t){if(t instanceof be)throw t;throw new be("AUTH_ISSUER_INVALID","Expected a supported issuer identifier","",{cause:t})}}function Ux(e){if(typeof e!=="string")return!1;try{return Wi(e)===e}catch{return!1}}function kH(e){let t=e.trim();if(t.length===0)throw TypeError("Issuer cannot be empty");if(OH.test(t))return t.toLowerCase();let r=DH.exec(t);if(r===null||r[2].length===0)throw TypeError("Issuer must be absolute");let i=r[1].toLowerCase(),n=r[2];if(!n.startsWith("//"))return`${i}:${n}`;let o=n.slice(2),s=o.search(/[/?#]/),a=s<0?o:o.slice(0,s),c=s<0?"":o.slice(s),u=c==="/"?"":c;if(a.length===0)throw TypeError("Issuer authority cannot be empty");return`${i}://${SH(a,i)}${u}`}function SH(e,t){let r=e.lastIndexOf("@"),i=r<0?"":e.slice(0,r+1),n=r<0?e:e.slice(r+1),o,s;if(n.startsWith("[")){let a=n.indexOf("]");if(a<0)throw TypeError("Issuer has an invalid IPv6 authority");if(o=n.slice(0,a+1).toLowerCase(),s=n.slice(a+1),s!==""&&!/^:\d+$/u.test(s))throw TypeError("Issuer has an invalid port")}else{let a=n.indexOf(":"),c=n.lastIndexOf(":");if(a!==c)throw TypeError("Issuer IPv6 authority must be bracketed");if(o=(c<0?n:n.slice(0,c)).toLowerCase(),s=c<0?"":n.slice(c),s!==""&&!/^:\d+$/u.test(s))throw TypeError("Issuer has an invalid port")}if(o.length===0)throw TypeError("Issuer host cannot be empty");if(s.startsWith(":")&&_H[t]===s.slice(1))s="";return`${i}${o}${s}`}function AH(){throw new be("AUTH_ISSUER_INVALID","Expected a supported issuer identifier")}var yN=/^\/:([^:]+):class\.([A-Za-z][A-Za-z0-9_]*)$/u,Ze=Object.freeze({parse(e){if(!xa(e))throw new di(e);return e},from(e,t){if(typeof e==="string"){if(t===void 0)throw new di(e);return Ze.parse(`/:${e}:class.${t}`)}if(e.kind!=="class")throw new di(e);return Ze.parse(`/:${e.origin}:class.${e.name}`)},origin(e){return gN(e).origin},name(e){return gN(e).name}});function xa(e){if(typeof e!=="string")return!1;let t=yN.exec(e);return t!==null&&t[1].length<=253&&Y.patterns.origin.test(t[1])&&Y.patterns.memberName.test(t[2])}class di extends TypeError{input;code="CLASS_PATH_INVALID";constructor(e){super(`Invalid canonical ClassPath: ${JH(e)}.`);this.input=e,this.name="ClassPathError"}}function gN(e){let t=yN.exec(e);if(t===null)throw new di(e);return{origin:t[1],name:t[2]}}function JH(e){try{return JSON.stringify(e)??String(e)}catch{return String(e)}}var fi=Object.freeze({type:"string",minLength:1,maxLength:255,fullMatch:"[A-Za-z0-9]([A-Za-z0-9._-]{0,253}[A-Za-z0-9])?"}),KH=/^[A-Za-z0-9](?:[A-Za-z0-9._-]{0,253}[A-Za-z0-9])?$/u;class Fx extends TypeError{input;code="EDGE_SLUG_INVALID";constructor(e){super("EdgeSlug must contain 1 to 255 ASCII characters, start and end with an alphanumeric character, and use only alphanumeric, dot, underscore, or hyphen characters.");this.input=e,this.name="EdgeSlugError"}}function Jo(e){return typeof e==="string"&&e.length<=255&&KH.test(e)}function Pn(e){if(!Jo(e))throw new Fx(e);return e}class Ko extends TypeError{input;code="PATH_INVALID";diagnostics;constructor(e,t){super(t[0].message);this.input=e,this.name="PathError",this.diagnostics=Object.freeze(t.map((r)=>Object.freeze(r)))}}function Yt(e,t,r,i){return new Ko(e,[{code:t,message:r,...i===void 0?{}:{position:i}}])}var ZH=new Set(["class","interface","function","policy","view","core"]);function Ru(e){if(e.length===0)throw Yt(e,"PATH_EMPTY","Path source is empty.",0);let t=e.startsWith("@")?WH(e):YH(e);if(EN(t)!==e)throw Yt(e,"PATH_NON_CANONICAL","Path source is not canonical.");return t}function gn(e){if(!Zp(e)||!Zo(e,["anchor","steps"])||!Array.isArray(e.steps))return Ut();let t=eV(e.anchor),r=[];for(let i of e.steps){if(!Zp(i)||typeof i.kind!=="string")Ut();if(i.kind==="projection"){if(!Zo(i,["kind","projection"])||t.kind!=="domain"||r.length!==0)Ut();r.push({kind:"projection",projection:tV(i.projection)});continue}if(i.kind==="method"){if(!Zo(i,["kind","dispatch","name"]))Ut();if(i.dispatch!=="static"&&i.dispatch!=="instance")Ut();if(typeof i.name!=="string"||!Y.patterns.memberName.test(i.name))Ut();if(i.dispatch==="static"){let n=r.length===1?r[0]:void 0;if(t.kind!=="domain"||n?.kind!=="projection"||n.projection.kind!=="class"&&n.projection.kind!=="interface")Ut()}r.push({kind:"method",dispatch:i.dispatch,name:i.name});continue}if(i.kind==="traverse"){let n=i.slug===void 0?["kind","direction","class"]:["kind","direction","class","slug"];if(!Zo(i,n)||r.at(-1)?.kind==="method")Ut();if(i.direction!=="out"&&i.direction!=="in")Ut();if(typeof i.class!=="string")Ut();let o;try{o=Ze.parse(i.class)}catch(a){if(a instanceof di)return Ut();throw a}let s=i.slug===void 0?void 0:rV(i.slug);r.push({kind:"traverse",direction:i.direction,class:o,...s===void 0?{}:{slug:s}});continue}throw Yt(e,"PATH_UNSUPPORTED_STEP","Path AST contains an unsupported step.")}if(r.some((i,n)=>i.kind==="method"&&n!==r.length-1))Ut();return Wp({anchor:t,steps:r})}function ju(e){return EN(gn(e))}function WH(e){let t=Vx(e,1),r=e.slice(1,t);if(!nn(r))throw Yt(e,"PATH_INVALID_NODE_ID","Id anchor is invalid.",1);return Wp({anchor:{kind:"id",id:r},steps:bN(e,t,"id")})}function YH(e){if(!e.startsWith("/:"))throw Yt(e,"PATH_UNKNOWN_FORM","Path must start with a Domain origin (`/:<domain-origin>`) or a Node ID (`@<node-id>`).",0);let t=Vx(e,2),r=e.slice(2,t);if(!vN(r))throw Yt(e,"PATH_INVALID_ORIGIN","Domain anchor contains an invalid origin.",2);return Wp({anchor:{kind:"domain",origin:r},steps:bN(e,t,"domain")})}function bN(e,t,r){let i=[],n=t;while(n<e.length){if(e.startsWith("::",n)){let c=e.slice(n+2);if(!Y.patterns.memberName.test(c))throw Yt(e,"PATH_INVALID_METHOD","Invalid instance Method name.",n+2);i.push({kind:"method",dispatch:"instance",name:c}),n=e.length;continue}if(e[n]===":"){let c=Vx(e,n+1),u=e.slice(n+1,c);if(r==="domain"&&i.length===0){i.push({kind:"projection",projection:QH(e,u,n+1)}),n=c;continue}let l=i.length===1?i[0]:void 0;if(r!=="domain"||l?.kind!=="projection"||l.projection.kind!=="class"&&l.projection.kind!=="interface"||c!==e.length||!Y.patterns.memberName.test(u))throw Yt(e,"PATH_INVALID_POSITION","Static Method is not in a valid position.",n);i.push({kind:"method",dispatch:"static",name:u}),n=c;continue}let o;if(e.startsWith("<~",n))o="in",n+=2;else if(e[n]==="~")o="out",n+=1;else throw Yt(e,"PATH_UNKNOWN_FORM","Unknown Path step.",n);let s=XH(e,n);n=s.end;let a;if(e[n]==="("){let c=e.indexOf(")",n+1);if(c<0)CN(e,n);let u=e.slice(n+1,c);if(!Jo(u))CN(e,n+1);a=Pn(u),n=c+1}i.push({kind:"traverse",direction:o,class:s.classPath,...a===void 0?{}:{slug:a}})}return i}function QH(e,t,r){let i=t.indexOf(".");if(i<1||t.indexOf(".",i+1)>=0)Gx(e,r);let n=t.slice(0,i),o=t.slice(i+1);if(!xN(n))Gx(e,r);if(n==="core"?!Y.patterns.coreSlug.test(o):!Y.patterns.memberName.test(o))Gx(e,r);return{kind:n,name:o}}function XH(e,t){if(e[t]!=='"')Hx(e,t);let r=e.indexOf('"',t+1);if(r<0)Hx(e,t);try{return{classPath:Ze.parse(e.slice(t+1,r)),end:r+1}}catch(i){if(i instanceof di)return Hx(e,t);throw i}}function eV(e){if(!Zp(e))return Ut();if(e.kind==="id"&&Zo(e,["kind","id"])&&nn(e.id))return{kind:"id",id:e.id};if(e.kind==="domain"&&Zo(e,["kind","origin"])&&vN(e.origin))return{kind:"domain",origin:e.origin};return Ut()}function tV(e){if(!Zp(e)||!Zo(e,["kind","name"]))return Ut();if(!xN(e.kind)||typeof e.name!=="string")return Ut();if(e.kind==="core"?!Y.patterns.coreSlug.test(e.name):!Y.patterns.memberName.test(e.name))return Ut();return{kind:e.kind,name:e.name}}function rV(e){if(!Jo(e))return Ut();return Pn(e)}function EN(e){let t=e.anchor.kind==="id"?`@${e.anchor.id}`:`/:${e.anchor.origin}`;for(let r of e.steps)if(r.kind==="projection")t+=`:${r.projection.kind}.${r.projection.name}`;else if(r.kind==="method")t+=`${r.dispatch==="instance"?"::":":"}${r.name}`;else if(t+=`${r.direction==="in"?"<~":"~"}"${r.class}"`,r.slug!==void 0)t+=`(${r.slug})`;return t}function Vx(e,t){for(let r=t;r<e.length;r++){let i=e[r];if(i===":"||i==="~"||i==="<")return r}return e.length}function vN(e){return typeof e==="string"&&e.length<=253&&Y.patterns.origin.test(e)}function xN(e){return typeof e==="string"&&ZH.has(e)}function Zo(e,t){let r=Object.keys(e).sort(),i=[...t].sort();return r.length===i.length&&r.every((n,o)=>n===i[o])}function Zp(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}function Wp(e){if(e===null||typeof e!=="object"||Object.isFrozen(e))return e;for(let t of Object.values(e))Wp(t);return Object.freeze(e)}function Ut(){throw Yt("<ast>","PATH_AST_INVALID","Path AST violates the V1 semantic grammar.")}function Gx(e,t){throw Yt(e,"PATH_INVALID_PROJECTION","Domain projection reference is invalid.",t)}function Hx(e,t){throw Yt(e,"PATH_INVALID_CLASS","Traversal ClassPath is invalid.",t)}function CN(e,t){throw Yt(e,"PATH_INVALID_EDGE_SLUG","Traversal Edge slug is invalid.",t)}function yn(e){return ju(Ru(e))}class q{raw;ast;constructor(){}static from(e){return e instanceof q?e:q.parse(e)}static parse(e){return pi(Ru(e))}static fromAST(e){return pi(gn(e))}static id(e){return pi(gn({anchor:{kind:"id",id:e},steps:[]}))}static domain(e){return pi(gn({anchor:{kind:"domain",origin:e},steps:[]}))}static project(e){let{origin:t,projection:r}=nV(e);return pi(gn({anchor:{kind:"domain",origin:t},steps:[{kind:"projection",projection:r}]}))}static staticMethod(e,t){if(e.projection.kind!=="class"&&e.projection.kind!=="interface")throw Yt(e.raw,"PATH_INVALID_POSITION","Static Method owner must be a Class or Interface.");return pi(gn({anchor:e.ast.anchor,steps:[...e.ast.steps,{kind:"method",dispatch:"static",name:t}]}))}static instanceMethod(e,t){return pi(gn({anchor:e.ast.anchor,steps:[...e.ast.steps,{kind:"method",dispatch:"instance",name:t}]}))}out(e,t={}){return this.traverse("out",e,t)}in(e,t={}){return this.traverse("in",e,t)}equals(e){return this.raw===e.raw}toString(){return this.raw}toJSON(){return this.raw}traverse(e,t,r){let i=r.slug===void 0?void 0:Pn(r.slug);return pi(gn({anchor:this.ast.anchor,steps:[...this.ast.steps,{kind:"traverse",direction:e,class:Ze.parse(t),...i===void 0?{}:{slug:i}}]}))}}function pi(e){let t=Object.create(q.prototype);return mi(t,"ast",e),mi(t,"raw",ju(e)),oV(t),Object.freeze(t)}function nV(e){if(typeof e==="string")return{origin:Ze.origin(e),projection:{kind:"class",name:Ze.name(e)}};let t=iV(e.kind);return{origin:e.origin,projection:{kind:t,name:e.name}}}function iV(e){return e}function oV(e){let{anchor:t,steps:r}=e.ast,i=r.at(-1);if(t.kind==="id"&&r.length===0)mi(e,"id",t.id);if(t.kind==="domain"&&r.length===0)mi(e,"origin",t.origin);if(t.kind==="domain"&&r.length===1&&r[0]?.kind==="projection")mi(e,"origin",t.origin),mi(e,"projection",r[0].projection);if(i?.kind==="method")mi(e,"dispatch",i.dispatch),mi(e,"name",i.name),mi(e,"source",pi(gn({anchor:t,steps:r.slice(0,-1)})))}function mi(e,t,r){Object.defineProperty(e,t,{enumerable:!0,value:r})}function wa(e){return Object.freeze({source:e.source,target:e.target,class:e.class,...e.slug===void 0?{}:{slug:e.slug},props:e.props})}function Cr(e,t){return At(e.source,t.source)||At(e.target,t.target)||sV(e.class,t.class)}function sV(e,t){return e<t?-1:e>t?1:0}function Ge(e){return JSON.stringify([e.source,e.target,e.class])}function it(e){return Object.freeze({source:e.source,target:e.target,class:e.class})}function ar(e,t=""){let r=se(e);if(r===null||typeof r!=="object"||Array.isArray(r))throw TypeError(`Expected Properties object at ${t||"/"}.`);let i=r,n=[];for(let o of Object.keys(i)){if(!Pe.is(o))throw TypeError(`Invalid PropertyKey ${JSON.stringify(o)} at ${t||"/"}.`);n.push([Pe(o),wN(i[o])])}return Pu(n)}function Pu(e){let t=Object.create(null);for(let[r,i]of[...e].sort(([n],[o])=>aV(n,o)))Object.defineProperty(t,r,{enumerable:!0,value:i});return Object.freeze(t)}function Ln(e,t){if(e===t)return!0;let r=Object.keys(e),i=Object.keys(t);return r.length===i.length&&r.every((n,o)=>n===i[o]&&Nr(e[Pe(n)],t[Pe(n)]))}function wN(e){if(e===null||typeof e!=="object")return e;for(let t of Object.values(e))wN(t);return Object.freeze(e)}function aV(e,t){return e<t?-1:e>t?1:0}function Kx(e,t=""){let r=se(e);if(r===null||typeof r!=="object"||Array.isArray(r)||!cV(r,["set","unset"]))throw TypeError(`Expected Property Delta object at ${t||"/"}.`);let i=ar(r.set,qx(t,"set"));if(!Array.isArray(r.unset))throw TypeError(`Expected Property Delta.unset array at ${qx(t,"unset")}.`);let n=r.unset.map((o,s)=>{if(typeof o!=="string"||!Pe.is(o))throw TypeError(`Invalid PropertyKey ${JSON.stringify(o)} at ${qx(t,`unset/${s}`)}.`);return Pe(o)});n.sort(Jx);for(let o=1;o<n.length;o+=1)if(n[o-1]===n[o])throw TypeError(`Property Delta repeats unset key ${n[o]}.`);for(let o of n)if(Object.hasOwn(i,o))throw TypeError(`Property Delta both sets and unsets ${o}.`);return IN(i,n)}function Jx(e,t){return e<t?-1:e>t?1:0}function IN(e,t){return Object.freeze({set:e,unset:Object.freeze([...t])})}function cV(e,t){let r=Object.keys(e).sort(Jx),i=[...t].sort(Jx);return r.length===i.length&&r.every((n,o)=>n===i[o])}function qx(e,t){return`${e}/${t}`}function Qp(e,t,r){let i=[...new Set([...Object.keys(e),...Object.keys(t),...Object.keys(r)])].map(Pe).sort(lV),n=[],o=[];for(let s of i){let a=Zx(e,s),c=Zx(t,s),u=Zx(r,s),l=uV(a,c,u);if(l===ON)o.push(Object.freeze({property:s}));else if(l!==Yp)n.push([s,l])}return o.length>0?Object.freeze({kind:"conflict",conflicts:Object.freeze(o)}):Object.freeze({kind:"merged",value:Pu(n)})}var Yp=Symbol("absent property"),ON=Symbol("property merge conflict");function Zx(e,t){return Object.hasOwn(e,t)?e[t]:Yp}function uV(e,t,r){if(Wx(t,e))return r;if(Wx(r,e))return t;if(Wx(t,r))return t;return ON}function Wx(e,t){if(e===Yp||t===Yp)return e===t;return Nr(e,t)}function lV(e,t){return e<t?-1:e>t?1:0}class Lu extends TypeError{diagnostics;code="GRAPH_ADMISSION_REJECTED";constructor(e){super(e.length===0?"Graph admission rejected.":`Graph admission rejected: ${e[0].code} at ${e[0].path}.`);this.diagnostics=e,this.name="GraphAdmissionError"}}function Qt(e,t,r){return Object.freeze({code:e,path:t,message:r})}function _N(e){return Object.freeze([...e].sort((t,r)=>Yx(t.path,r.path)||Yx(t.code,r.code)||Yx(t.message,r.message)))}function Yx(e,t){return e<t?-1:e>t?1:0}function Qx(e,t){let r=[],i=new Map,n=dV(e,t,i,r),o=new Map(n.map((c)=>[c.id,c])),s=fV(e,t,o,i,r);n.sort((c,u)=>At(c.id,u.id)),s.sort((c,u)=>Cr(it(c),it(u))),pV(n,r),mV(s,r);let a=_N(r);if(a.length>0)throw new Lu(a);return Object.freeze({data:Object.freeze({nodes:Object.freeze(n),edges:Object.freeze(s)}),classes:i})}function dV(e,t,r,i){if(!e||!Array.isArray(e.nodes))return i.push(Qt("GRAPH_FACT_INVALID","/nodes","Expected Node collection.")),[];return e.nodes.flatMap((n,o)=>{let s=`/nodes/${o}`;if(!n||!nn(n.id)||!xa(n.class))return i.push(Qt("GRAPH_FACT_INVALID",s,"Invalid Node fact.")),[];let a;try{a=Su({id:n.id,class:n.class,props:ar(n.props,`${s}/props`)})}catch(u){return i.push(Qt("GRAPH_FACT_INVALID",`${s}/props`,u instanceof Error?u.message:"Invalid Node properties.")),[]}let c=SN(t,a.class,`${s}/class`,r,i);if(c!==void 0&&c.kind!=="node")i.push(Qt("GRAPH_CLASS_KIND",`${s}/class`,"Node ClassPath resolves to an Edge Class."));else if(c?.orientation!==void 0)i.push(Qt("GRAPH_CLASS_ORIENTATION",`${s}/class`,"Node Class has an orientation."));if(c?.kind==="node")Xx(t.validateProperties(a.class,a.props),i);return[a]})}function fV(e,t,r,i,n){if(!e||!Array.isArray(e.edges))return n.push(Qt("GRAPH_FACT_INVALID","/edges","Expected Edge collection.")),[];return e.edges.flatMap((o,s)=>{let a=`/edges/${s}`;if(!o||!nn(o.source)||!nn(o.target)||!xa(o.class)||o.slug!==void 0&&!Jo(o.slug))return n.push(Qt("GRAPH_FACT_INVALID",a,"Invalid Edge fact.")),[];let c;try{c=ar(o.props,`${a}/props`)}catch(l){return n.push(Qt("GRAPH_FACT_INVALID",`${a}/props`,l instanceof Error?l.message:"Invalid Edge properties.")),[]}let u=SN(t,o.class,`${a}/class`,i,n);if(u!==void 0&&u.kind!=="edge")n.push(Qt("GRAPH_CLASS_KIND",`${a}/class`,"Edge ClassPath resolves to a Node Class."));else if(u?.kind==="edge"){let[l,d]=u.orientation==="undirected"&&At(o.source,o.target)>0?[o.target,o.source]:[o.source,o.target],f=wa({source:l,target:d,class:o.class,...o.slug===void 0?{}:{slug:o.slug},props:c});return Xx(t.validateProperties(f.class,f.props),n),kN(f,"source",r,t,n),kN(f,"target",r,t,n),[f]}return[wa({source:o.source,target:o.target,class:o.class,...o.slug===void 0?{}:{slug:o.slug},props:c})]})}function SN(e,t,r,i,n){let o=e.inspectClass(t);if(o===void 0){n.push(Qt("GRAPH_CLASS_UNKNOWN",r,`Unknown Class ${t}.`));return}if(!xa(o.path)||o.path!==t){n.push(Qt("GRAPH_CLASS_MISMATCH",r,"Schema context returned a different Class."));return}if(o.kind==="node"&&o.orientation!==void 0||o.kind==="edge"&&o.orientation!=="directed"&&o.orientation!=="undirected"){n.push(Qt("GRAPH_CLASS_INVALID",r,"Schema context returned invalid Graph Class information."));return}let s=o.kind==="edge"?Object.freeze({path:o.path,kind:o.kind,orientation:o.orientation}):Object.freeze({path:o.path,kind:o.kind});return i.set(t,s),s}function kN(e,t,r,i,n){let o=r.get(e[t]);if(o===void 0)return;Xx(i.validateEndpoint(e.class,t,o.class),n)}function Xx(e,t){for(let r of e)if(r&&typeof r.code==="string"&&typeof r.path==="string"&&typeof r.message==="string")t.push(Qt(r.code,r.path,r.message));else t.push(Qt("GRAPH_CONTEXT_INVALID","",`Schema context returned an invalid diagnostic: ${BV(r)}.`))}function pV(e,t){for(let r=1;r<e.length;r++)if(e[r-1].id===e[r].id)t.push(Qt("GRAPH_NODE_DUPLICATE",`/nodes/${r}/id`,`Duplicate NodeId ${e[r].id}.`))}function mV(e,t){let r=new Set;for(let i=0;i<e.length;i++){let n=Ge(it(e[i]));if(r.has(n))t.push(Qt("GRAPH_EDGE_DUPLICATE",`/edges/${i}`,"Duplicate normalized EdgeKey."));r.add(n)}}function BV(e){try{return te.serialize(e)}catch{return"<non-json>"}}function AN(e,t){let r=new Map(e.nodes.all.map((u)=>[u.id,u])),i=[],n=[],o=[];for(let u of t.nodes.all){let l=r.get(u.id);if(l===void 0)i.push(u);else if(l.class!==u.class)o.push(Object.freeze({kind:"node-class",node:u.id,left:l.class,right:u.class}));else if(!Ln(l.props,u.props))n.push(u)}let s=new Map(e.edges.all.map((u)=>[Ge(it(u)),u])),a=[],c=[];for(let u of t.edges.all){let l=s.get(Ge(it(u)));if(l===void 0)a.push(u);else if(l.slug!==u.slug||!Ln(l.props,u.props))c.push(u)}if(o.length>0)return Object.freeze({kind:"conflict",conflicts:Object.freeze(o)});return Object.freeze({kind:"delta",value:Object.freeze({additions:ew(i,a),replacements:ew(n,c)})})}function $N(e,t){let r=new Map(e.nodes.all.map((n)=>[n.id,n])),i=new Map(e.edges.all.map((n)=>[Ge(it(n)),n]));for(let n of t.additions.nodes){if(r.has(n.id))zu(`Graph Delta adds existing Node ${n.id}.`);r.set(n.id,n)}for(let n of t.replacements.nodes){let o=r.get(n.id);if(o===void 0)zu(`Graph Delta replaces absent Node ${n.id}.`);if(o.class!==n.class)zu(`Graph Delta changes Node ${n.id} Class.`);r.set(n.id,n)}for(let n of t.additions.edges){let o=Ge(it(n));if(i.has(o))zu(`Graph Delta adds existing Edge ${o}.`);i.set(o,n)}for(let n of t.replacements.edges){let o=Ge(it(n));if(!i.has(o))zu(`Graph Delta replaces absent Edge ${o}.`);i.set(o,n)}return ew([...r.values()].sort((n,o)=>At(n.id,o.id)),[...i.values()].sort((n,o)=>Cr(it(n),it(o))))}function ew(e,t){return Object.freeze({nodes:Object.freeze(e),edges:Object.freeze(t)})}function zu(e){throw TypeError(e)}var hV=Object.freeze([]),TN=Object.freeze([]);function rw(e,t,r){let i=Object.freeze({all:e,length:e.length,byId:(o)=>r.nodes.byId.get(o),byClass:(o)=>r.nodes.byClass.get(o)??hV}),n=Object.freeze({all:t,length:t.length,byKey:(o)=>r.edges.byKey.get(Ge(gV(o,r.classes))),byClass:(o)=>r.edges.byClass.get(o)??TN,incident:(o)=>r.edges.byEndpoint.get(o)??TN});return Object.freeze({nodes:i,edges:n})}function gV(e,t){let r=t.byPath.get(e.class);if(r?.kind!=="edge"||r.orientation!=="undirected")return e;if(At(e.source,e.target)<=0)return e;return{source:e.target,target:e.source,class:e.class}}function em(e,t,r){let i=new Map(r),n=new Map,o=new Map,s=new Map,a=new Map,c=new Map;for(let u of e)n.set(u.id,u),Xp(s,u.class,u);for(let u of t)if(o.set(Ge({source:u.source,target:u.target,class:u.class}),u),Xp(a,u.class,u),Xp(c,u.source,u),u.target!==u.source)Xp(c,u.target,u);return tw(s),tw(a),tw(c),Object.freeze({nodes:Object.freeze({byId:n,byClass:s}),edges:Object.freeze({byKey:o,byClass:a,byEndpoint:c}),classes:Object.freeze({byPath:i})})}function Xp(e,t,r){let i=e.get(t);if(i===void 0)e.set(t,[r]);else i.push(r)}function tw(e){for(let[t,r]of e)e.set(t,Object.freeze(r))}function ow(e,t,r){let i=new Map(e.nodes.map((h)=>[h.id,h])),n=new Map(t.nodes.map((h)=>[h.id,h])),o=new Map(r.nodes.map((h)=>[h.id,h])),s=[...new Set([...i.keys(),...n.keys(),...o.keys()])].sort(At),a=[],c=[];for(let h of s){let g=yV(h,i.get(h),n.get(h),o.get(h));if(g.value!==void 0)a.push(g.value);c.push(...g.conflicts)}let u=iw(e.edges),l=iw(t.edges),d=iw(r.edges),f=new Map;for(let h of[...e.edges,...t.edges,...r.edges])f.set(Ge(it(h)),it(h));let m=[...f.entries()].sort(([,h],[,g])=>Cr(h,g)),B=[];for(let[h,g]of m){let w=CV(g,u.get(h),l.get(h),d.get(h));if(w.value!==void 0)B.push(w.value);c.push(...w.conflicts)}return c.length>0?Object.freeze({kind:"conflict",conflicts:Object.freeze(c)}):Object.freeze({kind:"merged",value:vV(a,B)})}function yV(e,t,r,i){let n=NN(t,r,i,bV);if(n!==sw)return Object.freeze({...n?{value:n}:{},conflicts:[]});if(t===void 0||r===void 0||i===void 0)return Object.freeze({conflicts:[Object.freeze({kind:"node-presence",node:e})]});let o=[],s=RN(t.class,r.class,i.class);if(s===Mu)o.push(Object.freeze({kind:"node-class",node:e}));let a=Qp(t.props,r.props,i.props);if(a.kind==="conflict")for(let c of a.conflicts)o.push(Object.freeze({kind:"node-property",node:e,property:c.property}));if(s===Mu||a.kind==="conflict")return Object.freeze({conflicts:Object.freeze(o)});return Object.freeze({value:Object.freeze({id:e,class:s,props:a.value}),conflicts:Object.freeze([])})}function CV(e,t,r,i){let n=NN(t,r,i,EV);if(n!==sw)return Object.freeze({...n?{value:n}:{},conflicts:[]});if(t===void 0||r===void 0||i===void 0)return Object.freeze({conflicts:[Object.freeze({kind:"edge-presence",edge:e})]});let o=[],s=RN(t.slug,r.slug,i.slug);if(s===Mu)o.push(Object.freeze({kind:"edge-slug",edge:e}));let a=Qp(t.props,r.props,i.props);if(a.kind==="conflict")for(let c of a.conflicts)o.push(Object.freeze({kind:"edge-property",edge:e,property:c.property}));if(s===Mu||a.kind==="conflict")return Object.freeze({conflicts:Object.freeze(o)});return Object.freeze({value:Object.freeze({...e,...s===void 0?{}:{slug:s},props:a.value}),conflicts:Object.freeze([])})}var sw=Symbol("recurse"),Mu=Symbol("conflict");function NN(e,t,r,i){if(nw(t,e,i))return r;if(nw(r,e,i))return t;if(nw(t,r,i))return t;return sw}function RN(e,t,r){if(t===e)return r;if(r===e)return t;if(t===r)return t;return Mu}function nw(e,t,r){return e===void 0||t===void 0?e===t:r(e,t)}function bV(e,t){return e.id===t.id&&e.class===t.class&&Ln(e.props,t.props)}function EV(e,t){return Ge(it(e))===Ge(it(t))&&e.slug===t.slug&&Ln(e.props,t.props)}function iw(e){return new Map(e.map((t)=>[Ge(it(t)),t]))}function vV(e,t){return Object.freeze({nodes:Object.freeze(e),edges:Object.freeze(t)})}class Uu extends Error{path;code="GRAPH_PATH_WALKER_REQUIRED";constructor(e){super(`Graph Path ${JSON.stringify(e)} requires a walker.`);this.path=e,this.name="GraphPathWalkerRequiredError"}}var aw=Object.freeze({nodes:Object.freeze([]),edges:Object.freeze([])}),wV=em(aw.nodes,aw.edges,new Map);class Fu{static#e=new Fu(aw,wV);nodes;edges;#t;#r;#n;#i;constructor(e,t,r){this.#t=e,this.#r=t,this.#n=r;let i=rw(e.nodes,e.edges,t);this.nodes=i.nodes,this.edges=i.edges,this.#i=Object.freeze({nodes:this.nodes,edges:this.edges,orientation:(n)=>{let o=this.#r.classes.byPath.get(n);return o?.kind==="edge"?o.orientation:void 0}}),Object.freeze(this)}static admit(e,t,r){let i=Qx(e,t),n=em(i.data.nodes,i.data.edges,i.classes);return new Fu(i.data,n,r)}static empty(){return Fu.#e}static delta(e,t){return AN(e,t)}static apply(e,t){return $N(e,t)}static merge(e,t,r){return ow(e.toData(),t.toData(),r.toData())}static mergeData(e,t,r){return ow(e,t,r)}walk(e){let t=q.from(e);if(this.#n!==void 0)return this.#n.walk(t,this.#i);if(t.ast.anchor.kind==="id"&&t.ast.steps.length===0)return this.#r.nodes.byId.get(t.ast.anchor.id);throw new Uu(t.raw)}toData(){return this.#t}equals(e){if(this===e)return!0;if(this.nodes.length!==e.nodes.length||this.edges.length!==e.edges.length)return!1;return this.nodes.all.every((t,r)=>IV(t,e.nodes.all[r]))&&this.edges.all.every((t,r)=>OV(t,e.edges.all[r]))}}function IV(e,t){return e.id===t.id&&e.class===t.class&&Ln(e.props,t.props)}function OV(e,t){let r=it(e),i=it(t);return r.source===i.source&&r.target===i.target&&r.class===i.class&&e.slug===t.slug&&Ln(e.props,t.props)}function zn(e,t,r){let i=e.safeParse(t);if(i.success)return i.data;let n=i.error.issues[0];if(n===void 0)r("","Invalid wire value");r(n.path.length===0?"":`/${n.path.map((o)=>DV(String(o))).join("/")}`,n.message)}function DV(e){return e.replaceAll("~","~0").replaceAll("/","~1")}var _V=/^[A-Za-z][A-Za-z0-9_]{0,63}$/u;function Ur(e){if(!Mn(e))throw TypeError(`Invalid local binding ${JSON.stringify(e)}.`);return e}function Mn(e){return typeof e==="string"&&_V.test(e)}var Bi=p.string().min(1),tm=p.record(p.string(),p.unknown()),PN=p.string().check(en("[A-Za-z][A-Za-z0-9_]{0,63}")),LN=p.string().min(fi.minLength).max(fi.maxLength).check(en(fi.fullMatch)),rm=p.strictObject({id:Bi,class:Bi,props:tm}),kV=p.strictObject({as:PN,class:Bi,props:tm}),nm=p.strictObject({source:Bi,target:Bi,class:Bi}),cw=nm.extend({slug:LN.optional(),props:tm}),jN=p.union([Bi,p.strictObject({path:Bi}),p.strictObject({created:PN})]),SV=p.strictObject({source:jN,target:jN,class:Bi,slug:LN.optional(),props:tm}),zN=p.strictObject({nodes:p.array(p.union([rm,kV])),edges:p.array(SV)}),MN=p.strictObject({nodes:p.array(rm),edges:p.array(cw)});class Yi extends TypeError{path;code="GRAPH_DATA_INVALID";constructor(e,t,r){super(`${t} at ${e||"/"}.`,r);this.path=e,this.name="GraphDataDecodeError"}}class Wo extends TypeError{path;code="GRAPH_SPEC_INVALID";constructor(e,t,r){super(`${t} at ${e||"/"}.`,r);this.path=e,this.name="GraphSpecDecodeError"}}function im(e){try{let t=zn(zN,se(e),Cn),r=t.nodes.map((n,o)=>AV(n,`/nodes/${o}`)),i=t.edges.map((n,o)=>$V(n,`/edges/${o}`));return TV(r,i),Object.freeze({nodes:Object.freeze(r),edges:Object.freeze(i)})}catch(t){if(t instanceof Wo)throw t;throw new Wo(fw(t),"Invalid GraphSpec",{cause:t})}}function lw(e){let t=e.nodes.map((n)=>("id"in n)?Object.freeze({id:n.id,class:n.class,props:uw(n.props)}):Object.freeze({as:n.as,class:n.class,props:uw(n.props)})),r=e.edges.map((n)=>Object.freeze({source:GN(n.source),target:GN(n.target),class:n.class,...n.slug===void 0?{}:{slug:n.slug},props:uw(n.props)})),i=Object.freeze({nodes:Object.freeze(t),edges:Object.freeze(r)});return im(i),i}function dw(e){try{let t=im(e),r=t.nodes.map((n,o)=>{if(!("id"in n))Gu(`/nodes/${o}/as`,"GraphData cannot contain anonymous Nodes");return n}),i=t.edges.map((n,o)=>{if(typeof n.source!=="string")Gu(`/edges/${o}/source`,"GraphData endpoints must be NodeIds");if(typeof n.target!=="string")Gu(`/edges/${o}/target`,"GraphData endpoints must be NodeIds");return wa({source:n.source,target:n.target,class:n.class,...n.slug===void 0?{}:{slug:n.slug},props:n.props})});return NV(r,i),Object.freeze({nodes:Object.freeze(r),edges:Object.freeze(i)})}catch(t){if(t instanceof Yi)throw t;throw new Yi(t instanceof Wo?t.path:fw(t),"Invalid GraphData",{cause:t})}}function HN(e){let t=lw(e);return dw(t),t}function AV(e,t){let r=qN(e.class,`${t}/class`),i=KN(e.props,`${t}/props`);if("id"in e)return Su({id:JN(e.id,`${t}/id`),class:r,props:i});return Object.freeze({as:VN(e.as,`${t}/as`),class:r,props:i})}function $V(e,t){return Object.freeze({source:UN(e.source,`${t}/source`),target:UN(e.target,`${t}/target`),class:qN(e.class,`${t}/class`),...e.slug===void 0?{}:{slug:RV(e.slug,`${t}/slug`)},props:KN(e.props,`${t}/props`)})}function UN(e,t){if(typeof e==="string")return JN(e,t);if("path"in e)try{return Object.freeze({path:yn(e.path)})}catch{Cn(`${t}/path`,"Expected canonical NodePath string")}return Object.freeze({created:VN(e.created,`${t}/created`)})}function VN(e,t){if(!Mn(e))Cn(t,"Expected a local binding name of at most 64 characters");return Ur(e)}function TV(e,t){let r=new Set,i=new Set;for(let o=0;o<e.length;o++){let s=e[o];if("id"in s){if(r.has(s.id))Cn(`/nodes/${o}/id`,`Duplicate NodeId ${JSON.stringify(s.id)}`);r.add(s.id)}else{if(i.has(s.as))Cn(`/nodes/${o}/as`,`Duplicate binding ${JSON.stringify(s.as)}`);i.add(s.as)}}let n=new Set;for(let o=0;o<t.length;o++){let s=t[o];for(let[c,u]of[["source",s.source],["target",s.target]])if(typeof u!=="string"&&"created"in u&&!i.has(u.created))Cn(`/edges/${o}/${c}/created`,`Unresolved binding ${JSON.stringify(u.created)}`);let a=JSON.stringify([FN(s.source),FN(s.target),s.class]);if(n.has(a))Cn(`/edges/${o}`,"Duplicate ordered Edge identity");n.add(a)}}function FN(e){if(typeof e==="string")return["id",e];return"created"in e?["created",e.created]:["path",e.path]}function GN(e){if(typeof e==="string")return e;return"created"in e?Object.freeze({created:e.created}):Object.freeze({path:e.path})}function uw(e){return ar(e)}function NV(e,t){let r=new Set;for(let n=0;n<e.length;n++){let o=e[n].id;if(r.has(o))Gu(`/nodes/${n}/id`,`Duplicate NodeId ${JSON.stringify(o)}`);r.add(o)}let i=new Set;for(let n=0;n<t.length;n++){let o=t[n],s=JSON.stringify([o.source,o.target,o.class]);if(i.has(s))Gu(`/edges/${n}`,"Duplicate ordered Edge identity");i.add(s)}}function Gu(e,t){throw new Yi(e,t)}function Cn(e,t,r){throw new Wo(e,t,r)}function qN(e,t){try{return Ze.parse(e)}catch(r){Cn(t,"Invalid ClassPath",{cause:r})}}function JN(e,t){try{return Fe(e)}catch(r){Cn(t,"Invalid NodeId",{cause:r})}}function RV(e,t){try{return Pn(e)}catch(r){Cn(t,"Invalid EdgeSlug",{cause:r})}}function KN(e,t){try{return ar(e,t)}catch(r){Cn(fw(r,t),"Invalid Properties",{cause:r})}}function fw(e,t=""){return e instanceof he?e.pointer:t}var Hu=Object.freeze({decode:dw,encode:HN}),jV=Object.freeze({decode:im,encode:lw});class bn extends TypeError{path;code="QUERY_AST_INVALID";constructor(e,t,r){super(`${t} at ${e||"/"}.`,r);this.path=e,this.name="QueryASTDecodeError"}}var Ia="astrale.graph.query",Oa="v6",sn=Object.freeze({sourceTerms:1024,steps:256,expansionDefinitionsPerStep:256,bindings:513});var En=p.string().min(1),vn=En.max(64),sm=p.strictObject({origin:En.max(253),kind:p.enum(["class","interface"]),name:En}),PV=p.discriminatedUnion("kind",[p.strictObject({kind:p.literal("path"),path:En}),p.strictObject({kind:p.literal("definition"),definition:sm})]),LV=p.strictObject({kind:p.literal("definition"),definition:sm}),zV=p.discriminatedUnion("kind",[p.strictObject({kind:p.literal("node"),terms:p.array(PV).min(1).max(sn.sourceTerms),binding:vn}),p.strictObject({kind:p.literal("edge"),terms:p.array(LV).min(1).max(sn.sourceTerms),bindings:p.strictObject({source:vn,edge:vn,target:vn})})]),MV=p.discriminatedUnion("kind",[p.strictObject({kind:p.literal("definition.satisfies"),definition:sm}),p.strictObject({kind:p.literal("property.equal"),property:En,value:p.unknown()}),p.strictObject({kind:p.literal("property.present"),property:En}),p.strictObject({kind:p.literal("identity.equal"),identity:p.union([En,p.strictObject({source:En,target:En,class:En})])})]),UV=p.strictObject({op:p.literal("filter"),binding:vn,predicate:MV}),FV=p.strictObject({op:p.literal("expand"),from:vn,via:p.array(sm).min(1).max(sn.expansionDefinitionsPerStep),direction:p.enum(["outgoing","incoming","incident"]),bindings:p.strictObject({edge:vn,node:vn})}),pw=p.strictObject({property:En,direction:p.enum(["asc","desc"]),unranked:p.enum(["first","last"])}),om=p.enum(["reference","value"]),GV=p.strictObject({kind:p.literal("graph"),binding:vn,order:pw.optional()}),HV=p.strictObject({kind:p.literal("nodes"),binding:vn,projection:p.strictObject({kind:om}),order:pw.optional()}),VV=p.strictObject({kind:p.literal("edges"),binding:vn,projection:p.strictObject({edge:om,source:om,target:om}),order:pw.optional()}),Qi=p.strictObject({format:p.literal(Ia),version:p.literal(Oa),source:zV,steps:p.array(p.discriminatedUnion("op",[UV,FV])).max(sn.steps),select:p.discriminatedUnion("kind",[GV,HV,VV])});var WN=new WeakSet;function am(e){try{let t=qV(zn(Qi,se(e),$t));return WN.add(t),t}catch(t){if(t instanceof bn)throw t;throw new bn(eq(t),"Invalid QueryAST",{cause:t})}}function Yo(e){if(WN.has(e))return e;return am(e)}function qV(e){let t=new Map,r=JV(e.source,t),i=e.steps.map((o,s)=>WV(o,s,t));if(t.size>sn.bindings)$t("/steps",`Query introduces more than ${sn.bindings} bindings`);let n=KV(e.select,t);return Object.freeze({format:Ia,version:Oa,source:r,steps:Object.freeze(i),select:n})}function JV(e,t){let r=e.terms.map((i,n)=>ZV(i,`/source/terms/${n}`));if(XN(r,XV,"/source/terms","source term"),e.kind==="node")return Object.freeze({kind:"node",terms:Object.freeze(r),binding:Da(e.binding,"node","/source/binding",t)});if(r.some((i)=>i.kind!=="definition"))$t("/source/terms","Edge source accepts Definition terms only");return Object.freeze({kind:"edge",terms:Object.freeze(r),bindings:Object.freeze({source:Da(e.bindings.source,"node","/source/bindings/source",t),edge:Da(e.bindings.edge,"edge","/source/bindings/edge",t),target:Da(e.bindings.target,"node","/source/bindings/target",t)})})}function KV(e,t){if(e.kind==="graph")return Object.freeze({kind:"graph",binding:Vu(e.binding,void 0,"/select/binding",t),...e.order===void 0?{}:{order:Object.freeze({property:mw(e.order.property,"/select/order/property"),direction:e.order.direction,unranked:e.order.unranked})}});if(e.kind==="nodes")return Object.freeze({kind:"nodes",binding:Vu(e.binding,"node","/select/binding",t),projection:Object.freeze({kind:e.projection.kind}),...e.order===void 0?{}:{order:ZN(e.order)}});return Object.freeze({kind:"edges",binding:Vu(e.binding,"edge","/select/binding",t),projection:Object.freeze({...e.projection}),...e.order===void 0?{}:{order:ZN(e.order)}})}function ZN(e){return Object.freeze({property:mw(e.property,"/select/order/property"),direction:e.direction,unranked:e.unranked})}function ZV(e,t){if(e.kind==="path")try{return Object.freeze({kind:"path",path:yn(e.path)})}catch(r){$t(`${t}/path`,"Invalid NodePath",r)}return Object.freeze({kind:"definition",definition:Bw(e.definition,`${t}/definition`)})}function WV(e,t,r){let i=`/steps/${t}`;if(e.op==="filter"){let c=Vu(e.binding,void 0,`${i}/binding`,r),u=r.get(c);if(u===void 0)$t(`${i}/binding`,"Unknown binding");let l=YV(e.predicate,`${i}/predicate`,u);if(l.kind==="definition.satisfies")return Object.freeze({op:"filter",binding:c,predicate:l});return Object.freeze({op:"filter",binding:c,predicate:l})}let n=Vu(e.from,"node",`${i}/from`,r),o=e.via.map((c,u)=>Bw(c,`${i}/via/${u}`));XN(o,YN,`${i}/via`,"Definition reference");let s=Da(e.bindings.edge,"edge",`${i}/bindings/edge`,r),a=Da(e.bindings.node,"node",`${i}/bindings/node`,r);if(r.size>sn.bindings)$t(i,`Query introduces more than ${sn.bindings} bindings`);return Object.freeze({op:"expand",from:n,via:Object.freeze(o),direction:e.direction,bindings:Object.freeze({edge:s,node:a})})}function YV(e,t,r){if(e.kind==="definition.satisfies")return Object.freeze({kind:"definition.satisfies",definition:Bw(e.definition,`${t}/definition`)});if(e.kind==="identity.equal"){if(r==="node"){if(typeof e.identity!=="string")$t(`${t}/identity`,"Node binding requires a NodeId identity");try{return Object.freeze({kind:"identity.equal",identity:Fe(e.identity)})}catch(n){$t(`${t}/identity`,"Invalid NodeId",n)}}if(typeof e.identity==="string")$t(`${t}/identity`,"Edge binding requires an EdgeKey identity");try{let n=Object.freeze({source:Fe(e.identity.source),target:Fe(e.identity.target),class:Ze.parse(e.identity.class)});return Object.freeze({kind:"identity.equal",identity:n})}catch(n){$t(`${t}/identity`,"Invalid EdgeKey",n)}}let i=mw(e.property,`${t}/property`);if(e.kind==="property.present")return Object.freeze({kind:"property.present",property:i});return Object.freeze({kind:"property.equal",property:i,value:QV(e.value,`${t}/value`)})}function YN(e){return`${e.origin}\x00${e.kind}\x00${e.name}`}function mw(e,t){try{return Pe(e)}catch(r){$t(t,"Invalid PropertyKey",r)}}function QV(e,t){try{return QN(te.decode(te.encode(e)))}catch(r){$t(t,"Invalid portable equality value",r)}}function QN(e){if(e===null||typeof e!=="object")return e;for(let t of Object.values(e))QN(t);return Object.freeze(e)}function Bw(e,t){if(!Y.patterns.origin.test(e.origin))$t(`${t}/origin`,"Invalid Domain origin");if(!Y.patterns.memberName.test(e.name))$t(`${t}/name`,"Invalid Definition name");return Object.freeze({origin:e.origin,kind:e.kind,name:e.name})}function Da(e,t,r,i){let n;try{n=Ur(e)}catch(o){$t(r,"Invalid binding name",o)}if(i.has(n))$t(r,`Duplicate binding ${JSON.stringify(n)}`);return i.set(n,t),n}function Vu(e,t,r,i){let n;try{n=Ur(e)}catch(s){$t(r,"Invalid binding name",s)}let o=i.get(n);if(o===void 0)$t(r,`Unknown or forward binding ${JSON.stringify(n)}`);if(t!==void 0&&o!==t)$t(r,`Expected a ${t} binding but found ${o}`);return n}function XV(e){return e.kind==="path"?`path\x00${e.path}`:`definition\x00${YN(e.definition)}`}function XN(e,t,r,i){let n=new Set;for(let o=0;o<e.length;o++){let s=t(e[o]);if(n.has(s))$t(`${r}/${o}`,`Duplicate ${i}`);n.add(s)}}function $t(e,t,r){throw new bn(e,t,r===void 0?void 0:{cause:r})}function eq(e){return e instanceof he?e.pointer:""}var tq=h_("astrale-query-ast-v6\x00"),eR=new WeakMap;function gw(e){let t=Yo(e),r=eR.get(t);if(r!==void 0)return r;let i=new Map,n=0;if(t.source.kind==="node")i.set(t.source.binding,{kind:"node",index:n++});else i.set(t.source.bindings.source,{kind:"node",index:n++}),i.set(t.source.bindings.edge,{kind:"edge",index:n++}),i.set(t.source.bindings.target,{kind:"node",index:n++});let o=t.steps.map((l)=>{if(l.op==="filter")return{op:"filter",binding:hi(i,l.binding),predicate:nq(l.predicate)};let d={kind:"edge",index:n++},f={kind:"node",index:n++},m={op:"expand",from:hi(i,l.from),via:[...l.via].map(yw).sort(hw),direction:l.direction,bindings:{edge:d,node:f}};return i.set(l.bindings.edge,d),i.set(l.bindings.node,f),m}),s={format:t.format,version:t.version,source:t.source.kind==="node"?{kind:"node",terms:[...t.source.terms].map(tR).sort(hw),binding:hi(i,t.source.binding)}:{kind:"edge",terms:[...t.source.terms].map(tR).sort(hw),bindings:{source:hi(i,t.source.bindings.source),edge:hi(i,t.source.bindings.edge),target:hi(i,t.source.bindings.target)}},steps:o,select:rq(t.select,i)},a=Is(g_(tq,te.encode(s))),c="";for(let l of a)c+=l.toString(16).padStart(2,"0");let u=`sha256:${c}`;return eR.set(t,u),u}function rq(e,t){if(e.kind==="graph")return{kind:e.kind,binding:hi(t,e.binding),...e.order===void 0?{}:{order:{property:e.order.property,direction:e.order.direction,unranked:e.order.unranked}}};if(e.kind==="nodes")return{kind:e.kind,binding:hi(t,e.binding),projection:e.projection,...e.order===void 0?{}:{order:e.order}};return{kind:e.kind,binding:hi(t,e.binding),projection:e.projection,...e.order===void 0?{}:{order:e.order}}}function hi(e,t){let r=e.get(t);if(r===void 0)throw TypeError(`Missing admitted Query binding ${t}.`);return r}function tR(e){return e.kind==="path"?{kind:"path",path:e.path}:{kind:"definition",definition:yw(e.definition)}}function yw(e){return{origin:e.origin,kind:e.kind,name:e.name}}function nq(e){if(e.kind==="definition.satisfies")return{kind:e.kind,definition:yw(e.definition)};if(e.kind==="property.present")return{kind:e.kind,property:e.property};if(e.kind==="identity.equal")return{kind:e.kind,identity:typeof e.identity==="string"?e.identity:{source:e.identity.source,target:e.identity.target,class:e.identity.class}};return{kind:e.kind,property:e.property,value:e.value}}function hw(e,t){return iq(te.encode(e),te.encode(t))}function iq(e,t){let r=Math.min(e.length,t.length);for(let i=0;i<r;i++){let n=e[i]-t[i];if(n!==0)return n<0?-1:1}return Math.sign(e.length-t.length)}var Ot=Object.freeze({format:Ia,version:Oa,limits:sn,decode:am,encode:Yo,fingerprint:gw});function rR(e){if(e.select.kind==="nodes")return"node";if(e.select.kind==="edges")return"edge";if(e.source.kind==="node"){if(e.select.binding===e.source.binding)return"node"}else{if(e.select.binding===e.source.bindings.source||e.select.binding===e.source.bindings.target)return"node";if(e.select.binding===e.source.bindings.edge)return"edge"}for(let t of e.steps){if(t.op!=="expand")continue;if(e.select.binding===t.bindings.node)return"node";if(e.select.binding===t.bindings.edge)return"edge"}throw TypeError("Admitted Query selected an unknown binding.")}class Fr extends TypeError{path;code="MUTATION_AST_INVALID";constructor(e,t,r){super(`${t} at ${e||"/"}.`,r);this.path=e,this.name="MutationASTDecodeError"}}var _a="astrale.graph.mutation",ka="v3",Gr=Object.freeze({preconditions:2048,queryPreconditions:64,queryExpectedIdentities:4096});var cr=p.string().min(1),oR=p.string().min(1).max(64),cm=p.string().check(en(Y.patterns.propertyKeyFullMatch)),um=p.record(cm,p.unknown()),Cw=p.strictObject({set:um,unset:p.array(cm)}),nR=p.union([cr,p.strictObject({created:oR})]),lm=p.strictObject({source:cr,target:cr,class:cr}),bw=p.string().min(fi.minLength).max(fi.maxLength).check(en(fi.fullMatch)),oq=p.strictObject({op:p.literal("edge.update"),edge:lm,slug:bw.nullable(),props:Cw.optional()}),sq=p.strictObject({op:p.literal("edge.update"),edge:lm,props:Cw}),iR=p.union([p.strictObject({equals:um,absent:p.array(cm).optional()}),p.strictObject({absent:p.array(cm).min(1)})]),aq=p.discriminatedUnion("kind",[p.strictObject({kind:p.literal("node"),ids:p.array(cr).max(Gr.queryExpectedIdentities)}),p.strictObject({kind:p.literal("edge"),keys:p.array(p.strictObject({source:cr,target:cr,class:cr})).max(Gr.queryExpectedIdentities)})]),cq=p.union([p.strictObject({kind:p.literal("node"),node:cr,class:cr,props:iR.optional()}),p.strictObject({kind:p.literal("edge"),edge:lm,slug:bw.nullable().optional(),props:iR.optional()}),p.strictObject({kind:p.literal("query"),query:Qi,equals:aq})]),Xi=p.strictObject({format:p.literal(_a),version:p.literal(ka),preconditions:p.array(cq).max(Gr.preconditions),operations:p.array(p.union([p.strictObject({op:p.literal("node.create"),as:oR,class:cr,props:um}),p.strictObject({op:p.literal("node.update"),node:cr,class:cr,props:Cw}),p.strictObject({op:p.literal("node.delete"),node:cr,class:cr}),p.strictObject({op:p.literal("edge.create"),class:cr,source:nR,target:nR,slug:bw.optional(),props:um}),oq,sq,p.strictObject({op:p.literal("edge.delete"),edge:lm})])).min(1)});function xw(e){try{return uq(zn(Xi,se(e),gt))}catch(t){if(t instanceof Fr)throw t;throw new Fr(xq(t),"Invalid MutationAST",{cause:t})}}function uR(e){return xw(e)}function uq(e){let t=e.preconditions.map((i,n)=>lq(i,`/preconditions/${n}`)),r=e.operations.map((i,n)=>Bq(i,`/operations/${n}`));return yq(t),hq(r),Object.freeze({format:_a,version:ka,preconditions:bq(t),operations:gq(r)})}function lq(e,t){if(e.kind==="node")return Object.freeze({kind:"node",node:Aa(e.node,`${t}/node`),class:Sa(e.class,`${t}/class`),...e.props===void 0?{}:{props:sR(e.props,`${t}/props`)}});if(e.kind==="query"){let r=dq(e.query,`${t}/query`),i=rR(r);if(e.equals.kind!==i)gt(`${t}/equals/kind`,`Expected ${i} selection for the Query's selected binding`);return Object.freeze({kind:"query",query:r,equals:fq(e.equals,r,`${t}/equals`)})}return Object.freeze({kind:"edge",edge:dm(e.edge,`${t}/edge`),...Object.hasOwn(e,"slug")?{slug:e.slug===null?null:vw(e.slug,`${t}/slug`)}:{},...e.props===void 0?{}:{props:sR(e.props,`${t}/props`)}})}function dq(e,t){try{return Ot.decode(e)}catch(r){throw new Fr(t,"Invalid query precondition QueryAST",{cause:r})}}function fq(e,t,r){let i=t.select.order===void 0;if(e.kind==="node"){let o=e.ids.map((s,a)=>pq(s,`${r}/ids/${a}`));if(Ow(o,`${r}/ids`,"NodeId"),i)cR(o,At,`${r}/ids`,"NodeId");return Object.freeze({kind:"node",ids:Object.freeze(o)})}let n=e.keys.map((o,s)=>mq(o,`${r}/keys/${s}`));if(Eq(n,Ge,`${r}/keys`,"EdgeKey"),i)cR(n,Cr,`${r}/keys`,"EdgeKey");return Object.freeze({kind:"edge",keys:Object.freeze(n)})}function pq(e,t){if(typeof e!=="string")gt(t,"Expected a NodeId string");try{return Fe(e)}catch(r){throw new Fr(t,"Invalid NodeId",{cause:r})}}function mq(e,t){try{return Object.freeze({source:Fe(e.source),target:Fe(e.target),class:Ze.parse(e.class)})}catch(r){throw new Fr(t,"Invalid EdgeKey",{cause:r})}}function sR(e,t){let r="equals"in e?fm(e.equals,`${t}/equals`):void 0,i=(e.absent??[]).map((n,o)=>Iw(n,`${t}/absent/${o}`));if(Ow(i,`${t}/absent`,"PropertyKey"),i.sort(ww),(r===void 0||Object.keys(r).length===0)&&i.length===0)gt(t,"Expected at least one Property condition");for(let n of i)if(r!==void 0&&Object.hasOwn(r,n))gt(t,`Property ${JSON.stringify(n)} is both equal and absent`);return Object.freeze({...r===void 0?{}:{equals:r},...i.length===0?{}:{absent:Object.freeze(i)}})}function Bq(e,t){switch(e.op){case"node.create":return Object.freeze({op:"node.create",as:dR(e.as,`${t}/as`),class:Sa(e.class,`${t}/class`),props:fm(e.props,`${t}/props`)});case"node.update":return Object.freeze({op:"node.update",node:Aa(e.node,`${t}/node`),class:Sa(e.class,`${t}/class`),props:Ew(e.props,`${t}/props`)});case"node.delete":return Object.freeze({op:"node.delete",node:Aa(e.node,`${t}/node`),class:Sa(e.class,`${t}/class`)});case"edge.create":return Object.freeze({op:"edge.create",class:Sa(e.class,`${t}/class`),source:aR(e.source,`${t}/source`),target:aR(e.target,`${t}/target`),...Object.hasOwn(e,"slug")?{slug:vw(e.slug,`${t}/slug`)}:{},props:fm(e.props,`${t}/props`)});case"edge.update":if("slug"in e)return Object.freeze({op:"edge.update",edge:dm(e.edge,`${t}/edge`),slug:e.slug===null?null:vw(e.slug,`${t}/slug`),...e.props===void 0?{}:{props:Ew(e.props,`${t}/props`)}});return Object.freeze({op:"edge.update",edge:dm(e.edge,`${t}/edge`),props:Ew(e.props,`${t}/props`)});case"edge.delete":return Object.freeze({op:"edge.delete",edge:dm(e.edge,`${t}/edge`)})}}function aR(e,t){if(typeof e==="string")return Aa(e,t);return Object.freeze({created:dR(e.created,`${t}/created`)})}function dm(e,t){return Object.freeze({source:Aa(e.source,`${t}/source`),target:Aa(e.target,`${t}/target`),class:Sa(e.class,`${t}/class`)})}function Ew(e,t){let r=fm(e.set,`${t}/set`),i=e.unset.map((n,o)=>Iw(n,`${t}/unset/${o}`));if(Ow(i,`${t}/unset`,"PropertyKey"),Object.keys(r).length+i.length===0)gt(t,"Expected a non-empty patch");for(let n of i)if(Object.hasOwn(r,n))gt(t,`Property ${JSON.stringify(n)} is set and unset`);return Kx({set:r,unset:i},t)}function fm(e,t){let r={};for(let i of Object.keys(e).sort()){let n=Iw(i,`${t}/${vq(i)}`);Object.defineProperty(r,n,{enumerable:!0,value:e[i]})}return ar(r,t)}function hq(e){let t=new Map;for(let r=0;r<e.length;r++){let i=e[r];if(i.op!=="node.create")continue;let n=t.get(i.as);if(n!==void 0)gt(`/operations/${r}/as`,`Duplicate create binding declared at operation ${n}`);t.set(i.as,r)}for(let r=0;r<e.length;r++){let i=e[r];if(i.op!=="edge.create")continue;for(let[n,o]of[["source",i.source],["target",i.target]])if(typeof o!=="string"&&!t.has(o.created))gt(`/operations/${r}/${n}/created`,`Unresolved create binding ${o.created}`)}}function gq(e){if(e.length<2)return Object.freeze([...e]);let t=new Map,r=[];for(let i=0;i<e.length;i++){let n=e[i],o=lR(n),s=t.get(o);if(s!==void 0)gt(`/operations/${i}`,`Duplicate mutation operation declared at operation ${s}`);t.set(o,i),r.push({key:o,value:n})}return r.sort((i,n)=>ww(i.key,n.key)),Object.freeze(r.map(({value:i})=>i))}function yq(e){if(e.length>Gr.preconditions)gt("/preconditions",`Mutation declares more than ${Gr.preconditions} preconditions`);let t=new Map,r=new Map,i=0,n=0;for(let o=0;o<e.length;o++){let s=e[o];if(s.kind==="query")i++,n+=s.equals.kind==="node"?s.equals.ids.length:s.equals.keys.length;let a=Cq(s),c=t.get(a);if(c!==void 0)gt(`/preconditions/${o}`,`Duplicate precondition selector declared at precondition ${c}`);if(t.set(a,o),s.kind!=="node")continue;let u=r.get(s.node);if(u!==void 0&&u.class!==s.class)gt(`/preconditions/${o}/class`,`Contradictory Node Class assertion declared at precondition ${u.index}`);r.set(s.node,{class:s.class,index:o})}if(i>Gr.queryPreconditions)gt("/preconditions",`Mutation declares more than ${Gr.queryPreconditions} query preconditions`);if(n>Gr.queryExpectedIdentities)gt("/preconditions",`Mutation declares more than ${Gr.queryExpectedIdentities} expected query identities`)}function Cq(e){if(e.kind==="node")return te.serialize({kind:"node",node:e.node,class:e.class});if(e.kind==="edge")return te.serialize({kind:"edge",edge:e.edge});return`query:${Ot.fingerprint(e.query)}`}function bq(e){if(e.length<2)return Object.freeze([...e]);return Object.freeze(e.map((t)=>({key:lR(t),value:t})).sort((t,r)=>ww(t.key,r.key)).map(({value:t})=>t))}function lR(e){return te.serialize(e)}function ww(e,t){return e<t?-1:e>t?1:0}function dR(e,t){if(!Mn(e))gt(t,"Expected a local binding name of at most 64 characters");return Ur(e)}function Iw(e,t){if(typeof e!=="string"||!Pe.is(e))gt(t,"Expected a canonical PropertyKey");return Pe(e)}function Aa(e,t){if(typeof e!=="string")gt(t,"Expected a NodePath string");try{return yn(e)}catch(r){throw new Fr(t,"Invalid NodePath",{cause:r})}}function Sa(e,t){if(typeof e!=="string")gt(t,"Expected a ClassPath string");try{return Ze.parse(e)}catch(r){throw new Fr(t,"Invalid ClassPath",{cause:r})}}function vw(e,t){if(typeof e!=="string")gt(t,"Expected an EdgeSlug string");try{return Pn(e)}catch(r){throw new Fr(t,"Invalid EdgeSlug",{cause:r})}}function Ow(e,t,r){let i=new Set;for(let n=0;n<e.length;n++){let o=e[n];if(i.has(o))gt(`${t}/${n}`,`Duplicate ${r} ${JSON.stringify(o)}`);i.add(o)}}function Eq(e,t,r,i){let n=new Set;for(let o=0;o<e.length;o++){let s=t(e[o]);if(n.has(s))gt(`${r}/${o}`,`Duplicate ${i}`);n.add(s)}}function cR(e,t,r,i){for(let n=1;n<e.length;n++)if(t(e[n-1],e[n])>=0)gt(`${r}/${n}`,`${i} sequence is not in canonical identity order`)}function vq(e){return e.replaceAll("~","~0").replaceAll("/","~1")}function gt(e,t){throw new Fr(e,t)}function xq(e){return e instanceof he?e.pointer:""}var Un=Object.freeze({format:_a,version:ka,limits:Gr,decode:xw,encode:uR});function $a(e){let t=e.preconditions===void 0?[]:e.preconditions;return Un.decode({format:Un.format,version:Un.version,preconditions:t.map(wq),operations:e.operations.map(Iq)})}function _w(e){let t=[];for(let r of e.nodes){if("id"in r)throw TypeError(`Cannot create identified GraphSpec Node ${JSON.stringify(r.id)}.`);t.push({op:"node.create",as:r.as,class:r.class,props:pR(r.props)})}for(let r of e.edges){let i=pR(r.props);t.push({op:"edge.create",source:mR(r.source),target:mR(r.target),class:r.class,...r.slug===void 0?{}:{slug:r.slug},props:i})}if(t.length===0)throw TypeError("Cannot create an empty GraphSpec mutation.");return $a({operations:t})}function wq(e){if(e.kind==="node")return{...e,node:qu(e.node)};if(e.kind==="query")return e;return{...e,edge:Dw(e.edge)}}function Iq(e){switch(e.op){case"node.create":return e;case"node.update":return{...e,node:qu(e.node)};case"node.delete":return{...e,node:qu(e.node)};case"edge.create":return{...e,source:fR(e.source),target:fR(e.target)};case"edge.update":return{...e,edge:Dw(e.edge)};case"edge.delete":return{...e,edge:Dw(e.edge)}}}function fR(e){return e instanceof q?e.raw:e}function Dw(e){return{source:qu(e.source),target:qu(e.target),class:e.class}}function qu(e){return e instanceof q?e.raw:e}function pR(e){return e}function mR(e){if(typeof e==="string")return q.id(e);return"created"in e?Object.freeze({created:e.created}):e.path}function kw(e){if(typeof e!=="function")throw TypeError("Mutation author must be a function.");let t=[],r=[],i=!0,n=()=>{if(!i)throw TypeError("MutationBuilder is no longer active.")},s={expect:Object.freeze({node(c){return n(),r.push({kind:"node",...c}),a},edge(c){n();let u={source:c.source,target:c.target,class:c.class};return r.push({kind:"edge",edge:u,...Object.hasOwn(c,"slug")?{slug:c.slug??null}:{},...c.props===void 0?{}:{props:c.props}}),a},query(c){return n(),r.push({kind:"query",...c}),a}}),createNode(c){return n(),t.push({op:"node.create",as:c.as,class:c.class,props:c.props??{}}),Object.freeze({created:c.as})},updateNode(c){return n(),t.push({op:"node.update",...c}),a},deleteNode(c){return n(),t.push({op:"node.delete",...c}),a},createEdge(c){return n(),t.push({op:"edge.create",class:c.class,source:c.source,target:c.target,...c.slug===void 0?{}:{slug:c.slug},props:c.props??{}}),a},updateEdge(c){n();let u={source:c.source,target:c.target,class:c.class};if(Object.hasOwn(c,"slug"))return t.push({op:"edge.update",edge:u,slug:c.slug??null,...c.props===void 0?{}:{props:c.props}}),a;if(c.props===void 0)throw TypeError("Edge update must change slug or properties.");return t.push({op:"edge.update",edge:u,props:c.props}),a},deleteEdge(c){return n(),t.push({op:"edge.delete",edge:c}),a}},a=Object.freeze(s);try{let c=e(a);if(Oq(c))throw TypeError("Mutation author must be synchronous.");if(c!==void 0)throw TypeError("Mutation author must not return a value.");return $a({preconditions:r,operations:t})}finally{i=!1}}function Oq(e){return(typeof e==="object"||typeof e==="function")&&e!==null&&typeof e.then==="function"}class Qo extends TypeError{path;code="MUTATION_RESULT_INVALID";constructor(e,t,r){super(`${t} at ${e||"/"}.`,r);this.path=e,this.name="MutationResultDecodeError"}}var Dq=p.string().min(1),_q=p.string().min(1).max(64),Ta=p.strictObject({createdNodes:p.record(_q,Dq)});var pm=Object.freeze({decode:BR,encode:kq});function kq(e){return BR(e)}function BR(e){try{let t=zn(Ta,se(e),Sw).createdNodes,r={};for(let i of Object.keys(t).sort()){let n=`/createdNodes/${Aq(i)}`;Sq(i,n);let o=t[i];try{r[i]=Fe(o)}catch(s){Sw(n,"Invalid NodeId",s)}}return Object.freeze({createdNodes:Object.freeze(r)})}catch(t){if(t instanceof Qo)throw t;throw new Qo($q(t),"Invalid MutationResult",{cause:t})}}function Sq(e,t){if(!Mn(e))Sw(t,"Invalid LocalBinding")}function Aq(e){return e.replaceAll("~","~0").replaceAll("/","~1")}function Sw(e,t,r){throw new Qo(e,t,r===void 0?void 0:{cause:r})}function $q(e){return e instanceof he?e.pointer:""}var eo=Object.freeze({format:Un.format,version:Un.version,limits:Un.limits,build:kw,create:$a,fromGraph:_w,decode:Un.decode,encode:Un.encode});var Ra={};ze(Ra,{CODES:()=>Ae,ProtocolError:()=>Fn,acceptPayload:()=>Xo,acceptReason:()=>Aw,httpStatusOf:()=>hR,reasonOf:()=>mm});var Ae=Object.freeze({PARSE_ERROR:1001,INVALID_REQUEST:1002,VALIDATION_ERROR:1003,INVARIANT_VIOLATION:1004,AUTH_MISSING:2001,AUTH_INVALID:2002,AUTH_EXPIRED:2003,ACCESS_DENIED:2004,METHOD_NOT_FOUND:3001,NOT_FOUND:3002,METHOD_NOT_ALLOWED:3003,CONFLICT:4001,UNSUPPORTED:4002,LIMIT_EXCEEDED:4003,CANCELLED:4004,DEADLINE_EXCEEDED:4005,INTERNAL_ERROR:5000,BACKEND_UNAVAILABLE:5001,OUTCOME_UNKNOWN:5002});var Uq={[Ae.PARSE_ERROR]:400,[Ae.INVALID_REQUEST]:400,[Ae.VALIDATION_ERROR]:422,[Ae.INVARIANT_VIOLATION]:422,[Ae.AUTH_MISSING]:401,[Ae.AUTH_INVALID]:401,[Ae.AUTH_EXPIRED]:401,[Ae.ACCESS_DENIED]:403,[Ae.METHOD_NOT_FOUND]:404,[Ae.NOT_FOUND]:404,[Ae.METHOD_NOT_ALLOWED]:405,[Ae.CONFLICT]:409,[Ae.UNSUPPORTED]:422,[Ae.LIMIT_EXCEEDED]:429,[Ae.CANCELLED]:408,[Ae.DEADLINE_EXCEEDED]:504,[Ae.INTERNAL_ERROR]:500,[Ae.BACKEND_UNAVAILABLE]:503,[Ae.OUTCOME_UNKNOWN]:500};function hR(e){return Uq[e.code]??500}var Fq=new Set(Object.values(Ae)),Gq=new Set(["code","message","data"]);function Xo(e,t="error"){let r;try{r=se(e)}catch(i){if(i instanceof he)throw TypeError(`${t} must be a portable value object`,{cause:i});throw i}if(!Hq(r))throw TypeError(`${t} must be an object`);for(let i of Object.keys(r))if(!Gq.has(i))throw TypeError(`${t} contains unexpected field ${JSON.stringify(i)}`);if(!Object.hasOwn(r,"code")||!Fq.has(r.code))throw TypeError(`${t}.code is not a public error code`);if(typeof r.message!=="string")throw TypeError(`${t}.message must be a string`);return Object.freeze({code:r.code,message:r.message,...r.data===void 0?{}:{data:r.data}})}function Hq(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}class Fn extends Error{payload;constructor(e){super(e.message);this.name="ProtocolError",this.payload=e}}var gR=new Set(["code","details"]);function Aw(e,t="error reason"){let r;try{r=se(e)}catch(i){if(i instanceof he)throw TypeError(`${t} must be a portable value object`,{cause:i});throw i}if(!yR(r))throw TypeError(`${t} must be an object`);if(Object.keys(r).length!==gR.size||Object.keys(r).some((i)=>!gR.has(i)))throw TypeError(`${t} must contain exactly code and details`);if(typeof r.code!=="string"||r.code.normalize("NFC")!==r.code||!/^[A-Z][A-Z0-9_]{0,127}$/u.test(r.code))throw TypeError(`${t}.code is invalid`);if(!yR(r.details))throw TypeError(`${t}.details must be an object`);return Object.freeze({code:r.code,details:Object.freeze(r.details)})}function mm(e){if(e===void 0)return;try{return Aw(e)}catch(t){if(t instanceof TypeError)return;throw t}}function yR(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}function CR(e,t){if(e===null||typeof e==="string")return e;if(typeof e==="number"&&Number.isFinite(e)&&!Object.is(e,-0))return e;throw TypeError(`${t} must be a string, finite number, or null`)}var $w=255,Vq=/[^A-Za-z0-9._-]/u,qq="InvocationId must contain 1-255 ASCII characters drawn from [A-Za-z0-9._-].";class to extends TypeError{input;code="INVOCATION_INVALID";constructor(e,t="Invocation is invalid.",r){super(t,r);this.input=e,this.name="InvocationError"}}function ja(e){if(e===null||typeof e!=="object"||Array.isArray(e))bR(e);let t=e,r=Object.getOwnPropertyDescriptor(t,"source"),i=Object.getOwnPropertyDescriptor(t,"id");if(Reflect.ownKeys(t).some((o)=>o!=="source"&&o!=="id")||r===void 0||i===void 0||!r.enumerable||!i.enumerable||!("value"in r)||!("value"in i)||typeof r.value!=="string"||typeof i.value!=="string")bR(e);let n;try{n=ht.accept(r.value)}catch(o){throw new to(e,"Invocation source is invalid.",{cause:o})}if(!Jq(i.value))throw new to(e,qq);return Object.freeze({source:n,id:i.value})}function ER(e,t){return e.source===t.source&&e.id===t.id}function Jq(e){return typeof e==="string"&&e.length>0&&e.length<=$w&&!Vq.test(e)}function bR(e){throw new to(e)}function yt(e,t){let r;try{r=se(e)}catch(i){if(i instanceof he)return ue(`${t} must be a portable value object`);throw i}if(!Kq(r))ue(`${t} must be an object`);return r}function Ju(e,t){if(e===null||typeof e!=="object"||Array.isArray(e))ue(`${t} must be an object`);let r=Object.getPrototypeOf(e);if(r!==Object.prototype&&r!==null)ue(`${t} must be a plain object`);let i={};for(let n of Reflect.ownKeys(e)){if(typeof n!=="string")ue(`${t} cannot contain symbol fields`);let o=Object.getOwnPropertyDescriptor(e,n);if(o===void 0||!o.enumerable||!("value"in o))ue(`${t}.${n} must be an enumerable data field`);i[n]=o.value}return i}function He(e,t,r){for(let i of Object.keys(e))if(!t.has(i))ue(`${r} contains unexpected field ${JSON.stringify(i)}`)}function We(e,t,r){for(let i of t)if(!Object.hasOwn(e,i))ue(`${r}.${i} is required`)}function Tt(e,t){try{return CR(e,t)}catch(r){if(r instanceof TypeError)return ue(r.message);throw r}}function Hr(e,t){try{return ja(e)}catch(r){if(r instanceof to)return ue(`${t} must be a valid Invocation`);throw r}}function vR(e,t){if(typeof e!=="string")ue(`${t} must be a NodePath string`);try{return yn(e)}catch(r){if(r instanceof Ko)return ue(`${t} must be a valid NodePath`);throw r}}function Bm(e,t){if(typeof e!=="string")ue(`${t} must be an issuer identifier`);try{return ht.accept(e)}catch(r){if(r instanceof be)return ue(`${t} must be a valid issuer identifier`);throw r}}function ro(e,t){if(typeof e!=="string")ue(`${t} must be a string`);return e}function Tw(e,t){if(!Number.isSafeInteger(e)||e<0)ue(`${t} must be a non-negative safe integer`);return e}function Pa(e,t){let r=ro(e,t);if(!/^sha256:[0-9a-f]{64}$/u.test(r))ue(`${t} must be a SHA-256 digest`);return r}function hm(e,t){try{return Xo(e,t)}catch(r){if(r instanceof TypeError)return ue(r.message);throw r}}function xR(e){let t=Ju(e,"binary response.headers"),r={};for(let[i,n]of Object.entries(t)){if(!Zq.test(i))ue(`binary response header name ${JSON.stringify(i)} is invalid`);let o=ro(n,`binary response.headers.${i}`);if(Wq(o))ue(`binary response header ${JSON.stringify(i)} contains a control character`);let s=i.toLowerCase();if(Object.hasOwn(r,s))ue(`binary response header ${JSON.stringify(i)} occurs more than once`);if(s==="content-length"||s==="transfer-encoding"||s==="connection")ue(`binary response header ${JSON.stringify(i)} is transport-reserved`);r[s]=o}return Object.freeze(r)}function ue(e){throw new Fn({code:Ae.INVALID_REQUEST,message:e})}function Kq(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}var Zq=/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/u;function Wq(e){for(let t=0;t<e.length;t+=1){let r=e.charCodeAt(t);if(r<=31||r===127)return!0}return!1}var Yq=new Set(["kind","requestId","invocation","body","mediaType","headers"]),Qq=/^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/u;function gm(e){let t=Ju(e,"binary response");if(He(t,Yq,"binary response"),We(t,["kind","requestId","invocation","body","mediaType"],"binary response"),t.kind!=="binary")ue('binary response.kind must be "binary"');if(!(t.body instanceof Uint8Array))ue("binary response.body must be a Uint8Array");let r=ro(t.mediaType,"binary response.mediaType");if(!Qq.test(r))ue("binary response.mediaType is invalid");let i=t.headers===void 0?void 0:xR(t.headers);return Object.freeze({kind:"binary",requestId:Tt(t.requestId,"binary response.requestId"),invocation:Hr(t.invocation,"binary response.invocation"),body:new Uint8Array(t.body),mediaType:r,...i===void 0?{}:{headers:i}})}var Xq=new Set(["version","kind","requestId"]);function wR(e){let t=yt(e,"cancel request");if(He(t,Xq,"cancel request"),We(t,["version","kind","requestId"],"cancel request"),t.version!==2)ue("cancel request.version must be 2");if(t.kind!=="cancel")ue('cancel request.kind must be "cancel"');return Object.freeze({version:2,kind:"cancel",requestId:Tt(t.requestId,"cancel request.requestId")})}var Nw="x-astrale-idempotency-key",Rw=128;function ym(e,t="idempotency key"){if(typeof e!=="string"||e.length<1||e.length>Rw||!/^[A-Za-z0-9._~-]+$/u.test(e))ue(`${t} must contain 1-128 URL-safe ASCII characters`);return e}var oI={};ze(oI,{BAGGAGE_FIELD:()=>vj,BINARY_HEADERS_FIELD:()=>jw,INVOCATION_FIELD:()=>Lw,LENGTH_PREFIX_V1:()=>hj,MAXIMUM_INVOCATION_FIELD_BYTES:()=>Cm,REQUEST_ID_FIELD:()=>Pw,STREAM_FRAMING_FIELD:()=>Bj,TRACEPARENT_FIELD:()=>nI,TRACESTATE_FIELD:()=>iI,codecForContentType:()=>dj,decodeBinaryHeaderNames:()=>AR,decodeInvocationId:()=>kR,decodeTraceHeaders:()=>xj,encodeBinaryHeaderNames:()=>SR,encodeInvocationId:()=>_R,encodeStreamFrame:()=>gj,encodeTraceHeaders:()=>wj,isApplicationBinaryHeader:()=>bm,negotiateResponseCodec:()=>fj});var jw="x-astrale-binary-headers",Pw="x-astrale-request-id",Lw="x-astrale-invocation",Cm=8192,IR=/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/u,OR=8192,DR=128,zw="-",eJ=new Set(["authorization","cache-control","connection","content-encoding","content-length","content-type","cookie","date","etag","host","keep-alive","location","proxy-authenticate","proxy-authorization","referrer-policy","server","set-cookie","trailer","transfer-encoding","upgrade","vary","www-authenticate",zw,jw,Lw,Pw,"x-astrale-stream-framing"]);function _R(e){let t;try{t=encodeURIComponent(e.source)}catch{return Vr("HTTP binary InvocationId field is invalid.")}let r=`${t};${e.id}`;if(new TextEncoder().encode(r).byteLength>Cm)Vr("HTTP binary InvocationId field is invalid.");return r}function kR(e){if(e===null||e.length===0||new TextEncoder().encode(e).byteLength>Cm)return Vr("HTTP binary InvocationId field is invalid.");let t=e.indexOf(";");if(t<1||e.indexOf(";",t+1)!==-1)Vr("HTTP binary InvocationId field is invalid.");let r;try{r=decodeURIComponent(e.slice(0,t))}catch{return Vr("HTTP binary InvocationId field is invalid.")}try{return ja({source:r,id:e.slice(t+1)})}catch{return Vr("HTTP binary InvocationId field is invalid.")}}function bm(e){let t=e.toLowerCase();return IR.test(t)&&!t.startsWith("access-control-")&&!t.startsWith("sec-websocket-")&&!eJ.has(t)}function SR(e){let t=[],r=new Set;for(let n of Object.keys(e??{})){let o=n.toLowerCase();if(!IR.test(o)||r.has(o))Vr();if(r.add(o),!bm(o))continue;t.push(o)}if(t.length>DR)Vr();let i=t.length===0?zw:t.sort().join(", ");if(new TextEncoder().encode(i).byteLength>OR)Vr();return i}function AR(e){if(e===zw)return Object.freeze([]);if(e===null||e==="")Vr();if(new TextEncoder().encode(e).byteLength>OR)Vr();let t=e.split(",");if(t.length>DR)Vr();let r=[],i=new Set;for(let n of t){let o=n.trim().toLowerCase();if(!bm(o)||i.has(o))Vr();i.add(o),r.push(o)}return Object.freeze(r)}function Vr(e="HTTP binary application-header manifest is invalid."){throw new Fn({code:Ae.INVALID_REQUEST,message:e})}var Lt={};ze(Lt,{CONTENT_TYPE_JSON:()=>es,CONTENT_TYPE_MSGPACK:()=>ts,DecodeError:()=>no,json:()=>La,loadMsgpack:()=>cj});class no extends SyntaxError{name="DecodeError";constructor(e,t){super(e,t)}}var es="application/vnd.astrale+json",ts="application/vnd.astrale.msgpack";var La=Object.freeze({name:"json",contentType:es,binary:!1,encode:te.serialize,decode(e){try{return te.decode(e)}catch(t){if(t instanceof tt)throw new no("JSON envelope is malformed.",{cause:t});throw t}}});var Fa=null;async function cj(){if(Fa===null){let[e,t]=await Promise.all([Promise.resolve().then(() => (tI(),eI)),Promise.resolve().then(() => (Ma(),Yw))]);Fa=Object.freeze({pack:e.pack,unpack:t.unpack})}return uj}var uj=Object.freeze({name:"msgpack",contentType:ts,binary:!0,encode(e){if(Fa===null)throw Error("MsgPack codec is not loaded");return new Uint8Array(Fa.pack(se(e)))},decode(e){if(Fa===null)throw Error("MsgPack codec is not loaded");if(typeof e==="string")throw TypeError("MsgPack requires a binary envelope");let t;try{t=Fa.unpack(e)}catch(r){throw new no("MsgPack envelope is malformed.",{cause:r})}try{return se(t)}catch(r){if(r instanceof he)throw new no("MsgPack envelope is not a portable value.",{cause:r});throw r}}});function lj(e){return e===uj}function rI(e){if(e===La)return"json";if(lj(e))return"msgpack";return}function Xu(e){if(!Array.isArray(e))throw TypeError("supported codecs must be an array.");let t=[],r=new Set;for(let i of e){let n=rI(i);if(n===void 0)throw TypeError("supported contains a foreign codec.");if(r.has(n))throw TypeError(`supported contains duplicate ${n}.`);r.add(n),t.push(Object.freeze({codec:i,profile:n}))}if(!r.has("json"))throw TypeError("supported must contain the canonical JSON codec.");return Object.freeze(t)}var Sm=/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/u,IJ=/^(?:0(?:\.\d{0,3})?|1(?:\.0{0,3})?)$/u;function dj(e,t){let r=Xu(t);if(e===null||e.trim()==="")return;let i=DJ(e);if(i===void 0)return;let n=i===es?"json":i===ts?"msgpack":void 0;return r.find((o)=>o.profile===n)?.codec}function fj(e,t,r){let i=Xu(r),n=i.find((a)=>a.codec===t);if(n===void 0)throw TypeError("requestCodec must occur exactly once in supported.");if(e===null||e.trim()==="")return n.codec;let o=_J(e);if(o.length===0)return;let s=i.flatMap((a)=>{let[c,u]=OJ(a.profile).split("/"),l=o.filter((d)=>d.mediaParameters===0&&(d.type==="*"||d.type===c)&&(d.subtype==="*"||d.subtype===u)).sort((d,f)=>f.specificity-d.specificity||d.index-f.index)[0];return l===void 0||l.quality===0?[]:[{...a,governing:l}]});if(s.length===0)return;return s.sort((a,c)=>{let u=c.governing.quality-a.governing.quality;if(u!==0)return u;if(a.codec===n.codec)return-1;if(c.codec===n.codec)return 1;let l=a.governing.index-c.governing.index;if(l!==0)return l;if(a.profile==="json")return-1;if(c.profile==="json")return 1;return 0}),s[0]?.codec}function OJ(e){return e==="json"?es:ts}function DJ(e){if(Am(e,",")?.length!==1)return;let t=Am(e,";");if(t===void 0)return;let r=t.shift()?.trim().toLowerCase();if(r===void 0||pj(r,!1)===void 0)return;let i=new Set;for(let n of t){let o=mj(n);if(o===void 0||i.has(o.name))return;i.add(o.name)}return r}function _J(e){let t=Am(e,",");if(t===void 0)return[];let r=[];for(let[i,n]of t.entries()){let o=Am(n,";");if(o===void 0)continue;let s=pj(o.shift()?.trim().toLowerCase()??"",!0);if(s===void 0)continue;let a=1,c=!1,u=0,l=!1,d=new Set;for(let f of o){let m=mj(f);if(m===void 0||d.has(m.name)){l=!0;break}if(d.add(m.name),m.name==="q"){if(c||!IJ.test(m.value)){l=!0;break}c=!0,a=Number(m.value)}else if(!c)u+=1}if(l)continue;r.push({...s,quality:a,specificity:s.type==="*"?0:s.subtype==="*"?1:2,index:i,mediaParameters:u})}return r}function pj(e,t){let r=e.indexOf("/");if(r<=0||r!==e.lastIndexOf("/"))return;let i=e.slice(0,r),n=e.slice(r+1);if(n==="")return;let o=Sm.test(i)||t&&i==="*",s=Sm.test(n)||t&&n==="*";if(!o||!s||i==="*"&&n!=="*")return;return{type:i,subtype:n}}function mj(e){let t=e.indexOf("=");if(t<=0)return;let r=e.slice(0,t).trim().toLowerCase(),i=e.slice(t+1).trim();if(!Sm.test(r)||!Sm.test(i)&&!kJ(i))return;return{name:r,value:SJ(i)}}function kJ(e){if(e.length<2||e[0]!=='"'||e.at(-1)!=='"')return!1;for(let t=1;t<e.length-1;t+=1){let r=e.charCodeAt(t);if(e[t]==="\\"){if(t+=1,t>=e.length-1)return!1;continue}if(e[t]==='"'||r===127||r<32&&r!==9)return!1}return!0}function SJ(e){if(e[0]!=='"')return e;let t="";for(let r=1;r<e.length-1;r+=1){if(e[r]==="\\")r+=1;t+=e[r]}return t}function Am(e,t){let r=[],i=!1,n=!1,o=0;for(let s=0;s<e.length;s+=1){let a=e[s];if(n){n=!1;continue}if(i&&a==="\\"){n=!0;continue}if(a==='"'){i=!i;continue}if(!i&&a===t)r.push(e.slice(o,s)),o=s+1}if(i||n)return;return r.push(e.slice(o)),r}var Bj="x-astrale-stream-framing",hj="length-prefix-v1",AJ=new TextEncoder;function gj(e,t){let r=e.encode(t),i=typeof r==="string"?AJ.encode(r):r;if(i.byteLength>4294967295)throw RangeError("stream frame exceeds the uint32 length-prefix-v1 payload bound.");let n=new Uint8Array(4+i.byteLength);return new DataView(n.buffer).setUint32(0,i.byteLength),n.set(i,4),n}var yj=512,Cj=512,bj=32,$J=/^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})/u,TJ=/^-[\x21-\x7e]+$/u,NJ=/^[a-z][a-z0-9_*/-]{0,255}$/u,RJ=/^[a-z0-9][a-z0-9_*/-]{0,240}$/u,jJ=/^[a-z][a-z0-9_*/-]{0,13}$/u,PJ=/^[\x20-\x2b\x2d-\x3c\x3e-\x7e]{0,255}[\x21-\x2b\x2d-\x3c\x3e-\x7e]$/u;function Ci(e){if(e===null||typeof e!=="object"||Array.isArray(e))return;let t=Reflect.ownKeys(e);if(!t.includes("traceparent")||t.some((o)=>o!=="traceparent"&&o!=="tracestate"))return;let r,i;try{let o=e;r=o.traceparent,i=o.tracestate}catch{return}if(typeof r!=="string"||!LJ(r))return;let n=typeof i==="string"&&zJ(i)?i:void 0;return Object.freeze({traceparent:r,...n===void 0||n.trim()===""?{}:{tracestate:n}})}function LJ(e){if(e.length<55||e.length>512)return!1;let t=$J.exec(e);if(t===null||t.index!==0)return!1;let[,r,i,n,o]=t;if(r===void 0||i===void 0||n===void 0||o===void 0||r==="ff"||/^0+$/u.test(i)||/^0+$/u.test(n))return!1;if(r==="00")return e.length===55&&(o==="00"||o==="01");return e.length===55||TJ.test(e.slice(55))}function zJ(e){if(e.length>512)return!1;let t=e.split(",");if(t.length>32)return!1;let r=new Set;for(let i of t){let n=i.replace(/^[ \t]+|[ \t]+$/gu,"");if(n==="")continue;let o=n.indexOf("=");if(o<1||o!==n.lastIndexOf("="))return!1;let s=n.slice(0,o),a=n.slice(o+1);if(!MJ(s)||!PJ.test(a)||r.has(s))return!1;r.add(s)}return!0}function MJ(e){let t=e.indexOf("@");if(t===-1)return NJ.test(e);if(t!==e.lastIndexOf("@"))return!1;return RJ.test(e.slice(0,t))&&jJ.test(e.slice(t+1))}var nI="traceparent",iI="tracestate",vj="baggage",Ej=Object.freeze({});function xj(e,t){if(e===null)return;return Ci({traceparent:e,...t===null?{}:{tracestate:t}})}function wj(e){if(e===void 0)return Ej;let t=Ci(e);if(t===void 0)return Ej;return Object.freeze({[nI]:t.traceparent,...t.tracestate===void 0?{}:{[iI]:t.tracestate}})}var UJ=new Set(["ttlSeconds","attenuation"]);function Tm(e){let t=Ju(e,"delegate");if(He(t,UJ,"delegate"),We(t,["ttlSeconds"],"delegate"),!Number.isSafeInteger(t.ttlSeconds)||t.ttlSeconds<1)ue("delegate.ttlSeconds must be a positive safe integer");let r;if(t.attenuation!==void 0){try{r=Vp.acceptUnresolved({v:1,expr:t.attenuation}).expr}catch(i){if(i instanceof be)ue("delegate.attenuation must be a valid expression");throw i}$m(r)}return Object.freeze({ttlSeconds:t.ttlSeconds,...r===void 0?{}:{attenuation:r}})}function $m(e){if(e.kind==="identity"){if("credential"in e&&typeof e.credential!=="string")ue("delegate.attenuation credentials must be non-empty text");return}if(e.kind==="exclude"){$m(e.base);for(let t of e.excluded)$m(t);return}for(let t of e.operands)$m(t)}var FJ=new Set(["kind","requestId","invocation"]);function el(e){let t=yt(e,"miss control");if(He(t,FJ,"miss control"),We(t,["kind","requestId","invocation"],"miss control"),t.kind!=="miss")ue('miss control.kind must be "miss"');return Object.freeze({kind:"miss",requestId:Tt(t.requestId,"miss control.requestId"),invocation:Hr(t.invocation,"miss control.invocation")})}function Ij(e,t){return el({kind:"miss",requestId:e,invocation:t})}var er={};ze(er,{BUNDLE_MEDIA_TYPE:()=>Kr,ClassOperationOrder:()=>tB,MEDIA_TYPE:()=>TP,PATH:()=>oB,PublicationError:()=>so,accept:()=>hs,acceptBundle:()=>fl,acceptInvocationEndpoints:()=>ss,acceptReference:()=>Za,admitRequirements:()=>po,compareReference:()=>VO,compareReferences:()=>HO,decodeBundle:()=>sB,delivery:()=>GO,describeBundle:()=>Dj,encode:()=>dl,matchesReference:()=>qP,reference:()=>uB,seal:()=>RP,url:()=>NP,validateRequirements:()=>iB});class so extends Error{code;name="PublicationError";constructor(e,t,r){super(t,r);this.code=e}}function W(e,t,r){throw new so(e,t,r===void 0?void 0:{cause:r})}function Le(e,t,r){if(e===null||typeof e!=="object"||Array.isArray(e))W(t,r);return e}function Je(e,t,r){let i=new Set(t);if(Object.keys(e).some((n)=>!i.has(n)))W(r,"Object contains unknown fields.")}function Ga(e,t){if(!Array.isArray(e))W(t,"Expected an array.");return e}function bi(e,t,r){if(new Set(e).size!==e.length)W(t,`Duplicate ${r}.`)}function Gn(e){if(e===null||typeof e!=="object"||Object.isFrozen(e))return e;for(let t of Object.values(e))Gn(t);return Object.freeze(e)}function xn(e,t,r,i=!1){return sI(e,["http:","https:"],t,r,i)}function sI(e,t,r,i,n=!1){if(typeof e!=="string")return W(i,"Expected an absolute URL.");if(!n&&(e.includes("{")||e.includes("}")))return W(i,"Only native route URLs may contain placeholders.");let o;try{o=new URL(n?e.replaceAll(/\{[A-Za-z][A-Za-z0-9_]*\+?\}/gu,"placeholder"):e)}catch(s){if(s instanceof TypeError)return W(i,"Expected an absolute URL.",s);throw s}if(!t.includes(o.protocol)||o.username!==""||o.password!==""||o.hash!==""||!r&&o.search!=="")W(i,"URL has a forbidden protocol, credentials, query, or fragment.");return e}function ss(e){let t=Le(e,"PUBLICATION_BINDING_INVALID","Invocation endpoints are invalid.");Je(t,["http","websocket"],"PUBLICATION_BINDING_INVALID");let r=xn(t.http,!0,"PUBLICATION_BINDING_INVALID"),i=t.websocket===void 0?void 0:sI(t.websocket,["ws:","wss:"],!0,"PUBLICATION_BINDING_INVALID");return Object.freeze({http:r,...i===void 0?{}:{websocket:i}})}function aI(e,t){let r=Le(e,"PUBLICATION_BINDING_INVALID","Callable binding is invalid.");return Je(r,["callable","endpoint"],"PUBLICATION_BINDING_INVALID"),Object.freeze({callable:Nm(r.callable,t),endpoint:ss(r.endpoint)})}function Nm(e,t){let r;try{r=Z(String(e))}catch(n){if(n instanceof TypeError)return W("PUBLICATION_BINDING_INVALID","Callable key is invalid.",n);throw n}let i=Z.ref(r);if(Z.origin(r)!==t||!ne.isDefinition(i)&&!ne.isMethod(i)||!i.startsWith("function.")&&!ne.isMethod(i))W("PUBLICATION_BINDING_INVALID","Binding must name one callable owned by the root Domain.");return r}function cI(e,t){let r=Le(e,"PUBLICATION_VIEW_INVALID","Published View binding is invalid.");Je(r,["view","href","handshake"],"PUBLICATION_VIEW_INVALID");let i;try{i=Z(String(r.view))}catch(n){if(n instanceof TypeError)return W("PUBLICATION_VIEW_INVALID","View key is invalid.",n);throw n}if(Z.origin(i)!==t||!Z.ref(i).startsWith("view."))W("PUBLICATION_VIEW_INVALID","View binding must name a root View.");if(r.handshake!=="shell"&&r.handshake!=="none")W("PUBLICATION_VIEW_INVALID","View handshake is invalid.");return Object.freeze({view:i,href:xn(r.href,!0,"PUBLICATION_VIEW_INVALID"),handshake:r.handshake})}var GJ=/^sha256:[0-9a-f]{64}$/u;function Rm(e){if(typeof e!=="string"||!GJ.test(e))W("PUBLICATION_INVALID","Digest is invalid.");return e}function uI(e){let t=te.encode(e);return`sha256:${lI(t)}`}function lI(e){let t=e.length*8,r=Math.ceil((e.length+9)/64)*64,i=new Uint8Array(r);i.set(e),i[e.length]=128;let n=new DataView(i.buffer);n.setUint32(r-8,Math.floor(t/4294967296),!1),n.setUint32(r-4,t>>>0,!1);let o=new Uint32Array(HJ),s=new Uint32Array(64);for(let a=0;a<r;a+=64){for(let g=0;g<16;g+=1)s[g]=n.getUint32(a+g*4,!1);for(let g=16;g<64;g+=1){let w=s[g-15],b=s[g-2],O=Hn(w,7)^Hn(w,18)^w>>>3,k=Hn(b,17)^Hn(b,19)^b>>>10;s[g]=s[g-16]+O+s[g-7]+k>>>0}let[c,u,l,d,f,m,B,h]=o;for(let g=0;g<64;g+=1){let w=Hn(f,6)^Hn(f,11)^Hn(f,25),b=f&m^~f&B,O=h+w+b+VJ[g]+s[g]>>>0,k=Hn(c,2)^Hn(c,13)^Hn(c,22),G=c&u^c&l^u&l,oe=k+G>>>0;h=B,B=m,m=f,f=d+O>>>0,d=l,l=u,u=c,c=O+oe>>>0}o[0]=o[0]+c>>>0,o[1]=o[1]+u>>>0,o[2]=o[2]+l>>>0,o[3]=o[3]+d>>>0,o[4]=o[4]+f>>>0,o[5]=o[5]+m>>>0,o[6]=o[6]+B>>>0,o[7]=o[7]+h>>>0}return[...o].map((a)=>a.toString(16).padStart(8,"0")).join("")}function Hn(e,t){return e>>>t|e<<32-t}var HJ=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),VJ=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);var Kr="application/vnd.astrale.domain-bundle+json;v=1";function Oj(e){let t=Le(e,"PUBLICATION_INVALID","Bundle descriptor is invalid.");Je(t,["href","ref"],"PUBLICATION_INVALID");let r=Os(t.ref);if(r.mediaType!==Kr)W("PUBLICATION_INVALID","Bundle media type is unsupported.");if(r.size<1)W("PUBLICATION_INVALID","Bundle size is invalid.");return Object.freeze({href:xn(t.href,!0,"PUBLICATION_INVALID"),ref:Object.freeze({...r,mediaType:Kr})})}function Dj(e,t){let r=Mr.encode(e);return Object.freeze({href:xn(t,!0,"PUBLICATION_INVALID"),ref:Object.freeze({...Ds(r,Kr),mediaType:Kr})})}function _j(e){try{return Mr.accept(e)}catch(t){if(t instanceof Y.Error)return W("PUBLICATION_INVALID","Publication bundle is invalid.",t);throw t}}function dI(e,t){let r=e.schema.bundle;if(t.byteLength!==r.ref.size||`sha256:${lI(t)}`!==r.ref.digest)W("PUBLICATION_INVALID","Bundle artifact does not match its descriptor.")}function kj(e,t){if(!(t instanceof Uint8Array))W("PUBLICATION_INVALID","Bundle artifact bytes are invalid.");dI(e,t);try{return Mr.decode(t)}catch(r){if(r instanceof Y.Error)return W("PUBLICATION_INVALID","Bundle artifact cannot be decoded.",r);throw r}}function Sj(e,t){if(e===void 0)return;let r=Le(e,"PUBLICATION_INVALID","Delivery endpoint is invalid.");Je(r,["href","method","authentication"],"PUBLICATION_INVALID");let i=xn(r.href,!0,"PUBLICATION_INVALID");if(new URL(i).origin!==new URL(t).origin||r.method!=="POST")W("PUBLICATION_INVALID","Delivery endpoint must be same-origin POST.");let n=Le(r.authentication,"PUBLICATION_INVALID","Delivery authentication is invalid.");if(Je(n,["kind"],"PUBLICATION_INVALID"),n.kind!=="public"&&n.kind!=="bearer")W("PUBLICATION_INVALID","Delivery authentication kind is invalid.");return Object.freeze({href:i,method:"POST",authentication:Object.freeze({kind:n.kind})})}function Aj(e){if(e===void 0)return;let t=Le(e,"PUBLICATION_INVALID","Manifest is invalid.");if(Je(t,["logo","entrypoint"],"PUBLICATION_INVALID"),t.logo!==void 0&&typeof t.logo!=="string")W("PUBLICATION_INVALID","Manifest logo must be a string.");let r;if(t.entrypoint!==void 0){if(typeof t.entrypoint!=="string"||!ne.isDefinition(t.entrypoint)||!t.entrypoint.startsWith("view."))W("PUBLICATION_INVALID","Manifest entrypoint must be a root View reference.");r=t.entrypoint}return Object.freeze({...t.logo===void 0?{}:{logo:t.logo},...r===void 0?{}:{entrypoint:r}})}class jm{origin;name;ref;key;definition;path;constructor(e,t,r){this.origin=e,this.name=t,this.ref=ne.core(t),this.key=Z.of(e,this.ref),this.definition=r,this.path=q.project({origin:e,kind:"core",name:t}),Object.freeze(this)}}function fI(e){let t={};for(let r of Object.keys(e.core.nodes).sort())Object.defineProperty(t,r,{enumerable:!0,value:new jm(e.origin,r,e.core.nodes[r])});return Object.freeze(t)}class Oe extends Error{code;diagnostics;constructor(e,t,r=[],i){super(t,i);this.code=e,this.diagnostics=r,this.name="DomainError"}}class wn{#e;constructor(e){this.#e=new Map(e),Object.freeze(this)}get size(){return this.#e.size}get(e){return this.#e.get(e)}has(e){return this.#e.has(e)}entries(){return this.#e.entries()}keys(){return this.#e.keys()}values(){return this.#e.values()}forEach(e,t){for(let[r,i]of this.#e)e.call(t,i,r,this)}[Symbol.iterator](){return this.entries()}}function Ei(e,t,r){let i=ne.definition(t,r);return Object.freeze({origin:e,kind:t,name:r,ref:i,key:Z.of(e,i)})}function $j(e){let t=e.analysis?.data;return t===void 0?void 0:Object.freeze({owner:Ei(t.owner.origin,t.owner.kind,t.owner.name),definition:t.declaration})}function pI(e,t){let r=[e],i=new Set;while(r.length>0){let n=r.shift();if(n.key===t.key)return!0;if(i.has(n.key))continue;if(i.add(n.key),n.kind==="interface")r.push(...n.extends);if(n.kind==="class")r.push(...n.implements)}return!1}function mI(e){if(e.schemaRef.kind==="interface")return e.declaration.extends;if(e.schemaRef.kind==="class")return e.declaration.implements;return[]}function BI(e,t,r){let i=t.get(e.origin);if(i===void 0)return;if(qJ(e.kind)){let o=e,s=r.$.schema===i?r:Y.resolve(i),a=s.$.refs.definition(o);if(a===void 0)return;return Object.freeze({schemaRef:e,declaration:a.declaration,analysis:s.$.refs.effective(o)})}let n=Tj(i,e.kind,e.name);return n===void 0?void 0:Object.freeze({schemaRef:e,declaration:n})}function hI(e,t){let r=t.indexOf("."),i=t.slice(0,r),n=t.slice(r+1);switch(i){case"class":{let o=e.classes[n];return o===void 0?void 0:{origin:e.origin,kind:Rj(o),name:n}}case"interface":{let o=e.interfaces[n];return o===void 0?void 0:{origin:e.origin,kind:Nj(o),name:n}}case"type":case"function":case"policy":case"view":return Tj(e,i,n)===void 0?void 0:{origin:e.origin,kind:i,name:n};default:return}}function gI(e){return[...Object.entries(e.interfaces).map(([t,r])=>({origin:e.origin,kind:Nj(r),name:t})),...Object.entries(e.classes).map(([t,r])=>({origin:e.origin,kind:Rj(r),name:t})),...Object.keys(e.types).map((t)=>({origin:e.origin,kind:"type",name:t})),...Object.keys(e.functions).map((t)=>({origin:e.origin,kind:"function",name:t})),...Object.keys(e.policies).map((t)=>({origin:e.origin,kind:"policy",name:t})),...Object.keys(e.views).map((t)=>({origin:e.origin,kind:"view",name:t}))]}function yI(){return["type","interface","class","function","policy","view"]}function Tj(e,t,r){switch(t){case"type":return e.types[r];case"function":return e.functions[r];case"policy":return e.policies[r];case"view":return e.views[r];default:return}}function Nj(e){return"interface"}function Rj(e){return"class"}function qJ(e){return e==="class"||e==="interface"}function CI(e,t,r){if(typeof e!=="string")return r.has(e.origin)?e:void 0;let i=t,n;if(Z.is(e)){i=Z.origin(e);let s=Z.ref(e);if(!ne.isDefinition(s))return;n=s}else{if(!ne.isDefinition(e))return;n=e}let o=r.get(i);return o===void 0?void 0:hI(o,n)}function ao(e,t,r,i){let n=t.flatMap((o)=>{let s=e.localByKind.get(o)?.get(r);return s===void 0?[]:[s]});if(n.length===1)return n[0];if(n.length>1)throw new Oe("DOMAIN_DEFINITION_AMBIGUOUS",`${i} ${JSON.stringify(r)} is ambiguous in ${e.schema.origin}.`);throw new Oe("DOMAIN_DEFINITION_NOT_FOUND",`${i} ${JSON.stringify(r)} does not exist in ${e.schema.origin}.`)}var JJ=new Set(["$","origin","kind","name","ref","key","definition","path","properties","data","methods","family","implements","extends"]);function bI(e,t,r){let i=new Set([...t.keys(),...r.keys()]);for(let n of i){if(JJ.has(n))continue;let o=t.get(n)??[],s=r.get(n)??[];if(o.length+s.length!==1)continue;Object.defineProperty(e,n,{enumerable:!0,value:o[0]??s[0]})}}function Pm(e,t,r,i,n){let o=e.get(r);if(o!==void 0)return o;let s=t.get(r)??[];if(s.length===1)return s[0];if(s.length>1)throw new Oe(i==="Property"?"DOMAIN_PROPERTY_AMBIGUOUS":"DOMAIN_METHOD_NOT_FOUND",`${i} ${JSON.stringify(r)} is ambiguous on ${n}; use one of: ${s.map((a)=>a.key).join(", ")}.`);throw new Oe(i==="Property"?"DOMAIN_PROPERTY_NOT_FOUND":"DOMAIN_METHOD_NOT_FOUND",`${i} ${JSON.stringify(r)} does not exist on ${n}.`)}function Lm(e){let t=new Map;for(let r of e){let i=t.get(r.name)??[];i.push(r),t.set(r.name,i)}return t}function EI(e,t){return q.instanceMethod(e,t)}function vI(e,t){return q.staticMethod(q.project(e),t)}function xI(e){let t=[];for(let[r,i]of e.analysis?.methods??[]){let n=Ei(i.owner.origin,i.owner.kind,i.owner.name),o=ne.method(n.ref,r),s={ref:o,key:Z.of(n.origin,o),name:r,owner:n,definition:i.declaration},a=Object.freeze(i.declaration.static?{...s,path:vI(i.owner,r)}:{...s,on:(c)=>EI(c,r)});t.push([a.key,a])}return new wn(t)}function wI(e){let t=[];for(let[r,i]of e.analysis?.properties??[]){let n=Ei(i.owner.origin,i.owner.kind,i.owner.name),o=ne.property(n.ref,i.name);t.push([r,Object.freeze({ref:o,key:r,name:i.name,owner:n,definition:Object.freeze({schema:i.schema,required:i.required,visibility:i.visibility,...i.auto===void 0?{}:{auto:i.auto}})})])}return new wn(t)}class II{$;origin;kind;name;ref;key;schemaRef;definition;path;properties;data;methods;constructor(e,t){let r=Ei(e.schemaRef.origin,e.schemaRef.kind,e.schemaRef.name);this.origin=r.origin,this.kind=r.kind,this.name=r.name,this.ref=r.ref,this.key=r.key,this.schemaRef=Object.freeze({origin:e.schemaRef.origin,kind:e.schemaRef.kind,name:e.schemaRef.name}),this.definition=e.declaration,this.path=KJ(e.schemaRef),this.properties=wI(e),this.methods=xI(e),this.data=$j(e);let i=Object.freeze(mI(e).map((s)=>t(s)));if(e.schemaRef.kind==="interface")Object.defineProperty(this,"family",{enumerable:!0,value:e.declaration.family}),Object.defineProperty(this,"extends",{enumerable:!0,value:i});else if(e.schemaRef.kind==="class")Object.defineProperty(this,"family",{enumerable:!0,value:e.declaration.family}),Object.defineProperty(this,"implements",{enumerable:!0,value:i});let n=Lm(this.properties.values()),o=Lm(this.methods.values());this.$=Object.freeze({property:(s)=>Pm(this.properties,n,s,"Property",this.key),method:(s)=>Pm(this.methods,o,s,"Method",this.key)}),bI(this,n,o),Object.freeze(this)}satisfies(e){return pI(this,e)}}function KJ(e){switch(e.kind){case"interface":case"class":case"function":case"policy":case"view":return q.project(e);case"type":return}}function OI(e){let t;try{t=Y.resolve(e)}catch(m){throw new Oe("DOMAIN_DEPENDENCY_MISSING",`Cannot construct Domain ${e.origin} without its exact accepted dependency closure.`,[],{cause:m})}let r=new wn([e,...t.$.closure].map((m)=>[m.origin,m])),i=new Map,n=(m)=>{let B=ne.definition(m.kind,m.name),h=Z.of(m.origin,B),g=i.get(h);if(g!==void 0)return g;let w=BI(m,r,t);if(w===void 0)throw new Oe("DOMAIN_DEFINITION_NOT_FOUND",`Definition ${h} does not exist.`);let b=new II(w,n);return i.set(h,b),b},o=(m)=>{let B=CI(m,e.origin,r);if(B===void 0){let h=typeof m==="string"?m:JSON.stringify(m);throw new Oe("DOMAIN_DEFINITION_NOT_FOUND",`Definition ${h} does not exist in the accepted closure.`)}return n(B)},a=gI(e).sort((m,B)=>ZJ(Z.of(m.origin,ne.definition(m.kind,m.name)),Z.of(B.origin,ne.definition(B.kind,B.name)))).map((m)=>{let B=n(m);return[B.key,B]}),c=new wn(a),u=[];for(let m of yI()){let B=a.filter(([,h])=>h.kind===m).map(([,h])=>[h.name,h]);u.push([m,new wn(B)])}let l=new wn(u),d=new Map;for(let[,m]of a){let B=d.get(m.name)??[];B.push(m),d.set(m.name,B)}let f=new wn([...d].flatMap(([m,B])=>B.length===1?[[m,B[0]]]:[]));return Object.freeze({schema:e,resolved:t,schemas:r,localDefinitions:c,localByKind:l,flat:f,definition:o,schemaDefinition:n})}function ZJ(e,t){return e<t?-1:e>t?1:0}function DI(e,t,r,i){let n=[];for(let o of e.methods.values()){if(!jj(o))continue;let s=e.kind==="interface"?t.$.method(o.name):o;if(!jj(s)||s.definition.inheritance==="abstract")throw new Oe("DOMAIN_METHOD_NOT_FOUND",`Concrete Class ${t.key} has no executable instance Method for ${o.key}.`);n.push(Object.freeze({key:o.key,name:o.name,owner:o.owner,call:i(s,r)}))}return Object.freeze(n)}function jj(e){return typeof e==="object"&&e!==null&&"on"in e}var Lj=new Set(["$","$d","class","props"]);function _I(e,t,r,i){let n=new Map,o=new Map,s=new Map;for(let f of t.properties.values()){let m=e.props[f.key];n.set(f.key,m),zm(o,f.name,[f.key,m]);let B=Pj(s,f.owner.origin,f.owner.ref,f.owner.name);B.properties.set(f.key,m),zm(B.propertyNames,f.name,[f.key,m])}let a=new Map,c=new Map;if(i!==void 0&&eK(e))for(let f of DI(t,r,e,i)){a.set(f.key,f.call),zm(c,f.name,[f.key,f.call]);let m=Pj(s,f.owner.origin,f.owner.ref,f.owner.name);m.methods.set(f.key,f.call),zm(m.methodNames,f.name,[f.key,f.call])}let u=WJ(s),l=Object.freeze({definition:t,property:(f)=>Mm(n,o,f,"Property",t.key),method:(f)=>Mm(a,c,f,"Method",t.key)}),d={...e,$:l};return Object.defineProperty(d,"$d",{enumerable:!0,value:(f)=>{let m=u.get(f);if(m!==void 0)return m;throw new Oe("DOMAIN_DEFINITION_NOT_FOUND",`No Property or bound Method owner from ${f} exists on ${t.key}.`)}}),zj(d,o,c),QJ(d,u),Object.freeze(d)}function Pj(e,t,r,i){let n=`${t}:${r}`,o=e.get(n);if(o!==void 0)return o;let s={origin:t,ref:r,name:i,properties:new Map,propertyNames:new Map,methods:new Map,methodNames:new Map};return e.set(n,s),s}function WJ(e){let t=new Map;for(let i of e.values()){let n=t.get(i.origin)??[];n.push(i),t.set(i.origin,n)}let r=new Map;for(let[i,n]of t){let o={},s=XJ(n,(a)=>a.name);for(let a of n){let c=YJ(a);if(Object.defineProperty(o,a.ref,{enumerable:!0,value:c}),s.get(a.name)?.length===1&&!(a.name in o))Object.defineProperty(o,a.name,{enumerable:!0,value:c})}r.set(i,Object.freeze(o))}return r}function YJ(e){let t={},r=Object.freeze({property:(i)=>Mm(e.properties,e.propertyNames,i,"Property",`${e.origin}:${e.ref}`),method:(i)=>Mm(e.methods,e.methodNames,i,"Method",`${e.origin}:${e.ref}`)});return Object.defineProperty(t,"$",{enumerable:!0,value:r}),zj(t,e.propertyNames,e.methodNames),Object.freeze(t)}function zj(e,t,r){let i=new Set([...t.keys(),...r.keys()]);for(let n of i){if(Lj.has(n)||n in e)continue;let o=t.get(n)??[],s=r.get(n)??[];if(o.length+s.length!==1)continue;Object.defineProperty(e,n,{enumerable:!0,value:o[0]?.[1]??s[0]?.[1]})}}function QJ(e,t){let r=new Map;for(let i of t.values())for(let[n,o]of Object.entries(i)){if(n.includes("."))continue;let s=r.get(n)??[];if(!s.includes(o))s.push(o);r.set(n,s)}for(let[i,n]of r){if(n.length!==1||Lj.has(i)||i in e)continue;Object.defineProperty(e,i,{enumerable:!0,value:n[0]})}}function Mm(e,t,r,i,n){let o=e.get(r);if(o!==void 0||e.has(r))return o;let s=t.get(r)??[];if(s.length===1)return s[0][1];if(s.length>1)throw new Oe(i==="Property"?"DOMAIN_PROPERTY_AMBIGUOUS":"DOMAIN_METHOD_NOT_FOUND",`${i} ${JSON.stringify(r)} is ambiguous on ${n}; use one of: ${s.map(([a])=>a).join(", ")}.`);throw new Oe(i==="Property"?"DOMAIN_PROPERTY_NOT_FOUND":"DOMAIN_METHOD_NOT_FOUND",`${i} ${JSON.stringify(r)} does not exist on ${n}.`)}function zm(e,t,r){let i=e.get(t)??[];i.push(r),e.set(t,i)}function XJ(e,t){let r=new Map;for(let i of e){let n=t(i),o=r.get(n)??[];o.push(i),r.set(n,o)}return r}function eK(e){return"id"in e}function kI(e,t,r,i){let n=tK(t),o=e.schemaDefinition({origin:Ze.origin(t.class),kind:"class",name:Ze.name(t.class)});if(r!==void 0){if(n&&r.family!=="node"||!n&&(r.kind!=="class"||r.family!=="edge"))throw new Oe("DOMAIN_VALUE_KIND_MISMATCH",`${r.key} cannot describe a ${n?"Node":"Edge"} value.`);if(!(r.kind==="class"?r.key===o.key:o.satisfies(r)))throw new Oe("DOMAIN_VALUE_CLASS_MISMATCH",`Graph value Class ${o.key} does not satisfy ${r.key}.`)}return _I(t,r??o,o,n?i:void 0)}function tK(e){return"id"in e}function Um(e,t){let r=Z.origin(t),i=Z.ref(t);if(rK(i)){let o=i.lastIndexOf(".method."),s=i.slice(0,o),a=i.slice(o+8);return{declaration:e.definition(Z.of(r,s)).$.method(a).definition,owner:Mj(e,r)}}if(!ne.isDefinition(i)||!i.startsWith("function."))throw new Oe("DOMAIN_DEFINITION_KIND_MISMATCH",`${t} is not callable.`);let n=e.definition(t);if(n.kind!=="function")throw new Oe("DOMAIN_DEFINITION_KIND_MISMATCH",`${n.key} is not a Function.`);return{declaration:n.definition,owner:Mj(e,r)}}function Mj(e,t){let r=e.schemas.get(t);if(r===void 0)throw new Oe("DOMAIN_DEPENDENCY_MISSING",`Exact schema ${t} is unavailable while validating its declaration.`);return r}function rK(e){return e.includes(".method.")}function Xt(e,t,r,i){return Object.freeze({code:e,message:t,...r===void 0?{}:{path:r},...i===void 0?{}:{details:i}})}function Uj(e,t=[]){return Object.freeze({status:e,diagnostics:Object.freeze([...t])})}function cn(e){return Uj(e.length===0?"pass":"reject",e)}function SI(e,t,r){try{let{declaration:i,owner:n}=Um(e,t);return cn(Y.values.validate(n,i.input,r,"/input").map((o)=>Xt(o.code,o.message,o.pointer)))}catch(i){return cn([nK(i)])}}function nK(e){return e instanceof Oe?Xt(e.code,e.message):Xt("DOMAIN_VALIDATION_FAILED",e instanceof Error?e.message:String(e))}function AI(e,t,r){try{let{declaration:i,owner:n}=Um(e,t),o=i.output.mode==="value"?i.output.schema:i.output.mode==="stream"?i.output.item:void 0;if(o===void 0)return cn([Xt("DOMAIN_OUTPUT_NOT_JSON","A binary callable has no JSON output value to validate.","/output")]);return cn(Y.values.validate(n,o,r,"/output").map((s)=>Xt(s.code,s.message,s.pointer)))}catch(i){return cn([iK(i)])}}function iK(e){return e instanceof Oe?Xt(e.code,e.message):Xt("DOMAIN_VALIDATION_FAILED",e instanceof Error?e.message:String(e))}function tl(e,t,r){let i=se(r);if(i===null||typeof i!=="object"||Array.isArray(i))throw new Oe("DOMAIN_PROPERTY_INPUT_INVALID","Property input must be a JSON object.");let n=e.definition(t),o=oK(n.properties.values()),s={},a=new Set;for(let[c,u]of Object.entries(i)){let l=n.properties.get(c),d=l===void 0?o.get(c)??[]:[l];if(d.length===0)throw new Oe("DOMAIN_PROPERTY_UNKNOWN",`Property ${JSON.stringify(c)} does not exist on ${n.key}.`);if(d.length>1)throw new Oe("DOMAIN_PROPERTY_AMBIGUOUS",`Property ${JSON.stringify(c)} is ambiguous on ${n.key}; use one of: ${d.map((m)=>m.key).join(", ")}.`);let f=d[0];if(a.has(f.key))throw new Oe("DOMAIN_PROPERTY_DUPLICATE",`Property ${f.key} was supplied more than once.`);a.add(f.key),Object.defineProperty(s,f.key,{enumerable:!0,value:u})}return ar(s)}function oK(e){let t=new Map;for(let r of e){let i=t.get(r.name)??[];if(!i.some((n)=>n.key===r.key))i.push(r);t.set(r.name,i)}return t}function rl(e,t,r){let i,n;try{n=e.definition(t),i=tl(e,t,r)}catch(a){return cn([aK(a)])}if(n.kind!=="class")return cn([Xt("DOMAIN_CLASS_REQUIRED",`${n.key} is not a concrete Class.`,"/definition")]);let o=[],s=new Set(n.properties.keys());for(let a of Object.keys(i))if(!s.has(a))o.push(Xt("DOMAIN_PROPERTY_UNKNOWN",`Unknown Property ${a}.`,`/properties/${a}`));for(let a of n.properties.values()){let c=i[a.key];if(c===void 0){if(a.definition.required)o.push(Xt("DOMAIN_PROPERTY_REQUIRED",`Required Property ${a.key} is absent.`,`/properties/${a.key}`));continue}let u=sK(e,a.owner.origin);o.push(...Y.values.validate(u,a.definition.schema,c,`/properties/${a.key}`).map((l)=>Xt(l.code,l.message,l.pointer,l.ref===void 0?void 0:{ref:l.ref})))}return cn(o)}function sK(e,t){let r=e.schemas.get(t);if(r===void 0)throw new Oe("DOMAIN_DEPENDENCY_MISSING",`Exact schema ${t} is unavailable while validating its declaration.`);return r}function aK(e){return e instanceof Oe?Xt(e.code,e.message):Xt("DOMAIN_VALIDATION_FAILED",e instanceof Error?e.message:String(e))}function $I(e){return Object.freeze({properties:(t,r)=>rl(e,t,r),input(t,r){return SI(e,t,r)},output(t,r){return AI(e,t,r)}})}function TI(e,t,r){let i=tl(e,t,r),n=e.definition(t);if(n.kind!=="class")throw new Oe("DOMAIN_CLASS_REQUIRED",`${n.key} is not a concrete Class.`);let o=rl(e,t,i);if(o.status==="reject")throw new Oe("DOMAIN_VALIDATION_FAILED",`Properties do not satisfy ${n.key}.`,o.diagnostics);return i}function NI(e,t){if(e.kind==="domain")return t==="domain";if(t==="domain")return!1;return e.definitions.some((r)=>t.satisfies(r))}function RI(e,t){let r=t.definition.target;if(r.kind==="domain")return Object.freeze({kind:"domain"});return Object.freeze({kind:"definition",definitions:Object.freeze(r.definitions.map((i)=>e.schemaDefinition(i)))})}function Fj(e,t){return e.key<t.key?-1:e.key>t.key?1:0}function jI(e,t){let r=e.localByKind.get("view")?.values()??[];return Object.freeze([...r].filter((i)=>i.kind==="view").filter((i)=>NI(RI(e,i),t)).sort(Fj))}var Gj=new WeakSet;class PI{$;constructor(e){let t=Object.freeze({nodes:fI(e.schema)}),r=$I(e);this.$=Object.freeze({schema:e.schema,origin:e.schema.origin,path:q.domain(e.schema.origin),revision:e.resolved.$.revision,dependencies:e.schema.dependencies,definitions:e.localDefinitions,core:t,validate:r,inspect:(i)=>e.definition(i),class:(i)=>ao(e,["class"],i,"Class"),interface:(i)=>ao(e,["interface"],i,"Interface"),function:(i)=>ao(e,["function"],i,"Function"),policy:(i)=>ao(e,["policy"],i,"Policy"),view:(i)=>ao(e,["view"],i,"View"),type:(i)=>ao(e,["type"],i,"Type"),viewsFor:(i)=>jI(e,i),properties:(i,n)=>TI(e,i,n),wrap:(...i)=>{let n=cK(i[0]),o=n?i[0]:void 0,s=n?i[1]:i[0],a=n?i[2]:i[1];return kI(e,s,o,a)}});for(let[i,n]of e.flat){if(i==="$")continue;Object.defineProperty(this,i,{enumerable:!0,value:n})}Object.freeze(this),Gj.add(this)}static fromSchema(e){return new PI(OI(e))}static admit(e){if(typeof e!=="object"&&typeof e!=="function"||e===null||!Gj.has(e))throw TypeError("Domain is not an exact rich Domain projection.");return e}}var Ha=PI;function cK(e){return typeof e==="object"&&e!==null&&"$"in e&&"key"in e}var Zr=qt({family:"both",description:"Optional human-facing description metadata with no identity or authority semantics.",properties:{description:qe(Y.metadata.description,{required:!1})}});var Dt=qt({family:"both",description:"Explicit kernel marker for Edge definitions; it carries no structural fields."});var nl=qt({family:"both",description:"Optional bounded presentation icon metadata.",properties:{icon:qe(Y.metadata.icon,{required:!1})}});var il=qt({family:"both",description:"Stable human-facing name metadata that never acts as a locator.",properties:{name:{type:"string",minLength:1,maxLength:100}}});var as=_n({description:"The universal kernel node contract implicitly satisfied by every Node Interface and Node Class."});var LI=qt({family:"both",description:"Optional synchronization metadata for a value originating outside the local kernel.",properties:{externalId:qe({type:"string",minLength:1,maxLength:512},{required:!1}),onConflict:qe({enum:["defaults","error","merge","replace","skip"]},{required:!1}),updatedAt:qe(Y.values.instant,{required:!1})}});var zI=qt({family:"both",description:"Explicit lifecycle-state metadata for values whose contract declares such a state.",properties:{status:{enum:["active","creating","deleting","error","updating"]}}});var MI=qt({family:"both",description:"Explicit creation and update timestamp metadata.",properties:{createdAt:ou(qe(Y.values.instant),{on:"create",set:"instant"}),updatedAt:ou(qe(Y.values.instant),{on:["create","update"],set:"instant"})}});var bt=ir({description:"The installed graph projection of a concrete Node Class or Edge Class declaration.",implements:[Zr,nl],properties:{family:{enum:["node","edge"]}}});var un=ir({description:"The installed graph projection of a both-, Node-, or Edge-family Interface.",implements:[Zr],properties:{family:{enum:["both","node","edge"]}}});var UI=kt.directed({source:{as:"sub",accepts:[un],outgoing:"0..*"},target:{as:"super",accepts:[un],incoming:"0..*"},description:"The protected projection of compatible Interface inheritance.",implements:[Dt],constraints:{noSelf:!0,acyclic:!0}});var FI=kt.directed({source:{as:"class",accepts:[bt],outgoing:"0..*"},target:{as:"interface",accepts:[un],incoming:"0..*"},description:"The protected projection of a Class implementing a compatible Interface.",implements:[Dt],constraints:{noSelf:!0}});var GI=kt.directed({source:{as:"instance",accepts:[as],outgoing:"1"},target:{as:"class",accepts:[bt],incoming:"0..*"},description:"The concrete Node Class fact fixed when a node is created.",implements:[Dt]});var lK={origin:"kernel.astrale.ai",kind:"interface",name:"Identity"};function dr(e,t,r){return kt.directed({source:{as:"identity",accepts:[lK],outgoing:"0..*"},target:{as:t,accepts:[e],incoming:"0..*"},description:r,implements:[Dt]})}var Fm=dr(bt,"class","An Identity may create instances of the target Class.");var Gm=dr(bt,"class","An Identity may delete instances of the target Class.");var fr=ir({description:"One closed authority relation operation administered by can_grant and can_revoke.",implements:[il]});var Hm=dr(fr,"operation","An Identity may create authority edges for the target Operation.");var Vm=dr(bt,"class","An Identity may read complete instances of the target Class; read also permits traversal.");var HI=dr(fr,"operation","An Identity may remove authority edges for the target Operation.");var qm=dr(bt,"class","An Identity may use instances of the target Class as structural Query witnesses without reading their values.");var Jm=dr(bt,"class","An Identity may update instances of the target Class.");var VI=p.strictObject({call:p.strictObject({target:p.string().min(1),input:p.unknown()}),credential:p.string().optional()}),qI=p.strictObject({callable:p.string().min(1),receiver:p.string().min(1).optional()});var Hj=p.string().min(1),JI=p.strictObject({policy:Hj,object:Hj}),KI=p.strictObject({allowed:p.boolean()});var Vj=p.string().min(1),ZI=p.strictObject({audience:Vj,ttlSeconds:p.number().int().min(1),attenuation:p.unknown()}),WI=Vj;var co=p.string().check(en("[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}"));var xt=p.string().min(1),Vn=xt.check(en("sha256:[0-9a-f]{64}")),Kj=p.strictObject({digest:Vn,mediaType:xt,size:p.number().int().min(0).max(Number.MAX_SAFE_INTEGER)}),Zj=p.strictObject({origin:xt,installation:xt,target:Vn,readinessReceipt:Vn,meaningComparison:Vn}),dK=p.discriminatedUnion("kind",[p.strictObject({kind:p.literal("local"),artifact:Vn}),p.strictObject({kind:p.literal("remote"),etag:Vn})]),qj=p.enum(["use","create","read","traverse","update","delete","grant","revoke"]),fK=p.enum(["create","read","traverse","update","delete"]),pK=p.strictObject({functions:p.array(xt).min(1).optional(),classes:p.array(p.strictObject({class:p.strictObject({origin:xt,kind:p.literal("class"),name:xt}),operations:p.array(fK).min(1)})).min(1).optional(),admin:p.strictObject({grant:p.array(qj).min(1).optional(),revoke:p.array(qj).min(1).optional()}).optional()}),Jj=p.strictObject({origin:xt,schemaRevision:xt,schemaBundle:Vn,service:dK,capabilities:pK,dependencies:p.array(Zj)}),mK=p.strictObject({transition:xt,operation:co,installation:xt,origin:xt,source:Jj.nullable(),target:Jj.nullable()}),BK=p.strictObject({installation:xt,target:Vn,transition:xt,dependencies:p.array(Zj)}),Km=p.strictObject({intent:mK,phase:p.enum(["cutover","converge"]),state:p.literal("committed"),readiness:BK.optional()});var YI=p.strictObject({operation:co,domains:p.array(p.union([p.strictObject({source:p.strictObject({kind:p.literal("local"),artifact:Kj}),currentRevision:xt.nullable().optional()}),p.strictObject({source:p.strictObject({kind:p.literal("remote"),url:xt,token:xt.optional()}),targetRevision:xt.optional(),targetEtag:Vn.optional(),currentRevision:xt.nullable().optional()})])).min(1)}),QI=p.strictObject({operation:co,transitions:p.array(Km).min(1)});var hK=p.strictObject({state:p.literal(!0).optional(),target:p.literal(!0).optional(),source:p.literal(!0).optional(),bundle:p.literal(!0).optional(),readiness:p.literal(!0).optional(),capabilities:p.literal(!0).optional()}),XI=p.strictObject({from:p.strictObject({kind:p.literal("installation"),origin:p.string().min(1)}),select:hK});var qn=p.string().min(1),gK=p.strictObject({exact:p.array(qn).optional(),prefixes:p.array(qn).optional()}),eO=p.strictObject({invocation:p.strictObject({source:qn,id:qn}).optional(),topics:gK.optional(),principal:qn.optional(),since:qn.optional(),until:qn.optional(),cursor:qn.optional(),limit:p.number().int().min(1).optional()}),tO=p.strictObject({records:p.array(p.unknown()),frontier:p.strictObject({id:qn,first:p.number().int().min(1).optional(),committed:p.number().int().min(0),durable:p.number().int().min(0)}),cursor:qn.optional(),gap:p.unknown().optional()});var Wj=p.string().min(1),rO=p.strictObject({audience:Wj.optional(),ttlSeconds:p.number().int().min(1),grant:p.unknown().optional()}),nO=Wj;var iO=Xi,oO=Ta;var sO=p.string().min(1),Yj=p.unknown().nonoptional(),Qj=p.discriminatedUnion("op",[p.strictObject({claim:sO,op:p.literal("contains"),value:Yj}),p.strictObject({claim:sO,op:p.literal("eq"),value:Yj}),p.strictObject({claim:sO,op:p.literal("exists")})]),cs=p.array(Qj).max(Kp.MAX_REQUIRED_CLAIMS);var us=p.string().min(1),Xj=cs.optional(),yK=p.strictObject({issuer:us,subject:us,requiredClaims:Xj}),CK=p.strictObject({credentials:p.strictObject({publicKey:p.unknown(),proof:us}),requiredClaims:Xj}),aO=p.strictObject({idempotencyKey:us,mutation:Xi,identities:p.record(p.string(),p.union([yK,CK]))}),cO=p.strictObject({createdNodes:p.record(p.string(),us),identities:p.record(p.string(),p.strictObject({issuer:us,subject:us}))});class ls extends TypeError{path;code="QUERY_RESULT_INVALID";constructor(e,t,r){super(`${t} at ${e||"/"}.`,r);this.path=e,this.name="QueryResultDecodeError"}}var uO=p.string().min(1),bK=p.strictObject({id:uO,class:uO}),lO=p.discriminatedUnion("kind",[p.strictObject({kind:p.literal("reference"),value:bK}),p.strictObject({kind:p.literal("value"),value:rm})]),EK=p.discriminatedUnion("kind",[p.strictObject({kind:p.literal("reference"),value:nm}),p.strictObject({kind:p.literal("value"),value:cw})]),vK=p.strictObject({edge:EK,source:lO,target:lO}),Va=p.discriminatedUnion("kind",[p.strictObject({kind:p.literal("graph"),graph:MN,selection:p.discriminatedUnion("kind",[p.strictObject({kind:p.literal("node"),ids:p.array(uO)}),p.strictObject({kind:p.literal("edge"),keys:p.array(nm)})])}),p.strictObject({kind:p.literal("nodes"),nodes:p.array(lO)}),p.strictObject({kind:p.literal("edges"),edges:p.array(vK)})]);var ol=Object.freeze({decode:ds,encode:xK,selection:wK});function xK(e){return ds(e)}function wK(e){if(e.kind==="graph")return e.selection;if(e.kind==="nodes")return Object.freeze({kind:"node",ids:Object.freeze(e.nodes.map((t)=>t.value.id))});return Object.freeze({kind:"edge",keys:Object.freeze(e.edges.map((t)=>t.edge.kind==="reference"?t.edge.value:it(t.edge.value)))})}function ds(e){try{let t=zn(Va,se(e),Jn);if(t.kind==="graph"){let r=pO(t.graph,"/graph"),i=OK(t.selection,r);return i.kind==="node"?Object.freeze({kind:t.kind,graph:r,selection:i}):Object.freeze({kind:t.kind,graph:r,selection:i})}if(t.kind==="nodes")return Object.freeze({kind:t.kind,nodes:Object.freeze(t.nodes.map((r,i)=>dO(r,`/nodes/${i}`)))});return Object.freeze({kind:t.kind,edges:Object.freeze(t.edges.map((r,i)=>Object.freeze({edge:IK(r.edge,`/edges/${i}/edge`),source:dO(r.source,`/edges/${i}/source`),target:dO(r.target,`/edges/${i}/target`)})))})}catch(t){if(t instanceof ls)throw t;throw new ls(_K(t),"Invalid QueryResult",{cause:t})}}function dO(e,t){if(e.kind==="reference"){let i=e.value;return Object.freeze({kind:e.kind,value:Object.freeze({id:fO(i.id,`${t}/value/id`),class:eP(i.class,`${t}/value/class`)})})}let r=pO({nodes:[e.value],edges:[]},`${t}/value`,"/nodes/0");return Object.freeze({kind:e.kind,value:r.nodes[0]})}function IK(e,t){if(e.kind==="reference"){let i=e.value;return Object.freeze({kind:e.kind,value:Object.freeze({source:fO(i.source,`${t}/value/source`),target:fO(i.target,`${t}/value/target`),class:eP(i.class,`${t}/value/class`)})})}let r=pO({nodes:[],edges:[e.value]},`${t}/value`,"/edges/0");return Object.freeze({kind:e.kind,value:r.edges[0]})}function pO(e,t,r){try{return Hu.decode(e)}catch(i){let n=i instanceof Yi?r!==void 0&&i.path.startsWith(r)?i.path.slice(r.length):i.path:"";Jn(DK(t,n),"Invalid graph value",i)}}function fO(e,t){try{return Fe(e)}catch(r){Jn(t,"Invalid NodeId",r)}}function eP(e,t){try{return Ze.parse(e)}catch(r){Jn(t,"Invalid ClassPath",r)}}function OK(e,t){if(e.kind==="node"){let o=new Set(t.nodes.map((c)=>c.id)),s=new Set,a=Object.freeze(e.ids.map((c,u)=>{let l;try{l=Fe(c)}catch(d){Jn(`/selection/ids/${u}`,"Invalid selected NodeId",d)}if(s.has(l))Jn(`/selection/ids/${u}`,"Duplicate selected NodeId");if(!o.has(l))Jn(`/selection/ids/${u}`,"Selected NodeId is absent from graph");return s.add(l),l}));return Object.freeze({kind:"node",ids:a})}let r=new Set(t.edges.map((o)=>Ge(o))),i=new Set,n=Object.freeze(e.keys.map((o,s)=>{let a;try{a=Object.freeze({source:Fe(o.source),target:Fe(o.target),class:Ze.parse(o.class)})}catch(u){Jn(`/selection/keys/${s}`,"Invalid selected EdgeKey",u)}let c=Ge(a);if(i.has(c))Jn(`/selection/keys/${s}`,"Duplicate selected EdgeKey");if(!r.has(c))Jn(`/selection/keys/${s}`,"Selected EdgeKey is absent from graph");return i.add(c),a}));return Object.freeze({kind:"edge",keys:n})}function Jn(e,t,r){throw new ls(e,t,r===void 0?void 0:{cause:r})}function DK(e,t){return t===""?e:`${e}${t}`}function _K(e){return e instanceof he?e.pointer:""}var mO=p.strictObject({ast:Qi,page:p.strictObject({size:p.number().int().min(1).max(Number.MAX_SAFE_INTEGER),after:p.string().min(1).optional()})}),BO=p.strictObject({result:Va,page:p.strictObject({next:p.string().min(1).optional()})});var hO=p.strictObject({operation:co,origin:xt}),gO=p.strictObject({operation:co,transition:Km});var kK=p.discriminatedUnion("kind",[p.strictObject({origin:p.string().min(1),kind:p.literal("class"),name:p.string().min(1)}),p.strictObject({origin:p.string().min(1),kind:p.literal("interface"),name:p.string().min(1)})]),SK=p.strictObject({description:p.string().optional(),target:p.discriminatedUnion("kind",[p.strictObject({kind:p.literal("domain")}),p.strictObject({kind:p.literal("definition"),definitions:p.array(kK).min(1)})]),auth:p.enum(["required","optional","public"])}),yO=p.strictObject({target:p.string().min(1)}),CO=p.strictObject({snapshot:p.string().min(1),views:p.array(p.strictObject({key:p.string().min(1),declaration:SK,href:p.string().min(1),handshake:p.enum(["shell","none"]),issuer:p.string().min(1),etag:p.string().min(1),revision:p.string().min(1)}))});var bO=p.string().min(1),Zm=p.strictObject({id:bO,issuer:bO,subject:bO,frozen:p.boolean(),requiredClaims:cs});var EO=p.strictObject({}),vO=Zm;var tP=p.string().min(1),xO=p.strictObject({issuer:tP,subject:tP}),wO=Zm.nullable();function Xe(e){return rd(e)}var rP=Xe({description:"Admit one remote path-only attempt and return its request-scoped execution target.",auth:"authenticated",input:VI,output:qI,static:!0,inheritance:"sealed"});var nP=Xe({description:"Determine whether the current authenticated Identity satisfies one installed Policy for one object.",auth:"authenticated",input:JI,output:KI,static:!0,inheritance:"default"});var iP=Xe({description:"Issue one strictly attenuated credential from this authenticated Identity.",auth:"authenticated",input:ZI,output:WI,inheritance:"default"});var oP=Xe({description:"Durably install one or more exact Schema targets and return a terminal receipt.",auth:"authorized",input:YI,output:QI});var sP=Xe({description:"Return bounded installed-Publication evidence to an authenticated Kernel session.",auth:"authenticated",input:XI,output:nd.binary()});var aP=Xe({description:"Read one authorized page of semantic operations from the kernel journal.",auth:"authorized",input:eO,output:tO});var cP=Xe({description:"Resolve and sign one authorized Grant credential.",auth:"authorized",input:rO,output:nO,static:!0,inheritance:"default"});var uP=Xe({description:"Validate, authorize, and commit one atomic graph mutation.",auth:"authorized",input:iO,output:oO});var lP=Xe({description:"Atomically execute a graph transition whose designated Identities are born complete.",auth:"authorized",input:aO,output:cO});var dP=Xe({description:"Execute one finite authorized graph query.",auth:"authorized",input:mO,output:BO});var fP=Xe({description:"Durably uninstall one Domain installation epoch and return its terminal receipt.",auth:"authorized",input:hO,output:gO});var pP=Xe({description:"Resolve the installed View declarations applicable to one authorized graph target.",auth:"authorized",input:yO,output:CO,static:!0,inheritance:"sealed"});var mP=Xe({description:"Return the Identity authenticated for this invocation.",auth:"authenticated",input:EO,output:vO,static:!0,inheritance:"default"});var BP=Xe({description:"Resolve one issuer-and-subject Identity.",auth:"authorized",input:xO,output:wO,static:!0,inheritance:"default"});var hP=Object.freeze({query:dP,mutate:uP,provision:lP,install:oP,introspect:sP,uninstall:fP,journal:aP}),gP=Object.freeze({delegate:iP,can:nP,whoami:mP,whois:BP,mint:cP}),yP=Object.freeze({admit:rP}),CP=Object.freeze({resolve:pP});var sl=_n({description:"Ordinary projection-node contract for a standalone Function or Node Method declaration.",extends:[Zr],properties:{kind:{enum:["function","method"]},input:{},output:{type:"object"},auth:{enum:["anonymous","authenticated","authorized"]},policy:qe({type:"object"},{required:!1}),static:qe({type:"boolean"},{required:!1}),inheritance:qe({enum:["abstract","default","sealed"]},{required:!1})}});var fs=ir({description:"The installed projection of a standalone Function or Node Method declaration; it is not a principal.",implements:[sl],methods:yP});var IO=kt.directed({source:{as:"method",accepts:[fs],outgoing:"0..1"},target:{as:"owner",accepts:[bt,un],incoming:"0..*"},description:"A Function declaration belongs to one Class or Interface for dispatch.",implements:[Dt],properties:{name:qe({type:"string",minLength:1},{visibility:"private"}),static:qe({type:"boolean"},{visibility:"private"})}});var al=_n({description:"Ordinary projection-node contract for a declarative browser surface.",extends:[Zr],properties:{auth:{enum:["required","optional","public"]}}});var cl=ir({description:"The installed projection of a declarative browser surface; it is not a principal.",implements:[al],methods:CP});var uo=_n({description:"A principal that can be authenticated and can originate persistent authority facts.",properties:{frozen:qe({type:"boolean"},{required:!1,visibility:"private"}),iss:{type:"string",minLength:1},requiredClaims:qe(cs,{required:!1,visibility:"private"}),sub:{type:"string",minLength:1}},methods:gP});function qa(e,t){return kt.directed({source:{as:"subject",accepts:[uo],outgoing:"0..*"},target:{as:e,accepts:[uo],incoming:"0..*"},description:t,implements:[Dt],constraints:{noSelf:!0,acyclic:!0}})}var OO=qa("constraint","An Identity intersects its effective authority with another Identity.");var DO=qa("excluded","An Identity excludes another Identity from its effective authority.");var _O=qa("extension","An Identity unions its effective authority with another Identity.");var ps=ir({description:"A stable Domain principal and the active projection of one canonical DomainSchema revision.",implements:[uo],properties:{origin:{type:"string",pattern:"[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?(\\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)+"},dependencyContext:qe({type:"array",items:{type:"object"}},{visibility:"private",required:!1}),schema:qe({type:"object"},{visibility:"private"}),schemaRevision:qe({type:"string",pattern:"sha256:[0-9a-f]{64}"},{visibility:"private"})}});var kO=kt.directed({source:{as:"member",accepts:[as],outgoing:"0..1"},target:{as:"domain",accepts:[ps],incoming:"0..*"},description:"A schema declaration or Core node belongs to one Domain member namespace.",implements:[Dt],constraints:{noSelf:!0},properties:{member:qe({type:"string",minLength:3},{visibility:"private"})}});var SO=kt.directed({source:{as:"view",accepts:[cl],outgoing:"1..*"},target:{as:"target",accepts:[bt,ps,un],incoming:"0..*"},description:"A View declaration targets one Domain or a non-empty set of Classes and Interfaces.",implements:[Dt]});var Wm=dr(fs,"function","An Identity may invoke the exact target Function declaration.");var ul=ir({description:"The installed graph projection of one named closed Policy declaration owned by a Domain.",implements:[Zr]});var AO=kt.directed({source:{as:"class",accepts:[bt],outgoing:"0..*"},target:{as:"policy",accepts:[ul],incoming:"0..*"},description:"The protected projection of one Class read or traverse Policy assignment.",implements:[Dt],properties:{operations:qe({enum:[["read"],["traverse"],["read","traverse"]]},{visibility:"private"})},constraints:{noSelf:!0}});var ms=Object.freeze(["use","create","read","traverse","update","delete","grant","revoke"]),lo=Object.freeze({use:fn(fr,{name:"use"}),create:fn(fr,{name:"create"}),read:fn(fr,{name:"read"}),traverse:fn(fr,{name:"traverse"}),update:fn(fr,{name:"update"}),delete:fn(fr,{name:"delete"}),grant:fn(fr,{name:"grant"}),revoke:fn(fr,{name:"revoke"})});var Ym=Object.freeze({nodes:lo,edges:Object.freeze([])});var AK={interfaces:{Descriptable:Zr,Edge:Dt,Function:sl,Iconable:nl,Identity:uo,Named:il,Node:as,Remotable:LI,Statused:zI,Timestamped:MI,UI:al},classes:{Class:bt,Domain:ps,Function:fs,Interface:un,Operation:fr,Policy:ul,View:cl,can_create:Fm,can_read:Vm,can_traverse:qm,can_update:Jm,can_delete:Gm,can_grant:Hm,can_revoke:HI,can_use:Wm,constrained_by:OO,excluded_from:DO,extends:UI,extends_with:_O,governed_by:AO,implements:FI,instance_of:GI,method_of:IO,of_domain:kO,view_for:SO},policies:{},functions:hP},$K=Object.freeze({nodes:lo,edges:Ym.edges}),TK={...AK,core:$K},ll=$p("kernel.astrale.ai",TK),ge=Ha.fromSchema(ll),bP=Object.freeze({use:ge.can_use,create:ge.can_create,read:ge.can_read,traverse:ge.can_traverse,update:ge.can_update,delete:ge.can_delete,grant:ge.can_grant,revoke:ge.can_revoke}),EP=Object.freeze([ge.query,ge.mutate,ge.provision,ge.install,ge.introspect,ge.uninstall,ge.journal,ge.Identity.whois,ge.Identity.mint,ge.View.resolve].sort((e,t)=>e.key<t.key?-1:e.key>t.key?1:0));var et={};ze(et,{function:()=>Xm,identity:()=>Qm,install:()=>jO,introspect:()=>PO,journal:()=>zO,mutate:()=>NO,provision:()=>RO,query:()=>TO,uninstall:()=>LO,view:()=>eB});function fo(e){let t=Object.freeze({origin:e.origin,kind:"function",name:e.name});return Object.freeze({ref:t,declaration:e.definition,callable:e})}function Kn(e){if(e.owner.kind==="interface"){let r=Object.freeze({origin:e.owner.origin,kind:"interface",name:e.owner.name});return Object.freeze({ref:Object.freeze({owner:r,name:e.name}),declaration:e.definition,callable:e})}let t=Object.freeze({origin:e.owner.origin,kind:"class",name:e.owner.name});return Object.freeze({ref:Object.freeze({owner:t,name:e.name}),declaration:e.definition,callable:e})}var TO=fo(ge.query),NO=fo(ge.mutate),RO=fo(ge.provision),jO=fo(ge.install),PO=fo(ge.introspect),LO=fo(ge.uninstall),zO=fo(ge.journal);var Qm={};ze(Qm,{can:()=>RK,delegate:()=>NK,mint:()=>LK,whoami:()=>jK,whois:()=>PK});var NK=Kn(ge.Identity.delegate),RK=Kn(ge.Identity.can),jK=Kn(ge.Identity.whoami),PK=Kn(ge.Identity.whois),LK=Kn(ge.Identity.mint);var Xm={};ze(Xm,{admit:()=>MK});var zK=ge.$.class("Function").$.method("admit"),MK=Kn(zK);var eB={};ze(eB,{acceptResolution:()=>HK,resolve:()=>GK});function vP(e){let t=se(e);if(ge.$.validate.output(ge.View.resolve.key,t).status==="reject")Bs("View resolution violates its callable contract.");let i=t,n=i.views.map((o,s)=>{let a;try{a=Z(o.key)}catch(u){throw TypeError(`Resolved View ${s} key is invalid.`,{cause:u})}if(!Z.ref(a).startsWith("view."))Bs(`Resolved View ${s} is not a View.`);if(!ht.is(o.issuer))Bs(`Resolved View ${s} issuer is not canonical.`);let c=UK(o.declaration,s);return Object.freeze({key:a,declaration:c,href:o.href,handshake:o.handshake,issuer:o.issuer,etag:MO(o.etag,`Resolved View ${s} ETag`),revision:MO(o.revision,`Resolved View ${s} revision`)})});for(let o=1;o<n.length;o++)if(n[o-1].key>=n[o].key)Bs("Resolved Views are not in strict canonical key order.");return Object.freeze({snapshot:MO(i.snapshot,"Resolved View Registry snapshot"),views:Object.freeze(n)})}function UK(e,t){if(e.target.kind==="domain")return Object.freeze({...e.description===void 0?{}:{description:e.description},target:Object.freeze({kind:"domain"}),auth:e.auth});let r=e.target.definitions.map((i,n)=>{if(!Y.patterns.origin.test(i.origin)||i.kind!=="class"&&i.kind!=="interface"||!Y.patterns.memberName.test(i.name))Bs(`Resolved View ${t} target definition ${n} is invalid.`);return Object.freeze({origin:i.origin,kind:i.kind,name:i.name})});for(let i=1;i<r.length;i++)if(FK(r[i-1],r[i])>=0)Bs(`Resolved View ${t} target definitions are not in strict canonical order.`);return Object.freeze({...e.description===void 0?{}:{description:e.description},target:Object.freeze({kind:"definition",definitions:Object.freeze(r)}),auth:e.auth})}function FK(e,t){return UO(e.origin,t.origin)||UO(e.kind,t.kind)||UO(e.name,t.name)}function MO(e,t){if(!/^sha256:[0-9a-f]{64}$/u.test(e))Bs(`${t} is invalid.`);return e}function UO(e,t){return e<t?-1:e>t?1:0}function Bs(e){throw TypeError(e)}var GK=Kn(ge.View.resolve),HK=vP;var HIe=ar({});var YIe=Object.freeze({get:()=>{return}});var tB=Object.freeze(["create","read","traverse","update","delete"]);function po(e){let t=Le(e,"PUBLICATION_INVALID","Publication requirements are invalid.");Je(t,["capabilities"],"PUBLICATION_INVALID");let r=Le(t.capabilities,"PUBLICATION_INVALID","Publication capability requirements are invalid.");Je(r,["admin","classes","functions"],"PUBLICATION_INVALID");let i=r.functions===void 0?void 0:rB(r.functions,"Function capability requirements").map(KK);if(i!==void 0)bi(i,"PUBLICATION_INVALID","Function capability requirement"),nB(i,OP,"Function capability requirements");let n=r.classes===void 0?void 0:rB(r.classes,"Class capability requirements").map(ZK);if(n!==void 0)bi(n.map((s)=>FO(s.class)),"PUBLICATION_INVALID","Class capability requirement"),nB(n,(s,a)=>OP(FO(s.class),FO(a.class)),"Class capability requirements");let o=r.admin===void 0?void 0:WK(r.admin);return Gn({capabilities:{...i===void 0?{}:{functions:Object.freeze(i)},...n===void 0?{}:{classes:Object.freeze(n)},...o===void 0?{}:{admin:o}}})}function iB(e,t,r){let i=JK(e,t);for(let n of r.capabilities.functions??[]){DP(e,i,n,"Function");let o=i.get(Z.origin(n)),s=Z.ref(n);if(!QK(o,s))W("PUBLICATION_INVALID","Function capability requirement names an unknown dependency callable.")}for(let n of r.capabilities.classes??[]){let o=Z.fromSchema(n.class);if(DP(e,i,o,"Class"),i.get(n.class.origin).classes[n.class.name]===void 0)W("PUBLICATION_INVALID","Class capability requirement names an unknown dependency Class.")}}function JK(e,t){let r=new Map(t.map((o)=>[o.origin,o])),i=new Map,n=(o)=>{for(let s of o.dependencies){let a=r.get(s.origin);if(a===void 0||Y.revision(a)!==s.revision)W("PUBLICATION_INVALID","Publication Bundle omits an exact dependency.");if(i.has(a.origin))continue;i.set(a.origin,a),n(a)}};return n(e),i}function KK(e){if(typeof e!=="string"||!Z.is(e))return W("PUBLICATION_INVALID","Function capability reference is invalid.");let t=Z.ref(e);if(!t.startsWith("function.")&&!ne.isMethod(t))return W("PUBLICATION_INVALID","Function capability reference must name a Function or Method.");return e}function ZK(e){let t=Le(e,"PUBLICATION_INVALID","Class capability requirement is invalid.");Je(t,["class","operations"],"PUBLICATION_INVALID");let r=rB(t.operations,"Class capability operations").map((i)=>_P(i,tB,"Class capability operation"));return bi(r,"PUBLICATION_INVALID","Class capability operation"),nB(r,kP(tB),"Class capability operations"),Object.freeze({class:YK(t.class),operations:Object.freeze(r)})}function WK(e){let t=Le(e,"PUBLICATION_INVALID","Administrative capability requirements are invalid.");if(Je(t,["grant","revoke"],"PUBLICATION_INVALID"),t.grant===void 0&&t.revoke===void 0)W("PUBLICATION_INVALID","Administrative capability requirements cannot be empty.");let r=IP(t.grant,"grant"),i=IP(t.revoke,"revoke");return Object.freeze({...r===void 0?{}:{grant:r},...i===void 0?{}:{revoke:i}})}function IP(e,t){if(e===void 0)return;let r=rB(e,`Administrative ${t} operations`).map((i)=>_P(i,ms,`Administrative ${t} operation`));return bi(r,"PUBLICATION_INVALID",`administrative ${t} operation`),nB(r,kP(ms),`Administrative ${t} operations`),Object.freeze(r)}function YK(e){let t=Le(e,"PUBLICATION_INVALID","Class capability reference is invalid.");if(Je(t,["kind","name","origin"],"PUBLICATION_INVALID"),t.kind!=="class"||typeof t.origin!=="string"||!Y.patterns.origin.test(t.origin)||typeof t.name!=="string"||!Y.patterns.memberName.test(t.name))W("PUBLICATION_INVALID","Class capability reference is invalid.");return Object.freeze({origin:t.origin,kind:"class",name:t.name})}function rB(e,t){let r=[...Ga(e,"PUBLICATION_INVALID")];if(r.length===0)W("PUBLICATION_INVALID",`${t} cannot be empty.`);return r}function _P(e,t,r){if(typeof e!=="string"||!t.includes(e))return W("PUBLICATION_INVALID",`${r} is unknown.`);return e}function nB(e,t,r){if(e.some((i,n)=>n>0&&t(e[n-1],i)>=0))W("PUBLICATION_INVALID",`${r} must be sorted canonically.`)}function kP(e){return(t,r)=>e.indexOf(t)-e.indexOf(r)}function OP(e,t){return e<t?-1:e>t?1:0}function FO(e){return String(Z.fromSchema(e))}function DP(e,t,r,i){let n=Z.origin(r);if(n===e.origin)W("PUBLICATION_INVALID",`${i} capability target cannot be local.`);if(!t.has(n))W("PUBLICATION_INVALID",`${i} capability target must belong to the exact dependency closure.`)}function QK(e,t){if(t.startsWith("function."))return e.functions[ne.member(t)]!==void 0;let r=ne.namespace(t),i=ne.member(t),n=ne.child(t),o=r==="class"?e.classes[i]:e.interfaces[i];return o?.family==="node"&&o.methods[n]!==void 0}var XK=/^[A-Za-z][A-Za-z0-9_-]{0,63}$/u;function SP(e,t){let r=Le(e,"PUBLICATION_ROUTE_INVALID","Published HTTP route is invalid.");if(Je(r,["name","callable","href","method","requestMethod","default","receiver","query","headers","body","credential"],"PUBLICATION_ROUTE_INVALID"),typeof r.name!=="string"||!XK.test(r.name))W("PUBLICATION_ROUTE_INVALID","Route name is invalid.");let i=Nm(r.callable,t);if(!["GET","POST","PUT","PATCH","DELETE","*"].includes(r.method))W("PUBLICATION_ROUTE_INVALID","Route method is invalid.");if(r.default!==void 0&&r.default!==!0)W("PUBLICATION_ROUTE_INVALID","Route default may only be true.");if(r.requestMethod!==void 0&&(typeof r.requestMethod!=="string"||!Y.patterns.memberName.test(r.requestMethod)))W("PUBLICATION_ROUTE_INVALID","Route request-method mapping is invalid.");if(r.receiver!==void 0&&(typeof r.receiver!=="string"||!Y.patterns.memberName.test(r.receiver)))W("PUBLICATION_ROUTE_INVALID","Route receiver is invalid.");let n=n3(r.query),o=r3(r.headers),s=t3(r.body),a=e3(r.credential);return Gn({name:r.name,callable:i,href:xn(r.href,!1,"PUBLICATION_ROUTE_INVALID",!0),method:r.method,...r.requestMethod===void 0?{}:{requestMethod:r.requestMethod},...r.default===!0?{default:!0}:{},...r.receiver===void 0?{}:{receiver:r.receiver},...n===void 0?{}:{query:n},...o===void 0?{}:{headers:o},...s===void 0?{}:{body:s},...a===void 0?{}:{credential:a}})}function e3(e){if(e===void 0)return;let t=Array.isArray(e)?e:[e];if(t.length===0)W("PUBLICATION_ROUTE_INVALID","Credential source list is empty.");let r=t.map((i)=>{let n=Le(i,"PUBLICATION_ROUTE_INVALID","Credential source is invalid.");if(Je(n,["in","name"],"PUBLICATION_ROUTE_INVALID"),n.in==="header"){if(n.name!==void 0&&(typeof n.name!=="string"||n.name.length===0))W("PUBLICATION_ROUTE_INVALID","Credential header name is invalid.");return Object.freeze({in:"header",...n.name===void 0?{}:{name:n.name}})}if((n.in==="cookie"||n.in==="query")&&typeof n.name==="string"&&n.name.length>0)return Object.freeze({in:n.in,name:n.name});return W("PUBLICATION_ROUTE_INVALID","Credential source is invalid.")});return Array.isArray(e)?Object.freeze(r):r[0]}function t3(e){if(e===void 0||e==="*")return e;let t=Le(e,"PUBLICATION_ROUTE_INVALID","Route body mapping is invalid."),r={};for(let[i,n]of Object.entries(t))if(typeof n==="string"&&n.length>0)r[i]=n;else if(n!==null&&typeof n==="object"&&!Array.isArray(n)&&Object.keys(n).length===1&&n.as==="text")r[i]={as:"text"};else W("PUBLICATION_ROUTE_INVALID","Route body pick is invalid.");return Object.freeze(r)}function r3(e){if(e===void 0)return;let t=Le(e,"PUBLICATION_ROUTE_INVALID","Route header mapping is invalid."),r={};for(let[i,n]of Object.entries(t)){if(typeof n!=="string"||n.length===0)W("PUBLICATION_ROUTE_INVALID","Route header pick is invalid.");r[i]=n}return Object.freeze(r)}function n3(e){if(e===void 0)return;let t=Le(e,"PUBLICATION_ROUTE_INVALID","Route mapping is invalid."),r={};for(let[i,n]of Object.entries(t)){if(typeof n!=="string"||n.length===0)W("PUBLICATION_ROUTE_INVALID","Route wire name is invalid.");r[i]=n}return Object.freeze(r)}function AP(e){let t=Le(e,"PUBLICATION_INVALID","Published schema is invalid.");if(Je(t,["revision","bundle"],"PUBLICATION_INVALID"),typeof t.revision!=="string"||!Y.patterns.revision.test(t.revision))W("PUBLICATION_INVALID","Published schema revision is invalid.");return Object.freeze({revision:t.revision,bundle:Oj(t.bundle)})}var oB="/.well-known/astrale/domain.json",TP="application/vnd.astrale.domain-publication+json;v=2";function NP(e){let t=LP(e),r;try{r=new URL(t)}catch(i){return W("PUBLICATION_INVALID","Publication issuer is not an HTTP(S) URL.",i)}if(r.protocol!=="https:"&&r.protocol!=="http:"||r.username!==""||r.password!==""||r.search!==""||r.hash!=="")W("PUBLICATION_INVALID","Publication issuer is not an HTTP(S) URL.");return`${t.replace(/\/+$/u,"")}${oB}`}function RP(e){return jP({...e,etag:uI(e)},!1)}function hs(e){let t=jP(e,!0);if(t.etag!==uI(o3(t)))W("PUBLICATION_ETAG_MISMATCH","Publication ETag does not match its canonical content.");return t}function dl(e){return te.encode(e)}function fl(e,t){let r=_j(t);return dI(e,Mr.encode(r)),PP(e,r),r}function sB(e,t){let r=kj(e,t);return PP(e,r),r}function jP(e,t){let r=Le(e,"PUBLICATION_INVALID","Expected a Publication object.");if(Je(r,["format","version","origin","identity","etag","schema","requirements","manifest","bindings","routes","delivery"],"PUBLICATION_INVALID"),r.format!=="astrale.domain.publication"||r.version!==2)W("PUBLICATION_INVALID","Unsupported Publication format or version.");if(typeof r.origin!=="string"||!Y.patterns.origin.test(r.origin))W("PUBLICATION_INVALID","Publication origin is invalid.");let i=r.origin,n=Le(r.identity,"PUBLICATION_INVALID","Publication identity is invalid.");Je(n,["issuer","subject"],"PUBLICATION_INVALID");let o=LP(n.issuer);if(n.subject!==i)W("PUBLICATION_INVALID","Publication identity subject must equal its root origin.");let s=AP(r.schema),a=po(r.requirements),c=Aj(r.manifest),u=Le(r.bindings,"PUBLICATION_BINDING_INVALID","Publication bindings are invalid.");Je(u,["callables","views"],"PUBLICATION_BINDING_INVALID");let l=Ga(u.callables,"PUBLICATION_BINDING_INVALID").map((h)=>aI(h,i));bi(l.map(({callable:h})=>h),"PUBLICATION_BINDING_INVALID","callable binding");let d=Ga(u.views,"PUBLICATION_VIEW_INVALID").map((h)=>cI(h,i));bi(d.map(({view:h})=>h),"PUBLICATION_VIEW_INVALID","View binding");let f=Ga(r.routes,"PUBLICATION_ROUTE_INVALID").map((h)=>SP(h,i));bi(f.map(({name:h})=>h),"PUBLICATION_ROUTE_INVALID","route name");for(let h of new Set(f.map(({callable:g})=>g)))if(f.filter((g)=>g.callable===h&&g.default===!0).length>1)W("PUBLICATION_ROUTE_INVALID",`Callable ${h} has more than one default route.`);if(c?.entrypoint!==void 0){let h=Z.of(i,c.entrypoint);if(!d.some(({view:g})=>g===h))W("PUBLICATION_VIEW_INVALID","Manifest entrypoint must have a published View binding.")}let m=Sj(r.delivery,s.bundle.href),B=t?Rm(r.etag):r.etag;if(typeof B!=="string")W("PUBLICATION_INVALID","Publication ETag is missing.");return Gn({format:"astrale.domain.publication",version:2,origin:i,identity:{issuer:o,subject:i},etag:B,schema:s,requirements:a,...c===void 0?{}:{manifest:c},bindings:{callables:l,views:d},routes:f,...m===void 0?{}:{delivery:m}})}function PP(e,t){let r=t.root;if(r.origin!==e.origin||Y.revision(r)!==e.schema.revision)W("PUBLICATION_INVALID","Bundle root does not match the Publication schema.");iB(r,t.closure,e.requirements);let i=i3(r),n=new Set(e.bindings.callables.map(({callable:a})=>a));if(n.size!==i.size||[...i].some((a)=>!n.has(a)))W("PUBLICATION_BINDING_INVALID","Callable bindings must exhaust the root Domain.");let o=new Set(Object.keys(r.views).map((a)=>Z.of(r.origin,ne.definition("view",a)))),s=new Set(e.bindings.views.map(({view:a})=>a));if(s.size!==o.size||[...o].some((a)=>!s.has(a)))W("PUBLICATION_VIEW_INVALID","View bindings must exhaust the root Domain.");if(e.manifest?.entrypoint!==void 0&&r.views[ne.member(e.manifest.entrypoint)]===void 0)W("PUBLICATION_INVALID","Manifest entrypoint does not exist in the root schema.");for(let a of e.routes)if(!i.has(a.callable))W("PUBLICATION_ROUTE_INVALID",`Route ${a.name} names an unknown callable.`)}function i3(e){let t=new Set;for(let r of Object.keys(e.functions))t.add(Z.of(e.origin,ne.definition("function",r)));return $P(t,e.origin,"class",e.classes),$P(t,e.origin,"interface",e.interfaces),t}function $P(e,t,r,i){for(let[n,o]of Object.entries(i)){if(o.family!=="node")continue;for(let[s,a]of Object.entries(o.methods)){if(a.inheritance==="abstract")continue;e.add(Z.of(t,ne.method(ne.definition(r,n),s)))}}}function LP(e){try{return ht.accept(String(e))}catch(t){if(t instanceof be)return W("PUBLICATION_INVALID","Publication issuer is invalid.",t);throw t}}function o3(e){let{etag:t,...r}=e;return r}var GO={};ze(GO,{ATTESTATION_MAX_BYTES:()=>cB,Error:()=>aB,NONCE_MAX_LENGTH:()=>Ka,NONCE_MIN_LENGTH:()=>Ja,PURPOSE:()=>pl,accept:()=>GP,acceptClaims:()=>UP,acceptRequest:()=>VP});class aB extends Error{code;name="DeliveryError";constructor(e,t,r){super(t,r);this.code=e}}function Nt(e,t,r){throw new aB(e,t,r===void 0?void 0:{cause:r})}var pl="astrale.domain.delivery.v1",Ja=16,Ka=256,cB=16384;function zP(e){if(typeof e!=="string"||e.length===0||new TextEncoder().encode(e).byteLength>cB)Nt("DELIVERY_INVALID","Delivery attestation is invalid.");return e}function UP(e){if(e===null||typeof e!=="object"||Array.isArray(e))Nt("DELIVERY_CLAIMS_INVALID","Expected delivery claims.");let t=e,r=["purpose","iss","sub","aud","nonce","etag","schemaRevision","exp"];if(Object.keys(t).some((o)=>!r.includes(o)))Nt("DELIVERY_CLAIMS_INVALID","Delivery claims contain unknown fields.");if(t.purpose!==pl||typeof t.sub!=="string"||t.sub.length===0||typeof t.nonce!=="string"||t.nonce.length<Ja||t.nonce.length>Ka||typeof t.exp!=="number"||!Number.isSafeInteger(t.exp))Nt("DELIVERY_CLAIMS_INVALID","Delivery claims are invalid.");let i=MP(t.iss),n=MP(t.aud);if(typeof t.etag!=="string"||!/^sha256:[0-9a-f]{64}$/u.test(t.etag))Nt("DELIVERY_CLAIMS_INVALID","Delivery claims ETag is invalid.");if(typeof t.schemaRevision!=="string"||!Y.patterns.revision.test(t.schemaRevision))Nt("DELIVERY_CLAIMS_INVALID","Schema revision is invalid.");return FP({purpose:pl,iss:i,sub:t.sub,aud:n,nonce:t.nonce,etag:t.etag,schemaRevision:t.schemaRevision,exp:t.exp})}function MP(e){try{return ht.accept(String(e))}catch(t){if(t instanceof be)return Nt("DELIVERY_CLAIMS_INVALID","Delivery claims issuer is invalid.",t);throw t}}function FP(e){if(e===null||typeof e!=="object"||Object.isFrozen(e))return e;for(let t of Object.values(e))FP(t);return Object.freeze(e)}function GP(e){if(e===null||typeof e!=="object"||Array.isArray(e))Nt("DELIVERY_INVALID","Expected a Delivery object.");let t=e,r=new Set(["format","version","publication","attestation"]);if(Object.keys(t).some((i)=>!r.has(i)))Nt("DELIVERY_INVALID","Delivery contains unknown fields.");if(t.format!=="astrale.domain.delivery"||t.version!==1)Nt("DELIVERY_INVALID","Unsupported Delivery format or version.");return HP({format:"astrale.domain.delivery",version:1,publication:hs(t.publication),attestation:zP(t.attestation)})}function HP(e){if(e===null||typeof e!=="object"||Object.isFrozen(e))return e;for(let t of Object.values(e))HP(t);return Object.freeze(e)}function VP(e){if(e===null||typeof e!=="object"||Array.isArray(e))Nt("DELIVERY_REQUEST_INVALID","Expected a Delivery request.");let t=["version","kernel","nonce","etag"],r={},i=Reflect.ownKeys(e);if(i.length!==t.length)Nt("DELIVERY_REQUEST_INVALID","Delivery request is invalid.");for(let o of i){if(typeof o!=="string"||!t.includes(o))Nt("DELIVERY_REQUEST_INVALID","Delivery request is invalid.");let s=Object.getOwnPropertyDescriptor(e,o);if(s===void 0||!s.enumerable||!("value"in s))Nt("DELIVERY_REQUEST_INVALID","Delivery request is invalid.");r[o]=s.value}if(t.some((o)=>!Object.hasOwn(r,o))||r.version!==1||typeof r.kernel!=="string"||typeof r.nonce!=="string"||r.nonce.length<Ja||r.nonce.length>Ka||typeof r.etag!=="string"||!/^sha256:[0-9a-f]{64}$/u.test(r.etag))Nt("DELIVERY_REQUEST_INVALID","Delivery request is invalid.");let n;try{n=ht.accept(r.kernel)}catch(o){if(o instanceof be)return Nt("DELIVERY_REQUEST_INVALID","Delivery request issuer is invalid.",o);throw o}return Object.freeze({version:1,kernel:n,nonce:r.nonce,etag:r.etag})}function uB(e){return Gn({origin:e.origin,identity:{...e.identity},revision:e.schema.revision,etag:e.etag})}function Za(e){let t=Le(e,"PUBLICATION_INVALID","Publication reference is invalid.");if(Je(t,["origin","identity","revision","etag"],"PUBLICATION_INVALID"),typeof t.origin!=="string"||!Y.patterns.origin.test(t.origin))W("PUBLICATION_INVALID","Publication reference origin is invalid.");let r=t.origin,i=Le(t.identity,"PUBLICATION_INVALID","Publication reference identity is invalid.");Je(i,["issuer","subject"],"PUBLICATION_INVALID");let n=s3(i.issuer);if(i.subject!==r)W("PUBLICATION_INVALID","Publication reference subject must equal its root origin.");if(typeof t.revision!=="string"||!Y.patterns.revision.test(t.revision))W("PUBLICATION_INVALID","Publication reference revision is invalid.");return Gn({origin:r,identity:{issuer:n,subject:r},revision:t.revision,etag:Rm(t.etag)})}function HO(e,t){if(e.origin!==t.origin)return"origin-drift";if(e.identity.issuer!==t.identity.issuer||e.identity.subject!==t.identity.subject)return"identity-drift";if(e.revision!==t.revision)return"schema-drift";return e.etag===t.etag?"exact":"same-schema"}function VO(e,t){return HO(uB(e),t)}function qP(e,t){return VO(e,t)==="exact"}function s3(e){if(typeof e!=="string")W("PUBLICATION_INVALID","Publication reference issuer is invalid.");try{return ht.accept(e)}catch(t){if(t instanceof be)return W("PUBLICATION_INVALID","Publication reference issuer is invalid.",t);throw t}}var a3=new Set(["endpoint","via"]),c3=new Set(["kind","publication","issuer"]),u3=new Set(["route","credential","trace"]),l3=new Set(["kind","requestId","invocation","redirect"]);function lB(e){let t=yt(e,"route");He(t,a3,"route"),We(t,["endpoint","via"],"route");try{let r=yt(t.via,"route.via");if(He(r,c3,"route.via"),We(r,["kind","publication","issuer"],"route.via"),r.kind!=="via")ue('route.via.kind must be "via"');return Object.freeze({endpoint:ss(t.endpoint),via:Object.freeze({kind:"via",publication:Za(r.publication),issuer:Bm(r.issuer,"route.via.issuer")})})}catch(r){if(r instanceof so)return ue(`route is invalid: ${r.message}`);throw r}}function JP(e,t,r){return lB({endpoint:t.endpoint,via:{kind:"via",publication:{origin:e,identity:{issuer:t.issuer,subject:t.subject},revision:t.revision,etag:t.etag},issuer:r}})}function qO(e){let t=yt(e,"redirection");He(t,u3,"redirection"),We(t,["route"],"redirection");let r=lB(t.route),i=t.credential===void 0?void 0:ro(t.credential,"redirection.credential"),n=t.trace===void 0?void 0:Ci(t.trace);if(i!==void 0&&i.length===0)ue("redirection.credential must be non-empty");return Object.freeze({route:r,...i===void 0?{}:{credential:i},...n===void 0?{}:{trace:n}})}function dB(e){let t=yt(e,"redirect response");if(He(t,l3,"redirect response"),We(t,["kind","requestId","invocation","redirect"],"redirect response"),t.kind!=="redirect")ue('redirect response.kind must be "redirect"');return Object.freeze({kind:"redirect",requestId:Tt(t.requestId,"redirect response.requestId"),invocation:Hr(t.invocation,"redirect response.invocation"),redirect:qO(t.redirect)})}var d3=new Set(["kind","publication","issuer"]),f3=new Set(["kind","stale"]);function fB(e){let t=yt(e,"routing");if(t.kind==="via"){He(t,d3,"via routing"),We(t,["kind","publication","issuer"],"via routing");try{return Object.freeze({kind:"via",publication:Za(t.publication),issuer:Bm(t.issuer,"via routing.issuer")})}catch(r){if(r instanceof so)return ue(`via routing.publication is invalid: ${r.message}`);throw r}}if(t.kind==="refresh")return He(t,f3,"refresh routing"),We(t,["kind","stale"],"refresh routing"),Object.freeze({kind:"refresh",stale:Pa(t.stale,"refresh routing.stale")});return ue('routing.kind must be "via" or "refresh"')}var p3=new Set(["target","revision"]);function pB(e){let t=yt(e,"schema target");He(t,p3,"schema target");let r=Object.hasOwn(t,"target"),i=Object.hasOwn(t,"revision");if(r===i)ue("schema target must contain exactly one of target or revision");if(r)return Object.freeze({target:Pa(t.target,"schema target.target")});if(typeof t.revision!=="string"||!Y.patterns.revision.test(t.revision))ue("schema target.revision must be a Schema revision");return Object.freeze({revision:t.revision})}var m3=new Set(["target","input"]);function mB(e){let t=yt(e,"call");return He(t,m3,"call"),We(t,["target","input"],"call"),Object.freeze({target:vR(t.target,"call.target"),input:t.input})}var B3=new Set(["version","requestId","call","credential","delegate","routing","schema","idempotencyKey","trace"]);function KP(e){let t=yt(e,"request");if(He(t,B3,"request"),We(t,["version","requestId","call"],"request"),t.version!==2)ue("request.version must be 2");let r=t.credential===void 0?void 0:ro(t.credential,"request.credential"),i=t.delegate===void 0?void 0:Tm(t.delegate),n=t.routing===void 0?void 0:fB(t.routing),o=t.schema===void 0?void 0:pB(t.schema),s=t.trace===void 0?void 0:Ci(t.trace);if(n?.kind==="via"){if(i!==void 0)ue("destination requests with via routing forbid delegate");if(o!==void 0)ue("destination requests with via routing forbid schema target")}else if(r===void 0!==(i===void 0))ue("source requests require credential and delegate together");return Object.freeze({version:2,requestId:Tt(t.requestId,"request.requestId"),call:mB(t.call),...r===void 0?{}:{credential:r},...i===void 0?{}:{delegate:i},...n===void 0?{}:{routing:n},...o===void 0?{}:{schema:o},...t.idempotencyKey===void 0?{}:{idempotencyKey:ym(t.idempotencyKey,"request.idempotencyKey")},...s===void 0?{}:{trace:s}})}var h3=new Set(["kind","requestId","invocation","current"]);function ml(e){let t=yt(e,"stale control");if(He(t,h3,"stale control"),We(t,["kind","requestId","invocation","current"],"stale control"),t.kind!=="stale")ue('stale control.kind must be "stale"');return Object.freeze({kind:"stale",requestId:Tt(t.requestId,"stale control.requestId"),invocation:Hr(t.invocation,"stale control.invocation"),current:Pa(t.current,"stale control.current")})}function ZP(e,t,r){return ml({kind:"stale",requestId:e,invocation:t,current:r})}var g3=new Set(["result","requestId","invocation"]),y3=new Set(["error","requestId","invocation"]);function WP(e){let t=yt(e,"response"),r=Object.hasOwn(t,"result"),i=Object.hasOwn(t,"error");if(r||i){if(r===i)ue("response must contain exactly one of result or error");if(r)return He(t,g3,"response"),We(t,["requestId","invocation"],"response"),Object.freeze({result:t.result,requestId:Tt(t.requestId,"response.requestId"),invocation:Hr(t.invocation,"response.invocation")});return He(t,y3,"response"),We(t,["requestId","error","invocation"],"response"),Object.freeze({error:hm(t.error,"response.error"),requestId:Tt(t.requestId,"response.requestId"),invocation:Hr(t.invocation,"response.invocation")})}if(t.kind==="redirect")return dB(t);if(t.kind==="stale")return ml(t);if(t.kind==="miss")return el(t);return ue("response must contain a result, error, redirect, stale, or miss control")}var KO="SCHEMA_UPGRADE_REQUIRED",ZO="SERVICE_TRUST_REQUIRED",WO="SERVICE_UNAVAILABLE",YO="SERVICE_CANDIDATE_INVALID";function QP(e){let t=mm(e.data);if(t===void 0)return;switch(t.code){case KO:return e.code===Ae.CONFLICT&&C3(t.details)?e:void 0;case ZO:return e.code===Ae.CONFLICT&&b3(t.details)?e:void 0;case WO:return e.code===Ae.BACKEND_UNAVAILABLE&&E3(t.details)?e:void 0;case YO:return e.code===Ae.BACKEND_UNAVAILABLE&&v3(t.details)?e:void 0;default:return}}function C3(e){return BB(e,["origin","installedRevision","candidateRevision"])&&hB(e.origin)&&JO(e.installedRevision)&&JO(e.candidateRevision)}function b3(e){return BB(e,["origin","installedIssuer","candidateIssuer"])&&hB(e.origin)&&YP(e.installedIssuer)&&YP(e.candidateIssuer)}function E3(e){return BB(e,["origin","revision"])&&hB(e.origin)&&JO(e.revision)}function v3(e){return BB(e,["origin"])&&hB(e.origin)}function BB(e,t){return Object.keys(e).length===t.length&&t.every((r)=>Object.hasOwn(e,r))}function hB(e){return typeof e==="string"&&Y.patterns.origin.test(e)}function JO(e){return typeof e==="string"&&Y.patterns.revision.test(e)}function YP(e){if(typeof e!=="string")return!1;try{return ht.accept(e)===e}catch(t){if(t instanceof be)return!1;throw t}}function XP(e){let t=yt(e,"stream frame"),r=t.kind;if(typeof r!=="string")ue("stream frame.kind must be a string");switch(r){case"stream.start":return He(t,new Set(["kind","requestId","invocation"]),"stream.start"),We(t,["requestId","invocation"],"stream.start"),Object.freeze({kind:r,requestId:Tt(t.requestId,"stream.start.requestId"),invocation:Hr(t.invocation,"stream.start.invocation")});case"stream.item":return He(t,new Set(["kind","requestId","index","value"]),"stream.item"),We(t,["requestId","index","value"],"stream.item"),Object.freeze({kind:r,requestId:Tt(t.requestId,"stream.item.requestId"),index:Tw(t.index,"stream.item.index"),value:t.value});case"stream.end":return He(t,new Set(["kind","requestId","count"]),"stream.end"),We(t,["requestId","count"],"stream.end"),Object.freeze({kind:r,requestId:Tt(t.requestId,"stream.end.requestId"),count:Tw(t.count,"stream.end.count")});case"stream.error":return He(t,new Set(["kind","requestId","error"]),"stream.error"),We(t,["requestId","error"],"stream.error"),Object.freeze({kind:r,requestId:Tt(t.requestId,"stream.error.requestId"),error:hm(t.error,"stream.error.error")});default:return ue(`unsupported stream frame kind ${JSON.stringify(r)}`)}}var eL=2;var tD={};ze(tD,{JSON_SUBPROTOCOL:()=>QO,MSGPACK_SUBPROTOCOL:()=>XO,decodeBinary:()=>nL,encodeBinary:()=>rL,selectSubprotocol:()=>iL,subprotocolFor:()=>eD});var Zn=new Uint8Array([65,83,84,66,1]),hl=4,tL=65536,x3=new TextEncoder,w3=new TextDecoder("utf-8",{fatal:!0});function rL(e){let t=e.headers===void 0?void 0:Object.fromEntries(Object.entries(e.headers).sort(([n],[o])=>n<o?-1:n>o?1:0)),r=x3.encode(JSON.stringify({kind:e.kind,requestId:e.requestId,invocation:e.invocation,mediaType:e.mediaType,...t===void 0?{}:{headers:t}}));if(r.byteLength>tL)Bl();let i=new Uint8Array(Zn.byteLength+hl+r.byteLength+e.body.byteLength);return i.set(Zn,0),new DataView(i.buffer).setUint32(Zn.byteLength,r.byteLength),i.set(r,Zn.byteLength+hl),i.set(e.body,Zn.byteLength+hl+r.byteLength),i}function nL(e){if(!I3(e))return;let t=Zn.byteLength+hl;if(e.byteLength<t)Bl();let r=new DataView(e.buffer,e.byteOffset+Zn.byteLength,hl).getUint32(0),i=t+r;if(r===0||r>tL||i>e.byteLength)Bl();let n;try{n=JSON.parse(w3.decode(e.subarray(t,i)))}catch(o){if(o instanceof SyntaxError||o instanceof TypeError)return Bl();throw o}if(typeof n!=="object"||n===null||Array.isArray(n))Bl();return gm({...n,body:e.slice(i)})}function I3(e){if(e.byteLength<Zn.byteLength)return!1;for(let t=0;t<Zn.byteLength;t+=1)if(e[t]!==Zn[t])return!1;return!0}function Bl(){throw new Fn({code:Ae.INVALID_REQUEST,message:"WebSocket binary response is invalid."})}var QO="astrale.invocation.v2.json",XO="astrale.invocation.v2.msgpack",O3=/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/u;function eD(e){let t=rI(e);if(t===void 0)throw TypeError("codec is not a canonical Invocation codec.");return t==="json"?QO:XO}function iL(e,t){let r=Xu(t);if(e===null||e.trim()==="")return;let i=e.split(",").map((o)=>o.trim()),n=new Set;for(let o of i){if(!O3.test(o)||n.has(o))return;n.add(o)}for(let o of i){let s=r.find((a)=>eD(a.codec)===o);if(s!==void 0)return Object.freeze({subprotocol:o,codec:s.codec})}return}var gl={};ze(gl,{installation:()=>iD});var iD={};ze(iD,{introspection:()=>nD});var nD={};ze(nD,{MEDIA_TYPE:()=>sL,decode:()=>cL,encode:()=>aL});var gB="application/vnd.astrale.domain-runtime+json;v=2";var sL="application/vnd.astrale.schema-introspection.v1+msgpack";async function aL(e,t){let r=uL(e),i=t===null?null:_3(r,t),{pack:n}=await Promise.resolve().then(() => (tI(),eI));return new Uint8Array(n(i))}async function cL(e,t,r){if(!(t instanceof Uint8Array))_t("Schema introspection evidence must be binary.");if(oL(r.maximumPublicationBytes,"Publication"),oL(r.maximumBundleBytes,"Bundle"),t.byteLength>r.maximumPublicationBytes+r.maximumBundleBytes+2048)_t("Schema introspection evidence exceeds its declared bounds.");let{unpack:i}=await Promise.resolve().then(() => (Ma(),Yw)),n;try{n=i(t)}catch(s){throw TypeError("Schema introspection evidence is malformed.",{cause:s})}if(n===null)return null;if(!rD(n))_t("Schema introspection result must be an object or null.");let o=uL(e);return Ya(n,o,"Schema introspection result"),k3(o,n,r)}function _3(e,t){Ya(t,e,"Schema introspection result");let r=e.includes("source")?S3(t.source):void 0,i={};for(let n of e)switch(n){case"state":i.state=dL(t.state);break;case"target":i.target=yB(t.target,"Installation target");break;case"source":i.source=r;break;case"bundle":i.bundle=$3(t.bundle,t.source);break;case"readiness":i.readiness=t.readiness===null?null:yB(t.readiness,"Installation readiness");break;case"capabilities":i.capabilities=lL(t.capabilities);break}return Object.freeze(i)}function k3(e,t,r){let i=e.includes("source")?A3(t.source,r):void 0,n={};for(let o of e)switch(o){case"state":n.state=dL(t.state);break;case"target":n.target=yB(t.target,"Installation target");break;case"source":n.source=i;break;case"bundle":n.bundle=T3(t.bundle,i,r.maximumBundleBytes);break;case"readiness":n.readiness=t.readiness===null?null:yB(t.readiness,"Installation readiness");break;case"capabilities":n.capabilities=lL(t.capabilities);break}if(n.state==="ready"&&Object.hasOwn(n,"readiness")&&n.readiness===null)_t("A ready Installation requires readiness evidence.");return Object.freeze(n)}function S3(e){if(e?.kind==="builtin")return Object.freeze({kind:"builtin",bundle:Wa(e.bundle,Kr,"Builtin schema Bundle")});if(e?.kind==="local")return Object.freeze({kind:"local",artifact:Wa(e.artifact,gB,"Local Runtime Artifact"),bundle:Wa(e.bundle,Kr,"Local schema Bundle")});if(e?.kind==="remote")return Object.freeze({kind:"remote",publication:dl(hs(e.publication))});return _t("Installation source is invalid.")}function A3(e,t){if(!rD(e))_t("Installation source is invalid.");if(e.kind==="builtin")return Ya(e,["bundle","kind"],"Builtin installation source"),Object.freeze({kind:"builtin",bundle:Wa(e.bundle,Kr,"Builtin schema Bundle")});if(e.kind==="local")return Ya(e,["artifact","bundle","kind"],"Local installation source"),Object.freeze({kind:"local",artifact:Wa(e.artifact,gB,"Local Runtime Artifact"),bundle:Wa(e.bundle,Kr,"Local schema Bundle")});if(e.kind==="remote"){Ya(e,["kind","publication"],"Remote installation source");let r=pL(e.publication,t.maximumPublicationBytes,"Publication"),i;try{i=hs(La.decode(r))}catch(n){throw TypeError("Remote installed Publication is invalid.",{cause:n})}if(!mL(r,dl(i)))_t("Remote installed Publication is not canonical.");return Object.freeze({kind:"remote",publication:i})}return _t("Installation source kind is invalid.")}function $3(e,t){if(t===void 0||e===void 0)_t("Bundle source evidence is missing.");let r=t.kind==="remote"?fl(t.publication,e):Mr.accept(e),i=Mr.encode(r);if(t.kind!=="remote"&&!fL(Ds(i,Kr),t.bundle))_t("Local schema Bundle does not match its source Ref.");return i}function T3(e,t,r){let i=pL(e,r,"Bundle"),n;try{n=t.kind==="remote"?sB(t.publication,i):Mr.decode(i)}catch(o){throw TypeError("Installed schema Bundle is invalid.",{cause:o})}if(!mL(i,Mr.encode(n)))_t("Installed schema Bundle is not canonical.");if(t.kind!=="remote"&&!fL(Ds(i,Kr),t.bundle))_t("Local schema Bundle does not match its source Ref.");return n}function uL(e){if(e===null||typeof e!=="object"||e.from?.kind!=="installation"||e.select===null||typeof e.select!=="object")_t("Schema introspection request is invalid.");let t=["state","target","source","bundle","readiness","capabilities"],r=Object.keys(e.select);if(r.length===0||r.some((i)=>!t.includes(i)||e.select[i]!==!0)||e.select.bundle===!0&&e.select.source!==!0)_t("Schema introspection selection is invalid.");return Object.freeze(t.filter((i)=>e.select[i]===!0))}function lL(e){if(!rD(e))_t("Installation capabilities are invalid.");Ya(e,["materialized","requested"],"Installation capabilities");try{let t=po({capabilities:e.requested}).capabilities,r=po({capabilities:e.materialized}).capabilities;return Object.freeze({requested:t,materialized:r})}catch(t){throw TypeError("Installation capabilities are invalid.",{cause:t})}}function dL(e){if(e!=="installed"&&e!=="ready"&&e!=="removing")_t("Installation state is invalid.");return e}function yB(e,t){if(typeof e!=="string"||!/^sha256:[0-9a-f]{64}$/u.test(e))_t(`${t} digest is invalid.`);return e}function Wa(e,t,r){let i;try{i=Os(e)}catch(n){throw TypeError(`${r} Ref is invalid.`,{cause:n})}if(i.mediaType!==t)_t(`${r} media type is invalid.`);return i}function fL(e,t){return e.digest===t.digest&&e.mediaType===t.mediaType&&e.size===t.size}function pL(e,t,r){if(!(e instanceof Uint8Array)||e.byteLength===0||e.byteLength>t)_t(`${r} evidence is invalid or exceeds its bound.`);return Uint8Array.from(e)}function oL(e,t){if(!Number.isSafeInteger(e)||e<1)_t(`${t} evidence bound is invalid.`)}function Ya(e,t,r){let i=Object.keys(e).sort(),n=[...t].sort();if(i.length!==n.length||i.some((o,s)=>o!==n[s]))_t(`${r} fields are invalid.`)}function mL(e,t){return e.byteLength===t.byteLength&&e.every((r,i)=>r===t[i])}function rD(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}function _t(e){throw TypeError(e)}class zt extends X{code;invocation;data;reason;constructor(e,t,r,i){super(t);this.code=e,this.invocation=r,this.data=i,this.name="ResponseError",this.reason=Ra.reasonOf(i)}}class Qa extends X{currentEtag;invocation;name="StaleRouteError";constructor(e,t){super("The destination Publication route is stale.");this.currentEtag=e,this.invocation=t}}class De extends X{phase;delivery;invocation;constructor(e,t){super(e,t);this.name="TransportError",this.phase=t.phase,this.delivery=t.delivery,this.invocation=t.invocation}}function Cl(e,t){let r=new AbortController,i=!1,n=()=>r.abort(e?.reason);if(e?.aborted)n();else e?.addEventListener("abort",n,{once:!0});let o=setTimeout(()=>{i=!0,r.abort(Error("request timeout"))},t);return{signal:r.signal,get timedOut(){return i},cancel:(s)=>r.abort(s),close:()=>{clearTimeout(o),e?.removeEventListener("abort",n)}}}function Gt(e,t){if(!Number.isSafeInteger(e)||e<1||e>2147483647)throw TypeError(`${t} must be a positive safe platform integer.`);return e}function br(e){if(!e.signal.aborted)return;throw e.signal.reason??Error("request was cancelled.")}function at(e){return e instanceof Error?e:Error(String(e))}async function vL(e){let r=sD(e)===Lt.CONTENT_TYPE_MSGPACK?[Lt.json,await Lt.loadMsgpack()]:[Lt.json];return me.http.codecForContentType(e,r)}async function oD(e,t,r){let i=e.headers.get("content-length");if(i!==null&&Number(i)>t)throw new pe(`response exceeds maximumResponseBytes (${t}).`);if(e.body===null)return new Uint8Array;let n=e.body.getReader(),o=[],s=0;try{while(!0){if(r.aborted)throw r.reason;let u=await n.read();if(u.done)break;if(s+=u.value.byteLength,s>t)throw new pe(`response exceeds maximumResponseBytes (${t}).`);o.push(u.value)}}catch(u){throw await n.cancel(u).catch(()=>{return}),u}let a=new Uint8Array(s),c=0;for(let u of o)a.set(u,c),c+=u.byteLength;return a}function CB(e,t){if(t!==e)throw new pe(`response id ${JSON.stringify(t)} does not match request id ${JSON.stringify(e)}.`)}function In(e,t){try{return t()}catch(r){if(r instanceof zt||r instanceof pe)throw r;throw new pe(`server returned an invalid ${e}.`,{cause:at(r)})}}function sD(e){if(e===null)return;let t=e.split(";",1)[0]?.trim().toLowerCase();return t===""?void 0:t}function xL(e,t){let r={};for(let i of t){let n=e.get(i);if(n===null)throw new pe(`server omitted declared binary application header ${i}.`);r[i]=n}return Object.freeze(r)}class bB{frames;codec;requestId;control;invocation;claimed=!1;terminal=!1;index=0;interruption;constructor(e,t,r,i){this.frames=e,this.codec=t,this.requestId=r,this.control=i;let n=()=>void this.interrupt(this.abortFailure(i.signal.reason));if(i.signal.aborted)n();else i.signal.addEventListener("abort",n,{once:!0})}static async open(e,t,r,i,n){if(e.body===null)throw new pe("stream has no body.");let o=new bB(new wL(e.body.getReader(),i),t,r,n),s=await o.readFrame();if(s===null||s.kind!=="stream.start")throw await o.stop("invalid stream start"),new pe("stream did not begin with stream.start.");return o.invocation=s.invocation,o}[Symbol.asyncIterator](){if(this.claimed)throw TypeError("streams admit exactly one consumer.");return this.claimed=!0,{next:()=>this.next(),return:async()=>(await this.cancel("stream consumer stopped"),{done:!0,value:void 0}),throw:async(e)=>{throw await this.cancel("stream consumer failed"),e}}}async cancel(e="stream cancelled"){await this.stop(e)}async next(){if(this.interruption!==void 0)throw this.interruption;if(this.terminal)return{done:!0,value:void 0};try{let e=await this.readFrame();if(e===null)throw new pe("stream ended without a terminal frame.");if(e.kind==="stream.item"){if(e.index!==this.index)throw new pe(`stream item ${e.index} does not match expected index ${this.index}.`);return this.index+=1,{done:!1,value:e.value}}if(e.kind==="stream.error")throw await this.finish(),new zt(e.error.code,e.error.message,this.invocation,e.error.data);if(e.kind!=="stream.end")throw new pe(`Unexpected ${e.kind} frame inside stream.`);if(e.count!==this.index)throw new pe(`stream ended with count ${e.count}; ${this.index} items were received.`);return await this.finish(),{done:!0,value:void 0}}catch(e){let t=this.interruption??J3(e,this.invocation);throw await this.stop(t),t}}async readFrame(){let e=await this.frames.read();if(this.interruption!==void 0)throw this.interruption;if(e===null)return null;let t=In("stream frame",()=>me.decodeStreamFrame(this.codec.decode(e)));return CB(this.requestId,t.requestId),t}async finish(){if(this.terminal)return;await this.frames.requireEnd(),this.terminal=!0,this.control.close()}async interrupt(e){if(this.terminal||this.interruption!==void 0)return;this.interruption=e,await this.frames.cancel(e),this.control.close()}async stop(e){if(this.terminal)return;this.terminal=!0,this.control.cancel(e),await this.frames.cancel(e),this.control.close()}abortFailure(e){if(this.control.timedOut)return new De("stream exceeded its invocation timeout.",{cause:at(e),phase:"timeout",delivery:"unknown",invocation:this.invocation});return at(e??Error("stream was cancelled."))}}function J3(e,t){if(e instanceof pe&&e.invocation===void 0)return new pe(e.message,{cause:e,invocation:t});if(e instanceof De&&e.invocation===void 0)return new De(e.message,{cause:e,phase:e.phase,delivery:e.delivery,invocation:t});return e}class wL{reader;maximumFrameBytes;chunk=new Uint8Array;offset=0;done=!1;constructor(e,t){this.reader=e,this.maximumFrameBytes=t}async read(){let e=await this.take(4,!0);if(e===null)return null;let t=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(0);if(t>this.maximumFrameBytes)throw new pe(`stream frame exceeds maximumResponseBytes (${this.maximumFrameBytes}).`);return await this.take(t,!1)}async requireEnd(){if(await this.take(1,!0)!==null)throw new pe("stream contains data after its terminal frame.")}async cancel(e){try{await this.reader.cancel(e)}catch{}}async take(e,t){let r=new Uint8Array(e),i=0;while(i<e){if(this.offset===this.chunk.byteLength){if(this.done){if(t&&i===0)return null;throw new pe("stream ended in the middle of a frame.")}let s=await this.reader.read();if(s.done){this.done=!0;continue}if(this.chunk=s.value,this.offset=0,this.chunk.byteLength===0)continue}let n=this.chunk.byteLength-this.offset,o=Math.min(n,e-i);r.set(this.chunk.subarray(this.offset,this.offset+o),i),i+=o,this.offset+=o}return r}}var K3=30000,Z3=16777216,W3=16777216;class xi{url;codecName;fetchImpl;headers;timeoutMs;maximumRequestBytes;maximumResponseBytes;nextId=1;constructor(e){if(e===null||typeof e!=="object")throw TypeError("HttpTransport options must be an object.");this.url=Q3(e.url),this.codecName=i8(e.codec),this.fetchImpl=o8(e.fetch),this.headers=X3(e.headers??{}),this.timeoutMs=Gt(e.timeoutMs??K3,"timeoutMs"),this.maximumRequestBytes=Gt(e.maximumRequestBytes??Z3,"maximumRequestBytes"),this.maximumResponseBytes=Gt(e.maximumResponseBytes??W3,"maximumResponseBytes")}async dispatch(e,t={}){let r=this.nextRequestId(),i=Gt(t.timeoutMs??this.timeoutMs,"timeoutMs"),n=await this.requestCodec(),{trace:o,...s}=e,a=o===void 0?void 0:me.admitTrace(o),c=me.decodeRequest({version:me.VERSION,requestId:r,...s,...t.idempotencyKey===void 0?{}:{idempotencyKey:t.idempotencyKey}}),u=n.encode(c),l=Cl(t.signal,i),d=!1,f="connect",m="not-sent";try{if(br(l),t8(u)>this.maximumRequestBytes)throw new De(`request exceeds maximumRequestBytes (${this.maximumRequestBytes}).`,{phase:"send",delivery:"not-sent"});f="send",m="unknown";let B=await this.fetchResponse(n,u,a,l);if(f="receive",br(l),B.status>=300&&B.status<400)throw new pe("server returned a network redirect.");r8(B);let h=B.headers.get(me.http.STREAM_FRAMING_FIELD),g=B.headers.get(me.http.REQUEST_ID_FIELD),w=B.headers.get(me.http.BINARY_HEADERS_FIELD),b=h!==null,O=g!==null||w!==null;if(b&&O)throw new pe("server returned conflicting stream and binary response signals.");if(O){if(g===null||w===null)throw new pe("server returned an incomplete binary response signal.");return await this.decodeBinary(B,r,g,l)}let k=await vL(B.headers.get("content-type"));if(k===void 0)throw new pe(`server returned unsupported Content-Type ${JSON.stringify(B.headers.get("content-type"))}.`);if(b){if(h!==me.http.LENGTH_PREFIX_V1)throw new pe(`server returned unsupported stream framing ${JSON.stringify(h)}.`);if(!B.ok)throw new pe("server returned a non-success stream response.");let _e=await bB.open(B,k,r,this.maximumResponseBytes,l);return br(l),d=!0,{kind:"stream",stream:_e,invocation:_e.invocation}}let G=await oD(B,this.maximumResponseBytes,l.signal);br(l);let oe=In("response body",()=>k.decode(G)),V=In("response envelope",()=>me.decodeResponse(oe));if(V.requestId===null&&"error"in V)throw new zt(V.error.code,V.error.message,V.invocation,V.error.data);if(CB(r,V.requestId),"kind"in V&&V.kind==="stale"){let _e=In("stale response",()=>me.decodeStale(V));return br(l),Object.freeze({kind:"stale",current:_e.current,invocation:_e.invocation})}if("kind"in V&&V.kind==="miss")return In("miss response",()=>me.decodeMiss(V)),br(l),Object.freeze({kind:"miss",invocation:V.invocation});if("kind"in V&&V.kind==="redirect"){let _e=In("redirect response",()=>me.decodeRedirectResponse(V));return br(l),Y3(_e)}if("error"in V)throw new zt(V.error.code,V.error.message,V.invocation,V.error.data);return br(l),{kind:"value",value:V.result,invocation:V.invocation}}catch(B){throw n8(B,l,t.signal,i,this.url,f,m)}finally{if(!d)l.close()}}async fetchResponse(e,t,r,i){return this.fetchImpl(this.url,{method:"POST",redirect:"error",credentials:"omit",cache:"no-store",referrerPolicy:"no-referrer",headers:{...this.headers,...me.http.encodeTraceHeaders(r),"content-type":e.contentType,accept:e.contentType},body:e8(t),signal:i.signal})}async decodeBinary(e,t,r,i){if(!e.ok)throw new pe("server returned binary data with an error status.");if(r!==String(t))throw new pe(`binary response requestId ${JSON.stringify(r)} does not match request requestId ${t}.`);let n=sD(e.headers.get("content-type"));if(n===void 0)throw new pe("binary response has no media type.");let o=await oD(e,this.maximumResponseBytes,i.signal);br(i);let s=In("binary application-header manifest",()=>me.http.decodeBinaryHeaderNames(e.headers.get(me.http.BINARY_HEADERS_FIELD))),a=xL(e.headers,s),c=In("binary InvocationId field",()=>me.http.decodeInvocationId(e.headers.get(me.http.INVOCATION_FIELD))),u=In("binary response",()=>me.decodeBinaryResponse({kind:"binary",requestId:t,invocation:c,body:o,mediaType:n,...Object.keys(a).length===0?{}:{headers:a}}));return br(i),{kind:"binary",invocation:u.invocation,value:{body:u.body,mediaType:u.mediaType,...u.headers===void 0?{}:{headers:u.headers}}}}nextRequestId(){let e=this.nextId;return this.nextId=e===Number.MAX_SAFE_INTEGER?1:e+1,e}requestCodec(){return this.codecName==="msgpack"?Lt.loadMsgpack():Promise.resolve(Lt.json)}}function Y3(e){return Object.freeze({kind:"redirect",invocation:e.invocation,redirect:e.redirect})}function Q3(e){if(typeof e!=="string")throw TypeError("server URL must be a string.");let t;try{t=new URL(e)}catch(r){throw TypeError(`Invalid server URL ${JSON.stringify(e)}.`,{cause:at(r)})}if(t.protocol!=="http:"&&t.protocol!=="https:")throw TypeError("server URL must use http or https.");if(t.username!==""||t.password!==""||t.hash!=="")throw TypeError("server URL cannot contain credentials or a fragment.");return t.toString()}function X3(e){if(e===null||typeof e!=="object"||Array.isArray(e))throw TypeError("HTTP headers must be an object.");let t={};for(let[r,i]of Object.entries(e)){if(!s8.test(r))throw TypeError(`HTTP header name ${JSON.stringify(r)} is invalid.`);let n=r.toLowerCase();if(Object.hasOwn(t,n))throw TypeError(`HTTP header ${JSON.stringify(r)} occurs more than once.`);if(c8(n))throw TypeError(`HTTP header ${JSON.stringify(r)} is owned by transport.`);if(typeof i!=="string")throw TypeError(`HTTP header ${JSON.stringify(r)} must be a string.`);if(u8(i))throw TypeError(`HTTP header ${JSON.stringify(r)} contains a control character.`);t[n]=i}return Object.freeze(t)}function e8(e){if(typeof e==="string")return e;return new Uint8Array(e).buffer}function t8(e){return typeof e==="string"?new TextEncoder().encode(e).byteLength:e.byteLength}function r8(e){if(!(e.headers.get("cache-control")?.split(",").map((r)=>r.trim().toLowerCase())??[]).includes("no-store"))throw new pe("server response is missing Cache-Control: no-store.")}function n8(e,t,r,i,n,o,s){if(e instanceof zt||e instanceof pe)return e;if(t.timedOut)return new De(`request timed out after ${i}ms.`,{cause:at(e),phase:"timeout",delivery:s});if(r?.aborted)return at(r.reason??e);return e instanceof De?e:new De(`Failed to communicate with the server at ${n}.`,{cause:at(e),phase:o,delivery:s})}function i8(e){if(e===void 0||e==="json")return"json";if(e==="msgpack")return e;throw TypeError('codec must be "json" or "msgpack".')}function o8(e){let t=e??globalThis.fetch;if(typeof t!=="function")throw TypeError("HttpTransport requires a Fetch implementation.");return e===void 0?t.bind(globalThis):t}var s8=/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/,a8=new Set(["accept","accept-encoding","authorization","cache-control","connection","content-length","content-type","cookie","expect","forwarded","host","keep-alive","origin","pragma","proxy-authenticate","proxy-authorization","referer","referrer-policy","set-cookie","te",me.http.TRACEPARENT_FIELD,me.http.TRACESTATE_FIELD,me.http.BAGGAGE_FIELD,"trailer","transfer-encoding","upgrade","via"]);function c8(e){return a8.has(e)||e.startsWith("access-control-")||e.startsWith("content-")||e.startsWith("proxy-")||e.startsWith("sec-websocket-")||e.startsWith("x-astrale-")||e.startsWith("x-forwarded-")}function u8(e){for(let t=0;t<e.length;t+=1){let r=e.charCodeAt(t);if(r<=31||r===127)return!0}return!1}async function EB(e){let t=await e;if(t.kind!=="value")return OL("value",t);return t}async function vB(e){let t=await e;if(t.kind!=="stream")IL("stream",t.kind);return t}async function xB(e){let t=await e;if(t.kind!=="binary")return OL("binary",t);return t}function IL(e,t){throw new X(`Function returned ${t}; ${e} was required.`)}async function OL(e,t){if(t.kind==="stream")await t.stream.cancel(`Expected ${e} Function result.`).catch(()=>{return});IL(e,t.kind)}function DL(e,t){let r=(i,n)=>e(t,i,n);return Object.freeze({dispatch:r,call:(i,n)=>EB(r(i,n)),stream:(i,n)=>vB(r(i,n)),binary:(i,n)=>xB(r(i,n))})}async function _L(e,t){d8(t);let r=Promise.resolve(typeof e==="function"?e():e),i=await l8(r,t);if(typeof i!=="string"||i.length===0)throw TypeError("Remote credentials must be non-empty strings.");return i}function l8(e,t){if(t===void 0)return e;return new Promise((r,i)=>{let n=()=>{t.removeEventListener("abort",n),i(kL(t.reason))};if(t.addEventListener("abort",n,{once:!0}),t.aborted){n();return}e.then((o)=>{t.removeEventListener("abort",n),r(o)},(o)=>{t.removeEventListener("abort",n),i(o)})})}function d8(e){if(e?.aborted===!0)throw kL(e.reason)}function kL(e){return e instanceof Error?e:new X("Client request was cancelled.",{cause:e})}function bl(e){if(e===null||typeof e!=="object"||Array.isArray(e))throw TypeError("Client call must be an object.");return Object.freeze({target:f8(e.target),input:p8(e.input)})}function f8(e){try{return q.parse(typeof e==="string"?e:e.raw).raw}catch(t){throw TypeError("Client call path must be a NodePath.",{cause:t})}}function p8(e){try{return SL(se(e))}catch(t){throw TypeError("Client input must be a portable Value.",{cause:t})}}function SL(e){if(e!==null&&typeof e==="object"&&!Object.isFrozen(e)){for(let t of Object.values(e))SL(t);Object.freeze(e)}return e}function tr(e,t){return Object.freeze({target:e,input:t})}function AL(e,t,r){let i=bl(e),n=y8(m8(t),r),o=B8(t?.delegate),s=h8(t?.routing),a=g8(t?.schema);return Object.freeze({call:i,...o===void 0?{}:{delegate:o},...s===void 0?{}:{routing:s},...a===void 0?{}:{schema:a},options:n})}function $L(e,t,r){let i=r===void 0?void 0:me.admitTrace(r);if(e.routing?.kind==="via"){if(e.delegate!==void 0)throw TypeError("Destination Client requests cannot carry a delegation request.");if(e.schema!==void 0)throw TypeError("Destination Client requests cannot carry a Schema target.")}else if(t===void 0!==(e.delegate===void 0))throw TypeError("Source Client credentials and delegation requests must occur together.");return Object.freeze({call:e.call,...t===void 0?{}:{credential:t},...e.delegate===void 0?{}:{delegate:e.delegate},...e.routing===void 0?{}:{routing:e.routing},...e.schema===void 0?{}:{schema:e.schema},...i===void 0?{}:{trace:i}})}function m8(e){if(e===void 0)return;if(e===null||typeof e!=="object"||Array.isArray(e))throw TypeError("Client request options must be an object.");if(e.timeoutMs!==void 0&&(!Number.isSafeInteger(e.timeoutMs)||e.timeoutMs<1||e.timeoutMs>2147483647))throw TypeError("Client request timeoutMs must be a positive safe platform integer.");let t=e.idempotencyKey===void 0?void 0:me.acceptIdempotencyKey(e.idempotencyKey,"request.idempotencyKey");return Object.freeze({...e.signal===void 0?{}:{signal:e.signal},...e.timeoutMs===void 0?{}:{timeoutMs:e.timeoutMs},...t===void 0?{}:{idempotencyKey:t}})}function B8(e){if(e===void 0)return;try{return me.acceptDelegate(e)}catch(t){throw TypeError("Client delegation request is invalid.",{cause:t})}}function h8(e){if(e===void 0)return;try{return me.acceptRouting(e)}catch(t){throw TypeError("Client routing context is invalid.",{cause:t})}}function g8(e){if(e===void 0)return;try{return me.acceptSchemaTarget(e)}catch(t){throw TypeError("Client Schema target is invalid.",{cause:t})}}function y8(e,t){let r=e?.signal===void 0?t:AbortSignal.any([e.signal,t]);return Object.freeze({signal:r,...e?.timeoutMs===void 0?{}:{timeoutMs:e.timeoutMs},...e?.idempotencyKey===void 0?{}:{idempotencyKey:e.idempotencyKey}})}var TL=new WeakSet,NL=new WeakSet;function RL(e){let t=new ws(e);return TL.add(t),t}function jL(e,t){let r=new Qa(e,t);return NL.add(r),r}function aD(e){return e instanceof ws&&TL.has(e)}function cD(e){return e instanceof Qa&&NL.has(e)}var PL=new WeakMap;function uD(e,t,r,i,n){let o=PL.get(e);if(o===void 0)throw TypeError("Trace dispatch requires an owned Client.");return o(t,r,i,n)}class gs{transport;lifecycle=new AbortController;closed=!1;constructor(e){if(e===null||typeof e!=="object")throw TypeError("Client options must be an object.");this.transport=Object.hasOwn(e,"transport")?b8(e.transport):new xi(e),PL.set(this,(t,r,i,n)=>this.dispatchWith(t,r,i,n))}dispatch(e,t){return this.dispatchWith(void 0,e,t)}call(e,t){return EB(this.dispatch(e,t))}stream(e,t){return vB(this.dispatch(e,t))}binary(e,t){return xB(this.dispatch(e,t))}as(e){return DL((t,r,i)=>this.dispatchWith(t,r,i),e)}close(){if(this.closed)return;this.closed=!0;let e=new X("Client is closed.");this.lifecycle.abort(e),this.transport.close?.()}async dispatchWith(e,t,r,i){if(this.closed)throw new X("Client is closed.");let n=AL(t,r,this.lifecycle.signal),o=e===void 0?void 0:await _L(e,n.options.signal);C8(n.options.signal);let s=await this.transport.dispatch($L(n,o,i),n.options);if(s.kind==="stale")throw jL(s.current,s.invocation);if(s.kind==="miss")throw RL(s.invocation);return s}}function C8(e){if(e?.aborted!==!0)return;let t=e.reason;throw t instanceof Error?t:new X("Client request was cancelled.",{cause:t})}function b8(e){if(e===null||typeof e!=="object")throw TypeError("Client transport must be an object.");let t=e.dispatch;if(typeof t!=="function")throw TypeError("Client transport must implement dispatch().");let r=e.close;if(r!==void 0&&typeof r!=="function")throw TypeError("Client transport close capability is invalid.");return Object.freeze({dispatch:t.bind(e),...r===void 0?{}:{close:r.bind(e)}})}class lD{owner;requestId;control;maximumBufferedItems;result;resolveResult;rejectResult;abort;state="response";claimed=!1;index=0;values=[];waiters=[];terminal;sent=!1;invocation;constructor(e,t,r,i){if(this.owner=e,this.requestId=t,this.control=r,this.maximumBufferedItems=i,this.result=new Promise((n,o)=>{this.resolveResult=n,this.rejectResult=o}),this.abort=()=>this.cancelLocally(this.abortFailure()),!r.signal.aborted)r.signal.addEventListener("abort",this.abort,{once:!0})}start(e,t){if(this.state==="finished")return this.result;if(this.control.signal.aborted)return this.abort(),this.result;try{e(t),this.sent=!0}catch(r){this.fail(new De("Failed to send the WebSocket invocation.",{cause:at(r),phase:"send",delivery:"not-sent"}),1011)}return this.result}receive(e){try{if(this.state==="response"){this.receiveResponse(e);return}if(this.state!=="stream"||Xa(e,"binary"))throw new pe("server sent an unexpected WebSocket response.");this.receiveStreamFrame(e)}catch(t){let r=E8(t,this.invocation);this.fail(r,r instanceof El?1008:1002)}}connectionFailed(e){this.fail(this.sent?new De(e.message,{cause:e,phase:"receive",delivery:"unknown",...this.invocation===void 0?{}:{invocation:this.invocation}}):e)}[Symbol.asyncIterator](){if(this.claimed)throw TypeError("streams admit exactly one consumer.");return this.claimed=!0,{next:()=>this.next(),return:async()=>(await this.cancel("stream consumer stopped"),{done:!0,value:void 0}),throw:async(e)=>{throw await this.cancel("stream consumer failed"),e}}}async cancel(e="stream cancelled"){if(this.state==="finished")return;this.values.length=0,this.terminal=!0,this.finishCancelled(),this.flushTerminal()}receiveResponse(e){if(Xa(e,"binary")){let r=e;ys(this.requestId,r.requestId),this.complete({kind:"binary",invocation:r.invocation,value:{body:r.body,mediaType:r.mediaType,...r.headers===void 0?{}:{headers:r.headers}}});return}if(Xa(e,"stream.start")){let r=e;if(ys(this.requestId,r.requestId),r.kind!=="stream.start")throw new pe("stream did not begin with stream.start.");this.state="stream",this.invocation=r.invocation,this.resolveResult({kind:"stream",stream:this,invocation:r.invocation});return}if(Xa(e,"redirect")){let r=e;ys(this.requestId,r.requestId),this.complete({kind:"redirect",invocation:r.invocation,redirect:r.redirect});return}if(Xa(e,"stale")){let r=e;ys(this.requestId,r.requestId),this.complete(Object.freeze({kind:"stale",current:r.current,invocation:r.invocation}));return}if(Xa(e,"miss")){let r=e;ys(this.requestId,r.requestId),this.complete(Object.freeze({kind:"miss",invocation:r.invocation}));return}let t=e;if(ys(this.requestId,t.requestId),"error"in t){this.reject(new zt(t.error.code,t.error.message,t.invocation,t.error.data));return}this.complete({kind:"value",value:t.result,invocation:t.invocation})}receiveStreamFrame(e){if(ys(this.requestId,e.requestId),e.kind==="stream.start")throw new pe("server sent a duplicate stream.start frame.");if(e.kind==="stream.item"){if(e.index!==this.index)throw new pe(`stream item ${e.index} does not match expected index ${this.index}.`);this.index+=1;let t=this.waiters.shift();if(t!==void 0)t.resolve({done:!1,value:e.value});else{if(this.values.length>=this.maximumBufferedItems)throw new El(`stream exceeds maximumBufferedStreamItems (${this.maximumBufferedItems}).`);this.values.push(e.value)}return}if(e.kind==="stream.end"&&e.count!==this.index)throw new pe(`stream ended with count ${e.count}; ${this.index} items were received.`);this.terminal=e.kind==="stream.error"?new zt(e.error.code,e.error.message,this.invocation,e.error.data):!0,this.finish(!0),this.flushTerminal()}next(){let e=this.values.shift();if(e!==void 0)return Promise.resolve({done:!1,value:e});if(this.terminal===!0)return Promise.resolve({done:!0,value:void 0});if(this.terminal instanceof Error)return Promise.reject(this.terminal);return new Promise((t,r)=>this.waiters.push({resolve:t,reject:r}))}complete(e){this.finish(!0),this.resolveResult(e)}reject(e){this.finish(!0),this.rejectResult(e)}fail(e,t=1002){if(this.state==="finished")return;if(this.state==="response")this.rejectResult(e);else this.terminal=e,this.flushTerminal();this.finish(!1,t)}cancelLocally(e){if(this.state==="finished")return;if(this.state==="response")this.rejectResult(e);else this.values.length=0,this.terminal=e,this.flushTerminal();this.finishCancelled()}finish(e,t){if(this.state==="finished")return;this.state="finished",this.control.signal.removeEventListener("abort",this.abort),this.control.close(),this.owner.finish(this,e,t)}finishCancelled(){if(this.state==="finished")return;this.state="finished",this.control.signal.removeEventListener("abort",this.abort),this.control.close(),this.owner.cancel(this,this.requestId)}flushTerminal(){if(this.terminal===void 0)return;for(let e of this.waiters.splice(0))if(this.terminal===!0)e.resolve({done:!0,value:void 0});else e.reject(this.terminal)}abortFailure(){if(this.control.timedOut)return new De("WebSocket invocation exceeded its timeout.",{cause:at(this.control.signal.reason),phase:"timeout",delivery:this.sent?"unknown":"not-sent",...this.invocation===void 0?{}:{invocation:this.invocation}});return at(this.control.signal.reason??Error("WebSocket invocation was cancelled."))}}class El extends pe{}function E8(e,t){if(e instanceof zt)return e;if(e instanceof El)return e.invocation!==void 0||t===void 0?e:new El(e.message,{cause:e,invocation:t});if(e instanceof pe)return e.invocation!==void 0||t===void 0?e:new pe(e.message,{cause:e,invocation:t});if(e instanceof Ra.ProtocolError)return new pe(e.message,{cause:e,invocation:t});return new pe("server returned an invalid WebSocket frame.",{cause:at(e),invocation:t})}function ys(e,t){if(t!==e)throw new pe(`response requestId ${JSON.stringify(t)} does not match request requestId ${JSON.stringify(e)}.`)}function Xa(e,t){return typeof e==="object"&&e!==null&&!Array.isArray(e)&&e.kind===t}var v8=0,LL=1;class pD{owner;codec;maximumRequestBytes;maximumResponseBytes;maximumBufferedBytes;maximumActiveInvocations;socket;ready;resolveReady;rejectReady;opened=!1;closedState=!1;active=new Map;cancelled=new Set;incoming=Promise.resolve();constructor(e,t,r,i,n,o,s,a){this.owner=e,this.codec=i,this.maximumRequestBytes=n,this.maximumResponseBytes=o,this.maximumBufferedBytes=s,this.maximumActiveInvocations=a,this.ready=new Promise((c,u)=>{this.resolveReady=c,this.rejectReady=u}),this.socket=new t(r,me.websocket.subprotocolFor(i)),this.socket.binaryType="arraybuffer",this.socket.addEventListener("open",()=>this.onOpen(),{once:!0}),this.socket.addEventListener("message",(c)=>this.onMessage(c)),this.socket.addEventListener("error",()=>this.onFailure("WebSocket connection failed.")),this.socket.addEventListener("close",()=>this.onFailure("WebSocket connection closed."))}get isOpen(){return!this.closedState&&this.opened&&this.socket.readyState===LL}get isAvailable(){return!this.closedState}async connect(e){if(e.signal.aborted)throw at(e.signal.reason);let t,r=new Promise((i,n)=>{t=()=>n(at(e.signal.reason)),e.signal.addEventListener("abort",t,{once:!0})});try{await Promise.race([this.ready,r])}finally{e.signal.removeEventListener("abort",t)}}dispatch(e,t,r){if(!this.isOpen)return t.close(),Promise.reject(new De("WebSocket connection is not available.",{phase:"connect",delivery:"not-sent"}));let i=fD(e.requestId);if(this.active.has(i)||this.cancelled.has(i))return t.close(),Promise.reject(new pe("WebSocket request ID is already in use."));if(this.active.size+this.cancelled.size>=this.maximumActiveInvocations)return t.close(),Promise.reject(new De(`WebSocket connection exceeds maximumActiveInvocations (${this.maximumActiveInvocations}).`,{phase:"send",delivery:"not-sent"}));let n=this.codec.encode(e),o=dD(n);if(o>this.maximumRequestBytes)return t.close(),Promise.reject(new De(`WebSocket request exceeds maximumRequestBytes (${this.maximumRequestBytes}).`,{phase:"send",delivery:"not-sent"}));if(this.socket.bufferedAmount+o>this.maximumBufferedBytes)return t.close(),Promise.reject(new De(`WebSocket connection exceeds maximumBufferedBytes (${this.maximumBufferedBytes}).`,{phase:"send",delivery:"not-sent"}));let s=new lD(this,e.requestId,t,r);return this.active.set(i,s),s.start((a)=>this.socket.send(zL(a)),n)}finish(e,t,r=1002){if(k8(this.active,e),!t)this.shutdown(new De("WebSocket connection was closed after a binding failure.",{phase:"receive",delivery:"not-sent"}),r,O8(r))}cancel(e,t){let r=fD(t);if(this.active.get(r)!==e)return;this.active.delete(r),this.cancelled.add(r);try{let i=this.codec.encode(me.decodeCancelRequest({version:me.VERSION,kind:"cancel",requestId:t})),n=dD(i);if(n>this.maximumRequestBytes||this.socket.bufferedAmount+n>this.maximumBufferedBytes)throw new wi("WebSocket cancellation exceeds the connection send policy.",1008,"Client send policy exceeded");this.socket.send(zL(i))}catch(i){this.shutdown(new De("Failed to send WebSocket cancellation.",{cause:at(i),phase:"send",delivery:"unknown"}),i instanceof wi?i.closeCode:1011,i instanceof wi?i.closeReason:"Client send failed")}}shutdown(e=new De("WebSocket connection was closed.",{phase:"closed",delivery:"not-sent"}),t=1000,r="Client closed"){if(this.closedState)return;this.closedState=!0,this.rejectReady(e);let i=[...this.active.values()];this.active.clear(),this.cancelled.clear();for(let n of i)n.connectionFailed(e);try{if(this.socket.readyState===v8||this.socket.readyState===LL)this.socket.close(t,r)}catch{}this.owner.closed(this)}onOpen(){if(this.closedState)return;let e=me.websocket.subprotocolFor(this.codec);if(this.socket.protocol!==e){this.shutdown(new De(`server selected WebSocket subprotocol ${JSON.stringify(this.socket.protocol)}; expected ${JSON.stringify(e)}.`,{phase:"connect",delivery:"not-sent"}),1002,"Subprotocol mismatch");return}this.opened=!0,this.resolveReady()}onMessage(e){this.incoming=this.incoming.then(async()=>{let t=await x8(e.data);if(dD(t)>this.maximumResponseBytes)throw new wi(`WebSocket frame exceeds maximumResponseBytes (${this.maximumResponseBytes}).`,1009,"Message too big");let r=w8(this.codec,t),i=fD(r.requestId),n=this.active.get(i);if(n!==void 0){n.receive(r);return}if(this.cancelled.has(i)){if(D8(r))this.cancelled.delete(i);return}throw new pe("server sent an unsolicited WebSocket frame.")}).catch((t)=>{let r=I8(t);this.shutdown(r,r.closeCode,r.closeReason)})}onFailure(e){if(this.closedState)return;this.shutdown(new De(e,{phase:this.opened?"receive":"connect",delivery:"not-sent"}))}}async function x8(e){if(typeof e==="string")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e.slice(0));if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength));if(typeof Blob<"u"&&e instanceof Blob)return new Uint8Array(await e.arrayBuffer());throw new pe("server returned an unsupported WebSocket frame type.")}function dD(e){return typeof e==="string"?new TextEncoder().encode(e).byteLength:e.byteLength}function zL(e){if(typeof e==="string")return e;return new Uint8Array(e).buffer}function w8(e,t){try{let r=typeof t==="string"?void 0:me.websocket.decodeBinary(t);if(r!==void 0)return r;if(e.binary&&typeof t==="string"||!e.binary&&typeof t!=="string")throw new wi("server returned a message type incompatible with the selected subprotocol.",1003,"Unsupported message type");let i=e.decode(t);if(vl(i,"redirect"))return me.decodeRedirectResponse(i);if(vl(i,"stale"))return me.decodeStale(i);if(vl(i,"miss"))return me.decodeMiss(i);if(_8(i))return me.decodeStreamFrame(i);return me.decodeResponse(i)}catch(r){if(r instanceof wi)throw r;throw new pe("server returned an invalid WebSocket frame.",{cause:at(r)})}}class wi extends pe{closeCode;closeReason;constructor(e,t,r){super(e);this.closeCode=t,this.closeReason=r}}function I8(e){if(e instanceof wi)return e;let t=e instanceof pe?e:new pe("server returned an invalid WebSocket frame.",{cause:at(e)});return new wi(t.message,1002,"Protocol error")}function O8(e){if(e===1008)return"Client policy exceeded";if(e===1011)return"Client send failed";return"Protocol error"}function D8(e){return!vl(e,"stream.start")&&!vl(e,"stream.item")}function _8(e){let t=typeof e==="object"&&e!==null&&!Array.isArray(e)?e.kind:void 0;return typeof t==="string"&&t.startsWith("stream.")}function vl(e,t){return typeof e==="object"&&e!==null&&!Array.isArray(e)&&e.kind===t}function fD(e){return e===null?"null:":`${typeof e}:${String(e)}`}function k8(e,t){for(let[r,i]of e){if(i!==t)continue;e.delete(r);return}}var S8=30000,A8=16777216,$8=16777216,T8=16777216,N8=1024,R8=256;class Cs{url;connectionUrl;codecName;WebSocketConstructor;timeoutMs;maximumRequestBytes;maximumResponseBytes;maximumBufferedBytes;maximumActiveInvocations;maximumBufferedStreamItems;connections=new Set;connectionOwner=Object.freeze({closed:(e)=>this.connectionClosed(e)});connection;stopped=!1;nextId=1;constructor(e){if(e===null||typeof e!=="object")throw TypeError("WebSocketTransport options must be an object.");this.url=j8(e.url),this.connectionUrl=this.url,this.codecName=P8(e.codec),this.WebSocketConstructor=L8(e.websocket),this.timeoutMs=Gt(e.timeoutMs??S8,"timeoutMs"),this.maximumRequestBytes=Gt(e.maximumRequestBytes??A8,"maximumRequestBytes"),this.maximumResponseBytes=Gt(e.maximumResponseBytes??$8,"maximumResponseBytes"),this.maximumBufferedBytes=Gt(e.maximumBufferedBytes??T8,"maximumBufferedBytes"),this.maximumActiveInvocations=Gt(e.maximumActiveInvocations??N8,"maximumActiveInvocations"),this.maximumBufferedStreamItems=Gt(e.maximumBufferedStreamItems??R8,"maximumBufferedStreamItems")}async dispatch(e,t={}){if(this.stopped)throw new De("WebSocketTransport is closed.",{phase:"closed",delivery:"not-sent"});let r=Gt(t.timeoutMs??this.timeoutMs,"timeoutMs"),i=await this.codec();if(this.stopped)throw new De("WebSocketTransport is closed.",{phase:"closed",delivery:"not-sent"});let n=me.decodeRequest({version:me.VERSION,requestId:this.nextRequestId(),...e,...t.idempotencyKey===void 0?{}:{idempotencyKey:t.idempotencyKey}}),o=Cl(t.signal,r),s=!1;try{br(o);let a=await this.acquire(o,i);return br(o),s=!0,await a.dispatch(n,o,this.maximumBufferedStreamItems)}catch(a){throw z8(a,o,t.signal,r,this.url)}finally{if(!s)o.close()}}close(){if(this.stopped)return;this.stopped=!0,this.connection=void 0;let e=new De("WebSocketTransport is closed.",{phase:"closed",delivery:"not-sent"});for(let t of this.connections)t.shutdown(e)}connectionClosed(e){if(this.connections.delete(e),this.connection===e)this.connection=void 0}async acquire(e,t){let r=this.connection;if(r===void 0||!r.isAvailable)r=new pD(this.connectionOwner,this.WebSocketConstructor,this.connectionUrl,t,this.maximumRequestBytes,this.maximumResponseBytes,this.maximumBufferedBytes,this.maximumActiveInvocations),this.connection=r,this.connections.add(r);return await r.connect(e),r}nextRequestId(){let e=this.nextId;return this.nextId=e===Number.MAX_SAFE_INTEGER?1:e+1,e}codec(){return this.codecName==="msgpack"?Lt.loadMsgpack():Promise.resolve(Lt.json)}}function j8(e){if(typeof e!=="string")throw TypeError("server URL must be a string.");let t;try{t=new URL(e)}catch(r){throw TypeError(`Invalid server URL ${JSON.stringify(e)}.`,{cause:at(r)})}if(t.protocol==="http:")t.protocol="ws:";else if(t.protocol==="https:")t.protocol="wss:";else if(t.protocol!=="ws:"&&t.protocol!=="wss:")throw TypeError("server URL must use http, https, ws, or wss.");if(t.username!==""||t.password!==""||t.hash!=="")throw TypeError("server URL cannot contain credentials or a fragment.");return t.toString()}function P8(e){if(e===void 0||e==="json")return"json";if(e==="msgpack")return e;throw TypeError('codec must be "json" or "msgpack".')}function L8(e){let t=e??globalThis.WebSocket;if(typeof t!=="function")throw TypeError("WebSocketTransport requires a WebSocket implementation.");return t}function z8(e,t,r,i,n){if(e instanceof zt||e instanceof pe)return e;if(e instanceof De)return e;if(t.timedOut)return new De(`WebSocket invocation timed out after ${i}ms.`,{cause:at(e),phase:"timeout",delivery:"not-sent"});if(r?.aborted)return at(r.reason??e);return new De(`Failed to communicate with the server at ${n}.`,{cause:at(e),phase:"connect",delivery:"not-sent"})}class mD{selected;pending;closed=!1;begin(){if(this.closed)return{kind:"wait",selection:Promise.resolve(void 0)};if(this.selected)return{kind:"selected",selection:this.selected};if(this.pending)return{kind:"wait",selection:this.pending.promise};let e,t=new Promise((r)=>{e=r});return this.pending={promise:t,resolve:e},{kind:"probe"}}select(e){if(this.closed||this.selected)return;this.selected=e,this.pending?.resolve(e),this.pending=void 0}demote(){if(this.closed||this.selected==="http")return;this.selected="http",this.pending?.resolve("http"),this.pending=void 0}release(){if(this.closed||this.selected)return;this.pending?.resolve(void 0),this.pending=void 0}close(){if(this.closed)return;this.closed=!0,this.pending?.resolve(void 0),this.pending=void 0}}var M8=2147483647;class BD{input;started=Date.now();timeoutMs;constructor(e,t){this.input=e,this.timeoutMs=Gt(e?.timeoutMs??t,"timeoutMs")}options(){let e=this.remaining();return Object.freeze({...this.input?.signal===void 0?{}:{signal:this.input.signal},timeoutMs:e,...this.input?.idempotencyKey===void 0?{}:{idempotencyKey:this.input.idempotencyKey}})}get cancelled(){return this.input?.signal?.aborted===!0}get idempotency(){return this.input?.idempotencyKey===void 0?"absent":"supplied"}async wait(e){if(this.input?.signal?.aborted)throw ML(this.input.signal);let t=this.remaining(),r,i,n=new Promise((o,s)=>{if(r=setTimeout(()=>s(new De("Automatic transport decision exceeded its timeout.",{phase:"timeout",delivery:"not-sent"})),t),this.input?.signal)i=()=>s(ML(this.input.signal)),this.input.signal.addEventListener("abort",i,{once:!0})});try{return await Promise.race([e,n])}finally{if(r)clearTimeout(r);if(i&&this.input?.signal)this.input.signal.removeEventListener("abort",i)}}remaining(){let e=Math.min(M8,this.timeoutMs-(Date.now()-this.started));if(e<1)throw new De("Automatic transport invocation exceeded its timeout.",{phase:"timeout",delivery:"not-sent"});return e}}function UL(e){return e instanceof De&&e.phase!=="closed"&&e.phase!=="timeout"}function FL(e){return e.call.target}function ML(e){return e.reason instanceof Error?e.reason:Error(e.reason===void 0?"request was cancelled":String(e.reason))}function hD(e){return["[Astrale] WebSocket was unavailable before send; using HTTP for this client.",`idempotency=${e.idempotency}`,`target=${JSON.stringify(e.target)} websocket=${e.websocket} http=${e.http} phase=${e.phase}`].join(" ")}function GL(e,t){try{if(t)t(e);else globalThis.console?.warn(hD(e))}catch{}}var U8=30000;class xl{websocket;http;decision=new mD;timeoutMs;onWarning;closed=!1;constructor(e){if(e===null||typeof e!=="object")throw TypeError("AutoTransport options must be an object.");if(e.onWarning!==void 0&&typeof e.onWarning!=="function")throw TypeError("AutoTransport onWarning must be a function.");this.timeoutMs=Gt(e.timeoutMs??U8,"timeoutMs"),this.onWarning=e.onWarning,this.http=new xi({url:e.endpoints.http,...e.codec===void 0?{}:{codec:e.codec},...e.fetch===void 0?{}:{fetch:e.fetch},...e.headers===void 0?{}:{headers:e.headers},timeoutMs:this.timeoutMs,...e.maximumRequestBytes===void 0?{}:{maximumRequestBytes:e.maximumRequestBytes},...e.maximumResponseBytes===void 0?{}:{maximumResponseBytes:e.maximumResponseBytes}}),this.websocket=new Cs({url:e.endpoints.websocket,...e.codec===void 0?{}:{codec:e.codec},...e.websocket===void 0?{}:{websocket:e.websocket},timeoutMs:this.timeoutMs,...e.maximumRequestBytes===void 0?{}:{maximumRequestBytes:e.maximumRequestBytes},...e.maximumResponseBytes===void 0?{}:{maximumResponseBytes:e.maximumResponseBytes},...e.maximumBufferedBytes===void 0?{}:{maximumBufferedBytes:e.maximumBufferedBytes},...e.maximumActiveInvocations===void 0?{}:{maximumActiveInvocations:e.maximumActiveInvocations},...e.maximumBufferedStreamItems===void 0?{}:{maximumBufferedStreamItems:e.maximumBufferedStreamItems}})}async dispatch(e,t){this.requireOpen();let r=new BD(t,this.timeoutMs);return this.dispatchWithBudget(e,r)}async dispatchWithBudget(e,t){let r=this.decision.begin();if(r.kind==="selected")return r.selection==="websocket"?this.tryWebsocket(e,t,!1):this.http.dispatch(e,t.options());if(r.kind==="wait"){let i=await t.wait(r.selection);if(this.requireOpen(),!i)return this.dispatchWithBudget(e,t);return i==="websocket"?this.tryWebsocket(e,t,!1):this.http.dispatch(e,t.options())}return this.determine(e,t)}close(){if(this.closed)return;this.closed=!0,this.decision.close(),this.websocket.close()}async determine(e,t){return this.tryWebsocket(e,t,!0)}async tryWebsocket(e,t,r){try{let i=await this.websocket.dispatch(e,t.options());if(r)this.decision.select("websocket");return i}catch(i){if(t.cancelled){if(r)this.decision.release();throw i}if(i instanceof De&&i.delivery==="unknown")throw this.decision.demote(),i;if(!UL(i)){if(r)this.decision.select("websocket");throw i}let n=t.idempotency,o={code:"AUTO_TRANSPORT_DOWNGRADED",target:FL(e),websocket:this.websocket.url,http:this.http.url,phase:i.phase,delivery:"not-sent",idempotency:n};return GL(Object.freeze(o),this.onWarning),this.decision.demote(),this.http.dispatch(e,t.options())}}requireOpen(){if(!this.closed)return;throw new De("AutoTransport is closed.",{phase:"closed",delivery:"not-sent"})}}var F8=q.project(et.identity.whoami.ref.owner),HL=q.staticMethod(F8,et.identity.can.ref.name).raw;function VL(e){return Object.freeze({async can(t,r){return(await e(HL,Object.freeze({policy:G8(t.policy),object:t.object}),r)).allowed}})}function G8(e){return e instanceof q||typeof e==="string"?q.from(e).raw:q.project(e).raw}var H8=q.project(et.identity.whoami.ref.owner),JL=q.staticMethod(H8,et.identity.mint.ref.name).raw;function KL(e){return Object.freeze({async mint(t,r){return qL(await e(JL,t,r))},async delegate(t,r,i){let n=q.instanceMethod(q.id(t),et.identity.delegate.ref.name).raw;return qL(await e(n,r,i))}})}function qL(e){if(typeof e!=="string"||e.length===0)throw TypeError("Identity syscall returned an invalid credential.");return e}var ZL=q.project(et.identity.whoami.ref.owner),WL=q.staticMethod(ZL,et.identity.whoami.ref.name).raw,YL=q.staticMethod(ZL,et.identity.whois.ref.name).raw;function QL(e){return Object.freeze({async whoami(t){return await e(WL,Object.freeze({}),t)},async whois(t,r){return await e(YL,t,r)}})}var XL=q.project(et.provision.ref).raw;function e1(e){return Object.freeze({async provision(t,r){return await e(XL,t,r)}})}function gD(e){if(typeof e!=="function")throw TypeError("Auth call capability is invalid.");return Object.freeze({...e1(e),...QL(e),...VL(e),...KL(e)})}function yD(e){if(e===null||typeof e!=="object")throw TypeError("Client target must be an object.");if(e.transport==="http")return Object.freeze({transport:"http",url:wB(e.url,["http:","https:"])});if(e.transport==="websocket"){let t=new URL(wB(e.url,["http:","https:","ws:","wss:"]));if(t.protocol==="http:")t.protocol="ws:";if(t.protocol==="https:")t.protocol="wss:";return Object.freeze({transport:"websocket",url:t.toString()})}if(e.transport==="auto"&&e.endpoints&&typeof e.endpoints==="object")return Object.freeze({transport:"auto",endpoints:Object.freeze({http:wB(e.endpoints.http,["http:","https:"]),websocket:wB(e.endpoints.websocket,["http:","https:","ws:","wss:"])})});throw TypeError("Client target transport is invalid.")}function CD(e){return e.transport==="auto"?`auto\x00${e.endpoints.http}\x00${e.endpoints.websocket}`:`${e.transport}\x00${e.url}`}function wB(e,t){if(typeof e!=="string")throw TypeError("Client target URL must be a string.");let r;try{r=new URL(e)}catch(i){throw TypeError("Client target URL is invalid.",{cause:i})}if(!t.includes(r.protocol)||r.username!==""||r.password!==""||r.hash!=="")throw TypeError("Client target URL is invalid.");return r.toString()}class IB{clients=new Map;createClient;maximumSize;closed=!1;constructor(e){if(typeof e?.client!=="function")throw TypeError("ClientPool client factory is invalid.");if(this.createClient=e.client,this.maximumSize=e.maximumSize??32,!Number.isSafeInteger(this.maximumSize)||this.maximumSize<1)throw TypeError("ClientPool maximumSize must be a positive safe integer.")}clientFor(e){this.requireOpen();let t=yD(e),r=CD(t),i=this.clients.get(r);if(i)return this.clients.delete(r),this.clients.set(r,i),i.client;if(this.clients.size===this.maximumSize)this.evictOldest();let n=this.createClient(t);return this.clients.set(r,{target:t,client:n}),n}evict(e){let t=yD(e),r=CD(t),i=this.clients.get(r);if(!i)return;this.clients.delete(r),i.client.close()}close(){if(this.closed)return;this.closed=!0;for(let{client:e}of this.clients.values())e.close();this.clients.clear()}get size(){return this.clients.size}get isClosed(){return this.closed}evictOldest(){let e=this.clients.entries().next().value;if(!e)return;this.clients.delete(e[0]),e[1].client.close()}requireOpen(){if(this.closed)throw new X("ClientPool is closed.")}}function bD(e,t){if(e.declaration.output.mode!=="value")throw TypeError("Schema Client expected a value-producing Kernel syscall.");let r=se(t),i=Y.values.validate(ll,e.declaration.output.schema,r,"/output");if(i.length>0)throw TypeError(`Kernel returned an invalid Schema result: ${i[0].message}`);return t1(r)}function t1(e){if(e!==null&&typeof e==="object"&&!Object.isFrozen(e)){for(let t of Object.values(e))t1(t);Object.freeze(e)}return e}var V8=q.project(et.introspect.ref).raw;async function r1(e,t,r,i){let n=await e(tr(V8,r),i);if(n.kind!=="binary")throw TypeError("Schema introspection returned a non-binary result.");if(n.value.mediaType!==gl.installation.introspection.MEDIA_TYPE)throw TypeError("Schema introspection returned an unsupported media type.");return gl.installation.introspection.decode(r,n.value.body,t)}var q8=q.project(et.install.ref).raw,J8=q.project(et.uninstall.ref).raw;function ED(e,t){if(typeof e!=="function")throw TypeError("Schema call capability is invalid.");let r=K8(t);return Object.freeze({async install(i,n){let o=n1(await e(tr(q8,i),n));return bD(et.install,o)},async uninstall(i,n){let o=n1(await e(tr(J8,i),n));return bD(et.uninstall,o)},async introspect(i,n){return r1(e,r,i,n)}})}function n1(e){if(e.kind!=="value")throw TypeError("Schema syscall returned a non-value result.");return e.value}function K8(e){if(e===null||typeof e!=="object"||!Number.isSafeInteger(e.maximumPublicationBytes)||e.maximumPublicationBytes<1||!Number.isSafeInteger(e.maximumBundleBytes)||e.maximumBundleBytes<1)throw TypeError("Schema introspection limits are invalid.");return Object.freeze({...e})}var vD=1048576,xD=16777216,wD=16777216,ID=30000,OD=256;function mo(e,t){if(!Number.isSafeInteger(e)||e<1)throw TypeError(`${t} must be a positive safe integer.`);return e}function wl(e,t){let r=mo(e,t);if(r>2147483647)throw TypeError(`${t} exceeds the platform timer range.`);return r}function ec(e){if(e===void 0)return Object.freeze({});if(e===null||typeof e!=="object"||Array.isArray(e))throw TypeError("Session control options are invalid.");if(e.signal!==void 0&&!(e.signal instanceof AbortSignal))throw TypeError("Session cancellation signal is invalid.");return Object.freeze({...e.signal===void 0?{}:{signal:e.signal},...e.timeoutMs===void 0?{}:{timeoutMs:wl(e.timeoutMs,"timeoutMs")}})}function _D(e,t,r){let i=t?.timeoutMs??r,n=Date.now()+i,o=AbortSignal.timeout(i),s=t?.signal===void 0?[e,o]:[t.signal,e,o],a=!1;return Object.freeze({signal:AbortSignal.any(s),deadline:n,...t?.idempotencyKey===void 0?{}:{idempotencyKey:t.idempotencyKey},claimRecovery:()=>{if(a)return!1;return a=!0,!0}})}function Z8(e){DD(e);let t=e.deadline-Date.now();if(t<1)throw new X("Session operation timed out.");return t}function OB(e,t){return Object.freeze({signal:e.signal,timeoutMs:Z8(e),...t===void 0?{}:{idempotencyKey:t}})}function Er(e,t){try{DD(e)}catch(o){return Promise.reject(o)}let r,i=new Promise((o,s)=>{r=()=>s(i1(e.signal.reason)),e.signal.addEventListener("abort",r,{once:!0})}),n=Promise.resolve().then(()=>(DD(e),t(e.signal)));return Promise.race([n,i]).finally(()=>{if(r!==void 0)e.signal.removeEventListener("abort",r)})}function DD(e){if(!e.signal.aborted)return;throw i1(e.signal.reason)}function i1(e){if(e instanceof DOMException&&e.name==="TimeoutError")return new X("Session operation timed out.",{cause:e});return e instanceof Error?e:new X("Session operation was cancelled.",{cause:e})}function kD(e){if(e===null||typeof e!=="object")throw TypeError("Session policy is invalid.");if(e.allowEndpoint!==void 0&&typeof e.allowEndpoint!=="function")throw TypeError("Session endpoint policy is invalid.");if(e.allowInsecureHttp!==void 0&&typeof e.allowInsecureHttp!=="boolean")throw TypeError("Session insecure-transport policy is invalid.");return Object.freeze({maximumRouteAgeMs:mo(e.maximumRouteAgeMs,"maximumRouteAgeMs"),...e.allowEndpoint===void 0?{}:{allowEndpoint:e.allowEndpoint},...e.allowInsecureHttp===!0?{allowInsecureHttp:!0}:{}})}function SD(e,t){let r,i;try{i=ht.accept(e),r=new URL(i)}catch(n){throw TypeError("Session Kernel issuer is invalid.",{cause:n})}if(r.username!==""||r.password!==""||r.hash!==""||r.search!==""||r.protocol!=="https:"&&!(t&&r.protocol==="http:"))throw TypeError("Session Kernel issuer is invalid.");return i}function AD(e){return`${e}/invoke`}function vr(e,t){let r=new URL(e);if(r.protocol!=="https:"&&r.protocol!=="wss:"){if(r.protocol!=="http:"&&r.protocol!=="ws:"||t.allowInsecureHttp!==!0)throw new X("Insecure or unsupported endpoint is not allowed.")}if(t.allowEndpoint?.(r.toString())===!1)throw new X("Endpoint is denied by Session policy.")}class $D{options;publication;revision=0;constructor(e){this.options=e}current(){return this.publication}async revalidate(e){let t=this.revision,r=this.publication,i=await this.fetch(e,r);if(t!==this.revision)return this.revalidate(e);let n=r?.etag===i.etag?r:i;return this.publication=n,n}invalidate(){this.revision+=1,this.publication=void 0}async fetch(e,t){let r=er.url(this.options.kernel);vr(r,this.options.policy);let i=await Er(e,(a)=>this.options.fetch(r,{headers:{accept:"application/json",...t===void 0?{}:{"if-none-match":`"${t.etag}"`}},redirect:"manual",signal:a}));if(ND(i,r,"Publication discovery"),i.status===304){if(t===void 0)throw new X("Publication discovery returned an unexpected not-modified response.");let a=i.headers.get("etag");if(a!==null&&a!==`"${t.etag}"`)throw new X("Publication not-modified ETag differs from the cached snapshot.");return t}if(!i.ok)throw new X(`Publication discovery returned HTTP ${i.status}.`);let n=await Er(e,(a)=>TD(i,this.options.maximumBytes,a)),o=er.accept(Lt.json.decode(n));if(o.identity.issuer!==this.options.kernel)throw new X("Publication issuer differs from the requested Kernel issuer.");let s=i.headers.get("etag");if(s!==null&&s!==`"${o.etag}"`)throw new X("Publication response ETag differs from its canonical content.");return o}}async function TD(e,t,r){let i=e.headers.get("content-length");if(i!==null){let c=Number(i);if(!Number.isSafeInteger(c)||c<0)throw new X("Response Content-Length is invalid.");if(c>t)throw new X("Response exceeds its byte limit.")}if(e.body===null)return new Uint8Array;let n=e.body.getReader(),o=[],s=0,a=()=>void n.cancel(r.reason).catch(()=>{return});if(r.aborted)a();else r.addEventListener("abort",a,{once:!0});try{while(!0){if(r.aborted)throw r.reason;let c=await n.read();if(c.done)break;if(s+=c.value.byteLength,s>t)throw await n.cancel("response exceeds byte limit").catch(()=>{return}),new X("Response exceeds its byte limit.");o.push(c.value)}}finally{r.removeEventListener("abort",a),n.releaseLock()}return W8(o,s)}function ND(e,t,r){if(e.redirected||e.url!==t)throw new X(`${r} did not return the exact requested URL.`)}function W8(e,t){if(e.length===1)return new Uint8Array(e[0]);let r=new Uint8Array(t),i=0;for(let n of e)r.set(n,i),i+=n.byteLength;return r}class RD{options;bundles=new Map;constructor(e){this.options=e}async get(e,t){let r=Y8(e),i=this.bundles.get(r);if(i!==void 0)return i;let n=await this.fetch(e,t),o=this.bundles.get(r)??n;return this.bundles.set(r,o),o}clear(){this.bundles.clear()}async fetch(e,t){if(e.schema.bundle.ref.size>this.options.maximumBytes)throw new X("Bundle artifact exceeds its byte limit.");let r=e.schema.bundle.href;vr(r,this.options.policy);let i=await Er(t,(s)=>this.options.fetch(r,{headers:{accept:e.schema.bundle.ref.mediaType},redirect:"manual",signal:s}));if(ND(i,r,"Bundle retrieval"),!i.ok)throw new X(`Bundle retrieval returned HTTP ${i.status}.`);if(i.headers.get("content-type")!==e.schema.bundle.ref.mediaType)throw new X("Bundle artifact media type differs from its descriptor.");let n=i.headers.get("etag");if(n!==null&&n!==`"${e.schema.bundle.ref.digest}"`)throw new X("Bundle response ETag differs from its descriptor.");let o=await Er(t,(s)=>TD(i,e.schema.bundle.ref.size,s));if(o.byteLength!==e.schema.bundle.ref.size)throw new X("Bundle artifact size differs from its descriptor.");return er.decodeBundle(e,o)}}function Y8(e){return`${new URL(e.schema.bundle.href).origin}\x00${e.etag}`}function jD(e,t,r){let i=e.bindings.views.map((a)=>{vr(a.href,r);let c=t.root.views[ne.member(Z.ref(a.view))];if(c===void 0)throw new X("Published View has no verified root declaration.");return Object.freeze({key:a.view,declaration:c,href:a.href,handshake:a.handshake,issuer:e.identity.issuer,etag:e.etag,revision:e.schema.revision})}).sort((a,c)=>Q8(a.key,c.key)),n=Object.freeze(i),o=e.manifest?.entrypoint,s=o===void 0?void 0:n.find(({key:a})=>a===Z.of(e.origin,o));if(o!==void 0&&s===void 0)throw new X("Published View entrypoint has no verified Publication binding.");return Object.freeze({...s===void 0?{}:{entrypoint:s},views:n})}function PD(e,t){let r;try{r=et.view.acceptResolution(e)}catch(i){throw new X("Resolved View catalog is invalid.",{cause:i})}for(let i of r.views)vr(i.href,t);return Object.freeze({views:r.views})}function Q8(e,t){return e<t?-1:e>t?1:0}async function LD(e,t,r,i){let n=q.from(r).raw;return t(await e(tr(ge.View.resolve.path,{target:n}),i))}function o1(e,t,r,i){return Object.freeze({kernel:e,publication:t,bundle:r,views:i})}class zD{kernel;policy;publications;bundles;requireOpen;acquisitionOperation;retained;flight;constructor(e,t,r,i,n,o){this.kernel=e,this.policy=t,this.publications=r,this.bundles=i,this.requireOpen=n,this.acquisitionOperation=o}snapshot(e){this.requireOpen();let t=this.flight;if(t!==void 0)return Er(e,()=>t);let r=this.acquireSnapshot(this.acquisitionOperation());return this.flight=r,r.finally(()=>{if(this.flight===r)this.flight=void 0}).catch(()=>{return}),Er(e,()=>r)}clear(){this.publications.invalidate(),this.bundles.clear(),this.retained=void 0}async acquireSnapshot(e){let t=this.publications.current(),r=await this.publications.revalidate(e);if(t!==void 0&&t.etag!==r.etag)this.bundles.clear();let i=await this.bundles.get(r,e);if(this.requireOpen(),this.retained?.publication.etag===r.etag)return this.retained;let n=jD(r,i,this.policy),o=o1(this.kernel,r,i,n);return this.retained=o,o}}function s1(e){return new zD(e.kernel,e.policy,new $D({kernel:e.kernel,fetch:e.fetch,policy:e.policy,maximumBytes:e.maximumPublicationBytes}),new RD({fetch:e.fetch,policy:e.policy,maximumBytes:e.maximumBundleBytes}),e.requireOpen,e.acquisitionOperation)}function MD(e){if(e===void 0)return;if(e===null||typeof e!=="object"||typeof e.resolve!=="function")throw TypeError("Session auth resolver is invalid.");if(!Number.isSafeInteger(e.ttlSeconds)||e.ttlSeconds<1)throw TypeError("Session auth ttlSeconds must be a positive safe integer.");return Object.freeze({ttlSeconds:e.ttlSeconds,resolve:e.resolve.bind(e)})}async function UD(e,t,r){if(e===void 0)return Object.freeze({});let i=await Er(r,(a)=>e.resolve(t,a));if(i===null||typeof i!=="object"||Array.isArray(i))throw new X("Session auth resolver returned an invalid value.");if(Reflect.ownKeys(i).some((a)=>a!=="credential"&&a!=="delegate"))throw new X("Session auth resolver returned unsupported fields.");let o=i.credential;if(o!==void 0&&(typeof o!=="string"||o.length===0))throw new X("Session auth resolver returned an invalid credential.");if(o===void 0&&i.delegate!==void 0)throw new X("Session delegation overrides require a source credential.");if(o===void 0)return Object.freeze({});let s=i.delegate===void 0?me.acceptDelegate({ttlSeconds:e.ttlSeconds}):me.acceptDelegate(i.delegate);return Object.freeze({credential:o,delegate:s})}class _B{maximumAgeMs;maximumSize;entries=new Map;constructor(e,t=OD){this.maximumAgeMs=e,this.maximumSize=t}async key(e,t,r,i){let n=r.credential===void 0?"anonymous":await a1(r.credential),o=r.delegate===void 0?"anonymous":await a1(X8(r.delegate));return JSON.stringify([e,t.target,n,o,i===void 0?null:[i.schema,i.publication===void 0?null:[i.publication.origin,i.publication.revision,i.publication.etag]]])}get(e,t=Date.now()){let r=this.entries.get(e);if(r===void 0)return;if(r.expiresAt<=t){this.entries.delete(e);return}return this.entries.delete(e),this.entries.set(e,r),r}learn(e,t,r,i=Date.now()){let n=r===void 0?void 0:eZ(r),o=Math.min(i+this.maximumAgeMs,n??Number.POSITIVE_INFINITY),s=Object.freeze({route:t,...r===void 0?{}:{credential:r},expiresAt:o});if(r!==void 0&&n===void 0)return s;if(o<=i)return s;this.entries.delete(e);while(this.entries.size>=this.maximumSize){let a=this.entries.keys().next().value;if(a===void 0)break;this.entries.delete(a)}return this.entries.set(e,s),s}delete(e){this.entries.delete(e)}clear(){this.entries.clear()}}function X8(e){return JSON.stringify({ttlSeconds:e.ttlSeconds,...e.attenuation===void 0?{}:{attenuation:DB(e.attenuation)}})}function DB(e){if(e.kind==="identity")return"self"in e?{kind:"identity",self:!0}:{kind:"identity",credential:e.credential};if(e.kind==="exclude")return{kind:"exclude",base:DB(e.base),excluded:e.excluded.map(DB)};return{kind:e.kind,operands:e.operands.map(DB)}}async function a1(e){if(globalThis.crypto?.subtle===void 0)throw TypeError("Session route caching requires Web Crypto SHA-256 support.");let t=await globalThis.crypto.subtle.digest("SHA-256",new TextEncoder().encode(e));return[...new Uint8Array(t)].map((r)=>r.toString(16).padStart(2,"0")).join("")}function eZ(e){let t=e.split(".");if(t.length!==3)return;try{let r=t[1].replace(/-/gu,"+").replace(/_/gu,"/"),i="=".repeat((4-r.length%4)%4),n=tZ(r+i),o=JSON.parse(n);return typeof o.exp==="number"&&Number.isSafeInteger(o.exp)&&o.exp>0?o.exp*1000:void 0}catch{return}}function tZ(e){if(typeof globalThis.atob==="function"){let t=globalThis.atob(e);return new TextDecoder().decode(Uint8Array.from(t,(r)=>r.charCodeAt(0)))}throw TypeError("Session route caching requires base64 decoding support.")}function c1(e,t,r,i,n){let o;if(t==="websocket"){if(e.websocket===void 0)throw new X("Callable does not advertise a WebSocket endpoint.");if(!r)throw new X("No WebSocket implementation is available.");vr(e.websocket,n),o=Object.freeze({transport:"websocket",url:e.websocket})}else if(t==="auto"&&e.websocket!==void 0&&r)vr(e.http,n),vr(e.websocket,n),o=Object.freeze({transport:"auto",endpoints:Object.freeze({http:e.http,websocket:e.websocket})});else vr(e.http,n),o=Object.freeze({transport:"http",url:e.http});let s=i.clientFor(o);if(s===null||typeof s!=="object"||typeof s.dispatch!=="function"||typeof s.as!=="function"||typeof s.close!=="function")throw TypeError("Session client pool capability returned an invalid Client.");return Object.freeze({client:s,destination:o})}class kB{state;constructor(e){this.state=e}async dispatch(e,t,r,i){this.state.requireOpen();let n=bl(e),o=await UD(this.state.auth,n,r),s=await this.sourceKernel(r),a=await this.state.cache.key(s.issuer,n,o,i),c=Object.freeze({call:n,auth:o,source:s,cacheKey:a,...i===void 0?{}:{expected:i}}),u=this.state.cache.get(a);if(u!==void 0)return this.dispatchDestinationWithRecovery(u,c,t,r);let l=await this.dispatchSource(c,void 0,t,r);return this.followSource(l,c,t,r)}async dispatchSource(e,t,r,i){this.state.requireOpen(),vr(this.state.sourceEndpoint,this.state.policy);let n=this.state.pool.clientFor(Object.freeze({transport:"http",url:this.state.sourceEndpoint}));return Er(i,()=>l1(n,e.auth.credential).dispatch(e.call,{...OB(i,r.idempotencyKey),...e.auth.delegate===void 0?{}:{delegate:e.auth.delegate},...t===void 0?{}:{routing:t},...e.expected===void 0?{}:{schema:e.expected.schema}}))}async followSource(e,t,r,i){if(e.kind!=="redirect")return e;let n=e.redirect;if(n.route.via.issuer!==t.source.issuer)throw new X("Redirect issuer differs from the session-pinned source Kernel identity.");u1(n.route,t.expected);let o=this.state.cache.learn(t.cacheKey,n.route,n.credential);return this.dispatchDestinationWithRecovery(o,t,r,i,n.trace)}async dispatchDestinationWithRecovery(e,t,r,i,n){try{return await this.dispatchDestination(e,t.call,r,i,t.expected,n)}catch(o){let s=cD(o),a=aD(o);if(rZ(o))throw this.state.cache.delete(t.cacheKey),o;if(!s&&!a)throw o;if(this.state.cache.delete(t.cacheKey),!i.claimRecovery())throw o;let c=s?Object.freeze({kind:"refresh",stale:e.route.via.publication.etag}):void 0,u=await this.dispatchSource(t,c,r,i);return this.followSource(u,t,r,i)}}async dispatchDestination(e,t,r,i,n,o){if(e.route.via.issuer!==(await this.sourceKernel(i)).issuer)throw new X("Learned route issuer differs from the session-pinned source Kernel.");u1(e.route,n);let s=c1(e.route.endpoint,this.state.envelopeTransport,this.state.websocketAvailable,this.state.pool,this.state.policy),a={...OB(i,r.idempotencyKey),routing:e.route.via},c=await Er(i,()=>o===void 0?l1(s.client,e.credential).dispatch(t,a):uD(s.client,e.credential,t,a,o));if(c.kind==="redirect")throw new X("A destination redirect is invalid; only the source Kernel may redirect.");return c}async sourceKernel(e){let t=await this.state.discovery.snapshot(e);if(t.kernel!==this.state.kernel)throw new X("Session discovery returned another Kernel identity.");return Object.freeze({issuer:t.publication.identity.issuer})}}function rZ(e){if(!(e instanceof zt))return!1;let t=me.serviceErrorOf({code:e.code,message:e.message,...e.data===void 0?{}:{data:e.data}});return t?.data.code===me.SCHEMA_UPGRADE_REQUIRED||t?.data.code===me.SERVICE_TRUST_REQUIRED}function u1(e,t){if(t===void 0)return;if(t.publication===void 0)throw new X("A local bound installation cannot resolve to a remote route.");let r=e.via.publication,i=er.compareReferences(r,t.publication);if(i!=="exact"&&i!=="same-schema")throw new X("Resolved route does not match the bound installed Publication.")}function tc(e,t){if(t.kind===e)return t;if(t.kind==="stream")t.stream.cancel(`Expected ${e} result.`);throw new X(`Function returned ${t.kind}; ${e} was required.`)}function l1(e,t){return t===void 0?e:e.as(t)}function SB(e={}){if(e===null||typeof e!=="object"||Array.isArray(e))throw TypeError("Session request options are invalid.");let t=ec(e);if(Reflect.ownKeys(e).some((n)=>!["signal","timeoutMs","idempotencyKey"].includes(String(n))))throw TypeError("Session request options contain unsupported fields.");let i=e.idempotencyKey===void 0?void 0:me.acceptIdempotencyKey(e.idempotencyKey,"request.idempotencyKey");return Object.freeze({...t,...i===void 0?{}:{idempotencyKey:i}})}function FD(e){if(e!=="auto"&&e!=="http"&&e!=="websocket")throw TypeError("Session envelope transport is invalid.");return e}var ONe=Object.freeze({maximumRouteAgeMs:60000}),f1=new WeakMap;function GD(e,t,r,i){let n=f1.get(e);if(n===void 0)throw TypeError("Bound dispatch requires an owned ClientSession.");return n(t,r,i)}class rc{kernel;schema;ownedPool;discovery;dispatcher;lifecycle=new AbortController;timeoutMs;routes;admitTargetViews;closed=!1;constructor(e){if(e===null||typeof e!=="object")throw TypeError("ClientSession options are invalid.");let t=kD(e.policy);this.admitTargetViews=(f)=>PD(f,t),this.kernel=SD(e.kernel,t.allowInsecureHttp===!0);let r=AD(this.kernel),i=e.fetch??globalThis.fetch;if(typeof i!=="function")throw TypeError("ClientSession requires Fetch.");let n=e.fetch===void 0?i.bind(globalThis):i;if(e.client!==void 0&&e.pool!==void 0)throw TypeError("ClientSession accepts either client or pool, not both.");let o=mo(e.maximumPublicationBytes??vD,"maximumPublicationBytes"),s=mo(e.maximumBundleBytes??xD,"maximumBundleBytes"),a=mo(e.maximumResponseBytes??wD,"maximumResponseBytes"),c=wl(e.timeoutMs??ID,"timeoutMs");this.timeoutMs=c;let u=e.client!==void 0||e.pool!==void 0||e.websocket!==void 0||typeof globalThis.WebSocket==="function",l=e.client??iZ({fetch:n,...e.websocket===void 0?{}:{websocket:e.websocket},...e.onWarning===void 0?{}:{onWarning:e.onWarning},maximumResponseBytes:a,timeoutMs:c}),d;if(e.pool===void 0){let f=new IB({client:l});this.ownedPool=f,d=d1(f)}else d=d1(e.pool);this.discovery=s1({kernel:this.kernel,fetch:n,policy:t,maximumPublicationBytes:o,maximumBundleBytes:s,requireOpen:()=>this.requireOpen(),acquisitionOperation:()=>this.operation(void 0)}),this.routes=new _B(t.maximumRouteAgeMs),this.dispatcher=new kB({kernel:this.kernel,sourceEndpoint:r,pool:d,websocketAvailable:u,auth:MD(e.auth),cache:this.routes,policy:t,envelopeTransport:FD(e.envelopeTransport??"http"),discovery:this.discovery,requireOpen:()=>this.requireOpen()}),this.schema=ED((f,m)=>this.dispatch(f,m),{maximumPublicationBytes:o,maximumBundleBytes:s}),f1.set(this,(f,m,B)=>{let h=SB(B);return this.dispatcher.dispatch(f,h,this.operation(h),m)})}snapshot(e){return this.discovery.snapshot(this.operation(ec(e)))}viewsFor(e,t){return this.requireOpen(),LD(async(r,i)=>tc("value",await this.dispatcher.dispatch(r,{},i)).value,this.admitTargetViews,e,this.operation(ec(t)))}async installed(e,t){let r=await this.schema.introspect({from:{kind:"installation",origin:e},select:{state:!0,target:!0,source:!0,bundle:!0,readiness:!0,capabilities:!0}},t);if(r?.state!=="ready"||r.readiness===null)throw new X(`Domain ${e} is not ready on this Kernel.`);return r}dispatch(e,t){let r=SB(t);return this.dispatcher.dispatch(e,r,this.operation(r))}async call(e,t){let r=await this.dispatch(e,t);return tc("value",r).value}async stream(e,t){let r=await this.dispatch(e,t);return tc("stream",r).stream}async binary(e,t){let r=await this.dispatch(e,t);return tc("binary",r).value}close(){if(this.closed)return;this.closed=!0,this.lifecycle.abort(new X("ClientSession is closed.")),this.ownedPool?.close(),this.routes.clear(),this.discovery.clear()}requireOpen(){if(this.closed)throw new X("ClientSession is closed.")}operation(e){return this.requireOpen(),_D(this.lifecycle.signal,e,this.timeoutMs)}}function d1(e){if(e===null||typeof e!=="object"||typeof e.clientFor!=="function")throw TypeError("Session client pool capability is invalid.");return Object.freeze({clientFor:(t)=>nZ(e.clientFor.call(e,t))})}function nZ(e){if(e===null||typeof e!=="object"||typeof e.dispatch!=="function"||typeof e.as!=="function"||typeof e.close!=="function")throw TypeError("Session client pool capability returned an invalid Client.");return e}function iZ(e){return(t)=>{switch(t.transport){case"http":return new gs({transport:new xi({url:t.url,fetch:e.fetch,timeoutMs:e.timeoutMs,maximumResponseBytes:e.maximumResponseBytes})});case"websocket":return new gs({transport:new Cs({url:t.url,timeoutMs:e.timeoutMs,maximumResponseBytes:e.maximumResponseBytes,...e.websocket===void 0?{}:{websocket:e.websocket}})});case"auto":return new gs({transport:new xl({endpoints:t.endpoints,fetch:e.fetch,timeoutMs:e.timeoutMs,maximumResponseBytes:e.maximumResponseBytes,...e.websocket===void 0?{}:{websocket:e.websocket},...e.onWarning===void 0?{}:{onWarning:e.onWarning}})})}}}async function p1(e,t,r,i,n){return HD(e,t,r,void 0,i,n)}async function m1(e,t,r,i,n,o){return HD(e,t,r,i,n,o)}function B1(e,t){return(r,i)=>(n)=>HD(e,t,r,q.id(i.id),n)}function h1(e){let t=new Map;for(let r of e.$.definitions.values()){if(r.kind==="function"){let i=r;t.set(i.key,i);continue}if(r.kind!=="class"&&r.kind!=="interface"||r.family!=="node")continue;for(let i of r.methods.values())if(i.definition.inheritance!=="abstract"){let n=i;t.set(n.key,n)}}return t}async function HD(e,t,r,i,n,o={}){let s=t.callables.get(r.key);if(s===void 0)throw new X("Callable is not a concrete member of the bound Domain root.");let a=i===void 0?s.path:s.on(q.from(i)),c=await GD(e,tr(a,n),t.bound,o);return oZ(s,c)}function oZ(e,t){let r=e.definition.output.mode;switch(r){case"value":if(t.kind==="value")return t.value;break;case"stream":if(t.kind==="stream")return t.stream;break;case"binary":if(t.kind==="binary")return t.value;break}return sZ(r,t)}function sZ(e,t){if(t.kind==="stream")t.stream.cancel(`Remote callable declared ${e} output.`);throw new X(`Remote callable declared ${e} output but returned ${t.kind}.`)}function VD(e,t,r,i){return i===void 0?e.$.wrap(r,t):e.$.wrap(r,i,t)}function Il(e,t,r){let i=aZ(r??t),n=i.source.kind==="remote"?i.source.publication:void 0,o=r===void 0?i.bundle.root:t;if(n!==void 0)cZ(o,n);if(o.origin!==i.bundle.root.origin||Y.revision(o)!==Y.revision(i.bundle.root))throw TypeError("Expected Domain schema does not match the installed schema Bundle.");let s=Ha.fromSchema(o),a=Object.freeze({callables:h1(s),bound:Object.freeze({schema:n===void 0?Object.freeze({target:i.target}):Object.freeze({revision:Y.revision(o)}),...n===void 0?{}:{publication:er.reference(n)}})}),c=B1(e,a),u=(f,m,B,h)=>("on"in f)?m1(e,a,f,m,B,h):p1(e,a,f,m,B),l=(f,m)=>m===void 0?VD(s,c,f):VD(s,c,f,m),d={...s,$:Object.freeze({...s.$,installed:i,...n===void 0?{}:{publication:n},invoke:u,bind:l})};return Object.freeze(d)}function aZ(e){if(e===null||typeof e!=="object"||Array.isArray(e))throw TypeError("Installed Domain evidence is invalid.");if(e.state!=="ready"||e.readiness===null)throw TypeError("Installed Domain is not ready.");if(e.source.kind==="remote"){let t=er.accept(e.source.publication),r=er.acceptBundle(t,e.bundle);return Object.freeze({...e,source:Object.freeze({kind:"remote",publication:t}),bundle:r})}return e}function cZ(e,t){if(e.origin!==t.origin||Y.revision(e)!==t.schema.revision)throw TypeError("Expected Domain schema does not match the target Publication revision.")}var uZ=q.project(et.mutate.ref).raw;async function g1(e,t,r){let i=typeof t==="function"?eo.build(t):lZ(t),n=await e(tr(uZ,i),r);return pm.decode(n)}function lZ(e){return"format"in e?eo.decode(e):("operations"in e)?eo.create(e):eo.fromGraph(e)}function dZ(e){if(!bs(e))ft("","Query source input must be an object");let t=e.kind;if(t==="node")return fZ(e);if(t==="edge")return pZ(e);ft("/kind","Query source kind must be node or edge")}function Dl(e){let t;try{t=Pe(e)}catch(r){ft("/predicate/property","Invalid PropertyKey",r)}return Object.freeze({equals(r){return Object.freeze({kind:"property.equal",property:t,value:mZ(r)})},isPresent(){return Object.freeze({kind:"property.present",property:t})}})}var $r=Object.freeze({from:dZ});function fZ(e){Wn(e,["kind","paths","definitions","binding"],"","Node source input");let t=$B(e.paths,"/source/paths"),r=$B(e.definitions,"/source/definitions"),i=[];t.forEach((s,a)=>{try{i.push(Object.freeze({kind:"path",path:q.from(s).raw}))}catch(c){ft(`/source/paths/${a}`,"Invalid Path source",c)}}),r.forEach((s,a)=>{i.push(Object.freeze({kind:"definition",definition:TB(s,`/source/definitions/${a}`)}))});let n=e.binding===void 0?"n0":e.binding,o=Ot.decode({format:Ot.format,version:Ot.version,source:{kind:"node",terms:i,binding:n},steps:[],select:{kind:"graph",binding:n}});if(o.source.kind!=="node")ft("/source/kind","Node source was not retained");return AB(Object.freeze({source:o.source,steps:o.steps,node:o.source.binding}))}function pZ(e){Wn(e,["kind","definitions","bindings"],"","Edge source input");let r=$B(e.definitions,"/source/definitions").map((u,l)=>Object.freeze({kind:"definition",definition:TB(u,`/source/definitions/${l}`)})),i=new Set,n=e.bindings;if(n!==void 0&&!bs(n))ft("/source/bindings","Edge source bindings must be an object");if(n!==void 0)Wn(n,["source","edge","target"],"/source/bindings","Edge source bindings");for(let u of[n?.source,n?.edge,n?.target])if(typeof u==="string")i.add(u);let o=n?.source??Ol("n",i);i.add(o);let s=n?.edge??Ol("e",i);i.add(s);let a=n?.target??Ol("n",i),c=Ot.decode({format:Ot.format,version:Ot.version,source:{kind:"edge",terms:r,bindings:{source:o,edge:s,target:a}},steps:[],select:{kind:"graph",binding:s}});if(c.source.kind!=="edge")ft("/source/kind","Edge source was not retained");return y1(Object.freeze({source:c.source,steps:c.steps,edge:c.source.bindings.edge}))}function AB(e){if(e.node===void 0)ft("","Node builder has no current Node binding");let t={node:e.node,filter(i){return AB(qD(e,i,e.node))},expand(i){return b1(e,i)},select(i){return E1(e,i)}};if(e.edge===void 0)return Object.freeze(t);let r={...t,edge:e.edge,filter(i){return AB(qD(e,i,e.node))}};return Object.freeze(r)}function y1(e){if(e.source.kind!=="edge")ft("","Edge builder has no Edge source");let t=e.source.bindings;return Object.freeze({source:t.source,edge:t.edge,target:t.target,filter(r){return y1(qD(e,r,void 0))},expand(r){return b1(e,r)},select(r){return E1(e,r)}})}function qD(e,t,r){let i=`/steps/${e.steps.length}`;if(!bs(t))ft(i,"Filter input must be an object");let n=t,o=t.binding===void 0?r:t.binding;if(o===void 0)ft(`${i}/binding`,"Filter binding is required");let s;if(Object.hasOwn(t,"satisfies"))Wn(t,["binding","satisfies"],i,"Definition filter input"),s={op:"filter",binding:o,predicate:{kind:"definition.satisfies",definition:TB(n.satisfies,`${i}/satisfies`)}};else if(Object.hasOwn(t,"predicate"))Wn(t,["binding","predicate"],i,"Property filter input"),s={op:"filter",binding:o,predicate:n.predicate};else ft(i,"Filter input must contain satisfies or a Property predicate");let a=v1(e,s);return Object.freeze({source:a.source,steps:a.steps,...e.node===void 0?{}:{node:e.node},...e.edge===void 0?{}:{edge:e.edge}})}function mZ(e){try{return C1(te.decode(te.encode(e)))}catch(t){ft("/predicate/value","Invalid portable equality value",t)}}function C1(e){if(e===null||typeof e!=="object")return e;for(let t of Object.values(e))C1(t);return Object.freeze(e)}function b1(e,t){let r=`/steps/${e.steps.length}`;if(!bs(t))ft(r,"Expand input must be an object");Wn(t,["from","via","direction","bindings"],r,"Expand input");let i=BZ(e),n,o;if(t.bindings===void 0){let c=Ol("e",i);n=c,i.add(c),o=Ol("n",i)}else if(bs(t.bindings))Wn(t.bindings,["edge","node"],`${r}/bindings`,"Expand bindings"),n=t.bindings.edge,o=t.bindings.node;else ft(`/steps/${e.steps.length}/bindings`,"Expand bindings must be an object");let s=v1(e,{op:"expand",from:t.from===void 0?e.node===void 0?ft(`${r}/from`,"Expansion from an Edge source requires a Node binding"):e.node:t.from,via:$B(t.via,`${r}/via`).map((c,u)=>TB(c,`${r}/via/${u}`)),direction:t.direction,bindings:{edge:n,node:o}}),a=s.steps.at(-1);if(a?.op!=="expand")ft(`/steps/${e.steps.length}`,"Expand was not retained");return AB(Object.freeze({source:s.source,steps:s.steps,node:a.bindings.node,edge:a.bindings.edge}))}function E1(e,t){if(!bs(t))ft("/select","Select input must be an object");let r=t.kind,i=(()=>{if(r==="graph")return Wn(t,["kind","binding","order"],"/select","Graph select input"),{kind:r,binding:t.binding===void 0?e.node??e.edge??ft("/select/binding","Selection binding is required"):t.binding,...t.order===void 0?{}:{order:t.order}};if(r==="nodes")return Wn(t,["kind","binding","projection","order"],"/select","Node select input"),{kind:r,binding:t.binding===void 0?e.node??ft("/select/binding","Node selection binding is required"):t.binding,projection:t.projection,...t.order===void 0?{}:{order:t.order}};if(Wn(t,["kind","binding","projection","order"],"/select","Edge select input"),e.edge===void 0&&t.binding===void 0)ft("/select/binding","Edge selection requires an introduced Edge binding");return{kind:r,binding:t.binding===void 0?e.edge:t.binding,projection:t.projection,...t.order===void 0?{}:{order:t.order}}})();return Ot.decode({format:Ot.format,version:Ot.version,source:e.source,steps:e.steps,select:i})}function v1(e,t){let r=e.node??e.edge;if(r===void 0)ft("/select/binding","Query prefix has no selectable binding");return Ot.decode({format:Ot.format,version:Ot.version,source:e.source,steps:[...e.steps,t],select:{kind:"graph",binding:r}})}function BZ(e){let t=e.source.kind==="node"?new Set([e.source.binding]):new Set([e.source.bindings.source,e.source.bindings.edge,e.source.bindings.target]);for(let r of e.steps){if(r.op!=="expand")continue;t.add(r.bindings.edge),t.add(r.bindings.node)}return t}function Ol(e,t){for(let r=0;r<=t.size;r++){let i=`${e}${r}`;if(!t.has(i))return i}throw TypeError("No collision-free Query binding is available.")}function $B(e,t){if(e===void 0)return[];if(!Array.isArray(e))ft(t,"Expected an array");return e}function TB(e,t){if(!bs(e))ft(t,"Definition input must be an object");if(typeof e.origin!=="string"||e.kind!=="class"&&e.kind!=="interface"||typeof e.name!=="string")ft(t,"Definition input must contain origin, kind, and name");return Object.freeze({origin:e.origin,kind:e.kind,name:e.name})}function bs(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}function Wn(e,t,r,i){let n=Object.keys(e).find((o)=>!t.includes(o));if(n!==void 0)ft(`${r}/${hZ(n)}`,`${i} contains an unsupported field`)}function hZ(e){return e.replaceAll("~","~0").replaceAll("/","~1")}function ft(e,t,r){throw new bn(e,t,r===void 0?void 0:{cause:r})}class Bo extends TypeError{path;code="QUERY_REFERENCE_INVALID";constructor(e,t,r){super(`${t} at ${e||"/"}.`,r);this.path=e,this.name="QueryReferenceError"}}var w1=Object.freeze({evaluate(e,t,r){try{if(!Number.isSafeInteger(r.size)||r.size<1)ve("/size","Reference page size must be a positive safe integer");let i=Yo(e),n=_Z(t);return gZ(i,n,r)}catch(i){if(i instanceof Bo)throw i;if(i instanceof bn)throw new Bo(i.path,"Invalid QueryAST for reference evaluation",{cause:i});throw new Bo("","Reference evaluation failed",{cause:i})}}});function gZ(e,t,r){let i=new T1(t),n=new A1(t),o=new $1(t),s,a,c=[],u=new Map;if(e.source.kind==="node"){let f=e.source,m=new Map;f.terms.forEach((B,h)=>{let g=`/source/terms/${h}`;if(B.kind==="path"){yZ(B.path,g,t,i,m);return}let w=n.close(B.definition,"node",`${g}/definition`);for(let b of t.graph.nodes)if(w.has(b.class)&&i.node(b,`${g}/definition`))m.set(b.id,b)}),s=[...m.values()].map((B)=>new Map([[f.binding,{kind:"node",value:B}]])),a=m.size,u.set(f.binding,"node")}else{let f=e.source,m=new Set;f.terms.forEach((h,g)=>{for(let w of n.close(h.definition,"edge",`/source/terms/${g}/definition`))m.add(w)});let B=new Map;for(let h of t.graph.edges){if(!m.has(h.class))continue;let g=ln(t,h.source,"/source"),w=ln(t,h.target,"/source");if(i.edge(h,"/source")&&i.node(g,"/source")&&i.node(w,"/source"))B.set(Ge(h),h)}s=[...B.values()].sort(Cr).map((h)=>{let g=new Map;return g.set(f.bindings.source,{kind:"node",value:ln(t,h.source,"/source")}),g.set(f.bindings.edge,{kind:"edge",value:h}),g.set(f.bindings.target,{kind:"node",value:ln(t,h.target,"/source")}),g}),a=B.size,u.set(f.bindings.source,"node"),u.set(f.bindings.edge,"edge"),u.set(f.bindings.target,"node")}e.steps.forEach((f,m)=>{let B=`/steps/${m}`;if(f.op==="filter"){if(f.predicate.kind==="definition.satisfies"){let b=u.get(f.binding);if(b===void 0)ve(`${B}/binding`,"Filter binding is unavailable");let O=n.close(f.predicate.definition,b,`${B}/predicate/definition`);s=s.filter((k)=>O.has(_l(k,f.binding,`${B}/binding`).value.class))}else if(f.predicate.kind==="identity.equal"){let b=f.predicate;s=s.filter((O)=>{let k=_l(O,f.binding,`${B}/binding`);return k.kind==="node"?typeof b.identity==="string"&&k.value.id===b.identity:typeof b.identity!=="string"&&Ge(k.value)===Ge(b.identity)})}else{let b=f.predicate;s=s.filter((O)=>{let k=_l(O,f.binding,`${B}/binding`);if(!o.close(b.property,k.kind,`${B}/predicate/property`).has(k.value.class))return!1;if(!(k.kind==="node"?i.readNode(k.value,`${B}/binding`):i.readEdge(k.value,`${B}/binding`)))return!1;if(!Object.hasOwn(k.value.props,b.property))return!1;return b.kind==="property.present"||Nr(k.value.props[b.property],b.value)})}c.push(s.length);return}let h=new Map;f.via.forEach((b,O)=>{let k=n.close(b,"edge",`${B}/via/${O}`);for(let G of k){let oe=ho(`${B}/via/${O}`,"Edge Class orientation could not be resolved",()=>t.orientation(G));if(oe!=="directed"&&oe!=="undirected")ve(`${B}/via/${O}`,"Definition closes to a non-Edge Class");h.set(G,oe)}});let g=[...t.graph.edges].sort(Cr),w=[];for(let b of s){let O=S1(b,f.from,`${B}/from`);for(let k of g){let G=h.get(k.class);if(G===void 0)continue;let oe=OZ(k,O.id,G,f.direction);if(oe===void 0)continue;let V=t.nodes.get(oe);if(V===void 0)ve(B,`Expansion Edge endpoint ${JSON.stringify(oe)} is absent from graph`);if(!i.node(O,B)||!i.edge(k,B)||!i.node(V,B))continue;let _e=new Map(b);_e.set(f.bindings.edge,{kind:"edge",value:k}),_e.set(f.bindings.node,{kind:"node",value:V}),w.push(_e)}}s=w,c.push(s.length),u.set(f.bindings.edge,"edge"),u.set(f.bindings.node,"node")});let l=u.get(e.select.binding);if(l===void 0)ve("/select/binding","Selected binding is unavailable");if(e.select.kind==="nodes"&&l!=="node")ve("/select/binding","Node selection requires a Node binding");if(e.select.kind==="edges"&&l!=="edge")ve("/select/binding","Edge selection requires an Edge binding");let d=l==="node"?bZ(s,e.select,r.size,r.after,i,o):EZ(s,e.select,r.size,r.after,t,i,o);return Object.freeze({...d,trace:Object.freeze({sourceRows:a,stepRows:Object.freeze(c)})})}function yZ(e,t,r,i,n){let o=ho(`${t}/path`,"Path resolution failed",()=>r.resolve(e));if(!Array.isArray(o))ve(`${t}/path`,"Path resolver must return an array");let s=new Map;if(o.forEach((d,f)=>{let m=`${t}/path/witnesses/${f}`,B=CZ(d,m,r),h=s.get(B.result);if(h===void 0)s.set(B.result,[B]);else h.push(B)}),s.size!==1)return;let a=s.entries().next().value;if(a===void 0)return;let[c,u]=a,l=!1;if(u.forEach((d,f)=>{let m=`${t}/path/witnesses/${f}`,B=!0;for(let h of d.nodes)B=i.node(ln(r,h,m),m)&&B;for(let h of d.edges)B=i.edge(N1(r,h,m),m)&&B;l=l||B}),l)n.set(c,ln(r,c,t))}function CZ(e,t,r){if(!nc(e)||!Sl(e,["result","nodes","edges"]))ve(t,"Path witness must contain exactly result, nodes, and edges");let i=kl(e.result,`${t}/result`);if(!Array.isArray(e.nodes))ve(`${t}/nodes`,"Witness nodes must be an array");if(!Array.isArray(e.edges))ve(`${t}/edges`,"Witness edges must be an array");let n=e.nodes.map((a,c)=>kl(a,`${t}/nodes/${c}`));RB(n,(a)=>a,`${t}/nodes`,"NodeId");let o=e.edges.map((a,c)=>R1(a,`${t}/edges/${c}`));RB(o,Ge,`${t}/edges`,"EdgeKey");let s=new Set(n);if(!s.has(i))ve(`${t}/result`,"Path result is absent from witness nodes");return n.forEach((a)=>ln(r,a,t)),o.forEach((a,c)=>{if(N1(r,a,`${t}/edges/${c}`),!s.has(a.source)||!s.has(a.target))ve(`${t}/edges/${c}`,"Path Edge endpoints are absent from witness nodes")}),Object.freeze({result:i,nodes:Object.freeze(n),edges:Object.freeze(o)})}function bZ(e,t,r,i,n,o){let s=new Map;e.forEach((B)=>{let h=S1(B,t.binding,"/select/binding");if((t.kind==="graph"||t.kind==="nodes"&&t.projection.kind==="value")&&!n.readNode(h,"/select/binding"))return;s.set(h.id,h)});let a=t.order,c=I1(a,"node",o),u=[...s.values()].sort(c).filter((B)=>i===void 0||O1(i,B,a,"node",o)<0),l=u.slice(0,r),d=t.kind==="nodes"?ds({kind:"nodes",nodes:l.map((B)=>JD(B,t.projection.kind))}):ds({kind:"graph",graph:{nodes:[...l].sort((B,h)=>At(B.id,h.id)),edges:[]},selection:{kind:"node",ids:l.map((B)=>B.id)}}),f=u.length>r?l.at(-1):void 0,m=f===void 0?void 0:D1(f,a,"node",o);return Object.freeze({result:d,...m===void 0?{}:{next:m}})}function EZ(e,t,r,i,n,o,s){let a=new Map;e.forEach((w)=>{let b=DZ(w,t.binding,"/select/binding"),O=ln(n,b.source,"/select/binding"),k=ln(n,b.target,"/select/binding");if(!o.edge(b,"/select/binding")||!o.node(O,"/select/binding")||!o.node(k,"/select/binding"))return;if(!(t.kind==="graph"?o.readEdge(b,"/select/binding")&&o.readNode(O,"/select/binding")&&o.readNode(k,"/select/binding"):t.kind==="edges"?(t.projection.edge==="reference"||o.readEdge(b,"/select/binding"))&&(t.projection.source==="reference"||o.readNode(O,"/select/binding"))&&(t.projection.target==="reference"||o.readNode(k,"/select/binding")):!1))return;a.set(Ge(b),b)});let c=t.order,u=I1(c,"edge",s),l=[...a.values()].sort(u).filter((w)=>i===void 0||O1(i,w,c,"edge",s)<0),d=l.slice(0,r),f=new Set;d.forEach((w)=>{f.add(w.source),f.add(w.target)});let m=[...f].sort(At).map((w)=>ln(n,w,"/select/binding")),B=t.kind==="edges"?ds({kind:"edges",edges:d.map((w)=>({edge:IZ(w,t.projection.edge),source:JD(ln(n,w.source,"/select/binding"),t.projection.source),target:JD(ln(n,w.target,"/select/binding"),t.projection.target)}))}):ds({kind:"graph",graph:{nodes:m,edges:[...d].sort(Cr)},selection:{kind:"edge",keys:d.map(it)}}),h=l.length>r?d.at(-1):void 0,g=h===void 0?void 0:D1(h,c,"edge",s);return Object.freeze({result:B,...g===void 0?{}:{next:g}})}function I1(e,t,r){return(i,n)=>_1(NB(i,e,t,r),NB(n,e,t,r),e)}function O1(e,t,r,i,n){let o=vZ(e,r,i,n);return _1(o,NB(t,r,i,n),r)}function D1(e,t,r,i){let n=NB(e,t,r,i);if(n.bucket==="ranked")return Object.freeze({bucket:"ranked",value:n.value,identity:n.identity});return Object.freeze({bucket:n.bucket,identity:n.identity})}function NB(e,t,r,i){let n="id"in e?e.id:it(e);if(t===void 0)return Object.freeze({bucket:"identity",identity:n});let o=i.close(t.property,r,"/select/order/property"),s=i.ordering(t.property,r,"/select/order/property");if(!o.has(e.class)||!Object.hasOwn(e.props,t.property))return Object.freeze({bucket:"unranked",identity:n});let a=e.props[t.property];if(!k1(a,s))ve("/select/order/property","Ordered Property value is outside its declared ordering domain");return Object.freeze({bucket:"ranked",value:a,identity:n})}function vZ(e,t,r,i){if(!nc(e))ve("/after","Frontier must be an object");let n=e.bucket==="ranked"?["bucket","identity","value"]:["bucket","identity"];if(!Sl(e,n))ve("/after","Frontier has an invalid shape");let o=r==="node"?kl(e.identity,"/after/identity"):R1(e.identity,"/after/identity");if(t===void 0){if(e.bucket!=="identity")ve("/after/bucket","Unordered frontier bucket is invalid");return Object.freeze({bucket:"identity",identity:o})}if(e.bucket==="unranked")return Object.freeze({bucket:"unranked",identity:o});let s=i.ordering(t.property,r,"/select/order/property");if(e.bucket!=="ranked"||!k1(e.value,s))ve("/after","Ordered frontier is invalid");return Object.freeze({bucket:"ranked",value:e.value,identity:o})}function _1(e,t,r){if(r===void 0)return x1(e.identity,t.identity);if(e.bucket!==t.bucket)return e.bucket==="unranked"?r.unranked==="first"?-1:1:r.unranked==="first"?1:-1;if(e.bucket==="ranked"&&t.bucket==="ranked"){let i=typeof e.value==="boolean"?"boolean":typeof e.value==="number"?"number":"string",n=xZ(e.value,t.value,i);if(n!==0)return r.direction==="asc"?n:-n}return x1(e.identity,t.identity)}function x1(e,t){if(typeof e==="string"&&typeof t==="string")return At(e,t);if(typeof e!=="string"&&typeof t!=="string")return Cr(e,t);ve("/after/identity","Frontier identity kind disagrees with selection")}function k1(e,t){if(t==="boolean")return typeof e==="boolean";if(t==="number")return typeof e==="number"&&Number.isFinite(e);return typeof e==="string"}function xZ(e,t,r){if(r==="boolean")return Number(e)-Number(t);if(r==="number")return e-t;return wZ(e,t)}function wZ(e,t){let r=Array.from(e,(n)=>n.codePointAt(0)),i=Array.from(t,(n)=>n.codePointAt(0));for(let n=0;n<Math.min(r.length,i.length);n+=1)if(r[n]!==i[n])return r[n]-i[n];return r.length-i.length}function JD(e,t){return t==="value"?Object.freeze({kind:"value",value:e}):Object.freeze({kind:"reference",value:Object.freeze({id:e.id,class:e.class})})}function IZ(e,t){return t==="value"?Object.freeze({kind:"value",value:e}):Object.freeze({kind:"reference",value:it(e)})}function OZ(e,t,r,i){if(r==="undirected"||i==="incident"){if(e.source===t)return e.target;if(e.target===t)return e.source;return}if(i==="outgoing")return e.source===t?e.target:void 0;return e.target===t?e.source:void 0}function S1(e,t,r){let i=_l(e,t,r);if(i?.kind!=="node")ve(r,"Binding does not contain a Node");return i.value}function DZ(e,t,r){let i=_l(e,t,r);if(i?.kind!=="edge")ve(r,"Binding does not contain an Edge");return i.value}function _l(e,t,r){let i=e.get(t);if(i===void 0)ve(r,"Binding is unavailable");return i}class A1{context;#e=new Map;constructor(e){this.context=e}close(e,t,r){let i=`${t}\x00${e.origin}\x00${e.kind}\x00${e.name}`,n=this.#e.get(i);if(n!==void 0)return n;let o=ho(r,"Definition closure failed",()=>this.context.closeDefinition(e));if(o===void 0||!nc(o)||!Sl(o,["family","classes"]))ve(r,"Definition is unresolved");if(o.family!=="node"&&o.family!=="edge"&&o.family!=="both"||o.family!==t&&o.family!=="both")ve(r,`Definition is not ${t}-capable`);if(!Array.isArray(o.classes))ve(`${r}/classes`,"Classes must be an array");let s=o.classes.map((c,u)=>KD(c,`${r}/classes/${u}`));RB(s,(c)=>c,`${r}/classes`,"ClassPath");let a=new Set(s);return this.#e.set(i,a),a}}class $1{context;#e=new Map;#t=new Map;constructor(e){this.context=e}close(e,t,r){let i;try{i=Pe(e)}catch(l){ve(r,"PropertyKey is invalid",l)}let n=`${t}\x00${i}`,o=this.#e.get(n);if(o!==void 0)return o;let s=ho(r,"Property closure failed",()=>this.context.closeProperty(i));if(s===void 0||!nc(s)||!Sl(s,s.ordering===void 0?["nodes","edges"]:["nodes","edges","ordering"]))ve(r,"Property is unresolved");if(s.ordering!==void 0&&s.ordering!=="boolean"&&s.ordering!=="number"&&s.ordering!=="string"&&s.ordering!=="instant")ve(`${r}/ordering`,"Property ordering domain is invalid");let a=s[t==="node"?"nodes":"edges"];if(!Array.isArray(a))ve(r,"Property Classes must be an array");let c=a.map((l,d)=>KD(l,`${r}/classes/${d}`));RB(c,(l)=>l,`${r}/classes`,"ClassPath");let u=new Set(c);return this.#e.set(n,u),this.#t.set(i,s.ordering),u}ordering(e,t,r){this.close(e,t,r);let i=this.#t.get(e);if(i===void 0)ve(r,"Property has no supported ordering domain");return i}}class T1{context;#e=new Map;#t=new Map;#r=new Map;#n=new Map;constructor(e){this.context=e}node(e,t){let r=this.#e.get(e.id);if(r!==void 0)return r;let i=ho(t,"Node traversal admission failed",()=>this.context.traverseNode(e));if(typeof i!=="boolean")ve(t,"Node traversal admission must return boolean");let n=i||this.readNode(e,t);return this.#e.set(e.id,n),n}edge(e,t){let r=Ge(e),i=this.#t.get(r);if(i!==void 0)return i;let n=ho(t,"Edge traversal admission failed",()=>this.context.traverseEdge(e));if(typeof n!=="boolean")ve(t,"Edge traversal admission must return boolean");let o=n||this.readEdge(e,t);return this.#t.set(r,o),o}readNode(e,t){let r=this.#r.get(e.id);if(r!==void 0)return r;let i=ho(t,"Node read admission failed",()=>this.context.readNode(e));if(typeof i!=="boolean")ve(t,"Node read admission must return boolean");return this.#r.set(e.id,i),i}readEdge(e,t){let r=Ge(e),i=this.#n.get(r);if(i!==void 0)return i;let n=ho(t,"Edge read admission failed",()=>this.context.readEdge(e));if(typeof n!=="boolean")ve(t,"Edge read admission must return boolean");return this.#n.set(r,n),n}}function _Z(e){if(!nc(e))ve("","Reference context must be an object");for(let r of["resolve","closeDefinition","closeProperty","orientation","traverseNode","traverseEdge","readNode","readEdge"])if(typeof e[r]!=="function")ve(`/${r}`,`Reference ${r} must be callable`);let t;try{t=Hu.decode(e.graph)}catch(r){ve("/graph","Reference graph is invalid",r)}return Object.freeze({graph:t,nodes:new Map(t.nodes.map((r)=>[r.id,r])),edges:new Map(t.edges.map((r)=>[Ge(r),r])),resolve:e.resolve.bind(e),closeDefinition:e.closeDefinition.bind(e),closeProperty:e.closeProperty.bind(e),orientation:e.orientation.bind(e),traverseNode:e.traverseNode.bind(e),traverseEdge:e.traverseEdge.bind(e),readNode:e.readNode.bind(e),readEdge:e.readEdge.bind(e)})}function ln(e,t,r){let i=e.nodes.get(t);if(i===void 0)ve(r,`Node ${JSON.stringify(t)} is absent from reference graph`);return i}function N1(e,t,r){let i=e.edges.get(Ge(t));if(i===void 0)ve(r,"Edge is absent from reference graph");return i}function kl(e,t){if(typeof e!=="string")ve(t,"Expected NodeId string");try{return Fe(e)}catch(r){ve(t,"Invalid NodeId",r)}}function KD(e,t){if(typeof e!=="string")ve(t,"Expected ClassPath string");try{return Ze.parse(e)}catch(r){ve(t,"Invalid ClassPath",r)}}function R1(e,t){if(!nc(e)||!Sl(e,["source","target","class"]))ve(t,"EdgeKey must contain exactly source, target, and class");return Object.freeze({source:kl(e.source,`${t}/source`),target:kl(e.target,`${t}/target`),class:KD(e.class,`${t}/class`)})}function RB(e,t,r,i){let n=new Set;e.forEach((o,s)=>{let a=t(o);if(n.has(a))ve(`${r}/${s}`,`Duplicate ${i}`);n.add(a)})}function ho(e,t,r){try{return r()}catch(i){ve(e,t,i)}}function Sl(e,t){let r=Object.keys(e);return r.length===t.length&&r.every((i)=>t.includes(i))}function nc(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}function ve(e,t,r){throw new Bo(e,t,r===void 0?void 0:{cause:r})}function ZD(e,t,r,i,n){let{result:o}=r,s=o.graph.nodes,a=r.page.next??null,c=async(l)=>{if(a===null)return null;let d={...i,...l?.signal===void 0?{}:{signal:l.signal},...l?.timeoutMs===void 0?{}:{timeoutMs:l.timeoutMs},page:{size:l?.size??n,after:a}},f=await e(t,d);if(f.result.kind!=="graph"||f.result.selection.kind!=="node")throw TypeError("Node page continuation returned a non-Node graph result.");return ZD(e,t,f,i,l?.size??n)},u={nodes:s,first:s[0]??null,graph:o.graph,cursor:a,next:c,async collect(l){kZ(l.maximumPages);let d=[...s],f=u,m=1;while(f.cursor!==null&&m<l.maximumPages){let B=await f.next({...l.size===void 0?{}:{size:l.size},...l.signal===void 0?{}:{signal:l.signal},...l.timeoutMs===void 0?{}:{timeoutMs:l.timeoutMs}});if(B===null)break;d.push(...B.nodes),f=B,m+=1}return Object.freeze({nodes:Object.freeze(d),cursor:f.cursor})}};return Object.freeze(u)}function kZ(e){if(!Number.isSafeInteger(e)||e<1)throw TypeError("NodePage maximumPages must be a positive safe integer.")}async function WD(e,t,r,i){if(i===null||typeof i!=="object")throw TypeError("Neighbor read options are invalid.");let n=Array.isArray(r)?r:[r],[o,...s]=n;if(o===void 0)throw TypeError("Neighbor read requires at least one Definition.");let a=i.direction==="outgoing"?i.direction:i.direction==="incoming"?i.direction:i.direction==="incident"?i.direction:SZ(i.direction),c=$r.from({kind:"node",paths:[t]}).expand({via:[o,...s],direction:a}).select({kind:"graph"}),{direction:u,page:l,...d}=i,{idempotencyKey:f,...m}=d,B=await e(c,{...d,page:l});if(B.result.kind!=="graph"||B.result.selection.kind!=="node")throw TypeError("Neighbor query returned a non-Node graph result.");return ZD(e,c,B,m,l.size)}function SZ(e){throw TypeError(`Unsupported neighbor direction ${JSON.stringify(e)}.`)}var AZ=q.project(et.query.ref).raw;async function jB(e,t,r){let i=Ot.decode(t),{page:n,...o}=r,s=$Z(n),a=await e(tr(AZ,Object.freeze({ast:i,page:s})),o);return TZ(a)}function $Z(e){if(e===null||typeof e!=="object"||Array.isArray(e))throw TypeError("Graph query page is invalid.");if(!Number.isSafeInteger(e.size)||e.size<1)throw TypeError("Graph query page size must be a positive safe integer.");if(e.after!==void 0&&(typeof e.after!=="string"||e.after.length===0))throw TypeError("Graph query page continuation is invalid.");return Object.freeze({size:e.size,...e.after===void 0?{}:{after:e.after}})}function TZ(e){if(e===null||typeof e!=="object"||Array.isArray(e))throw TypeError("Graph query response is invalid.");let t=e;if(!j1(t,["result","page"]))throw TypeError("Graph query response is invalid.");let r=t.page;if(r===null||typeof r!=="object"||Array.isArray(r))throw TypeError("Graph query response page is invalid.");let i=r;if(!j1(i,i.next===void 0?[]:["next"]))throw TypeError("Graph query response page is invalid.");if(i.next!==void 0&&(typeof i.next!=="string"||i.next.length===0))throw TypeError("Graph query response continuation is invalid.");return Object.freeze({result:ol.decode(t.result),page:Object.freeze(i.next===void 0?{}:{next:i.next})})}function j1(e,t){let r=Object.keys(e);return r.length===t.length&&r.every((i)=>t.includes(i))}class PB extends X{code="NODE_UNAVAILABLE";path;constructor(e){let t=q.from(e).raw;super(`Node ${JSON.stringify(t)} is unavailable.`);this.name="NodeUnavailableError",this.path=t}}async function YD(e,t,r){let i=$r.from({kind:"node",paths:[t]}).select({kind:"graph"}),n=await jB(e,i,{...r,page:{size:1}}),{result:o}=n;if(o.kind!=="graph")throw TypeError("Node read returned a projection result.");return o.graph.nodes[0]??null}async function P1(e,t,r){let i=await YD(e,t,r);if(i===null)throw new PB(t);return i}function QD(e){if(typeof e!=="function")throw TypeError("Graph call capability is invalid.");let t=(i,n)=>jB(e,i,n);return Object.freeze({query:t,mutate:(i,n)=>g1(e,i,n),get:(i,n)=>YD(e,i,n),getOrThrow:(i,n)=>P1(e,i,n),neighbors:(i,n,o)=>WD(t,i,n,o)})}function ic(e){if(e===null||typeof e!=="object")throw TypeError("Kernel client adapter options are invalid.");let t=e.session,r=t.snapshot.bind(t),i=t.installed.bind(t),n=t.viewsFor.bind(t),o=t.call.bind(t),s=t.stream.bind(t),a=t.binary.bind(t),c=t.close.bind(t),u=NZ(e.graph??e.store?.graph??QD((b,O)=>o(b,O))),l=RZ(e.auth??gD((b,O,k)=>o(tr(b,O),k))),d=e.store,f=new Map,m=!1;function B(){if(m)throw Error("Kernel client adapter is closed.")}function h(b){if(B(),b===void 0)return r().then((G)=>{let oe=`${G.publication.origin}\x00${G.publication.schema.revision}`;return g(oe,async()=>Il(t,await i(G.publication.origin)))});let O=`${b.origin}\x00${Y.revision(b)}`,k=f.get(O);if(k!==void 0)return k;return g(O,async()=>Il(t,b,await i(b.origin)))}function g(b,O){let k=f.get(b);if(k!==void 0)return k;let G=O();return f.set(b,G),G.catch(()=>{if(f.get(b)===G)f.delete(b)}),G}let w={url:t.kernel,session:t,graph:u,auth:l,...d===void 0?{}:{store:d},snapshot(b){return B(),r(b)},viewsFor(b,O){return B(),n(b,O)},domain:h,call(b,O){return B(),o(b,O)},stream(b,O){return B(),s(b,O)},binary(b,O){return B(),a(b,O)},close(){if(m)return;m=!0,f.clear();try{d?.close()}finally{c()}}};return Object.freeze(w)}function NZ(e){return Object.freeze({query:e.query.bind(e),mutate:e.mutate.bind(e),get:e.get.bind(e),getOrThrow:e.getOrThrow.bind(e),neighbors:e.neighbors.bind(e)})}function RZ(e){return Object.freeze({provision:e.provision.bind(e),whoami:e.whoami.bind(e),whois:e.whois.bind(e),can:e.can.bind(e),mint:e.mint.bind(e),delegate:e.delegate.bind(e)})}var oc=120000;var Al=[1000,2000,4000],L1=2147483647;function LB(e){let t=e.now??Date.now,r=null,i=null,n=!1,o=null,s;function a(){if(n)return;if(r)clearTimeout(r);let f=e.token(),m=Math.max(f.expiresAt-t(),0),B=Math.min(oc,Math.floor(m/2)),h=Math.min(Math.max(m-B,1),L1);c(f.expiresAt),r=setTimeout(()=>{r=null,l()},h)}function c(f){if(i)clearTimeout(i);let m=Math.min(Math.max(f-t(),0),L1);i=setTimeout(()=>{if(i=null,n)return;if(e.token().expiresAt>t()){c(e.token().expiresAt);return}e.onFailure?.(s??Error("Delegated credential expired."))},m)}function u(){if(n||r!==null)return;let f=e.token().expiresAt-t();if(f<=0)return;r=setTimeout(()=>{r=null,l()},Math.min(f,Al[Al.length-1]))}function l(){if(o!==null)return o;return o=d().finally(()=>{o=null}),o}async function d(){if(n)return;e.onRefreshing?.();let f;for(let m=0;m<=Al.length;m+=1){if(n)return;try{let B=jZ(await e.mint(),t());if(n)return;e.setToken({credential:B.credential,expiresAt:B.expiresAt,issuedAt:t(),scope:{functionId:e.functionId}}),s=void 0,a();return}catch(B){if(f=B,s=B,m<Al.length)await PZ(Al[m])}}if(!n)e.onFailure?.(f),u()}return{start(){n=!1,a()},stop(){if(n=!0,r)clearTimeout(r);if(r=null,i)clearTimeout(i);i=null},async forceRefreshNow(){await l()},async refreshIfNeeded(){if(e.token().expiresAt-t()>oc)return;await l()}}}function jZ(e,t){if(typeof e.credential!=="string"||e.credential.trim().length===0||!Number.isSafeInteger(e.expiresAt)||e.expiresAt<=t)throw TypeError("Refreshed credential must be nonempty with a future safe expiry.");return e}function PZ(e){return new Promise((t)=>setTimeout(t,e))}function $l(e){let{observer:t,onDeliveryFailed:r}=e,i=t.notify.bind(t),n=new Map,o=new Map,s=new Set,a=!1;function c(u,l){let d=o.get(l.type);if(!d||d.size===0)return;for(let f of d)try{f(u,l)}catch{}}return{attach(u,l){if(a)throw Error("Children channel is disposed");if(u.length===0)throw TypeError("windowId must not be empty");if(n.get(u))throw Error(`Child '${u}' already attached`);let f=l.close.bind(l),m=l.onMessage.bind(l),B=l.send.bind(l),h=()=>{},g={send:B,close:f,unsubscribe:()=>h()};n.set(u,g);try{h=m((w)=>{if(n.get(u)!==g)return;i("inbound",w),c(u,w)})}catch(w){throw n.delete(u),f(),w}},detach(u){let l=n.get(u);if(!l)return;n.delete(u),l.unsubscribe(),l.close();for(let d of s)try{d(u)}catch{}},dispose(){if(a)return;a=!0;for(let u of n.values())u.unsubscribe(),u.close();n.clear(),o.clear(),s.clear()},send(u,l){let d=n.get(u);if(!d){r?.(u,l);return}i("outbound",l),d.send(l)},on(u,l){if(a)return()=>{};let d=o.get(u);if(!d)d=new Set,o.set(u,d);return d.add(l),()=>{d.delete(l)}},has(u){return n.has(u)},onClose(u){if(a)return()=>{};return s.add(u),()=>{s.delete(u)}}}}function sc(e){let{port:t,onClose:r}=e,i=t.postMessage.bind(t),n=t.addEventListener.bind(t),o=t.removeEventListener.bind(t),s=t.start.bind(t),a=t.close.bind(t),c=!1,u=new Set,l=(m)=>{if(c)return;if(typeof m!=="object"||m===null||!("data"in m)){f();return}let B;try{B=oh(m.data)}catch{f();return}for(let h of u)try{h(B)}catch{}},d=()=>{if(c)return;f()};n("message",l),n("messageerror",d),s();function f(){if(c)return;c=!0,o("message",l),o("messageerror",d),u.clear();try{a()}catch{}r?.()}return{send(m){if(c)return;i(m)},onMessage(m){if(c)return()=>{};return u.add(m),()=>{u.delete(m)}},close:f}}function Tl(){let e=new Set;return{notify(t,r){if(e.size===0)return;for(let i of e)try{i(r,t)}catch{}},subscribe(t){return e.add(t),()=>{e.delete(t)}}}}function z1(){let e=new Map;return{on(t,r){let i=e.get(t);if(!i)i=new Set,e.set(t,i);return i.add(r),()=>{i.delete(r)}},dispatch(t){let r=e.get(t.type);if(!r||r.size===0)return;for(let i of r)try{i(t)}catch{}},clear(){e.clear()}}}function XD(e){let{transport:t,observer:r}=e,i=t.close.bind(t),n=t.onMessage.bind(t),o=t.send.bind(t),s=r.notify.bind(r),a=z1(),c=!1,u=n((l)=>{if(c)return;s("inbound",l),a.dispatch(l)});return{send(l){if(c)return;s("outbound",l),o(l)},on(l,d){if(c)return()=>{};return a.on(l,d)},dispose(){if(c)return;c=!0,u(),a.clear(),i()}}}function zB(e,t){switch(e){case"opening":if(t.kind==="forceClose")return{ok:!0,next:"closed"};break;case"ready":if(t.kind==="hide")return{ok:!0,next:"suspended"};if(t.kind==="requestClose")return{ok:!0,next:"closing"};if(t.kind==="forceClose")return{ok:!0,next:"closed"};break;case"suspended":if(t.kind==="restore")return{ok:!0,next:"ready"};if(t.kind==="requestClose")return{ok:!0,next:"closing"};if(t.kind==="forceClose")return{ok:!0,next:"closed"};break;case"closing":if(t.kind==="closeAck")return{ok:!0,next:"closed"};if(t.kind==="closeRefuse")return{ok:!0,next:"ready"};if(t.kind==="forceClose")return{ok:!0,next:"closed"};break;case"closed":case"failed":break}return{ok:!1,reason:`invalid transition ${e}.${t.kind}`}}function Nl(e=()=>{}){let t=new Map;return{register(r,i="ready"){if(t.has(r))return;t.set(r,i)},apply(r,i){let n=t.get(r);if(n===void 0)return null;let o=zB(n,i);if(!o.ok)return null;return t.set(r,o.next),e(r,o.next),o.next},markCrashed(r){let i=t.get(r);if(i===void 0||i==="closed"||i==="failed")return;t.set(r,"failed"),e(r,"failed")},remove(r){t.delete(r)}}}var MZ={allowScripts:!0,allowForms:!1,allowPopups:!1,allowPopupsToEscapeSandbox:!1,allowSameOrigin:!1,allowModals:!1};function MB(e={}){return{resolve(t){return new URL(t,window.location.href)},decidePresentation(t){if(!(window.innerWidth<640)||t.preferred==="modal"||t.preferred==="window")return Object.freeze({kind:t.preferred,constrained:!1});let i=t.fallback?.find((n)=>n==="modal"||n==="inline");return Object.freeze({kind:i??"modal",constrained:!0})},focus(t){t.element.focus()},onActivation(t){let r=()=>{if(document.visibilityState!=="hidden")t()};return window.addEventListener("focus",r),document.addEventListener("visibilitychange",r),()=>{window.removeEventListener("focus",r),document.removeEventListener("visibilitychange",r)}},mount(t){if(t.isolation!=="sandboxed")throw Error(`iframe adapter only supports sandboxed windows, got '${t.isolation}'`);let r=document.createElement("iframe");if(r.dataset.astraleFunctionId=t.functionId,e.className)r.className=e.className;if(r.style.display="block",r.style.width="100%",r.style.height="100%",r.style.border="0",t.sandbox!==null){let n=t.sandbox??MZ;r.setAttribute("sandbox",UZ(n))}return r.setAttribute("loading","eager"),r.setAttribute("referrerpolicy","no-referrer"),{handle:{element:r,port:null,origin:""},dispose:()=>{r.remove()}}}}}function UZ(e){let t=[];if(e.allowScripts)t.push("allow-scripts");if(e.allowForms)t.push("allow-forms");if(e.allowPopups)t.push("allow-popups");if(e.allowPopupsToEscapeSandbox)t.push("allow-popups-to-escape-sandbox");if(e.allowSameOrigin)t.push("allow-same-origin");if(e.allowModals)t.push("allow-modals");return t.join(" ")}function Rl(e,t,r){let i=r,n=new Set;while(i!==void 0&&!n.has(i)){if(i===t)return!0;n.add(i),i=e.get(i)?.parentId}return!1}function M1(e){let{iframe:t,expectedOrigin:r,timeoutMs:i}=e,n=!1,o=!1,s=new Set,a,c,u=new Promise((B,h)=>{a=B,c=h}),l=setTimeout(()=>{if(o||n)return;o=!0,m(),c({code:"HANDSHAKE_TIMEOUT",message:`handshake timed out after ${i}ms`})},i);function d(B){if(o)return;o=!0,clearTimeout(l),m(),c(B)}function f(B){if(n||B.source!==t.contentWindow||!Kl(B.data))return;if(B.origin!==r){d({code:"ORIGIN_MISMATCH",message:`expected origin ${r}, got ${B.origin}`,actual:B.origin,expected:r});return}let h=new MessageChannel,g=h.port1;s.add(g);let w=setTimeout(()=>{if(s.delete(g),g.onmessage=null,g.close(),!o)d({code:"HANDSHAKE_TIMEOUT",message:`handshake timed out after ${i}ms`})},i);g.onmessage=(O)=>{try{uh(O.data,e.windowId)}catch{return}clearTimeout(w),s.delete(g),g.onmessage=null;let k={port:g};if(!o)o=!0,clearTimeout(l),a(k);else e.onReconnect(k)},g.start(),t.contentWindow?.postMessage({type:Bc,version:1,windowId:e.windowId},r,[h.port2]);let b=e.getCredential?.()??e;g.postMessage({type:"ctrl",version:1,action:"handshake",data:{delegationToken:b.delegationToken,tokenExpiresAt:b.tokenExpiresAt,windowId:e.windowId,kernelUrl:e.kernelUrl,functionId:e.functionId,targetNodeId:e.targetNodeId,mintIdentity:e.mintIdentity,capabilities:e.capabilities}})}function m(){if(n)return;n=!0,clearTimeout(l),window.removeEventListener("message",f);for(let B of s)B.onmessage=null,B.close();s.clear()}return window.addEventListener("message",f),{initial:u,dispose:m}}function ac(e,t){if(t!==void 0)return U1(t);return U1({target:e.target,view:e.route.key,params:{}})}function UB(e,t){let r=t.parentId===void 0?void 0:e.get(t.parentId);if(t.parentId!==void 0&&r===void 0)throw Error(`Parent window '${t.parentId}' is not live.`);let i=Object.freeze({windowId:t.windowId,...t.parentId===void 0?{}:{parentId:t.parentId},children:Object.freeze([]),functionId:t.view.route.key,targetNodeId:t.view.target,view:t.view,location:t.location,presentation:t.presentation,isolation:"sandboxed",state:t.state??"ready",credential:t.credential,capabilities:t.capabilities});if(e.set(t.windowId,i),r!==void 0)e.set(r.windowId,Object.freeze({...r,children:Object.freeze([...r.children,t.windowId])}));return i}function Es(e,t,r){let i=e.get(t);if(i===void 0)return;let n=Object.freeze(r(i));return e.set(t,n),n}function FB(e,t){let r=e.get(t);if(r===void 0)return;if(e.delete(t),r.parentId===void 0)return;let i=e.get(r.parentId);if(i===void 0)return;e.set(i.windowId,Object.freeze({...i,children:Object.freeze(i.children.filter((n)=>n!==t))}))}function U1(e){if(e===null||typeof e!=="object"||Array.isArray(e))throw TypeError("View location is invalid.");if(Object.keys(e).some((n)=>!["target","view","params"].includes(n)))throw TypeError("View location is invalid.");if(e.target!==void 0&&(typeof e.target!=="string"||e.target.length===0))throw TypeError("View location target is invalid.");if(e.view!==void 0&&(typeof e.view!=="string"||e.view.length===0))throw TypeError("View location key is invalid.");if(e.params===null||typeof e.params!=="object"||Array.isArray(e.params))throw TypeError("View location params are invalid.");let t=e.target===void 0?void 0:FZ(e.target),r=e.view===void 0?void 0:GZ(e.view),i=HZ(e.params);return Object.freeze({...t===void 0?{}:{target:t},...r===void 0?{}:{view:r},params:i})}function FZ(e){let t=q.parse(e);if(t.raw!==e)throw TypeError("View location target must be canonical.");return t.raw}function GZ(e){let t=Z(e);if(!Z.ref(t).startsWith("view."))throw TypeError("View location key is invalid.");return t}function HZ(e){let t=new WeakSet,r=(i,n)=>{if(n!==void 0&&/token|credential|authorization|secret/i.test(n))throw TypeError(`View location param '${n}' is sensitive.`);if(i===null||typeof i==="string"||typeof i==="boolean")return i;if(typeof i==="number"&&Number.isFinite(i))return i;if(typeof i!=="object"||ArrayBuffer.isView(i)||i instanceof ArrayBuffer)throw TypeError("View location params must be portable data.");if(t.has(i))throw TypeError("View location params cannot contain cycles.");t.add(i);try{if(Array.isArray(i))return Object.freeze(i.map((s)=>r(s)));let o=Object.getPrototypeOf(i);if(o!==Object.prototype&&o!==null)throw TypeError("View location params must be plain data.");return Object.freeze(Object.fromEntries(Object.entries(i).map(([s,a])=>[s,r(a,s)])))}finally{t.delete(i)}};return r(e)}var VZ=3000,qZ="<parent>";function F1(e){let{entries:t,children:r,windows:i,lifecycle:n}=e,o=async(s,a)=>{let c=t.get(s);if(!c)return{kind:"noop"};let u=a?.timeoutMs??VZ;if(!a?.force&&!c.plain){n.apply(s,{kind:"requestClose"});let d=await JZ(r,s,u);if(d.kind==="refused")return n.apply(s,{kind:"closeRefuse"}),{kind:"refused",reason:d.reason}}let l=i.get(s);for(let d of l?.children??[])await o(d,{force:!0,timeoutMs:u});return n.apply(s,{kind:"forceClose"}),c.refresher.stop(),t.delete(s),r.detach(s),FB(i,s),e.onWindowsChange?.(),c.dispose(),n.remove(s),{kind:"closed"}};return o}async function JZ(e,t,r){return new Promise((i)=>{let n=!1,o=e.on("intent",(a,c)=>{if(a!==t)return;if(c.envelope.name==="closeAck")n=!0,o(),clearTimeout(s),i({kind:"ack"});else if(c.envelope.name==="closeRefuse"){n=!0,o(),clearTimeout(s);let u=c.envelope.payload.reason;i({kind:"refused",reason:u})}}),s=setTimeout(()=>{if(n)return;o(),i({kind:"timeout"})},r);e.send(t,{type:"intent",version:1,envelope:{name:"willClose",payload:{},sender:{windowId:qZ}}})})}var jl={start:()=>{},stop:()=>{},forceRefreshNow:()=>Promise.resolve(),refreshIfNeeded:()=>Promise.resolve()};function G1(e){if(!Number.isSafeInteger(e.ttlSeconds)||e.ttlSeconds<1)throw TypeError("Delegation TTL must be a positive safe integer.");let t=async()=>{let n=await e.kernel.auth.mint({ttlSeconds:e.ttlSeconds});return e_({credential:n,expiresAt:Date.now()+e.ttlSeconds*1000})},r=e.provided;if(!r)return{acquire:t,refreshMint:t};let i=r.refresh?async()=>{let n=await r.refresh();return e_({credential:n.token,expiresAt:n.expiresAt})}:null;return{acquire:async()=>{let n={credential:r.token,expiresAt:r.expiresAt};if(i!==null&&(n.credential.length===0||n.expiresAt<=Date.now()))return await i();return e_(n)},refreshMint:i}}function e_(e){if(typeof e.credential!=="string"||e.credential.trim().length===0||!Number.isSafeInteger(e.expiresAt)||e.expiresAt<=Date.now())throw TypeError("Credential must be nonempty with a future safe expiry.");return Object.freeze(e)}function H1(e){let{windowId:t,refreshMint:r}=e;if(!r)return jl;let i=e.initial.expiresAt,n=e.initial.credential;return LB({functionId:e.functionId,token:()=>({credential:n,expiresAt:i,issuedAt:0,scope:{functionId:e.functionId}}),setToken:(o)=>{n=o.credential,i=o.expiresAt,e.onTokenChange?.(o),e.children.send(t,{type:"ctrl",version:1,action:"tokenRefresh",data:{delegationToken:o.credential,tokenExpiresAt:o.expiresAt}})},mint:r,onRefreshing:e.onRefreshing,onFailure:e.onFailure})}async function V1(e,t,r,i){let{adapter:n,windows:o,lifecycle:s,entries:a,close:c}=e,{route:u}=r.view,l=ac(r.view,r.location),d=i.presentation,{handle:f,dispose:m}=n.mount({functionId:u.key,isolation:"sandboxed",capabilities:r.capabilities,sandbox:r.sandbox});if(!(f.element instanceof HTMLIFrameElement))throw m(),Error("Shell adapter did not produce an HTMLIFrameElement");return r.host.appendChild(f.element),f.element.src=i.href,UB(o,{windowId:t,parentId:r.parentId,view:r.view,location:l,presentation:d,capabilities:r.capabilities,credential:Object.freeze({state:"none"})}),e.onWindowsChange?.(),s.register(t,"ready"),a.set(t,{handle:f,dispose:m,refresher:jl,plain:!0}),{windowId:t,get window(){return o.get(t)},handle:{element:f.element},credential:Object.freeze({state:"none"}),presentation:d,focus:()=>n.focus(f),close:(B)=>c(t,B)}}var KZ=5000,ZZ=3600,q1=Object.freeze({allowScripts:!0,allowForms:!1,allowPopups:!1,allowPopupsToEscapeSandbox:!1,allowSameOrigin:!0,allowModals:!1});function Pl(e){let{adapter:t,kernel:r,kernelUrl:i,mintIdentity:n,childrenChannel:o,windows:s,lifecycle:a}=e,c=t.resolve(i).href,u=new Map,l=0,d=!1,f=F1({entries:u,children:o,windows:s,lifecycle:a,onWindowsChange:e.onWindowsChange});function m(h){return l+=1,`win-${h.replace(/[^a-z0-9]/gi,"").slice(-8)||"fn"}-${l}`}return{async mount(h){if(d)throw Error("MountController is disposed");let{route:g,target:w}=h.view,b=g.key,O=t.resolve(g.href),k=O.href,G=g.handshake==="shell"?WZ(h.sandbox,O.origin,t.resolve("/").origin):h.sandbox,oe=ac(h.view,h.location),V=t.decidePresentation(h.presentation??{preferred:"inline"}),_e=h.parentId===void 0?e.parentCapabilities?.():s.get(h.parentId)?.capabilities;if(h.parentId!==void 0&&_e===void 0)throw Error(`Parent window '${h.parentId}' is not live.`);if(_e!==void 0)YZ(_e,O.origin,V.kind);let Mt=Tr(h.capabilities),pt=g.handshake==="none"?_i:_e===void 0?Mt:Wl(_e,Mt),Rt={...h,capabilities:pt,sandbox:G};if(g.handshake==="none"){let ct=m(b);return V1({adapter:t,windows:s,lifecycle:a,entries:u,close:f,onWindowsChange:e.onWindowsChange},ct,Rt,{href:k,presentation:V})}let xr=h.delegationTtlSeconds??ZZ,D=h.handshakeTimeoutMs??KZ,P=O.origin,R=m(b),{acquire:F,refreshMint:M}=G1({kernel:r,ttlSeconds:xr,provided:h.credential}),[{credential:de,expiresAt:fe},le]=await Promise.all([F(),Promise.resolve(t.mount({functionId:b,isolation:"sandboxed",capabilities:pt,sandbox:Rt.sandbox}))]),{handle:Ie,dispose:Se}=le;if(!(Ie.element instanceof HTMLIFrameElement))throw Se(),Error("Shell adapter did not produce an HTMLIFrameElement");UB(s,{windowId:R,parentId:h.parentId,view:h.view,location:oe,presentation:V,capabilities:pt,credential:Object.freeze({state:"none"}),state:"opening"}),e.onWindowsChange?.();let wt={delegationToken:de,tokenExpiresAt:fe},rr=0,Ht=jl;function Oi(ct){rr+=1;let Yr=rr;return sc({port:ct,onClose:()=>{if(Yr!==rr||!u.has(R))return;a.markCrashed(R),f(R,{force:!0}).catch(()=>{})}})}let Di=M1({iframe:Ie.element,expectedOrigin:P,windowId:R,delegationToken:de,tokenExpiresAt:fe,getCredential:()=>wt,kernelUrl:c,functionId:b,targetNodeId:w,mintIdentity:n,capabilities:pt,timeoutMs:D,onReconnect:({port:ct})=>{if(!u.has(R)){ct.close();return}let Yr=Oi(ct);o.detach(R),o.attach(R,Yr),Ht.refreshIfNeeded()}});h.host.appendChild(Ie.element),Ie.element.src=k;let vs;try{vs=await Di.initial}catch(ct){throw Di.dispose(),FB(s,R),e.onWindowsChange?.(),Se(),ct}let xs=Oi(vs.port);o.attach(R,xs),Es(s,R,(ct)=>({...ct,state:"ready",credential:Object.freeze({state:"valid",expiresAt:fe})})),e.onWindowsChange?.(),a.register(R,"ready"),Ht=H1({windowId:R,functionId:b,initial:{credential:de,expiresAt:fe},refreshMint:M,windows:s,children:o,onFailure:(ct)=>{Es(s,R,(Yr)=>Date.now()<wt.tokenExpiresAt?{...Yr,credential:Object.freeze({state:"degraded",expiresAt:wt.tokenExpiresAt,error:ct})}:{...Yr,credential:Object.freeze({state:"expired",error:ct,retry:()=>Ht.forceRefreshNow()})}),e.onWindowsChange?.()},onRefreshing:()=>{Es(s,R,(ct)=>({...ct,credential:Object.freeze({state:"refreshing",expiresAt:wt.tokenExpiresAt})})),e.onWindowsChange?.()},onTokenChange:(ct)=>{wt={delegationToken:ct.credential,tokenExpiresAt:ct.expiresAt},Es(s,R,(Yr)=>({...Yr,credential:Object.freeze({state:"valid",expiresAt:ct.expiresAt})})),e.onWindowsChange?.()}}),Ht.start();let yo=t.onActivation?.(()=>void Ht.refreshIfNeeded())??(()=>{});return u.set(R,{handle:Ie,dispose:()=>{yo(),Di.dispose(),Se()},refresher:Ht}),{windowId:R,get window(){return s.get(R)},handle:{element:Ie.element},get credential(){return s.get(R)?.credential??Object.freeze({state:"none"})},presentation:V,focus:()=>t.focus(Ie),close:(ct)=>f(R,ct)}},close:f,focus(h){let g=u.get(h),w=s.get(h);if(g===void 0||w===void 0||w.state!=="ready"&&w.state!=="suspended")return!1;return t.focus(g.handle),!0},async dispose(){if(d)return;d=!0;let h=[...u.keys()];await Promise.all(h.map((g)=>f(g,{force:!0})))}}}function WZ(e,t,r){if(t===r)throw TypeError("Shell-handshake Views must use a distinct origin so scripts cannot escape the origin-preserving sandbox.");if(e===null)throw TypeError("Shell-handshake Views cannot disable iframe sandboxing.");let i=e??q1;if(i.allowScripts!==!0||i.allowSameOrigin!==!0)throw TypeError("Shell-handshake Views require allowScripts and allowSameOrigin so the admitted route origin is observable.");for(let n of["allowScripts","allowForms","allowPopups","allowPopupsToEscapeSandbox","allowSameOrigin","allowModals"])if(typeof i[n]!=="boolean")throw TypeError("Shell-handshake sandbox flags must be boolean.");if(Object.keys(i).some((n)=>!["allowScripts","allowForms","allowPopups","allowPopupsToEscapeSandbox","allowSameOrigin","allowModals"].includes(n)))throw TypeError("Shell-handshake sandbox profiles are closed.");if(i.allowForms!==!1||i.allowPopups!==!1||i.allowPopupsToEscapeSandbox!==!1||i.allowModals!==!1)throw TypeError("Shell-handshake Views cannot grant forms, popups, modal dialogs, or sandbox escape outside typed host actions.");return q1}function YZ(e,t,r){let i=e.navigation.openView;if(i===void 0)throw Error("Host does not grant opening nested Views.");if(i.origins!==void 0&&!i.origins.includes(t))throw Error(`Host does not grant View origin '${t}'.`);if(i.presentations!==void 0&&!i.presentations.includes(r))throw Error(`Host does not grant '${r}' View presentation.`)}function cc(e){let{lookup:t,onViolation:r,selfWindowId:i}=e,n=e.allowSelf??!0;return async(o,s)=>{let a=o.envelope.sender.windowId;if(n&&i!==void 0&&a===i){await s();return}if(a==="<parent>"){await s();return}let c=t(a),u=o.envelope.name,d=e.credential?.(a)?.state==="expired"?"credential":c===void 0?"unsupported":n9(c,o,e);if(d!==!0){r?.({sender:a,intent:u,reason:d});return}await s()}}var XZ=new Set(["willClose","closeAck","closeRefuse","intentReply","setTarget"]),e9=new Set(["inline","panel","modal","window"]),t9=new Set(["info","success","warning","error"]),r9=4294967295;function n9(e,t,r){let i=t.envelope.name;if(XZ.has(i))return!0;switch(i){case"view.open":{let n=e.navigation.openView;if(n===void 0)return"unsupported";let o=t.envelope.payload;if(!J1(o))return"constraint";if(o.presentation!==void 0&&n.presentations!==void 0&&!n.presentations.includes(o.presentation))return"constraint";if(n.maximumDepth!==void 0&&(r.depth?.(t.envelope.sender.windowId)??1)>n.maximumDepth)return"constraint";return!0}case"view.close":case"view.focus":{let n=t.envelope.payload;if(!i9(i,n))return"constraint";let o=n.windowId;return typeof o==="string"&&r.owns?.(t.envelope.sender.windowId,o)===!0?!0:"constraint"}case"navigation.commit":{if(e.navigation.history===void 0)return"unsupported";let n=t.envelope.payload;if(!o9(n))return"constraint";let o=n.mode;if(o!=="push"&&o!=="replace")return"constraint";if(o==="replace"&&e.navigation.replace!==!0)return"constraint";return!0}case"actions.modal":{let n=e.actions.modal;if(n===void 0)return"unsupported";let o=t.envelope.payload;if(!u9(o))return"constraint";let s=o.nested;if(s===void 0)return!0;if(n.nestedViews!==!0)return"constraint";let a=e.navigation.openView;if(a===void 0)return"constraint";let c=s.presentation??"modal";if(a.presentations!==void 0&&!a.presentations.includes(c))return"constraint";if(a.maximumDepth!==void 0&&(r.depth?.(t.envelope.sender.windowId)??1)>a.maximumDepth)return"constraint";return!0}case"actions.notify":{let n=e.actions.notify;if(n===void 0)return"unsupported";let o=t.envelope.payload;if(!l9(o))return"constraint";return n.tones===void 0||n.tones.includes(o.tone)?!0:"constraint"}case"browser.openExternal":{let n=e.navigation.external;if(n===void 0)return"unsupported";let o=t.envelope.payload;if(!s9(o))return"constraint";try{let s=new URL(o.url);return s.protocol==="https:"&&n.origins.includes(s.origin)?!0:"constraint"}catch{return"constraint"}}case"access.request":{let n=e.access.request;if(n===void 0)return"unsupported";let o=t.envelope.payload;if(!a9(o))return"constraint";let s=o.permissions;return n.maximumPermissions===void 0||s.length<=n.maximumPermissions?!0:"constraint"}case"requestAccess":{let n=e.access.request;if(n===void 0)return"unsupported";let o=t.envelope.payload;if(!c9(o))return"constraint";let s=o.perms;if(!Number.isSafeInteger(s)||s<0||s>r9)return"constraint";return n.maximumPermissions===void 0||d9(s)<=n.maximumPermissions?!0:"constraint"}default:return"unsupported"}}function i9(e,t){if(!go(t,e==="view.close"?["windowId","force"]:["windowId"]))return!1;return typeof t.windowId==="string"&&t.windowId.length>0&&(e!=="view.close"||t.force===void 0||typeof t.force==="boolean")}function o9(e){if(!go(e,["mode","target","view","params"]))return!1;if(e.mode!=="push"&&e.mode!=="replace")return!1;if(e.target!==void 0&&!W1(e.target))return!1;if(e.view!==void 0&&!Z1(e.view))return!1;return K1(e.params)}function s9(e){return go(e,["url","mode"])&&typeof e.url==="string"&&(e.mode===void 0||e.mode==="tab"||e.mode==="popup")}function a9(e){if(!go(e,["node","identity","permissions","reason"]))return!1;return Ll(e.node)&&GB(e.node)&&Ll(e.identity)&&GB(e.identity)&&Array.isArray(e.permissions)&&e.permissions.every(Ll)&&(e.reason===void 0||typeof e.reason==="string")}function c9(e){return go(e,["node","identity","perms","reason"])&&Ll(e.node)&&GB(e.node)&&Ll(e.identity)&&GB(e.identity)&&typeof e.perms==="number"&&(e.reason===void 0||typeof e.reason==="string")}function J1(e){if(!go(e,["view","target","presentation","params"]))return!1;if(!Z1(e.view))return!1;if(e.target!==void 0&&!W1(e.target))return!1;if(e.presentation!==void 0&&(typeof e.presentation!=="string"||!e9.has(e.presentation)))return!1;return e.params===void 0||K1(e.params)}function u9(e){if(!go(e,["title","description","confirmLabel","cancelLabel","nested"]))return!1;if(typeof e.title!=="string"||e.title.length===0)return!1;for(let t of["description","confirmLabel","cancelLabel"])if(e[t]!==void 0&&typeof e[t]!=="string")return!1;return e.nested===void 0||J1(e.nested)}function l9(e){if(!go(e,["tone","title","description","dedupeKey"]))return!1;if(typeof e.tone!=="string"||!t9.has(e.tone))return!1;if(typeof e.title!=="string"||e.title.length===0)return!1;return(e.description===void 0||typeof e.description==="string")&&(e.dedupeKey===void 0||typeof e.dedupeKey==="string")}function go(e,t){return typeof e==="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).every((r)=>t.includes(r))}function K1(e){if(typeof e!=="object"||e===null||Array.isArray(e))return!1;let t=new WeakSet,r=(i,n)=>{if(n!==void 0&&/token|credential|authorization|secret/i.test(n))return!1;if(i===null||typeof i==="string"||typeof i==="boolean")return!0;if(typeof i==="number")return Number.isFinite(i);if(typeof i!=="object"||ArrayBuffer.isView(i)||i instanceof ArrayBuffer)return!1;if(t.has(i))return!1;t.add(i);try{if(Array.isArray(i))return i.every((s)=>r(s));let o=Object.getPrototypeOf(i);if(o!==Object.prototype&&o!==null)return!1;return Object.entries(i).every(([s,a])=>r(a,s))}finally{t.delete(i)}};return r(e)}function Ll(e){return typeof e==="string"&&e.length>0}function Z1(e){if(typeof e!=="string")return!1;try{let t=Z(e);return Z.ref(t).startsWith("view.")}catch{return!1}}function W1(e){if(typeof e!=="string")return!1;try{return q.parse(e).raw===e}catch{return!1}}function GB(e){try{return Fe(e)===e}catch{return!1}}function d9(e){let t=e>>>0,r=0;while(t!==0)t&=t-1,r+=1;return r}function uc(){let e=[];return{use(t){e.push(t)},async run(t,r){let i=-1,n=async(o)=>{if(o<=i)throw Error("next() called multiple times");if(i=o,o===e.length){await r();return}let s=e[o];await s(t,()=>n(o+1))};await n(0)}}}function Y1(){return(e,t)=>{if(t.origin==="self")return t.hasParent?{kind:"parent",message:e}:{kind:"local",message:e};return{kind:"local",message:e}}}function Q1(e,t){return{...e,envelope:{...e.envelope,sender:{windowId:t}}}}function lc(e){let{pipeline:t,parent:r,children:i,selfWindowId:n}=e,o=t.run.bind(t),s=r?.send.bind(r),a=i.has.bind(i),c=i.send.bind(i),u=Y1(),l=new Map;async function d(m){switch(m.kind){case"drop":return;case"parent":if(!s)return;s(m.message);return;case"child":if(!a(m.windowId))return;c(m.windowId,m.message);return;case"local":{let B=l.get(m.message.envelope.name);if(!B)return;for(let h of B)try{await h(m.message)}catch{}return}}}let f={selfWindowId:n,hasParent:s!==void 0};return{async handleInbound(m,B,h){if(h.length===0)throw TypeError("senderWindowId must not be empty");let g=Q1(B,h);await o(g,async()=>{let w=await u(g,{...f,origin:m});await d(w)})},async dispatchLocal(m){let B=Q1(m,n);await o(B,async()=>{let h=await u(B,{...f,origin:"self"});await d(h)})},setPolicy(m){u=m},onLocal(m,B){let h=l.get(m);if(!h)h=new Set,l.set(m,h);return h.add(B),()=>{h.delete(B)}}}}function HB(e,t,r,i){let n=r.envelope.correlationId;if(!n)return;e.send.bind(e)(t,{type:"intent",version:1,envelope:{name:"intentReply",payload:{correlationId:n,result:i},sender:{windowId:"root"}}})}function VB(e,t,r,i){let n=r.envelope.correlationId;if(!n)return;e.send.bind(e)(t,{type:"intent",version:1,envelope:{name:"intentReply",payload:{correlationId:n,error:{message:i instanceof Error?i.message:String(i)}},sender:{windowId:"root"}}})}var g9=new WeakMap,ez=Object.freeze({node(e,t){let r=$r.from({kind:"node",paths:[t]});return qB(e,r.filter({satisfies:e.schemaRef}),!1)},nodes(e){return qB(e,$r.from({kind:"node",definitions:[e.schemaRef]}),!0)}});function tz(e){if(!nz(e))return e;let t=e.compile();return g9.set(t,e),t}function rz(e){return nz(e)?e.many:void 0}function qB(e,t,r,i=t_(e),n=e){let s={...{current:i,...n===void 0?{}:{bindDefinition:n},builder:t,many:r,compile(){if(!("node"in t))throw TypeError("Node Query selection lost its node binding.");return t.select({kind:"nodes",projection:{kind:"value"}})},project(a,c){let u=a.nodes.map((l)=>n===void 0?c(l.value):c(n,l.value));return r?Object.freeze(u):u[0]??null}},__many:r,where(a){if(a===null||typeof a!=="object"||a.property===null||typeof a.property!=="object"||!("key"in a.property))throw TypeError("Node Query where requires one rich Property.");let c=Object.hasOwn(a,"equals"),u=a.present===!0;if(c===u)throw TypeError("Node Query where requires exactly one of equals or present.");let l=c?Dl(a.property.key).equals(a.equals):Dl(a.property.key).isPresent();return qB(e,t.filter({predicate:l}),r,i,n)},when(a,c){let u=s;return a===void 0||a===null||a===!1?u:c(u,a)},linked(a,c){if(c===null||typeof c!=="object"||c.to===void 0)throw TypeError("Node Query linked requires an accepted rich to definition.");let u=c?.from??y9(i,a);if(!JB(zl(a)[u].accepts,i))throw TypeError(`Relation ${a.key} does not accept the current selection at its ${u} endpoint.`);let l=t.expand({via:[a.schemaRef],direction:u==="source"?"outgoing":"incoming"}).filter({satisfies:c.to.schemaRef}),d=zl(a)[u==="source"?"target":"source"];if(!JB(d.accepts,t_(c.to)))throw TypeError(`Relation ${a.key} does not accept ${c.to.key} at its opposite endpoint.`);return Object.freeze({...qB(c.to,l,r||!b9(a,u),t_(c.to),c.to)})}};return Object.freeze(s)}function y9(e,t){let r=JB(zl(t).source.accepts,e),i=JB(zl(t).target.accepts,e);if(r===i)throw TypeError(r?`Relation ${t.key} accepts the current selection at both endpoints; declare from.`:`Relation ${t.key} does not accept the current selection.`);return r?"source":"target"}function JB(e,t){return e.some((r)=>t.some((i)=>C9(r,i)))}function t_(e){let t=[],r=new Set,i=(n)=>{let o=n.schemaRef,s=`${o.origin}\x00${o.kind}\x00${o.name}`;if(r.has(s))return;r.add(s),t.push(o);let a=n.kind==="class"?n.implements:n.extends;for(let c of a??[])i(c)};return i(e),Object.freeze(t)}function C9(e,t){return e.origin===t.origin&&e.kind===t.kind&&e.name===t.name}function b9(e,t){let r=zl(e)[t].count;return r==="1"||r==="0..1"}function zl(e){let t=e.definition;if(t.family!=="edge")throw TypeError(`Relation ${e.key} has no Edge endpoints.`);return t.orientation==="directed"?{source:{...t.endpoints.source,count:t.endpoints.source.outgoing},target:{...t.endpoints.target,count:t.endpoints.target.incoming}}:{source:{...t.endpoints[0],count:t.endpoints[0].incident},target:{...t.endpoints[1],count:t.endpoints[1].incident}}}function nz(e){return e!==null&&typeof e==="object"&&typeof e.compile==="function"}var iz=1024,E9=256;function v9(e){let t=e.build;return oz({...e,build(r){let i=t(r,ez);if(e.pagination!==void 0&&rz(i)===!1)throw TypeError("Node Query pagination requires an extent selection.");return tz(i)}},"single","build")}function x9(e){return oz(e,"composite","compose")}function oz(e,t,r){if(e===null||typeof e!=="object"||Array.isArray(e))throw TypeError("Query definition must be an object.");let i=e.id;if(typeof i!=="string"||i.length===0||i.trim()!==i)throw TypeError("Query definition id must be a non-empty stable string.");if(typeof e[r]!=="function")throw TypeError(`Query definition ${r} must be a function.`);for(let s of["prepare","project","reject"])if(e[s]!==void 0&&typeof e[s]!=="function")throw TypeError(`Query definition ${s} must be a function.`);let n=e.pagination;if(t==="composite"){if(Object.hasOwn(e,"page"))throw TypeError("Composite Query definitions cannot declare a page.");if(n!==void 0)throw TypeError("Composite Query definitions cannot declare pagination.");return Object.freeze({...e,kind:t})}let o=w9(e.page);if(n!==void 0){if(typeof e.project!=="function")throw TypeError("Paginated Query definitions must declare a project function.");if(n===null||typeof n!=="object"||Array.isArray(n)||Reflect.ownKeys(n).length!==1||!Object.hasOwn(n,"maximumPages"))throw TypeError("Query pagination must contain only maximumPages.");let s=n.maximumPages;if(!Number.isSafeInteger(s)||s<1||s>iz)throw TypeError(`Query pagination maximumPages must be a safe integer from 1 through ${iz}.`);return Object.freeze({...e,page:o,pagination:Object.freeze({maximumPages:s}),kind:t})}return Object.freeze({...e,page:o,kind:t})}function w9(e){if(e===void 0)return Object.freeze({size:E9});if(e===null||typeof e!=="object"||Array.isArray(e)||Reflect.ownKeys(e).length!==1||!Object.hasOwn(e,"size"))throw TypeError("Query page must contain only size.");let t=e.size;if(!Number.isSafeInteger(t)||t<1)throw TypeError("Query page size must be a positive safe integer.");return Object.freeze({size:t})}var I9=Object.assign(v9,{composite:x9});var $Pe=Symbol("astrale.sdk.query.plan"),TPe=Symbol("astrale.sdk.query.reference");function KB(e,t){if(e.kind==="graph")return A9(e,t);if(e.kind!=="nodes")throw TypeError(`Expected a Node ${t} query result.`);return Object.freeze(e.nodes.map((r)=>{if(r.kind!=="value")throw TypeError(`Expected ${t} query to project Node values.`);return r.value}))}function A9(e,t){if(e.selection.kind!=="node")throw TypeError(`Expected a Node ${t} query result.`);let r=new Map(e.graph.nodes.map((i)=>[i.id,i]));return Object.freeze(e.selection.ids.map((i)=>{let n=r.get(i);if(n===void 0)throw TypeError(`${t} graph omits selected Node ${i}.`);return n}))}function $9(e,t){return Object.freeze(e.flatMap((r)=>KB(r,t)))}function sz(e,t){if(e.kind==="graph"){if(e.selection.kind!=="node")throw TypeError(`Expected a Node ${t} query result.`);return e.selection.ids}if(e.kind!=="nodes")throw TypeError(`Expected a Node ${t} query result.`);return Object.freeze(e.nodes.map((r)=>r.value.id))}function T9(e,t){return Object.freeze(e.flatMap((r)=>sz(r,t)))}function N9(e,t){let r=KB(e,t);if(r.length!==1)throw TypeError(`${t} must resolve exactly one Node.`);return r[0]}function R9(e,t){let r=KB(e,t);if(r.length>1)throw TypeError(`${t} must resolve at most one Node.`);return r[0]}function ZB(e,t){if(e.kind!=="edges")throw TypeError(`Expected an Edge ${t} query result.`);return e.edges}function j9(e,t){let r=ZB(e,t);if(r.length>1)throw TypeError(`${t} must resolve at most one Edge.`);let i=r[0]?.target;if(i===void 0)return;if(i.kind!=="value")throw TypeError(`${t} must project its target value.`);return i.value}function P9(e,t){let r=ZB(e,t);if(r.length!==1)throw TypeError(`${t} must resolve exactly one Edge.`);let i=r[0].target;if(i.kind!=="value")throw TypeError(`${t} must project its target value.`);return i.value}function L9(e,t){let r=ZB(e,t);if(r.length!==1)throw TypeError(`${t} must resolve exactly one Edge.`);let i=r[0].source;if(i.kind!=="value")throw TypeError(`${t} must project its source value.`);return i.value}var az=Object.freeze({nodeValues:KB,completeNodeValues:$9,nodeIds:sz,completeNodeIds:T9,exactlyOneNode:N9,optionalNode:R9,edgeItems:ZB,optionalEdgeTarget:j9,exactlyOneEdgeTarget:P9,exactlyOneEdgeSource:L9});var Ml=new TextDecoder;function cz(e){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(e);let t=atob(e),r=new Uint8Array(t.length);for(let i=0;i<t.length;i++)r[i]=t.charCodeAt(i);return r}function uz(e){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(typeof e==="string"?e:Ml.decode(e),{alphabet:"base64url"});let t=e;if(t instanceof Uint8Array)t=Ml.decode(t);t=t.replace(/-/g,"+").replace(/_/g,"/");try{return cz(t)}catch{throw TypeError("The input to be decoded is not correctly encoded.")}}class r_ extends Error{static code="ERR_JOSE_GENERIC";code="ERR_JOSE_GENERIC";constructor(e,t){super(e,t);this.name=this.constructor.name,Error.captureStackTrace?.(this,this.constructor)}}class Ii extends r_{static code="ERR_JWT_INVALID";code="ERR_JWT_INVALID"}class z9 extends r_{[Symbol.asyncIterator];static code="ERR_JWKS_MULTIPLE_MATCHING_KEYS";code="ERR_JWKS_MULTIPLE_MATCHING_KEYS";constructor(e="multiple matching keys found in the JSON Web Key Set",t){super(e,t)}}var M9=(e)=>typeof e==="object"&&e!==null;function lz(e){if(!M9(e)||Object.prototype.toString.call(e)!=="[object Object]")return!1;if(Object.getPrototypeOf(e)===null)return!0;let t=e;while(Object.getPrototypeOf(t)!==null)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function n_(e){if(typeof e!=="string")throw new Ii("JWTs must use Compact JWS serialization, JWT must be a string");let{1:t,length:r}=e.split(".");if(r===5)throw new Ii("Only JWTs using Compact JWS serialization can be decoded");if(r!==3)throw new Ii("Invalid JWT");if(!t)throw new Ii("JWTs must contain a payload");let i;try{i=uz(t)}catch{throw new Ii("Failed to base64url decode the payload")}let n;try{n=JSON.parse(Ml.decode(i))}catch{throw new Ii("Failed to parse the decoded payload as JSON")}if(!lz(n))throw new Ii("Invalid JWT Claims Set");return n}function Wr(e){if(e instanceof q)return e;return e.startsWith("@")||e.startsWith("/")?q.parse(e):q.id(Fe(e))}function Ul(e){return Object.freeze({origin:e.origin,kind:e.kind,name:e.name})}function dc(e,t){let r=e.$.class(t);if(r.family!=="node")throw TypeError(`Shell ${t} is not a Node Class.`);return r}function fc(e,t){let r=e.$.class(t);if(r.family!=="edge")throw TypeError(`Shell ${t} is not an Edge Class.`);return r}async function dz(e,t,r,i){let n=t.$.method(r);if("on"in n)throw TypeError(`Shell ${t.name}.${r} is not static.`);let o=e.$.invoke;return await o(n,i)}async function WB(e,t,r){return await e.$.method(t)(r)}function fz(e){let t=null,r=()=>t??=e.domain();return{get:r,async bindAs(i,n){let o=await r(),s=dc(o,i);if(!o.$.bind(n).$.definition.satisfies(s))return null;let c=o.$.bind;return c(s,n)}}}class Fl extends Error{step;constructor(e,t,r){super(`AppSession token refresh failed at '${e}' for @${t}`,r);this.name="AppSessionRefreshError",this.step=e}}function pz(e){let{app:t,now:r}=e,i=null,n=null;async function o(){try{let a=await WB(t,"getToken",{});if(typeof a!=="string"||a.length===0)throw TypeError("Application.getToken returned an invalid credential.");let c=n_(a).exp;if(typeof c!=="number"||!Number.isFinite(c))throw TypeError("Application.getToken returned a credential without expiry.");return Object.freeze({token:a,expiresAt:c*1000})}catch(a){throw new Fl("getToken",t.id,{cause:a})}}function s(){if(n)return n;let a=o().then((c)=>(i=c,c)).finally(()=>{if(n===a)n=null});return n=a,a}return{current:()=>i,needsRefresh:()=>i===null||i.expiresAt-r()-oc<=0,refresh:s}}async function YB(e,t){let{kernel:r}=e,i=q.id(t.id).raw,o=(await r.viewsFor(i)).views[0],s=o===void 0?null:Object.freeze({target:i,route:o}),a=pz({app:t,now:e.now??Date.now}),c=!1;async function u(){if(c)throw Error("AppSession is disposed");if(a.needsRefresh())return(await a.refresh()).token;return a.current().token}let l={get token(){return a.current()?.token??""},get expiresAt(){return a.current()?.expiresAt??0},refresh:async()=>{if(c)throw Error("AppSession is disposed");let d=await a.refresh();return{token:d.token,expiresAt:d.expiresAt}}};return{app:t.id,view:s,credential:l,token:u,dispose(){c=!0}}}var mz=200,QB=1000;function Bz(e,t,r){return{async install(i,n){let o=await t.get(),s=dc(o,"Application"),a=i.startsWith("@")||i.startsWith("/")?Wr(i).raw:q.domain(i).raw,c=await dz(o,s,"install",{domain:a,space:Wr(n).raw}),u=await e.graph.get(q.parse(c.application.path)),l=u===null?null:await t.bindAs("Application",u);if(l===null)throw Error(`Application.install: app @${c.application.id} is not readable`);return l},async searchDomains(){let i=ge.Domain.$.property("origin").key,n=$r.from({kind:"node",definitions:[Ul(ge.Domain)]}).select({kind:"graph",order:{property:i,direction:"asc",unranked:"last"}}),o=[],s;for(let a=0;a<QB;a+=1){let c=await e.graph.query(n,{page:{size:mz,...s===void 0?{}:{after:s}}}),u=c.result;if(u.kind!=="graph")throw TypeError("Domain query returned a projection result.");for(let l of u.graph.nodes){let d=l.props[i];if(typeof d==="string")o.push({origin:d})}if(s=c.page.next,s===void 0)return o}throw Error(`Domain query exceeded ${QB} pages.`)},async in(i){let n=await t.get(),o=fc(n,"installed_in"),s=await e.graph.neighbors(Wr(i),Ul(o),{direction:"incoming",page:{size:mz}}),{nodes:a,cursor:c}=await s.collect({maximumPages:QB});if(c!==null)throw Error(`Application query exceeded ${QB} pages.`);return(await Promise.all(a.map((l)=>t.bindAs("Application",l)))).flatMap((l)=>l===null?[]:[l])},async open(i){let n=await e.graph.get(Wr(i)),o=n===null?null:await t.bindAs("Application",n);if(o===null)throw Error(`apps.open: application ${Wr(i).raw} is not readable`);return YB({kernel:e,...r?.now===void 0?{}:{now:r.now}},o)}}}var U9=200,hz=1000,gz=Ur("createdSpace");function yz(e,t){return{async list(){let r=await t.get(),i=dc(r,"Space"),n=$r.from({kind:"node",definitions:[Ul(i)]}).select({kind:"graph",order:{property:ge.Named.$.property("name").key,direction:"asc",unranked:"last"}}),o=await F9(e,n);return(await Promise.all(o.map((a)=>t.bindAs("Space",a)))).flatMap((a)=>a===null?[]:[a])},async get(r){let i=await e.graph.get(Wr(r));return i===null?null:t.bindAs("Space",i)},async create(r){let[i,n]=await Promise.all([t.get(),e.auth.whoami()]),o=dc(i,"Space"),s=fc(i,"owns_space"),c=(await e.graph.mutate((d)=>{let f=d.createNode({as:gz,class:Ze.from(o),props:{[ge.Named.$.property("name").key]:r?.name??"Untitled Space"}});d.createEdge({class:Ze.from(s),source:q.id(n.id),target:f})})).createdNodes[gz];if(c===void 0)throw Error("Space creation omitted its created Node.");let u=await e.graph.get(q.id(c)),l=u===null?null:await t.bindAs("Space",u);if(l===null)throw Error(`Created Space @${c} is not readable.`);return l}}}async function F9(e,t){let r=[],i;for(let n=0;n<hz;n+=1){let o=await e.graph.query(t,{page:{size:U9,...i===void 0?{}:{after:i}}}),s=o.result;if(s.kind!=="graph")throw TypeError("Space query returned a projection result.");if(r.push(...s.graph.nodes),i=o.page.next,i===void 0)return Object.freeze(r)}throw Error(`Space query exceeded ${hz} pages.`)}function Cz(e,t){async function r(){let i=await e.auth.whoami(),n=await e.graph.getOrThrow(q.id(i.id)),o=await t.bindAs("User",n);if(o===null)throw Error(`whoami identity @${i.id} is not a shell User`);return o}return{me:r,async currentSpace(){let i=await t.get(),n=await r(),o=fc(i,"default_space"),s=await e.graph.neighbors(q.id(n.id),o.schemaRef,{direction:"outgoing",page:{size:1}});return s.first===null?null:t.bindAs("Space",s.first)},async switchSpace(i){let n=await e.graph.get(Wr(i)),o=n===null?null:await t.bindAs("Space",n);if(o===null)throw Error(`Space ${Wr(i).raw} is not readable.`);await WB(o,"setDefault",{})}}}var G9=Object.freeze([]);function bz(e){return{async resolve(t){let r=Wr(t).raw,{views:i}=await e.viewsFor(r);if(i.length===0)return G9;return Object.freeze(i.map((n)=>Object.freeze({target:r,route:n})))}}}function XB(e,t){let r=fz(e);return{user:Cz(e,r),spaces:yz(e,r),apps:Bz(e,r,t),views:bz(e)}}function eh(e){let t=!1,r=null,i=()=>r??=XB(e.kernel),n={get parent(){return e.parent},children:e.childrenChannel,kernel:e.kernel,windows:e.windows,get targetNodeId(){return e.targetNodeId?.()},get hostCapabilities(){return e.hostCapabilities()},get user(){return i().user},get spaces(){return i().spaces},get apps(){return i().apps},get views(){return i().views},use(o){return e.pipeline.use(o),n},onMessage(o){return e.observer.subscribe(o)},onIntent(o,s){return e.onIntent(o,s)},onTargetChange(o){return e.onTargetChange?.(o)??(()=>{})},onWindowChange(o){return e.onWindowChange?.(o)??(()=>{})},openView(o){return e.getMountController().mount(o)},updateLocation(o,s){let a=e.windows.get(o);if(a===void 0)throw Error(`Window '${o}' is not live.`);let c=ac(a.view,s);if(c.view!==void 0&&c.view!==a.view.route.key)throw Error("Changing a window route requires opening a new View generation.");let u=Es(e.windows,o,(l)=>({...l,targetNodeId:c.target,location:c}));if(e.notifyWindows?.(),c.target!==a.targetNodeId)e.childrenChannel.send(o,{type:"intent",version:1,envelope:{name:"setTarget",payload:c.target===void 0?{}:{nodeId:c.target},sender:{windowId:"<parent>"}}});return u},focusView(o){let s=e.windows.get(o);if(s===void 0||s.state==="closed"||s.state==="failed")return!1;return e.getMountController().focus(o)},close(o,s){return e.getMountController().close(o,s)},async init(){if(e.init)await e.init();return n},async dispose(){if(t)return;t=!0,await e.onDispose()}};return n}var H9=5000;function th(e){let{parent:t}=e,r=e.timeoutMs??H9;return new Promise((i,n)=>{let o=null,s=setTimeout(()=>{a(),n(Error(`Shell child init timed out after ${r}ms`))},r);function a(){if(clearTimeout(s),window.removeEventListener("message",u),o)o.onmessage=null}function c(l){return(d)=>{let f;try{f=ch(d.data)}catch{return}let m=f.data;l.postMessage({type:"ctrl",version:1,action:"handshakeAck",data:{windowId:m.windowId}}),a();let B={credential:m.delegationToken,scope:{functionId:m.functionId},issuedAt:Date.now(),expiresAt:m.tokenExpiresAt},h=B,g=ic({session:new rc({kernel:m.kernelUrl,auth:{ttlSeconds:3600,resolve:()=>({credential:h.credential})},policy:{maximumRouteAgeMs:60000}})});i({windowId:m.windowId,functionId:m.functionId,kernelUrl:m.kernelUrl,targetNodeId:m.targetNodeId,mintIdentity:m.mintIdentity,capabilities:m.capabilities,initialToken:B,kernel:g,parentChannel:(w)=>{let b=sc({port:l}),O=XD({transport:b,observer:w});return O.on("ctrl",(k)=>{if(k.action!=="tokenRefresh")return;let G;try{G=lh(k)}catch{return}h={credential:G.data.delegationToken,scope:{functionId:m.functionId},issuedAt:Date.now(),expiresAt:G.data.tokenExpiresAt}}),O}})}}function u(l){if(!Zl(l.data))return;if(l.source!==t)return;let[d]=l.ports;if(!d)return;o=d,o.onmessage=c(d),o.start()}window.addEventListener("message",u),t.postMessage({type:mc,version:1},"*")})}function Ez(e){let t=e();if(!t)throw Error("Sandboxed shell not initialized — call shell.init() first");return t}function vz(e){return new Proxy({},{get(t,r){let i=e(),n=i[r];return typeof n==="function"?n.bind(i):n}})}function xz(e){return{send:(t)=>e().send(t),on:(t,r)=>e().on(t,r)}}function wz(){let e=[];return{add(t,r){let i={name:t,handler:r,unsubscribed:!1};return e.push(i),()=>{i.unsubscribed=!0,i.off?.()}},replay(t){for(let r of e){if(r.unsubscribed)continue;r.off=t.onLocal(r.name,r.handler)}e.length=0}}}function Iz(e){let t=e===void 0?void 0:i_(e),r=new Set,i=!1;return{current:()=>t,initialize(n){if(i)return;let o=n===void 0?void 0:i_(n);if(o===t)return;t=o,r.forEach((s)=>s(t))},handle(n){if(i||n.envelope.sender.windowId!=="<parent>")return!1;let o;try{o=V9(n.envelope.payload)}catch{return!1}if(o!==t)t=o,r.forEach((s)=>s(t));return!0},subscribe(n){if(i)return()=>{};return r.add(n),()=>r.delete(n)},dispose(){i=!0,r.clear()}}}function V9(e){if(typeof e!=="object"||e===null||Array.isArray(e))rh();if(Object.keys(e).some((i)=>i!=="nodeId"))rh();let r=e.nodeId;if(r===void 0)return;if(typeof r!=="string"||r.length===0)rh();return i_(r)}function i_(e){let t=q.parse(e).raw;if(t!==e)rh();return t}function rh(){throw TypeError("Invalid setTarget payload.")}var q9="<parent>";function Oz(e){let t=Tl(),r=new Map,i=new Set,n=()=>i.forEach((b)=>b()),o=Nl((b,O)=>{let k=r.get(b);if(k===void 0||k.state===O)return;r.set(b,Object.freeze({...k,state:O})),n()}),s=$l({observer:t,onDeliveryFailed:(b)=>o.markCrashed(b)}),a=uc(),c=null,u=null,l=null,d=Iz(void 0),f=wz();function m(b,O){if(u)return u.onLocal(b,O);return f.add(b,O)}let B=()=>Ez(()=>c),h=vz(()=>B().kernel),g=xz(()=>B().parent);function w(){if(l)return l;if(!e.adapter)throw Error("Shell.openView() requires a ShellAdapter in the config");let b=B();return l=Pl({adapter:e.adapter,kernel:h,kernelUrl:b.kernelUrl,mintIdentity:b.mintIdentity,childrenChannel:s,windows:r,lifecycle:o,parentCapabilities:()=>B().capabilities,onWindowsChange:n}),l}return eh({parent:g,childrenChannel:s,kernel:h,pipeline:a,observer:t,lifecycle:o,windows:r,getMountController:w,targetNodeId:()=>d.current(),onTargetChange:(b)=>d.subscribe(b),onWindowChange:(b)=>(i.add(b),()=>i.delete(b)),notifyWindows:n,hostCapabilities:()=>c?.capabilities??_i,onIntent:m,init:async()=>{let b=await th({parent:e.parentWindow??window.parent,timeoutMs:e.initTimeoutMs});c={windowId:b.windowId,kernelUrl:b.kernelUrl,targetNodeId:b.targetNodeId,mintIdentity:b.mintIdentity,capabilities:b.capabilities,kernel:b.kernel,parent:b.parentChannel(t)},d.initialize(b.targetNodeId),a.use(cc({selfWindowId:c.windowId,lookup:(O)=>r.get(O)?.capabilities,credential:(O)=>r.get(O)?.credential,owns:(O,k)=>Rl(r,O,k),depth:()=>1})),u=lc({selfWindowId:c.windowId,pipeline:a,parent:c.parent,children:s}),u.onLocal("setTarget",(O)=>{if(!d.handle(O))return;let k=c;if(k===null)return;let G=d.current(),{targetNodeId:oe,...V}=k;c={...V,...G===void 0?{}:{targetNodeId:G}}}),s.on("intent",(O,k)=>{u.handleInbound("child",k,O)}),c.parent.on("intent",(O)=>{u.handleInbound("parent",O,q9)}),f.replay(u)},onDispose:async()=>{if(l)await l.dispose();s.dispose(),d.dispose(),i.clear(),c?.parent.dispose(),c?.kernel.close()}})}var J9="root";function Dz(e){let t=e.windowId??J9,r=e.capabilities===void 0?_i:Tr(e.capabilities),i=Tl(),n=e.session!==void 0||e.ownClient===!0,o=e.session!==void 0?ic({session:new rc(e.session)}):e.client,s=new Map,a=new Set,c=()=>a.forEach((h)=>h()),u=Nl((h,g)=>{let w=s.get(h);if(w===void 0||w.state===g)return;s.set(h,Object.freeze({...w,state:g})),c()}),l=$l({observer:i,onDeliveryFailed:(h)=>u.markCrashed(h)}),d=uc();d.use(cc({selfWindowId:t,lookup:(h)=>s.get(h)?.capabilities,credential:(h)=>s.get(h)?.credential,owns:(h,g)=>Rl(s,h,g),depth:()=>1}));let f=lc({selfWindowId:t,pipeline:d,parent:null,children:l});l.on("intent",(h,g)=>{f.handleInbound("child",g,h)});let m=null;function B(){if(m)return m;if(!e.adapter)throw Error("Shell.openView() requires a ShellAdapter in the config");return m=Pl({adapter:e.adapter,kernel:o,kernelUrl:o.url,childrenChannel:l,windows:s,lifecycle:u,onWindowsChange:c}),m}return eh({parent:null,childrenChannel:l,kernel:o,pipeline:d,observer:i,lifecycle:u,windows:s,hostCapabilities:()=>r,onWindowChange:(h)=>(a.add(h),()=>a.delete(h)),notifyWindows:c,getMountController:B,onIntent:(h,g)=>f.onLocal(h,g),onDispose:async()=>{if(m)await m.dispose();if(l.dispose(),a.clear(),n)o.close()}})}function nh(e){return e.mode==="standalone"?Dz(e):Oz(e)}function _z(e,t){let r=Promise.resolve();return e.onIntent("open",(i)=>{let n=r.then(()=>Z9(e,t,i));return r=n.catch(()=>{}),n})}async function Z9(e,t,r){let{nodeId:i,viewId:n}=r.envelope.payload;try{let o=W9(await e.views.resolve(i),n),s=t.current(),a=await t.mount(o);if(t.setCurrent(a),t.opened(o),t.reply(r,a.windowId),s&&s.windowId!==a.windowId)try{let c=await s.close({force:!0});if(c.kind==="refused")t.failed(Error(c.reason??`Window ${s.windowId} refused to close`))}catch(c){t.failed(c)}}catch(o){t.reject(r,o),t.failed(o)}}function W9(e,t){let r=t?e.find((i)=>i.route.key===t||`/:${i.route.key}`===t):e[0];if(r)return r;throw Error(t?`View ${t} does not resolve for this node`:"No view resolves for this node")}var Y9=300000,Q9=1e4,X9=300000,e5=Tr({version:1,navigation:{openView:{}},actions:{},browser:{},access:{}}),kz=location.pathname.replace(/\/+$/,"");async function o_(e,t){let r=await fetch(kz+e,t);if(!r.ok)throw Error(`${e} → ${r.status}: ${await r.text()}`);return r.json()}function Gl(e,t){fetch(`${kz}/status`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({state:e,error:t}),keepalive:!0}).catch(()=>{})}function Yn(e){return document.getElementById(e)}function s_(e){Yn("status-dot").dataset.state=e}function t5(e){let t=e instanceof Error?e.message:String(e);s_("failed");let r=Yn("error");r.style.display="block",r.textContent=t,Gl("failed",t)}function r5(e){let t=Yn("error");t.style.display="block",t.textContent=e instanceof Error?e.message:String(e)}async function n5(){let e=await o_("/config.json"),t=e.view.route;Yn("view-label").textContent=`/:${t.key}`,Yn("target-label").textContent=e.view.target,Yn("identity-label").textContent=[e.identity,e.instance].filter(Boolean).join(" @ "),document.title=`astrale view — ${t.key}`,Gl("mounting");let r=null;if(t.handshake==="shell")r=await o_("/token",{method:"POST"});let i=new URL(e.kernelUrl,location.href).href,n=nh({mode:"standalone",session:{kernel:e.kernelIssuer,auth:{ttlSeconds:3600,resolve:()=>r===null?{}:{credential:r.token}},policy:{maximumRouteAgeMs:X9,...new URL(i).protocol==="http:"?{allowInsecureHttp:!0}:{}},envelopeTransport:"http"},adapter:MB()});await n.init();let o=Yn("frame"),s=null,a=async(c)=>{let u=c.route.handshake==="shell"?{token:r.token,expiresAt:r.expiresAt,refresh:async()=>(r=await o_("/token",{method:"POST"}),{token:r.token,expiresAt:r.expiresAt})}:void 0;return n.openView({host:o,view:c,capabilities:e5,sandbox:null,handshakeTimeoutMs:Q9,...u===void 0?{}:{credential:u}})};if(_z(n,{current:()=>s,setCurrent:(c)=>{s=c},mount:a,opened:(c)=>{Yn("view-label").textContent=`/:${c.route.key}`,Yn("target-label").textContent=c.target,Yn("error").style.display="none"},failed:r5,reply:(c,u)=>{HB(n.children,c.envelope.sender.windowId,c,{windowId:u})},reject:(c,u)=>{VB(n.children,c.envelope.sender.windowId,c,u)}}),s=await a(e.view),t.handshake==="shell")s_("connected"),Gl("connected");else s_("plain"),Gl("plain");setInterval(()=>Gl("alive"),Y9)}n5().catch(t5);
|
|
97
|
+
`))}let s=!0;while(!t.more()||t.peek()!==T.CODES.get("]")||s){if(t.more()&&t.lookingAt("-")&&(this.flags&j.PERL_X)===0&&!s){let l=t.rest();if(l==="-"||!l.startsWith("-]"))throw t.rewindTo(r),new ut(e.ERR_INVALID_CHAR_RANGE,t.rest())}s=!1;let a=t.pos();if(t.lookingAt("[:")){if(this.parseNamedClass(t,n))continue;t.rewindTo(a)}if(this.parseUnicodeClass(t,n))continue;if(this.parsePerlClassEscape(t,n))continue;t.rewindTo(a);let c=e.parseClassChar(t,r),u=c;if(t.more()&&t.lookingAt("-")){if(t.skip(1),t.more()&&t.lookingAt("]"))t.skip(-1);else if(u=e.parseClassChar(t,r),u<c)throw new ut(e.ERR_INVALID_CHAR_RANGE,t.from(a))}if((this.flags&j.FOLD_CASE)===0)n.appendRange(c,u);else n.appendFoldedRange(c,u)}if(t.skip(1),n.cleanClass(),o<0)n.negateClass();i.runes=n.toArray(),this.push(i)}},_4=class e{static initTest(t){let r=e.compile(t),i=new e(r.expr,r.prog,r.numSubexp,r.longest);return i.cond=r.cond,i.prefix=r.prefix,i.prefixUTF8=r.prefixUTF8,i.prefixComplete=r.prefixComplete,i.prefixRune=r.prefixRune,i.prefilter=r.prefilter,i}static compile(t){return e.compileImpl(t,j.PERL,!1)}static compilePOSIX(t){return e.compileImpl(t,j.POSIX,!0)}static compileImpl(t,r,i){let n=NS.parse(t,r),o=n.maxCap();n=TS.simplify(n);let s=I4.build(n),a=$S.compileRegexp(n),c=new e(t,a,o,i);c.prefilter=s.type===Me.Type.NONE?null:s;let[u,l]=a.prefix();if(c.prefixComplete=u,c.prefix=l,c.prefixUTF8=ce.stringToUtf8ByteArray(c.prefix),c.prefix.length>0)c.prefixRune=c.prefix.codePointAt(0);return c.namedGroups=n.namedGroups,c}static match(t,r){return e.compile(t).match(r)}constructor(t,r,i=0,n=0){this.expr=t,this.prog=r,this.numSubexp=i,this.longest=n,this.cond=r.startCond(),this.prefix=null,this.prefixUTF8=null,this.prefixComplete=!1,this.prefixRune=0,this.machinePool=[],this.dfa=new AS(this.prog),this.onepass=iS.compile(this.prog),this.prefilter=null}matchPrefixComplete(t,r,i,n){if((i===j.ANCHOR_START||i===j.ANCHOR_BOTH)&&r!==0)return null;let o=-1,s=-1,a=t.prefixLength(this);if(i===j.UNANCHORED){let c=t.index(this,r);if(c<0)return null;o=r+c,s=o+a}else if(i===j.ANCHOR_BOTH){if(t.endPos()!==a)return null;if(t.index(this,0)!==0)return null;o=0,s=a}else if(i===j.ANCHOR_START){if(t.index(this,0)!==0)return null;o=0,s=a}if(o<0)return null;if(n>0){let c=new Int32Array(n).fill(-1);return c[0]=o,c[1]=s,Array.from(c)}return[]}executeEngine(t,r,i,n){if(this.prefixComplete&&(n===0||this.numSubexp===0))return this.matchPrefixComplete(t,r,i,n);if(this.prefilter!==null&&i===j.UNANCHORED){if(!this.prefilter.eval(t,r))return null}if(this.onepass!==null)return iS.execute(this,t,r,i,n);if(n>0){if(this.prog.numLb===0&&t.endPos()<=Mf.maxBitStateLen(this.prog))return Mf.execute(this,t,r,i,n);return this.doExecuteNFA(t,r,i,n)}if(this.prog.numLb===0){let o=this.dfa.match(t,r,i);if(o!==null)return o?[]:null;if(t.endPos()<=Mf.maxBitStateLen(this.prog))return Mf.execute(this,t,r,i,n)}return this.doExecuteNFA(t,r,i,n)}numberOfCapturingGroups(){return this.numSubexp}numberOfInstructions(){return this.prog.numInst()}get(){return this.machinePool.length>0?this.machinePool.pop():null}reset(){this.machinePool.length=0}put(t){this.machinePool.push(t)}toString(){return this.expr}doExecuteNFA(t,r,i,n){let o=this.get();if(!o)o=SS.fromRE2(this);o.init(n);let s=o.match(t,r,i)?o.submatches():null;return this.put(o),s}match(t){return this.executeEngine(nt.fromUTF16(t),0,j.UNANCHORED,0)!==null}matchWithGroup(t,r,i,n,o){if(!(t instanceof Ao))if(ce.isByteArray(t))t=So.utf8(t);else t=So.utf16(t);return this.matchMachineInput(t,r,i,n,o)}matchMachineInput(t,r,i,n,o){if(r>i)return[!1,null];let s=t.isUTF16Encoding()?nt.fromUTF16(t.asCharSequence(),0,i):nt.fromUTF8(t.asBytes(),0,i),a=this.executeEngine(s,r,n,2*o);if(a===null)return[!1,null];return[!0,a]}matchUTF8(t){return this.executeEngine(nt.fromUTF8(t),0,j.UNANCHORED,0)!==null}replaceAll(t,r){return this.replaceAllFunc(t,()=>r,2*t.length+1)}replaceFirst(t,r){return this.replaceAllFunc(t,()=>r,1)}replaceAllFunc(t,r,i){let n=0,o=0,s="",a=nt.fromUTF16(t),c=0;while(o<=t.length){let u=this.executeEngine(a,o,j.UNANCHORED,2);if(u===null||u.length===0)break;if(s+=t.substring(n,u[0]),u[1]>n||u[0]===0)s+=r(t.substring(u[0],u[1])),c++;n=u[1];let l=a.step(o)&7;if(o+l>u[1])o+=l;else if(o+1>u[1])o++;else o=u[1];if(c>=i)break}return s+=t.substring(n),s}pad(t){if(t===null)return null;let r=(1+this.numSubexp)*2;if(t.length<r){let i=Array(r).fill(-1);for(let n=0;n<t.length;n++)i[n]=t[n];t=i}return t}allMatches(t,r,i=(n)=>n){let n=[],o=t.endPos();if(r<0)r=o+1;let s=0,a=0,c=-1;while(a<r&&s<=o){let u=this.executeEngine(t,s,j.UNANCHORED,this.prog.numCap);if(u===null||u.length===0)break;let l=!0;if(u[1]===s){if(u[0]===c)l=!1;let d=t.step(s);if(d<0)s=o+1;else s+=d&7}else s=u[1];if(c=u[1],l)n.push(i(this.pad(u))),a++}return n}findUTF8(t){let r=this.executeEngine(nt.fromUTF8(t),0,j.UNANCHORED,2);if(r===null)return null;return t.slice(r[0],r[1])}findUTF8Index(t){let r=this.executeEngine(nt.fromUTF8(t),0,j.UNANCHORED,2);if(r===null)return null;return r.slice(0,2)}find(t){let r=this.executeEngine(nt.fromUTF16(t),0,j.UNANCHORED,2);if(r===null)return"";return t.substring(r[0],r[1])}findIndex(t){return this.executeEngine(nt.fromUTF16(t),0,j.UNANCHORED,2)}findUTF8Submatch(t){let r=this.executeEngine(nt.fromUTF8(t),0,j.UNANCHORED,this.prog.numCap);if(r===null)return null;let i=Array(1+this.numSubexp).fill(null);for(let n=0;n<i.length;n++)if(2*n<r.length&&r[2*n]>=0)i[n]=t.slice(r[2*n],r[2*n+1]);return i}findUTF8SubmatchIndex(t){return this.pad(this.executeEngine(nt.fromUTF8(t),0,j.UNANCHORED,this.prog.numCap))}findSubmatch(t){let r=this.executeEngine(nt.fromUTF16(t),0,j.UNANCHORED,this.prog.numCap);if(r===null)return null;let i=Array(1+this.numSubexp).fill(null);for(let n=0;n<i.length;n++)if(2*n<r.length&&r[2*n]>=0)i[n]=t.substring(r[2*n],r[2*n+1]);return i}findSubmatchIndex(t){return this.pad(this.executeEngine(nt.fromUTF16(t),0,j.UNANCHORED,this.prog.numCap))}findAllUTF8(t,r){let i=this.allMatches(nt.fromUTF8(t),r,(n)=>t.slice(n[0],n[1]));if(i.length===0)return null;return i}findAllUTF8Index(t,r){let i=this.allMatches(nt.fromUTF8(t),r,(n)=>n.slice(0,2));if(i.length===0)return null;return i}findAll(t,r){let i=this.allMatches(nt.fromUTF16(t),r,(n)=>t.substring(n[0],n[1]));if(i.length===0)return null;return i}findAllIndex(t,r){let i=this.allMatches(nt.fromUTF16(t),r,(n)=>n.slice(0,2));if(i.length===0)return null;return i}findAllUTF8Submatch(t,r){let i=this.allMatches(nt.fromUTF8(t),r,(n)=>{let o=Array(n.length/2|0).fill(null);for(let s=0;s<o.length;s++)if(n[2*s]>=0)o[s]=t.slice(n[2*s],n[2*s+1]);return o});if(i.length===0)return null;return i}findAllUTF8SubmatchIndex(t,r){let i=this.allMatches(nt.fromUTF8(t),r);if(i.length===0)return null;return i}findAllSubmatch(t,r){let i=this.allMatches(nt.fromUTF16(t),r,(n)=>{let o=Array(n.length/2|0).fill(null);for(let s=0;s<o.length;s++)if(n[2*s]>=0)o[s]=t.substring(n[2*s],n[2*s+1]);return o});if(i.length===0)return null;return i}findAllSubmatchIndex(t,r){let i=this.allMatches(nt.fromUTF16(t),r);if(i.length===0)return null;return i}},jQ=class e{static UNANCHORED=j.UNANCHORED;static ANCHOR_START=j.ANCHOR_START;static ANCHOR_BOTH=j.ANCHOR_BOTH;constructor(t=e.UNANCHORED,r=0,i=8388608){this.anchor=t,this.jsFlags=r,this.maxMem=i;let n=j.PERL;if((r&mn.DISABLE_UNICODE_GROUPS)!==0)n&=~j.UNICODE_GROUPS;if((r&mn.LOOKBEHINDS)!==0)n|=j.LOOKBEHIND;this.re2Flags=n,this.regexps=[],this.prog=null,this.dfa=null,this.dummyRe2=null}add(t){if(this.prog)throw new kS("Cannot add patterns after compile");let r=t;if((this.jsFlags&mn.CASE_INSENSITIVE)!==0)r=`(?i)${r}`;if((this.jsFlags&mn.DOTALL)!==0)r=`(?s)${r}`;if((this.jsFlags&mn.MULTILINE)!==0)r=`(?m)${r}`;let i=NS.parse(r,this.re2Flags);return this.regexps.push(TS.simplify(i)),this.regexps.length-1}compile(){if(this.prog)return;this.prog=$S.compileSet(this.regexps),this.dfa=new AS(this.prog,this.maxMem),this.dummyRe2={prog:this.prog,cond:this.prog.startCond(),prefix:"",prefixRune:0,longest:!1}}match(t){if(!this.prog)this.compile();let r=ce.isByteArray(t)?nt.fromUTF8(t):nt.fromUTF16(t),i=j.UNANCHORED;if(this.anchor===e.ANCHOR_START)i=j.ANCHOR_START;else if(this.anchor===e.ANCHOR_BOTH)i=j.ANCHOR_BOTH;let n=this.dfa.matchSet(r,0,i);if(n!==null)return n;let o=SS.fromRE2(this.dummyRe2);return o.init(0),o.matchSet(r,0,i)}},k4=class e{static isHexadecimal(t){return"0"<=t&&t<="9"||"A"<=t&&t<="F"||"a"<=t&&t<="f"}static translate(t){let r="";if(t instanceof RegExp){if(t.ignoreCase)r+="i";if(t.multiline)r+="m";if(t.dotAll)r+="s";t=t.source}if(typeof t!=="string")return t;let i="",n=!1,o=t.length;if(o===0)i="(?:)",n=!0;let s=!1,a=0;while(a<o){let u=t[a];if(u==="\\"){if(a+1<o)switch(u=t[a+1],u){case"\\":i+="\\\\",a+=2;continue;case"c":if(a+2<o){let f=t[a+2].charCodeAt(0);if(f>=65&&f<=90||f>=97&&f<=122){let m=f%32;i+="\\x",i+=(m>>4).toString(16).toUpperCase(),i+=(m&15).toString(16).toUpperCase(),a+=3,n=!0;continue}}i+="c",a+=2,n=!0;continue;case"u":if(a+2<o){if(t[a+2]==="{"){let f=a+3,m=!1,B=!1;while(f<o){let h=t[f];if(h==="}"){B=!0;break}if(!e.isHexadecimal(h))break;m=!0,f++}if(B&&m){i+="\\x",a+=2,n=!0;continue}}else if(a+5<o){let f=!0;for(let m=0;m<4;m++)if(!e.isHexadecimal(t[a+2+m])){f=!1;break}if(f){i+="\\x{"+t.substring(a+2,a+6)+"}",a+=6,n=!0;continue}}}i+="u",a+=2,n=!0;continue;case"x":{let f=!1;if(a+2<o&&t[a+2]==="{"){let m=a+3,B=!1,h=!1;while(m<o){let g=t[m];if(g==="}"){h=!0;break}if(!e.isHexadecimal(g))break;B=!0,m++}if(h&&B)f=!0}else if(a+3<o&&e.isHexadecimal(t[a+2])&&e.isHexadecimal(t[a+3]))f=!0;if(f)i+="\\x",a+=2;else i+="x",a+=2,n=!0;continue}case"n":case"r":case"t":case"a":case"f":case"v":case"d":case"D":case"s":case"S":case"w":case"W":case"b":case"B":case"p":case"P":case"A":case"z":case"Q":case"E":case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":i+="\\"+u,a+=2;continue;default:{let f=t.codePointAt(a+1);if(f>=48&&f<=57||f>=65&&f<=90||f>=97&&f<=122){let m=ce.charCount(f);i+=t.substring(a+1,a+1+m),a+=m+1,n=!0}else{i+="\\";let m=ce.charCount(f);i+=t.substring(a+1,a+1+m),a+=m+1}continue}}}else if(u==="/"){i+="\\/",a+=1,n=!0;continue}else if(u==="[")s=!0;else if(u==="]")s=!1;else if(!s&&u==="("&&a+2<o&&t[a+1]==="?"&&t[a+2]==="<"){if(a+3<o&&!"=!>)".includes(t[a+3])){i+="(?P<",a+=3,n=!0;continue}}let l=t.codePointAt(a),d=ce.charCount(l);i+=t.substring(a,a+d),a+=d}let c=n?i:t;if(r.length>0)return`(?${r})${c}`;return c}},Ff=class e{static CASE_INSENSITIVE=mn.CASE_INSENSITIVE;static DOTALL=mn.DOTALL;static MULTILINE=mn.MULTILINE;static DISABLE_UNICODE_GROUPS=mn.DISABLE_UNICODE_GROUPS;static LONGEST_MATCH=mn.LONGEST_MATCH;static LOOKBEHINDS=mn.LOOKBEHINDS;static quote(t){return ce.quoteMeta(t)}static quoteReplacement(t,r=!1){return eS.quoteReplacement(t,r)}static translateRegExp(t){return k4.translate(t)}static compile(t,r=0){let i=t;if((r&e.CASE_INSENSITIVE)!==0)i=`(?i)${i}`;if((r&e.DOTALL)!==0)i=`(?s)${i}`;if((r&e.MULTILINE)!==0)i=`(?m)${i}`;if((r&~(e.MULTILINE|e.DOTALL|e.CASE_INSENSITIVE|e.DISABLE_UNICODE_GROUPS|e.LONGEST_MATCH|e.LOOKBEHINDS))!==0)throw new p4("Flags should only be a combination of MULTILINE, DOTALL, CASE_INSENSITIVE, DISABLE_UNICODE_GROUPS, LONGEST_MATCH, LOOKBEHINDS");let n=j.PERL;if((r&e.DISABLE_UNICODE_GROUPS)!==0)n&=~j.UNICODE_GROUPS;if((r&e.LOOKBEHINDS)!==0)n|=j.LOOKBEHIND;let o=new e(t,r);return o.re2Input=_4.compileImpl(i,n,(r&e.LONGEST_MATCH)!==0),o}static matches(t,r){return e.compile(t).testExact(r)}static initTest(t,r,i){if(t==null)throw Error("pattern is null");if(i==null)throw Error("re2 is null");let n=new e(t,r);return n.re2Input=i,n}constructor(t,r){this.patternInput=t,this.flagsInput=r,this.re2Input=null}reset(){this.re2Input.reset()}flags(){return this.flagsInput}pattern(){return this.patternInput}re2(){return this.re2Input}matches(t){return this.testExact(t)}matcher(t){if(ce.isByteArray(t))t=So.utf8(t);return new eS(this,t)}test(t){if(ce.isByteArray(t))return this.re2Input.matchUTF8(t);return this.re2Input.match(t)}testExact(t){let r=ce.isByteArray(t)?nt.fromUTF8(t):nt.fromUTF16(t);return this.re2Input.executeEngine(r,0,j.ANCHOR_BOTH,0)!==null}exec(t){let r=this.matcher(t);if(!r.find())return null;let i=[r.group(0)];for(let o=1;o<=r.groupCount();o++){let s=r.group(o);i.push(s===null?void 0:s)}i.index=r.start(0),i.input=t;let n=this.namedGroups();if(Object.keys(n).length>0){let o=r.getNamedGroups();for(let s in o)if(o[s]===null)o[s]=void 0;i.groups=o}else i.groups=void 0;return i}split(t,r=0){let i=this.matcher(t),n=[],o=0,s=0;while(i.find()){if(s===0&&i.end()===0){s=i.end();continue}if(r>0&&n.length===r-1)break;if(s===i.start()){if(r===0){o+=1,s=i.end();continue}}else while(o>0)n.push(""),o-=1;n.push(i.substring(s,i.start())),s=i.end()}if(r===0&&s!==i.inputLength()){while(o>0)n.push(""),o-=1;n.push(i.substring(s,i.inputLength()))}if(r!==0||n.length===0&&!(s===i.inputLength()&&s>0))n.push(i.substring(s,i.inputLength()));return n}*matchAll(t){let r=this.matcher(t);while(r.find()){let i=[r.group(0)];for(let o=1;o<=r.groupCount();o++){let s=r.group(o);i.push(s===null?void 0:s)}i.index=r.start(0),i.input=t;let n=this.namedGroups();if(Object.keys(n).length>0){let o=r.getNamedGroups();for(let s in o)if(o[s]===null)o[s]=void 0;i.groups=o}else i.groups=void 0;yield i}}toString(){return this.patternInput}programSize(){return this.re2Input.numberOfInstructions()}groupCount(){return this.re2Input.numberOfCapturingGroups()}namedGroups(){return this.re2Input.namedGroups}equals(t){if(this===t)return!0;if(t===null||this.constructor!==t.constructor)return!1;return this.flagsInput===t.flagsInput&&this.patternInput===t.patternInput}};function Gf(e){let t="",r=!1,i=!1;for(let n of Array.from(e)){if(r){t+=n,r=!1;continue}if(n==="\\"){t+=n,r=!0;continue}if(n==="["){i=!0,t+=n;continue}if(n==="]"){i=!1,t+=n;continue}if(!i&&n==="."){t+="[^\\n\\r]";continue}if(!i&&(n==="^"||n==="$")){t+=`\\${n}`;continue}t+=n}return t}var BX=Object.assign((e,t)=>Ff.compile(e),{code:'((pattern) => require("re2js").RE2JS.compile(pattern))'});function RS(e){try{return Ff.compile(e),!0}catch{return!1}}function Hf(e){return Ff.compile(Gf(e))}var S4=/^(?:L[lmotu]?|M[cen]?|N[dlo]?|P[cdfios]?|Z[lps]?|S[ckmo]?|C[cfno]?)$/u,A4=4096,$4=32,_v=1000;function Ui(e){if(!N4(e)||e==="[^]")return!1;let t=Array.from(e);if(t.length>A4)return!1;if(!new jS(t).parse())return!1;return RS(Gf(e))}class jS{chars;index=0;constructor(e){this.chars=e}parse(){return this.parseExpression(void 0,0)&&this.index===this.chars.length}parseExpression(e,t){if(t>$4||!this.parseBranch(e,t))return!1;while(this.peek()==="|")if(this.index++,!this.parseBranch(e,t))return!1;return!0}parseBranch(e,t){while(this.index<this.chars.length){let r=this.peek();if(r==="|"||r===e)return!0;if(!this.parsePiece(t))return!1}return e===void 0}parsePiece(e){if(!this.parseAtom(e))return!1;let t=this.peek();if(t==="*"||t==="+"||t==="?")return this.index++,!0;if(t==="{")return this.parseRangeQuantifier();return!0}parseAtom(e){let t=this.peek();if(t===void 0)return!1;if(t==="("){if(this.index++,!this.parseExpression(")",e+1)||this.peek()!==")")return!1;return this.index++,!0}if(t===".")return this.index++,!0;if(t==="[")return this.parseCharacterClass();if(t==="\\")return this.parseEscape(!0);if(!T4(t))return!1;return this.index++,!0}parseRangeQuantifier(){this.index++;let e=this.consumeInteger();if(e===void 0||e>_v)return!1;let t=e;if(this.peek()===",")this.index++,t=this.consumeInteger()??_v;if(t>_v||t<e||this.peek()!=="}")return!1;return this.index++,!0}parseCharacterClass(){let e=this.index;if(this.index++,this.peek()==="^")this.index++;if(this.peek()===void 0||this.peek()==="]")return!1;if(this.peek()==="-")this.index++;else if(!this.parseCharacterClassEntry())return!1;while(this.peek()!=="]"){if(this.peek()===void 0)return!1;if(this.peek()==="-"&&this.peek(1)==="]"){this.index++;break}if(!this.parseCharacterClassEntry())return!1}if(this.peek()!=="]")return!1;return this.index++,this.chars.slice(e,this.index).join("")!=="[^]"}parseCharacterClassEntry(){if(this.peek()==="\\"&&(this.peek(1)==="p"||this.peek(1)==="P"))return this.parseCategoryEscape();if(!this.parseClassCharacter())return!1;if(this.peek()==="-"&&this.peek(1)!=="]"){if(this.index++,!this.parseClassCharacter())return!1}return!0}parseClassCharacter(){let e=this.peek();if(e==="\\")return this.parseEscape(!1);if(e===void 0||e==="-"||e==="["||e==="]"||e==="\\")return!1;return this.index++,!0}parseEscape(e){if(e&&(this.peek(1)==="p"||this.peek(1)==="P"))return this.parseCategoryEscape();if(this.peek()!=="\\")return!1;let t=this.peek(1);if(t===void 0||!"()*+-.?[\\]^nrt{}".includes(t))return!1;return this.index+=2,!0}parseCategoryEscape(){if(this.peek()!=="\\"||this.peek(1)!=="p"&&this.peek(1)!=="P"||this.peek(2)!=="{")return!1;this.index+=3;let e="";while(this.peek()!=="}"&&this.peek()!==void 0)e+=this.peek(),this.index++;if(this.peek()!=="}"||!S4.test(e))return!1;return this.index++,!0}consumeInteger(){let e=this.index;while(/^[0-9]$/u.test(this.peek()??""))this.index++;if(this.index===e)return;let t=Number(this.chars.slice(e,this.index).join(""));return Number.isSafeInteger(t)?t:void 0}peek(e=0){return this.chars[this.index+e]}}function T4(e){let t=e.codePointAt(0);if(t===void 0)return!1;return t>=0&&t<=39||t===44||t===45||t>=47&&t<=62||t>=64&&t<=90||t>=94&&t<=122||t>=126&&t<=55295||t>=57344&&t<=1114111}function N4(e){for(let t=0;t<e.length;t++){let r=e.charCodeAt(t);if(r<55296||r>57343)continue;if(r>56319||t+1>=e.length)return!1;let i=e.charCodeAt(++t);if(i<56320||i>57343)return!1}return!0}var PS=new WeakMap;function en(e){if(!Ui(e))ie("BUILDER_FULL_MATCH_INVALID","/fullMatch","fullMatch(...) requires a complete RFC 9485 I-Regexp source.");let t=Hf(e),r=p.refine((i)=>t.matches(i),{error:`String must fully match I-Regexp ${JSON.stringify(e)}.`});return PS.set(r,e),r}function kv(e){return e!==null&&typeof e==="object"?PS.get(e):void 0}var R4=new WeakMap;function LS(e){return R4.get(e)}var MS=Object.freeze({allOf:(...e)=>zS("allOf",e),anyOf:(...e)=>zS("anyOf",e)});function US(e){let t=0,r=Object.freeze({kind:"subject"}),i=Object.freeze({kind:"object"}),n=Object.freeze({kind:"source"}),o=Object.freeze({kind:"target"});return Object.freeze({subject:r,object:i,source:n,target:o,edge(a){if(Ve(a,["source","class","target","repeat"]),a.repeat!==void 0)Ve(a.repeat,["min","max"]);return{source:a.source,class:e.resolveEdgeClass(a.class,`${e.pointer}/match/class`),target:a.target,...a.repeat===void 0?{}:{repeat:{...a.repeat}}}},exists(a){let c=[],u=a({node(l){let d=Object.freeze({kind:"variable",id:t++});return c.push({variable:d,class:e.resolveNodeClass(l,`${e.pointer}/match/exists/nodes`)}),d}});if(c.length===0)ie("BUILDER_POLICY_EMPTY_EXISTS",`${e.pointer}/match/exists/nodes`,"exists(...) must declare at least one variable Node.");return{exists:{nodes:c,where:u}}},allOf(...a){return Sv(a,`${e.pointer}/match/allOf`),{allOf:a}},anyOf(...a){return Sv(a,`${e.pointer}/match/anyOf`),{anyOf:a}}})}function zS(e,t){return Sv(t,`/${e}`),Vt("policy-composition",{operator:e,policies:[...t]})}function Sv(e,t){if(e.length===0)ie("BUILDER_POLICY_EMPTY_COMPOSITION",t,"Policy composition must be non-empty.")}function qe(e,t){let r=t??{};return Ve(r,["visibility","required"]),Vt("property",{schema:e,visibility:r.visibility??"public",...r.required===void 0?{}:{required:r.required}})}function ou(e,t){if(nr(e,"auto"))ie("BUILDER_AUTO_NESTED","","auto(...) cannot wrap another automatic Property.");Ve(t,["on","set"]);let r=Array.isArray(t.on)?t.on:[t.on];if(r.length===0)ie("BUILDER_AUTO_EVENT_INVALID","/on","auto(...) requires an event.");let i=[...new Set(r)];if(i.some((n)=>n!=="create"&&n!=="update"))ie("BUILDER_AUTO_EVENT_INVALID","/on","Automatic events are create or update.");if(t.set!=="instant")ie("BUILDER_AUTO_SET_INVALID","/set","The automatic setter must be instant.");if(i.sort((n,o)=>n===o?0:n==="create"?-1:1),e.required===!0&&!i.includes("create"))ie("BUILDER_AUTO_EVENT_INVALID","/on","A required automatic Property must run on create.");return Vt("auto",{property:e,options:{on:Object.freeze(i),set:t.set}})}var kr=/^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/u,Sr=/^[A-Za-z][A-Za-z0-9_]*$/u,Fi=/^[a-z][a-z0-9-]{0,99}$/u,ii=/^sha256:[0-9a-f]{64}$/u;var FS=new RegExp("^(?:([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?:(class|interface)\\.[A-Za-z][A-Za-z0-9_]*\\.property\\.[A-Za-z][A-Za-z0-9_]*)$","u"),Av=Object.freeze({coreSlug:Fi,memberName:Sr,origin:kr,propertyKey:FS,propertyKeyFullMatch:"([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?:(class|interface)\\.[A-Za-z][A-Za-z0-9_]*\\.property\\.[A-Za-z][A-Za-z0-9_]*",revision:ii});function Vf(e){if(!Sr.test(e))throw TypeError(`Invalid member name: ${JSON.stringify(e)}.`)}var j4=/^(class|interface|function|policy|view|type)\.([A-Za-z][A-Za-z0-9_]*)$/u,$v=/^(class|interface)\.([A-Za-z][A-Za-z0-9_]*)\.(property|method)\.([A-Za-z][A-Za-z0-9_]*)$/u;function ne(e){if(!HS(e))throw TypeError(`Invalid Ref: ${JSON.stringify(e)}.`);return e}(function(e){function t(B,h){return Vf(h),`${B}.${h}`}e.definition=t;function r(B){if(!Fi.test(B))throw TypeError(`Invalid Core member name: ${JSON.stringify(B)}.`);return`core.${B}`}e.core=r;function i(B,h){return GS(B,"Property"),Vf(h),`${B}.property.${h}`}e.property=i;function n(B,h){return GS(B,"Method"),Vf(h),`${B}.method.${h}`}e.method=n;function o(B){return B.kind==="core"?e.core(B.name):e.definition(B.kind,B.name)}e.fromSchema=o;function s(B){return e(B).slice(0,B.indexOf("."))}e.namespace=s;function a(B){return e(B).split(".")[1]}e.member=a;function c(B){return e(B).split(".")[2]}e.discriminator=c;function u(B){return e(B).split(".")[3]}e.child=u;function l(B){return HS(B)}e.is=l;function d(B){return typeof B==="string"&&Tv(B)}e.isDefinition=d;function f(B){return typeof B==="string"&&$v.exec(B)?.[3]==="property"}e.isProperty=f;function m(B){return typeof B==="string"&&$v.exec(B)?.[3]==="method"}e.isMethod=m})(ne||(ne={}));function Tv(e){return j4.test(e)}function HS(e){if(typeof e!=="string")return!1;if(Tv(e))return!0;if(e.startsWith("core."))return Fi.test(e.slice(5));return $v.exec(e)!==null}function GS(e,t){if(!e.startsWith("class.")&&!e.startsWith("interface.")||!Tv(e))P4(e,t)}function P4(e,t){throw TypeError(`${t} owner must be a Class or Interface Ref; received ${JSON.stringify(e)}.`)}var VS=(e)=>{let t=e.indexOf(":");if(t<0||!kr.test(e.slice(0,t))||!ne.is(e.slice(t+1)))throw TypeError(`Invalid Key: ${JSON.stringify(e)}.`);return e};function Z(e){return VS(e)}(function(e){function t(s,a){if(!kr.test(s))throw TypeError(`Invalid Domain origin: ${JSON.stringify(s)}.`);return`${s}:${ne(a)}`}e.of=t;function r(s){return e.of(s.origin,ne.fromSchema(s))}e.fromSchema=r;function i(s){return e(s).slice(0,s.indexOf(":"))}e.origin=i;function n(s){return e(s).slice(s.indexOf(":")+1)}e.ref=n;function o(s){if(typeof s!=="string")return!1;try{return VS(s),!0}catch{return!1}}e.is=o})(Z||(Z={}));function Pe(e){if(!Pe.is(e))throw TypeError(`Invalid canonical PropertyKey: ${JSON.stringify(e)}.`);return e}(function(e){function t(...i){let n;if(i.length===3){let[o,s,a]=i;n=Z.of(o,ne.property(s,a))}else{let[o,s]=i,a=ne.fromSchema(o);n=Z.of(o.origin,ne.property(a,s))}return n}e.of=t;function r(i){return Z.is(i)&&ne.isProperty(Z.ref(i))}e.is=r})(Pe||(Pe={}));var ca="astrale.dsl",ua="v1";function Q(e){return`${e.origin}\x00${e.kind}\x00${e.name}`}function Ue(e,t){return lt(e.origin,t.origin)||lt(e.kind,t.kind)||lt(e.name,t.name)}function lt(e,t){let r=Array.from(e,(o)=>o.codePointAt(0)??0),i=Array.from(t,(o)=>o.codePointAt(0)??0),n=Math.min(r.length,i.length);for(let o=0;o<n;o++)if(r[o]!==i[o])return(r[o]??0)-(i[o]??0);return r.length-i.length}function Bn(e,t){return`urn:astrale:dsl:v1:${encodeURIComponent(e)}:type:${encodeURIComponent(t)}`}function Be(e){return`${e.origin}:${e.kind}.${e.name}`}var qS=new TextEncoder;function To(e){if("match"in e)return Nv(e,{match:Pv(e.match)});if("allOf"in e)return Nv(e,{allOf:ZS(e.allOf)});return Nv(e,{anyOf:ZS(e.anyOf)})}function Pv(e){let t=Kf(e,L4(e));return qf(t)}function Nn(e){if("check"in e)return e;if("allOf"in e){let r=e.allOf.flatMap((i)=>{let n=Nn(i);return"allOf"in n?n.allOf:[n]});return{allOf:JS(Yf(r))}}let t=e.anyOf.flatMap((r)=>{let i=Nn(r);return"anyOf"in i?i.anyOf:[i]});return{anyOf:JS(Yf(t))}}function JS(e){return e}function qf(e){if(su(e)){let r=e.repeat;if(r?.min===1&&r.max===1){let{repeat:i,...n}=e;return n}return e}if("exists"in e)return{exists:{nodes:[...e.exists.nodes].sort((r,i)=>r.variable.id-i.variable.id),where:qf(e.exists.where)}};if("allOf"in e){let r=e.allOf.flatMap((i)=>{let n=qf(i);return"allOf"in n?n.allOf:[n]});return{allOf:Yf(r)}}let t=e.anyOf.flatMap((r)=>{let i=qf(r);return"anyOf"in i?i.anyOf:[i]});return{anyOf:Yf(t)}}function L4(e){let t=new Map;Jf(e,t);let r=new Map(t);for(let o=0;o<t.size+1;o++){let s=new Map;for(let a of t.keys()){let c=[];Rv(e,a,r,c),c.sort($o),s.set(a,`${t.get(a)??""}|${c.join("|")}`)}if([...s].every(([a,c])=>r.get(a)===c))break;r.clear();for(let[a,c]of s)r.set(a,c)}let i=new Map;jv(e,r,i);let n=[...t.keys()].sort((o,s)=>{let a=$o(r.get(o)??"",r.get(s)??"");if(a!==0)return a;let c=$o(i.get(o)??"",i.get(s)??"");if(c!==0)return c;return o-s});return new Map(n.map((o,s)=>[o,s]))}function Jf(e,t){if("exists"in e){for(let r of e.exists.nodes)t.set(r.variable.id,Q(r.class));Jf(e.exists.where,t);return}if("allOf"in e)for(let r of e.allOf)Jf(r,t);if("anyOf"in e)for(let r of e.anyOf)Jf(r,t)}function Rv(e,t,r,i){if(su(e)){if(e.source.kind==="variable"&&e.source.id===t)i.push(`s:${Q(e.class)}:${Zf(e.target,r)}`);if(e.target.kind==="variable"&&e.target.id===t)i.push(`t:${Q(e.class)}:${Zf(e.source,r)}`);return}if("exists"in e)return Rv(e.exists.where,t,r,i);let n="allOf"in e?e.allOf:e.anyOf;for(let o of n)Rv(o,t,r,i)}function Zf(e,t){if(e.kind==="variable")return`variable:${t.get(e.id)??"?"}`;return e.kind}function jv(e,t,r,i="$"){if(su(e)){for(let[a,c]of[["source",e.source],["target",e.target]])if(c.kind==="variable"){let u=`${i}:${Q(e.class)}:${a}`,l=r.get(c.id);if(l===void 0||u<l)r.set(c.id,u)}return}if("exists"in e){jv(e.exists.where,t,r,`${i}:exists`);return}let n="allOf"in e?"allOf":"anyOf";[..."allOf"in e?e.allOf:e.anyOf].sort((a,c)=>$o(Wf(a,t),Wf(c,t))).forEach((a,c)=>jv(a,t,r,`${i}:${n}:${c}`))}function Wf(e,t){if(su(e))return`edge:${Q(e.class)}:${Zf(e.source,t)}:${Zf(e.target,t)}:${e.repeat?.min??1}:${e.repeat?.max??1}`;if("exists"in e)return`exists:${e.exists.nodes.map((n)=>t.get(n.variable.id)??"").sort($o).join(",")}:${Wf(e.exists.where,t)}`;let r="allOf"in e?"allOf":"anyOf",i="allOf"in e?e.allOf:e.anyOf;return`${r}:${i.map((n)=>Wf(n,t)).sort($o).join("|")}`}function Kf(e,t){if(su(e))return{...e,source:KS(e.source,t),target:KS(e.target,t)};if("exists"in e)return{exists:{nodes:e.exists.nodes.map((r)=>({variable:{kind:"variable",id:t.get(r.variable.id)??r.variable.id},class:r.class})),where:Kf(e.exists.where,t)}};if("allOf"in e)return{allOf:e.allOf.map((r)=>Kf(r,t))};return{anyOf:e.anyOf.map((r)=>Kf(r,t))}}function KS(e,t){return e.kind==="variable"?{kind:"variable",id:t.get(e.id)??e.id}:e}function ZS(e){return[...new Map(e.map((r)=>[Q(r),r])).values()].sort(Ue)}function Yf(e){return[...new Map(e.map((r)=>[te.serialize(r),r])).entries()].sort(([r],[i])=>$o(r,i)).map(([,r])=>r)}function $o(e,t){let r=qS.encode(e),i=qS.encode(t),n=Math.min(r.length,i.length);for(let o=0;o<n;o++)if(r[o]!==i[o])return(r[o]??0)-(i[o]??0);return r.length-i.length}function Nv(e,t){return e.description===void 0?t:{description:e.description,...t}}function su(e){return"source"in e}var Gi=new Set(["allOf","anyOf","oneOf","prefixItems"]),Hi=new Set(["$defs","dependentSchemas","patternProperties","properties"]),Vi=new Set(["additionalProperties","contains","contentSchema","else","if","items","not","propertyNames","then","unevaluatedItems","unevaluatedProperties"]);function ye(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}var z4=["null","boolean","integer","number","string","array","object"],WS=new Map(z4.map((e,t)=>[e,t])),YS=new TextEncoder;function Kt(e,t,r){return Qf(e,!0,t)}function Qf(e,t,r){if(typeof e==="boolean")return e;let i={};for(let n of Object.keys(e).sort()){if(t&&n==="$schema")continue;if(t&&r==="named-type"&&n==="$id")continue;let o=e[n];if(n==="required"&&Array.isArray(o))au(o,String,"required"),i[n]=[...o].sort((s,a)=>lt(String(s),String(a)));else if(n==="type"&&Array.isArray(o))au(o,String,"type"),i[n]=[...o].sort((s,a)=>(WS.get(String(s))??Number.MAX_SAFE_INTEGER)-(WS.get(String(a))??Number.MAX_SAFE_INTEGER));else if(n==="enum"&&Array.isArray(o)){let s=o.map(oi);au(s,te.serialize,"enum"),i[n]=s.sort(F4)}else if(n==="dependentRequired"&&ye(o))i[n]=M4(o);else if(n==="x-astrale-path"&&ye(o))i[n]=U4(o);else if(Vi.has(n)&&Lv(o))i[n]=Qf(o,!1,r);else if(Gi.has(n)&&Array.isArray(o))i[n]=o.map((s)=>Lv(s)?Qf(s,!1,r):oi(s));else if(Hi.has(n)&&ye(o)){let s={};for(let a of Object.keys(o).sort()){let c=o[a];s[a]=Lv(c)?Qf(c,!1,r):oi(c)}i[n]=s}else i[n]=oi(o)}return i}function M4(e){let t={};for(let r of Object.keys(e).sort()){let i=e[r];if(!Array.isArray(i)){t[r]=oi(i);continue}au(i,String,`dependentRequired.${r}`),t[r]=[...i].sort((n,o)=>lt(String(n),String(o)))}return t}function U4(e){let t={};for(let r of Object.keys(e).sort()){let i=e[r];if(r==="accepts"&&Array.isArray(i)){let n=i.map(oi);au(n,te.serialize,"x-astrale-path.accepts"),t[r]=n.sort((o,s)=>Ue(o,s))}else t[r]=oi(i)}return t}function oi(e){if(e===null||typeof e==="boolean"||typeof e==="string")return e;if(typeof e==="number"){if(!Number.isFinite(e))throw TypeError("Cannot canonicalize a non-finite number.");if(Object.is(e,-0))throw TypeError("Cannot canonicalize negative zero.");return e}if(Array.isArray(e))return e.map(oi);if(!ye(e))throw TypeError("Cannot canonicalize a non-JSON value.");let t={};for(let r of Object.keys(e).sort())t[r]=oi(e[r]);return t}function F4(e,t){let r=YS.encode(te.serialize(e)),i=YS.encode(te.serialize(t)),n=Math.min(r.length,i.length);for(let o=0;o<n;o++)if(r[o]!==i[o])return(r[o]??0)-(i[o]??0);return r.length-i.length}function au(e,t,r){let i=new Set;for(let n of e){let o=t(n);if(i.has(o))throw TypeError(`${r} contains a duplicate value.`);i.add(o)}}function Lv(e){return typeof e==="boolean"||ye(e)}function Xf(e){let t=si(e.classes,V4),r=new Map(Object.entries(t).filter((n)=>n[1].family==="edge").map(([n,o])=>[n,o.orientation])),i={format:"astrale.dsl",version:"v1",origin:e.origin,dependencies:[...e.dependencies].sort((n,o)=>lt(n.origin,o.origin)),types:si(e.types,(n)=>Kt(n,"named-type")),interfaces:si(e.interfaces,H4),classes:t,functions:si(e.functions,QS),policies:si(e.policies,To),views:si(e.views,G4),core:{nodes:si(e.core.nodes,(n)=>({class:n.class,properties:cu(n.properties)})),edges:e.core.edges.map((n)=>J4(n,e.origin,r)).sort(K4)}};return cu(i)}function G4(e){return{...ep(e),target:e.target.kind==="domain"?{kind:"domain"}:{kind:"definition",definitions:[...e.target.definitions].sort(Ue)},auth:e.auth}}function H4(e){let t={...ep(e),family:e.family,extends:[...e.extends].sort(Ue),properties:eA(e.properties),propertyMetadata:tA(e.propertyMetadata)};if(e.family==="both")return t;if(e.family==="node")return{...t,methods:si(e.methods,XS),...e.data===void 0?{}:{data:{mediaType:e.data.mediaType}}};return e.orientation==="directed"?{...t,orientation:"directed",endpoints:rA(e.endpoints),constraints:e.constraints}:{...t,orientation:"undirected",endpoints:nA(e.endpoints),constraints:e.constraints}}function V4(e){let t={...ep(e),family:e.family,implements:[...e.implements].sort(Ue),properties:eA(e.properties),propertyMetadata:tA(e.propertyMetadata)};if(e.family==="node")return{...t,methods:si(e.methods,XS),...e.data===void 0?{}:{data:{mediaType:e.data.mediaType}},...e.icon===void 0?{}:{icon:e.icon},policies:e.policies};return e.orientation==="directed"?{...t,orientation:"directed",endpoints:rA(e.endpoints),policies:e.policies,constraints:e.constraints}:{...t,orientation:"undirected",endpoints:nA(e.endpoints),policies:e.policies,constraints:e.constraints}}function QS(e){return{...ep(e),input:Kt(e.input,"callable-input"),output:q4(e.output),auth:e.auth,...e.policy===void 0?{}:{policy:Nn(e.policy)}}}function XS(e){return{...QS(e),static:e.static,inheritance:e.inheritance}}function q4(e){switch(e.mode){case"value":return{mode:"value",schema:Kt(e.schema,"callable-output")};case"stream":return{mode:"stream",item:Kt(e.item,"callable-output")};case"binary":return{mode:"binary"}}}function eA(e){return Kt(e,"property-facet")}function tA(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t.visibility==="private"||t.auto!==void 0).map(([t,r])=>[t,r.auto===void 0?{visibility:r.visibility}:{visibility:r.visibility,auto:{on:[...new Set(r.auto.on)].sort(lt),set:r.auto.set}}]).sort(([t],[r])=>lt(t,r)))}function rA(e){return{...e,source:{...e.source,accepts:[...e.source.accepts].sort(Ue)},target:{...e.target,accepts:[...e.target.accepts].sort(Ue)}}}function nA(e){return[{...e[0],accepts:[...e[0].accepts].sort(Ue)},{...e[1],accepts:[...e[1].accepts].sort(Ue)}]}function J4(e,t,r){let n=e.class.origin===t&&r.get(e.class.name)==="undirected",[o,s]=n&&zv(e.source,e.target)>0?[e.target,e.source]:[e.source,e.target];return{class:e.class,source:o,target:s,properties:cu(e.properties)}}function K4(e,t){return Ue(e.class,t.class)||zv(e.source,t.source)||zv(e.target,t.target)||Z4(te.serialize(e.properties),te.serialize(t.properties))}function zv(e,t){if(e.kind==="domain")return t.kind==="domain"?0:-1;if(t.kind==="domain")return 1;return Ue(e,t)}function Z4(e,t){let r=new TextEncoder,i=r.encode(e),n=r.encode(t),o=Math.min(i.length,n.length);for(let s=0;s<o;s++)if(i[s]!==n[s])return(i[s]??0)-(n[s]??0);return i.length-n.length}function si(e,t){return Object.fromEntries(Object.entries(e).sort(([r],[i])=>lt(r,i)).map(([r,i])=>[r,t(i,r)]))}function ep(e){return e.description===void 0?{}:{description:e.description}}function cu(e){if(typeof e==="number"){if(Object.is(e,-0))throw TypeError("Cannot canonicalize negative zero.");return e}if(e===null||typeof e!=="object")return e;if(Array.isArray(e))return e.map((t)=>cu(t));return Object.fromEntries(Object.entries(e).map(([t,r])=>[t,cu(r)]))}function No(e){if(e===null||typeof e!=="object"||Object.isFrozen(e))return e;for(let t of Object.values(e))No(t);return Object.freeze(e)}function tp(e){let t="";for(let r of Is(e))t+=r.toString(16).padStart(2,"0");return`sha256:${t}`}function iA(e){return No(e)}function W4(e){return uu(e)}function uu(e){let t=iA(Xf(e)),r=te.encode(t),i=tp(r);return Object.freeze({schema:t,bytes:r,revision:i})}function mt(e){return W4(e).revision}class Ro{#e=new Map;constructor(e=[]){for(let t of e)this.set(t)}get(e,t){return this.#e.get(oA(e,t))}set(e){let{revision:t,schema:r}=e,i=mt(r);if(t!==i)throw Error(`Schema lookup revision ${t} disagrees with ${r.origin}@${i}`);let n=oA(r.origin,t),o=this.#e.get(n);if(o!==void 0&&o!==r)throw Error(`Schema lookup entry ${r.origin}@${t} is already bound`);return this.#e.set(n,r),this}}function rp(){return{get:()=>{return}}}function oA(e,t){return`${e}\x00${t}`}function It(e,t){let r=String(t).replaceAll("~","~0").replaceAll("/","~1");return`${e}/${r}`}function lu(e){if(!e.startsWith("#"))return;let t;try{t=decodeURIComponent(e.slice(1))}catch{return}if(t==="")return[];if(!t.startsWith("/"))return;let r=[];for(let i of t.slice(1).split("/")){if(/~(?:[^01]|$)/u.test(i))return;r.push(i.replaceAll("~1","/").replaceAll("~0","~"))}return r}function sA(e){return e.reduce((t,r)=>It(t,r),"")}function aA(e,t){let r=e;for(let i of t){if(Array.isArray(r)){if(!/^(?:0|[1-9][0-9]*)$/u.test(i))return;let n=Number(i);if(!Number.isSafeInteger(n)||n>=r.length||!(n in r))return;r=r[n];continue}if(!ye(r)||!Object.hasOwn(r,i))return;r=r[i]}return r}function Pr(e,t,r=""){let i=new Set;function n(o,s,a,c){if(typeof o==="object"&&o!==null){if(i.has(o))return;i.add(o)}try{if(t({schema:o,pointer:s,depth:a,parentKeyword:c}),!ye(o))return;for(let[u,l]of Object.entries(o)){let d=It(s,u);if(Vi.has(u)&&jo(l)){n(l,d,a+1,u);continue}if(Gi.has(u)&&Array.isArray(l)){l.forEach((f,m)=>{if(jo(f))n(f,It(d,m),a+1,u)});continue}if(Hi.has(u)&&ye(l)){for(let[f,m]of Object.entries(l))if(jo(m))n(m,It(d,f),a+1,u)}}}finally{if(typeof o==="object"&&o!==null)i.delete(o)}}n(e,r,0)}function cA(e){let t=new Set;return Pr(e,({pointer:r})=>t.add(r)),t}function jo(e){return typeof e==="boolean"||ye(e)}var np="https://json-schema.org/draft/2020-12/schema",Po="https://schemas.astrale.ai/dsl/v1/value-schema",uA="https://schemas.astrale.ai/dsl/v1/value-schema/vocabulary";var jt="https://schemas.astrale.ai/graph/1/node-path",ip=Object.freeze({$schema:np,$id:jt,title:"Astrale graph NodePath",description:"Canonical serialized exact-one locator for one logical graph Node. Full admission requires the astrale-node-path-v1 graph codec; JSON Schema format remains an annotation.",type:"string",minLength:1,format:"astrale-node-path-v1"});function lA(e){return ye(e)&&e.$ref===jt&&Object.hasOwn(e,"x-astrale-path")}function op(e,t){let r=[],i=new Map;i.set(e.current.origin,e.current),dA(e.current,`${t}/registry/current`,!1,r),[...e.directDependencies.map((s)=>({domain:s,lane:"directDependencies"})),...e.transitiveDependencies.map((s)=>({domain:s,lane:"transitiveDependencies"}))].forEach(({domain:s,lane:a},c)=>{let u=`${t}/registry/${a}/${c}`;if(dA(s,u,!0,r),s.origin===e.current.origin||i.has(s.origin)){r.push(_("VS_REFERENCE_RESOLUTION",u,`Registry origin ${s.origin} is duplicated in the exact closure.`));return}i.set(s.origin,s)});let o=new Map;for(let s of i.values()){let a=new Map(s.dependencies.map((c)=>[c.origin,c.revision]));o.set(s.origin,a);for(let c of s.dependencies){let u=i.get(c.origin);if(u===void 0||u.revision!==c.revision)r.push(_("VS_REFERENCE_RESOLUTION",`${t}/registry/${s.origin}/dependencies`,`Registry closure is missing exact ${c.origin}@${c.revision} required by ${s.origin}.`))}}return Y4(e.graphNodePath,`${t}/registry/graphNodePath`,r),{index:{registry:e,domains:i,dependenciesByOwner:o},diagnostics:r}}function sp(e,t,r=""){let i=/(?:^|\/)types\/([^/]+)$/u.exec(r);if(i!==null){let s=(i[1]??"").replaceAll("~1","/").replaceAll("~0","~");if(t.registry.current.types[s]===e)return{origin:t.registry.current.origin,name:s}}let n=[];for(let o of t.domains.values())for(let[s,a]of Object.entries(o.types))if(a===e)n.push({origin:o.origin,name:s});if(n.length===1)return n[0];if(ye(e)&&typeof e.$id==="string"){for(let o of t.domains.values())for(let s of Object.keys(o.types))if(e.$id===Bn(o.origin,s))return{origin:o.origin,name:s}}return}function fA(e,t,r){return e.domains.get(t)?.types[r]}function Mv(e,t,r){return t===r||e.dependenciesByOwner.get(t)?.has(r)===!0}function pA(e,t,r){if(!Mv(e,r,t.origin))return!1;return e.domains.get(t.origin)?.nodeDefinitions.some((i)=>Q(i)===Q(t))===!0}function dA(e,t,r,i){if(!kr.test(e.origin))i.push(_("VS_REFERENCE_RESOLUTION",`${t}/origin`,"Registry origin is invalid."));if(r&&e.revision===void 0||e.revision!==void 0&&!ii.test(e.revision))i.push(_("VS_REFERENCE_RESOLUTION",`${t}/revision`,"A dependency-closure registry entry requires its exact sha256 revision."));for(let n of Object.keys(e.types))if(!Sr.test(n))i.push(_("VS_REFERENCE_RESOLUTION",`${t}/types`,`Named type ${n} does not satisfy the V1 member-name grammar.`));for(let n of e.nodeDefinitions)if(n.origin!==e.origin)i.push(_("VS_REFERENCE_RESOLUTION",`${t}/nodeDefinitions`,"A registry domain can list only its own Node Definitions."))}function Y4(e,t,r){if(!ye(e)||e.$schema!==np||e.$id!==jt||e.type!=="string"||e.minLength!==1||e.format!=="astrale-node-path-v1")r.push(_("VS_REFERENCE_RESOLUTION",t,`The graph NodePath artifact must be preloaded under exact id ${jt}.`,jt))}function BA(e,t,r,i,n){if(e===jt){if(!n)return{diagnostic:_("VS_REFERENCE_FORM",i,"The graph NodePath schema may be referenced only beside a valid x-astrale-path annotation.",e)};return{resolved:{resource:{key:jt,schema:r.registry.graphNodePath,ownerOrigin:t.ownerOrigin},pointer:""}}}if(e.startsWith("#")){let s=lu(e);if(s===void 0)return{diagnostic:_("VS_REFERENCE_FORM",i,"A local $ref must be a JSON Pointer fragment; anchors are forbidden.",e)};return mA(t,s,i,e)}let o=Uv(e);if(o!==void 0){if(r.domains.get(o.origin)===void 0||!Mv(r,t.ownerOrigin,o.origin))return{diagnostic:_("VS_REFERENCE_RESOLUTION",i,`Named type origin ${o.origin} is not ${t.ownerOrigin} or one of its exact direct dependencies.`,e)};let a=fA(r,o.origin,o.name);if(a===void 0)return{diagnostic:_("VS_REFERENCE_RESOLUTION",i,`Named type ${o.origin}:${o.name} is absent from the exact registry.`,e)};return mA({key:Bn(o.origin,o.name),schema:a,ownerOrigin:o.origin,origin:o.origin,name:o.name},o.pointer,i,e)}return{diagnostic:_("VS_REFERENCE_FORM",i,"A $ref must be a local JSON Pointer, an exact current/direct named-type URI, or the graph NodePath id.",e)}}function mA(e,t,r,i){let n=aA(e.schema,t),o=sA(t);if(n===void 0||!cA(e.schema).has(o))return{diagnostic:_("VS_REFERENCE_RESOLUTION",r,"The $ref does not resolve to an exact schema location in the registry.",i)};return{resolved:{resource:e,pointer:o}}}function Uv(e){let t=/^urn:astrale:dsl:v1:([^:]+):type:([^#]+)(#.*)?$/u.exec(e);if(t===null)return;let r,i;try{r=decodeURIComponent(t[1]??""),i=decodeURIComponent(t[2]??"")}catch{return}if(!kr.test(r)||!Sr.test(i))return;if(Bn(r,i)!==`urn:astrale:dsl:v1:${t[1]}:type:${t[2]}`)return;let n=lu(t[3]??"#");if(n===void 0)return;return{origin:r,name:i,pointer:n}}function ap(e,t,r,i,n){let o=[],s=new Map,a=new Map,c={key:n===void 0?`urn:astrale:dsl:v1:embedded:${t}`:Bn(n.origin,n.name),schema:e,ownerOrigin:n?.origin??r.registry.current.origin,...n===void 0?{}:n,diagnosticPointer:i};s.set(c.key,c);let u=[c];while(u.length>0){let l=u.shift();if(l===void 0)break;Pr(l.schema,(d)=>{if(!ye(d.schema)||!Object.hasOwn(d.schema,"$ref"))return;let f=`${l.diagnosticPointer??i}${d.pointer}/$ref`;if(typeof d.schema.$ref!=="string"){o.push(_("VS_REFERENCE_FORM",f,"$ref must be a string URI-reference."));return}let m=BA(d.schema.$ref,l,r,f,lA(d.schema));if(m.diagnostic!==void 0)o.push(m.diagnostic);if(m.resolved===void 0)return;a.set(yr(l.key,d.pointer),m.resolved);let B=m.resolved.resource;if(s.has(B.key))return;let h=B.key===jt?`${i}/registry/graphNodePath`:`${i}/registry/${hA(B.origin??"")}/types/${hA(B.name??"")}`,g={...B,diagnosticPointer:h};s.set(B.key,g),u.push(g)})}return{resources:s,resolutions:a,diagnostics:o}}function yr(e,t){return`${e}\x00${t}`}function hA(e){return e.replaceAll("~","~0").replaceAll("/","~1")}function cp(e,t,r){let i=op(t,r);if(i.diagnostics.length>0)return gA(i.diagnostics);let n=sp(e,i.index,r),o=ap(e,n===void 0?"callable-input":"named-type",i.index,r,n);if(o.diagnostics.length>0)return gA(o.diagnostics);let s=new Map,a=new Map;for(let l of o.resources.values())Pr(l.schema,(d)=>{let f=yr(l.key,d.pointer);if(s.set(f,{key:f,pointer:d.pointer,resource:l,schema:d.schema}),!ye(d.schema))return;if(Fv(a,d.schema.pattern),Fv(a,d.schema.fullMatch),ye(d.schema.patternProperties))for(let m of Object.keys(d.schema.patternProperties))Fv(a,m)});let c=o.resources.values().next().value,u=c===void 0?void 0:s.get(yr(c.key,""));if(u===void 0)return{compiled:!1,message:"The root value schema is absent from its closure."};return{compiled:!0,value:{root:u,locations:s,resolutions:o.resolutions,matcher(l){let d=a.get(l);if(d===void 0)throw TypeError("Value schema uses an unprepared I-Regexp source.");return d}}}}function Fv(e,t){if(typeof t==="string"&&!e.has(t))e.set(t,Hf(t))}function gA(e){return{compiled:!1,message:e.map(({code:t,message:r})=>`${t}: ${r}`).join("; ")}}var yA=Object.freeze({type:"string","x-astrale-value-kind":"instant"}),Q4=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.(\d{3})Z$/u;function CA(e){if(typeof e!=="string")return!1;let t=Q4.exec(e);if(t===null)return!1;let r=Number(t[1]),i=Number(t[2]),n=Number(t[3]),o=Number(t[4]),s=Number(t[5]),a=Number(t[6]);return i>=1&&i<=12&&n>=1&&n<=X4(r,i)&&o<=23&&s<=59&&a<=59}function X4(e,t){if(t===2)return e2(e)?29:28;return t===4||t===6||t===9||t===11?30:31}function e2(e){return e%4===0&&(e%100!==0||e%400===0)}function Gv(e,t){switch(e){case"null":return t===null;case"boolean":case"number":case"string":return typeof t===e;case"integer":return typeof t==="number"&&Number.isInteger(t);case"array":return Array.isArray(t);case"object":return ye(t);default:return!1}}function Hv(e,t){return Nr(e,t)}function vA(e){let t=new Set;for(let r of e){let i=te.serialize(r);if(t.has(i))return!1;t.add(i)}return!0}function xA(e,t){if(!(t>0))return!1;let r=bA(e),i=bA(t),n=Math.min(r.exponent,i.exponent),o=r.coefficient*EA(r.exponent-n),s=i.coefficient*EA(i.exponent-n);return o%s===0n}function bA(e){let t=e.toString().toLowerCase(),[r="",i="0"]=t.split("e"),n=r.startsWith("-"),o=n?r.slice(1):r,s=o.indexOf("."),a=s===-1?0:o.length-s-1,c=o.replace(".","");return{coefficient:BigInt(`${n?"-":""}${c}`),exponent:Number(i)-a}}function EA(e){return 10n**BigInt(e)}function up(e=[],t=new Set,r=new Set){return{valid:e.length===0,failures:e,properties:t,items:r}}function Lo(e,t,r){for(let i of r.properties)e.add(i);for(let i of r.items)t.add(i)}function wA(e,t){return new IA(e).evaluate(e.root,t,"")}class IA{compiled;active=new Set;constructor(e){this.compiled=e}evaluate(e,t,r){let i=`${e.key}\x00${r}`;if(this.active.has(i))throw TypeError("Admitted value schema entered a non-productive evaluation cycle.");this.active.add(i);try{if(e.schema===!0)return up();if(e.schema===!1)return up([dt(r,"false","The false schema rejects every value.")]);return this.evaluateObjectSchema(e,e.schema,t,r)}finally{this.active.delete(i)}}evaluateObjectSchema(e,t,r,i){let n=[],o=new Set,s=new Set,a=(c)=>{if(c.valid)Lo(o,s,c);else n.push(...c.failures)};if(Object.hasOwn(t,"$ref")){let c=this.compiled.resolutions.get(e.key);if(c===void 0)throw TypeError("Admitted value schema reference has no prepared resolution.");let u=this.compiled.locations.get(yr(c.resource.key,c.pointer));if(u===void 0)throw TypeError("Prepared value schema reference target is absent.");a(this.evaluate(u,r,i))}if(this.evaluateCompositions(e,t,r,i,n,o,s),this.evaluateCommonAssertions(t,r,i,n),typeof r==="number")this.evaluateNumberAssertions(t,r,i,n);if(typeof r==="string")this.evaluateStringAssertions(t,r,i,n);if(Array.isArray(r))this.evaluateArray(e,t,r,i,n,o,s);else if(ye(r))this.evaluateObject(e,t,r,i,n,o,s);return up(n,o,s)}evaluateCompositions(e,t,r,i,n,o,s){let a=(d)=>{if(d.valid)Lo(o,s,d);else n.push(...d.failures)};lp(t.allOf)?.forEach((d,f)=>{a(this.evaluate(this.child(e,"allOf",f),r,i))});let u=lp(t.anyOf);if(u!==void 0){let f=u.map((m,B)=>this.evaluate(this.child(e,"anyOf",B),r,i)).filter(({valid:m})=>m);if(f.length===0)n.push(dt(i,"anyOf","Value satisfies no anyOf branch."));else f.forEach((m)=>Lo(o,s,m))}let l=lp(t.oneOf);if(l!==void 0){let d=l.map((f,m)=>this.evaluate(this.child(e,"oneOf",m),r,i)).filter(({valid:f})=>f);if(d.length!==1)n.push(dt(i,"oneOf","Value must satisfy exactly one oneOf branch."));else Lo(o,s,d[0])}if(ai(t.not)){if(this.evaluate(this.child(e,"not"),r,i).valid)n.push(dt(i,"not","Value satisfies not."))}if(ai(t.if)){let d=this.evaluate(this.child(e,"if"),r,i);if(d.valid)Lo(o,s,d);let f=d.valid?"then":"else";if(ai(t[f]))a(this.evaluate(this.child(e,f),r,i))}}evaluateCommonAssertions(e,t,r,i){if(e["x-astrale-value-kind"]==="instant"&&!CA(t))i.push(dt(r,"x-astrale-value-kind","Value is not an exact UTC millisecond Instant."));if(typeof e.type==="string"){if(!Gv(e.type,t))i.push(dt(r,"type",`Value is not of type ${e.type}.`))}else if(Array.isArray(e.type)&&!e.type.some((n)=>typeof n==="string"?Gv(n,t):!1))i.push(dt(r,"type","Value matches none of the admitted types."));if(Object.hasOwn(e,"const")&&!Hv(t,e.const))i.push(dt(r,"const","Value differs from const."));if(Array.isArray(e.enum)&&!e.enum.some((n)=>Hv(t,n)))i.push(dt(r,"enum","Value is absent from enum."))}evaluateNumberAssertions(e,t,r,i){if(typeof e.multipleOf==="number"&&!xA(t,e.multipleOf))i.push(dt(r,"multipleOf","Number is not an exact multiple."));if(typeof e.maximum==="number"&&t>e.maximum)i.push(dt(r,"maximum","Number exceeds maximum."));if(typeof e.exclusiveMaximum==="number"&&t>=e.exclusiveMaximum)i.push(dt(r,"exclusiveMaximum","Number reaches exclusiveMaximum."));if(typeof e.minimum==="number"&&t<e.minimum)i.push(dt(r,"minimum","Number is below minimum."));if(typeof e.exclusiveMinimum==="number"&&t<=e.exclusiveMinimum)i.push(dt(r,"exclusiveMinimum","Number reaches exclusiveMinimum."))}evaluateStringAssertions(e,t,r,i){let n=Array.from(t).length;if(typeof e.maxLength==="number"&&n>e.maxLength)i.push(dt(r,"maxLength","String exceeds maxLength."));if(typeof e.minLength==="number"&&n<e.minLength)i.push(dt(r,"minLength","String is below minLength."));if(typeof e.pattern==="string"&&!this.compiled.matcher(e.pattern).test(t))i.push(dt(r,"pattern","String does not match pattern."));if(typeof e.fullMatch==="string"&&!this.compiled.matcher(e.fullMatch).matches(t))i.push(dt(r,"fullMatch","String does not match fullMatch."))}evaluateArray(e,t,r,i,n,o,s){if(typeof t.maxItems==="number"&&r.length>t.maxItems)n.push(dt(i,"maxItems","Array exceeds maxItems."));if(typeof t.minItems==="number"&&r.length<t.minItems)n.push(dt(i,"minItems","Array is below minItems."));if(t.uniqueItems===!0&&!vA(r))n.push(dt(i,"uniqueItems","Array items are not unique."));let a=lp(t.prefixItems)??[],c=Math.min(a.length,r.length),u=!0;for(let l=0;l<c;l++){let d=this.evaluate(this.child(e,"prefixItems",l),r[l],It(i,l));if(!d.valid)u=!1,n.push(...d.failures)}if(u)for(let l=0;l<c;l++)s.add(l);if(ai(t.items)){let l=!0,d=[];for(let f=a.length;f<r.length;f++){let m=this.evaluate(this.child(e,"items"),r[f],It(i,f));if(m.valid)d.push(f);else l=!1,n.push(...m.failures)}if(l)d.forEach((f)=>s.add(f))}if(ai(t.contains)){let l=[];for(let m=0;m<r.length;m++)if(this.evaluate(this.child(e,"contains"),r[m],It(i,m)).valid)l.push(m);let d=typeof t.minContains==="number"?t.minContains:1,f=typeof t.maxContains==="number"?t.maxContains:Number.POSITIVE_INFINITY;if(l.length<d||l.length>f)n.push(dt(i,"contains","Array has an invalid number of contains matches."));else l.forEach((m)=>s.add(m))}if(ai(t.unevaluatedItems)){let l=!0,d=[];for(let f=0;f<r.length;f++){if(s.has(f))continue;let m=this.evaluate(this.child(e,"unevaluatedItems"),r[f],It(i,f));if(m.valid)d.push(f);else l=!1,n.push(...m.failures)}if(l)d.forEach((f)=>s.add(f))}}evaluateObject(e,t,r,i,n,o,s){let a=Object.keys(r);if(typeof t.maxProperties==="number"&&a.length>t.maxProperties)n.push(dt(i,"maxProperties","Object exceeds maxProperties."));if(typeof t.minProperties==="number"&&a.length<t.minProperties)n.push(dt(i,"minProperties","Object is below minProperties."));if(Array.isArray(t.required)){for(let B of t.required)if(typeof B==="string"&&!Object.hasOwn(r,B))n.push(dt(i,"required",`Object is missing required property ${B}.`))}if(ye(t.dependentRequired))for(let[B,h]of Object.entries(t.dependentRequired)){if(!Object.hasOwn(r,B)||!Array.isArray(h))continue;for(let g of h)if(typeof g==="string"&&!Object.hasOwn(r,g))n.push(dt(i,"dependentRequired",`Property ${B} requires property ${g}.`))}let c=ye(t.properties)?t.properties:{},u=Object.keys(c).filter((B)=>Object.hasOwn(r,B)),l=!0;for(let B of u){let h=this.evaluate(this.child(e,"properties",B),r[B],It(i,B));if(!h.valid)l=!1,n.push(...h.failures)}if(l)u.forEach((B)=>o.add(B));let d=ye(t.patternProperties)?t.patternProperties:{},f=new Set,m=!0;for(let B of Object.keys(d)){let h=this.compiled.matcher(B);for(let g of a){if(!h.test(g))continue;f.add(g);let w=this.evaluate(this.child(e,"patternProperties",B),r[g],It(i,g));if(!w.valid)m=!1,n.push(...w.failures)}}if(m)f.forEach((B)=>o.add(B));if(ai(t.additionalProperties)){let B=a.filter((g)=>!Object.hasOwn(c,g)&&!f.has(g)),h=!0;for(let g of B){let w=this.evaluate(this.child(e,"additionalProperties"),r[g],It(i,g));if(!w.valid)h=!1,n.push(...w.failures)}if(h)B.forEach((g)=>o.add(g))}if(ai(t.propertyNames))for(let B of a){let h=this.evaluate(this.child(e,"propertyNames"),B,It(i,B));if(!h.valid)n.push(...h.failures)}if(ye(t.dependentSchemas))for(let B of Object.keys(t.dependentSchemas)){if(!Object.hasOwn(r,B))continue;let h=this.evaluate(this.child(e,"dependentSchemas",B),r,i);if(h.valid)Lo(o,new Set,h);else n.push(...h.failures)}if(ai(t.unevaluatedProperties)){let B=a.filter((w)=>!o.has(w)),h=!0,g=[];for(let w of B){let b=this.evaluate(this.child(e,"unevaluatedProperties"),r[w],It(i,w));if(b.valid)g.push(w);else h=!1,n.push(...b.failures)}if(h)g.forEach((w)=>o.add(w))}}child(e,t,r){let i=It(e.pointer,t),n=r===void 0?i:It(i,r),o=this.compiled.locations.get(yr(e.resource.key,n));if(o===void 0)throw TypeError(`Admitted value schema child ${n} is absent from its closure.`);return o}}function lp(e){return Array.isArray(e)?e:void 0}function ai(e){return typeof e==="boolean"||ye(e)}function dt(e,t,r){return{instancePointer:e,keyword:t,message:r}}function du(e,t){try{return se(e),[]}catch(r){if(r instanceof he)return[_("VS_NUMBER_DOMAIN",`${t}${r.pointer}`,r.message)];return[_("VS_META_SCHEMA",t,"Value is outside the JSON data model.")]}}var OA=new WeakMap;function dp(e,t,r,i=""){let n=[...du(t,i)];if(n.length>0)return n;let o=t2(e,r,i);if(o.kind==="error")return[_("VS_REFERENCE_RESOLUTION",i,`Value validation failed closed while preparing exact schema resources: ${o.message}.`)];let s=wA(o.compiled,t);if(s.valid)return[];return s.failures.map((a)=>_("VALUE_SCHEMA_INSTANCE_INVALID",`${i}${a.instancePointer}`,`Value does not satisfy its complete V1 schema at ${a.keyword}: ${a.message}`))}function t2(e,t,r){let i=OA.get(t);if(i===void 0)i=new Map,OA.set(t,i);let n=i.get(e);if(n!==void 0)return n;let o=cp(e,t,r),s=o.compiled?{kind:"validator",compiled:o.value}:{kind:"error",message:o.message};return i.set(e,s),s}function kA(e,t,r){let i=[],n=r2(e,t,r,i),o=n2(e,t,r,n,i);return i2(e,o,n,i),Object.freeze(i)}function r2(e,t,r,i){let n=new Map;for(let[o,s]of Object.entries(e.candidate.core.nodes)){let a=`/core/nodes/${$A(o)}`,c=e.resolve(s.class);if(s.class.origin!==e.candidate.origin||c===void 0||c.ref.kind!=="class"||c.family!=="node"){i.push(_("DV_CORE_NODE_CLASS",`${a}/class`,`Core Node Class ${Be(s.class)} must resolve to a local concrete Node Class.`,Be(s.class)));continue}let u=t.definitions.get(Q(s.class));if(u===void 0)continue;SA(u,s.properties,r,"DV_CORE_NODE_PROPERTIES",`${a}/properties`,i);let l={origin:e.candidate.origin,kind:"core",name:o},d=Q(l);n.set(d,{kind:"core",slug:o,ref:l,key:d,classRef:s.class,analysis:u})}return n}function n2(e,t,r,i,n){let o=[];for(let[s,a]of e.candidate.core.edges.entries()){let c=`/core/edges/${s}`,u=DA(a.source,`${c}/source`,i,n),l=DA(a.target,`${c}/target`,i,n),d=e.resolve(a.class);if(a.class.origin!==e.candidate.origin||d===void 0||d.ref.kind!=="class"||d.family!=="edge"){n.push(_("DV_CORE_EDGE_CLASS",`${c}/class`,`Core Edge Class ${Be(a.class)} must resolve to a local concrete Edge Class.`,Be(a.class)));continue}let f=t.definitions.get(Q(a.class));if(f===void 0)continue;SA(f,a.properties,r,"DV_CORE_EDGE_PROPERTIES",`${c}/properties`,n);let m=d.declaration;if(u===void 0||l===void 0)continue;if(!(m.orientation==="directed"?la(e,u,m.endpoints.source.accepts)&&la(e,l,m.endpoints.target.accepts):la(e,u,m.endpoints[0].accepts)&&la(e,l,m.endpoints[1].accepts)||la(e,u,m.endpoints[1].accepts)&&la(e,l,m.endpoints[0].accepts))){n.push(_("DV_CORE_EDGE_CLASS",c,`Core Edge endpoints do not satisfy ${Be(a.class)}.`,Be(a.class)));continue}o.push({source:u,target:l,declaration:m,value:a,pointer:c})}return o}function DA(e,t,r,i){if(e.kind==="domain")return{kind:"domain",ref:e,key:"domain"};let n=r.get(Q(e));if(n===void 0)i.push(_("DV_CORE_REF",t,`Core endpoint ${Be(e)} does not name a declared local Core Node.`,Be(e)));return n}function la(e,t,r){return t.kind==="domain"||fu(e,t.classRef,r)}function SA(e,t,r,i,n,o){let s={type:"object",properties:Object.fromEntries([...e.properties].map(([a,c])=>[a,c.schema])),required:[...e.properties].filter(([,a])=>a.required).map(([a])=>a).sort(lt),additionalProperties:!1};for(let a of dp(s,t,r,n))o.push(_(i,a.pointer,a.message,a.ref))}function i2(e,t,r,i){let n=new Map,o=new Map;for(let[s,a]of Object.entries(e.candidate.classes)){if(a.family!=="edge")continue;let c={origin:e.candidate.origin,kind:"class",name:s},u=e.resolve(c);if(u===void 0||u.ref.kind!=="class"||u.family!=="edge")continue;o.set(Q(c),{declaration:u.declaration,edges:[]})}for(let s of t){let a=Q(s.value.class),[c,u]=s.declaration.orientation==="undirected"&<(s.source.key,s.target.key)>0?[s.target.key,s.source.key]:[s.source.key,s.target.key],l=`${a}\x00${c}\x00${u}`,d=n.get(l);if(d!==void 0)i.push(_("DV_CORE_EDGE_KEY",s.pointer,`Core Edge duplicates the normalized EdgeKey declared at ${d}.`));else n.set(l,s.pointer);let f=o.get(a)??{declaration:s.declaration,edges:[]};if(f.edges.push(s),o.set(a,f),s.declaration.constraints.noSelf===!0&&s.source.key===s.target.key)i.push(_("DV_CORE_EDGE_CONSTRAINTS",s.pointer,"Core Edge violates noSelf."))}for(let{declaration:s,edges:a}of o.values()){if(s.constraints.acyclic===!0&&c2(a))i.push(_("DV_CORE_EDGE_CONSTRAINTS","/core/edges","Core Edge set violates exact-Class acyclicity."));o2(e,s,a,r,i)}}function o2(e,t,r,i,n){if(t.orientation==="undirected"){let[o,s]=t.endpoints;for(let a of i.values()){let c=fu(e,a.classRef,o.accepts),u=fu(e,a.classRef,s.accepts);if(!c&&!u)continue;let l=r.filter((d)=>d.source.key===a.key||d.target.key===a.key).length;if(c)_A(o,l,a,n);if(u&&!s2(o,s))_A(s,l,a,n)}return}for(let o of i.values()){if(fu(e,o.classRef,t.endpoints.source.accepts)){let s=r.filter((a)=>a.source.key===o.key).length;Vv(t.endpoints.source,t.endpoints.source.outgoing,s,o,n)}if(fu(e,o.classRef,t.endpoints.target.accepts)){let s=r.filter((a)=>a.target.key===o.key).length;Vv(t.endpoints.target,t.endpoints.target.incoming,s,o,n)}}}function Vv(e,t,r,i,n){let[o,s]=a2(t);if(r>=o&&r<=s)return;n.push(_("DV_CORE_EDGE_CONSTRAINTS",`/core/nodes/${$A(i.slug)}`,`Core degree ${r} violates ${e.role} Edge count ${t}.`))}function _A(e,t,r,i){Vv(e,e.incident,t,r,i)}function s2(e,t){return e.incident===t.incident&&e.accepts.length===t.accepts.length&&e.accepts.every((r,i)=>Q(r)===Q(t.accepts[i]))}function a2(e){switch(e){case"0..*":return[0,Number.POSITIVE_INFINITY];case"1..*":return[1,Number.POSITIVE_INFINITY];case"0..1":return[0,1];case"1":return[1,1]}}function c2(e){let t=new Map;for(let o of e){let s=t.get(o.source.key)??[];s.push(o.target.key),t.set(o.source.key,s)}let r=new Set,i=new Set,n=(o)=>{if(r.has(o))return!0;if(i.has(o))return!1;r.add(o);for(let s of t.get(o)??[])if(n(s))return!0;return r.delete(o),i.add(o),!1};return[...t.keys()].some(n)}function fu(e,t,r){if(r.some((n)=>Q(n)===Q(t)))return!0;let i=e.resolveAny(t);if(i===void 0||i.ref.kind!=="class"||i.family!=="node")return!1;return AA(e,i.declaration.implements,r,new Set)}function AA(e,t,r,i){let n=new Set(r.map(Q));for(let o of t){let s=Q(o);if(n.has(s))return!0;if(i.has(s))continue;i.add(s);let a=e.resolveAny(o);if(a!==void 0&&a.ref.kind==="interface"&&(a.family==="node"||a.family==="both")&&AA(e,a.declaration.extends,r,i))return!0}return!1}function $A(e){return e.replaceAll("~","~0").replaceAll("/","~1")}function fp(e){let t=[],r=new Map,i=new Set,n=(o)=>{let s=Q(o),a=r.get(s);if(a!==void 0)return a;if(i.has(s)){t.push(_("DV_INTERFACE_ACYCLIC","",`Inheritance cycle reaches ${Be(o)}.`,Be(o)));return}let c=e.resolveAny(o);if(c===void 0)return;i.add(s);let u=c.declaration,d=u2(u,o.kind).flatMap((g)=>{let w=e.resolveAny(g);if(w===void 0)return t.push(_("DV_REF_RESOLVES","",`Inheritance ref ${Be(g)} does not resolve.`,Be(g))),[];let b=n(w.ref);return b===void 0?[]:[b]}),f=d2(d.map((g)=>g.properties),l2(o,u)),m=f2(o,u,d,t),B=p2(o,u,d,t),h={ref:o,declaration:u,properties:f,...m===void 0?{}:{data:m},methods:B};return r.set(s,h),i.delete(s),h};for(let o of e.definitions.values())n(o.ref);return Object.freeze({definitions:r,diagnostics:Object.freeze(t)})}function u2(e,t){if(t==="interface")return e.extends;return e.implements}function l2(e,t){let r=t.properties,i=new Set(r.required),n=new Map;for(let[o,s]of Object.entries(r.properties)){let a=Pe.of(e,o),c=t.propertyMetadata[o];n.set(a,{identity:a,owner:e,name:o,schema:s,required:i.has(o),visibility:c?.visibility==="private"?"private":"public",...c?.auto===void 0?{}:{auto:c.auto}})}return n}function d2(e,t){let r=new Map;for(let i of e)for(let[n,o]of i)if(!r.has(n))r.set(n,o);for(let[i,n]of t)r.set(i,n);return r}function f2(e,t,r,i){let n;for(let s of r){if(s.data===void 0)continue;if(n===void 0){n=s.data;continue}if(n.identity!==s.data.identity)i.push(_("DV_DATA_COMPOSITION","",`Data has distinct declaring owners ${Be(n.owner)} and ${Be(s.data.owner)}.`))}let o="data"in t?t.data:void 0;if(o===void 0)return n;if(n!==void 0)i.push(_("DV_DATA_COMPOSITION","",`Data redeclares the inherited contract from ${Be(n.owner)}.`));return{identity:`${Q(e)}\x00data`,owner:e,declaration:o}}function p2(e,t,r,i){if(!("methods"in t))return new Map;let n=new Map;for(let s of r)for(let[a,c]of s.methods){let u=n.get(a)??[];if(!u.some((l)=>l.identity===c.identity))u.push(c);n.set(a,u)}let o=new Map;for(let[s,a]of n)if(a.length===1)o.set(s,a[0]);for(let[s,a]of Object.entries(t.methods)){let c=n.get(s)??[];for(let u of c){if(u.declaration.inheritance==="sealed")i.push(_("DV_METHOD_COMPOSITION","",`Method ${s} cannot override sealed ${Be(u.owner)}.${s}.`));if(!m2(a,u.declaration))i.push(_("DV_METHOD_COMPOSITION","",`Method ${s} does not exactly preserve its inherited signature.`));if(u.declaration.inheritance!=="abstract"&&NA(u.declaration.policy)!==NA(a.policy))i.push(_("DV_METHOD_COMPOSITION","",`Method ${s} changes an executable inherited Policy.`))}o.set(s,{identity:`${Q(e)}\x00method\x00${s}`,owner:e,name:s,declaration:a}),n.delete(s)}for(let[s,a]of n)if(a.length>1)i.push(_("DV_METHOD_COMPOSITION","",`Inherited method ${s} is ambiguous and has no local override.`));if(e.kind==="class"&&t.family==="node"){for(let[s,a]of o)if(a.declaration.inheritance==="abstract")i.push(_("DV_METHOD_COMPOSITION","",`Concrete Class ${e.name} leaves method ${s} abstract.`))}return o}function m2(e,t){return te.serialize(Kt(e.input,"callable-input"))===te.serialize(Kt(t.input,"callable-input"))&&TA(e)===TA(t)&&e.auth===t.auth&&e.static===t.static}function TA(e){switch(e.output.mode){case"value":return`value:${te.serialize(Kt(e.output.schema,"callable-output"))}`;case"stream":return`stream:${te.serialize(Kt(e.output.item,"callable-output"))}`;case"binary":return"binary"}}function NA(e){return te.serialize(e===void 0?null:Nn(e))}var RA=new WeakMap;function jA(e,t){let r=new Map;for(let i of t){let n=mt(i);r.set(qv(i.origin,n),{revision:n,schema:i})}RA.set(e,LA(r.values()))}function B2(e){return RA.get(e)}function da(e){let t=B2(e);if(t!==void 0)return t;throw new xe([_("DV_ACCEPTANCE_CONTEXT","",`DomainSchema ${e.origin} has no retained acceptance context; accept it again against its exact lookup.`)])}function pp(e){return new Ro(da(e))}function PA(e){let t=new Map;for(let r of e){let i=mt(r);t.set(qv(r.origin,i),{schema:r,revision:i});for(let n of da(r))t.set(qv(n.schema.origin,n.revision),n)}return LA(t.values())}function LA(e){return Object.freeze([...e].map(({revision:t,schema:r})=>Object.freeze({revision:t,schema:r})).sort((t,r)=>lt(t.schema.origin,r.schema.origin)||lt(t.revision,r.revision)))}function qv(e,t){return`${e}\x00${t}`}function Jv(e){let t=new Map;for(let[r,i]of Object.entries(e.interfaces)){let n={origin:e.origin,kind:"interface",name:r};t.set(Q(n),{ref:n,family:i.family,owner:e,declaration:i})}for(let[r,i]of Object.entries(e.classes)){let n={origin:e.origin,kind:"class",name:r};t.set(Q(n),{ref:n,family:i.family,owner:e,declaration:i})}return t}function mp(e){return new Set(h2(e).filter((t)=>t.origin!==e.origin).map((t)=>t.origin))}function h2(e){let t=new Map,r=(i)=>{t.set(Q(i),i)};for(let i of Object.values(e.types))hn(i,r);for(let i of Object.values(e.interfaces))Bp(i,r);for(let i of Object.values(e.classes))hp(i,r);for(let i of Object.values(e.functions))qi(i,r);for(let i of Object.values(e.policies))gp(i,r);for(let i of Object.values(e.views))if(i.target.kind==="definition")i.target.definitions.forEach(r);for(let i of Object.values(e.core.nodes))r(i.class);for(let i of e.core.edges)r(i.class);return Object.freeze([...t.values()].sort(Ue))}function Bp(e,t){if(e.extends.forEach(t),hn(e.properties,t),"methods"in e)Object.values(e.methods).forEach((r)=>qi(r,t));if(e.family==="edge")zA(e,t)}function hp(e,t){if(e.implements.forEach(t),hn(e.properties,t),e.family==="edge"){zA(e,t);return}if(Object.values(e.methods).forEach((r)=>qi(r,t)),e.policies.read!==void 0)t(e.policies.read)}function zA(e,t){let r=e.orientation==="directed"?[e.endpoints.source,e.endpoints.target]:e.endpoints;r[0].accepts.forEach(t),r[1].accepts.forEach(t)}function qi(e,t){if(hn(e.input,t),e.output.mode==="value")hn(e.output.schema,t);if(e.output.mode==="stream")hn(e.output.item,t);if(e.policy!==void 0)MA(e.policy,t)}function gp(e,t){if("match"in e){Kv(e.match,t);return}("allOf"in e?e.allOf:e.anyOf).forEach(t)}function Kv(e,t){if("source"in e){t(e.class);return}if("exists"in e){e.exists.nodes.forEach((i)=>t(i.class)),Kv(e.exists.where,t);return}("allOf"in e?e.allOf:e.anyOf).forEach((i)=>Kv(i,t))}function MA(e,t){if("check"in e){if(t(e.check),e.object.kind==="ref")t(e.object.ref);return}("allOf"in e?e.allOf:e.anyOf).forEach((i)=>MA(i,t))}function hn(e,t){Pr(e,({schema:r})=>{if(!ye(r))return;if(typeof r.$ref==="string"){let n=Uv(r.$ref);if(n!==void 0){let o={origin:n.origin,kind:"type",name:n.name};t(o)}}let i=r["x-astrale-path"];if(!ye(i)||!Array.isArray(i.accepts))return;for(let n of i.accepts)if(ye(n)&&typeof n.origin==="string"&&typeof n.kind==="string"&&typeof n.name==="string")t(n)})}function fa(e,t){let r=[],i=new Map,n=new Map,o=new Set;for(let[s,a]of e.dependencies.entries()){let c=`/dependencies/${s}`;if(!ii.test(a.revision))continue;if(a.origin===e.origin){r.push(_("DV_DEPENDENCY_UNIQUE",`${c}/origin`,"A Domain cannot depend on itself."));continue}if(o.has(a.origin)){r.push(_("DV_DEPENDENCY_UNIQUE",`${c}/origin`,`Dependency origin ${a.origin} is declared more than once.`));continue}o.add(a.origin);let u=t.get(a.origin,a.revision);if(u===void 0){r.push(_("DV_DEPENDENCY_EXACT",c,`Schema lookup has no exact ${a.origin}@${a.revision}.`));continue}if(u.origin!==a.origin){r.push(_("DV_DEPENDENCY_EXACT",c,`Schema lookup value origin ${u.origin} disagrees with ${a.origin}.`));continue}let l=mt(u);if(l!==a.revision){r.push(_("DV_DEPENDENCY_EXACT",c,`Schema lookup content revision is ${l}, not ${a.revision}.`));continue}i.set(u.origin,u)}g2(e,i,t,r);for(let[s,a]of Jv(e))n.set(s,a);for(let s of i.values())for(let[a,c]of Jv(s))n.set(a,c);return y2(e,o,r),Object.freeze({candidate:e,dependencies:i,definitions:n,diagnostics:Object.freeze(r),resolve(s){if(s.origin!==e.origin&&!o.has(s.origin))return;return n.get(Q(s))},resolveAny(s){return n.get(Q(s))},resolvePolicy(s){if(s.origin!==e.origin)return;return e.policies[s.name]}})}function g2(e,t,r,i){let n=new Map,o=new Set,s=new Set,a=(c,u)=>{if(o.has(u)){i.push(_("DV_DEPENDENCY_ACYCLIC","/dependencies",`Dependency cycle reaches ${c.origin}.`));return}if(s.has(u))return;o.add(u);for(let l of c.dependencies){if(l.origin===e.origin){i.push(_("DV_DEPENDENCY_ACYCLIC","/dependencies",`Dependency cycle returns to ${e.origin}.`));continue}let d=n.get(l.origin);if(d!==void 0&&d!==l.revision)i.push(_("DV_DEPENDENCY_REVISION_COHERENCE","/dependencies",`Closure contains ${l.origin} at both ${d} and ${l.revision}.`));else n.set(l.origin,l.revision);let f=t.get(l.origin)??r.get(l.origin,l.revision);if(f===void 0){i.push(_("DV_DEPENDENCY_EXACT","/dependencies",`Dependency closure is missing ${l.origin}@${l.revision}.`));continue}if(f.origin!==l.origin){i.push(_("DV_DEPENDENCY_EXACT","/dependencies",`Schema lookup value origin ${f.origin} disagrees with ${l.origin}.`));continue}if(mt(f)!==l.revision){i.push(_("DV_DEPENDENCY_EXACT","/dependencies",`Schema lookup content for ${l.origin} disagrees with ${l.revision}.`));continue}t.set(f.origin,f),a(f,`${l.origin}\x00${l.revision}`)}o.delete(u),s.add(u)};a(e,`${e.origin}\x00candidate`)}function y2(e,t,r){let i=mp(e);for(let n of i)if(!t.has(n))r.push(_("DV_DEPENDENCY_DIRECT","",`Foreign origin ${n} is referenced without an exact direct dependency.`));for(let n of t)if(!i.has(n))r.push(_("DV_DEPENDENCY_USED","/dependencies",`Dependency ${n} is not referenced by the Domain.`))}function FA(e,t=pp(e)){return pu(fa(e,t))}function pu(e){let t=[],r=[],i=new Set(e.candidate.dependencies.map(({origin:n})=>n));for(let n of e.dependencies.values()){let o={...UA(n),revision:mt(n)};if(i.has(n.origin))t.push(o);else r.push(o)}return Object.freeze({current:UA(e.candidate),directDependencies:Object.freeze(t),transitiveDependencies:Object.freeze(r),graphNodePath:ip})}function UA(e){let t=[...Object.entries(e.interfaces).filter(([,r])=>r.family==="node").map(([r])=>({origin:e.origin,kind:"interface",name:r})),...Object.entries(e.classes).filter(([,r])=>r.family==="node").map(([r])=>({origin:e.origin,kind:"class",name:r}))];return Object.freeze({origin:e.origin,dependencies:e.dependencies,types:e.types,nodeDefinitions:Object.freeze(t)})}var Zv=new Set(["null","boolean","number","string","array","object"]);function yp(e,t){let r=cp(e,t,"");if(!r.compiled)return;let i=new qA(r.value).classify(r.value.root);if(i.size!==1)return;let[n]=i;return n==="boolean"||n==="number"||n==="string"||n==="instant"?n:void 0}class qA{compiled;active=new Set;cache=new Map;constructor(e){this.compiled=e}classify(e){let t=this.cache.get(e.key);if(t!==void 0)return t;if(this.active.has(e.key))return Zv;this.active.add(e.key);try{let r=this.classifySchema(e);return this.cache.set(e.key,r),r}finally{this.active.delete(e.key)}}classifySchema(e){if(e.schema===!1)return new Set;if(e.schema===!0)return Zv;let t=e.schema,r=Zv;if(Object.hasOwn(t,"x-astrale-value-kind")){if(t["x-astrale-value-kind"]!=="instant"||t.type!=="string")return new Set;r=zo(r,new Set(["instant"]))}let i=C2(t.type);if(i!==void 0)r=zo(r,i);if(Object.hasOwn(t,"const"))r=zo(r,new Set([HA(t.const)]));if(Array.isArray(t.enum))r=zo(r,Wv(new Set(t.enum.map(HA))));if(Object.hasOwn(t,"$ref")){let o=this.compiled.resolutions.get(e.key);if(o===void 0)return new Set;let s=this.compiled.locations.get(yr(o.resource.key,o.pointer));if(s===void 0)return new Set;r=zo(r,this.classify(s))}let n=VA(t.allOf);if(n!==void 0)for(let o=0;o<n.length;o+=1)r=zo(r,this.classify(this.child(e,"allOf",o)));for(let o of["anyOf","oneOf"]){let s=VA(t[o]);if(s===void 0)continue;let a=new Set;for(let c=0;c<s.length;c+=1)a=b2(a,this.classify(this.child(e,o,c)));r=zo(r,a)}return r}child(e,t,r){let i=r===void 0?`/${t}`:`/${t}/${r}`,n=this.compiled.locations.get(`${e.key}${i}`);if(n===void 0)throw TypeError("Prepared value schema child is absent from its closure.");return n}}function C2(e){if(typeof e==="string")return GA([e]);if(Array.isArray(e)){let t=e.filter((r)=>typeof r==="string");return GA(t)}return}function GA(e){let t=new Set;for(let r of e)if(r==="integer"||r==="number")t.add("number");else if(r==="null"||r==="boolean"||r==="string"||r==="array"||r==="object")t.add(r);return t}function HA(e){if(e===null)return"null";if(Array.isArray(e))return"array";if(typeof e==="object")return"object";if(typeof e==="boolean")return"boolean";if(typeof e==="number")return"number";return"string"}function zo(e,t){let r=new Set;for(let i of e)for(let n of t)if(i===n)r.add(i);else if(i==="string"&&n==="instant"||i==="instant"&&n==="string")r.add("instant");return Wv(r)}function b2(e,t){return Wv(new Set([...e,...t]))}function Wv(e){if(e.has("string"))e.delete("instant");return e}function VA(e){return Array.isArray(e)?e:void 0}function e$(e,t){let r=[...t.diagnostics],i=e.candidate;for(let[n,o]of Object.entries(i.interfaces)){let s=XA(i.origin,"interfaces",n);if(JA(e,o,`/interfaces/${pa(n)}`,r),KA(e,s,o.family,o.extends,r),o.family==="edge")ZA(e,s,o,r)}for(let[n,o]of Object.entries(i.classes)){let s=XA(i.origin,"classes",n);if(JA(e,o,`/classes/${pa(n)}`,r),KA(e,s,o.family,o.implements,r),o.family==="edge")ZA(e,s,o,r)}return E2(e,r),Object.freeze(r)}function JA(e,t,r,i){let n=new Set(Object.keys(t.properties.properties));for(let[a,c]of t.properties.required.entries())if(!n.has(c))i.push(_("DV_PROPERTY_FACET",`${r}/properties/required/${a}`,`Required property ${c} is not directly declared.`));for(let a of Object.keys(t.propertyMetadata))if(!n.has(a))i.push(_("DV_PROPERTY_FACET",`${r}/propertyMetadata/${pa(a)}`,`Metadata cannot create hidden property ${a}.`));let o=new Set(t.properties.required),s=pu(e);for(let[a,c]of Object.entries(t.propertyMetadata)){if(c.auto===void 0)continue;let u=`${r}/propertyMetadata/${pa(a)}/auto`;if(o.has(a)&&!c.auto.on.includes("create"))i.push(_("DV_PROPERTY_AUTO",`${u}/on`,"A required automatic Property must run on create."));let l=t.properties.properties[a];if(l!==void 0&&c.auto.set==="instant"&&yp(l,s)!=="instant")i.push(_("DV_PROPERTY_AUTO",`${u}/set`,"The instant setter requires an Instant value schema."))}if("methods"in t)for(let[a,c]of Object.entries(t.methods)){let u=`${r}/methods/${pa(a)}`;if(c.inheritance==="abstract"&&c.policy!==void 0)i.push(_("DV_METHOD_ABSTRACT",`${u}/policy`,"Abstract Methods cannot have a Policy."));if(!("implements"in t));else if(c.inheritance==="abstract")i.push(_("DV_METHOD_ABSTRACT",`${u}/inheritance`,"A Node Class cannot declare an abstract Method."))}}function KA(e,t,r,i,n){for(let[o,s]of i.entries()){let a=e.resolve(s);if(a===void 0){n.push(_("DV_REF_RESOLVES",`/${t.kind==="class"?"classes":"interfaces"}/${pa(t.name)}/${t.kind==="class"?"implements":"extends"}/${o}`,`Parent ${Be(s)} does not resolve exactly.`,Be(s)));continue}if(!(a.ref.kind==="interface"&&(r==="both"?a.family==="both":a.family===r||a.family==="both")))n.push(_("DV_INTERFACE_KIND","",`${Be(t)} cannot inherit ${Be(s)}.`))}}function ZA(e,t,r,i){let n=r.orientation==="directed"?[r.endpoints.source,r.endpoints.target]:r.endpoints;if(n[0].role===n[1].role)i.push(_("DV_EDGE_ROLE","",`${Be(t)} has equal source and target roles.`));if(WA(e,t,n[0],r.orientation==="directed"?"source":"first endpoint",i),WA(e,t,n[1],r.orientation==="directed"?"target":"second endpoint",i),r.orientation==="undirected"){if(!v2(r.endpoints[0],r.endpoints[1])&&x2(e,r.endpoints))i.push(_("DV_EDGE_UNDIRECTED","",`${Be(t)} has unequal undirected endpoint contracts whose accepted Node families overlap.`));if(r.constraints.acyclic===!0)i.push(_("DV_EDGE_CONSTRAINT","","acyclic is valid only for directed Edge contracts."))}}function WA(e,t,r,i,n){let o=new Set;for(let s of r.accepts){let a=Q(s);if(o.has(a))n.push(_("DV_EDGE_ACCEPTS","",`${Be(t)} ${i} repeats ${Be(s)}.`));o.add(a);let c=e.resolve(s);if(c===void 0||c.family!=="node")n.push(_("DV_EDGE_ACCEPTS","",`${Be(t)} ${i} ref ${Be(s)} does not resolve to a Node Definition.`))}}function E2(e,t){for(let r of e.definitions.values()){if(r.family!=="edge")continue;let i=r.declaration,n=r.ref.kind==="interface"?i.extends:i.implements;for(let o of n){let s=e.resolveAny(o);if(s===void 0||s.ref.kind!=="interface"||s.family!=="edge")continue;let a=s.declaration,c={endpoints:YA(i.endpoints),orientation:i.orientation,constraints:i.constraints},u={endpoints:YA(a.endpoints),orientation:a.orientation,constraints:a.constraints};if(te.serialize(c)!==te.serialize(u))t.push(_("DV_EDGE_INTERFACE_COMPOSITION","",`${Be(r.ref)} does not exactly preserve ${Be(o)}.`))}}}function YA(e){if(Array.isArray(e))return[{...e[0],accepts:[...e[0].accepts].sort(Ue)},{...e[1],accepts:[...e[1].accepts].sort(Ue)}];let t=e;return{source:{...t.source,accepts:[...t.source.accepts].sort(Ue)},target:{...t.target,accepts:[...t.target.accepts].sort(Ue)}}}function v2(e,t){if(e.incident!==t.incident)return!1;let r=[...e.accepts].map(Q).sort(),i=[...t.accepts].map(Q).sort();return r.length===i.length&&r.every((n,o)=>n===i[o])}function x2(e,t){for(let r of e.definitions.values()){if(r.ref.kind!=="class"||r.family!=="node")continue;let i=r.ref;if(QA(e,i,t[0].accepts)&&QA(e,i,t[1].accepts))return!0}return!1}function QA(e,t,r){if(r.some((o)=>Q(o)===Q(t)))return!0;let i=e.resolveAny(t);if(i===void 0||i.ref.kind!=="class"||i.family!=="node")return!1;let n=i.declaration;return t$(e,n.implements,r,new Set)}function t$(e,t,r,i){let n=new Set(r.map(Q));for(let o of t){let s=Q(o);if(n.has(s))return!0;if(i.has(s))continue;i.add(s);let a=e.resolveAny(o);if(a!==void 0&&a.ref.kind==="interface"&&(a.family==="node"||a.family==="both")&&t$(e,a.declaration.extends,r,i))return!0}return!1}function XA(e,t,r){return{origin:e,kind:t==="classes"?"class":"interface",name:r}}function pa(e){return e.replaceAll("~","~0").replaceAll("/","~1")}class Yv{environment;analysis;diagnostics=[];normalized=new Map;allNodeClasses;#e=new Set;constructor(e,t){this.environment=e,this.analysis=t,this.allNodeClasses=[...e.definitions.values()].filter((r)=>r.ref.kind==="class"&&r.family==="node").map((r)=>r.ref)}resolveNodeClass(e,t){let r=this.environment.resolve(e);if(r===void 0||r.ref.kind!=="class"||r.family!=="node"){this.add("PL_REF",t,`${Be(e)} does not resolve to an owning/direct-dependency Node Class.`,Be(e));return}return r}resolveEdge(e,t){let r=this.environment.resolve(e);if(r===void 0||r.ref.kind!=="class"||r.family!=="edge"){this.add("PL_REF",t,`${Be(e)} does not resolve to an owning/direct-dependency Edge Class.`,Be(e));return}return r}resolvePolicy(e,t){let r=`${t}\x00${Q(e)}`;if(this.#e.has(r))return!1;let i=this.environment.resolvePolicy(e);if(e.origin!==this.environment.candidate.origin||e.kind!=="policy"||i===void 0)return this.#e.add(r),this.add("PL_REF",t,`${Be(e)} is not an exact local named Policy ref.`,Be(e)),!1;return!0}isLocalPolicy(e){return e.origin===this.environment.candidate.origin&&e.kind==="policy"&&this.environment.candidate.policies[e.name]!==void 0}edgeDeclaration(e){let t=this.environment.resolve(e);if(t===void 0||t.ref.kind!=="class"||t.family!=="edge")return;let r=t.declaration;return r.family==="edge"?r:void 0}classImplements(e,t){let r=this.environment.resolveAny(e);if(r===void 0||r.ref.kind!=="class"||r.family!=="node")return!1;let i=r.declaration;if(i.family!=="node")return!1;return i.implements.some((n)=>this.interfaceExtends(n,t))}interfaceExtends(e,t){if(Q(e)===Q(t))return!0;let r=new Set,i=(n)=>{let o=Q(n);if(o===Q(t))return!0;if(r.has(o))return!1;r.add(o);let s=this.environment.resolveAny(n);if(s===void 0||s.ref.kind!=="interface"||s.family!=="node"&&s.family!=="both")return!1;return s.declaration.extends.some(i)};return i(e)}add(e,t,r,i){this.diagnostics.push(_(e,t,r,i))}}function Ar(e){return e.replaceAll("~","~0").replaceAll("/","~1")}var r$=4,ma=8,Xv=4,n$=6,mu=3,i$=4,ex=4,tx=8,ci=ma+1;function o$(e){for(let t of Object.keys(e.environment.candidate.policies)){let r=s$(e,t,new Set);if(r===void 0)continue;let i=`/policies/${Ar(t)}`;if(r.depth>r$)e.add("PL_BUDGET",i,`Expanded Pattern depth ${r.depth} exceeds ${r$}.`);if(r.edgeCounts.length>ma)e.add("PL_BUDGET",i,`Expanded Pattern has more than ${ma} normalized branches.`);let n=Math.max(0,...r.edgeCounts);if(n>n$)e.add("PL_BUDGET",i,`A normalized branch contains ${n} Edge predicates; the maximum is ${n$}.`);if(r.domains.size>i$)e.add("PL_BUDGET",i,`Expanded Pattern references ${r.domains.size} Domains; the maximum is ${i$}.`)}}function rx(e){if("check"in e)return{depth:1,branches:1,leaves:1};let{key:t,values:r}=O2(e),i=r.map(rx),n=t==="allOf"?i.reduce((o,s)=>w2(o,s.branches),1):i.reduce((o,s)=>Math.min(ci,o+s.branches),0);return{depth:1+Math.max(0,...i.map((o)=>o.depth)),branches:n,leaves:i.reduce((o,s)=>o+s.leaves,0)}}function s$(e,t,r){if(r.has(t))return;let i=e.normalized.get(t);if(i===void 0)return;let n=new Set(r);if(n.add(t),"match"in i)return Qv(i.match,e.environment.candidate.origin);let o="allOf"in i?i.allOf:i.anyOf,s=o.flatMap((a)=>{if(!e.isLocalPolicy(a))return[];let c=s$(e,a.name,n);return c===void 0?[]:[c]});if(s.length!==o.length||s.length===0)return;return a$("allOf"in i?"allOf":"anyOf",s)}function Qv(e,t){if(D2(e))return{depth:1,edgeCounts:[1],domains:new Set([t,e.class.origin])};if("exists"in e){let n=Qv(e.exists.where,t);return{depth:n.depth+1,edgeCounts:n.edgeCounts,domains:new Set([...n.domains,...e.exists.nodes.map((o)=>o.class.origin)])}}let{key:r,values:i}=I2(e);return a$(r,i.map((n)=>Qv(n,t)))}function a$(e,t){let r=1+Math.max(0,...t.map((o)=>o.depth)),i=new Set(t.flatMap((o)=>[...o.domains]));if(e==="anyOf")return{depth:r,edgeCounts:t.flatMap((o)=>o.edgeCounts).slice(0,ci),domains:i};let n=[0];for(let o of t){let s=[];for(let a of n){for(let c of o.edgeCounts)if(s.push(a+c),s.length>=ci)break;if(s.length>=ci)break}n=s}return{depth:r,edgeCounts:n,domains:i}}function w2(e,t){return Math.min(ci,e*t)}function I2(e){return"allOf"in e?{key:"allOf",values:e.allOf}:{key:"anyOf",values:e.anyOf}}function O2(e){return"allOf"in e?{key:"allOf",values:e.allOf}:{key:"anyOf",values:e.anyOf}}function D2(e){return"source"in e}function Cp(e,t){let r=S2(e,t);return nx(e,t,r)}function ix(e){let t=[_2()];for(let r of e){let i=[];for(let n of t)for(let o of r)if(i.push(k2(n,o)),i.length>=ci)return i;t=i}return t}function ox(e){return e.length<=ci?e:e.slice(0,ci)}function c$(e){let t=Ba(e);if(t===void 0)return!1;let r=new Set(t==="object"?["subject","object"]:["subject","source","target"]);for(let o of e.requiredVariables)r.add(o);let i=new u$(r);for(let o of e.edges){let s=Mo(o.pattern.source,o.namespace),a=Mo(o.pattern.target,o.namespace);i.add(s),i.add(a),i.join(s,a)}let n=i.find("subject");return[...r].every((o)=>i.find(o)===n)}function Ba(e){let t=!1,r=!1,i=!1;for(let n of e.edges)for(let o of[n.pattern.source,n.pattern.target])t||=o.kind==="object",r||=o.kind==="source",i||=o.kind==="target";if(t&&!r&&!i)return"object";if(!t&&r&&i)return"edge";return}function Mo(e,t){return e.kind==="variable"?sx(t,e.id):e.kind}function nx(e,t,r){if($2(e))return[{edges:[{pattern:e,namespace:t}],variables:r,requiredVariables:new Set,namespace:t}];if("exists"in e){let s=new Set(e.exists.nodes.map((a)=>sx(t,a.variable.id)));return nx(e.exists.where,t,r).map((a)=>({...a,requiredVariables:new Set([...a.requiredVariables,...s])}))}let{key:i,values:n}=A2(e),o=n.map((s)=>nx(s,t,r));return i==="allOf"?ix(o):ox(o.flat())}function _2(){return{edges:[],variables:new Map,requiredVariables:new Set,namespace:"$"}}function k2(e,t){return{edges:[...e.edges,...t.edges],variables:new Map([...e.variables,...t.variables]),requiredVariables:new Set([...e.requiredVariables,...t.requiredVariables]),namespace:`${e.namespace}&${t.namespace}`}}function S2(e,t){let r=new Map,i=(n)=>{if("exists"in n){for(let o of n.exists.nodes)r.set(sx(t,o.variable.id),o.class);i(n.exists.where)}else if("allOf"in n)n.allOf.forEach(i);else if("anyOf"in n)n.anyOf.forEach(i)};return i(e),r}function sx(e,t){return`variable:${e}:${t}`}function A2(e){return"allOf"in e?{key:"allOf",values:e.allOf}:{key:"anyOf",values:e.anyOf}}function $2(e){return"source"in e}class u${#e=new Map;constructor(e){for(let t of e)this.add(t)}add(e){if(!this.#e.has(e))this.#e.set(e,e)}find(e){this.add(e);let t=this.#e.get(e);if(t===e)return e;let r=this.find(t);return this.#e.set(e,r),r}join(e,t){let r=this.find(e),i=this.find(t);if(r!==i)this.#e.set(i,r)}}function d$(e){for(let[t,r]of Object.entries(e.environment.candidate.policies)){let i=`/policies/${Ar(t)}`;if(e.normalized.set(t,To(r)),"match"in r)T2(e,t,r.match,i);else N2(e,r,i)}R2(e)}function T2(e,t,r,i){let n=new Map,o=new Map;ax(e,r,`${i}/match`,new Set,n,o);for(let[c,u]of n)if((o.get(c)??0)===0)e.add("PL_VARIABLE_SCOPE",u.pointer,`Variable ${c} is declared but never used.`);let s=Pv(r),a=Cp(s,t);for(let[c,u]of a.entries()){let l=Ba(u);if(l===void 0){e.add("PL_TARGET",`${i}/match`,`Normalized branch ${c} must use object or both source and target, without mixing target modes.`);continue}if(!c$(u))e.add("PL_CONNECTIVITY",`${i}/match`,`Normalized ${l} branch ${c} does not connect subject, its target terms, and every scoped term.`)}}function ax(e,t,r,i,n,o){if(P2(t)){if(e.resolveEdge(t.class,`${r}/class`),l$(e,t.source,`${r}/source`,i,o),l$(e,t.target,`${r}/target`,i,o),t.repeat!==void 0){let{min:c,max:u}=t.repeat;if(!Number.isInteger(c)||!Number.isInteger(u)||c<0||u<c||u>mu)e.add("PL_REPEAT",`${r}/repeat`,`Repeat requires integral bounds 0 <= min <= max <= ${mu}.`)}return}if("exists"in t){if(t.exists.nodes.length>Xv)e.add("PL_BUDGET",`${r}/exists/nodes`,`An exists expression declares ${t.exists.nodes.length} variables; the maximum is ${Xv}.`);let c=new Set(i);for(let[u,l]of t.exists.nodes.entries()){let d=l.variable.id,f=`${r}/exists/nodes/${u}`;if(n.has(d))e.add("PL_VARIABLE_SCOPE",`${f}/variable/id`,`Variable ${d} is declared more than once; variable IDs are globally unique.`);else n.set(d,{ref:l.class,pointer:f});if(c.has(d))e.add("PL_VARIABLE_SCOPE",`${f}/variable/id`,`Variable ${d} shadows an enclosing variable.`);c.add(d),e.resolveNodeClass(l.class,`${f}/class`)}ax(e,t.exists.where,`${r}/exists/where`,c,n,o);return}let{key:s,values:a}=j2(t);if(a.length===0)e.add("PL_COMPOSITION",`${r}/${s}`,`${s} must be non-empty.`);a.forEach((c,u)=>ax(e,c,`${r}/${s}/${u}`,i,n,o))}function l$(e,t,r,i,n){if(t.kind==="variable")if(!i.has(t.id))e.add("PL_VARIABLE_SCOPE",r,`Variable ${t.id} is free, escaped, or outside its defining exists scope.`);else n.set(t.id,(n.get(t.id)??0)+1)}function N2(e,t,r){let i="allOf"in t?"allOf":"anyOf",n="allOf"in t?t.allOf:t.anyOf;if(n.length===0)e.add("PL_COMPOSITION",`${r}/${i}`,`${i} must be non-empty.`);n.forEach((o,s)=>e.resolvePolicy(o,`${r}/${i}/${s}`))}function R2(e){let t=new Set,r=new Set,i=(n,o)=>{if(t.has(n)){e.add("PL_COMPOSITION",`/policies/${Ar(n)}`,`Named Policy composition cycle: ${[...o,n].join(" -> ")}.`);return}if(r.has(n))return;t.add(n);let s=e.environment.candidate.policies[n];if(s!==void 0&&!("match"in s)){let a="allOf"in s?s.allOf:s.anyOf;for(let c of a)if(c.origin===e.environment.candidate.origin&&c.kind==="policy")i(c.name,[...o,n])}t.delete(n),r.add(n)};for(let n of Object.keys(e.environment.candidate.policies))i(n,[])}function j2(e){return"allOf"in e?{key:"allOf",values:e.allOf}:{key:"anyOf",values:e.anyOf}}function P2(e){return"source"in e}var f$={origin:"kernel.astrale.ai",kind:"interface",name:"Identity"};class cx{context;constructor(e){this.context=e}validatePolicies(){for(let e of Object.keys(this.context.environment.candidate.policies)){let t=this.#e(e,new Set,`$${e}`);if(t===void 0)continue;for(let[r,i]of t.entries()){let n=Ba(i);if(n===void 0){if(!("match"in this.context.environment.candidate.policies[e]))this.context.add("PL_TARGET",`/policies/${Ar(e)}`,`Expanded normalized branch ${r} must use object or both source and target, without mixing target modes.`);continue}let o=n==="object"?{kind:"object",object:{kind:"default"}}:{kind:"edge",source:{kind:"default"},target:{kind:"default"}};if(!this.#t(i,o))this.context.add("PL_TYPING",`/policies/${Ar(e)}`,`Expanded normalized branch ${r} has contradictory endpoint or repeat contracts.`)}}}policyAccepts(e,t){let r=this.#e(e,new Set,`$use:${e}`),i={kind:"object",object:t};return r!==void 0&&r.every((n)=>this.#t(n,i))}policyAcceptsEdge(e,t,r){let i=this.#e(e,new Set,`$edge-use:${e}`),n={kind:"edge",source:t,target:r};return i!==void 0&&i.every((o)=>this.#t(o,n))}concreteEndpointClasses(e){return this.context.allNodeClasses.filter((t)=>this.#c(t,e))}endpointsOverlap(e,t){let r=[{kind:"open",requirements:[]}],i=this.#s(r,e);return this.#s(i,t).length>0}#e(e,t,r){if(t.has(e))return;let i=this.context.normalized.get(e);if(i===void 0)return;if("match"in i)return Cp(i.match,r);let n=new Set(t);n.add(e);let o="allOf"in i?i.allOf:i.anyOf,s=[];for(let[a,c]of o.entries()){if(!this.context.isLocalPolicy(c))return;let u=this.#e(c.name,n,`${r}/${a}:${c.name}`);if(u===void 0)return;s.push(u)}return"allOf"in i?ix(s):ox(s.flat())}#t(e,t){if(Ba(e)!==t.kind)return!1;return L2(e.edges,this).some((i)=>this.#r(e,i,t))}#r(e,t,r){let i=new Set(r.kind==="object"?["subject","object"]:["subject","source","target"]);for(let a of e.variables.keys())i.add(a);for(let a of e.edges)i.add(Mo(a.pattern.source,a.namespace)),i.add(Mo(a.pattern.target,a.namespace));let n=new g$(i);for(let a of t)for(let[c,u]of a.equalities)n.join(c,u);let o=new Map;for(let a of t)for(let[c,u]of a.constraints){let l=n.find(c),d=o.get(l)??[];d.push(u),o.set(l,d)}let s=new Map;for(let a of i){let c=n.find(a),u=s.get(c)??[];u.push(a),s.set(c,u)}for(let[a,c]of s){let u=o.get(a)??[],l=c.map((f)=>({member:f,contract:p$(f,r)})).find((f)=>f.contract?.kind==="universal-interface");if(l!==void 0){if(!this.#n(c,u,l.member,l.contract.ref,e))return!1;continue}let d=[{kind:"open",requirements:[]}];for(let f of c)if(d=this.#i(d,f,e,r),d.length===0)return!1;for(let f of u)if(d=this.#s(d,f),d.length===0)return!1}return!0}#n(e,t,r,i,n){for(let o of e){if(o===r)continue;if(o==="subject"){if(!this.context.interfaceExtends(i,f$))return!1;continue}if(this.#a(o,n)!==void 0)return!1}return t.every((o)=>o.some((s)=>s.kind==="interface"&&this.context.interfaceExtends(i,s)))}#i(e,t,r,i){if(t==="subject")return this.#u(e,f$);let n=p$(t,i);if(n!==void 0){if(n.kind==="exact")return this.#o(e,n.ref);if(n.kind==="default")return bp(this.context.allNodeClasses.flatMap((s)=>this.#o(e,s)));return e}let o=this.#a(t,r);return o===void 0?[]:this.#o(e,o)}#a(e,t){return t.variables.get(e)}#o(e,t){let r=[];for(let i of e)if(i.kind==="exact"){if(Q(i.ref)===Q(t))r.push(i)}else if(i.requirements.every((n)=>this.context.classImplements(t,n)))r.push({kind:"exact",ref:t});return bp(r)}#u(e,t){return bp(e.flatMap((r)=>{if(r.kind==="exact")return this.context.classImplements(r.ref,t)?[r]:[];return[{kind:"open",requirements:h$([...r.requirements,t])}]}))}#s(e,t){let r=[];for(let i of e){if(i.kind==="exact"){if(this.#c(i.ref,t))r.push(i);continue}for(let n of t)if(n.kind==="interface")r.push({kind:"open",requirements:h$([...i.requirements,n])});else if(i.requirements.every((o)=>this.context.classImplements(n,o)))r.push({kind:"exact",ref:n})}return bp(r)}#c(e,t){return t.some((r)=>r.kind==="class"&&Q(r)===Q(e)||r.kind==="interface"&&this.context.classImplements(e,r))}}function p$(e,t){if(t.kind==="object")return e==="object"?t.object:void 0;if(e==="source")return t.source;if(e==="target")return t.target;return}function Ep(e){return e.kind==="class"?{kind:"exact",ref:e}:{kind:"universal-interface",ref:e}}function L2(e,t){let r=[[]];for(let i of e){let n=z2(i,t);if(n.length===0)return[];let o=[];for(let s of r)for(let a of n)o.push([...s,a]);r=o}return r}function z2(e,t){let r=e.pattern,i=t.context.edgeDeclaration(r.class);if(i===void 0)return[];let n=i.orientation==="directed"?[i.endpoints.source,i.endpoints.target]:i.endpoints,o=r.repeat??{min:1,max:1};if(!Number.isInteger(o.min)||!Number.isInteger(o.max)||o.min<0||o.max<o.min||o.max>mu)return[];let s=Mo(r.source,e.namespace),a=Mo(r.target,e.namespace),c=[];for(let u=o.min;u<=o.max;u++){if(u===0){c.push({constraints:[],equalities:[[s,a]]});continue}let l=i.orientation==="undirected"?2**u:1;for(let d=0;d<l;d++){let f=Array.from({length:u},(g,w)=>i.orientation==="undirected"&&(d&1<<w)!==0),m=!0;for(let g=0;g+1<u;g++){let w=B$(n,f[g]??!1),b=m$(n,f[g+1]??!1);if(!t.endpointsOverlap(w.accepts,b.accepts)){m=!1;break}}if(!m)continue;let B=m$(n,f[0]??!1),h=B$(n,f[u-1]??!1);c.push({constraints:[[s,B.accepts],[a,h.accepts]],equalities:[]})}}return M2(c)}function m$(e,t){return t?e[1]:e[0]}function B$(e,t){return t?e[0]:e[1]}function M2(e){let t=new Map;for(let r of e){let i=`${r.constraints.map(([n,o])=>`${n}:${o.map(Q).sort().join(",")}`).join("|")}=${r.equalities.map(([n,o])=>`${n}:${o}`).join("|")}`;t.set(i,r)}return[...t.values()]}function bp(e){let t=new Map;for(let r of e){let i=r.kind==="exact"?`exact:${Q(r.ref)}`:`open:${r.requirements.map(Q).sort().join("|")}`;t.set(i,r)}return[...t.values()]}function h$(e){return[...new Map(e.map((t)=>[Q(t),t])).values()]}class g${#e=new Map;constructor(e){for(let t of e)this.add(t)}add(e){if(!this.#e.has(e))this.#e.set(e,e)}find(e){this.add(e);let t=this.#e.get(e);if(t===e)return e;let r=this.find(t);return this.#e.set(e,r),r}join(e,t){let r=this.find(e),i=this.find(t);if(r!==i)this.#e.set(i,r)}}var U2="kernel.astrale.ai",F2=hu("Class"),G2=hu("Function"),H2=hu("Interface"),V2=hu("Policy"),q2=hu("View");function b$(e,t){for(let[r,i]of Object.entries(e.environment.candidate.classes)){if(i.family!=="node"||i.policies.read===void 0)continue;let n=`/classes/${Ar(r)}/policies/read`,o=i.policies.read;if(!e.resolvePolicy(o,n))continue;let s={kind:"exact",ref:{origin:e.environment.candidate.origin,kind:"class",name:r}};if(!t.policyAccepts(o.name,s))e.add("PL_USE",n,`${Be(o)} is not valid for every normalized branch of protected Class ${r}.`,Be(o))}}function E$(e,t){for(let[r,i]of Object.entries(e.environment.candidate.classes)){let n=i.policies.traverse;if(n===void 0)continue;let o=`/classes/${Ar(r)}/policies/traverse`;if(!e.resolvePolicy(n,o))continue;if(i.family==="node"){let l={kind:"exact",ref:{origin:e.environment.candidate.origin,kind:"class",name:r}};if(!t.policyAccepts(n.name,l))e.add("PL_USE",o,`${Be(n)} is not valid for every normalized branch of traversed Node Class ${r}.`,Be(n));continue}let s=i.orientation==="directed"?[i.endpoints.source,i.endpoints.target]:i.endpoints,a=t.concreteEndpointClasses(s[0].accepts),c=t.concreteEndpointClasses(s[1].accepts),u=!0;for(let l of a){for(let d of c)if(!t.policyAcceptsEdge(n.name,{kind:"exact",ref:l},{kind:"exact",ref:d})){u=!1;break}if(!u)break}if(!u)e.add("PL_USE",o,`${Be(n)} is not valid for every concrete source/target pair of traversed Edge Class ${r}.`,Be(n))}}function v$(e,t){for(let[r,i]of Object.entries(e.environment.candidate.functions)){if(i.policy===void 0)continue;x$(e,t,i.policy,{pointer:`/functions/${Ar(r)}/policy`,input:i.input,instanceMethod:!1})}for(let[r,i]of Object.entries(e.environment.candidate.interfaces)){if(i.family!=="node")continue;y$(e,t,"interfaces",r,i.methods,{origin:e.environment.candidate.origin,kind:"interface",name:r})}for(let[r,i]of Object.entries(e.environment.candidate.classes)){if(i.family!=="node")continue;y$(e,t,"classes",r,i.methods,{origin:e.environment.candidate.origin,kind:"class",name:r})}}function y$(e,t,r,i,n,o){let s=e.analysis.definitions.get(Q(o));for(let[a,c]of Object.entries(n)){if(c.policy===void 0)continue;if(s!==void 0&&!s.methods.has(a))continue;x$(e,t,c.policy,{pointer:`/${r}/${Ar(i)}/methods/${Ar(a)}/policy`,input:c.input,receiver:o,instanceMethod:!c.static})}}function x$(e,t,r,i){let n=Nn(r),o=rx(n);if(o.depth>ex||o.branches>ma||o.leaves>tx)e.add("PL_BUDGET",i.pointer,`Callable checks require depth <= ${ex}, branches <= ${ma}, and leaves <= ${tx}; got ${o.depth}, ${o.branches}, ${o.leaves}.`);w$(e,t,n,i,i.pointer)}function w$(e,t,r,i,n){if("check"in r){if(!e.resolvePolicy(r.check,`${n}/check`))return;let a=`${n}/object`,c=r.object.kind==="self"?K2(e,i,a):r.object.kind==="input"?Z2(e,i,r.object.field,a):J2(e,r.object.ref,a);if(c===void 0)return;for(let u of c)if(!t.policyAccepts(r.check.name,u)){e.add("PL_USE",n,`${Be(r.check)} is incompatible with the callable object contract.`,Be(r.check));break}return}let{key:o,values:s}=Y2(r);if(s.length===0)e.add("PL_COMPOSITION",`${n}/${o}`,`${o} must be non-empty.`);s.forEach((a,c)=>w$(e,t,a,i,`${n}/${o}/${c}`))}function J2(e,t,r){let i=e.environment.candidate;if(t.origin!==i.origin)return Uo(e,t,r);switch(t.kind){case"interface":return e.environment.resolve(t)?.ref.kind===t.kind?[{kind:"exact",ref:H2}]:Uo(e,t,r);case"class":return e.environment.resolve(t)?.ref.kind===t.kind?[{kind:"exact",ref:F2}]:Uo(e,t,r);case"function":return i.functions[t.name]===void 0?Uo(e,t,r):[{kind:"exact",ref:G2}];case"policy":return i.policies[t.name]===void 0?Uo(e,t,r):[{kind:"exact",ref:V2}];case"view":return i.views[t.name]===void 0?Uo(e,t,r):[{kind:"exact",ref:q2}];case"core":{let n=i.core.nodes[t.name];if(n===void 0)return Uo(e,t,r);let o=e.environment.resolve(n.class),s=e.analysis.definitions.get(Q(n.class));if(n.class.origin!==i.origin||o?.ref.kind!=="class"||o.family!=="node"||s===void 0)return;return[Ep(n.class)]}}}function Uo(e,t,r){e.add("PL_REF",`${r}/ref`,`${Be(t)} is not an exact local projected Policy object.`,Be(t));return}function K2(e,t,r){if(!t.instanceMethod||t.receiver===void 0){e.add("PL_USE",r,"self is valid only for a Node instance Method.");return}return[Ep(t.receiver)]}function Z2(e,t,r,i){let n=Bu(t.input),o=Bu(n?.properties),s=Bu(o?.[r]),a=n?.required,c=n?.type==="object"&&o!==void 0&&Array.isArray(a)&&a.includes(r)&&n.additionalProperties===!1&&!C$(n),u=Bu(s?.["x-astrale-path"]);if(!(c&&s?.$ref===jt&&!C$(s)&&u?.target==="node"&&u.cardinality==="one"&&Array.isArray(u.accepts)&&u.accepts.length>0)){e.add("PL_USE",i,`input.${r} must be one direct required single-Node x-astrale-path field of a closed object input.`);return}let d=[];for(let f of u.accepts){if(!W2(f)){e.add("PL_USE",i,`input.${r} has a non-Node acceptance ref.`);return}let m=e.environment.resolve(f);if(m===void 0||m.family!=="node"){e.add("PL_USE",i,`input.${r} ref ${Be(f)} does not resolve as an allowed Node Definition.`,Be(f));return}d.push(Ep(f))}return d}function Bu(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)?e:void 0}function C$(e){return["allOf","anyOf","oneOf","not","if","then","else"].some((t)=>Object.hasOwn(e,t))}function W2(e){let t=Bu(e);return t!==void 0&&typeof t.origin==="string"&&(t.kind==="class"||t.kind==="interface")&&typeof t.name==="string"}function Y2(e){return"allOf"in e?{key:"allOf",values:e.allOf}:{key:"anyOf",values:e.anyOf}}function hu(e){return{origin:U2,kind:"class",name:e}}function I$(e,t){let r=new Yv(e,t);d$(r),o$(r);let i=new cx(r);return i.validatePolicies(),b$(r,i),E$(r,i),v$(r,i),Object.freeze(r.diagnostics)}function O$(e,t,r,i){let n=[];return Pr(e,(o)=>{if(!ye(o.schema)||!Object.hasOwn(o.schema,"x-astrale-path"))return;let s=`${r}${o.pointer}/x-astrale-path`,a=lu(`#${o.pointer}`),c=a?.length===2&&a[0]==="properties"?a[1]:void 0,u=ye(e)?e:void 0;if(!(t==="callable-input"&&u?.type==="object"&&o.depth===1&&o.parentKeyword==="properties"&&c!==void 0&&Array.isArray(u?.required)&&u.required.includes(c)))n.push(_("VS_PATH_EXTENSION",s,"x-astrale-path is allowed only on a direct required property schema at a callable-input object root."));if(Object.keys(o.schema).length!==2||!Object.hasOwn(o.schema,"$ref")||o.schema.$ref!==jt)n.push(_("VS_PATH_EXTENSION",`${r}${o.pointer}`,`A Path field schema contains exactly $ref ${jt} and x-astrale-path.`,jt));let f=o.schema["x-astrale-path"];if(!ye(f)){n.push(_("VS_PATH_EXTENSION",s,"x-astrale-path must be a closed annotation object."));return}if(!D$(f,["target","cardinality","accepts"]))n.push(_("VS_PATH_EXTENSION",s,"x-astrale-path contains exactly target, cardinality, and accepts."));if(f.target!=="node"||f.cardinality!=="one")n.push(_("VS_PATH_EXTENSION",s,"A V1 Path field resolves exactly one Node."));if(!Array.isArray(f.accepts)||f.accepts.length===0){n.push(_("VS_PATH_EXTENSION",`${s}/accepts`,"x-astrale-path.accepts must be a non-empty Node Definition ref set."));return}let m=new Set;f.accepts.forEach((B,h)=>{let g=`${s}/accepts/${h}`;if(!Q2(B)){n.push(_("VS_PATH_EXTENSION",g,"Path acceptance entries are exact node-family class or interface refs."));return}let w=Q(B);if(m.has(w))n.push(_("VS_PATH_EXTENSION",g,"x-astrale-path.accepts rejects duplicate Definition refs."));if(m.add(w),!i(B))n.push(_("VS_REFERENCE_RESOLUTION",g,"Path acceptance Definition is absent from the current/direct exact registry."))})}),n}function Q2(e){return ye(e)&&D$(e,["origin","kind","name"])&&typeof e.origin==="string"&&kr.test(e.origin)&&(e.kind==="interface"||e.kind==="class")&&typeof e.name==="string"&&Sr.test(e.name)}function D$(e,t){return Object.keys(e).length===t.length&&t.every((i)=>Object.hasOwn(e,i))}var X2=new Set(["$defs","allOf","anyOf","dependentSchemas","else","if","not","oneOf","then"]);function _$(e,t){let r=new Map,i=new Map;for(let s of e.values())Pr(s.schema,(a)=>{let c=yr(s.key,a.pointer);i.set(c,`${s.diagnosticPointer??""}${a.pointer}`);let u=r.get(c)??new Set;if(r.set(c,u),!ye(a.schema))return;let l=t.get(c);if(l!==void 0)u.add(yr(l.resource.key,l.pointer));for(let[d,f]of Object.entries(a.schema)){if(!X2.has(d))continue;let m=It(a.pointer,d);if(Vi.has(d)&&jo(f)){u.add(yr(s.key,m));continue}if(Gi.has(d)&&Array.isArray(f)){f.forEach((B,h)=>{if(jo(B))u.add(yr(s.key,It(m,h)))});continue}if(Hi.has(d)&&ye(f)){for(let[B,h]of Object.entries(f))if(jo(h))u.add(yr(s.key,It(m,B)))}}});let n=new Set,o=new Set;for(let s of r.keys()){let a=k$(s,r,n,o);if(a!==void 0)return[_("VS_RECURSION_PRODUCTIVE",i.get(a)??"","Every recursive cycle must cross an instance-consuming schema edge.")]}return[]}function k$(e,t,r,i){if(r.has(e))return e;if(i.has(e))return;r.add(e);for(let n of t.get(e)??[]){let o=k$(n,t,r,i);if(o!==void 0)return o}r.delete(e),i.add(e);return}var A$=vp;var e6={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/schema",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/core":!0,"https://json-schema.org/draft/2020-12/vocab/applicator":!0,"https://json-schema.org/draft/2020-12/vocab/unevaluated":!0,"https://json-schema.org/draft/2020-12/vocab/validation":!0,"https://json-schema.org/draft/2020-12/vocab/meta-data":!0,"https://json-schema.org/draft/2020-12/vocab/format-annotation":!0,"https://json-schema.org/draft/2020-12/vocab/content":!0},$dynamicAnchor:"meta",title:"Core and Validation specifications meta-schema",allOf:[{$ref:"meta/core"},{$ref:"meta/applicator"},{$ref:"meta/unevaluated"},{$ref:"meta/validation"},{$ref:"meta/meta-data"},{$ref:"meta/format-annotation"},{$ref:"meta/content"}],type:["object","boolean"],$comment:"This meta-schema also defines keywords that have appeared in previous drafts in order to prevent incompatible extensions as they remain in common use.",properties:{definitions:{$comment:'"definitions" has been replaced by "$defs".',type:"object",additionalProperties:{$dynamicRef:"#meta"},deprecated:!0,default:{}},dependencies:{$comment:'"dependencies" has been split and replaced by "dependentSchemas" and "dependentRequired" in order to serve their differing semantics.',type:"object",additionalProperties:{anyOf:[{$dynamicRef:"#meta"},{$ref:"meta/validation#/$defs/stringArray"}]},deprecated:!0,default:{}},$recursiveAnchor:{$comment:'"$recursiveAnchor" has been replaced by "$dynamicAnchor".',$ref:"meta/core#/$defs/anchorString",deprecated:!0},$recursiveRef:{$comment:'"$recursiveRef" has been replaced by "$dynamicRef".',$ref:"meta/core#/$defs/uriReferenceString",deprecated:!0}}};var t6={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/core",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/core":!0},$dynamicAnchor:"meta",title:"Core vocabulary meta-schema",type:["object","boolean"],properties:{$id:{$ref:"#/$defs/uriReferenceString",$comment:"Non-empty fragments not allowed.",pattern:"^[^#]*#?$"},$schema:{$ref:"#/$defs/uriString"},$ref:{$ref:"#/$defs/uriReferenceString"},$anchor:{$ref:"#/$defs/anchorString"},$dynamicRef:{$ref:"#/$defs/uriReferenceString"},$dynamicAnchor:{$ref:"#/$defs/anchorString"},$vocabulary:{type:"object",propertyNames:{$ref:"#/$defs/uriString"},additionalProperties:{type:"boolean"}},$comment:{type:"string"},$defs:{type:"object",additionalProperties:{$dynamicRef:"#meta"}}},$defs:{anchorString:{type:"string",pattern:"^[A-Za-z_][-A-Za-z0-9._]*$"},uriString:{type:"string",format:"uri"},uriReferenceString:{type:"string",format:"uri-reference"}}};var r6=new RegExp("^[^#]*#?$","u"),ux=new RegExp("^[A-Za-z_][-A-Za-z0-9._]*$","u");function tn(e,{instancePath:t="",parentData:r,parentDataProperty:i,rootData:n=e,dynamicAnchors:o={}}={}){let s=null,a=0,c=tn.evaluated;if(c.dynamicProps)c.props=void 0;if(c.dynamicItems)c.items=void 0;if(!(e&&typeof e=="object"&&!Array.isArray(e))&&typeof e!=="boolean"){let B={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:t6.type},message:"must be object,boolean"};if(s===null)s=[B];else s.push(B);a++}if(!o.meta)o.meta=tn;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.$id!==void 0){let B=e.$id;if(typeof B!=="string"){let h={instancePath:t+"/$id",schemaPath:"#/$defs/uriReferenceString/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[h];else s.push(h);a++}if(typeof B==="string"){if(!r6.test(B)){let h={instancePath:t+"/$id",schemaPath:"#/properties/%24id/pattern",keyword:"pattern",params:{pattern:"^[^#]*#?$"},message:'must match pattern "^[^#]*#?$"'};if(s===null)s=[h];else s.push(h);a++}}}if(e.$schema!==void 0){if(typeof e.$schema!=="string"){let B={instancePath:t+"/$schema",schemaPath:"#/$defs/uriString/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[B];else s.push(B);a++}}if(e.$ref!==void 0){if(typeof e.$ref!=="string"){let B={instancePath:t+"/$ref",schemaPath:"#/$defs/uriReferenceString/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[B];else s.push(B);a++}}if(e.$anchor!==void 0){let B=e.$anchor;if(typeof B==="string"){if(!ux.test(B)){let h={instancePath:t+"/$anchor",schemaPath:"#/$defs/anchorString/pattern",keyword:"pattern",params:{pattern:"^[A-Za-z_][-A-Za-z0-9._]*$"},message:'must match pattern "^[A-Za-z_][-A-Za-z0-9._]*$"'};if(s===null)s=[h];else s.push(h);a++}}else{let h={instancePath:t+"/$anchor",schemaPath:"#/$defs/anchorString/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[h];else s.push(h);a++}}if(e.$dynamicRef!==void 0){if(typeof e.$dynamicRef!=="string"){let B={instancePath:t+"/$dynamicRef",schemaPath:"#/$defs/uriReferenceString/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[B];else s.push(B);a++}}if(e.$dynamicAnchor!==void 0){let B=e.$dynamicAnchor;if(typeof B==="string"){if(!ux.test(B)){let h={instancePath:t+"/$dynamicAnchor",schemaPath:"#/$defs/anchorString/pattern",keyword:"pattern",params:{pattern:"^[A-Za-z_][-A-Za-z0-9._]*$"},message:'must match pattern "^[A-Za-z_][-A-Za-z0-9._]*$"'};if(s===null)s=[h];else s.push(h);a++}}else{let h={instancePath:t+"/$dynamicAnchor",schemaPath:"#/$defs/anchorString/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[h];else s.push(h);a++}}if(e.$vocabulary!==void 0){let B=e.$vocabulary;if(B&&typeof B=="object"&&!Array.isArray(B)){for(let h in B){let g=a;if(typeof h!=="string"){let w={instancePath:t+"/$vocabulary",schemaPath:"#/$defs/uriString/type",keyword:"type",params:{type:"string"},message:"must be string",propertyName:h};if(s===null)s=[w];else s.push(w);a++}var u=g===a;if(!u){let w={instancePath:t+"/$vocabulary",schemaPath:"#/properties/%24vocabulary/propertyNames",keyword:"propertyNames",params:{propertyName:h},message:"property name must be valid"};if(s===null)s=[w];else s.push(w);a++}}for(let h in B)if(typeof B[h]!=="boolean"){let g={instancePath:t+"/$vocabulary/"+h.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/%24vocabulary/additionalProperties/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};if(s===null)s=[g];else s.push(g);a++}}else{let h={instancePath:t+"/$vocabulary",schemaPath:"#/properties/%24vocabulary/type",keyword:"type",params:{type:"object"},message:"must be object"};if(s===null)s=[h];else s.push(h);a++}}if(e.$comment!==void 0){if(typeof e.$comment!=="string"){let B={instancePath:t+"/$comment",schemaPath:"#/properties/%24comment/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[B];else s.push(B);a++}}if(e.$defs!==void 0){let B=e.$defs;if(B&&typeof B=="object"&&!Array.isArray(B))for(let h in B){let g=B[h],w=o.meta;if(w)if(!w(g,{instancePath:t+"/$defs/"+h.replace(/~/g,"~0").replace(/\//g,"~1"),parentData:B,parentDataProperty:h,rootData:n,dynamicAnchors:o}))s=s===null?w.errors:s.concat(w.errors),a=s.length;else var l=w.evaluated.props,d=w.evaluated.items;else if(!tn(g,{instancePath:t+"/$defs/"+h.replace(/~/g,"~0").replace(/\//g,"~1"),parentData:B,parentDataProperty:h,rootData:n,dynamicAnchors:o}))s=s===null?tn.errors:s.concat(tn.errors),a=s.length;else{var f=tn.evaluated.props;if(l!==!0&&f!==void 0)if(f===!0)l=!0;else l=l||{},Object.assign(l,f);var m=tn.evaluated.items;if(d!==!0&&m!==void 0)d=m===!0?!0:d>m?d:m}}else{let h={instancePath:t+"/$defs",schemaPath:"#/properties/%24defs/type",keyword:"type",params:{type:"object"},message:"must be object"};if(s===null)s=[h];else s.push(h);a++}}}return tn.errors=s,a===0}tn.evaluated={props:{$id:!0,$schema:!0,$ref:!0,$anchor:!0,$dynamicRef:!0,$dynamicAnchor:!0,$vocabulary:!0,$comment:!0,$defs:!0},dynamicProps:!1,dynamicItems:!1};var n6={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/applicator",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/applicator":!0},$dynamicAnchor:"meta",title:"Applicator vocabulary meta-schema",type:["object","boolean"],properties:{prefixItems:{$ref:"#/$defs/schemaArray"},items:{$dynamicRef:"#meta"},contains:{$dynamicRef:"#meta"},additionalProperties:{$dynamicRef:"#meta"},properties:{type:"object",additionalProperties:{$dynamicRef:"#meta"},default:{}},patternProperties:{type:"object",additionalProperties:{$dynamicRef:"#meta"},propertyNames:{format:"regex"},default:{}},dependentSchemas:{type:"object",additionalProperties:{$dynamicRef:"#meta"},default:{}},propertyNames:{$dynamicRef:"#meta"},if:{$dynamicRef:"#meta"},then:{$dynamicRef:"#meta"},else:{$dynamicRef:"#meta"},allOf:{$ref:"#/$defs/schemaArray"},anyOf:{$ref:"#/$defs/schemaArray"},oneOf:{$ref:"#/$defs/schemaArray"},not:{$dynamicRef:"#meta"}},$defs:{schemaArray:{type:"array",minItems:1,items:{$dynamicRef:"#meta"}}}};function St(e,{instancePath:t="",parentData:r,parentDataProperty:i,rootData:n=e,dynamicAnchors:o={}}={}){let s=null,a=0,c=St.evaluated;if(c.dynamicProps)c.props=void 0;if(c.dynamicItems)c.items=void 0;if(Array.isArray(e)){if(e.length<1){let B={instancePath:t,schemaPath:"#/minItems",keyword:"minItems",params:{limit:1},message:"must NOT have fewer than 1 items"};if(s===null)s=[B];else s.push(B);a++}let m=e.length;for(let B=0;B<m;B++){let h=e[B],g=o.meta;if(g)if(!g(h,{instancePath:t+"/"+B,parentData:e,parentDataProperty:B,rootData:n,dynamicAnchors:o}))s=s===null?g.errors:s.concat(g.errors),a=s.length;else var u=g.evaluated.props,l=g.evaluated.items;else if(!St(h,{instancePath:t+"/"+B,parentData:e,parentDataProperty:B,rootData:n,dynamicAnchors:o}))s=s===null?St.errors:s.concat(St.errors),a=s.length;else{var d=St.evaluated.props;if(u!==!0&&d!==void 0)if(d===!0)u=!0;else u=u||{},Object.assign(u,d);var f=St.evaluated.items;if(l!==!0&&f!==void 0)l=f===!0?!0:l>f?l:f}}}else{let m={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"array"},message:"must be array"};if(s===null)s=[m];else s.push(m);a++}return St.errors=s,a===0}St.evaluated={items:!0,dynamicProps:!1,dynamicItems:!1};function ae(e,{instancePath:t="",parentData:r,parentDataProperty:i,rootData:n=e,dynamicAnchors:o={}}={}){let s=null,a=0,c=ae.evaluated;if(c.dynamicProps)c.props=void 0;if(c.dynamicItems)c.items=void 0;if(!(e&&typeof e=="object"&&!Array.isArray(e))&&typeof e!=="boolean"){let Ce={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:n6.type},message:"must be object,boolean"};if(s===null)s=[Ce];else s.push(Ce);a++}if(!o.meta)o.meta=ae;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.prefixItems!==void 0){if(!St(e.prefixItems,{instancePath:t+"/prefixItems",parentData:e,parentDataProperty:"prefixItems",rootData:n,dynamicAnchors:o}))s=s===null?St.errors:s.concat(St.errors),a=s.length}if(e.items!==void 0){let Ce=e.items,J=o.meta;if(J)if(!J(Ce,{instancePath:t+"/items",parentData:e,parentDataProperty:"items",rootData:n,dynamicAnchors:o}))s=s===null?J.errors:s.concat(J.errors),a=s.length;else var u=J.evaluated.props,l=J.evaluated.items;else if(!ae(Ce,{instancePath:t+"/items",parentData:e,parentDataProperty:"items",rootData:n,dynamicAnchors:o}))s=s===null?ae.errors:s.concat(ae.errors),a=s.length;else{var d=ae.evaluated.props;if(u!==!0&&d!==void 0)if(d===!0)u=!0;else u=u||{},Object.assign(u,d);var f=ae.evaluated.items;if(l!==!0&&f!==void 0)l=f===!0?!0:l>f?l:f}}if(e.contains!==void 0){let Ce=e.contains,J=o.meta;if(J)if(!J(Ce,{instancePath:t+"/contains",parentData:e,parentDataProperty:"contains",rootData:n,dynamicAnchors:o}))s=s===null?J.errors:s.concat(J.errors),a=s.length;else var m=J.evaluated.props,B=J.evaluated.items;else if(!ae(Ce,{instancePath:t+"/contains",parentData:e,parentDataProperty:"contains",rootData:n,dynamicAnchors:o}))s=s===null?ae.errors:s.concat(ae.errors),a=s.length;else{var h=ae.evaluated.props;if(m!==!0&&h!==void 0)if(h===!0)m=!0;else m=m||{},Object.assign(m,h);var g=ae.evaluated.items;if(B!==!0&&g!==void 0)B=g===!0?!0:B>g?B:g}}if(e.additionalProperties!==void 0){let Ce=e.additionalProperties,J=o.meta;if(J)if(!J(Ce,{instancePath:t+"/additionalProperties",parentData:e,parentDataProperty:"additionalProperties",rootData:n,dynamicAnchors:o}))s=s===null?J.errors:s.concat(J.errors),a=s.length;else var w=J.evaluated.props,b=J.evaluated.items;else if(!ae(Ce,{instancePath:t+"/additionalProperties",parentData:e,parentDataProperty:"additionalProperties",rootData:n,dynamicAnchors:o}))s=s===null?ae.errors:s.concat(ae.errors),a=s.length;else{var O=ae.evaluated.props;if(w!==!0&&O!==void 0)if(O===!0)w=!0;else w=w||{},Object.assign(w,O);var k=ae.evaluated.items;if(b!==!0&&k!==void 0)b=k===!0?!0:b>k?b:k}}if(e.properties!==void 0){let Ce=e.properties;if(Ce&&typeof Ce=="object"&&!Array.isArray(Ce))for(let J in Ce){let Qn=Ce[J],Bt=o.meta;if(Bt)if(!Bt(Qn,{instancePath:t+"/properties/"+J.replace(/~/g,"~0").replace(/\//g,"~1"),parentData:Ce,parentDataProperty:J,rootData:n,dynamicAnchors:o}))s=s===null?Bt.errors:s.concat(Bt.errors),a=s.length;else var G=Bt.evaluated.props,oe=Bt.evaluated.items;else if(!ae(Qn,{instancePath:t+"/properties/"+J.replace(/~/g,"~0").replace(/\//g,"~1"),parentData:Ce,parentDataProperty:J,rootData:n,dynamicAnchors:o}))s=s===null?ae.errors:s.concat(ae.errors),a=s.length;else{var V=ae.evaluated.props;if(G!==!0&&V!==void 0)if(V===!0)G=!0;else G=G||{},Object.assign(G,V);var _e=ae.evaluated.items;if(oe!==!0&&_e!==void 0)oe=_e===!0?!0:oe>_e?oe:_e}}else{let J={instancePath:t+"/properties",schemaPath:"#/properties/properties/type",keyword:"type",params:{type:"object"},message:"must be object"};if(s===null)s=[J];else s.push(J);a++}}if(e.patternProperties!==void 0){let Ce=e.patternProperties;if(Ce&&typeof Ce=="object"&&!Array.isArray(Ce)){for(let J in Ce){var Mt=a===a;if(!Mt){let Bt={instancePath:t+"/patternProperties",schemaPath:"#/properties/patternProperties/propertyNames",keyword:"propertyNames",params:{propertyName:J},message:"property name must be valid"};if(s===null)s=[Bt];else s.push(Bt);a++}}for(let J in Ce){let Qn=Ce[J],Bt=o.meta;if(Bt)if(!Bt(Qn,{instancePath:t+"/patternProperties/"+J.replace(/~/g,"~0").replace(/\//g,"~1"),parentData:Ce,parentDataProperty:J,rootData:n,dynamicAnchors:o}))s=s===null?Bt.errors:s.concat(Bt.errors),a=s.length;else var pt=Bt.evaluated.props,Rt=Bt.evaluated.items;else if(!ae(Qn,{instancePath:t+"/patternProperties/"+J.replace(/~/g,"~0").replace(/\//g,"~1"),parentData:Ce,parentDataProperty:J,rootData:n,dynamicAnchors:o}))s=s===null?ae.errors:s.concat(ae.errors),a=s.length;else{var xr=ae.evaluated.props;if(pt!==!0&&xr!==void 0)if(xr===!0)pt=!0;else pt=pt||{},Object.assign(pt,xr);var D=ae.evaluated.items;if(Rt!==!0&&D!==void 0)Rt=D===!0?!0:Rt>D?Rt:D}}}else{let J={instancePath:t+"/patternProperties",schemaPath:"#/properties/patternProperties/type",keyword:"type",params:{type:"object"},message:"must be object"};if(s===null)s=[J];else s.push(J);a++}}if(e.dependentSchemas!==void 0){let Ce=e.dependentSchemas;if(Ce&&typeof Ce=="object"&&!Array.isArray(Ce))for(let J in Ce){let Qn=Ce[J],Bt=o.meta;if(Bt)if(!Bt(Qn,{instancePath:t+"/dependentSchemas/"+J.replace(/~/g,"~0").replace(/\//g,"~1"),parentData:Ce,parentDataProperty:J,rootData:n,dynamicAnchors:o}))s=s===null?Bt.errors:s.concat(Bt.errors),a=s.length;else var P=Bt.evaluated.props,R=Bt.evaluated.items;else if(!ae(Qn,{instancePath:t+"/dependentSchemas/"+J.replace(/~/g,"~0").replace(/\//g,"~1"),parentData:Ce,parentDataProperty:J,rootData:n,dynamicAnchors:o}))s=s===null?ae.errors:s.concat(ae.errors),a=s.length;else{var F=ae.evaluated.props;if(P!==!0&&F!==void 0)if(F===!0)P=!0;else P=P||{},Object.assign(P,F);var M=ae.evaluated.items;if(R!==!0&&M!==void 0)R=M===!0?!0:R>M?R:M}}else{let J={instancePath:t+"/dependentSchemas",schemaPath:"#/properties/dependentSchemas/type",keyword:"type",params:{type:"object"},message:"must be object"};if(s===null)s=[J];else s.push(J);a++}}if(e.propertyNames!==void 0){let Ce=e.propertyNames,J=o.meta;if(J)if(!J(Ce,{instancePath:t+"/propertyNames",parentData:e,parentDataProperty:"propertyNames",rootData:n,dynamicAnchors:o}))s=s===null?J.errors:s.concat(J.errors),a=s.length;else var de=J.evaluated.props,fe=J.evaluated.items;else if(!ae(Ce,{instancePath:t+"/propertyNames",parentData:e,parentDataProperty:"propertyNames",rootData:n,dynamicAnchors:o}))s=s===null?ae.errors:s.concat(ae.errors),a=s.length;else{var le=ae.evaluated.props;if(de!==!0&&le!==void 0)if(le===!0)de=!0;else de=de||{},Object.assign(de,le);var Ie=ae.evaluated.items;if(fe!==!0&&Ie!==void 0)fe=Ie===!0?!0:fe>Ie?fe:Ie}}if(e.if!==void 0){let Ce=e.if,J=o.meta;if(J)if(!J(Ce,{instancePath:t+"/if",parentData:e,parentDataProperty:"if",rootData:n,dynamicAnchors:o}))s=s===null?J.errors:s.concat(J.errors),a=s.length;else var Se=J.evaluated.props,wt=J.evaluated.items;else if(!ae(Ce,{instancePath:t+"/if",parentData:e,parentDataProperty:"if",rootData:n,dynamicAnchors:o}))s=s===null?ae.errors:s.concat(ae.errors),a=s.length;else{var rr=ae.evaluated.props;if(Se!==!0&&rr!==void 0)if(rr===!0)Se=!0;else Se=Se||{},Object.assign(Se,rr);var Ht=ae.evaluated.items;if(wt!==!0&&Ht!==void 0)wt=Ht===!0?!0:wt>Ht?wt:Ht}}if(e.then!==void 0){let Ce=e.then,J=o.meta;if(J)if(!J(Ce,{instancePath:t+"/then",parentData:e,parentDataProperty:"then",rootData:n,dynamicAnchors:o}))s=s===null?J.errors:s.concat(J.errors),a=s.length;else var Oi=J.evaluated.props,Di=J.evaluated.items;else if(!ae(Ce,{instancePath:t+"/then",parentData:e,parentDataProperty:"then",rootData:n,dynamicAnchors:o}))s=s===null?ae.errors:s.concat(ae.errors),a=s.length;else{var vs=ae.evaluated.props;if(Oi!==!0&&vs!==void 0)if(vs===!0)Oi=!0;else Oi=Oi||{},Object.assign(Oi,vs);var xs=ae.evaluated.items;if(Di!==!0&&xs!==void 0)Di=xs===!0?!0:Di>xs?Di:xs}}if(e.else!==void 0){let Ce=e.else,J=o.meta;if(J)if(!J(Ce,{instancePath:t+"/else",parentData:e,parentDataProperty:"else",rootData:n,dynamicAnchors:o}))s=s===null?J.errors:s.concat(J.errors),a=s.length;else var yo=J.evaluated.props,ct=J.evaluated.items;else if(!ae(Ce,{instancePath:t+"/else",parentData:e,parentDataProperty:"else",rootData:n,dynamicAnchors:o}))s=s===null?ae.errors:s.concat(ae.errors),a=s.length;else{var Yr=ae.evaluated.props;if(yo!==!0&&Yr!==void 0)if(Yr===!0)yo=!0;else yo=yo||{},Object.assign(yo,Yr);var Hl=ae.evaluated.items;if(ct!==!0&&Hl!==void 0)ct=Hl===!0?!0:ct>Hl?ct:Hl}}if(e.allOf!==void 0){if(!St(e.allOf,{instancePath:t+"/allOf",parentData:e,parentDataProperty:"allOf",rootData:n,dynamicAnchors:o}))s=s===null?St.errors:s.concat(St.errors),a=s.length}if(e.anyOf!==void 0){if(!St(e.anyOf,{instancePath:t+"/anyOf",parentData:e,parentDataProperty:"anyOf",rootData:n,dynamicAnchors:o}))s=s===null?St.errors:s.concat(St.errors),a=s.length}if(e.oneOf!==void 0){if(!St(e.oneOf,{instancePath:t+"/oneOf",parentData:e,parentDataProperty:"oneOf",rootData:n,dynamicAnchors:o}))s=s===null?St.errors:s.concat(St.errors),a=s.length}if(e.not!==void 0){let Ce=e.not,J=o.meta;if(J)if(!J(Ce,{instancePath:t+"/not",parentData:e,parentDataProperty:"not",rootData:n,dynamicAnchors:o}))s=s===null?J.errors:s.concat(J.errors),a=s.length;else var pc=J.evaluated.props,Vl=J.evaluated.items;else if(!ae(Ce,{instancePath:t+"/not",parentData:e,parentDataProperty:"not",rootData:n,dynamicAnchors:o}))s=s===null?ae.errors:s.concat(ae.errors),a=s.length;else{var ih=ae.evaluated.props;if(pc!==!0&&ih!==void 0)if(ih===!0)pc=!0;else pc=pc||{},Object.assign(pc,ih);var ql=ae.evaluated.items;if(Vl!==!0&&ql!==void 0)Vl=ql===!0?!0:Vl>ql?Vl:ql}}}return ae.errors=s,a===0}ae.evaluated={props:{prefixItems:!0,items:!0,contains:!0,additionalProperties:!0,properties:!0,patternProperties:!0,dependentSchemas:!0,propertyNames:!0,if:!0,then:!0,else:!0,allOf:!0,anyOf:!0,oneOf:!0,not:!0},dynamicProps:!1,dynamicItems:!1};var i6={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/unevaluated",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/unevaluated":!0},$dynamicAnchor:"meta",title:"Unevaluated applicator vocabulary meta-schema",type:["object","boolean"],properties:{unevaluatedItems:{$dynamicRef:"#meta"},unevaluatedProperties:{$dynamicRef:"#meta"}}};function Zt(e,{instancePath:t="",parentData:r,parentDataProperty:i,rootData:n=e,dynamicAnchors:o={}}={}){let s=null,a=0,c=Zt.evaluated;if(c.dynamicProps)c.props=void 0;if(c.dynamicItems)c.items=void 0;if(!(e&&typeof e=="object"&&!Array.isArray(e))&&typeof e!=="boolean"){let w={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:i6.type},message:"must be object,boolean"};if(s===null)s=[w];else s.push(w);a++}if(!o.meta)o.meta=Zt;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.unevaluatedItems!==void 0){let w=e.unevaluatedItems,b=o.meta;if(b)if(!b(w,{instancePath:t+"/unevaluatedItems",parentData:e,parentDataProperty:"unevaluatedItems",rootData:n,dynamicAnchors:o}))s=s===null?b.errors:s.concat(b.errors),a=s.length;else var u=b.evaluated.props,l=b.evaluated.items;else if(!Zt(w,{instancePath:t+"/unevaluatedItems",parentData:e,parentDataProperty:"unevaluatedItems",rootData:n,dynamicAnchors:o}))s=s===null?Zt.errors:s.concat(Zt.errors),a=s.length;else{var d=Zt.evaluated.props;if(u!==!0&&d!==void 0)if(d===!0)u=!0;else u=u||{},Object.assign(u,d);var f=Zt.evaluated.items;if(l!==!0&&f!==void 0)l=f===!0?!0:l>f?l:f}}if(e.unevaluatedProperties!==void 0){let w=e.unevaluatedProperties,b=o.meta;if(b)if(!b(w,{instancePath:t+"/unevaluatedProperties",parentData:e,parentDataProperty:"unevaluatedProperties",rootData:n,dynamicAnchors:o}))s=s===null?b.errors:s.concat(b.errors),a=s.length;else var m=b.evaluated.props,B=b.evaluated.items;else if(!Zt(w,{instancePath:t+"/unevaluatedProperties",parentData:e,parentDataProperty:"unevaluatedProperties",rootData:n,dynamicAnchors:o}))s=s===null?Zt.errors:s.concat(Zt.errors),a=s.length;else{var h=Zt.evaluated.props;if(m!==!0&&h!==void 0)if(h===!0)m=!0;else m=m||{},Object.assign(m,h);var g=Zt.evaluated.items;if(B!==!0&&g!==void 0)B=g===!0?!0:B>g?B:g}}}return Zt.errors=s,a===0}Zt.evaluated={props:{unevaluatedItems:!0,unevaluatedProperties:!0},dynamicProps:!1,dynamicItems:!1};var o6={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/validation",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/validation":!0},$dynamicAnchor:"meta",title:"Validation vocabulary meta-schema",type:["object","boolean"],properties:{type:{anyOf:[{$ref:"#/$defs/simpleTypes"},{type:"array",items:{$ref:"#/$defs/simpleTypes"},minItems:1,uniqueItems:!0}]},const:!0,enum:{type:"array",items:!0},multipleOf:{type:"number",exclusiveMinimum:0},maximum:{type:"number"},exclusiveMaximum:{type:"number"},minimum:{type:"number"},exclusiveMinimum:{type:"number"},maxLength:{$ref:"#/$defs/nonNegativeInteger"},minLength:{$ref:"#/$defs/nonNegativeIntegerDefault0"},pattern:{type:"string",format:"regex"},maxItems:{$ref:"#/$defs/nonNegativeInteger"},minItems:{$ref:"#/$defs/nonNegativeIntegerDefault0"},uniqueItems:{type:"boolean",default:!1},maxContains:{$ref:"#/$defs/nonNegativeInteger"},minContains:{$ref:"#/$defs/nonNegativeInteger",default:1},maxProperties:{$ref:"#/$defs/nonNegativeInteger"},minProperties:{$ref:"#/$defs/nonNegativeIntegerDefault0"},required:{$ref:"#/$defs/stringArray"},dependentRequired:{type:"object",additionalProperties:{$ref:"#/$defs/stringArray"}}},$defs:{nonNegativeInteger:{type:"integer",minimum:0},nonNegativeIntegerDefault0:{$ref:"#/$defs/nonNegativeInteger",default:0},simpleTypes:{enum:["array","boolean","integer","null","number","object","string"]},stringArray:{type:"array",items:{type:"string"},uniqueItems:!0,default:[]}}},S$={enum:["array","boolean","integer","null","number","object","string"]};function Fo(e,{instancePath:t="",parentData:r,parentDataProperty:i,rootData:n=e,dynamicAnchors:o={}}={}){let s=null,a=0,c=Fo.evaluated;if(c.dynamicProps)c.props=void 0;if(c.dynamicItems)c.items=void 0;if(!(e&&typeof e=="object"&&!Array.isArray(e))&&typeof e!=="boolean"){let l={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:o6.type},message:"must be object,boolean"};if(s===null)s=[l];else s.push(l);a++}if(!o.meta)o.meta=Fo;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.type!==void 0){let l=e.type,d=a,f=!1,m=a;if(!(l==="array"||l==="boolean"||l==="integer"||l==="null"||l==="number"||l==="object"||l==="string")){let h={instancePath:t+"/type",schemaPath:"#/$defs/simpleTypes/enum",keyword:"enum",params:{allowedValues:S$.enum},message:"must be equal to one of the allowed values"};if(s===null)s=[h];else s.push(h);a++}var u=m===a;f=f||u;let B=a;if(Array.isArray(l)){if(l.length<1){let b={instancePath:t+"/type",schemaPath:"#/properties/type/anyOf/1/minItems",keyword:"minItems",params:{limit:1},message:"must NOT have fewer than 1 items"};if(s===null)s=[b];else s.push(b);a++}let h=l.length;for(let b=0;b<h;b++){let O=l[b];if(!(O==="array"||O==="boolean"||O==="integer"||O==="null"||O==="number"||O==="object"||O==="string")){let k={instancePath:t+"/type/"+b,schemaPath:"#/$defs/simpleTypes/enum",keyword:"enum",params:{allowedValues:S$.enum},message:"must be equal to one of the allowed values"};if(s===null)s=[k];else s.push(k);a++}}let g=l.length,w;if(g>1){e:for(;g--;)for(w=g;w--;)if(Nr(l[g],l[w])){let b={instancePath:t+"/type",schemaPath:"#/properties/type/anyOf/1/uniqueItems",keyword:"uniqueItems",params:{i:g,j:w},message:"must NOT have duplicate items (items ## "+w+" and "+g+" are identical)"};if(s===null)s=[b];else s.push(b);a++;break e}}}else{let h={instancePath:t+"/type",schemaPath:"#/properties/type/anyOf/1/type",keyword:"type",params:{type:"array"},message:"must be array"};if(s===null)s=[h];else s.push(h);a++}var u=B===a;if(f=f||u,!f){let h={instancePath:t+"/type",schemaPath:"#/properties/type/anyOf",keyword:"anyOf",params:{},message:"must match a schema in anyOf"};if(s===null)s=[h];else s.push(h);a++}else if(a=d,s!==null)if(d)s.length=d;else s=null}if(e.enum!==void 0){if(!Array.isArray(e.enum)){let l={instancePath:t+"/enum",schemaPath:"#/properties/enum/type",keyword:"type",params:{type:"array"},message:"must be array"};if(s===null)s=[l];else s.push(l);a++}}if(e.multipleOf!==void 0){let l=e.multipleOf;if(typeof l=="number"){if(l<=0||isNaN(l)){let d={instancePath:t+"/multipleOf",schemaPath:"#/properties/multipleOf/exclusiveMinimum",keyword:"exclusiveMinimum",params:{comparison:">",limit:0},message:"must be > 0"};if(s===null)s=[d];else s.push(d);a++}}else{let d={instancePath:t+"/multipleOf",schemaPath:"#/properties/multipleOf/type",keyword:"type",params:{type:"number"},message:"must be number"};if(s===null)s=[d];else s.push(d);a++}}if(e.maximum!==void 0){if(typeof e.maximum!="number"){let l={instancePath:t+"/maximum",schemaPath:"#/properties/maximum/type",keyword:"type",params:{type:"number"},message:"must be number"};if(s===null)s=[l];else s.push(l);a++}}if(e.exclusiveMaximum!==void 0){if(typeof e.exclusiveMaximum!="number"){let l={instancePath:t+"/exclusiveMaximum",schemaPath:"#/properties/exclusiveMaximum/type",keyword:"type",params:{type:"number"},message:"must be number"};if(s===null)s=[l];else s.push(l);a++}}if(e.minimum!==void 0){if(typeof e.minimum!="number"){let l={instancePath:t+"/minimum",schemaPath:"#/properties/minimum/type",keyword:"type",params:{type:"number"},message:"must be number"};if(s===null)s=[l];else s.push(l);a++}}if(e.exclusiveMinimum!==void 0){if(typeof e.exclusiveMinimum!="number"){let l={instancePath:t+"/exclusiveMinimum",schemaPath:"#/properties/exclusiveMinimum/type",keyword:"type",params:{type:"number"},message:"must be number"};if(s===null)s=[l];else s.push(l);a++}}if(e.maxLength!==void 0){let l=e.maxLength;if(!(typeof l=="number"&&(!(l%1)&&!isNaN(l)))){let d={instancePath:t+"/maxLength",schemaPath:"#/$defs/nonNegativeInteger/type",keyword:"type",params:{type:"integer"},message:"must be integer"};if(s===null)s=[d];else s.push(d);a++}if(typeof l=="number"){if(l<0||isNaN(l)){let d={instancePath:t+"/maxLength",schemaPath:"#/$defs/nonNegativeInteger/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};if(s===null)s=[d];else s.push(d);a++}}}if(e.minLength!==void 0){let l=e.minLength;if(!(typeof l=="number"&&(!(l%1)&&!isNaN(l)))){let d={instancePath:t+"/minLength",schemaPath:"#/$defs/nonNegativeIntegerDefault0/type",keyword:"type",params:{type:"integer"},message:"must be integer"};if(s===null)s=[d];else s.push(d);a++}if(typeof l=="number"){if(l<0||isNaN(l)){let d={instancePath:t+"/minLength",schemaPath:"#/$defs/nonNegativeIntegerDefault0/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};if(s===null)s=[d];else s.push(d);a++}}}if(e.pattern!==void 0){if(typeof e.pattern!=="string"){let l={instancePath:t+"/pattern",schemaPath:"#/properties/pattern/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[l];else s.push(l);a++}}if(e.maxItems!==void 0){let l=e.maxItems;if(!(typeof l=="number"&&(!(l%1)&&!isNaN(l)))){let d={instancePath:t+"/maxItems",schemaPath:"#/$defs/nonNegativeInteger/type",keyword:"type",params:{type:"integer"},message:"must be integer"};if(s===null)s=[d];else s.push(d);a++}if(typeof l=="number"){if(l<0||isNaN(l)){let d={instancePath:t+"/maxItems",schemaPath:"#/$defs/nonNegativeInteger/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};if(s===null)s=[d];else s.push(d);a++}}}if(e.minItems!==void 0){let l=e.minItems;if(!(typeof l=="number"&&(!(l%1)&&!isNaN(l)))){let d={instancePath:t+"/minItems",schemaPath:"#/$defs/nonNegativeIntegerDefault0/type",keyword:"type",params:{type:"integer"},message:"must be integer"};if(s===null)s=[d];else s.push(d);a++}if(typeof l=="number"){if(l<0||isNaN(l)){let d={instancePath:t+"/minItems",schemaPath:"#/$defs/nonNegativeIntegerDefault0/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};if(s===null)s=[d];else s.push(d);a++}}}if(e.uniqueItems!==void 0){if(typeof e.uniqueItems!=="boolean"){let l={instancePath:t+"/uniqueItems",schemaPath:"#/properties/uniqueItems/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};if(s===null)s=[l];else s.push(l);a++}}if(e.maxContains!==void 0){let l=e.maxContains;if(!(typeof l=="number"&&(!(l%1)&&!isNaN(l)))){let d={instancePath:t+"/maxContains",schemaPath:"#/$defs/nonNegativeInteger/type",keyword:"type",params:{type:"integer"},message:"must be integer"};if(s===null)s=[d];else s.push(d);a++}if(typeof l=="number"){if(l<0||isNaN(l)){let d={instancePath:t+"/maxContains",schemaPath:"#/$defs/nonNegativeInteger/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};if(s===null)s=[d];else s.push(d);a++}}}if(e.minContains!==void 0){let l=e.minContains;if(!(typeof l=="number"&&(!(l%1)&&!isNaN(l)))){let d={instancePath:t+"/minContains",schemaPath:"#/$defs/nonNegativeInteger/type",keyword:"type",params:{type:"integer"},message:"must be integer"};if(s===null)s=[d];else s.push(d);a++}if(typeof l=="number"){if(l<0||isNaN(l)){let d={instancePath:t+"/minContains",schemaPath:"#/$defs/nonNegativeInteger/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};if(s===null)s=[d];else s.push(d);a++}}}if(e.maxProperties!==void 0){let l=e.maxProperties;if(!(typeof l=="number"&&(!(l%1)&&!isNaN(l)))){let d={instancePath:t+"/maxProperties",schemaPath:"#/$defs/nonNegativeInteger/type",keyword:"type",params:{type:"integer"},message:"must be integer"};if(s===null)s=[d];else s.push(d);a++}if(typeof l=="number"){if(l<0||isNaN(l)){let d={instancePath:t+"/maxProperties",schemaPath:"#/$defs/nonNegativeInteger/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};if(s===null)s=[d];else s.push(d);a++}}}if(e.minProperties!==void 0){let l=e.minProperties;if(!(typeof l=="number"&&(!(l%1)&&!isNaN(l)))){let d={instancePath:t+"/minProperties",schemaPath:"#/$defs/nonNegativeIntegerDefault0/type",keyword:"type",params:{type:"integer"},message:"must be integer"};if(s===null)s=[d];else s.push(d);a++}if(typeof l=="number"){if(l<0||isNaN(l)){let d={instancePath:t+"/minProperties",schemaPath:"#/$defs/nonNegativeIntegerDefault0/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};if(s===null)s=[d];else s.push(d);a++}}}if(e.required!==void 0){let l=e.required;if(Array.isArray(l)){let d=l.length;for(let B=0;B<d;B++)if(typeof l[B]!=="string"){let h={instancePath:t+"/required/"+B,schemaPath:"#/$defs/stringArray/items/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[h];else s.push(h);a++}let f=l.length,m;if(f>1){let B={};for(;f--;){let h=l[f];if(typeof h!=="string")continue;if(typeof B[h]=="number"){m=B[h];let g={instancePath:t+"/required",schemaPath:"#/$defs/stringArray/uniqueItems",keyword:"uniqueItems",params:{i:f,j:m},message:"must NOT have duplicate items (items ## "+m+" and "+f+" are identical)"};if(s===null)s=[g];else s.push(g);a++;break}B[h]=f}}}else{let d={instancePath:t+"/required",schemaPath:"#/$defs/stringArray/type",keyword:"type",params:{type:"array"},message:"must be array"};if(s===null)s=[d];else s.push(d);a++}}if(e.dependentRequired!==void 0){let l=e.dependentRequired;if(l&&typeof l=="object"&&!Array.isArray(l))for(let d in l){let f=l[d];if(Array.isArray(f)){let m=f.length;for(let g=0;g<m;g++)if(typeof f[g]!=="string"){let w={instancePath:t+"/dependentRequired/"+d.replace(/~/g,"~0").replace(/\//g,"~1")+"/"+g,schemaPath:"#/$defs/stringArray/items/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[w];else s.push(w);a++}let B=f.length,h;if(B>1){let g={};for(;B--;){let w=f[B];if(typeof w!=="string")continue;if(typeof g[w]=="number"){h=g[w];let b={instancePath:t+"/dependentRequired/"+d.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/$defs/stringArray/uniqueItems",keyword:"uniqueItems",params:{i:B,j:h},message:"must NOT have duplicate items (items ## "+h+" and "+B+" are identical)"};if(s===null)s=[b];else s.push(b);a++;break}g[w]=B}}}else{let m={instancePath:t+"/dependentRequired/"+d.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/$defs/stringArray/type",keyword:"type",params:{type:"array"},message:"must be array"};if(s===null)s=[m];else s.push(m);a++}}else{let d={instancePath:t+"/dependentRequired",schemaPath:"#/properties/dependentRequired/type",keyword:"type",params:{type:"object"},message:"must be object"};if(s===null)s=[d];else s.push(d);a++}}}return Fo.errors=s,a===0}Fo.evaluated={props:{type:!0,const:!0,enum:!0,multipleOf:!0,maximum:!0,exclusiveMaximum:!0,minimum:!0,exclusiveMinimum:!0,maxLength:!0,minLength:!0,pattern:!0,maxItems:!0,minItems:!0,uniqueItems:!0,maxContains:!0,minContains:!0,maxProperties:!0,minProperties:!0,required:!0,dependentRequired:!0},dynamicProps:!1,dynamicItems:!1};var s6={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/meta-data",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/meta-data":!0},$dynamicAnchor:"meta",title:"Meta-data vocabulary meta-schema",type:["object","boolean"],properties:{title:{type:"string"},description:{type:"string"},default:!0,deprecated:{type:"boolean",default:!1},readOnly:{type:"boolean",default:!1},writeOnly:{type:"boolean",default:!1},examples:{type:"array",items:!0}}};function Go(e,{instancePath:t="",parentData:r,parentDataProperty:i,rootData:n=e,dynamicAnchors:o={}}={}){let s=null,a=0,c=Go.evaluated;if(c.dynamicProps)c.props=void 0;if(c.dynamicItems)c.items=void 0;if(!(e&&typeof e=="object"&&!Array.isArray(e))&&typeof e!=="boolean"){let u={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:s6.type},message:"must be object,boolean"};if(s===null)s=[u];else s.push(u);a++}if(!o.meta)o.meta=Go;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.title!==void 0){if(typeof e.title!=="string"){let u={instancePath:t+"/title",schemaPath:"#/properties/title/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[u];else s.push(u);a++}}if(e.description!==void 0){if(typeof e.description!=="string"){let u={instancePath:t+"/description",schemaPath:"#/properties/description/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[u];else s.push(u);a++}}if(e.deprecated!==void 0){if(typeof e.deprecated!=="boolean"){let u={instancePath:t+"/deprecated",schemaPath:"#/properties/deprecated/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};if(s===null)s=[u];else s.push(u);a++}}if(e.readOnly!==void 0){if(typeof e.readOnly!=="boolean"){let u={instancePath:t+"/readOnly",schemaPath:"#/properties/readOnly/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};if(s===null)s=[u];else s.push(u);a++}}if(e.writeOnly!==void 0){if(typeof e.writeOnly!=="boolean"){let u={instancePath:t+"/writeOnly",schemaPath:"#/properties/writeOnly/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};if(s===null)s=[u];else s.push(u);a++}}if(e.examples!==void 0){if(!Array.isArray(e.examples)){let u={instancePath:t+"/examples",schemaPath:"#/properties/examples/type",keyword:"type",params:{type:"array"},message:"must be array"};if(s===null)s=[u];else s.push(u);a++}}}return Go.errors=s,a===0}Go.evaluated={props:{title:!0,description:!0,default:!0,deprecated:!0,readOnly:!0,writeOnly:!0,examples:!0},dynamicProps:!1,dynamicItems:!1};var a6={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/format-annotation",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/format-annotation":!0},$dynamicAnchor:"meta",title:"Format vocabulary meta-schema for annotation results",type:["object","boolean"],properties:{format:{type:"string"}}};function Ho(e,{instancePath:t="",parentData:r,parentDataProperty:i,rootData:n=e,dynamicAnchors:o={}}={}){let s=null,a=0,c=Ho.evaluated;if(c.dynamicProps)c.props=void 0;if(c.dynamicItems)c.items=void 0;if(!(e&&typeof e=="object"&&!Array.isArray(e))&&typeof e!=="boolean"){let u={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:a6.type},message:"must be object,boolean"};if(s===null)s=[u];else s.push(u);a++}if(!o.meta)o.meta=Ho;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.format!==void 0){if(typeof e.format!=="string"){let u={instancePath:t+"/format",schemaPath:"#/properties/format/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[u];else s.push(u);a++}}}return Ho.errors=s,a===0}Ho.evaluated={props:{format:!0},dynamicProps:!1,dynamicItems:!1};var c6={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/content",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/content":!0},$dynamicAnchor:"meta",title:"Content vocabulary meta-schema",type:["object","boolean"],properties:{contentEncoding:{type:"string"},contentMediaType:{type:"string"},contentSchema:{$dynamicRef:"#meta"}}};function rn(e,{instancePath:t="",parentData:r,parentDataProperty:i,rootData:n=e,dynamicAnchors:o={}}={}){let s=null,a=0,c=rn.evaluated;if(c.dynamicProps)c.props=void 0;if(c.dynamicItems)c.items=void 0;if(!(e&&typeof e=="object"&&!Array.isArray(e))&&typeof e!=="boolean"){let m={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:c6.type},message:"must be object,boolean"};if(s===null)s=[m];else s.push(m);a++}if(!o.meta)o.meta=rn;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.contentEncoding!==void 0){if(typeof e.contentEncoding!=="string"){let m={instancePath:t+"/contentEncoding",schemaPath:"#/properties/contentEncoding/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[m];else s.push(m);a++}}if(e.contentMediaType!==void 0){if(typeof e.contentMediaType!=="string"){let m={instancePath:t+"/contentMediaType",schemaPath:"#/properties/contentMediaType/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[m];else s.push(m);a++}}if(e.contentSchema!==void 0){let m=e.contentSchema,B=o.meta;if(B)if(!B(m,{instancePath:t+"/contentSchema",parentData:e,parentDataProperty:"contentSchema",rootData:n,dynamicAnchors:o}))s=s===null?B.errors:s.concat(B.errors),a=s.length;else var u=B.evaluated.props,l=B.evaluated.items;else if(!rn(m,{instancePath:t+"/contentSchema",parentData:e,parentDataProperty:"contentSchema",rootData:n,dynamicAnchors:o}))s=s===null?rn.errors:s.concat(rn.errors),a=s.length;else{var d=rn.evaluated.props;if(u!==!0&&d!==void 0)if(d===!0)u=!0;else u=u||{},Object.assign(u,d);var f=rn.evaluated.items;if(l!==!0&&f!==void 0)l=f===!0?!0:l>f?l:f}}}return rn.errors=s,a===0}rn.evaluated={props:{contentEncoding:!0,contentMediaType:!0,contentSchema:!0},dynamicProps:!1,dynamicItems:!1};function Wt(e,{instancePath:t="",parentData:r,parentDataProperty:i,rootData:n=e,dynamicAnchors:o={}}={}){let s=null,a=0,c=Wt.evaluated;if(c.dynamicProps)c.props=void 0;if(c.dynamicItems)c.items=void 0;if(!(e&&typeof e=="object"&&!Array.isArray(e))&&typeof e!=="boolean"){let b={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:e6.type},message:"must be object,boolean"};if(s===null)s=[b];else s.push(b);a++}if(!o.meta)o.meta=Wt;if(!tn(e,{instancePath:t,parentData:r,parentDataProperty:i,rootData:n,dynamicAnchors:o}))s=s===null?tn.errors:s.concat(tn.errors),a=s.length;if(!ae(e,{instancePath:t,parentData:r,parentDataProperty:i,rootData:n,dynamicAnchors:o}))s=s===null?ae.errors:s.concat(ae.errors),a=s.length;if(!Zt(e,{instancePath:t,parentData:r,parentDataProperty:i,rootData:n,dynamicAnchors:o}))s=s===null?Zt.errors:s.concat(Zt.errors),a=s.length;if(!Fo(e,{instancePath:t,parentData:r,parentDataProperty:i,rootData:n,dynamicAnchors:o}))s=s===null?Fo.errors:s.concat(Fo.errors),a=s.length;if(!Go(e,{instancePath:t,parentData:r,parentDataProperty:i,rootData:n,dynamicAnchors:o}))s=s===null?Go.errors:s.concat(Go.errors),a=s.length;if(!Ho(e,{instancePath:t,parentData:r,parentDataProperty:i,rootData:n,dynamicAnchors:o}))s=s===null?Ho.errors:s.concat(Ho.errors),a=s.length;if(!rn(e,{instancePath:t,parentData:r,parentDataProperty:i,rootData:n,dynamicAnchors:o}))s=s===null?rn.errors:s.concat(rn.errors),a=s.length;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.definitions!==void 0){let b=e.definitions;if(b&&typeof b=="object"&&!Array.isArray(b))for(let O in b){let k=b[O],G=o.meta;if(G)if(!G(k,{instancePath:t+"/definitions/"+O.replace(/~/g,"~0").replace(/\//g,"~1"),parentData:b,parentDataProperty:O,rootData:n,dynamicAnchors:o}))s=s===null?G.errors:s.concat(G.errors),a=s.length;else var u=G.evaluated.props,l=G.evaluated.items;else if(!Wt(k,{instancePath:t+"/definitions/"+O.replace(/~/g,"~0").replace(/\//g,"~1"),parentData:b,parentDataProperty:O,rootData:n,dynamicAnchors:o}))s=s===null?Wt.errors:s.concat(Wt.errors),a=s.length;else{var d=Wt.evaluated.props;if(u!==!0&&d!==void 0)if(d===!0)u=!0;else u=u||{},Object.assign(u,d);var f=Wt.evaluated.items;if(l!==!0&&f!==void 0)l=f===!0?!0:l>f?l:f}}else{let O={instancePath:t+"/definitions",schemaPath:"#/properties/definitions/type",keyword:"type",params:{type:"object"},message:"must be object"};if(s===null)s=[O];else s.push(O);a++}}if(e.dependencies!==void 0){let b=e.dependencies;if(b&&typeof b=="object"&&!Array.isArray(b))for(let O in b){let k=b[O],G=a,oe=!1,V=a,_e=o.meta;if(_e)if(!_e(k,{instancePath:t+"/dependencies/"+O.replace(/~/g,"~0").replace(/\//g,"~1"),parentData:b,parentDataProperty:O,rootData:n,dynamicAnchors:o}))s=s===null?_e.errors:s.concat(_e.errors),a=s.length;else var m=_e.evaluated.props,B=_e.evaluated.items;else if(!Wt(k,{instancePath:t+"/dependencies/"+O.replace(/~/g,"~0").replace(/\//g,"~1"),parentData:b,parentDataProperty:O,rootData:n,dynamicAnchors:o}))s=s===null?Wt.errors:s.concat(Wt.errors),a=s.length;else{var h=Wt.evaluated.props;if(m!==!0&&h!==void 0)if(h===!0)m=!0;else m=m||{},Object.assign(m,h);var g=Wt.evaluated.items;if(B!==!0&&g!==void 0)B=g===!0?!0:B>g?B:g}var w=V===a;oe=oe||w;let Mt=a;if(Array.isArray(k)){let pt=k.length;for(let D=0;D<pt;D++)if(typeof k[D]!=="string"){let P={instancePath:t+"/dependencies/"+O.replace(/~/g,"~0").replace(/\//g,"~1")+"/"+D,schemaPath:"meta/validation#/$defs/stringArray/items/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[P];else s.push(P);a++}let Rt=k.length,xr;if(Rt>1){let D={};for(;Rt--;){let P=k[Rt];if(typeof P!=="string")continue;if(typeof D[P]=="number"){xr=D[P];let R={instancePath:t+"/dependencies/"+O.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"meta/validation#/$defs/stringArray/uniqueItems",keyword:"uniqueItems",params:{i:Rt,j:xr},message:"must NOT have duplicate items (items ## "+xr+" and "+Rt+" are identical)"};if(s===null)s=[R];else s.push(R);a++;break}D[P]=Rt}}}else{let pt={instancePath:t+"/dependencies/"+O.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"meta/validation#/$defs/stringArray/type",keyword:"type",params:{type:"array"},message:"must be array"};if(s===null)s=[pt];else s.push(pt);a++}var w=Mt===a;if(oe=oe||w,w){if(B!==!0)B=!0}if(!oe){let pt={instancePath:t+"/dependencies/"+O.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/dependencies/additionalProperties/anyOf",keyword:"anyOf",params:{},message:"must match a schema in anyOf"};if(s===null)s=[pt];else s.push(pt);a++}else if(a=G,s!==null)if(G)s.length=G;else s=null}else{let O={instancePath:t+"/dependencies",schemaPath:"#/properties/dependencies/type",keyword:"type",params:{type:"object"},message:"must be object"};if(s===null)s=[O];else s.push(O);a++}}if(e.$recursiveAnchor!==void 0){let b=e.$recursiveAnchor;if(typeof b==="string"){if(!ux.test(b)){let O={instancePath:t+"/$recursiveAnchor",schemaPath:"meta/core#/$defs/anchorString/pattern",keyword:"pattern",params:{pattern:"^[A-Za-z_][-A-Za-z0-9._]*$"},message:'must match pattern "^[A-Za-z_][-A-Za-z0-9._]*$"'};if(s===null)s=[O];else s.push(O);a++}}else{let O={instancePath:t+"/$recursiveAnchor",schemaPath:"meta/core#/$defs/anchorString/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[O];else s.push(O);a++}}if(e.$recursiveRef!==void 0){if(typeof e.$recursiveRef!=="string"){let b={instancePath:t+"/$recursiveRef",schemaPath:"meta/core#/$defs/uriReferenceString/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[b];else s.push(b);a++}}}return Wt.errors=s,a===0}Wt.evaluated={props:{definitions:!0,dependencies:!0,$recursiveAnchor:!0,$recursiveRef:!0,contentEncoding:!0,contentMediaType:!0,contentSchema:!0,format:!0,title:!0,description:!0,default:!0,deprecated:!0,readOnly:!0,writeOnly:!0,examples:!0,type:!0,const:!0,enum:!0,multipleOf:!0,maximum:!0,exclusiveMaximum:!0,minimum:!0,exclusiveMinimum:!0,maxLength:!0,minLength:!0,pattern:!0,maxItems:!0,minItems:!0,uniqueItems:!0,maxContains:!0,minContains:!0,maxProperties:!0,minProperties:!0,required:!0,dependentRequired:!0,unevaluatedItems:!0,unevaluatedProperties:!0,prefixItems:!0,items:!0,contains:!0,additionalProperties:!0,properties:!0,patternProperties:!0,dependentSchemas:!0,propertyNames:!0,if:!0,then:!0,else:!0,allOf:!0,anyOf:!0,oneOf:!0,not:!0,$id:!0,$schema:!0,$ref:!0,$anchor:!0,$dynamicRef:!0,$dynamicAnchor:!0,$vocabulary:!0,$comment:!0,$defs:!0},dynamicProps:!1,dynamicItems:!1};function vp(e,{instancePath:t="",parentData:r,parentDataProperty:i,rootData:n=e,dynamicAnchors:o={}}={}){let s=null,a=0,c=vp.evaluated;if(c.dynamicProps)c.props=void 0;if(c.dynamicItems)c.items=void 0;if(!Wt(e,{instancePath:t,parentData:r,parentDataProperty:i,rootData:n,dynamicAnchors:o}))s=s===null?Wt.errors:s.concat(Wt.errors),a=s.length;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.fullMatch!==void 0){if(typeof e.fullMatch!=="string"){let u={instancePath:t+"/fullMatch",schemaPath:"#/properties/fullMatch/type",keyword:"type",params:{type:"string"},message:"must be string"};if(s===null)s=[u];else s.push(u);a++}}if(e["x-astrale-path"]!==void 0){let u=e["x-astrale-path"];if(!(u&&typeof u=="object"&&!Array.isArray(u))){let l={instancePath:t+"/x-astrale-path",schemaPath:"#/properties/x-astrale-path/type",keyword:"type",params:{type:"object"},message:"must be object"};if(s===null)s=[l];else s.push(l);a++}}}return vp.errors=s,a===0}vp.evaluated={props:{fullMatch:!0,"x-astrale-path":!0,definitions:!0,dependencies:!0,$recursiveAnchor:!0,$recursiveRef:!0,contentEncoding:!0,contentMediaType:!0,contentSchema:!0,format:!0,title:!0,description:!0,default:!0,deprecated:!0,readOnly:!0,writeOnly:!0,examples:!0,type:!0,const:!0,enum:!0,multipleOf:!0,maximum:!0,exclusiveMaximum:!0,minimum:!0,exclusiveMinimum:!0,maxLength:!0,minLength:!0,pattern:!0,maxItems:!0,minItems:!0,uniqueItems:!0,maxContains:!0,minContains:!0,maxProperties:!0,minProperties:!0,required:!0,dependentRequired:!0,unevaluatedItems:!0,unevaluatedProperties:!0,prefixItems:!0,items:!0,contains:!0,additionalProperties:!0,properties:!0,patternProperties:!0,dependentSchemas:!0,propertyNames:!0,if:!0,then:!0,else:!0,allOf:!0,anyOf:!0,oneOf:!0,not:!0,$id:!0,$schema:!0,$ref:!0,$anchor:!0,$dynamicRef:!0,$dynamicAnchor:!0,$vocabulary:!0,$comment:!0,$defs:!0},dynamicProps:!1,dynamicItems:!1};var $$=A$;function T$(e,t){try{if($$(e))return[];return($$.errors??[]).map((r)=>_("VS_META_SCHEMA",`${t}${r.instancePath}`,`Astrale V1 value-schema meta-schema rejected the schema: ${r.message??r.keyword}.`))}catch(r){return[_("VS_META_SCHEMA",t,`Astrale V1 value-schema meta-schema validation failed closed: ${u6(r)}.`)]}}function u6(e){return e instanceof Error?e.message:String(e)}var N$=new Set(["$anchor","$comment","$defs","$dynamicAnchor","$dynamicRef","$id","$ref","$schema","$vocabulary","additionalProperties","allOf","anyOf","const","contains","contentEncoding","contentMediaType","contentSchema","default","dependentRequired","dependentSchemas","deprecated","description","else","enum","examples","exclusiveMaximum","exclusiveMinimum","format","fullMatch","if","items","maxContains","maximum","maxItems","maxLength","maxProperties","minContains","minimum","minItems","minLength","minProperties","multipleOf","not","oneOf","pattern","patternProperties","prefixItems","properties","propertyNames","readOnly","required","then","title","type","unevaluatedItems","unevaluatedProperties","uniqueItems","writeOnly","x-astrale-path","x-astrale-value-kind"]),R$=new Set(["$anchor","$dynamicAnchor","$dynamicRef","$vocabulary"]);function j$(e,t,r,i){let n=[];if(t==="named-type"&&i===void 0)n.push(_("VS_RESOURCE_ID",r,"A named-type schema must have one exact identity in the supplied registry."));if(Pr(e,(o)=>{if(!ye(o.schema))return;let s=`${r}${o.pointer}`;for(let a of Object.keys(o.schema)){if(!N$.has(a))n.push(_("VS_KEYWORD_CLOSED",`${s}/${gu(a)}`,`Keyword ${a} is outside the closed V1 Draft 2020-12 vocabulary.`));if(R$.has(a))n.push(_("VS_DYNAMIC_FORBIDDEN",`${s}/${gu(a)}`,`Keyword ${a} is forbidden by V1.`))}if(Object.hasOwn(o.schema,"$schema")){if(o.depth!==0||o.schema.$schema!==Po)n.push(_("VS_DIALECT",`${s}/$schema`,`Embedded-root $schema is optional, but when present must equal ${Po}.`))}if(Object.hasOwn(o.schema,"$id")){let a=o.depth===0&&t==="named-type"&&i!==void 0?Bn(i.origin,i.name):void 0;if(a===void 0||o.schema.$id!==a)n.push(_("VS_RESOURCE_ID",`${s}/$id`,a===void 0?"$id is forbidden outside a named-type embedded root.":`Named-type $id must be absent or equal ${a}.`))}d6(o.schema,s,n),l6(o.schema,s,n),f6(o.schema,s,n)}),t==="property-facet")p6(e,r,n);return n}function l6(e,t,r){if(!Object.hasOwn(e,"x-astrale-value-kind"))return;if(e["x-astrale-value-kind"]!=="instant"||e.type!=="string")r.push(_("VS_VALUE_KIND",`${t}/x-astrale-value-kind`,"x-astrale-value-kind is exactly instant and requires type string at the same schema location."))}function d6(e,t,r){if(Array.isArray(e.type))lx(e.type,`${t}/type`,"type",r);if(Array.isArray(e.required))lx(e.required,`${t}/required`,"required",r);if(Array.isArray(e.enum))m6(e.enum,`${t}/enum`,"enum",r);if(ye(e.dependentRequired)){for(let[i,n]of Object.entries(e.dependentRequired))if(Array.isArray(n))lx(n,`${t}/dependentRequired/${gu(i)}`,"dependentRequired",r)}}function f6(e,t,r){if(Object.hasOwn(e,"fullMatch")&&typeof e.fullMatch!=="string")r.push(_("VS_META_SCHEMA",`${t}/fullMatch`,"fullMatch must be an I-Regexp source string."));if(typeof e.fullMatch==="string"&&!Ui(e.fullMatch))r.push(_("VS_REGEX_PORTABLE",`${t}/fullMatch`,"fullMatch must satisfy the complete RFC 9485 I-Regexp syntax."));if(typeof e.pattern==="string"&&!Ui(e.pattern))r.push(_("VS_REGEX_PORTABLE",`${t}/pattern`,"pattern must satisfy the complete RFC 9485 I-Regexp syntax."));if(ye(e.patternProperties)){for(let i of Object.keys(e.patternProperties))if(!Ui(i))r.push(_("VS_REGEX_PORTABLE",`${t}/patternProperties/${gu(i)}`,"patternProperties keys must satisfy RFC 9485 I-Regexp syntax."))}}function p6(e,t,r){if(!ye(e)){r.push(_("VS_PROPERTY_FACET",t,"A property facet is an object schema."));return}let i=Object.keys(e),n=["type","properties","required","additionalProperties"];if(i.length!==n.length||!n.every((s)=>Object.hasOwn(e,s)))r.push(_("VS_PROPERTY_FACET",t,"A property facet root contains exactly type, properties, required, and additionalProperties."));if(e.type!=="object"||e.additionalProperties!==!1||!ye(e.properties)||!Array.isArray(e.required)){r.push(_("VS_PROPERTY_FACET",t,"Facet constants are type object and additionalProperties false, with properties and required collections."));return}let o=new Set(Object.keys(e.properties));for(let s of o)if(!Sr.test(s))r.push(_("VS_PROPERTY_FACET",`${t}/properties/${gu(s)}`,`Property name ${s} violates the V1 member-name grammar.`));for(let s of e.required)if(typeof s==="string"&&!o.has(s))r.push(_("VS_PROPERTY_FACET",`${t}/required`,`Required member ${s} has no declared property schema.`))}function lx(e,t,r,i){let n=new Set;for(let o of e){if(n.has(o)){i.push(_("VS_META_SCHEMA",t,`${r} is a duplicate-free semantic set.`));return}n.add(o)}}function m6(e,t,r,i){let n=new Set;for(let o of e){let s;try{s=te.serialize(o)}catch{continue}if(n.has(s)){i.push(_("VS_META_SCHEMA",t,`${r} rejects canonically equal duplicates.`));return}n.add(s)}}function gu(e){return e.replaceAll("~","~0").replaceAll("/","~1")}function ha(e,t,r,i=""){let n=[];n.push(...du(e,i));let o=op(r,i);n.push(...o.diagnostics);let s=t==="named-type"?sp(e,o.index,i):void 0,a=ap(e,t,o.index,i,s);n.push(...a.diagnostics);for(let c of a.resources.values()){if(c.key===jt)continue;let u=c.diagnosticPointer??i,l=c===a.resources.values().next().value?t:"named-type",d=c.origin===void 0||c.name===void 0?l==="named-type"?s:void 0:{origin:c.origin,name:c.name};n.push(...T$(c.schema,u)),n.push(...du(c.schema,u)),n.push(...j$(c.schema,l,u,d)),n.push(...O$(c.schema,l,u,(f)=>pA(o.index,f,c.ownerOrigin)))}return n.push(..._$(a.resources,a.resolutions)),B6(n)}function B6(e){let t=new Map;for(let r of e)t.set(`${r.pointer}\x00${r.code}\x00${r.ref??""}\x00${r.message}`,r);return[...t.values()].sort((r,i)=>r.pointer.localeCompare(i.pointer)||r.code.localeCompare(i.code)||r.message.localeCompare(i.message))}function L$(e,t){let r=[];for(let[i,n]of Object.entries(e.types))Cu(n,"named-type",`/types/${yu(i)}`,t,r);for(let[i,n]of Object.entries(e.interfaces))P$(n,`/interfaces/${yu(i)}`,t,r);for(let[i,n]of Object.entries(e.classes))P$(n,`/classes/${yu(i)}`,t,r);for(let[i,n]of Object.entries(e.functions))z$(n,`/functions/${yu(i)}`,t,r);return Object.freeze(r)}function P$(e,t,r,i){if(Cu(e.properties,"property-facet",`${t}/properties`,r,i),"methods"in e)for(let[n,o]of Object.entries(e.methods))z$(o,`${t}/methods/${yu(n)}`,r,i)}function z$(e,t,r,i){if(Cu(e.input,"callable-input",`${t}/input`,r,i),e.output.mode==="value")Cu(e.output.schema,"callable-output",`${t}/output/schema`,r,i);else if(e.output.mode==="stream")Cu(e.output.item,"callable-output",`${t}/output/item`,r,i)}function Cu(e,t,r,i,n){for(let o of ha(e,t,i,r))n.push(_("DV_VALUE_SCHEMA",o.pointer,`[${o.code}] ${o.message}`,o.ref))}function yu(e){return e.replaceAll("~","~0").replaceAll("/","~1")}function M$(e){let t=[];for(let[r,i]of Object.entries(e.candidate.views)){let n=`/views/${g6(r)}`;if(i.target.kind==="definition")i.target.definitions.forEach((o,s)=>h6(e,o,`${n}/target/definitions/${s}`,t))}return Object.freeze(t)}function h6(e,t,r,i){let n=e.resolve(t);if(n===void 0||n.family!=="node")i.push(_("DV_VIEW_TARGET",r,`Definition target ${Be(t)} does not resolve to a Node Definition.`,Be(t)))}function g6(e){return e.replaceAll("~","~0").replaceAll("/","~1")}function xp(e,t){let r=fa(e,t),i=fp(r),n=pu(r),o=[...r.diagnostics,...L$(e,n),...e$(r,i),...I$(r,i),...M$(r),...kA(r,i,n)];return Object.freeze({context:r,analysis:i,diagnostics:Object.freeze(y6(o))})}function y6(e){let t=new Map;for(let r of e)t.set(`${r.pointer}\x00${r.code}\x00${r.ref??""}\x00${r.message}`,r);return[...t.values()].sort((r,i)=>r.pointer.localeCompare(i.pointer)||r.code.localeCompare(i.code)||r.message.localeCompare(i.message))}var U$=/^[a-z0-9][a-z0-9!#$&^_.+-]{0,126}\/[a-z0-9][a-z0-9!#$&^_.+-]{0,126}$/u;var Op={};ze(Op,{description:()=>wp,icon:()=>Ip});var wp=Object.freeze({type:"string",minLength:1,maxLength:1000}),Ip=Object.freeze({type:"string",minLength:1,maxLength:8000});var _p=p.string().min(3).max(253).regex(kr),Lr=p.string().regex(Sr),q$=p.string().refine(Pe.is,"Expected a canonical PropertyKey."),J$=p.string().min(1).max(100).regex(Fi),C6=p.string().regex(ii),Rn=p.string().min(wp.minLength).max(wp.maxLength),b6=p.string().min(Ip.minLength).max(Ip.maxLength),bu=p.lazy(()=>p.union([p.null(),p.boolean(),p.number(),p.string(),p.array(bu),p.record(p.string(),bu)])),E6=p.record(p.string(),bu),Eu=p.union([p.boolean(),E6]),v6=p.record(Lr,Eu),x6=ui(Lr),vu=p.strictObject({type:p.literal("object"),properties:v6,required:x6,additionalProperties:p.literal(!1)}),K$=p.strictObject({mediaType:p.string().regex(U$)}),w6=p.strictObject({visibility:p.enum(["public","private"]),auto:p.strictObject({on:ui(p.enum(["create","update"])).min(1),set:p.literal("instant")}).optional()}),xu=p.record(Lr,w6),I6=p.strictObject({origin:_p,revision:C6}),qo=wu("interface"),ga=wu("class"),O6=wu("function"),Vo=wu("policy"),D6=wu("view"),Z$=p.strictObject({origin:_p,kind:p.literal("core"),name:J$}),_6=p.strictObject({kind:p.literal("domain")}),F$=p.discriminatedUnion("kind",[Z$,_6]),W$=p.discriminatedUnion("kind",[qo,ga]),k6=p.discriminatedUnion("kind",[qo,ga,O6,Vo,D6,Z$]),dx={role:Lr,accepts:ui(W$).min(1)},fx=p.enum(["0..*","1..*","0..1","1"]),Y$=p.strictObject({source:p.strictObject({...dx,outgoing:fx}),target:p.strictObject({...dx,incoming:fx})}),G$=p.strictObject({...dx,incident:fx}),Q$=p.tuple([G$,G$]),X$=p.strictObject({noSelf:p.literal(!0).optional(),acyclic:p.literal(!0).optional()}),S6=p.strictObject({kind:p.literal("subject")}),A6=p.strictObject({kind:p.literal("object")}),$6=p.strictObject({kind:p.literal("source")}),T6=p.strictObject({kind:p.literal("target")}),eT=p.strictObject({kind:p.literal("variable"),id:p.number().int().min(0)}),H$=p.discriminatedUnion("kind",[S6,A6,$6,T6,eT]),N6=p.strictObject({variable:eT,class:ga}),R6=p.strictObject({min:p.number().int().min(0).max(3),max:p.number().int().min(0).max(3)}),Dp=p.lazy(()=>p.union([p.strictObject({source:H$,class:ga,target:H$,repeat:R6.optional()}),p.strictObject({exists:p.strictObject({nodes:p.array(N6).min(1).max(4),where:Dp})}),p.strictObject({allOf:p.array(Dp).min(1)}),p.strictObject({anyOf:p.array(Dp).min(1)})])),j6=p.discriminatedUnion("kind",[p.strictObject({kind:p.literal("self")}),p.strictObject({kind:p.literal("input"),field:Lr}),p.strictObject({kind:p.literal("ref"),ref:k6})]),px=p.lazy(()=>p.union([p.strictObject({check:Vo,object:j6}),p.strictObject({allOf:p.array(px).min(1)}),p.strictObject({anyOf:p.array(px).min(1)})])),P6=p.discriminatedUnion("mode",[p.strictObject({mode:p.literal("value"),schema:Eu}),p.strictObject({mode:p.literal("stream"),item:Eu}),p.strictObject({mode:p.literal("binary")})]),tT={description:Rn.optional(),input:Eu,output:P6,auth:p.enum(["anonymous","authenticated","authorized"]),policy:px.optional()},L6=p.strictObject({...tT,static:p.boolean(),inheritance:p.enum(["abstract","default","sealed"])}).superRefine((e,t)=>{if(e.inheritance==="abstract"&&e.policy!==void 0)t.addIssue({code:"custom",path:["policy"],message:"An abstract method cannot declare a policy.",params:{structureCode:"STRUCTURE_ABSTRACT_POLICY"}});if(e.auth!=="authorized"&&e.policy!==void 0)t.addIssue({code:"custom",path:["policy"],message:"Only an authorized method may declare a policy.",params:{structureCode:"STRUCTURE_CALLABLE_POLICY_AUTH"}})}),rT=p.record(Lr,L6),z6=p.strictObject({read:Vo.optional(),traverse:Vo.optional()}),M6=p.strictObject({traverse:Vo.optional()}),U6=p.strictObject({family:p.literal("both"),description:Rn.optional(),extends:ui(qo),properties:vu,propertyMetadata:xu}),F6=p.strictObject({family:p.literal("node"),description:Rn.optional(),extends:ui(qo),properties:vu,propertyMetadata:xu,methods:rT,data:K$.optional()}),G6={family:p.literal("edge"),description:Rn.optional(),extends:ui(qo),properties:vu,propertyMetadata:xu,constraints:X$},H6=p.strictObject({...G6,orientation:p.enum(["directed","undirected"]),endpoints:p.union([Y$,Q$])}).superRefine(nT),V6=p.discriminatedUnion("family",[U6,F6,H6]),q6=p.strictObject({family:p.literal("node"),description:Rn.optional(),implements:ui(qo),properties:vu,propertyMetadata:xu,methods:rT,data:K$.optional(),icon:b6.optional(),policies:z6}),J6={family:p.literal("edge"),description:Rn.optional(),implements:ui(qo),properties:vu,propertyMetadata:xu,policies:M6,constraints:X$},K6=p.strictObject({...J6,orientation:p.enum(["directed","undirected"]),endpoints:p.union([Y$,Q$])}).superRefine(nT),Z6=p.discriminatedUnion("family",[q6,K6]);function nT(e,t){if(e.orientation==="undirected"===Array.isArray(e.endpoints))return;t.addIssue({code:"custom",path:["endpoints"],message:`${e.orientation} Edge endpoints have the wrong structural shape.`,params:{structureCode:"STRUCTURE_EDGE_ORIENTATION"}})}var W6=p.strictObject(tT).superRefine((e,t)=>{if(e.auth!=="authorized"&&e.policy!==void 0)t.addIssue({code:"custom",path:["policy"],message:"Only an authorized function may declare a policy.",params:{structureCode:"STRUCTURE_CALLABLE_POLICY_AUTH"}})}),Y6=p.union([p.strictObject({description:Rn.optional(),match:Dp}),p.strictObject({description:Rn.optional(),allOf:p.array(Vo).min(1)}),p.strictObject({description:Rn.optional(),anyOf:p.array(Vo).min(1)})]),Q6=p.discriminatedUnion("kind",[p.strictObject({kind:p.literal("domain")}),p.strictObject({kind:p.literal("definition"),definitions:ui(W$).min(1)})]),X6=p.strictObject({description:Rn.optional(),target:Q6,auth:p.enum(["required","optional","public"])}),eG=p.strictObject({class:ga,properties:p.record(q$,bu)}),tG=p.strictObject({class:ga,source:F$,target:F$,properties:p.record(q$,bu)}),rG=p.strictObject({nodes:p.record(J$,eG),edges:p.array(tG)}),nG=p.strictObject({format:p.literal(ca),version:p.literal(ua),origin:_p,dependencies:p.array(I6),types:p.record(Lr,Eu),interfaces:p.record(Lr,V6),classes:p.record(Lr,Z6),functions:p.record(Lr,W6),policies:p.record(Lr,Y6),views:p.record(Lr,X6),core:rG}),iG=nG;function ya(e){let t=iG.safeParse(e);if(t.success)return t.data;throw new xe(t.error.issues.flatMap((r)=>oG(r,e)))}function wu(e){return p.strictObject({origin:_p,kind:p.literal(e),name:Lr})}function ui(e){return p.array(e).superRefine((t,r)=>{let i=new Map;t.forEach((n,o)=>{let s=mx(n),a=i.get(s);if(a===void 0){i.set(s,o);return}r.addIssue({code:"custom",path:[o],message:`Array item duplicates item ${a}.`,params:{structureCode:"STRUCTURE_DUPLICATE_ITEM"}})})})}function mx(e){if(e===null||typeof e!=="object")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(mx).join(",")}]`;return`{${Object.entries(e).sort(([t],[r])=>t<r?-1:t>r?1:0).map(([t,r])=>`${JSON.stringify(t)}:${mx(r)}`).join(",")}}`}function oG(e,t){if(e.code==="unrecognized_keys")return e.keys.map((i)=>_("STRUCTURE_UNKNOWN_FIELD",V$([...e.path,i]),`Unknown field ${JSON.stringify(i)}.`));let r=e.code==="custom"&&typeof e.params?.structureCode==="string"?e.params.structureCode:void 0;return[_(r??sG(e,t),V$(e.path),aG(e,t))]}function sG(e,t){switch(e.code){case"invalid_type":return iT(t,e.path)===void 0?"STRUCTURE_REQUIRED":"STRUCTURE_TYPE";case"invalid_value":return"STRUCTURE_VALUE";case"invalid_format":return"STRUCTURE_FORMAT";case"invalid_union":return"STRUCTURE_UNION";case"invalid_key":return"STRUCTURE_KEY";case"too_small":return"STRUCTURE_MINIMUM";case"too_big":return"STRUCTURE_MAXIMUM";case"not_multiple_of":return"STRUCTURE_MULTIPLE";default:return"STRUCTURE_INVALID"}}function aG(e,t){if(e.code==="invalid_type"&&iT(t,e.path)===void 0)return"Required value is missing.";if(e.code==="invalid_union")return"Value does not match any allowed structural variant.";if(e.code==="invalid_key")return"Record member name is invalid.";return e.message}function iT(e,t){let r=e;for(let i of t){if(typeof r!=="object"||r===null)return;r=Reflect.get(r,i)}return r}function V$(e){if(e.length===0)return"";return`/${e.map((t)=>cG(String(t))).join("/")}`}function cG(e){return e.replaceAll("~","~0").replaceAll("/","~1")}var uG=new Map([[ca,new Map([[ua,ya]])]]);function Ca(e){if(!lG(e))return ya(e);let t=uG.get(oT(e.format));if(t===void 0)aT("UNSUPPORTED_DOCUMENT_FORMAT","/format",`Unsupported Domain Schema document format ${sT(e.format)}.`);let r=t.get(oT(e.version));if(r===void 0)aT("UNSUPPORTED_DSL_VERSION","/version",`Unsupported Domain Schema DSL version ${sT(e.version)}.`);return r(e)}function lG(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}function oT(e){return typeof e==="string"?e:""}function sT(e){return e===void 0?"(missing)":JSON.stringify(e)}function aT(e,t,r){throw new xe([_(e,t,r)])}function Ji(e,t=rp()){let r;try{r=se(e)}catch(s){if(s instanceof he)throw new xe([_("DV_JSON_VALUE",s.pointer,s.message)]);throw s}let i=Ca(r),n=xp(i,t);if(n.diagnostics.length>0)throw new xe(n.diagnostics);let o=uu(i).schema;return jA(o,n.context.dependencies.values()),o}class Bx{context;values;constructor(e,t){this.context=e,this.values=t}compile(e,t){let r=e.config;if(r.auth!=="anonymous"&&r.auth!=="authenticated"&&r.auth!=="authorized")ie("BUILDER_CALLABLE_AUTH",`${t.pointer}/auth`,"Function authentication must be anonymous, authenticated, or authorized.");let i=r.auth;if(i!=="authorized"&&r.policy!==void 0)ie("BUILDER_CALLABLE_POLICY_AUTH",`${t.pointer}/policy`,"Only an authorized Function or Method may declare a Policy check.");let n=t.kind!=="function";if(!n&&(r.static!==void 0||r.inheritance!==void 0))ie("BUILDER_CALLABLE_PLACEMENT",t.pointer,"A standalone Function cannot declare Method staticness or inheritance.");let o=n?r.static??!1:void 0,s=n?r.inheritance??(t.kind==="node-interface-method"?"abstract":"default"):void 0;if(s==="abstract"&&r.policy!==void 0)ie("BUILDER_ABSTRACT_POLICY",`${t.pointer}/policy`,"An abstract Method cannot declare a Policy check.");let a=this.values.schema(r.input,"callable-input",`${t.pointer}/input`),c=this.compileOutput(r.output,`${t.pointer}/output`),u=r.policy===void 0?void 0:Nn(r.policy(this.policyContext(a,t,o??!1))),l={...r.description===void 0?{}:{description:r.description},input:a,output:c,auth:i,...u===void 0?{}:{policy:u}};if(!n)return l;return{...l,static:o,inheritance:s}}compileOutput(e,t){if(!q_(e))return{mode:"value",schema:this.values.schema(e,"callable-output",t)};if(e.mode==="binary")return{mode:"binary"};return{mode:"stream",item:this.values.schema(e.item,"callable-output",`${t}/item`)}}policyContext(e,t,r){let i=new Proxy(Object.create(null),{get(o,s){return typeof s==="string"?G_(s):void 0}}),n=H_();return Object.freeze({input:i,self:n,ref:(o)=>xh(this.context.resolvePolicyObject(o,`${t.pointer}/policy/ref`)),check:(o,s)=>{let a=V_(s),c=a;if(a.kind==="self"){if(t.kind==="function"||r)ie("BUILDER_POLICY_SELF",`${t.pointer}/policy`,"self is available only to a non-static Node Method.")}else if(a.kind==="input")if(dG(e,a.field));else ie("BUILDER_POLICY_INPUT",`${t.pointer}/policy`,`input.${a.field} is not one direct required single-Node path field.`);else c=xh(this.context.resolvePolicyObject(a.ref,`${t.pointer}/policy/ref`));return{check:this.context.resolvePolicy(o,`${t.pointer}/policy/check`),object:c}},allOf:(...o)=>(cT(o,`${t.pointer}/policy/allOf`),{allOf:o}),anyOf:(...o)=>(cT(o,`${t.pointer}/policy/anyOf`),{anyOf:o})})}}function dG(e,t){if(e===null||typeof e!=="object"||Array.isArray(e))return!1;if(e.type!=="object"||e.additionalProperties!==!1||!Array.isArray(e.required)||!e.required.includes(t)||e.properties===null||typeof e.properties!=="object"||Array.isArray(e.properties))return!1;let r=e.properties[t];return r!==null&&typeof r==="object"&&!Array.isArray(r)&&r.$ref==="https://schemas.astrale.ai/graph/1/node-path"&&Object.hasOwn(r,"x-astrale-path")}function cT(e,t){if(e.length===0)ie("BUILDER_POLICY_EMPTY_COMPOSITION",t,"Policy check composition must be non-empty.")}function lT(e,t){for(let[r,i]of Object.entries(e?.nodes??{})){if(!nr(i,"core-node"))ie("BUILDER_CORE_NODE",`/core/nodes/${Te(r)}`,"core.nodes entries are created by node(...).");t.captureCoreNode(i,r,`/core/nodes/${Te(r)}`)}}function dT(e,t){let r=Object.fromEntries(Object.entries(e?.nodes??{}).map(([n,o])=>[n,fG(o,t,`/core/nodes/${Te(n)}`)])),i=(e?.edges??[]).map((n,o)=>pG(n,t,`/core/edges/${o}`));return{nodes:r,edges:i}}function fG(e,t,r){let i=t.resolveNodeClass(e.class,`${r}/class`);if(i.origin!==t.origin)ie("BUILDER_CORE_CLASS",`${r}/class`,"A Core Node Class must be local to the owning Domain.");return{class:i,properties:e.properties}}function pG(e,t,r){if(!nr(e,"core-edge"))ie("BUILDER_CORE_EDGE",r,"core.edges entries are created by edge(...).");let i=t.resolveEdgeClass(e.class,`${r}/class`);if(i.origin!==t.origin)ie("BUILDER_CORE_CLASS",`${r}/class`,"A Core Edge Class must be local to the owning Domain.");return{class:i,source:uT(e.source,t,`${r}/source`),target:uT(e.target,t,`${r}/target`),properties:e.properties}}function uT(e,t,r){return t.resolveCoreEndpoint(e,r)}function pT(e,t){let r=fp(fa(e,t)).definitions,i=Object.fromEntries(Object.entries(e.core.nodes).map(([o,s])=>{let a=r.get(Q(s.class));if(a===void 0)ie("BUILDER_CORE_PROPERTY",`/core/nodes/${Te(o)}/class`,"Core property shorthand requires a resolvable concrete Class.");return[o,{...s,properties:fT(s.properties,a,`/core/nodes/${Te(o)}/properties`)}]})),n=e.core.edges.map((o,s)=>{let a=r.get(Q(o.class));if(a===void 0)ie("BUILDER_CORE_PROPERTY",`/core/edges/${s}/class`,"Core property shorthand requires a resolvable concrete Class.");return{...o,properties:fT(o.properties,a,`/core/edges/${s}/properties`)}});return{nodes:i,edges:n}}function fT(e,t,r){let i=new Map;for(let[s,a]of t.properties){let c=i.get(a.name)??[];c.push(s),i.set(a.name,c)}let n={},o=new Map;for(let[s,a]of Object.entries(e)){let c=mG(s,t,i,`${r}/${Te(s)}`),u=o.get(c);if(u!==void 0)ie("BUILDER_CORE_PROPERTY",`${r}/${Te(s)}`,`Property is supplied twice through ${JSON.stringify(u)} and ${JSON.stringify(s)}.`);o.set(c,s),n[c]=a}return n}function mG(e,t,r,i){if(Pe.is(e)){let o=Pe(e);if(!t.properties.has(o))ie("BUILDER_CORE_PROPERTY",i,`Property ${e} is not present on the Core Class.`);return o}let n=r.get(e)??[];if(n.length===1)return n[0];if(n.length===0)ie("BUILDER_CORE_PROPERTY",i,`Property ${JSON.stringify(e)} does not exist.`);ie("BUILDER_CORE_PROPERTY",i,`Property ${JSON.stringify(e)} is ambiguous; use one of: ${n.join(", ")}.`)}class hx{context;values;callables;policies;constructor(e,t,r,i){this.context=e,this.values=t,this.callables=r,this.policies=i}compileInterface(e,t){if(e.definitionKind==="interface"){if(e.config.family==="both")return this.bothInterface(e,t);if(e.config.family==="node")return this.nodeInterface(e,t);return this.edgeInterface(e,t)}ie("BUILDER_DEFINITION_PLACEMENT",t,`${e.definitionKind} belongs in classes, not interfaces.`)}compileClass(e,t){if(e.definitionKind==="node-class")return this.nodeClass(e,t);if(e.definitionKind==="edge-class")return this.edgeClass(e,t);ie("BUILDER_DEFINITION_PLACEMENT",t,`${e.definitionKind} belongs in interfaces, not classes.`)}bothInterface(e,t){let r=e.config;if(r.family!=="both")ie("BUILDER_DEFINITION_PLACEMENT",t,"Expected both family.");let i=this.values.properties(r.properties,`${t}/properties`);return{family:"both",...r.description===void 0?{}:{description:r.description},extends:this.parents(r.extends,["both"],`${t}/extends`),...i}}nodeInterface(e,t){let r=e.config;if(r.family!=="node")ie("BUILDER_DEFINITION_PLACEMENT",t,"Expected node family.");let i=this.values.properties(r.properties,`${t}/properties`),n=mT(r.data);return{family:"node",...r.description===void 0?{}:{description:r.description},extends:this.parents(r.extends,["node","both"],`${t}/extends`),...i,methods:this.methods(r.methods,"node-interface-method",`${t}/methods`),...n===void 0?{}:{data:n}}}edgeInterface(e,t){let r=e.config;if(r.family!=="edge")ie("BUILDER_DEFINITION_PLACEMENT",t,"Expected edge family.");let i=this.values.properties(r.properties,`${t}/properties`),n=this.interfaceEdgeContract(r,`${t}/endpoints`);return{family:"edge",...r.description===void 0?{}:{description:r.description},extends:this.parents(r.extends,["edge","both"],`${t}/extends`),...i,...n,constraints:BT(r)}}nodeClass(e,t){let r=this.values.properties(e.config.properties,`${t}/properties`),i=mT(e.config.data);return{family:"node",...e.config.description===void 0?{}:{description:e.config.description},implements:this.parents(e.config.implements,["node","both"],`${t}/implements`),...r,methods:this.methods(e.config.methods,"node-class-method",`${t}/methods`),...i===void 0?{}:{data:i},...e.config.icon===void 0?{}:{icon:e.config.icon},policies:{...e.config.policies?.read===void 0?{}:{read:this.policies.ref(e.config.policies.read,`${t}/policies/read`)},...e.config.policies?.traverse===void 0?{}:{traverse:this.policies.ref(e.config.policies.traverse,`${t}/policies/traverse`)}}}}edgeClass(e,t){let r=this.values.properties(e.options.properties,`${t}/properties`),i=e.orientation==="directed"?{orientation:"directed",endpoints:{source:this.directedSource(e.source,`${t}/endpoints/source`),target:this.directedTarget(e.target,`${t}/endpoints/target`)}}:{orientation:"undirected",endpoints:[this.incidentEndpoint(e.endpoints[0],`${t}/endpoints/0`),this.incidentEndpoint(e.endpoints[1],`${t}/endpoints/1`)]};return{family:"edge",...e.options.description===void 0?{}:{description:e.options.description},implements:this.parents(e.options.implements,["edge","both"],`${t}/implements`),...r,...i,policies:e.options.policies?.traverse===void 0?{}:{traverse:this.policies.ref(e.options.policies.traverse,`${t}/policies/traverse`)},constraints:BT(e.options)}}interfaceEdgeContract(e,t){if(e.orientation==="undirected")return{orientation:"undirected",endpoints:[this.incidentFromLegacyEndpoint(e.source,`${t}/0`),this.incidentFromLegacyEndpoint(e.target,`${t}/1`)]};return{orientation:"directed",endpoints:{source:this.directedSourceFromLegacyEndpoint(e.source,`${t}/source`),target:this.directedTargetFromLegacyEndpoint(e.target,`${t}/target`)}}}endpointBase(e,t){return{role:e.as,accepts:e.accepts.map((r,i)=>this.context.resolveNodeDefinition(r,`${t}/accepts/${i}`)).sort(Ue)}}directedSource(e,t){return{...this.endpointBase(e,t),outgoing:e.outgoing}}directedTarget(e,t){return{...this.endpointBase(e,t),incoming:e.incoming}}incidentEndpoint(e,t){return{...this.endpointBase(e,t),incident:e.incident}}directedSourceFromLegacyEndpoint(e,t){return{...this.endpointBase(e,t),outgoing:e.cardinality??"0..*"}}directedTargetFromLegacyEndpoint(e,t){return{...this.endpointBase(e,t),incoming:e.cardinality??"0..*"}}incidentFromLegacyEndpoint(e,t){return{...this.endpointBase(e,t),incident:e.cardinality??"0..*"}}parents(e,t,r){return(e??[]).map((i,n)=>this.context.resolveInterface(i,t,`${r}/${n}`)).sort(Ue)}methods(e,t,r){return Object.fromEntries(Object.entries(e??{}).map(([i,n])=>[i,this.callables.compile(n,{kind:t,pointer:`${r}/${Te(i)}`})]))}}function mT(e){return e===void 0?void 0:{mediaType:e}}function BT(e){return{...e.constraints?.noSelf===!0?{noSelf:!0}:{},...e.constraints?.acyclic===!0?{acyclic:!0}:{}}}class gx{context;constructor(e){this.context=e}ref(e,t){return this.context.resolvePolicy(e,t)}compile(e,t){let r=e.input;if("operator"in r){let n=r.policies.map((o,s)=>this.context.resolvePolicy(o,`${t}/${r.operator}/${s}`));return To(r.operator==="allOf"?{allOf:n}:{anyOf:n})}let i=r.match(US({resolveEdgeClass:(n,o)=>this.context.resolveEdgeClass(n,o),resolveNodeClass:(n,o)=>this.context.resolveNodeClass(n,o),pointer:t}));return To({...r.description===void 0?{}:{description:r.description},match:i})}}function hT(e,t){let r=new Set,i=new Set,n=(o)=>{if(r.has(o))ie("BUILDER_POLICY_CYCLE",`/policies/${o}`,`Policy composition cycle reaches ${t}:policy.${o}.`);if(i.has(o))return;r.add(o);let s=e[o],a=s!==void 0&&"allOf"in s?s.allOf:s!==void 0&&("anyOf"in s)?s.anyOf:[];for(let c of a)if(c.origin===t)n(c.name);r.delete(o),i.add(o)};for(let o of Object.keys(e))n(o)}function kp(e,t){let r=e,i=new Set;while(typeof r==="function"){if(i.has(r))ie("BUILDER_REFERENCE_CYCLE",t,"A lazy reference resolves cyclically.");i.add(r),r=r()}return r}var gT=new WeakMap,yT=new WeakMap;class yx{#e=new Map;#t=new Map;captureDefinition(e,t,r){this.capture(e,`${t.origin}:${t.kind}.${t.name}`,r),this.#e.set(e,t)}capture(e,t,r){let i=this.#t.get(e),n=yT.get(e),o=i??n;if(o!==void 0&&o!==t)ie("BUILDER_AMBIGUOUS_OWNERSHIP",r,`One detached builder value cannot be owned by both ${o} and ${t}.`);this.#t.set(e,t)}definition(e){return this.#e.get(e)??gT.get(e)}commit(){for(let[e,t]of this.#t)yT.set(e,t);for(let[e,t]of this.#e)gT.set(e,t)}}class Iu{origin;ownership=new yx;localDefinitions=new Map;localDefinitionFamilies=new Map;policies=new Map;coreNodes=new Map;policyObjects=new Map;policyObjectRefs=new Set;usedForeignOrigins=new Set;#e=new Map;constructor(e,t){this.origin=e;for(let r of t){let i={origin:r.origin,revision:mt(r)},n=this.#e.get(r.origin);if(n!==void 0&&n.dependency.revision!==i.revision)ie("BUILDER_DEPENDENCY_CONFLICT","/dependencies",`Dependency ${r.origin} was supplied at two different revisions.`);this.#e.set(r.origin,{schema:r,dependency:i})}}captureDefinition(e,t,r){let i=Q(t);if(this.localDefinitions.has(i))ie("BUILDER_DUPLICATE_MEMBER",r,`Definition ${t.kind}.${t.name} is duplicated.`);this.localDefinitions.set(i,t),this.localDefinitionFamilies.set(i,bG(e)),this.ownership.captureDefinition(e,t,r),this.capturePolicyObject(e,t)}capturePolicy(e,t,r){this.ownership.capture(e,`${t.origin}:policy.${t.name}`,r),this.policies.set(e,t),this.capturePolicyObject(e,t)}captureCoreNode(e,t,r){this.ownership.capture(e,`${this.origin}:core.${t}`,r);let i={origin:this.origin,kind:"core",name:t};this.coreNodes.set(e,i),this.capturePolicyObject(e,i)}captureFunction(e,t,r){this.ownership.capture(e,`${t.origin}:function.${t.name}`,r),this.capturePolicyObject(e,t)}captureView(e,t,r){this.ownership.capture(e,`${t.origin}:view.${t.name}`,r),this.capturePolicyObject(e,t)}resolveDefinition(e,t,r,i){let n=kp(e,i),o=hG(n)?n:typeof n==="object"&&n!==null?this.ownership.definition(n):void 0;if(o===void 0)ie("BUILDER_UNOWNED_REFERENCE",i,"Definition reference has no captured Domain owner.");if(!t.includes(o.kind))ie("BUILDER_REFERENCE_KIND",i,`Expected ${t.join(" or ")}, received ${o.kind}.`);let s=this.definitionFamily(o);if(s===void 0||!r.includes(s))ie("BUILDER_REFERENCE_KIND",i,`Expected ${r.join(" or ")} family, received ${s??"an unresolved family"}.`);return this.assertVisible(o,i),{...o}}resolveNodeDefinition(e,t){return this.resolveDefinition(e,["interface","class"],["node"],t)}resolveNodeClass(e,t){return this.resolveDefinition(e,["class"],["node"],t)}resolveEdgeClass(e,t){return this.resolveDefinition(e,["class"],["edge"],t)}resolveInterface(e,t,r){return this.resolveDefinition(e,["interface"],t,r)}resolvePolicy(e,t){let r=kp(e,t);if(typeof r!=="object"||r===null)ie("BUILDER_UNOWNED_REFERENCE",t,"Policy reference has no captured local owner.");let i=this.policies.get(r);if(i===void 0)ie("BUILDER_FOREIGN_POLICY",t,"V1 Policy references must name a local Policy.");return{...i}}resolvePolicyObject(e,t){let r=kp(e,t),i=yG(r)?r:typeof r==="object"&&r!==null?this.policyObjects.get(r):void 0;if(i===void 0||i.origin!==this.origin||!this.policyObjectRefs.has(Q(i)))ie("BUILDER_POLICY_REF",t,"Policy ref(...) must name one registered local Definition, Function, Policy, View, or Core Node.");return{...i}}resolveCoreEndpoint(e,t){if(BG(e))return{kind:"domain"};let r=gG(e)?e:this.coreNodes.get(e);if(r===void 0||r.origin!==this.origin)ie("BUILDER_CORE_REF",t,"A Core reference must name a registered local Core Node.");return{...r}}dependencies(){return[...this.usedForeignOrigins].map((e)=>{let t=this.#e.get(e);if(t===void 0)ie("BUILDER_DEPENDENCY_DIRECT","/dependencies",`Foreign origin ${e} is not supplied as an exact direct dependency.`);return t.dependency}).sort((e,t)=>e.origin.localeCompare(t.origin))}valueRegistry(e){let t=new Set(this.#e.keys()),r=new Map;for(let{schema:n}of this.#e.values())for(let o of da(n))if(!t.has(o.schema.origin))r.set(o.schema.origin,o.schema);let i=(n,o)=>({origin:n.origin,...o===void 0?{}:{revision:o},dependencies:n.dependencies,types:n.types,nodeDefinitions:CG(n)});return{current:{origin:this.origin,dependencies:[...this.#e.values()].map(({dependency:n})=>n),types:e,nodeDefinitions:[...this.localDefinitions.values()].filter((n)=>this.localDefinitionFamilies.get(Q(n))==="node").sort(Ue)},directDependencies:[...this.#e.values()].map(({schema:n,dependency:o})=>({...i(n,o.revision)})),transitiveDependencies:[...r.values()].map((n)=>i(n,mt(n))),graphNodePath:ip}}noteDomainReferences(e){for(let t of mp(e))this.usedForeignOrigins.add(t)}assertVisible(e,t){if(e.origin===this.origin){if(!this.localDefinitions.has(Q(e)))ie("BUILDER_REFERENCE_MISSING",t,`Local Definition ${e.kind}.${e.name} is not declared.`);return}if(!this.#e.has(e.origin))ie("BUILDER_DEPENDENCY_DIRECT",t,`Foreign Definition ${e.origin}:${e.kind}.${e.name} is not in a direct dependency.`);this.usedForeignOrigins.add(e.origin)}definitionFamily(e){if(e.origin===this.origin)return this.localDefinitionFamilies.get(Q(e));let t=this.#e.get(e.origin)?.schema;if(t===void 0)return;return e.kind==="class"?t.classes[e.name]?.family:t.interfaces[e.name]?.family}capturePolicyObject(e,t){this.policyObjects.set(e,t),this.policyObjectRefs.add(Q(t))}}function BG(e){if(typeof e!=="object"||e===null)return!1;let t=e;return t.kind==="domain"&&Object.keys(t).length===1}function hG(e){if(typeof e!=="object"||e===null)return!1;let t=e;return typeof t.origin==="string"&&typeof t.name==="string"&&(t.kind==="interface"||t.kind==="class")}function gG(e){if(typeof e!=="object"||e===null)return!1;let t=e;return typeof t.origin==="string"&&t.kind==="core"&&typeof t.name==="string"}function yG(e){if(typeof e!=="object"||e===null)return!1;let t=e;return typeof t.origin==="string"&&typeof t.name==="string"&&(t.kind==="interface"||t.kind==="class"||t.kind==="function"||t.kind==="policy"||t.kind==="view"||t.kind==="core")}function CG(e){let t=[];for(let[r,i]of Object.entries(e.interfaces))if(i.family==="node")t.push({origin:e.origin,kind:"interface",name:r});for(let[r,i]of Object.entries(e.classes))if(i.family==="node")t.push({origin:e.origin,kind:"class",name:r});return t.sort(Ue)}function bG(e){if(e.definitionKind==="interface")return e.config.family;return e.definitionKind==="node-class"?"node":"edge"}function Cx(e,t){EG(e.interfaces??{},e.classes??{},t),vG(e.policies??{},t),xG(e,t),lT(e.core,t)}function ET(e,t){let r=new Iu(t,e.dependencies??[]);Cx(e,r),r.ownership.commit()}function EG(e,t,r){for(let[i,n]of Object.entries(e)){if(CT(n,`/interfaces/${Te(i)}`),n.definitionKind!=="interface")ie("BUILDER_DEFINITION_PLACEMENT",`/interfaces/${Te(i)}`,`${n.definitionKind} belongs in classes.`);r.captureDefinition(n,{origin:r.origin,kind:"interface",name:i},`/interfaces/${Te(i)}`)}for(let[i,n]of Object.entries(t)){if(CT(n,`/classes/${Te(i)}`),n.definitionKind!=="node-class"&&n.definitionKind!=="edge-class")ie("BUILDER_DEFINITION_PLACEMENT",`/classes/${Te(i)}`,`${n.definitionKind} belongs in interfaces.`);r.captureDefinition(n,{origin:r.origin,kind:"class",name:i},`/classes/${Te(i)}`)}}function vG(e,t){for(let[r,i]of Object.entries(e)){if(!nr(i,"policy"))ie("BUILDER_POLICY",`/policies/${Te(r)}`,"Policies are created by definePolicy(...).");t.capturePolicy(i,{origin:t.origin,kind:"policy",name:r},`/policies/${Te(r)}`)}}function xG(e,t){for(let[r,i]of Object.entries(e.functions??{})){let n=`/functions/${Te(r)}`;bT(i,n),t.captureFunction(i,{origin:t.origin,kind:"function",name:r},n)}for(let[r,i]of[["interfaces",e.interfaces??{}],["classes",e.classes??{}]])for(let[n,o]of Object.entries(i)){if(!(o.definitionKind==="interface"&&o.config.family==="node"||o.definitionKind==="node-class"))continue;let s=o.definitionKind==="node-class"?o.config.methods:o.definitionKind==="interface"&&o.config.family==="node"?o.config.methods:void 0;for(let[a,c]of Object.entries(s??{})){let u=`/${r}/${Te(n)}/methods/${Te(a)}`;bT(c,u),t.ownership.capture(c,`${t.origin}:${o.definitionKind==="interface"?"interface":"class"}.${n}.method.${a}`,u)}}for(let[r,i]of Object.entries(e.views??{})){let n=`/views/${Te(r)}`;if(!nr(i,"view"))ie("BUILDER_VIEW",n,"Views are created by view(...).");t.captureView(i,{origin:t.origin,kind:"view",name:r},n)}}function CT(e,t){if(!nr(e,"definition"))ie("BUILDER_DEFINITION",t,"Definitions are created by a V1 Definition builder.")}function bT(e,t){if(!nr(e,"function"))ie("BUILDER_FUNCTION",t,"Functions and Methods are created by fn(...).")}function vT(e,t,r){let i=LS(e.zodSchema);if(i===void 0)return;let n=e.path.reduce((o,s)=>`${o}/${wG(String(s))}`,r);for(let o of Object.keys(e.jsonSchema))delete e.jsonSchema[o];Object.assign(e.jsonSchema,{$ref:"https://schemas.astrale.ai/graph/1/node-path","x-astrale-path":{target:"node",cardinality:"one",accepts:t(i,n)}})}function wG(e){return e.replaceAll("~","~0").replaceAll("/","~1")}function wT(e,t,r,i="",n={}){let o=IG(e,i,n.position??"value");if(o.length>0)return{ok:!1,diagnostics:o};let s;try{let a=p.toJSONSchema(e,{target:"draft-2020-12",unrepresentable:"throw",io:"input",cycles:"ref",reused:"inline",override:({zodSchema:c,jsonSchema:u,path:l})=>{if(c instanceof p.ZodObject)u.required=Object.entries(c.shape).filter(([,d])=>!Ex(d)).map(([d])=>d);if(c instanceof p.ZodType)OG(c,u),n.override?.({jsonSchema:u,path:l,zodSchema:c})}});if(s=bx(a),s!==null&&typeof s==="object"&&!Array.isArray(s))s={...s,$schema:Po}}catch(a){return{ok:!1,diagnostics:[_("ZOD_SCHEMA_NOT_LOSSLESS",i,`Zod cannot represent this contract exactly as Draft 2020-12: ${TG(a)}.`)]}}if(n.validate!==!1){let a=ha(s,t,r,i);if(a.length>0)return{ok:!1,diagnostics:a}}return{ok:!0,schema:Kt(s,t,r),diagnostics:[]}}function bx(e){if(e===null||["boolean","number","string"].includes(typeof e))return e;if(Array.isArray(e))return e.map(bx);if(e===null||typeof e!=="object")throw TypeError("Zod emitted a non-JSON schema value.");let t={};for(let r of Reflect.ownKeys(e)){if(typeof r==="symbol")throw TypeError("Zod emitted symbol-keyed schema metadata.");let i=Object.getOwnPropertyDescriptor(e,r);if(i===void 0)continue;if(!i.enumerable){if(r==="~standard")continue;throw TypeError(`Zod emitted unexpected non-enumerable schema member ${r}.`)}if(!("value"in i))throw TypeError(`Zod emitted accessor schema member ${r}.`);t[r]=bx(i.value)}return t}function Ex(e){return ba(e,new Set)}function IG(e,t,r){let i=[],n=new WeakMap;function o(s,a,c,u){let l=`${c}:${String(u)}`,d=n.get(s)??new Set;if(d.has(l))return;d.add(l),n.set(s,d);let f=Sp(s);if(f===void 0){i.push(_("ZOD_SCHEMA_NOT_LOSSLESS",a,"Zod schema has no inspectable v4 definition."));return}if(u&&c==="value"&&ba(s,new Set))i.push(_("ZOD_SCHEMA_NOT_LOSSLESS",a,"Zod optional() accepts JavaScript undefined, which V1 can represent only as absence of a containing object property."));let m=typeof f.type==="string"?f.type:"unknown";if($G.has(m))i.push(_("ZOD_SCHEMA_NOT_LOSSLESS",a,`Zod ${m} semantics cannot be represented losslessly in the V1 JSON value domain.`));if(f.coerce===!0)i.push(_("ZOD_SCHEMA_NOT_LOSSLESS",a,"Zod coercion changes the accepted input domain and is not serializable as JSON Schema."));if(xT(f,a,i),Array.isArray(f.checks))f.checks.forEach((B,h)=>{if(kv(B)!==void 0)return;let g=kG(B);if(g!==void 0)xT(g,`${a}/checks/${h}`,i)});for(let B of DG(f,a,c))o(B.schema,B.pointer,B.position,B.boundary)}return o(e,t,r,!0),i}function OG(e,t){let r=Sp(e)?.checks;if(!Array.isArray(r))return;let i=r.flatMap((o)=>{let s=kv(o);return s===void 0?[]:[s]});if(i.length===0)return;if(i.length===1){t.fullMatch=i[0];return}let n=Array.isArray(t.allOf)?t.allOf:[];t.allOf=[...n,...i.map((o)=>({fullMatch:o}))]}function xT(e,t,r){if(e.check==="custom"||e.check==="overwrite"){r.push(_("ZOD_SCHEMA_NOT_LOSSLESS",t,`Zod ${String(e.check)} checks are executable semantics with no lossless JSON Schema form.`));return}if(e.check==="string_format"&&e.format!=="regex"){r.push(_("ZOD_SCHEMA_NOT_LOSSLESS",t,`Zod format ${String(e.format)} asserts acceptance, while V1 format is annotation-only.`));return}if(e.check==="string_format"&&e.format==="regex"&&e.pattern instanceof RegExp){if(!AG(e.pattern))r.push(_("ZOD_SCHEMA_NOT_LOSSLESS",t,"Zod RegExp flags, anchors, dot semantics, or syntax cannot be preserved as a V1 I-Regexp substring pattern."))}}function DG(e,t,r){let i=[],n=(s,a=t)=>{if(Ki(s))i.push({boundary:!1,pointer:a,position:r,schema:s})},o=(s,a)=>{if(Ki(s))i.push({boundary:!0,pointer:a,position:"value",schema:s})};switch(e.type){case"array":o(e.element,`${t}/items`);break;case"intersection":n(e.left,`${t}/allOf/0`),n(e.right,`${t}/allOf/1`);break;case"lazy":if(typeof e.getter==="function")n(e.getter());break;case"object":if(vx(e.shape)){for(let[s,a]of Object.entries(e.shape))if(Ki(a))i.push({boundary:!0,pointer:`${t}/properties/${SG(s)}`,position:"object-property",schema:a})}o(e.catchall,`${t}/additionalProperties`);break;case"record":o(e.keyType,`${t}/propertyNames`),o(e.valueType,`${t}/additionalProperties`);break;case"tuple":if(Array.isArray(e.items))e.items.forEach((s,a)=>o(s,`${t}/prefixItems/${a}`));o(e.rest,`${t}/items`);break;case"union":if(Array.isArray(e.options))e.options.forEach((s,a)=>n(s,`${t}/anyOf/${a}`));break;default:n(e.innerType)}return i}function ba(e,t){if(t.has(e))return!1;t.add(e);let r=Sp(e);if(r===void 0)return t.delete(e),!1;let i=!1;switch(r.type){case"optional":i=!0;break;case"default":case"lazy":case"nullable":{let n=_G(r);i=n!==void 0&&ba(n,t);break}case"intersection":{let n=Ki(r.left)&&ba(r.left,t),o=Ki(r.right)&&ba(r.right,t);i=n&&o;break}case"union":i=Array.isArray(r.options)&&r.options.some((n)=>Ki(n)&&ba(n,t));break;default:i=!1}return t.delete(e),i}function _G(e){let t=e.type==="lazy"&&typeof e.getter==="function"?e.getter():e.innerType;return Ki(t)?t:void 0}function Sp(e){return vx(e.def)?e.def:void 0}function kG(e){if(Ki(e))return Sp(e);if(e===null||typeof e!=="object")return;let t=e._zod;return vx(t?.def)?t.def:void 0}function Ki(e){return e instanceof p.ZodType}function SG(e){return e.replaceAll("~","~0").replaceAll("/","~1")}function vx(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}function AG(e){if(e.flags!==""&&e.flags!=="u")return!1;if(!Ui(e.source))return!1;let t=!1,r=!1;for(let i of Array.from(e.source)){if(t){t=!1;continue}if(i==="\\"){t=!0;continue}if(i==="[")r=!0;else if(i==="]")r=!1;else if(!r&&(i==="^"||i==="$"||i==="."))return!1}return!0}var $G=new Set(["bigint","catch","custom","date","file","function","map","nan","pipe","prefault","promise","readonly","set","symbol","transform","undefined","void"]);function TG(e){return e instanceof Error?e.message:String(e)}class xx{context;types;registry;constructor(e,t){this.context=t;let r={};this.registry=t.valueRegistry(r);for(let[i,n]of Object.entries(e))r[i]=this.lower(n,"callable-output",`/types/${Te(i)}`);for(let[i,n]of Object.entries(r))this.assertValid(n,"named-type",`/types/${Te(i)}`),r[i]=Kt(n,"named-type",this.registry);this.types=r}schema(e,t,r){let i=this.lower(e,"callable-output",r);return this.assertValid(i,t,r),Kt(i,t,this.registry)}properties(e,t){let r=e??{},i=this.facet(r,"property-facet",t),n={};for(let[o,s]of Object.entries(r)){let a=OT(s)?s:void 0,c=a?.property??(IT(s)?s:void 0);if(c!==void 0&&(c.visibility==="private"||a!==void 0))n[o]={visibility:c.visibility,...a===void 0?{}:{auto:a.options}}}return{properties:i,propertyMetadata:n}}facet(e,t,r){let i={},n=[];for(let[s,a]of Object.entries(e)){let c=`${r}/properties/${Te(s)}`,l=(OT(a)?a:void 0)?.property??(IT(a)?a:void 0),d=l===void 0?a:l.schema;if(i[s]=this.lower(d,"callable-output",c,"object-property"),l?.required??NG(d))n.push(s)}let o={type:"object",properties:i,required:n,additionalProperties:!1};return this.assertValid(o,t,r),Kt(o,t,this.registry)}lower(e,t,r,i="value"){let n;if(e instanceof p.ZodType){let o=wT(e,t,this.registry,r,{position:i,validate:!1,override:(s)=>vT(s,(a,c)=>this.resolvePathAccepts(a,c),r)});if(!o.ok)throw new xe(o.diagnostics);n=Ap(o.schema)}else n=se(e);return n}resolvePathAccepts(e,t){let r=e.map((n,o)=>this.context.resolveNodeDefinition(n,`${t}/x-astrale-path/accepts/${o}`)),i=new Set;for(let n of r){let o=`${n.origin}\x00${n.kind}\x00${n.name}`;if(i.has(o))ie("BUILDER_PATH_DUPLICATE",`${t}/x-astrale-path/accepts`,"path(...) repeats one Node Definition.");i.add(o)}return r.sort(Ue)}assertValid(e,t,r){let i=ha(e,t,this.registry,r);if(i.length>0)throw new xe(i)}}function Ap(e){if(e===null||typeof e!=="object"||Array.isArray(e))return e;let t={...e};for(let r of["$defs","dependentSchemas","patternProperties","properties"]){let i=t[r];if(i===null||typeof i!=="object"||Array.isArray(i))continue;t[r]=Object.fromEntries(Object.entries(i).map(([n,o])=>[n,Ap(o)]))}for(let r of["allOf","anyOf","oneOf","prefixItems"]){let i=t[r];if(Array.isArray(i))t[r]=i.map((n)=>Ap(n))}for(let r of["additionalProperties","contains","contentSchema","else","if","items","not","propertyNames","then","unevaluatedItems","unevaluatedProperties"]){let i=t[r];if(typeof i==="boolean"||i!==null&&typeof i==="object"&&!Array.isArray(i))t[r]=Ap(i)}if(t.type==="object"&&t.properties!==null&&typeof t.properties==="object"&&!Array.isArray(t.properties)&&!Object.hasOwn(t,"additionalProperties"))t.additionalProperties=!1;return t}function IT(e){return nr(e,"property")}function OT(e){return nr(e,"auto")}function NG(e){if(!(e instanceof p.ZodType))return!0;return!Ex(e)}class wx{context;constructor(e){this.context=e}compile(e,t){let r=e.config,i=r.target;return{...r.description===void 0?{}:{description:r.description},target:i===void 0||i==="domain"?{kind:"domain"}:{kind:"definition",definitions:(RG(i)?i:[i]).map((n,o)=>this.context.resolveNodeDefinition(n,`${t}/target/definitions/${o}`)).sort(Ue)},auth:r.auth??"required"}}}function RG(e){return Array.isArray(e)}function DT(e,t){let r=new Ro(PA(t.dependencies??[])),i=jG(e,t,r),n=Ji(i,r);return ET(t,e),n}function jG(e,t,r){if(Ve(t,["dependencies","types","interfaces","classes","functions","policies","views","core"]),t.core!==void 0)Ve(t.core,["nodes","edges"],"/core");let i=new Iu(e,t.dependencies??[]);Cx(t,i);let n=new xx(t.types??{},i),o=new gx(i),s=new Bx(i,n),a=new hx(i,n,s,o),c=new wx(i),u=Ou(t.interfaces??{},(k,G)=>a.compileInterface(k,`/interfaces/${Te(G)}`)),l=Ou(t.classes??{},(k,G)=>a.compileClass(k,`/classes/${Te(G)}`)),d=Ou(t.functions??{},(k,G)=>s.compile(k,{kind:"function",pointer:`/functions/${Te(G)}`})),f=Ou(t.policies??{},(k,G)=>o.compile(k,`/policies/${Te(G)}`));hT(f,e);let m=Ou(t.views??{},(k,G)=>c.compile(k,`/views/${Te(G)}`)),B=dT(t.core,i),h={format:"astrale.dsl",version:"v1",origin:e,dependencies:[],types:n.types,interfaces:u,classes:l,functions:d,policies:f,views:m,core:B};i.noteDomainReferences(h);let g={...h,dependencies:i.dependencies()},w={...g,core:pT(g,r)},b=ya(w),O=ya(Xf(b));return No(O)}function Ou(e,t){return Object.fromEntries(Object.entries(e).map(([r,i])=>[r,t(i,r)]))}function $p(e,t){return DT(e,t)}var Y={};ze(Y,{Error:()=>xe,FORMAT:()=>ca,VERSION:()=>ua,accept:()=>Ji,compareDependencyMeaning:()=>$T,compareMemberMeaning:()=>TT,decode:()=>_T,encode:()=>ST,metadata:()=>Op,patterns:()=>Av,readHeader:()=>FT,resolve:()=>jn,revision:()=>mt,serialize:()=>kT,typeUri:()=>Bn,values:()=>_x});function _T(e,t=rp()){try{return Ji(te.decode(e),t)}catch(r){if(r instanceof te.DecodeError)throw new xe([_("DV_JSON_VALUE","",r.message)]);throw r}}function kT(e){return te.serialize(e)}function ST(e){return te.encode(e)}var AT=new WeakMap;function jn(e){let t=AT.get(e);if(t!==void 0)return t;let r=HG(e,pp(e));return AT.set(e,r),r}function HG(e,t){let r=xp(e,t);if(r.diagnostics.length>0)throw new xe(r.diagnostics);let i=Object.freeze({definitions:r.context.definitions,effectiveDefinitions:r.analysis.definitions,definition:(n)=>r.context.resolve(n),effective:(n)=>r.analysis.definitions.get(Q(n))});return Object.freeze({$:Object.freeze({schema:e,revision:mt(e),closure:Object.freeze([...r.context.dependencies.values()].sort((n,o)=>lt(n.origin,o.origin))),refs:i})})}var VG=new Set(["$comment","contentEncoding","contentMediaType","contentSchema","default","deprecated","description","examples","format","readOnly","title","writeOnly"]);function $T(e,t){let r=jn(e),i=r.$.closure.find((s)=>s.origin===t.origin);if(i===void 0)throw new xe([_("DM_DEPENDENCY_NOT_RETAINED","/target/origin",`Domain ${e.origin} was not admitted with a dependency at ${t.origin}.`)]);let n=new Map([[e.origin,e],...r.$.closure.map((s)=>[s.origin,s])]),o=qG(e,i.origin,n);return NT(i,t,o)}function TT(e,t,r){if(e.origin!==t.origin)throw new xe([_("DM_MEMBER_ORIGIN_MISMATCH","/target/origin",`Member comparison target ${t.origin} does not match source ${e.origin}.`)]);if(!Array.isArray(r)||r.length===0||new Set(r).size!==r.length)throw new xe([_("DM_MEMBER_ROOT_INVALID","/roots","Member comparison roots must be one non-empty duplicate-free Key set.")]);let i=jn(e),n=new Map([[e.origin,e],...i.$.closure.map((a)=>[a.origin,a])]),o=r.map((a,c)=>tH(e,a,c)),s=RT(o,e.origin,n);return NT(e,t,s)}function NT(e,t,r){jn(t);let i=Object.freeze([...r.keys()].sort(lt)),n=[],o=[];for(let l of i){let d=r.get(l),f=Rp(t,d.coordinate),m=f===void 0?void 0:Ox(f);if(o.push([l,d.fingerprint,m??null]),m===void 0)n.push(Object.freeze({key:l,kind:"missing",sourceFingerprint:d.fingerprint}));else if(m!==d.fingerprint)n.push(Object.freeze({key:l,kind:"changed",sourceFingerprint:d.fingerprint,targetFingerprint:m}))}let s=mt(e),a=mt(t),c=Object.freeze(n),u=Ox({version:1,dependency:e.origin,source:s,target:a,coordinates:o});return Object.freeze({version:1,dependency:e.origin,source:s,target:a,footprint:i,changes:c,fingerprint:u})}function qG(e,t,r){return RT(ZG(e).map(jp),t,r)}function RT(e,t,r){let i=new Map,n=[],o=new Set;for(let s of e){if(s.kind==="member"){n.push(s.ref);continue}let a=r.get(Z.origin(s.key)),c=a===void 0?void 0:Rp(a,s);if(a===void 0||c===void 0)throw new xe([_("DM_MEMBER_ROOT_INVALID","/roots",`Member comparison root ${s.key} does not exist in its source context.`,s.key)]);Np(i,t,s,c),JG(a,s,(u)=>n.push(Tp(u)))}for(let s=0;s<n.length;s+=1){let a=n[s],c=Q(a);if(o.has(c))continue;o.add(c);let u=r.get(a.origin);if(u===void 0)throw new xe([_("DM_DEPENDENCY_CONTEXT_INVALID","",`Retained acceptance context cannot resolve ${Z.fromSchema(a)}.`,String(Z.fromSchema(a)))]);let l=jp(a),d=Rp(u,l);if(d===void 0)throw new xe([_("DM_DEPENDENCY_CONTEXT_INVALID","",`Retained acceptance context has no meaning for ${l.key}.`,l.key)]);if(Np(i,t,l,d),WG(u,a,(m)=>n.push(Tp(m))),!nH(a))continue;let f=jn(u).$.refs.effective(a);if(f===void 0)continue;KG(f,t,i,(m)=>n.push(Tp(m)))}return i}function JG(e,t,r){let i=jn(e).$.refs.effective(t.owner);if(i===void 0)return;if(t.kind==="property"){let o=i.properties.get(t.key);if(o!==void 0)hn(zr(o.schema),r);return}let n=[...i.methods.values()].find((o)=>zp(o.owner,o.name)===t.key);if(n!==void 0)qi(Lp(n.declaration),r)}function KG(e,t,r,i){for(let n of e.properties.values()){let o=zT(n.owner,n.name);Np(r,t,o,jT(n)),i(n.owner),hn(zr(n.schema),i)}for(let n of e.methods.values()){let o=MT(n.owner,n.name);Np(r,t,o,PT(n)),i(n.owner),qi(Lp(n.declaration),i)}}function Np(e,t,r,i){if(Z.origin(r.key)!==t)return;let n=Ox(i),o=e.get(r.key);if(o!==void 0&&o.fingerprint!==n)throw new xe([_("DM_MEANING_INCONSISTENT","",`Semantic coordinate ${r.key} produced inconsistent effective meaning.`,r.key)]);e.set(r.key,Object.freeze({coordinate:r,fingerprint:n}))}function ZG(e){let t=new Map,r=(i)=>{let n=Tp(i);t.set(Q(n),n)};for(let i of Object.values(e.types))hn(zr(i),r);for(let i of Object.values(e.interfaces))Bp(Du(i),r);for(let i of Object.values(e.classes))hp(Du(i),r);for(let i of Object.values(e.functions))qi(Pp(i),r);for(let i of Object.values(e.policies))gp(Dx(i),r);for(let i of Object.values(e.views))if(i.target.kind==="definition")i.target.definitions.forEach(r);for(let i of Object.values(e.core.nodes))r(i.class);for(let i of e.core.edges){if(r(i.class),i.source.kind!=="domain")r(i.source);if(i.target.kind!=="domain")r(i.target)}return[...t.values()].sort(Ue)}function WG(e,t,r){switch(t.kind){case"type":{let i=e.types[t.name];if(i!==void 0)hn(zr(i),r);return}case"interface":{let i=e.interfaces[t.name];if(i!==void 0)Bp(Du(i),r);return}case"class":{let i=e.classes[t.name];if(i!==void 0)hp(Du(i),r);return}case"function":{let i=e.functions[t.name];if(i!==void 0)qi(Pp(i),r);return}case"policy":{let i=e.policies[t.name];if(i!==void 0)gp(Dx(i),r);return}case"view":{let i=e.views[t.name];if(i?.target.kind==="definition")i.target.definitions.forEach(r);return}case"core":{let i=e.core.nodes[t.name];if(i===void 0)return;r(i.class);for(let n of UT(e,t.name)){if(r(n.class),n.source.kind!=="domain")r(n.source);if(n.target.kind!=="domain")r(n.target)}}}}function Rp(e,t){if(Z.origin(t.key)!==e.origin)return;if(t.kind==="member")return YG(e,t.ref);let r=jn(e).$.refs.effective(t.owner);if(r===void 0)return;if(t.kind==="property"){let n=r.properties.get(t.key);return n===void 0?void 0:jT(n)}let i=[...r.methods.values()].find((n)=>zp(n.owner,n.name)===t.key);return i===void 0?void 0:PT(i)}function YG(e,t){if(t.origin!==e.origin)return;switch(t.kind){case"type":{let r=e.types[t.name];return r===void 0?void 0:{kind:t.kind,schema:zr(r)}}case"interface":case"class":return QG(e,t);case"function":{let r=e.functions[t.name];return r===void 0?void 0:{kind:t.kind,declaration:Pp(r)}}case"policy":{let r=e.policies[t.name];return r===void 0?void 0:{kind:t.kind,declaration:Dx(r)}}case"view":{let r=e.views[t.name];return r===void 0?void 0:{kind:t.kind,declaration:eH(r)}}case"core":{let r=e.core.nodes[t.name];return r===void 0?void 0:{kind:t.kind,node:r,edges:UT(e,t.name)}}}}function QG(e,t){let r=jn(e),i=r.$.refs.definition(t),n=r.$.refs.effective(t);if(i===void 0||n===void 0||i.owner!==e)return;return{kind:t.kind,declaration:Du(i.declaration),effective:{properties:[...n.properties.keys()].sort(lt),methods:[...n.methods.values()].map((o)=>zp(o.owner,o.name)).sort(lt),...n.data===void 0?{}:{data:{owner:Z.fromSchema(n.data.owner),declaration:n.data.declaration}}}}}function jT(e){return{kind:"property",owner:Z.fromSchema(e.owner),name:e.name,schema:zr(e.schema),required:e.required,visibility:e.visibility}}function PT(e){return{kind:"method",owner:Z.fromSchema(e.owner),name:e.name,declaration:Lp(e.declaration)}}function Du(e){let{description:t,...r}=e,i={...r,properties:zr(e.properties)};if("methods"in e)i.methods=Object.fromEntries(Object.entries(e.methods).map(([n,o])=>[n,Lp(o)]));return i}function Pp(e){let{description:t,...r}=e;return{...r,input:zr(e.input),output:XG(e.output)}}function Lp(e){return{...Pp(e),static:e.static,inheritance:e.inheritance}}function XG(e){switch(e.mode){case"value":return{mode:"value",schema:zr(e.schema)};case"stream":return{mode:"stream",item:zr(e.item)};case"binary":return{mode:"binary"}}}function Dx(e){let{description:t,...r}=e;return r}function eH(e){let{description:t,...r}=e;return r}function zr(e){if(typeof e==="boolean")return e;let t={};for(let[r,i]of Object.entries(e)){if(VG.has(r))continue;if(Vi.has(r)&&Ix(i))t[r]=zr(i);else if(Gi.has(r)&&Array.isArray(i))t[r]=i.map((n)=>Ix(n)?zr(n):n);else if(Hi.has(r)&&ye(i))t[r]=Object.fromEntries(Object.entries(i).map(([n,o])=>[n,Ix(o)?zr(o):o]));else t[r]=i}return t}function tH(e,t,r){let i;try{i=Z(t)}catch{return Ea(t,r,"is not a canonical semantic Key")}if(Z.origin(i)!==e.origin)return Ea(i,r,`belongs to ${Z.origin(i)}, not source ${e.origin}`);let n=Z.ref(i),o;if(ne.isProperty(n)||ne.isMethod(n)){let s=LT(e,ne.namespace(n),ne.member(n)),a=ne.child(n);if(s===void 0||a===void 0)return Ea(i,r,"has no exact owning Definition");o=ne.isProperty(n)?zT(s,a):MT(s,a)}else if(ne.isDefinition(n)){let s=rH(e,n);if(s===void 0)return Ea(i,r,"does not exist in the source");o=jp(s)}else if(n.startsWith("core."))o=jp({origin:e.origin,kind:"core",name:ne.member(n)});else return Ea(i,r,"is not an independently comparable V1 member");if(Rp(e,o)===void 0)return Ea(i,r,"does not exist in the source");return o}function rH(e,t){let r=ne.namespace(t),i=ne.member(t),n=LT(e,r,i);if(n!==void 0)return n;switch(r){case"type":return e.types[i]===void 0?void 0:{origin:e.origin,kind:"type",name:i};case"function":return e.functions[i]===void 0?void 0:{origin:e.origin,kind:"function",name:i};case"policy":return e.policies[i]===void 0?void 0:{origin:e.origin,kind:"policy",name:i};case"view":return e.views[i]===void 0?void 0:{origin:e.origin,kind:"view",name:i};default:return}}function LT(e,t,r){if(t==="class")return e.classes[r]===void 0?void 0:{origin:e.origin,kind:"class",name:r};if(t==="interface")return e.interfaces[r]===void 0?void 0:{origin:e.origin,kind:"interface",name:r};return}function Ea(e,t,r){throw new xe([_("DM_MEMBER_ROOT_INVALID",`/roots/${t}`,`Member comparison root ${JSON.stringify(e)} ${r}.`,typeof e==="string"?e:void 0)])}function jp(e){return Object.freeze({kind:"member",key:Z.fromSchema(e),ref:e})}function zT(e,t){return Object.freeze({kind:"property",key:Pe.of(e,t),owner:e,name:t})}function MT(e,t){return Object.freeze({kind:"method",key:zp(e,t),owner:e,name:t})}function zp(e,t){return Z.of(e.origin,ne.method(ne.fromSchema(e),t))}function UT(e,t){return e.core.edges.filter((r)=>r.source.kind==="core"&&r.source.name===t||r.target.kind==="core"&&r.target.name===t)}function Ox(e){return tp(te.encode(e))}function nH(e){switch(e.kind){case"interface":case"class":return!0;default:return!1}}function Tp(e){switch(e.kind){case"type":case"interface":case"class":case"function":case"policy":case"view":case"core":return e;default:throw new xe([_("DM_DEPENDENCY_CONTEXT_INVALID","",`Semantic reference kind ${JSON.stringify(e.kind)} is outside V1.`)])}}function Ix(e){return typeof e==="boolean"||ye(e)}function FT(e){let t;try{t=se(e)}catch(i){if(i instanceof he)throw new xe([_("DV_JSON_VALUE",i.pointer,i.message)]);throw i}let r=Ca(t);return Object.freeze({dependencies:Object.freeze([...r.dependencies]),origin:r.origin})}var _x={};ze(_x,{DIALECT:()=>Po,VOCABULARY:()=>uA,classifyOrdering:()=>oH,instant:()=>yA,validate:()=>iH});var GT=new WeakMap;function iH(e,t,r,i=""){return dp(t,r,HT(e),i)}function oH(e,t){return yp(t,HT(e))}function HT(e){let t=GT.get(e);if(t===void 0)t=FA(e),GT.set(e,t);return t}var Mr={};ze(Mr,{FORMAT:()=>_u,VERSION:()=>ku,accept:()=>lH,create:()=>uH,decode:()=>dH,encode:()=>fH,serialize:()=>pH});var _u="astrale.dsl.bundle",ku="v1";function VT(e){return kx(e,da(e).map(({schema:t})=>t))}function kx(e,t){return No({format:_u,version:ku,root:e,closure:[...t]})}function KT(e){if(!sH(e))throw new xe([_("BUNDLE_STRUCTURE","","DomainSchemaBundle must be an object.")]);let t=[],r=new Set(["format","version","root","closure"]);for(let o of Object.keys(e))if(!r.has(o))t.push(_("BUNDLE_STRUCTURE",`/${aH(o)}`,`Unknown bundle field ${o}.`));for(let o of r)if(!(o in e))t.push(_("BUNDLE_STRUCTURE",`/${o}`,`Missing bundle field ${o}.`));if(e.format!==_u)t.push(_("UNSUPPORTED_BUNDLE_FORMAT","/format",`Unsupported DomainSchemaBundle format ${JT(e.format)}.`));if(e.version!==ku)t.push(_("UNSUPPORTED_BUNDLE_VERSION","/version",`Unsupported DomainSchemaBundle version ${JT(e.version)}.`));let i=qT(e.root,"/root",t),n=[];if(!Array.isArray(e.closure))t.push(_("BUNDLE_STRUCTURE","/closure","DomainSchemaBundle closure must be an array."));else for(let[o,s]of e.closure.entries()){let a=qT(s,`/closure/${o}`,t);if(a!==void 0)n.push(a)}if(t.length>0)throw new xe(t);if(i===void 0)throw new xe([_("BUNDLE_STRUCTURE","/root","DomainSchemaBundle root is missing.")]);return Object.freeze({root:i,closure:Object.freeze(n)})}function qT(e,t,r){if(e===void 0)return;try{return Ca(e)}catch(i){if(!(i instanceof xe))throw i;r.push(...i.diagnostics.map((n)=>_(n.code,`${t}${n.pointer}`,n.message,n.ref)));return}}function sH(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}function JT(e){return e===void 0?"(missing)":JSON.stringify(e)}function aH(e){return e.replaceAll("~","~0").replaceAll("/","~1")}function WT(e){let t;try{t=se(e)}catch(r){if(r instanceof he)throw new xe([_("DV_JSON_VALUE",r.pointer,r.message)]);throw r}return eN(t)}function YT(e){try{return eN(te.decode(e))}catch(t){if(t instanceof te.DecodeError)throw new xe([_("DV_JSON_VALUE","",t.message)]);throw t}}function QT(e){return te.serialize(e)}function XT(e){return te.encode(e)}function eN(e){let t=KT(e),r=ZT(t.root,"/root"),i=t.closure.map((d,f)=>ZT(d,`/closure/${f}`)),n=[],o=new Map;for(let d of i){if(d.key===r.key){n.push(_("BUNDLE_ROOT_DUPLICATED",d.pointer,"The root schema must not also appear in the bundle closure."));continue}let f=o.get(d.key);if(f!==void 0){n.push(_("BUNDLE_SCHEMA_DUPLICATED",d.pointer,`Schema ${d.schema.origin}@${d.revision} duplicates ${f.pointer}.`));continue}o.set(d.key,d)}let s=new Set;tN(r,r,o,s,new Set,new Map,n);for(let d of o.values())if(!s.has(d.key))n.push(_("BUNDLE_CLOSURE_EXTRA",d.pointer,`Schema ${d.schema.origin}@${d.revision} is not reachable from the root.`));if(n.length>0)throw new xe(n);let a=new Map,c=(d)=>{let f=a.get(d.key);if(f!==void 0)return f.schema;for(let m of d.schema.dependencies){let B=o.get(Sx(m.origin,m.revision));if(B!==void 0)c(B)}try{let m=Ji(d.schema,new Ro([...a.values()])),B=mt(m);if(B!==d.revision)throw new xe([_("BUNDLE_SCHEMA_REVISION","",`Accepted schema revision ${B} differs from indexed revision ${d.revision}.`)]);return a.set(d.key,{schema:m,revision:B}),m}catch(m){if(!(m instanceof xe))throw m;throw new xe(m.diagnostics.map((B)=>_(B.code,`${d.pointer}${B.pointer}`,B.message,B.ref)))}};for(let d of o.values())if(s.has(d.key))c(d);let u=c(r),l=[...s].map((d)=>a.get(d)?.schema).filter((d)=>d!==void 0).sort(cH);return kx(u,l)}function ZT(e,t){let r=uu(e);return{schema:e,revision:r.revision,key:Sx(e.origin,r.revision),pointer:t}}function tN(e,t,r,i,n,o,s){if(n.has(e.key)){s.push(_("BUNDLE_CLOSURE_CYCLE",e.pointer,`Bundle dependency cycle reaches ${e.schema.origin}@${e.revision}.`));return}n.add(e.key);for(let[a,c]of e.schema.dependencies.entries()){let u=`${e.pointer}/dependencies/${a}`,l=Sx(c.origin,c.revision);if(l===t.key){s.push(_("BUNDLE_CLOSURE_CYCLE",u,"Bundle dependency closure returns to its root."));continue}let d=o.get(c.origin);if(d!==void 0&&d!==c.revision)s.push(_("BUNDLE_REVISION_COHERENCE",u,`Bundle requires ${c.origin} at both ${d} and ${c.revision}.`));else o.set(c.origin,c.revision);let f=r.get(l);if(f===void 0){s.push(_("BUNDLE_CLOSURE_MISSING",u,`Bundle has no exact ${c.origin}@${c.revision}.`));continue}i.add(f.key),tN(f,t,r,i,n,o,s)}n.delete(e.key)}function cH(e,t){return lt(e.origin,t.origin)||lt(mt(e),mt(t))}function Sx(e,t){return`${e}\x00${t}`}function uH(e){return VT(e)}function lH(e){return WT(e)}function dH(e){return YT(e)}function fH(e){return XT(e)}function pH(e){return QT(e)}var mH=255,BH=/[^A-Za-z0-9._-]/u,rN="NodeId must be 1-255 ASCII characters drawn from [A-Za-z0-9._-].";class Mp extends TypeError{input;code="NODE_ID_INVALID";constructor(e){super(rN);this.input=e,this.name="NodeIdError"}}function Fe(e){if(!nn(e))throw new Mp(e);return e}function nn(e){return typeof e==="string"&&e.length>0&&e.length<=mH&&!BH.test(e)}var uae=p.string().refine(nn,rN).transform((e)=>e);var nN=new TextEncoder;function At(e,t){let r=nN.encode(e),i=nN.encode(t),n=Math.min(r.length,i.length);for(let o=0;o<n;o++){let s=r[o]-i[o];if(s!==0)return Math.sign(s)}return Math.sign(r.length-i.length)}function Su(e){return Object.freeze({id:e.id,class:e.class,props:e.props})}var Vp={};ze(Vp,{accept:()=>Fp,acceptUnresolved:()=>zx,canonicalize:()=>Gp,limits:()=>Lx,self:()=>Rx});var va=32,on=64;function Up(e){try{return Au(se(e),"",0)}catch(t){if(t instanceof be)throw t;throw new be("AUTH_GRANT_INVALID","Expected a resolved Identity expression","",{cause:t})}}function Tx(e,t,r){return Au(e,t,r)}function Au(e,t,r){if(r>va)li(t,"Identity expression exceeds its depth limit");let i=hH(e,t);switch(i.kind){case"identity":if(Ax(i,["id","kind"],t),typeof i.id!=="string")li(`${t}/id`,"Expected a NodeId");return Object.freeze({kind:"identity",id:Fe(i.id)});case"union":case"intersect":{Ax(i,["kind","operands"],t);let n=oN(i.operands,`${t}/operands`,2),o=i.kind,s=iN(n.map((a,c)=>Au(a,`${t}/operands/${c}`,r+1)).flatMap((a)=>a.kind===o?a.operands:[a]));if(s.length>on)li(`${t}/operands`,`Expected 2-${on} operands`);return s.length===1?s[0]:Object.freeze({kind:o,operands:Object.freeze(s)})}case"exclude":{Ax(i,["base","excluded","kind"],t);let n=iN(oN(i.excluded,`${t}/excluded`,1).map((o,s)=>Au(o,`${t}/excluded/${s}`,r+1)).flatMap((o)=>o.kind==="union"?o.operands:[o]));if(n.length>on)li(`${t}/excluded`,`Expected 1-${on} operands`);return Object.freeze({kind:"exclude",base:Au(gH(i.base,`${t}/base`),`${t}/base`,r+1),excluded:Object.freeze(n)})}default:li(`${t}/kind`,"Expected identity, union, intersect, or exclude")}}function iN(e){let t=e.map((r)=>({expr:r,key:te.serialize(r)})).sort((r,i)=>$x(r.key,i.key));return t.filter((r,i)=>i===0||r.key!==t[i-1].key).map((r)=>r.expr)}function hH(e,t){if(e===null||Array.isArray(e)||typeof e!=="object")li(t,"Expected an object");return e}function oN(e,t,r){if(!Array.isArray(e)||e.length<r||e.length>on)li(t,`Expected ${r}-${on} operands`);return e}function gH(e,t){if(e===void 0)li(t,"Expected a value");return e}function Ax(e,t,r){let i=Object.keys(e).sort($x),n=[...t].sort($x);if(i.length!==n.length||i.some((o,s)=>o!==n[s]))li(r,`Expected exactly ${t.join(", ")}`)}function $x(e,t){return e<t?-1:e>t?1:0}function li(e,t){throw new be("AUTH_GRANT_INVALID",t,e)}function Fp(e){try{let t=se(e);if(t===null||Array.isArray(t)||typeof t!=="object")Nx("","Expected a Grant object");let r=t;if(CH(r,["expr"],""),r.expr===void 0)Nx("/expr","Expected a resolved Identity expression");return Object.freeze({expr:Tx(r.expr,"/expr",0)})}catch(t){if(t instanceof be)throw t;throw new be("AUTH_GRANT_INVALID","Expected a canonical resolved Grant","",{cause:t})}}function Gp(e){return Object.freeze({expr:Up(e.expr)})}function CH(e,t,r){let i=Object.keys(e).sort(sN),n=[...t].sort(sN);if(i.length!==n.length||i.some((o,s)=>o!==n[s]))Nx(r,`Expected exactly ${t.join(", ")}`)}function sN(e,t){return e<t?-1:e>t?1:0}function Nx(e,t){throw new be("AUTH_GRANT_INVALID",t,e)}function Rx(e){return Object.freeze({expr:Object.freeze({kind:"identity",id:Fe(e)})})}var jx=3,Px=65536,Lx=Object.freeze({expressionDepth:va,operandsPerExpression:on,credentialNestingDepth:jx});function zx(e){try{let t=lN(e,"");if($u(t,["expr","v"],""),Zi(t,"v","/v")!==1)sr("/v","Unsupported unresolved Grant version");return Object.freeze({v:1,expr:Hp(Zi(t,"expr","/expr"),"/expr",0,0,new WeakSet)})}catch(t){if(t instanceof be)throw t;throw new be("AUTH_GRANT_INVALID","Expected a bounded unresolved Grant","",{cause:t})}}function Hp(e,t,r,i,n){if(r>va)sr(t,"Identity expression exceeds its depth limit");let o=lN(e,t);if(n.has(o))sr(t,"Cyclic Identity expressions are not supported");n.add(o);try{let s=Zi(o,"kind",`${t}/kind`);switch(s){case"identity":{let a=aN(o,"self"),c=aN(o,"credential");if(a===c)sr(t,"Expected exactly one unresolved Identity leaf");if(a){if($u(o,["kind","self"],t),Zi(o,"self",`${t}/self`)!==!0)sr(`${t}/self`,"Expected true");return Object.freeze({kind:"identity",self:!0})}if($u(o,["credential","kind"],t),i>=jx)sr(`${t}/credential`,"Credential nesting exceeds its limit");return Object.freeze({kind:"identity",credential:bH(Zi(o,"credential",`${t}/credential`),`${t}/credential`)})}case"union":case"intersect":{$u(o,["kind","operands"],t);let a=cN(Zi(o,"operands",`${t}/operands`),`${t}/operands`,2);return Object.freeze({kind:s,operands:Object.freeze(a.map((c,u)=>Hp(c,`${t}/operands/${u}`,r+1,i,n)))})}case"exclude":{$u(o,["base","excluded","kind"],t);let a=cN(Zi(o,"excluded",`${t}/excluded`),`${t}/excluded`,1);return Object.freeze({kind:"exclude",base:Hp(Zi(o,"base",`${t}/base`),`${t}/base`,r+1,i,n),excluded:Object.freeze(a.map((c,u)=>Hp(c,`${t}/excluded/${u}`,r+1,i,n)))})}default:sr(`${t}/kind`,"Expected identity, union, intersect, or exclude")}}finally{n.delete(o)}}function bH(e,t){if(typeof e==="string"){if(e.length===0||new TextEncoder().encode(e).byteLength>Px)sr(t,"Credential size is outside its supported budget");return e}if(!(e instanceof Uint8Array)||e.byteLength===0||e.byteLength>Px)sr(t,"Expected non-empty credential text or bytes");return e.slice()}function lN(e,t){if(typeof e!=="object"||e===null||Array.isArray(e))sr(t,"Expected an object");let r=Object.getPrototypeOf(e);if(r!==null&&Object.getPrototypeOf(r)!==null)sr(t,"Expected a plain record-like object");return e}function Zi(e,t,r){let i=Object.getOwnPropertyDescriptor(e,t);if(i===void 0||!i.enumerable||!("value"in i))sr(r,"Expected an enumerable data property");return i.value}function aN(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function $u(e,t,r){let i=Reflect.ownKeys(e);if(i.some((s)=>typeof s!=="string"))sr(r,"Symbol fields are not supported");let n=i.sort(uN),o=[...t].sort(uN);if(n.length!==o.length||n.some((s,a)=>s!==o[a]))sr(r,`Expected exactly ${t.join(", ")}`)}function cN(e,t,r){if(!Array.isArray(e)||e.length<r||e.length>on)sr(t,`Expected ${r}-${on} operands`);if(Object.keys(e).length!==e.length)sr(t,"Expected a dense array");return e}function uN(e,t){return e<t?-1:e>t?1:0}function sr(e,t){throw new be("AUTH_GRANT_INVALID",t,e)}var qp=Object.freeze({expressionDepth:64,operandsPerExpression:512,localsPerExpression:64,repeatMaximum:16}),Zae=qp.operandsPerExpression;var Kp={};ze(Kp,{MAX_REQUIRED_CLAIMS:()=>Tu,matches:()=>Nu,verifyRequired:()=>Jp});var Tu=64;function Nu(e,t){let r=t[e.claim];switch(e.op){case"exists":return Object.hasOwn(t,e.claim);case"eq":return r!==void 0&&pN(r,e.value);case"contains":return Array.isArray(r)&&r.some((i)=>pN(i,e.value))}}function pN(e,t){return te.serialize(e)===te.serialize(t)}function Jp(e,t){for(let r=0;r<e.length;r++)if(!Nu(e[r],t))throw TypeError(`Verified claims do not satisfy required constraint ${r}.`)}var zce=new TextDecoder("utf-8",{fatal:!0});var ht={};ze(ht,{accept:()=>Wi,is:()=>Ux});var OH=/^(?=.{1,253}$)(?:(?!-)[a-z0-9-]{1,63}(?<!-)\.)+(?:(?!-)[a-z0-9-]{2,63}(?<!-))$/i,DH=/^([a-z][a-z0-9+.-]*):(.*)$/i,_H=Object.freeze({http:"80",https:"443"});function Wi(e){if(typeof e!=="string")AH();try{return kH(e)}catch(t){if(t instanceof be)throw t;throw new be("AUTH_ISSUER_INVALID","Expected a supported issuer identifier","",{cause:t})}}function Ux(e){if(typeof e!=="string")return!1;try{return Wi(e)===e}catch{return!1}}function kH(e){let t=e.trim();if(t.length===0)throw TypeError("Issuer cannot be empty");if(OH.test(t))return t.toLowerCase();let r=DH.exec(t);if(r===null||r[2].length===0)throw TypeError("Issuer must be absolute");let i=r[1].toLowerCase(),n=r[2];if(!n.startsWith("//"))return`${i}:${n}`;let o=n.slice(2),s=o.search(/[/?#]/),a=s<0?o:o.slice(0,s),c=s<0?"":o.slice(s),u=c==="/"?"":c;if(a.length===0)throw TypeError("Issuer authority cannot be empty");return`${i}://${SH(a,i)}${u}`}function SH(e,t){let r=e.lastIndexOf("@"),i=r<0?"":e.slice(0,r+1),n=r<0?e:e.slice(r+1),o,s;if(n.startsWith("[")){let a=n.indexOf("]");if(a<0)throw TypeError("Issuer has an invalid IPv6 authority");if(o=n.slice(0,a+1).toLowerCase(),s=n.slice(a+1),s!==""&&!/^:\d+$/u.test(s))throw TypeError("Issuer has an invalid port")}else{let a=n.indexOf(":"),c=n.lastIndexOf(":");if(a!==c)throw TypeError("Issuer IPv6 authority must be bracketed");if(o=(c<0?n:n.slice(0,c)).toLowerCase(),s=c<0?"":n.slice(c),s!==""&&!/^:\d+$/u.test(s))throw TypeError("Issuer has an invalid port")}if(o.length===0)throw TypeError("Issuer host cannot be empty");if(s.startsWith(":")&&_H[t]===s.slice(1))s="";return`${i}${o}${s}`}function AH(){throw new be("AUTH_ISSUER_INVALID","Expected a supported issuer identifier")}var yN=/^\/:([^:]+):class\.([A-Za-z][A-Za-z0-9_]*)$/u,Ze=Object.freeze({parse(e){if(!xa(e))throw new di(e);return e},from(e,t){if(typeof e==="string"){if(t===void 0)throw new di(e);return Ze.parse(`/:${e}:class.${t}`)}if(e.kind!=="class")throw new di(e);return Ze.parse(`/:${e.origin}:class.${e.name}`)},origin(e){return gN(e).origin},name(e){return gN(e).name}});function xa(e){if(typeof e!=="string")return!1;let t=yN.exec(e);return t!==null&&t[1].length<=253&&Y.patterns.origin.test(t[1])&&Y.patterns.memberName.test(t[2])}class di extends TypeError{input;code="CLASS_PATH_INVALID";constructor(e){super(`Invalid canonical ClassPath: ${JH(e)}.`);this.input=e,this.name="ClassPathError"}}function gN(e){let t=yN.exec(e);if(t===null)throw new di(e);return{origin:t[1],name:t[2]}}function JH(e){try{return JSON.stringify(e)??String(e)}catch{return String(e)}}var fi=Object.freeze({type:"string",minLength:1,maxLength:255,fullMatch:"[A-Za-z0-9]([A-Za-z0-9._-]{0,253}[A-Za-z0-9])?"}),KH=/^[A-Za-z0-9](?:[A-Za-z0-9._-]{0,253}[A-Za-z0-9])?$/u;class Fx extends TypeError{input;code="EDGE_SLUG_INVALID";constructor(e){super("EdgeSlug must contain 1 to 255 ASCII characters, start and end with an alphanumeric character, and use only alphanumeric, dot, underscore, or hyphen characters.");this.input=e,this.name="EdgeSlugError"}}function Jo(e){return typeof e==="string"&&e.length<=255&&KH.test(e)}function Pn(e){if(!Jo(e))throw new Fx(e);return e}class Ko extends TypeError{input;code="PATH_INVALID";diagnostics;constructor(e,t){super(t[0].message);this.input=e,this.name="PathError",this.diagnostics=Object.freeze(t.map((r)=>Object.freeze(r)))}}function Yt(e,t,r,i){return new Ko(e,[{code:t,message:r,...i===void 0?{}:{position:i}}])}var ZH=new Set(["class","interface","function","policy","view","core"]);function Ru(e){if(e.length===0)throw Yt(e,"PATH_EMPTY","Path source is empty.",0);let t=e.startsWith("@")?WH(e):YH(e);if(EN(t)!==e)throw Yt(e,"PATH_NON_CANONICAL","Path source is not canonical.");return t}function gn(e){if(!Zp(e)||!Zo(e,["anchor","steps"])||!Array.isArray(e.steps))return Ut();let t=eV(e.anchor),r=[];for(let i of e.steps){if(!Zp(i)||typeof i.kind!=="string")Ut();if(i.kind==="projection"){if(!Zo(i,["kind","projection"])||t.kind!=="domain"||r.length!==0)Ut();r.push({kind:"projection",projection:tV(i.projection)});continue}if(i.kind==="method"){if(!Zo(i,["kind","dispatch","name"]))Ut();if(i.dispatch!=="static"&&i.dispatch!=="instance")Ut();if(typeof i.name!=="string"||!Y.patterns.memberName.test(i.name))Ut();if(i.dispatch==="static"){let n=r.length===1?r[0]:void 0;if(t.kind!=="domain"||n?.kind!=="projection"||n.projection.kind!=="class"&&n.projection.kind!=="interface")Ut()}r.push({kind:"method",dispatch:i.dispatch,name:i.name});continue}if(i.kind==="traverse"){let n=i.slug===void 0?["kind","direction","class"]:["kind","direction","class","slug"];if(!Zo(i,n)||r.at(-1)?.kind==="method")Ut();if(i.direction!=="out"&&i.direction!=="in")Ut();if(typeof i.class!=="string")Ut();let o;try{o=Ze.parse(i.class)}catch(a){if(a instanceof di)return Ut();throw a}let s=i.slug===void 0?void 0:rV(i.slug);r.push({kind:"traverse",direction:i.direction,class:o,...s===void 0?{}:{slug:s}});continue}throw Yt(e,"PATH_UNSUPPORTED_STEP","Path AST contains an unsupported step.")}if(r.some((i,n)=>i.kind==="method"&&n!==r.length-1))Ut();return Wp({anchor:t,steps:r})}function ju(e){return EN(gn(e))}function WH(e){let t=Vx(e,1),r=e.slice(1,t);if(!nn(r))throw Yt(e,"PATH_INVALID_NODE_ID","Id anchor is invalid.",1);return Wp({anchor:{kind:"id",id:r},steps:bN(e,t,"id")})}function YH(e){if(!e.startsWith("/:"))throw Yt(e,"PATH_UNKNOWN_FORM","Path must start with a Domain origin (`/:<domain-origin>`) or a Node ID (`@<node-id>`).",0);let t=Vx(e,2),r=e.slice(2,t);if(!vN(r))throw Yt(e,"PATH_INVALID_ORIGIN","Domain anchor contains an invalid origin.",2);return Wp({anchor:{kind:"domain",origin:r},steps:bN(e,t,"domain")})}function bN(e,t,r){let i=[],n=t;while(n<e.length){if(e.startsWith("::",n)){let c=e.slice(n+2);if(!Y.patterns.memberName.test(c))throw Yt(e,"PATH_INVALID_METHOD","Invalid instance Method name.",n+2);i.push({kind:"method",dispatch:"instance",name:c}),n=e.length;continue}if(e[n]===":"){let c=Vx(e,n+1),u=e.slice(n+1,c);if(r==="domain"&&i.length===0){i.push({kind:"projection",projection:QH(e,u,n+1)}),n=c;continue}let l=i.length===1?i[0]:void 0;if(r!=="domain"||l?.kind!=="projection"||l.projection.kind!=="class"&&l.projection.kind!=="interface"||c!==e.length||!Y.patterns.memberName.test(u))throw Yt(e,"PATH_INVALID_POSITION","Static Method is not in a valid position.",n);i.push({kind:"method",dispatch:"static",name:u}),n=c;continue}let o;if(e.startsWith("<~",n))o="in",n+=2;else if(e[n]==="~")o="out",n+=1;else throw Yt(e,"PATH_UNKNOWN_FORM","Unknown Path step.",n);let s=XH(e,n);n=s.end;let a;if(e[n]==="("){let c=e.indexOf(")",n+1);if(c<0)CN(e,n);let u=e.slice(n+1,c);if(!Jo(u))CN(e,n+1);a=Pn(u),n=c+1}i.push({kind:"traverse",direction:o,class:s.classPath,...a===void 0?{}:{slug:a}})}return i}function QH(e,t,r){let i=t.indexOf(".");if(i<1||t.indexOf(".",i+1)>=0)Gx(e,r);let n=t.slice(0,i),o=t.slice(i+1);if(!xN(n))Gx(e,r);if(n==="core"?!Y.patterns.coreSlug.test(o):!Y.patterns.memberName.test(o))Gx(e,r);return{kind:n,name:o}}function XH(e,t){if(e[t]!=='"')Hx(e,t);let r=e.indexOf('"',t+1);if(r<0)Hx(e,t);try{return{classPath:Ze.parse(e.slice(t+1,r)),end:r+1}}catch(i){if(i instanceof di)return Hx(e,t);throw i}}function eV(e){if(!Zp(e))return Ut();if(e.kind==="id"&&Zo(e,["kind","id"])&&nn(e.id))return{kind:"id",id:e.id};if(e.kind==="domain"&&Zo(e,["kind","origin"])&&vN(e.origin))return{kind:"domain",origin:e.origin};return Ut()}function tV(e){if(!Zp(e)||!Zo(e,["kind","name"]))return Ut();if(!xN(e.kind)||typeof e.name!=="string")return Ut();if(e.kind==="core"?!Y.patterns.coreSlug.test(e.name):!Y.patterns.memberName.test(e.name))return Ut();return{kind:e.kind,name:e.name}}function rV(e){if(!Jo(e))return Ut();return Pn(e)}function EN(e){let t=e.anchor.kind==="id"?`@${e.anchor.id}`:`/:${e.anchor.origin}`;for(let r of e.steps)if(r.kind==="projection")t+=`:${r.projection.kind}.${r.projection.name}`;else if(r.kind==="method")t+=`${r.dispatch==="instance"?"::":":"}${r.name}`;else if(t+=`${r.direction==="in"?"<~":"~"}"${r.class}"`,r.slug!==void 0)t+=`(${r.slug})`;return t}function Vx(e,t){for(let r=t;r<e.length;r++){let i=e[r];if(i===":"||i==="~"||i==="<")return r}return e.length}function vN(e){return typeof e==="string"&&e.length<=253&&Y.patterns.origin.test(e)}function xN(e){return typeof e==="string"&&ZH.has(e)}function Zo(e,t){let r=Object.keys(e).sort(),i=[...t].sort();return r.length===i.length&&r.every((n,o)=>n===i[o])}function Zp(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}function Wp(e){if(e===null||typeof e!=="object"||Object.isFrozen(e))return e;for(let t of Object.values(e))Wp(t);return Object.freeze(e)}function Ut(){throw Yt("<ast>","PATH_AST_INVALID","Path AST violates the V1 semantic grammar.")}function Gx(e,t){throw Yt(e,"PATH_INVALID_PROJECTION","Domain projection reference is invalid.",t)}function Hx(e,t){throw Yt(e,"PATH_INVALID_CLASS","Traversal ClassPath is invalid.",t)}function CN(e,t){throw Yt(e,"PATH_INVALID_EDGE_SLUG","Traversal Edge slug is invalid.",t)}function yn(e){return ju(Ru(e))}class q{raw;ast;constructor(){}static from(e){return e instanceof q?e:q.parse(e)}static parse(e){return pi(Ru(e))}static fromAST(e){return pi(gn(e))}static id(e){return pi(gn({anchor:{kind:"id",id:e},steps:[]}))}static domain(e){return pi(gn({anchor:{kind:"domain",origin:e},steps:[]}))}static project(e){let{origin:t,projection:r}=nV(e);return pi(gn({anchor:{kind:"domain",origin:t},steps:[{kind:"projection",projection:r}]}))}static staticMethod(e,t){if(e.projection.kind!=="class"&&e.projection.kind!=="interface")throw Yt(e.raw,"PATH_INVALID_POSITION","Static Method owner must be a Class or Interface.");return pi(gn({anchor:e.ast.anchor,steps:[...e.ast.steps,{kind:"method",dispatch:"static",name:t}]}))}static instanceMethod(e,t){return pi(gn({anchor:e.ast.anchor,steps:[...e.ast.steps,{kind:"method",dispatch:"instance",name:t}]}))}out(e,t={}){return this.traverse("out",e,t)}in(e,t={}){return this.traverse("in",e,t)}equals(e){return this.raw===e.raw}toString(){return this.raw}toJSON(){return this.raw}traverse(e,t,r){let i=r.slug===void 0?void 0:Pn(r.slug);return pi(gn({anchor:this.ast.anchor,steps:[...this.ast.steps,{kind:"traverse",direction:e,class:Ze.parse(t),...i===void 0?{}:{slug:i}}]}))}}function pi(e){let t=Object.create(q.prototype);return mi(t,"ast",e),mi(t,"raw",ju(e)),oV(t),Object.freeze(t)}function nV(e){if(typeof e==="string")return{origin:Ze.origin(e),projection:{kind:"class",name:Ze.name(e)}};let t=iV(e.kind);return{origin:e.origin,projection:{kind:t,name:e.name}}}function iV(e){return e}function oV(e){let{anchor:t,steps:r}=e.ast,i=r.at(-1);if(t.kind==="id"&&r.length===0)mi(e,"id",t.id);if(t.kind==="domain"&&r.length===0)mi(e,"origin",t.origin);if(t.kind==="domain"&&r.length===1&&r[0]?.kind==="projection")mi(e,"origin",t.origin),mi(e,"projection",r[0].projection);if(i?.kind==="method")mi(e,"dispatch",i.dispatch),mi(e,"name",i.name),mi(e,"source",pi(gn({anchor:t,steps:r.slice(0,-1)})))}function mi(e,t,r){Object.defineProperty(e,t,{enumerable:!0,value:r})}function wa(e){return Object.freeze({source:e.source,target:e.target,class:e.class,...e.slug===void 0?{}:{slug:e.slug},props:e.props})}function Cr(e,t){return At(e.source,t.source)||At(e.target,t.target)||sV(e.class,t.class)}function sV(e,t){return e<t?-1:e>t?1:0}function Ge(e){return JSON.stringify([e.source,e.target,e.class])}function it(e){return Object.freeze({source:e.source,target:e.target,class:e.class})}function ar(e,t=""){let r=se(e);if(r===null||typeof r!=="object"||Array.isArray(r))throw TypeError(`Expected Properties object at ${t||"/"}.`);let i=r,n=[];for(let o of Object.keys(i)){if(!Pe.is(o))throw TypeError(`Invalid PropertyKey ${JSON.stringify(o)} at ${t||"/"}.`);n.push([Pe(o),wN(i[o])])}return Pu(n)}function Pu(e){let t=Object.create(null);for(let[r,i]of[...e].sort(([n],[o])=>aV(n,o)))Object.defineProperty(t,r,{enumerable:!0,value:i});return Object.freeze(t)}function Ln(e,t){if(e===t)return!0;let r=Object.keys(e),i=Object.keys(t);return r.length===i.length&&r.every((n,o)=>n===i[o]&&Nr(e[Pe(n)],t[Pe(n)]))}function wN(e){if(e===null||typeof e!=="object")return e;for(let t of Object.values(e))wN(t);return Object.freeze(e)}function aV(e,t){return e<t?-1:e>t?1:0}function Kx(e,t=""){let r=se(e);if(r===null||typeof r!=="object"||Array.isArray(r)||!cV(r,["set","unset"]))throw TypeError(`Expected Property Delta object at ${t||"/"}.`);let i=ar(r.set,qx(t,"set"));if(!Array.isArray(r.unset))throw TypeError(`Expected Property Delta.unset array at ${qx(t,"unset")}.`);let n=r.unset.map((o,s)=>{if(typeof o!=="string"||!Pe.is(o))throw TypeError(`Invalid PropertyKey ${JSON.stringify(o)} at ${qx(t,`unset/${s}`)}.`);return Pe(o)});n.sort(Jx);for(let o=1;o<n.length;o+=1)if(n[o-1]===n[o])throw TypeError(`Property Delta repeats unset key ${n[o]}.`);for(let o of n)if(Object.hasOwn(i,o))throw TypeError(`Property Delta both sets and unsets ${o}.`);return IN(i,n)}function Jx(e,t){return e<t?-1:e>t?1:0}function IN(e,t){return Object.freeze({set:e,unset:Object.freeze([...t])})}function cV(e,t){let r=Object.keys(e).sort(Jx),i=[...t].sort(Jx);return r.length===i.length&&r.every((n,o)=>n===i[o])}function qx(e,t){return`${e}/${t}`}function Qp(e,t,r){let i=[...new Set([...Object.keys(e),...Object.keys(t),...Object.keys(r)])].map(Pe).sort(lV),n=[],o=[];for(let s of i){let a=Zx(e,s),c=Zx(t,s),u=Zx(r,s),l=uV(a,c,u);if(l===ON)o.push(Object.freeze({property:s}));else if(l!==Yp)n.push([s,l])}return o.length>0?Object.freeze({kind:"conflict",conflicts:Object.freeze(o)}):Object.freeze({kind:"merged",value:Pu(n)})}var Yp=Symbol("absent property"),ON=Symbol("property merge conflict");function Zx(e,t){return Object.hasOwn(e,t)?e[t]:Yp}function uV(e,t,r){if(Wx(t,e))return r;if(Wx(r,e))return t;if(Wx(t,r))return t;return ON}function Wx(e,t){if(e===Yp||t===Yp)return e===t;return Nr(e,t)}function lV(e,t){return e<t?-1:e>t?1:0}class Lu extends TypeError{diagnostics;code="GRAPH_ADMISSION_REJECTED";constructor(e){super(e.length===0?"Graph admission rejected.":`Graph admission rejected: ${e[0].code} at ${e[0].path}.`);this.diagnostics=e,this.name="GraphAdmissionError"}}function Qt(e,t,r){return Object.freeze({code:e,path:t,message:r})}function _N(e){return Object.freeze([...e].sort((t,r)=>Yx(t.path,r.path)||Yx(t.code,r.code)||Yx(t.message,r.message)))}function Yx(e,t){return e<t?-1:e>t?1:0}function Qx(e,t){let r=[],i=new Map,n=dV(e,t,i,r),o=new Map(n.map((c)=>[c.id,c])),s=fV(e,t,o,i,r);n.sort((c,u)=>At(c.id,u.id)),s.sort((c,u)=>Cr(it(c),it(u))),pV(n,r),mV(s,r);let a=_N(r);if(a.length>0)throw new Lu(a);return Object.freeze({data:Object.freeze({nodes:Object.freeze(n),edges:Object.freeze(s)}),classes:i})}function dV(e,t,r,i){if(!e||!Array.isArray(e.nodes))return i.push(Qt("GRAPH_FACT_INVALID","/nodes","Expected Node collection.")),[];return e.nodes.flatMap((n,o)=>{let s=`/nodes/${o}`;if(!n||!nn(n.id)||!xa(n.class))return i.push(Qt("GRAPH_FACT_INVALID",s,"Invalid Node fact.")),[];let a;try{a=Su({id:n.id,class:n.class,props:ar(n.props,`${s}/props`)})}catch(u){return i.push(Qt("GRAPH_FACT_INVALID",`${s}/props`,u instanceof Error?u.message:"Invalid Node properties.")),[]}let c=SN(t,a.class,`${s}/class`,r,i);if(c!==void 0&&c.kind!=="node")i.push(Qt("GRAPH_CLASS_KIND",`${s}/class`,"Node ClassPath resolves to an Edge Class."));else if(c?.orientation!==void 0)i.push(Qt("GRAPH_CLASS_ORIENTATION",`${s}/class`,"Node Class has an orientation."));if(c?.kind==="node")Xx(t.validateProperties(a.class,a.props),i);return[a]})}function fV(e,t,r,i,n){if(!e||!Array.isArray(e.edges))return n.push(Qt("GRAPH_FACT_INVALID","/edges","Expected Edge collection.")),[];return e.edges.flatMap((o,s)=>{let a=`/edges/${s}`;if(!o||!nn(o.source)||!nn(o.target)||!xa(o.class)||o.slug!==void 0&&!Jo(o.slug))return n.push(Qt("GRAPH_FACT_INVALID",a,"Invalid Edge fact.")),[];let c;try{c=ar(o.props,`${a}/props`)}catch(l){return n.push(Qt("GRAPH_FACT_INVALID",`${a}/props`,l instanceof Error?l.message:"Invalid Edge properties.")),[]}let u=SN(t,o.class,`${a}/class`,i,n);if(u!==void 0&&u.kind!=="edge")n.push(Qt("GRAPH_CLASS_KIND",`${a}/class`,"Edge ClassPath resolves to a Node Class."));else if(u?.kind==="edge"){let[l,d]=u.orientation==="undirected"&&At(o.source,o.target)>0?[o.target,o.source]:[o.source,o.target],f=wa({source:l,target:d,class:o.class,...o.slug===void 0?{}:{slug:o.slug},props:c});return Xx(t.validateProperties(f.class,f.props),n),kN(f,"source",r,t,n),kN(f,"target",r,t,n),[f]}return[wa({source:o.source,target:o.target,class:o.class,...o.slug===void 0?{}:{slug:o.slug},props:c})]})}function SN(e,t,r,i,n){let o=e.inspectClass(t);if(o===void 0){n.push(Qt("GRAPH_CLASS_UNKNOWN",r,`Unknown Class ${t}.`));return}if(!xa(o.path)||o.path!==t){n.push(Qt("GRAPH_CLASS_MISMATCH",r,"Schema context returned a different Class."));return}if(o.kind==="node"&&o.orientation!==void 0||o.kind==="edge"&&o.orientation!=="directed"&&o.orientation!=="undirected"){n.push(Qt("GRAPH_CLASS_INVALID",r,"Schema context returned invalid Graph Class information."));return}let s=o.kind==="edge"?Object.freeze({path:o.path,kind:o.kind,orientation:o.orientation}):Object.freeze({path:o.path,kind:o.kind});return i.set(t,s),s}function kN(e,t,r,i,n){let o=r.get(e[t]);if(o===void 0)return;Xx(i.validateEndpoint(e.class,t,o.class),n)}function Xx(e,t){for(let r of e)if(r&&typeof r.code==="string"&&typeof r.path==="string"&&typeof r.message==="string")t.push(Qt(r.code,r.path,r.message));else t.push(Qt("GRAPH_CONTEXT_INVALID","",`Schema context returned an invalid diagnostic: ${BV(r)}.`))}function pV(e,t){for(let r=1;r<e.length;r++)if(e[r-1].id===e[r].id)t.push(Qt("GRAPH_NODE_DUPLICATE",`/nodes/${r}/id`,`Duplicate NodeId ${e[r].id}.`))}function mV(e,t){let r=new Set;for(let i=0;i<e.length;i++){let n=Ge(it(e[i]));if(r.has(n))t.push(Qt("GRAPH_EDGE_DUPLICATE",`/edges/${i}`,"Duplicate normalized EdgeKey."));r.add(n)}}function BV(e){try{return te.serialize(e)}catch{return"<non-json>"}}function AN(e,t){let r=new Map(e.nodes.all.map((u)=>[u.id,u])),i=[],n=[],o=[];for(let u of t.nodes.all){let l=r.get(u.id);if(l===void 0)i.push(u);else if(l.class!==u.class)o.push(Object.freeze({kind:"node-class",node:u.id,left:l.class,right:u.class}));else if(!Ln(l.props,u.props))n.push(u)}let s=new Map(e.edges.all.map((u)=>[Ge(it(u)),u])),a=[],c=[];for(let u of t.edges.all){let l=s.get(Ge(it(u)));if(l===void 0)a.push(u);else if(l.slug!==u.slug||!Ln(l.props,u.props))c.push(u)}if(o.length>0)return Object.freeze({kind:"conflict",conflicts:Object.freeze(o)});return Object.freeze({kind:"delta",value:Object.freeze({additions:ew(i,a),replacements:ew(n,c)})})}function $N(e,t){let r=new Map(e.nodes.all.map((n)=>[n.id,n])),i=new Map(e.edges.all.map((n)=>[Ge(it(n)),n]));for(let n of t.additions.nodes){if(r.has(n.id))zu(`Graph Delta adds existing Node ${n.id}.`);r.set(n.id,n)}for(let n of t.replacements.nodes){let o=r.get(n.id);if(o===void 0)zu(`Graph Delta replaces absent Node ${n.id}.`);if(o.class!==n.class)zu(`Graph Delta changes Node ${n.id} Class.`);r.set(n.id,n)}for(let n of t.additions.edges){let o=Ge(it(n));if(i.has(o))zu(`Graph Delta adds existing Edge ${o}.`);i.set(o,n)}for(let n of t.replacements.edges){let o=Ge(it(n));if(!i.has(o))zu(`Graph Delta replaces absent Edge ${o}.`);i.set(o,n)}return ew([...r.values()].sort((n,o)=>At(n.id,o.id)),[...i.values()].sort((n,o)=>Cr(it(n),it(o))))}function ew(e,t){return Object.freeze({nodes:Object.freeze(e),edges:Object.freeze(t)})}function zu(e){throw TypeError(e)}var hV=Object.freeze([]),TN=Object.freeze([]);function rw(e,t,r){let i=Object.freeze({all:e,length:e.length,byId:(o)=>r.nodes.byId.get(o),byClass:(o)=>r.nodes.byClass.get(o)??hV}),n=Object.freeze({all:t,length:t.length,byKey:(o)=>r.edges.byKey.get(Ge(gV(o,r.classes))),byClass:(o)=>r.edges.byClass.get(o)??TN,incident:(o)=>r.edges.byEndpoint.get(o)??TN});return Object.freeze({nodes:i,edges:n})}function gV(e,t){let r=t.byPath.get(e.class);if(r?.kind!=="edge"||r.orientation!=="undirected")return e;if(At(e.source,e.target)<=0)return e;return{source:e.target,target:e.source,class:e.class}}function em(e,t,r){let i=new Map(r),n=new Map,o=new Map,s=new Map,a=new Map,c=new Map;for(let u of e)n.set(u.id,u),Xp(s,u.class,u);for(let u of t)if(o.set(Ge({source:u.source,target:u.target,class:u.class}),u),Xp(a,u.class,u),Xp(c,u.source,u),u.target!==u.source)Xp(c,u.target,u);return tw(s),tw(a),tw(c),Object.freeze({nodes:Object.freeze({byId:n,byClass:s}),edges:Object.freeze({byKey:o,byClass:a,byEndpoint:c}),classes:Object.freeze({byPath:i})})}function Xp(e,t,r){let i=e.get(t);if(i===void 0)e.set(t,[r]);else i.push(r)}function tw(e){for(let[t,r]of e)e.set(t,Object.freeze(r))}function ow(e,t,r){let i=new Map(e.nodes.map((h)=>[h.id,h])),n=new Map(t.nodes.map((h)=>[h.id,h])),o=new Map(r.nodes.map((h)=>[h.id,h])),s=[...new Set([...i.keys(),...n.keys(),...o.keys()])].sort(At),a=[],c=[];for(let h of s){let g=yV(h,i.get(h),n.get(h),o.get(h));if(g.value!==void 0)a.push(g.value);c.push(...g.conflicts)}let u=iw(e.edges),l=iw(t.edges),d=iw(r.edges),f=new Map;for(let h of[...e.edges,...t.edges,...r.edges])f.set(Ge(it(h)),it(h));let m=[...f.entries()].sort(([,h],[,g])=>Cr(h,g)),B=[];for(let[h,g]of m){let w=CV(g,u.get(h),l.get(h),d.get(h));if(w.value!==void 0)B.push(w.value);c.push(...w.conflicts)}return c.length>0?Object.freeze({kind:"conflict",conflicts:Object.freeze(c)}):Object.freeze({kind:"merged",value:vV(a,B)})}function yV(e,t,r,i){let n=NN(t,r,i,bV);if(n!==sw)return Object.freeze({...n?{value:n}:{},conflicts:[]});if(t===void 0||r===void 0||i===void 0)return Object.freeze({conflicts:[Object.freeze({kind:"node-presence",node:e})]});let o=[],s=RN(t.class,r.class,i.class);if(s===Mu)o.push(Object.freeze({kind:"node-class",node:e}));let a=Qp(t.props,r.props,i.props);if(a.kind==="conflict")for(let c of a.conflicts)o.push(Object.freeze({kind:"node-property",node:e,property:c.property}));if(s===Mu||a.kind==="conflict")return Object.freeze({conflicts:Object.freeze(o)});return Object.freeze({value:Object.freeze({id:e,class:s,props:a.value}),conflicts:Object.freeze([])})}function CV(e,t,r,i){let n=NN(t,r,i,EV);if(n!==sw)return Object.freeze({...n?{value:n}:{},conflicts:[]});if(t===void 0||r===void 0||i===void 0)return Object.freeze({conflicts:[Object.freeze({kind:"edge-presence",edge:e})]});let o=[],s=RN(t.slug,r.slug,i.slug);if(s===Mu)o.push(Object.freeze({kind:"edge-slug",edge:e}));let a=Qp(t.props,r.props,i.props);if(a.kind==="conflict")for(let c of a.conflicts)o.push(Object.freeze({kind:"edge-property",edge:e,property:c.property}));if(s===Mu||a.kind==="conflict")return Object.freeze({conflicts:Object.freeze(o)});return Object.freeze({value:Object.freeze({...e,...s===void 0?{}:{slug:s},props:a.value}),conflicts:Object.freeze([])})}var sw=Symbol("recurse"),Mu=Symbol("conflict");function NN(e,t,r,i){if(nw(t,e,i))return r;if(nw(r,e,i))return t;if(nw(t,r,i))return t;return sw}function RN(e,t,r){if(t===e)return r;if(r===e)return t;if(t===r)return t;return Mu}function nw(e,t,r){return e===void 0||t===void 0?e===t:r(e,t)}function bV(e,t){return e.id===t.id&&e.class===t.class&&Ln(e.props,t.props)}function EV(e,t){return Ge(it(e))===Ge(it(t))&&e.slug===t.slug&&Ln(e.props,t.props)}function iw(e){return new Map(e.map((t)=>[Ge(it(t)),t]))}function vV(e,t){return Object.freeze({nodes:Object.freeze(e),edges:Object.freeze(t)})}class Uu extends Error{path;code="GRAPH_PATH_WALKER_REQUIRED";constructor(e){super(`Graph Path ${JSON.stringify(e)} requires a walker.`);this.path=e,this.name="GraphPathWalkerRequiredError"}}var aw=Object.freeze({nodes:Object.freeze([]),edges:Object.freeze([])}),wV=em(aw.nodes,aw.edges,new Map);class Fu{static#e=new Fu(aw,wV);nodes;edges;#t;#r;#n;#i;constructor(e,t,r){this.#t=e,this.#r=t,this.#n=r;let i=rw(e.nodes,e.edges,t);this.nodes=i.nodes,this.edges=i.edges,this.#i=Object.freeze({nodes:this.nodes,edges:this.edges,orientation:(n)=>{let o=this.#r.classes.byPath.get(n);return o?.kind==="edge"?o.orientation:void 0}}),Object.freeze(this)}static admit(e,t,r){let i=Qx(e,t),n=em(i.data.nodes,i.data.edges,i.classes);return new Fu(i.data,n,r)}static empty(){return Fu.#e}static delta(e,t){return AN(e,t)}static apply(e,t){return $N(e,t)}static merge(e,t,r){return ow(e.toData(),t.toData(),r.toData())}static mergeData(e,t,r){return ow(e,t,r)}walk(e){let t=q.from(e);if(this.#n!==void 0)return this.#n.walk(t,this.#i);if(t.ast.anchor.kind==="id"&&t.ast.steps.length===0)return this.#r.nodes.byId.get(t.ast.anchor.id);throw new Uu(t.raw)}toData(){return this.#t}equals(e){if(this===e)return!0;if(this.nodes.length!==e.nodes.length||this.edges.length!==e.edges.length)return!1;return this.nodes.all.every((t,r)=>IV(t,e.nodes.all[r]))&&this.edges.all.every((t,r)=>OV(t,e.edges.all[r]))}}function IV(e,t){return e.id===t.id&&e.class===t.class&&Ln(e.props,t.props)}function OV(e,t){let r=it(e),i=it(t);return r.source===i.source&&r.target===i.target&&r.class===i.class&&e.slug===t.slug&&Ln(e.props,t.props)}function zn(e,t,r){let i=e.safeParse(t);if(i.success)return i.data;let n=i.error.issues[0];if(n===void 0)r("","Invalid wire value");r(n.path.length===0?"":`/${n.path.map((o)=>DV(String(o))).join("/")}`,n.message)}function DV(e){return e.replaceAll("~","~0").replaceAll("/","~1")}var _V=/^[A-Za-z][A-Za-z0-9_]{0,63}$/u;function Ur(e){if(!Mn(e))throw TypeError(`Invalid local binding ${JSON.stringify(e)}.`);return e}function Mn(e){return typeof e==="string"&&_V.test(e)}var Bi=p.string().min(1),tm=p.record(p.string(),p.unknown()),PN=p.string().check(en("[A-Za-z][A-Za-z0-9_]{0,63}")),LN=p.string().min(fi.minLength).max(fi.maxLength).check(en(fi.fullMatch)),rm=p.strictObject({id:Bi,class:Bi,props:tm}),kV=p.strictObject({as:PN,class:Bi,props:tm}),nm=p.strictObject({source:Bi,target:Bi,class:Bi}),cw=nm.extend({slug:LN.optional(),props:tm}),jN=p.union([Bi,p.strictObject({path:Bi}),p.strictObject({created:PN})]),SV=p.strictObject({source:jN,target:jN,class:Bi,slug:LN.optional(),props:tm}),zN=p.strictObject({nodes:p.array(p.union([rm,kV])),edges:p.array(SV)}),MN=p.strictObject({nodes:p.array(rm),edges:p.array(cw)});class Yi extends TypeError{path;code="GRAPH_DATA_INVALID";constructor(e,t,r){super(`${t} at ${e||"/"}.`,r);this.path=e,this.name="GraphDataDecodeError"}}class Wo extends TypeError{path;code="GRAPH_SPEC_INVALID";constructor(e,t,r){super(`${t} at ${e||"/"}.`,r);this.path=e,this.name="GraphSpecDecodeError"}}function im(e){try{let t=zn(zN,se(e),Cn),r=t.nodes.map((n,o)=>AV(n,`/nodes/${o}`)),i=t.edges.map((n,o)=>$V(n,`/edges/${o}`));return TV(r,i),Object.freeze({nodes:Object.freeze(r),edges:Object.freeze(i)})}catch(t){if(t instanceof Wo)throw t;throw new Wo(fw(t),"Invalid GraphSpec",{cause:t})}}function lw(e){let t=e.nodes.map((n)=>("id"in n)?Object.freeze({id:n.id,class:n.class,props:uw(n.props)}):Object.freeze({as:n.as,class:n.class,props:uw(n.props)})),r=e.edges.map((n)=>Object.freeze({source:GN(n.source),target:GN(n.target),class:n.class,...n.slug===void 0?{}:{slug:n.slug},props:uw(n.props)})),i=Object.freeze({nodes:Object.freeze(t),edges:Object.freeze(r)});return im(i),i}function dw(e){try{let t=im(e),r=t.nodes.map((n,o)=>{if(!("id"in n))Gu(`/nodes/${o}/as`,"GraphData cannot contain anonymous Nodes");return n}),i=t.edges.map((n,o)=>{if(typeof n.source!=="string")Gu(`/edges/${o}/source`,"GraphData endpoints must be NodeIds");if(typeof n.target!=="string")Gu(`/edges/${o}/target`,"GraphData endpoints must be NodeIds");return wa({source:n.source,target:n.target,class:n.class,...n.slug===void 0?{}:{slug:n.slug},props:n.props})});return NV(r,i),Object.freeze({nodes:Object.freeze(r),edges:Object.freeze(i)})}catch(t){if(t instanceof Yi)throw t;throw new Yi(t instanceof Wo?t.path:fw(t),"Invalid GraphData",{cause:t})}}function HN(e){let t=lw(e);return dw(t),t}function AV(e,t){let r=qN(e.class,`${t}/class`),i=KN(e.props,`${t}/props`);if("id"in e)return Su({id:JN(e.id,`${t}/id`),class:r,props:i});return Object.freeze({as:VN(e.as,`${t}/as`),class:r,props:i})}function $V(e,t){return Object.freeze({source:UN(e.source,`${t}/source`),target:UN(e.target,`${t}/target`),class:qN(e.class,`${t}/class`),...e.slug===void 0?{}:{slug:RV(e.slug,`${t}/slug`)},props:KN(e.props,`${t}/props`)})}function UN(e,t){if(typeof e==="string")return JN(e,t);if("path"in e)try{return Object.freeze({path:yn(e.path)})}catch{Cn(`${t}/path`,"Expected canonical NodePath string")}return Object.freeze({created:VN(e.created,`${t}/created`)})}function VN(e,t){if(!Mn(e))Cn(t,"Expected a local binding name of at most 64 characters");return Ur(e)}function TV(e,t){let r=new Set,i=new Set;for(let o=0;o<e.length;o++){let s=e[o];if("id"in s){if(r.has(s.id))Cn(`/nodes/${o}/id`,`Duplicate NodeId ${JSON.stringify(s.id)}`);r.add(s.id)}else{if(i.has(s.as))Cn(`/nodes/${o}/as`,`Duplicate binding ${JSON.stringify(s.as)}`);i.add(s.as)}}let n=new Set;for(let o=0;o<t.length;o++){let s=t[o];for(let[c,u]of[["source",s.source],["target",s.target]])if(typeof u!=="string"&&"created"in u&&!i.has(u.created))Cn(`/edges/${o}/${c}/created`,`Unresolved binding ${JSON.stringify(u.created)}`);let a=JSON.stringify([FN(s.source),FN(s.target),s.class]);if(n.has(a))Cn(`/edges/${o}`,"Duplicate ordered Edge identity");n.add(a)}}function FN(e){if(typeof e==="string")return["id",e];return"created"in e?["created",e.created]:["path",e.path]}function GN(e){if(typeof e==="string")return e;return"created"in e?Object.freeze({created:e.created}):Object.freeze({path:e.path})}function uw(e){return ar(e)}function NV(e,t){let r=new Set;for(let n=0;n<e.length;n++){let o=e[n].id;if(r.has(o))Gu(`/nodes/${n}/id`,`Duplicate NodeId ${JSON.stringify(o)}`);r.add(o)}let i=new Set;for(let n=0;n<t.length;n++){let o=t[n],s=JSON.stringify([o.source,o.target,o.class]);if(i.has(s))Gu(`/edges/${n}`,"Duplicate ordered Edge identity");i.add(s)}}function Gu(e,t){throw new Yi(e,t)}function Cn(e,t,r){throw new Wo(e,t,r)}function qN(e,t){try{return Ze.parse(e)}catch(r){Cn(t,"Invalid ClassPath",{cause:r})}}function JN(e,t){try{return Fe(e)}catch(r){Cn(t,"Invalid NodeId",{cause:r})}}function RV(e,t){try{return Pn(e)}catch(r){Cn(t,"Invalid EdgeSlug",{cause:r})}}function KN(e,t){try{return ar(e,t)}catch(r){Cn(fw(r,t),"Invalid Properties",{cause:r})}}function fw(e,t=""){return e instanceof he?e.pointer:t}var Hu=Object.freeze({decode:dw,encode:HN}),jV=Object.freeze({decode:im,encode:lw});class bn extends TypeError{path;code="QUERY_AST_INVALID";constructor(e,t,r){super(`${t} at ${e||"/"}.`,r);this.path=e,this.name="QueryASTDecodeError"}}var Ia="astrale.graph.query",Oa="v6",sn=Object.freeze({sourceTerms:1024,steps:256,expansionDefinitionsPerStep:256,bindings:513});var En=p.string().min(1),vn=En.max(64),sm=p.strictObject({origin:En.max(253),kind:p.enum(["class","interface"]),name:En}),PV=p.discriminatedUnion("kind",[p.strictObject({kind:p.literal("path"),path:En}),p.strictObject({kind:p.literal("definition"),definition:sm})]),LV=p.strictObject({kind:p.literal("definition"),definition:sm}),zV=p.discriminatedUnion("kind",[p.strictObject({kind:p.literal("node"),terms:p.array(PV).min(1).max(sn.sourceTerms),binding:vn}),p.strictObject({kind:p.literal("edge"),terms:p.array(LV).min(1).max(sn.sourceTerms),bindings:p.strictObject({source:vn,edge:vn,target:vn})})]),MV=p.discriminatedUnion("kind",[p.strictObject({kind:p.literal("definition.satisfies"),definition:sm}),p.strictObject({kind:p.literal("property.equal"),property:En,value:p.unknown()}),p.strictObject({kind:p.literal("property.present"),property:En}),p.strictObject({kind:p.literal("identity.equal"),identity:p.union([En,p.strictObject({source:En,target:En,class:En})])})]),UV=p.strictObject({op:p.literal("filter"),binding:vn,predicate:MV}),FV=p.strictObject({op:p.literal("expand"),from:vn,via:p.array(sm).min(1).max(sn.expansionDefinitionsPerStep),direction:p.enum(["outgoing","incoming","incident"]),bindings:p.strictObject({edge:vn,node:vn})}),pw=p.strictObject({property:En,direction:p.enum(["asc","desc"]),unranked:p.enum(["first","last"])}),om=p.enum(["reference","value"]),GV=p.strictObject({kind:p.literal("graph"),binding:vn,order:pw.optional()}),HV=p.strictObject({kind:p.literal("nodes"),binding:vn,projection:p.strictObject({kind:om}),order:pw.optional()}),VV=p.strictObject({kind:p.literal("edges"),binding:vn,projection:p.strictObject({edge:om,source:om,target:om}),order:pw.optional()}),Qi=p.strictObject({format:p.literal(Ia),version:p.literal(Oa),source:zV,steps:p.array(p.discriminatedUnion("op",[UV,FV])).max(sn.steps),select:p.discriminatedUnion("kind",[GV,HV,VV])});var WN=new WeakSet;function am(e){try{let t=qV(zn(Qi,se(e),$t));return WN.add(t),t}catch(t){if(t instanceof bn)throw t;throw new bn(eq(t),"Invalid QueryAST",{cause:t})}}function Yo(e){if(WN.has(e))return e;return am(e)}function qV(e){let t=new Map,r=JV(e.source,t),i=e.steps.map((o,s)=>WV(o,s,t));if(t.size>sn.bindings)$t("/steps",`Query introduces more than ${sn.bindings} bindings`);let n=KV(e.select,t);return Object.freeze({format:Ia,version:Oa,source:r,steps:Object.freeze(i),select:n})}function JV(e,t){let r=e.terms.map((i,n)=>ZV(i,`/source/terms/${n}`));if(XN(r,XV,"/source/terms","source term"),e.kind==="node")return Object.freeze({kind:"node",terms:Object.freeze(r),binding:Da(e.binding,"node","/source/binding",t)});if(r.some((i)=>i.kind!=="definition"))$t("/source/terms","Edge source accepts Definition terms only");return Object.freeze({kind:"edge",terms:Object.freeze(r),bindings:Object.freeze({source:Da(e.bindings.source,"node","/source/bindings/source",t),edge:Da(e.bindings.edge,"edge","/source/bindings/edge",t),target:Da(e.bindings.target,"node","/source/bindings/target",t)})})}function KV(e,t){if(e.kind==="graph")return Object.freeze({kind:"graph",binding:Vu(e.binding,void 0,"/select/binding",t),...e.order===void 0?{}:{order:Object.freeze({property:mw(e.order.property,"/select/order/property"),direction:e.order.direction,unranked:e.order.unranked})}});if(e.kind==="nodes")return Object.freeze({kind:"nodes",binding:Vu(e.binding,"node","/select/binding",t),projection:Object.freeze({kind:e.projection.kind}),...e.order===void 0?{}:{order:ZN(e.order)}});return Object.freeze({kind:"edges",binding:Vu(e.binding,"edge","/select/binding",t),projection:Object.freeze({...e.projection}),...e.order===void 0?{}:{order:ZN(e.order)}})}function ZN(e){return Object.freeze({property:mw(e.property,"/select/order/property"),direction:e.direction,unranked:e.unranked})}function ZV(e,t){if(e.kind==="path")try{return Object.freeze({kind:"path",path:yn(e.path)})}catch(r){$t(`${t}/path`,"Invalid NodePath",r)}return Object.freeze({kind:"definition",definition:Bw(e.definition,`${t}/definition`)})}function WV(e,t,r){let i=`/steps/${t}`;if(e.op==="filter"){let c=Vu(e.binding,void 0,`${i}/binding`,r),u=r.get(c);if(u===void 0)$t(`${i}/binding`,"Unknown binding");let l=YV(e.predicate,`${i}/predicate`,u);if(l.kind==="definition.satisfies")return Object.freeze({op:"filter",binding:c,predicate:l});return Object.freeze({op:"filter",binding:c,predicate:l})}let n=Vu(e.from,"node",`${i}/from`,r),o=e.via.map((c,u)=>Bw(c,`${i}/via/${u}`));XN(o,YN,`${i}/via`,"Definition reference");let s=Da(e.bindings.edge,"edge",`${i}/bindings/edge`,r),a=Da(e.bindings.node,"node",`${i}/bindings/node`,r);if(r.size>sn.bindings)$t(i,`Query introduces more than ${sn.bindings} bindings`);return Object.freeze({op:"expand",from:n,via:Object.freeze(o),direction:e.direction,bindings:Object.freeze({edge:s,node:a})})}function YV(e,t,r){if(e.kind==="definition.satisfies")return Object.freeze({kind:"definition.satisfies",definition:Bw(e.definition,`${t}/definition`)});if(e.kind==="identity.equal"){if(r==="node"){if(typeof e.identity!=="string")$t(`${t}/identity`,"Node binding requires a NodeId identity");try{return Object.freeze({kind:"identity.equal",identity:Fe(e.identity)})}catch(n){$t(`${t}/identity`,"Invalid NodeId",n)}}if(typeof e.identity==="string")$t(`${t}/identity`,"Edge binding requires an EdgeKey identity");try{let n=Object.freeze({source:Fe(e.identity.source),target:Fe(e.identity.target),class:Ze.parse(e.identity.class)});return Object.freeze({kind:"identity.equal",identity:n})}catch(n){$t(`${t}/identity`,"Invalid EdgeKey",n)}}let i=mw(e.property,`${t}/property`);if(e.kind==="property.present")return Object.freeze({kind:"property.present",property:i});return Object.freeze({kind:"property.equal",property:i,value:QV(e.value,`${t}/value`)})}function YN(e){return`${e.origin}\x00${e.kind}\x00${e.name}`}function mw(e,t){try{return Pe(e)}catch(r){$t(t,"Invalid PropertyKey",r)}}function QV(e,t){try{return QN(te.decode(te.encode(e)))}catch(r){$t(t,"Invalid portable equality value",r)}}function QN(e){if(e===null||typeof e!=="object")return e;for(let t of Object.values(e))QN(t);return Object.freeze(e)}function Bw(e,t){if(!Y.patterns.origin.test(e.origin))$t(`${t}/origin`,"Invalid Domain origin");if(!Y.patterns.memberName.test(e.name))$t(`${t}/name`,"Invalid Definition name");return Object.freeze({origin:e.origin,kind:e.kind,name:e.name})}function Da(e,t,r,i){let n;try{n=Ur(e)}catch(o){$t(r,"Invalid binding name",o)}if(i.has(n))$t(r,`Duplicate binding ${JSON.stringify(n)}`);return i.set(n,t),n}function Vu(e,t,r,i){let n;try{n=Ur(e)}catch(s){$t(r,"Invalid binding name",s)}let o=i.get(n);if(o===void 0)$t(r,`Unknown or forward binding ${JSON.stringify(n)}`);if(t!==void 0&&o!==t)$t(r,`Expected a ${t} binding but found ${o}`);return n}function XV(e){return e.kind==="path"?`path\x00${e.path}`:`definition\x00${YN(e.definition)}`}function XN(e,t,r,i){let n=new Set;for(let o=0;o<e.length;o++){let s=t(e[o]);if(n.has(s))$t(`${r}/${o}`,`Duplicate ${i}`);n.add(s)}}function $t(e,t,r){throw new bn(e,t,r===void 0?void 0:{cause:r})}function eq(e){return e instanceof he?e.pointer:""}var tq=h_("astrale-query-ast-v6\x00"),eR=new WeakMap;function gw(e){let t=Yo(e),r=eR.get(t);if(r!==void 0)return r;let i=new Map,n=0;if(t.source.kind==="node")i.set(t.source.binding,{kind:"node",index:n++});else i.set(t.source.bindings.source,{kind:"node",index:n++}),i.set(t.source.bindings.edge,{kind:"edge",index:n++}),i.set(t.source.bindings.target,{kind:"node",index:n++});let o=t.steps.map((l)=>{if(l.op==="filter")return{op:"filter",binding:hi(i,l.binding),predicate:nq(l.predicate)};let d={kind:"edge",index:n++},f={kind:"node",index:n++},m={op:"expand",from:hi(i,l.from),via:[...l.via].map(yw).sort(hw),direction:l.direction,bindings:{edge:d,node:f}};return i.set(l.bindings.edge,d),i.set(l.bindings.node,f),m}),s={format:t.format,version:t.version,source:t.source.kind==="node"?{kind:"node",terms:[...t.source.terms].map(tR).sort(hw),binding:hi(i,t.source.binding)}:{kind:"edge",terms:[...t.source.terms].map(tR).sort(hw),bindings:{source:hi(i,t.source.bindings.source),edge:hi(i,t.source.bindings.edge),target:hi(i,t.source.bindings.target)}},steps:o,select:rq(t.select,i)},a=Is(g_(tq,te.encode(s))),c="";for(let l of a)c+=l.toString(16).padStart(2,"0");let u=`sha256:${c}`;return eR.set(t,u),u}function rq(e,t){if(e.kind==="graph")return{kind:e.kind,binding:hi(t,e.binding),...e.order===void 0?{}:{order:{property:e.order.property,direction:e.order.direction,unranked:e.order.unranked}}};if(e.kind==="nodes")return{kind:e.kind,binding:hi(t,e.binding),projection:e.projection,...e.order===void 0?{}:{order:e.order}};return{kind:e.kind,binding:hi(t,e.binding),projection:e.projection,...e.order===void 0?{}:{order:e.order}}}function hi(e,t){let r=e.get(t);if(r===void 0)throw TypeError(`Missing admitted Query binding ${t}.`);return r}function tR(e){return e.kind==="path"?{kind:"path",path:e.path}:{kind:"definition",definition:yw(e.definition)}}function yw(e){return{origin:e.origin,kind:e.kind,name:e.name}}function nq(e){if(e.kind==="definition.satisfies")return{kind:e.kind,definition:yw(e.definition)};if(e.kind==="property.present")return{kind:e.kind,property:e.property};if(e.kind==="identity.equal")return{kind:e.kind,identity:typeof e.identity==="string"?e.identity:{source:e.identity.source,target:e.identity.target,class:e.identity.class}};return{kind:e.kind,property:e.property,value:e.value}}function hw(e,t){return iq(te.encode(e),te.encode(t))}function iq(e,t){let r=Math.min(e.length,t.length);for(let i=0;i<r;i++){let n=e[i]-t[i];if(n!==0)return n<0?-1:1}return Math.sign(e.length-t.length)}var Ot=Object.freeze({format:Ia,version:Oa,limits:sn,decode:am,encode:Yo,fingerprint:gw});function rR(e){if(e.select.kind==="nodes")return"node";if(e.select.kind==="edges")return"edge";if(e.source.kind==="node"){if(e.select.binding===e.source.binding)return"node"}else{if(e.select.binding===e.source.bindings.source||e.select.binding===e.source.bindings.target)return"node";if(e.select.binding===e.source.bindings.edge)return"edge"}for(let t of e.steps){if(t.op!=="expand")continue;if(e.select.binding===t.bindings.node)return"node";if(e.select.binding===t.bindings.edge)return"edge"}throw TypeError("Admitted Query selected an unknown binding.")}class Fr extends TypeError{path;code="MUTATION_AST_INVALID";constructor(e,t,r){super(`${t} at ${e||"/"}.`,r);this.path=e,this.name="MutationASTDecodeError"}}var _a="astrale.graph.mutation",ka="v3",Gr=Object.freeze({preconditions:2048,queryPreconditions:64,queryExpectedIdentities:4096});var cr=p.string().min(1),oR=p.string().min(1).max(64),cm=p.string().check(en(Y.patterns.propertyKeyFullMatch)),um=p.record(cm,p.unknown()),Cw=p.strictObject({set:um,unset:p.array(cm)}),nR=p.union([cr,p.strictObject({created:oR})]),lm=p.strictObject({source:cr,target:cr,class:cr}),bw=p.string().min(fi.minLength).max(fi.maxLength).check(en(fi.fullMatch)),oq=p.strictObject({op:p.literal("edge.update"),edge:lm,slug:bw.nullable(),props:Cw.optional()}),sq=p.strictObject({op:p.literal("edge.update"),edge:lm,props:Cw}),iR=p.union([p.strictObject({equals:um,absent:p.array(cm).optional()}),p.strictObject({absent:p.array(cm).min(1)})]),aq=p.discriminatedUnion("kind",[p.strictObject({kind:p.literal("node"),ids:p.array(cr).max(Gr.queryExpectedIdentities)}),p.strictObject({kind:p.literal("edge"),keys:p.array(p.strictObject({source:cr,target:cr,class:cr})).max(Gr.queryExpectedIdentities)})]),cq=p.union([p.strictObject({kind:p.literal("node"),node:cr,class:cr,props:iR.optional()}),p.strictObject({kind:p.literal("edge"),edge:lm,slug:bw.nullable().optional(),props:iR.optional()}),p.strictObject({kind:p.literal("query"),query:Qi,equals:aq})]),Xi=p.strictObject({format:p.literal(_a),version:p.literal(ka),preconditions:p.array(cq).max(Gr.preconditions),operations:p.array(p.union([p.strictObject({op:p.literal("node.create"),as:oR,class:cr,props:um}),p.strictObject({op:p.literal("node.update"),node:cr,class:cr,props:Cw}),p.strictObject({op:p.literal("node.delete"),node:cr,class:cr}),p.strictObject({op:p.literal("edge.create"),class:cr,source:nR,target:nR,slug:bw.optional(),props:um}),oq,sq,p.strictObject({op:p.literal("edge.delete"),edge:lm})])).min(1)});function xw(e){try{return uq(zn(Xi,se(e),gt))}catch(t){if(t instanceof Fr)throw t;throw new Fr(xq(t),"Invalid MutationAST",{cause:t})}}function uR(e){return xw(e)}function uq(e){let t=e.preconditions.map((i,n)=>lq(i,`/preconditions/${n}`)),r=e.operations.map((i,n)=>Bq(i,`/operations/${n}`));return yq(t),hq(r),Object.freeze({format:_a,version:ka,preconditions:bq(t),operations:gq(r)})}function lq(e,t){if(e.kind==="node")return Object.freeze({kind:"node",node:Aa(e.node,`${t}/node`),class:Sa(e.class,`${t}/class`),...e.props===void 0?{}:{props:sR(e.props,`${t}/props`)}});if(e.kind==="query"){let r=dq(e.query,`${t}/query`),i=rR(r);if(e.equals.kind!==i)gt(`${t}/equals/kind`,`Expected ${i} selection for the Query's selected binding`);return Object.freeze({kind:"query",query:r,equals:fq(e.equals,r,`${t}/equals`)})}return Object.freeze({kind:"edge",edge:dm(e.edge,`${t}/edge`),...Object.hasOwn(e,"slug")?{slug:e.slug===null?null:vw(e.slug,`${t}/slug`)}:{},...e.props===void 0?{}:{props:sR(e.props,`${t}/props`)}})}function dq(e,t){try{return Ot.decode(e)}catch(r){throw new Fr(t,"Invalid query precondition QueryAST",{cause:r})}}function fq(e,t,r){let i=t.select.order===void 0;if(e.kind==="node"){let o=e.ids.map((s,a)=>pq(s,`${r}/ids/${a}`));if(Ow(o,`${r}/ids`,"NodeId"),i)cR(o,At,`${r}/ids`,"NodeId");return Object.freeze({kind:"node",ids:Object.freeze(o)})}let n=e.keys.map((o,s)=>mq(o,`${r}/keys/${s}`));if(Eq(n,Ge,`${r}/keys`,"EdgeKey"),i)cR(n,Cr,`${r}/keys`,"EdgeKey");return Object.freeze({kind:"edge",keys:Object.freeze(n)})}function pq(e,t){if(typeof e!=="string")gt(t,"Expected a NodeId string");try{return Fe(e)}catch(r){throw new Fr(t,"Invalid NodeId",{cause:r})}}function mq(e,t){try{return Object.freeze({source:Fe(e.source),target:Fe(e.target),class:Ze.parse(e.class)})}catch(r){throw new Fr(t,"Invalid EdgeKey",{cause:r})}}function sR(e,t){let r="equals"in e?fm(e.equals,`${t}/equals`):void 0,i=(e.absent??[]).map((n,o)=>Iw(n,`${t}/absent/${o}`));if(Ow(i,`${t}/absent`,"PropertyKey"),i.sort(ww),(r===void 0||Object.keys(r).length===0)&&i.length===0)gt(t,"Expected at least one Property condition");for(let n of i)if(r!==void 0&&Object.hasOwn(r,n))gt(t,`Property ${JSON.stringify(n)} is both equal and absent`);return Object.freeze({...r===void 0?{}:{equals:r},...i.length===0?{}:{absent:Object.freeze(i)}})}function Bq(e,t){switch(e.op){case"node.create":return Object.freeze({op:"node.create",as:dR(e.as,`${t}/as`),class:Sa(e.class,`${t}/class`),props:fm(e.props,`${t}/props`)});case"node.update":return Object.freeze({op:"node.update",node:Aa(e.node,`${t}/node`),class:Sa(e.class,`${t}/class`),props:Ew(e.props,`${t}/props`)});case"node.delete":return Object.freeze({op:"node.delete",node:Aa(e.node,`${t}/node`),class:Sa(e.class,`${t}/class`)});case"edge.create":return Object.freeze({op:"edge.create",class:Sa(e.class,`${t}/class`),source:aR(e.source,`${t}/source`),target:aR(e.target,`${t}/target`),...Object.hasOwn(e,"slug")?{slug:vw(e.slug,`${t}/slug`)}:{},props:fm(e.props,`${t}/props`)});case"edge.update":if("slug"in e)return Object.freeze({op:"edge.update",edge:dm(e.edge,`${t}/edge`),slug:e.slug===null?null:vw(e.slug,`${t}/slug`),...e.props===void 0?{}:{props:Ew(e.props,`${t}/props`)}});return Object.freeze({op:"edge.update",edge:dm(e.edge,`${t}/edge`),props:Ew(e.props,`${t}/props`)});case"edge.delete":return Object.freeze({op:"edge.delete",edge:dm(e.edge,`${t}/edge`)})}}function aR(e,t){if(typeof e==="string")return Aa(e,t);return Object.freeze({created:dR(e.created,`${t}/created`)})}function dm(e,t){return Object.freeze({source:Aa(e.source,`${t}/source`),target:Aa(e.target,`${t}/target`),class:Sa(e.class,`${t}/class`)})}function Ew(e,t){let r=fm(e.set,`${t}/set`),i=e.unset.map((n,o)=>Iw(n,`${t}/unset/${o}`));if(Ow(i,`${t}/unset`,"PropertyKey"),Object.keys(r).length+i.length===0)gt(t,"Expected a non-empty patch");for(let n of i)if(Object.hasOwn(r,n))gt(t,`Property ${JSON.stringify(n)} is set and unset`);return Kx({set:r,unset:i},t)}function fm(e,t){let r={};for(let i of Object.keys(e).sort()){let n=Iw(i,`${t}/${vq(i)}`);Object.defineProperty(r,n,{enumerable:!0,value:e[i]})}return ar(r,t)}function hq(e){let t=new Map;for(let r=0;r<e.length;r++){let i=e[r];if(i.op!=="node.create")continue;let n=t.get(i.as);if(n!==void 0)gt(`/operations/${r}/as`,`Duplicate create binding declared at operation ${n}`);t.set(i.as,r)}for(let r=0;r<e.length;r++){let i=e[r];if(i.op!=="edge.create")continue;for(let[n,o]of[["source",i.source],["target",i.target]])if(typeof o!=="string"&&!t.has(o.created))gt(`/operations/${r}/${n}/created`,`Unresolved create binding ${o.created}`)}}function gq(e){if(e.length<2)return Object.freeze([...e]);let t=new Map,r=[];for(let i=0;i<e.length;i++){let n=e[i],o=lR(n),s=t.get(o);if(s!==void 0)gt(`/operations/${i}`,`Duplicate mutation operation declared at operation ${s}`);t.set(o,i),r.push({key:o,value:n})}return r.sort((i,n)=>ww(i.key,n.key)),Object.freeze(r.map(({value:i})=>i))}function yq(e){if(e.length>Gr.preconditions)gt("/preconditions",`Mutation declares more than ${Gr.preconditions} preconditions`);let t=new Map,r=new Map,i=0,n=0;for(let o=0;o<e.length;o++){let s=e[o];if(s.kind==="query")i++,n+=s.equals.kind==="node"?s.equals.ids.length:s.equals.keys.length;let a=Cq(s),c=t.get(a);if(c!==void 0)gt(`/preconditions/${o}`,`Duplicate precondition selector declared at precondition ${c}`);if(t.set(a,o),s.kind!=="node")continue;let u=r.get(s.node);if(u!==void 0&&u.class!==s.class)gt(`/preconditions/${o}/class`,`Contradictory Node Class assertion declared at precondition ${u.index}`);r.set(s.node,{class:s.class,index:o})}if(i>Gr.queryPreconditions)gt("/preconditions",`Mutation declares more than ${Gr.queryPreconditions} query preconditions`);if(n>Gr.queryExpectedIdentities)gt("/preconditions",`Mutation declares more than ${Gr.queryExpectedIdentities} expected query identities`)}function Cq(e){if(e.kind==="node")return te.serialize({kind:"node",node:e.node,class:e.class});if(e.kind==="edge")return te.serialize({kind:"edge",edge:e.edge});return`query:${Ot.fingerprint(e.query)}`}function bq(e){if(e.length<2)return Object.freeze([...e]);return Object.freeze(e.map((t)=>({key:lR(t),value:t})).sort((t,r)=>ww(t.key,r.key)).map(({value:t})=>t))}function lR(e){return te.serialize(e)}function ww(e,t){return e<t?-1:e>t?1:0}function dR(e,t){if(!Mn(e))gt(t,"Expected a local binding name of at most 64 characters");return Ur(e)}function Iw(e,t){if(typeof e!=="string"||!Pe.is(e))gt(t,"Expected a canonical PropertyKey");return Pe(e)}function Aa(e,t){if(typeof e!=="string")gt(t,"Expected a NodePath string");try{return yn(e)}catch(r){throw new Fr(t,"Invalid NodePath",{cause:r})}}function Sa(e,t){if(typeof e!=="string")gt(t,"Expected a ClassPath string");try{return Ze.parse(e)}catch(r){throw new Fr(t,"Invalid ClassPath",{cause:r})}}function vw(e,t){if(typeof e!=="string")gt(t,"Expected an EdgeSlug string");try{return Pn(e)}catch(r){throw new Fr(t,"Invalid EdgeSlug",{cause:r})}}function Ow(e,t,r){let i=new Set;for(let n=0;n<e.length;n++){let o=e[n];if(i.has(o))gt(`${t}/${n}`,`Duplicate ${r} ${JSON.stringify(o)}`);i.add(o)}}function Eq(e,t,r,i){let n=new Set;for(let o=0;o<e.length;o++){let s=t(e[o]);if(n.has(s))gt(`${r}/${o}`,`Duplicate ${i}`);n.add(s)}}function cR(e,t,r,i){for(let n=1;n<e.length;n++)if(t(e[n-1],e[n])>=0)gt(`${r}/${n}`,`${i} sequence is not in canonical identity order`)}function vq(e){return e.replaceAll("~","~0").replaceAll("/","~1")}function gt(e,t){throw new Fr(e,t)}function xq(e){return e instanceof he?e.pointer:""}var Un=Object.freeze({format:_a,version:ka,limits:Gr,decode:xw,encode:uR});function $a(e){let t=e.preconditions===void 0?[]:e.preconditions;return Un.decode({format:Un.format,version:Un.version,preconditions:t.map(wq),operations:e.operations.map(Iq)})}function _w(e){let t=[];for(let r of e.nodes){if("id"in r)throw TypeError(`Cannot create identified GraphSpec Node ${JSON.stringify(r.id)}.`);t.push({op:"node.create",as:r.as,class:r.class,props:pR(r.props)})}for(let r of e.edges){let i=pR(r.props);t.push({op:"edge.create",source:mR(r.source),target:mR(r.target),class:r.class,...r.slug===void 0?{}:{slug:r.slug},props:i})}if(t.length===0)throw TypeError("Cannot create an empty GraphSpec mutation.");return $a({operations:t})}function wq(e){if(e.kind==="node")return{...e,node:qu(e.node)};if(e.kind==="query")return e;return{...e,edge:Dw(e.edge)}}function Iq(e){switch(e.op){case"node.create":return e;case"node.update":return{...e,node:qu(e.node)};case"node.delete":return{...e,node:qu(e.node)};case"edge.create":return{...e,source:fR(e.source),target:fR(e.target)};case"edge.update":return{...e,edge:Dw(e.edge)};case"edge.delete":return{...e,edge:Dw(e.edge)}}}function fR(e){return e instanceof q?e.raw:e}function Dw(e){return{source:qu(e.source),target:qu(e.target),class:e.class}}function qu(e){return e instanceof q?e.raw:e}function pR(e){return e}function mR(e){if(typeof e==="string")return q.id(e);return"created"in e?Object.freeze({created:e.created}):e.path}function kw(e){if(typeof e!=="function")throw TypeError("Mutation author must be a function.");let t=[],r=[],i=!0,n=()=>{if(!i)throw TypeError("MutationBuilder is no longer active.")},s={expect:Object.freeze({node(c){return n(),r.push({kind:"node",...c}),a},edge(c){n();let u={source:c.source,target:c.target,class:c.class};return r.push({kind:"edge",edge:u,...Object.hasOwn(c,"slug")?{slug:c.slug??null}:{},...c.props===void 0?{}:{props:c.props}}),a},query(c){return n(),r.push({kind:"query",...c}),a}}),createNode(c){return n(),t.push({op:"node.create",as:c.as,class:c.class,props:c.props??{}}),Object.freeze({created:c.as})},updateNode(c){return n(),t.push({op:"node.update",...c}),a},deleteNode(c){return n(),t.push({op:"node.delete",...c}),a},createEdge(c){return n(),t.push({op:"edge.create",class:c.class,source:c.source,target:c.target,...c.slug===void 0?{}:{slug:c.slug},props:c.props??{}}),a},updateEdge(c){n();let u={source:c.source,target:c.target,class:c.class};if(Object.hasOwn(c,"slug"))return t.push({op:"edge.update",edge:u,slug:c.slug??null,...c.props===void 0?{}:{props:c.props}}),a;if(c.props===void 0)throw TypeError("Edge update must change slug or properties.");return t.push({op:"edge.update",edge:u,props:c.props}),a},deleteEdge(c){return n(),t.push({op:"edge.delete",edge:c}),a}},a=Object.freeze(s);try{let c=e(a);if(Oq(c))throw TypeError("Mutation author must be synchronous.");if(c!==void 0)throw TypeError("Mutation author must not return a value.");return $a({preconditions:r,operations:t})}finally{i=!1}}function Oq(e){return(typeof e==="object"||typeof e==="function")&&e!==null&&typeof e.then==="function"}class Qo extends TypeError{path;code="MUTATION_RESULT_INVALID";constructor(e,t,r){super(`${t} at ${e||"/"}.`,r);this.path=e,this.name="MutationResultDecodeError"}}var Dq=p.string().min(1),_q=p.string().min(1).max(64),Ta=p.strictObject({createdNodes:p.record(_q,Dq)});var pm=Object.freeze({decode:BR,encode:kq});function kq(e){return BR(e)}function BR(e){try{let t=zn(Ta,se(e),Sw).createdNodes,r={};for(let i of Object.keys(t).sort()){let n=`/createdNodes/${Aq(i)}`;Sq(i,n);let o=t[i];try{r[i]=Fe(o)}catch(s){Sw(n,"Invalid NodeId",s)}}return Object.freeze({createdNodes:Object.freeze(r)})}catch(t){if(t instanceof Qo)throw t;throw new Qo($q(t),"Invalid MutationResult",{cause:t})}}function Sq(e,t){if(!Mn(e))Sw(t,"Invalid LocalBinding")}function Aq(e){return e.replaceAll("~","~0").replaceAll("/","~1")}function Sw(e,t,r){throw new Qo(e,t,r===void 0?void 0:{cause:r})}function $q(e){return e instanceof he?e.pointer:""}var eo=Object.freeze({format:Un.format,version:Un.version,limits:Un.limits,build:kw,create:$a,fromGraph:_w,decode:Un.decode,encode:Un.encode});var Ra={};ze(Ra,{CODES:()=>Ae,ProtocolError:()=>Fn,acceptPayload:()=>Xo,acceptReason:()=>Aw,httpStatusOf:()=>hR,reasonOf:()=>mm});var Ae=Object.freeze({PARSE_ERROR:1001,INVALID_REQUEST:1002,VALIDATION_ERROR:1003,INVARIANT_VIOLATION:1004,AUTH_MISSING:2001,AUTH_INVALID:2002,AUTH_EXPIRED:2003,ACCESS_DENIED:2004,METHOD_NOT_FOUND:3001,NOT_FOUND:3002,METHOD_NOT_ALLOWED:3003,CONFLICT:4001,UNSUPPORTED:4002,LIMIT_EXCEEDED:4003,CANCELLED:4004,DEADLINE_EXCEEDED:4005,INTERNAL_ERROR:5000,BACKEND_UNAVAILABLE:5001,OUTCOME_UNKNOWN:5002});var Uq={[Ae.PARSE_ERROR]:400,[Ae.INVALID_REQUEST]:400,[Ae.VALIDATION_ERROR]:422,[Ae.INVARIANT_VIOLATION]:422,[Ae.AUTH_MISSING]:401,[Ae.AUTH_INVALID]:401,[Ae.AUTH_EXPIRED]:401,[Ae.ACCESS_DENIED]:403,[Ae.METHOD_NOT_FOUND]:404,[Ae.NOT_FOUND]:404,[Ae.METHOD_NOT_ALLOWED]:405,[Ae.CONFLICT]:409,[Ae.UNSUPPORTED]:422,[Ae.LIMIT_EXCEEDED]:429,[Ae.CANCELLED]:408,[Ae.DEADLINE_EXCEEDED]:504,[Ae.INTERNAL_ERROR]:500,[Ae.BACKEND_UNAVAILABLE]:503,[Ae.OUTCOME_UNKNOWN]:500};function hR(e){return Uq[e.code]??500}var Fq=new Set(Object.values(Ae)),Gq=new Set(["code","message","data"]);function Xo(e,t="error"){let r;try{r=se(e)}catch(i){if(i instanceof he)throw TypeError(`${t} must be a portable value object`,{cause:i});throw i}if(!Hq(r))throw TypeError(`${t} must be an object`);for(let i of Object.keys(r))if(!Gq.has(i))throw TypeError(`${t} contains unexpected field ${JSON.stringify(i)}`);if(!Object.hasOwn(r,"code")||!Fq.has(r.code))throw TypeError(`${t}.code is not a public error code`);if(typeof r.message!=="string")throw TypeError(`${t}.message must be a string`);return Object.freeze({code:r.code,message:r.message,...r.data===void 0?{}:{data:r.data}})}function Hq(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}class Fn extends Error{payload;constructor(e){super(e.message);this.name="ProtocolError",this.payload=e}}var gR=new Set(["code","details"]);function Aw(e,t="error reason"){let r;try{r=se(e)}catch(i){if(i instanceof he)throw TypeError(`${t} must be a portable value object`,{cause:i});throw i}if(!yR(r))throw TypeError(`${t} must be an object`);if(Object.keys(r).length!==gR.size||Object.keys(r).some((i)=>!gR.has(i)))throw TypeError(`${t} must contain exactly code and details`);if(typeof r.code!=="string"||r.code.normalize("NFC")!==r.code||!/^[A-Z][A-Z0-9_]{0,127}$/u.test(r.code))throw TypeError(`${t}.code is invalid`);if(!yR(r.details))throw TypeError(`${t}.details must be an object`);return Object.freeze({code:r.code,details:Object.freeze(r.details)})}function mm(e){if(e===void 0)return;try{return Aw(e)}catch(t){if(t instanceof TypeError)return;throw t}}function yR(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}function CR(e,t){if(e===null||typeof e==="string")return e;if(typeof e==="number"&&Number.isFinite(e)&&!Object.is(e,-0))return e;throw TypeError(`${t} must be a string, finite number, or null`)}var $w=255,Vq=/[^A-Za-z0-9._-]/u,qq="InvocationId must contain 1-255 ASCII characters drawn from [A-Za-z0-9._-].";class to extends TypeError{input;code="INVOCATION_INVALID";constructor(e,t="Invocation is invalid.",r){super(t,r);this.input=e,this.name="InvocationError"}}function ja(e){if(e===null||typeof e!=="object"||Array.isArray(e))bR(e);let t=e,r=Object.getOwnPropertyDescriptor(t,"source"),i=Object.getOwnPropertyDescriptor(t,"id");if(Reflect.ownKeys(t).some((o)=>o!=="source"&&o!=="id")||r===void 0||i===void 0||!r.enumerable||!i.enumerable||!("value"in r)||!("value"in i)||typeof r.value!=="string"||typeof i.value!=="string")bR(e);let n;try{n=ht.accept(r.value)}catch(o){throw new to(e,"Invocation source is invalid.",{cause:o})}if(!Jq(i.value))throw new to(e,qq);return Object.freeze({source:n,id:i.value})}function ER(e,t){return e.source===t.source&&e.id===t.id}function Jq(e){return typeof e==="string"&&e.length>0&&e.length<=$w&&!Vq.test(e)}function bR(e){throw new to(e)}function yt(e,t){let r;try{r=se(e)}catch(i){if(i instanceof he)return ue(`${t} must be a portable value object`);throw i}if(!Kq(r))ue(`${t} must be an object`);return r}function Ju(e,t){if(e===null||typeof e!=="object"||Array.isArray(e))ue(`${t} must be an object`);let r=Object.getPrototypeOf(e);if(r!==Object.prototype&&r!==null)ue(`${t} must be a plain object`);let i={};for(let n of Reflect.ownKeys(e)){if(typeof n!=="string")ue(`${t} cannot contain symbol fields`);let o=Object.getOwnPropertyDescriptor(e,n);if(o===void 0||!o.enumerable||!("value"in o))ue(`${t}.${n} must be an enumerable data field`);i[n]=o.value}return i}function He(e,t,r){for(let i of Object.keys(e))if(!t.has(i))ue(`${r} contains unexpected field ${JSON.stringify(i)}`)}function We(e,t,r){for(let i of t)if(!Object.hasOwn(e,i))ue(`${r}.${i} is required`)}function Tt(e,t){try{return CR(e,t)}catch(r){if(r instanceof TypeError)return ue(r.message);throw r}}function Hr(e,t){try{return ja(e)}catch(r){if(r instanceof to)return ue(`${t} must be a valid Invocation`);throw r}}function vR(e,t){if(typeof e!=="string")ue(`${t} must be a NodePath string`);try{return yn(e)}catch(r){if(r instanceof Ko)return ue(`${t} must be a valid NodePath`);throw r}}function Bm(e,t){if(typeof e!=="string")ue(`${t} must be an issuer identifier`);try{return ht.accept(e)}catch(r){if(r instanceof be)return ue(`${t} must be a valid issuer identifier`);throw r}}function ro(e,t){if(typeof e!=="string")ue(`${t} must be a string`);return e}function Tw(e,t){if(!Number.isSafeInteger(e)||e<0)ue(`${t} must be a non-negative safe integer`);return e}function Pa(e,t){let r=ro(e,t);if(!/^sha256:[0-9a-f]{64}$/u.test(r))ue(`${t} must be a SHA-256 digest`);return r}function hm(e,t){try{return Xo(e,t)}catch(r){if(r instanceof TypeError)return ue(r.message);throw r}}function xR(e){let t=Ju(e,"binary response.headers"),r={};for(let[i,n]of Object.entries(t)){if(!Zq.test(i))ue(`binary response header name ${JSON.stringify(i)} is invalid`);let o=ro(n,`binary response.headers.${i}`);if(Wq(o))ue(`binary response header ${JSON.stringify(i)} contains a control character`);let s=i.toLowerCase();if(Object.hasOwn(r,s))ue(`binary response header ${JSON.stringify(i)} occurs more than once`);if(s==="content-length"||s==="transfer-encoding"||s==="connection")ue(`binary response header ${JSON.stringify(i)} is transport-reserved`);r[s]=o}return Object.freeze(r)}function ue(e){throw new Fn({code:Ae.INVALID_REQUEST,message:e})}function Kq(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}var Zq=/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/u;function Wq(e){for(let t=0;t<e.length;t+=1){let r=e.charCodeAt(t);if(r<=31||r===127)return!0}return!1}var Yq=new Set(["kind","requestId","invocation","body","mediaType","headers"]),Qq=/^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/u;function gm(e){let t=Ju(e,"binary response");if(He(t,Yq,"binary response"),We(t,["kind","requestId","invocation","body","mediaType"],"binary response"),t.kind!=="binary")ue('binary response.kind must be "binary"');if(!(t.body instanceof Uint8Array))ue("binary response.body must be a Uint8Array");let r=ro(t.mediaType,"binary response.mediaType");if(!Qq.test(r))ue("binary response.mediaType is invalid");let i=t.headers===void 0?void 0:xR(t.headers);return Object.freeze({kind:"binary",requestId:Tt(t.requestId,"binary response.requestId"),invocation:Hr(t.invocation,"binary response.invocation"),body:new Uint8Array(t.body),mediaType:r,...i===void 0?{}:{headers:i}})}var Xq=new Set(["version","kind","requestId"]);function wR(e){let t=yt(e,"cancel request");if(He(t,Xq,"cancel request"),We(t,["version","kind","requestId"],"cancel request"),t.version!==2)ue("cancel request.version must be 2");if(t.kind!=="cancel")ue('cancel request.kind must be "cancel"');return Object.freeze({version:2,kind:"cancel",requestId:Tt(t.requestId,"cancel request.requestId")})}var Nw="x-astrale-idempotency-key",Rw=128;function ym(e,t="idempotency key"){if(typeof e!=="string"||e.length<1||e.length>Rw||!/^[A-Za-z0-9._~-]+$/u.test(e))ue(`${t} must contain 1-128 URL-safe ASCII characters`);return e}var oI={};ze(oI,{BAGGAGE_FIELD:()=>vj,BINARY_HEADERS_FIELD:()=>jw,INVOCATION_FIELD:()=>Lw,LENGTH_PREFIX_V1:()=>hj,MAXIMUM_INVOCATION_FIELD_BYTES:()=>Cm,REQUEST_ID_FIELD:()=>Pw,STREAM_FRAMING_FIELD:()=>Bj,TRACEPARENT_FIELD:()=>nI,TRACESTATE_FIELD:()=>iI,codecForContentType:()=>dj,decodeBinaryHeaderNames:()=>AR,decodeInvocationId:()=>kR,decodeTraceHeaders:()=>xj,encodeBinaryHeaderNames:()=>SR,encodeInvocationId:()=>_R,encodeStreamFrame:()=>gj,encodeTraceHeaders:()=>wj,isApplicationBinaryHeader:()=>bm,negotiateResponseCodec:()=>fj});var jw="x-astrale-binary-headers",Pw="x-astrale-request-id",Lw="x-astrale-invocation",Cm=8192,IR=/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/u,OR=8192,DR=128,zw="-",eJ=new Set(["authorization","cache-control","connection","content-encoding","content-length","content-type","cookie","date","etag","host","keep-alive","location","proxy-authenticate","proxy-authorization","referrer-policy","server","set-cookie","trailer","transfer-encoding","upgrade","vary","www-authenticate",zw,jw,Lw,Pw,"x-astrale-stream-framing"]);function _R(e){let t;try{t=encodeURIComponent(e.source)}catch{return Vr("HTTP binary InvocationId field is invalid.")}let r=`${t};${e.id}`;if(new TextEncoder().encode(r).byteLength>Cm)Vr("HTTP binary InvocationId field is invalid.");return r}function kR(e){if(e===null||e.length===0||new TextEncoder().encode(e).byteLength>Cm)return Vr("HTTP binary InvocationId field is invalid.");let t=e.indexOf(";");if(t<1||e.indexOf(";",t+1)!==-1)Vr("HTTP binary InvocationId field is invalid.");let r;try{r=decodeURIComponent(e.slice(0,t))}catch{return Vr("HTTP binary InvocationId field is invalid.")}try{return ja({source:r,id:e.slice(t+1)})}catch{return Vr("HTTP binary InvocationId field is invalid.")}}function bm(e){let t=e.toLowerCase();return IR.test(t)&&!t.startsWith("access-control-")&&!t.startsWith("sec-websocket-")&&!eJ.has(t)}function SR(e){let t=[],r=new Set;for(let n of Object.keys(e??{})){let o=n.toLowerCase();if(!IR.test(o)||r.has(o))Vr();if(r.add(o),!bm(o))continue;t.push(o)}if(t.length>DR)Vr();let i=t.length===0?zw:t.sort().join(", ");if(new TextEncoder().encode(i).byteLength>OR)Vr();return i}function AR(e){if(e===zw)return Object.freeze([]);if(e===null||e==="")Vr();if(new TextEncoder().encode(e).byteLength>OR)Vr();let t=e.split(",");if(t.length>DR)Vr();let r=[],i=new Set;for(let n of t){let o=n.trim().toLowerCase();if(!bm(o)||i.has(o))Vr();i.add(o),r.push(o)}return Object.freeze(r)}function Vr(e="HTTP binary application-header manifest is invalid."){throw new Fn({code:Ae.INVALID_REQUEST,message:e})}var Lt={};ze(Lt,{CONTENT_TYPE_JSON:()=>es,CONTENT_TYPE_MSGPACK:()=>ts,DecodeError:()=>no,json:()=>La,loadMsgpack:()=>cj});class no extends SyntaxError{name="DecodeError";constructor(e,t){super(e,t)}}var es="application/vnd.astrale+json",ts="application/vnd.astrale.msgpack";var La=Object.freeze({name:"json",contentType:es,binary:!1,encode:te.serialize,decode(e){try{return te.decode(e)}catch(t){if(t instanceof tt)throw new no("JSON envelope is malformed.",{cause:t});throw t}}});var Fa=null;async function cj(){if(Fa===null){let[e,t]=await Promise.all([Promise.resolve().then(() => (tI(),eI)),Promise.resolve().then(() => (Ma(),Yw))]);Fa=Object.freeze({pack:e.pack,unpack:t.unpack})}return uj}var uj=Object.freeze({name:"msgpack",contentType:ts,binary:!0,encode(e){if(Fa===null)throw Error("MsgPack codec is not loaded");return new Uint8Array(Fa.pack(se(e)))},decode(e){if(Fa===null)throw Error("MsgPack codec is not loaded");if(typeof e==="string")throw TypeError("MsgPack requires a binary envelope");let t;try{t=Fa.unpack(e)}catch(r){throw new no("MsgPack envelope is malformed.",{cause:r})}try{return se(t)}catch(r){if(r instanceof he)throw new no("MsgPack envelope is not a portable value.",{cause:r});throw r}}});function lj(e){return e===uj}function rI(e){if(e===La)return"json";if(lj(e))return"msgpack";return}function Xu(e){if(!Array.isArray(e))throw TypeError("supported codecs must be an array.");let t=[],r=new Set;for(let i of e){let n=rI(i);if(n===void 0)throw TypeError("supported contains a foreign codec.");if(r.has(n))throw TypeError(`supported contains duplicate ${n}.`);r.add(n),t.push(Object.freeze({codec:i,profile:n}))}if(!r.has("json"))throw TypeError("supported must contain the canonical JSON codec.");return Object.freeze(t)}var Sm=/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/u,IJ=/^(?:0(?:\.\d{0,3})?|1(?:\.0{0,3})?)$/u;function dj(e,t){let r=Xu(t);if(e===null||e.trim()==="")return;let i=DJ(e);if(i===void 0)return;let n=i===es?"json":i===ts?"msgpack":void 0;return r.find((o)=>o.profile===n)?.codec}function fj(e,t,r){let i=Xu(r),n=i.find((a)=>a.codec===t);if(n===void 0)throw TypeError("requestCodec must occur exactly once in supported.");if(e===null||e.trim()==="")return n.codec;let o=_J(e);if(o.length===0)return;let s=i.flatMap((a)=>{let[c,u]=OJ(a.profile).split("/"),l=o.filter((d)=>d.mediaParameters===0&&(d.type==="*"||d.type===c)&&(d.subtype==="*"||d.subtype===u)).sort((d,f)=>f.specificity-d.specificity||d.index-f.index)[0];return l===void 0||l.quality===0?[]:[{...a,governing:l}]});if(s.length===0)return;return s.sort((a,c)=>{let u=c.governing.quality-a.governing.quality;if(u!==0)return u;if(a.codec===n.codec)return-1;if(c.codec===n.codec)return 1;let l=a.governing.index-c.governing.index;if(l!==0)return l;if(a.profile==="json")return-1;if(c.profile==="json")return 1;return 0}),s[0]?.codec}function OJ(e){return e==="json"?es:ts}function DJ(e){if(Am(e,",")?.length!==1)return;let t=Am(e,";");if(t===void 0)return;let r=t.shift()?.trim().toLowerCase();if(r===void 0||pj(r,!1)===void 0)return;let i=new Set;for(let n of t){let o=mj(n);if(o===void 0||i.has(o.name))return;i.add(o.name)}return r}function _J(e){let t=Am(e,",");if(t===void 0)return[];let r=[];for(let[i,n]of t.entries()){let o=Am(n,";");if(o===void 0)continue;let s=pj(o.shift()?.trim().toLowerCase()??"",!0);if(s===void 0)continue;let a=1,c=!1,u=0,l=!1,d=new Set;for(let f of o){let m=mj(f);if(m===void 0||d.has(m.name)){l=!0;break}if(d.add(m.name),m.name==="q"){if(c||!IJ.test(m.value)){l=!0;break}c=!0,a=Number(m.value)}else if(!c)u+=1}if(l)continue;r.push({...s,quality:a,specificity:s.type==="*"?0:s.subtype==="*"?1:2,index:i,mediaParameters:u})}return r}function pj(e,t){let r=e.indexOf("/");if(r<=0||r!==e.lastIndexOf("/"))return;let i=e.slice(0,r),n=e.slice(r+1);if(n==="")return;let o=Sm.test(i)||t&&i==="*",s=Sm.test(n)||t&&n==="*";if(!o||!s||i==="*"&&n!=="*")return;return{type:i,subtype:n}}function mj(e){let t=e.indexOf("=");if(t<=0)return;let r=e.slice(0,t).trim().toLowerCase(),i=e.slice(t+1).trim();if(!Sm.test(r)||!Sm.test(i)&&!kJ(i))return;return{name:r,value:SJ(i)}}function kJ(e){if(e.length<2||e[0]!=='"'||e.at(-1)!=='"')return!1;for(let t=1;t<e.length-1;t+=1){let r=e.charCodeAt(t);if(e[t]==="\\"){if(t+=1,t>=e.length-1)return!1;continue}if(e[t]==='"'||r===127||r<32&&r!==9)return!1}return!0}function SJ(e){if(e[0]!=='"')return e;let t="";for(let r=1;r<e.length-1;r+=1){if(e[r]==="\\")r+=1;t+=e[r]}return t}function Am(e,t){let r=[],i=!1,n=!1,o=0;for(let s=0;s<e.length;s+=1){let a=e[s];if(n){n=!1;continue}if(i&&a==="\\"){n=!0;continue}if(a==='"'){i=!i;continue}if(!i&&a===t)r.push(e.slice(o,s)),o=s+1}if(i||n)return;return r.push(e.slice(o)),r}var Bj="x-astrale-stream-framing",hj="length-prefix-v1",AJ=new TextEncoder;function gj(e,t){let r=e.encode(t),i=typeof r==="string"?AJ.encode(r):r;if(i.byteLength>4294967295)throw RangeError("stream frame exceeds the uint32 length-prefix-v1 payload bound.");let n=new Uint8Array(4+i.byteLength);return new DataView(n.buffer).setUint32(0,i.byteLength),n.set(i,4),n}var yj=512,Cj=512,bj=32,$J=/^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})/u,TJ=/^-[\x21-\x7e]+$/u,NJ=/^[a-z][a-z0-9_*/-]{0,255}$/u,RJ=/^[a-z0-9][a-z0-9_*/-]{0,240}$/u,jJ=/^[a-z][a-z0-9_*/-]{0,13}$/u,PJ=/^[\x20-\x2b\x2d-\x3c\x3e-\x7e]{0,255}[\x21-\x2b\x2d-\x3c\x3e-\x7e]$/u;function Ci(e){if(e===null||typeof e!=="object"||Array.isArray(e))return;let t=Reflect.ownKeys(e);if(!t.includes("traceparent")||t.some((o)=>o!=="traceparent"&&o!=="tracestate"))return;let r,i;try{let o=e;r=o.traceparent,i=o.tracestate}catch{return}if(typeof r!=="string"||!LJ(r))return;let n=typeof i==="string"&&zJ(i)?i:void 0;return Object.freeze({traceparent:r,...n===void 0||n.trim()===""?{}:{tracestate:n}})}function LJ(e){if(e.length<55||e.length>512)return!1;let t=$J.exec(e);if(t===null||t.index!==0)return!1;let[,r,i,n,o]=t;if(r===void 0||i===void 0||n===void 0||o===void 0||r==="ff"||/^0+$/u.test(i)||/^0+$/u.test(n))return!1;if(r==="00")return e.length===55&&(o==="00"||o==="01");return e.length===55||TJ.test(e.slice(55))}function zJ(e){if(e.length>512)return!1;let t=e.split(",");if(t.length>32)return!1;let r=new Set;for(let i of t){let n=i.replace(/^[ \t]+|[ \t]+$/gu,"");if(n==="")continue;let o=n.indexOf("=");if(o<1||o!==n.lastIndexOf("="))return!1;let s=n.slice(0,o),a=n.slice(o+1);if(!MJ(s)||!PJ.test(a)||r.has(s))return!1;r.add(s)}return!0}function MJ(e){let t=e.indexOf("@");if(t===-1)return NJ.test(e);if(t!==e.lastIndexOf("@"))return!1;return RJ.test(e.slice(0,t))&&jJ.test(e.slice(t+1))}var nI="traceparent",iI="tracestate",vj="baggage",Ej=Object.freeze({});function xj(e,t){if(e===null)return;return Ci({traceparent:e,...t===null?{}:{tracestate:t}})}function wj(e){if(e===void 0)return Ej;let t=Ci(e);if(t===void 0)return Ej;return Object.freeze({[nI]:t.traceparent,...t.tracestate===void 0?{}:{[iI]:t.tracestate}})}var UJ=new Set(["ttlSeconds","attenuation"]);function Tm(e){let t=Ju(e,"delegate");if(He(t,UJ,"delegate"),We(t,["ttlSeconds"],"delegate"),!Number.isSafeInteger(t.ttlSeconds)||t.ttlSeconds<1)ue("delegate.ttlSeconds must be a positive safe integer");let r;if(t.attenuation!==void 0){try{r=Vp.acceptUnresolved({v:1,expr:t.attenuation}).expr}catch(i){if(i instanceof be)ue("delegate.attenuation must be a valid expression");throw i}$m(r)}return Object.freeze({ttlSeconds:t.ttlSeconds,...r===void 0?{}:{attenuation:r}})}function $m(e){if(e.kind==="identity"){if("credential"in e&&typeof e.credential!=="string")ue("delegate.attenuation credentials must be non-empty text");return}if(e.kind==="exclude"){$m(e.base);for(let t of e.excluded)$m(t);return}for(let t of e.operands)$m(t)}var FJ=new Set(["kind","requestId","invocation"]);function el(e){let t=yt(e,"miss control");if(He(t,FJ,"miss control"),We(t,["kind","requestId","invocation"],"miss control"),t.kind!=="miss")ue('miss control.kind must be "miss"');return Object.freeze({kind:"miss",requestId:Tt(t.requestId,"miss control.requestId"),invocation:Hr(t.invocation,"miss control.invocation")})}function Ij(e,t){return el({kind:"miss",requestId:e,invocation:t})}var er={};ze(er,{BUNDLE_MEDIA_TYPE:()=>Kr,ClassOperationOrder:()=>tB,MEDIA_TYPE:()=>TP,PATH:()=>oB,PublicationError:()=>so,accept:()=>hs,acceptBundle:()=>fl,acceptInvocationEndpoints:()=>ss,acceptReference:()=>Za,admitRequirements:()=>po,compareReference:()=>VO,compareReferences:()=>HO,decodeBundle:()=>sB,delivery:()=>GO,describeBundle:()=>Dj,encode:()=>dl,matchesReference:()=>qP,reference:()=>uB,seal:()=>RP,url:()=>NP,validateRequirements:()=>iB});class so extends Error{code;name="PublicationError";constructor(e,t,r){super(t,r);this.code=e}}function W(e,t,r){throw new so(e,t,r===void 0?void 0:{cause:r})}function Le(e,t,r){if(e===null||typeof e!=="object"||Array.isArray(e))W(t,r);return e}function Je(e,t,r){let i=new Set(t);if(Object.keys(e).some((n)=>!i.has(n)))W(r,"Object contains unknown fields.")}function Ga(e,t){if(!Array.isArray(e))W(t,"Expected an array.");return e}function bi(e,t,r){if(new Set(e).size!==e.length)W(t,`Duplicate ${r}.`)}function Gn(e){if(e===null||typeof e!=="object"||Object.isFrozen(e))return e;for(let t of Object.values(e))Gn(t);return Object.freeze(e)}function xn(e,t,r,i=!1){return sI(e,["http:","https:"],t,r,i)}function sI(e,t,r,i,n=!1){if(typeof e!=="string")return W(i,"Expected an absolute URL.");if(!n&&(e.includes("{")||e.includes("}")))return W(i,"Only native route URLs may contain placeholders.");let o;try{o=new URL(n?e.replaceAll(/\{[A-Za-z][A-Za-z0-9_]*\+?\}/gu,"placeholder"):e)}catch(s){if(s instanceof TypeError)return W(i,"Expected an absolute URL.",s);throw s}if(!t.includes(o.protocol)||o.username!==""||o.password!==""||o.hash!==""||!r&&o.search!=="")W(i,"URL has a forbidden protocol, credentials, query, or fragment.");return e}function ss(e){let t=Le(e,"PUBLICATION_BINDING_INVALID","Invocation endpoints are invalid.");Je(t,["http","websocket"],"PUBLICATION_BINDING_INVALID");let r=xn(t.http,!0,"PUBLICATION_BINDING_INVALID"),i=t.websocket===void 0?void 0:sI(t.websocket,["ws:","wss:"],!0,"PUBLICATION_BINDING_INVALID");return Object.freeze({http:r,...i===void 0?{}:{websocket:i}})}function aI(e,t){let r=Le(e,"PUBLICATION_BINDING_INVALID","Callable binding is invalid.");return Je(r,["callable","endpoint"],"PUBLICATION_BINDING_INVALID"),Object.freeze({callable:Nm(r.callable,t),endpoint:ss(r.endpoint)})}function Nm(e,t){let r;try{r=Z(String(e))}catch(n){if(n instanceof TypeError)return W("PUBLICATION_BINDING_INVALID","Callable key is invalid.",n);throw n}let i=Z.ref(r);if(Z.origin(r)!==t||!ne.isDefinition(i)&&!ne.isMethod(i)||!i.startsWith("function.")&&!ne.isMethod(i))W("PUBLICATION_BINDING_INVALID","Binding must name one callable owned by the root Domain.");return r}function cI(e,t){let r=Le(e,"PUBLICATION_VIEW_INVALID","Published View binding is invalid.");Je(r,["view","href","handshake"],"PUBLICATION_VIEW_INVALID");let i;try{i=Z(String(r.view))}catch(n){if(n instanceof TypeError)return W("PUBLICATION_VIEW_INVALID","View key is invalid.",n);throw n}if(Z.origin(i)!==t||!Z.ref(i).startsWith("view."))W("PUBLICATION_VIEW_INVALID","View binding must name a root View.");if(r.handshake!=="shell"&&r.handshake!=="none")W("PUBLICATION_VIEW_INVALID","View handshake is invalid.");return Object.freeze({view:i,href:xn(r.href,!0,"PUBLICATION_VIEW_INVALID"),handshake:r.handshake})}var GJ=/^sha256:[0-9a-f]{64}$/u;function Rm(e){if(typeof e!=="string"||!GJ.test(e))W("PUBLICATION_INVALID","Digest is invalid.");return e}function uI(e){let t=te.encode(e);return`sha256:${lI(t)}`}function lI(e){let t=e.length*8,r=Math.ceil((e.length+9)/64)*64,i=new Uint8Array(r);i.set(e),i[e.length]=128;let n=new DataView(i.buffer);n.setUint32(r-8,Math.floor(t/4294967296),!1),n.setUint32(r-4,t>>>0,!1);let o=new Uint32Array(HJ),s=new Uint32Array(64);for(let a=0;a<r;a+=64){for(let g=0;g<16;g+=1)s[g]=n.getUint32(a+g*4,!1);for(let g=16;g<64;g+=1){let w=s[g-15],b=s[g-2],O=Hn(w,7)^Hn(w,18)^w>>>3,k=Hn(b,17)^Hn(b,19)^b>>>10;s[g]=s[g-16]+O+s[g-7]+k>>>0}let[c,u,l,d,f,m,B,h]=o;for(let g=0;g<64;g+=1){let w=Hn(f,6)^Hn(f,11)^Hn(f,25),b=f&m^~f&B,O=h+w+b+VJ[g]+s[g]>>>0,k=Hn(c,2)^Hn(c,13)^Hn(c,22),G=c&u^c&l^u&l,oe=k+G>>>0;h=B,B=m,m=f,f=d+O>>>0,d=l,l=u,u=c,c=O+oe>>>0}o[0]=o[0]+c>>>0,o[1]=o[1]+u>>>0,o[2]=o[2]+l>>>0,o[3]=o[3]+d>>>0,o[4]=o[4]+f>>>0,o[5]=o[5]+m>>>0,o[6]=o[6]+B>>>0,o[7]=o[7]+h>>>0}return[...o].map((a)=>a.toString(16).padStart(8,"0")).join("")}function Hn(e,t){return e>>>t|e<<32-t}var HJ=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),VJ=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);var Kr="application/vnd.astrale.domain-bundle+json;v=1";function Oj(e){let t=Le(e,"PUBLICATION_INVALID","Bundle descriptor is invalid.");Je(t,["href","ref"],"PUBLICATION_INVALID");let r=Os(t.ref);if(r.mediaType!==Kr)W("PUBLICATION_INVALID","Bundle media type is unsupported.");if(r.size<1)W("PUBLICATION_INVALID","Bundle size is invalid.");return Object.freeze({href:xn(t.href,!0,"PUBLICATION_INVALID"),ref:Object.freeze({...r,mediaType:Kr})})}function Dj(e,t){let r=Mr.encode(e);return Object.freeze({href:xn(t,!0,"PUBLICATION_INVALID"),ref:Object.freeze({...Ds(r,Kr),mediaType:Kr})})}function _j(e){try{return Mr.accept(e)}catch(t){if(t instanceof Y.Error)return W("PUBLICATION_INVALID","Publication bundle is invalid.",t);throw t}}function dI(e,t){let r=e.schema.bundle;if(t.byteLength!==r.ref.size||`sha256:${lI(t)}`!==r.ref.digest)W("PUBLICATION_INVALID","Bundle artifact does not match its descriptor.")}function kj(e,t){if(!(t instanceof Uint8Array))W("PUBLICATION_INVALID","Bundle artifact bytes are invalid.");dI(e,t);try{return Mr.decode(t)}catch(r){if(r instanceof Y.Error)return W("PUBLICATION_INVALID","Bundle artifact cannot be decoded.",r);throw r}}function Sj(e,t){if(e===void 0)return;let r=Le(e,"PUBLICATION_INVALID","Delivery endpoint is invalid.");Je(r,["href","method","authentication"],"PUBLICATION_INVALID");let i=xn(r.href,!0,"PUBLICATION_INVALID");if(new URL(i).origin!==new URL(t).origin||r.method!=="POST")W("PUBLICATION_INVALID","Delivery endpoint must be same-origin POST.");let n=Le(r.authentication,"PUBLICATION_INVALID","Delivery authentication is invalid.");if(Je(n,["kind"],"PUBLICATION_INVALID"),n.kind!=="public"&&n.kind!=="bearer")W("PUBLICATION_INVALID","Delivery authentication kind is invalid.");return Object.freeze({href:i,method:"POST",authentication:Object.freeze({kind:n.kind})})}function Aj(e){if(e===void 0)return;let t=Le(e,"PUBLICATION_INVALID","Manifest is invalid.");if(Je(t,["logo","entrypoint"],"PUBLICATION_INVALID"),t.logo!==void 0&&typeof t.logo!=="string")W("PUBLICATION_INVALID","Manifest logo must be a string.");let r;if(t.entrypoint!==void 0){if(typeof t.entrypoint!=="string"||!ne.isDefinition(t.entrypoint)||!t.entrypoint.startsWith("view."))W("PUBLICATION_INVALID","Manifest entrypoint must be a root View reference.");r=t.entrypoint}return Object.freeze({...t.logo===void 0?{}:{logo:t.logo},...r===void 0?{}:{entrypoint:r}})}class jm{origin;name;ref;key;definition;path;constructor(e,t,r){this.origin=e,this.name=t,this.ref=ne.core(t),this.key=Z.of(e,this.ref),this.definition=r,this.path=q.project({origin:e,kind:"core",name:t}),Object.freeze(this)}}function fI(e){let t={};for(let r of Object.keys(e.core.nodes).sort())Object.defineProperty(t,r,{enumerable:!0,value:new jm(e.origin,r,e.core.nodes[r])});return Object.freeze(t)}class Oe extends Error{code;diagnostics;constructor(e,t,r=[],i){super(t,i);this.code=e,this.diagnostics=r,this.name="DomainError"}}class wn{#e;constructor(e){this.#e=new Map(e),Object.freeze(this)}get size(){return this.#e.size}get(e){return this.#e.get(e)}has(e){return this.#e.has(e)}entries(){return this.#e.entries()}keys(){return this.#e.keys()}values(){return this.#e.values()}forEach(e,t){for(let[r,i]of this.#e)e.call(t,i,r,this)}[Symbol.iterator](){return this.entries()}}function Ei(e,t,r){let i=ne.definition(t,r);return Object.freeze({origin:e,kind:t,name:r,ref:i,key:Z.of(e,i)})}function $j(e){let t=e.analysis?.data;return t===void 0?void 0:Object.freeze({owner:Ei(t.owner.origin,t.owner.kind,t.owner.name),definition:t.declaration})}function pI(e,t){let r=[e],i=new Set;while(r.length>0){let n=r.shift();if(n.key===t.key)return!0;if(i.has(n.key))continue;if(i.add(n.key),n.kind==="interface")r.push(...n.extends);if(n.kind==="class")r.push(...n.implements)}return!1}function mI(e){if(e.schemaRef.kind==="interface")return e.declaration.extends;if(e.schemaRef.kind==="class")return e.declaration.implements;return[]}function BI(e,t,r){let i=t.get(e.origin);if(i===void 0)return;if(qJ(e.kind)){let o=e,s=r.$.schema===i?r:Y.resolve(i),a=s.$.refs.definition(o);if(a===void 0)return;return Object.freeze({schemaRef:e,declaration:a.declaration,analysis:s.$.refs.effective(o)})}let n=Tj(i,e.kind,e.name);return n===void 0?void 0:Object.freeze({schemaRef:e,declaration:n})}function hI(e,t){let r=t.indexOf("."),i=t.slice(0,r),n=t.slice(r+1);switch(i){case"class":{let o=e.classes[n];return o===void 0?void 0:{origin:e.origin,kind:Rj(o),name:n}}case"interface":{let o=e.interfaces[n];return o===void 0?void 0:{origin:e.origin,kind:Nj(o),name:n}}case"type":case"function":case"policy":case"view":return Tj(e,i,n)===void 0?void 0:{origin:e.origin,kind:i,name:n};default:return}}function gI(e){return[...Object.entries(e.interfaces).map(([t,r])=>({origin:e.origin,kind:Nj(r),name:t})),...Object.entries(e.classes).map(([t,r])=>({origin:e.origin,kind:Rj(r),name:t})),...Object.keys(e.types).map((t)=>({origin:e.origin,kind:"type",name:t})),...Object.keys(e.functions).map((t)=>({origin:e.origin,kind:"function",name:t})),...Object.keys(e.policies).map((t)=>({origin:e.origin,kind:"policy",name:t})),...Object.keys(e.views).map((t)=>({origin:e.origin,kind:"view",name:t}))]}function yI(){return["type","interface","class","function","policy","view"]}function Tj(e,t,r){switch(t){case"type":return e.types[r];case"function":return e.functions[r];case"policy":return e.policies[r];case"view":return e.views[r];default:return}}function Nj(e){return"interface"}function Rj(e){return"class"}function qJ(e){return e==="class"||e==="interface"}function CI(e,t,r){if(typeof e!=="string")return r.has(e.origin)?e:void 0;let i=t,n;if(Z.is(e)){i=Z.origin(e);let s=Z.ref(e);if(!ne.isDefinition(s))return;n=s}else{if(!ne.isDefinition(e))return;n=e}let o=r.get(i);return o===void 0?void 0:hI(o,n)}function ao(e,t,r,i){let n=t.flatMap((o)=>{let s=e.localByKind.get(o)?.get(r);return s===void 0?[]:[s]});if(n.length===1)return n[0];if(n.length>1)throw new Oe("DOMAIN_DEFINITION_AMBIGUOUS",`${i} ${JSON.stringify(r)} is ambiguous in ${e.schema.origin}.`);throw new Oe("DOMAIN_DEFINITION_NOT_FOUND",`${i} ${JSON.stringify(r)} does not exist in ${e.schema.origin}.`)}var JJ=new Set(["$","origin","kind","name","ref","key","definition","path","properties","data","methods","family","implements","extends"]);function bI(e,t,r){let i=new Set([...t.keys(),...r.keys()]);for(let n of i){if(JJ.has(n))continue;let o=t.get(n)??[],s=r.get(n)??[];if(o.length+s.length!==1)continue;Object.defineProperty(e,n,{enumerable:!0,value:o[0]??s[0]})}}function Pm(e,t,r,i,n){let o=e.get(r);if(o!==void 0)return o;let s=t.get(r)??[];if(s.length===1)return s[0];if(s.length>1)throw new Oe(i==="Property"?"DOMAIN_PROPERTY_AMBIGUOUS":"DOMAIN_METHOD_NOT_FOUND",`${i} ${JSON.stringify(r)} is ambiguous on ${n}; use one of: ${s.map((a)=>a.key).join(", ")}.`);throw new Oe(i==="Property"?"DOMAIN_PROPERTY_NOT_FOUND":"DOMAIN_METHOD_NOT_FOUND",`${i} ${JSON.stringify(r)} does not exist on ${n}.`)}function Lm(e){let t=new Map;for(let r of e){let i=t.get(r.name)??[];i.push(r),t.set(r.name,i)}return t}function EI(e,t){return q.instanceMethod(e,t)}function vI(e,t){return q.staticMethod(q.project(e),t)}function xI(e){let t=[];for(let[r,i]of e.analysis?.methods??[]){let n=Ei(i.owner.origin,i.owner.kind,i.owner.name),o=ne.method(n.ref,r),s={ref:o,key:Z.of(n.origin,o),name:r,owner:n,definition:i.declaration},a=Object.freeze(i.declaration.static?{...s,path:vI(i.owner,r)}:{...s,on:(c)=>EI(c,r)});t.push([a.key,a])}return new wn(t)}function wI(e){let t=[];for(let[r,i]of e.analysis?.properties??[]){let n=Ei(i.owner.origin,i.owner.kind,i.owner.name),o=ne.property(n.ref,i.name);t.push([r,Object.freeze({ref:o,key:r,name:i.name,owner:n,definition:Object.freeze({schema:i.schema,required:i.required,visibility:i.visibility,...i.auto===void 0?{}:{auto:i.auto}})})])}return new wn(t)}class II{$;origin;kind;name;ref;key;schemaRef;definition;path;properties;data;methods;constructor(e,t){let r=Ei(e.schemaRef.origin,e.schemaRef.kind,e.schemaRef.name);this.origin=r.origin,this.kind=r.kind,this.name=r.name,this.ref=r.ref,this.key=r.key,this.schemaRef=Object.freeze({origin:e.schemaRef.origin,kind:e.schemaRef.kind,name:e.schemaRef.name}),this.definition=e.declaration,this.path=KJ(e.schemaRef),this.properties=wI(e),this.methods=xI(e),this.data=$j(e);let i=Object.freeze(mI(e).map((s)=>t(s)));if(e.schemaRef.kind==="interface")Object.defineProperty(this,"family",{enumerable:!0,value:e.declaration.family}),Object.defineProperty(this,"extends",{enumerable:!0,value:i});else if(e.schemaRef.kind==="class")Object.defineProperty(this,"family",{enumerable:!0,value:e.declaration.family}),Object.defineProperty(this,"implements",{enumerable:!0,value:i});let n=Lm(this.properties.values()),o=Lm(this.methods.values());this.$=Object.freeze({property:(s)=>Pm(this.properties,n,s,"Property",this.key),method:(s)=>Pm(this.methods,o,s,"Method",this.key)}),bI(this,n,o),Object.freeze(this)}satisfies(e){return pI(this,e)}}function KJ(e){switch(e.kind){case"interface":case"class":case"function":case"policy":case"view":return q.project(e);case"type":return}}function OI(e){let t;try{t=Y.resolve(e)}catch(m){throw new Oe("DOMAIN_DEPENDENCY_MISSING",`Cannot construct Domain ${e.origin} without its exact accepted dependency closure.`,[],{cause:m})}let r=new wn([e,...t.$.closure].map((m)=>[m.origin,m])),i=new Map,n=(m)=>{let B=ne.definition(m.kind,m.name),h=Z.of(m.origin,B),g=i.get(h);if(g!==void 0)return g;let w=BI(m,r,t);if(w===void 0)throw new Oe("DOMAIN_DEFINITION_NOT_FOUND",`Definition ${h} does not exist.`);let b=new II(w,n);return i.set(h,b),b},o=(m)=>{let B=CI(m,e.origin,r);if(B===void 0){let h=typeof m==="string"?m:JSON.stringify(m);throw new Oe("DOMAIN_DEFINITION_NOT_FOUND",`Definition ${h} does not exist in the accepted closure.`)}return n(B)},a=gI(e).sort((m,B)=>ZJ(Z.of(m.origin,ne.definition(m.kind,m.name)),Z.of(B.origin,ne.definition(B.kind,B.name)))).map((m)=>{let B=n(m);return[B.key,B]}),c=new wn(a),u=[];for(let m of yI()){let B=a.filter(([,h])=>h.kind===m).map(([,h])=>[h.name,h]);u.push([m,new wn(B)])}let l=new wn(u),d=new Map;for(let[,m]of a){let B=d.get(m.name)??[];B.push(m),d.set(m.name,B)}let f=new wn([...d].flatMap(([m,B])=>B.length===1?[[m,B[0]]]:[]));return Object.freeze({schema:e,resolved:t,schemas:r,localDefinitions:c,localByKind:l,flat:f,definition:o,schemaDefinition:n})}function ZJ(e,t){return e<t?-1:e>t?1:0}function DI(e,t,r,i){let n=[];for(let o of e.methods.values()){if(!jj(o))continue;let s=e.kind==="interface"?t.$.method(o.name):o;if(!jj(s)||s.definition.inheritance==="abstract")throw new Oe("DOMAIN_METHOD_NOT_FOUND",`Concrete Class ${t.key} has no executable instance Method for ${o.key}.`);n.push(Object.freeze({key:o.key,name:o.name,owner:o.owner,call:i(s,r)}))}return Object.freeze(n)}function jj(e){return typeof e==="object"&&e!==null&&"on"in e}var Lj=new Set(["$","$d","class","props"]);function _I(e,t,r,i){let n=new Map,o=new Map,s=new Map;for(let f of t.properties.values()){let m=e.props[f.key];n.set(f.key,m),zm(o,f.name,[f.key,m]);let B=Pj(s,f.owner.origin,f.owner.ref,f.owner.name);B.properties.set(f.key,m),zm(B.propertyNames,f.name,[f.key,m])}let a=new Map,c=new Map;if(i!==void 0&&eK(e))for(let f of DI(t,r,e,i)){a.set(f.key,f.call),zm(c,f.name,[f.key,f.call]);let m=Pj(s,f.owner.origin,f.owner.ref,f.owner.name);m.methods.set(f.key,f.call),zm(m.methodNames,f.name,[f.key,f.call])}let u=WJ(s),l=Object.freeze({definition:t,property:(f)=>Mm(n,o,f,"Property",t.key),method:(f)=>Mm(a,c,f,"Method",t.key)}),d={...e,$:l};return Object.defineProperty(d,"$d",{enumerable:!0,value:(f)=>{let m=u.get(f);if(m!==void 0)return m;throw new Oe("DOMAIN_DEFINITION_NOT_FOUND",`No Property or bound Method owner from ${f} exists on ${t.key}.`)}}),zj(d,o,c),QJ(d,u),Object.freeze(d)}function Pj(e,t,r,i){let n=`${t}:${r}`,o=e.get(n);if(o!==void 0)return o;let s={origin:t,ref:r,name:i,properties:new Map,propertyNames:new Map,methods:new Map,methodNames:new Map};return e.set(n,s),s}function WJ(e){let t=new Map;for(let i of e.values()){let n=t.get(i.origin)??[];n.push(i),t.set(i.origin,n)}let r=new Map;for(let[i,n]of t){let o={},s=XJ(n,(a)=>a.name);for(let a of n){let c=YJ(a);if(Object.defineProperty(o,a.ref,{enumerable:!0,value:c}),s.get(a.name)?.length===1&&!(a.name in o))Object.defineProperty(o,a.name,{enumerable:!0,value:c})}r.set(i,Object.freeze(o))}return r}function YJ(e){let t={},r=Object.freeze({property:(i)=>Mm(e.properties,e.propertyNames,i,"Property",`${e.origin}:${e.ref}`),method:(i)=>Mm(e.methods,e.methodNames,i,"Method",`${e.origin}:${e.ref}`)});return Object.defineProperty(t,"$",{enumerable:!0,value:r}),zj(t,e.propertyNames,e.methodNames),Object.freeze(t)}function zj(e,t,r){let i=new Set([...t.keys(),...r.keys()]);for(let n of i){if(Lj.has(n)||n in e)continue;let o=t.get(n)??[],s=r.get(n)??[];if(o.length+s.length!==1)continue;Object.defineProperty(e,n,{enumerable:!0,value:o[0]?.[1]??s[0]?.[1]})}}function QJ(e,t){let r=new Map;for(let i of t.values())for(let[n,o]of Object.entries(i)){if(n.includes("."))continue;let s=r.get(n)??[];if(!s.includes(o))s.push(o);r.set(n,s)}for(let[i,n]of r){if(n.length!==1||Lj.has(i)||i in e)continue;Object.defineProperty(e,i,{enumerable:!0,value:n[0]})}}function Mm(e,t,r,i,n){let o=e.get(r);if(o!==void 0||e.has(r))return o;let s=t.get(r)??[];if(s.length===1)return s[0][1];if(s.length>1)throw new Oe(i==="Property"?"DOMAIN_PROPERTY_AMBIGUOUS":"DOMAIN_METHOD_NOT_FOUND",`${i} ${JSON.stringify(r)} is ambiguous on ${n}; use one of: ${s.map(([a])=>a).join(", ")}.`);throw new Oe(i==="Property"?"DOMAIN_PROPERTY_NOT_FOUND":"DOMAIN_METHOD_NOT_FOUND",`${i} ${JSON.stringify(r)} does not exist on ${n}.`)}function zm(e,t,r){let i=e.get(t)??[];i.push(r),e.set(t,i)}function XJ(e,t){let r=new Map;for(let i of e){let n=t(i),o=r.get(n)??[];o.push(i),r.set(n,o)}return r}function eK(e){return"id"in e}function kI(e,t,r,i){let n=tK(t),o=e.schemaDefinition({origin:Ze.origin(t.class),kind:"class",name:Ze.name(t.class)});if(r!==void 0){if(n&&r.family!=="node"||!n&&(r.kind!=="class"||r.family!=="edge"))throw new Oe("DOMAIN_VALUE_KIND_MISMATCH",`${r.key} cannot describe a ${n?"Node":"Edge"} value.`);if(!(r.kind==="class"?r.key===o.key:o.satisfies(r)))throw new Oe("DOMAIN_VALUE_CLASS_MISMATCH",`Graph value Class ${o.key} does not satisfy ${r.key}.`)}return _I(t,r??o,o,n?i:void 0)}function tK(e){return"id"in e}function Um(e,t){let r=Z.origin(t),i=Z.ref(t);if(rK(i)){let o=i.lastIndexOf(".method."),s=i.slice(0,o),a=i.slice(o+8);return{declaration:e.definition(Z.of(r,s)).$.method(a).definition,owner:Mj(e,r)}}if(!ne.isDefinition(i)||!i.startsWith("function."))throw new Oe("DOMAIN_DEFINITION_KIND_MISMATCH",`${t} is not callable.`);let n=e.definition(t);if(n.kind!=="function")throw new Oe("DOMAIN_DEFINITION_KIND_MISMATCH",`${n.key} is not a Function.`);return{declaration:n.definition,owner:Mj(e,r)}}function Mj(e,t){let r=e.schemas.get(t);if(r===void 0)throw new Oe("DOMAIN_DEPENDENCY_MISSING",`Exact schema ${t} is unavailable while validating its declaration.`);return r}function rK(e){return e.includes(".method.")}function Xt(e,t,r,i){return Object.freeze({code:e,message:t,...r===void 0?{}:{path:r},...i===void 0?{}:{details:i}})}function Uj(e,t=[]){return Object.freeze({status:e,diagnostics:Object.freeze([...t])})}function cn(e){return Uj(e.length===0?"pass":"reject",e)}function SI(e,t,r){try{let{declaration:i,owner:n}=Um(e,t);return cn(Y.values.validate(n,i.input,r,"/input").map((o)=>Xt(o.code,o.message,o.pointer)))}catch(i){return cn([nK(i)])}}function nK(e){return e instanceof Oe?Xt(e.code,e.message):Xt("DOMAIN_VALIDATION_FAILED",e instanceof Error?e.message:String(e))}function AI(e,t,r){try{let{declaration:i,owner:n}=Um(e,t),o=i.output.mode==="value"?i.output.schema:i.output.mode==="stream"?i.output.item:void 0;if(o===void 0)return cn([Xt("DOMAIN_OUTPUT_NOT_JSON","A binary callable has no JSON output value to validate.","/output")]);return cn(Y.values.validate(n,o,r,"/output").map((s)=>Xt(s.code,s.message,s.pointer)))}catch(i){return cn([iK(i)])}}function iK(e){return e instanceof Oe?Xt(e.code,e.message):Xt("DOMAIN_VALIDATION_FAILED",e instanceof Error?e.message:String(e))}function tl(e,t,r){let i=se(r);if(i===null||typeof i!=="object"||Array.isArray(i))throw new Oe("DOMAIN_PROPERTY_INPUT_INVALID","Property input must be a JSON object.");let n=e.definition(t),o=oK(n.properties.values()),s={},a=new Set;for(let[c,u]of Object.entries(i)){let l=n.properties.get(c),d=l===void 0?o.get(c)??[]:[l];if(d.length===0)throw new Oe("DOMAIN_PROPERTY_UNKNOWN",`Property ${JSON.stringify(c)} does not exist on ${n.key}.`);if(d.length>1)throw new Oe("DOMAIN_PROPERTY_AMBIGUOUS",`Property ${JSON.stringify(c)} is ambiguous on ${n.key}; use one of: ${d.map((m)=>m.key).join(", ")}.`);let f=d[0];if(a.has(f.key))throw new Oe("DOMAIN_PROPERTY_DUPLICATE",`Property ${f.key} was supplied more than once.`);a.add(f.key),Object.defineProperty(s,f.key,{enumerable:!0,value:u})}return ar(s)}function oK(e){let t=new Map;for(let r of e){let i=t.get(r.name)??[];if(!i.some((n)=>n.key===r.key))i.push(r);t.set(r.name,i)}return t}function rl(e,t,r){let i,n;try{n=e.definition(t),i=tl(e,t,r)}catch(a){return cn([aK(a)])}if(n.kind!=="class")return cn([Xt("DOMAIN_CLASS_REQUIRED",`${n.key} is not a concrete Class.`,"/definition")]);let o=[],s=new Set(n.properties.keys());for(let a of Object.keys(i))if(!s.has(a))o.push(Xt("DOMAIN_PROPERTY_UNKNOWN",`Unknown Property ${a}.`,`/properties/${a}`));for(let a of n.properties.values()){let c=i[a.key];if(c===void 0){if(a.definition.required)o.push(Xt("DOMAIN_PROPERTY_REQUIRED",`Required Property ${a.key} is absent.`,`/properties/${a.key}`));continue}let u=sK(e,a.owner.origin);o.push(...Y.values.validate(u,a.definition.schema,c,`/properties/${a.key}`).map((l)=>Xt(l.code,l.message,l.pointer,l.ref===void 0?void 0:{ref:l.ref})))}return cn(o)}function sK(e,t){let r=e.schemas.get(t);if(r===void 0)throw new Oe("DOMAIN_DEPENDENCY_MISSING",`Exact schema ${t} is unavailable while validating its declaration.`);return r}function aK(e){return e instanceof Oe?Xt(e.code,e.message):Xt("DOMAIN_VALIDATION_FAILED",e instanceof Error?e.message:String(e))}function $I(e){return Object.freeze({properties:(t,r)=>rl(e,t,r),input(t,r){return SI(e,t,r)},output(t,r){return AI(e,t,r)}})}function TI(e,t,r){let i=tl(e,t,r),n=e.definition(t);if(n.kind!=="class")throw new Oe("DOMAIN_CLASS_REQUIRED",`${n.key} is not a concrete Class.`);let o=rl(e,t,i);if(o.status==="reject")throw new Oe("DOMAIN_VALIDATION_FAILED",`Properties do not satisfy ${n.key}.`,o.diagnostics);return i}function NI(e,t){if(e.kind==="domain")return t==="domain";if(t==="domain")return!1;return e.definitions.some((r)=>t.satisfies(r))}function RI(e,t){let r=t.definition.target;if(r.kind==="domain")return Object.freeze({kind:"domain"});return Object.freeze({kind:"definition",definitions:Object.freeze(r.definitions.map((i)=>e.schemaDefinition(i)))})}function Fj(e,t){return e.key<t.key?-1:e.key>t.key?1:0}function jI(e,t){let r=e.localByKind.get("view")?.values()??[];return Object.freeze([...r].filter((i)=>i.kind==="view").filter((i)=>NI(RI(e,i),t)).sort(Fj))}var Gj=new WeakSet;class PI{$;constructor(e){let t=Object.freeze({nodes:fI(e.schema)}),r=$I(e);this.$=Object.freeze({schema:e.schema,origin:e.schema.origin,path:q.domain(e.schema.origin),revision:e.resolved.$.revision,dependencies:e.schema.dependencies,definitions:e.localDefinitions,core:t,validate:r,inspect:(i)=>e.definition(i),class:(i)=>ao(e,["class"],i,"Class"),interface:(i)=>ao(e,["interface"],i,"Interface"),function:(i)=>ao(e,["function"],i,"Function"),policy:(i)=>ao(e,["policy"],i,"Policy"),view:(i)=>ao(e,["view"],i,"View"),type:(i)=>ao(e,["type"],i,"Type"),viewsFor:(i)=>jI(e,i),properties:(i,n)=>TI(e,i,n),wrap:(...i)=>{let n=cK(i[0]),o=n?i[0]:void 0,s=n?i[1]:i[0],a=n?i[2]:i[1];return kI(e,s,o,a)}});for(let[i,n]of e.flat){if(i==="$")continue;Object.defineProperty(this,i,{enumerable:!0,value:n})}Object.freeze(this),Gj.add(this)}static fromSchema(e){return new PI(OI(e))}static admit(e){if(typeof e!=="object"&&typeof e!=="function"||e===null||!Gj.has(e))throw TypeError("Domain is not an exact rich Domain projection.");return e}}var Ha=PI;function cK(e){return typeof e==="object"&&e!==null&&"$"in e&&"key"in e}var Zr=qt({family:"both",description:"Optional human-facing description metadata with no identity or authority semantics.",properties:{description:qe(Y.metadata.description,{required:!1})}});var Dt=qt({family:"both",description:"Explicit kernel marker for Edge definitions; it carries no structural fields."});var nl=qt({family:"both",description:"Optional bounded presentation icon metadata.",properties:{icon:qe(Y.metadata.icon,{required:!1})}});var il=qt({family:"both",description:"Stable human-facing name metadata that never acts as a locator.",properties:{name:{type:"string",minLength:1,maxLength:100}}});var as=_n({description:"The universal kernel node contract implicitly satisfied by every Node Interface and Node Class."});var LI=qt({family:"both",description:"Optional synchronization metadata for a value originating outside the local kernel.",properties:{externalId:qe({type:"string",minLength:1,maxLength:512},{required:!1}),onConflict:qe({enum:["defaults","error","merge","replace","skip"]},{required:!1}),updatedAt:qe(Y.values.instant,{required:!1})}});var zI=qt({family:"both",description:"Explicit lifecycle-state metadata for values whose contract declares such a state.",properties:{status:{enum:["active","creating","deleting","error","updating"]}}});var MI=qt({family:"both",description:"Explicit creation and update timestamp metadata.",properties:{createdAt:ou(qe(Y.values.instant),{on:"create",set:"instant"}),updatedAt:ou(qe(Y.values.instant),{on:["create","update"],set:"instant"})}});var bt=ir({description:"The installed graph projection of a concrete Node Class or Edge Class declaration.",implements:[Zr,nl],properties:{family:{enum:["node","edge"]}}});var un=ir({description:"The installed graph projection of a both-, Node-, or Edge-family Interface.",implements:[Zr],properties:{family:{enum:["both","node","edge"]}}});var UI=kt.directed({source:{as:"sub",accepts:[un],outgoing:"0..*"},target:{as:"super",accepts:[un],incoming:"0..*"},description:"The protected projection of compatible Interface inheritance.",implements:[Dt],constraints:{noSelf:!0,acyclic:!0}});var FI=kt.directed({source:{as:"class",accepts:[bt],outgoing:"0..*"},target:{as:"interface",accepts:[un],incoming:"0..*"},description:"The protected projection of a Class implementing a compatible Interface.",implements:[Dt],constraints:{noSelf:!0}});var GI=kt.directed({source:{as:"instance",accepts:[as],outgoing:"1"},target:{as:"class",accepts:[bt],incoming:"0..*"},description:"The concrete Node Class fact fixed when a node is created.",implements:[Dt]});var lK={origin:"kernel.astrale.ai",kind:"interface",name:"Identity"};function dr(e,t,r){return kt.directed({source:{as:"identity",accepts:[lK],outgoing:"0..*"},target:{as:t,accepts:[e],incoming:"0..*"},description:r,implements:[Dt]})}var Fm=dr(bt,"class","An Identity may create instances of the target Class.");var Gm=dr(bt,"class","An Identity may delete instances of the target Class.");var fr=ir({description:"One closed authority relation operation administered by can_grant and can_revoke.",implements:[il]});var Hm=dr(fr,"operation","An Identity may create authority edges for the target Operation.");var Vm=dr(bt,"class","An Identity may read complete instances of the target Class; read also permits traversal.");var HI=dr(fr,"operation","An Identity may remove authority edges for the target Operation.");var qm=dr(bt,"class","An Identity may use instances of the target Class as structural Query witnesses without reading their values.");var Jm=dr(bt,"class","An Identity may update instances of the target Class.");var VI=p.strictObject({call:p.strictObject({target:p.string().min(1),input:p.unknown()}),credential:p.string().optional()}),qI=p.strictObject({callable:p.string().min(1),receiver:p.string().min(1).optional()});var Hj=p.string().min(1),JI=p.strictObject({policy:Hj,object:Hj}),KI=p.strictObject({allowed:p.boolean()});var Vj=p.string().min(1),ZI=p.strictObject({audience:Vj,ttlSeconds:p.number().int().min(1),attenuation:p.unknown()}),WI=Vj;var co=p.string().check(en("[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}"));var xt=p.string().min(1),Vn=xt.check(en("sha256:[0-9a-f]{64}")),Kj=p.strictObject({digest:Vn,mediaType:xt,size:p.number().int().min(0).max(Number.MAX_SAFE_INTEGER)}),Zj=p.strictObject({origin:xt,installation:xt,target:Vn,readinessReceipt:Vn,meaningComparison:Vn}),dK=p.discriminatedUnion("kind",[p.strictObject({kind:p.literal("local"),artifact:Vn}),p.strictObject({kind:p.literal("remote"),etag:Vn})]),qj=p.enum(["use","create","read","traverse","update","delete","grant","revoke"]),fK=p.enum(["create","read","traverse","update","delete"]),pK=p.strictObject({functions:p.array(xt).min(1).optional(),classes:p.array(p.strictObject({class:p.strictObject({origin:xt,kind:p.literal("class"),name:xt}),operations:p.array(fK).min(1)})).min(1).optional(),admin:p.strictObject({grant:p.array(qj).min(1).optional(),revoke:p.array(qj).min(1).optional()}).optional()}),Jj=p.strictObject({origin:xt,schemaRevision:xt,schemaBundle:Vn,service:dK,capabilities:pK,dependencies:p.array(Zj)}),mK=p.strictObject({transition:xt,operation:co,installation:xt,origin:xt,source:Jj.nullable(),target:Jj.nullable()}),BK=p.strictObject({installation:xt,target:Vn,transition:xt,dependencies:p.array(Zj)}),Km=p.strictObject({intent:mK,phase:p.enum(["cutover","converge"]),state:p.literal("committed"),readiness:BK.optional()});var YI=p.strictObject({operation:co,domains:p.array(p.union([p.strictObject({source:p.strictObject({kind:p.literal("local"),artifact:Kj}),currentRevision:xt.nullable().optional()}),p.strictObject({source:p.strictObject({kind:p.literal("remote"),url:xt,token:xt.optional()}),targetRevision:xt.optional(),targetEtag:Vn.optional(),currentRevision:xt.nullable().optional()})])).min(1)}),QI=p.strictObject({operation:co,transitions:p.array(Km).min(1)});var hK=p.strictObject({state:p.literal(!0).optional(),target:p.literal(!0).optional(),source:p.literal(!0).optional(),bundle:p.literal(!0).optional(),readiness:p.literal(!0).optional(),capabilities:p.literal(!0).optional()}),XI=p.strictObject({from:p.strictObject({kind:p.literal("installation"),origin:p.string().min(1)}),select:hK});var qn=p.string().min(1),gK=p.strictObject({exact:p.array(qn).optional(),prefixes:p.array(qn).optional()}),eO=p.strictObject({invocation:p.strictObject({source:qn,id:qn}).optional(),topics:gK.optional(),principal:qn.optional(),since:qn.optional(),until:qn.optional(),cursor:qn.optional(),limit:p.number().int().min(1).optional()}),tO=p.strictObject({records:p.array(p.unknown()),frontier:p.strictObject({id:qn,first:p.number().int().min(1).optional(),committed:p.number().int().min(0),durable:p.number().int().min(0)}),cursor:qn.optional(),gap:p.unknown().optional()});var Wj=p.string().min(1),rO=p.strictObject({audience:Wj.optional(),ttlSeconds:p.number().int().min(1),grant:p.unknown().optional()}),nO=Wj;var iO=Xi,oO=Ta;var sO=p.string().min(1),Yj=p.unknown().nonoptional(),Qj=p.discriminatedUnion("op",[p.strictObject({claim:sO,op:p.literal("contains"),value:Yj}),p.strictObject({claim:sO,op:p.literal("eq"),value:Yj}),p.strictObject({claim:sO,op:p.literal("exists")})]),cs=p.array(Qj).max(Kp.MAX_REQUIRED_CLAIMS);var us=p.string().min(1),Xj=cs.optional(),yK=p.strictObject({issuer:us,subject:us,requiredClaims:Xj}),CK=p.strictObject({credentials:p.strictObject({publicKey:p.unknown(),proof:us}),requiredClaims:Xj}),aO=p.strictObject({idempotencyKey:us,mutation:Xi,identities:p.record(p.string(),p.union([yK,CK]))}),cO=p.strictObject({createdNodes:p.record(p.string(),us),identities:p.record(p.string(),p.strictObject({issuer:us,subject:us}))});class ls extends TypeError{path;code="QUERY_RESULT_INVALID";constructor(e,t,r){super(`${t} at ${e||"/"}.`,r);this.path=e,this.name="QueryResultDecodeError"}}var uO=p.string().min(1),bK=p.strictObject({id:uO,class:uO}),lO=p.discriminatedUnion("kind",[p.strictObject({kind:p.literal("reference"),value:bK}),p.strictObject({kind:p.literal("value"),value:rm})]),EK=p.discriminatedUnion("kind",[p.strictObject({kind:p.literal("reference"),value:nm}),p.strictObject({kind:p.literal("value"),value:cw})]),vK=p.strictObject({edge:EK,source:lO,target:lO}),Va=p.discriminatedUnion("kind",[p.strictObject({kind:p.literal("graph"),graph:MN,selection:p.discriminatedUnion("kind",[p.strictObject({kind:p.literal("node"),ids:p.array(uO)}),p.strictObject({kind:p.literal("edge"),keys:p.array(nm)})])}),p.strictObject({kind:p.literal("nodes"),nodes:p.array(lO)}),p.strictObject({kind:p.literal("edges"),edges:p.array(vK)})]);var ol=Object.freeze({decode:ds,encode:xK,selection:wK});function xK(e){return ds(e)}function wK(e){if(e.kind==="graph")return e.selection;if(e.kind==="nodes")return Object.freeze({kind:"node",ids:Object.freeze(e.nodes.map((t)=>t.value.id))});return Object.freeze({kind:"edge",keys:Object.freeze(e.edges.map((t)=>t.edge.kind==="reference"?t.edge.value:it(t.edge.value)))})}function ds(e){try{let t=zn(Va,se(e),Jn);if(t.kind==="graph"){let r=pO(t.graph,"/graph"),i=OK(t.selection,r);return i.kind==="node"?Object.freeze({kind:t.kind,graph:r,selection:i}):Object.freeze({kind:t.kind,graph:r,selection:i})}if(t.kind==="nodes")return Object.freeze({kind:t.kind,nodes:Object.freeze(t.nodes.map((r,i)=>dO(r,`/nodes/${i}`)))});return Object.freeze({kind:t.kind,edges:Object.freeze(t.edges.map((r,i)=>Object.freeze({edge:IK(r.edge,`/edges/${i}/edge`),source:dO(r.source,`/edges/${i}/source`),target:dO(r.target,`/edges/${i}/target`)})))})}catch(t){if(t instanceof ls)throw t;throw new ls(_K(t),"Invalid QueryResult",{cause:t})}}function dO(e,t){if(e.kind==="reference"){let i=e.value;return Object.freeze({kind:e.kind,value:Object.freeze({id:fO(i.id,`${t}/value/id`),class:eP(i.class,`${t}/value/class`)})})}let r=pO({nodes:[e.value],edges:[]},`${t}/value`,"/nodes/0");return Object.freeze({kind:e.kind,value:r.nodes[0]})}function IK(e,t){if(e.kind==="reference"){let i=e.value;return Object.freeze({kind:e.kind,value:Object.freeze({source:fO(i.source,`${t}/value/source`),target:fO(i.target,`${t}/value/target`),class:eP(i.class,`${t}/value/class`)})})}let r=pO({nodes:[],edges:[e.value]},`${t}/value`,"/edges/0");return Object.freeze({kind:e.kind,value:r.edges[0]})}function pO(e,t,r){try{return Hu.decode(e)}catch(i){let n=i instanceof Yi?r!==void 0&&i.path.startsWith(r)?i.path.slice(r.length):i.path:"";Jn(DK(t,n),"Invalid graph value",i)}}function fO(e,t){try{return Fe(e)}catch(r){Jn(t,"Invalid NodeId",r)}}function eP(e,t){try{return Ze.parse(e)}catch(r){Jn(t,"Invalid ClassPath",r)}}function OK(e,t){if(e.kind==="node"){let o=new Set(t.nodes.map((c)=>c.id)),s=new Set,a=Object.freeze(e.ids.map((c,u)=>{let l;try{l=Fe(c)}catch(d){Jn(`/selection/ids/${u}`,"Invalid selected NodeId",d)}if(s.has(l))Jn(`/selection/ids/${u}`,"Duplicate selected NodeId");if(!o.has(l))Jn(`/selection/ids/${u}`,"Selected NodeId is absent from graph");return s.add(l),l}));return Object.freeze({kind:"node",ids:a})}let r=new Set(t.edges.map((o)=>Ge(o))),i=new Set,n=Object.freeze(e.keys.map((o,s)=>{let a;try{a=Object.freeze({source:Fe(o.source),target:Fe(o.target),class:Ze.parse(o.class)})}catch(u){Jn(`/selection/keys/${s}`,"Invalid selected EdgeKey",u)}let c=Ge(a);if(i.has(c))Jn(`/selection/keys/${s}`,"Duplicate selected EdgeKey");if(!r.has(c))Jn(`/selection/keys/${s}`,"Selected EdgeKey is absent from graph");return i.add(c),a}));return Object.freeze({kind:"edge",keys:n})}function Jn(e,t,r){throw new ls(e,t,r===void 0?void 0:{cause:r})}function DK(e,t){return t===""?e:`${e}${t}`}function _K(e){return e instanceof he?e.pointer:""}var mO=p.strictObject({ast:Qi,page:p.strictObject({size:p.number().int().min(1).max(Number.MAX_SAFE_INTEGER),after:p.string().min(1).optional()})}),BO=p.strictObject({result:Va,page:p.strictObject({next:p.string().min(1).optional()})});var hO=p.strictObject({operation:co,origin:xt}),gO=p.strictObject({operation:co,transition:Km});var kK=p.discriminatedUnion("kind",[p.strictObject({origin:p.string().min(1),kind:p.literal("class"),name:p.string().min(1)}),p.strictObject({origin:p.string().min(1),kind:p.literal("interface"),name:p.string().min(1)})]),SK=p.strictObject({description:p.string().optional(),target:p.discriminatedUnion("kind",[p.strictObject({kind:p.literal("domain")}),p.strictObject({kind:p.literal("definition"),definitions:p.array(kK).min(1)})]),auth:p.enum(["required","optional","public"])}),yO=p.strictObject({target:p.string().min(1)}),CO=p.strictObject({snapshot:p.string().min(1),views:p.array(p.strictObject({key:p.string().min(1),declaration:SK,href:p.string().min(1),handshake:p.enum(["shell","none"]),issuer:p.string().min(1),etag:p.string().min(1),revision:p.string().min(1)}))});var bO=p.string().min(1),Zm=p.strictObject({id:bO,issuer:bO,subject:bO,frozen:p.boolean(),requiredClaims:cs});var EO=p.strictObject({}),vO=Zm;var tP=p.string().min(1),xO=p.strictObject({issuer:tP,subject:tP}),wO=Zm.nullable();function Xe(e){return rd(e)}var rP=Xe({description:"Admit one remote path-only attempt and return its request-scoped execution target.",auth:"authenticated",input:VI,output:qI,static:!0,inheritance:"sealed"});var nP=Xe({description:"Determine whether the current authenticated Identity satisfies one installed Policy for one object.",auth:"authenticated",input:JI,output:KI,static:!0,inheritance:"default"});var iP=Xe({description:"Issue one strictly attenuated credential from this authenticated Identity.",auth:"authenticated",input:ZI,output:WI,inheritance:"default"});var oP=Xe({description:"Durably install one or more exact Schema targets and return a terminal receipt.",auth:"authorized",input:YI,output:QI});var sP=Xe({description:"Return bounded installed-Publication evidence to an authenticated Kernel session.",auth:"authenticated",input:XI,output:nd.binary()});var aP=Xe({description:"Read one authorized page of semantic operations from the kernel journal.",auth:"authorized",input:eO,output:tO});var cP=Xe({description:"Resolve and sign one authorized Grant credential.",auth:"authorized",input:rO,output:nO,static:!0,inheritance:"default"});var uP=Xe({description:"Validate, authorize, and commit one atomic graph mutation.",auth:"authorized",input:iO,output:oO});var lP=Xe({description:"Atomically execute a graph transition whose designated Identities are born complete.",auth:"authorized",input:aO,output:cO});var dP=Xe({description:"Execute one finite authorized graph query.",auth:"authorized",input:mO,output:BO});var fP=Xe({description:"Durably uninstall one Domain installation epoch and return its terminal receipt.",auth:"authorized",input:hO,output:gO});var pP=Xe({description:"Resolve the installed View declarations applicable to one authorized graph target.",auth:"authorized",input:yO,output:CO,static:!0,inheritance:"sealed"});var mP=Xe({description:"Return the Identity authenticated for this invocation.",auth:"authenticated",input:EO,output:vO,static:!0,inheritance:"default"});var BP=Xe({description:"Resolve one issuer-and-subject Identity.",auth:"authorized",input:xO,output:wO,static:!0,inheritance:"default"});var hP=Object.freeze({query:dP,mutate:uP,provision:lP,install:oP,introspect:sP,uninstall:fP,journal:aP}),gP=Object.freeze({delegate:iP,can:nP,whoami:mP,whois:BP,mint:cP}),yP=Object.freeze({admit:rP}),CP=Object.freeze({resolve:pP});var sl=_n({description:"Ordinary projection-node contract for a standalone Function or Node Method declaration.",extends:[Zr],properties:{kind:{enum:["function","method"]},input:{},output:{type:"object"},auth:{enum:["anonymous","authenticated","authorized"]},policy:qe({type:"object"},{required:!1}),static:qe({type:"boolean"},{required:!1}),inheritance:qe({enum:["abstract","default","sealed"]},{required:!1})}});var fs=ir({description:"The installed projection of a standalone Function or Node Method declaration; it is not a principal.",implements:[sl],methods:yP});var IO=kt.directed({source:{as:"method",accepts:[fs],outgoing:"0..1"},target:{as:"owner",accepts:[bt,un],incoming:"0..*"},description:"A Function declaration belongs to one Class or Interface for dispatch.",implements:[Dt],properties:{name:qe({type:"string",minLength:1},{visibility:"private"}),static:qe({type:"boolean"},{visibility:"private"})}});var al=_n({description:"Ordinary projection-node contract for a declarative browser surface.",extends:[Zr],properties:{auth:{enum:["required","optional","public"]}}});var cl=ir({description:"The installed projection of a declarative browser surface; it is not a principal.",implements:[al],methods:CP});var uo=_n({description:"A principal that can be authenticated and can originate persistent authority facts.",properties:{frozen:qe({type:"boolean"},{required:!1,visibility:"private"}),iss:{type:"string",minLength:1},requiredClaims:qe(cs,{required:!1,visibility:"private"}),sub:{type:"string",minLength:1}},methods:gP});function qa(e,t){return kt.directed({source:{as:"subject",accepts:[uo],outgoing:"0..*"},target:{as:e,accepts:[uo],incoming:"0..*"},description:t,implements:[Dt],constraints:{noSelf:!0,acyclic:!0}})}var OO=qa("constraint","An Identity intersects its effective authority with another Identity.");var DO=qa("excluded","An Identity excludes another Identity from its effective authority.");var _O=qa("extension","An Identity unions its effective authority with another Identity.");var ps=ir({description:"A stable Domain principal and the active projection of one canonical DomainSchema revision.",implements:[uo],properties:{origin:{type:"string",pattern:"[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?(\\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)+"},dependencyContext:qe({type:"array",items:{type:"object"}},{visibility:"private",required:!1}),schema:qe({type:"object"},{visibility:"private"}),schemaRevision:qe({type:"string",pattern:"sha256:[0-9a-f]{64}"},{visibility:"private"})}});var kO=kt.directed({source:{as:"member",accepts:[as],outgoing:"0..1"},target:{as:"domain",accepts:[ps],incoming:"0..*"},description:"A schema declaration or Core node belongs to one Domain member namespace.",implements:[Dt],constraints:{noSelf:!0},properties:{member:qe({type:"string",minLength:3},{visibility:"private"})}});var SO=kt.directed({source:{as:"view",accepts:[cl],outgoing:"1..*"},target:{as:"target",accepts:[bt,ps,un],incoming:"0..*"},description:"A View declaration targets one Domain or a non-empty set of Classes and Interfaces.",implements:[Dt]});var Wm=dr(fs,"function","An Identity may invoke the exact target Function declaration.");var ul=ir({description:"The installed graph projection of one named closed Policy declaration owned by a Domain.",implements:[Zr]});var AO=kt.directed({source:{as:"class",accepts:[bt],outgoing:"0..*"},target:{as:"policy",accepts:[ul],incoming:"0..*"},description:"The protected projection of one Class read or traverse Policy assignment.",implements:[Dt],properties:{operations:qe({enum:[["read"],["traverse"],["read","traverse"]]},{visibility:"private"})},constraints:{noSelf:!0}});var ms=Object.freeze(["use","create","read","traverse","update","delete","grant","revoke"]),lo=Object.freeze({use:fn(fr,{name:"use"}),create:fn(fr,{name:"create"}),read:fn(fr,{name:"read"}),traverse:fn(fr,{name:"traverse"}),update:fn(fr,{name:"update"}),delete:fn(fr,{name:"delete"}),grant:fn(fr,{name:"grant"}),revoke:fn(fr,{name:"revoke"})});var Ym=Object.freeze({nodes:lo,edges:Object.freeze([])});var AK={interfaces:{Descriptable:Zr,Edge:Dt,Function:sl,Iconable:nl,Identity:uo,Named:il,Node:as,Remotable:LI,Statused:zI,Timestamped:MI,UI:al},classes:{Class:bt,Domain:ps,Function:fs,Interface:un,Operation:fr,Policy:ul,View:cl,can_create:Fm,can_read:Vm,can_traverse:qm,can_update:Jm,can_delete:Gm,can_grant:Hm,can_revoke:HI,can_use:Wm,constrained_by:OO,excluded_from:DO,extends:UI,extends_with:_O,governed_by:AO,implements:FI,instance_of:GI,method_of:IO,of_domain:kO,view_for:SO},policies:{},functions:hP},$K=Object.freeze({nodes:lo,edges:Ym.edges}),TK={...AK,core:$K},ll=$p("kernel.astrale.ai",TK),ge=Ha.fromSchema(ll),bP=Object.freeze({use:ge.can_use,create:ge.can_create,read:ge.can_read,traverse:ge.can_traverse,update:ge.can_update,delete:ge.can_delete,grant:ge.can_grant,revoke:ge.can_revoke}),EP=Object.freeze([ge.query,ge.mutate,ge.provision,ge.install,ge.introspect,ge.uninstall,ge.journal,ge.Identity.whois,ge.Identity.mint,ge.View.resolve].sort((e,t)=>e.key<t.key?-1:e.key>t.key?1:0));var et={};ze(et,{function:()=>Xm,identity:()=>Qm,install:()=>jO,introspect:()=>PO,journal:()=>zO,mutate:()=>NO,provision:()=>RO,query:()=>TO,uninstall:()=>LO,view:()=>eB});function fo(e){let t=Object.freeze({origin:e.origin,kind:"function",name:e.name});return Object.freeze({ref:t,declaration:e.definition,callable:e})}function Kn(e){if(e.owner.kind==="interface"){let r=Object.freeze({origin:e.owner.origin,kind:"interface",name:e.owner.name});return Object.freeze({ref:Object.freeze({owner:r,name:e.name}),declaration:e.definition,callable:e})}let t=Object.freeze({origin:e.owner.origin,kind:"class",name:e.owner.name});return Object.freeze({ref:Object.freeze({owner:t,name:e.name}),declaration:e.definition,callable:e})}var TO=fo(ge.query),NO=fo(ge.mutate),RO=fo(ge.provision),jO=fo(ge.install),PO=fo(ge.introspect),LO=fo(ge.uninstall),zO=fo(ge.journal);var Qm={};ze(Qm,{can:()=>RK,delegate:()=>NK,mint:()=>LK,whoami:()=>jK,whois:()=>PK});var NK=Kn(ge.Identity.delegate),RK=Kn(ge.Identity.can),jK=Kn(ge.Identity.whoami),PK=Kn(ge.Identity.whois),LK=Kn(ge.Identity.mint);var Xm={};ze(Xm,{admit:()=>MK});var zK=ge.$.class("Function").$.method("admit"),MK=Kn(zK);var eB={};ze(eB,{acceptResolution:()=>HK,resolve:()=>GK});function vP(e){let t=se(e);if(ge.$.validate.output(ge.View.resolve.key,t).status==="reject")Bs("View resolution violates its callable contract.");let i=t,n=i.views.map((o,s)=>{let a;try{a=Z(o.key)}catch(u){throw TypeError(`Resolved View ${s} key is invalid.`,{cause:u})}if(!Z.ref(a).startsWith("view."))Bs(`Resolved View ${s} is not a View.`);if(!ht.is(o.issuer))Bs(`Resolved View ${s} issuer is not canonical.`);let c=UK(o.declaration,s);return Object.freeze({key:a,declaration:c,href:o.href,handshake:o.handshake,issuer:o.issuer,etag:MO(o.etag,`Resolved View ${s} ETag`),revision:MO(o.revision,`Resolved View ${s} revision`)})});for(let o=1;o<n.length;o++)if(n[o-1].key>=n[o].key)Bs("Resolved Views are not in strict canonical key order.");return Object.freeze({snapshot:MO(i.snapshot,"Resolved View Registry snapshot"),views:Object.freeze(n)})}function UK(e,t){if(e.target.kind==="domain")return Object.freeze({...e.description===void 0?{}:{description:e.description},target:Object.freeze({kind:"domain"}),auth:e.auth});let r=e.target.definitions.map((i,n)=>{if(!Y.patterns.origin.test(i.origin)||i.kind!=="class"&&i.kind!=="interface"||!Y.patterns.memberName.test(i.name))Bs(`Resolved View ${t} target definition ${n} is invalid.`);return Object.freeze({origin:i.origin,kind:i.kind,name:i.name})});for(let i=1;i<r.length;i++)if(FK(r[i-1],r[i])>=0)Bs(`Resolved View ${t} target definitions are not in strict canonical order.`);return Object.freeze({...e.description===void 0?{}:{description:e.description},target:Object.freeze({kind:"definition",definitions:Object.freeze(r)}),auth:e.auth})}function FK(e,t){return UO(e.origin,t.origin)||UO(e.kind,t.kind)||UO(e.name,t.name)}function MO(e,t){if(!/^sha256:[0-9a-f]{64}$/u.test(e))Bs(`${t} is invalid.`);return e}function UO(e,t){return e<t?-1:e>t?1:0}function Bs(e){throw TypeError(e)}var GK=Kn(ge.View.resolve),HK=vP;var VIe=ar({});var QIe=Object.freeze({get:()=>{return}});var tB=Object.freeze(["create","read","traverse","update","delete"]);function po(e){let t=Le(e,"PUBLICATION_INVALID","Publication requirements are invalid.");Je(t,["capabilities"],"PUBLICATION_INVALID");let r=Le(t.capabilities,"PUBLICATION_INVALID","Publication capability requirements are invalid.");Je(r,["admin","classes","functions"],"PUBLICATION_INVALID");let i=r.functions===void 0?void 0:rB(r.functions,"Function capability requirements").map(KK);if(i!==void 0)bi(i,"PUBLICATION_INVALID","Function capability requirement"),nB(i,OP,"Function capability requirements");let n=r.classes===void 0?void 0:rB(r.classes,"Class capability requirements").map(ZK);if(n!==void 0)bi(n.map((s)=>FO(s.class)),"PUBLICATION_INVALID","Class capability requirement"),nB(n,(s,a)=>OP(FO(s.class),FO(a.class)),"Class capability requirements");let o=r.admin===void 0?void 0:WK(r.admin);return Gn({capabilities:{...i===void 0?{}:{functions:Object.freeze(i)},...n===void 0?{}:{classes:Object.freeze(n)},...o===void 0?{}:{admin:o}}})}function iB(e,t,r){let i=JK(e,t);for(let n of r.capabilities.functions??[]){DP(e,i,n,"Function");let o=i.get(Z.origin(n)),s=Z.ref(n);if(!QK(o,s))W("PUBLICATION_INVALID","Function capability requirement names an unknown dependency callable.")}for(let n of r.capabilities.classes??[]){let o=Z.fromSchema(n.class);if(DP(e,i,o,"Class"),i.get(n.class.origin).classes[n.class.name]===void 0)W("PUBLICATION_INVALID","Class capability requirement names an unknown dependency Class.")}}function JK(e,t){let r=new Map(t.map((o)=>[o.origin,o])),i=new Map,n=(o)=>{for(let s of o.dependencies){let a=r.get(s.origin);if(a===void 0||Y.revision(a)!==s.revision)W("PUBLICATION_INVALID","Publication Bundle omits an exact dependency.");if(i.has(a.origin))continue;i.set(a.origin,a),n(a)}};return n(e),i}function KK(e){if(typeof e!=="string"||!Z.is(e))return W("PUBLICATION_INVALID","Function capability reference is invalid.");let t=Z.ref(e);if(!t.startsWith("function.")&&!ne.isMethod(t))return W("PUBLICATION_INVALID","Function capability reference must name a Function or Method.");return e}function ZK(e){let t=Le(e,"PUBLICATION_INVALID","Class capability requirement is invalid.");Je(t,["class","operations"],"PUBLICATION_INVALID");let r=rB(t.operations,"Class capability operations").map((i)=>_P(i,tB,"Class capability operation"));return bi(r,"PUBLICATION_INVALID","Class capability operation"),nB(r,kP(tB),"Class capability operations"),Object.freeze({class:YK(t.class),operations:Object.freeze(r)})}function WK(e){let t=Le(e,"PUBLICATION_INVALID","Administrative capability requirements are invalid.");if(Je(t,["grant","revoke"],"PUBLICATION_INVALID"),t.grant===void 0&&t.revoke===void 0)W("PUBLICATION_INVALID","Administrative capability requirements cannot be empty.");let r=IP(t.grant,"grant"),i=IP(t.revoke,"revoke");return Object.freeze({...r===void 0?{}:{grant:r},...i===void 0?{}:{revoke:i}})}function IP(e,t){if(e===void 0)return;let r=rB(e,`Administrative ${t} operations`).map((i)=>_P(i,ms,`Administrative ${t} operation`));return bi(r,"PUBLICATION_INVALID",`administrative ${t} operation`),nB(r,kP(ms),`Administrative ${t} operations`),Object.freeze(r)}function YK(e){let t=Le(e,"PUBLICATION_INVALID","Class capability reference is invalid.");if(Je(t,["kind","name","origin"],"PUBLICATION_INVALID"),t.kind!=="class"||typeof t.origin!=="string"||!Y.patterns.origin.test(t.origin)||typeof t.name!=="string"||!Y.patterns.memberName.test(t.name))W("PUBLICATION_INVALID","Class capability reference is invalid.");return Object.freeze({origin:t.origin,kind:"class",name:t.name})}function rB(e,t){let r=[...Ga(e,"PUBLICATION_INVALID")];if(r.length===0)W("PUBLICATION_INVALID",`${t} cannot be empty.`);return r}function _P(e,t,r){if(typeof e!=="string"||!t.includes(e))return W("PUBLICATION_INVALID",`${r} is unknown.`);return e}function nB(e,t,r){if(e.some((i,n)=>n>0&&t(e[n-1],i)>=0))W("PUBLICATION_INVALID",`${r} must be sorted canonically.`)}function kP(e){return(t,r)=>e.indexOf(t)-e.indexOf(r)}function OP(e,t){return e<t?-1:e>t?1:0}function FO(e){return String(Z.fromSchema(e))}function DP(e,t,r,i){let n=Z.origin(r);if(n===e.origin)W("PUBLICATION_INVALID",`${i} capability target cannot be local.`);if(!t.has(n))W("PUBLICATION_INVALID",`${i} capability target must belong to the exact dependency closure.`)}function QK(e,t){if(t.startsWith("function."))return e.functions[ne.member(t)]!==void 0;let r=ne.namespace(t),i=ne.member(t),n=ne.child(t),o=r==="class"?e.classes[i]:e.interfaces[i];return o?.family==="node"&&o.methods[n]!==void 0}var XK=/^[A-Za-z][A-Za-z0-9_-]{0,63}$/u;function SP(e,t){let r=Le(e,"PUBLICATION_ROUTE_INVALID","Published HTTP route is invalid.");if(Je(r,["name","callable","href","method","requestMethod","default","receiver","query","headers","body","credential"],"PUBLICATION_ROUTE_INVALID"),typeof r.name!=="string"||!XK.test(r.name))W("PUBLICATION_ROUTE_INVALID","Route name is invalid.");let i=Nm(r.callable,t);if(!["GET","POST","PUT","PATCH","DELETE","*"].includes(r.method))W("PUBLICATION_ROUTE_INVALID","Route method is invalid.");if(r.default!==void 0&&r.default!==!0)W("PUBLICATION_ROUTE_INVALID","Route default may only be true.");if(r.requestMethod!==void 0&&(typeof r.requestMethod!=="string"||!Y.patterns.memberName.test(r.requestMethod)))W("PUBLICATION_ROUTE_INVALID","Route request-method mapping is invalid.");if(r.receiver!==void 0&&(typeof r.receiver!=="string"||!Y.patterns.memberName.test(r.receiver)))W("PUBLICATION_ROUTE_INVALID","Route receiver is invalid.");let n=n3(r.query),o=r3(r.headers),s=t3(r.body),a=e3(r.credential);return Gn({name:r.name,callable:i,href:xn(r.href,!1,"PUBLICATION_ROUTE_INVALID",!0),method:r.method,...r.requestMethod===void 0?{}:{requestMethod:r.requestMethod},...r.default===!0?{default:!0}:{},...r.receiver===void 0?{}:{receiver:r.receiver},...n===void 0?{}:{query:n},...o===void 0?{}:{headers:o},...s===void 0?{}:{body:s},...a===void 0?{}:{credential:a}})}function e3(e){if(e===void 0)return;let t=Array.isArray(e)?e:[e];if(t.length===0)W("PUBLICATION_ROUTE_INVALID","Credential source list is empty.");let r=t.map((i)=>{let n=Le(i,"PUBLICATION_ROUTE_INVALID","Credential source is invalid.");if(Je(n,["in","name"],"PUBLICATION_ROUTE_INVALID"),n.in==="header"){if(n.name!==void 0&&(typeof n.name!=="string"||n.name.length===0))W("PUBLICATION_ROUTE_INVALID","Credential header name is invalid.");return Object.freeze({in:"header",...n.name===void 0?{}:{name:n.name}})}if((n.in==="cookie"||n.in==="query")&&typeof n.name==="string"&&n.name.length>0)return Object.freeze({in:n.in,name:n.name});return W("PUBLICATION_ROUTE_INVALID","Credential source is invalid.")});return Array.isArray(e)?Object.freeze(r):r[0]}function t3(e){if(e===void 0||e==="*")return e;let t=Le(e,"PUBLICATION_ROUTE_INVALID","Route body mapping is invalid."),r={};for(let[i,n]of Object.entries(t))if(typeof n==="string"&&n.length>0)r[i]=n;else if(n!==null&&typeof n==="object"&&!Array.isArray(n)&&Object.keys(n).length===1&&n.as==="text")r[i]={as:"text"};else W("PUBLICATION_ROUTE_INVALID","Route body pick is invalid.");return Object.freeze(r)}function r3(e){if(e===void 0)return;let t=Le(e,"PUBLICATION_ROUTE_INVALID","Route header mapping is invalid."),r={};for(let[i,n]of Object.entries(t)){if(typeof n!=="string"||n.length===0)W("PUBLICATION_ROUTE_INVALID","Route header pick is invalid.");r[i]=n}return Object.freeze(r)}function n3(e){if(e===void 0)return;let t=Le(e,"PUBLICATION_ROUTE_INVALID","Route mapping is invalid."),r={};for(let[i,n]of Object.entries(t)){if(typeof n!=="string"||n.length===0)W("PUBLICATION_ROUTE_INVALID","Route wire name is invalid.");r[i]=n}return Object.freeze(r)}function AP(e){let t=Le(e,"PUBLICATION_INVALID","Published schema is invalid.");if(Je(t,["revision","bundle"],"PUBLICATION_INVALID"),typeof t.revision!=="string"||!Y.patterns.revision.test(t.revision))W("PUBLICATION_INVALID","Published schema revision is invalid.");return Object.freeze({revision:t.revision,bundle:Oj(t.bundle)})}var oB="/.well-known/astrale/domain.json",TP="application/vnd.astrale.domain-publication+json;v=2";function NP(e){let t=LP(e),r;try{r=new URL(t)}catch(i){return W("PUBLICATION_INVALID","Publication issuer is not an HTTP(S) URL.",i)}if(r.protocol!=="https:"&&r.protocol!=="http:"||r.username!==""||r.password!==""||r.search!==""||r.hash!=="")W("PUBLICATION_INVALID","Publication issuer is not an HTTP(S) URL.");return`${t.replace(/\/+$/u,"")}${oB}`}function RP(e){return jP({...e,etag:uI(e)},!1)}function hs(e){let t=jP(e,!0);if(t.etag!==uI(o3(t)))W("PUBLICATION_ETAG_MISMATCH","Publication ETag does not match its canonical content.");return t}function dl(e){return te.encode(e)}function fl(e,t){let r=_j(t);return dI(e,Mr.encode(r)),PP(e,r),r}function sB(e,t){let r=kj(e,t);return PP(e,r),r}function jP(e,t){let r=Le(e,"PUBLICATION_INVALID","Expected a Publication object.");if(Je(r,["format","version","origin","identity","etag","schema","requirements","manifest","bindings","routes","delivery"],"PUBLICATION_INVALID"),r.format!=="astrale.domain.publication"||r.version!==2)W("PUBLICATION_INVALID","Unsupported Publication format or version.");if(typeof r.origin!=="string"||!Y.patterns.origin.test(r.origin))W("PUBLICATION_INVALID","Publication origin is invalid.");let i=r.origin,n=Le(r.identity,"PUBLICATION_INVALID","Publication identity is invalid.");Je(n,["issuer","subject"],"PUBLICATION_INVALID");let o=LP(n.issuer);if(n.subject!==i)W("PUBLICATION_INVALID","Publication identity subject must equal its root origin.");let s=AP(r.schema),a=po(r.requirements),c=Aj(r.manifest),u=Le(r.bindings,"PUBLICATION_BINDING_INVALID","Publication bindings are invalid.");Je(u,["callables","views"],"PUBLICATION_BINDING_INVALID");let l=Ga(u.callables,"PUBLICATION_BINDING_INVALID").map((h)=>aI(h,i));bi(l.map(({callable:h})=>h),"PUBLICATION_BINDING_INVALID","callable binding");let d=Ga(u.views,"PUBLICATION_VIEW_INVALID").map((h)=>cI(h,i));bi(d.map(({view:h})=>h),"PUBLICATION_VIEW_INVALID","View binding");let f=Ga(r.routes,"PUBLICATION_ROUTE_INVALID").map((h)=>SP(h,i));bi(f.map(({name:h})=>h),"PUBLICATION_ROUTE_INVALID","route name");for(let h of new Set(f.map(({callable:g})=>g)))if(f.filter((g)=>g.callable===h&&g.default===!0).length>1)W("PUBLICATION_ROUTE_INVALID",`Callable ${h} has more than one default route.`);if(c?.entrypoint!==void 0){let h=Z.of(i,c.entrypoint);if(!d.some(({view:g})=>g===h))W("PUBLICATION_VIEW_INVALID","Manifest entrypoint must have a published View binding.")}let m=Sj(r.delivery,s.bundle.href),B=t?Rm(r.etag):r.etag;if(typeof B!=="string")W("PUBLICATION_INVALID","Publication ETag is missing.");return Gn({format:"astrale.domain.publication",version:2,origin:i,identity:{issuer:o,subject:i},etag:B,schema:s,requirements:a,...c===void 0?{}:{manifest:c},bindings:{callables:l,views:d},routes:f,...m===void 0?{}:{delivery:m}})}function PP(e,t){let r=t.root;if(r.origin!==e.origin||Y.revision(r)!==e.schema.revision)W("PUBLICATION_INVALID","Bundle root does not match the Publication schema.");iB(r,t.closure,e.requirements);let i=i3(r),n=new Set(e.bindings.callables.map(({callable:a})=>a));if(n.size!==i.size||[...i].some((a)=>!n.has(a)))W("PUBLICATION_BINDING_INVALID","Callable bindings must exhaust the root Domain.");let o=new Set(Object.keys(r.views).map((a)=>Z.of(r.origin,ne.definition("view",a)))),s=new Set(e.bindings.views.map(({view:a})=>a));if(s.size!==o.size||[...o].some((a)=>!s.has(a)))W("PUBLICATION_VIEW_INVALID","View bindings must exhaust the root Domain.");if(e.manifest?.entrypoint!==void 0&&r.views[ne.member(e.manifest.entrypoint)]===void 0)W("PUBLICATION_INVALID","Manifest entrypoint does not exist in the root schema.");for(let a of e.routes)if(!i.has(a.callable))W("PUBLICATION_ROUTE_INVALID",`Route ${a.name} names an unknown callable.`)}function i3(e){let t=new Set;for(let r of Object.keys(e.functions))t.add(Z.of(e.origin,ne.definition("function",r)));return $P(t,e.origin,"class",e.classes),$P(t,e.origin,"interface",e.interfaces),t}function $P(e,t,r,i){for(let[n,o]of Object.entries(i)){if(o.family!=="node")continue;for(let[s,a]of Object.entries(o.methods)){if(a.inheritance==="abstract")continue;e.add(Z.of(t,ne.method(ne.definition(r,n),s)))}}}function LP(e){try{return ht.accept(String(e))}catch(t){if(t instanceof be)return W("PUBLICATION_INVALID","Publication issuer is invalid.",t);throw t}}function o3(e){let{etag:t,...r}=e;return r}var GO={};ze(GO,{ATTESTATION_MAX_BYTES:()=>cB,Error:()=>aB,NONCE_MAX_LENGTH:()=>Ka,NONCE_MIN_LENGTH:()=>Ja,PURPOSE:()=>pl,accept:()=>GP,acceptClaims:()=>UP,acceptRequest:()=>VP});class aB extends Error{code;name="DeliveryError";constructor(e,t,r){super(t,r);this.code=e}}function Nt(e,t,r){throw new aB(e,t,r===void 0?void 0:{cause:r})}var pl="astrale.domain.delivery.v1",Ja=16,Ka=256,cB=16384;function zP(e){if(typeof e!=="string"||e.length===0||new TextEncoder().encode(e).byteLength>cB)Nt("DELIVERY_INVALID","Delivery attestation is invalid.");return e}function UP(e){if(e===null||typeof e!=="object"||Array.isArray(e))Nt("DELIVERY_CLAIMS_INVALID","Expected delivery claims.");let t=e,r=["purpose","iss","sub","aud","nonce","etag","schemaRevision","exp"];if(Object.keys(t).some((o)=>!r.includes(o)))Nt("DELIVERY_CLAIMS_INVALID","Delivery claims contain unknown fields.");if(t.purpose!==pl||typeof t.sub!=="string"||t.sub.length===0||typeof t.nonce!=="string"||t.nonce.length<Ja||t.nonce.length>Ka||typeof t.exp!=="number"||!Number.isSafeInteger(t.exp))Nt("DELIVERY_CLAIMS_INVALID","Delivery claims are invalid.");let i=MP(t.iss),n=MP(t.aud);if(typeof t.etag!=="string"||!/^sha256:[0-9a-f]{64}$/u.test(t.etag))Nt("DELIVERY_CLAIMS_INVALID","Delivery claims ETag is invalid.");if(typeof t.schemaRevision!=="string"||!Y.patterns.revision.test(t.schemaRevision))Nt("DELIVERY_CLAIMS_INVALID","Schema revision is invalid.");return FP({purpose:pl,iss:i,sub:t.sub,aud:n,nonce:t.nonce,etag:t.etag,schemaRevision:t.schemaRevision,exp:t.exp})}function MP(e){try{return ht.accept(String(e))}catch(t){if(t instanceof be)return Nt("DELIVERY_CLAIMS_INVALID","Delivery claims issuer is invalid.",t);throw t}}function FP(e){if(e===null||typeof e!=="object"||Object.isFrozen(e))return e;for(let t of Object.values(e))FP(t);return Object.freeze(e)}function GP(e){if(e===null||typeof e!=="object"||Array.isArray(e))Nt("DELIVERY_INVALID","Expected a Delivery object.");let t=e,r=new Set(["format","version","publication","attestation"]);if(Object.keys(t).some((i)=>!r.has(i)))Nt("DELIVERY_INVALID","Delivery contains unknown fields.");if(t.format!=="astrale.domain.delivery"||t.version!==1)Nt("DELIVERY_INVALID","Unsupported Delivery format or version.");return HP({format:"astrale.domain.delivery",version:1,publication:hs(t.publication),attestation:zP(t.attestation)})}function HP(e){if(e===null||typeof e!=="object"||Object.isFrozen(e))return e;for(let t of Object.values(e))HP(t);return Object.freeze(e)}function VP(e){if(e===null||typeof e!=="object"||Array.isArray(e))Nt("DELIVERY_REQUEST_INVALID","Expected a Delivery request.");let t=["version","kernel","nonce","etag"],r={},i=Reflect.ownKeys(e);if(i.length!==t.length)Nt("DELIVERY_REQUEST_INVALID","Delivery request is invalid.");for(let o of i){if(typeof o!=="string"||!t.includes(o))Nt("DELIVERY_REQUEST_INVALID","Delivery request is invalid.");let s=Object.getOwnPropertyDescriptor(e,o);if(s===void 0||!s.enumerable||!("value"in s))Nt("DELIVERY_REQUEST_INVALID","Delivery request is invalid.");r[o]=s.value}if(t.some((o)=>!Object.hasOwn(r,o))||r.version!==1||typeof r.kernel!=="string"||typeof r.nonce!=="string"||r.nonce.length<Ja||r.nonce.length>Ka||typeof r.etag!=="string"||!/^sha256:[0-9a-f]{64}$/u.test(r.etag))Nt("DELIVERY_REQUEST_INVALID","Delivery request is invalid.");let n;try{n=ht.accept(r.kernel)}catch(o){if(o instanceof be)return Nt("DELIVERY_REQUEST_INVALID","Delivery request issuer is invalid.",o);throw o}return Object.freeze({version:1,kernel:n,nonce:r.nonce,etag:r.etag})}function uB(e){return Gn({origin:e.origin,identity:{...e.identity},revision:e.schema.revision,etag:e.etag})}function Za(e){let t=Le(e,"PUBLICATION_INVALID","Publication reference is invalid.");if(Je(t,["origin","identity","revision","etag"],"PUBLICATION_INVALID"),typeof t.origin!=="string"||!Y.patterns.origin.test(t.origin))W("PUBLICATION_INVALID","Publication reference origin is invalid.");let r=t.origin,i=Le(t.identity,"PUBLICATION_INVALID","Publication reference identity is invalid.");Je(i,["issuer","subject"],"PUBLICATION_INVALID");let n=s3(i.issuer);if(i.subject!==r)W("PUBLICATION_INVALID","Publication reference subject must equal its root origin.");if(typeof t.revision!=="string"||!Y.patterns.revision.test(t.revision))W("PUBLICATION_INVALID","Publication reference revision is invalid.");return Gn({origin:r,identity:{issuer:n,subject:r},revision:t.revision,etag:Rm(t.etag)})}function HO(e,t){if(e.origin!==t.origin)return"origin-drift";if(e.identity.issuer!==t.identity.issuer||e.identity.subject!==t.identity.subject)return"identity-drift";if(e.revision!==t.revision)return"schema-drift";return e.etag===t.etag?"exact":"same-schema"}function VO(e,t){return HO(uB(e),t)}function qP(e,t){return VO(e,t)==="exact"}function s3(e){if(typeof e!=="string")W("PUBLICATION_INVALID","Publication reference issuer is invalid.");try{return ht.accept(e)}catch(t){if(t instanceof be)return W("PUBLICATION_INVALID","Publication reference issuer is invalid.",t);throw t}}var a3=new Set(["endpoint","via"]),c3=new Set(["kind","publication","issuer"]),u3=new Set(["route","credential","trace"]),l3=new Set(["kind","requestId","invocation","redirect"]);function lB(e){let t=yt(e,"route");He(t,a3,"route"),We(t,["endpoint","via"],"route");try{let r=yt(t.via,"route.via");if(He(r,c3,"route.via"),We(r,["kind","publication","issuer"],"route.via"),r.kind!=="via")ue('route.via.kind must be "via"');return Object.freeze({endpoint:ss(t.endpoint),via:Object.freeze({kind:"via",publication:Za(r.publication),issuer:Bm(r.issuer,"route.via.issuer")})})}catch(r){if(r instanceof so)return ue(`route is invalid: ${r.message}`);throw r}}function JP(e,t,r){return lB({endpoint:t.endpoint,via:{kind:"via",publication:{origin:e,identity:{issuer:t.issuer,subject:t.subject},revision:t.revision,etag:t.etag},issuer:r}})}function qO(e){let t=yt(e,"redirection");He(t,u3,"redirection"),We(t,["route"],"redirection");let r=lB(t.route),i=t.credential===void 0?void 0:ro(t.credential,"redirection.credential"),n=t.trace===void 0?void 0:Ci(t.trace);if(i!==void 0&&i.length===0)ue("redirection.credential must be non-empty");return Object.freeze({route:r,...i===void 0?{}:{credential:i},...n===void 0?{}:{trace:n}})}function dB(e){let t=yt(e,"redirect response");if(He(t,l3,"redirect response"),We(t,["kind","requestId","invocation","redirect"],"redirect response"),t.kind!=="redirect")ue('redirect response.kind must be "redirect"');return Object.freeze({kind:"redirect",requestId:Tt(t.requestId,"redirect response.requestId"),invocation:Hr(t.invocation,"redirect response.invocation"),redirect:qO(t.redirect)})}var d3=new Set(["kind","publication","issuer"]),f3=new Set(["kind","stale"]);function fB(e){let t=yt(e,"routing");if(t.kind==="via"){He(t,d3,"via routing"),We(t,["kind","publication","issuer"],"via routing");try{return Object.freeze({kind:"via",publication:Za(t.publication),issuer:Bm(t.issuer,"via routing.issuer")})}catch(r){if(r instanceof so)return ue(`via routing.publication is invalid: ${r.message}`);throw r}}if(t.kind==="refresh")return He(t,f3,"refresh routing"),We(t,["kind","stale"],"refresh routing"),Object.freeze({kind:"refresh",stale:Pa(t.stale,"refresh routing.stale")});return ue('routing.kind must be "via" or "refresh"')}var p3=new Set(["target","revision"]);function pB(e){let t=yt(e,"schema target");He(t,p3,"schema target");let r=Object.hasOwn(t,"target"),i=Object.hasOwn(t,"revision");if(r===i)ue("schema target must contain exactly one of target or revision");if(r)return Object.freeze({target:Pa(t.target,"schema target.target")});if(typeof t.revision!=="string"||!Y.patterns.revision.test(t.revision))ue("schema target.revision must be a Schema revision");return Object.freeze({revision:t.revision})}var m3=new Set(["target","input"]);function mB(e){let t=yt(e,"call");return He(t,m3,"call"),We(t,["target","input"],"call"),Object.freeze({target:vR(t.target,"call.target"),input:t.input})}var B3=new Set(["version","requestId","call","credential","delegate","routing","schema","idempotencyKey","trace"]);function KP(e){let t=yt(e,"request");if(He(t,B3,"request"),We(t,["version","requestId","call"],"request"),t.version!==2)ue("request.version must be 2");let r=t.credential===void 0?void 0:ro(t.credential,"request.credential"),i=t.delegate===void 0?void 0:Tm(t.delegate),n=t.routing===void 0?void 0:fB(t.routing),o=t.schema===void 0?void 0:pB(t.schema),s=t.trace===void 0?void 0:Ci(t.trace);if(n?.kind==="via"){if(i!==void 0)ue("destination requests with via routing forbid delegate");if(o!==void 0)ue("destination requests with via routing forbid schema target")}else if(r===void 0!==(i===void 0))ue("source requests require credential and delegate together");return Object.freeze({version:2,requestId:Tt(t.requestId,"request.requestId"),call:mB(t.call),...r===void 0?{}:{credential:r},...i===void 0?{}:{delegate:i},...n===void 0?{}:{routing:n},...o===void 0?{}:{schema:o},...t.idempotencyKey===void 0?{}:{idempotencyKey:ym(t.idempotencyKey,"request.idempotencyKey")},...s===void 0?{}:{trace:s}})}var h3=new Set(["kind","requestId","invocation","current"]);function ml(e){let t=yt(e,"stale control");if(He(t,h3,"stale control"),We(t,["kind","requestId","invocation","current"],"stale control"),t.kind!=="stale")ue('stale control.kind must be "stale"');return Object.freeze({kind:"stale",requestId:Tt(t.requestId,"stale control.requestId"),invocation:Hr(t.invocation,"stale control.invocation"),current:Pa(t.current,"stale control.current")})}function ZP(e,t,r){return ml({kind:"stale",requestId:e,invocation:t,current:r})}var g3=new Set(["result","requestId","invocation"]),y3=new Set(["error","requestId","invocation"]);function WP(e){let t=yt(e,"response"),r=Object.hasOwn(t,"result"),i=Object.hasOwn(t,"error");if(r||i){if(r===i)ue("response must contain exactly one of result or error");if(r)return He(t,g3,"response"),We(t,["requestId","invocation"],"response"),Object.freeze({result:t.result,requestId:Tt(t.requestId,"response.requestId"),invocation:Hr(t.invocation,"response.invocation")});return He(t,y3,"response"),We(t,["requestId","error","invocation"],"response"),Object.freeze({error:hm(t.error,"response.error"),requestId:Tt(t.requestId,"response.requestId"),invocation:Hr(t.invocation,"response.invocation")})}if(t.kind==="redirect")return dB(t);if(t.kind==="stale")return ml(t);if(t.kind==="miss")return el(t);return ue("response must contain a result, error, redirect, stale, or miss control")}var KO="SCHEMA_UPGRADE_REQUIRED",ZO="SERVICE_TRUST_REQUIRED",WO="SERVICE_UNAVAILABLE",YO="SERVICE_CANDIDATE_INVALID";function QP(e){let t=mm(e.data);if(t===void 0)return;switch(t.code){case KO:return e.code===Ae.CONFLICT&&C3(t.details)?e:void 0;case ZO:return e.code===Ae.CONFLICT&&b3(t.details)?e:void 0;case WO:return e.code===Ae.BACKEND_UNAVAILABLE&&E3(t.details)?e:void 0;case YO:return e.code===Ae.BACKEND_UNAVAILABLE&&v3(t.details)?e:void 0;default:return}}function C3(e){return BB(e,["origin","installedRevision","candidateRevision"])&&hB(e.origin)&&JO(e.installedRevision)&&JO(e.candidateRevision)}function b3(e){return BB(e,["origin","installedIssuer","candidateIssuer"])&&hB(e.origin)&&YP(e.installedIssuer)&&YP(e.candidateIssuer)}function E3(e){return BB(e,["origin","revision"])&&hB(e.origin)&&JO(e.revision)}function v3(e){return BB(e,["origin"])&&hB(e.origin)}function BB(e,t){return Object.keys(e).length===t.length&&t.every((r)=>Object.hasOwn(e,r))}function hB(e){return typeof e==="string"&&Y.patterns.origin.test(e)}function JO(e){return typeof e==="string"&&Y.patterns.revision.test(e)}function YP(e){if(typeof e!=="string")return!1;try{return ht.accept(e)===e}catch(t){if(t instanceof be)return!1;throw t}}function XP(e){let t=yt(e,"stream frame"),r=t.kind;if(typeof r!=="string")ue("stream frame.kind must be a string");switch(r){case"stream.start":return He(t,new Set(["kind","requestId","invocation"]),"stream.start"),We(t,["requestId","invocation"],"stream.start"),Object.freeze({kind:r,requestId:Tt(t.requestId,"stream.start.requestId"),invocation:Hr(t.invocation,"stream.start.invocation")});case"stream.item":return He(t,new Set(["kind","requestId","index","value"]),"stream.item"),We(t,["requestId","index","value"],"stream.item"),Object.freeze({kind:r,requestId:Tt(t.requestId,"stream.item.requestId"),index:Tw(t.index,"stream.item.index"),value:t.value});case"stream.end":return He(t,new Set(["kind","requestId","count"]),"stream.end"),We(t,["requestId","count"],"stream.end"),Object.freeze({kind:r,requestId:Tt(t.requestId,"stream.end.requestId"),count:Tw(t.count,"stream.end.count")});case"stream.error":return He(t,new Set(["kind","requestId","error"]),"stream.error"),We(t,["requestId","error"],"stream.error"),Object.freeze({kind:r,requestId:Tt(t.requestId,"stream.error.requestId"),error:hm(t.error,"stream.error.error")});default:return ue(`unsupported stream frame kind ${JSON.stringify(r)}`)}}var eL=2;var tD={};ze(tD,{JSON_SUBPROTOCOL:()=>QO,MSGPACK_SUBPROTOCOL:()=>XO,decodeBinary:()=>nL,encodeBinary:()=>rL,selectSubprotocol:()=>iL,subprotocolFor:()=>eD});var Zn=new Uint8Array([65,83,84,66,1]),hl=4,tL=65536,x3=new TextEncoder,w3=new TextDecoder("utf-8",{fatal:!0});function rL(e){let t=e.headers===void 0?void 0:Object.fromEntries(Object.entries(e.headers).sort(([n],[o])=>n<o?-1:n>o?1:0)),r=x3.encode(JSON.stringify({kind:e.kind,requestId:e.requestId,invocation:e.invocation,mediaType:e.mediaType,...t===void 0?{}:{headers:t}}));if(r.byteLength>tL)Bl();let i=new Uint8Array(Zn.byteLength+hl+r.byteLength+e.body.byteLength);return i.set(Zn,0),new DataView(i.buffer).setUint32(Zn.byteLength,r.byteLength),i.set(r,Zn.byteLength+hl),i.set(e.body,Zn.byteLength+hl+r.byteLength),i}function nL(e){if(!I3(e))return;let t=Zn.byteLength+hl;if(e.byteLength<t)Bl();let r=new DataView(e.buffer,e.byteOffset+Zn.byteLength,hl).getUint32(0),i=t+r;if(r===0||r>tL||i>e.byteLength)Bl();let n;try{n=JSON.parse(w3.decode(e.subarray(t,i)))}catch(o){if(o instanceof SyntaxError||o instanceof TypeError)return Bl();throw o}if(typeof n!=="object"||n===null||Array.isArray(n))Bl();return gm({...n,body:e.slice(i)})}function I3(e){if(e.byteLength<Zn.byteLength)return!1;for(let t=0;t<Zn.byteLength;t+=1)if(e[t]!==Zn[t])return!1;return!0}function Bl(){throw new Fn({code:Ae.INVALID_REQUEST,message:"WebSocket binary response is invalid."})}var QO="astrale.invocation.v2.json",XO="astrale.invocation.v2.msgpack",O3=/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/u;function eD(e){let t=rI(e);if(t===void 0)throw TypeError("codec is not a canonical Invocation codec.");return t==="json"?QO:XO}function iL(e,t){let r=Xu(t);if(e===null||e.trim()==="")return;let i=e.split(",").map((o)=>o.trim()),n=new Set;for(let o of i){if(!O3.test(o)||n.has(o))return;n.add(o)}for(let o of i){let s=r.find((a)=>eD(a.codec)===o);if(s!==void 0)return Object.freeze({subprotocol:o,codec:s.codec})}return}var gl={};ze(gl,{installation:()=>iD});var iD={};ze(iD,{introspection:()=>nD});var nD={};ze(nD,{MEDIA_TYPE:()=>sL,decode:()=>cL,encode:()=>aL});var gB="application/vnd.astrale.domain-runtime+json;v=2";var sL="application/vnd.astrale.schema-introspection.v1+msgpack";async function aL(e,t){let r=uL(e),i=t===null?null:_3(r,t),{pack:n}=await Promise.resolve().then(() => (tI(),eI));return new Uint8Array(n(i))}async function cL(e,t,r){if(!(t instanceof Uint8Array))_t("Schema introspection evidence must be binary.");if(oL(r.maximumPublicationBytes,"Publication"),oL(r.maximumBundleBytes,"Bundle"),t.byteLength>r.maximumPublicationBytes+r.maximumBundleBytes+2048)_t("Schema introspection evidence exceeds its declared bounds.");let{unpack:i}=await Promise.resolve().then(() => (Ma(),Yw)),n;try{n=i(t)}catch(s){throw TypeError("Schema introspection evidence is malformed.",{cause:s})}if(n===null)return null;if(!rD(n))_t("Schema introspection result must be an object or null.");let o=uL(e);return Ya(n,o,"Schema introspection result"),k3(o,n,r)}function _3(e,t){Ya(t,e,"Schema introspection result");let r=e.includes("source")?S3(t.source):void 0,i={};for(let n of e)switch(n){case"state":i.state=dL(t.state);break;case"target":i.target=yB(t.target,"Installation target");break;case"source":i.source=r;break;case"bundle":i.bundle=$3(t.bundle,t.source);break;case"readiness":i.readiness=t.readiness===null?null:yB(t.readiness,"Installation readiness");break;case"capabilities":i.capabilities=lL(t.capabilities);break}return Object.freeze(i)}function k3(e,t,r){let i=e.includes("source")?A3(t.source,r):void 0,n={};for(let o of e)switch(o){case"state":n.state=dL(t.state);break;case"target":n.target=yB(t.target,"Installation target");break;case"source":n.source=i;break;case"bundle":n.bundle=T3(t.bundle,i,r.maximumBundleBytes);break;case"readiness":n.readiness=t.readiness===null?null:yB(t.readiness,"Installation readiness");break;case"capabilities":n.capabilities=lL(t.capabilities);break}if(n.state==="ready"&&Object.hasOwn(n,"readiness")&&n.readiness===null)_t("A ready Installation requires readiness evidence.");return Object.freeze(n)}function S3(e){if(e?.kind==="builtin")return Object.freeze({kind:"builtin",bundle:Wa(e.bundle,Kr,"Builtin schema Bundle")});if(e?.kind==="local")return Object.freeze({kind:"local",artifact:Wa(e.artifact,gB,"Local Runtime Artifact"),bundle:Wa(e.bundle,Kr,"Local schema Bundle")});if(e?.kind==="remote")return Object.freeze({kind:"remote",publication:dl(hs(e.publication))});return _t("Installation source is invalid.")}function A3(e,t){if(!rD(e))_t("Installation source is invalid.");if(e.kind==="builtin")return Ya(e,["bundle","kind"],"Builtin installation source"),Object.freeze({kind:"builtin",bundle:Wa(e.bundle,Kr,"Builtin schema Bundle")});if(e.kind==="local")return Ya(e,["artifact","bundle","kind"],"Local installation source"),Object.freeze({kind:"local",artifact:Wa(e.artifact,gB,"Local Runtime Artifact"),bundle:Wa(e.bundle,Kr,"Local schema Bundle")});if(e.kind==="remote"){Ya(e,["kind","publication"],"Remote installation source");let r=pL(e.publication,t.maximumPublicationBytes,"Publication"),i;try{i=hs(La.decode(r))}catch(n){throw TypeError("Remote installed Publication is invalid.",{cause:n})}if(!mL(r,dl(i)))_t("Remote installed Publication is not canonical.");return Object.freeze({kind:"remote",publication:i})}return _t("Installation source kind is invalid.")}function $3(e,t){if(t===void 0||e===void 0)_t("Bundle source evidence is missing.");let r=t.kind==="remote"?fl(t.publication,e):Mr.accept(e),i=Mr.encode(r);if(t.kind!=="remote"&&!fL(Ds(i,Kr),t.bundle))_t("Local schema Bundle does not match its source Ref.");return i}function T3(e,t,r){let i=pL(e,r,"Bundle"),n;try{n=t.kind==="remote"?sB(t.publication,i):Mr.decode(i)}catch(o){throw TypeError("Installed schema Bundle is invalid.",{cause:o})}if(!mL(i,Mr.encode(n)))_t("Installed schema Bundle is not canonical.");if(t.kind!=="remote"&&!fL(Ds(i,Kr),t.bundle))_t("Local schema Bundle does not match its source Ref.");return n}function uL(e){if(e===null||typeof e!=="object"||e.from?.kind!=="installation"||e.select===null||typeof e.select!=="object")_t("Schema introspection request is invalid.");let t=["state","target","source","bundle","readiness","capabilities"],r=Object.keys(e.select);if(r.length===0||r.some((i)=>!t.includes(i)||e.select[i]!==!0)||e.select.bundle===!0&&e.select.source!==!0)_t("Schema introspection selection is invalid.");return Object.freeze(t.filter((i)=>e.select[i]===!0))}function lL(e){if(!rD(e))_t("Installation capabilities are invalid.");Ya(e,["materialized","requested"],"Installation capabilities");try{let t=po({capabilities:e.requested}).capabilities,r=po({capabilities:e.materialized}).capabilities;return Object.freeze({requested:t,materialized:r})}catch(t){throw TypeError("Installation capabilities are invalid.",{cause:t})}}function dL(e){if(e!=="installed"&&e!=="ready"&&e!=="removing")_t("Installation state is invalid.");return e}function yB(e,t){if(typeof e!=="string"||!/^sha256:[0-9a-f]{64}$/u.test(e))_t(`${t} digest is invalid.`);return e}function Wa(e,t,r){let i;try{i=Os(e)}catch(n){throw TypeError(`${r} Ref is invalid.`,{cause:n})}if(i.mediaType!==t)_t(`${r} media type is invalid.`);return i}function fL(e,t){return e.digest===t.digest&&e.mediaType===t.mediaType&&e.size===t.size}function pL(e,t,r){if(!(e instanceof Uint8Array)||e.byteLength===0||e.byteLength>t)_t(`${r} evidence is invalid or exceeds its bound.`);return Uint8Array.from(e)}function oL(e,t){if(!Number.isSafeInteger(e)||e<1)_t(`${t} evidence bound is invalid.`)}function Ya(e,t,r){let i=Object.keys(e).sort(),n=[...t].sort();if(i.length!==n.length||i.some((o,s)=>o!==n[s]))_t(`${r} fields are invalid.`)}function mL(e,t){return e.byteLength===t.byteLength&&e.every((r,i)=>r===t[i])}function rD(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}function _t(e){throw TypeError(e)}class zt extends X{code;invocation;data;reason;constructor(e,t,r,i){super(t);this.code=e,this.invocation=r,this.data=i,this.name="ResponseError",this.reason=Ra.reasonOf(i)}}class Qa extends X{currentEtag;invocation;name="StaleRouteError";constructor(e,t){super("The destination Publication route is stale.");this.currentEtag=e,this.invocation=t}}class De extends X{phase;delivery;invocation;constructor(e,t){super(e,t);this.name="TransportError",this.phase=t.phase,this.delivery=t.delivery,this.invocation=t.invocation}}function Cl(e,t){let r=new AbortController,i=!1,n=()=>r.abort(e?.reason);if(e?.aborted)n();else e?.addEventListener("abort",n,{once:!0});let o=setTimeout(()=>{i=!0,r.abort(Error("request timeout"))},t);return{signal:r.signal,get timedOut(){return i},cancel:(s)=>r.abort(s),close:()=>{clearTimeout(o),e?.removeEventListener("abort",n)}}}function Gt(e,t){if(!Number.isSafeInteger(e)||e<1||e>2147483647)throw TypeError(`${t} must be a positive safe platform integer.`);return e}function br(e){if(!e.signal.aborted)return;throw e.signal.reason??Error("request was cancelled.")}function at(e){return e instanceof Error?e:Error(String(e))}async function vL(e){let r=sD(e)===Lt.CONTENT_TYPE_MSGPACK?[Lt.json,await Lt.loadMsgpack()]:[Lt.json];return me.http.codecForContentType(e,r)}async function oD(e,t,r){let i=e.headers.get("content-length");if(i!==null&&Number(i)>t)throw new pe(`response exceeds maximumResponseBytes (${t}).`);if(e.body===null)return new Uint8Array;let n=e.body.getReader(),o=[],s=0;try{while(!0){if(r.aborted)throw r.reason;let u=await n.read();if(u.done)break;if(s+=u.value.byteLength,s>t)throw new pe(`response exceeds maximumResponseBytes (${t}).`);o.push(u.value)}}catch(u){throw await n.cancel(u).catch(()=>{return}),u}let a=new Uint8Array(s),c=0;for(let u of o)a.set(u,c),c+=u.byteLength;return a}function CB(e,t){if(t!==e)throw new pe(`response id ${JSON.stringify(t)} does not match request id ${JSON.stringify(e)}.`)}function In(e,t){try{return t()}catch(r){if(r instanceof zt||r instanceof pe)throw r;throw new pe(`server returned an invalid ${e}.`,{cause:at(r)})}}function sD(e){if(e===null)return;let t=e.split(";",1)[0]?.trim().toLowerCase();return t===""?void 0:t}function xL(e,t){let r={};for(let i of t){let n=e.get(i);if(n===null)throw new pe(`server omitted declared binary application header ${i}.`);r[i]=n}return Object.freeze(r)}class bB{frames;codec;requestId;control;invocation;claimed=!1;terminal=!1;index=0;interruption;constructor(e,t,r,i){this.frames=e,this.codec=t,this.requestId=r,this.control=i;let n=()=>void this.interrupt(this.abortFailure(i.signal.reason));if(i.signal.aborted)n();else i.signal.addEventListener("abort",n,{once:!0})}static async open(e,t,r,i,n){if(e.body===null)throw new pe("stream has no body.");let o=new bB(new wL(e.body.getReader(),i),t,r,n),s=await o.readFrame();if(s===null||s.kind!=="stream.start")throw await o.stop("invalid stream start"),new pe("stream did not begin with stream.start.");return o.invocation=s.invocation,o}[Symbol.asyncIterator](){if(this.claimed)throw TypeError("streams admit exactly one consumer.");return this.claimed=!0,{next:()=>this.next(),return:async()=>(await this.cancel("stream consumer stopped"),{done:!0,value:void 0}),throw:async(e)=>{throw await this.cancel("stream consumer failed"),e}}}async cancel(e="stream cancelled"){await this.stop(e)}async next(){if(this.interruption!==void 0)throw this.interruption;if(this.terminal)return{done:!0,value:void 0};try{let e=await this.readFrame();if(e===null)throw new pe("stream ended without a terminal frame.");if(e.kind==="stream.item"){if(e.index!==this.index)throw new pe(`stream item ${e.index} does not match expected index ${this.index}.`);return this.index+=1,{done:!1,value:e.value}}if(e.kind==="stream.error")throw await this.finish(),new zt(e.error.code,e.error.message,this.invocation,e.error.data);if(e.kind!=="stream.end")throw new pe(`Unexpected ${e.kind} frame inside stream.`);if(e.count!==this.index)throw new pe(`stream ended with count ${e.count}; ${this.index} items were received.`);return await this.finish(),{done:!0,value:void 0}}catch(e){let t=this.interruption??J3(e,this.invocation);throw await this.stop(t),t}}async readFrame(){let e=await this.frames.read();if(this.interruption!==void 0)throw this.interruption;if(e===null)return null;let t=In("stream frame",()=>me.decodeStreamFrame(this.codec.decode(e)));return CB(this.requestId,t.requestId),t}async finish(){if(this.terminal)return;await this.frames.requireEnd(),this.terminal=!0,this.control.close()}async interrupt(e){if(this.terminal||this.interruption!==void 0)return;this.interruption=e,await this.frames.cancel(e),this.control.close()}async stop(e){if(this.terminal)return;this.terminal=!0,this.control.cancel(e),await this.frames.cancel(e),this.control.close()}abortFailure(e){if(this.control.timedOut)return new De("stream exceeded its invocation timeout.",{cause:at(e),phase:"timeout",delivery:"unknown",invocation:this.invocation});return at(e??Error("stream was cancelled."))}}function J3(e,t){if(e instanceof pe&&e.invocation===void 0)return new pe(e.message,{cause:e,invocation:t});if(e instanceof De&&e.invocation===void 0)return new De(e.message,{cause:e,phase:e.phase,delivery:e.delivery,invocation:t});return e}class wL{reader;maximumFrameBytes;chunk=new Uint8Array;offset=0;done=!1;constructor(e,t){this.reader=e,this.maximumFrameBytes=t}async read(){let e=await this.take(4,!0);if(e===null)return null;let t=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(0);if(t>this.maximumFrameBytes)throw new pe(`stream frame exceeds maximumResponseBytes (${this.maximumFrameBytes}).`);return await this.take(t,!1)}async requireEnd(){if(await this.take(1,!0)!==null)throw new pe("stream contains data after its terminal frame.")}async cancel(e){try{await this.reader.cancel(e)}catch{}}async take(e,t){let r=new Uint8Array(e),i=0;while(i<e){if(this.offset===this.chunk.byteLength){if(this.done){if(t&&i===0)return null;throw new pe("stream ended in the middle of a frame.")}let s=await this.reader.read();if(s.done){this.done=!0;continue}if(this.chunk=s.value,this.offset=0,this.chunk.byteLength===0)continue}let n=this.chunk.byteLength-this.offset,o=Math.min(n,e-i);r.set(this.chunk.subarray(this.offset,this.offset+o),i),i+=o,this.offset+=o}return r}}var K3=30000,Z3=16777216,W3=16777216;class xi{url;codecName;fetchImpl;headers;timeoutMs;maximumRequestBytes;maximumResponseBytes;nextId=1;constructor(e){if(e===null||typeof e!=="object")throw TypeError("HttpTransport options must be an object.");this.url=Q3(e.url),this.codecName=i8(e.codec),this.fetchImpl=o8(e.fetch),this.headers=X3(e.headers??{}),this.timeoutMs=Gt(e.timeoutMs??K3,"timeoutMs"),this.maximumRequestBytes=Gt(e.maximumRequestBytes??Z3,"maximumRequestBytes"),this.maximumResponseBytes=Gt(e.maximumResponseBytes??W3,"maximumResponseBytes")}async dispatch(e,t={}){let r=this.nextRequestId(),i=Gt(t.timeoutMs??this.timeoutMs,"timeoutMs"),n=await this.requestCodec(),{trace:o,...s}=e,a=o===void 0?void 0:me.admitTrace(o),c=me.decodeRequest({version:me.VERSION,requestId:r,...s,...t.idempotencyKey===void 0?{}:{idempotencyKey:t.idempotencyKey}}),u=n.encode(c),l=Cl(t.signal,i),d=!1,f="connect",m="not-sent";try{if(br(l),t8(u)>this.maximumRequestBytes)throw new De(`request exceeds maximumRequestBytes (${this.maximumRequestBytes}).`,{phase:"send",delivery:"not-sent"});f="send",m="unknown";let B=await this.fetchResponse(n,u,a,l);if(f="receive",br(l),B.status>=300&&B.status<400)throw new pe("server returned a network redirect.");r8(B);let h=B.headers.get(me.http.STREAM_FRAMING_FIELD),g=B.headers.get(me.http.REQUEST_ID_FIELD),w=B.headers.get(me.http.BINARY_HEADERS_FIELD),b=h!==null,O=g!==null||w!==null;if(b&&O)throw new pe("server returned conflicting stream and binary response signals.");if(O){if(g===null||w===null)throw new pe("server returned an incomplete binary response signal.");return await this.decodeBinary(B,r,g,l)}let k=await vL(B.headers.get("content-type"));if(k===void 0)throw new pe(`server returned unsupported Content-Type ${JSON.stringify(B.headers.get("content-type"))}.`);if(b){if(h!==me.http.LENGTH_PREFIX_V1)throw new pe(`server returned unsupported stream framing ${JSON.stringify(h)}.`);if(!B.ok)throw new pe("server returned a non-success stream response.");let _e=await bB.open(B,k,r,this.maximumResponseBytes,l);return br(l),d=!0,{kind:"stream",stream:_e,invocation:_e.invocation}}let G=await oD(B,this.maximumResponseBytes,l.signal);br(l);let oe=In("response body",()=>k.decode(G)),V=In("response envelope",()=>me.decodeResponse(oe));if(V.requestId===null&&"error"in V)throw new zt(V.error.code,V.error.message,V.invocation,V.error.data);if(CB(r,V.requestId),"kind"in V&&V.kind==="stale"){let _e=In("stale response",()=>me.decodeStale(V));return br(l),Object.freeze({kind:"stale",current:_e.current,invocation:_e.invocation})}if("kind"in V&&V.kind==="miss")return In("miss response",()=>me.decodeMiss(V)),br(l),Object.freeze({kind:"miss",invocation:V.invocation});if("kind"in V&&V.kind==="redirect"){let _e=In("redirect response",()=>me.decodeRedirectResponse(V));return br(l),Y3(_e)}if("error"in V)throw new zt(V.error.code,V.error.message,V.invocation,V.error.data);return br(l),{kind:"value",value:V.result,invocation:V.invocation}}catch(B){throw n8(B,l,t.signal,i,this.url,f,m)}finally{if(!d)l.close()}}async fetchResponse(e,t,r,i){return this.fetchImpl(this.url,{method:"POST",redirect:"error",credentials:"omit",cache:"no-store",referrerPolicy:"no-referrer",headers:{...this.headers,...me.http.encodeTraceHeaders(r),"content-type":e.contentType,accept:e.contentType},body:e8(t),signal:i.signal})}async decodeBinary(e,t,r,i){if(!e.ok)throw new pe("server returned binary data with an error status.");if(r!==String(t))throw new pe(`binary response requestId ${JSON.stringify(r)} does not match request requestId ${t}.`);let n=sD(e.headers.get("content-type"));if(n===void 0)throw new pe("binary response has no media type.");let o=await oD(e,this.maximumResponseBytes,i.signal);br(i);let s=In("binary application-header manifest",()=>me.http.decodeBinaryHeaderNames(e.headers.get(me.http.BINARY_HEADERS_FIELD))),a=xL(e.headers,s),c=In("binary InvocationId field",()=>me.http.decodeInvocationId(e.headers.get(me.http.INVOCATION_FIELD))),u=In("binary response",()=>me.decodeBinaryResponse({kind:"binary",requestId:t,invocation:c,body:o,mediaType:n,...Object.keys(a).length===0?{}:{headers:a}}));return br(i),{kind:"binary",invocation:u.invocation,value:{body:u.body,mediaType:u.mediaType,...u.headers===void 0?{}:{headers:u.headers}}}}nextRequestId(){let e=this.nextId;return this.nextId=e===Number.MAX_SAFE_INTEGER?1:e+1,e}requestCodec(){return this.codecName==="msgpack"?Lt.loadMsgpack():Promise.resolve(Lt.json)}}function Y3(e){return Object.freeze({kind:"redirect",invocation:e.invocation,redirect:e.redirect})}function Q3(e){if(typeof e!=="string")throw TypeError("server URL must be a string.");let t;try{t=new URL(e)}catch(r){throw TypeError(`Invalid server URL ${JSON.stringify(e)}.`,{cause:at(r)})}if(t.protocol!=="http:"&&t.protocol!=="https:")throw TypeError("server URL must use http or https.");if(t.username!==""||t.password!==""||t.hash!=="")throw TypeError("server URL cannot contain credentials or a fragment.");return t.toString()}function X3(e){if(e===null||typeof e!=="object"||Array.isArray(e))throw TypeError("HTTP headers must be an object.");let t={};for(let[r,i]of Object.entries(e)){if(!s8.test(r))throw TypeError(`HTTP header name ${JSON.stringify(r)} is invalid.`);let n=r.toLowerCase();if(Object.hasOwn(t,n))throw TypeError(`HTTP header ${JSON.stringify(r)} occurs more than once.`);if(c8(n))throw TypeError(`HTTP header ${JSON.stringify(r)} is owned by transport.`);if(typeof i!=="string")throw TypeError(`HTTP header ${JSON.stringify(r)} must be a string.`);if(u8(i))throw TypeError(`HTTP header ${JSON.stringify(r)} contains a control character.`);t[n]=i}return Object.freeze(t)}function e8(e){if(typeof e==="string")return e;return new Uint8Array(e).buffer}function t8(e){return typeof e==="string"?new TextEncoder().encode(e).byteLength:e.byteLength}function r8(e){if(!(e.headers.get("cache-control")?.split(",").map((r)=>r.trim().toLowerCase())??[]).includes("no-store"))throw new pe("server response is missing Cache-Control: no-store.")}function n8(e,t,r,i,n,o,s){if(e instanceof zt||e instanceof pe)return e;if(t.timedOut)return new De(`request timed out after ${i}ms.`,{cause:at(e),phase:"timeout",delivery:s});if(r?.aborted)return at(r.reason??e);return e instanceof De?e:new De(`Failed to communicate with the server at ${n}.`,{cause:at(e),phase:o,delivery:s})}function i8(e){if(e===void 0||e==="json")return"json";if(e==="msgpack")return e;throw TypeError('codec must be "json" or "msgpack".')}function o8(e){let t=e??globalThis.fetch;if(typeof t!=="function")throw TypeError("HttpTransport requires a Fetch implementation.");return e===void 0?t.bind(globalThis):t}var s8=/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/,a8=new Set(["accept","accept-encoding","authorization","cache-control","connection","content-length","content-type","cookie","expect","forwarded","host","keep-alive","origin","pragma","proxy-authenticate","proxy-authorization","referer","referrer-policy","set-cookie","te",me.http.TRACEPARENT_FIELD,me.http.TRACESTATE_FIELD,me.http.BAGGAGE_FIELD,"trailer","transfer-encoding","upgrade","via"]);function c8(e){return a8.has(e)||e.startsWith("access-control-")||e.startsWith("content-")||e.startsWith("proxy-")||e.startsWith("sec-websocket-")||e.startsWith("x-astrale-")||e.startsWith("x-forwarded-")}function u8(e){for(let t=0;t<e.length;t+=1){let r=e.charCodeAt(t);if(r<=31||r===127)return!0}return!1}async function EB(e){let t=await e;if(t.kind!=="value")return OL("value",t);return t}async function vB(e){let t=await e;if(t.kind!=="stream")IL("stream",t.kind);return t}async function xB(e){let t=await e;if(t.kind!=="binary")return OL("binary",t);return t}function IL(e,t){throw new X(`Function returned ${t}; ${e} was required.`)}async function OL(e,t){if(t.kind==="stream")await t.stream.cancel(`Expected ${e} Function result.`).catch(()=>{return});IL(e,t.kind)}function DL(e,t){let r=(i,n)=>e(t,i,n);return Object.freeze({dispatch:r,call:(i,n)=>EB(r(i,n)),stream:(i,n)=>vB(r(i,n)),binary:(i,n)=>xB(r(i,n))})}async function _L(e,t){d8(t);let r=Promise.resolve(typeof e==="function"?e():e),i=await l8(r,t);if(typeof i!=="string"||i.length===0)throw TypeError("Remote credentials must be non-empty strings.");return i}function l8(e,t){if(t===void 0)return e;return new Promise((r,i)=>{let n=()=>{t.removeEventListener("abort",n),i(kL(t.reason))};if(t.addEventListener("abort",n,{once:!0}),t.aborted){n();return}e.then((o)=>{t.removeEventListener("abort",n),r(o)},(o)=>{t.removeEventListener("abort",n),i(o)})})}function d8(e){if(e?.aborted===!0)throw kL(e.reason)}function kL(e){return e instanceof Error?e:new X("Client request was cancelled.",{cause:e})}function bl(e){if(e===null||typeof e!=="object"||Array.isArray(e))throw TypeError("Client call must be an object.");return Object.freeze({target:f8(e.target),input:p8(e.input)})}function f8(e){try{return q.parse(typeof e==="string"?e:e.raw).raw}catch(t){throw TypeError("Client call path must be a NodePath.",{cause:t})}}function p8(e){try{return SL(se(e))}catch(t){throw TypeError("Client input must be a portable Value.",{cause:t})}}function SL(e){if(e!==null&&typeof e==="object"&&!Object.isFrozen(e)){for(let t of Object.values(e))SL(t);Object.freeze(e)}return e}function tr(e,t){return Object.freeze({target:e,input:t})}function AL(e,t,r){let i=bl(e),n=y8(m8(t),r),o=B8(t?.delegate),s=h8(t?.routing),a=g8(t?.schema);return Object.freeze({call:i,...o===void 0?{}:{delegate:o},...s===void 0?{}:{routing:s},...a===void 0?{}:{schema:a},options:n})}function $L(e,t,r){let i=r===void 0?void 0:me.admitTrace(r);if(e.routing?.kind==="via"){if(e.delegate!==void 0)throw TypeError("Destination Client requests cannot carry a delegation request.");if(e.schema!==void 0)throw TypeError("Destination Client requests cannot carry a Schema target.")}else if(t===void 0!==(e.delegate===void 0))throw TypeError("Source Client credentials and delegation requests must occur together.");return Object.freeze({call:e.call,...t===void 0?{}:{credential:t},...e.delegate===void 0?{}:{delegate:e.delegate},...e.routing===void 0?{}:{routing:e.routing},...e.schema===void 0?{}:{schema:e.schema},...i===void 0?{}:{trace:i}})}function m8(e){if(e===void 0)return;if(e===null||typeof e!=="object"||Array.isArray(e))throw TypeError("Client request options must be an object.");if(e.timeoutMs!==void 0&&(!Number.isSafeInteger(e.timeoutMs)||e.timeoutMs<1||e.timeoutMs>2147483647))throw TypeError("Client request timeoutMs must be a positive safe platform integer.");let t=e.idempotencyKey===void 0?void 0:me.acceptIdempotencyKey(e.idempotencyKey,"request.idempotencyKey");return Object.freeze({...e.signal===void 0?{}:{signal:e.signal},...e.timeoutMs===void 0?{}:{timeoutMs:e.timeoutMs},...t===void 0?{}:{idempotencyKey:t}})}function B8(e){if(e===void 0)return;try{return me.acceptDelegate(e)}catch(t){throw TypeError("Client delegation request is invalid.",{cause:t})}}function h8(e){if(e===void 0)return;try{return me.acceptRouting(e)}catch(t){throw TypeError("Client routing context is invalid.",{cause:t})}}function g8(e){if(e===void 0)return;try{return me.acceptSchemaTarget(e)}catch(t){throw TypeError("Client Schema target is invalid.",{cause:t})}}function y8(e,t){let r=e?.signal===void 0?t:AbortSignal.any([e.signal,t]);return Object.freeze({signal:r,...e?.timeoutMs===void 0?{}:{timeoutMs:e.timeoutMs},...e?.idempotencyKey===void 0?{}:{idempotencyKey:e.idempotencyKey}})}var TL=new WeakSet,NL=new WeakSet;function RL(e){let t=new ws(e);return TL.add(t),t}function jL(e,t){let r=new Qa(e,t);return NL.add(r),r}function aD(e){return e instanceof ws&&TL.has(e)}function cD(e){return e instanceof Qa&&NL.has(e)}var PL=new WeakMap;function uD(e,t,r,i,n){let o=PL.get(e);if(o===void 0)throw TypeError("Trace dispatch requires an owned Client.");return o(t,r,i,n)}class gs{transport;lifecycle=new AbortController;closed=!1;constructor(e){if(e===null||typeof e!=="object")throw TypeError("Client options must be an object.");this.transport=Object.hasOwn(e,"transport")?b8(e.transport):new xi(e),PL.set(this,(t,r,i,n)=>this.dispatchWith(t,r,i,n))}dispatch(e,t){return this.dispatchWith(void 0,e,t)}call(e,t){return EB(this.dispatch(e,t))}stream(e,t){return vB(this.dispatch(e,t))}binary(e,t){return xB(this.dispatch(e,t))}as(e){return DL((t,r,i)=>this.dispatchWith(t,r,i),e)}close(){if(this.closed)return;this.closed=!0;let e=new X("Client is closed.");this.lifecycle.abort(e),this.transport.close?.()}async dispatchWith(e,t,r,i){if(this.closed)throw new X("Client is closed.");let n=AL(t,r,this.lifecycle.signal),o=e===void 0?void 0:await _L(e,n.options.signal);C8(n.options.signal);let s=await this.transport.dispatch($L(n,o,i),n.options);if(s.kind==="stale")throw jL(s.current,s.invocation);if(s.kind==="miss")throw RL(s.invocation);return s}}function C8(e){if(e?.aborted!==!0)return;let t=e.reason;throw t instanceof Error?t:new X("Client request was cancelled.",{cause:t})}function b8(e){if(e===null||typeof e!=="object")throw TypeError("Client transport must be an object.");let t=e.dispatch;if(typeof t!=="function")throw TypeError("Client transport must implement dispatch().");let r=e.close;if(r!==void 0&&typeof r!=="function")throw TypeError("Client transport close capability is invalid.");return Object.freeze({dispatch:t.bind(e),...r===void 0?{}:{close:r.bind(e)}})}class lD{owner;requestId;control;maximumBufferedItems;result;resolveResult;rejectResult;abort;state="response";claimed=!1;index=0;values=[];waiters=[];terminal;sent=!1;invocation;constructor(e,t,r,i){if(this.owner=e,this.requestId=t,this.control=r,this.maximumBufferedItems=i,this.result=new Promise((n,o)=>{this.resolveResult=n,this.rejectResult=o}),this.abort=()=>this.cancelLocally(this.abortFailure()),!r.signal.aborted)r.signal.addEventListener("abort",this.abort,{once:!0})}start(e,t){if(this.state==="finished")return this.result;if(this.control.signal.aborted)return this.abort(),this.result;try{e(t),this.sent=!0}catch(r){this.fail(new De("Failed to send the WebSocket invocation.",{cause:at(r),phase:"send",delivery:"not-sent"}),1011)}return this.result}receive(e){try{if(this.state==="response"){this.receiveResponse(e);return}if(this.state!=="stream"||Xa(e,"binary"))throw new pe("server sent an unexpected WebSocket response.");this.receiveStreamFrame(e)}catch(t){let r=E8(t,this.invocation);this.fail(r,r instanceof El?1008:1002)}}connectionFailed(e){this.fail(this.sent?new De(e.message,{cause:e,phase:"receive",delivery:"unknown",...this.invocation===void 0?{}:{invocation:this.invocation}}):e)}[Symbol.asyncIterator](){if(this.claimed)throw TypeError("streams admit exactly one consumer.");return this.claimed=!0,{next:()=>this.next(),return:async()=>(await this.cancel("stream consumer stopped"),{done:!0,value:void 0}),throw:async(e)=>{throw await this.cancel("stream consumer failed"),e}}}async cancel(e="stream cancelled"){if(this.state==="finished")return;this.values.length=0,this.terminal=!0,this.finishCancelled(),this.flushTerminal()}receiveResponse(e){if(Xa(e,"binary")){let r=e;ys(this.requestId,r.requestId),this.complete({kind:"binary",invocation:r.invocation,value:{body:r.body,mediaType:r.mediaType,...r.headers===void 0?{}:{headers:r.headers}}});return}if(Xa(e,"stream.start")){let r=e;if(ys(this.requestId,r.requestId),r.kind!=="stream.start")throw new pe("stream did not begin with stream.start.");this.state="stream",this.invocation=r.invocation,this.resolveResult({kind:"stream",stream:this,invocation:r.invocation});return}if(Xa(e,"redirect")){let r=e;ys(this.requestId,r.requestId),this.complete({kind:"redirect",invocation:r.invocation,redirect:r.redirect});return}if(Xa(e,"stale")){let r=e;ys(this.requestId,r.requestId),this.complete(Object.freeze({kind:"stale",current:r.current,invocation:r.invocation}));return}if(Xa(e,"miss")){let r=e;ys(this.requestId,r.requestId),this.complete(Object.freeze({kind:"miss",invocation:r.invocation}));return}let t=e;if(ys(this.requestId,t.requestId),"error"in t){this.reject(new zt(t.error.code,t.error.message,t.invocation,t.error.data));return}this.complete({kind:"value",value:t.result,invocation:t.invocation})}receiveStreamFrame(e){if(ys(this.requestId,e.requestId),e.kind==="stream.start")throw new pe("server sent a duplicate stream.start frame.");if(e.kind==="stream.item"){if(e.index!==this.index)throw new pe(`stream item ${e.index} does not match expected index ${this.index}.`);this.index+=1;let t=this.waiters.shift();if(t!==void 0)t.resolve({done:!1,value:e.value});else{if(this.values.length>=this.maximumBufferedItems)throw new El(`stream exceeds maximumBufferedStreamItems (${this.maximumBufferedItems}).`);this.values.push(e.value)}return}if(e.kind==="stream.end"&&e.count!==this.index)throw new pe(`stream ended with count ${e.count}; ${this.index} items were received.`);this.terminal=e.kind==="stream.error"?new zt(e.error.code,e.error.message,this.invocation,e.error.data):!0,this.finish(!0),this.flushTerminal()}next(){let e=this.values.shift();if(e!==void 0)return Promise.resolve({done:!1,value:e});if(this.terminal===!0)return Promise.resolve({done:!0,value:void 0});if(this.terminal instanceof Error)return Promise.reject(this.terminal);return new Promise((t,r)=>this.waiters.push({resolve:t,reject:r}))}complete(e){this.finish(!0),this.resolveResult(e)}reject(e){this.finish(!0),this.rejectResult(e)}fail(e,t=1002){if(this.state==="finished")return;if(this.state==="response")this.rejectResult(e);else this.terminal=e,this.flushTerminal();this.finish(!1,t)}cancelLocally(e){if(this.state==="finished")return;if(this.state==="response")this.rejectResult(e);else this.values.length=0,this.terminal=e,this.flushTerminal();this.finishCancelled()}finish(e,t){if(this.state==="finished")return;this.state="finished",this.control.signal.removeEventListener("abort",this.abort),this.control.close(),this.owner.finish(this,e,t)}finishCancelled(){if(this.state==="finished")return;this.state="finished",this.control.signal.removeEventListener("abort",this.abort),this.control.close(),this.owner.cancel(this,this.requestId)}flushTerminal(){if(this.terminal===void 0)return;for(let e of this.waiters.splice(0))if(this.terminal===!0)e.resolve({done:!0,value:void 0});else e.reject(this.terminal)}abortFailure(){if(this.control.timedOut)return new De("WebSocket invocation exceeded its timeout.",{cause:at(this.control.signal.reason),phase:"timeout",delivery:this.sent?"unknown":"not-sent",...this.invocation===void 0?{}:{invocation:this.invocation}});return at(this.control.signal.reason??Error("WebSocket invocation was cancelled."))}}class El extends pe{}function E8(e,t){if(e instanceof zt)return e;if(e instanceof El)return e.invocation!==void 0||t===void 0?e:new El(e.message,{cause:e,invocation:t});if(e instanceof pe)return e.invocation!==void 0||t===void 0?e:new pe(e.message,{cause:e,invocation:t});if(e instanceof Ra.ProtocolError)return new pe(e.message,{cause:e,invocation:t});return new pe("server returned an invalid WebSocket frame.",{cause:at(e),invocation:t})}function ys(e,t){if(t!==e)throw new pe(`response requestId ${JSON.stringify(t)} does not match request requestId ${JSON.stringify(e)}.`)}function Xa(e,t){return typeof e==="object"&&e!==null&&!Array.isArray(e)&&e.kind===t}var v8=0,LL=1;class pD{owner;codec;maximumRequestBytes;maximumResponseBytes;maximumBufferedBytes;maximumActiveInvocations;socket;ready;resolveReady;rejectReady;opened=!1;closedState=!1;active=new Map;cancelled=new Set;incoming=Promise.resolve();constructor(e,t,r,i,n,o,s,a){this.owner=e,this.codec=i,this.maximumRequestBytes=n,this.maximumResponseBytes=o,this.maximumBufferedBytes=s,this.maximumActiveInvocations=a,this.ready=new Promise((c,u)=>{this.resolveReady=c,this.rejectReady=u}),this.socket=new t(r,me.websocket.subprotocolFor(i)),this.socket.binaryType="arraybuffer",this.socket.addEventListener("open",()=>this.onOpen(),{once:!0}),this.socket.addEventListener("message",(c)=>this.onMessage(c)),this.socket.addEventListener("error",()=>this.onFailure("WebSocket connection failed.")),this.socket.addEventListener("close",()=>this.onFailure("WebSocket connection closed."))}get isOpen(){return!this.closedState&&this.opened&&this.socket.readyState===LL}get isAvailable(){return!this.closedState}async connect(e){if(e.signal.aborted)throw at(e.signal.reason);let t,r=new Promise((i,n)=>{t=()=>n(at(e.signal.reason)),e.signal.addEventListener("abort",t,{once:!0})});try{await Promise.race([this.ready,r])}finally{e.signal.removeEventListener("abort",t)}}dispatch(e,t,r){if(!this.isOpen)return t.close(),Promise.reject(new De("WebSocket connection is not available.",{phase:"connect",delivery:"not-sent"}));let i=fD(e.requestId);if(this.active.has(i)||this.cancelled.has(i))return t.close(),Promise.reject(new pe("WebSocket request ID is already in use."));if(this.active.size+this.cancelled.size>=this.maximumActiveInvocations)return t.close(),Promise.reject(new De(`WebSocket connection exceeds maximumActiveInvocations (${this.maximumActiveInvocations}).`,{phase:"send",delivery:"not-sent"}));let n=this.codec.encode(e),o=dD(n);if(o>this.maximumRequestBytes)return t.close(),Promise.reject(new De(`WebSocket request exceeds maximumRequestBytes (${this.maximumRequestBytes}).`,{phase:"send",delivery:"not-sent"}));if(this.socket.bufferedAmount+o>this.maximumBufferedBytes)return t.close(),Promise.reject(new De(`WebSocket connection exceeds maximumBufferedBytes (${this.maximumBufferedBytes}).`,{phase:"send",delivery:"not-sent"}));let s=new lD(this,e.requestId,t,r);return this.active.set(i,s),s.start((a)=>this.socket.send(zL(a)),n)}finish(e,t,r=1002){if(k8(this.active,e),!t)this.shutdown(new De("WebSocket connection was closed after a binding failure.",{phase:"receive",delivery:"not-sent"}),r,O8(r))}cancel(e,t){let r=fD(t);if(this.active.get(r)!==e)return;this.active.delete(r),this.cancelled.add(r);try{let i=this.codec.encode(me.decodeCancelRequest({version:me.VERSION,kind:"cancel",requestId:t})),n=dD(i);if(n>this.maximumRequestBytes||this.socket.bufferedAmount+n>this.maximumBufferedBytes)throw new wi("WebSocket cancellation exceeds the connection send policy.",1008,"Client send policy exceeded");this.socket.send(zL(i))}catch(i){this.shutdown(new De("Failed to send WebSocket cancellation.",{cause:at(i),phase:"send",delivery:"unknown"}),i instanceof wi?i.closeCode:1011,i instanceof wi?i.closeReason:"Client send failed")}}shutdown(e=new De("WebSocket connection was closed.",{phase:"closed",delivery:"not-sent"}),t=1000,r="Client closed"){if(this.closedState)return;this.closedState=!0,this.rejectReady(e);let i=[...this.active.values()];this.active.clear(),this.cancelled.clear();for(let n of i)n.connectionFailed(e);try{if(this.socket.readyState===v8||this.socket.readyState===LL)this.socket.close(t,r)}catch{}this.owner.closed(this)}onOpen(){if(this.closedState)return;let e=me.websocket.subprotocolFor(this.codec);if(this.socket.protocol!==e){this.shutdown(new De(`server selected WebSocket subprotocol ${JSON.stringify(this.socket.protocol)}; expected ${JSON.stringify(e)}.`,{phase:"connect",delivery:"not-sent"}),1002,"Subprotocol mismatch");return}this.opened=!0,this.resolveReady()}onMessage(e){this.incoming=this.incoming.then(async()=>{let t=await x8(e.data);if(dD(t)>this.maximumResponseBytes)throw new wi(`WebSocket frame exceeds maximumResponseBytes (${this.maximumResponseBytes}).`,1009,"Message too big");let r=w8(this.codec,t),i=fD(r.requestId),n=this.active.get(i);if(n!==void 0){n.receive(r);return}if(this.cancelled.has(i)){if(D8(r))this.cancelled.delete(i);return}throw new pe("server sent an unsolicited WebSocket frame.")}).catch((t)=>{let r=I8(t);this.shutdown(r,r.closeCode,r.closeReason)})}onFailure(e){if(this.closedState)return;this.shutdown(new De(e,{phase:this.opened?"receive":"connect",delivery:"not-sent"}))}}async function x8(e){if(typeof e==="string")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e.slice(0));if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength));if(typeof Blob<"u"&&e instanceof Blob)return new Uint8Array(await e.arrayBuffer());throw new pe("server returned an unsupported WebSocket frame type.")}function dD(e){return typeof e==="string"?new TextEncoder().encode(e).byteLength:e.byteLength}function zL(e){if(typeof e==="string")return e;return new Uint8Array(e).buffer}function w8(e,t){try{let r=typeof t==="string"?void 0:me.websocket.decodeBinary(t);if(r!==void 0)return r;if(e.binary&&typeof t==="string"||!e.binary&&typeof t!=="string")throw new wi("server returned a message type incompatible with the selected subprotocol.",1003,"Unsupported message type");let i=e.decode(t);if(vl(i,"redirect"))return me.decodeRedirectResponse(i);if(vl(i,"stale"))return me.decodeStale(i);if(vl(i,"miss"))return me.decodeMiss(i);if(_8(i))return me.decodeStreamFrame(i);return me.decodeResponse(i)}catch(r){if(r instanceof wi)throw r;throw new pe("server returned an invalid WebSocket frame.",{cause:at(r)})}}class wi extends pe{closeCode;closeReason;constructor(e,t,r){super(e);this.closeCode=t,this.closeReason=r}}function I8(e){if(e instanceof wi)return e;let t=e instanceof pe?e:new pe("server returned an invalid WebSocket frame.",{cause:at(e)});return new wi(t.message,1002,"Protocol error")}function O8(e){if(e===1008)return"Client policy exceeded";if(e===1011)return"Client send failed";return"Protocol error"}function D8(e){return!vl(e,"stream.start")&&!vl(e,"stream.item")}function _8(e){let t=typeof e==="object"&&e!==null&&!Array.isArray(e)?e.kind:void 0;return typeof t==="string"&&t.startsWith("stream.")}function vl(e,t){return typeof e==="object"&&e!==null&&!Array.isArray(e)&&e.kind===t}function fD(e){return e===null?"null:":`${typeof e}:${String(e)}`}function k8(e,t){for(let[r,i]of e){if(i!==t)continue;e.delete(r);return}}var S8=30000,A8=16777216,$8=16777216,T8=16777216,N8=1024,R8=256;class Cs{url;connectionUrl;codecName;WebSocketConstructor;timeoutMs;maximumRequestBytes;maximumResponseBytes;maximumBufferedBytes;maximumActiveInvocations;maximumBufferedStreamItems;connections=new Set;connectionOwner=Object.freeze({closed:(e)=>this.connectionClosed(e)});connection;stopped=!1;nextId=1;constructor(e){if(e===null||typeof e!=="object")throw TypeError("WebSocketTransport options must be an object.");this.url=j8(e.url),this.connectionUrl=this.url,this.codecName=P8(e.codec),this.WebSocketConstructor=L8(e.websocket),this.timeoutMs=Gt(e.timeoutMs??S8,"timeoutMs"),this.maximumRequestBytes=Gt(e.maximumRequestBytes??A8,"maximumRequestBytes"),this.maximumResponseBytes=Gt(e.maximumResponseBytes??$8,"maximumResponseBytes"),this.maximumBufferedBytes=Gt(e.maximumBufferedBytes??T8,"maximumBufferedBytes"),this.maximumActiveInvocations=Gt(e.maximumActiveInvocations??N8,"maximumActiveInvocations"),this.maximumBufferedStreamItems=Gt(e.maximumBufferedStreamItems??R8,"maximumBufferedStreamItems")}async dispatch(e,t={}){if(this.stopped)throw new De("WebSocketTransport is closed.",{phase:"closed",delivery:"not-sent"});let r=Gt(t.timeoutMs??this.timeoutMs,"timeoutMs"),i=await this.codec();if(this.stopped)throw new De("WebSocketTransport is closed.",{phase:"closed",delivery:"not-sent"});let n=me.decodeRequest({version:me.VERSION,requestId:this.nextRequestId(),...e,...t.idempotencyKey===void 0?{}:{idempotencyKey:t.idempotencyKey}}),o=Cl(t.signal,r),s=!1;try{br(o);let a=await this.acquire(o,i);return br(o),s=!0,await a.dispatch(n,o,this.maximumBufferedStreamItems)}catch(a){throw z8(a,o,t.signal,r,this.url)}finally{if(!s)o.close()}}close(){if(this.stopped)return;this.stopped=!0,this.connection=void 0;let e=new De("WebSocketTransport is closed.",{phase:"closed",delivery:"not-sent"});for(let t of this.connections)t.shutdown(e)}connectionClosed(e){if(this.connections.delete(e),this.connection===e)this.connection=void 0}async acquire(e,t){let r=this.connection;if(r===void 0||!r.isAvailable)r=new pD(this.connectionOwner,this.WebSocketConstructor,this.connectionUrl,t,this.maximumRequestBytes,this.maximumResponseBytes,this.maximumBufferedBytes,this.maximumActiveInvocations),this.connection=r,this.connections.add(r);return await r.connect(e),r}nextRequestId(){let e=this.nextId;return this.nextId=e===Number.MAX_SAFE_INTEGER?1:e+1,e}codec(){return this.codecName==="msgpack"?Lt.loadMsgpack():Promise.resolve(Lt.json)}}function j8(e){if(typeof e!=="string")throw TypeError("server URL must be a string.");let t;try{t=new URL(e)}catch(r){throw TypeError(`Invalid server URL ${JSON.stringify(e)}.`,{cause:at(r)})}if(t.protocol==="http:")t.protocol="ws:";else if(t.protocol==="https:")t.protocol="wss:";else if(t.protocol!=="ws:"&&t.protocol!=="wss:")throw TypeError("server URL must use http, https, ws, or wss.");if(t.username!==""||t.password!==""||t.hash!=="")throw TypeError("server URL cannot contain credentials or a fragment.");return t.toString()}function P8(e){if(e===void 0||e==="json")return"json";if(e==="msgpack")return e;throw TypeError('codec must be "json" or "msgpack".')}function L8(e){let t=e??globalThis.WebSocket;if(typeof t!=="function")throw TypeError("WebSocketTransport requires a WebSocket implementation.");return t}function z8(e,t,r,i,n){if(e instanceof zt||e instanceof pe)return e;if(e instanceof De)return e;if(t.timedOut)return new De(`WebSocket invocation timed out after ${i}ms.`,{cause:at(e),phase:"timeout",delivery:"not-sent"});if(r?.aborted)return at(r.reason??e);return new De(`Failed to communicate with the server at ${n}.`,{cause:at(e),phase:"connect",delivery:"not-sent"})}class mD{selected;pending;closed=!1;begin(){if(this.closed)return{kind:"wait",selection:Promise.resolve(void 0)};if(this.selected)return{kind:"selected",selection:this.selected};if(this.pending)return{kind:"wait",selection:this.pending.promise};let e,t=new Promise((r)=>{e=r});return this.pending={promise:t,resolve:e},{kind:"probe"}}select(e){if(this.closed||this.selected)return;this.selected=e,this.pending?.resolve(e),this.pending=void 0}demote(){if(this.closed||this.selected==="http")return;this.selected="http",this.pending?.resolve("http"),this.pending=void 0}release(){if(this.closed||this.selected)return;this.pending?.resolve(void 0),this.pending=void 0}close(){if(this.closed)return;this.closed=!0,this.pending?.resolve(void 0),this.pending=void 0}}var M8=2147483647;class BD{input;started=Date.now();timeoutMs;constructor(e,t){this.input=e,this.timeoutMs=Gt(e?.timeoutMs??t,"timeoutMs")}options(){let e=this.remaining();return Object.freeze({...this.input?.signal===void 0?{}:{signal:this.input.signal},timeoutMs:e,...this.input?.idempotencyKey===void 0?{}:{idempotencyKey:this.input.idempotencyKey}})}get cancelled(){return this.input?.signal?.aborted===!0}get idempotency(){return this.input?.idempotencyKey===void 0?"absent":"supplied"}async wait(e){if(this.input?.signal?.aborted)throw ML(this.input.signal);let t=this.remaining(),r,i,n=new Promise((o,s)=>{if(r=setTimeout(()=>s(new De("Automatic transport decision exceeded its timeout.",{phase:"timeout",delivery:"not-sent"})),t),this.input?.signal)i=()=>s(ML(this.input.signal)),this.input.signal.addEventListener("abort",i,{once:!0})});try{return await Promise.race([e,n])}finally{if(r)clearTimeout(r);if(i&&this.input?.signal)this.input.signal.removeEventListener("abort",i)}}remaining(){let e=Math.min(M8,this.timeoutMs-(Date.now()-this.started));if(e<1)throw new De("Automatic transport invocation exceeded its timeout.",{phase:"timeout",delivery:"not-sent"});return e}}function UL(e){return e instanceof De&&e.phase!=="closed"&&e.phase!=="timeout"}function FL(e){return e.call.target}function ML(e){return e.reason instanceof Error?e.reason:Error(e.reason===void 0?"request was cancelled":String(e.reason))}function hD(e){return["[Astrale] WebSocket was unavailable before send; using HTTP for this client.",`idempotency=${e.idempotency}`,`target=${JSON.stringify(e.target)} websocket=${e.websocket} http=${e.http} phase=${e.phase}`].join(" ")}function GL(e,t){try{if(t)t(e);else globalThis.console?.warn(hD(e))}catch{}}var U8=30000;class xl{websocket;http;decision=new mD;timeoutMs;onWarning;closed=!1;constructor(e){if(e===null||typeof e!=="object")throw TypeError("AutoTransport options must be an object.");if(e.onWarning!==void 0&&typeof e.onWarning!=="function")throw TypeError("AutoTransport onWarning must be a function.");this.timeoutMs=Gt(e.timeoutMs??U8,"timeoutMs"),this.onWarning=e.onWarning,this.http=new xi({url:e.endpoints.http,...e.codec===void 0?{}:{codec:e.codec},...e.fetch===void 0?{}:{fetch:e.fetch},...e.headers===void 0?{}:{headers:e.headers},timeoutMs:this.timeoutMs,...e.maximumRequestBytes===void 0?{}:{maximumRequestBytes:e.maximumRequestBytes},...e.maximumResponseBytes===void 0?{}:{maximumResponseBytes:e.maximumResponseBytes}}),this.websocket=new Cs({url:e.endpoints.websocket,...e.codec===void 0?{}:{codec:e.codec},...e.websocket===void 0?{}:{websocket:e.websocket},timeoutMs:this.timeoutMs,...e.maximumRequestBytes===void 0?{}:{maximumRequestBytes:e.maximumRequestBytes},...e.maximumResponseBytes===void 0?{}:{maximumResponseBytes:e.maximumResponseBytes},...e.maximumBufferedBytes===void 0?{}:{maximumBufferedBytes:e.maximumBufferedBytes},...e.maximumActiveInvocations===void 0?{}:{maximumActiveInvocations:e.maximumActiveInvocations},...e.maximumBufferedStreamItems===void 0?{}:{maximumBufferedStreamItems:e.maximumBufferedStreamItems}})}async dispatch(e,t){this.requireOpen();let r=new BD(t,this.timeoutMs);return this.dispatchWithBudget(e,r)}async dispatchWithBudget(e,t){let r=this.decision.begin();if(r.kind==="selected")return r.selection==="websocket"?this.tryWebsocket(e,t,!1):this.http.dispatch(e,t.options());if(r.kind==="wait"){let i=await t.wait(r.selection);if(this.requireOpen(),!i)return this.dispatchWithBudget(e,t);return i==="websocket"?this.tryWebsocket(e,t,!1):this.http.dispatch(e,t.options())}return this.determine(e,t)}close(){if(this.closed)return;this.closed=!0,this.decision.close(),this.websocket.close()}async determine(e,t){return this.tryWebsocket(e,t,!0)}async tryWebsocket(e,t,r){try{let i=await this.websocket.dispatch(e,t.options());if(r)this.decision.select("websocket");return i}catch(i){if(t.cancelled){if(r)this.decision.release();throw i}if(i instanceof De&&i.delivery==="unknown")throw this.decision.demote(),i;if(!UL(i)){if(r)this.decision.select("websocket");throw i}let n=t.idempotency,o={code:"AUTO_TRANSPORT_DOWNGRADED",target:FL(e),websocket:this.websocket.url,http:this.http.url,phase:i.phase,delivery:"not-sent",idempotency:n};return GL(Object.freeze(o),this.onWarning),this.decision.demote(),this.http.dispatch(e,t.options())}}requireOpen(){if(!this.closed)return;throw new De("AutoTransport is closed.",{phase:"closed",delivery:"not-sent"})}}var F8=q.project(et.identity.whoami.ref.owner),HL=q.staticMethod(F8,et.identity.can.ref.name).raw;function VL(e){return Object.freeze({async can(t,r){return(await e(HL,Object.freeze({policy:G8(t.policy),object:t.object}),r)).allowed}})}function G8(e){return e instanceof q||typeof e==="string"?q.from(e).raw:q.project(e).raw}var H8=q.project(et.identity.whoami.ref.owner),JL=q.staticMethod(H8,et.identity.mint.ref.name).raw;function KL(e){return Object.freeze({async mint(t,r){return qL(await e(JL,t,r))},async delegate(t,r,i){let n=q.instanceMethod(q.id(t),et.identity.delegate.ref.name).raw;return qL(await e(n,r,i))}})}function qL(e){if(typeof e!=="string"||e.length===0)throw TypeError("Identity syscall returned an invalid credential.");return e}var ZL=q.project(et.identity.whoami.ref.owner),WL=q.staticMethod(ZL,et.identity.whoami.ref.name).raw,YL=q.staticMethod(ZL,et.identity.whois.ref.name).raw;function QL(e){return Object.freeze({async whoami(t){return await e(WL,Object.freeze({}),t)},async whois(t,r){return await e(YL,t,r)}})}var XL=q.project(et.provision.ref).raw;function e1(e){return Object.freeze({async provision(t,r){return await e(XL,t,r)}})}function gD(e){if(typeof e!=="function")throw TypeError("Auth call capability is invalid.");return Object.freeze({...e1(e),...QL(e),...VL(e),...KL(e)})}function yD(e){if(e===null||typeof e!=="object")throw TypeError("Client target must be an object.");if(e.transport==="http")return Object.freeze({transport:"http",url:wB(e.url,["http:","https:"])});if(e.transport==="websocket"){let t=new URL(wB(e.url,["http:","https:","ws:","wss:"]));if(t.protocol==="http:")t.protocol="ws:";if(t.protocol==="https:")t.protocol="wss:";return Object.freeze({transport:"websocket",url:t.toString()})}if(e.transport==="auto"&&e.endpoints&&typeof e.endpoints==="object")return Object.freeze({transport:"auto",endpoints:Object.freeze({http:wB(e.endpoints.http,["http:","https:"]),websocket:wB(e.endpoints.websocket,["http:","https:","ws:","wss:"])})});throw TypeError("Client target transport is invalid.")}function CD(e){return e.transport==="auto"?`auto\x00${e.endpoints.http}\x00${e.endpoints.websocket}`:`${e.transport}\x00${e.url}`}function wB(e,t){if(typeof e!=="string")throw TypeError("Client target URL must be a string.");let r;try{r=new URL(e)}catch(i){throw TypeError("Client target URL is invalid.",{cause:i})}if(!t.includes(r.protocol)||r.username!==""||r.password!==""||r.hash!=="")throw TypeError("Client target URL is invalid.");return r.toString()}class IB{clients=new Map;createClient;maximumSize;closed=!1;constructor(e){if(typeof e?.client!=="function")throw TypeError("ClientPool client factory is invalid.");if(this.createClient=e.client,this.maximumSize=e.maximumSize??32,!Number.isSafeInteger(this.maximumSize)||this.maximumSize<1)throw TypeError("ClientPool maximumSize must be a positive safe integer.")}clientFor(e){this.requireOpen();let t=yD(e),r=CD(t),i=this.clients.get(r);if(i)return this.clients.delete(r),this.clients.set(r,i),i.client;if(this.clients.size===this.maximumSize)this.evictOldest();let n=this.createClient(t);return this.clients.set(r,{target:t,client:n}),n}evict(e){let t=yD(e),r=CD(t),i=this.clients.get(r);if(!i)return;this.clients.delete(r),i.client.close()}close(){if(this.closed)return;this.closed=!0;for(let{client:e}of this.clients.values())e.close();this.clients.clear()}get size(){return this.clients.size}get isClosed(){return this.closed}evictOldest(){let e=this.clients.entries().next().value;if(!e)return;this.clients.delete(e[0]),e[1].client.close()}requireOpen(){if(this.closed)throw new X("ClientPool is closed.")}}function bD(e,t){if(e.declaration.output.mode!=="value")throw TypeError("Schema Client expected a value-producing Kernel syscall.");let r=se(t),i=Y.values.validate(ll,e.declaration.output.schema,r,"/output");if(i.length>0)throw TypeError(`Kernel returned an invalid Schema result: ${i[0].message}`);return t1(r)}function t1(e){if(e!==null&&typeof e==="object"&&!Object.isFrozen(e)){for(let t of Object.values(e))t1(t);Object.freeze(e)}return e}var V8=q.project(et.introspect.ref).raw;async function r1(e,t,r,i){let n=await e(tr(V8,r),i);if(n.kind!=="binary")throw TypeError("Schema introspection returned a non-binary result.");if(n.value.mediaType!==gl.installation.introspection.MEDIA_TYPE)throw TypeError("Schema introspection returned an unsupported media type.");return gl.installation.introspection.decode(r,n.value.body,t)}var q8=q.project(et.install.ref).raw,J8=q.project(et.uninstall.ref).raw;function ED(e,t){if(typeof e!=="function")throw TypeError("Schema call capability is invalid.");let r=K8(t);return Object.freeze({async install(i,n){let o=n1(await e(tr(q8,i),n));return bD(et.install,o)},async uninstall(i,n){let o=n1(await e(tr(J8,i),n));return bD(et.uninstall,o)},async introspect(i,n){return r1(e,r,i,n)}})}function n1(e){if(e.kind!=="value")throw TypeError("Schema syscall returned a non-value result.");return e.value}function K8(e){if(e===null||typeof e!=="object"||!Number.isSafeInteger(e.maximumPublicationBytes)||e.maximumPublicationBytes<1||!Number.isSafeInteger(e.maximumBundleBytes)||e.maximumBundleBytes<1)throw TypeError("Schema introspection limits are invalid.");return Object.freeze({...e})}var vD=1048576,xD=16777216,wD=16777216,ID=30000,OD=256;function mo(e,t){if(!Number.isSafeInteger(e)||e<1)throw TypeError(`${t} must be a positive safe integer.`);return e}function wl(e,t){let r=mo(e,t);if(r>2147483647)throw TypeError(`${t} exceeds the platform timer range.`);return r}function ec(e){if(e===void 0)return Object.freeze({});if(e===null||typeof e!=="object"||Array.isArray(e))throw TypeError("Session control options are invalid.");if(e.signal!==void 0&&!(e.signal instanceof AbortSignal))throw TypeError("Session cancellation signal is invalid.");return Object.freeze({...e.signal===void 0?{}:{signal:e.signal},...e.timeoutMs===void 0?{}:{timeoutMs:wl(e.timeoutMs,"timeoutMs")}})}function _D(e,t,r){let i=t?.timeoutMs??r,n=Date.now()+i,o=AbortSignal.timeout(i),s=t?.signal===void 0?[e,o]:[t.signal,e,o],a=!1;return Object.freeze({signal:AbortSignal.any(s),deadline:n,...t?.idempotencyKey===void 0?{}:{idempotencyKey:t.idempotencyKey},claimRecovery:()=>{if(a)return!1;return a=!0,!0}})}function Z8(e){DD(e);let t=e.deadline-Date.now();if(t<1)throw new X("Session operation timed out.");return t}function OB(e,t){return Object.freeze({signal:e.signal,timeoutMs:Z8(e),...t===void 0?{}:{idempotencyKey:t}})}function Er(e,t){try{DD(e)}catch(o){return Promise.reject(o)}let r,i=new Promise((o,s)=>{r=()=>s(i1(e.signal.reason)),e.signal.addEventListener("abort",r,{once:!0})}),n=Promise.resolve().then(()=>(DD(e),t(e.signal)));return Promise.race([n,i]).finally(()=>{if(r!==void 0)e.signal.removeEventListener("abort",r)})}function DD(e){if(!e.signal.aborted)return;throw i1(e.signal.reason)}function i1(e){if(e instanceof DOMException&&e.name==="TimeoutError")return new X("Session operation timed out.",{cause:e});return e instanceof Error?e:new X("Session operation was cancelled.",{cause:e})}function kD(e){if(e===null||typeof e!=="object")throw TypeError("Session policy is invalid.");if(e.allowEndpoint!==void 0&&typeof e.allowEndpoint!=="function")throw TypeError("Session endpoint policy is invalid.");if(e.allowInsecureHttp!==void 0&&typeof e.allowInsecureHttp!=="boolean")throw TypeError("Session insecure-transport policy is invalid.");return Object.freeze({maximumRouteAgeMs:mo(e.maximumRouteAgeMs,"maximumRouteAgeMs"),...e.allowEndpoint===void 0?{}:{allowEndpoint:e.allowEndpoint},...e.allowInsecureHttp===!0?{allowInsecureHttp:!0}:{}})}function SD(e,t){let r,i;try{i=ht.accept(e),r=new URL(i)}catch(n){throw TypeError("Session Kernel issuer is invalid.",{cause:n})}if(r.username!==""||r.password!==""||r.hash!==""||r.search!==""||r.protocol!=="https:"&&!(t&&r.protocol==="http:"))throw TypeError("Session Kernel issuer is invalid.");return i}function AD(e){return`${e}/invoke`}function vr(e,t){let r=new URL(e);if(r.protocol!=="https:"&&r.protocol!=="wss:"){if(r.protocol!=="http:"&&r.protocol!=="ws:"||t.allowInsecureHttp!==!0)throw new X("Insecure or unsupported endpoint is not allowed.")}if(t.allowEndpoint?.(r.toString())===!1)throw new X("Endpoint is denied by Session policy.")}class $D{options;publication;revision=0;constructor(e){this.options=e}current(){return this.publication}async revalidate(e){let t=this.revision,r=this.publication,i=await this.fetch(e,r);if(t!==this.revision)return this.revalidate(e);let n=r?.etag===i.etag?r:i;return this.publication=n,n}invalidate(){this.revision+=1,this.publication=void 0}async fetch(e,t){let r=er.url(this.options.kernel);vr(r,this.options.policy);let i=await Er(e,(a)=>this.options.fetch(r,{headers:{accept:"application/json",...t===void 0?{}:{"if-none-match":`"${t.etag}"`}},redirect:"manual",signal:a}));if(ND(i,r,"Publication discovery"),i.status===304){if(t===void 0)throw new X("Publication discovery returned an unexpected not-modified response.");let a=i.headers.get("etag");if(a!==null&&a!==`"${t.etag}"`)throw new X("Publication not-modified ETag differs from the cached snapshot.");return t}if(!i.ok)throw new X(`Publication discovery returned HTTP ${i.status}.`);let n=await Er(e,(a)=>TD(i,this.options.maximumBytes,a)),o=er.accept(Lt.json.decode(n));if(o.identity.issuer!==this.options.kernel)throw new X("Publication issuer differs from the requested Kernel issuer.");let s=i.headers.get("etag");if(s!==null&&s!==`"${o.etag}"`)throw new X("Publication response ETag differs from its canonical content.");return o}}async function TD(e,t,r){let i=e.headers.get("content-length");if(i!==null){let c=Number(i);if(!Number.isSafeInteger(c)||c<0)throw new X("Response Content-Length is invalid.");if(c>t)throw new X("Response exceeds its byte limit.")}if(e.body===null)return new Uint8Array;let n=e.body.getReader(),o=[],s=0,a=()=>void n.cancel(r.reason).catch(()=>{return});if(r.aborted)a();else r.addEventListener("abort",a,{once:!0});try{while(!0){if(r.aborted)throw r.reason;let c=await n.read();if(c.done)break;if(s+=c.value.byteLength,s>t)throw await n.cancel("response exceeds byte limit").catch(()=>{return}),new X("Response exceeds its byte limit.");o.push(c.value)}}finally{r.removeEventListener("abort",a),n.releaseLock()}return W8(o,s)}function ND(e,t,r){if(e.redirected||e.url!==t)throw new X(`${r} did not return the exact requested URL.`)}function W8(e,t){if(e.length===1)return new Uint8Array(e[0]);let r=new Uint8Array(t),i=0;for(let n of e)r.set(n,i),i+=n.byteLength;return r}class RD{options;bundles=new Map;constructor(e){this.options=e}async get(e,t){let r=Y8(e),i=this.bundles.get(r);if(i!==void 0)return i;let n=await this.fetch(e,t),o=this.bundles.get(r)??n;return this.bundles.set(r,o),o}clear(){this.bundles.clear()}async fetch(e,t){if(e.schema.bundle.ref.size>this.options.maximumBytes)throw new X("Bundle artifact exceeds its byte limit.");let r=e.schema.bundle.href;vr(r,this.options.policy);let i=await Er(t,(s)=>this.options.fetch(r,{headers:{accept:e.schema.bundle.ref.mediaType},redirect:"manual",signal:s}));if(ND(i,r,"Bundle retrieval"),!i.ok)throw new X(`Bundle retrieval returned HTTP ${i.status}.`);if(i.headers.get("content-type")!==e.schema.bundle.ref.mediaType)throw new X("Bundle artifact media type differs from its descriptor.");let n=i.headers.get("etag");if(n!==null&&n!==`"${e.schema.bundle.ref.digest}"`)throw new X("Bundle response ETag differs from its descriptor.");let o=await Er(t,(s)=>TD(i,e.schema.bundle.ref.size,s));if(o.byteLength!==e.schema.bundle.ref.size)throw new X("Bundle artifact size differs from its descriptor.");return er.decodeBundle(e,o)}}function Y8(e){return`${new URL(e.schema.bundle.href).origin}\x00${e.etag}`}function jD(e,t,r){let i=e.bindings.views.map((a)=>{vr(a.href,r);let c=t.root.views[ne.member(Z.ref(a.view))];if(c===void 0)throw new X("Published View has no verified root declaration.");return Object.freeze({key:a.view,declaration:c,href:a.href,handshake:a.handshake,issuer:e.identity.issuer,etag:e.etag,revision:e.schema.revision})}).sort((a,c)=>Q8(a.key,c.key)),n=Object.freeze(i),o=e.manifest?.entrypoint,s=o===void 0?void 0:n.find(({key:a})=>a===Z.of(e.origin,o));if(o!==void 0&&s===void 0)throw new X("Published View entrypoint has no verified Publication binding.");return Object.freeze({...s===void 0?{}:{entrypoint:s},views:n})}function PD(e,t){let r;try{r=et.view.acceptResolution(e)}catch(i){throw new X("Resolved View catalog is invalid.",{cause:i})}for(let i of r.views)vr(i.href,t);return Object.freeze({views:r.views})}function Q8(e,t){return e<t?-1:e>t?1:0}async function LD(e,t,r,i){let n=q.from(r).raw;return t(await e(tr(ge.View.resolve.path,{target:n}),i))}function o1(e,t,r,i){return Object.freeze({kernel:e,publication:t,bundle:r,views:i})}class zD{kernel;policy;publications;bundles;requireOpen;acquisitionOperation;retained;flight;constructor(e,t,r,i,n,o){this.kernel=e,this.policy=t,this.publications=r,this.bundles=i,this.requireOpen=n,this.acquisitionOperation=o}snapshot(e){this.requireOpen();let t=this.flight;if(t!==void 0)return Er(e,()=>t);let r=this.acquireSnapshot(this.acquisitionOperation());return this.flight=r,r.finally(()=>{if(this.flight===r)this.flight=void 0}).catch(()=>{return}),Er(e,()=>r)}clear(){this.publications.invalidate(),this.bundles.clear(),this.retained=void 0}async acquireSnapshot(e){let t=this.publications.current(),r=await this.publications.revalidate(e);if(t!==void 0&&t.etag!==r.etag)this.bundles.clear();let i=await this.bundles.get(r,e);if(this.requireOpen(),this.retained?.publication.etag===r.etag)return this.retained;let n=jD(r,i,this.policy),o=o1(this.kernel,r,i,n);return this.retained=o,o}}function s1(e){return new zD(e.kernel,e.policy,new $D({kernel:e.kernel,fetch:e.fetch,policy:e.policy,maximumBytes:e.maximumPublicationBytes}),new RD({fetch:e.fetch,policy:e.policy,maximumBytes:e.maximumBundleBytes}),e.requireOpen,e.acquisitionOperation)}function MD(e){if(e===void 0)return;if(e===null||typeof e!=="object"||typeof e.resolve!=="function")throw TypeError("Session auth resolver is invalid.");if(!Number.isSafeInteger(e.ttlSeconds)||e.ttlSeconds<1)throw TypeError("Session auth ttlSeconds must be a positive safe integer.");return Object.freeze({ttlSeconds:e.ttlSeconds,resolve:e.resolve.bind(e)})}async function UD(e,t,r){if(e===void 0)return Object.freeze({});let i=await Er(r,(a)=>e.resolve(t,a));if(i===null||typeof i!=="object"||Array.isArray(i))throw new X("Session auth resolver returned an invalid value.");if(Reflect.ownKeys(i).some((a)=>a!=="credential"&&a!=="delegate"))throw new X("Session auth resolver returned unsupported fields.");let o=i.credential;if(o!==void 0&&(typeof o!=="string"||o.length===0))throw new X("Session auth resolver returned an invalid credential.");if(o===void 0&&i.delegate!==void 0)throw new X("Session delegation overrides require a source credential.");if(o===void 0)return Object.freeze({});let s=i.delegate===void 0?me.acceptDelegate({ttlSeconds:e.ttlSeconds}):me.acceptDelegate(i.delegate);return Object.freeze({credential:o,delegate:s})}class _B{maximumAgeMs;maximumSize;entries=new Map;constructor(e,t=OD){this.maximumAgeMs=e,this.maximumSize=t}async key(e,t,r,i){let n=r.credential===void 0?"anonymous":await a1(r.credential),o=r.delegate===void 0?"anonymous":await a1(X8(r.delegate));return JSON.stringify([e,t.target,n,o,i===void 0?null:[i.schema,i.publication===void 0?null:[i.publication.origin,i.publication.revision,i.publication.etag]]])}get(e,t=Date.now()){let r=this.entries.get(e);if(r===void 0)return;if(r.expiresAt<=t){this.entries.delete(e);return}return this.entries.delete(e),this.entries.set(e,r),r}learn(e,t,r,i=Date.now()){let n=r===void 0?void 0:eZ(r),o=Math.min(i+this.maximumAgeMs,n??Number.POSITIVE_INFINITY),s=Object.freeze({route:t,...r===void 0?{}:{credential:r},expiresAt:o});if(r!==void 0&&n===void 0)return s;if(o<=i)return s;this.entries.delete(e);while(this.entries.size>=this.maximumSize){let a=this.entries.keys().next().value;if(a===void 0)break;this.entries.delete(a)}return this.entries.set(e,s),s}delete(e){this.entries.delete(e)}clear(){this.entries.clear()}}function X8(e){return JSON.stringify({ttlSeconds:e.ttlSeconds,...e.attenuation===void 0?{}:{attenuation:DB(e.attenuation)}})}function DB(e){if(e.kind==="identity")return"self"in e?{kind:"identity",self:!0}:{kind:"identity",credential:e.credential};if(e.kind==="exclude")return{kind:"exclude",base:DB(e.base),excluded:e.excluded.map(DB)};return{kind:e.kind,operands:e.operands.map(DB)}}async function a1(e){if(globalThis.crypto?.subtle===void 0)throw TypeError("Session route caching requires Web Crypto SHA-256 support.");let t=await globalThis.crypto.subtle.digest("SHA-256",new TextEncoder().encode(e));return[...new Uint8Array(t)].map((r)=>r.toString(16).padStart(2,"0")).join("")}function eZ(e){let t=e.split(".");if(t.length!==3)return;try{let r=t[1].replace(/-/gu,"+").replace(/_/gu,"/"),i="=".repeat((4-r.length%4)%4),n=tZ(r+i),o=JSON.parse(n);return typeof o.exp==="number"&&Number.isSafeInteger(o.exp)&&o.exp>0?o.exp*1000:void 0}catch{return}}function tZ(e){if(typeof globalThis.atob==="function"){let t=globalThis.atob(e);return new TextDecoder().decode(Uint8Array.from(t,(r)=>r.charCodeAt(0)))}throw TypeError("Session route caching requires base64 decoding support.")}function c1(e,t,r,i,n){let o;if(t==="websocket"){if(e.websocket===void 0)throw new X("Callable does not advertise a WebSocket endpoint.");if(!r)throw new X("No WebSocket implementation is available.");vr(e.websocket,n),o=Object.freeze({transport:"websocket",url:e.websocket})}else if(t==="auto"&&e.websocket!==void 0&&r)vr(e.http,n),vr(e.websocket,n),o=Object.freeze({transport:"auto",endpoints:Object.freeze({http:e.http,websocket:e.websocket})});else vr(e.http,n),o=Object.freeze({transport:"http",url:e.http});let s=i.clientFor(o);if(s===null||typeof s!=="object"||typeof s.dispatch!=="function"||typeof s.as!=="function"||typeof s.close!=="function")throw TypeError("Session client pool capability returned an invalid Client.");return Object.freeze({client:s,destination:o})}class kB{state;constructor(e){this.state=e}async dispatch(e,t,r,i){this.state.requireOpen();let n=bl(e),o=await UD(this.state.auth,n,r),s=await this.sourceKernel(r),a=await this.state.cache.key(s.issuer,n,o,i),c=Object.freeze({call:n,auth:o,source:s,cacheKey:a,...i===void 0?{}:{expected:i}}),u=this.state.cache.get(a);if(u!==void 0)return this.dispatchDestinationWithRecovery(u,c,t,r);let l=await this.dispatchSource(c,void 0,t,r);return this.followSource(l,c,t,r)}async dispatchSource(e,t,r,i){this.state.requireOpen(),vr(this.state.sourceEndpoint,this.state.policy);let n=this.state.pool.clientFor(Object.freeze({transport:"http",url:this.state.sourceEndpoint}));return Er(i,()=>l1(n,e.auth.credential).dispatch(e.call,{...OB(i,r.idempotencyKey),...e.auth.delegate===void 0?{}:{delegate:e.auth.delegate},...t===void 0?{}:{routing:t},...e.expected===void 0?{}:{schema:e.expected.schema}}))}async followSource(e,t,r,i){if(e.kind!=="redirect")return e;let n=e.redirect;if(n.route.via.issuer!==t.source.issuer)throw new X("Redirect issuer differs from the session-pinned source Kernel identity.");u1(n.route,t.expected);let o=this.state.cache.learn(t.cacheKey,n.route,n.credential);return this.dispatchDestinationWithRecovery(o,t,r,i,n.trace)}async dispatchDestinationWithRecovery(e,t,r,i,n){try{return await this.dispatchDestination(e,t.call,r,i,t.expected,n)}catch(o){let s=cD(o),a=aD(o);if(rZ(o))throw this.state.cache.delete(t.cacheKey),o;if(!s&&!a)throw o;if(this.state.cache.delete(t.cacheKey),!i.claimRecovery())throw o;let c=s?Object.freeze({kind:"refresh",stale:e.route.via.publication.etag}):void 0,u=await this.dispatchSource(t,c,r,i);return this.followSource(u,t,r,i)}}async dispatchDestination(e,t,r,i,n,o){if(e.route.via.issuer!==(await this.sourceKernel(i)).issuer)throw new X("Learned route issuer differs from the session-pinned source Kernel.");u1(e.route,n);let s=c1(e.route.endpoint,this.state.envelopeTransport,this.state.websocketAvailable,this.state.pool,this.state.policy),a={...OB(i,r.idempotencyKey),routing:e.route.via},c=await Er(i,()=>o===void 0?l1(s.client,e.credential).dispatch(t,a):uD(s.client,e.credential,t,a,o));if(c.kind==="redirect")throw new X("A destination redirect is invalid; only the source Kernel may redirect.");return c}async sourceKernel(e){let t=await this.state.discovery.snapshot(e);if(t.kernel!==this.state.kernel)throw new X("Session discovery returned another Kernel identity.");return Object.freeze({issuer:t.publication.identity.issuer})}}function rZ(e){if(!(e instanceof zt))return!1;let t=me.serviceErrorOf({code:e.code,message:e.message,...e.data===void 0?{}:{data:e.data}});return t?.data.code===me.SCHEMA_UPGRADE_REQUIRED||t?.data.code===me.SERVICE_TRUST_REQUIRED}function u1(e,t){if(t===void 0)return;if(t.publication===void 0)throw new X("A local bound installation cannot resolve to a remote route.");let r=e.via.publication,i=er.compareReferences(r,t.publication);if(i!=="exact"&&i!=="same-schema")throw new X("Resolved route does not match the bound installed Publication.")}function tc(e,t){if(t.kind===e)return t;if(t.kind==="stream")t.stream.cancel(`Expected ${e} result.`);throw new X(`Function returned ${t.kind}; ${e} was required.`)}function l1(e,t){return t===void 0?e:e.as(t)}function SB(e={}){if(e===null||typeof e!=="object"||Array.isArray(e))throw TypeError("Session request options are invalid.");let t=ec(e);if(Reflect.ownKeys(e).some((n)=>!["signal","timeoutMs","idempotencyKey"].includes(String(n))))throw TypeError("Session request options contain unsupported fields.");let i=e.idempotencyKey===void 0?void 0:me.acceptIdempotencyKey(e.idempotencyKey,"request.idempotencyKey");return Object.freeze({...t,...i===void 0?{}:{idempotencyKey:i}})}function FD(e){if(e!=="auto"&&e!=="http"&&e!=="websocket")throw TypeError("Session envelope transport is invalid.");return e}var DNe=Object.freeze({maximumRouteAgeMs:60000}),f1=new WeakMap;function GD(e,t,r,i){let n=f1.get(e);if(n===void 0)throw TypeError("Bound dispatch requires an owned ClientSession.");return n(t,r,i)}class rc{kernel;schema;ownedPool;discovery;dispatcher;lifecycle=new AbortController;timeoutMs;routes;admitTargetViews;closed=!1;constructor(e){if(e===null||typeof e!=="object")throw TypeError("ClientSession options are invalid.");let t=kD(e.policy);this.admitTargetViews=(f)=>PD(f,t),this.kernel=SD(e.kernel,t.allowInsecureHttp===!0);let r=AD(this.kernel),i=e.fetch??globalThis.fetch;if(typeof i!=="function")throw TypeError("ClientSession requires Fetch.");let n=e.fetch===void 0?i.bind(globalThis):i;if(e.client!==void 0&&e.pool!==void 0)throw TypeError("ClientSession accepts either client or pool, not both.");let o=mo(e.maximumPublicationBytes??vD,"maximumPublicationBytes"),s=mo(e.maximumBundleBytes??xD,"maximumBundleBytes"),a=mo(e.maximumResponseBytes??wD,"maximumResponseBytes"),c=wl(e.timeoutMs??ID,"timeoutMs");this.timeoutMs=c;let u=e.client!==void 0||e.pool!==void 0||e.websocket!==void 0||typeof globalThis.WebSocket==="function",l=e.client??iZ({fetch:n,...e.websocket===void 0?{}:{websocket:e.websocket},...e.onWarning===void 0?{}:{onWarning:e.onWarning},maximumResponseBytes:a,timeoutMs:c}),d;if(e.pool===void 0){let f=new IB({client:l});this.ownedPool=f,d=d1(f)}else d=d1(e.pool);this.discovery=s1({kernel:this.kernel,fetch:n,policy:t,maximumPublicationBytes:o,maximumBundleBytes:s,requireOpen:()=>this.requireOpen(),acquisitionOperation:()=>this.operation(void 0)}),this.routes=new _B(t.maximumRouteAgeMs),this.dispatcher=new kB({kernel:this.kernel,sourceEndpoint:r,pool:d,websocketAvailable:u,auth:MD(e.auth),cache:this.routes,policy:t,envelopeTransport:FD(e.envelopeTransport??"http"),discovery:this.discovery,requireOpen:()=>this.requireOpen()}),this.schema=ED((f,m)=>this.dispatch(f,m),{maximumPublicationBytes:o,maximumBundleBytes:s}),f1.set(this,(f,m,B)=>{let h=SB(B);return this.dispatcher.dispatch(f,h,this.operation(h),m)})}snapshot(e){return this.discovery.snapshot(this.operation(ec(e)))}viewsFor(e,t){return this.requireOpen(),LD(async(r,i)=>tc("value",await this.dispatcher.dispatch(r,{},i)).value,this.admitTargetViews,e,this.operation(ec(t)))}async installed(e,t){let r=await this.schema.introspect({from:{kind:"installation",origin:e},select:{state:!0,target:!0,source:!0,bundle:!0,readiness:!0,capabilities:!0}},t);if(r?.state!=="ready"||r.readiness===null)throw new X(`Domain ${e} is not ready on this Kernel.`);return r}dispatch(e,t){let r=SB(t);return this.dispatcher.dispatch(e,r,this.operation(r))}async call(e,t){let r=await this.dispatch(e,t);return tc("value",r).value}async stream(e,t){let r=await this.dispatch(e,t);return tc("stream",r).stream}async binary(e,t){let r=await this.dispatch(e,t);return tc("binary",r).value}close(){if(this.closed)return;this.closed=!0,this.lifecycle.abort(new X("ClientSession is closed.")),this.ownedPool?.close(),this.routes.clear(),this.discovery.clear()}requireOpen(){if(this.closed)throw new X("ClientSession is closed.")}operation(e){return this.requireOpen(),_D(this.lifecycle.signal,e,this.timeoutMs)}}function d1(e){if(e===null||typeof e!=="object"||typeof e.clientFor!=="function")throw TypeError("Session client pool capability is invalid.");return Object.freeze({clientFor:(t)=>nZ(e.clientFor.call(e,t))})}function nZ(e){if(e===null||typeof e!=="object"||typeof e.dispatch!=="function"||typeof e.as!=="function"||typeof e.close!=="function")throw TypeError("Session client pool capability returned an invalid Client.");return e}function iZ(e){return(t)=>{switch(t.transport){case"http":return new gs({transport:new xi({url:t.url,fetch:e.fetch,timeoutMs:e.timeoutMs,maximumResponseBytes:e.maximumResponseBytes})});case"websocket":return new gs({transport:new Cs({url:t.url,timeoutMs:e.timeoutMs,maximumResponseBytes:e.maximumResponseBytes,...e.websocket===void 0?{}:{websocket:e.websocket}})});case"auto":return new gs({transport:new xl({endpoints:t.endpoints,fetch:e.fetch,timeoutMs:e.timeoutMs,maximumResponseBytes:e.maximumResponseBytes,...e.websocket===void 0?{}:{websocket:e.websocket},...e.onWarning===void 0?{}:{onWarning:e.onWarning}})})}}}async function p1(e,t,r,i,n){return HD(e,t,r,void 0,i,n)}async function m1(e,t,r,i,n,o){return HD(e,t,r,i,n,o)}function B1(e,t){return(r,i)=>(n)=>HD(e,t,r,q.id(i.id),n)}function h1(e){let t=new Map;for(let r of e.$.definitions.values()){if(r.kind==="function"){let i=r;t.set(i.key,i);continue}if(r.kind!=="class"&&r.kind!=="interface"||r.family!=="node")continue;for(let i of r.methods.values())if(i.definition.inheritance!=="abstract"){let n=i;t.set(n.key,n)}}return t}async function HD(e,t,r,i,n,o={}){let s=t.callables.get(r.key);if(s===void 0)throw new X("Callable is not a concrete member of the bound Domain root.");let a=i===void 0?s.path:s.on(q.from(i)),c=await GD(e,tr(a,n),t.bound,o);return oZ(s,c)}function oZ(e,t){let r=e.definition.output.mode;switch(r){case"value":if(t.kind==="value")return t.value;break;case"stream":if(t.kind==="stream")return t.stream;break;case"binary":if(t.kind==="binary")return t.value;break}return sZ(r,t)}function sZ(e,t){if(t.kind==="stream")t.stream.cancel(`Remote callable declared ${e} output.`);throw new X(`Remote callable declared ${e} output but returned ${t.kind}.`)}function VD(e,t,r,i){return i===void 0?e.$.wrap(r,t):e.$.wrap(r,i,t)}function Il(e,t,r){let i=aZ(r??t),n=i.source.kind==="remote"?i.source.publication:void 0,o=r===void 0?i.bundle.root:t;if(n!==void 0)cZ(o,n);if(o.origin!==i.bundle.root.origin||Y.revision(o)!==Y.revision(i.bundle.root))throw TypeError("Expected Domain schema does not match the installed schema Bundle.");let s=Ha.fromSchema(o),a=Object.freeze({callables:h1(s),bound:Object.freeze({schema:n===void 0?Object.freeze({target:i.target}):Object.freeze({revision:Y.revision(o)}),...n===void 0?{}:{publication:er.reference(n)}})}),c=B1(e,a),u=(f,m,B,h)=>("on"in f)?m1(e,a,f,m,B,h):p1(e,a,f,m,B),l=(f,m)=>m===void 0?VD(s,c,f):VD(s,c,f,m),d={...s,$:Object.freeze({...s.$,installed:i,...n===void 0?{}:{publication:n},invoke:u,bind:l})};return Object.freeze(d)}function aZ(e){if(e===null||typeof e!=="object"||Array.isArray(e))throw TypeError("Installed Domain evidence is invalid.");if(e.state!=="ready"||e.readiness===null)throw TypeError("Installed Domain is not ready.");if(e.source.kind==="remote"){let t=er.accept(e.source.publication),r=er.acceptBundle(t,e.bundle);return Object.freeze({...e,source:Object.freeze({kind:"remote",publication:t}),bundle:r})}return e}function cZ(e,t){if(e.origin!==t.origin||Y.revision(e)!==t.schema.revision)throw TypeError("Expected Domain schema does not match the target Publication revision.")}var uZ=q.project(et.mutate.ref).raw;async function g1(e,t,r){let i=typeof t==="function"?eo.build(t):lZ(t),n=await e(tr(uZ,i),r);return pm.decode(n)}function lZ(e){return"format"in e?eo.decode(e):("operations"in e)?eo.create(e):eo.fromGraph(e)}function dZ(e){if(!bs(e))ft("","Query source input must be an object");let t=e.kind;if(t==="node")return fZ(e);if(t==="edge")return pZ(e);ft("/kind","Query source kind must be node or edge")}function Dl(e){let t;try{t=Pe(e)}catch(r){ft("/predicate/property","Invalid PropertyKey",r)}return Object.freeze({equals(r){return Object.freeze({kind:"property.equal",property:t,value:mZ(r)})},isPresent(){return Object.freeze({kind:"property.present",property:t})}})}var $r=Object.freeze({from:dZ});function fZ(e){Wn(e,["kind","paths","definitions","binding"],"","Node source input");let t=$B(e.paths,"/source/paths"),r=$B(e.definitions,"/source/definitions"),i=[];t.forEach((s,a)=>{try{i.push(Object.freeze({kind:"path",path:q.from(s).raw}))}catch(c){ft(`/source/paths/${a}`,"Invalid Path source",c)}}),r.forEach((s,a)=>{i.push(Object.freeze({kind:"definition",definition:TB(s,`/source/definitions/${a}`)}))});let n=e.binding===void 0?"n0":e.binding,o=Ot.decode({format:Ot.format,version:Ot.version,source:{kind:"node",terms:i,binding:n},steps:[],select:{kind:"graph",binding:n}});if(o.source.kind!=="node")ft("/source/kind","Node source was not retained");return AB(Object.freeze({source:o.source,steps:o.steps,node:o.source.binding}))}function pZ(e){Wn(e,["kind","definitions","bindings"],"","Edge source input");let r=$B(e.definitions,"/source/definitions").map((u,l)=>Object.freeze({kind:"definition",definition:TB(u,`/source/definitions/${l}`)})),i=new Set,n=e.bindings;if(n!==void 0&&!bs(n))ft("/source/bindings","Edge source bindings must be an object");if(n!==void 0)Wn(n,["source","edge","target"],"/source/bindings","Edge source bindings");for(let u of[n?.source,n?.edge,n?.target])if(typeof u==="string")i.add(u);let o=n?.source??Ol("n",i);i.add(o);let s=n?.edge??Ol("e",i);i.add(s);let a=n?.target??Ol("n",i),c=Ot.decode({format:Ot.format,version:Ot.version,source:{kind:"edge",terms:r,bindings:{source:o,edge:s,target:a}},steps:[],select:{kind:"graph",binding:s}});if(c.source.kind!=="edge")ft("/source/kind","Edge source was not retained");return y1(Object.freeze({source:c.source,steps:c.steps,edge:c.source.bindings.edge}))}function AB(e){if(e.node===void 0)ft("","Node builder has no current Node binding");let t={node:e.node,filter(i){return AB(qD(e,i,e.node))},expand(i){return b1(e,i)},select(i){return E1(e,i)}};if(e.edge===void 0)return Object.freeze(t);let r={...t,edge:e.edge,filter(i){return AB(qD(e,i,e.node))}};return Object.freeze(r)}function y1(e){if(e.source.kind!=="edge")ft("","Edge builder has no Edge source");let t=e.source.bindings;return Object.freeze({source:t.source,edge:t.edge,target:t.target,filter(r){return y1(qD(e,r,void 0))},expand(r){return b1(e,r)},select(r){return E1(e,r)}})}function qD(e,t,r){let i=`/steps/${e.steps.length}`;if(!bs(t))ft(i,"Filter input must be an object");let n=t,o=t.binding===void 0?r:t.binding;if(o===void 0)ft(`${i}/binding`,"Filter binding is required");let s;if(Object.hasOwn(t,"satisfies"))Wn(t,["binding","satisfies"],i,"Definition filter input"),s={op:"filter",binding:o,predicate:{kind:"definition.satisfies",definition:TB(n.satisfies,`${i}/satisfies`)}};else if(Object.hasOwn(t,"predicate"))Wn(t,["binding","predicate"],i,"Property filter input"),s={op:"filter",binding:o,predicate:n.predicate};else ft(i,"Filter input must contain satisfies or a Property predicate");let a=v1(e,s);return Object.freeze({source:a.source,steps:a.steps,...e.node===void 0?{}:{node:e.node},...e.edge===void 0?{}:{edge:e.edge}})}function mZ(e){try{return C1(te.decode(te.encode(e)))}catch(t){ft("/predicate/value","Invalid portable equality value",t)}}function C1(e){if(e===null||typeof e!=="object")return e;for(let t of Object.values(e))C1(t);return Object.freeze(e)}function b1(e,t){let r=`/steps/${e.steps.length}`;if(!bs(t))ft(r,"Expand input must be an object");Wn(t,["from","via","direction","bindings"],r,"Expand input");let i=BZ(e),n,o;if(t.bindings===void 0){let c=Ol("e",i);n=c,i.add(c),o=Ol("n",i)}else if(bs(t.bindings))Wn(t.bindings,["edge","node"],`${r}/bindings`,"Expand bindings"),n=t.bindings.edge,o=t.bindings.node;else ft(`/steps/${e.steps.length}/bindings`,"Expand bindings must be an object");let s=v1(e,{op:"expand",from:t.from===void 0?e.node===void 0?ft(`${r}/from`,"Expansion from an Edge source requires a Node binding"):e.node:t.from,via:$B(t.via,`${r}/via`).map((c,u)=>TB(c,`${r}/via/${u}`)),direction:t.direction,bindings:{edge:n,node:o}}),a=s.steps.at(-1);if(a?.op!=="expand")ft(`/steps/${e.steps.length}`,"Expand was not retained");return AB(Object.freeze({source:s.source,steps:s.steps,node:a.bindings.node,edge:a.bindings.edge}))}function E1(e,t){if(!bs(t))ft("/select","Select input must be an object");let r=t.kind,i=(()=>{if(r==="graph")return Wn(t,["kind","binding","order"],"/select","Graph select input"),{kind:r,binding:t.binding===void 0?e.node??e.edge??ft("/select/binding","Selection binding is required"):t.binding,...t.order===void 0?{}:{order:t.order}};if(r==="nodes")return Wn(t,["kind","binding","projection","order"],"/select","Node select input"),{kind:r,binding:t.binding===void 0?e.node??ft("/select/binding","Node selection binding is required"):t.binding,projection:t.projection,...t.order===void 0?{}:{order:t.order}};if(Wn(t,["kind","binding","projection","order"],"/select","Edge select input"),e.edge===void 0&&t.binding===void 0)ft("/select/binding","Edge selection requires an introduced Edge binding");return{kind:r,binding:t.binding===void 0?e.edge:t.binding,projection:t.projection,...t.order===void 0?{}:{order:t.order}}})();return Ot.decode({format:Ot.format,version:Ot.version,source:e.source,steps:e.steps,select:i})}function v1(e,t){let r=e.node??e.edge;if(r===void 0)ft("/select/binding","Query prefix has no selectable binding");return Ot.decode({format:Ot.format,version:Ot.version,source:e.source,steps:[...e.steps,t],select:{kind:"graph",binding:r}})}function BZ(e){let t=e.source.kind==="node"?new Set([e.source.binding]):new Set([e.source.bindings.source,e.source.bindings.edge,e.source.bindings.target]);for(let r of e.steps){if(r.op!=="expand")continue;t.add(r.bindings.edge),t.add(r.bindings.node)}return t}function Ol(e,t){for(let r=0;r<=t.size;r++){let i=`${e}${r}`;if(!t.has(i))return i}throw TypeError("No collision-free Query binding is available.")}function $B(e,t){if(e===void 0)return[];if(!Array.isArray(e))ft(t,"Expected an array");return e}function TB(e,t){if(!bs(e))ft(t,"Definition input must be an object");if(typeof e.origin!=="string"||e.kind!=="class"&&e.kind!=="interface"||typeof e.name!=="string")ft(t,"Definition input must contain origin, kind, and name");return Object.freeze({origin:e.origin,kind:e.kind,name:e.name})}function bs(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}function Wn(e,t,r,i){let n=Object.keys(e).find((o)=>!t.includes(o));if(n!==void 0)ft(`${r}/${hZ(n)}`,`${i} contains an unsupported field`)}function hZ(e){return e.replaceAll("~","~0").replaceAll("/","~1")}function ft(e,t,r){throw new bn(e,t,r===void 0?void 0:{cause:r})}class Bo extends TypeError{path;code="QUERY_REFERENCE_INVALID";constructor(e,t,r){super(`${t} at ${e||"/"}.`,r);this.path=e,this.name="QueryReferenceError"}}var w1=Object.freeze({evaluate(e,t,r){try{if(!Number.isSafeInteger(r.size)||r.size<1)ve("/size","Reference page size must be a positive safe integer");let i=Yo(e),n=_Z(t);return gZ(i,n,r)}catch(i){if(i instanceof Bo)throw i;if(i instanceof bn)throw new Bo(i.path,"Invalid QueryAST for reference evaluation",{cause:i});throw new Bo("","Reference evaluation failed",{cause:i})}}});function gZ(e,t,r){let i=new T1(t),n=new A1(t),o=new $1(t),s,a,c=[],u=new Map;if(e.source.kind==="node"){let f=e.source,m=new Map;f.terms.forEach((B,h)=>{let g=`/source/terms/${h}`;if(B.kind==="path"){yZ(B.path,g,t,i,m);return}let w=n.close(B.definition,"node",`${g}/definition`);for(let b of t.graph.nodes)if(w.has(b.class)&&i.node(b,`${g}/definition`))m.set(b.id,b)}),s=[...m.values()].map((B)=>new Map([[f.binding,{kind:"node",value:B}]])),a=m.size,u.set(f.binding,"node")}else{let f=e.source,m=new Set;f.terms.forEach((h,g)=>{for(let w of n.close(h.definition,"edge",`/source/terms/${g}/definition`))m.add(w)});let B=new Map;for(let h of t.graph.edges){if(!m.has(h.class))continue;let g=ln(t,h.source,"/source"),w=ln(t,h.target,"/source");if(i.edge(h,"/source")&&i.node(g,"/source")&&i.node(w,"/source"))B.set(Ge(h),h)}s=[...B.values()].sort(Cr).map((h)=>{let g=new Map;return g.set(f.bindings.source,{kind:"node",value:ln(t,h.source,"/source")}),g.set(f.bindings.edge,{kind:"edge",value:h}),g.set(f.bindings.target,{kind:"node",value:ln(t,h.target,"/source")}),g}),a=B.size,u.set(f.bindings.source,"node"),u.set(f.bindings.edge,"edge"),u.set(f.bindings.target,"node")}e.steps.forEach((f,m)=>{let B=`/steps/${m}`;if(f.op==="filter"){if(f.predicate.kind==="definition.satisfies"){let b=u.get(f.binding);if(b===void 0)ve(`${B}/binding`,"Filter binding is unavailable");let O=n.close(f.predicate.definition,b,`${B}/predicate/definition`);s=s.filter((k)=>O.has(_l(k,f.binding,`${B}/binding`).value.class))}else if(f.predicate.kind==="identity.equal"){let b=f.predicate;s=s.filter((O)=>{let k=_l(O,f.binding,`${B}/binding`);return k.kind==="node"?typeof b.identity==="string"&&k.value.id===b.identity:typeof b.identity!=="string"&&Ge(k.value)===Ge(b.identity)})}else{let b=f.predicate;s=s.filter((O)=>{let k=_l(O,f.binding,`${B}/binding`);if(!o.close(b.property,k.kind,`${B}/predicate/property`).has(k.value.class))return!1;if(!(k.kind==="node"?i.readNode(k.value,`${B}/binding`):i.readEdge(k.value,`${B}/binding`)))return!1;if(!Object.hasOwn(k.value.props,b.property))return!1;return b.kind==="property.present"||Nr(k.value.props[b.property],b.value)})}c.push(s.length);return}let h=new Map;f.via.forEach((b,O)=>{let k=n.close(b,"edge",`${B}/via/${O}`);for(let G of k){let oe=ho(`${B}/via/${O}`,"Edge Class orientation could not be resolved",()=>t.orientation(G));if(oe!=="directed"&&oe!=="undirected")ve(`${B}/via/${O}`,"Definition closes to a non-Edge Class");h.set(G,oe)}});let g=[...t.graph.edges].sort(Cr),w=[];for(let b of s){let O=S1(b,f.from,`${B}/from`);for(let k of g){let G=h.get(k.class);if(G===void 0)continue;let oe=OZ(k,O.id,G,f.direction);if(oe===void 0)continue;let V=t.nodes.get(oe);if(V===void 0)ve(B,`Expansion Edge endpoint ${JSON.stringify(oe)} is absent from graph`);if(!i.node(O,B)||!i.edge(k,B)||!i.node(V,B))continue;let _e=new Map(b);_e.set(f.bindings.edge,{kind:"edge",value:k}),_e.set(f.bindings.node,{kind:"node",value:V}),w.push(_e)}}s=w,c.push(s.length),u.set(f.bindings.edge,"edge"),u.set(f.bindings.node,"node")});let l=u.get(e.select.binding);if(l===void 0)ve("/select/binding","Selected binding is unavailable");if(e.select.kind==="nodes"&&l!=="node")ve("/select/binding","Node selection requires a Node binding");if(e.select.kind==="edges"&&l!=="edge")ve("/select/binding","Edge selection requires an Edge binding");let d=l==="node"?bZ(s,e.select,r.size,r.after,i,o):EZ(s,e.select,r.size,r.after,t,i,o);return Object.freeze({...d,trace:Object.freeze({sourceRows:a,stepRows:Object.freeze(c)})})}function yZ(e,t,r,i,n){let o=ho(`${t}/path`,"Path resolution failed",()=>r.resolve(e));if(!Array.isArray(o))ve(`${t}/path`,"Path resolver must return an array");let s=new Map;if(o.forEach((d,f)=>{let m=`${t}/path/witnesses/${f}`,B=CZ(d,m,r),h=s.get(B.result);if(h===void 0)s.set(B.result,[B]);else h.push(B)}),s.size!==1)return;let a=s.entries().next().value;if(a===void 0)return;let[c,u]=a,l=!1;if(u.forEach((d,f)=>{let m=`${t}/path/witnesses/${f}`,B=!0;for(let h of d.nodes)B=i.node(ln(r,h,m),m)&&B;for(let h of d.edges)B=i.edge(N1(r,h,m),m)&&B;l=l||B}),l)n.set(c,ln(r,c,t))}function CZ(e,t,r){if(!nc(e)||!Sl(e,["result","nodes","edges"]))ve(t,"Path witness must contain exactly result, nodes, and edges");let i=kl(e.result,`${t}/result`);if(!Array.isArray(e.nodes))ve(`${t}/nodes`,"Witness nodes must be an array");if(!Array.isArray(e.edges))ve(`${t}/edges`,"Witness edges must be an array");let n=e.nodes.map((a,c)=>kl(a,`${t}/nodes/${c}`));RB(n,(a)=>a,`${t}/nodes`,"NodeId");let o=e.edges.map((a,c)=>R1(a,`${t}/edges/${c}`));RB(o,Ge,`${t}/edges`,"EdgeKey");let s=new Set(n);if(!s.has(i))ve(`${t}/result`,"Path result is absent from witness nodes");return n.forEach((a)=>ln(r,a,t)),o.forEach((a,c)=>{if(N1(r,a,`${t}/edges/${c}`),!s.has(a.source)||!s.has(a.target))ve(`${t}/edges/${c}`,"Path Edge endpoints are absent from witness nodes")}),Object.freeze({result:i,nodes:Object.freeze(n),edges:Object.freeze(o)})}function bZ(e,t,r,i,n,o){let s=new Map;e.forEach((B)=>{let h=S1(B,t.binding,"/select/binding");if((t.kind==="graph"||t.kind==="nodes"&&t.projection.kind==="value")&&!n.readNode(h,"/select/binding"))return;s.set(h.id,h)});let a=t.order,c=I1(a,"node",o),u=[...s.values()].sort(c).filter((B)=>i===void 0||O1(i,B,a,"node",o)<0),l=u.slice(0,r),d=t.kind==="nodes"?ds({kind:"nodes",nodes:l.map((B)=>JD(B,t.projection.kind))}):ds({kind:"graph",graph:{nodes:[...l].sort((B,h)=>At(B.id,h.id)),edges:[]},selection:{kind:"node",ids:l.map((B)=>B.id)}}),f=u.length>r?l.at(-1):void 0,m=f===void 0?void 0:D1(f,a,"node",o);return Object.freeze({result:d,...m===void 0?{}:{next:m}})}function EZ(e,t,r,i,n,o,s){let a=new Map;e.forEach((w)=>{let b=DZ(w,t.binding,"/select/binding"),O=ln(n,b.source,"/select/binding"),k=ln(n,b.target,"/select/binding");if(!o.edge(b,"/select/binding")||!o.node(O,"/select/binding")||!o.node(k,"/select/binding"))return;if(!(t.kind==="graph"?o.readEdge(b,"/select/binding")&&o.readNode(O,"/select/binding")&&o.readNode(k,"/select/binding"):t.kind==="edges"?(t.projection.edge==="reference"||o.readEdge(b,"/select/binding"))&&(t.projection.source==="reference"||o.readNode(O,"/select/binding"))&&(t.projection.target==="reference"||o.readNode(k,"/select/binding")):!1))return;a.set(Ge(b),b)});let c=t.order,u=I1(c,"edge",s),l=[...a.values()].sort(u).filter((w)=>i===void 0||O1(i,w,c,"edge",s)<0),d=l.slice(0,r),f=new Set;d.forEach((w)=>{f.add(w.source),f.add(w.target)});let m=[...f].sort(At).map((w)=>ln(n,w,"/select/binding")),B=t.kind==="edges"?ds({kind:"edges",edges:d.map((w)=>({edge:IZ(w,t.projection.edge),source:JD(ln(n,w.source,"/select/binding"),t.projection.source),target:JD(ln(n,w.target,"/select/binding"),t.projection.target)}))}):ds({kind:"graph",graph:{nodes:m,edges:[...d].sort(Cr)},selection:{kind:"edge",keys:d.map(it)}}),h=l.length>r?d.at(-1):void 0,g=h===void 0?void 0:D1(h,c,"edge",s);return Object.freeze({result:B,...g===void 0?{}:{next:g}})}function I1(e,t,r){return(i,n)=>_1(NB(i,e,t,r),NB(n,e,t,r),e)}function O1(e,t,r,i,n){let o=vZ(e,r,i,n);return _1(o,NB(t,r,i,n),r)}function D1(e,t,r,i){let n=NB(e,t,r,i);if(n.bucket==="ranked")return Object.freeze({bucket:"ranked",value:n.value,identity:n.identity});return Object.freeze({bucket:n.bucket,identity:n.identity})}function NB(e,t,r,i){let n="id"in e?e.id:it(e);if(t===void 0)return Object.freeze({bucket:"identity",identity:n});let o=i.close(t.property,r,"/select/order/property"),s=i.ordering(t.property,r,"/select/order/property");if(!o.has(e.class)||!Object.hasOwn(e.props,t.property))return Object.freeze({bucket:"unranked",identity:n});let a=e.props[t.property];if(!k1(a,s))ve("/select/order/property","Ordered Property value is outside its declared ordering domain");return Object.freeze({bucket:"ranked",value:a,identity:n})}function vZ(e,t,r,i){if(!nc(e))ve("/after","Frontier must be an object");let n=e.bucket==="ranked"?["bucket","identity","value"]:["bucket","identity"];if(!Sl(e,n))ve("/after","Frontier has an invalid shape");let o=r==="node"?kl(e.identity,"/after/identity"):R1(e.identity,"/after/identity");if(t===void 0){if(e.bucket!=="identity")ve("/after/bucket","Unordered frontier bucket is invalid");return Object.freeze({bucket:"identity",identity:o})}if(e.bucket==="unranked")return Object.freeze({bucket:"unranked",identity:o});let s=i.ordering(t.property,r,"/select/order/property");if(e.bucket!=="ranked"||!k1(e.value,s))ve("/after","Ordered frontier is invalid");return Object.freeze({bucket:"ranked",value:e.value,identity:o})}function _1(e,t,r){if(r===void 0)return x1(e.identity,t.identity);if(e.bucket!==t.bucket)return e.bucket==="unranked"?r.unranked==="first"?-1:1:r.unranked==="first"?1:-1;if(e.bucket==="ranked"&&t.bucket==="ranked"){let i=typeof e.value==="boolean"?"boolean":typeof e.value==="number"?"number":"string",n=xZ(e.value,t.value,i);if(n!==0)return r.direction==="asc"?n:-n}return x1(e.identity,t.identity)}function x1(e,t){if(typeof e==="string"&&typeof t==="string")return At(e,t);if(typeof e!=="string"&&typeof t!=="string")return Cr(e,t);ve("/after/identity","Frontier identity kind disagrees with selection")}function k1(e,t){if(t==="boolean")return typeof e==="boolean";if(t==="number")return typeof e==="number"&&Number.isFinite(e);return typeof e==="string"}function xZ(e,t,r){if(r==="boolean")return Number(e)-Number(t);if(r==="number")return e-t;return wZ(e,t)}function wZ(e,t){let r=Array.from(e,(n)=>n.codePointAt(0)),i=Array.from(t,(n)=>n.codePointAt(0));for(let n=0;n<Math.min(r.length,i.length);n+=1)if(r[n]!==i[n])return r[n]-i[n];return r.length-i.length}function JD(e,t){return t==="value"?Object.freeze({kind:"value",value:e}):Object.freeze({kind:"reference",value:Object.freeze({id:e.id,class:e.class})})}function IZ(e,t){return t==="value"?Object.freeze({kind:"value",value:e}):Object.freeze({kind:"reference",value:it(e)})}function OZ(e,t,r,i){if(r==="undirected"||i==="incident"){if(e.source===t)return e.target;if(e.target===t)return e.source;return}if(i==="outgoing")return e.source===t?e.target:void 0;return e.target===t?e.source:void 0}function S1(e,t,r){let i=_l(e,t,r);if(i?.kind!=="node")ve(r,"Binding does not contain a Node");return i.value}function DZ(e,t,r){let i=_l(e,t,r);if(i?.kind!=="edge")ve(r,"Binding does not contain an Edge");return i.value}function _l(e,t,r){let i=e.get(t);if(i===void 0)ve(r,"Binding is unavailable");return i}class A1{context;#e=new Map;constructor(e){this.context=e}close(e,t,r){let i=`${t}\x00${e.origin}\x00${e.kind}\x00${e.name}`,n=this.#e.get(i);if(n!==void 0)return n;let o=ho(r,"Definition closure failed",()=>this.context.closeDefinition(e));if(o===void 0||!nc(o)||!Sl(o,["family","classes"]))ve(r,"Definition is unresolved");if(o.family!=="node"&&o.family!=="edge"&&o.family!=="both"||o.family!==t&&o.family!=="both")ve(r,`Definition is not ${t}-capable`);if(!Array.isArray(o.classes))ve(`${r}/classes`,"Classes must be an array");let s=o.classes.map((c,u)=>KD(c,`${r}/classes/${u}`));RB(s,(c)=>c,`${r}/classes`,"ClassPath");let a=new Set(s);return this.#e.set(i,a),a}}class $1{context;#e=new Map;#t=new Map;constructor(e){this.context=e}close(e,t,r){let i;try{i=Pe(e)}catch(l){ve(r,"PropertyKey is invalid",l)}let n=`${t}\x00${i}`,o=this.#e.get(n);if(o!==void 0)return o;let s=ho(r,"Property closure failed",()=>this.context.closeProperty(i));if(s===void 0||!nc(s)||!Sl(s,s.ordering===void 0?["nodes","edges"]:["nodes","edges","ordering"]))ve(r,"Property is unresolved");if(s.ordering!==void 0&&s.ordering!=="boolean"&&s.ordering!=="number"&&s.ordering!=="string"&&s.ordering!=="instant")ve(`${r}/ordering`,"Property ordering domain is invalid");let a=s[t==="node"?"nodes":"edges"];if(!Array.isArray(a))ve(r,"Property Classes must be an array");let c=a.map((l,d)=>KD(l,`${r}/classes/${d}`));RB(c,(l)=>l,`${r}/classes`,"ClassPath");let u=new Set(c);return this.#e.set(n,u),this.#t.set(i,s.ordering),u}ordering(e,t,r){this.close(e,t,r);let i=this.#t.get(e);if(i===void 0)ve(r,"Property has no supported ordering domain");return i}}class T1{context;#e=new Map;#t=new Map;#r=new Map;#n=new Map;constructor(e){this.context=e}node(e,t){let r=this.#e.get(e.id);if(r!==void 0)return r;let i=ho(t,"Node traversal admission failed",()=>this.context.traverseNode(e));if(typeof i!=="boolean")ve(t,"Node traversal admission must return boolean");let n=i||this.readNode(e,t);return this.#e.set(e.id,n),n}edge(e,t){let r=Ge(e),i=this.#t.get(r);if(i!==void 0)return i;let n=ho(t,"Edge traversal admission failed",()=>this.context.traverseEdge(e));if(typeof n!=="boolean")ve(t,"Edge traversal admission must return boolean");let o=n||this.readEdge(e,t);return this.#t.set(r,o),o}readNode(e,t){let r=this.#r.get(e.id);if(r!==void 0)return r;let i=ho(t,"Node read admission failed",()=>this.context.readNode(e));if(typeof i!=="boolean")ve(t,"Node read admission must return boolean");return this.#r.set(e.id,i),i}readEdge(e,t){let r=Ge(e),i=this.#n.get(r);if(i!==void 0)return i;let n=ho(t,"Edge read admission failed",()=>this.context.readEdge(e));if(typeof n!=="boolean")ve(t,"Edge read admission must return boolean");return this.#n.set(r,n),n}}function _Z(e){if(!nc(e))ve("","Reference context must be an object");for(let r of["resolve","closeDefinition","closeProperty","orientation","traverseNode","traverseEdge","readNode","readEdge"])if(typeof e[r]!=="function")ve(`/${r}`,`Reference ${r} must be callable`);let t;try{t=Hu.decode(e.graph)}catch(r){ve("/graph","Reference graph is invalid",r)}return Object.freeze({graph:t,nodes:new Map(t.nodes.map((r)=>[r.id,r])),edges:new Map(t.edges.map((r)=>[Ge(r),r])),resolve:e.resolve.bind(e),closeDefinition:e.closeDefinition.bind(e),closeProperty:e.closeProperty.bind(e),orientation:e.orientation.bind(e),traverseNode:e.traverseNode.bind(e),traverseEdge:e.traverseEdge.bind(e),readNode:e.readNode.bind(e),readEdge:e.readEdge.bind(e)})}function ln(e,t,r){let i=e.nodes.get(t);if(i===void 0)ve(r,`Node ${JSON.stringify(t)} is absent from reference graph`);return i}function N1(e,t,r){let i=e.edges.get(Ge(t));if(i===void 0)ve(r,"Edge is absent from reference graph");return i}function kl(e,t){if(typeof e!=="string")ve(t,"Expected NodeId string");try{return Fe(e)}catch(r){ve(t,"Invalid NodeId",r)}}function KD(e,t){if(typeof e!=="string")ve(t,"Expected ClassPath string");try{return Ze.parse(e)}catch(r){ve(t,"Invalid ClassPath",r)}}function R1(e,t){if(!nc(e)||!Sl(e,["source","target","class"]))ve(t,"EdgeKey must contain exactly source, target, and class");return Object.freeze({source:kl(e.source,`${t}/source`),target:kl(e.target,`${t}/target`),class:KD(e.class,`${t}/class`)})}function RB(e,t,r,i){let n=new Set;e.forEach((o,s)=>{let a=t(o);if(n.has(a))ve(`${r}/${s}`,`Duplicate ${i}`);n.add(a)})}function ho(e,t,r){try{return r()}catch(i){ve(e,t,i)}}function Sl(e,t){let r=Object.keys(e);return r.length===t.length&&r.every((i)=>t.includes(i))}function nc(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}function ve(e,t,r){throw new Bo(e,t,r===void 0?void 0:{cause:r})}function ZD(e,t,r,i,n){let{result:o}=r,s=o.graph.nodes,a=r.page.next??null,c=async(l)=>{if(a===null)return null;let d={...i,...l?.signal===void 0?{}:{signal:l.signal},...l?.timeoutMs===void 0?{}:{timeoutMs:l.timeoutMs},page:{size:l?.size??n,after:a}},f=await e(t,d);if(f.result.kind!=="graph"||f.result.selection.kind!=="node")throw TypeError("Node page continuation returned a non-Node graph result.");return ZD(e,t,f,i,l?.size??n)},u={nodes:s,first:s[0]??null,graph:o.graph,cursor:a,next:c,async collect(l){kZ(l.maximumPages);let d=[...s],f=u,m=1;while(f.cursor!==null&&m<l.maximumPages){let B=await f.next({...l.size===void 0?{}:{size:l.size},...l.signal===void 0?{}:{signal:l.signal},...l.timeoutMs===void 0?{}:{timeoutMs:l.timeoutMs}});if(B===null)break;d.push(...B.nodes),f=B,m+=1}return Object.freeze({nodes:Object.freeze(d),cursor:f.cursor})}};return Object.freeze(u)}function kZ(e){if(!Number.isSafeInteger(e)||e<1)throw TypeError("NodePage maximumPages must be a positive safe integer.")}async function WD(e,t,r,i){if(i===null||typeof i!=="object")throw TypeError("Neighbor read options are invalid.");let n=Array.isArray(r)?r:[r],[o,...s]=n;if(o===void 0)throw TypeError("Neighbor read requires at least one Definition.");let a=i.direction==="outgoing"?i.direction:i.direction==="incoming"?i.direction:i.direction==="incident"?i.direction:SZ(i.direction),c=$r.from({kind:"node",paths:[t]}).expand({via:[o,...s],direction:a}).select({kind:"graph"}),{direction:u,page:l,...d}=i,{idempotencyKey:f,...m}=d,B=await e(c,{...d,page:l});if(B.result.kind!=="graph"||B.result.selection.kind!=="node")throw TypeError("Neighbor query returned a non-Node graph result.");return ZD(e,c,B,m,l.size)}function SZ(e){throw TypeError(`Unsupported neighbor direction ${JSON.stringify(e)}.`)}var AZ=q.project(et.query.ref).raw;async function jB(e,t,r){let i=Ot.decode(t),{page:n,...o}=r,s=$Z(n),a=await e(tr(AZ,Object.freeze({ast:i,page:s})),o);return TZ(a)}function $Z(e){if(e===null||typeof e!=="object"||Array.isArray(e))throw TypeError("Graph query page is invalid.");if(!Number.isSafeInteger(e.size)||e.size<1)throw TypeError("Graph query page size must be a positive safe integer.");if(e.after!==void 0&&(typeof e.after!=="string"||e.after.length===0))throw TypeError("Graph query page continuation is invalid.");return Object.freeze({size:e.size,...e.after===void 0?{}:{after:e.after}})}function TZ(e){if(e===null||typeof e!=="object"||Array.isArray(e))throw TypeError("Graph query response is invalid.");let t=e;if(!j1(t,["result","page"]))throw TypeError("Graph query response is invalid.");let r=t.page;if(r===null||typeof r!=="object"||Array.isArray(r))throw TypeError("Graph query response page is invalid.");let i=r;if(!j1(i,i.next===void 0?[]:["next"]))throw TypeError("Graph query response page is invalid.");if(i.next!==void 0&&(typeof i.next!=="string"||i.next.length===0))throw TypeError("Graph query response continuation is invalid.");return Object.freeze({result:ol.decode(t.result),page:Object.freeze(i.next===void 0?{}:{next:i.next})})}function j1(e,t){let r=Object.keys(e);return r.length===t.length&&r.every((i)=>t.includes(i))}class PB extends X{code="NODE_UNAVAILABLE";path;constructor(e){let t=q.from(e).raw;super(`Node ${JSON.stringify(t)} is unavailable.`);this.name="NodeUnavailableError",this.path=t}}async function YD(e,t,r){let i=$r.from({kind:"node",paths:[t]}).select({kind:"graph"}),n=await jB(e,i,{...r,page:{size:1}}),{result:o}=n;if(o.kind!=="graph")throw TypeError("Node read returned a projection result.");return o.graph.nodes[0]??null}async function P1(e,t,r){let i=await YD(e,t,r);if(i===null)throw new PB(t);return i}function QD(e){if(typeof e!=="function")throw TypeError("Graph call capability is invalid.");let t=(i,n)=>jB(e,i,n);return Object.freeze({query:t,mutate:(i,n)=>g1(e,i,n),get:(i,n)=>YD(e,i,n),getOrThrow:(i,n)=>P1(e,i,n),neighbors:(i,n,o)=>WD(t,i,n,o)})}function ic(e){if(e===null||typeof e!=="object")throw TypeError("Kernel client adapter options are invalid.");let t=e.session,r=t.snapshot.bind(t),i=t.installed.bind(t),n=t.viewsFor.bind(t),o=t.call.bind(t),s=t.stream.bind(t),a=t.binary.bind(t),c=t.close.bind(t),u=NZ(e.graph??e.store?.graph??QD((b,O)=>o(b,O))),l=RZ(e.auth??gD((b,O,k)=>o(tr(b,O),k))),d=e.store,f=new Map,m=!1;function B(){if(m)throw Error("Kernel client adapter is closed.")}function h(b){if(B(),b===void 0)return r().then((G)=>{let oe=`${G.publication.origin}\x00${G.publication.schema.revision}`;return g(oe,async()=>Il(t,await i(G.publication.origin)))});let O=`${b.origin}\x00${Y.revision(b)}`,k=f.get(O);if(k!==void 0)return k;return g(O,async()=>Il(t,b,await i(b.origin)))}function g(b,O){let k=f.get(b);if(k!==void 0)return k;let G=O();return f.set(b,G),G.catch(()=>{if(f.get(b)===G)f.delete(b)}),G}let w={url:t.kernel,session:t,graph:u,auth:l,...d===void 0?{}:{store:d},snapshot(b){return B(),r(b)},viewsFor(b,O){return B(),n(b,O)},domain:h,call(b,O){return B(),o(b,O)},stream(b,O){return B(),s(b,O)},binary(b,O){return B(),a(b,O)},close(){if(m)return;m=!0,f.clear();try{d?.close()}finally{c()}}};return Object.freeze(w)}function NZ(e){return Object.freeze({query:e.query.bind(e),mutate:e.mutate.bind(e),get:e.get.bind(e),getOrThrow:e.getOrThrow.bind(e),neighbors:e.neighbors.bind(e)})}function RZ(e){return Object.freeze({provision:e.provision.bind(e),whoami:e.whoami.bind(e),whois:e.whois.bind(e),can:e.can.bind(e),mint:e.mint.bind(e),delegate:e.delegate.bind(e)})}var oc=120000;var Al=[1000,2000,4000],L1=2147483647;function LB(e){let t=e.now??Date.now,r=null,i=null,n=!1,o=null,s;function a(){if(n)return;if(r)clearTimeout(r);let f=e.token(),m=Math.max(f.expiresAt-t(),0),B=Math.min(oc,Math.floor(m/2)),h=Math.min(Math.max(m-B,1),L1);c(f.expiresAt),r=setTimeout(()=>{r=null,l()},h)}function c(f){if(i)clearTimeout(i);let m=Math.min(Math.max(f-t(),0),L1);i=setTimeout(()=>{if(i=null,n)return;if(e.token().expiresAt>t()){c(e.token().expiresAt);return}e.onFailure?.(s??Error("Delegated credential expired."))},m)}function u(){if(n||r!==null)return;let f=e.token().expiresAt-t();if(f<=0)return;r=setTimeout(()=>{r=null,l()},Math.min(f,Al[Al.length-1]))}function l(){if(o!==null)return o;return o=d().finally(()=>{o=null}),o}async function d(){if(n)return;e.onRefreshing?.();let f;for(let m=0;m<=Al.length;m+=1){if(n)return;try{let B=jZ(await e.mint(),t());if(n)return;e.setToken({credential:B.credential,expiresAt:B.expiresAt,issuedAt:t(),scope:{functionId:e.functionId}}),s=void 0,a();return}catch(B){if(f=B,s=B,m<Al.length)await PZ(Al[m])}}if(!n)e.onFailure?.(f),u()}return{start(){n=!1,a()},stop(){if(n=!0,r)clearTimeout(r);if(r=null,i)clearTimeout(i);i=null},async forceRefreshNow(){await l()},async refreshIfNeeded(){if(e.token().expiresAt-t()>oc)return;await l()}}}function jZ(e,t){if(typeof e.credential!=="string"||e.credential.trim().length===0||!Number.isSafeInteger(e.expiresAt)||e.expiresAt<=t)throw TypeError("Refreshed credential must be nonempty with a future safe expiry.");return e}function PZ(e){return new Promise((t)=>setTimeout(t,e))}function $l(e){let{observer:t,onDeliveryFailed:r}=e,i=t.notify.bind(t),n=new Map,o=new Map,s=new Set,a=!1;function c(u,l){let d=o.get(l.type);if(!d||d.size===0)return;for(let f of d)try{f(u,l)}catch{}}return{attach(u,l){if(a)throw Error("Children channel is disposed");if(u.length===0)throw TypeError("windowId must not be empty");if(n.get(u))throw Error(`Child '${u}' already attached`);let f=l.close.bind(l),m=l.onMessage.bind(l),B=l.send.bind(l),h=()=>{},g={send:B,close:f,unsubscribe:()=>h()};n.set(u,g);try{h=m((w)=>{if(n.get(u)!==g)return;i("inbound",w),c(u,w)})}catch(w){throw n.delete(u),f(),w}},detach(u){let l=n.get(u);if(!l)return;n.delete(u),l.unsubscribe(),l.close();for(let d of s)try{d(u)}catch{}},dispose(){if(a)return;a=!0;for(let u of n.values())u.unsubscribe(),u.close();n.clear(),o.clear(),s.clear()},send(u,l){let d=n.get(u);if(!d){r?.(u,l);return}i("outbound",l),d.send(l)},on(u,l){if(a)return()=>{};let d=o.get(u);if(!d)d=new Set,o.set(u,d);return d.add(l),()=>{d.delete(l)}},has(u){return n.has(u)},onClose(u){if(a)return()=>{};return s.add(u),()=>{s.delete(u)}}}}function sc(e){let{port:t,onClose:r}=e,i=t.postMessage.bind(t),n=t.addEventListener.bind(t),o=t.removeEventListener.bind(t),s=t.start.bind(t),a=t.close.bind(t),c=!1,u=new Set,l=(m)=>{if(c)return;if(typeof m!=="object"||m===null||!("data"in m)){f();return}let B;try{B=oh(m.data)}catch{f();return}for(let h of u)try{h(B)}catch{}},d=()=>{if(c)return;f()};n("message",l),n("messageerror",d),s();function f(){if(c)return;c=!0,o("message",l),o("messageerror",d),u.clear();try{a()}catch{}r?.()}return{send(m){if(c)return;i(m)},onMessage(m){if(c)return()=>{};return u.add(m),()=>{u.delete(m)}},close:f}}function Tl(){let e=new Set;return{notify(t,r){if(e.size===0)return;for(let i of e)try{i(r,t)}catch{}},subscribe(t){return e.add(t),()=>{e.delete(t)}}}}function z1(){let e=new Map;return{on(t,r){let i=e.get(t);if(!i)i=new Set,e.set(t,i);return i.add(r),()=>{i.delete(r)}},dispatch(t){let r=e.get(t.type);if(!r||r.size===0)return;for(let i of r)try{i(t)}catch{}},clear(){e.clear()}}}function XD(e){let{transport:t,observer:r}=e,i=t.close.bind(t),n=t.onMessage.bind(t),o=t.send.bind(t),s=r.notify.bind(r),a=z1(),c=!1,u=n((l)=>{if(c)return;s("inbound",l),a.dispatch(l)});return{send(l){if(c)return;s("outbound",l),o(l)},on(l,d){if(c)return()=>{};return a.on(l,d)},dispose(){if(c)return;c=!0,u(),a.clear(),i()}}}function zB(e,t){switch(e){case"opening":if(t.kind==="forceClose")return{ok:!0,next:"closed"};break;case"ready":if(t.kind==="hide")return{ok:!0,next:"suspended"};if(t.kind==="requestClose")return{ok:!0,next:"closing"};if(t.kind==="forceClose")return{ok:!0,next:"closed"};break;case"suspended":if(t.kind==="restore")return{ok:!0,next:"ready"};if(t.kind==="requestClose")return{ok:!0,next:"closing"};if(t.kind==="forceClose")return{ok:!0,next:"closed"};break;case"closing":if(t.kind==="closeAck")return{ok:!0,next:"closed"};if(t.kind==="closeRefuse")return{ok:!0,next:"ready"};if(t.kind==="forceClose")return{ok:!0,next:"closed"};break;case"closed":case"failed":break}return{ok:!1,reason:`invalid transition ${e}.${t.kind}`}}function Nl(e=()=>{}){let t=new Map;return{register(r,i="ready"){if(t.has(r))return;t.set(r,i)},apply(r,i){let n=t.get(r);if(n===void 0)return null;let o=zB(n,i);if(!o.ok)return null;return t.set(r,o.next),e(r,o.next),o.next},markCrashed(r){let i=t.get(r);if(i===void 0||i==="closed"||i==="failed")return;t.set(r,"failed"),e(r,"failed")},remove(r){t.delete(r)}}}var MZ={allowScripts:!0,allowForms:!1,allowPopups:!1,allowPopupsToEscapeSandbox:!1,allowSameOrigin:!1,allowModals:!1};function MB(e={}){return{resolve(t){return new URL(t,window.location.href)},decidePresentation(t){if(!(window.innerWidth<640)||t.preferred==="modal"||t.preferred==="window")return Object.freeze({kind:t.preferred,constrained:!1});let i=t.fallback?.find((n)=>n==="modal"||n==="inline");return Object.freeze({kind:i??"modal",constrained:!0})},focus(t){t.element.focus()},onActivation(t){let r=()=>{if(document.visibilityState!=="hidden")t()};return window.addEventListener("focus",r),document.addEventListener("visibilitychange",r),()=>{window.removeEventListener("focus",r),document.removeEventListener("visibilitychange",r)}},mount(t){if(t.isolation!=="sandboxed")throw Error(`iframe adapter only supports sandboxed windows, got '${t.isolation}'`);let r=document.createElement("iframe");if(r.dataset.astraleFunctionId=t.functionId,e.className)r.className=e.className;if(r.style.display="block",r.style.width="100%",r.style.height="100%",r.style.border="0",t.sandbox!==null){let n=t.sandbox??MZ;r.setAttribute("sandbox",UZ(n))}return r.setAttribute("loading","eager"),r.setAttribute("referrerpolicy","no-referrer"),{handle:{element:r,port:null,origin:""},dispose:()=>{r.remove()}}}}}function UZ(e){let t=[];if(e.allowScripts)t.push("allow-scripts");if(e.allowForms)t.push("allow-forms");if(e.allowPopups)t.push("allow-popups");if(e.allowPopupsToEscapeSandbox)t.push("allow-popups-to-escape-sandbox");if(e.allowSameOrigin)t.push("allow-same-origin");if(e.allowModals)t.push("allow-modals");return t.join(" ")}function Rl(e,t,r){let i=r,n=new Set;while(i!==void 0&&!n.has(i)){if(i===t)return!0;n.add(i),i=e.get(i)?.parentId}return!1}function M1(e){let{iframe:t,expectedOrigin:r,timeoutMs:i}=e,n=!1,o=!1,s=new Set,a,c,u=new Promise((B,h)=>{a=B,c=h}),l=setTimeout(()=>{if(o||n)return;o=!0,m(),c({code:"HANDSHAKE_TIMEOUT",message:`handshake timed out after ${i}ms`})},i);function d(B){if(o)return;o=!0,clearTimeout(l),m(),c(B)}function f(B){if(n||B.source!==t.contentWindow||!Kl(B.data))return;if(B.origin!==r){d({code:"ORIGIN_MISMATCH",message:`expected origin ${r}, got ${B.origin}`,actual:B.origin,expected:r});return}let h=new MessageChannel,g=h.port1;s.add(g);let w=setTimeout(()=>{if(s.delete(g),g.onmessage=null,g.close(),!o)d({code:"HANDSHAKE_TIMEOUT",message:`handshake timed out after ${i}ms`})},i);g.onmessage=(O)=>{try{uh(O.data,e.windowId)}catch{return}clearTimeout(w),s.delete(g),g.onmessage=null;let k={port:g};if(!o)o=!0,clearTimeout(l),a(k);else e.onReconnect(k)},g.start(),t.contentWindow?.postMessage({type:Bc,version:1,windowId:e.windowId},r,[h.port2]);let b=e.getCredential?.()??e;g.postMessage({type:"ctrl",version:1,action:"handshake",data:{delegationToken:b.delegationToken,tokenExpiresAt:b.tokenExpiresAt,windowId:e.windowId,kernelUrl:e.kernelUrl,functionId:e.functionId,targetNodeId:e.targetNodeId,mintIdentity:e.mintIdentity,capabilities:e.capabilities}})}function m(){if(n)return;n=!0,clearTimeout(l),window.removeEventListener("message",f);for(let B of s)B.onmessage=null,B.close();s.clear()}return window.addEventListener("message",f),{initial:u,dispose:m}}function ac(e,t){if(t!==void 0)return U1(t);return U1({target:e.target,view:e.route.key,params:{}})}function UB(e,t){let r=t.parentId===void 0?void 0:e.get(t.parentId);if(t.parentId!==void 0&&r===void 0)throw Error(`Parent window '${t.parentId}' is not live.`);let i=Object.freeze({windowId:t.windowId,...t.parentId===void 0?{}:{parentId:t.parentId},children:Object.freeze([]),functionId:t.view.route.key,targetNodeId:t.view.target,view:t.view,location:t.location,presentation:t.presentation,isolation:"sandboxed",state:t.state??"ready",credential:t.credential,capabilities:t.capabilities});if(e.set(t.windowId,i),r!==void 0)e.set(r.windowId,Object.freeze({...r,children:Object.freeze([...r.children,t.windowId])}));return i}function Es(e,t,r){let i=e.get(t);if(i===void 0)return;let n=Object.freeze(r(i));return e.set(t,n),n}function FB(e,t){let r=e.get(t);if(r===void 0)return;if(e.delete(t),r.parentId===void 0)return;let i=e.get(r.parentId);if(i===void 0)return;e.set(i.windowId,Object.freeze({...i,children:Object.freeze(i.children.filter((n)=>n!==t))}))}function U1(e){if(e===null||typeof e!=="object"||Array.isArray(e))throw TypeError("View location is invalid.");if(Object.keys(e).some((n)=>!["target","view","params"].includes(n)))throw TypeError("View location is invalid.");if(e.target!==void 0&&(typeof e.target!=="string"||e.target.length===0))throw TypeError("View location target is invalid.");if(e.view!==void 0&&(typeof e.view!=="string"||e.view.length===0))throw TypeError("View location key is invalid.");if(e.params===null||typeof e.params!=="object"||Array.isArray(e.params))throw TypeError("View location params are invalid.");let t=e.target===void 0?void 0:FZ(e.target),r=e.view===void 0?void 0:GZ(e.view),i=HZ(e.params);return Object.freeze({...t===void 0?{}:{target:t},...r===void 0?{}:{view:r},params:i})}function FZ(e){let t=q.parse(e);if(t.raw!==e)throw TypeError("View location target must be canonical.");return t.raw}function GZ(e){let t=Z(e);if(!Z.ref(t).startsWith("view."))throw TypeError("View location key is invalid.");return t}function HZ(e){let t=new WeakSet,r=(i,n)=>{if(n!==void 0&&/token|credential|authorization|secret/i.test(n))throw TypeError(`View location param '${n}' is sensitive.`);if(i===null||typeof i==="string"||typeof i==="boolean")return i;if(typeof i==="number"&&Number.isFinite(i))return i;if(typeof i!=="object"||ArrayBuffer.isView(i)||i instanceof ArrayBuffer)throw TypeError("View location params must be portable data.");if(t.has(i))throw TypeError("View location params cannot contain cycles.");t.add(i);try{if(Array.isArray(i))return Object.freeze(i.map((s)=>r(s)));let o=Object.getPrototypeOf(i);if(o!==Object.prototype&&o!==null)throw TypeError("View location params must be plain data.");return Object.freeze(Object.fromEntries(Object.entries(i).map(([s,a])=>[s,r(a,s)])))}finally{t.delete(i)}};return r(e)}var VZ=3000,qZ="<parent>";function F1(e){let{entries:t,children:r,windows:i,lifecycle:n}=e,o=async(s,a)=>{let c=t.get(s);if(!c)return{kind:"noop"};let u=a?.timeoutMs??VZ;if(!a?.force&&!c.plain){n.apply(s,{kind:"requestClose"});let d=await JZ(r,s,u);if(d.kind==="refused")return n.apply(s,{kind:"closeRefuse"}),{kind:"refused",reason:d.reason}}let l=i.get(s);for(let d of l?.children??[])await o(d,{force:!0,timeoutMs:u});return n.apply(s,{kind:"forceClose"}),c.refresher.stop(),t.delete(s),r.detach(s),FB(i,s),e.onWindowsChange?.(),c.dispose(),n.remove(s),{kind:"closed"}};return o}async function JZ(e,t,r){return new Promise((i)=>{let n=!1,o=e.on("intent",(a,c)=>{if(a!==t)return;if(c.envelope.name==="closeAck")n=!0,o(),clearTimeout(s),i({kind:"ack"});else if(c.envelope.name==="closeRefuse"){n=!0,o(),clearTimeout(s);let u=c.envelope.payload.reason;i({kind:"refused",reason:u})}}),s=setTimeout(()=>{if(n)return;o(),i({kind:"timeout"})},r);e.send(t,{type:"intent",version:1,envelope:{name:"willClose",payload:{},sender:{windowId:qZ}}})})}var jl={start:()=>{},stop:()=>{},forceRefreshNow:()=>Promise.resolve(),refreshIfNeeded:()=>Promise.resolve()};function G1(e){if(!Number.isSafeInteger(e.ttlSeconds)||e.ttlSeconds<1)throw TypeError("Delegation TTL must be a positive safe integer.");let t=async()=>{let n=await e.kernel.auth.mint({ttlSeconds:e.ttlSeconds});return e_({credential:n,expiresAt:Date.now()+e.ttlSeconds*1000})},r=e.provided;if(!r)return{acquire:t,refreshMint:t};let i=r.refresh?async()=>{let n=await r.refresh();return e_({credential:n.token,expiresAt:n.expiresAt})}:null;return{acquire:async()=>{let n={credential:r.token,expiresAt:r.expiresAt};if(i!==null&&(n.credential.length===0||n.expiresAt<=Date.now()))return await i();return e_(n)},refreshMint:i}}function e_(e){if(typeof e.credential!=="string"||e.credential.trim().length===0||!Number.isSafeInteger(e.expiresAt)||e.expiresAt<=Date.now())throw TypeError("Credential must be nonempty with a future safe expiry.");return Object.freeze(e)}function H1(e){let{windowId:t,refreshMint:r}=e;if(!r)return jl;let i=e.initial.expiresAt,n=e.initial.credential;return LB({functionId:e.functionId,token:()=>({credential:n,expiresAt:i,issuedAt:0,scope:{functionId:e.functionId}}),setToken:(o)=>{n=o.credential,i=o.expiresAt,e.onTokenChange?.(o),e.children.send(t,{type:"ctrl",version:1,action:"tokenRefresh",data:{delegationToken:o.credential,tokenExpiresAt:o.expiresAt}})},mint:r,onRefreshing:e.onRefreshing,onFailure:e.onFailure})}async function V1(e,t,r,i){let{adapter:n,windows:o,lifecycle:s,entries:a,close:c}=e,{route:u}=r.view,l=ac(r.view,r.location),d=i.presentation,{handle:f,dispose:m}=n.mount({functionId:u.key,isolation:"sandboxed",capabilities:r.capabilities,sandbox:r.sandbox});if(!(f.element instanceof HTMLIFrameElement))throw m(),Error("Shell adapter did not produce an HTMLIFrameElement");return r.host.appendChild(f.element),f.element.src=i.href,UB(o,{windowId:t,parentId:r.parentId,view:r.view,location:l,presentation:d,capabilities:r.capabilities,credential:Object.freeze({state:"none"})}),e.onWindowsChange?.(),s.register(t,"ready"),a.set(t,{handle:f,dispose:m,refresher:jl,plain:!0}),{windowId:t,get window(){return o.get(t)},handle:{element:f.element},credential:Object.freeze({state:"none"}),presentation:d,focus:()=>n.focus(f),close:(B)=>c(t,B)}}var KZ=5000,ZZ=3600,q1=Object.freeze({allowScripts:!0,allowForms:!1,allowPopups:!1,allowPopupsToEscapeSandbox:!1,allowSameOrigin:!0,allowModals:!1});function Pl(e){let{adapter:t,kernel:r,kernelUrl:i,mintIdentity:n,childrenChannel:o,windows:s,lifecycle:a}=e,c=t.resolve(i).href,u=new Map,l=0,d=!1,f=F1({entries:u,children:o,windows:s,lifecycle:a,onWindowsChange:e.onWindowsChange});function m(h){return l+=1,`win-${h.replace(/[^a-z0-9]/gi,"").slice(-8)||"fn"}-${l}`}return{async mount(h){if(d)throw Error("MountController is disposed");let{route:g,target:w}=h.view,b=g.key,O=t.resolve(g.href),k=O.href,G=g.handshake==="shell"?WZ(h.sandbox,O.origin,t.resolve("/").origin):h.sandbox,oe=ac(h.view,h.location),V=t.decidePresentation(h.presentation??{preferred:"inline"}),_e=h.parentId===void 0?e.parentCapabilities?.():s.get(h.parentId)?.capabilities;if(h.parentId!==void 0&&_e===void 0)throw Error(`Parent window '${h.parentId}' is not live.`);if(_e!==void 0)YZ(_e,O.origin,V.kind);let Mt=Tr(h.capabilities),pt=g.handshake==="none"?_i:_e===void 0?Mt:Wl(_e,Mt),Rt={...h,capabilities:pt,sandbox:G};if(g.handshake==="none"){let ct=m(b);return V1({adapter:t,windows:s,lifecycle:a,entries:u,close:f,onWindowsChange:e.onWindowsChange},ct,Rt,{href:k,presentation:V})}let xr=h.delegationTtlSeconds??ZZ,D=h.handshakeTimeoutMs??KZ,P=O.origin,R=m(b),{acquire:F,refreshMint:M}=G1({kernel:r,ttlSeconds:xr,provided:h.credential}),[{credential:de,expiresAt:fe},le]=await Promise.all([F(),Promise.resolve(t.mount({functionId:b,isolation:"sandboxed",capabilities:pt,sandbox:Rt.sandbox}))]),{handle:Ie,dispose:Se}=le;if(!(Ie.element instanceof HTMLIFrameElement))throw Se(),Error("Shell adapter did not produce an HTMLIFrameElement");UB(s,{windowId:R,parentId:h.parentId,view:h.view,location:oe,presentation:V,capabilities:pt,credential:Object.freeze({state:"none"}),state:"opening"}),e.onWindowsChange?.();let wt={delegationToken:de,tokenExpiresAt:fe},rr=0,Ht=jl;function Oi(ct){rr+=1;let Yr=rr;return sc({port:ct,onClose:()=>{if(Yr!==rr||!u.has(R))return;a.markCrashed(R),f(R,{force:!0}).catch(()=>{})}})}let Di=M1({iframe:Ie.element,expectedOrigin:P,windowId:R,delegationToken:de,tokenExpiresAt:fe,getCredential:()=>wt,kernelUrl:c,functionId:b,targetNodeId:w,mintIdentity:n,capabilities:pt,timeoutMs:D,onReconnect:({port:ct})=>{if(!u.has(R)){ct.close();return}let Yr=Oi(ct);o.detach(R),o.attach(R,Yr),Ht.refreshIfNeeded()}});h.host.appendChild(Ie.element),Ie.element.src=k;let vs;try{vs=await Di.initial}catch(ct){throw Di.dispose(),FB(s,R),e.onWindowsChange?.(),Se(),ct}let xs=Oi(vs.port);o.attach(R,xs),Es(s,R,(ct)=>({...ct,state:"ready",credential:Object.freeze({state:"valid",expiresAt:fe})})),e.onWindowsChange?.(),a.register(R,"ready"),Ht=H1({windowId:R,functionId:b,initial:{credential:de,expiresAt:fe},refreshMint:M,windows:s,children:o,onFailure:(ct)=>{Es(s,R,(Yr)=>Date.now()<wt.tokenExpiresAt?{...Yr,credential:Object.freeze({state:"degraded",expiresAt:wt.tokenExpiresAt,error:ct})}:{...Yr,credential:Object.freeze({state:"expired",error:ct,retry:()=>Ht.forceRefreshNow()})}),e.onWindowsChange?.()},onRefreshing:()=>{Es(s,R,(ct)=>({...ct,credential:Object.freeze({state:"refreshing",expiresAt:wt.tokenExpiresAt})})),e.onWindowsChange?.()},onTokenChange:(ct)=>{wt={delegationToken:ct.credential,tokenExpiresAt:ct.expiresAt},Es(s,R,(Yr)=>({...Yr,credential:Object.freeze({state:"valid",expiresAt:ct.expiresAt})})),e.onWindowsChange?.()}}),Ht.start();let yo=t.onActivation?.(()=>void Ht.refreshIfNeeded())??(()=>{});return u.set(R,{handle:Ie,dispose:()=>{yo(),Di.dispose(),Se()},refresher:Ht}),{windowId:R,get window(){return s.get(R)},handle:{element:Ie.element},get credential(){return s.get(R)?.credential??Object.freeze({state:"none"})},presentation:V,focus:()=>t.focus(Ie),close:(ct)=>f(R,ct)}},close:f,focus(h){let g=u.get(h),w=s.get(h);if(g===void 0||w===void 0||w.state!=="ready"&&w.state!=="suspended")return!1;return t.focus(g.handle),!0},async dispose(){if(d)return;d=!0;let h=[...u.keys()];await Promise.all(h.map((g)=>f(g,{force:!0})))}}}function WZ(e,t,r){if(t===r)throw TypeError("Shell-handshake Views must use a distinct origin so scripts cannot escape the origin-preserving sandbox.");if(e===null)throw TypeError("Shell-handshake Views cannot disable iframe sandboxing.");let i=e??q1;if(i.allowScripts!==!0||i.allowSameOrigin!==!0)throw TypeError("Shell-handshake Views require allowScripts and allowSameOrigin so the admitted route origin is observable.");for(let n of["allowScripts","allowForms","allowPopups","allowPopupsToEscapeSandbox","allowSameOrigin","allowModals"])if(typeof i[n]!=="boolean")throw TypeError("Shell-handshake sandbox flags must be boolean.");if(Object.keys(i).some((n)=>!["allowScripts","allowForms","allowPopups","allowPopupsToEscapeSandbox","allowSameOrigin","allowModals"].includes(n)))throw TypeError("Shell-handshake sandbox profiles are closed.");if(i.allowForms!==!1||i.allowPopups!==!1||i.allowPopupsToEscapeSandbox!==!1||i.allowModals!==!1)throw TypeError("Shell-handshake Views cannot grant forms, popups, modal dialogs, or sandbox escape outside typed host actions.");return q1}function YZ(e,t,r){let i=e.navigation.openView;if(i===void 0)throw Error("Host does not grant opening nested Views.");if(i.origins!==void 0&&!i.origins.includes(t))throw Error(`Host does not grant View origin '${t}'.`);if(i.presentations!==void 0&&!i.presentations.includes(r))throw Error(`Host does not grant '${r}' View presentation.`)}function cc(e){let{lookup:t,onViolation:r,selfWindowId:i}=e,n=e.allowSelf??!0;return async(o,s)=>{let a=o.envelope.sender.windowId;if(n&&i!==void 0&&a===i){await s();return}if(a==="<parent>"){await s();return}let c=t(a),u=o.envelope.name,d=e.credential?.(a)?.state==="expired"?"credential":c===void 0?"unsupported":n9(c,o,e);if(d!==!0){r?.({sender:a,intent:u,reason:d});return}await s()}}var XZ=new Set(["willClose","closeAck","closeRefuse","intentReply","setTarget"]),e9=new Set(["inline","panel","modal","window"]),t9=new Set(["info","success","warning","error"]),r9=4294967295;function n9(e,t,r){let i=t.envelope.name;if(XZ.has(i))return!0;switch(i){case"view.open":{let n=e.navigation.openView;if(n===void 0)return"unsupported";let o=t.envelope.payload;if(!J1(o))return"constraint";if(o.presentation!==void 0&&n.presentations!==void 0&&!n.presentations.includes(o.presentation))return"constraint";if(n.maximumDepth!==void 0&&(r.depth?.(t.envelope.sender.windowId)??1)>n.maximumDepth)return"constraint";return!0}case"view.close":case"view.focus":{let n=t.envelope.payload;if(!i9(i,n))return"constraint";let o=n.windowId;return typeof o==="string"&&r.owns?.(t.envelope.sender.windowId,o)===!0?!0:"constraint"}case"navigation.commit":{if(e.navigation.history===void 0)return"unsupported";let n=t.envelope.payload;if(!o9(n))return"constraint";let o=n.mode;if(o!=="push"&&o!=="replace")return"constraint";if(o==="replace"&&e.navigation.replace!==!0)return"constraint";return!0}case"actions.modal":{let n=e.actions.modal;if(n===void 0)return"unsupported";let o=t.envelope.payload;if(!u9(o))return"constraint";let s=o.nested;if(s===void 0)return!0;if(n.nestedViews!==!0)return"constraint";let a=e.navigation.openView;if(a===void 0)return"constraint";let c=s.presentation??"modal";if(a.presentations!==void 0&&!a.presentations.includes(c))return"constraint";if(a.maximumDepth!==void 0&&(r.depth?.(t.envelope.sender.windowId)??1)>a.maximumDepth)return"constraint";return!0}case"actions.notify":{let n=e.actions.notify;if(n===void 0)return"unsupported";let o=t.envelope.payload;if(!l9(o))return"constraint";return n.tones===void 0||n.tones.includes(o.tone)?!0:"constraint"}case"browser.openExternal":{let n=e.navigation.external;if(n===void 0)return"unsupported";let o=t.envelope.payload;if(!s9(o))return"constraint";try{let s=new URL(o.url);return s.protocol==="https:"&&n.origins.includes(s.origin)?!0:"constraint"}catch{return"constraint"}}case"access.request":{let n=e.access.request;if(n===void 0)return"unsupported";let o=t.envelope.payload;if(!a9(o))return"constraint";let s=o.permissions;return n.maximumPermissions===void 0||s.length<=n.maximumPermissions?!0:"constraint"}case"requestAccess":{let n=e.access.request;if(n===void 0)return"unsupported";let o=t.envelope.payload;if(!c9(o))return"constraint";let s=o.perms;if(!Number.isSafeInteger(s)||s<0||s>r9)return"constraint";return n.maximumPermissions===void 0||d9(s)<=n.maximumPermissions?!0:"constraint"}default:return"unsupported"}}function i9(e,t){if(!go(t,e==="view.close"?["windowId","force"]:["windowId"]))return!1;return typeof t.windowId==="string"&&t.windowId.length>0&&(e!=="view.close"||t.force===void 0||typeof t.force==="boolean")}function o9(e){if(!go(e,["mode","target","view","params"]))return!1;if(e.mode!=="push"&&e.mode!=="replace")return!1;if(e.target!==void 0&&!W1(e.target))return!1;if(e.view!==void 0&&!Z1(e.view))return!1;return K1(e.params)}function s9(e){return go(e,["url","mode"])&&typeof e.url==="string"&&(e.mode===void 0||e.mode==="tab"||e.mode==="popup")}function a9(e){if(!go(e,["node","identity","permissions","reason"]))return!1;return Ll(e.node)&&GB(e.node)&&Ll(e.identity)&&GB(e.identity)&&Array.isArray(e.permissions)&&e.permissions.every(Ll)&&(e.reason===void 0||typeof e.reason==="string")}function c9(e){return go(e,["node","identity","perms","reason"])&&Ll(e.node)&&GB(e.node)&&Ll(e.identity)&&GB(e.identity)&&typeof e.perms==="number"&&(e.reason===void 0||typeof e.reason==="string")}function J1(e){if(!go(e,["view","target","presentation","params"]))return!1;if(!Z1(e.view))return!1;if(e.target!==void 0&&!W1(e.target))return!1;if(e.presentation!==void 0&&(typeof e.presentation!=="string"||!e9.has(e.presentation)))return!1;return e.params===void 0||K1(e.params)}function u9(e){if(!go(e,["title","description","confirmLabel","cancelLabel","nested"]))return!1;if(typeof e.title!=="string"||e.title.length===0)return!1;for(let t of["description","confirmLabel","cancelLabel"])if(e[t]!==void 0&&typeof e[t]!=="string")return!1;return e.nested===void 0||J1(e.nested)}function l9(e){if(!go(e,["tone","title","description","dedupeKey"]))return!1;if(typeof e.tone!=="string"||!t9.has(e.tone))return!1;if(typeof e.title!=="string"||e.title.length===0)return!1;return(e.description===void 0||typeof e.description==="string")&&(e.dedupeKey===void 0||typeof e.dedupeKey==="string")}function go(e,t){return typeof e==="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).every((r)=>t.includes(r))}function K1(e){if(typeof e!=="object"||e===null||Array.isArray(e))return!1;let t=new WeakSet,r=(i,n)=>{if(n!==void 0&&/token|credential|authorization|secret/i.test(n))return!1;if(i===null||typeof i==="string"||typeof i==="boolean")return!0;if(typeof i==="number")return Number.isFinite(i);if(typeof i!=="object"||ArrayBuffer.isView(i)||i instanceof ArrayBuffer)return!1;if(t.has(i))return!1;t.add(i);try{if(Array.isArray(i))return i.every((s)=>r(s));let o=Object.getPrototypeOf(i);if(o!==Object.prototype&&o!==null)return!1;return Object.entries(i).every(([s,a])=>r(a,s))}finally{t.delete(i)}};return r(e)}function Ll(e){return typeof e==="string"&&e.length>0}function Z1(e){if(typeof e!=="string")return!1;try{let t=Z(e);return Z.ref(t).startsWith("view.")}catch{return!1}}function W1(e){if(typeof e!=="string")return!1;try{return q.parse(e).raw===e}catch{return!1}}function GB(e){try{return Fe(e)===e}catch{return!1}}function d9(e){let t=e>>>0,r=0;while(t!==0)t&=t-1,r+=1;return r}function uc(){let e=[];return{use(t){e.push(t)},async run(t,r){let i=-1,n=async(o)=>{if(o<=i)throw Error("next() called multiple times");if(i=o,o===e.length){await r();return}let s=e[o];await s(t,()=>n(o+1))};await n(0)}}}function Y1(){return(e,t)=>{if(t.origin==="self")return t.hasParent?{kind:"parent",message:e}:{kind:"local",message:e};return{kind:"local",message:e}}}function Q1(e,t){return{...e,envelope:{...e.envelope,sender:{windowId:t}}}}function lc(e){let{pipeline:t,parent:r,children:i,selfWindowId:n}=e,o=t.run.bind(t),s=r?.send.bind(r),a=i.has.bind(i),c=i.send.bind(i),u=Y1(),l=new Map;async function d(m){switch(m.kind){case"drop":return;case"parent":if(!s)return;s(m.message);return;case"child":if(!a(m.windowId))return;c(m.windowId,m.message);return;case"local":{let B=l.get(m.message.envelope.name);if(!B)return;for(let h of B)try{await h(m.message)}catch{}return}}}let f={selfWindowId:n,hasParent:s!==void 0};return{async handleInbound(m,B,h){if(h.length===0)throw TypeError("senderWindowId must not be empty");let g=Q1(B,h);await o(g,async()=>{let w=await u(g,{...f,origin:m});await d(w)})},async dispatchLocal(m){let B=Q1(m,n);await o(B,async()=>{let h=await u(B,{...f,origin:"self"});await d(h)})},setPolicy(m){u=m},onLocal(m,B){let h=l.get(m);if(!h)h=new Set,l.set(m,h);return h.add(B),()=>{h.delete(B)}}}}function HB(e,t,r,i){let n=r.envelope.correlationId;if(!n)return;e.send.bind(e)(t,{type:"intent",version:1,envelope:{name:"intentReply",payload:{correlationId:n,result:i},sender:{windowId:"root"}}})}function VB(e,t,r,i){let n=r.envelope.correlationId;if(!n)return;e.send.bind(e)(t,{type:"intent",version:1,envelope:{name:"intentReply",payload:{correlationId:n,error:{message:i instanceof Error?i.message:String(i)}},sender:{windowId:"root"}}})}var g9=new WeakMap,ez=Object.freeze({node(e,t){let r=$r.from({kind:"node",paths:[t]});return qB(e,r.filter({satisfies:e.schemaRef}),!1)},nodes(e){return qB(e,$r.from({kind:"node",definitions:[e.schemaRef]}),!0)}});function tz(e){if(!nz(e))return e;let t=e.compile();return g9.set(t,e),t}function rz(e){return nz(e)?e.many:void 0}function qB(e,t,r,i=t_(e),n=e){let s={...{current:i,...n===void 0?{}:{bindDefinition:n},builder:t,many:r,compile(){if(!("node"in t))throw TypeError("Node Query selection lost its node binding.");return t.select({kind:"nodes",projection:{kind:"value"}})},project(a,c){let u=a.nodes.map((l)=>n===void 0?c(l.value):c(n,l.value));return r?Object.freeze(u):u[0]??null}},__many:r,where(a){if(a===null||typeof a!=="object"||a.property===null||typeof a.property!=="object"||!("key"in a.property))throw TypeError("Node Query where requires one rich Property.");let c=Object.hasOwn(a,"equals"),u=a.present===!0;if(c===u)throw TypeError("Node Query where requires exactly one of equals or present.");let l=c?Dl(a.property.key).equals(a.equals):Dl(a.property.key).isPresent();return qB(e,t.filter({predicate:l}),r,i,n)},when(a,c){let u=s;return a===void 0||a===null||a===!1?u:c(u,a)},linked(a,c){if(c===null||typeof c!=="object"||c.to===void 0)throw TypeError("Node Query linked requires an accepted rich to definition.");let u=c?.from??y9(i,a);if(!JB(zl(a,u).accepts,i))throw TypeError(`Relation ${a.key} does not accept the current selection at its ${u} endpoint.`);let l=t.expand({via:[a.schemaRef],direction:u==="source"?"outgoing":"incoming"}).filter({satisfies:c.to.schemaRef}),d=zl(a,u==="source"?"target":"source");if(!JB(d.accepts,t_(c.to)))throw TypeError(`Relation ${a.key} does not accept ${c.to.key} at its opposite endpoint.`);return Object.freeze({...qB(c.to,l,r||!b9(a,u),t_(c.to),c.to)})}};return Object.freeze(s)}function y9(e,t){let r=JB(zl(t,"source").accepts,e),i=JB(zl(t,"target").accepts,e);if(r===i)throw TypeError(r?`Relation ${t.key} accepts the current selection at both endpoints; declare from.`:`Relation ${t.key} does not accept the current selection.`);return r?"source":"target"}function JB(e,t){return e.some((r)=>t.some((i)=>C9(r,i)))}function t_(e){let t=[],r=new Set,i=(n)=>{let o=n.schemaRef,s=`${o.origin}\x00${o.kind}\x00${o.name}`;if(r.has(s))return;r.add(s),t.push(o);let a=n.kind==="class"?n.implements:n.extends;for(let c of a??[])i(c)};return i(e),Object.freeze(t)}function C9(e,t){return e.origin===t.origin&&e.kind===t.kind&&e.name===t.name}function b9(e,t){let r=E9(zl(e,t));return r==="1"||r==="0..1"}function zl(e,t){if(e.definition.endpoints===void 0)throw TypeError(`Relation ${e.key} has no Edge endpoints.`);let i=e.definition;if(i.orientation==="directed")return i.endpoints[t];return i.endpoints[t==="source"?0:1]}function E9(e){if("outgoing"in e)return e.outgoing;if("incoming"in e)return e.incoming;return e.incident}function nz(e){return e!==null&&typeof e==="object"&&typeof e.compile==="function"}var iz=1024,v9=256;function x9(e){let t=e.build;return oz({...e,build(r){let i=t(r,ez);if(e.pagination!==void 0&&rz(i)===!1)throw TypeError("Node Query pagination requires an extent selection.");return tz(i)}},"single","build")}function w9(e){return oz(e,"composite","compose")}function oz(e,t,r){if(e===null||typeof e!=="object"||Array.isArray(e))throw TypeError("Query definition must be an object.");let i=e.id;if(typeof i!=="string"||i.length===0||i.trim()!==i)throw TypeError("Query definition id must be a non-empty stable string.");if(typeof e[r]!=="function")throw TypeError(`Query definition ${r} must be a function.`);for(let s of["prepare","project","reject"])if(e[s]!==void 0&&typeof e[s]!=="function")throw TypeError(`Query definition ${s} must be a function.`);let n=e.pagination;if(t==="composite"){if(Object.hasOwn(e,"page"))throw TypeError("Composite Query definitions cannot declare a page.");if(n!==void 0)throw TypeError("Composite Query definitions cannot declare pagination.");return Object.freeze({...e,kind:t})}let o=I9(e.page);if(n!==void 0){if(typeof e.project!=="function")throw TypeError("Paginated Query definitions must declare a project function.");if(n===null||typeof n!=="object"||Array.isArray(n)||Reflect.ownKeys(n).length!==1||!Object.hasOwn(n,"maximumPages"))throw TypeError("Query pagination must contain only maximumPages.");let s=n.maximumPages;if(!Number.isSafeInteger(s)||s<1||s>iz)throw TypeError(`Query pagination maximumPages must be a safe integer from 1 through ${iz}.`);return Object.freeze({...e,page:o,pagination:Object.freeze({maximumPages:s}),kind:t})}return Object.freeze({...e,page:o,kind:t})}function I9(e){if(e===void 0)return Object.freeze({size:v9});if(e===null||typeof e!=="object"||Array.isArray(e)||Reflect.ownKeys(e).length!==1||!Object.hasOwn(e,"size"))throw TypeError("Query page must contain only size.");let t=e.size;if(!Number.isSafeInteger(t)||t<1)throw TypeError("Query page size must be a positive safe integer.");return Object.freeze({size:t})}var O9=Object.assign(x9,{composite:w9});var TPe=Symbol("astrale.sdk.query.plan"),NPe=Symbol("astrale.sdk.query.reference");function KB(e,t){if(e.kind==="graph")return $9(e,t);if(e.kind!=="nodes")throw TypeError(`Expected a Node ${t} query result.`);return Object.freeze(e.nodes.map((r)=>{if(r.kind!=="value")throw TypeError(`Expected ${t} query to project Node values.`);return r.value}))}function $9(e,t){if(e.selection.kind!=="node")throw TypeError(`Expected a Node ${t} query result.`);let r=new Map(e.graph.nodes.map((i)=>[i.id,i]));return Object.freeze(e.selection.ids.map((i)=>{let n=r.get(i);if(n===void 0)throw TypeError(`${t} graph omits selected Node ${i}.`);return n}))}function T9(e,t){return Object.freeze(e.flatMap((r)=>KB(r,t)))}function sz(e,t){if(e.kind==="graph"){if(e.selection.kind!=="node")throw TypeError(`Expected a Node ${t} query result.`);return e.selection.ids}if(e.kind!=="nodes")throw TypeError(`Expected a Node ${t} query result.`);return Object.freeze(e.nodes.map((r)=>r.value.id))}function N9(e,t){return Object.freeze(e.flatMap((r)=>sz(r,t)))}function R9(e,t){let r=KB(e,t);if(r.length!==1)throw TypeError(`${t} must resolve exactly one Node.`);return r[0]}function j9(e,t){let r=KB(e,t);if(r.length>1)throw TypeError(`${t} must resolve at most one Node.`);return r[0]}function ZB(e,t){if(e.kind!=="edges")throw TypeError(`Expected an Edge ${t} query result.`);return e.edges}function P9(e,t){let r=ZB(e,t);if(r.length>1)throw TypeError(`${t} must resolve at most one Edge.`);let i=r[0]?.target;if(i===void 0)return;if(i.kind!=="value")throw TypeError(`${t} must project its target value.`);return i.value}function L9(e,t){let r=ZB(e,t);if(r.length!==1)throw TypeError(`${t} must resolve exactly one Edge.`);let i=r[0].target;if(i.kind!=="value")throw TypeError(`${t} must project its target value.`);return i.value}function z9(e,t){let r=ZB(e,t);if(r.length!==1)throw TypeError(`${t} must resolve exactly one Edge.`);let i=r[0].source;if(i.kind!=="value")throw TypeError(`${t} must project its source value.`);return i.value}var az=Object.freeze({nodeValues:KB,completeNodeValues:T9,nodeIds:sz,completeNodeIds:N9,exactlyOneNode:R9,optionalNode:j9,edgeItems:ZB,optionalEdgeTarget:P9,exactlyOneEdgeTarget:L9,exactlyOneEdgeSource:z9});var Ml=new TextDecoder;function cz(e){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(e);let t=atob(e),r=new Uint8Array(t.length);for(let i=0;i<t.length;i++)r[i]=t.charCodeAt(i);return r}function uz(e){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(typeof e==="string"?e:Ml.decode(e),{alphabet:"base64url"});let t=e;if(t instanceof Uint8Array)t=Ml.decode(t);t=t.replace(/-/g,"+").replace(/_/g,"/");try{return cz(t)}catch{throw TypeError("The input to be decoded is not correctly encoded.")}}class r_ extends Error{static code="ERR_JOSE_GENERIC";code="ERR_JOSE_GENERIC";constructor(e,t){super(e,t);this.name=this.constructor.name,Error.captureStackTrace?.(this,this.constructor)}}class Ii extends r_{static code="ERR_JWT_INVALID";code="ERR_JWT_INVALID"}class M9 extends r_{[Symbol.asyncIterator];static code="ERR_JWKS_MULTIPLE_MATCHING_KEYS";code="ERR_JWKS_MULTIPLE_MATCHING_KEYS";constructor(e="multiple matching keys found in the JSON Web Key Set",t){super(e,t)}}var U9=(e)=>typeof e==="object"&&e!==null;function lz(e){if(!U9(e)||Object.prototype.toString.call(e)!=="[object Object]")return!1;if(Object.getPrototypeOf(e)===null)return!0;let t=e;while(Object.getPrototypeOf(t)!==null)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function n_(e){if(typeof e!=="string")throw new Ii("JWTs must use Compact JWS serialization, JWT must be a string");let{1:t,length:r}=e.split(".");if(r===5)throw new Ii("Only JWTs using Compact JWS serialization can be decoded");if(r!==3)throw new Ii("Invalid JWT");if(!t)throw new Ii("JWTs must contain a payload");let i;try{i=uz(t)}catch{throw new Ii("Failed to base64url decode the payload")}let n;try{n=JSON.parse(Ml.decode(i))}catch{throw new Ii("Failed to parse the decoded payload as JSON")}if(!lz(n))throw new Ii("Invalid JWT Claims Set");return n}function Wr(e){if(e instanceof q)return e;return e.startsWith("@")||e.startsWith("/")?q.parse(e):q.id(Fe(e))}function Ul(e){return Object.freeze({origin:e.origin,kind:e.kind,name:e.name})}function dc(e,t){let r=e.$.class(t);if(r.family!=="node")throw TypeError(`Shell ${t} is not a Node Class.`);return r}function fc(e,t){let r=e.$.class(t);if(r.family!=="edge")throw TypeError(`Shell ${t} is not an Edge Class.`);return r}async function dz(e,t,r,i){let n=t.$.method(r);if("on"in n)throw TypeError(`Shell ${t.name}.${r} is not static.`);let o=e.$.invoke;return await o(n,i)}async function WB(e,t,r){return await e.$.method(t)(r)}function fz(e){let t=null,r=()=>t??=e.domain();return{get:r,async bindAs(i,n){let o=await r(),s=dc(o,i);if(!o.$.bind(n).$.definition.satisfies(s))return null;let c=o.$.bind;return c(s,n)}}}class Fl extends Error{step;constructor(e,t,r){super(`AppSession token refresh failed at '${e}' for @${t}`,r);this.name="AppSessionRefreshError",this.step=e}}function pz(e){let{app:t,now:r}=e,i=null,n=null;async function o(){try{let a=await WB(t,"getToken",{});if(typeof a!=="string"||a.length===0)throw TypeError("Application.getToken returned an invalid credential.");let c=n_(a).exp;if(typeof c!=="number"||!Number.isFinite(c))throw TypeError("Application.getToken returned a credential without expiry.");return Object.freeze({token:a,expiresAt:c*1000})}catch(a){throw new Fl("getToken",t.id,{cause:a})}}function s(){if(n)return n;let a=o().then((c)=>(i=c,c)).finally(()=>{if(n===a)n=null});return n=a,a}return{current:()=>i,needsRefresh:()=>i===null||i.expiresAt-r()-oc<=0,refresh:s}}async function YB(e,t){let{kernel:r}=e,i=q.id(t.id).raw,o=(await r.viewsFor(i)).views[0],s=o===void 0?null:Object.freeze({target:i,route:o}),a=pz({app:t,now:e.now??Date.now}),c=!1;async function u(){if(c)throw Error("AppSession is disposed");if(a.needsRefresh())return(await a.refresh()).token;return a.current().token}let l={get token(){return a.current()?.token??""},get expiresAt(){return a.current()?.expiresAt??0},refresh:async()=>{if(c)throw Error("AppSession is disposed");let d=await a.refresh();return{token:d.token,expiresAt:d.expiresAt}}};return{app:t.id,view:s,credential:l,token:u,dispose(){c=!0}}}var mz=200,QB=1000;function Bz(e,t,r){return{async install(i,n){let o=await t.get(),s=dc(o,"Application"),a=i.startsWith("@")||i.startsWith("/")?Wr(i).raw:q.domain(i).raw,c=await dz(o,s,"install",{domain:a,space:Wr(n).raw}),u=await e.graph.get(q.parse(c.application.path)),l=u===null?null:await t.bindAs("Application",u);if(l===null)throw Error(`Application.install: app @${c.application.id} is not readable`);return l},async searchDomains(){let i=ge.Domain.$.property("origin").key,n=$r.from({kind:"node",definitions:[Ul(ge.Domain)]}).select({kind:"graph",order:{property:i,direction:"asc",unranked:"last"}}),o=[],s;for(let a=0;a<QB;a+=1){let c=await e.graph.query(n,{page:{size:mz,...s===void 0?{}:{after:s}}}),u=c.result;if(u.kind!=="graph")throw TypeError("Domain query returned a projection result.");for(let l of u.graph.nodes){let d=l.props[i];if(typeof d==="string")o.push({origin:d})}if(s=c.page.next,s===void 0)return o}throw Error(`Domain query exceeded ${QB} pages.`)},async in(i){let n=await t.get(),o=fc(n,"installed_in"),s=await e.graph.neighbors(Wr(i),Ul(o),{direction:"incoming",page:{size:mz}}),{nodes:a,cursor:c}=await s.collect({maximumPages:QB});if(c!==null)throw Error(`Application query exceeded ${QB} pages.`);return(await Promise.all(a.map((l)=>t.bindAs("Application",l)))).flatMap((l)=>l===null?[]:[l])},async open(i){let n=await e.graph.get(Wr(i)),o=n===null?null:await t.bindAs("Application",n);if(o===null)throw Error(`apps.open: application ${Wr(i).raw} is not readable`);return YB({kernel:e,...r?.now===void 0?{}:{now:r.now}},o)}}}var F9=200,hz=1000,gz=Ur("createdSpace");function yz(e,t){return{async list(){let r=await t.get(),i=dc(r,"Space"),n=$r.from({kind:"node",definitions:[Ul(i)]}).select({kind:"graph",order:{property:ge.Named.$.property("name").key,direction:"asc",unranked:"last"}}),o=await G9(e,n);return(await Promise.all(o.map((a)=>t.bindAs("Space",a)))).flatMap((a)=>a===null?[]:[a])},async get(r){let i=await e.graph.get(Wr(r));return i===null?null:t.bindAs("Space",i)},async create(r){let[i,n]=await Promise.all([t.get(),e.auth.whoami()]),o=dc(i,"Space"),s=fc(i,"owns_space"),c=(await e.graph.mutate((d)=>{let f=d.createNode({as:gz,class:Ze.from(o),props:{[ge.Named.$.property("name").key]:r?.name??"Untitled Space"}});d.createEdge({class:Ze.from(s),source:q.id(n.id),target:f})})).createdNodes[gz];if(c===void 0)throw Error("Space creation omitted its created Node.");let u=await e.graph.get(q.id(c)),l=u===null?null:await t.bindAs("Space",u);if(l===null)throw Error(`Created Space @${c} is not readable.`);return l}}}async function G9(e,t){let r=[],i;for(let n=0;n<hz;n+=1){let o=await e.graph.query(t,{page:{size:F9,...i===void 0?{}:{after:i}}}),s=o.result;if(s.kind!=="graph")throw TypeError("Space query returned a projection result.");if(r.push(...s.graph.nodes),i=o.page.next,i===void 0)return Object.freeze(r)}throw Error(`Space query exceeded ${hz} pages.`)}function Cz(e,t){async function r(){let i=await e.auth.whoami(),n=await e.graph.getOrThrow(q.id(i.id)),o=await t.bindAs("User",n);if(o===null)throw Error(`whoami identity @${i.id} is not a shell User`);return o}return{me:r,async currentSpace(){let i=await t.get(),n=await r(),o=fc(i,"default_space"),s=await e.graph.neighbors(q.id(n.id),o.schemaRef,{direction:"outgoing",page:{size:1}});return s.first===null?null:t.bindAs("Space",s.first)},async switchSpace(i){let n=await e.graph.get(Wr(i)),o=n===null?null:await t.bindAs("Space",n);if(o===null)throw Error(`Space ${Wr(i).raw} is not readable.`);await WB(o,"setDefault",{})}}}var H9=Object.freeze([]);function bz(e){return{async resolve(t){let r=Wr(t).raw,{views:i}=await e.viewsFor(r);if(i.length===0)return H9;return Object.freeze(i.map((n)=>Object.freeze({target:r,route:n})))}}}function XB(e,t){let r=fz(e);return{user:Cz(e,r),spaces:yz(e,r),apps:Bz(e,r,t),views:bz(e)}}function eh(e){let t=!1,r=null,i=()=>r??=XB(e.kernel),n={get parent(){return e.parent},children:e.childrenChannel,kernel:e.kernel,windows:e.windows,get targetNodeId(){return e.targetNodeId?.()},get hostCapabilities(){return e.hostCapabilities()},get user(){return i().user},get spaces(){return i().spaces},get apps(){return i().apps},get views(){return i().views},use(o){return e.pipeline.use(o),n},onMessage(o){return e.observer.subscribe(o)},onIntent(o,s){return e.onIntent(o,s)},onTargetChange(o){return e.onTargetChange?.(o)??(()=>{})},onWindowChange(o){return e.onWindowChange?.(o)??(()=>{})},openView(o){return e.getMountController().mount(o)},updateLocation(o,s){let a=e.windows.get(o);if(a===void 0)throw Error(`Window '${o}' is not live.`);let c=ac(a.view,s);if(c.view!==void 0&&c.view!==a.view.route.key)throw Error("Changing a window route requires opening a new View generation.");let u=Es(e.windows,o,(l)=>({...l,targetNodeId:c.target,location:c}));if(e.notifyWindows?.(),c.target!==a.targetNodeId)e.childrenChannel.send(o,{type:"intent",version:1,envelope:{name:"setTarget",payload:c.target===void 0?{}:{nodeId:c.target},sender:{windowId:"<parent>"}}});return u},focusView(o){let s=e.windows.get(o);if(s===void 0||s.state==="closed"||s.state==="failed")return!1;return e.getMountController().focus(o)},close(o,s){return e.getMountController().close(o,s)},async init(){if(e.init)await e.init();return n},async dispose(){if(t)return;t=!0,await e.onDispose()}};return n}var V9=5000;function th(e){let{parent:t}=e,r=e.timeoutMs??V9;return new Promise((i,n)=>{let o=null,s=setTimeout(()=>{a(),n(Error(`Shell child init timed out after ${r}ms`))},r);function a(){if(clearTimeout(s),window.removeEventListener("message",u),o)o.onmessage=null}function c(l){return(d)=>{let f;try{f=ch(d.data)}catch{return}let m=f.data;l.postMessage({type:"ctrl",version:1,action:"handshakeAck",data:{windowId:m.windowId}}),a();let B={credential:m.delegationToken,scope:{functionId:m.functionId},issuedAt:Date.now(),expiresAt:m.tokenExpiresAt},h=B,g=ic({session:new rc({kernel:m.kernelUrl,auth:{ttlSeconds:3600,resolve:()=>({credential:h.credential})},policy:{maximumRouteAgeMs:60000}})});i({windowId:m.windowId,functionId:m.functionId,kernelUrl:m.kernelUrl,targetNodeId:m.targetNodeId,mintIdentity:m.mintIdentity,capabilities:m.capabilities,initialToken:B,kernel:g,parentChannel:(w)=>{let b=sc({port:l}),O=XD({transport:b,observer:w});return O.on("ctrl",(k)=>{if(k.action!=="tokenRefresh")return;let G;try{G=lh(k)}catch{return}h={credential:G.data.delegationToken,scope:{functionId:m.functionId},issuedAt:Date.now(),expiresAt:G.data.tokenExpiresAt}}),O}})}}function u(l){if(!Zl(l.data))return;if(l.source!==t)return;let[d]=l.ports;if(!d)return;o=d,o.onmessage=c(d),o.start()}window.addEventListener("message",u),t.postMessage({type:mc,version:1},"*")})}function Ez(e){let t=e();if(!t)throw Error("Sandboxed shell not initialized — call shell.init() first");return t}function vz(e){return new Proxy({},{get(t,r){let i=e(),n=i[r];return typeof n==="function"?n.bind(i):n}})}function xz(e){return{send:(t)=>e().send(t),on:(t,r)=>e().on(t,r)}}function wz(){let e=[];return{add(t,r){let i={name:t,handler:r,unsubscribed:!1};return e.push(i),()=>{i.unsubscribed=!0,i.off?.()}},replay(t){for(let r of e){if(r.unsubscribed)continue;r.off=t.onLocal(r.name,r.handler)}e.length=0}}}function Iz(e){let t=e===void 0?void 0:i_(e),r=new Set,i=!1;return{current:()=>t,initialize(n){if(i)return;let o=n===void 0?void 0:i_(n);if(o===t)return;t=o,r.forEach((s)=>s(t))},handle(n){if(i||n.envelope.sender.windowId!=="<parent>")return!1;let o;try{o=q9(n.envelope.payload)}catch{return!1}if(o!==t)t=o,r.forEach((s)=>s(t));return!0},subscribe(n){if(i)return()=>{};return r.add(n),()=>r.delete(n)},dispose(){i=!0,r.clear()}}}function q9(e){if(typeof e!=="object"||e===null||Array.isArray(e))rh();if(Object.keys(e).some((i)=>i!=="nodeId"))rh();let r=e.nodeId;if(r===void 0)return;if(typeof r!=="string"||r.length===0)rh();return i_(r)}function i_(e){let t=q.parse(e).raw;if(t!==e)rh();return t}function rh(){throw TypeError("Invalid setTarget payload.")}var J9="<parent>";function Oz(e){let t=Tl(),r=new Map,i=new Set,n=()=>i.forEach((b)=>b()),o=Nl((b,O)=>{let k=r.get(b);if(k===void 0||k.state===O)return;r.set(b,Object.freeze({...k,state:O})),n()}),s=$l({observer:t,onDeliveryFailed:(b)=>o.markCrashed(b)}),a=uc(),c=null,u=null,l=null,d=Iz(void 0),f=wz();function m(b,O){if(u)return u.onLocal(b,O);return f.add(b,O)}let B=()=>Ez(()=>c),h=vz(()=>B().kernel),g=xz(()=>B().parent);function w(){if(l)return l;if(!e.adapter)throw Error("Shell.openView() requires a ShellAdapter in the config");let b=B();return l=Pl({adapter:e.adapter,kernel:h,kernelUrl:b.kernelUrl,mintIdentity:b.mintIdentity,childrenChannel:s,windows:r,lifecycle:o,parentCapabilities:()=>B().capabilities,onWindowsChange:n}),l}return eh({parent:g,childrenChannel:s,kernel:h,pipeline:a,observer:t,lifecycle:o,windows:r,getMountController:w,targetNodeId:()=>d.current(),onTargetChange:(b)=>d.subscribe(b),onWindowChange:(b)=>(i.add(b),()=>i.delete(b)),notifyWindows:n,hostCapabilities:()=>c?.capabilities??_i,onIntent:m,init:async()=>{let b=await th({parent:e.parentWindow??window.parent,timeoutMs:e.initTimeoutMs});c={windowId:b.windowId,kernelUrl:b.kernelUrl,targetNodeId:b.targetNodeId,mintIdentity:b.mintIdentity,capabilities:b.capabilities,kernel:b.kernel,parent:b.parentChannel(t)},d.initialize(b.targetNodeId),a.use(cc({selfWindowId:c.windowId,lookup:(O)=>r.get(O)?.capabilities,credential:(O)=>r.get(O)?.credential,owns:(O,k)=>Rl(r,O,k),depth:()=>1})),u=lc({selfWindowId:c.windowId,pipeline:a,parent:c.parent,children:s}),u.onLocal("setTarget",(O)=>{if(!d.handle(O))return;let k=c;if(k===null)return;let G=d.current(),{targetNodeId:oe,...V}=k;c={...V,...G===void 0?{}:{targetNodeId:G}}}),s.on("intent",(O,k)=>{u.handleInbound("child",k,O)}),c.parent.on("intent",(O)=>{u.handleInbound("parent",O,J9)}),f.replay(u)},onDispose:async()=>{if(l)await l.dispose();s.dispose(),d.dispose(),i.clear(),c?.parent.dispose(),c?.kernel.close()}})}var K9="root";function Dz(e){let t=e.windowId??K9,r=e.capabilities===void 0?_i:Tr(e.capabilities),i=Tl(),n=e.session!==void 0||e.ownClient===!0,o=e.session!==void 0?ic({session:new rc(e.session)}):e.client,s=new Map,a=new Set,c=()=>a.forEach((h)=>h()),u=Nl((h,g)=>{let w=s.get(h);if(w===void 0||w.state===g)return;s.set(h,Object.freeze({...w,state:g})),c()}),l=$l({observer:i,onDeliveryFailed:(h)=>u.markCrashed(h)}),d=uc();d.use(cc({selfWindowId:t,lookup:(h)=>s.get(h)?.capabilities,credential:(h)=>s.get(h)?.credential,owns:(h,g)=>Rl(s,h,g),depth:()=>1}));let f=lc({selfWindowId:t,pipeline:d,parent:null,children:l});l.on("intent",(h,g)=>{f.handleInbound("child",g,h)});let m=null;function B(){if(m)return m;if(!e.adapter)throw Error("Shell.openView() requires a ShellAdapter in the config");return m=Pl({adapter:e.adapter,kernel:o,kernelUrl:o.url,childrenChannel:l,windows:s,lifecycle:u,onWindowsChange:c}),m}return eh({parent:null,childrenChannel:l,kernel:o,pipeline:d,observer:i,lifecycle:u,windows:s,hostCapabilities:()=>r,onWindowChange:(h)=>(a.add(h),()=>a.delete(h)),notifyWindows:c,getMountController:B,onIntent:(h,g)=>f.onLocal(h,g),onDispose:async()=>{if(m)await m.dispose();if(l.dispose(),a.clear(),n)o.close()}})}function nh(e){return e.mode==="standalone"?Dz(e):Oz(e)}function _z(e,t){let r=Promise.resolve();return e.onIntent("open",(i)=>{let n=r.then(()=>W9(e,t,i));return r=n.catch(()=>{}),n})}async function W9(e,t,r){let{nodeId:i,viewId:n}=r.envelope.payload;try{let o=Y9(await e.views.resolve(i),n),s=t.current(),a=await t.mount(o);if(t.setCurrent(a),t.opened(o),t.reply(r,a.windowId),s&&s.windowId!==a.windowId)try{let c=await s.close({force:!0});if(c.kind==="refused")t.failed(Error(c.reason??`Window ${s.windowId} refused to close`))}catch(c){t.failed(c)}}catch(o){t.reject(r,o),t.failed(o)}}function Y9(e,t){let r=t?e.find((i)=>i.route.key===t||`/:${i.route.key}`===t):e[0];if(r)return r;throw Error(t?`View ${t} does not resolve for this node`:"No view resolves for this node")}var Q9=300000,X9=1e4,e5=300000,t5=Tr({version:1,navigation:{openView:{}},actions:{},browser:{},access:{}}),kz=location.pathname.replace(/\/+$/,"");async function o_(e,t){let r=await fetch(kz+e,t);if(!r.ok)throw Error(`${e} → ${r.status}: ${await r.text()}`);return r.json()}function Gl(e,t){fetch(`${kz}/status`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({state:e,error:t}),keepalive:!0}).catch(()=>{})}function Yn(e){return document.getElementById(e)}function s_(e){Yn("status-dot").dataset.state=e}function r5(e){let t=e instanceof Error?e.message:String(e);s_("failed");let r=Yn("error");r.style.display="block",r.textContent=t,Gl("failed",t)}function n5(e){let t=Yn("error");t.style.display="block",t.textContent=e instanceof Error?e.message:String(e)}async function i5(){let e=await o_("/config.json"),t=e.view.route;Yn("view-label").textContent=`/:${t.key}`,Yn("target-label").textContent=e.view.target,Yn("identity-label").textContent=[e.identity,e.instance].filter(Boolean).join(" @ "),document.title=`astrale view — ${t.key}`,Gl("mounting");let r=null;if(t.handshake==="shell")r=await o_("/token",{method:"POST"});let i=new URL(e.kernelUrl,location.href).href,n=nh({mode:"standalone",session:{kernel:e.kernelIssuer,auth:{ttlSeconds:3600,resolve:()=>r===null?{}:{credential:r.token}},policy:{maximumRouteAgeMs:e5,...new URL(i).protocol==="http:"?{allowInsecureHttp:!0}:{}},envelopeTransport:"http"},adapter:MB()});await n.init();let o=Yn("frame"),s=null,a=async(c)=>{let u=c.route.handshake==="shell"?{token:r.token,expiresAt:r.expiresAt,refresh:async()=>(r=await o_("/token",{method:"POST"}),{token:r.token,expiresAt:r.expiresAt})}:void 0;return n.openView({host:o,view:c,capabilities:t5,sandbox:null,handshakeTimeoutMs:X9,...u===void 0?{}:{credential:u}})};if(_z(n,{current:()=>s,setCurrent:(c)=>{s=c},mount:a,opened:(c)=>{Yn("view-label").textContent=`/:${c.route.key}`,Yn("target-label").textContent=c.target,Yn("error").style.display="none"},failed:n5,reply:(c,u)=>{HB(n.children,c.envelope.sender.windowId,c,{windowId:u})},reject:(c,u)=>{VB(n.children,c.envelope.sender.windowId,c,u)}}),s=await a(e.view),t.handshake==="shell")s_("connected"),Gl("connected");else s_("plain"),Gl("plain");setInterval(()=>Gl("alive"),Q9)}i5().catch(r5);
|