llmz 0.8.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/DOCS.md +230 -1796
  2. package/ERRORS.md +98 -0
  3. package/README.md +96 -548
  4. package/dist/chat/chat.d.ts +63 -0
  5. package/dist/chat/component.d.ts +31 -0
  6. package/dist/chat/component.default.d.ts +58 -0
  7. package/dist/chat/response.d.ts +15 -0
  8. package/dist/compiler/compiler.d.ts +2 -7
  9. package/dist/compiler/plugins/dynamic-code.d.ts +7 -0
  10. package/dist/compiler/plugins/replace-comment.d.ts +2 -3
  11. package/dist/compiler/plugins/return-async.d.ts +5 -4
  12. package/dist/compiler/plugins/termination.d.ts +8 -0
  13. package/dist/compiler/plugins/tool-resolution.d.ts +4 -0
  14. package/dist/compiler/plugins/variable-extraction.d.ts +2 -8
  15. package/dist/component-BpMVZYOa.cjs +649 -0
  16. package/dist/component-C27qu6Zv.js +614 -0
  17. package/dist/context.d.ts +74 -385
  18. package/dist/custom-client-BDkgBR2w.js +1631 -0
  19. package/dist/custom-client-MytucGI-.cjs +1708 -0
  20. package/dist/custom-client.d.ts +12 -2
  21. package/dist/errors/catalog.d.ts +287 -0
  22. package/dist/errors/hooks.d.ts +2 -0
  23. package/dist/errors-H4JJFH3S.js +620 -0
  24. package/dist/errors-IhnTKUp7.cjs +871 -0
  25. package/dist/errors.d.ts +18 -36
  26. package/dist/execute-BYI_U5sR.js +1943 -0
  27. package/dist/execute-DLas4V2n.cjs +1944 -0
  28. package/dist/{exit-DUM96DN1.cjs → exit-BUgJ5qi5.cjs} +38 -28
  29. package/dist/{exit-CDdxDBRT.js → exit-CPNk3vbz.js} +37 -27
  30. package/dist/exit.d.ts +19 -16
  31. package/dist/index.cjs +181 -999
  32. package/dist/index.d.ts +25 -28
  33. package/dist/index.js +141 -974
  34. package/dist/index.workerd.js +7725 -9531
  35. package/dist/inspect.d.ts +19 -3
  36. package/dist/inspection.d.ts +38 -0
  37. package/dist/native-Bm6L9zOb.cjs +212 -0
  38. package/dist/native-DvTH9vFe.js +177 -0
  39. package/dist/objects.d.ts +2 -57
  40. package/dist/prompts/native.d.ts +2 -0
  41. package/dist/prompts/prompt.d.ts +10 -98
  42. package/dist/quickjs-variant-DJwYDSsb.cjs +1073 -0
  43. package/dist/quickjs-variant-DlPi9-Sx.js +984 -0
  44. package/dist/result.d.ts +30 -861
  45. package/dist/runtime/execute.d.ts +3 -2
  46. package/dist/runtime/execution-activity.d.ts +11 -0
  47. package/dist/runtime/execution-activity.test.d.ts +1 -0
  48. package/dist/runtime/execution-diagnostics.d.ts +11 -0
  49. package/dist/runtime/execution-diagnostics.test.d.ts +1 -0
  50. package/dist/runtime/execution-report.d.ts +48 -0
  51. package/dist/runtime/execution-report.test.d.ts +1 -0
  52. package/dist/runtime/execution-safety.test.d.ts +1 -0
  53. package/dist/runtime/exit-control-flow.test.d.ts +1 -0
  54. package/dist/runtime/fixtures/chat.d.ts +8 -0
  55. package/dist/runtime/fixtures/long-search.d.ts +19 -0
  56. package/dist/runtime/fixtures/long-search.test.d.ts +1 -0
  57. package/dist/runtime/fixtures/native-client.d.ts +33 -0
  58. package/dist/runtime/fixtures/protocol-languages.d.ts +74 -0
  59. package/dist/runtime/generate.d.ts +23 -27
  60. package/dist/runtime/generate.test.d.ts +1 -0
  61. package/dist/runtime/hook-provenance.test.d.ts +1 -0
  62. package/dist/runtime/inspection-hook.test.d.ts +1 -0
  63. package/dist/runtime/inspection-values.d.ts +14 -0
  64. package/dist/runtime/inspection-values.test.d.ts +1 -0
  65. package/dist/runtime/interruption-control-flow.test.d.ts +1 -0
  66. package/dist/runtime/interruption-settings.test.d.ts +1 -0
  67. package/dist/runtime/javascript-api.d.ts +59 -0
  68. package/dist/runtime/javascript-api.test.d.ts +1 -0
  69. package/dist/runtime/native-review.test.d.ts +1 -0
  70. package/dist/runtime/native-tools.d.ts +18 -0
  71. package/dist/runtime/native-tools.test.d.ts +1 -0
  72. package/dist/runtime/object-memory.test.d.ts +1 -0
  73. package/dist/runtime/protocol-adherence.test.d.ts +1 -0
  74. package/dist/runtime/single-tool.test.d.ts +1 -0
  75. package/dist/runtime/token-budget.d.ts +22 -0
  76. package/dist/runtime/token-budget.test.d.ts +1 -0
  77. package/dist/runtime/tool-wrapper.d.ts +4 -5
  78. package/dist/runtime/traces.test.d.ts +1 -0
  79. package/dist/runtime/truncation.test.d.ts +1 -0
  80. package/dist/runtime/types.d.ts +41 -36
  81. package/dist/runtime/variable-recovery.test.d.ts +1 -0
  82. package/dist/runtime/vm-context.d.ts +6 -1
  83. package/dist/runtime/worker-completion.test.d.ts +1 -0
  84. package/dist/runtime-names.d.ts +4 -0
  85. package/dist/schema-Aer_W7Al.js +45 -0
  86. package/dist/schema-DBkjo0b7.cjs +68 -0
  87. package/dist/schema.d.ts +10 -0
  88. package/dist/schema.test.d.ts +1 -0
  89. package/dist/session/compactor.d.ts +51 -0
  90. package/dist/session/compactor.test.d.ts +1 -0
  91. package/dist/session/history.d.ts +36 -0
  92. package/dist/session/history.test.d.ts +1 -0
  93. package/dist/session/json.d.ts +3 -0
  94. package/dist/session/json.test.d.ts +1 -0
  95. package/dist/session/memory-codec.d.ts +9 -0
  96. package/dist/session/memory-codec.test.d.ts +1 -0
  97. package/dist/session/memory-render.d.ts +15 -0
  98. package/dist/session/memory-render.test.d.ts +1 -0
  99. package/dist/session/memory.d.ts +112 -0
  100. package/dist/session/memory.test.d.ts +1 -0
  101. package/dist/session/messages.d.ts +17 -0
  102. package/dist/session/messages.test.d.ts +1 -0
  103. package/dist/session/serialization.d.ts +34 -0
  104. package/dist/session/serialization.test.d.ts +1 -0
  105. package/dist/session/session-memory.test.d.ts +1 -0
  106. package/dist/session/session.d.ts +117 -0
  107. package/dist/session/session.test.d.ts +1 -0
  108. package/dist/{transcript.d.ts → session/transcript.d.ts} +4 -8
  109. package/dist/session/transcript.test.d.ts +1 -0
  110. package/dist/{tool-Bv8N4IPj.js → tool--gK91eez.js} +144 -92
  111. package/dist/{tool-Dy6AJpJH.cjs → tool-Da_F-N-5.cjs} +146 -94
  112. package/dist/tool.d.ts +25 -17
  113. package/dist/truncate-BSoH2-nY.js +79 -0
  114. package/dist/truncate-nV3Mxr6-.cjs +102 -0
  115. package/dist/truncate.d.ts +24 -0
  116. package/dist/truncate.test.d.ts +1 -0
  117. package/dist/types.d.ts +27 -9
  118. package/dist/{typings-3lsqCbkn.cjs → typings-C1ihexWE.cjs} +38 -193
  119. package/dist/{typings-CrBa7Tyy.js → typings-D9_aC8aq.js} +38 -175
  120. package/dist/typings-formatter.d.ts +1 -1
  121. package/dist/typings.d.ts +3 -0
  122. package/dist/{uniq-BYQ7GWwb.js → uniq-DfUeSNaX.js} +2 -2
  123. package/dist/{uniq-G872RWmE.cjs → uniq-DiXgysNV.cjs} +6 -18
  124. package/dist/{_baseIteratee-P_firB7b.js → utils-BOFzb8Ok.js} +1134 -16
  125. package/dist/{_baseIteratee-CF4qP2a8.cjs → utils-CTlsXvdj.cjs} +1281 -84
  126. package/dist/vm/drivers/node.d.ts +1 -1
  127. package/dist/vm/drivers/quickjs.d.ts +1 -1
  128. package/dist/vm/errors.d.ts +4 -4
  129. package/dist/vm/index.d.ts +3 -4
  130. package/dist/vm/instrument.d.ts +14 -6
  131. package/dist/vm/member-proxy.d.ts +4 -0
  132. package/dist/vm/member-proxy.test.d.ts +1 -0
  133. package/dist/vm/memory.test.d.ts +1 -0
  134. package/dist/vm/return-semantics.test.d.ts +1 -0
  135. package/dist/vm/types.d.ts +18 -3
  136. package/dist/{vm-BLsHw1da.js → vm-8jxt8PTK.js} +1162 -180
  137. package/dist/{vm-D6s1zF6M.cjs → vm-XuVPuW3Y.cjs} +1195 -207
  138. package/package.json +13 -6
  139. package/dist/_baseForOwn-BfWDTL8L.cjs +0 -53
  140. package/dist/_baseForOwn-CFhWe_W6.js +0 -48
  141. package/dist/_getPrototype-CG7Dxrrz.js +0 -6
  142. package/dist/_getPrototype-DQDlNVVM.cjs +0 -10
  143. package/dist/_overArg-C5Hy7oCi.cjs +0 -196
  144. package/dist/_overArg-CRYbj1NH.js +0 -155
  145. package/dist/chat.d.ts +0 -401
  146. package/dist/common-DdArNQhl.cjs +0 -643
  147. package/dist/common-pgJjFu2Y.js +0 -596
  148. package/dist/compiler/plugins/track-tool-calls.d.ts +0 -33
  149. package/dist/compiler-C-OI9sim.cjs +0 -547
  150. package/dist/compiler-CW1VjQsn.js +0 -473
  151. package/dist/component-BXS8vAwO.cjs +0 -73
  152. package/dist/component-Dq7ZLdvy.js +0 -44
  153. package/dist/component.d.ts +0 -88
  154. package/dist/component.default.d.ts +0 -268
  155. package/dist/custom-client-2V9lmzUf.js +0 -2655
  156. package/dist/custom-client-HkM1Sdzv.cjs +0 -2726
  157. package/dist/dual-modes-Cb7ThvoV.cjs +0 -3020
  158. package/dist/dual-modes-Cy0_W4O2.js +0 -2930
  159. package/dist/errors-C962uJdS.cjs +0 -220
  160. package/dist/errors-Cg1G0Awu.js +0 -161
  161. package/dist/example.d.ts +0 -45
  162. package/dist/execute-Aw4cbIx-.js +0 -1080
  163. package/dist/execute-COIHOIKR.cjs +0 -1081
  164. package/dist/exit-parser.d.ts +0 -39
  165. package/dist/handlers.d.ts +0 -10
  166. package/dist/hoist.d.ts +0 -2
  167. package/dist/isEmpty-BhJRCqIF.js +0 -52
  168. package/dist/isEmpty-LY533Wmh.cjs +0 -57
  169. package/dist/jsx-B0iYyvfr.js +0 -100
  170. package/dist/jsx-D5Y2cPo-.cjs +0 -129
  171. package/dist/jsx.d.ts +0 -11
  172. package/dist/message-stream/index.d.ts +0 -9
  173. package/dist/message-stream/instructions.d.ts +0 -22
  174. package/dist/message-stream/normalizer.d.ts +0 -21
  175. package/dist/message-stream/parser.d.ts +0 -83
  176. package/dist/message-stream/registry.d.ts +0 -14
  177. package/dist/message-stream/replayable.d.ts +0 -27
  178. package/dist/message-stream/sanitize.d.ts +0 -10
  179. package/dist/message-stream/stream.d.ts +0 -54
  180. package/dist/message-stream/types.d.ts +0 -96
  181. package/dist/message-stream/validator.d.ts +0 -23
  182. package/dist/prompts/chat-mode/system.d.ts +0 -2
  183. package/dist/prompts/chat-mode/system.md.d.ts +0 -2
  184. package/dist/prompts/chat-mode/user.d.ts +0 -2
  185. package/dist/prompts/chat-mode/user.md.d.ts +0 -2
  186. package/dist/prompts/common.d.ts +0 -6
  187. package/dist/prompts/dual-modes.d.ts +0 -2
  188. package/dist/prompts/execution-history.d.ts +0 -6
  189. package/dist/prompts/execution-state.d.ts +0 -3
  190. package/dist/prompts/protocol.d.ts +0 -18
  191. package/dist/prompts/worker-mode/system.d.ts +0 -2
  192. package/dist/prompts/worker-mode/system.md.d.ts +0 -2
  193. package/dist/prompts/worker-mode/user.d.ts +0 -2
  194. package/dist/prompts/worker-mode/user.md.d.ts +0 -2
  195. package/dist/quickjs-variant-BYhMBpwU.js +0 -45
  196. package/dist/quickjs-variant-CsIwTVFC.cjs +0 -56
  197. package/dist/rolldown-runtime-EAsCxrDo.js +0 -14
  198. package/dist/runtime/interpret-result.d.ts +0 -22
  199. package/dist/snapshots.d.ts +0 -249
  200. package/dist/stack-traces-BIE_5Xwf.js +0 -21
  201. package/dist/stack-traces-ntw_qhoy.cjs +0 -26
  202. package/dist/truncator-CLkouTCO.cjs +0 -276
  203. package/dist/truncator-DZqEqnpD.js +0 -253
  204. package/dist/truncator.d.ts +0 -118
  205. package/dist/utils-3ESwP3yg.cjs +0 -1075
  206. package/dist/utils-UBeAFeEI.js +0 -950
  207. /package/dist/{citations.d.ts → chat/citations.d.ts} +0 -0
  208. /package/dist/{citations.test.d.ts → chat/citations.test.d.ts} +0 -0
  209. /package/dist/{component.default.test.d.ts → chat/component.default.test.d.ts} +0 -0
  210. /package/dist/{compiler/plugins/track-tool-calls.test.d.ts → chat/component.test.d.ts} +0 -0
  211. /package/dist/{example.test.d.ts → chat/response.test.d.ts} +0 -0
  212. /package/dist/{exit-parser.test.d.ts → compiler/plugins/dynamic-code.test.d.ts} +0 -0
  213. /package/dist/{handlers.test.d.ts → compiler/plugins/tool-resolution.test.d.ts} +0 -0
  214. /package/dist/{hoist.test.d.ts → errors/catalog.test.d.ts} +0 -0
  215. /package/dist/{message-stream/instructions.test.d.ts → exit.test.d.ts} +0 -0
  216. /package/dist/{message-stream/normalizer.test.d.ts → inspection.test.d.ts} +0 -0
  217. /package/dist/{message-stream/parser.test.d.ts → prompts/native.test.d.ts} +0 -0
  218. /package/dist/{message-stream/stream.test.d.ts → result.test.d.ts} +0 -0
  219. /package/dist/{message-stream/validator.test.d.ts → runtime/chat-delivery.test.d.ts} +0 -0
  220. /package/dist/{prompts/common.test.d.ts → runtime/citations.test.d.ts} +0 -0
  221. /package/dist/{prompts/protocol.test.d.ts → runtime/compatibility-regressions.test.d.ts} +0 -0
  222. /package/dist/runtime/{interpret-result.test.d.ts → context-registration.test.d.ts} +0 -0
  223. /package/dist/{transcript.test.d.ts → runtime/error-recovery.test.d.ts} +0 -0
  224. /package/dist/{truncator.test.d.ts → runtime/errors.test.d.ts} +0 -0
@@ -1,11 +1,10 @@
1
- import { n as __exportAll } from "./rolldown-runtime-EAsCxrDo.js";
2
- import { a as getMultilineComment, f as toPropertyKey, n as escapeString } from "./utils-UBeAFeEI.js";
3
- import { r as CodeFormattingError } from "./errors-Cg1G0Awu.js";
4
- import { z } from "@bpinternal/zui";
1
+ import { Y as __exportAll, d as toPropertyKey, i as getMultilineComment, n as fromJSONSchemaCompat } from "./utils-BOFzb8Ok.js";
2
+ import { b as InvalidConfigurationError, c as CodeFormattingError } from "./errors-H4JJFH3S.js";
3
+ import { transforms, z } from "@bpinternal/zui";
5
4
  //#region src/typings-formatter.ts
6
5
  /**
7
6
  * A minimal, dependency-free formatter for the TypeScript typings generated by
8
- * llmz (typings.ts, objects.ts, hoist.ts). It supports only the small grammar
7
+ * llmz (typings.ts, objects.ts). It supports only the small grammar
9
8
  * those generators emit — type expressions, `declare const` / `declare function`
10
9
  * declarations, `type` aliases and `export namespace` blocks — and produces
11
10
  * prettier-like output: 80 columns, 2-space indent, no semicolons in broken
@@ -427,7 +426,7 @@ function breakGroup(p, g, level, tailWidth = 0) {
427
426
  });
428
427
  return;
429
428
  }
430
- const separator = g.open === "(" || g.open === "[" ? "," : usedComma ? "," : null;
429
+ const separator = g.open === "(" || g.open === "[" || usedComma ? "," : null;
431
430
  const trailingSeparator = g.open === "(" || g.open === "[";
432
431
  p.atom({
433
432
  kind: "open",
@@ -566,178 +565,42 @@ async function formatTypings(typings, options) {
566
565
  }
567
566
  //#endregion
568
567
  //#region src/typings.ts
569
- var typings_exports = /* @__PURE__ */ __exportAll({ getTypings: () => getTypings });
570
- const Primitives = [
571
- "string",
572
- "number",
573
- "boolean",
574
- "unknown",
575
- "void",
576
- "any",
577
- "null",
578
- "undefined",
579
- "never",
580
- "bigint",
581
- "symbol",
582
- "object"
583
- ];
584
- const LARGE_DECLARATION_LINES = 5;
585
- const isPrimitive = (type) => Primitives.includes(type);
586
- const isArrayOfPrimitives = (type) => Primitives.map((p) => `${p}[]`).includes(type);
587
- const stripSpaces = (typings) => typings.replace(/ +/g, " ").trim();
588
- var KeyValue = class {
589
- key;
590
- value;
591
- constructor(key, value) {
592
- this.key = key;
593
- this.value = value;
594
- }
595
- };
596
- var FnParameters = class {
597
- schema;
598
- constructor(schema) {
599
- this.schema = schema;
600
- }
601
- };
602
- var FnReturn = class {
603
- schema;
604
- constructor(schema) {
605
- this.schema = schema;
606
- }
607
- };
608
- var Declaration = class {
609
- schema;
610
- identifier;
611
- constructor(schema, identifier) {
612
- this.schema = schema;
613
- this.identifier = identifier;
614
- }
615
- };
616
- async function getTypings(schema, options) {
617
- options ??= {};
618
- options.declaration ??= false;
619
- let wrappedSchema = schema;
620
- if ((options === null || options === void 0 ? void 0 : options.declaration) && z.is.zuiType(schema)) {
621
- const title = "title" in schema.ui ? schema.ui.title : null;
622
- if (!title) throw new Error("Only schemas with \"title\" Zui property can be declared.");
623
- wrappedSchema = new Declaration(schema, title);
568
+ var typings_exports = /* @__PURE__ */ __exportAll({
569
+ getTypings: () => getTypings,
570
+ schemaToTypeScript: () => schemaToTypeScript
571
+ });
572
+ /** One schema renderer for API inputs, results, and memory properties. */
573
+ function schemaToTypeScript(schema) {
574
+ if (z.is.zuiDefault(schema)) return schemaToTypeScript(schema._def.innerType);
575
+ const options = { treatDefaultAsOptional: true };
576
+ try {
577
+ return transforms.toTypescriptType(schema, options);
578
+ } catch {
579
+ const normalized = fromJSONSchemaCompat(transforms.toJSONSchemaLegacy(schema));
580
+ return transforms.toTypescriptType(normalized, options);
624
581
  }
625
- let dts = await sUnwrapZodRecursive(wrappedSchema, { ...options });
626
- dts = await formatTypings(dts, { throwOnError: false });
627
- return dts;
628
582
  }
629
- async function sUnwrapZodRecursive(schema, options) {
630
- return sUnwrapZod(schema, options);
583
+ function describeParameter(parameter, index) {
584
+ var _parameter$ui;
585
+ const name = toPropertyKey(((_parameter$ui = parameter.ui) === null || _parameter$ui === void 0 ? void 0 : _parameter$ui.title) ?? `arg${index}`);
586
+ const optional = z.is.zuiOptional(parameter) || z.is.zuiDefault(parameter);
587
+ let value = parameter;
588
+ while (z.is.zuiOptional(value) || z.is.zuiDefault(value)) value = value._def.innerType;
589
+ return `${getMultilineComment(parameter.description)}${name}${optional ? "?" : ""}: ${schemaToTypeScript(value.describe(""))}`;
631
590
  }
632
- async function sUnwrapZod(schema, options) {
633
- const newOptions = {
634
- ...options,
635
- declaration: false,
636
- parent: schema
637
- };
638
- if (schema instanceof Declaration) {
639
- const description = getMultilineComment(schema.schema.description);
640
- const typings = await sUnwrapZodRecursive(schema.schema.describe(""), {
641
- ...newOptions,
642
- declaration: true
643
- });
644
- const closingTag = typings.split("\n").length >= LARGE_DECLARATION_LINES ? `// end of ${schema.identifier}` : "";
645
- if (z.is.zuiFunction(schema.schema)) return stripSpaces(`${description}
646
- declare function ${schema.identifier}${typings};${closingTag}`);
647
- return stripSpaces(`${description}
648
- declare const ${schema.identifier}: ${typings};${closingTag}`);
649
- }
650
- if (schema instanceof KeyValue) {
651
- if (z.is.zuiOptional(schema.value) || z.is.zuiDefault(schema.value)) {
652
- let innerType = schema.value._def.innerType;
653
- if (z.is.zuiType(innerType) && !innerType.description && schema.value.description) innerType = innerType === null || innerType === void 0 ? void 0 : innerType.describe(schema.value.description);
654
- const optionalToken = schema.key.endsWith("?") ? "" : "?";
655
- return sUnwrapZodRecursive(new KeyValue(schema.key + optionalToken, innerType), newOptions);
656
- }
657
- const description = getMultilineComment(schema.value._def.description || schema.value.description);
658
- const delimiter = (description === null || description === void 0 ? void 0 : description.trim().length) > 0 ? "\n" : "";
659
- const withoutDesc = schema.value.describe("");
660
- return `${delimiter}${description}${delimiter}${schema.key}: ${await sUnwrapZodRecursive(withoutDesc, newOptions)}${delimiter}`;
661
- }
662
- if (schema instanceof FnParameters) {
663
- if (z.is.zuiTuple(schema.schema)) {
664
- let args = "";
665
- for (let i = 0; i < schema.schema.items.length; i++) {
666
- var _schema$schema$items$;
667
- const argName = ((_schema$schema$items$ = schema.schema.items[i]) === null || _schema$schema$items$ === void 0 || (_schema$schema$items$ = _schema$schema$items$.ui) === null || _schema$schema$items$ === void 0 ? void 0 : _schema$schema$items$.title) ?? `arg${i}`;
668
- const item = schema.schema.items[i];
669
- args += `${await sUnwrapZodRecursive(new KeyValue(toPropertyKey(argName), item), newOptions)}, `;
670
- }
671
- return args;
672
- }
673
- const isLiteral = z.is.zuiLiteral(schema.schema.naked());
674
- const typings = (await sUnwrapZodRecursive(schema.schema, newOptions)).trim();
675
- if (typings.startsWith("{") && typings.endsWith("}") || typings.startsWith("[") && typings.endsWith("]") || typings.startsWith("(") && typings.endsWith(")") || typings.startsWith("Array<") && typings.endsWith(">") || typings.startsWith("Record<") && typings.endsWith(">") || isArrayOfPrimitives(typings) || isLiteral) return `args: ${typings}`;
676
- else return typings;
677
- }
678
- if (schema instanceof FnReturn) {
679
- if (z.is.zuiOptional(schema.schema)) return `${await sUnwrapZodRecursive(schema.schema.unwrap(), newOptions)} | undefined`;
680
- return sUnwrapZodRecursive(schema.schema, newOptions);
681
- }
682
- if (schema === null) return "unknown";
683
- if (z.is.zuiDefault(schema)) return sUnwrapZodRecursive(schema._def.innerType, options);
684
- if (z.is.zuiVoid(schema)) return "void";
685
- if (z.is.zuiUnknown(schema)) return "unknown";
686
- if (z.is.zuiAny(schema)) return "any";
687
- if (z.is.zuiPromise(schema)) return `Promise<${await sUnwrapZodRecursive(schema.unwrap(), newOptions)}>`;
591
+ /** Preserve declaration names and parameter labels; Zui renders every value type. */
592
+ async function getTypings(schema, options = {}) {
593
+ var _schema$ui;
594
+ if (!options.declaration) return formatTypings(schemaToTypeScript(schema), { throwOnError: false });
595
+ const title = (_schema$ui = schema.ui) === null || _schema$ui === void 0 ? void 0 : _schema$ui.title;
596
+ if (typeof title !== "string" || !title) throw new InvalidConfigurationError("Only schemas with \"title\" Zui property can be declared.");
597
+ const description = getMultilineComment(schema.description);
598
+ let declaration;
688
599
  if (z.is.zuiFunction(schema)) {
689
- const description = getMultilineComment(schema._def.description);
690
- const input = await sUnwrapZodRecursive(new FnParameters(schema._def.args), newOptions);
691
- const output = await sUnwrapZodRecursive(new FnReturn(schema._def.returns), newOptions);
692
- if (options === null || options === void 0 ? void 0 : options.declaration) return `${description}
693
- (${input}): ${output}`;
694
- return `${description}
695
- (${input}) => ${output}`;
696
- }
697
- if (z.is.zuiArray(schema)) {
698
- const item = await sUnwrapZodRecursive(schema._def.type, newOptions);
699
- if (isPrimitive(item)) return `${item}[]`;
700
- return `Array<${item}>`;
701
- }
702
- if (z.is.zuiEnum(schema)) return schema._def.values.map(escapeString).join(" | ");
703
- if (z.is.zuiTuple(schema)) {
704
- if (schema.items.length === 0) return "[]";
705
- return `[${(await Promise.all(schema.items.map((i) => sUnwrapZodRecursive(i, newOptions)))).join(", ")}]`;
706
- }
707
- if (z.is.zuiNullable(schema)) return `${await sUnwrapZodRecursive(schema.unwrap(), options)} | null`;
708
- if (z.is.zuiOptional(schema)) {
709
- if ((options === null || options === void 0 ? void 0 : options.declaration) || z.is.zuiType(options === null || options === void 0 ? void 0 : options.parent) && options.parent.typeName === "ZodRecord") return `${await sUnwrapZodRecursive(schema._def.innerType, newOptions)} | undefined`;
710
- const optionalToken = options.parent instanceof KeyValue ? "| undefined" : "";
711
- return `${await sUnwrapZodRecursive(schema._def.innerType, newOptions)}${optionalToken}`;
712
- }
713
- if (z.is.zuiObject(schema)) return `{ ${(await Promise.all(Object.entries(schema.shape).map(async ([key, value]) => {
714
- if (z.is.zuiType(value)) return sUnwrapZodRecursive(new KeyValue(toPropertyKey(key), value), newOptions);
715
- return `${key}: unknown`;
716
- }))).join("; ")} }`;
717
- if (z.is.zuiString(schema)) return `${getMultilineComment(schema._def.description)} string`.trim();
718
- if (z.is.zuiUnion(schema)) return `${getMultilineComment(schema._def.description)}
719
- ${(await Promise.all(schema.options.map(async (option) => {
720
- return sUnwrapZodRecursive(option, newOptions);
721
- }))).join(" | ")}`;
722
- if (z.is.zuiLiteral(schema)) return `${getMultilineComment(schema._def.description)}
723
- ${typeof schema.value === "string" ? escapeString(schema.value) : String(schema.value)}`.trim();
724
- if (z.is.zuiNumber(schema)) return `${getMultilineComment(schema._def.description)} number`.trim();
725
- if (z.is.zuiBoolean(schema)) return `${getMultilineComment(schema._def.description)} boolean`.trim();
726
- if (z.is.zuiCatch(schema)) return sUnwrapZodRecursive(schema.removeCatch(), newOptions);
727
- if (z.is.zuiLazy(schema)) return sUnwrapZodRecursive(schema._def.getter(), newOptions);
728
- if (z.is.zuiRecord(schema)) return `${getMultilineComment(schema._def.description)} { [key: (${await sUnwrapZodRecursive(schema._def.keyType, newOptions)})]: (${await sUnwrapZodRecursive(schema._def.valueType, newOptions)}) }`;
729
- try {
730
- let typings = schema === null || schema === void 0 ? void 0 : schema.toTypescriptType({ treatDefaultAsOptional: true });
731
- typings ??= "unknown";
732
- return stripSpaces(typings);
733
- } catch (error) {
734
- console.error("Error in sUnwrapZod", {
735
- error,
736
- schema,
737
- parent: options === null || options === void 0 ? void 0 : options.parent
738
- });
739
- return "unknown";
740
- }
600
+ const input = schema.parameters();
601
+ declaration = `declare function ${title}(${z.is.zuiTuple(input) ? input.items.map(describeParameter).join(", ") : `args: ${schemaToTypeScript(input)}`}): ${schemaToTypeScript(schema.returnType())};`;
602
+ } else declaration = `declare const ${title}: ${schemaToTypeScript(schema.describe(""))};`;
603
+ return formatTypings(`${description}\n${declaration}`, { throwOnError: false });
741
604
  }
742
605
  //#endregion
743
- export { isPunct as a, isGroup as i, typings_exports as n, parse as o, formatTypings as r, tokenize as s, getTypings as t };
606
+ export { formatTypings as i, schemaToTypeScript as n, typings_exports as r, getTypings as t };
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * A minimal, dependency-free formatter for the TypeScript typings generated by
3
- * llmz (typings.ts, objects.ts, hoist.ts). It supports only the small grammar
3
+ * llmz (typings.ts, objects.ts). It supports only the small grammar
4
4
  * those generators emit — type expressions, `declare const` / `declare function`
5
5
  * declarations, `type` aliases and `export namespace` blocks — and produces
6
6
  * prettier-like output: 80 columns, 2-space indent, no semicolons in broken
package/dist/typings.d.ts CHANGED
@@ -2,4 +2,7 @@ import { z } from '@bpinternal/zui';
2
2
  export type Options = {
3
3
  declaration?: boolean;
4
4
  };
5
+ /** One schema renderer for API inputs, results, and memory properties. */
6
+ export declare function schemaToTypeScript(schema: z.Schema): string;
7
+ /** Preserve declaration names and parameter labels; Zui renders every value type. */
5
8
  export declare function getTypings(schema: z.Schema, options?: Options): Promise<string>;
@@ -1,4 +1,4 @@
1
- import { a as cacheHas, l as Set, o as SetCache, r as setToArray } from "./_baseIteratee-P_firB7b.js";
1
+ import { S as Set, _ as setToArray, v as cacheHas, y as SetCache } from "./utils-BOFzb8Ok.js";
2
2
  //#region ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/noop.js
3
3
  /**
4
4
  * This method returns `undefined`.
@@ -180,4 +180,4 @@ function uniq(array) {
180
180
  return array && array.length ? baseUniq(array) : [];
181
181
  }
182
182
  //#endregion
183
- export { baseUniq as n, noop as r, uniq as t };
183
+ export { uniq as t };
@@ -1,4 +1,4 @@
1
- const require__baseIteratee = require("./_baseIteratee-CF4qP2a8.cjs");
1
+ const require_utils = require("./utils-CTlsXvdj.cjs");
2
2
  //#region ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/noop.js
3
3
  /**
4
4
  * This method returns `undefined`.
@@ -113,8 +113,8 @@ function arrayIncludesWith(array, value, comparator) {
113
113
  * @param {Array} values The values to add to the set.
114
114
  * @returns {Object} Returns the new set.
115
115
  */
116
- var createSet = !(require__baseIteratee.Set && 1 / require__baseIteratee.setToArray(new require__baseIteratee.Set([, -0]))[1] == 1 / 0) ? noop : function(values) {
117
- return new require__baseIteratee.Set(values);
116
+ var createSet = !(require_utils.Set && 1 / require_utils.setToArray(new require_utils.Set([, -0]))[1] == 1 / 0) ? noop : function(values) {
117
+ return new require_utils.Set(values);
118
118
  };
119
119
  //#endregion
120
120
  //#region ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseUniq.js
@@ -136,10 +136,10 @@ function baseUniq(array, iteratee, comparator) {
136
136
  includes = arrayIncludesWith;
137
137
  } else if (length >= LARGE_ARRAY_SIZE) {
138
138
  var set = iteratee ? null : createSet(array);
139
- if (set) return require__baseIteratee.setToArray(set);
139
+ if (set) return require_utils.setToArray(set);
140
140
  isCommon = false;
141
- includes = require__baseIteratee.cacheHas;
142
- seen = new require__baseIteratee.SetCache();
141
+ includes = require_utils.cacheHas;
142
+ seen = new require_utils.SetCache();
143
143
  } else seen = iteratee ? [] : result;
144
144
  outer: while (++index < length) {
145
145
  var value = array[index], computed = iteratee ? iteratee(value) : value;
@@ -180,18 +180,6 @@ function uniq(array) {
180
180
  return array && array.length ? baseUniq(array) : [];
181
181
  }
182
182
  //#endregion
183
- Object.defineProperty(exports, "baseUniq", {
184
- enumerable: true,
185
- get: function() {
186
- return baseUniq;
187
- }
188
- });
189
- Object.defineProperty(exports, "noop", {
190
- enumerable: true,
191
- get: function() {
192
- return noop;
193
- }
194
- });
195
183
  Object.defineProperty(exports, "uniq", {
196
184
  enumerable: true,
197
185
  get: function() {