feat(server): add typed list session gql (#12979)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Introduced new API endpoints and GraphQL queries to retrieve Copilot
chat sessions by workspace, document, and pinned status, with detailed
session and message information.
* Added support for filtering and querying Copilot chat histories with
new options such as pinned status and message ordering.

* **Bug Fixes**
* Improved filtering logic for listing and retrieving chat sessions,
ensuring accurate results for workspace, document, and pinned session
queries.

* **Tests**
* Expanded and refactored test coverage for session listing, filtering,
and new query options to ensure reliability and correctness of Copilot
session retrieval.
* Updated snapshot data to reflect new session types and filtering
capabilities.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
DarkSky
2025-07-01 19:31:37 +08:00
committed by GitHub
parent 6e9487a9e1
commit 0326da0806
13 changed files with 704 additions and 152 deletions
@@ -709,26 +709,30 @@ type ChatMessage = {
type History = {
sessionId: string;
pinned: boolean;
tokens: number;
action: string | null;
createdAt: string;
messages: ChatMessage[];
};
type HistoryOptions = {
action?: boolean;
fork?: boolean;
pinned?: boolean;
limit?: number;
skip?: number;
sessionOrder?: 'asc' | 'desc';
messageOrder?: 'asc' | 'desc';
sessionId?: string;
};
export async function getHistories(
app: TestingApp,
variables: {
workspaceId: string;
docId?: string;
options?: {
action?: boolean;
fork?: boolean;
limit?: number;
skip?: number;
sessionOrder?: 'asc' | 'desc';
messageOrder?: 'asc' | 'desc';
sessionId?: string;
};
docId?: string | null;
options?: HistoryOptions;
}
): Promise<History[]> {
const res = await app.gql(
@@ -742,6 +746,7 @@ export async function getHistories(
copilot(workspaceId: $workspaceId) {
histories(docId: $docId, options: $options) {
sessionId
pinned
tokens
action
createdAt
@@ -763,6 +768,152 @@ export async function getHistories(
return res.currentUser?.copilot?.histories || [];
}
export async function getWorkspaceSessions(
app: TestingApp,
variables: {
workspaceId: string;
options?: HistoryOptions;
}
): Promise<History[]> {
const res = await app.gql(
`query getCopilotWorkspaceSessions(
$workspaceId: String!
$options: QueryChatHistoriesInput
) {
currentUser {
copilot(workspaceId: $workspaceId) {
histories(docId: null, options: $options) {
sessionId
pinned
tokens
action
createdAt
messages {
id
role
content
streamObjects {
type
textDelta
toolCallId
toolName
args
result
}
attachments
createdAt
}
}
}
}
}`,
variables
);
return res.currentUser?.copilot?.histories || [];
}
export async function getDocSessions(
app: TestingApp,
variables: {
workspaceId: string;
docId: string;
options?: HistoryOptions;
}
): Promise<History[]> {
const res = await app.gql(
`query getCopilotDocSessions(
$workspaceId: String!
$docId: String!
$options: QueryChatHistoriesInput
) {
currentUser {
copilot(workspaceId: $workspaceId) {
histories(docId: $docId, options: $options) {
sessionId
pinned
tokens
action
createdAt
messages {
id
role
content
streamObjects {
type
textDelta
toolCallId
toolName
args
result
}
attachments
createdAt
}
}
}
}
}`,
variables
);
return res.currentUser?.copilot?.histories || [];
}
export async function getPinnedSessions(
app: TestingApp,
variables: {
workspaceId: string;
docId?: string;
messageOrder?: 'asc' | 'desc';
withPrompt?: boolean;
}
): Promise<History[]> {
const res = await app.gql(
`query getCopilotPinnedSessions(
$workspaceId: String!
$docId: String
$messageOrder: ChatHistoryOrder
$withPrompt: Boolean
) {
currentUser {
copilot(workspaceId: $workspaceId) {
histories(docId: $docId, options: {
limit: 1,
pinned: true,
messageOrder: $messageOrder,
withPrompt: $withPrompt
}) {
sessionId
pinned
tokens
action
createdAt
messages {
id
role
content
streamObjects {
type
textDelta
toolCallId
toolName
args
result
}
attachments
createdAt
}
}
}
}
}`,
variables
);
return res.currentUser?.copilot?.histories || [];
}
type Prompt = {
name: string;
model: string;