Skip to content

AI: replace single-turn AIRequest with a real messages array #240

Description

@remcostoeten

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions