Skip to content

Commit 101e5f9

Browse files
fix(web): review comments in question answers reach the agent with their text (pingdotgg#34855)
1 parent 3b732f4 commit 101e5f9

3 files changed

Lines changed: 51 additions & 12 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.test.ts‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
22
import { describe, expect, it } from "vite-plus/test";
33
import { formatInlineContextReference } from "./lib/composerContextReferences";
4-
import { threadContextReference } from "./lib/composerContextRecords";
4+
import { reviewCommentContextRecord, threadContextReference } from "./lib/composerContextRecords";
55
import { threadContextRecord } from "@t3tools/shared/composerContextReferences";
66

77
import {
@@ -27,6 +27,30 @@ describe("projectPendingUserInputAnswer", () => {
2727
);
2828
});
2929

30+
// regression: #28022 a review comment chip in an answer reached the agent as a bare link
31+
it("sends review comment chips with the comment text and diff", () => {
32+
const comment = reviewCommentContextRecord({
33+
id: "file-comment-1",
34+
sectionId: "branch",
35+
sectionTitle: "Changes",
36+
filePath: "notes.md",
37+
startIndex: 2,
38+
endIndex: 2,
39+
rangeLabel: "+2",
40+
text: "Rename this to line two updated",
41+
diff: "@@ -0,0 +2,1 @@\n+line two changed",
42+
fenceLanguage: "diff",
43+
});
44+
const answer = `See my note: ${formatInlineContextReference({
45+
kind: "review-comment",
46+
contextId: comment.contextId,
47+
label: comment.label,
48+
})}`;
49+
const projected = projectPendingUserInputAnswer(answer, [comment]);
50+
expect(projected).toContain("Rename this to line two updated");
51+
expect(projected).toContain("+line two changed");
52+
});
53+
3054
// regression: #18789 answers to pending questions lost exact text and option values
3155
it("preserves option values and exact answer text", () => {
3256
const options = [" first\t", "second"];

‎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)