forked from langflow-ai/langflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update step duration display and logic (langflow-ai#4506)
* feat: Add durationStore for managing chat durations and intervals and update duration display logic to use store * [autofix.ci] apply automated fixes * Expand `recursive_serialize_or_str` to support `BaseModelV1` subclasses * fix: Update duration calculation for event handlers Improve accuracy of duration measurement in event handlers by centralizing the calculation method. This ensures consistent timing across different events and enhances the reliability of event processing. * refactor: improve duration calculation logic Enhance the duration calculation by clearly handling both integer and float timestamps. This ensures accurate duration tracking and simplifies the code structure, improving maintainability and readability. --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Gabriel Luiz Freitas Almeida <[email protected]> Co-authored-by: Cristhian Zanforlin Lousa <[email protected]>
- Loading branch information
1 parent
471b28a
commit 78ca4fd
Showing
7 changed files
with
105 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 29 additions & 18 deletions
47
src/frontend/src/components/chatComponents/DurationDisplay.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { create } from "zustand"; | ||
|
||
interface DurationState { | ||
durations: Record<string, number>; | ||
intervals: Record<string, NodeJS.Timeout>; | ||
setDuration: (chatId: string, duration: number) => void; | ||
incrementDuration: (chatId: string) => void; | ||
clearInterval: (chatId: string) => void; | ||
setInterval: (chatId: string, intervalId: NodeJS.Timeout) => void; | ||
} | ||
|
||
export const useDurationStore = create<DurationState>((set) => ({ | ||
durations: {}, | ||
intervals: {}, | ||
setDuration: (chatId, duration) => | ||
set((state) => ({ | ||
durations: { ...state.durations, [chatId]: duration }, | ||
})), | ||
incrementDuration: (chatId) => | ||
set((state) => ({ | ||
durations: { | ||
...state.durations, | ||
[chatId]: (state.durations[chatId] || 0) + 10, | ||
}, | ||
})), | ||
clearInterval: (chatId) => | ||
set((state) => { | ||
if (state.intervals[chatId]) { | ||
clearInterval(state.intervals[chatId]); | ||
} | ||
const { [chatId]: _, ...rest } = state.intervals; | ||
return { intervals: rest }; | ||
}), | ||
setInterval: (chatId, intervalId) => | ||
set((state) => ({ | ||
intervals: { ...state.intervals, [chatId]: intervalId }, | ||
})), | ||
})); |