mirror of
https://github.com/stackblitz-labs/bolt.diy
synced 2025-06-26 18:26:38 +00:00
Fix bugs when using stop button
This commit is contained in:
parent
ede4993ab5
commit
3271171646
@ -23,6 +23,7 @@ import {
|
|||||||
simulationRepositoryUpdated,
|
simulationRepositoryUpdated,
|
||||||
sendChatMessage,
|
sendChatMessage,
|
||||||
type ChatReference,
|
type ChatReference,
|
||||||
|
simulationReset,
|
||||||
} from '~/lib/replay/SimulationPrompt';
|
} from '~/lib/replay/SimulationPrompt';
|
||||||
import { getIFrameSimulationData } from '~/lib/replay/Recording';
|
import { getIFrameSimulationData } from '~/lib/replay/Recording';
|
||||||
import { getCurrentIFrame } from '~/components/workbench/Preview';
|
import { getCurrentIFrame } from '~/components/workbench/Preview';
|
||||||
@ -216,6 +217,7 @@ export const ChatImpl = memo(
|
|||||||
if (gActiveChatMessageTelemetry) {
|
if (gActiveChatMessageTelemetry) {
|
||||||
gActiveChatMessageTelemetry.abort('StopButtonClicked');
|
gActiveChatMessageTelemetry.abort('StopButtonClicked');
|
||||||
clearActiveChat();
|
clearActiveChat();
|
||||||
|
simulationReset();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -381,6 +383,8 @@ export const ChatImpl = memo(
|
|||||||
|
|
||||||
const lastMessage = newMessages[newMessages.length - 1];
|
const lastMessage = newMessages[newMessages.length - 1];
|
||||||
setApproveChangesMessageId(lastMessage.id);
|
setApproveChangesMessageId(lastMessage.id);
|
||||||
|
} else {
|
||||||
|
simulationReset();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -110,15 +110,11 @@ class ChatManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
finishSimulationData(): SimulationData {
|
finishSimulationData() {
|
||||||
assert(this.client, 'Chat has been destroyed');
|
assert(this.client, 'Chat has been destroyed');
|
||||||
assert(!this.simulationFinished, 'Simulation has been finished');
|
assert(!this.simulationFinished, 'Simulation has been finished');
|
||||||
assert(this.repositoryId, 'Expected repository ID');
|
|
||||||
|
|
||||||
const allData = [createRepositoryIdPacket(this.repositoryId), ...this.pageData];
|
|
||||||
this.simulationFinished = true;
|
this.simulationFinished = true;
|
||||||
|
|
||||||
return allData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendChatMessage(messages: Message[], references: ChatReference[], onResponsePart: ChatResponsePartCallback) {
|
async sendChatMessage(messages: Message[], references: ChatReference[], onResponsePart: ChatResponsePartCallback) {
|
||||||
@ -152,14 +148,16 @@ class ChatManager {
|
|||||||
// There is only one chat active at a time.
|
// There is only one chat active at a time.
|
||||||
let gChatManager: ChatManager | undefined;
|
let gChatManager: ChatManager | undefined;
|
||||||
|
|
||||||
function startChat(repositoryId: string, pageData: SimulationData) {
|
function startChat(repositoryId: string | undefined, pageData: SimulationData) {
|
||||||
if (gChatManager) {
|
if (gChatManager) {
|
||||||
gChatManager.destroy();
|
gChatManager.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
gChatManager = new ChatManager();
|
gChatManager = new ChatManager();
|
||||||
|
|
||||||
gChatManager.setRepositoryId(repositoryId);
|
if (repositoryId) {
|
||||||
|
gChatManager.setRepositoryId(repositoryId);
|
||||||
|
}
|
||||||
|
|
||||||
if (pageData.length) {
|
if (pageData.length) {
|
||||||
gChatManager.addPageData(pageData);
|
gChatManager.addPageData(pageData);
|
||||||
@ -179,7 +177,7 @@ export function simulationRepositoryUpdated(repositoryId: string) {
|
|||||||
* Called when the page gathering interaction data has been reloaded. We'll
|
* Called when the page gathering interaction data has been reloaded. We'll
|
||||||
* start a new chat with the same repository contents as any existing chat.
|
* start a new chat with the same repository contents as any existing chat.
|
||||||
*/
|
*/
|
||||||
export async function simulationReloaded() {
|
export function simulationReloaded() {
|
||||||
assert(gChatManager, 'Expected to have an active chat');
|
assert(gChatManager, 'Expected to have an active chat');
|
||||||
|
|
||||||
const repositoryId = gChatManager.repositoryId;
|
const repositoryId = gChatManager.repositoryId;
|
||||||
@ -188,6 +186,15 @@ export async function simulationReloaded() {
|
|||||||
startChat(repositoryId, []);
|
startChat(repositoryId, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Called when the current message has finished with no repository change.
|
||||||
|
* We'll start a new chat with the same simulation data as the previous chat.
|
||||||
|
*/
|
||||||
|
export function simulationReset() {
|
||||||
|
assert(gChatManager, 'Expected to have an active chat');
|
||||||
|
startChat(gChatManager.repositoryId, gChatManager.pageData);
|
||||||
|
}
|
||||||
|
|
||||||
export function simulationAddData(data: SimulationData) {
|
export function simulationAddData(data: SimulationData) {
|
||||||
assert(gChatManager, 'Expected to have an active chat');
|
assert(gChatManager, 'Expected to have an active chat');
|
||||||
gChatManager.addPageData(data);
|
gChatManager.addPageData(data);
|
||||||
|
Loading…
Reference in New Issue
Block a user