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:
DarkSky 2025-06-26 17:04:25 +08:00 committed by GitHub
parent eef2e05d83
commit 5e193b58c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -188,11 +188,6 @@ export class CopilotSessionModel extends BaseModel {
@Transactional()
async fork(options: ForkSessionOptions): Promise<string> {
if (!options.messages?.length) {
throw new CopilotSessionInvalidInput(
'Cannot fork session without messages'
);
}
if (options.pinned) {
await this.unpin(options.workspaceId, options.userId);
}
@ -203,12 +198,15 @@ export class CopilotSessionModel extends BaseModel {
...forkedState,
messages: [],
});
// save message
await this.models.copilotSession.updateMessages({
...forkedState,
sessionId,
messages,
});
if (options.messages.length) {
// save message
await this.models.copilotSession.updateMessages({
...forkedState,
sessionId,
messages,
});
}
return sessionId;
}