Skip to content

Commit 42ba20b

Browse files
committed
feat(chat): 添加继续生成的功能支持
- 在 ChatProvider 中新增 continueGeneration 方法以处理续写请求 - 修改状态管理,移除对继续提示的已关闭本地存储逻辑 - 优化会话状态显示,只在中断时展示继续提示 - 为用户消息生成唯一 ID,保证消息唯一性 - 在 App 组件中将 ContinuePrompt 的 onContinue 回调绑定到 continueGeneration - 在路由逻辑中排除 "/continue" 指令的用户消息展示,避免重复发送请求
1 parent f569915 commit 42ba20b

3 files changed

Lines changed: 26 additions & 19 deletions

File tree

packages/vscode-ide-companion/src/router.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,15 @@ export const appRouter = router({
143143
}
144144

145145
const displayPrompt = prompt || (normalizedImages.length > 0 ? "粘贴的图像" : "");
146+
const promptTrimmed = prompt.trim();
146147
const isPermissionContinue =
147-
prompt === "/continue" &&
148+
promptTrimmed === "/continue" &&
148149
normalizedImages.length === 0 &&
149150
((permissions?.length ?? 0) > 0 || (alwaysAllows?.length ?? 0) > 0);
151+
const isPlainContinue = promptTrimmed === "/continue" && normalizedImages.length === 0;
150152

151-
// Show user message in webview
152-
if (displayPrompt && !isPermissionContinue) {
153+
// Show user message in webview (skip for /continue commands)
154+
if (displayPrompt && !isPermissionContinue && !isPlainContinue) {
153155
ctx.postMessage({ type: "userMessage", content: displayPrompt });
154156
}
155157

packages/vscode-ide-companion/src/webview/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default function App() {
4949
onInterrupt={actions.interrupt}
5050
/>
5151
{state.showContinuePrompt && (
52-
<ContinuePrompt onContinue={actions.dismissContinuePrompt} onDismiss={actions.dismissContinuePrompt} />
52+
<ContinuePrompt onContinue={actions.continueGeneration} onDismiss={actions.dismissContinuePrompt} />
5353
)}
5454
{state.loading && (
5555
<ThinkingLiveBubble

packages/vscode-ide-companion/src/webview/context/ChatProvider.tsx

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ interface ChatContextValue {
4141
renameSession: (sessionId: string, summary: string) => Promise<void>;
4242
deleteSession: (sessionId: string) => Promise<void>;
4343
dismissContinuePrompt: () => void;
44+
continueGeneration: () => Promise<void>;
4445
};
4546
}
4647

@@ -93,20 +94,12 @@ function appReducer(state: AppState, action: AppAction): AppState {
9394
permissionPromptState: null,
9495
pendingPermissionReply: null,
9596
loading: action.status === "processing" || action.status === "pending",
96-
showContinuePrompt:
97-
action.status === "interrupted"
98-
? localStorage.getItem(`deepcode:continuePromptDismissed:${action.sessionId}`) !== "1"
99-
: false,
97+
showContinuePrompt: action.status === "interrupted",
10098
};
10199
case "SET_SESSIONS":
102100
return { ...state, sessions: action.sessions };
103101
case "SESSION_STATUS": {
104102
const isInterrupted = action.status === "interrupted";
105-
const sessionId = action.sessionId || state.activeSessionId;
106-
const dismissed =
107-
isInterrupted && sessionId
108-
? localStorage.getItem(`deepcode:continuePromptDismissed:${sessionId}`) === "1"
109-
: true;
110103

111104
return {
112105
...state,
@@ -115,7 +108,7 @@ function appReducer(state: AppState, action: AppAction): AppState {
115108
processes: action.processes ?? state.processes,
116109
tokenTelemetry: action.tokenTelemetry ?? state.tokenTelemetry,
117110
loading: action.status === "processing" || action.status === "pending",
118-
showContinuePrompt: isInterrupted && !dismissed,
111+
showContinuePrompt: isInterrupted,
119112
};
120113
}
121114
case "LLM_STREAM_PROGRESS":
@@ -124,7 +117,12 @@ function appReducer(state: AppState, action: AppAction): AppState {
124117
}
125118
return { ...state, llmStreamProgress: action.progress };
126119
case "USER_MESSAGE": {
127-
const newMsg: SessionMessage = { role: "user", content: action.content, meta: action.meta };
120+
const newMsg: SessionMessage = {
121+
id: crypto.randomUUID(),
122+
role: "user",
123+
content: action.content,
124+
meta: action.meta,
125+
};
128126
return {
129127
...state,
130128
messages: [...state.messages, newMsg],
@@ -399,11 +397,17 @@ export function ChatProvider({ children }: ChatProviderProps) {
399397
);
400398

401399
const dismissContinuePrompt = useCallback(() => {
402-
if (state.activeSessionId) {
403-
localStorage.setItem(`deepcode:continuePromptDismissed:${state.activeSessionId}`, "1");
404-
}
405400
dispatch({ type: "DISMISS_CONTINUE_PROMPT" });
406-
}, [state.activeSessionId]);
401+
}, []);
402+
403+
const continueGeneration = useCallback(async () => {
404+
dispatch({ type: "DISMISS_CONTINUE_PROMPT" });
405+
try {
406+
await chatService.sendPrompt({ prompt: "/continue" });
407+
} catch (err) {
408+
console.error("[ChatProvider] continueGeneration failed:", err);
409+
}
410+
}, []);
407411

408412
const contextValue: ChatContextValue = {
409413
state,
@@ -419,6 +423,7 @@ export function ChatProvider({ children }: ChatProviderProps) {
419423
renameSession,
420424
deleteSession,
421425
dismissContinuePrompt,
426+
continueGeneration,
422427
},
423428
};
424429

0 commit comments

Comments
 (0)