fix: basic app crash by llm editor use the workflow context

This commit is contained in:
Joel
2026-02-09 15:19:52 +08:00
parent 2d6b30f3b8
commit b289e6a2b6

View File

@@ -16,6 +16,7 @@ import type {
VariableBlockType,
WorkflowVariableBlockType,
} from './types'
import type { Node as WorkflowNode } from '@/app/components/workflow/types'
import type { EventPayload } from '@/context/event-emitter'
import { CodeNode } from '@lexical/code'
import { LexicalComposer } from '@lexical/react/LexicalComposer'
@@ -34,6 +35,8 @@ import {
import * as React from 'react'
import { useEffect } from 'react'
import { Trans } from 'react-i18next'
import { WorkflowContext } from '@/app/components/workflow/context'
import { HooksStoreContext } from '@/app/components/workflow/hooks-store/provider'
import { FileReferenceNode } from '@/app/components/workflow/skill/editor/skill-editor/plugins/file-reference-block/node'
import { FilePreviewContextProvider } from '@/app/components/workflow/skill/editor/skill-editor/plugins/file-reference-block/preview-context'
import FileReferenceReplacementBlock from '@/app/components/workflow/skill/editor/skill-editor/plugins/file-reference-block/replacement-block'
@@ -153,6 +156,30 @@ const EnterCommandPlugin: FC<{ onEnter?: (event: KeyboardEvent) => void }> = ({
return null
}
type WorkflowAvailableNodesProps = {
nodeId?: string
isSupportSandbox?: boolean
children: (availableNodes: WorkflowNode[]) => React.ReactNode
}
const WorkflowAvailableNodes: FC<WorkflowAvailableNodesProps> = ({
nodeId,
isSupportSandbox,
children,
}) => {
const { getBeforeNodesInSameBranch } = useWorkflow()
const availableNodes = React.useMemo(
() => nodeId && isSupportSandbox ? getBeforeNodesInSameBranch(nodeId || '') : [],
[getBeforeNodesInSameBranch, isSupportSandbox, nodeId],
)
return (
<>
{children(availableNodes)}
</>
)
}
export type PromptEditorProps = {
instanceId?: string
nodeId?: string
@@ -185,7 +212,11 @@ export type PromptEditorProps = {
onEnter?: (event: KeyboardEvent) => void
}
const PromptEditor: FC<PromptEditorProps> = ({
type PromptEditorContentProps = PromptEditorProps & {
availableNodes: WorkflowNode[]
}
const PromptEditorContent: FC<PromptEditorContentProps> = ({
instanceId,
nodeId,
compact,
@@ -215,6 +246,7 @@ const PromptEditor: FC<PromptEditorProps> = ({
isSupportSandbox,
disableToolBlocks,
onEnter,
availableNodes,
}) => {
const { eventEmitter } = useEventEmitterContextContext()
const initialConfig = {
@@ -264,12 +296,6 @@ const PromptEditor: FC<PromptEditorProps> = ({
} as EventPayload)
}, [eventEmitter, historyBlock?.history])
const { getBeforeNodesInSameBranch } = useWorkflow()
const availableNodes = React.useMemo(
() => nodeId && isSupportSandbox ? getBeforeNodesInSameBranch(nodeId || '') : [],
[getBeforeNodesInSameBranch, isSupportSandbox, nodeId],
)
const toolBlockContextValue = React.useMemo(() => {
if (!onToolMetadataChange)
return null
@@ -491,4 +517,33 @@ const PromptEditor: FC<PromptEditorProps> = ({
)
}
const PromptEditor: FC<PromptEditorProps> = (props) => {
const workflowStore = React.useContext(WorkflowContext)
const hooksStore = React.useContext(HooksStoreContext)
const hasWorkflowContext = Boolean(workflowStore && hooksStore)
if (!hasWorkflowContext) {
return (
<PromptEditorContent
{...props}
availableNodes={[]}
/>
)
}
return (
<WorkflowAvailableNodes
nodeId={props.nodeId}
isSupportSandbox={props.isSupportSandbox}
>
{availableNodes => (
<PromptEditorContent
{...props}
availableNodes={availableNodes}
/>
)}
</WorkflowAvailableNodes>
)
}
export default PromptEditor