Commit Graph
65 Commits
Author SHA1 Message Date
Guoyu Su e8fae013bd fix(ai): harden MiniMax reasoning and tool replay 2026-08-12 10:27:25 +08:00
lewis c72b429899 feat(ai): add Qoder CLI provider 2026-08-11 21:33:15 +08:00
Guoyu Su 1a3645a04d feat(ai): add CodeBuddy Code CLI provider 2026-08-10 18:27:37 +08:00
chenow9andt8y2 d08189ba7d feat(ai): add Grok CLI as a Desktop no-API-key provider
* feat(ai): add Grok CLI as a Desktop no-API-key provider

Add grok-cli alongside Codex/Claude Code/Pi, with path/env settings,
isolated MCP-scoped headless runs, model listing, and connection test.

* feat(ai): expose Grok CLI reasoning effort like Codex

Attach low/medium/high effort capabilities to Grok models for the
assistant effort menu, wire resolve_model_effort for grok-cli, and
use the monochrome Grok mark icon.

* i18n: add Grok CLI error messages for remaining locales

Fill grokCli* cliErrors strings in es, it, ja, ko, pt-BR, and zh-TW
to match en/zh-CN and satisfy i18n autofill CI.

* fix(ai): align Grok CLI headless with official Build flags

Address review feedback on PR #5494:
- Use streaming-json + CliAgentJsonlDialect::GrokStreamingJson
- Switch permission to --always-approve and MCPTool(dbx__*) rules
- Prefer --effort over --reasoning-effort; keep --prompt-file

Verified with unit tests and a local headless e2e against grok 1.0.

* style(ai): fix rustfmt for Grok CLI provider files

* test(ai): fix Grok CLI entry in provider ordering spec

* fix(ai): harden grok CLI error wording and config schema

Add 'not signed in' to classify_grok_run_error and test_grok_connection
auth detection — real @xai-official/grok 1.0.0 emits this exact wording
on headless auth failure (verified against the shipped binary).

Remove invalid config.toml fields: permission_mode='always-approve'
(not a valid enum; auto-approve is driven by --always-approve flag) and
startup_timeout_sec/tool_timeout_sec/enabled_tools (not mcp_servers
schema fields per 'grok mcp add').

---------

Co-authored-by: t8y2 <1156263951@qq.com>
2026-08-10 10:54:27 +08:00
Abeautifulsnow 0402fea37b feat(ai): make default assistant mode (Ask/Agent) configurable 2026-08-10 01:06:44 +08:00
Guoyu Su 36e5fa4f4c feat(ai): add Cursor CLI provider 2026-08-08 11:08:18 +08:00
Guoyu Su 309e3aef5e feat(ai): add OpenCode CLI provider 2026-08-07 17:06:03 +08:00
Eden 4a2f8f1f33 fix(ai): preserve Gemini thought signatures across tool calls 2026-07-31 16:49:40 +08:00
Octopus 0234470466 feat(ai): add MiniMax provider preset 2026-07-30 23:05:12 +08:00
Guoyu Su 9571519179 feat(ai): add Anthropic-compatible provider 2026-07-29 20:38:09 +08:00
Abeautifulsnow 52d5c99a92 fix(ai): improve API retry handling 2026-07-29 16:16:39 +08:00
Guoyu Su de44fddf29 feat(ai): add Pi Coding Agent provider 2026-07-29 02:10:06 +08:00
Guoyu Su c7e7b7c9d9 feat(ai): unify model discovery and effort handling 2026-07-28 21:37:55 +08:00
t8y2 054702e223 fix(ai): trim API keys before authentication 2026-07-28 13:19:04 +08:00
zipg a8e5e8d8f9 fix(ai): normalize Claude 1M model suffix for HTTP 2026-07-23 17:06:15 +08:00
zipg 21e9578f78 fix(ai): improve connection test diagnostics 2026-07-23 12:51:19 +08:00
zipg c19c4b9be6 fix(ai): finish compatible streams after finish reason 2026-07-18 16:38:01 +08:00
二丫讲梵 fec458dc2d feat(ai): allow empty API keys for self-hosted providers 2026-07-17 23:56:33 +08:00
Guoyu Su d3947d246c feat(ai): add Claude Code CLI provider 2026-07-17 01:17:06 +08:00
lexmin0412 dd3a2e30a4 feat(ai): support multiple configurations and models 2026-07-16 17:59:40 +08:00
t8y2 6eedf5eb39 fix(ai): omit extra body from OpenAI requests 2026-07-14 21:56:49 +08:00
t8y2 bdc30bae28 fix(ai): use Gemini streaming endpoint in connection test 2026-07-11 09:30:23 +08:00
zipg cb5ed9baf8 fix(ai): disable Ollama thinking with reasoning effort 2026-07-10 23:05:08 +08:00
lexmin0412 f590a727a0 fix(ai): use correct DeepSeek API format to disable thinking 2026-07-09 18:12:05 +08:00
Abeautifulsnow ffc0279352 fix(ai): make stop button actually cancel the agent stream
The stop button called aiCancelStream -> notify_one(), but the four
stream_*_with_tools SSE loops only `break`ed and returned Ok(token_usage)
when cancelled. run_agent_loop treated that as a normal completed turn and
kept going (often into contract-repair or the next turn), so isGenerating
stayed true and a single click did not stop the agent.

Return Err(AGENT_CANCELLED_ERROR) from the cancel branch so the existing
Err-cancel match arm sets loop_exit = Cancelled and stops the loop cleanly,
preserving whatever was streamed so far.

Additional:
- Promote AGENT_CANCELLED_ERROR to a shared `pub const` in ai.rs; agent_loop
  now references ai::AGENT_CANCELLED_ERROR.
- Check cancellation before executing requested tools, so a stop landing
  between stream-end and tool execution is honored.
- Wire cancellation into the text-only fallback (previously `_cancelled`,
  ignored) via tokio::select! racing ai::complete against cancelled.notified().

Known limitation left: in-flight tool execution (e.g. execute_query) is
still not interruptible mid-call.
2026-07-08 18:44:13 +08:00
zipg d90847bbba feat(ai): support SQL library file references 2026-07-07 15:39:10 +08:00
t8y2 3e01840825 fix(ai): remove temperature from AI requests 2026-07-02 17:58:35 +08:00
二丫讲梵 f871e00330 feat(ai): support OpenAI max completion tokens 2026-07-02 01:15:49 +08:00
jischeng c6719eec55 fix(ai): preserve tool name when OpenAI-compatible provider re-sends empty id (#2196)
GLM-5.2 (and potentially other OpenAI-compatible providers) send id="" on
every tool-call delta after the first, while only the first delta carries
function.name. The streaming parser treated Some("") as a valid id and
emitted ToolCallStart for every chunk; the accumulator's insert then
overwrote the previously-correct name with "", producing "Unknown tool:"
errors and trapping the agent in a retry loop until the 30-turn limit.

Two fixes, mutually reinforcing:

1. OpenAI parser: only treat a non-empty id as a genuine tool-call start
   (filter out id=""), so subsequent deltas no longer trigger ToolCallStart.

2. Accumulator: merge ToolCallStart into an existing entry instead of
   blind insert — keep the known name when the new one is empty, and
   preserve accumulated arguments. Defense in depth for any other provider
   that re-sends id or splits name across chunks.

Added a regression test that feeds a re-sent ToolCallStart with an empty
name and asserts the name and arguments survive.

Verified end-to-end with the real GLM-5.2 provider: Unknown tool count
dropped from 12+ to 0, and the agent completed in 3 turns instead of
hitting the 30-turn safety limit.
2026-06-30 19:52:43 +08:00
LC b951d3a50a fix(ai): 修复 OpenAI Responses API 请求和流解析 (#2149) 2026-06-29 21:21:45 +08:00
t8y2 2d2284a0ef fix(ai): preserve UTF-8 in streamed responses 2026-06-29 01:25:43 +08:00
huangyemin 4ad6723512 feat(ai): support custom Anthropic messages API 2026-06-27 10:02:13 +08:00
Abeautifulsnow 5f2b24d700 fix(ai): enforce SQL task contracts structurally instead of keyword heuristics
* fix: enforce agent task contracts

* fix(ai): enforce SQL task contracts structurally
2026-06-26 13:18:49 +08:00
t8y2 fe01de3f17 fix(ai): round temperature precision 2026-06-26 00:58:53 +08:00
Oleksandr Liakhevych 034cce47e0 fix(ai): Codex CLI provider reliability fixes for DBX Desktop
* fix(ai): resolve Codex CLI from shell PATH on macOS

* fix(ai): hide Codex CLI subprocess windows on Windows

* feat(ai): allow to set environment variable for Codex CLI

* fix(ai): parse Codex MCP tool events

* fix(mcp): honor Postgres TLS settings in direct queries
2026-06-25 22:31:14 +08:00
t8y2 cc7b034341 fix(ai): omit Kimi test connection temperature 2026-06-23 12:05:50 +08:00
lexmin0412 c026647785 fix(ai): handle non-JSON error response in AI connection test
Replace res.json() with res.text() + fallback JSON parse so that
non-JSON error bodies (e.g. HTTP 502 with empty body) no longer
produce the unclear 'error decoding response body' message.

Also add 502/503/504 to classify_error for proper category prefixes.
2026-06-23 12:04:46 +08:00
t8y2 c9ab2fb60a fix(ci): sync diagnostics and AI sampling 2026-06-19 14:49:34 +08:00
t8y2 dc90a80468 fix(ai): enable temperature for Kimi models and default to 1.0 2026-06-19 11:36:29 +08:00
Oleksandr Liakhevych 4f5d09aaa8 feat(ai): add Codex CLI as a no-API-key AI provider for Desktop
* codex cli provider

* fixes

* mcp check

* reasoning

* simplify

* minor fixes
2026-06-19 08:51:10 +08:00
t8y2 a9d1b48dd5 fix(ai): skip temperature and thinking-disable for Kimi K2.5+ models 2026-06-18 12:32:10 +08:00
t8y2 a0136c5bd7 fix(ai): parse ollama reasoning stream chunks 2026-06-17 17:13:48 +08:00
t8y2 95b03998d1 fix(tests): reorder imports for better readability in AI module tests 2026-06-16 19:23:31 +08:00
iiusky 57f1b6cedc fix(ai): avoid empty Claude system field rejected by Anthropic
Anthropic rejects requests whose system field is an empty string with
"system: text content blocks must be non-empty". The connection test
hardcoded an empty system, and regular completion/stream requests sent
an empty system_prompt when none was configured.

Add a claude_system_prompt() helper that substitutes a non-empty default
for empty or whitespace-only prompts, and apply it to all Claude request
sites. Covered by a unit test.
2026-06-16 18:52:02 +08:00
t8y2 c57e18bf3e fix: resolve clippy warnings and missing struct fields in tests 2026-06-16 00:55:32 +08:00
Abeautifulsnow c300336281 feat(ai): context window management and token usage tracking
* @
feat(ai): add conversation context management and token usage tracking (Phase 4)

## Background
Phase 4 of AI agent loop upgrade: token usage extraction from LLM responses,
cost estimation display, and automatic context window management (summarization
when approaching limits).

## Changes

### Backend (Rust)
- New token_usage::TokenUsage — cross-turn token accumulation
- New agent_loop::maybe_compact — proactive context compaction: token estimation
  → cut-point selection → LLM summarization → fallback summary
  → tool-pair integrity protection → drain/insert
- New agent_loop::context_window_for_model — auto-detect context window by model
- New agent_loop::is_context_length_error — detect upstream context-length errors
- New agent_loop::compact_tool_result_for_context — JSON/text sampling for large results
- Modified agent_loop::run_agent_loop — pre-turn compaction check, retry on context error
- Modified agent_events::AgentEnd — split total_tokens into input_tokens/output_tokens
- New agent_events::ContextCompacted — compaction event with metrics
- New AiConfig.context_window — user-configurable context window size
- New AiChatMessage.kind — context summary message marker
- Modified stream_with_tools & 3 provider stream functions — extract TokenUsage
  - Claude: message_start(input) + message_delta(output)
  - OpenAI: stream_options { include_usage } → final usage chunk
  - Gemini: usageMetadata per chunk, keep last

### Frontend (TypeScript/Vue)
- AiAssistant.vue: token + cost display row, estimateCost() with 7 model families,
  contextCompacted UI step, pendingCompaction deferred apply,
  messagesForAgentHistory post-compaction history reconstruction
- EditorSettingsDialog.vue: contextWindow input (min=1000, auto-detect)
- settingsStore.ts: AiConfig.contextWindow field
- tauri.ts: AgentEvent type updates, AiChatMessage.kind
- i18n: 6 new keys in en.ts and zh-CN.ts

## Fixed Issues
- messages[0] dropped from LLM context after compaction
- estimate_text_tokens hard threshold causing 2.8x estimate jump
- context_compacted event field semantics mismatch with frontend insert position
- validate_summary English-only keywords causing fallback on non-English LLMs
- Stale agentTokens after conversation switch
@

* remove cost computation logic
2026-06-15 18:55:22 +08:00
t8y2 c6e50f80f2 fix(ai): accept thinking/reasoning deltas as first stream chunk in connection test 2026-06-12 20:40:40 +08:00
t8y2 484658c6b7 feat(ai): streaming probe for connection test with latency measurement 2026-06-12 19:29:55 +08:00
t8y2 2395727b6b fix(ai): auto-add /v1 prefix for bare-origin OpenAI-compatible endpoints 2026-06-12 16:10:42 +08:00
Abeautifulsnow 082e3bb4eb feat(ai): add agent tool calling loop 2026-06-12 13:18:36 +08:00