Skip to content
Merged
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
6 changes: 3 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ app/
app/api/
sessions/route.ts GET list all sessions
sessions/search/route.ts GET ?q= — NDJSON { scores } batches (titles + transcripts); closing the request stops the scan
sessions/[id]/route.ts GET/PATCH/DELETE session
sessions/[id]/context/route.ts GET ?leafId= — context for a specific leaf
sessions/[id]/route.ts GET/PATCH/DELETE session; GET ?meta=1 answers the navigation shape (tree + leaf, no transcript), ?includeState=alive the split liveness shape (`running` = a turn in flight, `alive` = the child exists; every other `includeState` value keeps the historical `running` = live-wrapper meaning)
sessions/[id]/context/route.ts GET ?leafId= — context for a specific leaf; answers a strong ETag for the exact bytes and 304 on a matching If-None-Match
sessions/[id]/matches/route.ts GET ?q=&limit= — best `limit` search hits in the active conversation (best match, then newest); Load more asks for a longer prefix
sessions/[id]/export/route.ts GET exported HTML for a session
sessions/[id]/local-file/route.ts GET ?uri=local://<file> → `{ path, sessionId }`: the absolute path of a file in the session's own local:// directory, resolved on the owning host's daemon, and the canonical session that owns it (a live alias resolves to its current id; the tab must store that, since the alias goes with its wrapper). The open_file host tool then reads it through /api/files with that `sessionId`; 400 `invalid_local_uri` / `not_a_file`, 404 `session_not_found` / `file_not_found`, 403 on a symlink out, 501 `workspace_unsupported` for a host daemon that predates `resolveLocalFile`
agent/new/route.ts POST { cwd, message, toolNames?, provider?, modelId? }
agent/[id]/route.ts GET state | POST any channel command
agent/[id]/route.ts GET state (?systemPrompt=0 drops the ~13 KB prompt from the poll) | POST any channel command
events/route.ts GET multiplexed SSE | POST subscribe/unsubscribe channels
events/link/route.ts GET WebSocket upgrade: the browser link (lib/browser-link.ts), bound to the request's web session; gated like every API route, 426 without an upgrade
transport-metrics/route.ts GET { now } (the SSE clock probe) | POST { samples } → <agent dir>/omp-web/transport-metrics.jsonl
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f
**Before upgrading:** after this update, every linked host already in the first pool uses this machine's provider logins (it can read their access tokens and stored API keys) without a confirmation having been shown. This includes a first pool disabled through the API, and a host added to the first pool later through `PUT /api/hosts` or by editing `pools.json`. Each linked member needs an updated ompweb host daemon (link protocol 9 at that release; cluster members now need link protocol 10, see the first entry) and omp 15.13.1 or newer; until its daemon is updated, cluster placement skips that member, and a start fails when no other member is eligible. Before updating, remove a host that should not receive the logins from the first pool using `PUT /api/hosts` or editing `~/.omp/agent/omp-web/pools.json`; the old version has no membership switch.
- **Hosts can use the server's provider logins.** **Settings → Hosts** has a per-host toggle, **Use this server's provider logins**, off by default; turning it on asks for confirmation. Sessions started on that host then use the logins stored on the ompweb server instead of the host's own, through `omp auth-broker serve` on the server and a loopback forwarder in the host daemon. The host token never enters an omp process's environment, and OAuth refresh tokens never leave the server machine; the host can read current access tokens and stored API keys. Starting a session on a sharing host needs a daemon on link protocol v9 and omp 15.13.1 or newer, and is refused otherwise rather than falling back to the host's own logins. Custom providers in `models.yml`, environment-variable API keys and omp settings are not shared. A reverse proxy must let `/api/hosts/broker/` through without its own authentication, response buffering or redirects.
- **Windows hosts can be pool workers and accept local maintenance controls.** `ompweb host status`, `drain` and `resume` now work on Windows through a named pipe with a random name and a per-start token, kept in `<agent dir>/omp-web/host-control.json`; requests without the current token are refused. Windows hosts also report CPU busy time and available memory, so pools can place sessions on them. Windows reports no load average, so CPU pressure there comes from busy time alone.
- **Native clients can read a session without downloading its transcript.** `GET /api/sessions/[id]?meta=1` answers only the navigation shape (message tree and current leaf), `?includeState=alive` splits liveness into `running` (a turn in flight) and `alive` (the child exists) while every other `includeState` value keeps the historical meaning, and `GET /api/agent/[id]?systemPrompt=0` drops the ~13 KB system prompt from the periodic state poll. `GET /api/sessions/[id]/context` now answers a strong `ETag` for the exact bytes and 304 on a matching `If-None-Match`, so an unchanged context costs no body.
- **Archive and restore sessions on linked hosts.** Archiving now works for sessions on any linked machine, not only this one. The Archived Sessions browser lists every host's archive, shows which host each session is on, and restores it on that host. A host that is offline or runs an older ompweb host is named in the browser instead of hiding its archive silently. Restore rejects a session ID already active on any registered host, so every registered host must be online to restore, even an archive on this machine; the browser names the offline host that blocks it. A per-session claim stops web-server processes that share one agent directory from restoring the same session together; it does not coordinate separate web servers that share a daemon. A restore on another host keeps running when the web server stops waiting for it (after 30 s, or when the link drops), so the session stays claimed until that host's daemon process confirms it stopped: restoring the same ID again, on any host, is refused until then instead of creating a second active copy. Only the daemon process that took the restore can confirm that, so if the daemon was replaced, restarted or shut down meanwhile, or its host was unregistered, the session stays blocked: there is no timeout and no automatic clearing, and recovery is manual (see AGENTS.md). A restored session's attachments and other files are put back before the session becomes visible, so a file attached from another tab at that moment can no longer fail the restore or block retrying it. Restore streams archives with fixed 256 MiB compressed and expanded limits and rejects unsupported session IDs before consuming the archive.
- **Traditional Chinese (`zh-TW`) interface language.** Select Traditional Chinese (繁體中文) in the top-bar language menu. On compact layouts, open **More controls** first. Alternatively, let omp-web pick it automatically when the browser language is `zh-TW`, `zh-HK`, `zh-MO`, or `zh-Hant`. Localized Web Push notifications and a Traditional Chinese README (`README.zh-TW.md`) are included.
- **Several web apps can share one host daemon and the same live sessions.** Link additional servers with `ompweb host login --add --url <server>` (token from stdin). Prompts, tool progress, results and dialogs stay synchronized, and restarting one web app leaves the other connected to the same omp process. Link protocol v7 moves session startup, idle cleanup and interrupted-run recovery into the host; older links remain supported without sharing their processes. Schedule the first daemon upgrade while its host is quiescent.
Expand Down
13 changes: 11 additions & 2 deletions app/api/agent/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,27 @@ export async function POST(

// GET /api/agent/[id] - Get current agent state
export async function GET(
_req: Request,
req: Request,
{ params }: { params: Promise<{ id: string }> }
) {
const { id } = await params;
// Default stays the full shape; `?systemPrompt=0` drops the ~13 KB prompt
// from the 15 s state poll. Any other value (including "1") keeps it.
const includeSystemPrompt = new URL(req.url).searchParams.get("systemPrompt") !== "0";

try {
const session = getRpcSession(id);
if (!session || !session.isAlive()) {
return Response.json({ running: false });
}
try {
const state = await session.send({ type: "get_state" });
// Through the wrapper's command path, not a dedicated method: that is
// the contract every wrapper fake implements, and `dispatchCommand`
// already honors `systemPrompt: false`.
const state = await session.send({
type: "get_state",
...(includeSystemPrompt ? {} : { systemPrompt: false }),
});
return Response.json({ running: true, state });
} catch (error) {
if (error instanceof WebRpcError && error.code === "session_unresponsive") {
Expand Down
31 changes: 25 additions & 6 deletions app/api/sessions/[id]/context/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
import { buildSessionContext } from "@/lib/session-reader";
import { apiErrorResponse, opErrorResponse, resolveSessionHostOr404 } from "@/lib/api-utils";
import { apiErrorResponse, ifNoneMatchSatisfied, opErrorResponse, resolveSessionHostOr404, strongEtag } from "@/lib/api-utils";
import { getRpcSession } from "@/lib/rpc-manager";
import { MAX_SYNC_MESSAGES, parseHistoryCursor, selectSessionHistory, type SessionHistoryCursor, type SessionHistoryPage, type SessionSyncResponse } from "@/lib/session-sync";

/**
* Serialize once, key the validator on those exact bytes: the ETag cannot
* disagree with the body, and it covers everything that shapes it (branch,
* options, live stream snapshot) without this route needing the file's
* identity — which a remote host would not expose to this process.
*/
function jsonBodyResponse(req: Request, body: unknown, cacheControl: "no-store" | null = null): Response {
const text = JSON.stringify(body);
const etag = strongEtag(text);
const headers: Record<string, string> = { ETag: etag };
if (cacheControl) headers["Cache-Control"] = cacheControl;
if (ifNoneMatchSatisfied(req.headers.get("if-none-match"), etag)) {
return new Response(null, { status: 304, headers });
}
return new Response(text, {
headers: { "Content-Type": "application/json", "Content-Length": String(Buffer.byteLength(text)), ...headers },
});
}

export async function GET(
req: Request,
{ params }: { params: Promise<{ id: string }> }
Expand Down Expand Up @@ -63,20 +82,20 @@ export async function GET(
const session = notFound && (boundary === "1" || (sync === "1" && !cursor?.lastEntryId && leafId === undefined)) ? getRpcSession(id) : undefined;
if (session?.isAlive() && !(await session.host.sessionFileExists(session.sessionFile))) {
if (boundary === "1") {
return Response.json({ entryIds: [] }, { headers: { "Cache-Control": "no-store" } });
return jsonBodyResponse(req, { entryIds: [] }, "no-store");
}
const response: SessionSyncResponse = {
...selectSessionHistory(buildSessionContext([]), cursor, limit),
sessionId: id,
leafId: null,
live: session.getStreamSnapshot(),
};
return Response.json(response, { headers: { "Cache-Control": "no-store" } });
return jsonBodyResponse(req, response, "no-store");
}
return "response" in result ? result.response : opErrorResponse(result);
}
if (boundary === "1") {
return Response.json(result.value, { headers: { "Cache-Control": "no-store" } });
return jsonBodyResponse(req, result.value, "no-store");
}
if (sync === "1") {
const page = result.value as { history: SessionHistoryPage; leafId: string | null; tipId: string | null };
Expand All @@ -87,9 +106,9 @@ export async function GET(
? session.getStreamSnapshot()
: null;
const response: SessionSyncResponse = { ...page.history, sessionId: id, leafId: page.leafId, live };
return Response.json(response, { headers: { "Cache-Control": "no-store" } });
return jsonBodyResponse(req, response, "no-store");
}
return Response.json(result.value);
return jsonBodyResponse(req, result.value);
} catch (error) {
return apiErrorResponse(error);
}
Expand Down
Loading
Loading