fix(cli): auto-create conversation on TUI start when no -c flag given
Without --conversation/-c, the TUI was starting with no conversationId, leaving the session bar showing "No session" and gateway commands unable to dispatch. Now creates a new conversation via REST before rendering so the socket is immediately attached to an active session. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -144,6 +144,23 @@ program
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Auto-create a conversation if none was specified
|
||||||
|
let conversationId = opts.conversation;
|
||||||
|
if (!conversationId) {
|
||||||
|
try {
|
||||||
|
const { createConversation } = await import('./tui/gateway-api.js');
|
||||||
|
const conv = await createConversation(opts.gateway, session.cookie, {
|
||||||
|
...(projectId ? { projectId } : {}),
|
||||||
|
});
|
||||||
|
conversationId = conv.id;
|
||||||
|
} catch (err) {
|
||||||
|
console.error(
|
||||||
|
`Failed to create conversation: ${err instanceof Error ? err.message : String(err)}`,
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Dynamic import to avoid loading React/Ink for other commands
|
// Dynamic import to avoid loading React/Ink for other commands
|
||||||
const { render } = await import('ink');
|
const { render } = await import('ink');
|
||||||
const React = await import('react');
|
const React = await import('react');
|
||||||
@@ -152,7 +169,7 @@ program
|
|||||||
render(
|
render(
|
||||||
React.createElement(TuiApp, {
|
React.createElement(TuiApp, {
|
||||||
gatewayUrl: opts.gateway,
|
gatewayUrl: opts.gateway,
|
||||||
conversationId: opts.conversation,
|
conversationId,
|
||||||
sessionCookie: session.cookie,
|
sessionCookie: session.cookie,
|
||||||
initialModel: opts.model,
|
initialModel: opts.model,
|
||||||
initialProvider: opts.provider,
|
initialProvider: opts.provider,
|
||||||
|
|||||||
@@ -110,6 +110,31 @@ async function handleResponse<T>(res: Response, errorPrefix: string): Promise<T>
|
|||||||
return (await res.json()) as T;
|
return (await res.json()) as T;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Conversation types ──
|
||||||
|
|
||||||
|
export interface ConversationInfo {
|
||||||
|
id: string;
|
||||||
|
title: string | null;
|
||||||
|
archived: boolean;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Conversation endpoints ──
|
||||||
|
|
||||||
|
export async function createConversation(
|
||||||
|
gatewayUrl: string,
|
||||||
|
sessionCookie: string,
|
||||||
|
data: { title?: string; projectId?: string } = {},
|
||||||
|
): Promise<ConversationInfo> {
|
||||||
|
const res = await fetch(`${gatewayUrl}/api/conversations`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: jsonHeaders(sessionCookie, gatewayUrl),
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
return handleResponse<ConversationInfo>(res, 'Failed to create conversation');
|
||||||
|
}
|
||||||
|
|
||||||
// ── Provider / Model endpoints ──
|
// ── Provider / Model endpoints ──
|
||||||
|
|
||||||
export async function fetchAvailableModels(
|
export async function fetchAvailableModels(
|
||||||
|
|||||||
Reference in New Issue
Block a user