flowquery 1.0.11 → 1.0.13

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 (59) hide show
  1. package/README.md +142 -38
  2. package/dist/flowquery.min.js +1 -1
  3. package/dist/parsing/functions/aggregate_function.d.ts +1 -1
  4. package/dist/parsing/functions/aggregate_function.d.ts.map +1 -1
  5. package/dist/parsing/functions/aggregate_function.js.map +1 -1
  6. package/dist/parsing/functions/async_function.d.ts +4 -15
  7. package/dist/parsing/functions/async_function.d.ts.map +1 -1
  8. package/dist/parsing/functions/async_function.js +6 -59
  9. package/dist/parsing/functions/async_function.js.map +1 -1
  10. package/dist/parsing/functions/function.d.ts +1 -1
  11. package/dist/parsing/functions/function.d.ts.map +1 -1
  12. package/dist/parsing/functions/function.js +1 -1
  13. package/dist/parsing/functions/function.js.map +1 -1
  14. package/dist/parsing/functions/function_factory.d.ts +2 -0
  15. package/dist/parsing/functions/function_factory.d.ts.map +1 -1
  16. package/dist/parsing/functions/function_factory.js +12 -11
  17. package/dist/parsing/functions/function_factory.js.map +1 -1
  18. package/dist/parsing/functions/function_metadata.d.ts +53 -24
  19. package/dist/parsing/functions/function_metadata.d.ts.map +1 -1
  20. package/dist/parsing/functions/function_metadata.js +57 -53
  21. package/dist/parsing/functions/function_metadata.js.map +1 -1
  22. package/dist/parsing/functions/predicate_function.d.ts +1 -1
  23. package/dist/parsing/functions/predicate_function.d.ts.map +1 -1
  24. package/dist/parsing/functions/predicate_function.js +1 -1
  25. package/dist/parsing/functions/predicate_function.js.map +1 -1
  26. package/dist/parsing/operations/load.js +1 -1
  27. package/dist/parsing/operations/load.js.map +1 -1
  28. package/dist/parsing/parser.d.ts.map +1 -1
  29. package/dist/parsing/parser.js +1 -2
  30. package/dist/parsing/parser.js.map +1 -1
  31. package/docs/flowquery.min.js +1 -1
  32. package/flowquery-vscode/flowQueryEngine/flowquery.min.js +1 -1
  33. package/misc/apps/RAG/README.md +0 -12
  34. package/misc/apps/RAG/package.json +1 -2
  35. package/misc/apps/RAG/src/components/ChatContainer.tsx +33 -6
  36. package/misc/apps/RAG/src/components/ChatMessage.css +24 -0
  37. package/misc/apps/RAG/src/components/ChatMessage.tsx +51 -2
  38. package/misc/apps/RAG/src/components/FlowQueryAgent.ts +566 -286
  39. package/misc/apps/RAG/src/plugins/index.ts +3 -1
  40. package/misc/apps/RAG/src/plugins/loaders/CatFacts.ts +6 -5
  41. package/misc/apps/RAG/src/plugins/loaders/FetchJson.ts +3 -3
  42. package/misc/apps/RAG/src/plugins/loaders/Form.ts +5 -5
  43. package/misc/apps/RAG/src/plugins/loaders/Llm.ts +14 -14
  44. package/misc/apps/RAG/src/plugins/loaders/MockData.ts +5 -5
  45. package/misc/apps/RAG/src/plugins/loaders/Table.ts +4 -4
  46. package/misc/apps/RAG/src/plugins/loaders/Weather.ts +126 -0
  47. package/misc/apps/RAG/src/prompts/FlowQuerySystemPrompt.ts +4 -0
  48. package/package.json +1 -1
  49. package/src/parsing/functions/aggregate_function.ts +1 -1
  50. package/src/parsing/functions/async_function.ts +5 -50
  51. package/src/parsing/functions/function.ts +2 -2
  52. package/src/parsing/functions/function_factory.ts +18 -9
  53. package/src/parsing/functions/function_metadata.ts +57 -56
  54. package/src/parsing/functions/predicate_function.ts +2 -2
  55. package/src/parsing/operations/load.ts +1 -1
  56. package/src/parsing/parser.ts +2 -1
  57. package/tests/extensibility.test.ts +50 -12
  58. package/tests/parsing/parser.test.ts +2 -2
  59. package/misc/apps/RAG/.env.example +0 -14
package/README.md CHANGED
@@ -145,45 +145,137 @@ return data
145
145
 
146
146
  ## Extending FlowQuery with Custom Functions
147
147
 
148
- FlowQuery provides a plugin system that allows you to register custom functions using the `@FunctionDef` decorator. Import from the extensibility module for a clean API:
148
+ FlowQuery supports extending its functionality with custom functions using the `@FunctionDef` decorator. You can create scalar functions, aggregate functions, predicate functions, and async data providers.
149
+
150
+ ### Installing the Extensibility API
151
+
152
+ Import the necessary classes and decorators from the extensibility module:
153
+
154
+ ```typescript
155
+ import {
156
+ Function,
157
+ AggregateFunction,
158
+ PredicateFunction,
159
+ ReducerElement,
160
+ FunctionDef
161
+ } from 'flowquery/extensibility';
162
+ ```
163
+
164
+ ### Creating a Custom Scalar Function
165
+
166
+ Scalar functions operate on individual values and return a result:
167
+
168
+ ```typescript
169
+ import { Function, FunctionDef } from 'flowquery/extensibility';
170
+
171
+ @FunctionDef({
172
+ description: "Doubles a number",
173
+ category: "scalar",
174
+ parameters: [{ name: "value", description: "Number to double", type: "number" }],
175
+ output: { description: "Doubled value", type: "number" }
176
+ })
177
+ class Double extends Function {
178
+ constructor() {
179
+ super("double");
180
+ this._expectedParameterCount = 1;
181
+ }
182
+
183
+ public value(): number {
184
+ return this.getChildren()[0].value() * 2;
185
+ }
186
+ }
187
+ ```
188
+
189
+ Once defined, use it in your queries:
190
+
191
+ ```cypher
192
+ WITH 5 AS num RETURN double(num) AS result
193
+ // Returns: [{ result: 10 }]
194
+ ```
195
+
196
+ ### Creating a Custom String Function
149
197
 
150
198
  ```typescript
151
- import { Function, FunctionDef } from "flowquery/extensibility";
199
+ import { Function, FunctionDef } from 'flowquery/extensibility';
152
200
 
153
201
  @FunctionDef({
154
- description: "Converts a string to uppercase",
155
- category: "string",
156
- parameters: [
157
- { name: "text", description: "String to convert", type: "string" }
158
- ],
159
- output: {
160
- description: "Uppercase string",
161
- type: "string",
162
- example: "HELLO WORLD"
163
- },
164
- examples: ["WITH 'hello' AS s RETURN uppercase(s)"]
202
+ description: "Reverses a string",
203
+ category: "scalar",
204
+ parameters: [{ name: "text", description: "String to reverse", type: "string" }],
205
+ output: { description: "Reversed string", type: "string" }
165
206
  })
166
- class UpperCase extends Function {
207
+ class StrReverse extends Function {
167
208
  constructor() {
168
- super("uppercase"); // Function name used in queries
169
- this._expectedParameterCount = 1; // Number of required parameters
209
+ super("strreverse");
210
+ this._expectedParameterCount = 1;
170
211
  }
171
212
 
172
213
  public value(): string {
173
- const input = this.getChildren()[0].value();
174
- return String(input).toUpperCase();
214
+ const input = String(this.getChildren()[0].value());
215
+ return input.split('').reverse().join('');
216
+ }
217
+ }
218
+ ```
219
+
220
+ Usage:
221
+
222
+ ```cypher
223
+ WITH 'hello' AS s RETURN strreverse(s) AS reversed
224
+ // Returns: [{ reversed: 'olleh' }]
225
+ ```
226
+
227
+ ### Creating a Custom Aggregate Function
228
+
229
+ Aggregate functions process multiple values and return a single result. They require a `ReducerElement` to track state:
230
+
231
+ ```typescript
232
+ import { AggregateFunction, ReducerElement, FunctionDef } from 'flowquery/extensibility';
233
+
234
+ class ProductElement extends ReducerElement {
235
+ private _value: number = 1;
236
+ public get value(): number {
237
+ return this._value;
238
+ }
239
+ public set value(v: number) {
240
+ this._value *= v;
241
+ }
242
+ }
243
+
244
+ @FunctionDef({
245
+ description: "Calculates the product of values",
246
+ category: "aggregate",
247
+ parameters: [{ name: "value", description: "Number to multiply", type: "number" }],
248
+ output: { description: "Product of all values", type: "number" }
249
+ })
250
+ class Product extends AggregateFunction {
251
+ constructor() {
252
+ super("product");
253
+ this._expectedParameterCount = 1;
254
+ }
255
+
256
+ public reduce(element: ReducerElement): void {
257
+ element.value = this.firstChild().value();
258
+ }
259
+
260
+ public element(): ReducerElement {
261
+ return new ProductElement();
175
262
  }
176
263
  }
177
264
  ```
178
265
 
179
- The decorator automatically registers the function with the FlowQuery function factory.
266
+ Usage:
267
+
268
+ ```cypher
269
+ UNWIND [2, 3, 4] AS num RETURN product(num) AS result
270
+ // Returns: [{ result: 24 }]
271
+ ```
180
272
 
181
- ### Creating Async Data Providers
273
+ ### Creating a Custom Async Data Provider
182
274
 
183
- For functions that fetch data asynchronously (used with `LOAD JSON FROM`), use the `@FunctionDef` decorator with `category: "async"`. The class must have a `fetch` method that returns an async generator:
275
+ Async providers allow you to create custom data sources that can be used with `LOAD JSON FROM`:
184
276
 
185
277
  ```typescript
186
- import { FunctionDef } from "flowquery/extensibility";
278
+ import { FunctionDef, AsyncFunction } from 'flowquery/extensibility';
187
279
 
188
280
  @FunctionDef({
189
281
  description: "Provides example data for testing",
@@ -191,31 +283,43 @@ import { FunctionDef } from "flowquery/extensibility";
191
283
  parameters: [],
192
284
  output: { description: "Example data object", type: "object" }
193
285
  })
194
- class GetExampleDataLoader {
195
- async *fetch(): AsyncGenerator<any> {
286
+ class GetExampleData extends AsyncFunction {
287
+ async *generate(): AsyncGenerator<any> {
196
288
  yield { id: 1, name: "Alice" };
197
289
  yield { id: 2, name: "Bob" };
198
290
  }
199
291
  }
200
292
  ```
201
293
 
202
- The function name is derived from the class name by removing the `Loader` suffix (if present) and converting to camelCase. In this example, `GetExampleDataLoader` becomes `getExampleData`.
294
+ Usage:
295
+
296
+ ```cypher
297
+ LOAD JSON FROM getExampleData() AS data RETURN data.id AS id, data.name AS name
298
+ // Returns: [{ id: 1, name: "Alice" }, { id: 2, name: "Bob" }]
299
+ ```
300
+
301
+ ### Using Custom Functions with Expressions
203
302
 
204
- Use the async provider in a FlowQuery statement:
303
+ Custom functions integrate seamlessly with FlowQuery expressions and can be combined with other functions:
205
304
 
206
305
  ```cypher
207
- LOAD JSON FROM getExampleData() AS data
208
- RETURN data.id AS id, data.name AS name
209
- ```
210
-
211
- The extensibility module (`flowquery/extensibility`) exports:
212
- - `Function` - Base class for scalar functions
213
- - `AggregateFunction` - Base class for aggregate functions (like `sum`, `avg`, `collect`)
214
- - `AsyncFunction` - Base class for async function calls
215
- - `PredicateFunction` - Base class for predicate functions (like list comprehensions)
216
- - `ReducerElement` - Helper class for aggregate function state
217
- - `FunctionDef` - Decorator for registering functions with metadata
218
- - `FunctionMetadata`, `FunctionDefOptions`, `ParameterSchema`, `OutputSchema`, `FunctionCategory` - TypeScript types for metadata definitions
306
+ // Using custom function with expressions
307
+ WITH 5 * 3 AS num RETURN addhundred(num) + 1 AS result
308
+
309
+ // Using multiple custom functions together
310
+ WITH 2 AS num RETURN triple(num) AS tripled, square(num) AS squared
311
+ ```
312
+
313
+ ### Introspecting Registered Functions
314
+
315
+ You can use the built-in `functions()` function to discover registered functions including your custom ones:
316
+
317
+ ```cypher
318
+ WITH functions() AS funcs
319
+ UNWIND funcs AS f
320
+ WITH f WHERE f.name = 'double'
321
+ RETURN f.name AS name, f.description AS description, f.category AS category
322
+ ```
219
323
 
220
324
  ## Contributing
221
325