feat: improve context api (#10812)
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
export { CopilotContextDocJob } from './job';
|
export { CopilotContextDocJob } from './job';
|
||||||
export { CopilotContextResolver, CopilotContextRootResolver } from './resolver';
|
export { CopilotContextResolver, CopilotContextRootResolver } from './resolver';
|
||||||
export { CopilotContextService } from './service';
|
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 { CopilotContextService } from './service';
|
||||||
import {
|
import {
|
||||||
ContextDoc,
|
ContextDoc,
|
||||||
|
ContextEmbedStatus,
|
||||||
type ContextFile,
|
type ContextFile,
|
||||||
ContextFileStatus,
|
|
||||||
DocChunkSimilarity,
|
DocChunkSimilarity,
|
||||||
FileChunkSimilarity,
|
FileChunkSimilarity,
|
||||||
MAX_EMBEDDABLE_SIZE,
|
MAX_EMBEDDABLE_SIZE,
|
||||||
@@ -94,13 +94,16 @@ export class CopilotContextType {
|
|||||||
workspaceId!: string;
|
workspaceId!: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
registerEnumType(ContextFileStatus, { name: 'ContextFileStatus' });
|
registerEnumType(ContextEmbedStatus, { name: 'ContextEmbedStatus' });
|
||||||
|
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
class CopilotContextDoc implements ContextDoc {
|
class CopilotContextDoc implements ContextDoc {
|
||||||
@Field(() => ID)
|
@Field(() => ID)
|
||||||
id!: string;
|
id!: string;
|
||||||
|
|
||||||
|
@Field(() => ContextEmbedStatus, { nullable: true })
|
||||||
|
status!: ContextEmbedStatus | null;
|
||||||
|
|
||||||
@Field(() => SafeIntResolver)
|
@Field(() => SafeIntResolver)
|
||||||
createdAt!: number;
|
createdAt!: number;
|
||||||
}
|
}
|
||||||
@@ -116,8 +119,8 @@ class CopilotContextFile implements ContextFile {
|
|||||||
@Field(() => SafeIntResolver)
|
@Field(() => SafeIntResolver)
|
||||||
chunkSize!: number;
|
chunkSize!: number;
|
||||||
|
|
||||||
@Field(() => ContextFileStatus)
|
@Field(() => ContextEmbedStatus)
|
||||||
status!: ContextFileStatus;
|
status!: ContextEmbedStatus;
|
||||||
|
|
||||||
@Field(() => String, { nullable: true })
|
@Field(() => String, { nullable: true })
|
||||||
error!: string | null;
|
error!: string | null;
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ import { ContextSession } from './session';
|
|||||||
import {
|
import {
|
||||||
ContextConfig,
|
ContextConfig,
|
||||||
ContextConfigSchema,
|
ContextConfigSchema,
|
||||||
|
ContextEmbedStatus,
|
||||||
ContextFile,
|
ContextFile,
|
||||||
ContextFileStatus,
|
|
||||||
EmbeddingClient,
|
EmbeddingClient,
|
||||||
} from './types';
|
} from './types';
|
||||||
import { checkEmbeddingAvailable } from './utils';
|
import { checkEmbeddingAvailable } from './utils';
|
||||||
@@ -173,7 +173,7 @@ export class CopilotContextService implements OnModuleInit {
|
|||||||
await context.saveFileRecord(fileId, file => ({
|
await context.saveFileRecord(fileId, file => ({
|
||||||
...(file as ContextFile),
|
...(file as ContextFile),
|
||||||
chunkSize,
|
chunkSize,
|
||||||
status: ContextFileStatus.finished,
|
status: ContextEmbedStatus.finished,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,7 +187,7 @@ export class CopilotContextService implements OnModuleInit {
|
|||||||
await context.saveFileRecord(fileId, file => ({
|
await context.saveFileRecord(fileId, file => ({
|
||||||
...(file as ContextFile),
|
...(file as ContextFile),
|
||||||
error,
|
error,
|
||||||
status: ContextFileStatus.failed,
|
status: ContextEmbedStatus.failed,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import {
|
|||||||
ChunkSimilarity,
|
ChunkSimilarity,
|
||||||
ContextConfig,
|
ContextConfig,
|
||||||
ContextDoc,
|
ContextDoc,
|
||||||
|
ContextEmbedStatus,
|
||||||
ContextFile,
|
ContextFile,
|
||||||
ContextFileStatus,
|
|
||||||
ContextList,
|
ContextList,
|
||||||
DocChunkSimilarity,
|
DocChunkSimilarity,
|
||||||
EmbeddingClient,
|
EmbeddingClient,
|
||||||
@@ -54,7 +54,7 @@ export class ContextSession implements AsyncDisposable {
|
|||||||
if (doc) {
|
if (doc) {
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
const record = { id: docId, createdAt: Date.now() };
|
const record = { id: docId, createdAt: Date.now(), status: null };
|
||||||
this.config.docs.push(record);
|
this.config.docs.push(record);
|
||||||
await this.save();
|
await this.save();
|
||||||
return record;
|
return record;
|
||||||
@@ -76,7 +76,7 @@ export class ContextSession implements AsyncDisposable {
|
|||||||
if (existsBlob) {
|
if (existsBlob) {
|
||||||
// use exists file id if the blob exists
|
// use exists file id if the blob exists
|
||||||
// we assume that the file content pointed to by the same blobId is consistent.
|
// 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;
|
return existsBlob;
|
||||||
}
|
}
|
||||||
fileId = existsBlob.id;
|
fileId = existsBlob.id;
|
||||||
@@ -179,7 +179,7 @@ export class ContextSession implements AsyncDisposable {
|
|||||||
if (file) {
|
if (file) {
|
||||||
Object.assign(file, cb({ ...file }));
|
Object.assign(file, cb({ ...file }));
|
||||||
} else {
|
} else {
|
||||||
const file = { id: fileId, status: ContextFileStatus.processing };
|
const file = { id: fileId, status: ContextEmbedStatus.processing };
|
||||||
files.push(cb(file));
|
files.push(cb(file));
|
||||||
}
|
}
|
||||||
await this.save(tx);
|
await this.save(tx);
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ declare global {
|
|||||||
|
|
||||||
export const MAX_EMBEDDABLE_SIZE = 50 * OneMB;
|
export const MAX_EMBEDDABLE_SIZE = 50 * OneMB;
|
||||||
|
|
||||||
export enum ContextFileStatus {
|
export enum ContextEmbedStatus {
|
||||||
processing = 'processing',
|
processing = 'processing',
|
||||||
finished = 'finished',
|
finished = 'finished',
|
||||||
failed = 'failed',
|
failed = 'failed',
|
||||||
@@ -40,9 +40,9 @@ export const ContextConfigSchema = z.object({
|
|||||||
chunkSize: z.number(),
|
chunkSize: z.number(),
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
status: z.enum([
|
status: z.enum([
|
||||||
ContextFileStatus.processing,
|
ContextEmbedStatus.processing,
|
||||||
ContextFileStatus.finished,
|
ContextEmbedStatus.finished,
|
||||||
ContextFileStatus.failed,
|
ContextEmbedStatus.failed,
|
||||||
]),
|
]),
|
||||||
error: z.string().nullable(),
|
error: z.string().nullable(),
|
||||||
blobId: z.string(),
|
blobId: z.string(),
|
||||||
@@ -52,6 +52,15 @@ export const ContextConfigSchema = z.object({
|
|||||||
docs: z
|
docs: z
|
||||||
.object({
|
.object({
|
||||||
id: z.string(),
|
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(),
|
createdAt: z.number(),
|
||||||
})
|
})
|
||||||
.array(),
|
.array(),
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ type ChatMessage {
|
|||||||
role: String!
|
role: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ContextFileStatus {
|
enum ContextEmbedStatus {
|
||||||
failed
|
failed
|
||||||
finished
|
finished
|
||||||
processing
|
processing
|
||||||
@@ -95,6 +95,7 @@ type CopilotContext {
|
|||||||
type CopilotContextDoc {
|
type CopilotContextDoc {
|
||||||
createdAt: SafeInt!
|
createdAt: SafeInt!
|
||||||
id: ID!
|
id: ID!
|
||||||
|
status: ContextEmbedStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
type CopilotContextFile {
|
type CopilotContextFile {
|
||||||
@@ -104,7 +105,7 @@ type CopilotContextFile {
|
|||||||
error: String
|
error: String
|
||||||
id: ID!
|
id: ID!
|
||||||
name: String!
|
name: String!
|
||||||
status: ContextFileStatus!
|
status: ContextEmbedStatus!
|
||||||
}
|
}
|
||||||
|
|
||||||
type CopilotContextFileNotSupportedDataType {
|
type CopilotContextFileNotSupportedDataType {
|
||||||
|
|||||||
@@ -2,5 +2,6 @@ mutation addContextDoc($options: AddContextDocInput!) {
|
|||||||
addContextDoc(options: $options) {
|
addContextDoc(options: $options) {
|
||||||
id
|
id
|
||||||
createdAt
|
createdAt
|
||||||
|
status
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ query listContextDocsAndFiles($workspaceId: String!, $sessionId: String!, $conte
|
|||||||
contexts(sessionId: $sessionId, contextId: $contextId) {
|
contexts(sessionId: $sessionId, contextId: $contextId) {
|
||||||
docs {
|
docs {
|
||||||
id
|
id
|
||||||
|
status
|
||||||
createdAt
|
createdAt
|
||||||
}
|
}
|
||||||
files {
|
files {
|
||||||
|
|||||||
@@ -149,6 +149,7 @@ export const addContextDocMutation = {
|
|||||||
addContextDoc(options: $options) {
|
addContextDoc(options: $options) {
|
||||||
id
|
id
|
||||||
createdAt
|
createdAt
|
||||||
|
status
|
||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
};
|
};
|
||||||
@@ -240,6 +241,7 @@ export const listContextDocsAndFilesQuery = {
|
|||||||
contexts(sessionId: $sessionId, contextId: $contextId) {
|
contexts(sessionId: $sessionId, contextId: $contextId) {
|
||||||
docs {
|
docs {
|
||||||
id
|
id
|
||||||
|
status
|
||||||
createdAt
|
createdAt
|
||||||
}
|
}
|
||||||
files {
|
files {
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ export interface ChatMessage {
|
|||||||
role: Scalars['String']['output'];
|
role: Scalars['String']['output'];
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum ContextFileStatus {
|
export enum ContextEmbedStatus {
|
||||||
failed = 'failed',
|
failed = 'failed',
|
||||||
finished = 'finished',
|
finished = 'finished',
|
||||||
processing = 'processing',
|
processing = 'processing',
|
||||||
@@ -167,6 +167,7 @@ export interface CopilotContextDoc {
|
|||||||
__typename?: 'CopilotContextDoc';
|
__typename?: 'CopilotContextDoc';
|
||||||
createdAt: Scalars['SafeInt']['output'];
|
createdAt: Scalars['SafeInt']['output'];
|
||||||
id: Scalars['ID']['output'];
|
id: Scalars['ID']['output'];
|
||||||
|
status: Maybe<ContextEmbedStatus>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CopilotContextFile {
|
export interface CopilotContextFile {
|
||||||
@@ -177,7 +178,7 @@ export interface CopilotContextFile {
|
|||||||
error: Maybe<Scalars['String']['output']>;
|
error: Maybe<Scalars['String']['output']>;
|
||||||
id: Scalars['ID']['output'];
|
id: Scalars['ID']['output'];
|
||||||
name: Scalars['String']['output'];
|
name: Scalars['String']['output'];
|
||||||
status: ContextFileStatus;
|
status: ContextEmbedStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CopilotContextFileNotSupportedDataType {
|
export interface CopilotContextFileNotSupportedDataType {
|
||||||
@@ -2330,6 +2331,7 @@ export type AddContextDocMutation = {
|
|||||||
__typename?: 'CopilotContextDoc';
|
__typename?: 'CopilotContextDoc';
|
||||||
id: string;
|
id: string;
|
||||||
createdAt: number;
|
createdAt: number;
|
||||||
|
status: ContextEmbedStatus | null;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -2356,7 +2358,7 @@ export type AddContextFileMutation = {
|
|||||||
name: string;
|
name: string;
|
||||||
chunkSize: number;
|
chunkSize: number;
|
||||||
error: string | null;
|
error: string | null;
|
||||||
status: ContextFileStatus;
|
status: ContextEmbedStatus;
|
||||||
blobId: string;
|
blobId: string;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -2387,7 +2389,7 @@ export type ListContextFilesQuery = {
|
|||||||
blobId: string;
|
blobId: string;
|
||||||
chunkSize: number;
|
chunkSize: number;
|
||||||
error: string | null;
|
error: string | null;
|
||||||
status: ContextFileStatus;
|
status: ContextEmbedStatus;
|
||||||
createdAt: number;
|
createdAt: number;
|
||||||
}>;
|
}>;
|
||||||
}>;
|
}>;
|
||||||
@@ -2447,6 +2449,7 @@ export type ListContextDocsAndFilesQuery = {
|
|||||||
docs: Array<{
|
docs: Array<{
|
||||||
__typename?: 'CopilotContextDoc';
|
__typename?: 'CopilotContextDoc';
|
||||||
id: string;
|
id: string;
|
||||||
|
status: ContextEmbedStatus | null;
|
||||||
createdAt: number;
|
createdAt: number;
|
||||||
}>;
|
}>;
|
||||||
files: Array<{
|
files: Array<{
|
||||||
@@ -2456,7 +2459,7 @@ export type ListContextDocsAndFilesQuery = {
|
|||||||
blobId: string;
|
blobId: string;
|
||||||
chunkSize: number;
|
chunkSize: number;
|
||||||
error: string | null;
|
error: string | null;
|
||||||
status: ContextFileStatus;
|
status: ContextEmbedStatus;
|
||||||
createdAt: number;
|
createdAt: number;
|
||||||
}>;
|
}>;
|
||||||
}>;
|
}>;
|
||||||
|
|||||||
Reference in New Issue
Block a user