@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.
Files changed (153) hide show
  1. package/README.md +436 -0
  2. package/dist/__test__/dsl-descriptor.test.d.ts +1 -0
  3. package/dist/__test__/dsl-descriptor.test.js +27 -0
  4. package/dist/__test__/dsl-descriptor.test.js.map +1 -0
  5. package/dist/__test__/example_descriptor.d.ts +125 -0
  6. package/dist/__test__/example_descriptor.js +607 -0
  7. package/dist/__test__/example_descriptor.js.map +1 -0
  8. package/dist/__test__/food_descriptor.state.json +1 -0
  9. package/dist/__test__/food_descriptor.test.d.ts +74 -0
  10. package/dist/__test__/food_descriptor.test.js +205 -0
  11. package/dist/__test__/food_descriptor.test.js.map +1 -0
  12. package/dist/__test__/nl-interpreter-provider-selection.test.d.ts +1 -0
  13. package/dist/__test__/nl-interpreter-provider-selection.test.js +73 -0
  14. package/dist/__test__/nl-interpreter-provider-selection.test.js.map +1 -0
  15. package/dist/__test__/nl-interpreter.test.d.ts +1 -0
  16. package/dist/__test__/nl-interpreter.test.js +86 -0
  17. package/dist/__test__/nl-interpreter.test.js.map +1 -0
  18. package/dist/decorators/__test__/decorators.test.d.ts +1 -0
  19. package/dist/decorators/__test__/decorators.test.js +182 -0
  20. package/dist/decorators/__test__/decorators.test.js.map +1 -0
  21. package/dist/decorators/__test__/inheritance-descriptor.test.d.ts +1 -0
  22. package/dist/decorators/__test__/inheritance-descriptor.test.js +107 -0
  23. package/dist/decorators/__test__/inheritance-descriptor.test.js.map +1 -0
  24. package/dist/decorators/decorators.d.ts +20 -0
  25. package/dist/decorators/decorators.js +520 -0
  26. package/dist/decorators/decorators.js.map +1 -0
  27. package/dist/decorators/index.d.ts +2 -0
  28. package/dist/decorators/index.js +19 -0
  29. package/dist/decorators/index.js.map +1 -0
  30. package/dist/decorators/store.d.ts +12 -0
  31. package/dist/decorators/store.js +43 -0
  32. package/dist/decorators/store.js.map +1 -0
  33. package/dist/dsl/__test__/dsl-interpreter.test.d.ts +1 -0
  34. package/dist/dsl/__test__/dsl-interpreter.test.js +334 -0
  35. package/dist/dsl/__test__/dsl-interpreter.test.js.map +1 -0
  36. package/dist/dsl/__test__/parser.gen.test.d.ts +1 -0
  37. package/dist/dsl/__test__/parser.gen.test.js +283 -0
  38. package/dist/dsl/__test__/parser.gen.test.js.map +1 -0
  39. package/dist/dsl/dsl-interpreter.d.ts +66 -0
  40. package/dist/dsl/dsl-interpreter.js +767 -0
  41. package/dist/dsl/dsl-interpreter.js.map +1 -0
  42. package/dist/dsl/index.d.ts +1 -0
  43. package/dist/dsl/index.js +18 -0
  44. package/dist/dsl/index.js.map +1 -0
  45. package/dist/dsl/parser.gen.d.ts +10 -0
  46. package/dist/dsl/parser.gen.js +1524 -0
  47. package/dist/dsl/parser.gen.js.map +1 -0
  48. package/dist/dsl-descriptor.d.ts +75 -0
  49. package/dist/dsl-descriptor.js +151 -0
  50. package/dist/dsl-descriptor.js.map +1 -0
  51. package/dist/index.d.ts +5 -0
  52. package/dist/index.js +22 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/nl/__test__/context-aware-prompt.test.d.ts +1 -0
  55. package/dist/nl/__test__/context-aware-prompt.test.js +247 -0
  56. package/dist/nl/__test__/context-aware-prompt.test.js.map +1 -0
  57. package/dist/nl/__test__/context-selector.test.d.ts +1 -0
  58. package/dist/nl/__test__/context-selector.test.js +20 -0
  59. package/dist/nl/__test__/context-selector.test.js.map +1 -0
  60. package/dist/nl/__test__/nl-parser-groq-transport.test.d.ts +1 -0
  61. package/dist/nl/__test__/nl-parser-groq-transport.test.js +87 -0
  62. package/dist/nl/__test__/nl-parser-groq-transport.test.js.map +1 -0
  63. package/dist/nl/__test__/nl-parser-openai-parity.test.d.ts +1 -0
  64. package/dist/nl/__test__/nl-parser-openai-parity.test.js +206 -0
  65. package/dist/nl/__test__/nl-parser-openai-parity.test.js.map +1 -0
  66. package/dist/nl/__test__/nl-parser-openai-sampling.test.d.ts +1 -0
  67. package/dist/nl/__test__/nl-parser-openai-sampling.test.js +44 -0
  68. package/dist/nl/__test__/nl-parser-openai-sampling.test.js.map +1 -0
  69. package/dist/nl/__test__/nl-parser-openai-transport.test.d.ts +1 -0
  70. package/dist/nl/__test__/nl-parser-openai-transport.test.js +55 -0
  71. package/dist/nl/__test__/nl-parser-openai-transport.test.js.map +1 -0
  72. package/dist/nl/__test__/nl-parser-utils.test.d.ts +1 -0
  73. package/dist/nl/__test__/nl-parser-utils.test.js +70 -0
  74. package/dist/nl/__test__/nl-parser-utils.test.js.map +1 -0
  75. package/dist/nl/__test__/nl-parser.test.d.ts +1 -0
  76. package/dist/nl/__test__/nl-parser.test.js +64 -0
  77. package/dist/nl/__test__/nl-parser.test.js.map +1 -0
  78. package/dist/nl/__test__/parameter-tuning.test.d.ts +1 -0
  79. package/dist/nl/__test__/parameter-tuning.test.js +95 -0
  80. package/dist/nl/__test__/parameter-tuning.test.js.map +1 -0
  81. package/dist/nl/__test__/semantic-parsing-experiment.test.d.ts +1 -0
  82. package/dist/nl/__test__/semantic-parsing-experiment.test.js +178 -0
  83. package/dist/nl/__test__/semantic-parsing-experiment.test.js.map +1 -0
  84. package/dist/nl/context-selector.d.ts +17 -0
  85. package/dist/nl/context-selector.js +99 -0
  86. package/dist/nl/context-selector.js.map +1 -0
  87. package/dist/nl/index.d.ts +6 -0
  88. package/dist/nl/index.js +15 -0
  89. package/dist/nl/index.js.map +1 -0
  90. package/dist/nl/llm-monitoring.d.ts +49 -0
  91. package/dist/nl/llm-monitoring.js +243 -0
  92. package/dist/nl/llm-monitoring.js.map +1 -0
  93. package/dist/nl/llm-monitoring.test.d.ts +5 -0
  94. package/dist/nl/llm-monitoring.test.js +101 -0
  95. package/dist/nl/llm-monitoring.test.js.map +1 -0
  96. package/dist/nl/nl-parser-groq.d.ts +21 -0
  97. package/dist/nl/nl-parser-groq.js +357 -0
  98. package/dist/nl/nl-parser-groq.js.map +1 -0
  99. package/dist/nl/nl-parser-utils.d.ts +101 -0
  100. package/dist/nl/nl-parser-utils.js +255 -0
  101. package/dist/nl/nl-parser-utils.js.map +1 -0
  102. package/dist/nl/nl-parser.d.ts +30 -0
  103. package/dist/nl/nl-parser.js +433 -0
  104. package/dist/nl/nl-parser.js.map +1 -0
  105. package/dist/nl/prompt-gen.d.ts +93 -0
  106. package/dist/nl/prompt-gen.js +369 -0
  107. package/dist/nl/prompt-gen.js.map +1 -0
  108. package/dist/nl/prompt-res.d.ts +16 -0
  109. package/dist/nl/prompt-res.js +190 -0
  110. package/dist/nl/prompt-res.js.map +1 -0
  111. package/dist/nl-interpreter.d.ts +48 -0
  112. package/dist/nl-interpreter.js +155 -0
  113. package/dist/nl-interpreter.js.map +1 -0
  114. package/lib/__test__/dsl-descriptor.test.ts +27 -0
  115. package/lib/__test__/example_descriptor.ts +762 -0
  116. package/lib/__test__/food_descriptor.state.json +1 -0
  117. package/lib/__test__/food_descriptor.test.ts +331 -0
  118. package/lib/__test__/nl-interpreter-provider-selection.test.ts +126 -0
  119. package/lib/__test__/nl-interpreter.test.ts +129 -0
  120. package/lib/decorators/__test__/decorators.test.ts +177 -0
  121. package/lib/decorators/__test__/inheritance-descriptor.test.ts +92 -0
  122. package/lib/decorators/decorators.ts +754 -0
  123. package/lib/decorators/index.ts +2 -0
  124. package/lib/decorators/store.ts +47 -0
  125. package/lib/dsl/__test__/dsl-interpreter.test.ts +453 -0
  126. package/lib/dsl/__test__/parser.gen.test.ts +296 -0
  127. package/lib/dsl/dsl-interpreter.ts +974 -0
  128. package/lib/dsl/index.ts +1 -0
  129. package/lib/dsl/parser.gen.js +1479 -0
  130. package/lib/dsl/parser.pegjs +130 -0
  131. package/lib/dsl-descriptor.ts +241 -0
  132. package/lib/index.ts +5 -0
  133. package/lib/nl/__test__/context-aware-prompt.test.ts +372 -0
  134. package/lib/nl/__test__/context-selector.test.ts +27 -0
  135. package/lib/nl/__test__/nl-parser-groq-transport.test.ts +139 -0
  136. package/lib/nl/__test__/nl-parser-openai-parity.test.ts +381 -0
  137. package/lib/nl/__test__/nl-parser-openai-sampling.test.ts +73 -0
  138. package/lib/nl/__test__/nl-parser-openai-transport.test.ts +79 -0
  139. package/lib/nl/__test__/nl-parser-utils.test.ts +98 -0
  140. package/lib/nl/__test__/nl-parser.test.ts +119 -0
  141. package/lib/nl/__test__/parameter-tuning.test.ts +137 -0
  142. package/lib/nl/__test__/semantic-parsing-experiment.test.ts +260 -0
  143. package/lib/nl/context-selector.ts +123 -0
  144. package/lib/nl/index.ts +19 -0
  145. package/lib/nl/llm-monitoring.test.ts +136 -0
  146. package/lib/nl/llm-monitoring.ts +339 -0
  147. package/lib/nl/nl-parser-groq.ts +510 -0
  148. package/lib/nl/nl-parser-utils.ts +310 -0
  149. package/lib/nl/nl-parser.ts +616 -0
  150. package/lib/nl/prompt-gen.ts +607 -0
  151. package/lib/nl/prompt-res.ts +207 -0
  152. package/lib/nl-interpreter.ts +262 -0
  153. package/package.json +58 -0
@@ -0,0 +1,130 @@
1
+ {
2
+ const DEBUGGING = false;
3
+ const debug = (...args) => {
4
+ if (DEBUGGING) {
5
+ console.log('DEBUG: ' + args)
6
+ }
7
+ }
8
+ }
9
+
10
+ top = s: statement sl: (SP* ';' SP* statement?)* {
11
+ return [s].concat(
12
+ sl.map((e) => {
13
+ return e[3];
14
+ }).reduce((acc, cur) => {
15
+ if (cur !== null) {
16
+ acc.push(cur);
17
+ }
18
+ return acc;
19
+ }, [])
20
+ );
21
+ }
22
+
23
+ statement = s: (value / all_symbol) SP* {
24
+ return s
25
+ }
26
+
27
+ all_symbol = s:(index_symbol) l:('.' all_symbol)? {
28
+ if (l !== null) {
29
+ var last_l_parent = null;
30
+ l = l[1];
31
+ var l_parent = l;
32
+ while (l_parent.parent !== undefined) {
33
+ last_l_parent = l_parent;
34
+ l_parent = l_parent.parent;
35
+ }
36
+ if (last_l_parent !== null) {
37
+ last_l_parent.parent = {
38
+ type: "access",
39
+ parent: s,
40
+ access: l_parent
41
+ };
42
+ } else {
43
+ l = {
44
+ type: "access",
45
+ parent: s,
46
+ access: l_parent
47
+ }
48
+ }
49
+ return l;
50
+ } else {
51
+ return s;
52
+ }
53
+ }
54
+
55
+ index_symbol = p: (function_call / symbol ) i: ('[' int_literal ']')* {
56
+ var return_value = p;
57
+ for (var index_element of i) {
58
+ return_value = {
59
+ type: "index",
60
+ parent: return_value,
61
+ index: index_element[1]
62
+ };
63
+ }
64
+ return return_value;
65
+ }
66
+
67
+ function_call = func_name:symbol SP* '(' SP* pl:(parameter_list)? SP* ')' {
68
+ debug('function_call', func_name, pl);
69
+ return {
70
+ type: 'function_call',
71
+ func_name: func_name,
72
+ parameters: pl !== null ? pl.parameters : null
73
+ };
74
+ }
75
+
76
+ parameter_list = pp:parameter_pair pl:(SP* ',' SP* parameter_pair)* {
77
+ debug('parameter_list', pp, pl);
78
+ return {"parameters": pl.reduce((acc, cur) => {
79
+ acc.push(cur[3]);
80
+ return acc;
81
+ }, [pp])};
82
+ }
83
+
84
+ parameter_pair = sy:symbol SP* ':' SP* v:(value / accessor) {
85
+ return {"parameter": sy, "value": v};
86
+ }
87
+
88
+ value = 'true' {
89
+ return { type: "boolean", value: true };
90
+ } / 'false' {
91
+ return { type: "boolean", value: false };
92
+ } / fl: float_literal {
93
+ return {"type": "float", "value": fl};
94
+ } / il: int_literal {
95
+ return {"type": "int", "value": il};
96
+ } / s: all_symbol {
97
+ return s;
98
+ } / '"' s: [^"]* '"' {
99
+ return { type: "string", value: s.join("") };
100
+ } / '[' SP* s: array_value SP* ']' {
101
+ return { type: "array", value: s };
102
+ }
103
+
104
+ accessor = '.' s: all_symbol {
105
+ return {"type": "accessor", "field": s};
106
+ }
107
+
108
+ float_literal = s:("+" / "-")? i:[0-9]+ "." f:[0-9]+ {
109
+ return parseFloat((s === "-" ? "-" : "") + i.join("") + "." + f.join(""));
110
+ }
111
+
112
+ array_value = vi: value iv:(SP* ',' SP* value)* {
113
+ return iv.reduce((acc, cur) => {
114
+ acc.push(cur[3]);
115
+ return acc;
116
+ }, [vi]);
117
+ }
118
+
119
+ symbol = [a-zA-Z_][a-zA-Z0-9_]* {
120
+ return text();
121
+ }
122
+
123
+ int_literal = s:("+" / "-")? i:[0-9]+ {
124
+ return parseInt((s === "-" ? "-" : "") + i.join(""));
125
+ }
126
+
127
+ INTDIGIT = [1-9]
128
+ SIGN = '+' / '-'
129
+ DIGIT = [0-9]
130
+ SP = [ \t\r\n]
@@ -0,0 +1,241 @@
1
+ import { ExampleParse } from "./nl";
2
+
3
+ let constructorInCreateObject = false;
4
+
5
+ export class GenieObject {
6
+ static __genieObjectType: string;
7
+ constructor({}) {
8
+ if (!constructorInCreateObject) {
9
+ console.error(
10
+ "Constructor not called in CreateObject\nAll GenieObject should be created using CreateObject"
11
+ );
12
+ }
13
+ }
14
+
15
+ /**
16
+ * This function is called after the object is created, and called before function calls and property access.
17
+ */
18
+ update(): void | Promise<void> {
19
+ return
20
+ }
21
+
22
+ /**
23
+ * This function is called object's property is updated.
24
+ */
25
+ sync(): void | Promise<void> {
26
+ return
27
+ }
28
+
29
+ // placeholder, should be replaced by GenieClass decorator
30
+ static _createObject<T extends typeof GenieObject>(
31
+ this: T,
32
+ ...args: any[]
33
+ ): InstanceType<T> {
34
+ throw new Error(
35
+ "Not implemented. Did you forget to decorate the class with @GenieClass?"
36
+ );
37
+ }
38
+
39
+ static CreateObject<T extends typeof GenieObject>(
40
+ this: T,
41
+ ...args: any[]
42
+ ): InstanceType<T> {
43
+ constructorInCreateObject = true;
44
+ let returnValue = this._createObject(...args);
45
+ constructorInCreateObject = false;
46
+ return returnValue;
47
+ }
48
+
49
+ // placeholder, other code that should run after initGenie
50
+ static setup() {}
51
+
52
+ description(): {} {
53
+ return this;
54
+ }
55
+
56
+ static Examples: ExampleParse[] = [];
57
+
58
+ static ClassDescriptor: ClassDescriptor<GenieObject>;
59
+
60
+ public __deleted = false;
61
+
62
+ __getState(): {} {
63
+ return {};
64
+ }
65
+ }
66
+
67
+ /**
68
+ * DataClass are objects that controls the interactions.
69
+ *
70
+ * DataClass will be automatically indexed by ReactGenie.
71
+ */
72
+ export class DataClass extends GenieObject {
73
+ static genieKey: string;
74
+ static __genieObjectType: string = "DataClass";
75
+
76
+ constructor({}) {
77
+ super({});
78
+ }
79
+
80
+ // noinspection JSUnusedGlobalSymbols
81
+ _getConstructorParams(): any {
82
+ const name = this.constructor.prototype.genieKey;
83
+ return {
84
+ [name]: this[name],
85
+ };
86
+ }
87
+
88
+ // placeholder, should be replaced by GenieClass decorator
89
+ static GetObject<T extends typeof DataClass>(
90
+ this: T,
91
+ ...args: any[]
92
+ ): InstanceType<T> {
93
+ throw new Error(
94
+ "Not implemented. Did you forget to decorate the class with @GenieClass?"
95
+ );
96
+ }
97
+
98
+ static All<T extends typeof DataClass>(
99
+ this: T,
100
+ ...args: any[]
101
+ ): InstanceType<T>[] | Promise<InstanceType<T>[]> {
102
+ throw new Error(
103
+ "Not implemented. Did you forget to decorate the class with @GenieClass?"
104
+ );
105
+ }
106
+
107
+ static DeleteObject<T extends typeof DataClass>(
108
+ this: T,
109
+ ...args: any[]
110
+ ): InstanceType<T> {
111
+ throw new Error(
112
+ "Not implemented. Did you forget to decorate the class with @GenieClass?"
113
+ );
114
+ }
115
+ }
116
+
117
+ export type HelperClassGetter = () => {};
118
+ export type HelperClassSetter = (value: {}) => void;
119
+ export type HelperClassGetterSetter = [HelperClassGetter, HelperClassSetter];
120
+
121
+ /**
122
+ * Helper class are for storing complex data types in DataClass.
123
+ */
124
+ export class HelperClass extends GenieObject {
125
+ localStore: {} = null;
126
+ localStoreGetterSetter: HelperClassGetterSetter = null;
127
+ static __genieObjectType: string = "HelperClass";
128
+
129
+ constructor(value: { __genieObjectType: {} } | {}) {
130
+ super(value);
131
+ if (value && value.hasOwnProperty("__genieObjectType")) {
132
+ this.localStore = value;
133
+ }
134
+ }
135
+ }
136
+
137
+ export class ParamDescriptor {
138
+ // noinspection JSUnusedGlobalSymbols
139
+ constructor(
140
+ public name: string,
141
+ public type: string,
142
+ public required: boolean = true,
143
+ public defaultValue: any = null
144
+ ) {}
145
+ description(): string {
146
+ return (
147
+ `${this.name}: ${this.type}` + (this.required ? "" : "?") +
148
+ (this.defaultValue ? ` = \`${this.defaultValue}\`` : "")
149
+ );
150
+ }
151
+ }
152
+
153
+ export class FuncDescriptor {
154
+ constructor(
155
+ public func_name: string,
156
+ public parameters: ParamDescriptor[],
157
+ public returnType: string,
158
+ public isStatic: boolean = false,
159
+ public comment: string = ""
160
+ ) {}
161
+ description(): string {
162
+ return (
163
+ (this.comment !== "" ? `// ${this.comment}\n\t` : "") +
164
+ (this.isStatic ? `static ` : "") +
165
+ `${this.returnType} ${this.func_name}(${this.parameters
166
+ .map((p) => p.description())
167
+ .join(", ")});`
168
+ );
169
+ }
170
+
171
+ isSame(another: FuncDescriptor) {
172
+ return (
173
+ this.func_name === another.func_name &&
174
+ this.returnType === another.returnType &&
175
+ this.isStatic === another.isStatic &&
176
+ this.parameters.length === another.parameters.length &&
177
+ this.parameters.every(
178
+ (p, i) =>
179
+ p.name === another.parameters[i].name &&
180
+ p.type === another.parameters[i].type
181
+ )
182
+ );
183
+ }
184
+ }
185
+
186
+ export class FieldDescriptor {
187
+ constructor(
188
+ public field: string,
189
+ public fieldType: string,
190
+ public isStatic: boolean = false,
191
+ public comment: string = ""
192
+ ) {}
193
+
194
+ description(): string {
195
+ return (
196
+ (this.comment !== "" ? `// ${this.comment}\n\t` : "") +
197
+ (this.isStatic ? `static ` : "") +
198
+ `${this.fieldType} ${this.field};`
199
+ );
200
+ }
201
+
202
+ isSame(another: FieldDescriptor) {
203
+ return (
204
+ this.field === another.field &&
205
+ this.fieldType === another.fieldType &&
206
+ this.isStatic === another.isStatic
207
+ );
208
+ }
209
+ }
210
+
211
+ export class ClassDescriptor<T extends GenieObject> {
212
+ public functions: Set<FuncDescriptor>;
213
+ public fields: Set<FieldDescriptor>;
214
+
215
+ constructor(
216
+ public className: string,
217
+ functions: FuncDescriptor[],
218
+ fields: FieldDescriptor[],
219
+ public classConstructor: { new (...any): T },
220
+ public comment: string = ""
221
+ ) {
222
+ this.functions = new Set(functions);
223
+ this.fields = new Set(fields);
224
+ }
225
+
226
+ description(): string {
227
+ return (
228
+ (this.comment !== "" ? `// ${this.comment}\n` : "") +
229
+ `class ${this.className} {\n` +
230
+ Array.from(this.fields)
231
+ .map((f) => "\t" + f.description())
232
+ .join("\n") +
233
+ "\n" +
234
+ Array.from(this.functions)
235
+ .map((f) => "\t" + f.description())
236
+ .join("\n") +
237
+ "\n" +
238
+ `}`
239
+ );
240
+ }
241
+ }
package/lib/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from "./dsl-descriptor";
2
+ export * from "./dsl";
3
+ export * from "./decorators";
4
+ export * from "./nl";
5
+ export * from "./nl-interpreter";