@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.
- package/dist/aot/index.d.ts +1 -0
- package/dist/aot/index.d.ts.map +1 -1
- package/dist/aot/registry-bridge.d.ts +27 -0
- package/dist/aot/registry-bridge.d.ts.map +1 -0
- package/dist/api/create-dsl.d.ts.map +1 -1
- package/dist/api/dispatcher.d.ts +22 -0
- package/dist/api/dispatcher.d.ts.map +1 -1
- package/dist/api/domain-registry.d.ts +41 -0
- package/dist/api/domain-registry.d.ts.map +1 -1
- package/dist/api/index.js +1351 -21
- package/dist/api/index.js.map +1 -1
- package/dist/core/index.js +114 -10
- package/dist/core/index.js.map +1 -1
- package/dist/core/pattern-matching/index.js +74 -10
- package/dist/core/pattern-matching/index.js.map +1 -1
- package/dist/core/pattern-matching/pattern-matcher.d.ts.map +1 -1
- package/dist/core/types.d.ts +80 -2
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js +40 -0
- package/dist/core/types.js.map +1 -1
- package/dist/feedback/confidence-gate.d.ts +28 -0
- package/dist/feedback/confidence-gate.d.ts.map +1 -0
- package/dist/feedback/feedback-formatter.d.ts +21 -0
- package/dist/feedback/feedback-formatter.d.ts.map +1 -0
- package/dist/feedback/index.d.ts +11 -0
- package/dist/feedback/index.d.ts.map +1 -0
- package/dist/feedback/pattern-tracker.d.ts +47 -0
- package/dist/feedback/pattern-tracker.d.ts.map +1 -0
- package/dist/feedback/types.d.ts +113 -0
- package/dist/feedback/types.d.ts.map +1 -0
- package/dist/generation/index.js +2 -1
- package/dist/generation/index.js.map +1 -1
- package/dist/index.cjs +2685 -71
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2652 -71
- package/dist/index.js.map +1 -1
- package/dist/ir/explicit-parser.d.ts +31 -0
- package/dist/ir/explicit-parser.d.ts.map +1 -0
- package/dist/ir/explicit-renderer.d.ts +17 -0
- package/dist/ir/explicit-renderer.d.ts.map +1 -0
- package/dist/ir/from-interchange.d.ts +51 -0
- package/dist/ir/from-interchange.d.ts.map +1 -0
- package/dist/ir/index.d.ts +29 -0
- package/dist/ir/index.d.ts.map +1 -0
- package/dist/ir/index.js +1557 -0
- package/dist/ir/index.js.map +1 -0
- package/dist/ir/json-schema.d.ts +40 -0
- package/dist/ir/json-schema.d.ts.map +1 -0
- package/dist/ir/protocol-json.d.ts +73 -0
- package/dist/ir/protocol-json.d.ts.map +1 -0
- package/dist/ir/references.d.ts +19 -0
- package/dist/ir/references.d.ts.map +1 -0
- package/dist/ir/types.d.ts +141 -0
- package/dist/ir/types.d.ts.map +1 -0
- package/dist/parsing/index.js +74 -10
- package/dist/parsing/index.js.map +1 -1
- package/dist/prompts/index.d.ts +9 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/prompt-generator.d.ts +49 -0
- package/dist/prompts/prompt-generator.d.ts.map +1 -0
- package/dist/prompts/types.d.ts +64 -0
- package/dist/prompts/types.d.ts.map +1 -0
- package/dist/schema/command-schema.d.ts +17 -0
- package/dist/schema/command-schema.d.ts.map +1 -1
- package/dist/schema/index.js.map +1 -1
- package/dist/testing/index.js +3 -0
- package/dist/testing/index.js.map +1 -1
- package/dist/training/index.d.ts +11 -0
- package/dist/training/index.d.ts.map +1 -0
- package/dist/training/jsonl-writer.d.ts +42 -0
- package/dist/training/jsonl-writer.d.ts.map +1 -0
- package/dist/training/schema-synthesizer.d.ts +20 -0
- package/dist/training/schema-synthesizer.d.ts.map +1 -0
- package/dist/training/types.d.ts +73 -0
- package/dist/training/types.d.ts.map +1 -0
- package/package.json +5 -1
- package/src/aot/index.ts +1 -0
- package/src/aot/registry-bridge.test.ts +104 -0
- package/src/aot/registry-bridge.ts +66 -0
- package/src/api/create-dsl.test.ts +306 -0
- package/src/api/create-dsl.ts +21 -0
- package/src/api/dispatcher.test.ts +66 -0
- package/src/api/dispatcher.ts +77 -9
- package/src/api/domain-registry.ts +120 -4
- package/src/core/pattern-matching/pattern-matcher.test.ts +131 -0
- package/src/core/pattern-matching/pattern-matcher.ts +102 -19
- package/src/core/types.ts +145 -2
- package/src/feedback/confidence-gate.test.ts +111 -0
- package/src/feedback/confidence-gate.ts +70 -0
- package/src/feedback/feedback-formatter.test.ts +198 -0
- package/src/feedback/feedback-formatter.ts +298 -0
- package/src/feedback/index.ts +24 -0
- package/src/feedback/pattern-tracker.test.ts +198 -0
- package/src/feedback/pattern-tracker.ts +140 -0
- package/src/feedback/types.ts +149 -0
- package/src/generation/pattern-generator.ts +2 -2
- package/src/index.ts +22 -0
- package/src/integration/llm-lse-integration.test.ts +457 -0
- package/src/ir/explicit-parser.test.ts +306 -0
- package/src/ir/explicit-parser.ts +419 -0
- package/src/ir/explicit-renderer.test.ts +144 -0
- package/src/ir/explicit-renderer.ts +146 -0
- package/src/ir/from-interchange.test.ts +853 -0
- package/src/ir/from-interchange.ts +594 -0
- package/src/ir/index.ts +66 -0
- package/src/ir/json-schema.test.ts +281 -0
- package/src/ir/json-schema.ts +299 -0
- package/src/ir/protocol-json.test.ts +1185 -0
- package/src/ir/protocol-json.ts +745 -0
- package/src/ir/references.test.ts +38 -0
- package/src/ir/references.ts +33 -0
- package/src/ir/round-trip.test.ts +557 -0
- package/src/ir/types.ts +181 -0
- package/src/prompts/index.ts +15 -0
- package/src/prompts/prompt-generator.test.ts +386 -0
- package/src/prompts/prompt-generator.ts +531 -0
- package/src/prompts/types.ts +89 -0
- package/src/schema/command-schema.ts +19 -0
- package/src/training/index.ts +13 -0
- package/src/training/jsonl-writer.test.ts +138 -0
- package/src/training/jsonl-writer.ts +67 -0
- package/src/training/schema-synthesizer.test.ts +250 -0
- package/src/training/schema-synthesizer.ts +306 -0
- 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;;;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W,CAAC,EAAE,cAAc,EAAE,CAAC;IAE/B,WAAW,CAAC,EAAE,gBAAgB,EAAE,CAAC;IACjC,aAAa,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAEnC,YAAY,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IAC9B,SAAS,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAE/B,IAAI,CAAC,EAAE,YAAY,EAAE,CAAC;IACtB,UAAU,CAAC,EAAE,gBAAgB,EAAE,CAAC;CACjC;AAMD,mEAAmE;AACnE,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,OAAO,GAAG,SAAS,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,4DAA4D;AAC5D,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,kDAAkD;AAClD,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,iBAAiB,CAAC;IAC3B,IAAI,EAAE,gBAAgB,EAAE,CAAC;CAC1B;AAED,8DAA8D;AAC9D,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,KAAK,EAAE,gBAAgB,EAAE,CAAC;CAC3B"}
|
package/dist/parsing/index.js
CHANGED
|
@@ -224,7 +224,7 @@ var _PatternMatcher = class _PatternMatcher {
|
|
|
224
224
|
* 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 (!
|
|
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 (!
|
|
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 (!
|
|
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(
|
|
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(
|
|
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
|
-
|
|
845
|
-
|
|
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.
|