64 lines
2.0 KiB
TypeScript
64 lines
2.0 KiB
TypeScript
import { useEffect, useRef, type ComponentProps } from "react";
|
|
|
|
import { InputBox } from "@/components/workspace/input-box";
|
|
import { usePromptInputController } from "@/components/ai-elements/prompt-input";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
type PositionAgentInputProps = ComponentProps<typeof InputBox> & {
|
|
/** Stable node/builtin key used to restore the matching SQL-backed draft. */
|
|
draftKey?: string;
|
|
draftValue?: string;
|
|
onDraftChange?: (value: string) => void;
|
|
};
|
|
|
|
/**
|
|
* 岗位会商的岗位智能体输入框。
|
|
*
|
|
* 目前保留 InputBox 的完整交互能力;后续本页面需要独立调整视觉或工具栏时,
|
|
* 只改这个组件即可,不会影响普通对话、工作区或其他业务页面。
|
|
*/
|
|
export function PositionAgentInput({
|
|
className,
|
|
draftKey = "",
|
|
draftValue = "",
|
|
onDraftChange,
|
|
...props
|
|
}: PositionAgentInputProps) {
|
|
const { textInput } = usePromptInputController();
|
|
const activeDraftKeyRef = useRef("");
|
|
const restoringValueRef = useRef<string | null>(null);
|
|
const textInputRef = useRef(textInput);
|
|
textInputRef.current = textInput;
|
|
|
|
useEffect(() => {
|
|
activeDraftKeyRef.current = draftKey;
|
|
if (textInputRef.current.value !== draftValue) {
|
|
restoringValueRef.current = draftValue;
|
|
textInputRef.current.setInput(draftValue);
|
|
} else {
|
|
restoringValueRef.current = null;
|
|
}
|
|
}, [draftKey, draftValue]);
|
|
|
|
useEffect(() => {
|
|
if (activeDraftKeyRef.current !== draftKey) return;
|
|
if (restoringValueRef.current !== null) {
|
|
if (textInput.value === restoringValueRef.current) {
|
|
restoringValueRef.current = null;
|
|
}
|
|
return;
|
|
}
|
|
onDraftChange?.(textInput.value);
|
|
}, [draftKey, onDraftChange, textInput.value]);
|
|
|
|
// Keep the page-specific class on the wrapper rather than adding a variant
|
|
// to InputBox. Node chat and built-in chat can evolve together while every
|
|
// other workspace keeps the global composer untouched.
|
|
return (
|
|
<InputBox
|
|
{...props}
|
|
className={cn("position-roundtable-agent-input w-full", className)}
|
|
/>
|
|
);
|
|
}
|