AI assistant plugin addition with aks-agent support#419
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a new Headlamp AI Assistant plugin that adds an in-UI chat/agent experience for Kubernetes help, including provider configuration, prompt/context generation, and a LangChain-based tool system for Kubernetes API access (with confirmation UI for write operations).
Changes:
- Adds a new
plugins/ai-assistantpackage with build/test configuration and plugin metadata. - Implements provider configuration storage, UI settings (including terms), and core chat panel UI/UX (rendering YAML/logs, suggestions, agent thinking steps).
- Adds a LangChain tool framework (registry/manager/base) plus a Kubernetes API tool and UI plumbing for confirmation + execution.
Reviewed changes
Copilot reviewed 57 out of 60 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| plugins/ai-assistant/tsconfig.json | Adds TypeScript config for the plugin package. |
| plugins/ai-assistant/src/utils/ToolConfigManager.ts | Tool enable/disable settings management. |
| plugins/ai-assistant/src/utils/SampleYamlLibrary.ts | Sample YAML library plus YAML parsing/extraction helpers. |
| plugins/ai-assistant/src/utils/ProviderConfigManager.ts | Provider config persistence helpers (save/delete/default/terms). |
| plugins/ai-assistant/src/utils/promptLinkHelper.ts | Headlamp link instruction template + parsing/normalization of Headlamp links. |
| plugins/ai-assistant/src/utils/promptGenerator.ts | Generates dynamic prompt suggestions from current UI context. |
| plugins/ai-assistant/src/utils/modalUtils.ts | Markdown-to-plain-text and suggestion parsing; provider model helpers. |
| plugins/ai-assistant/src/utils/LogsHelper.ts | Pod/container log fetching and pod info extraction helpers. |
| plugins/ai-assistant/src/utils/icons.ts | Bundles Iconify collections for offline provider/logo icons. |
| plugins/ai-assistant/src/utils/contextGenerator.ts | Generates human-readable AI context strings from Headlamp events/resources/warnings. |
| plugins/ai-assistant/src/utils.tsx | Shared plugin constants, ConfigStore wiring, and global state hook. |
| plugins/ai-assistant/src/textstream.tsx | Chat message stream UI with auto-scroll logic and YAML/editor integration. |
| plugins/ai-assistant/src/storybook.test.tsx | Storyshots test bootstrap for plugin stories. |
| plugins/ai-assistant/src/langchain/tools/ToolManager.ts | Loads enabled tools, binds them to the model, and executes tool calls. |
| plugins/ai-assistant/src/langchain/tools/ToolBase.ts | Base class for defining LangChain tools and a standard tool response shape. |
| plugins/ai-assistant/src/langchain/tools/registry.ts | Central tool registry (currently Kubernetes tool only). |
| plugins/ai-assistant/src/langchain/tools/kubernetes/types.ts | Type definitions for Kubernetes tool UI state/callback context. |
| plugins/ai-assistant/src/langchain/tools/kubernetes/KubernetesTool.ts | Implements kubernetes_api_request tool with confirmation flow. |
| plugins/ai-assistant/src/langchain/tools/kubernetes/index.ts | Kubernetes tool barrel exports. |
| plugins/ai-assistant/src/langchain/tools/index.ts | Tools barrel exports. |
| plugins/ai-assistant/src/langchain/PromptTemplates.ts | Reusable prompt templates for structured tasks and error reporting. |
| plugins/ai-assistant/src/langchain/OutputParsers.ts | Zod-based structured output parsers and safe parsing utility. |
| plugins/ai-assistant/src/index.tsx | Registers UI panel + app bar action + plugin settings page (providers/tools). |
| plugins/ai-assistant/src/hooks/useKubernetesToolUI.ts | Hook for Kubernetes tool UI state and API execution callback wrapper. |
| plugins/ai-assistant/src/hooks/useClusterWarnings.ts | Hook to fetch per-cluster warnings/errors for context. |
| plugins/ai-assistant/src/helper/index.tsx | Misc helpers (formatString, log URL detection, test-mode flag). |
| plugins/ai-assistant/src/helper/apihelper.tsx | Executes confirmed Kubernetes API operations; formats tables/log responses into chat history. |
| plugins/ai-assistant/src/headlamp-plugin.d.ts | Headlamp plugin type reference shim for TS. |
| plugins/ai-assistant/src/editordialog.tsx | Monaco-based YAML editor dialog to apply resources to cluster. |
| plugins/ai-assistant/src/ContentRenderer.tsx | Renders assistant markdown, YAML previews, logs button, and Headlamp links. |
| plugins/ai-assistant/src/config/modelConfig.ts | Provider definitions (fields/models/icons) and defaults. |
| plugins/ai-assistant/src/components/settings/TermsDialog.tsx | Terms/important info dialog for AI assistant usage. |
| plugins/ai-assistant/src/components/settings/index.ts | Settings component barrel exports. |
| plugins/ai-assistant/src/components/index.ts | Components barrel exports. |
| plugins/ai-assistant/src/components/common/YamlDisplay.tsx | Read-only YAML preview with “Open in Editor” action and resize handling. |
| plugins/ai-assistant/src/components/common/SafeIcon.tsx | Safe wrapper around Iconify <Icon> to avoid frozen-style mutation crash. |
| plugins/ai-assistant/src/components/common/LogsDialog.tsx | Monaco-based log viewer dialog with copy/download and basic formatting. |
| plugins/ai-assistant/src/components/common/LogsButton.tsx | UI card/button that opens the log viewer dialog. |
| plugins/ai-assistant/src/components/common/index.ts | Common component barrel exports. |
| plugins/ai-assistant/src/components/common/ApiConfirmationDialog.tsx | Confirmation/edit flow for API write operations (PUT/POST/DELETE). |
| plugins/ai-assistant/src/components/assistant/TestModeInput.tsx | UI for injecting test messages/responses in “test mode”. |
| plugins/ai-assistant/src/components/assistant/PromptSuggestions.tsx | Renders clickable suggestion chips (including content-filter recovery). |
| plugins/ai-assistant/src/components/assistant/index.ts | Assistant component barrel exports. |
| plugins/ai-assistant/src/components/assistant/AIInputSection.tsx | Input box, send/stop/clear, provider+model dropdown, agent mode selector. |
| plugins/ai-assistant/src/components/assistant/AIChatContent.tsx | Wraps chat history stream and shows top-level API error banner. |
| plugins/ai-assistant/src/components/assistant/AIAssistantHeader.tsx | Header (settings/close) and test-mode badge. |
| plugins/ai-assistant/src/components/agent/AgentThinkingSteps.tsx | Displays streamed agent “thinking steps” grouped by phase. |
| plugins/ai-assistant/src/components/agent/AgentModeSelector.tsx | Toggles chat vs agent mode and selects AKS-agent cluster. |
| plugins/ai-assistant/src/ai/prompts.ts | Base system prompt (tool usage rules, YAML formatting, link rules, suggestions format). |
| plugins/ai-assistant/src/ai/manager.ts | Abstract AI manager + prompt history model used by UI. |
| plugins/ai-assistant/README.md | Plugin readme describing features and supported providers. |
| plugins/ai-assistant/package.json | Plugin package definition, scripts, and dependencies. |
| plugins/ai-assistant/artifacthub-pkg.yml | ArtifactHub metadata for distributing the plugin. |
| plugins/ai-assistant/.gitignore | Plugin-specific ignores (dist/build/storybook/etc.). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 57 out of 60 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
|
I'll work on hooking it up to preview toggle. |
97d6a04 to
e5847ae
Compare
|
Rebased against main. |
2d0a432 to
2227345
Compare
|
@ashu8912 worked on finding response parser related bugs. Fixes 7 parsing bugs in agent response handling and adds comprehensive test coverage for all parsing and markdown utility functions in the ai-assistant plugin, including extensive malformed AI output tests, code block preservation tests for TypeScript, Mermaid, Bash, and JSON fenced blocks, and Kubernetes YAML markdown block tests with real-world manifests and parser edge cases. Changes MadeBug fixes
Test coverage (369 tests)
Malformed AI output testsTests validate graceful handling of:
Code block preservation testsTests verify that fenced code blocks for TypeScript (
Kubernetes YAML markdown block testsTests cover real-world Kubernetes manifests and YAML edge cases:
Internal parsing functions exported via Test Cases
|
|
@ashu8912 some contrast fixes. Code blocks in the agent chat used hardcoded Changes Made
Screenshots/VideosLight Theme
Dark Theme
Agent Thinking Steps (Dark, Completed)
|
|
@ashu8912 I pushed a commit for viewport scrolling. Fix chat viewport scrolling to show top of new agent responses New agent responses scrolled the viewport to the bottom of the response instead of the top. Users couldn't see the beginning of the answer without scrolling back up. Additionally, when the last message was a user message (during loading), the viewport would incorrectly jump back to a previous assistant message, and tall new responses could cause auto-scroll to be skipped entirely. Changes Made
Test Cases
Screenshots/VideosBefore — conversation with pending user question: After clicking "Add Agent Response" — viewport at the top of the new response: Reviewer NotesThe old The Storybook stories simulate the real chat flow by adding both a user question and an agent response on each button click. This ensures the scroll-trigger |
|
@ashu8912 Improved parsing and rendering of AI responses. Add levelled debug logging, robust code-line detection, real-world parsing tests and stories, normalize terminal-formatted responses, collapse terminal blank lines, fix code block boundary detection, fix GFM table/YAML rendering, wrap bare code command... Screenshots/VideosStorybook rendering of the Real World stories:
DescriptionAdds structured, levelled debug logging throughout the AKS agent response parsing pipeline and incoming data flow. Logging uses a simple This PR also adds real-world parsing test cases and ContentRenderer Storybook stories derived from dev console captures. Stories use raw exec output (with ANSI codes, bracketed paste mode, bash prompts, task tables, and terminal formatting) piped through
The code-line detection function A new
A new The ANSI stripping in The The The All ContentRenderer Storybook stories now pass Before (from real-world Java deployment responses):
Related IssuesRelated to the ai-integration PR — addresses difficulty diagnosing response parsing bugs in development and verifying real-world agent response rendering. Changes Made
Test Cases
Breaking ChangesNo breaking changes. All existing parsing behavior is preserved — the new Performance Impact
The debug logging is completely eliminated in production builds via Reviewer Notes
|
…er, preview toggle for ai-assistant
|
rebased against main |
5093388 to
9a69339
Compare
…rsing/markdown fix parsing bugs and add comprehensive tests for agent response/markdown parsing - Fix wrapBareYamlBlocks: handle apiVersion with no value after colon - Fix wrapBareYamlBlocks: remove early-exit when yaml fence exists (allows wrapping additional bare blocks) - Fix parseLogsButtonData: track string context when counting braces to handle braces inside JSON string values - Add 172 tests covering: stripAnsi, normalizeBullets, looksLikeYaml, wrapBareYamlBlocks, cleanTerminalFormatting, isAgentNoiseLine, stripAgentNoise, extractAIAnswer, ThinkingStepTracker, extractTaskRow, friendlyToolLabel, parseLogsButtonData, parseJsonContent, isJsonKubernetesResource, convertJsonToYaml, markdownToPlainText, parseSuggestionsFromResponse fix parseSuggestionsFromResponse to strip all SUGGESTIONS: lines from cleanContent add malformed AI output tests and code block preservation tests Add 100+ new tests covering: - Code block preservation (ts, mermaid, bash, json) across wrapBareYamlBlocks, cleanTerminalFormatting, stripAgentNoise, and extractAIAnswer pipeline - Malformed extractAIAnswer inputs (truncated, garbled ANSI, multiple AI: prefixes, null bytes, interleaved noise) - Malformed YAML (trailing garbage, no kind/metadata, deeply indented, unclosed fences) - Malformed Rich terminal borders (incomplete, mismatched, nested, empty panels) - Garbled agent noise patterns, edge cases in looksLikeYaml, normalizeBullets, stripAnsi - Malformed ThinkingStepTracker inputs (empty models, unknown tool finish, partial rows) - Malformed parseLogsButtonData JSON (truncated, trailing commas, single quotes, deeply nested, unicode, very long content, null logs) - Malformed parseJsonContent (truncated, trailing commas, YAML/XML content) - Edge cases in isJsonKubernetesResource and convertJsonToYaml - Malformed markdown (unclosed bold/italic/code/links, nested unclosed markers) - Malformed SUGGESTIONS (no pipes, only pipes, unicode, embedded in markdown) fix: looksLikeYaml misses --- YAML doc separator, markdownToPlainText ordering bug, ThinkingStepTracker = sign border - looksLikeYaml: recognize --- (YAML document separator) and ... (document end marker) so wrapBareYamlBlocks keeps multi-document YAML in a single fence instead of leaving bare --- as a markdown horizontal rule. - markdownToPlainText: move whitespace collapse (\s+ → ' ') after the line-start-anchored patterns (list markers, blockquotes, horizontal rules). Previously the collapse removed all newlines first, making the ^ anchors useless for list/blockquote/hr removal. - ThinkingStepTracker.processLine: partial-row abandon regex now includes = (consistent with the updated AGENT_NOISE_PATTERNS). docs: improve comments on YAML separator and table border patterns
…lors in agent chat Code blocks in the agent chat used hardcoded `grey[100]`/`grey[900]` regardless of theme mode, and success icons used hardcoded `#4caf50`. Both break contrast in dark mode. This PR makes these colors theme-aware, fixes the user message bubble to use the real `theme.palette.sidebar.selectedBackground` instead of a hardcoded color, and adds Storybook stories (co-located next to their components) to verify contrast visually across light and dark themes. - **ContentRenderer.tsx**: Swap `grey[100]`↔`grey[900]` for code block bg/text based on `theme.palette.mode` - **AgentThinkingSteps.tsx**: Replace 3× hardcoded `#4caf50` with `theme.palette.success.main` - **ChatContrast stories**: Use `theme.palette.sidebar.selectedBackground` (with fallback) for user message bubble instead of hardcoded `#c2c2c2`, matching production `textstream.tsx` behavior - **Story file co-location**: Stories are placed next to their components (`ContentRenderer.stories.tsx` next to `ContentRenderer.tsx`, `ChatContrast.stories.tsx` next to `textstream.tsx`, `AgentThinkingSteps.stories.tsx` next to `AgentThinkingSteps.tsx`) - **Edge case stories added**: - ContentRenderer: empty content, very long content, nested code blocks, YAML blocks, inline code heavy, multiple code block languages - ChatContrast: short messages, error/success sequences, long unbroken strings, deeply nested markdown, YAML + multi-language code blocks - AgentThinkingSteps: single step, many steps (15+), long step labels, all-pending state
Add levelled debug logging, robust code-line detection, real-world parsing tests and stories, normalize terminal-formatted responses, collapse terminal blank lines, fix code block boundary detection, fix GFM table/YAML rendering, wrap bare code command.
|
@ashu8912 Added a loader to when the "Agent is working..." DescriptionAdds a small MUI Changes Made
Screenshots/Videos
|
- dev script now runs ai-assistant:start alongside plugin:start via concurrently
- Added ai-assistant:{install,build,start,test,lint,format} convenience scripts mirroring the plugin:* scripts
- Updated install:all and build:all to include ai-assistant
|
@ashu8912 fixed npm run dev to start ai-assistant too.
|
…ndicator **`AgentThinkingSteps.tsx`** (~20 net lines) - Added `endRef` sentinel `<div>` at the bottom of the component content (used as DOM anchor for scroll parent lookup) and `scrollParentRef` to cache the nearest scrollable ancestor - Scroll parent lookup uses `getComputedStyle(sp).overflowY` to find containers with `'auto'`/`'scroll'` — correctly skips MUI Collapse wrappers which use `overflow: hidden` - Added `useEffect` that calls `scrollParent.scrollTo()` directly when `steps.length` changes — fires after a 350ms delay to let MUI Collapse animations settle, with cleanup to clear the timer on unmount/re-render - Uses direct `scrollParent.scrollTo()` instead of `scrollIntoView()` which was targeting the wrong container through nested `overflow: hidden` MUI Collapse wrappers - Gated by a `distanceFromBottom` check on the scroll parent (matching TextStreamContainer's "near bottom" pattern), skipping if the user has scrolled more than one viewport-height away from the bottom - Respects `prefers-reduced-motion` via inline `window.matchMedia` check with SSR guard (`typeof window !== 'undefined' && typeof window.matchMedia === 'function'`), using `behavior: 'auto'` instead of `'smooth'` when reduced motion is preferred **`AgentThinkingSteps.stories.tsx`** - Added `SmartScroll` story with a 300px scrollable container, filler messages, a user question, and progressive thinking steps to demonstrate the scroll behavior when the user is near the bottom - Added `ScrolledAway` story with a 200px container starting scrolled to the top, demonstrating that new steps do NOT yank the viewport back down
|
@ashu8912 fixed "Agent working…" not scrolling into viewport issue. DescriptionWhen "Agent working…" appears, the viewport scrolled to the very bottom, hiding the user's question. Now The scroll parent is found by checking Changes Made
Screenshots/VideosSmartScroll with Collapse wrappers — scroll parent correctly found through nested
SmartScroll story — user question + "Agent working…" + all steps visible in viewport:
ScrolledAway story — user scrolled to top, steps arrive but viewport is NOT yanked back:
|
Mention headlamp AI assistant.
|
@ashu8912 Renamed the "alpha" label to "preview" in the AI Assistant header, and adds a disclaimer warning icon next to the tidy-up (broom) button. Two small UI polish changes to the AI Assistant panel:
|
|
@ashu8912 Improved the AI response parsing. It's not perfect, but now renders many code blocks better. After parser improvements:
Before parser improvements:See how there's errors with the python code, the requirements.txt code? It's like this for most code blocks before. |
|
@ashu8912 added i18n t() all over the place |
57f5780 to
e679e36
Compare
All user-visible hardcoded strings in the ai-assistant plugin
are now wrapped with t() using useTranslation enabling full
i18n support. All translation keys use {{placeholder}}
interpolation instead of string concatenation,
ensuring correct grammar and word order across locales.
e679e36 to
64aa8b4
Compare
|
@ashu8912 also upgraded to headlamp-plugin to 0.13.1, because that has fixed i18n support. |
|
Added files so the localization team can update the translations for the ai-assistant |
|
Hii @illume the changes look good to me, i think we can merge this and continue the development from the base we have created here, in future we will have to think about using the upstream ai-assistant changes here, as right now it's just a copy of the upstream plugin here, but things will get more smoother once we have ag-ui support in aks agent. Thanks |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 95 out of 101 changed files in this pull request and generated 11 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.














Description
Adds AKS agent version of the ai-assistant plugin.
It's preview state, and off by default. Turn it on in the plugin settings.
Type of Change
Related Issues
Related to #156
Changes Made
On top of the AI assistant it adds AKS agent support.
Testing
Test Cases
Describe the test cases that were run:
You need to install AKS agent on a cluster.
Ask Ashu / Rene for cluster with it already installed.
Screenshots/Videos
If applicable, add screenshots or videos to demonstrate the changes.
Checklist
Breaking Changes
If this is a breaking change, describe:
Performance Impact
Documentation Updates
Reviewer Notes
Any specific areas you'd like reviewers to focus on or questions you have.