Repository navigation
feat(custom-widget): add native AI copilot - #42063
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughThe custom widget editor now provides a Redux-backed AI assistant that builds widget context, parses HTML/CSS/JS updates, applies them to the builder, and renders configuration, chat, loading, and error states. ChangesCustom Widget AI Assistant
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant CustomWidgetEditor
participant AIAssistant
participant ReduxAIState
participant CustomWidgetBuilder
CustomWidgetEditor->>AIAssistant: Open the feature-flagged AI tab
AIAssistant->>ReduxAIState: Dispatch FETCH_AI_RESPONSE with widget context
ReduxAIState-->>AIAssistant: Return assistant response
AIAssistant->>CustomWidgetBuilder: Apply extracted HTML/CSS/JS updates
Possibly related issues
Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ac96dd8 to
26007de
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
/build-deploy-preview |
|
Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/30431314713. |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
app/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/index.tsx (1)
50-58: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winSuggested-prompt copy bypasses the localization pattern.
Every other user-facing string in this file goes through
createMessage(CUSTOM_WIDGET_AI_ASSISTANT.*), butSUGGESTED_PROMPTSlabels/prompts are hardcoded English literals.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@app/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/index.tsx` around lines 50 - 58, Update SUGGESTED_PROMPTS so each user-facing label and prompt uses the file’s existing createMessage(CUSTOM_WIDGET_AI_ASSISTANT.*) localization pattern, adding or reusing the corresponding message keys as needed while preserving the current suggested prompt content.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/client/src/ce/constants/messages.ts`:
- Around line 2748-2749: Update EMPTY_STATE_MESSAGE to describe applying
complete or partial updates to the HTML, Style, and JavaScript editors,
replacing “replaces” with wording that reflects partial changes and correcting
the “Javascript” spelling.
In
`@app/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/index.tsx`:
- Around line 500-504: Remove the redundant role-based ternary in the message
rendering block and render message.content once through UserMessageContent,
preserving the current output for both user and assistant messages.
In
`@app/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/utils.ts`:
- Around line 28-60: Update buildWidgetAIContext to sanitize srcDoc.html,
srcDoc.css, and srcDoc.js before interpolation so no literal triple-backtick
sequence can appear in the returned context. Add a focused escaping helper that
neutralizes each ``` sequence while preserving the widget source content, and
retain the existing "(empty)" fallback behavior for missing or empty files.
---
Nitpick comments:
In
`@app/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/index.tsx`:
- Around line 50-58: Update SUGGESTED_PROMPTS so each user-facing label and
prompt uses the file’s existing createMessage(CUSTOM_WIDGET_AI_ASSISTANT.*)
localization pattern, adding or reusing the corresponding message keys as needed
while preserving the current suggested prompt content.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: f2cfac13-b4b9-4642-8f50-6d953c2f4218
📒 Files selected for processing (9)
app/client/src/ce/constants/messages.tsapp/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/NotConfigured.tsxapp/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/index.test.tsxapp/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/index.tsxapp/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/utils.test.tsapp/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/utils.tsapp/client/src/pages/Editor/CustomWidgetBuilder/Editor/ChatBot/ChatBot.tsxapp/client/src/pages/Editor/CustomWidgetBuilder/Editor/index.tsxapp/client/src/pages/Editor/CustomWidgetBuilder/constants.ts
💤 Files with no reviewable changes (2)
- app/client/src/pages/Editor/CustomWidgetBuilder/Editor/ChatBot/ChatBot.tsx
- app/client/src/pages/Editor/CustomWidgetBuilder/constants.ts
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
/build-deploy-preview |
|
Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/30435818962. |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
app/client/src/pages/Editor/CustomWidgetBuilder/Editor/ChatBot/ChatBot.tsx (1)
35-44: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick winSecurity Misconfiguration (CWE-346): Origin Validation Error
Reachability: External
● Entry app/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/index.tsx:577 ChatBot │ ▼ ● Sink app/client/src/pages/Editor/CustomWidgetBuilder/Editor/ChatBot/ChatBot.tsxPin the iframe origin for both directions.
postMessagesends the full widget source with"*", whileevent.sourcealone does not verify the iframe’s current origin. If the iframe is navigated or compromised, that page could read the source and send arbitraryhtml_code,css_code, orjs_codeupdates. Derive the expected origin fromCUSTOM_WIDGET_AI_BOT_URLand use it astargetOrigin; also requireevent.originto match before processing messages.Also applies to: 54-58
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@app/client/src/pages/Editor/CustomWidgetBuilder/Editor/ChatBot/ChatBot.tsx` around lines 35 - 44, Pin the iframe messaging origin in the ChatBot component: derive the expected origin from CUSTOM_WIDGET_AI_BOT_URL, pass it as targetOrigin in the ref.current.contentWindow.postMessage call, and require incoming message events to match event.origin as well as the expected iframe source before applying html_code, css_code, or js_code updates.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@app/client/src/pages/Editor/CustomWidgetBuilder/Editor/ChatBot/ChatBot.tsx`:
- Around line 35-44: Pin the iframe messaging origin in the ChatBot component:
derive the expected origin from CUSTOM_WIDGET_AI_BOT_URL, pass it as
targetOrigin in the ref.current.contentWindow.postMessage call, and require
incoming message events to match event.origin as well as the expected iframe
source before applying html_code, css_code, or js_code updates.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 39efe00d-89bc-4414-a60e-7ecaa768329a
📒 Files selected for processing (3)
app/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/index.test.tsxapp/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/index.tsxapp/client/src/pages/Editor/CustomWidgetBuilder/Editor/ChatBot/ChatBot.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
- app/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/index.test.tsx
- app/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/index.tsx
|
🔴🔴🔴 Cyclic Dependency Check: This PR has increased the number of cyclic dependencies by 1, when compared with the release branch. Refer this document to identify the cyclic dependencies introduced by this PR. You can view the dependency diff in the run log. Look for the check-cyclic-dependencies job in the run. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/client/src/pages/Editor/CustomWidgetBuilder/Editor/ChatBot/ChatBot.tsx`:
- Around line 12-23: The ChatBotProps definition currently makes required legacy
copilot inputs optional through Partial. Update ChatBotProps to keep only
uncompiledSrcDoc optional while requiring propId, parentEntityId, update, and
widgetId, preserving the existing ChatBot destructuring and behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 85720d9e-ac4b-466b-a083-edea5149ddf6
📒 Files selected for processing (2)
app/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/index.tsxapp/client/src/pages/Editor/CustomWidgetBuilder/Editor/ChatBot/ChatBot.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
- app/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/index.tsx
|
@coderabbitai review |
✅ Action performedReview finished.
|
## Description **TL;DR** — Ask AI (AI-assisted code editing in the JS/query editors, plus an admin page to configure the AI provider) currently exists only in the enterprise edition. Nothing about it is actually enterprise-specific, so this brings it to CE. The code is ported from `appsmith-ee/release` unchanged where it already lives in `ce` packages, and moved from `src/ee` into `src/ce` where it does not. ### Background Ask AI was originally built for CE on `feat/enable-ai` (PR #41590). That PR was handed over for review in March, went quiet, and was closed by the stale bot on 2026-04-03 without ever being merged. The feature instead shipped in the enterprise repo as `appsmith-ee#8845`, and CE received only inert stubs via #41692 — `ce/selectors/aiAssistantSelectors.ts` and friends returning `null` / `false` / `[]`. That split was not driven by any technical requirement: - `ee/selectors/aiAssistantSelectors.ts` contains **no license or entitlement check** — it reads `state.aiAssistant` and nothing else. - Enablement is ordinary organization configuration (`AIAssistantConfig.isAIAssistantEnabled`), set by an instance admin. - The feature flag that once gated it was removed wholesale in `appsmith-ee#9119`. The enterprise-only placement was a product decision, and this PR reverses it. ### Why port from EE rather than revive the original branch `feat/enable-ai` is four months stale and EE has since reworked the implementation: | | `feat/enable-ai` | `appsmith-ee/release` | |---|---|---| | AI settings storage | flat fields on `OrganizationConfiguration` | nested `AIAssistantConfig` document | | Provider dispatch | inline `if` chain | extracted `dispatchToProvider` | | Datasource schema enrichment | client-side | server-side `AiDatasourceSchemaSerializerCE` | | `/ai-config` endpoints | ~1450 lines inlined into `OrganizationControllerCE` | dedicated `AIConfigControllerCE` + `AIConfigServiceCE` | | `AIReferenceServiceCEImpl` | 239 lines | 107 lines | Reviving the branch would land a divergent second implementation and guarantee a conflict with the community sync. Porting EE's current version starts CE and EE byte-identical on the `ce`-package files. Note the security commit and the review fixes on top of it deliberately move CE **ahead** of EE, so the sync is no longer a no-op — see **CE→EE sync: required resolution** below for the exact steps. ### Architecture **Server** — follows the existing `controller → ce service → ce_compatible → ee override` layering, all in `ce` packages: - `AIConfigControllerCE` / `AIConfigController` for `/ai-config` (`test-connection`, `fetch-models`, `test-api-key`), each gated on `MANAGE_ORGANIZATION` - `AIConfigServiceCE(Impl)`, `AIAssistantServiceCE(Impl)`, `AIReferenceServiceCE(Impl)` with their `ee` override points and `AIConfigServiceCECompatible(Impl)` - `AIAssistantConfig` on `OrganizationConfiguration`, `Migration075`, and the `AIProvider` / DTO types - `POST /users/ai-assistant/request` on `UserControllerCE` - `ai-references/*.md` prompt-reference resources **Client** — the implementation moves from `src/ee` into `src/ce`, which is where a CE-owned feature belongs. This is safe because the EE UI files import nothing EE-only; every import is a package, a shared path, or an `ee/` alias that resolves through CE's shims. The existing `src/ee` shims from #41692 are untouched and now re-export real code instead of stubs, and the exported symbol surface of every relocated file is unchanged. The AI reducer and saga are registered in `ce/reducers` and `ce/sagas` rather than their `ee` counterparts, and the admin AI settings page is registered for superusers. **This PR adds no `src/ee` files**, because the CE pre-push architecture guard rejects them. Four CE-owned modules therefore have no `ee` shim to import through — `aiAssistantReducer`, `AIAssistantSagas`, `GPT/shared`, and the admin AI config — so they are imported from `ce/` directly, each with a documented `eslint-disable` for `no-restricted-imports`. That is the same accommodation the native Custom Widget copilot uses in #42063. If EE would rather route these through `ee/` shims, those shims belong in a companion EE PR. Adds `react-markdown` and `remark-gfm`, used by the assistant's response renderer. ### Impact on existing instances Inert by default. `AIAssistantConfig` is absent until an admin configures a provider, `isAIAssistantEnabled` defaults to false, and `Migration075` only adds the field. With nothing configured, the Ask AI affordances stay hidden exactly as they do today — no feature flag is involved, matching how EE ships it since #9119. ### Security fixes included A nine-reviewer council on the ported code surfaced four defects. All four are inherited byte-identical from EE and are therefore **live in EE production today**; because EE's `AIConfigServiceImpl` delegates every method to the CE class and `AIAssistantServiceImpl` overrides nothing, fixing them here carries them into EE through the sync rather than needing a parallel EE change. 1. **SSRF, two call sites.** `callLocalLLMAPI` built a raw `WebClient`, bypassing `WebClientUtils` and substituting a check that tested only `isLinkLocalAddress` on the first resolved address — missing loopback, and racy. `callAzureOpenAIAPI` chained `.clientConnector(...)` *after* `WebClientUtils.builder()`, which replaces the connector carrying the DNS-aware resolver; it read as protected and was not. Both now build through `WebClientUtils.builder(httpClient)`. 2. **`getAIConfig` authorization.** It was the only one of five service methods without `MANAGE_ORGANIZATION`, disclosing `localLlmUrl`, `azureOpenaiEndpoint` and the deployment name to any authenticated user, on every session. Managers still get the full configuration; everyone else gets enablement, provider, and credential-presence booleans — exactly what the client consumes. 3. **API keys stored in cleartext.** The `@Encrypted` annotations never applied — the traversal only descends into `AppsmithDomain` types, and the write is a sparse `updateById` so the encrypting lifecycle listener never fires. `AIConfigSecretsCE` now encrypts and decrypts at the few write/read points, and `Migration076` encrypts existing values in place, idempotently. 4. **Admin key field corrupted credentials.** A stored key loaded into the input as the literal `••••••••` with a save guard comparing against that mask, so typing without clearing persisted `••••••••sk-…` behind a success toast. **Behaviour change worth calling out:** a local-LLM URL pointing at loopback is now refused. In the single-container CE deployment `127.0.0.1` is Mongo, Redis and RTS rather than the operator's Ollama — which is the reason to refuse it. A local model on another host or container stays reachable by hostname or private IP. This also makes the runtime path agree with `/ai-config/test-connection`, which already went through `WebClientUtils`. ### Follow-ups (tracked, not addressed here) 1. **Unmetered LLM spend** — `/users/ai-assistant/request` has no rate limit or per-user quota; on an open-signup CE instance any account can drain the admin's provider billing. 2. **OpenAI provider lacks guards the others have** — no empty/max-length prompt validation and no `max_tokens`. 3. **`/users/ai-assistant/request` maps every failure to 400**, including upstream timeouts, which hurts monitoring. 4. **A measured 0.5–1.0 s reactive-thread stall** in `AiDatasourceSchemaSerializerCE.extractReferencedTableNames` at the DTO's own size ceilings. 5. **Dead code carried from EE** — `AIWindow` and the in-editor `AISidePanel` have no importer, and `ce/utils/aiSchemaSerializer.ts` has no consumer but its own test. 6. **Test coverage** — `AIConfigSecretsCE` and `Migration076` both route through `EncryptionHelper`, whose static initialiser needs `APPSMITH_ENCRYPTION_PASSWORD`/`SALT`. Those are set for the integration-test and Docker CI jobs but not for `server-unit-tests`, so this coverage belongs in the integration suite. A follow-up in `appsmith-ee` should reduce EE's `src/ee` Ask AI files to re-export shims and drop its `ee/reducers` + `ee/sagas` registration, so EE consumes this CE implementation instead of shadowing it. https://linear.app/appsmith/issue/APP-15737 Supersedes the original, stale-closed CE attempt in #41590. ## Automation /ok-to-test tags="@tag.All" ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/30836147916> > Commit: deab697 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=30836147916&attempt=2" target="_blank">Cypress dashboard</a>. > Tags: `@tag.All` > Spec: > <hr>Mon, 03 Aug 2026 18:47:45 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [x] Yes - [ ] No Ask AI becoming available in the community edition is a user-facing change worth announcing. ## CE→EE sync: required resolution **This section is load-bearing. The sync of this PR is not a no-op, and two of its failure modes arrive through *clean* merges — no conflict marker will surface them.** Whoever runs the sync should follow this, and it is the condition the architecture review set for unblocking. Of the changed files that also exist in EE, **18 differ from EE's copy**. Most are the deliberate hardening in the security commit, which moves CE ahead of EE on purpose. Five are add/add conflicts (`ce/sagas/AIAssistantSagas.ts`, `ce/pages/AdminSettings/config/ai.tsx`, `pages/AdminSettings/AI/index.tsx`, `AIAssistantServiceCEImpl.java`, `AIConfigServiceCEImpl.java`). > **These steps are for the sync itself. None of them can be pre-landed in EE as a separate PR — verified against `appsmith-ee/origin/release` (`0aff44fa56`, "Sync community release"):** > > - **The saga.** EE's `ce/sagas/index.tsx` does **not** register the AI saga yet — only `ee/sagas/index.tsx` does. Removing EE's registration *before* the CE change syncs would leave zero registrations and take Ask AI out of EE entirely. It is only safe once CE's registration has arrived. > - **The enum.** EE's `ASK_AI_ORG_CONFIG_UPDATED` / `ASK_AI_ORG_TEST_RUN` are referenced by `AIConfigServiceCEImpl` (lines 172-173, 236) and its test. Deleting them ahead of the sync breaks EE's compile. This is a conflict *resolution*, not a change that exists independently. > > So this is work for whoever runs the sync, in the same merge — not a companion PR that can land first. ### 1. Remove EE's now-duplicate saga registration CE now registers the AI saga itself, and that CE file merges **cleanly** into EE — so EE ends up registering it twice: | EE file | What to do | |---|---| | `app/client/src/ee/sagas/index.tsx` | **Remove** the `aiAssistantSagas` import (from `ee/sagas/AIAssistantSagas`, a shim that re-exports `ce/sagas/AIAssistantSagas`) and its entry in the saga array — CE's registration now covers EE | Left as-is, EE runs the *same* watcher generator twice, so every Ask AI action fires duplicate requests to the provider — double latency and double spend. This one genuinely needs an EE change: EE builds `sagasArr` as `[...CE_Sagas, …, aiAssistantSagas]`, appending its own entry *after* spreading CE's list, so CE cannot deduplicate it from its side. **The duplicate admin category no longer needs an EE change.** `ConfigFactory.register` is CE-owned and was a raw push into three collections (`categories`, `settings`, `savableCategories` — only `settingsMap` was keyed and therefore safe). It is now idempotent, so a category registered from both `ce/` and `ee/` collapses to one entry on its own. EE's `ConfigFactory.register(AIConfig)` can stay exactly as it is. ### 2. Resolve the five add/add conflicts toward CE, wholesale `Migration076EncryptAIAssistantApiKeys` merges cleanly and will encrypt EE's stored keys on first boot. EE's current `AIAssistantServiceCEImpl` / `AIConfigServiceCEImpl` read those keys **without** `AIConfigSecretsCE.decrypt`. If either file is resolved toward EE's copy, **EE sends ciphertext as its `Authorization` header and Ask AI breaks in EE**. `pages/AdminSettings/AI/index.tsx` must also move together with `AIConfigServiceCEImpl` — the client's `hasStoredX` model depends on the server's `has*` response shape and the manager-only full config. ### 3. Collapse the duplicated analytics enum `AnalyticsEvents.java`: CE adds `ASK_AI_ORG_CONFIG_UPDATED` / `ASK_AI_ORG_TEST_RUN` at the enum tail (lines 106/109); EE already has both at lines 140/143. Naive resolution produces duplicate enum constants and **fails to compile**. Keep one pair. ### Correction to an earlier claim in this description An earlier revision said porting from EE keeps the two editions "byte-identical on the `ce`-package files, so the sync stays a no-op". That was true of the initial port and is **no longer true**: the security commit, and the review fixes on top of it, deliberately move CE ahead. The byte-identity argument still holds for the ~40 untouched ported files and for the reason to port rather than revive `feat/enable-ai`, but the sync itself needs the three steps above. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added Ask AI assistance for JavaScript, SQL, GraphQL, and JSON editing. * Added resizable chat panels with conversation history, editor context, Markdown responses, quick actions, and keyboard shortcuts. * Added a global AI assistant panel with context-aware prompts and schema support. * Added administrator settings for Claude, OpenAI, Azure OpenAI, and local Ollama-compatible providers. * Added connection, credential, and model testing with secure credential handling and request safeguards. * **Documentation** * Added reference guides for JavaScript, SQL, GraphQL, and common troubleshooting scenarios. * **Tests** * Added coverage for schema handling and AI configuration workflows. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
|
Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/30939032401. |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (1)
app/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/index.tsx (1)
282-288: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low valueRemove the stale CE stub note.
app/client/src/ce/selectors/aiAssistantSelectors.tsdefinesgetAIMessages(state: DefaultRootState): AIMessage[]and returnsstate.aiAssistant.messages, while EE re-exports the CE selector. This comment is inaccurate and can mislead future maintenance; update or remove it.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@app/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/index.tsx` around lines 282 - 288, Remove the stale CE selector stub comment immediately above the messages assignment in the AI assistant component. Keep the getAIMessages selector usage and AIMessage[] cast unchanged.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@app/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/index.test.tsx`:
- Around line 148-195: Update applyCodeUpdatesFromAssistant and its surrounding
widget flow to associate each assistant response with the active widget, then
prevent bulkUpdate when the response recipient differs from the current
widgetId. Extend the test coverage to deliver a response through the widget flow
and verify that cross-widget responses are ignored while matching-widget
responses still apply.
In
`@app/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/index.tsx`:
- Around line 68-72: Update APPLIED_FILE_LABELS to use localized message keys
resolved through createMessage rather than hardcoded English text, ensuring the
HTML, Style, and JavaScript chip labels are localized. Use “JavaScript” with the
correct capitalization for the JavaScript label and keep the existing label
lookup behavior intact.
- Around line 202-215: Replace the native styled.button used by
SuggestedPromptChip with the appropriate ADS Button variant, and replace
PromptTextArea with the ADS multiline/textarea control. Add a stable accessible
label or aria-label to the textarea, moving any necessary styling to its
wrapper/container while preserving the existing prompt interaction and
appearance.
- Around line 373-386: Bind each AI request and response to the originating
widget and request identity: update
app/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/index.tsx
lines 373-386 to include both identifiers in fetchAIResponse, propagate them
through the success payload, reducer, and AIMessage handling around lines
317-361, and guard bulkUpdate so it runs only when the response matches the
current builder context. Add a regression test in
app/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/index.test.tsx
lines 148-195 covering a delayed response after the widget context changes.
---
Nitpick comments:
In
`@app/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/index.tsx`:
- Around line 282-288: Remove the stale CE selector stub comment immediately
above the messages assignment in the AI assistant component. Keep the
getAIMessages selector usage and AIMessage[] cast unchanged.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 2ae096e7-eab7-4065-b8a0-fbafd83bf9f0
📒 Files selected for processing (9)
app/client/src/ce/constants/messages.tsapp/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/NotConfigured.tsxapp/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/index.test.tsxapp/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/index.tsxapp/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/utils.test.tsapp/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/utils.tsapp/client/src/pages/Editor/CustomWidgetBuilder/Editor/ChatBot/ChatBot.tsxapp/client/src/pages/Editor/CustomWidgetBuilder/Editor/index.tsxapp/client/src/pages/Editor/CustomWidgetBuilder/constants.ts
💤 Files with no reviewable changes (2)
- app/client/src/pages/Editor/CustomWidgetBuilder/Editor/ChatBot/ChatBot.tsx
- app/client/src/pages/Editor/CustomWidgetBuilder/constants.ts
🚧 Files skipped from review as they are similar to previous changes (5)
- app/client/src/ce/constants/messages.ts
- app/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/utils.test.ts
- app/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/NotConfigured.tsx
- app/client/src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/utils.ts
- app/client/src/pages/Editor/CustomWidgetBuilder/Editor/index.tsx
The builder's AI tab sends mode "custom_widget", which intentionally has no bundled reference document. Document that contract at the fallback branch it relies on. Also ensures deploy previews build the server from source instead of reusing the prebuilt cache jar. Co-Authored-By: Claude Fable 5 <[email protected]>
|
/build-deploy-preview |
|
Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/30942324881. |
|
/build-deploy-preview |
|
Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/30984620202. |
Adds a behaviour contract for the apply step in the Custom Widget Builder's AI tab. These seven tests are RED on purpose: each failure marks a case where a reply can overwrite or silently drop widget code the user never agreed to change. They use the real aiAssistantReducer and the real selectors instead of mocks. The existing suite mocks both and uses redux-mock-store, so state transitions never actually run - which is why none of these cases surfaced. What each failure means: - a question answered with a ```javascript snippet replaces the whole JS file (the server's system prompt asks the model to tag snippets that way) - a reply cut off mid block applies the closed blocks over the old JS, leaving new markup beside stale logic - clearing the chat mid-generation does not end the request, so the reply still writes to editors the user walked away from - "remove all the CSS" is a silent no-op, because empty blocks are dropped - carriage returns from a CRLF reply land in the editors - a 60 KB widget builds a 61,436 char context, over the server's 50,000 limit on AIEditorContextDTO.functionString - a first-time user on an instance with no AI provider still opens on the AI tab, which can only show the not-configured screen No production code is touched.
subrata71
left a comment
There was a problem hiding this comment.
Hey @tomjose92 — went through this properly and actually ran the code instead of just reading it. The idea is solid, and getting rid of the internal.appsmith.com iframe is a genuinely good win. But I hit a few cases where the assistant overwrites code the user never asked it to touch, so I'd like those sorted before this goes in.
Review was requested here: https://theappsmith.slack.com/archives/C09NG5BJ18S/p1785912148207769
I pushed some tests to your branch
Commit 04a25fdc39 adds app/client/src/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant/codeApply.test.tsx.
Heads up: 7 of those tests fail on purpose. Each one says what should happen, so every red test is one of the problems below. No production code was touched, and your existing 21 tests still pass. Fix the issues and the file goes green. If you'd rather restructure or rename it, go ahead — I mostly wanted these pinned down as running code instead of just words in a review.
Quick note on why new tests were needed: the current test file mocks ee/selectors/aiAssistantSelectors and uses redux-mock-store, so the real reducer never runs. That's why none of this showed up. Mine use the real reducer and the real selectors.
Blockers
1. Asking a plain question can delete the whole JS file
extractCodeUpdates maps ```javascript to the JS file, and anything it matches replaces that file completely.
Now look at what the server sends in the system prompt (AIAssistantServiceCEImpl.buildSystemPrompt):
Use fenced code blocks with language identifiers (
javascript,sql, etc.) for all code snippets
So the server is literally telling the model to tag every snippet that way. Your rule 3 in buildWidgetAIContext says the opposite — but yours is in the user message and the server's is in the system prompt, which models weight higher.
I ran it. Ask "how do I read the model?", get a normal three-line answer with a ```javascript block, and this is what lands in the editors:
{
"html": "<div id='app'><h1>Sales dashboard</h1></div>",
"css": ".app { color: blue; font-family: sans-serif; }",
"js": "console.log(appsmith.model.rows);"
}Their whole JS file is gone, replaced by an example snippet.
Smallest fix: drop javascript from LANGUAGE_TO_FILE so only an exact js tag counts. I'd leave the server prompt alone — that line is shared with the SQL and GraphQL modes.
2. A cut-off reply applies half the change
Claude gets called with max_tokens: 8192, but the prompt asks for the complete contents of every changed file. So a reply can end in the middle of a block.
When that happens the parser returns only the blocks that closed, and those get applied anyway:
{
"html": "<div id='app'><h1 class='hot'>Sales dashboard</h1></div>",
"css": ".hot { color: red; }",
"js": "appsmith.onReady(() => {\n renderChart(appsmith.model.rows);\n});"
}New HTML and CSS sitting on top of the old JS. Broken widget — and the chat still shows "Updated editors: HTML, Style" like it worked.
Fix: if the reply has an unclosed fence, apply nothing and tell the user it got cut off.
3. Clearing the chat doesn't cancel the request, and the reply still writes
This is the one that bothers me most, because there's no guessing about model behaviour involved. Just normal clicking.
- The clear button is enabled while a request is running (I checked:
disabled: false) CLEAR_AI_RESPONSEempties the messages but never touchesisLoading, so the saga keeps goinghandleClearChatalso resetslastAppliedTimestampRefto0, which guarantees the late reply gets applied
So: user gets bored of a slow generation, hits clear, spinner keeps spinning, and a minute later code they thought they threw away overwrites their widget.
Fix: give each request an id and ignore stale successes, and have CLEAR_AI_RESPONSE reset isLoading. That part lives in the shared Ask AI reducer/saga (also used by the main editor's AI panel), so it might be cleaner as its own PR with its own Linear issue — your call.
One fix covers all three
If you add an Apply button per block, or a small diff preview, instead of writing straight to the editors, all three of these go away at once. It also handles the "widget code came from a template someone else wrote" case, where the source itself could steer the model. Right now there's no confirm step and no per-message undo — only the whole-session revert via initialSrcDoc.
Should fix before we turn the flag on
4. Big widgets just fail
AIEditorContextDTO.functionString is @Size(max = 50000) and the request DTO is validated, so it's a hard reject, not a trim.
Your preamble is 1,457 characters, which leaves 48,564 characters (~47.4 KB) for the actual widget source. I tested this against your DP:
functionString = 50001 chars -> HTTP 400
AE-APP-4028: Validation Failure(s): {context.functionString=Function string cannot exceed 50000 characters}
That raw validation string is what the user sees. Worth clamping client-side with a proper message. Same idea for conversation history — AIMessageDTO.content is also capped at 50,000 and assistant replies carry full file dumps, so long chats will start failing too. Pruning by size rather than just MAX_MESSAGES would help.
5. First-time users land on an empty AI tab
TabsLayout picks the AI tab first when the flag is on. But if the org hasn't set up an AI provider, that tab can only show "AI assistant isn't set up". So the builder opens on a dead screen instead of the JS editor.
Good news: it's only people with no saved tab preference — I checked, and anyone who last used JS keeps JS. Still worth gating the default on isEnabled && hasApiKey.
Worth flagging the product side of this too: the old copilot worked for everyone because we hosted the model. This one only works if the customer configures a provider and pays for it. Probably fine, just make sure that's a deliberate call before the flag goes on.
6. "Remove all the CSS" does nothing
Empty tagged blocks get dropped by if (file && match[2].trim()), so the user can't ask the assistant to clear a file. And stripCodeUpdates hides the block too, so they see neither a change nor the code — just "Removed the stylesheet." and nothing happening.
Minor
7. If a reply comes back with CRLF, the \r characters end up in the editors — I get ".a { color: red; }\r". One replace(/\r\n/g, "\n") sorts it.
Stuff I couldn't check
Being upfront about this so you know what's verified and what isn't.
- The server always appends
common-issues.mdto the system prompt, even forcustom_widgetmode. That's ~7.9 KB about app-level{{Query1.data}}bindings and JS objects, which don't exist inside a widget sandbox. I couldn't confirm the impact because the system prompt is built server-side and never comes back to the client — I'd need server logs. Might be worth skipping it for this mode, or adding acustom_widget-reference.mdand putting the mode inSUPPORTED_MODES. - No accessibility pass. The message area has no
aria-live, and the icon-only clear button has no accessible name. - There's no Cypress coverage for this tab, so the green
@tag.Allrun doesn't tell us much about this feature.
What's good
- Ditching the third-party iframe is a real security and privacy improvement — widget code stops leaving the instance, and there's no more
postMessage(..., "*")to an external origin. For self-hosted customers that alone justifies this. - Clean removal. No leftover constants, no dangling references, nothing stale in Cypress.
- The backtick escaping (
breakMarkdownFence/restoreMarkdownFence) is a nice touch, and asserting that the context never contains triple backticks is exactly the right thing to pin. - Nice one on moving the component out of
ce/ina887c54— that reads much better than the directce/import. - Flag defaults to
false, so the risk is contained while this gets sorted.
Happy to pair on the apply-confirmation bit if it's useful — it's the one change that clears items 1, 2 and 3 together.
|
Thanks for the detailed review — it helped tighten this up. I have addressed the following points:
I have also added regression coverage for these behaviors and validated the generation and cancellation flows in the running product. One thing @subrata71 I need your help is in how do we fix for the 4th pointer you mentioned. Considering the user can configure any model as small as haiku, and we have hardcoded the max_tokens as 8192 |
|
/build-deploy-preview |
|
Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/30997460895. |
| expect(bulkUpdate).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("can empty a file when asked to remove it", () => { |
There was a problem hiding this comment.
@tomjose92 Was it intentional to delete these tests? May I know the reason please?
There was a problem hiding this comment.
@subrata71 You’re right to call this out—I made a mistake by removing those two test cases.
I’ve restored both. The empty CSS case is now handled correctly, so an explicitly empty CSS block clears the file. For large widget context, the test now verifies that an oversized request is not sent and that the user sees a clear message instead.
@tomjose92 Not necessarily it has to be taken care in this PR but can we not add |
Summary
src/ceinternal.appsmith.comiframe integration now that Ask AI configuration and execution are CE-ownedArchitecture and community sync
src/eechanges; the CE pre-push architecture guard passesImpact on existing instances
The AI tab remains behind the pre-existing
release_custom_widget_ai_builderflag. When enabled, the tab now always renders the native assistant in both CE and EE. Instances with a configured and enabled Ask AI provider get the conversational editor experience; unconfigured instances get administrator guidance. The Custom Widget builder no longer loads or communicates withinternal.appsmith.com.Validation
yarn jest src/ce/pages/Editor/CustomWidgetBuilder/Editor/AIAssistant --runInBand— 21 tests passedyarn tsc --noEmit— passedgit diff --check— passedLinear issue
https://linear.app/appsmith/issue/APP-15735
Automation
/ok-to-test tags="@tag.All"
Tip
🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/31007662363
Commit: 697e3a8
Cypress dashboard.
Tags:
@tag.AllSpec:
Wed, 05 Aug 2026 13:53:28 UTC
Summary by CodeRabbit