Skip to content

chore(wren-ui): extend ask history to 10#1381

Merged
fredalai merged 2 commits into
mainfrom
chore/ask-history
Mar 13, 2025
Merged

chore(wren-ui): extend ask history to 10#1381
fredalai merged 2 commits into
mainfrom
chore/ask-history

Conversation

@onlyjackfrost
Copy link
Copy Markdown
Contributor

@onlyjackfrost onlyjackfrost commented Mar 10, 2025

Description

extend ask history to 10
ref PR: #1377

Summary by CodeRabbit

  • New Features

    • Enhanced conversation history processing now supports multiple interactions, delivering improved AI response context.
    • Introduced a new method to retrieve a list of historical responses, expanding the context available for AI interactions.
  • Refactor

    • Streamlined data transformation and historical input handling to simplify processing and enhance reliability.
    • Updated data structures to focus on single questions rather than collections of steps.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 10, 2025

Walkthrough

The changes update the handling of historical thread responses across several modules. The adaptor now transforms an array of thread responses instead of a single history, and model interfaces are updated accordingly—removing the steps array in favor of a question string and renaming a property from singular to plural. In the service layer, a method that previously returned one history is replaced by one that retrieves up to 10 responses. These modifications shift the architecture from handling a single historical context to working with multiple thread responses.

Changes

File(s) Change Summary
wren-ui/src/apollo/server/adaptors/.../wrenAIAdaptor.ts
wren-ui/src/apollo/server/models/adaptor.ts
- Updated method signature in WrenAIAdaptor: transformHistoryInput now accepts ThreadResponse[] and returns an array of transformed objects containing sql and question.
- Modified interfaces: In AskHistory, replaced steps: AskStep[] with question: string; renamed and changed type of history in AskInput to histories?: ThreadResponse[].
wren-ui/src/apollo/server/services/askingService.ts - Removed the method getHistory that returned a single AskHistory.
- Added getAskingHistory to retrieve up to 10 ThreadResponse objects.
- Updated usage in createAskingTask to pass histories to the AI adaptor.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant S as AskingService
    participant DB as History Store
    participant A as WrenAIAdaptor

    C->>S: Submit asking task (with threadId)
    S->>DB: getAskingHistory(threadId)
    DB-->>S: Return array of ThreadResponse objects
    S->>A: Call ask(histories)
    A->>A: transformHistoryInput(histories)
    A-->>S: Return transformed AskHistory[]
    S-->>C: Return AI response
Loading

Suggested reviewers

  • wwwy3y3

Poem

I'm just a hopping rabbit in a code-filled glen,
Transforming single tales into arrays now and then.
Each thread response is a carrot crunchy and bright,
Guiding our code through the digital night.
With hops and winks, I cheer this change today—
A playful leap in code, in a whimsical way!

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 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 24e75ee and c7d56a5.

📒 Files selected for processing (3)
  • wren-ui/src/apollo/server/adaptors/wrenAIAdaptor.ts (3 hunks)
  • wren-ui/src/apollo/server/models/adaptor.ts (3 hunks)
  • wren-ui/src/apollo/server/services/askingService.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • wren-ui/src/apollo/server/services/askingService.ts
  • wren-ui/src/apollo/server/models/adaptor.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
🔇 Additional comments (3)
wren-ui/src/apollo/server/adaptors/wrenAIAdaptor.ts (3)

34-34: New import added to support multiple thread responses.

The import of ThreadResponse from '@server/repositories' is necessary to support the updated signature of the transformHistoryInput method, which now processes an array of thread responses instead of a single history object.


192-192: Updated method call to use plural 'histories'.

This change correctly reflects the shift from a single history item to multiple history items, maintaining consistency with the interface changes in the AskInput type.


733-743: Method refactored to handle multiple history items.

The transformHistoryInput method has been updated to:

  1. Accept an array of ThreadResponse objects instead of a single AskHistory
  2. Return an array of AskHistory objects
  3. Map each thread response to extract only sql and question properties
  4. Handle null/undefined input by returning an empty array

This change aligns with the PR objective of extending ask history to 10 entries and follows good practices for null handling and type safety.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
wren-ui/src/apollo/server/services/askingService.ts (2)

938-943: Consider adding null/undefined check for threadId parameter

The method doesn't validate the threadId parameter. Consider adding a check to handle edge cases.

  private async getAskingHistory(threadId: number): Promise<ThreadResponse[]> {
+    if (!threadId) {
+      return [];
+    }
    return await this.threadResponseRepository.getResponsesWithThread(
      threadId,
      10,
    );
  }

938-943: Consider adding documentation about response ordering

The implementation assumes that getResponsesWithThread returns responses in the desired order, but this isn't explicit. Consider adding a comment to clarify the expected order (e.g., most recent first).

  private async getAskingHistory(threadId: number): Promise<ThreadResponse[]> {
+    // Retrieves up to 10 most recent thread responses, ordered by creation time (newest first)
    return await this.threadResponseRepository.getResponsesWithThread(
      threadId,
      10,
    );
  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3f0f7a6 and c09a0bd.

📒 Files selected for processing (3)
  • wren-ui/src/apollo/server/adaptors/wrenAIAdaptor.ts (3 hunks)
  • wren-ui/src/apollo/server/models/adaptor.ts (3 hunks)
  • wren-ui/src/apollo/server/services/askingService.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
🔇 Additional comments (8)
wren-ui/src/apollo/server/models/adaptor.ts (3)

3-3: Added import for ThreadResponse is correctly used in updated interfaces

This import is necessary to support the interface changes that follow, specifically for the updated AskInput interface that now accepts an array of ThreadResponse objects.


52-54: Interface simplification: steps array replaced with question string

The AskHistory interface has been simplified by replacing the complex steps array with a single question string. This change supports the architectural shift from handling a single detailed history to working with multiple thread responses.


61-65: Renamed history to histories to support multiple thread responses

The property has been renamed from singular to plural and its type changed from a single AskHistory to an array of ThreadResponse objects, aligning with the PR objective to extend ask history to 10.

wren-ui/src/apollo/server/adaptors/wrenAIAdaptor.ts (3)

28-28: Added import for ThreadResponse to support updated method signature

The ThreadResponse import is necessary for the updated transformHistoryInput method signature.


105-112: Updated input parameter name to reflect interface change

The code correctly references the renamed histories property instead of history, ensuring compatibility with the updated AskInput interface.


604-614: Refactored method to handle multiple thread responses

The method has been updated to:

  1. Take an array of ThreadResponse objects instead of a single AskHistory
  2. Handle null/undefined input by returning an empty array
  3. Map each ThreadResponse to include just sql and question properties

This implementation correctly supports the PR objective of extending ask history to 10 entries.

wren-ui/src/apollo/server/services/askingService.ts (2)

525-541: Updated to use multiple histories instead of a single history

The method now correctly uses the new getAskingHistory method that returns multiple thread responses, and passes them to the wrenAIAdaptor.ask method as histories instead of a single history.


938-943: Implemented retrieval of multiple thread responses

The method has been completely rewritten to return an array of up to 10 most recent ThreadResponse objects for a given thread, rather than just the most recent one. This implements the core functionality required by the PR objective.

Comment thread wren-ui/src/apollo/server/services/askingService.ts
Comment on lines +937 to 939
if (!threadId) {
return [];
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why this judgment is needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will throw a knex error if threadId is undefined. just a defensive check.

@onlyjackfrost onlyjackfrost requested a review from fredalai March 13, 2025 02:23
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