@lokascript/framework 2.0.0 → 2.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.
Files changed (126) hide show
  1. package/dist/aot/index.d.ts +1 -0
  2. package/dist/aot/index.d.ts.map +1 -1
  3. package/dist/aot/registry-bridge.d.ts +27 -0
  4. package/dist/aot/registry-bridge.d.ts.map +1 -0
  5. package/dist/api/create-dsl.d.ts.map +1 -1
  6. package/dist/api/dispatcher.d.ts +22 -0
  7. package/dist/api/dispatcher.d.ts.map +1 -1
  8. package/dist/api/domain-registry.d.ts +41 -0
  9. package/dist/api/domain-registry.d.ts.map +1 -1
  10. package/dist/api/index.js +1351 -21
  11. package/dist/api/index.js.map +1 -1
  12. package/dist/core/index.js +114 -10
  13. package/dist/core/index.js.map +1 -1
  14. package/dist/core/pattern-matching/index.js +74 -10
  15. package/dist/core/pattern-matching/index.js.map +1 -1
  16. package/dist/core/pattern-matching/pattern-matcher.d.ts.map +1 -1
  17. package/dist/core/types.d.ts +80 -2
  18. package/dist/core/types.d.ts.map +1 -1
  19. package/dist/core/types.js +40 -0
  20. package/dist/core/types.js.map +1 -1
  21. package/dist/feedback/confidence-gate.d.ts +28 -0
  22. package/dist/feedback/confidence-gate.d.ts.map +1 -0
  23. package/dist/feedback/feedback-formatter.d.ts +21 -0
  24. package/dist/feedback/feedback-formatter.d.ts.map +1 -0
  25. package/dist/feedback/index.d.ts +11 -0
  26. package/dist/feedback/index.d.ts.map +1 -0
  27. package/dist/feedback/pattern-tracker.d.ts +47 -0
  28. package/dist/feedback/pattern-tracker.d.ts.map +1 -0
  29. package/dist/feedback/types.d.ts +113 -0
  30. package/dist/feedback/types.d.ts.map +1 -0
  31. package/dist/generation/index.js +2 -1
  32. package/dist/generation/index.js.map +1 -1
  33. package/dist/index.cjs +2685 -71
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.ts +6 -2
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +2652 -71
  38. package/dist/index.js.map +1 -1
  39. package/dist/ir/explicit-parser.d.ts +31 -0
  40. package/dist/ir/explicit-parser.d.ts.map +1 -0
  41. package/dist/ir/explicit-renderer.d.ts +17 -0
  42. package/dist/ir/explicit-renderer.d.ts.map +1 -0
  43. package/dist/ir/from-interchange.d.ts +51 -0
  44. package/dist/ir/from-interchange.d.ts.map +1 -0
  45. package/dist/ir/index.d.ts +29 -0
  46. package/dist/ir/index.d.ts.map +1 -0
  47. package/dist/ir/index.js +1557 -0
  48. package/dist/ir/index.js.map +1 -0
  49. package/dist/ir/json-schema.d.ts +40 -0
  50. package/dist/ir/json-schema.d.ts.map +1 -0
  51. package/dist/ir/protocol-json.d.ts +73 -0
  52. package/dist/ir/protocol-json.d.ts.map +1 -0
  53. package/dist/ir/references.d.ts +19 -0
  54. package/dist/ir/references.d.ts.map +1 -0
  55. package/dist/ir/types.d.ts +141 -0
  56. package/dist/ir/types.d.ts.map +1 -0
  57. package/dist/parsing/index.js +74 -10
  58. package/dist/parsing/index.js.map +1 -1
  59. package/dist/prompts/index.d.ts +9 -0
  60. package/dist/prompts/index.d.ts.map +1 -0
  61. package/dist/prompts/prompt-generator.d.ts +49 -0
  62. package/dist/prompts/prompt-generator.d.ts.map +1 -0
  63. package/dist/prompts/types.d.ts +64 -0
  64. package/dist/prompts/types.d.ts.map +1 -0
  65. package/dist/schema/command-schema.d.ts +17 -0
  66. package/dist/schema/command-schema.d.ts.map +1 -1
  67. package/dist/schema/index.js.map +1 -1
  68. package/dist/testing/index.js +3 -0
  69. package/dist/testing/index.js.map +1 -1
  70. package/dist/training/index.d.ts +11 -0
  71. package/dist/training/index.d.ts.map +1 -0
  72. package/dist/training/jsonl-writer.d.ts +42 -0
  73. package/dist/training/jsonl-writer.d.ts.map +1 -0
  74. package/dist/training/schema-synthesizer.d.ts +20 -0
  75. package/dist/training/schema-synthesizer.d.ts.map +1 -0
  76. package/dist/training/types.d.ts +73 -0
  77. package/dist/training/types.d.ts.map +1 -0
  78. package/package.json +5 -1
  79. package/src/aot/index.ts +1 -0
  80. package/src/aot/registry-bridge.test.ts +104 -0
  81. package/src/aot/registry-bridge.ts +66 -0
  82. package/src/api/create-dsl.test.ts +306 -0
  83. package/src/api/create-dsl.ts +21 -0
  84. package/src/api/dispatcher.test.ts +66 -0
  85. package/src/api/dispatcher.ts +77 -9
  86. package/src/api/domain-registry.ts +120 -4
  87. package/src/core/pattern-matching/pattern-matcher.test.ts +131 -0
  88. package/src/core/pattern-matching/pattern-matcher.ts +102 -19
  89. package/src/core/types.ts +145 -2
  90. package/src/feedback/confidence-gate.test.ts +111 -0
  91. package/src/feedback/confidence-gate.ts +70 -0
  92. package/src/feedback/feedback-formatter.test.ts +198 -0
  93. package/src/feedback/feedback-formatter.ts +298 -0
  94. package/src/feedback/index.ts +24 -0
  95. package/src/feedback/pattern-tracker.test.ts +198 -0
  96. package/src/feedback/pattern-tracker.ts +140 -0
  97. package/src/feedback/types.ts +149 -0
  98. package/src/generation/pattern-generator.ts +2 -2
  99. package/src/index.ts +22 -0
  100. package/src/integration/llm-lse-integration.test.ts +457 -0
  101. package/src/ir/explicit-parser.test.ts +306 -0
  102. package/src/ir/explicit-parser.ts +419 -0
  103. package/src/ir/explicit-renderer.test.ts +144 -0
  104. package/src/ir/explicit-renderer.ts +146 -0
  105. package/src/ir/from-interchange.test.ts +853 -0
  106. package/src/ir/from-interchange.ts +594 -0
  107. package/src/ir/index.ts +66 -0
  108. package/src/ir/json-schema.test.ts +281 -0
  109. package/src/ir/json-schema.ts +299 -0
  110. package/src/ir/protocol-json.test.ts +1185 -0
  111. package/src/ir/protocol-json.ts +745 -0
  112. package/src/ir/references.test.ts +38 -0
  113. package/src/ir/references.ts +33 -0
  114. package/src/ir/round-trip.test.ts +557 -0
  115. package/src/ir/types.ts +181 -0
  116. package/src/prompts/index.ts +15 -0
  117. package/src/prompts/prompt-generator.test.ts +386 -0
  118. package/src/prompts/prompt-generator.ts +531 -0
  119. package/src/prompts/types.ts +89 -0
  120. package/src/schema/command-schema.ts +19 -0
  121. package/src/training/index.ts +13 -0
  122. package/src/training/jsonl-writer.test.ts +138 -0
  123. package/src/training/jsonl-writer.ts +67 -0
  124. package/src/training/schema-synthesizer.test.ts +250 -0
  125. package/src/training/schema-synthesizer.ts +306 -0
  126. package/src/training/types.ts +103 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/ir/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAM9D;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,YAAY;IAC3B,8BAA8B;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IACzC,8DAA8D;IAC9D,OAAO,CAAC,EAAE;QACR,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACrC,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,UAAU,GAAG,SAAS,GAAG,WAAW,GAAG,YAAY,GAAG,eAAe,GAAG,MAAM,CAAC;IACrF,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;CAClC;AAMD;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAAC;CACtD;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,iDAAiD;IACjD,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,2EAA2E;IAC3E,YAAY,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CACpC;AAMD;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,OAAO,GAAG,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
  * a token and the immediately following pattern token fails, the matcher
225
225
  * resets to before the optional role and retries the failed token.
226
226
  */
227
- matchTokenSequence(tokens, patternTokens, captured) {
227
+ matchTokenSequence(tokens, patternTokens, captured, parentStopMarkers) {
228
228
  const firstPatternToken = patternTokens[0];
229
229
  const patternExpectsConjunction = firstPatternToken?.type === "literal" && (firstPatternToken.value === "and" || firstPatternToken.value === "then" || firstPatternToken.alternatives?.includes("and") || firstPatternToken.alternatives?.includes("then"));
230
230
  if (this.currentProfile?.code === "ar" && !patternExpectsConjunction) {
@@ -248,6 +248,9 @@ var _PatternMatcher = class _PatternMatcher {
248
248
  );
249
249
  if (patternToken.type === "role" && patternToken.greedy) {
250
250
  const stopMarkers = this.collectStopMarkers(patternTokens, i + 1);
251
+ if (parentStopMarkers) {
252
+ for (const m of parentStopMarkers) stopMarkers.add(m);
253
+ }
251
254
  const values = [];
252
255
  while (!tokens.isAtEnd()) {
253
256
  const nextToken = tokens.peek();
@@ -267,8 +270,58 @@ var _PatternMatcher = class _PatternMatcher {
267
270
  return false;
268
271
  }
269
272
  }
273
+ if (patternToken.type === "group") {
274
+ const siblingStopMarkers = this.collectStopMarkers(patternTokens, i + 1);
275
+ if (parentStopMarkers) {
276
+ for (const m of parentStopMarkers) siblingStopMarkers.add(m);
277
+ }
278
+ const groupMatched = this.matchGroupToken(
279
+ tokens,
280
+ patternToken,
281
+ captured,
282
+ siblingStopMarkers
283
+ );
284
+ if (groupMatched) {
285
+ prevOptionalMark = null;
286
+ prevOptionalRole = null;
287
+ continue;
288
+ }
289
+ if (this.isOptional(patternToken)) {
290
+ continue;
291
+ }
292
+ return false;
293
+ }
270
294
  const isOptionalRole = patternToken.type === "role" && patternToken.optional === true;
271
295
  const markBefore = isOptionalRole ? tokens.mark() : null;
296
+ const isRoleToken = patternToken.type === "role";
297
+ if (isRoleToken && !isOptionalRole) {
298
+ const nextPT = i + 1 < patternTokens.length ? patternTokens[i + 1] : null;
299
+ if (nextPT?.type === "literal") {
300
+ const currentToken = tokens.peek();
301
+ if (currentToken && this.getMatchType(currentToken, nextPT.value) !== "none") {
302
+ this.logger.debug(
303
+ " >> MARKER-STEAL GUARD: current token matches next literal, skipping role"
304
+ );
305
+ this.logger.debug(" >> Token match FAILED");
306
+ if (this.isOptional(patternToken)) {
307
+ continue;
308
+ }
309
+ if (prevOptionalMark && prevOptionalRole) {
310
+ this.logger.debug(" >> BACKTRACKING: undoing optional role", prevOptionalRole);
311
+ tokens.reset(prevOptionalMark);
312
+ captured.delete(prevOptionalRole);
313
+ prevOptionalMark = null;
314
+ prevOptionalRole = null;
315
+ const retryMatched = this.matchPatternToken(tokens, patternToken, captured);
316
+ this.logger.debug(" >> Backtrack retry result:", retryMatched);
317
+ if (retryMatched) {
318
+ continue;
319
+ }
320
+ }
321
+ return false;
322
+ }
323
+ }
324
+ }
272
325
  const matched = this.matchPatternToken(tokens, patternToken, captured);
273
326
  this.logger.debug(" >> Match result:", matched);
274
327
  if (matched) {
@@ -389,7 +442,7 @@ var _PatternMatcher = class _PatternMatcher {
389
442
  const possessiveValue = this.tryMatchPossessiveExpression(tokens);
390
443
  if (possessiveValue) {
391
444
  if (patternToken.expectedTypes && patternToken.expectedTypes.length > 0) {
392
- if (!patternToken.expectedTypes.includes(possessiveValue.type) && !patternToken.expectedTypes.includes("expression")) {
445
+ if (!isTypeCompatible(possessiveValue.type, patternToken.expectedTypes)) {
393
446
  return patternToken.optional || false;
394
447
  }
395
448
  }
@@ -399,7 +452,7 @@ var _PatternMatcher = class _PatternMatcher {
399
452
  const methodCallValue = this.tryMatchMethodCallExpression(tokens);
400
453
  if (methodCallValue) {
401
454
  if (patternToken.expectedTypes && patternToken.expectedTypes.length > 0) {
402
- if (!patternToken.expectedTypes.includes(methodCallValue.type) && !patternToken.expectedTypes.includes("expression")) {
455
+ if (!isTypeCompatible(methodCallValue.type, patternToken.expectedTypes)) {
403
456
  return patternToken.optional || false;
404
457
  }
405
458
  }
@@ -419,7 +472,7 @@ var _PatternMatcher = class _PatternMatcher {
419
472
  const propertyAccessValue = this.tryMatchPropertyAccessExpression(tokens);
420
473
  if (propertyAccessValue) {
421
474
  if (patternToken.expectedTypes && patternToken.expectedTypes.length > 0) {
422
- if (!patternToken.expectedTypes.includes(propertyAccessValue.type) && !patternToken.expectedTypes.includes("expression")) {
475
+ if (!isTypeCompatible(propertyAccessValue.type, patternToken.expectedTypes)) {
423
476
  return patternToken.optional || false;
424
477
  }
425
478
  }
@@ -739,10 +792,15 @@ var _PatternMatcher = class _PatternMatcher {
739
792
  * (e.g., a value like 'hello') to sit between groups without blocking later
740
793
  * marker matches.
741
794
  */
742
- matchGroupToken(tokens, patternToken, captured) {
795
+ matchGroupToken(tokens, patternToken, captured, parentStopMarkers) {
743
796
  const mark = tokens.mark();
744
797
  const capturedBefore = new Set(captured.keys());
745
- const success = this.matchTokenSequence(tokens, patternToken.tokens, captured);
798
+ const success = this.matchTokenSequence(
799
+ tokens,
800
+ patternToken.tokens,
801
+ captured,
802
+ parentStopMarkers
803
+ );
746
804
  if (success) return true;
747
805
  tokens.reset(mark);
748
806
  for (const role of captured.keys()) {
@@ -764,7 +822,12 @@ var _PatternMatcher = class _PatternMatcher {
764
822
  "- skipping intervening tokens"
765
823
  );
766
824
  for (let s = 0; s < offset; s++) tokens.advance();
767
- const retrySuccess = this.matchTokenSequence(tokens, patternToken.tokens, captured);
825
+ const retrySuccess = this.matchTokenSequence(
826
+ tokens,
827
+ patternToken.tokens,
828
+ captured,
829
+ parentStopMarkers
830
+ );
768
831
  if (retrySuccess) return true;
769
832
  tokens.reset(mark);
770
833
  for (const role of captured.keys()) {
@@ -831,7 +894,7 @@ var _PatternMatcher = class _PatternMatcher {
831
894
  break;
832
895
  }
833
896
  }
834
- break;
897
+ if (!pt.optional) break;
835
898
  }
836
899
  }
837
900
  return markers;
@@ -841,8 +904,9 @@ var _PatternMatcher = class _PatternMatcher {
841
904
  */
842
905
  isStopMarker(token, stopMarkers) {
843
906
  if (stopMarkers.size === 0) return false;
844
- const value = (token.normalized || token.value).toLowerCase();
845
- return stopMarkers.has(value);
907
+ if (stopMarkers.has(token.value.toLowerCase())) return true;
908
+ if (token.normalized && stopMarkers.has(token.normalized.toLowerCase())) return true;
909
+ return false;
846
910
  }
847
911
  /**
848
912
  * Convert a language token to a semantic value.