fix(ui): show chat send errors

This commit is contained in:
Peter Steinberger
2026-01-04 17:11:42 +00:00
parent 2694e59ba6
commit 3fed0ac2e8
4 changed files with 34 additions and 6 deletions

View File

@@ -391,6 +391,7 @@ export function renderApp(state: AppViewState) {
connected: state.connected,
canSend: state.connected,
disabledReason: chatDisabledReason,
error: state.lastError,
sessions: state.sessionsResult,
onRefresh: () => {
state.resetToolStream();

View File

@@ -756,8 +756,9 @@ export class ClawdbotApp extends LitElement {
}
async handleSendChat() {
if (!this.connected) return;
await sendChat(this);
void loadChatHistory(this);
const ok = await sendChat(this);
if (ok) void loadChatHistory(this);
this.scheduleChatScroll();
}
async handleWhatsAppStart(force: boolean) {

View File

@@ -41,10 +41,20 @@ export async function loadChatHistory(state: ChatState) {
}
}
export async function sendChat(state: ChatState) {
if (!state.client || !state.connected) return;
export async function sendChat(state: ChatState): Promise<boolean> {
if (!state.client || !state.connected) return false;
const msg = state.chatMessage.trim();
if (!msg) return;
if (!msg) return false;
const now = Date.now();
state.chatMessages = [
...state.chatMessages,
{
role: "user",
content: [{ type: "text", text: msg }],
timestamp: now,
},
];
state.chatSending = true;
state.chatMessage = "";
@@ -59,11 +69,22 @@ export async function sendChat(state: ChatState) {
deliver: false,
idempotencyKey: runId,
});
return true;
} catch (err) {
const error = String(err);
state.chatRunId = null;
state.chatStream = null;
state.chatMessage = msg;
state.lastError = String(err);
state.lastError = error;
state.chatMessages = [
...state.chatMessages,
{
role: "assistant",
content: [{ type: "text", text: "Error: " + error }],
timestamp: Date.now(),
},
];
return false;
} finally {
state.chatSending = false;
}

View File

@@ -15,6 +15,7 @@ export type ChatProps = {
connected: boolean;
canSend: boolean;
disabledReason: string | null;
error: string | null;
sessions: SessionsListResult | null;
onRefresh: () => void;
onDraftChange: (next: string) => void;
@@ -68,6 +69,10 @@ export function renderChat(props: ChatProps) {
</div>`
: nothing}
${props.error
? html`<div class="callout danger" style="margin-top: 12px;">${props.error}</div>`
: nothing}
<div class="chat-thread" role="log" aria-live="polite">
${props.loading ? html`<div class="muted">Loading chat…</div>` : nothing}
${props.messages.map((m) => renderMessage(m))}