@adhd/apigen-core-client 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.mjs ADDED
@@ -0,0 +1,1618 @@
1
+ import { Project as te, Scope as R } from "ts-morph";
2
+ import $e from "node:fs";
3
+ import * as Ae from "node:path";
4
+ import Q from "node:path";
5
+ import { createParser as Pe, createFormatter as Ne, SchemaGenerator as Oe, AnnotatedType as ne, StringType as re } from "ts-json-schema-generator";
6
+ const le = Symbol.for("adhd.apigen.extraction-session");
7
+ function pe(e, t) {
8
+ const r = [
9
+ ...e.getImportDeclarations().map((o) => o.getModuleSpecifierSourceFile()),
10
+ ...e.getExportDeclarations().map((o) => o.getModuleSpecifierSourceFile())
11
+ ];
12
+ for (const o of r) {
13
+ if (!o)
14
+ continue;
15
+ const n = o.getFilePath();
16
+ if (!n.includes("/node_modules/") && !t.has(n)) {
17
+ t.add(n);
18
+ try {
19
+ o.refreshFromFileSystemSync();
20
+ } catch {
21
+ }
22
+ pe(o, t);
23
+ }
24
+ }
25
+ }
26
+ function me(e) {
27
+ try {
28
+ const t = $e.statSync(e);
29
+ return `${t.mtimeMs}:${t.size}`;
30
+ } catch {
31
+ return "nostat";
32
+ }
33
+ }
34
+ const I = /* @__PURE__ */ new Map(), B = /* @__PURE__ */ new Map();
35
+ function Ee(e, t, r) {
36
+ const o = t ?? "", n = I.get(o);
37
+ let i = r;
38
+ if (n && n.fileVersions.size > 0) {
39
+ const c = [r], u = [...n.fileVersions.entries()].sort(
40
+ ([f], [l]) => f.localeCompare(l)
41
+ );
42
+ for (const [f, l] of u)
43
+ f !== e && c.push(`${f}:${l}`);
44
+ i = c.join("|");
45
+ }
46
+ const s = `${e}\0${t ?? ""}`;
47
+ let a = B.get(s);
48
+ return (!a || a.version !== i) && (a = { version: i, schemas: /* @__PURE__ */ new Map() }, B.set(s, a)), a.schemas;
49
+ }
50
+ function At() {
51
+ I.clear(), B.clear();
52
+ }
53
+ function ge() {
54
+ const e = {
55
+ projectsBuilt: 0,
56
+ generatorsBuilt: 0,
57
+ schemaCacheHits: 0,
58
+ schemaCacheMisses: 0
59
+ }, t = /* @__PURE__ */ new Map();
60
+ let r = !1;
61
+ return {
62
+ [le]: !0,
63
+ stats: e,
64
+ schemaCache: /* @__PURE__ */ new Map(),
65
+ aliasCache: /* @__PURE__ */ new WeakMap(),
66
+ zodImportCache: /* @__PURE__ */ new WeakMap(),
67
+ generatorCache: /* @__PURE__ */ new Map(),
68
+ projectFor(n) {
69
+ if (r)
70
+ throw new Error("apigen-core: ExtractionSession used after dispose()");
71
+ const i = n ?? "", s = n ? this.statVersion(n) : "";
72
+ let a = I.get(i);
73
+ return a && a.tsconfigVersion !== s && (a = void 0), a || (a = { project: n ? new te({
74
+ tsConfigFilePath: n,
75
+ skipAddingFilesFromTsConfig: !0
76
+ }) : new te({ skipAddingFilesFromTsConfig: !0 }), tsconfigVersion: s, fileVersions: /* @__PURE__ */ new Map() }, I.set(i, a), e.projectsBuilt++), a.project;
77
+ },
78
+ sourceFileFor(n, i) {
79
+ const s = this.projectFor(i), a = I.get(i ?? ""), c = this.statVersion(n);
80
+ let u = s.getSourceFile(n);
81
+ if (u === void 0 ? u = s.addSourceFileAtPath(n) : a && a.fileVersions.get(n) !== c && u.refreshFromFileSystemSync(), a == null || a.fileVersions.set(n, c), a) {
82
+ const f = /* @__PURE__ */ new Set([n]);
83
+ pe(u, f);
84
+ for (const l of f)
85
+ l !== n && a.fileVersions.set(l, this.statVersion(l));
86
+ }
87
+ return u;
88
+ },
89
+ statVersion(n) {
90
+ let i = t.get(n);
91
+ return i === void 0 && (i = me(n), t.set(n, i)), i;
92
+ },
93
+ dispose() {
94
+ r = !0, this.schemaCache.clear(), this.generatorCache.clear(), t.clear();
95
+ }
96
+ };
97
+ }
98
+ function de(e) {
99
+ const t = e;
100
+ if (t[le] !== !0)
101
+ throw new Error(
102
+ "apigen-core: unknown ExtractionSession implementation — create sessions with createExtractionSession()"
103
+ );
104
+ return t;
105
+ }
106
+ const z = "x-apigen-logical";
107
+ function oe(e, t) {
108
+ const r = /* @__PURE__ */ new Set(), o = [e];
109
+ for (; o.length > 0; ) {
110
+ const n = o.pop();
111
+ if (!n || r.has(n))
112
+ continue;
113
+ r.add(n);
114
+ const i = n.$ref;
115
+ if (typeof i == "string") {
116
+ if (t) {
117
+ const l = t[i];
118
+ if (!l) {
119
+ const g = Object.keys(t).join(", ") || "(none)";
120
+ throw new Error(
121
+ `[apigen-logical] $ref "${i}" cannot be resolved. Available $defs: ${g}`
122
+ );
123
+ }
124
+ o.push(l);
125
+ }
126
+ continue;
127
+ }
128
+ const s = n.oneOf;
129
+ if (Array.isArray(s))
130
+ for (const l of s)
131
+ typeof l == "object" && l !== null && o.push(l);
132
+ const a = n.properties;
133
+ if (a)
134
+ for (const l of Object.values(a))
135
+ o.push(l);
136
+ const c = n.items;
137
+ if (Array.isArray(c))
138
+ for (const l of c)
139
+ typeof l == "object" && l !== null && o.push(l);
140
+ else
141
+ typeof c == "object" && c !== null && o.push(c);
142
+ const u = n.additionalProperties;
143
+ typeof u == "object" && u !== null && o.push(u);
144
+ const f = n.propertyNames;
145
+ typeof f == "object" && f !== null && o.push(f);
146
+ }
147
+ }
148
+ const ie = /* @__PURE__ */ new Set(["string", "number", "boolean", "integer"]);
149
+ function ke(e) {
150
+ if (typeof e != "object" || e === null)
151
+ return !1;
152
+ const t = e;
153
+ if (t.$ref !== void 0 || t.oneOf || t.anyOf || t.allOf)
154
+ return !1;
155
+ const { type: r } = t;
156
+ return typeof r == "string" ? ie.has(r) : Array.isArray(r) ? r.every((o) => ie.has(o) || o === "null") : Array.isArray(t.enum) && t.enum.length > 0 ? t.enum.every((o) => ["string", "number", "boolean"].includes(typeof o)) : !1;
157
+ }
158
+ function Ce(e) {
159
+ if (!e || typeof e != "object")
160
+ return !1;
161
+ const t = e.properties;
162
+ return t === void 0 || typeof t != "object" || t === null ? !1 : Object.values(t).every(
163
+ ke
164
+ );
165
+ }
166
+ function Ie(e) {
167
+ const t = {}, r = (o) => {
168
+ for (const n of ["definitions", "$defs"]) {
169
+ const i = o[n];
170
+ if (i)
171
+ for (const [s, a] of Object.entries(i)) {
172
+ const c = s.startsWith("#/") ? s : `#/${n}/${s}`;
173
+ t[c] = a;
174
+ }
175
+ }
176
+ };
177
+ for (const o of Object.values(e.schemas))
178
+ r(o.input), r(o.output);
179
+ if (Object.keys(t).length !== 0)
180
+ for (const [o, n] of Object.entries(e.schemas))
181
+ try {
182
+ oe(n.input, t), oe(n.output, t);
183
+ } catch (i) {
184
+ throw new Error(
185
+ `[apigen-core-client] Schema validation failed for function "${o}": ${i.message}`
186
+ );
187
+ }
188
+ }
189
+ function Fe(e, t) {
190
+ const r = [
191
+ 'apigen calling convention: all domain parameters go inside a "data" envelope — e.g. { "data": { ... } }' + (t ? "." : " (an empty object for this zero-parameter tool).")
192
+ ];
193
+ return e.length > 0 && r.push(
194
+ `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-naming's envelopeMetaKey/envelopeCliFlag/envelopeEnvVar for the HTTP-header / CLI-flag / env-var equivalents.`
195
+ ), r.join(" ");
196
+ }
197
+ function Pt(e, t, r) {
198
+ Ie(e);
199
+ const o = {};
200
+ for (const [n, i] of Object.entries(e.schemas)) {
201
+ const s = (r == null ? void 0 : r[n]) ?? {}, a = i.input.properties ?? {}, c = i.input.required ?? [], u = {}, f = [];
202
+ for (const y of t)
203
+ if (y.envelope && s[y.id] !== !1)
204
+ for (const [h, T] of Object.entries(y.envelope))
205
+ u[h] = T, f.includes(h) || f.push(h);
206
+ const l = {
207
+ type: "object",
208
+ properties: a,
209
+ additionalProperties: !1,
210
+ ...c.length > 0 ? { required: c } : {}
211
+ }, g = i.safe === !0 || Ce(i.input), m = i.input.definitions, p = i.input.$defs;
212
+ o[n] = {
213
+ input: {
214
+ type: "object",
215
+ properties: { ...u, data: l },
216
+ required: [
217
+ ...f,
218
+ ...c.length > 0 ? ["data"] : []
219
+ ],
220
+ // BUG-APIGEN-017: reject any property that isn't a declared envelope
221
+ // field or the "data" wrapper — no silently-ignored junk params.
222
+ additionalProperties: !1,
223
+ // BUG-APIGEN-020: document the envelope/data calling convention inline.
224
+ description: Fe(
225
+ Object.keys(u),
226
+ Object.keys(a).length > 0
227
+ ),
228
+ ...m ? { definitions: m } : {},
229
+ ...p ? { $defs: p } : {}
230
+ },
231
+ output: i.output,
232
+ // Carry the ctx-param flag through to dispatch (BUG-APIGEN-001).
233
+ ...i.hasCtx ? { hasCtx: !0 } : {},
234
+ "x-apigen-safe": g
235
+ };
236
+ }
237
+ return o;
238
+ }
239
+ const Re = 8;
240
+ function Le(e, t) {
241
+ try {
242
+ return t ? e.getText(t) : e.getText();
243
+ } catch {
244
+ try {
245
+ return e.getText();
246
+ } catch {
247
+ return;
248
+ }
249
+ }
250
+ }
251
+ let _e = 0;
252
+ async function Me(e, t, r, o) {
253
+ const n = `__ApigenProbe_${process.pid}_${_e++}`;
254
+ let i;
255
+ try {
256
+ i = t.addTypeAlias({ name: n, type: r });
257
+ const s = i.getType();
258
+ return await o(s);
259
+ } catch {
260
+ return;
261
+ } finally {
262
+ try {
263
+ i == null || i.remove();
264
+ } catch {
265
+ }
266
+ }
267
+ }
268
+ async function ye(e, t, r) {
269
+ if (r > Re)
270
+ return {};
271
+ if (e.isString() || e.isStringLiteral())
272
+ return e.isStringLiteral() ? { type: "string", enum: [e.getLiteralValue()] } : { type: "string" };
273
+ if (e.isNumber() || e.isNumberLiteral())
274
+ return e.isNumberLiteral() ? { type: "number", enum: [e.getLiteralValue()] } : { type: "number" };
275
+ if (e.isBoolean())
276
+ return { type: "boolean" };
277
+ if (e.isBooleanLiteral())
278
+ return { type: "boolean" };
279
+ if (e.isNull() || e.isUndefined() || e.isVoid())
280
+ return { type: "null" };
281
+ if (e.isUnion()) {
282
+ const o = e.getUnionTypes();
283
+ if (o.every((c) => c.isStringLiteral()) && o.length > 0)
284
+ return {
285
+ type: "string",
286
+ enum: o.map((c) => c.getLiteralValue())
287
+ };
288
+ if (o.every((c) => c.isNumberLiteral()) && o.length > 0)
289
+ return {
290
+ type: "number",
291
+ enum: o.map((c) => c.getLiteralValue())
292
+ };
293
+ const s = await Promise.all(
294
+ o.map((c) => ye(c, t, r + 1))
295
+ ), a = J(s);
296
+ return {
297
+ oneOf: s,
298
+ ...a ? { discriminator: a } : {},
299
+ [z]: "union"
300
+ };
301
+ }
302
+ if (e.isArray()) {
303
+ const o = e.getArrayElementType();
304
+ return { type: "array", items: o ? await t(o.getText()) : {} };
305
+ }
306
+ if (e.isTuple()) {
307
+ const o = e.getTupleElements(), n = await Promise.all(
308
+ o.map((i) => t(i.getText()))
309
+ );
310
+ return {
311
+ type: "array",
312
+ items: n,
313
+ minItems: n.length,
314
+ maxItems: n.length
315
+ };
316
+ }
317
+ if (e.isObject()) {
318
+ const o = e.getStringIndexType(), n = e.getNumberIndexType(), i = o ?? n, s = e.getProperties();
319
+ if (i && s.length === 0)
320
+ return { type: "object", additionalProperties: await t(i.getText()) };
321
+ const a = {};
322
+ for (const c of s) {
323
+ const u = c.getName(), l = c.getDeclarations()[0];
324
+ let g;
325
+ if (l)
326
+ try {
327
+ g = c.getTypeAtLocation(l);
328
+ } catch {
329
+ g = void 0;
330
+ }
331
+ if (g !== void 0 && g.getCallSignatures().length > 0)
332
+ continue;
333
+ const m = g !== void 0 ? Le(g, l) : void 0;
334
+ a[u] = m !== void 0 ? await t(m) : {};
335
+ }
336
+ return Object.keys(a).length > 0 ? { type: "object", properties: a } : {};
337
+ }
338
+ return {};
339
+ }
340
+ function J(e) {
341
+ if (e.length < 2)
342
+ return;
343
+ const t = [];
344
+ for (const o of e) {
345
+ if (o.type !== "object")
346
+ return;
347
+ const n = o.properties;
348
+ if (!n || typeof n != "object")
349
+ return;
350
+ t.push(n);
351
+ }
352
+ const r = Object.keys(t[0]).filter(
353
+ (o) => t.every((n) => Object.prototype.hasOwnProperty.call(n, o))
354
+ );
355
+ for (const o of r) {
356
+ const n = [];
357
+ let i = !0;
358
+ for (const a of t) {
359
+ const c = a[o], u = c && (c.type === "string" || c.type === "number"), f = c == null ? void 0 : c.enum;
360
+ if (!u || !Array.isArray(f) || f.length !== 1) {
361
+ i = !1;
362
+ break;
363
+ }
364
+ n.push(String(f[0]));
365
+ }
366
+ if (!i || new Set(n).size !== n.length)
367
+ continue;
368
+ const s = {};
369
+ return n.forEach((a, c) => {
370
+ s[a] = `#/oneOf/${c}`;
371
+ }), { propertyName: o, mapping: s };
372
+ }
373
+ }
374
+ function M(e, t, r) {
375
+ if (t > 6)
376
+ return {};
377
+ const o = e.trim();
378
+ if (o === "string")
379
+ return { type: "string" };
380
+ if (o === "number")
381
+ return { type: "number" };
382
+ if (o === "boolean")
383
+ return { type: "boolean" };
384
+ if (o === "null")
385
+ return { type: "null" };
386
+ if (o === "undefined")
387
+ return { type: "null" };
388
+ const n = U[o];
389
+ if (n !== void 0)
390
+ return n;
391
+ if (r != null && r.size) {
392
+ const i = r.get(o);
393
+ if (i !== void 0) {
394
+ const s = U[i];
395
+ if (s !== void 0)
396
+ return s;
397
+ }
398
+ }
399
+ if (o.endsWith("[]"))
400
+ return {
401
+ type: "array",
402
+ items: M(o.slice(0, -2), t + 1, r)
403
+ };
404
+ if (o.includes("|")) {
405
+ const i = o.split("|").map((c) => c.trim());
406
+ if (i.every((c) => c.startsWith("'")))
407
+ return { type: "string", enum: i.map((c) => c.replace(/'/g, "")) };
408
+ const s = i.map((c) => M(c, t + 1, r)), a = J(s);
409
+ return {
410
+ oneOf: s,
411
+ ...a ? { discriminator: a } : {},
412
+ [z]: "union"
413
+ };
414
+ }
415
+ if (o.startsWith("{") && o.endsWith("}")) {
416
+ const i = o.slice(1, -1).trim(), s = {};
417
+ for (const a of i.split(";").filter(Boolean)) {
418
+ const [c, u] = a.split(":").map((f) => f.trim());
419
+ c && u && (s[c.replace("?", "")] = M(u, t + 1, r));
420
+ }
421
+ return { type: "object", properties: s };
422
+ }
423
+ return {};
424
+ }
425
+ function he(e) {
426
+ const t = [];
427
+ let r = 0, o = 0;
428
+ for (let i = 0; i < e.length; i++) {
429
+ const s = e[i];
430
+ s === "<" || s === "[" || s === "{" || s === "(" ? r++ : s === ">" || s === "]" || s === "}" || s === ")" ? r-- : s === "," && r === 0 && (t.push(e.slice(o, i).trim()), o = i + 1);
431
+ }
432
+ const n = e.slice(o).trim();
433
+ return n.length > 0 && t.push(n), t;
434
+ }
435
+ function Ve(e) {
436
+ const t = /^(?:Readonly)?Map<(.+)>$/.exec(e);
437
+ return t ? t[1] : void 0;
438
+ }
439
+ function ze(e) {
440
+ const t = /^(?:Readonly)?Set<(.+)>$/.exec(e);
441
+ return t ? t[1] : void 0;
442
+ }
443
+ function Ke(e) {
444
+ let t = e.trim();
445
+ if (t.startsWith("readonly ") && (t = t.slice(9).trim()), !t.startsWith("[") || !t.endsWith("]"))
446
+ return;
447
+ const r = t.slice(1, -1).trim();
448
+ if (r.length !== 0)
449
+ return he(r);
450
+ }
451
+ async function De(e, t) {
452
+ const r = e.trim(), o = Ve(r);
453
+ if (o !== void 0) {
454
+ const s = he(o);
455
+ if (s.length === 2) {
456
+ const [a, c] = await Promise.all([
457
+ t(s[0]),
458
+ t(s[1])
459
+ ]);
460
+ return {
461
+ type: "array",
462
+ items: {
463
+ type: "array",
464
+ items: [a, c],
465
+ minItems: 2,
466
+ maxItems: 2
467
+ }
468
+ };
469
+ }
470
+ }
471
+ const n = ze(r);
472
+ if (n !== void 0)
473
+ return { type: "array", items: await t(n), uniqueItems: !0 };
474
+ const i = Ke(r);
475
+ if (i !== void 0) {
476
+ const s = await Promise.all(i.map((a) => t(a)));
477
+ return {
478
+ type: "array",
479
+ items: s,
480
+ minItems: s.length,
481
+ maxItems: s.length
482
+ };
483
+ }
484
+ }
485
+ const Te = {
486
+ "decimal.js": "Decimal"
487
+ }, U = {
488
+ Date: { type: "string", format: "date-time" },
489
+ bigint: { type: "string", format: "int64" },
490
+ Uint8Array: { type: "string", format: "byte" },
491
+ Buffer: { type: "string", format: "byte" },
492
+ URL: { type: "string", format: "uri" },
493
+ RegExp: { type: "string", format: "regex" },
494
+ Decimal: { type: "string", format: "decimal" }
495
+ }, se = {
496
+ Uint8Array: "byte",
497
+ Buffer: "byte",
498
+ Decimal: "decimal"
499
+ };
500
+ function ae(e) {
501
+ var r;
502
+ const t = /* @__PURE__ */ new Map();
503
+ for (const o of e.getImportDeclarations()) {
504
+ const n = o.getModuleSpecifierValue(), i = Te[n];
505
+ if (!i)
506
+ continue;
507
+ const s = o.getDefaultImport();
508
+ if (s) {
509
+ const a = s.getText();
510
+ a !== i && t.set(a, i);
511
+ }
512
+ for (const a of o.getNamedImports()) {
513
+ const c = ((r = a.getAliasNode()) == null ? void 0 : r.getText()) ?? a.getName();
514
+ c !== i && t.set(c, i);
515
+ }
516
+ }
517
+ return t;
518
+ }
519
+ function qe(e, t) {
520
+ return (r) => {
521
+ r.addNodeParser({
522
+ supportsNode(o) {
523
+ var i, s, a;
524
+ if (o.kind !== t)
525
+ return !1;
526
+ const n = ((i = o.typeName) == null ? void 0 : i.escapedText) ?? ((a = (s = o.typeName) == null ? void 0 : s.right) == null ? void 0 : a.escapedText);
527
+ return n !== void 0 && Object.prototype.hasOwnProperty.call(se, n);
528
+ },
529
+ createType(o) {
530
+ var i, s, a;
531
+ const n = ((i = o.typeName) == null ? void 0 : i.escapedText) ?? ((a = (s = o.typeName) == null ? void 0 : s.right) == null ? void 0 : a.escapedText);
532
+ return new ne(
533
+ new re(),
534
+ { format: se[n] },
535
+ !1
536
+ );
537
+ }
538
+ }), r.addNodeParser({
539
+ supportsNode(o) {
540
+ return o.kind === e;
541
+ },
542
+ createType() {
543
+ return new ne(new re(), { format: "int64" }, !1);
544
+ }
545
+ });
546
+ };
547
+ }
548
+ let k;
549
+ function We() {
550
+ if (k)
551
+ return k;
552
+ try {
553
+ const e = Q.dirname(
554
+ require.resolve("ts-json-schema-generator/package.json")
555
+ );
556
+ k = require(require.resolve("typescript", {
557
+ paths: [e]
558
+ }));
559
+ } catch {
560
+ k = require("typescript");
561
+ }
562
+ return k;
563
+ }
564
+ const O = /* @__PURE__ */ new Map();
565
+ function Be() {
566
+ const e = process.env.APIGEN_PROGRAM_CACHE, t = e === void 0 ? NaN : Number(e);
567
+ return Number.isFinite(t) && t >= 0 ? t : 8;
568
+ }
569
+ function Ue(e) {
570
+ const t = O.get(e);
571
+ return t && (O.delete(e), O.set(e, t)), t;
572
+ }
573
+ function Ge(e, t) {
574
+ const r = Be();
575
+ if (r !== 0)
576
+ for (O.delete(e), O.set(e, t); O.size > r; ) {
577
+ const o = O.keys().next().value;
578
+ O.delete(o);
579
+ }
580
+ }
581
+ function He(e, t) {
582
+ return `${e}\0${t ?? ""}`;
583
+ }
584
+ const Ze = /* @__PURE__ */ new Set(["zod", /^zod\/./]);
585
+ function Qe(e) {
586
+ for (const t of e.getImportDeclarations()) {
587
+ const r = t.getModuleSpecifierValue();
588
+ for (const o of Ze)
589
+ if (typeof o == "string") {
590
+ if (r === o)
591
+ return !0;
592
+ } else if (o.test(r))
593
+ return !0;
594
+ }
595
+ return !1;
596
+ }
597
+ function Je(e) {
598
+ for (const t of ["$defs", "definitions"]) {
599
+ const r = e[t];
600
+ if (!r || typeof r != "object")
601
+ continue;
602
+ const o = Object.keys(r);
603
+ if (o.length === 0)
604
+ continue;
605
+ const n = new Set(o.filter((i) => /zod/i.test(i)));
606
+ for (const [i, s] of Object.entries(r)) {
607
+ if (n.has(i) || typeof s != "object" || s === null)
608
+ continue;
609
+ const a = s, c = typeof a.$ref == "string" ? a.$ref : "";
610
+ if (c) {
611
+ for (const u of n)
612
+ if (c.includes(u)) {
613
+ n.add(i);
614
+ break;
615
+ }
616
+ }
617
+ }
618
+ for (const i of n)
619
+ delete r[i];
620
+ }
621
+ G(e);
622
+ }
623
+ function G(e, t) {
624
+ if (!e || typeof e != "object")
625
+ return;
626
+ const r = t ?? /* @__PURE__ */ new WeakSet();
627
+ if (!r.has(e)) {
628
+ r.add(e);
629
+ for (const o of Object.keys(e))
630
+ if (o === "$ref" && typeof e[o] == "string") {
631
+ const n = e[o];
632
+ /zod/i.test(n) && delete e[o];
633
+ }
634
+ for (const [, o] of Object.entries(e))
635
+ if (typeof o == "object" && o !== null)
636
+ if (Array.isArray(o))
637
+ for (const n of o)
638
+ typeof n == "object" && n !== null && G(n, r);
639
+ else
640
+ G(o, r);
641
+ }
642
+ }
643
+ function Xe(e) {
644
+ const t = /* @__PURE__ */ new Set();
645
+ for (const o of ["$defs", "definitions"]) {
646
+ const n = e[o];
647
+ if (n && typeof n == "object")
648
+ for (const i of Object.keys(n))
649
+ t.add(i);
650
+ }
651
+ const r = H(e, t);
652
+ if (r.length > 0)
653
+ throw new Error(
654
+ `[apigen-core-client] Generated schema contains ${r.length} unresolvable $ref(s): ${r.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.`
655
+ );
656
+ }
657
+ function H(e, t) {
658
+ if (!e || typeof e != "object")
659
+ return [];
660
+ const r = [];
661
+ for (const [o, n] of Object.entries(e))
662
+ if (o === "$ref" && typeof n == "string") {
663
+ const i = n.match(/#\/(?:\$defs|definitions)\/(.+)$/);
664
+ i && !t.has(i[1]) && r.push(n);
665
+ } else if (typeof n == "object" && n !== null)
666
+ if (Array.isArray(n))
667
+ for (const i of n)
668
+ typeof i == "object" && i !== null && r.push(
669
+ ...H(i, t)
670
+ );
671
+ else
672
+ r.push(
673
+ ...H(n, t)
674
+ );
675
+ return r;
676
+ }
677
+ function Ye(e) {
678
+ const t = e.anyOf;
679
+ if (!Array.isArray(t) || t.length < 2)
680
+ return e;
681
+ const r = t, o = J(r), n = { ...e };
682
+ return delete n.anyOf, {
683
+ ...n,
684
+ oneOf: r,
685
+ ...o ? { discriminator: o } : {},
686
+ [z]: n[z] ?? "union"
687
+ };
688
+ }
689
+ function et(e, t, r) {
690
+ const { DEFAULT_CONFIG: o } = require("ts-json-schema-generator/dist/src/Config.js"), n = { ...o, ...e }, i = n.path, s = He(i, n.tsconfig);
691
+ let a;
692
+ a = r ? r.statVersion(i) : me(i);
693
+ let c;
694
+ if (s !== void 0) {
695
+ const f = (r == null ? void 0 : r.generatorCache.get(s)) ?? Ue(s);
696
+ f && f.version === a && (c = f.gen);
697
+ }
698
+ if (!c) {
699
+ const { createProgram: f } = require("ts-json-schema-generator/dist/factory/program.js"), l = We(), g = qe(
700
+ l.SyntaxKind.BigIntKeyword,
701
+ l.SyntaxKind.TypeReference
702
+ ), m = f(n), p = Pe(
703
+ m,
704
+ n,
705
+ g
706
+ ), y = Ne(n);
707
+ if (c = new Oe(
708
+ m,
709
+ p,
710
+ y,
711
+ n
712
+ ), r && r.stats.generatorsBuilt++, s !== void 0 && a !== void 0) {
713
+ const h = { version: a, gen: c };
714
+ Ge(s, h), r == null || r.generatorCache.set(s, h);
715
+ }
716
+ }
717
+ const u = c.createSchema(n.type);
718
+ return Je(u), Xe(u), u;
719
+ }
720
+ function tt(e, t) {
721
+ let r = e.trim();
722
+ if (r = be(r), t != null && t.size) {
723
+ const n = t.get(r);
724
+ if (n !== void 0)
725
+ return n;
726
+ }
727
+ const o = r.match(/^ReadonlyArray<(.+)>$/);
728
+ for (o && (r = `${o[1].trim()}[]`); r.startsWith("readonly "); )
729
+ r = r.slice(9).trim();
730
+ return r;
731
+ }
732
+ function Se(e) {
733
+ return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
734
+ }
735
+ const nt = Object.entries(Te).map(([e, t]) => ({
736
+ // Matches: import("...{modSpec}...").<anyMemberName> (single or double quotes)
737
+ // The module specifier appears inside an absolute path, so we allow any
738
+ // characters between the quote and the specifier, and between the specifier
739
+ // and the closing quote. The trailing member accessor (`.default`, `.Decimal`,
740
+ // …) is matched generically (`\w+`) rather than anchored to one spelling —
741
+ // see the doc comment above for why.
742
+ pattern: new RegExp(
743
+ `import\\(["'][^"']*${Se(e)}[^"']*["']\\)\\.\\w+`,
744
+ "g"
745
+ ),
746
+ key: t
747
+ }));
748
+ function be(e) {
749
+ let t = e;
750
+ for (const { pattern: r, key: o } of nt)
751
+ t = t.replace(r, o);
752
+ return t;
753
+ }
754
+ function rt(e, t) {
755
+ let r = be(e);
756
+ for (const [o, n] of t)
757
+ r = r.replace(
758
+ new RegExp(`\\b${Se(o)}\\b`, "g"),
759
+ n
760
+ );
761
+ return r;
762
+ }
763
+ async function A(e, t, r, o, n, i) {
764
+ const s = t.getFilePath(), a = `${s}\0${o ?? ""}\0${r}`, c = i ?? /* @__PURE__ */ new Set();
765
+ if (c.has(a))
766
+ return {};
767
+ if (!n) {
768
+ const p = new Set(c);
769
+ return p.add(a), ce(
770
+ e,
771
+ t,
772
+ r,
773
+ o,
774
+ void 0,
775
+ p
776
+ );
777
+ }
778
+ const u = n.schemaCache.get(a);
779
+ if (u !== void 0)
780
+ return n.stats.schemaCacheHits++, u;
781
+ const f = Ee(
782
+ s,
783
+ o,
784
+ n.statVersion(s)
785
+ ), l = f.get(r);
786
+ if (l !== void 0)
787
+ return n.stats.schemaCacheHits++, n.schemaCache.set(a, Promise.resolve(l)), l;
788
+ n.stats.schemaCacheMisses++;
789
+ const g = new Set(c);
790
+ g.add(a);
791
+ const m = ce(
792
+ e,
793
+ t,
794
+ r,
795
+ o,
796
+ n,
797
+ g
798
+ ).then((p) => (f.set(r, p), p)).catch((p) => {
799
+ throw n.schemaCache.delete(a), p;
800
+ });
801
+ return n.schemaCache.set(a, m), m;
802
+ }
803
+ async function ce(e, t, r, o, n, i) {
804
+ if (["void", "undefined", "null", "Promise<void>"].includes(r))
805
+ return { type: "null" };
806
+ let s;
807
+ if (n) {
808
+ const g = n.aliasCache.get(t);
809
+ s = g ?? ae(t), g || n.aliasCache.set(t, s);
810
+ } else
811
+ s = ae(t);
812
+ const a = tt(r, s), c = U[a];
813
+ if (c !== void 0)
814
+ return c;
815
+ const u = await De(
816
+ a,
817
+ (g) => A(e, t, g, o, n, i)
818
+ );
819
+ if (u !== void 0)
820
+ return u;
821
+ const f = (n == null ? void 0 : n.zodImportCache.get(t)) ?? Qe(t);
822
+ if (n && n.zodImportCache.set(t, f), !f)
823
+ try {
824
+ const g = {
825
+ path: t.getFilePath(),
826
+ type: a,
827
+ skipTypeCheck: !0,
828
+ tsconfig: o,
829
+ // BUG-APIGEN-026: ts-json-schema-generator's own default (topRef:
830
+ // true) wraps EVERY named-type schema as `{ $ref: "#/definitions/X",
831
+ // definitions: { X: {...} } }` instead of inlining it. This function
832
+ // returns that whole fragment, which `extract.ts` then splices into
833
+ // an arbitrarily nested property position inside a much larger
834
+ // composed function schema (see `compose-schemas.ts`'s `data`
835
+ // wrapper). JSON-Schema `$ref` resolution is root-relative to the
836
+ // document being compiled, NOT fragment-relative -- so a `$ref`
837
+ // sitting several levels deep, whose matching `definitions` sibling
838
+ // landed at that SAME nested depth (not the true document root),
839
+ // permanently dangles once AJV compiles the full composed schema
840
+ // (`validate-layer.ts`'s `ajv.compile(schema.input)`, one schema per
841
+ // function, no shared multi-schema registry to resolve against).
842
+ // `topRef: false` inlines the entry type directly instead, which
843
+ // eliminates the dangling ref for the common (non-recursive)
844
+ // named-type case. It does NOT fully solve genuinely self-
845
+ // referential/cyclic named types, which still need an internal
846
+ // `$ref` to model the cycle and would carry the identical class of
847
+ // bug if ever embedded nested -- that needs a proper
848
+ // dereference/hoist pass and is tracked separately, unresolved, in
849
+ // BUG-APIGEN-026's BACKLOG entry.
850
+ topRef: !1
851
+ }, m = et(g, !0, n);
852
+ return Ye(m);
853
+ } catch {
854
+ }
855
+ try {
856
+ const g = await Me(
857
+ e,
858
+ t,
859
+ a,
860
+ (m) => ye(
861
+ m,
862
+ (p) => A(e, t, p, o, n, i),
863
+ 0
864
+ )
865
+ );
866
+ if (g !== void 0)
867
+ return g;
868
+ } catch {
869
+ }
870
+ const l = rt(a, s);
871
+ return M(l, 0, s);
872
+ }
873
+ function X(e, t, r) {
874
+ if (e != null && e.hasInitializer()) {
875
+ const o = e.getInitializer();
876
+ if (o)
877
+ return o.getText();
878
+ }
879
+ return ot(r, t);
880
+ }
881
+ function ot(e, t) {
882
+ var s;
883
+ const r = e, o = ((s = r == null ? void 0 : r.getJsDocs) == null ? void 0 : s.call(r)) ?? [], n = t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), i = new RegExp(`\\[\\s*${n}\\s*=\\s*([^\\]]+)\\]`);
884
+ for (const a of o)
885
+ for (const c of a.getTags()) {
886
+ if (c.getTagName() !== "param")
887
+ continue;
888
+ const u = c.getText().match(i);
889
+ if (u)
890
+ return u[1].trim();
891
+ }
892
+ }
893
+ function it(e) {
894
+ const t = e.trim(), r = t.match(/^(['"`])([\s\S]*)\1$/);
895
+ if (r)
896
+ return r[2];
897
+ if (t === "true")
898
+ return !0;
899
+ if (t === "false")
900
+ return !1;
901
+ if (t === "null")
902
+ return null;
903
+ if (t !== "undefined") {
904
+ if (/^-?\d+(\.\d+)?$/.test(t))
905
+ return Number(t);
906
+ try {
907
+ return JSON.parse(t);
908
+ } catch {
909
+ return t;
910
+ }
911
+ }
912
+ }
913
+ function st(e, t) {
914
+ const r = it(t);
915
+ if (r === void 0)
916
+ return;
917
+ e.default = r;
918
+ const o = typeof r == "string" ? r : JSON.stringify(r), n = typeof e.description == "string" ? e.description : void 0;
919
+ e.description = n ? `${n} (default: ${o})` : `(default: ${o})`;
920
+ }
921
+ async function Nt(e) {
922
+ const t = e.session === void 0, r = de(e.session ?? ge());
923
+ try {
924
+ return await at(e, r);
925
+ } finally {
926
+ t && r.dispose();
927
+ }
928
+ }
929
+ async function at(e, t) {
930
+ const { sourceFile: r, namespace: o = "", tsconfig: n } = e, i = t.projectFor(n), s = t.sourceFileFor(r, n), a = Q.basename(r), c = P(ft(a)), u = P(o), f = [];
931
+ for (const [m, p] of s.getExportedDeclarations()) {
932
+ if (m === "default" || _(m))
933
+ continue;
934
+ const y = pt(p);
935
+ if (y) {
936
+ const d = y.getSignature(), S = ue(d, y), b = d.getReturnType().getText();
937
+ f.push(
938
+ await L(
939
+ i,
940
+ s,
941
+ u,
942
+ c,
943
+ m,
944
+ S,
945
+ b,
946
+ y.isAsync(),
947
+ n,
948
+ t
949
+ )
950
+ );
951
+ continue;
952
+ }
953
+ const h = p.find(
954
+ (d) => d.getKindName() === "VariableDeclaration"
955
+ );
956
+ if (!h)
957
+ continue;
958
+ const T = h.getInitializer(), x = T == null ? void 0 : T.getKindName();
959
+ if (T && ["ArrowFunction", "FunctionExpression"].includes(x ?? "")) {
960
+ const S = h.getType().getCallSignatures();
961
+ if (S.length === 0)
962
+ continue;
963
+ const b = S[0], $ = fe(
964
+ b,
965
+ h,
966
+ h.getVariableStatement()
967
+ ), j = b.getReturnType().getText(), v = T.isAsync();
968
+ f.push(
969
+ await L(
970
+ i,
971
+ s,
972
+ u,
973
+ c,
974
+ m,
975
+ $,
976
+ j,
977
+ v,
978
+ n,
979
+ t
980
+ )
981
+ );
982
+ } else if (x === "ObjectLiteralExpression") {
983
+ const d = h.getType();
984
+ for (const S of d.getProperties()) {
985
+ const b = S.getName();
986
+ if (_(b))
987
+ continue;
988
+ const j = S.getTypeAtLocation(h).getCallSignatures();
989
+ if (j.length === 0)
990
+ continue;
991
+ const v = j[0], w = fe(
992
+ v,
993
+ h,
994
+ h.getVariableStatement()
995
+ ), F = v.getReturnType().getText(), K = [
996
+ c,
997
+ P(m),
998
+ P(b)
999
+ ];
1000
+ f.push(
1001
+ await V(
1002
+ i,
1003
+ s,
1004
+ u,
1005
+ K,
1006
+ b,
1007
+ w,
1008
+ F,
1009
+ !1,
1010
+ n,
1011
+ t
1012
+ )
1013
+ );
1014
+ }
1015
+ } else {
1016
+ const d = h.getType(), S = d.getText();
1017
+ if (E(d, h)) {
1018
+ const b = await A(
1019
+ i,
1020
+ s,
1021
+ S,
1022
+ n,
1023
+ t
1024
+ );
1025
+ f.push(
1026
+ ut(u, c, m, b)
1027
+ );
1028
+ } else
1029
+ console.warn(
1030
+ `[apigen-core] Skipping non-callable, non-serializable export: ${m}`
1031
+ );
1032
+ }
1033
+ }
1034
+ const l = s.getDefaultExportSymbol();
1035
+ if (l) {
1036
+ const m = s.getExportAssignment((p) => !p.isExportEquals());
1037
+ if (m) {
1038
+ const p = m.getExpression(), y = p.getKindName();
1039
+ if (["ArrowFunction", "FunctionExpression"].includes(y)) {
1040
+ const T = p.getType().getCallSignatures();
1041
+ if (T.length > 0) {
1042
+ const x = T[0], d = D(x, m), S = x.getReturnType().getText(), b = p.isAsync();
1043
+ f.push(
1044
+ await L(
1045
+ i,
1046
+ s,
1047
+ u,
1048
+ c,
1049
+ "default",
1050
+ d,
1051
+ S,
1052
+ b,
1053
+ n,
1054
+ t
1055
+ )
1056
+ );
1057
+ }
1058
+ } else {
1059
+ const h = p.getType();
1060
+ for (const T of h.getProperties()) {
1061
+ const x = T.getName();
1062
+ if (_(x))
1063
+ continue;
1064
+ const S = T.getTypeAtLocation(m).getCallSignatures();
1065
+ if (S.length === 0)
1066
+ continue;
1067
+ const b = S[0], $ = D(b, m), j = b.getReturnType().getText(), v = [
1068
+ c,
1069
+ P("default"),
1070
+ P(x)
1071
+ ];
1072
+ f.push(
1073
+ await V(
1074
+ i,
1075
+ s,
1076
+ u,
1077
+ v,
1078
+ x,
1079
+ $,
1080
+ j,
1081
+ !1,
1082
+ n,
1083
+ t
1084
+ )
1085
+ );
1086
+ }
1087
+ }
1088
+ } else {
1089
+ const p = l.getDeclarations();
1090
+ for (const y of p) {
1091
+ if (y.getKindName() !== "FunctionDeclaration")
1092
+ continue;
1093
+ const h = y, T = h.getName(), x = T && T.length > 0 ? T : "default", d = h.getSignature(), S = ue(d, h), b = d.getReturnType().getText();
1094
+ f.push(
1095
+ await L(
1096
+ i,
1097
+ s,
1098
+ u,
1099
+ c,
1100
+ x,
1101
+ S,
1102
+ b,
1103
+ h.isAsync(),
1104
+ n,
1105
+ t
1106
+ )
1107
+ );
1108
+ }
1109
+ }
1110
+ }
1111
+ const g = lt(s);
1112
+ if (g.length > 0)
1113
+ for (const { name: m, sig: p } of g) {
1114
+ if (_(m))
1115
+ continue;
1116
+ const y = D(p), h = p.getReturnType().getText(), T = [c, P(m)];
1117
+ f.push(
1118
+ await V(
1119
+ i,
1120
+ s,
1121
+ u,
1122
+ T,
1123
+ m,
1124
+ y,
1125
+ h,
1126
+ !1,
1127
+ n,
1128
+ t
1129
+ )
1130
+ );
1131
+ }
1132
+ return f;
1133
+ }
1134
+ function ct(e, t, r, o) {
1135
+ const n = /* @__PURE__ */ new Set(), i = (s) => {
1136
+ if (Array.isArray(s))
1137
+ return s.map(i);
1138
+ if (!s || typeof s != "object" || n.has(s))
1139
+ return s;
1140
+ n.add(s);
1141
+ try {
1142
+ const a = s, c = {};
1143
+ for (const [u, f] of Object.entries(a)) {
1144
+ if (u === "definitions" || u === "$defs") {
1145
+ const l = u, g = t[l];
1146
+ for (const [m, p] of Object.entries(
1147
+ f
1148
+ )) {
1149
+ const y = i(p), h = g[m];
1150
+ if (h !== void 0 && JSON.stringify(h) !== JSON.stringify(y))
1151
+ throw new Error(
1152
+ `[apigen-core-client] Function "${r}": param "${o}" contributes a "${l}.${m}" 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.`
1153
+ );
1154
+ g[m] = y;
1155
+ }
1156
+ continue;
1157
+ }
1158
+ c[u] = i(f);
1159
+ }
1160
+ return c;
1161
+ } finally {
1162
+ n.delete(s);
1163
+ }
1164
+ };
1165
+ return i(e);
1166
+ }
1167
+ async function L(e, t, r, o, n, i, s, a, c, u) {
1168
+ const f = P(n);
1169
+ return V(
1170
+ e,
1171
+ t,
1172
+ r,
1173
+ [o, f],
1174
+ n,
1175
+ i,
1176
+ s,
1177
+ a,
1178
+ c,
1179
+ u
1180
+ );
1181
+ }
1182
+ async function V(e, t, r, o, n, i, s, a, c, u) {
1183
+ const f = i.length > 0 && i[0].name === "ctx", l = i.filter((d) => d.name !== "ctx"), g = l.filter((d) => !d.optional).map((d) => d.name), m = {}, p = {
1184
+ definitions: {},
1185
+ $defs: {}
1186
+ };
1187
+ for (const d of l) {
1188
+ const S = await A(e, t, d.type, c, u), b = ct(S, p, n, d.name);
1189
+ d.defaultValue !== void 0 && st(b, d.defaultValue), m[d.name] = b;
1190
+ }
1191
+ const y = s.replace(/^Promise<(.+)>$/, "$1").trim(), h = await A(
1192
+ e,
1193
+ t,
1194
+ y,
1195
+ c,
1196
+ u
1197
+ ), T = {
1198
+ type: "object",
1199
+ properties: m,
1200
+ required: g,
1201
+ // BUG-APIGEN-029: hoisted definitions from param fragments — see
1202
+ // hoistNestedDefs. Only attached when non-empty so the common
1203
+ // (no-recursive-type) case's schema shape is unchanged.
1204
+ ...Object.keys(p.definitions).length > 0 ? { definitions: p.definitions } : {},
1205
+ ...Object.keys(p.$defs).length > 0 ? { $defs: p.$defs } : {}
1206
+ };
1207
+ return {
1208
+ id: xe(r, o),
1209
+ host: "ts",
1210
+ namespace: r,
1211
+ path: o,
1212
+ kind: "action",
1213
+ async: a,
1214
+ streaming: !1,
1215
+ safe: !1,
1216
+ // action → false per §4
1217
+ input: T,
1218
+ output: h,
1219
+ envelope: {},
1220
+ typeText: {
1221
+ lang: "ts",
1222
+ input: mt(i),
1223
+ output: y
1224
+ },
1225
+ ...f ? { hasCtx: !0 } : {}
1226
+ };
1227
+ }
1228
+ function ut(e, t, r, o) {
1229
+ const n = P(r), i = [t, n];
1230
+ return {
1231
+ id: xe(e, i),
1232
+ host: "ts",
1233
+ namespace: e,
1234
+ path: i,
1235
+ kind: "query",
1236
+ async: !1,
1237
+ streaming: !1,
1238
+ safe: !0,
1239
+ // query → true per §4
1240
+ input: { type: "object", properties: {}, required: [] },
1241
+ output: o,
1242
+ envelope: {},
1243
+ typeText: null
1244
+ };
1245
+ }
1246
+ function xe(e, t) {
1247
+ return (e.raw ? [e, ...t] : t).map((o) => o.words.join("-")).join("/");
1248
+ }
1249
+ function ve(e) {
1250
+ return e.split(/[-_.]+/).flatMap(
1251
+ (t) => (
1252
+ // Then split PascalCase / camelCase transitions
1253
+ t.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").replace(/([a-z\d])([A-Z])/g, "$1_$2").split("_").filter(Boolean)
1254
+ )
1255
+ ).map((t) => t.toLowerCase()).filter(Boolean);
1256
+ }
1257
+ function P(e) {
1258
+ return { raw: e, words: ve(e) };
1259
+ }
1260
+ function ft(e) {
1261
+ return e.replace(/\.[^.]+$/, "").replace(/[._]+/g, "-");
1262
+ }
1263
+ function lt(e) {
1264
+ const t = [];
1265
+ for (const r of e.getStatements()) {
1266
+ if (r.getKindName() !== "ExpressionStatement")
1267
+ continue;
1268
+ const o = r.getExpression();
1269
+ if (o.getKindName() !== "BinaryExpression")
1270
+ continue;
1271
+ const n = o;
1272
+ if (n.getLeft().getText().trim() !== "module.exports" || n.getOperatorToken().getKindName() !== "EqualsToken")
1273
+ continue;
1274
+ const s = n.getRight(), a = s.getType();
1275
+ for (const c of a.getProperties()) {
1276
+ const f = c.getTypeAtLocation(s).getCallSignatures();
1277
+ f.length !== 0 && t.push({ name: c.getName(), sig: f[0] });
1278
+ }
1279
+ }
1280
+ return t;
1281
+ }
1282
+ function pt(e) {
1283
+ let t;
1284
+ for (const r of e) {
1285
+ if (r.getKindName() !== "FunctionDeclaration")
1286
+ continue;
1287
+ const o = r;
1288
+ if (t || (t = o), o.getBody())
1289
+ return o;
1290
+ }
1291
+ return t;
1292
+ }
1293
+ function ue(e, t) {
1294
+ return e.getParameters().map((r) => {
1295
+ var s;
1296
+ const o = r.getDeclarations(), n = o.length > 0 && o[0].getKindName() === "Parameter" ? o[0] : null, i = r.isOptional() || ((n == null ? void 0 : n.hasInitializer()) ?? !1) || (((s = n == null ? void 0 : n.hasQuestionToken) == null ? void 0 : s.call(n)) ?? !1);
1297
+ return {
1298
+ name: r.getName(),
1299
+ type: r.getTypeAtLocation(e.getDeclaration()).getText(),
1300
+ optional: i,
1301
+ defaultValue: X(n, r.getName(), t)
1302
+ };
1303
+ });
1304
+ }
1305
+ function fe(e, t, r) {
1306
+ return e.getParameters().map((o) => {
1307
+ var a;
1308
+ const n = o.getDeclarations(), i = n.length > 0 && n[0].getKindName() === "Parameter" ? n[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);
1309
+ return {
1310
+ name: o.getName(),
1311
+ type: o.getTypeAtLocation(t).getText(),
1312
+ optional: s,
1313
+ defaultValue: X(
1314
+ i,
1315
+ o.getName(),
1316
+ r ?? t
1317
+ )
1318
+ };
1319
+ });
1320
+ }
1321
+ function D(e, t) {
1322
+ return e.getParameters().map((r) => {
1323
+ var s, a, c;
1324
+ const o = r.getDeclarations(), n = o.length > 0 && o[0].getKindName() === "Parameter" ? o[0] : null, i = r.isOptional() || ((n == null ? void 0 : n.hasInitializer()) ?? !1) || (((s = n == null ? void 0 : n.hasQuestionToken) == null ? void 0 : s.call(n)) ?? !1);
1325
+ return {
1326
+ name: r.getName(),
1327
+ type: n ? n.getType().getText() : ((c = (a = r.getValueDeclaration()) == null ? void 0 : a.getType()) == null ? void 0 : c.getText()) ?? "unknown",
1328
+ optional: i,
1329
+ defaultValue: X(n, r.getName(), t)
1330
+ };
1331
+ });
1332
+ }
1333
+ function mt(e) {
1334
+ const t = e.filter((r) => r.name !== "ctx");
1335
+ return t.length === 0 ? "()" : "(" + t.map((r) => `${r.name}${r.optional ? "?" : ""}: ${r.type}`).join(", ") + ")";
1336
+ }
1337
+ function _(e) {
1338
+ return !!(e === "__samples__" || e.startsWith("__"));
1339
+ }
1340
+ function E(e, t, r = /* @__PURE__ */ new Set()) {
1341
+ if (e.getCallSignatures().length > 0 || e.getConstructSignatures().length > 0)
1342
+ return !1;
1343
+ if (e.isString() || e.isNumber() || e.isBoolean() || e.isNull() || e.isUndefined() || e.isStringLiteral() || e.isNumberLiteral() || e.isBooleanLiteral() || e.isEnumLiteral())
1344
+ return !0;
1345
+ if (e.isArray() || e.isReadonlyArray()) {
1346
+ const o = e.getArrayElementType();
1347
+ return o ? E(o, t, r) : !1;
1348
+ }
1349
+ if (e.isTuple())
1350
+ return e.getTupleElements().every((o) => E(o, t, r));
1351
+ if (e.isUnion())
1352
+ return e.getUnionTypes().every((o) => E(o, t, r));
1353
+ if (e.isIntersection())
1354
+ return e.getIntersectionTypes().every((o) => E(o, t, r));
1355
+ if (e.isObject()) {
1356
+ const o = e.getText(t);
1357
+ if (r.has(o))
1358
+ return !0;
1359
+ r.add(o);
1360
+ const n = e.getStringIndexType(), i = e.getNumberIndexType();
1361
+ if (n || i)
1362
+ return [n, i].every(
1363
+ (a) => !a || E(a, t, r)
1364
+ );
1365
+ const s = e.getProperties();
1366
+ return s.length === 0 ? !0 : s.every((a) => {
1367
+ const c = a.getTypeAtLocation(t);
1368
+ return E(c, t, r);
1369
+ });
1370
+ }
1371
+ return !1;
1372
+ }
1373
+ async function Ot(e) {
1374
+ const t = e.session === void 0, r = de(e.session ?? ge());
1375
+ try {
1376
+ return await gt(e, r);
1377
+ } finally {
1378
+ t && r.dispose();
1379
+ }
1380
+ }
1381
+ async function gt(e, t) {
1382
+ const {
1383
+ sourceFile: r,
1384
+ namespace: o = "",
1385
+ tsconfig: n,
1386
+ includeInstances: i = !1
1387
+ } = e, s = t.projectFor(n), a = t.sourceFileFor(r, n), c = Q.basename(r), u = C(yt(c)), f = C(o), l = [];
1388
+ for (const [g, m] of a.getExportedDeclarations()) {
1389
+ const p = m.find(
1390
+ (T) => T.getKindName() === "ClassDeclaration"
1391
+ );
1392
+ if (!p)
1393
+ continue;
1394
+ const y = g === "default" ? p.getName() : g;
1395
+ if (!y || W(y))
1396
+ continue;
1397
+ const h = C(y);
1398
+ for (const T of p.getStaticMethods()) {
1399
+ const x = T.getName();
1400
+ if (W(x))
1401
+ continue;
1402
+ const d = T.getScope();
1403
+ if (d === R.Private || d === R.Protected)
1404
+ continue;
1405
+ const S = T.getSignature(), b = q(S, T), $ = S.getReturnType().getText(), j = T.isAsync(), v = [u, h, C(x)];
1406
+ l.push(
1407
+ await dt(
1408
+ s,
1409
+ a,
1410
+ f,
1411
+ v,
1412
+ b,
1413
+ $,
1414
+ j,
1415
+ n,
1416
+ t
1417
+ )
1418
+ );
1419
+ }
1420
+ if (i) {
1421
+ {
1422
+ const x = p.getConstructors()[0] ?? null;
1423
+ let d = [];
1424
+ if (x) {
1425
+ const w = x.getSignature();
1426
+ d = q(w, x);
1427
+ }
1428
+ const S = [u, h], b = Z(f, S), $ = d.filter((w) => w.name !== "ctx"), j = $.filter((w) => !w.optional).map((w) => w.name), v = {};
1429
+ for (const w of $)
1430
+ v[w.name] = await A(
1431
+ s,
1432
+ a,
1433
+ w.type,
1434
+ n,
1435
+ t
1436
+ );
1437
+ l.push({
1438
+ id: b,
1439
+ host: "ts",
1440
+ namespace: f,
1441
+ path: S,
1442
+ kind: "constructor",
1443
+ async: !1,
1444
+ streaming: !1,
1445
+ safe: !1,
1446
+ input: { type: "object", properties: v, required: j },
1447
+ output: {
1448
+ type: "object",
1449
+ properties: { instanceId: { type: "string" } },
1450
+ required: ["instanceId"]
1451
+ },
1452
+ envelope: {},
1453
+ typeText: {
1454
+ lang: "ts",
1455
+ input: ht(d),
1456
+ output: "{ instanceId: string }"
1457
+ }
1458
+ });
1459
+ }
1460
+ for (const T of p.getInstanceMethods()) {
1461
+ const x = T.getName();
1462
+ if (W(x))
1463
+ continue;
1464
+ const d = T.getScope();
1465
+ if (d === R.Private || d === R.Protected)
1466
+ continue;
1467
+ const S = T.getSignature(), b = q(S, T), $ = S.getReturnType().getText(), j = T.isAsync(), v = [u, h, C(x)], w = Z(f, v), F = b.filter((N) => N.name !== "ctx"), K = F.filter((N) => !N.optional).map((N) => N.name), Y = {};
1468
+ for (const N of F)
1469
+ Y[N.name] = await A(
1470
+ s,
1471
+ a,
1472
+ N.type,
1473
+ n,
1474
+ t
1475
+ );
1476
+ const ee = $.replace(/^Promise<(.+)>$/, "$1").trim(), je = await A(
1477
+ s,
1478
+ a,
1479
+ ee,
1480
+ n,
1481
+ t
1482
+ );
1483
+ l.push({
1484
+ id: w,
1485
+ host: "ts",
1486
+ namespace: f,
1487
+ path: v,
1488
+ kind: "instance-method",
1489
+ async: j,
1490
+ streaming: !1,
1491
+ safe: !1,
1492
+ input: { type: "object", properties: Y, required: K },
1493
+ output: je,
1494
+ envelope: {
1495
+ type: "object",
1496
+ properties: { instanceId: { type: "string" } },
1497
+ required: ["instanceId"]
1498
+ },
1499
+ typeText: {
1500
+ lang: "ts",
1501
+ input: we(b),
1502
+ output: ee
1503
+ }
1504
+ });
1505
+ }
1506
+ }
1507
+ }
1508
+ return l;
1509
+ }
1510
+ async function dt(e, t, r, o, n, i, s, a, c) {
1511
+ const u = n.filter((y) => y.name !== "ctx"), f = u.filter((y) => !y.optional).map((y) => y.name), l = {};
1512
+ for (const y of u)
1513
+ l[y.name] = await A(
1514
+ e,
1515
+ t,
1516
+ y.type,
1517
+ a,
1518
+ c
1519
+ );
1520
+ const g = i.replace(/^Promise<(.+)>$/, "$1").trim(), m = await A(
1521
+ e,
1522
+ t,
1523
+ g,
1524
+ a,
1525
+ c
1526
+ );
1527
+ return {
1528
+ id: Z(r, o),
1529
+ host: "ts",
1530
+ namespace: r,
1531
+ path: o,
1532
+ kind: "action",
1533
+ async: s,
1534
+ streaming: !1,
1535
+ safe: !1,
1536
+ // action → false per §4
1537
+ input: { type: "object", properties: l, required: f },
1538
+ output: m,
1539
+ envelope: {},
1540
+ typeText: {
1541
+ lang: "ts",
1542
+ input: we(n),
1543
+ output: g
1544
+ }
1545
+ };
1546
+ }
1547
+ function Z(e, t) {
1548
+ return (e.raw ? [e, ...t] : t).map((o) => o.words.join("-")).join("/");
1549
+ }
1550
+ function C(e) {
1551
+ return { raw: e, words: ve(e) };
1552
+ }
1553
+ function yt(e) {
1554
+ return e.replace(/\.[^.]+$/, "").replace(/[._]+/g, "-");
1555
+ }
1556
+ function q(e, t) {
1557
+ return e.getParameters().map((r) => {
1558
+ var s;
1559
+ const o = r.getDeclarations(), n = o.length > 0 && o[0].getKindName() === "Parameter" ? o[0] : null, i = r.isOptional() || ((n == null ? void 0 : n.hasInitializer()) ?? !1) || (((s = n == null ? void 0 : n.hasQuestionToken) == null ? void 0 : s.call(n)) ?? !1);
1560
+ return {
1561
+ name: r.getName(),
1562
+ type: r.getTypeAtLocation(t).getText(),
1563
+ optional: i
1564
+ };
1565
+ });
1566
+ }
1567
+ function we(e) {
1568
+ const t = e.filter((r) => r.name !== "ctx");
1569
+ return t.length === 0 ? "()" : "(" + t.map((r) => `${r.name}${r.optional ? "?" : ""}: ${r.type}`).join(", ") + ")";
1570
+ }
1571
+ function ht(e) {
1572
+ return e.length === 0 ? "()" : "(" + e.map((t) => `${t.name}${t.optional ? "?" : ""}: ${t.type}`).join(", ") + ")";
1573
+ }
1574
+ function W(e) {
1575
+ return !!(e === "__samples__" || e.startsWith("__") || e.startsWith("_"));
1576
+ }
1577
+ const Tt = /* @__PURE__ */ new Map([
1578
+ // TypeScript variants
1579
+ [".ts", "ts"],
1580
+ [".tsx", "ts"],
1581
+ [".mts", "ts"],
1582
+ [".cts", "ts"],
1583
+ // Python
1584
+ [".py", "py"],
1585
+ // Rust
1586
+ [".rs", "rust"],
1587
+ // Go
1588
+ [".go", "go"],
1589
+ // Java / Kotlin (both are JVM host languages for the purposes of routing)
1590
+ [".java", "java"]
1591
+ ]);
1592
+ function St(e) {
1593
+ const t = Ae.extname(e).toLowerCase();
1594
+ return Tt.get(t);
1595
+ }
1596
+ function bt(e) {
1597
+ return e.language ?? "ts";
1598
+ }
1599
+ function xt(e, t) {
1600
+ const r = St(t);
1601
+ return r === void 0 ? !1 : r === bt(e);
1602
+ }
1603
+ function Et(e, t) {
1604
+ return t.filter((r) => xt(e, r));
1605
+ }
1606
+ export {
1607
+ At as clearPersistentProjectCache,
1608
+ Pt as composeSchemas,
1609
+ ge as createExtractionSession,
1610
+ bt as effectiveLanguage,
1611
+ Nt as extract,
1612
+ Ot as extractClasses,
1613
+ Ce as isPrimitiveOnlyInputSchema,
1614
+ St as languageOfSource,
1615
+ xt as pluginConsumesSource,
1616
+ Et as sourcesForPlugin,
1617
+ ve as tokenize
1618
+ };