Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix: message attachment merge (#8498)

DarkSky075cedabf7f9
diff --git a/packages/backend/server/src/plugins/copilot/session.ts b/packages/backend/server/src/plugins/copilot/session.ts
index 604cffec5b..98482d88b4 100644
--- a/packages/backend/server/src/plugins/copilot/session.ts
+++ b/packages/backend/server/src/plugins/copilot/session.ts
@@ -149,7 +149,17 @@ export class ChatSession implements AsyncDisposable {
normalizedParams,
this.config.sessionId
);
- finished[0].attachments = firstMessage.attachments;
+
+ // attachments should be combined with the first user message
+ const firstUserMessage =
+ finished.find(m => m.role === 'user') || finished[0];
+ firstUserMessage.attachments = [
+ finished[0].attachments || [],
+ firstMessage.attachments || [],
+ ]
+ .flat()
+ .filter(v => !!v?.trim());
+
return finished;
}