2025-12-03 14:37:58 +08:00
|
|
|
import { NodeCollapsible } from '@/components/collapse';
|
2025-02-24 17:19:06 +08:00
|
|
|
import { IMessageNode } from '@/interfaces/database/flow';
|
2025-12-03 14:37:58 +08:00
|
|
|
import { cn } from '@/lib/utils';
|
2025-12-09 17:59:49 +08:00
|
|
|
import { useGetVariableLabelOrTypeByValue } from '@/pages/agent/hooks/use-get-begin-query';
|
2025-10-11 18:45:38 +08:00
|
|
|
import { NodeProps } from '@xyflow/react';
|
2025-02-24 17:19:06 +08:00
|
|
|
import classNames from 'classnames';
|
|
|
|
|
import { get } from 'lodash';
|
2025-05-29 11:10:45 +08:00
|
|
|
import { memo } from 'react';
|
2025-12-03 14:37:58 +08:00
|
|
|
import { LabelCard } from './card';
|
2025-10-11 18:45:38 +08:00
|
|
|
import { LeftEndHandle } from './handle';
|
2026-01-04 19:14:20 +08:00
|
|
|
import styles from './index.module.less';
|
2025-02-24 17:19:06 +08:00
|
|
|
import NodeHeader from './node-header';
|
2025-06-16 09:29:08 +08:00
|
|
|
import { NodeWrapper } from './node-wrapper';
|
|
|
|
|
import { ToolBar } from './toolbar';
|
2025-12-09 17:59:49 +08:00
|
|
|
import { VariableDisplay } from './variable-display';
|
2025-02-24 17:19:06 +08:00
|
|
|
|
2025-10-11 18:45:38 +08:00
|
|
|
function InnerMessageNode({ id, data, selected }: NodeProps<IMessageNode>) {
|
2025-12-03 14:37:58 +08:00
|
|
|
const messages: string[] = get(data, 'form.content', []);
|
2025-12-09 17:59:49 +08:00
|
|
|
const { getLabel } = useGetVariableLabelOrTypeByValue({ nodeId: id });
|
2025-02-24 17:19:06 +08:00
|
|
|
return (
|
2025-06-16 09:29:08 +08:00
|
|
|
<ToolBar selected={selected} id={id} label={data.label}>
|
2025-12-04 13:40:49 +08:00
|
|
|
<NodeWrapper selected={selected} id={id}>
|
2025-10-11 18:45:38 +08:00
|
|
|
<LeftEndHandle></LeftEndHandle>
|
2025-06-16 09:29:08 +08:00
|
|
|
<NodeHeader
|
|
|
|
|
id={id}
|
|
|
|
|
name={data.name}
|
|
|
|
|
label={data.label}
|
|
|
|
|
className={classNames({
|
|
|
|
|
[styles.nodeHeader]: messages.length > 0,
|
|
|
|
|
})}
|
|
|
|
|
></NodeHeader>
|
2025-12-03 14:37:58 +08:00
|
|
|
<section
|
|
|
|
|
className={cn('flex flex-col gap-2', styles.messageNodeContainer)}
|
|
|
|
|
>
|
|
|
|
|
<NodeCollapsible items={messages}>
|
|
|
|
|
{(x, idx) => (
|
|
|
|
|
<LabelCard key={idx} className="truncate">
|
2025-12-09 17:59:49 +08:00
|
|
|
<VariableDisplay content={x} getLabel={getLabel} />
|
2025-12-03 14:37:58 +08:00
|
|
|
</LabelCard>
|
|
|
|
|
)}
|
|
|
|
|
</NodeCollapsible>
|
|
|
|
|
</section>
|
2025-06-16 09:29:08 +08:00
|
|
|
</NodeWrapper>
|
|
|
|
|
</ToolBar>
|
2025-02-24 17:19:06 +08:00
|
|
|
);
|
|
|
|
|
}
|
2025-05-29 11:10:45 +08:00
|
|
|
|
|
|
|
|
export const MessageNode = memo(InnerMessageNode);
|