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,
|
||||
conversationId,
|
||||
sessionCookie,
|
||||
initialModel: _initialModel,
|
||||
initialProvider: _initialProvider,
|
||||
initialModel,
|
||||
initialProvider,
|
||||
}: TuiAppProps) {
|
||||
const { exit } = useApp();
|
||||
const gitInfo = useGitInfo();
|
||||
@@ -36,6 +36,8 @@ export function TuiApp({
|
||||
gatewayUrl,
|
||||
sessionCookie,
|
||||
initialConversationId: conversationId,
|
||||
initialModel,
|
||||
initialProvider,
|
||||
});
|
||||
|
||||
const conversations = useConversations({ gatewayUrl, sessionCookie });
|
||||
@@ -72,11 +74,14 @@ export function TuiApp({
|
||||
|
||||
const handleDeleteConversation = useCallback(
|
||||
(id: string) => {
|
||||
void conversations.deleteConversation(id).then((ok) => {
|
||||
if (ok && id === socket.conversationId) {
|
||||
socket.clearMessages();
|
||||
}
|
||||
});
|
||||
void conversations
|
||||
.deleteConversation(id)
|
||||
.then((ok) => {
|
||||
if (ok && id === socket.conversationId) {
|
||||
socket.clearMessages();
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
},
|
||||
[conversations, socket],
|
||||
);
|
||||
@@ -95,12 +100,15 @@ export function TuiApp({
|
||||
}
|
||||
// Ctrl+N: create new conversation and switch to it
|
||||
if (key.ctrl && ch === 'n') {
|
||||
void conversations.createConversation().then((conv) => {
|
||||
if (conv) {
|
||||
socket.switchConversation(conv.id);
|
||||
appMode.setMode('chat');
|
||||
}
|
||||
});
|
||||
void conversations
|
||||
.createConversation()
|
||||
.then((conv) => {
|
||||
if (conv) {
|
||||
socket.switchConversation(conv.id);
|
||||
appMode.setMode('chat');
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
// Ctrl+K: toggle search mode
|
||||
if (key.ctrl && ch === 'k') {
|
||||
|
||||
@@ -41,6 +41,8 @@ export interface UseSocketOptions {
|
||||
gatewayUrl: string;
|
||||
sessionCookie?: string;
|
||||
initialConversationId?: string;
|
||||
initialModel?: string;
|
||||
initialProvider?: string;
|
||||
}
|
||||
|
||||
export interface UseSocketReturn {
|
||||
@@ -78,7 +80,7 @@ const EMPTY_USAGE: TokenUsage = {
|
||||
};
|
||||
|
||||
export function useSocket(opts: UseSocketOptions): UseSocketReturn {
|
||||
const { gatewayUrl, sessionCookie, initialConversationId } = opts;
|
||||
const { gatewayUrl, sessionCookie, initialConversationId, initialModel, initialProvider } = opts;
|
||||
|
||||
const [connected, setConnected] = useState(false);
|
||||
const [connecting, setConnecting] = useState(true);
|
||||
@@ -227,6 +229,8 @@ export function useSocket(opts: UseSocketOptions): UseSocketReturn {
|
||||
socketRef.current.emit('message', {
|
||||
conversationId,
|
||||
content,
|
||||
...(initialProvider ? { provider: initialProvider } : {}),
|
||||
...(initialModel ? { modelId: initialModel } : {}),
|
||||
});
|
||||
},
|
||||
[conversationId, isStreaming],
|
||||
|
||||
@@ -62,6 +62,8 @@ export interface ErrorPayload {
|
||||
export interface ChatMessagePayload {
|
||||
conversationId?: string;
|
||||
content: string;
|
||||
provider?: string;
|
||||
modelId?: string;
|
||||
}
|
||||
|
||||
/** Session info pushed when session is created or model changes */
|
||||
|
||||
Reference in New Issue
Block a user