flowquery 1.0.25 → 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 (49) 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/docs/flowquery.min.js +1 -1
  8. package/flowquery-py/pyproject.toml +1 -1
  9. package/flowquery-py/src/parsing/parser.py +1 -0
  10. package/flowquery-py/tests/compute/test_runner.py +26 -0
  11. package/flowquery-py/tests/parsing/test_parser.py +18 -0
  12. package/flowquery-vscode/flowQueryEngine/flowquery.min.js +1 -1
  13. package/jest.config.js +6 -9
  14. package/misc/apps/RAG/data/chats.json +302 -0
  15. package/misc/apps/RAG/data/emails.json +182 -0
  16. package/misc/apps/RAG/data/events.json +226 -0
  17. package/misc/apps/RAG/data/files.json +172 -0
  18. package/misc/apps/RAG/data/users.json +158 -0
  19. package/misc/apps/RAG/jest.config.js +21 -0
  20. package/misc/apps/RAG/package.json +9 -2
  21. package/misc/apps/RAG/src/App.tsx +5 -5
  22. package/misc/apps/RAG/src/components/ChatContainer.tsx +53 -124
  23. package/misc/apps/RAG/src/components/FlowQueryAgent.ts +151 -157
  24. package/misc/apps/RAG/src/components/index.ts +1 -1
  25. package/misc/apps/RAG/src/graph/index.ts +19 -0
  26. package/misc/apps/RAG/src/graph/initializeGraph.ts +254 -0
  27. package/misc/apps/RAG/src/index.tsx +25 -13
  28. package/misc/apps/RAG/src/prompts/FlowQuerySystemPrompt.ts +146 -231
  29. package/misc/apps/RAG/src/prompts/index.ts +4 -4
  30. package/misc/apps/RAG/src/tests/graph.test.ts +35 -0
  31. package/misc/apps/RAG/src/utils/FlowQueryExecutor.ts +20 -21
  32. package/misc/apps/RAG/src/utils/FlowQueryExtractor.ts +35 -30
  33. package/misc/apps/RAG/src/utils/Llm.ts +248 -0
  34. package/misc/apps/RAG/src/utils/index.ts +7 -4
  35. package/misc/apps/RAG/tsconfig.json +4 -3
  36. package/misc/apps/RAG/webpack.config.js +40 -40
  37. package/package.json +1 -1
  38. package/src/parsing/parser.ts +1 -0
  39. package/tests/compute/runner.test.ts +1 -1
  40. package/tests/parsing/parser.test.ts +16 -0
  41. package/misc/apps/RAG/src/plugins/README.md +0 -139
  42. package/misc/apps/RAG/src/plugins/index.ts +0 -72
  43. package/misc/apps/RAG/src/plugins/loaders/CatFacts.ts +0 -70
  44. package/misc/apps/RAG/src/plugins/loaders/FetchJson.ts +0 -65
  45. package/misc/apps/RAG/src/plugins/loaders/Form.ts +0 -594
  46. package/misc/apps/RAG/src/plugins/loaders/Llm.ts +0 -450
  47. package/misc/apps/RAG/src/plugins/loaders/MockData.ts +0 -101
  48. package/misc/apps/RAG/src/plugins/loaders/Table.ts +0 -274
  49. package/misc/apps/RAG/src/plugins/loaders/Weather.ts +0 -138
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Graph module exports
3
+ */
4
+ import FlowQuery from "flowquery";
5
+
6
+ export { initializeGraph } from "./initializeGraph";
7
+
8
+ /**
9
+ * Get the graph schema including all node labels and relationship types.
10
+ *
11
+ * @returns Promise resolving to the graph schema
12
+ */
13
+ export async function getGraphSchema(): Promise<any> {
14
+ const runner = new FlowQuery(
15
+ `CALL schema() YIELD kind, label, type, sample RETURN kind, label, type, sample`
16
+ );
17
+ await runner.run();
18
+ return runner.results;
19
+ }
@@ -0,0 +1,254 @@
1
+ /**
2
+ * Graph Initialization Module
3
+ *
4
+ * Models the JSON data files as a virtual FlowQuery graph.
5
+ * Creates virtual nodes and relationships using FlowQuery Cypher.
6
+ * Uses native LOAD JSON FROM to read data from the /data/ endpoint.
7
+ */
8
+ import FlowQuery from "flowquery";
9
+
10
+ /**
11
+ * Initializes the virtual FlowQuery graph with data from JSON files.
12
+ * Creates nodes for: User, Chat, Email, Event, File
13
+ * Creates relationships connecting them based on the data.
14
+ */
15
+ export async function initializeGraph(): Promise<void> {
16
+ console.log("Initializing FlowQuery graph...");
17
+
18
+ // Create all nodes
19
+ await createUserNodes();
20
+ await createChatNodes();
21
+ await createEmailNodes();
22
+ await createEventNodes();
23
+ await createFileNodes();
24
+
25
+ // Create relationships
26
+ await createUserManagesRelationships();
27
+ await createChatMemberRelationships();
28
+ await createEmailSentByRelationships();
29
+ await createEmailReceivedByRelationships();
30
+ await createEventOrganizerRelationships();
31
+ await createEventAttendeeRelationships();
32
+ await createFileCreatedByRelationships();
33
+ await createFileSharedWithRelationships();
34
+ await createEmailAttachmentRelationships();
35
+ await createEventFileRelationships();
36
+ await createEventEmailRelationships();
37
+
38
+ console.log("FlowQuery graph initialized successfully.");
39
+ }
40
+
41
+ // ============ Node Creation Functions ============
42
+
43
+ async function createUserNodes(): Promise<void> {
44
+ const runner = new FlowQuery(`
45
+ CREATE VIRTUAL (:User) AS {
46
+ LOAD JSON FROM '/data/users.json' AS user
47
+ RETURN
48
+ user.id AS id, user.displayName AS displayName, user.mail AS mail,
49
+ user.jobTitle AS jobTitle, user.department AS department,
50
+ user.officeLocation AS officeLocation, user.managerId AS managerId,
51
+ user.directReports AS directReports, user.hireDate AS hireDate,
52
+ user.skills AS skills, user.phone AS phone
53
+ }
54
+ `);
55
+ await runner.run();
56
+ console.log("Created User nodes");
57
+ }
58
+
59
+ async function createChatNodes(): Promise<void> {
60
+ const runner = new FlowQuery(`
61
+ CREATE VIRTUAL (:Chat) AS {
62
+ LOAD JSON FROM '/data/chats.json' AS chat
63
+ RETURN chat.id AS id, chat.topic AS topic, chat.type AS type,
64
+ chat.teamName AS teamName, chat.members AS members, chat.messages AS messages
65
+ }
66
+ `);
67
+ await runner.run();
68
+ console.log("Created Chat nodes");
69
+ }
70
+
71
+ async function createEmailNodes(): Promise<void> {
72
+ const runner = new FlowQuery(`
73
+ CREATE VIRTUAL (:Email) AS {
74
+ LOAD JSON FROM '/data/emails.json' AS email
75
+ RETURN
76
+ email.id AS id, email.subject AS subject, email.from AS fromUser,
77
+ email.to AS toUsers, email.cc AS cc, email.receivedDateTime AS receivedDateTime,
78
+ email.body AS body, email.importance AS importance,
79
+ email.hasAttachments AS hasAttachments, email.attachments AS attachments,
80
+ email.isRead AS isRead, email.conversationId AS conversationId,
81
+ email.categories AS categories
82
+ }
83
+ `);
84
+ await runner.run();
85
+ console.log("Created Email nodes");
86
+ }
87
+
88
+ async function createEventNodes(): Promise<void> {
89
+ const runner = new FlowQuery(`
90
+ CREATE VIRTUAL (:Event) AS {
91
+ LOAD JSON FROM '/data/events.json' AS event
92
+ RETURN
93
+ event.id AS id, event.subject AS subject, event.organizer AS organizer,
94
+ event.attendees AS attendees, event.start AS start, event.end AS end,
95
+ event.location AS location, event.isOnline AS isOnline,
96
+ event.onlineMeetingUrl AS onlineMeetingUrl, event.body AS body,
97
+ event.recurrence AS recurrence, event.relatedEmails AS relatedEmails,
98
+ event.relatedFiles AS relatedFiles, event.categories AS categories
99
+ }
100
+ `);
101
+ await runner.run();
102
+ console.log("Created Event nodes");
103
+ }
104
+
105
+ async function createFileNodes(): Promise<void> {
106
+ const runner = new FlowQuery(`
107
+ CREATE VIRTUAL (:File) AS {
108
+ LOAD JSON FROM '/data/files.json' AS file
109
+ RETURN
110
+ file.id AS id, file.name AS name, file.createdBy AS createdBy,
111
+ file.createdDateTime AS createdDateTime, file.lastModifiedBy AS lastModifiedBy,
112
+ file.lastModifiedDateTime AS lastModifiedDateTime, file.size AS size,
113
+ file.mimeType AS mimeType, file.webUrl AS webUrl, file.driveId AS driveId,
114
+ file.parentFolder AS parentFolder, file.sharedWith AS sharedWith,
115
+ file.relatedEmails AS relatedEmails, file.relatedEvents AS relatedEvents,
116
+ file.tags AS tags
117
+ }
118
+ `);
119
+ await runner.run();
120
+ console.log("Created File nodes");
121
+ }
122
+
123
+ // ============ Relationship Creation Functions ============
124
+
125
+ async function createUserManagesRelationships(): Promise<void> {
126
+ const runner = new FlowQuery(`
127
+ CREATE VIRTUAL (:User)-[:MANAGES]-(:User) AS {
128
+ LOAD JSON FROM '/data/users.json' AS user
129
+ RETURN user.managerId AS left_id, user.id AS right_id
130
+ }
131
+ `);
132
+ await runner.run();
133
+ console.log("Created User-[:MANAGES]->User relationships");
134
+ }
135
+
136
+ async function createChatMemberRelationships(): Promise<void> {
137
+ const runner = new FlowQuery(`
138
+ CREATE VIRTUAL (:User)-[:MEMBER_OF]-(:Chat) AS {
139
+ LOAD JSON FROM '/data/chats.json' AS chat
140
+ UNWIND chat.members AS memberId
141
+ RETURN memberId AS left_id, chat.id AS right_id
142
+ }
143
+ `);
144
+ await runner.run();
145
+ console.log("Created User-[:MEMBER_OF]->Chat relationships");
146
+ }
147
+
148
+ async function createEmailSentByRelationships(): Promise<void> {
149
+ const runner = new FlowQuery(`
150
+ CREATE VIRTUAL (:User)-[:SENT]-(:Email) AS {
151
+ LOAD JSON FROM '/data/emails.json' AS email
152
+ RETURN email.from AS left_id, email.id AS right_id
153
+ }
154
+ `);
155
+ await runner.run();
156
+ console.log("Created User-[:SENT]->Email relationships");
157
+ }
158
+
159
+ async function createEmailReceivedByRelationships(): Promise<void> {
160
+ const runner = new FlowQuery(`
161
+ CREATE VIRTUAL (:Email)-[:RECEIVED_BY]-(:User) AS {
162
+ LOAD JSON FROM '/data/emails.json' AS email
163
+ UNWIND email.to AS recipient
164
+ RETURN email.id AS left_id, recipient AS right_id
165
+ }
166
+ `);
167
+ await runner.run();
168
+ console.log("Created Email-[:RECEIVED_BY]->User relationships");
169
+ }
170
+
171
+ async function createEventOrganizerRelationships(): Promise<void> {
172
+ const runner = new FlowQuery(`
173
+ CREATE VIRTUAL (:User)-[:ORGANIZES]-(:Event) AS {
174
+ LOAD JSON FROM '/data/events.json' AS event
175
+ RETURN event.organizer AS left_id, event.id AS right_id
176
+ }
177
+ `);
178
+ await runner.run();
179
+ console.log("Created User-[:ORGANIZES]->Event relationships");
180
+ }
181
+
182
+ async function createEventAttendeeRelationships(): Promise<void> {
183
+ const runner = new FlowQuery(`
184
+ CREATE VIRTUAL (:User)-[:ATTENDS]-(:Event) AS {
185
+ LOAD JSON FROM '/data/events.json' AS event
186
+ UNWIND event.attendees AS attendee
187
+ RETURN attendee.userId AS left_id, event.id AS right_id
188
+ }
189
+ `);
190
+ await runner.run();
191
+ console.log("Created User-[:ATTENDS]->Event relationships");
192
+ }
193
+
194
+ async function createFileCreatedByRelationships(): Promise<void> {
195
+ const runner = new FlowQuery(`
196
+ CREATE VIRTUAL (:User)-[:CREATED]-(:File) AS {
197
+ LOAD JSON FROM '/data/files.json' AS file
198
+ RETURN file.createdBy AS left_id, file.id AS right_id
199
+ }
200
+ `);
201
+ await runner.run();
202
+ console.log("Created User-[:CREATED]->File relationships");
203
+ }
204
+
205
+ async function createFileSharedWithRelationships(): Promise<void> {
206
+ const runner = new FlowQuery(`
207
+ CREATE VIRTUAL (:File)-[:SHARED_WITH]-(:User) AS {
208
+ LOAD JSON FROM '/data/files.json' AS file
209
+ UNWIND file.sharedWith AS userId
210
+ RETURN file.id AS left_id, userId AS right_id
211
+ }
212
+ `);
213
+ await runner.run();
214
+ console.log("Created File-[:SHARED_WITH]->User relationships");
215
+ }
216
+
217
+ async function createEmailAttachmentRelationships(): Promise<void> {
218
+ const runner = new FlowQuery(`
219
+ CREATE VIRTUAL (:Email)-[:HAS_ATTACHMENT]-(:File) AS {
220
+ LOAD JSON FROM '/data/emails.json' AS email
221
+ WHERE email.hasAttachments = true
222
+ UNWIND email.attachments AS fileId
223
+ RETURN email.id AS left_id, fileId AS right_id
224
+ }
225
+ `);
226
+ await runner.run();
227
+ console.log("Created Email-[:HAS_ATTACHMENT]->File relationships");
228
+ }
229
+
230
+ async function createEventFileRelationships(): Promise<void> {
231
+ const runner = new FlowQuery(`
232
+ CREATE VIRTUAL (:Event)-[:RELATED_TO_FILE]-(:File) AS {
233
+ LOAD JSON FROM '/data/events.json' AS event
234
+ UNWIND event.relatedFiles AS fileId
235
+ WHERE fileId IS NOT NULL
236
+ RETURN event.id AS left_id, fileId AS right_id
237
+ }
238
+ `);
239
+ await runner.run();
240
+ console.log("Created Event-[:RELATED_TO_FILE]->File relationships");
241
+ }
242
+
243
+ async function createEventEmailRelationships(): Promise<void> {
244
+ const runner = new FlowQuery(`
245
+ CREATE VIRTUAL (:Event)-[:RELATED_TO_EMAIL]-(:Email) AS {
246
+ LOAD JSON FROM '/data/events.json' AS event
247
+ UNWIND event.relatedEmails AS emailId
248
+ WHERE emailId IS NOT NULL
249
+ RETURN event.id AS left_id, emailId AS right_id
250
+ }
251
+ `);
252
+ await runner.run();
253
+ console.log("Created Event-[:RELATED_TO_EMAIL]->Email relationships");
254
+ }
@@ -1,17 +1,29 @@
1
1
  import React from 'react';
2
2
  import { createRoot } from 'react-dom/client';
3
3
  import App from './App';
4
- import { initializePlugins } from './plugins';
4
+ import { initializeGraph } from './graph';
5
5
 
6
- // Initialize FlowQuery plugins before rendering
7
- initializePlugins();
8
-
9
- const container = document.getElementById('root');
10
- if (container) {
11
- const root = createRoot(container);
12
- root.render(
13
- <React.StrictMode>
14
- <App />
15
- </React.StrictMode>
16
- );
17
- }
6
+ // Initialize the FlowQuery graph and then render the app
7
+ initializeGraph().then(() => {
8
+ const container = document.getElementById('root');
9
+ if (container) {
10
+ const root = createRoot(container);
11
+ root.render(
12
+ <React.StrictMode>
13
+ <App />
14
+ </React.StrictMode>
15
+ );
16
+ }
17
+ }).catch((error) => {
18
+ console.error('Failed to initialize FlowQuery graph:', error);
19
+ // Still render the app even if graph initialization fails
20
+ const container = document.getElementById('root');
21
+ if (container) {
22
+ const root = createRoot(container);
23
+ root.render(
24
+ <React.StrictMode>
25
+ <App />
26
+ </React.StrictMode>
27
+ );
28
+ }
29
+ });