返回 DeepSeek-Reasonix
remoteTurnState.ts
根目录 / desktop / frontend / src / lib / remoteTurnState.ts
1 import { t } from "./i18n";
2 import type { Item, State } from "./useController";
3 import { removeEmptyAssistantItems } from "./assistantItems";
4
5 export function withRemoteProviderUnreachable(state: State, detail: string): State {
6 const notice: Item = { kind: "notice", id: "provider-unreachable", level: "warn", text: t("notice.remoteProviderUnreachable", { detail }) };
7 return { ...state, items: [...state.items.filter((item) => item.id !== notice.id), notice] };
8 }
9
10 export function withRemoteTurnInterrupted(state: State): State {
11 if (!state.running && !state.turnActive) return state;
12 const items = removeEmptyAssistantItems(state.items.map((item): Item => {
13 if (item.kind === "assistant" && state.live && item.id === state.live.id) {
14 return { ...item, text: state.live.text, reasoning: state.live.reasoning, streaming: false };
15 }
16 if (item.kind === "assistant" && item.streaming) return { ...item, streaming: false };
17 if (item.kind === "tool" && item.status === "running") return { ...item, status: "stopped" };
18 return item;
19 }));
20 const notice: Item = { kind: "notice", id: `n${state.seq}`, level: "warn", text: t("notice.remoteTurnInterrupted") };
21 return {
22 ...state,
23 items: [...items, notice],
24 running: false,
25 turnActive: false,
26 pendingPrompt: false,
27 cancelRequested: false,
28 cancellable: false,
29 pendingUser: undefined,
30 pendingSubmissionId: undefined,
31 deliveryRecoveryActive: false,
32 retry: undefined,
33 approval: undefined,
34 ask: undefined,
35 live: undefined,
36 currentAssistant: undefined,
37 assistantSegmentOrdinal: 0,
38 activeTurnId: undefined,
39 streamAttemptJournal: undefined,
40 seq: state.seq + 1,
41 };
42 }
43
43 lines TYPESCRIPT