fix(cli): auto-create conversation on TUI start when no -c flag given
All checks were successful
ci/woodpecker/pr/ci Pipeline was successful
ci/woodpecker/push/ci Pipeline was successful

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:
2026-03-16 08:09:04 -05:00
parent 193d171acb
commit 1214a4cce7
2 changed files with 43 additions and 1 deletions

View File

@@ -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
const { render } = await import('ink');
const React = await import('react');
@@ -152,7 +169,7 @@ program
render(
React.createElement(TuiApp, {
gatewayUrl: opts.gateway,
conversationId: opts.conversation,
conversationId,
sessionCookie: session.cookie,
initialModel: opts.model,
initialProvider: opts.provider,

View File

@@ -110,6 +110,31 @@ async function handleResponse<T>(res: Response, errorPrefix: string): Promise<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 ──
export async function fetchAvailableModels(