marlarky 1.0.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.
Files changed (274) hide show
  1. package/README.md +489 -0
  2. package/dist/adapters/faker-js-adapter.d.ts +44 -0
  3. package/dist/adapters/faker-js-adapter.d.ts.map +1 -0
  4. package/dist/adapters/faker-js-adapter.js +46 -0
  5. package/dist/adapters/faker-js-adapter.js.map +1 -0
  6. package/dist/adapters/index.d.ts +3 -0
  7. package/dist/adapters/index.d.ts.map +1 -0
  8. package/dist/adapters/index.js +3 -0
  9. package/dist/adapters/index.js.map +1 -0
  10. package/dist/adapters/simple-faker-adapter.d.ts +22 -0
  11. package/dist/adapters/simple-faker-adapter.d.ts.map +1 -0
  12. package/dist/adapters/simple-faker-adapter.js +54 -0
  13. package/dist/adapters/simple-faker-adapter.js.map +1 -0
  14. package/dist/cli.d.ts +7 -0
  15. package/dist/cli.d.ts.map +1 -0
  16. package/dist/cli.js +588 -0
  17. package/dist/cli.js.map +1 -0
  18. package/dist/defaults/index.d.ts +2 -0
  19. package/dist/defaults/index.d.ts.map +1 -0
  20. package/dist/defaults/index.js +2 -0
  21. package/dist/defaults/index.js.map +1 -0
  22. package/dist/defaults/word-lists.d.ts +22 -0
  23. package/dist/defaults/word-lists.d.ts.map +1 -0
  24. package/dist/defaults/word-lists.js +124 -0
  25. package/dist/defaults/word-lists.js.map +1 -0
  26. package/dist/generator/index.d.ts +2 -0
  27. package/dist/generator/index.d.ts.map +1 -0
  28. package/dist/generator/index.js +2 -0
  29. package/dist/generator/index.js.map +1 -0
  30. package/dist/generator/text-generator.d.ts +93 -0
  31. package/dist/generator/text-generator.d.ts.map +1 -0
  32. package/dist/generator/text-generator.js +411 -0
  33. package/dist/generator/text-generator.js.map +1 -0
  34. package/dist/generator/text-generator.test.d.ts +2 -0
  35. package/dist/generator/text-generator.test.d.ts.map +1 -0
  36. package/dist/generator/text-generator.test.js +151 -0
  37. package/dist/generator/text-generator.test.js.map +1 -0
  38. package/dist/grammar/index.d.ts +5 -0
  39. package/dist/grammar/index.d.ts.map +1 -0
  40. package/dist/grammar/index.js +3 -0
  41. package/dist/grammar/index.js.map +1 -0
  42. package/dist/grammar/phrase-builders.d.ts +72 -0
  43. package/dist/grammar/phrase-builders.d.ts.map +1 -0
  44. package/dist/grammar/phrase-builders.js +241 -0
  45. package/dist/grammar/phrase-builders.js.map +1 -0
  46. package/dist/grammar/sentence-templates.d.ts +67 -0
  47. package/dist/grammar/sentence-templates.d.ts.map +1 -0
  48. package/dist/grammar/sentence-templates.js +272 -0
  49. package/dist/grammar/sentence-templates.js.map +1 -0
  50. package/dist/index.d.ts +17 -0
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +40 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/interfaces/faker-adapter.d.ts +25 -0
  55. package/dist/interfaces/faker-adapter.d.ts.map +1 -0
  56. package/dist/interfaces/faker-adapter.js +2 -0
  57. package/dist/interfaces/faker-adapter.js.map +1 -0
  58. package/dist/interfaces/index.d.ts +4 -0
  59. package/dist/interfaces/index.d.ts.map +1 -0
  60. package/dist/interfaces/index.js +2 -0
  61. package/dist/interfaces/index.js.map +1 -0
  62. package/dist/interfaces/lexicon-store.d.ts +39 -0
  63. package/dist/interfaces/lexicon-store.d.ts.map +1 -0
  64. package/dist/interfaces/lexicon-store.js +2 -0
  65. package/dist/interfaces/lexicon-store.js.map +1 -0
  66. package/dist/interfaces/rng.d.ts +25 -0
  67. package/dist/interfaces/rng.d.ts.map +1 -0
  68. package/dist/interfaces/rng.js +2 -0
  69. package/dist/interfaces/rng.js.map +1 -0
  70. package/dist/lexicon/index.d.ts +4 -0
  71. package/dist/lexicon/index.d.ts.map +1 -0
  72. package/dist/lexicon/index.js +4 -0
  73. package/dist/lexicon/index.js.map +1 -0
  74. package/dist/lexicon/loader.d.ts +24 -0
  75. package/dist/lexicon/loader.d.ts.map +1 -0
  76. package/dist/lexicon/loader.js +47 -0
  77. package/dist/lexicon/loader.js.map +1 -0
  78. package/dist/lexicon/store.d.ts +39 -0
  79. package/dist/lexicon/store.d.ts.map +1 -0
  80. package/dist/lexicon/store.js +291 -0
  81. package/dist/lexicon/store.js.map +1 -0
  82. package/dist/lexicon/validator.d.ts +10 -0
  83. package/dist/lexicon/validator.d.ts.map +1 -0
  84. package/dist/lexicon/validator.js +273 -0
  85. package/dist/lexicon/validator.js.map +1 -0
  86. package/dist/morphology/articles.d.ts +17 -0
  87. package/dist/morphology/articles.d.ts.map +1 -0
  88. package/dist/morphology/articles.js +66 -0
  89. package/dist/morphology/articles.js.map +1 -0
  90. package/dist/morphology/articles.test.d.ts +2 -0
  91. package/dist/morphology/articles.test.d.ts.map +1 -0
  92. package/dist/morphology/articles.test.js +56 -0
  93. package/dist/morphology/articles.test.js.map +1 -0
  94. package/dist/morphology/conjugate.d.ts +46 -0
  95. package/dist/morphology/conjugate.d.ts.map +1 -0
  96. package/dist/morphology/conjugate.js +337 -0
  97. package/dist/morphology/conjugate.js.map +1 -0
  98. package/dist/morphology/conjugate.test.d.ts +2 -0
  99. package/dist/morphology/conjugate.test.d.ts.map +1 -0
  100. package/dist/morphology/conjugate.test.js +168 -0
  101. package/dist/morphology/conjugate.test.js.map +1 -0
  102. package/dist/morphology/index.d.ts +6 -0
  103. package/dist/morphology/index.d.ts.map +1 -0
  104. package/dist/morphology/index.js +9 -0
  105. package/dist/morphology/index.js.map +1 -0
  106. package/dist/morphology/normalize.d.ts +52 -0
  107. package/dist/morphology/normalize.d.ts.map +1 -0
  108. package/dist/morphology/normalize.js +127 -0
  109. package/dist/morphology/normalize.js.map +1 -0
  110. package/dist/morphology/pluralize.d.ts +17 -0
  111. package/dist/morphology/pluralize.d.ts.map +1 -0
  112. package/dist/morphology/pluralize.js +186 -0
  113. package/dist/morphology/pluralize.js.map +1 -0
  114. package/dist/morphology/pluralize.test.d.ts +2 -0
  115. package/dist/morphology/pluralize.test.d.ts.map +1 -0
  116. package/dist/morphology/pluralize.test.js +86 -0
  117. package/dist/morphology/pluralize.test.js.map +1 -0
  118. package/dist/providers/index.d.ts +2 -0
  119. package/dist/providers/index.d.ts.map +1 -0
  120. package/dist/providers/index.js +2 -0
  121. package/dist/providers/index.js.map +1 -0
  122. package/dist/providers/word-provider.d.ts +125 -0
  123. package/dist/providers/word-provider.d.ts.map +1 -0
  124. package/dist/providers/word-provider.js +266 -0
  125. package/dist/providers/word-provider.js.map +1 -0
  126. package/dist/rng/index.d.ts +2 -0
  127. package/dist/rng/index.d.ts.map +1 -0
  128. package/dist/rng/index.js +2 -0
  129. package/dist/rng/index.js.map +1 -0
  130. package/dist/rng/seedable-rng.d.ts +19 -0
  131. package/dist/rng/seedable-rng.d.ts.map +1 -0
  132. package/dist/rng/seedable-rng.js +77 -0
  133. package/dist/rng/seedable-rng.js.map +1 -0
  134. package/dist/rng/seedable-rng.test.d.ts +2 -0
  135. package/dist/rng/seedable-rng.test.d.ts.map +1 -0
  136. package/dist/rng/seedable-rng.test.js +165 -0
  137. package/dist/rng/seedable-rng.test.js.map +1 -0
  138. package/dist/rules/index.d.ts +3 -0
  139. package/dist/rules/index.d.ts.map +1 -0
  140. package/dist/rules/index.js +2 -0
  141. package/dist/rules/index.js.map +1 -0
  142. package/dist/rules/rule-engine.d.ts +78 -0
  143. package/dist/rules/rule-engine.d.ts.map +1 -0
  144. package/dist/rules/rule-engine.js +271 -0
  145. package/dist/rules/rule-engine.js.map +1 -0
  146. package/dist/transforms/config-merge.d.ts +19 -0
  147. package/dist/transforms/config-merge.d.ts.map +1 -0
  148. package/dist/transforms/config-merge.js +88 -0
  149. package/dist/transforms/config-merge.js.map +1 -0
  150. package/dist/transforms/config-merge.test.d.ts +2 -0
  151. package/dist/transforms/config-merge.test.d.ts.map +1 -0
  152. package/dist/transforms/config-merge.test.js +91 -0
  153. package/dist/transforms/config-merge.test.js.map +1 -0
  154. package/dist/transforms/default-registry.d.ts +10 -0
  155. package/dist/transforms/default-registry.d.ts.map +1 -0
  156. package/dist/transforms/default-registry.js +17 -0
  157. package/dist/transforms/default-registry.js.map +1 -0
  158. package/dist/transforms/index.d.ts +15 -0
  159. package/dist/transforms/index.d.ts.map +1 -0
  160. package/dist/transforms/index.js +20 -0
  161. package/dist/transforms/index.js.map +1 -0
  162. package/dist/transforms/pipeline.d.ts +28 -0
  163. package/dist/transforms/pipeline.d.ts.map +1 -0
  164. package/dist/transforms/pipeline.js +176 -0
  165. package/dist/transforms/pipeline.js.map +1 -0
  166. package/dist/transforms/pipeline.test.d.ts +2 -0
  167. package/dist/transforms/pipeline.test.d.ts.map +1 -0
  168. package/dist/transforms/pipeline.test.js +175 -0
  169. package/dist/transforms/pipeline.test.js.map +1 -0
  170. package/dist/transforms/protection.d.ts +16 -0
  171. package/dist/transforms/protection.d.ts.map +1 -0
  172. package/dist/transforms/protection.js +97 -0
  173. package/dist/transforms/protection.js.map +1 -0
  174. package/dist/transforms/protection.test.d.ts +2 -0
  175. package/dist/transforms/protection.test.d.ts.map +1 -0
  176. package/dist/transforms/protection.test.js +79 -0
  177. package/dist/transforms/protection.test.js.map +1 -0
  178. package/dist/transforms/registry.d.ts +25 -0
  179. package/dist/transforms/registry.d.ts.map +1 -0
  180. package/dist/transforms/registry.js +32 -0
  181. package/dist/transforms/registry.js.map +1 -0
  182. package/dist/transforms/registry.test.d.ts +2 -0
  183. package/dist/transforms/registry.test.d.ts.map +1 -0
  184. package/dist/transforms/registry.test.js +64 -0
  185. package/dist/transforms/registry.test.js.map +1 -0
  186. package/dist/transforms/tokenizer.d.ts +26 -0
  187. package/dist/transforms/tokenizer.d.ts.map +1 -0
  188. package/dist/transforms/tokenizer.js +137 -0
  189. package/dist/transforms/tokenizer.js.map +1 -0
  190. package/dist/transforms/tokenizer.test.d.ts +2 -0
  191. package/dist/transforms/tokenizer.test.d.ts.map +1 -0
  192. package/dist/transforms/tokenizer.test.js +85 -0
  193. package/dist/transforms/tokenizer.test.js.map +1 -0
  194. package/dist/transforms/transforms/biz-jargon.d.ts +7 -0
  195. package/dist/transforms/transforms/biz-jargon.d.ts.map +1 -0
  196. package/dist/transforms/transforms/biz-jargon.js +117 -0
  197. package/dist/transforms/transforms/biz-jargon.js.map +1 -0
  198. package/dist/transforms/transforms/emoji.d.ts +7 -0
  199. package/dist/transforms/transforms/emoji.d.ts.map +1 -0
  200. package/dist/transforms/transforms/emoji.js +127 -0
  201. package/dist/transforms/transforms/emoji.js.map +1 -0
  202. package/dist/transforms/transforms/index.d.ts +17 -0
  203. package/dist/transforms/transforms/index.d.ts.map +1 -0
  204. package/dist/transforms/transforms/index.js +37 -0
  205. package/dist/transforms/transforms/index.js.map +1 -0
  206. package/dist/transforms/transforms/leet.d.ts +7 -0
  207. package/dist/transforms/transforms/leet.d.ts.map +1 -0
  208. package/dist/transforms/transforms/leet.js +109 -0
  209. package/dist/transforms/transforms/leet.js.map +1 -0
  210. package/dist/transforms/transforms/mock-case.d.ts +7 -0
  211. package/dist/transforms/transforms/mock-case.d.ts.map +1 -0
  212. package/dist/transforms/transforms/mock-case.js +116 -0
  213. package/dist/transforms/transforms/mock-case.js.map +1 -0
  214. package/dist/transforms/transforms/pig-latin.d.ts +7 -0
  215. package/dist/transforms/transforms/pig-latin.d.ts.map +1 -0
  216. package/dist/transforms/transforms/pig-latin.js +132 -0
  217. package/dist/transforms/transforms/pig-latin.js.map +1 -0
  218. package/dist/transforms/transforms/pig-latin.test.d.ts +2 -0
  219. package/dist/transforms/transforms/pig-latin.test.d.ts.map +1 -0
  220. package/dist/transforms/transforms/pig-latin.test.js +77 -0
  221. package/dist/transforms/transforms/pig-latin.test.js.map +1 -0
  222. package/dist/transforms/transforms/pirate.d.ts +7 -0
  223. package/dist/transforms/transforms/pirate.d.ts.map +1 -0
  224. package/dist/transforms/transforms/pirate.js +150 -0
  225. package/dist/transforms/transforms/pirate.js.map +1 -0
  226. package/dist/transforms/transforms/redact.d.ts +7 -0
  227. package/dist/transforms/transforms/redact.d.ts.map +1 -0
  228. package/dist/transforms/transforms/redact.js +109 -0
  229. package/dist/transforms/transforms/redact.js.map +1 -0
  230. package/dist/transforms/transforms/reverse-words.d.ts +7 -0
  231. package/dist/transforms/transforms/reverse-words.d.ts.map +1 -0
  232. package/dist/transforms/transforms/reverse-words.js +88 -0
  233. package/dist/transforms/transforms/reverse-words.js.map +1 -0
  234. package/dist/transforms/transforms/transforms.test.d.ts +11 -0
  235. package/dist/transforms/transforms/transforms.test.d.ts.map +1 -0
  236. package/dist/transforms/transforms/transforms.test.js +489 -0
  237. package/dist/transforms/transforms/transforms.test.js.map +1 -0
  238. package/dist/transforms/transforms/ubbi-dubbi.d.ts +7 -0
  239. package/dist/transforms/transforms/ubbi-dubbi.d.ts.map +1 -0
  240. package/dist/transforms/transforms/ubbi-dubbi.js +120 -0
  241. package/dist/transforms/transforms/ubbi-dubbi.js.map +1 -0
  242. package/dist/transforms/transforms/uwu.d.ts +7 -0
  243. package/dist/transforms/transforms/uwu.d.ts.map +1 -0
  244. package/dist/transforms/transforms/uwu.js +106 -0
  245. package/dist/transforms/transforms/uwu.js.map +1 -0
  246. package/dist/transforms/types.d.ts +159 -0
  247. package/dist/transforms/types.d.ts.map +1 -0
  248. package/dist/transforms/types.js +22 -0
  249. package/dist/transforms/types.js.map +1 -0
  250. package/dist/types/api.d.ts +158 -0
  251. package/dist/types/api.d.ts.map +1 -0
  252. package/dist/types/api.js +6 -0
  253. package/dist/types/api.js.map +1 -0
  254. package/dist/types/config.d.ts +86 -0
  255. package/dist/types/config.d.ts.map +1 -0
  256. package/dist/types/config.js +66 -0
  257. package/dist/types/config.js.map +1 -0
  258. package/dist/types/context.d.ts +74 -0
  259. package/dist/types/context.d.ts.map +1 -0
  260. package/dist/types/context.js +83 -0
  261. package/dist/types/context.js.map +1 -0
  262. package/dist/types/index.d.ts +7 -0
  263. package/dist/types/index.d.ts.map +1 -0
  264. package/dist/types/index.js +3 -0
  265. package/dist/types/index.js.map +1 -0
  266. package/dist/types/lexicon.d.ts +247 -0
  267. package/dist/types/lexicon.d.ts.map +1 -0
  268. package/dist/types/lexicon.js +6 -0
  269. package/dist/types/lexicon.js.map +1 -0
  270. package/examples/basic-usage.ts +48 -0
  271. package/examples/corporate-lexicon.ts +71 -0
  272. package/examples/lexicons/corporate-min.json +200 -0
  273. package/examples/with-tracing.ts +85 -0
  274. package/package.json +70 -0
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Default Curated Word Lists
3
+ * Used when no lexicon is provided or as fallback
4
+ */
5
+ // Common nouns (countable)
6
+ export const DEFAULT_NOUNS = [
7
+ 'idea', 'system', 'problem', 'question', 'answer', 'plan', 'reason', 'result',
8
+ 'group', 'project', 'team', 'process', 'change', 'way', 'part', 'place',
9
+ 'case', 'point', 'fact', 'example', 'issue', 'matter', 'thing', 'situation',
10
+ 'area', 'level', 'type', 'kind', 'form', 'method', 'approach', 'solution',
11
+ 'person', 'company', 'organization', 'market', 'industry', 'service', 'product',
12
+ 'customer', 'client', 'user', 'employee', 'manager', 'leader', 'expert',
13
+ 'report', 'document', 'policy', 'strategy', 'goal', 'objective', 'target',
14
+ 'decision', 'action', 'step', 'task', 'activity', 'event', 'meeting',
15
+ 'resource', 'tool', 'technology', 'data', 'information', 'knowledge', 'skill',
16
+ 'opportunity', 'challenge', 'risk', 'benefit', 'value', 'cost', 'time',
17
+ ];
18
+ // Common verbs (base form)
19
+ export const DEFAULT_VERBS = [
20
+ 'be', 'have', 'do', 'say', 'get', 'make', 'go', 'know', 'take', 'see',
21
+ 'come', 'think', 'look', 'want', 'give', 'use', 'find', 'tell', 'ask', 'work',
22
+ 'seem', 'feel', 'try', 'leave', 'call', 'need', 'become', 'put', 'mean', 'keep',
23
+ 'let', 'begin', 'show', 'hear', 'play', 'run', 'move', 'live', 'believe', 'hold',
24
+ 'bring', 'happen', 'write', 'provide', 'sit', 'stand', 'lose', 'pay', 'meet',
25
+ 'include', 'continue', 'set', 'learn', 'change', 'lead', 'understand', 'watch',
26
+ 'follow', 'stop', 'create', 'speak', 'read', 'spend', 'grow', 'open', 'walk',
27
+ 'offer', 'remember', 'consider', 'appear', 'buy', 'wait', 'serve', 'send',
28
+ 'expect', 'build', 'stay', 'fall', 'cut', 'reach', 'remain', 'suggest', 'raise',
29
+ 'pass', 'sell', 'require', 'report', 'decide', 'support', 'develop', 'produce',
30
+ 'achieve', 'improve', 'increase', 'reduce', 'manage', 'maintain', 'ensure',
31
+ ];
32
+ // Common adjectives
33
+ export const DEFAULT_ADJECTIVES = [
34
+ 'good', 'new', 'first', 'last', 'long', 'great', 'little', 'own', 'other',
35
+ 'old', 'right', 'big', 'high', 'different', 'small', 'large', 'next', 'early',
36
+ 'young', 'important', 'few', 'public', 'bad', 'same', 'able', 'sure', 'real',
37
+ 'best', 'better', 'true', 'certain', 'clear', 'full', 'special', 'free',
38
+ 'strong', 'hard', 'likely', 'simple', 'recent', 'possible', 'whole', 'current',
39
+ 'general', 'specific', 'available', 'significant', 'particular', 'major',
40
+ 'successful', 'effective', 'essential', 'critical', 'key', 'primary', 'main',
41
+ 'direct', 'positive', 'negative', 'basic', 'common', 'serious', 'difficult',
42
+ 'similar', 'final', 'previous', 'additional', 'individual', 'professional',
43
+ ];
44
+ // Common adverbs
45
+ export const DEFAULT_ADVERBS = [
46
+ 'also', 'just', 'only', 'now', 'then', 'more', 'very', 'well', 'even', 'still',
47
+ 'already', 'often', 'always', 'never', 'really', 'much', 'most', 'almost',
48
+ 'here', 'there', 'together', 'quite', 'soon', 'perhaps', 'probably', 'actually',
49
+ 'simply', 'certainly', 'clearly', 'definitely', 'directly', 'easily', 'especially',
50
+ 'eventually', 'exactly', 'finally', 'frequently', 'generally', 'greatly',
51
+ 'highly', 'immediately', 'increasingly', 'indeed', 'naturally', 'nearly',
52
+ 'necessarily', 'normally', 'obviously', 'particularly', 'possibly', 'primarily',
53
+ 'quickly', 'rapidly', 'recently', 'regularly', 'significantly', 'slightly',
54
+ 'sometimes', 'specifically', 'strongly', 'successfully', 'suddenly', 'typically',
55
+ ];
56
+ // Common prepositions
57
+ export const DEFAULT_PREPOSITIONS = [
58
+ 'of', 'in', 'to', 'for', 'with', 'on', 'at', 'from', 'by', 'about',
59
+ 'as', 'into', 'through', 'during', 'before', 'after', 'above', 'below',
60
+ 'between', 'under', 'since', 'without', 'toward', 'upon', 'within',
61
+ 'against', 'among', 'across', 'behind', 'beyond', 'over', 'around',
62
+ 'throughout', 'despite', 'near', 'along', 'beside', 'outside', 'inside',
63
+ ];
64
+ // Common conjunctions (coordinating)
65
+ export const DEFAULT_CONJUNCTIONS = [
66
+ 'and', 'but', 'or', 'so', 'yet', 'nor', 'for',
67
+ ];
68
+ // Subordinating conjunctions
69
+ export const DEFAULT_SUBORDINATORS = [
70
+ 'after', 'although', 'as', 'because', 'before', 'if', 'once', 'since',
71
+ 'than', 'that', 'though', 'unless', 'until', 'when', 'whenever', 'where',
72
+ 'wherever', 'while', 'whereas',
73
+ ];
74
+ // Common interjections
75
+ export const DEFAULT_INTERJECTIONS = [
76
+ 'oh', 'ah', 'well', 'wow', 'hey', 'alas', 'indeed', 'certainly', 'surely',
77
+ 'naturally', 'clearly', 'obviously', 'honestly', 'frankly', 'fortunately',
78
+ 'unfortunately', 'surprisingly', 'interestingly',
79
+ ];
80
+ // Determiners
81
+ export const DEFAULT_DETERMINERS = [
82
+ 'the', 'a', 'an', 'this', 'that', 'these', 'those',
83
+ 'my', 'your', 'his', 'her', 'its', 'our', 'their',
84
+ 'some', 'any', 'no', 'every', 'each', 'all', 'both', 'few', 'many', 'several',
85
+ 'most', 'other', 'another', 'such', 'what', 'which',
86
+ ];
87
+ // Subject pronouns
88
+ export const DEFAULT_SUBJECT_PRONOUNS = [
89
+ 'I', 'you', 'he', 'she', 'it', 'we', 'they',
90
+ ];
91
+ // Object pronouns
92
+ export const DEFAULT_OBJECT_PRONOUNS = [
93
+ 'me', 'you', 'him', 'her', 'it', 'us', 'them',
94
+ ];
95
+ // Possessive determiners
96
+ export const DEFAULT_POSSESSIVE_DETERMINERS = [
97
+ 'my', 'your', 'his', 'her', 'its', 'our', 'their',
98
+ ];
99
+ // Modal verbs
100
+ export const DEFAULT_MODALS = [
101
+ 'can', 'could', 'may', 'might', 'must', 'shall', 'should', 'will', 'would',
102
+ ];
103
+ // Relative pronouns
104
+ export const DEFAULT_RELATIVES = [
105
+ 'who', 'whom', 'whose', 'which', 'that',
106
+ ];
107
+ // Transition words/phrases
108
+ export const DEFAULT_TRANSITIONS = [
109
+ 'however', 'therefore', 'moreover', 'furthermore', 'meanwhile',
110
+ 'consequently', 'nevertheless', 'otherwise', 'accordingly', 'indeed',
111
+ 'certainly', 'naturally', 'fortunately', 'unfortunately', 'surprisingly',
112
+ 'generally', 'specifically', 'particularly', 'additionally', 'similarly',
113
+ 'conversely', 'alternatively', 'subsequently', 'ultimately', 'eventually',
114
+ ];
115
+ // Question words
116
+ export const DEFAULT_QUESTION_WORDS = [
117
+ 'what', 'which', 'who', 'whom', 'whose', 'where', 'when', 'why', 'how',
118
+ ];
119
+ // Auxiliary verbs
120
+ export const DEFAULT_AUXILIARIES = [
121
+ 'be', 'have', 'do', 'will', 'would', 'shall', 'should', 'may', 'might',
122
+ 'can', 'could', 'must',
123
+ ];
124
+ //# sourceMappingURL=word-lists.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"word-lists.js","sourceRoot":"","sources":["../../src/defaults/word-lists.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,2BAA2B;AAC3B,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ;IAC7E,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO;IACvE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW;IAC3E,MAAM,EAAE,OAAO,EAAE,MAAM,EA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a,EAAE,WAAW;IAC9D,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,aAAa,EAAE,QAAQ;IACpE,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,eAAe,EAAE,cAAc;IACxE,WAAW,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW;IACxE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY;CAC1E,CAAC;AAEF,iBAAiB;AACjB,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;CACvE,CAAC;AAEF,kBAAkB;AAClB,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO;IACtE,KAAK,EAAE,OAAO,EAAE,MAAM;CACvB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { TextGenerator } from './text-generator.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { TextGenerator } from './text-generator.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * TextGenerator - Public API
3
+ * Main entry point for text generation
4
+ */
5
+ import type { GeneratorInitOptions, SentenceOptions, ParagraphOptions, TextBlockOptions, GeneratedText } from '../types/api.js';
6
+ import type { Lexicon } from '../types/lexicon.js';
7
+ import { TransformRegistry } from '../transforms/registry.js';
8
+ export declare class TextGenerator {
9
+ private config;
10
+ private rng;
11
+ private lexiconStore;
12
+ private wordProvider;
13
+ private phraseBuilders;
14
+ private sentenceTemplates;
15
+ private ruleEngine;
16
+ private fakerAdapter;
17
+ private enableTrace;
18
+ private currentArchetype;
19
+ private currentSeed;
20
+ private transformRegistry;
21
+ private currentLexicon?;
22
+ constructor(options: GeneratorInitOptions);
23
+ /**
24
+ * Set the random seed for deterministic output
25
+ */
26
+ setSeed(seed: number): void;
27
+ /**
28
+ * Set or replace the lexicon
29
+ */
30
+ setLexicon(lexicon: Lexicon): void;
31
+ /**
32
+ * Set the active archetype
33
+ */
34
+ setArchetype(name: string): void;
35
+ /**
36
+ * Get the transform registry (for registering custom transforms)
37
+ */
38
+ getTransformRegistry(): TransformRegistry;
39
+ /**
40
+ * Generate a single sentence
41
+ */
42
+ sentence(opts?: SentenceOptions): string | GeneratedText;
43
+ /**
44
+ * Generate a paragraph
45
+ */
46
+ paragraph(opts?: ParagraphOptions): string | GeneratedText;
47
+ /**
48
+ * Generate a text block (multiple paragraphs)
49
+ */
50
+ textBlock(opts?: TextBlockOptions): string | GeneratedText;
51
+ /**
52
+ * Apply output transforms to generated text.
53
+ * Merges config from: base config → lexicon defaults → archetype → per-call overrides.
54
+ */
55
+ private applyOutputTransforms;
56
+ /**
57
+ * Create a generation context
58
+ */
59
+ private createGenerationContext;
60
+ /**
61
+ * Generate a sentence with retry logic
62
+ */
63
+ private generateSentenceWithRetry;
64
+ /**
65
+ * Get active constraints (from lexicon + defaults)
66
+ */
67
+ private getActiveConstraints;
68
+ /**
69
+ * Get active invariants (from lexicon + defaults)
70
+ */
71
+ private getActiveInvariants;
72
+ /**
73
+ * Get generation metadata
74
+ */
75
+ private getMeta;
76
+ /**
77
+ * Create a trace for a single sentence result
78
+ */
79
+ private createSingleSentenceTrace;
80
+ /**
81
+ * Create a sentence trace
82
+ */
83
+ private createSentenceTrace;
84
+ /**
85
+ * Get list of correlations that were applied
86
+ */
87
+ private getAppliedCorrelations;
88
+ /**
89
+ * Check invariants on final text
90
+ */
91
+ private checkInvariants;
92
+ }
93
+ //# sourceMappingURL=text-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-generator.d.ts","sourceRoot":"","sources":["../../src/generator/text-generator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EAKd,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,OAAO,EAAyB,MAAM,qBAAqB,CAAC;AAoB1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAM9D,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,GAAG,CAAO;IAClB,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,WAAW,CAAU;IAC7B,OAAO,CAAC,gBAAgB,CAAqB;IAC7C,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,cAAc,CAAC,CAAU;gBAErB,OAAO,EAAE,oBAAoB;IAoCzC;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAK3B;;OAEG;IACH,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAKlC;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIhC;;OAEG;IACH,oBAAoB,IAAI,iBAAiB;IAIzC;;OAEG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,eAAe,GAAG,MAAM,GAAG,aAAa;IAoCxD;;OAEG;IACH,SAAS,CAAC,IAAI,CAAC,EAAE,gBAAgB,GAAG,MAAM,GAAG,aAAa;IAuD1D;;OAEG;IACH,SAAS,CAAC,IAAI,CAAC,EAAE,gBAAgB,GAAG,MAAM,GAAG,aAAa;IA0E1D;;;OAGG;IACH,OAAO,CAAC,qBAAqB;IAkC7B;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAyB/B;;OAEG;IACH,OAAO,CAAC,yBAAyB;IA6DjC;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAe5B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAY3B;;OAEG;IACH,OAAO,CAAC,OAAO;IAUf;;OAEG;IACH,OAAO,CAAC,yBAAyB;IAYjC;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAoC3B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAM9B;;OAEG;IACH,OAAO,CAAC,eAAe;CAOxB"}
@@ -0,0 +1,411 @@
1
+ /**
2
+ * TextGenerator - Public API
3
+ * Main entry point for text generation
4
+ */
5
+ import { SeedableRng } from '../rng/index.js';
6
+ import { LexiconStore } from '../lexicon/index.js';
7
+ import { WordProvider } from '../providers/index.js';
8
+ import { PhraseBuilders, SentenceTemplates } from '../grammar/index.js';
9
+ import { RuleEngine } from '../rules/index.js';
10
+ import { createContext, clearSentenceState, clearParagraphState } from '../types/context.js';
11
+ import { mergeConfig } from '../types/config.js';
12
+ import { formatParagraph, formatTextBlock } from '../morphology/index.js';
13
+ import { createDefaultRegistry } from '../transforms/default-registry.js';
14
+ import { executePipeline } from '../transforms/pipeline.js';
15
+ import { mergeOutputTransformsConfig } from '../transforms/config-merge.js';
16
+ export class TextGenerator {
17
+ config;
18
+ rng;
19
+ lexiconStore;
20
+ wordProvider;
21
+ phraseBuilders;
22
+ sentenceTemplates;
23
+ ruleEngine;
24
+ fakerAdapter;
25
+ enableTrace;
26
+ currentArchetype = 'default';
27
+ currentSeed;
28
+ transformRegistry;
29
+ currentLexicon;
30
+ constructor(options) {
31
+ this.fakerAdapter = options.fakerAdapter;
32
+ this.config = mergeConfig(options.config);
33
+ this.enableTrace = options.enableTrace ?? this.config.enableTrace;
34
+ // Initialize RNG
35
+ this.rng = options.rng ?? new SeedableRng();
36
+ this.currentSeed = Date.now();
37
+ this.rng.seed(this.currentSeed);
38
+ // Initialize lexicon store
39
+ this.lexiconStore = new LexiconStore(this.rng, options.lexicon);
40
+ this.currentLexicon = options.lexicon;
41
+ // Initialize word provider
42
+ this.wordProvider = new WordProvider(this.lexiconStore, this.fakerAdapter, this.rng);
43
+ // Initialize grammar components
44
+ this.phraseBuilders = new PhraseBuilders(this.wordProvider, this.rng, this.config);
45
+ this.sentenceTemplates = new SentenceTemplates(this.phraseBuilders, this.rng, this.config);
46
+ // Initialize rule engine
47
+ this.ruleEngine = new RuleEngine(this.config);
48
+ // Initialize transform registry with V1 defaults
49
+ this.transformRegistry = createDefaultRegistry();
50
+ // Set archetype if lexicon has one
51
+ if (options.lexicon) {
52
+ const archetypes = Object.keys(options.lexicon.archetypes ?? {});
53
+ if (archetypes.length > 0) {
54
+ this.currentArchetype = archetypes[0];
55
+ }
56
+ }
57
+ }
58
+ /**
59
+ * Set the random seed for deterministic output
60
+ */
61
+ setSeed(seed) {
62
+ this.currentSeed = seed;
63
+ this.rng.seed(seed);
64
+ }
65
+ /**
66
+ * Set or replace the lexicon
67
+ */
68
+ setLexicon(lexicon) {
69
+ this.lexiconStore.setLexicon(lexicon);
70
+ this.currentLexicon = lexicon;
71
+ }
72
+ /**
73
+ * Set the active archetype
74
+ */
75
+ setArchetype(name) {
76
+ this.currentArchetype = name;
77
+ }
78
+ /**
79
+ * Get the transform registry (for registering custom transforms)
80
+ */
81
+ getTransformRegistry() {
82
+ return this.transformRegistry;
83
+ }
84
+ /**
85
+ * Generate a single sentence
86
+ */
87
+ sentence(opts) {
88
+ const ctx = this.createGenerationContext(opts?.hints);
89
+ // Apply sentence type override if provided
90
+ const sentenceType = opts?.type;
91
+ // Generate with retry logic
92
+ const result = this.generateSentenceWithRetry(ctx, sentenceType);
93
+ // Apply output transforms
94
+ const perCallOverride = opts ? {
95
+ outputTransforms: opts.outputTransforms,
96
+ mergeMode: opts.mergeMode,
97
+ } : undefined;
98
+ const pipelineResult = this.applyOutputTransforms(result.text, perCallOverride);
99
+ const finalText = pipelineResult.text;
100
+ if (this.enableTrace) {
101
+ const trace = this.createSingleSentenceTrace(result, ctx);
102
+ trace.outputTokens = pipelineResult.outputTokens;
103
+ trace.transformEvents = pipelineResult.transformEvents;
104
+ return {
105
+ text: finalText,
106
+ trace,
107
+ meta: {
108
+ ...this.getMeta(),
109
+ transformsApplied: pipelineResult.transformsApplied.length > 0
110
+ ? pipelineResult.transformsApplied : undefined,
111
+ },
112
+ };
113
+ }
114
+ return finalText;
115
+ }
116
+ /**
117
+ * Generate a paragraph
118
+ */
119
+ paragraph(opts) {
120
+ const ctx = this.createGenerationContext(opts?.hints);
121
+ const minSentences = opts?.minSentences ?? opts?.sentences ?? this.config.minSentencesPerParagraph;
122
+ const maxSentences = opts?.maxSentences ?? opts?.sentences ?? this.config.maxSentencesPerParagraph;
123
+ const numSentences = opts?.sentences ?? this.rng.int(minSentences, maxSentences);
124
+ const sentences = [];
125
+ const sentenceTraces = [];
126
+ for (let i = 0; i < numSentences; i++) {
127
+ ctx.sentenceIndex = i;
128
+ clearSentenceState(ctx);
129
+ const result = this.generateSentenceWithRetry(ctx);
130
+ sentences.push(result);
131
+ if (this.enableTrace) {
132
+ sentenceTraces.push(this.createSentenceTrace(result, ctx));
133
+ }
134
+ }
135
+ const rawText = formatParagraph(sentences.map(s => s.text));
136
+ // Apply output transforms
137
+ const perCallOverride = opts ? {
138
+ outputTransforms: opts.outputTransforms,
139
+ mergeMode: opts.mergeMode,
140
+ } : undefined;
141
+ const pipelineResult = this.applyOutputTransforms(rawText, perCallOverride);
142
+ const finalText = pipelineResult.text;
143
+ if (this.enableTrace) {
144
+ const trace = {
145
+ paragraphs: [{ sentences: sentenceTraces }],
146
+ correlationsApplied: this.getAppliedCorrelations(ctx),
147
+ invariantsChecked: this.checkInvariants(finalText),
148
+ outputTokens: pipelineResult.outputTokens,
149
+ transformEvents: pipelineResult.transformEvents,
150
+ };
151
+ return {
152
+ text: finalText,
153
+ trace,
154
+ meta: {
155
+ ...this.getMeta(),
156
+ transformsApplied: pipelineResult.transformsApplied.length > 0
157
+ ? pipelineResult.transformsApplied : undefined,
158
+ },
159
+ };
160
+ }
161
+ return finalText;
162
+ }
163
+ /**
164
+ * Generate a text block (multiple paragraphs)
165
+ */
166
+ textBlock(opts) {
167
+ const minParagraphs = opts?.minParagraphs ?? opts?.paragraphs ?? 1;
168
+ const maxParagraphs = opts?.maxParagraphs ?? opts?.paragraphs ?? 3;
169
+ const numParagraphs = opts?.paragraphs ?? this.rng.int(minParagraphs, maxParagraphs);
170
+ const paragraphs = [];
171
+ const paragraphTraces = [];
172
+ for (let i = 0; i < numParagraphs; i++) {
173
+ const ctx = this.createGenerationContext(opts?.hints);
174
+ ctx.paragraphIndex = i;
175
+ const minSentences = this.config.minSentencesPerParagraph;
176
+ const maxSentences = this.config.maxSentencesPerParagraph;
177
+ const numSentences = this.rng.int(minSentences, maxSentences);
178
+ const sentences = [];
179
+ const sentenceTraces = [];
180
+ for (let j = 0; j < numSentences; j++) {
181
+ ctx.sentenceIndex = j;
182
+ clearSentenceState(ctx);
183
+ const result = this.generateSentenceWithRetry(ctx);
184
+ sentences.push(result);
185
+ if (this.enableTrace) {
186
+ sentenceTraces.push(this.createSentenceTrace(result, ctx));
187
+ }
188
+ }
189
+ paragraphs.push(formatParagraph(sentences.map(s => s.text)));
190
+ if (this.enableTrace) {
191
+ paragraphTraces.push({ sentences: sentenceTraces });
192
+ }
193
+ clearParagraphState(ctx);
194
+ }
195
+ const rawText = formatTextBlock(paragraphs);
196
+ // Apply output transforms
197
+ const perCallOverride = opts ? {
198
+ outputTransforms: opts.outputTransforms,
199
+ mergeMode: opts.mergeMode,
200
+ } : undefined;
201
+ const pipelineResult = this.applyOutputTransforms(rawText, perCallOverride);
202
+ const finalText = pipelineResult.text;
203
+ if (this.enableTrace) {
204
+ const ctx = this.createGenerationContext(opts?.hints);
205
+ const trace = {
206
+ paragraphs: paragraphTraces,
207
+ correlationsApplied: this.getAppliedCorrelations(ctx),
208
+ invariantsChecked: this.checkInvariants(finalText),
209
+ outputTokens: pipelineResult.outputTokens,
210
+ transformEvents: pipelineResult.transformEvents,
211
+ };
212
+ return {
213
+ text: finalText,
214
+ trace,
215
+ meta: {
216
+ ...this.getMeta(),
217
+ transformsApplied: pipelineResult.transformsApplied.length > 0
218
+ ? pipelineResult.transformsApplied : undefined,
219
+ },
220
+ };
221
+ }
222
+ return finalText;
223
+ }
224
+ /**
225
+ * Apply output transforms to generated text.
226
+ * Merges config from: base config → lexicon defaults → archetype → per-call overrides.
227
+ */
228
+ applyOutputTransforms(text, perCallOverride) {
229
+ // Get lexicon-level defaults
230
+ const lexiconDefaults = this.currentLexicon?.outputTransforms;
231
+ // Get archetype-level transforms
232
+ let archetypeTransforms;
233
+ if (this.currentLexicon?.archetypes?.[this.currentArchetype]) {
234
+ archetypeTransforms = this.currentLexicon.archetypes[this.currentArchetype].outputTransforms;
235
+ }
236
+ // Merge all sources
237
+ const finalConfig = mergeOutputTransformsConfig(this.config.outputTransforms, lexiconDefaults, archetypeTransforms, perCallOverride ? {
238
+ outputTransforms: perCallOverride.outputTransforms,
239
+ mergeMode: perCallOverride.mergeMode,
240
+ } : undefined);
241
+ // Execute pipeline
242
+ return executePipeline(text, finalConfig, this.transformRegistry, this.currentSeed, this.enableTrace);
243
+ }
244
+ /**
245
+ * Create a generation context
246
+ */
247
+ createGenerationContext(hints) {
248
+ const ctx = createContext(this.currentSeed, this.currentArchetype);
249
+ // Add hints as active tags
250
+ if (hints) {
251
+ for (const hint of hints) {
252
+ ctx.activeTags.add(hint);
253
+ }
254
+ }
255
+ // Add archetype tags
256
+ const archetype = this.lexiconStore.getArchetype(this.currentArchetype);
257
+ if (archetype?.tags) {
258
+ for (const tag of archetype.tags) {
259
+ ctx.activeTags.add(tag);
260
+ }
261
+ }
262
+ // Merge constraints and invariants
263
+ ctx.constraints = this.getActiveConstraints();
264
+ ctx.invariants = this.getActiveInvariants();
265
+ return ctx;
266
+ }
267
+ /**
268
+ * Generate a sentence with retry logic
269
+ */
270
+ generateSentenceWithRetry(ctx, type) {
271
+ let attempts = 0;
272
+ let lastResult;
273
+ let lastError;
274
+ while (attempts < this.config.maxSentenceAttempts) {
275
+ attempts++;
276
+ ctx.retryCount = attempts - 1;
277
+ try {
278
+ const result = this.sentenceTemplates.buildSentence(ctx, type);
279
+ // Validate
280
+ const validation = this.ruleEngine.validate(ctx.constraints, ctx.invariants, ctx, result.text, result.tokens, 'sentence');
281
+ if (validation.valid) {
282
+ return result;
283
+ }
284
+ lastResult = result;
285
+ // If only soft constraints failed, use this result
286
+ if (validation.hardConstraintsFailed.length === 0 && validation.invariantsFailed.length === 0) {
287
+ return result;
288
+ }
289
+ // Apply degradation strategy on subsequent attempts
290
+ if (attempts > 5) {
291
+ // Simplify: reduce complexity for next attempt
292
+ this.config.maxPPChain = Math.max(0, this.config.maxPPChain - 1);
293
+ }
294
+ if (attempts > 10) {
295
+ // Force simple declarative
296
+ type = 'simpleDeclarative';
297
+ }
298
+ }
299
+ catch (e) {
300
+ lastError = e instanceof Error ? e : new Error(String(e));
301
+ }
302
+ }
303
+ // Return best effort or throw
304
+ if (lastResult) {
305
+ return lastResult;
306
+ }
307
+ if (this.config.strictMode) {
308
+ throw lastError ?? new Error('Failed to generate valid sentence');
309
+ }
310
+ // Fallback: generate simplest possible sentence
311
+ return this.sentenceTemplates.buildSimpleDeclarative(ctx);
312
+ }
313
+ /**
314
+ * Get active constraints (from lexicon + defaults)
315
+ */
316
+ getActiveConstraints() {
317
+ const defaults = this.ruleEngine.getDefaultConstraints();
318
+ if (!this.lexiconStore.isLoaded()) {
319
+ return defaults;
320
+ }
321
+ const meta = this.lexiconStore.getMeta();
322
+ if (!meta)
323
+ return defaults;
324
+ // Would need to access lexicon.constraints
325
+ // For now, return defaults
326
+ return defaults;
327
+ }
328
+ /**
329
+ * Get active invariants (from lexicon + defaults)
330
+ */
331
+ getActiveInvariants() {
332
+ const defaults = this.ruleEngine.getDefaultInvariants();
333
+ if (!this.lexiconStore.isLoaded()) {
334
+ return defaults;
335
+ }
336
+ // Would need to access lexicon.invariants
337
+ // For now, return defaults
338
+ return defaults;
339
+ }
340
+ /**
341
+ * Get generation metadata
342
+ */
343
+ getMeta() {
344
+ const lexiconMeta = this.lexiconStore.getMeta();
345
+ return {
346
+ archetype: this.currentArchetype,
347
+ seed: this.currentSeed,
348
+ lexiconVersion: lexiconMeta?.version,
349
+ lexiconId: lexiconMeta?.id,
350
+ };
351
+ }
352
+ /**
353
+ * Create a trace for a single sentence result
354
+ */
355
+ createSingleSentenceTrace(result, ctx) {
356
+ return {
357
+ paragraphs: [
358
+ {
359
+ sentences: [this.createSentenceTrace(result, ctx)],
360
+ },
361
+ ],
362
+ correlationsApplied: this.getAppliedCorrelations(ctx),
363
+ invariantsChecked: this.checkInvariants(result.text),
364
+ };
365
+ }
366
+ /**
367
+ * Create a sentence trace
368
+ */
369
+ createSentenceTrace(result, ctx) {
370
+ const tokenTraces = result.tokens.map(token => {
371
+ // Find if this token came from lexicon or faker
372
+ const events = ctx.history.events.filter(e => e.type === 'term' && e.item.value === token);
373
+ const event = events[events.length - 1];
374
+ return {
375
+ value: token,
376
+ source: event?.termSetId ?? 'default',
377
+ pos: event?.type === 'term' ? event.item.pos : undefined,
378
+ };
379
+ });
380
+ const validation = this.ruleEngine.validate(ctx.constraints, ctx.invariants, ctx, result.text, result.tokens, 'sentence');
381
+ return {
382
+ text: result.text,
383
+ template: result.type,
384
+ tokens: tokenTraces,
385
+ constraintsEvaluated: validation.constraintResults.map(r => ({
386
+ id: r.id,
387
+ passed: r.passed,
388
+ })),
389
+ retryCount: ctx.retryCount,
390
+ };
391
+ }
392
+ /**
393
+ * Get list of correlations that were applied
394
+ */
395
+ getAppliedCorrelations(ctx) {
396
+ // Would need to track this during generation
397
+ // For now, return the biases that were set
398
+ return Array.from(ctx.biases.keys());
399
+ }
400
+ /**
401
+ * Check invariants on final text
402
+ */
403
+ checkInvariants(text) {
404
+ const invariants = this.ruleEngine.getDefaultInvariants();
405
+ return invariants.map(inv => {
406
+ const result = this.ruleEngine.evaluateInvariant(inv, text);
407
+ return { id: result.id, passed: result.passed };
408
+ });
409
+ }
410
+ }
411
+ //# sourceMappingURL=text-generator.js.map