Skip to content

Commit 2735a1f

Browse files
committed
feat(condo): DOMA-12967 fix comments
1 parent 886a818 commit 2735a1f

6 files changed

Lines changed: 20 additions & 16 deletions

File tree

apps/condo/domains/ai/components/AIChat/AIChat.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,11 @@ export const AIChat: React.FC<AIChatProps> = ({
151151
return
152152
}
153153

154+
const rawAnswer = result.data.result?.answer
154155
const { text: assistantAnswerText, suggestions, suggestionsFailureReason } = parseAssistantAnswer(
155-
result.data.result?.answer ?? noResponseMessage,
156+
rawAnswer?.trim() ? rawAnswer : noResponseMessage,
156157
)
158+
157159
if (suggestionsFailureReason) {
158160
void analytics.track('ai_suggestions_failure', {
159161
reason: suggestionsFailureReason,
@@ -406,16 +408,14 @@ export const AIChat: React.FC<AIChatProps> = ({
406408
if (!activeTurnUserMessageId) return
407409

408410
const container = messagesContainerRef.current
409-
if (!container) return
410-
411411
const onScroll = () => {
412412
clampActiveTurnScroll()
413413
}
414414

415-
container.addEventListener('scroll', onScroll, { passive: true })
415+
container?.addEventListener('scroll', onScroll, { passive: true })
416416
clampActiveTurnScroll()
417417

418-
return () => container.removeEventListener('scroll', onScroll)
418+
return () => container?.removeEventListener('scroll', onScroll)
419419
}, [activeTurnUserMessageId, clampActiveTurnScroll, messages])
420420

421421
useEffect(() => {
@@ -652,7 +652,7 @@ export const AIChat: React.FC<AIChatProps> = ({
652652
inputValue={inputValue}
653653
onInputChange={setInputValue}
654654
onInputKeyDown={handleComposerKeyDown}
655-
onSendMessage={() => void handleSendMessage()}
655+
onSendMessage={handleSendMessage}
656656
placeholder={placeholder}
657657
/>
658658
</div>

apps/condo/domains/ai/components/AIChat/AIChatInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type AIChatInputProps = {
2121
inputValue: string
2222
onInputChange: (nextValue: string) => void
2323
onInputKeyDown: (e: React.KeyboardEvent<HTMLTextAreaElement>) => void
24-
onSendMessage: () => void
24+
onSendMessage: () => void | Promise<void>
2525
placeholder: string
2626
}
2727

apps/condo/domains/ai/components/AIInputNotification.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@
5050
/* Match textarea line breaks after "Apply" (plain text with \n, not Markdown). */
5151
.result-text {
5252
white-space: pre-wrap;
53-
word-break: break-word;
53+
overflow-wrap: break-word;
5454
}

apps/condo/domains/ai/utils/aiAnswerPresenter.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function stripServiceToolCallLines (text: string): string {
6868
}
6969

7070
function stripSuggestionsForDisplay (text: string): string {
71-
const completeBlockMatch = text.match(SUGGESTIONS_BLOCK_REGEX)
71+
const completeBlockMatch = SUGGESTIONS_BLOCK_REGEX.exec(text)
7272
if (completeBlockMatch) {
7373
return text.replace(SUGGESTIONS_BLOCK_REGEX, '').trimEnd()
7474
}
@@ -94,7 +94,7 @@ export function parseAssistantAnswer (answer: string): ParsedAssistantAnswer {
9494
return { text: '', suggestions: [], suggestionsFailureReason: 'missing_block' }
9595
}
9696

97-
const match = answer.match(SUGGESTIONS_BLOCK_REGEX)
97+
const match = SUGGESTIONS_BLOCK_REGEX.exec(answer)
9898
if (!match) {
9999
const hasSuggestionMarkers = answer.includes(SUGGESTIONS_OPEN_PREFIX) || answer.includes(SUGGESTIONS_CLOSE_PREFIX)
100100
return {
@@ -120,11 +120,16 @@ export function parseAssistantAnswer (answer: string): ParsedAssistantAnswer {
120120
|| textWithoutSuggestions.includes(SUGGESTIONS_CLOSE_PREFIX)
121121
const parsedSuggestions = suggestions.slice(0, 3)
122122

123+
let suggestionsFailureReason: SuggestionsFailureReason | undefined
124+
if (hasLeakedServiceText) {
125+
suggestionsFailureReason = 'service_text_leaked'
126+
} else if (parsedSuggestions.length === 0) {
127+
suggestionsFailureReason = 'empty_after_parse'
128+
}
129+
123130
return {
124131
text: textWithoutSuggestions,
125132
suggestions: parsedSuggestions,
126-
suggestionsFailureReason: hasLeakedServiceText
127-
? 'service_text_leaked'
128-
: (parsedSuggestions.length === 0 ? 'empty_after_parse' : undefined),
133+
suggestionsFailureReason,
129134
}
130135
}

apps/condo/domains/news/components/NewsForm/InputStep/InputStepForm.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,7 @@ const DefaultAiTextArea: React.FC<DefaultAiTextAreaProps> = ({
172172
})
173173

174174
useEffect(() => {
175-
if (rewriteNewsTextData?.result?.answer) {
176-
setRewriteNewsText(rewriteNewsTextData.result.answer)
177-
}
175+
setRewriteNewsText(rewriteNewsTextData?.result?.answer ?? '')
178176
}, [rewriteNewsTextData?.result?.answer])
179177

180178
useEffect(() => {

packages/messaging/hooks/useMessagingSubscription.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ export const useMessagingSubscription = <T = unknown>(options: UseMessagingSubsc
200200
try {
201201
connection.publish(`${RELAY_UNSUBSCRIBE_PREFIX}.${userId}.${currentRelayId}`)
202202
} catch {
203+
// connection may already be closed
203204
}
204205
}
205206
if (inboxSub) {

0 commit comments

Comments
 (0)