feat(condo): DOMA-13253 add file in ai chat#7678
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds end-to-end file attachment support to AI Chat: client upload hook and UI, attachment display component and styles, send integration with analytics, server-side FileRecord resolution to public URLs, schema validation tests, and i18n strings. ChangesAI Chat Attachment Feature
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c1a935c985
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
Actionable comments posted: 6
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/condo/domains/ai/components/AIChatFile/AIChatDocument.tsx`:
- Around line 72-80: The remove button's aria-label is hardcoded to English;
update the Button in AIChatDocument (the Button with className removeButton and
onClick handler onRemove) to use a localized string instead of the literal
'Remove attachment' by importing/using the app's i18n/intl utility (or
translation hook) and passing the translated value into aria-label so screen
readers receive the localized label.
In `@apps/condo/domains/ai/hooks/useAIChatAttachments.tsx`:
- Around line 192-200: readyAttachments currently falls back to
application/octet-stream because the upload success path only stores { id } in
file.response, so browser-empty RcFile.type values never get a persisted MIME;
update the upload success handler (the code that sets file.response after
upload) to include a mimetype property (e.g., mimeType: file.type ||
serverResponse.mimetype || 'application/octet-stream') and then update the
readyAttachments mapping to prefer file.response.mimeType when present (use
file.type || file.response.mimeType || 'application/octet-stream'); reference
the readyAttachments computation and the upload success assignment that
currently only stores id to locate and change both places.
- Around line 203-214: beforeUpload currently only checks the existing fileList
and lets multiple selected files through, causing uploads to start that exceed
maxAttachments; fix by tracking in-flight/accepted-but-not-yet-added files and
refusing extra files in beforeUpload. Add a ref/state like pendingAcceptedCount
and in beforeUpload check (fileList.filter(f=>f.status!=='error').length +
pendingAcceptedCount >= maxAttachments) and return Upload.LIST_IGNORE when the
cap would be exceeded; increment pendingAcceptedCount when returning true and
decrement it in the upload completion/error handlers (and onRemove). Also keep
the existing size check (maxFileSizeBytes) and ensure customRequest and upload
completion handlers (the code referenced at customRequest and the
completion/error callbacks around line ~271) decrement pendingAcceptedCount so
no orphaned uploads occur.
In `@apps/condo/domains/ai/tasks/executeAIFlow.js`:
- Around line 105-117: Stop resolving files with skipAccessControl; either fetch
the FileRecord using the normal context or explicitly verify ownership before
proceeding: after FileRecord.getOne (where skipAccessControl: true is used)
check a definitive ownership field on the returned fileRecord (e.g.,
fileRecord.createdById or fileRecord.ownerId) against the current actor (from
context.session or the ai flow task owner) and throw an error if they don't
match; alternatively remove context.createContext({ skipAccessControl: true })
and re-run FileRecord.getOne with the regular context so existing ACLs enforce
access; keep the existing modelNames check
(EXECUTION_AI_FLOW_TASK_FILE_MODEL_NAME) and still throw when not matched.
- Around line 129-142: The code currently builds resolvedAttachments using
untrusted request fields (attachment.name, attachment.mimeType,
attachment.size); after resolving fileRecord you must use the canonical stored
metadata from fileRecord (e.g., fileRecord.originalFilename or fileRecord.name,
fileRecord.fileMimeType, fileRecord.size) when constructing resolvedAttachments
and when calling fileAdapter.publicUrl; replace uses of attachment.name,
attachment.mimeType, and attachment.size with the corresponding fileRecord
properties and only include size if fileRecord.size is present so downstream
cannot receive spoofed client-provided metadata.
In `@apps/condo/lang/ru/ru.json`:
- Line 391: The translation string identified by the key
"ai.chat.attachments.tooltip.addFiles" uses lowercase "мб." for the file size
unit; update the value to use the consistent uppercase "МБ" (e.g., "Добавить
файлы (макс. {max} шт., каждый {maxFileSizeMb} МБ)") so it matches other locale
entries and UI copy.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: da74c8f2-ea5f-4491-b3c7-ddcec892ede5
📒 Files selected for processing (14)
apps/condo/domains/ai/components/AIChat/AIChat.module.cssapps/condo/domains/ai/components/AIChat/AIChat.tsxapps/condo/domains/ai/components/AIChat/AIChatMessage.tsxapps/condo/domains/ai/components/AIChatFile/AIChatDocument.module.cssapps/condo/domains/ai/components/AIChatFile/AIChatDocument.tsxapps/condo/domains/ai/components/AIChatFile/index.tsapps/condo/domains/ai/constants.jsapps/condo/domains/ai/hooks/useAIChatAttachments.tsxapps/condo/domains/ai/schema/ExecutionAIFlowTask.test.jsapps/condo/domains/ai/tasks/executeAIFlow.jsapps/condo/domains/common/constants/featureflags.jsapps/condo/lang/en/en.jsonapps/condo/lang/es/es.jsonapps/condo/lang/ru/ru.json
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/condo/domains/ai/components/AIChatFile/AIChatDocument.module.css (1)
28-28: ⚡ Quick winConsider removing
!importantfrom margin override.The
!importantdeclaration is a code smell that suggests the styles are fighting against theTypography.Paragraphcomponent's defaults. Consider usingTypography.Textinstead ofTypography.Paragraphin the component, or applying the margin reset through a more specific selector.♻️ Alternative approach if switching to Typography.Text
If the component can use
Typography.Textsemantically instead ofTypography.Paragraph, the margin override becomes unnecessary:.baseName { flex: 0 1 auto; min-width: 0; - margin-bottom: 0 !important; color: var(--condo-global-color-black); }Then update the component to use
Typography.Textwhich doesn't have default bottom margin.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/condo/domains/ai/components/AIChatFile/AIChatDocument.module.css` at line 28, Remove the `!important` margin override in AIChatDocument.module.css and instead either (A) change the component using this style (AIChatDocument / AIChatFile) to use Typography.Text in place of Typography.Paragraph so no bottom margin reset is needed, or (B) keep using Typography.Paragraph but apply the reset with a more specific selector (e.g., target the component's module class combined with the paragraph element) to override the default without `!important`; update the JSX to match the chosen approach (switch element or selector) and delete the `!important` token from the CSS.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@apps/condo/domains/ai/components/AIChatFile/AIChatDocument.module.css`:
- Line 28: Remove the `!important` margin override in AIChatDocument.module.css
and instead either (A) change the component using this style (AIChatDocument /
AIChatFile) to use Typography.Text in place of Typography.Paragraph so no bottom
margin reset is needed, or (B) keep using Typography.Paragraph but apply the
reset with a more specific selector (e.g., target the component's module class
combined with the paragraph element) to override the default without
`!important`; update the JSX to match the chosen approach (switch element or
selector) and delete the `!important` token from the CSS.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 6896be2b-1252-4c5d-a708-39ca0945cd8d
📒 Files selected for processing (6)
apps/condo/domains/ai/components/AIChatFile/AIChatDocument.module.cssapps/condo/domains/ai/components/AIChatFile/AIChatDocument.tsxapps/condo/domains/ai/hooks/useAIChatAttachments.tsxapps/condo/lang/en/en.jsonapps/condo/lang/es/es.jsonapps/condo/lang/ru/ru.json
🚧 Files skipped from review as they are similar to previous changes (3)
- apps/condo/lang/en/en.json
- apps/condo/domains/ai/components/AIChatFile/AIChatDocument.tsx
- apps/condo/domains/ai/hooks/useAIChatAttachments.tsx
7b69cef to
46e88ca
Compare
| }) | ||
| }) | ||
|
|
||
| describe('Attachments validation', () => { |
There was a problem hiding this comment.
you need to add langfuse datasets too
0bc43df to
95b445c
Compare
95b445c to
0bc43df
Compare
0bc43df to
dd052b5
Compare
3a8de6d to
19f6bf0
Compare
|
* feat(condo): DOMA-13253 add file attachments to ai chat * feat(condo): DOMA-13253 fix lint * feat(condo): DOMA-13253 fix tests * feat(condo): DOMA-13253 small fix after review * feat(condo): DOMA-13253 small fix after review 2



Summary by CodeRabbit
New Features
Validation
Internationalization