flowquery 1.0.3 → 1.0.6

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 (268) hide show
  1. package/README.md +182 -0
  2. package/dist/compute/runner.d.ts +81 -0
  3. package/dist/compute/runner.d.ts.map +1 -0
  4. package/dist/extensibility.d.ts +9 -0
  5. package/dist/extensibility.d.ts.map +1 -0
  6. package/dist/extensibility.js +25 -0
  7. package/dist/extensibility.js.map +1 -0
  8. package/dist/flowquery.min.js +1 -1
  9. package/dist/index.browser.d.ts +10 -0
  10. package/dist/index.browser.d.ts.map +1 -0
  11. package/dist/index.d.ts +9 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.node.d.ts +14 -0
  14. package/dist/index.node.d.ts.map +1 -0
  15. package/dist/io/command_line.d.ts +28 -0
  16. package/dist/io/command_line.d.ts.map +1 -0
  17. package/dist/parsing/alias.d.ts +10 -0
  18. package/dist/parsing/alias.d.ts.map +1 -0
  19. package/dist/parsing/alias_option.d.ts +6 -0
  20. package/dist/parsing/alias_option.d.ts.map +1 -0
  21. package/dist/parsing/ast_node.d.ts +100 -0
  22. package/dist/parsing/ast_node.d.ts.map +1 -0
  23. package/dist/parsing/base_parser.d.ts +49 -0
  24. package/dist/parsing/base_parser.d.ts.map +1 -0
  25. package/dist/parsing/components/csv.d.ts +6 -0
  26. package/dist/parsing/components/csv.d.ts.map +1 -0
  27. package/dist/parsing/components/from.d.ts +7 -0
  28. package/dist/parsing/components/from.d.ts.map +1 -0
  29. package/dist/parsing/components/headers.d.ts +7 -0
  30. package/dist/parsing/components/headers.d.ts.map +1 -0
  31. package/dist/parsing/components/json.d.ts +6 -0
  32. package/dist/parsing/components/json.d.ts.map +1 -0
  33. package/dist/parsing/components/null.d.ts +6 -0
  34. package/dist/parsing/components/null.d.ts.map +1 -0
  35. package/dist/parsing/components/post.d.ts +6 -0
  36. package/dist/parsing/components/post.d.ts.map +1 -0
  37. package/dist/parsing/components/text.d.ts +6 -0
  38. package/dist/parsing/components/text.d.ts.map +1 -0
  39. package/dist/parsing/context.d.ts +38 -0
  40. package/dist/parsing/context.d.ts.map +1 -0
  41. package/dist/parsing/data_structures/associative_array.d.ts +28 -0
  42. package/dist/parsing/data_structures/associative_array.d.ts.map +1 -0
  43. package/dist/parsing/data_structures/json_array.d.ts +26 -0
  44. package/dist/parsing/data_structures/json_array.d.ts.map +1 -0
  45. package/dist/parsing/data_structures/key_value_pair.d.ts +25 -0
  46. package/dist/parsing/data_structures/key_value_pair.d.ts.map +1 -0
  47. package/dist/parsing/data_structures/lookup.d.ts +25 -0
  48. package/dist/parsing/data_structures/lookup.d.ts.map +1 -0
  49. package/dist/parsing/data_structures/range_lookup.d.ts +14 -0
  50. package/dist/parsing/data_structures/range_lookup.d.ts.map +1 -0
  51. package/dist/parsing/expressions/expression.d.ts +53 -0
  52. package/dist/parsing/expressions/expression.d.ts.map +1 -0
  53. package/dist/parsing/expressions/f_string.d.ts +21 -0
  54. package/dist/parsing/expressions/f_string.d.ts.map +1 -0
  55. package/dist/parsing/expressions/identifier.d.ts +17 -0
  56. package/dist/parsing/expressions/identifier.d.ts.map +1 -0
  57. package/dist/parsing/expressions/number.d.ts +25 -0
  58. package/dist/parsing/expressions/number.d.ts.map +1 -0
  59. package/dist/parsing/expressions/operator.d.ts +79 -0
  60. package/dist/parsing/expressions/operator.d.ts.map +1 -0
  61. package/dist/parsing/expressions/reference.d.ts +29 -0
  62. package/dist/parsing/expressions/reference.d.ts.map +1 -0
  63. package/dist/parsing/expressions/string.d.ts +23 -0
  64. package/dist/parsing/expressions/string.d.ts.map +1 -0
  65. package/dist/parsing/functions/aggregate_function.d.ts +42 -0
  66. package/dist/parsing/functions/aggregate_function.d.ts.map +1 -0
  67. package/dist/parsing/functions/async_function.d.ts +52 -0
  68. package/dist/parsing/functions/async_function.d.ts.map +1 -0
  69. package/dist/parsing/functions/avg.d.ts +15 -0
  70. package/dist/parsing/functions/avg.d.ts.map +1 -0
  71. package/dist/parsing/functions/avg.js +20 -2
  72. package/dist/parsing/functions/avg.js.map +1 -1
  73. package/dist/parsing/functions/collect.d.ts +21 -0
  74. package/dist/parsing/functions/collect.d.ts.map +1 -0
  75. package/dist/parsing/functions/collect.js +20 -2
  76. package/dist/parsing/functions/collect.js.map +1 -1
  77. package/dist/parsing/functions/extensibility/index.d.ts +37 -0
  78. package/dist/parsing/functions/extensibility/index.d.ts.map +1 -0
  79. package/dist/parsing/functions/extensibility/index.js +50 -0
  80. package/dist/parsing/functions/extensibility/index.js.map +1 -0
  81. package/dist/parsing/functions/function.d.ts +36 -0
  82. package/dist/parsing/functions/function.d.ts.map +1 -0
  83. package/dist/parsing/functions/function_factory.d.ts +174 -0
  84. package/dist/parsing/functions/function_factory.d.ts.map +1 -0
  85. package/dist/parsing/functions/function_factory.js +44 -47
  86. package/dist/parsing/functions/function_factory.js.map +1 -1
  87. package/dist/parsing/functions/function_metadata.d.ts +134 -0
  88. package/dist/parsing/functions/function_metadata.d.ts.map +1 -0
  89. package/dist/parsing/functions/function_metadata.js +103 -153
  90. package/dist/parsing/functions/function_metadata.js.map +1 -1
  91. package/dist/parsing/functions/functions.d.ts +21 -0
  92. package/dist/parsing/functions/functions.d.ts.map +1 -0
  93. package/dist/parsing/functions/functions.js +37 -2
  94. package/dist/parsing/functions/functions.js.map +1 -1
  95. package/dist/parsing/functions/join.d.ts +9 -0
  96. package/dist/parsing/functions/join.d.ts.map +1 -0
  97. package/dist/parsing/functions/join.js +21 -2
  98. package/dist/parsing/functions/join.js.map +1 -1
  99. package/dist/parsing/functions/predicate_function.d.ts +19 -0
  100. package/dist/parsing/functions/predicate_function.d.ts.map +1 -0
  101. package/dist/parsing/functions/predicate_function.js +3 -0
  102. package/dist/parsing/functions/predicate_function.js.map +1 -1
  103. package/dist/parsing/functions/predicate_sum.d.ts +7 -0
  104. package/dist/parsing/functions/predicate_sum.d.ts.map +1 -0
  105. package/dist/parsing/functions/predicate_sum.js +23 -2
  106. package/dist/parsing/functions/predicate_sum.js.map +1 -1
  107. package/dist/parsing/functions/rand.d.ts +7 -0
  108. package/dist/parsing/functions/rand.d.ts.map +1 -0
  109. package/dist/parsing/functions/rand.js +18 -2
  110. package/dist/parsing/functions/rand.js.map +1 -1
  111. package/dist/parsing/functions/range.d.ts +7 -0
  112. package/dist/parsing/functions/range.d.ts.map +1 -0
  113. package/dist/parsing/functions/range.js +21 -2
  114. package/dist/parsing/functions/range.js.map +1 -1
  115. package/dist/parsing/functions/reducer_element.d.ts +6 -0
  116. package/dist/parsing/functions/reducer_element.d.ts.map +1 -0
  117. package/dist/parsing/functions/replace.d.ts +7 -0
  118. package/dist/parsing/functions/replace.d.ts.map +1 -0
  119. package/dist/parsing/functions/replace.js +22 -2
  120. package/dist/parsing/functions/replace.js.map +1 -1
  121. package/dist/parsing/functions/round.d.ts +7 -0
  122. package/dist/parsing/functions/round.d.ts.map +1 -0
  123. package/dist/parsing/functions/round.js +20 -2
  124. package/dist/parsing/functions/round.js.map +1 -1
  125. package/dist/parsing/functions/size.d.ts +7 -0
  126. package/dist/parsing/functions/size.d.ts.map +1 -0
  127. package/dist/parsing/functions/size.js +20 -2
  128. package/dist/parsing/functions/size.js.map +1 -1
  129. package/dist/parsing/functions/split.d.ts +9 -0
  130. package/dist/parsing/functions/split.d.ts.map +1 -0
  131. package/dist/parsing/functions/split.js +21 -2
  132. package/dist/parsing/functions/split.js.map +1 -1
  133. package/dist/parsing/functions/stringify.d.ts +9 -0
  134. package/dist/parsing/functions/stringify.d.ts.map +1 -0
  135. package/dist/parsing/functions/stringify.js +20 -2
  136. package/dist/parsing/functions/stringify.js.map +1 -1
  137. package/dist/parsing/functions/sum.d.ts +14 -0
  138. package/dist/parsing/functions/sum.d.ts.map +1 -0
  139. package/dist/parsing/functions/sum.js +20 -2
  140. package/dist/parsing/functions/sum.js.map +1 -1
  141. package/dist/parsing/functions/to_json.d.ts +7 -0
  142. package/dist/parsing/functions/to_json.d.ts.map +1 -0
  143. package/dist/parsing/functions/to_json.js +20 -2
  144. package/dist/parsing/functions/to_json.js.map +1 -1
  145. package/dist/parsing/functions/value_holder.d.ts +8 -0
  146. package/dist/parsing/functions/value_holder.d.ts.map +1 -0
  147. package/dist/parsing/logic/case.d.ts +7 -0
  148. package/dist/parsing/logic/case.d.ts.map +1 -0
  149. package/dist/parsing/logic/else.d.ts +7 -0
  150. package/dist/parsing/logic/else.d.ts.map +1 -0
  151. package/dist/parsing/logic/end.d.ts +6 -0
  152. package/dist/parsing/logic/end.d.ts.map +1 -0
  153. package/dist/parsing/logic/then.d.ts +7 -0
  154. package/dist/parsing/logic/then.d.ts.map +1 -0
  155. package/dist/parsing/logic/when.d.ts +7 -0
  156. package/dist/parsing/logic/when.d.ts.map +1 -0
  157. package/dist/parsing/operations/aggregated_return.d.ts +8 -0
  158. package/dist/parsing/operations/aggregated_return.d.ts.map +1 -0
  159. package/dist/parsing/operations/aggregated_with.d.ts +8 -0
  160. package/dist/parsing/operations/aggregated_with.d.ts.map +1 -0
  161. package/dist/parsing/operations/group_by.d.ts +35 -0
  162. package/dist/parsing/operations/group_by.d.ts.map +1 -0
  163. package/dist/parsing/operations/limit.d.ts +10 -0
  164. package/dist/parsing/operations/limit.d.ts.map +1 -0
  165. package/dist/parsing/operations/load.d.ts +48 -0
  166. package/dist/parsing/operations/load.d.ts.map +1 -0
  167. package/dist/parsing/operations/operation.d.ts +39 -0
  168. package/dist/parsing/operations/operation.d.ts.map +1 -0
  169. package/dist/parsing/operations/projection.d.ts +8 -0
  170. package/dist/parsing/operations/projection.d.ts.map +1 -0
  171. package/dist/parsing/operations/return.d.ts +23 -0
  172. package/dist/parsing/operations/return.d.ts.map +1 -0
  173. package/dist/parsing/operations/unwind.d.ts +12 -0
  174. package/dist/parsing/operations/unwind.d.ts.map +1 -0
  175. package/dist/parsing/operations/where.d.ts +26 -0
  176. package/dist/parsing/operations/where.d.ts.map +1 -0
  177. package/dist/parsing/operations/with.d.ts +17 -0
  178. package/dist/parsing/operations/with.d.ts.map +1 -0
  179. package/dist/parsing/parser.d.ts +66 -0
  180. package/dist/parsing/parser.d.ts.map +1 -0
  181. package/dist/parsing/parser.js +2 -3
  182. package/dist/parsing/parser.js.map +1 -1
  183. package/dist/parsing/token_to_node.d.ts +7 -0
  184. package/dist/parsing/token_to_node.d.ts.map +1 -0
  185. package/dist/tokenization/keyword.d.ts +43 -0
  186. package/dist/tokenization/keyword.d.ts.map +1 -0
  187. package/dist/tokenization/operator.d.ts +22 -0
  188. package/dist/tokenization/operator.d.ts.map +1 -0
  189. package/dist/tokenization/string_walker.d.ts +55 -0
  190. package/dist/tokenization/string_walker.d.ts.map +1 -0
  191. package/dist/tokenization/symbol.d.ts +15 -0
  192. package/dist/tokenization/symbol.d.ts.map +1 -0
  193. package/dist/tokenization/token.d.ts +176 -0
  194. package/dist/tokenization/token.d.ts.map +1 -0
  195. package/dist/tokenization/token_mapper.d.ts +40 -0
  196. package/dist/tokenization/token_mapper.d.ts.map +1 -0
  197. package/dist/tokenization/token_type.d.ts +16 -0
  198. package/dist/tokenization/token_type.d.ts.map +1 -0
  199. package/dist/tokenization/tokenizer.d.ts +45 -0
  200. package/dist/tokenization/tokenizer.d.ts.map +1 -0
  201. package/dist/tokenization/trie.d.ts +41 -0
  202. package/dist/tokenization/trie.d.ts.map +1 -0
  203. package/dist/utils/object_utils.d.ts +15 -0
  204. package/dist/utils/object_utils.d.ts.map +1 -0
  205. package/dist/utils/string_utils.d.ts +51 -0
  206. package/dist/utils/string_utils.d.ts.map +1 -0
  207. package/docs/flowquery.min.js +1 -1
  208. package/flowquery-vscode/flowQueryEngine/flowquery.min.js +1 -1
  209. package/misc/apps/RAG/.env.example +14 -0
  210. package/misc/apps/RAG/README.md +0 -7
  211. package/misc/apps/RAG/package.json +16 -7
  212. package/misc/apps/RAG/public/index.html +18 -0
  213. package/misc/apps/RAG/src/App.css +42 -0
  214. package/misc/apps/RAG/src/App.tsx +50 -0
  215. package/misc/apps/RAG/src/components/ApiKeySettings.tsx +245 -0
  216. package/misc/apps/RAG/src/components/ChatContainer.css +67 -0
  217. package/misc/apps/RAG/src/components/ChatContainer.tsx +239 -0
  218. package/misc/apps/RAG/src/components/ChatInput.css +23 -0
  219. package/misc/apps/RAG/src/components/ChatInput.tsx +62 -0
  220. package/misc/apps/RAG/src/components/ChatMessage.css +136 -0
  221. package/misc/apps/RAG/src/components/ChatMessage.tsx +152 -0
  222. package/misc/apps/RAG/src/components/FlowQueryAgent.ts +390 -0
  223. package/misc/apps/RAG/src/components/FlowQueryRunner.css +104 -0
  224. package/misc/apps/RAG/src/components/FlowQueryRunner.tsx +332 -0
  225. package/misc/apps/RAG/src/components/index.ts +15 -0
  226. package/misc/apps/RAG/src/index.tsx +17 -0
  227. package/misc/apps/RAG/src/plugins/PluginRegistry.ts +136 -0
  228. package/misc/apps/RAG/src/plugins/README.md +139 -0
  229. package/misc/apps/RAG/src/plugins/index.ts +72 -0
  230. package/misc/apps/RAG/src/plugins/loaders/CatFacts.ts +79 -0
  231. package/misc/apps/RAG/src/plugins/loaders/FetchJson.ts +71 -0
  232. package/misc/apps/RAG/src/plugins/loaders/Llm.ts +441 -0
  233. package/misc/apps/RAG/src/plugins/loaders/MockData.ts +161 -0
  234. package/misc/apps/RAG/src/plugins/types.ts +52 -0
  235. package/misc/apps/RAG/src/prompts/FlowQuerySystemPrompt.ts +385 -0
  236. package/misc/apps/RAG/src/prompts/index.ts +10 -0
  237. package/misc/apps/RAG/src/utils/FlowQueryExecutor.ts +131 -0
  238. package/misc/apps/RAG/src/utils/FlowQueryExtractor.ts +203 -0
  239. package/misc/apps/RAG/src/utils/index.ts +9 -0
  240. package/misc/apps/RAG/tsconfig.json +4 -2
  241. package/misc/apps/RAG/webpack.config.js +23 -12
  242. package/package.json +7 -1
  243. package/src/extensibility.ts +9 -0
  244. package/src/parsing/functions/avg.ts +10 -0
  245. package/src/parsing/functions/collect.ts +10 -0
  246. package/src/parsing/functions/extensibility/index.ts +54 -0
  247. package/src/parsing/functions/function_factory.ts +51 -48
  248. package/src/parsing/functions/function_metadata.ts +132 -156
  249. package/src/parsing/functions/functions.ts +27 -0
  250. package/src/parsing/functions/join.ts +11 -0
  251. package/src/parsing/functions/predicate_function.ts +4 -0
  252. package/src/parsing/functions/predicate_sum.ts +13 -0
  253. package/src/parsing/functions/rand.ts +8 -0
  254. package/src/parsing/functions/range.ts +11 -0
  255. package/src/parsing/functions/replace.ts +12 -0
  256. package/src/parsing/functions/round.ts +10 -0
  257. package/src/parsing/functions/size.ts +10 -0
  258. package/src/parsing/functions/split.ts +11 -0
  259. package/src/parsing/functions/stringify.ts +10 -0
  260. package/src/parsing/functions/sum.ts +10 -0
  261. package/src/parsing/functions/to_json.ts +10 -0
  262. package/src/parsing/parser.ts +2 -3
  263. package/tests/parsing/function_plugins.test.ts +11 -11
  264. package/tsconfig.json +4 -1
  265. package/dist/parsing/functions/predicate_function_factory.js +0 -19
  266. package/dist/parsing/functions/predicate_function_factory.js.map +0 -1
  267. package/misc/apps/RAG/src/index.ts +0 -20
  268. package/src/parsing/functions/predicate_function_factory.ts +0 -15
@@ -0,0 +1,139 @@
1
+ # FlowQuery Plugin System
2
+
3
+ This folder contains the plugin system for adding async data loader functions to FlowQuery.
4
+
5
+ ## Quick Start
6
+
7
+ 1. Create a new file in `loaders/` (e.g., `my-api.ts`)
8
+ 2. Define your plugin following the `AsyncLoaderPlugin` interface
9
+ 3. Import and add it to the `allPlugins` array in `index.ts`
10
+
11
+ ## Creating a Plugin
12
+
13
+ ### Basic Plugin Structure
14
+
15
+ ```typescript
16
+ import { AsyncLoaderPlugin } from '../types';
17
+
18
+ // Your async data provider function
19
+ async function* myDataProvider(arg1: string, arg2?: number): AsyncGenerator<any, void, unknown> {
20
+ const response = await fetch(`https://api.example.com/${arg1}`);
21
+ const data = await response.json();
22
+
23
+ // Yield items one at a time (for arrays)
24
+ if (Array.isArray(data)) {
25
+ for (const item of data) {
26
+ yield item;
27
+ }
28
+ } else {
29
+ yield data;
30
+ }
31
+ }
32
+
33
+ // Export the plugin definition
34
+ export const myPlugin: AsyncLoaderPlugin = {
35
+ name: 'myData', // Function name in FlowQuery
36
+ provider: myDataProvider,
37
+ metadata: {
38
+ description: 'Fetches data from My API',
39
+ category: 'data',
40
+ parameters: [
41
+ { name: 'arg1', description: 'First argument', type: 'string', required: true },
42
+ { name: 'arg2', description: 'Optional second arg', type: 'number', required: false }
43
+ ],
44
+ output: {
45
+ description: 'Data item',
46
+ type: 'object',
47
+ properties: {
48
+ id: { description: 'Item ID', type: 'number' },
49
+ value: { description: 'Item value', type: 'string' }
50
+ }
51
+ },
52
+ examples: [
53
+ "LOAD JSON FROM myData('users') AS item RETURN item.id, item.value"
54
+ ]
55
+ }
56
+ };
57
+
58
+ export default myPlugin;
59
+ ```
60
+
61
+ ### Register the Plugin
62
+
63
+ Add your plugin to `index.ts`:
64
+
65
+ ```typescript
66
+ import myPlugin from './loaders/my-api';
67
+
68
+ const allPlugins: AsyncLoaderPlugin[] = [
69
+ // ... existing plugins
70
+ myPlugin,
71
+ ];
72
+ ```
73
+
74
+ ## Using Plugins in FlowQuery
75
+
76
+ Once registered, use your plugin in FlowQuery queries:
77
+
78
+ ```sql
79
+ -- Fetch data from your custom source
80
+ LOAD JSON FROM myData('users') AS user
81
+ WHERE user.active = true
82
+ RETURN user.name, user.email
83
+
84
+ -- Combine with filtering and ordering
85
+ LOAD JSON FROM myData('products', 50) AS product
86
+ WHERE product.price > 10
87
+ ORDER BY product.name ASC
88
+ RETURN product.name, product.price
89
+ ```
90
+
91
+ ## Available Built-in Plugins
92
+
93
+ | Plugin | Description | Example |
94
+ |--------|-------------|---------|
95
+ | `fetchJson` | Fetch JSON from any URL | `fetchJson('https://api.example.com/data')` |
96
+
97
+ > **Note**: Additional plugins may be registered. Check `index.ts` for the current list of available plugins.
98
+
99
+ ## Plugin Types
100
+
101
+ ### AsyncLoaderPlugin
102
+
103
+ ```typescript
104
+ interface AsyncLoaderPlugin {
105
+ name: string; // Function name (lowercased when registered)
106
+ provider: AsyncDataProvider; // The async generator/function
107
+ metadata?: PluginMetadata; // Optional metadata for LLM consumption
108
+ }
109
+ ```
110
+
111
+ ### AsyncDataProvider
112
+
113
+ ```typescript
114
+ type AsyncDataProvider = (...args: any[]) => AsyncGenerator<any, void, unknown> | Promise<any>;
115
+ ```
116
+
117
+ Plugins can return either:
118
+ - An `AsyncGenerator` that yields items one at a time
119
+ - A `Promise` that resolves to an array or single value
120
+
121
+ ### PluginMetadata
122
+
123
+ ```typescript
124
+ interface PluginMetadata {
125
+ name: string;
126
+ description: string;
127
+ category?: string;
128
+ parameters?: ParameterSchema[];
129
+ output?: OutputSchema;
130
+ examples?: string[];
131
+ }
132
+ ```
133
+
134
+ ## Tips
135
+
136
+ 1. **Use generators for large datasets** - Yield items one at a time to avoid memory issues
137
+ 2. **Add comprehensive metadata** - This helps LLMs understand and use your functions
138
+ 3. **Handle errors gracefully** - Throw descriptive errors for API failures
139
+ 4. **Include examples** - Show users how to use your plugin in FlowQuery
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Plugin loader - automatically discovers and loads all plugins.
3
+ *
4
+ * To add a new plugin:
5
+ * 1. Create a new file in the `loaders/` directory
6
+ * 2. Export your plugin(s) following the AsyncLoaderPlugin interface
7
+ * 3. Import and add to the plugins array in this file
8
+ */
9
+
10
+ import pluginRegistry from './PluginRegistry';
11
+ import { AsyncLoaderPlugin, PluginMetadata } from './types';
12
+
13
+ // Import individual plugins
14
+ import fetchJsonPlugin from './loaders/FetchJson';
15
+ import catFactsPlugin from './loaders/CatFacts';
16
+ import mockDataPlugins from './loaders/MockData';
17
+ import llmPlugin from './loaders/Llm';
18
+
19
+ /**
20
+ * All plugins to be loaded on startup.
21
+ * Add new plugins here as they are created.
22
+ */
23
+ const allPlugins: AsyncLoaderPlugin[] = [
24
+ fetchJsonPlugin,
25
+ catFactsPlugin,
26
+ ...mockDataPlugins,
27
+ llmPlugin,
28
+ ];
29
+
30
+ /**
31
+ * Initialize and load all plugins.
32
+ * Call this function once on app startup.
33
+ */
34
+ export function initializePlugins(): void {
35
+ console.log('Initializing FlowQuery plugins...');
36
+ pluginRegistry.registerAll(allPlugins);
37
+ console.log(`Loaded ${pluginRegistry.getLoadedPlugins().length} plugins`);
38
+ }
39
+
40
+ /**
41
+ * Get the list of loaded plugin names.
42
+ * Uses FlowQuery's introspection to discover registered async providers.
43
+ */
44
+ export function getLoadedPluginNames(): string[] {
45
+ return pluginRegistry.getLoadedPlugins();
46
+ }
47
+
48
+ /**
49
+ * Get metadata for all loaded plugins.
50
+ * Uses FlowQuery's functions() introspection as the single source of truth.
51
+ */
52
+ export function getAllPluginMetadata(): PluginMetadata[] {
53
+ return pluginRegistry.getAllPluginMetadata();
54
+ }
55
+
56
+ /**
57
+ * Get all available async loader plugins by querying FlowQuery directly.
58
+ * This is the preferred async method that uses functions() introspection.
59
+ *
60
+ * @returns Promise resolving to array of plugin metadata
61
+ */
62
+ export async function getAvailableLoaders(): Promise<PluginMetadata[]> {
63
+ return pluginRegistry.getAvailableLoadersAsync();
64
+ }
65
+
66
+ // Re-export types and registry for external use
67
+ export { pluginRegistry } from './PluginRegistry';
68
+ export type { AsyncLoaderPlugin, PluginModule, PluginMetadata, AsyncDataProvider, ParameterSchema, OutputSchema, FunctionMetadata } from './types';
69
+
70
+ // Re-export standalone loader functions for use outside of FlowQuery
71
+ export { llm, llmStream, extractContent } from './loaders/Llm';
72
+ export type { LlmOptions, LlmResponse } from './loaders/Llm';
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Example plugin: Fetch random cat facts from the Cat Facts API.
3
+ *
4
+ * Usage in FlowQuery:
5
+ * LOAD JSON FROM catFacts(5) AS fact
6
+ * RETURN fact.text
7
+ */
8
+
9
+ import { AsyncLoaderPlugin } from '../types';
10
+
11
+ const CAT_FACTS_API = 'https://catfact.ninja/facts';
12
+
13
+ /**
14
+ * CatFacts loader class - fetches random cat facts from the Cat Facts API.
15
+ */
16
+ export class CatFactsLoader {
17
+ private readonly apiUrl: string;
18
+
19
+ constructor(apiUrl: string = CAT_FACTS_API) {
20
+ this.apiUrl = apiUrl;
21
+ }
22
+
23
+ /**
24
+ * Fetches random cat facts from the Cat Facts API.
25
+ *
26
+ * @param count - Number of cat facts to fetch (default: 1)
27
+ */
28
+ async *fetch(count: number = 1): AsyncGenerator<any, void, unknown> {
29
+ const url = `${this.apiUrl}?limit=${count}`;
30
+ const response = await fetch(url);
31
+
32
+ if (!response.ok) {
33
+ throw new Error(`Failed to fetch cat facts: ${response.statusText}`);
34
+ }
35
+
36
+ const json = await response.json();
37
+ const data = json.data || [];
38
+
39
+ for (const item of data) {
40
+ // Map 'fact' to 'text' for backwards compatibility with existing queries
41
+ yield {
42
+ text: item.fact,
43
+ length: item.length
44
+ };
45
+ }
46
+ }
47
+ }
48
+
49
+ export const catFactsPlugin: AsyncLoaderPlugin = {
50
+ name: 'catFacts',
51
+ provider: (count: number = 1) => new CatFactsLoader().fetch(count),
52
+ metadata: {
53
+ description: 'Fetches random cat facts from the Cat Facts API (catfact.ninja)',
54
+ category: 'examples',
55
+ parameters: [
56
+ {
57
+ name: 'count',
58
+ description: 'Number of cat facts to fetch',
59
+ type: 'number',
60
+ required: false,
61
+ default: 1
62
+ }
63
+ ],
64
+ output: {
65
+ description: 'Cat fact object',
66
+ type: 'object',
67
+ properties: {
68
+ text: { description: 'The cat fact text', type: 'string' },
69
+ length: { description: 'Length of the fact text', type: 'number' }
70
+ }
71
+ },
72
+ examples: [
73
+ "LOAD JSON FROM catFacts() AS fact RETURN fact.text",
74
+ "LOAD JSON FROM catFacts(5) AS fact RETURN fact.text, fact.length AS length"
75
+ ]
76
+ }
77
+ };
78
+
79
+ export default catFactsPlugin;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Example plugin: Fetch JSON data from a URL.
3
+ *
4
+ * Usage in FlowQuery:
5
+ * LOAD JSON FROM fetchJson('https://api.example.com/data') AS item
6
+ * RETURN item.name, item.value
7
+ */
8
+
9
+ import { AsyncLoaderPlugin } from '../types';
10
+
11
+ /**
12
+ * FetchJson loader class - fetches JSON data from a URL and yields items.
13
+ */
14
+ export class FetchJsonLoader {
15
+ /**
16
+ * Fetches JSON data from a URL and yields each item if array, or the object itself.
17
+ *
18
+ * @param url - The URL to fetch JSON from
19
+ * @param options - Optional fetch options
20
+ */
21
+ async *fetch(url: string, options?: RequestInit): AsyncGenerator<any, void, unknown> {
22
+ const response = await fetch(url, options);
23
+
24
+ if (!response.ok) {
25
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
26
+ }
27
+
28
+ const data = await response.json();
29
+
30
+ if (Array.isArray(data)) {
31
+ for (const item of data) {
32
+ yield item;
33
+ }
34
+ } else {
35
+ yield data;
36
+ }
37
+ }
38
+ }
39
+
40
+ export const fetchJsonPlugin: AsyncLoaderPlugin = {
41
+ name: 'fetchJson',
42
+ provider: (url: string, options?: RequestInit) => new FetchJsonLoader().fetch(url, options),
43
+ metadata: {
44
+ description: 'Fetches JSON data from a URL. If the response is an array, yields each item individually.',
45
+ category: 'data',
46
+ parameters: [
47
+ {
48
+ name: 'url',
49
+ description: 'The URL to fetch JSON from',
50
+ type: 'string',
51
+ required: true
52
+ },
53
+ {
54
+ name: 'options',
55
+ description: 'Optional fetch options (headers, method, etc.)',
56
+ type: 'object',
57
+ required: false
58
+ }
59
+ ],
60
+ output: {
61
+ description: 'JSON data items',
62
+ type: 'object'
63
+ },
64
+ examples: [
65
+ "LOAD JSON FROM fetchJson('https://api.example.com/users') AS user RETURN user.name",
66
+ "LOAD JSON FROM fetchJson('https://api.example.com/data') AS item RETURN item WHERE item.active = true"
67
+ ]
68
+ }
69
+ };
70
+
71
+ export default fetchJsonPlugin;