fix(agent): chat console keeps its thread across turns and reloads (#1859)
Three user-reported failures in the assistant panel, one root cause each: 1. "The chat asks what I'm referring to" when continuing a thread. The single-call console (general.help, AskConsole -> /api/agent/ask) was stateless since the 08-20 model-agnostic cutover: conversationId was only the tool actor id, so every turn was answered blind, reload or not. The provider-agnostic GenerateTextRequest gains an optional `history` (real message turns before the prompt, in both the Anthropic-family and the OpenAI-compatible adapter; absent/empty leaves the request byte-identical to the single-turn call). The route loads the thread's earlier turns server-side (loadChatHistory: text only, hidden and tool rows dropped, alternation repaired, newest 16 rows / 10k chars) before writing the new question, and hands them to the model. 2. A full page reload (the deploy prompt's "Ladda om") closed the docked panel and dropped the thread from view. The panel now remembers its open thread per tab in sessionStorage (lib/agent-panel/session-restore) and the provider reopens it on mount; the sheet loads it exactly like a pick from "Tidigare konversationer". Close and "Ny konversation" forget it; a thread that no longer opens is dropped instead of retried on every reload. 3. "Can't type any more" once the update banner shows. DeployReloadPrompt's full-width wrapper sits at z-[60] after the panel in DOM order and swallowed clicks on the panel's composer; only the card takes input now. Claude-Session: https://claude.ai/code/session_01VjoXN3xdNZrHZeYA6qMi3g Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Jakob Wennberg
Claude Fable 5
parent
f75ea2384d
commit
3edbf0a2e3
@@ -66,11 +66,29 @@ export interface AiToolDef {
|
||||
execute: (args: Record<string, unknown>) => Promise<unknown>
|
||||
}
|
||||
|
||||
/**
|
||||
* One earlier turn of a conversation, text only. Sent to the model as a real
|
||||
* message turn (not inlined into the prompt), so the answer can refer back
|
||||
* to what was said without the caller re-describing it.
|
||||
*/
|
||||
export interface AiChatTurn {
|
||||
role: 'user' | 'assistant'
|
||||
text: string
|
||||
}
|
||||
|
||||
export interface GenerateTextRequest {
|
||||
tier: AiTier
|
||||
system?: string
|
||||
prompt: string
|
||||
maxTokens: number
|
||||
/**
|
||||
* Earlier turns of the same conversation, oldest first, placed before
|
||||
* `prompt` (which stays the final user message). Callers must hand over a
|
||||
* clean alternation that starts with a user turn (see
|
||||
* lib/agent/ask/persist.ts loadChatHistory); the services do not repair it.
|
||||
* Absent or empty leaves the request exactly as a single-turn call.
|
||||
*/
|
||||
history?: AiChatTurn[]
|
||||
/**
|
||||
* Read-only tools the model may call to gather data before answering. When
|
||||
* present AND the backend supports tool use (capabilities.toolUse), the
|
||||
|
||||
Reference in New Issue
Block a user