Commit Graph
44 Commits
Author SHA1 Message Date
lexmin0412 bc409cffc0 feat(ai): add vector DB assistant tools 2026-06-29 11:46:41 +08:00
zipg 28e7cdfacc improve: 统一表单控件小圆角样式 2026-06-28 00:51:45 +08:00
t8y2 bc5ae91abd fix(ai): open assistant links externally 2026-06-27 16:40:04 +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
二丫讲梵 16f546ada1 feat(AiAssistant): 增加输入框高度调整功能,AI 回答同时支持输入
- 新增输入框高度拖拽调整功能
- 保存用户偏好的输入框高度
- 优化输入框在窗口调整时的响应
2026-06-25 22:13:04 +08:00
二丫讲梵 c2aeaaa8f7 feat(ai): 添加 Codex CLI 命令解析和环境变量处理功能
- 实现了对 Codex CLI 命令的解析,支持路径解析和环境变量设置
- 增加了对命令环境的处理,确保正确的执行路径
- 添加了相关的单元测试,确保功能的正确性
2026-06-25 16:47:43 +08:00
zipgandstaff 7ae024ffd4 优化 SearchableSelect 滚动逻辑和 AI 模型选择器布局
Co-authored-by: staff <staff@qimaos-MacBook-Pro.local>
2026-06-23 20:19:22 +08:00
zipgandstaff 25bac0c67a 优化 AI 模型选择控件布局
Co-authored-by: staff <staff@qimaos-MacBook-Pro.local>
2026-06-23 19:56:02 +08:00
Abeautifulsnow bbd3ccf864 fix(ai): add inline proposal confirmation buttons
* fix(ai): add quick proposal confirmation buttons (all locales)

When the assistant proposes an action, render Yes/No buttons below the
message so the user does not need to type a short reply — fixing the
issue where short replies caused the LLM to re-ask instead of executing.

- aiProposalDetect.ts: pure detectors for proposal sentences/short replies
- AiAssistant.vue: inline Yes/No buttons on last assistant proposal message
- ai.ts: system-prompt rule to skip re-confirmation on short affirmatives
- i18n: 3 keys added to all 7 locales (en/zh-CN/zh-TW/ja/es/it/pt-BR)

Tests: 55/55. TypeCheck: passed.

* fix(ai): add i18n keys and UI changes for proposal confirmation
2026-06-23 18:25:57 +08:00
74df246d7e feat(ai): improve model selection with searchable dropdown
* fix(ui): toast 消息支持换行显示

- 添加 max-w-3xl 限制最大宽度
- 使用 whitespace-pre-wrap 允许自动换行
- 添加 break-words 防止长单词溢出

* fix(ai): 优化模型选择下拉列表

---------

Co-authored-by: t8y2 <1156263951@qq.com>
Co-authored-by: staff <staff@qimaos-MacBook-Pro.local>
2026-06-22 17:22:17 +08:00
Abeautifulsnow 629c92bf7e feat: prompt input history navigation with ↑/↓ arrow keys in AI assistant 2026-06-22 10:50:18 +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
Abeautifulsnow 320336e84e feat(ai): add inline model selector to AI assistant toolbar 2026-06-18 18:10:28 +08:00
t8y2 03e5e27c79 fix(ai): prevent marked parse error from crashing chat during streaming 2026-06-18 10:30:28 +08:00
Libon f1b8579994 style: improve UI interface 2026-06-18 02:01:00 +08:00
Abeautifulsnow ec28005f20 feat(agent): safety check display
* fix(i18n): add missing agent tool step translations for zh-TW, pt-BR, it, ja

* propagate explainData to agent step items for ExplainPlanViewer

* feat(ai): show safety check result for execute_query tool steps
2026-06-16 13:56:16 +08:00
Abeautifulsnow a1f15f6c45 fix(ai): propagate explainData and add missing agent i18n keys
Thanks @Abeautifulsnow!
2026-06-16 10:28:35 +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
Abeautifulsnow d845a318c6 feat(ai-agent): Phase 3 — explain_query tool, parallel/sequential execution, DB gating (#1187)
- Add explain_query tool with structured EXPLAIN result, gated on supports_explain_plan()
- Add supports_sql_query() to gate execute_query/get_sample_data for non-SQL DBs (Redis, ES, MongoDB, etc.)
- Split agent loop tool dispatch: execute_query runs sequentially, all others run in parallel via join_all
- Wire explain_query result button to ExplainPlanViewer in AiAssistant + App.vue
- Fix O(n²) agentSteps rebuild: incremental O(1) push per event during streaming
- finally block falls back to full rebuild only when streaming push did not occur
2026-06-15 13:14:59 +08:00
t8y2 6a87f31fdc feat(ai): add resizable textarea with drag handle 2026-06-13 15:13:19 +08:00
runstone 094412d956 fix error 2026-06-12 19:00:27 +08:00
runstone 40f0f98540 Merge branch 'main' of https://github.com/Abeautifulsnow/dbx into feat/ai-agent-loop-phase1 2026-06-12 18:52:05 +08:00
runstone 7df7fd9235 feat(ai): add tool result collapsible UI and fix agent mode prompt
AiAssistant.vue:
- Tool call steps now support click-to-expand/collapse for SQL args
  and results (expandedSteps set); chevron rotates on open
- Remove fixed-open result display (was always visible, no toggle)
- Max result height raised to 48 (max-h-48) with scroll

ai.ts (buildModePromptLines agent branch):
- Replace vague "prioritize SQL" hint with explicit tool-use
  instruction: must call execute_query, not just emit SQL text
- List available tools (list_tables, get_columns, execute_query,
  get_sample_data) so LLM knows what it can call
- Clarify allowed statement types for execute_query
2026-06-12 18:27:28 +08:00
runstone 100124da3e feat(ai): Phase 2 SQL 风险分类 + Agent 模式工具调用结果渲染
后端:
  - 新增 sql_risk.rs:基于 sqlparser AST 的 SQL 风险分类(ReadOnly/Write/Ddl/Transaction)
  - agent_tools.rs:新增 execute_query 和 get_sample_data 工具,写操作/DDL 被风险分类阻止
  - agent_loop.rs:支持 is_agent_mode 参数,Agent 模式下暴露全部工具,Ask 模式仅暴露只读工具
  - agent_loop/web/tauri:mode 参数全链路传递(前端→HTTP→Tauri→Rust)

  前端:
  - AiAgentStepItem 接口扩展:toolName/toolArgs/toolResult/isError 字段
  - AiAssistant.vue:工具调用结果实时+最终渲染,SQL 查询结果/错误信息展示
  - ai.ts/http.ts/tauri.ts:mode 参数透传到后端
2026-06-12 17:42:23 +08:00
Abeautifulsnow 082e3bb4eb feat(ai): add agent tool calling loop 2026-06-12 13:18:36 +08:00
runstone 2d75667b9a feat(ai): upgrade agent loop tool calling to true SSE streaming
Move tool calling from non-streaming (complete) API calls to real
streaming SSE, so text, reasoning, and tool call arguments all arrive
incrementally — users see the AI think and act in real time.

- Extract ~370 lines of non-streaming tool-call functions from
  agent_loop.rs (call_with_tools, call_openai_with_tools,
  call_claude_with_tools, call_gemini_with_tools) and replace with
  a single ai::stream_with_tools() dispatch call.

- Add streaming-with-tools infrastructure to ai.rs (~550 lines):
  - StreamToolEvent enum: Chunk, ToolCallStart, ToolCallDelta,
    ToolCallComplete — provider-agnostic, feeds into the
    StreamingToolCallAccumulator
  - stream_claude_with_tools(): parse SSE content_block_start/delta/
    stop events, incremental input_json_delta for tool arguments
  - stream_openai_with_tools(): parse SSE delta.tool_calls with
    incremental function.arguments
  - stream_gemini_with_tools(): parse SSE functionCall (Gemini
    sends complete objects, not deltas — emit as one chunk)
  - Cancellation support via tokio::select! in every streaming loop
  - Extended timeout for reasoning models (600s vs 120s)

- StreamingToolCallAccumulator: collect partial tool call fragments
  from streaming deltas, then deserialize into complete ToolCall
  objects in index order once the stream ends.
2026-06-12 11:43:09 +08:00
runstone 9ab41795d6 @
feat(ai): add agent loop with tool calling, fix connection routing and Gemini compatibility

## 背景说明
将 dbx AI 助手从单次 SQL 文本生成器升级为具备 tool calling 的数据库 Agent。
Phase 1 实现 Agent Loop 框架 + 只读工具(list_tables、get_columns)。
参考:Pi agent-core,.trellis/tasks/06-11-feat-ai-agent-loop-tool-calling-upgrade

## 修改内容
- 新增 agent_loop.rs:Agent Loop 核心,支持 OpenAI/Claude/Gemini Provider 的 tool calling,最大 10 轮,Ollama 自动降级为 text-only
- 新增 agent_tools.rs:read_only_tools (list_tables, get_columns) 的工具定义与执行器
- 新增 agent_events.rs:AgentEvent/ToolCall/ToolResult/ToolDefinition 类型定义
- 修改 ai.rs:AiMessage 新增 tool_call_id 字段
- 修改 lib.rs:注册 agent_events、agent_loop、agent_tools 模块
- 修改 routes/ai.rs & commands/ai.rs:新增 ai_agent_stream SSE 端点
- 修改 tauri.ts & http.ts:新增 AgentEvent 类型与 aiAgentStream 函数
- 修改 api.ts:注册 aiAgentStream 转发
- 修改 ai.ts:新增 runAgentStream,AiContext 增加 connectionId 字段
- 修改 AiAssistant.vue:接入 runAgentStream,解析 AgentEvent 渲染工具调用步骤
- 修改 en.ts / zh-CN.ts:新增 agentSteps 国际化文案

## 修复的问题
- [#I01] connectionName 误传为 connectionId → add connectionId to AiContext
- [#I02] agent loop 取消操作无效 → add cancel checks before each turn
- [#C01] TODO 缺少 issue 引用 → add PRD reference to TODO
- [#C02] stream_with_tools 命名不准确 → add clarifying doc comment
- [#C03] Gemini functionResponse.name 解析错误 → fix tool_call_id format and extraction

## 测试建议
- execute_get_columns:合法表名/空表名/SQL 注入字符拒绝
- call_openai_with_tools:空 choices/空 tool_calls/非 JSON arguments
- call_gemini_with_tools:空 candidates/parts 无 functionCall
- runAgentStream:有效 connectionId 正常调用
@
2026-06-11 18:27:24 +08:00
t8y2 e3b4aac84c fix(desktop): tighten frontend transitions 2026-06-10 19:20:30 +08:00
t8y2 edba8214b5 feat: show username/password fields for Access database connections 2026-06-10 08:37:18 +08:00
t8y2 025a4fdcce fix: support tree-schema default DB selection in AI assistant 2026-06-09 00:44:04 +08:00
t8y2 bcafb9bc93 Revert "feat: support multiple desktop windows"
This reverts commit 642fa39bb8.
2026-06-06 00:01:38 +08:00
t8y2 642fa39bb8 feat: support multiple desktop windows 2026-06-05 20:45:00 +08:00
t8y2 e67894bea7 chore: upgrade frontend tooling and speed up checks 2026-06-03 12:20:27 +08:00
t8y2 133f3cfc04 perf(desktop): use lightweight dropdown menus 2026-05-30 11:02:16 +08:00
t8y2 58b8552316 feat(desktop): expand window drag regions 2026-05-30 10:14:25 +08:00
徐文彬andClaude Opus 4.7 c56bcb8e2d feat(mongodb): 支持聚合查询、批量写入和 MCP 集成
- 桌面端:解析 db.<集合>.aggregate([...]) shell 语法,新增 mongoAggregateDocuments
  接口(Tauri + HTTP);mongo 入口统一补 ensureConnected;ObjectId(...) 自动
  转换为 {"\$oid":"..."} 扩展 JSON 表示。
- dbx-core:新增 aggregate_documents、insert/update/delete_documents bulk
  操作;扩展 JSON 解析识别 \$oid;schema list_tables_core 补 MongoDB/Elasticsearch
  分支返回 COLLECTION/INDEX。
- dbx-web / Tauri 命令 / MCP bridge:注册 4 个新 mongo 路由
  (aggregate/insert/update/delete documents);MCP bridge 新增 mongo HTTP 入口
  和 lazy 连接复用。
- node-core (MCP 后端):mongodb 走专属 executeQuery / listTables /
  describeTable;read-only 默认 + DBX_MCP_ALLOW_WRITES /
  DBX_MCP_ALLOW_DANGEROUS_SQL 两级开关;aggregate 含 \$out/\$merge 走同样开关;
  describeTable 抽样 20 条文档推断字段类型,_id 自动标记主键。
- mcp-server:mongodb 跳过 SQL safety evaluator(mongo shell 与 SQL 语法
  不兼容),改由 backend 做命令级 gating;附注释。
- AiAssistant 同时 emit replaceSql + executeSql 让编辑器和结果保持一致;
  App.vue ensureQueryTab 在无上下文时回退到连接默认库;aiMessageRender
  识别 mongodb / mongo 代码块。
- Review 修复:合并两份重复的 evaluateMongo*Safety 实现(同时修复 web-backend
  用字符串比较导致空 filter 检查可被空格绕过的 bug);ObjectId 正则兼容
  单/双引号;mongo_ops 错误文案 "MCP" 改为 "bulk";补 aggregate 解析测试用例。

测试:pnpm test 911 通过;vue-tsc 通过;cargo check -p dbx-core 通过。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-28 21:25:43 +08:00
t8y2 967a12cc42 fix: remove fixed width from ask/agent mode dropdown to allow adaptive sizing 2026-05-28 14:33:24 +08:00
t8y2 2fea0c38c5 fix(app): harden clipboard copy flows 2026-05-23 10:52:19 +08:00
t8y2 e1dd45e418 fix(editor): update AI mode icons 2026-05-22 21:18:32 +08:00
t8y2 7a3721952a feat(ai): highlight chat code with Shiki 2026-05-22 01:09:40 +08:00
t8y2 2afcfff4e3 fix(ai): extend timeout and token budget for thinking models
Thinking models like DeepSeek V4 Flash can exceed the 120s stream
timeout during long reasoning, causing truncated output and missing
answers. Increase stream timeout to 600s when thinking is enabled,
raise max_tokens floor to 8192, and bump reasoning display max-height.

Closes #326
2026-05-19 18:08:08 +08:00
t8y2 613c2f981f fix(ai): ignore IME composition enter 2026-05-19 15:56:34 +08:00
t8y2 f09fd5aa69 perf(ai): cache rendered message segments 2026-05-18 17:22:46 +08:00
t8y2 06683c57b1 chore(repo): move desktop app under apps 2026-05-18 02:35:39 +08:00