feat(server): copilot session prompt query (#10479)

This commit is contained in:
darkskygit
2025-02-27 11:25:52 +00:00
parent d50860eee2
commit 985906aa13
10 changed files with 79 additions and 21 deletions

View File

@@ -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,

View File

@@ -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(