
























@@ -240,6 +240,99 @@ describe("stripInlineDirectiveTagsFromMessageForDisplay", () => {
240240content: "plain text",
241241};
242242const result = stripInlineDirectiveTagsFromMessageForDisplay(input);
243-expect(result).toEqual(input);
243+expect(result).toBe(input);
244+});
245+246+test("returns original message reference when no directives are present", () => {
247+const input = {
248+role: "assistant",
249+content: [{ type: "text", text: "plain text without directives" }],
250+};
251+const result = stripInlineDirectiveTagsFromMessageForDisplay(input);
252+expect(result).toBe(input);
253+});
254+255+test("returns original message reference when content has only non-text parts", () => {
256+const input = {
257+role: "assistant",
258+content: [{ type: "image", url: "https://example.test/x.png" }],
259+};
260+const result = stripInlineDirectiveTagsFromMessageForDisplay(input);
261+expect(result).toBe(input);
262+});
263+264+test("preserves unchanged text-part references when only some parts change", () => {
265+const unchangedPart = { type: "text" as const, text: "plain text" };
266+const changedPart = { type: "text" as const, text: "with [[reply_to_current]] tag" };
267+const nonTextPart = { type: "image" as const, url: "https://example.test/x.png" };
268+const input = {
269+role: "assistant",
270+content: [unchangedPart, changedPart, nonTextPart],
271+};
272+const result = stripInlineDirectiveTagsFromMessageForDisplay(input);
273+expect(result).not.toBe(input);
274+const content = result?.content as Array<Record<string, unknown>>;
275+expect(content[0]).toBe(unchangedPart);
276+expect(content[1]).not.toBe(changedPart);
277+expect(content[1]).toEqual({ type: "text", text: "with tag" });
278+expect(content[2]).toBe(nonTextPart);
279+});
280+281+test("preserves trailing references when only the first part changes", () => {
282+const changedPart = { type: "text" as const, text: "first [[reply_to_current]]" };
283+const unchangedText = { type: "text" as const, text: "second" };
284+const unchangedImage = { type: "image" as const, url: "https://example.test/x.png" };
285+const input = {
286+role: "assistant",
287+content: [changedPart, unchangedText, unchangedImage],
288+};
289+const result = stripInlineDirectiveTagsFromMessageForDisplay(input);
290+expect(result).not.toBe(input);
291+const content = result?.content as Array<Record<string, unknown>>;
292+expect(content).toHaveLength(3);
293+expect(content[0]).not.toBe(changedPart);
294+expect(content[0]).toEqual({ type: "text", text: "first " });
295+expect(content[1]).toBe(unchangedText);
296+expect(content[2]).toBe(unchangedImage);
297+});
298+299+test("preserves leading references when only the last part changes", () => {
300+const unchangedText = { type: "text" as const, text: "first" };
301+const unchangedImage = { type: "image" as const, url: "https://example.test/x.png" };
302+const changedPart = { type: "text" as const, text: "last [[reply_to_current]]" };
303+const input = {
304+role: "assistant",
305+content: [unchangedText, unchangedImage, changedPart],
306+};
307+const result = stripInlineDirectiveTagsFromMessageForDisplay(input);
308+expect(result).not.toBe(input);
309+const content = result?.content as Array<Record<string, unknown>>;
310+expect(content).toHaveLength(3);
311+expect(content[0]).toBe(unchangedText);
312+expect(content[1]).toBe(unchangedImage);
313+expect(content[2]).not.toBe(changedPart);
314+expect(content[2]).toEqual({ type: "text", text: "last " });
315+});
316+317+test("preserves arbitrary extra fields on rebuilt text parts", () => {
318+const input = {
319+role: "assistant",
320+content: [
321+{
322+type: "text",
323+text: "with [[reply_to_current]] tag",
324+id: "part-1",
325+cache_control: { type: "ephemeral" },
326+},
327+],
328+};
329+const result = stripInlineDirectiveTagsFromMessageForDisplay(input);
330+const content = result?.content as Array<Record<string, unknown>>;
331+expect(content[0]).toEqual({
332+type: "text",
333+text: "with tag",
334+id: "part-1",
335+cache_control: { type: "ephemeral" },
336+});
244337});
245338});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。