feat(webui): complete bang commands and literal output (NAN-291) (#6173)
* feat(webui): complete direct bang shell commands Reuse the gateway user-shell side channel, retain failed drafts without reconnect replay, and preserve literal output across live delivery and history. Highlight the bang prefix before and after sending. NAN-291 * fix(clients): preserve literal shell output through display metadata
This commit is contained in:
1 parent
f23a6d1485
commit
7e5dcb79e0
43 files changed
+805
-100
No files matched your search
@@ -175,7 +175,7 @@ function projectOrderedTurn(
|
||||
};
|
||||
|
||||
for (const message of messages) {
|
||||
if (message.kind === "compaction") {
|
||||
if (message.kind === "compaction" || message.renderAs === "text") {
|
||||
flushActivity();
|
||||
flushAnswers();
|
||||
units.push({
|
||||
|
||||
@@ -766,6 +766,24 @@ export class NanobotClient {
|
||||
}
|
||||
}
|
||||
|
||||
async sendUserShellCommand(
|
||||
chatId: string, content: string, options?: Parameters<NanobotClient["sendMessage"]>[3],
|
||||
): Promise<void> {
|
||||
const turnId = options?.turnId ?? crypto.randomUUID();
|
||||
try {
|
||||
await this.receipts.wait(turnId, () => {
|
||||
if (!this.sendMessage(chatId, content, undefined, { ...options, turnId, userShell: true, startsNewRun: false })) {
|
||||
throw new Error("Shell command was not sent; draft retained");
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
this.applyRunEffects(this.runs.transition({ kind: "reject", chatId, turnId }));
|
||||
this.emitError({ kind: "turn_rejected", chatId, turnId, detail: "message_rejected",
|
||||
reason: error instanceof Error ? error.message : "Shell command send failed" });
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
sendMessage(
|
||||
chatId: string,
|
||||
content: string,
|
||||
@@ -776,12 +794,14 @@ export class NanobotClient {
|
||||
sessionMentions?: SessionMention[];
|
||||
quotedContext?: string;
|
||||
intent?: "create_automation";
|
||||
userShell?: boolean;
|
||||
workspaceScope?: WorkspaceScopePayload | null;
|
||||
turnId?: string;
|
||||
/** False for side-channel or injected messages that do not own a lifecycle. */
|
||||
startsNewRun?: boolean;
|
||||
},
|
||||
): boolean {
|
||||
if (options?.userShell && this.socket?.readyState !== WS_OPEN) return false;
|
||||
const temporary = this.temporaryChatIds.has(chatId);
|
||||
if (!temporary) this.knownChats.add(chatId);
|
||||
const frame: Outbound = {
|
||||
@@ -796,6 +816,7 @@ export class NanobotClient {
|
||||
: {}),
|
||||
...(options?.quotedContext?.trim() ? { quoted_context: options.quotedContext.trim() } : {}),
|
||||
...(options?.intent === "create_automation" ? { intent: options.intent } : {}),
|
||||
...(options?.userShell ? { user_shell: true } : {}),
|
||||
...(options?.workspaceScope ? { workspace_scope: options.workspaceScope } : {}),
|
||||
...(options?.turnId ? { turn_id: options.turnId } : {}),
|
||||
webui: true,
|
||||
@@ -819,6 +840,7 @@ export class NanobotClient {
|
||||
role: options.startsNewRun === false ? "supplement" : "candidate-owner",
|
||||
}));
|
||||
}
|
||||
if (options?.userShell) return this.rawSend(frame);
|
||||
this.queueSend(frame);
|
||||
return true;
|
||||
}
|
||||
@@ -1285,8 +1307,8 @@ export class NanobotClient {
|
||||
return new TextEncoder().encode(JSON.stringify(frame)).byteLength <= this.maxFrameBytes;
|
||||
}
|
||||
|
||||
private rawSend(frame: Outbound): void {
|
||||
if (!this.socket) return;
|
||||
private rawSend(frame: Outbound): boolean {
|
||||
if (!this.socket) return false;
|
||||
try {
|
||||
this.socket.send(JSON.stringify(frame));
|
||||
this.lastSocketMessageSend = null;
|
||||
@@ -1297,9 +1319,11 @@ export class NanobotClient {
|
||||
this.lastSocketMessageSend = ref;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch {
|
||||
// Send failure will materialize as a close; queue the frame for retry.
|
||||
this.sendQueue.push(frame);
|
||||
// Shell commands require a new explicit submission, never reconnect replay.
|
||||
if (frame.type !== "message" || !frame.user_shell) this.sendQueue.push(frame);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ export function scrubSubagentAnnounceBody(
|
||||
/** Apply scrub to assistant rows that look like subagent inject announcements. */
|
||||
export function scrubSubagentUiMessages(messages: UIMessage[]): UIMessage[] {
|
||||
return messages.map((m) => {
|
||||
if (m.role !== "assistant" || typeof m.content !== "string") {
|
||||
if (m.role !== "assistant" || m.renderAs === "text" || typeof m.content !== "string") {
|
||||
return m;
|
||||
}
|
||||
if (!m.content.includes("[Subagent")) {
|
||||
|
||||
@@ -20,7 +20,7 @@ function prepareMessage(original: UIMessage): PreparedMessage {
|
||||
message,
|
||||
hidden: isSystemCommandTurnId(message.turnId)
|
||||
|| (message.role === "user" && isModelCommandText(message.content))
|
||||
|| (message.role === "assistant" && isModelCommandResponseText(message.content)),
|
||||
|| (message.role === "assistant" && message.renderAs !== "text" && isModelCommandResponseText(message.content)),
|
||||
compact: message.role === "user" && message.content.trim().toLowerCase() === "/compact",
|
||||
};
|
||||
preparedMessages.set(original, prepared);
|
||||
@@ -47,7 +47,7 @@ export function projectWebuiThreadMessages(messages: UIMessage[]): UIMessage[] {
|
||||
latestStart = message.createdAt;
|
||||
if (message.turnId) starts.set(message.turnId, message.createdAt);
|
||||
}
|
||||
if (message.role === "assistant" && !message.kind && !message.isStreaming
|
||||
if (message.role === "assistant" && message.renderAs !== "text" && !message.kind && !message.isStreaming
|
||||
&& message.turnId && compactTurns.has(message.turnId)) {
|
||||
if (message.content === "Nothing to compact.") message = { ...message, compactReply: "empty" };
|
||||
if (message.content === "Unable to compact context. Check the logs and try again.") {
|
||||
|
||||
@@ -1053,6 +1053,7 @@ export function projectThreadEvent(
|
||||
: undefined;
|
||||
const projected = {
|
||||
content: event.text,
|
||||
...(event.render_as === "text" ? { renderAs: event.render_as } : {}),
|
||||
...(media?.length ? { media } : {}),
|
||||
...(latencyMs !== undefined ? { latencyMs } : {}),
|
||||
...(event.source ? { source: event.source } : {}),
|
||||
|
||||
@@ -113,6 +113,8 @@ export interface UIMessage {
|
||||
id: string;
|
||||
role: Role;
|
||||
content: string;
|
||||
/** Literal output bypasses Markdown and content-based reply recognition. */
|
||||
renderAs?: "text";
|
||||
/** Invocation-time snapshots, never resolved from today's model presets. */
|
||||
responseSources?: ResponseSource[];
|
||||
kind?: MessageKind;
|
||||
@@ -1514,6 +1516,7 @@ export type InboundEvent =
|
||||
event: "message";
|
||||
chat_id: string;
|
||||
text: string;
|
||||
render_as?: "text";
|
||||
reply_to?: string;
|
||||
media?: string[];
|
||||
media_urls?: Array<{ url: string; name?: string; kind?: UIMediaKind }>;
|
||||
@@ -1794,6 +1797,7 @@ export type Outbound =
|
||||
session_mentions?: SessionMention[];
|
||||
quoted_context?: string;
|
||||
intent?: "create_automation";
|
||||
user_shell?: true;
|
||||
workspace_scope?: WorkspaceScopePayload;
|
||||
turn_id?: string;
|
||||
/** Marks messages sent by the embedded WebUI, without changing the
|
||||
|
||||
Reference in new issue
Block a user