Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix: preserve image URIs through vision bridge
zhanghengxd912fb3bfdddc
diff --git a/packages/maker-core/src/session.ts b/packages/maker-core/src/session.tsindex 9c85f79396..969137a0fb 100644--- a/packages/maker-core/src/session.ts+++ b/packages/maker-core/src/session.ts@@ -54,6 +54,7 @@ import {TurnDispatchRejectedError,TurnDispatchUnconfirmedError,} from './agents/base-agent.js';+import { formatManagedImageReferences } from './agents/shared/managed-image-reference.js';import type { Logger } from './interfaces/logger.js';export type SessionStatus = 'active' | 'aborting' | 'closed' | 'error';@@ -242,6 +243,29 @@ function redactNestedStrings(value: unknown, onChange: () => void): unknown {return copy;}+/**+ * Vision bridging replaces image blocks before the provider adapter sees them.+ * Preserve the Host-managed attachment identities as ordinary per-turn text,+ * without exposing them to the external vision backend or changing image bytes.+ */+function appendManagedImageReferences(+ source: UserMessage,+ bridged: UserMessage,+): UserMessage {+ const references = formatManagedImageReferences(source.content);+ if (!references) return bridged;+ if (typeof bridged.content === 'string') {+ return {+ ...bridged,+ content: bridged.content ? `${bridged.content}\n${references}` : references,+ };+ }+ return {+ ...bridged,+ content: [...bridged.content, { type: 'text', text: references }],+ };+}+export interface SessionSendOptions extends SendOptions {/*** Turn reservation 建立后的原子准备钩子。@@ -676,7 +700,7 @@ export class Session {signal,sessionId: this.id,});- if (bridged.applied) return bridged.message;+ if (bridged.applied) return appendManagedImageReferences(msg, bridged.message);if (bridged.note) {// 无论 applied 与否,note(fallback 生效 / 视觉桥不可用)都上报,避免静默。this.logger.info('vision bridge note', { sessionId: this.id, note: bridged.note });diff --git a/packages/maker-core/src/session.vision-bridge.test.ts b/packages/maker-core/src/session.vision-bridge.test.tsindex 8179a1109d..0c4e9d1a08 100644--- a/packages/maker-core/src/session.vision-bridge.test.ts+++ b/packages/maker-core/src/session.vision-bridge.test.ts@@ -89,6 +89,33 @@ describe('Session.send vision bridge hook', () => {expect(sent[0].content).toEqual([{ type: 'text', text: '[desc] the image shows a red button' }]);});+ it('preserves Host-managed image references after the bridge replaces image blocks', async () => {+ const managedUrl = `cindy-media://blobs/${'a'.repeat(64)}.png`;+ const { handle, sent } = makeRecordingHandle();+ const hook: VisionBridgeHook = async () => ({+ applied: true,+ message: {+ type: 'user',+ content: [{ type: 'text', text: '[desc] the image shows a red button' }],+ },+ });+ const session = makeSession(handle, hook);++ await session.send({+ type: 'user',+ content: [{ type: 'image', path: '/tmp/ui.png', managedUrl }],+ });++ expect(sent).toHaveLength(1);+ expect(sent[0].content).toEqual([+ { type: 'text', text: '[desc] the image shows a red button' },+ {+ type: 'text',+ text: expect.stringContaining(JSON.stringify({ image: 1, uri: managedUrl })),+ },+ ]);+ });+it('passes through unchanged when applied=false with note (note not blocking)', async () => {const { handle, sent } = makeRecordingHandle();const hook: VisionBridgeHook = async (msg) => ({ applied: false, message: msg, note: 'vision backend down' });@@ -277,6 +304,56 @@ describe('Session.steer vision bridge hook', () => {expect(steered[0].content).toEqual([{ type: 'text', text: '[desc] the image shows a chat list' }]);});+ it('preserves Host-managed image references when steering through the vision bridge', async () => {+ const managedUrl = 'xdt-image://vision-steer/screenshot.png';+ const steered: UserMessage[] = [];+ const handle = {+ id: 'thread-1',+ agentKind: 'claude-code',+ model: 'deepseek-v4',+ async send() {},+ async steer(msg: UserMessage) {+ steered.push(msg);+ },+ async abort() {},+ async close() {},+ async *events() {},+ getUsageSnapshot: () => ({ tokenUsage: 0, contextTokens: 0, contextWindow: 0, costUsd: 0 }),+ setInteractionResolver: () => undefined,+ isTurnRunning: () => true,+ } as unknown as AgentSessionHandle;+ const hook: VisionBridgeHook = async () => ({+ applied: true,+ message: {+ type: 'user',+ content: [{ type: 'text', text: '[desc] bridged screenshot' }],+ },+ });+ const session = new Session({+ id: 'session-vb-steer-reference',+ agentKind: 'claude-code',+ workDir: path.join('workspace', 'repo'),+ handle,+ capabilities: { sameTurnSteer: { supported: true } } as never,+ logger: createLogger() as never,+ visionBridge: hook,+ });++ await session.steer({+ type: 'user',+ content: [{ type: 'image', path: '/tmp/a.png', managedUrl }],+ });++ expect(steered).toHaveLength(1);+ expect(steered[0].content).toEqual([+ { type: 'text', text: '[desc] bridged screenshot' },+ {+ type: 'text',+ text: expect.stringContaining(JSON.stringify({ image: 1, uri: managedUrl })),+ },+ ]);+ });+it('does not steer when the turn ends during async vision conversion', async () => {// turn 在视觉转换期间结束:steer 必须先复查生命周期再调 handle.steer,// 否则底层以「No active turn to steer」拒绝或 Pi 把迟到消息交给已结束的 turn。