From be17a801f870b8e4aaa682caf33ea43ce1af1860 Mon Sep 17 00:00:00 2001 From: Laura Date: Sat, 30 Aug 2025 00:25:48 +0200 Subject: [PATCH] improvements --- chat.go | 16 +++++++++------- static/css/chat.css | 2 ++ static/js/chat.js | 5 ++++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/chat.go b/chat.go index 6dca2f1..86623f6 100644 --- a/chat.go +++ b/chat.go @@ -14,12 +14,13 @@ import ( ) type ToolCall struct { - ID string `json:"id"` - Name string `json:"name"` - Args string `json:"args"` - Result string `json:"result,omitempty"` - Done bool `json:"done,omitempty"` - Cost float64 `json:"cost,omitempty"` + ID string `json:"id"` + Name string `json:"name"` + Args string `json:"args"` + Result string `json:"result,omitempty"` + Done bool `json:"done,omitempty"` + Invalid bool `json:"invalid,omitempty"` + Cost float64 `json:"cost,omitempty"` } type TextFile struct { @@ -323,7 +324,8 @@ func HandleChat(w http.ResponseWriter, r *http.Request) { return } default: - return + tool.Invalid = true + tool.Result = "error: invalid tool call" } tool.Done = true diff --git a/static/css/chat.css b/static/css/chat.css index 6d1c0e5..c4e5174 100644 --- a/static/css/chat.css +++ b/static/css/chat.css @@ -368,6 +368,8 @@ body:not(.loading) #loading { width: calc(800px - 24px); } +.message .tool.invalid, +.message .tool .result.error, .message .text .error { color: #ed8796; } diff --git a/static/js/chat.js b/static/js/chat.js index 1aae6ca..f397ace 100644 --- a/static/js/chat.js +++ b/static/js/chat.js @@ -493,7 +493,7 @@ if (!only || only === "tool") { if (this.#tool) { - const { name, args, result, cost } = this.#tool; + const { name, args, result, cost, invalid } = this.#tool; const _name = this.#_tool.querySelector(".name"), _arguments = this.#_tool.querySelector(".arguments"), @@ -508,8 +508,11 @@ _cost.textContent = cost ? `${formatMoney(cost)}` : ""; + _result.classList.toggle("error", result?.startsWith("error: ")); _result.innerHTML = render(result || "*processing*"); + this.#_tool.classList.toggle("invalid", invalid); + this.#_tool.setAttribute("data-tool", name); } else { this.#_tool.removeAttribute("data-tool");