feat(server): add created timestamp to history (#6607)

This commit is contained in:
forehalo 2024-04-18 07:06:46 +00:00
parent 5fc56a20ac
commit d9e6561762
No known key found for this signature in database
GPG Key ID: 56709255DC7EC728
4 changed files with 8 additions and 1 deletions

View File

@ -123,6 +123,9 @@ class CopilotHistoriesType implements Partial<ChatHistory> {
@Field(() => [ChatMessageType])
messages!: ChatMessageType[];
@Field(() => Date)
createdAt!: Date;
}
@ObjectType('CopilotQuota')

View File

@ -318,6 +318,7 @@ export class ChatSessionService {
select: {
id: true,
promptName: true,
createdAt: true,
messages: {
select: {
role: true,
@ -335,7 +336,7 @@ export class ChatSessionService {
})
.then(sessions =>
Promise.all(
sessions.map(async ({ id, promptName, messages }) => {
sessions.map(async ({ id, promptName, messages, createdAt }) => {
try {
const ret = PromptMessageSchema.array().safeParse(messages);
if (ret.success) {
@ -357,6 +358,7 @@ export class ChatSessionService {
sessionId: id,
action: prompt.action || undefined,
tokens,
createdAt,
messages: preload.concat(ret.data),
};
} else {

View File

@ -93,6 +93,7 @@ export const ChatHistorySchema = z
action: z.string().optional(),
tokens: z.number(),
messages: z.array(PromptMessageSchema.or(ChatMessageSchema)),
createdAt: z.date(),
})
.strict();

View File

@ -9,6 +9,7 @@ query getCopilotHistories(
sessionId
tokens
action
createdAt
messages {
role
content