fix(cli): wire initialModel/initialProvider through useSocket, add error handling
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
- Pass initialModel/initialProvider from CLI flags into useSocket hook - Include provider/modelId in socket message emit (restores PR #144 functionality) - Add provider/modelId optional fields to ChatMessagePayload type - Add .catch() to floating promises in createConversation/deleteConversation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -25,8 +25,8 @@ export function TuiApp({
|
|||||||
gatewayUrl,
|
gatewayUrl,
|
||||||
conversationId,
|
conversationId,
|
||||||
sessionCookie,
|
sessionCookie,
|
||||||
initialModel: _initialModel,
|
initialModel,
|
||||||
initialProvider: _initialProvider,
|
initialProvider,
|
||||||
}: TuiAppProps) {
|
}: TuiAppProps) {
|
||||||
const { exit } = useApp();
|
const { exit } = useApp();
|
||||||
const gitInfo = useGitInfo();
|
const gitInfo = useGitInfo();
|
||||||
@@ -36,6 +36,8 @@ export function TuiApp({
|
|||||||
gatewayUrl,
|
gatewayUrl,
|
||||||
sessionCookie,
|
sessionCookie,
|
||||||
initialConversationId: conversationId,
|
initialConversationId: conversationId,
|
||||||
|
initialModel,
|
||||||
|
initialProvider,
|
||||||
});
|
});
|
||||||
|
|
||||||
const conversations = useConversations({ gatewayUrl, sessionCookie });
|
const conversations = useConversations({ gatewayUrl, sessionCookie });
|
||||||
@@ -72,11 +74,14 @@ export function TuiApp({
|
|||||||
|
|
||||||
const handleDeleteConversation = useCallback(
|
const handleDeleteConversation = useCallback(
|
||||||
(id: string) => {
|
(id: string) => {
|
||||||
void conversations.deleteConversation(id).then((ok) => {
|
void conversations
|
||||||
|
.deleteConversation(id)
|
||||||
|
.then((ok) => {
|
||||||
if (ok && id === socket.conversationId) {
|
if (ok && id === socket.conversationId) {
|
||||||
socket.clearMessages();
|
socket.clearMessages();
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(() => {});
|
||||||
},
|
},
|
||||||
[conversations, socket],
|
[conversations, socket],
|
||||||
);
|
);
|
||||||
@@ -95,12 +100,15 @@ export function TuiApp({
|
|||||||
}
|
}
|
||||||
// Ctrl+N: create new conversation and switch to it
|
// Ctrl+N: create new conversation and switch to it
|
||||||
if (key.ctrl && ch === 'n') {
|
if (key.ctrl && ch === 'n') {
|
||||||
void conversations.createConversation().then((conv) => {
|
void conversations
|
||||||
|
.createConversation()
|
||||||
|
.then((conv) => {
|
||||||
if (conv) {
|
if (conv) {
|
||||||
socket.switchConversation(conv.id);
|
socket.switchConversation(conv.id);
|
||||||
appMode.setMode('chat');
|
appMode.setMode('chat');
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(() => {});
|
||||||
}
|
}
|
||||||
// Ctrl+K: toggle search mode
|
// Ctrl+K: toggle search mode
|
||||||
if (key.ctrl && ch === 'k') {
|
if (key.ctrl && ch === 'k') {
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ export interface UseSocketOptions {
|
|||||||
gatewayUrl: string;
|
gatewayUrl: string;
|
||||||
sessionCookie?: string;
|
sessionCookie?: string;
|
||||||
initialConversationId?: string;
|
initialConversationId?: string;
|
||||||
|
initialModel?: string;
|
||||||
|
initialProvider?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UseSocketReturn {
|
export interface UseSocketReturn {
|
||||||
@@ -78,7 +80,7 @@ const EMPTY_USAGE: TokenUsage = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function useSocket(opts: UseSocketOptions): UseSocketReturn {
|
export function useSocket(opts: UseSocketOptions): UseSocketReturn {
|
||||||
const { gatewayUrl, sessionCookie, initialConversationId } = opts;
|
const { gatewayUrl, sessionCookie, initialConversationId, initialModel, initialProvider } = opts;
|
||||||
|
|
||||||
const [connected, setConnected] = useState(false);
|
const [connected, setConnected] = useState(false);
|
||||||
const [connecting, setConnecting] = useState(true);
|
const [connecting, setConnecting] = useState(true);
|
||||||
@@ -227,6 +229,8 @@ export function useSocket(opts: UseSocketOptions): UseSocketReturn {
|
|||||||
socketRef.current.emit('message', {
|
socketRef.current.emit('message', {
|
||||||
conversationId,
|
conversationId,
|
||||||
content,
|
content,
|
||||||
|
...(initialProvider ? { provider: initialProvider } : {}),
|
||||||
|
...(initialModel ? { modelId: initialModel } : {}),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[conversationId, isStreaming],
|
[conversationId, isStreaming],
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ export interface ErrorPayload {
|
|||||||
export interface ChatMessagePayload {
|
export interface ChatMessagePayload {
|
||||||
conversationId?: string;
|
conversationId?: string;
|
||||||
content: string;
|
content: string;
|
||||||
|
provider?: string;
|
||||||
|
modelId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Session info pushed when session is created or model changes */
|
/** Session info pushed when session is created or model changes */
|
||||||
|
|||||||
Reference in New Issue
Block a user