Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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
396 changes: 396 additions & 0 deletions docs/design/2026-07-09-webshell-user-message-input-annotations.md

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions packages/acp-bridge/src/bridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4409,13 +4409,28 @@ describe('createAcpSessionBridge', () => {

const aPromise = firstUserChunk(iterA);
const bPromise = firstUserChunk(iterB);
const inputAnnotations = [
{
type: 'reference',
start: 0,
end: 7,
text: '@file/a',
reference: {
id: 'file:@file/a',
kind: 'file',
value: 'file/a',
serialized: '@file/a',
},
},
];

// Client A sends the prompt with its trusted clientId.
await bridge.sendPrompt(
session.sessionId,
{
sessionId: session.sessionId,
prompt: [{ type: 'text', text: 'hello from A' }],
_meta: { inputAnnotations, privateRequestId: 'hidden' },
},
undefined,
{ clientId: session.clientId },
Expand Down Expand Up @@ -4443,6 +4458,12 @@ describe('createAcpSessionBridge', () => {
expect((update._meta as { source?: string })?.source).toBe(
'bridge-echo',
);
expect(
(update._meta as { inputAnnotations?: unknown })?.inputAnnotations,
).toEqual(inputAnnotations);
expect(
(update._meta as { privateRequestId?: unknown })?.privateRequestId,
).toBeUndefined();
}

abortA.abort();
Expand Down
14 changes: 13 additions & 1 deletion packages/acp-bridge/src/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,14 @@ function parseWorkspaceMemoryDreamResult(
};
}

function pickUserInputEchoMeta(meta: unknown): Record<string, unknown> {
if (!meta || typeof meta !== 'object' || Array.isArray(meta)) return {};
const inputAnnotations = (meta as Record<string, unknown>)[
'inputAnnotations'
];
return Array.isArray(inputAnnotations) ? { inputAnnotations } : {};
}

/**
* Echo a user prompt to the session bus so multi-client SSE subscribers
* see the input alongside the agent response. Iterates content blocks
Expand Down Expand Up @@ -830,7 +838,11 @@ function echoPromptToSessionBus(
// field permitted alongside spec fields, the SDK normalizer
// reads it from `update._meta`/`data._meta`, and every other
// agent-emitted session_update carries `_meta` the same way.
_meta: { serverTimestamp, source: 'bridge-echo' },
_meta: {
...pickUserInputEchoMeta(req._meta),
serverTimestamp,
source: 'bridge-echo',
},
},
},
...(originatorClientId ? { originatorClientId } : {}),
Expand Down
3 changes: 3 additions & 0 deletions packages/sdk-typescript/src/daemon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ export type {
DaemonUserShellTranscriptBlock,
DaemonPermissionTranscriptBlock,
DaemonStatusTranscriptBlock,
DaemonInputAnnotation,
DaemonInputReference,
DaemonInputReferenceAnnotation,
DaemonTextTranscriptBlock,
DaemonTextDeltaMeta,
DaemonToolPreview,
Expand Down
3 changes: 3 additions & 0 deletions packages/sdk-typescript/src/daemon/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ export type {
DaemonUserShellTranscriptBlock,
DaemonPermissionTranscriptBlock,
DaemonStatusTranscriptBlock,
DaemonInputAnnotation,
DaemonInputReference,
DaemonInputReferenceAnnotation,
DaemonTextTranscriptBlock,
DaemonTextDeltaMeta,
DaemonToolPreview,
Expand Down
4 changes: 3 additions & 1 deletion packages/sdk-typescript/src/daemon/ui/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import type {
DaemonTextDeltaMeta,
DaemonTranscriptState,
DaemonTranscriptStore,
DaemonUiEvent,
Expand Down Expand Up @@ -60,8 +61,9 @@ export function createDaemonTranscriptStore(
appendLocalUserMessage(
text: string,
images?: Array<{ data: string; mimeType: string }>,
meta?: DaemonTextDeltaMeta,
) {
state = appendLocalUserTranscriptMessage(state, text, { images });
state = appendLocalUserTranscriptMessage(state, text, { images, meta });
scheduleNotify();
},
reset(nextSeed: Partial<DaemonTranscriptState> = {}) {
Expand Down
11 changes: 10 additions & 1 deletion packages/sdk-typescript/src/daemon/ui/transcript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
DaemonPromptCancelledTranscriptBlock,
DaemonShellTranscriptBlock,
DaemonStatusTranscriptBlock,
DaemonTextDeltaMeta,
DaemonTextTranscriptBlock,
DaemonToolTranscriptBlock,
DaemonTranscriptBlock,
Expand Down Expand Up @@ -96,11 +97,19 @@ export function appendLocalUserTranscriptMessage(
text: string,
opts: DaemonTranscriptReducerOptions & {
images?: Array<{ data: string; mimeType: string }>;
meta?: DaemonTextDeltaMeta;
} = {},
): DaemonTranscriptState {
const next = cloneTranscriptState(state, opts);
finishAssistant(next);
const block = createTextBlock(next, 'user', text);
const block = createTextBlock(
next,
'user',
text,
undefined,
undefined,
opts.meta,
);
if (opts.images && opts.images.length > 0) {
(block as DaemonTextTranscriptBlock).images = [...opts.images];
}
Expand Down
21 changes: 21 additions & 0 deletions packages/sdk-typescript/src/daemon/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,28 @@ export interface DaemonUiTextEvent extends DaemonUiEventBase {
meta?: DaemonTextDeltaMeta;
}

export interface DaemonInputReference {
id: string;
kind?: string;
label?: string;
value?: string;
serialized?: string;
removable?: boolean;
}

export interface DaemonInputReferenceAnnotation {
type: 'reference';
start: number;
end: number;
text: string;
reference: DaemonInputReference;
}

export type DaemonInputAnnotation = DaemonInputReferenceAnnotation;

export interface DaemonTextDeltaMeta extends Record<string, unknown> {
qwenDiscreteMessage?: boolean;
inputAnnotations?: DaemonInputAnnotation[];
}

export interface DaemonUiUserImageEvent extends DaemonUiEventBase {
Expand Down Expand Up @@ -963,6 +983,7 @@ export interface DaemonTranscriptStore {
appendLocalUserMessage(
text: string,
images?: Array<{ data: string; mimeType: string }>,
meta?: DaemonTextDeltaMeta,
): void;
reset(seed?: Partial<DaemonTranscriptState>): void;
/**
Expand Down
66 changes: 66 additions & 0 deletions packages/sdk-typescript/test/unit/daemonUi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,72 @@ describe('daemon UI normalizer and transcript reducer', () => {
]);
});

it('stores input annotations on locally appended user messages', () => {
const store = createDaemonTranscriptStore();
const inputAnnotations = [
{
type: 'reference' as const,
start: 6,
end: 13,
text: '@file/a',
reference: {
id: 'file:@file/a',
kind: 'file',
value: 'file/a',
serialized: '@file/a',
},
},
];

store.appendLocalUserMessage('hello @file/a', undefined, {
inputAnnotations,
});

expect(store.getSnapshot().blocks[0]).toMatchObject({
kind: 'user',
meta: { inputAnnotations },
});
});

it('stores input annotations from replayed user message chunks', () => {
const inputAnnotations = [
{
type: 'reference' as const,
start: 0,
end: 7,
text: '@file/a',
reference: {
id: 'file:@file/a',
kind: 'file',
value: 'file/a',
serialized: '@file/a',
},
},
];
const state = reduceDaemonTranscriptEvents(
createDaemonTranscriptState({ now: 1 }),
normalizeDaemonEvent({
id: 1,
v: 1,
type: 'session_update',
data: {
sessionId: 's1',
update: {
sessionUpdate: 'user_message_chunk',
content: { type: 'text', text: '@file/a' },
_meta: { inputAnnotations },
},
},
}),
{ now: 2 },
);

expect(state.blocks[0]).toMatchObject({
kind: 'user',
meta: { inputAnnotations },
});
});

it('preserves assistant message metadata on transcript blocks', () => {
const events = normalizeDaemonEvent({
id: 10,
Expand Down
Loading
Loading