feat(server): deprecate blob id provide by client (#12991)

fix AI-287
This commit is contained in:
DarkSky
2025-07-03 11:45:34 +08:00
committed by GitHub
parent 4641b080f2
commit 2ae3c3e2cd
5 changed files with 17 additions and 23 deletions

View File

@@ -42,7 +42,7 @@ Generated by [AVA](https://avajs.dev).
[
{
blobId: 'fileId1',
blobId: 'Ip3vuwzubwJnOlzeKQ0Gc-daDcMc7EOYnIqypOyn4bs',
chunkSize: 0,
name: 'sample.pdf',
status: 'processing',

View File

@@ -1,3 +1,5 @@
import { createHash } from 'node:crypto';
import {
Args,
Context,
@@ -102,8 +104,9 @@ class AddContextFileInput {
@Field(() => String)
contextId!: string;
@Field(() => String)
blobId!: string;
// @TODO(@darkskygit): remove this after client lower then 0.22 has been disconnected
@Field(() => String, { nullable: true, deprecationReason: 'Never used' })
blobId!: string | undefined;
}
@InputType()
@@ -611,8 +614,9 @@ export class CopilotContextResolver {
if (!this.context.canEmbedding) {
throw new CopilotEmbeddingUnavailable();
}
const { contextId } = options;
const lockFlag = `${COPILOT_LOCKER}:context:${options.contextId}`;
const lockFlag = `${COPILOT_LOCKER}:context:${contextId}`;
await using lock = await this.mutex.acquire(lockFlag);
if (!lock) {
throw new TooManyRequest('Server is busy');
@@ -623,22 +627,15 @@ export class CopilotContextResolver {
throw new BlobQuotaExceeded();
}
const session = await this.context.get(options.contextId);
const session = await this.context.get(contextId);
try {
const file = await session.addFile(
options.blobId,
content.filename,
content.mimetype
);
const buffer = await readStream(content.createReadStream());
await this.storage.put(
user.id,
session.workspaceId,
options.blobId,
buffer
);
const blobId = createHash('sha256').update(buffer).digest('base64url');
const { filename, mimetype } = content;
await this.storage.put(user.id, session.workspaceId, blobId, buffer);
const file = await session.addFile(blobId, filename, mimetype);
await this.jobs.addFileEmbeddingQueue({
userId: user.id,
@@ -655,10 +652,7 @@ export class CopilotContextResolver {
if (e instanceof UserFriendlyError) {
throw e;
}
throw new CopilotFailedToModifyContext({
contextId: options.contextId,
message: e.message,
});
throw new CopilotFailedToModifyContext({ contextId, message: e.message });
}
}

View File

@@ -15,7 +15,7 @@ input AddContextDocInput {
}
input AddContextFileInput {
blobId: String!
blobId: String
contextId: String!
}