feat: improve histories query for forked session (#7414)

This commit is contained in:
darkskygit
2024-07-03 04:49:19 +00:00
parent cc7740d8d3
commit e8285289fe
8 changed files with 210 additions and 21 deletions

View File

@@ -174,6 +174,35 @@ export async function createCopilotSession(
return res.body.data.createCopilotSession;
}
export async function forkCopilotSession(
app: INestApplication,
userToken: string,
workspaceId: string,
docId: string,
sessionId: string,
latestMessageId: string
): Promise<string> {
const res = await request(app.getHttpServer())
.post(gql)
.auth(userToken, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
query: `
mutation forkCopilotSession($options: ForkChatSessionInput!) {
forkCopilotSession(options: $options)
}
`,
variables: {
options: { workspaceId, docId, sessionId, latestMessageId },
},
})
.expect(200);
handleGraphQLError(res);
return res.body.data.forkCopilotSession;
}
export async function createCopilotMessage(
app: INestApplication,
userToken: string,
@@ -286,6 +315,7 @@ export function textToEventStream(
}
type ChatMessage = {
id?: string;
role: string;
content: string;
attachments: string[] | null;
@@ -333,6 +363,7 @@ export async function getHistories(
action
createdAt
messages {
id
role
content
attachments

View File

@@ -145,7 +145,14 @@ export function handleGraphQLError(resp: Response) {
if (errors) {
const cause = errors[0];
const stacktrace = cause.extensions?.stacktrace;
throw new Error(stacktrace ? stacktrace.join('\n') : cause.message, cause);
throw new Error(
stacktrace
? Array.isArray(stacktrace)
? stacktrace.join('\n')
: String(stacktrace)
: cause.message,
cause
);
}
}