fix(ui): show chat send errors
This commit is contained in:
@@ -391,6 +391,7 @@ export function renderApp(state: AppViewState) {
|
|||||||
connected: state.connected,
|
connected: state.connected,
|
||||||
canSend: state.connected,
|
canSend: state.connected,
|
||||||
disabledReason: chatDisabledReason,
|
disabledReason: chatDisabledReason,
|
||||||
|
error: state.lastError,
|
||||||
sessions: state.sessionsResult,
|
sessions: state.sessionsResult,
|
||||||
onRefresh: () => {
|
onRefresh: () => {
|
||||||
state.resetToolStream();
|
state.resetToolStream();
|
||||||
|
|||||||
@@ -756,8 +756,9 @@ export class ClawdbotApp extends LitElement {
|
|||||||
}
|
}
|
||||||
async handleSendChat() {
|
async handleSendChat() {
|
||||||
if (!this.connected) return;
|
if (!this.connected) return;
|
||||||
await sendChat(this);
|
const ok = await sendChat(this);
|
||||||
void loadChatHistory(this);
|
if (ok) void loadChatHistory(this);
|
||||||
|
this.scheduleChatScroll();
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleWhatsAppStart(force: boolean) {
|
async handleWhatsAppStart(force: boolean) {
|
||||||
|
|||||||
@@ -41,10 +41,20 @@ export async function loadChatHistory(state: ChatState) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function sendChat(state: ChatState) {
|
export async function sendChat(state: ChatState): Promise<boolean> {
|
||||||
if (!state.client || !state.connected) return;
|
if (!state.client || !state.connected) return false;
|
||||||
const msg = state.chatMessage.trim();
|
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.chatSending = true;
|
||||||
state.chatMessage = "";
|
state.chatMessage = "";
|
||||||
@@ -59,11 +69,22 @@ export async function sendChat(state: ChatState) {
|
|||||||
deliver: false,
|
deliver: false,
|
||||||
idempotencyKey: runId,
|
idempotencyKey: runId,
|
||||||
});
|
});
|
||||||
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
const error = String(err);
|
||||||
state.chatRunId = null;
|
state.chatRunId = null;
|
||||||
state.chatStream = null;
|
state.chatStream = null;
|
||||||
state.chatMessage = msg;
|
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 {
|
} finally {
|
||||||
state.chatSending = false;
|
state.chatSending = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ export type ChatProps = {
|
|||||||
connected: boolean;
|
connected: boolean;
|
||||||
canSend: boolean;
|
canSend: boolean;
|
||||||
disabledReason: string | null;
|
disabledReason: string | null;
|
||||||
|
error: string | null;
|
||||||
sessions: SessionsListResult | null;
|
sessions: SessionsListResult | null;
|
||||||
onRefresh: () => void;
|
onRefresh: () => void;
|
||||||
onDraftChange: (next: string) => void;
|
onDraftChange: (next: string) => void;
|
||||||
@@ -68,6 +69,10 @@ export function renderChat(props: ChatProps) {
|
|||||||
</div>`
|
</div>`
|
||||||
: nothing}
|
: 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">
|
<div class="chat-thread" role="log" aria-live="polite">
|
||||||
${props.loading ? html`<div class="muted">Loading chat…</div>` : nothing}
|
${props.loading ? html`<div class="muted">Loading chat…</div>` : nothing}
|
||||||
${props.messages.map((m) => renderMessage(m))}
|
${props.messages.map((m) => renderMessage(m))}
|
||||||
|
|||||||
Reference in New Issue
Block a user