@lokascript/framework 2.0.0 → 2.2.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 +1438 -21
- package/dist/api/index.js.map +1 -1
- package/dist/core/index.js +247 -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/tokenization/index.js +133 -0
- package/dist/core/tokenization/index.js.map +1 -1
- package/dist/core/tokenization/morphology/base-normalizer.d.ts +94 -0
- package/dist/core/tokenization/morphology/base-normalizer.d.ts.map +1 -0
- package/dist/core/tokenization/morphology/index.d.ts +3 -1
- package/dist/core/tokenization/morphology/index.d.ts.map +1 -1
- package/dist/core/types.d.ts +81 -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 +3264 -132
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3223 -132
- package/dist/index.js.map +1 -1
- package/dist/ir/explicit-parser.d.ts +86 -0
- package/dist/ir/explicit-parser.d.ts.map +1 -0
- package/dist/ir/explicit-renderer.d.ts +34 -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 +31 -0
- package/dist/ir/index.d.ts.map +1 -0
- package/dist/ir/index.js +1934 -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/to-runtime-ast.d.ts +53 -0
- package/dist/ir/to-runtime-ast.d.ts.map +1 -0
- package/dist/ir/types.d.ts +151 -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 +8673 -8260
- 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/tokenization/morphology/base-normalizer.ts +249 -0
- package/src/core/tokenization/morphology/index.ts +3 -1
- package/src/core/types.ts +147 -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 +29 -0
- package/src/integration/llm-lse-integration.test.ts +457 -0
- package/src/ir/conformance.test.ts +120 -0
- package/src/ir/explicit-parser.test.ts +612 -0
- package/src/ir/explicit-parser.ts +793 -0
- package/src/ir/explicit-renderer.test.ts +229 -0
- package/src/ir/explicit-renderer.ts +198 -0
- package/src/ir/from-interchange.test.ts +853 -0
- package/src/ir/from-interchange.ts +594 -0
- package/src/ir/index.ts +77 -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 +1187 -0
- package/src/ir/protocol-json.ts +751 -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/to-runtime-ast.ts +203 -0
- package/src/ir/types.ts +191 -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,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SemanticNode → Runtime AST Converter
|
|
3
|
+
*
|
|
4
|
+
* Converts framework SemanticNode (LSE IR) to a structural AST format
|
|
5
|
+
* that the core runtime can execute directly. Uses structural typing
|
|
6
|
+
* to avoid a dependency on the core package.
|
|
7
|
+
*
|
|
8
|
+
* This is the canonical converter — AOT compiler delegates to it.
|
|
9
|
+
*
|
|
10
|
+
* The output matches the core runtime's expected node shapes:
|
|
11
|
+
* - `{ type: 'command', name, args, roles }` → processCommand()
|
|
12
|
+
* - `{ type: 'event', event, modifiers, body }` → adapted to executeEventHandler()
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type {
|
|
16
|
+
SemanticNode,
|
|
17
|
+
SemanticValue,
|
|
18
|
+
EventHandlerSemanticNode,
|
|
19
|
+
ConditionalSemanticNode,
|
|
20
|
+
LoopSemanticNode,
|
|
21
|
+
} from '../core/types';
|
|
22
|
+
|
|
23
|
+
// =============================================================================
|
|
24
|
+
// Structural output types (no core package dependency)
|
|
25
|
+
// =============================================================================
|
|
26
|
+
|
|
27
|
+
/** Minimal AST node that the core runtime can execute. */
|
|
28
|
+
export interface RuntimeASTNode {
|
|
29
|
+
readonly type: string;
|
|
30
|
+
readonly [key: string]: unknown;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Command node shape expected by runtime's processCommand(). */
|
|
34
|
+
export interface RuntimeCommandNode extends RuntimeASTNode {
|
|
35
|
+
readonly type: 'command';
|
|
36
|
+
readonly name: string;
|
|
37
|
+
readonly args: RuntimeASTNode[];
|
|
38
|
+
readonly roles?: Readonly<Record<string, RuntimeASTNode>>;
|
|
39
|
+
readonly modifiers?: Record<string, unknown>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Event node shape expected by runtime's event adapter. */
|
|
43
|
+
export interface RuntimeEventNode extends RuntimeASTNode {
|
|
44
|
+
readonly type: 'event';
|
|
45
|
+
readonly event: string;
|
|
46
|
+
readonly modifiers: Record<string, unknown>;
|
|
47
|
+
readonly body: RuntimeASTNode[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// =============================================================================
|
|
51
|
+
// Converter
|
|
52
|
+
// =============================================================================
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Convert a SemanticNode to a RuntimeASTNode that the core runtime can execute.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* import { parseExplicit } from '@lokascript/framework/ir';
|
|
60
|
+
* import { semanticNodeToRuntimeAST } from '@lokascript/framework/ir';
|
|
61
|
+
*
|
|
62
|
+
* const node = parseExplicit('[toggle patient:.active]');
|
|
63
|
+
* const ast = semanticNodeToRuntimeAST(node);
|
|
64
|
+
* // { type: 'command', name: 'toggle', args: [{ type: 'selector', value: '.active' }], roles: { patient: ... } }
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export function semanticNodeToRuntimeAST(node: SemanticNode): RuntimeASTNode {
|
|
68
|
+
switch (node.kind) {
|
|
69
|
+
case 'event-handler':
|
|
70
|
+
return convertEventHandler(node as EventHandlerSemanticNode);
|
|
71
|
+
|
|
72
|
+
case 'conditional':
|
|
73
|
+
return convertConditional(node as ConditionalSemanticNode);
|
|
74
|
+
|
|
75
|
+
case 'loop':
|
|
76
|
+
return convertLoop(node as LoopSemanticNode);
|
|
77
|
+
|
|
78
|
+
case 'compound': {
|
|
79
|
+
const compound = node as SemanticNode & { statements?: SemanticNode[]; chainType?: string };
|
|
80
|
+
const commands = (compound.statements ?? []).map(semanticNodeToRuntimeAST);
|
|
81
|
+
return {
|
|
82
|
+
type: 'CommandSequence',
|
|
83
|
+
commands,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
case 'command':
|
|
88
|
+
default:
|
|
89
|
+
return convertCommand(node);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function convertEventHandler(eh: EventHandlerSemanticNode): RuntimeEventNode {
|
|
94
|
+
const eventValue = eh.roles.get('event');
|
|
95
|
+
const eventName = eventValue && 'value' in eventValue ? String(eventValue.value) : 'click';
|
|
96
|
+
|
|
97
|
+
const modifiers: Record<string, unknown> = {};
|
|
98
|
+
if (eh.eventModifiers) {
|
|
99
|
+
if (eh.eventModifiers.once) modifiers.once = true;
|
|
100
|
+
if (eh.eventModifiers.debounce) modifiers.debounce = eh.eventModifiers.debounce;
|
|
101
|
+
if (eh.eventModifiers.throttle) modifiers.throttle = eh.eventModifiers.throttle;
|
|
102
|
+
if (eh.eventModifiers.queue) modifiers.queue = eh.eventModifiers.queue;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
type: 'event',
|
|
107
|
+
event: eventName,
|
|
108
|
+
modifiers,
|
|
109
|
+
body: (eh.body ?? []).map(semanticNodeToRuntimeAST),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function convertCommand(node: SemanticNode): RuntimeCommandNode {
|
|
114
|
+
const roles: Record<string, RuntimeASTNode> = {};
|
|
115
|
+
const args: RuntimeASTNode[] = [];
|
|
116
|
+
|
|
117
|
+
for (const [roleName, value] of node.roles) {
|
|
118
|
+
const astValue = semanticValueToAST(value);
|
|
119
|
+
roles[roleName] = astValue;
|
|
120
|
+
args.push(astValue);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
type: 'command',
|
|
125
|
+
name: node.action,
|
|
126
|
+
args,
|
|
127
|
+
roles,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function convertConditional(node: ConditionalSemanticNode): RuntimeASTNode {
|
|
132
|
+
const conditionValue = node.roles.get('condition');
|
|
133
|
+
return {
|
|
134
|
+
type: 'command',
|
|
135
|
+
name: 'if',
|
|
136
|
+
args: conditionValue ? [semanticValueToAST(conditionValue)] : [],
|
|
137
|
+
condition: conditionValue ? semanticValueToAST(conditionValue) : undefined,
|
|
138
|
+
thenBranch: (node.thenBranch ?? []).map(semanticNodeToRuntimeAST),
|
|
139
|
+
elseBranch: (node.elseBranch ?? []).map(semanticNodeToRuntimeAST),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function convertLoop(node: LoopSemanticNode): RuntimeASTNode {
|
|
144
|
+
const countValue = node.roles.get('patient') || node.roles.get('count');
|
|
145
|
+
return {
|
|
146
|
+
type: 'command',
|
|
147
|
+
name: 'repeat',
|
|
148
|
+
args: countValue ? [semanticValueToAST(countValue)] : [],
|
|
149
|
+
loopVariant: node.loopVariant ?? 'forever',
|
|
150
|
+
body: (node.body ?? []).map(semanticNodeToRuntimeAST),
|
|
151
|
+
loopVariable: node.loopVariable,
|
|
152
|
+
indexVariable: node.indexVariable,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Convert a SemanticValue to a RuntimeASTNode.
|
|
158
|
+
*/
|
|
159
|
+
export function semanticValueToAST(value: SemanticValue): RuntimeASTNode {
|
|
160
|
+
switch (value.type) {
|
|
161
|
+
case 'selector':
|
|
162
|
+
return { type: 'selector', value: value.value as string };
|
|
163
|
+
|
|
164
|
+
case 'reference':
|
|
165
|
+
return { type: 'identifier', value: value.value as string };
|
|
166
|
+
|
|
167
|
+
case 'literal': {
|
|
168
|
+
const lit = value as { value: unknown; dataType?: string };
|
|
169
|
+
if (lit.dataType === 'duration') {
|
|
170
|
+
const str = String(lit.value);
|
|
171
|
+
const match = /^(\d+(?:\.\d+)?)(ms|s)$/.exec(str);
|
|
172
|
+
if (match) {
|
|
173
|
+
const ms = match[2] === 's' ? parseFloat(match[1]) * 1000 : parseFloat(match[1]);
|
|
174
|
+
return { type: 'literal', value: ms };
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return { type: 'literal', value: lit.value as string | number | boolean | null };
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
case 'property-path': {
|
|
181
|
+
const pp = value as import('../core/types').PropertyPathValue;
|
|
182
|
+
const objectAST = semanticValueToAST(pp.object);
|
|
183
|
+
return {
|
|
184
|
+
type: 'member',
|
|
185
|
+
object: objectAST,
|
|
186
|
+
property: pp.property,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
case 'expression': {
|
|
191
|
+
const expr = value as { raw: string };
|
|
192
|
+
return { type: 'expression', value: expr.raw };
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
case 'flag': {
|
|
196
|
+
const flag = value as { name: string; enabled: boolean };
|
|
197
|
+
return { type: 'literal', value: flag.enabled };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
default:
|
|
201
|
+
return { type: 'literal', value: String((value as { value?: unknown }).value ?? '') };
|
|
202
|
+
}
|
|
203
|
+
}
|
package/src/ir/types.ts
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IR (Intermediate Representation) Types
|
|
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.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { CommandSchema } from '../schema/command-schema';
|
|
10
|
+
|
|
11
|
+
// =============================================================================
|
|
12
|
+
// LLM JSON Format
|
|
13
|
+
// =============================================================================
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Structured input format for LLMs.
|
|
17
|
+
* No parsing ambiguity — action and roles are explicitly typed.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```json
|
|
21
|
+
* {
|
|
22
|
+
* "action": "toggle",
|
|
23
|
+
* "roles": { "patient": { "type": "selector", "value": ".active" } },
|
|
24
|
+
* "trigger": { "event": "click" }
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export interface SemanticJSON {
|
|
29
|
+
/** The command/action name */
|
|
30
|
+
action: string;
|
|
31
|
+
/** Named semantic roles with typed values */
|
|
32
|
+
roles: Record<string, SemanticJSONValue>;
|
|
33
|
+
/** Optional event trigger (wraps command in event handler) */
|
|
34
|
+
trigger?: {
|
|
35
|
+
event: string;
|
|
36
|
+
modifiers?: Record<string, unknown>;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A typed value in the LLM JSON format.
|
|
42
|
+
*/
|
|
43
|
+
export interface SemanticJSONValue {
|
|
44
|
+
type: 'selector' | 'literal' | 'reference' | 'expression' | 'property-path' | 'flag';
|
|
45
|
+
value: string | number | boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// =============================================================================
|
|
49
|
+
// Schema Lookup
|
|
50
|
+
// =============================================================================
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Interface for optional schema-based role validation in the explicit parser.
|
|
54
|
+
* Consumers provide this to validate roles against command definitions.
|
|
55
|
+
*
|
|
56
|
+
* When not provided, the parser accepts any role names.
|
|
57
|
+
*/
|
|
58
|
+
export interface SchemaLookup {
|
|
59
|
+
getSchema(action: string): CommandSchema | undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Options for parseExplicit().
|
|
64
|
+
*/
|
|
65
|
+
export interface ParseExplicitOptions {
|
|
66
|
+
/** Optional schema lookup for role validation */
|
|
67
|
+
schemaLookup?: SchemaLookup;
|
|
68
|
+
/** Custom set of valid reference names (defaults to DEFAULT_REFERENCES) */
|
|
69
|
+
referenceSet?: ReadonlySet<string>;
|
|
70
|
+
/**
|
|
71
|
+
* When true, validation errors are collected as diagnostics on the
|
|
72
|
+
* returned node instead of throwing. Fatal parse errors (missing brackets,
|
|
73
|
+
* empty input) still throw. Default: false.
|
|
74
|
+
*/
|
|
75
|
+
collectDiagnostics?: boolean;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// =============================================================================
|
|
79
|
+
// Diagnostics
|
|
80
|
+
// =============================================================================
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* A diagnostic message from IR validation.
|
|
84
|
+
*
|
|
85
|
+
* Uses required `code` field (compatible with both framework Diagnostic
|
|
86
|
+
* and compilation-service Diagnostic types via structural typing).
|
|
87
|
+
*/
|
|
88
|
+
export interface IRDiagnostic {
|
|
89
|
+
severity: 'error' | 'warning' | 'info';
|
|
90
|
+
code: string;
|
|
91
|
+
message: string;
|
|
92
|
+
suggestion?: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// =============================================================================
|
|
96
|
+
// Protocol Full-Fidelity JSON Format
|
|
97
|
+
// =============================================================================
|
|
98
|
+
// These types match the wire format spec (protocol/spec/wire-format.md).
|
|
99
|
+
// Wire format has 3 node kinds; TS-only kinds (conditional, loop) are losslessly
|
|
100
|
+
// encoded as command nodes with v1.1 extension fields.
|
|
101
|
+
// property-path is flattened to expression.
|
|
102
|
+
|
|
103
|
+
export type ProtocolNodeKind = 'command' | 'event-handler' | 'compound';
|
|
104
|
+
export type ProtocolChainType = 'then' | 'and' | 'async' | 'sequential' | 'pipe';
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* A typed semantic value in the protocol full-fidelity JSON format.
|
|
108
|
+
* Matches protocol/spec/wire-format.md "Value Shapes" table.
|
|
109
|
+
*/
|
|
110
|
+
export interface ProtocolValueJSON {
|
|
111
|
+
type: 'selector' | 'literal' | 'reference' | 'expression' | 'property-path' | 'flag';
|
|
112
|
+
value?: string | number | boolean;
|
|
113
|
+
dataType?: 'string' | 'number' | 'boolean' | 'duration';
|
|
114
|
+
raw?: string; // expression only
|
|
115
|
+
name?: string; // flag only
|
|
116
|
+
enabled?: boolean; // flag only
|
|
117
|
+
selectorKind?: 'id' | 'class' | 'attribute' | 'element' | 'complex'; // selector only, optional
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Protocol JSON node — matches protocol/spec/wire-format.md.
|
|
122
|
+
* Produced by toProtocolJSON() and consumed by fromProtocolJSON().
|
|
123
|
+
*
|
|
124
|
+
* `kind` defaults to `"command"` when omitted.
|
|
125
|
+
* `trigger` is convenience sugar that wraps a command in an event handler.
|
|
126
|
+
*/
|
|
127
|
+
export interface ProtocolNodeJSON {
|
|
128
|
+
kind?: ProtocolNodeKind; // defaults to "command" when absent
|
|
129
|
+
action: string;
|
|
130
|
+
roles: Record<string, ProtocolValueJSON>;
|
|
131
|
+
trigger?: { event: string; modifiers?: Record<string, unknown> }; // convenience sugar
|
|
132
|
+
body?: ProtocolNodeJSON[]; // event-handler body OR try body (v1.2)
|
|
133
|
+
statements?: ProtocolNodeJSON[]; // compound only
|
|
134
|
+
chainType?: ProtocolChainType; // compound only
|
|
135
|
+
// Conditional fields (v1.1)
|
|
136
|
+
thenBranch?: ProtocolNodeJSON[];
|
|
137
|
+
elseBranch?: ProtocolNodeJSON[];
|
|
138
|
+
// Loop fields (v1.1)
|
|
139
|
+
loopVariant?: 'forever' | 'times' | 'for' | 'while' | 'until';
|
|
140
|
+
loopBody?: ProtocolNodeJSON[];
|
|
141
|
+
loopVariable?: string;
|
|
142
|
+
indexVariable?: string;
|
|
143
|
+
// Type constraint diagnostics (v1.2)
|
|
144
|
+
diagnostics?: ProtocolDiagnosticJSON[];
|
|
145
|
+
// Metadata annotations (v1.2)
|
|
146
|
+
annotations?: AnnotationJSON[];
|
|
147
|
+
// Error handling: try/catch/finally (v1.2)
|
|
148
|
+
catchBranch?: ProtocolNodeJSON[];
|
|
149
|
+
finallyBranch?: ProtocolNodeJSON[];
|
|
150
|
+
// Async coordination: all/race (v1.2)
|
|
151
|
+
asyncVariant?: 'all' | 'race';
|
|
152
|
+
asyncBody?: ProtocolNodeJSON[];
|
|
153
|
+
// Pattern matching: match/arms (v1.2)
|
|
154
|
+
arms?: MatchArmJSON[];
|
|
155
|
+
defaultArm?: ProtocolNodeJSON[];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// =============================================================================
|
|
159
|
+
// v1.2 Sub-types
|
|
160
|
+
// =============================================================================
|
|
161
|
+
|
|
162
|
+
/** A diagnostic in protocol wire format (v1.2, extended v1.2.1). */
|
|
163
|
+
export interface ProtocolDiagnosticJSON {
|
|
164
|
+
level: 'error' | 'warning' | 'info';
|
|
165
|
+
role?: string;
|
|
166
|
+
message: string;
|
|
167
|
+
code?: string;
|
|
168
|
+
/** v1.2.1: source parser/stage that produced this diagnostic. */
|
|
169
|
+
source?: string;
|
|
170
|
+
/** v1.2.1: actionable fix suggestions. */
|
|
171
|
+
suggestions?: string[];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** A metadata annotation in protocol wire format (v1.2). */
|
|
175
|
+
export interface AnnotationJSON {
|
|
176
|
+
name: string;
|
|
177
|
+
value?: string;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** A match arm in protocol wire format (v1.2). */
|
|
181
|
+
export interface MatchArmJSON {
|
|
182
|
+
pattern: ProtocolValueJSON;
|
|
183
|
+
body: ProtocolNodeJSON[];
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Versioned envelope for multi-node LSE documents (v1.2). */
|
|
187
|
+
export interface LSEEnvelopeJSON {
|
|
188
|
+
lseVersion: string;
|
|
189
|
+
features?: string[];
|
|
190
|
+
nodes: ProtocolNodeJSON[];
|
|
191
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM Prompt Generation
|
|
3
|
+
*
|
|
4
|
+
* Auto-generates system prompts from CommandSchema[] for teaching LLMs
|
|
5
|
+
* to output valid LokaScript Explicit Syntax.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export type {
|
|
9
|
+
PromptGeneratorConfig,
|
|
10
|
+
GeneratedPrompt,
|
|
11
|
+
PromptSection,
|
|
12
|
+
PromptMetadata,
|
|
13
|
+
} from './types';
|
|
14
|
+
|
|
15
|
+
export { generatePrompt, generateExamples, generateProtocolReference } from './prompt-generator';
|