diff --git a/web/app/components/workflow/nodes/llm/use-config.ts b/web/app/components/workflow/nodes/llm/use-config.ts index 6922a8989f..f2928ec180 100644 --- a/web/app/components/workflow/nodes/llm/use-config.ts +++ b/web/app/components/workflow/nodes/llm/use-config.ts @@ -2,6 +2,7 @@ import type { Memory, PromptItem, PromptTemplateItem, ValueSelector, Var, Variab import type { LLMNodeType, StructuredOutput } from './types' import { produce } from 'immer' import { useCallback, useEffect, useRef, useState } from 'react' +import { useFeatures } from '@/app/components/base/features/hooks' import { checkHasContextBlock, checkHasHistoryBlock, checkHasQueryBlock } from '@/app/components/base/prompt-editor/constants' import { ModelFeatureEnum, @@ -23,6 +24,8 @@ import useAvailableVarList from '../_base/hooks/use-available-var-list' const useConfig = (id: string, payload: LLMNodeType) => { const { nodesReadOnly: readOnly } = useNodesReadOnly() const isChatMode = useIsChatMode() + const features = useFeatures(s => s.features) + const isSupportSandbox = !!features.sandbox?.enabled const defaultConfig = useStore(s => s.nodesDefaultConfigs)?.[payload.type] const [defaultRolePrefix, setDefaultRolePrefix] = useState<{ user: string, assistant: string }>({ user: '', assistant: '' }) @@ -35,17 +38,37 @@ const useConfig = (id: string, payload: LLMNodeType) => { const { deleteNodeInspectorVars } = useInspectVarsCrud() const setInputs = useCallback((newInputs: LLMNodeType) => { + let newPayload = { ...newInputs } if (newInputs.memory && !newInputs.memory.role_prefix) { - const newPayload = produce(newInputs, (draft) => { + newPayload = produce(newInputs, (draft) => { draft.memory!.role_prefix = defaultRolePrefix }) - doSetInputs(newPayload) - inputRef.current = newPayload - return } - doSetInputs(newInputs) - inputRef.current = newInputs - }, [doSetInputs, defaultRolePrefix]) + + // set skill=true for sandbox + if (isSupportSandbox) { + if (Array.isArray(newPayload.prompt_template) && newPayload.prompt_template.find(item => !item.skill)) { + newPayload = produce(newPayload, (draft) => { + draft.prompt_template = (draft.prompt_template as PromptItem[]).map((item) => { + return { + ...item, + skill: true, + } + }) + }) + } + else if (!Array.isArray(newPayload.prompt_template) && !newPayload.prompt_template.skill) { + newPayload = produce(newPayload, (draft) => { + draft.prompt_template = { + ...draft.prompt_template, + skill: true, + } + }) + } + } + doSetInputs(newPayload) + inputRef.current = newPayload + }, [doSetInputs, defaultRolePrefix, isSupportSandbox]) // model const model = inputs.model diff --git a/web/app/components/workflow/types.ts b/web/app/components/workflow/types.ts index fb757753ab..52ec596fef 100644 --- a/web/app/components/workflow/types.ts +++ b/web/app/components/workflow/types.ts @@ -1,3 +1,4 @@ +/* eslint-disable ts/no-explicit-any */ import type { Edge as ReactFlowEdge, Node as ReactFlowNode, @@ -255,11 +256,15 @@ export type PromptItem = { text: string edition_type?: EditionType jinja2_text?: string + skill?: boolean + metadata?: Record } export type PromptMessageContext = { id?: string $context: ValueSelector + skill?: boolean + metadata?: Record } export type PromptTemplateItem = PromptItem | PromptMessageContext diff --git a/web/eslint-suppressions.json b/web/eslint-suppressions.json index 24b29129cb..4e0c4da489 100644 --- a/web/eslint-suppressions.json +++ b/web/eslint-suppressions.json @@ -4005,9 +4005,6 @@ "app/components/workflow/types.ts": { "ts/no-empty-object-type": { "count": 3 - }, - "ts/no-explicit-any": { - "count": 8 } }, "app/components/workflow/update-dsl-modal.tsx": {