fix(app): settle out-of-band submissions compatibly

This commit is contained in:
Mohamed Boudra
2026-07-27 19:18:06 +02:00
parent eec9fb3992
commit 73119d0f36
15 changed files with 108 additions and 33 deletions
@@ -1952,19 +1952,12 @@ export class AgentManager {
* emitted by the handler flow through dispatchStream so they persist and
* broadcast like normal timeline events.
*/
tryRunOutOfBand(
agentId: string,
prompt: AgentPromptInput,
runOptions?: AgentRunOptions,
): boolean {
tryRunOutOfBand(agentId: string, prompt: AgentPromptInput): boolean {
const agent = this.requireSessionAgent(agentId);
const handler = agent.session.tryHandleOutOfBand?.(prompt);
if (!handler) {
return false;
}
if (typeof prompt !== "string") {
throw new Error("Out-of-band commands require a text prompt");
}
const dispatch = (event: AgentStreamEvent): void => {
// Persist timeline items so they show up in fetchAgentTimeline; broadcast
// for live subscribers. Other event types are broadcast only.
@@ -1980,15 +1973,6 @@ export class AgentManager {
}
this.dispatchStream(agent.id, event, { timestamp: new Date().toISOString() });
};
dispatch({
type: "timeline",
provider: agent.provider,
item: {
type: "user_message",
text: prompt,
...(runOptions?.clientMessageId ? { clientMessageId: runOptions.clientMessageId } : {}),
},
});
void (async () => {
try {
await handler.run({ emit: dispatch });
@@ -41,7 +41,7 @@ export async function startAgentRun(
// Out-of-band commands (e.g. /goal pause) must run WITHOUT canceling an
// in-flight turn — replaceAgentRun would interrupt the running turn. The
// intercept lives at this layer so it covers every prompt entrypoint.
if (agentManager.tryRunOutOfBand(agentId, prompt, options?.runOptions)) {
if (agentManager.tryRunOutOfBand(agentId, prompt)) {
return { outOfBand: true };
}
const shouldReplace = Boolean(options?.replaceRunning && agentManager.hasInFlightRun(agentId));
+2
View File
@@ -6335,6 +6335,7 @@ export class Session {
agentId,
accepted: true,
error: null,
outOfBand: true,
},
});
return;
@@ -6362,6 +6363,7 @@ export class Session {
agentId,
accepted: true,
error: null,
outOfBand: false,
},
});
} catch (error) {