Skip to content

Commit 9cea105

Browse files
fix(web): review comments in question answers reach the agent with their text
Answers to a pending question only expanded thread chips, so a Diff panel comment added to an answer reached the agent as a bare t3-context link. The comment record lives in the thread's main draft, not the question's draft. Submitting an answer now looks review comments up there and expands each chip into the same context entry a normal message carries (comment text and diff). Fixes #28022 AI-assisted; verified with the tests and tools listed above.
1 parent fcd2f93 commit 9cea105

2 files changed

Lines changed: 26 additions & 11 deletions

File tree

‎apps/web/src/components/chat/usePendingThreadRequests.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { useShallow } from "zustand/react/shallow";
2222
import { type DraftId, useComposerDraftStore } from "../../composerDraftStore";
2323
import { useStableCallback } from "../../hooks/useStableCallback";
2424
import { getUploadedAttachments, useAttachmentUploadStore } from "../../lib/attachmentUploadQueue";
25+
import { reviewCommentContextRecord } from "../../lib/composerContextRecords";
2526
import {
2627
buildPendingUserInputAnswers,
2728
setPendingUserInputCustomAnswer,
@@ -287,6 +288,10 @@ export function usePendingThreadRequests(input: {
287288
if (userInputResponsesInFlight.current.has(responseKey)) return;
288289
const attachmentsByQuestionId = new Map<string, UserInputAttachments[string]>();
289290
const providerAnswers = { ...answers };
291+
// Diff comments land in the thread draft even when their chip is in an answer.
292+
const reviewCommentRecords = (
293+
useComposerDraftStore.getState().getComposerDraft(composerDraftTarget)?.reviewComments ?? []
294+
).map(reviewCommentContextRecord);
290295
for (const question of pendingInput.questions) {
291296
const target = questionAttachmentDraftId(
292297
environmentId,
@@ -296,10 +301,10 @@ export function usePendingThreadRequests(input: {
296301
);
297302
if ((useQuestionAttachmentPreparation.getState().counts[target] ?? 0) > 0) return;
298303
const draft = useComposerDraftStore.getState().getComposerDraft(target);
299-
providerAnswers[question.id] = projectPendingUserInputAnswer(
300-
answers[question.id],
301-
draft?.threadContexts ?? [],
302-
);
304+
providerAnswers[question.id] = projectPendingUserInputAnswer(answers[question.id], [
305+
...(draft?.threadContexts ?? []),
306+
...reviewCommentRecords,
307+
]);
303308
const attachments = draft ? [...draft.images, ...draft.files] : [];
304309
if (attachments.length === 0) continue;
305310
const uploaded = getUploadedAttachments({ environmentId, images: attachments });

‎apps/web/src/pendingUserInput.ts‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
import type { ThreadContextRecord, UserInputQuestion } from "@t3tools/contracts";
2-
import { replaceComposerContextReferences } from "@t3tools/shared/composerContextReferences";
1+
import type {
2+
ReviewCommentContextRecord,
3+
ThreadContextRecord,
4+
UserInputQuestion,
5+
} from "@t3tools/contracts";
6+
import {
7+
projectComposerContextForProvider,
8+
replaceComposerContextReferences,
9+
} from "@t3tools/shared/composerContextReferences";
310
import { formatThreadLink } from "@t3tools/shared/threadLinks";
411
import {
512
buildPendingUserInputAnswers,
@@ -13,13 +20,16 @@ import { collectInlineContextIds } from "./lib/composerContextReferences";
1320

1421
export function projectPendingUserInputAnswer(
1522
answer: unknown,
16-
threadContexts: ReadonlyArray<ThreadContextRecord>,
23+
records: ReadonlyArray<ThreadContextRecord | ReviewCommentContextRecord>,
1724
) {
18-
if (typeof answer !== "string" || threadContexts.length === 0) return answer;
19-
const recordsById = new Map(threadContexts.map((record) => [record.contextId, record]));
25+
if (typeof answer !== "string" || records.length === 0) return answer;
26+
const recordsById = new Map(records.map((record) => [record.contextId, record]));
2027
return replaceComposerContextReferences(answer, (reference) => {
21-
const record = reference.kind === "thread" ? recordsById.get(reference.contextId) : undefined;
22-
return record ? formatThreadLink(record, reference.label) : reference.source;
28+
const record = recordsById.get(reference.contextId);
29+
if (record?.kind !== reference.kind) return reference.source;
30+
return record.kind === "thread"
31+
? formatThreadLink(record, reference.label)
32+
: projectComposerContextForProvider({ text: reference.source, records: [record] });
2333
});
2434
}
2535

0 commit comments

Comments
 (0)