@adhd/apigen-core-client 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 +116 -110
  4. package/package.json +1 -1
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-core-client to align it with other projects, there were no code changes.
package/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var Re=Object.create;var oe=Object.defineProperty;var _e=Object.getOwnPropertyDescriptor;var Le=Object.getOwnPropertyNames;var Me=Object.getPrototypeOf,Ve=Object.prototype.hasOwnProperty;var qe=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Le(t))!Ve.call(e,r)&&r!==n&&oe(e,r,{get:()=>t[r],enumerable:!(o=_e(t,r))||o.enumerable});return e};var ze=(e,t,n)=>(n=e!=null?Re(Me(e)):{},qe(t||!e||!e.__esModule?oe(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("ts-morph"),Ke=require("node:fs"),D=require("node:path"),E=require("ts-json-schema-generator");function Be(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const De=Be(D);function ie(e){return{raw:e,words:e.split(/(?=[A-Z])|[-_]/).map(t=>t.toLowerCase()).filter(Boolean)}}function de(e,t,n={}){const o=e.split("/");if(o.length<2||o.some(l=>l.length===0))throw new Error(`syntheticOp: id "${e}" must be "<namespace>/<path...>" with non-empty segments`);const[r,...i]=o,s=r.replace(/^_+/,""),a=n.kind??"action",c={id:e,host:t.host,namespace:ie(s),path:i.map(ie),kind:a,async:n.async??!1,streaming:n.streaming??!1,safe:n.safe??a==="query",input:n.input??{},output:n.output??{},envelope:n.envelope??{},typeText:n.typeText??null};return n.hasCtx!==void 0&&(c.hasCtx=n.hasCtx),n.transports!==void 0&&(c.transports=n.transports),c}const ye=Symbol.for("adhd.apigen.extraction-session");function he(e,t){const n=[...e.getImportDeclarations().map(o=>o.getModuleSpecifierSourceFile()),...e.getExportDeclarations().map(o=>o.getModuleSpecifierSourceFile())];for(const o of n){if(!o)continue;const r=o.getFilePath();if(!r.includes("/node_modules/")&&!t.has(r)){t.add(r);try{o.refreshFromFileSystemSync()}catch{}he(o,t)}}}function Te(e){try{const t=Ke.statSync(e);return`${t.mtimeMs}:${t.size}`}catch{return"nostat"}}const _=new Map,J=new Map;function We(e,t,n){const o=t??"",r=_.get(o);let i=n;if(r&&r.fileVersions.size>0){const c=[n],l=[...r.fileVersions.entries()].sort(([u],[f])=>u.localeCompare(f));for(const[u,f]of l)u!==e&&c.push(`${u}:${f}`);i=c.join("|")}const s=`${e}\0${t??""}`;let a=J.get(s);return(!a||a.version!==i)&&(a={version:i,schemas:new Map},J.set(s,a)),a.schemas}function Ue(){_.clear(),J.clear()}function te(){const e={projectsBuilt:0,generatorsBuilt:0,schemaCacheHits:0,schemaCacheMisses:0},t=new Map;let n=!1;return{[ye]:!0,stats:e,schemaCache:new Map,aliasCache:new WeakMap,zodImportCache:new WeakMap,generatorCache:new Map,projectFor(r){if(n)throw new Error("apigen-core: ExtractionSession used after dispose()");const i=r??"",s=r?this.statVersion(r):"";let a=_.get(i);return a&&a.tsconfigVersion!==s&&(a=void 0),a||(a={project:r?new I.Project({tsConfigFilePath:r,skipAddingFilesFromTsConfig:!0}):new I.Project({skipAddingFilesFromTsConfig:!0}),tsconfigVersion:s,fileVersions:new Map},_.set(i,a),e.projectsBuilt++),a.project},sourceFileFor(r,i){const s=this.projectFor(i),a=_.get(i??""),c=this.statVersion(r);let l=s.getSourceFile(r);if(l===void 0?l=s.addSourceFileAtPath(r):a&&a.fileVersions.get(r)!==c&&l.refreshFromFileSystemSync(),a==null||a.fileVersions.set(r,c),a){const u=new Set([r]);he(l,u);for(const f of u)f!==r&&a.fileVersions.set(f,this.statVersion(f))}return l},statVersion(r){let i=t.get(r);return i===void 0&&(i=Te(r),t.set(r,i)),i},dispose(){n=!0,this.schemaCache.clear(),this.generatorCache.clear(),t.clear()}}}function be(e){const t=e;if(t[ye]!==!0)throw new Error("apigen-core: unknown ExtractionSession implementation โ€” create sessions with createExtractionSession()");return t}const B="x-apigen-logical";function se(e,t){const n=new Set,o=[e];for(;o.length>0;){const r=o.pop();if(!r||n.has(r))continue;n.add(r);const i=r.$ref;if(typeof i=="string"){if(t){const f=t[i];if(!f){const p=Object.keys(t).join(", ")||"(none)";throw new Error(`[apigen-logical] $ref "${i}" cannot be resolved. Available $defs: ${p}`)}o.push(f)}continue}const s=r.oneOf;if(Array.isArray(s))for(const f of s)typeof f=="object"&&f!==null&&o.push(f);const a=r.properties;if(a)for(const f of Object.values(a))o.push(f);const c=r.items;if(Array.isArray(c))for(const f of c)typeof f=="object"&&f!==null&&o.push(f);else typeof c=="object"&&c!==null&&o.push(c);const l=r.additionalProperties;typeof l=="object"&&l!==null&&o.push(l);const u=r.propertyNames;typeof u=="object"&&u!==null&&o.push(u)}}const ae=new Set(["string","number","boolean","integer"]);function Ge(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:n}=t;return typeof n=="string"?ae.has(n):Array.isArray(n)?n.every(o=>ae.has(o)||o==="null"):Array.isArray(t.enum)&&t.enum.length>0?t.enum.every(o=>["string","number","boolean"].includes(typeof o)):!1}function Se(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(Ge)}function Ze(e){var n,o;const t=[];for(const r of e){const i={...(n=r.capabilities.layer)==null?void 0:n.envelopeFields,...(o=r.capabilities.envelope)==null?void 0:o.request};Object.keys(i).length>0&&t.push({id:r.id,envelope:i})}return t}function He(e){const t={},n=o=>{for(const r of["definitions","$defs"]){const i=o[r];if(i)for(const[s,a]of Object.entries(i)){const c=s.startsWith("#/")?s:`#/${r}/${s}`;t[c]=a}}};for(const o of Object.values(e.schemas))n(o.input),n(o.output);if(Object.keys(t).length!==0)for(const[o,r]of Object.entries(e.schemas))try{se(r.input,t),se(r.output,t)}catch(i){throw new Error(`[apigen-core-client] Schema validation failed for function "${o}": ${i.message}`)}}function Je(e,t){const n=['apigen calling convention: all domain parameters go inside a "data" envelope โ€” e.g. { "data": { ... } }'+(t?".":" (an empty object for this zero-parameter tool).")];return e.length>0&&n.push(`Field(s) ${e.map(o=>`"${o}"`).join(", ")} are transport-level envelope metadata, NOT domain data โ€” do not nest them under "data". Over MCP they are read from arguments._meta["x-<pluginId>-<field>"] (default pluginId "adhd"); see @adhd/apigen-engine-naming's envelopeMetaKey/envelopeCliFlag/envelopeEnvVar for the HTTP-header / CLI-flag / env-var equivalents.`),n.join(" ")}function Qe(e,t,n){He(e);const o={};for(const[r,i]of Object.entries(e.schemas)){const s=(n==null?void 0:n[r])??{},a=i.input.properties??{},c=i.input.required??[],l={},u=[],f={};for(const T of t)if(T.envelope&&s[T.id]!==!1)for(const[d,y]of Object.entries(T.envelope))l[d]=y,f[d]=T.id,u.includes(d)||u.push(d);const p={type:"object",properties:a,additionalProperties:!1,...c.length>0?{required:c}:{}},b=i.safe===!0||Se(i.input),h=i.input.definitions,m=i.input.$defs;o[r]={input:{type:"object",properties:{...l,data:p},required:[...u,...c.length>0?["data"]:[]],additionalProperties:!1,description:Je(Object.keys(l),Object.keys(a).length>0),...h?{definitions:h}:{},...m?{$defs:m}:{}},output:i.output,...i.hasCtx?{hasCtx:!0}:{},"x-apigen-safe":b,...Object.keys(f).length>0?{"x-apigen-envelope":f}:{}}}return o}const Xe=8;function Ye(e,t){try{return t?e.getText(t):e.getText()}catch{try{return e.getText()}catch{return}}}let et=0;async function tt(e,t,n,o){const r=`__ApigenProbe_${process.pid}_${et++}`;let i;try{i=t.addTypeAlias({name:r,type:n});const s=i.getType();return await o(s)}catch{return}finally{try{i==null||i.remove()}catch{}}}async function ve(e,t,n){if(n>Xe)return{};if(e.isString()||e.isStringLiteral())return e.isStringLiteral()?{type:"string",enum:[e.getLiteralValue()]}:{type:"string"};if(e.isNumber()||e.isNumberLiteral())return e.isNumberLiteral()?{type:"number",enum:[e.getLiteralValue()]}:{type:"number"};if(e.isBoolean())return{type:"boolean"};if(e.isBooleanLiteral())return{type:"boolean"};if(e.isNull()||e.isUndefined()||e.isVoid())return{type:"null"};if(e.isUnion()){const o=e.getUnionTypes();if(o.every(c=>c.isStringLiteral())&&o.length>0)return{type:"string",enum:o.map(c=>c.getLiteralValue())};if(o.every(c=>c.isNumberLiteral())&&o.length>0)return{type:"number",enum:o.map(c=>c.getLiteralValue())};const s=await Promise.all(o.map(c=>ve(c,t,n+1))),a=W(s);return{oneOf:s,...a?{discriminator:a}:{},[B]:"union"}}if(e.isArray()){const o=e.getArrayElementType();return{type:"array",items:o?await t(o.getText()):{}}}if(e.isTuple()){const o=e.getTupleElements(),r=await Promise.all(o.map(i=>t(i.getText())));return{type:"array",items:r,minItems:r.length,maxItems:r.length}}if(e.isObject()){const o=e.getStringIndexType(),r=e.getNumberIndexType(),i=o??r,s=e.getProperties();if(i&&s.length===0)return{type:"object",additionalProperties:await t(i.getText())};const a={};for(const c of s){const l=c.getName(),f=c.getDeclarations()[0];let p;if(f)try{p=c.getTypeAtLocation(f)}catch{p=void 0}if(p!==void 0&&p.getCallSignatures().length>0)continue;const b=p!==void 0?Ye(p,f):void 0;a[l]=b!==void 0?await t(b):{}}return Object.keys(a).length>0?{type:"object",properties:a}:{}}return{}}function W(e){if(e.length<2)return;const t=[];for(const o of e){if(o.type!=="object")return;const r=o.properties;if(!r||typeof r!="object")return;t.push(r)}const n=Object.keys(t[0]).filter(o=>t.every(r=>Object.prototype.hasOwnProperty.call(r,o)));for(const o of n){const r=[];let i=!0;for(const a of t){const c=a[o],l=c&&(c.type==="string"||c.type==="number"),u=c==null?void 0:c.enum;if(!l||!Array.isArray(u)||u.length!==1){i=!1;break}r.push(String(u[0]))}if(!i||new Set(r).size!==r.length)continue;const s={};return r.forEach((a,c)=>{s[a]=`#/oneOf/${c}`}),{propertyName:o,mapping:s}}}function z(e,t,n){if(t>6)return{};const o=e.trim();if(o==="string")return{type:"string"};if(o==="number")return{type:"number"};if(o==="boolean")return{type:"boolean"};if(o==="null")return{type:"null"};if(o==="undefined")return{type:"null"};const r=Q[o];if(r!==void 0)return r;if(n!=null&&n.size){const i=n.get(o);if(i!==void 0){const s=Q[i];if(s!==void 0)return s}}if(o.endsWith("[]"))return{type:"array",items:z(o.slice(0,-2),t+1,n)};if(o.includes("|")){const i=o.split("|").map(c=>c.trim());if(i.every(c=>c.startsWith("'")))return{type:"string",enum:i.map(c=>c.replace(/'/g,""))};const s=i.map(c=>z(c,t+1,n)),a=W(s);return{oneOf:s,...a?{discriminator:a}:{},[B]:"union"}}if(o.startsWith("{")&&o.endsWith("}")){const i=o.slice(1,-1).trim(),s={};for(const a of i.split(";").filter(Boolean)){const[c,l]=a.split(":").map(u=>u.trim());c&&l&&(s[c.replace("?","")]=z(l,t+1,n))}return{type:"object",properties:s}}return{}}function xe(e){const t=[];let n=0,o=0;for(let i=0;i<e.length;i++){const s=e[i];s==="<"||s==="["||s==="{"||s==="("?n++:s===">"||s==="]"||s==="}"||s===")"?n--:s===","&&n===0&&(t.push(e.slice(o,i).trim()),o=i+1)}const r=e.slice(o).trim();return r.length>0&&t.push(r),t}function nt(e){const t=/^(?:Readonly)?Map<(.+)>$/.exec(e);return t?t[1]:void 0}function rt(e){const t=/^(?:Readonly)?Set<(.+)>$/.exec(e);return t?t[1]:void 0}function ot(e){let t=e.trim();if(t.startsWith("readonly ")&&(t=t.slice(9).trim()),!t.startsWith("[")||!t.endsWith("]"))return;const n=t.slice(1,-1).trim();if(n.length!==0)return xe(n)}async function it(e,t){const n=e.trim(),o=nt(n);if(o!==void 0){const s=xe(o);if(s.length===2){const[a,c]=await Promise.all([t(s[0]),t(s[1])]);return{type:"array",items:{type:"array",items:[a,c],minItems:2,maxItems:2}}}}const r=rt(n);if(r!==void 0)return{type:"array",items:await t(r),uniqueItems:!0};const i=ot(n);if(i!==void 0){const s=await Promise.all(i.map(a=>t(a)));return{type:"array",items:s,minItems:s.length,maxItems:s.length}}}const we={"decimal.js":"Decimal"},Q={Date:{type:"string",format:"date-time"},bigint:{type:"string",format:"int64"},Uint8Array:{type:"string",format:"byte"},Buffer:{type:"string",format:"byte"},URL:{type:"string",format:"uri"},RegExp:{type:"string",format:"regex"},Decimal:{type:"string",format:"decimal"}},ce={Uint8Array:"byte",Buffer:"byte",Decimal:"decimal"};function ue(e){var n;const t=new Map;for(const o of e.getImportDeclarations()){const r=o.getModuleSpecifierValue(),i=we[r];if(!i)continue;const s=o.getDefaultImport();if(s){const a=s.getText();a!==i&&t.set(a,i)}for(const a of o.getNamedImports()){const c=((n=a.getAliasNode())==null?void 0:n.getText())??a.getName();c!==i&&t.set(c,i)}}return t}function st(e,t){return n=>{n.addNodeParser({supportsNode(o){var i,s,a;if(o.kind!==t)return!1;const r=((i=o.typeName)==null?void 0:i.escapedText)??((a=(s=o.typeName)==null?void 0:s.right)==null?void 0:a.escapedText);return r!==void 0&&Object.prototype.hasOwnProperty.call(ce,r)},createType(o){var i,s,a;const r=((i=o.typeName)==null?void 0:i.escapedText)??((a=(s=o.typeName)==null?void 0:s.right)==null?void 0:a.escapedText);return new E.AnnotatedType(new E.StringType,{format:ce[r]},!1)}}),n.addNodeParser({supportsNode(o){return o.kind===e},createType(){return new E.AnnotatedType(new E.StringType,{format:"int64"},!1)}})}}let F;function at(){if(F)return F;try{const e=D.dirname(require.resolve("ts-json-schema-generator/package.json"));F=require(require.resolve("typescript",{paths:[e]}))}catch{F=require("typescript")}return F}const k=new Map;function ct(){const e=process.env.APIGEN_PROGRAM_CACHE,t=e===void 0?NaN:Number(e);return Number.isFinite(t)&&t>=0?t:8}function ut(e){const t=k.get(e);return t&&(k.delete(e),k.set(e,t)),t}function lt(e,t){const n=ct();if(n!==0)for(k.delete(e),k.set(e,t);k.size>n;){const o=k.keys().next().value;k.delete(o)}}function ft(e,t){return`${e}\0${t??""}`}const pt=new Set(["zod",/^zod\/./]);function mt(e){for(const t of e.getImportDeclarations()){const n=t.getModuleSpecifierValue();for(const o of pt)if(typeof o=="string"){if(n===o)return!0}else if(o.test(n))return!0}return!1}function gt(e){for(const t of["$defs","definitions"]){const n=e[t];if(!n||typeof n!="object")continue;const o=Object.keys(n);if(o.length===0)continue;const r=new Set(o.filter(i=>/zod/i.test(i)));for(const[i,s]of Object.entries(n)){if(r.has(i)||typeof s!="object"||s===null)continue;const a=s,c=typeof a.$ref=="string"?a.$ref:"";if(c){for(const l of r)if(c.includes(l)){r.add(i);break}}}for(const i of r)delete n[i]}X(e)}function X(e,t){if(!e||typeof e!="object")return;const n=t??new WeakSet;if(!n.has(e)){n.add(e);for(const o of Object.keys(e))if(o==="$ref"&&typeof e[o]=="string"){const r=e[o];/zod/i.test(r)&&delete e[o]}for(const[,o]of Object.entries(e))if(typeof o=="object"&&o!==null)if(Array.isArray(o))for(const r of o)typeof r=="object"&&r!==null&&X(r,n);else X(o,n)}}function dt(e){const t=new Set;for(const o of["$defs","definitions"]){const r=e[o];if(r&&typeof r=="object")for(const i of Object.keys(r))t.add(i)}const n=Y(e,t);if(n.length>0)throw new Error(`[apigen-core-client] Generated schema contains ${n.length} unresolvable $ref(s): ${n.join(", ")}. This usually means zod-internal definitions were stripped but $ref references to them remain. Check the source file's imports or the ts-json-schema-generator output.`)}function Y(e,t){if(!e||typeof e!="object")return[];const n=[];for(const[o,r]of Object.entries(e))if(o==="$ref"&&typeof r=="string"){const i=r.match(/#\/(?:\$defs|definitions)\/(.+)$/);i&&!t.has(i[1])&&n.push(r)}else if(typeof r=="object"&&r!==null)if(Array.isArray(r))for(const i of r)typeof i=="object"&&i!==null&&n.push(...Y(i,t));else n.push(...Y(r,t));return n}function yt(e){const t=e.anyOf;if(!Array.isArray(t)||t.length<2)return e;const n=t,o=W(n),r={...e};return delete r.anyOf,{...r,oneOf:n,...o?{discriminator:o}:{},[B]:r[B]??"union"}}function ht(e,t,n){const{DEFAULT_CONFIG:o}=require("ts-json-schema-generator/dist/src/Config.js"),r={...o,...e},i=r.path,s=ft(i,r.tsconfig);let a;a=n?n.statVersion(i):Te(i);let c;if(s!==void 0){const u=(n==null?void 0:n.generatorCache.get(s))??ut(s);u&&u.version===a&&(c=u.gen)}if(!c){const{createProgram:u}=require("ts-json-schema-generator/dist/factory/program.js"),f=at(),p=st(f.SyntaxKind.BigIntKeyword,f.SyntaxKind.TypeReference),b=u(r),h=E.createParser(b,r,p),m=E.createFormatter(r);if(c=new E.SchemaGenerator(b,h,m,r),n&&n.stats.generatorsBuilt++,s!==void 0&&a!==void 0){const T={version:a,gen:c};lt(s,T),n==null||n.generatorCache.set(s,T)}}const l=c.createSchema(r.type);return gt(l),dt(l),l}function Tt(e,t){let n=e.trim();if(n=Pe(n),t!=null&&t.size){const r=t.get(n);if(r!==void 0)return r}const o=n.match(/^ReadonlyArray<(.+)>$/);for(o&&(n=`${o[1].trim()}[]`);n.startsWith("readonly ");)n=n.slice(9).trim();return n}function je(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}const bt=Object.entries(we).map(([e,t])=>({pattern:new RegExp(`import\\(["'][^"']*${je(e)}[^"']*["']\\)\\.\\w+`,"g"),key:t}));function Pe(e){let t=e;for(const{pattern:n,key:o}of bt)t=t.replace(n,o);return t}function St(e,t){let n=Pe(e);for(const[o,r]of t)n=n.replace(new RegExp(`\\b${je(o)}\\b`,"g"),r);return n}async function $(e,t,n,o,r,i){const s=t.getFilePath(),a=`${s}\0${o??""}\0${n}`,c=i??new Set;if(c.has(a))return{};if(!r){const h=new Set(c);return h.add(a),le(e,t,n,o,void 0,h)}const l=r.schemaCache.get(a);if(l!==void 0)return r.stats.schemaCacheHits++,l;const u=We(s,o,r.statVersion(s)),f=u.get(n);if(f!==void 0)return r.stats.schemaCacheHits++,r.schemaCache.set(a,Promise.resolve(f)),f;r.stats.schemaCacheMisses++;const p=new Set(c);p.add(a);const b=le(e,t,n,o,r,p).then(h=>(u.set(n,h),h)).catch(h=>{throw r.schemaCache.delete(a),h});return r.schemaCache.set(a,b),b}async function le(e,t,n,o,r,i){if(["void","undefined","null","Promise<void>"].includes(n))return{type:"null"};let s;if(r){const p=r.aliasCache.get(t);s=p??ue(t),p||r.aliasCache.set(t,s)}else s=ue(t);const a=Tt(n,s),c=Q[a];if(c!==void 0)return c;const l=await it(a,p=>$(e,t,p,o,r,i));if(l!==void 0)return l;const u=(r==null?void 0:r.zodImportCache.get(t))??mt(t);if(r&&r.zodImportCache.set(t,u),!u)try{const p={path:t.getFilePath(),type:a,skipTypeCheck:!0,tsconfig:o,topRef:!1},b=ht(p,!0,r);return yt(b)}catch{}try{const p=await tt(e,t,a,b=>ve(b,h=>$(e,t,h,o,r,i),0));if(p!==void 0)return p}catch{}const f=St(a,s);return z(f,0,s)}function ne(e,t,n){if(e!=null&&e.hasInitializer()){const o=e.getInitializer();if(o)return o.getText()}return vt(n,t)}function vt(e,t){var s;const n=e,o=((s=n==null?void 0:n.getJsDocs)==null?void 0:s.call(n))??[],r=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=new RegExp(`\\[\\s*${r}\\s*=\\s*([^\\]]+)\\]`);for(const a of o)for(const c of a.getTags()){if(c.getTagName()!=="param")continue;const l=c.getText().match(i);if(l)return l[1].trim()}}function xt(e){const t=e.trim(),n=t.match(/^(['"`])([\s\S]*)\1$/);if(n)return n[2];if(t==="true")return!0;if(t==="false")return!1;if(t==="null")return null;if(t!=="undefined"){if(/^-?\d+(\.\d+)?$/.test(t))return Number(t);try{return JSON.parse(t)}catch{return t}}}function wt(e,t){const n=xt(t);if(n===void 0)return;e.default=n;const o=typeof n=="string"?n:JSON.stringify(n),r=typeof e.description=="string"?e.description:void 0;e.description=r?`${r} (default: ${o})`:`(default: ${o})`}async function jt(e){const t=e.session===void 0,n=be(e.session??te());try{return await Pt(e,n)}finally{t&&n.dispose()}}async function Pt(e,t){const{sourceFile:n,namespace:o="",dropFileSegment:r=!1,tsconfig:i}=e,s=t.projectFor(i),a=t.sourceFileFor(n,i),c=D.basename(n),l=O(Ot(c)),u=r?null:l,f=O(o),p=[];for(const[m,T]of a.getExportedDeclarations()){if(m==="default"||q(m))continue;const d=kt(T);if(d){const S=d.getSignature(),x=fe(S,d),w=S.getReturnType().getText();p.push(await V(s,a,f,u,m,x,w,d.isAsync(),i,t));continue}const y=T.find(S=>S.getKindName()==="VariableDeclaration");if(!y)continue;const g=y.getInitializer(),v=g==null?void 0:g.getKindName();if(g&&["ArrowFunction","FunctionExpression"].includes(v??"")){const x=y.getType().getCallSignatures();if(x.length===0)continue;const w=x[0],P=pe(w,y,y.getVariableStatement()),j=w.getReturnType().getText(),A=g.isAsync();p.push(await V(s,a,f,u,m,P,j,A,i,t))}else if(v==="ObjectLiteralExpression"){const S=y.getType();for(const x of S.getProperties()){const w=x.getName();if(q(w))continue;const j=x.getTypeAtLocation(y).getCallSignatures();if(j.length===0)continue;const A=j[0],U=pe(A,y,y.getVariableStatement()),L=A.getReturnType().getText(),M=[...u?[u]:[],O(m),O(w)];p.push(await K(s,a,f,M,w,U,L,!1,i,t))}}else{const S=y.getType(),x=S.getText();if(C(S,y)){const w=await $(s,a,x,i,t);p.push(At(f,u,m,w))}else console.warn(`[apigen-core] Skipping non-callable, non-serializable export: ${m}`)}}const b=a.getDefaultExportSymbol();if(b){const m=a.getExportAssignment(T=>!T.isExportEquals());if(m){const T=m.getExpression(),d=T.getKindName();if(["ArrowFunction","FunctionExpression"].includes(d)){const g=T.getType().getCallSignatures();if(g.length>0){const v=g[0],S=G(v,m),x=v.getReturnType().getText(),w=T.isAsync();p.push(await V(s,a,f,u,"default",S,x,w,i,t))}}else{const y=T.getType();for(const g of y.getProperties()){const v=g.getName();if(q(v))continue;const x=g.getTypeAtLocation(m).getCallSignatures();if(x.length===0)continue;const w=x[0],P=G(w,m),j=w.getReturnType().getText(),A=[...u?[u]:[],O("default"),O(v)];p.push(await K(s,a,f,A,v,P,j,!1,i,t))}}}else{const T=b.getDeclarations();for(const d of T){if(d.getKindName()!=="FunctionDeclaration")continue;const y=d,g=y.getName(),v=g&&g.length>0?g:"default",S=y.getSignature(),x=fe(S,y),w=S.getReturnType().getText();p.push(await V(s,a,f,u,v,x,w,y.isAsync(),i,t))}}}const h=Nt(a);if(h.length>0)for(const{name:m,sig:T}of h){if(q(m))continue;const d=G(T),y=T.getReturnType().getText(),g=[...u?[u]:[],O(m)];p.push(await K(s,a,f,g,m,d,y,!1,i,t))}return p}function $t(e,t,n,o){const r=new Set,i=s=>{if(Array.isArray(s))return s.map(i);if(!s||typeof s!="object"||r.has(s))return s;r.add(s);try{const a=s,c={};for(const[l,u]of Object.entries(a)){if(l==="definitions"||l==="$defs"){const f=l,p=t[f];for(const[b,h]of Object.entries(u)){const m=i(h),T=p[b];if(T!==void 0&&JSON.stringify(T)!==JSON.stringify(m))throw new Error(`[apigen-core-client] Function "${n}": param "${o}" contributes a "${f}.${b}" definition that conflicts with an identically-named definition already hoisted from another param/output in the same function. Two structurally different types share the same generated definition key, so apigen cannot safely merge them into one function-level schema.`);p[b]=m}continue}c[l]=i(u)}return c}finally{r.delete(s)}};return i(e)}async function V(e,t,n,o,r,i,s,a,c,l){const u=O(r);return K(e,t,n,o?[o,u]:[u],r,i,s,a,c,l)}async function K(e,t,n,o,r,i,s,a,c,l){const u=i.length>0&&i[0].name==="ctx",f=i.filter(g=>g.name!=="ctx"),p=f.filter(g=>!g.optional).map(g=>g.name),b={},h={definitions:{},$defs:{}};for(const g of f){const v=await $(e,t,g.type,c,l),S=$t(v,h,r,g.name);g.defaultValue!==void 0&&wt(S,g.defaultValue),b[g.name]=S}const m=s.replace(/^Promise<(.+)>$/,"$1").trim(),T=await $(e,t,m,c,l),d={type:"object",properties:b,required:p,...Object.keys(h.definitions).length>0?{definitions:h.definitions}:{},...Object.keys(h.$defs).length>0?{$defs:h.$defs}:{}};return{id:$e(n,o),host:"ts",namespace:n,path:o,kind:"action",async:a,streaming:!1,safe:!1,input:d,output:T,envelope:{},typeText:{lang:"ts",input:Ct(i),output:m},...u?{hasCtx:!0}:{}}}function At(e,t,n,o){const r=O(n),i=t?[t,r]:[r];return{id:$e(e,i),host:"ts",namespace:e,path:i,kind:"query",async:!1,streaming:!1,safe:!0,input:{type:"object",properties:{},required:[]},output:o,envelope:{},typeText:null}}function $e(e,t){return(e.raw?[e,...t]:t).map(o=>o.words.join("-")).join("/")}function re(e){return e.split(/[-_.]+/).flatMap(t=>t.replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2").replace(/([a-z\d])([A-Z])/g,"$1_$2").split("_").filter(Boolean)).map(t=>t.toLowerCase()).filter(Boolean)}function O(e){return{raw:e,words:re(e)}}function Ot(e){return e.replace(/\.[^.]+$/,"").replace(/[._]+/g,"-")}function Nt(e){const t=[];for(const n of e.getStatements()){if(n.getKindName()!=="ExpressionStatement")continue;const o=n.getExpression();if(o.getKindName()!=="BinaryExpression")continue;const r=o;if(r.getLeft().getText().trim()!=="module.exports"||r.getOperatorToken().getKindName()!=="EqualsToken")continue;const s=r.getRight(),a=s.getType();for(const c of a.getProperties()){const u=c.getTypeAtLocation(s).getCallSignatures();u.length!==0&&t.push({name:c.getName(),sig:u[0]})}}return t}function kt(e){let t;for(const n of e){if(n.getKindName()!=="FunctionDeclaration")continue;const o=n;if(t||(t=o),o.getBody())return o}return t}function fe(e,t){return e.getParameters().map(n=>{var s;const o=n.getDeclarations(),r=o.length>0&&o[0].getKindName()==="Parameter"?o[0]:null,i=n.isOptional()||((r==null?void 0:r.hasInitializer())??!1)||(((s=r==null?void 0:r.hasQuestionToken)==null?void 0:s.call(r))??!1);return{name:n.getName(),type:n.getTypeAtLocation(e.getDeclaration()).getText(),optional:i,defaultValue:ne(r,n.getName(),t)}})}function pe(e,t,n){return e.getParameters().map(o=>{var a;const r=o.getDeclarations(),i=r.length>0&&r[0].getKindName()==="Parameter"?r[0]:null,s=o.isOptional()||((i==null?void 0:i.hasInitializer())??!1)||(((a=i==null?void 0:i.hasQuestionToken)==null?void 0:a.call(i))??!1);return{name:o.getName(),type:o.getTypeAtLocation(t).getText(),optional:s,defaultValue:ne(i,o.getName(),n??t)}})}function G(e,t){return e.getParameters().map(n=>{var s,a,c;const o=n.getDeclarations(),r=o.length>0&&o[0].getKindName()==="Parameter"?o[0]:null,i=n.isOptional()||((r==null?void 0:r.hasInitializer())??!1)||(((s=r==null?void 0:r.hasQuestionToken)==null?void 0:s.call(r))??!1);return{name:n.getName(),type:r?r.getType().getText():((c=(a=n.getValueDeclaration())==null?void 0:a.getType())==null?void 0:c.getText())??"unknown",optional:i,defaultValue:ne(r,n.getName(),t)}})}function Ct(e){const t=e.filter(n=>n.name!=="ctx");return t.length===0?"()":"("+t.map(n=>`${n.name}${n.optional?"?":""}: ${n.type}`).join(", ")+")"}function q(e){return!!(e==="__samples__"||e.startsWith("__"))}function C(e,t,n=new Set){if(e.getCallSignatures().length>0||e.getConstructSignatures().length>0)return!1;if(e.isString()||e.isNumber()||e.isBoolean()||e.isNull()||e.isUndefined()||e.isStringLiteral()||e.isNumberLiteral()||e.isBooleanLiteral()||e.isEnumLiteral())return!0;if(e.isArray()||e.isReadonlyArray()){const o=e.getArrayElementType();return o?C(o,t,n):!1}if(e.isTuple())return e.getTupleElements().every(o=>C(o,t,n));if(e.isUnion())return e.getUnionTypes().every(o=>C(o,t,n));if(e.isIntersection())return e.getIntersectionTypes().every(o=>C(o,t,n));if(e.isObject()){const o=e.getText(t);if(n.has(o))return!0;n.add(o);const r=e.getStringIndexType(),i=e.getNumberIndexType();if(r||i)return[r,i].every(a=>!a||C(a,t,n));const s=e.getProperties();return s.length===0?!0:s.every(a=>{const c=a.getTypeAtLocation(t);return C(c,t,n)})}return!1}async function Et(e){const t=e.session===void 0,n=be(e.session??te());try{return await It(e,n)}finally{t&&n.dispose()}}async function It(e,t){const{sourceFile:n,namespace:o="",tsconfig:r,includeInstances:i=!1}=e,s=t.projectFor(r),a=t.sourceFileFor(n,r),c=D.basename(n),l=R(Rt(c)),u=R(o),f=[];for(const[p,b]of a.getExportedDeclarations()){const h=b.find(d=>d.getKindName()==="ClassDeclaration");if(!h)continue;const m=p==="default"?h.getName():p;if(!m||H(m))continue;const T=R(m);for(const d of h.getStaticMethods()){const y=d.getName();if(H(y))continue;const g=d.getScope();if(g===I.Scope.Private||g===I.Scope.Protected)continue;const v=d.getSignature(),S=Z(v,d),x=v.getReturnType().getText(),w=d.isAsync(),P=[l,T,R(y)];f.push(await Ft(s,a,u,P,S,x,w,r,t))}if(i){{const y=h.getConstructors()[0]??null;let g=[];if(y){const j=y.getSignature();g=Z(j,y)}const v=[l,T],S=ee(u,v),x=g.filter(j=>j.name!=="ctx"),w=x.filter(j=>!j.optional).map(j=>j.name),P={};for(const j of x)P[j.name]=await $(s,a,j.type,r,t);f.push({id:S,host:"ts",namespace:u,path:v,kind:"constructor",async:!1,streaming:!1,safe:!1,input:{type:"object",properties:P,required:w},output:{type:"object",properties:{instanceId:{type:"string"}},required:["instanceId"]},envelope:{},typeText:{lang:"ts",input:_t(g),output:"{ instanceId: string }"}})}for(const d of h.getInstanceMethods()){const y=d.getName();if(H(y))continue;const g=d.getScope();if(g===I.Scope.Private||g===I.Scope.Protected)continue;const v=d.getSignature(),S=Z(v,d),x=v.getReturnType().getText(),w=d.isAsync(),P=[l,T,R(y)],j=ee(u,P),A=S.filter(N=>N.name!=="ctx"),U=A.filter(N=>!N.optional).map(N=>N.name),L={};for(const N of A)L[N.name]=await $(s,a,N.type,r,t);const M=x.replace(/^Promise<(.+)>$/,"$1").trim(),Fe=await $(s,a,M,r,t);f.push({id:j,host:"ts",namespace:u,path:P,kind:"instance-method",async:w,streaming:!1,safe:!1,input:{type:"object",properties:L,required:U},output:Fe,envelope:{type:"object",properties:{instanceId:{type:"string"}},required:["instanceId"]},typeText:{lang:"ts",input:Ae(S),output:M}})}}}return f}async function Ft(e,t,n,o,r,i,s,a,c){const l=r.filter(m=>m.name!=="ctx"),u=l.filter(m=>!m.optional).map(m=>m.name),f={};for(const m of l)f[m.name]=await $(e,t,m.type,a,c);const p=i.replace(/^Promise<(.+)>$/,"$1").trim(),b=await $(e,t,p,a,c);return{id:ee(n,o),host:"ts",namespace:n,path:o,kind:"action",async:s,streaming:!1,safe:!1,input:{type:"object",properties:f,required:u},output:b,envelope:{},typeText:{lang:"ts",input:Ae(r),output:p}}}function ee(e,t){return(e.raw?[e,...t]:t).map(o=>o.words.join("-")).join("/")}function R(e){return{raw:e,words:re(e)}}function Rt(e){return e.replace(/\.[^.]+$/,"").replace(/[._]+/g,"-")}function Z(e,t){return e.getParameters().map(n=>{var s;const o=n.getDeclarations(),r=o.length>0&&o[0].getKindName()==="Parameter"?o[0]:null,i=n.isOptional()||((r==null?void 0:r.hasInitializer())??!1)||(((s=r==null?void 0:r.hasQuestionToken)==null?void 0:s.call(r))??!1);return{name:n.getName(),type:n.getTypeAtLocation(t).getText(),optional:i}})}function Ae(e){const t=e.filter(n=>n.name!=="ctx");return t.length===0?"()":"("+t.map(n=>`${n.name}${n.optional?"?":""}: ${n.type}`).join(", ")+")"}function _t(e){return e.length===0?"()":"("+e.map(t=>`${t.name}${t.optional?"?":""}: ${t.type}`).join(", ")+")"}function H(e){return!!(e==="__samples__"||e.startsWith("__")||e.startsWith("_"))}const Lt=new Map([[".ts","ts"],[".tsx","ts"],[".mts","ts"],[".cts","ts"],[".py","py"],[".rs","rust"],[".go","go"],[".java","java"]]);function Oe(e){const t=De.extname(e).toLowerCase();return Lt.get(t)}function Ne(e){return e.language??"ts"}function ke(e,t){const n=Oe(t);return n===void 0?!1:n===Ne(e)}function Mt(e,t){return t.filter(n=>ke(e,n))}function Vt(e){return{oneOf:[{type:"object",required:["index","status","value"],properties:{index:{type:"integer"},status:{type:"string",enum:["fulfilled"]},value:e}},{type:"object",required:["index","status","chunks"],properties:{index:{type:"integer"},status:{type:"string",enum:["fulfilled"]},chunks:{type:"array"}}},{type:"object",required:["index","status","reason"],properties:{index:{type:"integer"},status:{type:"string",enum:["rejected"]},reason:{},chunksDelivered:{type:"integer"}}}]}}function Ce(e){return{operationConst:e.id,itemsSchema:e.input,resultSchema:Vt(e.output)}}function Ee(e,t={}){const n=new Set(t.exclude??[]),o=new Map;for(const r of e){if(n.has(r.id))continue;const i=o.get(r.kind);i?i.push(r):o.set(r.kind,[r])}return o}function me(e){return{type:"string",enum:[e]}}function ge(e,t){return{type:"object",required:["operation","items"],properties:{operation:t,items:{type:"array",items:e.itemsSchema},concurrency:{type:"number"},mode:{type:"string",enum:["parallel","serial","chained"]},onItemError:{type:"string",enum:["continue","abort"]},itemTimeoutMs:{type:"number"}},additionalProperties:!0}}function Ie(e){if(e.length===0)throw new Error("buildBatchKindSchema: at least one operation is required");const t=e.map(Ce);if(e.length===1){const[r]=e,[i]=t;return{input:ge(i,me(r.id)),output:{type:"array",items:i.resultSchema}}}const n=e.map((r,i)=>ge(t[i],me(r.id))),o=W(n);return{input:{oneOf:n,...o?{discriminator:o}:{}},output:{oneOf:t.map(r=>({type:"array",items:r.resultSchema}))},...o?{discriminator:o}:{}}}function qt(e,t={}){const n=Ee(e.operations,t),o=[];for(const[r,i]of n){const{input:s,output:a}=Ie(i),c=de(`_batch/${r}`,e,{kind:r,safe:r==="query",input:s,output:a});o.push({...c,operationIds:i.map(l=>l.id)})}return o}exports.buildBatchKindSchema=Ie;exports.buildBatchMountedOperations=qt;exports.clearPersistentProjectCache=Ue;exports.composeSchemas=Qe;exports.createExtractionSession=te;exports.deriveBatchOperationBranch=Ce;exports.effectiveLanguage=Ne;exports.extract=jt;exports.extractClasses=Et;exports.groupBatchableOperationsByKind=Ee;exports.isPrimitiveOnlyInputSchema=Se;exports.languageOfSource=Oe;exports.pluginConsumesSource=ke;exports.pluginsToEnvelopeMiddlewares=Ze;exports.sourcesForPlugin=Mt;exports.syntheticOp=de;exports.tokenize=re;
1
+ "use strict";var Re=Object.create;var oe=Object.defineProperty;var _e=Object.getOwnPropertyDescriptor;var Le=Object.getOwnPropertyNames;var Me=Object.getPrototypeOf,qe=Object.prototype.hasOwnProperty;var Ve=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Le(t))!qe.call(e,r)&&r!==n&&oe(e,r,{get:()=>t[r],enumerable:!(o=_e(t,r))||o.enumerable});return e};var ze=(e,t,n)=>(n=e!=null?Re(Me(e)):{},Ve(t||!e||!e.__esModule?oe(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("ts-morph"),Ke=require("node:fs"),D=require("node:path"),E=require("ts-json-schema-generator");function Be(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const De=Be(D);function ie(e){return{raw:e,words:e.split(/(?=[A-Z])|[-_]/).map(t=>t.toLowerCase()).filter(Boolean)}}function de(e,t,n={}){const o=e.split("/");if(o.length<2||o.some(l=>l.length===0))throw new Error(`syntheticOp: id "${e}" must be "<namespace>/<path...>" with non-empty segments`);const[r,...i]=o,s=r.replace(/^_+/,""),a=n.kind??"action",c={id:e,host:t.host,namespace:ie(s),path:i.map(ie),kind:a,async:n.async??!1,streaming:n.streaming??!1,safe:n.safe??a==="query",input:n.input??{},output:n.output??{},envelope:n.envelope??{},typeText:n.typeText??null};return n.hasCtx!==void 0&&(c.hasCtx=n.hasCtx),n.transports!==void 0&&(c.transports=n.transports),c}const ye=Symbol.for("adhd.apigen.extraction-session");function he(e,t){const n=[...e.getImportDeclarations().map(o=>o.getModuleSpecifierSourceFile()),...e.getExportDeclarations().map(o=>o.getModuleSpecifierSourceFile())];for(const o of n){if(!o)continue;const r=o.getFilePath();if(!r.includes("/node_modules/")&&!t.has(r)){t.add(r);try{o.refreshFromFileSystemSync()}catch{}he(o,t)}}}function Te(e){try{const t=Ke.statSync(e);return`${t.mtimeMs}:${t.size}`}catch{return"nostat"}}const _=new Map,J=new Map;function We(e,t,n){const o=t??"",r=_.get(o);let i=n;if(r&&r.fileVersions.size>0){const c=[n],l=[...r.fileVersions.entries()].sort(([u],[f])=>u.localeCompare(f));for(const[u,f]of l)u!==e&&c.push(`${u}:${f}`);i=c.join("|")}const s=`${e}\0${t??""}`;let a=J.get(s);return(!a||a.version!==i)&&(a={version:i,schemas:new Map},J.set(s,a)),a.schemas}function Ue(){_.clear(),J.clear()}function te(){const e={projectsBuilt:0,generatorsBuilt:0,schemaCacheHits:0,schemaCacheMisses:0},t=new Map;let n=!1;return{[ye]:!0,stats:e,schemaCache:new Map,aliasCache:new WeakMap,zodImportCache:new WeakMap,generatorCache:new Map,projectFor(r){if(n)throw new Error("apigen-core: ExtractionSession used after dispose()");const i=r??"",s=r?this.statVersion(r):"";let a=_.get(i);return a&&a.tsconfigVersion!==s&&(a=void 0),a||(a={project:r?new I.Project({tsConfigFilePath:r,skipAddingFilesFromTsConfig:!0}):new I.Project({skipAddingFilesFromTsConfig:!0}),tsconfigVersion:s,fileVersions:new Map},_.set(i,a),e.projectsBuilt++),a.project},sourceFileFor(r,i){const s=this.projectFor(i),a=_.get(i??""),c=this.statVersion(r);let l=s.getSourceFile(r);if(l===void 0?l=s.addSourceFileAtPath(r):a&&a.fileVersions.get(r)!==c&&l.refreshFromFileSystemSync(),a==null||a.fileVersions.set(r,c),a){const u=new Set([r]);he(l,u);for(const f of u)f!==r&&a.fileVersions.set(f,this.statVersion(f))}return l},statVersion(r){let i=t.get(r);return i===void 0&&(i=Te(r),t.set(r,i)),i},dispose(){n=!0,this.schemaCache.clear(),this.generatorCache.clear(),t.clear()}}}function be(e){const t=e;if(t[ye]!==!0)throw new Error("apigen-core: unknown ExtractionSession implementation โ€” create sessions with createExtractionSession()");return t}const B="x-apigen-logical";function se(e,t){const n=new Set,o=[e];for(;o.length>0;){const r=o.pop();if(!r||n.has(r))continue;n.add(r);const i=r.$ref;if(typeof i=="string"){if(t){const f=t[i];if(!f){const p=Object.keys(t).join(", ")||"(none)";throw new Error(`[apigen-logical] $ref "${i}" cannot be resolved. Available $defs: ${p}`)}o.push(f)}continue}const s=r.oneOf;if(Array.isArray(s))for(const f of s)typeof f=="object"&&f!==null&&o.push(f);const a=r.properties;if(a)for(const f of Object.values(a))o.push(f);const c=r.items;if(Array.isArray(c))for(const f of c)typeof f=="object"&&f!==null&&o.push(f);else typeof c=="object"&&c!==null&&o.push(c);const l=r.additionalProperties;typeof l=="object"&&l!==null&&o.push(l);const u=r.propertyNames;typeof u=="object"&&u!==null&&o.push(u)}}const ae=new Set(["string","number","boolean","integer"]);function Ge(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:n}=t;return typeof n=="string"?ae.has(n):Array.isArray(n)?n.every(o=>ae.has(o)||o==="null"):Array.isArray(t.enum)&&t.enum.length>0?t.enum.every(o=>["string","number","boolean"].includes(typeof o)):!1}function Se(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(Ge)}function Ze(e){var n,o;const t=[];for(const r of e){const i={...(n=r.capabilities.layer)==null?void 0:n.envelopeFields,...(o=r.capabilities.envelope)==null?void 0:o.request};Object.keys(i).length>0&&t.push({id:r.id,envelope:i})}return t}function He(e){const t={},n=o=>{for(const r of["definitions","$defs"]){const i=o[r];if(i)for(const[s,a]of Object.entries(i)){const c=s.startsWith("#/")?s:`#/${r}/${s}`;t[c]=a}}};for(const o of Object.values(e.schemas))n(o.input),n(o.output);if(Object.keys(t).length!==0)for(const[o,r]of Object.entries(e.schemas))try{se(r.input,t),se(r.output,t)}catch(i){throw new Error(`[apigen-core-client] Schema validation failed for function "${o}": ${i.message}`)}}function Je(e,t){const n=['apigen calling convention: all domain parameters go inside a "data" envelope โ€” e.g. { "data": { ... } }'+(t?".":" (an empty object for this zero-parameter tool).")];return e.length>0&&n.push(`Field(s) ${e.map(o=>`"${o}"`).join(", ")} are transport-level envelope metadata, NOT domain data โ€” do not nest them under "data". Over MCP they are read from arguments._meta["x-<pluginId>-<field>"] (default pluginId "adhd"); see @adhd/apigen-engine-naming's envelopeMetaKey/envelopeCliFlag/envelopeEnvVar for the HTTP-header / CLI-flag / env-var equivalents.`),n.join(" ")}function Qe(e,t,n){He(e);const o={};for(const[r,i]of Object.entries(e.schemas)){const s=(n==null?void 0:n[r])??{},a=i.input.properties??{},c=i.input.required??[],l={},u=[],f={};for(const b of t)if(b.envelope&&s[b.id]!==!1)for(const[y,h]of Object.entries(b.envelope))l[y]=h,f[y]=b.id,u.includes(y)||u.push(y);const p={type:"object",properties:a,additionalProperties:!1,...c.length>0?{required:c}:{}},T=i.safe===!0||Se(i.input),d=i.input.definitions,m=i.input.$defs;o[r]={input:{type:"object",properties:{...l,data:p},required:[...u,...c.length>0?["data"]:[]],additionalProperties:!1,description:Je(Object.keys(l),Object.keys(a).length>0),...d?{definitions:d}:{},...m?{$defs:m}:{}},output:i.output,...i.hasCtx?{hasCtx:!0}:{},"x-apigen-safe":T,...Object.keys(f).length>0?{"x-apigen-envelope":f}:{}}}return o}const Xe=8;function Ye(e,t){try{return t?e.getText(t):e.getText()}catch{try{return e.getText()}catch{return}}}let et=0;async function tt(e,t,n,o){const r=`__ApigenProbe_${process.pid}_${et++}`;let i;try{i=t.addTypeAlias({name:r,type:n});const s=i.getType();return await o(s)}catch{return}finally{try{i==null||i.remove()}catch{}}}async function ve(e,t,n){if(n>Xe)return{};if(e.isString()||e.isStringLiteral())return e.isStringLiteral()?{type:"string",enum:[e.getLiteralValue()]}:{type:"string"};if(e.isNumber()||e.isNumberLiteral())return e.isNumberLiteral()?{type:"number",enum:[e.getLiteralValue()]}:{type:"number"};if(e.isBoolean())return{type:"boolean"};if(e.isBooleanLiteral())return{type:"boolean"};if(e.isNull()||e.isUndefined()||e.isVoid())return{type:"null"};if(e.isUnion()){const o=e.getUnionTypes();if(o.every(c=>c.isStringLiteral())&&o.length>0)return{type:"string",enum:o.map(c=>c.getLiteralValue())};if(o.every(c=>c.isNumberLiteral())&&o.length>0)return{type:"number",enum:o.map(c=>c.getLiteralValue())};const s=await Promise.all(o.map(c=>ve(c,t,n+1))),a=W(s);return{oneOf:s,...a?{discriminator:a}:{},[B]:"union"}}if(e.isArray()){const o=e.getArrayElementType();return{type:"array",items:o?await t(o.getText()):{}}}if(e.isTuple()){const o=e.getTupleElements(),r=await Promise.all(o.map(i=>t(i.getText())));return{type:"array",items:r,minItems:r.length,maxItems:r.length}}if(e.isObject()){const o=e.getStringIndexType(),r=e.getNumberIndexType(),i=o??r,s=e.getProperties();if(i&&s.length===0)return{type:"object",additionalProperties:await t(i.getText())};const a={},c=[];for(const l of s){const u=l.getName(),p=l.getDeclarations()[0];let T;if(p)try{T=l.getTypeAtLocation(p)}catch{T=void 0}if(T!==void 0&&T.getCallSignatures().length>0)continue;const d=T!==void 0?Ye(T,p):void 0;a[u]=d!==void 0?await t(d):{},l.isOptional()||c.push(u)}return Object.keys(a).length>0?{type:"object",properties:a,...c.length>0?{required:c}:{}}:{}}return{}}function W(e){if(e.length<2)return;const t=[];for(const o of e){if(o.type!=="object")return;const r=o.properties;if(!r||typeof r!="object")return;t.push(r)}const n=Object.keys(t[0]).filter(o=>t.every(r=>Object.prototype.hasOwnProperty.call(r,o)));for(const o of n){const r=[];let i=!0;for(const a of t){const c=a[o],l=c&&(c.type==="string"||c.type==="number"),u=c==null?void 0:c.enum;if(!l||!Array.isArray(u)||u.length!==1){i=!1;break}r.push(String(u[0]))}if(!i||new Set(r).size!==r.length)continue;const s={};return r.forEach((a,c)=>{s[a]=`#/oneOf/${c}`}),{propertyName:o,mapping:s}}}function z(e,t,n){if(t>6)return{};const o=e.trim();if(o==="string")return{type:"string"};if(o==="number")return{type:"number"};if(o==="boolean")return{type:"boolean"};if(o==="null")return{type:"null"};if(o==="undefined")return{type:"null"};const r=Q[o];if(r!==void 0)return r;if(n!=null&&n.size){const i=n.get(o);if(i!==void 0){const s=Q[i];if(s!==void 0)return s}}if(o.endsWith("[]"))return{type:"array",items:z(o.slice(0,-2),t+1,n)};if(o.includes("|")){const i=o.split("|").map(c=>c.trim());if(i.every(c=>c.startsWith("'")))return{type:"string",enum:i.map(c=>c.replace(/'/g,""))};const s=i.map(c=>z(c,t+1,n)),a=W(s);return{oneOf:s,...a?{discriminator:a}:{},[B]:"union"}}if(o.startsWith("{")&&o.endsWith("}")){const i=o.slice(1,-1).trim(),s={};for(const a of i.split(";").filter(Boolean)){const[c,l]=a.split(":").map(u=>u.trim());c&&l&&(s[c.replace("?","")]=z(l,t+1,n))}return{type:"object",properties:s}}return{}}function xe(e){const t=[];let n=0,o=0;for(let i=0;i<e.length;i++){const s=e[i];s==="<"||s==="["||s==="{"||s==="("?n++:s===">"||s==="]"||s==="}"||s===")"?n--:s===","&&n===0&&(t.push(e.slice(o,i).trim()),o=i+1)}const r=e.slice(o).trim();return r.length>0&&t.push(r),t}function nt(e){const t=/^(?:Readonly)?Map<(.+)>$/.exec(e);return t?t[1]:void 0}function rt(e){const t=/^(?:Readonly)?Set<(.+)>$/.exec(e);return t?t[1]:void 0}function ot(e){let t=e.trim();if(t.startsWith("readonly ")&&(t=t.slice(9).trim()),!t.startsWith("[")||!t.endsWith("]"))return;const n=t.slice(1,-1).trim();if(n.length!==0)return xe(n)}async function it(e,t){const n=e.trim(),o=nt(n);if(o!==void 0){const s=xe(o);if(s.length===2){const[a,c]=await Promise.all([t(s[0]),t(s[1])]);return{type:"array",items:{type:"array",items:[a,c],minItems:2,maxItems:2}}}}const r=rt(n);if(r!==void 0)return{type:"array",items:await t(r),uniqueItems:!0};const i=ot(n);if(i!==void 0){const s=await Promise.all(i.map(a=>t(a)));return{type:"array",items:s,minItems:s.length,maxItems:s.length}}}const we={"decimal.js":"Decimal"},Q={Date:{type:"string",format:"date-time"},bigint:{type:"string",format:"int64"},Uint8Array:{type:"string",format:"byte"},Buffer:{type:"string",format:"byte"},URL:{type:"string",format:"uri"},RegExp:{type:"string",format:"regex"},Decimal:{type:"string",format:"decimal"}},ce={Uint8Array:"byte",Buffer:"byte",Decimal:"decimal"};function ue(e){var n;const t=new Map;for(const o of e.getImportDeclarations()){const r=o.getModuleSpecifierValue(),i=we[r];if(!i)continue;const s=o.getDefaultImport();if(s){const a=s.getText();a!==i&&t.set(a,i)}for(const a of o.getNamedImports()){const c=((n=a.getAliasNode())==null?void 0:n.getText())??a.getName();c!==i&&t.set(c,i)}}return t}function st(e,t){return n=>{n.addNodeParser({supportsNode(o){var i,s,a;if(o.kind!==t)return!1;const r=((i=o.typeName)==null?void 0:i.escapedText)??((a=(s=o.typeName)==null?void 0:s.right)==null?void 0:a.escapedText);return r!==void 0&&Object.prototype.hasOwnProperty.call(ce,r)},createType(o){var i,s,a;const r=((i=o.typeName)==null?void 0:i.escapedText)??((a=(s=o.typeName)==null?void 0:s.right)==null?void 0:a.escapedText);return new E.AnnotatedType(new E.StringType,{format:ce[r]},!1)}}),n.addNodeParser({supportsNode(o){return o.kind===e},createType(){return new E.AnnotatedType(new E.StringType,{format:"int64"},!1)}})}}let F;function at(){if(F)return F;try{const e=D.dirname(require.resolve("ts-json-schema-generator/package.json"));F=require(require.resolve("typescript",{paths:[e]}))}catch{F=require("typescript")}return F}const k=new Map;function ct(){const e=process.env.APIGEN_PROGRAM_CACHE,t=e===void 0?NaN:Number(e);return Number.isFinite(t)&&t>=0?t:8}function ut(e){const t=k.get(e);return t&&(k.delete(e),k.set(e,t)),t}function lt(e,t){const n=ct();if(n!==0)for(k.delete(e),k.set(e,t);k.size>n;){const o=k.keys().next().value;k.delete(o)}}function ft(e,t){return`${e}\0${t??""}`}const pt=new Set(["zod",/^zod\/./]);function mt(e){for(const t of e.getImportDeclarations()){const n=t.getModuleSpecifierValue();for(const o of pt)if(typeof o=="string"){if(n===o)return!0}else if(o.test(n))return!0}return!1}function gt(e){for(const t of["$defs","definitions"]){const n=e[t];if(!n||typeof n!="object")continue;const o=Object.keys(n);if(o.length===0)continue;const r=new Set(o.filter(i=>/zod/i.test(i)));for(const[i,s]of Object.entries(n)){if(r.has(i)||typeof s!="object"||s===null)continue;const a=s,c=typeof a.$ref=="string"?a.$ref:"";if(c){for(const l of r)if(c.includes(l)){r.add(i);break}}}for(const i of r)delete n[i]}X(e)}function X(e,t){if(!e||typeof e!="object")return;const n=t??new WeakSet;if(!n.has(e)){n.add(e);for(const o of Object.keys(e))if(o==="$ref"&&typeof e[o]=="string"){const r=e[o];/zod/i.test(r)&&delete e[o]}for(const[,o]of Object.entries(e))if(typeof o=="object"&&o!==null)if(Array.isArray(o))for(const r of o)typeof r=="object"&&r!==null&&X(r,n);else X(o,n)}}function dt(e){const t=new Set;for(const o of["$defs","definitions"]){const r=e[o];if(r&&typeof r=="object")for(const i of Object.keys(r))t.add(i)}const n=Y(e,t);if(n.length>0)throw new Error(`[apigen-core-client] Generated schema contains ${n.length} unresolvable $ref(s): ${n.join(", ")}. This usually means zod-internal definitions were stripped but $ref references to them remain. Check the source file's imports or the ts-json-schema-generator output.`)}function Y(e,t){if(!e||typeof e!="object")return[];const n=[];for(const[o,r]of Object.entries(e))if(o==="$ref"&&typeof r=="string"){const i=r.match(/#\/(?:\$defs|definitions)\/(.+)$/);i&&!t.has(i[1])&&n.push(r)}else if(typeof r=="object"&&r!==null)if(Array.isArray(r))for(const i of r)typeof i=="object"&&i!==null&&n.push(...Y(i,t));else n.push(...Y(r,t));return n}function yt(e){const t=e.anyOf;if(!Array.isArray(t)||t.length<2)return e;const n=t,o=W(n),r={...e};return delete r.anyOf,{...r,oneOf:n,...o?{discriminator:o}:{},[B]:r[B]??"union"}}function ht(e,t,n){const{DEFAULT_CONFIG:o}=require("ts-json-schema-generator/dist/src/Config.js"),r={...o,...e},i=r.path,s=ft(i,r.tsconfig);let a;a=n?n.statVersion(i):Te(i);let c;if(s!==void 0){const u=(n==null?void 0:n.generatorCache.get(s))??ut(s);u&&u.version===a&&(c=u.gen)}if(!c){const{createProgram:u}=require("ts-json-schema-generator/dist/factory/program.js"),f=at(),p=st(f.SyntaxKind.BigIntKeyword,f.SyntaxKind.TypeReference),T=u(r),d=E.createParser(T,r,p),m=E.createFormatter(r);if(c=new E.SchemaGenerator(T,d,m,r),n&&n.stats.generatorsBuilt++,s!==void 0&&a!==void 0){const b={version:a,gen:c};lt(s,b),n==null||n.generatorCache.set(s,b)}}const l=c.createSchema(r.type);return gt(l),dt(l),l}function Tt(e,t){let n=e.trim();if(n=Pe(n),t!=null&&t.size){const r=t.get(n);if(r!==void 0)return r}const o=n.match(/^ReadonlyArray<(.+)>$/);for(o&&(n=`${o[1].trim()}[]`);n.startsWith("readonly ");)n=n.slice(9).trim();return n}function je(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}const bt=Object.entries(we).map(([e,t])=>({pattern:new RegExp(`import\\(["'][^"']*${je(e)}[^"']*["']\\)\\.\\w+`,"g"),key:t}));function Pe(e){let t=e;for(const{pattern:n,key:o}of bt)t=t.replace(n,o);return t}function St(e,t){let n=Pe(e);for(const[o,r]of t)n=n.replace(new RegExp(`\\b${je(o)}\\b`,"g"),r);return n}async function $(e,t,n,o,r,i){const s=t.getFilePath(),a=`${s}\0${o??""}\0${n}`,c=i??new Set;if(c.has(a))return{};if(!r){const d=new Set(c);return d.add(a),le(e,t,n,o,void 0,d)}const l=r.schemaCache.get(a);if(l!==void 0)return r.stats.schemaCacheHits++,l;const u=We(s,o,r.statVersion(s)),f=u.get(n);if(f!==void 0)return r.stats.schemaCacheHits++,r.schemaCache.set(a,Promise.resolve(f)),f;r.stats.schemaCacheMisses++;const p=new Set(c);p.add(a);const T=le(e,t,n,o,r,p).then(d=>(u.set(n,d),d)).catch(d=>{throw r.schemaCache.delete(a),d});return r.schemaCache.set(a,T),T}async function le(e,t,n,o,r,i){if(["void","undefined","null","Promise<void>"].includes(n))return{type:"null"};let s;if(r){const p=r.aliasCache.get(t);s=p??ue(t),p||r.aliasCache.set(t,s)}else s=ue(t);const a=Tt(n,s),c=Q[a];if(c!==void 0)return c;const l=await it(a,p=>$(e,t,p,o,r,i));if(l!==void 0)return l;const u=(r==null?void 0:r.zodImportCache.get(t))??mt(t);if(r&&r.zodImportCache.set(t,u),!u)try{const p={path:t.getFilePath(),type:a,skipTypeCheck:!0,tsconfig:o,topRef:!1},T=ht(p,!0,r);return yt(T)}catch{}try{const p=await tt(e,t,a,T=>ve(T,d=>$(e,t,d,o,r,i),0));if(p!==void 0)return p}catch{}const f=St(a,s);return z(f,0,s)}function ne(e,t,n){if(e!=null&&e.hasInitializer()){const o=e.getInitializer();if(o)return o.getText()}return vt(n,t)}function vt(e,t){var s;const n=e,o=((s=n==null?void 0:n.getJsDocs)==null?void 0:s.call(n))??[],r=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=new RegExp(`\\[\\s*${r}\\s*=\\s*([^\\]]+)\\]`);for(const a of o)for(const c of a.getTags()){if(c.getTagName()!=="param")continue;const l=c.getText().match(i);if(l)return l[1].trim()}}function xt(e){const t=e.trim(),n=t.match(/^(['"`])([\s\S]*)\1$/);if(n)return n[2];if(t==="true")return!0;if(t==="false")return!1;if(t==="null")return null;if(t!=="undefined"){if(/^-?\d+(\.\d+)?$/.test(t))return Number(t);try{return JSON.parse(t)}catch{return t}}}function wt(e,t){const n=xt(t);if(n===void 0)return;e.default=n;const o=typeof n=="string"?n:JSON.stringify(n),r=typeof e.description=="string"?e.description:void 0;e.description=r?`${r} (default: ${o})`:`(default: ${o})`}async function jt(e){const t=e.session===void 0,n=be(e.session??te());try{return await Pt(e,n)}finally{t&&n.dispose()}}async function Pt(e,t){const{sourceFile:n,namespace:o="",dropFileSegment:r=!1,tsconfig:i}=e,s=t.projectFor(i),a=t.sourceFileFor(n,i),c=D.basename(n),l=O(Ot(c)),u=r?null:l,f=O(o),p=[];for(const[m,b]of a.getExportedDeclarations()){if(m==="default"||V(m))continue;const y=kt(b);if(y){const S=y.getSignature(),x=fe(S,y),w=S.getReturnType().getText();p.push(await q(s,a,f,u,m,x,w,y.isAsync(),i,t));continue}const h=b.find(S=>S.getKindName()==="VariableDeclaration");if(!h)continue;const g=h.getInitializer(),v=g==null?void 0:g.getKindName();if(g&&["ArrowFunction","FunctionExpression"].includes(v??"")){const x=h.getType().getCallSignatures();if(x.length===0)continue;const w=x[0],P=pe(w,h,h.getVariableStatement()),j=w.getReturnType().getText(),A=g.isAsync();p.push(await q(s,a,f,u,m,P,j,A,i,t))}else if(v==="ObjectLiteralExpression"){const S=h.getType();for(const x of S.getProperties()){const w=x.getName();if(V(w))continue;const j=x.getTypeAtLocation(h).getCallSignatures();if(j.length===0)continue;const A=j[0],U=pe(A,h,h.getVariableStatement()),L=A.getReturnType().getText(),M=[...u?[u]:[],O(m),O(w)];p.push(await K(s,a,f,M,w,U,L,!1,i,t))}}else{const S=h.getType(),x=S.getText();if(C(S,h)){const w=await $(s,a,x,i,t);p.push(At(f,u,m,w))}else console.warn(`[apigen-core] Skipping non-callable, non-serializable export: ${m}`)}}const T=a.getDefaultExportSymbol();if(T){const m=a.getExportAssignment(b=>!b.isExportEquals());if(m){const b=m.getExpression(),y=b.getKindName();if(["ArrowFunction","FunctionExpression"].includes(y)){const g=b.getType().getCallSignatures();if(g.length>0){const v=g[0],S=G(v,m),x=v.getReturnType().getText(),w=b.isAsync();p.push(await q(s,a,f,u,"default",S,x,w,i,t))}}else{const h=b.getType();for(const g of h.getProperties()){const v=g.getName();if(V(v))continue;const x=g.getTypeAtLocation(m).getCallSignatures();if(x.length===0)continue;const w=x[0],P=G(w,m),j=w.getReturnType().getText(),A=[...u?[u]:[],O("default"),O(v)];p.push(await K(s,a,f,A,v,P,j,!1,i,t))}}}else{const b=T.getDeclarations();for(const y of b){if(y.getKindName()!=="FunctionDeclaration")continue;const h=y,g=h.getName(),v=g&&g.length>0?g:"default",S=h.getSignature(),x=fe(S,h),w=S.getReturnType().getText();p.push(await q(s,a,f,u,v,x,w,h.isAsync(),i,t))}}}const d=Nt(a);if(d.length>0)for(const{name:m,sig:b}of d){if(V(m))continue;const y=G(b),h=b.getReturnType().getText(),g=[...u?[u]:[],O(m)];p.push(await K(s,a,f,g,m,y,h,!1,i,t))}return p}function $t(e,t,n,o){const r=new Set,i=s=>{if(Array.isArray(s))return s.map(i);if(!s||typeof s!="object"||r.has(s))return s;r.add(s);try{const a=s,c={};for(const[l,u]of Object.entries(a)){if(l==="definitions"||l==="$defs"){const f=l,p=t[f];for(const[T,d]of Object.entries(u)){const m=i(d),b=p[T];if(b!==void 0&&JSON.stringify(b)!==JSON.stringify(m))throw new Error(`[apigen-core-client] Function "${n}": param "${o}" contributes a "${f}.${T}" definition that conflicts with an identically-named definition already hoisted from another param/output in the same function. Two structurally different types share the same generated definition key, so apigen cannot safely merge them into one function-level schema.`);p[T]=m}continue}c[l]=i(u)}return c}finally{r.delete(s)}};return i(e)}async function q(e,t,n,o,r,i,s,a,c,l){const u=O(r);return K(e,t,n,o?[o,u]:[u],r,i,s,a,c,l)}async function K(e,t,n,o,r,i,s,a,c,l){const u=i.length>0&&i[0].name==="ctx",f=i.filter(g=>g.name!=="ctx"),p=f.filter(g=>!g.optional).map(g=>g.name),T={},d={definitions:{},$defs:{}};for(const g of f){const v=await $(e,t,g.type,c,l),S=$t(v,d,r,g.name);g.defaultValue!==void 0&&wt(S,g.defaultValue),T[g.name]=S}const m=s.replace(/^Promise<(.+)>$/,"$1").trim(),b=await $(e,t,m,c,l),y={type:"object",properties:T,required:p,...Object.keys(d.definitions).length>0?{definitions:d.definitions}:{},...Object.keys(d.$defs).length>0?{$defs:d.$defs}:{}};return{id:$e(n,o),host:"ts",namespace:n,path:o,kind:"action",async:a,streaming:!1,safe:!1,input:y,output:b,envelope:{},typeText:{lang:"ts",input:Ct(i),output:m},...u?{hasCtx:!0}:{}}}function At(e,t,n,o){const r=O(n),i=t?[t,r]:[r];return{id:$e(e,i),host:"ts",namespace:e,path:i,kind:"query",async:!1,streaming:!1,safe:!0,input:{type:"object",properties:{},required:[]},output:o,envelope:{},typeText:null}}function $e(e,t){return(e.raw?[e,...t]:t).map(o=>o.words.join("-")).join("/")}function re(e){return e.split(/[-_.]+/).flatMap(t=>t.replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2").replace(/([a-z\d])([A-Z])/g,"$1_$2").split("_").filter(Boolean)).map(t=>t.toLowerCase()).filter(Boolean)}function O(e){return{raw:e,words:re(e)}}function Ot(e){return e.replace(/\.[^.]+$/,"").replace(/[._]+/g,"-")}function Nt(e){const t=[];for(const n of e.getStatements()){if(n.getKindName()!=="ExpressionStatement")continue;const o=n.getExpression();if(o.getKindName()!=="BinaryExpression")continue;const r=o;if(r.getLeft().getText().trim()!=="module.exports"||r.getOperatorToken().getKindName()!=="EqualsToken")continue;const s=r.getRight(),a=s.getType();for(const c of a.getProperties()){const u=c.getTypeAtLocation(s).getCallSignatures();u.length!==0&&t.push({name:c.getName(),sig:u[0]})}}return t}function kt(e){let t;for(const n of e){if(n.getKindName()!=="FunctionDeclaration")continue;const o=n;if(t||(t=o),o.getBody())return o}return t}function fe(e,t){return e.getParameters().map(n=>{var s;const o=n.getDeclarations(),r=o.length>0&&o[0].getKindName()==="Parameter"?o[0]:null,i=n.isOptional()||((r==null?void 0:r.hasInitializer())??!1)||(((s=r==null?void 0:r.hasQuestionToken)==null?void 0:s.call(r))??!1);return{name:n.getName(),type:n.getTypeAtLocation(e.getDeclaration()).getText(),optional:i,defaultValue:ne(r,n.getName(),t)}})}function pe(e,t,n){return e.getParameters().map(o=>{var a;const r=o.getDeclarations(),i=r.length>0&&r[0].getKindName()==="Parameter"?r[0]:null,s=o.isOptional()||((i==null?void 0:i.hasInitializer())??!1)||(((a=i==null?void 0:i.hasQuestionToken)==null?void 0:a.call(i))??!1);return{name:o.getName(),type:o.getTypeAtLocation(t).getText(),optional:s,defaultValue:ne(i,o.getName(),n??t)}})}function G(e,t){return e.getParameters().map(n=>{var s,a,c;const o=n.getDeclarations(),r=o.length>0&&o[0].getKindName()==="Parameter"?o[0]:null,i=n.isOptional()||((r==null?void 0:r.hasInitializer())??!1)||(((s=r==null?void 0:r.hasQuestionToken)==null?void 0:s.call(r))??!1);return{name:n.getName(),type:r?r.getType().getText():((c=(a=n.getValueDeclaration())==null?void 0:a.getType())==null?void 0:c.getText())??"unknown",optional:i,defaultValue:ne(r,n.getName(),t)}})}function Ct(e){const t=e.filter(n=>n.name!=="ctx");return t.length===0?"()":"("+t.map(n=>`${n.name}${n.optional?"?":""}: ${n.type}`).join(", ")+")"}function V(e){return!!(e==="__samples__"||e.startsWith("__"))}function C(e,t,n=new Set){if(e.getCallSignatures().length>0||e.getConstructSignatures().length>0)return!1;if(e.isString()||e.isNumber()||e.isBoolean()||e.isNull()||e.isUndefined()||e.isStringLiteral()||e.isNumberLiteral()||e.isBooleanLiteral()||e.isEnumLiteral())return!0;if(e.isArray()||e.isReadonlyArray()){const o=e.getArrayElementType();return o?C(o,t,n):!1}if(e.isTuple())return e.getTupleElements().every(o=>C(o,t,n));if(e.isUnion())return e.getUnionTypes().every(o=>C(o,t,n));if(e.isIntersection())return e.getIntersectionTypes().every(o=>C(o,t,n));if(e.isObject()){const o=e.getText(t);if(n.has(o))return!0;n.add(o);const r=e.getStringIndexType(),i=e.getNumberIndexType();if(r||i)return[r,i].every(a=>!a||C(a,t,n));const s=e.getProperties();return s.length===0?!0:s.every(a=>{const c=a.getTypeAtLocation(t);return C(c,t,n)})}return!1}async function Et(e){const t=e.session===void 0,n=be(e.session??te());try{return await It(e,n)}finally{t&&n.dispose()}}async function It(e,t){const{sourceFile:n,namespace:o="",tsconfig:r,includeInstances:i=!1}=e,s=t.projectFor(r),a=t.sourceFileFor(n,r),c=D.basename(n),l=R(Rt(c)),u=R(o),f=[];for(const[p,T]of a.getExportedDeclarations()){const d=T.find(y=>y.getKindName()==="ClassDeclaration");if(!d)continue;const m=p==="default"?d.getName():p;if(!m||H(m))continue;const b=R(m);for(const y of d.getStaticMethods()){const h=y.getName();if(H(h))continue;const g=y.getScope();if(g===I.Scope.Private||g===I.Scope.Protected)continue;const v=y.getSignature(),S=Z(v,y),x=v.getReturnType().getText(),w=y.isAsync(),P=[l,b,R(h)];f.push(await Ft(s,a,u,P,S,x,w,r,t))}if(i){{const h=d.getConstructors()[0]??null;let g=[];if(h){const j=h.getSignature();g=Z(j,h)}const v=[l,b],S=ee(u,v),x=g.filter(j=>j.name!=="ctx"),w=x.filter(j=>!j.optional).map(j=>j.name),P={};for(const j of x)P[j.name]=await $(s,a,j.type,r,t);f.push({id:S,host:"ts",namespace:u,path:v,kind:"constructor",async:!1,streaming:!1,safe:!1,input:{type:"object",properties:P,required:w},output:{type:"object",properties:{instanceId:{type:"string"}},required:["instanceId"]},envelope:{},typeText:{lang:"ts",input:_t(g),output:"{ instanceId: string }"}})}for(const y of d.getInstanceMethods()){const h=y.getName();if(H(h))continue;const g=y.getScope();if(g===I.Scope.Private||g===I.Scope.Protected)continue;const v=y.getSignature(),S=Z(v,y),x=v.getReturnType().getText(),w=y.isAsync(),P=[l,b,R(h)],j=ee(u,P),A=S.filter(N=>N.name!=="ctx"),U=A.filter(N=>!N.optional).map(N=>N.name),L={};for(const N of A)L[N.name]=await $(s,a,N.type,r,t);const M=x.replace(/^Promise<(.+)>$/,"$1").trim(),Fe=await $(s,a,M,r,t);f.push({id:j,host:"ts",namespace:u,path:P,kind:"instance-method",async:w,streaming:!1,safe:!1,input:{type:"object",properties:L,required:U},output:Fe,envelope:{type:"object",properties:{instanceId:{type:"string"}},required:["instanceId"]},typeText:{lang:"ts",input:Ae(S),output:M}})}}}return f}async function Ft(e,t,n,o,r,i,s,a,c){const l=r.filter(m=>m.name!=="ctx"),u=l.filter(m=>!m.optional).map(m=>m.name),f={};for(const m of l)f[m.name]=await $(e,t,m.type,a,c);const p=i.replace(/^Promise<(.+)>$/,"$1").trim(),T=await $(e,t,p,a,c);return{id:ee(n,o),host:"ts",namespace:n,path:o,kind:"action",async:s,streaming:!1,safe:!1,input:{type:"object",properties:f,required:u},output:T,envelope:{},typeText:{lang:"ts",input:Ae(r),output:p}}}function ee(e,t){return(e.raw?[e,...t]:t).map(o=>o.words.join("-")).join("/")}function R(e){return{raw:e,words:re(e)}}function Rt(e){return e.replace(/\.[^.]+$/,"").replace(/[._]+/g,"-")}function Z(e,t){return e.getParameters().map(n=>{var s;const o=n.getDeclarations(),r=o.length>0&&o[0].getKindName()==="Parameter"?o[0]:null,i=n.isOptional()||((r==null?void 0:r.hasInitializer())??!1)||(((s=r==null?void 0:r.hasQuestionToken)==null?void 0:s.call(r))??!1);return{name:n.getName(),type:n.getTypeAtLocation(t).getText(),optional:i}})}function Ae(e){const t=e.filter(n=>n.name!=="ctx");return t.length===0?"()":"("+t.map(n=>`${n.name}${n.optional?"?":""}: ${n.type}`).join(", ")+")"}function _t(e){return e.length===0?"()":"("+e.map(t=>`${t.name}${t.optional?"?":""}: ${t.type}`).join(", ")+")"}function H(e){return!!(e==="__samples__"||e.startsWith("__")||e.startsWith("_"))}const Lt=new Map([[".ts","ts"],[".tsx","ts"],[".mts","ts"],[".cts","ts"],[".py","py"],[".rs","rust"],[".go","go"],[".java","java"]]);function Oe(e){const t=De.extname(e).toLowerCase();return Lt.get(t)}function Ne(e){return e.language??"ts"}function ke(e,t){const n=Oe(t);return n===void 0?!1:n===Ne(e)}function Mt(e,t){return t.filter(n=>ke(e,n))}function qt(e){return{oneOf:[{type:"object",required:["index","status","value"],properties:{index:{type:"integer"},status:{type:"string",enum:["fulfilled"]},value:e}},{type:"object",required:["index","status","chunks"],properties:{index:{type:"integer"},status:{type:"string",enum:["fulfilled"]},chunks:{type:"array"}}},{type:"object",required:["index","status","reason"],properties:{index:{type:"integer"},status:{type:"string",enum:["rejected"]},reason:{},chunksDelivered:{type:"integer"}}}]}}function Ce(e){return{operationConst:e.id,itemsSchema:e.input,resultSchema:qt(e.output)}}function Ee(e,t={}){const n=new Set(t.exclude??[]),o=new Map;for(const r of e){if(n.has(r.id))continue;const i=o.get(r.kind);i?i.push(r):o.set(r.kind,[r])}return o}function me(e){return{type:"string",enum:[e]}}function ge(e,t){return{type:"object",required:["operation","items"],properties:{operation:t,items:{type:"array",items:e.itemsSchema},concurrency:{type:"number"},mode:{type:"string",enum:["parallel","serial","chained"]},onItemError:{type:"string",enum:["continue","abort"]},itemTimeoutMs:{type:"number"}},additionalProperties:!0}}function Ie(e){if(e.length===0)throw new Error("buildBatchKindSchema: at least one operation is required");const t=e.map(Ce);if(e.length===1){const[r]=e,[i]=t;return{input:ge(i,me(r.id)),output:{type:"array",items:i.resultSchema}}}const n=e.map((r,i)=>ge(t[i],me(r.id))),o=W(n);return{input:{oneOf:n,...o?{discriminator:o}:{}},output:{oneOf:t.map(r=>({type:"array",items:r.resultSchema}))},...o?{discriminator:o}:{}}}function Vt(e,t={}){const n=Ee(e.operations,t),o=[];for(const[r,i]of n){const{input:s,output:a}=Ie(i),c=de(`_batch/${r}`,e,{kind:r,safe:r==="query",input:s,output:a});o.push({...c,operationIds:i.map(l=>l.id)})}return o}exports.buildBatchKindSchema=Ie;exports.buildBatchMountedOperations=Vt;exports.clearPersistentProjectCache=Ue;exports.composeSchemas=Qe;exports.createExtractionSession=te;exports.deriveBatchOperationBranch=Ce;exports.effectiveLanguage=Ne;exports.extract=jt;exports.extractClasses=Et;exports.groupBatchableOperationsByKind=Ee;exports.isPrimitiveOnlyInputSchema=Se;exports.languageOfSource=Oe;exports.pluginConsumesSource=ke;exports.pluginsToEnvelopeMiddlewares=Ze;exports.sourcesForPlugin=Mt;exports.syntheticOp=de;exports.tokenize=re;
package/index.mjs CHANGED
@@ -239,16 +239,16 @@ function _t(e, t, n) {
239
239
  const o = {};
240
240
  for (const [r, i] of Object.entries(e.schemas)) {
241
241
  const s = (n == null ? void 0 : n[r]) ?? {}, a = i.input.properties ?? {}, c = i.input.required ?? [], l = {}, u = [], f = {};
242
- for (const T of t)
243
- if (T.envelope && s[T.id] !== !1)
244
- for (const [d, y] of Object.entries(T.envelope))
245
- l[d] = y, f[d] = T.id, u.includes(d) || u.push(d);
242
+ for (const b of t)
243
+ if (b.envelope && s[b.id] !== !1)
244
+ for (const [y, h] of Object.entries(b.envelope))
245
+ l[y] = h, f[y] = b.id, u.includes(y) || u.push(y);
246
246
  const p = {
247
247
  type: "object",
248
248
  properties: a,
249
249
  additionalProperties: !1,
250
250
  ...c.length > 0 ? { required: c } : {}
251
- }, b = i.safe === !0 || _e(i.input), h = i.input.definitions, m = i.input.$defs;
251
+ }, T = i.safe === !0 || _e(i.input), d = i.input.definitions, m = i.input.$defs;
252
252
  o[r] = {
253
253
  input: {
254
254
  type: "object",
@@ -265,13 +265,13 @@ function _t(e, t, n) {
265
265
  Object.keys(l),
266
266
  Object.keys(a).length > 0
267
267
  ),
268
- ...h ? { definitions: h } : {},
268
+ ...d ? { definitions: d } : {},
269
269
  ...m ? { $defs: m } : {}
270
270
  },
271
271
  output: i.output,
272
272
  // Carry the ctx-param flag through to dispatch (BUG-APIGEN-001).
273
273
  ...i.hasCtx ? { hasCtx: !0 } : {},
274
- "x-apigen-safe": b,
274
+ "x-apigen-safe": T,
275
275
  // DEBT-APIGEN-ENVELOPE-CAPABILITY-UNWIRED-001: field โ†’ pluginId map,
276
276
  // read by `op-plan.ts`'s `computeEnvelopeFields`. Omitted (not an empty
277
277
  // object) when no middleware contributed an envelope field, matching
@@ -363,22 +363,28 @@ async function be(e, t, n) {
363
363
  const o = e.getStringIndexType(), r = e.getNumberIndexType(), i = o ?? r, s = e.getProperties();
364
364
  if (i && s.length === 0)
365
365
  return { type: "object", additionalProperties: await t(i.getText()) };
366
- const a = {};
367
- for (const c of s) {
368
- const l = c.getName(), f = c.getDeclarations()[0];
369
- let p;
370
- if (f)
366
+ const a = {}, c = [];
367
+ for (const l of s) {
368
+ const u = l.getName(), p = l.getDeclarations()[0];
369
+ let T;
370
+ if (p)
371
371
  try {
372
- p = c.getTypeAtLocation(f);
372
+ T = l.getTypeAtLocation(p);
373
373
  } catch {
374
- p = void 0;
374
+ T = void 0;
375
375
  }
376
- if (p !== void 0 && p.getCallSignatures().length > 0)
376
+ if (T !== void 0 && T.getCallSignatures().length > 0)
377
377
  continue;
378
- const b = p !== void 0 ? qe(p, f) : void 0;
379
- a[l] = b !== void 0 ? await t(b) : {};
378
+ const d = T !== void 0 ? qe(T, p) : void 0;
379
+ a[u] = d !== void 0 ? await t(d) : {}, l.isOptional() || c.push(u);
380
380
  }
381
- return Object.keys(a).length > 0 ? { type: "object", properties: a } : {};
381
+ return Object.keys(a).length > 0 ? {
382
+ type: "object",
383
+ properties: a,
384
+ // Match ts-json-schema-generator's own convention: omit `required`
385
+ // entirely when no property is required, rather than emitting `[]`.
386
+ ...c.length > 0 ? { required: c } : {}
387
+ } : {};
382
388
  }
383
389
  return {};
384
390
  }
@@ -744,19 +750,19 @@ function ot(e, t, n) {
744
750
  const { createProgram: u } = require("ts-json-schema-generator/dist/factory/program.js"), f = Ze(), p = Ge(
745
751
  f.SyntaxKind.BigIntKeyword,
746
752
  f.SyntaxKind.TypeReference
747
- ), b = u(r), h = ke(
748
- b,
753
+ ), T = u(r), d = ke(
754
+ T,
749
755
  r,
750
756
  p
751
757
  ), m = Ee(r);
752
758
  if (c = new Ce(
753
- b,
754
- h,
759
+ T,
760
+ d,
755
761
  m,
756
762
  r
757
763
  ), n && n.stats.generatorsBuilt++, s !== void 0 && a !== void 0) {
758
- const T = { version: a, gen: c };
759
- Je(s, T), n == null || n.generatorCache.set(s, T);
764
+ const b = { version: a, gen: c };
765
+ Je(s, b), n == null || n.generatorCache.set(s, b);
760
766
  }
761
767
  }
762
768
  const l = c.createSchema(r.type);
@@ -810,14 +816,14 @@ async function A(e, t, n, o, r, i) {
810
816
  if (c.has(a))
811
817
  return {};
812
818
  if (!r) {
813
- const h = new Set(c);
814
- return h.add(a), ue(
819
+ const d = new Set(c);
820
+ return d.add(a), ue(
815
821
  e,
816
822
  t,
817
823
  n,
818
824
  o,
819
825
  void 0,
820
- h
826
+ d
821
827
  );
822
828
  }
823
829
  const l = r.schemaCache.get(a);
@@ -833,17 +839,17 @@ async function A(e, t, n, o, r, i) {
833
839
  r.stats.schemaCacheMisses++;
834
840
  const p = new Set(c);
835
841
  p.add(a);
836
- const b = ue(
842
+ const T = ue(
837
843
  e,
838
844
  t,
839
845
  n,
840
846
  o,
841
847
  r,
842
848
  p
843
- ).then((h) => (u.set(n, h), h)).catch((h) => {
844
- throw r.schemaCache.delete(a), h;
849
+ ).then((d) => (u.set(n, d), d)).catch((d) => {
850
+ throw r.schemaCache.delete(a), d;
845
851
  });
846
- return r.schemaCache.set(a, b), b;
852
+ return r.schemaCache.set(a, T), T;
847
853
  }
848
854
  async function ue(e, t, n, o, r, i) {
849
855
  if (["void", "undefined", "null", "Promise<void>"].includes(n))
@@ -893,8 +899,8 @@ async function ue(e, t, n, o, r, i) {
893
899
  // dereference/hoist pass and is tracked separately, unresolved, in
894
900
  // BUG-APIGEN-026's BACKLOG entry.
895
901
  topRef: !1
896
- }, b = ot(p, !0, r);
897
- return rt(b);
902
+ }, T = ot(p, !0, r);
903
+ return rt(T);
898
904
  } catch {
899
905
  }
900
906
  try {
@@ -902,9 +908,9 @@ async function ue(e, t, n, o, r, i) {
902
908
  e,
903
909
  t,
904
910
  a,
905
- (b) => be(
906
- b,
907
- (h) => A(e, t, h, o, r, i),
911
+ (T) => be(
912
+ T,
913
+ (d) => A(e, t, d, o, r, i),
908
914
  0
909
915
  )
910
916
  );
@@ -978,12 +984,12 @@ async function ft(e, t) {
978
984
  dropFileSegment: r = !1,
979
985
  tsconfig: i
980
986
  } = e, s = t.projectFor(i), a = t.sourceFileFor(n, i), c = Y.basename(n), l = N(gt(c)), u = r ? null : l, f = N(o), p = [];
981
- for (const [m, T] of a.getExportedDeclarations()) {
987
+ for (const [m, b] of a.getExportedDeclarations()) {
982
988
  if (m === "default" || V(m))
983
989
  continue;
984
- const d = yt(T);
985
- if (d) {
986
- const S = d.getSignature(), v = le(S, d), w = S.getReturnType().getText();
990
+ const y = yt(b);
991
+ if (y) {
992
+ const S = y.getSignature(), v = le(S, y), w = S.getReturnType().getText();
987
993
  p.push(
988
994
  await M(
989
995
  s,
@@ -993,27 +999,27 @@ async function ft(e, t) {
993
999
  m,
994
1000
  v,
995
1001
  w,
996
- d.isAsync(),
1002
+ y.isAsync(),
997
1003
  i,
998
1004
  t
999
1005
  )
1000
1006
  );
1001
1007
  continue;
1002
1008
  }
1003
- const y = T.find(
1009
+ const h = b.find(
1004
1010
  (S) => S.getKindName() === "VariableDeclaration"
1005
1011
  );
1006
- if (!y)
1012
+ if (!h)
1007
1013
  continue;
1008
- const g = y.getInitializer(), x = g == null ? void 0 : g.getKindName();
1014
+ const g = h.getInitializer(), x = g == null ? void 0 : g.getKindName();
1009
1015
  if (g && ["ArrowFunction", "FunctionExpression"].includes(x ?? "")) {
1010
- const v = y.getType().getCallSignatures();
1016
+ const v = h.getType().getCallSignatures();
1011
1017
  if (v.length === 0)
1012
1018
  continue;
1013
1019
  const w = v[0], $ = fe(
1014
1020
  w,
1015
- y,
1016
- y.getVariableStatement()
1021
+ h,
1022
+ h.getVariableStatement()
1017
1023
  ), j = w.getReturnType().getText(), P = g.isAsync();
1018
1024
  p.push(
1019
1025
  await M(
@@ -1030,18 +1036,18 @@ async function ft(e, t) {
1030
1036
  )
1031
1037
  );
1032
1038
  } else if (x === "ObjectLiteralExpression") {
1033
- const S = y.getType();
1039
+ const S = h.getType();
1034
1040
  for (const v of S.getProperties()) {
1035
1041
  const w = v.getName();
1036
1042
  if (V(w))
1037
1043
  continue;
1038
- const j = v.getTypeAtLocation(y).getCallSignatures();
1044
+ const j = v.getTypeAtLocation(h).getCallSignatures();
1039
1045
  if (j.length === 0)
1040
1046
  continue;
1041
1047
  const P = j[0], B = fe(
1042
1048
  P,
1043
- y,
1044
- y.getVariableStatement()
1049
+ h,
1050
+ h.getVariableStatement()
1045
1051
  ), R = P.getReturnType().getText(), _ = [
1046
1052
  ...u ? [u] : [],
1047
1053
  N(m),
@@ -1063,8 +1069,8 @@ async function ft(e, t) {
1063
1069
  );
1064
1070
  }
1065
1071
  } else {
1066
- const S = y.getType(), v = S.getText();
1067
- if (E(S, y)) {
1072
+ const S = h.getType(), v = S.getText();
1073
+ if (E(S, h)) {
1068
1074
  const w = await A(
1069
1075
  s,
1070
1076
  a,
@@ -1081,15 +1087,15 @@ async function ft(e, t) {
1081
1087
  );
1082
1088
  }
1083
1089
  }
1084
- const b = a.getDefaultExportSymbol();
1085
- if (b) {
1086
- const m = a.getExportAssignment((T) => !T.isExportEquals());
1090
+ const T = a.getDefaultExportSymbol();
1091
+ if (T) {
1092
+ const m = a.getExportAssignment((b) => !b.isExportEquals());
1087
1093
  if (m) {
1088
- const T = m.getExpression(), d = T.getKindName();
1089
- if (["ArrowFunction", "FunctionExpression"].includes(d)) {
1090
- const g = T.getType().getCallSignatures();
1094
+ const b = m.getExpression(), y = b.getKindName();
1095
+ if (["ArrowFunction", "FunctionExpression"].includes(y)) {
1096
+ const g = b.getType().getCallSignatures();
1091
1097
  if (g.length > 0) {
1092
- const x = g[0], S = W(x, m), v = x.getReturnType().getText(), w = T.isAsync();
1098
+ const x = g[0], S = W(x, m), v = x.getReturnType().getText(), w = b.isAsync();
1093
1099
  p.push(
1094
1100
  await M(
1095
1101
  s,
@@ -1106,8 +1112,8 @@ async function ft(e, t) {
1106
1112
  );
1107
1113
  }
1108
1114
  } else {
1109
- const y = T.getType();
1110
- for (const g of y.getProperties()) {
1115
+ const h = b.getType();
1116
+ for (const g of h.getProperties()) {
1111
1117
  const x = g.getName();
1112
1118
  if (V(x))
1113
1119
  continue;
@@ -1136,11 +1142,11 @@ async function ft(e, t) {
1136
1142
  }
1137
1143
  }
1138
1144
  } else {
1139
- const T = b.getDeclarations();
1140
- for (const d of T) {
1141
- if (d.getKindName() !== "FunctionDeclaration")
1145
+ const b = T.getDeclarations();
1146
+ for (const y of b) {
1147
+ if (y.getKindName() !== "FunctionDeclaration")
1142
1148
  continue;
1143
- const y = d, g = y.getName(), x = g && g.length > 0 ? g : "default", S = y.getSignature(), v = le(S, y), w = S.getReturnType().getText();
1149
+ const h = y, g = h.getName(), x = g && g.length > 0 ? g : "default", S = h.getSignature(), v = le(S, h), w = S.getReturnType().getText();
1144
1150
  p.push(
1145
1151
  await M(
1146
1152
  s,
@@ -1150,7 +1156,7 @@ async function ft(e, t) {
1150
1156
  x,
1151
1157
  v,
1152
1158
  w,
1153
- y.isAsync(),
1159
+ h.isAsync(),
1154
1160
  i,
1155
1161
  t
1156
1162
  )
@@ -1158,12 +1164,12 @@ async function ft(e, t) {
1158
1164
  }
1159
1165
  }
1160
1166
  }
1161
- const h = dt(a);
1162
- if (h.length > 0)
1163
- for (const { name: m, sig: T } of h) {
1167
+ const d = dt(a);
1168
+ if (d.length > 0)
1169
+ for (const { name: m, sig: b } of d) {
1164
1170
  if (V(m))
1165
1171
  continue;
1166
- const d = W(T), y = T.getReturnType().getText(), g = [
1172
+ const y = W(b), h = b.getReturnType().getText(), g = [
1167
1173
  ...u ? [u] : [],
1168
1174
  N(m)
1169
1175
  ];
@@ -1174,8 +1180,8 @@ async function ft(e, t) {
1174
1180
  f,
1175
1181
  g,
1176
1182
  m,
1177
- d,
1178
1183
  y,
1184
+ h,
1179
1185
  !1,
1180
1186
  i,
1181
1187
  t
@@ -1196,15 +1202,15 @@ function pt(e, t, n, o) {
1196
1202
  for (const [l, u] of Object.entries(a)) {
1197
1203
  if (l === "definitions" || l === "$defs") {
1198
1204
  const f = l, p = t[f];
1199
- for (const [b, h] of Object.entries(
1205
+ for (const [T, d] of Object.entries(
1200
1206
  u
1201
1207
  )) {
1202
- const m = i(h), T = p[b];
1203
- if (T !== void 0 && JSON.stringify(T) !== JSON.stringify(m))
1208
+ const m = i(d), b = p[T];
1209
+ if (b !== void 0 && JSON.stringify(b) !== JSON.stringify(m))
1204
1210
  throw new Error(
1205
- `[apigen-core-client] Function "${n}": param "${o}" contributes a "${f}.${b}" definition that conflicts with an identically-named definition already hoisted from another param/output in the same function. Two structurally different types share the same generated definition key, so apigen cannot safely merge them into one function-level schema.`
1211
+ `[apigen-core-client] Function "${n}": param "${o}" contributes a "${f}.${T}" definition that conflicts with an identically-named definition already hoisted from another param/output in the same function. Two structurally different types share the same generated definition key, so apigen cannot safely merge them into one function-level schema.`
1206
1212
  );
1207
- p[b] = m;
1213
+ p[T] = m;
1208
1214
  }
1209
1215
  continue;
1210
1216
  }
@@ -1233,29 +1239,29 @@ async function M(e, t, n, o, r, i, s, a, c, l) {
1233
1239
  );
1234
1240
  }
1235
1241
  async function z(e, t, n, o, r, i, s, a, c, l) {
1236
- const u = i.length > 0 && i[0].name === "ctx", f = i.filter((g) => g.name !== "ctx"), p = f.filter((g) => !g.optional).map((g) => g.name), b = {}, h = {
1242
+ const u = i.length > 0 && i[0].name === "ctx", f = i.filter((g) => g.name !== "ctx"), p = f.filter((g) => !g.optional).map((g) => g.name), T = {}, d = {
1237
1243
  definitions: {},
1238
1244
  $defs: {}
1239
1245
  };
1240
1246
  for (const g of f) {
1241
- const x = await A(e, t, g.type, c, l), S = pt(x, h, r, g.name);
1242
- g.defaultValue !== void 0 && lt(S, g.defaultValue), b[g.name] = S;
1247
+ const x = await A(e, t, g.type, c, l), S = pt(x, d, r, g.name);
1248
+ g.defaultValue !== void 0 && lt(S, g.defaultValue), T[g.name] = S;
1243
1249
  }
1244
- const m = s.replace(/^Promise<(.+)>$/, "$1").trim(), T = await A(
1250
+ const m = s.replace(/^Promise<(.+)>$/, "$1").trim(), b = await A(
1245
1251
  e,
1246
1252
  t,
1247
1253
  m,
1248
1254
  c,
1249
1255
  l
1250
- ), d = {
1256
+ ), y = {
1251
1257
  type: "object",
1252
- properties: b,
1258
+ properties: T,
1253
1259
  required: p,
1254
1260
  // BUG-APIGEN-029: hoisted definitions from param fragments โ€” see
1255
1261
  // hoistNestedDefs. Only attached when non-empty so the common
1256
1262
  // (no-recursive-type) case's schema shape is unchanged.
1257
- ...Object.keys(h.definitions).length > 0 ? { definitions: h.definitions } : {},
1258
- ...Object.keys(h.$defs).length > 0 ? { $defs: h.$defs } : {}
1263
+ ...Object.keys(d.definitions).length > 0 ? { definitions: d.definitions } : {},
1264
+ ...Object.keys(d.$defs).length > 0 ? { $defs: d.$defs } : {}
1259
1265
  };
1260
1266
  return {
1261
1267
  id: je(n, o),
@@ -1267,8 +1273,8 @@ async function z(e, t, n, o, r, i, s, a, c, l) {
1267
1273
  streaming: !1,
1268
1274
  safe: !1,
1269
1275
  // action โ†’ false per ยง4
1270
- input: d,
1271
- output: T,
1276
+ input: y,
1277
+ output: b,
1272
1278
  envelope: {},
1273
1279
  typeText: {
1274
1280
  lang: "ts",
@@ -1438,24 +1444,24 @@ async function Tt(e, t) {
1438
1444
  tsconfig: r,
1439
1445
  includeInstances: i = !1
1440
1446
  } = e, s = t.projectFor(r), a = t.sourceFileFor(n, r), c = Y.basename(n), l = I(St(c)), u = I(o), f = [];
1441
- for (const [p, b] of a.getExportedDeclarations()) {
1442
- const h = b.find(
1443
- (d) => d.getKindName() === "ClassDeclaration"
1447
+ for (const [p, T] of a.getExportedDeclarations()) {
1448
+ const d = T.find(
1449
+ (y) => y.getKindName() === "ClassDeclaration"
1444
1450
  );
1445
- if (!h)
1451
+ if (!d)
1446
1452
  continue;
1447
- const m = p === "default" ? h.getName() : p;
1453
+ const m = p === "default" ? d.getName() : p;
1448
1454
  if (!m || G(m))
1449
1455
  continue;
1450
- const T = I(m);
1451
- for (const d of h.getStaticMethods()) {
1452
- const y = d.getName();
1453
- if (G(y))
1456
+ const b = I(m);
1457
+ for (const y of d.getStaticMethods()) {
1458
+ const h = y.getName();
1459
+ if (G(h))
1454
1460
  continue;
1455
- const g = d.getScope();
1461
+ const g = y.getScope();
1456
1462
  if (g === L.Private || g === L.Protected)
1457
1463
  continue;
1458
- const x = d.getSignature(), S = U(x, d), v = x.getReturnType().getText(), w = d.isAsync(), $ = [l, T, I(y)];
1464
+ const x = y.getSignature(), S = U(x, y), v = x.getReturnType().getText(), w = y.isAsync(), $ = [l, b, I(h)];
1459
1465
  f.push(
1460
1466
  await bt(
1461
1467
  s,
@@ -1472,13 +1478,13 @@ async function Tt(e, t) {
1472
1478
  }
1473
1479
  if (i) {
1474
1480
  {
1475
- const y = h.getConstructors()[0] ?? null;
1481
+ const h = d.getConstructors()[0] ?? null;
1476
1482
  let g = [];
1477
- if (y) {
1478
- const j = y.getSignature();
1479
- g = U(j, y);
1483
+ if (h) {
1484
+ const j = h.getSignature();
1485
+ g = U(j, h);
1480
1486
  }
1481
- const x = [l, T], S = X(u, x), v = g.filter((j) => j.name !== "ctx"), w = v.filter((j) => !j.optional).map((j) => j.name), $ = {};
1487
+ const x = [l, b], S = X(u, x), v = g.filter((j) => j.name !== "ctx"), w = v.filter((j) => !j.optional).map((j) => j.name), $ = {};
1482
1488
  for (const j of v)
1483
1489
  $[j.name] = await A(
1484
1490
  s,
@@ -1510,14 +1516,14 @@ async function Tt(e, t) {
1510
1516
  }
1511
1517
  });
1512
1518
  }
1513
- for (const d of h.getInstanceMethods()) {
1514
- const y = d.getName();
1515
- if (G(y))
1519
+ for (const y of d.getInstanceMethods()) {
1520
+ const h = y.getName();
1521
+ if (G(h))
1516
1522
  continue;
1517
- const g = d.getScope();
1523
+ const g = y.getScope();
1518
1524
  if (g === L.Private || g === L.Protected)
1519
1525
  continue;
1520
- const x = d.getSignature(), S = U(x, d), v = x.getReturnType().getText(), w = d.isAsync(), $ = [l, T, I(y)], j = X(u, $), P = S.filter((O) => O.name !== "ctx"), B = P.filter((O) => !O.optional).map((O) => O.name), R = {};
1526
+ const x = y.getSignature(), S = U(x, y), v = x.getReturnType().getText(), w = y.isAsync(), $ = [l, b, I(h)], j = X(u, $), P = S.filter((O) => O.name !== "ctx"), B = P.filter((O) => !O.optional).map((O) => O.name), R = {};
1521
1527
  for (const O of P)
1522
1528
  R[O.name] = await A(
1523
1529
  s,
@@ -1570,7 +1576,7 @@ async function bt(e, t, n, o, r, i, s, a, c) {
1570
1576
  a,
1571
1577
  c
1572
1578
  );
1573
- const p = i.replace(/^Promise<(.+)>$/, "$1").trim(), b = await A(
1579
+ const p = i.replace(/^Promise<(.+)>$/, "$1").trim(), T = await A(
1574
1580
  e,
1575
1581
  t,
1576
1582
  p,
@@ -1588,7 +1594,7 @@ async function bt(e, t, n, o, r, i, s, a, c) {
1588
1594
  safe: !1,
1589
1595
  // action โ†’ false per ยง4
1590
1596
  input: { type: "object", properties: f, required: u },
1591
- output: b,
1597
+ output: T,
1592
1598
  envelope: {},
1593
1599
  typeText: {
1594
1600
  lang: "ts",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adhd/apigen-core-client",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "dependencies": {
5
5
  "ts-morph": "^23.0.0",
6
6
  "ts-json-schema-generator": "^2.3.0",