-
Notifications
You must be signed in to change notification settings - Fork 48
feat: add runner syncing, simplify generation selection and stream handling #1886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
415d07b
745fbbe
880304c
d4a61c3
59152a7
2489fef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,5 +1,5 @@ | ||||||
import type { NodeId } from "@giselle-sdk/data-type"; | ||||||
import { useCallback, useMemo } from "react"; | ||||||
import { useCallback, useEffect, useMemo } from "react"; | ||||||
import useSWR from "swr"; | ||||||
import { useShallow } from "zustand/shallow"; | ||||||
import type { | ||||||
|
@@ -30,12 +30,13 @@ export function useNodeGenerations({ | |||||
startGenerationRunner, | ||||||
createAndStartGenerationRunner, | ||||||
stopGenerationRunner: stopGenerationSystem, | ||||||
addGenerationRunner, | ||||||
} = useGenerationRunnerSystem(); | ||||||
const client = useGiselleEngine(); | ||||||
const { experimental_storage } = useFeatureFlag(); | ||||||
|
||||||
/** @todo fetch on server */ | ||||||
const { data } = useSWR( | ||||||
const { data, isLoading } = useSWR( | ||||||
{ | ||||||
api: "node-generations", | ||||||
origin, | ||||||
|
@@ -49,35 +50,33 @@ export function useNodeGenerations({ | |||||
revalidateOnReconnect: false, | ||||||
}, | ||||||
); | ||||||
|
||||||
useEffect(() => { | ||||||
if (isLoading || data === undefined) { | ||||||
return; | ||||||
} | ||||||
addGenerationRunner(data); | ||||||
}, [isLoading, data, addGenerationRunner]); | ||||||
|
||||||
const currentGeneration = useMemo<Generation>(() => { | ||||||
const fetchGenerations = data ?? []; | ||||||
const createdGenerations = generations.filter( | ||||||
(generation) => | ||||||
generation.context.operationNode.id === nodeId && | ||||||
generation.context.origin.type === origin.type && | ||||||
(origin.type === "studio" | ||||||
? generation.context.origin.type === "studio" && | ||||||
generation.context.origin.workspaceId === origin.workspaceId | ||||||
: generation.context.origin.type !== "studio" && | ||||||
generation.context.origin.actId === origin.actId), | ||||||
); | ||||||
// Deduplicate generations by filtering out fetched generations from created ones | ||||||
const deduplicatedCreatedGenerations = createdGenerations.filter( | ||||||
(created) => | ||||||
!fetchGenerations.some((fetched) => fetched.id === created.id), | ||||||
); | ||||||
// Filter out cancelled generations from both sources after deduplication | ||||||
const allGenerations = [ | ||||||
...fetchGenerations, | ||||||
...deduplicatedCreatedGenerations, | ||||||
] | ||||||
.filter((generation) => generation.status !== "cancelled") | ||||||
const filteredGenerations = generations | ||||||
.filter( | ||||||
(generation) => | ||||||
generation.status !== "cancelled" && | ||||||
generation.context.operationNode.id === nodeId && | ||||||
generation.context.origin.type === origin.type && | ||||||
(origin.type === "studio" | ||||||
? generation.context.origin.type === "studio" && | ||||||
generation.context.origin.workspaceId === origin.workspaceId | ||||||
: generation.context.origin.type !== "studio" && | ||||||
generation.context.origin.actId === origin.actId), | ||||||
) | ||||||
.sort( | ||||||
(a, b) => | ||||||
new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(), | ||||||
); | ||||||
return allGenerations[0]; | ||||||
}, [generations, data, nodeId, origin]); | ||||||
return filteredGenerations[0]; | ||||||
}, [generations, nodeId, origin]); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The dependency array is missing
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
|
||||||
const isGenerating = useMemo( | ||||||
() => | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,8 +24,12 @@ export const useGenerationStore = create<GenerationStore>((set) => ({ | |
addGenerationRunner: (generations) => | ||
set((state) => { | ||
const arr = Array.isArray(generations) ? generations : [generations]; | ||
const incomingIds = new Set(arr.map((g) => g.id)); | ||
const filteredExisting = state.generations.filter( | ||
(g) => !incomingIds.has(g.id), | ||
); | ||
return { | ||
generations: [...state.generations, ...arr], | ||
generations: [...filteredExisting, ...arr], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Local Generation Data Overwritten by ServerThe Additional Locations (1) |
||
}; | ||
}), | ||
updateGeneration: (generation) => | ||
|
Uh oh!
There was an error while loading. Please reload this page.