Skip to content

Conversation

@FelixMalfait
Copy link
Member

Summary

  • Add BrowsingContext type to automatically pass what the user is currently viewing (recordPage or listView) to the AI chat
  • Simplify context architecture: remove toggleable context UI, make it automatic and invisible to the user
  • Fix tool loading: add unionOf handling in getDatabaseToolsForObject and fix regex ordering so find_one_* tools are properly registered
  • Use plural names for find tools (find_people vs find_one_person) for better semantics
  • Clean up unused components and states

Changes

Frontend

  • New BrowsingContext type and useGetBrowsingContext hook to gather context from Recoil state
  • Simplified useAgentChat to use the new browsing context
  • Removed toggleable context UI components (AgentChatContextRecordPreview, SendMessageWithRecordsContextButton, etc.)
  • Removed isAgentChatCurrentContextActiveState

Backend

  • New BrowsingContextType for recordPage and listView contexts
  • Updated ChatExecutionService to build context from browsing context
  • Fixed tool-registry.service.ts:
    • Added unionOf handling in permission config
    • Fixed regex ordering (find_one before find) so tools load correctly
    • Use plural names for search tools (find_people instead of find_person)

Test plan

  • Typecheck passes
  • Lint passes
  • Test AI chat on record page - should show context in system prompt
  • Test AI chat on list view - should show view name and filters
  • Test find_one_* tools now load correctly
  • Test find_* tools use plural naming

- Add BrowsingContext type to pass what the user is currently viewing
  (recordPage or listView) to the AI chat
- Simplify context architecture: remove toggleable context UI, make it
  automatic and invisible to the user
- Fix tool loading: add unionOf handling and fix regex ordering so
  find_one_* tools are properly registered
- Use plural names for find tools (find_people vs find_one_person)
- Clean up unused components and states
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

Copy link

@cubic-dev-ai cubic-dev-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.

1 issue found across 20 files

Prompt for AI agents (all 1 issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="packages/twenty-server/src/engine/core-modules/tool-provider/services/tool-registry.service.ts">

<violation number="1" location="packages/twenty-server/src/engine/core-modules/tool-provider/services/tool-registry.service.ts:515">
P1: The `unionOf` handling silently ignores all roles except the first one. Other parts of the codebase (workspace-entity-manager.ts, per-object-tool-generator.service.ts) explicitly check if `unionOf.length === 1` and throw an error for multiple roles. This code should do the same to avoid silently incorrect permission behavior.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

Comment on lines 515 to 516
// For unionOf with single role, just use that role's permissions
objectPermissions = allRolePermissions[0];
Copy link

@cubic-dev-ai cubic-dev-ai bot Dec 10, 2025

Choose a reason for hiding this comment

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

P1: The unionOf handling silently ignores all roles except the first one. Other parts of the codebase (workspace-entity-manager.ts, per-object-tool-generator.service.ts) explicitly check if unionOf.length === 1 and throw an error for multiple roles. This code should do the same to avoid silently incorrect permission behavior.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/twenty-server/src/engine/core-modules/tool-provider/services/tool-registry.service.ts, line 515:

<comment>The `unionOf` handling silently ignores all roles except the first one. Other parts of the codebase (workspace-entity-manager.ts, per-object-tool-generator.service.ts) explicitly check if `unionOf.length === 1` and throw an error for multiple roles. This code should do the same to avoid silently incorrect permission behavior.</comment>

<file context>
@@ -505,6 +507,13 @@ export class ToolRegistryService {
+        (roleId: string) =&gt; rolesPermissions[roleId],
+      );
+
+      // For unionOf with single role, just use that role&#39;s permissions
+      objectPermissions = allRolePermissions[0];
     } else {
</file context>
Suggested change
// For unionOf with single role, just use that role's permissions
objectPermissions = allRolePermissions[0];
// For unionOf with single role, just use that role's permissions
if (allRolePermissions.length === 1) {
objectPermissions = allRolePermissions[0];
} else {
throw new Error(
'Union permission logic for multiple roles not yet implemented',
);
}

✅ Addressed in 8f0df54

@github-actions
Copy link
Contributor

github-actions bot commented Dec 10, 2025

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:52824

This environment will automatically shut down when the PR is closed or after 5 hours.

FelixMalfait and others added 5 commits December 10, 2025 18:51
…ata tools

- Introduce ToolProvider interface for consistent tool category handling
- Create ActionToolProvider, DatabaseToolProvider, MetadataToolProvider, WorkflowToolProvider
- Simplify ToolRegistryService from 702 to 185 lines using provider pattern
- Register metadata tools (object/field CRUD) in AI chat
- Rename search_articles to search_help_center for clarity
NestJS dependency injection requires regular imports (not 'import type')
for injectable services. Using 'import type' causes the class reference
to be unavailable at runtime, resulting in 'undefined' being injected.
@FelixMalfait FelixMalfait merged commit bc57b8e into main Dec 11, 2025
68 checks passed
@FelixMalfait FelixMalfait deleted the feat/browsing-context-for-ai-chat branch December 11, 2025 09:19
@twenty-eng-sync
Copy link

Hey @FelixMalfait! After you've done the QA of your Pull Request, you can mark it as done here. Thank you!

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