feat: flux to logos
This commit is contained in:
@@ -9,6 +9,7 @@ import { useAbstractNode } from '@/lib/graph/abstractNode'
|
||||
import { useSyncConnectionStatus } from '@/lib/graph/nodeLifecycle'
|
||||
import { useCanvasStore, dispatchCanvasCommand } from '@/app/canvas/canvasStore'
|
||||
import { usePlatform } from '@/app/kosmos/KosmosContext'
|
||||
import { useOptionalRecollectionActions } from '@/app/recollections/RecollectionActionsContext'
|
||||
import { getDefaultDataForType, getNextNodeId } from '@/lib/graph/flowUtils'
|
||||
import { getDefaultStyle } from '@/lib/graph/nodeRegistry'
|
||||
import {
|
||||
@@ -132,6 +133,9 @@ export function useRenderingNodeState(
|
||||
nodesEdgesRef.current = { nodes, edges }
|
||||
|
||||
const { aiConnection } = usePlatform()
|
||||
const recollectionActions = useOptionalRecollectionActions()
|
||||
const recollectionActionsRef = useRef(recollectionActions)
|
||||
recollectionActionsRef.current = recollectionActions
|
||||
|
||||
const viewportWidth = data?.viewportWidth ?? DEFAULT_VIEWPORT_WIDTH
|
||||
const viewportHeight = data?.viewportHeight ?? DEFAULT_VIEWPORT_HEIGHT
|
||||
@@ -289,7 +293,18 @@ export function useRenderingNodeState(
|
||||
data?.lastRunSourceSignature != null && data.lastRunSourceSignature === sourceSignature
|
||||
const withinVisibilityGrace =
|
||||
mountTimeRef.current > 0 && Date.now() - mountTimeRef.current < VISIBILITY_GRACE_MS
|
||||
if (hasCache && (signatureUnchanged || withinVisibilityGrace)) return
|
||||
if (hasCache && (signatureUnchanged || withinVisibilityGrace)) {
|
||||
// Keep Logos cache in sync with node's cached output so the picker shows the latest when not re-running.
|
||||
const cached = (data?.cachedRenderedContent as string | undefined) ?? ''
|
||||
const isSvgContent = Boolean(cached.trim() && /<svg[\s>]/i.test(cached.trim()))
|
||||
recollectionActionsRef.current?.upsertRenderOutputToLogos?.({
|
||||
nodeId: id,
|
||||
label: id,
|
||||
type: isSvgContent ? 'image' : 'html',
|
||||
content: cached,
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
runIdRef.current += 1
|
||||
@@ -342,6 +357,16 @@ export function useRenderingNodeState(
|
||||
if (thisRunId !== runIdRef.current) return
|
||||
setRenderedContent(htmlOrSvg)
|
||||
setError(null)
|
||||
// Use the rendering node's id as the label (same as the node name shown in Flux header).
|
||||
// Infer image from SVG content so we never store 'html' for diagram output.
|
||||
const isSvgContent = Boolean(htmlOrSvg?.trim() && /<svg[\s>]/i.test(htmlOrSvg.trim()))
|
||||
const cacheType = typeRenderer.outputType === 'image' || isSvgContent ? 'image' : 'html'
|
||||
recollectionActionsRef.current?.upsertRenderOutputToLogos?.({
|
||||
nodeId: id,
|
||||
label: id,
|
||||
type: cacheType,
|
||||
content: htmlOrSvg ?? '',
|
||||
})
|
||||
const mode = outputModeRef.current
|
||||
const cachedOutputValue =
|
||||
mode === 'string'
|
||||
@@ -406,6 +431,8 @@ export function useRenderingNodeState(
|
||||
}
|
||||
// Content updates only when connected-node data changes (sourceSignature) or explicit run/viewport.
|
||||
// React Flow updates (position, selection, context ref churn) do not trigger re-runs.
|
||||
// recollectionActions is intentionally omitted: we use recollectionActionsRef so slot/context
|
||||
// identity changes (e.g. after setFluxSlot) do not re-trigger this effect and cause an auto-run loop.
|
||||
}, [
|
||||
id,
|
||||
srcId,
|
||||
|
||||
Reference in New Issue
Block a user