@adhd/apigen-engine-runtime 0.3.3 β†’ 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.3.4 (2026-10-15)
2
+
3
+ This was a version bump only for apigen-engine-runtime to align it with other projects, there were no code changes.
4
+
1
5
  ## 0.3.3 (2026-10-09)
2
6
 
3
7
  ### 🩹 Fixes
package/index.js CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));require("node:fs");let c=require("node:module");require("node:path");let l=require("pino");l=s(l);let u=require("ajv");u=s(u);let d=require("ajv-formats");d=s(d);var f=`$apigen`,p=class extends Error{constructor(e){super(e),this.code=`E_DUP_CODEC`,this.name=`CodecRegistryError`}};function m(e){e?.wellKnown;let t=new Map;return{register(e,n){if(t.has(e.id)&&!n?.override)throw new p(`E_DUP_CODEC: a codec is already registered for id "${e.id}"`);t.set(e.id,e)},resolve(e){for(let n of t.values())if(n.matches(e))return n},get(e){return t.get(e)},ids(){return[...t.keys()]},freeze(){let e=new Map(t),n={register(){throw new p(`E_DUP_CODEC: registry is frozen and cannot accept new codecs`)},resolve(t){for(let n of e.values())if(n.matches(t))return n},get(t){return e.get(t)},ids(){return[...e.keys()]},freeze(){return n}};return n}}}var ee=`x-apigen-logical`,h=`x-apigen-codec`,te=`x-apigen-ctor`,ne=`x-apigen-tojson`,re=`0.1.0`;function ie(e,t){return{registry:e,resolve:e=>{throw Error(`[apigen-logical] $ref "${e}" cannot be resolved in run-mode without a descriptor root. Supply a resolve() in the ctx override to handle $ref.`)},seen:new WeakSet,path:``,mode:`strict`,...t}}function g(e,t,n){let r=n.registry.resolve(t);if(r)return r.encode(e,t,n);let i=t.$ref;if(typeof i==`string`)return g(e,n.resolve(i),n);let a=t.oneOf;if(Array.isArray(a))return g(e,ae(e,a,t,n),n);let o=t.type;if(o===`array`){if(!Array.isArray(e))return b(e,t,n);let r=t.items;if(!r)return e.map(e=>S(e));let i=n.path;return Array.isArray(r)?e.map((e,t)=>{let a=r[t];return a===void 0?S(e):g(e,a,{...n,path:`${i}/${t}`})}):e.map((e,t)=>g(e,r,{...n,path:`${i}/${t}`}))}if(o===`object`){if(typeof e!=`object`||!e||Array.isArray(e))return b(e,t,n);let r=t.properties;if(!r)return S(e);let i=n.path,a={};for(let[t,o]of Object.entries(r)){let r=e[t];r!==void 0&&(a[t]=g(r,o,{...n,path:`${i}/${t}`}))}return a}return o==null?b(e,t,n):S(e)}function _(e,t,n){let r=n.registry.resolve(t);if(r)return r.decode(e,t,n);let i=t.$ref;if(typeof i==`string`)return _(e,n.resolve(i),n);let a=t.oneOf;if(Array.isArray(a))return _(e,ae(e,a,t,n),n);let o=t.type;if(o===`array`){if(!Array.isArray(e))return e;let r=t.items;if(!r)return e;let i=n.path;return Array.isArray(r)?e.map((e,t)=>{let a=r[t];return a===void 0?e:_(e,a,{...n,path:`${i}/${t}`})}):e.map((e,t)=>_(e,r,{...n,path:`${i}/${t}`}))}if(o===`object`){if(typeof e!=`object`||!e||Array.isArray(e))return e;let r=t.properties;if(!r)return e;let i=n.path,a={};for(let[t,o]of Object.entries(r)){let r=e[t];r!==void 0&&(a[t]=_(r,o,{...n,path:`${i}/${t}`}))}for(let[t,n]of Object.entries(e))!(t in r)&&n!==void 0&&(a[t]=n);return a}return o==null?x(e,n):e}function ae(e,t,n,r){let i=n.discriminator;if(i?.propertyName){let n=i.propertyName,a=typeof e==`object`&&e?e[n]:void 0;if(typeof a==`string`){if(i.mapping){let e=i.mapping[a];if(e){let n=t.find(t=>t.$ref===e);if(n)return n}}for(let e of t){let t=v(e,r).properties?.[n];if(!t)continue;let i=t.enum;if(t.const===a||Array.isArray(i)&&i.includes(a))return e}}}let a=se(e,t,r);if(a)return a;let o,s=-1;for(let n of t){let t=y(e,v(n,r),r);t!==null&&t>s&&(s=t,o=n)}return o===void 0?t[0]??{}:o}function v(e,t){let n=e.$ref;return typeof n==`string`?t.resolve(n):e}function oe(e){if(`const`in e)return e.const;let t=e.enum;if(Array.isArray(t)&&t.length===1)return t[0]}function se(e,t,n){if(typeof e!=`object`||!e||Array.isArray(e))return;let r=e,i=t.map(e=>v(e,n)),a=new Set;for(let e of i){let t=e.properties;if(t)for(let[e,n]of Object.entries(t))oe(n)!==void 0&&a.add(e)}for(let o of a){let a=i.map(e=>{let t=e.properties?.[o];return t?oe(t):void 0}),s=a.filter(e=>e!==void 0),c=new Set(s);if(s.length<2||c.size!==s.length)continue;let l=r[o];if(l===void 0)continue;let u=a.findIndex(e=>e===l);if(u!==-1&&y(e,i[u],n)!==null)return t[u]}}function ce(e){if(e===null)return`null`;if(Array.isArray(e))return`array`;let t=typeof e;return t===`number`?Number.isInteger(e)?`integer`:`number`:t}function y(e,t,n){let r=t.oneOf;if(Array.isArray(r)){let t=null;for(let i of r){let r=y(e,v(i,n),n);r!==null&&(t===null||r>t)&&(t=r)}return t}let i=t.type,a=ce(e);if(typeof i==`string`){if(!(i===a||i===`number`&&a===`integer`))return null}else if(Array.isArray(i)&&!i.some(e=>e===a||e===`number`&&a===`integer`))return null;if(typeof e!=`object`||!e||Array.isArray(e))return+(typeof i==`string`);let o=e,s=t.required,c=0;if(Array.isArray(s)){for(let e of s)if(typeof e==`string`){if(o[e]===void 0)return null;c+=2}}let l=t.properties;if(l){for(let e of Object.keys(l))o[e]!==void 0&&(c+=1);for(let e of Object.keys(o))l[e]===void 0&&--c}return c}function b(e,t,n){for(let t of n.registry.ids()){let r=n.registry.get(t);if(r?.ownsValue?.(e))return{[f]:t,v:r.encode(e,r.schema,n)}}if(Array.isArray(e))return e.map(e=>b(e,{},n));if(le(e)){let t={};for(let[r,i]of Object.entries(e))i!==void 0&&(t[r]=b(i,{},n));return t}return S(e)}function le(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function x(e,t){if(typeof e==`object`&&e&&!Array.isArray(e)&&`$apigen`in e){let n=e,r=n[f],i=t.registry.get(r);if(i)return i.decode(n.v,i.schema,t)}if(Array.isArray(e))return e.map(e=>x(e,t));if(le(e)){let n={};for(let[r,i]of Object.entries(e))n[r]=x(i,t);return n}return e}function S(e){if(e===null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return e;if(Array.isArray(e))return e.map(S);if(typeof e==`object`){let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=S(r));return t}return null}function ue(e,t){let n=new Set,r=[e];for(;r.length>0;){let e=r.pop();if(!e||n.has(e))continue;n.add(e);let i=e.$ref;if(typeof i==`string`){if(t){let e=t[i];if(!e){let e=Object.keys(t).join(`, `)||`(none)`;throw Error(`[apigen-logical] $ref "${i}" cannot be resolved. Available $defs: ${e}`)}r.push(e)}continue}let a=e.oneOf;if(Array.isArray(a))for(let e of a)typeof e==`object`&&e&&r.push(e);let o=e.properties;if(o)for(let e of Object.values(o))r.push(e);let s=e.items;if(Array.isArray(s))for(let e of s)typeof e==`object`&&e&&r.push(e);else typeof s==`object`&&s&&r.push(s);let c=e.additionalProperties;typeof c==`object`&&c&&r.push(c);let l=e.propertyNames;typeof l==`object`&&l&&r.push(l)}}function de(e){return{encode(t,n,r){return g(t,n,ie(e,r))},decode(t,n,r){return _(t,n,ie(e,r))}}}var C={id:`date-time`,kind:`scalar`,schema:{type:`string`,format:`date-time`},matches(e){return e.type===`string`&&e.format===`date-time`},ownsValue(e){return e instanceof Date},encode(e,t,n){return e.toISOString()},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[date-time] expected a string on the wire at "${n.path}", got ${typeof e}`);return new Date(String(e))}if(n.mode===`strict`&&Number.isNaN(new Date(e).getTime()))throw TypeError(`[date-time] invalid date-time string at "${n.path}": ${JSON.stringify(e)}`);return new Date(e)}},w={id:`int64`,kind:`scalar`,schema:{type:`string`,format:`int64`},matches(e){return e.type===`string`&&e.format===`int64`},ownsValue(e){return typeof e==`bigint`},encode(e,t,n){return String(e)},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[int64] expected a string on the wire at "${n.path}", got ${typeof e}`);try{return BigInt(Math.trunc(Number(e)))}catch{return BigInt(0)}}if(n.mode===`strict`)return BigInt(e);if(/^-?\d+$/.test(e))try{return BigInt(e)}catch{return BigInt(0)}return BigInt(0)}};function fe(e){return e}var T={id:`decimal`,kind:`scalar`,schema:{type:`string`,format:`decimal`},matches(e){return e.type===`string`&&e.format===`decimal`},encode(e,t,n){return e},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[decimal] expected a string on the wire at "${n.path}", got ${typeof e}`);return fe(String(e))}if(n.mode===`strict`&&!/^-?\d+(\.\d+)?$/.test(e))throw TypeError(`[decimal] wire value "${e}" at "${n.path}" is not a valid decimal string`);return fe(e)}},E={id:`byte`,kind:`scalar`,schema:{type:`string`,format:`byte`},matches(e){return e.type===`string`&&e.format===`byte`},ownsValue(e){return e instanceof Uint8Array},encode(e,t,n){return Buffer.from(e).toString(`base64`)},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[byte] expected a base64 string on the wire at "${n.path}", got ${typeof e}`);return new Uint8Array}if(n.mode===`strict`&&!/^[A-Za-z0-9+/]*={0,2}$/.test(e))throw TypeError(`[byte] wire value at "${n.path}" is not standard base64 (format:byte): "${e}"`);return new Uint8Array(Buffer.from(e,`base64`))}},pe=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,D={id:`uuid`,kind:`scalar`,schema:{type:`string`,format:`uuid`},matches(e){return e.type===`string`&&e.format===`uuid`},encode(e,t,n){return e.toLowerCase()},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[uuid] expected a string on the wire at "${n.path}", got ${typeof e}`);return String(e).toLowerCase()}if(n.mode===`strict`&&!pe.test(e))throw TypeError(`[uuid] wire value "${e}" at "${n.path}" is not a lowercase-hyphenated RFC 4122 UUID`);return e}},O=`NaN`,k=`Infinity`,A=`-Infinity`,me=new Set([O,k,A]),j={id:`number-special`,kind:`scalar`,schema:{type:`number`},matches(e){return e.type===`number`&&e.format===void 0},ownsValue(e){return typeof e==`number`&&!Number.isFinite(e)},encode(e,t,n){return Number.isNaN(e)?O:e===1/0?k:e===-1/0?A:e},decode(e,t,n){if(typeof e==`number`)return e;if(typeof e==`string`){if(e===O)return NaN;if(e===k)return 1/0;if(e===A)return-1/0;let t=Number(e);if(!Number.isNaN(t))return t}if(n.mode===`strict`)throw TypeError(`[number-special] unrecognized wire value at "${n.path}": ${JSON.stringify(e)}. Expected a number or one of ${[...me].join(`, `)}.`);return NaN}},he=[C,w,T,E,D,j];function ge(e,t={}){for(let n of he)e.register(n,{override:t.override??!1})}var _e=12;function ve(e,t){let n=/^#\/(definitions|\$defs)\/(.+)$/.exec(e);if(!n)return;let[,r,i]=n;return(r===`$defs`?t.$defs:t.definitions)?.[decodeURIComponent(i)]}function ye(e){return Array.isArray(e)&&e.length>0?e[0]:void 0}function be(e){if(Array.isArray(e.type))return e.type.find(e=>e!==`null`)??e.type[0];if(typeof e.type==`string`)return e.type;if(e.properties)return`object`}function xe(e){switch(e.format){case`date-time`:return`1970-01-01T00:00:00.000Z`;case`date`:return`1970-01-01`;case`time`:return`00:00:00Z`;case`uuid`:return`00000000-0000-0000-0000-000000000000`;case`email`:return`user@example.com`;case`uri`:case`url`:case`uri-reference`:return`https://example.com`;case`hostname`:return`example.com`;case`ipv4`:return`127.0.0.1`;case`ipv6`:return`::1`;case`decimal`:return`0`;case`int64`:return`0`;case`byte`:return``;default:return`<string>`}}function Se(e,t,n){let r=e.properties??{},i=e.required??[],a={};for(let e of i){let i=r[e];a[e]=i===void 0?`<${e}>`:M(i,t,n+1)}return a}function Ce(e,t,n){let r=Array.isArray(e.items)?e.items[0]:e.items;return r?[M(r,t,n+1)]:[]}function M(e,t=e??{},n=0){if(!e||n>_e)return null;if(typeof e.$ref==`string`){let r=ve(e.$ref,t);return r===void 0?null:M(r,t,n+1)}if(e.const!==void 0)return e.const;if(Array.isArray(e.enum)&&e.enum.length>0)return e.enum[0];if(Array.isArray(e.allOf)&&e.allOf.length>0){let r={},i=[];for(let t of e.allOf){Object.assign(r,t.properties??{});for(let e of t.required??[])i.includes(e)||i.push(e)}return Se({...e,properties:r,required:i},t,n)}let r=ye(e.oneOf)??ye(e.anyOf);if(r)return M(r,t,n+1);switch(be(e)){case`object`:return Se(e,t,n);case`array`:return Ce(e,t,n);case`string`:return xe(e);case`integer`:case`number`:return 0;case`boolean`:return!1;case`null`:return null;default:return null}}function we(e){if(!e)return;let t=M(e);return`Example: ${JSON.stringify(t)}`}C.id,w.id,T.id,E.id,D.id,j.id,Object.freeze({typescript:{"date-time":{encode:`$.toISOString()`,decode:`new Date($)`,mode:`native`},int64:{encode:`String($)`,decode:`BigInt($)`,mode:`native`},decimal:{encode:`$.toString()`,decode:`new Decimal($)`,imports:[],dep:{name:`decimal.js`,version:`^10`},mode:`branded`},byte:{encode:`Buffer.from($).toString('base64')`,decode:`new Uint8Array(Buffer.from($, 'base64'))`,mode:`native`},uuid:{encode:`$.toLowerCase()`,decode:`$`,mode:`native`},"number-special":{encode:`numToWire($)`,decode:`wireToNum($)`,mode:`native`}},python:{"date-time":{encode:`$.isoformat()`,decode:`datetime.fromisoformat($)`,imports:[`from datetime import datetime`],mode:`native`},int64:{encode:`str($)`,decode:`int($)`,mode:`native`},decimal:{encode:`str($)`,decode:`Decimal($)`,imports:[`from decimal import Decimal`],mode:`native`},byte:{encode:`b64encode($).decode()`,decode:`b64decode($)`,imports:[`from base64 import b64encode, b64decode`],mode:`native`},uuid:{encode:`str($)`,decode:`UUID($)`,imports:[`from uuid import UUID`],mode:`native`},"number-special":{encode:`num_to_wire($)`,decode:`wire_to_num($)`,mode:`native`}},rust:{"date-time":{encode:`__SCAFFOLD_RUST_DATETIME_ENCODE__`,decode:`__SCAFFOLD_RUST_DATETIME_DECODE__`,imports:[`use chrono::{DateTime, Utc};`],dep:{name:`chrono`,version:`^0.4`},mode:`lib`},int64:{encode:`__SCAFFOLD_RUST_INT64_ENCODE__`,decode:`__SCAFFOLD_RUST_INT64_DECODE__`,imports:[`use serde_with::DisplayFromStr;`],dep:{name:`serde_with`,version:`^3`},mode:`lib`},decimal:{encode:`__SCAFFOLD_RUST_DECIMAL_ENCODE__`,decode:`__SCAFFOLD_RUST_DECIMAL_DECODE__`,imports:[`use rust_decimal::Decimal;`],dep:{name:`rust_decimal`,version:`^1`},mode:`lib`},byte:{encode:`__SCAFFOLD_RUST_BYTE_ENCODE__`,decode:`__SCAFFOLD_RUST_BYTE_DECODE__`,imports:[`use serde_with::base64::Base64;`],dep:{name:`serde_with`,version:`^3`},mode:`lib`},uuid:{encode:`__SCAFFOLD_RUST_UUID_ENCODE__`,decode:`__SCAFFOLD_RUST_UUID_DECODE__`,imports:[`use uuid::Uuid;`],dep:{name:`uuid`,version:`^1`},mode:`lib`},"number-special":{encode:`__SCAFFOLD_RUST_NUMSPECIAL_ENCODE__`,decode:`__SCAFFOLD_RUST_NUMSPECIAL_DECODE__`,mode:`native`}},go:{"date-time":{encode:`__SCAFFOLD_GO_DATETIME_ENCODE__`,decode:`__SCAFFOLD_GO_DATETIME_DECODE__`,imports:[`"time"`],mode:`native`},int64:{encode:`__SCAFFOLD_GO_INT64_ENCODE__`,decode:`__SCAFFOLD_GO_INT64_DECODE__`,imports:[`"strconv"`],mode:`native`},decimal:{encode:`__SCAFFOLD_GO_DECIMAL_ENCODE__`,decode:`__SCAFFOLD_GO_DECIMAL_DECODE__`,imports:[`"github.com/shopspring/decimal"`],dep:{name:`github.com/shopspring/decimal`,version:`v1`},mode:`lib`},byte:{encode:`__SCAFFOLD_GO_BYTE_ENCODE__`,decode:`__SCAFFOLD_GO_BYTE_DECODE__`,imports:[`"encoding/base64"`],mode:`native`},uuid:{encode:`__SCAFFOLD_GO_UUID_ENCODE__`,decode:`__SCAFFOLD_GO_UUID_DECODE__`,imports:[`"github.com/google/uuid"`],dep:{name:`github.com/google/uuid`,version:`v1`},mode:`lib`},"number-special":{encode:`__SCAFFOLD_GO_NUMSPECIAL_ENCODE__`,decode:`__SCAFFOLD_GO_NUMSPECIAL_DECODE__`,mode:`native`}},java:{"date-time":{encode:`$.toString()`,decode:`Instant.parse($)`,imports:[`import java.time.Instant;`],dep:{name:`jackson-datatype-jsr310`,version:`2.x`},mode:`lib`},int64:{encode:`@JsonFormat(shape = JsonFormat.Shape.STRING)`,decode:`@JsonFormat(shape = JsonFormat.Shape.STRING)`,imports:[`import com.fasterxml.jackson.annotation.JsonFormat;`],mode:`native`},decimal:{encode:`@JsonSerialize(using = ToStringSerializer.class)`,decode:`new BigDecimal($)`,imports:[`import java.math.BigDecimal;`,`import com.fasterxml.jackson.databind.annotation.JsonSerialize;`,`import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;`],mode:`native`},byte:{encode:`$`,decode:`$`,mode:`native`},uuid:{encode:`$.toString()`,decode:`UUID.fromString($)`,imports:[`import java.util.UUID;`],mode:`native`},"number-special":{encode:`@JsonSerialize(using = NumberSpecialSerializer.class)`,decode:`@JsonDeserialize(using = NumberSpecialDeserializer.class)`,imports:[`import com.fasterxml.jackson.databind.annotation.JsonSerialize;`,`import com.fasterxml.jackson.databind.annotation.JsonDeserialize;`],mode:`native`}}});var Te=m();ge(Te);var Ee=de(Te.freeze());function De(e,t){return t in(e.input?.properties??{})}function Oe(e){let t=e.input?.properties?.data;return Object.keys(t?.properties??{})}function ke(e,t){let n=e.input?.properties?.data?.properties?.[t];return n===void 0?void 0:n}function Ae(e,t){return t===void 0||e===void 0?e:Ee.decode(e,t)}function N(e,t){let n=t.output;return!n||Object.keys(n).length===0?e:Ee.encode(e,n)}async function je(e,t,n,r,i,a){let o=Oe(n).map(e=>Ae(a[e],ke(n,e)));if(De(n,`session`)&&t){let a=await t({session:i.session});return N(await e[r](a,...o),n)}if(n.hasCtx){let a=t?await t(i):void 0;return N(await e[r](a,...o),n)}return N(await e[r](...o),n)}var Me=class{constructor(){this._map=new Map}set(e,t){this._map.set(e,t)}get(e){return this._map.get(e)}has(e){return this._map.has(e)}};function P(e=[]){return async function(t,n,r){let i=r.schemas[t];if(!i)throw Error(`apigen/invoke: no schema found for operation "${t}"`);return e.reduceRight((e,t)=>()=>t(n,e),()=>je(r.fns,r.createClient,i,t,n.envelope,n.domainArgs))()}}function Ne(e){return e}var F=class{constructor(){this.handlers=new Map}on(e,t){let n=this.handlers.get(e)??[];return this.handlers.set(e,[...n,t]),()=>this.off(e,t)}off(e,t){let n=this.handlers.get(e);if(!n)return;let r=n.filter(e=>e!==t);r.length===0?this.handlers.delete(e):this.handlers.set(e,r)}clear(){this.handlers.clear()}async emit(e){for(let[t,n]of this.handlers)if(Pe(t,e))for(let t of n)await t(e)}};function Pe(e,t){let[n,r,i]=e.split(`:`);return!(n!==`*`&&n!==t.module||r&&r!==`*`&&r!==t.method||i&&i!==`*`&&i!==t.lifecycle)}function I(e,t){for(let n of e)if(n.eventMapping)for(let[e,r]of Object.entries(n.eventMapping))t.on(e,r)}async function L(e,t,n){let r={...t};for(let t of e)if(t.createContext){await n.emit({module:t.id,method:`createContext`,lifecycle:`start`,ctx:r});try{let e=await t.createContext(r);r={...r,...e},await n.emit({module:t.id,method:`createContext`,lifecycle:`complete`,ctx:r})}catch(e){throw await n.emit({module:t.id,method:`createContext`,lifecycle:`error`,ctx:r,error:e}),e}}return r}(0,c.createRequire)(require("node:url").pathToFileURL(__filename).href);var R=new Set([`string`,`number`,`boolean`,`integer`]);function Fe(e){if(typeof e!=`object`||!e)return!1;let t=e;if(t.$ref!==void 0||t.oneOf||t.anyOf||t.allOf)return!1;let{type:n}=t;return typeof n==`string`?R.has(n):Array.isArray(n)?n.every(e=>R.has(e)||e===`null`):Array.isArray(t.enum)&&t.enum.length>0?t.enum.every(e=>[`string`,`number`,`boolean`].includes(typeof e)):!1}function z(e){if(!e||typeof e!=`object`)return!1;let t=e.properties;return t===void 0||typeof t!=`object`||!t?!1:Object.values(t).every(Fe)}function Ie(e){let t={},n=e=>{for(let n of[`definitions`,`$defs`]){let r=e[n];if(r)for(let[e,i]of Object.entries(r)){let r=e.startsWith(`#/`)?e:`#/${n}/${e}`;t[r]=i}}};for(let t of Object.values(e.schemas))n(t.input),n(t.output);if(Object.keys(t).length!==0)for(let[n,r]of Object.entries(e.schemas))try{ue(r.input,t),ue(r.output,t)}catch(e){throw Error(`[apigen-core-client] Schema validation failed for function "${n}": ${e.message}`)}}function Le(e,t){let n=[`apigen calling convention: all domain parameters go inside a "data" envelope β€” e.g. { "data": { ... } }`+(t?`.`:` (an empty object for this zero-parameter tool).`)];return e.length>0&&n.push(`Field(s) ${e.map(e=>`"${e}"`).join(`, `)} are transport-level envelope metadata, NOT domain data β€” do not nest them under "data". Over MCP they are read from arguments._meta["x-<pluginId>-<field>"] (default pluginId "adhd"); see @adhd/apigen-engine-naming's envelopeMetaKey/envelopeCliFlag/envelopeEnvVar for the HTTP-header / CLI-flag / env-var equivalents.`),n.join(` `)}function Re(e,t,n){Ie(e);let r={};for(let[i,a]of Object.entries(e.schemas)){let e=n?.[i]??{},o=a.input.properties??{},s=a.input.required??[],c={},l=[],u={};for(let n of t)if(n.envelope&&e[n.id]!==!1)for(let[e,t]of Object.entries(n.envelope))c[e]=t,u[e]=n.id,l.includes(e)||l.push(e);let d={type:`object`,properties:o,additionalProperties:!1,...s.length>0?{required:s}:{}},f=a.safe===!0||z(a.input),p=a.input.definitions,m=a.input.$defs;r[i]={input:{type:`object`,properties:{...c,data:d},required:[...l,...s.length>0?[`data`]:[]],additionalProperties:!1,description:Le(Object.keys(c),Object.keys(o).length>0),...p?{definitions:p}:{},...m?{$defs:m}:{}},output:a.output,...a.hasCtx?{hasCtx:!0}:{},"x-apigen-safe":f,...Object.keys(u).length>0?{"x-apigen-envelope":u}:{}}}return r}var ze={"decimal.js":`Decimal`};function Be(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}Object.entries(ze).map(([e,t])=>({pattern:RegExp(`import\\(["'][^"']*${Be(e)}[^"']*["']\\)\\.\\w+`,`g`),key:t}));var B=class extends Error{constructor(e){super(e),this.name=`ConfigurationError`}};function Ve(e){for(let t of e)for(let e of Object.keys(t.eventMapping??{})){let[n]=e.split(`:`);if(n!==`*`&&n===t.id)throw new B(`Middleware "${t.id}" subscribes to its own events via "${e}". This would cause infinite recursion.`)}}function He(e){let{domainSchemas:t,middlewares:n,overrides:r={},strict:i=!1}=e;Ve(n);for(let e of Object.keys(r))if(!(e in t.schemas)){let t=`Override key "${e}" not found in domain schemas.`;if(i)throw new B(t);console.warn(`[apigen-runtime]`,t)}let a=new Set(n.map(e=>e.id));for(let[e,t]of Object.entries(r))for(let n of Object.keys(t??{}))if(!a.has(n)){let t=`Override key "${e}.${n}" does not match any declared middleware id.`;if(i)throw new B(t);console.warn(`[apigen-runtime]`,t)}let o=Re(t,n,r),s=new F;return I(n,s),{schemas:o,createClient:async e=>L(n,e,s),dispose:()=>s.clear()}}function Ue(e={}){let t=e.level??`info`,n=typeof e.destination==`string`&&e.destination.length>0,r=!n&&!!process.stderr.isTTY,i=e.format??(r?`pretty`:`json`),a={level:t};if(i===`pretty`)return a.transport={target:`pino-pretty`,options:{colorize:!n,translateTime:`SYS:HH:MM:ss.l`,ignore:`pid,hostname`,...n?{destination:e.destination,mkdir:!0}:{destination:2}}},(0,l.default)(a);let o=n?l.default.destination({dest:e.destination,mkdir:!0,sync:!0}):l.default.destination(2);return(0,l.default)(a,o)}function We(e){if(e?.type!==`object`||!e.properties)return;let t=Object.entries(e.properties);if(t.length===0)return;let n=new Set(e.required??[]);return`{ ${t.map(([e,t])=>`${e}${n.has(e)?``:`?`}: ${V(t)}`).join(`, `)} }`}function Ge(e){return typeof e==`string`?`'${e}'`:JSON.stringify(e)}function Ke(e){let t=e.enum??[];return t.length===0?`unknown`:t.map(Ge).join(`|`)}function qe(e,t){return e.map(e=>V(e,t)).join(` | `)}function V(e,t=0){if(!e)return`unknown`;if(e.type===`array`)return`${V(e.items,0)}[]`;if(e.enum)return Ke(e);if(e.$ref)return String(e.$ref).split(`/`).pop()||`object`;let n=e.anyOf??e.oneOf;return n?n.length===0?`unknown`:t>=2?qe(n,t-1):`union`:t>=1&&e.type===`object`?We(e)??`object`:e.type??`object`}function Je(e){let t=(e?.input??{}).properties?.data,n=t?.properties??{},r=new Set(t?.required??[]),i=Object.entries(n).map(([e,t])=>({name:e,type:V(t,2),required:r.has(e)}));return{params:i,text:i.map(e=>`${e.name}${e.required?``:`?`}: ${e.type}`).join(`, `)}}function Ye(e){let t;return t=Array.isArray(e)?e:e?[e]:[],t.find(e=>e===`number`||e===`integer`||e===`boolean`)}function Xe(e,t){let n=(t?.input??{}).properties?.data?.properties??{},r={...e};for(let[e,t]of Object.entries(n)){let n=r[e];if(typeof n!=`string`)continue;let i=Ye(t?.type);if(i===`number`||i===`integer`){let t=Number(n);!Number.isNaN(t)&&n.trim()!==``&&(r[e]=t)}else i===`boolean`&&(n===`true`?r[e]=!0:n===`false`&&(r[e]=!1))}return r}var Ze=new Set([`default`,`module.exports`,`__esModule`]);function Qe(e){let t={},n=(e,r)=>{for(let[i,a]of Object.entries(e))if(typeof a==`function`){!Ze.has(i)&&!(i in t)&&(t[i]=a);let e=a.name;e&&!(e in t)&&(t[e]=a)}else a&&typeof a==`object`&&r<2&&Ze.has(i)&&n(a,r+1)};return n(e,0),t}var $e=[`invalid_argument`,`unauthenticated`,`permission_denied`,`not_found`,`internal`],H=class extends Error{constructor(e,t,n){super(t),this.name=`ApiError`,this.code=e,this.details=n,Object.setPrototypeOf(this,new.target.prototype)}toJSON(){let e={code:this.code,message:this.message};return this.details!==void 0&&(e.details=this.details),e}};function et(e){return typeof e==`object`&&!!e&&e.name===`ApiError`&&$e.includes(e.code)&&typeof e.toJSON==`function`}function tt(e,t,n=0){return e===`before-first-chunk`?{phase:e,error:t}:{phase:e,error:t,chunksDelivered:n}}var U=new u.default({allErrors:!0,verbose:!0});(0,d.default)(U);for(let e of[ee,h,te,ne,`discriminator`])U.addKeyword({keyword:e,valid:!0});U.addFormat(`decimal`,/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)$/);function nt(e){return e?e.replace(/^\//,``).split(`/`).map(e=>e.replace(/~1/g,`/`).replace(/~0/g,`~`)).join(`.`):`(root)`}function rt(e){let t=e?.properties;return t?Object.keys(t):[]}function it(e,t){let n=e.length,r=t.length;if(n===0)return r;if(r===0)return n;let i=Array.from({length:r+1},(e,t)=>t);for(let a=1;a<=n;a++){let n=[a];for(let o=1;o<=r;o++){let r=e[a-1]===t[o-1]?0:1;n[o]=Math.min(i[o]+1,n[o-1]+1,i[o-1]+r)}i=n}return i[r]}function at(e,t){let n,r=1/0;for(let i of t){let t=it(e.toLowerCase(),i.toLowerCase());t<r&&(r=t,n=i)}let i=Math.max(2,Math.floor(e.length/3));return n!==void 0&&r<=i?n:void 0}function ot(e){return e===null?`null`:Array.isArray(e)?`array`:typeof e}function st(e){let t=nt(e.instancePath),n=e.params??{};switch(e.keyword){case`additionalProperties`:{let r=String(n.additionalProperty??`?`),i=rt(e.parentSchema),a=at(r,i);return`unknown key '${r}' at ${t}${i.length?`; allowed keys: ${i.join(`, `)}`:``}${a?` (did you mean '${a}'?)`:``}`}case`required`:{let r=String(n.missingProperty??`?`),i=rt(e.parentSchema);return`missing required key '${r}' at ${t}${i.length?`; allowed keys: ${i.join(`, `)}`:``}`}case`enum`:{let r=Array.isArray(n.allowedValues)?n.allowedValues:[],i=e.data;return`value ${JSON.stringify(i)} at ${t} is not one of: ${r.map(e=>JSON.stringify(e)).join(`, `)}`}case`type`:{let r=e.data;return`${t} must be ${String(n.type)} (got ${ot(r)})`}default:return`${t} ${e.message??`failed schema check`}`}}var W=12;function ct(e){let t=e.slice(0,W).map(st);return e.length>W&&t.push(`…and ${e.length-W} more`),t.join(`; `)}function G(e){return e===null?!1:Array.isArray(e)?e.some(G):typeof e!=`object`||Object.values(e).some(G)}function lt(e,t){let n=[`Validation failed: ${ct(e)}`],r=M(t);return G(r)&&n.push(`Example: ${JSON.stringify(r)}`),n.join(` β€” `)}var ut=async(e,t)=>{let n=e.ctx.get(dt);if(n===void 0)return t();let r=n[e.operation.id];if(r===void 0)return t();let i={data:e.domainArgs,...e.envelope},a=U.compile(r.input);if(!a(i)){let e=a.errors??[];throw new H(`invalid_argument`,lt(e,r.input),e)}return t()},dt=Symbol(`ValidateSchemasToken`);function ft(e){return async function(t,n){let r=e[t.operation.id];if(r===void 0)return n();let i={data:t.domainArgs,...t.envelope},a=U.compile(r.input);if(!a(i)){let e=a.errors??[];throw new H(`invalid_argument`,lt(e,r.input),e)}return n()}}function pt(){return`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e===`x`?t:t&3|8).toString(16)})}var mt=class{constructor(e={}){this._store=new Map,this._sweeper=null,this._defaultTtlMs=e.defaultTtlMs;let t=null;t=e.sweepIntervalMs===0?null:e.sweepIntervalMs===void 0?this._defaultTtlMs===void 0?null:Math.max(1e3,Math.floor(this._defaultTtlMs/4)):e.sweepIntervalMs,t!==null&&t>0&&(this._sweeper=setInterval(()=>this._sweep(),t),this._sweeper.unref?.())}create(e,t=[],n){let r=new e(...t),i=pt(),a=n??this._defaultTtlMs,o=a===void 0?null:Date.now()+a;return this._store.set(i,{instance:r,expiresAt:o}),{instanceId:i}}get(e){let t=this._store.get(e);if(!t)throw Error(`[instance-registry] Unknown instanceId: "${e}"`);if(t.expiresAt!==null&&Date.now()>t.expiresAt)throw this._evict(e,t),Error(`[instance-registry] Instance "${e}" has expired`);return t.instance}async dispatch(e,t,n=[]){let r=this.get(e),i=r[t];if(typeof i!=`function`)throw Error(`[instance-registry] Method "${t}" not found on instance "${e}"`);return i.call(r,...n)}async dispose(e){let t=this._store.get(e);t&&(this._store.delete(e),await K(t.instance))}async disposeAll(){this._sweeper!==null&&(clearInterval(this._sweeper),this._sweeper=null);let e=[...this._store.entries()];this._store.clear(),await Promise.all(e.map(([,e])=>K(e.instance)))}get size(){return this._store.size}_sweep(){let e=Date.now();for(let[t,n]of this._store)n.expiresAt!==null&&e>n.expiresAt&&this._evict(t,n)}_evict(e,t){this._store.delete(e),K(t.instance)}};async function K(e){if(typeof e==`object`&&e&&`dispose`in e){let t=e.dispose;typeof t==`function`&&await t.call(e)}}function ht(e){let{produce:t,signal:n}=e,r=n??new AbortController().signal;return{[Symbol.asyncIterator](){let e=t(r);return{async next(){return r.aborted?(await e.return(void 0),{done:!0,value:void 0}):e.next()},async return(t){return await e.return(t),{done:!0,value:void 0}},async throw(t){return await e.throw(t),{done:!0,value:void 0}}}}}}async function gt(e){let t=[];for await(let n of e)t.push(n);return t}async function _t(e){let t=[];try{for await(let n of e)t.push(n);return{ok:!0,chunks:t}}catch(e){let n=et(e)?e:new H(`internal`,e instanceof Error?e.message:String(e));return t.length===0?{ok:!1,carrier:tt(`before-first-chunk`,n)}:{ok:!1,carrier:tt(`after-first-chunk`,n,t.length)}}}function vt(e){return typeof e==`object`&&!!e&&Symbol.asyncIterator in e}var q=class extends Error{constructor(e,t){super(t),this.name=`UnionCodecError`,this.code=e}};function J(e){let t=e.discriminator;if(typeof t!=`object`||!t||Array.isArray(t))return;let n=t;if(typeof n.propertyName!=`string`)return;let r=n.mapping;if(typeof r==`object`&&r&&!Array.isArray(r))return{propertyName:n.propertyName,mapping:r}}function yt(e,t){let n=e[h];if(typeof n==`string`){let e=t.registry.get(n);if(e)return e}return t.registry.resolve(e)}function bt(e,t,n){let r=yt(t,n);return r?r.encode(e,t,n):e}function xt(e,t,n){let r=yt(t,n);return r?r.decode(e,t,n):e}function St(e){let{id:t,schema:n}=e;return{id:t,kind:`union`,schema:n,matches(e){if(e[`x-apigen-logical`]===`union`)return!0;let t=e.oneOf;return!Array.isArray(t)||t.length===0?!1:J(e)!==void 0},encode(e,n,r){let i=J(n);if(!i)throw new q(`E_UNION_NO_DISCRIMINATOR`,`[${t}] schema node at "${r.path}" has no discriminator.propertyName; cannot dispatch union branch.`);let{propertyName:a,mapping:o}=i,s=e[a];if(s==null)throw new q(`E_UNION_NO_DISCRIMINATOR`,`[${t}] value at "${r.path}" is missing the discriminator property "${a}".`);let c=String(s),l=o[c];if(!l)throw new q(`E_UNION_UNKNOWN_TAG`,`[${t}] discriminator tag "${c}" at "${r.path}" is not in the mapping (known: ${Object.keys(o).join(`, `)}).`);return bt(e,r.resolve(l),{...r,path:`${r.path}[${c}]`})},decode(e,n,r){if(typeof e!=`object`||!e||Array.isArray(e)){let n;throw n=e===null?`null`:Array.isArray(e)?`array`:typeof e,new q(`E_UNION_INVALID_WIRE`,`[${t}] expected a JSON object on the wire at "${r.path}", got ${n}.`)}let i=e,a=J(n);if(!a)throw new q(`E_UNION_NO_DISCRIMINATOR`,`[${t}] schema node at "${r.path}" has no discriminator.propertyName; cannot dispatch union branch.`);let{propertyName:o,mapping:s}=a,c=i[o];if(c==null)throw new q(`E_UNION_NO_DISCRIMINATOR`,`[${t}] wire object at "${r.path}" is missing the discriminator property "${o}".`);let l=String(c),u=s[l];if(!u)throw new q(`E_UNION_UNKNOWN_TAG`,`[${t}] discriminator tag "${l}" on the wire at "${r.path}" is not in the mapping (known: ${Object.keys(s).join(`, `)}).`);return xt(e,r.resolve(u),{...r,path:`${r.path}[${l}]`})}}}var Y=class extends Error{constructor(e,t){super(t),this.name=`NominalCodecError`,this.code=e}};function Ct(e){let t=e.properties;return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}function wt(e){let t=e.required;return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}function Tt(e,t,n){if(t){let r=n.registry.resolve(t);if(r)return r.encode(e,t,n)}return e}function Et(e,t,n){if(t){let r=n.registry.resolve(t);if(r)return r.decode(e,t,n)}return e}function Dt(e){let{id:t,schema:n,ctor:r}=e;return{id:t,kind:`nominal`,schema:n,matches(e){return e[`x-apigen-logical`]===`nominal`||e[h]===t},encode(e,n,r){if(typeof e!=`object`||!e)return e;if(r.seen.has(e)){if(r.mode===`strict`)throw new Y(`E_NOMINAL_CYCLE`,`[${t}] cycle detected at "${r.path}": a nominal instance references itself. Strict mode rejects cycles (DESIGN Β§8.3); break the cycle or use 'lossy' mode.`);return null}r.seen.add(e);try{let t=Ct(n),i=e[typeof n[`x-apigen-tojson`]==`string`?n[ne]:`toJSON`];if(typeof i==`function`){let n=i.call(e);if(typeof n==`object`&&n&&!Array.isArray(n)){let e={};for(let[i,a]of Object.entries(n))e[i]=Tt(a,t[i],{...r,path:`${r.path}/${i}`});return e}return n}let a={},o=Object.keys(t),s=e,c=o.length>0?o:Object.keys(s);for(let e of c){let n=s[e];n!==void 0&&(a[e]=Tt(n,t[e],{...r,path:`${r.path}/${e}`}))}return a}finally{r.seen.delete(e)}},decode(e,n,i){if(typeof e!=`object`||!e||Array.isArray(e)){let n;throw n=e===null?`null`:Array.isArray(e)?`array`:typeof e,new Y(`E_NOMINAL_INVALID_WIRE`,`[${t}] expected a JSON object on the wire at "${i.path}", got ${n}.`)}let a=e;for(let e of wt(n))if(!(e in a))throw new Y(`E_NOMINAL_INVALID_WIRE`,`[${t}] required field "${e}" missing on the wire at "${i.path}".`);if(n[`x-apigen-instances`]===!1)throw new Y(`E_NOMINAL_NONRECONSTRUCTABLE`,`[${t}] is encode-only: the extractor marked it non-reconstructable (x-apigen-instances:false). It cannot be decoded back to a live instance.`);let o=Ct(n),s={};for(let[e,t]of Object.entries(a))s[e]=Et(t,o[e],{...i,path:`${i.path}/${e}`});if(r){let e=typeof n[`x-apigen-ctor`]==`string`?n[te]:`fromJSON`,t=r[e];return typeof t==`function`?t.call(r,s):new r(s)}return s}}}var Ot=[C,w,T,E,D,j],kt=Dt({id:`ts.NominalSentinel`,schema:{type:`object`,"x-apigen-logical":`nominal`,"x-apigen-codec":`ts.NominalSentinel`}}),At=St({id:`ts.UnionSentinel`,schema:{oneOf:[],discriminator:{propertyName:`kind`,mapping:{}},"x-apigen-logical":`union`,"x-apigen-codec":`ts.UnionSentinel`}});function jt(){let e=[...Ot.map(e=>[e.id,e]),[kt.id,kt],[At.id,At]];return Object.freeze(new Map(e))}var Mt=Object.freeze({host:`ts`,logicalTypeVersion:re,codecs:jt()});function Nt(e,t,n){let r=[n,typeof t?.input?.description==`string`?t.input.description:void 0,we(t?.input)].filter(e=>typeof e==`string`&&e.length>0);return r.length>0?r.join(` β€” `):e}function Pt(e){if(!e||typeof e!=`object`||Array.isArray(e)||Object.keys(e).length===0)return{outputSchema:void 0,wrapped:!1};let t=e;return t.type===`object`?{outputSchema:t,wrapped:!0}:{outputSchema:void 0,wrapped:!1}}function Ft(e,t){if(e)return t&&typeof t==`object`&&!Array.isArray(t)?t:void 0}var It=4,Lt=32;function X(e){return et(e)?e:e instanceof Error?new H(`internal`,e.message):e}function Rt(e,t){if(e===`serial`||e===`chained`)return 1;let n=t??4;return!Number.isFinite(n)||n<1?1:Math.min(Math.floor(n),32)}function zt(){}function Bt(e,t){if(!e&&!t)return{signal:void 0,dispose:zt};let n=new AbortController,r=()=>{n.abort(e?.reason)};e&&(e.aborted?n.abort(e.reason):e.addEventListener(`abort`,r,{once:!0}));let i;return t!==void 0&&!n.signal.aborted&&(i=setTimeout(()=>{n.abort(new DOMException(`apigen/invokeBatch: item timed out after ${t}ms`,`TimeoutError`))},t),i.unref?.()),{signal:n.signal,dispose(){e&&e.removeEventListener(`abort`,r),i&&clearTimeout(i)}}}async function Z(e,t,n,r,i,a){let o=Bt(r.signal,a);try{let a=await e(t,o.signal?{...r,signal:o.signal}:r,i);if(vt(a)){let e=await _t(a);if(!e.ok){let t=e.carrier;return{index:n,status:`rejected`,reason:X(t.error),...t.phase===`after-first-chunk`?{chunksDelivered:t.chunksDelivered}:{}}}return{index:n,status:`fulfilled`,chunks:e.chunks}}return{index:n,status:`fulfilled`,value:a}}catch(e){return{index:n,status:`rejected`,reason:X(e)}}finally{o.dispose()}}async function Vt(e,t,n,r,i={}){let a=i.mode??`parallel`,o=i.onItemError??`continue`,s=Rt(a,i.concurrency),c=Array(n.length),l=e=>({index:e,status:`rejected`,reason:X(Error(`apigen/invokeBatch: not attempted β€” an earlier item failed and `+(a===`chained`?`mode is "chained"`:`onItemError is "abort"`)))});if(a===`serial`||a===`chained`){let s=!1;for(let u=0;u<n.length;u++){if(s){c[u]=l(u);continue}let d=await Z(e,t,u,n[u],r,i.itemTimeoutMs);c[u]=d,d.status===`rejected`&&(a===`chained`||o===`abort`)&&(s=!0)}return c}let u=0,d=!1,f=Math.max(1,Math.min(s,n.length)),p=Array.from({length:f},async()=>{for(;;){let a=u++;if(a>=n.length)return;if(d){c[a]=l(a);continue}let s=await Z(e,t,a,n[a],r,i.itemTimeoutMs);c[a]=s,s.status===`rejected`&&o===`abort`&&(d=!0)}});return await Promise.all(p),c}function Ht(e){return e.words.join(`-`)}function Ut(e){return e.words.map(Yt).join(``)}function Wt(e){return e.words.join(`_`)}function Gt(e,t={}){let n=[e.namespace,...e.path],r=e.safe||z(e.input)?`GET`:`POST`,i=t.http?.verb?.[e.id]??r,a=`/`+n.map(e=>Ht(e)).join(`/`),o=n.map(e=>Wt(e)).join(`_`),s=n.map(e=>Wt(e)).slice(0,-1).join(`.`),c=Ut(n[n.length-2]??n[0]),l=Ut(n[n.length-1]),u=n.map(e=>Ht(e));return{http:{verb:i,route:a},mcp:{name:o},grpc:{package:s,service:c,method:l},cli:{path:u}}}function Kt(e,t){return`x-${e}-${t}`}function qt(e,t){return`--${e}-${t}`}function Jt(e,t){let n=e=>e.toUpperCase().replace(/-/g,`_`);return e===`adhd`?`APIGEN_${n(t)}`:`APIGEN_${n(e)}_${n(t)}`}function Yt(e){return e.length===0?e:e[0].toUpperCase()+e.slice(1)}function Q(e){return e.anyOf??e.oneOf}function Xt(e){if(!e)return!1;if(e.type===`array`||e.type===`object`)return!0;let t=Q(e);if(t){let e=t.filter(e=>e.type!==`null`);return e.length>0&&e.every(e=>e.type===`array`||e.type===`object`)}return!1}function Zt(e){if(!e)return!1;if(e.type===`boolean`)return!0;let t=Q(e);if(t){let e=t.filter(e=>e.type!==`null`);return e.length>0&&e.every(e=>e.type===`boolean`)}return!1}function Qt(e){if(!e)return!1;if(e.type===`number`||e.type===`integer`)return!0;let t=Q(e);if(t){let e=t.filter(e=>e.type!==`null`);return e.length>0&&e.every(e=>e.type===`number`||e.type===`integer`)}return!1}function $t(e){return e.replace(/[A-Z]/g,e=>`-`+e.toLowerCase())}function en(e){let t=e.input?.properties?.data;return{props:t?.properties??{},required:t?.required??[]}}function tn(e){return typeof e.handler==`function`}function nn(e){let t=e.input?.properties??{},n=e[`x-apigen-envelope`],r=[];for(let e of Object.keys(t)){if(e===`data`)continue;let t=n?.[e]??`adhd`,i=Kt(t,e);r.push({field:e,pluginId:t,httpHeader:i,mcpMetaKey:i,cliFlag:qt(t,e),envVar:Jt(t,e)})}return r}function rn(e,t,n,r){t===n||e.has(t)||e.set(t,{...r,aliasOf:n})}function an(e,t){let n=new Map,{props:r}=en(e);for(let[e,t]of Object.entries(r)){let r=`string`;Zt(t)?r=`boolean`:(Xt(t)||Qt(t))&&(r=`json`);let i=$t(e),a={camelKey:e,kind:`domain`,valueKind:r};n.set(i,a),rn(n,e,i,a)}for(let e of t){let t=e.cliFlag.replace(/^--/,``),r={camelKey:e.field,kind:`envelope`,valueKind:`string`,envVar:e.envVar};n.set(t,r)}return n}function on(e){let{op:t,schema:n,transport:r,projection:i}=e,a=Gt(t,i),o=n?nn(n):[],s=n?an(n,o):new Map,c=n?Je(n).params:void 0,l={op:t,transport:r,http:a.http,mcp:a.mcp,cli:a.cli,grpc:a.grpc,params:c,envelope:o,cliFlags:s,streaming:t.streaming,isMount:tn(t)};if(tn(t)){let e=t.handler;l.mountHandler=async t=>e(t)}return l}function sn(e){let t=e.usePlugins;return Array.isArray(t)?t:[]}function cn(e){let t=e.exitCode;return typeof t==`function`?t:void 0}function ln(e){let t=e.useOptions;return t&&typeof t==`object`?t:{}}function un(e){return async function(t,n){let r=Object.assign(t,{data:t.domainArgs});return await e.layer(r,n)}}function dn(e,t){let n=[];for(let e of t){let t=e.capabilities?.layer;t&&n.push(un(t))}return n.push(ft(e)),P(n)}function fn(){let e=new Map;return{get:t=>e.get(t),set:(t,n)=>{e.set(t,n)}}}var pn={input:{type:`object`,properties:{data:{type:`object`,properties:{}}}},output:{}};async function mn(e,t,n,r){let i={...n,operation:{id:e.op.id},ctx:new Me,transport:e.transport};if(e.isMount){let a=e.mountHandler;if(!a)throw Error(`apigen-engine-runtime/dispatchForPlan: OpPlan for mount op "${e.op.id}" has isMount=true but no mountHandler`);let o={operation:e.op,data:n.domainArgs,envelope:n.envelope,ctx:fn(),transport:e.transport,signal:n.signal??new AbortController().signal},s={...r,fns:{[e.op.id]:()=>a(o)},schemas:{[e.op.id]:pn}};return t(e.op.id,i,s)}return t(e.op.id,i,r)}var $=`127.0.0.1`;function hn(e){let t=e.trim().toLowerCase().replace(/^\[|\]$/g,``);if(t===`localhost`||t===`::1`)return!0;let n=t.startsWith(`::ffff:`)?t.slice(7):t;return/^127(\.\d{1,3}){3}$/.test(n)}function gn(e){if(typeof e!=`string`)return $;let t=e.trim();return t===``?$:t}function _n(e,t,n){return!hn(e)&&(n?.warn({host:e,host_kind:t},`${t} binding non-loopback host "${e}": the server will be reachable from the network. Omit the host option to bind ${$}.`),!0)}exports.BATCH_DEFAULT_CONCURRENCY=It,exports.BATCH_MAX_CONCURRENCY=Lt,exports.DEFAULT_LISTEN_HOST=$,exports.EventBus=F,exports.InstanceRegistry=mt,exports.LayerContext=Me,exports.UnionCodecError=q,exports.ValidateSchemasToken=dt,exports.WELL_KNOWN_TS_CODECS=Ot,exports.adaptCoreLayer=un,exports.assertNoSelfSubscription=Ve,exports.buildContext=L,exports.buildFnTable=Qe,exports.buildMcpOutputSchema=Pt,exports.buildOpPlan=on,exports.buildToolDescription=Nt,exports.coerceQueryParams=Xe,exports.collectWithPhase=_t,exports.createApiPackage=He,exports.createInvoker=P,exports.createLogger=Ue,exports.createPackageInvoker=dn,exports.createStream=ht,exports.createUnionCodec=St,exports.dataParamNames=Oe,exports.defineMiddleware=Ne,exports.describeParams=Je,exports.dispatch=je,exports.dispatchForPlan=mn,exports.drainStream=gt,exports.invokeBatch=Vt,exports.isApiStream=vt,exports.isLoopbackListenHost=hn,exports.makeValidateLayer=ft,exports.needsEnvelopeField=De,exports.readExitCodeHook=cn,exports.readUseOptions=ln,exports.readUsePlugins=sn,exports.resolveListenHost=gn,exports.tsHostBinding=Mt,exports.validateLayer=ut,exports.warnIfNonLoopbackListen=_n,exports.wireObservers=I,exports.wrapMcpStructuredContent=Ft;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));require("node:fs");let c=require("node:module");require("node:path");let l=require("pino");l=s(l);let u=require("ajv");u=s(u);let d=require("ajv-formats");d=s(d);var f=`$apigen`,p=class extends Error{constructor(e){super(e),this.code=`E_DUP_CODEC`,this.name=`CodecRegistryError`}};function m(e){e?.wellKnown;let t=new Map;return{register(e,n){if(t.has(e.id)&&!n?.override)throw new p(`E_DUP_CODEC: a codec is already registered for id "${e.id}"`);t.set(e.id,e)},resolve(e){for(let n of t.values())if(n.matches(e))return n},get(e){return t.get(e)},ids(){return[...t.keys()]},freeze(){let e=new Map(t),n={register(){throw new p(`E_DUP_CODEC: registry is frozen and cannot accept new codecs`)},resolve(t){for(let n of e.values())if(n.matches(t))return n},get(t){return e.get(t)},ids(){return[...e.keys()]},freeze(){return n}};return n}}}var ee=`x-apigen-logical`,h=`x-apigen-codec`,te=`x-apigen-ctor`,ne=`x-apigen-tojson`,re=`0.1.0`;function ie(e,t){return{registry:e,resolve:e=>{throw Error(`[apigen-logical] $ref "${e}" cannot be resolved in run-mode without a descriptor root. Supply a resolve() in the ctx override to handle $ref.`)},seen:new WeakSet,path:``,mode:`strict`,...t}}function g(e,t,n){let r=n.registry.resolve(t);if(r)return r.encode(e,t,n);let i=t.$ref;if(typeof i==`string`)return g(e,n.resolve(i),n);let a=t.oneOf;if(Array.isArray(a))return g(e,ae(e,a,t,n),n);let o=t.type;if(o===`array`){if(!Array.isArray(e))return b(e,t,n);let r=t.items;if(!r)return e.map(e=>C(e));let i=n.path;return Array.isArray(r)?e.map((e,t)=>{let a=r[t];return a===void 0?C(e):g(e,a,{...n,path:`${i}/${t}`})}):e.map((e,t)=>g(e,r,{...n,path:`${i}/${t}`}))}if(o===`object`){if(typeof e!=`object`||!e||Array.isArray(e))return b(e,t,n);let r=t.properties;if(!r)return C(e);let i=n.path,a={};for(let[t,o]of Object.entries(r)){let r=e[t];r!==void 0&&(a[t]=g(r,o,{...n,path:`${i}/${t}`}))}return a}return o==null?b(e,t,n):C(e)}function _(e,t,n){let r=n.registry.resolve(t);if(r)return r.decode(e,t,n);let i=t.$ref;if(typeof i==`string`)return _(e,n.resolve(i),n);let a=t.oneOf;if(Array.isArray(a))return _(e,ae(e,a,t,n),n);let o=t.type;if(o===`array`){if(!Array.isArray(e))return e;let r=t.items;if(!r)return e;let i=n.path;return Array.isArray(r)?e.map((e,t)=>{let a=r[t];return a===void 0?e:_(e,a,{...n,path:`${i}/${t}`})}):e.map((e,t)=>_(e,r,{...n,path:`${i}/${t}`}))}if(o===`object`){if(typeof e!=`object`||!e||Array.isArray(e))return e;let r=t.properties;if(!r)return e;let i=n.path,a={};for(let[t,o]of Object.entries(r)){let r=e[t];r!==void 0&&(a[t]=_(r,o,{...n,path:`${i}/${t}`}))}for(let[t,n]of Object.entries(e))!(t in r)&&n!==void 0&&(a[t]=n);return a}return o==null?S(e,n):e}function ae(e,t,n,r){let i=n.discriminator;if(i?.propertyName){let n=i.propertyName,a=typeof e==`object`&&e?e[n]:void 0;if(typeof a==`string`){if(i.mapping){let e=i.mapping[a];if(e){let n=t.find(t=>t.$ref===e);if(n)return n}}for(let e of t){let t=v(e,r).properties?.[n];if(!t)continue;let i=t.enum;if(t.const===a||Array.isArray(i)&&i.includes(a))return e}}}let a=se(e,t,r);if(a)return a;let o,s=-1;for(let n of t){let t=y(e,v(n,r),r);t!==null&&t>s&&(s=t,o=n)}return o===void 0?t[0]??{}:o}function v(e,t){let n=e.$ref;return typeof n==`string`?t.resolve(n):e}function oe(e){if(`const`in e)return e.const;let t=e.enum;if(Array.isArray(t)&&t.length===1)return t[0]}function se(e,t,n){if(typeof e!=`object`||!e||Array.isArray(e))return;let r=e,i=t.map(e=>v(e,n)),a=new Set;for(let e of i){let t=e.properties;if(t)for(let[e,n]of Object.entries(t))oe(n)!==void 0&&a.add(e)}for(let o of a){let a=i.map(e=>{let t=e.properties?.[o];return t?oe(t):void 0}),s=a.filter(e=>e!==void 0),c=new Set(s);if(s.length<2||c.size!==s.length)continue;let l=r[o];if(l===void 0)continue;let u=a.findIndex(e=>e===l);if(u!==-1&&y(e,i[u],n)!==null)return t[u]}}function ce(e){if(e===null)return`null`;if(Array.isArray(e))return`array`;let t=typeof e;return t===`number`?Number.isInteger(e)?`integer`:`number`:t}function y(e,t,n){let r=t.oneOf;if(Array.isArray(r)){let t=null;for(let i of r){let r=y(e,v(i,n),n);r!==null&&(t===null||r>t)&&(t=r)}return t}let i=t.type,a=ce(e);if(typeof i==`string`){if(!(i===a||i===`number`&&a===`integer`))return null}else if(Array.isArray(i)&&!i.some(e=>e===a||e===`number`&&a===`integer`))return null;if(typeof e!=`object`||!e||Array.isArray(e))return+(typeof i==`string`);let o=e,s=t.required,c=0;if(Array.isArray(s)){for(let e of s)if(typeof e==`string`){if(o[e]===void 0)return null;c+=2}}let l=t.properties;if(l){for(let e of Object.keys(l))o[e]!==void 0&&(c+=1);for(let e of Object.keys(o))l[e]===void 0&&--c}return c}function b(e,t,n){for(let t of n.registry.ids()){let r=n.registry.get(t);if(r?.ownsValue?.(e))return{[f]:t,v:r.encode(e,r.schema,n)}}if(Array.isArray(e))return e.map(e=>b(e,{},n));if(x(e)){let t={};for(let[r,i]of Object.entries(e))i!==void 0&&(t[r]=b(i,{},n));return t}return C(e)}function x(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function S(e,t){if(typeof e==`object`&&e&&!Array.isArray(e)&&`$apigen`in e){let n=e,r=n[f],i=t.registry.get(r);if(i)return i.decode(n.v,i.schema,t)}if(Array.isArray(e))return e.map(e=>S(e,t));if(x(e)){let n={};for(let[r,i]of Object.entries(e))n[r]=S(i,t);return n}return e}function C(e){if(e===null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return e;if(Array.isArray(e))return e.map(C);if(typeof e==`object`){let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=C(r));return t}return null}function le(e,t){let n=new Set,r=[e];for(;r.length>0;){let e=r.pop();if(!e||n.has(e))continue;n.add(e);let i=e.$ref;if(typeof i==`string`){if(t){let e=t[i];if(!e){let e=Object.keys(t).join(`, `)||`(none)`;throw Error(`[apigen-logical] $ref "${i}" cannot be resolved. Available $defs: ${e}`)}r.push(e)}continue}let a=e.oneOf;if(Array.isArray(a))for(let e of a)typeof e==`object`&&e&&r.push(e);let o=e.properties;if(o)for(let e of Object.values(o))r.push(e);let s=e.items;if(Array.isArray(s))for(let e of s)typeof e==`object`&&e&&r.push(e);else typeof s==`object`&&s&&r.push(s);let c=e.additionalProperties;typeof c==`object`&&c&&r.push(c);let l=e.propertyNames;typeof l==`object`&&l&&r.push(l)}}function ue(e){return{encode(t,n,r){return g(t,n,ie(e,r))},decode(t,n,r){return _(t,n,ie(e,r))}}}var w={id:`date-time`,kind:`scalar`,schema:{type:`string`,format:`date-time`},matches(e){return e.type===`string`&&e.format===`date-time`},ownsValue(e){return e instanceof Date},encode(e,t,n){return e.toISOString()},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[date-time] expected a string on the wire at "${n.path}", got ${typeof e}`);return new Date(String(e))}if(n.mode===`strict`&&Number.isNaN(new Date(e).getTime()))throw TypeError(`[date-time] invalid date-time string at "${n.path}": ${JSON.stringify(e)}`);return new Date(e)}},T={id:`int64`,kind:`scalar`,schema:{type:`string`,format:`int64`},matches(e){return e.type===`string`&&e.format===`int64`},ownsValue(e){return typeof e==`bigint`},encode(e,t,n){return String(e)},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[int64] expected a string on the wire at "${n.path}", got ${typeof e}`);try{return BigInt(Math.trunc(Number(e)))}catch{return BigInt(0)}}if(n.mode===`strict`)return BigInt(e);if(/^-?\d+$/.test(e))try{return BigInt(e)}catch{return BigInt(0)}return BigInt(0)}};function de(e){return e}var E={id:`decimal`,kind:`scalar`,schema:{type:`string`,format:`decimal`},matches(e){return e.type===`string`&&e.format===`decimal`},encode(e,t,n){return e},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[decimal] expected a string on the wire at "${n.path}", got ${typeof e}`);return de(String(e))}if(n.mode===`strict`&&!/^-?\d+(\.\d+)?$/.test(e))throw TypeError(`[decimal] wire value "${e}" at "${n.path}" is not a valid decimal string`);return de(e)}},D={id:`byte`,kind:`scalar`,schema:{type:`string`,format:`byte`},matches(e){return e.type===`string`&&e.format===`byte`},ownsValue(e){return e instanceof Uint8Array},encode(e,t,n){return Buffer.from(e).toString(`base64`)},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[byte] expected a base64 string on the wire at "${n.path}", got ${typeof e}`);return new Uint8Array}if(n.mode===`strict`&&!/^[A-Za-z0-9+/]*={0,2}$/.test(e))throw TypeError(`[byte] wire value at "${n.path}" is not standard base64 (format:byte): "${e}"`);return new Uint8Array(Buffer.from(e,`base64`))}},fe=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,O={id:`uuid`,kind:`scalar`,schema:{type:`string`,format:`uuid`},matches(e){return e.type===`string`&&e.format===`uuid`},encode(e,t,n){return e.toLowerCase()},decode(e,t,n){if(typeof e!=`string`){if(n.mode===`strict`)throw TypeError(`[uuid] expected a string on the wire at "${n.path}", got ${typeof e}`);return String(e).toLowerCase()}if(n.mode===`strict`&&!fe.test(e))throw TypeError(`[uuid] wire value "${e}" at "${n.path}" is not a lowercase-hyphenated RFC 4122 UUID`);return e}},k=`NaN`,A=`Infinity`,j=`-Infinity`,pe=new Set([k,A,j]),M={id:`number-special`,kind:`scalar`,schema:{type:`number`},matches(e){return e.type===`number`&&e.format===void 0},ownsValue(e){return typeof e==`number`&&!Number.isFinite(e)},encode(e,t,n){return Number.isNaN(e)?k:e===1/0?A:e===-1/0?j:e},decode(e,t,n){if(typeof e==`number`)return e;if(typeof e==`string`){if(e===k)return NaN;if(e===A)return 1/0;if(e===j)return-1/0;let t=Number(e);if(!Number.isNaN(t))return t}if(n.mode===`strict`)throw TypeError(`[number-special] unrecognized wire value at "${n.path}": ${JSON.stringify(e)}. Expected a number or one of ${[...pe].join(`, `)}.`);return NaN}},me=[w,T,E,D,O,M];function he(e,t={}){for(let n of me)e.register(n,{override:t.override??!1})}var ge=12;function _e(e,t){let n=/^#\/(definitions|\$defs)\/(.+)$/.exec(e);if(!n)return;let[,r,i]=n;return(r===`$defs`?t.$defs:t.definitions)?.[decodeURIComponent(i)]}function ve(e){return Array.isArray(e)&&e.length>0?e[0]:void 0}function ye(e){if(Array.isArray(e.type))return e.type.find(e=>e!==`null`)??e.type[0];if(typeof e.type==`string`)return e.type;if(e.properties)return`object`}function be(e){switch(e.format){case`date-time`:return`1970-01-01T00:00:00.000Z`;case`date`:return`1970-01-01`;case`time`:return`00:00:00Z`;case`uuid`:return`00000000-0000-0000-0000-000000000000`;case`email`:return`user@example.com`;case`uri`:case`url`:case`uri-reference`:return`https://example.com`;case`hostname`:return`example.com`;case`ipv4`:return`127.0.0.1`;case`ipv6`:return`::1`;case`decimal`:return`0`;case`int64`:return`0`;case`byte`:return``;default:return`<string>`}}function xe(e,t,n){let r=e.properties??{},i=e.required??[],a={};for(let e of i){let i=r[e];a[e]=i===void 0?`<${e}>`:N(i,t,n+1)}return a}function Se(e,t,n){let r=Array.isArray(e.items)?e.items[0]:e.items;return r?[N(r,t,n+1)]:[]}function N(e,t=e??{},n=0){if(!e||n>ge)return null;if(typeof e.$ref==`string`){let r=_e(e.$ref,t);return r===void 0?null:N(r,t,n+1)}if(e.const!==void 0)return e.const;if(Array.isArray(e.enum)&&e.enum.length>0)return e.enum[0];if(Array.isArray(e.allOf)&&e.allOf.length>0){let r={},i=[];for(let t of e.allOf){Object.assign(r,t.properties??{});for(let e of t.required??[])i.includes(e)||i.push(e)}return xe({...e,properties:r,required:i},t,n)}let r=ve(e.oneOf)??ve(e.anyOf);if(r)return N(r,t,n+1);switch(ye(e)){case`object`:return xe(e,t,n);case`array`:return Se(e,t,n);case`string`:return be(e);case`integer`:case`number`:return 0;case`boolean`:return!1;case`null`:return null;default:return null}}function Ce(e){if(!e)return;let t=N(e);return`Example: ${JSON.stringify(t)}`}w.id,T.id,E.id,D.id,O.id,M.id,Object.freeze({typescript:{"date-time":{encode:`$.toISOString()`,decode:`new Date($)`,mode:`native`},int64:{encode:`String($)`,decode:`BigInt($)`,mode:`native`},decimal:{encode:`$.toString()`,decode:`new Decimal($)`,imports:[],dep:{name:`decimal.js`,version:`^10`},mode:`branded`},byte:{encode:`Buffer.from($).toString('base64')`,decode:`new Uint8Array(Buffer.from($, 'base64'))`,mode:`native`},uuid:{encode:`$.toLowerCase()`,decode:`$`,mode:`native`},"number-special":{encode:`numToWire($)`,decode:`wireToNum($)`,mode:`native`}},python:{"date-time":{encode:`$.isoformat()`,decode:`datetime.fromisoformat($)`,imports:[`from datetime import datetime`],mode:`native`},int64:{encode:`str($)`,decode:`int($)`,mode:`native`},decimal:{encode:`str($)`,decode:`Decimal($)`,imports:[`from decimal import Decimal`],mode:`native`},byte:{encode:`b64encode($).decode()`,decode:`b64decode($)`,imports:[`from base64 import b64encode, b64decode`],mode:`native`},uuid:{encode:`str($)`,decode:`UUID($)`,imports:[`from uuid import UUID`],mode:`native`},"number-special":{encode:`num_to_wire($)`,decode:`wire_to_num($)`,mode:`native`}},rust:{"date-time":{encode:`__SCAFFOLD_RUST_DATETIME_ENCODE__`,decode:`__SCAFFOLD_RUST_DATETIME_DECODE__`,imports:[`use chrono::{DateTime, Utc};`],dep:{name:`chrono`,version:`^0.4`},mode:`lib`},int64:{encode:`__SCAFFOLD_RUST_INT64_ENCODE__`,decode:`__SCAFFOLD_RUST_INT64_DECODE__`,imports:[`use serde_with::DisplayFromStr;`],dep:{name:`serde_with`,version:`^3`},mode:`lib`},decimal:{encode:`__SCAFFOLD_RUST_DECIMAL_ENCODE__`,decode:`__SCAFFOLD_RUST_DECIMAL_DECODE__`,imports:[`use rust_decimal::Decimal;`],dep:{name:`rust_decimal`,version:`^1`},mode:`lib`},byte:{encode:`__SCAFFOLD_RUST_BYTE_ENCODE__`,decode:`__SCAFFOLD_RUST_BYTE_DECODE__`,imports:[`use serde_with::base64::Base64;`],dep:{name:`serde_with`,version:`^3`},mode:`lib`},uuid:{encode:`__SCAFFOLD_RUST_UUID_ENCODE__`,decode:`__SCAFFOLD_RUST_UUID_DECODE__`,imports:[`use uuid::Uuid;`],dep:{name:`uuid`,version:`^1`},mode:`lib`},"number-special":{encode:`__SCAFFOLD_RUST_NUMSPECIAL_ENCODE__`,decode:`__SCAFFOLD_RUST_NUMSPECIAL_DECODE__`,mode:`native`}},go:{"date-time":{encode:`__SCAFFOLD_GO_DATETIME_ENCODE__`,decode:`__SCAFFOLD_GO_DATETIME_DECODE__`,imports:[`"time"`],mode:`native`},int64:{encode:`__SCAFFOLD_GO_INT64_ENCODE__`,decode:`__SCAFFOLD_GO_INT64_DECODE__`,imports:[`"strconv"`],mode:`native`},decimal:{encode:`__SCAFFOLD_GO_DECIMAL_ENCODE__`,decode:`__SCAFFOLD_GO_DECIMAL_DECODE__`,imports:[`"github.com/shopspring/decimal"`],dep:{name:`github.com/shopspring/decimal`,version:`v1`},mode:`lib`},byte:{encode:`__SCAFFOLD_GO_BYTE_ENCODE__`,decode:`__SCAFFOLD_GO_BYTE_DECODE__`,imports:[`"encoding/base64"`],mode:`native`},uuid:{encode:`__SCAFFOLD_GO_UUID_ENCODE__`,decode:`__SCAFFOLD_GO_UUID_DECODE__`,imports:[`"github.com/google/uuid"`],dep:{name:`github.com/google/uuid`,version:`v1`},mode:`lib`},"number-special":{encode:`__SCAFFOLD_GO_NUMSPECIAL_ENCODE__`,decode:`__SCAFFOLD_GO_NUMSPECIAL_DECODE__`,mode:`native`}},java:{"date-time":{encode:`$.toString()`,decode:`Instant.parse($)`,imports:[`import java.time.Instant;`],dep:{name:`jackson-datatype-jsr310`,version:`2.x`},mode:`lib`},int64:{encode:`@JsonFormat(shape = JsonFormat.Shape.STRING)`,decode:`@JsonFormat(shape = JsonFormat.Shape.STRING)`,imports:[`import com.fasterxml.jackson.annotation.JsonFormat;`],mode:`native`},decimal:{encode:`@JsonSerialize(using = ToStringSerializer.class)`,decode:`new BigDecimal($)`,imports:[`import java.math.BigDecimal;`,`import com.fasterxml.jackson.databind.annotation.JsonSerialize;`,`import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;`],mode:`native`},byte:{encode:`$`,decode:`$`,mode:`native`},uuid:{encode:`$.toString()`,decode:`UUID.fromString($)`,imports:[`import java.util.UUID;`],mode:`native`},"number-special":{encode:`@JsonSerialize(using = NumberSpecialSerializer.class)`,decode:`@JsonDeserialize(using = NumberSpecialDeserializer.class)`,imports:[`import com.fasterxml.jackson.databind.annotation.JsonSerialize;`,`import com.fasterxml.jackson.databind.annotation.JsonDeserialize;`],mode:`native`}}});var we=m();he(we);var Te=ue(we.freeze());function Ee(e,t){return t in(e.input?.properties??{})}function De(e){let t=e.input?.properties?.data;return Object.keys(t?.properties??{})}function Oe(e,t){let n=e.input?.properties?.data?.properties?.[t];return n===void 0?void 0:n}function ke(e,t){return t===void 0||e===void 0?e:Te.decode(e,t)}function P(e,t){let n=t.output;return!n||Object.keys(n).length===0?e:Te.encode(e,n)}async function Ae(e,t,n,r,i,a){let o=De(n).map(e=>ke(a[e],Oe(n,e)));if(Ee(n,`session`)&&t){let a=await t({session:i.session});return P(await e[r](a,...o),n)}if(n.hasCtx){let a=t?await t(i):void 0;return P(await e[r](a,...o),n)}return P(await e[r](...o),n)}var je=class{constructor(){this._map=new Map}set(e,t){this._map.set(e,t)}get(e){return this._map.get(e)}has(e){return this._map.has(e)}};function Me(e=[]){return async function(t,n,r){let i=r.schemas[t];if(!i)throw Error(`apigen/invoke: no schema found for operation "${t}"`);return e.reduceRight((e,t)=>()=>t(n,e),()=>Ae(r.fns,r.createClient,i,t,n.envelope,n.domainArgs))()}}function Ne(e){return e}var F=class{constructor(){this.handlers=new Map}on(e,t){let n=this.handlers.get(e)??[];return this.handlers.set(e,[...n,t]),()=>this.off(e,t)}off(e,t){let n=this.handlers.get(e);if(!n)return;let r=n.filter(e=>e!==t);r.length===0?this.handlers.delete(e):this.handlers.set(e,r)}clear(){this.handlers.clear()}async emit(e){for(let[t,n]of this.handlers)if(Pe(t,e))for(let t of n)await t(e)}};function Pe(e,t){let[n,r,i]=e.split(`:`);return!(n!==`*`&&n!==t.module||r&&r!==`*`&&r!==t.method||i&&i!==`*`&&i!==t.lifecycle)}function I(e,t){for(let n of e)if(n.eventMapping)for(let[e,r]of Object.entries(n.eventMapping))t.on(e,r)}async function L(e,t,n){let r={...t};for(let t of e)if(t.createContext){await n.emit({module:t.id,method:`createContext`,lifecycle:`start`,ctx:r});try{let e=await t.createContext(r);r={...r,...e},await n.emit({module:t.id,method:`createContext`,lifecycle:`complete`,ctx:r})}catch(e){throw await n.emit({module:t.id,method:`createContext`,lifecycle:`error`,ctx:r,error:e}),e}}return r}(0,c.createRequire)(require("node:url").pathToFileURL(__filename).href);var R=new Set([`string`,`number`,`boolean`,`integer`]);function Fe(e){if(!Array.isArray(e)||e.length<2)return!1;let t=0;for(let n of e){if(typeof n!=`object`||!n)return!1;let{type:e,$ref:r,oneOf:i,anyOf:a,allOf:o}=n;if(r!==void 0||i||a||o)return!1;if(e!==`null`){if(typeof e==`string`&&R.has(e)){t++;continue}return!1}}return t===1}function Ie(e){if(typeof e!=`object`||!e)return!1;let t=e;if(t.$ref!==void 0||t.allOf)return!1;if(t.oneOf||t.anyOf)return Fe(t.oneOf??t.anyOf);let{type:n}=t;return typeof n==`string`?R.has(n):Array.isArray(n)?n.every(e=>R.has(e)||e===`null`):Array.isArray(t.enum)&&t.enum.length>0?t.enum.every(e=>[`string`,`number`,`boolean`].includes(typeof e)):!1}function z(e){if(!e||typeof e!=`object`)return!1;let t=e.properties;return t===void 0||typeof t!=`object`||!t?!1:Object.values(t).every(Ie)}function Le(e){let t={},n=e=>{for(let n of[`definitions`,`$defs`]){let r=e[n];if(r)for(let[e,i]of Object.entries(r)){let r=e.startsWith(`#/`)?e:`#/${n}/${e}`;t[r]=i}}};for(let t of Object.values(e.schemas))n(t.input),n(t.output);if(Object.keys(t).length!==0)for(let[n,r]of Object.entries(e.schemas))try{le(r.input,t),le(r.output,t)}catch(e){throw Error(`[apigen-core-client] Schema validation failed for function "${n}": ${e.message}`)}}function Re(e,t){let n=[`apigen calling convention: all domain parameters go inside a "data" envelope β€” e.g. { "data": { ... } }`+(t?`.`:` (an empty object for this zero-parameter tool).`)];return e.length>0&&n.push(`Field(s) ${e.map(e=>`"${e}"`).join(`, `)} are transport-level envelope metadata, NOT domain data β€” do not nest them under "data". Over MCP they are read from arguments._meta["x-<pluginId>-<field>"] (default pluginId "adhd"); see @adhd/apigen-engine-naming's envelopeMetaKey/envelopeCliFlag/envelopeEnvVar for the HTTP-header / CLI-flag / env-var equivalents.`),n.join(` `)}function ze(e,t,n){Le(e);let r={};for(let[i,a]of Object.entries(e.schemas)){let e=n?.[i]??{},o=a.input.properties??{},s=a.input.required??[],c={},l=[],u={};for(let n of t)if(n.envelope&&e[n.id]!==!1)for(let[e,t]of Object.entries(n.envelope))c[e]=t,u[e]=n.id,l.includes(e)||l.push(e);let d={type:`object`,properties:o,additionalProperties:!1,...s.length>0?{required:s}:{}},f=a.safe===!0||z(a.input),p=a.input.definitions,m=a.input.$defs;r[i]={input:{type:`object`,properties:{...c,data:d},required:[...l,...s.length>0?[`data`]:[]],additionalProperties:!1,description:Re(Object.keys(c),Object.keys(o).length>0),...p?{definitions:p}:{},...m?{$defs:m}:{}},output:a.output,...a.hasCtx?{hasCtx:!0}:{},"x-apigen-safe":f,...Object.keys(u).length>0?{"x-apigen-envelope":u}:{}}}return r}var Be={"decimal.js":`Decimal`};function Ve(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}Object.entries(Be).map(([e,t])=>({pattern:RegExp(`import\\(["'][^"']*${Ve(e)}[^"']*["']\\)\\.\\w+`,`g`),key:t}));var B=class extends Error{constructor(e){super(e),this.name=`ConfigurationError`}};function He(e){for(let t of e)for(let e of Object.keys(t.eventMapping??{})){let[n]=e.split(`:`);if(n!==`*`&&n===t.id)throw new B(`Middleware "${t.id}" subscribes to its own events via "${e}". This would cause infinite recursion.`)}}function Ue(e){let{domainSchemas:t,middlewares:n,overrides:r={},strict:i=!1}=e;He(n);for(let e of Object.keys(r))if(!(e in t.schemas)){let t=`Override key "${e}" not found in domain schemas.`;if(i)throw new B(t);console.warn(`[apigen-runtime]`,t)}let a=new Set(n.map(e=>e.id));for(let[e,t]of Object.entries(r))for(let n of Object.keys(t??{}))if(!a.has(n)){let t=`Override key "${e}.${n}" does not match any declared middleware id.`;if(i)throw new B(t);console.warn(`[apigen-runtime]`,t)}let o=ze(t,n,r),s=new F;return I(n,s),{schemas:o,createClient:async e=>L(n,e,s),dispose:()=>s.clear()}}function We(e={}){let t=e.level??`info`,n=typeof e.destination==`string`&&e.destination.length>0,r=!n&&!!process.stderr.isTTY,i=e.format??(r?`pretty`:`json`),a={level:t};if(i===`pretty`)return a.transport={target:`pino-pretty`,options:{colorize:!n,translateTime:`SYS:HH:MM:ss.l`,ignore:`pid,hostname`,...n?{destination:e.destination,mkdir:!0}:{destination:2}}},(0,l.default)(a);let o=n?l.default.destination({dest:e.destination,mkdir:!0,sync:!0}):l.default.destination(2);return(0,l.default)(a,o)}function Ge(e){if(e?.type!==`object`||!e.properties)return;let t=Object.entries(e.properties);if(t.length===0)return;let n=new Set(e.required??[]);return`{ ${t.map(([e,t])=>`${e}${n.has(e)?``:`?`}: ${V(t)}`).join(`, `)} }`}function Ke(e){return typeof e==`string`?`'${e}'`:JSON.stringify(e)}function qe(e){let t=e.enum??[];return t.length===0?`unknown`:t.map(Ke).join(`|`)}function Je(e,t){return e.map(e=>V(e,t)).join(` | `)}function V(e,t=0){if(!e)return`unknown`;if(e.type===`array`)return`${V(e.items,0)}[]`;if(e.enum)return qe(e);if(e.$ref)return String(e.$ref).split(`/`).pop()||`object`;let n=e.anyOf??e.oneOf;return n?n.length===0?`unknown`:t>=2?Je(n,t-1):`union`:t>=1&&e.type===`object`?Ge(e)??`object`:e.type??`object`}function Ye(e){let t=(e?.input??{}).properties?.data,n=t?.properties??{},r=new Set(t?.required??[]),i=Object.entries(n).map(([e,t])=>({name:e,type:V(t,2),required:r.has(e)}));return{params:i,text:i.map(e=>`${e.name}${e.required?``:`?`}: ${e.type}`).join(`, `)}}function Xe(e){let t;return t=Array.isArray(e)?e:e?[e]:[],t.find(e=>e===`number`||e===`integer`||e===`boolean`)}function Ze(e,t){let n=(t?.input??{}).properties?.data?.properties??{},r={...e};for(let[e,t]of Object.entries(n)){let n=r[e];if(typeof n!=`string`)continue;let i=Xe(t?.type);if(i===`number`||i===`integer`){let t=Number(n);!Number.isNaN(t)&&n.trim()!==``&&(r[e]=t)}else i===`boolean`&&(n===`true`?r[e]=!0:n===`false`&&(r[e]=!1))}return r}var Qe=new Set([`default`,`module.exports`,`__esModule`]);function $e(e){let t={},n=(e,r)=>{for(let[i,a]of Object.entries(e))if(typeof a==`function`){!Qe.has(i)&&!(i in t)&&(t[i]=a);let e=a.name;e&&!(e in t)&&(t[e]=a)}else a&&typeof a==`object`&&r<2&&Qe.has(i)&&n(a,r+1)};return n(e,0),t}var et=[`invalid_argument`,`unauthenticated`,`permission_denied`,`not_found`,`internal`],H=class extends Error{constructor(e,t,n){super(t),this.name=`ApiError`,this.code=e,this.details=n,Object.setPrototypeOf(this,new.target.prototype)}toJSON(){let e={code:this.code,message:this.message};return this.details!==void 0&&(e.details=this.details),e}};function tt(e){return typeof e==`object`&&!!e&&e.name===`ApiError`&&et.includes(e.code)&&typeof e.toJSON==`function`}function nt(e,t,n=0){return e===`before-first-chunk`?{phase:e,error:t}:{phase:e,error:t,chunksDelivered:n}}var U=new u.default({allErrors:!0,verbose:!0});(0,d.default)(U);for(let e of[ee,h,te,ne,`discriminator`])U.addKeyword({keyword:e,valid:!0});U.addFormat(`decimal`,/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)$/);function rt(e){return e?e.replace(/^\//,``).split(`/`).map(e=>e.replace(/~1/g,`/`).replace(/~0/g,`~`)).join(`.`):`(root)`}function it(e){let t=e?.properties;return t?Object.keys(t):[]}function at(e,t){let n=e.length,r=t.length;if(n===0)return r;if(r===0)return n;let i=Array.from({length:r+1},(e,t)=>t);for(let a=1;a<=n;a++){let n=[a];for(let o=1;o<=r;o++){let r=e[a-1]===t[o-1]?0:1;n[o]=Math.min(i[o]+1,n[o-1]+1,i[o-1]+r)}i=n}return i[r]}function ot(e,t){let n,r=1/0;for(let i of t){let t=at(e.toLowerCase(),i.toLowerCase());t<r&&(r=t,n=i)}let i=Math.max(2,Math.floor(e.length/3));return n!==void 0&&r<=i?n:void 0}function st(e){return e===null?`null`:Array.isArray(e)?`array`:typeof e}function ct(e){let t=rt(e.instancePath),n=e.params??{};switch(e.keyword){case`additionalProperties`:{let r=String(n.additionalProperty??`?`),i=it(e.parentSchema),a=ot(r,i);return`unknown key '${r}' at ${t}${i.length?`; allowed keys: ${i.join(`, `)}`:``}${a?` (did you mean '${a}'?)`:``}`}case`required`:{let r=String(n.missingProperty??`?`),i=it(e.parentSchema);return`missing required key '${r}' at ${t}${i.length?`; allowed keys: ${i.join(`, `)}`:``}`}case`enum`:{let r=Array.isArray(n.allowedValues)?n.allowedValues:[],i=e.data;return`value ${JSON.stringify(i)} at ${t} is not one of: ${r.map(e=>JSON.stringify(e)).join(`, `)}`}case`type`:{let r=e.data;return`${t} must be ${String(n.type)} (got ${st(r)})`}default:return`${t} ${e.message??`failed schema check`}`}}var W=12;function lt(e){let t=e.slice(0,W).map(ct);return e.length>W&&t.push(`…and ${e.length-W} more`),t.join(`; `)}function G(e){return e===null?!1:Array.isArray(e)?e.some(G):typeof e!=`object`||Object.values(e).some(G)}function ut(e,t){let n=[`Validation failed: ${lt(e)}`],r=N(t);return G(r)&&n.push(`Example: ${JSON.stringify(r)}`),n.join(` β€” `)}var dt=async(e,t)=>{let n=e.ctx.get(ft);if(n===void 0)return t();let r=n[e.operation.id];if(r===void 0)return t();let i={data:e.domainArgs,...e.envelope},a=U.compile(r.input);if(!a(i)){let e=a.errors??[];throw new H(`invalid_argument`,ut(e,r.input),e)}return t()},ft=Symbol(`ValidateSchemasToken`);function pt(e){return async function(t,n){let r=e[t.operation.id];if(r===void 0)return n();let i={data:t.domainArgs,...t.envelope},a=U.compile(r.input);if(!a(i)){let e=a.errors??[];throw new H(`invalid_argument`,ut(e,r.input),e)}return n()}}function mt(){return`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e===`x`?t:t&3|8).toString(16)})}var ht=class{constructor(e={}){this._store=new Map,this._sweeper=null,this._defaultTtlMs=e.defaultTtlMs;let t=null;t=e.sweepIntervalMs===0?null:e.sweepIntervalMs===void 0?this._defaultTtlMs===void 0?null:Math.max(1e3,Math.floor(this._defaultTtlMs/4)):e.sweepIntervalMs,t!==null&&t>0&&(this._sweeper=setInterval(()=>this._sweep(),t),this._sweeper.unref?.())}create(e,t=[],n){let r=new e(...t),i=mt(),a=n??this._defaultTtlMs,o=a===void 0?null:Date.now()+a;return this._store.set(i,{instance:r,expiresAt:o}),{instanceId:i}}get(e){let t=this._store.get(e);if(!t)throw Error(`[instance-registry] Unknown instanceId: "${e}"`);if(t.expiresAt!==null&&Date.now()>t.expiresAt)throw this._evict(e,t),Error(`[instance-registry] Instance "${e}" has expired`);return t.instance}async dispatch(e,t,n=[]){let r=this.get(e),i=r[t];if(typeof i!=`function`)throw Error(`[instance-registry] Method "${t}" not found on instance "${e}"`);return i.call(r,...n)}async dispose(e){let t=this._store.get(e);t&&(this._store.delete(e),await K(t.instance))}async disposeAll(){this._sweeper!==null&&(clearInterval(this._sweeper),this._sweeper=null);let e=[...this._store.entries()];this._store.clear(),await Promise.all(e.map(([,e])=>K(e.instance)))}get size(){return this._store.size}_sweep(){let e=Date.now();for(let[t,n]of this._store)n.expiresAt!==null&&e>n.expiresAt&&this._evict(t,n)}_evict(e,t){this._store.delete(e),K(t.instance)}};async function K(e){if(typeof e==`object`&&e&&`dispose`in e){let t=e.dispose;typeof t==`function`&&await t.call(e)}}function gt(e){let{produce:t,signal:n}=e,r=n??new AbortController().signal;return{[Symbol.asyncIterator](){let e=t(r);return{async next(){return r.aborted?(await e.return(void 0),{done:!0,value:void 0}):e.next()},async return(t){return await e.return(t),{done:!0,value:void 0}},async throw(t){return await e.throw(t),{done:!0,value:void 0}}}}}}async function _t(e){let t=[];for await(let n of e)t.push(n);return t}async function vt(e){let t=[];try{for await(let n of e)t.push(n);return{ok:!0,chunks:t}}catch(e){let n=tt(e)?e:new H(`internal`,e instanceof Error?e.message:String(e));return t.length===0?{ok:!1,carrier:nt(`before-first-chunk`,n)}:{ok:!1,carrier:nt(`after-first-chunk`,n,t.length)}}}function yt(e){return typeof e==`object`&&!!e&&Symbol.asyncIterator in e}var q=class extends Error{constructor(e,t){super(t),this.name=`UnionCodecError`,this.code=e}};function J(e){let t=e.discriminator;if(typeof t!=`object`||!t||Array.isArray(t))return;let n=t;if(typeof n.propertyName!=`string`)return;let r=n.mapping;if(typeof r==`object`&&r&&!Array.isArray(r))return{propertyName:n.propertyName,mapping:r}}function bt(e,t){let n=e[h];if(typeof n==`string`){let e=t.registry.get(n);if(e)return e}return t.registry.resolve(e)}function xt(e,t,n){let r=bt(t,n);return r?r.encode(e,t,n):e}function St(e,t,n){let r=bt(t,n);return r?r.decode(e,t,n):e}function Ct(e){let{id:t,schema:n}=e;return{id:t,kind:`union`,schema:n,matches(e){if(e[`x-apigen-logical`]===`union`)return!0;let t=e.oneOf;return!Array.isArray(t)||t.length===0?!1:J(e)!==void 0},encode(e,n,r){let i=J(n);if(!i)throw new q(`E_UNION_NO_DISCRIMINATOR`,`[${t}] schema node at "${r.path}" has no discriminator.propertyName; cannot dispatch union branch.`);let{propertyName:a,mapping:o}=i,s=e[a];if(s==null)throw new q(`E_UNION_NO_DISCRIMINATOR`,`[${t}] value at "${r.path}" is missing the discriminator property "${a}".`);let c=String(s),l=o[c];if(!l)throw new q(`E_UNION_UNKNOWN_TAG`,`[${t}] discriminator tag "${c}" at "${r.path}" is not in the mapping (known: ${Object.keys(o).join(`, `)}).`);return xt(e,r.resolve(l),{...r,path:`${r.path}[${c}]`})},decode(e,n,r){if(typeof e!=`object`||!e||Array.isArray(e)){let n;throw n=e===null?`null`:Array.isArray(e)?`array`:typeof e,new q(`E_UNION_INVALID_WIRE`,`[${t}] expected a JSON object on the wire at "${r.path}", got ${n}.`)}let i=e,a=J(n);if(!a)throw new q(`E_UNION_NO_DISCRIMINATOR`,`[${t}] schema node at "${r.path}" has no discriminator.propertyName; cannot dispatch union branch.`);let{propertyName:o,mapping:s}=a,c=i[o];if(c==null)throw new q(`E_UNION_NO_DISCRIMINATOR`,`[${t}] wire object at "${r.path}" is missing the discriminator property "${o}".`);let l=String(c),u=s[l];if(!u)throw new q(`E_UNION_UNKNOWN_TAG`,`[${t}] discriminator tag "${l}" on the wire at "${r.path}" is not in the mapping (known: ${Object.keys(s).join(`, `)}).`);return St(e,r.resolve(u),{...r,path:`${r.path}[${l}]`})}}}var Y=class extends Error{constructor(e,t){super(t),this.name=`NominalCodecError`,this.code=e}};function wt(e){let t=e.properties;return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}function Tt(e){let t=e.required;return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}function Et(e,t,n){if(t){let r=n.registry.resolve(t);if(r)return r.encode(e,t,n)}return e}function Dt(e,t,n){if(t){let r=n.registry.resolve(t);if(r)return r.decode(e,t,n)}return e}function Ot(e){let{id:t,schema:n,ctor:r}=e;return{id:t,kind:`nominal`,schema:n,matches(e){return e[`x-apigen-logical`]===`nominal`||e[h]===t},encode(e,n,r){if(typeof e!=`object`||!e)return e;if(r.seen.has(e)){if(r.mode===`strict`)throw new Y(`E_NOMINAL_CYCLE`,`[${t}] cycle detected at "${r.path}": a nominal instance references itself. Strict mode rejects cycles (DESIGN Β§8.3); break the cycle or use 'lossy' mode.`);return null}r.seen.add(e);try{let t=wt(n),i=e[typeof n[`x-apigen-tojson`]==`string`?n[ne]:`toJSON`];if(typeof i==`function`){let n=i.call(e);if(typeof n==`object`&&n&&!Array.isArray(n)){let e={};for(let[i,a]of Object.entries(n))e[i]=Et(a,t[i],{...r,path:`${r.path}/${i}`});return e}return n}let a={},o=Object.keys(t),s=e,c=o.length>0?o:Object.keys(s);for(let e of c){let n=s[e];n!==void 0&&(a[e]=Et(n,t[e],{...r,path:`${r.path}/${e}`}))}return a}finally{r.seen.delete(e)}},decode(e,n,i){if(typeof e!=`object`||!e||Array.isArray(e)){let n;throw n=e===null?`null`:Array.isArray(e)?`array`:typeof e,new Y(`E_NOMINAL_INVALID_WIRE`,`[${t}] expected a JSON object on the wire at "${i.path}", got ${n}.`)}let a=e;for(let e of Tt(n))if(!(e in a))throw new Y(`E_NOMINAL_INVALID_WIRE`,`[${t}] required field "${e}" missing on the wire at "${i.path}".`);if(n[`x-apigen-instances`]===!1)throw new Y(`E_NOMINAL_NONRECONSTRUCTABLE`,`[${t}] is encode-only: the extractor marked it non-reconstructable (x-apigen-instances:false). It cannot be decoded back to a live instance.`);let o=wt(n),s={};for(let[e,t]of Object.entries(a))s[e]=Dt(t,o[e],{...i,path:`${i.path}/${e}`});if(r){let e=typeof n[`x-apigen-ctor`]==`string`?n[te]:`fromJSON`,t=r[e];return typeof t==`function`?t.call(r,s):new r(s)}return s}}}var kt=[w,T,E,D,O,M],At=Ot({id:`ts.NominalSentinel`,schema:{type:`object`,"x-apigen-logical":`nominal`,"x-apigen-codec":`ts.NominalSentinel`}}),jt=Ct({id:`ts.UnionSentinel`,schema:{oneOf:[],discriminator:{propertyName:`kind`,mapping:{}},"x-apigen-logical":`union`,"x-apigen-codec":`ts.UnionSentinel`}});function Mt(){let e=[...kt.map(e=>[e.id,e]),[At.id,At],[jt.id,jt]];return Object.freeze(new Map(e))}var Nt=Object.freeze({host:`ts`,logicalTypeVersion:re,codecs:Mt()});function Pt(e,t,n){let r=[n,typeof t?.input?.description==`string`?t.input.description:void 0,Ce(t?.input)].filter(e=>typeof e==`string`&&e.length>0);return r.length>0?r.join(` β€” `):e}function Ft(e){if(!e||typeof e!=`object`||Array.isArray(e)||Object.keys(e).length===0)return{outputSchema:void 0,wrapped:!1};let t=e;return t.type===`object`?{outputSchema:t,wrapped:!0}:{outputSchema:void 0,wrapped:!1}}function It(e,t){if(e)return t&&typeof t==`object`&&!Array.isArray(t)?t:void 0}var Lt=4,Rt=32;function X(e){return tt(e)?e:e instanceof Error?new H(`internal`,e.message):e}function zt(e,t){if(e===`serial`||e===`chained`)return 1;let n=t??4;return!Number.isFinite(n)||n<1?1:Math.min(Math.floor(n),32)}function Bt(){}function Vt(e,t){if(!e&&!t)return{signal:void 0,dispose:Bt};let n=new AbortController,r=()=>{n.abort(e?.reason)};e&&(e.aborted?n.abort(e.reason):e.addEventListener(`abort`,r,{once:!0}));let i;return t!==void 0&&!n.signal.aborted&&(i=setTimeout(()=>{n.abort(new DOMException(`apigen/invokeBatch: item timed out after ${t}ms`,`TimeoutError`))},t),i.unref?.()),{signal:n.signal,dispose(){e&&e.removeEventListener(`abort`,r),i&&clearTimeout(i)}}}async function Z(e,t,n,r,i,a){let o=Vt(r.signal,a);try{let a=await e(t,o.signal?{...r,signal:o.signal}:r,i);if(yt(a)){let e=await vt(a);if(!e.ok){let t=e.carrier;return{index:n,status:`rejected`,reason:X(t.error),...t.phase===`after-first-chunk`?{chunksDelivered:t.chunksDelivered}:{}}}return{index:n,status:`fulfilled`,chunks:e.chunks}}return{index:n,status:`fulfilled`,value:a}}catch(e){return{index:n,status:`rejected`,reason:X(e)}}finally{o.dispose()}}async function Ht(e,t,n,r,i={}){let a=i.mode??`parallel`,o=i.onItemError??`continue`,s=zt(a,i.concurrency),c=Array(n.length),l=e=>({index:e,status:`rejected`,reason:X(Error(`apigen/invokeBatch: not attempted β€” an earlier item failed and `+(a===`chained`?`mode is "chained"`:`onItemError is "abort"`)))});if(a===`serial`||a===`chained`){let s=!1;for(let u=0;u<n.length;u++){if(s){c[u]=l(u);continue}let d=await Z(e,t,u,n[u],r,i.itemTimeoutMs);c[u]=d,d.status===`rejected`&&(a===`chained`||o===`abort`)&&(s=!0)}return c}let u=0,d=!1,f=Math.max(1,Math.min(s,n.length)),p=Array.from({length:f},async()=>{for(;;){let a=u++;if(a>=n.length)return;if(d){c[a]=l(a);continue}let s=await Z(e,t,a,n[a],r,i.itemTimeoutMs);c[a]=s,s.status===`rejected`&&o===`abort`&&(d=!0)}});return await Promise.all(p),c}function Ut(e){return e.words.join(`-`)}function Wt(e){return e.words.map(Xt).join(``)}function Gt(e){return e.words.join(`_`)}function Kt(e,t={}){let n=[e.namespace,...e.path],r=e.safe||z(e.input)?`GET`:`POST`,i=t.http?.verb?.[e.id]??r,a=`/`+n.map(e=>Ut(e)).join(`/`),o=n.map(e=>Gt(e)).join(`_`),s=n.map(e=>Gt(e)).slice(0,-1).join(`.`),c=Wt(n[n.length-2]??n[0]),l=Wt(n[n.length-1]),u=n.map(e=>Ut(e));return{http:{verb:i,route:a},mcp:{name:o},grpc:{package:s,service:c,method:l},cli:{path:u}}}function qt(e,t){return`x-${e}-${t}`}function Jt(e,t){return`--${e}-${t}`}function Yt(e,t){let n=e=>e.toUpperCase().replace(/-/g,`_`);return e===`adhd`?`APIGEN_${n(t)}`:`APIGEN_${n(e)}_${n(t)}`}function Xt(e){return e.length===0?e:e[0].toUpperCase()+e.slice(1)}function Q(e){return e.anyOf??e.oneOf}function Zt(e){if(!e)return!1;if(e.type===`array`||e.type===`object`)return!0;let t=Q(e);if(t){let e=t.filter(e=>e.type!==`null`);return e.length>0&&e.every(e=>e.type===`array`||e.type===`object`)}return!1}function Qt(e){if(!e)return!1;if(e.type===`boolean`)return!0;let t=Q(e);if(t){let e=t.filter(e=>e.type!==`null`);return e.length>0&&e.every(e=>e.type===`boolean`)}return!1}function $t(e){if(!e)return!1;if(e.type===`number`||e.type===`integer`)return!0;let t=Q(e);if(t){let e=t.filter(e=>e.type!==`null`);return e.length>0&&e.every(e=>e.type===`number`||e.type===`integer`)}return!1}function en(e){return e.replace(/[A-Z]/g,e=>`-`+e.toLowerCase())}function tn(e){let t=e.input?.properties?.data;return{props:t?.properties??{},required:t?.required??[]}}function nn(e){return typeof e.handler==`function`}function rn(e){let t=e.input?.properties??{},n=e[`x-apigen-envelope`],r=[];for(let e of Object.keys(t)){if(e===`data`)continue;let t=n?.[e]??`adhd`,i=qt(t,e);r.push({field:e,pluginId:t,httpHeader:i,mcpMetaKey:i,cliFlag:Jt(t,e),envVar:Yt(t,e)})}return r}function an(e,t,n,r){t===n||e.has(t)||e.set(t,{...r,aliasOf:n})}function on(e,t){let n=new Map,{props:r}=tn(e);for(let[e,t]of Object.entries(r)){let r=`string`;Qt(t)?r=`boolean`:(Zt(t)||$t(t))&&(r=`json`);let i=en(e),a={camelKey:e,kind:`domain`,valueKind:r};n.set(i,a),an(n,e,i,a)}for(let e of t){let t=e.cliFlag.replace(/^--/,``),r={camelKey:e.field,kind:`envelope`,valueKind:`string`,envVar:e.envVar};n.set(t,r)}return n}function sn(e){let{op:t,schema:n,transport:r,projection:i}=e,a=Kt(t,i),o=n?rn(n):[],s=n?on(n,o):new Map,c=n?Ye(n).params:void 0,l={op:t,transport:r,http:a.http,mcp:a.mcp,cli:a.cli,grpc:a.grpc,params:c,envelope:o,cliFlags:s,streaming:t.streaming,isMount:nn(t)};if(nn(t)){let e=t.handler;l.mountHandler=async t=>e(t)}return l}function cn(e){let t=e.usePlugins;return Array.isArray(t)?t:[]}function ln(e){let t=e.exitCode;return typeof t==`function`?t:void 0}function un(e){let t=e.useOptions;return t&&typeof t==`object`?t:{}}function dn(e){return async function(t,n){let r=Object.assign(t,{data:t.domainArgs});return await e.layer(r,n)}}function fn(e,t){let n=[];for(let e of t){let t=e.capabilities?.layer;t&&n.push(dn(t))}return n.push(pt(e)),Me(n)}function pn(){let e=new Map;return{get:t=>e.get(t),set:(t,n)=>{e.set(t,n)}}}var mn={input:{type:`object`,properties:{data:{type:`object`,properties:{}}}},output:{}};async function hn(e,t,n,r){let i={...n,operation:{id:e.op.id},ctx:new je,transport:e.transport};if(e.isMount){let a=e.mountHandler;if(!a)throw Error(`apigen-engine-runtime/dispatchForPlan: OpPlan for mount op "${e.op.id}" has isMount=true but no mountHandler`);let o={operation:e.op,data:n.domainArgs,envelope:n.envelope,ctx:pn(),transport:e.transport,signal:n.signal??new AbortController().signal},s={...r,fns:{[e.op.id]:()=>a(o)},schemas:{[e.op.id]:mn}};return t(e.op.id,i,s)}return t(e.op.id,i,r)}var $=`127.0.0.1`;function gn(e){let t=e.trim().toLowerCase().replace(/^\[|\]$/g,``);if(t===`localhost`||t===`::1`)return!0;let n=t.startsWith(`::ffff:`)?t.slice(7):t;return/^127(\.\d{1,3}){3}$/.test(n)}function _n(e){if(typeof e!=`string`)return $;let t=e.trim();return t===``?$:t}function vn(e,t,n){return!gn(e)&&(n?.warn({host:e,host_kind:t},`${t} binding non-loopback host "${e}": the server will be reachable from the network. Omit the host option to bind ${$}.`),!0)}exports.BATCH_DEFAULT_CONCURRENCY=Lt,exports.BATCH_MAX_CONCURRENCY=Rt,exports.DEFAULT_LISTEN_HOST=$,exports.EventBus=F,exports.InstanceRegistry=ht,exports.LayerContext=je,exports.UnionCodecError=q,exports.ValidateSchemasToken=ft,exports.WELL_KNOWN_TS_CODECS=kt,exports.adaptCoreLayer=dn,exports.assertNoSelfSubscription=He,exports.buildContext=L,exports.buildFnTable=$e,exports.buildMcpOutputSchema=Ft,exports.buildOpPlan=sn,exports.buildToolDescription=Pt,exports.coerceQueryParams=Ze,exports.collectWithPhase=vt,exports.createApiPackage=Ue,exports.createInvoker=Me,exports.createLogger=We,exports.createPackageInvoker=fn,exports.createStream=gt,exports.createUnionCodec=Ct,exports.dataParamNames=De,exports.defineMiddleware=Ne,exports.describeParams=Ye,exports.dispatch=Ae,exports.dispatchForPlan=hn,exports.drainStream=_t,exports.invokeBatch=Ht,exports.isApiStream=yt,exports.isLoopbackListenHost=gn,exports.makeValidateLayer=pt,exports.needsEnvelopeField=Ee,exports.readExitCodeHook=ln,exports.readUseOptions=un,exports.readUsePlugins=cn,exports.resolveListenHost=_n,exports.tsHostBinding=Nt,exports.validateLayer=dt,exports.warnIfNonLoopbackListen=vn,exports.wireObservers=I,exports.wrapMcpStructuredContent=It;
package/index.mjs CHANGED
@@ -805,42 +805,42 @@ S.id, C.id, w.id, T.id, E.id, A.id, Object.freeze({
805
805
  });
806
806
  //#endregion
807
807
  //#region src/lib/dispatch.ts
808
- var _e = o();
809
- le(_e);
810
- var ve = ie(_e.freeze());
811
- function ye(e, t) {
808
+ var N = o();
809
+ le(N);
810
+ var _e = ie(N.freeze());
811
+ function ve(e, t) {
812
812
  return t in (e.input?.properties ?? {});
813
813
  }
814
- function be(e) {
814
+ function ye(e) {
815
815
  let t = e.input?.properties?.data;
816
816
  return Object.keys(t?.properties ?? {});
817
817
  }
818
- function xe(e, t) {
818
+ function be(e, t) {
819
819
  let n = e.input?.properties?.data?.properties?.[t];
820
820
  return n === void 0 ? void 0 : n;
821
821
  }
822
- function Se(e, t) {
823
- return t === void 0 || e === void 0 ? e : ve.decode(e, t);
822
+ function xe(e, t) {
823
+ return t === void 0 || e === void 0 ? e : _e.decode(e, t);
824
824
  }
825
- function N(e, t) {
825
+ function P(e, t) {
826
826
  let n = t.output;
827
- return !n || Object.keys(n).length === 0 ? e : ve.encode(e, n);
827
+ return !n || Object.keys(n).length === 0 ? e : _e.encode(e, n);
828
828
  }
829
- async function Ce(e, t, n, r, i, a) {
830
- let o = be(n).map((e) => Se(a[e], xe(n, e)));
831
- if (ye(n, "session") && t) {
829
+ async function Se(e, t, n, r, i, a) {
830
+ let o = ye(n).map((e) => xe(a[e], be(n, e)));
831
+ if (ve(n, "session") && t) {
832
832
  let a = await t({ session: i.session });
833
- return N(await e[r](a, ...o), n);
833
+ return P(await e[r](a, ...o), n);
834
834
  }
835
835
  if (n.hasCtx) {
836
836
  let a = t ? await t(i) : void 0;
837
- return N(await e[r](a, ...o), n);
837
+ return P(await e[r](a, ...o), n);
838
838
  }
839
- return N(await e[r](...o), n);
839
+ return P(await e[r](...o), n);
840
840
  }
841
841
  //#endregion
842
842
  //#region src/lib/invoke.ts
843
- var we = class {
843
+ var Ce = class {
844
844
  constructor() {
845
845
  this._map = /* @__PURE__ */ new Map();
846
846
  }
@@ -854,21 +854,21 @@ var we = class {
854
854
  return this._map.has(e);
855
855
  }
856
856
  };
857
- function Te(e = []) {
857
+ function we(e = []) {
858
858
  return async function(t, n, r) {
859
859
  let i = r.schemas[t];
860
860
  if (!i) throw Error(`apigen/invoke: no schema found for operation "${t}"`);
861
- return e.reduceRight((e, t) => () => t(n, e), () => Ce(r.fns, r.createClient, i, t, n.envelope, n.domainArgs))();
861
+ return e.reduceRight((e, t) => () => t(n, e), () => Se(r.fns, r.createClient, i, t, n.envelope, n.domainArgs))();
862
862
  };
863
863
  }
864
864
  //#endregion
865
865
  //#region src/lib/define-middleware.ts
866
- function Ee(e) {
866
+ function Te(e) {
867
867
  return e;
868
868
  }
869
869
  //#endregion
870
870
  //#region src/lib/event-bus.ts
871
- var De = class {
871
+ var Ee = class {
872
872
  constructor() {
873
873
  this.handlers = /* @__PURE__ */ new Map();
874
874
  }
@@ -886,19 +886,19 @@ var De = class {
886
886
  this.handlers.clear();
887
887
  }
888
888
  async emit(e) {
889
- for (let [t, n] of this.handlers) if (Oe(t, e)) for (let t of n) await t(e);
889
+ for (let [t, n] of this.handlers) if (De(t, e)) for (let t of n) await t(e);
890
890
  }
891
891
  };
892
- function Oe(e, t) {
892
+ function De(e, t) {
893
893
  let [n, r, i] = e.split(":");
894
894
  return !(n !== "*" && n !== t.module || r && r !== "*" && r !== t.method || i && i !== "*" && i !== t.lifecycle);
895
895
  }
896
- function ke(e, t) {
896
+ function Oe(e, t) {
897
897
  for (let n of e) if (n.eventMapping) for (let [e, r] of Object.entries(n.eventMapping)) t.on(e, r);
898
898
  }
899
899
  //#endregion
900
900
  //#region src/lib/build-context.ts
901
- async function P(e, t, n) {
901
+ async function ke(e, t, n) {
902
902
  let r = { ...t };
903
903
  for (let t of e) if (t.createContext) {
904
904
  await n.emit({
@@ -940,9 +940,27 @@ var F = /* @__PURE__ */ new Set([
940
940
  "integer"
941
941
  ]);
942
942
  function Ae(e) {
943
+ if (!Array.isArray(e) || e.length < 2) return !1;
944
+ let t = 0;
945
+ for (let n of e) {
946
+ if (typeof n != "object" || !n) return !1;
947
+ let { type: e, $ref: r, oneOf: i, anyOf: a, allOf: o } = n;
948
+ if (r !== void 0 || i || a || o) return !1;
949
+ if (e !== "null") {
950
+ if (typeof e == "string" && F.has(e)) {
951
+ t++;
952
+ continue;
953
+ }
954
+ return !1;
955
+ }
956
+ }
957
+ return t === 1;
958
+ }
959
+ function je(e) {
943
960
  if (typeof e != "object" || !e) return !1;
944
961
  let t = e;
945
- if (t.$ref !== void 0 || t.oneOf || t.anyOf || t.allOf) return !1;
962
+ if (t.$ref !== void 0 || t.allOf) return !1;
963
+ if (t.oneOf || t.anyOf) return Ae(t.oneOf ?? t.anyOf);
946
964
  let { type: n } = t;
947
965
  return typeof n == "string" ? F.has(n) : Array.isArray(n) ? n.every((e) => F.has(e) || e === "null") : Array.isArray(t.enum) && t.enum.length > 0 ? t.enum.every((e) => [
948
966
  "string",
@@ -953,11 +971,11 @@ function Ae(e) {
953
971
  function I(e) {
954
972
  if (!e || typeof e != "object") return !1;
955
973
  let t = e.properties;
956
- return t === void 0 || typeof t != "object" || !t ? !1 : Object.values(t).every(Ae);
974
+ return t === void 0 || typeof t != "object" || !t ? !1 : Object.values(t).every(je);
957
975
  }
958
976
  //#endregion
959
977
  //#region ../apigen-core-client/src/lib/compose-schemas.ts
960
- function je(e) {
978
+ function Me(e) {
961
979
  let t = {}, n = (e) => {
962
980
  for (let n of ["definitions", "$defs"]) {
963
981
  let r = e[n];
@@ -974,12 +992,12 @@ function je(e) {
974
992
  throw Error(`[apigen-core-client] Schema validation failed for function "${n}": ${e.message}`);
975
993
  }
976
994
  }
977
- function Me(e, t) {
995
+ function Ne(e, t) {
978
996
  let n = ["apigen calling convention: all domain parameters go inside a \"data\" envelope β€” e.g. { \"data\": { ... } }" + (t ? "." : " (an empty object for this zero-parameter tool).")];
979
997
  return e.length > 0 && n.push(`Field(s) ${e.map((e) => `"${e}"`).join(", ")} are transport-level envelope metadata, NOT domain data β€” do not nest them under "data". Over MCP they are read from arguments._meta["x-<pluginId>-<field>"] (default pluginId "adhd"); see @adhd/apigen-engine-naming's envelopeMetaKey/envelopeCliFlag/envelopeEnvVar for the HTTP-header / CLI-flag / env-var equivalents.`), n.join(" ");
980
998
  }
981
- function Ne(e, t, n) {
982
- je(e);
999
+ function Pe(e, t, n) {
1000
+ Me(e);
983
1001
  let r = {};
984
1002
  for (let [i, a] of Object.entries(e.schemas)) {
985
1003
  let e = n?.[i] ?? {}, o = a.input.properties ?? {}, s = a.input.required ?? [], c = {}, l = [], u = {};
@@ -999,7 +1017,7 @@ function Ne(e, t, n) {
999
1017
  },
1000
1018
  required: [...l, ...s.length > 0 ? ["data"] : []],
1001
1019
  additionalProperties: !1,
1002
- description: Me(Object.keys(c), Object.keys(o).length > 0),
1020
+ description: Ne(Object.keys(c), Object.keys(o).length > 0),
1003
1021
  ...p ? { definitions: p } : {},
1004
1022
  ...m ? { $defs: m } : {}
1005
1023
  },
@@ -1013,12 +1031,12 @@ function Ne(e, t, n) {
1013
1031
  }
1014
1032
  //#endregion
1015
1033
  //#region ../apigen-core-client/src/lib/schema-builders/ts-json-schema.ts
1016
- var Pe = { "decimal.js": "Decimal" };
1017
- function Fe(e) {
1034
+ var Fe = { "decimal.js": "Decimal" };
1035
+ function Ie(e) {
1018
1036
  return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1019
1037
  }
1020
- Object.entries(Pe).map(([e, t]) => ({
1021
- pattern: RegExp(`import\\(["'][^"']*${Fe(e)}[^"']*["']\\)\\.\\w+`, "g"),
1038
+ Object.entries(Fe).map(([e, t]) => ({
1039
+ pattern: RegExp(`import\\(["'][^"']*${Ie(e)}[^"']*["']\\)\\.\\w+`, "g"),
1022
1040
  key: t
1023
1041
  }));
1024
1042
  //#endregion
@@ -1036,7 +1054,7 @@ function R(e) {
1036
1054
  if (n !== "*" && n === t.id) throw new L(`Middleware "${t.id}" subscribes to its own events via "${e}". This would cause infinite recursion.`);
1037
1055
  }
1038
1056
  }
1039
- function Ie(e) {
1057
+ function Le(e) {
1040
1058
  let { domainSchemas: t, middlewares: n, overrides: r = {}, strict: i = !1 } = e;
1041
1059
  R(n);
1042
1060
  for (let e of Object.keys(r)) if (!(e in t.schemas)) {
@@ -1050,16 +1068,16 @@ function Ie(e) {
1050
1068
  if (i) throw new L(t);
1051
1069
  console.warn("[apigen-runtime]", t);
1052
1070
  }
1053
- let o = Ne(t, n, r), s = new De();
1054
- return ke(n, s), {
1071
+ let o = Pe(t, n, r), s = new Ee();
1072
+ return Oe(n, s), {
1055
1073
  schemas: o,
1056
- createClient: async (e) => P(n, e, s),
1074
+ createClient: async (e) => ke(n, e, s),
1057
1075
  dispose: () => s.clear()
1058
1076
  };
1059
1077
  }
1060
1078
  //#endregion
1061
1079
  //#region src/lib/logger.ts
1062
- function Le(e = {}) {
1080
+ function Re(e = {}) {
1063
1081
  let n = e.level ?? "info", r = typeof e.destination == "string" && e.destination.length > 0, i = !r && !!process.stderr.isTTY, a = e.format ?? (i ? "pretty" : "json"), o = { level: n };
1064
1082
  if (a === "pretty") return o.transport = {
1065
1083
  target: "pino-pretty",
@@ -1082,30 +1100,30 @@ function Le(e = {}) {
1082
1100
  }
1083
1101
  //#endregion
1084
1102
  //#region src/lib/describe-params.ts
1085
- function Re(e) {
1103
+ function ze(e) {
1086
1104
  if (e?.type !== "object" || !e.properties) return;
1087
1105
  let t = Object.entries(e.properties);
1088
1106
  if (t.length === 0) return;
1089
1107
  let n = new Set(e.required ?? []);
1090
1108
  return `{ ${t.map(([e, t]) => `${e}${n.has(e) ? "" : "?"}: ${z(t)}`).join(", ")} }`;
1091
1109
  }
1092
- function ze(e) {
1110
+ function Be(e) {
1093
1111
  return typeof e == "string" ? `'${e}'` : JSON.stringify(e);
1094
1112
  }
1095
- function Be(e) {
1113
+ function Ve(e) {
1096
1114
  let t = e.enum ?? [];
1097
- return t.length === 0 ? "unknown" : t.map(ze).join("|");
1115
+ return t.length === 0 ? "unknown" : t.map(Be).join("|");
1098
1116
  }
1099
- function Ve(e, t) {
1117
+ function He(e, t) {
1100
1118
  return e.map((e) => z(e, t)).join(" | ");
1101
1119
  }
1102
1120
  function z(e, t = 0) {
1103
1121
  if (!e) return "unknown";
1104
1122
  if (e.type === "array") return `${z(e.items, 0)}[]`;
1105
- if (e.enum) return Be(e);
1123
+ if (e.enum) return Ve(e);
1106
1124
  if (e.$ref) return String(e.$ref).split("/").pop() || "object";
1107
1125
  let n = e.anyOf ?? e.oneOf;
1108
- return n ? n.length === 0 ? "unknown" : t >= 2 ? Ve(n, t - 1) : "union" : t >= 1 && e.type === "object" ? Re(e) ?? "object" : e.type ?? "object";
1126
+ return n ? n.length === 0 ? "unknown" : t >= 2 ? He(n, t - 1) : "union" : t >= 1 && e.type === "object" ? ze(e) ?? "object" : e.type ?? "object";
1109
1127
  }
1110
1128
  function B(e) {
1111
1129
  let t = (e?.input ?? {}).properties?.data, n = t?.properties ?? {}, r = new Set(t?.required ?? []), i = Object.entries(n).map(([e, t]) => ({
@@ -1120,16 +1138,16 @@ function B(e) {
1120
1138
  }
1121
1139
  //#endregion
1122
1140
  //#region src/lib/coerce-query.ts
1123
- function He(e) {
1141
+ function Ue(e) {
1124
1142
  let t;
1125
1143
  return t = Array.isArray(e) ? e : e ? [e] : [], t.find((e) => e === "number" || e === "integer" || e === "boolean");
1126
1144
  }
1127
- function Ue(e, t) {
1145
+ function We(e, t) {
1128
1146
  let n = (t?.input ?? {}).properties?.data?.properties ?? {}, r = { ...e };
1129
1147
  for (let [e, t] of Object.entries(n)) {
1130
1148
  let n = r[e];
1131
1149
  if (typeof n != "string") continue;
1132
- let i = He(t?.type);
1150
+ let i = Ue(t?.type);
1133
1151
  if (i === "number" || i === "integer") {
1134
1152
  let t = Number(n);
1135
1153
  !Number.isNaN(t) && n.trim() !== "" && (r[e] = t);
@@ -1144,7 +1162,7 @@ var V = /* @__PURE__ */ new Set([
1144
1162
  "module.exports",
1145
1163
  "__esModule"
1146
1164
  ]);
1147
- function We(e) {
1165
+ function Ge(e) {
1148
1166
  let t = {}, n = (e, r) => {
1149
1167
  for (let [i, a] of Object.entries(e)) if (typeof a == "function") {
1150
1168
  !V.has(i) && !(i in t) && (t[i] = a);
@@ -1156,7 +1174,7 @@ function We(e) {
1156
1174
  }
1157
1175
  //#endregion
1158
1176
  //#region ../apigen-base-errors/src/lib/errors.ts
1159
- var Ge = [
1177
+ var Ke = [
1160
1178
  "invalid_argument",
1161
1179
  "unauthenticated",
1162
1180
  "permission_denied",
@@ -1174,10 +1192,10 @@ var Ge = [
1174
1192
  return this.details !== void 0 && (e.details = this.details), e;
1175
1193
  }
1176
1194
  };
1177
- function Ke(e) {
1178
- return typeof e == "object" && !!e && e.name === "ApiError" && Ge.includes(e.code) && typeof e.toJSON == "function";
1195
+ function qe(e) {
1196
+ return typeof e == "object" && !!e && e.name === "ApiError" && Ke.includes(e.code) && typeof e.toJSON == "function";
1179
1197
  }
1180
- function qe(e, t, n = 0) {
1198
+ function Je(e, t, n = 0) {
1181
1199
  return e === "before-first-chunk" ? {
1182
1200
  phase: e,
1183
1201
  error: t
@@ -1205,14 +1223,14 @@ for (let e of [
1205
1223
  valid: !0
1206
1224
  });
1207
1225
  U.addFormat("decimal", /^[+-]?(?:\d+(?:\.\d+)?|\.\d+)$/);
1208
- function Je(e) {
1226
+ function Ye(e) {
1209
1227
  return e ? e.replace(/^\//, "").split("/").map((e) => e.replace(/~1/g, "/").replace(/~0/g, "~")).join(".") : "(root)";
1210
1228
  }
1211
- function Ye(e) {
1229
+ function Xe(e) {
1212
1230
  let t = e?.properties;
1213
1231
  return t ? Object.keys(t) : [];
1214
1232
  }
1215
- function Xe(e, t) {
1233
+ function Ze(e, t) {
1216
1234
  let n = e.length, r = t.length;
1217
1235
  if (n === 0) return r;
1218
1236
  if (r === 0) return n;
@@ -1227,27 +1245,27 @@ function Xe(e, t) {
1227
1245
  }
1228
1246
  return i[r];
1229
1247
  }
1230
- function Ze(e, t) {
1248
+ function Qe(e, t) {
1231
1249
  let n, r = Infinity;
1232
1250
  for (let i of t) {
1233
- let t = Xe(e.toLowerCase(), i.toLowerCase());
1251
+ let t = Ze(e.toLowerCase(), i.toLowerCase());
1234
1252
  t < r && (r = t, n = i);
1235
1253
  }
1236
1254
  let i = Math.max(2, Math.floor(e.length / 3));
1237
1255
  return n !== void 0 && r <= i ? n : void 0;
1238
1256
  }
1239
- function Qe(e) {
1257
+ function $e(e) {
1240
1258
  return e === null ? "null" : Array.isArray(e) ? "array" : typeof e;
1241
1259
  }
1242
- function $e(e) {
1243
- let t = Je(e.instancePath), n = e.params ?? {};
1260
+ function et(e) {
1261
+ let t = Ye(e.instancePath), n = e.params ?? {};
1244
1262
  switch (e.keyword) {
1245
1263
  case "additionalProperties": {
1246
- let r = String(n.additionalProperty ?? "?"), i = Ye(e.parentSchema), a = Ze(r, i);
1264
+ let r = String(n.additionalProperty ?? "?"), i = Xe(e.parentSchema), a = Qe(r, i);
1247
1265
  return `unknown key '${r}' at ${t}${i.length ? `; allowed keys: ${i.join(", ")}` : ""}${a ? ` (did you mean '${a}'?)` : ""}`;
1248
1266
  }
1249
1267
  case "required": {
1250
- let r = String(n.missingProperty ?? "?"), i = Ye(e.parentSchema);
1268
+ let r = String(n.missingProperty ?? "?"), i = Xe(e.parentSchema);
1251
1269
  return `missing required key '${r}' at ${t}${i.length ? `; allowed keys: ${i.join(", ")}` : ""}`;
1252
1270
  }
1253
1271
  case "enum": {
@@ -1256,25 +1274,25 @@ function $e(e) {
1256
1274
  }
1257
1275
  case "type": {
1258
1276
  let r = e.data;
1259
- return `${t} must be ${String(n.type)} (got ${Qe(r)})`;
1277
+ return `${t} must be ${String(n.type)} (got ${$e(r)})`;
1260
1278
  }
1261
1279
  default: return `${t} ${e.message ?? "failed schema check"}`;
1262
1280
  }
1263
1281
  }
1264
1282
  var W = 12;
1265
- function et(e) {
1266
- let t = e.slice(0, W).map($e);
1283
+ function tt(e) {
1284
+ let t = e.slice(0, W).map(et);
1267
1285
  return e.length > W && t.push(`…and ${e.length - W} more`), t.join("; ");
1268
1286
  }
1269
1287
  function G(e) {
1270
1288
  return e === null ? !1 : Array.isArray(e) ? e.some(G) : typeof e != "object" || Object.values(e).some(G);
1271
1289
  }
1272
- function tt(e, t) {
1273
- let n = [`Validation failed: ${et(e)}`], r = M(t);
1290
+ function nt(e, t) {
1291
+ let n = [`Validation failed: ${tt(e)}`], r = M(t);
1274
1292
  return G(r) && n.push(`Example: ${JSON.stringify(r)}`), n.join(" β€” ");
1275
1293
  }
1276
- var nt = async (e, t) => {
1277
- let n = e.ctx.get(rt);
1294
+ var rt = async (e, t) => {
1295
+ let n = e.ctx.get(it);
1278
1296
  if (n === void 0) return t();
1279
1297
  let r = n[e.operation.id];
1280
1298
  if (r === void 0) return t();
@@ -1284,11 +1302,11 @@ var nt = async (e, t) => {
1284
1302
  }, a = U.compile(r.input);
1285
1303
  if (!a(i)) {
1286
1304
  let e = a.errors ?? [];
1287
- throw new H("invalid_argument", tt(e, r.input), e);
1305
+ throw new H("invalid_argument", nt(e, r.input), e);
1288
1306
  }
1289
1307
  return t();
1290
- }, rt = Symbol("ValidateSchemasToken");
1291
- function it(e) {
1308
+ }, it = Symbol("ValidateSchemasToken");
1309
+ function at(e) {
1292
1310
  return async function(t, n) {
1293
1311
  let r = e[t.operation.id];
1294
1312
  if (r === void 0) return n();
@@ -1298,27 +1316,27 @@ function it(e) {
1298
1316
  }, a = U.compile(r.input);
1299
1317
  if (!a(i)) {
1300
1318
  let e = a.errors ?? [];
1301
- throw new H("invalid_argument", tt(e, r.input), e);
1319
+ throw new H("invalid_argument", nt(e, r.input), e);
1302
1320
  }
1303
1321
  return n();
1304
1322
  };
1305
1323
  }
1306
1324
  //#endregion
1307
1325
  //#region src/lib/instance-registry.ts
1308
- function at() {
1326
+ function ot() {
1309
1327
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (e) => {
1310
1328
  let t = Math.random() * 16 | 0;
1311
1329
  return (e === "x" ? t : t & 3 | 8).toString(16);
1312
1330
  });
1313
1331
  }
1314
- var ot = class {
1332
+ var st = class {
1315
1333
  constructor(e = {}) {
1316
1334
  this._store = /* @__PURE__ */ new Map(), this._sweeper = null, this._defaultTtlMs = e.defaultTtlMs;
1317
1335
  let t = null;
1318
1336
  t = e.sweepIntervalMs === 0 ? null : e.sweepIntervalMs === void 0 ? this._defaultTtlMs === void 0 ? null : Math.max(1e3, Math.floor(this._defaultTtlMs / 4)) : e.sweepIntervalMs, t !== null && t > 0 && (this._sweeper = setInterval(() => this._sweep(), t), this._sweeper.unref?.());
1319
1337
  }
1320
1338
  create(e, t = [], n) {
1321
- let r = new e(...t), i = at(), a = n ?? this._defaultTtlMs, o = a === void 0 ? null : Date.now() + a;
1339
+ let r = new e(...t), i = ot(), a = n ?? this._defaultTtlMs, o = a === void 0 ? null : Date.now() + a;
1322
1340
  return this._store.set(i, {
1323
1341
  instance: r,
1324
1342
  expiresAt: o
@@ -1363,7 +1381,7 @@ async function K(e) {
1363
1381
  }
1364
1382
  //#endregion
1365
1383
  //#region src/lib/stream.ts
1366
- function st(e) {
1384
+ function ct(e) {
1367
1385
  let { produce: t, signal: n } = e, r = n ?? new AbortController().signal;
1368
1386
  return { [Symbol.asyncIterator]() {
1369
1387
  let e = t(r);
@@ -1389,12 +1407,12 @@ function st(e) {
1389
1407
  };
1390
1408
  } };
1391
1409
  }
1392
- async function ct(e) {
1410
+ async function lt(e) {
1393
1411
  let t = [];
1394
1412
  for await (let n of e) t.push(n);
1395
1413
  return t;
1396
1414
  }
1397
- async function lt(e) {
1415
+ async function ut(e) {
1398
1416
  let t = [];
1399
1417
  try {
1400
1418
  for await (let n of e) t.push(n);
@@ -1403,17 +1421,17 @@ async function lt(e) {
1403
1421
  chunks: t
1404
1422
  };
1405
1423
  } catch (e) {
1406
- let n = Ke(e) ? e : new H("internal", e instanceof Error ? e.message : String(e));
1424
+ let n = qe(e) ? e : new H("internal", e instanceof Error ? e.message : String(e));
1407
1425
  return t.length === 0 ? {
1408
1426
  ok: !1,
1409
- carrier: qe("before-first-chunk", n)
1427
+ carrier: Je("before-first-chunk", n)
1410
1428
  } : {
1411
1429
  ok: !1,
1412
- carrier: qe("after-first-chunk", n, t.length)
1430
+ carrier: Je("after-first-chunk", n, t.length)
1413
1431
  };
1414
1432
  }
1415
1433
  }
1416
- function ut(e) {
1434
+ function dt(e) {
1417
1435
  return typeof e == "object" && !!e && Symbol.asyncIterator in e;
1418
1436
  }
1419
1437
  //#endregion
@@ -1434,7 +1452,7 @@ function J(e) {
1434
1452
  mapping: r
1435
1453
  };
1436
1454
  }
1437
- function dt(e, t) {
1455
+ function ft(e, t) {
1438
1456
  let n = e[c];
1439
1457
  if (typeof n == "string") {
1440
1458
  let e = t.registry.get(n);
@@ -1442,15 +1460,15 @@ function dt(e, t) {
1442
1460
  }
1443
1461
  return t.registry.resolve(e);
1444
1462
  }
1445
- function ft(e, t, n) {
1446
- let r = dt(t, n);
1463
+ function pt(e, t, n) {
1464
+ let r = ft(t, n);
1447
1465
  return r ? r.encode(e, t, n) : e;
1448
1466
  }
1449
- function pt(e, t, n) {
1450
- let r = dt(t, n);
1467
+ function mt(e, t, n) {
1468
+ let r = ft(t, n);
1451
1469
  return r ? r.decode(e, t, n) : e;
1452
1470
  }
1453
- function mt(e) {
1471
+ function ht(e) {
1454
1472
  let { id: t, schema: n } = e;
1455
1473
  return {
1456
1474
  id: t,
@@ -1468,7 +1486,7 @@ function mt(e) {
1468
1486
  if (s == null) throw new q("E_UNION_NO_DISCRIMINATOR", `[${t}] value at "${r.path}" is missing the discriminator property "${a}".`);
1469
1487
  let c = String(s), l = o[c];
1470
1488
  if (!l) throw new q("E_UNION_UNKNOWN_TAG", `[${t}] discriminator tag "${c}" at "${r.path}" is not in the mapping (known: ${Object.keys(o).join(", ")}).`);
1471
- return ft(e, r.resolve(l), {
1489
+ return pt(e, r.resolve(l), {
1472
1490
  ...r,
1473
1491
  path: `${r.path}[${c}]`
1474
1492
  });
@@ -1484,7 +1502,7 @@ function mt(e) {
1484
1502
  if (c == null) throw new q("E_UNION_NO_DISCRIMINATOR", `[${t}] wire object at "${r.path}" is missing the discriminator property "${o}".`);
1485
1503
  let l = String(c), u = s[l];
1486
1504
  if (!u) throw new q("E_UNION_UNKNOWN_TAG", `[${t}] discriminator tag "${l}" on the wire at "${r.path}" is not in the mapping (known: ${Object.keys(s).join(", ")}).`);
1487
- return pt(e, r.resolve(u), {
1505
+ return mt(e, r.resolve(u), {
1488
1506
  ...r,
1489
1507
  path: `${r.path}[${l}]`
1490
1508
  });
@@ -1496,29 +1514,29 @@ var Y = class extends Error {
1496
1514
  super(t), this.name = "NominalCodecError", this.code = e;
1497
1515
  }
1498
1516
  };
1499
- function ht(e) {
1517
+ function gt(e) {
1500
1518
  let t = e.properties;
1501
1519
  return t && typeof t == "object" && !Array.isArray(t) ? t : {};
1502
1520
  }
1503
- function gt(e) {
1521
+ function _t(e) {
1504
1522
  let t = e.required;
1505
1523
  return Array.isArray(t) ? t.filter((e) => typeof e == "string") : [];
1506
1524
  }
1507
- function _t(e, t, n) {
1525
+ function vt(e, t, n) {
1508
1526
  if (t) {
1509
1527
  let r = n.registry.resolve(t);
1510
1528
  if (r) return r.encode(e, t, n);
1511
1529
  }
1512
1530
  return e;
1513
1531
  }
1514
- function vt(e, t, n) {
1532
+ function yt(e, t, n) {
1515
1533
  if (t) {
1516
1534
  let r = n.registry.resolve(t);
1517
1535
  if (r) return r.decode(e, t, n);
1518
1536
  }
1519
1537
  return e;
1520
1538
  }
1521
- function yt(e) {
1539
+ function bt(e) {
1522
1540
  let { id: t, schema: n, ctor: r } = e;
1523
1541
  return {
1524
1542
  id: t,
@@ -1535,12 +1553,12 @@ function yt(e) {
1535
1553
  }
1536
1554
  r.seen.add(e);
1537
1555
  try {
1538
- let t = ht(n), i = e[typeof n["x-apigen-tojson"] == "string" ? n[u] : "toJSON"];
1556
+ let t = gt(n), i = e[typeof n["x-apigen-tojson"] == "string" ? n[u] : "toJSON"];
1539
1557
  if (typeof i == "function") {
1540
1558
  let n = i.call(e);
1541
1559
  if (typeof n == "object" && n && !Array.isArray(n)) {
1542
1560
  let e = {};
1543
- for (let [i, a] of Object.entries(n)) e[i] = _t(a, t[i], {
1561
+ for (let [i, a] of Object.entries(n)) e[i] = vt(a, t[i], {
1544
1562
  ...r,
1545
1563
  path: `${r.path}/${i}`
1546
1564
  });
@@ -1551,7 +1569,7 @@ function yt(e) {
1551
1569
  let a = {}, o = Object.keys(t), s = e, c = o.length > 0 ? o : Object.keys(s);
1552
1570
  for (let e of c) {
1553
1571
  let n = s[e];
1554
- n !== void 0 && (a[e] = _t(n, t[e], {
1572
+ n !== void 0 && (a[e] = vt(n, t[e], {
1555
1573
  ...r,
1556
1574
  path: `${r.path}/${e}`
1557
1575
  }));
@@ -1567,10 +1585,10 @@ function yt(e) {
1567
1585
  throw n = e === null ? "null" : Array.isArray(e) ? "array" : typeof e, new Y("E_NOMINAL_INVALID_WIRE", `[${t}] expected a JSON object on the wire at "${i.path}", got ${n}.`);
1568
1586
  }
1569
1587
  let a = e;
1570
- for (let e of gt(n)) if (!(e in a)) throw new Y("E_NOMINAL_INVALID_WIRE", `[${t}] required field "${e}" missing on the wire at "${i.path}".`);
1588
+ for (let e of _t(n)) if (!(e in a)) throw new Y("E_NOMINAL_INVALID_WIRE", `[${t}] required field "${e}" missing on the wire at "${i.path}".`);
1571
1589
  if (n["x-apigen-instances"] === !1) throw new Y("E_NOMINAL_NONRECONSTRUCTABLE", `[${t}] is encode-only: the extractor marked it non-reconstructable (x-apigen-instances:false). It cannot be decoded back to a live instance.`);
1572
- let o = ht(n), s = {};
1573
- for (let [e, t] of Object.entries(a)) s[e] = vt(t, o[e], {
1590
+ let o = gt(n), s = {};
1591
+ for (let [e, t] of Object.entries(a)) s[e] = yt(t, o[e], {
1574
1592
  ...i,
1575
1593
  path: `${i.path}/${e}`
1576
1594
  });
@@ -1584,21 +1602,21 @@ function yt(e) {
1584
1602
  }
1585
1603
  //#endregion
1586
1604
  //#region src/lib/logical/host-ts.ts
1587
- var bt = [
1605
+ var xt = [
1588
1606
  S,
1589
1607
  C,
1590
1608
  w,
1591
1609
  T,
1592
1610
  E,
1593
1611
  A
1594
- ], X = yt({
1612
+ ], X = bt({
1595
1613
  id: "ts.NominalSentinel",
1596
1614
  schema: {
1597
1615
  type: "object",
1598
1616
  "x-apigen-logical": "nominal",
1599
1617
  "x-apigen-codec": "ts.NominalSentinel"
1600
1618
  }
1601
- }), xt = mt({
1619
+ }), St = ht({
1602
1620
  id: "ts.UnionSentinel",
1603
1621
  schema: {
1604
1622
  oneOf: [],
@@ -1610,22 +1628,22 @@ var bt = [
1610
1628
  "x-apigen-codec": "ts.UnionSentinel"
1611
1629
  }
1612
1630
  });
1613
- function St() {
1631
+ function Ct() {
1614
1632
  let e = [
1615
- ...bt.map((e) => [e.id, e]),
1633
+ ...xt.map((e) => [e.id, e]),
1616
1634
  [X.id, X],
1617
- [xt.id, xt]
1635
+ [St.id, St]
1618
1636
  ];
1619
1637
  return Object.freeze(new Map(e));
1620
1638
  }
1621
- var Ct = Object.freeze({
1639
+ var wt = Object.freeze({
1622
1640
  host: "ts",
1623
1641
  logicalTypeVersion: d,
1624
- codecs: St()
1642
+ codecs: Ct()
1625
1643
  });
1626
1644
  //#endregion
1627
1645
  //#region src/lib/tool-description.ts
1628
- function wt(e, t, n) {
1646
+ function Tt(e, t, n) {
1629
1647
  let r = [
1630
1648
  n,
1631
1649
  typeof t?.input?.description == "string" ? t.input.description : void 0,
@@ -1635,7 +1653,7 @@ function wt(e, t, n) {
1635
1653
  }
1636
1654
  //#endregion
1637
1655
  //#region src/lib/mcp-output-schema.ts
1638
- function Tt(e) {
1656
+ function Et(e) {
1639
1657
  if (!e || typeof e != "object" || Array.isArray(e) || Object.keys(e).length === 0) return {
1640
1658
  outputSchema: void 0,
1641
1659
  wrapped: !1
@@ -1649,25 +1667,25 @@ function Tt(e) {
1649
1667
  wrapped: !1
1650
1668
  };
1651
1669
  }
1652
- function Et(e, t) {
1670
+ function Dt(e, t) {
1653
1671
  if (e) return t && typeof t == "object" && !Array.isArray(t) ? t : void 0;
1654
1672
  }
1655
1673
  //#endregion
1656
1674
  //#region src/lib/batch.ts
1657
- var Dt = 4, Ot = 32;
1675
+ var Ot = 4, kt = 32;
1658
1676
  function Z(e) {
1659
- return Ke(e) ? e : e instanceof Error ? new H("internal", e.message) : e;
1677
+ return qe(e) ? e : e instanceof Error ? new H("internal", e.message) : e;
1660
1678
  }
1661
- function kt(e, t) {
1679
+ function At(e, t) {
1662
1680
  if (e === "serial" || e === "chained") return 1;
1663
1681
  let n = t ?? 4;
1664
1682
  return !Number.isFinite(n) || n < 1 ? 1 : Math.min(Math.floor(n), 32);
1665
1683
  }
1666
- function At() {}
1667
- function jt(e, t) {
1684
+ function jt() {}
1685
+ function Mt(e, t) {
1668
1686
  if (!e && !t) return {
1669
1687
  signal: void 0,
1670
- dispose: At
1688
+ dispose: jt
1671
1689
  };
1672
1690
  let n = new AbortController(), r = () => {
1673
1691
  n.abort(e?.reason);
@@ -1683,15 +1701,15 @@ function jt(e, t) {
1683
1701
  }
1684
1702
  };
1685
1703
  }
1686
- async function Mt(e, t, n, r, i, a) {
1687
- let o = jt(r.signal, a);
1704
+ async function Nt(e, t, n, r, i, a) {
1705
+ let o = Mt(r.signal, a);
1688
1706
  try {
1689
1707
  let a = await e(t, o.signal ? {
1690
1708
  ...r,
1691
1709
  signal: o.signal
1692
1710
  } : r, i);
1693
- if (ut(a)) {
1694
- let e = await lt(a);
1711
+ if (dt(a)) {
1712
+ let e = await ut(a);
1695
1713
  if (!e.ok) {
1696
1714
  let t = e.carrier;
1697
1715
  return {
@@ -1722,8 +1740,8 @@ async function Mt(e, t, n, r, i, a) {
1722
1740
  o.dispose();
1723
1741
  }
1724
1742
  }
1725
- async function Nt(e, t, n, r, i = {}) {
1726
- let a = i.mode ?? "parallel", o = i.onItemError ?? "continue", s = kt(a, i.concurrency), c = Array(n.length), l = (e) => ({
1743
+ async function Pt(e, t, n, r, i = {}) {
1744
+ let a = i.mode ?? "parallel", o = i.onItemError ?? "continue", s = At(a, i.concurrency), c = Array(n.length), l = (e) => ({
1727
1745
  index: e,
1728
1746
  status: "rejected",
1729
1747
  reason: Z(/* @__PURE__ */ Error("apigen/invokeBatch: not attempted β€” an earlier item failed and " + (a === "chained" ? "mode is \"chained\"" : "onItemError is \"abort\"")))
@@ -1735,7 +1753,7 @@ async function Nt(e, t, n, r, i = {}) {
1735
1753
  c[u] = l(u);
1736
1754
  continue;
1737
1755
  }
1738
- let d = await Mt(e, t, u, n[u], r, i.itemTimeoutMs);
1756
+ let d = await Nt(e, t, u, n[u], r, i.itemTimeoutMs);
1739
1757
  c[u] = d, d.status === "rejected" && (a === "chained" || o === "abort") && (s = !0);
1740
1758
  }
1741
1759
  return c;
@@ -1748,7 +1766,7 @@ async function Nt(e, t, n, r, i = {}) {
1748
1766
  c[a] = l(a);
1749
1767
  continue;
1750
1768
  }
1751
- let s = await Mt(e, t, a, n[a], r, i.itemTimeoutMs);
1769
+ let s = await Nt(e, t, a, n[a], r, i.itemTimeoutMs);
1752
1770
  c[a] = s, s.status === "rejected" && o === "abort" && (d = !0);
1753
1771
  }
1754
1772
  });
@@ -1756,17 +1774,17 @@ async function Nt(e, t, n, r, i = {}) {
1756
1774
  }
1757
1775
  //#endregion
1758
1776
  //#region ../apigen-engine-naming/src/lib/naming.ts
1759
- function Pt(e) {
1760
- return e.words.join("-");
1761
- }
1762
1777
  function Ft(e) {
1763
- return e.words.map(Vt).join("");
1778
+ return e.words.join("-");
1764
1779
  }
1765
1780
  function It(e) {
1781
+ return e.words.map(Ht).join("");
1782
+ }
1783
+ function Lt(e) {
1766
1784
  return e.words.join("_");
1767
1785
  }
1768
- function Lt(e, t = {}) {
1769
- let n = [e.namespace, ...e.path], r = e.safe || I(e.input) ? "GET" : "POST", i = t.http?.verb?.[e.id] ?? r, a = "/" + n.map((e) => Pt(e)).join("/"), o = n.map((e) => It(e)).join("_"), s = n.map((e) => It(e)).slice(0, -1).join("."), c = Ft(n[n.length - 2] ?? n[0]), l = Ft(n[n.length - 1]), u = n.map((e) => Pt(e));
1786
+ function Rt(e, t = {}) {
1787
+ let n = [e.namespace, ...e.path], r = e.safe || I(e.input) ? "GET" : "POST", i = t.http?.verb?.[e.id] ?? r, a = "/" + n.map((e) => Ft(e)).join("/"), o = n.map((e) => Lt(e)).join("_"), s = n.map((e) => Lt(e)).slice(0, -1).join("."), c = It(n[n.length - 2] ?? n[0]), l = It(n[n.length - 1]), u = n.map((e) => Ft(e));
1770
1788
  return {
1771
1789
  http: {
1772
1790
  verb: i,
@@ -1781,17 +1799,17 @@ function Lt(e, t = {}) {
1781
1799
  cli: { path: u }
1782
1800
  };
1783
1801
  }
1784
- function Rt(e, t) {
1802
+ function zt(e, t) {
1785
1803
  return `x-${e}-${t}`;
1786
1804
  }
1787
- function zt(e, t) {
1805
+ function Bt(e, t) {
1788
1806
  return `--${e}-${t}`;
1789
1807
  }
1790
- function Bt(e, t) {
1808
+ function Vt(e, t) {
1791
1809
  let n = (e) => e.toUpperCase().replace(/-/g, "_");
1792
1810
  return e === "adhd" ? `APIGEN_${n(t)}` : `APIGEN_${n(e)}_${n(t)}`;
1793
1811
  }
1794
- function Vt(e) {
1812
+ function Ht(e) {
1795
1813
  return e.length === 0 ? e : e[0].toUpperCase() + e.slice(1);
1796
1814
  }
1797
1815
  //#endregion
@@ -1799,7 +1817,7 @@ function Vt(e) {
1799
1817
  function Q(e) {
1800
1818
  return e.anyOf ?? e.oneOf;
1801
1819
  }
1802
- function Ht(e) {
1820
+ function Ut(e) {
1803
1821
  if (!e) return !1;
1804
1822
  if (e.type === "array" || e.type === "object") return !0;
1805
1823
  let t = Q(e);
@@ -1809,7 +1827,7 @@ function Ht(e) {
1809
1827
  }
1810
1828
  return !1;
1811
1829
  }
1812
- function Ut(e) {
1830
+ function Wt(e) {
1813
1831
  if (!e) return !1;
1814
1832
  if (e.type === "boolean") return !0;
1815
1833
  let t = Q(e);
@@ -1819,7 +1837,7 @@ function Ut(e) {
1819
1837
  }
1820
1838
  return !1;
1821
1839
  }
1822
- function Wt(e) {
1840
+ function Gt(e) {
1823
1841
  if (!e) return !1;
1824
1842
  if (e.type === "number" || e.type === "integer") return !0;
1825
1843
  let t = Q(e);
@@ -1829,52 +1847,52 @@ function Wt(e) {
1829
1847
  }
1830
1848
  return !1;
1831
1849
  }
1832
- function Gt(e) {
1850
+ function Kt(e) {
1833
1851
  return e.replace(/[A-Z]/g, (e) => "-" + e.toLowerCase());
1834
1852
  }
1835
- function Kt(e) {
1853
+ function qt(e) {
1836
1854
  let t = e.input?.properties?.data;
1837
1855
  return {
1838
1856
  props: t?.properties ?? {},
1839
1857
  required: t?.required ?? []
1840
1858
  };
1841
1859
  }
1842
- function qt(e) {
1860
+ function Jt(e) {
1843
1861
  return typeof e.handler == "function";
1844
1862
  }
1845
- function Jt(e) {
1863
+ function Yt(e) {
1846
1864
  let t = e.input?.properties ?? {}, n = e["x-apigen-envelope"], r = [];
1847
1865
  for (let e of Object.keys(t)) {
1848
1866
  if (e === "data") continue;
1849
- let t = n?.[e] ?? "adhd", i = Rt(t, e);
1867
+ let t = n?.[e] ?? "adhd", i = zt(t, e);
1850
1868
  r.push({
1851
1869
  field: e,
1852
1870
  pluginId: t,
1853
1871
  httpHeader: i,
1854
1872
  mcpMetaKey: i,
1855
- cliFlag: zt(t, e),
1856
- envVar: Bt(t, e)
1873
+ cliFlag: Bt(t, e),
1874
+ envVar: Vt(t, e)
1857
1875
  });
1858
1876
  }
1859
1877
  return r;
1860
1878
  }
1861
- function Yt(e, t, n, r) {
1879
+ function Xt(e, t, n, r) {
1862
1880
  t === n || e.has(t) || e.set(t, {
1863
1881
  ...r,
1864
1882
  aliasOf: n
1865
1883
  });
1866
1884
  }
1867
- function Xt(e, t) {
1868
- let n = /* @__PURE__ */ new Map(), { props: r } = Kt(e);
1885
+ function Zt(e, t) {
1886
+ let n = /* @__PURE__ */ new Map(), { props: r } = qt(e);
1869
1887
  for (let [e, t] of Object.entries(r)) {
1870
1888
  let r = "string";
1871
- Ut(t) ? r = "boolean" : (Ht(t) || Wt(t)) && (r = "json");
1872
- let i = Gt(e), a = {
1889
+ Wt(t) ? r = "boolean" : (Ut(t) || Gt(t)) && (r = "json");
1890
+ let i = Kt(e), a = {
1873
1891
  camelKey: e,
1874
1892
  kind: "domain",
1875
1893
  valueKind: r
1876
1894
  };
1877
- n.set(i, a), Yt(n, e, i, a);
1895
+ n.set(i, a), Xt(n, e, i, a);
1878
1896
  }
1879
1897
  for (let e of t) {
1880
1898
  let t = e.cliFlag.replace(/^--/, ""), r = {
@@ -1887,8 +1905,8 @@ function Xt(e, t) {
1887
1905
  }
1888
1906
  return n;
1889
1907
  }
1890
- function Zt(e) {
1891
- let { op: t, schema: n, transport: r, projection: i } = e, a = Lt(t, i), o = n ? Jt(n) : [], s = n ? Xt(n, o) : /* @__PURE__ */ new Map(), c = n ? B(n).params : void 0, l = {
1908
+ function Qt(e) {
1909
+ let { op: t, schema: n, transport: r, projection: i } = e, a = Rt(t, i), o = n ? Yt(n) : [], s = n ? Zt(n, o) : /* @__PURE__ */ new Map(), c = n ? B(n).params : void 0, l = {
1892
1910
  op: t,
1893
1911
  transport: r,
1894
1912
  http: a.http,
@@ -1899,9 +1917,9 @@ function Zt(e) {
1899
1917
  envelope: o,
1900
1918
  cliFlags: s,
1901
1919
  streaming: t.streaming,
1902
- isMount: qt(t)
1920
+ isMount: Jt(t)
1903
1921
  };
1904
- if (qt(t)) {
1922
+ if (Jt(t)) {
1905
1923
  let e = t.handler;
1906
1924
  l.mountHandler = async (t) => e(t);
1907
1925
  }
@@ -1909,35 +1927,35 @@ function Zt(e) {
1909
1927
  }
1910
1928
  //#endregion
1911
1929
  //#region src/lib/package-invoker.ts
1912
- function Qt(e) {
1930
+ function $t(e) {
1913
1931
  let t = e.usePlugins;
1914
1932
  return Array.isArray(t) ? t : [];
1915
1933
  }
1916
- function $t(e) {
1934
+ function en(e) {
1917
1935
  let t = e.exitCode;
1918
1936
  return typeof t == "function" ? t : void 0;
1919
1937
  }
1920
- function en(e) {
1938
+ function tn(e) {
1921
1939
  let t = e.useOptions;
1922
1940
  return t && typeof t == "object" ? t : {};
1923
1941
  }
1924
- function tn(e) {
1942
+ function nn(e) {
1925
1943
  return async function(t, n) {
1926
1944
  let r = Object.assign(t, { data: t.domainArgs });
1927
1945
  return await e.layer(r, n);
1928
1946
  };
1929
1947
  }
1930
- function nn(e, t) {
1948
+ function rn(e, t) {
1931
1949
  let n = [];
1932
1950
  for (let e of t) {
1933
1951
  let t = e.capabilities?.layer;
1934
- t && n.push(tn(t));
1952
+ t && n.push(nn(t));
1935
1953
  }
1936
- return n.push(it(e)), Te(n);
1954
+ return n.push(at(e)), we(n);
1937
1955
  }
1938
1956
  //#endregion
1939
1957
  //#region src/lib/dispatch-for-plan.ts
1940
- function rn() {
1958
+ function an() {
1941
1959
  let e = /* @__PURE__ */ new Map();
1942
1960
  return {
1943
1961
  get: (t) => e.get(t),
@@ -1946,7 +1964,7 @@ function rn() {
1946
1964
  }
1947
1965
  };
1948
1966
  }
1949
- var an = {
1967
+ var on = {
1950
1968
  input: {
1951
1969
  type: "object",
1952
1970
  properties: { data: {
@@ -1956,11 +1974,11 @@ var an = {
1956
1974
  },
1957
1975
  output: {}
1958
1976
  };
1959
- async function on(e, t, n, r) {
1977
+ async function sn(e, t, n, r) {
1960
1978
  let i = {
1961
1979
  ...n,
1962
1980
  operation: { id: e.op.id },
1963
- ctx: new we(),
1981
+ ctx: new Ce(),
1964
1982
  transport: e.transport
1965
1983
  };
1966
1984
  if (e.isMount) {
@@ -1970,13 +1988,13 @@ async function on(e, t, n, r) {
1970
1988
  operation: e.op,
1971
1989
  data: n.domainArgs,
1972
1990
  envelope: n.envelope,
1973
- ctx: rn(),
1991
+ ctx: an(),
1974
1992
  transport: e.transport,
1975
1993
  signal: n.signal ?? new AbortController().signal
1976
1994
  }, s = {
1977
1995
  ...r,
1978
1996
  fns: { [e.op.id]: () => a(o) },
1979
- schemas: { [e.op.id]: an }
1997
+ schemas: { [e.op.id]: on }
1980
1998
  };
1981
1999
  return t(e.op.id, i, s);
1982
2000
  }
@@ -1985,22 +2003,22 @@ async function on(e, t, n, r) {
1985
2003
  //#endregion
1986
2004
  //#region src/lib/bind-host.ts
1987
2005
  var $ = "127.0.0.1";
1988
- function sn(e) {
2006
+ function cn(e) {
1989
2007
  let t = e.trim().toLowerCase().replace(/^\[|\]$/g, "");
1990
2008
  if (t === "localhost" || t === "::1") return !0;
1991
2009
  let n = t.startsWith("::ffff:") ? t.slice(7) : t;
1992
2010
  return /^127(\.\d{1,3}){3}$/.test(n);
1993
2011
  }
1994
- function cn(e) {
2012
+ function ln(e) {
1995
2013
  if (typeof e != "string") return $;
1996
2014
  let t = e.trim();
1997
2015
  return t === "" ? $ : t;
1998
2016
  }
1999
- function ln(e, t, n) {
2000
- return !sn(e) && (n?.warn({
2017
+ function un(e, t, n) {
2018
+ return !cn(e) && (n?.warn({
2001
2019
  host: e,
2002
2020
  host_kind: t
2003
2021
  }, `${t} binding non-loopback host "${e}": the server will be reachable from the network. Omit the host option to bind ${$}.`), !0);
2004
2022
  }
2005
2023
  //#endregion
2006
- export { Dt as BATCH_DEFAULT_CONCURRENCY, Ot as BATCH_MAX_CONCURRENCY, $ as DEFAULT_LISTEN_HOST, De as EventBus, ot as InstanceRegistry, we as LayerContext, q as UnionCodecError, rt as ValidateSchemasToken, bt as WELL_KNOWN_TS_CODECS, tn as adaptCoreLayer, R as assertNoSelfSubscription, P as buildContext, We as buildFnTable, Tt as buildMcpOutputSchema, Zt as buildOpPlan, wt as buildToolDescription, Ue as coerceQueryParams, lt as collectWithPhase, Ie as createApiPackage, Te as createInvoker, Le as createLogger, nn as createPackageInvoker, st as createStream, mt as createUnionCodec, be as dataParamNames, Ee as defineMiddleware, B as describeParams, Ce as dispatch, on as dispatchForPlan, ct as drainStream, Nt as invokeBatch, ut as isApiStream, sn as isLoopbackListenHost, it as makeValidateLayer, ye as needsEnvelopeField, $t as readExitCodeHook, en as readUseOptions, Qt as readUsePlugins, cn as resolveListenHost, Ct as tsHostBinding, nt as validateLayer, ln as warnIfNonLoopbackListen, ke as wireObservers, Et as wrapMcpStructuredContent };
2024
+ export { Ot as BATCH_DEFAULT_CONCURRENCY, kt as BATCH_MAX_CONCURRENCY, $ as DEFAULT_LISTEN_HOST, Ee as EventBus, st as InstanceRegistry, Ce as LayerContext, q as UnionCodecError, it as ValidateSchemasToken, xt as WELL_KNOWN_TS_CODECS, nn as adaptCoreLayer, R as assertNoSelfSubscription, ke as buildContext, Ge as buildFnTable, Et as buildMcpOutputSchema, Qt as buildOpPlan, Tt as buildToolDescription, We as coerceQueryParams, ut as collectWithPhase, Le as createApiPackage, we as createInvoker, Re as createLogger, rn as createPackageInvoker, ct as createStream, ht as createUnionCodec, ye as dataParamNames, Te as defineMiddleware, B as describeParams, Se as dispatch, sn as dispatchForPlan, lt as drainStream, Pt as invokeBatch, dt as isApiStream, cn as isLoopbackListenHost, at as makeValidateLayer, ve as needsEnvelopeField, en as readExitCodeHook, tn as readUseOptions, $t as readUsePlugins, ln as resolveListenHost, wt as tsHostBinding, rt as validateLayer, un as warnIfNonLoopbackListen, Oe as wireObservers, Dt as wrapMcpStructuredContent };
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@adhd/apigen-engine-runtime",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "dependencies": {
5
5
  "ajv": "^8.20.0",
6
6
  "ajv-formats": "2.1.1",
7
7
  "pino": "10.3.1",
8
- "@adhd/apigen-core-client": "^0.3.4",
8
+ "@adhd/apigen-core-client": "^0.3.5",
9
9
  "@adhd/apigen-base-logical": "^0.1.4",
10
10
  "@adhd/apigen-base-errors": "^0.2.3",
11
- "@adhd/apigen-engine-naming": "^0.2.5",
11
+ "@adhd/apigen-engine-naming": "^0.2.6",
12
12
  "better-sqlite3": "12.10.0"
13
13
  },
14
14
  "main": "./index.js",