Skip to content

feat(ai): add secure page-aware context to AI conversations#1511

Open
sohandsomejie wants to merge 13 commits into
apache:aifrom
sohandsomejie:ai
Open

feat(ai): add secure page-aware context to AI conversations#1511
sohandsomejie wants to merge 13 commits into
apache:aifrom
sohandsomejie:ai

Conversation

@sohandsomejie

Copy link
Copy Markdown
Contributor

Please provide a description of this PR:

This PR adds end-to-end page-aware context support to Dubbo Admin AI conversations.

What changed

  • Add a frontend context manager and provider system for collecting page, resource, search, topology, and traffic-rule context.
  • Sanitize and limit collected context before sending it to the AI service.
  • Add context preview, section selection, refresh, and one-shot exclusion controls to the chat drawer.
  • Pass structured context through the AI API and normalize it before injecting it into agent prompts.
  • Add detailed context coverage for resource details, search filters, configuration pages, and unsaved rule drafts.
  • Extract the AI chat drawer into a reusable component with injectable service, context collector, labels, and suggestions.
  • Make session-history support optional for consumers of the reusable component.
  • Upgrade the default model configuration to Qwen 3.7 Max.
  • Restore required Markdown, syntax highlighting, and drawer styling dependencies.
  • Add frontend and backend unit and integration tests.

Validation

  • Frontend AI context and chat component tests: 41 passed.
  • Vite production build completed successfully.
  • Targeted ESLint checks completed without errors or warnings.
  • Added backend tests for context validation, normalization, and agent integration.

To help us figure out who should review this PR, please put an X in all the areas that this PR affects.

  • Docs
  • Installation
  • User Experience
  • Dubboctl
  • Console
  • Core Component

Please check any characteristics that apply to this pull request.

  • The page context payload is optional and backward compatible.
  • Sensitive fields are filtered before context is sent to the AI service.
  • Unit and integration tests are included.

wangyongjie added 12 commits July 19, 2026 19:55
## Summary
Restore the global Tailwind styles required by the AI chat drawer and add the missing build and Markdown rendering dependencies so a clean installation builds and displays the drawer correctly.

## Target
- Load the global Tailwind stylesheet from the frontend entry point
- Add Tailwind, PostCSS, and Autoprefixer build dependencies
- Add Markdown and syntax highlighting runtime dependencies and type declarations
- Update the Yarn lockfile

## Stats
 3 files changed, 452 insertions(+), 3 deletions(-)
## Summary
Add the frontend context infrastructure required for AI conversations to understand the current page. Context is collected on demand and consistently isolated by route, sanitized, and constrained by a size budget.

## Target
- Add AIContextManager, context contracts, and the page provider composable
- Collect the active mesh, current locale, route parameters, and active tab
- Add context sanitization, an 8 KB budget, and deterministic truncation
- Add unit tests for providers, snapshots, and sanitization
- Add the AI context management design document

## Stats
 14 files changed, 1299 insertions(+)
## Summary
Add a home page pilot and context preview to AI context management. The home page exposes an allowlisted summary on demand, while users can inspect, disable, and filter optional page information without changing the existing AI request contract.

## Target
- Register a home page provider for application, service, and instance summaries
- Add a page context entry, preview, toggle, and section selection to the AI drawer
- Add snapshot selection helpers without mutating the original snapshot
- Add English and Chinese copy plus provider, route lifecycle, and selection tests
- Remove obsolete icon imports from AgentDrawer

## Stats
 12 files changed, 730 insertions(+), 9 deletions(-)
## Summary
Connect the frontend page context snapshot to the AI streaming request and inject validated, sanitized context into the current ReAct turn without persisting it in conversation history.

## Target
- Add the optional context field to the frontend and backend chat contracts
- Recollect and consume the selected context once per outgoing message
- Validate context version, structure, size, timestamps, and required identifiers
- Sanitize sensitive keys, URL credentials, nested values, arrays, and long strings
- Inject context before the current user question as an untrusted observation
- Document the OpenAPI contract and add frontend and Go request tests

## Stats
 20 files changed, 984 insertions(+), 26 deletions(-)
## Summary
Reset one-shot page context controls as soon as a valid send attempt begins, so the next message returns to the default context selection even when session creation fails.

## Target
- Consume the selected page context before creating an AI session
- Restore the context toggle and section selection on failed send attempts
- Preserve the existing chat request payload behavior

## Stats
 1 file changed, 2 insertions(+), 2 deletions(-)
## Summary
Upgrade the AI agent to the Qwen 3.7 generation while preserving the existing DashScope integration and embedding configuration.

## Target
- Register Qwen 3.7 Max and Plus chat models
- Use Qwen 3.7 Max as the default and ReAct agent model

## Stats
2 files changed, 8 insertions(+), 2 deletions(-)
## Summary
Add resource-aware and editor-aware page context to the AI drawer while keeping payloads small, explicit, and user-controlled.

## Target
- Add application, service, instance, and traffic rule context providers
- Summarize unsaved condition rule, tag rule, and dynamic config drafts through a strict whitelist
- Allow unsaved draft context to be excluded from the next AI message
- Cover provider sanitization and context selection behavior with unit tests

## Stats
21 files changed, 545 insertions(+), 21 deletions(-)
## Summary
Provide detailed, bounded AI context for the admin console's accessible business pages while keeping sensitive and oversized data out of model requests.

## Target
- Collect visible list rows, resource details, topology state, debug results, dashboards, events, configuration forms, and traffic rule content
- Apply explicit field allowlists, semantic secret redaction, item limits, and an 8 KB snapshot budget
- Re-sanitize context at the AI service boundary and extend frontend and Go coverage

## Stats
31 files changed, 1317 insertions(+), 29 deletions(-)
## Summary
Extract the AI chat UI and controller behind injected service and context contracts while preserving the existing Dubbo Admin integration.

## Target
- Add a reusable AI chat drawer, public exports, and transport contracts
- Keep Dubbo-specific context collection, labels, and suggestions in a thin adapter
- Move the context preview outside the generic component boundary
- Add contract tests and update context integration coverage

## Stats
13 files changed, 1449 insertions(+), 979 deletions(-)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds end-to-end “page-aware context” support for Dubbo Admin’s AI chat by introducing a frontend context collection system (providers + snapshot + sanitization + selection UI) and extending the AI backend request/agent pipeline to accept, validate, sanitize, and inject the current-turn page context into prompts safely.

Changes:

  • Frontend: introduce ai-context module (providers, snapshotting, sanitization, selection) and register page-specific context providers across resource, traffic, search, topology, config, and debug pages.
  • Frontend: refactor AI chat UI into reusable components, add context preview/section selection controls, and update i18n strings and dependencies.
  • Backend: extend streaming chat request contract to accept optional context, validate+sanitize it server-side, and inject it into agent prompts as an untrusted current-turn observation.

Reviewed changes

Copilot reviewed 83 out of 84 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
ui-vue3/src/views/traffic/tagRule/tabs/YAMLView.vue Registers tag-rule rule-content context provider for YAML view.
ui-vue3/src/views/traffic/tagRule/tabs/formView.vue Registers tag-rule rule-content context provider for form view.
ui-vue3/src/views/traffic/tagRule/slots/updateTagRuleTabHeaderSlot.vue Provides tag-rule draft context for update flow via tab state injection.
ui-vue3/src/views/traffic/tagRule/slots/tagRuleDetailTabHeaderSlot.vue Provides tag-rule resource scope context.
ui-vue3/src/views/traffic/tagRule/slots/addTagRuleTabHeaderSlot.vue Provides tag-rule draft context for create flow via tab state injection.
ui-vue3/src/views/traffic/routingRule/tabs/YAMLView.vue Registers condition-rule rule-content context provider for YAML view.
ui-vue3/src/views/traffic/routingRule/tabs/formView.vue Registers condition-rule rule-content context provider for form view.
ui-vue3/src/views/traffic/routingRule/slots/updateConditionRuleTabHeaderSlot.vue Provides condition-rule draft context for update flow.
ui-vue3/src/views/traffic/routingRule/slots/conditionRuleDetailTabHeaderSlot.vue Provides condition-rule resource scope context.
ui-vue3/src/views/traffic/routingRule/slots/addConditionRuleTabHeaderSlot.vue Provides condition-rule draft context for create flow (incl. qualifiers).
ui-vue3/src/views/traffic/dynamicConfig/slots/updateDCTabHeaderSlot.vue Provides dynamic-config context (either resource+content or draft).
ui-vue3/src/views/resources/services/tabs/topology.vue Collects topology graph + selection as AI context evidence.
ui-vue3/src/views/resources/services/tabs/detail.vue Collects whitelisted service detail fields as context evidence.
ui-vue3/src/views/resources/services/tabs/debug.vue Collects service debug request/response/method/provider summaries as evidence.
ui-vue3/src/views/resources/services/slots/ServiceTabHeaderSlot.vue Provides service resource scope (service/group/version).
ui-vue3/src/views/resources/instances/tabs/detail.vue Collects instance detail evidence via provider.
ui-vue3/src/views/resources/instances/slots/InstanceTabHeaderSlot.vue Provides instance resource scope (instance + optional application).
ui-vue3/src/views/resources/applications/tabs/topology.vue Collects application topology graph + selection as evidence.
ui-vue3/src/views/resources/applications/tabs/event.vue Collects event list summary as context evidence.
ui-vue3/src/views/resources/applications/tabs/detail.vue Collects whitelisted application detail fields as context evidence.
ui-vue3/src/views/resources/applications/slots/AppTabHeaderSlot.vue Provides application resource scope.
ui-vue3/src/views/home/index.vue Adds home overview context provider; adjusts icon layout styling.
ui-vue3/src/main.ts Restores global stylesheet import.
ui-vue3/src/layout/index.vue Layout logo CSS adjustments for alignment and wrapping.
ui-vue3/src/components/SearchTable.vue Registers providers for search filters and visible result summaries.
ui-vue3/src/components/GrafanaPage.vue Adds dashboard state context provider (route + params + url metadata).
ui-vue3/src/components/ConfigPage.vue Adds configuration form state context provider.
ui-vue3/src/components/ai-context/AIContextPreview.vue Adds UI to preview/enable/disable context and select sections.
ui-vue3/src/components/ai-chat/types.ts Introduces reusable AI chat component type contracts + default labels.
ui-vue3/src/components/ai-chat/SuggestionCard.vue Switches suggestion typing to shared ChatSuggestion model.
ui-vue3/src/components/ai-chat/SessionHistoryModal.vue Makes session history UI label-driven; updates types import.
ui-vue3/src/components/ai-chat/MessageList.vue Passes labels/suggestions through; removes hard-coded suggestions.
ui-vue3/src/components/ai-chat/MessageItem.vue Uses label-driven strings; keeps markdown rendering path.
ui-vue3/src/components/ai-chat/index.ts Exports reusable drawer and shared types/labels.
ui-vue3/src/components/ai-chat/ChatInput.vue Adds label-driven text, optional history button, and focus() expose.
ui-vue3/src/components/ai-chat/tests/AiChatDrawer.spec.ts Adds unit coverage for injected service, context collection, and history support.
ui-vue3/src/base/i18n/zh.ts Adds zh translations for context preview UI.
ui-vue3/src/base/i18n/en.ts Adds en translations for context preview UI.
ui-vue3/src/api/service/ai.ts Adapts aiService to reusable ChatService contract and adds context payload.
ui-vue3/src/api/service/tests/ai.spec.ts Tests context inclusion/omission in the chat payload.
ui-vue3/src/ai-context/types.ts Defines versioned context snapshot contract and provider interfaces.
ui-vue3/src/ai-context/snapshot.ts Builds sanitized, budget-constrained snapshots from providers.
ui-vue3/src/ai-context/selection.ts Implements per-message context enablement + section exclusion.
ui-vue3/src/ai-context/sanitize.ts Adds frontend redaction/limits for sensitive keys, URLs, depth, etc.
ui-vue3/src/ai-context/providers/traffic.ts Provides safe summaries for traffic rules and drafts.
ui-vue3/src/ai-context/providers/search.ts Collects declared filter params and visible result table summaries.
ui-vue3/src/ai-context/providers/route.ts Captures route/path/tab/params/query for base page context.
ui-vue3/src/ai-context/providers/resource.ts Captures stable application/service/instance identifiers + qualifiers.
ui-vue3/src/ai-context/providers/page.ts Provides helpers for config/dashboard/details/topology/events/debug evidence.
ui-vue3/src/ai-context/providers/instance.ts Provides whitelisted instance detail summary evidence.
ui-vue3/src/ai-context/providers/index.ts Exports providers and builds base context from global + route.
ui-vue3/src/ai-context/providers/home.ts Builds compact home/cluster overview evidence.
ui-vue3/src/ai-context/providers/global.ts Captures mesh + locale for global context.
ui-vue3/src/ai-context/manager.ts Registers providers and snapshots only those matching the active route.
ui-vue3/src/ai-context/instance.ts Creates the singleton AIContextManager instance.
ui-vue3/src/ai-context/index.ts Barrel export for ai-context module.
ui-vue3/src/ai-context/composables/useAIContextProvider.ts Adds composable to register/unregister per-page providers tied to route lifecycle.
ui-vue3/src/ai-context/tests/useAIContextProvider.spec.ts Tests provider registration and route tracking/unregister behavior.
ui-vue3/src/ai-context/tests/snapshot.spec.ts Tests snapshot determinism, budgeting, and selection behavior.
ui-vue3/src/ai-context/tests/sanitize.spec.ts Tests frontend redaction (keys, URL creds, depth/limits/circular).
ui-vue3/src/ai-context/tests/providers.spec.ts Tests provider outputs stay small/whitelisted and redact sensitive fields.
ui-vue3/src/ai-context/tests/pageContext.integration.spec.ts Integration tests across routes + AgentDrawer request inclusion/exclusion.
ui-vue3/src/ai-context/tests/manager.spec.ts Tests manager route scoping, priority, unregister, and failure isolation.
ui-vue3/package.json Restores markdown/highlighting and adds Tailwind/PostCSS toolchain deps.
docs/ai-context-management-design.md Adds design doc for page-aware AI context architecture and constraints.
ai/schema/react.go Adds current-turn page context field to schema UserInput (not serialized).
ai/schema/context.go Introduces backend AIContextSnapshot schema/types and size constants.
ai/prompts/agentThink.txt Adds “Page Context Safety” instructions for prompt consumption.
ai/prompts/agentObserve.txt Adds “Page Context Safety” instructions for prompt consumption.
ai/prompts/agentAct.txt Adds “Page Context Safety” instructions and fixes formatting.
ai/component/server/engine/models.go Extends ChatRequest with optional raw JSON context.
ai/component/server/engine/handlers.go Parses/validates/sanitizes context and passes it into agent interaction.
ai/component/server/engine/handlers_test.go Adds integration coverage for request contract and sanitization boundary.
ai/component/server/engine/docs/openapi.yaml Documents the new context payload and schema in OpenAPI.
ai/component/server/engine/context.go Implements backend context parsing, validation, and sanitization/redaction.
ai/component/server/engine/context_test.go Tests backend context validation and redaction behavior.
ai/component/models/models.yaml Updates default model to qwen3.7-max and registers qwen3.7 models.
ai/component/agent/react/react.go Injects current-turn context into think/act/observe prompts; avoids storing it in history.
ai/component/agent/react/context.go Implements context envelope injection as a user JSON message for current turn only.
ai/component/agent/react/context_test.go Tests context injection placement and non-serialization in history.
ai/component/agent/agent.yaml Updates agent model config to qwen3.7-max.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ui-vue3/src/api/service/ai.ts Outdated
Comment thread ui-vue3/src/components/ai-chat/MessageItem.vue
## Summary
Secure AI chat rendering against untrusted HTML and make stream response handling explicit.

## Target
- Disable raw HTML in Markdown rendering
- Render user and error messages with Vue escaping
- Type AI response streams and reject empty response bodies
- Add regression coverage for unsafe HTML and empty streams

## Stats
 5 files changed, 93 insertions(+), 6 deletions(-)
@sonarqubecloud

Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants