@adhd/apigen-engine-runtime 0.2.1 โ†’ 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/index.js +1 -1
  3. package/index.mjs +186 -174
  4. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ## 0.2.2 (2026-07-30)
2
+
3
+
4
+ ### ๐Ÿš€ Features
5
+
6
+ - **apigen:** generic batch/bulk fan-out operations (FEAT-APIGEN-BULK-OPS-001)
7
+
8
+
9
+ ### ๐Ÿฉน Fixes
10
+
11
+ - **apigen:** schema extraction required-array + CLI mount/discriminated-union gaps
12
+
13
+
14
+ ### โค๏ธ Thank You
15
+
16
+ - pseudosky
17
+
1
18
  ## 0.2.1 (2026-07-28)
2
19
 
3
20
  This was a version bump only for apigen-engine-runtime to align it with other projects, there were no code changes.
package/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("ts-morph");require("node:fs");require("node:path");require("ts-json-schema-generator");const N=require("pino"),Ue=require("ajv"),De=require("ajv-formats"),I="$apigen";class z extends Error{constructor(t){super(t),this.code="E_DUP_CODEC",this.name="CodecRegistryError"}}function Le(e){const t=new Map;return{register(r,n){if(t.has(r.id)&&!(n!=null&&n.override))throw new z(`E_DUP_CODEC: a codec is already registered for id "${r.id}"`);t.set(r.id,r)},resolve(r){for(const n of t.values())if(n.matches(r))return n},get(r){return t.get(r)},ids(){return[...t.keys()]},freeze(){const r=new Map(t),n={register(){throw new z("E_DUP_CODEC: registry is frozen and cannot accept new codecs")},resolve(o){for(const i of r.values())if(i.matches(o))return i},get(o){return r.get(o)},ids(){return[...r.keys()]},freeze(){return n}};return n}}}const L="x-apigen-logical",R="x-apigen-codec",S="x-apigen-ctor",x="x-apigen-tojson",Re="0.1.0";function V(e,t){return{registry:e,resolve:r=>{throw new Error(`[apigen-logical] $ref "${r}" 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 v(e,t,r){const n=r.registry.resolve(t);if(n)return n.encode(e,t,r);const o=t.$ref;if(typeof o=="string"){const a=r.resolve(o);return v(e,a,r)}const i=t.oneOf;if(Array.isArray(i)){const a=ce(e,i,t);return v(e,a,r)}const s=t.type;if(s==="array"){if(!Array.isArray(e))return _(e,t,r);const a=t.items;if(!a)return e.map(c=>w(c));const f=r.path;return Array.isArray(a)?e.map((c,u)=>{const d=a[u];return d===void 0?w(c):v(c,d,{...r,path:`${f}/${u}`})}):e.map((c,u)=>v(c,a,{...r,path:`${f}/${u}`}))}if(s==="object"){if(e===null||typeof e!="object"||Array.isArray(e))return _(e,t,r);const a=t.properties;if(!a)return w(e);const f=r.path,c={};for(const[u,d]of Object.entries(a)){const l=e[u];l!==void 0&&(c[u]=v(l,d,{...r,path:`${f}/${u}`}))}return c}return s==null?_(e,t,r):w(e)}function $(e,t,r){const n=r.registry.resolve(t);if(n)return n.decode(e,t,r);const o=t.$ref;if(typeof o=="string"){const a=r.resolve(o);return $(e,a,r)}const i=t.oneOf;if(Array.isArray(i)){const a=ce(e,i,t);return $(e,a,r)}const s=t.type;if(s==="array"){if(!Array.isArray(e))return e;const a=t.items;if(!a)return e;const f=r.path;return Array.isArray(a)?e.map((c,u)=>{const d=a[u];return d===void 0?c:$(c,d,{...r,path:`${f}/${u}`})}):e.map((c,u)=>$(c,a,{...r,path:`${f}/${u}`}))}if(s==="object"){if(e===null||typeof e!="object"||Array.isArray(e))return e;const a=t.properties;if(!a)return e;const f=r.path,c={};for(const[u,d]of Object.entries(a)){const l=e[u];l!==void 0&&(c[u]=$(l,d,{...r,path:`${f}/${u}`}))}return c}return s==null?Be(e,r):e}function ce(e,t,r,n){const o=r.discriminator;if(o!=null&&o.propertyName){const i=e!==null&&typeof e=="object"?e[o.propertyName]:void 0;if(typeof i=="string"&&o.mapping){const s=o.mapping[i];if(s){const a=t.find(f=>f.$ref===s);if(a)return a}}}return t[0]??{}}function _(e,t,r){for(const n of r.registry.ids()){const o=r.registry.get(n);if(o)try{const i=o.encode(e,o.schema,r);return{[I]:n,v:i}}catch{}}return w(e)}function Be(e,t){if(e!==null&&typeof e=="object"&&!Array.isArray(e)&&I in e){const r=e,n=r[I],o=t.registry.get(n);if(o)return o.decode(r.v,o.schema,t)}return e}function w(e){if(e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean")return e;if(Array.isArray(e))return e.map(w);if(typeof e=="object"){const t={};for(const[r,n]of Object.entries(e))n!==void 0&&(t[r]=w(n));return t}return null}function Fe(e){return{encode(t,r,n){const o=V(e,n);return v(t,r,o)},decode(t,r,n){const o=V(e,n);return $(t,r,o)}}}const B={id:"date-time",kind:"scalar",schema:{type:"string",format:"date-time"},matches(e){return e.type==="string"&&e.format==="date-time"},encode(e,t,r){return e.toISOString()},decode(e,t,r){if(typeof e!="string"){if(r.mode==="strict")throw new TypeError(`[date-time] expected a string on the wire at "${r.path}", got ${typeof e}`);return new Date(String(e))}if(r.mode==="strict"&&Number.isNaN(new Date(e).getTime()))throw new TypeError(`[date-time] invalid date-time string at "${r.path}": ${JSON.stringify(e)}`);return new Date(e)}},F={id:"int64",kind:"scalar",schema:{type:"string",format:"int64"},matches(e){return e.type==="string"&&e.format==="int64"},encode(e,t,r){return String(e)},decode(e,t,r){if(typeof e!="string"){if(r.mode==="strict")throw new TypeError(`[int64] expected a string on the wire at "${r.path}", got ${typeof e}`);try{return BigInt(Math.trunc(Number(e)))}catch{return BigInt(0)}}if(r.mode==="strict")return BigInt(e);if(/^-?\d+$/.test(e))try{return BigInt(e)}catch{return BigInt(0)}return BigInt(0)}},q={id:"decimal",kind:"scalar",schema:{type:"string",format:"decimal"},matches(e){return e.type==="string"&&e.format==="decimal"},encode(e,t,r){return e},decode(e,t,r){if(typeof e!="string"){if(r.mode==="strict")throw new TypeError(`[decimal] expected a string on the wire at "${r.path}", got ${typeof e}`);return String(e)}if(r.mode==="strict"&&!/^-?\d+(\.\d+)?$/.test(e))throw new TypeError(`[decimal] wire value "${e}" at "${r.path}" is not a valid decimal string`);return e}},H={id:"byte",kind:"scalar",schema:{type:"string",format:"byte"},matches(e){return e.type==="string"&&e.format==="byte"},encode(e,t,r){return Buffer.from(e).toString("base64")},decode(e,t,r){if(typeof e!="string"){if(r.mode==="strict")throw new TypeError(`[byte] expected a base64 string on the wire at "${r.path}", got ${typeof e}`);return new Uint8Array(0)}if(r.mode==="strict"&&!/^[A-Za-z0-9+/]*={0,2}$/.test(e))throw new TypeError(`[byte] wire value at "${r.path}" is not standard base64 (format:byte): "${e}"`);return new Uint8Array(Buffer.from(e,"base64"))}},qe=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,K={id:"uuid",kind:"scalar",schema:{type:"string",format:"uuid"},matches(e){return e.type==="string"&&e.format==="uuid"},encode(e,t,r){return e.toLowerCase()},decode(e,t,r){if(typeof e!="string"){if(r.mode==="strict")throw new TypeError(`[uuid] expected a string on the wire at "${r.path}", got ${typeof e}`);return String(e).toLowerCase()}if(r.mode==="strict"&&!qe.test(e))throw new TypeError(`[uuid] wire value "${e}" at "${r.path}" is not a lowercase-hyphenated RFC 4122 UUID`);return e}},M="NaN",T="Infinity",P="-Infinity",He=new Set([M,T,P]),W={id:"number-special",kind:"scalar",schema:{type:"number"},matches(e){return e.type==="number"&&e.format===void 0},encode(e,t,r){return Number.isNaN(e)?M:e===1/0?T:e===-1/0?P:e},decode(e,t,r){if(typeof e=="number")return e;if(typeof e=="string"){if(e===M)return NaN;if(e===T)return 1/0;if(e===P)return-1/0;const n=Number(e);if(!Number.isNaN(n))return n}if(r.mode==="strict")throw new TypeError(`[number-special] unrecognized wire value at "${r.path}": ${JSON.stringify(e)}. Expected a number or one of ${[...He].join(", ")}.`);return NaN}},Ke=[B,F,q,H,K,W];function We(e,t={}){for(const r of Ke)e.register(r,{override:t.override??!1})}B.id,F.id,q.id,H.id,K.id,W.id;const ue=Le();We(ue);const fe=Fe(ue.freeze());function de(e,t){var n;const r=((n=e.input)==null?void 0:n.properties)??{};return t in r}function pe(e){var r,n;const t=(n=(r=e.input)==null?void 0:r.properties)==null?void 0:n.data;return Object.keys((t==null?void 0:t.properties)??{})}function ze(e,t){var o,i,s;const r=(s=(i=(o=e.input)==null?void 0:o.properties)==null?void 0:i.data)==null?void 0:s.properties,n=r==null?void 0:r[t];return n!==void 0?n:void 0}function Ve(e,t){return t===void 0||e===void 0?e:fe.decode(e,t)}function E(e,t){const r=t.output;return!r||Object.keys(r).length===0?e:fe.encode(e,r)}async function le(e,t,r,n,o,i){const a=pe(r).map(c=>Ve(i[c],ze(r,c)));if(de(r,"session")&&t){const c=await t({session:o.session}),u=await e[n](c,...a);return E(u,r)}if(r.hasCtx){const c=t?await t(o):void 0,u=await e[n](c,...a);return E(u,r)}const f=await e[n](...a);return E(f,r)}class ye{constructor(){this._map=new Map}set(t,r){this._map.set(t,r)}get(t){return this._map.get(t)}has(t){return this._map.has(t)}}function me(e=[]){return async function(r,n,o){const i=o.schemas[r];if(!i)throw new Error(`apigen/invoke: no schema found for operation "${r}"`);const s=()=>le(o.fns,o.createClient,i,r,n.envelope,n.domainArgs);return e.reduceRight((f,c)=>()=>c(n,f),s)()}}function Ge(e){return e}class he{constructor(){this.handlers=new Map}on(t,r){const n=this.handlers.get(t)??[];return this.handlers.set(t,[...n,r]),()=>this.off(t,r)}off(t,r){const n=this.handlers.get(t);if(!n)return;const o=n.filter(i=>i!==r);o.length===0?this.handlers.delete(t):this.handlers.set(t,o)}clear(){this.handlers.clear()}async emit(t){for(const[r,n]of this.handlers)if(Je(r,t))for(const o of n)await o(t)}}function Je(e,t){const[r,n,o]=e.split(":");return!(r!=="*"&&r!==t.module||n&&n!=="*"&&n!==t.method||o&&o!=="*"&&o!==t.lifecycle)}function ge(e,t){for(const r of e)if(r.eventMapping)for(const[n,o]of Object.entries(r.eventMapping))t.on(n,o)}async function we(e,t,r){let n={...t};for(const o of e)if(o.createContext){await r.emit({module:o.id,method:"createContext",lifecycle:"start",ctx:n});try{const i=await o.createContext(n);n={...n,...i},await r.emit({module:o.id,method:"createContext",lifecycle:"complete",ctx:n})}catch(i){throw await r.emit({module:o.id,method:"createContext",lifecycle:"error",ctx:n,error:i}),i}}return n}function G(e,t){const r=new Set,n=[e];for(;n.length>0;){const o=n.pop();if(!o||r.has(o))continue;r.add(o);const i=o.$ref;if(typeof i=="string"){if(t){const d=t[i];if(!d){const l=Object.keys(t).join(", ")||"(none)";throw new Error(`[apigen-logical] $ref "${i}" cannot be resolved. Available $defs: ${l}`)}n.push(d)}continue}const s=o.oneOf;if(Array.isArray(s))for(const d of s)typeof d=="object"&&d!==null&&n.push(d);const a=o.properties;if(a)for(const d of Object.values(a))n.push(d);const f=o.items;if(Array.isArray(f))for(const d of f)typeof d=="object"&&d!==null&&n.push(d);else typeof f=="object"&&f!==null&&n.push(f);const c=o.additionalProperties;typeof c=="object"&&c!==null&&n.push(c);const u=o.propertyNames;typeof u=="object"&&u!==null&&n.push(u)}}const J=new Set(["string","number","boolean","integer"]);function Ye(e){if(typeof e!="object"||e===null)return!1;const t=e;if(t.$ref!==void 0||t.oneOf||t.anyOf||t.allOf)return!1;const{type:r}=t;return typeof r=="string"?J.has(r):Array.isArray(r)?r.every(n=>J.has(n)||n==="null"):Array.isArray(t.enum)&&t.enum.length>0?t.enum.every(n=>["string","number","boolean"].includes(typeof n)):!1}function Xe(e){if(!e||typeof e!="object")return!1;const t=e.properties;return t===void 0||typeof t!="object"||t===null?!1:Object.values(t).every(Ye)}function Qe(e){const t={},r=n=>{for(const o of["definitions","$defs"]){const i=n[o];if(i)for(const[s,a]of Object.entries(i)){const f=s.startsWith("#/")?s:`#/${o}/${s}`;t[f]=a}}};for(const n of Object.values(e.schemas))r(n.input),r(n.output);if(Object.keys(t).length!==0)for(const[n,o]of Object.entries(e.schemas))try{G(o.input,t),G(o.output,t)}catch(i){throw new Error(`[apigen-core-client] Schema validation failed for function "${n}": ${i.message}`)}}function Ze(e,t){const r=['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&&r.push(`Field(s) ${e.map(n=>`"${n}"`).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.`),r.join(" ")}function et(e,t,r){Qe(e);const n={};for(const[o,i]of Object.entries(e.schemas)){const s=(r==null?void 0:r[o])??{},a=i.input.properties??{},f=i.input.required??[],c={},u=[],d={};for(const h of t)if(h.envelope&&s[h.id]!==!1)for(const[b,Pe]of Object.entries(h.envelope))c[b]=Pe,d[b]=h.id,u.includes(b)||u.push(b);const l={type:"object",properties:a,additionalProperties:!1,...f.length>0?{required:f}:{}},m=i.safe===!0||Xe(i.input),p=i.input.definitions,y=i.input.$defs;n[o]={input:{type:"object",properties:{...c,data:l},required:[...u,...f.length>0?["data"]:[]],additionalProperties:!1,description:Ze(Object.keys(c),Object.keys(a).length>0),...p?{definitions:p}:{},...y?{$defs:y}:{}},output:i.output,...i.hasCtx?{hasCtx:!0}:{},"x-apigen-safe":m,...Object.keys(d).length>0?{"x-apigen-envelope":d}:{}}}return n}const tt={"decimal.js":"Decimal"};function rt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}Object.entries(tt).map(([e,t])=>({pattern:new RegExp(`import\\(["'][^"']*${rt(e)}[^"']*["']\\)\\.\\w+`,"g"),key:t}));class U extends Error{constructor(t){super(t),this.name="ConfigurationError"}}function be(e){for(const t of e)for(const r of Object.keys(t.eventMapping??{})){const[n]=r.split(":");if(n!=="*"&&n===t.id)throw new U(`Middleware "${t.id}" subscribes to its own events via "${r}". This would cause infinite recursion.`)}}function nt(e){const{domainSchemas:t,middlewares:r,overrides:n={},strict:o=!1}=e;be(r);for(const c of Object.keys(n))if(!(c in t.schemas)){const u=`Override key "${c}" not found in domain schemas.`;if(o)throw new U(u);console.warn("[apigen-runtime]",u)}const i=new Set(r.map(c=>c.id));for(const[c,u]of Object.entries(n))for(const d of Object.keys(u??{}))if(!i.has(d)){const l=`Override key "${c}.${d}" does not match any declared middleware id.`;if(o)throw new U(l);console.warn("[apigen-runtime]",l)}const s=et(t,r,n),a=new he;return ge(r,a),{schemas:s,createClient:async c=>we(r,c,a),dispose:()=>a.clear()}}function ot(e={}){const t=e.level??"info",r=typeof e.destination=="string"&&e.destination.length>0,n=!r&&!!process.stderr.isTTY,o=e.format??(n?"pretty":"json"),i={level:t};if(o==="pretty")return i.transport={target:"pino-pretty",options:{colorize:!r,translateTime:"SYS:HH:MM:ss.l",ignore:"pid,hostname",...r?{destination:e.destination,mkdir:!0}:{destination:2}}},N(i);const s=r?N.destination({dest:e.destination,mkdir:!0,sync:!0}):N.destination(2);return N(i,s)}function ve(e){return e?e.type==="array"?`${ve(e.items)}[]`:e.enum?"enum":e.$ref?String(e.$ref).split("/").pop()||"object":e.anyOf||e.oneOf?"union":e.type??"object":"unknown"}function $e(e){var a;const r=(a=((e==null?void 0:e.input)??{}).properties)==null?void 0:a.data,n=(r==null?void 0:r.properties)??{},o=new Set((r==null?void 0:r.required)??[]),i=Object.entries(n).map(([f,c])=>({name:f,type:ve(c),required:o.has(f)})),s=i.map(f=>`${f.name}${f.required?"":"?"}: ${f.type}`).join(", ");return{params:i,text:s}}function it(e){let t;return Array.isArray(e)?t=e:e?t=[e]:t=[],t.find(r=>r==="number"||r==="integer"||r==="boolean")}function st(e,t){var i,s;const n=((s=(i=((t==null?void 0:t.input)??{}).properties)==null?void 0:i.data)==null?void 0:s.properties)??{},o={...e};for(const[a,f]of Object.entries(n)){const c=o[a];if(typeof c!="string")continue;const u=it(f==null?void 0:f.type);if(u==="number"||u==="integer"){const d=Number(c);!Number.isNaN(d)&&c.trim()!==""&&(o[a]=d)}else u==="boolean"&&(c==="true"?o[a]=!0:c==="false"&&(o[a]=!1))}return o}const Y=new Set(["default","module.exports","__esModule"]);function at(e){const t={},r=(n,o)=>{for(const[i,s]of Object.entries(n))if(typeof s=="function"){!Y.has(i)&&!(i in t)&&(t[i]=s);const a=s.name;a&&!(a in t)&&(t[a]=s)}else s&&typeof s=="object"&&o<2&&Y.has(i)&&r(s,o+1)};return r(e,0),t}const ct=["invalid_argument","unauthenticated","permission_denied","not_found","internal"];class A extends Error{constructor(t,r,n){super(r),this.name="ApiError",this.code=t,this.details=n,Object.setPrototypeOf(this,new.target.prototype)}toJSON(){const t={code:this.code,message:this.message};return this.details!==void 0&&(t.details=this.details),t}}function Oe(e){return typeof e=="object"&&e!==null&&e.name==="ApiError"&&ct.includes(e.code)&&typeof e.toJSON=="function"}function X(e,t,r=0){return e==="before-first-chunk"?{phase:e,error:t}:{phase:e,error:t,chunksDelivered:r}}const O=new Ue({allErrors:!0});De(O);for(const e of[L,R,S,x,"discriminator"])O.addKeyword({keyword:e,valid:!0});O.addFormat("decimal",/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)$/);function Ne(e){return e.map(t=>`${t.instancePath||"(root)"} ${t.message??"failed schema check"}`).join("; ")}const ut=async(e,t)=>{const r=e.ctx.get(je);if(r===void 0)return t();const n=e.operation.id,o=r[n];if(o===void 0)return t();const i={data:e.domainArgs,...e.envelope},s=O.compile(o.input);if(!s(i)){const f=s.errors??[];throw new A("invalid_argument",`Validation failed: ${Ne(f)}`,f)}return t()},je=Symbol("ValidateSchemasToken");function Ae(e){return async function(r,n){const o=r.operation.id,i=e[o];if(i===void 0)return n();const s={data:r.domainArgs,...r.envelope},a=O.compile(i.input);if(!a(s)){const c=a.errors??[];throw new A("invalid_argument",`Validation failed: ${Ne(c)}`,c)}return n()}}function ft(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}class dt{constructor(t={}){var n,o;this._store=new Map,this._sweeper=null,this._defaultTtlMs=t.defaultTtlMs;let r=null;t.sweepIntervalMs===0?r=null:t.sweepIntervalMs!==void 0?r=t.sweepIntervalMs:this._defaultTtlMs!==void 0?r=Math.max(1e3,Math.floor(this._defaultTtlMs/4)):r=null,r!==null&&r>0&&(this._sweeper=setInterval(()=>this._sweep(),r),(o=(n=this._sweeper).unref)==null||o.call(n))}create(t,r=[],n){const o=new t(...r),i=ft(),s=n??this._defaultTtlMs,a=s!==void 0?Date.now()+s:null;return this._store.set(i,{instance:o,expiresAt:a}),{instanceId:i}}get(t){const r=this._store.get(t);if(!r)throw new Error(`[instance-registry] Unknown instanceId: "${t}"`);if(r.expiresAt!==null&&Date.now()>r.expiresAt)throw this._evict(t,r),new Error(`[instance-registry] Instance "${t}" has expired`);return r.instance}async dispatch(t,r,n=[]){const o=this.get(t),i=o[r];if(typeof i!="function")throw new Error(`[instance-registry] Method "${r}" not found on instance "${t}"`);return i.call(o,...n)}async dispose(t){const r=this._store.get(t);r&&(this._store.delete(t),await C(r.instance))}async disposeAll(){this._sweeper!==null&&(clearInterval(this._sweeper),this._sweeper=null);const t=[...this._store.entries()];this._store.clear(),await Promise.all(t.map(([,r])=>C(r.instance)))}get size(){return this._store.size}_sweep(){const t=Date.now();for(const[r,n]of this._store)n.expiresAt!==null&&t>n.expiresAt&&this._evict(r,n)}_evict(t,r){this._store.delete(t),C(r.instance)}}async function C(e){if(e!==null&&typeof e=="object"&&"dispose"in e){const t=e.dispose;typeof t=="function"&&await t.call(e)}}function pt(e){const{produce:t,signal:r}=e,n=r??new AbortController().signal;return{[Symbol.asyncIterator](){const o=t(n);return{async next(){return n.aborted?(await o.return(void 0),{done:!0,value:void 0}):o.next()},async return(i){return await o.return(i),{done:!0,value:void 0}},async throw(i){return await o.throw(i),{done:!0,value:void 0}}}}}}async function lt(e){const t=[];for await(const r of e)t.push(r);return t}async function _e(e){const t=[];try{for await(const r of e)t.push(r);return{ok:!0,chunks:t}}catch(r){const n=Oe(r)?r:new A("internal",r instanceof Error?r.message:String(r));return t.length===0?{ok:!1,carrier:X("before-first-chunk",n)}:{ok:!1,carrier:X("after-first-chunk",n,t.length)}}}function Ee(e){return e!==null&&typeof e=="object"&&Symbol.asyncIterator in e}class g extends Error{constructor(t,r){super(r),this.name="UnionCodecError",this.code=t}}function k(e){const t=e.discriminator;if(t===null||typeof t!="object"||Array.isArray(t))return;const r=t;if(typeof r.propertyName!="string")return;const n=r.mapping;if(!(n===null||typeof n!="object"||Array.isArray(n)))return{propertyName:r.propertyName,mapping:n}}function Ce(e,t){const r=e[R];if(typeof r=="string"){const n=t.registry.get(r);if(n)return n}return t.registry.resolve(e)}function yt(e,t,r){const n=Ce(t,r);return n?n.encode(e,t,r):e}function mt(e,t,r){const n=Ce(t,r);return n?n.decode(e,t,r):e}function ke(e){const{id:t,schema:r}=e;return{id:t,kind:"union",schema:r,matches(n){if(n[L]==="union")return!0;const o=n.oneOf;return!Array.isArray(o)||o.length===0?!1:k(n)!==void 0},encode(n,o,i){const s=k(o);if(!s)throw new g("E_UNION_NO_DISCRIMINATOR",`[${t}] schema node at "${i.path}" has no discriminator.propertyName; cannot dispatch union branch.`);const{propertyName:a,mapping:f}=s,c=n[a];if(c==null)throw new g("E_UNION_NO_DISCRIMINATOR",`[${t}] value at "${i.path}" is missing the discriminator property "${a}".`);const u=String(c),d=f[u];if(!d)throw new g("E_UNION_UNKNOWN_TAG",`[${t}] discriminator tag "${u}" at "${i.path}" is not in the mapping (known: ${Object.keys(f).join(", ")}).`);const l=i.resolve(d);return yt(n,l,{...i,path:`${i.path}[${u}]`})},decode(n,o,i){if(n===null||typeof n!="object"||Array.isArray(n)){let p;throw n===null?p="null":Array.isArray(n)?p="array":p=typeof n,new g("E_UNION_INVALID_WIRE",`[${t}] expected a JSON object on the wire at "${i.path}", got ${p}.`)}const s=n,a=k(o);if(!a)throw new g("E_UNION_NO_DISCRIMINATOR",`[${t}] schema node at "${i.path}" has no discriminator.propertyName; cannot dispatch union branch.`);const{propertyName:f,mapping:c}=a,u=s[f];if(u==null)throw new g("E_UNION_NO_DISCRIMINATOR",`[${t}] wire object at "${i.path}" is missing the discriminator property "${f}".`);const d=String(u),l=c[d];if(!l)throw new g("E_UNION_UNKNOWN_TAG",`[${t}] discriminator tag "${d}" on the wire at "${i.path}" is not in the mapping (known: ${Object.keys(c).join(", ")}).`);const m=i.resolve(l);return mt(n,m,{...i,path:`${i.path}[${d}]`})}}}const ht="x-apigen-instances";class j extends Error{constructor(t,r){super(r),this.name="NominalCodecError",this.code=t}}function Q(e){const t=e.properties;return t&&typeof t=="object"&&!Array.isArray(t)?t:{}}function gt(e){const t=e.required;return Array.isArray(t)?t.filter(r=>typeof r=="string"):[]}function Z(e,t,r){if(t){const n=r.registry.resolve(t);if(n)return n.encode(e,t,r)}return e}function wt(e,t,r){if(t){const n=r.registry.resolve(t);if(n)return n.decode(e,t,r)}return e}function bt(e){const{id:t,schema:r,ctor:n}=e;return{id:t,kind:"nominal",schema:r,matches(o){return o[L]==="nominal"?!0:o[R]===t},encode(o,i,s){if(o===null||typeof o!="object")return o;if(s.seen.has(o)){if(s.mode==="strict")throw new j("E_NOMINAL_CYCLE",`[${t}] cycle detected at "${s.path}": a nominal instance references itself. Strict mode rejects cycles (DESIGN ยง8.3); break the cycle or use 'lossy' mode.`);return null}s.seen.add(o);try{const a=Q(i),f=typeof i[x]=="string"?i[x]:"toJSON",c=o[f];if(typeof c=="function"){const p=c.call(o);if(p!==null&&typeof p=="object"&&!Array.isArray(p)){const y={};for(const[h,b]of Object.entries(p))y[h]=Z(b,a[h],{...s,path:`${s.path}/${h}`});return y}return p}const u={},d=Object.keys(a),l=o,m=d.length>0?d:Object.keys(l);for(const p of m){const y=l[p];y!==void 0&&(u[p]=Z(y,a[p],{...s,path:`${s.path}/${p}`}))}return u}finally{s.seen.delete(o)}},decode(o,i,s){if(o===null||typeof o!="object"||Array.isArray(o)){let u;throw o===null?u="null":Array.isArray(o)?u="array":u=typeof o,new j("E_NOMINAL_INVALID_WIRE",`[${t}] expected a JSON object on the wire at "${s.path}", got ${u}.`)}const a=o;for(const u of gt(i))if(!(u in a))throw new j("E_NOMINAL_INVALID_WIRE",`[${t}] required field "${u}" missing on the wire at "${s.path}".`);if(i[ht]===!1)throw new j("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.`);const f=Q(i),c={};for(const[u,d]of Object.entries(a))c[u]=wt(d,f[u],{...s,path:`${s.path}/${u}`});if(n){const u=typeof i[S]=="string"?i[S]:"fromJSON",d=n[u];if(typeof d=="function")return d.call(n,c);const l=n;return new l(c)}return c}}}const Ie=[B,F,q,H,K,W],vt={type:"object","x-apigen-logical":"nominal","x-apigen-codec":"ts.NominalSentinel"},ee=bt({id:"ts.NominalSentinel",schema:vt}),$t={oneOf:[],discriminator:{propertyName:"kind",mapping:{}},"x-apigen-logical":"union","x-apigen-codec":"ts.UnionSentinel"},te=ke({id:"ts.UnionSentinel",schema:$t});function Ot(){const e=[...Ie.map(t=>[t.id,t]),[ee.id,ee],[te.id,te]];return Object.freeze(new Map(e))}const Nt=Object.freeze({host:"ts",logicalTypeVersion:Re,codecs:Ot()});function jt(e,t,r){var i;const n=typeof((i=t==null?void 0:t.input)==null?void 0:i.description)=="string"?t.input.description:void 0,o=[r,n].filter(s=>typeof s=="string"&&s.length>0);return o.length>0?o.join(" โ€” "):e}function At(e){if(!e||typeof e!="object"||Array.isArray(e)||Object.keys(e).length===0)return{outputSchema:void 0,wrapped:!1};const t=e;return t.type==="object"?{outputSchema:t,wrapped:!1}:{outputSchema:{type:"object",properties:{result:t},required:["result"]},wrapped:!0}}function _t(e,t){return e?{result:t}:t&&typeof t=="object"&&!Array.isArray(t)?t:void 0}const Se=4,xe=32;function D(e){return Oe(e)?e:e instanceof Error?new A("internal",e.message):e}function Et(e,t){if(e==="serial"||e==="chained")return 1;const r=t??Se;return!Number.isFinite(r)||r<1?1:Math.min(Math.floor(r),xe)}function Ct(){}function kt(e,t){var i;if(!e&&!t)return{signal:void 0,dispose:Ct};const r=new AbortController,n=()=>{r.abort(e==null?void 0:e.reason)};e&&(e.aborted?r.abort(e.reason):e.addEventListener("abort",n,{once:!0}));let o;return t!==void 0&&!r.signal.aborted&&(o=setTimeout(()=>{r.abort(new DOMException(`apigen/invokeBatch: item timed out after ${t}ms`,"TimeoutError"))},t),(i=o.unref)==null||i.call(o)),{signal:r.signal,dispose(){e&&e.removeEventListener("abort",n),o&&clearTimeout(o)}}}async function re(e,t,r,n,o,i){const s=kt(n.signal,i);try{const a=s.signal?{...n,signal:s.signal}:n,f=await e(t,a,o);if(Ee(f)){const c=await _e(f);if(c.ok)return{index:r,status:"fulfilled",chunks:c.chunks};const u=c.carrier;return{index:r,status:"rejected",reason:D(u.error),...u.phase==="after-first-chunk"?{chunksDelivered:u.chunksDelivered}:{}}}return{index:r,status:"fulfilled",value:f}}catch(a){return{index:r,status:"rejected",reason:D(a)}}finally{s.dispose()}}async function It(e,t,r,n,o={}){const i=o.mode??"parallel",s=o.onItemError??"continue",a=Et(i,o.concurrency),f=new Array(r.length),c=p=>({index:p,status:"rejected",reason:D(new Error("apigen/invokeBatch: not attempted โ€” an earlier item failed and "+(i==="chained"?'mode is "chained"':'onItemError is "abort"')))});if(i==="serial"||i==="chained"){let p=!1;for(let y=0;y<r.length;y++){if(p){f[y]=c(y);continue}const h=await re(e,t,y,r[y],n,o.itemTimeoutMs);f[y]=h,h.status==="rejected"&&(i==="chained"||s==="abort")&&(p=!0)}return f}let u=0,d=!1;const l=Math.max(1,Math.min(a,r.length)),m=Array.from({length:l},async()=>{for(;;){const p=u++;if(p>=r.length)return;if(d){f[p]=c(p);continue}const y=await re(e,t,p,r[p],n,o.itemTimeoutMs);f[p]=y,y.status==="rejected"&&s==="abort"&&(d=!0)}});return await Promise.all(m),f}const ne=new Set(["string","number","boolean","integer"]);function St(e){if(typeof e!="object"||e===null)return!1;const t=e;if(t.$ref!==void 0||t.oneOf||t.anyOf||t.allOf)return!1;const{type:r}=t;return typeof r=="string"?ne.has(r):Array.isArray(r)?r.every(n=>ne.has(n)||n==="null"):Array.isArray(t.enum)&&t.enum.length>0?t.enum.every(n=>["string","number","boolean"].includes(typeof n)):!1}function xt(e){if(!e||typeof e!="object")return!1;const t=e.properties;return t===void 0||typeof t!="object"||t===null?!1:Object.values(t).every(St)}const Mt={"decimal.js":"Decimal"};function Tt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}Object.entries(Mt).map(([e,t])=>({pattern:new RegExp(`import\\(["'][^"']*${Tt(e)}[^"']*["']\\)\\.\\w+`,"g"),key:t}));function oe(e){return e.words.join("-")}function ie(e){return e.words.map(Rt).join("")}function se(e){return e.words.join("_")}function Pt(e,t={}){var r,n;const o=[e.namespace,...e.path],i=e.safe||xt(e.input)?"GET":"POST",s=((n=(r=t.http)==null?void 0:r.verb)==null?void 0:n[e.id])??i,a="/"+o.map(m=>oe(m)).join("/"),f=o.map(m=>se(m)).join("_"),c=o.map(m=>se(m)).slice(0,-1).join("."),u=ie(o[o.length-2]??o[0]),d=ie(o[o.length-1]),l=o.map(m=>oe(m));return{http:{verb:s,route:a},mcp:{name:f},grpc:{package:c,service:u,method:d},cli:{path:l}}}function Ut(e,t){return`x-${e}-${t}`}function Dt(e,t){return`--${e}-${t}`}function Lt(e,t){const r=n=>n.toUpperCase().replace(/-/g,"_");return e==="adhd"?`APIGEN_${r(t)}`:`APIGEN_${r(e)}_${r(t)}`}function Rt(e){return e.length===0?e:e[0].toUpperCase()+e.slice(1)}function Me(e){return e.anyOf??e.oneOf}function Bt(e){if(!e)return!1;if(e.type==="array"||e.type==="object")return!0;const t=Me(e);if(t){const r=t.filter(n=>n.type!=="null");return r.length>0&&r.every(n=>n.type==="array"||n.type==="object")}return!1}function Ft(e){if(!e)return!1;if(e.type==="boolean")return!0;const t=Me(e);if(t){const r=t.filter(n=>n.type!=="null");return r.length>0&&r.every(n=>n.type==="boolean")}return!1}function qt(e){return e.replace(/[A-Z]/g,t=>"-"+t.toLowerCase())}function Ht(e){var o,i;const t=(i=(o=e.input)==null?void 0:o.properties)==null?void 0:i.data,r=(t==null?void 0:t.properties)??{},n=(t==null?void 0:t.required)??[];return{props:r,required:n}}function ae(e){return typeof e.handler=="function"}function Kt(e){var o;const t=((o=e.input)==null?void 0:o.properties)??{},r=e["x-apigen-envelope"],n=[];for(const i of Object.keys(t)){if(i==="data")continue;const s=(r==null?void 0:r[i])??"adhd",a=Ut(s,i);n.push({field:i,pluginId:s,httpHeader:a,mcpMetaKey:a,cliFlag:Dt(s,i),envVar:Lt(s,i)})}return n}function Wt(e,t){const r=new Map,{props:n}=Ht(e);for(const[o,i]of Object.entries(n)){let s="string";Ft(i)?s="boolean":Bt(i)&&(s="json"),r.set(qt(o),{camelKey:o,kind:"domain",valueKind:s})}for(const o of t){const i=o.cliFlag.replace(/^--/,"");r.set(i,{camelKey:o.field,kind:"envelope",valueKind:"string",envVar:o.envVar})}return r}function zt(e){const{op:t,schema:r,transport:n,projection:o}=e,i=Pt(t,o),s=r?Kt(r):[],a=r?Wt(r,s):new Map,f=r?$e(r).params:void 0,c={op:t,transport:n,http:i.http,mcp:i.mcp,cli:i.cli,grpc:i.grpc,params:f,envelope:s,cliFlags:a,streaming:t.streaming,isMount:ae(t)};if(ae(t)){const u=t.handler;c.mountHandler=async d=>u(d)}return c}function Vt(e){const t=e.usePlugins;return Array.isArray(t)?t:[]}function Gt(e){const t=e.useOptions;return t&&typeof t=="object"?t:{}}function Te(e){return async function(r,n){const o=Object.assign(r,{data:r.domainArgs});return await e.layer(o,n)}}function Jt(e,t){var n;const r=[];for(const o of t){const i=(n=o.capabilities)==null?void 0:n.layer;i&&r.push(Te(i))}return r.push(Ae(e)),me(r)}function Yt(){const e=new Map;return{get:t=>e.get(t),set:(t,r)=>{e.set(t,r)}}}const Xt={input:{type:"object",properties:{data:{type:"object",properties:{}}}},output:{}};async function Qt(e,t,r,n){const o={...r,operation:{id:e.op.id},ctx:new ye};if(e.isMount){const i=e.mountHandler;if(!i)throw new Error(`apigen-engine-runtime/dispatchForPlan: OpPlan for mount op "${e.op.id}" has isMount=true but no mountHandler`);const s={operation:e.op,data:r.domainArgs,envelope:r.envelope,ctx:Yt(),transport:e.transport,signal:r.signal??new AbortController().signal},a={...n,fns:{[e.op.id]:()=>i(s)},schemas:{[e.op.id]:Xt}};return t(e.op.id,o,a)}return t(e.op.id,o,n)}exports.BATCH_DEFAULT_CONCURRENCY=Se;exports.BATCH_MAX_CONCURRENCY=xe;exports.EventBus=he;exports.InstanceRegistry=dt;exports.LayerContext=ye;exports.UnionCodecError=g;exports.ValidateSchemasToken=je;exports.WELL_KNOWN_TS_CODECS=Ie;exports.adaptCoreLayer=Te;exports.assertNoSelfSubscription=be;exports.buildContext=we;exports.buildFnTable=at;exports.buildMcpOutputSchema=At;exports.buildOpPlan=zt;exports.buildToolDescription=jt;exports.coerceQueryParams=st;exports.collectWithPhase=_e;exports.createApiPackage=nt;exports.createInvoker=me;exports.createLogger=ot;exports.createPackageInvoker=Jt;exports.createStream=pt;exports.createUnionCodec=ke;exports.dataParamNames=pe;exports.defineMiddleware=Ge;exports.describeParams=$e;exports.dispatch=le;exports.dispatchForPlan=Qt;exports.drainStream=lt;exports.invokeBatch=It;exports.isApiStream=Ee;exports.makeValidateLayer=Ae;exports.needsEnvelopeField=de;exports.readUseOptions=Gt;exports.readUsePlugins=Vt;exports.tsHostBinding=Nt;exports.validateLayer=ut;exports.wireObservers=ge;exports.wrapMcpStructuredContent=_t;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("ts-morph");require("node:fs");require("node:path");require("ts-json-schema-generator");const O=require("pino"),Ue=require("ajv"),De=require("ajv-formats"),I="$apigen";class V extends Error{constructor(t){super(t),this.code="E_DUP_CODEC",this.name="CodecRegistryError"}}function Le(e){const t=new Map;return{register(r,n){if(t.has(r.id)&&!(n!=null&&n.override))throw new V(`E_DUP_CODEC: a codec is already registered for id "${r.id}"`);t.set(r.id,r)},resolve(r){for(const n of t.values())if(n.matches(r))return n},get(r){return t.get(r)},ids(){return[...t.keys()]},freeze(){const r=new Map(t),n={register(){throw new V("E_DUP_CODEC: registry is frozen and cannot accept new codecs")},resolve(o){for(const i of r.values())if(i.matches(o))return i},get(o){return r.get(o)},ids(){return[...r.keys()]},freeze(){return n}};return n}}}const L="x-apigen-logical",R="x-apigen-codec",S="x-apigen-ctor",x="x-apigen-tojson",Re="0.1.0";function G(e,t){return{registry:e,resolve:r=>{throw new Error(`[apigen-logical] $ref "${r}" 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 v(e,t,r){const n=r.registry.resolve(t);if(n)return n.encode(e,t,r);const o=t.$ref;if(typeof o=="string"){const a=r.resolve(o);return v(e,a,r)}const i=t.oneOf;if(Array.isArray(i)){const a=ue(e,i,t);return v(e,a,r)}const s=t.type;if(s==="array"){if(!Array.isArray(e))return _(e,t,r);const a=t.items;if(!a)return e.map(c=>w(c));const f=r.path;return Array.isArray(a)?e.map((c,u)=>{const l=a[u];return l===void 0?w(c):v(c,l,{...r,path:`${f}/${u}`})}):e.map((c,u)=>v(c,a,{...r,path:`${f}/${u}`}))}if(s==="object"){if(e===null||typeof e!="object"||Array.isArray(e))return _(e,t,r);const a=t.properties;if(!a)return w(e);const f=r.path,c={};for(const[u,l]of Object.entries(a)){const p=e[u];p!==void 0&&(c[u]=v(p,l,{...r,path:`${f}/${u}`}))}return c}return s==null?_(e,t,r):w(e)}function $(e,t,r){const n=r.registry.resolve(t);if(n)return n.decode(e,t,r);const o=t.$ref;if(typeof o=="string"){const a=r.resolve(o);return $(e,a,r)}const i=t.oneOf;if(Array.isArray(i)){const a=ue(e,i,t);return $(e,a,r)}const s=t.type;if(s==="array"){if(!Array.isArray(e))return e;const a=t.items;if(!a)return e;const f=r.path;return Array.isArray(a)?e.map((c,u)=>{const l=a[u];return l===void 0?c:$(c,l,{...r,path:`${f}/${u}`})}):e.map((c,u)=>$(c,a,{...r,path:`${f}/${u}`}))}if(s==="object"){if(e===null||typeof e!="object"||Array.isArray(e))return e;const a=t.properties;if(!a)return e;const f=r.path,c={};for(const[u,l]of Object.entries(a)){const p=e[u];p!==void 0&&(c[u]=$(p,l,{...r,path:`${f}/${u}`}))}return c}return s==null?Be(e,r):e}function ue(e,t,r,n){const o=r.discriminator;if(o!=null&&o.propertyName){const i=e!==null&&typeof e=="object"?e[o.propertyName]:void 0;if(typeof i=="string"&&o.mapping){const s=o.mapping[i];if(s){const a=t.find(f=>f.$ref===s);if(a)return a}}}return t[0]??{}}function _(e,t,r){for(const n of r.registry.ids()){const o=r.registry.get(n);if(o)try{const i=o.encode(e,o.schema,r);return{[I]:n,v:i}}catch{}}return w(e)}function Be(e,t){if(e!==null&&typeof e=="object"&&!Array.isArray(e)&&I in e){const r=e,n=r[I],o=t.registry.get(n);if(o)return o.decode(r.v,o.schema,t)}return e}function w(e){if(e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean")return e;if(Array.isArray(e))return e.map(w);if(typeof e=="object"){const t={};for(const[r,n]of Object.entries(e))n!==void 0&&(t[r]=w(n));return t}return null}function Fe(e){return{encode(t,r,n){const o=G(e,n);return v(t,r,o)},decode(t,r,n){const o=G(e,n);return $(t,r,o)}}}const B={id:"date-time",kind:"scalar",schema:{type:"string",format:"date-time"},matches(e){return e.type==="string"&&e.format==="date-time"},encode(e,t,r){return e.toISOString()},decode(e,t,r){if(typeof e!="string"){if(r.mode==="strict")throw new TypeError(`[date-time] expected a string on the wire at "${r.path}", got ${typeof e}`);return new Date(String(e))}if(r.mode==="strict"&&Number.isNaN(new Date(e).getTime()))throw new TypeError(`[date-time] invalid date-time string at "${r.path}": ${JSON.stringify(e)}`);return new Date(e)}},F={id:"int64",kind:"scalar",schema:{type:"string",format:"int64"},matches(e){return e.type==="string"&&e.format==="int64"},encode(e,t,r){return String(e)},decode(e,t,r){if(typeof e!="string"){if(r.mode==="strict")throw new TypeError(`[int64] expected a string on the wire at "${r.path}", got ${typeof e}`);try{return BigInt(Math.trunc(Number(e)))}catch{return BigInt(0)}}if(r.mode==="strict")return BigInt(e);if(/^-?\d+$/.test(e))try{return BigInt(e)}catch{return BigInt(0)}return BigInt(0)}},q={id:"decimal",kind:"scalar",schema:{type:"string",format:"decimal"},matches(e){return e.type==="string"&&e.format==="decimal"},encode(e,t,r){return e},decode(e,t,r){if(typeof e!="string"){if(r.mode==="strict")throw new TypeError(`[decimal] expected a string on the wire at "${r.path}", got ${typeof e}`);return String(e)}if(r.mode==="strict"&&!/^-?\d+(\.\d+)?$/.test(e))throw new TypeError(`[decimal] wire value "${e}" at "${r.path}" is not a valid decimal string`);return e}},H={id:"byte",kind:"scalar",schema:{type:"string",format:"byte"},matches(e){return e.type==="string"&&e.format==="byte"},encode(e,t,r){return Buffer.from(e).toString("base64")},decode(e,t,r){if(typeof e!="string"){if(r.mode==="strict")throw new TypeError(`[byte] expected a base64 string on the wire at "${r.path}", got ${typeof e}`);return new Uint8Array(0)}if(r.mode==="strict"&&!/^[A-Za-z0-9+/]*={0,2}$/.test(e))throw new TypeError(`[byte] wire value at "${r.path}" is not standard base64 (format:byte): "${e}"`);return new Uint8Array(Buffer.from(e,"base64"))}},qe=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,K={id:"uuid",kind:"scalar",schema:{type:"string",format:"uuid"},matches(e){return e.type==="string"&&e.format==="uuid"},encode(e,t,r){return e.toLowerCase()},decode(e,t,r){if(typeof e!="string"){if(r.mode==="strict")throw new TypeError(`[uuid] expected a string on the wire at "${r.path}", got ${typeof e}`);return String(e).toLowerCase()}if(r.mode==="strict"&&!qe.test(e))throw new TypeError(`[uuid] wire value "${e}" at "${r.path}" is not a lowercase-hyphenated RFC 4122 UUID`);return e}},M="NaN",T="Infinity",P="-Infinity",He=new Set([M,T,P]),W={id:"number-special",kind:"scalar",schema:{type:"number"},matches(e){return e.type==="number"&&e.format===void 0},encode(e,t,r){return Number.isNaN(e)?M:e===1/0?T:e===-1/0?P:e},decode(e,t,r){if(typeof e=="number")return e;if(typeof e=="string"){if(e===M)return NaN;if(e===T)return 1/0;if(e===P)return-1/0;const n=Number(e);if(!Number.isNaN(n))return n}if(r.mode==="strict")throw new TypeError(`[number-special] unrecognized wire value at "${r.path}": ${JSON.stringify(e)}. Expected a number or one of ${[...He].join(", ")}.`);return NaN}},Ke=[B,F,q,H,K,W];function We(e,t={}){for(const r of Ke)e.register(r,{override:t.override??!1})}B.id,F.id,q.id,H.id,K.id,W.id;const fe=Le();We(fe);const le=Fe(fe.freeze());function de(e,t){var n;const r=((n=e.input)==null?void 0:n.properties)??{};return t in r}function pe(e){var r,n;const t=(n=(r=e.input)==null?void 0:r.properties)==null?void 0:n.data;return Object.keys((t==null?void 0:t.properties)??{})}function ze(e,t){var o,i,s;const r=(s=(i=(o=e.input)==null?void 0:o.properties)==null?void 0:i.data)==null?void 0:s.properties,n=r==null?void 0:r[t];return n!==void 0?n:void 0}function Ve(e,t){return t===void 0||e===void 0?e:le.decode(e,t)}function E(e,t){const r=t.output;return!r||Object.keys(r).length===0?e:le.encode(e,r)}async function ye(e,t,r,n,o,i){const a=pe(r).map(c=>Ve(i[c],ze(r,c)));if(de(r,"session")&&t){const c=await t({session:o.session}),u=await e[n](c,...a);return E(u,r)}if(r.hasCtx){const c=t?await t(o):void 0,u=await e[n](c,...a);return E(u,r)}const f=await e[n](...a);return E(f,r)}class me{constructor(){this._map=new Map}set(t,r){this._map.set(t,r)}get(t){return this._map.get(t)}has(t){return this._map.has(t)}}function he(e=[]){return async function(r,n,o){const i=o.schemas[r];if(!i)throw new Error(`apigen/invoke: no schema found for operation "${r}"`);const s=()=>ye(o.fns,o.createClient,i,r,n.envelope,n.domainArgs);return e.reduceRight((f,c)=>()=>c(n,f),s)()}}function Ge(e){return e}class ge{constructor(){this.handlers=new Map}on(t,r){const n=this.handlers.get(t)??[];return this.handlers.set(t,[...n,r]),()=>this.off(t,r)}off(t,r){const n=this.handlers.get(t);if(!n)return;const o=n.filter(i=>i!==r);o.length===0?this.handlers.delete(t):this.handlers.set(t,o)}clear(){this.handlers.clear()}async emit(t){for(const[r,n]of this.handlers)if(Je(r,t))for(const o of n)await o(t)}}function Je(e,t){const[r,n,o]=e.split(":");return!(r!=="*"&&r!==t.module||n&&n!=="*"&&n!==t.method||o&&o!=="*"&&o!==t.lifecycle)}function we(e,t){for(const r of e)if(r.eventMapping)for(const[n,o]of Object.entries(r.eventMapping))t.on(n,o)}async function be(e,t,r){let n={...t};for(const o of e)if(o.createContext){await r.emit({module:o.id,method:"createContext",lifecycle:"start",ctx:n});try{const i=await o.createContext(n);n={...n,...i},await r.emit({module:o.id,method:"createContext",lifecycle:"complete",ctx:n})}catch(i){throw await r.emit({module:o.id,method:"createContext",lifecycle:"error",ctx:n,error:i}),i}}return n}function J(e,t){const r=new Set,n=[e];for(;n.length>0;){const o=n.pop();if(!o||r.has(o))continue;r.add(o);const i=o.$ref;if(typeof i=="string"){if(t){const l=t[i];if(!l){const p=Object.keys(t).join(", ")||"(none)";throw new Error(`[apigen-logical] $ref "${i}" cannot be resolved. Available $defs: ${p}`)}n.push(l)}continue}const s=o.oneOf;if(Array.isArray(s))for(const l of s)typeof l=="object"&&l!==null&&n.push(l);const a=o.properties;if(a)for(const l of Object.values(a))n.push(l);const f=o.items;if(Array.isArray(f))for(const l of f)typeof l=="object"&&l!==null&&n.push(l);else typeof f=="object"&&f!==null&&n.push(f);const c=o.additionalProperties;typeof c=="object"&&c!==null&&n.push(c);const u=o.propertyNames;typeof u=="object"&&u!==null&&n.push(u)}}const Y=new Set(["string","number","boolean","integer"]);function Ye(e){if(typeof e!="object"||e===null)return!1;const t=e;if(t.$ref!==void 0||t.oneOf||t.anyOf||t.allOf)return!1;const{type:r}=t;return typeof r=="string"?Y.has(r):Array.isArray(r)?r.every(n=>Y.has(n)||n==="null"):Array.isArray(t.enum)&&t.enum.length>0?t.enum.every(n=>["string","number","boolean"].includes(typeof n)):!1}function Xe(e){if(!e||typeof e!="object")return!1;const t=e.properties;return t===void 0||typeof t!="object"||t===null?!1:Object.values(t).every(Ye)}function Qe(e){const t={},r=n=>{for(const o of["definitions","$defs"]){const i=n[o];if(i)for(const[s,a]of Object.entries(i)){const f=s.startsWith("#/")?s:`#/${o}/${s}`;t[f]=a}}};for(const n of Object.values(e.schemas))r(n.input),r(n.output);if(Object.keys(t).length!==0)for(const[n,o]of Object.entries(e.schemas))try{J(o.input,t),J(o.output,t)}catch(i){throw new Error(`[apigen-core-client] Schema validation failed for function "${n}": ${i.message}`)}}function Ze(e,t){const r=['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&&r.push(`Field(s) ${e.map(n=>`"${n}"`).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.`),r.join(" ")}function et(e,t,r){Qe(e);const n={};for(const[o,i]of Object.entries(e.schemas)){const s=(r==null?void 0:r[o])??{},a=i.input.properties??{},f=i.input.required??[],c={},u=[],l={};for(const h of t)if(h.envelope&&s[h.id]!==!1)for(const[b,Pe]of Object.entries(h.envelope))c[b]=Pe,l[b]=h.id,u.includes(b)||u.push(b);const p={type:"object",properties:a,additionalProperties:!1,...f.length>0?{required:f}:{}},m=i.safe===!0||Xe(i.input),d=i.input.definitions,y=i.input.$defs;n[o]={input:{type:"object",properties:{...c,data:p},required:[...u,...f.length>0?["data"]:[]],additionalProperties:!1,description:Ze(Object.keys(c),Object.keys(a).length>0),...d?{definitions:d}:{},...y?{$defs:y}:{}},output:i.output,...i.hasCtx?{hasCtx:!0}:{},"x-apigen-safe":m,...Object.keys(l).length>0?{"x-apigen-envelope":l}:{}}}return n}const tt={"decimal.js":"Decimal"};function rt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}Object.entries(tt).map(([e,t])=>({pattern:new RegExp(`import\\(["'][^"']*${rt(e)}[^"']*["']\\)\\.\\w+`,"g"),key:t}));class U extends Error{constructor(t){super(t),this.name="ConfigurationError"}}function ve(e){for(const t of e)for(const r of Object.keys(t.eventMapping??{})){const[n]=r.split(":");if(n!=="*"&&n===t.id)throw new U(`Middleware "${t.id}" subscribes to its own events via "${r}". This would cause infinite recursion.`)}}function nt(e){const{domainSchemas:t,middlewares:r,overrides:n={},strict:o=!1}=e;ve(r);for(const c of Object.keys(n))if(!(c in t.schemas)){const u=`Override key "${c}" not found in domain schemas.`;if(o)throw new U(u);console.warn("[apigen-runtime]",u)}const i=new Set(r.map(c=>c.id));for(const[c,u]of Object.entries(n))for(const l of Object.keys(u??{}))if(!i.has(l)){const p=`Override key "${c}.${l}" does not match any declared middleware id.`;if(o)throw new U(p);console.warn("[apigen-runtime]",p)}const s=et(t,r,n),a=new ge;return we(r,a),{schemas:s,createClient:async c=>be(r,c,a),dispose:()=>a.clear()}}function ot(e={}){const t=e.level??"info",r=typeof e.destination=="string"&&e.destination.length>0,n=!r&&!!process.stderr.isTTY,o=e.format??(n?"pretty":"json"),i={level:t};if(o==="pretty")return i.transport={target:"pino-pretty",options:{colorize:!r,translateTime:"SYS:HH:MM:ss.l",ignore:"pid,hostname",...r?{destination:e.destination,mkdir:!0}:{destination:2}}},O(i);const s=r?O.destination({dest:e.destination,mkdir:!0,sync:!0}):O.destination(2);return O(i,s)}function $e(e){return e?e.type==="array"?`${$e(e.items)}[]`:e.enum?"enum":e.$ref?String(e.$ref).split("/").pop()||"object":e.anyOf||e.oneOf?"union":e.type??"object":"unknown"}function Ne(e){var a;const r=(a=((e==null?void 0:e.input)??{}).properties)==null?void 0:a.data,n=(r==null?void 0:r.properties)??{},o=new Set((r==null?void 0:r.required)??[]),i=Object.entries(n).map(([f,c])=>({name:f,type:$e(c),required:o.has(f)})),s=i.map(f=>`${f.name}${f.required?"":"?"}: ${f.type}`).join(", ");return{params:i,text:s}}function it(e){let t;return Array.isArray(e)?t=e:e?t=[e]:t=[],t.find(r=>r==="number"||r==="integer"||r==="boolean")}function st(e,t){var i,s;const n=((s=(i=((t==null?void 0:t.input)??{}).properties)==null?void 0:i.data)==null?void 0:s.properties)??{},o={...e};for(const[a,f]of Object.entries(n)){const c=o[a];if(typeof c!="string")continue;const u=it(f==null?void 0:f.type);if(u==="number"||u==="integer"){const l=Number(c);!Number.isNaN(l)&&c.trim()!==""&&(o[a]=l)}else u==="boolean"&&(c==="true"?o[a]=!0:c==="false"&&(o[a]=!1))}return o}const X=new Set(["default","module.exports","__esModule"]);function at(e){const t={},r=(n,o)=>{for(const[i,s]of Object.entries(n))if(typeof s=="function"){!X.has(i)&&!(i in t)&&(t[i]=s);const a=s.name;a&&!(a in t)&&(t[a]=s)}else s&&typeof s=="object"&&o<2&&X.has(i)&&r(s,o+1)};return r(e,0),t}const ct=["invalid_argument","unauthenticated","permission_denied","not_found","internal"];class A extends Error{constructor(t,r,n){super(r),this.name="ApiError",this.code=t,this.details=n,Object.setPrototypeOf(this,new.target.prototype)}toJSON(){const t={code:this.code,message:this.message};return this.details!==void 0&&(t.details=this.details),t}}function Oe(e){return typeof e=="object"&&e!==null&&e.name==="ApiError"&&ct.includes(e.code)&&typeof e.toJSON=="function"}function Q(e,t,r=0){return e==="before-first-chunk"?{phase:e,error:t}:{phase:e,error:t,chunksDelivered:r}}const N=new Ue({allErrors:!0});De(N);for(const e of[L,R,S,x,"discriminator"])N.addKeyword({keyword:e,valid:!0});N.addFormat("decimal",/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)$/);function je(e){return e.map(t=>`${t.instancePath||"(root)"} ${t.message??"failed schema check"}`).join("; ")}const ut=async(e,t)=>{const r=e.ctx.get(Ae);if(r===void 0)return t();const n=e.operation.id,o=r[n];if(o===void 0)return t();const i={data:e.domainArgs,...e.envelope},s=N.compile(o.input);if(!s(i)){const f=s.errors??[];throw new A("invalid_argument",`Validation failed: ${je(f)}`,f)}return t()},Ae=Symbol("ValidateSchemasToken");function _e(e){return async function(r,n){const o=r.operation.id,i=e[o];if(i===void 0)return n();const s={data:r.domainArgs,...r.envelope},a=N.compile(i.input);if(!a(s)){const c=a.errors??[];throw new A("invalid_argument",`Validation failed: ${je(c)}`,c)}return n()}}function ft(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}class lt{constructor(t={}){var n,o;this._store=new Map,this._sweeper=null,this._defaultTtlMs=t.defaultTtlMs;let r=null;t.sweepIntervalMs===0?r=null:t.sweepIntervalMs!==void 0?r=t.sweepIntervalMs:this._defaultTtlMs!==void 0?r=Math.max(1e3,Math.floor(this._defaultTtlMs/4)):r=null,r!==null&&r>0&&(this._sweeper=setInterval(()=>this._sweep(),r),(o=(n=this._sweeper).unref)==null||o.call(n))}create(t,r=[],n){const o=new t(...r),i=ft(),s=n??this._defaultTtlMs,a=s!==void 0?Date.now()+s:null;return this._store.set(i,{instance:o,expiresAt:a}),{instanceId:i}}get(t){const r=this._store.get(t);if(!r)throw new Error(`[instance-registry] Unknown instanceId: "${t}"`);if(r.expiresAt!==null&&Date.now()>r.expiresAt)throw this._evict(t,r),new Error(`[instance-registry] Instance "${t}" has expired`);return r.instance}async dispatch(t,r,n=[]){const o=this.get(t),i=o[r];if(typeof i!="function")throw new Error(`[instance-registry] Method "${r}" not found on instance "${t}"`);return i.call(o,...n)}async dispose(t){const r=this._store.get(t);r&&(this._store.delete(t),await C(r.instance))}async disposeAll(){this._sweeper!==null&&(clearInterval(this._sweeper),this._sweeper=null);const t=[...this._store.entries()];this._store.clear(),await Promise.all(t.map(([,r])=>C(r.instance)))}get size(){return this._store.size}_sweep(){const t=Date.now();for(const[r,n]of this._store)n.expiresAt!==null&&t>n.expiresAt&&this._evict(r,n)}_evict(t,r){this._store.delete(t),C(r.instance)}}async function C(e){if(e!==null&&typeof e=="object"&&"dispose"in e){const t=e.dispose;typeof t=="function"&&await t.call(e)}}function dt(e){const{produce:t,signal:r}=e,n=r??new AbortController().signal;return{[Symbol.asyncIterator](){const o=t(n);return{async next(){return n.aborted?(await o.return(void 0),{done:!0,value:void 0}):o.next()},async return(i){return await o.return(i),{done:!0,value:void 0}},async throw(i){return await o.throw(i),{done:!0,value:void 0}}}}}}async function pt(e){const t=[];for await(const r of e)t.push(r);return t}async function Ee(e){const t=[];try{for await(const r of e)t.push(r);return{ok:!0,chunks:t}}catch(r){const n=Oe(r)?r:new A("internal",r instanceof Error?r.message:String(r));return t.length===0?{ok:!1,carrier:Q("before-first-chunk",n)}:{ok:!1,carrier:Q("after-first-chunk",n,t.length)}}}function Ce(e){return e!==null&&typeof e=="object"&&Symbol.asyncIterator in e}class g extends Error{constructor(t,r){super(r),this.name="UnionCodecError",this.code=t}}function k(e){const t=e.discriminator;if(t===null||typeof t!="object"||Array.isArray(t))return;const r=t;if(typeof r.propertyName!="string")return;const n=r.mapping;if(!(n===null||typeof n!="object"||Array.isArray(n)))return{propertyName:r.propertyName,mapping:n}}function ke(e,t){const r=e[R];if(typeof r=="string"){const n=t.registry.get(r);if(n)return n}return t.registry.resolve(e)}function yt(e,t,r){const n=ke(t,r);return n?n.encode(e,t,r):e}function mt(e,t,r){const n=ke(t,r);return n?n.decode(e,t,r):e}function Ie(e){const{id:t,schema:r}=e;return{id:t,kind:"union",schema:r,matches(n){if(n[L]==="union")return!0;const o=n.oneOf;return!Array.isArray(o)||o.length===0?!1:k(n)!==void 0},encode(n,o,i){const s=k(o);if(!s)throw new g("E_UNION_NO_DISCRIMINATOR",`[${t}] schema node at "${i.path}" has no discriminator.propertyName; cannot dispatch union branch.`);const{propertyName:a,mapping:f}=s,c=n[a];if(c==null)throw new g("E_UNION_NO_DISCRIMINATOR",`[${t}] value at "${i.path}" is missing the discriminator property "${a}".`);const u=String(c),l=f[u];if(!l)throw new g("E_UNION_UNKNOWN_TAG",`[${t}] discriminator tag "${u}" at "${i.path}" is not in the mapping (known: ${Object.keys(f).join(", ")}).`);const p=i.resolve(l);return yt(n,p,{...i,path:`${i.path}[${u}]`})},decode(n,o,i){if(n===null||typeof n!="object"||Array.isArray(n)){let d;throw n===null?d="null":Array.isArray(n)?d="array":d=typeof n,new g("E_UNION_INVALID_WIRE",`[${t}] expected a JSON object on the wire at "${i.path}", got ${d}.`)}const s=n,a=k(o);if(!a)throw new g("E_UNION_NO_DISCRIMINATOR",`[${t}] schema node at "${i.path}" has no discriminator.propertyName; cannot dispatch union branch.`);const{propertyName:f,mapping:c}=a,u=s[f];if(u==null)throw new g("E_UNION_NO_DISCRIMINATOR",`[${t}] wire object at "${i.path}" is missing the discriminator property "${f}".`);const l=String(u),p=c[l];if(!p)throw new g("E_UNION_UNKNOWN_TAG",`[${t}] discriminator tag "${l}" on the wire at "${i.path}" is not in the mapping (known: ${Object.keys(c).join(", ")}).`);const m=i.resolve(p);return mt(n,m,{...i,path:`${i.path}[${l}]`})}}}const ht="x-apigen-instances";class j extends Error{constructor(t,r){super(r),this.name="NominalCodecError",this.code=t}}function Z(e){const t=e.properties;return t&&typeof t=="object"&&!Array.isArray(t)?t:{}}function gt(e){const t=e.required;return Array.isArray(t)?t.filter(r=>typeof r=="string"):[]}function ee(e,t,r){if(t){const n=r.registry.resolve(t);if(n)return n.encode(e,t,r)}return e}function wt(e,t,r){if(t){const n=r.registry.resolve(t);if(n)return n.decode(e,t,r)}return e}function bt(e){const{id:t,schema:r,ctor:n}=e;return{id:t,kind:"nominal",schema:r,matches(o){return o[L]==="nominal"?!0:o[R]===t},encode(o,i,s){if(o===null||typeof o!="object")return o;if(s.seen.has(o)){if(s.mode==="strict")throw new j("E_NOMINAL_CYCLE",`[${t}] cycle detected at "${s.path}": a nominal instance references itself. Strict mode rejects cycles (DESIGN ยง8.3); break the cycle or use 'lossy' mode.`);return null}s.seen.add(o);try{const a=Z(i),f=typeof i[x]=="string"?i[x]:"toJSON",c=o[f];if(typeof c=="function"){const d=c.call(o);if(d!==null&&typeof d=="object"&&!Array.isArray(d)){const y={};for(const[h,b]of Object.entries(d))y[h]=ee(b,a[h],{...s,path:`${s.path}/${h}`});return y}return d}const u={},l=Object.keys(a),p=o,m=l.length>0?l:Object.keys(p);for(const d of m){const y=p[d];y!==void 0&&(u[d]=ee(y,a[d],{...s,path:`${s.path}/${d}`}))}return u}finally{s.seen.delete(o)}},decode(o,i,s){if(o===null||typeof o!="object"||Array.isArray(o)){let u;throw o===null?u="null":Array.isArray(o)?u="array":u=typeof o,new j("E_NOMINAL_INVALID_WIRE",`[${t}] expected a JSON object on the wire at "${s.path}", got ${u}.`)}const a=o;for(const u of gt(i))if(!(u in a))throw new j("E_NOMINAL_INVALID_WIRE",`[${t}] required field "${u}" missing on the wire at "${s.path}".`);if(i[ht]===!1)throw new j("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.`);const f=Z(i),c={};for(const[u,l]of Object.entries(a))c[u]=wt(l,f[u],{...s,path:`${s.path}/${u}`});if(n){const u=typeof i[S]=="string"?i[S]:"fromJSON",l=n[u];if(typeof l=="function")return l.call(n,c);const p=n;return new p(c)}return c}}}const Se=[B,F,q,H,K,W],vt={type:"object","x-apigen-logical":"nominal","x-apigen-codec":"ts.NominalSentinel"},te=bt({id:"ts.NominalSentinel",schema:vt}),$t={oneOf:[],discriminator:{propertyName:"kind",mapping:{}},"x-apigen-logical":"union","x-apigen-codec":"ts.UnionSentinel"},re=Ie({id:"ts.UnionSentinel",schema:$t});function Nt(){const e=[...Se.map(t=>[t.id,t]),[te.id,te],[re.id,re]];return Object.freeze(new Map(e))}const Ot=Object.freeze({host:"ts",logicalTypeVersion:Re,codecs:Nt()});function jt(e,t,r){var i;const n=typeof((i=t==null?void 0:t.input)==null?void 0:i.description)=="string"?t.input.description:void 0,o=[r,n].filter(s=>typeof s=="string"&&s.length>0);return o.length>0?o.join(" โ€” "):e}function At(e){if(!e||typeof e!="object"||Array.isArray(e)||Object.keys(e).length===0)return{outputSchema:void 0,wrapped:!1};const t=e;return t.type==="object"?{outputSchema:t,wrapped:!1}:{outputSchema:{type:"object",properties:{result:t},required:["result"]},wrapped:!0}}function _t(e,t){return e?{result:t}:t&&typeof t=="object"&&!Array.isArray(t)?t:void 0}const xe=4,Me=32;function D(e){return Oe(e)?e:e instanceof Error?new A("internal",e.message):e}function Et(e,t){if(e==="serial"||e==="chained")return 1;const r=t??xe;return!Number.isFinite(r)||r<1?1:Math.min(Math.floor(r),Me)}function Ct(){}function kt(e,t){var i;if(!e&&!t)return{signal:void 0,dispose:Ct};const r=new AbortController,n=()=>{r.abort(e==null?void 0:e.reason)};e&&(e.aborted?r.abort(e.reason):e.addEventListener("abort",n,{once:!0}));let o;return t!==void 0&&!r.signal.aborted&&(o=setTimeout(()=>{r.abort(new DOMException(`apigen/invokeBatch: item timed out after ${t}ms`,"TimeoutError"))},t),(i=o.unref)==null||i.call(o)),{signal:r.signal,dispose(){e&&e.removeEventListener("abort",n),o&&clearTimeout(o)}}}async function ne(e,t,r,n,o,i){const s=kt(n.signal,i);try{const a=s.signal?{...n,signal:s.signal}:n,f=await e(t,a,o);if(Ce(f)){const c=await Ee(f);if(c.ok)return{index:r,status:"fulfilled",chunks:c.chunks};const u=c.carrier;return{index:r,status:"rejected",reason:D(u.error),...u.phase==="after-first-chunk"?{chunksDelivered:u.chunksDelivered}:{}}}return{index:r,status:"fulfilled",value:f}}catch(a){return{index:r,status:"rejected",reason:D(a)}}finally{s.dispose()}}async function It(e,t,r,n,o={}){const i=o.mode??"parallel",s=o.onItemError??"continue",a=Et(i,o.concurrency),f=new Array(r.length),c=d=>({index:d,status:"rejected",reason:D(new Error("apigen/invokeBatch: not attempted โ€” an earlier item failed and "+(i==="chained"?'mode is "chained"':'onItemError is "abort"')))});if(i==="serial"||i==="chained"){let d=!1;for(let y=0;y<r.length;y++){if(d){f[y]=c(y);continue}const h=await ne(e,t,y,r[y],n,o.itemTimeoutMs);f[y]=h,h.status==="rejected"&&(i==="chained"||s==="abort")&&(d=!0)}return f}let u=0,l=!1;const p=Math.max(1,Math.min(a,r.length)),m=Array.from({length:p},async()=>{for(;;){const d=u++;if(d>=r.length)return;if(l){f[d]=c(d);continue}const y=await ne(e,t,d,r[d],n,o.itemTimeoutMs);f[d]=y,y.status==="rejected"&&s==="abort"&&(l=!0)}});return await Promise.all(m),f}const oe=new Set(["string","number","boolean","integer"]);function St(e){if(typeof e!="object"||e===null)return!1;const t=e;if(t.$ref!==void 0||t.oneOf||t.anyOf||t.allOf)return!1;const{type:r}=t;return typeof r=="string"?oe.has(r):Array.isArray(r)?r.every(n=>oe.has(n)||n==="null"):Array.isArray(t.enum)&&t.enum.length>0?t.enum.every(n=>["string","number","boolean"].includes(typeof n)):!1}function xt(e){if(!e||typeof e!="object")return!1;const t=e.properties;return t===void 0||typeof t!="object"||t===null?!1:Object.values(t).every(St)}const Mt={"decimal.js":"Decimal"};function Tt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}Object.entries(Mt).map(([e,t])=>({pattern:new RegExp(`import\\(["'][^"']*${Tt(e)}[^"']*["']\\)\\.\\w+`,"g"),key:t}));function ie(e){return e.words.join("-")}function se(e){return e.words.map(Rt).join("")}function ae(e){return e.words.join("_")}function Pt(e,t={}){var r,n;const o=[e.namespace,...e.path],i=e.safe||xt(e.input)?"GET":"POST",s=((n=(r=t.http)==null?void 0:r.verb)==null?void 0:n[e.id])??i,a="/"+o.map(m=>ie(m)).join("/"),f=o.map(m=>ae(m)).join("_"),c=o.map(m=>ae(m)).slice(0,-1).join("."),u=se(o[o.length-2]??o[0]),l=se(o[o.length-1]),p=o.map(m=>ie(m));return{http:{verb:s,route:a},mcp:{name:f},grpc:{package:c,service:u,method:l},cli:{path:p}}}function Ut(e,t){return`x-${e}-${t}`}function Dt(e,t){return`--${e}-${t}`}function Lt(e,t){const r=n=>n.toUpperCase().replace(/-/g,"_");return e==="adhd"?`APIGEN_${r(t)}`:`APIGEN_${r(e)}_${r(t)}`}function Rt(e){return e.length===0?e:e[0].toUpperCase()+e.slice(1)}function z(e){return e.anyOf??e.oneOf}function Bt(e){if(!e)return!1;if(e.type==="array"||e.type==="object")return!0;const t=z(e);if(t){const r=t.filter(n=>n.type!=="null");return r.length>0&&r.every(n=>n.type==="array"||n.type==="object")}return!1}function Ft(e){if(!e)return!1;if(e.type==="boolean")return!0;const t=z(e);if(t){const r=t.filter(n=>n.type!=="null");return r.length>0&&r.every(n=>n.type==="boolean")}return!1}function qt(e){if(!e)return!1;if(e.type==="number"||e.type==="integer")return!0;const t=z(e);if(t){const r=t.filter(n=>n.type!=="null");return r.length>0&&r.every(n=>n.type==="number"||n.type==="integer")}return!1}function Ht(e){return e.replace(/[A-Z]/g,t=>"-"+t.toLowerCase())}function Kt(e){var o,i;const t=(i=(o=e.input)==null?void 0:o.properties)==null?void 0:i.data,r=(t==null?void 0:t.properties)??{},n=(t==null?void 0:t.required)??[];return{props:r,required:n}}function ce(e){return typeof e.handler=="function"}function Wt(e){var o;const t=((o=e.input)==null?void 0:o.properties)??{},r=e["x-apigen-envelope"],n=[];for(const i of Object.keys(t)){if(i==="data")continue;const s=(r==null?void 0:r[i])??"adhd",a=Ut(s,i);n.push({field:i,pluginId:s,httpHeader:a,mcpMetaKey:a,cliFlag:Dt(s,i),envVar:Lt(s,i)})}return n}function zt(e,t){const r=new Map,{props:n}=Kt(e);for(const[o,i]of Object.entries(n)){let s="string";Ft(i)?s="boolean":(Bt(i)||qt(i))&&(s="json"),r.set(Ht(o),{camelKey:o,kind:"domain",valueKind:s})}for(const o of t){const i=o.cliFlag.replace(/^--/,"");r.set(i,{camelKey:o.field,kind:"envelope",valueKind:"string",envVar:o.envVar})}return r}function Vt(e){const{op:t,schema:r,transport:n,projection:o}=e,i=Pt(t,o),s=r?Wt(r):[],a=r?zt(r,s):new Map,f=r?Ne(r).params:void 0,c={op:t,transport:n,http:i.http,mcp:i.mcp,cli:i.cli,grpc:i.grpc,params:f,envelope:s,cliFlags:a,streaming:t.streaming,isMount:ce(t)};if(ce(t)){const u=t.handler;c.mountHandler=async l=>u(l)}return c}function Gt(e){const t=e.usePlugins;return Array.isArray(t)?t:[]}function Jt(e){const t=e.useOptions;return t&&typeof t=="object"?t:{}}function Te(e){return async function(r,n){const o=Object.assign(r,{data:r.domainArgs});return await e.layer(o,n)}}function Yt(e,t){var n;const r=[];for(const o of t){const i=(n=o.capabilities)==null?void 0:n.layer;i&&r.push(Te(i))}return r.push(_e(e)),he(r)}function Xt(){const e=new Map;return{get:t=>e.get(t),set:(t,r)=>{e.set(t,r)}}}const Qt={input:{type:"object",properties:{data:{type:"object",properties:{}}}},output:{}};async function Zt(e,t,r,n){const o={...r,operation:{id:e.op.id},ctx:new me};if(e.isMount){const i=e.mountHandler;if(!i)throw new Error(`apigen-engine-runtime/dispatchForPlan: OpPlan for mount op "${e.op.id}" has isMount=true but no mountHandler`);const s={operation:e.op,data:r.domainArgs,envelope:r.envelope,ctx:Xt(),transport:e.transport,signal:r.signal??new AbortController().signal},a={...n,fns:{[e.op.id]:()=>i(s)},schemas:{[e.op.id]:Qt}};return t(e.op.id,o,a)}return t(e.op.id,o,n)}exports.BATCH_DEFAULT_CONCURRENCY=xe;exports.BATCH_MAX_CONCURRENCY=Me;exports.EventBus=ge;exports.InstanceRegistry=lt;exports.LayerContext=me;exports.UnionCodecError=g;exports.ValidateSchemasToken=Ae;exports.WELL_KNOWN_TS_CODECS=Se;exports.adaptCoreLayer=Te;exports.assertNoSelfSubscription=ve;exports.buildContext=be;exports.buildFnTable=at;exports.buildMcpOutputSchema=At;exports.buildOpPlan=Vt;exports.buildToolDescription=jt;exports.coerceQueryParams=st;exports.collectWithPhase=Ee;exports.createApiPackage=nt;exports.createInvoker=he;exports.createLogger=ot;exports.createPackageInvoker=Yt;exports.createStream=dt;exports.createUnionCodec=Ie;exports.dataParamNames=pe;exports.defineMiddleware=Ge;exports.describeParams=Ne;exports.dispatch=ye;exports.dispatchForPlan=Zt;exports.drainStream=pt;exports.invokeBatch=It;exports.isApiStream=Ce;exports.makeValidateLayer=_e;exports.needsEnvelopeField=de;exports.readUseOptions=Jt;exports.readUsePlugins=Gt;exports.tsHostBinding=Ot;exports.validateLayer=ut;exports.wireObservers=we;exports.wrapMcpStructuredContent=_t;
package/index.mjs CHANGED
@@ -2,11 +2,11 @@ import "ts-morph";
2
2
  import "node:fs";
3
3
  import "node:path";
4
4
  import "ts-json-schema-generator";
5
- import O from "pino";
5
+ import N from "pino";
6
6
  import ge from "ajv";
7
7
  import we from "ajv-formats";
8
8
  const C = "$apigen";
9
- class V extends Error {
9
+ class W extends Error {
10
10
  constructor(t) {
11
11
  super(t), this.code = "E_DUP_CODEC", this.name = "CodecRegistryError";
12
12
  }
@@ -16,7 +16,7 @@ function be(e) {
16
16
  return {
17
17
  register(r, n) {
18
18
  if (t.has(r.id) && !(n != null && n.override))
19
- throw new V(
19
+ throw new W(
20
20
  `E_DUP_CODEC: a codec is already registered for id "${r.id}"`
21
21
  );
22
22
  t.set(r.id, r);
@@ -35,7 +35,7 @@ function be(e) {
35
35
  freeze() {
36
36
  const r = new Map(t), n = {
37
37
  register() {
38
- throw new V(
38
+ throw new W(
39
39
  "E_DUP_CODEC: registry is frozen and cannot accept new codecs"
40
40
  );
41
41
  },
@@ -59,7 +59,7 @@ function be(e) {
59
59
  };
60
60
  }
61
61
  const L = "x-apigen-logical", R = "x-apigen-codec", S = "x-apigen-ctor", x = "x-apigen-tojson", ve = "0.1.0";
62
- function W(e, t) {
62
+ function G(e, t) {
63
63
  return {
64
64
  registry: e,
65
65
  resolve: (r) => {
@@ -84,7 +84,7 @@ function v(e, t, r) {
84
84
  }
85
85
  const i = t.oneOf;
86
86
  if (Array.isArray(i)) {
87
- const a = ce(e, i, t);
87
+ const a = ue(e, i, t);
88
88
  return v(e, a, r);
89
89
  }
90
90
  const s = t.type;
@@ -110,8 +110,8 @@ function v(e, t, r) {
110
110
  return w(e);
111
111
  const f = r.path, c = {};
112
112
  for (const [u, p] of Object.entries(a)) {
113
- const l = e[u];
114
- l !== void 0 && (c[u] = v(l, p, {
113
+ const d = e[u];
114
+ d !== void 0 && (c[u] = v(d, p, {
115
115
  ...r,
116
116
  path: `${f}/${u}`
117
117
  }));
@@ -131,7 +131,7 @@ function $(e, t, r) {
131
131
  }
132
132
  const i = t.oneOf;
133
133
  if (Array.isArray(i)) {
134
- const a = ce(e, i, t);
134
+ const a = ue(e, i, t);
135
135
  return $(e, a, r);
136
136
  }
137
137
  const s = t.type;
@@ -157,8 +157,8 @@ function $(e, t, r) {
157
157
  return e;
158
158
  const f = r.path, c = {};
159
159
  for (const [u, p] of Object.entries(a)) {
160
- const l = e[u];
161
- l !== void 0 && (c[u] = $(l, p, {
160
+ const d = e[u];
161
+ d !== void 0 && (c[u] = $(d, p, {
162
162
  ...r,
163
163
  path: `${f}/${u}`
164
164
  }));
@@ -167,7 +167,7 @@ function $(e, t, r) {
167
167
  }
168
168
  return s == null ? $e(e, r) : e;
169
169
  }
170
- function ce(e, t, r, n) {
170
+ function ue(e, t, r, n) {
171
171
  const o = r.discriminator;
172
172
  if (o != null && o.propertyName) {
173
173
  const i = e !== null && typeof e == "object" ? e[o.propertyName] : void 0;
@@ -218,11 +218,11 @@ function w(e) {
218
218
  function je(e) {
219
219
  return {
220
220
  encode(t, r, n) {
221
- const o = W(e, n);
221
+ const o = G(e, n);
222
222
  return v(t, r, o);
223
223
  },
224
224
  decode(t, r, n) {
225
- const o = W(e, n);
225
+ const o = G(e, n);
226
226
  return $(t, r, o);
227
227
  }
228
228
  };
@@ -331,7 +331,7 @@ const B = {
331
331
  );
332
332
  return new Uint8Array(Buffer.from(e, "base64"));
333
333
  }
334
- }, Oe = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/, q = {
334
+ }, Ne = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/, q = {
335
335
  id: "uuid",
336
336
  kind: "scalar",
337
337
  schema: { type: "string", format: "uuid" },
@@ -349,13 +349,13 @@ const B = {
349
349
  );
350
350
  return String(e).toLowerCase();
351
351
  }
352
- if (r.mode === "strict" && !Oe.test(e))
352
+ if (r.mode === "strict" && !Ne.test(e))
353
353
  throw new TypeError(
354
354
  `[uuid] wire value "${e}" at "${r.path}" is not a lowercase-hyphenated RFC 4122 UUID`
355
355
  );
356
356
  return e;
357
357
  }
358
- }, M = "NaN", T = "Infinity", P = "-Infinity", Ne = /* @__PURE__ */ new Set([
358
+ }, M = "NaN", T = "Infinity", P = "-Infinity", Oe = /* @__PURE__ */ new Set([
359
359
  M,
360
360
  T,
361
361
  P
@@ -385,7 +385,7 @@ const B = {
385
385
  }
386
386
  if (r.mode === "strict")
387
387
  throw new TypeError(
388
- `[number-special] unrecognized wire value at "${r.path}": ${JSON.stringify(e)}. Expected a number or one of ${[...Ne].join(", ")}.`
388
+ `[number-special] unrecognized wire value at "${r.path}": ${JSON.stringify(e)}. Expected a number or one of ${[...Oe].join(", ")}.`
389
389
  );
390
390
  return NaN;
391
391
  }
@@ -407,9 +407,9 @@ K.id, // 'decimal'
407
407
  H.id, // 'byte'
408
408
  q.id, // 'uuid'
409
409
  z.id;
410
- const ue = be();
411
- _e(ue);
412
- const fe = je(ue.freeze());
410
+ const fe = be();
411
+ _e(fe);
412
+ const pe = je(fe.freeze());
413
413
  function Ee(e, t) {
414
414
  var n;
415
415
  const r = ((n = e.input) == null ? void 0 : n.properties) ?? {};
@@ -426,11 +426,11 @@ function Ie(e, t) {
426
426
  return n !== void 0 ? n : void 0;
427
427
  }
428
428
  function Ce(e, t) {
429
- return t === void 0 || e === void 0 ? e : fe.decode(e, t);
429
+ return t === void 0 || e === void 0 ? e : pe.decode(e, t);
430
430
  }
431
431
  function E(e, t) {
432
432
  const r = t.output;
433
- return !r || Object.keys(r).length === 0 ? e : fe.encode(e, r);
433
+ return !r || Object.keys(r).length === 0 ? e : pe.encode(e, r);
434
434
  }
435
435
  async function Se(e, t, r, n, o, i) {
436
436
  const a = ke(r).map(
@@ -483,7 +483,7 @@ function Me(e = []) {
483
483
  )();
484
484
  };
485
485
  }
486
- function Ft(e) {
486
+ function Kt(e) {
487
487
  return e;
488
488
  }
489
489
  class Te {
@@ -558,7 +558,7 @@ async function Ue(e, t, r) {
558
558
  }
559
559
  return n;
560
560
  }
561
- function G(e, t) {
561
+ function J(e, t) {
562
562
  const r = /* @__PURE__ */ new Set(), n = [e];
563
563
  for (; n.length > 0; ) {
564
564
  const o = n.pop();
@@ -570,9 +570,9 @@ function G(e, t) {
570
570
  if (t) {
571
571
  const p = t[i];
572
572
  if (!p) {
573
- const l = Object.keys(t).join(", ") || "(none)";
573
+ const d = Object.keys(t).join(", ") || "(none)";
574
574
  throw new Error(
575
- `[apigen-logical] $ref "${i}" cannot be resolved. Available $defs: ${l}`
575
+ `[apigen-logical] $ref "${i}" cannot be resolved. Available $defs: ${d}`
576
576
  );
577
577
  }
578
578
  n.push(p);
@@ -599,7 +599,7 @@ function G(e, t) {
599
599
  typeof u == "object" && u !== null && n.push(u);
600
600
  }
601
601
  }
602
- const J = /* @__PURE__ */ new Set(["string", "number", "boolean", "integer"]);
602
+ const Y = /* @__PURE__ */ new Set(["string", "number", "boolean", "integer"]);
603
603
  function Le(e) {
604
604
  if (typeof e != "object" || e === null)
605
605
  return !1;
@@ -607,7 +607,7 @@ function Le(e) {
607
607
  if (t.$ref !== void 0 || t.oneOf || t.anyOf || t.allOf)
608
608
  return !1;
609
609
  const { type: r } = t;
610
- return typeof r == "string" ? J.has(r) : Array.isArray(r) ? r.every((n) => J.has(n) || n === "null") : Array.isArray(t.enum) && t.enum.length > 0 ? t.enum.every((n) => ["string", "number", "boolean"].includes(typeof n)) : !1;
610
+ return typeof r == "string" ? Y.has(r) : Array.isArray(r) ? r.every((n) => Y.has(n) || n === "null") : Array.isArray(t.enum) && t.enum.length > 0 ? t.enum.every((n) => ["string", "number", "boolean"].includes(typeof n)) : !1;
611
611
  }
612
612
  function Re(e) {
613
613
  if (!e || typeof e != "object")
@@ -633,7 +633,7 @@ function Be(e) {
633
633
  if (Object.keys(t).length !== 0)
634
634
  for (const [n, o] of Object.entries(e.schemas))
635
635
  try {
636
- G(o.input, t), G(o.output, t);
636
+ J(o.input, t), J(o.output, t);
637
637
  } catch (i) {
638
638
  throw new Error(
639
639
  `[apigen-core-client] Schema validation failed for function "${n}": ${i.message}`
@@ -657,16 +657,16 @@ function Ke(e, t, r) {
657
657
  if (h.envelope && s[h.id] !== !1)
658
658
  for (const [b, he] of Object.entries(h.envelope))
659
659
  c[b] = he, p[b] = h.id, u.includes(b) || u.push(b);
660
- const l = {
660
+ const d = {
661
661
  type: "object",
662
662
  properties: a,
663
663
  additionalProperties: !1,
664
664
  ...f.length > 0 ? { required: f } : {}
665
- }, m = i.safe === !0 || Re(i.input), d = i.input.definitions, y = i.input.$defs;
665
+ }, m = i.safe === !0 || Re(i.input), l = i.input.definitions, y = i.input.$defs;
666
666
  n[o] = {
667
667
  input: {
668
668
  type: "object",
669
- properties: { ...c, data: l },
669
+ properties: { ...c, data: d },
670
670
  required: [
671
671
  ...u,
672
672
  ...f.length > 0 ? ["data"] : []
@@ -679,7 +679,7 @@ function Ke(e, t, r) {
679
679
  Object.keys(c),
680
680
  Object.keys(a).length > 0
681
681
  ),
682
- ...d ? { definitions: d } : {},
682
+ ...l ? { definitions: l } : {},
683
683
  ...y ? { $defs: y } : {}
684
684
  },
685
685
  output: i.output,
@@ -729,7 +729,7 @@ function ze(e) {
729
729
  );
730
730
  }
731
731
  }
732
- function Kt(e) {
732
+ function Ht(e) {
733
733
  const {
734
734
  domainSchemas: t,
735
735
  middlewares: r,
@@ -748,10 +748,10 @@ function Kt(e) {
748
748
  for (const [c, u] of Object.entries(n))
749
749
  for (const p of Object.keys(u ?? {}))
750
750
  if (!i.has(p)) {
751
- const l = `Override key "${c}.${p}" does not match any declared middleware id.`;
751
+ const d = `Override key "${c}.${p}" does not match any declared middleware id.`;
752
752
  if (o)
753
- throw new D(l);
754
- console.warn("[apigen-runtime]", l);
753
+ throw new D(d);
754
+ console.warn("[apigen-runtime]", d);
755
755
  }
756
756
  const s = Ke(
757
757
  t,
@@ -760,7 +760,7 @@ function Kt(e) {
760
760
  ), a = new Te();
761
761
  return De(r, a), { schemas: s, createClient: async (c) => Ue(r, c, a), dispose: () => a.clear() };
762
762
  }
763
- function Ht(e = {}) {
763
+ function qt(e = {}) {
764
764
  const t = e.level ?? "info", r = typeof e.destination == "string" && e.destination.length > 0, n = !r && !!process.stderr.isTTY, o = e.format ?? (n ? "pretty" : "json"), i = { level: t };
765
765
  if (o === "pretty")
766
766
  return i.transport = {
@@ -771,18 +771,18 @@ function Ht(e = {}) {
771
771
  ignore: "pid,hostname",
772
772
  ...r ? { destination: e.destination, mkdir: !0 } : { destination: 2 }
773
773
  }
774
- }, O(i);
775
- const s = r ? O.destination({ dest: e.destination, mkdir: !0, sync: !0 }) : O.destination(2);
776
- return O(i, s);
774
+ }, N(i);
775
+ const s = r ? N.destination({ dest: e.destination, mkdir: !0, sync: !0 }) : N.destination(2);
776
+ return N(i, s);
777
777
  }
778
- function pe(e) {
779
- return e ? e.type === "array" ? `${pe(e.items)}[]` : e.enum ? "enum" : e.$ref ? String(e.$ref).split("/").pop() || "object" : e.anyOf || e.oneOf ? "union" : e.type ?? "object" : "unknown";
778
+ function le(e) {
779
+ return e ? e.type === "array" ? `${le(e.items)}[]` : e.enum ? "enum" : e.$ref ? String(e.$ref).split("/").pop() || "object" : e.anyOf || e.oneOf ? "union" : e.type ?? "object" : "unknown";
780
780
  }
781
781
  function Ve(e) {
782
782
  var a;
783
783
  const r = (a = ((e == null ? void 0 : e.input) ?? {}).properties) == null ? void 0 : a.data, n = (r == null ? void 0 : r.properties) ?? {}, o = new Set((r == null ? void 0 : r.required) ?? []), i = Object.entries(n).map(([f, c]) => ({
784
784
  name: f,
785
- type: pe(c),
785
+ type: le(c),
786
786
  required: o.has(f)
787
787
  })), s = i.map((f) => `${f.name}${f.required ? "" : "?"}: ${f.type}`).join(", ");
788
788
  return { params: i, text: s };
@@ -791,7 +791,7 @@ function We(e) {
791
791
  let t;
792
792
  return Array.isArray(e) ? t = e : e ? t = [e] : t = [], t.find((r) => r === "number" || r === "integer" || r === "boolean");
793
793
  }
794
- function qt(e, t) {
794
+ function zt(e, t) {
795
795
  var i, s;
796
796
  const n = ((s = (i = ((t == null ? void 0 : t.input) ?? {}).properties) == null ? void 0 : i.data) == null ? void 0 : s.properties) ?? {}, o = { ...e };
797
797
  for (const [a, f] of Object.entries(n)) {
@@ -807,16 +807,16 @@ function qt(e, t) {
807
807
  }
808
808
  return o;
809
809
  }
810
- const Y = /* @__PURE__ */ new Set(["default", "module.exports", "__esModule"]);
811
- function zt(e) {
810
+ const X = /* @__PURE__ */ new Set(["default", "module.exports", "__esModule"]);
811
+ function Vt(e) {
812
812
  const t = {}, r = (n, o) => {
813
813
  for (const [i, s] of Object.entries(n))
814
814
  if (typeof s == "function") {
815
- !Y.has(i) && !(i in t) && (t[i] = s);
815
+ !X.has(i) && !(i in t) && (t[i] = s);
816
816
  const a = s.name;
817
817
  a && !(a in t) && (t[a] = s);
818
818
  } else
819
- s && typeof s == "object" && o < 2 && Y.has(i) && r(s, o + 1);
819
+ s && typeof s == "object" && o < 2 && X.has(i) && r(s, o + 1);
820
820
  };
821
821
  return r(e, 0), t;
822
822
  }
@@ -843,7 +843,7 @@ class A extends Error {
843
843
  function de(e) {
844
844
  return typeof e == "object" && e !== null && e.name === "ApiError" && Ge.includes(e.code) && typeof e.toJSON == "function";
845
845
  }
846
- function X(e, t, r = 0) {
846
+ function Q(e, t, r = 0) {
847
847
  return e === "before-first-chunk" ? { phase: e, error: t } : { phase: e, error: t, chunksDelivered: r };
848
848
  }
849
849
  const j = new ge({ allErrors: !0 });
@@ -857,12 +857,12 @@ for (const e of [
857
857
  ])
858
858
  j.addKeyword({ keyword: e, valid: !0 });
859
859
  j.addFormat("decimal", /^[+-]?(?:\d+(?:\.\d+)?|\.\d+)$/);
860
- function le(e) {
860
+ function ye(e) {
861
861
  return e.map(
862
862
  (t) => `${t.instancePath || "(root)"} ${t.message ?? "failed schema check"}`
863
863
  ).join("; ");
864
864
  }
865
- const Vt = async (e, t) => {
865
+ const Wt = async (e, t) => {
866
866
  const r = e.ctx.get(Je);
867
867
  if (r === void 0)
868
868
  return t();
@@ -877,7 +877,7 @@ const Vt = async (e, t) => {
877
877
  const f = s.errors ?? [];
878
878
  throw new A(
879
879
  "invalid_argument",
880
- `Validation failed: ${le(f)}`,
880
+ `Validation failed: ${ye(f)}`,
881
881
  f
882
882
  );
883
883
  }
@@ -896,7 +896,7 @@ function Ye(e) {
896
896
  const c = a.errors ?? [];
897
897
  throw new A(
898
898
  "invalid_argument",
899
- `Validation failed: ${le(c)}`,
899
+ `Validation failed: ${ye(c)}`,
900
900
  c
901
901
  );
902
902
  }
@@ -909,7 +909,7 @@ function Xe() {
909
909
  return (e === "x" ? t : t & 3 | 8).toString(16);
910
910
  });
911
911
  }
912
- class Wt {
912
+ class Gt {
913
913
  constructor(t = {}) {
914
914
  var n, o;
915
915
  this._store = /* @__PURE__ */ new Map(), this._sweeper = null, this._defaultTtlMs = t.defaultTtlMs;
@@ -1016,7 +1016,7 @@ async function k(e) {
1016
1016
  typeof t == "function" && await t.call(e);
1017
1017
  }
1018
1018
  }
1019
- function Gt(e) {
1019
+ function Jt(e) {
1020
1020
  const { produce: t, signal: r } = e, n = r ?? new AbortController().signal;
1021
1021
  return {
1022
1022
  [Symbol.asyncIterator]() {
@@ -1035,7 +1035,7 @@ function Gt(e) {
1035
1035
  }
1036
1036
  };
1037
1037
  }
1038
- async function Jt(e) {
1038
+ async function Yt(e) {
1039
1039
  const t = [];
1040
1040
  for await (const r of e)
1041
1041
  t.push(r);
@@ -1054,10 +1054,10 @@ async function Qe(e) {
1054
1054
  );
1055
1055
  return t.length === 0 ? {
1056
1056
  ok: !1,
1057
- carrier: X("before-first-chunk", n)
1057
+ carrier: Q("before-first-chunk", n)
1058
1058
  } : {
1059
1059
  ok: !1,
1060
- carrier: X("after-first-chunk", n, t.length)
1060
+ carrier: Q("after-first-chunk", n, t.length)
1061
1061
  };
1062
1062
  }
1063
1063
  }
@@ -1083,7 +1083,7 @@ function I(e) {
1083
1083
  mapping: n
1084
1084
  };
1085
1085
  }
1086
- function ye(e, t) {
1086
+ function me(e, t) {
1087
1087
  const r = e[R];
1088
1088
  if (typeof r == "string") {
1089
1089
  const n = t.registry.get(r);
@@ -1093,11 +1093,11 @@ function ye(e, t) {
1093
1093
  return t.registry.resolve(e);
1094
1094
  }
1095
1095
  function et(e, t, r) {
1096
- const n = ye(t, r);
1096
+ const n = me(t, r);
1097
1097
  return n ? n.encode(e, t, r) : e;
1098
1098
  }
1099
1099
  function tt(e, t, r) {
1100
- const n = ye(t, r);
1100
+ const n = me(t, r);
1101
1101
  return n ? n.decode(e, t, r) : e;
1102
1102
  }
1103
1103
  function rt(e) {
@@ -1136,18 +1136,18 @@ function rt(e) {
1136
1136
  "E_UNION_UNKNOWN_TAG",
1137
1137
  `[${t}] discriminator tag "${u}" at "${i.path}" is not in the mapping (known: ${Object.keys(f).join(", ")}).`
1138
1138
  );
1139
- const l = i.resolve(p);
1140
- return et(n, l, {
1139
+ const d = i.resolve(p);
1140
+ return et(n, d, {
1141
1141
  ...i,
1142
1142
  path: `${i.path}[${u}]`
1143
1143
  });
1144
1144
  },
1145
1145
  decode(n, o, i) {
1146
1146
  if (n === null || typeof n != "object" || Array.isArray(n)) {
1147
- let d;
1148
- throw n === null ? d = "null" : Array.isArray(n) ? d = "array" : d = typeof n, new g(
1147
+ let l;
1148
+ throw n === null ? l = "null" : Array.isArray(n) ? l = "array" : l = typeof n, new g(
1149
1149
  "E_UNION_INVALID_WIRE",
1150
- `[${t}] expected a JSON object on the wire at "${i.path}", got ${d}.`
1150
+ `[${t}] expected a JSON object on the wire at "${i.path}", got ${l}.`
1151
1151
  );
1152
1152
  }
1153
1153
  const s = n, a = I(o);
@@ -1162,13 +1162,13 @@ function rt(e) {
1162
1162
  "E_UNION_NO_DISCRIMINATOR",
1163
1163
  `[${t}] wire object at "${i.path}" is missing the discriminator property "${f}".`
1164
1164
  );
1165
- const p = String(u), l = c[p];
1166
- if (!l)
1165
+ const p = String(u), d = c[p];
1166
+ if (!d)
1167
1167
  throw new g(
1168
1168
  "E_UNION_UNKNOWN_TAG",
1169
1169
  `[${t}] discriminator tag "${p}" on the wire at "${i.path}" is not in the mapping (known: ${Object.keys(c).join(", ")}).`
1170
1170
  );
1171
- const m = i.resolve(l);
1171
+ const m = i.resolve(d);
1172
1172
  return tt(n, m, {
1173
1173
  ...i,
1174
1174
  path: `${i.path}[${p}]`
@@ -1177,12 +1177,12 @@ function rt(e) {
1177
1177
  };
1178
1178
  }
1179
1179
  const nt = "x-apigen-instances";
1180
- class N extends Error {
1180
+ class O extends Error {
1181
1181
  constructor(t, r) {
1182
1182
  super(r), this.name = "NominalCodecError", this.code = t;
1183
1183
  }
1184
1184
  }
1185
- function Q(e) {
1185
+ function Z(e) {
1186
1186
  const t = e.properties;
1187
1187
  return t && typeof t == "object" && !Array.isArray(t) ? t : {};
1188
1188
  }
@@ -1190,7 +1190,7 @@ function ot(e) {
1190
1190
  const t = e.required;
1191
1191
  return Array.isArray(t) ? t.filter((r) => typeof r == "string") : [];
1192
1192
  }
1193
- function Z(e, t, r) {
1193
+ function ee(e, t, r) {
1194
1194
  if (t) {
1195
1195
  const n = r.registry.resolve(t);
1196
1196
  if (n)
@@ -1227,7 +1227,7 @@ function st(e) {
1227
1227
  return o;
1228
1228
  if (s.seen.has(o)) {
1229
1229
  if (s.mode === "strict")
1230
- throw new N(
1230
+ throw new O(
1231
1231
  "E_NOMINAL_CYCLE",
1232
1232
  `[${t}] cycle detected at "${s.path}": a nominal instance references itself. Strict mode rejects cycles (DESIGN ยง8.3); break the cycle or use 'lossy' mode.`
1233
1233
  );
@@ -1235,28 +1235,28 @@ function st(e) {
1235
1235
  }
1236
1236
  s.seen.add(o);
1237
1237
  try {
1238
- const a = Q(i), f = typeof i[x] == "string" ? i[x] : "toJSON", c = o[f];
1238
+ const a = Z(i), f = typeof i[x] == "string" ? i[x] : "toJSON", c = o[f];
1239
1239
  if (typeof c == "function") {
1240
- const d = c.call(o);
1241
- if (d !== null && typeof d == "object" && !Array.isArray(d)) {
1240
+ const l = c.call(o);
1241
+ if (l !== null && typeof l == "object" && !Array.isArray(l)) {
1242
1242
  const y = {};
1243
1243
  for (const [h, b] of Object.entries(
1244
- d
1244
+ l
1245
1245
  ))
1246
- y[h] = Z(b, a[h], {
1246
+ y[h] = ee(b, a[h], {
1247
1247
  ...s,
1248
1248
  path: `${s.path}/${h}`
1249
1249
  });
1250
1250
  return y;
1251
1251
  }
1252
- return d;
1252
+ return l;
1253
1253
  }
1254
- const u = {}, p = Object.keys(a), l = o, m = p.length > 0 ? p : Object.keys(l);
1255
- for (const d of m) {
1256
- const y = l[d];
1257
- y !== void 0 && (u[d] = Z(y, a[d], {
1254
+ const u = {}, p = Object.keys(a), d = o, m = p.length > 0 ? p : Object.keys(d);
1255
+ for (const l of m) {
1256
+ const y = d[l];
1257
+ y !== void 0 && (u[l] = ee(y, a[l], {
1258
1258
  ...s,
1259
- path: `${s.path}/${d}`
1259
+ path: `${s.path}/${l}`
1260
1260
  }));
1261
1261
  }
1262
1262
  return u;
@@ -1267,7 +1267,7 @@ function st(e) {
1267
1267
  decode(o, i, s) {
1268
1268
  if (o === null || typeof o != "object" || Array.isArray(o)) {
1269
1269
  let u;
1270
- throw o === null ? u = "null" : Array.isArray(o) ? u = "array" : u = typeof o, new N(
1270
+ throw o === null ? u = "null" : Array.isArray(o) ? u = "array" : u = typeof o, new O(
1271
1271
  "E_NOMINAL_INVALID_WIRE",
1272
1272
  `[${t}] expected a JSON object on the wire at "${s.path}", got ${u}.`
1273
1273
  );
@@ -1275,16 +1275,16 @@ function st(e) {
1275
1275
  const a = o;
1276
1276
  for (const u of ot(i))
1277
1277
  if (!(u in a))
1278
- throw new N(
1278
+ throw new O(
1279
1279
  "E_NOMINAL_INVALID_WIRE",
1280
1280
  `[${t}] required field "${u}" missing on the wire at "${s.path}".`
1281
1281
  );
1282
1282
  if (i[nt] === !1)
1283
- throw new N(
1283
+ throw new O(
1284
1284
  "E_NOMINAL_NONRECONSTRUCTABLE",
1285
1285
  `[${t}] is encode-only: the extractor marked it non-reconstructable (x-apigen-instances:false). It cannot be decoded back to a live instance.`
1286
1286
  );
1287
- const f = Q(i), c = {};
1287
+ const f = Z(i), c = {};
1288
1288
  for (const [u, p] of Object.entries(a))
1289
1289
  c[u] = it(p, f[u], {
1290
1290
  ...s,
@@ -1297,8 +1297,8 @@ function st(e) {
1297
1297
  n,
1298
1298
  c
1299
1299
  );
1300
- const l = n;
1301
- return new l(c);
1300
+ const d = n;
1301
+ return new d(c);
1302
1302
  }
1303
1303
  return c;
1304
1304
  }
@@ -1315,7 +1315,7 @@ const at = [
1315
1315
  type: "object",
1316
1316
  "x-apigen-logical": "nominal",
1317
1317
  "x-apigen-codec": "ts.NominalSentinel"
1318
- }, ee = st({
1318
+ }, te = st({
1319
1319
  id: "ts.NominalSentinel",
1320
1320
  schema: ct
1321
1321
  }), ut = {
@@ -1323,7 +1323,7 @@ const at = [
1323
1323
  discriminator: { propertyName: "kind", mapping: {} },
1324
1324
  "x-apigen-logical": "union",
1325
1325
  "x-apigen-codec": "ts.UnionSentinel"
1326
- }, te = rt({
1326
+ }, re = rt({
1327
1327
  id: "ts.UnionSentinel",
1328
1328
  schema: ut
1329
1329
  });
@@ -1335,25 +1335,25 @@ function ft() {
1335
1335
  t
1336
1336
  ]),
1337
1337
  // nominal kind sentinel
1338
- [ee.id, ee],
1338
+ [te.id, te],
1339
1339
  // union kind sentinel
1340
- [te.id, te]
1340
+ [re.id, re]
1341
1341
  ];
1342
1342
  return Object.freeze(new Map(e));
1343
1343
  }
1344
- const Yt = Object.freeze({
1344
+ const Xt = Object.freeze({
1345
1345
  host: "ts",
1346
1346
  logicalTypeVersion: ve,
1347
1347
  codecs: ft()
1348
1348
  });
1349
- function Xt(e, t, r) {
1349
+ function Qt(e, t, r) {
1350
1350
  var i;
1351
1351
  const n = typeof ((i = t == null ? void 0 : t.input) == null ? void 0 : i.description) == "string" ? t.input.description : void 0, o = [r, n].filter(
1352
1352
  (s) => typeof s == "string" && s.length > 0
1353
1353
  );
1354
1354
  return o.length > 0 ? o.join(" โ€” ") : e;
1355
1355
  }
1356
- function Qt(e) {
1356
+ function Zt(e) {
1357
1357
  if (!e || typeof e != "object" || Array.isArray(e) || Object.keys(e).length === 0)
1358
1358
  return { outputSchema: void 0, wrapped: !1 };
1359
1359
  const t = e;
@@ -1366,18 +1366,18 @@ function Qt(e) {
1366
1366
  wrapped: !0
1367
1367
  };
1368
1368
  }
1369
- function Zt(e, t) {
1369
+ function er(e, t) {
1370
1370
  return e ? { result: t } : t && typeof t == "object" && !Array.isArray(t) ? t : void 0;
1371
1371
  }
1372
- const pt = 4, dt = 32;
1372
+ const pt = 4, lt = 32;
1373
1373
  function U(e) {
1374
1374
  return de(e) ? e : e instanceof Error ? new A("internal", e.message) : e;
1375
1375
  }
1376
- function lt(e, t) {
1376
+ function dt(e, t) {
1377
1377
  if (e === "serial" || e === "chained")
1378
1378
  return 1;
1379
1379
  const r = t ?? pt;
1380
- return !Number.isFinite(r) || r < 1 ? 1 : Math.min(Math.floor(r), dt);
1380
+ return !Number.isFinite(r) || r < 1 ? 1 : Math.min(Math.floor(r), lt);
1381
1381
  }
1382
1382
  function yt() {
1383
1383
  }
@@ -1404,7 +1404,7 @@ function mt(e, t) {
1404
1404
  }
1405
1405
  };
1406
1406
  }
1407
- async function re(e, t, r, n, o, i) {
1407
+ async function ne(e, t, r, n, o, i) {
1408
1408
  const s = mt(n.signal, i);
1409
1409
  try {
1410
1410
  const a = s.signal ? { ...n, signal: s.signal } : n, f = await e(t, a, o);
@@ -1427,9 +1427,9 @@ async function re(e, t, r, n, o, i) {
1427
1427
  s.dispose();
1428
1428
  }
1429
1429
  }
1430
- async function er(e, t, r, n, o = {}) {
1431
- const i = o.mode ?? "parallel", s = o.onItemError ?? "continue", a = lt(i, o.concurrency), f = new Array(r.length), c = (d) => ({
1432
- index: d,
1430
+ async function tr(e, t, r, n, o = {}) {
1431
+ const i = o.mode ?? "parallel", s = o.onItemError ?? "continue", a = dt(i, o.concurrency), f = new Array(r.length), c = (l) => ({
1432
+ index: l,
1433
1433
  status: "rejected",
1434
1434
  reason: U(
1435
1435
  new Error(
@@ -1438,13 +1438,13 @@ async function er(e, t, r, n, o = {}) {
1438
1438
  )
1439
1439
  });
1440
1440
  if (i === "serial" || i === "chained") {
1441
- let d = !1;
1441
+ let l = !1;
1442
1442
  for (let y = 0; y < r.length; y++) {
1443
- if (d) {
1443
+ if (l) {
1444
1444
  f[y] = c(y);
1445
1445
  continue;
1446
1446
  }
1447
- const h = await re(
1447
+ const h = await ne(
1448
1448
  e,
1449
1449
  t,
1450
1450
  y,
@@ -1452,34 +1452,34 @@ async function er(e, t, r, n, o = {}) {
1452
1452
  n,
1453
1453
  o.itemTimeoutMs
1454
1454
  );
1455
- f[y] = h, h.status === "rejected" && (i === "chained" || s === "abort") && (d = !0);
1455
+ f[y] = h, h.status === "rejected" && (i === "chained" || s === "abort") && (l = !0);
1456
1456
  }
1457
1457
  return f;
1458
1458
  }
1459
1459
  let u = 0, p = !1;
1460
- const l = Math.max(1, Math.min(a, r.length)), m = Array.from({ length: l }, async () => {
1460
+ const d = Math.max(1, Math.min(a, r.length)), m = Array.from({ length: d }, async () => {
1461
1461
  for (; ; ) {
1462
- const d = u++;
1463
- if (d >= r.length)
1462
+ const l = u++;
1463
+ if (l >= r.length)
1464
1464
  return;
1465
1465
  if (p) {
1466
- f[d] = c(d);
1466
+ f[l] = c(l);
1467
1467
  continue;
1468
1468
  }
1469
- const y = await re(
1469
+ const y = await ne(
1470
1470
  e,
1471
1471
  t,
1472
- d,
1473
- r[d],
1472
+ l,
1473
+ r[l],
1474
1474
  n,
1475
1475
  o.itemTimeoutMs
1476
1476
  );
1477
- f[d] = y, y.status === "rejected" && s === "abort" && (p = !0);
1477
+ f[l] = y, y.status === "rejected" && s === "abort" && (p = !0);
1478
1478
  }
1479
1479
  });
1480
1480
  return await Promise.all(m), f;
1481
1481
  }
1482
- const ne = /* @__PURE__ */ new Set(["string", "number", "boolean", "integer"]);
1482
+ const oe = /* @__PURE__ */ new Set(["string", "number", "boolean", "integer"]);
1483
1483
  function ht(e) {
1484
1484
  if (typeof e != "object" || e === null)
1485
1485
  return !1;
@@ -1487,7 +1487,7 @@ function ht(e) {
1487
1487
  if (t.$ref !== void 0 || t.oneOf || t.anyOf || t.allOf)
1488
1488
  return !1;
1489
1489
  const { type: r } = t;
1490
- return typeof r == "string" ? ne.has(r) : Array.isArray(r) ? r.every((n) => ne.has(n) || n === "null") : Array.isArray(t.enum) && t.enum.length > 0 ? t.enum.every((n) => ["string", "number", "boolean"].includes(typeof n)) : !1;
1490
+ return typeof r == "string" ? oe.has(r) : Array.isArray(r) ? r.every((n) => oe.has(n) || n === "null") : Array.isArray(t.enum) && t.enum.length > 0 ? t.enum.every((n) => ["string", "number", "boolean"].includes(typeof n)) : !1;
1491
1491
  }
1492
1492
  function gt(e) {
1493
1493
  if (!e || typeof e != "object")
@@ -1516,23 +1516,23 @@ Object.entries(wt).map(([e, t]) => ({
1516
1516
  ),
1517
1517
  key: t
1518
1518
  }));
1519
- function oe(e) {
1520
- return e.words.join("-");
1521
- }
1522
1519
  function ie(e) {
1523
- return e.words.map(Nt).join("");
1520
+ return e.words.join("-");
1524
1521
  }
1525
1522
  function se(e) {
1523
+ return e.words.map(Ot).join("");
1524
+ }
1525
+ function ae(e) {
1526
1526
  return e.words.join("_");
1527
1527
  }
1528
1528
  function vt(e, t = {}) {
1529
1529
  var r, n;
1530
- const o = [e.namespace, ...e.path], i = e.safe || gt(e.input) ? "GET" : "POST", s = ((n = (r = t.http) == null ? void 0 : r.verb) == null ? void 0 : n[e.id]) ?? i, a = "/" + o.map((m) => oe(m)).join("/"), f = o.map((m) => se(m)).join("_"), c = o.map((m) => se(m)).slice(0, -1).join("."), u = ie(o[o.length - 2] ?? o[0]), p = ie(o[o.length - 1]), l = o.map((m) => oe(m));
1530
+ const o = [e.namespace, ...e.path], i = e.safe || gt(e.input) ? "GET" : "POST", s = ((n = (r = t.http) == null ? void 0 : r.verb) == null ? void 0 : n[e.id]) ?? i, a = "/" + o.map((m) => ie(m)).join("/"), f = o.map((m) => ae(m)).join("_"), c = o.map((m) => ae(m)).slice(0, -1).join("."), u = se(o[o.length - 2] ?? o[0]), p = se(o[o.length - 1]), d = o.map((m) => ie(m));
1531
1531
  return {
1532
1532
  http: { verb: s, route: a },
1533
1533
  mcp: { name: f },
1534
1534
  grpc: { package: c, service: u, method: p },
1535
- cli: { path: l }
1535
+ cli: { path: d }
1536
1536
  };
1537
1537
  }
1538
1538
  function $t(e, t) {
@@ -1541,14 +1541,14 @@ function $t(e, t) {
1541
1541
  function jt(e, t) {
1542
1542
  return `--${e}-${t}`;
1543
1543
  }
1544
- function Ot(e, t) {
1544
+ function Nt(e, t) {
1545
1545
  const r = (n) => n.toUpperCase().replace(/-/g, "_");
1546
1546
  return e === "adhd" ? `APIGEN_${r(t)}` : `APIGEN_${r(e)}_${r(t)}`;
1547
1547
  }
1548
- function Nt(e) {
1548
+ function Ot(e) {
1549
1549
  return e.length === 0 ? e : e[0].toUpperCase() + e.slice(1);
1550
1550
  }
1551
- function me(e) {
1551
+ function V(e) {
1552
1552
  return e.anyOf ?? e.oneOf;
1553
1553
  }
1554
1554
  function At(e) {
@@ -1556,7 +1556,7 @@ function At(e) {
1556
1556
  return !1;
1557
1557
  if (e.type === "array" || e.type === "object")
1558
1558
  return !0;
1559
- const t = me(e);
1559
+ const t = V(e);
1560
1560
  if (t) {
1561
1561
  const r = t.filter((n) => n.type !== "null");
1562
1562
  return r.length > 0 && r.every((n) => n.type === "array" || n.type === "object");
@@ -1568,7 +1568,7 @@ function _t(e) {
1568
1568
  return !1;
1569
1569
  if (e.type === "boolean")
1570
1570
  return !0;
1571
- const t = me(e);
1571
+ const t = V(e);
1572
1572
  if (t) {
1573
1573
  const r = t.filter((n) => n.type !== "null");
1574
1574
  return r.length > 0 && r.every((n) => n.type === "boolean");
@@ -1576,17 +1576,29 @@ function _t(e) {
1576
1576
  return !1;
1577
1577
  }
1578
1578
  function Et(e) {
1579
- return e.replace(/[A-Z]/g, (t) => "-" + t.toLowerCase());
1579
+ if (!e)
1580
+ return !1;
1581
+ if (e.type === "number" || e.type === "integer")
1582
+ return !0;
1583
+ const t = V(e);
1584
+ if (t) {
1585
+ const r = t.filter((n) => n.type !== "null");
1586
+ return r.length > 0 && r.every((n) => n.type === "number" || n.type === "integer");
1587
+ }
1588
+ return !1;
1580
1589
  }
1581
1590
  function kt(e) {
1591
+ return e.replace(/[A-Z]/g, (t) => "-" + t.toLowerCase());
1592
+ }
1593
+ function It(e) {
1582
1594
  var o, i;
1583
1595
  const t = (i = (o = e.input) == null ? void 0 : o.properties) == null ? void 0 : i.data, r = (t == null ? void 0 : t.properties) ?? {}, n = (t == null ? void 0 : t.required) ?? [];
1584
1596
  return { props: r, required: n };
1585
1597
  }
1586
- function ae(e) {
1598
+ function ce(e) {
1587
1599
  return typeof e.handler == "function";
1588
1600
  }
1589
- function It(e) {
1601
+ function Ct(e) {
1590
1602
  var o;
1591
1603
  const t = ((o = e.input) == null ? void 0 : o.properties) ?? {}, r = e["x-apigen-envelope"], n = [];
1592
1604
  for (const i of Object.keys(t)) {
@@ -1599,16 +1611,16 @@ function It(e) {
1599
1611
  httpHeader: a,
1600
1612
  mcpMetaKey: a,
1601
1613
  cliFlag: jt(s, i),
1602
- envVar: Ot(s, i)
1614
+ envVar: Nt(s, i)
1603
1615
  });
1604
1616
  }
1605
1617
  return n;
1606
1618
  }
1607
- function Ct(e, t) {
1608
- const r = /* @__PURE__ */ new Map(), { props: n } = kt(e);
1619
+ function St(e, t) {
1620
+ const r = /* @__PURE__ */ new Map(), { props: n } = It(e);
1609
1621
  for (const [o, i] of Object.entries(n)) {
1610
1622
  let s = "string";
1611
- _t(i) ? s = "boolean" : At(i) && (s = "json"), r.set(Et(o), {
1623
+ _t(i) ? s = "boolean" : (At(i) || Et(i)) && (s = "json"), r.set(kt(o), {
1612
1624
  camelKey: o,
1613
1625
  kind: "domain",
1614
1626
  valueKind: s
@@ -1625,8 +1637,8 @@ function Ct(e, t) {
1625
1637
  }
1626
1638
  return r;
1627
1639
  }
1628
- function tr(e) {
1629
- const { op: t, schema: r, transport: n, projection: o } = e, i = vt(t, o), s = r ? It(r) : [], a = r ? Ct(r, s) : /* @__PURE__ */ new Map(), f = r ? Ve(r).params : void 0, c = {
1640
+ function rr(e) {
1641
+ const { op: t, schema: r, transport: n, projection: o } = e, i = vt(t, o), s = r ? Ct(r) : [], a = r ? St(r, s) : /* @__PURE__ */ new Map(), f = r ? Ve(r).params : void 0, c = {
1630
1642
  op: t,
1631
1643
  transport: n,
1632
1644
  http: i.http,
@@ -1637,38 +1649,38 @@ function tr(e) {
1637
1649
  envelope: s,
1638
1650
  cliFlags: a,
1639
1651
  streaming: t.streaming,
1640
- isMount: ae(t)
1652
+ isMount: ce(t)
1641
1653
  };
1642
- if (ae(t)) {
1654
+ if (ce(t)) {
1643
1655
  const u = t.handler;
1644
1656
  c.mountHandler = async (p) => u(p);
1645
1657
  }
1646
1658
  return c;
1647
1659
  }
1648
- function rr(e) {
1660
+ function nr(e) {
1649
1661
  const t = e.usePlugins;
1650
1662
  return Array.isArray(t) ? t : [];
1651
1663
  }
1652
- function nr(e) {
1664
+ function or(e) {
1653
1665
  const t = e.useOptions;
1654
1666
  return t && typeof t == "object" ? t : {};
1655
1667
  }
1656
- function St(e) {
1668
+ function xt(e) {
1657
1669
  return async function(r, n) {
1658
1670
  const o = Object.assign(r, { data: r.domainArgs });
1659
1671
  return await e.layer(o, n);
1660
1672
  };
1661
1673
  }
1662
- function or(e, t) {
1674
+ function ir(e, t) {
1663
1675
  var n;
1664
1676
  const r = [];
1665
1677
  for (const o of t) {
1666
1678
  const i = (n = o.capabilities) == null ? void 0 : n.layer;
1667
- i && r.push(St(i));
1679
+ i && r.push(xt(i));
1668
1680
  }
1669
1681
  return r.push(Ye(e)), Me(r);
1670
1682
  }
1671
- function xt() {
1683
+ function Mt() {
1672
1684
  const e = /* @__PURE__ */ new Map();
1673
1685
  return {
1674
1686
  get: (t) => e.get(t),
@@ -1677,14 +1689,14 @@ function xt() {
1677
1689
  }
1678
1690
  };
1679
1691
  }
1680
- const Mt = {
1692
+ const Tt = {
1681
1693
  input: {
1682
1694
  type: "object",
1683
1695
  properties: { data: { type: "object", properties: {} } }
1684
1696
  },
1685
1697
  output: {}
1686
1698
  };
1687
- async function ir(e, t, r, n) {
1699
+ async function sr(e, t, r, n) {
1688
1700
  const o = {
1689
1701
  ...r,
1690
1702
  operation: { id: e.op.id },
@@ -1700,13 +1712,13 @@ async function ir(e, t, r, n) {
1700
1712
  operation: e.op,
1701
1713
  data: r.domainArgs,
1702
1714
  envelope: r.envelope,
1703
- ctx: xt(),
1715
+ ctx: Mt(),
1704
1716
  transport: e.transport,
1705
1717
  signal: r.signal ?? new AbortController().signal
1706
1718
  }, a = {
1707
1719
  ...n,
1708
1720
  fns: { [e.op.id]: () => i(s) },
1709
- schemas: { [e.op.id]: Mt }
1721
+ schemas: { [e.op.id]: Tt }
1710
1722
  };
1711
1723
  return t(e.op.id, o, a);
1712
1724
  }
@@ -1714,42 +1726,42 @@ async function ir(e, t, r, n) {
1714
1726
  }
1715
1727
  export {
1716
1728
  pt as BATCH_DEFAULT_CONCURRENCY,
1717
- dt as BATCH_MAX_CONCURRENCY,
1729
+ lt as BATCH_MAX_CONCURRENCY,
1718
1730
  Te as EventBus,
1719
- Wt as InstanceRegistry,
1731
+ Gt as InstanceRegistry,
1720
1732
  xe as LayerContext,
1721
1733
  g as UnionCodecError,
1722
1734
  Je as ValidateSchemasToken,
1723
1735
  at as WELL_KNOWN_TS_CODECS,
1724
- St as adaptCoreLayer,
1736
+ xt as adaptCoreLayer,
1725
1737
  ze as assertNoSelfSubscription,
1726
1738
  Ue as buildContext,
1727
- zt as buildFnTable,
1728
- Qt as buildMcpOutputSchema,
1729
- tr as buildOpPlan,
1730
- Xt as buildToolDescription,
1731
- qt as coerceQueryParams,
1739
+ Vt as buildFnTable,
1740
+ Zt as buildMcpOutputSchema,
1741
+ rr as buildOpPlan,
1742
+ Qt as buildToolDescription,
1743
+ zt as coerceQueryParams,
1732
1744
  Qe as collectWithPhase,
1733
- Kt as createApiPackage,
1745
+ Ht as createApiPackage,
1734
1746
  Me as createInvoker,
1735
- Ht as createLogger,
1736
- or as createPackageInvoker,
1737
- Gt as createStream,
1747
+ qt as createLogger,
1748
+ ir as createPackageInvoker,
1749
+ Jt as createStream,
1738
1750
  rt as createUnionCodec,
1739
1751
  ke as dataParamNames,
1740
- Ft as defineMiddleware,
1752
+ Kt as defineMiddleware,
1741
1753
  Ve as describeParams,
1742
1754
  Se as dispatch,
1743
- ir as dispatchForPlan,
1744
- Jt as drainStream,
1745
- er as invokeBatch,
1755
+ sr as dispatchForPlan,
1756
+ Yt as drainStream,
1757
+ tr as invokeBatch,
1746
1758
  Ze as isApiStream,
1747
1759
  Ye as makeValidateLayer,
1748
1760
  Ee as needsEnvelopeField,
1749
- nr as readUseOptions,
1750
- rr as readUsePlugins,
1751
- Yt as tsHostBinding,
1752
- Vt as validateLayer,
1761
+ or as readUseOptions,
1762
+ nr as readUsePlugins,
1763
+ Xt as tsHostBinding,
1764
+ Wt as validateLayer,
1753
1765
  De as wireObservers,
1754
- Zt as wrapMcpStructuredContent
1766
+ er as wrapMcpStructuredContent
1755
1767
  };
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@adhd/apigen-engine-runtime",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
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.2.1",
8
+ "@adhd/apigen-core-client": "^0.2.2",
9
9
  "@adhd/apigen-base-logical": "^0.1.0",
10
10
  "@adhd/apigen-base-errors": "^0.2.0",
11
11
  "@adhd/apigen-engine-naming": "^0.2.1",