Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): preserve rich share state keys and icon titles
zqchris4b6e58a901ba
diff --git a/apps/mobile/src/__tests__/conversationShareImages.test.ts b/apps/mobile/src/__tests__/conversationShareImages.test.tsindex ea6233e9ad..881142899d 100644--- a/apps/mobile/src/__tests__/conversationShareImages.test.ts+++ b/apps/mobile/src/__tests__/conversationShareImages.test.ts@@ -471,6 +471,109 @@ it("exports composed images, values, charts and vectors on both capture paths wiexpect(user[0]!.images!.size).toBe(0); // User-authored examples remain code.});+// Regression: trimming before splitting shifted local-state keys in the iOS exporter.+// The real media preparation and both output builders must agree on visible content (unit).+it("keeps leading-whitespace component keys aligned with edited values and image visibility", async () => {+ const nodes = [+ {+ id: "months",+ kind: "range",+ props: { label: "Months", min: 1, max: 12, default: 1 },+ },+ {+ id: "plan",+ kind: "select",+ props: {+ label: "Plan",+ default: "basic",+ options: [+ { label: "Basic", value: "basic" },+ { label: "Selected plan", value: "chosen" },+ ],+ },+ },+ { id: "details", kind: "details", props: { label: "More", default: false } },+ {+ id: "photo",+ kind: "image",+ parent: "details",+ props: { src: "cindy-media://blobs/edited.png", alt: "Visible photo" },+ },+ ];+ const body =+ "\n```cindy-ui\n" ++ nodes.map((node, index) =>+ JSON.stringify({ version: 1, seq: index + 1, op: "create", ...node }),+ ).join("\n") ++ "\n```\n";+ const load = vi.fn(async () => image);+ const messages = await prepareConversationShareImages(+ [{ clientId: "edited", kind: "assistant", body,+ richValues: { 1: { months: 6, plan: "chosen", details: true } } }],+ load,+ );+ expect(load.mock.calls).toEqual([["cindy-media://blobs/edited.png"]]);+ const colors = {+ ...lightColors, background: lightColors.surface,+ codeSurface: lightColors.chatCodeSurface,+ inlineCode: lightColors.chatInlineCodeText, syntax: {},+ };+ const html = buildConversationShareHtml({+ selectedMessages: messages, allShareableIds: ["edited"], contentWidth: 390, colors,+ });+ const layout = buildConversationShareSvgLayout({+ messages, allShareableIds: ["edited"], width: 390, colors,+ });+ const text = layout.bubbles+ .flatMap((b) => b.textBlocks.flatMap((b) => b.lines)).join("\n");+ for (const output of [html, text]) {+ expect(output).toContain("Months 6");+ expect(output).toContain("Selected plan");+ expect(output).not.toContain("Basic");+ }+ expect(html).toContain(image.uri);+ expect(layout.images).toHaveLength(1);+});++// Regression: a legal name-only icon disappeared from both export paths (unit).+it("exports icon names as fallback titles and preserves explicit labels and text", async () => {+ const nodes = [+ { id: "named", kind: "icon", props: { name: "Info" } },+ {+ id: "labelled", kind: "icon",+ props: { name: "Star", label: "Custom title", text: "Supporting text" },+ },+ ];+ const body =+ "```cindy-ui\n" ++ nodes.map((node, index) =>+ JSON.stringify({ version: 1, seq: index + 1, op: "create", ...node }),+ ).join("\n") ++ "\n```";+ const messages = await prepareConversationShareImages(+ [{ clientId: "icons", kind: "assistant", body }], vi.fn(async () => image),+ );+ const colors = {+ ...lightColors, background: lightColors.surface,+ codeSurface: lightColors.chatCodeSurface,+ inlineCode: lightColors.chatInlineCodeText, syntax: {},+ };+ const html = buildConversationShareHtml({+ selectedMessages: messages, allShareableIds: ["icons"], contentWidth: 390, colors,+ });+ const layout = buildConversationShareSvgLayout({+ messages, allShareableIds: ["icons"], width: 390, colors,+ });+ const text = layout.bubbles+ .flatMap((b) => b.textBlocks.flatMap((b) => b.lines)).join("\n");+ for (const output of [html, text]) {+ expect(output).toContain("Info");+ expect(output).toContain("Custom title");+ expect(output).toContain("Supporting text");+ expect(output).not.toContain("Star");+ }+});+// A selected option label is visible output, even though its stored value is harmless.// Regression guard for the new component projection crossing the existing redaction boundary.it("redacts resolved component content before either capture path renders it", () => {diff --git a/apps/mobile/src/session/conversationShareRichAnswer.ts b/apps/mobile/src/session/conversationShareRichAnswer.tsindex bdad2fd13d..166fbb4913 100644--- a/apps/mobile/src/session/conversationShareRichAnswer.ts+++ b/apps/mobile/src/session/conversationShareRichAnswer.ts@@ -53,6 +53,14 @@ export type ShareMarkdownLayout = (width: number,) => ShareRichLayout;+// Match the live icon title, including legal nodes that only supply a name.+function shareRichTitle(node: RichNode): string {+ return (+ richString(node, "label") ||+ (node.kind === "icon" ? richString(node, "name") : "")+ );+}+/** Read the same document and local values as the conversation. Hidden tabs/details stay hidden. */export function shareRichDocument(source: string, edited?: RichValues) {const doc = new RichAnswerStream().update(source, true);@@ -102,7 +110,7 @@ export function conversationShareReadableBody(),].join("\n"): [- richString(node, "label"),+ shareRichTitle(node),richString(node, "text"),richString(node, "alt"),]@@ -244,7 +252,7 @@ export function layoutConversationShareRichAnswer(innerY = top + margin + pt,innerWidth = Math.max(1, outerWidth - pl - pr);const gap = number("gap", spacing.sm);- const label = richString(node, "label"),+ const label = shareRichTitle(node),current = values[richString(node, "bind", id)];const color =typeof visual.color === "string" ? visual.color : colors.textPrimary;@@ -625,7 +633,7 @@ export function conversationShareRichHtml(}).join(";"),);- const label = richString(node, "label"),+ const label = shareRichTitle(node),current = values[richString(node, "bind", id)];let content = "";if (richCalculationUnavailable(node, values))diff --git a/apps/mobile/src/session/conversationShareWebViewHtml.ts b/apps/mobile/src/session/conversationShareWebViewHtml.tsindex cb52d869a8..0b95f70608 100644--- a/apps/mobile/src/session/conversationShareWebViewHtml.ts+++ b/apps/mobile/src/session/conversationShareWebViewHtml.ts@@ -210,18 +210,18 @@ function buildMessageHtml(if (readable !== redactSensitiveText(readable)) {message = { ...message, body: readable, richValues: undefined };}- const body = (+ // Rich part keys are source offsets into the unmodified conversation body.+ const body =message.kind === "assistant"? message.body- : redactSensitiveText(message.body)- ).trim();+ : redactSensitiveText(message.body).trim();const renderBody = (source: string) =>message.kind === "assistant"? splitRichAnswer(source).map((part) => {if (part.kind === "markdown")return buildSelectableMarkdownFragmentHtml(- redactSensitiveText(part.source),+ redactSensitiveText(part.source).trim(),markdownOptions,);return conversationShareRichHtml(@@ -254,7 +254,7 @@ function buildMessageHtml(: "";const bodyHtml = message.bodyParts? buildBodyPartsHtml(message.bodyParts, markdownOptions)- : body+ : body.trim()? renderBody(body): "";const secondaryHtml = secondaryBody ? renderBody(secondaryBody) : "";