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: copilot blob process (#6612)

darkskygit28f2ff24b9b5
diff --git a/packages/backend/server/src/plugins/copilot/providers/openai.ts b/packages/backend/server/src/plugins/copilot/providers/openai.ts
index dc2ac8ae9d..c522120df7 100644
--- a/packages/backend/server/src/plugins/copilot/providers/openai.ts
+++ b/packages/backend/server/src/plugins/copilot/providers/openai.ts
@@ -113,8 +113,9 @@ export class OpenAIProvider
!m ||
// check content
typeof m.content !== 'string' ||
- !m.content ||
- !m.content.trim()
+ // content and attachments must exist at least one
+ ((!m.content || !m.content.trim()) &&
+ (!Array.isArray(m.attachments) || !m.attachments.length))
)
) {
throw new Error('Empty message content');
diff --git a/packages/backend/server/src/plugins/copilot/resolver.ts b/packages/backend/server/src/plugins/copilot/resolver.ts
index 222ba7900e..dfd1ded0f3 100644
--- a/packages/backend/server/src/plugins/copilot/resolver.ts
+++ b/packages/backend/server/src/plugins/copilot/resolver.ts
@@ -280,7 +280,10 @@ export class CopilotResolver {
options.attachments = options.attachments || [];
const { workspaceId } = session.config;
- for (const blob of await Promise.all(options.blobs)) {
+ const blobs = await Promise.all(options.blobs);
+ delete options.blobs;
+
+ for (const blob of blobs) {
const uploaded = await this.storage.handleUpload(user.id, blob);
const link = await this.storage.put(
user.id,
@@ -289,7 +292,6 @@ export class CopilotResolver {
uploaded.buffer
);
options.attachments.push(link);
- delete options.blobs;
}
}