@garrix82/reactgenie-dsl 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.
- package/README.md +436 -0
- package/dist/__test__/dsl-descriptor.test.d.ts +1 -0
- package/dist/__test__/dsl-descriptor.test.js +27 -0
- package/dist/__test__/dsl-descriptor.test.js.map +1 -0
- package/dist/__test__/example_descriptor.d.ts +125 -0
- package/dist/__test__/example_descriptor.js +607 -0
- package/dist/__test__/example_descriptor.js.map +1 -0
- package/dist/__test__/food_descriptor.state.json +1 -0
- package/dist/__test__/food_descriptor.test.d.ts +74 -0
- package/dist/__test__/food_descriptor.test.js +205 -0
- package/dist/__test__/food_descriptor.test.js.map +1 -0
- package/dist/__test__/nl-interpreter-provider-selection.test.d.ts +1 -0
- package/dist/__test__/nl-interpreter-provider-selection.test.js +73 -0
- package/dist/__test__/nl-interpreter-provider-selection.test.js.map +1 -0
- package/dist/__test__/nl-interpreter.test.d.ts +1 -0
- package/dist/__test__/nl-interpreter.test.js +86 -0
- package/dist/__test__/nl-interpreter.test.js.map +1 -0
- package/dist/decorators/__test__/decorators.test.d.ts +1 -0
- package/dist/decorators/__test__/decorators.test.js +182 -0
- package/dist/decorators/__test__/decorators.test.js.map +1 -0
- package/dist/decorators/__test__/inheritance-descriptor.test.d.ts +1 -0
- package/dist/decorators/__test__/inheritance-descriptor.test.js +107 -0
- package/dist/decorators/__test__/inheritance-descriptor.test.js.map +1 -0
- package/dist/decorators/decorators.d.ts +20 -0
- package/dist/decorators/decorators.js +520 -0
- package/dist/decorators/decorators.js.map +1 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.js +19 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/store.d.ts +12 -0
- package/dist/decorators/store.js +43 -0
- package/dist/decorators/store.js.map +1 -0
- package/dist/dsl/__test__/dsl-interpreter.test.d.ts +1 -0
- package/dist/dsl/__test__/dsl-interpreter.test.js +334 -0
- package/dist/dsl/__test__/dsl-interpreter.test.js.map +1 -0
- package/dist/dsl/__test__/parser.gen.test.d.ts +1 -0
- package/dist/dsl/__test__/parser.gen.test.js +283 -0
- package/dist/dsl/__test__/parser.gen.test.js.map +1 -0
- package/dist/dsl/dsl-interpreter.d.ts +66 -0
- package/dist/dsl/dsl-interpreter.js +767 -0
- package/dist/dsl/dsl-interpreter.js.map +1 -0
- package/dist/dsl/index.d.ts +1 -0
- package/dist/dsl/index.js +18 -0
- package/dist/dsl/index.js.map +1 -0
- package/dist/dsl/parser.gen.d.ts +10 -0
- package/dist/dsl/parser.gen.js +1524 -0
- package/dist/dsl/parser.gen.js.map +1 -0
- package/dist/dsl-descriptor.d.ts +75 -0
- package/dist/dsl-descriptor.js +151 -0
- package/dist/dsl-descriptor.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/nl/__test__/context-aware-prompt.test.d.ts +1 -0
- package/dist/nl/__test__/context-aware-prompt.test.js +247 -0
- package/dist/nl/__test__/context-aware-prompt.test.js.map +1 -0
- package/dist/nl/__test__/context-selector.test.d.ts +1 -0
- package/dist/nl/__test__/context-selector.test.js +20 -0
- package/dist/nl/__test__/context-selector.test.js.map +1 -0
- package/dist/nl/__test__/nl-parser-groq-transport.test.d.ts +1 -0
- package/dist/nl/__test__/nl-parser-groq-transport.test.js +87 -0
- package/dist/nl/__test__/nl-parser-groq-transport.test.js.map +1 -0
- package/dist/nl/__test__/nl-parser-openai-parity.test.d.ts +1 -0
- package/dist/nl/__test__/nl-parser-openai-parity.test.js +206 -0
- package/dist/nl/__test__/nl-parser-openai-parity.test.js.map +1 -0
- package/dist/nl/__test__/nl-parser-openai-sampling.test.d.ts +1 -0
- package/dist/nl/__test__/nl-parser-openai-sampling.test.js +44 -0
- package/dist/nl/__test__/nl-parser-openai-sampling.test.js.map +1 -0
- package/dist/nl/__test__/nl-parser-openai-transport.test.d.ts +1 -0
- package/dist/nl/__test__/nl-parser-openai-transport.test.js +55 -0
- package/dist/nl/__test__/nl-parser-openai-transport.test.js.map +1 -0
- package/dist/nl/__test__/nl-parser-utils.test.d.ts +1 -0
- package/dist/nl/__test__/nl-parser-utils.test.js +70 -0
- package/dist/nl/__test__/nl-parser-utils.test.js.map +1 -0
- package/dist/nl/__test__/nl-parser.test.d.ts +1 -0
- package/dist/nl/__test__/nl-parser.test.js +64 -0
- package/dist/nl/__test__/nl-parser.test.js.map +1 -0
- package/dist/nl/__test__/parameter-tuning.test.d.ts +1 -0
- package/dist/nl/__test__/parameter-tuning.test.js +95 -0
- package/dist/nl/__test__/parameter-tuning.test.js.map +1 -0
- package/dist/nl/__test__/semantic-parsing-experiment.test.d.ts +1 -0
- package/dist/nl/__test__/semantic-parsing-experiment.test.js +178 -0
- package/dist/nl/__test__/semantic-parsing-experiment.test.js.map +1 -0
- package/dist/nl/context-selector.d.ts +17 -0
- package/dist/nl/context-selector.js +99 -0
- package/dist/nl/context-selector.js.map +1 -0
- package/dist/nl/index.d.ts +6 -0
- package/dist/nl/index.js +15 -0
- package/dist/nl/index.js.map +1 -0
- package/dist/nl/llm-monitoring.d.ts +49 -0
- package/dist/nl/llm-monitoring.js +243 -0
- package/dist/nl/llm-monitoring.js.map +1 -0
- package/dist/nl/llm-monitoring.test.d.ts +5 -0
- package/dist/nl/llm-monitoring.test.js +101 -0
- package/dist/nl/llm-monitoring.test.js.map +1 -0
- package/dist/nl/nl-parser-groq.d.ts +21 -0
- package/dist/nl/nl-parser-groq.js +357 -0
- package/dist/nl/nl-parser-groq.js.map +1 -0
- package/dist/nl/nl-parser-utils.d.ts +101 -0
- package/dist/nl/nl-parser-utils.js +255 -0
- package/dist/nl/nl-parser-utils.js.map +1 -0
- package/dist/nl/nl-parser.d.ts +30 -0
- package/dist/nl/nl-parser.js +433 -0
- package/dist/nl/nl-parser.js.map +1 -0
- package/dist/nl/prompt-gen.d.ts +93 -0
- package/dist/nl/prompt-gen.js +369 -0
- package/dist/nl/prompt-gen.js.map +1 -0
- package/dist/nl/prompt-res.d.ts +16 -0
- package/dist/nl/prompt-res.js +190 -0
- package/dist/nl/prompt-res.js.map +1 -0
- package/dist/nl-interpreter.d.ts +48 -0
- package/dist/nl-interpreter.js +155 -0
- package/dist/nl-interpreter.js.map +1 -0
- package/lib/__test__/dsl-descriptor.test.ts +27 -0
- package/lib/__test__/example_descriptor.ts +762 -0
- package/lib/__test__/food_descriptor.state.json +1 -0
- package/lib/__test__/food_descriptor.test.ts +331 -0
- package/lib/__test__/nl-interpreter-provider-selection.test.ts +126 -0
- package/lib/__test__/nl-interpreter.test.ts +129 -0
- package/lib/decorators/__test__/decorators.test.ts +177 -0
- package/lib/decorators/__test__/inheritance-descriptor.test.ts +92 -0
- package/lib/decorators/decorators.ts +754 -0
- package/lib/decorators/index.ts +2 -0
- package/lib/decorators/store.ts +47 -0
- package/lib/dsl/__test__/dsl-interpreter.test.ts +453 -0
- package/lib/dsl/__test__/parser.gen.test.ts +296 -0
- package/lib/dsl/dsl-interpreter.ts +974 -0
- package/lib/dsl/index.ts +1 -0
- package/lib/dsl/parser.gen.js +1479 -0
- package/lib/dsl/parser.pegjs +130 -0
- package/lib/dsl-descriptor.ts +241 -0
- package/lib/index.ts +5 -0
- package/lib/nl/__test__/context-aware-prompt.test.ts +372 -0
- package/lib/nl/__test__/context-selector.test.ts +27 -0
- package/lib/nl/__test__/nl-parser-groq-transport.test.ts +139 -0
- package/lib/nl/__test__/nl-parser-openai-parity.test.ts +381 -0
- package/lib/nl/__test__/nl-parser-openai-sampling.test.ts +73 -0
- package/lib/nl/__test__/nl-parser-openai-transport.test.ts +79 -0
- package/lib/nl/__test__/nl-parser-utils.test.ts +98 -0
- package/lib/nl/__test__/nl-parser.test.ts +119 -0
- package/lib/nl/__test__/parameter-tuning.test.ts +137 -0
- package/lib/nl/__test__/semantic-parsing-experiment.test.ts +260 -0
- package/lib/nl/context-selector.ts +123 -0
- package/lib/nl/index.ts +19 -0
- package/lib/nl/llm-monitoring.test.ts +136 -0
- package/lib/nl/llm-monitoring.ts +339 -0
- package/lib/nl/nl-parser-groq.ts +510 -0
- package/lib/nl/nl-parser-utils.ts +310 -0
- package/lib/nl/nl-parser.ts +616 -0
- package/lib/nl/prompt-gen.ts +607 -0
- package/lib/nl/prompt-res.ts +207 -0
- package/lib/nl-interpreter.ts +262 -0
- package/package.json +58 -0
package/README.md
ADDED
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
# ReactGenieDSL
|
|
2
|
+
|
|
3
|
+
> Decorators, DSL execution, and LLM-backed semantic parsing for ReactGenie-style applications
|
|
4
|
+
|
|
5
|
+
> Fork notice: this package snapshot is maintained as a thesis-project fork by [Omkar Mirgal](https://github.com/OmkarMirgal). For the original ReactGenie project, see [StanfordHCI/ReactGenie](https://github.com/StanfordHCI/ReactGenieDSL).
|
|
6
|
+
|
|
7
|
+
## Introduction
|
|
8
|
+
|
|
9
|
+
`@omkarfork/reactgenie-dsl` is the lower-level engine that powers Genie-based apps.
|
|
10
|
+
|
|
11
|
+
It provides:
|
|
12
|
+
|
|
13
|
+
- a decorated object model for app state and actions
|
|
14
|
+
- a shared Redux-backed Genie store
|
|
15
|
+
- a DSL interpreter for explicit command execution
|
|
16
|
+
- an LLM-backed semantic parser that translates natural language into DSL
|
|
17
|
+
- structured response generation for spoken and on-screen feedback
|
|
18
|
+
- monitoring hooks for parser and response calls
|
|
19
|
+
|
|
20
|
+
If you need the React integration layer, voice UI, route handling, or screen-aware `Current()` resolution, use `@omkarfork/reactgenie-lib` on top of this package.
|
|
21
|
+
|
|
22
|
+
This README covers installation, quick start, feature overview, and the current public surface. For deeper implementation details and parser/runtime behavior, see [DEVELOPER_GUIDE.md](./DEVELOPER_GUIDE.md).
|
|
23
|
+
|
|
24
|
+
## Feature Overview
|
|
25
|
+
|
|
26
|
+
ReactGenieDSL currently includes:
|
|
27
|
+
|
|
28
|
+
- Genie model base classes: `GenieObject`, `DataClass`, `HelperClass`
|
|
29
|
+
- decorators: `GenieClass`, `GenieFunction`, `GenieProperty`, `GenieKey`
|
|
30
|
+
- descriptor types: `ClassDescriptor`, `FuncDescriptor`, `FieldDescriptor`, `ParamDescriptor`
|
|
31
|
+
- shared store bootstrap and access: `initGenie`, `genieDispatch`, `sharedStore`, `sharedState`, `AllGenieObjects`
|
|
32
|
+
- DSL execution with `DslInterpreter`
|
|
33
|
+
- stepwise execution introspection with `interpretSteps(...)`
|
|
34
|
+
- JSON-friendly result shaping with `describe(...)` and `describeSteps(...)`
|
|
35
|
+
- built-in collection operators:
|
|
36
|
+
- `matching(...)`
|
|
37
|
+
- `contains(...)`
|
|
38
|
+
- `between(...)`
|
|
39
|
+
- `equals(...)`
|
|
40
|
+
- `sort(...)`
|
|
41
|
+
- `index(...)`
|
|
42
|
+
- `length()`
|
|
43
|
+
- natural-language orchestration with `NlInterpreter`
|
|
44
|
+
- parser backends:
|
|
45
|
+
- `NlParserGroq`
|
|
46
|
+
- `NlParser` for OpenAI-compatible APIs
|
|
47
|
+
- prompt generators:
|
|
48
|
+
- `BasicPromptGen`
|
|
49
|
+
- `DescriptorPromptGen`
|
|
50
|
+
- `ContextAwareDescriptorPromptGen`
|
|
51
|
+
- parser monitoring with `getLLMMonitor(...)`
|
|
52
|
+
- configurable sampling and provider selection
|
|
53
|
+
- structured agent-response generation with normalized fallback handling
|
|
54
|
+
|
|
55
|
+
## Parser Enhancements In The Current Implementation
|
|
56
|
+
|
|
57
|
+
The current parser stack includes several implementation details beyond the older basic prompt flow:
|
|
58
|
+
|
|
59
|
+
- context-aware prompt narrowing that selects only relevant class descriptions and examples
|
|
60
|
+
- lexical ranking of descriptors/examples without an embeddings dependency
|
|
61
|
+
- bounded caching of prompt selections for repeated utterances
|
|
62
|
+
- recent-turn memory plus summarized older-turn context
|
|
63
|
+
- runtime UI context injection for deictic utterances such as "this", "it", or "current"
|
|
64
|
+
- explicit parser rules for:
|
|
65
|
+
- named parameters
|
|
66
|
+
- array-parameter brackets
|
|
67
|
+
- dotted accessor parameters such as `.receivedAt`
|
|
68
|
+
- structured JSON output for command parsing and agent responses
|
|
69
|
+
- lenient-first then strict structured-output retries
|
|
70
|
+
- semantic validation of generated commands through a validator interpreter
|
|
71
|
+
- automatic repair passes when the generated DSL is semantically invalid
|
|
72
|
+
- optional stateful validation retry for the OpenAI Responses path
|
|
73
|
+
- normalized response payloads and safe fallback responses when response synthesis fails
|
|
74
|
+
- LangSmith-compatible monitoring hooks for prompt, token, latency, and cost tracking
|
|
75
|
+
|
|
76
|
+
## Installation
|
|
77
|
+
|
|
78
|
+
Install the current package and `reflect-metadata`:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
npm install @omkarfork/reactgenie-dsl reflect-metadata
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## TypeScript and Babel setup
|
|
85
|
+
|
|
86
|
+
ReactGenieDSL relies on decorator metadata.
|
|
87
|
+
|
|
88
|
+
TypeScript:
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"compilerOptions": {
|
|
93
|
+
"experimentalDecorators": true,
|
|
94
|
+
"emitDecoratorMetadata": true,
|
|
95
|
+
"useDefineForClassFields": false
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Babel:
|
|
101
|
+
|
|
102
|
+
```js
|
|
103
|
+
plugins: [
|
|
104
|
+
["@babel/plugin-proposal-decorators", { legacy: true }],
|
|
105
|
+
["@babel/plugin-transform-class-properties", { loose: true }],
|
|
106
|
+
"babel-plugin-parameter-decorator",
|
|
107
|
+
"babel-plugin-reactgenie"
|
|
108
|
+
]
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Import `reflect-metadata` before any decorated Genie classes are evaluated.
|
|
112
|
+
|
|
113
|
+
## Quick Start
|
|
114
|
+
|
|
115
|
+
### 1. Define a Genie model
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
import "reflect-metadata";
|
|
119
|
+
import {
|
|
120
|
+
DataClass,
|
|
121
|
+
GenieClass,
|
|
122
|
+
GenieFunction,
|
|
123
|
+
GenieKey,
|
|
124
|
+
GenieProperty,
|
|
125
|
+
int,
|
|
126
|
+
} from "@omkarfork/reactgenie-dsl";
|
|
127
|
+
|
|
128
|
+
@GenieClass("A counter the user can inspect or update")
|
|
129
|
+
export class Counter extends DataClass {
|
|
130
|
+
@GenieKey
|
|
131
|
+
@GenieProperty("Stable counter identifier")
|
|
132
|
+
name: string;
|
|
133
|
+
|
|
134
|
+
@GenieProperty("Current count")
|
|
135
|
+
count: int;
|
|
136
|
+
|
|
137
|
+
static Examples = [
|
|
138
|
+
{
|
|
139
|
+
user_utterance: "increment the apples counter",
|
|
140
|
+
example_parsed: 'Counter.findByName(name: "apples").increment()',
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
user_utterance: "what is the apples count",
|
|
144
|
+
example_parsed: 'Counter.findByName(name: "apples").count',
|
|
145
|
+
},
|
|
146
|
+
];
|
|
147
|
+
|
|
148
|
+
constructor({ name, count = 0 }: { name: string; count?: int }) {
|
|
149
|
+
super({ name });
|
|
150
|
+
this.name = name;
|
|
151
|
+
this.count = count;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
static setup() {
|
|
155
|
+
Counter.CreateObject({ name: "apples", count: 2 });
|
|
156
|
+
Counter.CreateObject({ name: "oranges", count: 5 });
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
@GenieFunction("Return the default counter")
|
|
160
|
+
static current(): Counter {
|
|
161
|
+
return Counter.GetObject({ name: "apples" });
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
@GenieFunction("Find a counter by name")
|
|
165
|
+
static findByName({ name }: { name: string }): Counter {
|
|
166
|
+
return Counter.GetObject({ name });
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
@GenieFunction("Increase the counter by one")
|
|
170
|
+
increment(): this {
|
|
171
|
+
this.count += 1;
|
|
172
|
+
return this;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Notes:
|
|
178
|
+
|
|
179
|
+
- use `DataClass` for indexed, retrievable entities
|
|
180
|
+
- use `HelperClass` for nested value objects
|
|
181
|
+
- create objects with `CreateObject(...)`, not `new`
|
|
182
|
+
- `@GenieFunction()` currently expects either no parameters or a single destructured object parameter
|
|
183
|
+
|
|
184
|
+
### 2. Initialize Genie
|
|
185
|
+
|
|
186
|
+
```ts
|
|
187
|
+
import { initGenie } from "@omkarfork/reactgenie-dsl";
|
|
188
|
+
|
|
189
|
+
const store = initGenie();
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
`initGenie()` initializes the shared store, applies registered modifiers, and runs `setup()` on already-registered classes.
|
|
193
|
+
|
|
194
|
+
### 3. Execute explicit DSL
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
import { AllGenieObjects, DslInterpreter } from "@omkarfork/reactgenie-dsl";
|
|
198
|
+
|
|
199
|
+
const descriptors = Object.values(AllGenieObjects).map(
|
|
200
|
+
(klass: any) => klass.ClassDescriptor
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
const interpreter = new DslInterpreter(descriptors);
|
|
204
|
+
|
|
205
|
+
await interpreter.interpret('Counter.findByName(name: "apples").increment()');
|
|
206
|
+
const value = await interpreter.interpret('Counter.findByName(name: "apples").count');
|
|
207
|
+
const described = await interpreter.describe(value);
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### 4. Parse natural language into DSL
|
|
211
|
+
|
|
212
|
+
```ts
|
|
213
|
+
import {
|
|
214
|
+
AllGenieObjects,
|
|
215
|
+
ClassDescriptor,
|
|
216
|
+
ExampleParse,
|
|
217
|
+
GenieObject,
|
|
218
|
+
NlInterpreter,
|
|
219
|
+
} from "@omkarfork/reactgenie-dsl";
|
|
220
|
+
|
|
221
|
+
const descriptors = Object.values(AllGenieObjects).map(
|
|
222
|
+
(klass: any) => klass.ClassDescriptor as ClassDescriptor<GenieObject>
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
const examples: ExampleParse[] = [
|
|
226
|
+
new ExampleParse(
|
|
227
|
+
"increment the apples counter",
|
|
228
|
+
'Counter.findByName(name: "apples").increment()'
|
|
229
|
+
),
|
|
230
|
+
new ExampleParse(
|
|
231
|
+
"what is the apples count",
|
|
232
|
+
'Counter.findByName(name: "apples").count'
|
|
233
|
+
),
|
|
234
|
+
];
|
|
235
|
+
|
|
236
|
+
const interpreter = new NlInterpreter(
|
|
237
|
+
descriptors,
|
|
238
|
+
process.env.LLM_API_KEY!,
|
|
239
|
+
undefined,
|
|
240
|
+
examples
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
const executionResult = await interpreter.interpret("increment the apples counter");
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### 5. Generate a structured response
|
|
247
|
+
|
|
248
|
+
```ts
|
|
249
|
+
const response = await interpreter.respond(
|
|
250
|
+
"increment the apples counter",
|
|
251
|
+
'Counter.findByName(name: "apples").increment()',
|
|
252
|
+
JSON.stringify(await interpreter.dslInterpreter.describe(executionResult))
|
|
253
|
+
);
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
The response payload shape is:
|
|
257
|
+
|
|
258
|
+
```ts
|
|
259
|
+
{
|
|
260
|
+
minimalText: string;
|
|
261
|
+
fullText: string;
|
|
262
|
+
type: "info" | "error" | "success" | "warning";
|
|
263
|
+
shouldSpeak: boolean;
|
|
264
|
+
}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
## Current DSL Capabilities
|
|
268
|
+
|
|
269
|
+
ReactGenieDSL currently supports:
|
|
270
|
+
|
|
271
|
+
- static calls such as `Order.current()`
|
|
272
|
+
- instance calls such as `Order.current().placeOrder()`
|
|
273
|
+
- property access such as `Order.current().status`
|
|
274
|
+
- chained access such as `Order.All().sort(field: .dateTime, ascending: false)[0].restaurant.name`
|
|
275
|
+
- array literals
|
|
276
|
+
- negative indexing
|
|
277
|
+
- collection filters through `matching`, `contains`, `between`, and `equals`
|
|
278
|
+
- collection sorting through `sort`
|
|
279
|
+
- collection indexing through `index(...)` or bracket syntax
|
|
280
|
+
- collection length via `length()`
|
|
281
|
+
|
|
282
|
+
Important parser rules:
|
|
283
|
+
|
|
284
|
+
- parameter names must be explicit
|
|
285
|
+
- accessor parameters for filters/sort must be dotted accessors such as `.name`, not quoted strings
|
|
286
|
+
- when passing an array expression into a function parameter, the expression must be wrapped in `[...]`
|
|
287
|
+
|
|
288
|
+
## Provider Configuration
|
|
289
|
+
|
|
290
|
+
`NlInterpreter` supports `groq` and `openai` parser providers.
|
|
291
|
+
|
|
292
|
+
### Groq example
|
|
293
|
+
|
|
294
|
+
```ts
|
|
295
|
+
const interpreter = new NlInterpreter(
|
|
296
|
+
descriptors,
|
|
297
|
+
process.env.LLM_API_KEY!,
|
|
298
|
+
undefined,
|
|
299
|
+
examples,
|
|
300
|
+
undefined,
|
|
301
|
+
{
|
|
302
|
+
parser: {
|
|
303
|
+
provider: "groq",
|
|
304
|
+
groq: {
|
|
305
|
+
model: "llama-3.3-70b-versatile",
|
|
306
|
+
baseUrl: "https://api.groq.com/openai/v1",
|
|
307
|
+
samplingParams: {
|
|
308
|
+
temperature: 0.2,
|
|
309
|
+
top_p: 1,
|
|
310
|
+
frequency_penalty: 0,
|
|
311
|
+
presence_penalty: 0,
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
}
|
|
316
|
+
);
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
### OpenAI-compatible example
|
|
320
|
+
|
|
321
|
+
```ts
|
|
322
|
+
const interpreter = new NlInterpreter(
|
|
323
|
+
descriptors,
|
|
324
|
+
process.env.LLM_API_KEY!,
|
|
325
|
+
undefined,
|
|
326
|
+
examples,
|
|
327
|
+
undefined,
|
|
328
|
+
{
|
|
329
|
+
parser: {
|
|
330
|
+
provider: "openai",
|
|
331
|
+
openai: {
|
|
332
|
+
baseUrl: "https://api.openai.com/v1",
|
|
333
|
+
model: "gpt-4o-mini",
|
|
334
|
+
statefulValidationRetry: true,
|
|
335
|
+
samplingParams: {
|
|
336
|
+
temperature: 0.2,
|
|
337
|
+
top_p: 1,
|
|
338
|
+
frequency_penalty: 0,
|
|
339
|
+
presence_penalty: 0,
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
}
|
|
344
|
+
);
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
Provider notes:
|
|
348
|
+
|
|
349
|
+
- default provider is `groq`
|
|
350
|
+
- `GENIE_PARSER_PROVIDER` can select the provider if config is omitted
|
|
351
|
+
- OpenAI mode requires an explicit model
|
|
352
|
+
- Groq mode defaults to `llama-3.3-70b-versatile`
|
|
353
|
+
- base URLs are normalized internally to the expected OpenAI-compatible endpoints
|
|
354
|
+
|
|
355
|
+
## Monitoring
|
|
356
|
+
|
|
357
|
+
The NL stack exposes `getLLMMonitor(...)` and integrates with LangSmith-style telemetry.
|
|
358
|
+
|
|
359
|
+
Monitoring supports:
|
|
360
|
+
|
|
361
|
+
- prompt / completion token counts
|
|
362
|
+
- cost metadata when the backend returns it
|
|
363
|
+
- latency tracking
|
|
364
|
+
- parser/response errors
|
|
365
|
+
- optional telemetry bridges for error and message forwarding
|
|
366
|
+
|
|
367
|
+
## Public API At a Glance
|
|
368
|
+
|
|
369
|
+
### Model and decorators
|
|
370
|
+
|
|
371
|
+
- `GenieObject`
|
|
372
|
+
- `DataClass`
|
|
373
|
+
- `HelperClass`
|
|
374
|
+
- `GenieClass`
|
|
375
|
+
- `GenieFunction`
|
|
376
|
+
- `GenieProperty`
|
|
377
|
+
- `GenieKey`
|
|
378
|
+
- `ClassDescriptor`
|
|
379
|
+
- `FuncDescriptor`
|
|
380
|
+
- `FieldDescriptor`
|
|
381
|
+
- `ParamDescriptor`
|
|
382
|
+
- `int`
|
|
383
|
+
- `float`
|
|
384
|
+
- `LazyType`
|
|
385
|
+
|
|
386
|
+
### Store and registry
|
|
387
|
+
|
|
388
|
+
- `initGenie`
|
|
389
|
+
- `genieDispatch`
|
|
390
|
+
- `sharedStore`
|
|
391
|
+
- `sharedState`
|
|
392
|
+
- `AllGenieObjects`
|
|
393
|
+
|
|
394
|
+
### DSL execution
|
|
395
|
+
|
|
396
|
+
- `DslInterpreter`
|
|
397
|
+
- `InterpreterError`
|
|
398
|
+
- `ClassMissingError`
|
|
399
|
+
- `FieldMissingError`
|
|
400
|
+
- `FieldStaticError`
|
|
401
|
+
- `FunctionMissingError`
|
|
402
|
+
- `FunctionStaticError`
|
|
403
|
+
- `InvalidParameterTypeError`
|
|
404
|
+
|
|
405
|
+
### NL parsing and prompting
|
|
406
|
+
|
|
407
|
+
- `NlInterpreter`
|
|
408
|
+
- `NlParser`
|
|
409
|
+
- `NlParserGroq`
|
|
410
|
+
- `BasicPromptGen`
|
|
411
|
+
- `DescriptorPromptGen`
|
|
412
|
+
- `ContextAwareDescriptorPromptGen`
|
|
413
|
+
- `PromptGen`
|
|
414
|
+
- `ExampleParse`
|
|
415
|
+
- `PromptSelectionConfig`
|
|
416
|
+
- `PromptRuntimeContextSetter`
|
|
417
|
+
- `RuntimeUiContext`
|
|
418
|
+
- `PromptInteractionRecord`
|
|
419
|
+
- `PromptInteractionRecorder`
|
|
420
|
+
- `AgentResponsePayload`
|
|
421
|
+
- `ResponseSeverity`
|
|
422
|
+
- `SamplingParams`
|
|
423
|
+
|
|
424
|
+
### Monitoring
|
|
425
|
+
|
|
426
|
+
- `getLLMMonitor`
|
|
427
|
+
- `LLMMonitorTelemetryBridge`
|
|
428
|
+
|
|
429
|
+
## Documentation Split
|
|
430
|
+
|
|
431
|
+
- `README.md`: install, quick start, feature overview, and public API summary
|
|
432
|
+
- `DEVELOPER_GUIDE.md`: deeper package behavior, parser/runtime details, DSL semantics, provider configuration, and troubleshooting
|
|
433
|
+
|
|
434
|
+
## License
|
|
435
|
+
|
|
436
|
+
Apache-2.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const example_descriptor_1 = require("./example_descriptor");
|
|
4
|
+
test("Restaurant Description", async () => {
|
|
5
|
+
const description = example_descriptor_1.Restaurant._ClassDescriptor.description();
|
|
6
|
+
expect(description).toEqual("// A restaurant\n" +
|
|
7
|
+
"class Restaurant {\n" +
|
|
8
|
+
"\tstring name;\n" +
|
|
9
|
+
"\tFood[] menu;\n" +
|
|
10
|
+
"\tint rating;\n" +
|
|
11
|
+
"\tfloat priceGrade;\n" +
|
|
12
|
+
"\tstring cuisine;\n" +
|
|
13
|
+
"\tstring address;\n" +
|
|
14
|
+
"\tOrder[] orders;\n" +
|
|
15
|
+
"\t// All active restaurants\n" +
|
|
16
|
+
"\tstatic Restaurant[] all();\n" +
|
|
17
|
+
"\t// All active restaurants\n" +
|
|
18
|
+
"\tstatic Restaurant[] All();\n" +
|
|
19
|
+
"\t// The current restaurant\n" +
|
|
20
|
+
"\tstatic Restaurant current();\n" +
|
|
21
|
+
"\t// Book a table for a given date time\n" +
|
|
22
|
+
"\tvoid book(dateTime: DateTime? = `DateTime.today()`);\n" +
|
|
23
|
+
"\t// Book numbers tables for a given date time\n" +
|
|
24
|
+
"\tvoid bookTable(dateTime: DateTime?, number: int?);\n" +
|
|
25
|
+
"}");
|
|
26
|
+
});
|
|
27
|
+
//# sourceMappingURL=dsl-descriptor.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dsl-descriptor.test.js","sourceRoot":"","sources":["../../lib/__test__/dsl-descriptor.test.ts"],"names":[],"mappings":";;AAAA,6DAAkD;AAElD,IAAI,CAAC,wBAAwB,EAAE,KAAK,IAAI,EAAE;IACxC,MAAM,WAAW,GAAG,+BAAU,CAAC,gBAAgB,CAAC,WAAW,EAAE,CAAC;IAC9D,MAAM,CAAC,WAAW,CAAC,CAAC,OAAO,CACzB,mBAAmB;QACnB,sBAAsB;QACpB,kBAAkB;QAClB,kBAAkB;QAClB,iBAAiB;QACjB,uBAAuB;QACvB,qBAAqB;QACrB,qBAAqB;QACrB,qBAAqB;QACrB,+BAA+B;QAC/B,gCAAgC;QAChC,+BAA+B;QAC/B,gCAAgC;QAChC,+BAA+B;QAC/B,kCAAkC;QAClC,2CAA2C;QAC3C,0DAA0D;QAC1D,kDAAkD;QAClD,wDAAwD;QACxD,GAAG,CACN,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { ClassDescriptor, DataClass, HelperClass } from "../dsl-descriptor";
|
|
2
|
+
import { ExampleParse } from "../nl";
|
|
3
|
+
import { float, int, LazyType } from "../decorators";
|
|
4
|
+
export declare let recentBooking: any;
|
|
5
|
+
export declare class DateTime extends HelperClass {
|
|
6
|
+
private _date;
|
|
7
|
+
year: number;
|
|
8
|
+
month: number;
|
|
9
|
+
day: number;
|
|
10
|
+
dayOfWeek: string;
|
|
11
|
+
hour: number;
|
|
12
|
+
minute: number;
|
|
13
|
+
private updateDate;
|
|
14
|
+
static today(): DateTime;
|
|
15
|
+
static sunday: number;
|
|
16
|
+
static monday: number;
|
|
17
|
+
static tuesday: number;
|
|
18
|
+
static wednesday: number;
|
|
19
|
+
static thursday: number;
|
|
20
|
+
static friday: number;
|
|
21
|
+
static saturday: number;
|
|
22
|
+
static fromDate(date: Date): DateTime;
|
|
23
|
+
description(): {};
|
|
24
|
+
static compare(a: DateTime, b: DateTime): number;
|
|
25
|
+
constructor({ year, month, day, hour, minute, }: {
|
|
26
|
+
year?: number;
|
|
27
|
+
month?: number;
|
|
28
|
+
day?: number;
|
|
29
|
+
hour?: number;
|
|
30
|
+
minute?: number;
|
|
31
|
+
});
|
|
32
|
+
_getConstructorParams(): any;
|
|
33
|
+
addDateOffset({ year, month, day, hour, minute, }: {
|
|
34
|
+
year: number;
|
|
35
|
+
month: number;
|
|
36
|
+
day: number;
|
|
37
|
+
hour: number;
|
|
38
|
+
minute: number;
|
|
39
|
+
}): this;
|
|
40
|
+
setDate({ year, month, day, hour, minute, day_of_the_week, }: {
|
|
41
|
+
year?: number;
|
|
42
|
+
month?: number;
|
|
43
|
+
day?: number;
|
|
44
|
+
hour?: number;
|
|
45
|
+
minute?: number;
|
|
46
|
+
day_of_the_week?: number;
|
|
47
|
+
}): this;
|
|
48
|
+
toString(): string;
|
|
49
|
+
static _ClassDescriptor: ClassDescriptor<DateTime>;
|
|
50
|
+
}
|
|
51
|
+
export declare class Food extends DataClass {
|
|
52
|
+
static _all: Food[];
|
|
53
|
+
static all(): Food[];
|
|
54
|
+
_price: float;
|
|
55
|
+
name: string;
|
|
56
|
+
price: float;
|
|
57
|
+
restaurant: LazyType<Restaurant>;
|
|
58
|
+
constructor({ name, price, restaurant, }: {
|
|
59
|
+
name: string;
|
|
60
|
+
price: float;
|
|
61
|
+
restaurant: LazyType<Restaurant>;
|
|
62
|
+
});
|
|
63
|
+
update(): Promise<void>;
|
|
64
|
+
description(): {};
|
|
65
|
+
static _ClassDescriptor: ClassDescriptor<Food>;
|
|
66
|
+
}
|
|
67
|
+
export declare class Order extends DataClass {
|
|
68
|
+
static _all: Order[];
|
|
69
|
+
static all(): Order[];
|
|
70
|
+
static _current: Order;
|
|
71
|
+
static current(): Promise<Order>;
|
|
72
|
+
orderId: string;
|
|
73
|
+
dateTime: DateTime;
|
|
74
|
+
foods: Food[];
|
|
75
|
+
restaurant: LazyType<Restaurant>;
|
|
76
|
+
constructor({ orderId, dateTime, foods, restaurant, }: {
|
|
77
|
+
orderId: string;
|
|
78
|
+
dateTime: DateTime;
|
|
79
|
+
foods: Food[];
|
|
80
|
+
restaurant: LazyType<Restaurant> | null;
|
|
81
|
+
});
|
|
82
|
+
addFoods({ foods }: {
|
|
83
|
+
foods: Food[];
|
|
84
|
+
}): void;
|
|
85
|
+
removeFoods({ foods }: {
|
|
86
|
+
foods: Food[];
|
|
87
|
+
}): void;
|
|
88
|
+
placeOrder(): void;
|
|
89
|
+
description(): {};
|
|
90
|
+
static _ClassDescriptor: ClassDescriptor<Order>;
|
|
91
|
+
}
|
|
92
|
+
export declare class Restaurant extends DataClass {
|
|
93
|
+
static _all: Restaurant[];
|
|
94
|
+
orders: Order[];
|
|
95
|
+
static all(): Restaurant[];
|
|
96
|
+
description(): {};
|
|
97
|
+
createFood(name: string, price: float): Food;
|
|
98
|
+
createOrder(orderId: string, dateTime: DateTime, foods: Food[]): Promise<Order>;
|
|
99
|
+
static current(): Promise<Restaurant>;
|
|
100
|
+
book({ dateTime }: {
|
|
101
|
+
dateTime?: DateTime;
|
|
102
|
+
}): void;
|
|
103
|
+
bookTable({ dateTime, number }: {
|
|
104
|
+
dateTime?: DateTime;
|
|
105
|
+
number?: int;
|
|
106
|
+
}): void;
|
|
107
|
+
name: string;
|
|
108
|
+
menu: Food[];
|
|
109
|
+
rating: int;
|
|
110
|
+
priceGrade: float;
|
|
111
|
+
cuisine: string;
|
|
112
|
+
address: string;
|
|
113
|
+
constructor({ name, menu, rating, priceGrade, cuisine, address, }: {
|
|
114
|
+
name: string;
|
|
115
|
+
menu: Food[];
|
|
116
|
+
rating: number;
|
|
117
|
+
priceGrade: number;
|
|
118
|
+
cuisine: string;
|
|
119
|
+
address: string;
|
|
120
|
+
});
|
|
121
|
+
static _ClassDescriptor: ClassDescriptor<Restaurant>;
|
|
122
|
+
}
|
|
123
|
+
export declare const allDescriptors: ClassDescriptor<import("../dsl-descriptor").GenieObject>[];
|
|
124
|
+
export declare const classDescriptions: string[];
|
|
125
|
+
export declare const examples: ExampleParse[];
|