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。

feat(plugins): 插件工具结果可附图片,模型调用一次就能看到截图

Dash31a24bb2b3f6
diff --git a/apps/desktop/resources/system-skills/cindy-plugin-creator/references/plugin-runtime.md b/apps/desktop/resources/system-skills/cindy-plugin-creator/references/plugin-runtime.md
index 9820f50d88..bccf547e85 100644
--- a/apps/desktop/resources/system-skills/cindy-plugin-creator/references/plugin-runtime.md
+++ b/apps/desktop/resources/system-skills/cindy-plugin-creator/references/plugin-runtime.md
@@ -58,6 +58,24 @@ cindy.send({
message: '删除需要确认,请传 confirm:true 后重试',
});
+// 给模型看的图片:工具的用途就是让当前 Agent「看一眼」时(截图、渲染预览、
+// 图表快照),在 tool-result **顶层**(与 result 平级,不要放进 result)附 images,
+// 主机把它们作为图片内容放在结果文字之后交给模型,省掉模型再去读文件的一步:
+cindy.send({ type: 'tool-result', callId: msg.callId, ok: true,
+ result: { path: '/…/shot.jpg', width: 402, height: 874 }, // 文字照常给
+ images: [{ data: '<base64>' }], // 最多 2 张
+});
+// - 格式由主机按字节判定,只收 PNG / JPEG / WebP / GIF(不收 SVG),单张解码后
+// ≤6MB;无效项静默丢弃。一次结果里所有图合计约 140KB:小于份额的原样交给
+// 模型,超出的由主机重新编码(可能缩小像素尺寸),仍放不下的不附,结果里会多
+// images_omitted:N。图上的像素若有含义(例如可直接点击的坐标),自己先压到
+// 份额以内,别让主机替你缩放。
+// - 每张图都占模型上下文(几百到一千多 token)且留在对话里:只在 Agent 明确要看
+// 时附,自动附带的观察结果给路径即可。
+// - 图片只交给模型和本次工具步骤展示,不入媒体库、不进产物账本、不会自动发到
+// IM;要交付给用户的产物仍走上面的 xdt_image_urls 等媒体字段。
+// - 旧版 Cindy 不认这个字段,会直接忽略:result 里仍要给出够用的文字或路径。
+
// 长任务续命(超时窗口默认 330s,从派发起算绝对上限 30 分钟):
// - 经 cindy-request 请主机代办且带 callId 的署名单(出图/视频)在途时,
// 主机**自动**替这份卷续命,你不用做任何事;
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/ghostModelImages.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/ghostModelImages.test.ts
new file mode 100644
index 0000000000..07559f2f2a
--- /dev/null
+++ b/apps/desktop/src/main/cindy-brain/__tests__/ghostModelImages.test.ts
@@ -0,0 +1,49 @@
+import { describe, it, expect, vi } from 'vitest';
+
+import {
+ GHOST_MODEL_IMAGE_MAX_COUNT,
+ fitGhostModelImages,
+ normalizeGhostModelImages,
+} from '../ghostModelImages';
+
+const PNG = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0, 0, 0, 13]).toString('base64');
+const JPEG = Buffer.from([0xff, 0xd8, 0xff, 0xe0, 1, 2, 3]).toString('base64');
+const SVG = Buffer.from('<svg xmlns="http://www.w3.org/2000/svg"></svg>').toString('base64');
+
+describe('normalizeGhostModelImages', () => {
+ it('keeps PNG and JPEG with the format sniffed from the bytes, not the claimed type', () => {
+ const { images, dropped } = normalizeGhostModelImages([{ data: PNG, mimeType: 'image/jpeg' }, { data: JPEG }]);
+ expect(images.map((i) => i.mimeType)).toEqual(['image/png', 'image/jpeg']);
+ expect(dropped).toBe(0);
+ });
+
+ it('drops SVG, text, malformed base64, non-objects and anything past the limit', () => {
+ const many = Array.from({ length: GHOST_MODEL_IMAGE_MAX_COUNT + 1 }, () => ({ data: PNG }));
+ expect(normalizeGhostModelImages(many).images).toHaveLength(GHOST_MODEL_IMAGE_MAX_COUNT);
+ expect(normalizeGhostModelImages(many).dropped).toBe(1);
+ expect(normalizeGhostModelImages([{ data: SVG }, { data: 'not base64!' }, { data: '' }, null, 'x']).images).toEqual([]);
+ expect(normalizeGhostModelImages({ data: PNG })).toEqual({ images: [], dropped: 1 });
+ expect(normalizeGhostModelImages(undefined)).toEqual({ images: [], dropped: 0 });
+ });
+});
+
+describe('fitGhostModelImages', () => {
+ it('passes small images through untouched and shares the budget between images', async () => {
+ const compress = vi.fn();
+ const small = { data: Buffer.alloc(100, 1).toString('base64'), mimeType: 'image/png' };
+ expect(await fitGhostModelImages([small], compress, 1000)).toEqual({ images: [small], omitted: 0 });
+ expect(compress).not.toHaveBeenCalled();
+ const big = { data: Buffer.alloc(800, 1).toString('base64'), mimeType: 'image/png' };
+ compress.mockResolvedValue({ buffer: Buffer.alloc(400), mime: 'image/webp' });
+ const fitted = await fitGhostModelImages([small, big], compress, 1000);
+ expect(compress).toHaveBeenCalledWith(expect.any(Buffer), 'image/png', { targetBytes: 500 });
+ expect(fitted.images.map((i) => i.mimeType)).toEqual(['image/png', 'image/webp']);
+ });
+
+ it('leaves out an image that cannot be made small enough, and counts it', async () => {
+ const big = { data: Buffer.alloc(2000, 1).toString('base64'), mimeType: 'image/jpeg' };
+ expect(await fitGhostModelImages([big], vi.fn().mockResolvedValue(null), 1000)).toEqual({ images: [], omitted: 1 });
+ expect(await fitGhostModelImages([big], vi.fn().mockResolvedValue({ buffer: Buffer.alloc(1500), mime: 'image/webp' }), 1000))
+ .toEqual({ images: [], omitted: 1 });
+ });
+});
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/pipeDispatcher.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/pipeDispatcher.test.ts
index c074248f09..7065f87319 100644
--- a/apps/desktop/src/main/cindy-brain/__tests__/pipeDispatcher.test.ts
+++ b/apps/desktop/src/main/cindy-brain/__tests__/pipeDispatcher.test.ts
@@ -106,6 +106,27 @@ describe('mail reader opening intent', () => {
});
});
+describe('images shown to the model', () => {
+ const PNG = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0, 0, 0, 13]).toString('base64');
+
+ it('accepts top-level images next to result and drops invalid ones', async () => {
+ const h = makeHarness();
+ const pending = h.dispatcher.callGhostTool({ ghostId: 'art', tool: 'gen_image', args: {} });
+ h.dispatcher.handleToolResult('art', { callId: h.sent[0].callId, ok: true, result: { path: '/x.jpg' }, images: [{ data: PNG }, { data: 'nope!' }] });
+ expect(await pending).toEqual({ ok: true, result: { path: '/x.jpg' }, images: [{ data: PNG, mimeType: 'image/png' }] });
+ });
+
+ it('a result without images, or a failure, is unchanged', async () => {
+ const h = makeHarness();
+ const plain = h.dispatcher.callGhostTool({ ghostId: 'art', tool: 'gen_image', args: {} });
+ h.dispatcher.handleToolResult('art', { callId: h.sent[0].callId, ok: true, result: 'r' });
+ expect(await plain).toEqual({ ok: true, result: 'r' });
+ const failed = h.dispatcher.callGhostTool({ ghostId: 'art', tool: 'gen_image', args: {} });
+ h.dispatcher.handleToolResult('art', { callId: h.sent[1].callId, ok: false, errorCode: 'INVALID_ARGS', message: 'bad', images: [{ data: PNG }] });
+ expect(await failed).toEqual({ ok: false, errorCode: 'INVALID_ARGS', message: 'bad' });
+ });
+});
+
describe('caller cancellation', () => {
it('Host Stop affects only opted-in calls in that session, preserving legacy calls', async () => {
const h = makeHarness();
diff --git a/apps/desktop/src/main/cindy-brain/ghostModelImages.ts b/apps/desktop/src/main/cindy-brain/ghostModelImages.ts
new file mode 100644
index 0000000000..9d3c61f28d
--- /dev/null
+++ b/apps/desktop/src/main/cindy-brain/ghostModelImages.ts
@@ -0,0 +1,90 @@
+/**
+ * Images a plugin asks to show the model with its tool result.
+ *
+ * A plugin's logic page may add a top-level `images: [{ data: <base64> }]` to its
+ * `tool-result` message (next to `result`, never inside it, so hosts that do not
+ * know the field drop it instead of pasting base64 into the model's context).
+ * The host checks every image here, re-encodes it under the inline budget and
+ * ghost_call returns it as MCP image content after the JSON text.
+ *
+ * The bytes decide the format: only PNG, JPEG, WebP and GIF are accepted, never
+ * a type the plugin claims. Images are not added to the media library or the
+ * per-call media ledger, so they are never delivered to IM by themselves.
+ */
+import type { GhostModelImage } from '../../shared/ghost.js';
+import { sniffMediaMime } from '../cindy-media/sniffMediaMime.js';
+
+export const GHOST_MODEL_IMAGE_MAX_COUNT = 2;
+/** Decoded bytes per image before re-encoding. */
+export const GHOST_MODEL_IMAGE_MAX_BYTES = 6 * 1024 * 1024;
+/**
+ * Total bytes of inline images in one ghost_call result. Same value and reason
+ * as `INLINE_IMAGE_TARGET_BYTES` in @cindy/mcps: Claude Code writes stream-json
+ * lines over 256 KiB in chunks that other output can interleave with.
+ */
+export const GHOST_MODEL_IMAGE_BUDGET_BYTES = 140_000;
+
+const MODEL_IMAGE_MIMES = new Set(['image/png', 'image/jpeg', 'image/webp', 'image/gif']);
+const BASE64 = /^[A-Za-z0-9+/]+={0,2}$/;
+const MAX_BASE64_LENGTH = Math.ceil(GHOST_MODEL_IMAGE_MAX_BYTES / 3) * 4;
+
+/** Keep the valid images (at most the limit); report how many were dropped. */
+export function normalizeGhostModelImages(raw: unknown): { images: GhostModelImage[]; dropped: number } {
+ if (raw === undefined || raw === null) return { images: [], dropped: 0 };
+ if (!Array.isArray(raw)) return { images: [], dropped: 1 };
+ const images: GhostModelImage[] = [];
+ let dropped = 0;
+ for (const item of raw) {
+ const data = (item as { data?: unknown } | null)?.data;
+ if (images.length >= GHOST_MODEL_IMAGE_MAX_COUNT || typeof data !== 'string' || data.length === 0
+ || data.length > MAX_BASE64_LENGTH || !BASE64.test(data)) {
+ dropped++;
+ continue;
+ }
+ const bytes = Buffer.from(data, 'base64');
+ const mimeType = sniffMediaMime(bytes);
+ if (!bytes.byteLength || bytes.byteLength > GHOST_MODEL_IMAGE_MAX_BYTES || !mimeType || !MODEL_IMAGE_MIMES.has(mimeType)) {
+ dropped++;
+ continue;
+ }
+ images.push({ data: bytes.toString('base64'), mimeType });
+ }
+ return { images, dropped };
+}
+
+export type CompressModelImage = (
+ buffer: Buffer,
+ mime: string,
+ opts: { targetBytes: number },
+) => Promise<{ buffer: Buffer; mime: string } | null>;
+
+/**
+ * Fit the images into the inline budget, sharing it equally. An image that is
+ * already small enough is passed through untouched (its pixel size is part of
+ * what it shows); a larger one is re-encoded, and one that still does not fit is
+ * left out and counted.
+ */
+export async function fitGhostModelImages(
+ images: GhostModelImage[],
+ compress: CompressModelImage,
+ budget = GHOST_MODEL_IMAGE_BUDGET_BYTES,
+): Promise<{ images: GhostModelImage[]; omitted: number }> {
+ if (!images.length) return { images: [], omitted: 0 };
+ const share = Math.floor(budget / images.length);
+ const out: GhostModelImage[] = [];
+ let omitted = 0;
+ for (const image of images) {
+ const buffer = Buffer.from(image.data, 'base64');
+ if (buffer.byteLength <= share) {
+ out.push(image);
+ continue;
+ }
+ const smaller = await compress(buffer, image.mimeType, { targetBytes: share }).catch(() => null);
+ if (smaller && smaller.buffer.byteLength <= share) {
+ out.push({ data: smaller.buffer.toString('base64'), mimeType: smaller.mime });
+ } else {
+ omitted++;
+ }
+ }
+ return { images: out, omitted };
+}
diff --git a/apps/desktop/src/main/cindy-brain/pipeDispatcher.ts b/apps/desktop/src/main/cindy-brain/pipeDispatcher.ts
index 8c39898f16..517949f735 100644
--- a/apps/desktop/src/main/cindy-brain/pipeDispatcher.ts
+++ b/apps/desktop/src/main/cindy-brain/pipeDispatcher.ts
@@ -30,6 +30,7 @@ import { GHOST_PIPE_CALL_MAX_TOTAL_MS, isGhostPluginErrorCode } from '../../shar
import { installedGhostStoragePart } from '../../shared/pluginIdentity.js';
import type { GhostRuntimeState } from './runtime/GhostRuntime.js';
import { isGhostOwnerScopeUsable, type GhostOwnerScope } from './ghostOwnerScope.js';
+import { normalizeGhostModelImages } from './ghostModelImages.js';
import type { PluginUsageOutcome } from '../../shared/pluginUsage.js';
/** Internal observation only; no parameters or result bodies leave the dispatcher. */
@@ -513,6 +514,7 @@ export class GhostPipeDispatcher {
callId?: unknown;
ok?: unknown;
result?: unknown;
+ images?: unknown;
errorCode?: unknown;
message?: unknown;
};
@@ -536,8 +538,13 @@ export class GhostPipeDispatcher {
this.settle(p.callId, this.ownerBoundaryResult());
return { accepted: false, reason: '账号边界已变化' };
}
+ // Images for the model ride next to `result`; invalid ones are dropped here.
+ const shown = p.ok ? normalizeGhostModelImages(p.images) : { images: [], dropped: 0 };
+ if (shown.dropped) {
+ this.deps.log?.warn('ghost tool result images dropped', { callId: p.callId, dropped: shown.dropped });
+ }
const result: GhostToolCallResult = p.ok
- ? { ok: true, result: p.result ?? null }
+ ? { ok: true, result: p.result ?? null, ...(shown.images.length ? { images: shown.images } : {}) }
: {
ok: false,
errorCode: isGhostPluginErrorCode(p.errorCode) ? p.errorCode : 'INTERNAL',
diff --git a/apps/desktop/src/main/mcp-integrations/__tests__/ghostWorkdirGate.test.ts b/apps/desktop/src/main/mcp-integrations/__tests__/ghostWorkdirGate.test.ts
index c4a23d767c..c831eae835 100644
--- a/apps/desktop/src/main/mcp-integrations/__tests__/ghostWorkdirGate.test.ts
+++ b/apps/desktop/src/main/mcp-integrations/__tests__/ghostWorkdirGate.test.ts
@@ -1390,7 +1390,7 @@ describe('花名册 / ghost_list 过滤', () => {
ghost_id: discovered.id,
...(Object.hasOwn(discovered, 'namespace') ? { namespace: discovered.namespace } : {}),
};
- const called = JSON.parse((await handleGhostCall(deps, { ...target, tool: 'run' })).content[0].text);
+ const called = JSON.parse(((await handleGhostCall(deps, { ...target, tool: 'run' })).content[0] as { text: string }).text);
expect(called).toMatchObject({ ok: true, result: 'done' });
const manual = JSON.parse((await handleGhostManual(deps, target)).content[0].text);
expect(manual).toMatchObject({ ok: true, manual: [{ name: 'guide' }] });
@@ -1417,7 +1417,7 @@ describe('花名册 / ghost_list 过滤', () => {
const target = { ghost_id: discovered.id, namespace: discovered.namespace };
const info = JSON.parse((await handleGhostInfo(deps, target)).content[0].text);
expect(info).toMatchObject({ ok: true, ghost: { id: 'art', namespace: discovered.namespace } });
- expect(JSON.parse((await handleGhostCall(deps, { ...target, tool: 'run' })).content[0].text))
+ expect(JSON.parse(((await handleGhostCall(deps, { ...target, tool: 'run' })).content[0] as { text: string }).text))
.toMatchObject({ ok: true, result: 'done' });
}
expect(dispatchMock).toHaveBeenNthCalledWith(1, expect.objectContaining({ ghostId: '_root__art' }));
diff --git a/apps/desktop/src/main/mcp-integrations/ghost.ts b/apps/desktop/src/main/mcp-integrations/ghost.ts
index 2261d51adb..86448b7612 100644
--- a/apps/desktop/src/main/mcp-integrations/ghost.ts
+++ b/apps/desktop/src/main/mcp-integrations/ghost.ts
@@ -82,6 +82,7 @@ import {
deriveGhostSessionContext,
ghostInstallApprovalToken,
type GhostSessionContextInjected,
+ type GhostToolCallResult,
type GhostSetupAssessment,
type InstalledGhost,
} from '../../shared/ghost.js';
@@ -94,6 +95,8 @@ import {
resolveInstalledGhost,
} from '../../shared/pluginIdentity.js';
import { withCardToken } from '../cindy-brain/cardService.js';
+import { fitGhostModelImages } from '../cindy-brain/ghostModelImages.js';
+import { compressInlineImage } from './inlineImageCompressor.js';
import { drainGhostCallMedia } from '../cindy-brain/ghostMediaLedger.js';
import {
getGhostCardService,
@@ -2406,13 +2409,23 @@ export function getCindyGhostsMcpDeps(
// 失败也 drain(清账防泄漏),但只在成功结果上附带——cindy-tools 层
// 在意识未声明媒体字段时以 xdt_media_produced 注入,兜底 IM/hook 送达。
const producedMedia = drainGhostCallMedia(instanceId, callId);
- const finalized = withCardToken(result, cardService.finalizeCall(callId), callId);
+ // Images the plugin shows the model stay out of the card and media-ledger
+ // path (never stored, never sent to IM): fit them into the inline budget
+ // and let ghost_call return them as image content (ghostModelImages.ts).
+ const requestedImages = result.ok ? result.images : undefined;
+ const plainResult: GhostToolCallResult = result.ok && result.images ? { ok: true, result: result.result } : result;
+ const finalized = withCardToken(plainResult, cardService.finalizeCall(callId), callId);
if (!finalized.ok) return finalized;
+ const fitted = requestedImages?.length ? await fitGhostModelImages(requestedImages, compressInlineImage) : null;
+ const modelImages = {
+ ...(fitted?.images.length ? { images: fitted.images } : {}),
+ ...(fitted?.omitted ? { imagesOmitted: fitted.omitted } : {}),
+ };
// 附最后一道 gate(postCtx)的快照:它是派发前最新的 ready 判定。
const advisory = postCtxAssessment.reauthSuggest ? { setup: postCtxAssessment } : {};
const base = producedMedia.length > 0
- ? { ...finalized, ...advisory, producedMedia }
- : { ...finalized, ...advisory };
+ ? { ...finalized, ...advisory, producedMedia, ...modelImages }
+ : { ...finalized, ...advisory, ...modelImages };
// 视觉桥工具结果图片描述(最佳努力,不阻塞):把工具返回的 cindy-media://
// 图片 URL 转成文字描述,附加为 xdt_media_descriptions——纯文本模型
// (deepseek 等)拿不到 image block,只能看到 URL 文本,易幻觉编造图片
diff --git a/apps/desktop/src/shared/ghost.ts b/apps/desktop/src/shared/ghost.ts
index fd27558735..c6827abafb 100644
--- a/apps/desktop/src/shared/ghost.ts
+++ b/apps/desktop/src/shared/ghost.ts
@@ -8963,8 +8963,17 @@ export function isGhostPluginErrorCode(value: unknown): value is string {
}
/** 工具调用结果(主机侧;ghost 总机 MCP 原样透传给 agent)。 */
+/**
+ * An image a plugin shows the model with its tool result (top-level `images` of
+ * the `tool-result` message). `mimeType` is sniffed from the bytes by the host.
+ */
+export interface GhostModelImage {
+ data: string;
+ mimeType: string;
+}
+
export type GhostToolCallResult =
- | { ok: true; result: unknown }
+ | { ok: true; result: unknown; images?: GhostModelImage[] }
| { ok: false; errorCode: GhostToolCallErrorCode | (string & {}); message: string };
/**
diff --git a/packages/cindy-tools/src/__tests__/ghostMcp.test.ts b/packages/cindy-tools/src/__tests__/ghostMcp.test.ts
index 9a7ea14842..8bbe30f3b3 100644
--- a/packages/cindy-tools/src/__tests__/ghostMcp.test.ts
+++ b/packages/cindy-tools/src/__tests__/ghostMcp.test.ts
@@ -100,9 +100,10 @@ function fakeDeps(
}
function parsePayload(result: {
- content: { text: string }[];
+ content: Array<{ type: string; text?: string }>;
}): Record<string, unknown> {
- return JSON.parse(result.content[0].text) as Record<string, unknown>;
+ // The first block is always the JSON text (ghost_call may append images).
+ return JSON.parse(result.content[0].text ?? "") as Record<string, unknown>;
}
const READY_WITH_REAUTH_SUGGEST = {
@@ -594,6 +595,22 @@ describe("cindy_ghosts · ghost_call(派活透传)", () => {
});
});
+ it("images the plugin shows the model follow the JSON text as image content and stay out of the JSON", async () => {
+ const callGhostTool = vi.fn().mockResolvedValue({
+ ok: true,
+ result: { path: "/tmp/s.jpg" },
+ images: [{ data: "AAAA", mimeType: "image/jpeg" }],
+ imagesOmitted: 1,
+ });
+ const result = await handleGhostCall(fakeDeps({ callGhostTool }), { ghost_id: "sim", tool: "screenshot" });
+ expect(result.content).toHaveLength(2);
+ expect(result.content[1]).toEqual({ type: "image", data: "AAAA", mimeType: "image/jpeg" });
+ const payload = parsePayload(result);
+ expect(payload).toMatchObject({ ok: true, result: { path: "/tmp/s.jpg" }, images_omitted: 1 });
+ expect(payload).not.toHaveProperty("images");
+ expect(payload).not.toHaveProperty("imagesOmitted");
+ });
+
it("成功调用可附 setup.reauthSuggest,仍保持 ok:true", async () => {
const result = await handleGhostCall(
fakeDeps({
diff --git a/packages/cindy-tools/src/ghost/mcpServer.ts b/packages/cindy-tools/src/ghost/mcpServer.ts
index 7345f616b8..083b776031 100644
--- a/packages/cindy-tools/src/ghost/mcpServer.ts
+++ b/packages/cindy-tools/src/ghost/mcpServer.ts
@@ -320,6 +320,13 @@ interface McpTextResult {
isError?: boolean;
}
+/** ghost_call's result: the JSON text first, then any images the plugin shows the model. */
+interface McpGhostCallResult {
+ [key: string]: unknown;
+ content: ({ type: "text"; text: string } | { type: "image"; data: string; mimeType: string })[];
+ isError?: boolean;
+}
+
function textResult(payload: unknown, isError = false): McpTextResult {
return {
content: [{ type: "text", text: JSON.stringify(payload) }],
@@ -917,7 +924,7 @@ export async function handleGhostCall(
},
agentToolUseId?: string,
signal?: AbortSignal,
-): Promise<McpTextResult> {
+): Promise<McpGhostCallResult> {
try {
const result = await deps.callGhostTool({
ghostId: input.ghost_id,
@@ -969,7 +976,7 @@ export async function handleGhostCall(
// IM/hook 出站消费它,保证"意识画卡后删字段"也不影响媒体送达 IM 用户。
// 声明了媒体字段(含 xdt_audio_tracks)时以声明为准,账本不注入
// (声明是意图表达,能覆盖 render:false 抑制等语义)。
- const { producedMedia, setup: unsafeSetup, ...resultForModel } = result;
+ const { producedMedia, setup: unsafeSetup, images, imagesOmitted, ...resultForModel } = result;
const setup = sanitizeGhostSetupAssessment(unsafeSetup);
const advisory = setup?.state === "ready" && setup.reauthSuggest ? { setup } : {};
const declaredMedia = [
@@ -1015,13 +1022,19 @@ export async function handleGhostCall(
: typeof hoisted.xdt_card_id === "string" || typeof hoisted.xdt_anchor_card_id === "string"
? { hint: "xdt_card_id / xdt_anchor_card_id 是卡片配对令牌,不代表所有客户端已经展示。请在最终回复中概括实际结果,不要复述令牌。" }
: {};
- return textResult({
+ const response: McpGhostCallResult = textResult({
...resultForModel,
...advisory,
...hoisted,
...producedFallback,
...mediaHint,
+ ...(imagesOmitted ? { images_omitted: imagesOmitted } : {}),
});
+ // Images the plugin shows the model follow the JSON text as image content.
+ if (Array.isArray(images)) {
+ for (const image of images) response.content.push({ type: "image", data: image.data, mimeType: image.mimeType });
+ }
+ return response;
} catch (err) {
return textResult(
{
diff --git a/packages/cindy-tools/src/types.ts b/packages/cindy-tools/src/types.ts
index e80d801192..243e48fd57 100644
--- a/packages/cindy-tools/src/types.ts
+++ b/packages/cindy-tools/src/types.ts
@@ -216,6 +216,14 @@ export type CindyGhostCallResult =
* 固定媒体字段,不消费本字段(兼容性有回归测试锁定)。
*/
xdt_media_descriptions?: Array<{ url: string; description: string }>;
+ /**
+ * Images the plugin shows the model (host-checked and re-encoded under
+ * the inline budget). ghost_call returns them as MCP image content after
+ * the JSON text; they are not part of the JSON.
+ */
+ images?: Array<{ data: string; mimeType: string }>;
+ /** Images the plugin offered that did not fit the inline budget. */
+ imagesOmitted?: number;
}
| {
ok: false;