Skip to content

Commit e56077a

Browse files
committed
fix(): handle done immediately
1 parent 3298a98 commit e56077a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

bricks/ai/src/chat-view/ChatService.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ export class ChatService {
385385
async chat(msg: string | ChatBody): Promise<void> {
386386
this.#ctrl = new AbortController();
387387
let hadMatchMessage = false;
388+
let hadUsefulMessage = false;
388389
this.#chatting = true;
389390
await fetchEventSource(
390391
`${getBasePath()}api/gateway/easyops.api.aiops_chat.manage.LLMChatProxy@1.0.0/api/aiops_chat/v1/chat/completions`,
@@ -424,8 +425,23 @@ export class ChatService {
424425
hadMatchMessage = true;
425426
if (data === "[DONE]") {
426427
this.#ctrl!.abort();
428+
if (!hadUsefulMessage) {
429+
this.enqueue({
430+
topic: "add",
431+
message: {
432+
created: moment().format("YYYY-MM-DD HH:mm:ss"),
433+
delta: {
434+
role: "assistant",
435+
content: "",
436+
},
437+
agentId: this.#agentId,
438+
robotId: this.#robotId,
439+
},
440+
});
441+
}
427442
return;
428443
}
444+
hadUsefulMessage = true;
429445
let result = {} as SSEMessageItem;
430446
try {
431447
result = JSON.parse(data);
@@ -538,7 +554,7 @@ export class ChatService {
538554

539555
stop() {
540556
clearTimeout(this.#emitTimer);
541-
this.#ctrl && this.#ctrl?.abort();
557+
this.#ctrl?.abort();
542558
this.#chatting = false;
543559
this.#emitTimer = undefined;
544560
this.#isStartEmitEvent = false;

0 commit comments

Comments
 (0)