mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 13:25:12 +00:00
feat: improve context api (#10812)
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
export { CopilotContextDocJob } from './job';
|
||||
export { CopilotContextResolver, CopilotContextRootResolver } from './resolver';
|
||||
export { CopilotContextService } from './service';
|
||||
export { type ContextFile, ContextFileStatus } from './types';
|
||||
export {
|
||||
type ContextFile,
|
||||
ContextEmbedStatus as ContextFileStatus,
|
||||
} from './types';
|
||||
|
||||
@@ -41,8 +41,8 @@ import { CopilotContextDocJob } from './job';
|
||||
import { CopilotContextService } from './service';
|
||||
import {
|
||||
ContextDoc,
|
||||
ContextEmbedStatus,
|
||||
type ContextFile,
|
||||
ContextFileStatus,
|
||||
DocChunkSimilarity,
|
||||
FileChunkSimilarity,
|
||||
MAX_EMBEDDABLE_SIZE,
|
||||
@@ -94,13 +94,16 @@ export class CopilotContextType {
|
||||
workspaceId!: string;
|
||||
}
|
||||
|
||||
registerEnumType(ContextFileStatus, { name: 'ContextFileStatus' });
|
||||
registerEnumType(ContextEmbedStatus, { name: 'ContextEmbedStatus' });
|
||||
|
||||
@ObjectType()
|
||||
class CopilotContextDoc implements ContextDoc {
|
||||
@Field(() => ID)
|
||||
id!: string;
|
||||
|
||||
@Field(() => ContextEmbedStatus, { nullable: true })
|
||||
status!: ContextEmbedStatus | null;
|
||||
|
||||
@Field(() => SafeIntResolver)
|
||||
createdAt!: number;
|
||||
}
|
||||
@@ -116,8 +119,8 @@ class CopilotContextFile implements ContextFile {
|
||||
@Field(() => SafeIntResolver)
|
||||
chunkSize!: number;
|
||||
|
||||
@Field(() => ContextFileStatus)
|
||||
status!: ContextFileStatus;
|
||||
@Field(() => ContextEmbedStatus)
|
||||
status!: ContextEmbedStatus;
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
error!: string | null;
|
||||
|
||||
@@ -16,8 +16,8 @@ import { ContextSession } from './session';
|
||||
import {
|
||||
ContextConfig,
|
||||
ContextConfigSchema,
|
||||
ContextEmbedStatus,
|
||||
ContextFile,
|
||||
ContextFileStatus,
|
||||
EmbeddingClient,
|
||||
} from './types';
|
||||
import { checkEmbeddingAvailable } from './utils';
|
||||
@@ -173,7 +173,7 @@ export class CopilotContextService implements OnModuleInit {
|
||||
await context.saveFileRecord(fileId, file => ({
|
||||
...(file as ContextFile),
|
||||
chunkSize,
|
||||
status: ContextFileStatus.finished,
|
||||
status: ContextEmbedStatus.finished,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ export class CopilotContextService implements OnModuleInit {
|
||||
await context.saveFileRecord(fileId, file => ({
|
||||
...(file as ContextFile),
|
||||
error,
|
||||
status: ContextFileStatus.failed,
|
||||
status: ContextEmbedStatus.failed,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ import {
|
||||
ChunkSimilarity,
|
||||
ContextConfig,
|
||||
ContextDoc,
|
||||
ContextEmbedStatus,
|
||||
ContextFile,
|
||||
ContextFileStatus,
|
||||
ContextList,
|
||||
DocChunkSimilarity,
|
||||
EmbeddingClient,
|
||||
@@ -54,7 +54,7 @@ export class ContextSession implements AsyncDisposable {
|
||||
if (doc) {
|
||||
return doc;
|
||||
}
|
||||
const record = { id: docId, createdAt: Date.now() };
|
||||
const record = { id: docId, createdAt: Date.now(), status: null };
|
||||
this.config.docs.push(record);
|
||||
await this.save();
|
||||
return record;
|
||||
@@ -76,7 +76,7 @@ export class ContextSession implements AsyncDisposable {
|
||||
if (existsBlob) {
|
||||
// use exists file id if the blob exists
|
||||
// we assume that the file content pointed to by the same blobId is consistent.
|
||||
if (existsBlob.status === ContextFileStatus.finished) {
|
||||
if (existsBlob.status === ContextEmbedStatus.finished) {
|
||||
return existsBlob;
|
||||
}
|
||||
fileId = existsBlob.id;
|
||||
@@ -179,7 +179,7 @@ export class ContextSession implements AsyncDisposable {
|
||||
if (file) {
|
||||
Object.assign(file, cb({ ...file }));
|
||||
} else {
|
||||
const file = { id: fileId, status: ContextFileStatus.processing };
|
||||
const file = { id: fileId, status: ContextEmbedStatus.processing };
|
||||
files.push(cb(file));
|
||||
}
|
||||
await this.save(tx);
|
||||
|
||||
@@ -26,7 +26,7 @@ declare global {
|
||||
|
||||
export const MAX_EMBEDDABLE_SIZE = 50 * OneMB;
|
||||
|
||||
export enum ContextFileStatus {
|
||||
export enum ContextEmbedStatus {
|
||||
processing = 'processing',
|
||||
finished = 'finished',
|
||||
failed = 'failed',
|
||||
@@ -40,9 +40,9 @@ export const ContextConfigSchema = z.object({
|
||||
chunkSize: z.number(),
|
||||
name: z.string(),
|
||||
status: z.enum([
|
||||
ContextFileStatus.processing,
|
||||
ContextFileStatus.finished,
|
||||
ContextFileStatus.failed,
|
||||
ContextEmbedStatus.processing,
|
||||
ContextEmbedStatus.finished,
|
||||
ContextEmbedStatus.failed,
|
||||
]),
|
||||
error: z.string().nullable(),
|
||||
blobId: z.string(),
|
||||
@@ -52,6 +52,15 @@ export const ContextConfigSchema = z.object({
|
||||
docs: z
|
||||
.object({
|
||||
id: z.string(),
|
||||
// status for workspace doc embedding progress
|
||||
// only exists when the client submits the doc embedding task
|
||||
status: z
|
||||
.enum([
|
||||
ContextEmbedStatus.processing,
|
||||
ContextEmbedStatus.finished,
|
||||
ContextEmbedStatus.failed,
|
||||
])
|
||||
.nullable(),
|
||||
createdAt: z.number(),
|
||||
})
|
||||
.array(),
|
||||
|
||||
@@ -35,7 +35,7 @@ type ChatMessage {
|
||||
role: String!
|
||||
}
|
||||
|
||||
enum ContextFileStatus {
|
||||
enum ContextEmbedStatus {
|
||||
failed
|
||||
finished
|
||||
processing
|
||||
@@ -95,6 +95,7 @@ type CopilotContext {
|
||||
type CopilotContextDoc {
|
||||
createdAt: SafeInt!
|
||||
id: ID!
|
||||
status: ContextEmbedStatus
|
||||
}
|
||||
|
||||
type CopilotContextFile {
|
||||
@@ -104,7 +105,7 @@ type CopilotContextFile {
|
||||
error: String
|
||||
id: ID!
|
||||
name: String!
|
||||
status: ContextFileStatus!
|
||||
status: ContextEmbedStatus!
|
||||
}
|
||||
|
||||
type CopilotContextFileNotSupportedDataType {
|
||||
|
||||
Reference in New Issue
Block a user