Skip to content
Closed
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
2 changes: 2 additions & 0 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
- [omp](https://github.com/can1357/oh-my-pi) がインストールされ、`PATH` に含まれていること(または `OMP_WEB_OMP_BIN` で指定)
- Node.js `>= 22.19.0`

キュー内のフォローアップに対する **Steer** 操作には、`promote_queued_message` RPC コマンドをサポートする omp ランタイムが必要です(omp 18.1.16 では未対応)。古いランタイムではエラーを表示し、メッセージはフォローアップとしてキューに残ります。ompweb が重複したステアリングメッセージを送信することはありません。

## クイックスタート

**インストールせずに直接実行:**
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ A clean, modern web UI for the [oh-my-pi (omp)](https://github.com/can1357/oh-my
- [omp](https://github.com/can1357/oh-my-pi) installed and available on your `PATH` (or specified via `OMP_WEB_OMP_BIN`)
- Node.js `>= 22.19.0`

The **Steer** action on a queued follow-up requires an omp runtime with the `promote_queued_message` RPC command (not available in omp 18.1.16). Older runtimes report an error and leave the message queued as a follow-up; ompweb does not send a duplicate steering message.

## Quick Start

**Run directly without installing:**
Expand Down
2 changes: 2 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
- 已安装 [omp](https://github.com/can1357/oh-my-pi) 且在 `PATH` 中(或通过 `OMP_WEB_OMP_BIN` 指定路径)
- Node.js `>= 22.19.0`

将排队的后续消息转为 **Steer** 需要 omp 运行时支持 `promote_queued_message` RPC 命令(omp 18.1.16 尚不支持)。旧版运行时会返回错误,消息仍作为后续消息排队;ompweb 不会重复发送一条引导消息。

## 快速开始

**免安装直接运行:**
Expand Down
4 changes: 2 additions & 2 deletions components/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ interface Props {
modelCapacity?: { contextWindow?: number; maxTokens?: number } | null;
/** Generation speed shown in the context ring popover. */
generationSpeed?: GenerationSpeedInfo | null;
/** Remove one queued message from the queue panel (Edit/Delete/Steer). */
/** Remove one queued message from the queue panel (Edit/Delete). */
onRemoveQueuedMessage?: (text: string) => void;
/** Relabel the first queued follow-up as a steering message. */
/** Promote the first matching native follow-up into steering. */
onPromoteQueuedToSteer?: (text: string) => void;
slashCommands?: SlashCommandInfo[];
slashCommandsLoading?: boolean;
Expand Down
213 changes: 205 additions & 8 deletions hooks/useAgentSession.rpc.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function jsonResponse(status, value) {
const world = {
esInstances: [],
calls: [],
holds: [], // { match(method, url), produce: () => Promise<{ status, value }> }
holds: [], // { match(method, url, body), produce: () => Promise<{ status, value }> }
sessions: new Map(), // sid -> { leafId, messages, entryIds }
agents: new Map(), // sid -> { running, state }
subagentSnapshots: new Map(), // sid -> SubagentSnapshotLike[]
Expand All @@ -138,10 +138,11 @@ const world = {
async function fetchStub(url, init = {}) {
const method = (init.method ?? "GET").toUpperCase();
const u = String(url);
world.calls.push({ method, url: u, body: typeof init.body === "string" ? safeParse(init.body) : null });
const body = typeof init.body === "string" ? safeParse(init.body) : null;
world.calls.push({ method, url: u, body });

for (let i = 0; i < world.holds.length; i++) {
if (world.holds[i].match(method, u)) {
if (world.holds[i].match(method, u, body)) {
const h = world.holds.splice(i, 1)[0];
const { status = 200, value } = await h.produce();
return jsonResponse(status, value);
Expand Down Expand Up @@ -174,7 +175,6 @@ async function fetchStub(url, init = {}) {
return jsonResponse(200, { running: a.running, state: a.state });
}
if (method === "POST") {
const body = typeof init.body === "string" ? safeParse(init.body) : null;
if (body?.type === "get_subagents") {
return jsonResponse(200, { success: true, data: { subagents: world.subagentSnapshots.get(sid) ?? [] } });
}
Expand Down Expand Up @@ -221,15 +221,16 @@ function sessionInfo(sid) {
};
}

async function mountSession(sid, onAgentEnd) {
async function mountSession(sid, onAgentEnd, strictMode = false) {
let latest = null;
function Chat({ session }) {
latest = useAgentSession({ session, newSessionCwd: null, ...(onAgentEnd ? { onAgentEnd } : {}) });
return null;
}
let renderer;
await act(async () => {
renderer = TestRenderer.create(React.createElement(Chat, { session: sessionInfo(sid) }));
const chat = React.createElement(Chat, { session: sessionInfo(sid) });
renderer = TestRenderer.create(strictMode ? React.createElement(React.StrictMode, null, chat) : chat);
});
await settle(); // hydration: loadSession + /state + models + subagents
activeRenderers.add(renderer);
Expand Down Expand Up @@ -290,8 +291,8 @@ const assistantMsg = (id, text) => ({
});

/** Mount + hydrate, then send a prompt and open the stream. Returns the ES. */
async function startRun(t, sid, message) {
const w = await mountSession(sid);
async function startRun(t, sid, message, strictMode = false) {
const w = await mountSession(sid, undefined, strictMode);
if (t) t.after(unmountAll);
assert.equal(w.latest.loading, false, "hydration must complete");
assert.equal(w.latest.agentRunning, false);
Expand All @@ -317,6 +318,202 @@ async function startRun(t, sid, message) {
// Tests
// ---------------------------------------------------------------------------

test("queued promotion waits for native acknowledgement and moves only the first matching follow-up", async (t) => {
t.after(unmountAll);
resetWorld();
primeSession("promotion", [userMsg("u0", "q")]);
const w = await mountSession("promotion", undefined, true);
await act(async () => {
await w.latest.handleSteer("existing steer");
await w.latest.handleFollowUp("other");
await w.latest.handleFollowUp("target");
await w.latest.handleFollowUp("target");
});
const before = { steering: ["existing steer"], followUp: ["other", "target", "target"] };
let release;
const acknowledgement = new Promise((resolve) => { release = resolve; });
world.holds.push({
match: (method, url, body) => method === "POST" && url === "/api/agent/promotion" && body?.type === "promote_queued_message",
produce: () => acknowledgement,
});
const callsBefore = world.calls.length;
let promotion;
await act(async () => { promotion = w.latest.promoteQueuedToSteer("target"); });
assert.deepEqual(w.latest.queuedMessages, before, "pending RPC must not relabel the chip");
assert.deepEqual(world.calls.slice(callsBefore), [{
method: "POST", url: "/api/agent/promotion", body: { type: "promote_queued_message", message: "target" },
}], "promotion must not enqueue a separate steer or follow-up");
await act(async () => {
release({ value: { success: true, data: { promoted: true } } });
await promotion;
});
assert.deepEqual(w.latest.queuedMessages, {
steering: ["existing steer", "target"], followUp: ["other", "target"],
});
assert.deepEqual(w.latest.notices, []);
});

test("queued promotion preserves the follow-up and reports native refusal or rejection", async (t) => {
for (const outcome of [
{ name: "not-found", response: { value: { success: true, data: { promoted: false } } }, noticeType: "warning" },
{ name: "unsupported", response: { status: 400, value: { error: "Unknown RPC command: promote_queued_message" } }, noticeType: "error" },
]) {
await t.test(outcome.name, async (t) => {
t.after(unmountAll);
resetWorld();
primeSession(outcome.name, [userMsg("u0", "q")]);
const w = await mountSession(outcome.name);
await act(async () => { await w.latest.handleFollowUp("target"); });
let release;
const acknowledgement = new Promise((resolve) => { release = resolve; });
world.holds.push({
match: (method, _url, body) => method === "POST" && body?.type === "promote_queued_message",
produce: () => acknowledgement,
});
let promotion;
await act(async () => { promotion = w.latest.promoteQueuedToSteer("target"); });
assert.deepEqual(w.latest.queuedMessages, { steering: [], followUp: ["target"] });
await act(async () => {
release(outcome.response);
await promotion;
});
assert.deepEqual(w.latest.queuedMessages, { steering: [], followUp: ["target"] });
assert.equal(w.latest.notices.length, 1);
assert.equal(w.latest.notices[0].type, outcome.noticeType);
if (outcome.response.value.error) {
assert.equal(w.latest.notices[0].message, outcome.response.value.error);
}

// A settled failure releases the overlap guard so a deliberate retry works.
world.holds.push({
match: (method, _url, body) => method === "POST" && body?.type === "promote_queued_message",
produce: async () => ({ value: { success: true, data: { promoted: true } } }),
});
await act(async () => { await w.latest.promoteQueuedToSteer("target"); });
assert.deepEqual(w.latest.queuedMessages, { steering: ["target"], followUp: [] });
});
}
});

test("overlapping same-text promotion clicks send one command and promote one occurrence", async (t) => {
t.after(unmountAll);
resetWorld();
primeSession("double-promotion", [userMsg("u0", "q")]);
const w = await mountSession("double-promotion");
await act(async () => {
await w.latest.handleFollowUp("target");
await w.latest.handleFollowUp("target");
});
let release;
const acknowledgement = new Promise((resolve) => { release = resolve; });
world.holds.push({
match: (method, _url, body) => method === "POST" && body?.type === "promote_queued_message",
produce: () => acknowledgement,
});
let first;
let second;
await act(async () => {
first = w.latest.promoteQueuedToSteer("target");
second = w.latest.promoteQueuedToSteer("target");
});
assert.equal(world.calls.filter((call) => call.body?.type === "promote_queued_message").length, 1);
assert.deepEqual(w.latest.queuedMessages, { steering: [], followUp: ["target", "target"] });
await act(async () => {
release({ value: { success: true, data: { promoted: true } } });
await Promise.all([first, second]);
});
assert.deepEqual(w.latest.queuedMessages, { steering: ["target"], followUp: ["target"] });
});

test("delivery before promotion acknowledgement does not relabel the next duplicate or resurrect the delivered chip", async (t) => {
t.after(unmountAll);
resetWorld();
primeSession("delivered-promotion", [userMsg("u0", "q")]);
const { w, es } = await startRun(t, "delivered-promotion", "run", true);
await act(async () => {
es.emit({ type: "agent_start" });
await w.latest.handleFollowUp("target");
await w.latest.handleFollowUp("target");
});
let release;
const acknowledgement = new Promise((resolve) => { release = resolve; });
world.holds.push({
match: (method, _url, body) => method === "POST" && body?.type === "promote_queued_message",
produce: () => acknowledgement,
});
let promotion;
await act(async () => { promotion = w.latest.promoteQueuedToSteer("target"); });
await act(async () => { es.emit({ type: "message_end", message: userMsg("delivered", "target") }); });
assert.deepEqual(w.latest.queuedMessages, { steering: [], followUp: ["target"] });
assert.equal(w.latest.messages.filter((message) => message.role === "user" && message.content === "target").length, 1);
await act(async () => {
release({ value: { success: true, data: { promoted: true } } });
await promotion;
});
assert.deepEqual(w.latest.queuedMessages, { steering: [], followUp: ["target"] });
});

test("a batched local removal and promotion acknowledgement preserve the next duplicate in StrictMode", async (t) => {
t.after(unmountAll);
resetWorld();
primeSession("removed-promotion", [userMsg("u0", "q")]);
const w = await mountSession("removed-promotion", undefined, true);
await act(async () => {
await w.latest.handleFollowUp("target");
await w.latest.handleFollowUp("target");
});
let release;
const acknowledgement = new Promise((resolve) => { release = resolve; });
world.holds.push({
match: (method, _url, body) => method === "POST" && body?.type === "promote_queued_message",
produce: () => acknowledgement,
});
let promotion;
await act(async () => { promotion = w.latest.promoteQueuedToSteer("target"); });
await act(async () => {
React.startTransition(() => w.latest.removeQueuedMessage("target"));
release({ value: { success: true, data: { promoted: true } } });
await promotion;
});
assert.deepEqual(w.latest.queuedMessages, { steering: [], followUp: ["target"] });
assert.deepEqual(w.latest.notices, []);
});

test("promotion acknowledgements after navigation cannot change the newly mounted session", async (t) => {
for (const response of [
{ value: { success: true, data: { promoted: true } } },
{ status: 400, value: { error: "Native promotion failed" } },
]) {
await t.test(response.status ? "error" : "success", async (t) => {
t.after(unmountAll);
resetWorld();
primeSession("old-promotion", [userMsg("u0", "old")]);
primeSession("new-promotion", [userMsg("u1", "new")]);
const old = await mountSession("old-promotion");
await act(async () => { await old.latest.handleFollowUp("target"); });
let release;
const acknowledgement = new Promise((resolve) => { release = resolve; });
world.holds.push({
match: (method, _url, body) => method === "POST" && body?.type === "promote_queued_message",
produce: () => acknowledgement,
});
let promotion;
await act(async () => { promotion = old.latest.promoteQueuedToSteer("target"); });
await act(async () => { old.renderer.unmount(); });
activeRenderers.delete(old.renderer);
const current = await mountSession("new-promotion");
await act(async () => { await current.latest.handleFollowUp("target"); });
await act(async () => {
release(response);
await promotion;
});
assert.deepEqual(current.latest.queuedMessages, { steering: [], followUp: ["target"] });
assert.deepEqual(current.latest.notices, []);
assert.equal(world.calls.some((call) => call.url === "/api/agent/new-promotion" && call.body?.type === "promote_queued_message"), false);
});
}
});

test("full run over fake SSE: optimistic bubble, coalesced streaming, terminal reload", async (t) => {
t.after(unmountAll);
resetWorld();
Expand Down
Loading