feat: instruction template

feat/enchance-prompt-and-code-fe
Joel 7 months ago
parent 71d08d0580
commit ab45f3ce26

@ -276,6 +276,7 @@ const Prompt: FC<ISimplePromptInput> = ({
isShow={showAutomatic} isShow={showAutomatic}
onClose={showAutomaticFalse} onClose={showAutomaticFalse}
onFinished={handleAutomaticRes} onFinished={handleAutomaticRes}
currentPrompt={promptTemplate}
isBasicMode isBasicMode
/> />
)} )}

@ -144,7 +144,7 @@ const GetAutomaticRes: FC<IGetAutomaticResProps> = ({
} }
}, [t]) }, [t])
const { data: instructionTemplate } = useGenerateRuleTemplate(GeneratorType.prompt) const { data: instructionTemplate } = useGenerateRuleTemplate(GeneratorType.prompt, isBasicMode)
useEffect(() => { useEffect(() => {
if (!instruction && instructionTemplate) { if (!instruction && instructionTemplate) {
setInstruction(instructionTemplate.data) setInstruction(instructionTemplate.data)
@ -337,6 +337,7 @@ const GetAutomaticRes: FC<IGetAutomaticResProps> = ({
availableVars={[]} availableVars={[]}
availableNodes={[]} availableNodes={[]}
isShowCurrentBlock={!!currentPrompt} isShowCurrentBlock={!!currentPrompt}
isShowLastRunBlock={false}
/> />
) : ( ) : (
<InstructionEditorInWorkflow <InstructionEditorInWorkflow

@ -1,13 +1,13 @@
'use client' 'use client'
import type { FC } from 'react' import type { FC } from 'react'
import React, { useCallback } from 'react' import React, { useCallback, useMemo } from 'react'
import type { GeneratorType } from './types' import type { GeneratorType } from './types'
import type { ValueSelector, Var } from '@/app/components/workflow/types' import type { ValueSelector, Var } from '@/app/components/workflow/types'
import { VarType } from '@/app/components/workflow/types' import { VarType } from '@/app/components/workflow/types'
import useAvailableVarList from '@/app/components/workflow/nodes/_base/hooks/use-available-var-list' import useAvailableVarList from '@/app/components/workflow/nodes/_base/hooks/use-available-var-list'
import InstructionEditor from './instruction-editor' import InstructionEditor from './instruction-editor'
import { useWorkflowVariableType } from '@/app/components/workflow/hooks' import { useWorkflowVariableType } from '@/app/components/workflow/hooks'
import { useWorkflowStore } from '@/app/components/workflow/store' import { useStore, useWorkflowStore } from '@/app/components/workflow/store'
type Props = { type Props = {
nodeId: string nodeId: string
@ -27,7 +27,10 @@ const InstructionEditorInWorkflow: FC<Props> = ({
isShowCurrentBlock, isShowCurrentBlock,
}) => { }) => {
const workflowStore = useWorkflowStore() const workflowStore = useWorkflowStore()
const nodesWithInspectVars = useStore(s => s.nodesWithInspectVars)
const isShowLastRunBlock = useMemo(() => {
return !!nodesWithInspectVars.find(node => node.nodeId === nodeId)
}, [nodesWithInspectVars])
const filterVar = useCallback((payload: Var, selector: ValueSelector) => { const filterVar = useCallback((payload: Var, selector: ValueSelector) => {
const { nodesWithInspectVars } = workflowStore.getState() const { nodesWithInspectVars } = workflowStore.getState()
const nodeId = selector?.[0] const nodeId = selector?.[0]
@ -52,6 +55,7 @@ const InstructionEditorInWorkflow: FC<Props> = ({
availableNodes={availableNodes} availableNodes={availableNodes}
getVarType={getVarType} getVarType={getVarType}
isShowCurrentBlock={isShowCurrentBlock} isShowCurrentBlock={isShowCurrentBlock}
isShowLastRunBlock
/> />
) )
} }

@ -21,6 +21,7 @@ type Props = {
valueSelector: ValueSelector, valueSelector: ValueSelector,
}) => Type }) => Type
isShowCurrentBlock: boolean isShowCurrentBlock: boolean
isShowLastRunBlock: boolean
} }
const i18nPrefix = 'appDebug.generate' const i18nPrefix = 'appDebug.generate'
@ -34,6 +35,7 @@ const InstructionEditor: FC<Props> = ({
availableNodes, availableNodes,
getVarType = () => Type.string, getVarType = () => Type.string,
isShowCurrentBlock, isShowCurrentBlock,
isShowLastRunBlock,
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
const isBasicMode = !!getVarType const isBasicMode = !!getVarType
@ -88,7 +90,7 @@ const InstructionEditor: FC<Props> = ({
show: isCode, show: isCode,
}} }}
lastRunBlock={{ lastRunBlock={{
show: true, show: isShowLastRunBlock,
}} }}
onChange={onChange} onChange={onChange}
editable editable

@ -416,7 +416,7 @@ const VarReferenceVars: FC<Props> = ({
</div>)) </div>))
} }
</div> </div>
: <div className='pl-3 text-xs font-medium uppercase leading-[18px] text-gray-500'>{t('workflow.common.noVar')}</div>} : <div className='mt-2 pl-3 text-xs font-medium uppercase leading-[18px] text-gray-500'>{t('workflow.common.noVar')}</div>}
</> </>
) )
} }

@ -27,7 +27,7 @@ export const useAppDetail = (appID: string) => {
}) })
} }
export const useGenerateRuleTemplate = (type: GeneratorType) => { export const useGenerateRuleTemplate = (type: GeneratorType, disabled?: boolean) => {
return useQuery({ return useQuery({
queryKey: [NAME_SPACE, 'generate-rule-template', type], queryKey: [NAME_SPACE, 'generate-rule-template', type],
queryFn: () => post<{ data: string }>('instruction-generate/template', { queryFn: () => post<{ data: string }>('instruction-generate/template', {
@ -35,6 +35,7 @@ export const useGenerateRuleTemplate = (type: GeneratorType) => {
type, type,
}, },
}), }),
enabled: !disabled,
retry: 0, retry: 0,
}) })
} }

Loading…
Cancel
Save