diff --git a/chat.go b/chat.go index 1179cfb..2609024 100644 --- a/chat.go +++ b/chat.go @@ -14,11 +14,12 @@ 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"` + 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"` } type TextFile struct { diff --git a/exa.go b/exa.go index cbba3a1..5f1e94d 100644 --- a/exa.go +++ b/exa.go @@ -18,9 +18,14 @@ type ExaResult struct { Summary string `json:"summary"` } +type ExaCost struct { + Total float64 `json:"total"` +} + type ExaResults struct { RequestID string `json:"requestId"` Results []ExaResult `json:"results"` + Cost ExaCost `json:"costDollars"` } func (e *ExaResult) String() string { diff --git a/search.go b/search.go index 4d4f876..1f15ca6 100644 --- a/search.go +++ b/search.go @@ -116,6 +116,8 @@ func HandleSearchWebTool(ctx context.Context, tool *ToolCall) error { return nil } + tool.Cost = results.Cost.Total + if len(results.Results) == 0 { tool.Result = "error: no search results" @@ -146,6 +148,8 @@ func HandleFetchContentsTool(ctx context.Context, tool *ToolCall) error { return nil } + tool.Cost = results.Cost.Total + if len(results.Results) == 0 { tool.Result = "error: no search results" diff --git a/static/js/chat.js b/static/js/chat.js index 7477ea6..5b292b7 100644 --- a/static/js/chat.js +++ b/static/js/chat.js @@ -407,16 +407,6 @@ #updateToolHeight() { const result = this.#_tool.querySelector(".result"); - try { - const clone = result.cloneNode(); - - setTimeout(() => { - console.log(clone, clone.getBoundingClientRect(), clone.scrollHeight, clone.height); - }, 0); - } catch(err) { - console.warn(err); - } - this.#_tool.style.setProperty("--height", `${result.scrollHeight}px`); } @@ -1047,6 +1037,8 @@ message.setTool(chunk.text); if (chunk.text.done) { + totalCost += chunk.text.cost || 0; + finish(); }