feat: allow sort and filter forked session (#7519)

This commit is contained in:
DarkSky
2024-07-18 11:08:47 +08:00
committed by GitHub
parent ccac7a883c
commit dcb9d75db7
10 changed files with 166 additions and 26 deletions
+21 -7
View File
@@ -564,15 +564,29 @@ test('should be able to list history', async t => {
promptName
);
const messageId = await createCopilotMessage(app, token, sessionId);
const messageId = await createCopilotMessage(app, token, sessionId, 'hello');
await chatWithText(app, token, sessionId, messageId);
const histories = await getHistories(app, token, { workspaceId });
t.deepEqual(
histories.map(h => h.messages.map(m => m.content)),
[['generate text to text']],
'should be able to list history'
);
{
const histories = await getHistories(app, token, { workspaceId });
t.deepEqual(
histories.map(h => h.messages.map(m => m.content)),
[['hello', 'generate text to text']],
'should be able to list history'
);
}
{
const histories = await getHistories(app, token, {
workspaceId,
options: { messageOrder: 'desc' },
});
t.deepEqual(
histories.map(h => h.messages.map(m => m.content)),
[['generate text to text', 'hello']],
'should be able to list history'
);
}
});
test('should reject request that user have not permission', async t => {
+13 -2
View File
@@ -27,7 +27,7 @@ import {
WorkflowParams,
} from '../../src/plugins/copilot/workflow/types';
import { gql } from './common';
import { handleGraphQLError } from './utils';
import { handleGraphQLError, sleep } from './utils';
// @ts-expect-error no error
export class MockCopilotTestProvider
@@ -84,6 +84,8 @@ export class MockCopilotTestProvider
options: CopilotChatOptions = {}
): Promise<string> {
this.checkParams({ messages, model, options });
// make some time gap for history test case
await sleep(100);
return 'generate text to text';
}
@@ -94,6 +96,8 @@ export class MockCopilotTestProvider
): AsyncIterable<string> {
this.checkParams({ messages, model, options });
// make some time gap for history test case
await sleep(100);
const result = 'generate text to text stream';
for await (const message of result) {
yield message;
@@ -113,6 +117,8 @@ export class MockCopilotTestProvider
messages = Array.isArray(messages) ? messages : [messages];
this.checkParams({ embeddings: messages, model, options });
// make some time gap for history test case
await sleep(100);
return [Array.from(randomBytes(options.dimensions)).map(v => v % 128)];
}
@@ -130,6 +136,8 @@ export class MockCopilotTestProvider
throw new Error('Prompt is required');
}
// make some time gap for history test case
await sleep(100);
// just let test case can easily verify the final prompt
return [`https://example.com/${model}.jpg`, prompt];
}
@@ -338,10 +346,13 @@ export async function getHistories(
workspaceId: string;
docId?: string;
options?: {
sessionId?: string;
action?: boolean;
fork?: boolean;
limit?: number;
skip?: number;
sessionOrder?: 'asc' | 'desc';
messageOrder?: 'asc' | 'desc';
sessionId?: string;
};
}
): Promise<History[]> {
@@ -167,3 +167,7 @@ export function gql(app: INestApplication, query?: string) {
return req;
}
export async function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}