AIRequest (apps/desktop/src-tauri/src/database/services/ai/mod.rs:292) carries a single prompt: String. Chat history is therefore flattened client-side into a USER: / ASSISTANT: transcript in packages/studio/src/features/ai-assistant/build-prompt.ts (buildChatPrompt), and the chat-mode system prompt in prompts.rs has to be told about that shape so it only answers the trailing turn.
Consequences:
- Providers cannot distinguish real turns, so role-specific handling (system vs user vs assistant) is lost.
- Anthropic and OpenAI prompt caching cannot be used — caching keys off a stable message prefix.
- No path to tool use / function calling later.
- Token accounting in
usage.rs sees one opaque blob.
Proposed work:
- Add
messages: Vec<AiMessage> (role + content) to AIRequest, keeping prompt as a deprecated fallback for one release so bindings consumers do not break.
- Map messages properly in each client:
compat.rs (messages array), anthropic.rs (system + messages), gemini.rs (contents with roles), ollama.rs (chat endpoint).
- Move history assembly out of
build-prompt.ts into the request; keep the UI-context block as a system message.
- Drop the
USER:/ASSISTANT: transcript instructions from the chat-mode prompt.
- Regenerate bindings:
cargo test --lib bindings::tests::export_bindings -- --ignored --exact.
Follow-up unlocked by this: prompt caching for the schema-context block, which is the largest and most repeated part of every request.
AIRequest(apps/desktop/src-tauri/src/database/services/ai/mod.rs:292) carries a singleprompt: String. Chat history is therefore flattened client-side into aUSER:/ASSISTANT:transcript inpackages/studio/src/features/ai-assistant/build-prompt.ts(buildChatPrompt), and the chat-mode system prompt inprompts.rshas to be told about that shape so it only answers the trailing turn.Consequences:
usage.rssees one opaque blob.Proposed work:
messages: Vec<AiMessage>(role + content) toAIRequest, keepingpromptas a deprecated fallback for one release so bindings consumers do not break.compat.rs(messagesarray),anthropic.rs(system+messages),gemini.rs(contentswith roles),ollama.rs(chat endpoint).build-prompt.tsinto the request; keep the UI-context block as a system message.USER:/ASSISTANT:transcript instructions from the chat-mode prompt.cargo test --lib bindings::tests::export_bindings -- --ignored --exact.Follow-up unlocked by this: prompt caching for the schema-context block, which is the largest and most repeated part of every request.