mirror of
https://github.com/R0m1k3/Loki.git
synced 2026-10-22 06:28:11 +02:00
add stop streaming and robust code copy
This commit is contained in:
1 parent
c794d58718
commit
b9bccac4ba
4 files changed
+90
-18
No files matched your search
@@ -62,8 +62,11 @@ interface LokiState {
|
||||
openSession: (id: string) => Promise<void>;
|
||||
removeSession: (id: string) => Promise<void>;
|
||||
sendMessage: (content: string) => Promise<void>;
|
||||
stopStreaming: () => void;
|
||||
}
|
||||
|
||||
let activeStreamController: AbortController | null = null;
|
||||
|
||||
export const useStore = create<LokiState>((set, get) => ({
|
||||
status: null,
|
||||
models: [],
|
||||
@@ -207,6 +210,22 @@ export const useStore = create<LokiState>((set, get) => ({
|
||||
await get().refreshSessions();
|
||||
},
|
||||
|
||||
stopStreaming: () => {
|
||||
activeStreamController?.abort();
|
||||
activeStreamController = null;
|
||||
set({
|
||||
streaming: false,
|
||||
streamingSessionId: null,
|
||||
streamContent: "",
|
||||
streamThinking: "",
|
||||
streamStatus: "",
|
||||
streamNotice: null,
|
||||
streamTools: [],
|
||||
pendingShell: null,
|
||||
});
|
||||
void get().refreshSessions();
|
||||
},
|
||||
|
||||
sendMessage: async (content) => {
|
||||
if (get().streaming) return;
|
||||
content = content.trim();
|
||||
@@ -264,6 +283,9 @@ export const useStore = create<LokiState>((set, get) => ({
|
||||
pendingShell: null,
|
||||
});
|
||||
|
||||
const controller = new AbortController();
|
||||
activeStreamController = controller;
|
||||
|
||||
await streamChat(
|
||||
{ session_id: sid, content, model: get().selectedModel || undefined },
|
||||
{
|
||||
@@ -286,6 +308,7 @@ export const useStore = create<LokiState>((set, get) => ({
|
||||
},
|
||||
onToolConfirm: (command) => set({ pendingShell: command }),
|
||||
onDone: async () => {
|
||||
activeStreamController = null;
|
||||
// Repère un fichier HTML écrit pour l'afficher automatiquement.
|
||||
const writtenHtml = [...get().streamTools]
|
||||
.reverse()
|
||||
@@ -311,6 +334,7 @@ export const useStore = create<LokiState>((set, get) => ({
|
||||
if (writtenHtml) await get().openPreview(writtenHtml.args.path as string);
|
||||
},
|
||||
onError: (msg) => {
|
||||
activeStreamController = null;
|
||||
const errMsg: Message = {
|
||||
id: `err-${Date.now()}`,
|
||||
session_id: sid!,
|
||||
@@ -333,7 +357,22 @@ export const useStore = create<LokiState>((set, get) => ({
|
||||
});
|
||||
void get().refreshSessions();
|
||||
},
|
||||
}
|
||||
onAbort: () => {
|
||||
activeStreamController = null;
|
||||
set({
|
||||
streaming: false,
|
||||
streamingSessionId: null,
|
||||
streamContent: "",
|
||||
streamThinking: "",
|
||||
streamStatus: "",
|
||||
streamNotice: null,
|
||||
streamTools: [],
|
||||
pendingShell: null,
|
||||
});
|
||||
void get().refreshSessions();
|
||||
},
|
||||
},
|
||||
controller.signal
|
||||
);
|
||||
},
|
||||
}));
|
||||
Reference in new issue
Block a user