Skip to content

Conversation

@Kitenite
Copy link
Contributor

@Kitenite Kitenite commented Sep 24, 2025

Description

Related Issues

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Release
  • Refactor
  • Other (please describe):

Testing

Screenshots (if applicable)

Additional Notes


Important

Enhance chat context with active branch information and refactor prompt structure for better organization.

  • Behavior:
    • ChatContext in context.ts now includes active branch context when generating chat context from selected elements and frames.
    • getBranchContext() updated to derive branch IDs from both highlighted context and frames.
  • Refactoring:
    • Moved prompt-related files to prompt/constants directory.
    • Updated imports in provider.ts, onlook-instructions.ts, and suggestion.ts to reflect new prompt file structure.
  • Misc:
    • Minor prompt text adjustments in context.ts and system.ts for clarity.
    • Removed unnecessary whitespace in route.ts.

This description was created by Ellipsis for 3a0c36a. You can customize this summary. It will automatically update as commits are pushed.

Summary by CodeRabbit

  • New Features

    • Chat now incorporates frames and branch context, enabling more precise, branch-aware suggestions and context generation.
  • Improvements

    • Clearer prompt messages: added line-number guidance and explicit trust instructions for file/highlight content.
    • Stronger safeguards around data-oid attributes to prevent unintended changes.
  • Refactor

    • Consolidated prompt constants into a central export and streamlined imports (no user-facing behavior change).
  • Tests

    • Updated prompt fixture text to align with new messaging and safeguards.

@vercel
Copy link

vercel bot commented Sep 24, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
web Ready Ready Preview Comment Sep 24, 2025 10:21pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Sep 24, 2025 10:21pm

@supabase
Copy link

supabase bot commented Sep 24, 2025

This pull request has been ignored for the connected project wowaemfasoptxrdjhilu because there are no changes detected in apps/backend/supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai
Copy link

coderabbitai bot commented Sep 24, 2025

Caution

Review failed

The pull request is closed.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

This PR integrates frame data into chat context generation, adds branch-aware prompt handling in the AI prompt provider, consolidates prompt constants/export surfaces, updates prompt/test copy, and performs minor import cleanups and a whitespace change. Public exports shift toward a centralized constants module; provider signatures expand to include message indices and branch helpers.

Changes

Cohort / File(s) Summary
Editor chat context: frames integration
apps/web/client/src/components/store/editor/chat/context.ts
Context generation now accepts and threads both elements and frames; branch context derives from frames and highlighted context. Reaction callback emits {elements, frames}.
Prompt provider: branch support and API tweaks
packages/ai/src/prompt/provider.ts
Introduces MessageContextType enum usage, branch content helpers (getBranchContent, changed getBranchesContent), hydrates user messages with branches, updates file/error/highlight builders to include branch tags, broadens HydrateMessageOptions signature, minor nullish coalescing change.
Prompt constants and exports
packages/ai/src/prompt/constants/context.ts, packages/ai/src/prompt/constants/system.ts, packages/ai/src/prompt/constants/index.ts, packages/ai/src/prompt/index.ts
Adjusts copy for files/highlights/system text; adds constants index re-exports; prompt index now re-exports constants and drops direct create/onlook/summary exports.
Import consolidation to constants
apps/web/client/src/server/api/routers/chat/suggestion.ts, packages/ai/src/tools/classes/onlook-instructions.ts
Collapses imports to source prompts from constants, including SUGGESTION_SYSTEM_PROMPT and ONLOOK_INSTRUCTIONS; no logic changes.
Tests: prompt text updates
packages/ai/test/prompt/data/create-page-system.txt, .../file.txt, .../highlights.txt, .../system.txt, .../user.txt
Syncs test fixtures with new prompt wording (files/highlights/system guidance and formatting).
Whitespace cleanup
apps/web/client/src/app/api/chat/route.ts
Removes a blank line; no behavioral change.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant UI as Editor UI
  participant Sel as Selection Tracker
  participant Ctx as Context Generator
  participant Chat as Chat Store
  participant Svc as Chat Service
  participant Prov as Prompt Provider
  participant LLM as Model

  UI->>Sel: User updates selection (elements, frames)
  Sel-->>Ctx: Reaction emits {elements, frames}
  Ctx->>Ctx: Build highlighted + branch context (from frames + elements)
  Ctx-->>Chat: Context payload
  Chat->>Svc: Send messages + context
  Svc->>Prov: Hydrate system/user prompts with contexts
  Prov->>Prov: Include files/highlights/errors + branch tags
  Prov-->>Svc: Final prompt
  Svc-->>LLM: Invoke
  LLM-->>Svc: Response
  Svc-->>Chat: Update conversation
Loading
sequenceDiagram
  autonumber
  participant Ctx as Contexts
  participant Prov as Prompt Provider
  participant Build as Builders

  Ctx-->>Prov: Message contexts (FILE, HIGHLIGHT, ERROR, PROJECT, IMAGE, BRANCH)
  Prov->>Build: getFilesContent(...branchId)
  Build-->>Prov: File blocks + getBranchContent(id)
  Prov->>Build: getHighlightsContent(...branchId)
  Build-->>Prov: Highlight blocks + branch tags
  Prov->>Build: getErrorsContent(...branchId)
  Build-->>Prov: Error blocks + branch tags
  Prov->>Prov: getBranchesContent(branches[])
  Prov-->>Prov: Hydrated user message including branches
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

A nibble of frames, a branch in the breeze,
I thump-tap prompts with whiskered ease.
Tags stay put—no pass-down spree!
Constants hop to one API.
Tests now chirp the updated tune—
Contexts bloom, we ship by noon. 🐇✨

✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/contexts

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b616f66 and 3a0c36a.

📒 Files selected for processing (14)
  • apps/web/client/src/app/api/chat/route.ts (0 hunks)
  • apps/web/client/src/components/store/editor/chat/context.ts (4 hunks)
  • apps/web/client/src/server/api/routers/chat/suggestion.ts (1 hunks)
  • packages/ai/src/prompt/constants/context.ts (1 hunks)
  • packages/ai/src/prompt/constants/index.ts (1 hunks)
  • packages/ai/src/prompt/constants/system.ts (1 hunks)
  • packages/ai/src/prompt/index.ts (1 hunks)
  • packages/ai/src/prompt/provider.ts (10 hunks)
  • packages/ai/src/tools/classes/onlook-instructions.ts (1 hunks)
  • packages/ai/test/prompt/data/create-page-system.txt (1 hunks)
  • packages/ai/test/prompt/data/file.txt (1 hunks)
  • packages/ai/test/prompt/data/highlights.txt (1 hunks)
  • packages/ai/test/prompt/data/system.txt (1 hunks)
  • packages/ai/test/prompt/data/user.txt (1 hunks)

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@vercel vercel bot temporarily deployed to Preview – docs September 24, 2025 22:14 Inactive
@vercel vercel bot temporarily deployed to Preview – docs September 24, 2025 22:17 Inactive
@Kitenite Kitenite merged commit 2931e91 into main Sep 24, 2025
6 of 7 checks passed
@Kitenite Kitenite deleted the fix/contexts branch September 24, 2025 22:20
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