feat: add doc copilot context api (#10103)

### What Changed?
- Add graphql APIs.
- Provide context and session service in `AIProvider`.
- Rename the state from `embedding` to `processing`.
- Reafctor front-end session create, update and save logic.

Persist the document selected by the user:
[录屏2025-02-08 11.04.40.mov <span class="graphite__hidden">(uploaded via Graphite)</span> <img class="graphite__hidden" src="https://app.graphite.dev/api/v1/graphite/video/thumbnail/sJGviKxfE3Ap685cl5bj/195a85f2-43c4-4e49-88d9-6b5fc4f235ca.mov" />](https://app.graphite.dev/media/video/sJGviKxfE3Ap685cl5bj/195a85f2-43c4-4e49-88d9-6b5fc4f235ca.mov)
This commit is contained in:
akumatus
2025-02-12 08:33:06 +00:00
parent 53fdb1e8a5
commit 58fed5928b
21 changed files with 588 additions and 244 deletions

View File

@@ -36,12 +36,12 @@ class AddContextDocInput {
}
@InputType()
class RemoveContextFileInput {
class RemoveContextDocInput {
@Field(() => String)
contextId!: string;
@Field(() => String)
fileId!: string;
docId!: string;
}
@ObjectType('CopilotContext')
@@ -227,8 +227,8 @@ export class CopilotContextResolver {
})
@CallMetric('ai', 'context_doc_remove')
async removeContextDoc(
@Args({ name: 'options', type: () => RemoveContextFileInput })
options: RemoveContextFileInput
@Args({ name: 'options', type: () => RemoveContextDocInput })
options: RemoveContextDocInput
) {
const lockFlag = `${COPILOT_LOCKER}:context:${options.contextId}`;
await using lock = await this.mutex.acquire(lockFlag);
@@ -238,7 +238,7 @@ export class CopilotContextResolver {
const session = await this.context.get(options.contextId);
try {
return await session.removeDocRecord(options.fileId);
return await session.removeDocRecord(options.docId);
} catch (e: any) {
throw new CopilotFailedToModifyContext({
contextId: options.contextId,