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
@@ -2,16 +2,11 @@ import React, { Component, createRef, RefObject } from 'react';
2
2
  import { Spinner } from '@fluentui/react-components';
3
3
  import { ChatMessage, Message } from './ChatMessage';
4
4
  import { ChatInput } from './ChatInput';
5
- import { LlmOptions } from '../plugins/loaders/Llm';
6
- import { processQueryStream } from './FlowQueryAgent';
5
+ import { FlowQueryAgent } from './FlowQueryAgent';
7
6
  import './ChatContainer.css';
8
7
 
9
8
  interface ChatContainerProps {
10
9
  systemPrompt?: string;
11
- llmOptions?: LlmOptions;
12
- useStreaming?: boolean;
13
- /** Whether to use the FlowQuery agent for processing queries */
14
- useFlowQueryAgent?: boolean;
15
10
  /** Whether to show intermediate steps (query generation, execution) */
16
11
  showIntermediateSteps?: boolean;
17
12
  }
@@ -25,12 +20,11 @@ interface ChatContainerState {
25
20
  export class ChatContainer extends Component<ChatContainerProps, ChatContainerState> {
26
21
  static defaultProps: Partial<ChatContainerProps> = {
27
22
  systemPrompt: 'You are a helpful assistant. Be concise and informative in your responses.',
28
- llmOptions: {},
29
- useStreaming: true,
30
- useFlowQueryAgent: true,
31
23
  showIntermediateSteps: true
32
24
  };
33
25
 
26
+ private readonly agent = new FlowQueryAgent();
27
+
34
28
  private messagesEndRef: RefObject<HTMLDivElement | null>;
35
29
 
36
30
  constructor(props: ChatContainerProps) {
@@ -65,7 +59,7 @@ export class ChatContainer extends Component<ChatContainerProps, ChatContainerSt
65
59
  };
66
60
 
67
61
  private handleSendMessage = async (content: string): Promise<void> => {
68
- const { systemPrompt, llmOptions, useStreaming, useFlowQueryAgent, showIntermediateSteps } = this.props;
62
+ const { systemPrompt, showIntermediateSteps } = this.props;
69
63
  const { messages } = this.state;
70
64
 
71
65
  const userMessage: Message = {
@@ -88,134 +82,69 @@ export class ChatContainer extends Component<ChatContainerProps, ChatContainerSt
88
82
 
89
83
  try {
90
84
  const conversationHistory = this.buildConversationHistory([...messages, userMessage]);
91
-
92
- if (useFlowQueryAgent) {
93
- // Use the FlowQuery agent for processing
94
- const assistantMessage: Message = {
95
- id: assistantMessageId,
96
- role: 'assistant',
97
- content: '',
98
- timestamp: new Date(),
99
- isStreaming: true
100
- };
101
- this.setState(prev => ({
102
- messages: [...prev.messages, assistantMessage]
103
- }));
104
-
105
- let fullContent = '';
106
- let adaptiveCardFromStream: Record<string, unknown> | undefined;
107
-
108
- for await (const { chunk, done, adaptiveCard, newMessage } of processQueryStream(content, {
109
- systemPrompt: systemPrompt ?? 'You are a helpful assistant. Be concise and informative in your responses.',
110
- llmOptions,
111
- conversationHistory: conversationHistory.slice(0, -1),
112
- showIntermediateSteps
113
- })) {
114
- // If newMessage flag is set, finalize current message and start a new one
115
- if (newMessage) {
116
- // Create a new assistant message for the retry
117
- const previousMessageId = currentMessageId;
118
- currentMessageId = this.generateMessageId();
119
- fullContent = '';
120
- const newAssistantMessage: Message = {
121
- id: currentMessageId,
122
- role: 'assistant',
123
- content: '',
124
- timestamp: new Date(),
125
- isStreaming: true
126
- };
127
- // Mark previous message as done streaming AND add new message atomically
128
- this.setState(prev => ({
129
- messages: [...prev.messages.map(msg =>
130
- msg.id === previousMessageId
131
- ? { ...msg, isStreaming: false }
132
- : msg
133
- ), newAssistantMessage]
134
- }));
135
- }
136
-
137
- if (chunk) {
138
- fullContent += chunk;
139
- this.setState(prev => ({
140
- messages: prev.messages.map(msg =>
141
- msg.id === currentMessageId
142
- ? { ...msg, content: fullContent }
143
- : msg
144
- )
145
- }));
146
- }
147
-
148
- // Capture adaptive card if present
149
- if (adaptiveCard) {
150
- adaptiveCardFromStream = adaptiveCard;
151
- }
152
-
153
- if (done) {
154
- this.setState(prev => ({
155
- messages: prev.messages.map(msg =>
156
- msg.id === currentMessageId
157
- ? { ...msg, isStreaming: false, adaptiveCard: adaptiveCardFromStream }
158
- : msg
159
- )
160
- }));
161
- }
162
- }
163
- } else {
164
- // Original LLM-only behavior (kept for backward compatibility)
165
- const { llm, llmStream } = await import('../plugins/loaders/Llm');
166
-
167
- const options: LlmOptions = {
168
- ...llmOptions,
169
- systemPrompt,
170
- messages: conversationHistory.slice(0, -1),
171
- };
172
85
 
173
- if (useStreaming) {
174
- const assistantMessage: Message = {
175
- id: assistantMessageId,
86
+ const assistantMessage: Message = {
87
+ id: assistantMessageId,
88
+ role: 'assistant',
89
+ content: '',
90
+ timestamp: new Date(),
91
+ isStreaming: true
92
+ };
93
+ this.setState(prev => ({
94
+ messages: [...prev.messages, assistantMessage]
95
+ }));
96
+
97
+ let fullContent = '';
98
+ let adaptiveCardFromStream: Record<string, unknown> | undefined;
99
+
100
+ for await (const { chunk, done, adaptiveCard, newMessage } of this.agent.processQueryStream(content, {
101
+ systemPrompt: systemPrompt ?? 'You are a helpful assistant. Be concise and informative in your responses.',
102
+ conversationHistory: conversationHistory.slice(0, -1),
103
+ showIntermediateSteps
104
+ })) {
105
+ // If newMessage flag is set, finalize current message and start a new one
106
+ if (newMessage) {
107
+ const previousMessageId = currentMessageId;
108
+ currentMessageId = this.generateMessageId();
109
+ fullContent = '';
110
+ const newAssistantMessage: Message = {
111
+ id: currentMessageId,
176
112
  role: 'assistant',
177
113
  content: '',
178
114
  timestamp: new Date(),
179
115
  isStreaming: true
180
116
  };
181
117
  this.setState(prev => ({
182
- messages: [...prev.messages, assistantMessage]
118
+ messages: [...prev.messages.map(msg =>
119
+ msg.id === previousMessageId
120
+ ? { ...msg, isStreaming: false }
121
+ : msg
122
+ ), newAssistantMessage]
183
123
  }));
184
-
185
- let fullContent = '';
186
- for await (const chunk of llmStream(content, options)) {
187
- const deltaContent = chunk.choices?.[0]?.delta?.content || '';
188
- if (deltaContent) {
189
- fullContent += deltaContent;
190
- this.setState(prev => ({
191
- messages: prev.messages.map(msg =>
192
- msg.id === assistantMessageId
193
- ? { ...msg, content: fullContent }
194
- : msg
195
- )
196
- }));
197
- }
198
- }
199
-
124
+ }
125
+
126
+ if (chunk) {
127
+ fullContent += chunk;
200
128
  this.setState(prev => ({
201
129
  messages: prev.messages.map(msg =>
202
- msg.id === assistantMessageId
203
- ? { ...msg, isStreaming: false }
130
+ msg.id === currentMessageId
131
+ ? { ...msg, content: fullContent }
204
132
  : msg
205
133
  )
206
134
  }));
207
- } else {
208
- const response = await llm(content, options);
209
- const assistantContent = response.choices[0]?.message?.content || 'No response received.';
210
-
211
- const assistantMessage: Message = {
212
- id: assistantMessageId,
213
- role: 'assistant',
214
- content: assistantContent,
215
- timestamp: new Date()
216
- };
135
+ }
136
+
137
+ if (adaptiveCard) {
138
+ adaptiveCardFromStream = adaptiveCard;
139
+ }
140
+
141
+ if (done) {
217
142
  this.setState(prev => ({
218
- messages: [...prev.messages, assistantMessage]
143
+ messages: prev.messages.map(msg =>
144
+ msg.id === currentMessageId
145
+ ? { ...msg, isStreaming: false, adaptiveCard: adaptiveCardFromStream }
146
+ : msg
147
+ )
219
148
  }));
220
149
  }
221
150
  }