Skip to content

Conversation

@fredalai
Copy link
Contributor

@fredalai fredalai commented Oct 21, 2025

Description

This PR enhances when saving query results as Views. For follow-up questions, we will use the rephrased question (AI-rewritten question).

Implementation

The implementation uses client-side decision-making, where the frontend determines whether it's an opening question and passes the corresponding question text (original or rephrased) to the backend via GraphQL mutation.

Improve Question Handling Logic When Creating Views

Changes

Core Changes:

  • Added rephrasedQuestion parameter to CreateViewInput to allow frontend to explicitly specify the question text to save
  • Modified createView resolver to use the passed rephrasedQuestion instead of directly using response.question

Frontend Logic Optimization:

  • Added isOpeningQuestion prop to AnswerResult component to determine if it's an opening question
  • Implemented smart question selection logic:
    • Opening Question: Uses original question text
    • Follow-up Question: Uses rephrased question text (includes full context)
  • Updated SaveAsViewModal to receive and pass through the rephrasedQuestion parameter

Technical Details

Modified Files:

  1. wren-ui/src/apollo/server/schema.ts - GraphQL schema definition
  2. wren-ui/src/apollo/server/resolvers/modelResolver.ts - Resolver implementation
  3. wren-ui/src/apollo/client/graphql/__types__.ts - TypeScript type definitions
  4. wren-ui/src/components/pages/home/promptThread/AnswerResult.tsx - Main logic implementation
  5. wren-ui/src/components/pages/home/promptThread/index.tsx - Props passing
  6. wren-ui/src/components/pages/home/promptThread/store.tsx - Store type definitions
  7. wren-ui/src/components/modals/SaveAsViewModal.tsx - Modal component update

Screenshots or Recordings

Opening Question (First thread response) -> (save as view with question)

截圖 2025-10-21 上午10 43 54 截圖 2025-10-21 上午10 45 16

Follow-up Question WITH rephrased Question -> (save as view with rephrased question)

截圖 2025-10-21 上午10 47 16 截圖 2025-10-21 上午10 50 21

Testing

Recommended test scenarios:

  1. Create a View from an opening question and verify it uses the original question text
  2. Create a View from a follow-up question and verify it uses the rephrased question text
  3. Verify that the created View stores the correct question text in the database

Summary by CodeRabbit

  • New Features
    • Rephrased question support: When saving views from conversation results, the system now captures and uses rephrased versions of opening questions, providing improved clarity and better context for saved queries.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 21, 2025

Walkthrough

The changes introduce a rephrasedQuestion field to the GraphQL CreateViewInput type and thread it through the application stack. The field is computed in the AnswerResult component based on rephrasing context, passed through the SaveAsViewModal, and used by the modelResolver to replace the original question when creating views.

Changes

Cohort / File(s) Change Summary
GraphQL Type Definitions
wren-ui/src/apollo/client/graphql/__types__.ts, wren-ui/src/apollo/server/schema.ts
Added required rephrasedQuestion: String field to CreateViewInput type
Model Resolver
wren-ui/src/apollo/server/resolvers/modelResolver.ts
Updated createView to destructure rephrasedQuestion from args and use it as the question value instead of response.question
Save Modal Component
wren-ui/src/components/modals/SaveAsViewModal.tsx
Added payload: { rephrasedQuestion: string } prop and merged it into onSubmit call payload
Answer Result Component
wren-ui/src/components/pages/home/promptThread/AnswerResult.tsx
Added isOpeningQuestion prop, computed rephrasedQuestion and questionForSaveAsView logic, and passed rephrasedQuestion to modal handlers
Thread Container
wren-ui/src/components/pages/home/promptThread/index.tsx
Passed isOpeningQuestion={index === 0} prop to AnswerResult component
Prompt Thread Store
wren-ui/src/components/pages/home/promptThread/store.tsx
Extended onOpenSaveAsViewModal signature to accept payload: { rephrasedQuestion: string } parameter

Sequence Diagram

sequenceDiagram
    participant AnswerResult
    participant SaveAsViewModal
    participant PromptThreadStore
    participant ModelResolver
    participant GraphQL

    AnswerResult->>AnswerResult: compute rephrasedQuestion<br/>(based on isOpeningQuestion)
    AnswerResult->>SaveAsViewModal: open with payload<br/>{rephrasedQuestion}
    SaveAsViewModal->>SaveAsViewModal: merge payload into<br/>form submission
    SaveAsViewModal->>PromptThreadStore: onSubmit({...payload, ...values})
    PromptThreadStore->>ModelResolver: mutation createView with<br/>rephrasedQuestion
    ModelResolver->>GraphQL: use rephrasedQuestion<br/>instead of response.question
    GraphQL-->>ModelResolver: view created
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • onlyjackfrost
  • wwwy3y3
  • andreashimin

Poem

🐰 A question rephrased, through layers it flows,
From Answer to Modal, the data now glows,
The view is now wiser, it captures intent,
No longer the first ask, but better—well-meant! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "feat(wren-ui): Enhance save as view for follow-up questions" directly aligns with the main changes in the changeset. The pull request core objective is to modify how query results are saved as Views for follow-up questions by using AI-rephrased questions instead of raw follow-up text. The title accurately captures this enhancement across the GraphQL schema, resolvers, and frontend components. The title is concise, avoids vague language, and would clearly communicate the primary change to a developer reviewing the commit history.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/create-view

📜 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 43166d9 and 090baa7.

📒 Files selected for processing (7)
  • wren-ui/src/apollo/client/graphql/__types__.ts (1 hunks)
  • wren-ui/src/apollo/server/resolvers/modelResolver.ts (2 hunks)
  • wren-ui/src/apollo/server/schema.ts (1 hunks)
  • wren-ui/src/components/modals/SaveAsViewModal.tsx (2 hunks)
  • wren-ui/src/components/pages/home/promptThread/AnswerResult.tsx (5 hunks)
  • wren-ui/src/components/pages/home/promptThread/index.tsx (1 hunks)
  • wren-ui/src/components/pages/home/promptThread/store.tsx (1 hunks)
🔇 Additional comments (11)
wren-ui/src/apollo/client/graphql/__types__.ts (1)

244-248: Type definition correctly reflects the schema change.

The addition of rephrasedQuestion to CreateViewInput aligns with the GraphQL schema update. Since this appears to be an auto-generated file, ensure it's regenerated from the schema after any future schema changes.

wren-ui/src/apollo/server/resolvers/modelResolver.ts (2)

805-805: Clean destructuring of the new field.

The addition of rephrasedQuestion to the destructuring pattern is straightforward and aligns with the schema change.


839-846: ****

The concern about validation is unfounded. The data flow guarantees rephrasedQuestion is always available:

  1. GraphQL validation — Schema defines rephrasedQuestion: String! (required input)
  2. Component prop requirement — SaveAsViewModal requires payload: { rephrasedQuestion: string } (non-optional)
  3. Safe data derivationquestionForSaveAsView always returns a value: either the original question (if opening question) or rephrasedQuestion with fallback to question

The resolver safely receives rephrasedQuestion through multiple redundant safety layers. No additional validation or defensive coding is needed.

Likely an incorrect or invalid review comment.

wren-ui/src/apollo/server/schema.ts (1)

436-440: Schema change correctly defines the new required field.

The addition of rephrasedQuestion: String! to CreateViewInput is clean and correctly marks it as required. This provides type safety at the GraphQL layer.

wren-ui/src/components/pages/home/promptThread/index.tsx (1)

58-64: Correctly identifies opening questions.

The logic isOpeningQuestion={index === 0} cleanly identifies the first question in a thread. This enables downstream components to handle opening vs. follow-up questions differently.

wren-ui/src/components/pages/home/promptThread/store.tsx (1)

24-27: Clean API extension for the store interface.

The addition of the payload parameter with rephrasedQuestion maintains good separation between core data and metadata. The type signature is clear and type-safe.

wren-ui/src/components/pages/home/promptThread/AnswerResult.tsx (3)

125-125: New prop correctly added to component interface.

The isOpeningQuestion prop enables the component to distinguish between opening and follow-up questions, which is essential for this feature.


365-372: Payload structure correctly passes rephrased question.

The save as view flow now correctly passes questionForSaveAsView through the payload, enabling the backend to store the appropriate question text based on whether it's an opening or follow-up question.


274-283: Clarify the intentional behavior difference between Save as View and Save to Knowledge for opening questions.

The inconsistency identified in the review comment is confirmed:

  • Save as View (line 369): Uses questionForSaveAsView, which respects the isOpeningQuestion flag and returns the original question for opening questions
  • Save to Knowledge (line 349): Uses rephrasedQuestion directly, without checking isOpeningQuestion

For opening questions that have a stored rephrasedQuestion, these operations handle them differently. No tests or comments explain whether this design choice is intentional.

For opening questions without a stored rephrasedQuestion, both operations are functionally consistent due to the fallback logic on line 275.

Verify whether the behavior difference is intentional design (perhaps because Save to Knowledge benefits from using the question variant used during answer generation) or an oversight that should be aligned with Save as View's logic.

wren-ui/src/components/modals/SaveAsViewModal.tsx (2)

10-14: Props type correctly extended with payload.

The addition of payload: { rephrasedQuestion: string } cleanly extends the modal's interface to support the new field.


27-31: Payload correctly merged into submission.

The spread operator usage { responseId: defaultValue.responseId, ...payload, ...values } cleanly merges all necessary data for the GraphQL mutation. The order ensures that form values can override payload if needed, though in practice rephrasedQuestion should only come from payload.


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.

@fredalai fredalai changed the title fix(wren-ui): feat(wren-ui): Enhance save as view Oct 21, 2025
@fredalai fredalai changed the title feat(wren-ui): Enhance save as view feat(wren-ui): Enhance save as view for follow-up questions Oct 21, 2025
@fredalai fredalai marked this pull request as ready for review October 21, 2025 03:05
@fredalai fredalai merged commit 19374da into main Oct 27, 2025
7 checks passed
@fredalai fredalai deleted the fix/create-view branch October 27, 2025 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants