mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
refactor(core): get copilot sessions api (#10168)
Fix issue [BS-2575](https://linear.app/affine-design/issue/BS-2575). ### What Changed? - Refactor `getCopilotSessions` api. - Add `docId` parameter. - Add `action` parameter.
This commit is contained in:
@@ -136,15 +136,23 @@ export class CopilotClient {
|
||||
}
|
||||
}
|
||||
|
||||
async getSessions(workspaceId: string) {
|
||||
async getSessionIds(
|
||||
workspaceId: string,
|
||||
docId?: string,
|
||||
options?: RequestOptions<
|
||||
typeof getCopilotSessionsQuery
|
||||
>['variables']['options']
|
||||
) {
|
||||
try {
|
||||
const res = await this.gql({
|
||||
query: getCopilotSessionsQuery,
|
||||
variables: {
|
||||
workspaceId,
|
||||
docId,
|
||||
options,
|
||||
},
|
||||
});
|
||||
return res.currentUser?.copilot;
|
||||
return res.currentUser?.copilot?.sessionIds;
|
||||
} catch (err) {
|
||||
throw resolveError(err);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { AIProvider } from '@affine/core/blocksuite/presets/ai';
|
||||
import type { ForkChatSessionInput } from '@affine/graphql';
|
||||
import { assertExists } from '@blocksuite/affine/global/utils';
|
||||
import { partition } from 'lodash-es';
|
||||
|
||||
@@ -48,36 +47,13 @@ export async function createChatSession({
|
||||
promptName,
|
||||
});
|
||||
// always update the prompt name
|
||||
await updateChatSession({
|
||||
await client.updateSession({
|
||||
sessionId,
|
||||
client,
|
||||
promptName,
|
||||
});
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
export function updateChatSession({
|
||||
client,
|
||||
sessionId,
|
||||
promptName,
|
||||
}: {
|
||||
client: CopilotClient;
|
||||
sessionId: string;
|
||||
promptName: string;
|
||||
}) {
|
||||
return client.updateSession({
|
||||
sessionId,
|
||||
promptName,
|
||||
});
|
||||
}
|
||||
|
||||
export function forkCopilotSession(
|
||||
client: CopilotClient,
|
||||
forkChatSessionInput: ForkChatSessionInput
|
||||
) {
|
||||
return client.forkSession(forkChatSessionInput);
|
||||
}
|
||||
|
||||
async function resizeImage(blob: Blob | File): Promise<Blob | null> {
|
||||
let src = '';
|
||||
try {
|
||||
@@ -360,17 +336,3 @@ export function toImage({
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function cleanupSessions({
|
||||
workspaceId,
|
||||
docId,
|
||||
sessionIds,
|
||||
client,
|
||||
}: {
|
||||
workspaceId: string;
|
||||
docId: string;
|
||||
sessionIds: string[];
|
||||
client: CopilotClient;
|
||||
}) {
|
||||
return client.cleanupSessions({ workspaceId, docId, sessionIds });
|
||||
}
|
||||
|
||||
@@ -11,14 +11,7 @@ import { z } from 'zod';
|
||||
|
||||
import type { CopilotClient } from './copilot-client';
|
||||
import type { PromptKey } from './prompt';
|
||||
import {
|
||||
cleanupSessions,
|
||||
createChatSession,
|
||||
forkCopilotSession,
|
||||
textToText,
|
||||
toImage,
|
||||
updateChatSession,
|
||||
} from './request';
|
||||
import { createChatSession, textToText, toImage } from './request';
|
||||
import { setupTracker } from './tracker';
|
||||
|
||||
const filterStyleToPromptName = new Map(
|
||||
@@ -424,9 +417,15 @@ Could you make a new website based on these notes and send back just the html fi
|
||||
promptName,
|
||||
});
|
||||
},
|
||||
getSessionIds: async (
|
||||
workspaceId: string,
|
||||
docId?: string,
|
||||
options?: { action?: boolean }
|
||||
) => {
|
||||
return client.getSessionIds(workspaceId, docId, options);
|
||||
},
|
||||
updateSession: async (sessionId: string, promptName: string) => {
|
||||
return updateChatSession({
|
||||
client,
|
||||
return client.updateSession({
|
||||
sessionId,
|
||||
promptName,
|
||||
});
|
||||
@@ -490,7 +489,7 @@ Could you make a new website based on these notes and send back just the html fi
|
||||
docId: string,
|
||||
sessionIds: string[]
|
||||
) => {
|
||||
await cleanupSessions({ workspaceId, docId, sessionIds, client });
|
||||
await client.cleanupSessions({ workspaceId, docId, sessionIds });
|
||||
},
|
||||
ids: async (
|
||||
workspaceId: string,
|
||||
@@ -533,7 +532,7 @@ Could you make a new website based on these notes and send back just the html fi
|
||||
AIProvider.provide('onboarding', toggleGeneralAIOnboarding);
|
||||
|
||||
AIProvider.provide('forkChat', options => {
|
||||
return forkCopilotSession(client, options);
|
||||
return client.forkSession(options);
|
||||
});
|
||||
|
||||
const disposeRequestLoginHandler = AIProvider.slots.requestLogin.on(() => {
|
||||
|
||||
Reference in New Issue
Block a user