Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(protocol): 同步公开插件分享的图标字段

liugaoweicd71d4263366
diff --git a/packages/plugin-protocol/src/__tests__/publicPresentation.test.ts b/packages/plugin-protocol/src/__tests__/publicPresentation.test.ts
index 55f55f1527..5ebd3e7d13 100644
--- a/packages/plugin-protocol/src/__tests__/publicPresentation.test.ts
+++ b/packages/plugin-protocol/src/__tests__/publicPresentation.test.ts
@@ -26,6 +26,19 @@ describe("public plugin presentation boundary", () => {
}),
).toEqual(publicView);
});
+ it("preserves an embedded current plugin icon without exposing its storage location", () => {
+ const icon = "data:image/png;base64,iVBORw0KGgo=";
+ expect(parsePublicPluginPresentation({ ...publicView, icon })).toEqual({ ...publicView, icon });
+ expect(parsePublicPluginPresentation({ ...publicView, icon: null }).icon).toBeNull();
+ });
+ it.each([
+ "https://example.test/icon.png",
+ "data:image/svg+xml;base64,PHN2Zz48L3N2Zz4=",
+ "data:image/png;base64,invalid!",
+ `data:image/png;base64,${"A".repeat(700_000)}`,
+ ])("uses the missing-icon state for an unsafe or oversized image", (icon) => {
+ expect(parsePublicPluginPresentation({ ...publicView, icon }).icon).toBeNull();
+ });
it.each([
{ schemaVersion: 2 },
{ pluginId: "../../private" },
diff --git a/packages/plugin-protocol/src/publicPresentation.ts b/packages/plugin-protocol/src/publicPresentation.ts
index 071f21811b..f0fa0d27b3 100644
--- a/packages/plugin-protocol/src/publicPresentation.ts
+++ b/packages/plugin-protocol/src/publicPresentation.ts
@@ -15,6 +15,8 @@ export interface PublicPluginPresentation {
author: string | null;
version: string;
publishedAt: string;
+ /** Current verified raster icon, embedded without a storage URL; absent on older servers. */
+ icon?: string | null;
}
export function parsePublicPluginPresentation(
@@ -26,6 +28,11 @@ export function parsePublicPluginPresentation(
}
const nullableText = (value: unknown, path: string, max: number) =>
value === null || value === "" ? null : string(value, path, max);
+ const image = typeof row.icon === "string" && row.icon.length <= Math.ceil(512 * 1024 / 3) * 4 + 32
+ ? /^data:image\/(png|jpeg|webp|gif);base64,([A-Za-z0-9+/]+={0,2})$/.exec(row.icon) : null;
+ const base64 = image?.[2] ?? "";
+ const size = base64.length / 4 * 3 - (base64.endsWith("==") ? 2 : base64.endsWith("=") ? 1 : 0);
+ const icon = image && base64.length % 4 === 0 && size <= 512 * 1024 ? row.icon as string : null;
return {
schemaVersion: 1,
pluginId: row.pluginId,
@@ -34,5 +41,6 @@ export function parsePublicPluginPresentation(
author: nullableText(row.author, "author", 256),
version: string(row.version, "version", 128),
publishedAt: isoDate(row.publishedAt, "publishedAt"),
+ ...(row.icon === undefined ? {} : { icon }),
};
}