Skip to content

Commit 812de1d

Browse files
szokeptrclaude
andcommitted
fix(server): providers read cited assistant text again
The orchestrator V2 rewrite dropped the expandAssistantCitationsForProvider call, so providers received raw percent-encoded t3-citation:// links. Expand citations inside projectComposerContextForProvider, which every provider-bound user text passes through. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a9e709f commit 812de1d

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

‎docs/internals/composer-context-references.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ links, so a context link is never mistaken for a mention.
6666
records produce a marker but no entry. Unknown kinds emit their payload as JSON.
6767
3. Captured text is data: any `<` that would open or close `t3_context` or `context` is escaped,
6868
so a terminal line or PR comment cannot forge a record.
69+
4. Assistant citation links are expanded too (`expandAssistantCitationsForProvider`).
6970

7071
Attachment bytes travel on the existing attachment channel; the envelope only carries metadata.
71-
Text without references is returned unchanged.
72+
Text without references or citations is returned unchanged.
7273

7374
## Legacy messages
7475

‎packages/shared/src/composerContextReferences.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import {
22
ComposerContextId,
33
type ComposerContextRecord,
44
EnvironmentId,
5+
MessageId,
56
ThreadId,
67
} from "@t3tools/contracts";
78
import { describe, expect, it } from "vite-plus/test";
89

10+
import { serializeAssistantCitation } from "./assistantCitations.ts";
911
import {
1012
ATTACHMENT_ONLY_BOOTSTRAP_PROMPT,
1113
collectComposerContextReferences,
@@ -196,6 +198,31 @@ describe("provider projection", () => {
196198
expect(projected).toContain("- font-size: 12px → 20px");
197199
});
198200

201+
it("expands assistant citations with and without context references", () => {
202+
const citation = serializeAssistantCitation({
203+
version: 1,
204+
environmentId: EnvironmentId.make("env"),
205+
threadId: ThreadId.make("thread"),
206+
messageId: MessageId.make("message"),
207+
text: "Use a mutex here",
208+
comment: "Why not a channel?",
209+
start: 0,
210+
end: 16,
211+
prefix: "",
212+
suffix: "",
213+
});
214+
for (const text of [
215+
`See ${citation} ok`,
216+
`See ${citation} ok [Preview annotation: Checkout](t3-context://v1/preview-annotation/ctx_p)`,
217+
]) {
218+
const projected = projectComposerContextForProvider({ text, records: [] });
219+
expect(projected).not.toContain("t3-citation:");
220+
expect(projected).toContain("See [assistant-quote-1]");
221+
expect(projected).toContain('"text": "Use a mutex here"');
222+
expect(projected).toContain('"comment": "Why not a channel?"');
223+
}
224+
});
225+
199226
it("uses the payload kind when a reference disagrees with its record", () => {
200227
const projected = projectComposerContextForProvider({
201228
text: "[log](t3-context://v1/image/ctx_t)",

‎packages/shared/src/composerContextReferences.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
type ThreadContextRecord,
1111
} from "@t3tools/contracts";
1212

13+
import { expandAssistantCitationsForProvider } from "./assistantCitations.ts";
1314
import { replaceThreadLinks, threadLinkCandidates } from "./threadLinks.ts";
1415

1516
const CONTEXT_PROTOCOL = "t3-context:";
@@ -375,6 +376,13 @@ function formatEnvelopeEntry(
375376
export function projectComposerContextForProvider(input: {
376377
text: string;
377378
records: ReadonlyArray<ComposerContextRecord>;
379+
}): string {
380+
return expandAssistantCitationsForProvider(projectContextReferences(input));
381+
}
382+
383+
function projectContextReferences(input: {
384+
text: string;
385+
records: ReadonlyArray<ComposerContextRecord>;
378386
}): string {
379387
const occurrences = collectComposerContextReferences(input.text);
380388
if (occurrences.length === 0) return input.text;

0 commit comments

Comments
 (0)