diff --git a/paseo-omp/README.md b/paseo-omp/README.md index 305c2c87..62bb306e 100644 --- a/paseo-omp/README.md +++ b/paseo-omp/README.md @@ -35,7 +35,7 @@ Open the **OMP** sidebar to review the provider-profile contract, choose which c Open the **Accounts** tab of the **OMP** sidebar to see the logins in OMP's own credential store with their usage and banked resets, add a login through OMP's own sign-in, sign one out, spend a banked reset, and steer OMP's balancing: prefer a login, keep part of its quota in reserve, and set what OMP does at a limit. Steering is written to OMP's own config. See [OMP accounts](docs/configuration.md#omp-accounts). -The quota popover groups recorded limits by provider and OMP account, showing an available recorded email or, when absent, the Copilot account ID (GitHub username) across that account's windows. Duplicate and unnamed accounts receive numbers in opaque account-key order, so changing usage does not swap their numbers; accounts are still displayed by highest usage. Duplicate-name suffixes stay visible when long emails truncate, and a lone unnamed account needs no heading. Copilot accounts also show **GitHub** or **GHE · host**, using the enterprise URL in OMP's recorded account key; unrecognized keys show neither. Only a server-side SHA-256 hash of the account key reaches the client. **CURRENT PROVIDER** identifies the session's provider, not its active account. Provider summary percentages show the highest recorded usage across that provider's accounts. +The quota popover groups recorded limits by provider and OMP account, showing an available recorded email or, when absent, the Copilot account ID (GitHub username) across that account's windows. Duplicate and unnamed accounts receive numbers in opaque account-key order, so changing usage does not swap their numbers; accounts are still displayed by highest usage. Duplicate-name suffixes stay visible when long emails truncate, and a lone unnamed account needs no heading. Copilot accounts also show **GitHub** or **GHE · host**, using the enterprise URL in OMP's recorded account key; unrecognized keys show neither. Only a server-side SHA-256 hash of the account key reaches the client. **CURRENT PROVIDER** identifies the session's provider, not its active account. Paseo sees an OMP Plugin agent's model only as an opaque id, so the pill and popover ask the agent's live OMP session which provider that model belongs to; a closed OMP Plugin agent shows every provider until its session runs again. Provider summary percentages show the highest recorded usage across that provider's accounts. Open the **MCPs** tab of the **OMP** sidebar to list the MCP servers OMP connects to, add one by URL or command, test, enable, disable or remove it, and sign a remote server in through your browser, like **Accounts** does for logins. See [OMP MCP servers](docs/configuration.md#omp-mcp-servers). diff --git a/paseo-omp/client/quota-popover.tsx b/paseo-omp/client/quota-popover.tsx index aa44582e..a68cbada 100644 --- a/paseo-omp/client/quota-popover.tsx +++ b/paseo-omp/client/quota-popover.tsx @@ -4,9 +4,10 @@ import { useQuery } from "@tanstack/react-query"; import { useMemo } from "react"; import { Text, View } from "react-native"; import { storeForProvider, storeLabel } from "../shared/omp-store"; -import { listOmpQuotas } from "../shared/quota"; +import { getOmpSessionModelProvider, listOmpQuotas } from "../shared/quota"; import { ompStoreKey } from "./omp-store-state"; import { + needsSessionModelProvider, type QuotaProviderGroup, quotaDetailLabel, quotaProviderFromSession, @@ -21,8 +22,31 @@ const QUOTA_POLL_MS = 30_000; export function QuotaPopover(props: PluginButtonContentProps) { const { theme, layout } = props; const agentId = props.context === "agent" ? props.agentId : ""; - const session = useAgent(agentId, (agent) => ({ model: agent.model, provider: agent.provider })); - const currentProvider = quotaProviderFromSession(session?.provider ?? "", session?.model ?? null); + const session = useAgent(agentId, (agent) => ({ + model: agent.model, + provider: agent.provider, + status: agent.status, + })); + const loadSessionModelProvider = useRpc(getOmpSessionModelProvider); + const sessionModelProvider = useQuery({ + // The answer comes from the live session, so a closed or resumed session asks again. + queryKey: [ + "paseo-omp", + "session-model-provider", + agentId, + session?.model ?? null, + session?.status ?? null, + ], + queryFn: () => loadSessionModelProvider({ agentId }), + enabled: Boolean( + agentId && session && needsSessionModelProvider(session.provider, session.model), + ), + retry: false, + }); + const currentProvider = + quotaProviderFromSession(session?.provider ?? "", session?.model ?? null) ?? + sessionModelProvider.data?.provider ?? + null; const store = storeForProvider(session?.provider); const loadQuotas = useRpc(listOmpQuotas); const quotas = useQuery({ diff --git a/paseo-omp/client/quota-state.ts b/paseo-omp/client/quota-state.ts index 9518a602..2c744bfa 100644 --- a/paseo-omp/client/quota-state.ts +++ b/paseo-omp/client/quota-state.ts @@ -43,6 +43,15 @@ export function quotaProviderFromSession( return model?.includes("/") ? model.split("/")[0] : null; } +/** An OMP Plugin agent's model reaches Paseo as an opaque id; its live session names the provider. */ +export function needsSessionModelProvider(provider: string, model: string | null): boolean { + return ( + isOmpProvider(provider.split("/")[0]) && + Boolean(model) && + quotaProviderFromSession(provider, model) === null + ); +} + export function quotaProviderLabel(provider: string | null): string { return provider ? (PROVIDER_LABELS[provider] ?? `${provider.slice(0, 1).toUpperCase()}${provider.slice(1)}`) diff --git a/paseo-omp/index.client.tsx b/paseo-omp/index.client.tsx index eabeeb15..2baab67d 100644 --- a/paseo-omp/index.client.tsx +++ b/paseo-omp/index.client.tsx @@ -28,6 +28,7 @@ import { quotaProviderIcon } from "./client/provider-icon"; import { OmpImageTimeline } from "./client/provider-image"; import { QuotaPopover } from "./client/quota-popover"; import { + needsSessionModelProvider, type QuotaSeverity, quotaProviderFromSession, quotaSeverityForProvider, @@ -61,7 +62,7 @@ import { import { OMP_MCP_AUTH_TIMELINE_KIND, ompMcpAuthorizationTimelineSchema } from "./shared/mcp"; import { type OmpStore, storeForProvider } from "./shared/omp-store"; import { ompImageTimelineSchema, transformOmpImageToolItem } from "./shared/provider-image"; -import { listOmpQuotas } from "./shared/quota"; +import { getOmpSessionModelProvider, listOmpQuotas } from "./shared/quota"; import { OMP_RULE_NOTICE_KIND, ompRuleNoticeSchema } from "./shared/rule-notices"; import { OMP_SUBAGENT_STRIP_KIND, ompSubagentStripSchema } from "./shared/subagents"; @@ -382,15 +383,40 @@ export default function contribute(client: PluginClientContext) { } } + // Agent id to its session's provider, asked again only when the agent's model or status changes. + const sessionModelProviders = new Map(); + + async function sessionModelProvider(agent: AgentEntry["agent"]): Promise { + if (agent.status === "closed" || !needsSessionModelProvider(agent.provider, agent.model)) { + return null; + } + const key = `${agent.model}|${agent.status}`; + const cached = sessionModelProviders.get(agent.id); + if (cached?.key === key) return cached.provider; + try { + const { provider } = await client.rpc(getOmpSessionModelProvider, { agentId: agent.id }); + sessionModelProviders.set(agent.id, { key, provider }); + return provider; + } catch { + return null; + } + } + async function reconcileOnce(): Promise { if (!preferences) return; - const agents = await loadAgents(client.paseo); + const listed = (await loadAgents(client.paseo)).filter( + ({ agent }) => !agent.archivedAt && agent.workspaceId && agent.cwd, + ); + const sessionProviders = await Promise.all( + listed.map(({ agent }) => sessionModelProvider(agent)), + ); if (disposed || !preferences) return; const activeIds = new Set(); - for (const { agent } of agents) { - if (agent.archivedAt || !agent.workspaceId || !agent.cwd) continue; + for (const [index, { agent }] of listed.entries()) { + if (!agent.workspaceId || !agent.cwd) continue; activeIds.add(agent.id); - const quotaProvider = quotaProviderFromSession(agent.provider, agent.model); + const quotaProvider = + quotaProviderFromSession(agent.provider, agent.model) ?? sessionProviders[index]; const store = storeForProvider(agent.provider); let entry = pills.get(agent.id); if ( @@ -419,6 +445,9 @@ export default function contribute(client: PluginClientContext) { removePills(entry); pills.delete(agentId); } + for (const agentId of sessionModelProviders.keys()) { + if (!activeIds.has(agentId)) sessionModelProviders.delete(agentId); + } await Promise.all([refreshHubStatus(), refreshQuotaStatus()]); } diff --git a/paseo-omp/index.server.ts b/paseo-omp/index.server.ts index cd5c27aa..dd618f25 100644 --- a/paseo-omp/index.server.ts +++ b/paseo-omp/index.server.ts @@ -57,6 +57,7 @@ import { ompRuleNoticeRow } from "./server/rule-notices"; import { OmpSubagentControlRegistry, resolveCancelOmpSubagent, + resolveGetOmpSessionModelProvider, resolveSteerOmpSubagent, } from "./server/subagents"; import { resolveGetOmpSupportReport } from "./server/support-diagnostics"; @@ -116,7 +117,7 @@ import { getOmpUpdateStatus, installOmpUpdate } from "./shared/omp-update"; import { getOmpProviderHealth } from "./shared/provider-diagnostics"; import { getOmpImage } from "./shared/provider-image"; import { providerLaunchSettings } from "./shared/provider-launch-settings"; -import { listOmpQuotas } from "./shared/quota"; +import { getOmpSessionModelProvider, listOmpQuotas } from "./shared/quota"; import { cancelOmpSubagent, steerOmpSubagent } from "./shared/subagents"; import { getOmpSupportReport } from "./shared/support-diagnostics"; @@ -283,6 +284,9 @@ export default function contribute(server: PluginServerContext) { server.handle(steerOmpSubagent, (input) => resolveSteerOmpSubagent(input, subagentControlRegistry), ); + server.handle(getOmpSessionModelProvider, (input) => + resolveGetOmpSessionModelProvider(input, subagentControlRegistry), + ); const removeTurnRows = registerOmpTurnRows(server, [ompRuleNoticeRow, ompScreenshotRow]); const removeSessionOpenHook = server.before("agent.session_open", ({ request }) => { if (request.provider !== "omp-plugin" && !request.provider.startsWith("omp-plugin-")) return; diff --git a/paseo-omp/server/provider/session.ts b/paseo-omp/server/provider/session.ts index 1c9dc8a9..dad377d4 100644 --- a/paseo-omp/server/provider/session.ts +++ b/paseo-omp/server/provider/session.ts @@ -482,6 +482,15 @@ export class OmpProviderSession implements OmpOpenedSession, OmpSubagentControls await target.runtime.steerSubagent(target.nativeId, message); } + /** Paseo publishes the model as an opaque id; only the session can map it back to OMP's model. */ + modelProvider(): string | null { + if (this.closed || this.runtimeDead) return null; + const model = this.configState.model + ? this.nativeModelsByPublicId.get(this.configState.model) + : undefined; + return model?.provider ?? null; + } + /** * The native ID and runtime of a subagent this session's current runtime lists as running, or * `null`. OMP repeats the check; this scopes the request to this session and answers exactly. diff --git a/paseo-omp/server/subagents.ts b/paseo-omp/server/subagents.ts index 5d15e1ad..8499b6b7 100644 --- a/paseo-omp/server/subagents.ts +++ b/paseo-omp/server/subagents.ts @@ -1,4 +1,5 @@ import type { RpcInput, RpcOutput } from "@getpaseo/plugin"; +import type { getOmpSessionModelProvider } from "../shared/quota"; import type { cancelOmpSubagent, steerOmpSubagent } from "../shared/subagents"; import { OmpRpcRequestRejectedError } from "./provider/omp-rpc-transport"; import { isOmpPublicError, OmpPublicError } from "./provider/security"; @@ -8,6 +9,8 @@ export interface OmpSubagentControls { /** Resolves `false` when the subagent is no longer running. */ cancelSubagent(handle: string): Promise; steerSubagent(handle: string, message: string): Promise; + /** The OMP provider of the session's current model, or null once the session has ended. */ + modelProvider(): string | null; } export class OmpSubagentNotRunningError extends OmpPublicError { @@ -95,3 +98,11 @@ export async function resolveSteerOmpSubagent( await withPublicFailure("steer", () => controls.steerSubagent(input.subagentId, input.message)); return { accepted: true }; } + +/** No live session (closed, history-only or another daemon's) answers null rather than failing. */ +export function resolveGetOmpSessionModelProvider( + input: RpcInput, + registry: OmpSubagentControlRegistry, +): RpcOutput { + return { provider: registry.get(input.agentId)?.modelProvider() ?? null }; +} diff --git a/paseo-omp/shared/quota.ts b/paseo-omp/shared/quota.ts index be39817b..098f3e0a 100644 --- a/paseo-omp/shared/quota.ts +++ b/paseo-omp/shared/quota.ts @@ -30,3 +30,13 @@ export const listOmpQuotas = defineRpc({ input: z.object({ store: OmpStoreSchema.optional() }), output: z.object({ quotas: z.array(OmpQuotaSchema) }), }); + +/** + * The OMP provider (such as `anthropic`) of the model an OMP Plugin agent's live session uses. + * Paseo only sees that model as an opaque id, so the provider is null without a live session. + */ +export const getOmpSessionModelProvider = defineRpc({ + name: "paseo-omp.session-model-provider", + input: z.object({ agentId: z.string().min(1).max(256) }), + output: z.object({ provider: z.string().nullable() }), +}); diff --git a/paseo-omp/tests/profile-pills.test.ts b/paseo-omp/tests/profile-pills.test.ts index 3ebec612..323a57ce 100644 --- a/paseo-omp/tests/profile-pills.test.ts +++ b/paseo-omp/tests/profile-pills.test.ts @@ -22,7 +22,7 @@ vi.mock("../client/generated-image", () => ({ OmpGeneratedImagesRow: () => null vi.mock("../client/ast-edit", () => ({ OmpAstEditCard: () => null })); import contribute from "../index.client"; -import { listOmpQuotas } from "../shared/quota"; +import { getOmpSessionModelProvider, listOmpQuotas } from "../shared/quota"; afterEach(() => { vi.useRealTimers(); @@ -179,3 +179,95 @@ test("owned agent directory updates reconcile new agent pills and cached quota r dispose(); } }); + +test("summarizes an OMP Plugin agent's quota by the provider its live session names", async () => { + vi.useFakeTimers(); + const agents = [ + { id: "live", provider: "omp-plugin", model: "omp:model:opaque", status: "idle" }, + { id: "ended", provider: "omp-plugin", model: "omp:model:opaque", status: "closed" }, + ]; + let onDirectoryUpdate = () => {}; + const buttons: Array<{ id: string; agentId: string; update: ReturnType }> = []; + const rpc = vi.fn(async (definition, input) => { + if (definition.name === "settings.composer-pills.read") { + return { status: "ready", revision: "r", values: { quota: true } }; + } + if (definition === getOmpSessionModelProvider) { + return { provider: input.agentId === "live" ? "openai-codex" : null }; + } + if (definition !== listOmpQuotas) return { processes: [] }; + const row = { label: "Window", windowLabel: null, status: "ok", resetsAt: null, recordedAt: 1 }; + return { + quotas: [ + { ...row, provider: "anthropic", usedFraction: 0.9 }, + { ...row, provider: "openai-codex", usedFraction: 0.3 }, + ], + }; + }); + const registration = () => () => {}; + const list = async (options?: { subscribe?: object }) => { + const result = { + entries: agents.map((agent) => ({ + agent: { ...agent, cwd: "/workspace", workspaceId: "workspace", archivedAt: null }, + })), + pageInfo: { hasMore: false }, + }; + if (!options?.subscribe) return result; + return { + ...result, + subscription: { + ready: Promise.resolve(result), + subscribe: (observer: { update: () => void }) => { + onDirectoryUpdate = observer.update; + return () => {}; + }, + release: async () => {}, + }, + }; + }; + const client = { + paseo: { agents: { list } }, + rpc, + addWorkspacePanel: registration, + addCommandCenterItem: registration, + addScreen: registration, + addSidebarHeaderItem: registration, + openScreen: vi.fn(), + addTimelineRenderer: registration, + addTimelineTransformer: registration, + addComposerPill: (options: { id: string; agentId: string }) => { + const button = { ...options, update: vi.fn(), remove: vi.fn() }; + buttons.push(button); + return button; + }, + } as unknown as PluginClientContext; + const dispose = contribute(client); + const quota = (agentId: string) => + buttons.findLast((button) => button.id === "quota" && button.agentId === agentId)?.update; + const asked = () => + rpc.mock.calls + .filter(([definition]) => definition === getOmpSessionModelProvider) + .map(([, input]) => input.agentId); + try { + await vi.advanceTimersByTimeAsync(300); + expect(quota("live")).toHaveBeenLastCalledWith( + expect.objectContaining({ label: "OpenAI · 30%" }), + ); + // A closed agent has no session to ask and keeps the all-provider summary. + expect(quota("ended")).toHaveBeenLastCalledWith( + expect.objectContaining({ label: "Quotas · 90%" }), + ); + expect(asked()).toEqual(["live"]); + + // The same model and status reuse the answer; a new model asks again. + onDirectoryUpdate(); + await vi.advanceTimersByTimeAsync(250); + expect(asked()).toEqual(["live"]); + agents[0].model = "omp:model:other"; + onDirectoryUpdate(); + await vi.advanceTimersByTimeAsync(250); + expect(asked()).toEqual(["live", "live"]); + } finally { + dispose(); + } +}); diff --git a/paseo-omp/tests/provider-subagent-control.test.ts b/paseo-omp/tests/provider-subagent-control.test.ts index a3189586..0b688908 100644 --- a/paseo-omp/tests/provider-subagent-control.test.ts +++ b/paseo-omp/tests/provider-subagent-control.test.ts @@ -7,6 +7,7 @@ import { OmpSubagentControlRegistry, type OmpSubagentControls, resolveCancelOmpSubagent, + resolveGetOmpSessionModelProvider, resolveSteerOmpSubagent, } from "../server/subagents"; import { OMP_SUBAGENT_STRIP_KIND, ompSubagentStripSchema } from "../shared/subagents"; @@ -451,11 +452,26 @@ describe("OMP subagent controls", () => { await connection.close(); }); + test("names the OMP provider behind an agent's opaque model only while its session runs", async () => { + const { connection, events, runtime, registry } = await createControlledHarness(); + await openSession(connection, events, "open-a", "session-a", { PASEO_AGENT_ID: "agent-a" }); + const provider = (agentId: string) => + resolveGetOmpSessionModelProvider({ agentId }, registry).provider; + + expect(provider("agent-a")).toBe("anthropic"); + expect(provider("agent-unknown")).toBeNull(); + sessionAt(runtime, 0).emit({ type: "process_exit", error: "OMP exited between turns" }); + await Promise.resolve(); + expect(provider("agent-a")).toBeNull(); + await connection.close(); + }); + test("lets a newer session replace an agent's controls without the older cleanup removing it", () => { const registry = new OmpSubagentControlRegistry(); const controls = (): OmpSubagentControls => ({ cancelSubagent: async () => false, steerSubagent: async () => {}, + modelProvider: () => null, }); const older = controls(); const newer = controls(); diff --git a/paseo-omp/tests/quota-popover-session-provider.test.tsx b/paseo-omp/tests/quota-popover-session-provider.test.tsx new file mode 100644 index 00000000..c1fe0ccf --- /dev/null +++ b/paseo-omp/tests/quota-popover-session-provider.test.tsx @@ -0,0 +1,125 @@ +// @vitest-environment happy-dom +import type { PluginButtonContentProps } from "@getpaseo/plugin/client"; +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; +import { act, type ReactNode } from "react"; +import { createRoot, type Root } from "react-dom/client"; +import { afterEach, beforeEach, expect, test, vi } from "vitest"; +import { QuotaPopover } from "../client/quota-popover"; +import { getOmpSessionModelProvider, type OmpQuota } from "../shared/quota"; + +// The agent as Paseo reports it, and the provider its live session names (null once it ends). +const agent = vi.hoisted(() => ({ + status: "idle", + sessionProvider: null as string | null, + asked: 0, +})); + +vi.mock("@getpaseo/plugin/client", () => ({ + useAgent: () => ({ provider: "omp-plugin", model: "omp:model:opaque", status: agent.status }), + usePaseo: () => ({}), + useRpc: (definition: unknown) => async () => { + if (definition === getOmpSessionModelProvider) { + agent.asked += 1; + return { provider: agent.sessionProvider }; + } + return { quotas: [quota("anthropic"), quota("openai-codex")], accounts: [] }; + }, +})); +vi.mock("@getpaseo/plugin/client/ui", () => ({ Icon: () => null })); +vi.mock("react-native", () => ({ + View: (props: { children?: ReactNode }) =>
{props.children}
, + Text: (props: { children?: ReactNode }) => {props.children}, + Pressable: (props: { children?: ReactNode }) => , +})); + +function quota(provider: string): OmpQuota { + return { + provider, + accountKey: provider, + limitId: "weekly", + email: null, + accountId: null, + accountService: null, + accountHost: null, + label: "Usage", + windowLabel: "Weekly", + usedFraction: 0.5, + status: "ok", + resetsAt: null, + recordedAt: 1, + }; +} + +const props: PluginButtonContentProps = { + context: "agent", + workspaceId: "synthetic-workspace", + agentId: "synthetic-agent", + host: { id: "synthetic-host", label: "Test host" }, + layout: { compact: false, platform: "web" }, + close() {}, + theme: { + colors: { + surface0: "#111111", + surface1: "#222222", + surface2: "#333333", + border: "#444444", + foreground: "#eeeeee", + foregroundMuted: "#aaaaaa", + accent: "#008800", + accentForeground: "#ffffff", + statusSuccess: "#008800", + statusWarning: "#aa8800", + statusDanger: "#aa0000", + }, + }, +}; + +let container: HTMLDivElement; +let root: Root; +let client: QueryClient; + +beforeEach(() => { + vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true); + container = document.createElement("div"); + document.body.append(container); + root = createRoot(container); + client = new QueryClient({ defaultOptions: { queries: { retry: false } } }); +}); + +afterEach(async () => { + await act(() => root.unmount()); + client.clear(); + container.remove(); + vi.unstubAllGlobals(); +}); + +/** Re-renders the open popover, as Paseo does when the agent's status changes. */ +async function show(status: string, sessionProvider: string | null) { + agent.status = status; + agent.sessionProvider = sessionProvider; + await act(async () => { + root.render( + + + , + ); + }); +} + +const currentProvider = () => container.textContent?.includes("CURRENT PROVIDER") ?? false; + +test("asks the session for its provider again when it ends or resumes while the popover is open", async () => { + // Opened before the session runs: nothing to name yet. + await show("closed", null); + await vi.waitFor(() => expect(agent.asked).toBe(1)); + expect(currentProvider()).toBe(false); + + // The same model resumes: the popover asks again and marks the provider. + await show("idle", "anthropic"); + await vi.waitFor(() => expect(currentProvider()).toBe(true)); + expect(agent.asked).toBe(2); + + // The session ends: the earlier answer is not kept. + await show("closed", null); + await vi.waitFor(() => expect(currentProvider()).toBe(false)); +});