Skip to content

Use full workspace context for root AI chats#365

Merged
appflowy merged 1 commit into
mainfrom
codex/full-workspace-ai-chat-context
May 24, 2026
Merged

Use full workspace context for root AI chats#365
appflowy merged 1 commit into
mainfrom
codex/full-workspace-ai-chat-context

Conversation

@appflowy
Copy link
Copy Markdown
Contributor

@appflowy appflowy commented May 24, 2026

Summary

  • create root/space AI chats with full_workspace enabled and an empty rag_ids list
  • keep explicit source rag_ids for non-root AI follow-up chats
  • show full-workspace chats as selecting all non-AI chat views, and disable full-workspace only when sources are manually changed

Verification

  • pnpm exec jest src/components/ai-chat/tests/chat-settings.test.ts src/components/chat/tests/ChatRequest.test.ts --no-coverage
  • pnpm exec tsc --noEmit --project tsconfig.web.json

Summary by Sourcery

Initialize AI chat pages with workspace-aware context settings and update related views selection to reflect full-workspace chats.

New Features:

  • Add support for full_workspace flag in chat settings to enable workspace-wide AI context.
  • Introduce helper utilities to derive initial AI chat settings based on parent view, query, and source IDs.

Enhancements:

  • Automatically attach appropriate AI chat settings when creating chats from search or the add-page menu, including initial prompt and context source behavior.
  • Update related-views selection UI so full-workspace chats appear as using all non-AI views and disable full-workspace when sources are manually changed.

Tests:

  • Add unit tests covering initial AI chat settings behavior for workspace-root and non-root chats.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 24, 2026

Reviewer's Guide

Implements workspace-aware initial AI chat settings so root workspace chats use full workspace context with empty rag_ids, while non-root chats preserve explicit source rag_ids, and wires these settings into chat creation and related-views selection behavior.

File-Level Changes

Change Details Files
Add utilities and tests to build initial AI chat settings based on the parent view (workspace root vs page) and optional query/source IDs.
  • Introduce isWorkspaceRootView to detect workspace root views via view.extra.is_space.
  • Add buildInitialAIChatSettings to construct initial ChatSettings including full_workspace, rag_ids, and metadata.initial_prompt.
  • Create unit tests covering workspace-root chats, page-based chats with sources, and page-based chats with initial prompts only.
src/components/ai-chat/chat-settings.ts
src/components/ai-chat/__tests__/chat-settings.test.ts
Use the new initial AI chat settings when creating AI chats from search and from the add-page UI, and persist them via ChatRequest.updateChatSettings.
  • In global search, replace inline rag_ids/metadata construction with buildInitialAIChatSettings using parent, query, and sourceIds.
  • In AddPageActions, after creating an AIChat view, compute initialSettings via buildInitialAIChatSettings({ parent: view }) and send them with ChatRequest.updateChatSettings if non-empty.
  • Improve toast handling by tracking and dismissing a specific loadingToastId and showing an error toast when chat settings attachment fails.
  • Update ChatSettings type to include optional full_workspace flag.
src/components/app/search/Search.tsx
src/components/app/view-actions/AddPageActions.tsx
src/components/chat/types/request.ts
Adjust related views selector to reflect full-workspace chats as selecting all non-AI views and to disable full-workspace when the user manually changes sources.
  • Add collectSelectableViewIds helper to traverse the view tree and collect IDs of non-AIChat views.
  • When chatSettings.full_workspace is true, derive selected viewIds from the full workspace tree instead of rag_ids; otherwise keep using rag_ids.
  • On manual related-view toggles, update chat settings with the new rag_ids and explicitly set full_workspace to false.
  • Minor UI/formatting tweaks in RelatedViews (CSS classes, arrow icon dimension order, consistent arrow function spacing).
src/components/chat/components/chat-input/related-views/index.tsx

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • In collectSelectableViewIds, consider guarding against view.children being undefined (e.g. stack.push(...(view.children ?? []))) to avoid potential runtime errors if a view has no children array.
  • The handleAddPage callback now calls toast.dismiss(loadingToastId) in both the try and catch branches; refactoring to a finally block (or a helper) would avoid duplicating this cleanup logic.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `collectSelectableViewIds`, consider guarding against `view.children` being undefined (e.g. `stack.push(...(view.children ?? []))`) to avoid potential runtime errors if a view has no children array.
- The `handleAddPage` callback now calls `toast.dismiss(loadingToastId)` in both the try and catch branches; refactoring to a `finally` block (or a helper) would avoid duplicating this cleanup logic.

## Individual Comments

### Comment 1
<location path="src/components/chat/components/chat-input/related-views/index.tsx" line_range="31" />
<code_context>
+    if (!view || view.layout === ViewLayout.AIChat) continue;
+
+    ids.push(view.view_id);
+    stack.push(...view.children);
+  }
+
</code_context>
<issue_to_address>
**issue:** Guard against `view.children` being undefined when pushing onto the stack.

Elsewhere in this file `children` is treated as optional (e.g. `folder?.children || []`), but `stack.push(...view.children)` will throw if `children` is undefined. Use a safe fallback, e.g. `stack.push(...(view.children || []));`, so the traversal doesn’t break when `children` is missing.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

if (!view || view.layout === ViewLayout.AIChat) continue;

ids.push(view.view_id);
stack.push(...view.children);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue: Guard against view.children being undefined when pushing onto the stack.

Elsewhere in this file children is treated as optional (e.g. folder?.children || []), but stack.push(...view.children) will throw if children is undefined. Use a safe fallback, e.g. stack.push(...(view.children || []));, so the traversal doesn’t break when children is missing.

@appflowy appflowy force-pushed the codex/full-workspace-ai-chat-context branch from 8df587c to cd42f17 Compare May 24, 2026 09:10
@appflowy appflowy force-pushed the codex/full-workspace-ai-chat-context branch from cd42f17 to 941ffe6 Compare May 24, 2026 09:36
@appflowy appflowy merged commit 5c0b44b into main May 24, 2026
13 checks passed
@appflowy appflowy deleted the codex/full-workspace-ai-chat-context branch May 24, 2026 12:17
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.

1 participant