Files
ragflow/web/src/pages/agent/form/agent-form/use-build-prompt-options.ts
balibabu 70ffe2b4e8 Feat: The bottom anchor of the agent node is only displayed when there is a downstream node #9869 (#10611)
### What problem does this PR solve?

Feat: The bottom anchor of the agent node is only displayed when there
is a downstream node #9869

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
2025-10-16 17:47:55 +08:00

45 lines
1.1 KiB
TypeScript

import { useFetchPrompt } from '@/hooks/use-agent-request';
import { Edge } from '@xyflow/react';
import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { hasSubAgentOrTool } from '../../utils';
export const PromptIdentity = 'RAGFlow-Prompt';
function wrapPromptWithTag(text: string, tag: string) {
const capitalTag = tag.toUpperCase();
return `<${capitalTag}>
${text}
</${capitalTag}>`;
}
export function useBuildPromptExtraPromptOptions(
edges: Edge[],
nodeId?: string,
) {
const { data: prompts } = useFetchPrompt();
const { t } = useTranslation();
const has = hasSubAgentOrTool(edges, nodeId);
const options = useMemo(() => {
return Object.entries(prompts || {})
.map(([key, value]) => ({
label: key,
value: wrapPromptWithTag(value, key),
icon: null,
}))
.filter((x) => {
if (!has) {
return x.label === 'citation_guidelines';
}
return true;
});
}, [has, prompts]);
const extraOptions = [
{ label: PromptIdentity, title: t('flow.frameworkPrompts'), options },
];
return { extraOptions };
}