fix(ui): show chat send errors
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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))}
|
||||
|
||||
Reference in New Issue
Block a user