A desktop coding agent with free access to frontier models.
TypeScript
feat(desktop): name the app on every omnirush.ai request (X-OmniRush-Client: gui/<version>)
ogsamrat0fe624146b5e
diff --git a/apps/desktop/electron/main.mjs b/apps/desktop/electron/main.mjsindex b0bcc3e9..741fb22e 100644--- a/apps/desktop/electron/main.mjs+++ b/apps/desktop/electron/main.mjs@@ -1357,6 +1357,7 @@ const omnirushAccountStore = createDesktopOmniRushAccountStore({fallbackFilePath: path.join(app.getPath("userData"), "private-credentials", "omnirush-account.json"),onKeyringSealed: recordKeyringSealed("omnirush-account.bin"),onClientUpdate: (clientUpdate) => updateGate.signal({ kind: "profile", clientUpdate }),+ clientVersion: app.getVersion(),legacyKeychain: legacyKeychainAllowed({appIdentifier: APP_IDENTIFIER,productionAppIdentifier: TAURI_APP_IDENTIFIER,diff --git a/apps/desktop/electron/omnirush-account.mjs b/apps/desktop/electron/omnirush-account.mjsindex 2c6dc893..a2294bd3 100644--- a/apps/desktop/electron/omnirush-account.mjs+++ b/apps/desktop/electron/omnirush-account.mjs@@ -12,7 +12,7 @@ import {usableSafeStorage,writePlaintextCredentialFile,} from "./plaintext-credential-file.mjs";-import { parseClientUpdate } from "./update-gate.mjs";+import { CLIENT_HEADER, guiClientHeaderValue, parseClientUpdate } from "./update-gate.mjs";const execFileAsync = promisify(execFile);@@ -313,7 +313,19 @@ export function createDesktopOmniRushAccountStore({// Hears `client_update` from /device/me, sign-in and refresh answers// (update-gate.mjs); null when an answer carried none.onClientUpdate = null,+ // The desktop app's version, named on every account request as+ // `X-OmniRush-Client: gui/<version>`; unset sends no header.+ clientVersion = null,}) {+ const clientHeader = guiClientHeaderValue(clientVersion);+ /** fetchImpl with `X-OmniRush-Client` added to every account request. */+ const send = clientHeader+ ? (url, init = {}) => {+ const headers = new Headers(init.headers);+ headers.set(CLIENT_HEADER, clientHeader);+ return fetchImpl(url, { ...init, headers });+ }+ : fetchImpl;/** A `client_update` this account server sent; never lets the gate break sign-in. */function reportClientUpdate(payload) {if (typeof onClientUpdate !== "function" || !payload || typeof payload !== "object") return;@@ -810,7 +822,7 @@ export function createDesktopOmniRushAccountStore({refreshUrl.pathname += "/device/refresh";let response;try {- response = await fetchImpl(refreshUrl, {+ response = await send(refreshUrl, {method: "POST",headers: { "Content-Type": "application/json" },body: JSON.stringify({ refresh_token: credentials.refreshToken }),@@ -895,7 +907,7 @@ export function createDesktopOmniRushAccountStore({logoutUrl.pathname += "/device/logout";let response;try {- response = await fetchImpl(logoutUrl, {+ response = await send(logoutUrl, {method: "POST",headers: { "Content-Type": "application/json" },body: JSON.stringify({ refresh_token: credentials.refreshToken }),@@ -917,7 +929,7 @@ export function createDesktopOmniRushAccountStore({async function fetchProfile(credentials, refreshesLeft = 2) {const profileUrl = controlPlaneBase(credentials.gatewayUrl);profileUrl.pathname += "/device/me";- const response = await fetchImpl(profileUrl, {+ const response = await send(profileUrl, {headers: { Authorization: `Bearer ${credentials.accessToken}` },signal: AbortSignal.timeout(20_000),});@@ -943,7 +955,7 @@ export function createDesktopOmniRushAccountStore({const base = controlPlaneBase(configured);const authorizeUrl = new URL(base);authorizeUrl.pathname += "/device/authorize";- const issuedResponse = await fetchImpl(authorizeUrl, {+ const issuedResponse = await send(authorizeUrl, {method: "POST",headers: { "Content-Type": "application/json" },body: JSON.stringify({ device_name: deviceName, platform }),@@ -960,7 +972,7 @@ export function createDesktopOmniRushAccountStore({const deadline = Date.now() + Math.max(60, Number(issued.expires_in) || 600) * 1_000;while (Date.now() < deadline) {await sleep(interval);- const tokenResponse = await fetchImpl(tokenUrl, {+ const tokenResponse = await send(tokenUrl, {method: "POST",headers: { "Content-Type": "application/json" },body: JSON.stringify({ device_code: issued.device_code }),diff --git a/apps/desktop/electron/omnirush-account.test.mjs b/apps/desktop/electron/omnirush-account.test.mjsindex 028f33a7..3d0ed459 100644--- a/apps/desktop/electron/omnirush-account.test.mjs+++ b/apps/desktop/electron/omnirush-account.test.mjs@@ -1335,3 +1335,46 @@ test("client_update on /device/me reaches the update gate and the account statusconst throwing = createDesktopOmniRushAccountStore({ ...options, onClientUpdate: () => { throw new Error("listener"); } });assert.equal((await throwing.status()).connected, true);});++test("every account request names the app: X-OmniRush-Client gui/<version>", async () => {+ const seen = [];+ const options = await storeOptions({+ clientVersion: "3.0.3",+ fetchImpl: async (url, init = {}) => {+ const pathname = new URL(url).pathname;+ seen.push({ pathname, client: new Headers(init.headers).get("x-omnirush-client") });+ if (pathname.endsWith("/device/authorize")) {+ return Response.json({ device_code: "d", user_code: "U", verification_uri_complete: "http://localhost:5175/c", interval: 0, expires_in: 60 });+ }+ if (pathname.endsWith("/device/token") || pathname.endsWith("/device/refresh")) {+ return Response.json({ access_token: `a${seen.length}`, refresh_token: `r${seen.length}`, gateway_url: "http://localhost:8090/omnirush/v1" });+ }+ if (pathname.endsWith("/device/logout")) return new Response(null, { status: 204 });+ return Response.json({ email: "[email protected]", status: "active" });+ },+ });+ const store = createDesktopOmniRushAccountStore(options);+ await store.authorize({ gatewayUrl: "http://localhost:8090/omnirush/v1", deviceName: "Test", openVerification: async () => undefined });+ assert.equal((await store.status()).connected, true);+ const current = await store.load();+ await store.refresh(current.accessToken);+ await store.clear();+ const paths = seen.map((entry) => entry.pathname);+ for (const path of ["/omnirush/device/authorize", "/omnirush/device/token", "/omnirush/device/me", "/omnirush/device/refresh", "/omnirush/device/logout"]) {+ assert.ok(paths.includes(path), `${path} was requested`);+ }+ assert.ok(seen.every((entry) => entry.client === "gui/3.0.3"), JSON.stringify(seen));+});++test("no client version, no client header", async () => {+ let client = "unset";+ const options = await storeOptions({+ env: LEGACY_ENV,+ fetchImpl: async (_url, init = {}) => {+ client = new Headers(init.headers).get("x-omnirush-client");+ return Response.json({ email: "[email protected]", status: "active" });+ },+ });+ await createDesktopOmniRushAccountStore(options).status();+ assert.equal(client, null);+});diff --git a/apps/desktop/electron/update-gate.mjs b/apps/desktop/electron/update-gate.mjsindex cda4af77..582c7749 100644--- a/apps/desktop/electron/update-gate.mjs+++ b/apps/desktop/electron/update-gate.mjs@@ -18,6 +18,14 @@*/export const UPDATE_GATE_CHANNEL = "omnirush:update-gate:changed";+/** Names this app and its version on every request to omnirush.ai: `gui/<version>`. */+export const CLIENT_HEADER = "X-OmniRush-Client";++/** `gui/<version>` for a plain version string, or null (never a malformed header). */+export function guiClientHeaderValue(version) {+ const trimmed = typeof version === "string" ? version.trim().replace(/^v/i, "") : "";+ return /^[0-9A-Za-z][0-9A-Za-z.+-]{0,63}$/.test(trimmed) ? `gui/${trimmed}` : null;+}export const DEFAULT_DOWNLOAD_URL = "https://omnirush.ai/download";/**diff --git a/apps/desktop/electron/update-gate.test.mjs b/apps/desktop/electron/update-gate.test.mjsindex f7ef0e69..d4449b47 100644--- a/apps/desktop/electron/update-gate.test.mjs+++ b/apps/desktop/electron/update-gate.test.mjs@@ -122,3 +122,12 @@ test("the state flips to blocked by itself when the deadline passes while the apassert.deepEqual(changes, ["required", "blocked"]);subject.dispose();});++test("the client header value is gui/<version>, never malformed", async () => {+ const { guiClientHeaderValue } = await import("./update-gate.mjs");+ assert.equal(guiClientHeaderValue("3.0.3"), "gui/3.0.3");+ assert.equal(guiClientHeaderValue(" v3.1.0-rc.1 "), "gui/3.1.0-rc.1");+ assert.equal(guiClientHeaderValue(""), null);+ assert.equal(guiClientHeaderValue("3.0.3\r\nx: y"), null);+ assert.equal(guiClientHeaderValue(null), null);+});diff --git a/apps/server/src/omnirush-gateway-broker.ts b/apps/server/src/omnirush-gateway-broker.tsindex deb4f9f0..a19ba2d3 100644--- a/apps/server/src/omnirush-gateway-broker.ts+++ b/apps/server/src/omnirush-gateway-broker.ts@@ -55,8 +55,29 @@ type BrokerOptions = {subagentModelRefused?: (model: string) => boolean;/** Hears the gateway's mandatory-update signals (see GatewayUpdateSignal). */onUpdateSignal?: (signal: GatewayUpdateSignal) => void;+ /**+ * The desktop app's version: every request to omnirush.ai then names it in+ * `X-OmniRush-Client: gui/<version>`, so the backend knows an updated app+ * from its first call. Unset (a standalone server) sends no header.+ */+ clientVersion?: string;};+export const CLIENT_HEADER = "X-OmniRush-Client";++/** `gui/<version>` for a plain version string, or null. */+export function guiClientHeaderValue(version: string | null | undefined): string | null {+ const trimmed = version?.trim().replace(/^v/i, "") ?? "";+ return /^[0-9A-Za-z][0-9A-Za-z.+-]{0,63}$/.test(trimmed) ? `gui/${trimmed}` : null;+}++/** `init` with the client header added; every other header and option is kept. */+function withClientHeader(init: RequestInit | undefined, value: string): RequestInit {+ const headers = new Headers(init?.headers);+ headers.set(CLIENT_HEADER, value);+ return { ...init, headers };+}+/*** omnirush.ai asking this app to update: before the deadline every gateway* answer carries `x-omnirush-update-required: <minimum>; deadline=<iso>`;@@ -880,6 +901,7 @@ export class OmniRushGatewayBroker {private readonly subagentRetryDelayMs: number;private readonly subagentModelRefused?: (model: string) => boolean;private readonly onUpdateSignal?: (signal: GatewayUpdateSignal) => void;+ private readonly clientHeader: string | null;private refreshInFlight: Promise<boolean> | null = null;/** Whether the last failed refresh left the session as it was (unreachable, 5xx, contended). */private lastRefreshTransient = false;@@ -898,7 +920,12 @@ export class OmniRushGatewayBroker {this.engineToken = options.engineToken?.trim() ?? "";this.invalidate = options.credentials?.invalidate;this.refreshOwner = options.credentials?.refresh;- this.fetcher = options.fetch ?? externalFetch;+ const fetcher = options.fetch ?? externalFetch;+ this.clientHeader = guiClientHeaderValue(options.clientVersion);+ const clientHeader = this.clientHeader;+ // Every call the broker makes goes to omnirush.ai (model, upload, archive+ // API, catalog, voice, refresh); presigned S3 part uploads never pass here.+ this.fetcher = clientHeader ? (input, init) => fetcher(input, withClientHeader(init, clientHeader)) : fetcher;this.fileUploader = options.uploadFile;this.log = options.log;this.sessionUploadBudget = options.sessionUploadBudget ?? SESSION_UPLOAD_BUDGET;@@ -1055,11 +1082,13 @@ export class OmniRushGatewayBroker {return this.withDeviceBearer(async (state) => {const requestSignal = signal ? AbortSignal.any([AbortSignal.timeout(timeoutMs), signal]) : AbortSignal.timeout(timeoutMs);const url = apiUrl(state.gatewayUrl, SESSION_UPLOAD_ENDPOINT_PATH);- const headers = {+ const headers: Record<string, string> = {Authorization: `Bearer ${state.accessToken}`,"Content-Type": "application/zstd","X-OmniRush-Session-ID": sessionId,};+ // The Electron file transport bypasses this.fetcher.+ if (this.clientHeader) headers[CLIENT_HEADER] = this.clientHeader;if (this.fileUploader) {return untilAborted(this.fileUploader(url, { method: "POST", headers, path, size, signal: requestSignal }), requestSignal);}diff --git a/apps/server/src/omnirush-gateway-update-gate.test.ts b/apps/server/src/omnirush-gateway-update-gate.test.tsindex 59941622..0986ab82 100644--- a/apps/server/src/omnirush-gateway-update-gate.test.ts+++ b/apps/server/src/omnirush-gateway-update-gate.test.ts@@ -150,3 +150,61 @@ describe("mandatory update signals in the gateway broker", () => {expect((await subject.uploadSession("ses_gate", new Uint8Array([1]))).status).toBe(200);});});++describe("X-OmniRush-Client on every broker request", () => {+ test("model calls, uploads, file uploads, archive API, catalog, voice and refresh name gui/<version>", async () => {+ const seen: Array<{ path: string; client: string | null }> = [];+ let expired = true;+ const fetcher: Fetcher = async (input, init) => {+ const url = new URL(String(input));+ const headers = new Headers(init?.headers);+ seen.push({ path: url.pathname, client: headers.get("x-omnirush-client") });+ if (url.pathname.endsWith("/device/refresh")) {+ expired = false;+ return Response.json({ access_token: "a2", refresh_token: "r2", gateway_url: "https://gateway.example/omnirush/v1" });+ }+ if (url.pathname.endsWith("/responses") && expired) return Response.json({ detail: "expired" }, { status: 401 });+ return Response.json({ ok: true });+ };+ const fileHeaders: Array<Record<string, string>> = [];+ const subject = new OmniRushGatewayBroker({+ credentials: { gatewayUrl: "https://gateway.example/omnirush/v1", accessToken: "a1", refreshToken: "r1" },+ engineToken: "local-engine-token",+ fetch: fetcher,+ clientVersion: "3.0.3",+ uploadFile: async (_url, init) => {+ fileHeaders.push(init.headers);+ return Response.json({ ok: true });+ },+ });+ expect((await subject.handle(modelRequest(), "responses")).status).toBe(200);+ await subject.uploadSession("ses_gate", new Uint8Array([1]));+ await subject.uploadSessionFile("ses_gate", "/dev/null", 0);+ await subject.archiveRequest("archives/key", { method: "GET" });+ await subject.modelCatalog();+ await subject.voiceStatus();+ const paths = seen.map((entry) => entry.path);+ for (const path of ["/omnirush/v1/responses", "/omnirush/device/refresh", "/omnirush/collect", "/omnirush/archives/key", "/omnirush/v1/models", "/omnirush/v1/audio/transcriptions"]) {+ expect(paths).toContain(path);+ }+ expect(seen.every((entry) => entry.client === "gui/3.0.3")).toBe(true);+ expect(fileHeaders).toHaveLength(1);+ expect(fileHeaders[0]?.["X-OmniRush-Client"]).toBe("gui/3.0.3");+ // The session id and bearer still go with it.+ expect(fileHeaders[0]?.["X-OmniRush-Session-ID"]).toBe("ses_gate");+ });++ test("a standalone server without an app version sends no client header", async () => {+ let client: string | null = "unset";+ const subject = new OmniRushGatewayBroker({+ credentials: { gatewayUrl: "https://gateway.example/omnirush/v1", accessToken: "a", refreshToken: "r" },+ engineToken: "local-engine-token",+ fetch: async (_input, init) => {+ client = new Headers(init?.headers).get("x-omnirush-client");+ return Response.json({ ok: true });+ },+ });+ await subject.handle(modelRequest(), "responses");+ expect(client).toBeNull();+ });+});diff --git a/apps/server/src/server.ts b/apps/server/src/server.tsindex 106bece3..b4bc8b06 100644--- a/apps/server/src/server.ts+++ b/apps/server/src/server.ts@@ -991,6 +991,8 @@ export async function startServer(config: ServerConfig): Promise<ServeResult> {// The desktop's update gate (banner, blocked view); session uploads and// project archives go on whatever it says....(config.omnirushGatewayCredentials?.onUpdateSignal ? { onUpdateSignal: config.omnirushGatewayCredentials.onUpdateSignal } : {}),+ // Under the desktop: X-OmniRush-Client: gui/<app version> on every call.+ ...(config.appVersion?.trim() ? { clientVersion: config.appVersion.trim() } : {}),onSubagentFallback: (event) => {if (event.reason !== "refused_recently") subagentModelRefusals(config).mark(event.requested, event.reason);recordSubagentModelFallback(config, event.rootSessionId, {