Skip to content

Revert "fix(web): prompt editor"#906

Merged
shuqinzhao merged 1 commit intorelease/v0.3.0from
fix/v0.3.0_zy
Apr 15, 2026
Merged

Revert "fix(web): prompt editor"#906
shuqinzhao merged 1 commit intorelease/v0.3.0from
fix/v0.3.0_zy

Conversation

@shuqinzhao
Copy link
Copy Markdown
Collaborator

@shuqinzhao shuqinzhao commented Apr 15, 2026

This reverts commit 71e5b65.

Summary by Sourcery

用更简单的「聊天列表 + 编辑器」流程替换自定义提示词聊天面板集成,并调整提示词编辑器的滚动和布局行为。

新功能:

  • 使用共享的 ChatContent 组件进行提示词会话的就地聊天列表渲染,替代专用的提示词聊天面板。

改进:

  • 简化 lexical 编辑器 API,将 height 属性改为数值类型,并依赖启用 overflow 的编辑器根节点来处理滚动。
  • 精简提示词流式逻辑,移除 hasPrompt/isStreaming 标志,仅通过表单状态和 appendText 驱动编辑器,并启用自动滚动。
  • 使提示词和 AI 提示词模态框的布局和高度与新的聊天和编辑器结构保持一致。

杂务:

  • 移除 PromptChatPanel 组件,并将其使用场景迁移到共享的 ChatContent 组件上。
Original summary in English

Summary by Sourcery

Replace the custom prompt chat panel integration with a simpler chat list + editor flow and adjust the prompt editor’s scrolling and layout behavior.

New Features:

  • Introduce in-place chat list rendering for prompt conversations using a shared ChatContent component instead of a dedicated prompt chat panel.

Enhancements:

  • Simplify the lexical editor API by changing the height prop to a numeric value and relying on the editor root for scrolling with overflow enabled.
  • Streamline prompt streaming logic by removing hasPrompt/isStreaming flags and driving the editor purely from form state and appendText with auto-scroll.
  • Align prompt and AI prompt modal layouts and heights with the new chat and editor structure.

Chores:

  • Remove the PromptChatPanel component and migrate its usages to the shared ChatContent component.

@shuqinzhao shuqinzhao merged commit e0d7a5a into release/v0.3.0 Apr 15, 2026
1 check passed
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Apr 15, 2026

审阅者指南

回滚之前的流式提示词编辑器行为和面板组件,改为更简单、可滚动的 Lexical 编辑器和通用的 ChatContent 列表,并在 Prompt 和 AiPromptModal 中清理相关的状态和 ref。

SSE 流式写入编辑器和聊天列表的时序图

sequenceDiagram
  actor User
  participant Prompt
  participant SSEClient
  participant Backend
  participant Editor as EditorRef
  participant Chat as ChatContent

  User->>Prompt: Click send(message)
  Prompt->>Backend: createPromptSessions()
  Backend-->>Prompt: sessionId
  Prompt->>Backend: sendPrompt(sessionId, message)
  Backend-->>SSEClient: SSE stream

  loop SSE events
    SSEClient-->>Prompt: handleStreamMessage(data[])
    Prompt->>Prompt: for each item in data
    alt event == start
      Prompt->>Prompt: currentPromptValueRef = ""
      Prompt->>Editor: clear()
    else event == message (content)
      Prompt->>Prompt: currentPromptValueRef += content
      Prompt->>Editor: appendText(content)
      Prompt->>Editor: scrollToBottom()
    end
    alt event == message (desc)
      Prompt->>Prompt: chatList.push({role: assistant, content: desc})
      Prompt->>Chat: re-render with new data
    end
    alt event == message (variables)
      Prompt->>Prompt: setVariables(variables)
    end
    alt event == end
      Prompt->>Prompt: loading = false
      Prompt->>Prompt: form.current_prompt = currentPromptValueRef
    end
  end
Loading

回滚后的提示词编辑器和聊天组件类图

classDiagram
  class LexicalEditorProps {
    +string value
    +string placeholder
    +function onChange(value)
    +number height
    +boolean disabled
  }

  class EditorRef {
    +function setContent(value)
    +function appendText(text)
    +function clear()
    +function scrollToBottom()
  }

  class EditorContent {
    +ReactRef editorRef
    +function appendText(text)
    +function scrollToBottom()
  }

  class Editor {
    +LexicalEditorProps props
    +EditorRef ref
  }

  class ChatItem {
    +string role
    +string content
  }

  class ChatContent {
    +ChatItem[] data
    +boolean streamLoading
    +string labelPosition
    +string classNames
    +string contentClassNames
    +ReactNode empty
    +function labelFormat(item)
  }

  class PromptChatPanel {
    <<removed>>
    +function append(item)
    +function clear()
  }

  class Prompt {
    -boolean loading
    -FormInstance form
    -ChatItem[] chatList
    -string[] variables
    -string promptSession
    -PromptVariableModalRef aiPromptVariableModalRef
    -PromptSaveModalRef promptSaveModalRef
    -EditorRef editorRef
    -string currentPromptValueRef
    -HistoryItem editVo
    -function handleSend()
    -function handleRefresh()
    -function updateSession()
  }

  class AiPromptModal {
    -boolean visible
    -boolean loading
    -FormInstance form
    -ChatItem[] chatList
    -string[] variables
    -string promptSession
    -AiPromptVariableModalRef aiPromptVariableModalRef
    -EditorRef editorRef
    -string currentPromptValueRef
    -function handleOpen(initialValue)
    -function handleClose()
    -function handleSend()
  }

  Editor o-- LexicalEditorProps
  EditorContent ..|> EditorRef
  Prompt --> EditorRef
  Prompt --> ChatContent
  Prompt --> ChatItem
  AiPromptModal --> EditorRef
  AiPromptModal --> ChatContent
  AiPromptModal --> ChatItem
  ChatContent --> ChatItem
  PromptChatPanel <|.. ChatContent
Loading

文件级变更

Change Details Files
简化了 Lexical 编辑器容器和滚动行为,修改 height 属性类型,并使用编辑器根元素进行滚动控制。
  • 将 LexicalEditorProps.height 的类型从 string 改为 number,并移除其在外层 wrapper div className 中的使用。
  • 移除了基于 scrollRef 的自定义滚动管理、pointerdown 监听器以及针对 appendText 的 requestAnimationFrame 批处理逻辑。
  • 重新实现 appendText,使其同步地将文本节点追加到最后一段落,如有需要则创建新段落。
  • 更新 scrollToBottom,使其滚动 Lexical 编辑器根元素,而不是外部滚动容器。
  • 调整 ContentEditable 的 class,使其包含内部的 overflow-auto,并移除依赖高度的 wrapper 样式。
web/src/views/ApplicationConfig/components/Editor/index.tsx
在 Prompt 页面中用 ChatContent 替换 PromptChatPanel 的使用,并简化提示词流式和编辑器状态处理。
  • 引入 chatList 状态来存储聊天消息,而不是依赖 PromptChatPanel 的 ref API。
  • 更新 SSE 流式处理逻辑,将用户与助手消息追加到 chatList,并在追加内容后调用 editorRef.scrollToBottom。
  • 移除 isStreamingRef 和 hasPrompt 标志,始终将 Editor 的 onChange 直接绑定到表单值。
  • 简化提示词刷新和编辑逻辑,通过清空 chatList 并移除对 PromptChatPanel.clear 的调用。
  • 重构主布局,根据 current_prompt 条件渲染 Editor 或 Empty 占位,同时调整与高度相关的 classNames。
web/src/views/Prompt/index.tsx
重构 AiPromptModal,使用 ChatContent 和更简单的编辑器可见性模型,替代 PromptChatPanel 和流式标志位。
  • 新增 chatList 状态来保存会话条目,并移除 PromptChatPanel 的 ref 以及 hasPrompt/isStreamingRef 标志。
  • 在模态框关闭和发起新请求时,通过重置 chatList 代替调用 PromptChatPanel.clear()。
  • 更新 SSE 流式逻辑,将消息追加到 chatList、调用 editorRef.scrollToBottom,并始终通过 form 同步 current_prompt,而不再依赖流式状态判断。
  • 调整布局和尺寸:移除固定表单高度,使用 Tailwind 工具类修改聊天区域/编辑器高度,并始终将 Editor 包裹在 Form.Item 中,同时根据 current_prompt 条件渲染。
  • 用 ChatContent 替换 PromptChatPanel,并相应连接 data、label 格式化和 empty 状态等 props。
web/src/views/ApplicationConfig/components/AiPromptModal.tsx
移除专用的 PromptChatPanel 组件,统一使用通用的 ChatContent 组件。
  • 从 Chat 组件目录中删除 PromptChatPanel 实现文件。
  • 更新所有引用,改为使用 ChatContent,并提供等价的 data、label 和 empty 状态 props。
web/src/components/Chat/PromptChatPanel.tsx

提示与命令

与 Sourcery 交互

  • 触发新审查: 在 pull request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub issue: 回复 Sourcery 的审查评论,要求从该评论创建一个 issue。你也可以直接回复审查评论 @sourcery-ai issue 来基于该评论创建 issue。
  • 生成 pull request 标题: 在 pull request 标题中任意位置写上 @sourcery-ai 即可随时生成标题。你也可以在 pull request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 pull request 摘要: 在 pull request 正文任意位置写上 @sourcery-ai summary,即可在该位置生成 PR 摘要。你也可以在 pull request 中评论 @sourcery-ai summary 来在任意时间(重新)生成摘要。
  • 生成审阅者指南: 在 pull request 中评论 @sourcery-ai guide,即可在任意时间(重新)生成审阅者指南。
  • 一次性解决所有 Sourcery 评论: 在 pull request 中评论 @sourcery-ai resolve,即可解决所有 Sourcery 评论。如果你已经处理完所有评论且不想再看到它们,这会很有用。
  • 忽略所有 Sourcery 审查: 在 pull request 中评论 @sourcery-ai dismiss,即可忽略所有现有的 Sourcery 审查。尤其适用于你想从头开始一次新审查的情况——别忘了再评论 @sourcery-ai review 来触发新的审查!

自定义你的体验

访问你的 dashboard 来:

  • 启用或禁用诸如 Sourcery 自动生成的 pull request 摘要、审阅者指南等审查功能。
  • 修改审查语言。
  • 添加、删除或编辑自定义审查说明。
  • 调整其他审查设置。

获取帮助

Original review guide in English

Reviewer's Guide

Reverts the previous streaming prompt editor behavior and panel component in favor of a simpler, scrollable Lexical editor and a generic ChatContent list, while cleaning up related state and refs in Prompt and AiPromptModal.

Sequence diagram for SSE streaming to editor and chat list

sequenceDiagram
  actor User
  participant Prompt
  participant SSEClient
  participant Backend
  participant Editor as EditorRef
  participant Chat as ChatContent

  User->>Prompt: Click send(message)
  Prompt->>Backend: createPromptSessions()
  Backend-->>Prompt: sessionId
  Prompt->>Backend: sendPrompt(sessionId, message)
  Backend-->>SSEClient: SSE stream

  loop SSE events
    SSEClient-->>Prompt: handleStreamMessage(data[])
    Prompt->>Prompt: for each item in data
    alt event == start
      Prompt->>Prompt: currentPromptValueRef = ""
      Prompt->>Editor: clear()
    else event == message (content)
      Prompt->>Prompt: currentPromptValueRef += content
      Prompt->>Editor: appendText(content)
      Prompt->>Editor: scrollToBottom()
    end
    alt event == message (desc)
      Prompt->>Prompt: chatList.push({role: assistant, content: desc})
      Prompt->>Chat: re-render with new data
    end
    alt event == message (variables)
      Prompt->>Prompt: setVariables(variables)
    end
    alt event == end
      Prompt->>Prompt: loading = false
      Prompt->>Prompt: form.current_prompt = currentPromptValueRef
    end
  end
Loading

Class diagram for reverted prompt editor and chat components

classDiagram
  class LexicalEditorProps {
    +string value
    +string placeholder
    +function onChange(value)
    +number height
    +boolean disabled
  }

  class EditorRef {
    +function setContent(value)
    +function appendText(text)
    +function clear()
    +function scrollToBottom()
  }

  class EditorContent {
    +ReactRef editorRef
    +function appendText(text)
    +function scrollToBottom()
  }

  class Editor {
    +LexicalEditorProps props
    +EditorRef ref
  }

  class ChatItem {
    +string role
    +string content
  }

  class ChatContent {
    +ChatItem[] data
    +boolean streamLoading
    +string labelPosition
    +string classNames
    +string contentClassNames
    +ReactNode empty
    +function labelFormat(item)
  }

  class PromptChatPanel {
    <<removed>>
    +function append(item)
    +function clear()
  }

  class Prompt {
    -boolean loading
    -FormInstance form
    -ChatItem[] chatList
    -string[] variables
    -string promptSession
    -PromptVariableModalRef aiPromptVariableModalRef
    -PromptSaveModalRef promptSaveModalRef
    -EditorRef editorRef
    -string currentPromptValueRef
    -HistoryItem editVo
    -function handleSend()
    -function handleRefresh()
    -function updateSession()
  }

  class AiPromptModal {
    -boolean visible
    -boolean loading
    -FormInstance form
    -ChatItem[] chatList
    -string[] variables
    -string promptSession
    -AiPromptVariableModalRef aiPromptVariableModalRef
    -EditorRef editorRef
    -string currentPromptValueRef
    -function handleOpen(initialValue)
    -function handleClose()
    -function handleSend()
  }

  Editor o-- LexicalEditorProps
  EditorContent ..|> EditorRef
  Prompt --> EditorRef
  Prompt --> ChatContent
  Prompt --> ChatItem
  AiPromptModal --> EditorRef
  AiPromptModal --> ChatContent
  AiPromptModal --> ChatItem
  ChatContent --> ChatItem
  PromptChatPanel <|.. ChatContent
Loading

File-Level Changes

Change Details Files
Simplified Lexical editor container and scrolling behavior, changing height prop type and using the editor root element for scroll control.
  • Changed LexicalEditorProps.height type from string to number and removed its usage in the wrapper div className.
  • Removed custom scrollRef-based scroll management, pointerdown listeners, and requestAnimationFrame batching for appendText.
  • Reimplemented appendText to synchronously append text nodes to the last paragraph or create a new one if needed.
  • Updated scrollToBottom to scroll the Lexical editor root element instead of an outer scroll container.
  • Adjusted ContentEditable classes to include internal overflow-auto and removed height-dependent wrapper styling.
web/src/views/ApplicationConfig/components/Editor/index.tsx
Replaced PromptChatPanel usage with ChatContent and simplified prompt streaming and editor state handling in the Prompt page.
  • Introduced chatList state to store chat messages instead of using PromptChatPanel ref APIs.
  • Updated SSE streaming handlers to append user and assistant messages to chatList and to call editorRef.scrollToBottom after appending content.
  • Removed isStreamingRef and hasPrompt flags, always binding Editor onChange directly to the form value.
  • Simplified prompt refresh and edit handling by clearing chatList and removing PromptChatPanel clear calls.
  • Refactored the main layout to conditionally render Editor vs an Empty placeholder based on current_prompt while adjusting height-related classNames.
web/src/views/Prompt/index.tsx
Refactored AiPromptModal to use ChatContent and a simpler editor visibility model instead of PromptChatPanel and streaming flags.
  • Added chatList state to hold conversation items and removed PromptChatPanel ref and hasPrompt/isStreamingRef flags.
  • On modal close and new requests, reset chatList instead of calling PromptChatPanel.clear().
  • Updated SSE streaming logic to append to chatList, call editorRef.scrollToBottom, and always sync current_prompt via form without guarding on streaming state.
  • Adjusted layout and sizing: removed fixed form height, changed chat area/editor heights to Tailwind utility classes, and always wrapped Editor in Form.Item with conditional rendering based on current_prompt.
  • Replaced PromptChatPanel with ChatContent, wiring data, label formatting, and empty-state props accordingly.
web/src/views/ApplicationConfig/components/AiPromptModal.tsx
Removed the dedicated PromptChatPanel component in favor of the generic ChatContent component.
  • Deleted PromptChatPanel implementation file from the Chat components directory.
  • Updated all references to use ChatContent with equivalent props for data, labels, and empty states.
web/src/components/Chat/PromptChatPanel.tsx

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@shuqinzhao shuqinzhao deleted the fix/v0.3.0_zy branch April 15, 2026 06:51
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我在这里给出一些整体性的反馈:

  • LexicalEditorProps 中的 height 属性已经改回为 number 类型,但在 EditorContent 中已经不再被使用;建议将其从该接口以及所有调用方中移除,以避免无用属性和潜在的困惑。
  • 代码里还残留了几处 console.log 语句(例如 Prompt 中的 updateSession、以及 AiPromptModal 中打印 values 的日志),看起来像是调试遗留,应在合并前移除。
提供给 AI Agent 的提示
Please address the comments from this code review:

## Overall Comments
- The `height` prop in `LexicalEditorProps` has been changed back to `number` but is no longer used anywhere in `EditorContent`; consider removing it from the interface and any callers to avoid dead props and confusion.
- There are a couple of leftover `console.log` statements (e.g., `updateSession` in `Prompt` and the `values` log in `AiPromptModal`) that look like debugging artifacts and should be removed before merging.

Sourcery 对开源项目免费——如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈来改进之后的评审。
Original comment in English

Hey - I've left some high level feedback:

  • The height prop in LexicalEditorProps has been changed back to number but is no longer used anywhere in EditorContent; consider removing it from the interface and any callers to avoid dead props and confusion.
  • There are a couple of leftover console.log statements (e.g., updateSession in Prompt and the values log in AiPromptModal) that look like debugging artifacts and should be removed before merging.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `height` prop in `LexicalEditorProps` has been changed back to `number` but is no longer used anywhere in `EditorContent`; consider removing it from the interface and any callers to avoid dead props and confusion.
- There are a couple of leftover `console.log` statements (e.g., `updateSession` in `Prompt` and the `values` log in `AiPromptModal`) that look like debugging artifacts and should be removed before merging.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant