feat(ai): add dashboard tools for AI chat#16517
Conversation
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
There was a problem hiding this comment.
3 issues found across 18 files
Prompt for AI agents (all 3 issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="packages/twenty-server/src/modules/dashboard/tools/schemas/widget.schema.ts">
<violation number="1" location="packages/twenty-server/src/modules/dashboard/tools/schemas/widget.schema.ts:50">
P1: `z.discriminatedUnion` requires a single literal value per member schema for the discriminator field. Using `z.enum` with multiple values (`VERTICAL_BAR`, `HORIZONTAL_BAR`) here will cause Zod to fail. Consider splitting this into two separate schemas or using `z.union` instead of `z.discriminatedUnion`.</violation>
</file>
<file name="packages/twenty-server/src/modules/dashboard/tools/update-dashboard-widget.tool.ts">
<violation number="1" location="packages/twenty-server/src/modules/dashboard/tools/update-dashboard-widget.tool.ts:80">
P2: Unsafe access to `error.message` without type checking. If a non-Error object is thrown, this will result in `undefined`. Consider using a type guard.</violation>
</file>
<file name="packages/twenty-server/src/engine/core-modules/skills/skills/dashboard-building.skill.ts">
<violation number="1" location="packages/twenty-server/src/engine/core-modules/skills/skills/dashboard-building.skill.ts:38">
P2: PIE chart documentation is incomplete and inconsistent with other chart types. Missing required fields: `objectMetadataId`, `aggregateFieldMetadataId`, and `aggregateOperation`. The actual Zod schema in `widget.schema.ts` requires all these fields, so AI-generated configurations will fail validation.</violation>
</file>
Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR
|
|
||
| // Graph configuration schema for BAR charts | ||
| const barChartConfigSchema = z.object({ | ||
| graphType: z.enum([GraphType.VERTICAL_BAR, GraphType.HORIZONTAL_BAR]), |
There was a problem hiding this comment.
P1: z.discriminatedUnion requires a single literal value per member schema for the discriminator field. Using z.enum with multiple values (VERTICAL_BAR, HORIZONTAL_BAR) here will cause Zod to fail. Consider splitting this into two separate schemas or using z.union instead of z.discriminatedUnion.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/twenty-server/src/modules/dashboard/tools/schemas/widget.schema.ts, line 50:
<comment>`z.discriminatedUnion` requires a single literal value per member schema for the discriminator field. Using `z.enum` with multiple values (`VERTICAL_BAR`, `HORIZONTAL_BAR`) here will cause Zod to fail. Consider splitting this into two separate schemas or using `z.union` instead of `z.discriminatedUnion`.</comment>
<file context>
@@ -0,0 +1,119 @@
+
+// Graph configuration schema for BAR charts
+const barChartConfigSchema = z.object({
+ graphType: z.enum([GraphType.VERTICAL_BAR, GraphType.HORIZONTAL_BAR]),
+ aggregateFieldMetadataId: z
+ .string()
</file context>
| } catch (error) { | ||
| return { | ||
| success: false, | ||
| message: `Failed to update widget: ${error.message}`, |
There was a problem hiding this comment.
P2: Unsafe access to error.message without type checking. If a non-Error object is thrown, this will result in undefined. Consider using a type guard.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/twenty-server/src/modules/dashboard/tools/update-dashboard-widget.tool.ts, line 80:
<comment>Unsafe access to `error.message` without type checking. If a non-Error object is thrown, this will result in `undefined`. Consider using a type guard.</comment>
<file context>
@@ -0,0 +1,85 @@
+ } catch (error) {
+ return {
+ success: false,
+ message: `Failed to update widget: ${error.message}`,
+ error: error.message,
+ };
</file context>
| ### GRAPH - PIE Charts | ||
| Required: | ||
| - configuration.graphType: "PIE" | ||
| - configuration.groupByFieldMetadataId: field to slice by |
There was a problem hiding this comment.
P2: PIE chart documentation is incomplete and inconsistent with other chart types. Missing required fields: objectMetadataId, aggregateFieldMetadataId, and aggregateOperation. The actual Zod schema in widget.schema.ts requires all these fields, so AI-generated configurations will fail validation.
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/skills/skills/dashboard-building.skill.ts, line 38:
<comment>PIE chart documentation is incomplete and inconsistent with other chart types. Missing required fields: `objectMetadataId`, `aggregateFieldMetadataId`, and `aggregateOperation`. The actual Zod schema in `widget.schema.ts` requires all these fields, so AI-generated configurations will fail validation.</comment>
<file context>
@@ -8,59 +8,67 @@ export const DASHBOARD_BUILDING_SKILL: SkillDefinition = {
+- configuration.aggregateOperation: aggregation type
+- configuration.primaryAxisGroupByFieldMetadataId: field to group by (x-axis)
+
+### GRAPH - PIE Charts
+Required:
+- configuration.graphType: "PIE"
</file context>
| ### GRAPH - PIE Charts | |
| Required: | |
| - configuration.graphType: "PIE" | |
| - configuration.groupByFieldMetadataId: field to slice by | |
| ### GRAPH - PIE Charts | |
| Shows data distribution by category. | |
| Required: | |
| - objectMetadataId: UUID of the object | |
| - configuration.graphType: "PIE" | |
| - configuration.aggregateFieldMetadataId: field to aggregate | |
| - configuration.aggregateOperation: aggregation type | |
| - configuration.groupByFieldMetadataId: field to slice by |
|
🚀 Preview Environment Ready! Your preview environment is available at: http://bore.pub:25988 This environment will automatically shut down when the PR is closed or after 5 hours. |
Implements real tools for the dashboard-building skill to create and manage dashboards through the AI chat interface. New tools: - create_complete_dashboard: Create dashboard with layout, tab, and widgets - list_dashboards: List all dashboards in workspace - get_dashboard: Get full dashboard details including tabs and widgets - add_dashboard_widget: Add widget to existing dashboard tab - update_dashboard_widget: Update widget properties or configuration - delete_dashboard_widget: Remove widget from dashboard Key improvements: - Typed Zod schemas for widget configuration validation - Discriminated union for graph types (AGGREGATE, BAR, LINE, PIE) - Widget-level error handling for partial success - Updated skill documentation with field metadata lookup workflow - Proper guidance for AI to use list_object_metadata_items first
f725339 to
3b246fc
Compare
|
Hey @FelixMalfait! After you've done the QA of your Pull Request, you can mark it as done here. Thank you! |
Summary
create_complete_dashboard,list_dashboards,get_dashboard,add_dashboard_widget,update_dashboard_widget,delete_dashboard_widgetKey Changes
New Dashboard Tools:
create_complete_dashboard- Creates a dashboard with layout, tab, and widgets in a single calllist_dashboards- Lists all dashboards in the workspaceget_dashboard- Gets full dashboard details including tabs and widget configurationsadd_dashboard_widget- Adds a widget to an existing dashboard tabupdate_dashboard_widget- Updates widget properties or configurationdelete_dashboard_widget- Removes a widget from a dashboardWidget Configuration Improvements:
graphTypeobjectMetadataIdand field UUIDsSkill Documentation Updates:
dashboard-building.skill.tswith critical guidance about looking up field metadata firstlist_object_metadata_itemsbefore creating GRAPH widgetsTest plan