Commit ede65d3
feat(ambient-ui): live preview with visual feedback and BFF proxy (#1618)
## Summary
- **Live preview overlay**: sandboxed iframe with device size toggles
(desktop/tablet/mobile), host allowlist validation, CSP frame-src
hardening, and BFF reverse proxy for auth-protected preview targets
- **Visual feedback mode**: crosshair element/region selection, comment
cards, right-side batch panel with inline send confirmation, feedback
delivery via session messages API
- **Annotation registry**: 19 registered annotation keys with
categories, labels, and icons per the ambient-ui spec
- **BFF preview proxy**: reverse-proxies preview URLs through the
Next.js BFF, strips X-Frame-Options/CSP frame-ancestors, injects
navigation interceptor for OAuth redirect chain handling, forwards SSO
tokens for same-issuer auth
- **PostMessage bridge**: `preview-bridge.js` for cross-origin HTML
capture with hover highlighting
- **CI fix**: adds ambient-ui to stage build pipeline and fixes oauth
client-id
## Architecture
```
User clicks "Open Preview" on session with ambient-code.io/ui/preview-url annotation
→ Preview overlay opens with sandboxed iframe
→ iframe src = /api/preview-proxy?url=<target>
→ BFF fetches target server-side, strips X-Frame-Options, injects <base> + interceptor
→ Content renders same-origin in iframe
→ Feedback mode: click/drag to select, comment, batch send via POST /sessions/{id}/messages
```
**Port/adapter pattern**: SessionMessagesPort + direct-fetch adapter
(bypasses broken SDK SessionMessageAPI). Domain types only in components
— no SDK type leakage.
**167 tests** across 13 test files. Fakes over mocks per workflow
standards.
## Security
- Sandbox: `allow-scripts allow-same-origin allow-forms` (no
top-navigation, no popups)
- `referrerPolicy="no-referrer"` on iframe
- Host allowlist validation (client-side + CSP frame-src + server-side
proxy)
- Payload sanitization: backtick/newline escaping to prevent prompt
injection via captured HTML
- `maxLength=2000` on comment textarea
- 10MB response size limit on preview proxy
- Manual redirect handling (`redirect: "manual"`) to prevent
off-allowlist redirect chains
## Test plan
- [ ] Navigate to project → Fleet → session with
`ambient-code.io/ui/preview-url` annotation
- [ ] Click "Open Preview" — iframe renders proxied content
- [ ] Toggle device sizes (Desktop/Tablet/Mobile)
- [ ] Press `C` or click "Comment" to enter feedback mode
- [ ] Click element → comment card appears → "Add Comment" → appears in
right panel
- [ ] Drag region → region selection with dimensions
- [ ] "Send All Feedback" → inline confirmation → delivered via session
messages API
- [ ] Test with blocked URL → "Preview URL is not on the trusted hosts
allowlist"
- [ ] Test with auth-protected URL → proxy handles redirect chain,
renders login page
- [ ] Verify 167 tests pass: `cd components/ambient-ui && npx vitest
run`
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Added preview overlay with interactive feedback collection, supporting
element capture and region selection with comments.
* Implemented cross-origin iframe preview support with automatic bridge
injection and hover highlighting.
* Added session message delivery for user feedback via structured event
payloads.
* Introduced preview host allowlisting and URL validation for trusted
preview content.
* **Configuration**
* Updated OAuth client identifier and CSP headers for iframe embedding.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>1 parent e098d0e commit ede65d3
36 files changed
Lines changed: 3711 additions & 32 deletions
File tree
- .github/workflows
- components
- ambient-ui
- public
- src
- adapters
- __tests__
- app
- (dashboard)/[projectId]/fleet/[sessionId]/_components
- api
- ambient/v1/[...path]
- preview-proxy
- components
- preview
- ui
- domain
- __tests__
- hooks
- __tests__
- lib
- __tests__
- ports
- queries
- __tests__
- manifests/overlays/production
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
33 | | - | |
| 35 | + | |
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
| |||
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
63 | | - | |
| 65 | + | |
| 66 | + | |
64 | 67 | | |
65 | 68 | | |
66 | 69 | | |
| |||
384 | 387 | | |
385 | 388 | | |
386 | 389 | | |
| 390 | + | |
387 | 391 | | |
388 | 392 | | |
389 | 393 | | |
| |||
462 | 466 | | |
463 | 467 | | |
464 | 468 | | |
| 469 | + | |
465 | 470 | | |
466 | 471 | | |
467 | 472 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
24 | | - | |
| 26 | + | |
25 | 27 | | |
26 | | - | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
4 | 45 | | |
5 | 46 | | |
6 | 47 | | |
| |||
9 | 50 | | |
10 | 51 | | |
11 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
12 | 66 | | |
13 | 67 | | |
14 | 68 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
0 commit comments