@zh-xx/antu 0.9.0 → 0.9.1

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.
@@ -8,9 +8,9 @@
8
8
  <meta charset="UTF-8">
9
9
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
10
10
  <title>Antu · Antu</title>
11
- <meta name="generator" content="antu 0.9.0">
11
+ <meta name="generator" content="antu 0.9.1">
12
12
  <script type="text/plain" id="antu-license">
13
- Antu 0.9.0
13
+ Antu 0.9.1
14
14
  Copyright (C) 2026 Ji Cheng
15
15
 
16
16
  Antu is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public
@@ -24,9 +24,9 @@ you drew from your material, are not part of Antu and are not covered by this li
24
24
  publish them, or sell them on any terms you like. This licence covers Antu's code in the page, and the notices in
25
25
  the page must stay with it.
26
26
 
27
- Corresponding Source of this version: https://github.com/zh-xx/Antu/tree/v0.9.0
28
- The licence: https://github.com/zh-xx/Antu/blob/v0.9.0/LICENSE
29
- Third-party notices: https://github.com/zh-xx/Antu/blob/v0.9.0/skills/antu/THIRD-PARTY-NOTICES.md
27
+ Corresponding Source of this version: https://github.com/zh-xx/Antu/tree/v0.9.1
28
+ The licence: https://github.com/zh-xx/Antu/blob/v0.9.1/LICENSE
29
+ Third-party notices: https://github.com/zh-xx/Antu/blob/v0.9.1/skills/antu/THIRD-PARTY-NOTICES.md
30
30
 
31
31
  === The licence of Antu ===
32
32
 
package/bin/antu-mcp.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // Antu 0.9.0
2
+ // Antu 0.9.1
3
3
  // Copyright (C) 2026 Ji Cheng
4
4
  //
5
5
  // Antu is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public
@@ -13,9 +13,9 @@
13
13
  // publish them, or sell them on any terms you like. This licence covers Antu's code in the page, and the notices in
14
14
  // the page must stay with it.
15
15
  //
16
- // Corresponding Source of this version: https://github.com/zh-xx/Antu/tree/v0.9.0
17
- // The licence: https://github.com/zh-xx/Antu/blob/v0.9.0/LICENSE
18
- // Third-party notices: https://github.com/zh-xx/Antu/blob/v0.9.0/skills/antu/THIRD-PARTY-NOTICES.md
16
+ // Corresponding Source of this version: https://github.com/zh-xx/Antu/tree/v0.9.1
17
+ // The licence: https://github.com/zh-xx/Antu/blob/v0.9.1/LICENSE
18
+ // Third-party notices: https://github.com/zh-xx/Antu/blob/v0.9.1/skills/antu/THIRD-PARTY-NOTICES.md
19
19
  //
20
20
  // === The licence of Antu ===
21
21
  //
@@ -1489,7 +1489,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
1489
1489
  depsCount: ${n},
1490
1490
  deps: ${r}}`};var i={keyword:`dependencies`,type:`object`,schemaType:`object`,error:e.error,code(e){let[t,n]=a(e);o(e,t),s(e,n)}};function a({schema:e}){let t={},n={};for(let r in e){if(r===`__proto__`)continue;let i=Array.isArray(e[r])?t:n;i[r]=e[r]}return[t,n]}function o(e,n=e.schema){let{gen:i,data:a,it:o}=e;if(Object.keys(n).length===0)return;let s=i.let(`missing`);for(let c in n){let l=n[c];if(l.length===0)continue;let u=(0,r.propertyInData)(i,a,c,o.opts.ownProperties);e.setParams({property:c,depsCount:l.length,deps:l.join(`, `)}),o.allErrors?i.if(u,()=>{for(let t of l)(0,r.checkReportMissingProp)(e,t)}):(i.if((0,t._)`${u} && (${(0,r.checkMissingProp)(e,l,s)})`),(0,r.reportMissingProp)(e,s),i.else())}}e.validatePropertyDeps=o;function s(e,t=e.schema){let{gen:i,data:a,keyword:o,it:s}=e,c=i.name(`valid`);for(let l in t)(0,n.alwaysValidSchema)(s,t[l])||(i.if((0,r.propertyInData)(i,a,l,s.opts.ownProperties),()=>{let t=e.subschema({keyword:o,schemaProp:l},c);e.mergeValidEvaluated(t,c)},()=>i.var(c,!0)),e.ok(c))}e.validateSchemaDeps=s,e.default=i})),Ose=w((e=>{Object.defineProperty(e,"__esModule",{value:!0});var t=wc(),n=Tc();e.default={keyword:`propertyNames`,type:`object`,schemaType:[`object`,`boolean`],error:{message:`property name must be valid`,params:({params:e})=>(0,t._)`{propertyName: ${e.propertyName}}`},code(e){let{gen:r,schema:i,data:a,it:o}=e;if((0,n.alwaysValidSchema)(o,i))return;let s=r.name(`valid`);r.forIn(`key`,a,n=>{e.setParams({propertyName:n}),e.subschema({keyword:`propertyNames`,data:n,dataTypes:[`string`],propertyName:n,compositeRule:!0},s),r.if((0,t.not)(s),()=>{e.error(!0),o.allErrors||r.break()})}),e.ok(s)}}})),Zc=w((e=>{Object.defineProperty(e,"__esModule",{value:!0});var t=Mc(),n=wc(),r=Ec(),i=Tc();e.default={keyword:`additionalProperties`,type:[`object`],schemaType:[`boolean`,`object`],allowUndefined:!0,trackErrors:!0,error:{message:`must NOT have additional properties`,params:({params:e})=>(0,n._)`{additionalProperty: ${e.additionalProperty}}`},code(e){let{gen:a,schema:o,parentSchema:s,data:c,errsCount:l,it:u}=e;if(!l)throw Error(`ajv implementation error`);let{allErrors:d,opts:f}=u;if(u.props=!0,f.removeAdditional!==`all`&&(0,i.alwaysValidSchema)(u,o))return;let p=(0,t.allSchemaProperties)(s.properties),m=(0,t.allSchemaProperties)(s.patternProperties);h(),e.ok((0,n._)`${l} === ${r.default.errors}`);function h(){a.forIn(`key`,c,e=>{!p.length&&!m.length?v(e):a.if(g(e),()=>v(e))})}function g(r){let o;if(p.length>8){let e=(0,i.schemaRefOrVal)(u,s.properties,`properties`);o=(0,t.isOwnProperty)(a,e,r)}else o=p.length?(0,n.or)(...p.map(e=>(0,n._)`${r} === ${e}`)):n.nil;return m.length&&(o=(0,n.or)(o,...m.map(i=>(0,n._)`${(0,t.usePattern)(e,i)}.test(${r})`))),(0,n.not)(o)}function _(e){a.code((0,n._)`delete ${c}[${e}]`)}function v(t){if(f.removeAdditional===`all`||f.removeAdditional&&o===!1){_(t);return}if(o===!1){e.setParams({additionalProperty:t}),e.error(),d||a.break();return}if(typeof o==`object`&&!(0,i.alwaysValidSchema)(u,o)){let r=a.name(`valid`);f.removeAdditional===`failing`?(y(t,r,!1),a.if((0,n.not)(r),()=>{e.reset(),_(t)})):(y(t,r),d||a.if((0,n.not)(r),()=>a.break()))}}function y(t,n,r){let a={keyword:`additionalProperties`,dataProp:t,dataPropType:i.Type.Str};r===!1&&Object.assign(a,{compositeRule:!0,createErrors:!1,allErrors:!1}),e.subschema(a,n)}}}})),kse=w((e=>{Object.defineProperty(e,"__esModule",{value:!0});var t=Rc(),n=Mc(),r=Tc(),i=Zc();e.default={keyword:`properties`,type:`object`,schemaType:`object`,code(e){let{gen:a,schema:o,parentSchema:s,data:c,it:l}=e;l.opts.removeAdditional===`all`&&s.additionalProperties===void 0&&i.default.code(new t.KeywordCxt(l,i.default,`additionalProperties`));let u=(0,n.allSchemaProperties)(o);for(let e of u)l.definedProperties.add(e);l.opts.unevaluated&&u.length&&l.props!==!0&&(l.props=r.mergeEvaluated.props(a,(0,r.toHash)(u),l.props));let d=u.filter(e=>!(0,r.alwaysValidSchema)(l,o[e]));if(d.length===0)return;let f=a.name(`valid`);for(let t of d)p(t)?m(t):(a.if((0,n.propertyInData)(a,c,t,l.opts.ownProperties)),m(t),l.allErrors||a.else().var(f,!0),a.endIf()),e.it.definedProperties.add(t),e.ok(f);function p(e){return l.opts.useDefaults&&!l.compositeRule&&o[e].default!==void 0}function m(t){e.subschema({keyword:`properties`,schemaProp:t,dataProp:t},f)}}}})),Ase=w((e=>{Object.defineProperty(e,"__esModule",{value:!0});var t=Mc(),n=wc(),r=Tc(),i=Tc();e.default={keyword:`patternProperties`,type:`object`,schemaType:`object`,code(e){let{gen:a,schema:o,data:s,parentSchema:c,it:l}=e,{opts:u}=l,d=(0,t.allSchemaProperties)(o),f=d.filter(e=>(0,r.alwaysValidSchema)(l,o[e]));if(d.length===0||f.length===d.length&&(!l.opts.unevaluated||l.props===!0))return;let p=u.strictSchema&&!u.allowMatchingProperties&&c.properties,m=a.name(`valid`);l.props!==!0&&!(l.props instanceof n.Name)&&(l.props=(0,i.evaluatedPropsToName)(a,l.props));let{props:h}=l;g();function g(){for(let e of d)p&&_(e),l.allErrors?v(e):(a.var(m,!0),v(e),a.if(m))}function _(e){for(let t in p)new RegExp(e).test(t)&&(0,r.checkStrictMode)(l,`property ${t} matches pattern ${e} (use allowMatchingProperties)`)}function v(r){a.forIn(`key`,s,o=>{a.if((0,n._)`${(0,t.usePattern)(e,r)}.test(${o})`,()=>{let t=f.includes(r);t||e.subschema({keyword:`patternProperties`,schemaProp:r,dataProp:o,dataPropType:i.Type.Str},m),l.opts.unevaluated&&h!==!0?a.assign((0,n._)`${h}[${o}]`,!0):!t&&!l.allErrors&&a.if((0,n.not)(m),()=>a.break())})})}}}})),jse=w((e=>{Object.defineProperty(e,"__esModule",{value:!0});var t=Tc();e.default={keyword:`not`,schemaType:[`object`,`boolean`],trackErrors:!0,code(e){let{gen:n,schema:r,it:i}=e;if((0,t.alwaysValidSchema)(i,r)){e.fail();return}let a=n.name(`valid`);e.subschema({keyword:`not`,compositeRule:!0,createErrors:!1,allErrors:!1},a),e.failResult(a,()=>e.reset(),()=>e.error())},error:{message:`must NOT be valid`}}})),Mse=w((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default={keyword:`anyOf`,schemaType:`array`,trackErrors:!0,code:Mc().validateUnion,error:{message:`must match a schema in anyOf`}}})),Nse=w((e=>{Object.defineProperty(e,"__esModule",{value:!0});var t=wc(),n=Tc();e.default={keyword:`oneOf`,schemaType:`array`,trackErrors:!0,error:{message:`must match exactly one schema in oneOf`,params:({params:e})=>(0,t._)`{passingSchemas: ${e.passing}}`},code(e){let{gen:r,schema:i,parentSchema:a,it:o}=e;if(!Array.isArray(i))throw Error(`ajv implementation error`);if(o.opts.discriminator&&a.discriminator)return;let s=i,c=r.let(`valid`,!1),l=r.let(`passing`,null),u=r.name(`_valid`);e.setParams({passing:l}),r.block(d),e.result(c,()=>e.reset(),()=>e.error(!0));function d(){s.forEach((i,a)=>{let s;(0,n.alwaysValidSchema)(o,i)?r.var(u,!0):s=e.subschema({keyword:`oneOf`,schemaProp:a,compositeRule:!0},u),a>0&&r.if((0,t._)`${u} && ${c}`).assign(c,!1).assign(l,(0,t._)`[${l}, ${a}]`).else(),r.if(u,()=>{r.assign(c,!0),r.assign(l,a),s&&e.mergeEvaluated(s,t.Name)})})}}}})),Pse=w((e=>{Object.defineProperty(e,"__esModule",{value:!0});var t=Tc();e.default={keyword:`allOf`,schemaType:`array`,code(e){let{gen:n,schema:r,it:i}=e;if(!Array.isArray(r))throw Error(`ajv implementation error`);let a=n.name(`valid`);r.forEach((n,r)=>{if((0,t.alwaysValidSchema)(i,n))return;let o=e.subschema({keyword:`allOf`,schemaProp:r},a);e.ok(a),e.mergeEvaluated(o)})}}})),Fse=w((e=>{Object.defineProperty(e,"__esModule",{value:!0});var t=wc(),n=Tc(),r={keyword:`if`,schemaType:[`object`,`boolean`],trackErrors:!0,error:{message:({params:e})=>(0,t.str)`must match "${e.ifClause}" schema`,params:({params:e})=>(0,t._)`{failingKeyword: ${e.ifClause}}`},code(e){let{gen:r,parentSchema:a,it:o}=e;a.then===void 0&&a.else===void 0&&(0,n.checkStrictMode)(o,`"if" without "then" and "else" is ignored`);let s=i(o,`then`),c=i(o,`else`);if(!s&&!c)return;let l=r.let(`valid`,!0),u=r.name(`_valid`);if(d(),e.reset(),s&&c){let t=r.let(`ifClause`);e.setParams({ifClause:t}),r.if(u,f(`then`,t),f(`else`,t))}else s?r.if(u,f(`then`)):r.if((0,t.not)(u),f(`else`));e.pass(l,()=>e.error(!0));function d(){let t=e.subschema({keyword:`if`,compositeRule:!0,createErrors:!1,allErrors:!1},u);e.mergeEvaluated(t)}function f(n,i){return()=>{let a=e.subschema({keyword:n},u);r.assign(l,u),e.mergeValidEvaluated(a,l),i?r.assign(i,(0,t._)`${n}`):e.setParams({ifClause:n})}}}};function i(e,t){let r=e.schema[t];return r!==void 0&&!(0,n.alwaysValidSchema)(e,r)}e.default=r})),Ise=w((e=>{Object.defineProperty(e,"__esModule",{value:!0});var t=Tc();e.default={keyword:[`then`,`else`],schemaType:[`object`,`boolean`],code({keyword:e,parentSchema:n,it:r}){n.if===void 0&&(0,t.checkStrictMode)(r,`"${e}" without "if" is ignored`)}}})),Lse=w((e=>{Object.defineProperty(e,"__esModule",{value:!0});var t=Yc(),n=wse(),r=Xc(),i=Tse(),a=Ese(),o=Dse(),s=Ose(),c=Zc(),l=kse(),u=Ase(),d=jse(),f=Mse(),p=Nse(),m=Pse(),h=Fse(),g=Ise();function _(e=!1){let _=[d.default,f.default,p.default,m.default,h.default,g.default,s.default,c.default,o.default,l.default,u.default];return e?_.push(n.default,i.default):_.push(t.default,r.default),_.push(a.default),_}e.default=_})),Rse=w((e=>{Object.defineProperty(e,"__esModule",{value:!0});var t=wc();e.default={keyword:`format`,type:[`number`,`string`],schemaType:`string`,$data:!0,error:{message:({schemaCode:e})=>(0,t.str)`must match format "${e}"`,params:({schemaCode:e})=>(0,t._)`{format: ${e}}`},code(e,n){let{gen:r,data:i,$data:a,schema:o,schemaCode:s,it:c}=e,{opts:l,errSchemaPath:u,schemaEnv:d,self:f}=c;if(!l.validateFormats)return;a?p():m();function p(){let a=r.scopeValue(`formats`,{ref:f.formats,code:l.code.formats}),o=r.const(`fDef`,(0,t._)`${a}[${s}]`),c=r.let(`fType`),u=r.let(`format`);r.if((0,t._)`typeof ${o} == "object" && !(${o} instanceof RegExp)`,()=>r.assign(c,(0,t._)`${o}.type || "string"`).assign(u,(0,t._)`${o}.validate`),()=>r.assign(c,(0,t._)`"string"`).assign(u,o)),e.fail$data((0,t.or)(p(),m()));function p(){return l.strictSchema===!1?t.nil:(0,t._)`${s} && !${u}`}function m(){let e=d.$async?(0,t._)`(${o}.async ? await ${u}(${i}) : ${u}(${i}))`:(0,t._)`${u}(${i})`,r=(0,t._)`(typeof ${u} == "function" ? ${e} : ${u}.test(${i}))`;return(0,t._)`${u} && ${u} !== true && ${c} === ${n} && !${r}`}}function m(){let a=f.formats[o];if(!a){m();return}if(a===!0)return;let[s,c,p]=h(a);s===n&&e.pass(g());function m(){if(l.strictSchema===!1){f.logger.warn(e());return}throw Error(e());function e(){return`unknown format "${o}" ignored in schema at path "${u}"`}}function h(e){let n=e instanceof RegExp?(0,t.regexpCode)(e):l.code.formats?(0,t._)`${l.code.formats}${(0,t.getProperty)(o)}`:void 0,i=r.scopeValue(`formats`,{key:o,ref:e,code:n});return typeof e==`object`&&!(e instanceof RegExp)?[e.type||`string`,e.validate,(0,t._)`${i}.validate`]:[`string`,e,i]}function g(){if(typeof a==`object`&&!(a instanceof RegExp)&&a.async){if(!d.$async)throw Error(`async format in sync schema`);return(0,t._)`await ${p}(${i})`}return typeof c==`function`?(0,t._)`${p}(${i})`:(0,t._)`${p}.test(${i})`}}}}})),zse=w((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=[Rse().default]})),Bse=w((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.contentVocabulary=e.metadataVocabulary=void 0,e.metadataVocabulary=[`title`,`description`,`default`,`deprecated`,`readOnly`,`writeOnly`,`examples`],e.contentVocabulary=[`contentMediaType`,`contentEncoding`,`contentSchema`]})),Vse=w((e=>{Object.defineProperty(e,"__esModule",{value:!0});var t=fse(),n=Cse(),r=Lse(),i=zse(),a=Bse();e.default=[t.default,n.default,(0,r.default)(),i.default,a.metadataVocabulary,a.contentVocabulary]})),Hse=w((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.DiscrError=void 0;var t;(function(e){e.Tag=`tag`,e.Mapping=`mapping`})(t||(e.DiscrError=t={}))})),Use=w((e=>{Object.defineProperty(e,"__esModule",{value:!0});var t=wc(),n=Hse(),r=Vc(),i=Bc(),a=Tc();e.default={keyword:`discriminator`,type:`object`,schemaType:`object`,error:{message:({params:{discrError:e,tagName:t}})=>e===n.DiscrError.Tag?`tag "${t}" must be string`:`value of tag "${t}" must be in oneOf`,params:({params:{discrError:e,tag:n,tagName:r}})=>(0,t._)`{error: ${e}, tag: ${r}, tagValue: ${n}}`},code(e){let{gen:o,data:s,schema:c,parentSchema:l,it:u}=e,{oneOf:d}=l;if(!u.opts.discriminator)throw Error(`discriminator: requires discriminator option`);let f=c.propertyName;if(typeof f!=`string`)throw Error(`discriminator: requires propertyName`);if(c.mapping)throw Error(`discriminator: mapping is not supported`);if(!d)throw Error(`discriminator: requires oneOf keyword`);let p=o.let(`valid`,!1),m=o.const(`tag`,(0,t._)`${s}${(0,t.getProperty)(f)}`);o.if((0,t._)`typeof ${m} == "string"`,()=>h(),()=>e.error(!1,{discrError:n.DiscrError.Tag,tag:m,tagName:f})),e.ok(p);function h(){let r=_();o.if(!1);for(let e in r)o.elseIf((0,t._)`${m} === ${e}`),o.assign(p,g(r[e]));o.else(),e.error(!1,{discrError:n.DiscrError.Mapping,tag:m,tagName:f}),o.endIf()}function g(n){let r=o.name(`valid`),i=e.subschema({keyword:`oneOf`,schemaProp:n},r);return e.mergeEvaluated(i,t.Name),r}function _(){let e={},t=o(l),n=!0;for(let e=0;e<d.length;e++){let c=d[e];if(c?.$ref&&!(0,a.schemaHasRulesButRef)(c,u.self.RULES)){let e=c.$ref;if(c=r.resolveRef.call(u.self,u.schemaEnv.root,u.baseId,e),c instanceof r.SchemaEnv&&(c=c.schema),c===void 0)throw new i.default(u.opts.uriResolver,u.baseId,e)}let l=c?.properties?.[f];if(typeof l!=`object`)throw Error(`discriminator: oneOf subschemas (or referenced schemas) must have "properties/${f}"`);n&&=t||o(c),s(l,e)}if(!n)throw Error(`discriminator: "${f}" must be required`);return e;function o({required:e}){return Array.isArray(e)&&e.includes(f)}function s(e,t){if(e.const)c(e.const,t);else if(e.enum)for(let n of e.enum)c(n,t);else throw Error(`discriminator: "properties/${f}" must have "const" or "enum"`)}function c(t,n){if(typeof t!=`string`||t in e)throw Error(`discriminator: "${f}" values must be unique strings`);e[t]=n}}}}})),Wse=T({$id:()=>$c,$schema:()=>Qc,default:()=>il,definitions:()=>tl,properties:()=>rl,title:()=>el,type:()=>nl}),Qc,$c,el,tl,nl,rl,il,Gse=C((()=>{Qc=`http://json-schema.org/draft-07/schema#`,$c=`http://json-schema.org/draft-07/schema#`,el=`Core schema meta-schema`,tl={schemaArray:{type:`array`,minItems:1,items:{$ref:`#`}},nonNegativeInteger:{type:`integer`,minimum:0},nonNegativeIntegerDefault0:{allOf:[{$ref:`#/definitions/nonNegativeInteger`},{default:0}]},simpleTypes:{enum:[`array`,`boolean`,`integer`,`null`,`number`,`object`,`string`]},stringArray:{type:`array`,items:{type:`string`},uniqueItems:!0,default:[]}},nl=[`object`,`boolean`],rl={$id:{type:`string`,format:`uri-reference`},$schema:{type:`string`,format:`uri`},$ref:{type:`string`,format:`uri-reference`},$comment:{type:`string`},title:{type:`string`},description:{type:`string`},default:!0,readOnly:{type:`boolean`,default:!1},examples:{type:`array`,items:!0},multipleOf:{type:`number`,exclusiveMinimum:0},maximum:{type:`number`},exclusiveMaximum:{type:`number`},minimum:{type:`number`},exclusiveMinimum:{type:`number`},maxLength:{$ref:`#/definitions/nonNegativeInteger`},minLength:{$ref:`#/definitions/nonNegativeIntegerDefault0`},pattern:{type:`string`,format:`regex`},additionalItems:{$ref:`#`},items:{anyOf:[{$ref:`#`},{$ref:`#/definitions/schemaArray`}],default:!0},maxItems:{$ref:`#/definitions/nonNegativeInteger`},minItems:{$ref:`#/definitions/nonNegativeIntegerDefault0`},uniqueItems:{type:`boolean`,default:!1},contains:{$ref:`#`},maxProperties:{$ref:`#/definitions/nonNegativeInteger`},minProperties:{$ref:`#/definitions/nonNegativeIntegerDefault0`},required:{$ref:`#/definitions/stringArray`},additionalProperties:{$ref:`#`},definitions:{type:`object`,additionalProperties:{$ref:`#`},default:{}},properties:{type:`object`,additionalProperties:{$ref:`#`},default:{}},patternProperties:{type:`object`,additionalProperties:{$ref:`#`},propertyNames:{format:`regex`},default:{}},dependencies:{type:`object`,additionalProperties:{anyOf:[{$ref:`#`},{$ref:`#/definitions/stringArray`}]}},propertyNames:{$ref:`#`},const:!0,enum:{type:`array`,items:!0,minItems:1,uniqueItems:!0},type:{anyOf:[{$ref:`#/definitions/simpleTypes`},{type:`array`,items:{$ref:`#/definitions/simpleTypes`},minItems:1,uniqueItems:!0}]},format:{type:`string`},contentMediaType:{type:`string`},contentEncoding:{type:`string`},if:{$ref:`#`},then:{$ref:`#`},else:{$ref:`#`},allOf:{$ref:`#/definitions/schemaArray`},anyOf:{$ref:`#/definitions/schemaArray`},oneOf:{$ref:`#/definitions/schemaArray`},not:{$ref:`#`}},il={$schema:Qc,$id:$c,title:el,definitions:tl,type:nl,properties:rl,default:!0}})),al=w(((e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.MissingRefError=e.ValidationError=e.CodeGen=e.Name=e.nil=e.stringify=e.str=e._=e.KeywordCxt=e.Ajv=void 0;var n=lse(),r=Vse(),i=Use(),a=(Gse(),ne(Wse).default),o=[`/properties`],s=`http://json-schema.org/draft-07/schema`,c=class extends n.default{_addVocabularies(){super._addVocabularies(),r.default.forEach(e=>this.addVocabulary(e)),this.opts.discriminator&&this.addKeyword(i.default)}_addDefaultMetaSchema(){if(super._addDefaultMetaSchema(),!this.opts.meta)return;let e=this.opts.$data?this.$dataMetaSchema(a,o):a;this.addMetaSchema(e,s,!1),this.refs[`http://json-schema.org/schema`]=s}defaultMeta(){return this.opts.defaultMeta=super.defaultMeta()||(this.getSchema(s)?s:void 0)}};e.Ajv=c,t.exports=e=c,t.exports.Ajv=c,Object.defineProperty(e,"__esModule",{value:!0}),e.default=c;var l=Rc();Object.defineProperty(e,"KeywordCxt",{enumerable:!0,get:function(){return l.KeywordCxt}});var u=wc();Object.defineProperty(e,"_",{enumerable:!0,get:function(){return u._}}),Object.defineProperty(e,"str",{enumerable:!0,get:function(){return u.str}}),Object.defineProperty(e,"stringify",{enumerable:!0,get:function(){return u.stringify}}),Object.defineProperty(e,"nil",{enumerable:!0,get:function(){return u.nil}}),Object.defineProperty(e,"Name",{enumerable:!0,get:function(){return u.Name}}),Object.defineProperty(e,"CodeGen",{enumerable:!0,get:function(){return u.CodeGen}});var d=zc();Object.defineProperty(e,"ValidationError",{enumerable:!0,get:function(){return d.default}});var f=Bc();Object.defineProperty(e,"MissingRefError",{enumerable:!0,get:function(){return f.default}})})),Kse=w((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.formatNames=e.fastFormats=e.fullFormats=void 0;function t(e,t){return{validate:e,compare:t}}e.fullFormats={date:t(a,o),time:t(c(!0),l),"date-time":t(f(!0),p),"iso-time":t(c(),u),"iso-date-time":t(f(),m),duration:/^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/,uri:_,"uri-reference":/^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,"uri-template":/^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,url:/^(?:https?|ftp):\/\/(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)(?:\.(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu,email:/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,hostname:/^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i,ipv4:/^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/,ipv6:/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i,regex:ee,uuid:/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,"json-pointer":/^(?:\/(?:[^~/]|~0|~1)*)*$/,"json-pointer-uri-fragment":/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,"relative-json-pointer":/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,byte:y,int32:{type:`number`,validate:S},int64:{type:`number`,validate:C},float:{type:`number`,validate:w},double:{type:`number`,validate:w},password:!0,binary:!0},e.fastFormats={...e.fullFormats,date:t(/^\d\d\d\d-[0-1]\d-[0-3]\d$/,o),time:t(/^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i,l),"date-time":t(/^\d\d\d\d-[0-1]\d-[0-3]\dt(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i,p),"iso-time":t(/^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i,u),"iso-date-time":t(/^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i,m),uri:/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/)?[^\s]*$/i,"uri-reference":/^(?:(?:[a-z][a-z0-9+\-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i,email:/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i},e.formatNames=Object.keys(e.fullFormats);function n(e){return e%4==0&&(e%100!=0||e%400==0)}var r=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,i=[0,31,28,31,30,31,30,31,31,30,31,30,31];function a(e){let t=r.exec(e);if(!t)return!1;let a=+t[1],o=+t[2],s=+t[3];return o>=1&&o<=12&&s>=1&&s<=(o===2&&n(a)?29:i[o])}function o(e,t){if(e&&t)return e>t?1:e<t?-1:0}var s=/^(\d\d):(\d\d):(\d\d(?:\.\d+)?)(z|([+-])(\d\d)(?::?(\d\d))?)?$/i;function c(e){return function(t){let n=s.exec(t);if(!n)return!1;let r=+n[1],i=+n[2],a=+n[3],o=n[4],c=n[5]===`-`?-1:1,l=+(n[6]||0),u=+(n[7]||0);if(l>23||u>59||e&&!o)return!1;if(r<=23&&i<=59&&a<60)return!0;let d=i-u*c,f=r-l*c-+(d<0);return(f===23||f===-1)&&(d===59||d===-1)&&a<61}}function l(e,t){if(!(e&&t))return;let n=new Date(`2020-01-01T`+e).valueOf(),r=new Date(`2020-01-01T`+t).valueOf();if(n&&r)return n-r}function u(e,t){if(!(e&&t))return;let n=s.exec(e),r=s.exec(t);if(n&&r)return e=n[1]+n[2]+n[3],t=r[1]+r[2]+r[3],e>t?1:e<t?-1:0}var d=/t|\s/i;function f(e){let t=c(e);return function(e){let n=e.split(d);return n.length===2&&a(n[0])&&t(n[1])}}function p(e,t){if(!(e&&t))return;let n=new Date(e).valueOf(),r=new Date(t).valueOf();if(n&&r)return n-r}function m(e,t){if(!(e&&t))return;let[n,r]=e.split(d),[i,a]=t.split(d),s=o(n,i);if(s!==void 0)return s||l(r,a)}var h=/\/|:/,g=/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;function _(e){return h.test(e)&&g.test(e)}var v=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm;function y(e){return v.lastIndex=0,v.test(e)}var b=-(2**31),x=2**31-1;function S(e){return Number.isInteger(e)&&e<=x&&e>=b}function C(e){return Number.isInteger(e)}function w(){return!0}var T=/[^\\]\\Z/;function ee(e){if(T.test(e))return!1;try{return new RegExp(e),!0}catch{return!1}}})),qse=w((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.formatLimitDefinition=void 0;var t=al(),n=wc(),r=n.operators,i={formatMaximum:{okStr:`<=`,ok:r.LTE,fail:r.GT},formatMinimum:{okStr:`>=`,ok:r.GTE,fail:r.LT},formatExclusiveMaximum:{okStr:`<`,ok:r.LT,fail:r.GTE},formatExclusiveMinimum:{okStr:`>`,ok:r.GT,fail:r.LTE}};e.formatLimitDefinition={keyword:Object.keys(i),type:`string`,schemaType:`string`,$data:!0,error:{message:({keyword:e,schemaCode:t})=>(0,n.str)`should be ${i[e].okStr} ${t}`,params:({keyword:e,schemaCode:t})=>(0,n._)`{comparison: ${i[e].okStr}, limit: ${t}}`},code(e){let{gen:r,data:a,schemaCode:o,keyword:s,it:c}=e,{opts:l,self:u}=c;if(!l.validateFormats)return;let d=new t.KeywordCxt(c,u.RULES.all.format.definition,`format`);d.$data?f():p();function f(){let t=r.scopeValue(`formats`,{ref:u.formats,code:l.code.formats}),i=r.const(`fmt`,(0,n._)`${t}[${d.schemaCode}]`);e.fail$data((0,n.or)((0,n._)`typeof ${i} != "object"`,(0,n._)`${i} instanceof RegExp`,(0,n._)`typeof ${i}.compare != "function"`,m(i)))}function p(){let t=d.schema,i=u.formats[t];if(!i||i===!0)return;if(typeof i!=`object`||i instanceof RegExp||typeof i.compare!=`function`)throw Error(`"${s}": format "${t}" does not define "compare" function`);let a=r.scopeValue(`formats`,{key:t,ref:i,code:l.code.formats?(0,n._)`${l.code.formats}${(0,n.getProperty)(t)}`:void 0});e.fail$data(m(a))}function m(e){return(0,n._)`${e}.compare(${a}, ${o}) ${i[s].fail} 0`}},dependencies:[`format`]},e.default=t=>(t.addKeyword(e.formatLimitDefinition),t)})),Jse=w(((e,t)=>{Object.defineProperty(e,"__esModule",{value:!0});var n=Kse(),r=qse(),i=wc(),a=new i.Name(`fullFormats`),o=new i.Name(`fastFormats`),s=(e,t={keywords:!0})=>{if(Array.isArray(t))return c(e,t,n.fullFormats,a),e;let[i,s]=t.mode===`fast`?[n.fastFormats,o]:[n.fullFormats,a];return c(e,t.formats||n.formatNames,i,s),t.keywords&&(0,r.default)(e),e};s.get=(e,t=`full`)=>{let r=(t===`fast`?n.fastFormats:n.fullFormats)[e];if(!r)throw Error(`Unknown format "${e}"`);return r};function c(e,t,n,r){var a;(a=e.opts.code).formats??(a.formats=(0,i._)`require("ajv-formats/dist/formats").${r}`);for(let r of t)e.addFormat(r,n[r])}t.exports=e=s,Object.defineProperty(e,"__esModule",{value:!0}),e.default=s})),Yse=te(al(),1),Xse=te(Jse(),1);function Zse(){let e=new Yse.default({strict:!1,validateFormats:!0,validateSchema:!1,allErrors:!0});return(0,Xse.default)(e),e}var Qse=class{constructor(e){this._ajv=e??Zse()}getValidator(e){let t=`$id`in e&&typeof e.$id==`string`?this._ajv.getSchema(e.$id)??this._ajv.compile(e):this._ajv.compile(e);return e=>t(e)?{valid:!0,data:e,errorMessage:void 0}:{valid:!1,data:void 0,errorMessage:this._ajv.errorsText(t.errors)}}},$se=class{constructor(e){this._server=e}requestStream(e,t,n){return this._server.requestStream(e,t,n)}createMessageStream(e,t){let n=this._server.getClientCapabilities();if((e.tools||e.toolChoice)&&!n?.sampling?.tools)throw Error(`Client does not support sampling tools capability.`);if(e.messages.length>0){let t=e.messages[e.messages.length-1],n=Array.isArray(t.content)?t.content:[t.content],r=n.some(e=>e.type===`tool_result`),i=e.messages.length>1?e.messages[e.messages.length-2]:void 0,a=i?Array.isArray(i.content)?i.content:[i.content]:[],o=a.some(e=>e.type===`tool_use`);if(r){if(n.some(e=>e.type!==`tool_result`))throw Error(`The last message must contain only tool_result content if any is present`);if(!o)throw Error(`tool_result blocks are not matching any tool_use from the previous message`)}if(o){let e=new Set(a.filter(e=>e.type===`tool_use`).map(e=>e.id)),t=new Set(n.filter(e=>e.type===`tool_result`).map(e=>e.toolUseId));if(e.size!==t.size||![...e].every(e=>t.has(e)))throw Error(`ids of tool_result blocks and tool_use blocks from previous message do not match`)}}return this.requestStream({method:`sampling/createMessage`,params:e},ws,t)}elicitInputStream(e,t){let n=this._server.getClientCapabilities(),r=e.mode??`form`;switch(r){case`url`:if(!n?.elicitation?.url)throw Error(`Client does not support url elicitation.`);break;case`form`:if(!n?.elicitation?.form)throw Error(`Client does not support form elicitation.`)}let i=r===`form`&&e.mode===void 0?{...e,mode:`form`}:e;return this.requestStream({method:`elicitation/create`,params:i},js,t)}async getTask(e,t){return this._server.getTask({taskId:e},t)}async getTaskResult(e,t,n){return this._server.getTaskResult({taskId:e},t,n)}async listTasks(e,t){return this._server.listTasks(e?{cursor:e}:void 0,t)}async cancelTask(e,t){return this._server.cancelTask({taskId:e},t)}};function ece(e,t,n){if(!e)throw Error(`${n} does not support task creation (required for ${t})`);if(t===`tools/call`&&!e.tools?.call)throw Error(`${n} does not support task creation for tools/call (required for ${t})`)}function tce(e,t,n){if(!e)throw Error(`${n} does not support task creation (required for ${t})`);switch(t){case`sampling/createMessage`:if(!e.sampling?.createMessage)throw Error(`${n} does not support task creation for sampling/createMessage (required for ${t})`);break;case`elicitation/create`:if(!e.elicitation?.create)throw Error(`${n} does not support task creation for elicitation/create (required for ${t})`)}}var nce=class extends ese{constructor(e,t){super(t),this._serverInfo=e,this._loggingLevels=new Map,this.LOG_LEVEL_SEVERITY=new Map(_s.options.map((e,t)=>[e,t])),this.isMessageIgnored=(e,t)=>{let n=this._loggingLevels.get(t);return n?this.LOG_LEVEL_SEVERITY.get(e)<this.LOG_LEVEL_SEVERITY.get(n):!1},this._capabilities=t?.capabilities??{},this._instructions=t?.instructions,this._jsonSchemaValidator=t?.jsonSchemaValidator??new Qse,this.setRequestHandler(Do,e=>this._oninitialize(e)),this.setNotificationHandler(Oo,()=>this.oninitialized?.()),this._capabilities.logging&&this.setRequestHandler(ys,async(e,t)=>{let n=t.sessionId||t.requestInfo?.headers[`mcp-session-id`]||void 0,{level:r}=e.params,i=_s.safeParse(r);return i.success&&this._loggingLevels.set(n,i.data),{}})}get experimental(){return this._experimental||={tasks:new $se(this)},this._experimental}registerCapabilities(e){if(this.transport)throw Error(`Cannot register capabilities after connecting to transport`);this._capabilities=xc(this._capabilities,e)}setRequestHandler(e,t){let n=da(e)?.method;if(!n)throw Error(`Schema is missing a method literal`);let r=ma(n);if(typeof r!=`string`)throw Error(`Schema method literal must be a string`);return r===`tools/call`?super.setRequestHandler(e,async(e,n)=>{let r=la(gs,e);if(!r.success){let e=r.error instanceof Error?r.error.message:String(r.error);throw new Is(bo.InvalidParams,`Invalid tools/call request: ${e}`)}let{params:i}=r.data,a=await Promise.resolve(t(e,n));if(i.task){let e=la(Po,a);if(!e.success){let t=e.error instanceof Error?e.error.message:String(e.error);throw new Is(bo.InvalidParams,`Invalid task creation result: ${t}`)}return e.data}let o=la(hs,a);if(!o.success){let e=o.error instanceof Error?o.error.message:String(o.error);throw new Is(bo.InvalidParams,`Invalid tools/call result: ${e}`)}return o.data}):super.setRequestHandler(e,t)}assertCapabilityForMethod(e){switch(e){case`sampling/createMessage`:if(!this._clientCapabilities?.sampling)throw Error(`Client does not support sampling (required for ${e})`);break;case`elicitation/create`:if(!this._clientCapabilities?.elicitation)throw Error(`Client does not support elicitation (required for ${e})`);break;case`roots/list`:if(!this._clientCapabilities?.roots)throw Error(`Client does not support listing roots (required for ${e})`)}}assertNotificationCapability(e){switch(e){case`notifications/message`:if(!this._capabilities.logging)throw Error(`Server does not support logging (required for ${e})`);break;case`notifications/resources/updated`:case`notifications/resources/list_changed`:if(!this._capabilities.resources)throw Error(`Server does not support notifying about resources (required for ${e})`);break;case`notifications/tools/list_changed`:if(!this._capabilities.tools)throw Error(`Server does not support notifying of tool list changes (required for ${e})`);break;case`notifications/prompts/list_changed`:if(!this._capabilities.prompts)throw Error(`Server does not support notifying of prompt list changes (required for ${e})`);break;case`notifications/elicitation/complete`:if(!this._clientCapabilities?.elicitation?.url)throw Error(`Client does not support URL elicitation (required for ${e})`)}}assertRequestHandlerCapability(e){if(this._capabilities)switch(e){case`completion/complete`:if(!this._capabilities.completions)throw Error(`Server does not support completions (required for ${e})`);break;case`logging/setLevel`:if(!this._capabilities.logging)throw Error(`Server does not support logging (required for ${e})`);break;case`prompts/get`:case`prompts/list`:if(!this._capabilities.prompts)throw Error(`Server does not support prompts (required for ${e})`);break;case`resources/list`:case`resources/templates/list`:case`resources/read`:if(!this._capabilities.resources)throw Error(`Server does not support resources (required for ${e})`);break;case`tools/call`:case`tools/list`:if(!this._capabilities.tools)throw Error(`Server does not support tools (required for ${e})`);break;case`tasks/get`:case`tasks/list`:case`tasks/result`:case`tasks/cancel`:if(!this._capabilities.tasks)throw Error(`Server does not support tasks capability (required for ${e})`)}}assertTaskCapability(e){tce(this._clientCapabilities?.tasks?.requests,e,`Client`)}assertTaskHandlerCapability(e){this._capabilities&&ece(this._capabilities.tasks?.requests,e,`Server`)}async _oninitialize(e){let t=e.params.protocolVersion;return this._clientCapabilities=e.params.capabilities,this._clientVersion=e.params.clientInfo,{protocolVersion:Dae.includes(t)?t:to,capabilities:this.getCapabilities(),serverInfo:this._serverInfo,...this._instructions&&{instructions:this._instructions}}}getClientCapabilities(){return this._clientCapabilities}getClientVersion(){return this._clientVersion}getCapabilities(){return this._capabilities}async ping(){return this.request({method:`ping`},So)}async createMessage(e,t){if((e.tools||e.toolChoice)&&!this._clientCapabilities?.sampling?.tools)throw Error(`Client does not support sampling tools capability.`);if(e.messages.length>0){let t=e.messages[e.messages.length-1],n=Array.isArray(t.content)?t.content:[t.content],r=n.some(e=>e.type===`tool_result`),i=e.messages.length>1?e.messages[e.messages.length-2]:void 0,a=i?Array.isArray(i.content)?i.content:[i.content]:[],o=a.some(e=>e.type===`tool_use`);if(r){if(n.some(e=>e.type!==`tool_result`))throw Error(`The last message must contain only tool_result content if any is present`);if(!o)throw Error(`tool_result blocks are not matching any tool_use from the previous message`)}if(o){let e=new Set(a.filter(e=>e.type===`tool_use`).map(e=>e.id)),t=new Set(n.filter(e=>e.type===`tool_result`).map(e=>e.toolUseId));if(e.size!==t.size||![...e].every(e=>t.has(e)))throw Error(`ids of tool_result blocks and tool_use blocks from previous message do not match`)}}return e.tools?this.request({method:`sampling/createMessage`,params:e},Ts,t):this.request({method:`sampling/createMessage`,params:e},ws,t)}async elicitInput(e,t){switch(e.mode??`form`){case`url`:{if(!this._clientCapabilities?.elicitation?.url)throw Error(`Client does not support url elicitation.`);let n=e;return this.request({method:`elicitation/create`,params:n},js,t)}case`form`:{if(!this._clientCapabilities?.elicitation?.form)throw Error(`Client does not support form elicitation.`);let n=e.mode===`form`?e:{...e,mode:`form`},r=await this.request({method:`elicitation/create`,params:n},js,t);if(r.action===`accept`&&r.content&&n.requestedSchema)try{let e=this._jsonSchemaValidator.getValidator(n.requestedSchema)(r.content);if(!e.valid)throw new Is(bo.InvalidParams,`Elicitation response content does not match requested schema: ${e.errorMessage}`)}catch(e){throw e instanceof Is?e:new Is(bo.InternalError,`Error validating elicitation response: ${e instanceof Error?e.message:String(e)}`)}return r}}}createElicitationCompletionNotifier(e,t){if(!this._clientCapabilities?.elicitation?.url)throw Error(`Client does not support URL elicitation (required for notifications/elicitation/complete)`);return()=>this.notification({method:`notifications/elicitation/complete`,params:{elicitationId:e}},t)}async listRoots(e,t){return this.request({method:`roots/list`,params:e},Fs,t)}async sendLoggingMessage(e,t){if(this._capabilities.logging&&!this.isMessageIgnored(e.level,t))return this.notification({method:`notifications/message`,params:e})}async sendResourceUpdated(e){return this.notification({method:`notifications/resources/updated`,params:e})}async sendResourceListChanged(){return this.notification({method:`notifications/resources/list_changed`})}async sendToolListChanged(){return this.notification({method:`notifications/tools/list_changed`})}async sendPromptListChanged(){return this.notification({method:`notifications/prompts/list_changed`})}},ol=Symbol.for(`mcp.completable`);function sl(e){return!!e&&typeof e==`object`&&ol in e}function rce(e){return e[ol]?.complete}var ice;(function(e){e.Completable=`McpCompletable`})(ice||={});var ace=/^[A-Za-z0-9._-]{1,128}$/;function oce(e){let t=[];if(e.length===0)return{isValid:!1,warnings:[`Tool name cannot be empty`]};if(e.length>128)return{isValid:!1,warnings:[`Tool name exceeds maximum length of 128 characters (current: ${e.length})`]};if(e.includes(` `)&&t.push(`Tool name contains spaces, which may cause parsing issues`),e.includes(`,`)&&t.push(`Tool name contains commas, which may cause parsing issues`),(e.startsWith(`-`)||e.endsWith(`-`))&&t.push(`Tool name starts or ends with a dash, which may cause parsing issues in some contexts`),(e.startsWith(`.`)||e.endsWith(`.`))&&t.push(`Tool name starts or ends with a dot, which may cause parsing issues in some contexts`),!ace.test(e)){let n=e.split(``).filter(e=>!/[A-Za-z0-9._-]/.test(e)).filter((e,t,n)=>n.indexOf(e)===t);return t.push(`Tool name contains invalid characters: ${n.map(e=>`"${e}"`).join(`, `)}`,`Allowed characters are: A-Z, a-z, 0-9, underscore (_), dash (-), and dot (.)`),{isValid:!1,warnings:t}}return{isValid:!0,warnings:t}}function sce(e,t){if(t.length>0){console.warn(`Tool name validation warning for "${e}":`);for(let e of t)console.warn(` - ${e}`);console.warn(`Tool registration will proceed, but this may cause compatibility issues.`),console.warn(`Consider updating the tool name to conform to the MCP tool naming standard.`),console.warn(`See SEP: Specify Format for Tool Names (https://github.com/modelcontextprotocol/modelcontextprotocol/issues/986) for more details.`)}}function cl(e){let t=oce(e);return sce(e,t.warnings),t.isValid}var ll=class{constructor(e){this._mcpServer=e}registerToolTask(e,t,n){let r={taskSupport:`required`,...t.execution};if(r.taskSupport===`forbidden`)throw Error(`Cannot register task-based tool '${e}' with taskSupport 'forbidden'. Use registerTool() instead.`);return this._mcpServer._createRegisteredTool(e,t.title,t.description,t.inputSchema,t.outputSchema,t.annotations,r,t._meta,n)}},cce=class{constructor(e,t){this._registeredResources={},this._registeredResourceTemplates={},this._registeredTools={},this._registeredPrompts={},this._toolHandlersInitialized=!1,this._completionHandlerInitialized=!1,this._resourceHandlersInitialized=!1,this._promptHandlersInitialized=!1,this.server=new nce(e,t)}get experimental(){return this._experimental||={tasks:new ll(this)},this._experimental}async connect(e){return await this.server.connect(e)}async close(){await this.server.close()}setToolRequestHandlers(){this._toolHandlersInitialized||=(this.server.assertCanSetRequestHandler(ml(ms)),this.server.assertCanSetRequestHandler(ml(gs)),this.server.registerCapabilities({tools:{listChanged:!0}}),this.server.setRequestHandler(ms,()=>({tools:Object.entries(this._registeredTools).filter(([,e])=>e.enabled).map(([e,t])=>{let n={name:e,title:t.title,description:t.description,inputSchema:(()=>{let e=fa(t.inputSchema);return e?_c(e,{strictUnions:!0,pipeStrategy:`input`}):lce})(),annotations:t.annotations,execution:t.execution,_meta:t._meta};if(t.outputSchema){let e=fa(t.outputSchema);e&&(n.outputSchema=_c(e,{strictUnions:!0,pipeStrategy:`output`}))}return n})})),this.server.setRequestHandler(gs,async(e,t)=>{try{let n=this._registeredTools[e.params.name];if(!n)throw new Is(bo.InvalidParams,`Tool ${e.params.name} not found`);if(!n.enabled)throw new Is(bo.InvalidParams,`Tool ${e.params.name} disabled`);let r=!!e.params.task,i=n.execution?.taskSupport,a=`createTask`in n.handler;if((i===`required`||i===`optional`)&&!a)throw new Is(bo.InternalError,`Tool ${e.params.name} has taskSupport '${i}' but was not registered with registerToolTask`);if(i===`required`&&!r)throw new Is(bo.MethodNotFound,`Tool ${e.params.name} requires task augmentation (taskSupport: 'required')`);if(i===`optional`&&!r&&a)return await this.handleAutomaticTaskPolling(n,e,t);let o=await this.validateToolInput(n,e.params.arguments,e.params.name),s=await this.executeToolHandler(n,o,t);return r||await this.validateToolOutput(n,s,e.params.name),s}catch(e){if(e instanceof Is&&e.code===bo.UrlElicitationRequired)throw e;return this.createToolError(e instanceof Error?e.message:String(e))}}),!0)}createToolError(e){return{content:[{type:`text`,text:e}],isError:!0}}async validateToolInput(e,t,n){if(!e.inputSchema)return;let r=await ua(fa(e.inputSchema)??e.inputSchema,t);if(!r.success){let e=pa(`error`in r?r.error:`Unknown error`);throw new Is(bo.InvalidParams,`Input validation error: Invalid arguments for tool ${n}: ${e}`)}return r.data}async validateToolOutput(e,t,n){if(!e.outputSchema||!(`content`in t)||t.isError)return;if(!t.structuredContent)throw new Is(bo.InvalidParams,`Output validation error: Tool ${n} has an output schema but no structured content was provided`);let r=await ua(fa(e.outputSchema),t.structuredContent);if(!r.success){let e=pa(`error`in r?r.error:`Unknown error`);throw new Is(bo.InvalidParams,`Output validation error: Invalid structured content for tool ${n}: ${e}`)}}async executeToolHandler(e,t,n){let r=e.handler;if(`createTask`in r){if(!n.taskStore)throw Error(`No task store provided.`);let i={...n,taskStore:n.taskStore};if(e.inputSchema){let e=r;return await Promise.resolve(e.createTask(t,i))}{let e=r;return await Promise.resolve(e.createTask(i))}}if(e.inputSchema){let e=r;return await Promise.resolve(e(t,n))}{let e=r;return await Promise.resolve(e(n))}}async handleAutomaticTaskPolling(e,t,n){if(!n.taskStore)throw Error(`No task store provided for task-capable tool.`);let r=await this.validateToolInput(e,t.params.arguments,t.params.name),i=e.handler,a={...n,taskStore:n.taskStore},o=r?await Promise.resolve(i.createTask(r,a)):await Promise.resolve(i.createTask(a)),s=o.task.taskId,c=o.task,l=c.pollInterval??5e3;for(;c.status!==`completed`&&c.status!==`failed`&&c.status!==`cancelled`;){await new Promise(e=>setTimeout(e,l));let e=await n.taskStore.getTask(s);if(!e)throw new Is(bo.InternalError,`Task ${s} not found during polling`);c=e}return await n.taskStore.getTaskResult(s)}setCompletionRequestHandler(){this._completionHandlerInitialized||=(this.server.assertCanSetRequestHandler(ml(Ms)),this.server.registerCapabilities({completions:{}}),this.server.setRequestHandler(Ms,async e=>{switch(e.params.ref.type){case`ref/prompt`:return Eoe(e),this.handlePromptCompletion(e,e.params.ref);case`ref/resource`:return Doe(e),this.handleResourceCompletion(e,e.params.ref);default:throw new Is(bo.InvalidParams,`Invalid completion reference: ${e.params.ref}`)}}),!0)}async handlePromptCompletion(e,t){let n=this._registeredPrompts[t.name];if(!n)throw new Is(bo.InvalidParams,`Prompt ${t.name} not found`);if(!n.enabled)throw new Is(bo.InvalidParams,`Prompt ${t.name} disabled`);if(!n.argsSchema)return gl;let r=da(n.argsSchema)?.[e.params.argument.name];if(!sl(r))return gl;let i=rce(r);return i?hl(await i(e.params.argument.value,e.params.context)):gl}async handleResourceCompletion(e,t){let n=Object.values(this._registeredResourceTemplates).find(e=>e.resourceTemplate.uriTemplate.toString()===t.uri);if(!n){if(this._registeredResources[t.uri])return gl;throw new Is(bo.InvalidParams,`Resource template ${e.params.ref.uri} not found`)}let r=n.resourceTemplate.completeCallback(e.params.argument.name);return r?hl(await r(e.params.argument.value,e.params.context)):gl}setResourceRequestHandlers(){this._resourceHandlersInitialized||=(this.server.assertCanSetRequestHandler(ml(Zo)),this.server.assertCanSetRequestHandler(ml($o)),this.server.assertCanSetRequestHandler(ml(ns)),this.server.registerCapabilities({resources:{listChanged:!0}}),this.server.setRequestHandler(Zo,async(e,t)=>{let n=Object.entries(this._registeredResources).filter(([e,t])=>t.enabled).map(([e,t])=>({uri:e,name:t.name,...t.metadata})),r=[];for(let e of Object.values(this._registeredResourceTemplates)){if(!e.resourceTemplate.listCallback)continue;let n=await e.resourceTemplate.listCallback(t);for(let t of n.resources)r.push({...e.metadata,...t})}return{resources:[...n,...r]}}),this.server.setRequestHandler($o,async()=>({resourceTemplates:Object.entries(this._registeredResourceTemplates).map(([e,t])=>({name:e,uriTemplate:t.resourceTemplate.uriTemplate.toString(),...t.metadata}))})),this.server.setRequestHandler(ns,async(e,t)=>{let n=new URL(e.params.uri),r=this._registeredResources[n.toString()];if(r){if(!r.enabled)throw new Is(bo.InvalidParams,`Resource ${n} disabled`);return r.readCallback(n,t)}for(let e of Object.values(this._registeredResourceTemplates)){let r=e.resourceTemplate.uriTemplate.match(n.toString());if(r)return e.readCallback(n,r,t)}throw new Is(bo.InvalidParams,`Resource ${n} not found`)}),!0)}setPromptRequestHandlers(){this._promptHandlersInitialized||=(this.server.assertCanSetRequestHandler(ml(as)),this.server.assertCanSetRequestHandler(ml(ss)),this.server.registerCapabilities({prompts:{listChanged:!0}}),this.server.setRequestHandler(as,()=>({prompts:Object.entries(this._registeredPrompts).filter(([,e])=>e.enabled).map(([e,t])=>({name:e,title:t.title,description:t.description,arguments:t.argsSchema?uce(t.argsSchema):void 0}))})),this.server.setRequestHandler(ss,async(e,t)=>{let n=this._registeredPrompts[e.params.name];if(!n)throw new Is(bo.InvalidParams,`Prompt ${e.params.name} not found`);if(!n.enabled)throw new Is(bo.InvalidParams,`Prompt ${e.params.name} disabled`);if(n.argsSchema){let r=await ua(fa(n.argsSchema),e.params.arguments);if(!r.success){let t=pa(`error`in r?r.error:`Unknown error`);throw new Is(bo.InvalidParams,`Invalid arguments for prompt ${e.params.name}: ${t}`)}let i=r.data,a=n.callback;return await Promise.resolve(a(i,t))}{let e=n.callback;return await Promise.resolve(e(t))}}),!0)}resource(e,t,...n){let r;typeof n[0]==`object`&&(r=n.shift());let i=n[0];if(typeof t==`string`){if(this._registeredResources[t])throw Error(`Resource ${t} is already registered`);let n=this._createRegisteredResource(e,void 0,t,r,i);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),n}{if(this._registeredResourceTemplates[e])throw Error(`Resource template ${e} is already registered`);let n=this._createRegisteredResourceTemplate(e,void 0,t,r,i);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),n}}registerResource(e,t,n,r){if(typeof t==`string`){if(this._registeredResources[t])throw Error(`Resource ${t} is already registered`);let i=this._createRegisteredResource(e,n.title,t,n,r);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),i}{if(this._registeredResourceTemplates[e])throw Error(`Resource template ${e} is already registered`);let i=this._createRegisteredResourceTemplate(e,n.title,t,n,r);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),i}}_createRegisteredResource(e,t,n,r,i){let a={name:e,title:t,metadata:r,readCallback:i,enabled:!0,disable:()=>a.update({enabled:!1}),enable:()=>a.update({enabled:!0}),remove:()=>a.update({uri:null}),update:e=>{e.uri!==void 0&&e.uri!==n&&(delete this._registeredResources[n],e.uri&&(this._registeredResources[e.uri]=a)),e.name!==void 0&&(a.name=e.name),e.title!==void 0&&(a.title=e.title),e.metadata!==void 0&&(a.metadata=e.metadata),e.callback!==void 0&&(a.readCallback=e.callback),e.enabled!==void 0&&(a.enabled=e.enabled),this.sendResourceListChanged()}};return this._registeredResources[n]=a,a}_createRegisteredResourceTemplate(e,t,n,r,i){let a={resourceTemplate:n,title:t,metadata:r,readCallback:i,enabled:!0,disable:()=>a.update({enabled:!1}),enable:()=>a.update({enabled:!0}),remove:()=>a.update({name:null}),update:t=>{t.name!==void 0&&t.name!==e&&(delete this._registeredResourceTemplates[e],t.name&&(this._registeredResourceTemplates[t.name]=a)),t.title!==void 0&&(a.title=t.title),t.template!==void 0&&(a.resourceTemplate=t.template),t.metadata!==void 0&&(a.metadata=t.metadata),t.callback!==void 0&&(a.readCallback=t.callback),t.enabled!==void 0&&(a.enabled=t.enabled),this.sendResourceListChanged()}};this._registeredResourceTemplates[e]=a;let o=n.uriTemplate.variableNames;return Array.isArray(o)&&o.some(e=>!!n.completeCallback(e))&&this.setCompletionRequestHandler(),a}_createRegisteredPrompt(e,t,n,r,i){let a={title:t,description:n,argsSchema:r===void 0?void 0:ca(r),callback:i,enabled:!0,disable:()=>a.update({enabled:!1}),enable:()=>a.update({enabled:!0}),remove:()=>a.update({name:null}),update:t=>{t.name!==void 0&&t.name!==e&&(delete this._registeredPrompts[e],t.name&&(this._registeredPrompts[t.name]=a)),t.title!==void 0&&(a.title=t.title),t.description!==void 0&&(a.description=t.description),t.argsSchema!==void 0&&(a.argsSchema=ca(t.argsSchema)),t.callback!==void 0&&(a.callback=t.callback),t.enabled!==void 0&&(a.enabled=t.enabled),this.sendPromptListChanged()}};return this._registeredPrompts[e]=a,r&&Object.values(r).some(e=>sl(e instanceof Ka?e._def?.innerType:e))&&this.setCompletionRequestHandler(),a}_createRegisteredTool(e,t,n,r,i,a,o,s,c){cl(e);let l={title:t,description:n,inputSchema:pl(r),outputSchema:pl(i),annotations:a,execution:o,_meta:s,handler:c,enabled:!0,disable:()=>l.update({enabled:!1}),enable:()=>l.update({enabled:!0}),remove:()=>l.update({name:null}),update:t=>{t.name!==void 0&&t.name!==e&&(typeof t.name==`string`&&cl(t.name),delete this._registeredTools[e],t.name&&(this._registeredTools[t.name]=l)),t.title!==void 0&&(l.title=t.title),t.description!==void 0&&(l.description=t.description),t.paramsSchema!==void 0&&(l.inputSchema=ca(t.paramsSchema)),t.outputSchema!==void 0&&(l.outputSchema=ca(t.outputSchema)),t.callback!==void 0&&(l.handler=t.callback),t.annotations!==void 0&&(l.annotations=t.annotations),t._meta!==void 0&&(l._meta=t._meta),t.enabled!==void 0&&(l.enabled=t.enabled),this.sendToolListChanged()}};return this._registeredTools[e]=l,this.setToolRequestHandlers(),this.sendToolListChanged(),l}tool(e,...t){if(this._registeredTools[e])throw Error(`Tool ${e} is already registered`);let n,r,i,a;if(typeof t[0]==`string`&&(n=t.shift()),t.length>1){let n=t[0];if(fl(n))r=t.shift(),t.length>1&&typeof t[0]==`object`&&t[0]!==null&&!fl(t[0])&&(a=t.shift());else if(typeof n==`object`&&n){if(Object.values(n).some(e=>typeof e==`object`&&!!e))throw Error(`Tool ${e} expected a Zod schema or ToolAnnotations, but received an unrecognized object`);a=t.shift()}}let o=t[0];return this._createRegisteredTool(e,void 0,n,r,i,a,{taskSupport:`forbidden`},void 0,o)}registerTool(e,t,n){if(this._registeredTools[e])throw Error(`Tool ${e} is already registered`);let{title:r,description:i,inputSchema:a,outputSchema:o,annotations:s,_meta:c}=t;return this._createRegisteredTool(e,r,i,a,o,s,{taskSupport:`forbidden`},c,n)}prompt(e,...t){if(this._registeredPrompts[e])throw Error(`Prompt ${e} is already registered`);let n;typeof t[0]==`string`&&(n=t.shift());let r;t.length>1&&(r=t.shift());let i=t[0],a=this._createRegisteredPrompt(e,void 0,n,r,i);return this.setPromptRequestHandlers(),this.sendPromptListChanged(),a}registerPrompt(e,t,n){if(this._registeredPrompts[e])throw Error(`Prompt ${e} is already registered`);let{title:r,description:i,argsSchema:a}=t,o=this._createRegisteredPrompt(e,r,i,a,n);return this.setPromptRequestHandlers(),this.sendPromptListChanged(),o}isConnected(){return this.server.transport!==void 0}async sendLoggingMessage(e,t){return this.server.sendLoggingMessage(e,t)}sendResourceListChanged(){this.isConnected()&&this.server.sendResourceListChanged()}sendToolListChanged(){this.isConnected()&&this.server.sendToolListChanged()}sendPromptListChanged(){this.isConnected()&&this.server.sendPromptListChanged()}},lce={type:`object`,properties:{}};function ul(e){return typeof e==`object`&&!!e&&`parse`in e&&typeof e.parse==`function`&&`safeParse`in e&&typeof e.safeParse==`function`}function dl(e){return`_def`in e||`_zod`in e||ul(e)}function fl(e){return typeof e!=`object`||!e||dl(e)?!1:Object.keys(e).length===0||Object.values(e).some(ul)}function pl(e){if(e){if(fl(e))return ca(e);if(!dl(e))throw Error(`inputSchema must be a Zod schema or raw shape, received an unrecognized object`);return e}}function uce(e){let t=da(e);return t?Object.entries(t).map(([e,t])=>({name:e,description:vie(t),required:!yie(t)})):[]}function ml(e){let t=da(e)?.method;if(!t)throw Error(`Schema is missing a method literal`);let n=ma(t);if(typeof n==`string`)return n;throw Error(`Schema method literal must be a string`)}function hl(e){return{completion:{values:e.slice(0,100),total:e.length,hasMore:e.length>100}}}var gl={completion:{values:[],hasMore:!1}},dce=class{constructor(e){this._maxBufferSize=e?.maxBufferSize??10485760}append(e){if((this._buffer?.length??0)+e.length>this._maxBufferSize)throw this.clear(),Error(`ReadBuffer exceeded maximum size of ${this._maxBufferSize} bytes`);this._buffer=this._buffer?Buffer.concat([this._buffer,e]):e}readMessage(){if(!this._buffer)return null;let e=this._buffer.indexOf(`
1491
1491
  `);if(e===-1)return null;let t=this._buffer.toString(`utf8`,0,e).replace(/\r$/,``);return this._buffer=this._buffer.subarray(e+1),fce(t)}clear(){this._buffer=void 0}};function fce(e){return Nae.parse(JSON.parse(e))}function pce(e){return JSON.stringify(e)+`
1492
- `}var mce=class{constructor(t=e.stdin,n=e.stdout,r){this._stdin=t,this._stdout=n,this._started=!1,this._ondata=e=>{try{this._readBuffer.append(e),this.processReadBuffer()}catch(e){this.onerror?.(e),this.close().catch(()=>{})}},this._onerror=e=>{this.onerror?.(e)},this._readBuffer=new dce({maxBufferSize:r?.maxBufferSize})}async start(){if(this._started)throw Error(`StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.`);this._started=!0,this._stdin.on(`data`,this._ondata),this._stdin.on(`error`,this._onerror)}processReadBuffer(){for(;;)try{let e=this._readBuffer.readMessage();if(e===null)break;this.onmessage?.(e)}catch(e){this.onerror?.(e)}}async close(){this._stdin.off(`data`,this._ondata),this._stdin.off(`error`,this._onerror),this._stdin.listenerCount(`data`)===0&&this._stdin.pause(),this._readBuffer.clear(),this.onclose?.()}send(e){return new Promise(t=>{let n=pce(e);this._stdout.write(n)?t():this._stdout.once(`drain`,t)})}},_l=`/*ANTU_SPEC*/null`;function vl(e){return String(e).replace(/</g,`\\u003c`)}function hce(e,t,{preset:n}={}){if(e.split(`/*ANTU_SPEC*/null`).length!==2)throw Error(`the viewer template does not hold exactly one ${_l}`);let r=vl(JSON.stringify(t)),i=n?`;window.__ANTU_PRESET__ = ${vl(JSON.stringify(n))}`:``;return e.replace(_l,()=>r+i)}f(u(h(import.meta.url)),`../..`);var yl=f(u(h(import.meta.url)),`..`);d(yl,`dist-engine/engine.js`),d(yl,`dist-engine/engine.css`);function gce(e){return String(e).replace(/[&<>"]/g,e=>({"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`})[e])}function _ce(){return`0.9.0`}function vce(e){return String(e||`antu`).replace(/[\\/:*?"<>|\s]+/g,`-`).slice(0,60)}function yce(e,{outPath:t,preset:r,force:a=!1,quiet:o=!1}={}){let s;{let t=gce(e?.title||`Antu`);s=hce(i(d(yl,`assets/viewer.html`),`utf8`),e,{preset:r}).replace(/<title>[^<]*<\/title>/,()=>`<title>${t} · Antu</title>`)}let l=f(t||`${vce(e?.title)}.html`);return n(u(l),{recursive:!0}),c(l,s),{path:l,bytes:Buffer.byteLength(s)}}var bl=new Map;function xl(e,t){if(!e)throw Error(`registerKnowledge: type must not be empty`);if(!t?.validate)throw Error(`registerKnowledge: validate is required`);if(!t?.describe)throw Error(`registerKnowledge: describe is required (the agent-facing field table)`);if(!Number.isInteger(t.specVersion)||t.specVersion<1)throw Error(`registerKnowledge: specVersion is required, a whole number (the generation of this type's JSON format, core/specVersion.js)`);bl.set(e,t)}function Sl(e){return bl.get(e)}function Cl(){return[...bl.entries()].map(([e,t])=>({type:e,labelKey:t.label??`graphType.${e}`}))}function wl(e){return bl.get(e)?.validate}function bce(e,t){let n=bl.get(e)?.layouts;if(n)return t&&n[t]?n[t]:Object.values(n)[0]}function Tl(e){return Object.keys(bl.get(e)?.layouts??{})}var El=e=>({name:`specVersion`,req:`no`,ty:`integer`,note:`which generation of this format the file follows (now ${e}); omit = the current one. Write it: it is how an older file is recognised after a breaking change`});function xce(e,t){return e.specVersion===void 0?null:!Number.isInteger(e.specVersion)||e.specVersion<1?{key:`err.specVersionForm`,params:{value:JSON.stringify(e.specVersion)}}:Number.isInteger(t)&&e.specVersion>t?{key:`err.specVersionNewer`,params:{value:e.specVersion,known:t,type:e.type}}:null}var Sce=19,Cce=2,wce=18,Dl=6,Tce=16,Ece=11.5,Ol=1,Dce=.55;function kl(e){let t=e.codePointAt(0);return t>=4352&&t<=4447||t>=11904&&t<=42191||t>=44032&&t<=55203||t>=63744&&t<=64255||t>=65072&&t<=65135||t>=65280&&t<=65376||t>=65504&&t<=65510?Ol:Dce}function Al(e){let t=0;for(let n of String(e??``))t+=kl(n);return t}var jl=(e,t)=>Al(e)*t,Oce=262/13;262/Ece;function kce(e={},t=Cce,n=0){let r=22+Sce*t+Dl+Tce;return e.summary&&(r+=24),e.actors&&n>0&&(r+=wce*n+Dl),r}function Ml(e,t,n={}){let r=n.latin??1,i=n.cjk??1;return Nl(e,t,e=>{let t=0;for(let n of e)t+=kl(n)*(kl(n)===Ol?i:r);return t})}function Nl(e,t,n){let r=t,i=n,a=String(e??``);if(!a)return 0;let o=a.match(/[^\sᄀ-ᅟ⺀-꓏가-힣豈-﫿︰-﹯＀-⦆¢-₩]+|\s|./gu)||[],s=1,c=0;for(let e of o){let t=i(e);if(/^\s$/.test(e)){c>0&&(c+=t);continue}if(c+t<=r)c+=t;else if(t<=r)s+=+(c>0),c=t;else{c>0&&(s+=1);let e=Math.ceil(t/r);s+=e-1,c=t-(e-1)*r}}return s}var Pl={SIDE1:`side1`,AXIS:`axis`,SIDE2:`side2`},Fl=3,Ace={label:`all`,splitBy:`group`};function Il(e){let t=Array.isArray(e?.views)?e.views.filter(Bl):[];return t.length>0?t:[Ace]}function Ll(e,t){let n=e?.[t]?.actors;return Array.isArray(n)?[...new Set(n.filter(e=>typeof e==`string`))]:[]}function jce(e,t){return e.splitBy===`actor`?{[Pl.SIDE1]:e?.side1?.label??``,[Pl.SIDE2]:e?.side2?.label??``,[Pl.AXIS]:e?.axis?.label??``}:{[Pl.SIDE1]:t[0]?.label??``,[Pl.SIDE2]:t[1]?.label??``,[Pl.AXIS]:t[2]?.label??``}}var Rl=/^\d{4}(-\d{2}(-\d{2}(T\d{2}(:\d{2}(:\d{2})?)?)?)?)?$/;function Mce(e,t){if(typeof e!=`string`||typeof t!=`string`)return!1;let n=Math.min(e.length,t.length);return e.slice(0,n)<t.slice(0,n)}var zl=[Pl.SIDE1,Pl.SIDE2,Pl.AXIS];function Bl(e){return e&&typeof e==`object`&&!Array.isArray(e)}function Vl(e,t){let n=Bl(t)?t:Il(e)[0],r=n.splitBy===`actor`,i=Ll(n,`side1`),a=Ll(n,`side2`),o=[],s=Array.isArray(e?.actors)?e.actors:[],c=Array.isArray(e?.groups)?e.groups:[],l=Array.isArray(e?.sources)?e.sources:[],u=e?.slots,d={errors:o,view:n,sideLabels:{[Pl.SIDE1]:``,[Pl.SIDE2]:``,[Pl.AXIS]:``},columns:[],rows:[],placements:new Map,axisColumnIndex:0,actorById:new Map,groupById:new Map,groupIndexById:new Map,sourceById:new Map,eventCount:0},f=new Map;s.forEach((e,t)=>{if(!Bl(e)){o.push(se(`err.notObject`,{at:`actors[${t}]`}));return}if(!e.id){o.push(se(`err.required`,{at:`actors[${t}]`,field:`id`}));return}f.has(e.id)&&o.push(se(`err.duplicateId`,{at:`actors[${t}]`,id:e.id})),f.set(e.id,e),e.name||o.push(se(`err.required`,{at:`actors[${t}] (${e.id})`,field:`name`}))}),e?.views!==void 0&&e?.views!==null&&(Array.isArray(e.views)?e.views.forEach((e,t)=>{let n=`views[${t}]`;if(!Bl(e)){o.push(se(`err.notObject`,{at:n}));return}if(e.label||o.push(se(`err.required`,{at:n,field:`label`})),e.splitBy!==`actor`&&e.splitBy!==`group`&&o.push(se(`err.badSplitBy`,{at:n,value:e.splitBy})),e.splitBy===`actor`){let t=Ll(e,`side1`),r=Ll(e,`side2`);[...t,...r].forEach(e=>{f.has(e)||o.push(se(`err.missingRef`,{at:n,field:`side`,kind:`actor`,id:e}))});let i=t.filter(e=>r.includes(e));i.length>0&&o.push(se(`err.bothSides`,{at:n,names:i.join(`, `)}))}}):o.push(se(`err.viewsNotArray`)));let p=new Map,m=new Map;c.length>Fl&&o.push(se(`err.tooManyGroups`,{at:`groups`,max:Fl,actual:c.length})),c.forEach((e,t)=>{if(!Bl(e)){o.push(se(`err.notObject`,{at:`groups[${t}]`}));return}if(!e.id){o.push(se(`err.required`,{at:`groups[${t}]`,field:`id`}));return}m.has(e.id)&&o.push(se(`err.duplicateId`,{at:`groups[${t}]`,id:e.id})),p.set(e.id,e),m.set(e.id,t),e.label||o.push(se(`err.required`,{at:`groups[${t}] (${e.id})`,field:`label`}))});let h=new Map;if(l.forEach((e,t)=>{if(!Bl(e)){o.push(se(`err.notObject`,{at:`sources[${t}]`}));return}if(!e.id){o.push(se(`err.required`,{at:`sources[${t}]`,field:`id`}));return}h.has(e.id)&&o.push(se(`err.duplicateId`,{at:`sources[${t}]`,id:e.id})),h.set(e.id,e),e.type||o.push(se(`err.required`,{at:`sources[${t}] (${e.id})`,field:`type`})),e.name||o.push(se(`err.required`,{at:`sources[${t}] (${e.id})`,field:`name`}))}),!Array.isArray(u))return o.push(se(`err.slotNotArray`)),{...d,actorById:f,groupById:p,groupIndexById:m,sourceById:h};u.length===0&&o.push(se(`err.slotsEmpty`));let g=new Set,_={[Pl.SIDE1]:new Set,[Pl.SIDE2]:new Set},v=[];u.forEach((e,t)=>{let n=`slots[${t}]`;if(!Bl(e)){o.push(se(`err.slotShape`,{at:n}));return}if(!Array.isArray(e.events)){o.push(se(`err.eventsNotArray`,{at:n}));return}e.events.length===0&&o.push(se(`err.slotEventsEmpty`,{at:n})),e.events.forEach((e,s)=>{let c=`${n}.events[${s}]${e?.id?` (${e.id})`:``}`;if(!Bl(e)){o.push(se(`err.notObject`,{at:c}));return}e.id?g.has(e.id)?o.push(se(`err.duplicateId`,{at:c,id:e.id})):g.add(e.id):o.push(se(`err.required`,{at:c,field:`id`})),e.date&&!Rl.test(e.date)&&o.push(se(`err.badDate`,{at:c,field:`date`,value:e.date})),e.label||o.push(se(`err.required`,{at:c,field:`label`})),e.dateEnd!==void 0&&e.dateEnd!==null&&(typeof e.dateEnd!=`string`||!Rl.test(e.dateEnd)?o.push(se(`err.badDate`,{at:c,field:`dateEnd`,value:e.dateEnd})):e.date?Mce(e.dateEnd,e.date)&&o.push(se(`err.dateEndBeforeDate`,{at:c,end:e.dateEnd,start:e.date})):o.push(se(`err.dateEndNeedsDate`,{at:c}))),e.summary!==void 0&&e.summary!==null&&(typeof e.summary==`string`?Al(e.summary)>22.782608695652176&&o.push(se(`err.summaryTooLong`,{at:c,max:22,actual:Math.ceil(Al(e.summary))})):o.push(se(`err.mustBeString`,{at:c,field:`summary`})));let l=Array.isArray(e.actorIds)?e.actorIds:[];l.forEach(e=>{f.has(e)||o.push(se(`err.missingRef`,{at:c,field:`actorIds`,kind:`actor`,id:e}))}),e.groupId&&!m.has(e.groupId)&&o.push(se(`err.missingRef`,{at:c,field:`groupId`,kind:`group`,id:e.groupId})),(Array.isArray(e.sourceIds)?e.sourceIds:[]).forEach(e=>{h.has(e)||o.push(se(`err.missingRef`,{at:c,field:`sourceIds`,kind:`source`,id:e}))});let u=e.groupId?m.get(e.groupId):void 0,d,p=null;if(r){let e=[...i,...a];if(e.length>0&&l.length>0&&!l.some(t=>e.includes(t)))return;l.length===1&&i.includes(l[0])?(d=Pl.SIDE1,p=l[0]):l.length===1&&a.includes(l[0])?(d=Pl.SIDE2,p=l[0]):d=Pl.AXIS}else if(l.length>=2)d=Pl.AXIS,(u===0||u===1)&&o.push(se(`err.multiActorNeedsAxis`,{at:c,n:l.length,groupId:e.groupId}));else if(e.groupId===void 0||e.groupId===null||e.groupId===``)d=Pl.AXIS;else if(u===void 0)return;else d=zl[u]??Pl.AXIS;if(!r&&d!==Pl.AXIS&&l.length!==1){o.push(se(`err.groupNeedsOneActor`,{at:c,groupId:e.groupId,n:l.length}));return}!r&&d!==Pl.AXIS&&l.length===1&&(p=l[0]),p&&f.has(p)&&_[d].add(p),v.push({slotIndex:t,event:e,side:d,actorId:p})})});let y=s.map(e=>Bl(e)?e.id:null).filter(Boolean),b=e=>r?y.filter(t=>Ll(n,e).includes(t)):y.filter(t=>_[e].has(t)),x=[];b(Pl.SIDE1).reverse().forEach(e=>{x.push({key:`${Pl.SIDE1}:${e}`,side:Pl.SIDE1,actorId:e,actorName:f.get(e)?.name})});let S=x.length;x.push({key:Pl.AXIS,side:Pl.AXIS}),b(Pl.SIDE2).forEach(e=>{x.push({key:`${Pl.SIDE2}:${e}`,side:Pl.SIDE2,actorId:e,actorName:f.get(e)?.name})});let C=new Map(x.map((e,t)=>[e.key,t])),w=u.map((e,t)=>({index:t,cells:new Map})),T=new Map,ee=0;return v.forEach(({slotIndex:e,event:t,side:n,actorId:r})=>{let i=n===Pl.AXIS?Pl.AXIS:`${n}:${r}`,a=C.get(i);if(a===void 0)return;ee+=1;let s=w[e];if(s.cells.has(i)){let n=s.cells.get(i);o.push(se(`err.oneEventPerCell`,{at:`slots[${e}]`,a:n.id,b:t.id}))}else s.cells.set(i,t);T.set(t.id,{row:e,col:a,key:i})}),{errors:o,view:n,sideLabels:jce(n,c),columns:x,rows:w,placements:T,axisColumnIndex:S,actorById:f,groupById:p,groupIndexById:m,sourceById:h,eventCount:ee}}function Hl(e){return e===Pl.SIDE1?0:e===Pl.SIDE2?1:2}function Nce(e){let t=1;for(let n of e.rows)n.cells.forEach(e=>{let n=Al(e.label||``);t=Math.max(t,Math.min(2,Math.ceil(n/Oce)))});return t}function Pce(e,t){if(!t.actors)return 0;let n=0;for(let t of e.rows)t.cells.forEach(t=>{let r=(Array.isArray(t.actorIds)?t.actorIds:[]).map(t=>e.actorById.get(t)?.name||t);if(r.length===0)return;let i=r.reduce((e,t)=>e+jl(t,10)+14,0)+4*(r.length-1);n=Math.max(n,Math.ceil(i/262))});return n}function Fce(e,t,n){let r=e.columns.length,i=e.rows.length,a=Nce(e),o=Pce(e,t),s=kce(t,a,o),c=s+28,l=n?316:c,u=n?c:316,d=n?150:0,f=n?0:96;return{isH:n,colCount:r,rowCount:i,labelLines:a,actorLines:o,cardH:s,cellH:c,slotExtent:l,laneExtent:u,originX:d,originY:f,cellBoxW:n?l:u,cellBoxH:n?u:l,cellAt:(e,t)=>n?{x:d+e*l,y:t*u}:{x:t*u,y:f+e*l},axisCenter:e.axisColumnIndex*u+u/2,contentW:n?d+i*l+6:r*u,contentH:n?r*u:f+i*l+6}}var Ul={draggable:!1,selectable:!1,connectable:!1,focusable:!1};function Ice(e,t,n){let r=(Array.isArray(e.actorIds)?e.actorIds:[]).map(e=>t.actorById.get(e)?.name||e),i=(Array.isArray(e.sourceIds)?e.sourceIds:[]).map(e=>t.sourceById.get(e)).filter(Boolean);return{event:e,actorNames:r,sources:i,sourceCount:i.length,row:n}}function Lce(e){return{id:`__cells__`,type:`cells`,position:{x:0,y:0},width:1,height:1,style:{pointerEvents:`none`},data:{cols:e.colCount,rows:e.rowCount,cellW:e.cellBoxW,cellH:e.cellBoxH,originX:e.originX,originY:e.originY,isH:e.isH},...Ul}}function Rce(e,t){let n=e.columns.filter(e=>e.side===Pl.SIDE1).length,r=e.columns.filter(e=>e.side===Pl.SIDE2).length;return e.columns.map((i,a)=>{let o=i.side===Pl.SIDE1?n>1:i.side===Pl.SIDE2&&r>1;return{id:`__head__${i.key}`,type:`colHeader`,position:t.isH?{x:0,y:a*t.laneExtent}:{x:a*t.laneExtent,y:0},data:{width:t.isH?150:t.laneExtent,height:t.isH?t.laneExtent:null,isH:t.isH,side:i.side,groupIndex:Hl(i.side),sideTitle:e.sideLabels[i.side],colTitle:o?i.actorName:null},...Ul}})}function zce(e,t){let n=e.rows.map(e=>e.index*t.slotExtent+t.slotExtent/2-5);return{id:`__axis__`,type:`axis`,position:t.isH?{x:t.originX,y:t.axisCenter-1}:{x:t.axisCenter-1,y:t.originY},data:{isH:t.isH,length:t.rowCount*t.slotExtent,dotSize:10,dotOffsets:n},...Ul}}function Wl(e,t){return{id:`__links__`,type:`links`,position:{x:0,y:0},width:1,height:1,style:{pointerEvents:`none`},data:{segments:e,isH:t},...Ul}}function Bce(e,t,n,r,i,a){let o=i.cellAt(n,t),s=o.x+(i.cellBoxW-288)/2,c=o.y+(i.cellBoxH-i.cardH)/2,l=null;if(i.isH){let e=s+144;if(t<r.axisColumnIndex){let t=c+i.cardH;l={left:e,top:t,height:i.axisCenter-t}}else t>r.axisColumnIndex&&(l={left:e,top:i.axisCenter,height:c-i.axisCenter})}else{let e=c+i.cardH/2;if(t<r.axisColumnIndex){let t=s+288;l={left:t,top:e,width:i.axisCenter-t}}else t>r.axisColumnIndex&&(l={left:i.axisCenter,top:e,width:s-i.axisCenter})}return{node:{id:e.id,type:`card`,position:{x:s,y:c},data:{...Ice(e,r,n),groupIndex:Hl(r.columns[t].side),cardW:288,cardH:i.cardH,labelLines:i.labelLines,fields:a,isH:i.isH}},link:l}}function Vce(e,t={},n,r=`vertical`){let i=r===`horizontal`,a=Vl(e,n),o=Fce(a,t,i),s=[Lce(o),...Rce(a,o)],c=[],l=[];return a.rows.forEach(e=>{e.cells.forEach((n,r)=>{let i=a.columns.findIndex(e=>e.key===r);if(i<0)return;let{node:s,link:u}=Bce(n,i,e.index,a,o,t);c.push(s),u&&l.push(u)})}),l.length&&s.push(Wl(l,i)),s.push(zce(a,o)),s.push(...c),{errors:a.errors,sideLabels:a.sideLabels,nodes:s,edges:[],grid:a,layout:`grid`,size:{width:o.contentW,height:o.contentH}}}var Gl=12.5,Kl=4,Hce=6,ql=10,Jl=90,Uce={latin:1.2,cjk:1.06},Yl={latin:1.12,cjk:1.06},Xl={sameSlot:10,none:22,short:38,long:70},Zl=864e5,Ql=/^(\d{4})(?:-(\d{2})(?:-(\d{2})(?:T(\d{2})(?::(\d{2})(?::(\d{2}))?)?)?)?)?$/;function $l(e){let t=typeof e==`string`?Ql.exec(e):null;if(!t)return null;let[,n,r,i,a,o,s]=t,c=a==null?i==null?r==null?`year`:`month`:`day`:`time`;return{y:+n,mo:r?+r:1,d:i?+i:1,h:a?+a:0,mi:o?+o:0,s:s?+s:0,prec:c}}var eu={year:0,month:1,day:2,time:3},tu=e=>Date.UTC(e.y,e.mo-1,e.d,e.h,e.mi,e.s);function nu(e,t,n=!1){let r=$l(e),i=$l(t);if(!r||!i)return null;let a=eu[r.prec]<=eu[i.prec]?r.prec:i.prec,o=(e,t,r)=>({key:e,vars:t,long:r,approx:!!n});if(a===`year`||a===`month`){let e=a===`year`?(i.y-r.y)*12:(i.y-r.y)*12+(i.mo-r.mo);return e<=0?null:au(e,o)}if(a===`time`){let e=tu(i)-tu(r);if(e<=0)return null;if(e<Zl){let t=Math.round(e/1e3);if(t<60)return o(`chronicle.gapSeconds`,{n:t},!1);if(t<3600)return o(`chronicle.gapMinutes`,{n:Math.round(t/60)},!1);let n=Math.floor(t/3600),r=Math.round((t-n*3600)/60);return r===60&&(n+=1,r=0),r?o(`chronicle.gapHoursMinutes`,{h:n,m:r},!1):o(`chronicle.gapHours`,{n},!1)}return iu(Math.floor(e/Zl),o)}let s=Math.round((Date.UTC(i.y,i.mo-1,i.d)-Date.UTC(r.y,r.mo-1,r.d))/Zl);return s<=0?null:iu(s,o)}function ru(e){let t=(e,t,n)=>({key:e,vars:t,long:n,approx:!1});if(!(e>0))return null;if(e<Zl){let n=Math.round(e/1e3);return n<60?t(`chronicle.gapSeconds`,{n},!1):n<3600?t(`chronicle.gapMinutes`,{n:Math.round(n/60)},!1):t(`chronicle.gapHours`,{n:Math.round(n/3600)},!1)}return iu(Math.round(e/Zl),t)}function iu(e,t){return e<30?t(`chronicle.gapDays`,{n:e},!1):au(Math.max(1,Math.round(e/30.44)),t)}function au(e,t){let n=Math.floor(e/12),r=e%12;return n?r?t(`chronicle.gapYearsMonths`,{y:n,m:r},!0):t(`chronicle.gapYears`,{n},!0):t(`chronicle.gapMonths`,{n:r},!0)}var ou=(e,t)=>e==null?t:t==null||e>t?e:t;function Wce(e){let t=Array.isArray(e?.slots)?e.slots:[],n=[],r=null,i=!1,a=!1;return t.forEach((e,t)=>{let o=(Array.isArray(e?.events)?e.events:[]).filter(e=>e&&typeof e==`object`);if(!o.length)return;let s=o.every(e=>typeof e.date==`string`&&e.date),c=s?[...o].sort((e,t)=>e.date<t.date?-1:+(e.date>t.date)):o,l=c.find(e=>e.date)?.date??null,u=c.some(e=>e.date&&e.approx);c.forEach((e,o)=>{let c=o===0,d=null,f=`sameSlot`;c&&(n.length?(d=a&&s?nu(r,l,i||u):null,f=d?d.long?`long`:`short`:`none`):f=`top`);let p=typeof e.date==`string`&&e.date.length>=10?e.date.slice(0,10):null,m=n.at(-1)?.event,h=!(!p||!m||typeof m.date!=`string`||m.date.slice(0,10)!==p||e.approx||m.approx);n.push({event:e,slotIndex:t,first:c,gap:d,spacing:f,sameDay:h})}),a=s,r=null;for(let e of c)r=ou(r,ou(e.date,e.dateEnd));i=c.some(e=>e.approx)}),n}var Gce=[`circle`,`square`,`diamond`];function Kce(e,t){let n=(Array.isArray(e?.groups)?e.groups:[]).findIndex(e=>e?.id===t?.groupId);return n<0?`none`:Gce[Math.min(n,2)]}function qce(e,t){let n=(Array.isArray(e?.groups)?e.groups:[]).findIndex(e=>e?.id===t?.groupId);return n>=0&&n<3?n:2}function Jce(e,t,n,r){let i=[];if(n.actors)for(let t of Array.isArray(e.actorIds)?e.actorIds:[])i.push(jl(r.get(t)?.name||t,10)+14);if(n.sources&&i.push(Jl),!i.length)return 0;let a=1,o=0;for(let e of i){let t=o?ql+e:e;o&&o+t>532?(a+=1,o=e):o+=t}return a}function Yce({titleLines:e,summaryLines:t,tagLines:n}){let r=20+20*Math.max(1,e);return t&&(r+=Kl+18*t),n&&(r+=Hce+20*n),Math.max(r,64)}function D(e,t,n){let r=(e,t,r,i)=>n?Nl(e,531,e=>n(e,t)):Ml(e,532/r,i);return{title:Math.max(1,r(e.label||``,`title`,14,Uce)),summary:t.summary&&e.summary?r(e.summary,`summary`,Gl,Yl):0}}function Xce(e,t={},{measure:n}={}){let r=new Map((e?.actors||[]).filter(Boolean).map(e=>[e.id,e])),i=new Map((e?.sources||[]).filter(Boolean).map(e=>[e.id,e])),a=(Array.isArray(e?.groups)?e.groups.slice(0,3):[]).map((e,t)=>({label:e?.label,groupIndex:t,shape:Gce[t]})).filter(e=>e.label),o=Wce(e),s=[],c=[],l=[],u=[],d=a.length?34:0,f=null;o.forEach((a,o)=>{let{event:p}=a;if(f!=null){let e=Xl[a.spacing]??Xl.none;a.gap&&(l.push({y:f+e/2,gap:a.gap}),a.gap.long&&u.push({y0:f,y1:f+e})),d=f+e}let{title:m,summary:h}=D(p,t,typeof n==`function`?n:null),g=Jce(p,e,t,r),_=Yce({titleLines:m,summaryLines:h,tagLines:g}),v=qce(e,p),y=(Array.isArray(p.actorIds)?p.actorIds:[]).map(e=>r.get(e)?.name||e),b=(Array.isArray(p.sourceIds)?p.sourceIds:[]).map(e=>i.get(e)).filter(Boolean);s.push({id:p.id,type:`entry`,position:{x:0,y:d},width:758,height:_,draggable:!1,connectable:!1,data:{event:p,index:o,groupIndex:v,shape:Kce(e,p),actorNames:y,sources:b,fields:t,lines:{title:m,summary:h,tags:g},sameDay:a.sameDay,cardH:_}}),c.push({y:d+20,groupIndex:v,shape:Kce(e,p),hollow:!p.date}),f=d+_});let p=f??0,m=[];return o.length&&m.push({id:`__spine__`,type:`spine`,position:{x:0,y:0},width:1,height:1,draggable:!1,selectable:!1,connectable:!1,focusable:!1,style:{pointerEvents:`none`},data:{x:174,top:c[0].y,bottom:c[c.length-1].y,dots:c,pills:l,breaks:u,dotSize:13}}),a.length&&m.push({id:`__legend__`,type:`legend`,position:{x:198,y:0},width:1,height:1,draggable:!1,selectable:!1,connectable:!1,focusable:!1,data:{groups:a}}),m.push(...s),{errors:[],nodes:m,edges:[],items:o,eventCount:o.length,layout:`chronicle`,size:{width:758,height:p}}}var Zce=12.5,Qce={latin:1.2,cjk:1.06},su=e=>16+17*e+2+15,cu=su(2)+10,lu=10,$ce=22,ele=12,uu=e=>ele+Math.max(1,e)*cu+$ce,du=14,fu=864e5,pu=36e5;function mu(e){let t=$l(e?.date);if(!t)return null;let n=e=>Date.UTC(e.y,e.mo-1,e.d,e.h,e.mi,e.s),r=e=>e.prec===`year`?Date.UTC(e.y+1,0,1):e.prec===`month`?Date.UTC(e.y,e.mo,1):e.prec===`day`?Date.UTC(e.y,e.mo-1,e.d+1):n(e),i=n(t),a=$l(e?.dateEnd);return a&&r(a)>i?{from:i,to:r(a),kind:`bar`,exact:!0}:t.prec===`time`?{from:i,to:i,kind:`dot`,exact:!0}:{from:i,to:r(t),kind:`band`,exact:!1}}var tle=e=>{let t=[...e].sort((e,t)=>e-t),n=Math.floor(t.length/2);return t.length%2?t[n]:(t[n-1]+t[n])/2};function nle(e){let t=e.slice(1).map((t,n)=>t-e[n]),n=[],r=(e,n)=>{let r=[];for(let i=e+n;i>=0&&i<t.length&&r.length<3&&!(t[i]>=t[e]);i+=n)r.push(t[i]);return r};return t.forEach((e,t)=>{if(e<1728e5)return;let i=r(t,1);i.length||(i=r(t,-1)),i.length&&e/Math.max(tle(i),6e4)>=20&&n.push({i:t,g:e})}),n.sort((e,t)=>t.g-e.g).slice(0,2).map(e=>e.i).sort((e,t)=>e-t)}function hu(e){return e>730*fu?`year`:e>60*fu?`month`:e>2*fu?`day`:e>3*pu?`hour`:`minute`}function rle(e,t,n,r){let i=new Date(e),a=[],o={year:[1,2,5,10],month:[1,2,3,6],day:[1,2,7,14],hour:[1,2,3,6,12],minute:[1,2,5,10,15,30]}[n];for(let s of o){a.length=0;let o;o=n===`year`?Date.UTC(i.getUTCFullYear(),0,1):n===`month`?Date.UTC(i.getUTCFullYear(),i.getUTCMonth(),1):n===`day`?Date.UTC(i.getUTCFullYear(),i.getUTCMonth(),i.getUTCDate()):n===`hour`?Date.UTC(i.getUTCFullYear(),i.getUTCMonth(),i.getUTCDate(),i.getUTCHours()):Date.UTC(i.getUTCFullYear(),i.getUTCMonth(),i.getUTCDate(),i.getUTCHours(),i.getUTCMinutes());let c=0;for(;o<=t&&c++<2e3;){o>=e&&a.push(o);let t=new Date(o);n===`year`?o=Date.UTC(t.getUTCFullYear()+s,0,1):n===`month`?o=Date.UTC(t.getUTCFullYear(),t.getUTCMonth()+s,1):o+=n===`day`?s*fu:n===`hour`?s*pu:s*6e4}if(a.length<=r)break}return[...a]}function ile(e,t,n){let r=new Date(e),i=e=>String(e).padStart(2,`0`),a=`${i(r.getUTCMonth()+1)}-${i(r.getUTCDate())}`;if(t===`year`)return String(r.getUTCFullYear());if(t===`month`)return`${r.getUTCFullYear()}-${i(r.getUTCMonth()+1)}`;if(t===`day`)return a;let o=`${i(r.getUTCHours())}:${i(r.getUTCMinutes())}`;return n==null||new Date(n).getUTCDate()!==r.getUTCDate()?`${a} ${o}`:o}function gu(e,t){let n=(Array.isArray(e?.groups)?e.groups.slice(0,3):[]).filter(e=>e&&e.id).map((e,t)=>({key:e.id,label:e.label??``,groupIndex:t})),r=new Set(n.map(e=>e.key));return t.some(e=>!r.has(e.groupId))&&n.push({key:`__other__`,label:null,groupIndex:2,other:!0}),n}function _u(e,{levels:t=3,width:n=196,gap:r=lu}={}){let i=e.map(e=>({ids:[e.id],x:e.x,from:e.x,to:e.x}));for(;;){let e=vu(i,t,n,r);if(e)return e;let a=-1,o=1/0;for(let e=0;e+1<i.length;e++){let t=i[e+1].x-i[e].x;t<o&&(o=t,a=e)}if(a<0)return vu(i,t,n,r)??[];let s=i[a],c=i[a+1],l=[...s.ids,...c.ids],u=Math.min(s.from,c.from),d=Math.max(s.to,c.to);i.splice(a,2,{ids:l,x:(u+d)/2,from:u,to:d}),i=i.sort((e,t)=>e.x-t.x)}}function vu(e,t,n,r){let i=Array(t).fill(-1/0),a=[];for(let t of e){let e=t.x-n/2,o=i.findIndex(t=>t+r<=e);if(o<0)return null;i[o]=t.x+n/2,a.push({...t,level:o})}return a}function ale(e,t={},{measure:n}={}){let r=new Map((e?.actors||[]).filter(Boolean).map(e=>[e.id,e])),i=new Map((e?.sources||[]).filter(Boolean).map(e=>[e.id,e])),a=[];(Array.isArray(e?.slots)?e.slots:[]).forEach((e,t)=>{for(let n of Array.isArray(e?.events)?e.events:[])n&&typeof n==`object`&&a.push({event:n,slotIndex:t})}),a.forEach(e=>e.time=mu(e.event)),a.forEach(e=>{e.time?.exact&&(e.time.t=e.time.from)});let o=e=>({before:a.slice(0,e).reverse().find(e=>e.time?.exact),after:a.slice(e+1).find(e=>e.time?.exact)}),s=a.filter(e=>e.time?.exact).map(e=>e.time.t),c=s.length>1?Math.max(6e4,(Math.max(...s)-Math.min(...s))/20):pu,l=(e,t,n)=>{let{before:r,after:i}=o(e),a;return a=r&&i?(r.time.t+i.time.t)/2:r?r.time.t+c:i?i.time.t-c:t==null?e*pu:(t+n)/2,t==null?a:Math.min(Math.max(a,t),n-1)};a.forEach((e,t)=>{e.time&&!e.time.exact&&(e.time.t=l(t,e.time.from,e.time.to))}),a.forEach((e,t)=>{if(e.time)return;let n=a.slice(0,t).reverse().find(e=>e.time),r=a.slice(t+1).find(e=>e.time),i=n&&r?(n.time.t+r.time.t)/2:n?n.time.t+c:r?r.time.t-c:t*pu;e.time={t:i,from:i,to:i,kind:`dot`,undated:!0}});let u=[...new Set(a.map(e=>e.time.t))].sort((e,t)=>e-t),d=nle(u),f=[],p=0;for(let e of d)f.push([u[p],u[e]]),p=e+1;f.push([u[p],u[u.length-1]]);let m=e=>{let t=f.findIndex(([,t])=>e<=t);return t<0?f.length-1:t},h=f.map(([e,t],n)=>({index:n,from:e,to:t,count:a.filter(e=>m(e.time.t)===n).length,unit:t>e?hu(t-e):`day`})),g=132;h.forEach((e,t)=>{if(t>0){let n=e.from-h[t-1].to;e.breakBefore={x:g,w:64,gap:ru(n)},g+=64}e.x0=g,e.w=Math.max(170,e.count*116),e.x1=g+e.w,g=e.x1});let _=g,v=e=>{let t=h[m(e)],n=t.w-196;return t.to===t.from?t.x0+t.w/2:t.x0+98+(Math.min(Math.max(e,t.from),t.to)-t.from)/(t.to-t.from)*n},y=(e,t)=>Math.min(Math.max(e,h[t].from),h[t].to),b=gu(e,a.map(e=>e.event)),x=e=>{let t=b.findIndex(t=>t.key===e.groupId);return t>=0?t:b.length-1},S=[],C=[],w=e=>S[e],T=e=>S[e]+C[e],ee=a.map((e,t)=>{let n=m(e.time.t),r=e.time.kind,i=v(r===`dot`?e.time.t:y(e.time.from,n)),a=r===`dot`?i:v(y(e.time.to,n)),o=r===`bar`?i:v(e.time.t),s=r===`band`&&a-i<8?`dot`:r;return s===`dot`?i=a=o:a-i<6&&(a=i+6),{id:e.event.id,order:t,lane:x(e.event),kind:s,x:o,x0:i,x1:a,undated:!!e.time.undated,event:e.event}}),te=new Map;for(let e of ee){let t=`${e.lane}:${Math.round(e.x)}`;e.stack=te.get(t)??0,te.set(t,e.stack+1)}let ne=e=>Math.min(2,Math.max(1,n?Nl(e,173,e=>n(e,`title`)):Ml(e,176/Zce,Qce))),re=[],ie=[],ae=b.map((e,t)=>{let n=ee.filter(e=>e.lane===t).sort((e,t)=>e.x-t.x||e.order-t.order),r=e=>Math.min(Math.max(e,234),_-98);return _u(n.map(e=>({id:e.id,x:r(e.x)})))}),oe=0;ae.forEach((e,t)=>{S[t]=oe,C[t]=uu(Math.max(0,...e.map(e=>e.level))+1),oe+=C[t]}),ae.forEach((e,t)=>{let n=e=>{let t=e.ids.map(e=>ee.find(t=>t.id===e).x);return(Math.min(...t)+Math.max(...t))/2};for(let r of e){let e=r.x-98,i=r.ids.map(e=>ee.find(t=>t.id===e)).sort((e,t)=>e.order-t.order),a=i.length>1,o=a?1:ne(i[0].event.label||``),s=su(o),c=T(t)-$ce-r.level*cu,l={id:a?`__run__${ie.length+1}`:i[0].id,lane:t,level:r.level,x:e,y:c-s,w:196,h:s,titleLines:o,anchor:n(r),members:i};a&&(l.run=ie.length+1,l.span=[Math.min(...i.map(e=>e.x0)),Math.max(...i.map(e=>e.x1))],ie.push(l)),re.push(l)}});let se=S.length?S[S.length-1]+C[C.length-1]:0,ce=se+14,le=h.flatMap(e=>{let t=Math.max(2,Math.floor(e.w/84)),n=e.to>e.from?rle(e.from,e.to,e.unit,t):[],r=e.unit;return n.length||(n=e.to>e.from?[e.from,e.to]:[e.from],r=e.to>e.from?`minute`:`day`),n.map((e,t)=>({x:v(e),label:ile(e,r,t?n[t-1]:null)}))}),ue=ie.reduce((e,t)=>e+1+t.members.length,0),de=ie.length?du+ue*18:0,fe=se+56+de,pe=e=>b[x(e)].groupIndex,me=[{id:`__scale__`,type:`scaleLayer`,position:{x:0,y:0},width:1,height:1,draggable:!1,selectable:!1,connectable:!1,focusable:!1,style:{pointerEvents:`none`},data:{width:_,lanesH:se,axisY:ce,lanes:b.map((e,t)=>({...e,top:w(t),lineY:T(t)})),segments:h,ticks:le,marks:ee.map(e=>({id:e.id,kind:e.kind,x:e.x,x0:e.x0,x1:e.x1,y:T(e.lane)-e.stack*12,undated:e.undated,approx:!!e.event.approx,groupIndex:b[e.lane].groupIndex})),leaders:re.map(e=>({x:Math.min(Math.max(e.anchor,e.x+8),e.x+e.w-8),y0:e.y+e.h,y1:T(e.lane)-6,run:!!e.run})),brackets:ie.map(e=>({x0:e.span[0],x1:e.span[1],y:T(e.lane)+9,run:e.run}))}}];for(let e of re)me.push({id:e.id,type:e.run?`scaleRun`:`scaleCard`,position:{x:e.x,y:e.y},width:e.w,height:e.h,draggable:!1,connectable:!1,data:e.run?{run:e.run,events:e.members.map(e=>e.event),groupIndex:b[e.lane].groupIndex,cardH:e.h}:{event:e.members[0].event,undated:e.members[0].undated,groupIndex:pe(e.members[0].event),titleLines:e.titleLines,cardH:e.h,actorNames:(Array.isArray(e.members[0].event.actorIds)?e.members[0].event.actorIds:[]).map(e=>r.get(e)?.name||e),sources:(Array.isArray(e.members[0].event.sourceIds)?e.members[0].event.sourceIds:[]).map(e=>i.get(e)).filter(Boolean)}});return ie.length&&me.push({id:`__runs__`,type:`scaleRunList`,position:{x:132,y:se+56+du},width:1,height:1,draggable:!1,selectable:!1,connectable:!1,focusable:!1,data:{runs:ie.map(e=>({run:e.run,events:e.members.map(e=>e.event)})),width:_-132,lh:18}}),{errors:[],nodes:me,edges:[],layout:`scale`,eventCount:a.length,segments:h,gathered:ie.map(e=>({run:e.run,ids:e.members.map(e=>e.id)})),cards:re.map(e=>({id:e.id,lane:e.lane,level:e.level,x:e.x,y:e.y,w:e.w,h:e.h,ids:e.members.map(e=>e.id)})),undated:ee.filter(e=>e.undated).length,size:{width:_,height:fe}}}function yu(e,t){if(!e||!t||!e.width||!e.height)return 1;let n=t.width/(e.width*1.12),r=t.height/(e.height*1.12);return Math.min(n,r,1)}function ole(e,t){return!e||!t||!e.width?1:Math.min(t.width/(e.width*1.12),1)}var bu=(e,t)=>Math.round(e*Math.min(t,1)*10)/10;function xu(e,t){let n=`Text on one screen (${e.canvas.width}×${e.canvas.height})`,r=bu(e.font,e.open.fit),i=bu(e.font,e.other.fit),a=e=>e.toFixed(1),o=[];e.open.fit>=1&&e.other.fit>=1?o.push(`${n}: full size (${e.font} px) either way.`):o.push(`${n}: ${a(r)} px as it opens (${e.open.name}), ${a(i)} px ${e.other.name}. Full size is ${e.font} px.`);let s=Math.max(r,i);if(s<9?o.push(`Note: the text is too small to read without zooming in (under 9 px). Consider ${t}; do not drop facts to make it fit.`):s<11&&o.push(`Note: the text is small (under 11 px); the reader can zoom in. ${t[0].toUpperCase()}${t.slice(1)} would make it easier to read.`),e.folded!==void 0&&s<11){let t=e.folded>=1?`full size (${e.font} px)`:`${a(bu(e.font,e.folded))} px`;o.push(`With every issue folded the text is ${t}: the reader can fold issues ("Fold issues" in the bar) instead of your splitting it.`)}return o}var Su={envelope:[{name:`type`,req:`yes`,ty:`string`,note:`always "fact"`},El(1),{name:`title`,req:`yes`,ty:`string`,note:`diagram title, shown at the top left`}],actors:[{name:`id`,req:`yes`,ty:`string`,note:`unique within the diagram; events reference it via actorIds`},{name:`name`,req:`yes`,ty:`string`,note:`display name, e.g. "Huayuan Trading"`},{name:`role`,req:`no`,ty:`string`,note:`procedural standing, e.g. "plaintiff"`}],groups:[{name:`id`,req:`yes`,ty:`string`,note:`events reference it via groupId`},{name:`label`,req:`yes`,ty:`string`,note:`column heading, e.g. "performance as agreed"`},{name:``,req:``,ty:``,note:`at most 3: the 1st on the left (top) side, the 2nd on the right (bottom) side, the 3rd on the axis`}],sources:[{name:`id`,req:`yes`,ty:`string`,note:`events reference it via sourceIds`},{name:`type`,req:`yes`,ty:`string`,note:`contract / evidence / judgment / transcript, etc.`},{name:`name`,req:`yes`,ty:`string`,note:`material name, e.g. "corridor surveillance video"`},{name:`loc`,req:`no`,ty:`object`,note:`location, e.g. { file, page } or { file, timestamp }`},{name:`quote`,req:`no`,ty:`string`,note:`verbatim excerpt (several passages joined with ……), shown when the card is opened; a shortened or reworded version goes in detail`}],slots:[{name:`events`,req:`yes`,ty:`array`,note:`events at this time point; must not be empty`},{name:``,req:``,ty:``,note:`array order is chronological order; date is display-only and never reorders`}],events:[{name:`id`,req:`yes`,ty:`string`,note:`unique within the diagram`},{name:`date`,req:`no`,ty:`string`,note:`ISO 8601. Go to seconds when known, otherwise stop at the day. **Leave it out when the material gives no date: never make one up.** The card then says the date is unknown; the order is the order of slots, so nothing moves`},{name:`label`,req:`yes`,ty:`string`,note:`card title; about 20 characters per line, at most two lines`},{name:`dateEnd`,req:`no`,ty:`string`,note:`for a span, the end instant; needs date, and must not be earlier than it`},{name:`approx`,req:`no`,ty:`boolean`,note:`time is not exact (estimated or inferred); the diagram shows "approx."`},{name:`dateNote`,req:`no`,ty:`string`,note:`why the time is not exact, and how it was derived`},{name:`summary`,req:`no`,ty:`string`,note:`the line under the card title; about 22 characters`},{name:`detail`,req:`no`,ty:`string`,note:`full text revealed when the card is opened`},{name:`actorIds`,req:`no`,ty:`string[]`,note:`parties involved. Two or more puts this event on the centre axis`},{name:`groupId`,req:`no`,ty:`string`,note:`which side this event falls on`},{name:`sourceIds`,req:`no`,ty:`string[]`,note:`which materials it rests on`}],views:[{name:`label`,req:`yes`,ty:`string`,note:`view name, shown in the dropdown`},{name:`splitBy`,req:`yes`,ty:`"actor" | "group"`,note:`split the sides by party or by group`},{name:`side1 / side2`,req:`no`,ty:`object`,note:`{ label, actors: [...] }. Required when splitBy=actor`},{name:`axis`,req:`no`,ty:`object`,note:`{ label }. Heading of the centre column`},{name:``,req:``,ty:``,note:`views may be omitted; the engine then provides a single "all" view`}]};function Cu(){let e=[`Fields of a fact spec. "yes" means required.`,``];for(let[t,n]of Object.entries(Su)){e.push(`[${t}]`);for(let t of n){if(!t.name){e.push(` · ${t.note}`);continue}e.push(` ${t.name.padEnd(12)} ${t.req.padEnd(3)} ${t.ty.padEnd(15)} ${t.note}`)}e.push(``)}return e.push(`Cross-field rules (dangling references, a span running backwards, one party on`),e.push(`both sides at once, two events in the same lane of one time slot) are not listed`),e.push(`above: call antu_validate after writing. It reports each problem with its field path.`),e.join(`
1492
+ `}var mce=class{constructor(t=e.stdin,n=e.stdout,r){this._stdin=t,this._stdout=n,this._started=!1,this._ondata=e=>{try{this._readBuffer.append(e),this.processReadBuffer()}catch(e){this.onerror?.(e),this.close().catch(()=>{})}},this._onerror=e=>{this.onerror?.(e)},this._readBuffer=new dce({maxBufferSize:r?.maxBufferSize})}async start(){if(this._started)throw Error(`StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.`);this._started=!0,this._stdin.on(`data`,this._ondata),this._stdin.on(`error`,this._onerror)}processReadBuffer(){for(;;)try{let e=this._readBuffer.readMessage();if(e===null)break;this.onmessage?.(e)}catch(e){this.onerror?.(e)}}async close(){this._stdin.off(`data`,this._ondata),this._stdin.off(`error`,this._onerror),this._stdin.listenerCount(`data`)===0&&this._stdin.pause(),this._readBuffer.clear(),this.onclose?.()}send(e){return new Promise(t=>{let n=pce(e);this._stdout.write(n)?t():this._stdout.once(`drain`,t)})}},_l=`/*ANTU_SPEC*/null`;function vl(e){return String(e).replace(/</g,`\\u003c`)}function hce(e,t,{preset:n}={}){if(e.split(`/*ANTU_SPEC*/null`).length!==2)throw Error(`the viewer template does not hold exactly one ${_l}`);let r=vl(JSON.stringify(t)),i=n?`;window.__ANTU_PRESET__ = ${vl(JSON.stringify(n))}`:``;return e.replace(_l,()=>r+i)}f(u(h(import.meta.url)),`../..`);var yl=f(u(h(import.meta.url)),`..`);d(yl,`dist-engine/engine.js`),d(yl,`dist-engine/engine.css`);function gce(e){return String(e).replace(/[&<>"]/g,e=>({"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`})[e])}function _ce(){return`0.9.1`}function vce(e){return String(e||`antu`).replace(/[\\/:*?"<>|\s]+/g,`-`).slice(0,60)}function yce(e,{outPath:t,preset:r,force:a=!1,quiet:o=!1}={}){let s;{let t=gce(e?.title||`Antu`);s=hce(i(d(yl,`assets/viewer.html`),`utf8`),e,{preset:r}).replace(/<title>[^<]*<\/title>/,()=>`<title>${t} · Antu</title>`)}let l=f(t||`${vce(e?.title)}.html`);return n(u(l),{recursive:!0}),c(l,s),{path:l,bytes:Buffer.byteLength(s)}}var bl=new Map;function xl(e,t){if(!e)throw Error(`registerKnowledge: type must not be empty`);if(!t?.validate)throw Error(`registerKnowledge: validate is required`);if(!t?.describe)throw Error(`registerKnowledge: describe is required (the agent-facing field table)`);if(!Number.isInteger(t.specVersion)||t.specVersion<1)throw Error(`registerKnowledge: specVersion is required, a whole number (the generation of this type's JSON format, core/specVersion.js)`);bl.set(e,t)}function Sl(e){return bl.get(e)}function Cl(){return[...bl.entries()].map(([e,t])=>({type:e,labelKey:t.label??`graphType.${e}`}))}function wl(e){return bl.get(e)?.validate}function bce(e,t){let n=bl.get(e)?.layouts;if(n)return t&&n[t]?n[t]:Object.values(n)[0]}function Tl(e){return Object.keys(bl.get(e)?.layouts??{})}var El=e=>({name:`specVersion`,req:`no`,ty:`integer`,note:`which generation of this format the file follows (now ${e}); omit = the current one. Write it: it is how an older file is recognised after a breaking change`});function xce(e,t){return e.specVersion===void 0?null:!Number.isInteger(e.specVersion)||e.specVersion<1?{key:`err.specVersionForm`,params:{value:JSON.stringify(e.specVersion)}}:Number.isInteger(t)&&e.specVersion>t?{key:`err.specVersionNewer`,params:{value:e.specVersion,known:t,type:e.type}}:null}var Sce=19,Cce=2,wce=18,Dl=6,Tce=16,Ece=11.5,Ol=1,Dce=.55;function kl(e){let t=e.codePointAt(0);return t>=4352&&t<=4447||t>=11904&&t<=42191||t>=44032&&t<=55203||t>=63744&&t<=64255||t>=65072&&t<=65135||t>=65280&&t<=65376||t>=65504&&t<=65510?Ol:Dce}function Al(e){let t=0;for(let n of String(e??``))t+=kl(n);return t}var jl=(e,t)=>Al(e)*t,Oce=262/13;262/Ece;function kce(e={},t=Cce,n=0){let r=22+Sce*t+Dl+Tce;return e.summary&&(r+=24),e.actors&&n>0&&(r+=wce*n+Dl),r}function Ml(e,t,n={}){let r=n.latin??1,i=n.cjk??1;return Nl(e,t,e=>{let t=0;for(let n of e)t+=kl(n)*(kl(n)===Ol?i:r);return t})}function Nl(e,t,n){let r=t,i=n,a=String(e??``);if(!a)return 0;let o=a.match(/[^\sᄀ-ᅟ⺀-꓏가-힣豈-﫿︰-﹯＀-⦆¢-₩]+|\s|./gu)||[],s=1,c=0;for(let e of o){let t=i(e);if(/^\s$/.test(e)){c>0&&(c+=t);continue}if(c+t<=r)c+=t;else if(t<=r)s+=+(c>0),c=t;else{c>0&&(s+=1);let e=Math.ceil(t/r);s+=e-1,c=t-(e-1)*r}}return s}var Pl={SIDE1:`side1`,AXIS:`axis`,SIDE2:`side2`},Fl=3,Ace={label:`all`,splitBy:`group`};function Il(e){let t=Array.isArray(e?.views)?e.views.filter(Bl):[];return t.length>0?t:[Ace]}function Ll(e,t){let n=e?.[t]?.actors;return Array.isArray(n)?[...new Set(n.filter(e=>typeof e==`string`))]:[]}function jce(e,t){return e.splitBy===`actor`?{[Pl.SIDE1]:e?.side1?.label??``,[Pl.SIDE2]:e?.side2?.label??``,[Pl.AXIS]:e?.axis?.label??``}:{[Pl.SIDE1]:t[0]?.label??``,[Pl.SIDE2]:t[1]?.label??``,[Pl.AXIS]:t[2]?.label??``}}var Rl=/^\d{4}(-\d{2}(-\d{2}(T\d{2}(:\d{2}(:\d{2})?)?)?)?)?$/;function Mce(e,t){if(typeof e!=`string`||typeof t!=`string`)return!1;let n=Math.min(e.length,t.length);return e.slice(0,n)<t.slice(0,n)}var zl=[Pl.SIDE1,Pl.SIDE2,Pl.AXIS];function Bl(e){return e&&typeof e==`object`&&!Array.isArray(e)}function Vl(e,t){let n=Bl(t)?t:Il(e)[0],r=n.splitBy===`actor`,i=Ll(n,`side1`),a=Ll(n,`side2`),o=[],s=Array.isArray(e?.actors)?e.actors:[],c=Array.isArray(e?.groups)?e.groups:[],l=Array.isArray(e?.sources)?e.sources:[],u=e?.slots,d={errors:o,view:n,sideLabels:{[Pl.SIDE1]:``,[Pl.SIDE2]:``,[Pl.AXIS]:``},columns:[],rows:[],placements:new Map,axisColumnIndex:0,actorById:new Map,groupById:new Map,groupIndexById:new Map,sourceById:new Map,eventCount:0},f=new Map;s.forEach((e,t)=>{if(!Bl(e)){o.push(se(`err.notObject`,{at:`actors[${t}]`}));return}if(!e.id){o.push(se(`err.required`,{at:`actors[${t}]`,field:`id`}));return}f.has(e.id)&&o.push(se(`err.duplicateId`,{at:`actors[${t}]`,id:e.id})),f.set(e.id,e),e.name||o.push(se(`err.required`,{at:`actors[${t}] (${e.id})`,field:`name`}))}),e?.views!==void 0&&e?.views!==null&&(Array.isArray(e.views)?e.views.forEach((e,t)=>{let n=`views[${t}]`;if(!Bl(e)){o.push(se(`err.notObject`,{at:n}));return}if(e.label||o.push(se(`err.required`,{at:n,field:`label`})),e.splitBy!==`actor`&&e.splitBy!==`group`&&o.push(se(`err.badSplitBy`,{at:n,value:e.splitBy})),e.splitBy===`actor`){let t=Ll(e,`side1`),r=Ll(e,`side2`);[...t,...r].forEach(e=>{f.has(e)||o.push(se(`err.missingRef`,{at:n,field:`side`,kind:`actor`,id:e}))});let i=t.filter(e=>r.includes(e));i.length>0&&o.push(se(`err.bothSides`,{at:n,names:i.join(`, `)}))}}):o.push(se(`err.viewsNotArray`)));let p=new Map,m=new Map;c.length>Fl&&o.push(se(`err.tooManyGroups`,{at:`groups`,max:Fl,actual:c.length})),c.forEach((e,t)=>{if(!Bl(e)){o.push(se(`err.notObject`,{at:`groups[${t}]`}));return}if(!e.id){o.push(se(`err.required`,{at:`groups[${t}]`,field:`id`}));return}m.has(e.id)&&o.push(se(`err.duplicateId`,{at:`groups[${t}]`,id:e.id})),p.set(e.id,e),m.set(e.id,t),e.label||o.push(se(`err.required`,{at:`groups[${t}] (${e.id})`,field:`label`}))});let h=new Map;if(l.forEach((e,t)=>{if(!Bl(e)){o.push(se(`err.notObject`,{at:`sources[${t}]`}));return}if(!e.id){o.push(se(`err.required`,{at:`sources[${t}]`,field:`id`}));return}h.has(e.id)&&o.push(se(`err.duplicateId`,{at:`sources[${t}]`,id:e.id})),h.set(e.id,e),e.type||o.push(se(`err.required`,{at:`sources[${t}] (${e.id})`,field:`type`})),e.name||o.push(se(`err.required`,{at:`sources[${t}] (${e.id})`,field:`name`}))}),!Array.isArray(u))return o.push(se(`err.slotNotArray`)),{...d,actorById:f,groupById:p,groupIndexById:m,sourceById:h};u.length===0&&o.push(se(`err.slotsEmpty`));let g=new Set,_={[Pl.SIDE1]:new Set,[Pl.SIDE2]:new Set},v=[];u.forEach((e,t)=>{let n=`slots[${t}]`;if(!Bl(e)){o.push(se(`err.slotShape`,{at:n}));return}if(!Array.isArray(e.events)){o.push(se(`err.eventsNotArray`,{at:n}));return}e.events.length===0&&o.push(se(`err.slotEventsEmpty`,{at:n})),e.events.forEach((e,s)=>{let c=`${n}.events[${s}]${e?.id?` (${e.id})`:``}`;if(!Bl(e)){o.push(se(`err.notObject`,{at:c}));return}e.id?g.has(e.id)?o.push(se(`err.duplicateId`,{at:c,id:e.id})):g.add(e.id):o.push(se(`err.required`,{at:c,field:`id`})),e.date&&!Rl.test(e.date)&&o.push(se(`err.badDate`,{at:c,field:`date`,value:e.date})),e.label||o.push(se(`err.required`,{at:c,field:`label`})),e.dateEnd!==void 0&&e.dateEnd!==null&&(typeof e.dateEnd!=`string`||!Rl.test(e.dateEnd)?o.push(se(`err.badDate`,{at:c,field:`dateEnd`,value:e.dateEnd})):e.date?Mce(e.dateEnd,e.date)&&o.push(se(`err.dateEndBeforeDate`,{at:c,end:e.dateEnd,start:e.date})):o.push(se(`err.dateEndNeedsDate`,{at:c}))),e.summary!==void 0&&e.summary!==null&&(typeof e.summary==`string`?Al(e.summary)>22.782608695652176&&o.push(se(`err.summaryTooLong`,{at:c,max:22,actual:Math.ceil(Al(e.summary))})):o.push(se(`err.mustBeString`,{at:c,field:`summary`})));let l=Array.isArray(e.actorIds)?e.actorIds:[];l.forEach(e=>{f.has(e)||o.push(se(`err.missingRef`,{at:c,field:`actorIds`,kind:`actor`,id:e}))}),e.groupId&&!m.has(e.groupId)&&o.push(se(`err.missingRef`,{at:c,field:`groupId`,kind:`group`,id:e.groupId})),(Array.isArray(e.sourceIds)?e.sourceIds:[]).forEach(e=>{h.has(e)||o.push(se(`err.missingRef`,{at:c,field:`sourceIds`,kind:`source`,id:e}))});let u=e.groupId?m.get(e.groupId):void 0,d,p=null;if(r){let e=[...i,...a];if(e.length>0&&l.length>0&&!l.some(t=>e.includes(t)))return;l.length===1&&i.includes(l[0])?(d=Pl.SIDE1,p=l[0]):l.length===1&&a.includes(l[0])?(d=Pl.SIDE2,p=l[0]):d=Pl.AXIS}else if(l.length>=2)d=Pl.AXIS,(u===0||u===1)&&o.push(se(`err.multiActorNeedsAxis`,{at:c,n:l.length,groupId:e.groupId}));else if(e.groupId===void 0||e.groupId===null||e.groupId===``)d=Pl.AXIS;else if(u===void 0)return;else d=zl[u]??Pl.AXIS;if(!r&&d!==Pl.AXIS&&l.length!==1){o.push(se(`err.groupNeedsOneActor`,{at:c,groupId:e.groupId,n:l.length}));return}!r&&d!==Pl.AXIS&&l.length===1&&(p=l[0]),p&&f.has(p)&&_[d].add(p),v.push({slotIndex:t,event:e,side:d,actorId:p})})});let y=s.map(e=>Bl(e)?e.id:null).filter(Boolean),b=e=>r?y.filter(t=>Ll(n,e).includes(t)):y.filter(t=>_[e].has(t)),x=[];b(Pl.SIDE1).reverse().forEach(e=>{x.push({key:`${Pl.SIDE1}:${e}`,side:Pl.SIDE1,actorId:e,actorName:f.get(e)?.name})});let S=x.length;x.push({key:Pl.AXIS,side:Pl.AXIS}),b(Pl.SIDE2).forEach(e=>{x.push({key:`${Pl.SIDE2}:${e}`,side:Pl.SIDE2,actorId:e,actorName:f.get(e)?.name})});let C=new Map(x.map((e,t)=>[e.key,t])),w=u.map((e,t)=>({index:t,cells:new Map})),T=new Map,ee=0;return v.forEach(({slotIndex:e,event:t,side:n,actorId:r})=>{let i=n===Pl.AXIS?Pl.AXIS:`${n}:${r}`,a=C.get(i);if(a===void 0)return;ee+=1;let s=w[e];if(s.cells.has(i)){let n=s.cells.get(i);o.push(se(`err.oneEventPerCell`,{at:`slots[${e}]`,a:n.id,b:t.id}))}else s.cells.set(i,t);T.set(t.id,{row:e,col:a,key:i})}),{errors:o,view:n,sideLabels:jce(n,c),columns:x,rows:w,placements:T,axisColumnIndex:S,actorById:f,groupById:p,groupIndexById:m,sourceById:h,eventCount:ee}}function Hl(e){return e===Pl.SIDE1?0:e===Pl.SIDE2?1:2}function Nce(e){let t=1;for(let n of e.rows)n.cells.forEach(e=>{let n=Al(e.label||``);t=Math.max(t,Math.min(2,Math.ceil(n/Oce)))});return t}function Pce(e,t){if(!t.actors)return 0;let n=0;for(let t of e.rows)t.cells.forEach(t=>{let r=(Array.isArray(t.actorIds)?t.actorIds:[]).map(t=>e.actorById.get(t)?.name||t);if(r.length===0)return;let i=r.reduce((e,t)=>e+jl(t,10)+14,0)+4*(r.length-1);n=Math.max(n,Math.ceil(i/262))});return n}function Fce(e,t,n){let r=e.columns.length,i=e.rows.length,a=Nce(e),o=Pce(e,t),s=kce(t,a,o),c=s+28,l=n?316:c,u=n?c:316,d=n?150:0,f=n?0:96;return{isH:n,colCount:r,rowCount:i,labelLines:a,actorLines:o,cardH:s,cellH:c,slotExtent:l,laneExtent:u,originX:d,originY:f,cellBoxW:n?l:u,cellBoxH:n?u:l,cellAt:(e,t)=>n?{x:d+e*l,y:t*u}:{x:t*u,y:f+e*l},axisCenter:e.axisColumnIndex*u+u/2,contentW:n?d+i*l+6:r*u,contentH:n?r*u:f+i*l+6}}var Ul={draggable:!1,selectable:!1,connectable:!1,focusable:!1};function Ice(e,t,n){let r=(Array.isArray(e.actorIds)?e.actorIds:[]).map(e=>t.actorById.get(e)?.name||e),i=(Array.isArray(e.sourceIds)?e.sourceIds:[]).map(e=>t.sourceById.get(e)).filter(Boolean);return{event:e,actorNames:r,sources:i,sourceCount:i.length,row:n}}function Lce(e){return{id:`__cells__`,type:`cells`,position:{x:0,y:0},width:1,height:1,style:{pointerEvents:`none`},data:{cols:e.colCount,rows:e.rowCount,cellW:e.cellBoxW,cellH:e.cellBoxH,originX:e.originX,originY:e.originY,isH:e.isH},...Ul}}function Rce(e,t){let n=e.columns.filter(e=>e.side===Pl.SIDE1).length,r=e.columns.filter(e=>e.side===Pl.SIDE2).length;return e.columns.map((i,a)=>{let o=i.side===Pl.SIDE1?n>1:i.side===Pl.SIDE2&&r>1;return{id:`__head__${i.key}`,type:`colHeader`,position:t.isH?{x:0,y:a*t.laneExtent}:{x:a*t.laneExtent,y:0},data:{width:t.isH?150:t.laneExtent,height:t.isH?t.laneExtent:null,isH:t.isH,side:i.side,groupIndex:Hl(i.side),sideTitle:e.sideLabels[i.side],colTitle:o?i.actorName:null},...Ul}})}function zce(e,t){let n=e.rows.map(e=>e.index*t.slotExtent+t.slotExtent/2-5);return{id:`__axis__`,type:`axis`,position:t.isH?{x:t.originX,y:t.axisCenter-1}:{x:t.axisCenter-1,y:t.originY},data:{isH:t.isH,length:t.rowCount*t.slotExtent,dotSize:10,dotOffsets:n},...Ul}}function Wl(e,t){return{id:`__links__`,type:`links`,position:{x:0,y:0},width:1,height:1,style:{pointerEvents:`none`},data:{segments:e,isH:t},...Ul}}function Bce(e,t,n,r,i,a){let o=i.cellAt(n,t),s=o.x+(i.cellBoxW-288)/2,c=o.y+(i.cellBoxH-i.cardH)/2,l=null;if(i.isH){let e=s+144;if(t<r.axisColumnIndex){let t=c+i.cardH;l={left:e,top:t,height:i.axisCenter-t}}else t>r.axisColumnIndex&&(l={left:e,top:i.axisCenter,height:c-i.axisCenter})}else{let e=c+i.cardH/2;if(t<r.axisColumnIndex){let t=s+288;l={left:t,top:e,width:i.axisCenter-t}}else t>r.axisColumnIndex&&(l={left:i.axisCenter,top:e,width:s-i.axisCenter})}return{node:{id:e.id,type:`card`,position:{x:s,y:c},data:{...Ice(e,r,n),groupIndex:Hl(r.columns[t].side),cardW:288,cardH:i.cardH,labelLines:i.labelLines,fields:a,isH:i.isH}},link:l}}function Vce(e,t={},n,r=`vertical`){let i=r===`horizontal`,a=Vl(e,n),o=Fce(a,t,i),s=[Lce(o),...Rce(a,o)],c=[],l=[];return a.rows.forEach(e=>{e.cells.forEach((n,r)=>{let i=a.columns.findIndex(e=>e.key===r);if(i<0)return;let{node:s,link:u}=Bce(n,i,e.index,a,o,t);c.push(s),u&&l.push(u)})}),l.length&&s.push(Wl(l,i)),s.push(zce(a,o)),s.push(...c),{errors:a.errors,sideLabels:a.sideLabels,nodes:s,edges:[],grid:a,layout:`grid`,size:{width:o.contentW,height:o.contentH}}}var Gl=12.5,Kl=4,Hce=6,ql=10,Jl=90,Uce={latin:1.2,cjk:1.06},Yl={latin:1.12,cjk:1.06},Xl={sameSlot:10,none:22,short:38,long:70},Zl=864e5,Ql=/^(\d{4})(?:-(\d{2})(?:-(\d{2})(?:T(\d{2})(?::(\d{2})(?::(\d{2}))?)?)?)?)?$/;function $l(e){let t=typeof e==`string`?Ql.exec(e):null;if(!t)return null;let[,n,r,i,a,o,s]=t,c=a==null?i==null?r==null?`year`:`month`:`day`:`time`;return{y:+n,mo:r?+r:1,d:i?+i:1,h:a?+a:0,mi:o?+o:0,s:s?+s:0,prec:c}}var eu={year:0,month:1,day:2,time:3},tu=e=>Date.UTC(e.y,e.mo-1,e.d,e.h,e.mi,e.s);function nu(e,t,n=!1){let r=$l(e),i=$l(t);if(!r||!i)return null;let a=eu[r.prec]<=eu[i.prec]?r.prec:i.prec,o=(e,t,r)=>({key:e,vars:t,long:r,approx:!!n});if(a===`year`||a===`month`){let e=a===`year`?(i.y-r.y)*12:(i.y-r.y)*12+(i.mo-r.mo);return e<=0?null:au(e,o)}if(a===`time`){let e=tu(i)-tu(r);if(e<=0)return null;if(e<Zl){let t=Math.round(e/1e3);if(t<60)return o(`chronicle.gapSeconds`,{n:t},!1);if(t<3600)return o(`chronicle.gapMinutes`,{n:Math.round(t/60)},!1);let n=Math.floor(t/3600),r=Math.round((t-n*3600)/60);return r===60&&(n+=1,r=0),r?o(`chronicle.gapHoursMinutes`,{h:n,m:r},!1):o(`chronicle.gapHours`,{n},!1)}return iu(Math.floor(e/Zl),o)}let s=Math.round((Date.UTC(i.y,i.mo-1,i.d)-Date.UTC(r.y,r.mo-1,r.d))/Zl);return s<=0?null:iu(s,o)}function ru(e){let t=(e,t,n)=>({key:e,vars:t,long:n,approx:!1});if(!(e>0))return null;if(e<Zl){let n=Math.round(e/1e3);return n<60?t(`chronicle.gapSeconds`,{n},!1):n<3600?t(`chronicle.gapMinutes`,{n:Math.round(n/60)},!1):t(`chronicle.gapHours`,{n:Math.round(n/3600)},!1)}return iu(Math.round(e/Zl),t)}function iu(e,t){return e<30?t(`chronicle.gapDays`,{n:e},!1):au(Math.max(1,Math.round(e/30.44)),t)}function au(e,t){let n=Math.floor(e/12),r=e%12;return n?r?t(`chronicle.gapYearsMonths`,{y:n,m:r},!0):t(`chronicle.gapYears`,{n},!0):t(`chronicle.gapMonths`,{n:r},!0)}var ou=(e,t)=>e==null?t:t==null||e>t?e:t;function Wce(e){let t=Array.isArray(e?.slots)?e.slots:[],n=[],r=null,i=!1,a=!1;return t.forEach((e,t)=>{let o=(Array.isArray(e?.events)?e.events:[]).filter(e=>e&&typeof e==`object`);if(!o.length)return;let s=o.every(e=>typeof e.date==`string`&&e.date),c=s?[...o].sort((e,t)=>e.date<t.date?-1:+(e.date>t.date)):o,l=c.find(e=>e.date)?.date??null,u=c.some(e=>e.date&&e.approx);c.forEach((e,o)=>{let c=o===0,d=null,f=`sameSlot`;c&&(n.length?(d=a&&s?nu(r,l,i||u):null,f=d?d.long?`long`:`short`:`none`):f=`top`);let p=typeof e.date==`string`&&e.date.length>=10?e.date.slice(0,10):null,m=n.at(-1)?.event,h=!(!p||!m||typeof m.date!=`string`||m.date.slice(0,10)!==p||e.approx||m.approx);n.push({event:e,slotIndex:t,first:c,gap:d,spacing:f,sameDay:h})}),a=s,r=null;for(let e of c)r=ou(r,ou(e.date,e.dateEnd));i=c.some(e=>e.approx)}),n}var Gce=[`circle`,`square`,`diamond`];function Kce(e,t){let n=(Array.isArray(e?.groups)?e.groups:[]).findIndex(e=>e?.id===t?.groupId);return n<0?`none`:Gce[Math.min(n,2)]}function qce(e,t){let n=(Array.isArray(e?.groups)?e.groups:[]).findIndex(e=>e?.id===t?.groupId);return n>=0&&n<3?n:2}function Jce(e,t,n,r){let i=[];if(n.actors)for(let t of Array.isArray(e.actorIds)?e.actorIds:[])i.push(jl(r.get(t)?.name||t,10)+14);if(n.sources&&i.push(Jl),!i.length)return 0;let a=1,o=0;for(let e of i){let t=o?ql+e:e;o&&o+t>532?(a+=1,o=e):o+=t}return a}function Yce({titleLines:e,summaryLines:t,tagLines:n}){let r=20+20*Math.max(1,e);return t&&(r+=Kl+18*t),n&&(r+=Hce+20*n),Math.max(r,64)}function D(e,t,n){let r=(e,t,r,i)=>n?Nl(e,531,e=>n(e,t)):Ml(e,532/r,i);return{title:Math.max(1,r(e.label||``,`title`,14,Uce)),summary:t.summary&&e.summary?r(e.summary,`summary`,Gl,Yl):0}}function Xce(e,t={},{measure:n}={}){let r=new Map((e?.actors||[]).filter(Boolean).map(e=>[e.id,e])),i=new Map((e?.sources||[]).filter(Boolean).map(e=>[e.id,e])),a=(Array.isArray(e?.groups)?e.groups.slice(0,3):[]).map((e,t)=>({label:e?.label,groupIndex:t,shape:Gce[t]})).filter(e=>e.label),o=Wce(e),s=[],c=[],l=[],u=[],d=a.length?34:0,f=null;o.forEach((a,o)=>{let{event:p}=a;if(f!=null){let e=Xl[a.spacing]??Xl.none;a.gap&&(l.push({y:f+e/2,gap:a.gap}),a.gap.long&&u.push({y0:f,y1:f+e})),d=f+e}let{title:m,summary:h}=D(p,t,typeof n==`function`?n:null),g=Jce(p,e,t,r),_=Yce({titleLines:m,summaryLines:h,tagLines:g}),v=qce(e,p),y=(Array.isArray(p.actorIds)?p.actorIds:[]).map(e=>r.get(e)?.name||e),b=(Array.isArray(p.sourceIds)?p.sourceIds:[]).map(e=>i.get(e)).filter(Boolean);s.push({id:p.id,type:`entry`,position:{x:0,y:d},width:758,height:_,draggable:!1,connectable:!1,data:{event:p,index:o,groupIndex:v,shape:Kce(e,p),actorNames:y,sources:b,fields:t,lines:{title:m,summary:h,tags:g},sameDay:a.sameDay,cardH:_}}),c.push({y:d+20,groupIndex:v,shape:Kce(e,p),hollow:!p.date}),f=d+_});let p=f??0,m=[];return o.length&&m.push({id:`__spine__`,type:`spine`,position:{x:0,y:0},width:1,height:1,draggable:!1,selectable:!1,connectable:!1,focusable:!1,style:{pointerEvents:`none`},data:{x:174,top:c[0].y,bottom:c[c.length-1].y,dots:c,pills:l,breaks:u,dotSize:13}}),a.length&&m.push({id:`__legend__`,type:`legend`,position:{x:198,y:0},width:1,height:1,draggable:!1,selectable:!1,connectable:!1,focusable:!1,data:{groups:a}}),m.push(...s),{errors:[],nodes:m,edges:[],items:o,eventCount:o.length,layout:`chronicle`,size:{width:758,height:p}}}var Zce=12.5,Qce={latin:1.2,cjk:1.06},su=e=>16+17*e+2+15,cu=su(2)+10,lu=10,$ce=22,ele=12,uu=e=>ele+Math.max(1,e)*cu+$ce,du=14,fu=864e5,pu=36e5;function mu(e){let t=$l(e?.date);if(!t)return null;let n=e=>Date.UTC(e.y,e.mo-1,e.d,e.h,e.mi,e.s),r=e=>e.prec===`year`?Date.UTC(e.y+1,0,1):e.prec===`month`?Date.UTC(e.y,e.mo,1):e.prec===`day`?Date.UTC(e.y,e.mo-1,e.d+1):n(e),i=n(t),a=$l(e?.dateEnd);return a&&r(a)>i?{from:i,to:r(a),kind:`bar`,exact:!0}:t.prec===`time`?{from:i,to:i,kind:`dot`,exact:!0}:{from:i,to:r(t),kind:`band`,exact:!1}}var tle=e=>{let t=[...e].sort((e,t)=>e-t),n=Math.floor(t.length/2);return t.length%2?t[n]:(t[n-1]+t[n])/2};function nle(e){let t=e.slice(1).map((t,n)=>t-e[n]),n=[],r=(e,n)=>{let r=[];for(let i=e+n;i>=0&&i<t.length&&r.length<3&&!(t[i]>=t[e]);i+=n)r.push(t[i]);return r};return t.forEach((e,t)=>{if(e<1728e5)return;let i=r(t,1);i.length||(i=r(t,-1)),i.length&&e/Math.max(tle(i),6e4)>=20&&n.push({i:t,g:e})}),n.sort((e,t)=>t.g-e.g).slice(0,2).map(e=>e.i).sort((e,t)=>e-t)}function hu(e){return e>730*fu?`year`:e>60*fu?`month`:e>2*fu?`day`:e>3*pu?`hour`:`minute`}function rle(e,t,n,r){let i=new Date(e),a=[],o={year:[1,2,5,10],month:[1,2,3,6],day:[1,2,7,14],hour:[1,2,3,6,12],minute:[1,2,5,10,15,30]}[n];for(let s of o){a.length=0;let o;o=n===`year`?Date.UTC(i.getUTCFullYear(),0,1):n===`month`?Date.UTC(i.getUTCFullYear(),i.getUTCMonth(),1):n===`day`?Date.UTC(i.getUTCFullYear(),i.getUTCMonth(),i.getUTCDate()):n===`hour`?Date.UTC(i.getUTCFullYear(),i.getUTCMonth(),i.getUTCDate(),i.getUTCHours()):Date.UTC(i.getUTCFullYear(),i.getUTCMonth(),i.getUTCDate(),i.getUTCHours(),i.getUTCMinutes());let c=0;for(;o<=t&&c++<2e3;){o>=e&&a.push(o);let t=new Date(o);n===`year`?o=Date.UTC(t.getUTCFullYear()+s,0,1):n===`month`?o=Date.UTC(t.getUTCFullYear(),t.getUTCMonth()+s,1):o+=n===`day`?s*fu:n===`hour`?s*pu:s*6e4}if(a.length<=r)break}return[...a]}function ile(e,t,n){let r=new Date(e),i=e=>String(e).padStart(2,`0`),a=`${i(r.getUTCMonth()+1)}-${i(r.getUTCDate())}`;if(t===`year`)return String(r.getUTCFullYear());if(t===`month`)return`${r.getUTCFullYear()}-${i(r.getUTCMonth()+1)}`;if(t===`day`)return a;let o=`${i(r.getUTCHours())}:${i(r.getUTCMinutes())}`;return n==null||new Date(n).getUTCDate()!==r.getUTCDate()?`${a} ${o}`:o}function gu(e,t){let n=(Array.isArray(e?.groups)?e.groups.slice(0,3):[]).filter(e=>e&&e.id).map((e,t)=>({key:e.id,label:e.label??``,groupIndex:t})),r=new Set(n.map(e=>e.key));return t.some(e=>!r.has(e.groupId))&&n.push({key:`__other__`,label:null,groupIndex:2,other:!0}),n}function _u(e,{levels:t=3,width:n=196,gap:r=lu}={}){let i=e.map(e=>({ids:[e.id],x:e.x,from:e.x,to:e.x}));for(;;){let e=vu(i,t,n,r);if(e)return e;let a=-1,o=1/0;for(let e=0;e+1<i.length;e++){let t=i[e+1].x-i[e].x;t<o&&(o=t,a=e)}if(a<0)return vu(i,t,n,r)??[];let s=i[a],c=i[a+1],l=[...s.ids,...c.ids],u=Math.min(s.from,c.from),d=Math.max(s.to,c.to);i.splice(a,2,{ids:l,x:(u+d)/2,from:u,to:d}),i=i.sort((e,t)=>e.x-t.x)}}function vu(e,t,n,r){let i=Array(t).fill(-1/0),a=[];for(let t of e){let e=t.x-n/2,o=i.findIndex(t=>t+r<=e);if(o<0)return null;i[o]=t.x+n/2,a.push({...t,level:o})}return a}function ale(e,t={},{measure:n}={}){let r=new Map((e?.actors||[]).filter(Boolean).map(e=>[e.id,e])),i=new Map((e?.sources||[]).filter(Boolean).map(e=>[e.id,e])),a=[];(Array.isArray(e?.slots)?e.slots:[]).forEach((e,t)=>{for(let n of Array.isArray(e?.events)?e.events:[])n&&typeof n==`object`&&a.push({event:n,slotIndex:t})}),a.forEach(e=>e.time=mu(e.event)),a.forEach(e=>{e.time?.exact&&(e.time.t=e.time.from)});let o=e=>({before:a.slice(0,e).reverse().find(e=>e.time?.exact),after:a.slice(e+1).find(e=>e.time?.exact)}),s=a.filter(e=>e.time?.exact).map(e=>e.time.t),c=s.length>1?Math.max(6e4,(Math.max(...s)-Math.min(...s))/20):pu,l=(e,t,n)=>{let{before:r,after:i}=o(e),a;return a=r&&i?(r.time.t+i.time.t)/2:r?r.time.t+c:i?i.time.t-c:t==null?e*pu:(t+n)/2,t==null?a:Math.min(Math.max(a,t),n-1)};a.forEach((e,t)=>{e.time&&!e.time.exact&&(e.time.t=l(t,e.time.from,e.time.to))}),a.forEach((e,t)=>{if(e.time)return;let n=a.slice(0,t).reverse().find(e=>e.time),r=a.slice(t+1).find(e=>e.time),i=n&&r?(n.time.t+r.time.t)/2:n?n.time.t+c:r?r.time.t-c:t*pu;e.time={t:i,from:i,to:i,kind:`dot`,undated:!0}});let u=[...new Set(a.map(e=>e.time.t))].sort((e,t)=>e-t),d=nle(u),f=[],p=0;for(let e of d)f.push([u[p],u[e]]),p=e+1;f.push([u[p],u[u.length-1]]);let m=e=>{let t=f.findIndex(([,t])=>e<=t);return t<0?f.length-1:t},h=f.map(([e,t],n)=>({index:n,from:e,to:t,count:a.filter(e=>m(e.time.t)===n).length,unit:t>e?hu(t-e):`day`})),g=132;h.forEach((e,t)=>{if(t>0){let n=e.from-h[t-1].to;e.breakBefore={x:g,w:64,gap:ru(n)},g+=64}e.x0=g,e.w=Math.max(170,e.count*116),e.x1=g+e.w,g=e.x1});let _=g,v=e=>{let t=h[m(e)],n=t.w-196;return t.to===t.from?t.x0+t.w/2:t.x0+98+(Math.min(Math.max(e,t.from),t.to)-t.from)/(t.to-t.from)*n},y=(e,t)=>Math.min(Math.max(e,h[t].from),h[t].to),b=gu(e,a.map(e=>e.event)),x=e=>{let t=b.findIndex(t=>t.key===e.groupId);return t>=0?t:b.length-1},S=[],C=[],w=e=>S[e],T=e=>S[e]+C[e],ee=a.map((e,t)=>{let n=m(e.time.t),r=e.time.kind,i=v(r===`dot`?e.time.t:y(e.time.from,n)),a=r===`dot`?i:v(y(e.time.to,n)),o=r===`bar`?i:v(e.time.t),s=r===`band`&&a-i<8?`dot`:r;return s===`dot`?i=a=o:a-i<6&&(a=i+6),{id:e.event.id,order:t,lane:x(e.event),kind:s,x:o,x0:i,x1:a,undated:!!e.time.undated,event:e.event}}),te=new Map;for(let e of ee){let t=`${e.lane}:${Math.round(e.x)}`;e.stack=te.get(t)??0,te.set(t,e.stack+1)}let ne=e=>Math.min(2,Math.max(1,n?Nl(e,173,e=>n(e,`title`)):Ml(e,176/Zce,Qce))),re=[],ie=[],ae=b.map((e,t)=>{let n=ee.filter(e=>e.lane===t).sort((e,t)=>e.x-t.x||e.order-t.order),r=e=>Math.min(Math.max(e,234),_-98);return _u(n.map(e=>({id:e.id,x:r(e.x)})))}),oe=0;ae.forEach((e,t)=>{S[t]=oe,C[t]=uu(Math.max(0,...e.map(e=>e.level))+1),oe+=C[t]}),ae.forEach((e,t)=>{let n=e=>{let t=e.ids.map(e=>ee.find(t=>t.id===e).x);return(Math.min(...t)+Math.max(...t))/2};for(let r of e){let e=r.x-98,i=r.ids.map(e=>ee.find(t=>t.id===e)).sort((e,t)=>e.order-t.order),a=i.length>1,o=a?1:ne(i[0].event.label||``),s=su(o),c=T(t)-$ce-r.level*cu,l={id:a?`__run__${ie.length+1}`:i[0].id,lane:t,level:r.level,x:e,y:c-s,w:196,h:s,titleLines:o,anchor:n(r),members:i};a&&(l.run=ie.length+1,l.span=[Math.min(...i.map(e=>e.x0)),Math.max(...i.map(e=>e.x1))],ie.push(l)),re.push(l)}});let se=S.length?S[S.length-1]+C[C.length-1]:0,ce=se+14,le=h.flatMap(e=>{let t=Math.max(2,Math.floor(e.w/84)),n=e.to>e.from?rle(e.from,e.to,e.unit,t):[],r=e.unit;return n.length||(n=e.to>e.from?[e.from,e.to]:[e.from],r=e.to>e.from?`minute`:`day`),n.map((e,t)=>({x:v(e),label:ile(e,r,t?n[t-1]:null)}))}),ue=ie.reduce((e,t)=>e+1+t.members.length,0),de=ie.length?du+ue*18:0,fe=se+56+de,pe=e=>b[x(e)].groupIndex,me=[{id:`__scale__`,type:`scaleLayer`,position:{x:0,y:0},width:1,height:1,draggable:!1,selectable:!1,connectable:!1,focusable:!1,style:{pointerEvents:`none`},data:{width:_,lanesH:se,axisY:ce,lanes:b.map((e,t)=>({...e,top:w(t),lineY:T(t)})),segments:h,ticks:le,marks:ee.map(e=>({id:e.id,kind:e.kind,x:e.x,x0:e.x0,x1:e.x1,y:T(e.lane)-e.stack*12,undated:e.undated,approx:!!e.event.approx,groupIndex:b[e.lane].groupIndex})),leaders:re.map(e=>({x:Math.min(Math.max(e.anchor,e.x+8),e.x+e.w-8),y0:e.y+e.h,y1:T(e.lane)-6,run:!!e.run})),brackets:ie.map(e=>({x0:e.span[0],x1:e.span[1],y:T(e.lane)+9,run:e.run}))}}];for(let e of re)me.push({id:e.id,type:e.run?`scaleRun`:`scaleCard`,position:{x:e.x,y:e.y},width:e.w,height:e.h,draggable:!1,connectable:!1,data:e.run?{run:e.run,events:e.members.map(e=>e.event),groupIndex:b[e.lane].groupIndex,cardH:e.h}:{event:e.members[0].event,undated:e.members[0].undated,groupIndex:pe(e.members[0].event),titleLines:e.titleLines,cardH:e.h,actorNames:(Array.isArray(e.members[0].event.actorIds)?e.members[0].event.actorIds:[]).map(e=>r.get(e)?.name||e),sources:(Array.isArray(e.members[0].event.sourceIds)?e.members[0].event.sourceIds:[]).map(e=>i.get(e)).filter(Boolean)}});return ie.length&&me.push({id:`__runs__`,type:`scaleRunList`,position:{x:132,y:se+56+du},width:1,height:1,draggable:!1,selectable:!1,connectable:!1,focusable:!1,data:{runs:ie.map(e=>({run:e.run,events:e.members.map(e=>e.event)})),width:_-132,lh:18}}),{errors:[],nodes:me,edges:[],layout:`scale`,eventCount:a.length,segments:h,gathered:ie.map(e=>({run:e.run,ids:e.members.map(e=>e.id)})),cards:re.map(e=>({id:e.id,lane:e.lane,level:e.level,x:e.x,y:e.y,w:e.w,h:e.h,ids:e.members.map(e=>e.id)})),undated:ee.filter(e=>e.undated).length,size:{width:_,height:fe}}}function yu(e,t){if(!e||!t||!e.width||!e.height)return 1;let n=t.width/(e.width*1.12),r=t.height/(e.height*1.12);return Math.min(n,r,1)}function ole(e,t){return!e||!t||!e.width?1:Math.min(t.width/(e.width*1.12),1)}var bu=(e,t)=>Math.round(e*Math.min(t,1)*10)/10;function xu(e,t){let n=`Text on one screen (${e.canvas.width}×${e.canvas.height})`,r=bu(e.font,e.open.fit),i=bu(e.font,e.other.fit),a=e=>e.toFixed(1),o=[];e.open.fit>=1&&e.other.fit>=1?o.push(`${n}: full size (${e.font} px) either way.`):o.push(`${n}: ${a(r)} px as it opens (${e.open.name}), ${a(i)} px ${e.other.name}. Full size is ${e.font} px.`);let s=Math.max(r,i);if(s<9?o.push(`Note: the text is too small to read without zooming in (under 9 px). Consider ${t}; do not drop facts to make it fit.`):s<11&&o.push(`Note: the text is small (under 11 px); the reader can zoom in. ${t[0].toUpperCase()}${t.slice(1)} would make it easier to read.`),e.folded!==void 0&&s<11){let t=e.folded>=1?`full size (${e.font} px)`:`${a(bu(e.font,e.folded))} px`;o.push(`With every issue folded the text is ${t}: the reader can fold issues ("Fold issues" in the bar) instead of your splitting it.`)}return o}var Su={envelope:[{name:`type`,req:`yes`,ty:`string`,note:`always "fact"`},El(1),{name:`title`,req:`yes`,ty:`string`,note:`diagram title, shown at the top left`}],actors:[{name:`id`,req:`yes`,ty:`string`,note:`unique within the diagram; events reference it via actorIds`},{name:`name`,req:`yes`,ty:`string`,note:`display name, e.g. "Huayuan Trading"`},{name:`role`,req:`no`,ty:`string`,note:`procedural standing, e.g. "plaintiff"`}],groups:[{name:`id`,req:`yes`,ty:`string`,note:`events reference it via groupId`},{name:`label`,req:`yes`,ty:`string`,note:`column heading, e.g. "performance as agreed"`},{name:``,req:``,ty:``,note:`at most 3: the 1st on the left (top) side, the 2nd on the right (bottom) side, the 3rd on the axis`}],sources:[{name:`id`,req:`yes`,ty:`string`,note:`events reference it via sourceIds`},{name:`type`,req:`yes`,ty:`string`,note:`contract / evidence / judgment / transcript, etc.`},{name:`name`,req:`yes`,ty:`string`,note:`material name, e.g. "corridor surveillance video"`},{name:`loc`,req:`no`,ty:`object`,note:`location, e.g. { file, page } or { file, timestamp }`},{name:`quote`,req:`no`,ty:`string`,note:`verbatim excerpt (several passages joined with ……), shown when the card is opened; a shortened or reworded version goes in detail`}],slots:[{name:`events`,req:`yes`,ty:`array`,note:`events at this time point; must not be empty`},{name:``,req:``,ty:``,note:`array order is chronological order; date is display-only and never reorders`}],events:[{name:`id`,req:`yes`,ty:`string`,note:`unique within the diagram`},{name:`date`,req:`no`,ty:`string`,note:`ISO 8601. Go to seconds when known, otherwise stop at the day. **Leave it out when the material gives no date: never make one up.** The card then says the date is unknown; the order is the order of slots, so nothing moves`},{name:`label`,req:`yes`,ty:`string`,note:`card title; about 20 characters per line, at most two lines`},{name:`dateEnd`,req:`no`,ty:`string`,note:`for a span, the end instant; needs date, and must not be earlier than it`},{name:`approx`,req:`no`,ty:`boolean`,note:`time is not exact (estimated or inferred); the diagram shows "approx."`},{name:`dateNote`,req:`no`,ty:`string`,note:`why the time is not exact, and how it was derived`},{name:`summary`,req:`no`,ty:`string`,note:`the line under the card title; about 22 characters`},{name:`detail`,req:`no`,ty:`string`,note:`full text revealed when the card is opened`},{name:`actorIds`,req:`no`,ty:`string[]`,note:`parties involved. Two or more puts this event on the centre axis`},{name:`groupId`,req:`no`,ty:`string`,note:`which side this event falls on`},{name:`sourceIds`,req:`no`,ty:`string[]`,note:`which materials it rests on`}],views:[{name:`label`,req:`yes`,ty:`string`,note:`view name, shown in the dropdown`},{name:`splitBy`,req:`yes`,ty:`"actor" | "group"`,note:`split the sides by party or by group`},{name:`side1 / side2`,req:`no`,ty:`object`,note:`{ label, actors: [...] }. Required when splitBy=actor`},{name:`axis`,req:`no`,ty:`object`,note:`{ label }. Heading of the centre column`},{name:``,req:``,ty:``,note:`views may be omitted; the engine then provides a single "all" view`}]};function Cu(){let e=[`Fields of a fact spec. "yes" means required.`,``];for(let[t,n]of Object.entries(Su)){e.push(`[${t}]`);for(let t of n){if(!t.name){e.push(` · ${t.note}`);continue}e.push(` ${t.name.padEnd(12)} ${t.req.padEnd(3)} ${t.ty.padEnd(15)} ${t.note}`)}e.push(``)}return e.push(`Cross-field rules (dangling references, a span running backwards, one party on`),e.push(`both sides at once, two events in the same lane of one time slot) are not listed`),e.push(`above: call antu_validate after writing. It reports each problem with its field path.`),e.join(`
1493
1493
  `)}function wu(e,t,{fields:n,canvas:r}){let i=t(e,n),a=Number(ole(i.size,r).toFixed(3)),o=Number(yu(i.size,r).toFixed(3)),s=Math.max(1,Math.round(i.size.height*a/r.height*10)/10),c=i.items.filter(e=>e.gap);return{text:{font:14,canvas:r,open:{name:`fitted to width`,fit:a},other:{name:`whole column`,fit:o}},counts:{slots:Array.isArray(e.slots)?e.slots.length:0,events:i.items.length,actors:e.actors?.length??0,sources:e.sources?.length??0},size:i.size,screens:s,gaps:{short:c.filter(e=>!e.gap.long).length,long:c.filter(e=>e.gap.long).length},undated:i.items.filter(e=>!e.event.date).length}}function sle(e){let t=[];return t.push(`Kind: chronicle (every event in one column, in slot order; views and orientation do not apply)`),t.push(`Data: ${e.counts.events} events / ${e.counts.slots} time slots / ${e.counts.actors} parties / ${e.counts.sources} sources`),t.push(`Content ${e.size.width}×${e.size.height}; it opens fitted to its width, about ${e.screens} screen(s) tall`),t.push(`Gaps written between time points: ${e.gaps.short} short, ${e.gaps.long} of 30 days or more (marked)`),e.undated&&t.push(`${e.undated} event(s) without a date: shown in slot order with a hollow dot, and no gap on either side`),t.push(...xu(e.text,`splitting the case into periods, one diagram each`)),t.join(`
1494
1494
  `)}function Tu(e,t,{canvas:n}){let r=t(e,{}),i=Number(yu(r.size,n).toFixed(3));return{text:{font:Zce,canvas:n,open:{name:`fitted whole`,fit:i},other:{name:`fitted whole`,fit:i}},counts:{events:r.eventCount,actors:e.actors?.length??0,sources:e.sources?.length??0},size:r.size,segments:r.segments.map(e=>({unit:e.unit,count:e.count})),gathered:r.gathered.map(e=>e.ids.length),undated:r.undated}}function cle(e){let t=[];return t.push(`Kind: scale (distance on the axis is real time; views and orientation do not apply)`),t.push(`Data: ${e.counts.events} events / ${e.counts.actors} parties / ${e.counts.sources} sources`),t.push(`Content ${e.size.width}×${e.size.height}`),t.push(e.segments.length>1?`The axis breaks into ${e.segments.length} segments: ${e.segments.map((e,t)=>`${t+1}. by ${e.unit}, ${e.count} event(s)`).join(`; `)}`:`One segment, by ${e.segments[0]?.unit??`day`}`),e.gathered.length&&t.push(`${e.gathered.length} run(s) of events too close to show one by one are gathered (${e.gathered.join(`, `)} events); they are listed in full under the diagram`),e.undated&&t.push(`${e.undated} event(s) without a date: placed between their neighbours in data order, with a hollow dot`),t.push(...xu(e.text,`splitting the case into periods, one diagram each`)),t.join(`
1495
1495
  `)}var Eu={specVersion:1,label:`graphType.fact`,fields:Su,describe:Cu,validate:e=>Vl(e).errors,notes:e=>Il(e).map(t=>({label:t.label,reason:Vl(e,t).errors[0]})).filter(e=>e.reason).map(e=>se(`note.viewBlocked`,e)),info:(e,t,n)=>{let r=Array.isArray(e.slots)?e.slots:[],i=r.flatMap(e=>(e?.events||[]).map(e=>e?.date)).filter(e=>typeof e==`string`&&e).sort(),a=t(`info.slots`,{n:n(r.length)});if(i.length>0){let e=i[0].slice(0,10),n=i[i.length-1].slice(0,10);a+=e===n?` · ${e}`:` · ${t(`info.span`,{from:e,to:n})}`}return[a,t(`info.actors`,{n:n(e.actors?.length||0)}),t(`info.sources`,{n:n(e.sources?.length||0)})]},report:(e,t,{orientation:n,fields:r={summary:!0},kind:i,canvas:a})=>{if(i===`chronicle`)return wu(e,t,{fields:r,canvas:a});if(i===`scale`)return Tu(e,t,{canvas:a});let o=Il(e),s=o.map((i,a)=>{let o=t(e,r,i,n??`vertical`),s=Vl(e,i),c={side1:0,axis:0,side2:0};return s.columns.forEach(e=>{c[e.side]+=1}),{index:a,label:i.label,events:o.eventCount??s.eventCount??0,slots:s.rows.length,columns:c,blocked:o.errors.length>0,blockReason:o.errors[0]??null}}),c={};for(let n of[`vertical`,`horizontal`]){let i=t(e,r,void 0,n);c[n]={size:i.size,fit:Number(yu(i.size,a).toFixed(3))}}let l=Array.isArray(e.slots)?e.slots.length:0,u=n??(l>=5?`vertical`:`horizontal`),d=u===`vertical`?`horizontal`:`vertical`;return{text:{font:13,canvas:a,open:{name:u,fit:c[u].fit},other:{name:d,fit:c[d].fit}},views:o,counts:{slots:l,events:(e.slots??[]).reduce((e,t)=>e+(t?.events?.length||0),0),actors:e.actors?.length??0,sources:e.sources?.length??0},byOrientation:c,suggestedOrientation:l>=5?`vertical`:`horizontal`,blockedViews:s.filter(e=>e.blocked).map(e=>({label:e.label,reason:e.blockReason})),rows:s}},formatReport:e=>{if(e.kind===`chronicle`)return sle(e);if(e.kind===`scale`)return cle(e);let t=[];t.push(`Data: ${e.counts.events} events / ${e.counts.slots} time slots / ${e.counts.actors} parties / ${e.counts.sources} sources`);let n=e.byOrientation.vertical,r=e.byOrientation.horizontal;t.push(`Vertical: content ${n.size.width}×${n.size.height}, fit zoom ${n.fit}`),t.push(`Horizontal: content ${r.size.width}×${r.size.height}, fit zoom ${r.fit}`),t.push(e.suggestedOrientation===`vertical`?`Suggested orientation: vertical (by the slot-count rule, ${e.counts.slots} slots >= 5)`:`Suggested orientation: horizontal (by the slot-count rule, ${e.counts.slots} slots < 5)`),t.push(...xu(e.text,`splitting the timeline into periods, one diagram each`)),t.push(`${e.views.length} view(s):`);for(let n of e.rows){let e=n.columns,r=n.blocked?`does not fit (${n.blockReason})`:`fits`;t.push(` ${n.index}. ${n.label}: side1 ${e.side1} / axis ${e.axis} / side2 ${e.side2}, ${n.events} events -> ${r}`)}return e.blockedViews.length>0&&(t.push(``),t.push(`Note: ${e.blockedViews.length} view(s) do not fit and will not appear in the view dropdown.`),t.push(`Common cause: two or more events of one time slot fall in the same lane (the grid is one event per cell).`),t.push(`How to fix: split that time slot into two finer time points, or change the groups / parties so the events land in different lanes.`)),t.join(`