Skip to content

fix: The form recall node cannot respond #2824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ui/src/api/type/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,12 @@ export class ChatManagement {
chatRecord.write()
}
}
static open(chatRecordId: string) {
const chatRecord = this.chatMessageContainer[chatRecordId]
if (chatRecord) {
chatRecord.open()
}
}
/**
* 等待所有数据输出完毕后 才会关闭流
* @param chatRecordId 对话记录id
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Review of Code

@@ -442,6 +442,12 @@ export class ChatManagement {
   chatRecord.write()
 }

+static open(chatRecordId: string) {
+  const chatRecord = this.chatMessageContainer[chatRecordId]
+  if (chatRecord) {
+    chatRecord.open()
+  }
+}
+
/**
 * 等待所有数据输出完毕后 才会关闭流
 * @param chatRecordId 对话记录id

Suggestions:

  • Ensure that this.chatMessageContainer is properly initialized before using it to avoid potential errors when accessing non-existent keys.
  • Add null checks around the chatMessageContainer access and ensure that all methods (write, open) are defined correctly in the ChatRecord interface or type definition to prevent runtime exceptions.

Optimizations

  • Consider moving the initialization of this.chatMessageContainer during the creation of ChatManagement instance instead of relying solely on static accessor properties like chatMessageContainer.

Alternative Initialization:

export class ChatManagement {
  private _chatMessageContainer: Record<string, any> = {}; // Assuming ChatRecord is a generic object

  constructor() {
    this._chatMessageContainer = {};
  }

// Rest of the code remains unchanged.

By making these changes, you can ensure better encapsulation and handle edge cases more gracefully.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<template>
<div class="item-content mb-16 lighter">

<template v-for="(answer_text, index) in answer_text_list" :key="index">
<div class="avatar mr-8" v-if="application.show_avatar">
<img v-if="application.avatar" :src="application.avatar" height="28px" width="28px" />
Expand Down Expand Up @@ -91,6 +90,7 @@ const chatMessage = (question: string, type: 'old' | 'new', other_params_data?:
if (type === 'old') {
add_answer_text_list(props.chatRecord.answer_text_list)
props.sendMessage(question, other_params_data, props.chatRecord)
props.chatManagement.open(props.chatRecord.id)
props.chatManagement.write(props.chatRecord.id)
} else {
props.sendMessage(question, other_params_data)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The provided code appears to be part of a Vue.js component that handles user input and chat management. Here's an analysis with potential suggestions:

Potential Issues:

  1. Duplicate Code: The add_answer_text_list function is called within both branches of the if (type === 'old') condition, which might be unnecessary.
  2. Unnecessary Condition: The else block can be simplified since similar logic applies when type !== 'old'.

Optimization Suggestions:

// Simplified chatMessage method
const chatMessage = async (
  question: string,
  type: 'old' | 'new',
  other_params_data?: Record<string, any>
): Promise<void> => {
  const messageData = await fetchApi('create-message', { question });
  
  // Handle old message type specifically
  if (type === 'old') {
    addAnswerTextList(messageData.answer_texts);
    handleChatRecordUpdate(messageData);
    notifyUser("New Message Added!");
    props.chatManagement.refresh();
  }
  
  // Standard message handling for non-old types
  const paramsWithId = { ...other_params_data, id: messageData.id };
  handleSubmitQuestion(question, paramsWithId);

  // Open conversation if applicable
  handleOpenConversation();

  // Write to log or database
  handleWriteToLogOrDatabase();
};

// Helper functions

function addAnswerTextList(answerTexts: string[]): void {
  for (let text of answerTexts) {
    store.commit('chat/add-answer-text-item', parseAnswerTextContent(text));
  }
}

// Ensure this function updates chat record state accordingly
function handleChatRecordUpdate(updatedRecord: ChatRecordData) {
  props.chatRecord.updateWith(updatedRecord); // Assuming an update method exists in the chatRecord object
}

function onSubmitQuestion(question: string, otherParamsData: Record<string, any>) {
  props.sendMessage(question, otherParamsData, props.chatRecord);
}

function handleOpenConversation() {
  props.chatManagement.open(props.chatRecord.id);
}

function handleWriteToLogOrDatabase() {
  writeMessageToDatabase(props.chatRecord.id);
}

Explanation of Changes:

  • Simplified Logic: Moved the common behavior (handleChatRecordUpdate, notifyUser, etc.) out of conditional blocks into separate helper functions for better readability and reusability.
  • Encapsulation: Encapsulated specific actions related to opening conversations and writing data into their own methods for ease of maintenance and reuse.
  • Assumptions:
    • If additional chat record states need updating, it assumes there’s an updateWith method on the props.chatRecord.
    • The writeMessageToDatabase function is assumed based on how chat interactions are handled elsewhere.

These changes aim to improve modularity, maintainability, and reduce redundancy while ensuring all necessary operations follow logical steps.

Expand Down