@garrix82/reactgenie-dsl 1.0.1 → 1.0.2

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 (104) hide show
  1. package/.env +10 -0
  2. package/.env.example +17 -0
  3. package/.github/workflows/publish.yml +20 -0
  4. package/package.json +1 -5
  5. package/dist/__test__/dsl-descriptor.test.d.ts +0 -1
  6. package/dist/__test__/dsl-descriptor.test.js +0 -27
  7. package/dist/__test__/dsl-descriptor.test.js.map +0 -1
  8. package/dist/__test__/example_descriptor.d.ts +0 -125
  9. package/dist/__test__/example_descriptor.js +0 -607
  10. package/dist/__test__/example_descriptor.js.map +0 -1
  11. package/dist/__test__/food_descriptor.state.json +0 -1
  12. package/dist/__test__/food_descriptor.test.d.ts +0 -74
  13. package/dist/__test__/food_descriptor.test.js +0 -205
  14. package/dist/__test__/food_descriptor.test.js.map +0 -1
  15. package/dist/__test__/nl-interpreter-provider-selection.test.d.ts +0 -1
  16. package/dist/__test__/nl-interpreter-provider-selection.test.js +0 -73
  17. package/dist/__test__/nl-interpreter-provider-selection.test.js.map +0 -1
  18. package/dist/__test__/nl-interpreter.test.d.ts +0 -1
  19. package/dist/__test__/nl-interpreter.test.js +0 -86
  20. package/dist/__test__/nl-interpreter.test.js.map +0 -1
  21. package/dist/decorators/__test__/decorators.test.d.ts +0 -1
  22. package/dist/decorators/__test__/decorators.test.js +0 -182
  23. package/dist/decorators/__test__/decorators.test.js.map +0 -1
  24. package/dist/decorators/__test__/inheritance-descriptor.test.d.ts +0 -1
  25. package/dist/decorators/__test__/inheritance-descriptor.test.js +0 -107
  26. package/dist/decorators/__test__/inheritance-descriptor.test.js.map +0 -1
  27. package/dist/dsl/__test__/dsl-interpreter.test.d.ts +0 -1
  28. package/dist/dsl/__test__/dsl-interpreter.test.js +0 -334
  29. package/dist/dsl/__test__/dsl-interpreter.test.js.map +0 -1
  30. package/dist/dsl/__test__/parser.gen.test.d.ts +0 -1
  31. package/dist/dsl/__test__/parser.gen.test.js +0 -283
  32. package/dist/dsl/__test__/parser.gen.test.js.map +0 -1
  33. package/dist/nl/__test__/context-aware-prompt.test.d.ts +0 -1
  34. package/dist/nl/__test__/context-aware-prompt.test.js +0 -247
  35. package/dist/nl/__test__/context-aware-prompt.test.js.map +0 -1
  36. package/dist/nl/__test__/context-selector.test.d.ts +0 -1
  37. package/dist/nl/__test__/context-selector.test.js +0 -20
  38. package/dist/nl/__test__/context-selector.test.js.map +0 -1
  39. package/dist/nl/__test__/nl-parser-groq-transport.test.d.ts +0 -1
  40. package/dist/nl/__test__/nl-parser-groq-transport.test.js +0 -87
  41. package/dist/nl/__test__/nl-parser-groq-transport.test.js.map +0 -1
  42. package/dist/nl/__test__/nl-parser-openai-parity.test.d.ts +0 -1
  43. package/dist/nl/__test__/nl-parser-openai-parity.test.js +0 -206
  44. package/dist/nl/__test__/nl-parser-openai-parity.test.js.map +0 -1
  45. package/dist/nl/__test__/nl-parser-openai-sampling.test.d.ts +0 -1
  46. package/dist/nl/__test__/nl-parser-openai-sampling.test.js +0 -44
  47. package/dist/nl/__test__/nl-parser-openai-sampling.test.js.map +0 -1
  48. package/dist/nl/__test__/nl-parser-openai-transport.test.d.ts +0 -1
  49. package/dist/nl/__test__/nl-parser-openai-transport.test.js +0 -55
  50. package/dist/nl/__test__/nl-parser-openai-transport.test.js.map +0 -1
  51. package/dist/nl/__test__/nl-parser-utils.test.d.ts +0 -1
  52. package/dist/nl/__test__/nl-parser-utils.test.js +0 -70
  53. package/dist/nl/__test__/nl-parser-utils.test.js.map +0 -1
  54. package/dist/nl/__test__/nl-parser.test.d.ts +0 -1
  55. package/dist/nl/__test__/nl-parser.test.js +0 -64
  56. package/dist/nl/__test__/nl-parser.test.js.map +0 -1
  57. package/dist/nl/__test__/parameter-tuning.test.d.ts +0 -1
  58. package/dist/nl/__test__/parameter-tuning.test.js +0 -95
  59. package/dist/nl/__test__/parameter-tuning.test.js.map +0 -1
  60. package/dist/nl/__test__/semantic-parsing-experiment.test.d.ts +0 -1
  61. package/dist/nl/__test__/semantic-parsing-experiment.test.js +0 -178
  62. package/dist/nl/__test__/semantic-parsing-experiment.test.js.map +0 -1
  63. package/dist/nl/llm-monitoring.test.d.ts +0 -5
  64. package/dist/nl/llm-monitoring.test.js +0 -101
  65. package/dist/nl/llm-monitoring.test.js.map +0 -1
  66. package/lib/__test__/dsl-descriptor.test.ts +0 -27
  67. package/lib/__test__/example_descriptor.ts +0 -762
  68. package/lib/__test__/food_descriptor.state.json +0 -1
  69. package/lib/__test__/food_descriptor.test.ts +0 -331
  70. package/lib/__test__/nl-interpreter-provider-selection.test.ts +0 -126
  71. package/lib/__test__/nl-interpreter.test.ts +0 -129
  72. package/lib/decorators/__test__/decorators.test.ts +0 -177
  73. package/lib/decorators/__test__/inheritance-descriptor.test.ts +0 -92
  74. package/lib/decorators/decorators.ts +0 -754
  75. package/lib/decorators/index.ts +0 -2
  76. package/lib/decorators/store.ts +0 -47
  77. package/lib/dsl/__test__/dsl-interpreter.test.ts +0 -453
  78. package/lib/dsl/__test__/parser.gen.test.ts +0 -296
  79. package/lib/dsl/dsl-interpreter.ts +0 -974
  80. package/lib/dsl/index.ts +0 -1
  81. package/lib/dsl/parser.gen.js +0 -1479
  82. package/lib/dsl/parser.pegjs +0 -130
  83. package/lib/dsl-descriptor.ts +0 -241
  84. package/lib/index.ts +0 -5
  85. package/lib/nl/__test__/context-aware-prompt.test.ts +0 -372
  86. package/lib/nl/__test__/context-selector.test.ts +0 -27
  87. package/lib/nl/__test__/nl-parser-groq-transport.test.ts +0 -139
  88. package/lib/nl/__test__/nl-parser-openai-parity.test.ts +0 -381
  89. package/lib/nl/__test__/nl-parser-openai-sampling.test.ts +0 -73
  90. package/lib/nl/__test__/nl-parser-openai-transport.test.ts +0 -79
  91. package/lib/nl/__test__/nl-parser-utils.test.ts +0 -98
  92. package/lib/nl/__test__/nl-parser.test.ts +0 -119
  93. package/lib/nl/__test__/parameter-tuning.test.ts +0 -137
  94. package/lib/nl/__test__/semantic-parsing-experiment.test.ts +0 -260
  95. package/lib/nl/context-selector.ts +0 -123
  96. package/lib/nl/index.ts +0 -19
  97. package/lib/nl/llm-monitoring.test.ts +0 -136
  98. package/lib/nl/llm-monitoring.ts +0 -339
  99. package/lib/nl/nl-parser-groq.ts +0 -510
  100. package/lib/nl/nl-parser-utils.ts +0 -310
  101. package/lib/nl/nl-parser.ts +0 -616
  102. package/lib/nl/prompt-gen.ts +0 -607
  103. package/lib/nl/prompt-res.ts +0 -207
  104. package/lib/nl-interpreter.ts +0 -262
@@ -1,130 +0,0 @@
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]
@@ -1,241 +0,0 @@
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 DELETED
@@ -1,5 +0,0 @@
1
- export * from "./dsl-descriptor";
2
- export * from "./dsl";
3
- export * from "./decorators";
4
- export * from "./nl";
5
- export * from "./nl-interpreter";