@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,310 +0,0 @@
1
- import { AgentResponsePayload, PromptGen, ResponseSeverity } from "./prompt-gen";
2
-
3
- export interface PromptWithBroadFallback extends PromptGen {
4
- zero_shot_prompt_broad?: (user_utterance: string) => string;
5
- }
6
-
7
- export type CommandValidator = (command: string) => Promise<void>;
8
-
9
- export interface SamplingParams {
10
- temperature?: number;
11
- top_p?: number;
12
- frequency_penalty?: number;
13
- presence_penalty?: number;
14
- }
15
-
16
- export const DEFAULT_SEMANTIC_PARSER_SAMPLING: Required<SamplingParams> = {
17
- temperature: 0.2,
18
- top_p: 1,
19
- frequency_penalty: 0,
20
- presence_penalty: 0,
21
- };
22
-
23
- const DSL_COMMAND_SCHEMA = {
24
- name: "dsl_command",
25
- schema: {
26
- type: "object",
27
- properties: {
28
- command: {
29
- type: "string",
30
- description: "Single DSL command string to execute.",
31
- },
32
- },
33
- required: ["command"],
34
- additionalProperties: false,
35
- },
36
- } as const;
37
-
38
- const AGENT_RESPONSE_SCHEMA = {
39
- name: "agent_response",
40
- schema: {
41
- type: "object",
42
- properties: {
43
- minimalText: {
44
- type: "string",
45
- description: "Short, speech-friendly response.",
46
- },
47
- fullText: {
48
- type: "string",
49
- description: "More informative response for on-screen UI.",
50
- },
51
- type: {
52
- type: "string",
53
- enum: ["info", "error", "success", "warning"],
54
- },
55
- shouldSpeak: {
56
- type: "boolean",
57
- },
58
- },
59
- required: ["minimalText", "fullText", "type", "shouldSpeak"],
60
- additionalProperties: false,
61
- },
62
- } as const;
63
-
64
- export function getStructuredResponseFormat(strict: boolean) {
65
- return {
66
- type: "json_schema",
67
- json_schema: {
68
- name: DSL_COMMAND_SCHEMA.name,
69
- strict,
70
- schema: DSL_COMMAND_SCHEMA.schema,
71
- },
72
- } as const;
73
- }
74
-
75
- export function getStructuredResponseTextFormat(strict: boolean) {
76
- return {
77
- type: "json_schema",
78
- name: DSL_COMMAND_SCHEMA.name,
79
- strict,
80
- schema: DSL_COMMAND_SCHEMA.schema,
81
- } as const;
82
- }
83
-
84
- export function getStructuredAgentResponseFormat(strict: boolean) {
85
- return {
86
- type: "json_schema",
87
- json_schema: {
88
- name: AGENT_RESPONSE_SCHEMA.name,
89
- strict,
90
- schema: AGENT_RESPONSE_SCHEMA.schema,
91
- },
92
- } as const;
93
- }
94
-
95
- export function extractStructuredCommand(raw?: string | null): string | null {
96
- if (!raw) return null;
97
- try {
98
- const parsed = JSON.parse(raw);
99
- if (parsed && typeof parsed.command === "string") {
100
- return parsed.command.trim();
101
- }
102
- } catch {
103
- // ignore parse errors
104
- }
105
- return null;
106
- }
107
-
108
- export function extractResponseOutputText(response: any): string | null {
109
- if (typeof response?.output_text === "string" && response.output_text.trim()) {
110
- return response.output_text;
111
- }
112
-
113
- const output = Array.isArray(response?.output) ? response.output : [];
114
- const parts: string[] = [];
115
- for (const item of output) {
116
- const content = Array.isArray(item?.content) ? item.content : [];
117
- for (const part of content) {
118
- if (typeof part?.text === "string" && part.text) {
119
- parts.push(part.text);
120
- } else if (typeof part?.output_text === "string" && part.output_text) {
121
- parts.push(part.output_text);
122
- }
123
- }
124
- }
125
-
126
- return parts.length > 0 ? parts.join("") : null;
127
- }
128
-
129
- export function truncateText(value: string, maxLength: number): string {
130
- if (value.length <= maxLength) {
131
- return value;
132
- }
133
- return `${value.slice(0, Math.max(0, maxLength - 1)).trimEnd()}…`;
134
- }
135
-
136
- function normalizeMinimalText(value?: string): string {
137
- const collapsed = (value || "Completed").replace(/\s+/g, " ").trim();
138
- if (!collapsed) {
139
- return "Completed";
140
- }
141
- const words = collapsed.split(" ").slice(0, 2);
142
- return truncateText(words.join(" "), 24);
143
- }
144
-
145
- function normalizeSeverity(value: unknown): ResponseSeverity {
146
- if (
147
- value === "info" ||
148
- value === "error" ||
149
- value === "success" ||
150
- value === "warning"
151
- ) {
152
- return value;
153
- }
154
- return "info";
155
- }
156
-
157
- export function normalizeAgentResponse(
158
- payload: Partial<AgentResponsePayload>
159
- ): AgentResponsePayload {
160
- const minimal = normalizeMinimalText(payload.minimalText);
161
- const full = truncateText(
162
- (payload.fullText || payload.minimalText || "Completed").trim(),
163
- 240
164
- );
165
- return {
166
- minimalText: minimal || "Completed",
167
- fullText: full || minimal || "Completed",
168
- type: normalizeSeverity(payload.type),
169
- shouldSpeak:
170
- typeof payload.shouldSpeak === "boolean" ? payload.shouldSpeak : true,
171
- };
172
- }
173
-
174
- export function extractStructuredAgentResponse(
175
- raw?: string | null
176
- ): AgentResponsePayload | null {
177
- if (!raw) return null;
178
- try {
179
- const parsed = JSON.parse(raw);
180
- if (!parsed || typeof parsed !== "object") {
181
- return null;
182
- }
183
- return normalizeAgentResponse(parsed as Partial<AgentResponsePayload>);
184
- } catch {
185
- return null;
186
- }
187
- }
188
-
189
- export function buildFallbackAgentResponse(
190
- parsedDsl: string,
191
- resultContext: string
192
- ): AgentResponsePayload {
193
- const lowResultContext = resultContext.toLowerCase();
194
- const isError =
195
- lowResultContext.includes("error") || lowResultContext.includes("failed");
196
- const responseType: ResponseSeverity = isError ? "error" : "success";
197
- const intent = parsedDsl.split(";")[0]?.trim() || "command";
198
-
199
- if (isError) {
200
- return {
201
- minimalText: "Retry task",
202
- fullText:
203
- "I couldn't complete that request. Please try rephrasing or checking the target item.",
204
- type: responseType,
205
- shouldSpeak: true,
206
- };
207
- }
208
-
209
- return {
210
- minimalText: "Completed",
211
- fullText: truncateText(`Done: ${intent}`, 240),
212
- type: responseType,
213
- shouldSpeak: true,
214
- };
215
- }
216
-
217
- export function buildCommandRepairMessages(
218
- userUtterance: string,
219
- invalidCommand: string,
220
- validationError: string,
221
- lastUsedPrompt?: string
222
- ) {
223
- return [
224
- {
225
- role: "user",
226
- content: lastUsedPrompt || `Original user utterance: ${userUtterance}`,
227
- },
228
- {
229
- role: "assistant",
230
- content: invalidCommand,
231
- },
232
- {
233
- role: "user",
234
- content:
235
- "The previous DSL command is invalid.\n" +
236
- `validation_error: ${validationError}\n` +
237
- "Rewrite only the DSL command so it satisfies the original user utterance.\n" +
238
- "Keep the original intent. Do not explain anything.",
239
- },
240
- ] as const;
241
- }
242
-
243
- export function buildCommandRepairInputText(
244
- userUtterance: string,
245
- invalidCommand: string,
246
- validationError: string
247
- ): string {
248
- return (
249
- "The previous DSL command is invalid.\n" +
250
- `original_user_utterance: ${userUtterance}\n` +
251
- `invalid_command: ${invalidCommand}\n` +
252
- `validation_error: ${validationError}\n` +
253
- "Rewrite only the DSL command so it satisfies the original user utterance.\n" +
254
- "Keep the original intent. Do not explain anything."
255
- );
256
- }
257
-
258
- export function normalizeBaseUrl(baseUrl: string): string {
259
- return baseUrl.replace(/\/+$/, "");
260
- }
261
-
262
- export async function createJsonChatCompletion(params: {
263
- endpoint: string;
264
- apiKey: string;
265
- body: Record<string, unknown>;
266
- provider?: "openai" | "groq";
267
- requestLabel: string;
268
- invalidPayloadLabel: string;
269
- }): Promise<any> {
270
- const headers: Record<string, string> = {
271
- "content-type": "application/json",
272
- };
273
- if (params.apiKey) {
274
- headers.authorization = `Bearer ${params.apiKey}`;
275
- }
276
- if (params.provider) {
277
- headers["x-genie-provider"] = params.provider;
278
- }
279
-
280
- const response = await fetch(params.endpoint, {
281
- method: "POST",
282
- headers,
283
- body: JSON.stringify(params.body),
284
- });
285
-
286
- const text = await response.text();
287
- let payload: any = null;
288
- try {
289
- payload = text ? JSON.parse(text) : null;
290
- } catch {
291
- payload = null;
292
- }
293
-
294
- if (!response.ok) {
295
- const details = payload?.error
296
- ? typeof payload.error === "string"
297
- ? payload.error
298
- : JSON.stringify(payload.error)
299
- : text;
300
- throw new Error(
301
- `${params.requestLabel} (${response.status})${details ? `: ${details}` : ""}`
302
- );
303
- }
304
-
305
- if (!payload || typeof payload !== "object") {
306
- throw new Error(params.invalidPayloadLabel);
307
- }
308
-
309
- return payload;
310
- }