flowquery 1.0.24 → 1.0.26

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 (54) hide show
  1. package/.github/workflows/release.yml +1 -0
  2. package/.husky/pre-commit +3 -2
  3. package/dist/flowquery.min.js +1 -1
  4. package/dist/parsing/parser.d.ts.map +1 -1
  5. package/dist/parsing/parser.js +1 -0
  6. package/dist/parsing/parser.js.map +1 -1
  7. package/dist/tokenization/string_walker.d.ts.map +1 -1
  8. package/dist/tokenization/string_walker.js +13 -12
  9. package/dist/tokenization/string_walker.js.map +1 -1
  10. package/docs/flowquery.min.js +1 -1
  11. package/flowquery-py/pyproject.toml +1 -1
  12. package/flowquery-py/src/parsing/parser.py +1 -0
  13. package/flowquery-py/src/tokenization/string_walker.py +1 -1
  14. package/flowquery-py/tests/compute/test_runner.py +26 -0
  15. package/flowquery-py/tests/parsing/test_parser.py +64 -0
  16. package/flowquery-vscode/flowQueryEngine/flowquery.min.js +1 -1
  17. package/jest.config.js +6 -9
  18. package/misc/apps/RAG/data/chats.json +302 -0
  19. package/misc/apps/RAG/data/emails.json +182 -0
  20. package/misc/apps/RAG/data/events.json +226 -0
  21. package/misc/apps/RAG/data/files.json +172 -0
  22. package/misc/apps/RAG/data/users.json +158 -0
  23. package/misc/apps/RAG/jest.config.js +21 -0
  24. package/misc/apps/RAG/package.json +9 -2
  25. package/misc/apps/RAG/src/App.tsx +5 -5
  26. package/misc/apps/RAG/src/components/ChatContainer.tsx +53 -124
  27. package/misc/apps/RAG/src/components/FlowQueryAgent.ts +151 -157
  28. package/misc/apps/RAG/src/components/index.ts +1 -1
  29. package/misc/apps/RAG/src/graph/index.ts +19 -0
  30. package/misc/apps/RAG/src/graph/initializeGraph.ts +254 -0
  31. package/misc/apps/RAG/src/index.tsx +25 -13
  32. package/misc/apps/RAG/src/prompts/FlowQuerySystemPrompt.ts +146 -231
  33. package/misc/apps/RAG/src/prompts/index.ts +4 -4
  34. package/misc/apps/RAG/src/tests/graph.test.ts +35 -0
  35. package/misc/apps/RAG/src/utils/FlowQueryExecutor.ts +20 -21
  36. package/misc/apps/RAG/src/utils/FlowQueryExtractor.ts +35 -30
  37. package/misc/apps/RAG/src/utils/Llm.ts +248 -0
  38. package/misc/apps/RAG/src/utils/index.ts +7 -4
  39. package/misc/apps/RAG/tsconfig.json +4 -3
  40. package/misc/apps/RAG/webpack.config.js +40 -40
  41. package/package.json +1 -1
  42. package/src/parsing/parser.ts +1 -0
  43. package/src/tokenization/string_walker.ts +19 -16
  44. package/tests/compute/runner.test.ts +1 -1
  45. package/tests/parsing/parser.test.ts +61 -0
  46. package/misc/apps/RAG/src/plugins/README.md +0 -139
  47. package/misc/apps/RAG/src/plugins/index.ts +0 -72
  48. package/misc/apps/RAG/src/plugins/loaders/CatFacts.ts +0 -70
  49. package/misc/apps/RAG/src/plugins/loaders/FetchJson.ts +0 -65
  50. package/misc/apps/RAG/src/plugins/loaders/Form.ts +0 -594
  51. package/misc/apps/RAG/src/plugins/loaders/Llm.ts +0 -450
  52. package/misc/apps/RAG/src/plugins/loaders/MockData.ts +0 -101
  53. package/misc/apps/RAG/src/plugins/loaders/Table.ts +0 -274
  54. package/misc/apps/RAG/src/plugins/loaders/Weather.ts +0 -138
@@ -1,594 +0,0 @@
1
- /**
2
- * Form plugin - transforms configuration into Adaptive Card form format.
3
- *
4
- * Adaptive Cards are platform-agnostic UI snippets that can be rendered in
5
- * Microsoft Teams, Outlook, Windows, and other applications.
6
- *
7
- * This plugin creates customizable forms with various input types including:
8
- * - Text inputs (single and multi-line)
9
- * - Number inputs
10
- * - Date and time pickers
11
- * - Dropdown/choice sets
12
- * - Toggle switches
13
- * - Choice sets (radio buttons, checkboxes)
14
- *
15
- * Usage in FlowQuery:
16
- * // Create a simple contact form:
17
- * CALL form('Contact Us', [
18
- * { id: 'name', type: 'text', label: 'Your Name', required: true },
19
- * { id: 'email', type: 'text', label: 'Email', placeholder: 'you@example.com' },
20
- * { id: 'message', type: 'textarea', label: 'Message' }
21
- * ]) YIELD type, body, actions
22
- */
23
- import { AsyncFunction, FunctionDef } from "flowquery/extensibility";
24
-
25
- /**
26
- * Interface for Adaptive Card structure
27
- */
28
- interface AdaptiveCard {
29
- type: "AdaptiveCard";
30
- $schema: string;
31
- version: string;
32
- body: AdaptiveCardElement[];
33
- actions?: AdaptiveCardAction[];
34
- }
35
-
36
- interface AdaptiveCardElement {
37
- type: string;
38
- [key: string]: any;
39
- }
40
-
41
- interface AdaptiveCardAction {
42
- type: string;
43
- title: string;
44
- [key: string]: any;
45
- }
46
-
47
- /**
48
- * Input field configuration
49
- */
50
- interface FormFieldConfig {
51
- /** Unique identifier for the field */
52
- id: string;
53
- /** Input type: text, textarea, number, date, time, datetime, toggle, dropdown, radio, checkbox */
54
- type:
55
- | "text"
56
- | "textarea"
57
- | "number"
58
- | "date"
59
- | "time"
60
- | "datetime"
61
- | "toggle"
62
- | "dropdown"
63
- | "radio"
64
- | "checkbox";
65
- /** Display label for the field */
66
- label: string;
67
- /** Placeholder text for input fields */
68
- placeholder?: string;
69
- /** Default value */
70
- defaultValue?: any;
71
- /** Whether the field is required */
72
- required?: boolean;
73
- /** Choices for dropdown/radio/checkbox types */
74
- choices?: Array<{ title: string; value: string }> | string[];
75
- /** Minimum value for number inputs */
76
- min?: number;
77
- /** Maximum value for number inputs */
78
- max?: number;
79
- /** Regex pattern for validation (displayed in error message) */
80
- pattern?: string;
81
- /** Error message for validation */
82
- errorMessage?: string;
83
- /** Toggle title (for toggle type) */
84
- toggleTitle?: string;
85
- /** Whether the field is read-only */
86
- readOnly?: boolean;
87
- /** Separator before this field */
88
- separator?: boolean;
89
- /** Field width: auto, stretch, or weighted value */
90
- width?: "auto" | "stretch" | number;
91
- /** Custom style for the label */
92
- labelStyle?: "default" | "heading";
93
- }
94
-
95
- /**
96
- * Form configuration options
97
- */
98
- interface FormConfig {
99
- /** Form title */
100
- title?: string;
101
- /** Form description/subtitle */
102
- description?: string;
103
- /** Submit button configuration */
104
- submitButton?: {
105
- title?: string;
106
- style?: "default" | "positive" | "destructive";
107
- /** Action URL for form submission */
108
- url?: string;
109
- /** Action type: submit, openUrl, or custom */
110
- actionType?: "submit" | "openUrl" | "showCard";
111
- };
112
- /** Additional action buttons */
113
- additionalActions?: Array<{
114
- title: string;
115
- type: "submit" | "openUrl" | "showCard";
116
- url?: string;
117
- style?: "default" | "positive" | "destructive";
118
- data?: any;
119
- }>;
120
- /** Card background style */
121
- style?: "default" | "emphasis" | "good" | "attention" | "warning" | "accent";
122
- /** Whether to show a reset/clear button */
123
- showResetButton?: boolean;
124
- /** Card schema version */
125
- version?: string;
126
- }
127
-
128
- /**
129
- * Form class - creates customizable Adaptive Card forms.
130
- */
131
- @FunctionDef({
132
- description: "Creates a customizable Adaptive Card form with various input types",
133
- category: "async",
134
- parameters: [
135
- {
136
- name: "title",
137
- description: "Form title displayed at the top",
138
- type: "string",
139
- required: true,
140
- },
141
- {
142
- name: "fields",
143
- description: "Array of field configurations defining the form inputs",
144
- type: "array",
145
- required: true,
146
- },
147
- {
148
- name: "config",
149
- description: "Optional form configuration (submit button, additional actions, styling)",
150
- type: "object",
151
- required: false,
152
- },
153
- ],
154
- output: {
155
- description: "Adaptive Card JSON object with form elements",
156
- type: "object",
157
- properties: {
158
- type: { description: 'Always "AdaptiveCard"', type: "string" },
159
- $schema: { description: "Adaptive Card schema URL", type: "string" },
160
- version: { description: "Adaptive Card version", type: "string" },
161
- body: { description: "Card body elements including form inputs", type: "array" },
162
- actions: { description: "Card actions (submit, cancel, etc.)", type: "array" },
163
- },
164
- },
165
- examples: [
166
- "CALL form('Contact Form', [{ id: 'name', type: 'text', label: 'Name', required: true }, { id: 'email', type: 'text', label: 'Email' }]) YIELD type, body, actions",
167
- "CALL form('Survey', [{ id: 'rating', type: 'dropdown', label: 'Rating', choices: ['1', '2', '3', '4', '5'] }, { id: 'subscribe', type: 'toggle', label: 'Subscribe', toggleTitle: 'Yes, send me updates' }], { submitButton: { title: 'Submit Survey', style: 'positive' } }) YIELD type, body, actions",
168
- ],
169
- })
170
- export class Form extends AsyncFunction {
171
- /**
172
- * Creates an Adaptive Card form with the specified fields and configuration.
173
- *
174
- * @param title - Form title
175
- * @param fields - Array of field configurations
176
- * @param config - Optional form configuration
177
- */
178
- async *generate(
179
- title: string,
180
- fields: FormFieldConfig[],
181
- config?: FormConfig
182
- ): AsyncGenerator<AdaptiveCard, void, unknown> {
183
- const card = this.createFormCard(title, fields, config || {});
184
- yield card;
185
- }
186
-
187
- /**
188
- * Creates the Adaptive Card with form elements.
189
- */
190
- private createFormCard(
191
- title: string,
192
- fields: FormFieldConfig[],
193
- config: FormConfig
194
- ): AdaptiveCard {
195
- const card: AdaptiveCard = {
196
- type: "AdaptiveCard",
197
- $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
198
- version: config.version || "1.5",
199
- body: [],
200
- actions: [],
201
- };
202
-
203
- // Add container with optional background style
204
- const container: AdaptiveCardElement = {
205
- type: "Container",
206
- style: config.style || "default",
207
- items: [],
208
- };
209
-
210
- // Add title
211
- container.items.push({
212
- type: "TextBlock",
213
- text: title,
214
- weight: "Bolder",
215
- size: "Large",
216
- wrap: true,
217
- });
218
-
219
- // Add description if provided
220
- if (config.description) {
221
- container.items.push({
222
- type: "TextBlock",
223
- text: config.description,
224
- isSubtle: true,
225
- wrap: true,
226
- spacing: "Small",
227
- });
228
- }
229
-
230
- // Add separator after header
231
- container.items.push({
232
- type: "TextBlock",
233
- text: " ",
234
- separator: true,
235
- spacing: "Medium",
236
- });
237
-
238
- // Add form fields
239
- for (const field of fields) {
240
- const fieldElements = this.createFieldElements(field);
241
- container.items.push(...fieldElements);
242
- }
243
-
244
- card.body.push(container);
245
-
246
- // Add actions
247
- card.actions = this.createActions(config);
248
-
249
- return card;
250
- }
251
-
252
- /**
253
- * Creates the elements for a single form field (label + input).
254
- */
255
- private createFieldElements(field: FormFieldConfig): AdaptiveCardElement[] {
256
- const elements: AdaptiveCardElement[] = [];
257
-
258
- // Add label
259
- const labelText = field.required ? `${field.label} *` : field.label;
260
- elements.push({
261
- type: "TextBlock",
262
- text: labelText,
263
- weight: field.labelStyle === "heading" ? "Bolder" : "Default",
264
- wrap: true,
265
- separator: field.separator || false,
266
- spacing: field.separator ? "Large" : "Default",
267
- });
268
-
269
- // Add input based on type
270
- const inputElement = this.createInputElement(field);
271
- elements.push(inputElement);
272
-
273
- return elements;
274
- }
275
-
276
- /**
277
- * Creates the appropriate input element based on field type.
278
- */
279
- private createInputElement(field: FormFieldConfig): AdaptiveCardElement {
280
- switch (field.type) {
281
- case "text":
282
- return this.createTextInput(field, false);
283
-
284
- case "textarea":
285
- return this.createTextInput(field, true);
286
-
287
- case "number":
288
- return this.createNumberInput(field);
289
-
290
- case "date":
291
- return this.createDateInput(field);
292
-
293
- case "time":
294
- return this.createTimeInput(field);
295
-
296
- case "datetime":
297
- return this.createDateTimeInputs(field);
298
-
299
- case "toggle":
300
- return this.createToggleInput(field);
301
-
302
- case "dropdown":
303
- return this.createChoiceSet(field, "compact");
304
-
305
- case "radio":
306
- return this.createChoiceSet(field, "expanded");
307
-
308
- case "checkbox":
309
- return this.createChoiceSet(field, "expanded", true);
310
-
311
- default:
312
- return this.createTextInput(field, false);
313
- }
314
- }
315
-
316
- /**
317
- * Creates a text input element.
318
- */
319
- private createTextInput(field: FormFieldConfig, isMultiLine: boolean): AdaptiveCardElement {
320
- const input: AdaptiveCardElement = {
321
- type: "Input.Text",
322
- id: field.id,
323
- placeholder: field.placeholder || "",
324
- isMultiline: isMultiLine,
325
- isRequired: field.required || false,
326
- };
327
-
328
- if (field.defaultValue !== undefined) {
329
- input.value = String(field.defaultValue);
330
- }
331
-
332
- if (field.pattern) {
333
- input.regex = field.pattern;
334
- }
335
-
336
- if (field.errorMessage) {
337
- input.errorMessage = field.errorMessage;
338
- }
339
-
340
- if (isMultiLine) {
341
- input.style = "text";
342
- }
343
-
344
- return input;
345
- }
346
-
347
- /**
348
- * Creates a number input element.
349
- */
350
- private createNumberInput(field: FormFieldConfig): AdaptiveCardElement {
351
- const input: AdaptiveCardElement = {
352
- type: "Input.Number",
353
- id: field.id,
354
- placeholder: field.placeholder || "",
355
- isRequired: field.required || false,
356
- };
357
-
358
- if (field.defaultValue !== undefined) {
359
- input.value = Number(field.defaultValue);
360
- }
361
-
362
- if (field.min !== undefined) {
363
- input.min = field.min;
364
- }
365
-
366
- if (field.max !== undefined) {
367
- input.max = field.max;
368
- }
369
-
370
- if (field.errorMessage) {
371
- input.errorMessage = field.errorMessage;
372
- }
373
-
374
- return input;
375
- }
376
-
377
- /**
378
- * Creates a date input element.
379
- */
380
- private createDateInput(field: FormFieldConfig): AdaptiveCardElement {
381
- const input: AdaptiveCardElement = {
382
- type: "Input.Date",
383
- id: field.id,
384
- isRequired: field.required || false,
385
- };
386
-
387
- if (field.defaultValue !== undefined) {
388
- input.value = String(field.defaultValue);
389
- }
390
-
391
- if (field.placeholder) {
392
- input.placeholder = field.placeholder;
393
- }
394
-
395
- return input;
396
- }
397
-
398
- /**
399
- * Creates a time input element.
400
- */
401
- private createTimeInput(field: FormFieldConfig): AdaptiveCardElement {
402
- const input: AdaptiveCardElement = {
403
- type: "Input.Time",
404
- id: field.id,
405
- isRequired: field.required || false,
406
- };
407
-
408
- if (field.defaultValue !== undefined) {
409
- input.value = String(field.defaultValue);
410
- }
411
-
412
- if (field.placeholder) {
413
- input.placeholder = field.placeholder;
414
- }
415
-
416
- return input;
417
- }
418
-
419
- /**
420
- * Creates date and time inputs in a column set for datetime fields.
421
- */
422
- private createDateTimeInputs(field: FormFieldConfig): AdaptiveCardElement {
423
- const dateValue = field.defaultValue ? String(field.defaultValue).split("T")[0] : undefined;
424
- const timeValue = field.defaultValue
425
- ? String(field.defaultValue).split("T")[1]?.substring(0, 5)
426
- : undefined;
427
-
428
- return {
429
- type: "ColumnSet",
430
- columns: [
431
- {
432
- type: "Column",
433
- width: "stretch",
434
- items: [
435
- {
436
- type: "Input.Date",
437
- id: `${field.id}_date`,
438
- isRequired: field.required || false,
439
- value: dateValue,
440
- },
441
- ],
442
- },
443
- {
444
- type: "Column",
445
- width: "stretch",
446
- items: [
447
- {
448
- type: "Input.Time",
449
- id: `${field.id}_time`,
450
- isRequired: field.required || false,
451
- value: timeValue,
452
- },
453
- ],
454
- },
455
- ],
456
- };
457
- }
458
-
459
- /**
460
- * Creates a toggle input element.
461
- */
462
- private createToggleInput(field: FormFieldConfig): AdaptiveCardElement {
463
- const input: AdaptiveCardElement = {
464
- type: "Input.Toggle",
465
- id: field.id,
466
- title: field.toggleTitle || field.label,
467
- valueOn: "true",
468
- valueOff: "false",
469
- isRequired: field.required || false,
470
- };
471
-
472
- if (field.defaultValue !== undefined) {
473
- input.value = field.defaultValue ? "true" : "false";
474
- }
475
-
476
- return input;
477
- }
478
-
479
- /**
480
- * Creates a choice set (dropdown, radio, or checkbox).
481
- */
482
- private createChoiceSet(
483
- field: FormFieldConfig,
484
- style: "compact" | "expanded",
485
- isMultiSelect: boolean = false
486
- ): AdaptiveCardElement {
487
- const choices = this.normalizeChoices(field.choices || []);
488
-
489
- const input: AdaptiveCardElement = {
490
- type: "Input.ChoiceSet",
491
- id: field.id,
492
- style: style,
493
- isMultiSelect: isMultiSelect,
494
- isRequired: field.required || false,
495
- choices: choices,
496
- };
497
-
498
- if (field.defaultValue !== undefined) {
499
- input.value = String(field.defaultValue);
500
- }
501
-
502
- if (field.placeholder && style === "compact") {
503
- input.placeholder = field.placeholder;
504
- }
505
-
506
- return input;
507
- }
508
-
509
- /**
510
- * Normalizes choices to the expected format.
511
- */
512
- private normalizeChoices(
513
- choices: Array<{ title: string; value: string }> | string[]
514
- ): Array<{ title: string; value: string }> {
515
- return choices.map((choice) => {
516
- if (typeof choice === "string") {
517
- return { title: choice, value: choice };
518
- }
519
- return choice;
520
- });
521
- }
522
-
523
- /**
524
- * Creates the action buttons for the form.
525
- */
526
- private createActions(config: FormConfig): AdaptiveCardAction[] {
527
- const actions: AdaptiveCardAction[] = [];
528
-
529
- // Add submit button
530
- const submitConfig = config.submitButton || {};
531
- const submitAction: AdaptiveCardAction = {
532
- type: this.getActionType(submitConfig.actionType || "submit"),
533
- title: submitConfig.title || "Submit",
534
- style: submitConfig.style || "positive",
535
- };
536
-
537
- if (submitConfig.actionType === "openUrl" && submitConfig.url) {
538
- submitAction.url = submitConfig.url;
539
- }
540
-
541
- actions.push(submitAction);
542
-
543
- // Add reset button if requested
544
- if (config.showResetButton) {
545
- actions.push({
546
- type: "Action.Submit",
547
- title: "Reset",
548
- style: "default",
549
- data: { action: "reset" },
550
- });
551
- }
552
-
553
- // Add additional actions
554
- if (config.additionalActions) {
555
- for (const actionConfig of config.additionalActions) {
556
- const action: AdaptiveCardAction = {
557
- type: this.getActionType(actionConfig.type),
558
- title: actionConfig.title,
559
- style: actionConfig.style || "default",
560
- };
561
-
562
- if (actionConfig.type === "openUrl" && actionConfig.url) {
563
- action.url = actionConfig.url;
564
- }
565
-
566
- if (actionConfig.data) {
567
- action.data = actionConfig.data;
568
- }
569
-
570
- actions.push(action);
571
- }
572
- }
573
-
574
- return actions;
575
- }
576
-
577
- /**
578
- * Gets the Adaptive Card action type string.
579
- */
580
- private getActionType(type: string): string {
581
- switch (type) {
582
- case "submit":
583
- return "Action.Submit";
584
- case "openUrl":
585
- return "Action.OpenUrl";
586
- case "showCard":
587
- return "Action.ShowCard";
588
- default:
589
- return "Action.Submit";
590
- }
591
- }
592
- }
593
-
594
- export { Form as default };