Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

991 B
Raw Blame
'use client';

import { memo, useCallback } from 'react';

import PromptTransformAction from '@/features/PromptTransform/PromptTransformAction';

import { useChatInputStore } from '../../store';
import { ChatInputAction } from '../components/ChatInputAction';

const PromptTransform = memo(() => {
  const [editor, markdownContent] = useChatInputStore((s) => [s.editor, s.markdownContent]);

  const onPromptChange = useCallback(
    (prompt: string) => {
      if (!editor) return;
      // `keepHistory` prevents setDocument from wiping the undo/redo stacks.
      editor.setDocument('markdown', prompt, { keepHistory: true });
    },
    [editor],
  );

  // Image mode expands vague inputs; text mode forbids expansion.
  return (
    <PromptTransformAction
      ActionComponent={ChatInputAction}
      mode={'image'}
      prompt={markdownContent}
      onPromptChange={onPromptChange}
    />
  );
});

PromptTransform.displayName = 'PromptTransform';

export default PromptTransform;