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.
- package/README.md +182 -0
- package/dist/compute/runner.d.ts +81 -0
- package/dist/compute/runner.d.ts.map +1 -0
- package/dist/extensibility.d.ts +9 -0
- package/dist/extensibility.d.ts.map +1 -0
- package/dist/extensibility.js +25 -0
- package/dist/extensibility.js.map +1 -0
- package/dist/flowquery.min.js +1 -1
- package/dist/index.browser.d.ts +10 -0
- package/dist/index.browser.d.ts.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.node.d.ts +14 -0
- package/dist/index.node.d.ts.map +1 -0
- package/dist/io/command_line.d.ts +28 -0
- package/dist/io/command_line.d.ts.map +1 -0
- package/dist/parsing/alias.d.ts +10 -0
- package/dist/parsing/alias.d.ts.map +1 -0
- package/dist/parsing/alias_option.d.ts +6 -0
- package/dist/parsing/alias_option.d.ts.map +1 -0
- package/dist/parsing/ast_node.d.ts +100 -0
- package/dist/parsing/ast_node.d.ts.map +1 -0
- package/dist/parsing/base_parser.d.ts +49 -0
- package/dist/parsing/base_parser.d.ts.map +1 -0
- package/dist/parsing/components/csv.d.ts +6 -0
- package/dist/parsing/components/csv.d.ts.map +1 -0
- package/dist/parsing/components/from.d.ts +7 -0
- package/dist/parsing/components/from.d.ts.map +1 -0
- package/dist/parsing/components/headers.d.ts +7 -0
- package/dist/parsing/components/headers.d.ts.map +1 -0
- package/dist/parsing/components/json.d.ts +6 -0
- package/dist/parsing/components/json.d.ts.map +1 -0
- package/dist/parsing/components/null.d.ts +6 -0
- package/dist/parsing/components/null.d.ts.map +1 -0
- package/dist/parsing/components/post.d.ts +6 -0
- package/dist/parsing/components/post.d.ts.map +1 -0
- package/dist/parsing/components/text.d.ts +6 -0
- package/dist/parsing/components/text.d.ts.map +1 -0
- package/dist/parsing/context.d.ts +38 -0
- package/dist/parsing/context.d.ts.map +1 -0
- package/dist/parsing/data_structures/associative_array.d.ts +28 -0
- package/dist/parsing/data_structures/associative_array.d.ts.map +1 -0
- package/dist/parsing/data_structures/json_array.d.ts +26 -0
- package/dist/parsing/data_structures/json_array.d.ts.map +1 -0
- package/dist/parsing/data_structures/key_value_pair.d.ts +25 -0
- package/dist/parsing/data_structures/key_value_pair.d.ts.map +1 -0
- package/dist/parsing/data_structures/lookup.d.ts +25 -0
- package/dist/parsing/data_structures/lookup.d.ts.map +1 -0
- package/dist/parsing/data_structures/range_lookup.d.ts +14 -0
- package/dist/parsing/data_structures/range_lookup.d.ts.map +1 -0
- package/dist/parsing/expressions/expression.d.ts +53 -0
- package/dist/parsing/expressions/expression.d.ts.map +1 -0
- package/dist/parsing/expressions/f_string.d.ts +21 -0
- package/dist/parsing/expressions/f_string.d.ts.map +1 -0
- package/dist/parsing/expressions/identifier.d.ts +17 -0
- package/dist/parsing/expressions/identifier.d.ts.map +1 -0
- package/dist/parsing/expressions/number.d.ts +25 -0
- package/dist/parsing/expressions/number.d.ts.map +1 -0
- package/dist/parsing/expressions/operator.d.ts +79 -0
- package/dist/parsing/expressions/operator.d.ts.map +1 -0
- package/dist/parsing/expressions/reference.d.ts +29 -0
- package/dist/parsing/expressions/reference.d.ts.map +1 -0
- package/dist/parsing/expressions/string.d.ts +23 -0
- package/dist/parsing/expressions/string.d.ts.map +1 -0
- package/dist/parsing/functions/aggregate_function.d.ts +42 -0
- package/dist/parsing/functions/aggregate_function.d.ts.map +1 -0
- package/dist/parsing/functions/async_function.d.ts +52 -0
- package/dist/parsing/functions/async_function.d.ts.map +1 -0
- package/dist/parsing/functions/avg.d.ts +15 -0
- package/dist/parsing/functions/avg.d.ts.map +1 -0
- package/dist/parsing/functions/avg.js +20 -2
- package/dist/parsing/functions/avg.js.map +1 -1
- package/dist/parsing/functions/collect.d.ts +21 -0
- package/dist/parsing/functions/collect.d.ts.map +1 -0
- package/dist/parsing/functions/collect.js +20 -2
- package/dist/parsing/functions/collect.js.map +1 -1
- package/dist/parsing/functions/extensibility/index.d.ts +37 -0
- package/dist/parsing/functions/extensibility/index.d.ts.map +1 -0
- package/dist/parsing/functions/extensibility/index.js +50 -0
- package/dist/parsing/functions/extensibility/index.js.map +1 -0
- package/dist/parsing/functions/function.d.ts +36 -0
- package/dist/parsing/functions/function.d.ts.map +1 -0
- package/dist/parsing/functions/function_factory.d.ts +174 -0
- package/dist/parsing/functions/function_factory.d.ts.map +1 -0
- package/dist/parsing/functions/function_factory.js +44 -47
- package/dist/parsing/functions/function_factory.js.map +1 -1
- package/dist/parsing/functions/function_metadata.d.ts +134 -0
- package/dist/parsing/functions/function_metadata.d.ts.map +1 -0
- package/dist/parsing/functions/function_metadata.js +103 -153
- package/dist/parsing/functions/function_metadata.js.map +1 -1
- package/dist/parsing/functions/functions.d.ts +21 -0
- package/dist/parsing/functions/functions.d.ts.map +1 -0
- package/dist/parsing/functions/functions.js +37 -2
- package/dist/parsing/functions/functions.js.map +1 -1
- package/dist/parsing/functions/join.d.ts +9 -0
- package/dist/parsing/functions/join.d.ts.map +1 -0
- package/dist/parsing/functions/join.js +21 -2
- package/dist/parsing/functions/join.js.map +1 -1
- package/dist/parsing/functions/predicate_function.d.ts +19 -0
- package/dist/parsing/functions/predicate_function.d.ts.map +1 -0
- package/dist/parsing/functions/predicate_function.js +3 -0
- package/dist/parsing/functions/predicate_function.js.map +1 -1
- package/dist/parsing/functions/predicate_sum.d.ts +7 -0
- package/dist/parsing/functions/predicate_sum.d.ts.map +1 -0
- package/dist/parsing/functions/predicate_sum.js +23 -2
- package/dist/parsing/functions/predicate_sum.js.map +1 -1
- package/dist/parsing/functions/rand.d.ts +7 -0
- package/dist/parsing/functions/rand.d.ts.map +1 -0
- package/dist/parsing/functions/rand.js +18 -2
- package/dist/parsing/functions/rand.js.map +1 -1
- package/dist/parsing/functions/range.d.ts +7 -0
- package/dist/parsing/functions/range.d.ts.map +1 -0
- package/dist/parsing/functions/range.js +21 -2
- package/dist/parsing/functions/range.js.map +1 -1
- package/dist/parsing/functions/reducer_element.d.ts +6 -0
- package/dist/parsing/functions/reducer_element.d.ts.map +1 -0
- package/dist/parsing/functions/replace.d.ts +7 -0
- package/dist/parsing/functions/replace.d.ts.map +1 -0
- package/dist/parsing/functions/replace.js +22 -2
- package/dist/parsing/functions/replace.js.map +1 -1
- package/dist/parsing/functions/round.d.ts +7 -0
- package/dist/parsing/functions/round.d.ts.map +1 -0
- package/dist/parsing/functions/round.js +20 -2
- package/dist/parsing/functions/round.js.map +1 -1
- package/dist/parsing/functions/size.d.ts +7 -0
- package/dist/parsing/functions/size.d.ts.map +1 -0
- package/dist/parsing/functions/size.js +20 -2
- package/dist/parsing/functions/size.js.map +1 -1
- package/dist/parsing/functions/split.d.ts +9 -0
- package/dist/parsing/functions/split.d.ts.map +1 -0
- package/dist/parsing/functions/split.js +21 -2
- package/dist/parsing/functions/split.js.map +1 -1
- package/dist/parsing/functions/stringify.d.ts +9 -0
- package/dist/parsing/functions/stringify.d.ts.map +1 -0
- package/dist/parsing/functions/stringify.js +20 -2
- package/dist/parsing/functions/stringify.js.map +1 -1
- package/dist/parsing/functions/sum.d.ts +14 -0
- package/dist/parsing/functions/sum.d.ts.map +1 -0
- package/dist/parsing/functions/sum.js +20 -2
- package/dist/parsing/functions/sum.js.map +1 -1
- package/dist/parsing/functions/to_json.d.ts +7 -0
- package/dist/parsing/functions/to_json.d.ts.map +1 -0
- package/dist/parsing/functions/to_json.js +20 -2
- package/dist/parsing/functions/to_json.js.map +1 -1
- package/dist/parsing/functions/value_holder.d.ts +8 -0
- package/dist/parsing/functions/value_holder.d.ts.map +1 -0
- package/dist/parsing/logic/case.d.ts +7 -0
- package/dist/parsing/logic/case.d.ts.map +1 -0
- package/dist/parsing/logic/else.d.ts +7 -0
- package/dist/parsing/logic/else.d.ts.map +1 -0
- package/dist/parsing/logic/end.d.ts +6 -0
- package/dist/parsing/logic/end.d.ts.map +1 -0
- package/dist/parsing/logic/then.d.ts +7 -0
- package/dist/parsing/logic/then.d.ts.map +1 -0
- package/dist/parsing/logic/when.d.ts +7 -0
- package/dist/parsing/logic/when.d.ts.map +1 -0
- package/dist/parsing/operations/aggregated_return.d.ts +8 -0
- package/dist/parsing/operations/aggregated_return.d.ts.map +1 -0
- package/dist/parsing/operations/aggregated_with.d.ts +8 -0
- package/dist/parsing/operations/aggregated_with.d.ts.map +1 -0
- package/dist/parsing/operations/group_by.d.ts +35 -0
- package/dist/parsing/operations/group_by.d.ts.map +1 -0
- package/dist/parsing/operations/limit.d.ts +10 -0
- package/dist/parsing/operations/limit.d.ts.map +1 -0
- package/dist/parsing/operations/load.d.ts +48 -0
- package/dist/parsing/operations/load.d.ts.map +1 -0
- package/dist/parsing/operations/operation.d.ts +39 -0
- package/dist/parsing/operations/operation.d.ts.map +1 -0
- package/dist/parsing/operations/projection.d.ts +8 -0
- package/dist/parsing/operations/projection.d.ts.map +1 -0
- package/dist/parsing/operations/return.d.ts +23 -0
- package/dist/parsing/operations/return.d.ts.map +1 -0
- package/dist/parsing/operations/unwind.d.ts +12 -0
- package/dist/parsing/operations/unwind.d.ts.map +1 -0
- package/dist/parsing/operations/where.d.ts +26 -0
- package/dist/parsing/operations/where.d.ts.map +1 -0
- package/dist/parsing/operations/with.d.ts +17 -0
- package/dist/parsing/operations/with.d.ts.map +1 -0
- package/dist/parsing/parser.d.ts +66 -0
- package/dist/parsing/parser.d.ts.map +1 -0
- package/dist/parsing/parser.js +2 -3
- package/dist/parsing/parser.js.map +1 -1
- package/dist/parsing/token_to_node.d.ts +7 -0
- package/dist/parsing/token_to_node.d.ts.map +1 -0
- package/dist/tokenization/keyword.d.ts +43 -0
- package/dist/tokenization/keyword.d.ts.map +1 -0
- package/dist/tokenization/operator.d.ts +22 -0
- package/dist/tokenization/operator.d.ts.map +1 -0
- package/dist/tokenization/string_walker.d.ts +55 -0
- package/dist/tokenization/string_walker.d.ts.map +1 -0
- package/dist/tokenization/symbol.d.ts +15 -0
- package/dist/tokenization/symbol.d.ts.map +1 -0
- package/dist/tokenization/token.d.ts +176 -0
- package/dist/tokenization/token.d.ts.map +1 -0
- package/dist/tokenization/token_mapper.d.ts +40 -0
- package/dist/tokenization/token_mapper.d.ts.map +1 -0
- package/dist/tokenization/token_type.d.ts +16 -0
- package/dist/tokenization/token_type.d.ts.map +1 -0
- package/dist/tokenization/tokenizer.d.ts +45 -0
- package/dist/tokenization/tokenizer.d.ts.map +1 -0
- package/dist/tokenization/trie.d.ts +41 -0
- package/dist/tokenization/trie.d.ts.map +1 -0
- package/dist/utils/object_utils.d.ts +15 -0
- package/dist/utils/object_utils.d.ts.map +1 -0
- package/dist/utils/string_utils.d.ts +51 -0
- package/dist/utils/string_utils.d.ts.map +1 -0
- package/docs/flowquery.min.js +1 -1
- package/flowquery-vscode/flowQueryEngine/flowquery.min.js +1 -1
- package/misc/apps/RAG/.env.example +14 -0
- package/misc/apps/RAG/README.md +0 -7
- package/misc/apps/RAG/package.json +16 -7
- package/misc/apps/RAG/public/index.html +18 -0
- package/misc/apps/RAG/src/App.css +42 -0
- package/misc/apps/RAG/src/App.tsx +50 -0
- package/misc/apps/RAG/src/components/ApiKeySettings.tsx +245 -0
- package/misc/apps/RAG/src/components/ChatContainer.css +67 -0
- package/misc/apps/RAG/src/components/ChatContainer.tsx +239 -0
- package/misc/apps/RAG/src/components/ChatInput.css +23 -0
- package/misc/apps/RAG/src/components/ChatInput.tsx +62 -0
- package/misc/apps/RAG/src/components/ChatMessage.css +136 -0
- package/misc/apps/RAG/src/components/ChatMessage.tsx +152 -0
- package/misc/apps/RAG/src/components/FlowQueryAgent.ts +390 -0
- package/misc/apps/RAG/src/components/FlowQueryRunner.css +104 -0
- package/misc/apps/RAG/src/components/FlowQueryRunner.tsx +332 -0
- package/misc/apps/RAG/src/components/index.ts +15 -0
- package/misc/apps/RAG/src/index.tsx +17 -0
- package/misc/apps/RAG/src/plugins/PluginRegistry.ts +136 -0
- package/misc/apps/RAG/src/plugins/README.md +139 -0
- package/misc/apps/RAG/src/plugins/index.ts +72 -0
- package/misc/apps/RAG/src/plugins/loaders/CatFacts.ts +79 -0
- package/misc/apps/RAG/src/plugins/loaders/FetchJson.ts +71 -0
- package/misc/apps/RAG/src/plugins/loaders/Llm.ts +441 -0
- package/misc/apps/RAG/src/plugins/loaders/MockData.ts +161 -0
- package/misc/apps/RAG/src/plugins/types.ts +52 -0
- package/misc/apps/RAG/src/prompts/FlowQuerySystemPrompt.ts +385 -0
- package/misc/apps/RAG/src/prompts/index.ts +10 -0
- package/misc/apps/RAG/src/utils/FlowQueryExecutor.ts +131 -0
- package/misc/apps/RAG/src/utils/FlowQueryExtractor.ts +203 -0
- package/misc/apps/RAG/src/utils/index.ts +9 -0
- package/misc/apps/RAG/tsconfig.json +4 -2
- package/misc/apps/RAG/webpack.config.js +23 -12
- package/package.json +7 -1
- package/src/extensibility.ts +9 -0
- package/src/parsing/functions/avg.ts +10 -0
- package/src/parsing/functions/collect.ts +10 -0
- package/src/parsing/functions/extensibility/index.ts +54 -0
- package/src/parsing/functions/function_factory.ts +51 -48
- package/src/parsing/functions/function_metadata.ts +132 -156
- package/src/parsing/functions/functions.ts +27 -0
- package/src/parsing/functions/join.ts +11 -0
- package/src/parsing/functions/predicate_function.ts +4 -0
- package/src/parsing/functions/predicate_sum.ts +13 -0
- package/src/parsing/functions/rand.ts +8 -0
- package/src/parsing/functions/range.ts +11 -0
- package/src/parsing/functions/replace.ts +12 -0
- package/src/parsing/functions/round.ts +10 -0
- package/src/parsing/functions/size.ts +10 -0
- package/src/parsing/functions/split.ts +11 -0
- package/src/parsing/functions/stringify.ts +10 -0
- package/src/parsing/functions/sum.ts +10 -0
- package/src/parsing/functions/to_json.ts +10 -0
- package/src/parsing/parser.ts +2 -3
- package/tests/parsing/function_plugins.test.ts +11 -11
- package/tsconfig.json +4 -1
- package/dist/parsing/functions/predicate_function_factory.js +0 -19
- package/dist/parsing/functions/predicate_function_factory.js.map +0 -1
- package/misc/apps/RAG/src/index.ts +0 -20
- 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;
|