pgadmin4/web/pgadmin/tools
Dave Page 6296016b67
Fix an issue where LLM responses are not streamed or rendered properly in the AI Assistant. #9734
* Address CodeRabbit review feedback for streaming and SQL extraction.

- Anthropic: preserve separators between text blocks in streaming to
  match _parse_response() behavior.
- Docker: validate that the API URL points to a loopback address to
  constrain the request surface.
- Docker/OpenAI: raise LLMClientError on empty streams instead of
  yielding blank LLMResponse objects, matching non-streaming behavior.
- SQL extraction: strip trailing semicolons before joining blocks to
  avoid double semicolons in output.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Address remaining CodeRabbit review feedback for streaming and rendering.

- Use distinct 3-tuple ('complete', text, messages) for completion events
  to avoid ambiguity with ('tool_use', [...]) 2-tuples in chat streaming.
- Pass conversation history from request into chat_with_database_stream()
  so follow-up NLQ turns retain context.
- Add re.IGNORECASE to SQL fence regex for case-insensitive matching.
- Render MarkdownContent as block element instead of span to avoid
  invalid DOM when response contains paragraphs, lists, or tables.
- Keep stop notice as a separate message instead of appending to partial
  markdown, preventing it from being swallowed by open code fences.
- Snapshot streamingIdRef before setMessages in error handler to avoid
  race condition where ref is cleared before React executes the updater.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Address CodeRabbit review feedback for streaming providers and history.

- Fix critical NameError: use self._api_url instead of undefined API_URL
  in anthropic and openai streaming _process_stream() methods.
- Match sync path auth handling: conditionally set API key headers in
  streaming paths for both anthropic and openai providers.
- Remove unconditional temperature from openai streaming payload to
  match sync path compatibility approach.
- Add URL scheme validation to OllamaClient.__init__ to prevent unsafe
  local/resource access via non-http schemes.
- Guard ollama streaming finalizer: raise error when stream drops
  without a done frame and no content was received.
- Update chat.py type hint and docstring for 3-tuple completion event.
- Serialize and return filtered conversation history in the complete
  SSE event so the client can round-trip it on follow-up turns.
- Store and send conversation history from NLQChatPanel, clear on
  conversation reset.
- Fix JSON-fallback SQL render path: clear content when SQL was
  extracted without fenced blocks so ChatMessage uses sql-only renderer.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Fix missing closing brace in NLQChatPanel switch statement.

Adding block scoping to the error case introduced an unmatched brace
that prevented the switch statement from closing properly, causing
an eslint parse error.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Fix missing compaction module and SQL extraction test.

- Replace compaction module imports with inline history deserialization
  and filtering since compaction.py is on a different branch.
- Add rstrip(';') to SQL extraction test to match production code,
  fixing double-semicolon assertion failure.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Fix SQL extraction test expected values after rstrip(';') change.

The rstrip(';') applied to each block before joining means single
blocks and the last block in multi-block joins no longer have
trailing semicolons. Update expected values to match.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Strictly guard Ollama stream: raise if no terminal done frame received.

Truncated content from a dropped connection should not be treated as
a complete response, even if partial text was streamed. Always raise
when final_data is None, matching CodeRabbit's recommendation.
2026-03-17 11:41:57 +05:30
..
backup Fix broken checkbox selection in backup dialog objects tree. #9649 2026-02-27 17:01:11 +05:30
debugger Copyright updated for 2026 2026-01-05 13:33:45 +05:30
erd ERD Tool: Insert table with relations via drag-and-drop. #5578 #8198 2026-02-24 12:15:54 +05:30
grant_wizard Copyright updated for 2026 2026-01-05 13:33:45 +05:30
import_export Copyright updated for 2026 2026-01-05 13:33:45 +05:30
import_export_servers Copyright updated for 2026 2026-01-05 13:33:45 +05:30
maintenance Copyright updated for 2026 2026-01-05 13:33:45 +05:30
psql Copyright updated for 2026 2026-01-05 13:33:45 +05:30
restore Fix pgAdmin fails when performing Backup/Restore on a PostgreSQL connection defined exclusively via pg_service.conf. #9553 2026-01-30 16:54:48 +05:30
schema_diff Fixed an issue where tools settings changed by the users were not restored on application relaunch. #8988 2026-02-09 10:54:53 +05:30
search_objects Copyright updated for 2026 2026-01-05 13:33:45 +05:30
sqleditor Fix an issue where LLM responses are not streamed or rendered properly in the AI Assistant. #9734 2026-03-17 11:41:57 +05:30
templates Copyright updated for 2026 2026-01-05 13:33:45 +05:30
user_management Core LLM integration infrastructure to allow pgAdmin to connect to AI providers. #9641 2026-02-17 17:16:06 +05:30
__init__.py Copyright updated for 2026 2026-01-05 13:33:45 +05:30