Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/design/web-shell-vision-bridge-notice-i18n.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Web Shell Vision Bridge Notice Localization

## Problem

Vision Bridge status is emitted as an ordinary English assistant message. Web Shell receives no semantic data, so a Chinese locale cannot translate it.

## Design

Keep the English text as an ACP fallback for clients that do not understand Qwen metadata. Add a discrete `vision_bridge_notice` source with structured status, counts, model display name, endpoint, and egress state. Web Shell projects that event as a standalone system message and formats it through its existing locale catalog. Invalid or missing metadata falls back to the original text.

Within a turn, the existing processed-step control hides the notice when collapsed and restores it when expanded.

Message rewriting passes these notices through without adding them to the rewritten assistant response.

Channel bridges continue forwarding the English fallback as ordinary response text.

This change is limited to prompt-level Vision Bridge notices. TUI, headless, external ACP clients, tool-result notices, and voice notices retain their current behavior.

## Verification

- The cancelled prompt-level notice carries fallback text and structured metadata.
- The Web Shell keeps the notice separate from adjacent assistant output.
- Chinese renders localized text; malformed metadata renders the fallback.
25 changes: 25 additions & 0 deletions packages/channels/base/src/AcpBridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,31 @@ describe('AcpBridge', () => {
);
});

it('emits discrete vision bridge notices as text chunks', () => {
const bridge = new AcpBridge({
cliEntryPath: '/tmp/qwen',
cwd: '/tmp',
}) as unknown as TestableAcpBridge;
const textChunks: Array<[string, string]> = [];
bridge.on('textChunk', (sessionId, text) => {
textChunks.push([sessionId, text]);
});

bridge.handleSessionUpdate({
sessionId: 's-1',
update: {
sessionUpdate: 'agent_message_chunk',
content: { type: 'text', text: 'Vision bridge cancelled.' },
_meta: {
source: 'vision_bridge_notice',
qwenDiscreteMessage: true,
},
},
});

expect(textChunks).toEqual([['s-1', 'Vision bridge cancelled.']]);
});

it('emits a completed background response separately from the active turn', () => {
const bridge = new AcpBridge({
cliEntryPath: '/tmp/qwen',
Expand Down
6 changes: 6 additions & 0 deletions packages/channels/base/src/AcpBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,12 @@ export class AcpBridge extends EventEmitter implements ChannelAgentBridge {
content.text
) {
this.emit('backgroundResponse', sessionId, content.text);
} else if (
meta['source'] === 'vision_bridge_notice' &&
content?.type === 'text' &&
content.text
) {
this.emit('textChunk', sessionId, content.text);
}
break;
}
Expand Down
39 changes: 39 additions & 0 deletions packages/channels/base/src/DaemonChannelBridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,45 @@ describe('DaemonChannelBridge', () => {
bridge.stop();
});

it('emits discrete vision bridge notices as text chunks', async () => {
const events = new EventQueue();
const session = createFakeSession(events);
const bridge = new DaemonChannelBridge({
cwd: '/repo',
sessionFactory: vi.fn().mockResolvedValue(session),
});
const textChunks: Array<[string, string]> = [];
bridge.on('textChunk', (sessionId, text) => {
textChunks.push([sessionId, text]);
});

await bridge.start();
await bridge.newSession('/repo');
events.push({
id: 1,
v: 1,
type: 'session_update',
data: {
sessionId: 'session-1',
update: {
sessionUpdate: 'agent_message_chunk',
content: { type: 'text', text: 'Vision bridge cancelled.' },
_meta: {
source: 'vision_bridge_notice',
qwenDiscreteMessage: true,
},
},
},
});

await vi.waitFor(() => {
expect(textChunks).toEqual([['session-1', 'Vision bridge cancelled.']]);
});

events.close();
bridge.stop();
});

it('ignores a rewritten background response to avoid duplicate delivery', async () => {
const events = new EventQueue();
const session = createFakeSession(events);
Expand Down
2 changes: 2 additions & 0 deletions packages/channels/base/src/DaemonChannelBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,8 @@ export class DaemonChannelBridge
text
) {
this.emit('backgroundResponse', sessionId, text);
} else if (meta['source'] === 'vision_bridge_notice' && text) {
this.emit('textChunk', sessionId, text);
}
break;
}
Expand Down
25 changes: 24 additions & 1 deletion packages/cli/src/acp-integration/session/Session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8773,7 +8773,8 @@ describe('Session', () => {
status: 'skipped',
convertedCount: 0,
omittedCount: 0,
modelId: 'qwen3.7-plus',
modelId: 'idealab:qwen3.7-plus',
modelEndpoint: 'idealab.alibaba-inc.com',
egressOccurred: true,
});
mockChat.sendMessageStream = vi
Expand All @@ -8797,6 +8798,28 @@ describe('Session', () => {
expect(
textParts(sent).some((t: string) => t.includes('look at this')),
).toBe(true);
expect(mockClient.sessionUpdate).toHaveBeenCalledWith({
sessionId: 'test-session-id',
update: {
sessionUpdate: 'agent_message_chunk',
content: {
type: 'text',
text: 'Vision bridge cancelled. Your image and prompt/context were sent to qwen3.7-plus (idealab.alibaba-inc.com).',
},
_meta: {
source: 'vision_bridge_notice',
qwenDiscreteMessage: true,
visionBridgeNotice: {
status: 'skipped',
convertedCount: 0,
omittedCount: 0,
modelName: 'qwen3.7-plus',
modelEndpoint: 'idealab.alibaba-inc.com',
egressOccurred: true,
},
},
},
});
});

it('preserves oversized inline images for the vision bridge', async () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/acp-integration/session/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12424,8 +12424,9 @@ export class Session implements SessionContext {

if (bridgeResult.status !== 'skipped' || bridgeResult.egressOccurred) {
try {
await this.messageEmitter.emitAgentMessage(
await this.messageEmitter.emitVisionBridgeNotice(
formatVisionBridgeNotice(bridgeResult),
bridgeResult,
);
} catch (error) {
debugLogger.debug(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
type GoalRecord,
type GoalSnapshotV2,
type GoalStateCause,
type VisionBridgeResult,
} from '@qwen-code/qwen-code-core';
import { BaseEmitter } from './base-emitter.js';
import type { SessionUpdate } from '@agentclientprotocol/sdk';
Expand Down Expand Up @@ -202,6 +203,34 @@ export class MessageEmitter extends BaseEmitter {
);
}

async emitVisionBridgeNotice(
text: string,
result: VisionBridgeResult,
): Promise<void> {
await this.sendUpdate(
createTranscriptMessageUpdate({
role: 'assistant',
text,
extra: {
source: 'vision_bridge_notice',
qwenDiscreteMessage: true,
visionBridgeNotice: {
status: result.status,
convertedCount: result.convertedCount,
omittedCount: result.omittedCount,
...(result.modelId
? { modelName: result.modelId.replace(/^[^:]+:/, '') }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] The provider-prefix strip here (result.modelId.replace(/^[^:]+:/, '')) duplicates core's private displayVisionModelId (in packages/core/src/services/visionBridge/vision-bridge-service.ts) — the byte-identical regex that produces the model name inside the English fallback text emitted in this very same update. The two derivations are kept in sync by convention alone; the new Session test ties them for exactly one prefixed shape. If core's display-name logic ever changes (the module already carries \0-suffixed selector variants of model ids), the English fallback and the structured modelName metadata silently diverge — the localized Web Shell notice would then name a different model than the daemon's English text for the same event, so the privacy-relevant egress disclosure ("your image was sent to X") disagrees between two renderings of one event. Export displayVisionModelId from the core vision-bridge service and call it here instead of re-inlining the regex:

// core: export function displayVisionModelId(modelId: string): string
...(result.modelId
  ? { modelName: displayVisionModelId(result.modelId) }
  : {}),
中文说明

这里的 provider 前缀剥离(result.modelId.replace(/^[^:]+:/, ''))与 core 中私有的 displayVisionModelId(位于 packages/core/src/services/visionBridge/vision-bridge-service.ts)重复——该正则逐字节相同,用于生成同一条 update 中英文回退文本里的模型名。两处推导仅靠约定保持同步,新增的 Session 测试也只针对一种带前缀格式将二者绑定。一旦 core 的显示名逻辑变更(该模块已经存在带 \0 后缀的模型 id selector 变体),英文回退文本与结构化 modelName 元数据会悄悄分叉——本地化的 Web Shell 通知将与 daemon 英文文本就同一事件显示不同的模型名,即隐私相关的出站披露("你的图片已发送至 X")在同一事件的两种渲染中互相矛盾。建议从 core 的 vision-bridge service 导出 displayVisionModelId,在此调用它,而不是重新内联这段正则:

// core: export function displayVisionModelId(modelId: string): string
...(result.modelId
  ? { modelName: displayVisionModelId(result.modelId) }
  : {}),

— qwen3.8-max via Qwen Code /review (v0.22.0)

: {}),
...(result.modelEndpoint
? { modelEndpoint: result.modelEndpoint }
: {}),
egressOccurred: result.egressOccurred === true,
},
},
}),
);
}

async emitSlashCommandOutput(
text: string,
timestamp?: string | number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,47 @@ describe('MessageRewriteMiddleware', () => {
},
);

it('does not rewrite vision bridge notices or carry their metadata', async () => {
const { middleware, mockSendUpdate } = createMiddleware('message');
const notice = {
sessionUpdate: 'agent_message_chunk',
content: { type: 'text', text: 'Vision bridge cancelled.' },
_meta: {
source: 'vision_bridge_notice',
qwenDiscreteMessage: true,
visionBridgeNotice: { status: 'skipped' },
},
} as unknown as SessionUpdate;

await middleware.interceptUpdate(notice);
await middleware.interceptUpdate({
sessionUpdate: 'agent_message_chunk',
content: { type: 'text', text: 'Normal model response.' },
} as unknown as SessionUpdate);
await middleware.flushTurn();
await middleware.waitForPendingRewrites();

expect(mockSendUpdate).toHaveBeenNthCalledWith(1, notice);
expect(mockSendUpdate).toHaveBeenNthCalledWith(3, {
sessionUpdate: 'agent_message_chunk',
content: { type: 'text', text: 'rewritten text' },
_meta: { rewritten: true, turnIndex: 1 },
});

const { LlmRewriter } = await import('./LlmRewriter.js');
const rewriter = vi.mocked(LlmRewriter).mock.results[0]?.value as {
rewrite: ReturnType<typeof vi.fn>;
};
expect(rewriter.rewrite).toHaveBeenCalledWith(
{
thoughts: [],
messages: ['Normal model response.'],
hasToolCalls: false,
},
expect.any(AbortSignal),
);
});

it('should accumulate messages when target is "message"', async () => {
const { middleware, mockSendUpdate } = createMiddleware('message');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@ export class MessageRewriteMiddleware {
// Always send original message as-is
await this.sendUpdate(update);

const source = (
updateRecord['_meta'] as Record<string, unknown> | undefined
)?.['source'];
if (
updateType === 'agent_message_chunk' &&
(updateRecord['_meta'] as Record<string, unknown> | undefined)?.[
'source'
] === 'slash_command'
(source === 'slash_command' || source === 'vision_bridge_notice')
) {
return;
}
Expand Down
55 changes: 55 additions & 0 deletions packages/web-shell/client/adapters/transcriptToMessages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,61 @@ describe('transcriptBlocksToDaemonMessages', () => {
]);
});

it('keeps vision bridge notices separate from assistant output', () => {
const notice = {
status: 'skipped',
convertedCount: 0,
omittedCount: 0,
modelName: 'qwen3.6-plus',
modelEndpoint: 'idealab.alibaba-inc.com',
egressOccurred: true,
};
const messages = transcriptBlocksToDaemonMessages([
textBlock('assistant-0', 'assistant', 'Earlier reply', 0),
textBlock(
'vision-notice',
'assistant',
'Vision bridge cancelled.',
1,
false,
{
meta: {
source: 'vision_bridge_notice',
qwenDiscreteMessage: true,
visionBridgeNotice: notice,
},
},
),
textBlock('assistant-1', 'assistant', 'Normal reply', 2),
]);

expect(messages).toEqual([
{
id: 'assistant-0',
role: 'assistant',
content: 'Earlier reply',
isStreaming: false,
timestamp: 0,
},
{
id: 'vision-notice',
role: 'system',
content: 'Vision bridge cancelled.',
variant: 'info',
source: 'vision_bridge_notice',
data: notice,
timestamp: 1,
},
{
id: 'assistant-1',
role: 'assistant',
content: 'Normal reply',
isStreaming: false,
timestamp: 2,
},
]);
});

it.each([
['completed', 'completed'],
['failed', 'failed'],
Expand Down
18 changes: 18 additions & 0 deletions packages/web-shell/client/adapters/transcriptToMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,24 @@ export function transcriptBlocksToDaemonMessages(
});
break;
}
const meta = getRecord(textBlock.meta);
if (meta?.['source'] === 'vision_bridge_notice') {
currentAssistantIdx = null;
currentThinkingIdx = null;
needsNewContentMessage = true;
messages.push({
id: block.id,
role: 'system',
content: textBlock.text,
variant: 'info',
source: 'vision_bridge_notice',
...(meta['visionBridgeNotice'] !== undefined
? { data: meta['visionBridgeNotice'] }
: {}),
timestamp: blockTime,
});
break;
}
if (!textBlock.text && !textBlock.usage) break;

const parentSubAgent = textBlock.parentToolCallId
Expand Down
Loading
Loading