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

View File

@@ -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;
} }