mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 05:14:54 +00:00
feat(server): copilot session prompt query (#10479)
This commit is contained in:
@@ -275,6 +275,15 @@ class CopilotPromptType {
|
||||
messages!: CopilotPromptMessageType[];
|
||||
}
|
||||
|
||||
@ObjectType()
|
||||
class CopilotSessionType {
|
||||
@Field(() => ID)
|
||||
id!: string;
|
||||
|
||||
@Field(() => String)
|
||||
promptName!: string;
|
||||
}
|
||||
|
||||
// ================== Resolver ==================
|
||||
|
||||
@ObjectType('Copilot')
|
||||
@@ -306,18 +315,32 @@ export class CopilotResolver {
|
||||
}
|
||||
|
||||
@ResolveField(() => [String], {
|
||||
description: 'Get the session list in the workspace',
|
||||
description: 'Get the session id list in the workspace',
|
||||
complexity: 2,
|
||||
deprecationReason: 'Use `sessions` instead',
|
||||
})
|
||||
async sessionIds(
|
||||
@Parent() copilot: CopilotType,
|
||||
@CurrentUser() user: CurrentUser,
|
||||
@Args('docId', { nullable: true }) docId?: string,
|
||||
@Args('options', { nullable: true }) options?: QueryChatSessionsInput
|
||||
) {
|
||||
return await this.sessions(copilot, user, docId, options);
|
||||
}
|
||||
|
||||
@ResolveField(() => [CopilotSessionType], {
|
||||
description: 'Get the session list in the workspace',
|
||||
complexity: 2,
|
||||
})
|
||||
async sessions(
|
||||
@Parent() copilot: CopilotType,
|
||||
@CurrentUser() user: CurrentUser,
|
||||
@Args('docId', { nullable: true }) docId?: string,
|
||||
@Args('options', { nullable: true }) options?: QueryChatSessionsInput
|
||||
) {
|
||||
if (!copilot.workspaceId) return [];
|
||||
await this.permissions.checkCloudWorkspace(copilot.workspaceId, user.id);
|
||||
return await this.chatSession.listSessionIds(
|
||||
return await this.chatSession.listSessions(
|
||||
user.id,
|
||||
copilot.workspaceId,
|
||||
docId,
|
||||
|
||||
@@ -396,12 +396,12 @@ export class ChatSessionService {
|
||||
.reduce((prev, cost) => prev + cost, 0);
|
||||
}
|
||||
|
||||
async listSessionIds(
|
||||
async listSessions(
|
||||
userId: string,
|
||||
workspaceId: string,
|
||||
docId?: string,
|
||||
options?: { action?: boolean }
|
||||
): Promise<string[]> {
|
||||
): Promise<Array<{ id: string; promptName: string }>> {
|
||||
return await this.db.aiSession
|
||||
.findMany({
|
||||
where: {
|
||||
@@ -413,9 +413,17 @@ export class ChatSessionService {
|
||||
},
|
||||
deletedAt: null,
|
||||
},
|
||||
select: { id: true },
|
||||
select: {
|
||||
id: true,
|
||||
promptName: true,
|
||||
},
|
||||
})
|
||||
.then(sessions => sessions.map(({ id }) => id));
|
||||
.then(sessions =>
|
||||
sessions.map(({ id, promptName }) => ({
|
||||
id,
|
||||
promptName,
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
async listHistories(
|
||||
|
||||
Reference in New Issue
Block a user