Skip to content

refactor: Migrate livechat/users endpoints to OpenAPI with AJV validation#39584

Open
amitb0ra wants to merge 5 commits intoRocketChat:developfrom
amitb0ra:refactor/migrate-livechat-users-openapi
Open

refactor: Migrate livechat/users endpoints to OpenAPI with AJV validation#39584
amitb0ra wants to merge 5 commits intoRocketChat:developfrom
amitb0ra:refactor/migrate-livechat-users-openapi

Conversation

@amitb0ra
Copy link
Copy Markdown
Contributor

@amitb0ra amitb0ra commented Mar 12, 2026

Proposed changes

Migrates the livechat/users/:type and livechat/users/:type/:_id endpoints from the legacy addRoute() pattern to the new OpenAPI-compatible chained route pattern with inline AJV validation schemas.

Resolves: RocketChat/Rocket.Chat-Open-API#150

Changes

apps/meteor/app/livechat/imports/server/rest/users.ts

  • Replaced legacy API.v1.addRoute() calls with the new chained API.v1.get().post().get().delete() pattern
  • Added inline AJV validation schemas for query params, request body, and responses (200/400/401/403)
  • Used ExtractRoutesFromAPI + declare module augmentation for type extraction
  • All 4 endpoints migrated: GET /livechat/users/:type, POST /livechat/users/:type, GET /livechat/users/:type/:_id, DELETE /livechat/users/:type/:_id

packages/rest-typings/src/v1/omnichannel.ts

  • Removed parameterized path types (/livechat/users/${string}, /livechat/users/${string}/${string}) that were previously in the shared Endpoints interface
  • Kept concrete path aliases (e.g., /livechat/users/agent) for client-side useEndpoint() compatibility

.changeset/migrate-livechat-users-openapi.md

  • Added changeset with minor bump for @rocket.chat/meteor and @rocket.chat/rest-typings

Test results

image

Summary by CodeRabbit

  • New Features

    • OpenAPI-backed request/response validation for livechat user endpoints.
    • Separate manager and user routes with create, list, fetch-by-id, and delete actions; create now accepts a simple username payload.
  • Refactor

    • Routes reorganized for clearer manager/user separation, improved pagination, filtering, and sensible defaults.
    • Stronger authorization checks and clearer error responses; single-user fetch may return null when not found.

@amitb0ra amitb0ra requested review from a team as code owners March 12, 2026 19:01
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 12, 2026

🦋 Changeset detected

Latest commit: 0c5e53f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 41 packages
Name Type
@rocket.chat/meteor Minor
@rocket.chat/rest-typings Minor
@rocket.chat/api-client Patch
@rocket.chat/core-services Patch
@rocket.chat/ddp-client Patch
@rocket.chat/http-router Patch
@rocket.chat/models Patch
@rocket.chat/ui-contexts Major
@rocket.chat/web-ui-registration Major
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/federation-matrix Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/abac Patch
@rocket.chat/network-broker Patch
@rocket.chat/omni-core-ee Patch
@rocket.chat/livechat Patch
@rocket.chat/mock-providers Patch
@rocket.chat/cron Patch
@rocket.chat/instance-status Patch
@rocket.chat/omni-core Patch
@rocket.chat/server-fetch Patch
@rocket.chat/ui-client Major
@rocket.chat/media-calls Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/fuselage-ui-kit Major
@rocket.chat/gazzodown Major
@rocket.chat/ui-avatar Major
@rocket.chat/ui-video-conf Major
@rocket.chat/ui-voip Major
@rocket.chat/core-typings Minor
@rocket.chat/apps Patch
@rocket.chat/model-typings Patch
@rocket.chat/license Patch
@rocket.chat/pdf-worker Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 12, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Replaced legacy addRoute for livechat/users with OpenAPI-style per-route API.v1.get/post/delete, added AJV request/response schemas and validators, moved some typings into route file, and updated public REST typings to use concrete /v1/livechat/users/manager and /v1/livechat/users/user routes.

Changes

Cohort / File(s) Summary
Changeset
\.changeset/migrate-livechat-users-openapi.md
Added changeset declaring minor package bumps and noting migration of livechat/users endpoints to OpenAPI-style routes with AJV validation.
Livechat users REST implementation
apps/meteor/app/livechat/imports/server/rest/users.ts
Replaced single param-based addRoute with per-path API.v1.get/post/delete handlers; introduced local request/response AJV schemas, validators, and new local types; adjusted permission checks, defaulted missing booleans, added explicit responses, and exported livechatUsersEndpoints with module augmentation.
REST typings
packages/rest-typings/src/v1/omnichannel.ts
Removed legacy :type and :type/:_id endpoint typings and related props/schemas; added concrete /v1/livechat/users/manager and /v1/livechat/users/user endpoint signatures with updated GET PaginatedRequest params and simplified POST payloads; removed obsolete exported props/schemas.

Sequence Diagram(s)

sequenceDiagram
  participant Client as Client
  participant API as API.v1 (route layer)
  participant Service as LivechatUsersManager
  participant DB as Database

  Client->>API: HTTP GET/POST/DELETE /v1/livechat/users/{manager|user} ...
  API->>API: AJV validate request (query/body)
  API->>Service: authorize & invoke handler
  Service->>DB: query/update user records
  DB-->>Service: result
  Service-->>API: prepare response
  API->>API: AJV validate response
  API-->>Client: HTTP response
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

type: chore

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: migrating livechat/users endpoints to OpenAPI with AJV validation, matching the primary objective.
Linked Issues check ✅ Passed The PR implements the core OpenAPI migration requirements: chained route pattern, inline AJV schemas, response validation, ExtractRoutesFromAPI usage, and type augmentation for rest-typings.
Out of Scope Changes check ✅ Passed All changes are scoped to migrating the four livechat/users endpoints and updating related typings; no unrelated refactoring or feature additions detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot bot commented Mar 12, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

Copy link
Copy Markdown
Contributor

@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.

No issues found across 3 files

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: 1

🧹 Nitpick comments (2)
apps/meteor/app/livechat/imports/server/rest/users.ts (2)

69-70: Remove inline comment explaining schema fallback.

This explanatory comment violates coding guidelines. The reason for using { type: 'object' } can be documented in a PR description or ADR if needed, but should not remain in the code.

Suggested fix
 const paginatedUsersResponseSchema = ajv.compile<{
 	users: object[];
 	count: number;
 	offset: number;
 	total: number;
 }>({
 	type: 'object',
 	properties: {
-		// ILivechatAgent is not registered in typia (extends IUser with livechat-specific fields),
-		// so we use { type: 'object' } as a fallback.
 		users: { type: 'array', items: { type: 'object' } },
 		count: { type: 'number' },
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/meteor/app/livechat/imports/server/rest/users.ts` around lines 69 - 70,
Remove the inline explanatory comment about the ILivechatAgent schema fallback:
find the comment referencing "ILivechatAgent is not registered in typia (extends
IUser with livechat-specific fields), so we use { type: 'object' } as a
fallback" and delete it so only the code uses the fallback schema ({ type:
'object' }) without the explanatory note; if documentation is needed, move the
explanation to the PR description or an ADR instead.

11-11: Remove section divider comments.

Per coding guidelines, code comments should be avoided in the implementation. The section divider comments on lines 11, 59, and 258 (// --- Local types..., // --- Response schemas ---, // --- Type augmentation ---) should be removed.

Also applies to: 59-59, 258-258

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/meteor/app/livechat/imports/server/rest/users.ts` at line 11, Remove the
three section divider comments that violate the coding guideline: delete the
lines containing "// --- Local types and AJV schemas (moved from rest-typings)
---", "// --- Response schemas ---", and "// --- Type augmentation ---" in the
users.ts file; search for these exact comment strings (or similar divider
comments) near the top of the module and remove them so only code and necessary
inline comments remain, ensuring no other identical divider comments are left in
the file.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/rest-typings/src/v1/omnichannel.ts`:
- Line 4664: The POST signature for the /livechat/users/agent route is
incorrectly using PaginatedRequest<{ username: string }>, causing a mismatch
with the shared handler which expects a plain body; update the POST type for the
route currently declared as "POST: (params: PaginatedRequest<{ username: string
}>) => { success: boolean }" to "POST: (params: { username: string }) => {
success: boolean }" so it matches the other routes (/livechat/users/manager and
/livechat/users/user) and the POST livechat/users/:type handler.

---

Nitpick comments:
In `@apps/meteor/app/livechat/imports/server/rest/users.ts`:
- Around line 69-70: Remove the inline explanatory comment about the
ILivechatAgent schema fallback: find the comment referencing "ILivechatAgent is
not registered in typia (extends IUser with livechat-specific fields), so we use
{ type: 'object' } as a fallback" and delete it so only the code uses the
fallback schema ({ type: 'object' }) without the explanatory note; if
documentation is needed, move the explanation to the PR description or an ADR
instead.
- Line 11: Remove the three section divider comments that violate the coding
guideline: delete the lines containing "// --- Local types and AJV schemas
(moved from rest-typings) ---", "// --- Response schemas ---", and "// --- Type
augmentation ---" in the users.ts file; search for these exact comment strings
(or similar divider comments) near the top of the module and remove them so only
code and necessary inline comments remain, ensuring no other identical divider
comments are left in the file.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e9949ec8-d2c8-4776-a74b-6619bd1d6195

📥 Commits

Reviewing files that changed from the base of the PR and between 1cac8c3 and 735c59b.

📒 Files selected for processing (3)
  • .changeset/migrate-livechat-users-openapi.md
  • apps/meteor/app/livechat/imports/server/rest/users.ts
  • packages/rest-typings/src/v1/omnichannel.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: cubic · AI code reviewer
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • packages/rest-typings/src/v1/omnichannel.ts
  • apps/meteor/app/livechat/imports/server/rest/users.ts
🧠 Learnings (11)
📓 Common learnings
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38974
File: apps/meteor/app/api/server/v1/im.ts:220-221
Timestamp: 2026-02-24T19:09:09.561Z
Learning: In RocketChat/Rocket.Chat OpenAPI migration PRs for apps/meteor/app/api/server/v1 endpoints, maintainers prefer to avoid any logic changes; style-only cleanups (like removing inline comments) may be deferred to follow-ups to keep scope tight.
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39414
File: apps/meteor/app/api/server/v1/rooms.ts:1241-1297
Timestamp: 2026-03-10T08:13:52.153Z
Learning: In the RocketChat/Rocket.Chat OpenAPI migration PRs for endpoints under apps/meteor/app/api/server/v1/rooms.ts, the pattern `ajv.compile<void>({...})` is intentionally used for the 200 response schema even when the endpoint returns `{ success: true }`. This is an established convention across all migrated endpoints (rooms.leave, rooms.favorite, rooms.delete, rooms.muteUser, rooms.unmuteUser). Do not flag this as a type mismatch during reviews of these migration PRs.
Learnt from: ggazzo
Repo: RocketChat/Rocket.Chat PR: 35995
File: apps/meteor/app/api/server/v1/rooms.ts:1107-1112
Timestamp: 2026-02-23T17:53:18.785Z
Learning: In Rocket.Chat PR reviews, maintain strict scope boundaries—when a PR is focused on a specific endpoint (e.g., rooms.favorite), avoid reviewing or suggesting changes to other endpoints that were incidentally refactored (e.g., rooms.invite) unless explicitly requested by maintainers.
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39230
File: apps/meteor/app/api/server/v1/chat.ts:214-222
Timestamp: 2026-03-03T11:11:48.541Z
Learning: In apps/meteor/server/lib/moderation/reportMessage.ts, the reportMessage function validates that description is not empty or whitespace-only with `if (!description.trim())`. When migrating the chat.reportMessage endpoint to OpenAPI, adding minLength validation to the schema preserves this existing behavior.
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39340
File: apps/meteor/app/api/server/v1/im.ts:1349-1398
Timestamp: 2026-03-12T10:26:26.697Z
Learning: In `apps/meteor/app/api/server/v1/im.ts` (PR `#39340`), the `DmEndpoints` type intentionally includes temporary stub entries for `/v1/im.kick`, `/v1/dm.kick`, `/v1/im.leave`, and `/v1/dm.leave` (using `DmKickProps` and `DmLeaveProps`) even though no route handlers exist for them yet. These stubs were added to preserve type compatibility after removing the original `DmLeaveProps` and related files. They are planned for cleanup in a follow-up PR. Do not flag these as missing implementations when reviewing this file until the follow-up is merged.
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38913
File: packages/ddp-client/src/legacy/types/SDKLegacy.ts:34-34
Timestamp: 2026-02-25T20:10:16.987Z
Learning: In the RocketChat/Rocket.Chat monorepo, packages/ddp-client and apps/meteor do not use TypeScript project references. Module augmentations in apps/meteor (e.g., declare module 'rocket.chat/rest-typings') are not visible when compiling packages/ddp-client in isolation, which is why legacy SDK methods that depend on OperationResult types for OpenAPI-migrated endpoints must remain commented out.
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38528
File: apps/meteor/client/startup/roles.ts:14-14
Timestamp: 2026-02-10T16:32:49.806Z
Learning: In Rocket.Chat's Meteor client code, DDP streams use EJSON which automatically deserializes Date objects. Stream handlers (e.g., sdk.stream()) receive Date fields as Date objects directly and do not require manual conversion using `new Date()`. Only REST API responses require manual date conversion because they return plain JSON where dates are serialized as strings.
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 37205
File: ee/packages/federation-matrix/src/FederationMatrix.ts:296-301
Timestamp: 2025-10-28T16:53:42.761Z
Learning: In the Rocket.Chat federation-matrix integration (ee/packages/federation-matrix/), the createRoom method from rocket.chat/federation-sdk will support a 4-argument signature (userId, roomName, visibility, displayName) in newer versions. Code using this 4-argument call is forward-compatible with planned library updates and should not be flagged as an error.
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 37205
File: ee/packages/federation-matrix/src/FederationMatrix.ts:296-301
Timestamp: 2025-10-28T16:53:42.761Z
Learning: In the Rocket.Chat federation-matrix integration (ee/packages/federation-matrix/), the createRoom method from rocket.chat/federation-sdk will support a 4-argument signature (userId, roomName, visibility, displayName) in newer versions. Code using this 4-argument call is forward-compatible with planned library updates and should not be flagged as an error.
📚 Learning: 2026-02-24T19:09:09.561Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38974
File: apps/meteor/app/api/server/v1/im.ts:220-221
Timestamp: 2026-02-24T19:09:09.561Z
Learning: In RocketChat/Rocket.Chat OpenAPI migration PRs for apps/meteor/app/api/server/v1 endpoints, maintainers prefer to avoid any logic changes; style-only cleanups (like removing inline comments) may be deferred to follow-ups to keep scope tight.

Applied to files:

  • .changeset/migrate-livechat-users-openapi.md
  • apps/meteor/app/livechat/imports/server/rest/users.ts
📚 Learning: 2026-02-25T20:10:16.987Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38913
File: packages/ddp-client/src/legacy/types/SDKLegacy.ts:34-34
Timestamp: 2026-02-25T20:10:16.987Z
Learning: In the RocketChat/Rocket.Chat monorepo, packages/ddp-client and apps/meteor do not use TypeScript project references. Module augmentations in apps/meteor (e.g., declare module 'rocket.chat/rest-typings') are not visible when compiling packages/ddp-client in isolation, which is why legacy SDK methods that depend on OperationResult types for OpenAPI-migrated endpoints must remain commented out.

Applied to files:

  • .changeset/migrate-livechat-users-openapi.md
  • apps/meteor/app/livechat/imports/server/rest/users.ts
📚 Learning: 2026-03-03T11:11:48.541Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39230
File: apps/meteor/app/api/server/v1/chat.ts:214-222
Timestamp: 2026-03-03T11:11:48.541Z
Learning: In apps/meteor/server/lib/moderation/reportMessage.ts, the reportMessage function validates that description is not empty or whitespace-only with `if (!description.trim())`. When migrating the chat.reportMessage endpoint to OpenAPI, adding minLength validation to the schema preserves this existing behavior.

Applied to files:

  • .changeset/migrate-livechat-users-openapi.md
  • apps/meteor/app/livechat/imports/server/rest/users.ts
📚 Learning: 2026-02-24T19:05:56.710Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 0
File: :0-0
Timestamp: 2026-02-24T19:05:56.710Z
Learning: Rocket.Chat repo context: When a workspace manifest on develop already pins a dependency version (e.g., packages/web-ui-registration → "rocket.chat/ui-contexts": "27.0.1"), a lockfile change in a feature PR that upgrades only that dependency’s resolution is considered a manifest-driven sync and can be kept, preferably as a small "chore: sync yarn.lock with manifests" commit.

Applied to files:

  • .changeset/migrate-livechat-users-openapi.md
📚 Learning: 2026-03-10T08:13:52.153Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39414
File: apps/meteor/app/api/server/v1/rooms.ts:1241-1297
Timestamp: 2026-03-10T08:13:52.153Z
Learning: In the RocketChat/Rocket.Chat OpenAPI migration PRs for endpoints under apps/meteor/app/api/server/v1/rooms.ts, the pattern `ajv.compile<void>({...})` is intentionally used for the 200 response schema even when the endpoint returns `{ success: true }`. This is an established convention across all migrated endpoints (rooms.leave, rooms.favorite, rooms.delete, rooms.muteUser, rooms.unmuteUser). Do not flag this as a type mismatch during reviews of these migration PRs.

Applied to files:

  • .changeset/migrate-livechat-users-openapi.md
  • packages/rest-typings/src/v1/omnichannel.ts
  • apps/meteor/app/livechat/imports/server/rest/users.ts
📚 Learning: 2026-03-12T10:26:26.697Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39340
File: apps/meteor/app/api/server/v1/im.ts:1349-1398
Timestamp: 2026-03-12T10:26:26.697Z
Learning: In `apps/meteor/app/api/server/v1/im.ts` (PR `#39340`), the `DmEndpoints` type intentionally includes temporary stub entries for `/v1/im.kick`, `/v1/dm.kick`, `/v1/im.leave`, and `/v1/dm.leave` (using `DmKickProps` and `DmLeaveProps`) even though no route handlers exist for them yet. These stubs were added to preserve type compatibility after removing the original `DmLeaveProps` and related files. They are planned for cleanup in a follow-up PR. Do not flag these as missing implementations when reviewing this file until the follow-up is merged.

Applied to files:

  • packages/rest-typings/src/v1/omnichannel.ts
  • apps/meteor/app/livechat/imports/server/rest/users.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • packages/rest-typings/src/v1/omnichannel.ts
  • apps/meteor/app/livechat/imports/server/rest/users.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • packages/rest-typings/src/v1/omnichannel.ts
  • apps/meteor/app/livechat/imports/server/rest/users.ts
📚 Learning: 2026-03-09T18:39:21.178Z
Learnt from: Harxhit
Repo: RocketChat/Rocket.Chat PR: 39476
File: apps/meteor/server/methods/addAllUserToRoom.ts:0-0
Timestamp: 2026-03-09T18:39:21.178Z
Learning: In apps/meteor/server/methods/addAllUserToRoom.ts, the implementation uses a single cursor pass (Users.find(userFilter).batchSize(100)) that collects both the full user objects (collectedUsers: IUser[]) and their usernames (usernames: string[]) in one iteration. `beforeAddUserToRoom` is then called once with the full usernames batch (preserving batch-validation semantics), and the subsequent subscription/message processing loop iterates over the same stable `collectedUsers` array — no second DB query is made. This avoids any race condition between validation and processing while preserving the original batch-validation behavior.

Applied to files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
📚 Learning: 2026-03-11T16:46:55.955Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 39535
File: apps/meteor/app/apps/server/bridges/livechat.ts:249-249
Timestamp: 2026-03-11T16:46:55.955Z
Learning: In `apps/meteor/app/apps/server/bridges/livechat.ts`, `createVisitor()` intentionally does not propagate `externalIds` to `registerData`. This is by design: the method is deprecated (JSDoc: `deprecated Use createAndReturnVisitor instead. Note: This method does not support externalIds.`) to push callers toward `createAndReturnVisitor()`, which does support `externalIds`. Do not flag the missing `externalIds` field in `createVisitor()` as a bug.

Applied to files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
🔇 Additional comments (3)
apps/meteor/app/livechat/imports/server/rest/users.ts (2)

258-265: LGTM!

The type augmentation pattern using ExtractRoutesFromAPI and module augmentation to extend @rocket.chat/rest-typings Endpoints interface follows the established convention for OpenAPI migrations.


241-255: This concern is unfounded. The POST handler at lines 184-198 also calls addAgent and addManager, which throw Error('error-invalid-user') when users are not found, yet it has no try-catch wrapper. Both handlers directly throw new Error('Invalid type') without catching. This pattern indicates the framework's error handling (via Hono) manages exceptions from route handlers appropriately. No changes needed.

			> Likely an incorrect or invalid review comment.
.changeset/migrate-livechat-users-openapi.md (1)

1-6: LGTM!

The changeset correctly documents the minor version bumps for both packages and accurately describes the OpenAPI migration with AJV validation for the livechat/users endpoints.

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: 2

🧹 Nitpick comments (1)
packages/rest-typings/src/v1/omnichannel.ts (1)

4633-4639: Return type should include departments field to match actual API response.

The backend calls findManagers() which uses Users.findAgentsWithDepartments(). According to the model definition in packages/models/src/models/Users.ts, this method returns documents with an added departments: string[] field via aggregation lookup.

The current return type ILivechatAgent[] doesn't reflect this, which may cause type mismatches for consumers expecting the full response shape.

Suggested fix
 '/v1/livechat/users/manager': {
 	GET: (
 		params: PaginatedRequest<{ text?: string; fields?: string; onlyAvailable?: boolean; excludeId?: string; showIdleAgents?: boolean }>,
 	) => PaginatedResult<{
-		users: ILivechatAgent[];
+		users: (ILivechatAgent & { departments: string[] })[];
 	}>;
 	POST: (params: { username: string }) => { success: boolean };
 };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/rest-typings/src/v1/omnichannel.ts` around lines 4633 - 4639, The
GET response type for '/v1/livechat/users/manager' is missing the aggregated
departments field; update the PaginatedResult return type so each user includes
departments: string[] (e.g., change PaginatedResult<{ users: ILivechatAgent[] }>
to PaginatedResult<{ users: (ILivechatAgent & { departments: string[] })[] }>),
matching the data produced by findManagers()/Users.findAgentsWithDepartments().
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/rest-typings/src/v1/omnichannel.ts`:
- Around line 4642-4649: The typings declare endpoints '/v1/livechat/users/user'
and '/v1/livechat/users/user/:_id' that the backend does not support (handler in
apps/meteor/app/livechat/imports/server/rest/users.ts only accepts type ===
'agent' or 'manager' and throws "Invalid type" at the check around line 167);
either remove these two endpoint entries from
packages/rest-typings/src/v1/omnichannel.ts or implement corresponding backend
handling for type === 'user' in the server handler (add acceptance, validation
and response logic matching the typings), and ensure the REST handler and the
PaginatedResult/POST shapes (as declared) stay consistent between the typing
symbols and the server functions.
- Line 4665: The POST signature for the /v1/livechat/users/agent endpoint
references an undefined type POSTLivechatUsersTypeProps which will break
TypeScript; replace that reference with the same parameter type used by the
other livechat user POST endpoints (i.e. use { username: string }) or
alternatively declare POSTLivechatUsersTypeProps as an alias for { username:
string } so the POST: (params: POSTLivechatUsersTypeProps) => { success: boolean
} becomes consistent with the manager/user endpoints.

---

Nitpick comments:
In `@packages/rest-typings/src/v1/omnichannel.ts`:
- Around line 4633-4639: The GET response type for '/v1/livechat/users/manager'
is missing the aggregated departments field; update the PaginatedResult return
type so each user includes departments: string[] (e.g., change PaginatedResult<{
users: ILivechatAgent[] }> to PaginatedResult<{ users: (ILivechatAgent & {
departments: string[] })[] }>), matching the data produced by
findManagers()/Users.findAgentsWithDepartments().
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4e1cd62f-97ec-4de5-9c68-4c90836547ca

📥 Commits

Reviewing files that changed from the base of the PR and between 735c59b and 5603116.

📒 Files selected for processing (1)
  • packages/rest-typings/src/v1/omnichannel.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • packages/rest-typings/src/v1/omnichannel.ts
🧠 Learnings (8)
📓 Common learnings
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38974
File: apps/meteor/app/api/server/v1/im.ts:220-221
Timestamp: 2026-02-24T19:09:09.561Z
Learning: In RocketChat/Rocket.Chat OpenAPI migration PRs for apps/meteor/app/api/server/v1 endpoints, maintainers prefer to avoid any logic changes; style-only cleanups (like removing inline comments) may be deferred to follow-ups to keep scope tight.
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39414
File: apps/meteor/app/api/server/v1/rooms.ts:1241-1297
Timestamp: 2026-03-10T08:13:52.153Z
Learning: In the RocketChat/Rocket.Chat OpenAPI migration PRs for endpoints under apps/meteor/app/api/server/v1/rooms.ts, the pattern `ajv.compile<void>({...})` is intentionally used for the 200 response schema even when the endpoint returns `{ success: true }`. This is an established convention across all migrated endpoints (rooms.leave, rooms.favorite, rooms.delete, rooms.muteUser, rooms.unmuteUser). Do not flag this as a type mismatch during reviews of these migration PRs.
Learnt from: ggazzo
Repo: RocketChat/Rocket.Chat PR: 35995
File: apps/meteor/app/api/server/v1/rooms.ts:1107-1112
Timestamp: 2026-02-23T17:53:18.785Z
Learning: In Rocket.Chat PR reviews, maintain strict scope boundaries—when a PR is focused on a specific endpoint (e.g., rooms.favorite), avoid reviewing or suggesting changes to other endpoints that were incidentally refactored (e.g., rooms.invite) unless explicitly requested by maintainers.
📚 Learning: 2026-03-12T10:26:26.697Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39340
File: apps/meteor/app/api/server/v1/im.ts:1349-1398
Timestamp: 2026-03-12T10:26:26.697Z
Learning: In `apps/meteor/app/api/server/v1/im.ts` (PR `#39340`), the `DmEndpoints` type intentionally includes temporary stub entries for `/v1/im.kick`, `/v1/dm.kick`, `/v1/im.leave`, and `/v1/dm.leave` (using `DmKickProps` and `DmLeaveProps`) even though no route handlers exist for them yet. These stubs were added to preserve type compatibility after removing the original `DmLeaveProps` and related files. They are planned for cleanup in a follow-up PR. Do not flag these as missing implementations when reviewing this file until the follow-up is merged.

Applied to files:

  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2026-03-10T08:13:52.153Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39414
File: apps/meteor/app/api/server/v1/rooms.ts:1241-1297
Timestamp: 2026-03-10T08:13:52.153Z
Learning: In the RocketChat/Rocket.Chat OpenAPI migration PRs for endpoints under apps/meteor/app/api/server/v1/rooms.ts, the pattern `ajv.compile<void>({...})` is intentionally used for the 200 response schema even when the endpoint returns `{ success: true }`. This is an established convention across all migrated endpoints (rooms.leave, rooms.favorite, rooms.delete, rooms.muteUser, rooms.unmuteUser). Do not flag this as a type mismatch during reviews of these migration PRs.

Applied to files:

  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2026-03-11T16:46:55.955Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 39535
File: apps/meteor/app/apps/server/bridges/livechat.ts:249-249
Timestamp: 2026-03-11T16:46:55.955Z
Learning: In `apps/meteor/app/apps/server/bridges/livechat.ts`, `createVisitor()` intentionally does not propagate `externalIds` to `registerData`. This is by design: the method is deprecated (JSDoc: `deprecated Use createAndReturnVisitor instead. Note: This method does not support externalIds.`) to push callers toward `createAndReturnVisitor()`, which does support `externalIds`. Do not flag the missing `externalIds` field in `createVisitor()` as a bug.

Applied to files:

  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2026-01-17T01:51:47.764Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38219
File: packages/core-typings/src/cloud/Announcement.ts:5-6
Timestamp: 2026-01-17T01:51:47.764Z
Learning: In packages/core-typings/src/cloud/Announcement.ts, the AnnouncementSchema.createdBy field intentionally overrides IBannerSchema.createdBy (object with _id and optional username) with a string enum ['cloud', 'system'] to match existing runtime behavior. This is documented as technical debt with a FIXME comment at apps/meteor/app/cloud/server/functions/syncWorkspace/handleCommsSync.ts:53 and should not be flagged as an error until the runtime behavior is corrected.

Applied to files:

  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2025-10-06T20:32:23.658Z
Learnt from: d-gubert
Repo: RocketChat/Rocket.Chat PR: 37152
File: packages/apps-engine/tests/test-data/utilities.ts:557-573
Timestamp: 2025-10-06T20:32:23.658Z
Learning: In packages/apps-engine/tests/test-data/utilities.ts, the field name `isSubscripbedViaBundle` in the `IMarketplaceSubscriptionInfo` type should not be flagged as a typo, as it may match the upstream API's field name.

Applied to files:

  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • packages/rest-typings/src/v1/omnichannel.ts

@amitb0ra amitb0ra force-pushed the refactor/migrate-livechat-users-openapi branch from 5603116 to dc8f9f2 Compare March 12, 2026 19:41
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: 1

🧹 Nitpick comments (2)
apps/meteor/app/livechat/imports/server/rest/users.ts (2)

61-89: Tighten the user payload schemas before publishing these OpenAPI responses.

user and users[*] are validated as plain object, so AJV will not catch contract drift and Swagger will not show the fields these endpoints actually return. The POST path already returns a stable { _id, username } shape, and the GET-by-id path projects a fixed field set, so these schemas should be explicit (or share a small reusable schema) instead of staying opaque.

Also applies to: 100-107

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/meteor/app/livechat/imports/server/rest/users.ts` around lines 61 - 89,
The response schemas are too loose: replace the anonymous { type: 'object' } for
user and users[*] with an explicit schema describing the actual fields returned
(at minimum the POST response shape {_id, username} and the GET-by-id projected
fields) and reuse it across paginatedUsersResponseSchema and
postUserResponseSchema (e.g. create a single userResponseSchema and reference it
in users.items and in user). Ensure success remains required and
additionalProperties is set appropriately; update the same pattern used around
the other schemas referenced in the diff (paginatedUsersResponseSchema,
postUserResponseSchema and the nearby schemas mentioned in the comment) so the
OpenAPI output and AJV validation reflect the real fields.

11-12: Please drop the added implementation comments from this migration diff.

The section headers, fallback note, and TODO add noise to a file that is already readable through names and schemas. If you want to keep this PR narrowly scoped, this is fine as a quick follow-up.

As per coding guidelines, "Avoid code comments in the implementation." Based on learnings, maintainers prefer to defer style-only cleanups in OpenAPI migration PRs.

Also applies to: 59-60, 69-70, 224-224, 258-259

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/meteor/app/livechat/imports/server/rest/users.ts` around lines 11 - 12,
Remove the added implementation comments and section headers introduced in this
migration (e.g. the "// --- Local types and AJV schemas (moved from
rest-typings) ---" header, the fallback note comment, and the "TODO"
implementation notes) so the file contains only code and schemas; search for
those exact comment strings in users.ts and delete them (and any other similar
migration-only commentary) to comply with the "Avoid code comments in the
implementation" guideline.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/meteor/app/livechat/imports/server/rest/users.ts`:
- Around line 260-264: The generated type LivechatUsersEndpoints =
ExtractRoutesFromAPI<typeof livechatUsersEndpoints> is exposing literal route
keys like 'livechat/users/:type' and 'livechat/users/:type/:_id', which don't
match the concrete endpoint aliases in the public Endpoints interface; update
the augmentation so the Endpoints interface in module
'@rocket.chat/rest-typings' is extended with the concrete alias keys used in
packages/rest-typings/src/v1/omnichannel.ts (or stop exporting
LivechatUsersEndpoints until you map the literal paths to those aliases).
Concretely, replace or wrap the current augmentation of Endpoints with a mapped
type or explicit aliasing that translates the ExtractRoutesFromAPI keys from
livechatUsersEndpoints into the actual public endpoint names so the exported
Endpoints matches the manual omnichannel aliases.

---

Nitpick comments:
In `@apps/meteor/app/livechat/imports/server/rest/users.ts`:
- Around line 61-89: The response schemas are too loose: replace the anonymous {
type: 'object' } for user and users[*] with an explicit schema describing the
actual fields returned (at minimum the POST response shape {_id, username} and
the GET-by-id projected fields) and reuse it across paginatedUsersResponseSchema
and postUserResponseSchema (e.g. create a single userResponseSchema and
reference it in users.items and in user). Ensure success remains required and
additionalProperties is set appropriately; update the same pattern used around
the other schemas referenced in the diff (paginatedUsersResponseSchema,
postUserResponseSchema and the nearby schemas mentioned in the comment) so the
OpenAPI output and AJV validation reflect the real fields.
- Around line 11-12: Remove the added implementation comments and section
headers introduced in this migration (e.g. the "// --- Local types and AJV
schemas (moved from rest-typings) ---" header, the fallback note comment, and
the "TODO" implementation notes) so the file contains only code and schemas;
search for those exact comment strings in users.ts and delete them (and any
other similar migration-only commentary) to comply with the "Avoid code comments
in the implementation" guideline.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 261c76f2-e53d-4d5e-a1d1-9adc16605912

📥 Commits

Reviewing files that changed from the base of the PR and between 5603116 and dc8f9f2.

📒 Files selected for processing (3)
  • .changeset/migrate-livechat-users-openapi.md
  • apps/meteor/app/livechat/imports/server/rest/users.ts
  • packages/rest-typings/src/v1/omnichannel.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • .changeset/migrate-livechat-users-openapi.md
  • packages/rest-typings/src/v1/omnichannel.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
🧠 Learnings (8)
📓 Common learnings
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38974
File: apps/meteor/app/api/server/v1/im.ts:220-221
Timestamp: 2026-02-24T19:09:09.561Z
Learning: In RocketChat/Rocket.Chat OpenAPI migration PRs for apps/meteor/app/api/server/v1 endpoints, maintainers prefer to avoid any logic changes; style-only cleanups (like removing inline comments) may be deferred to follow-ups to keep scope tight.
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39414
File: apps/meteor/app/api/server/v1/rooms.ts:1241-1297
Timestamp: 2026-03-10T08:13:52.153Z
Learning: In the RocketChat/Rocket.Chat OpenAPI migration PRs for endpoints under apps/meteor/app/api/server/v1/rooms.ts, the pattern `ajv.compile<void>({...})` is intentionally used for the 200 response schema even when the endpoint returns `{ success: true }`. This is an established convention across all migrated endpoints (rooms.leave, rooms.favorite, rooms.delete, rooms.muteUser, rooms.unmuteUser). Do not flag this as a type mismatch during reviews of these migration PRs.
Learnt from: ggazzo
Repo: RocketChat/Rocket.Chat PR: 35995
File: apps/meteor/app/api/server/v1/rooms.ts:1107-1112
Timestamp: 2026-02-23T17:53:18.785Z
Learning: In Rocket.Chat PR reviews, maintain strict scope boundaries—when a PR is focused on a specific endpoint (e.g., rooms.favorite), avoid reviewing or suggesting changes to other endpoints that were incidentally refactored (e.g., rooms.invite) unless explicitly requested by maintainers.
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39340
File: apps/meteor/app/api/server/v1/im.ts:1349-1398
Timestamp: 2026-03-12T10:26:26.697Z
Learning: In `apps/meteor/app/api/server/v1/im.ts` (PR `#39340`), the `DmEndpoints` type intentionally includes temporary stub entries for `/v1/im.kick`, `/v1/dm.kick`, `/v1/im.leave`, and `/v1/dm.leave` (using `DmKickProps` and `DmLeaveProps`) even though no route handlers exist for them yet. These stubs were added to preserve type compatibility after removing the original `DmLeaveProps` and related files. They are planned for cleanup in a follow-up PR. Do not flag these as missing implementations when reviewing this file until the follow-up is merged.
📚 Learning: 2026-03-12T10:26:26.697Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39340
File: apps/meteor/app/api/server/v1/im.ts:1349-1398
Timestamp: 2026-03-12T10:26:26.697Z
Learning: In `apps/meteor/app/api/server/v1/im.ts` (PR `#39340`), the `DmEndpoints` type intentionally includes temporary stub entries for `/v1/im.kick`, `/v1/dm.kick`, `/v1/im.leave`, and `/v1/dm.leave` (using `DmKickProps` and `DmLeaveProps`) even though no route handlers exist for them yet. These stubs were added to preserve type compatibility after removing the original `DmLeaveProps` and related files. They are planned for cleanup in a follow-up PR. Do not flag these as missing implementations when reviewing this file until the follow-up is merged.

Applied to files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
📚 Learning: 2026-02-25T20:10:16.987Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38913
File: packages/ddp-client/src/legacy/types/SDKLegacy.ts:34-34
Timestamp: 2026-02-25T20:10:16.987Z
Learning: In the RocketChat/Rocket.Chat monorepo, packages/ddp-client and apps/meteor do not use TypeScript project references. Module augmentations in apps/meteor (e.g., declare module 'rocket.chat/rest-typings') are not visible when compiling packages/ddp-client in isolation, which is why legacy SDK methods that depend on OperationResult types for OpenAPI-migrated endpoints must remain commented out.

Applied to files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
📚 Learning: 2026-02-24T19:09:09.561Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38974
File: apps/meteor/app/api/server/v1/im.ts:220-221
Timestamp: 2026-02-24T19:09:09.561Z
Learning: In RocketChat/Rocket.Chat OpenAPI migration PRs for apps/meteor/app/api/server/v1 endpoints, maintainers prefer to avoid any logic changes; style-only cleanups (like removing inline comments) may be deferred to follow-ups to keep scope tight.

Applied to files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
📚 Learning: 2026-03-09T18:39:21.178Z
Learnt from: Harxhit
Repo: RocketChat/Rocket.Chat PR: 39476
File: apps/meteor/server/methods/addAllUserToRoom.ts:0-0
Timestamp: 2026-03-09T18:39:21.178Z
Learning: In apps/meteor/server/methods/addAllUserToRoom.ts, the implementation uses a single cursor pass (Users.find(userFilter).batchSize(100)) that collects both the full user objects (collectedUsers: IUser[]) and their usernames (usernames: string[]) in one iteration. `beforeAddUserToRoom` is then called once with the full usernames batch (preserving batch-validation semantics), and the subsequent subscription/message processing loop iterates over the same stable `collectedUsers` array — no second DB query is made. This avoids any race condition between validation and processing while preserving the original batch-validation behavior.

Applied to files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
📚 Learning: 2026-03-10T08:13:52.153Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39414
File: apps/meteor/app/api/server/v1/rooms.ts:1241-1297
Timestamp: 2026-03-10T08:13:52.153Z
Learning: In the RocketChat/Rocket.Chat OpenAPI migration PRs for endpoints under apps/meteor/app/api/server/v1/rooms.ts, the pattern `ajv.compile<void>({...})` is intentionally used for the 200 response schema even when the endpoint returns `{ success: true }`. This is an established convention across all migrated endpoints (rooms.leave, rooms.favorite, rooms.delete, rooms.muteUser, rooms.unmuteUser). Do not flag this as a type mismatch during reviews of these migration PRs.

Applied to files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts

@amitb0ra amitb0ra force-pushed the refactor/migrate-livechat-users-openapi branch from dc8f9f2 to 5dc4b44 Compare March 12, 2026 20:13
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: 1

♻️ Duplicate comments (1)
packages/rest-typings/src/v1/omnichannel.ts (1)

4642-4648: ⚠️ Potential issue | 🟠 Major

Remove the unsupported /livechat/users/user alias.

apps/meteor/app/livechat/imports/server/rest/users.ts only accepts type === 'agent' or type === 'manager' for these migrated handlers. Keeping /v1/livechat/users/user in the public typings advertises an endpoint that will always fail with Invalid type, and the sibling '/v1/livechat/users/user/:_id' just below has the same problem.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/rest-typings/src/v1/omnichannel.ts` around lines 4642 - 4648, The
public typings advertise an unsupported alias: remove the
'/v1/livechat/users/user' route entry (and its sibling
'/v1/livechat/users/user/:_id') from packages/rest-typings/src/v1/omnichannel.ts
so the declared REST surface matches the actual handlers that only accept type
=== 'agent' or 'manager'; locate and delete the objects keyed by
'/v1/livechat/users/user' and '/v1/livechat/users/user/:_id' in the file
(keeping the correct '/v1/livechat/users' routes) so the typings no longer
advertise endpoints that will always return "Invalid type".
🧹 Nitpick comments (1)
apps/meteor/app/livechat/imports/server/rest/users.ts (1)

10-11: Drop the new section-header comments.

These headers are just organizing comments in implementation code. Please remove them and let the symbols/grouping carry the structure instead.

As per coding guidelines "Avoid code comments in the implementation".

Also applies to: 58-58

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/meteor/app/livechat/imports/server/rest/users.ts` around lines 10 - 11,
Remove the section-header comment lines that act as organizational headers (e.g.
the "// --- Local types and AJV schemas (moved from rest-typings) ---" line and
the similar header at the other location around line 58) in
apps/meteor/app/livechat/imports/server/rest/users.ts; leave the actual
declarations (types, AJV schema objects, functions like the local type
definitions or schema constants) intact so the symbols and groupings convey
structure rather than using comment headers.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/meteor/app/livechat/imports/server/rest/users.ts`:
- Around line 99-107: The GET /v1/livechat/users/agent/:_id handler (validated
by getUserByIdResponseSchema) can return { user: null } on missing/unauthorized
IDs but the REST typing for the route in
packages/rest-typings/src/v1/omnichannel.ts still marks user as non-null; update
the concrete route response type for '/v1/livechat/users/agent/:_id' to make the
user field nullable (object | null) to match getUserByIdResponseSchema (and
apply the same nullable change to any other routes in that file flagged by the
reviewer in the 200-225 range), or alternatively change the handler to return a
non-200 failure (e.g., 404/403) instead—pick one approach and make both the AJV
schema and the route typing consistent (references: getUserByIdResponseSchema
and the '/v1/livechat/users/agent/:_id' entry in omnihchannel.ts).

---

Duplicate comments:
In `@packages/rest-typings/src/v1/omnichannel.ts`:
- Around line 4642-4648: The public typings advertise an unsupported alias:
remove the '/v1/livechat/users/user' route entry (and its sibling
'/v1/livechat/users/user/:_id') from packages/rest-typings/src/v1/omnichannel.ts
so the declared REST surface matches the actual handlers that only accept type
=== 'agent' or 'manager'; locate and delete the objects keyed by
'/v1/livechat/users/user' and '/v1/livechat/users/user/:_id' in the file
(keeping the correct '/v1/livechat/users' routes) so the typings no longer
advertise endpoints that will always return "Invalid type".

---

Nitpick comments:
In `@apps/meteor/app/livechat/imports/server/rest/users.ts`:
- Around line 10-11: Remove the section-header comment lines that act as
organizational headers (e.g. the "// --- Local types and AJV schemas (moved from
rest-typings) ---" line and the similar header at the other location around line
58) in apps/meteor/app/livechat/imports/server/rest/users.ts; leave the actual
declarations (types, AJV schema objects, functions like the local type
definitions or schema constants) intact so the symbols and groupings convey
structure rather than using comment headers.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6d3e752e-b91b-4855-9e0d-a45f5a03aa05

📥 Commits

Reviewing files that changed from the base of the PR and between dc8f9f2 and 5dc4b44.

📒 Files selected for processing (3)
  • .changeset/migrate-livechat-users-openapi.md
  • apps/meteor/app/livechat/imports/server/rest/users.ts
  • packages/rest-typings/src/v1/omnichannel.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • .changeset/migrate-livechat-users-openapi.md
📜 Review details
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
  • packages/rest-typings/src/v1/omnichannel.ts
🧠 Learnings (15)
📓 Common learnings
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38974
File: apps/meteor/app/api/server/v1/im.ts:220-221
Timestamp: 2026-02-24T19:09:09.561Z
Learning: In RocketChat/Rocket.Chat OpenAPI migration PRs for apps/meteor/app/api/server/v1 endpoints, maintainers prefer to avoid any logic changes; style-only cleanups (like removing inline comments) may be deferred to follow-ups to keep scope tight.
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39414
File: apps/meteor/app/api/server/v1/rooms.ts:1241-1297
Timestamp: 2026-03-10T08:13:52.153Z
Learning: In the RocketChat/Rocket.Chat OpenAPI migration PRs for endpoints under apps/meteor/app/api/server/v1/rooms.ts, the pattern `ajv.compile<void>({...})` is intentionally used for the 200 response schema even when the endpoint returns `{ success: true }`. This is an established convention across all migrated endpoints (rooms.leave, rooms.favorite, rooms.delete, rooms.muteUser, rooms.unmuteUser). Do not flag this as a type mismatch during reviews of these migration PRs.
Learnt from: ggazzo
Repo: RocketChat/Rocket.Chat PR: 35995
File: apps/meteor/app/api/server/v1/rooms.ts:1107-1112
Timestamp: 2026-02-23T17:53:18.785Z
Learning: In Rocket.Chat PR reviews, maintain strict scope boundaries—when a PR is focused on a specific endpoint (e.g., rooms.favorite), avoid reviewing or suggesting changes to other endpoints that were incidentally refactored (e.g., rooms.invite) unless explicitly requested by maintainers.
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39340
File: apps/meteor/app/api/server/v1/im.ts:1349-1398
Timestamp: 2026-03-12T10:26:26.697Z
Learning: In `apps/meteor/app/api/server/v1/im.ts` (PR `#39340`), the `DmEndpoints` type intentionally includes temporary stub entries for `/v1/im.kick`, `/v1/dm.kick`, `/v1/im.leave`, and `/v1/dm.leave` (using `DmKickProps` and `DmLeaveProps`) even though no route handlers exist for them yet. These stubs were added to preserve type compatibility after removing the original `DmLeaveProps` and related files. They are planned for cleanup in a follow-up PR. Do not flag these as missing implementations when reviewing this file until the follow-up is merged.
📚 Learning: 2026-03-12T10:26:26.697Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39340
File: apps/meteor/app/api/server/v1/im.ts:1349-1398
Timestamp: 2026-03-12T10:26:26.697Z
Learning: In `apps/meteor/app/api/server/v1/im.ts` (PR `#39340`), the `DmEndpoints` type intentionally includes temporary stub entries for `/v1/im.kick`, `/v1/dm.kick`, `/v1/im.leave`, and `/v1/dm.leave` (using `DmKickProps` and `DmLeaveProps`) even though no route handlers exist for them yet. These stubs were added to preserve type compatibility after removing the original `DmLeaveProps` and related files. They are planned for cleanup in a follow-up PR. Do not flag these as missing implementations when reviewing this file until the follow-up is merged.

Applied to files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2026-02-25T20:10:16.987Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38913
File: packages/ddp-client/src/legacy/types/SDKLegacy.ts:34-34
Timestamp: 2026-02-25T20:10:16.987Z
Learning: In the RocketChat/Rocket.Chat monorepo, packages/ddp-client and apps/meteor do not use TypeScript project references. Module augmentations in apps/meteor (e.g., declare module 'rocket.chat/rest-typings') are not visible when compiling packages/ddp-client in isolation, which is why legacy SDK methods that depend on OperationResult types for OpenAPI-migrated endpoints must remain commented out.

Applied to files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2026-02-24T19:09:09.561Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38974
File: apps/meteor/app/api/server/v1/im.ts:220-221
Timestamp: 2026-02-24T19:09:09.561Z
Learning: In RocketChat/Rocket.Chat OpenAPI migration PRs for apps/meteor/app/api/server/v1 endpoints, maintainers prefer to avoid any logic changes; style-only cleanups (like removing inline comments) may be deferred to follow-ups to keep scope tight.

Applied to files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2026-03-09T18:39:21.178Z
Learnt from: Harxhit
Repo: RocketChat/Rocket.Chat PR: 39476
File: apps/meteor/server/methods/addAllUserToRoom.ts:0-0
Timestamp: 2026-03-09T18:39:21.178Z
Learning: In apps/meteor/server/methods/addAllUserToRoom.ts, the implementation uses a single cursor pass (Users.find(userFilter).batchSize(100)) that collects both the full user objects (collectedUsers: IUser[]) and their usernames (usernames: string[]) in one iteration. `beforeAddUserToRoom` is then called once with the full usernames batch (preserving batch-validation semantics), and the subsequent subscription/message processing loop iterates over the same stable `collectedUsers` array — no second DB query is made. This avoids any race condition between validation and processing while preserving the original batch-validation behavior.

Applied to files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
📚 Learning: 2026-03-10T08:13:52.153Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39414
File: apps/meteor/app/api/server/v1/rooms.ts:1241-1297
Timestamp: 2026-03-10T08:13:52.153Z
Learning: In the RocketChat/Rocket.Chat OpenAPI migration PRs for endpoints under apps/meteor/app/api/server/v1/rooms.ts, the pattern `ajv.compile<void>({...})` is intentionally used for the 200 response schema even when the endpoint returns `{ success: true }`. This is an established convention across all migrated endpoints (rooms.leave, rooms.favorite, rooms.delete, rooms.muteUser, rooms.unmuteUser). Do not flag this as a type mismatch during reviews of these migration PRs.

Applied to files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2026-03-11T16:46:55.955Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 39535
File: apps/meteor/app/apps/server/bridges/livechat.ts:249-249
Timestamp: 2026-03-11T16:46:55.955Z
Learning: In `apps/meteor/app/apps/server/bridges/livechat.ts`, `createVisitor()` intentionally does not propagate `externalIds` to `registerData`. This is by design: the method is deprecated (JSDoc: `deprecated Use createAndReturnVisitor instead. Note: This method does not support externalIds.`) to push callers toward `createAndReturnVisitor()`, which does support `externalIds`. Do not flag the missing `externalIds` field in `createVisitor()` as a bug.

Applied to files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2026-01-17T01:51:47.764Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38219
File: packages/core-typings/src/cloud/Announcement.ts:5-6
Timestamp: 2026-01-17T01:51:47.764Z
Learning: In packages/core-typings/src/cloud/Announcement.ts, the AnnouncementSchema.createdBy field intentionally overrides IBannerSchema.createdBy (object with _id and optional username) with a string enum ['cloud', 'system'] to match existing runtime behavior. This is documented as technical debt with a FIXME comment at apps/meteor/app/cloud/server/functions/syncWorkspace/handleCommsSync.ts:53 and should not be flagged as an error until the runtime behavior is corrected.

Applied to files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2026-01-26T18:26:01.279Z
Learnt from: d-gubert
Repo: RocketChat/Rocket.Chat PR: 38227
File: apps/meteor/app/api/server/router.ts:44-49
Timestamp: 2026-01-26T18:26:01.279Z
Learning: In apps/meteor/app/api/server/router.ts, when retrieving bodyParams and queryParams from the Hono context via c.get(), do not add defensive defaults (e.g., ?? {}). The code should fail fast if these parameters are missing, as endpoint handlers expect them to be present and breaking here helps surface parsing problems rather than hiding them.

Applied to files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2025-10-06T20:32:23.658Z
Learnt from: d-gubert
Repo: RocketChat/Rocket.Chat PR: 37152
File: packages/apps-engine/tests/test-data/utilities.ts:557-573
Timestamp: 2025-10-06T20:32:23.658Z
Learning: In packages/apps-engine/tests/test-data/utilities.ts, the field name `isSubscripbedViaBundle` in the `IMarketplaceSubscriptionInfo` type should not be flagged as a typo, as it may match the upstream API's field name.

Applied to files:

  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2025-09-25T09:59:26.461Z
Learnt from: Dnouv
Repo: RocketChat/Rocket.Chat PR: 37057
File: packages/apps-engine/src/definition/accessors/IUserRead.ts:23-27
Timestamp: 2025-09-25T09:59:26.461Z
Learning: UserBridge.doGetUserRoomIds in packages/apps-engine/src/server/bridges/UserBridge.ts has a bug where it implicitly returns undefined when the app lacks read permission (missing return statement in the else case of the permission check).

Applied to files:

  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2025-11-19T18:20:37.116Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 37419
File: apps/meteor/server/services/media-call/service.ts:141-141
Timestamp: 2025-11-19T18:20:37.116Z
Learning: In apps/meteor/server/services/media-call/service.ts, the sendHistoryMessage method should use call.caller.id or call.createdBy?.id as the message author, not call.transferredBy?.id. Even for transferred calls, the message should appear in the DM between the two users who are calling each other, not sent by the person who transferred the call.

Applied to files:

  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2026-03-04T14:16:49.202Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 39304
File: packages/ui-contexts/src/ActionManagerContext.ts:26-26
Timestamp: 2026-03-04T14:16:49.202Z
Learning: In `packages/ui-contexts/src/ActionManagerContext.ts` (TypeScript, RocketChat/Rocket.Chat), the `disposeView` method in `IActionManager` uses an intentionally explicit union `UiKit.ModalView['id'] | UiKit.BannerView['viewId'] | UiKit.ContextualBarView['id']` to document which view types are accepted, even though all constituents resolve to the same primitive. The inline `// eslint-disable-next-line typescript-eslint/no-duplicate-type-constituents` comment is intentional and should not be flagged or removed.

Applied to files:

  • packages/rest-typings/src/v1/omnichannel.ts

@amitb0ra amitb0ra force-pushed the refactor/migrate-livechat-users-openapi branch from 5dc4b44 to 2324f5f Compare March 12, 2026 20:25
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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/meteor/app/livechat/imports/server/rest/users.ts (1)

240-254: ⚠️ Potential issue | 🟡 Minor

Unhandled exceptions from removeAgent/removeManager will propagate as 500 errors.

Both functions throw Error('error-invalid-user') when the user is not found. Additionally, they call removeUserFromRolesAsync, which throws MeteorError('error-invalid-user') if validation fails. These exceptions are not caught and will bypass the fallback API.v1.failure('error-removing-user') response, resulting in unhandled 500 errors instead of the declared 400 error response.

Wrap the calls in try-catch to handle these errors gracefully:

Example
try {
    if (await removeAgent(this.urlParams._id)) {
        return API.v1.success();
    }
} catch (error) {
    return API.v1.failure('error-removing-user');
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/meteor/app/livechat/imports/server/rest/users.ts` around lines 240 -
254, The action handler calls removeAgent/removeManager (which can throw
Error('error-invalid-user') and call removeUserFromRolesAsync that may throw
MeteorError) without catching exceptions, causing 500s; wrap the await
removeAgent(this.urlParams._id) and await removeManager(this.urlParams._id)
calls in try-catch blocks inside the action function and on any caught error
return API.v1.failure('error-removing-user') so validation errors are converted
to the intended failure response rather than propagating.
♻️ Duplicate comments (1)
packages/rest-typings/src/v1/omnichannel.ts (1)

4642-4649: ⚠️ Potential issue | 🟠 Major

/v1/livechat/users/user endpoints have no backend handler.

All operations on /v1/livechat/users/user and /v1/livechat/users/user/:_id fail at runtime. The backend implementation only supports type === 'agent' or type === 'manager' and throws Error('Invalid type') for requests with type === 'user', affecting GET list, POST, GET by ID, and DELETE operations.

Remove these endpoint definitions from packages/rest-typings/src/v1/omnichannel.ts or add backend support for the user type in apps/meteor/app/livechat/imports/server/rest/users.ts.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/rest-typings/src/v1/omnichannel.ts` around lines 4642 - 4649, The
REST typings declare endpoints for '/v1/livechat/users/user' and
'/v1/livechat/users/user/:_id' but the backend
(apps/meteor/app/livechat/imports/server/rest/users.ts) only supports type ===
'agent' or 'manager' and throws for 'user'; either remove those endpoint entries
from packages/rest-typings/src/v1/omnichannel.ts, or implement full backend
support for the 'user' type in the users REST handlers (update the request
router/handler in apps/meteor/app/livechat/imports/server/rest/users.ts to
accept type === 'user' for GET list, POST, GET by ID and DELETE, ensure
responses match ILivechatAgent/expected shapes and update any
validation/permission checks), then keep the typings in sync.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/rest-typings/src/v1/omnichannel.ts`:
- Line 4665: Update the POST response type for the livechat agent endpoint to
match the server shape (returning an object with user) by replacing the current
signature POST: (params: { username: string }) => { success: boolean } with a
signature that returns the user object (e.g., POST: (params: { username: string
}) => { user: User } or the appropriate user type used elsewhere); locate the
signature string "POST: (params: { username: string }) => { success: boolean }"
in the omnichannel typings and align it with the manager endpoint's corrected
return type.
- Around line 4639-4648: The POST return type for the endpoints
'/v1/livechat/users/manager' and '/v1/livechat/users/user' is incorrect: update
their POST signatures in the rest typings so they return the user object the
server actually returns (i.e. change POST: (params: { username: string }) => {
success: boolean } to POST: (params: { username: string }) => { user:
ILivechatAgent }), matching the server's postUserResponseSchema and the
ILivechatAgent type used elsewhere.

---

Outside diff comments:
In `@apps/meteor/app/livechat/imports/server/rest/users.ts`:
- Around line 240-254: The action handler calls removeAgent/removeManager (which
can throw Error('error-invalid-user') and call removeUserFromRolesAsync that may
throw MeteorError) without catching exceptions, causing 500s; wrap the await
removeAgent(this.urlParams._id) and await removeManager(this.urlParams._id)
calls in try-catch blocks inside the action function and on any caught error
return API.v1.failure('error-removing-user') so validation errors are converted
to the intended failure response rather than propagating.

---

Duplicate comments:
In `@packages/rest-typings/src/v1/omnichannel.ts`:
- Around line 4642-4649: The REST typings declare endpoints for
'/v1/livechat/users/user' and '/v1/livechat/users/user/:_id' but the backend
(apps/meteor/app/livechat/imports/server/rest/users.ts) only supports type ===
'agent' or 'manager' and throws for 'user'; either remove those endpoint entries
from packages/rest-typings/src/v1/omnichannel.ts, or implement full backend
support for the 'user' type in the users REST handlers (update the request
router/handler in apps/meteor/app/livechat/imports/server/rest/users.ts to
accept type === 'user' for GET list, POST, GET by ID and DELETE, ensure
responses match ILivechatAgent/expected shapes and update any
validation/permission checks), then keep the typings in sync.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4d0d51bb-f461-4fc6-8cf9-bbee1e5e1509

📥 Commits

Reviewing files that changed from the base of the PR and between 5dc4b44 and 2324f5f.

📒 Files selected for processing (3)
  • .changeset/migrate-livechat-users-openapi.md
  • apps/meteor/app/livechat/imports/server/rest/users.ts
  • packages/rest-typings/src/v1/omnichannel.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
  • packages/rest-typings/src/v1/omnichannel.ts
🧠 Learnings (17)
📓 Common learnings
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38974
File: apps/meteor/app/api/server/v1/im.ts:220-221
Timestamp: 2026-02-24T19:09:09.561Z
Learning: In RocketChat/Rocket.Chat OpenAPI migration PRs for apps/meteor/app/api/server/v1 endpoints, maintainers prefer to avoid any logic changes; style-only cleanups (like removing inline comments) may be deferred to follow-ups to keep scope tight.
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39414
File: apps/meteor/app/api/server/v1/rooms.ts:1241-1297
Timestamp: 2026-03-10T08:13:52.153Z
Learning: In the RocketChat/Rocket.Chat OpenAPI migration PRs for endpoints under apps/meteor/app/api/server/v1/rooms.ts, the pattern `ajv.compile<void>({...})` is intentionally used for the 200 response schema even when the endpoint returns `{ success: true }`. This is an established convention across all migrated endpoints (rooms.leave, rooms.favorite, rooms.delete, rooms.muteUser, rooms.unmuteUser). Do not flag this as a type mismatch during reviews of these migration PRs.
Learnt from: ggazzo
Repo: RocketChat/Rocket.Chat PR: 35995
File: apps/meteor/app/api/server/v1/rooms.ts:1107-1112
Timestamp: 2026-02-23T17:53:18.785Z
Learning: In Rocket.Chat PR reviews, maintain strict scope boundaries—when a PR is focused on a specific endpoint (e.g., rooms.favorite), avoid reviewing or suggesting changes to other endpoints that were incidentally refactored (e.g., rooms.invite) unless explicitly requested by maintainers.
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39340
File: apps/meteor/app/api/server/v1/im.ts:1349-1398
Timestamp: 2026-03-12T10:26:26.697Z
Learning: In `apps/meteor/app/api/server/v1/im.ts` (PR `#39340`), the `DmEndpoints` type intentionally includes temporary stub entries for `/v1/im.kick`, `/v1/dm.kick`, `/v1/im.leave`, and `/v1/dm.leave` (using `DmKickProps` and `DmLeaveProps`) even though no route handlers exist for them yet. These stubs were added to preserve type compatibility after removing the original `DmLeaveProps` and related files. They are planned for cleanup in a follow-up PR. Do not flag these as missing implementations when reviewing this file until the follow-up is merged.
📚 Learning: 2026-02-24T19:09:09.561Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38974
File: apps/meteor/app/api/server/v1/im.ts:220-221
Timestamp: 2026-02-24T19:09:09.561Z
Learning: In RocketChat/Rocket.Chat OpenAPI migration PRs for apps/meteor/app/api/server/v1 endpoints, maintainers prefer to avoid any logic changes; style-only cleanups (like removing inline comments) may be deferred to follow-ups to keep scope tight.

Applied to files:

  • .changeset/migrate-livechat-users-openapi.md
  • apps/meteor/app/livechat/imports/server/rest/users.ts
  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2026-02-25T20:10:16.987Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38913
File: packages/ddp-client/src/legacy/types/SDKLegacy.ts:34-34
Timestamp: 2026-02-25T20:10:16.987Z
Learning: In the RocketChat/Rocket.Chat monorepo, packages/ddp-client and apps/meteor do not use TypeScript project references. Module augmentations in apps/meteor (e.g., declare module 'rocket.chat/rest-typings') are not visible when compiling packages/ddp-client in isolation, which is why legacy SDK methods that depend on OperationResult types for OpenAPI-migrated endpoints must remain commented out.

Applied to files:

  • .changeset/migrate-livechat-users-openapi.md
  • apps/meteor/app/livechat/imports/server/rest/users.ts
  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2026-03-03T11:11:48.541Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39230
File: apps/meteor/app/api/server/v1/chat.ts:214-222
Timestamp: 2026-03-03T11:11:48.541Z
Learning: In apps/meteor/server/lib/moderation/reportMessage.ts, the reportMessage function validates that description is not empty or whitespace-only with `if (!description.trim())`. When migrating the chat.reportMessage endpoint to OpenAPI, adding minLength validation to the schema preserves this existing behavior.

Applied to files:

  • .changeset/migrate-livechat-users-openapi.md
📚 Learning: 2026-02-24T19:05:56.710Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 0
File: :0-0
Timestamp: 2026-02-24T19:05:56.710Z
Learning: Rocket.Chat repo context: When a workspace manifest on develop already pins a dependency version (e.g., packages/web-ui-registration → "rocket.chat/ui-contexts": "27.0.1"), a lockfile change in a feature PR that upgrades only that dependency’s resolution is considered a manifest-driven sync and can be kept, preferably as a small "chore: sync yarn.lock with manifests" commit.

Applied to files:

  • .changeset/migrate-livechat-users-openapi.md
📚 Learning: 2026-03-10T08:13:52.153Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39414
File: apps/meteor/app/api/server/v1/rooms.ts:1241-1297
Timestamp: 2026-03-10T08:13:52.153Z
Learning: In the RocketChat/Rocket.Chat OpenAPI migration PRs for endpoints under apps/meteor/app/api/server/v1/rooms.ts, the pattern `ajv.compile<void>({...})` is intentionally used for the 200 response schema even when the endpoint returns `{ success: true }`. This is an established convention across all migrated endpoints (rooms.leave, rooms.favorite, rooms.delete, rooms.muteUser, rooms.unmuteUser). Do not flag this as a type mismatch during reviews of these migration PRs.

Applied to files:

  • .changeset/migrate-livechat-users-openapi.md
  • apps/meteor/app/livechat/imports/server/rest/users.ts
  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2026-03-12T10:26:26.697Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39340
File: apps/meteor/app/api/server/v1/im.ts:1349-1398
Timestamp: 2026-03-12T10:26:26.697Z
Learning: In `apps/meteor/app/api/server/v1/im.ts` (PR `#39340`), the `DmEndpoints` type intentionally includes temporary stub entries for `/v1/im.kick`, `/v1/dm.kick`, `/v1/im.leave`, and `/v1/dm.leave` (using `DmKickProps` and `DmLeaveProps`) even though no route handlers exist for them yet. These stubs were added to preserve type compatibility after removing the original `DmLeaveProps` and related files. They are planned for cleanup in a follow-up PR. Do not flag these as missing implementations when reviewing this file until the follow-up is merged.

Applied to files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2026-03-09T18:39:21.178Z
Learnt from: Harxhit
Repo: RocketChat/Rocket.Chat PR: 39476
File: apps/meteor/server/methods/addAllUserToRoom.ts:0-0
Timestamp: 2026-03-09T18:39:21.178Z
Learning: In apps/meteor/server/methods/addAllUserToRoom.ts, the implementation uses a single cursor pass (Users.find(userFilter).batchSize(100)) that collects both the full user objects (collectedUsers: IUser[]) and their usernames (usernames: string[]) in one iteration. `beforeAddUserToRoom` is then called once with the full usernames batch (preserving batch-validation semantics), and the subsequent subscription/message processing loop iterates over the same stable `collectedUsers` array — no second DB query is made. This avoids any race condition between validation and processing while preserving the original batch-validation behavior.

Applied to files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
📚 Learning: 2026-03-11T16:46:55.955Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 39535
File: apps/meteor/app/apps/server/bridges/livechat.ts:249-249
Timestamp: 2026-03-11T16:46:55.955Z
Learning: In `apps/meteor/app/apps/server/bridges/livechat.ts`, `createVisitor()` intentionally does not propagate `externalIds` to `registerData`. This is by design: the method is deprecated (JSDoc: `deprecated Use createAndReturnVisitor instead. Note: This method does not support externalIds.`) to push callers toward `createAndReturnVisitor()`, which does support `externalIds`. Do not flag the missing `externalIds` field in `createVisitor()` as a bug.

Applied to files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2026-01-17T01:51:47.764Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38219
File: packages/core-typings/src/cloud/Announcement.ts:5-6
Timestamp: 2026-01-17T01:51:47.764Z
Learning: In packages/core-typings/src/cloud/Announcement.ts, the AnnouncementSchema.createdBy field intentionally overrides IBannerSchema.createdBy (object with _id and optional username) with a string enum ['cloud', 'system'] to match existing runtime behavior. This is documented as technical debt with a FIXME comment at apps/meteor/app/cloud/server/functions/syncWorkspace/handleCommsSync.ts:53 and should not be flagged as an error until the runtime behavior is corrected.

Applied to files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2026-01-26T18:26:01.279Z
Learnt from: d-gubert
Repo: RocketChat/Rocket.Chat PR: 38227
File: apps/meteor/app/api/server/router.ts:44-49
Timestamp: 2026-01-26T18:26:01.279Z
Learning: In apps/meteor/app/api/server/router.ts, when retrieving bodyParams and queryParams from the Hono context via c.get(), do not add defensive defaults (e.g., ?? {}). The code should fail fast if these parameters are missing, as endpoint handlers expect them to be present and breaking here helps surface parsing problems rather than hiding them.

Applied to files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/app/livechat/imports/server/rest/users.ts
  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2025-10-06T20:32:23.658Z
Learnt from: d-gubert
Repo: RocketChat/Rocket.Chat PR: 37152
File: packages/apps-engine/tests/test-data/utilities.ts:557-573
Timestamp: 2025-10-06T20:32:23.658Z
Learning: In packages/apps-engine/tests/test-data/utilities.ts, the field name `isSubscripbedViaBundle` in the `IMarketplaceSubscriptionInfo` type should not be flagged as a typo, as it may match the upstream API's field name.

Applied to files:

  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2025-09-25T09:59:26.461Z
Learnt from: Dnouv
Repo: RocketChat/Rocket.Chat PR: 37057
File: packages/apps-engine/src/definition/accessors/IUserRead.ts:23-27
Timestamp: 2025-09-25T09:59:26.461Z
Learning: UserBridge.doGetUserRoomIds in packages/apps-engine/src/server/bridges/UserBridge.ts has a bug where it implicitly returns undefined when the app lacks read permission (missing return statement in the else case of the permission check).

Applied to files:

  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2025-11-19T18:20:37.116Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 37419
File: apps/meteor/server/services/media-call/service.ts:141-141
Timestamp: 2025-11-19T18:20:37.116Z
Learning: In apps/meteor/server/services/media-call/service.ts, the sendHistoryMessage method should use call.caller.id or call.createdBy?.id as the message author, not call.transferredBy?.id. Even for transferred calls, the message should appear in the DM between the two users who are calling each other, not sent by the person who transferred the call.

Applied to files:

  • packages/rest-typings/src/v1/omnichannel.ts
📚 Learning: 2026-03-04T14:16:49.202Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 39304
File: packages/ui-contexts/src/ActionManagerContext.ts:26-26
Timestamp: 2026-03-04T14:16:49.202Z
Learning: In `packages/ui-contexts/src/ActionManagerContext.ts` (TypeScript, RocketChat/Rocket.Chat), the `disposeView` method in `IActionManager` uses an intentionally explicit union `UiKit.ModalView['id'] | UiKit.BannerView['viewId'] | UiKit.ContextualBarView['id']` to document which view types are accepted, even though all constituents resolve to the same primitive. The inline `// eslint-disable-next-line typescript-eslint/no-duplicate-type-constituents` comment is intentional and should not be flagged or removed.

Applied to files:

  • packages/rest-typings/src/v1/omnichannel.ts
🔇 Additional comments (9)
apps/meteor/app/livechat/imports/server/rest/users.ts (8)

10-11: LGTM!

The section header comments are acceptable for code organization and improve readability of the local types/schemas structure.


24-41: LGTM!

The LivechatUsersManagerGETLocalSchema correctly defines all query parameters with appropriate types and nullable settings. The schema matches the TypeScript type definition.


47-56: LGTM!

The POST body schema correctly requires username as a non-nullable string with additionalProperties: false for strict validation.


60-78: LGTM!

The paginated response schema appropriately uses { type: 'object' } for ILivechatAgent items since the type isn't registered in Typia. The comment explaining this is helpful technical documentation.


90-97: LGTM!

The successOnlyResponseSchema follows the established convention of using ajv.compile<void>({...}) for success-only responses. Based on learnings, this pattern is intentionally used across migrated endpoints.


111-167: LGTM!

The GET handler correctly:

  • Uses permissionsRequired: emptyStringArray since permissions are checked inline per type
  • Applies appropriate permission checks for agent vs manager types
  • Returns proper forbidden response with 'error-not-authorized'
  • Defaults onlyAvailable to false which matches the findAgents function signature

169-198: LGTM!

The POST handler correctly validates the body using isPOSTLivechatUsersTypeLocal and returns { user } on success. The view-livechat-manager permission is appropriately required for both agent and manager creation.


200-225: LGTM!

The GET by ID handler correctly:

  • Validates type is either 'agent' or 'manager'
  • Maps type to appropriate role for database query
  • Uses proper projection to limit returned fields
  • Returns nullable user (addresses past review comment about response typing)

The TODO comment at line 223 is appropriate for flagging future improvement.

.changeset/migrate-livechat-users-openapi.md (1)

1-6: LGTM!

The changeset correctly declares minor version bumps for both affected packages. The description accurately summarizes the migration to chained route definitions with AJV validation.

Copy link
Copy Markdown
Contributor

@ahmed-n-abdeltwab ahmed-n-abdeltwab left a comment

Choose a reason for hiding this comment

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

Please update the rest-typings to focus only on the /v1/livechat/users/:type and /v1/livechat/users/:type/:id routes

@amitb0ra amitb0ra requested a review from a team as a code owner March 14, 2026 08:38
Copy link
Copy Markdown
Contributor

@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 14 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/meteor/client/views/omnichannel/agents/AgentInfo.tsx">

<violation number="1" location="apps/meteor/client/views/omnichannel/agents/AgentInfo.tsx:29">
P1: Migrating to `/livechat/users/:type/:_id` introduces a null-return path (`user: null`) that this component does not guard, causing runtime crashes on successful responses for missing/non-agent users.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

…tion

- Migrate livechat/users/:type and livechat/users/:type/:_id from addRoute() to chained .get()/.post()/.delete() pattern
- Add local AJV schemas for query, body, and response validation
- Add ExtractRoutesFromAPI type augmentation for auto-generated Endpoints types
- Remove manual type definitions and schemas from rest-typings
- Update all client consumers to use parameterized route paths
@amitb0ra amitb0ra force-pushed the refactor/migrate-livechat-users-openapi branch from ef08e49 to f1ed33c Compare March 14, 2026 09:04
- Restore original type/variable names (remove Local suffix) per migration rules
- Use $ref: '#/components/schemas/IUser' instead of bare { type: 'object' }
- Revert logic changes: remove forbidden() args, onlyAvailable default, failure() args
- Keep concrete path aliases (/v1/livechat/users/agent, /manager, etc.) in rest-typings
- Revert all client-side file changes (concrete aliases preserved for useEndpoint compatibility)
- Only remove parameterized /v1/livechat/users/:type entries from OmnichannelEndpoints
Copy link
Copy Markdown
Contributor

@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 15 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/rest-typings/src/v1/omnichannel.ts">

<violation number="1" location="packages/rest-typings/src/v1/omnichannel.ts:4655">
P2: `/v1/livechat/users/agent/:_id` GET is typed as non-null, but server route can return `user: null` for missing IDs.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

- Remove /v1/livechat/users/agent, /v1/livechat/users/manager,
  /v1/livechat/users/agent/:_id, /v1/livechat/users/manager/:_id
  concrete aliases from omnichannel.ts
- Types now come solely from ExtractRoutesFromAPI augmentation
  via /v1/livechat/users/:type and /v1/livechat/users/:type/:_id
- Update all client-side useEndpoint/useEndpointMutation calls
  to use parameterized paths with type keys
- Update storybook stories and test mocks accordingly
Copy link
Copy Markdown
Contributor

@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.

2 issues found across 14 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/meteor/client/views/omnichannel/departments/DepartmentAgentsTable/AddAgent.tsx">

<violation number="1" location="apps/meteor/client/views/omnichannel/departments/DepartmentAgentsTable/AddAgent.tsx:22">
P2: Endpoint migration allows `user: null`, but AddAgent still destructures `user` as non-null, causing a runtime crash when agent lookup returns null.</violation>
</file>

<file name="apps/meteor/client/views/omnichannel/agents/AgentInfo.tsx">

<violation number="1" location="apps/meteor/client/views/omnichannel/agents/AgentInfo.tsx:29">
P1: Switched endpoint now allows successful `user: null`, but component still dereferences `data.user` and can crash on not-found responses.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

- AgentInfo.tsx: handle user: null by showing 'User_not_found'
- DepartmentAgentsTable/AddAgent.tsx: guard against null user
- useAgentsList.ts: relax formatAgentItem type for object response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants