Skip to content

Commit 6493de8

Browse files
committed
refactor: clean up chat-atoms by removing unused imports and optimizing cancelMessageAtom logic, fix: enhance time field detection in ChatArtifactEnhanced and ArtifactRenderer components, feat: implement time field selector with improved detection logic and user experience, fix: update query processor to handle table variable replacement, chore: update PanelEdit to ensure useParentTimeFilter is set for new panels and improve time range handling, feat: add Switch component for better UI control
1 parent e08de1c commit 6493de8

File tree

12 files changed

+465
-297
lines changed

12 files changed

+465
-297
lines changed

bun.lock

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gigapi-ui",
3-
"version": "1.0.19",
3+
"version": "1.0.20",
44
"type": "module",
55
"description": "UI interface for GigAPI: The Infinite Timeseries Lakehouse. GigAPI UI provides a slick web interface to query time-series using GigAPI Catalog Metadata + DuckDB",
66
"scripts": {
@@ -27,6 +27,7 @@
2727
"@radix-ui/react-select": "^2.2.5",
2828
"@radix-ui/react-separator": "^1.1.7",
2929
"@radix-ui/react-slot": "^1.2.3",
30+
"@radix-ui/react-switch": "^1.2.5",
3031
"@radix-ui/react-tabs": "^1.1.12",
3132
"@radix-ui/react-tooltip": "^1.2.7",
3233
"@tailwindcss/vite": "^4.1.11",

src/atoms/chat-atoms.ts

Lines changed: 69 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { SchemaContextBuilder } from "@/lib/schema-context-builder";
1414
import { ConversationAnalyzer } from "@/lib/conversation-analyzer";
1515
import { StorageUtils } from "@/lib/storage-utils";
1616
import { schemaCacheAtom, loadAndCacheTableSchemaAtom } from "./database-atoms";
17-
import { apiUrlAtom } from "./connection-atoms";
1817
import { getCurrentTabData } from "./tab-atoms";
1918
import type {
2019
ChatSession,
@@ -244,7 +243,6 @@ export const sessionListAtom = atom((get) => {
244243
);
245244
});
246245

247-
248246
// ============================================================================
249247
// Helper Functions
250248
// ============================================================================
@@ -332,54 +330,51 @@ export const createSessionAtom = atom(
332330
);
333331

334332
// Cancel streaming message
335-
export const cancelMessageAtom = atom(
336-
null,
337-
(get, set, sessionId: string) => {
338-
const abortControllers = get(activeAbortControllersAtom);
339-
const controller = abortControllers.get(sessionId);
340-
341-
if (controller) {
342-
// Abort the fetch request
343-
controller.abort();
344-
345-
// Remove from active controllers
346-
const newControllers = new Map(abortControllers);
347-
newControllers.delete(sessionId);
348-
set(activeAbortControllersAtom, newControllers);
349-
350-
// Update the session to remove streaming flag from the last message
351-
const sessions = get(chatSessionsAtom);
352-
const session = sessions[sessionId];
353-
if (session && session.messages.length > 0) {
354-
const lastMessage = session.messages[session.messages.length - 1];
355-
if (lastMessage.metadata?.isStreaming) {
356-
const updatedMessages = [...session.messages];
357-
updatedMessages[updatedMessages.length - 1] = {
358-
...lastMessage,
359-
metadata: {
360-
...lastMessage.metadata,
361-
isStreaming: false,
362-
wasCancelled: true,
363-
},
364-
};
365-
366-
set(chatSessionsAtom, {
367-
...sessions,
368-
[sessionId]: {
369-
...session,
370-
messages: updatedMessages,
371-
updatedAt: new Date().toISOString(),
372-
},
373-
});
374-
}
333+
export const cancelMessageAtom = atom(null, (get, set, sessionId: string) => {
334+
const abortControllers = get(activeAbortControllersAtom);
335+
const controller = abortControllers.get(sessionId);
336+
337+
if (controller) {
338+
// Abort the fetch request
339+
controller.abort();
340+
341+
// Remove from active controllers
342+
const newControllers = new Map(abortControllers);
343+
newControllers.delete(sessionId);
344+
set(activeAbortControllersAtom, newControllers);
345+
346+
// Update the session to remove streaming flag from the last message
347+
const sessions = get(chatSessionsAtom);
348+
const session = sessions[sessionId];
349+
if (session && session.messages.length > 0) {
350+
const lastMessage = session.messages[session.messages.length - 1];
351+
if (lastMessage.metadata?.isStreaming) {
352+
const updatedMessages = [...session.messages];
353+
updatedMessages[updatedMessages.length - 1] = {
354+
...lastMessage,
355+
metadata: {
356+
...lastMessage.metadata,
357+
isStreaming: false,
358+
wasCancelled: true,
359+
},
360+
};
361+
362+
set(chatSessionsAtom, {
363+
...sessions,
364+
[sessionId]: {
365+
...session,
366+
messages: updatedMessages,
367+
updatedAt: new Date().toISOString(),
368+
},
369+
});
375370
}
376-
377-
return true;
378371
}
379-
380-
return false;
372+
373+
return true;
381374
}
382-
);
375+
376+
return false;
377+
});
383378

384379
// Send message with streaming support
385380
export const sendMessageAtom = atom(
@@ -515,7 +510,9 @@ export const sendMessageAtom = atom(
515510

516511
// Get time context from current tab
517512
const currentTab = getCurrentTabData();
518-
const timeRange = currentTab?.timeRange ? JSON.stringify(currentTab.timeRange) : null;
513+
const timeRange = currentTab?.timeRange
514+
? JSON.stringify(currentTab.timeRange)
515+
: null;
519516
const selectedDb = currentTab?.database || "";
520517
const selectedTable = currentTab?.table || "";
521518

@@ -686,7 +683,7 @@ export const sendMessageAtom = atom(
686683
},
687684
abortController.signal
688685
);
689-
686+
690687
// Clean up abort controller after successful completion
691688
const currentControllers = get(activeAbortControllersAtom);
692689
const updatedControllers = new Map(currentControllers);
@@ -700,9 +697,9 @@ export const sendMessageAtom = atom(
700697
set(activeAbortControllersAtom, updatedControllers);
701698

702699
// Check if the error is due to abort
703-
if (error instanceof Error && error.name === 'AbortError') {
700+
if (error instanceof Error && error.name === "AbortError") {
704701
// Don't show error message for cancelled requests
705-
console.log('Message streaming was cancelled');
702+
console.log("Message streaming was cancelled");
706703
return;
707704
}
708705

@@ -789,7 +786,11 @@ export const deleteSessionAtom = atom(null, (get, set, sessionId: string) => {
789786
// Edit message
790787
export const editMessageAtom = atom(
791788
null,
792-
async (get, set, options: { sessionId: string; messageId: string; newContent: string }) => {
789+
async (
790+
get,
791+
set,
792+
options: { sessionId: string; messageId: string; newContent: string }
793+
) => {
793794
const { sessionId, messageId, newContent } = options;
794795
const sessions = get(chatSessionsAtom);
795796
const session = sessions[sessionId];
@@ -844,7 +845,11 @@ export const editMessageAtom = atom(
844845
// Regenerate from message
845846
export const regenerateFromMessageAtom = atom(
846847
null,
847-
async (get, set, options: { sessionId: string; messageId: string; isAgentic?: boolean }) => {
848+
async (
849+
get,
850+
set,
851+
options: { sessionId: string; messageId: string; isAgentic?: boolean }
852+
) => {
848853
const { sessionId, messageId, isAgentic } = options;
849854
const sessions = get(chatSessionsAtom);
850855
const session = sessions[sessionId];
@@ -911,7 +916,9 @@ export const regenerateFromMessageAtom = atom(
911916

912917
// Get time context from current tab
913918
const currentTab = getCurrentTabData();
914-
const timeRange = currentTab?.timeRange ? JSON.stringify(currentTab.timeRange) : null;
919+
const timeRange = currentTab?.timeRange
920+
? JSON.stringify(currentTab.timeRange)
921+
: null;
915922
const selectedDb = currentTab?.database || "";
916923
const selectedTable = currentTab?.table || "";
917924

@@ -963,7 +970,10 @@ export const regenerateFromMessageAtom = atom(
963970
function processChunkForThinking(text: string) {
964971
const thinkingStartMatch = text.match(/<think>/);
965972
if (thinkingStartMatch && thinkingStartMatch.index !== undefined) {
966-
const beforeThinking = text.substring(0, thinkingStartMatch.index);
973+
const beforeThinking = text.substring(
974+
0,
975+
thinkingStartMatch.index
976+
);
967977
const afterThinking = text.substring(
968978
thinkingStartMatch.index + thinkingStartMatch[0].length
969979
);
@@ -1049,7 +1059,7 @@ export const regenerateFromMessageAtom = atom(
10491059
},
10501060
abortController.signal
10511061
);
1052-
1062+
10531063
// Clean up abort controller after successful completion
10541064
const currentControllers = get(activeAbortControllersAtom);
10551065
const updatedControllers = new Map(currentControllers);
@@ -1063,8 +1073,8 @@ export const regenerateFromMessageAtom = atom(
10631073
set(activeAbortControllersAtom, updatedControllers);
10641074

10651075
// Check if the error is due to abort
1066-
if (error instanceof Error && error.name === 'AbortError') {
1067-
console.log('Message streaming was cancelled');
1076+
if (error instanceof Error && error.name === "AbortError") {
1077+
console.log("Message streaming was cancelled");
10681078
return;
10691079
}
10701080

@@ -1122,7 +1132,6 @@ export const renameSessionAtom = atom(
11221132
}
11231133
);
11241134

1125-
11261135
// Delete connection
11271136
export const deleteConnectionAtom = atom(
11281137
null,
@@ -1325,11 +1334,9 @@ Example: When user asks "show me sales by month", respond with:
13251334
includeIndices: true,
13261335
summaryOnly: false,
13271336
includeRecentContext: true, // Always include recent context for better continuity
1328-
isAgentic, // Pass agentic mode flag
1329-
// Enhanced with sample data
1337+
isAgentic,
13301338
includeSampleData: true,
13311339
sampleDataLimit: 5,
1332-
apiUrl: queryContext.apiUrl || "http://localhost:7971/query",
13331340
}
13341341
);
13351342

src/atoms/time-atoms.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { atom } from "jotai";
2-
import { atomWithStorage } from "jotai/utils";
32
import type { TimeRange } from "@/types/tab.types";
43
import { currentTabTimeFieldAtom, currentTabTimeRangeAtom, currentTabTimeZoneAtom } from "./tab-atoms";
54

0 commit comments

Comments
 (0)