@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
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContextAwareDescriptorPromptGen = exports.DescriptorPromptGen = exports.BasicPromptGen = exports.ExampleParse = void 0;
|
|
4
|
+
const prompt_res_1 = require("./prompt-res");
|
|
5
|
+
const context_selector_1 = require("./context-selector");
|
|
6
|
+
const DEFAULT_PROMPT_SELECTION_CONFIG = {
|
|
7
|
+
enabled: true,
|
|
8
|
+
topNClassDescriptions: 12,
|
|
9
|
+
topMExamples: 4,
|
|
10
|
+
recentTurnsWindow: 4,
|
|
11
|
+
olderSummaryMaxChars: 600,
|
|
12
|
+
cacheSize: 64,
|
|
13
|
+
};
|
|
14
|
+
class ExampleParse {
|
|
15
|
+
constructor(user_utterance, example_parsed) {
|
|
16
|
+
this.user_utterance = user_utterance;
|
|
17
|
+
this.example_parsed = example_parsed;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.ExampleParse = ExampleParse;
|
|
21
|
+
class BasicPromptGen {
|
|
22
|
+
constructor(class_descriptions, examples, extraPrompt) {
|
|
23
|
+
this.class_descriptions = class_descriptions;
|
|
24
|
+
this.examples = examples;
|
|
25
|
+
this.extraPrompt = extraPrompt;
|
|
26
|
+
}
|
|
27
|
+
prompt_basic() {
|
|
28
|
+
let prompt = `${prompt_res_1.class_prequel}${prompt_res_1.pre_section_separator}` +
|
|
29
|
+
`${prompt_res_1.array_definition}${prompt_res_1.class_separator}` +
|
|
30
|
+
`${this.class_descriptions.join(prompt_res_1.class_separator)}${prompt_res_1.post_section_separator}` +
|
|
31
|
+
`${prompt_res_1.example_prequel}${prompt_res_1.pre_section_separator}` +
|
|
32
|
+
`${(0, prompt_res_1.example_parses)(this.examples)}${prompt_res_1.post_section_separator}` +
|
|
33
|
+
`${prompt_res_1.accessor_parameter_rules}${prompt_res_1.post_section_separator}` +
|
|
34
|
+
`${prompt_res_1.user_interaction_prequel}${prompt_res_1.pre_section_separator}`;
|
|
35
|
+
if (this.extraPrompt !== undefined) {
|
|
36
|
+
prompt += `${this.extraPrompt}${prompt_res_1.pre_section_separator}`;
|
|
37
|
+
}
|
|
38
|
+
return prompt;
|
|
39
|
+
}
|
|
40
|
+
zero_shot_prompt_basic() {
|
|
41
|
+
return (0, prompt_res_1.parseCodePrompt)(this.prompt_basic());
|
|
42
|
+
}
|
|
43
|
+
prompt(user_utterance) {
|
|
44
|
+
let prompt = this.prompt_basic();
|
|
45
|
+
prompt += `${(0, prompt_res_1.user_interaction_prompt)(user_utterance)}`;
|
|
46
|
+
return prompt;
|
|
47
|
+
}
|
|
48
|
+
zero_shot_prompt(user_utterance) {
|
|
49
|
+
let prompt = this.zero_shot_prompt_basic();
|
|
50
|
+
prompt += `${(0, prompt_res_1.user_interaction_prompt)(user_utterance)}`;
|
|
51
|
+
return prompt;
|
|
52
|
+
}
|
|
53
|
+
response_prompt(user_utterance, parsed, result) {
|
|
54
|
+
return (0, prompt_res_1.agent_response_prompt)(user_utterance, parsed, result);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.BasicPromptGen = BasicPromptGen;
|
|
58
|
+
class DescriptorPromptGen extends BasicPromptGen {
|
|
59
|
+
constructor(class_descriptors, examples, extraPrompt) {
|
|
60
|
+
super(class_descriptors.map((c) => c.description()), examples, extraPrompt);
|
|
61
|
+
this.class_descriptors = class_descriptors;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.DescriptorPromptGen = DescriptorPromptGen;
|
|
65
|
+
class ContextAwareDescriptorPromptGen {
|
|
66
|
+
constructor(class_descriptors, examples, extraPrompt, config) {
|
|
67
|
+
this.extraPrompt = extraPrompt;
|
|
68
|
+
this.recentTurns = [];
|
|
69
|
+
this.olderTurnsSummary = "";
|
|
70
|
+
this.runtimeUiContext = null;
|
|
71
|
+
this.allClassNames = class_descriptors.map((c) => c.className);
|
|
72
|
+
this.allClassDescriptions = class_descriptors.map((c) => c.description());
|
|
73
|
+
this.allExamples = examples;
|
|
74
|
+
this.allExampleRootClasses = examples.map((example) => ContextAwareDescriptorPromptGen.extractRootClass(example.example_parsed));
|
|
75
|
+
this.config = {
|
|
76
|
+
...DEFAULT_PROMPT_SELECTION_CONFIG,
|
|
77
|
+
...config,
|
|
78
|
+
};
|
|
79
|
+
this.selectionCache = new context_selector_1.BoundedCache(this.config.cacheSize);
|
|
80
|
+
}
|
|
81
|
+
setRuntimeContext(context) {
|
|
82
|
+
if (!context) {
|
|
83
|
+
this.runtimeUiContext = null;
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
this.runtimeUiContext = {
|
|
87
|
+
tapClassName: context.tapClassName,
|
|
88
|
+
visibleClassNames: Array.from(new Set((context.visibleClassNames || []).filter((entry) => !!entry))),
|
|
89
|
+
isDeicticUtterance: !!context.isDeicticUtterance,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
static normalizeClassName(className) {
|
|
93
|
+
return className.replace(/\[\]$/g, "");
|
|
94
|
+
}
|
|
95
|
+
static extractRootClass(parsedExpression) {
|
|
96
|
+
const match = parsedExpression.match(/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*\./);
|
|
97
|
+
return match?.[1] || "";
|
|
98
|
+
}
|
|
99
|
+
static isScreenIndependentExample(example) {
|
|
100
|
+
return !/\b(?:AllCurrent|Current|getCurrent|current)\s*\(/.test(example.example_parsed);
|
|
101
|
+
}
|
|
102
|
+
getAllowedRootClassesForDeicticContext() {
|
|
103
|
+
const context = this.runtimeUiContext;
|
|
104
|
+
const allowed = new Set();
|
|
105
|
+
if (!context || !context.isDeicticUtterance) {
|
|
106
|
+
return allowed;
|
|
107
|
+
}
|
|
108
|
+
if (context.tapClassName) {
|
|
109
|
+
allowed.add(ContextAwareDescriptorPromptGen.normalizeClassName(context.tapClassName));
|
|
110
|
+
return allowed;
|
|
111
|
+
}
|
|
112
|
+
context.visibleClassNames
|
|
113
|
+
.map((className) => ContextAwareDescriptorPromptGen.normalizeClassName(className))
|
|
114
|
+
.forEach((className) => {
|
|
115
|
+
if (this.allClassNames.includes(className)) {
|
|
116
|
+
allowed.add(className);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
return allowed;
|
|
120
|
+
}
|
|
121
|
+
getPreferredRootClassesForVisibleScreenContext() {
|
|
122
|
+
const context = this.runtimeUiContext;
|
|
123
|
+
const preferred = new Set();
|
|
124
|
+
if (!context || context.isDeicticUtterance) {
|
|
125
|
+
return preferred;
|
|
126
|
+
}
|
|
127
|
+
if (context.tapClassName) {
|
|
128
|
+
const normalizedTapClass = ContextAwareDescriptorPromptGen.normalizeClassName(context.tapClassName);
|
|
129
|
+
if (this.allClassNames.includes(normalizedTapClass)) {
|
|
130
|
+
preferred.add(normalizedTapClass);
|
|
131
|
+
}
|
|
132
|
+
return preferred;
|
|
133
|
+
}
|
|
134
|
+
const visibleRootClasses = Array.from(new Set(context.visibleClassNames
|
|
135
|
+
.map((className) => ContextAwareDescriptorPromptGen.normalizeClassName(className))
|
|
136
|
+
.filter((className) => this.allClassNames.includes(className))));
|
|
137
|
+
if (visibleRootClasses.length === 1) {
|
|
138
|
+
preferred.add(visibleRootClasses[0]);
|
|
139
|
+
}
|
|
140
|
+
return preferred;
|
|
141
|
+
}
|
|
142
|
+
buildRuntimeUiContextBlock() {
|
|
143
|
+
const context = this.runtimeUiContext;
|
|
144
|
+
if (!context) {
|
|
145
|
+
return "";
|
|
146
|
+
}
|
|
147
|
+
const hasExplicitContext = !!context.tapClassName || context.visibleClassNames.length > 0;
|
|
148
|
+
const lines = ["// Runtime UI context"];
|
|
149
|
+
lines.push(`ui_context: current_tap_class=${context.tapClassName || "none"}; visible_classes=${context.visibleClassNames.length > 0
|
|
150
|
+
? context.visibleClassNames.join(", ")
|
|
151
|
+
: "none"}; deictic_utterance=${context.isDeicticUtterance ? "true" : "false"}`);
|
|
152
|
+
lines.push("deictic_rules:");
|
|
153
|
+
lines.push("1. If deictic_utterance=true and current_tap_class exists, root the DSL chain on current_tap_class.");
|
|
154
|
+
lines.push("2. If deictic_utterance=true and current_tap_class=none, prefer root classes that are in visible_classes.");
|
|
155
|
+
lines.push("3. For deictic utterances, avoid root classes outside visible_classes unless the user explicitly names another class.");
|
|
156
|
+
if (context.isDeicticUtterance && !hasExplicitContext) {
|
|
157
|
+
lines.push("4. No visible object context is available. Do not use Current()/AllCurrent()/getCurrent(); resolve the command from the utterance itself.");
|
|
158
|
+
}
|
|
159
|
+
lines.push("deictic_examples:");
|
|
160
|
+
lines.push('- user: "show this item" parsed: Item.Current()');
|
|
161
|
+
lines.push('- user: "update this status to done" parsed: Task.Current().setStatus(value: "done")');
|
|
162
|
+
return lines.join("\n");
|
|
163
|
+
}
|
|
164
|
+
buildPromptBasic(classDescriptions, examples, historyContext, uiContext) {
|
|
165
|
+
let prompt = `${prompt_res_1.class_prequel}${prompt_res_1.pre_section_separator}` +
|
|
166
|
+
`${prompt_res_1.array_definition}${prompt_res_1.class_separator}` +
|
|
167
|
+
`${classDescriptions.join(prompt_res_1.class_separator)}${prompt_res_1.post_section_separator}` +
|
|
168
|
+
`${prompt_res_1.example_prequel}${prompt_res_1.pre_section_separator}` +
|
|
169
|
+
`${(0, prompt_res_1.example_parses)(examples)}${prompt_res_1.post_section_separator}` +
|
|
170
|
+
`${prompt_res_1.accessor_parameter_rules}${prompt_res_1.post_section_separator}` +
|
|
171
|
+
`${prompt_res_1.user_interaction_prequel}${prompt_res_1.pre_section_separator}`;
|
|
172
|
+
if (historyContext) {
|
|
173
|
+
prompt += `${historyContext}${prompt_res_1.post_section_separator}`;
|
|
174
|
+
}
|
|
175
|
+
if (uiContext) {
|
|
176
|
+
prompt += `${uiContext}${prompt_res_1.post_section_separator}`;
|
|
177
|
+
}
|
|
178
|
+
if (this.extraPrompt !== undefined) {
|
|
179
|
+
prompt += `${this.extraPrompt}${prompt_res_1.pre_section_separator}`;
|
|
180
|
+
}
|
|
181
|
+
return prompt;
|
|
182
|
+
}
|
|
183
|
+
buildHistoryContext() {
|
|
184
|
+
if (this.recentTurns.length === 0 && !this.olderTurnsSummary) {
|
|
185
|
+
return "";
|
|
186
|
+
}
|
|
187
|
+
const sections = ["// Conversation context"];
|
|
188
|
+
if (this.olderTurnsSummary) {
|
|
189
|
+
sections.push(`summary: ${this.olderTurnsSummary}`);
|
|
190
|
+
}
|
|
191
|
+
if (this.recentTurns.length > 0) {
|
|
192
|
+
sections.push("recent_turns:");
|
|
193
|
+
this.recentTurns.forEach((turn, index) => {
|
|
194
|
+
const parsed = turn.parsed ? ` parsed=${turn.parsed}` : "";
|
|
195
|
+
const result = turn.resultSummary ? ` result=${turn.resultSummary}` : "";
|
|
196
|
+
sections.push(`- t${index + 1}: user=${turn.utterance} success=${turn.success}${parsed}${result}`);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
return sections.join("\n");
|
|
200
|
+
}
|
|
201
|
+
summarizeRecord(record) {
|
|
202
|
+
const parsed = record.parsed ? `parsed=${record.parsed}` : "parsed=<none>";
|
|
203
|
+
const result = record.resultSummary
|
|
204
|
+
? `result=${record.resultSummary}`
|
|
205
|
+
: "result=<none>";
|
|
206
|
+
return `user=${record.utterance} success=${record.success} ${parsed} ${result}`;
|
|
207
|
+
}
|
|
208
|
+
appendOlderSummary(summaryLine) {
|
|
209
|
+
const next = this.olderTurnsSummary
|
|
210
|
+
? `${this.olderTurnsSummary} | ${summaryLine}`
|
|
211
|
+
: summaryLine;
|
|
212
|
+
if (next.length <= this.config.olderSummaryMaxChars) {
|
|
213
|
+
this.olderTurnsSummary = next;
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
this.olderTurnsSummary = next.slice(next.length - this.config.olderSummaryMaxChars);
|
|
217
|
+
}
|
|
218
|
+
selectionFromCache(cacheKey) {
|
|
219
|
+
const key = (0, context_selector_1.normalizeCacheKey)(cacheKey);
|
|
220
|
+
if (!key) {
|
|
221
|
+
return undefined;
|
|
222
|
+
}
|
|
223
|
+
return this.selectionCache.get(key);
|
|
224
|
+
}
|
|
225
|
+
cacheSelection(cacheKey, selection) {
|
|
226
|
+
const key = (0, context_selector_1.normalizeCacheKey)(cacheKey);
|
|
227
|
+
if (!key) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
this.selectionCache.set(key, selection);
|
|
231
|
+
}
|
|
232
|
+
selectionCacheKeyForUtterance(user_utterance) {
|
|
233
|
+
const context = this.runtimeUiContext;
|
|
234
|
+
if (!context) {
|
|
235
|
+
return user_utterance;
|
|
236
|
+
}
|
|
237
|
+
const preferredVisibleRoots = this.getPreferredRootClassesForVisibleScreenContext();
|
|
238
|
+
if (!context.isDeicticUtterance && preferredVisibleRoots.size === 0) {
|
|
239
|
+
return user_utterance;
|
|
240
|
+
}
|
|
241
|
+
const visibleKey = [...context.visibleClassNames].sort().join(",");
|
|
242
|
+
return `${user_utterance}::tap=${context.tapClassName || ""}::visible=${visibleKey}::deictic=${context.isDeicticUtterance ? 1 : 0}`;
|
|
243
|
+
}
|
|
244
|
+
buildSelectionFromExampleIndexes(exampleIndexes) {
|
|
245
|
+
if (exampleIndexes.length === 0) {
|
|
246
|
+
return {
|
|
247
|
+
classDescriptions: [],
|
|
248
|
+
examples: [],
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
const uniqueExampleIndexes = Array.from(new Set(exampleIndexes)).sort((a, b) => a - b);
|
|
252
|
+
const examples = uniqueExampleIndexes.map((index) => this.allExamples[index]);
|
|
253
|
+
const exampleRootClasses = new Set(uniqueExampleIndexes
|
|
254
|
+
.map((index) => this.allExampleRootClasses[index])
|
|
255
|
+
.filter((className) => className.length > 0));
|
|
256
|
+
const classDescriptions = this.allClassNames
|
|
257
|
+
.map((className, index) => ({ className, index }))
|
|
258
|
+
.filter((entry) => exampleRootClasses.has(entry.className))
|
|
259
|
+
.map((entry) => this.allClassDescriptions[entry.index]);
|
|
260
|
+
return {
|
|
261
|
+
classDescriptions,
|
|
262
|
+
examples,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
rescueSelectionWithoutVisibleContext(user_utterance, rankedExamples) {
|
|
266
|
+
const rescuedExampleIndexes = rankedExamples
|
|
267
|
+
.filter((entry) => ContextAwareDescriptorPromptGen.isScreenIndependentExample(this.allExamples[entry.index]))
|
|
268
|
+
.slice(0, this.config.topMExamples)
|
|
269
|
+
.map((entry) => entry.index);
|
|
270
|
+
return this.buildSelectionFromExampleIndexes(rescuedExampleIndexes);
|
|
271
|
+
}
|
|
272
|
+
computeSelection(user_utterance) {
|
|
273
|
+
if (!this.config.enabled) {
|
|
274
|
+
return {
|
|
275
|
+
classDescriptions: this.allClassDescriptions,
|
|
276
|
+
examples: this.allExamples,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
const cacheKey = this.selectionCacheKeyForUtterance(user_utterance);
|
|
280
|
+
const cached = this.selectionFromCache(cacheKey);
|
|
281
|
+
if (cached) {
|
|
282
|
+
return cached;
|
|
283
|
+
}
|
|
284
|
+
const allowedDeicticRootClasses = this.getAllowedRootClassesForDeicticContext();
|
|
285
|
+
const preferredVisibleRootClasses = this.getPreferredRootClassesForVisibleScreenContext();
|
|
286
|
+
const contextRootClasses = allowedDeicticRootClasses.size > 0
|
|
287
|
+
? allowedDeicticRootClasses
|
|
288
|
+
: preferredVisibleRootClasses;
|
|
289
|
+
const isDeicticUtterance = !!this.runtimeUiContext?.isDeicticUtterance;
|
|
290
|
+
const isContextConstrained = contextRootClasses.size > 0;
|
|
291
|
+
const rankingQuery = isContextConstrained
|
|
292
|
+
? `${user_utterance} ${Array.from(contextRootClasses).join(" ")}`
|
|
293
|
+
: user_utterance;
|
|
294
|
+
const rankedClassDescriptions = (0, context_selector_1.rankByQuery)(rankingQuery, this.allClassDescriptions, (description) => description, isContextConstrained
|
|
295
|
+
? this.allClassDescriptions.length
|
|
296
|
+
: this.config.topNClassDescriptions, {
|
|
297
|
+
allowZeroScoreBackfill: !isContextConstrained,
|
|
298
|
+
});
|
|
299
|
+
const candidateClassEntries = isContextConstrained
|
|
300
|
+
? rankedClassDescriptions.filter((entry) => contextRootClasses.has(this.allClassNames[entry.index]))
|
|
301
|
+
: rankedClassDescriptions;
|
|
302
|
+
const classIndexes = candidateClassEntries
|
|
303
|
+
.slice(0, this.config.topNClassDescriptions)
|
|
304
|
+
.map((entry) => entry.index)
|
|
305
|
+
.sort((a, b) => a - b);
|
|
306
|
+
const selectedClassDescriptions = classIndexes.map((index) => this.allClassDescriptions[index]);
|
|
307
|
+
const rankedExamples = (0, context_selector_1.rankByQuery)(rankingQuery, this.allExamples, (example) => `${example.user_utterance}\n${example.example_parsed}`, isContextConstrained ? this.allExamples.length : this.config.topMExamples, {
|
|
308
|
+
allowZeroScoreBackfill: !isContextConstrained,
|
|
309
|
+
});
|
|
310
|
+
const candidateExampleEntries = isContextConstrained
|
|
311
|
+
? rankedExamples.filter((entry) => contextRootClasses.has(this.allExampleRootClasses[entry.index]))
|
|
312
|
+
: rankedExamples;
|
|
313
|
+
if (isDeicticUtterance && contextRootClasses.size === 0) {
|
|
314
|
+
const rescuedSelection = this.rescueSelectionWithoutVisibleContext(user_utterance, rankedExamples);
|
|
315
|
+
this.cacheSelection(cacheKey, rescuedSelection);
|
|
316
|
+
return rescuedSelection;
|
|
317
|
+
}
|
|
318
|
+
const exampleIndexes = candidateExampleEntries
|
|
319
|
+
.slice(0, this.config.topMExamples)
|
|
320
|
+
.map((entry) => entry.index)
|
|
321
|
+
.sort((a, b) => a - b);
|
|
322
|
+
const selectedExamples = exampleIndexes.map((index) => this.allExamples[index]);
|
|
323
|
+
const selection = {
|
|
324
|
+
classDescriptions: selectedClassDescriptions.length > 0
|
|
325
|
+
? selectedClassDescriptions
|
|
326
|
+
: isDeicticUtterance
|
|
327
|
+
? []
|
|
328
|
+
: this.allClassDescriptions,
|
|
329
|
+
examples: selectedExamples.length > 0
|
|
330
|
+
? selectedExamples
|
|
331
|
+
: isContextConstrained
|
|
332
|
+
? []
|
|
333
|
+
: this.allExamples,
|
|
334
|
+
};
|
|
335
|
+
this.cacheSelection(cacheKey, selection);
|
|
336
|
+
return selection;
|
|
337
|
+
}
|
|
338
|
+
zeroShotPromptForSelection(user_utterance, selection) {
|
|
339
|
+
const historyContext = this.buildHistoryContext();
|
|
340
|
+
const uiContext = this.buildRuntimeUiContextBlock();
|
|
341
|
+
const basic = this.buildPromptBasic(selection.classDescriptions, selection.examples, historyContext, uiContext);
|
|
342
|
+
return `${(0, prompt_res_1.parseCodePrompt)(basic)}${(0, prompt_res_1.user_interaction_prompt)(user_utterance)}`;
|
|
343
|
+
}
|
|
344
|
+
prompt(user_utterance) {
|
|
345
|
+
const selection = this.computeSelection(user_utterance);
|
|
346
|
+
const historyContext = this.buildHistoryContext();
|
|
347
|
+
const uiContext = this.buildRuntimeUiContextBlock();
|
|
348
|
+
const basic = this.buildPromptBasic(selection.classDescriptions, selection.examples, historyContext, uiContext);
|
|
349
|
+
return `${basic}${(0, prompt_res_1.user_interaction_prompt)(user_utterance)}`;
|
|
350
|
+
}
|
|
351
|
+
zero_shot_prompt(user_utterance) {
|
|
352
|
+
const selection = this.computeSelection(user_utterance);
|
|
353
|
+
return this.zeroShotPromptForSelection(user_utterance, selection);
|
|
354
|
+
}
|
|
355
|
+
response_prompt(user_utterance, parsed, result) {
|
|
356
|
+
return (0, prompt_res_1.agent_response_prompt)(user_utterance, parsed, result);
|
|
357
|
+
}
|
|
358
|
+
recordInteraction(record) {
|
|
359
|
+
this.recentTurns.push(record);
|
|
360
|
+
while (this.recentTurns.length > this.config.recentTurnsWindow) {
|
|
361
|
+
const shifted = this.recentTurns.shift();
|
|
362
|
+
if (shifted) {
|
|
363
|
+
this.appendOlderSummary(this.summarizeRecord(shifted));
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
exports.ContextAwareDescriptorPromptGen = ContextAwareDescriptorPromptGen;
|
|
369
|
+
//# sourceMappingURL=prompt-gen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-gen.js","sourceRoot":"","sources":["../../lib/nl/prompt-gen.ts"],"names":[],"mappings":";;;AAAA,6CAasB;AAEtB,yDAAkF;AA6DlF,MAAM,+BAA+B,GAA0B;IAC7D,OAAO,EAAE,IAAI;IACb,qBAAqB,EAAE,EAAE;IACzB,YAAY,EAAE,CAAC;IACf,iBAAiB,EAAE,CAAC;IACpB,oBAAoB,EAAE,GAAG;IACzB,SAAS,EAAE,EAAE;CACd,CAAC;AAEF,MAAa,YAAY;IACvB,YAAqB,cAAc,EAAW,cAAc;QAAvC,mBAAc,GAAd,cAAc,CAAA;QAAW,mBAAc,GAAd,cAAc,CAAA;IAAG,CAAC;CACjE;AAFD,oCAEC;AAED,MAAa,cAAc;IACzB,YACU,kBAA4B,EAC5B,QAAwB,EACxB,WAAoB;QAFpB,uBAAkB,GAAlB,kBAAkB,CAAU;QAC5B,aAAQ,GAAR,QAAQ,CAAgB;QACxB,gBAAW,GAAX,WAAW,CAAS;IAC3B,CAAC;IAEJ,YAAY;QACV,IAAI,MAAM,GACR,GAAG,0BAAa,GAAG,kCAAqB,EAAE;YAC1C,GAAG,6BAAgB,GAAG,4BAAe,EAAE;YACvC,GAAG,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAC7B,4BAAe,CAChB,GAAG,mCAAsB,EAAE;YAC5B,GAAG,4BAAe,GAAG,kCAAqB,EAAE;YAC5C,GAAG,IAAA,2BAAc,EAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,mCAAsB,EAAE;YAC3D,GAAG,qCAAwB,GAAG,mCAAsB,EAAE;YAEtD,GAAG,qCAAwB,GAAG,kCAA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,EAAE,CAAC;gBACZ,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAncD,0EAmcC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ExampleParse } from "./prompt-gen";
|
|
2
|
+
export declare const pre_section_separator = "\n";
|
|
3
|
+
export declare const post_section_separator = "\n\n\n";
|
|
4
|
+
export declare const class_prequel = "// Here are all the functions";
|
|
5
|
+
export declare const array_definition: string;
|
|
6
|
+
export declare const class_separator = "\n\n";
|
|
7
|
+
export declare const example_prequel = "// Here are all the examples that we have";
|
|
8
|
+
export declare function example_pair(example: ExampleParse): string;
|
|
9
|
+
export declare const example_separator = "\n\n";
|
|
10
|
+
export declare const accessor_parameter_rules: string;
|
|
11
|
+
export declare function example_parses(examples: ExampleParse[]): string;
|
|
12
|
+
export declare const user_interaction_prequel = "// New user interaction";
|
|
13
|
+
export declare function user_interaction_prompt(user_utterance: string): string;
|
|
14
|
+
export declare function agent_response_prompt(user_utterance: string, parsed: string, result: string): string;
|
|
15
|
+
export declare const parse_issues = "\n// Here are the issues that need to be noticed\n// 1. Use \"Array[index]\" instead of index related functions. For example, \"hotels[0]\" instead of \"hotels.first()\"\n// 2. Use \"setProperty(value) instead of \"property = value\". For example, \"hotel.setName(123)\" instead of \"hotel.name = 123\"\n// 3. Use \";\" between multiple function calls. For example, \"hotel.setName(123); hotel.setDesc(123)\"";
|
|
16
|
+
export declare function parseCodePrompt(appBasicPrompt: string): string;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseCodePrompt = exports.parse_issues = exports.agent_response_prompt = exports.user_interaction_prompt = exports.user_interaction_prequel = exports.example_parses = exports.accessor_parameter_rules = exports.example_separator = exports.example_pair = exports.example_prequel = exports.class_separator = exports.array_definition = exports.class_prequel = exports.post_section_separator = exports.pre_section_separator = void 0;
|
|
4
|
+
exports.pre_section_separator = "\n";
|
|
5
|
+
exports.post_section_separator = "\n\n\n";
|
|
6
|
+
exports.class_prequel = "// Here are all the functions";
|
|
7
|
+
exports.array_definition = "extension Array<Type> {\n" +
|
|
8
|
+
" // Find items with matching fields in an array\n" +
|
|
9
|
+
" Array<Type> matching(field: Field, value: Type);\n" +
|
|
10
|
+
"\n" +
|
|
11
|
+
" // Find items with field in an array that contains a specific value\n" +
|
|
12
|
+
" Array<Type> contains(field: Field, value: Type);\n" +
|
|
13
|
+
"\n" +
|
|
14
|
+
" // Find items with exact fields in an array\n" +
|
|
15
|
+
" Array<Type> equals(field: Field, value: Type);\n" +
|
|
16
|
+
"\n" +
|
|
17
|
+
" // Find items with the field above from (if provided) and below to (if provided).\n" +
|
|
18
|
+
" Array<Type> between(field: Field, from?: Type, to?: Type);\n" +
|
|
19
|
+
"\n" +
|
|
20
|
+
" // Sort an array based on a specific field in ascending or descending order\n" +
|
|
21
|
+
" Array<Type> sort(field: Field, ascending: bool);\n" +
|
|
22
|
+
"\n" +
|
|
23
|
+
" // Get length of an array\n" +
|
|
24
|
+
" int length();\n" +
|
|
25
|
+
"}";
|
|
26
|
+
exports.class_separator = "\n\n";
|
|
27
|
+
exports.example_prequel = "// Here are all the examples that we have";
|
|
28
|
+
function example_pair(example) {
|
|
29
|
+
return (`user: ${example.user_utterance}\n` + `parsed: ${example.example_parsed}`);
|
|
30
|
+
}
|
|
31
|
+
exports.example_pair = example_pair;
|
|
32
|
+
exports.example_separator = "\n\n";
|
|
33
|
+
exports.accessor_parameter_rules = "// Accessor parameter rules\n" +
|
|
34
|
+
"// For matching, contains, equals, between, and sort, the field parameter MUST be a dotted accessor, never a quoted string.\n" +
|
|
35
|
+
'// ✅ CORRECT: Probe.getAllProbes().contains(field: .customerName, value: "Freshmarket")\n' +
|
|
36
|
+
'// ❌ WRONG: Probe.getAllProbes().contains(field: "customerName", value: "Freshmarket")\n' +
|
|
37
|
+
"// Use nested dotted accessors for nested fields, for example .dateTime.day.\n";
|
|
38
|
+
function example_parses(examples) {
|
|
39
|
+
return examples
|
|
40
|
+
.map((example) => example_pair(example))
|
|
41
|
+
.join(exports.example_separator);
|
|
42
|
+
}
|
|
43
|
+
exports.example_parses = example_parses;
|
|
44
|
+
exports.user_interaction_prequel = "// New user interaction";
|
|
45
|
+
function user_interaction_prompt(user_utterance) {
|
|
46
|
+
return `user: ${user_utterance}\n` + `parsed:`;
|
|
47
|
+
}
|
|
48
|
+
exports.user_interaction_prompt = user_interaction_prompt;
|
|
49
|
+
function agent_response_prompt(user_utterance, parsed, result) {
|
|
50
|
+
return (`user: ${user_utterance}\n` +
|
|
51
|
+
`parsed: ${parsed}\n` +
|
|
52
|
+
`response_context: ${result}\n` +
|
|
53
|
+
`Generate STRICT JSON with keys: minimalText, fullText, type, shouldSpeak.\n` +
|
|
54
|
+
`Rules: minimalText MUST be exactly one or two words, easy to speak, and no DSL/code.\n` +
|
|
55
|
+
`Rules: minimalText should sound task/equipment-work professional (lab persona), low emotion, low cognitive load.\n` +
|
|
56
|
+
`Rules: minimalText examples: "Completed", "In progress", "Check sample", "Retry task".\n` +
|
|
57
|
+
`Rules: fullText should be informative but concise (<=240 chars).\n` +
|
|
58
|
+
`Rules: type must be one of info|error|success|warning.\n` +
|
|
59
|
+
`Rules: shouldSpeak must be true only when spoken feedback helps the user.\n` +
|
|
60
|
+
`agent_response_json:`);
|
|
61
|
+
}
|
|
62
|
+
exports.agent_response_prompt = agent_response_prompt;
|
|
63
|
+
exports.parse_issues = `
|
|
64
|
+
// Here are the issues that need to be noticed
|
|
65
|
+
// 1. Use "Array[index]" instead of index related functions. For example, "hotels[0]" instead of "hotels.first()"
|
|
66
|
+
// 2. Use "setProperty(value) instead of "property = value". For example, "hotel.setName(123)" instead of "hotel.name = 123"
|
|
67
|
+
// 3. Use ";" between multiple function calls. For example, "hotel.setName(123); hotel.setDesc(123)"`;
|
|
68
|
+
const exampleDeveloperClasses = `
|
|
69
|
+
// Here are all the function that we have
|
|
70
|
+
extension Array<Type> {
|
|
71
|
+
// find items with matching field in an array
|
|
72
|
+
Array<Type> matching(field: Field, value: Type);
|
|
73
|
+
|
|
74
|
+
// find items with field in an array that contains a specific value
|
|
75
|
+
Array<Type> contains(field: Field, value: Type);
|
|
76
|
+
|
|
77
|
+
// find items with exact field in an array
|
|
78
|
+
Array<Type> equals(field: Field, value: Type);
|
|
79
|
+
|
|
80
|
+
// find items with field between two values in an array
|
|
81
|
+
Array<Type> between(field: Field, from: Type, to: Type);
|
|
82
|
+
|
|
83
|
+
// sort an array based on a specific field in ascending or descending order
|
|
84
|
+
Array<Type> sort(field: Field, ascending: bool);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
class Counter {
|
|
88
|
+
string name;
|
|
89
|
+
string type;
|
|
90
|
+
int count;
|
|
91
|
+
static float Version;
|
|
92
|
+
static Counter GetCounter(name: string);
|
|
93
|
+
void increment();
|
|
94
|
+
void decrement();
|
|
95
|
+
static Counter[] All();
|
|
96
|
+
static Counter Current();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
// Here are all the examples that we have
|
|
101
|
+
user: increment
|
|
102
|
+
parsed: Counter.Current().increment()
|
|
103
|
+
|
|
104
|
+
user: what is the count
|
|
105
|
+
parsed: Counter.Current().count
|
|
106
|
+
|
|
107
|
+
user: what is the count of potato
|
|
108
|
+
parsed: Counter.GetCounter(name: "potato").count
|
|
109
|
+
|
|
110
|
+
user: increment potato counter
|
|
111
|
+
parsed: Counter.GetCounter(name: "potato").increment()
|
|
112
|
+
|
|
113
|
+
user: show me all vegetables counters
|
|
114
|
+
parsed: Counter.All().matching(field: .type, value: "vegetable")
|
|
115
|
+
`;
|
|
116
|
+
function parseCodePrompt(appBasicPrompt) {
|
|
117
|
+
return `
|
|
118
|
+
Below are the developer class definitions, methods, and their descriptions as the comments of an example app.
|
|
119
|
+
After that, code parses from another app using ReactGenieDSL will be given.
|
|
120
|
+
A code parse is a voice command the user gives to be parsed into code that completes the requested action.
|
|
121
|
+
|
|
122
|
+
BEGIN
|
|
123
|
+
\`
|
|
124
|
+
${exampleDeveloperClasses}
|
|
125
|
+
\`
|
|
126
|
+
END
|
|
127
|
+
|
|
128
|
+
Note that all function calls have to have explicit parameter names in ReactGenieDSL.
|
|
129
|
+
|
|
130
|
+
For example:
|
|
131
|
+
\`
|
|
132
|
+
parsed: Counter.All().matching(.type, "vegetable")
|
|
133
|
+
\`
|
|
134
|
+
Is INCORRECT.
|
|
135
|
+
|
|
136
|
+
This is correct:
|
|
137
|
+
\`
|
|
138
|
+
parsed: Counter.All().matching(field: .type, value: "vegetable")
|
|
139
|
+
\`
|
|
140
|
+
|
|
141
|
+
And here is the developer classes and (optionally) code parses for this app in ReactGenieDSL:\n
|
|
142
|
+
BEGIN
|
|
143
|
+
\`
|
|
144
|
+
${appBasicPrompt}
|
|
145
|
+
\`
|
|
146
|
+
END
|
|
147
|
+
|
|
148
|
+
For code translation using \`ReactGenieDSL\`, follow these guidelines:
|
|
149
|
+
|
|
150
|
+
1. Formatting: Directly output code without code blocks. Use semicolons for separating multiple statements.
|
|
151
|
+
2. Follow declarations: Only use existing functions, do not introduce new functions.
|
|
152
|
+
3. Retrieval Over Answers: Translate user queries into code for information retrieval, not direct answers.
|
|
153
|
+
4. Contextual 'Current': Use 'Current' for items the user is directly interacting with or viewing.
|
|
154
|
+
5. Indexing: Use bracket notation for array indexing, supporting negative indices for last element.
|
|
155
|
+
6. No Math Operations: Replace direct math operations with method calls (e.g., 1.plus(1)).
|
|
156
|
+
7. Simplified Array Operations: Avoid map/lambda expressions; apply functions directly to array elements.
|
|
157
|
+
8. No Default Constructors: Use 'Create' methods for object creation; otherwise, selection from existing options.
|
|
158
|
+
9. Static vs. Non-Static Methods: Use static methods for direct class calls; retrieve instances for non-static methods.
|
|
159
|
+
10. Optional Parameters: Optional parameters are noted by \`?\` after their type, they can be omitted in function calls.
|
|
160
|
+
11. Use Setters: Avoid assignments; utilize function calls (set[Something]) for selections or changes.
|
|
161
|
+
12. Property Access: When accessing nested properties, ensure to navigate through all necessary parent properties.
|
|
162
|
+
|
|
163
|
+
**CRITICAL - Array Parameter Syntax:**
|
|
164
|
+
13. When passing array values to function parameters, you MUST wrap them in square brackets [...] even if the expression already returns an array.
|
|
165
|
+
|
|
166
|
+
✅ CORRECT: Order.current().addFoods(foods: [Order.all().matching(field: .restaurant, value: Restaurant.all()[0]).foods()])
|
|
167
|
+
❌ WRONG: Order.current().addFoods(foods: Order.all().matching(field: .restaurant, value: Restaurant.all()[0]).foods())
|
|
168
|
+
|
|
169
|
+
✅ CORRECT: someFunction(items: [array.matching(field: .name, value: "test")])
|
|
170
|
+
❌ WRONG: someFunction(items: array.matching(field: .name, value: "test"))
|
|
171
|
+
|
|
172
|
+
Even though the expression returns an array type, the DSL syntax requires explicit brackets for array parameters.
|
|
173
|
+
|
|
174
|
+
**CRITICAL - Accessor Parameter Syntax:**
|
|
175
|
+
14. For matching, contains, equals, between, and sort, the \`field\` parameter MUST be a dotted accessor, never a quoted string literal.
|
|
176
|
+
|
|
177
|
+
✅ CORRECT: Probe.getAllProbes().contains(field: .customerName, value: "Freshmarket")
|
|
178
|
+
❌ WRONG: Probe.getAllProbes().contains(field: "customerName", value: "Freshmarket")
|
|
179
|
+
|
|
180
|
+
✅ CORRECT: Probe.getAllProbes().sort(field: .receivedAt, ascending: false)
|
|
181
|
+
❌ WRONG: Probe.getAllProbes().sort(field: "receivedAt", ascending: false)
|
|
182
|
+
|
|
183
|
+
For nested fields, keep the full dotted path, for example \`.dateTime.day\`.
|
|
184
|
+
|
|
185
|
+
New user interaction (think carefully)
|
|
186
|
+
|
|
187
|
+
`;
|
|
188
|
+
}
|
|
189
|
+
exports.parseCodePrompt = parseCodePrompt;
|
|
190
|
+
//# sourceMappingURL=prompt-res.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-res.js","sourceRoot":"","sources":["../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O,CACL,SAAS,cAAc,IAAI;QAC3B,WAAW,MAAM,IAAI;QACrB,qBAAqB,MAAM,IAAI;QAC/B,6EAA6E;QAC7E,wFAAwF;QACxF,oHAAoH;QACpH,0FAA0F;QAC1F,oEAAoE;QACpE,0DAA0D;QAC1D,6EAA6E;QAC7E,sBAAsB,CACvB,CAAC;AACJ,CAAC;AAlBD,sDAkBC;AAEY,QAAA,YAAY,GAAG;;;;qGAIyE,CAAA;AAErG,MAAM,uBAAuB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+C/B,CAAA;AAED,SAAgB,eAAe,CAAC,cAAsB;IAClD,OAAO;;;;;;;EAOT,uBAAuB;;;;;;;;;;;;;;;;;;;;EAoBvB,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2Cf,CAAC;AACF,CAAC;AAxED,0CAwEC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { PromptGen, SamplingParams } from "./nl";
|
|
2
|
+
import { ClassDescriptor, GenieObject } from "./dsl-descriptor";
|
|
3
|
+
import { NlParser, NlParserGroq } from "./nl";
|
|
4
|
+
import { DslInterpreter } from "./dsl";
|
|
5
|
+
import { AgentResponsePayload, ExampleParse, RuntimeUiContext } from "./nl/prompt-gen";
|
|
6
|
+
export type NlParserProvider = "groq" | "openai";
|
|
7
|
+
export interface NlInterpreterProviderSettings {
|
|
8
|
+
baseUrl?: string;
|
|
9
|
+
model?: string;
|
|
10
|
+
samplingParams?: SamplingParams;
|
|
11
|
+
statefulValidationRetry?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface NlInterpreterParserConfig {
|
|
14
|
+
provider?: NlParserProvider;
|
|
15
|
+
groq?: NlInterpreterProviderSettings;
|
|
16
|
+
openai?: NlInterpreterProviderSettings;
|
|
17
|
+
}
|
|
18
|
+
export interface NlInterpreterMonitoringConfig {
|
|
19
|
+
langsmithApiKey?: string;
|
|
20
|
+
langsmithProject?: string;
|
|
21
|
+
langsmithEndpoint?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface NlInterpreterOptions {
|
|
24
|
+
parser?: NlInterpreterParserConfig;
|
|
25
|
+
monitoring?: NlInterpreterMonitoringConfig;
|
|
26
|
+
}
|
|
27
|
+
export declare class NlInterpreter {
|
|
28
|
+
private descriptions;
|
|
29
|
+
private apiKey;
|
|
30
|
+
private prompt?;
|
|
31
|
+
private examples?;
|
|
32
|
+
private extraPrompt?;
|
|
33
|
+
private options;
|
|
34
|
+
nlParser: NlParser | NlParserGroq;
|
|
35
|
+
dslInterpreter: DslInterpreter;
|
|
36
|
+
private dslValidator;
|
|
37
|
+
constructor(descriptions: ClassDescriptor<GenieObject>[], apiKey: string, prompt?: PromptGen, examples?: ExampleParse[], extraPrompt?: string, options?: NlInterpreterOptions);
|
|
38
|
+
private recordInteraction;
|
|
39
|
+
recordTurn(record: {
|
|
40
|
+
utterance: string;
|
|
41
|
+
parsed?: string | null;
|
|
42
|
+
success: boolean;
|
|
43
|
+
resultSummary?: string;
|
|
44
|
+
}): void;
|
|
45
|
+
setRuntimeContext(context: RuntimeUiContext | null): void;
|
|
46
|
+
interpret(nl: string): Promise<GenieObject | null>;
|
|
47
|
+
respond(nl: string, parsed: string, result: string): Promise<AgentResponsePayload | null>;
|
|
48
|
+
}
|