feat(auth): 优化认证流程并添加认证状态管理

- 新增 AuthStateManager 类用于管理认证状态
- 修改 createNewSession 方法以使用缓存的认证信息
- 添加清除认证缓存的功能
- 优化登录命令处理,增加加载状态显示
- 新增登录成功和失败的消息处理
This commit is contained in:
yiliang114
2025-11-27 01:41:56 +08:00
parent 4f63d92bb1
commit b986692f94
5 changed files with 108 additions and 47 deletions

View File

@@ -135,6 +135,31 @@ export const useWebViewMessages = ({
const handlers = handlersRef.current;
switch (message.type) {
case 'loginSuccess': {
// Clear loading state and show a short assistant notice
handlers.messageHandling.clearWaitingForResponse();
handlers.messageHandling.addMessage({
role: 'assistant',
content: 'Successfully logged in. You can continue chatting.',
timestamp: Date.now(),
});
break;
}
case 'loginError': {
// Clear loading state and show error notice
handlers.messageHandling.clearWaitingForResponse();
const errorMsg =
(message?.data?.message as string) ||
'Login failed. Please try again.';
handlers.messageHandling.addMessage({
role: 'assistant',
content: errorMsg,
timestamp: Date.now(),
});
break;
}
case 'conversationLoaded': {
const conversation = message.data as Conversation;
handlers.messageHandling.setMessages(conversation.messages);