Skip to content

Merge dev into main: SDK, API docs, chat API, storage RPCs, and tests#58

Merged
suggestied merged 59 commits intomainfrom
dev
Mar 12, 2026
Merged

Merge dev into main: SDK, API docs, chat API, storage RPCs, and tests#58
suggestied merged 59 commits intomainfrom
dev

Conversation

@suggestied
Copy link
Contributor

@suggestied suggestied commented Mar 12, 2026

Summary

Merges dev into main with the following changes. Please do not delete the dev branch when merging (uncheck "Delete branch" after merge if shown).


What's included

API & documentation

  • Revised API documentation: clearer section titles, navigation, and resource structure
  • New/updated docs: Analytics reporting, Labor, Maintenance & meters, Catalogs, Inventory & plugins
  • Tenant context, authentication, installation, and SDK usage guidance
  • Safety & compliance, parts/inventory, asset lifecycle, location hierarchy (region/site/building/floor/room/zone), scheduling, mobile fields

SDK & database

  • Labor management, scheduling (schedule blocks, work order scheduling), mobile field resource with offline sync
  • Location bulk import, lifecycle fields (commissioned, warranty, replacement), optional project IDs for cost roll-up
  • Work order attachment RPC: validation for ownership and path structure (tenant/work order IDs)
  • Mobile sync RPC: stability/volatile and error-handling improvements
  • Storage insert definer checks and auth/tenant path handling

Chat API & UI

  • Chat API with auth, tool integration, dashboard metrics, semantic search for similar past work orders
  • Work order listing filters (priority, status), picker tools for work orders/assets, tool output rendering improvements
  • Tenant context handling in DB client (session refresh for tenant_id in JWT)
  • CMMSChat: charts, asset tracking, cause/resolution form, entity audit timeline

Tests & tooling

  • Shared user/tenant helpers (getOrCreateSharedUser, getOrCreateSharedTenant) to reduce auth connections
  • New/updated tests: asset lifecycle, reporting schema, space management, purchasing (unique order numbers), work order creation, RPC validation
  • test:reset script and CONTRIBUTING updates for test execution and auth errors

Other

  • Prompt kit and UI library form refactors (login, signup, forgot/reset password)
  • CauseResolutionForm, Entity Audit Timeline, and related UI components

Checklist

  • dev is up to date with origin/dev
  • Keep dev branch — do not delete it after merge

Made with Cursor


Note

High Risk
High risk because it introduces new authenticated API routes that accept user tokens and can trigger state-changing operations (work orders/assets) after confirmation, plus significant new surface area in a new app and docs.

Overview
Introduces a new apps/chat Next.js app, including Supabase-backed auth pages and a streaming /api/chat endpoint that uses AI SDK tools to read tenant data and propose write actions that require explicit user confirmation via /api/chat/execute.

Adds chat tool definitions (list/search/dashboard metrics, pickers, and confirmed mutations) plus UI rendering for tool outputs (grids, cards, charts, pickers) and tenant/session handling for tool execution.

Updates repo hygiene and docs: ignores storybook-static, removes an obsolete Cursor plan, improves contributor/test reset guidance, and significantly expands/reorganizes the docs site with new pages (analytics, costs/lifecycle, labor, scheduling, mobile field, parts/inventory, safety/compliance, spaces) and revamped navigation and copy.

Written by Cursor Bugbot for commit abca814. This will update automatically on new commits. Configure here.

…th meter management features. Added meter creation and reading functionalities, improved data fetching for meters and readings, and integrated sparkline visualizations for asset trends.
…mponents for improved UI consistency and structure.
…ents with Empty and Item components for improved user experience and visual consistency.
…data display, including status and priority catalogs for improved change tracking.
- Introduced `requireResolution` prop to enforce resolution input before submission.
- Added `isSubmitting` prop to show loading state on the submit button.
- Enhanced form accessibility with aria attributes and validation messages.
- Updated storybook stories to demonstrate new features and states.
…sted prompts for improved user interaction. Updated descriptions to reflect multiple use cases and added new user prompts for better guidance.
…ser interaction. Added typewriter effect for welcome and assistant replies, updated conversation flow descriptions, and improved layout for better visual feedback during interactions.
…factor conversation flow descriptions for clarity and remove unused streaming features for a more streamlined user experience.
…t rendering and improve type handling in MarkdownComponent. Simplified rendering logic by removing unnecessary wrapper and enhanced string conversion for better compatibility.
…uding a bar chart visualization of work order distribution. Enhanced user guidance with hints for further actions.
…ding Next.js, React, and TypeScript, along with various development tools like ESLint and Tailwind CSS.
…UI library forms. Updated routes for login, signup, forgot password, and reset password to replace existing card-based layouts with dedicated form components from the workspace UI library. Added workspace SDK dependencies to chat application and adjusted CSS imports for compatibility with Next.js.
… Added new AI SDK dependencies and integrated ChatClient component for improved chat functionality. Updated package.json and pnpm-lock.yaml to reflect these changes.
…ants for maximum messages and output tokens to optimize performance and cost. Added a system prompt to guide concise responses, ensuring user interactions remain focused and actionable.
…efresh logic to ensure JWT includes tenant_id from user metadata, preventing null tenant_id issues in subsequent SDK requests.
…put rendering. Added a new tool for retrieving dashboard metrics as chart data, including work orders by status and priority. Updated chat-client and CMMSChat components to support custom rendering of tool outputs, improving user experience and data visualization.
…ew tool for searching similar completed work orders based on user queries, enhancing the assistant's ability to provide relevant historical context. Updated system prompts and chat-client to support this feature, improving user interaction and response accuracy.
…justed the order to prioritize title, description, status, cause, and resolution, ensuring a more logical presentation of important fields.
…ation. Reduced maximum messages and output tokens for efficiency. Introduced new functions to summarize tool results and prune unnecessary data, enhancing user experience. Updated CSV handling in tool outputs for better integration with chat components.
…ncy. Updated system prompts to streamline user interactions and revised tool parameters to emphasize required fields while minimizing unnecessary queries. Implemented a guard in the chat client to prevent duplicate executions of tool calls, enhancing user experience and reliability.
…reation. Updated the system prompt to improve clarity and conciseness in user interactions. Modified the chat client to display newly created work orders with a dedicated card component, ensuring better presentation of work order details. Enhanced tool output handling to include work order data in responses, improving user experience.
…ced optional priority and status filters for work order listings, improving user query handling. Updated dashboard tools to exclude draft work orders by default, streamlining data presentation. Revised tool descriptions for clarity and added new methods to support draft inclusion when necessary.
…Changed development port in package.json for consistency. Introduced new picker tools for selecting work orders and assets, improving user interaction. Enhanced tool output rendering to support picker functionality, allowing users to confirm actions on selected items. Updated error handling in execute route for better user feedback on work order status transitions.
…ase types and RPCs for managing schedule blocks and work orders. Updated navigation to include scheduling section.
…nd SDK. Updated location types to include region, site, building, floor, room, and zone. Enhanced location creation and update parameters with optional fields for code, address line, and external ID. Introduced new bulk import functionality for locations and added navigation for spaces. Updated database types and SDK to accommodate new space management features.
…troduced new sections for asset lifecycle management, including fields for commissioned dates, warranty, and replacement planning. Updated work order parameters to include optional project IDs for cost roll-up. Enhanced navigation and README to reflect these changes, improving clarity on asset and cost management features.
… Introduced new resource for parts inventory, updated navigation to include a new section for parts and inventory, and expanded type exports to support inventory-related operations. This enhances the overall asset management capabilities within the application.
…ed a new section in the API documentation, updated navigation to include safety and compliance, and expanded type exports to support inspection and incident management. This enhances the application's capabilities for regulatory compliance and safety management.
…oduced a new resource for analytics reporting, detailing schema and KPIs, and updated navigation to include the new section. This enhances the application's reporting capabilities and user access to analytics features.
…UTING.md to clarify test execution steps and added instructions for handling auth errors. Introduced a new `test:reset` script in package.json for easier test setup. Expanded test coverage with new cases for asset lifecycle, reporting schema, and space management, ensuring better validation of features and tenant isolation.
…mobile field resource with offline sync capabilities, updated API documentation to reflect mobile functionalities, and enhanced work order parameters to support GPS logging. Updated navigation and resource types to improve access to mobile features.
…ng and work order creation. Adjusted function stability in SQL migration and improved test cases to validate RPC responses and work order parameters.
…anced test cases for work order creation and RPC response validation, ensuring robust functionality during SQL migration.
…OrCreateSharedUser` and `getOrCreateSharedTenant` functions to optimize user and tenant creation, reducing authentication connections. Updated test cases to utilize these functions for improved efficiency and consistency across test suites.
…dation. Introduced checks for work order ownership and attachment path structure to ensure compliance with tenant and work order IDs. Updated function documentation to reflect new permission requirements and validation rules.
…ty. Updated section titles and reorganized links into new categories, enhancing clarity for users. Added new links for 'Catalogs' and 'Inventory & plugins', while consolidating related resources under appropriate headings.
…ion for clarity and added new resource categories in the documentation, including 'Labor' and 'Maintenance & meters'. Adjusted schemas in Supabase configuration for better API organization. Enhanced test cases for purchasing functionality to ensure unique order numbers and improved validation.
…n titles and descriptions across multiple pages, including API, analytics, authentication, installation, and tenant context. Enhanced user guidance on SDK usage and tenant management. Improved navigation structure for better accessibility to resources. Added next steps sections to guide users through related topics.
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Bugbot Free Tier Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.


React.useEffect(() => {
console.log("[chat] messages", messages)
}, [messages])
Copy link

Choose a reason for hiding this comment

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

Debug console.log left in production chat component

Medium Severity

Two console.log statements appear to be debug code left in the production ChatClient component. The useEffect on line 381 logs the entire messages array on every update — during streaming this fires on every token, flooding the browser console with potentially large objects. The onFilesAdded handler on line 456 only logs files without processing them, meaning the file-upload UI silently drops all files.

Additional Locations (1)
Fix in Cursor Fix in Web

const accessToken = body.accessToken as string | undefined
const refreshToken = (body.refreshToken as string | undefined) ?? null
const tenantId = body.tenantId as string | undefined
const action = body.action as ExecuteAction | undefined
Copy link

Choose a reason for hiding this comment

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

Execute route does not validate action against allowed values

Low Severity

The action field from the request body is cast to ExecuteAction with as but never validated against the allowed action strings before being passed to executeAction. The switch in executeAction has a default branch that returns an error, so it won't crash, but the body.action type assertion gives a false sense of type safety at the API boundary — any arbitrary string is accepted without a 400 rejection upfront.

Fix in Cursor Fix in Web

params: Record<string, unknown>,
tenantId: string
): Promise<{ ok: true; data: unknown } | { ok: false; error: string }> {
await db.setTenant(tenantId)
Copy link

Choose a reason for hiding this comment

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

Redundant setTenant call in executeAction

Low Severity

executeAction calls db.setTenant(tenantId) at line 407, but getDbClientForUser in chat-db.ts already calls db.setTenant(tenantId) at line 36 and refreshes the session. The caller in the execute route creates the client via getDbClientForUser then immediately passes it to executeAction, resulting in a duplicate setTenant call that adds an unnecessary RPC round-trip on every action execution.

Additional Locations (1)
Fix in Cursor Fix in Web

@suggestied suggestied merged commit 76287df into main Mar 12, 2026
3 checks passed
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