fix(server): allow fork empty session in playground (#12940)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved session forking by allowing sessions to be forked even when no messages are provided, preventing unnecessary errors. * Reduced unnecessary database operations by only updating messages when there are messages to update. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -188,11 +188,6 @@ export class CopilotSessionModel extends BaseModel {
|
|||||||
|
|
||||||
@Transactional()
|
@Transactional()
|
||||||
async fork(options: ForkSessionOptions): Promise<string> {
|
async fork(options: ForkSessionOptions): Promise<string> {
|
||||||
if (!options.messages?.length) {
|
|
||||||
throw new CopilotSessionInvalidInput(
|
|
||||||
'Cannot fork session without messages'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (options.pinned) {
|
if (options.pinned) {
|
||||||
await this.unpin(options.workspaceId, options.userId);
|
await this.unpin(options.workspaceId, options.userId);
|
||||||
}
|
}
|
||||||
@@ -203,12 +198,15 @@ export class CopilotSessionModel extends BaseModel {
|
|||||||
...forkedState,
|
...forkedState,
|
||||||
messages: [],
|
messages: [],
|
||||||
});
|
});
|
||||||
// save message
|
if (options.messages.length) {
|
||||||
await this.models.copilotSession.updateMessages({
|
// save message
|
||||||
...forkedState,
|
await this.models.copilotSession.updateMessages({
|
||||||
sessionId,
|
...forkedState,
|
||||||
messages,
|
sessionId,
|
||||||
});
|
messages,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return sessionId;
|
return sessionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user