feat: steer active chat messages

Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
Harivansh Rathi 2026-03-09 16:56:24 -07:00
parent a018a0cd3e
commit 4a29c13e0d
2 changed files with 172 additions and 1 deletions

View file

@ -849,7 +849,7 @@ export class GatewayRuntime {
}
const sessionMatch = path.match(
/^\/sessions\/([^/]+)(?:\/(events|messages|abort|reset|chat|history|model|reload|state))?$/,
/^\/sessions\/([^/]+)(?:\/(events|messages|abort|reset|chat|history|model|reload|state|steer))?$/,
);
if (!sessionMatch) {
this.writeJson(response, 404, { error: "Not found" });
@ -910,6 +910,18 @@ export class GatewayRuntime {
return;
}
if (action === "steer" && method === "POST") {
const body = await this.readJsonBody(request);
const text = extractUserText(body);
if (!text) {
this.writeJson(response, 400, { error: "Missing user message text" });
return;
}
const result = await this.handleSteer(sessionKey, text);
this.writeJson(response, 200, result);
return;
}
if (action === "reset" && method === "POST") {
await this.requireExistingSession(sessionKey);
await this.resetSession(sessionKey);
@ -1099,6 +1111,47 @@ export class GatewayRuntime {
}
}
private async handleSteer(
sessionKey: string,
text: string,
): Promise<{ ok: true; mode: "steer" | "queued"; sessionKey: string }> {
const managedSession = await this.requireExistingSession(sessionKey);
const preview = text.length > 80 ? `${text.slice(0, 80)}...` : text;
if (managedSession.processing) {
this.logSession(managedSession, `steer text="${preview}"`);
await managedSession.session.steer(text);
return { ok: true, mode: "steer", sessionKey };
}
if (managedSession.queue.length >= this.config.session.maxQueuePerSession) {
throw new HttpError(
409,
`Queue full (${this.config.session.maxQueuePerSession} pending).`,
);
}
this.logSession(
managedSession,
`steer-fallback queue text="${preview}" depth=${managedSession.queue.length + 1}`,
);
void this.enqueueManagedMessage({
request: {
sessionKey,
text,
source: "extension",
},
}).then((result) => {
if (!result.ok) {
this.log(
`[steer] session=${sessionKey} queued fallback failed: ${result.error ?? "Unknown error"}`,
);
}
});
return { ok: true, mode: "queued", sessionKey };
}
private requireAuth(
request: IncomingMessage,
response: ServerResponse,