@lokascript/framework 2.3.1 → 2.5.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/api/index.js +29 -516
- package/dist/api/index.js.map +1 -1
- package/dist/core/index.js +20 -128
- package/dist/core/index.js.map +1 -1
- package/dist/core/pattern-matching/index.js +19 -12
- package/dist/core/pattern-matching/index.js.map +1 -1
- package/dist/core/tokenization/index.js.map +1 -1
- package/dist/core/types.d.ts +7 -354
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js +21 -129
- package/dist/core/types.js.map +1 -1
- package/dist/generation/diagnostics.d.ts +5 -115
- package/dist/generation/diagnostics.d.ts.map +1 -1
- package/dist/generation/index.js +20 -77
- package/dist/generation/index.js.map +1 -1
- package/dist/index.cjs +189 -1458
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +108 -1347
- package/dist/index.js.map +1 -1
- package/dist/interfaces/value-extractor.d.ts +20 -0
- package/dist/interfaces/value-extractor.d.ts.map +1 -1
- package/dist/ir/explicit-parser.d.ts +2 -83
- package/dist/ir/explicit-parser.d.ts.map +1 -1
- package/dist/ir/explicit-renderer.d.ts +2 -31
- package/dist/ir/explicit-renderer.d.ts.map +1 -1
- package/dist/ir/index.js +89 -1260
- package/dist/ir/index.js.map +1 -1
- package/dist/ir/protocol-json.d.ts +2 -70
- package/dist/ir/protocol-json.d.ts.map +1 -1
- package/dist/ir/references.d.ts +2 -16
- package/dist/ir/references.d.ts.map +1 -1
- package/dist/ir/types.d.ts +2 -148
- package/dist/ir/types.d.ts.map +1 -1
- package/dist/parsing/index.js +19 -12
- package/dist/parsing/index.js.map +1 -1
- package/dist/schema/command-schema.d.ts +3 -92
- package/dist/schema/command-schema.d.ts.map +1 -1
- package/dist/schema/index.js +3 -20
- package/dist/schema/index.js.map +1 -1
- package/dist/testing/index.js +1066 -712
- package/dist/testing/index.js.map +1 -1
- package/package.json +6 -2
- package/src/core/types.ts +71 -600
- package/src/generation/diagnostics.ts +12 -233
- package/src/interfaces/value-extractor.ts +32 -0
- package/src/ir/explicit-parser.ts +12 -792
- package/src/ir/explicit-renderer.ts +2 -195
- package/src/ir/from-interchange.test.ts +91 -4
- package/src/ir/from-interchange.ts +59 -0
- package/src/ir/protocol-json.test.ts +16 -7
- package/src/ir/protocol-json.ts +9 -748
- package/src/ir/references.ts +2 -30
- package/src/ir/types.ts +18 -190
- package/src/schema/command-schema.ts +3 -134
|
@@ -1,73 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Protocol JSON Serialization
|
|
3
|
-
*
|
|
4
|
-
* Converts between TypeScript SemanticNode (internal representation) and
|
|
5
|
-
* the protocol wire format defined in protocol/spec/wire-format.md.
|
|
6
|
-
*
|
|
7
|
-
* `kind` is optional and defaults to `"command"` when absent.
|
|
8
|
-
* `trigger` is accepted as convenience sugar for wrapping a command in an
|
|
9
|
-
* event handler (e.g., `{ action: "toggle", trigger: { event: "click" } }`).
|
|
10
|
-
*
|
|
11
|
-
* The TypeScript layer is a superset of the protocol spec:
|
|
12
|
-
* - TS has 5 node kinds; protocol has 3 (command, event-handler, compound)
|
|
13
|
-
* - TS uses ReadonlyMap<SemanticRole, SemanticValue>; protocol uses plain Record
|
|
14
|
-
* - TS SelectorValue has optional selectorKind; protocol preserves it when present (v1.1)
|
|
15
|
-
* - TS has PropertyPathValue; protocol flattens it to expression
|
|
16
|
-
* - TS conditional/loop nodes are losslessly encoded as command nodes with
|
|
17
|
-
* thenBranch/elseBranch/loopVariant/loopBody/loopVariable/indexVariable fields (v1.1)
|
|
18
|
-
* - v1.2 adds: annotations, diagnostics, try/catch/finally, async all/race,
|
|
19
|
-
* match/arms, pipe chainType, and LSEEnvelope
|
|
20
|
-
*
|
|
21
|
-
* Use toProtocolJSON() to serialize for tool-to-tool interchange.
|
|
22
|
-
* Use fromProtocolJSON() to deserialize from protocol-conformant sources.
|
|
2
|
+
* Protocol JSON Serialization — re-exported from @lokascript/intent
|
|
23
3
|
*/
|
|
24
|
-
|
|
25
|
-
import type { ProtocolNodeJSON, IRDiagnostic, LSEEnvelopeJSON } from './types';
|
|
26
|
-
/**
|
|
27
|
-
* Serialize a SemanticNode to the protocol full-fidelity JSON wire format.
|
|
28
|
-
*
|
|
29
|
-
* TS-only node kinds are losslessly encoded as command nodes (v1.1):
|
|
30
|
-
* - `conditional` → `command` with thenBranch/elseBranch arrays
|
|
31
|
-
* - `loop` → `command` with loopVariant/loopBody/loopVariable/indexVariable fields
|
|
32
|
-
*
|
|
33
|
-
* v1.2 fields (annotations, diagnostics, try/catch/finally, async, match)
|
|
34
|
-
* are serialized when present on the source node.
|
|
35
|
-
*
|
|
36
|
-
* TS-only value fields:
|
|
37
|
-
* - `property-path` flattened to `expression` using extractValue()
|
|
38
|
-
*/
|
|
39
|
-
export declare function toProtocolJSON(node: SemanticNode): ProtocolNodeJSON;
|
|
40
|
-
/**
|
|
41
|
-
* Deserialize a protocol wire format JSON object into a SemanticNode.
|
|
42
|
-
*
|
|
43
|
-
* Produces all 5 node kinds — detects v1.1/v1.2 fields on command nodes to
|
|
44
|
-
* reconstruct appropriate node types:
|
|
45
|
-
* - thenBranch present → `conditional` node via createConditionalNode()
|
|
46
|
-
* - loopVariant present → `loop` node via createLoopNode()
|
|
47
|
-
* - catchBranch/finallyBranch → try node via createTryNode() (v1.2)
|
|
48
|
-
* - asyncVariant → async node via createAsyncNode() (v1.2)
|
|
49
|
-
* - arms → match node via createMatchNode() (v1.2)
|
|
50
|
-
*
|
|
51
|
-
* Annotations and diagnostics (v1.2) are preserved on all node kinds.
|
|
52
|
-
*/
|
|
53
|
-
export declare function fromProtocolJSON(json: ProtocolNodeJSON): SemanticNode;
|
|
54
|
-
/**
|
|
55
|
-
* Serialize an LSEEnvelope to its JSON wire format.
|
|
56
|
-
*/
|
|
57
|
-
export declare function toEnvelopeJSON(envelope: LSEEnvelope): LSEEnvelopeJSON;
|
|
58
|
-
/**
|
|
59
|
-
* Deserialize an LSEEnvelopeJSON into an LSEEnvelope.
|
|
60
|
-
*/
|
|
61
|
-
export declare function fromEnvelopeJSON(json: LSEEnvelopeJSON): LSEEnvelope;
|
|
62
|
-
/**
|
|
63
|
-
* Check whether an unknown JSON value is an LSE envelope (has lseVersion + nodes).
|
|
64
|
-
*/
|
|
65
|
-
export declare function isEnvelope(json: unknown): json is LSEEnvelopeJSON;
|
|
66
|
-
/**
|
|
67
|
-
* Validate that an unknown value conforms to the protocol JSON format.
|
|
68
|
-
* `kind` is optional (defaults to `"command"`). `trigger` is accepted as
|
|
69
|
-
* convenience sugar for wrapping a command in an event handler.
|
|
70
|
-
* Returns an array of diagnostics (empty array = valid).
|
|
71
|
-
*/
|
|
72
|
-
export declare function validateProtocolJSON(json: unknown): IRDiagnostic[];
|
|
4
|
+
export { toProtocolJSON, fromProtocolJSON, validateProtocolJSON, toEnvelopeJSON, fromEnvelopeJSON, isEnvelope, } from '@lokascript/intent';
|
|
73
5
|
//# sourceMappingURL=protocol-json.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol-json.d.ts","sourceRoot":"","sources":["../../src/ir/protocol-json.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"protocol-json.d.ts","sourceRoot":"","sources":["../../src/ir/protocol-json.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,gBAAgB,EAChB,UAAU,GACX,MAAM,oBAAoB,CAAC"}
|
package/dist/ir/references.d.ts
CHANGED
|
@@ -1,19 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Reference Validation
|
|
3
|
-
*
|
|
4
|
-
* Configurable validation for reference values (me, you, it, result, etc.).
|
|
5
|
-
* Domain DSLs can provide custom reference sets.
|
|
2
|
+
* Reference Validation — re-exported from @lokascript/intent
|
|
6
3
|
*/
|
|
7
|
-
|
|
8
|
-
* Default set of valid references.
|
|
9
|
-
* Covers the common hyperscript references; domain DSLs can extend or replace.
|
|
10
|
-
*/
|
|
11
|
-
export declare const DEFAULT_REFERENCES: ReadonlySet<string>;
|
|
12
|
-
/**
|
|
13
|
-
* Check if a value is a valid reference name.
|
|
14
|
-
*
|
|
15
|
-
* @param value - The string to check
|
|
16
|
-
* @param referenceSet - Custom reference set (defaults to DEFAULT_REFERENCES)
|
|
17
|
-
*/
|
|
18
|
-
export declare function isValidReference(value: string, referenceSet?: ReadonlySet<string>): boolean;
|
|
4
|
+
export { DEFAULT_REFERENCES, isValidReference } from '@lokascript/intent';
|
|
19
5
|
//# sourceMappingURL=references.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"references.d.ts","sourceRoot":"","sources":["../../src/ir/references.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"references.d.ts","sourceRoot":"","sources":["../../src/ir/references.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/ir/types.d.ts
CHANGED
|
@@ -1,151 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* IR
|
|
3
|
-
*
|
|
4
|
-
* Types for the explicit bracket syntax, LLM JSON format, and
|
|
5
|
-
* schema-based validation. These are domain-agnostic — they work
|
|
6
|
-
* for any DSL built on the framework.
|
|
2
|
+
* IR Types — re-exported from @lokascript/intent
|
|
7
3
|
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Structured input format for LLMs.
|
|
11
|
-
* No parsing ambiguity — action and roles are explicitly typed.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```json
|
|
15
|
-
* {
|
|
16
|
-
* "action": "toggle",
|
|
17
|
-
* "roles": { "patient": { "type": "selector", "value": ".active" } },
|
|
18
|
-
* "trigger": { "event": "click" }
|
|
19
|
-
* }
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export interface SemanticJSON {
|
|
23
|
-
/** The command/action name */
|
|
24
|
-
action: string;
|
|
25
|
-
/** Named semantic roles with typed values */
|
|
26
|
-
roles: Record<string, SemanticJSONValue>;
|
|
27
|
-
/** Optional event trigger (wraps command in event handler) */
|
|
28
|
-
trigger?: {
|
|
29
|
-
event: string;
|
|
30
|
-
modifiers?: Record<string, unknown>;
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* A typed value in the LLM JSON format.
|
|
35
|
-
*/
|
|
36
|
-
export interface SemanticJSONValue {
|
|
37
|
-
type: 'selector' | 'literal' | 'reference' | 'expression' | 'property-path' | 'flag';
|
|
38
|
-
value: string | number | boolean;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Interface for optional schema-based role validation in the explicit parser.
|
|
42
|
-
* Consumers provide this to validate roles against command definitions.
|
|
43
|
-
*
|
|
44
|
-
* When not provided, the parser accepts any role names.
|
|
45
|
-
*/
|
|
46
|
-
export interface SchemaLookup {
|
|
47
|
-
getSchema(action: string): CommandSchema | undefined;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Options for parseExplicit().
|
|
51
|
-
*/
|
|
52
|
-
export interface ParseExplicitOptions {
|
|
53
|
-
/** Optional schema lookup for role validation */
|
|
54
|
-
schemaLookup?: SchemaLookup;
|
|
55
|
-
/** Custom set of valid reference names (defaults to DEFAULT_REFERENCES) */
|
|
56
|
-
referenceSet?: ReadonlySet<string>;
|
|
57
|
-
/**
|
|
58
|
-
* When true, validation errors are collected as diagnostics on the
|
|
59
|
-
* returned node instead of throwing. Fatal parse errors (missing brackets,
|
|
60
|
-
* empty input) still throw. Default: false.
|
|
61
|
-
*/
|
|
62
|
-
collectDiagnostics?: boolean;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* A diagnostic message from IR validation.
|
|
66
|
-
*
|
|
67
|
-
* Uses required `code` field (compatible with both framework Diagnostic
|
|
68
|
-
* and compilation-service Diagnostic types via structural typing).
|
|
69
|
-
*/
|
|
70
|
-
export interface IRDiagnostic {
|
|
71
|
-
severity: 'error' | 'warning' | 'info';
|
|
72
|
-
code: string;
|
|
73
|
-
message: string;
|
|
74
|
-
suggestion?: string;
|
|
75
|
-
}
|
|
76
|
-
export type ProtocolNodeKind = 'command' | 'event-handler' | 'compound';
|
|
77
|
-
export type ProtocolChainType = 'then' | 'and' | 'async' | 'sequential' | 'pipe';
|
|
78
|
-
/**
|
|
79
|
-
* A typed semantic value in the protocol full-fidelity JSON format.
|
|
80
|
-
* Matches protocol/spec/wire-format.md "Value Shapes" table.
|
|
81
|
-
*/
|
|
82
|
-
export interface ProtocolValueJSON {
|
|
83
|
-
type: 'selector' | 'literal' | 'reference' | 'expression' | 'property-path' | 'flag';
|
|
84
|
-
value?: string | number | boolean;
|
|
85
|
-
dataType?: 'string' | 'number' | 'boolean' | 'duration';
|
|
86
|
-
raw?: string;
|
|
87
|
-
name?: string;
|
|
88
|
-
enabled?: boolean;
|
|
89
|
-
selectorKind?: 'id' | 'class' | 'attribute' | 'element' | 'complex';
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Protocol JSON node — matches protocol/spec/wire-format.md.
|
|
93
|
-
* Produced by toProtocolJSON() and consumed by fromProtocolJSON().
|
|
94
|
-
*
|
|
95
|
-
* `kind` defaults to `"command"` when omitted.
|
|
96
|
-
* `trigger` is convenience sugar that wraps a command in an event handler.
|
|
97
|
-
*/
|
|
98
|
-
export interface ProtocolNodeJSON {
|
|
99
|
-
kind?: ProtocolNodeKind;
|
|
100
|
-
action: string;
|
|
101
|
-
roles: Record<string, ProtocolValueJSON>;
|
|
102
|
-
trigger?: {
|
|
103
|
-
event: string;
|
|
104
|
-
modifiers?: Record<string, unknown>;
|
|
105
|
-
};
|
|
106
|
-
body?: ProtocolNodeJSON[];
|
|
107
|
-
statements?: ProtocolNodeJSON[];
|
|
108
|
-
chainType?: ProtocolChainType;
|
|
109
|
-
thenBranch?: ProtocolNodeJSON[];
|
|
110
|
-
elseBranch?: ProtocolNodeJSON[];
|
|
111
|
-
loopVariant?: 'forever' | 'times' | 'for' | 'while' | 'until';
|
|
112
|
-
loopBody?: ProtocolNodeJSON[];
|
|
113
|
-
loopVariable?: string;
|
|
114
|
-
indexVariable?: string;
|
|
115
|
-
diagnostics?: ProtocolDiagnosticJSON[];
|
|
116
|
-
annotations?: AnnotationJSON[];
|
|
117
|
-
catchBranch?: ProtocolNodeJSON[];
|
|
118
|
-
finallyBranch?: ProtocolNodeJSON[];
|
|
119
|
-
asyncVariant?: 'all' | 'race';
|
|
120
|
-
asyncBody?: ProtocolNodeJSON[];
|
|
121
|
-
arms?: MatchArmJSON[];
|
|
122
|
-
defaultArm?: ProtocolNodeJSON[];
|
|
123
|
-
}
|
|
124
|
-
/** A diagnostic in protocol wire format (v1.2, extended v1.2.1). */
|
|
125
|
-
export interface ProtocolDiagnosticJSON {
|
|
126
|
-
level: 'error' | 'warning' | 'info';
|
|
127
|
-
role?: string;
|
|
128
|
-
message: string;
|
|
129
|
-
code?: string;
|
|
130
|
-
/** v1.2.1: source parser/stage that produced this diagnostic. */
|
|
131
|
-
source?: string;
|
|
132
|
-
/** v1.2.1: actionable fix suggestions. */
|
|
133
|
-
suggestions?: string[];
|
|
134
|
-
}
|
|
135
|
-
/** A metadata annotation in protocol wire format (v1.2). */
|
|
136
|
-
export interface AnnotationJSON {
|
|
137
|
-
name: string;
|
|
138
|
-
value?: string;
|
|
139
|
-
}
|
|
140
|
-
/** A match arm in protocol wire format (v1.2). */
|
|
141
|
-
export interface MatchArmJSON {
|
|
142
|
-
pattern: ProtocolValueJSON;
|
|
143
|
-
body: ProtocolNodeJSON[];
|
|
144
|
-
}
|
|
145
|
-
/** Versioned envelope for multi-node LSE documents (v1.2). */
|
|
146
|
-
export interface LSEEnvelopeJSON {
|
|
147
|
-
lseVersion: string;
|
|
148
|
-
features?: string[];
|
|
149
|
-
nodes: ProtocolNodeJSON[];
|
|
150
|
-
}
|
|
4
|
+
export type { SemanticJSON, SemanticJSONValue, SchemaLookup, ParseExplicitOptions, IRDiagnostic, ProtocolNodeKind, ProtocolChainType, ProtocolValueJSON, ProtocolNodeJSON, ProtocolDiagnosticJSON, AnnotationJSON, MatchArmJSON, LSEEnvelopeJSON, } from '@lokascript/intent';
|
|
151
5
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/ir/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/ir/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/ir/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,YAAY,EACV,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,oBAAoB,EACpB,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,EACtB,cAAc,EACd,YAAY,EACZ,eAAe,GAChB,MAAM,oBAAoB,CAAC"}
|
package/dist/parsing/index.js
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
// src/core/types.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
import {
|
|
3
|
+
createLiteral,
|
|
4
|
+
createSelector,
|
|
5
|
+
createReference,
|
|
6
|
+
createPropertyPath,
|
|
7
|
+
createExpression,
|
|
8
|
+
createFlag,
|
|
9
|
+
createCommandNode,
|
|
10
|
+
createEventHandlerNode,
|
|
11
|
+
createConditionalNode,
|
|
12
|
+
createCompoundNode,
|
|
13
|
+
createLoopNode,
|
|
14
|
+
createTryNode,
|
|
15
|
+
createAsyncNode,
|
|
16
|
+
createMatchNode,
|
|
17
|
+
extractValue,
|
|
18
|
+
extractRoleValue,
|
|
19
|
+
getRoleValue
|
|
20
|
+
} from "@lokascript/intent";
|
|
14
21
|
|
|
15
22
|
// src/core/logger.ts
|
|
16
23
|
var DebugLogger = class {
|