mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-08 01:14:52 +00:00
Compare commits
74
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
152a5ae731 | ||
|
|
9f39663722 | ||
|
|
568bd447e3 | ||
|
|
41a36fa593 | ||
|
|
f91ec81f7c | ||
|
|
af2fb8ab35 | ||
|
|
cdc64ecfa4 | ||
|
|
042bc36ba5 | ||
|
|
4f6e71e8d6 | ||
|
|
51505a7d3b | ||
|
|
13c318838f | ||
|
|
d9fb2ffe93 | ||
|
|
0d82eed6b5 | ||
|
|
2ec0ac3c25 | ||
|
|
6cb9685a6d | ||
|
|
8a972b8c2e | ||
|
|
cc56b392de | ||
|
|
cb331532ad | ||
|
|
da994fb400 | ||
|
|
c4baf750f2 | ||
|
|
31a408d108 | ||
|
|
3be00f5105 | ||
|
|
6e704f803c | ||
|
|
949462f39b | ||
|
|
53d91d63da | ||
|
|
4709b49dc4 | ||
|
|
f938bf963d | ||
|
|
1131241b73 | ||
|
|
ce39ab6f09 | ||
|
|
c242f4d8db | ||
|
|
66aeff70d1 | ||
|
|
adf8badade | ||
|
|
1b45d92dac | ||
|
|
42ed0a8a99 | ||
|
|
d8fca6fdc6 | ||
|
|
77f97f82bc | ||
|
|
26b1e122ae | ||
|
|
7dfb63d0c4 | ||
|
|
5c81d08959 | ||
|
|
96b2bea130 | ||
|
|
33338be16e | ||
|
|
32230e24c5 | ||
|
|
d641cb5179 | ||
|
|
58094053dc | ||
|
|
3f75a11a49 | ||
|
|
f0807c5deb | ||
|
|
e0ff0959a1 | ||
|
|
591dd3bc92 | ||
|
|
8fb31cf8c0 | ||
|
|
b99d2a010d | ||
|
|
41011ddc60 | ||
|
|
e9d440259c | ||
|
|
0d697e6330 | ||
|
|
5413b8122c | ||
|
|
8960e76d19 | ||
|
|
218bcaaa6b | ||
|
|
30cc0a8c21 | ||
|
|
a362664f47 | ||
|
|
20ce734367 | ||
|
|
ca2bdd66eb | ||
|
|
1aaac5b231 | ||
|
|
b60b74384b | ||
|
|
034f639c88 | ||
|
|
55e8cff9f4 | ||
|
|
06be203c5c | ||
|
|
007a8e36ae | ||
|
|
eb6bed8447 | ||
|
|
bfbd4d5175 | ||
|
|
52b84b7835 | ||
|
|
d68271565a | ||
|
|
ce7b14a143 | ||
|
|
c7e137d4b4 | ||
|
|
d37262be56 | ||
|
|
0952ddbd4b |
+2
-1
@@ -593,7 +593,8 @@ rerun passes only by landing elsewhere.
|
||||
|
||||
To confirm, fetch the URL from several runners and compare `content-length`, the `cf-ray` colo
|
||||
suffix, and the number of `attestations` entries (#7730 has the probe). To fix, remove or
|
||||
replace that version in the lockfile and report the URL to npm so they purge it.
|
||||
replace that version in the lockfile. If the dependent’s range cannot be changed, pin a clean
|
||||
version in root `overrides` and regenerate the lockfile. Report the URL to npm so they purge it.
|
||||
|
||||
## ACP provider catalog versions
|
||||
|
||||
|
||||
+62
-3
@@ -30,6 +30,65 @@ at session startup. See [provider configuration](custom-providers.md#provider-op
|
||||
for defaults and merge rules, and the [SDK guide](../public-docs/sdk/provider-options.md)
|
||||
for native keys and examples.
|
||||
|
||||
### Options flow
|
||||
|
||||
`options` on the agent snapshot is the only option state. Controls describe how to draw an
|
||||
option and read `options`; they hold no value of their own. Any option can be read and set with
|
||||
or without a control.
|
||||
|
||||
- **Create and resume.** The provider opens with the options it is given and emits nothing about
|
||||
them while opening. `openOptionsPatch` carries every option the session ended up with that
|
||||
differs from what it was given, including a setting nobody asked for (a native default such as
|
||||
Cursor opening with Fast on). It is set before `createSession`/`resumeSession` resolves and the
|
||||
daemon stores it before the agent is published. A reopened agent resumes that state, so a
|
||||
native default the provider later changes does not follow. `options` on the snapshot is what
|
||||
the session opened with, and afterwards it moves only through an apply or an `options_changed`.
|
||||
Editing a provider default in `config.json` affects agents the next time they open.
|
||||
- **Live apply.** `applyOptions` receives the keys the patch touches, resolved against the
|
||||
`config.json` defaults. A removal arrives as the default the key falls back to, or `null` when
|
||||
there is none; the provider returns the setting to its own default if it can, or throws to
|
||||
reject. A key the running session cannot apply (one the provider reads only when it opens) is
|
||||
rejected too, so a stored option always describes what runs. Claude reads most options when it
|
||||
starts its query, and replacing a started query would end its background work, so after the
|
||||
first prompt only Fast can change. Codex fixes its approval policy and sandbox when the thread
|
||||
starts, so it applies only `service_tier` and `plan_mode` live. A session with no
|
||||
`applyOptions` rejects every patch; the daemon enforces this. The provider returns the options
|
||||
it ended up with when they differ from the request. The daemon
|
||||
stores the patch and that result in one step after the call resolves, onto the agent's options
|
||||
as they are at that moment, so the last write wins. Throwing rejects the whole patch and
|
||||
none of it is stored. Emit nothing from inside the call. If the provider's own state moved
|
||||
before it refused, it reports the moved values once as `options_changed` after the call has
|
||||
ended, because the stored options must match what runs.
|
||||
- **Old data converts in the agent manager.** Codex used to take `fast_mode`; it takes
|
||||
`service_tier` now. `AgentManager` runs `convertLegacyOptions` (`option-controls.ts`) on an
|
||||
agent's own options when it creates, resumes, imports, reloads or applies to it, and on draft
|
||||
controls, before defaults merge and before anything is stored (`true` is `"fast"`, `false` is
|
||||
`"default"`, and a `service_tier` in the same input wins). The manager converts for the adapter
|
||||
behind the provider id, following `derivedFromProviderId`, so a custom provider with
|
||||
`extends: "codex"` is converted too. Configured defaults convert in the provider registry. A
|
||||
stored record keeps `fast_mode` until the agent is next opened or applied to, and is stored
|
||||
converted from then on. Nothing past the manager sees `fast_mode` for Codex. Codex resolves
|
||||
`"fast"` to the model's Fast tier and reports the id it runs through `openOptionsPatch` or the
|
||||
`applyOptions` result like any other value. The `featureValues` to `options` fold is separate
|
||||
and provider-agnostic; it stays at the protocol and legacy edges.
|
||||
- **Clients draw from the daemon's answer.** The app reads `controls` and `options` from the
|
||||
agent snapshot for a running or closed agent. A draft and a profile form send everything they
|
||||
would create with (seed, the provider's last-used control values once the provider has said it
|
||||
still draws them, and the user's edits) in `provider.controls.list.request` and draw only what
|
||||
comes back, so an alias such as a legacy Fast profile's `service_tier: "fast"` is resolved once,
|
||||
by the daemon. A toggle shows over the last answer until its own answer arrives. The draft's
|
||||
layers live in a plain model (`agent-controls/draft-options-model.ts`): applying a profile
|
||||
replaces provider and options in one step, while choosing a provider by hand starts over. A
|
||||
profile saves its stored options plus the form's edits, so options no control draws survive an
|
||||
edit. A daemon without `server_info.features.providerOptionControls` sends `features` and
|
||||
`featureValues`; `packages/client/src/compat/legacy-provider-options.ts` is the one place that
|
||||
turns those into `controls` and `options` and back, so nothing in the app branches on it. A
|
||||
create that carries options first lists the controls for its own provider, model, mode and
|
||||
thinking level, since which options are controls differs by model, and sends those as
|
||||
`featureValues`; callers do not prime anything.
|
||||
- **Provider-initiated changes.** A setting the provider changes on its own is an
|
||||
`options_changed` event. The daemon stores and forwards it and does not push the old value back.
|
||||
|
||||
Exact MCP preapproval is a separate daemon-owned contract. A new provider must fail
|
||||
closed for Hub unattended execution until it can approve one exact injected MCP
|
||||
server and tool identity without approving native tools.
|
||||
@@ -115,7 +174,7 @@ Submitted user-message wire items carry the same Paseo ID in `messageId` and `cl
|
||||
|
||||
Provider adapters must terminalize every transient timeline row before emitting the turn's terminal event. Codex may omit the completed `contextCompaction` item when a turn ends during compaction, so its adapter closes any pending root compaction before forwarding `turn_completed`, `turn_failed`, or `turn_canceled`. A terminal turn must never leave the client showing an operation as still loading.
|
||||
|
||||
Draft metadata lookups should avoid creating provider sessions when the upstream provider has top-level APIs for that metadata. Prefer `AgentClient.fetchCatalog`, `listCommands`, or `listFeatures` over creating a scratch `AgentSession`; scratch sessions can show up as empty native sessions in provider import/history UIs. `fetchCatalog` is the single discovery API for models and modes — provider implementations may use one process, separate upstream calls, or static data internally, but callers outside the provider do not get separate runtime model/mode probes. Draft command listing and scratch-session feature listing require an explicit draft model. Do not resolve a default model through catalog discovery. A client-level `listFeatures` implementation may return features from an incomplete, model-less draft and owns which features are valid in that state.
|
||||
Draft metadata lookups should avoid creating provider sessions when the upstream provider has top-level APIs for that metadata. Prefer `AgentClient.fetchCatalog`, `listCommands`, or `listControls` over creating a scratch `AgentSession`; scratch sessions can show up as empty native sessions in provider import/history UIs. `fetchCatalog` is the single discovery API for models and modes — provider implementations may use one process, separate upstream calls, or static data internally, but callers outside the provider do not get separate runtime model/mode probes. Draft command listing and scratch-session control listing require an explicit draft model. Do not resolve a default model through catalog discovery. A client-level `listControls` implementation may return controls from an incomplete, model-less draft and owns which features are valid in that state.
|
||||
|
||||
Provider session import has its own contract. The picker calls `listImportableSessions` and receives rows only: provider handle, cwd, title, prompt previews, and last activity. Import calls `importSession({ providerHandleId, cwd })` for the selected row and must not call listing again. The provider returns the resumed session, storage config, persistence handle, and hydrated timeline for that one native session; `AgentManager.importProviderSession` seeds the daemon timeline and publishes the Paseo agent only after it is ready.
|
||||
|
||||
@@ -478,7 +537,7 @@ interface AgentSession {
|
||||
readonly provider: AgentProvider;
|
||||
readonly id: string | null;
|
||||
readonly capabilities: AgentCapabilityFlags;
|
||||
readonly features?: AgentFeature[];
|
||||
readonly controls?: AgentOptionControl[];
|
||||
run(prompt: AgentPromptInput, options?: AgentRunOptions): Promise<AgentRunResult>;
|
||||
startTurn(prompt: AgentPromptInput, options?: AgentRunOptions): Promise<{ turnId: string }>;
|
||||
steerActiveTurn?(prompt: AgentPromptInput, options: SteerActiveTurnOptions): Promise<SteerResult>;
|
||||
@@ -500,7 +559,7 @@ interface AgentSession {
|
||||
listCommands?(): Promise<AgentSlashCommand[]>;
|
||||
setModel?(modelId: string | null): Promise<void>;
|
||||
setThinkingOption?(thinkingOptionId: string | null): Promise<void | AgentProviderNotice>;
|
||||
setFeature?(featureId: string, value: unknown): Promise<void>;
|
||||
applyOptions?(options: ProviderOptions): Promise<void>;
|
||||
tryHandleOutOfBand?(prompt: AgentPromptInput): {
|
||||
run(ctx: { emit: (event: AgentStreamEvent) => void }): Promise<void>;
|
||||
} | null;
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
sha256-VdM4lXdgNEXPpTfvHSFvF9nm302rK/ZbVkZUp9tyOfg=
|
||||
sha256-p97CaALgkY+x9XVvS4/ILqmbwYSX0fSbVUgQl35BjiU=
|
||||
|
||||
Generated
+707
-615
File diff suppressed because it is too large
Load Diff
@@ -131,6 +131,7 @@
|
||||
"concurrently": "^9.2.1",
|
||||
"cross-env": "^10.1.0",
|
||||
"electron": "44.2.0",
|
||||
"electron-builder": "26.18.0",
|
||||
"expo-module-scripts": "^5.0.8",
|
||||
"get-port-cli": "^3.0.0",
|
||||
"js-yaml": "^4.1.1",
|
||||
@@ -151,6 +152,7 @@
|
||||
"expo": "~57.0.30",
|
||||
"expo-router": "~57.0.28",
|
||||
"lightningcss": "1.30.1",
|
||||
"pkijs": "3.4.2",
|
||||
"react": "19.2.3",
|
||||
"react-dom": "19.2.3",
|
||||
"react-native": "0.86.3",
|
||||
|
||||
@@ -62,7 +62,7 @@ async function readProviderFeaturePreferences(page: Page, provider: string): Pro
|
||||
const raw = localStorage.getItem(preferencesKey);
|
||||
if (!raw) return null;
|
||||
const preferences = JSON.parse(raw) as FormPreferences;
|
||||
return preferences.providerPreferences?.[providerId]?.featureValues ?? null;
|
||||
return preferences.providerPreferences?.[providerId]?.options ?? null;
|
||||
},
|
||||
{ preferencesKey: CREATE_AGENT_PREFERENCES_KEY, providerId: provider },
|
||||
);
|
||||
@@ -145,7 +145,7 @@ test.describe("Agent profiles repair modeless provider preferences", () => {
|
||||
provider: featureProviderId,
|
||||
model: featureModelId,
|
||||
modeId: "bypassPermissions",
|
||||
featureValues: { fast_mode: true },
|
||||
options: { fast_mode: true },
|
||||
},
|
||||
]);
|
||||
const provider = await seedModelProvider({
|
||||
@@ -181,7 +181,7 @@ test.describe("Agent profiles repair modeless provider preferences", () => {
|
||||
expect(createAgentRequest).toMatchObject({
|
||||
config: {
|
||||
provider: featureProviderId,
|
||||
featureValues: { fast_mode: true },
|
||||
providerOptions: { fast_mode: true },
|
||||
},
|
||||
});
|
||||
} finally {
|
||||
|
||||
@@ -429,6 +429,32 @@ test("context details support keyboard entry and dismiss when the viewport moves
|
||||
await expect(details).toHaveCount(0);
|
||||
});
|
||||
|
||||
test("context details stay open while the chat streams", async ({ page }) => {
|
||||
test.setTimeout(120_000);
|
||||
await page.setViewportSize(DESKTOP);
|
||||
const session = await seedMockAgentWorkspace({
|
||||
repoPrefix: "context-window-streaming-",
|
||||
title: "Context details while streaming",
|
||||
model: "ten-second-stream",
|
||||
});
|
||||
try {
|
||||
await openAgentRoute(page, session);
|
||||
await expectComposerVisible(page);
|
||||
await submitMessageWithButton(page, "Stream while the context details are open.");
|
||||
const stop = page.getByRole("button", { name: /stop|cancel/i }).first();
|
||||
await expect(stop).toBeVisible();
|
||||
const details = await pressContextWindowMeter(page, /^Context window/);
|
||||
await expect(stop).toBeVisible();
|
||||
await qaScreenshot(page, "context-details-while-streaming");
|
||||
|
||||
await expect(stop).toHaveCount(0, { timeout: 30_000 });
|
||||
await expect(details).toBeVisible();
|
||||
await qaScreenshot(page, "context-details-after-streaming");
|
||||
} finally {
|
||||
await session.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test("pointer hovering context details preserves composer focus", async ({ page, agent }) => {
|
||||
const usage = await scriptAgentUsage(page);
|
||||
await page.setViewportSize(DESKTOP);
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
movePointerAwayFromWorkspaceHoverCard,
|
||||
openMobileAgentSidebar,
|
||||
pinWorkspaceFromSidebar,
|
||||
scrollWorkspaceList,
|
||||
} from "../support/helpers/sidebar";
|
||||
import { seedWorkspace } from "../support/helpers/seed-client";
|
||||
import { expectWorkspaceHeader } from "../support/helpers/workspace-ui";
|
||||
@@ -582,6 +583,12 @@ test.describe("Half-screen desktop layout", () => {
|
||||
await page.getByTestId("menu-button").click();
|
||||
await expect(page.getByTestId("sidebar-global-new-workspace")).toBeVisible();
|
||||
await expect(sidebarScroll).toHaveJSProperty("scrollTop", scrollTop);
|
||||
|
||||
await movePointerAwayFromWorkspaceHoverCard(page);
|
||||
await focusWorkspaceRowWithKeyboard(page, lastWorkspaceId);
|
||||
await expectWorkspaceHoverCardOpen(page);
|
||||
await scrollWorkspaceList(page);
|
||||
await expectWorkspaceHoverCardClosed(page);
|
||||
} finally {
|
||||
await workspace.cleanup();
|
||||
}
|
||||
|
||||
@@ -54,12 +54,15 @@ export async function leaveContextWindowMeter(page: Page): Promise<void> {
|
||||
await expect(contextWindowDetails(page)).toHaveCount(0);
|
||||
}
|
||||
|
||||
/** Compact screens open the meter's details in a sheet. */
|
||||
export async function pressContextWindowMeter(page: Page, name = METER_NAME): Promise<Locator> {
|
||||
/** Clicking the meter opens its details in the active layout. */
|
||||
export async function pressContextWindowMeter(
|
||||
page: Page,
|
||||
name: string | RegExp = METER_NAME,
|
||||
): Promise<Locator> {
|
||||
await page.getByRole("button", { name, exact: true }).click({ timeout: 30_000 });
|
||||
const sheet = contextWindowDetails(page);
|
||||
await expect(sheet).toBeVisible();
|
||||
return sheet;
|
||||
const details = contextWindowDetails(page);
|
||||
await expect(details).toBeVisible();
|
||||
return details;
|
||||
}
|
||||
|
||||
export async function closeContextWindowSheet(page: Page): Promise<void> {
|
||||
|
||||
@@ -71,6 +71,15 @@ export async function focusWorkspaceRowWithKeyboard(
|
||||
await expect(row).toBeFocused();
|
||||
}
|
||||
|
||||
export async function scrollWorkspaceList(page: Page): Promise<void> {
|
||||
const list = page.getByTestId("sidebar-project-workspace-list-scroll");
|
||||
const before = await list.evaluate((element) => element.scrollTop);
|
||||
await list.evaluate((element) =>
|
||||
element.scrollBy({ top: element.scrollTop > 0 ? -40 : 40, behavior: "instant" }),
|
||||
);
|
||||
await expect.poll(() => list.evaluate((element) => element.scrollTop)).not.toBe(before);
|
||||
}
|
||||
|
||||
export async function expectWorkspaceHoverCardOpen(page: Page): Promise<void> {
|
||||
await expect(page.getByTestId("workspace-hover-card")).toBeVisible();
|
||||
}
|
||||
|
||||
+2
-2
@@ -18,7 +18,7 @@ export interface AgentCommandsDraftConfig {
|
||||
modeId?: string;
|
||||
model?: string;
|
||||
thinkingOptionId?: string;
|
||||
featureValues?: Record<string, unknown>;
|
||||
providerOptions?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export function normalizeAgentCommandsCwd(cwd: string): string {
|
||||
@@ -98,7 +98,7 @@ export function draftAgentCommandsQueryKey(input: {
|
||||
"thinking",
|
||||
draftConfig.thinkingOptionId ?? null,
|
||||
"features",
|
||||
draftConfig.featureValues ?? null,
|
||||
draftConfig.providerOptions ?? null,
|
||||
] as const;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { AgentOptionControl } from "@getpaseo/protocol/agent-types";
|
||||
import { isControlActive } from "./option-controls";
|
||||
import {
|
||||
draftControlsRequest,
|
||||
openDraftOptions,
|
||||
ownDraftOptions,
|
||||
viewDraftOptions,
|
||||
} from "./draft-options-model";
|
||||
|
||||
const SPEED: AgentOptionControl = {
|
||||
type: "select",
|
||||
key: "service_tier",
|
||||
label: "Speed",
|
||||
defaultValue: "default",
|
||||
choices: [
|
||||
{ value: "default", label: "Standard" },
|
||||
{ value: "priority", label: "Fast" },
|
||||
],
|
||||
};
|
||||
const WEB_SEARCH: AgentOptionControl = { type: "toggle", key: "web_search", label: "Web search" };
|
||||
|
||||
function answer(
|
||||
provider: string,
|
||||
requestKey: string,
|
||||
options: Record<string, unknown>,
|
||||
controls = [SPEED, WEB_SEARCH],
|
||||
) {
|
||||
return { provider, requestKey, controls, options };
|
||||
}
|
||||
|
||||
describe("draft options model", () => {
|
||||
it("draws a legacy Fast profile as the Fast tier the daemon resolved", () => {
|
||||
const model = openDraftOptions({ provider: "codex", seed: { service_tier: "fast" } });
|
||||
model.applyResolved(answer("codex", "k1", { service_tier: "priority" }));
|
||||
|
||||
const view = viewDraftOptions(model.getState(), { provider: "codex", requestKey: "k1" });
|
||||
|
||||
expect(view?.options).toEqual({ service_tier: "priority" });
|
||||
expect(view && isControlActive(SPEED, view.options)).toBe(true);
|
||||
// The daemon still gets the stored value to resolve, and so does create.
|
||||
expect(ownDraftOptions(model.getState())).toEqual({ service_tier: "fast" });
|
||||
});
|
||||
|
||||
it("applying a profile from another provider keeps its options through the provider change", () => {
|
||||
const model = openDraftOptions({ provider: "claude" });
|
||||
model.applyResolved(answer("claude", "k1", {}));
|
||||
|
||||
model.applyProfile({
|
||||
provider: "codex",
|
||||
options: { sandbox_mode: "read-only", service_tier: "fast" },
|
||||
});
|
||||
// The form follows the profile to its provider.
|
||||
model.observeProvider("codex");
|
||||
|
||||
expect(ownDraftOptions(model.getState())).toEqual({
|
||||
sandbox_mode: "read-only",
|
||||
service_tier: "fast",
|
||||
});
|
||||
expect(model.getState().resolved).toBeNull();
|
||||
});
|
||||
|
||||
it("choosing another provider by hand starts the options over", () => {
|
||||
const model = openDraftOptions({ provider: "codex", seed: { sandbox_mode: "read-only" } });
|
||||
model.setOption("web_search", true);
|
||||
|
||||
model.observeProvider("claude");
|
||||
|
||||
expect(ownDraftOptions(model.getState())).toBeUndefined();
|
||||
expect(model.getState().resolved).toBeNull();
|
||||
});
|
||||
|
||||
it("never pairs a manually chosen provider with the previous provider's options", () => {
|
||||
const model = openDraftOptions({ provider: "claude" });
|
||||
model.applyResolved(
|
||||
answer("claude", "k1", { fast_mode: true }, [
|
||||
{ type: "toggle", key: "fast_mode", label: "Fast" },
|
||||
]),
|
||||
);
|
||||
model.setOption("fast_mode", true);
|
||||
const form = { provider: "claude", cwd: "/repo" };
|
||||
expect(draftControlsRequest(model.getState(), form)).toMatchObject({
|
||||
provider: "claude",
|
||||
providerOptions: { fast_mode: true },
|
||||
});
|
||||
|
||||
// The form shows OpenCode on its next render; the model has not observed it yet.
|
||||
expect(draftControlsRequest(model.getState(), { ...form, provider: "opencode" })).toBeNull();
|
||||
|
||||
model.observeProvider("opencode");
|
||||
const request = draftControlsRequest(model.getState(), { ...form, provider: "opencode" });
|
||||
expect(request).toEqual({ provider: "opencode", cwd: "/repo" });
|
||||
});
|
||||
|
||||
it("stops sending a toggle once the model in use draws no control for it", () => {
|
||||
const FAST_MODE: AgentOptionControl = { type: "toggle", key: "fast_mode", label: "Fast" };
|
||||
const model = openDraftOptions({ provider: "claude", seed: { sandbox_mode: "read-only" } });
|
||||
model.applyResolved(answer("claude", "opus", { fast_mode: false }, [FAST_MODE]));
|
||||
model.setOption("fast_mode", true);
|
||||
expect(ownDraftOptions(model.getState())).toEqual({
|
||||
sandbox_mode: "read-only",
|
||||
fast_mode: true,
|
||||
});
|
||||
|
||||
// The form moves to a model without Fast; its answer lists no such control.
|
||||
model.applyResolved(answer("claude", "haiku", {}, []));
|
||||
|
||||
expect(ownDraftOptions(model.getState())).toEqual({ sandbox_mode: "read-only" });
|
||||
|
||||
// Back on a model that draws the control, the toggle applies again. The daemon's answer
|
||||
// for the request without it said Fast was off; the request that carries it follows.
|
||||
model.applyResolved(answer("claude", "opus-again", { fast_mode: false }, [FAST_MODE]));
|
||||
expect(ownDraftOptions(model.getState())).toEqual({
|
||||
sandbox_mode: "read-only",
|
||||
fast_mode: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("always sends an option no control has drawn", () => {
|
||||
const FAST_MODE: AgentOptionControl = { type: "toggle", key: "fast_mode", label: "Fast" };
|
||||
const model = openDraftOptions({ provider: "claude" });
|
||||
model.applyResolved(answer("claude", "k1", {}, [FAST_MODE]));
|
||||
|
||||
model.setOption("token_budget", 5);
|
||||
|
||||
expect(ownDraftOptions(model.getState())).toEqual({ token_budget: 5 });
|
||||
model.applyResolved(answer("claude", "k2", {}, []));
|
||||
expect(ownDraftOptions(model.getState())).toEqual({ token_budget: 5 });
|
||||
});
|
||||
|
||||
it("keeps a draft's seed when the first provider is chosen", () => {
|
||||
const model = openDraftOptions({ provider: null, seed: { web_search: true } });
|
||||
|
||||
model.observeProvider("claude");
|
||||
|
||||
expect(ownDraftOptions(model.getState())).toEqual({ web_search: true });
|
||||
});
|
||||
|
||||
it("sends a remembered value to the daemon, and draws only what comes back", () => {
|
||||
const model = openDraftOptions({ provider: "codex" });
|
||||
model.setRemembered({ service_tier: "fast", retired: true });
|
||||
// Nothing is known about the provider's controls yet.
|
||||
expect(ownDraftOptions(model.getState())).toBeUndefined();
|
||||
|
||||
model.applyResolved(answer("codex", "k1", { service_tier: "default" }));
|
||||
expect(ownDraftOptions(model.getState())).toEqual({ service_tier: "fast" });
|
||||
// The answer to the first request does not show the remembered value as if it applied.
|
||||
expect(
|
||||
viewDraftOptions(model.getState(), { provider: "codex", requestKey: "k2" })?.options,
|
||||
).toEqual({ service_tier: "default" });
|
||||
|
||||
model.applyResolved(answer("codex", "k2", { service_tier: "priority" }));
|
||||
expect(
|
||||
viewDraftOptions(model.getState(), { provider: "codex", requestKey: "k2" })?.options,
|
||||
).toEqual({ service_tier: "priority" });
|
||||
});
|
||||
|
||||
it("does not let a remembered value override the seed", () => {
|
||||
const model = openDraftOptions({ provider: "codex", seed: { service_tier: "default" } });
|
||||
model.applyResolved(answer("codex", "k1", { service_tier: "default" }));
|
||||
model.setRemembered({ service_tier: "fast" });
|
||||
|
||||
expect(ownDraftOptions(model.getState())).toEqual({ service_tier: "default" });
|
||||
});
|
||||
|
||||
it("lays a toggle over the previous answer until the new one arrives", () => {
|
||||
const model = openDraftOptions({ provider: "claude" });
|
||||
model.applyResolved(answer("claude", "k1", { web_search: false }));
|
||||
|
||||
model.setOption("web_search", true);
|
||||
|
||||
expect(
|
||||
viewDraftOptions(model.getState(), { provider: "claude", requestKey: "k2" })?.options,
|
||||
).toEqual({ web_search: true });
|
||||
model.applyResolved(answer("claude", "k2", { web_search: true }));
|
||||
expect(
|
||||
viewDraftOptions(model.getState(), { provider: "claude", requestKey: "k2" })?.options,
|
||||
).toEqual({ web_search: true });
|
||||
});
|
||||
|
||||
it("draws nothing for a provider the answer is not for", () => {
|
||||
const model = openDraftOptions({ provider: "claude" });
|
||||
model.applyResolved(answer("claude", "k1", {}));
|
||||
|
||||
expect(viewDraftOptions(model.getState(), { provider: "codex", requestKey: "k1" })).toBe(
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,193 @@
|
||||
import type {
|
||||
AgentOptionControl,
|
||||
AgentSessionConfig,
|
||||
ProviderOptions,
|
||||
} from "@getpaseo/protocol/agent-types";
|
||||
import { withoutLostControls } from "./lost-controls";
|
||||
|
||||
/**
|
||||
* The options of one draft agent, as a plain model (see docs/forms.md). It owns which layers
|
||||
* make up the draft's options; the daemon owns what they mean. Every layer is sent to the daemon
|
||||
* (`ownDraftOptions`) and the UI draws what comes back (`viewDraftOptions`), so no alias,
|
||||
* default or legacy key is resolved here.
|
||||
*
|
||||
* - `seed`: options the draft started from (a profile, a forked agent).
|
||||
* - `remembered`: the provider's last-used control values.
|
||||
* - `edits`: toggles made in this draft.
|
||||
*
|
||||
* Choosing a provider by hand starts the options over; applying a profile replaces the provider
|
||||
* and the options in one step, so the provider change that follows does not clear them.
|
||||
*/
|
||||
export interface ResolvedDraftOptions {
|
||||
provider: string;
|
||||
/** Names the request that produced this answer; see `viewDraftOptions`. */
|
||||
requestKey: string;
|
||||
controls: AgentOptionControl[];
|
||||
options: ProviderOptions;
|
||||
}
|
||||
|
||||
export interface DraftOptionsState {
|
||||
provider: string | null;
|
||||
seed: ProviderOptions;
|
||||
remembered: ProviderOptions;
|
||||
edits: ProviderOptions;
|
||||
resolved: ResolvedDraftOptions | null;
|
||||
/** Every key an answer for this provider has drawn as a control. */
|
||||
drawn: ReadonlySet<string>;
|
||||
}
|
||||
|
||||
export interface DraftOptionsModel {
|
||||
getState: () => DraftOptionsState;
|
||||
subscribe: (listener: () => void) => () => void;
|
||||
/** The provider the draft's form now has. A different one than the model's is a manual choice. */
|
||||
observeProvider: (provider: string | null) => void;
|
||||
applyProfile: (profile: { provider: string; options: ProviderOptions }) => void;
|
||||
setRemembered: (remembered: ProviderOptions) => void;
|
||||
setOption: (key: string, value: unknown) => void;
|
||||
applyResolved: (resolved: ResolvedDraftOptions) => void;
|
||||
}
|
||||
|
||||
export function openDraftOptions(input: {
|
||||
provider: string | null;
|
||||
seed?: ProviderOptions;
|
||||
}): DraftOptionsModel {
|
||||
let state: DraftOptionsState = {
|
||||
provider: input.provider,
|
||||
seed: input.seed ?? {},
|
||||
remembered: {},
|
||||
edits: {},
|
||||
resolved: null,
|
||||
drawn: new Set(),
|
||||
};
|
||||
const listeners = new Set<() => void>();
|
||||
|
||||
function publish(update: (current: DraftOptionsState) => DraftOptionsState): void {
|
||||
const next = update(state);
|
||||
if (next === state) return;
|
||||
state = next;
|
||||
for (const listener of listeners) listener();
|
||||
}
|
||||
|
||||
return {
|
||||
getState: () => state,
|
||||
subscribe: (listener) => {
|
||||
listeners.add(listener);
|
||||
return () => {
|
||||
listeners.delete(listener);
|
||||
};
|
||||
},
|
||||
observeProvider: (provider) =>
|
||||
publish((current) => {
|
||||
if (provider === current.provider) return current;
|
||||
// The first provider a draft picks does not discard what it was opened with.
|
||||
if (current.provider === null) return { ...current, provider };
|
||||
return {
|
||||
...current,
|
||||
provider,
|
||||
seed: {},
|
||||
edits: {},
|
||||
resolved: null,
|
||||
drawn: new Set(),
|
||||
};
|
||||
}),
|
||||
applyProfile: (profile) =>
|
||||
publish((current) => ({
|
||||
...current,
|
||||
provider: profile.provider,
|
||||
seed: profile.options,
|
||||
edits: {},
|
||||
resolved: current.provider === profile.provider ? current.resolved : null,
|
||||
drawn: current.provider === profile.provider ? current.drawn : new Set(),
|
||||
})),
|
||||
setRemembered: (remembered) => publish((current) => ({ ...current, remembered })),
|
||||
setOption: (key, value) =>
|
||||
publish((current) =>
|
||||
Object.is(current.edits[key], value)
|
||||
? current
|
||||
: { ...current, edits: { ...current.edits, [key]: value } },
|
||||
),
|
||||
applyResolved: (resolved) =>
|
||||
publish((current) => ({
|
||||
...current,
|
||||
resolved,
|
||||
drawn: new Set([...current.drawn, ...resolved.controls.map((control) => control.key)]),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Everything the draft would create with, for the daemon to resolve. A last-used value applies
|
||||
* once the provider has told us it still draws a control for that key, and never over the seed.
|
||||
* An edit of a key an earlier answer drew as a control stops applying when the latest answer
|
||||
* draws none for it (the model changed to one without that control) and applies again when a
|
||||
* control for it returns. An edit of a key no answer has drawn is an option without a control
|
||||
* and always applies.
|
||||
*/
|
||||
export function ownDraftOptions(state: DraftOptionsState): ProviderOptions | undefined {
|
||||
const controlKeys = new Set((state.resolved?.controls ?? []).map((control) => control.key));
|
||||
const remembered = Object.fromEntries(
|
||||
Object.entries(state.remembered).filter(
|
||||
([key]) => controlKeys.has(key) && !(key in state.seed),
|
||||
),
|
||||
);
|
||||
const edits = withoutLostControls(state.edits, state.drawn, controlKeys);
|
||||
const own = { ...state.seed, ...remembered, ...edits };
|
||||
return Object.keys(own).length > 0 ? own : undefined;
|
||||
}
|
||||
|
||||
export type DraftControlsRequest = Pick<
|
||||
AgentSessionConfig,
|
||||
"provider" | "cwd" | "modeId" | "model" | "thinkingOptionId" | "providerOptions"
|
||||
>;
|
||||
|
||||
/** What the draft's form has chosen; the options come from the model. */
|
||||
export interface DraftControlsForm {
|
||||
provider: string | null;
|
||||
cwd: string;
|
||||
modeId?: string | null;
|
||||
modelId?: string | null;
|
||||
thinkingOptionId?: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The listing request for the draft's form, built from one snapshot of the model. The form
|
||||
* reaches a new provider before the model has observed it, and the model still holds the
|
||||
* previous provider's options until it does; that render has no request, so a request never
|
||||
* pairs one provider with another's options.
|
||||
*/
|
||||
export function draftControlsRequest(
|
||||
state: DraftOptionsState,
|
||||
form: DraftControlsForm,
|
||||
): DraftControlsRequest | null {
|
||||
if (!form.provider || !form.cwd || form.provider !== state.provider) return null;
|
||||
const providerOptions = ownDraftOptions(state);
|
||||
return {
|
||||
provider: form.provider,
|
||||
cwd: form.cwd,
|
||||
...(form.modeId ? { modeId: form.modeId } : {}),
|
||||
...(form.modelId ? { model: form.modelId } : {}),
|
||||
...(form.thinkingOptionId ? { thinkingOptionId: form.thinkingOptionId } : {}),
|
||||
...(providerOptions ? { providerOptions } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* What the controls draw: the daemon's answer for this provider. The last answer stays up while
|
||||
* a newer request is in flight, with the toggles made since laid over it, so a switch does not
|
||||
* wait for the round trip. It never carries a seed or remembered value the daemon has not
|
||||
* resolved.
|
||||
*/
|
||||
export function viewDraftOptions(
|
||||
state: DraftOptionsState,
|
||||
current: { provider: string | null; requestKey: string },
|
||||
): { controls: AgentOptionControl[]; options: ProviderOptions } | undefined {
|
||||
const { resolved } = state;
|
||||
if (!resolved || resolved.provider !== current.provider) return undefined;
|
||||
return {
|
||||
controls: resolved.controls,
|
||||
options:
|
||||
resolved.requestKey === current.requestKey
|
||||
? resolved.options
|
||||
: { ...resolved.options, ...state.edits },
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import type { ProviderOptions } from "@getpaseo/protocol/agent-types";
|
||||
|
||||
/**
|
||||
* The options that still apply after an answer from the daemon. A key an earlier answer drew as a
|
||||
* control and the latest answer does not (the model changed to one without that control) is
|
||||
* dropped, and applies again if a control for it returns. A key no answer has drawn is an option
|
||||
* without a control and always applies.
|
||||
*/
|
||||
export function withoutLostControls(
|
||||
options: ProviderOptions,
|
||||
drawn: ReadonlySet<string>,
|
||||
current: ReadonlySet<string>,
|
||||
): ProviderOptions {
|
||||
return Object.fromEntries(
|
||||
Object.entries(options).filter(([key]) => !drawn.has(key) || current.has(key)),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { AgentOptionControl } from "@getpaseo/protocol/agent-types";
|
||||
import {
|
||||
getControlTooltip,
|
||||
isControlActive,
|
||||
readSelectOption,
|
||||
readToggleOption,
|
||||
} from "./option-controls";
|
||||
|
||||
const speed: AgentOptionControl = {
|
||||
type: "select",
|
||||
key: "service_tier",
|
||||
label: "Speed",
|
||||
defaultValue: "default",
|
||||
choices: [
|
||||
{ value: "default", label: "Normal" },
|
||||
{ value: "priority", label: "Fast" },
|
||||
],
|
||||
};
|
||||
const fast: AgentOptionControl = { type: "toggle", key: "fast_mode", label: "Fast" };
|
||||
|
||||
describe("option controls", () => {
|
||||
it("reads a select from options and falls back to the control's default", () => {
|
||||
if (speed.type !== "select") throw new Error("select expected");
|
||||
expect(readSelectOption(speed, { service_tier: "priority" })).toBe("priority");
|
||||
expect(readSelectOption(speed, {})).toBe("default");
|
||||
expect(readSelectOption(speed, { service_tier: "unknown-tier" })).toBe("default");
|
||||
});
|
||||
|
||||
it("reads a toggle from options and is off when unset", () => {
|
||||
if (fast.type !== "toggle") throw new Error("toggle expected");
|
||||
expect(readToggleOption(fast, { fast_mode: true })).toBe(true);
|
||||
expect(readToggleOption(fast, {})).toBe(false);
|
||||
});
|
||||
|
||||
it("is active when the option differs from the control's default", () => {
|
||||
expect(isControlActive(speed, { service_tier: "priority" })).toBe(true);
|
||||
expect(isControlActive(speed, { service_tier: "default" })).toBe(false);
|
||||
expect(isControlActive(speed, {})).toBe(false);
|
||||
expect(isControlActive(fast, { fast_mode: true })).toBe(true);
|
||||
expect(isControlActive(fast, {})).toBe(false);
|
||||
});
|
||||
|
||||
it("prefers a control's tooltip over its label", () => {
|
||||
expect(getControlTooltip({ label: "Plan", tooltip: "Toggle plan mode" })).toBe(
|
||||
"Toggle plan mode",
|
||||
);
|
||||
expect(getControlTooltip({ label: "Custom" })).toBe("Custom");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,47 @@
|
||||
import type {
|
||||
AgentOptionControl,
|
||||
AgentOptionSelectControl,
|
||||
AgentOptionToggleControl,
|
||||
ProviderOptions,
|
||||
} from "@getpaseo/protocol/agent-types";
|
||||
|
||||
/**
|
||||
* The composer's option controls. A control only describes how to draw one option key; the
|
||||
* value is read from `options`, which the daemon resolved (defaults, aliases, what runs).
|
||||
*/
|
||||
export interface ComposerOptionControls {
|
||||
controls: AgentOptionControl[];
|
||||
options: ProviderOptions;
|
||||
onSetOption: (key: string, value: unknown) => void;
|
||||
}
|
||||
|
||||
export function readToggleOption(
|
||||
control: AgentOptionToggleControl,
|
||||
options: ProviderOptions,
|
||||
): boolean {
|
||||
const value = options[control.key];
|
||||
return typeof value === "boolean" ? value : (control.defaultValue ?? false);
|
||||
}
|
||||
|
||||
/** The selected choice's value, or the control's default when the option names no choice. */
|
||||
export function readSelectOption(
|
||||
control: AgentOptionSelectControl,
|
||||
options: ProviderOptions,
|
||||
): string | null {
|
||||
const value = options[control.key];
|
||||
if (typeof value === "string" && control.choices.some((choice) => choice.value === value)) {
|
||||
return value;
|
||||
}
|
||||
return control.defaultValue ?? null;
|
||||
}
|
||||
|
||||
/** Whether the option is set to something other than the control's default. */
|
||||
export function isControlActive(control: AgentOptionControl, options: ProviderOptions): boolean {
|
||||
if (control.type === "toggle") return readToggleOption(control, options);
|
||||
const value = readSelectOption(control, options);
|
||||
return value !== null && value !== control.defaultValue;
|
||||
}
|
||||
|
||||
export function getControlTooltip(control: Pick<AgentOptionControl, "label" | "tooltip">): string {
|
||||
return control.tooltip ?? control.label;
|
||||
}
|
||||
@@ -23,7 +23,7 @@ describe("materializeAgentProfile", () => {
|
||||
model: "claude-opus-5",
|
||||
modeId: "plan",
|
||||
thinkingOptionId: "think-hard",
|
||||
featureValues: { web_search: true },
|
||||
options: { web_search: true },
|
||||
}),
|
||||
),
|
||||
).toEqual({
|
||||
@@ -31,7 +31,7 @@ describe("materializeAgentProfile", () => {
|
||||
modelId: "claude-opus-5",
|
||||
modeId: "plan",
|
||||
thinkingOptionId: "think-hard",
|
||||
featureValues: { web_search: true },
|
||||
options: { web_search: true },
|
||||
});
|
||||
});
|
||||
|
||||
@@ -41,7 +41,7 @@ describe("materializeAgentProfile", () => {
|
||||
modelId: "",
|
||||
modeId: "",
|
||||
thinkingOptionId: "",
|
||||
featureValues: {},
|
||||
options: {},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -61,7 +61,7 @@ describe("toAgentConfigApply", () => {
|
||||
model: "claude-opus-5",
|
||||
modeId: "plan",
|
||||
thinkingOptionId: "think-hard",
|
||||
featureValues: { web_search: true },
|
||||
options: { web_search: true },
|
||||
}),
|
||||
),
|
||||
),
|
||||
@@ -69,7 +69,7 @@ describe("toAgentConfigApply", () => {
|
||||
modelId: "claude-opus-5",
|
||||
modeId: "plan",
|
||||
thinkingOptionId: "think-hard",
|
||||
featureValues: { web_search: true },
|
||||
options: { web_search: true },
|
||||
});
|
||||
});
|
||||
|
||||
@@ -81,8 +81,8 @@ describe("toAgentConfigApply", () => {
|
||||
|
||||
it("omits an empty feature map so the agent keeps its own feature values", () => {
|
||||
expect(
|
||||
toAgentConfigApply(materializeAgentProfile(profile({ featureValues: {} }))),
|
||||
).not.toHaveProperty("featureValues");
|
||||
toAgentConfigApply(materializeAgentProfile(profile({ options: {} }))),
|
||||
).not.toHaveProperty("options");
|
||||
});
|
||||
|
||||
it("never carries a provider, which a running agent cannot change", () => {
|
||||
|
||||
@@ -12,7 +12,7 @@ export interface MaterializedAgentProfile {
|
||||
modelId: string;
|
||||
modeId: string;
|
||||
thinkingOptionId: string;
|
||||
featureValues: Record<string, unknown>;
|
||||
options: Record<string, unknown>;
|
||||
}
|
||||
|
||||
function trimmed(value: string | undefined): string {
|
||||
@@ -25,7 +25,7 @@ export function materializeAgentProfile(profile: AgentProfile): MaterializedAgen
|
||||
modelId: trimmed(profile.model),
|
||||
modeId: trimmed(profile.modeId),
|
||||
thinkingOptionId: trimmed(profile.thinkingOptionId),
|
||||
featureValues: profile.featureValues ?? {},
|
||||
options: profile.options ?? {},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -52,8 +52,6 @@ export function toAgentConfigApply(profile: MaterializedAgentProfile): AgentConf
|
||||
...(profile.modelId ? { modelId: profile.modelId } : {}),
|
||||
...(profile.modeId ? { modeId: profile.modeId } : {}),
|
||||
...(profile.thinkingOptionId ? { thinkingOptionId: profile.thinkingOptionId } : {}),
|
||||
...(Object.keys(profile.featureValues).length > 0
|
||||
? { featureValues: profile.featureValues }
|
||||
: {}),
|
||||
...(Object.keys(profile.options).length > 0 ? { options: profile.options } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { ProviderSnapshotEntry } from "@getpaseo/protocol/agent-types";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
buildFeatureRequestKey,
|
||||
buildControlsRequestKey,
|
||||
openAgentProfileForm,
|
||||
type AgentProfileFormModel,
|
||||
} from "./profile-form-model";
|
||||
@@ -70,6 +70,21 @@ function optionValues(options: readonly { value: string }[]): string[] {
|
||||
return options.map((option) => option.value);
|
||||
}
|
||||
|
||||
const FAST = {
|
||||
controls: [{ type: "toggle" as const, key: "fast_mode", label: "Fast" }],
|
||||
options: { fast_mode: false },
|
||||
};
|
||||
const NO_CONTROLS = { controls: [], options: {} };
|
||||
|
||||
function toggledOnOpus(): AgentProfileFormModel {
|
||||
const model = openWithCatalog({ mode: "create" });
|
||||
model.setName("Fast");
|
||||
selectClaude(model);
|
||||
model.applyControls(model.getState().controlsRequestKey ?? "", FAST);
|
||||
model.setOption("fast_mode", true);
|
||||
return model;
|
||||
}
|
||||
|
||||
describe("openAgentProfileForm", () => {
|
||||
it("starts a create form empty and cannot submit", () => {
|
||||
const model = openWithCatalog({ mode: "create" });
|
||||
@@ -173,7 +188,7 @@ describe("openAgentProfileForm", () => {
|
||||
model: "claude-opus-5",
|
||||
modeId: "plan",
|
||||
thinkingOptionId: "think-hard",
|
||||
featureValues: { webSearch: true },
|
||||
options: { webSearch: true },
|
||||
notes: "Visual work only.",
|
||||
},
|
||||
});
|
||||
@@ -229,10 +244,11 @@ describe("openAgentProfileForm", () => {
|
||||
selectClaude(model);
|
||||
model.setModel("claude-opus-5", { label: "Opus 5" });
|
||||
model.setThinking("think-hard", { label: "Think hard" });
|
||||
model.applyFeatures(model.getState().featureRequestKey ?? "", [
|
||||
{ type: "toggle", id: "webSearch", label: "Web search", value: false },
|
||||
]);
|
||||
model.setFeatureValue("webSearch", true);
|
||||
model.applyControls(model.getState().controlsRequestKey ?? "", {
|
||||
controls: [{ type: "toggle", key: "webSearch", label: "Web search" }],
|
||||
options: { webSearch: false },
|
||||
});
|
||||
model.setOption("webSearch", true);
|
||||
|
||||
model.setProvider("codex", { label: "Codex" });
|
||||
const state = model.getState();
|
||||
@@ -242,8 +258,9 @@ describe("openAgentProfileForm", () => {
|
||||
expect(state.modelDisplay).toEqual({ label: "GPT-5.2 Codex" });
|
||||
expect(state.thinkingOptionId).toBe("");
|
||||
expect(state.thinkingDisplay).toBeNull();
|
||||
expect(state.featureValues).toEqual({});
|
||||
expect(state.features).toEqual([]);
|
||||
expect(state.options).toEqual({});
|
||||
expect(state.optionEdits).toEqual({});
|
||||
expect(state.controls).toEqual([]);
|
||||
expect(state.name).toBe("Test writer");
|
||||
});
|
||||
|
||||
@@ -334,23 +351,28 @@ describe("openAgentProfileForm", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("features", () => {
|
||||
it("asks for features per provider/model/mode/thinking combination", () => {
|
||||
const WEB_SEARCH_CONTROLS = {
|
||||
controls: [{ type: "toggle" as const, key: "webSearch", label: "Web search" }],
|
||||
options: { webSearch: false },
|
||||
};
|
||||
|
||||
describe("controls", () => {
|
||||
it("asks for controls per provider/model/mode/thinking combination", () => {
|
||||
const model = openWithCatalog({ mode: "create" });
|
||||
selectClaude(model);
|
||||
|
||||
expect(model.getState().featureRequest).toEqual({
|
||||
expect(model.getState().controlsRequest).toEqual({
|
||||
provider: "claude",
|
||||
model: "claude-opus-5",
|
||||
modeId: "plan",
|
||||
thinkingOptionId: "think",
|
||||
});
|
||||
const firstKey = model.getState().featureRequestKey;
|
||||
const firstKey = model.getState().controlsRequestKey;
|
||||
|
||||
model.setModel("claude-haiku-4-5", { label: "Haiku 4.5" });
|
||||
|
||||
expect(model.getState().featureRequestKey).not.toBe(firstKey);
|
||||
expect(model.getState().featureRequest).toEqual({
|
||||
expect(model.getState().controlsRequestKey).not.toBe(firstKey);
|
||||
expect(model.getState().controlsRequest).toEqual({
|
||||
provider: "claude",
|
||||
model: "claude-haiku-4-5",
|
||||
modeId: "plan",
|
||||
@@ -361,77 +383,233 @@ describe("openAgentProfileForm", () => {
|
||||
it("moves from pending to complete only for the current request", () => {
|
||||
const model = openWithCatalog({ mode: "create" });
|
||||
selectClaude(model);
|
||||
const key = model.getState().featureRequestKey ?? "";
|
||||
expect(model.getState().featureResolution).toBe("pending");
|
||||
const key = model.getState().controlsRequestKey ?? "";
|
||||
expect(model.getState().controlsResolution).toBe("pending");
|
||||
|
||||
model.applyFeatures("stale-key", [
|
||||
{ type: "toggle", id: "webSearch", label: "Web search", value: false },
|
||||
]);
|
||||
expect(model.getState().featureResolution).toBe("pending");
|
||||
expect(model.getState().features).toEqual([]);
|
||||
model.applyControls("stale-key", {
|
||||
controls: [{ type: "toggle", key: "webSearch", label: "Web search" }],
|
||||
options: { webSearch: false },
|
||||
});
|
||||
expect(model.getState().controlsResolution).toBe("pending");
|
||||
expect(model.getState().controls).toEqual([]);
|
||||
|
||||
model.applyFeatures(key, [
|
||||
{ type: "toggle", id: "webSearch", label: "Web search", value: false },
|
||||
]);
|
||||
expect(model.getState().featureResolution).toBe("complete");
|
||||
expect(model.getState().disclosure.showFeaturesField).toBe(true);
|
||||
model.applyControls(key, {
|
||||
controls: [{ type: "toggle", key: "webSearch", label: "Web search" }],
|
||||
options: { webSearch: false },
|
||||
});
|
||||
expect(model.getState().controlsResolution).toBe("complete");
|
||||
expect(model.getState().disclosure.showControlsField).toBe(true);
|
||||
});
|
||||
|
||||
it("reflects a set feature value back into the rendered feature", () => {
|
||||
it("reflects a set option back into the rendered controls", () => {
|
||||
const model = openWithCatalog({ mode: "create" });
|
||||
model.setName("Searcher");
|
||||
selectClaude(model);
|
||||
model.applyControls(model.getState().controlsRequestKey ?? "", WEB_SEARCH_CONTROLS);
|
||||
|
||||
model.setOption("webSearch", true);
|
||||
|
||||
expect(model.getState().controls[0]).toMatchObject({ key: "webSearch" });
|
||||
expect(model.getState().controlOptions).toEqual({ webSearch: true });
|
||||
expect(model.getState().submitValue?.options).toEqual({ webSearch: true });
|
||||
});
|
||||
|
||||
it("keeps stored options while the controls are still pending", () => {
|
||||
const model = openAgentProfileForm({
|
||||
mode: "edit",
|
||||
profile: { id: "p1", name: "UI work", provider: "claude", options: { webSearch: true } },
|
||||
});
|
||||
model.applyProviderCatalog(ENTRIES);
|
||||
|
||||
expect(model.getState().controlsResolution).toBe("pending");
|
||||
expect(model.getState().submitValue?.options).toEqual({ webSearch: true });
|
||||
});
|
||||
|
||||
it("keeps options no control draws, so editing a profile does not drop them", () => {
|
||||
const model = openAgentProfileForm({
|
||||
mode: "edit",
|
||||
profile: {
|
||||
id: "p1",
|
||||
name: "UI work",
|
||||
provider: "claude",
|
||||
options: { webSearch: true, sandbox_mode: "read-only" },
|
||||
},
|
||||
});
|
||||
model.applyProviderCatalog(ENTRIES);
|
||||
model.applyControls(model.getState().controlsRequestKey ?? "", WEB_SEARCH_CONTROLS);
|
||||
model.setOption("webSearch", false);
|
||||
|
||||
expect(model.getState().submitValue?.options).toEqual({
|
||||
webSearch: false,
|
||||
sandbox_mode: "read-only",
|
||||
});
|
||||
});
|
||||
|
||||
it("draws the options the daemon resolved from the stored ones, then the edits", () => {
|
||||
const model = openAgentProfileForm({
|
||||
mode: "edit",
|
||||
profile: { id: "p1", name: "Fast", provider: "codex", options: { service_tier: "fast" } },
|
||||
});
|
||||
model.applyProviderCatalog(ENTRIES);
|
||||
|
||||
// The request carries the stored options so the daemon can resolve the legacy tier.
|
||||
expect(model.getState().controlsRequest?.providerOptions).toEqual({ service_tier: "fast" });
|
||||
|
||||
model.applyControls(model.getState().controlsRequestKey ?? "", {
|
||||
controls: [
|
||||
{
|
||||
type: "select",
|
||||
key: "service_tier",
|
||||
label: "Speed",
|
||||
defaultValue: "default",
|
||||
choices: [
|
||||
{ value: "default", label: "Standard" },
|
||||
{ value: "priority", label: "Fast" },
|
||||
],
|
||||
},
|
||||
],
|
||||
options: { service_tier: "priority" },
|
||||
});
|
||||
|
||||
expect(model.getState().controlOptions).toEqual({ service_tier: "priority" });
|
||||
// Nothing was edited, so the stored value is saved as it was.
|
||||
expect(model.getState().submitValue?.options).toEqual({ service_tier: "fast" });
|
||||
});
|
||||
|
||||
it("sends an edit to the daemon with the stored options, and draws the answer", () => {
|
||||
const model = openAgentProfileForm({
|
||||
mode: "edit",
|
||||
profile: {
|
||||
id: "p1",
|
||||
name: "Fast",
|
||||
provider: "codex",
|
||||
options: { service_tier: "fast", sandbox_mode: "read-only" },
|
||||
},
|
||||
});
|
||||
model.applyProviderCatalog(ENTRIES);
|
||||
const speed = {
|
||||
controls: [
|
||||
{
|
||||
type: "select" as const,
|
||||
key: "service_tier",
|
||||
label: "Speed",
|
||||
defaultValue: "default",
|
||||
choices: [
|
||||
{ value: "default", label: "Standard" },
|
||||
{ value: "priority", label: "Fast" },
|
||||
],
|
||||
},
|
||||
],
|
||||
options: { service_tier: "priority", sandbox_mode: "read-only" },
|
||||
};
|
||||
model.applyControls(model.getState().controlsRequestKey ?? "", speed);
|
||||
|
||||
model.setOption("service_tier", "default");
|
||||
|
||||
// The controls stay up while the daemon answers, with the toggle laid over the last answer.
|
||||
expect(model.getState().controls).toHaveLength(1);
|
||||
expect(model.getState().controlOptions).toMatchObject({ service_tier: "default" });
|
||||
// The request carries everything the profile would save, so the daemon resolves it.
|
||||
expect(model.getState().controlsRequest?.providerOptions).toEqual({
|
||||
service_tier: "default",
|
||||
sandbox_mode: "read-only",
|
||||
});
|
||||
expect(model.getState().controlsResolution).toBe("pending");
|
||||
|
||||
model.applyControls(model.getState().controlsRequestKey ?? "", {
|
||||
...speed,
|
||||
options: { service_tier: "default", sandbox_mode: "read-only" },
|
||||
});
|
||||
expect(model.getState().controlsResolution).toBe("complete");
|
||||
expect(model.getState().controlOptions).toEqual({
|
||||
service_tier: "default",
|
||||
sandbox_mode: "read-only",
|
||||
});
|
||||
});
|
||||
|
||||
it("draws no controls for the previous model while another model's answer is pending", () => {
|
||||
const model = openWithCatalog({ mode: "create" });
|
||||
selectClaude(model);
|
||||
model.applyFeatures(model.getState().featureRequestKey ?? "", [
|
||||
{ type: "toggle", id: "webSearch", label: "Web search", value: false },
|
||||
]);
|
||||
model.applyControls(model.getState().controlsRequestKey ?? "", WEB_SEARCH_CONTROLS);
|
||||
|
||||
model.setFeatureValue("webSearch", true);
|
||||
model.setModel("claude-haiku-4-5", { label: "Haiku 4.5" });
|
||||
|
||||
expect(model.getState().features[0]).toMatchObject({ id: "webSearch", value: true });
|
||||
expect(model.getState().featureValues).toEqual({ webSearch: true });
|
||||
expect(model.getState().controls).toEqual([]);
|
||||
});
|
||||
|
||||
it("keeps stored feature values while the feature list is still pending", () => {
|
||||
it("does not save a toggle once the model that drew it is replaced by one without it", () => {
|
||||
const model = toggledOnOpus();
|
||||
expect(model.getState().submitValue?.options).toEqual({ fast_mode: true });
|
||||
|
||||
model.setModel("claude-haiku-4-5", { label: "Haiku 4.5" });
|
||||
model.applyControls(model.getState().controlsRequestKey ?? "", NO_CONTROLS);
|
||||
|
||||
expect(model.getState().submitValue?.options).toBeUndefined();
|
||||
expect(model.getState().controlsRequest?.providerOptions).toBeUndefined();
|
||||
});
|
||||
|
||||
it("saves a toggle again when the model that draws it returns", () => {
|
||||
const model = toggledOnOpus();
|
||||
model.setModel("claude-haiku-4-5", { label: "Haiku 4.5" });
|
||||
model.applyControls(model.getState().controlsRequestKey ?? "", NO_CONTROLS);
|
||||
|
||||
model.setModel("claude-opus-5", { label: "Opus 5" });
|
||||
model.applyControls(model.getState().controlsRequestKey ?? "", FAST);
|
||||
|
||||
expect(model.getState().submitValue?.options).toEqual({ fast_mode: true });
|
||||
});
|
||||
|
||||
it("does not save a stored toggle profile either", () => {
|
||||
const model = openAgentProfileForm({
|
||||
mode: "edit",
|
||||
profile: {
|
||||
id: "p1",
|
||||
name: "UI work",
|
||||
name: "Fast",
|
||||
provider: "claude",
|
||||
featureValues: { webSearch: true },
|
||||
model: "claude-opus-5",
|
||||
options: { fast_mode: true },
|
||||
},
|
||||
});
|
||||
model.applyProviderCatalog(ENTRIES);
|
||||
model.applyControls(model.getState().controlsRequestKey ?? "", FAST);
|
||||
|
||||
expect(model.getState().featureResolution).toBe("pending");
|
||||
expect(model.getState().submitValue?.featureValues).toEqual({ webSearch: true });
|
||||
model.setModel("claude-haiku-4-5", { label: "Haiku 4.5" });
|
||||
model.applyControls(model.getState().controlsRequestKey ?? "", NO_CONTROLS);
|
||||
|
||||
expect(model.getState().submitValue?.options).toBeUndefined();
|
||||
});
|
||||
|
||||
it("prunes stored values the provider no longer reports", () => {
|
||||
const model = openAgentProfileForm({
|
||||
mode: "edit",
|
||||
profile: {
|
||||
id: "p1",
|
||||
name: "UI work",
|
||||
provider: "claude",
|
||||
featureValues: { webSearch: true, retiredFlag: true },
|
||||
},
|
||||
});
|
||||
model.applyProviderCatalog(ENTRIES);
|
||||
model.applyFeatures(model.getState().featureRequestKey ?? "", [
|
||||
{ type: "toggle", id: "webSearch", label: "Web search", value: false },
|
||||
]);
|
||||
it("never drops an option no control has drawn", () => {
|
||||
const model = openWithCatalog({ mode: "create" });
|
||||
model.setName("Fast");
|
||||
selectClaude(model);
|
||||
model.applyControls(model.getState().controlsRequestKey ?? "", FAST);
|
||||
model.setOption("token_budget", 8000);
|
||||
model.setOption("fast_mode", true);
|
||||
|
||||
expect(model.getState().featureValues).toEqual({ webSearch: true });
|
||||
model.setModel("claude-haiku-4-5", { label: "Haiku 4.5" });
|
||||
model.applyControls(model.getState().controlsRequestKey ?? "", NO_CONTROLS);
|
||||
|
||||
expect(model.getState().submitValue?.options).toEqual({ token_budget: 8000 });
|
||||
});
|
||||
|
||||
it("keeps a toggle when the daemon cannot list controls", () => {
|
||||
const model = toggledOnOpus();
|
||||
|
||||
model.setModel("claude-haiku-4-5", { label: "Haiku 4.5" });
|
||||
model.applyControlsUnavailable(model.getState().controlsRequestKey ?? "");
|
||||
|
||||
expect(model.getState().submitValue?.options).toEqual({ fast_mode: true });
|
||||
});
|
||||
|
||||
it("resolves an unavailable feature listing without showing the field", () => {
|
||||
const model = openWithCatalog({ mode: "create" });
|
||||
selectClaude(model);
|
||||
|
||||
model.applyFeaturesUnavailable(model.getState().featureRequestKey ?? "");
|
||||
model.applyControlsUnavailable(model.getState().controlsRequestKey ?? "");
|
||||
|
||||
expect(model.getState().featureResolution).toBe("complete");
|
||||
expect(model.getState().disclosure.showFeaturesField).toBe(false);
|
||||
expect(model.getState().controlsResolution).toBe("complete");
|
||||
expect(model.getState().disclosure.showControlsField).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -464,15 +642,15 @@ describe("openAgentProfileForm", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildFeatureRequestKey", () => {
|
||||
describe("buildControlsRequestKey", () => {
|
||||
it("is null without a provider", () => {
|
||||
expect(buildFeatureRequestKey(null)).toBeNull();
|
||||
expect(buildControlsRequestKey(null)).toBeNull();
|
||||
});
|
||||
|
||||
it("separates the fields so a value cannot bleed across positions", () => {
|
||||
expect(buildFeatureRequestKey({ provider: "claude", model: "a|b" })).toBe("claude|a|b||");
|
||||
expect(buildFeatureRequestKey({ provider: "claude", modeId: "a" })).not.toBe(
|
||||
buildFeatureRequestKey({ provider: "claude", model: "a" }),
|
||||
expect(buildControlsRequestKey({ provider: "claude", model: "a|b" })).toBe("claude|a|b||");
|
||||
expect(buildControlsRequestKey({ provider: "claude", modeId: "a" })).not.toBe(
|
||||
buildControlsRequestKey({ provider: "claude", model: "a" }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import type {
|
||||
AgentFeature,
|
||||
AgentOptionControl,
|
||||
ProviderOptions,
|
||||
AgentMode,
|
||||
AgentModelDefinition,
|
||||
AgentSelectOption,
|
||||
ProviderSnapshotEntry,
|
||||
} from "@getpaseo/protocol/agent-types";
|
||||
import type { AgentProfile } from "@getpaseo/protocol/messages";
|
||||
import { withoutLostControls } from "@/agent-controls/lost-controls";
|
||||
import { formatAgentModeLabel, formatThinkingOptionLabel } from "@/agent-controls/labels";
|
||||
import { applyFeatureValues, pruneFeatureValues } from "@/hooks/feature-preferences";
|
||||
import { filterSelectableModels } from "@/provider-selection/model-catalog";
|
||||
|
||||
/**
|
||||
@@ -57,11 +58,15 @@ export interface AgentProfileFormSnapshot {
|
||||
}
|
||||
|
||||
/**
|
||||
* The inputs a feature listing needs. Features are provider-scoped and change
|
||||
* with model/mode/thinking, so every one of those is part of the request.
|
||||
* The inputs a controls listing needs. Controls are provider-scoped and change
|
||||
* with model/mode/thinking, so every one of those is part of the request. The
|
||||
* profile's own options ride along so the daemon can resolve them (a legacy
|
||||
* `service_tier: "fast"` is drawn as the model's Fast tier); they are the same
|
||||
* for the life of one provider, so they are not part of the key.
|
||||
*/
|
||||
export interface AgentProfileFeatureRequest {
|
||||
export interface AgentProfileControlsRequest {
|
||||
provider: string;
|
||||
providerOptions?: ProviderOptions;
|
||||
model?: string;
|
||||
modeId?: string;
|
||||
thinkingOptionId?: string;
|
||||
@@ -73,7 +78,7 @@ export interface AgentProfileFormDisclosure {
|
||||
showModelField: boolean;
|
||||
showModeField: boolean;
|
||||
showThinkingField: boolean;
|
||||
showFeaturesField: boolean;
|
||||
showControlsField: boolean;
|
||||
}
|
||||
|
||||
export interface AgentProfileFormState {
|
||||
@@ -86,13 +91,22 @@ export interface AgentProfileFormState {
|
||||
modelId: string;
|
||||
modeId: string;
|
||||
thinkingOptionId: string;
|
||||
featureValues: Record<string, unknown>;
|
||||
/** The options the profile was opened with, including ones no control draws. */
|
||||
options: ProviderOptions;
|
||||
/** Changes made in this form, over `options`. */
|
||||
optionEdits: ProviderOptions;
|
||||
|
||||
providerOptions: AgentProfileFormOption[];
|
||||
modelOptions: AgentProfileFormOption[];
|
||||
modeOptions: AgentProfileFormOption[];
|
||||
thinkingOptions: AgentProfileFormOption[];
|
||||
features: AgentFeature[];
|
||||
controls: AgentOptionControl[];
|
||||
/** What the controls show: the options the daemon resolved from `options`, then the edits. */
|
||||
controlOptions: ProviderOptions;
|
||||
/** Every key an answer for this provider has drawn as a control. */
|
||||
drawnControlKeys: ReadonlySet<string>;
|
||||
/** The keys the latest answer draws as controls. */
|
||||
answeredControlKeys: ReadonlySet<string>;
|
||||
|
||||
providerDisplay: AgentProfileFormDisplay | null;
|
||||
modelDisplay: AgentProfileFormDisplay | null;
|
||||
@@ -100,9 +114,9 @@ export interface AgentProfileFormState {
|
||||
thinkingDisplay: AgentProfileFormDisplay | null;
|
||||
|
||||
catalogResolution: AgentProfileResolutionStatus;
|
||||
featureResolution: AgentProfileResolutionStatus;
|
||||
featureRequest: AgentProfileFeatureRequest | null;
|
||||
featureRequestKey: string | null;
|
||||
controlsResolution: AgentProfileResolutionStatus;
|
||||
controlsRequest: AgentProfileControlsRequest | null;
|
||||
controlsRequestKey: string | null;
|
||||
|
||||
disclosure: AgentProfileFormDisclosure;
|
||||
isSubmitting: boolean;
|
||||
@@ -118,9 +132,12 @@ export interface AgentProfileFormModel {
|
||||
/** Late input: the host-scoped provider catalog. Never touches selections. */
|
||||
applyProviderCatalog: (entries: readonly ProviderSnapshotEntry[]) => void;
|
||||
/** Late input: the feature list for one request. Stale keys are ignored. */
|
||||
applyFeatures: (requestKey: string, features: readonly AgentFeature[]) => void;
|
||||
applyControls: (
|
||||
requestKey: string,
|
||||
resolved: { controls: readonly AgentOptionControl[]; options: ProviderOptions },
|
||||
) => void;
|
||||
/** Resolve a request that produced no usable features (provider error). */
|
||||
applyFeaturesUnavailable: (requestKey: string) => void;
|
||||
applyControlsUnavailable: (requestKey: string) => void;
|
||||
setName: (value: string) => void;
|
||||
setAppearance: (value: { icon: string; color: string }) => void;
|
||||
setNotes: (value: string) => void;
|
||||
@@ -128,7 +145,7 @@ export interface AgentProfileFormModel {
|
||||
setModel: (modelId: string, display: AgentProfileFormDisplay | null) => void;
|
||||
setMode: (modeId: string, display: AgentProfileFormDisplay | null) => void;
|
||||
setThinking: (thinkingOptionId: string, display: AgentProfileFormDisplay | null) => void;
|
||||
setFeatureValue: (featureId: string, value: unknown) => void;
|
||||
setOption: (key: string, value: unknown) => void;
|
||||
setSubmitting: (value: boolean) => void;
|
||||
setSubmitError: (value: string | null) => void;
|
||||
}
|
||||
@@ -312,19 +329,39 @@ function refineDisplay(
|
||||
return current ?? { label: selectedId };
|
||||
}
|
||||
|
||||
function buildFeatureRequest(state: AgentProfileFormState): AgentProfileFeatureRequest | null {
|
||||
function buildControlsRequest(state: AgentProfileFormState): AgentProfileControlsRequest | null {
|
||||
if (!state.provider) {
|
||||
return null;
|
||||
}
|
||||
const ownOptions = ownOptionsOf(state);
|
||||
return {
|
||||
provider: state.provider,
|
||||
...(state.modelId ? { model: state.modelId } : {}),
|
||||
...(state.modeId ? { modeId: state.modeId } : {}),
|
||||
...(state.thinkingOptionId ? { thinkingOptionId: state.thinkingOptionId } : {}),
|
||||
...(Object.keys(ownOptions).length > 0 ? { providerOptions: ownOptions } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
export function buildFeatureRequestKey(request: AgentProfileFeatureRequest | null): string | null {
|
||||
/**
|
||||
* Everything the profile would save as its options; the daemon resolves them for the form. A
|
||||
* toggle the model in use does not draw is not saved (see `withoutLostControls`).
|
||||
*/
|
||||
function ownOptionsOf(
|
||||
state: Pick<
|
||||
AgentProfileFormState,
|
||||
"options" | "optionEdits" | "drawnControlKeys" | "answeredControlKeys"
|
||||
>,
|
||||
): ProviderOptions {
|
||||
return withoutLostControls(
|
||||
{ ...state.options, ...state.optionEdits },
|
||||
state.drawnControlKeys,
|
||||
state.answeredControlKeys,
|
||||
);
|
||||
}
|
||||
|
||||
/** The part of a request that decides which controls exist; options only change their values. */
|
||||
function buildControlsScopeKey(request: AgentProfileControlsRequest | null): string | null {
|
||||
if (!request) {
|
||||
return null;
|
||||
}
|
||||
@@ -336,12 +373,25 @@ export function buildFeatureRequestKey(request: AgentProfileFeatureRequest | nul
|
||||
].join("|");
|
||||
}
|
||||
|
||||
export function buildControlsRequestKey(
|
||||
request: AgentProfileControlsRequest | null,
|
||||
): string | null {
|
||||
if (!request) {
|
||||
return null;
|
||||
}
|
||||
const scope = buildControlsScopeKey(request);
|
||||
return request.providerOptions
|
||||
? `${scope}|${JSON.stringify(Object.entries(request.providerOptions).sort(([a], [b]) => a.localeCompare(b)))}`
|
||||
: scope;
|
||||
}
|
||||
|
||||
function buildSubmitValue(state: AgentProfileFormState): AgentProfileValue | null {
|
||||
const name = state.name.trim();
|
||||
const notes = state.notes.trim();
|
||||
if (!name || !state.provider) {
|
||||
return null;
|
||||
}
|
||||
const options = ownOptionsOf(state);
|
||||
return {
|
||||
name,
|
||||
...(state.icon ? { icon: state.icon } : {}),
|
||||
@@ -350,16 +400,16 @@ function buildSubmitValue(state: AgentProfileFormState): AgentProfileValue | nul
|
||||
...(state.modelId ? { model: state.modelId } : {}),
|
||||
...(state.modeId ? { modeId: state.modeId } : {}),
|
||||
...(state.thinkingOptionId ? { thinkingOptionId: state.thinkingOptionId } : {}),
|
||||
...(Object.keys(state.featureValues).length > 0 ? { featureValues: state.featureValues } : {}),
|
||||
...(Object.keys(options).length > 0 ? { options } : {}),
|
||||
...(notes ? { notes } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
function resolveFeatureStatus(
|
||||
featureRequestKey: string | null,
|
||||
function resolveControlsStatus(
|
||||
controlsRequestKey: string | null,
|
||||
featuresAreCurrent: boolean,
|
||||
): AgentProfileResolutionStatus {
|
||||
if (featureRequestKey === null) {
|
||||
if (controlsRequestKey === null) {
|
||||
return "idle";
|
||||
}
|
||||
return featuresAreCurrent ? "complete" : "pending";
|
||||
@@ -392,25 +442,29 @@ function buildInitialState(snapshot: AgentProfileFormSnapshot): AgentProfileForm
|
||||
modelId,
|
||||
modeId: profile.modeId ?? "",
|
||||
thinkingOptionId: profile.thinkingOptionId ?? "",
|
||||
featureValues: { ...profile.featureValues },
|
||||
options: { ...profile.options },
|
||||
optionEdits: {},
|
||||
providerOptions: [],
|
||||
modelOptions: [],
|
||||
modeOptions: [],
|
||||
thinkingOptions: [],
|
||||
features: [],
|
||||
controls: [],
|
||||
controlOptions: {},
|
||||
drawnControlKeys: new Set(),
|
||||
answeredControlKeys: new Set(),
|
||||
providerDisplay: seedDisplay(provider),
|
||||
modelDisplay: seedDisplay(modelId),
|
||||
modeDisplay: seedDisplay(profile.modeId),
|
||||
thinkingDisplay: seedDisplay(profile.thinkingOptionId),
|
||||
catalogResolution: "idle",
|
||||
featureResolution: "idle",
|
||||
featureRequest: null,
|
||||
featureRequestKey: null,
|
||||
controlsResolution: "idle",
|
||||
controlsRequest: null,
|
||||
controlsRequestKey: null,
|
||||
disclosure: {
|
||||
showModelField: false,
|
||||
showModeField: false,
|
||||
showThinkingField: false,
|
||||
showFeaturesField: false,
|
||||
showControlsField: false,
|
||||
},
|
||||
isSubmitting: false,
|
||||
submitError: null,
|
||||
@@ -422,28 +476,45 @@ function buildInitialState(snapshot: AgentProfileFormSnapshot): AgentProfileForm
|
||||
export function openAgentProfileForm(snapshot: AgentProfileFormSnapshot): AgentProfileFormModel {
|
||||
let entries: readonly ProviderSnapshotEntry[] = [];
|
||||
let catalogResolution: AgentProfileResolutionStatus = "idle";
|
||||
let resolvedFeatureKey: string | null = null;
|
||||
let resolvedFeatures: AgentFeature[] = [];
|
||||
let resolvedControlsKey: string | null = null;
|
||||
let resolvedScopeKey: string | null = null;
|
||||
let resolvedControls: AgentOptionControl[] = [];
|
||||
let resolvedOptions: ProviderOptions = {};
|
||||
let drawnKeys: ReadonlySet<string> = new Set();
|
||||
let answeredKeys: ReadonlySet<string> = new Set();
|
||||
let listeners = new Set<() => void>();
|
||||
let closed = false;
|
||||
|
||||
function derive(incoming: AgentProfileFormState): AgentProfileFormState {
|
||||
const models = resolveModels(entries, incoming.provider);
|
||||
const modes = resolveModes(entries, incoming.provider);
|
||||
const next = seedSelections(incoming, {
|
||||
entry: findEntry(entries, incoming.provider),
|
||||
models,
|
||||
modes,
|
||||
});
|
||||
const next: AgentProfileFormState = {
|
||||
...seedSelections(incoming, {
|
||||
entry: findEntry(entries, incoming.provider),
|
||||
models,
|
||||
modes,
|
||||
}),
|
||||
drawnControlKeys: drawnKeys,
|
||||
answeredControlKeys: answeredKeys,
|
||||
};
|
||||
const thinking = resolveThinkingOptions(entries, next.provider, next.modelId);
|
||||
const featureRequest = buildFeatureRequest(next);
|
||||
const featureRequestKey = buildFeatureRequestKey(featureRequest);
|
||||
const controlsRequest = buildControlsRequest(next);
|
||||
const controlsRequestKey = buildControlsRequestKey(controlsRequest);
|
||||
const controlsScopeKey = buildControlsScopeKey(controlsRequest);
|
||||
const featuresAreCurrent =
|
||||
featureRequestKey !== null && featureRequestKey === resolvedFeatureKey;
|
||||
const features = featuresAreCurrent
|
||||
? applyFeatureValues(resolvedFeatures, next.featureValues)
|
||||
: [];
|
||||
const featureResolution = resolveFeatureStatus(featureRequestKey, featuresAreCurrent);
|
||||
controlsRequestKey !== null && controlsRequestKey === resolvedControlsKey;
|
||||
// A toggle changes only the options, so the controls stay up while the daemon answers and the
|
||||
// toggle shows over the last answer. A change of provider, model, mode or thinking draws none
|
||||
// until its own answer arrives.
|
||||
const controlsApply = controlsScopeKey !== null && controlsScopeKey === resolvedScopeKey;
|
||||
const controls = controlsApply ? resolvedControls : [];
|
||||
let controlOptions: ProviderOptions = next.options;
|
||||
if (controlsApply) {
|
||||
controlOptions = featuresAreCurrent
|
||||
? resolvedOptions
|
||||
: { ...resolvedOptions, ...next.optionEdits };
|
||||
}
|
||||
const controlsResolution = resolveControlsStatus(controlsRequestKey, featuresAreCurrent);
|
||||
|
||||
const withOptions: AgentProfileFormState = {
|
||||
...next,
|
||||
@@ -451,7 +522,8 @@ export function openAgentProfileForm(snapshot: AgentProfileFormSnapshot): AgentP
|
||||
modelOptions: buildModelOptions(models),
|
||||
modeOptions: buildModeOptions(modes),
|
||||
thinkingOptions: buildThinkingOptions(thinking),
|
||||
features,
|
||||
controls,
|
||||
controlOptions,
|
||||
providerDisplay: refineDisplay(
|
||||
next.providerDisplay,
|
||||
next.provider,
|
||||
@@ -479,9 +551,9 @@ export function openAgentProfileForm(snapshot: AgentProfileFormSnapshot): AgentP
|
||||
})(),
|
||||
),
|
||||
catalogResolution,
|
||||
featureResolution,
|
||||
featureRequest,
|
||||
featureRequestKey,
|
||||
controlsResolution,
|
||||
controlsRequest,
|
||||
controlsRequestKey,
|
||||
};
|
||||
|
||||
// A field appears once the catalog can populate it, and stays visible while
|
||||
@@ -492,7 +564,7 @@ export function openAgentProfileForm(snapshot: AgentProfileFormSnapshot): AgentP
|
||||
showModeField: hasProvider && (modes.length > 0 || Boolean(withOptions.modeId)),
|
||||
showThinkingField:
|
||||
hasProvider && (thinking.length > 0 || Boolean(withOptions.thinkingOptionId)),
|
||||
showFeaturesField: hasProvider && features.length > 0,
|
||||
showControlsField: hasProvider && controls.length > 0,
|
||||
};
|
||||
const canSubmit =
|
||||
withOptions.name.trim().length > 0 &&
|
||||
@@ -531,23 +603,26 @@ export function openAgentProfileForm(snapshot: AgentProfileFormSnapshot): AgentP
|
||||
catalogResolution = "complete";
|
||||
publish((current) => current);
|
||||
},
|
||||
applyFeatures: (requestKey, features) => {
|
||||
if (requestKey !== state.featureRequestKey) {
|
||||
applyControls: (requestKey, resolved) => {
|
||||
if (requestKey !== state.controlsRequestKey) {
|
||||
return;
|
||||
}
|
||||
resolvedFeatureKey = requestKey;
|
||||
resolvedFeatures = [...features];
|
||||
publish((current) => ({
|
||||
...current,
|
||||
featureValues: pruneFeatureValues(current.featureValues, resolvedFeatures),
|
||||
}));
|
||||
resolvedControlsKey = requestKey;
|
||||
resolvedScopeKey = buildControlsScopeKey(state.controlsRequest);
|
||||
resolvedControls = [...resolved.controls];
|
||||
resolvedOptions = resolved.options;
|
||||
answeredKeys = new Set(resolved.controls.map((control) => control.key));
|
||||
drawnKeys = new Set([...drawnKeys, ...answeredKeys]);
|
||||
publish((current) => current);
|
||||
},
|
||||
applyFeaturesUnavailable: (requestKey) => {
|
||||
if (requestKey !== state.featureRequestKey) {
|
||||
applyControlsUnavailable: (requestKey) => {
|
||||
if (requestKey !== state.controlsRequestKey) {
|
||||
return;
|
||||
}
|
||||
resolvedFeatureKey = requestKey;
|
||||
resolvedFeatures = [];
|
||||
resolvedControlsKey = requestKey;
|
||||
resolvedScopeKey = buildControlsScopeKey(state.controlsRequest);
|
||||
resolvedControls = [];
|
||||
resolvedOptions = {};
|
||||
publish((current) => current);
|
||||
},
|
||||
setName: (value) => publish((current) => ({ ...current, name: value })),
|
||||
@@ -562,6 +637,8 @@ export function openAgentProfileForm(snapshot: AgentProfileFormSnapshot): AgentP
|
||||
// Everything below the provider is provider-scoped: a model id, mode id,
|
||||
// thinking id or feature id from the old provider means nothing here.
|
||||
// Clearing them is enough — `derive` seeds the new provider's defaults.
|
||||
drawnKeys = new Set();
|
||||
answeredKeys = new Set();
|
||||
return {
|
||||
...current,
|
||||
provider: providerId,
|
||||
@@ -572,7 +649,8 @@ export function openAgentProfileForm(snapshot: AgentProfileFormSnapshot): AgentP
|
||||
modeDisplay: null,
|
||||
thinkingOptionId: "",
|
||||
thinkingDisplay: null,
|
||||
featureValues: {},
|
||||
options: {},
|
||||
optionEdits: {},
|
||||
};
|
||||
}),
|
||||
setModel: (modelId, display) =>
|
||||
@@ -598,10 +676,10 @@ export function openAgentProfileForm(snapshot: AgentProfileFormSnapshot): AgentP
|
||||
publish((current) => ({ ...current, modeId, modeDisplay: display })),
|
||||
setThinking: (thinkingOptionId, display) =>
|
||||
publish((current) => ({ ...current, thinkingOptionId, thinkingDisplay: display })),
|
||||
setFeatureValue: (featureId, value) =>
|
||||
setOption: (key, value) =>
|
||||
publish((current) => ({
|
||||
...current,
|
||||
featureValues: { ...current.featureValues, [featureId]: value },
|
||||
optionEdits: { ...current.optionEdits, [key]: value },
|
||||
})),
|
||||
setSubmitting: (value) => publish((current) => ({ ...current, isSubmitting: value })),
|
||||
setSubmitError: (value) => publish((current) => ({ ...current, submitError: value })),
|
||||
|
||||
@@ -47,7 +47,7 @@ export function buildAgentProfileTags(input: {
|
||||
tags.push({ id: "thinking", label: formatThinkingOptionLabel({ id: thinkingOptionId }) });
|
||||
}
|
||||
|
||||
const featureCount = Object.keys(input.profile.featureValues ?? {}).length;
|
||||
const featureCount = Object.keys(input.profile.options ?? {}).length;
|
||||
if (featureCount > 0) {
|
||||
tags.push({ id: "features", label: input.formatFeatureCount(featureCount) });
|
||||
}
|
||||
|
||||
@@ -117,9 +117,7 @@ export function useAgentProfilePicker(
|
||||
modelId: resolved.modelId,
|
||||
modeId: resolved.modeId,
|
||||
thinkingOptionId: resolved.thinkingOptionId,
|
||||
...(Object.keys(resolved.featureValues).length > 0
|
||||
? { featureValues: resolved.featureValues }
|
||||
: {}),
|
||||
...(Object.keys(resolved.options).length > 0 ? { options: resolved.options } : {}),
|
||||
}),
|
||||
).catch((error) => {
|
||||
console.warn("[useAgentProfilePicker] persist profile selection failed", error);
|
||||
|
||||
@@ -27,7 +27,7 @@ export function useAgentProfileFormCatalog(input: {
|
||||
}, [entries, input.model]);
|
||||
}
|
||||
|
||||
export function useAgentProfileFormFeatures(input: {
|
||||
export function useAgentProfileFormControls(input: {
|
||||
serverId: string;
|
||||
model: AgentProfileFormModel;
|
||||
state: AgentProfileFormState;
|
||||
@@ -35,14 +35,14 @@ export function useAgentProfileFormFeatures(input: {
|
||||
const { t } = useTranslation();
|
||||
const client = useHostRuntimeClient(input.serverId);
|
||||
const isConnected = useHostRuntimeIsConnected(input.serverId);
|
||||
const request = input.state.featureRequest;
|
||||
const requestKey = input.state.featureRequestKey;
|
||||
const request = input.state.controlsRequest;
|
||||
const requestKey = input.state.controlsRequestKey;
|
||||
|
||||
// `dataShape: "value"` and not `"list"`: a list shape keeps the previous
|
||||
// page's data while the next request is in flight, which would hand the
|
||||
// features of one provider/model combination to the key of another.
|
||||
const featuresQuery = useFetchQuery({
|
||||
queryKey: ["agentProfileFeatures", input.serverId, requestKey],
|
||||
const controlsQuery = useFetchQuery({
|
||||
queryKey: ["agentProfileControls", input.serverId, requestKey],
|
||||
dataShape: "value",
|
||||
staleTimeMs: 5 * 60 * 1000,
|
||||
enabled: Boolean(client && isConnected && request),
|
||||
@@ -51,28 +51,28 @@ export function useAgentProfileFormFeatures(input: {
|
||||
if (!client || !request) {
|
||||
throw new Error(t("workspace.terminal.hostDisconnected"));
|
||||
}
|
||||
const payload = await client.listProviderFeatures({ ...request, cwd: HOME_SCOPE_CWD });
|
||||
const payload = await client.listProviderControls({ ...request, cwd: HOME_SCOPE_CWD });
|
||||
if (payload.error) {
|
||||
throw new Error(payload.error);
|
||||
}
|
||||
return payload.features ?? [];
|
||||
return { controls: payload.controls ?? [], options: payload.options ?? {} };
|
||||
},
|
||||
});
|
||||
|
||||
const { data, isError } = featuresQuery;
|
||||
const { data, isError } = controlsQuery;
|
||||
const { model } = input;
|
||||
|
||||
useEffect(() => {
|
||||
if (!requestKey || !data) {
|
||||
return;
|
||||
}
|
||||
model.applyFeatures(requestKey, data);
|
||||
model.applyControls(requestKey, data);
|
||||
}, [data, model, requestKey]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!requestKey || !isError) {
|
||||
return;
|
||||
}
|
||||
model.applyFeaturesUnavailable(requestKey);
|
||||
model.applyControlsUnavailable(requestKey);
|
||||
}, [isError, model, requestKey]);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@ import { useCallback, useEffect, useMemo, useRef, useState, type ReactElement }
|
||||
import { Text, View } from "react-native";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { StyleSheet } from "react-native-unistyles";
|
||||
import type { AgentFeature } from "@getpaseo/protocol/agent-types";
|
||||
import type { AgentOptionControl, ProviderOptions } from "@getpaseo/protocol/agent-types";
|
||||
import { readSelectOption, readToggleOption } from "@/agent-controls/option-controls";
|
||||
import type { AgentProfile } from "@getpaseo/protocol/messages";
|
||||
import { AdaptiveModalSheet, type SheetHeader } from "@/components/adaptive-modal-sheet";
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -24,7 +25,7 @@ import type {
|
||||
} from "../internal/profile-form-model";
|
||||
import {
|
||||
useAgentProfileFormCatalog,
|
||||
useAgentProfileFormFeatures,
|
||||
useAgentProfileFormControls,
|
||||
} from "../internal/use-profile-form-inputs";
|
||||
import {
|
||||
useAgentProfileFormModel,
|
||||
@@ -140,7 +141,7 @@ function OpenAgentProfileEditModal({
|
||||
const model = useAgentProfileFormModel(snapshot);
|
||||
const state = useAgentProfileFormState(model);
|
||||
useAgentProfileFormCatalog({ serverId, model });
|
||||
useAgentProfileFormFeatures({ serverId, model, state });
|
||||
useAgentProfileFormControls({ serverId, model, state });
|
||||
|
||||
const sheetHeader = useMemo<SheetHeader>(
|
||||
() => ({
|
||||
@@ -327,16 +328,17 @@ function OpenAgentProfileEditModal({
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{state.disclosure.showFeaturesField ? (
|
||||
{state.disclosure.showControlsField ? (
|
||||
<Field
|
||||
label={t("settings.host.agentProfiles.featuresLabel")}
|
||||
testID="agent-profile-features-field"
|
||||
>
|
||||
<View style={styles.featureCard} testID="agent-profile-features-card">
|
||||
{state.features.map((feature, index) => (
|
||||
<AgentProfileFeatureRow
|
||||
key={feature.id}
|
||||
feature={feature}
|
||||
{state.controls.map((control, index) => (
|
||||
<AgentProfileControlRow
|
||||
key={control.key}
|
||||
control={control}
|
||||
options={state.controlOptions}
|
||||
isFirst={index === 0}
|
||||
disabled={state.isSubmitting}
|
||||
size={controlSize}
|
||||
@@ -399,14 +401,16 @@ function OpenAgentProfileEditModal({
|
||||
);
|
||||
}
|
||||
|
||||
function AgentProfileFeatureRow({
|
||||
feature,
|
||||
function AgentProfileControlRow({
|
||||
control,
|
||||
options,
|
||||
isFirst,
|
||||
disabled,
|
||||
size,
|
||||
model,
|
||||
}: {
|
||||
feature: AgentFeature;
|
||||
control: AgentOptionControl;
|
||||
options: ProviderOptions;
|
||||
isFirst: boolean;
|
||||
disabled: boolean;
|
||||
size: ControlSize;
|
||||
@@ -417,74 +421,75 @@ function AgentProfileFeatureRow({
|
||||
[isFirst],
|
||||
);
|
||||
const handleToggle = useCallback(
|
||||
(value: boolean) => model.setFeatureValue(feature.id, value),
|
||||
[feature.id, model],
|
||||
(value: boolean) => model.setOption(control.key, value),
|
||||
[control.key, model],
|
||||
);
|
||||
const handleSelect = useCallback(
|
||||
(value: string) => model.setFeatureValue(feature.id, value),
|
||||
[feature.id, model],
|
||||
(value: string) => model.setOption(control.key, value),
|
||||
[control.key, model],
|
||||
);
|
||||
const selectOptions = useMemo<SelectFieldOption<string>[]>(
|
||||
() =>
|
||||
feature.type === "select"
|
||||
? feature.options.map((option) => ({
|
||||
id: option.id,
|
||||
value: option.id,
|
||||
label: option.label,
|
||||
...(option.description ? { description: option.description } : {}),
|
||||
testID: `agent-profile-feature-option-${feature.id}-${option.id}`,
|
||||
control.type === "select"
|
||||
? control.choices.map((choice) => ({
|
||||
id: choice.value,
|
||||
value: choice.value,
|
||||
label: choice.label,
|
||||
...(choice.description ? { description: choice.description } : {}),
|
||||
testID: `agent-profile-feature-option-${control.key}-${choice.value}`,
|
||||
}))
|
||||
: [],
|
||||
[feature],
|
||||
[control],
|
||||
);
|
||||
const selectedValue = control.type === "select" ? readSelectOption(control, options) : null;
|
||||
const selectedDisplay = useMemo<SelectFieldDisplay | null>(() => {
|
||||
if (feature.type !== "select" || !feature.value) {
|
||||
if (control.type !== "select" || !selectedValue) {
|
||||
return null;
|
||||
}
|
||||
const option = feature.options.find((candidate) => candidate.id === feature.value);
|
||||
return { label: option?.label ?? feature.value };
|
||||
}, [feature]);
|
||||
const choice = control.choices.find((candidate) => candidate.value === selectedValue);
|
||||
return { label: choice?.label ?? selectedValue };
|
||||
}, [control, selectedValue]);
|
||||
|
||||
if (feature.type === "select") {
|
||||
if (control.type === "select") {
|
||||
return (
|
||||
<View style={rowStyle} testID={`agent-profile-feature-row-${feature.id}`}>
|
||||
<View style={rowStyle} testID={`agent-profile-feature-row-${control.key}`}>
|
||||
<SelectField
|
||||
label={feature.label}
|
||||
value={feature.value}
|
||||
label={control.label}
|
||||
value={selectedValue}
|
||||
selectedDisplay={selectedDisplay}
|
||||
options={selectOptions}
|
||||
onChange={handleSelect}
|
||||
placeholder={feature.label}
|
||||
emptyText={feature.label}
|
||||
placeholder={control.label}
|
||||
emptyText={control.label}
|
||||
disabled={disabled}
|
||||
{...(feature.description ? { hint: feature.description } : {})}
|
||||
title={feature.label}
|
||||
{...(control.description ? { hint: control.description } : {})}
|
||||
title={control.label}
|
||||
size={size}
|
||||
testID={`agent-profile-feature-field-${feature.id}`}
|
||||
triggerTestID={`agent-profile-feature-trigger-${feature.id}`}
|
||||
testID={`agent-profile-feature-field-${control.key}`}
|
||||
triggerTestID={`agent-profile-feature-trigger-${control.key}`}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<View style={rowStyle} testID={`agent-profile-feature-row-${feature.id}`}>
|
||||
<View style={rowStyle} testID={`agent-profile-feature-row-${control.key}`}>
|
||||
<View style={styles.featureMeta}>
|
||||
<Text style={styles.featureLabel} numberOfLines={1}>
|
||||
{feature.label}
|
||||
{control.label}
|
||||
</Text>
|
||||
{feature.description ? (
|
||||
{control.description ? (
|
||||
<Text style={styles.featureDescription} numberOfLines={2}>
|
||||
{feature.description}
|
||||
{control.description}
|
||||
</Text>
|
||||
) : null}
|
||||
</View>
|
||||
<Switch
|
||||
value={feature.value === true}
|
||||
value={readToggleOption(control, options)}
|
||||
onValueChange={handleToggle}
|
||||
disabled={disabled}
|
||||
accessibilityLabel={feature.label}
|
||||
testID={`agent-profile-feature-switch-${feature.id}`}
|
||||
accessibilityLabel={control.label}
|
||||
testID={`agent-profile-feature-switch-${control.key}`}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
|
||||
@@ -1304,7 +1304,8 @@ function collectAgentSetupDiffs(left: AgentScreenAgent, right: AgentScreenAgent)
|
||||
if (left.runtimeInfo?.thinkingOptionId !== right.runtimeInfo?.thinkingOptionId) {
|
||||
reasons.push("agent.runtimeInfo.thinkingOptionId");
|
||||
}
|
||||
if (left.features !== right.features) reasons.push("agent.features");
|
||||
if (left.options !== right.options) reasons.push("agent.options");
|
||||
if (left.controls !== right.controls) reasons.push("agent.controls");
|
||||
return reasons;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,16 +40,7 @@ function createAgent(overrides: Partial<Agent> = {}): Agent {
|
||||
cwd: "/repo",
|
||||
model: "agent-model",
|
||||
thinkingOptionId: "think-hard",
|
||||
features: [
|
||||
{ type: "toggle", id: "web-search", label: "Web search", value: true },
|
||||
{
|
||||
type: "select",
|
||||
id: "effort",
|
||||
label: "Effort",
|
||||
value: "high",
|
||||
options: [{ id: "high", label: "High" }],
|
||||
},
|
||||
],
|
||||
options: { "web-search": true, effort: "high" },
|
||||
parentAgentId: null,
|
||||
labels: {},
|
||||
...overrides,
|
||||
@@ -114,7 +105,7 @@ describe("buildDraftAgentSetup", () => {
|
||||
modeId: "mode-current",
|
||||
model: "agent-model",
|
||||
thinkingOptionId: "think-hard",
|
||||
featureValues: {
|
||||
providerOptions: {
|
||||
"web-search": true,
|
||||
effort: "high",
|
||||
},
|
||||
|
||||
@@ -65,17 +65,12 @@ export function resolveClientSlashCommand(input: {
|
||||
}
|
||||
|
||||
export function buildDraftAgentSetup(agent: Agent): WorkspaceDraftTabSetup {
|
||||
const featureValues: Record<string, unknown> = {};
|
||||
for (const feature of agent.features ?? []) {
|
||||
featureValues[feature.id] = feature.value;
|
||||
}
|
||||
|
||||
return {
|
||||
provider: agent.provider,
|
||||
cwd: agent.cwd,
|
||||
modeId: agent.currentModeId ?? agent.runtimeInfo?.modeId ?? null,
|
||||
model: agent.model ?? agent.runtimeInfo?.model ?? null,
|
||||
thinkingOptionId: agent.thinkingOptionId ?? agent.runtimeInfo?.thinkingOptionId ?? null,
|
||||
featureValues,
|
||||
providerOptions: { ...agent.options },
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { AgentFeature, AgentMode, AgentSelectOption } from "@getpaseo/protocol/agent-types";
|
||||
import type {
|
||||
AgentMode,
|
||||
AgentOptionControl,
|
||||
AgentSelectOption,
|
||||
} from "@getpaseo/protocol/agent-types";
|
||||
import type { ProviderSelectorProvider } from "@/provider-selection/provider-selection";
|
||||
import type { CommandCenterContribution } from "./contributions";
|
||||
import {
|
||||
@@ -31,7 +35,7 @@ const ICONS: AgentControlContributionSource["icons"] = {
|
||||
thinking: TestIcon,
|
||||
planMode: TestIcon,
|
||||
mode: () => TestIcon,
|
||||
feature: () => TestIcon,
|
||||
control: () => TestIcon,
|
||||
};
|
||||
|
||||
function provider(input: {
|
||||
@@ -65,8 +69,8 @@ function provider(input: {
|
||||
};
|
||||
}
|
||||
|
||||
function toggleFeature(id: string, value = false, icon?: string): AgentFeature {
|
||||
return { type: "toggle", id, label: id, value, icon };
|
||||
function toggleControl(key: string, icon?: string): AgentOptionControl {
|
||||
return { type: "toggle", key, label: key, icon };
|
||||
}
|
||||
|
||||
function makeSource(
|
||||
@@ -75,7 +79,7 @@ function makeSource(
|
||||
models?: Partial<AgentControlContributionSource["models"]>;
|
||||
thinking?: Partial<AgentControlContributionSource["thinking"]>;
|
||||
modes?: Partial<NonNullable<AgentControlContributionSource["modes"]>>;
|
||||
features?: Partial<AgentControlContributionSource["features"]>;
|
||||
optionControls?: Partial<AgentControlContributionSource["optionControls"]>;
|
||||
} = {},
|
||||
): AgentControlContributionSource {
|
||||
return {
|
||||
@@ -104,10 +108,11 @@ function makeSource(
|
||||
select: () => undefined,
|
||||
...overrides.modes,
|
||||
},
|
||||
features: {
|
||||
list: [],
|
||||
set: () => undefined,
|
||||
...overrides.features,
|
||||
optionControls: {
|
||||
controls: [],
|
||||
options: {},
|
||||
onSetOption: () => undefined,
|
||||
...overrides.optionControls,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -133,7 +138,7 @@ describe("Command Center agent-control contributions", () => {
|
||||
const contributions = buildAgentControlContributions({
|
||||
...makeSource({
|
||||
models: { providers: [provider({ id: "claude", label: "Claude" })] },
|
||||
features: { list: [toggleFeature("plan_mode", true)] },
|
||||
optionControls: { controls: [toggleControl("plan_mode")], options: { plan_mode: true } },
|
||||
}),
|
||||
modes: undefined,
|
||||
});
|
||||
@@ -323,9 +328,10 @@ describe("Command Center agent-control contributions", () => {
|
||||
selectedId: "default",
|
||||
defaultModeId: "default",
|
||||
},
|
||||
features: {
|
||||
list: [toggleFeature("plan_mode", true, "list-todo")],
|
||||
set: (id, value) => {
|
||||
optionControls: {
|
||||
controls: [toggleControl("plan_mode", "list-todo")],
|
||||
options: { plan_mode: true },
|
||||
onSetOption: (id, value) => {
|
||||
calls.push([id, value]);
|
||||
},
|
||||
},
|
||||
@@ -341,9 +347,10 @@ describe("Command Center agent-control contributions", () => {
|
||||
const calls: [string, unknown][] = [];
|
||||
const contributions = buildAgentControlContributions(
|
||||
makeSource({
|
||||
features: {
|
||||
list: [toggleFeature("fast_mode", false, "zap"), toggleFeature("auto_accept", true)],
|
||||
set: (id, value) => {
|
||||
optionControls: {
|
||||
controls: [toggleControl("fast_mode", "zap"), toggleControl("auto_accept")],
|
||||
options: { fast_mode: false, auto_accept: true },
|
||||
onSetOption: (id, value) => {
|
||||
calls.push([id, value]);
|
||||
},
|
||||
},
|
||||
@@ -376,7 +383,7 @@ describe("Command Center agent-control contributions", () => {
|
||||
selectedId: "default",
|
||||
defaultModeId: "default",
|
||||
},
|
||||
features: { list: [toggleFeature("fast_mode")] },
|
||||
optionControls: { controls: [toggleControl("fast_mode")], options: {} },
|
||||
}),
|
||||
);
|
||||
const ranks = new Map<string, number>();
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import type {
|
||||
AgentFeature,
|
||||
AgentMode,
|
||||
AgentOptionControl,
|
||||
AgentProvider,
|
||||
AgentSelectOption,
|
||||
} from "@getpaseo/protocol/agent-types";
|
||||
import { readToggleOption, type ComposerOptionControls } from "@/agent-controls/option-controls";
|
||||
import type { ProviderSelectorProvider } from "@/provider-selection/provider-selection";
|
||||
import { formatAgentModeLabel, formatThinkingOptionLabel } from "@/agent-controls/labels";
|
||||
import {
|
||||
@@ -61,7 +62,7 @@ export interface AgentControlContributionIcons {
|
||||
thinking: CommandCenterIcon;
|
||||
planMode: CommandCenterIcon;
|
||||
mode(modeId: string): CommandCenterIcon;
|
||||
feature(feature: AgentFeature): CommandCenterIcon;
|
||||
control(control: AgentOptionControl): CommandCenterIcon;
|
||||
}
|
||||
|
||||
interface CommandCenterChoice {
|
||||
@@ -105,10 +106,7 @@ export interface AgentControlContributionSource {
|
||||
defaultModeId: string | null;
|
||||
select(modeId: string): void | Promise<void>;
|
||||
};
|
||||
features: {
|
||||
list: readonly AgentFeature[];
|
||||
set(featureId: string, value: unknown): void | Promise<void>;
|
||||
};
|
||||
optionControls: ComposerOptionControls;
|
||||
}
|
||||
|
||||
function buildContributions(
|
||||
@@ -242,18 +240,19 @@ function toggleChoices(input: {
|
||||
}
|
||||
|
||||
function buildPlanModeGroup(source: AgentControlContributionSource): CommandCenterChoiceGroup {
|
||||
const planFeature = source.features.list.find(
|
||||
(feature) => feature.id === PLAN_MODE_FEATURE_ID && feature.type === "toggle",
|
||||
const { controls, options, onSetOption } = source.optionControls;
|
||||
const planControl = controls.find(
|
||||
(control) => control.key === PLAN_MODE_FEATURE_ID && control.type === "toggle",
|
||||
);
|
||||
let choices: CommandCenterChoice[] = [];
|
||||
if (planFeature?.type === "toggle") {
|
||||
if (planControl?.type === "toggle") {
|
||||
choices = toggleChoices({
|
||||
source,
|
||||
key: "plan",
|
||||
icon: source.icons.feature(planFeature),
|
||||
isOn: planFeature.value,
|
||||
turnOn: () => source.features.set(PLAN_MODE_FEATURE_ID, true),
|
||||
turnOff: () => source.features.set(PLAN_MODE_FEATURE_ID, false),
|
||||
icon: source.icons.control(planControl),
|
||||
isOn: readToggleOption(planControl, options),
|
||||
turnOn: () => onSetOption(PLAN_MODE_FEATURE_ID, true),
|
||||
turnOff: () => onSetOption(PLAN_MODE_FEATURE_ID, false),
|
||||
});
|
||||
} else if (source.modes) {
|
||||
const modes = source.modes;
|
||||
@@ -280,18 +279,19 @@ function buildPlanModeGroup(source: AgentControlContributionSource): CommandCent
|
||||
}
|
||||
|
||||
function buildFastModeGroup(source: AgentControlContributionSource): CommandCenterChoiceGroup {
|
||||
const fastFeature = source.features.list.find(
|
||||
(feature) => feature.id === FAST_MODE_FEATURE_ID && feature.type === "toggle",
|
||||
const { controls, options, onSetOption } = source.optionControls;
|
||||
const fastControl = controls.find(
|
||||
(control) => control.key === FAST_MODE_FEATURE_ID && control.type === "toggle",
|
||||
);
|
||||
const choices =
|
||||
fastFeature?.type === "toggle"
|
||||
fastControl?.type === "toggle"
|
||||
? toggleChoices({
|
||||
source,
|
||||
key: "fast",
|
||||
icon: source.icons.feature(fastFeature),
|
||||
isOn: fastFeature.value,
|
||||
turnOn: () => source.features.set(FAST_MODE_FEATURE_ID, true),
|
||||
turnOff: () => source.features.set(FAST_MODE_FEATURE_ID, false),
|
||||
icon: source.icons.control(fastControl),
|
||||
isOn: readToggleOption(fastControl, options),
|
||||
turnOn: () => onSetOption(FAST_MODE_FEATURE_ID, true),
|
||||
turnOff: () => onSetOption(FAST_MODE_FEATURE_ID, false),
|
||||
})
|
||||
: [];
|
||||
return {
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import { useMemo } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type {
|
||||
AgentFeature,
|
||||
AgentMode,
|
||||
AgentProvider,
|
||||
AgentSelectOption,
|
||||
} from "@getpaseo/protocol/agent-types";
|
||||
import type { AgentMode, AgentProvider, AgentSelectOption } from "@getpaseo/protocol/agent-types";
|
||||
import type { AgentProviderDefinition } from "@getpaseo/protocol/provider-manifest";
|
||||
import {
|
||||
getAgentFeatureIcon,
|
||||
@@ -14,6 +9,7 @@ import {
|
||||
ThinkingIcon,
|
||||
} from "@/agent-controls/icons";
|
||||
import { useProviderIcons } from "@/components/provider-icons";
|
||||
import type { ComposerOptionControls } from "@/agent-controls/option-controls";
|
||||
import type { ProviderSelectorProvider } from "@/provider-selection/provider-selection";
|
||||
import {
|
||||
buildAgentControlContributions,
|
||||
@@ -44,15 +40,15 @@ export interface AgentControlCommandCenterSource {
|
||||
selectedId: string | null | undefined;
|
||||
select(modeId: string): void | Promise<void>;
|
||||
};
|
||||
features: {
|
||||
list: readonly AgentFeature[] | undefined;
|
||||
set?: (featureId: string, value: unknown) => void | Promise<void>;
|
||||
};
|
||||
/** Absent when the surface cannot change options (the agent has no client). */
|
||||
optionControls: ComposerOptionControls | null;
|
||||
}
|
||||
|
||||
function ignoreAgentFeatureChange(): void {
|
||||
return;
|
||||
}
|
||||
const NO_OPTION_CONTROLS: ComposerOptionControls = {
|
||||
controls: [],
|
||||
options: {},
|
||||
onSetOption: () => undefined,
|
||||
};
|
||||
|
||||
function resolveDefaultModeId(
|
||||
provider: string | null | undefined,
|
||||
@@ -87,7 +83,7 @@ export function useAgentControlCommandCenterActions(input: {
|
||||
}): void {
|
||||
const { t } = useTranslation();
|
||||
const { controls } = input;
|
||||
const { features, models, modes, thinking } = controls;
|
||||
const { optionControls, models, modes, thinking } = controls;
|
||||
const getProviderIcon = useProviderIcons(controls.serverId);
|
||||
const actions = useMemo(
|
||||
() =>
|
||||
@@ -104,7 +100,7 @@ export function useAgentControlCommandCenterActions(input: {
|
||||
getCommandCenterIcon(
|
||||
getAgentModeIcon(controls.provider ?? "", modeId, controls.providerDefinitions),
|
||||
),
|
||||
feature: (feature) => getCommandCenterIcon(getAgentFeatureIcon(feature.icon)),
|
||||
control: (control) => getCommandCenterIcon(getAgentFeatureIcon(control.icon)),
|
||||
},
|
||||
models: {
|
||||
providers: models.providers,
|
||||
@@ -123,10 +119,7 @@ export function useAgentControlCommandCenterActions(input: {
|
||||
modes?.select,
|
||||
resolveDefaultModeId(controls.provider, controls.providerDefinitions),
|
||||
),
|
||||
features: {
|
||||
list: features.set ? (features.list ?? []) : [],
|
||||
set: features.set ?? ignoreAgentFeatureChange,
|
||||
},
|
||||
optionControls: optionControls ?? NO_OPTION_CONTROLS,
|
||||
}),
|
||||
[
|
||||
getProviderIcon,
|
||||
@@ -134,8 +127,7 @@ export function useAgentControlCommandCenterActions(input: {
|
||||
controls.provider,
|
||||
controls.providerDefinitions,
|
||||
controls.serverId,
|
||||
features.list,
|
||||
features.set,
|
||||
optionControls,
|
||||
models.providers,
|
||||
models.select,
|
||||
models.selectedModelId,
|
||||
|
||||
@@ -208,9 +208,9 @@ function WebHoverCard({
|
||||
)
|
||||
keyPressed(event);
|
||||
};
|
||||
// Only a scroll that moves the trigger detaches the card. A streaming chat beside it does not.
|
||||
const scrolled = (event: Event) => {
|
||||
if (!(contentRef.current as unknown as HTMLElement | null)?.contains(event.target as Node))
|
||||
close();
|
||||
if ((event.target as Node).contains(trigger)) close();
|
||||
};
|
||||
document.addEventListener("focusin", focusEntered);
|
||||
document.addEventListener("focusout", focusLeft);
|
||||
|
||||
@@ -25,6 +25,13 @@ import { StyleSheet, useUnistyles } from "react-native-unistyles";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import { Settings2 } from "lucide-react-native";
|
||||
import { getAgentFeatureIcon, ThinkingIcon } from "@/agent-controls/icons";
|
||||
import {
|
||||
getControlTooltip,
|
||||
isControlActive,
|
||||
readSelectOption,
|
||||
readToggleOption,
|
||||
type ComposerOptionControls,
|
||||
} from "@/agent-controls/option-controls";
|
||||
import { formatThinkingOptionLabel } from "@/agent-controls/labels";
|
||||
import { ComboboxTrigger } from "@/components/ui/combobox-trigger";
|
||||
import { CombinedModelSelector } from "@/components/combined-model-selector";
|
||||
@@ -47,7 +54,8 @@ import {
|
||||
import { AdaptiveModalSheet, type SheetHeader } from "@/components/adaptive-modal-sheet";
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import type {
|
||||
AgentFeature,
|
||||
AgentOptionControl,
|
||||
ProviderOptions,
|
||||
AgentMode,
|
||||
AgentModelDefinition,
|
||||
AgentProvider,
|
||||
@@ -55,8 +63,6 @@ import type {
|
||||
import type { AgentProviderDefinition } from "@getpaseo/protocol/provider-manifest";
|
||||
import {
|
||||
getFeatureHighlightColor,
|
||||
isFeatureActive,
|
||||
getFeatureTooltip,
|
||||
getAgentControlHintKey,
|
||||
resolveAgentModelSelection,
|
||||
} from "@/composer/agent-controls/utils";
|
||||
@@ -101,6 +107,7 @@ interface AgentControlOption {
|
||||
type AgentControlSelector = "provider" | "mode" | "model" | "thinking" | `feature-${string}`;
|
||||
|
||||
const EMPTY_AGENT_PROVIDER_DEFINITIONS: AgentProviderDefinition[] = [];
|
||||
const EMPTY_OPTIONS: ProviderOptions = {};
|
||||
|
||||
interface ControlledAgentControlsProps {
|
||||
provider: string;
|
||||
@@ -122,8 +129,7 @@ interface ControlledAgentControlsProps {
|
||||
onEditAgentProfiles?: () => void;
|
||||
onCreateAgentProfile?: (seed: AgentProfileSeed) => void;
|
||||
onEditAgentProfile?: (profileId: string) => void;
|
||||
features?: AgentFeature[];
|
||||
onSetFeature?: (featureId: string, value: unknown) => void;
|
||||
optionControls?: ComposerOptionControls;
|
||||
onDropdownClose?: () => void;
|
||||
onModelSelectorOpen?: () => void;
|
||||
onRetryModelProvider?: (provider: AgentProvider) => void;
|
||||
@@ -150,8 +156,7 @@ export interface DraftAgentControlsProps {
|
||||
selectedThinkingOptionId: string;
|
||||
onSelectThinkingOption: (thinkingOptionId: string) => void;
|
||||
onApplyAgentProfile: DraftAgentProfileControls["applyProfile"];
|
||||
features?: AgentFeature[];
|
||||
onSetFeature?: (featureId: string, value: unknown) => void;
|
||||
optionControls?: ComposerOptionControls;
|
||||
onDropdownClose?: () => void;
|
||||
onModelSelectorOpen?: () => void;
|
||||
onRetryModelProvider?: (provider: AgentProvider) => void;
|
||||
@@ -212,7 +217,8 @@ function getModeProviderDefinitions(modeControl: AgentModeControlValue | null) {
|
||||
}
|
||||
|
||||
function getFeatureIconColor(
|
||||
feature: AgentFeature,
|
||||
control: AgentOptionControl,
|
||||
options: ProviderOptions,
|
||||
palette: {
|
||||
blue: { 400: string };
|
||||
green: { 400: string };
|
||||
@@ -220,11 +226,11 @@ function getFeatureIconColor(
|
||||
},
|
||||
foregroundMuted: string,
|
||||
): string {
|
||||
if (!isFeatureActive(feature)) {
|
||||
if (!isControlActive(control, options)) {
|
||||
return foregroundMuted;
|
||||
}
|
||||
|
||||
switch (getFeatureHighlightColor(feature.id)) {
|
||||
switch (getFeatureHighlightColor(control.key)) {
|
||||
case "blue":
|
||||
return palette.blue[400];
|
||||
case "green":
|
||||
@@ -242,20 +248,20 @@ function resolveHasAnyControl({
|
||||
providerOptions,
|
||||
canSelectModel,
|
||||
thinkingOptions,
|
||||
features,
|
||||
controls,
|
||||
hasMode,
|
||||
}: {
|
||||
providerOptions: AgentControlOption[] | undefined;
|
||||
canSelectModel: boolean;
|
||||
thinkingOptions: AgentControlOption[] | undefined;
|
||||
features: AgentFeature[] | undefined;
|
||||
controls: readonly AgentOptionControl[] | undefined;
|
||||
hasMode: boolean;
|
||||
}) {
|
||||
return (
|
||||
Boolean(providerOptions?.length) ||
|
||||
canSelectModel ||
|
||||
Boolean(thinkingOptions?.length) ||
|
||||
Boolean(features?.length) ||
|
||||
Boolean(controls?.length) ||
|
||||
hasMode
|
||||
);
|
||||
}
|
||||
@@ -393,7 +399,8 @@ type AgentControlsSlice = {
|
||||
cwd: string | null;
|
||||
runtimeModelId: string | null;
|
||||
model: string | null | undefined;
|
||||
features: AgentFeature[] | undefined;
|
||||
options: ProviderOptions | undefined;
|
||||
controls: AgentOptionControl[] | undefined;
|
||||
runtimeThinkingOptionId: string | null;
|
||||
thinkingOptionId: string | null | undefined;
|
||||
lastUsage: unknown;
|
||||
@@ -413,7 +420,8 @@ function selectAgentControlsSlice(
|
||||
cwd: currentAgent.cwd,
|
||||
runtimeModelId: currentAgent.runtimeInfo?.model ?? null,
|
||||
model: currentAgent.model,
|
||||
features: currentAgent.features,
|
||||
options: currentAgent.options,
|
||||
controls: currentAgent.controls,
|
||||
runtimeThinkingOptionId: currentAgent.runtimeInfo?.thinkingOptionId ?? null,
|
||||
thinkingOptionId: currentAgent.thinkingOptionId,
|
||||
lastUsage: currentAgent.lastUsage,
|
||||
@@ -493,8 +501,7 @@ function ControlledAgentControls({
|
||||
onEditAgentProfiles,
|
||||
onCreateAgentProfile,
|
||||
onEditAgentProfile,
|
||||
features,
|
||||
onSetFeature,
|
||||
optionControls,
|
||||
onDropdownClose,
|
||||
onModelSelectorOpen,
|
||||
onRetryModelProvider,
|
||||
@@ -546,20 +553,21 @@ function ControlledAgentControls({
|
||||
providerOptions,
|
||||
canSelectModel,
|
||||
thinkingOptions,
|
||||
features,
|
||||
controls: optionControls?.controls,
|
||||
hasMode: modeControl !== null && modeControl !== undefined,
|
||||
});
|
||||
const featureControls = useMemo(
|
||||
() =>
|
||||
(features ?? []).map((feature) => {
|
||||
if (feature.type === "toggle") return { type: "toggle" as const };
|
||||
const selectedOption = feature.options.find((option) => option.id === feature.value);
|
||||
(optionControls?.controls ?? []).map((control) => {
|
||||
if (control.type === "toggle") return { type: "toggle" as const };
|
||||
const selected = readSelectOption(control, optionControls?.options ?? {});
|
||||
const choice = control.choices.find((candidate) => candidate.value === selected);
|
||||
return {
|
||||
type: "select" as const,
|
||||
label: selectedOption?.label ?? feature.label,
|
||||
label: choice?.label ?? control.label,
|
||||
};
|
||||
}),
|
||||
[features],
|
||||
[optionControls],
|
||||
);
|
||||
const controlPresence = useMemo(
|
||||
() => ({
|
||||
@@ -743,8 +751,7 @@ function ControlledAgentControls({
|
||||
selectedModelId={selectedModelId}
|
||||
thinkingOptions={formattedThinkingOptions}
|
||||
selectedThinkingOptionId={selectedThinkingOptionId}
|
||||
features={features}
|
||||
onSetFeature={onSetFeature}
|
||||
optionControls={optionControls}
|
||||
onApplyAgentProfile={onApplyAgentProfile}
|
||||
onEditAgentProfiles={onEditAgentProfiles}
|
||||
onCreateAgentProfile={onCreateAgentProfile}
|
||||
@@ -792,8 +799,7 @@ function ControlledAgentControls({
|
||||
provider={provider}
|
||||
selectedModelId={selectedModelId}
|
||||
selectedThinkingOptionId={selectedThinkingOptionId}
|
||||
features={features}
|
||||
onSetFeature={onSetFeature}
|
||||
optionControls={optionControls}
|
||||
onApplyAgentProfile={onApplyAgentProfile}
|
||||
onEditAgentProfiles={onEditAgentProfiles}
|
||||
onCreateAgentProfile={onCreateAgentProfile}
|
||||
@@ -838,8 +844,7 @@ interface DesktopAgentControlsContentProps {
|
||||
selectedModelId?: string;
|
||||
thinkingOptions?: AgentControlOption[];
|
||||
selectedThinkingOptionId?: string;
|
||||
features?: AgentFeature[];
|
||||
onSetFeature?: (featureId: string, value: unknown) => void;
|
||||
optionControls?: ComposerOptionControls;
|
||||
onApplyAgentProfile?: (profileId: string) => void;
|
||||
onEditAgentProfiles?: () => void;
|
||||
onCreateAgentProfile?: (seed: AgentProfileSeed) => void;
|
||||
@@ -900,8 +905,7 @@ function DesktopAgentControlsContent(props: DesktopAgentControlsContentProps) {
|
||||
selectedModelId,
|
||||
thinkingOptions,
|
||||
selectedThinkingOptionId,
|
||||
features,
|
||||
onSetFeature,
|
||||
optionControls,
|
||||
onApplyAgentProfile,
|
||||
onEditAgentProfiles,
|
||||
onCreateAgentProfile,
|
||||
@@ -1057,7 +1061,7 @@ function DesktopAgentControlsContent(props: DesktopAgentControlsContentProps) {
|
||||
|
||||
{modeControl ? <AgentModeControl {...modeControl} onClose={onDropdownClose} /> : null}
|
||||
|
||||
{presentation.aggregateFeatures && features?.length ? (
|
||||
{presentation.aggregateFeatures && optionControls?.controls.length ? (
|
||||
<>
|
||||
<Pressable
|
||||
onPress={handleOpenFeatures}
|
||||
@@ -1077,27 +1081,29 @@ function DesktopAgentControlsContent(props: DesktopAgentControlsContentProps) {
|
||||
onClose={handleCloseSheet}
|
||||
testID="agent-features-sheet"
|
||||
>
|
||||
{features.map((feature) => (
|
||||
{optionControls.controls.map((control) => (
|
||||
<SheetFeatureItem
|
||||
key={`feature-${feature.id}`}
|
||||
feature={feature}
|
||||
key={`feature-${control.key}`}
|
||||
control={control}
|
||||
options={optionControls.options}
|
||||
disabled={disabled}
|
||||
openSelector={openSelector}
|
||||
handleOpenChange={handleNestedOpenChange}
|
||||
onSetFeature={onSetFeature}
|
||||
onSetOption={optionControls.onSetOption}
|
||||
/>
|
||||
))}
|
||||
</AdaptiveModalSheet>
|
||||
</>
|
||||
) : (
|
||||
features?.map((feature) => (
|
||||
optionControls?.controls.map((control) => (
|
||||
<DesktopFeatureItem
|
||||
key={`feature-${feature.id}`}
|
||||
feature={feature}
|
||||
key={`feature-${control.key}`}
|
||||
control={control}
|
||||
options={optionControls.options}
|
||||
disabled={disabled}
|
||||
openSelector={openSelector}
|
||||
handleOpenChange={handleOpenChange}
|
||||
onSetFeature={onSetFeature}
|
||||
onSetOption={optionControls.onSetOption}
|
||||
onActionComplete={onDropdownClose}
|
||||
/>
|
||||
))
|
||||
@@ -1110,8 +1116,7 @@ interface SheetAgentControlsContentProps {
|
||||
provider: string;
|
||||
selectedModelId?: string;
|
||||
selectedThinkingOptionId?: string;
|
||||
features?: AgentFeature[];
|
||||
onSetFeature?: (featureId: string, value: unknown) => void;
|
||||
optionControls?: ComposerOptionControls;
|
||||
onApplyAgentProfile?: (profileId: string) => void;
|
||||
onEditAgentProfiles?: () => void;
|
||||
onCreateAgentProfile?: (seed: AgentProfileSeed) => void;
|
||||
@@ -1154,8 +1159,7 @@ function SheetAgentControlsContent(props: SheetAgentControlsContentProps) {
|
||||
provider,
|
||||
selectedModelId,
|
||||
selectedThinkingOptionId,
|
||||
features,
|
||||
onSetFeature,
|
||||
optionControls,
|
||||
onApplyAgentProfile,
|
||||
onEditAgentProfiles,
|
||||
onCreateAgentProfile,
|
||||
@@ -1188,6 +1192,7 @@ function SheetAgentControlsContent(props: SheetAgentControlsContentProps) {
|
||||
} = props;
|
||||
|
||||
const thinkingAnchorRef = useRef<View | null>(null);
|
||||
const sheetOptions = optionControls?.options ?? EMPTY_OPTIONS;
|
||||
|
||||
const hasThinking = comboboxThinkingOptions.length > 0;
|
||||
|
||||
@@ -1238,14 +1243,15 @@ function SheetAgentControlsContent(props: SheetAgentControlsContentProps) {
|
||||
|
||||
{modeControl ? <AgentModeControl {...modeControl} surface="sheet" /> : null}
|
||||
|
||||
{(features ?? []).map((feature) => (
|
||||
{(optionControls?.controls ?? []).map((control) => (
|
||||
<SheetFeatureItem
|
||||
key={`feature-${feature.id}`}
|
||||
feature={feature}
|
||||
key={`feature-${control.key}`}
|
||||
control={control}
|
||||
options={sheetOptions}
|
||||
disabled={disabled}
|
||||
openSelector={openSelector}
|
||||
handleOpenChange={handleOpenChange}
|
||||
onSetFeature={onSetFeature}
|
||||
onSetOption={optionControls?.onSetOption}
|
||||
/>
|
||||
))}
|
||||
</View>
|
||||
@@ -1279,22 +1285,24 @@ function SheetAgentControlsContent(props: SheetAgentControlsContentProps) {
|
||||
}
|
||||
|
||||
function DesktopFeatureItem({
|
||||
feature,
|
||||
control,
|
||||
options,
|
||||
disabled,
|
||||
openSelector,
|
||||
handleOpenChange,
|
||||
onSetFeature,
|
||||
onSetOption,
|
||||
onActionComplete,
|
||||
}: {
|
||||
feature: AgentFeature;
|
||||
control: AgentOptionControl;
|
||||
options: ProviderOptions;
|
||||
disabled: boolean;
|
||||
openSelector: AgentControlSelector | null;
|
||||
handleOpenChange: (selector: AgentControlSelector) => (nextOpen: boolean) => void;
|
||||
onSetFeature?: (featureId: string, value: unknown) => void;
|
||||
onSetOption?: (key: string, value: unknown) => void;
|
||||
onActionComplete?: () => void;
|
||||
}) {
|
||||
const { theme } = useUnistyles();
|
||||
const featureSelector: AgentControlSelector = `feature-${feature.id}`;
|
||||
const featureSelector: AgentControlSelector = `feature-${control.key}`;
|
||||
const featureAnchorRef = useRef<View>(null);
|
||||
|
||||
const handleFeatureOpenChange = useMemo(
|
||||
@@ -1307,120 +1315,117 @@ function DesktopFeatureItem({
|
||||
);
|
||||
|
||||
const handleTogglePress = useCallback(() => {
|
||||
if (feature.type === "toggle") {
|
||||
onSetFeature?.(feature.id, !feature.value);
|
||||
if (control.type === "toggle") {
|
||||
onSetOption?.(control.key, !readToggleOption(control, options));
|
||||
onActionComplete?.();
|
||||
}
|
||||
}, [feature, onActionComplete, onSetFeature]);
|
||||
}, [control, onActionComplete, onSetOption, options]);
|
||||
|
||||
const handleSelectOption = useCallback(
|
||||
(optionId: string) => {
|
||||
onSetFeature?.(feature.id, optionId);
|
||||
(choiceValue: string) => {
|
||||
onSetOption?.(control.key, choiceValue);
|
||||
},
|
||||
[feature.id, onSetFeature],
|
||||
[control.key, onSetOption],
|
||||
);
|
||||
const comboboxOptions = useMemo<ComboboxOption[]>(
|
||||
() =>
|
||||
feature.type === "select"
|
||||
? feature.options.map((option) => ({ id: option.id, label: option.label }))
|
||||
control.type === "select"
|
||||
? control.choices.map((choice) => ({ id: choice.value, label: choice.label }))
|
||||
: [],
|
||||
[feature],
|
||||
[control],
|
||||
);
|
||||
|
||||
if (feature.type === "toggle") {
|
||||
const FeatureIcon = getAgentFeatureIcon(feature.icon);
|
||||
const FeatureIcon = getAgentFeatureIcon(control.icon);
|
||||
const iconColor = getFeatureIconColor(
|
||||
control,
|
||||
options,
|
||||
theme.colors.palette,
|
||||
theme.colors.foregroundMuted,
|
||||
);
|
||||
|
||||
if (control.type === "toggle") {
|
||||
return (
|
||||
<Tooltip delayDuration={0} enabledOnDesktop enabledOnMobile={false}>
|
||||
<TooltipTrigger asChild triggerRefProp="ref">
|
||||
<AgentControlTrigger
|
||||
icon={FeatureIcon}
|
||||
iconColor={getFeatureIconColor(
|
||||
feature,
|
||||
theme.colors.palette,
|
||||
theme.colors.foregroundMuted,
|
||||
)}
|
||||
iconColor={iconColor}
|
||||
surface="toolbar"
|
||||
label={feature.label}
|
||||
label={control.label}
|
||||
showToolbarLabel={false}
|
||||
disabled={disabled}
|
||||
onPress={handleTogglePress}
|
||||
accessibilityLabel={getFeatureTooltip(feature)}
|
||||
testID={`agent-feature-${feature.id}`}
|
||||
accessibilityLabel={getControlTooltip(control)}
|
||||
testID={`agent-feature-${control.key}`}
|
||||
/>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top" align="center" offset={8}>
|
||||
<Text style={styles.tooltipText}>{getFeatureTooltip(feature)}</Text>
|
||||
<Text style={styles.tooltipText}>{getControlTooltip(control)}</Text>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
if (feature.type === "select") {
|
||||
const FeatureIcon = getAgentFeatureIcon(feature.icon);
|
||||
const selectedOption = feature.options.find((o) => o.id === feature.value);
|
||||
const iconOnly = feature.desktopTrigger === "icon";
|
||||
const tooltip = iconOnly
|
||||
? `${feature.label}: ${selectedOption?.label ?? feature.label}`
|
||||
: getFeatureTooltip(feature);
|
||||
return (
|
||||
<>
|
||||
<Tooltip delayDuration={0} enabledOnDesktop enabledOnMobile={false}>
|
||||
<TooltipTrigger asChild triggerRefProp="ref">
|
||||
<AgentControlTrigger
|
||||
ref={featureAnchorRef}
|
||||
icon={FeatureIcon}
|
||||
iconColor={getFeatureIconColor(
|
||||
feature,
|
||||
theme.colors.palette,
|
||||
theme.colors.foregroundMuted,
|
||||
)}
|
||||
surface="toolbar"
|
||||
label={feature.label}
|
||||
value={selectedOption?.label ?? feature.label}
|
||||
showToolbarLabel={!iconOnly}
|
||||
open={openSelector === featureSelector}
|
||||
disabled={disabled}
|
||||
onPress={handleSelectPress}
|
||||
accessibilityLabel={tooltip}
|
||||
testID={`agent-feature-${feature.id}`}
|
||||
/>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top" align="center" offset={8}>
|
||||
<Text style={styles.tooltipText}>{tooltip}</Text>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
<Combobox
|
||||
options={comboboxOptions}
|
||||
value={String(feature.value)}
|
||||
onSelect={handleSelectOption}
|
||||
open={openSelector === featureSelector}
|
||||
onOpenChange={handleFeatureOpenChange}
|
||||
anchorRef={featureAnchorRef}
|
||||
desktopPlacement="top-start"
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
const selectedValue = readSelectOption(control, options);
|
||||
const selectedChoice = control.choices.find((choice) => choice.value === selectedValue);
|
||||
const iconOnly = control.desktopTrigger === "icon";
|
||||
const tooltip = iconOnly
|
||||
? `${control.label}: ${selectedChoice?.label ?? control.label}`
|
||||
: getControlTooltip(control);
|
||||
return (
|
||||
<>
|
||||
<Tooltip delayDuration={0} enabledOnDesktop enabledOnMobile={false}>
|
||||
<TooltipTrigger asChild triggerRefProp="ref">
|
||||
<AgentControlTrigger
|
||||
ref={featureAnchorRef}
|
||||
icon={FeatureIcon}
|
||||
iconColor={iconColor}
|
||||
surface="toolbar"
|
||||
label={control.label}
|
||||
value={selectedChoice?.label ?? control.label}
|
||||
showToolbarLabel={!iconOnly}
|
||||
open={openSelector === featureSelector}
|
||||
disabled={disabled}
|
||||
onPress={handleSelectPress}
|
||||
accessibilityLabel={tooltip}
|
||||
testID={`agent-feature-${control.key}`}
|
||||
/>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top" align="center" offset={8}>
|
||||
<Text style={styles.tooltipText}>{tooltip}</Text>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
<Combobox
|
||||
options={comboboxOptions}
|
||||
value={String(selectedValue)}
|
||||
onSelect={handleSelectOption}
|
||||
open={openSelector === featureSelector}
|
||||
onOpenChange={handleFeatureOpenChange}
|
||||
anchorRef={featureAnchorRef}
|
||||
desktopPlacement="top-start"
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function SheetFeatureItem({
|
||||
feature,
|
||||
control,
|
||||
options,
|
||||
disabled,
|
||||
openSelector,
|
||||
handleOpenChange,
|
||||
onSetFeature,
|
||||
onSetOption,
|
||||
}: {
|
||||
feature: AgentFeature;
|
||||
control: AgentOptionControl;
|
||||
options: ProviderOptions;
|
||||
disabled: boolean;
|
||||
openSelector: AgentControlSelector | null;
|
||||
handleOpenChange: (selector: AgentControlSelector) => (nextOpen: boolean) => void;
|
||||
onSetFeature?: (featureId: string, value: unknown) => void;
|
||||
onSetOption?: (key: string, value: unknown) => void;
|
||||
}) {
|
||||
const { theme } = useUnistyles();
|
||||
const { t } = useTranslation();
|
||||
const featureSelector: AgentControlSelector = `feature-${feature.id}`;
|
||||
const featureSelector: AgentControlSelector = `feature-${control.key}`;
|
||||
const featureAnchorRef = useRef<View>(null);
|
||||
|
||||
const handleFeatureOpenChange = useMemo(
|
||||
@@ -1431,97 +1436,71 @@ function SheetFeatureItem({
|
||||
() => handleFeatureOpenChange(openSelector !== featureSelector),
|
||||
[featureSelector, handleFeatureOpenChange, openSelector],
|
||||
);
|
||||
const sheetHeader = useMemo<SheetHeader>(() => ({ title: feature.label }), [feature.label]);
|
||||
const sheetHeader = useMemo<SheetHeader>(() => ({ title: control.label }), [control.label]);
|
||||
|
||||
const handleSelectOption = useCallback(
|
||||
(optionId: string) => {
|
||||
onSetFeature?.(feature.id, feature.type === "toggle" ? optionId === "true" : optionId);
|
||||
(choiceValue: string) => {
|
||||
onSetOption?.(control.key, control.type === "toggle" ? choiceValue === "true" : choiceValue);
|
||||
},
|
||||
[feature.id, feature.type, onSetFeature],
|
||||
[control.key, control.type, onSetOption],
|
||||
);
|
||||
const comboboxOptions = useMemo<ComboboxOption[]>(() => {
|
||||
if (feature.type === "select") {
|
||||
return feature.options.map((option) => ({ id: option.id, label: option.label }));
|
||||
if (control.type === "select") {
|
||||
return control.choices.map((choice) => ({ id: choice.value, label: choice.label }));
|
||||
}
|
||||
return [
|
||||
{ id: "true", label: t("agentControls.features.on") },
|
||||
{ id: "false", label: t("agentControls.features.off") },
|
||||
];
|
||||
}, [feature, t]);
|
||||
}, [control, t]);
|
||||
|
||||
if (feature.type === "toggle") {
|
||||
const FeatureIcon = getAgentFeatureIcon(feature.icon);
|
||||
return (
|
||||
<>
|
||||
<AgentControlTrigger
|
||||
ref={featureAnchorRef}
|
||||
icon={FeatureIcon}
|
||||
iconColor={getFeatureIconColor(
|
||||
feature,
|
||||
theme.colors.palette,
|
||||
theme.colors.foregroundMuted,
|
||||
)}
|
||||
surface="sheet"
|
||||
label={feature.label}
|
||||
value={feature.value ? t("agentControls.features.on") : t("agentControls.features.off")}
|
||||
open={openSelector === featureSelector}
|
||||
disabled={disabled}
|
||||
onPress={handleSelectPress}
|
||||
accessibilityLabel={getFeatureTooltip(feature)}
|
||||
testID={`agent-feature-${feature.id}`}
|
||||
/>
|
||||
<Combobox
|
||||
options={comboboxOptions}
|
||||
value={String(feature.value)}
|
||||
onSelect={handleSelectOption}
|
||||
open={openSelector === featureSelector}
|
||||
onOpenChange={handleFeatureOpenChange}
|
||||
anchorRef={featureAnchorRef}
|
||||
presentation="push"
|
||||
searchable={false}
|
||||
header={sheetHeader}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
const FeatureIcon = getAgentFeatureIcon(control.icon);
|
||||
const iconColor = getFeatureIconColor(
|
||||
control,
|
||||
options,
|
||||
theme.colors.palette,
|
||||
theme.colors.foregroundMuted,
|
||||
);
|
||||
let selectedValue: string;
|
||||
let displayValue: string;
|
||||
if (control.type === "toggle") {
|
||||
const isOn = readToggleOption(control, options);
|
||||
selectedValue = String(isOn);
|
||||
displayValue = isOn ? t("agentControls.features.on") : t("agentControls.features.off");
|
||||
} else {
|
||||
const selected = readSelectOption(control, options);
|
||||
selectedValue = String(selected);
|
||||
displayValue =
|
||||
control.choices.find((choice) => choice.value === selected)?.label ?? control.label;
|
||||
}
|
||||
|
||||
if (feature.type === "select") {
|
||||
const FeatureIcon = getAgentFeatureIcon(feature.icon);
|
||||
const selectedOption = feature.options.find((o) => o.id === feature.value);
|
||||
return (
|
||||
<>
|
||||
<AgentControlTrigger
|
||||
ref={featureAnchorRef}
|
||||
icon={FeatureIcon}
|
||||
iconColor={getFeatureIconColor(
|
||||
feature,
|
||||
theme.colors.palette,
|
||||
theme.colors.foregroundMuted,
|
||||
)}
|
||||
surface="sheet"
|
||||
label={feature.label}
|
||||
value={selectedOption?.label ?? feature.label}
|
||||
open={openSelector === featureSelector}
|
||||
disabled={disabled}
|
||||
onPress={handleSelectPress}
|
||||
accessibilityLabel={getFeatureTooltip(feature)}
|
||||
testID={`agent-feature-${feature.id}`}
|
||||
/>
|
||||
<Combobox
|
||||
options={comboboxOptions}
|
||||
value={String(feature.value)}
|
||||
onSelect={handleSelectOption}
|
||||
open={openSelector === featureSelector}
|
||||
onOpenChange={handleFeatureOpenChange}
|
||||
anchorRef={featureAnchorRef}
|
||||
presentation="push"
|
||||
header={sheetHeader}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
return (
|
||||
<>
|
||||
<AgentControlTrigger
|
||||
ref={featureAnchorRef}
|
||||
icon={FeatureIcon}
|
||||
iconColor={iconColor}
|
||||
surface="sheet"
|
||||
label={control.label}
|
||||
value={displayValue}
|
||||
open={openSelector === featureSelector}
|
||||
disabled={disabled}
|
||||
onPress={handleSelectPress}
|
||||
accessibilityLabel={getControlTooltip(control)}
|
||||
testID={`agent-feature-${control.key}`}
|
||||
/>
|
||||
<Combobox
|
||||
options={comboboxOptions}
|
||||
value={selectedValue}
|
||||
onSelect={handleSelectOption}
|
||||
open={openSelector === featureSelector}
|
||||
onOpenChange={handleFeatureOpenChange}
|
||||
anchorRef={featureAnchorRef}
|
||||
presentation="push"
|
||||
searchable={control.type === "toggle" ? false : undefined}
|
||||
header={sheetHeader}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function ThinkingComboboxOption({
|
||||
@@ -1549,6 +1528,18 @@ function ThinkingComboboxOption({
|
||||
);
|
||||
}
|
||||
|
||||
function useAgentOptionControls(
|
||||
agent: { controls?: AgentOptionControl[]; options?: ProviderOptions } | null | undefined,
|
||||
onSetOption: ComposerOptionControls["onSetOption"],
|
||||
): ComposerOptionControls {
|
||||
const controls = agent?.controls;
|
||||
const options = agent?.options;
|
||||
return useMemo(
|
||||
() => ({ controls: controls ?? [], options: options ?? EMPTY_OPTIONS, onSetOption }),
|
||||
[controls, onSetOption, options],
|
||||
);
|
||||
}
|
||||
|
||||
export const AgentControls = memo(function AgentControls({
|
||||
agentId,
|
||||
serverId,
|
||||
@@ -1700,8 +1691,8 @@ export const AgentControls = memo(function AgentControls({
|
||||
[activeModelId, agentId, agentProvider, client, toast, updatePreferences],
|
||||
);
|
||||
|
||||
const handleSetFeature = useCallback(
|
||||
(featureId: string, value: unknown) => {
|
||||
const handleSetOption = useCallback(
|
||||
(key: string, value: unknown) => {
|
||||
if (!client || !agentProvider) {
|
||||
return;
|
||||
}
|
||||
@@ -1710,22 +1701,24 @@ export const AgentControls = memo(function AgentControls({
|
||||
preferences: current,
|
||||
provider: agentProvider,
|
||||
updates: {
|
||||
featureValues: {
|
||||
[featureId]: value,
|
||||
options: {
|
||||
[key]: value,
|
||||
},
|
||||
},
|
||||
}),
|
||||
).catch((error) => {
|
||||
console.warn("[AgentControls] persist feature preference failed", error);
|
||||
console.warn("[AgentControls] persist option preference failed", error);
|
||||
});
|
||||
void client.setAgentFeature(agentId, featureId, value).catch((error) => {
|
||||
console.warn("[AgentControls] setAgentFeature failed", error);
|
||||
void client.setAgentOptions(agentId, { [key]: value }).catch((error) => {
|
||||
console.warn("[AgentControls] setAgentOptions failed", error);
|
||||
toast.error(toErrorMessage(error));
|
||||
});
|
||||
},
|
||||
[agentId, agentProvider, client, toast, updatePreferences],
|
||||
);
|
||||
|
||||
const agentOptionControls = useAgentOptionControls(agent, handleSetOption);
|
||||
|
||||
const commandCenterControls = useMemo<AgentControlCommandCenterSource>(
|
||||
() => ({
|
||||
serverId,
|
||||
@@ -1744,21 +1737,18 @@ export const AgentControls = memo(function AgentControls({
|
||||
select: handleSelectThinkingOption,
|
||||
},
|
||||
modes: commandCenterModes,
|
||||
features: {
|
||||
list: agent?.features,
|
||||
set: handleSetFeature,
|
||||
},
|
||||
optionControls: client ? agentOptionControls : null,
|
||||
}),
|
||||
[
|
||||
activeModelId,
|
||||
agent?.features,
|
||||
agentOptionControls,
|
||||
client,
|
||||
agentId,
|
||||
agentModelSelectorProviders,
|
||||
agentProvider,
|
||||
commandCenterModes,
|
||||
handleSelectCommandCenterModel,
|
||||
handleSelectThinkingOption,
|
||||
handleSetFeature,
|
||||
modeProviderDefinitions,
|
||||
modelSelection.selectedThinkingId,
|
||||
modelSelection.thinkingOptions,
|
||||
@@ -1807,8 +1797,7 @@ export const AgentControls = memo(function AgentControls({
|
||||
thinkingOptions={thinkingOptions.length > 0 ? thinkingOptions : undefined}
|
||||
selectedThinkingOptionId={modelSelection.selectedThinkingId ?? undefined}
|
||||
onSelectThinkingOption={handleSelectThinkingOption}
|
||||
features={agent.features}
|
||||
onSetFeature={handleSetFeature}
|
||||
optionControls={agentOptionControls}
|
||||
isModelLoading={snapshotIsLoading || selectedProviderIsLoading}
|
||||
onModelSelectorOpen={handleModelSelectorOpen}
|
||||
onRetryModelProvider={handleRetryModelProvider}
|
||||
@@ -1840,8 +1829,7 @@ export function DraftAgentControls({
|
||||
selectedThinkingOptionId,
|
||||
onSelectThinkingOption,
|
||||
onApplyAgentProfile,
|
||||
features,
|
||||
onSetFeature,
|
||||
optionControls,
|
||||
onDropdownClose,
|
||||
onModelSelectorOpen,
|
||||
onRetryModelProvider,
|
||||
@@ -1927,8 +1915,7 @@ export function DraftAgentControls({
|
||||
thinkingOptions={mappedThinkingOptions.length > 0 ? mappedThinkingOptions : undefined}
|
||||
selectedThinkingOptionId={effectiveSelectedThinkingOption}
|
||||
onSelectThinkingOption={onSelectThinkingOption}
|
||||
features={features}
|
||||
onSetFeature={onSetFeature}
|
||||
optionControls={optionControls}
|
||||
onDropdownClose={onDropdownClose}
|
||||
onModelSelectorOpen={onModelSelectorOpen}
|
||||
onRetryModelProvider={onRetryModelProvider}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
getFeatureHighlightColor,
|
||||
getFeatureTooltip,
|
||||
getAgentControlHintKey,
|
||||
isFeatureActive,
|
||||
normalizeModelId,
|
||||
resolveAgentModelSelection,
|
||||
} from "./utils";
|
||||
@@ -17,51 +15,12 @@ describe("getAgentControlHintKey", () => {
|
||||
});
|
||||
|
||||
describe("feature metadata helpers", () => {
|
||||
it("prefers explicit feature tooltip copy", () => {
|
||||
expect(
|
||||
getFeatureTooltip({
|
||||
label: "Plan",
|
||||
tooltip: "Toggle plan mode",
|
||||
}),
|
||||
).toBe("Toggle plan mode");
|
||||
});
|
||||
|
||||
it("falls back to the feature label when no tooltip is provided", () => {
|
||||
expect(
|
||||
getFeatureTooltip({
|
||||
label: "Custom",
|
||||
}),
|
||||
).toBe("Custom");
|
||||
});
|
||||
|
||||
it("maps feature highlight colors by feature id", () => {
|
||||
expect(getFeatureHighlightColor("fast_mode")).toBe("yellow");
|
||||
expect(getFeatureHighlightColor("service_tier")).toBe("yellow");
|
||||
expect(getFeatureHighlightColor("plan_mode")).toBe("blue");
|
||||
expect(getFeatureHighlightColor("other")).toBe("default");
|
||||
});
|
||||
|
||||
it("treats a select feature as active when a non-default option is selected", () => {
|
||||
const speed = {
|
||||
type: "select" as const,
|
||||
id: "service_tier",
|
||||
label: "Speed",
|
||||
options: [
|
||||
{ id: "default", label: "Normal", isDefault: true },
|
||||
{ id: "fast", label: "Fast" },
|
||||
],
|
||||
};
|
||||
expect(isFeatureActive({ ...speed, value: "default" })).toBe(false);
|
||||
expect(isFeatureActive({ ...speed, value: "fast" })).toBe(true);
|
||||
expect(
|
||||
isFeatureActive({
|
||||
type: "toggle",
|
||||
id: "fast_mode",
|
||||
label: "Fast",
|
||||
value: true,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("normalizeModelId", () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { AgentFeature, AgentModelDefinition } from "@getpaseo/protocol/agent-types";
|
||||
import type { AgentModelDefinition } from "@getpaseo/protocol/agent-types";
|
||||
import { i18n } from "@/i18n/i18next";
|
||||
import { formatThinkingOptionLabel } from "@/agent-controls/labels";
|
||||
import {
|
||||
@@ -35,16 +35,6 @@ export function normalizeModelId(modelId: string | null | undefined): string | n
|
||||
return normalized;
|
||||
}
|
||||
|
||||
export function getFeatureTooltip(feature: Pick<AgentFeature, "label" | "tooltip">): string {
|
||||
return feature.tooltip ?? feature.label;
|
||||
}
|
||||
|
||||
export function isFeatureActive(feature: AgentFeature): boolean {
|
||||
if (feature.type === "toggle") return feature.value;
|
||||
const selectedOption = feature.options.find((option) => option.id === feature.value);
|
||||
return selectedOption !== undefined && !selectedOption.isDefault;
|
||||
}
|
||||
|
||||
export function getFeatureHighlightColor(featureId: string): FeatureHighlightColor {
|
||||
switch (featureId) {
|
||||
case FAST_MODE_FEATURE_ID:
|
||||
|
||||
@@ -20,12 +20,11 @@ export function resolveDraftKey(input: {
|
||||
|
||||
export function buildDraftAgentControls(input: {
|
||||
formState: UseAgentFormStateResult;
|
||||
features?: DraftAgentControlsProps["features"];
|
||||
onSetFeature?: DraftAgentControlsProps["onSetFeature"];
|
||||
optionControls?: DraftAgentControlsProps["optionControls"];
|
||||
onApplyAgentProfile: DraftAgentControlsProps["onApplyAgentProfile"];
|
||||
onDropdownClose?: DraftAgentControlsProps["onDropdownClose"];
|
||||
}): DraftAgentControlsProps {
|
||||
const { formState, features, onSetFeature, onApplyAgentProfile, onDropdownClose } = input;
|
||||
const { formState, optionControls, onApplyAgentProfile, onDropdownClose } = input;
|
||||
return {
|
||||
providerDefinitions: formState.providerDefinitions,
|
||||
selectedProvider: formState.selectedProvider,
|
||||
@@ -43,8 +42,7 @@ export function buildDraftAgentControls(input: {
|
||||
selectedThinkingOptionId: formState.selectedThinkingOptionId,
|
||||
onSelectThinkingOption: formState.setThinkingOptionFromUser,
|
||||
onApplyAgentProfile,
|
||||
features,
|
||||
onSetFeature,
|
||||
optionControls,
|
||||
onDropdownClose,
|
||||
onModelSelectorOpen: formState.refetchProviderModelsIfStale,
|
||||
onRetryModelProvider: formState.refreshProviderModels,
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
type CreateAgentInitialValues,
|
||||
type UseAgentFormStateResult,
|
||||
} from "@/hooks/use-agent-form-state";
|
||||
import { useDraftAgentFeatures } from "@/hooks/use-draft-agent-features";
|
||||
import { useDraftProviderOptions } from "@/hooks/use-draft-provider-options";
|
||||
import {
|
||||
buildDraftAgentControls,
|
||||
hasDraftContent,
|
||||
@@ -35,7 +35,7 @@ type AttachmentUpdater =
|
||||
interface AgentInputDraftComposerOptions {
|
||||
initialServerId: string | null;
|
||||
initialValues?: CreateAgentInitialValues;
|
||||
initialFeatureValues?: Record<string, unknown>;
|
||||
initialProviderOptions?: Record<string, unknown>;
|
||||
isVisible?: boolean;
|
||||
lockedWorkingDir?: string;
|
||||
}
|
||||
@@ -50,7 +50,7 @@ type DraftComposerState = UseAgentFormStateResult & {
|
||||
effectiveModeId: string;
|
||||
effectiveModelId: string;
|
||||
effectiveThinkingOptionId: string;
|
||||
featureValues: Record<string, unknown> | undefined;
|
||||
providerOptions: Record<string, unknown> | undefined;
|
||||
agentControls: DraftAgentControlsProps;
|
||||
commandDraft: DraftCommandTarget;
|
||||
};
|
||||
@@ -274,26 +274,25 @@ export function useAgentInputDraft(input: UseAgentInputDraftInput): AgentInputDr
|
||||
);
|
||||
|
||||
const {
|
||||
features: draftFeatures,
|
||||
featureValues: draftFeatureValues,
|
||||
setFeatureValue: setDraftFeatureValue,
|
||||
applyProfileFeatureValues,
|
||||
} = useDraftAgentFeatures({
|
||||
optionControls: draftOptionControls,
|
||||
options: draftOptions,
|
||||
applyProfile: applyProfileOptions,
|
||||
} = useDraftProviderOptions({
|
||||
serverId: formState.selectedServerId,
|
||||
provider: formState.selectedProvider,
|
||||
cwd: workingDir,
|
||||
modeId: formState.selectedMode,
|
||||
modelId: effectiveModelId,
|
||||
thinkingOptionId: effectiveThinkingOptionId,
|
||||
initialFeatureValues: composerOptions?.initialFeatureValues,
|
||||
initialOptions: composerOptions?.initialProviderOptions,
|
||||
});
|
||||
|
||||
const applyDraftAgentProfile = useCallback(
|
||||
(profile: Parameters<typeof formState.applyProfileFromUser>[0]) => {
|
||||
formState.applyProfileFromUser(profile);
|
||||
applyProfileFeatureValues(profile.featureValues);
|
||||
applyProfileOptions({ provider: profile.provider, options: profile.options });
|
||||
},
|
||||
[applyProfileFeatureValues, formState],
|
||||
[applyProfileOptions, formState],
|
||||
);
|
||||
|
||||
const commandDraft = useMemo(
|
||||
@@ -303,15 +302,9 @@ export function useAgentInputDraft(input: UseAgentInputDraftInput): AgentInputDr
|
||||
cwd: workingDir,
|
||||
effectiveModelId,
|
||||
effectiveThinkingOptionId,
|
||||
featureValues: draftFeatureValues,
|
||||
providerOptions: draftOptions,
|
||||
}),
|
||||
[
|
||||
effectiveModelId,
|
||||
effectiveThinkingOptionId,
|
||||
draftFeatureValues,
|
||||
providerSelection,
|
||||
workingDir,
|
||||
],
|
||||
[effectiveModelId, effectiveThinkingOptionId, draftOptions, providerSelection, workingDir],
|
||||
);
|
||||
|
||||
const composerState = useMemo<DraftComposerState | null>(() => {
|
||||
@@ -325,11 +318,10 @@ export function useAgentInputDraft(input: UseAgentInputDraftInput): AgentInputDr
|
||||
effectiveModeId,
|
||||
effectiveModelId,
|
||||
effectiveThinkingOptionId,
|
||||
featureValues: draftFeatureValues,
|
||||
providerOptions: draftOptions,
|
||||
agentControls: buildDraftAgentControls({
|
||||
formState,
|
||||
features: draftFeatures,
|
||||
onSetFeature: setDraftFeatureValue,
|
||||
optionControls: draftOptionControls,
|
||||
onApplyAgentProfile: applyDraftAgentProfile,
|
||||
}),
|
||||
commandDraft,
|
||||
@@ -340,11 +332,10 @@ export function useAgentInputDraft(input: UseAgentInputDraftInput): AgentInputDr
|
||||
effectiveModeId,
|
||||
effectiveModelId,
|
||||
effectiveThinkingOptionId,
|
||||
draftFeatures,
|
||||
draftFeatureValues,
|
||||
draftOptionControls,
|
||||
draftOptions,
|
||||
applyDraftAgentProfile,
|
||||
formState,
|
||||
setDraftFeatureValue,
|
||||
workingDir,
|
||||
]);
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { ComposerOptionControls } from "@/agent-controls/option-controls";
|
||||
import { useCallback, useEffect, useMemo, useRef } from "react";
|
||||
import { Keyboard, ScrollView, StyleSheet as RNStyleSheet, Text, View } from "react-native";
|
||||
import { useTranslation } from "react-i18next";
|
||||
@@ -65,7 +66,7 @@ interface AutoSubmitConfig {
|
||||
modeId: string | null;
|
||||
model: string | null;
|
||||
thinkingOptionId: string | null;
|
||||
featureValues: Record<string, unknown>;
|
||||
providerOptions: Record<string, unknown>;
|
||||
}
|
||||
|
||||
function resolveAutoSubmitConfig(
|
||||
@@ -74,7 +75,7 @@ function resolveAutoSubmitConfig(
|
||||
modeId?: string | null;
|
||||
model?: string | null;
|
||||
thinkingOptionId?: string | null;
|
||||
featureValues?: Record<string, unknown>;
|
||||
providerOptions?: Record<string, unknown>;
|
||||
} | null,
|
||||
): AutoSubmitConfig | null {
|
||||
if (!pending) return null;
|
||||
@@ -83,7 +84,7 @@ function resolveAutoSubmitConfig(
|
||||
modeId: pending.modeId ?? null,
|
||||
model: pending.model ?? null,
|
||||
thinkingOptionId: pending.thinkingOptionId ?? null,
|
||||
featureValues: pending.featureValues ?? {},
|
||||
providerOptions: pending.providerOptions ?? {},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -131,7 +132,7 @@ async function submitDraftCreateRequest(input: {
|
||||
effectiveModeId: string;
|
||||
effectiveModelId: string | null;
|
||||
effectiveThinkingOptionId: string | null;
|
||||
featureValues: Record<string, unknown> | undefined;
|
||||
providerOptions: Record<string, unknown> | undefined;
|
||||
};
|
||||
hostDisconnectedMessage: string;
|
||||
selectModelMessage: string;
|
||||
@@ -170,7 +171,7 @@ async function submitDraftCreateRequest(input: {
|
||||
model: autoSubmitConfig?.model ?? (composerState.effectiveModelId || undefined),
|
||||
thinkingOptionId:
|
||||
autoSubmitConfig?.thinkingOptionId ?? (composerState.effectiveThinkingOptionId || undefined),
|
||||
featureValues: autoSubmitConfig?.featureValues ?? composerState.featureValues,
|
||||
providerOptions: autoSubmitConfig?.providerOptions ?? composerState.providerOptions,
|
||||
});
|
||||
|
||||
const attachmentsArray = Array.isArray(attachments) ? attachments : undefined;
|
||||
@@ -204,7 +205,7 @@ function buildDraftAgentSnapshot(input: {
|
||||
effectiveThinkingOptionId: string | null;
|
||||
effectiveModeId: string;
|
||||
selectedProvider: string | null;
|
||||
agentControls: { features?: Agent["features"] };
|
||||
agentControls: { optionControls?: ComposerOptionControls };
|
||||
};
|
||||
selectModelMessage: string;
|
||||
}): Agent {
|
||||
@@ -241,7 +242,8 @@ function buildDraftAgentSnapshot(input: {
|
||||
title: "Agent",
|
||||
cwd: workspaceDirectory,
|
||||
model,
|
||||
features: composerState.agentControls.features,
|
||||
options: composerState.agentControls.optionControls?.options,
|
||||
controls: composerState.agentControls.optionControls?.controls,
|
||||
thinkingOptionId,
|
||||
parentAgentId: null,
|
||||
labels: {},
|
||||
@@ -333,7 +335,7 @@ export function WorkspaceDraftAgentTab({
|
||||
composer: {
|
||||
initialServerId: serverId,
|
||||
initialValues: draftInitialValues,
|
||||
initialFeatureValues: draftSetup?.featureValues,
|
||||
initialProviderOptions: draftSetup?.providerOptions,
|
||||
isVisible: true,
|
||||
lockedWorkingDir: draftWorkingDirectory ?? undefined,
|
||||
},
|
||||
@@ -351,8 +353,7 @@ export function WorkspaceDraftAgentTab({
|
||||
const draftModeOptions = composerState.modeOptions;
|
||||
const draftSelectedMode = composerState.selectedMode;
|
||||
const draftSetMode = composerState.setModeFromUser;
|
||||
const draftFeatures = composerState.agentControls.features;
|
||||
const draftOnSetFeature = composerState.agentControls.onSetFeature;
|
||||
const draftOptionControls = composerState.agentControls.optionControls;
|
||||
|
||||
const clearDraftInput = draftInput.clear;
|
||||
const replaceDraftText = draftInput.replaceText;
|
||||
@@ -521,10 +522,7 @@ export function WorkspaceDraftAgentTab({
|
||||
selectedId: draftSelectedMode,
|
||||
select: draftSetMode,
|
||||
},
|
||||
features: {
|
||||
list: draftFeatures,
|
||||
set: draftOnSetFeature,
|
||||
},
|
||||
optionControls: draftOptionControls ?? null,
|
||||
},
|
||||
});
|
||||
const isReadyForPendingAutoSubmit = Boolean(
|
||||
|
||||
@@ -80,7 +80,7 @@ describe("create agent preferences", () => {
|
||||
modelId: "gpt-5.5",
|
||||
modeId: "full-access",
|
||||
thinkingOptionId: "high",
|
||||
featureValues: { fast_mode: true },
|
||||
options: { fast_mode: true },
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -95,7 +95,7 @@ describe("create agent preferences", () => {
|
||||
model: "gpt-5.5",
|
||||
mode: "full-access",
|
||||
thinkingByModel: { "gpt-5.5": "high" },
|
||||
featureValues: { fast_mode: true },
|
||||
options: { fast_mode: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -119,7 +119,7 @@ describe("create agent preferences", () => {
|
||||
model: "gpt-5.6",
|
||||
mode: undefined,
|
||||
thinkingByModel: undefined,
|
||||
featureValues: undefined,
|
||||
options: undefined,
|
||||
},
|
||||
}),
|
||||
).toEqual({
|
||||
@@ -167,13 +167,13 @@ describe("create agent preferences", () => {
|
||||
modelId: "one-minute-stream",
|
||||
modeId: "approval-test",
|
||||
thinkingOptionId: "",
|
||||
featureValues: {},
|
||||
options: {},
|
||||
}),
|
||||
).toEqual({
|
||||
provider: "mock",
|
||||
providerPreferences: {
|
||||
pi: { model: "anthropic/sonnet" },
|
||||
mock: { model: "one-minute-stream", mode: "approval-test", featureValues: {} },
|
||||
mock: { model: "one-minute-stream", mode: "approval-test", options: {} },
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -208,6 +208,29 @@ describe("create agent preferences", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("reads preferences saved as featureValues as options", () => {
|
||||
expect(
|
||||
parseFormPreferences({
|
||||
provider: "codex",
|
||||
providerPreferences: { codex: { featureValues: { service_tier: "priority" } } },
|
||||
}),
|
||||
).toEqual({
|
||||
provider: "codex",
|
||||
providerPreferences: { codex: { options: { service_tier: "priority" } } },
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps options that are not booleans or strings, such as a profile's sandbox settings", () => {
|
||||
const options = {
|
||||
sandbox_workspace_write: { network_access: true, writable_roots: ["/tmp"] },
|
||||
max_turns: 3,
|
||||
};
|
||||
|
||||
expect(
|
||||
parseFormPreferences({ provider: "codex", providerPreferences: { codex: { options } } }),
|
||||
).toEqual({ provider: "codex", providerPreferences: { codex: { options } } });
|
||||
});
|
||||
|
||||
it("rejects unknown persisted fields outside the explicit legacy shape", () => {
|
||||
expect(parseFormPreferences({ provider: "codex", surprise: true })).toEqual({});
|
||||
});
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import { z } from "zod";
|
||||
import type { AgentProvider } from "@getpaseo/protocol/agent-types";
|
||||
|
||||
const featureValuesSchema = z.record(z.string(), z.union([z.boolean(), z.string(), z.null()]));
|
||||
const optionsSchema = z.record(z.string(), z.json());
|
||||
|
||||
export interface ProviderPreferences {
|
||||
model?: string;
|
||||
mode?: string;
|
||||
thinkingByModel?: Record<string, string>;
|
||||
featureValues?: Record<string, unknown>;
|
||||
/** Last-used values of the provider's option controls, by option key. */
|
||||
options?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export type LaunchTarget = { kind: "chat" } | { kind: "terminal"; profileId: string };
|
||||
@@ -20,12 +21,23 @@ export interface FormPreferences {
|
||||
launchTarget?: LaunchTarget;
|
||||
}
|
||||
|
||||
const providerPreferencesSchema: z.ZodType<ProviderPreferences> = z.strictObject({
|
||||
model: z.string().optional(),
|
||||
mode: z.string().optional(),
|
||||
thinkingByModel: z.record(z.string(), z.string()).optional(),
|
||||
featureValues: featureValuesSchema.optional(),
|
||||
});
|
||||
// COMPAT(providerOptionControls): added in v0.15.0, remove after 2027-05-01. Preferences written
|
||||
// before the rename stored the same record as `featureValues`.
|
||||
function renameLegacyFeatureValues(value: unknown): unknown {
|
||||
if (typeof value !== "object" || value === null || !("featureValues" in value)) return value;
|
||||
const { featureValues, ...rest } = value as { featureValues: unknown } & Record<string, unknown>;
|
||||
return "options" in rest ? rest : { ...rest, options: featureValues };
|
||||
}
|
||||
|
||||
const providerPreferencesSchema: z.ZodType<ProviderPreferences> = z.preprocess(
|
||||
renameLegacyFeatureValues,
|
||||
z.strictObject({
|
||||
model: z.string().optional(),
|
||||
mode: z.string().optional(),
|
||||
thinkingByModel: z.record(z.string(), z.string()).optional(),
|
||||
options: optionsSchema.optional(),
|
||||
}),
|
||||
);
|
||||
|
||||
const launchTargetSchema: z.ZodType<LaunchTarget> = z.discriminatedUnion("kind", [
|
||||
z.strictObject({ kind: z.literal("chat") }),
|
||||
@@ -116,7 +128,7 @@ function applyProviderPreferenceUpdates(
|
||||
): ProviderPreferences {
|
||||
const next: ProviderPreferences = { ...existing };
|
||||
const nextThinkingByModel = mergeDefinedRecord(existing.thinkingByModel, updates.thinkingByModel);
|
||||
const nextFeatureValues = mergeDefinedRecord(existing.featureValues, updates.featureValues);
|
||||
const nextOptions = mergeDefinedRecord(existing.options, updates.options);
|
||||
|
||||
if (updates.model !== undefined) {
|
||||
next.model = updates.model;
|
||||
@@ -129,8 +141,8 @@ function applyProviderPreferenceUpdates(
|
||||
if (nextThinkingByModel !== undefined) {
|
||||
next.thinkingByModel = nextThinkingByModel;
|
||||
}
|
||||
if (nextFeatureValues !== undefined) {
|
||||
next.featureValues = nextFeatureValues;
|
||||
if (nextOptions !== undefined) {
|
||||
next.options = nextOptions;
|
||||
}
|
||||
|
||||
return next;
|
||||
@@ -161,7 +173,7 @@ export function mergeCreateAgentSelectionPreferences(args: {
|
||||
modelId?: string | null;
|
||||
modeId?: string | null;
|
||||
thinkingOptionId?: string | null;
|
||||
featureValues?: Record<string, unknown>;
|
||||
options?: Record<string, unknown>;
|
||||
}): FormPreferences {
|
||||
if (!args.provider) {
|
||||
return args.preferences;
|
||||
@@ -170,7 +182,7 @@ export function mergeCreateAgentSelectionPreferences(args: {
|
||||
const modelId = args.modelId?.trim() ?? "";
|
||||
const modeId = args.modeId?.trim() ?? "";
|
||||
const thinkingOptionId = args.thinkingOptionId?.trim() ?? "";
|
||||
const featureValues = featureValuesSchema.safeParse(args.featureValues);
|
||||
const options = optionsSchema.safeParse(args.options);
|
||||
|
||||
return mergeProviderPreferences({
|
||||
preferences: args.preferences,
|
||||
@@ -179,7 +191,7 @@ export function mergeCreateAgentSelectionPreferences(args: {
|
||||
model: modelId || undefined,
|
||||
mode: args.modeId === undefined ? undefined : modeId || null,
|
||||
...(modelId && thinkingOptionId ? { thinkingByModel: { [modelId]: thinkingOptionId } } : {}),
|
||||
...(featureValues.success ? { featureValues: featureValues.data } : {}),
|
||||
...(options.success ? { options: options.data } : {}),
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -192,7 +204,7 @@ export function applyAgentProfilePreferences(args: {
|
||||
modelId: string;
|
||||
modeId: string;
|
||||
thinkingOptionId: string;
|
||||
featureValues: Record<string, unknown>;
|
||||
options: Record<string, unknown>;
|
||||
}): FormPreferences {
|
||||
let next = args.preferences;
|
||||
if (args.previousProvider) {
|
||||
@@ -215,7 +227,7 @@ export function applyAgentProfilePreferences(args: {
|
||||
...(args.modelId && args.thinkingOptionId
|
||||
? { thinkingByModel: { [args.modelId]: args.thinkingOptionId } }
|
||||
: {}),
|
||||
featureValues: args.featureValues,
|
||||
options: args.options,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { resolveFeatureValues } from "./feature-preferences";
|
||||
|
||||
describe("feature-preferences", () => {
|
||||
const features = [
|
||||
{
|
||||
type: "toggle" as const,
|
||||
id: "fast_mode",
|
||||
label: "Fast",
|
||||
value: false,
|
||||
},
|
||||
{
|
||||
type: "toggle" as const,
|
||||
id: "plan_mode",
|
||||
label: "Plan",
|
||||
value: false,
|
||||
},
|
||||
];
|
||||
|
||||
it("restores persisted values for available features", () => {
|
||||
expect(
|
||||
resolveFeatureValues({
|
||||
features,
|
||||
persistedFeatureValues: {
|
||||
fast_mode: true,
|
||||
unknown_feature: true,
|
||||
},
|
||||
localFeatureValues: {},
|
||||
}),
|
||||
).toEqual({
|
||||
fast_mode: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("prefers local values over persisted values", () => {
|
||||
expect(
|
||||
resolveFeatureValues({
|
||||
features,
|
||||
persistedFeatureValues: {
|
||||
fast_mode: true,
|
||||
plan_mode: false,
|
||||
},
|
||||
localFeatureValues: {
|
||||
fast_mode: false,
|
||||
},
|
||||
}),
|
||||
).toEqual({
|
||||
fast_mode: false,
|
||||
plan_mode: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,60 +0,0 @@
|
||||
import type { AgentFeature } from "@getpaseo/protocol/agent-types";
|
||||
|
||||
export function pruneFeatureValues(
|
||||
featureValues: Record<string, unknown>,
|
||||
features: AgentFeature[],
|
||||
): Record<string, unknown> {
|
||||
const allowedFeatureIds = new Set(features.map((feature) => feature.id));
|
||||
let changed = false;
|
||||
const next: Record<string, unknown> = {};
|
||||
|
||||
for (const [featureId, value] of Object.entries(featureValues)) {
|
||||
if (!allowedFeatureIds.has(featureId)) {
|
||||
changed = true;
|
||||
continue;
|
||||
}
|
||||
next[featureId] = value;
|
||||
}
|
||||
|
||||
return changed ? next : featureValues;
|
||||
}
|
||||
|
||||
export function applyFeatureValues(
|
||||
features: AgentFeature[],
|
||||
featureValues: Record<string, unknown>,
|
||||
): AgentFeature[] {
|
||||
if (Object.keys(featureValues).length === 0) {
|
||||
return features;
|
||||
}
|
||||
|
||||
return features.map((feature) => {
|
||||
if (!Object.prototype.hasOwnProperty.call(featureValues, feature.id)) {
|
||||
return feature;
|
||||
}
|
||||
|
||||
return {
|
||||
...feature,
|
||||
value: featureValues[feature.id],
|
||||
} as AgentFeature;
|
||||
});
|
||||
}
|
||||
|
||||
export function resolveFeatureValues(args: {
|
||||
features: AgentFeature[];
|
||||
persistedFeatureValues: Record<string, unknown>;
|
||||
localFeatureValues: Record<string, unknown>;
|
||||
}): Record<string, unknown> {
|
||||
const next: Record<string, unknown> = {};
|
||||
|
||||
for (const feature of args.features) {
|
||||
if (Object.prototype.hasOwnProperty.call(args.localFeatureValues, feature.id)) {
|
||||
next[feature.id] = args.localFeatureValues[feature.id];
|
||||
continue;
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(args.persistedFeatureValues, feature.id)) {
|
||||
next[feature.id] = args.persistedFeatureValues[feature.id];
|
||||
}
|
||||
}
|
||||
|
||||
return next;
|
||||
}
|
||||
@@ -128,14 +128,14 @@ function resolveDraftQueryConfig(draft?: DraftCommandTarget): DraftCommandConfig
|
||||
const modeId = draftConfig.modeId?.trim() ?? "";
|
||||
const model = draftConfig.model?.trim() ?? "";
|
||||
const thinkingOptionId = draftConfig.thinkingOptionId?.trim() ?? "";
|
||||
const featureValues = draftConfig.featureValues;
|
||||
const providerOptions = draftConfig.providerOptions;
|
||||
return {
|
||||
provider: draftConfig.provider,
|
||||
cwd,
|
||||
...(modeId ? { modeId } : {}),
|
||||
...(model ? { model } : {}),
|
||||
...(thinkingOptionId ? { thinkingOptionId } : {}),
|
||||
...(featureValues && Object.keys(featureValues).length > 0 ? { featureValues } : {}),
|
||||
...(providerOptions && Object.keys(providerOptions).length > 0 ? { providerOptions } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -352,7 +352,7 @@ export function useAgentFormState(options: UseAgentFormStateOptions): UseAgentFo
|
||||
modelId: model,
|
||||
modeId,
|
||||
thinkingOptionId,
|
||||
featureValues: profile.featureValues,
|
||||
options: profile.options,
|
||||
});
|
||||
}).catch((error) => {
|
||||
console.warn("[useAgentFormState] persist profile preference failed", error);
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import { useRef } from "react";
|
||||
import type {
|
||||
AgentCapabilityFlags,
|
||||
AgentFeature,
|
||||
AgentProvider,
|
||||
} from "@getpaseo/protocol/agent-types";
|
||||
import type { AgentCapabilityFlags, AgentProvider } from "@getpaseo/protocol/agent-types";
|
||||
import type { Agent } from "@/stores/session-store";
|
||||
import type { ViewedTimelineStatus } from "@/timeline/viewed-timeline-sync";
|
||||
|
||||
export interface AgentScreenAgent {
|
||||
@@ -22,7 +19,8 @@ export interface AgentScreenAgent {
|
||||
modeId?: string | null;
|
||||
thinkingOptionId?: string | null;
|
||||
} | null;
|
||||
features?: readonly AgentFeature[];
|
||||
options?: Agent["options"];
|
||||
controls?: Agent["controls"];
|
||||
lastError?: string | null;
|
||||
projectPlacement?: {
|
||||
projectKey?: string;
|
||||
|
||||
@@ -1,159 +0,0 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { AgentProvider, AgentSessionConfig } from "@getpaseo/protocol/agent-types";
|
||||
import { useHostRuntimeClient, useHostRuntimeIsConnected } from "@/runtime/host-runtime";
|
||||
import { mergeProviderPreferences, useFormPreferences } from "./use-form-preferences";
|
||||
import {
|
||||
applyFeatureValues,
|
||||
pruneFeatureValues,
|
||||
resolveFeatureValues,
|
||||
} from "./feature-preferences";
|
||||
|
||||
type DraftFeatureConfig = Pick<
|
||||
AgentSessionConfig,
|
||||
"provider" | "cwd" | "modeId" | "model" | "thinkingOptionId"
|
||||
>;
|
||||
|
||||
export function useDraftAgentFeatures(input: {
|
||||
serverId: string | null | undefined;
|
||||
provider: AgentProvider | null;
|
||||
cwd: string | null | undefined;
|
||||
modeId: string | null | undefined;
|
||||
modelId: string | null | undefined;
|
||||
thinkingOptionId: string | null | undefined;
|
||||
initialFeatureValues?: Record<string, unknown>;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const { serverId, provider, cwd, modeId, modelId, thinkingOptionId, initialFeatureValues } =
|
||||
input;
|
||||
const [localFeatureValues, setLocalFeatureValues] = useState<Record<string, unknown>>(
|
||||
() => initialFeatureValues ?? {},
|
||||
);
|
||||
const client = useHostRuntimeClient(serverId ?? "");
|
||||
const isConnected = useHostRuntimeIsConnected(serverId ?? "");
|
||||
const { preferences, updatePreferences } = useFormPreferences();
|
||||
const normalizedCwd = cwd?.trim() || "";
|
||||
const normalizedProvider = provider ?? null;
|
||||
const previousProviderRef = useRef<AgentProvider | null>(normalizedProvider);
|
||||
const persistedFeatureValues = useMemo(
|
||||
() => (provider ? (preferences.providerPreferences?.[provider]?.featureValues ?? {}) : {}),
|
||||
[preferences.providerPreferences, provider],
|
||||
);
|
||||
|
||||
const draftConfig = useMemo<DraftFeatureConfig | null>(() => {
|
||||
if (!normalizedProvider || !normalizedCwd) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
provider: normalizedProvider,
|
||||
cwd: normalizedCwd,
|
||||
...(modeId ? { modeId } : {}),
|
||||
...(modelId ? { model: modelId } : {}),
|
||||
...(thinkingOptionId ? { thinkingOptionId } : {}),
|
||||
};
|
||||
}, [modeId, modelId, normalizedCwd, normalizedProvider, thinkingOptionId]);
|
||||
|
||||
const featuresQuery = useQuery({
|
||||
queryKey: [
|
||||
"providerFeatures",
|
||||
serverId ?? null,
|
||||
normalizedProvider,
|
||||
normalizedCwd || null,
|
||||
modeId ?? null,
|
||||
modelId ?? null,
|
||||
thinkingOptionId ?? null,
|
||||
],
|
||||
enabled: Boolean(serverId && client && isConnected && draftConfig),
|
||||
staleTime: 5 * 60 * 1000,
|
||||
queryFn: async () => {
|
||||
if (!client || !draftConfig) {
|
||||
throw new Error(t("workspace.terminal.hostDisconnected"));
|
||||
}
|
||||
const payload = await client.listProviderFeatures(draftConfig);
|
||||
if (payload.error) {
|
||||
throw new Error(payload.error);
|
||||
}
|
||||
return payload.features ?? [];
|
||||
},
|
||||
});
|
||||
const availableFeaturesRaw = featuresQuery.data;
|
||||
const availableFeatures = useMemo(() => availableFeaturesRaw ?? [], [availableFeaturesRaw]);
|
||||
const featureValues = useMemo(
|
||||
() =>
|
||||
resolveFeatureValues({
|
||||
features: availableFeatures,
|
||||
persistedFeatureValues,
|
||||
localFeatureValues,
|
||||
}),
|
||||
[availableFeatures, localFeatureValues, persistedFeatureValues],
|
||||
);
|
||||
|
||||
const features = useMemo(() => {
|
||||
return applyFeatureValues(availableFeatures, featureValues);
|
||||
}, [availableFeatures, featureValues]);
|
||||
|
||||
useEffect(() => {
|
||||
const previousProvider = previousProviderRef.current;
|
||||
previousProviderRef.current = normalizedProvider;
|
||||
if (previousProvider === null) {
|
||||
return;
|
||||
}
|
||||
if (previousProvider !== normalizedProvider) {
|
||||
setLocalFeatureValues({});
|
||||
}
|
||||
}, [normalizedProvider]);
|
||||
|
||||
useEffect(() => {
|
||||
if (availableFeaturesRaw === undefined) {
|
||||
return;
|
||||
}
|
||||
const next = pruneFeatureValues(localFeatureValues, availableFeatures);
|
||||
if (next !== localFeatureValues) {
|
||||
setLocalFeatureValues(next);
|
||||
}
|
||||
}, [availableFeatures, availableFeaturesRaw, localFeatureValues]);
|
||||
|
||||
const effectiveFeatureValues = Object.keys(featureValues).length > 0 ? featureValues : undefined;
|
||||
const setFeatureValue = useCallback(
|
||||
(featureId: string, value: unknown) => {
|
||||
setLocalFeatureValues((current) => {
|
||||
if (Object.is(current[featureId], value)) {
|
||||
return current;
|
||||
}
|
||||
|
||||
return { ...current, [featureId]: value };
|
||||
});
|
||||
if (!provider) {
|
||||
return;
|
||||
}
|
||||
void updatePreferences((current) =>
|
||||
mergeProviderPreferences({
|
||||
preferences: current,
|
||||
provider,
|
||||
updates: {
|
||||
featureValues: {
|
||||
[featureId]: value,
|
||||
},
|
||||
},
|
||||
}),
|
||||
).catch((error) => {
|
||||
console.warn("[useDraftAgentFeatures] persist feature preference failed", error);
|
||||
});
|
||||
},
|
||||
[provider, updatePreferences],
|
||||
);
|
||||
|
||||
const applyProfileFeatureValues = useCallback((values: Record<string, unknown>) => {
|
||||
setLocalFeatureValues(values);
|
||||
}, []);
|
||||
|
||||
return {
|
||||
features,
|
||||
featureValues: effectiveFeatureValues,
|
||||
isLoading: featuresQuery.isLoading,
|
||||
setFeatureValue,
|
||||
applyProfileFeatureValues,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
import { useCallback, useEffect, useMemo, useState, useSyncExternalStore } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { AgentProvider, ProviderOptions } from "@getpaseo/protocol/agent-types";
|
||||
import {
|
||||
draftControlsRequest,
|
||||
openDraftOptions,
|
||||
ownDraftOptions,
|
||||
viewDraftOptions,
|
||||
} from "@/agent-controls/draft-options-model";
|
||||
import type { ComposerOptionControls } from "@/agent-controls/option-controls";
|
||||
import { useFetchQuery } from "@/data/query";
|
||||
import { useHostRuntimeClient, useHostRuntimeIsConnected } from "@/runtime/host-runtime";
|
||||
import { mergeProviderPreferences, useFormPreferences } from "./use-form-preferences";
|
||||
|
||||
/**
|
||||
* Adapter between a draft's options model and the screen: it sends the model's complete options
|
||||
* to the daemon, hands the answer back, and persists the user's toggles as last-used values.
|
||||
*/
|
||||
export function useDraftProviderOptions(input: {
|
||||
serverId: string | null | undefined;
|
||||
provider: AgentProvider | null;
|
||||
cwd: string | null | undefined;
|
||||
modeId: string | null | undefined;
|
||||
modelId: string | null | undefined;
|
||||
thinkingOptionId: string | null | undefined;
|
||||
initialOptions?: ProviderOptions;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const { serverId, provider, cwd, modeId, modelId, thinkingOptionId, initialOptions } = input;
|
||||
const [model] = useState(() => openDraftOptions({ provider, seed: initialOptions }));
|
||||
const state = useSyncExternalStore(model.subscribe, model.getState, model.getState);
|
||||
const client = useHostRuntimeClient(serverId ?? "");
|
||||
const isConnected = useHostRuntimeIsConnected(serverId ?? "");
|
||||
const { preferences, updatePreferences } = useFormPreferences();
|
||||
const normalizedCwd = cwd?.trim() || "";
|
||||
const persisted = preferences.providerPreferences?.[provider ?? ""]?.options;
|
||||
|
||||
useEffect(() => model.observeProvider(provider), [model, provider]);
|
||||
useEffect(() => model.setRemembered(persisted ?? {}), [model, persisted]);
|
||||
|
||||
const ownOptions = ownDraftOptions(state);
|
||||
const draftConfig = useMemo(
|
||||
() =>
|
||||
draftControlsRequest(state, {
|
||||
provider,
|
||||
cwd: normalizedCwd,
|
||||
modeId,
|
||||
modelId,
|
||||
thinkingOptionId,
|
||||
}),
|
||||
[modeId, modelId, normalizedCwd, provider, state, thinkingOptionId],
|
||||
);
|
||||
const queryKey = useMemo(
|
||||
() => ["providerControls", serverId ?? null, draftConfig],
|
||||
[draftConfig, serverId],
|
||||
);
|
||||
const requestKey = JSON.stringify(queryKey);
|
||||
|
||||
const { data } = useFetchQuery({
|
||||
queryKey,
|
||||
dataShape: "value",
|
||||
staleTimeMs: 5 * 60 * 1000,
|
||||
enabled: Boolean(serverId && client && isConnected && draftConfig),
|
||||
queryFn: async () => {
|
||||
if (!client || !draftConfig) {
|
||||
throw new Error(t("workspace.terminal.hostDisconnected"));
|
||||
}
|
||||
const payload = await client.listProviderControls(draftConfig);
|
||||
if (payload.error) {
|
||||
throw new Error(payload.error);
|
||||
}
|
||||
return { controls: payload.controls ?? [], options: payload.options ?? {} };
|
||||
},
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (provider && data) model.applyResolved({ provider, requestKey, ...data });
|
||||
}, [data, model, provider, requestKey]);
|
||||
|
||||
const setOption = useCallback(
|
||||
(key: string, value: unknown) => {
|
||||
model.setOption(key, value);
|
||||
if (!provider) return;
|
||||
void updatePreferences((current) =>
|
||||
mergeProviderPreferences({
|
||||
preferences: current,
|
||||
provider,
|
||||
updates: { options: { [key]: value } },
|
||||
}),
|
||||
).catch((error) => {
|
||||
console.warn("[useDraftProviderOptions] persist option preference failed", error);
|
||||
});
|
||||
},
|
||||
[model, provider, updatePreferences],
|
||||
);
|
||||
|
||||
const view = viewDraftOptions(state, { provider, requestKey });
|
||||
const viewControls = view?.controls;
|
||||
const viewOptions = view?.options;
|
||||
const optionControls = useMemo<ComposerOptionControls | undefined>(
|
||||
() =>
|
||||
viewControls && viewOptions
|
||||
? { controls: viewControls, options: viewOptions, onSetOption: setOption }
|
||||
: undefined,
|
||||
[setOption, viewControls, viewOptions],
|
||||
);
|
||||
|
||||
return { optionControls, options: ownOptions, applyProfile: model.applyProfile };
|
||||
}
|
||||
@@ -36,7 +36,7 @@ export type ForkAgentSource = Pick<
|
||||
| "model"
|
||||
| "thinkingOptionId"
|
||||
| "runtimeInfo"
|
||||
| "features"
|
||||
| "options"
|
||||
| "projectPlacement"
|
||||
>;
|
||||
|
||||
@@ -95,18 +95,13 @@ function buildForkDraftSetup(agent: ForkAgentSource): WorkspaceDraftTabSetup | u
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const featureValues: Record<string, unknown> = {};
|
||||
for (const feature of agent.features ?? []) {
|
||||
featureValues[feature.id] = feature.value;
|
||||
}
|
||||
|
||||
return {
|
||||
provider: agent.provider,
|
||||
cwd: agent.cwd,
|
||||
modeId: agent.currentModeId ?? agent.runtimeInfo?.modeId ?? null,
|
||||
model: agent.model ?? agent.runtimeInfo?.model ?? null,
|
||||
thinkingOptionId: agent.thinkingOptionId ?? agent.runtimeInfo?.thinkingOptionId ?? null,
|
||||
featureValues,
|
||||
providerOptions: { ...agent.options },
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ describe("mergeProviderPreferences", () => {
|
||||
providerPreferences: {
|
||||
codex: {
|
||||
model: "gpt-5.4",
|
||||
featureValues: {
|
||||
options: {
|
||||
fast_mode: true,
|
||||
},
|
||||
},
|
||||
@@ -71,7 +71,7 @@ describe("mergeProviderPreferences", () => {
|
||||
},
|
||||
provider: "codex",
|
||||
updates: {
|
||||
featureValues: {
|
||||
options: {
|
||||
plan_mode: true,
|
||||
},
|
||||
},
|
||||
@@ -81,7 +81,7 @@ describe("mergeProviderPreferences", () => {
|
||||
providerPreferences: {
|
||||
codex: {
|
||||
model: "gpt-5.4",
|
||||
featureValues: {
|
||||
options: {
|
||||
fast_mode: true,
|
||||
plan_mode: true,
|
||||
},
|
||||
|
||||
@@ -116,7 +116,8 @@ interface ChatAgentStateShape {
|
||||
model?: Agent["model"];
|
||||
thinkingOptionId?: Agent["thinkingOptionId"];
|
||||
runtimeInfo?: Agent["runtimeInfo"];
|
||||
features?: Agent["features"];
|
||||
options?: Agent["options"];
|
||||
controls?: Agent["controls"];
|
||||
lastError?: Agent["lastError"] | null;
|
||||
}
|
||||
|
||||
@@ -175,7 +176,8 @@ function selectChatAgentState(
|
||||
model: agent.model,
|
||||
thinkingOptionId: agent.thinkingOptionId,
|
||||
runtimeInfo: agent.runtimeInfo,
|
||||
features: agent.features,
|
||||
options: agent.options,
|
||||
controls: agent.controls,
|
||||
lastError: agent.lastError ?? null,
|
||||
archivedAt: agent.archivedAt ?? null,
|
||||
requiresAttention: agent.requiresAttention ?? false,
|
||||
@@ -202,7 +204,8 @@ function buildChatAgentFromState(
|
||||
model: state.model,
|
||||
thinkingOptionId: state.thinkingOptionId,
|
||||
runtimeInfo: state.runtimeInfo,
|
||||
features: state.features,
|
||||
options: state.options,
|
||||
controls: state.controls,
|
||||
lastError: state.lastError ?? null,
|
||||
projectPlacement,
|
||||
};
|
||||
@@ -635,7 +638,8 @@ function AgentPanelBody({
|
||||
model: agentState.model,
|
||||
thinkingOptionId: agentState.thinkingOptionId,
|
||||
runtimeInfo: agentState.runtimeInfo,
|
||||
features: agentState.features,
|
||||
options: agentState.options,
|
||||
controls: agentState.controls,
|
||||
lastError: agentState.lastError ?? null,
|
||||
projectPlacement,
|
||||
}
|
||||
|
||||
@@ -312,7 +312,7 @@ export function buildDraftCommandTarget(input: {
|
||||
cwd: string;
|
||||
effectiveModelId: string;
|
||||
effectiveThinkingOptionId: string;
|
||||
featureValues?: Record<string, unknown>;
|
||||
providerOptions?: Record<string, unknown>;
|
||||
}): DraftCommandTarget {
|
||||
const cwd = input.cwd.trim();
|
||||
if (!cwd) {
|
||||
@@ -332,7 +332,7 @@ export function buildDraftCommandTarget(input: {
|
||||
...(input.effectiveThinkingOptionId
|
||||
? { thinkingOptionId: input.effectiveThinkingOptionId }
|
||||
: {}),
|
||||
...(input.featureValues ? { featureValues: input.featureValues } : {}),
|
||||
...(input.providerOptions ? { providerOptions: input.providerOptions } : {}),
|
||||
};
|
||||
return { status: "ready", config };
|
||||
}
|
||||
|
||||
@@ -284,7 +284,7 @@ describe("mergeSelectedComposerPreferences", () => {
|
||||
codex: {
|
||||
mode: "full-access",
|
||||
thinkingByModel: { "gpt-5.4-mini": "medium" },
|
||||
featureValues: { fast_mode: true },
|
||||
options: { fast_mode: true },
|
||||
},
|
||||
claude: { model: "claude-sonnet-4-6" },
|
||||
},
|
||||
@@ -299,7 +299,7 @@ describe("mergeSelectedComposerPreferences", () => {
|
||||
model: "gpt-5.4",
|
||||
mode: "full-access",
|
||||
thinkingByModel: { "gpt-5.4-mini": "medium" },
|
||||
featureValues: { fast_mode: true },
|
||||
options: { fast_mode: true },
|
||||
},
|
||||
claude: { model: "claude-sonnet-4-6" },
|
||||
},
|
||||
|
||||
@@ -270,7 +270,7 @@ interface WorkspaceDraftSubmissionConfig {
|
||||
modeId: string | null;
|
||||
model: string | null;
|
||||
thinkingOptionId: string | null;
|
||||
featureValues: Record<string, unknown> | undefined;
|
||||
providerOptions: Record<string, unknown> | undefined;
|
||||
target: WorkspaceTabTarget;
|
||||
}
|
||||
|
||||
@@ -373,7 +373,7 @@ function buildWorkspaceDraftSetupFromComposer(input: {
|
||||
modeId: input.composerState.effectiveModeId || null,
|
||||
model: input.composerState.effectiveModelId || null,
|
||||
thinkingOptionId: input.composerState.effectiveThinkingOptionId || null,
|
||||
featureValues: input.composerState.featureValues ?? {},
|
||||
providerOptions: input.composerState.providerOptions ?? {},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -453,7 +453,7 @@ async function createWorkspaceChatAgent(input: CreateChatAgentInput): Promise<Su
|
||||
modeId: composerState.effectiveModeId || undefined,
|
||||
model: composerState.effectiveModelId || undefined,
|
||||
thinkingOptionId: composerState.effectiveThinkingOptionId || undefined,
|
||||
featureValues: composerState.featureValues,
|
||||
providerOptions: composerState.providerOptions,
|
||||
},
|
||||
initialPrompt: text,
|
||||
clientMessageId: `${input.draftId}:initial-message`,
|
||||
@@ -533,7 +533,7 @@ function buildComposerConfig(input: {
|
||||
return {
|
||||
initialServerId: serverId || null,
|
||||
initialValues: buildComposerInitialValues({ initialSetup }),
|
||||
initialFeatureValues: initialSetup?.featureValues,
|
||||
initialProviderOptions: initialSetup?.providerOptions,
|
||||
isVisible: true,
|
||||
lockedWorkingDir: workingDir,
|
||||
};
|
||||
@@ -566,7 +566,7 @@ function resolveWorkspaceDraftSubmissionConfig(input: {
|
||||
modeId: initialSetup.modeId,
|
||||
model: initialSetup.model,
|
||||
thinkingOptionId: initialSetup.thinkingOptionId,
|
||||
featureValues: initialSetup.featureValues,
|
||||
providerOptions: initialSetup.providerOptions,
|
||||
target: { kind: "draft", draftId, setup: initialSetup },
|
||||
};
|
||||
}
|
||||
@@ -576,7 +576,7 @@ function resolveWorkspaceDraftSubmissionConfig(input: {
|
||||
modeId: composerState.effectiveModeId || null,
|
||||
model: composerState.effectiveModelId || null,
|
||||
thinkingOptionId: composerState.effectiveThinkingOptionId || null,
|
||||
featureValues: composerState.featureValues,
|
||||
providerOptions: composerState.providerOptions,
|
||||
target: { kind: "draft", draftId },
|
||||
};
|
||||
}
|
||||
@@ -634,7 +634,7 @@ function submitWorkspaceDraft(input: SubmitDraftInput): SubmitOutcome {
|
||||
...(submission.modeId ? { modeId: submission.modeId } : {}),
|
||||
...(submission.model ? { model: submission.model } : {}),
|
||||
...(submission.thinkingOptionId ? { thinkingOptionId: submission.thinkingOptionId } : {}),
|
||||
...(submission.featureValues ? { featureValues: submission.featureValues } : {}),
|
||||
...(submission.providerOptions ? { providerOptions: submission.providerOptions } : {}),
|
||||
allowEmptyText: true,
|
||||
agentCreation: input.agentCreation,
|
||||
});
|
||||
|
||||
@@ -69,7 +69,7 @@ describe("createWorkspaceAgentInBackground", () => {
|
||||
modeId: null,
|
||||
model: null,
|
||||
thinkingOptionId: null,
|
||||
featureValues: {},
|
||||
providerOptions: {},
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -89,7 +89,7 @@ describe("createWorkspaceAgentInBackground", () => {
|
||||
modeId: null,
|
||||
model: null,
|
||||
thinkingOptionId: null,
|
||||
featureValues: {},
|
||||
providerOptions: {},
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ export function buildWorkspaceDraftAgentConfig(input: {
|
||||
modeId?: string;
|
||||
model?: string;
|
||||
thinkingOptionId?: string;
|
||||
featureValues?: Record<string, unknown>;
|
||||
providerOptions?: Record<string, unknown>;
|
||||
}): AgentSessionConfig {
|
||||
return {
|
||||
provider: input.provider,
|
||||
@@ -14,6 +14,6 @@ export function buildWorkspaceDraftAgentConfig(input: {
|
||||
...(input.modeId ? { modeId: input.modeId } : {}),
|
||||
...(input.model ? { model: input.model } : {}),
|
||||
...(input.thinkingOptionId ? { thinkingOptionId: input.thinkingOptionId } : {}),
|
||||
...(input.featureValues ? { featureValues: input.featureValues } : {}),
|
||||
...(input.providerOptions ? { providerOptions: input.providerOptions } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -26,7 +26,8 @@ import type { ComposerAttachment } from "@/attachments/types";
|
||||
import type { AgentLifecycleStatus } from "@getpaseo/protocol/agent-lifecycle";
|
||||
import type {
|
||||
AgentPermissionRequest,
|
||||
AgentFeature,
|
||||
AgentOptionControl,
|
||||
ProviderOptions,
|
||||
AgentProvider,
|
||||
AgentMode,
|
||||
AgentCapabilityFlags,
|
||||
@@ -91,7 +92,8 @@ export interface Agent {
|
||||
cwd: string;
|
||||
workspaceId?: string;
|
||||
model: string | null;
|
||||
features?: AgentFeature[];
|
||||
options?: ProviderOptions;
|
||||
controls?: AgentOptionControl[];
|
||||
thinkingOptionId?: string | null;
|
||||
requiresAttention?: boolean;
|
||||
attentionReason?: "finished" | "error" | "permission" | null;
|
||||
|
||||
@@ -23,7 +23,7 @@ export interface PendingWorkspaceDraftSubmission {
|
||||
modeId?: string;
|
||||
model?: string;
|
||||
thinkingOptionId?: string;
|
||||
featureValues?: Record<string, unknown>;
|
||||
providerOptions?: Record<string, unknown>;
|
||||
allowEmptyText?: boolean;
|
||||
}
|
||||
|
||||
|
||||
@@ -95,6 +95,53 @@ it("keeps the saved layout when the shell publishes its layout mode before hydra
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps every saved layout when a draft tab's setup carries a nested provider option", async () => {
|
||||
const values = new Map<string, string>();
|
||||
const storage: StateStorage = {
|
||||
getItem: (name) => values.get(name) ?? null,
|
||||
setItem: (name, value) => {
|
||||
values.set(name, value);
|
||||
},
|
||||
removeItem: (name) => {
|
||||
values.delete(name);
|
||||
},
|
||||
};
|
||||
const store = createWorkspaceLayoutStore(undefined, storage);
|
||||
await store.persist.rehydrate();
|
||||
store.getState().openTab({
|
||||
workspaceKey: "server:kept",
|
||||
target: { kind: "agent", agentId: "agent-1" },
|
||||
intent: "reveal",
|
||||
});
|
||||
store.getState().openTab({
|
||||
workspaceKey: "server:forked",
|
||||
target: {
|
||||
kind: "draft",
|
||||
draftId: "draft-1",
|
||||
setup: {
|
||||
provider: "codex",
|
||||
cwd: "/repo",
|
||||
modeId: null,
|
||||
model: null,
|
||||
thinkingOptionId: null,
|
||||
providerOptions: { sandbox_workspace_write: { network_access: true }, max_turns: 3 },
|
||||
},
|
||||
},
|
||||
intent: "reveal",
|
||||
});
|
||||
|
||||
const restored = createWorkspaceLayoutStore(undefined, storage);
|
||||
await restored.persist.rehydrate();
|
||||
|
||||
expect(Object.keys(restored.getState().layoutByWorkspace).sort()).toEqual([
|
||||
"server:forked",
|
||||
"server:kept",
|
||||
]);
|
||||
expect(JSON.stringify(restored.getState().layoutByWorkspace["server:forked"])).toContain(
|
||||
"network_access",
|
||||
);
|
||||
});
|
||||
|
||||
it.each([1, 2])(
|
||||
"restores the agent pane after parked focus in storage version %i",
|
||||
async (version) => {
|
||||
|
||||
@@ -1,14 +1,25 @@
|
||||
import { z } from "zod";
|
||||
import type { SplitNode, WorkspaceLayout } from "./workspace-layout-actions";
|
||||
|
||||
const WorkspaceDraftTabSetupStorageSchema = z.strictObject({
|
||||
provider: z.string(),
|
||||
cwd: z.string(),
|
||||
modeId: z.string().nullable(),
|
||||
model: z.string().nullable(),
|
||||
thinkingOptionId: z.string().nullable(),
|
||||
featureValues: z.record(z.string(), z.union([z.boolean(), z.string(), z.null()])),
|
||||
});
|
||||
// COMPAT(providerOptionControls): added in v0.15.0, remove after 2027-05-01. Layouts saved before
|
||||
// the rename stored the same record as `featureValues`.
|
||||
function renameLegacyFeatureValues(value: unknown): unknown {
|
||||
if (typeof value !== "object" || value === null || !("featureValues" in value)) return value;
|
||||
const { featureValues, ...rest } = value as { featureValues: unknown } & Record<string, unknown>;
|
||||
return "providerOptions" in rest ? rest : { ...rest, providerOptions: featureValues };
|
||||
}
|
||||
|
||||
const WorkspaceDraftTabSetupStorageSchema = z.preprocess(
|
||||
renameLegacyFeatureValues,
|
||||
z.strictObject({
|
||||
provider: z.string(),
|
||||
cwd: z.string(),
|
||||
modeId: z.string().nullable(),
|
||||
model: z.string().nullable(),
|
||||
thinkingOptionId: z.string().nullable(),
|
||||
providerOptions: z.record(z.string(), z.json()),
|
||||
}),
|
||||
);
|
||||
const WorkspaceTabTargetStorageSchema = z.discriminatedUnion("kind", [
|
||||
z.strictObject({ kind: z.literal("new_tab") }),
|
||||
z.strictObject({
|
||||
|
||||
@@ -4551,7 +4551,6 @@ describe("compact workspace sheet", () => {
|
||||
title: agent.id,
|
||||
cwd: "/repo",
|
||||
model: null,
|
||||
features: undefined,
|
||||
thinkingOptionId: undefined,
|
||||
requiresAttention: false,
|
||||
attentionReason: null,
|
||||
|
||||
@@ -63,7 +63,6 @@ const AGENT_DEFAULTS: Agent = {
|
||||
cwd: WORKSPACE_DIRECTORY,
|
||||
workspaceId: WORKSPACE_ID,
|
||||
model: null,
|
||||
features: undefined,
|
||||
thinkingOptionId: undefined,
|
||||
requiresAttention: false,
|
||||
attentionReason: null,
|
||||
|
||||
@@ -41,7 +41,6 @@ const AGENT_DEFAULTS: Agent = {
|
||||
title: "Agent",
|
||||
cwd: "/tmp/project",
|
||||
model: null,
|
||||
features: undefined,
|
||||
thinkingOptionId: undefined,
|
||||
requiresAttention: false,
|
||||
attentionReason: null,
|
||||
|
||||
@@ -60,7 +60,6 @@ const AGENT_DEFAULTS: Agent = {
|
||||
cwd: "/repo/worktree",
|
||||
workspaceId: WORKSPACE_ID,
|
||||
model: null,
|
||||
features: undefined,
|
||||
thinkingOptionId: undefined,
|
||||
requiresAttention: false,
|
||||
attentionReason: null,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { AgentSnapshotPayload } from "@getpaseo/protocol/messages";
|
||||
import { PARENT_AGENT_ID_LABEL } from "@getpaseo/protocol/agent-labels";
|
||||
import { isControlActive, readSelectOption } from "@/agent-controls/option-controls";
|
||||
import { normalizeAgentSnapshot, projectAgentSnapshot } from "./agent-snapshots";
|
||||
|
||||
function createSnapshot(
|
||||
@@ -32,10 +33,39 @@ function createSnapshot(
|
||||
persistence: input.persistence ?? null,
|
||||
title: input.title ?? null,
|
||||
labels: (input.labels ?? {}) as AgentSnapshotPayload["labels"],
|
||||
...(input.controls ? { controls: input.controls } : {}),
|
||||
...(input.options ? { options: input.options } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
describe("normalizeAgentSnapshot", () => {
|
||||
it("keeps a closed agent's stored options and controls, so its Fast control draws", () => {
|
||||
const speed = {
|
||||
type: "select" as const,
|
||||
key: "service_tier",
|
||||
label: "Speed",
|
||||
defaultValue: "default",
|
||||
choices: [
|
||||
{ value: "default", label: "Normal" },
|
||||
{ value: "priority", label: "Fast" },
|
||||
],
|
||||
};
|
||||
const agent = normalizeAgentSnapshot(
|
||||
createSnapshot({
|
||||
status: "closed",
|
||||
controls: [speed],
|
||||
options: { service_tier: "priority", sandbox_mode: "read-only" },
|
||||
}),
|
||||
"server-1",
|
||||
);
|
||||
|
||||
expect(agent.status).toBe("closed");
|
||||
expect(agent.controls).toEqual([speed]);
|
||||
expect(agent.options).toEqual({ service_tier: "priority", sandbox_mode: "read-only" });
|
||||
expect(readSelectOption(speed, agent.options ?? {})).toBe("priority");
|
||||
expect(isControlActive(speed, agent.options ?? {})).toBe(true);
|
||||
});
|
||||
|
||||
it("round-trips identified active turns through the canonical snapshot boundary", () => {
|
||||
const snapshot = createSnapshot({
|
||||
status: "running",
|
||||
|
||||
@@ -64,7 +64,8 @@ export function projectAgentSnapshot(agent: Agent): AgentSnapshotPayload {
|
||||
cwd: agent.cwd,
|
||||
...(agent.workspaceId ? { workspaceId: agent.workspaceId } : {}),
|
||||
model: agent.model,
|
||||
...(agent.features ? { features: agent.features } : {}),
|
||||
...(agent.options ? { options: agent.options } : {}),
|
||||
...(agent.controls ? { controls: agent.controls } : {}),
|
||||
thinkingOptionId: agent.thinkingOptionId ?? null,
|
||||
createdAt: agent.createdAt.toISOString(),
|
||||
updatedAt: agent.updatedAt.toISOString(),
|
||||
@@ -128,7 +129,8 @@ export function normalizeAgentSnapshot(snapshot: AgentSnapshotPayload, serverId:
|
||||
cwd: snapshot.cwd,
|
||||
workspaceId: snapshot.workspaceId,
|
||||
model: snapshot.model ?? null,
|
||||
features: snapshot.features,
|
||||
options: snapshot.options,
|
||||
controls: snapshot.controls,
|
||||
thinkingOptionId: snapshot.thinkingOptionId ?? null,
|
||||
requiresAttention: snapshot.requiresAttention ?? false,
|
||||
attentionReason: snapshot.attentionReason ?? null,
|
||||
|
||||
@@ -92,7 +92,7 @@ export function normalizeWorkspaceDraftTabSetup(
|
||||
thinkingOptionId: trimOptionalString(
|
||||
typeof record.thinkingOptionId === "string" ? record.thinkingOptionId : null,
|
||||
),
|
||||
featureValues: isPlainRecord(record.featureValues) ? { ...record.featureValues } : {},
|
||||
providerOptions: isPlainRecord(record.providerOptions) ? { ...record.providerOptions } : {},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ function workspaceDraftTabSetupsEqual(
|
||||
left.modeId === right.modeId &&
|
||||
left.model === right.model &&
|
||||
left.thinkingOptionId === right.thinkingOptionId &&
|
||||
recordsShallowEqual(left.featureValues, right.featureValues)
|
||||
recordsShallowEqual(left.providerOptions, right.providerOptions)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ export interface WorkspaceDraftTabSetup {
|
||||
modeId: string | null;
|
||||
model: string | null;
|
||||
thinkingOptionId: string | null;
|
||||
featureValues: Record<string, unknown>;
|
||||
providerOptions: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface WorkspaceWorkingDiffTabTarget {
|
||||
|
||||
@@ -0,0 +1,252 @@
|
||||
import { controlsFromFeatures, optionsFromFeatures } from "@getpaseo/protocol/option-controls";
|
||||
import type { AgentOptionControl } from "@getpaseo/protocol/agent-types";
|
||||
import type {
|
||||
AgentConfigApply,
|
||||
AgentProfile,
|
||||
AgentSnapshotPayload,
|
||||
MutableDaemonConfig,
|
||||
ListProviderFeaturesResponseMessage,
|
||||
ProviderControlsListResponseMessage,
|
||||
ServerInfoStatusPayload,
|
||||
SessionInboundMessage,
|
||||
SessionOutboundMessage,
|
||||
} from "@getpaseo/protocol/messages";
|
||||
|
||||
/**
|
||||
* COMPAT(providerOptionControls): added in v0.15.0, remove after 2027-05-01 once daemon floor >=
|
||||
* v0.15.0.
|
||||
*
|
||||
* A daemon without `server_info.features.providerOptionControls` sends `features` (a control with
|
||||
* its value attached) and takes composer values as `featureValues`. This is the one place that
|
||||
* turns that into the shape everyone else uses: `controls` over `options`, written through
|
||||
* `providerOptions`.
|
||||
*/
|
||||
export function usesLegacyProviderOptions(info: ServerInfoStatusPayload): boolean {
|
||||
return info.features?.providerOptionControls !== true;
|
||||
}
|
||||
|
||||
export class LegacyProviderOptions {
|
||||
/** Gives agent snapshots `controls` and `options`, built from their `features`. */
|
||||
normalize(message: SessionOutboundMessage): SessionOutboundMessage {
|
||||
switch (message.type) {
|
||||
case "agent_update":
|
||||
if (message.payload.kind !== "upsert") return message;
|
||||
return {
|
||||
...message,
|
||||
payload: { ...message.payload, agent: this.snapshot(message.payload.agent) },
|
||||
};
|
||||
case "agent_status":
|
||||
return {
|
||||
...message,
|
||||
payload: { ...message.payload, info: this.snapshot(message.payload.info) },
|
||||
};
|
||||
case "fetch_agents_response":
|
||||
return {
|
||||
...message,
|
||||
payload: {
|
||||
...message.payload,
|
||||
entries: message.payload.entries.map((entry) => ({
|
||||
...entry,
|
||||
agent: this.snapshot(entry.agent),
|
||||
})),
|
||||
},
|
||||
};
|
||||
case "fetch_agent_response":
|
||||
case "agent.create.response":
|
||||
case "cancel_agent_response":
|
||||
return {
|
||||
...message,
|
||||
payload: {
|
||||
...message.payload,
|
||||
agent: message.payload.agent && this.snapshot(message.payload.agent),
|
||||
},
|
||||
} as SessionOutboundMessage;
|
||||
case "workspace.create.response":
|
||||
return {
|
||||
...message,
|
||||
payload: {
|
||||
...message.payload,
|
||||
...(message.payload.agent ? { agent: this.snapshot(message.payload.agent) } : {}),
|
||||
},
|
||||
};
|
||||
case "wait_for_finish_response":
|
||||
return {
|
||||
...message,
|
||||
payload: {
|
||||
...message.payload,
|
||||
final: message.payload.final && this.snapshot(message.payload.final),
|
||||
},
|
||||
};
|
||||
case "get_daemon_config_response":
|
||||
case "set_daemon_config_response":
|
||||
return {
|
||||
...message,
|
||||
payload: { ...message.payload, config: this.daemonConfig(message.payload.config) },
|
||||
};
|
||||
case "fetch_agent_timeline_response":
|
||||
return {
|
||||
...message,
|
||||
payload: {
|
||||
...message.payload,
|
||||
agent: message.payload.agent && this.snapshot(message.payload.agent),
|
||||
},
|
||||
};
|
||||
case "status":
|
||||
return this.status(message);
|
||||
default:
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
private status(
|
||||
message: Extract<SessionOutboundMessage, { type: "status" }>,
|
||||
): SessionOutboundMessage {
|
||||
const { payload } = message;
|
||||
if (payload.status === "agent_created" || payload.status === "agent_resumed") {
|
||||
const { agent } = payload as unknown as { agent: AgentSnapshotPayload };
|
||||
return { ...message, payload: { ...payload, agent: this.snapshot(agent) } };
|
||||
}
|
||||
if (payload.status === "daemon_config_changed") {
|
||||
const config = payload.config as MutableDaemonConfig;
|
||||
return { ...message, payload: { ...payload, config: this.daemonConfig(config) } };
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits a create's options for a legacy daemon: the ids it lists as features for that very
|
||||
* config go out as `featureValues`, which is where it reads them, and the rest stay
|
||||
* `providerOptions`. Which options are features depends on the model, mode and thinking level
|
||||
* as well as the provider, so the ids come from a listing for this config, never from memory.
|
||||
*/
|
||||
routeCreateConfig<
|
||||
T extends {
|
||||
providerOptions?: Record<string, unknown>;
|
||||
featureValues?: Record<string, unknown>;
|
||||
},
|
||||
>(config: T, featureIds: ReadonlySet<string>): T {
|
||||
if (!config.providerOptions) return config;
|
||||
const featureValues: Record<string, unknown> = {};
|
||||
const providerOptions: Record<string, unknown> = {};
|
||||
for (const [key, value] of Object.entries(config.providerOptions)) {
|
||||
(featureIds.has(key) ? featureValues : providerOptions)[key] = value;
|
||||
}
|
||||
const { providerOptions: _options, ...rest } = config;
|
||||
return {
|
||||
...(rest as T),
|
||||
...(Object.keys(providerOptions).length > 0 ? { providerOptions } : {}),
|
||||
...(Object.keys(featureValues).length > 0
|
||||
? { featureValues: { ...config.featureValues, ...featureValues } }
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
|
||||
/** Sends options as `featureValues`, which is where a legacy daemon reads them. */
|
||||
prepare(message: SessionInboundMessage): SessionInboundMessage {
|
||||
switch (message.type) {
|
||||
case "list_commands_request": {
|
||||
if (!message.draftConfig?.providerOptions) return message;
|
||||
const { providerOptions, ...draftConfig } = message.draftConfig;
|
||||
return {
|
||||
...message,
|
||||
draftConfig: {
|
||||
...draftConfig,
|
||||
featureValues: { ...draftConfig.featureValues, ...providerOptions },
|
||||
},
|
||||
};
|
||||
}
|
||||
case "set_daemon_config_request":
|
||||
if (!message.config.agentProfiles) return message;
|
||||
return {
|
||||
...message,
|
||||
config: {
|
||||
...message.config,
|
||||
agentProfiles: message.config.agentProfiles.map(profileWithFeatureValues),
|
||||
},
|
||||
};
|
||||
default:
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An options patch as feature writes. `null` removes an option, which the old API cannot say:
|
||||
* its setters take a value, and the Codex one rejects anything but a choice id. A toggle goes
|
||||
* off and a choice goes to its default; an option with no control to say what its default is
|
||||
* cannot be reset, and nothing is written.
|
||||
*/
|
||||
featureWrites(
|
||||
patch: Record<string, unknown>,
|
||||
controls: readonly AgentOptionControl[],
|
||||
): [string, unknown][] {
|
||||
return Object.entries(patch).map(([key, value]) => {
|
||||
if (value !== null) return [key, value];
|
||||
const control = controls.find((candidate) => candidate.key === key);
|
||||
if (control?.type === "toggle") return [key, false];
|
||||
if (control?.type === "select" && control.defaultValue !== undefined) {
|
||||
return [key, control.defaultValue];
|
||||
}
|
||||
throw new Error(`Update the host to reset ${key}.`);
|
||||
});
|
||||
}
|
||||
|
||||
/** A config apply with its `options` as `featureValues`, the way a daemon without them takes it. */
|
||||
featureValuesConfig(
|
||||
config: AgentConfigApply,
|
||||
controls: readonly AgentOptionControl[],
|
||||
): AgentConfigApply {
|
||||
const { options, ...rest } = config;
|
||||
if (!options) return config;
|
||||
return {
|
||||
...rest,
|
||||
featureValues: {
|
||||
...rest.featureValues,
|
||||
...Object.fromEntries(this.featureWrites(options, controls)),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** The legacy answer to a controls listing, in the shape of the current response. */
|
||||
controlsResponse(
|
||||
legacy: ListProviderFeaturesResponseMessage["payload"],
|
||||
): ProviderControlsListResponseMessage["payload"] {
|
||||
const { features, ...rest } = legacy;
|
||||
return {
|
||||
...rest,
|
||||
...(features
|
||||
? { controls: controlsFromFeatures(features), options: optionsFromFeatures(features) }
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
|
||||
private daemonConfig(config: MutableDaemonConfig): MutableDaemonConfig {
|
||||
if (!config.agentProfiles) return config;
|
||||
return { ...config, agentProfiles: config.agentProfiles.map(profileWithOptions) };
|
||||
}
|
||||
|
||||
private readonly snapshot = (agent: AgentSnapshotPayload): AgentSnapshotPayload => {
|
||||
if (agent.controls || !agent.features) return agent;
|
||||
return {
|
||||
...agent,
|
||||
controls: controlsFromFeatures(agent.features),
|
||||
options: optionsFromFeatures(agent.features),
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* A legacy daemon stores a profile's options under `featureValues`, and keeps an `options` field
|
||||
* a newer daemon left on it. Both are read, and an explicit `options` key wins, as it does on the
|
||||
* daemon (`foldFeatureValues`).
|
||||
*/
|
||||
function profileWithOptions(profile: AgentProfile): AgentProfile {
|
||||
if (!profile.featureValues) return profile;
|
||||
const { featureValues, ...rest } = profile;
|
||||
return { ...rest, options: { ...featureValues, ...profile.options } };
|
||||
}
|
||||
|
||||
function profileWithFeatureValues(profile: AgentProfile): AgentProfile {
|
||||
if (!profile.options) return profile;
|
||||
const { options, ...rest } = profile;
|
||||
return { ...rest, featureValues: options };
|
||||
}
|
||||
@@ -8926,3 +8926,552 @@ test("routed channels inherit an origin without drain support", async () => {
|
||||
expect(route.supportsDrain).toBe(false);
|
||||
route.close();
|
||||
});
|
||||
|
||||
describe("provider options across daemon versions", () => {
|
||||
const agentSnapshot = {
|
||||
id: "agent-1",
|
||||
provider: "codex",
|
||||
cwd: "/repo",
|
||||
model: null,
|
||||
thinkingOptionId: null,
|
||||
effectiveThinkingOptionId: null,
|
||||
createdAt: "2026-04-30T00:00:00.000Z",
|
||||
updatedAt: "2026-04-30T00:00:00.000Z",
|
||||
lastUserMessageAt: null,
|
||||
status: "idle",
|
||||
capabilities: {
|
||||
supportsStreaming: false,
|
||||
supportsSessionPersistence: false,
|
||||
supportsDynamicModes: false,
|
||||
supportsMcpServers: false,
|
||||
supportsReasoningStream: false,
|
||||
supportsToolInvocations: false,
|
||||
},
|
||||
currentModeId: null,
|
||||
availableModes: [],
|
||||
pendingPermissions: [],
|
||||
persistence: null,
|
||||
title: null,
|
||||
labels: {},
|
||||
requiresAttention: false,
|
||||
attentionReason: null,
|
||||
};
|
||||
const speedFeature = {
|
||||
type: "select",
|
||||
id: "service_tier",
|
||||
label: "Speed",
|
||||
value: "priority",
|
||||
options: [
|
||||
{ id: "default", label: "Normal", isDefault: true },
|
||||
{ id: "priority", label: "Fast" },
|
||||
],
|
||||
};
|
||||
|
||||
async function connect(features: Record<string, boolean>) {
|
||||
const mock = createMockTransport();
|
||||
const client = new DaemonClient({
|
||||
url: "ws://test",
|
||||
clientId: "provider_options",
|
||||
transportFactory: () => mock.transport,
|
||||
reconnect: { enabled: false },
|
||||
});
|
||||
clients.push(client);
|
||||
const connecting = client.connect();
|
||||
mock.triggerOpen({ features });
|
||||
await connecting;
|
||||
const sentMessages = () =>
|
||||
mock.sent.map(
|
||||
(frame) => (JSON.parse(frame as string) as { message: Record<string, unknown> }).message,
|
||||
);
|
||||
return { mock, client, sentMessages };
|
||||
}
|
||||
|
||||
test("a legacy create and a timeline read return the agent with controls over options", async () => {
|
||||
const { mock, client, sentMessages } = await connect({});
|
||||
const legacyAgent = { ...agentSnapshot, features: [speedFeature] };
|
||||
const answerLast = (reply: (requestId: string) => Record<string, unknown>) => {
|
||||
const sent = sentMessages();
|
||||
const requestId = String(sent[sent.length - 1].requestId);
|
||||
mock.triggerMessage(wrapSessionMessage(reply(requestId) as never));
|
||||
};
|
||||
|
||||
const creating = client.createAgent({ provider: "codex", cwd: "/repo" });
|
||||
answerLast((requestId) => ({
|
||||
type: "status",
|
||||
payload: { status: "agent_created", requestId, agentId: "agent-1", agent: legacyAgent },
|
||||
}));
|
||||
const created = await creating;
|
||||
|
||||
const reading = client.fetchAgentTimeline("agent-1");
|
||||
answerLast((requestId) => ({
|
||||
type: "fetch_agent_timeline_response",
|
||||
payload: {
|
||||
requestId,
|
||||
agentId: "agent-1",
|
||||
agent: legacyAgent,
|
||||
direction: "tail",
|
||||
projection: "projected",
|
||||
epoch: "epoch-1",
|
||||
reset: false,
|
||||
staleCursor: false,
|
||||
gap: false,
|
||||
window: { minSeq: 0, maxSeq: 0, nextSeq: 1 },
|
||||
startCursor: null,
|
||||
endCursor: null,
|
||||
hasOlder: false,
|
||||
hasNewer: false,
|
||||
entries: [],
|
||||
error: null,
|
||||
},
|
||||
}));
|
||||
const timeline = await reading;
|
||||
|
||||
expect(created.options).toEqual({ service_tier: "priority" });
|
||||
expect(created.controls).toEqual([expect.objectContaining({ key: "service_tier" })]);
|
||||
expect(timeline.agent?.options).toEqual({ service_tier: "priority" });
|
||||
expect(timeline.agent?.controls).toEqual([expect.objectContaining({ key: "service_tier" })]);
|
||||
});
|
||||
|
||||
test("a legacy daemon's features arrive as controls over options", async () => {
|
||||
const { mock, client } = await connect({});
|
||||
const received: Array<{ controls?: unknown; options?: unknown }> = [];
|
||||
client.on("agent_update", (message) => {
|
||||
if (message.payload.kind === "upsert") received.push(message.payload.agent);
|
||||
});
|
||||
mock.triggerMessage(
|
||||
wrapSessionMessage({
|
||||
type: "agent_update",
|
||||
payload: { kind: "upsert", agent: { ...agentSnapshot, features: [speedFeature] } },
|
||||
}),
|
||||
);
|
||||
expect(received).toEqual([
|
||||
expect.objectContaining({
|
||||
options: { service_tier: "priority" },
|
||||
controls: [
|
||||
expect.objectContaining({
|
||||
type: "select",
|
||||
key: "service_tier",
|
||||
defaultValue: "default",
|
||||
choices: [
|
||||
{ value: "default", label: "Normal" },
|
||||
{ value: "priority", label: "Fast" },
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
test("a legacy daemon takes option writes as feature writes", async () => {
|
||||
const { client, sentMessages, mock } = await connect({});
|
||||
const write = client.setAgentOptions("agent-1", { service_tier: "default" });
|
||||
const [request] = sentMessages();
|
||||
expect(request).toMatchObject({
|
||||
type: "set_agent_feature_request",
|
||||
agentId: "agent-1",
|
||||
featureId: "service_tier",
|
||||
value: "default",
|
||||
});
|
||||
mock.triggerMessage(
|
||||
wrapSessionMessage({
|
||||
type: "set_agent_feature_response",
|
||||
payload: { requestId: request.requestId, agentId: "agent-1", accepted: true, error: null },
|
||||
}),
|
||||
);
|
||||
await write;
|
||||
});
|
||||
|
||||
// The old Codex setter rejects a non-string `service_tier` and the old Claude setter reads
|
||||
// `null` as off, so a reset is sent as the value the old API can represent.
|
||||
async function resetOnLegacyDaemon(agent: Record<string, unknown>, patch: Record<string, null>) {
|
||||
const { client, sentMessages, mock } = await connect({});
|
||||
const reply = (message: Record<string, unknown>) =>
|
||||
mock.triggerMessage(wrapSessionMessage(message as never));
|
||||
const writing = client.setAgentOptions("agent-1", patch);
|
||||
const [fetch] = sentMessages();
|
||||
expect(fetch).toMatchObject({ type: "fetch_agent_request", agentId: "agent-1" });
|
||||
reply({
|
||||
type: "fetch_agent_response",
|
||||
payload: { requestId: fetch.requestId, agent, project: null, error: null },
|
||||
});
|
||||
return { writing, sentMessages, reply };
|
||||
}
|
||||
|
||||
test("a legacy daemon resets a choice to the default the old API names", async () => {
|
||||
const { writing, sentMessages, reply } = await resetOnLegacyDaemon(
|
||||
{ ...agentSnapshot, provider: "codex", features: [speedFeature] },
|
||||
{ service_tier: null },
|
||||
);
|
||||
await vi.waitFor(() => expect(sentMessages()).toHaveLength(2));
|
||||
const write = sentMessages()[1];
|
||||
expect(write).toMatchObject({
|
||||
type: "set_agent_feature_request",
|
||||
featureId: "service_tier",
|
||||
value: "default",
|
||||
});
|
||||
reply({
|
||||
type: "set_agent_feature_response",
|
||||
payload: { requestId: write.requestId, agentId: "agent-1", accepted: true, error: null },
|
||||
});
|
||||
await writing;
|
||||
});
|
||||
|
||||
test("a legacy daemon resets a toggle to off", async () => {
|
||||
const { writing, sentMessages, reply } = await resetOnLegacyDaemon(
|
||||
{
|
||||
...agentSnapshot,
|
||||
features: [{ type: "toggle", id: "fast_mode", label: "Fast", value: true }],
|
||||
},
|
||||
{ fast_mode: null },
|
||||
);
|
||||
await vi.waitFor(() => expect(sentMessages()).toHaveLength(2));
|
||||
const write = sentMessages()[1];
|
||||
expect(write).toMatchObject({ featureId: "fast_mode", value: false });
|
||||
reply({
|
||||
type: "set_agent_feature_response",
|
||||
payload: { requestId: write.requestId, agentId: "agent-1", accepted: true, error: null },
|
||||
});
|
||||
await writing;
|
||||
});
|
||||
|
||||
test("a legacy daemon cannot reset an option no control draws, and writes nothing", async () => {
|
||||
const { writing, sentMessages } = await resetOnLegacyDaemon(
|
||||
{ ...agentSnapshot, features: [speedFeature] },
|
||||
{ token_budget: null },
|
||||
);
|
||||
await expect(writing).rejects.toThrow("Update the host to reset token_budget.");
|
||||
expect(sentMessages()).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("a legacy daemon applies a config reset as the default the old API names", async () => {
|
||||
const { client, sentMessages, mock } = await connect({});
|
||||
const reply = (message: Record<string, unknown>) =>
|
||||
mock.triggerMessage(wrapSessionMessage(message as never));
|
||||
const applying = client.applyAgentConfig("agent-1", {
|
||||
modeId: "plan",
|
||||
options: { service_tier: null, sandbox_mode: "read-only" },
|
||||
});
|
||||
const [fetch] = sentMessages();
|
||||
expect(fetch).toMatchObject({ type: "fetch_agent_request", agentId: "agent-1" });
|
||||
reply({
|
||||
type: "fetch_agent_response",
|
||||
payload: {
|
||||
requestId: fetch.requestId,
|
||||
agent: { ...agentSnapshot, provider: "codex", features: [speedFeature] },
|
||||
project: null,
|
||||
error: null,
|
||||
},
|
||||
});
|
||||
await vi.waitFor(() => expect(sentMessages()).toHaveLength(2));
|
||||
const apply = sentMessages()[1];
|
||||
expect(apply).toMatchObject({
|
||||
type: "agent.config.apply.request",
|
||||
config: {
|
||||
modeId: "plan",
|
||||
featureValues: { service_tier: "default", sandbox_mode: "read-only" },
|
||||
},
|
||||
});
|
||||
expect(apply.config).not.toHaveProperty("options");
|
||||
reply({
|
||||
type: "agent.config.apply.response",
|
||||
payload: { requestId: apply.requestId, agentId: "agent-1", accepted: true, error: null },
|
||||
});
|
||||
await applying;
|
||||
});
|
||||
|
||||
test("a legacy daemon cannot apply a config reset it cannot name, and applies nothing", async () => {
|
||||
const { client, sentMessages, mock } = await connect({});
|
||||
const applying = client.applyAgentConfig("agent-1", { options: { token_budget: null } });
|
||||
const [fetch] = sentMessages();
|
||||
mock.triggerMessage(
|
||||
wrapSessionMessage({
|
||||
type: "fetch_agent_response",
|
||||
payload: {
|
||||
requestId: fetch.requestId,
|
||||
agent: { ...agentSnapshot, features: [speedFeature] },
|
||||
project: null,
|
||||
error: null,
|
||||
},
|
||||
} as never),
|
||||
);
|
||||
await expect(applying).rejects.toThrow("Update the host to reset token_budget.");
|
||||
expect(sentMessages()).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("a current daemon takes option writes as one options patch", async () => {
|
||||
const { client, sentMessages, mock } = await connect({ providerOptionControls: true });
|
||||
const write = client.setAgentOptions("agent-1", { service_tier: null, sandbox_mode: "x" });
|
||||
const [request] = sentMessages();
|
||||
expect(request).toMatchObject({
|
||||
type: "agent.config.apply.request",
|
||||
agentId: "agent-1",
|
||||
config: { options: { service_tier: null, sandbox_mode: "x" } },
|
||||
});
|
||||
mock.triggerMessage(
|
||||
wrapSessionMessage({
|
||||
type: "agent.config.apply.response",
|
||||
payload: { requestId: request.requestId, agentId: "agent-1", accepted: true, error: null },
|
||||
}),
|
||||
);
|
||||
await write;
|
||||
});
|
||||
|
||||
test("a legacy draft listing answers with controls and options", async () => {
|
||||
const { client, sentMessages, mock } = await connect({});
|
||||
const listing = client.listProviderControls({
|
||||
provider: "codex",
|
||||
cwd: "/repo",
|
||||
providerOptions: { service_tier: "default" },
|
||||
});
|
||||
const [request] = sentMessages();
|
||||
expect(request).toMatchObject({
|
||||
type: "list_provider_features_request",
|
||||
draftConfig: { provider: "codex", featureValues: { service_tier: "default" } },
|
||||
});
|
||||
mock.triggerMessage(
|
||||
wrapSessionMessage({
|
||||
type: "list_provider_features_response",
|
||||
payload: {
|
||||
provider: "codex",
|
||||
features: [{ ...speedFeature, value: "default" }],
|
||||
error: null,
|
||||
fetchedAt: "2026-04-30T00:00:00.000Z",
|
||||
requestId: request.requestId,
|
||||
},
|
||||
}),
|
||||
);
|
||||
await expect(listing).resolves.toMatchObject({
|
||||
provider: "codex",
|
||||
options: { service_tier: "default" },
|
||||
controls: [expect.objectContaining({ key: "service_tier" })],
|
||||
});
|
||||
});
|
||||
|
||||
test("a legacy daemon's profiles are read and saved by their options", async () => {
|
||||
const { client, sentMessages, mock } = await connect({});
|
||||
const reading = client.getDaemonConfig();
|
||||
const [read] = sentMessages();
|
||||
mock.triggerMessage(
|
||||
wrapSessionMessage({
|
||||
type: "get_daemon_config_response",
|
||||
payload: {
|
||||
requestId: read.requestId,
|
||||
config: {
|
||||
mcp: { injectIntoAgents: true },
|
||||
agentProfiles: [
|
||||
{
|
||||
id: "p1",
|
||||
name: "Fast",
|
||||
provider: "codex",
|
||||
featureValues: { service_tier: "fast" },
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
const { config } = await reading;
|
||||
expect(config.agentProfiles?.[0]).toMatchObject({ options: { service_tier: "fast" } });
|
||||
expect(config.agentProfiles?.[0]).not.toHaveProperty("featureValues");
|
||||
|
||||
void client.patchDaemonConfig({ agentProfiles: config.agentProfiles }).catch(() => {});
|
||||
const written = sentMessages().find((message) => message.type === "set_daemon_config_request");
|
||||
expect(written).toMatchObject({
|
||||
config: { agentProfiles: [{ featureValues: { service_tier: "fast" } }] },
|
||||
});
|
||||
expect(written).not.toMatchObject({ config: { agentProfiles: [{ options: {} }] } });
|
||||
});
|
||||
|
||||
test("a legacy daemon's profile with both featureValues and options keeps both when saved", async () => {
|
||||
// `options` survives on a legacy daemon's passthrough profile after a downgrade, while its
|
||||
// own app keeps editing `featureValues`.
|
||||
const { client, sentMessages, mock } = await connect({});
|
||||
const reading = client.getDaemonConfig();
|
||||
const [read] = sentMessages();
|
||||
mock.triggerMessage(
|
||||
wrapSessionMessage({
|
||||
type: "get_daemon_config_response",
|
||||
payload: {
|
||||
requestId: read.requestId,
|
||||
config: {
|
||||
mcp: { injectIntoAgents: true },
|
||||
agentProfiles: [
|
||||
{
|
||||
id: "p1",
|
||||
name: "Mixed",
|
||||
provider: "codex",
|
||||
featureValues: { service_tier: "fast", sandbox_mode: "workspace-write" },
|
||||
options: { sandbox_mode: "read-only" },
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
const { config } = await reading;
|
||||
expect(config.agentProfiles?.[0]).toMatchObject({
|
||||
options: { service_tier: "fast", sandbox_mode: "read-only" },
|
||||
});
|
||||
expect(config.agentProfiles?.[0]).not.toHaveProperty("featureValues");
|
||||
|
||||
void client.patchDaemonConfig({ agentProfiles: config.agentProfiles }).catch(() => {});
|
||||
const written = sentMessages().find((message) => message.type === "set_daemon_config_request");
|
||||
expect(written).toMatchObject({
|
||||
config: {
|
||||
agentProfiles: [{ featureValues: { service_tier: "fast", sandbox_mode: "read-only" } }],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test("a legacy daemon applies a profile's options as feature values", async () => {
|
||||
const { client, sentMessages } = await connect({});
|
||||
void client.applyAgentConfig("agent-1", { options: { service_tier: "fast" } }).catch(() => {});
|
||||
const [request] = sentMessages();
|
||||
expect(request).toMatchObject({
|
||||
type: "agent.config.apply.request",
|
||||
config: { featureValues: { service_tier: "fast" } },
|
||||
});
|
||||
});
|
||||
|
||||
test("a cold legacy create lists the provider's features before routing its options", async () => {
|
||||
const { client, sentMessages, mock } = await connect({});
|
||||
void client
|
||||
.createAgent({
|
||||
config: {
|
||||
provider: "claude",
|
||||
cwd: "/repo",
|
||||
providerOptions: { fast_mode: true, sandbox_mode: "read-only" },
|
||||
},
|
||||
})
|
||||
.catch(() => {});
|
||||
await vi.waitFor(() => expect(sentMessages()).toHaveLength(1));
|
||||
const [listing] = sentMessages();
|
||||
expect(listing).toMatchObject({
|
||||
type: "list_provider_features_request",
|
||||
draftConfig: { provider: "claude", cwd: "/repo" },
|
||||
});
|
||||
mock.triggerMessage(
|
||||
wrapSessionMessage({
|
||||
type: "list_provider_features_response",
|
||||
payload: {
|
||||
provider: "claude",
|
||||
features: [{ type: "toggle", id: "fast_mode", label: "Fast", value: false }],
|
||||
error: null,
|
||||
fetchedAt: "2026-04-30T00:00:00.000Z",
|
||||
requestId: listing.requestId,
|
||||
},
|
||||
}),
|
||||
);
|
||||
await vi.waitFor(() => expect(sentMessages()).toHaveLength(2));
|
||||
expect(sentMessages()[1].config).toMatchObject({
|
||||
featureValues: { fast_mode: true },
|
||||
providerOptions: { sandbox_mode: "read-only" },
|
||||
});
|
||||
});
|
||||
|
||||
test("a legacy workspace create routes its agent's options from its own model's controls", async () => {
|
||||
const { client, sentMessages, mock } = await connect({ creationLifecycle: true });
|
||||
mock.triggerMessage(
|
||||
wrapSessionMessage({
|
||||
type: "agent_update",
|
||||
payload: {
|
||||
kind: "upsert",
|
||||
agent: { ...agentSnapshot, provider: "codex", model: "mini", features: [] },
|
||||
},
|
||||
}),
|
||||
);
|
||||
void client
|
||||
.createWorkspace({
|
||||
source: { kind: "directory", path: "/repo" },
|
||||
agent: {
|
||||
config: {
|
||||
provider: "codex",
|
||||
cwd: "/repo",
|
||||
model: "gpt-5.5",
|
||||
providerOptions: { service_tier: "fast" },
|
||||
},
|
||||
},
|
||||
} as never)
|
||||
.catch(() => {});
|
||||
await vi.waitFor(() => expect(sentMessages()).toHaveLength(1));
|
||||
const [listing] = sentMessages();
|
||||
expect(listing).toMatchObject({
|
||||
type: "list_provider_features_request",
|
||||
draftConfig: { provider: "codex", cwd: "/repo", model: "gpt-5.5" },
|
||||
});
|
||||
mock.triggerMessage(
|
||||
wrapSessionMessage({
|
||||
type: "list_provider_features_response",
|
||||
payload: {
|
||||
provider: "codex",
|
||||
features: [speedFeature],
|
||||
error: null,
|
||||
fetchedAt: "2026-04-30T00:00:00.000Z",
|
||||
requestId: listing.requestId,
|
||||
},
|
||||
}),
|
||||
);
|
||||
const sentTypes = () => sentMessages().map((message) => message.type);
|
||||
await vi.waitFor(() => expect(sentTypes()).toContain("workspace.create.request"));
|
||||
const created = sentMessages()[sentTypes().indexOf("workspace.create.request")];
|
||||
expect(created).toMatchObject({
|
||||
agent: { config: { featureValues: { service_tier: "fast" } } },
|
||||
});
|
||||
});
|
||||
|
||||
test("a legacy create lists the controls of its own model, whatever a snapshot showed", async () => {
|
||||
const { client, sentMessages, mock } = await connect({});
|
||||
// A Haiku agent has no Fast control; that says nothing about Opus.
|
||||
mock.triggerMessage(
|
||||
wrapSessionMessage({
|
||||
type: "agent_update",
|
||||
payload: {
|
||||
kind: "upsert",
|
||||
agent: { ...agentSnapshot, provider: "claude", model: "haiku", features: [] },
|
||||
},
|
||||
}),
|
||||
);
|
||||
void client
|
||||
.createAgent({
|
||||
config: {
|
||||
provider: "claude",
|
||||
cwd: "/repo",
|
||||
model: "opus",
|
||||
modeId: "plan",
|
||||
thinkingOptionId: "high",
|
||||
providerOptions: { fast_mode: true, sandbox_mode: "read-only" },
|
||||
},
|
||||
})
|
||||
.catch(() => {});
|
||||
await vi.waitFor(() => expect(sentMessages()).toHaveLength(1));
|
||||
const [listing] = sentMessages();
|
||||
expect(listing).toMatchObject({
|
||||
type: "list_provider_features_request",
|
||||
draftConfig: {
|
||||
provider: "claude",
|
||||
cwd: "/repo",
|
||||
model: "opus",
|
||||
modeId: "plan",
|
||||
thinkingOptionId: "high",
|
||||
},
|
||||
});
|
||||
mock.triggerMessage(
|
||||
wrapSessionMessage({
|
||||
type: "list_provider_features_response",
|
||||
payload: {
|
||||
provider: "claude",
|
||||
features: [{ type: "toggle", id: "fast_mode", label: "Fast", value: false }],
|
||||
error: null,
|
||||
fetchedAt: "2026-04-30T00:00:00.000Z",
|
||||
requestId: listing.requestId,
|
||||
},
|
||||
}),
|
||||
);
|
||||
await vi.waitFor(() => expect(sentMessages()).toHaveLength(2));
|
||||
expect(sentMessages()[1].config).toMatchObject({
|
||||
model: "opus",
|
||||
featureValues: { fast_mode: true },
|
||||
providerOptions: { sandbox_mode: "read-only" },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -102,6 +102,7 @@ import type {
|
||||
WorkspaceSetupStatusResponseMessage,
|
||||
ListCommandsResponse,
|
||||
ListProviderFeaturesResponseMessage,
|
||||
ProviderControlsListResponseMessage,
|
||||
ListProviderModelsResponseMessage,
|
||||
ListProviderModesResponseMessage,
|
||||
ListAvailableProvidersResponse,
|
||||
@@ -143,6 +144,7 @@ import type {
|
||||
AgentSkillsSaveResult,
|
||||
} from "@getpaseo/protocol/messages";
|
||||
import type {
|
||||
AgentOptionControl,
|
||||
AgentPermissionRequest,
|
||||
AgentPermissionResponse,
|
||||
AgentPersistenceHandle,
|
||||
@@ -189,6 +191,10 @@ import {
|
||||
normalizeProviderSnapshotUpdateMessage,
|
||||
normalizeProvidersSnapshotPayload,
|
||||
} from "./compat/normalize-provider-models.js";
|
||||
import {
|
||||
LegacyProviderOptions,
|
||||
usesLegacyProviderOptions,
|
||||
} from "./compat/legacy-provider-options.js";
|
||||
import { TerminalStreamRouter, type TerminalStreamEvent } from "./terminal-stream-router.js";
|
||||
import type {
|
||||
BrowserAutomationExecuteRequest,
|
||||
@@ -604,6 +610,7 @@ export interface FileUploadInput {
|
||||
export type FileUploadResult = FileUploadResponse["payload"];
|
||||
type FileDownloadTokenPayload = FileDownloadTokenResponse["payload"];
|
||||
type ListProviderFeaturesPayload = ListProviderFeaturesResponseMessage["payload"];
|
||||
export type ListProviderControlsPayload = ProviderControlsListResponseMessage["payload"];
|
||||
type ListProviderModelsPayload = ListProviderModelsResponseMessage["payload"];
|
||||
type ListProviderModesPayload = ListProviderModesResponseMessage["payload"];
|
||||
type ListAvailableProvidersPayload = ListAvailableProvidersResponse["payload"];
|
||||
@@ -630,7 +637,7 @@ type WriteProjectConfigPayload = Extract<
|
||||
type ListCommandsPayload = ListCommandsResponse["payload"];
|
||||
type ListCommandsDraftConfig = Pick<
|
||||
AgentSessionConfig,
|
||||
"provider" | "cwd" | "modeId" | "model" | "thinkingOptionId" | "featureValues"
|
||||
"provider" | "cwd" | "modeId" | "model" | "thinkingOptionId" | "featureValues" | "providerOptions"
|
||||
>;
|
||||
export interface WriteProjectConfigInput {
|
||||
repoRoot: string;
|
||||
@@ -2103,17 +2110,13 @@ export class DaemonClient {
|
||||
}
|
||||
|
||||
private sendSessionPayload(payload: SessionInboundMessage): Promise<void> {
|
||||
return this.sendJsonMessage(
|
||||
"session",
|
||||
payload.type,
|
||||
{ type: "session", message: payload },
|
||||
() => {
|
||||
if (!("requestId" in payload) || typeof payload.requestId !== "string") return;
|
||||
for (const waiter of this.waiters) {
|
||||
if (waiter.requestId === payload.requestId) waiter.submitted = true;
|
||||
}
|
||||
},
|
||||
);
|
||||
const wire = this.legacyProviderOptions()?.prepare(payload) ?? payload;
|
||||
return this.sendJsonMessage("session", payload.type, { type: "session", message: wire }, () => {
|
||||
if (!("requestId" in payload) || typeof payload.requestId !== "string") return;
|
||||
for (const waiter of this.waiters) {
|
||||
if (waiter.requestId === payload.requestId) waiter.submitted = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private sendTransportFrame(
|
||||
@@ -3334,14 +3337,44 @@ export class DaemonClient {
|
||||
);
|
||||
}
|
||||
if (options.background !== undefined) this.requireBackgroundCreation(options);
|
||||
const config = resolveAgentConfig(options);
|
||||
const result = await this.creations.createAgent({
|
||||
...options,
|
||||
config: resolveAgentConfig(options),
|
||||
config: this.carriesLegacyOptions(config)
|
||||
? await this.routeLegacyCreateConfig(config)
|
||||
: config,
|
||||
});
|
||||
if (result.error || !result.agent) throw new Error(result.error ?? "Agent creation failed");
|
||||
return result.agent;
|
||||
}
|
||||
|
||||
/**
|
||||
* A legacy daemon reads control options as `featureValues`, and which options are controls
|
||||
* depends on the config (Claude's differ by model), so a create that carries options first lists
|
||||
* the controls for its own config. Callers never prime anything.
|
||||
*/
|
||||
private carriesLegacyOptions(config: AgentSessionConfig): boolean {
|
||||
return (
|
||||
this.legacyProviderOptions() !== null && Object.keys(config.providerOptions ?? {}).length > 0
|
||||
);
|
||||
}
|
||||
|
||||
private async routeLegacyCreateConfig(config: AgentSessionConfig): Promise<AgentSessionConfig> {
|
||||
const payload = await this.listProviderFeatures({
|
||||
provider: config.provider,
|
||||
cwd: config.cwd || "~",
|
||||
...(config.modeId ? { modeId: config.modeId } : {}),
|
||||
...(config.model ? { model: config.model } : {}),
|
||||
...(config.thinkingOptionId ? { thinkingOptionId: config.thinkingOptionId } : {}),
|
||||
featureValues: config.providerOptions,
|
||||
});
|
||||
if (payload.error) throw new Error(payload.error);
|
||||
return this.legacyOptions.routeCreateConfig(
|
||||
config,
|
||||
new Set((payload.features ?? []).map((feature) => feature.id)),
|
||||
);
|
||||
}
|
||||
|
||||
private async createLegacyAgent(
|
||||
options: CreateAgentRequestOptions,
|
||||
): Promise<AgentSnapshotPayload> {
|
||||
@@ -4132,6 +4165,41 @@ export class DaemonClient {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the agent's own provider options: top-level keys replace, `null` removes the key.
|
||||
* A daemon without `providerOptionControls` takes each key as a feature write.
|
||||
*/
|
||||
async setAgentOptions(
|
||||
agentId: string,
|
||||
patch: Record<string, unknown>,
|
||||
): Promise<AgentProviderNotice | null> {
|
||||
const legacy = this.legacyProviderOptions();
|
||||
if (legacy) {
|
||||
// COMPAT(providerOptionControls): added in v0.15.0, remove after 2027-05-01.
|
||||
const pending = this.legacyResetControls(agentId, patch);
|
||||
const controls = pending ? await pending : [];
|
||||
for (const [featureId, value] of legacy.featureWrites(patch, controls)) {
|
||||
await this.setAgentFeature(agentId, featureId, value);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return this.applyAgentConfig(agentId, { options: patch });
|
||||
}
|
||||
|
||||
/**
|
||||
* COMPAT(providerOptionControls): added in v0.15.0, remove after 2027-05-01.
|
||||
* A reset (`null`) on a daemon without `providerOptionControls` is written as the value its
|
||||
* control resets to, which takes the agent's controls. Without a reset nothing is fetched, so
|
||||
* the write is not delayed.
|
||||
*/
|
||||
private legacyResetControls(
|
||||
agentId: string,
|
||||
patch: Record<string, unknown>,
|
||||
): Promise<AgentOptionControl[]> | null {
|
||||
if (!Object.values(patch).includes(null)) return null;
|
||||
return this.fetchAgent(agentId).then((result) => result?.agent.controls ?? []);
|
||||
}
|
||||
|
||||
async setAgentThinkingOption(
|
||||
agentId: string,
|
||||
thinkingOptionId: string | null,
|
||||
@@ -4174,11 +4242,18 @@ export class DaemonClient {
|
||||
agentId: string,
|
||||
config: AgentConfigApply,
|
||||
): Promise<AgentProviderNotice | null> {
|
||||
let wireConfig = config;
|
||||
const legacy = this.legacyProviderOptions();
|
||||
if (legacy && config.options) {
|
||||
// COMPAT(providerOptionControls): added in v0.15.0, remove after 2027-05-01.
|
||||
const pending = this.legacyResetControls(agentId, config.options);
|
||||
wireConfig = legacy.featureValuesConfig(config, pending ? await pending : []);
|
||||
}
|
||||
const requestId = this.createRequestId();
|
||||
const message = SessionInboundMessageSchema.parse({
|
||||
type: "agent.config.apply.request",
|
||||
agentId,
|
||||
config,
|
||||
config: wireConfig,
|
||||
requestId,
|
||||
});
|
||||
const payload = await this.sendRequest({
|
||||
@@ -5075,12 +5150,14 @@ export class DaemonClient {
|
||||
if (input.background !== undefined || input.callerAgentId) this.requireBackgroundWorkspaces();
|
||||
if (input.agent?.background !== undefined)
|
||||
throw new Error("Configure background on the workspace, not its initial agent.");
|
||||
let agentConfig = input.agent ? resolveAgentConfig(input.agent) : undefined;
|
||||
if (agentConfig && this.carriesLegacyOptions(agentConfig)) {
|
||||
agentConfig = await this.routeLegacyCreateConfig(agentConfig);
|
||||
}
|
||||
const result = await this.creations.createWorkspace({
|
||||
...input,
|
||||
requestId: resolvedRequestId,
|
||||
...(input.agent
|
||||
? { agent: { ...input.agent, config: resolveAgentConfig(input.agent) } }
|
||||
: {}),
|
||||
...(input.agent && agentConfig ? { agent: { ...input.agent, config: agentConfig } } : {}),
|
||||
});
|
||||
return {
|
||||
...result,
|
||||
@@ -5561,6 +5638,36 @@ export class DaemonClient {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The controls a draft agent would show and the options it would run with: `config.json`
|
||||
* defaults merged with the draft's own `providerOptions`, resolved by the daemon.
|
||||
*/
|
||||
async listProviderControls(
|
||||
draftConfig: ListCommandsDraftConfig,
|
||||
options?: { requestId?: string },
|
||||
): Promise<ListProviderControlsPayload> {
|
||||
const legacy = this.legacyProviderOptions();
|
||||
if (legacy) {
|
||||
const { providerOptions, ...rest } = draftConfig;
|
||||
const payload = await this.listProviderFeatures(
|
||||
{
|
||||
...rest,
|
||||
// A legacy daemon reads the options it exposes as features, whatever the others are.
|
||||
...(providerOptions ? { featureValues: providerOptions } : {}),
|
||||
},
|
||||
options,
|
||||
);
|
||||
return legacy.controlsResponse(payload);
|
||||
}
|
||||
return this.sendCorrelatedSessionRequest({
|
||||
requestId: options?.requestId,
|
||||
message: { type: "provider.controls.list.request", draftConfig },
|
||||
responseType: "provider.controls.list.response",
|
||||
timeout: 90000,
|
||||
});
|
||||
}
|
||||
|
||||
/** @deprecated Use `listProviderControls`. */
|
||||
async listProviderFeatures(
|
||||
draftConfig: ListCommandsDraftConfig,
|
||||
options?: { requestId?: string },
|
||||
@@ -6851,6 +6958,14 @@ export class DaemonClient {
|
||||
return requestId ?? crypto.randomUUID();
|
||||
}
|
||||
|
||||
private readonly legacyOptions = new LegacyProviderOptions();
|
||||
|
||||
/** The translation for a daemon without `providerOptionControls`; null for a current one. */
|
||||
private legacyProviderOptions(): LegacyProviderOptions | null {
|
||||
const info = this.lastServerInfoMessage;
|
||||
return info && usesLegacyProviderOptions(info) ? this.legacyOptions : null;
|
||||
}
|
||||
|
||||
getLastServerInfoMessage(): ServerInfoStatusPayload | null {
|
||||
return this.lastServerInfoMessage;
|
||||
}
|
||||
@@ -7433,6 +7548,7 @@ export class DaemonClient {
|
||||
|
||||
private handleSessionMessage(msg: SessionOutboundMessage): void {
|
||||
msg = this.owned.normalize(msg);
|
||||
msg = this.legacyProviderOptions()?.normalize(msg) ?? msg;
|
||||
if (
|
||||
msg.type === "providers_snapshot_update" &&
|
||||
this.config.providerSnapshots !== "wire" &&
|
||||
|
||||
@@ -1683,7 +1683,12 @@ test("config actions delegate to existing daemon config RPCs", async () => {
|
||||
});
|
||||
|
||||
test("agent config maps provider/model and provider-native options to the daemon", async () => {
|
||||
const { client, ws } = await connectClient();
|
||||
const { client, ws } = await connectClient({
|
||||
providerUsageList: true,
|
||||
providersSnapshotCwd: true,
|
||||
ownedSubscriptions: true,
|
||||
providerOptionControls: true,
|
||||
});
|
||||
const createdAgent = createAgent({
|
||||
model: "gpt-5.4",
|
||||
currentModeId: "full-access",
|
||||
@@ -1715,8 +1720,8 @@ test("agent config maps provider/model and provider-native options to the daemon
|
||||
model: "gpt-5.4",
|
||||
modeId: "full-access",
|
||||
thinkingOptionId: "high",
|
||||
featureValues: { webSearch: true },
|
||||
providerOptions: {
|
||||
webSearch: true,
|
||||
approval_policy: "never",
|
||||
sandbox_mode: "workspace-write",
|
||||
sandbox_workspace_write: {
|
||||
|
||||
@@ -20,6 +20,8 @@ import type {
|
||||
ListCommandsResponse,
|
||||
ListProviderFeaturesRequestMessage,
|
||||
ListProviderFeaturesResponseMessage,
|
||||
ProviderControlsListRequestMessage,
|
||||
ProviderControlsListResponseMessage,
|
||||
ListProviderModelsResponseMessage,
|
||||
ProjectListRequestMessage,
|
||||
ProjectListResponseMessage,
|
||||
@@ -239,8 +241,12 @@ export interface PaseoAgentConfig {
|
||||
provider: string;
|
||||
modeId?: PaseoAgentSessionConfig["modeId"];
|
||||
thinkingOptionId?: PaseoAgentSessionConfig["thinkingOptionId"];
|
||||
/** @deprecated Put these in `options`; they are folded into it on send. */
|
||||
featureValues?: PaseoProviderFeatureValues;
|
||||
/** JSON-safe provider-native settings, validated by the selected provider. */
|
||||
/**
|
||||
* JSON-safe provider settings, validated by the selected provider. They include the settings the
|
||||
* provider offers a composer control for, such as `service_tier` or `fast_mode`.
|
||||
*/
|
||||
options?: PaseoAgentSessionConfig["providerOptions"];
|
||||
systemPrompt?: PaseoAgentSessionConfig["systemPrompt"];
|
||||
toolPolicy?: PaseoAgentSessionConfig["toolPolicy"];
|
||||
@@ -368,7 +374,12 @@ export interface PaseoAgentHandle {
|
||||
readonly activeTurn: NonNullable<PaseoAgent["activeTurn"]> | null;
|
||||
readonly lastUsage: NonNullable<PaseoAgent["lastUsage"]> | null;
|
||||
readonly lastError: NonNullable<PaseoAgent["lastError"]> | null;
|
||||
/** @deprecated Use `controls` and `options`. */
|
||||
readonly features: NonNullable<PaseoAgent["features"]> | null;
|
||||
/** The provider options the agent runs with: `config.json` defaults merged with its own. */
|
||||
readonly options: NonNullable<PaseoAgent["options"]> | null;
|
||||
/** How the provider wants its options drawn. Controls hold no value; read `options`. */
|
||||
readonly controls: NonNullable<PaseoAgent["controls"]> | null;
|
||||
readonly runtimeInfo: NonNullable<PaseoAgent["runtimeInfo"]> | null;
|
||||
readonly archivedAt: NonNullable<PaseoAgent["archivedAt"]> | null;
|
||||
readonly timeline: PaseoAgentTimelineHandle;
|
||||
@@ -381,6 +392,12 @@ export interface PaseoAgentHandle {
|
||||
reload(options?: { requestId?: string }): Promise<PaseoAgentRefetchResult | null>;
|
||||
send(text: string, options?: PaseoAgentSendOptions): Promise<void>;
|
||||
respondToPermission(options: PaseoAgentRespondToPermissionOptions): Promise<void>;
|
||||
/**
|
||||
* Changes the agent's own options: top-level keys replace, `null` removes the key so the
|
||||
* `config.json` default (or the provider's own default) applies again. Resolves once the
|
||||
* provider has applied the patch; a provider that cannot apply a key live rejects it.
|
||||
*/
|
||||
setOptions(patch: Record<string, unknown>): Promise<void>;
|
||||
/** Sends a prompt and resolves when that turn finishes or needs attention. */
|
||||
run(text: string, options?: PaseoAgentRunOptions): Promise<PaseoAgentRunResult>;
|
||||
/** Waits for the current turn, including one started with `prompt`. */
|
||||
@@ -417,14 +434,21 @@ export interface PaseoAgentActions {
|
||||
|
||||
export type PaseoProviderModelsResult = ListProviderModelsResponseMessage["payload"];
|
||||
export type PaseoProviderModesResult = ListProviderModesResponseMessage["payload"];
|
||||
type PaseoProviderFeaturesDraft = ListProviderFeaturesRequestMessage["draftConfig"];
|
||||
export interface PaseoProviderFeaturesInput extends Omit<
|
||||
PaseoProviderFeaturesDraft,
|
||||
type PaseoProviderControlsDraft = ProviderControlsListRequestMessage["draftConfig"];
|
||||
export interface PaseoProviderControlsInput extends Omit<
|
||||
PaseoProviderControlsDraft,
|
||||
"provider" | "model"
|
||||
> {
|
||||
/** Provider and model in `provider/model` format. */
|
||||
provider: string;
|
||||
}
|
||||
export type PaseoProviderControlsResult = ProviderControlsListResponseMessage["payload"];
|
||||
/** @deprecated Use `PaseoProviderControlsInput`. */
|
||||
export type PaseoProviderFeaturesInput = Omit<
|
||||
ListProviderFeaturesRequestMessage["draftConfig"],
|
||||
"provider" | "model"
|
||||
> & { provider: string };
|
||||
/** @deprecated Use `PaseoProviderControlsResult`. */
|
||||
export type PaseoProviderFeaturesResult = ListProviderFeaturesResponseMessage["payload"];
|
||||
export type PaseoProviderAvailabilityResult = ListAvailableProvidersResponse["payload"];
|
||||
export type PaseoProviderSnapshotResult = GetProvidersSnapshotResponseMessage["payload"];
|
||||
@@ -463,6 +487,15 @@ export interface PaseoProviderActions {
|
||||
provider: PaseoAgentProvider,
|
||||
options?: PaseoProviderListOptions,
|
||||
): Promise<PaseoProviderModesResult>;
|
||||
/**
|
||||
* The controls a draft agent would show and the options it would run with, resolved by the
|
||||
* daemon from `config.json` defaults and the draft's own `providerOptions`.
|
||||
*/
|
||||
listControls(
|
||||
draftConfig: PaseoProviderControlsInput,
|
||||
options?: { requestId?: string },
|
||||
): Promise<PaseoProviderControlsResult>;
|
||||
/** @deprecated Use `listControls`. */
|
||||
listFeatures(
|
||||
draftConfig: PaseoProviderFeaturesInput,
|
||||
options?: { requestId?: string },
|
||||
@@ -547,7 +580,14 @@ function toDaemonAgentCreateOptions(
|
||||
serverId?: string,
|
||||
): CreateAgentRequestOptions {
|
||||
const { config: agentConfig, cwd, parent, title, prompt, ...requestOptions } = options;
|
||||
const { provider: providerModel, options: providerOptions, ...runtimeConfig } = agentConfig;
|
||||
const {
|
||||
provider: providerModel,
|
||||
options: ownOptions,
|
||||
featureValues,
|
||||
...runtimeConfig
|
||||
} = agentConfig;
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01. An explicit option wins.
|
||||
const providerOptions = featureValues ? { ...featureValues, ...ownOptions } : ownOptions;
|
||||
const { provider, model } = parseProviderModel(providerModel);
|
||||
const relationship = parent ? encodeParent(parent, serverId) : {};
|
||||
return {
|
||||
@@ -782,6 +822,10 @@ export function createPaseoApi(
|
||||
const { provider, model } = parseProviderModel(providerModel);
|
||||
return daemonClient.listProviderFeatures({ ...draftConfig, provider, model }, options);
|
||||
},
|
||||
listControls: ({ provider: providerModel, ...draftConfig }, options) => {
|
||||
const { provider, model } = parseProviderModel(providerModel);
|
||||
return daemonClient.listProviderControls({ ...draftConfig, provider, model }, options);
|
||||
},
|
||||
listAvailable: (options) => daemonClient.listAvailableProviders(options),
|
||||
snapshot: (options) => daemonClient.getProvidersSnapshot(options),
|
||||
waitForReady: (options) =>
|
||||
@@ -963,6 +1007,12 @@ function createAgentHandleFactory(
|
||||
get features() {
|
||||
return current?.features ?? null;
|
||||
},
|
||||
get options() {
|
||||
return current?.options ?? null;
|
||||
},
|
||||
get controls() {
|
||||
return current?.controls ?? null;
|
||||
},
|
||||
get runtimeInfo() {
|
||||
return current?.runtimeInfo ?? null;
|
||||
},
|
||||
@@ -984,6 +1034,9 @@ function createAgentHandleFactory(
|
||||
send: async (text, options) => {
|
||||
await daemonClient.sendAgentMessage(id, text, options);
|
||||
},
|
||||
setOptions: async (patch) => {
|
||||
await daemonClient.setAgentOptions(id, patch);
|
||||
},
|
||||
respondToPermission: async ({ requestId, response }) => {
|
||||
await daemonClient.respondToPermission(id, requestId, response);
|
||||
},
|
||||
|
||||
@@ -41,7 +41,6 @@
|
||||
"@types/node": "24.6.0",
|
||||
"@types/ws": "^8.5.14",
|
||||
"electron": "44.2.0",
|
||||
"electron-builder": "26.18.0",
|
||||
"typescript": "5.9.3",
|
||||
"unzip-crx-3": "^0.2.0",
|
||||
"vitest": "^4.1.6",
|
||||
|
||||
@@ -21,7 +21,10 @@ export const AgentProfileSchema = z
|
||||
model: z.string().optional(),
|
||||
modeId: z.string().optional(),
|
||||
thinkingOptionId: z.string().optional(),
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01. Read as `options`.
|
||||
featureValues: z.record(z.string(), z.unknown()).optional(),
|
||||
/** Provider options applied when the profile creates an agent. */
|
||||
options: z.record(z.string(), z.unknown()).optional(),
|
||||
/** Free text, surfaced to orchestrating agents by the `list_profiles` MCP tool. */
|
||||
notes: z.string().optional(),
|
||||
})
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
import type { AgentMessage } from "./agent-message.js";
|
||||
import type { AgentAttachment } from "./messages.js";
|
||||
import type {
|
||||
AgentAttachment,
|
||||
AgentOptionChoiceSchema,
|
||||
AgentOptionControlSchema,
|
||||
AgentOptionSelectControlSchema,
|
||||
AgentOptionToggleControlSchema,
|
||||
} from "./messages.js";
|
||||
import type { z } from "zod";
|
||||
|
||||
export type AgentProvider = string;
|
||||
|
||||
@@ -154,6 +161,20 @@ export interface AgentFeatureSelect {
|
||||
|
||||
export type AgentFeature = AgentFeatureToggle | AgentFeatureSelect;
|
||||
|
||||
export type AgentOptionChoice = z.infer<typeof AgentOptionChoiceSchema>;
|
||||
|
||||
/** `key` is the top-level provider option key the control reads and writes. */
|
||||
export type AgentOptionToggleControl = z.infer<typeof AgentOptionToggleControlSchema>;
|
||||
|
||||
/** `defaultValue` is the choice an unset option stands for. */
|
||||
export type AgentOptionSelectControl = z.infer<typeof AgentOptionSelectControlSchema>;
|
||||
|
||||
/**
|
||||
* A provider's description of a composer control over one top-level option key.
|
||||
* The control carries no value: it is read from the agent's effective options.
|
||||
*/
|
||||
export type AgentOptionControl = z.infer<typeof AgentOptionControlSchema>;
|
||||
|
||||
export interface AgentCapabilityFlags {
|
||||
[capability: string]: boolean | undefined;
|
||||
supportsStreaming: boolean;
|
||||
@@ -523,6 +544,10 @@ export interface AgentSessionConfig {
|
||||
modeId?: string;
|
||||
model?: string;
|
||||
thinkingOptionId?: string;
|
||||
/**
|
||||
* @deprecated COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01.
|
||||
* Folded into `providerOptions` at the daemon's edge; the daemon never reads it internally.
|
||||
*/
|
||||
featureValues?: Record<string, unknown>;
|
||||
title?: string | null;
|
||||
providerOptions?: ProviderOptions;
|
||||
|
||||
@@ -361,6 +361,39 @@ export const AgentFeatureSchema = z.discriminatedUnion("type", [
|
||||
AgentFeatureSelectSchema,
|
||||
]);
|
||||
|
||||
export const AgentOptionChoiceSchema = z.object({
|
||||
value: z.string(),
|
||||
label: z.string(),
|
||||
description: z.string().optional(),
|
||||
});
|
||||
|
||||
export const AgentOptionToggleControlSchema = z.object({
|
||||
type: z.literal("toggle"),
|
||||
key: z.string(),
|
||||
label: z.string(),
|
||||
description: z.string().optional(),
|
||||
tooltip: z.string().optional(),
|
||||
icon: z.string().optional(),
|
||||
defaultValue: z.boolean().optional(),
|
||||
});
|
||||
|
||||
export const AgentOptionSelectControlSchema = z.object({
|
||||
type: z.literal("select"),
|
||||
key: z.string(),
|
||||
label: z.string(),
|
||||
description: z.string().optional(),
|
||||
tooltip: z.string().optional(),
|
||||
icon: z.string().optional(),
|
||||
desktopTrigger: z.enum(["icon", "label"]).optional(),
|
||||
defaultValue: z.string().optional(),
|
||||
choices: z.array(AgentOptionChoiceSchema),
|
||||
});
|
||||
|
||||
export const AgentOptionControlSchema = z.discriminatedUnion("type", [
|
||||
AgentOptionToggleControlSchema,
|
||||
AgentOptionSelectControlSchema,
|
||||
]);
|
||||
|
||||
const AgentModelDefinitionSchema = z.object({
|
||||
provider: AgentProviderSchema,
|
||||
id: z.string(),
|
||||
@@ -490,6 +523,7 @@ const AgentSessionConfigSchema = z.object({
|
||||
modeId: z.string().optional(),
|
||||
model: z.string().optional(),
|
||||
thinkingOptionId: z.string().optional(),
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01. Folded into providerOptions.
|
||||
featureValues: z.record(z.string(), z.unknown()).optional(),
|
||||
title: z.string().trim().min(1).max(MAX_EXPLICIT_AGENT_TITLE_CHARS).optional().nullable(),
|
||||
providerOptions: ProviderOptionsSchema.optional(),
|
||||
@@ -866,7 +900,11 @@ export const AgentSnapshotPayloadSchema = z.object({
|
||||
cwd: z.string(),
|
||||
workspaceId: z.string().optional(),
|
||||
model: z.string().nullable(),
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01. Built from controls + options.
|
||||
features: z.array(AgentFeatureSchema).optional(),
|
||||
/** Effective provider options: `config.json` defaults deep-merged with the agent's own. */
|
||||
options: ProviderOptionsSchema.optional(),
|
||||
controls: z.array(AgentOptionControlSchema).optional(),
|
||||
thinkingOptionId: z.string().nullable().optional(),
|
||||
effectiveThinkingOptionId: z.string().nullable().optional(),
|
||||
createdAt: z.string(),
|
||||
@@ -2076,7 +2114,10 @@ export const AgentConfigApplySchema = z.object({
|
||||
modelId: z.string().nullable().optional(),
|
||||
modeId: z.string().optional(),
|
||||
thinkingOptionId: z.string().nullable().optional(),
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01. Maps to an options patch.
|
||||
featureValues: z.record(z.string(), z.unknown()).optional(),
|
||||
/** Patch of the agent's own options: replaces top-level keys; `null` removes the key. */
|
||||
options: ProviderOptionsSchema.optional(),
|
||||
});
|
||||
|
||||
export type AgentConfigApply = z.infer<typeof AgentConfigApplySchema>;
|
||||
@@ -2992,7 +3033,9 @@ const ListCommandsDraftConfigSchema = z.object({
|
||||
modeId: z.string().optional(),
|
||||
model: z.string().optional(),
|
||||
thinkingOptionId: z.string().optional(),
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01. Folded into providerOptions.
|
||||
featureValues: z.record(z.string(), z.unknown()).optional(),
|
||||
providerOptions: ProviderOptionsSchema.optional(),
|
||||
});
|
||||
|
||||
export const ListProviderFeaturesRequestMessageSchema = z.object({
|
||||
@@ -3001,6 +3044,12 @@ export const ListProviderFeaturesRequestMessageSchema = z.object({
|
||||
requestId: z.string(),
|
||||
});
|
||||
|
||||
export const ProviderControlsListRequestMessageSchema = z.object({
|
||||
type: z.literal("provider.controls.list.request"),
|
||||
draftConfig: ListCommandsDraftConfigSchema,
|
||||
requestId: z.string(),
|
||||
});
|
||||
|
||||
export const ListCommandsRequestSchema = z.object({
|
||||
type: z.literal("list_commands_request"),
|
||||
agentId: z.string(),
|
||||
@@ -3178,6 +3227,7 @@ export const HubExecutionAgentCreateRequestSchema = z.object({
|
||||
model: z.string().optional(),
|
||||
modeId: z.string().optional(),
|
||||
thinkingOptionId: z.string().optional(),
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01. Folded into providerOptions.
|
||||
featureValues: z.record(z.string(), z.unknown()).optional(),
|
||||
providerOptions: ProviderOptionsSchema.optional(),
|
||||
toolPolicy: ToolPolicySchema.optional(),
|
||||
@@ -3380,6 +3430,7 @@ export const SessionInboundMessageSchema = z.discriminatedUnion("type", [
|
||||
ListProviderModelsRequestMessageSchema,
|
||||
ListProviderModesRequestMessageSchema,
|
||||
ListProviderFeaturesRequestMessageSchema,
|
||||
ProviderControlsListRequestMessageSchema,
|
||||
ListAvailableProvidersRequestMessageSchema,
|
||||
GetProvidersSnapshotRequestMessageSchema,
|
||||
RefreshProvidersSnapshotRequestMessageSchema,
|
||||
@@ -3865,6 +3916,7 @@ export const ServerInfoStatusPayloadSchema = z
|
||||
selectiveAgentTimeline: z.boolean().optional(),
|
||||
explicitEventSubscriptions: z.boolean().optional(),
|
||||
ownedSubscriptions: z.boolean().optional(),
|
||||
providerOptionControls: z.boolean().optional(),
|
||||
binaryChunkingV1: z.boolean().optional(),
|
||||
workspaceSetupObservation: z.boolean().optional(),
|
||||
workspaceSortTimes: z.boolean().optional(),
|
||||
@@ -6350,6 +6402,19 @@ export const ListProviderModesResponseMessageSchema = z.object({
|
||||
}),
|
||||
});
|
||||
|
||||
export const ProviderControlsListResponseMessageSchema = z.object({
|
||||
type: z.literal("provider.controls.list.response"),
|
||||
payload: z.object({
|
||||
provider: AgentProviderSchema,
|
||||
controls: z.array(AgentOptionControlSchema).optional(),
|
||||
/** Effective options for the draft: `config.json` defaults merged with the draft's own. */
|
||||
options: ProviderOptionsSchema.optional(),
|
||||
error: z.string().nullable().optional(),
|
||||
fetchedAt: z.string(),
|
||||
requestId: z.string(),
|
||||
}),
|
||||
});
|
||||
|
||||
export const ListProviderFeaturesResponseMessageSchema = z.object({
|
||||
type: z.literal("list_provider_features_response"),
|
||||
payload: z.object({
|
||||
@@ -7262,6 +7327,7 @@ export const SessionOutboundMessageSchema = z.discriminatedUnion("type", [
|
||||
ListProviderModelsResponseMessageSchema,
|
||||
ListProviderModesResponseMessageSchema,
|
||||
ListProviderFeaturesResponseMessageSchema,
|
||||
ProviderControlsListResponseMessageSchema,
|
||||
ListAvailableProvidersResponseSchema,
|
||||
GetProvidersSnapshotResponseMessageSchema,
|
||||
ProvidersSnapshotUpdateMessageSchema,
|
||||
@@ -7519,6 +7585,12 @@ export type ListProviderModelsRequestMessage = z.infer<
|
||||
typeof ListProviderModelsRequestMessageSchema
|
||||
>;
|
||||
export type ListProviderModesRequestMessage = z.infer<typeof ListProviderModesRequestMessageSchema>;
|
||||
export type ProviderControlsListRequestMessage = z.infer<
|
||||
typeof ProviderControlsListRequestMessageSchema
|
||||
>;
|
||||
export type ProviderControlsListResponseMessage = z.infer<
|
||||
typeof ProviderControlsListResponseMessageSchema
|
||||
>;
|
||||
export type ListProviderFeaturesRequestMessage = z.infer<
|
||||
typeof ListProviderFeaturesRequestMessageSchema
|
||||
>;
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
import type {
|
||||
AgentFeature,
|
||||
AgentOptionControl,
|
||||
AgentOptionSelectControl,
|
||||
ProviderOptions,
|
||||
} from "./agent-types.js";
|
||||
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01.
|
||||
// `features` are controls with their value attached. The daemon builds them for apps that
|
||||
// predate controls, and the client package rebuilds controls and options from them when it
|
||||
// talks to a daemon that predates controls. Both directions live here so they stay inverse.
|
||||
|
||||
function selectedChoice(control: AgentOptionSelectControl, options: ProviderOptions) {
|
||||
const value = options[control.key];
|
||||
if (typeof value === "string") {
|
||||
const choice = control.choices.find((candidate) => candidate.value === value);
|
||||
if (choice) return choice.value;
|
||||
}
|
||||
return control.defaultValue ?? null;
|
||||
}
|
||||
|
||||
function describe(control: { description?: string; tooltip?: string; icon?: string }): {
|
||||
description?: string;
|
||||
tooltip?: string;
|
||||
icon?: string;
|
||||
} {
|
||||
return {
|
||||
...(control.description !== undefined ? { description: control.description } : {}),
|
||||
...(control.tooltip !== undefined ? { tooltip: control.tooltip } : {}),
|
||||
...(control.icon !== undefined ? { icon: control.icon } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
function featureFromControl(control: AgentOptionControl, effective: ProviderOptions): AgentFeature {
|
||||
if (control.type === "toggle") {
|
||||
const value = effective[control.key];
|
||||
return {
|
||||
type: "toggle",
|
||||
id: control.key,
|
||||
label: control.label,
|
||||
...describe(control),
|
||||
value: typeof value === "boolean" ? value : (control.defaultValue ?? false),
|
||||
};
|
||||
}
|
||||
return {
|
||||
type: "select",
|
||||
id: control.key,
|
||||
label: control.label,
|
||||
...describe(control),
|
||||
...(control.desktopTrigger ? { desktopTrigger: control.desktopTrigger } : {}),
|
||||
value: selectedChoice(control, effective),
|
||||
options: control.choices.map((choice) => ({
|
||||
id: choice.value,
|
||||
label: choice.label,
|
||||
...(choice.description ? { description: choice.description } : {}),
|
||||
...(choice.value === control.defaultValue ? { isDefault: true } : {}),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
/** Apps that predate controls render `features`; build them from controls + effective options. */
|
||||
export function featuresFromControls(input: {
|
||||
controls: readonly AgentOptionControl[] | undefined;
|
||||
options: ProviderOptions | undefined;
|
||||
}): AgentFeature[] {
|
||||
const { controls, options } = input;
|
||||
const effective = options ?? {};
|
||||
return (controls ?? []).map((control) => featureFromControl(control, effective));
|
||||
}
|
||||
|
||||
/** A recorded feature's value is not carried over: controls hold no state, only `options` do. */
|
||||
function controlFromFeature(feature: AgentFeature): AgentOptionControl {
|
||||
const descriptor = {
|
||||
key: feature.id,
|
||||
label: feature.label,
|
||||
...describe(feature),
|
||||
};
|
||||
if (feature.type === "toggle") {
|
||||
return { type: "toggle", ...descriptor };
|
||||
}
|
||||
const defaultChoice = feature.options.find((option) => option.isDefault);
|
||||
return {
|
||||
type: "select",
|
||||
...descriptor,
|
||||
...(feature.desktopTrigger ? { desktopTrigger: feature.desktopTrigger } : {}),
|
||||
...(defaultChoice ? { defaultValue: defaultChoice.id } : {}),
|
||||
choices: feature.options.map((option) => ({
|
||||
value: option.id,
|
||||
label: option.label,
|
||||
...(option.description ? { description: option.description } : {}),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
/** Agent records and daemons that predate controls carry `features`; their descriptors become controls. */
|
||||
export function controlsFromFeatures(
|
||||
features: readonly AgentFeature[] | undefined,
|
||||
): AgentOptionControl[] {
|
||||
return (features ?? []).map(controlFromFeature);
|
||||
}
|
||||
|
||||
/** The options a list of `features` stands for: each feature's value under its id. */
|
||||
export function optionsFromFeatures(
|
||||
features: readonly AgentFeature[] | undefined,
|
||||
): ProviderOptions {
|
||||
return Object.fromEntries((features ?? []).map((feature) => [feature.id, feature.value]));
|
||||
}
|
||||
@@ -34,6 +34,7 @@ export const ScheduleTargetSchema = z.discriminatedUnion("type", [
|
||||
isolation: z.enum(["local", "worktree"]).optional(),
|
||||
title: z.string().trim().min(1).nullable().optional(),
|
||||
providerOptions: z.record(z.string(), z.unknown()).optional(),
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01. Folded into providerOptions.
|
||||
featureValues: z.record(z.string(), z.unknown()).optional(),
|
||||
systemPrompt: z.string().optional(),
|
||||
mcpServers: z.record(z.string(), z.unknown()).optional(),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
||||
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { expect, test } from "vitest";
|
||||
@@ -17,6 +17,7 @@ import type {
|
||||
AgentSessionConfig,
|
||||
} from "./agent-sdk-types.js";
|
||||
import { createTestAgentClients } from "../test-utils/fake-agent-client.js";
|
||||
import { createDaemonTestContext } from "../test-utils/daemon-test-context.js";
|
||||
|
||||
test("loads archived records for history and active records with the interactive default", async () => {
|
||||
const root = await mkdtemp(path.join(tmpdir(), "agent-loading-purpose-"));
|
||||
@@ -142,60 +143,247 @@ test("resuming a stored agent keeps its unread flag and its last-activity time",
|
||||
}
|
||||
});
|
||||
|
||||
test("loads an archived agent's history after its working directory is removed", async () => {
|
||||
const root = await mkdtemp(path.join(tmpdir(), "agent-loading-missing-cwd-"));
|
||||
const worktree = path.join(root, "managed-worktree");
|
||||
await mkdir(worktree, { recursive: true });
|
||||
const logger = createTestLogger();
|
||||
const storage = new AgentStorage(path.join(root, "agents"), logger);
|
||||
const manager = new AgentManager({
|
||||
clients: createTestAgentClients(),
|
||||
registry: storage,
|
||||
logger,
|
||||
});
|
||||
|
||||
const agentId = "00000000-0000-4000-8000-000000000501";
|
||||
|
||||
try {
|
||||
const agent = await manager.createAgent({ provider: "codex", cwd: worktree }, agentId, {
|
||||
workspaceId: "workspace-worktree",
|
||||
});
|
||||
await startAgentRun(manager, agent.id, "what did you change", logger, {});
|
||||
// Dispatching a run does not finish it: the provider appends the reply to its
|
||||
// history afterwards, and the turn is finalized only once that append lands.
|
||||
// Archive after the turn is finalized so the transcript this test reads back is
|
||||
// already on disk when the worktree goes away.
|
||||
const finished = await manager.waitForAgentEvent(agent.id);
|
||||
expect(finished.status).toBe("idle");
|
||||
await manager.archiveAgent(agent.id);
|
||||
await manager.closeAgent(agent.id);
|
||||
await manager.flush();
|
||||
await storage.flush();
|
||||
|
||||
// Archiving the workspace removes the worktree it owned. The agent's history is
|
||||
// persisted and reading it must not depend on that directory still being there.
|
||||
await rm(worktree, { recursive: true, force: true });
|
||||
|
||||
const loaded = await ensureAgentLoaded(agentId, {
|
||||
agentManager: manager,
|
||||
agentStorage: storage,
|
||||
test.each([false, true])(
|
||||
"loads history after its working directory is removed (archived: %s)",
|
||||
async (archived) => {
|
||||
const root = await mkdtemp(path.join(tmpdir(), "agent-loading-missing-cwd-"));
|
||||
const worktree = path.join(root, "managed-worktree");
|
||||
await mkdir(worktree, { recursive: true });
|
||||
const logger = createTestLogger();
|
||||
const storage = new AgentStorage(path.join(root, "agents"), logger);
|
||||
const manager = new AgentManager({
|
||||
clients: createTestAgentClients(),
|
||||
registry: storage,
|
||||
logger,
|
||||
});
|
||||
|
||||
expect(loaded.id).toBe(agentId);
|
||||
// The transcript is replayed from the provider's persisted history, so the reply the
|
||||
// agent gave before the worktree went away is still readable.
|
||||
const replies = manager
|
||||
.getTimeline(agentId)
|
||||
.filter((item) => item.type === "assistant_message");
|
||||
expect(replies.length).toBeGreaterThan(0);
|
||||
expect(replies.every((item) => item.type === "assistant_message" && item.text.length > 0)).toBe(
|
||||
true,
|
||||
const agentId = "00000000-0000-4000-8000-000000000501";
|
||||
|
||||
try {
|
||||
const agent = await manager.createAgent({ provider: "codex", cwd: worktree }, agentId, {
|
||||
workspaceId: "workspace-worktree",
|
||||
});
|
||||
await startAgentRun(manager, agent.id, "what did you change", logger, {});
|
||||
// Dispatching a run does not finish it: the provider appends the reply to its
|
||||
// history afterwards, and the turn is finalized only once that append lands.
|
||||
// Archive after the turn is finalized so the transcript this test reads back is
|
||||
// already on disk when the worktree goes away.
|
||||
const finished = await manager.waitForAgentEvent(agent.id);
|
||||
expect(finished.status).toBe("idle");
|
||||
if (archived) await manager.archiveAgent(agent.id);
|
||||
await manager.closeAgent(agent.id);
|
||||
await manager.flush();
|
||||
await storage.flush();
|
||||
|
||||
// Archiving the workspace removes the worktree it owned. The agent's history is
|
||||
// persisted and reading it must not depend on that directory still being there.
|
||||
await rm(worktree, { recursive: true, force: true });
|
||||
|
||||
const loaded = await ensureAgentLoaded(agentId, {
|
||||
agentManager: manager,
|
||||
agentStorage: storage,
|
||||
logger,
|
||||
purpose: "history",
|
||||
});
|
||||
|
||||
expect(loaded.id).toBe(agentId);
|
||||
// The transcript is replayed from the provider's persisted history, so the reply the
|
||||
// agent gave before the worktree went away is still readable.
|
||||
const replies = manager
|
||||
.getTimeline(agentId)
|
||||
.filter((item) => item.type === "assistant_message");
|
||||
expect(replies.length).toBeGreaterThan(0);
|
||||
expect(
|
||||
replies.every((item) => item.type === "assistant_message" && item.text.length > 0),
|
||||
).toBe(true);
|
||||
} finally {
|
||||
await manager.closeAgent(agentId).catch(() => undefined);
|
||||
await manager.flush().catch(() => undefined);
|
||||
await storage.flush().catch(() => undefined);
|
||||
await rm(root, { recursive: true, force: true });
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
test("timeline requests read unarchived stored history with a deleted cwd", async () => {
|
||||
const ctx = await createDaemonTestContext();
|
||||
const cwd = await mkdtemp(path.join(tmpdir(), "timeline-deleted-cwd-"));
|
||||
try {
|
||||
const agent = await ctx.client.createAgent({ provider: "codex", cwd });
|
||||
await ctx.client.sendMessage(agent.id, "remember this conversation");
|
||||
await ctx.client.waitForFinish(agent.id, 15000);
|
||||
const before = await ctx.client.fetchAgentTimeline(agent.id);
|
||||
await ctx.daemon.daemon.agentManager.closeAgent(agent.id);
|
||||
await ctx.daemon.daemon.agentManager.flush();
|
||||
await rm(cwd, { recursive: true, force: true });
|
||||
const after = await ctx.client.fetchAgentTimeline(agent.id);
|
||||
expect(after.entries).toEqual(before.entries);
|
||||
expect(after.entries.length).toBeGreaterThan(0);
|
||||
await expect(ctx.client.sendMessage(agent.id, "continue")).rejects.toThrow(
|
||||
"Working directory does not exist",
|
||||
);
|
||||
await expect(ctx.client.createAgent({ provider: "codex", cwd })).rejects.toThrow(
|
||||
"Working directory does not exist",
|
||||
);
|
||||
await mkdir(cwd);
|
||||
await ctx.client.sendMessage(agent.id, "continue after restoring directory");
|
||||
expect((await ctx.client.waitForFinish(agent.id, 15000)).status).toBe("idle");
|
||||
} finally {
|
||||
await manager.closeAgent(agentId).catch(() => undefined);
|
||||
await manager.flush().catch(() => undefined);
|
||||
await storage.flush().catch(() => undefined);
|
||||
await rm(root, { recursive: true, force: true });
|
||||
await ctx.cleanup();
|
||||
await rm(cwd, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
}, 30000);
|
||||
|
||||
test("timeline reads keep runnable unarchived agents interactive for the next prompt", async () => {
|
||||
const clients = createTestAgentClients();
|
||||
const base = clients.codex!;
|
||||
const purposes: Array<AgentResumeSessionOptions | undefined> = [];
|
||||
const client: AgentClient = {
|
||||
provider: base.provider,
|
||||
capabilities: base.capabilities,
|
||||
createSession: (config, context) => base.createSession(config, context),
|
||||
resumeSession: (handle, overrides, context, options) => {
|
||||
purposes.push(options);
|
||||
return base.resumeSession(handle, overrides, context, options);
|
||||
},
|
||||
fetchCatalog: (options) => base.fetchCatalog(options),
|
||||
isAvailable: () => base.isAvailable(),
|
||||
};
|
||||
const ctx = await createDaemonTestContext({ agentClients: { codex: client } });
|
||||
const cwd = await mkdtemp(path.join(tmpdir(), "timeline-interactive-"));
|
||||
try {
|
||||
const agent = await ctx.client.createAgent({ provider: "codex", cwd });
|
||||
await ctx.daemon.daemon.agentManager.closeAgent(agent.id);
|
||||
await ctx.client.fetchAgentTimeline(agent.id);
|
||||
expect(purposes).toEqual([{ purpose: "interactive" }]);
|
||||
await ctx.client.sendMessage(agent.id, "continue after opening history");
|
||||
expect((await ctx.client.waitForFinish(agent.id, 15000)).status).toBe("idle");
|
||||
const timeline = await ctx.client.fetchAgentTimeline(agent.id);
|
||||
expect(timeline.entries.length).toBeGreaterThan(0);
|
||||
await ctx.daemon.daemon.agentManager.closeAgent(agent.id);
|
||||
await rm(cwd, { recursive: true, force: true });
|
||||
await ctx.client.fetchAgentTimeline(agent.id);
|
||||
await mkdir(cwd);
|
||||
const manager = ctx.daemon.daemon.agentManager;
|
||||
await Promise.all([
|
||||
manager.tryRunOutOfBand(agent.id, "first prompt"),
|
||||
manager.tryRunOutOfBand(agent.id, "second prompt"),
|
||||
]);
|
||||
expect(purposes).toEqual([
|
||||
{ purpose: "interactive" },
|
||||
{ purpose: "history" },
|
||||
undefined, // Reload uses the provider's interactive default.
|
||||
]);
|
||||
} finally {
|
||||
await ctx.cleanup();
|
||||
await rm(cwd, { recursive: true, force: true });
|
||||
}
|
||||
}, 30000);
|
||||
|
||||
test.each(["mode", "thinking", "rewind"])(
|
||||
"restored OMP history accepts %s before starting an interactive turn",
|
||||
async (setting) => {
|
||||
const { OmpAgentClient } = await import("./providers/omp/agent.js");
|
||||
const { FakeOmp } = await import("./providers/omp/test-utils/fake-omp.js");
|
||||
const { sendPreparedPromptToAgent } = await import("./agent-prompt.js");
|
||||
const root = await mkdtemp(path.join(tmpdir(), "history-mode-"));
|
||||
const cwd = path.join(root, "removed-worktree");
|
||||
const sessionFile = path.join(root, "session.jsonl");
|
||||
await writeFile(
|
||||
sessionFile,
|
||||
[
|
||||
{ type: "session", id: "root", parentId: null },
|
||||
{
|
||||
type: "message",
|
||||
id: "user-1",
|
||||
parentId: "root",
|
||||
message: { role: "user", content: "saved question" },
|
||||
},
|
||||
]
|
||||
.map((entry) => JSON.stringify(entry))
|
||||
.join("\n") + "\n",
|
||||
);
|
||||
const logger = createTestLogger();
|
||||
const storage = new AgentStorage(path.join(root, "agents"), logger);
|
||||
const runtime = new FakeOmp();
|
||||
const manager = new AgentManager({
|
||||
clients: {
|
||||
omp: new OmpAgentClient({
|
||||
logger,
|
||||
runtime,
|
||||
runtimeSettings: { command: { mode: "replace", argv: [process.execPath] } },
|
||||
}),
|
||||
},
|
||||
registry: storage,
|
||||
logger,
|
||||
});
|
||||
const agentId = "00000000-0000-4000-8000-000000000601";
|
||||
const now = new Date().toISOString();
|
||||
try {
|
||||
await storage.upsert({
|
||||
id: agentId,
|
||||
provider: "omp",
|
||||
cwd,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
labels: {},
|
||||
lastStatus: "closed",
|
||||
archivedAt: null,
|
||||
persistence: {
|
||||
provider: "omp",
|
||||
sessionId: "history-mode",
|
||||
nativeHandle: sessionFile,
|
||||
metadata: { cwd },
|
||||
},
|
||||
});
|
||||
await ensureAgentLoaded(agentId, {
|
||||
agentManager: manager,
|
||||
agentStorage: storage,
|
||||
logger,
|
||||
purpose: "history",
|
||||
});
|
||||
expect(
|
||||
runtime.recordedLaunches.filter((launch) => launch.session === sessionFile),
|
||||
).toHaveLength(0);
|
||||
await mkdir(cwd);
|
||||
if (setting === "rewind") {
|
||||
await manager.rewind(agentId, "user-1", "conversation");
|
||||
expect(runtime.latestSession().branchRequests).toEqual(["user-1"]);
|
||||
}
|
||||
if (setting === "thinking") {
|
||||
await manager.setAgentThinkingOption(agentId, "high");
|
||||
expect(manager.getAgent(agentId)?.config.thinkingOptionId).toBe("high");
|
||||
expect(runtime.latestSession().setThinkingLevelRequests).toContain("high");
|
||||
}
|
||||
await sendPreparedPromptToAgent({
|
||||
agentManager: manager,
|
||||
agentStorage: storage,
|
||||
agentId,
|
||||
logger,
|
||||
prompt: "continue",
|
||||
sessionMode: "full",
|
||||
});
|
||||
expect(
|
||||
runtime.recordedLaunches.filter((launch) => launch.session === sessionFile),
|
||||
).toHaveLength(1);
|
||||
expect(manager.getAgent(agentId)?.currentModeId).toBe("full");
|
||||
expect(runtime.latestSession().prompts).toEqual([
|
||||
expect.objectContaining({ message: "continue" }),
|
||||
]);
|
||||
runtime.latestSession().finishTurn();
|
||||
await manager.waitForAgentEvent(agentId);
|
||||
await manager.archiveAgent(agentId);
|
||||
await manager.closeAgent(agentId);
|
||||
await ensureAgentLoaded(agentId, { agentManager: manager, agentStorage: storage, logger });
|
||||
const launchesBeforeModeChange = runtime.recordedLaunches.length;
|
||||
await expect(manager.setAgentMode(agentId, "full")).rejects.toThrow("Agent is archived");
|
||||
expect(runtime.recordedLaunches).toHaveLength(launchesBeforeModeChange);
|
||||
} finally {
|
||||
await manager.closeAgent(agentId).catch(() => undefined);
|
||||
await manager.flush();
|
||||
await storage.flush();
|
||||
await rm(root, { recursive: true, force: true });
|
||||
}
|
||||
},
|
||||
30000,
|
||||
);
|
||||
|
||||
@@ -41,6 +41,7 @@ export interface EnsureAgentLoadedDeps {
|
||||
agentStorage: AgentStorage;
|
||||
validProviders?: Iterable<AgentProvider>;
|
||||
broadcastTimeline?: boolean;
|
||||
purpose?: "history" | "interactive";
|
||||
logger: Logger;
|
||||
}
|
||||
|
||||
@@ -118,7 +119,7 @@ export async function ensureAgentLoaded(
|
||||
buildConfigOverrides(record),
|
||||
agentId,
|
||||
{ ...extractTimestamps(record), attention: extractAttention(record) },
|
||||
record.archivedAt ? { purpose: "history" } : undefined,
|
||||
deps.purpose ? { purpose: deps.purpose } : undefined,
|
||||
);
|
||||
deps.logger.info({ agentId, provider: record.provider }, "Agent resumed from persistence");
|
||||
} else {
|
||||
|
||||
@@ -23,6 +23,7 @@ import { AgentStorage } from "./agent-storage.js";
|
||||
import { InMemoryAgentTimelineStore } from "./agent-timeline-store.js";
|
||||
import { limitAgentTimelineItemContent } from "./agent-timeline-content.js";
|
||||
import { toAgentPayload } from "./agent-projections.js";
|
||||
import type { ProviderOptions } from "@getpaseo/protocol/agent-types";
|
||||
import { projectTimelineRows } from "./timeline-projection.js";
|
||||
import { getOpenAgentTabLabel, PARENT_AGENT_ID_LABEL } from "@getpaseo/protocol/agent-labels";
|
||||
import { startAgentRun } from "./agent-prompt.js";
|
||||
@@ -38,7 +39,7 @@ import type {
|
||||
import type {
|
||||
AgentClient,
|
||||
AgentCreateSessionOptions,
|
||||
AgentFeature,
|
||||
AgentOptionControl,
|
||||
AgentLaunchContext,
|
||||
AgentPromptInput,
|
||||
AgentProvider,
|
||||
@@ -57,6 +58,7 @@ import type {
|
||||
} from "./agent-sdk-types.js";
|
||||
import type { PaseoToolCatalog } from "./tools/types.js";
|
||||
import type { ProviderDefinition } from "./provider-registry.js";
|
||||
import { mergeProviderOptions } from "./provider-options.js";
|
||||
|
||||
import { OpenCodeV2AgentClient } from "./providers/opencode/v2/agent.js";
|
||||
import { V2Harness } from "./providers/opencode/test-utils/v2-harness.js";
|
||||
@@ -185,13 +187,8 @@ class RecordingTimelineStore implements AgentTimelineStore {
|
||||
}
|
||||
}
|
||||
|
||||
function createFeature(args: { id: string; label: string; value: boolean }): AgentFeature {
|
||||
return {
|
||||
type: "toggle",
|
||||
id: args.id,
|
||||
label: args.label,
|
||||
value: args.value,
|
||||
};
|
||||
function createControl(args: { key: string; label: string }): AgentOptionControl {
|
||||
return { type: "toggle", key: args.key, label: args.label };
|
||||
}
|
||||
|
||||
function expectArchivedAgentRecord(
|
||||
@@ -2362,7 +2359,7 @@ test("listDraftCommands uses explicit model config without default model fetchin
|
||||
]);
|
||||
});
|
||||
|
||||
test("listDraftFeatures does not start a fallback session without a model", async () => {
|
||||
test("listDraftControls does not start a fallback session without a model", async () => {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-draft-features-"));
|
||||
const storagePath = join(workdir, "agents");
|
||||
const storage = new AgentStorage(storagePath, logger);
|
||||
@@ -2395,18 +2392,21 @@ test("listDraftFeatures does not start a fallback session without a model", asyn
|
||||
logger,
|
||||
});
|
||||
|
||||
await expect(manager.listDraftFeatures({ provider: "codex", cwd: workdir })).resolves.toEqual([]);
|
||||
await expect(manager.listDraftControls({ provider: "codex", cwd: workdir })).resolves.toEqual({
|
||||
controls: [],
|
||||
options: {},
|
||||
});
|
||||
|
||||
expect(client.fetchCatalogCalls).toBe(0);
|
||||
expect(client.createSessionCalls).toBe(0);
|
||||
expect(client.availabilityCalls).toBe(0);
|
||||
});
|
||||
|
||||
test("listDraftFeatures uses client feature listing without a model", async () => {
|
||||
test("listDraftControls uses client feature listing without a model", async () => {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-draft-features-"));
|
||||
const storagePath = join(workdir, "agents");
|
||||
const storage = new AgentStorage(storagePath, logger);
|
||||
const draftFeature = createFeature({ id: "auto_accept", label: "Auto Accept", value: false });
|
||||
const draftControl = createControl({ key: "auto_accept", label: "Auto Accept" });
|
||||
class DraftFeatureClient extends TestAgentClient {
|
||||
fetchCatalogCalls = 0;
|
||||
createSessionCalls = 0;
|
||||
@@ -2428,9 +2428,9 @@ test("listDraftFeatures uses client feature listing without a model", async () =
|
||||
return await super.createSession(config);
|
||||
}
|
||||
|
||||
async listFeatures(config: AgentSessionConfig): Promise<AgentFeature[]> {
|
||||
async listControls(config: AgentSessionConfig): Promise<AgentOptionControl[]> {
|
||||
this.featureConfigs.push(config);
|
||||
return [draftFeature];
|
||||
return [draftControl];
|
||||
}
|
||||
}
|
||||
const client = new DraftFeatureClient();
|
||||
@@ -2442,9 +2442,13 @@ test("listDraftFeatures uses client feature listing without a model", async () =
|
||||
logger,
|
||||
});
|
||||
|
||||
await expect(manager.listDraftFeatures({ provider: "codex", cwd: workdir })).resolves.toEqual([
|
||||
draftFeature,
|
||||
]);
|
||||
await expect(
|
||||
manager.listDraftControls({
|
||||
provider: "codex",
|
||||
cwd: workdir,
|
||||
providerOptions: { auto_accept: true },
|
||||
}),
|
||||
).resolves.toEqual({ controls: [draftControl], options: { auto_accept: true } });
|
||||
|
||||
expect(client.fetchCatalogCalls).toBe(0);
|
||||
expect(client.createSessionCalls).toBe(0);
|
||||
@@ -2453,15 +2457,28 @@ test("listDraftFeatures uses client feature listing without a model", async () =
|
||||
{
|
||||
provider: "codex",
|
||||
cwd: workdir,
|
||||
providerOptions: { auto_accept: true },
|
||||
},
|
||||
]);
|
||||
|
||||
// Options without a control come back too.
|
||||
await expect(
|
||||
manager.listDraftControls({
|
||||
provider: "codex",
|
||||
cwd: workdir,
|
||||
providerOptions: { auto_accept: true, sandbox_mode: "workspace-write" },
|
||||
}),
|
||||
).resolves.toEqual({
|
||||
controls: [draftControl],
|
||||
options: { auto_accept: true, sandbox_mode: "workspace-write" },
|
||||
});
|
||||
});
|
||||
|
||||
test("listDraftFeatures uses explicit model config without default model fetching", async () => {
|
||||
test("listDraftControls uses explicit model config without default model fetching", async () => {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-draft-features-"));
|
||||
const storagePath = join(workdir, "agents");
|
||||
const storage = new AgentStorage(storagePath, logger);
|
||||
const draftFeature = createFeature({ id: "fast_mode", label: "Fast mode", value: false });
|
||||
const draftControl = createControl({ key: "web_search", label: "Fast mode" });
|
||||
class DraftFeatureClient extends TestAgentClient {
|
||||
fetchCatalogCalls = 0;
|
||||
createSessionCalls = 0;
|
||||
@@ -2477,9 +2494,9 @@ test("listDraftFeatures uses explicit model config without default model fetchin
|
||||
return await super.createSession(config);
|
||||
}
|
||||
|
||||
async listFeatures(config: AgentSessionConfig): Promise<AgentFeature[]> {
|
||||
async listControls(config: AgentSessionConfig): Promise<AgentOptionControl[]> {
|
||||
this.featureConfigs.push(config);
|
||||
return [draftFeature];
|
||||
return [draftControl];
|
||||
}
|
||||
}
|
||||
const client = new DraftFeatureClient();
|
||||
@@ -2491,13 +2508,13 @@ test("listDraftFeatures uses explicit model config without default model fetchin
|
||||
logger,
|
||||
});
|
||||
|
||||
const features = await manager.listDraftFeatures({
|
||||
const draft = await manager.listDraftControls({
|
||||
provider: "codex",
|
||||
cwd: workdir,
|
||||
model: "gpt-5.4",
|
||||
});
|
||||
|
||||
expect(features).toEqual([draftFeature]);
|
||||
expect(draft).toEqual({ controls: [draftControl], options: {} });
|
||||
expect(client.fetchCatalogCalls).toBe(0);
|
||||
expect(client.createSessionCalls).toBe(0);
|
||||
expect(client.featureConfigs).toEqual([
|
||||
@@ -4092,7 +4109,7 @@ test("createAgent rejects a disabled provider without creating a session", async
|
||||
),
|
||||
).rejects.toThrow("Provider 'codex' is disabled");
|
||||
expect(disabledClient.createSessionCalls).toBe(0);
|
||||
expect(await storage.list()).toHaveLength(0);
|
||||
expect(await storage.listAll()).toHaveLength(0);
|
||||
});
|
||||
|
||||
test("updateProviderRegistry re-enables a previously disabled provider", async () => {
|
||||
@@ -4580,6 +4597,46 @@ test("resumeAgentFromPersistence keeps metadata config, applies overrides, and p
|
||||
});
|
||||
});
|
||||
|
||||
test("importProviderSession reports the defaults the session launched with, not defaults edited during the import", async () => {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-import-options-"));
|
||||
let tier = "default";
|
||||
class ImportClient extends TestAgentClient {
|
||||
effectiveOptions(own: ProviderOptions | undefined): ProviderOptions {
|
||||
return { service_tier: tier, ...own };
|
||||
}
|
||||
|
||||
async importSession(input: ImportProviderSessionInput) {
|
||||
// The user edits the default in config.json after the provider has launched.
|
||||
tier = "fast";
|
||||
return {
|
||||
session: new TestAgentSession({ provider: "codex", cwd: workdir }),
|
||||
config: { provider: "codex" as const, cwd: workdir },
|
||||
persistence: {
|
||||
provider: "codex" as const,
|
||||
sessionId: input.providerHandleId,
|
||||
nativeHandle: input.providerHandleId,
|
||||
metadata: { provider: "codex", cwd: workdir },
|
||||
},
|
||||
timeline: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
const manager = new AgentManager({
|
||||
clients: { codex: new ImportClient() },
|
||||
registry: new AgentStorage(join(workdir, "agents"), logger),
|
||||
logger,
|
||||
});
|
||||
|
||||
const imported = await manager.importProviderSession({
|
||||
provider: "codex",
|
||||
providerHandleId: "thread-selected",
|
||||
cwd: workdir,
|
||||
workspaceId: "ws-imported",
|
||||
});
|
||||
|
||||
expect(imported.effectiveOptions).toEqual({ service_tier: "default" });
|
||||
});
|
||||
|
||||
test("importProviderSession imports the selected session without listing and publishes ready state", async () => {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-import-session-"));
|
||||
const storagePath = join(workdir, "agents");
|
||||
@@ -8273,7 +8330,7 @@ test("archiveAgent closes an internal agent without writing a record", async ()
|
||||
expect(Number.isNaN(Date.parse(archivedAt))).toBe(false);
|
||||
expect(manager.getAgent(internalAgentId)).toBeNull();
|
||||
expect(await storage.get(internalAgentId)).toBeNull();
|
||||
expect(await storage.list()).toEqual([]);
|
||||
expect(await storage.listAll()).toEqual([]);
|
||||
expect(manager.getRetiredInternalAgent(internalAgentId)).toEqual({
|
||||
record: expect.objectContaining({
|
||||
id: internalAgentId,
|
||||
@@ -9379,8 +9436,8 @@ test("archiveAgent re-reads a child before deciding whether to cascade", async (
|
||||
class ChildOpensAfterCascadeListStorage extends AgentStorage {
|
||||
childId: string | null = null;
|
||||
|
||||
override async list(): Promise<StoredAgentRecord[]> {
|
||||
const records = await super.list();
|
||||
override async listActive(): Promise<StoredAgentRecord[]> {
|
||||
const records = await super.listAll();
|
||||
const parentIsArchived = records.some(
|
||||
(record) => record.id !== this.childId && Boolean(record.archivedAt),
|
||||
);
|
||||
@@ -10127,16 +10184,13 @@ test("respondToPermission updates currentModeId after plan approval", async () =
|
||||
expect(client.resumedModeId).toBe("acceptEdits");
|
||||
});
|
||||
|
||||
test("respondToPermission refreshes features and runtime info after provider-managed plan approval", async () => {
|
||||
test("respondToPermission applies provider option changes and refreshes runtime info after provider-managed plan approval", async () => {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-test-"));
|
||||
const storagePath = join(workdir, "agents");
|
||||
const storage = new AgentStorage(storagePath, logger);
|
||||
|
||||
class RefreshingPermissionSession extends TestAgentSession {
|
||||
private featureState: AgentFeature[] = [
|
||||
createFeature({ id: "fast_mode", label: "Fast", value: true }),
|
||||
createFeature({ id: "plan_mode", label: "Plan", value: true }),
|
||||
];
|
||||
private planMode = true;
|
||||
private modeId = "auto";
|
||||
private pending = [
|
||||
{
|
||||
@@ -10148,8 +10202,11 @@ test("respondToPermission refreshes features and runtime info after provider-man
|
||||
},
|
||||
];
|
||||
|
||||
get features(): AgentFeature[] {
|
||||
return this.featureState;
|
||||
get controls(): AgentOptionControl[] {
|
||||
return [
|
||||
createControl({ key: "web_search", label: "Fast" }),
|
||||
createControl({ key: "plan_mode", label: "Plan" }),
|
||||
];
|
||||
}
|
||||
|
||||
override async getRuntimeInfo() {
|
||||
@@ -10158,7 +10215,7 @@ test("respondToPermission refreshes features and runtime info after provider-man
|
||||
sessionId: this.id,
|
||||
model: "gpt-5.4",
|
||||
modeId: this.modeId,
|
||||
extra: { collaborationMode: this.features[1]?.value ? "Plan" : "Code" },
|
||||
extra: { collaborationMode: this.planMode ? "Plan" : "Code" },
|
||||
};
|
||||
}
|
||||
|
||||
@@ -10173,10 +10230,12 @@ test("respondToPermission refreshes features and runtime info after provider-man
|
||||
override async respondToPermission(): Promise<void> {
|
||||
this.modeId = "auto";
|
||||
this.pending = [];
|
||||
this.featureState = [
|
||||
createFeature({ id: "fast_mode", label: "Fast", value: true }),
|
||||
createFeature({ id: "plan_mode", label: "Plan", value: false }),
|
||||
];
|
||||
this.planMode = false;
|
||||
this.pushEvent({
|
||||
type: "options_changed",
|
||||
provider: this.provider,
|
||||
patch: { plan_mode: false },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10199,6 +10258,7 @@ test("respondToPermission refreshes features and runtime info after provider-man
|
||||
{
|
||||
provider: "codex",
|
||||
cwd: workdir,
|
||||
providerOptions: { web_search: true, plan_mode: true },
|
||||
},
|
||||
undefined,
|
||||
{ workspaceId: undefined },
|
||||
@@ -10223,20 +10283,14 @@ test("respondToPermission refreshes features and runtime info after provider-man
|
||||
|
||||
const updated = manager.getAgent(snapshot.id);
|
||||
expect(updated?.pendingPermissions.size).toBe(0);
|
||||
expect(updated?.features).toEqual([
|
||||
createFeature({ id: "fast_mode", label: "Fast", value: true }),
|
||||
createFeature({ id: "plan_mode", label: "Plan", value: false }),
|
||||
]);
|
||||
expect(updated?.effectiveOptions).toEqual({ web_search: true, plan_mode: false });
|
||||
expect(updated?.runtimeInfo).toMatchObject({
|
||||
model: "gpt-5.4",
|
||||
extra: { collaborationMode: "Code" },
|
||||
});
|
||||
|
||||
const persisted = await storage.get(snapshot.id);
|
||||
expect(persisted?.features).toEqual([
|
||||
createFeature({ id: "fast_mode", label: "Fast", value: true }),
|
||||
createFeature({ id: "plan_mode", label: "Plan", value: false }),
|
||||
]);
|
||||
expect(persisted?.config?.providerOptions).toEqual({ web_search: true, plan_mode: false });
|
||||
});
|
||||
|
||||
test("respondToPermission emits refreshed state before permission_resolved", async () => {
|
||||
@@ -10245,9 +10299,6 @@ test("respondToPermission emits refreshed state before permission_resolved", asy
|
||||
const storage = new AgentStorage(storagePath, logger);
|
||||
|
||||
class OrderedPermissionSession extends TestAgentSession {
|
||||
private featureState: AgentFeature[] = [
|
||||
createFeature({ id: "fast_mode", label: "Fast", value: true }),
|
||||
];
|
||||
private modeId = "plan";
|
||||
private pending = [
|
||||
{
|
||||
@@ -10259,8 +10310,8 @@ test("respondToPermission emits refreshed state before permission_resolved", asy
|
||||
},
|
||||
];
|
||||
|
||||
get features(): AgentFeature[] {
|
||||
return this.featureState;
|
||||
get controls(): AgentOptionControl[] {
|
||||
return [createControl({ key: "web_search", label: "Fast" })];
|
||||
}
|
||||
|
||||
override async getRuntimeInfo() {
|
||||
@@ -10281,6 +10332,11 @@ test("respondToPermission emits refreshed state before permission_resolved", asy
|
||||
}
|
||||
|
||||
override async respondToPermission(): Promise<void> {
|
||||
this.pushEvent({
|
||||
type: "options_changed",
|
||||
provider: this.provider,
|
||||
patch: { web_search: false },
|
||||
});
|
||||
this.pushEvent({
|
||||
type: "permission_resolved",
|
||||
provider: this.provider,
|
||||
@@ -10288,7 +10344,6 @@ test("respondToPermission emits refreshed state before permission_resolved", asy
|
||||
resolution: { behavior: "allow" },
|
||||
});
|
||||
this.modeId = "acceptEdits";
|
||||
this.featureState = [createFeature({ id: "fast_mode", label: "Fast", value: false })];
|
||||
this.pending = [];
|
||||
}
|
||||
}
|
||||
@@ -10312,6 +10367,7 @@ test("respondToPermission emits refreshed state before permission_resolved", asy
|
||||
{
|
||||
provider: "codex",
|
||||
cwd: workdir,
|
||||
providerOptions: { web_search: true },
|
||||
},
|
||||
undefined,
|
||||
{ workspaceId: undefined },
|
||||
@@ -10323,9 +10379,8 @@ test("respondToPermission emits refreshed state before permission_resolved", asy
|
||||
return;
|
||||
}
|
||||
if (event.type === "agent_state" && event.agent.id === snapshot.id) {
|
||||
const fastMode = event.agent.features?.find((feature) => feature.id === "fast_mode");
|
||||
seen.push(
|
||||
`state:${event.agent.currentModeId}:${String(fastMode?.type === "toggle" ? fastMode.value : null)}`,
|
||||
`state:${event.agent.currentModeId}:${String(event.agent.effectiveOptions?.web_search)}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -12920,3 +12975,478 @@ test("an out-of-band command racing idle cleanup waits for the resumed runtime",
|
||||
expect(h.commands).toEqual(["/maintenance"]);
|
||||
expect(h.prompts).toEqual([]);
|
||||
});
|
||||
|
||||
describe("agent options", () => {
|
||||
class OptionsSession extends TestAgentSession {
|
||||
readonly applied: ProviderOptions[] = [];
|
||||
rejectWith: Error | null = null;
|
||||
applyGate: Promise<void> | null = null;
|
||||
/** What the session says it ended up with after the next apply. */
|
||||
ended: Record<string, unknown> = {};
|
||||
openOptionsPatch: Record<string, unknown> = {};
|
||||
|
||||
async applyOptions(options: ProviderOptions): Promise<Record<string, unknown>> {
|
||||
if (this.rejectWith) throw this.rejectWith;
|
||||
await this.applyGate;
|
||||
this.applied.push(options);
|
||||
return this.ended;
|
||||
}
|
||||
}
|
||||
|
||||
class OptionsClient extends TestAgentClient {
|
||||
session: OptionsSession | null = null;
|
||||
openOptionsPatch: Record<string, unknown> = {};
|
||||
|
||||
// Stands in for the `config.json` provider defaults the registry wrapper merges in.
|
||||
effectiveOptions(own: ProviderOptions | undefined): ProviderOptions {
|
||||
return { service_tier: "default", ...own };
|
||||
}
|
||||
|
||||
override async createSession(config: AgentSessionConfig): Promise<AgentSession> {
|
||||
this.session = new OptionsSession(config);
|
||||
this.session.openOptionsPatch = this.openOptionsPatch;
|
||||
return this.session;
|
||||
}
|
||||
}
|
||||
|
||||
async function createOptionsAgent(
|
||||
providerOptions?: ProviderOptions,
|
||||
openOptionsPatch: Record<string, unknown> = {},
|
||||
) {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-options-"));
|
||||
const storage = new AgentStorage(join(workdir, "agents"), logger);
|
||||
const client = new OptionsClient();
|
||||
client.openOptionsPatch = openOptionsPatch;
|
||||
const manager = new AgentManager({ clients: { codex: client }, registry: storage, logger });
|
||||
const agent = await manager.createAgent(
|
||||
{ provider: "codex", cwd: workdir, ...(providerOptions ? { providerOptions } : {}) },
|
||||
undefined,
|
||||
{ workspaceId: undefined },
|
||||
);
|
||||
return { manager, client, storage, agentId: agent.id };
|
||||
}
|
||||
|
||||
test("config.json defaults show as effective options without entering the agent's own options", async () => {
|
||||
const { manager, agentId } = await createOptionsAgent({ web_search: true });
|
||||
|
||||
const agent = manager.getAgent(agentId);
|
||||
expect(agent?.config.providerOptions).toEqual({ web_search: true });
|
||||
expect(agent?.effectiveOptions).toEqual({ service_tier: "default", web_search: true });
|
||||
expect(toAgentPayload(agent!).options).toEqual({ service_tier: "default", web_search: true });
|
||||
});
|
||||
|
||||
test("setAgentOptions hands the provider only the keys the patch sets", async () => {
|
||||
const { manager, client, storage, agentId } = await createOptionsAgent({ web_search: true });
|
||||
|
||||
await manager.setAgentOptions(agentId, { service_tier: "fast" });
|
||||
|
||||
expect(client.session?.applied).toEqual([{ service_tier: "fast" }]);
|
||||
const agent = manager.getAgent(agentId);
|
||||
expect(agent?.config.providerOptions).toEqual({ web_search: true, service_tier: "fast" });
|
||||
expect(agent?.effectiveOptions).toEqual({ service_tier: "fast", web_search: true });
|
||||
await manager.flush();
|
||||
expect((await storage.get(agentId))?.config?.providerOptions).toEqual({
|
||||
web_search: true,
|
||||
service_tier: "fast",
|
||||
});
|
||||
});
|
||||
|
||||
test("a patch key is resolved against the configured defaults, merging nested objects", async () => {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-options-"));
|
||||
const client = new OptionsClient();
|
||||
client.effectiveOptions = (own) =>
|
||||
mergeProviderOptions({ sandbox: { enabled: true, failIfUnavailable: true } }, own) ?? {};
|
||||
const manager = new AgentManager({
|
||||
clients: { codex: client },
|
||||
registry: new AgentStorage(join(workdir, "agents"), logger),
|
||||
logger,
|
||||
});
|
||||
const agent = await manager.createAgent({ provider: "codex", cwd: workdir }, undefined, {
|
||||
workspaceId: undefined,
|
||||
});
|
||||
|
||||
await manager.setAgentOptions(agent.id, {
|
||||
sandbox: { network: { allowedDomains: ["a.test"] } },
|
||||
});
|
||||
|
||||
expect(client.session?.applied).toEqual([
|
||||
{
|
||||
sandbox: {
|
||||
enabled: true,
|
||||
failIfUnavailable: true,
|
||||
network: { allowedDomains: ["a.test"] },
|
||||
},
|
||||
},
|
||||
]);
|
||||
expect(manager.getAgent(agent.id)?.config.providerOptions).toEqual({
|
||||
sandbox: { network: { allowedDomains: ["a.test"] } },
|
||||
});
|
||||
// The snapshot shows what the provider was given, defaults included, and keeps showing it.
|
||||
await manager.markAgentUnread(agent.id);
|
||||
expect(manager.getAgent(agent.id)?.effectiveOptions).toEqual({
|
||||
sandbox: {
|
||||
enabled: true,
|
||||
failIfUnavailable: true,
|
||||
network: { allowedDomains: ["a.test"] },
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test("setAgentOptions sends a removal to the provider like any change, as the default it falls back to", async () => {
|
||||
const { manager, client, agentId } = await createOptionsAgent({ service_tier: "fast" });
|
||||
|
||||
await manager.setAgentOptions(agentId, { service_tier: null });
|
||||
|
||||
expect(client.session?.applied).toEqual([{ service_tier: "default" }]);
|
||||
const agent = manager.getAgent(agentId);
|
||||
expect(agent?.config.providerOptions).toBeUndefined();
|
||||
expect(agent?.effectiveOptions).toEqual({ service_tier: "default" });
|
||||
});
|
||||
|
||||
test("a removal with no default is sent as null", async () => {
|
||||
const { manager, client, agentId } = await createOptionsAgent({ web_search: true });
|
||||
|
||||
await manager.setAgentOptions(agentId, { web_search: null });
|
||||
|
||||
expect(client.session?.applied).toEqual([{ web_search: null }]);
|
||||
expect(manager.getAgent(agentId)?.config.providerOptions).toBeUndefined();
|
||||
});
|
||||
|
||||
test("a value the provider kept through a removal is stored", async () => {
|
||||
const { manager, client, agentId } = await createOptionsAgent({ web_search: true });
|
||||
client.session!.ended = { web_search: true };
|
||||
|
||||
await manager.setAgentOptions(agentId, { web_search: null });
|
||||
|
||||
const agent = manager.getAgent(agentId);
|
||||
expect(agent?.config.providerOptions).toEqual({ web_search: true });
|
||||
expect(agent?.effectiveOptions).toEqual({ service_tier: "default", web_search: true });
|
||||
});
|
||||
|
||||
test("what the provider ended up with is stored together with the patch", async () => {
|
||||
const { manager, client, agentId } = await createOptionsAgent();
|
||||
client.session!.ended = { service_tier: "slow" };
|
||||
|
||||
await manager.setAgentOptions(agentId, { service_tier: "fast", plan_mode: true });
|
||||
|
||||
expect(manager.getAgent(agentId)?.config.providerOptions).toEqual({
|
||||
service_tier: "slow",
|
||||
plan_mode: true,
|
||||
});
|
||||
});
|
||||
|
||||
test("the difference a session opened with is stored before the agent is published", async () => {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-options-"));
|
||||
const client = new OptionsClient();
|
||||
client.openOptionsPatch = { service_tier: "slow", web_search: null };
|
||||
const manager = new AgentManager({
|
||||
clients: { codex: client },
|
||||
registry: new AgentStorage(join(workdir, "agents"), logger),
|
||||
logger,
|
||||
});
|
||||
const published: Array<ProviderOptions | undefined> = [];
|
||||
manager.subscribe((event) => {
|
||||
if (event.type === "agent_state") published.push(event.agent.config.providerOptions);
|
||||
});
|
||||
|
||||
const agent = await manager.createAgent(
|
||||
{ provider: "codex", cwd: workdir, providerOptions: { web_search: true } },
|
||||
undefined,
|
||||
{ workspaceId: undefined },
|
||||
);
|
||||
|
||||
expect(agent.config.providerOptions).toEqual({ service_tier: "slow" });
|
||||
expect(published.length).toBeGreaterThan(0);
|
||||
expect(published.every((options) => options?.service_tier === "slow")).toBe(true);
|
||||
});
|
||||
|
||||
test("a default edited while the session is opening does not change the opening snapshot", async () => {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-options-"));
|
||||
const client = new OptionsClient();
|
||||
let tier = "default";
|
||||
client.effectiveOptions = (own) => ({ service_tier: tier, ...own });
|
||||
const open = client.createSession.bind(client);
|
||||
client.createSession = async (config) => {
|
||||
const session = await open(config);
|
||||
// The user edits the default in config.json after the provider has launched.
|
||||
tier = "fast";
|
||||
return session;
|
||||
};
|
||||
const manager = new AgentManager({
|
||||
clients: { codex: client },
|
||||
registry: new AgentStorage(join(workdir, "agents"), logger),
|
||||
logger,
|
||||
});
|
||||
|
||||
const agent = await manager.createAgent({ provider: "codex", cwd: workdir }, undefined, {
|
||||
workspaceId: undefined,
|
||||
});
|
||||
|
||||
expect(agent.effectiveOptions).toEqual({ service_tier: "default" });
|
||||
});
|
||||
|
||||
test("an option the session dropped when opening does not come back from a configured default", async () => {
|
||||
const { manager, agentId } = await createOptionsAgent(undefined, { service_tier: null });
|
||||
|
||||
const agent = manager.getAgent(agentId);
|
||||
expect(agent?.effectiveOptions).toEqual({});
|
||||
await manager.markAgentUnread(agentId);
|
||||
expect(toAgentPayload(manager.getAgent(agentId)!).options).toEqual({});
|
||||
});
|
||||
|
||||
test("an option without a control is settable through the patch and readable in the snapshot", async () => {
|
||||
const { manager, client, storage, agentId } = await createOptionsAgent();
|
||||
|
||||
await manager.setAgentOptions(agentId, { sandbox_mode: "read-only" });
|
||||
|
||||
expect(client.session?.applied).toEqual([{ sandbox_mode: "read-only" }]);
|
||||
const agent = manager.getAgent(agentId);
|
||||
expect(agent?.config.providerOptions).toEqual({ sandbox_mode: "read-only" });
|
||||
expect(toAgentPayload(agent!).options).toEqual({
|
||||
service_tier: "default",
|
||||
sandbox_mode: "read-only",
|
||||
});
|
||||
await manager.flush();
|
||||
expect((await storage.get(agentId))?.config?.providerOptions).toEqual({
|
||||
sandbox_mode: "read-only",
|
||||
});
|
||||
});
|
||||
|
||||
test("concurrent patches both land: each is applied to the options as they are when its provider call resolves", async () => {
|
||||
const { manager, client, agentId } = await createOptionsAgent();
|
||||
let release!: () => void;
|
||||
client.session!.applyGate = new Promise<void>((resolve) => {
|
||||
release = resolve;
|
||||
});
|
||||
|
||||
const slow = manager.setAgentOptions(agentId, { sandbox_mode: "read-only" });
|
||||
client.session!.applyGate = null;
|
||||
await manager.setAgentOptions(agentId, { web_search: true });
|
||||
release();
|
||||
await slow;
|
||||
|
||||
expect(manager.getAgent(agentId)?.config.providerOptions).toEqual({
|
||||
sandbox_mode: "read-only",
|
||||
web_search: true,
|
||||
});
|
||||
});
|
||||
|
||||
test("a stored agent that is not loaded still reports its effective options", async () => {
|
||||
const { manager, agentId } = await createOptionsAgent({ web_search: true });
|
||||
await manager.closeAgent(agentId);
|
||||
const states: ManagedAgent[] = [];
|
||||
manager.subscribe(
|
||||
(event) => {
|
||||
if (event.type === "agent_state" && event.agent.id === agentId) states.push(event.agent);
|
||||
},
|
||||
{ replayState: false },
|
||||
);
|
||||
|
||||
await manager.markAgentUnread(agentId);
|
||||
|
||||
expect(states.at(-1)?.effectiveOptions).toEqual({ service_tier: "default", web_search: true });
|
||||
});
|
||||
|
||||
test("editing a provider default does not change the options of a loaded agent", async () => {
|
||||
const { manager, client, agentId } = await createOptionsAgent({ web_search: true });
|
||||
expect(manager.getAgent(agentId)?.effectiveOptions).toEqual({
|
||||
service_tier: "default",
|
||||
web_search: true,
|
||||
});
|
||||
|
||||
// The user edits the default in config.json while the agent is running.
|
||||
client.effectiveOptions = (own) => ({ service_tier: "fast", ...own });
|
||||
await manager.markAgentUnread(agentId);
|
||||
|
||||
const agent = manager.getAgent(agentId);
|
||||
expect(agent?.effectiveOptions).toEqual({ service_tier: "default", web_search: true });
|
||||
expect(toAgentPayload(agent!).options).toEqual({ service_tier: "default", web_search: true });
|
||||
});
|
||||
|
||||
test("a provider that rejects an option leaves the stored options unchanged", async () => {
|
||||
const { manager, client, agentId } = await createOptionsAgent({ web_search: false });
|
||||
client.session!.rejectWith = new Error("fast mode unavailable");
|
||||
|
||||
await expect(manager.setAgentOptions(agentId, { web_search: true })).rejects.toThrow(
|
||||
"fast mode unavailable",
|
||||
);
|
||||
|
||||
expect(manager.getAgent(agentId)?.config.providerOptions).toEqual({ web_search: false });
|
||||
});
|
||||
|
||||
test("a provider whose session cannot apply options rejects a patch and stores nothing", async () => {
|
||||
// Like a provider with no live option support: the session has no `applyOptions`.
|
||||
class NoOptionsSession extends TestAgentSession {
|
||||
constructor(config: AgentSessionConfig) {
|
||||
super(config);
|
||||
Object.defineProperty(this, "applyOptions", { value: undefined });
|
||||
}
|
||||
}
|
||||
class NoOptionsClient extends TestAgentClient {
|
||||
override async createSession(config: AgentSessionConfig): Promise<AgentSession> {
|
||||
return new NoOptionsSession(config);
|
||||
}
|
||||
}
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-no-options-"));
|
||||
const manager = new AgentManager({
|
||||
clients: { codex: new NoOptionsClient() },
|
||||
registry: new AgentStorage(join(workdir, "agents"), logger),
|
||||
logger,
|
||||
});
|
||||
const agent = await manager.createAgent(
|
||||
{ provider: "codex", cwd: workdir, providerOptions: { web_search: false } },
|
||||
undefined,
|
||||
{ workspaceId: undefined },
|
||||
);
|
||||
|
||||
await expect(manager.setAgentOptions(agent.id, { web_search: true })).rejects.toThrow(
|
||||
/web_search.*cannot change on a running session/,
|
||||
);
|
||||
|
||||
expect(manager.getAgent(agent.id)?.config.providerOptions).toEqual({ web_search: false });
|
||||
});
|
||||
|
||||
test("agent.create.before hook featureValues fold into providerOptions", async () => {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-hook-"));
|
||||
const storage = new AgentStorage(join(workdir, "agents"), logger);
|
||||
const client = new OptionsClient();
|
||||
const manager = new AgentManager({
|
||||
clients: { codex: client },
|
||||
registry: storage,
|
||||
logger,
|
||||
pluginLifecycle: {
|
||||
emit: () => {},
|
||||
before: async (_name, request) => ({
|
||||
...request,
|
||||
config: { ...request.config, featureValues: { web_search: true } },
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
const created = await manager.createAgent({ provider: "codex", cwd: workdir }, undefined, {
|
||||
workspaceId: undefined,
|
||||
});
|
||||
|
||||
expect(manager.getAgent(created.id)?.config.providerOptions).toEqual({ web_search: true });
|
||||
expect(manager.getAgent(created.id)?.config).not.toHaveProperty("featureValues");
|
||||
});
|
||||
|
||||
test("agent.create.before hook featureValues edit overrides an option the create already set", async () => {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-hook-"));
|
||||
const storage = new AgentStorage(join(workdir, "agents"), logger);
|
||||
const client = new OptionsClient();
|
||||
const manager = new AgentManager({
|
||||
clients: { codex: client },
|
||||
registry: storage,
|
||||
logger,
|
||||
pluginLifecycle: {
|
||||
emit: () => {},
|
||||
// A plugin written against the previous SDK: flips one value, leaves the rest.
|
||||
before: async (name, request) =>
|
||||
name === "agent.create.before"
|
||||
? {
|
||||
...request,
|
||||
config: {
|
||||
...request.config,
|
||||
featureValues: { ...request.config.featureValues, web_search: true },
|
||||
},
|
||||
}
|
||||
: request,
|
||||
},
|
||||
});
|
||||
|
||||
const created = await manager.createAgent(
|
||||
{ provider: "codex", cwd: workdir, providerOptions: { web_search: false, plan_mode: true } },
|
||||
undefined,
|
||||
{ workspaceId: undefined },
|
||||
);
|
||||
|
||||
expect(manager.getAgent(created.id)?.config.providerOptions).toEqual({
|
||||
web_search: true,
|
||||
plan_mode: true,
|
||||
});
|
||||
});
|
||||
|
||||
test("agent.create.before hook leaving featureValues untouched keeps providerOptions edits", async () => {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-hook-"));
|
||||
const storage = new AgentStorage(join(workdir, "agents"), logger);
|
||||
const client = new OptionsClient();
|
||||
const manager = new AgentManager({
|
||||
clients: { codex: client },
|
||||
registry: storage,
|
||||
logger,
|
||||
pluginLifecycle: {
|
||||
emit: () => {},
|
||||
before: async (name, request) =>
|
||||
name === "agent.create.before"
|
||||
? {
|
||||
...request,
|
||||
config: {
|
||||
...request.config,
|
||||
providerOptions: { ...request.config.providerOptions, plan_mode: false },
|
||||
},
|
||||
}
|
||||
: request,
|
||||
},
|
||||
});
|
||||
|
||||
const created = await manager.createAgent(
|
||||
{ provider: "codex", cwd: workdir, providerOptions: { web_search: false, plan_mode: true } },
|
||||
undefined,
|
||||
{ workspaceId: undefined },
|
||||
);
|
||||
|
||||
expect(manager.getAgent(created.id)?.config.providerOptions).toEqual({
|
||||
web_search: false,
|
||||
plan_mode: false,
|
||||
});
|
||||
});
|
||||
|
||||
describe.each([
|
||||
{
|
||||
name: "deletes a key",
|
||||
edit: (values: Record<string, unknown> | undefined) => {
|
||||
const { web_search: _removed, ...rest } = values ?? {};
|
||||
return { featureValues: rest };
|
||||
},
|
||||
expected: { plan_mode: true },
|
||||
},
|
||||
{
|
||||
name: "empties featureValues",
|
||||
edit: () => ({ featureValues: {} }),
|
||||
expected: {},
|
||||
},
|
||||
{
|
||||
name: "drops featureValues",
|
||||
edit: () => ({ featureValues: undefined }),
|
||||
expected: {},
|
||||
},
|
||||
])("agent.create.before hook that $name", ({ edit, expected }) => {
|
||||
test("removes those options from the new agent", async () => {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-hook-"));
|
||||
const manager = new AgentManager({
|
||||
clients: { codex: new OptionsClient() },
|
||||
registry: new AgentStorage(join(workdir, "agents"), logger),
|
||||
logger,
|
||||
pluginLifecycle: {
|
||||
emit: () => {},
|
||||
before: async (name, request) =>
|
||||
name === "agent.create.before"
|
||||
? {
|
||||
...request,
|
||||
config: { ...request.config, ...edit(request.config.featureValues) },
|
||||
}
|
||||
: request,
|
||||
},
|
||||
});
|
||||
|
||||
const created = await manager.createAgent(
|
||||
{ provider: "codex", cwd: workdir, providerOptions: { web_search: true, plan_mode: true } },
|
||||
undefined,
|
||||
{ workspaceId: undefined },
|
||||
);
|
||||
|
||||
expect(manager.getAgent(created.id)?.config.providerOptions).toEqual(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { AttachedAgentTool, PluginAgentToolsRuntime } from "../plugins/agent-tools.js";
|
||||
import { ProviderOptionsValidationError } from "./provider-options.js";
|
||||
import type { AgentToolResult } from "@getpaseo/plugin/server";
|
||||
import type { RuntimeCleanupCandidate } from "./idle-runtime-cleanup/index.js";
|
||||
import { ensureAgentLoaded } from "./agent-loading.js";
|
||||
@@ -33,7 +34,7 @@ import {
|
||||
type AgentCreateSessionOptions,
|
||||
type AgentResumePurpose,
|
||||
type AgentResumeSessionOptions,
|
||||
type AgentFeature,
|
||||
type AgentOptionControl,
|
||||
type AgentLaunchContext,
|
||||
type AgentSlashCommand,
|
||||
type AgentMode,
|
||||
@@ -59,7 +60,16 @@ import {
|
||||
type ListImportableSessionsOptions,
|
||||
} from "./agent-sdk-types.js";
|
||||
import { buildArchivedAgentRecord, type ArchivedStoredAgentRecord } from "./agent-archive.js";
|
||||
import type { ProviderOptions } from "@getpaseo/protocol/agent-types";
|
||||
import { toStoredAgentRecord } from "./agent-projections.js";
|
||||
import {
|
||||
applyProviderOptionsPatch,
|
||||
exposeFeatureValuesToHook,
|
||||
convertLegacyOptions,
|
||||
resolveAdapter,
|
||||
foldHookFeatureValues,
|
||||
type ProviderOptionsPatch,
|
||||
} from "./option-controls.js";
|
||||
import type { StoredAgentRecord, AgentStorage } from "./agent-storage.js";
|
||||
import type { AgentOwner } from "./agent-owner.js";
|
||||
import {
|
||||
@@ -171,6 +181,23 @@ async function assertUsableWorkingDirectory(cwd: string): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
async function resolveResumePurpose(
|
||||
record: StoredAgentRecord | null,
|
||||
requested: AgentResumePurpose | undefined,
|
||||
cwd: string,
|
||||
): Promise<AgentResumePurpose> {
|
||||
if (!record) return requested ?? "interactive";
|
||||
if (record.archivedAt) return "history";
|
||||
if (requested !== "history") return "interactive";
|
||||
try {
|
||||
await stat(cwd);
|
||||
return "interactive";
|
||||
} catch (error) {
|
||||
if ((error as NodeJS.ErrnoException).code === "ENOENT") return "history";
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
interface PreparedSessionConfig {
|
||||
storedConfig: AgentSessionConfig;
|
||||
launchConfig: AgentSessionConfig;
|
||||
@@ -210,9 +237,6 @@ function buildStoredAgentConfig(record: StoredAgentRecord): AgentSessionConfig {
|
||||
if (record.config.thinkingOptionId != null) {
|
||||
config.thinkingOptionId = record.config.thinkingOptionId;
|
||||
}
|
||||
if (record.config.featureValues != null) {
|
||||
config.featureValues = record.config.featureValues;
|
||||
}
|
||||
if (record.config.providerOptions != null) {
|
||||
config.providerOptions = record.config.providerOptions;
|
||||
}
|
||||
@@ -435,7 +459,9 @@ interface ManagedAgentBase {
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
availableModes: AgentMode[];
|
||||
features?: AgentFeature[];
|
||||
controls?: AgentOptionControl[];
|
||||
/** `config.json` defaults deep-merged with `config.providerOptions`; refreshed on every state emit. */
|
||||
effectiveOptions?: ProviderOptions;
|
||||
currentModeId: string | null;
|
||||
pendingPermissions: Map<string, AgentPermissionRequest>;
|
||||
bufferedPermissionResolutions: Map<
|
||||
@@ -783,6 +809,7 @@ export class AgentManager {
|
||||
private readonly backgroundTasks = new Set<Promise<void>>();
|
||||
private readonly agentRegistrationTasks = new Set<Promise<void>>();
|
||||
private readonly inFlightAgentCloses = new Map<string, Promise<void>>();
|
||||
private readonly historySessions = new WeakSet<AgentSession>();
|
||||
private readonly reloadedSessionCloses = new WeakMap<AgentSession, Promise<void>>();
|
||||
private readonly runtimeCleanupIdentities = new WeakMap<AgentSession, object>();
|
||||
private readonly collectingRuntimes = new Set<string>();
|
||||
@@ -1255,11 +1282,17 @@ export class AgentManager {
|
||||
}
|
||||
}
|
||||
|
||||
async listDraftFeatures(config: AgentSessionConfig): Promise<AgentFeature[]> {
|
||||
async listDraftControls(
|
||||
config: AgentSessionConfig,
|
||||
): Promise<{ controls: AgentOptionControl[]; options: ProviderOptions }> {
|
||||
const normalizedConfig = await this.normalizeConfig(config, { resolveDefaultModel: false });
|
||||
const client = this.requireClient(normalizedConfig.provider);
|
||||
if (!normalizedConfig.model && !client.listFeatures) {
|
||||
return [];
|
||||
const options = this.effectiveOptionsFor(
|
||||
normalizedConfig.provider,
|
||||
normalizedConfig.providerOptions,
|
||||
);
|
||||
if (!normalizedConfig.model && !client.listControls) {
|
||||
return { controls: [], options };
|
||||
}
|
||||
const available = await client.isAvailable();
|
||||
if (!available) {
|
||||
@@ -1268,13 +1301,18 @@ export class AgentManager {
|
||||
);
|
||||
}
|
||||
|
||||
if (client.listFeatures) {
|
||||
return await client.listFeatures(normalizedConfig);
|
||||
if (client.listControls) {
|
||||
return { controls: await client.listControls(normalizedConfig), options };
|
||||
}
|
||||
|
||||
const session = await client.createSession(normalizedConfig);
|
||||
try {
|
||||
return session.features ?? [];
|
||||
// The options a session opens with, as create would report them, so the controls'
|
||||
// selection matches what the first turn runs with.
|
||||
return {
|
||||
controls: session.controls ?? [],
|
||||
options: this.openedEffectiveOptions({ session, launchedOptions: options }),
|
||||
};
|
||||
} finally {
|
||||
try {
|
||||
await session.close();
|
||||
@@ -1372,12 +1410,23 @@ export class AgentManager {
|
||||
): Promise<ManagedAgent> {
|
||||
this.assertAcceptingAgentRegistrations();
|
||||
const resolvedAgentId = validateAgentId(agentId ?? this.idFactory(), "createAgent");
|
||||
config = this.withConvertedOptions(config);
|
||||
if (this.pluginLifecycle && !config.internal) {
|
||||
const sent = exposeFeatureValuesToHook(config);
|
||||
const request = await this.pluginLifecycle.before("agent.create.before", {
|
||||
config,
|
||||
config: sent,
|
||||
env: options.env,
|
||||
});
|
||||
config = { ...request.config, internal: config.internal };
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01. A plugin written
|
||||
// against the previous SDK edits `config.featureValues`.
|
||||
config = {
|
||||
...foldHookFeatureValues({
|
||||
returned: request.config,
|
||||
sent,
|
||||
convert: (values) => this.convertLegacyOptions(request.config.provider, values),
|
||||
}),
|
||||
internal: config.internal,
|
||||
};
|
||||
options = { ...options, env: request.env };
|
||||
}
|
||||
await this.deleteAgentState(resolvedAgentId);
|
||||
@@ -1407,9 +1456,11 @@ export class AgentManager {
|
||||
);
|
||||
const providerLaunchConfig = this.resolveProviderLaunchConfig(launchConfig, launchContext);
|
||||
const createOptions = this.buildCreateSessionOptions(options);
|
||||
const launchedOptions = this.launchOptionsFor({ client, own: storedConfig.providerOptions });
|
||||
const session = await client.createSession(providerLaunchConfig, launchContext, createOptions);
|
||||
await this.requireExternalMcpSupport(session, providerLaunchConfig, launchContext);
|
||||
const agent = await this.registerSession(session, storedConfig, resolvedAgentId, {
|
||||
launchedOptions,
|
||||
labels: options.labels,
|
||||
initialTitle: options.initialTitle,
|
||||
workspaceId: options.workspaceId,
|
||||
@@ -1501,10 +1552,8 @@ export class AgentManager {
|
||||
// settled before the config is prepared, because a history load reads an archived
|
||||
// agent whose working directory may be gone.
|
||||
const record = this.registry ? await this.registry.get(resolvedAgentId) : null;
|
||||
const currentResumeOptions = record
|
||||
? { purpose: record.archivedAt ? ("history" as const) : ("interactive" as const) }
|
||||
: resumeOptions;
|
||||
const purpose = currentResumeOptions?.purpose ?? "interactive";
|
||||
const purpose = await resolveResumePurpose(record, resumeOptions?.purpose, mergedConfig.cwd);
|
||||
const currentResumeOptions = { purpose } satisfies AgentResumeSessionOptions;
|
||||
|
||||
const launchEnv = record?.launchEnv;
|
||||
const { storedConfig, launchConfig, paseoToolPolicy } = await this.prepareSessionConfig(
|
||||
@@ -1535,14 +1584,17 @@ export class AgentManager {
|
||||
},
|
||||
);
|
||||
const providerLaunchConfig = this.resolveProviderLaunchConfig(launchConfig, launchContext);
|
||||
const launchedOptions = this.launchOptionsFor({ client, own: storedConfig.providerOptions });
|
||||
const session = await client.resumeSession(
|
||||
handle,
|
||||
providerLaunchConfig,
|
||||
launchContext,
|
||||
currentResumeOptions,
|
||||
);
|
||||
if (purpose === "history") this.historySessions.add(session);
|
||||
await this.requireExternalMcpSupport(session, providerLaunchConfig, launchContext);
|
||||
return this.registerSession(session, storedConfig, resolvedAgentId, {
|
||||
launchedOptions,
|
||||
...options,
|
||||
launchEnv,
|
||||
persistence: handle,
|
||||
@@ -1598,6 +1650,7 @@ export class AgentManager {
|
||||
},
|
||||
);
|
||||
const providerLaunchConfig = this.resolveProviderLaunchConfig(launchConfig, launchContext);
|
||||
const launchedOptions = this.launchOptionsFor({ client, own: storedConfig.providerOptions });
|
||||
const imported = await client.importSession(
|
||||
{
|
||||
providerHandleId: input.providerHandleId,
|
||||
@@ -1616,6 +1669,7 @@ export class AgentManager {
|
||||
|
||||
handedToRegistration = true;
|
||||
const agent = await this.registerSession(imported.session, importedConfig, resolvedAgentId, {
|
||||
launchedOptions,
|
||||
labels: input.labels,
|
||||
workspaceId: input.workspaceId,
|
||||
timelineRows,
|
||||
@@ -1721,6 +1775,7 @@ export class AgentManager {
|
||||
this.assertAcceptingAgentRegistrations();
|
||||
|
||||
this.paseoToolPolicies.set(agentId, paseoToolPolicy);
|
||||
const launchedOptions = this.launchOptionsFor({ client, own: storedConfig.providerOptions });
|
||||
session = handle
|
||||
? await client.resumeSession(handle, providerLaunchConfig, launchContext)
|
||||
: await client.createSession(providerLaunchConfig, launchContext);
|
||||
@@ -1739,6 +1794,7 @@ export class AgentManager {
|
||||
// Preserve existing labels and timeline during reload.
|
||||
handedToRegistration = true;
|
||||
return this.registerSession(session, storedConfig, agentId, {
|
||||
launchedOptions,
|
||||
labels: existing.labels,
|
||||
workspaceId: existing.workspaceId,
|
||||
owner: existing.owner,
|
||||
@@ -2065,7 +2121,7 @@ export class AgentManager {
|
||||
return;
|
||||
}
|
||||
const parentAgentId = parent.id;
|
||||
const records = await registry.list();
|
||||
const records = await registry.listActive();
|
||||
for (const record of records) {
|
||||
if (record.archivedAt) {
|
||||
continue;
|
||||
@@ -2178,7 +2234,11 @@ export class AgentManager {
|
||||
createdAt: new Date(record.createdAt),
|
||||
updatedAt,
|
||||
availableModes: [],
|
||||
features: record.features,
|
||||
controls: record.controls,
|
||||
effectiveOptions: this.effectiveOptionsFor(
|
||||
record.provider,
|
||||
record.config?.providerOptions ?? undefined,
|
||||
),
|
||||
currentModeId: record.lastModeId ?? null,
|
||||
pendingPermissions: new Map(),
|
||||
bufferedPermissionResolutions: new Map(),
|
||||
@@ -2204,7 +2264,7 @@ export class AgentManager {
|
||||
}
|
||||
|
||||
async setAgentMode(agentId: string, modeId: string): Promise<AgentProviderNotice | null> {
|
||||
const agent = this.requireSessionAgent(agentId);
|
||||
const agent = await this.ensureInteractiveSession(agentId);
|
||||
const notice = (await agent.session.setMode(modeId)) ?? null;
|
||||
await this.drainSessionEvents(agentId);
|
||||
const currentMode = (await agent.session.getCurrentMode()) ?? modeId;
|
||||
@@ -2220,7 +2280,7 @@ export class AgentManager {
|
||||
}
|
||||
|
||||
async setAgentModel(agentId: string, modelId: string | null): Promise<void> {
|
||||
const agent = this.requireSessionAgent(agentId);
|
||||
const agent = await this.ensureInteractiveSession(agentId);
|
||||
const normalizedModelId =
|
||||
typeof modelId === "string" && modelId.trim().length > 0 ? modelId : null;
|
||||
|
||||
@@ -2242,7 +2302,7 @@ export class AgentManager {
|
||||
agentId: string,
|
||||
thinkingOptionId: string | null,
|
||||
): Promise<AgentProviderNotice | null> {
|
||||
const agent = this.requireSessionAgent(agentId);
|
||||
const agent = await this.ensureInteractiveSession(agentId);
|
||||
const normalizedThinkingOptionId =
|
||||
typeof thinkingOptionId === "string" && thinkingOptionId.trim().length > 0
|
||||
? thinkingOptionId
|
||||
@@ -2272,20 +2332,107 @@ export class AgentManager {
|
||||
return notice;
|
||||
}
|
||||
|
||||
async setAgentFeature(agentId: string, featureId: string, value: unknown): Promise<void> {
|
||||
const agent = this.requireAgent(agentId);
|
||||
|
||||
if (!agent.session.setFeature) {
|
||||
throw new Error("Agent session does not support setting features");
|
||||
/**
|
||||
* Applies an options patch to a running agent (see `AgentSession.applyOptions`). The provider
|
||||
* gets each key the patch touches, resolved against the `config.json` defaults, with `null`
|
||||
* where nothing is set. The patch and whatever the provider says it ended up with are stored in
|
||||
* one step once the provider accepts, over the options as they are at that moment, so concurrent
|
||||
* writes to one agent resolve by arrival order.
|
||||
*/
|
||||
async setAgentOptions(agentId: string, requested: ProviderOptionsPatch): Promise<void> {
|
||||
const agent = await this.ensureInteractiveSession(agentId);
|
||||
const patch = this.convertLegacyOptions(agent.provider, requested);
|
||||
let ended: ProviderOptionsPatch = {};
|
||||
let sent: ProviderOptionsPatch = {};
|
||||
if (Object.keys(patch).length > 0) {
|
||||
// A provider that cannot apply options to a running agent must not store them either.
|
||||
if (!agent.session.applyOptions) {
|
||||
throw new ProviderOptionsValidationError(
|
||||
agent.provider,
|
||||
Object.keys(patch).map((key) => ({
|
||||
path: [key],
|
||||
message: "cannot change on a running session; it applies when the agent is opened",
|
||||
})),
|
||||
);
|
||||
}
|
||||
const set = Object.fromEntries(Object.entries(patch).filter(([, value]) => value != null));
|
||||
const resolved = this.effectiveOptionsFor(agent.provider, set);
|
||||
sent = Object.fromEntries(Object.keys(patch).map((key) => [key, resolved[key] ?? null]));
|
||||
ended = (await agent.session.applyOptions(sent)) ?? {};
|
||||
// Changes the provider made on its own while applying are older than its final answer.
|
||||
await this.drainSessionEvents(agentId);
|
||||
}
|
||||
|
||||
await agent.session.setFeature(featureId, value);
|
||||
await this.drainSessionEvents(agentId);
|
||||
agent.config.featureValues = { ...agent.config.featureValues, [featureId]: value };
|
||||
this.storeOptionsPatch({ agent, patch: { ...patch, ...ended } });
|
||||
this.updateEffectiveOptions({ agent, sent, reported: ended });
|
||||
this.touchUpdatedAt(agent);
|
||||
this.emitState(agent);
|
||||
}
|
||||
|
||||
/** The config as the opened session left it: its own difference from the options it was given. */
|
||||
private withOpenedOptions(input: {
|
||||
config: AgentSessionConfig;
|
||||
session: AgentSession;
|
||||
}): AgentSessionConfig {
|
||||
const { config } = input;
|
||||
const opened = input.session.openOptionsPatch;
|
||||
if (!opened || Object.keys(opened).length === 0) return config;
|
||||
const own = applyProviderOptionsPatch({ options: config.providerOptions, patch: opened });
|
||||
return { ...config, providerOptions: Object.keys(own).length > 0 ? own : undefined };
|
||||
}
|
||||
|
||||
private storeOptionsPatch(input: { agent: ManagedAgent; patch: ProviderOptionsPatch }): void {
|
||||
const { agent } = input;
|
||||
const own = applyProviderOptionsPatch({
|
||||
options: agent.config.providerOptions,
|
||||
patch: input.patch,
|
||||
});
|
||||
agent.config.providerOptions = Object.keys(own).length > 0 ? own : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* What the running session has: the options it opened with, moved only by what an apply sent
|
||||
* it (defaults merged in, `null` where a removal left nothing) and by what the provider reports
|
||||
* back. The agent's own stored options keep only the raw patch.
|
||||
*/
|
||||
private updateEffectiveOptions(input: {
|
||||
agent: ManagedAgent;
|
||||
sent: ProviderOptionsPatch;
|
||||
reported: ProviderOptionsPatch;
|
||||
}): void {
|
||||
input.agent.effectiveOptions = applyProviderOptionsPatch({
|
||||
options: input.agent.effectiveOptions,
|
||||
patch: { ...input.sent, ...input.reported },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Defaults merge into what the session was given; what it reports it ended up with comes
|
||||
* after, so an option it dropped does not come back from a default.
|
||||
*/
|
||||
private openedEffectiveOptions(input: {
|
||||
session: AgentSession;
|
||||
launchedOptions: ProviderOptions;
|
||||
}): ProviderOptions {
|
||||
return applyProviderOptionsPatch({
|
||||
options: input.launchedOptions,
|
||||
patch: input.session.openOptionsPatch ?? {},
|
||||
});
|
||||
}
|
||||
|
||||
/** The options a client opens with: its own defaults merged under the agent's. */
|
||||
private launchOptionsFor(input: {
|
||||
client: AgentClient;
|
||||
own: ProviderOptions | undefined;
|
||||
}): ProviderOptions {
|
||||
return input.client.effectiveOptions?.(input.own) ?? input.own ?? {};
|
||||
}
|
||||
|
||||
/** What an agent of this provider runs with, given its own options: the defaults under them. */
|
||||
effectiveOptionsFor(provider: AgentProvider, own: ProviderOptions | undefined): ProviderOptions {
|
||||
const client = this.clients.get(provider);
|
||||
return client ? this.launchOptionsFor({ client, own }) : (own ?? {});
|
||||
}
|
||||
|
||||
async setTitle(agentId: string, title: string): Promise<void> {
|
||||
const agent = this.requireAgent(agentId);
|
||||
const normalizedTitle = title.trim();
|
||||
@@ -2531,7 +2678,8 @@ export class AgentManager {
|
||||
|
||||
async unarchiveSnapshotByHandle(handle: AgentPersistenceHandle): Promise<void> {
|
||||
const registry = this.requireRegistry();
|
||||
const records = await registry.list();
|
||||
// Restoring an archived provider session is an explicit recovery operation.
|
||||
const records = await registry.listAll();
|
||||
const matched = records.find(
|
||||
(record) =>
|
||||
record.persistence?.provider === handle.provider &&
|
||||
@@ -2654,7 +2802,7 @@ export class AgentManager {
|
||||
logger: this.logger,
|
||||
});
|
||||
}
|
||||
const agent = this.requireSessionAgent(agentId);
|
||||
const agent = await this.ensureInteractiveSession(agentId);
|
||||
// Providers parse slash commands from the raw text, so a command another agent sent
|
||||
// must reach them without its sender envelope.
|
||||
const agentMessage = typeof prompt === "string" ? parseAgentMessage(prompt) : null;
|
||||
@@ -2783,6 +2931,34 @@ export class AgentManager {
|
||||
}
|
||||
}
|
||||
|
||||
private async ensureInteractiveSession(agentId: string): Promise<ActiveManagedAgent> {
|
||||
const agent = this.requireSessionAgent(agentId);
|
||||
if (this.historySessions.has(agent.session)) {
|
||||
await this.trackAgentRegistrationOperation(
|
||||
this.runLifecycleMutation(agentId, async () => {
|
||||
const record = await this.registry?.get(agentId);
|
||||
if (record?.archivedAt) throw new Error(`Agent is archived: ${agentId}`);
|
||||
const current = this.requireSessionAgent(agentId);
|
||||
if (this.historySessions.has(current.session)) {
|
||||
// Recheck inside the lane: another prompt may already have upgraded it.
|
||||
// Reload validates the directory before releasing readable history.
|
||||
await this.reloadAgentSessionInternal(agentId);
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
return this.requireSessionAgent(agentId);
|
||||
}
|
||||
|
||||
private async *streamAfterHistoryLoad(
|
||||
agentId: string,
|
||||
prompt: AgentPromptInput,
|
||||
options?: AgentRunOptions,
|
||||
): AsyncGenerator<AgentStreamEvent> {
|
||||
await this.ensureInteractiveSession(agentId);
|
||||
yield* this.streamAgent(agentId, prompt, options);
|
||||
}
|
||||
|
||||
private async *streamAfterRuntimeCollection(
|
||||
agentId: string,
|
||||
prompt: AgentPromptInput,
|
||||
@@ -2805,6 +2981,8 @@ export class AgentManager {
|
||||
if (this.collectingRuntimes.has(agentId) || (!this.agents.has(agentId) && this.registry))
|
||||
return this.streamAfterRuntimeCollection(agentId, prompt, options);
|
||||
const existingAgent = this.requireSessionAgent(agentId);
|
||||
if (this.historySessions.has(existingAgent.session))
|
||||
return this.streamAfterHistoryLoad(agentId, prompt, options);
|
||||
this.logger.trace(
|
||||
{
|
||||
agentId,
|
||||
@@ -3491,7 +3669,12 @@ export class AgentManager {
|
||||
}
|
||||
|
||||
async rewind(agentId: string, messageId: string, mode: RewindMode): Promise<void> {
|
||||
const agent = this.requireSessionAgent(agentId);
|
||||
let agent = this.requireSessionAgent(agentId);
|
||||
if (this.historySessions.has(agent.session)) {
|
||||
agent = await this.ensureInteractiveSession(agentId);
|
||||
}
|
||||
// An interactive session must acquire its rewind lock without yielding.
|
||||
|
||||
const submittedRow = this.timelineStore
|
||||
.getRows(agentId)
|
||||
.find(
|
||||
@@ -3799,9 +3982,9 @@ export class AgentManager {
|
||||
|
||||
private async registerSession(
|
||||
session: AgentSession,
|
||||
config: AgentSessionConfig,
|
||||
openedConfig: AgentSessionConfig,
|
||||
agentId: string,
|
||||
options?: {
|
||||
options: {
|
||||
createdAt?: Date;
|
||||
updatedAt?: Date;
|
||||
lastUserMessageAt?: Date | null;
|
||||
@@ -3819,6 +4002,12 @@ export class AgentManager {
|
||||
* attention come from what was already recorded, and installing the session is not
|
||||
* activity in it.
|
||||
*/
|
||||
/**
|
||||
* The effective options the opening resolved before the session started. Registration
|
||||
* starts from these rather than reading the defaults again, which may have been edited
|
||||
* while the provider was opening.
|
||||
*/
|
||||
launchedOptions: ProviderOptions;
|
||||
restoring?: boolean;
|
||||
initialTitle?: string | null;
|
||||
publishWhenReady?: boolean;
|
||||
@@ -3831,6 +4020,7 @@ export class AgentManager {
|
||||
let registered = false;
|
||||
try {
|
||||
this.assertAcceptingAgentRegistrations();
|
||||
const config = this.withOpenedOptions({ config: openedConfig, session });
|
||||
const resolvedAgentId = validateAgentId(agentId, "registerSession");
|
||||
if (this.agents.has(resolvedAgentId)) {
|
||||
throw new Error(`Agent with id ${resolvedAgentId} already exists`);
|
||||
@@ -3852,6 +4042,10 @@ export class AgentManager {
|
||||
resolvedAgentId,
|
||||
session,
|
||||
config,
|
||||
effectiveOptions: this.openedEffectiveOptions({
|
||||
session,
|
||||
launchedOptions: options.launchedOptions,
|
||||
}),
|
||||
now,
|
||||
durableTimelineHasRows,
|
||||
background: options?.background === true,
|
||||
@@ -3997,6 +4191,7 @@ export class AgentManager {
|
||||
resolvedAgentId: string;
|
||||
session: AgentSession;
|
||||
config: AgentSessionConfig;
|
||||
effectiveOptions: ProviderOptions;
|
||||
now: Date;
|
||||
durableTimelineHasRows: boolean;
|
||||
background: boolean;
|
||||
@@ -4017,7 +4212,15 @@ export class AgentManager {
|
||||
}
|
||||
| undefined;
|
||||
}): ActiveManagedAgent {
|
||||
const { resolvedAgentId, session, config, now, durableTimelineHasRows, options } = params;
|
||||
const {
|
||||
resolvedAgentId,
|
||||
session,
|
||||
config,
|
||||
effectiveOptions,
|
||||
now,
|
||||
durableTimelineHasRows,
|
||||
options,
|
||||
} = params;
|
||||
return {
|
||||
id: resolvedAgentId,
|
||||
provider: config.provider,
|
||||
@@ -4028,6 +4231,8 @@ export class AgentManager {
|
||||
session,
|
||||
capabilities: session.capabilities,
|
||||
config,
|
||||
// What the session opened with. Provider defaults edited later reach it when it next opens.
|
||||
effectiveOptions,
|
||||
runtimeInfo: undefined,
|
||||
lifecycle: "initializing",
|
||||
createdAt: options?.createdAt ?? now,
|
||||
@@ -4334,7 +4539,7 @@ export class AgentManager {
|
||||
agent.pendingPermissions.clear();
|
||||
}
|
||||
|
||||
this.syncFeaturesFromSession(agent);
|
||||
this.syncControls(agent);
|
||||
await this.refreshRuntimeInfo(agent, options);
|
||||
}
|
||||
|
||||
@@ -4680,6 +4885,18 @@ export class AgentManager {
|
||||
);
|
||||
}
|
||||
|
||||
private onStreamOptionsChanged(params: {
|
||||
agent: ActiveManagedAgent;
|
||||
patch: ProviderOptionsPatch;
|
||||
flags: StreamEventFlags;
|
||||
}): void {
|
||||
const { agent, patch, flags } = params;
|
||||
this.storeOptionsPatch({ agent, patch });
|
||||
this.updateEffectiveOptions({ agent, sent: {}, reported: patch });
|
||||
flags.shouldDispatchEvent = false;
|
||||
this.emitState(agent);
|
||||
}
|
||||
|
||||
private dispatchStreamEventByType(params: {
|
||||
agent: ActiveManagedAgent;
|
||||
event: AgentStreamEvent;
|
||||
@@ -4731,6 +4948,9 @@ export class AgentManager {
|
||||
flags.shouldDispatchEvent = false;
|
||||
this.emitState(agent);
|
||||
return undefined;
|
||||
case "options_changed":
|
||||
this.onStreamOptionsChanged({ agent, patch: event.patch, flags });
|
||||
return undefined;
|
||||
case "timeline":
|
||||
return this.onStreamTimelineEvent({ agent, event, options, flags });
|
||||
case "turn_completed":
|
||||
@@ -5208,7 +5428,7 @@ export class AgentManager {
|
||||
this.enqueueBackgroundPersist(agent);
|
||||
}
|
||||
|
||||
this.syncFeaturesFromSession(agent);
|
||||
this.syncControls(agent);
|
||||
|
||||
this.logger.trace(
|
||||
{
|
||||
@@ -5230,9 +5450,9 @@ export class AgentManager {
|
||||
});
|
||||
}
|
||||
|
||||
private syncFeaturesFromSession(agent: ManagedAgent): void {
|
||||
if ("session" in agent && agent.session?.features) {
|
||||
agent.features = agent.session.features;
|
||||
private syncControls(agent: ManagedAgent): void {
|
||||
if ("session" in agent && agent.session?.controls) {
|
||||
agent.controls = agent.session.controls;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5478,7 +5698,7 @@ export class AgentManager {
|
||||
config: AgentSessionConfig,
|
||||
options: NormalizeConfigOptions = {},
|
||||
): Promise<AgentSessionConfig> {
|
||||
const normalized: AgentSessionConfig = { ...config };
|
||||
const normalized: AgentSessionConfig = { ...this.withConvertedOptions(config) };
|
||||
|
||||
// Always resolve cwd to absolute path for consistent history file lookup
|
||||
if (normalized.cwd) {
|
||||
@@ -5550,6 +5770,30 @@ export class AgentManager {
|
||||
}
|
||||
}
|
||||
|
||||
/** The adapter a provider id runs on: a custom provider is named by the one it extends. */
|
||||
private adapterOf(provider: AgentProvider): AgentProvider {
|
||||
return resolveAdapter({
|
||||
provider,
|
||||
extendsOf: (id) => this.providerDefinitions.get(id)?.derivedFromProviderId,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Options older data carries are converted for the adapter the provider runs on, before
|
||||
* defaults merge and before anything is stored; nothing past the manager sees the old keys.
|
||||
*/
|
||||
private convertLegacyOptions<T extends ProviderOptions | undefined>(
|
||||
provider: AgentProvider,
|
||||
options: T,
|
||||
): T {
|
||||
return convertLegacyOptions({ provider: this.adapterOf(provider), options }) as T;
|
||||
}
|
||||
|
||||
private withConvertedOptions(config: AgentSessionConfig): AgentSessionConfig {
|
||||
const providerOptions = this.convertLegacyOptions(config.provider, config.providerOptions);
|
||||
return providerOptions === config.providerOptions ? config : { ...config, providerOptions };
|
||||
}
|
||||
|
||||
private async prepareSessionConfig(
|
||||
config: AgentSessionConfig,
|
||||
agentId: string,
|
||||
|
||||
@@ -10,13 +10,16 @@ import {
|
||||
} from "./agent-projections.js";
|
||||
import type { AgentSession } from "./agent-sdk-types.js";
|
||||
import type {
|
||||
AgentFeature,
|
||||
AgentOptionControl,
|
||||
ImportableProviderSession,
|
||||
AgentPermissionRequest,
|
||||
AgentPersistenceHandle,
|
||||
AgentSessionConfig,
|
||||
} from "./agent-sdk-types.js";
|
||||
|
||||
/** A provider with no defaults of its own: the effective options are the agent's own. */
|
||||
const ownOptionsOnly = (_provider: string, own: Record<string, unknown> | undefined) => own ?? {};
|
||||
|
||||
type ManagedAgentOverrides = Omit<Partial<ManagedAgent>, "config" | "pendingPermissions"> & {
|
||||
config?: Partial<AgentSessionConfig>;
|
||||
pendingPermissions?: Map<string, AgentPermissionRequest>;
|
||||
@@ -128,16 +131,6 @@ function createPermission(overrides: Partial<AgentPermissionRequest> = {}): Agen
|
||||
return { ...base, ...overrides };
|
||||
}
|
||||
|
||||
function createFeature(overrides: Partial<AgentFeature> = {}): AgentFeature {
|
||||
return {
|
||||
type: "toggle",
|
||||
id: "fast_mode",
|
||||
label: "Fast mode",
|
||||
value: true,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe("toStoredAgentRecord", () => {
|
||||
it("captures lifecycle metadata, config, and persistence", () => {
|
||||
const agent = createManagedAgent({
|
||||
@@ -391,7 +384,7 @@ describe("toAgentPayload", () => {
|
||||
}),
|
||||
);
|
||||
|
||||
const payload = buildStoredAgentPayload(record, ["codex"]);
|
||||
const payload = buildStoredAgentPayload(record, ["codex"], ownOptionsOnly);
|
||||
|
||||
expect(record.persistence?.metadata).toEqual({
|
||||
conversationId: "conversation-stored",
|
||||
@@ -407,15 +400,81 @@ describe("toAgentPayload", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("projects a closed agent's stored controls and options", () => {
|
||||
const controls: AgentOptionControl[] = [
|
||||
{
|
||||
type: "select",
|
||||
key: "service_tier",
|
||||
label: "Speed",
|
||||
defaultValue: "default",
|
||||
choices: [
|
||||
{ value: "default", label: "Normal" },
|
||||
{ value: "priority", label: "Fast" },
|
||||
],
|
||||
},
|
||||
];
|
||||
const record = toStoredAgentRecord(
|
||||
createManagedAgent({
|
||||
provider: "codex",
|
||||
lifecycle: "closed",
|
||||
controls,
|
||||
config: {
|
||||
provider: "codex",
|
||||
providerOptions: { service_tier: "priority", sandbox_mode: "read-only" },
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
const payload = buildStoredAgentPayload(record, ["codex"], ownOptionsOnly);
|
||||
|
||||
expect(payload.status).toBe("closed");
|
||||
expect(payload.controls).toEqual(controls);
|
||||
expect(payload.options).toEqual({ service_tier: "priority", sandbox_mode: "read-only" });
|
||||
expect(payload.features).toEqual([
|
||||
{
|
||||
type: "select",
|
||||
id: "service_tier",
|
||||
label: "Speed",
|
||||
value: "priority",
|
||||
options: [
|
||||
{ id: "default", label: "Normal", isDefault: true },
|
||||
{ id: "priority", label: "Fast" },
|
||||
],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("projects a closed agent's options with the provider defaults under its own, like a live one", () => {
|
||||
const record = toStoredAgentRecord(
|
||||
createManagedAgent({
|
||||
provider: "claude",
|
||||
lifecycle: "closed",
|
||||
controls: [{ type: "toggle", key: "fast_mode", label: "Fast" }],
|
||||
config: { provider: "claude", providerOptions: {} },
|
||||
}),
|
||||
);
|
||||
const withConfigDefaults = (_provider: string, own: Record<string, unknown> | undefined) => ({
|
||||
fast_mode: true,
|
||||
...own,
|
||||
});
|
||||
|
||||
const payload = buildStoredAgentPayload(record, ["claude"], withConfigDefaults);
|
||||
|
||||
expect(payload.options).toEqual({ fast_mode: true });
|
||||
expect(payload.features).toEqual([
|
||||
{ type: "toggle", id: "fast_mode", label: "Fast", value: true },
|
||||
]);
|
||||
});
|
||||
|
||||
it("carries a stored lastError onto the payload", () => {
|
||||
const record = toStoredAgentRecord(
|
||||
createManagedAgent({ provider: "codex", config: { provider: "codex" }, lastError: "boom" }),
|
||||
);
|
||||
|
||||
expect(buildStoredAgentPayload(record, ["codex"]).lastError).toBe("boom");
|
||||
expect(buildStoredAgentPayload({ ...record, lastError: null }, ["codex"])).not.toHaveProperty(
|
||||
"lastError",
|
||||
);
|
||||
expect(buildStoredAgentPayload(record, ["codex"], ownOptionsOnly).lastError).toBe("boom");
|
||||
expect(
|
||||
buildStoredAgentPayload({ ...record, lastError: null }, ["codex"], ownOptionsOnly),
|
||||
).not.toHaveProperty("lastError");
|
||||
});
|
||||
|
||||
it("omits lastUsage when not available", () => {
|
||||
@@ -474,13 +533,44 @@ describe("toAgentPayload", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("includes features in the snapshot payload", () => {
|
||||
const features = [createFeature()];
|
||||
const agent = createManagedAgent({ features });
|
||||
it("projects controls, effective options, and legacy features from the same source", () => {
|
||||
const controls: AgentOptionControl[] = [
|
||||
{ type: "toggle", key: "fast_mode", label: "Fast mode" },
|
||||
{
|
||||
type: "select",
|
||||
key: "service_tier",
|
||||
label: "Speed",
|
||||
defaultValue: "default",
|
||||
choices: [
|
||||
{ value: "default", label: "Normal" },
|
||||
{ value: "fast", label: "Fast" },
|
||||
],
|
||||
},
|
||||
];
|
||||
// `config.json` supplies fast_mode; the agent itself sets nothing for service_tier.
|
||||
// Options without a control are part of the snapshot too.
|
||||
const agent = createManagedAgent({
|
||||
controls,
|
||||
effectiveOptions: { fast_mode: true, sandbox_mode: "workspace-write" },
|
||||
});
|
||||
|
||||
const payload = toAgentPayload(agent);
|
||||
|
||||
expect(payload.features).toEqual(features);
|
||||
expect(payload.controls).toEqual(controls);
|
||||
expect(payload.options).toEqual({ fast_mode: true, sandbox_mode: "workspace-write" });
|
||||
expect(payload.features).toEqual([
|
||||
{ type: "toggle", id: "fast_mode", label: "Fast mode", value: true },
|
||||
{
|
||||
type: "select",
|
||||
id: "service_tier",
|
||||
label: "Speed",
|
||||
value: "default",
|
||||
options: [
|
||||
{ id: "default", label: "Normal", isDefault: true },
|
||||
{ id: "fast", label: "Fast" },
|
||||
],
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import type {
|
||||
import type { SerializableAgentConfig, StoredAgentRecord } from "./agent-storage.js";
|
||||
import type {
|
||||
AgentCapabilityFlags,
|
||||
AgentFeature,
|
||||
AgentOptionControl,
|
||||
AgentMetadata,
|
||||
AgentMode,
|
||||
AgentPermissionRequest,
|
||||
@@ -18,7 +18,9 @@ import type {
|
||||
AgentUsage,
|
||||
ImportableProviderSession,
|
||||
} from "./agent-sdk-types.js";
|
||||
import type { ProviderOptions } from "@getpaseo/protocol/agent-types";
|
||||
import type { ManagedAgent } from "./agent-manager.js";
|
||||
import { featuresFromControls } from "@getpaseo/protocol/option-controls";
|
||||
import type { JsonValue } from "../json-utils.js";
|
||||
import {
|
||||
isStoredAgentProviderAvailable,
|
||||
@@ -97,7 +99,7 @@ export function toStoredAgentRecord(
|
||||
config: config ?? null,
|
||||
launchEnv: agent.launchEnv ? { ...agent.launchEnv } : undefined,
|
||||
runtimeInfo,
|
||||
features: normalizeFeatures(agent.features),
|
||||
controls: normalizeControls(agent.controls),
|
||||
persistence,
|
||||
lastError: agent.lastError ?? undefined,
|
||||
requiresAttention: agent.attention.requiresAttention,
|
||||
@@ -144,7 +146,12 @@ export function toAgentPayload(
|
||||
capabilities: cloneCapabilities(agent.capabilities),
|
||||
currentModeId: agent.currentModeId,
|
||||
availableModes: cloneAvailableModes(agent.availableModes),
|
||||
features: normalizeFeatures(agent.features),
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01.
|
||||
features: featuresFromControls({ controls: agent.controls, options: agent.effectiveOptions }),
|
||||
...(agent.effectiveOptions
|
||||
? { options: sanitizeEffectiveOptions(agent.effectiveOptions) }
|
||||
: {}),
|
||||
controls: normalizeControls(agent.controls),
|
||||
pendingPermissions: sanitizePendingPermissions(agent.pendingPermissions),
|
||||
persistence: projectPersistenceHandleForWire(agent.persistence),
|
||||
title: options?.title ?? null,
|
||||
@@ -218,9 +225,32 @@ function visibilityFlags(agent: {
|
||||
};
|
||||
}
|
||||
|
||||
/** The options an agent runs with, given the options it owns; see `toAgentPayload`. */
|
||||
export type EffectiveOptionsResolver = (
|
||||
provider: AgentProvider,
|
||||
own: ProviderOptions | undefined,
|
||||
) => ProviderOptions;
|
||||
|
||||
function buildStoredOptionControls(
|
||||
record: StoredAgentRecord,
|
||||
effectiveOptionsFor: EffectiveOptionsResolver,
|
||||
): Pick<AgentSnapshotPayload, "features" | "options" | "controls"> {
|
||||
const controls = normalizeControls(record.controls);
|
||||
const options = sanitizeEffectiveOptions(
|
||||
effectiveOptionsFor(record.provider, record.config?.providerOptions ?? undefined),
|
||||
);
|
||||
return {
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01.
|
||||
features: featuresFromControls({ controls, options }),
|
||||
options,
|
||||
controls,
|
||||
};
|
||||
}
|
||||
|
||||
export function buildStoredAgentPayload(
|
||||
record: StoredAgentRecord,
|
||||
validProviders: Iterable<AgentProvider>,
|
||||
effectiveOptionsFor: EffectiveOptionsResolver,
|
||||
): AgentSnapshotPayload {
|
||||
const defaultCapabilities = {
|
||||
supportsStreaming: false,
|
||||
@@ -239,6 +269,7 @@ export function buildStoredAgentPayload(
|
||||
const lastUserMessageAt = record.lastUserMessageAt ? new Date(record.lastUserMessageAt) : null;
|
||||
|
||||
const runtimeInfo = buildStoredRuntimeInfo(record);
|
||||
const optionControls = buildStoredOptionControls(record, effectiveOptionsFor);
|
||||
const providerAvailable = isStoredAgentProviderAvailable(record, validProviders);
|
||||
const persistence = projectPersistenceHandleForWire(
|
||||
buildStoredPersistenceHandle(record, validProviders),
|
||||
@@ -263,6 +294,7 @@ export function buildStoredAgentPayload(
|
||||
capabilities: defaultCapabilities,
|
||||
currentModeId: record.lastModeId ?? null,
|
||||
availableModes: [],
|
||||
...optionControls,
|
||||
pendingPermissions: [],
|
||||
persistence,
|
||||
title: record.title ?? null,
|
||||
@@ -387,12 +419,6 @@ function buildSerializableConfig(config: AgentSessionConfig): SerializableAgentC
|
||||
if (config.thinkingOptionId) {
|
||||
serializable.thinkingOptionId = config.thinkingOptionId;
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(config, "featureValues")) {
|
||||
const featureValues = sanitizeMetadata(config.featureValues);
|
||||
if (featureValues !== undefined) {
|
||||
serializable.featureValues = featureValues;
|
||||
}
|
||||
}
|
||||
if (config.providerOptions !== undefined) {
|
||||
const providerOptions = sanitizeOptionalJson(config.providerOptions);
|
||||
if (providerOptions && isJsonObject(providerOptions)) {
|
||||
@@ -468,8 +494,15 @@ function cloneAvailableModes(modes: AgentMode[]): AgentMode[] {
|
||||
return modes.map((mode) => ({ ...mode }));
|
||||
}
|
||||
|
||||
function normalizeFeatures(features: AgentFeature[] | null | undefined): AgentFeature[] {
|
||||
return Array.isArray(features) ? features.map((feature) => ({ ...feature })) : [];
|
||||
function normalizeControls(
|
||||
controls: AgentOptionControl[] | null | undefined,
|
||||
): AgentOptionControl[] {
|
||||
return Array.isArray(controls) ? controls.map((control) => ({ ...control })) : [];
|
||||
}
|
||||
|
||||
function sanitizeEffectiveOptions(options: Record<string, unknown>): ProviderOptions {
|
||||
const sanitized = sanitizeOptionalJson(options);
|
||||
return sanitized && isJsonObject(sanitized) ? sanitized : {};
|
||||
}
|
||||
|
||||
function sanitizeOptionalJson(value: unknown): JsonValue | undefined {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type {
|
||||
AgentFeature,
|
||||
AgentFeatureSelect,
|
||||
AgentFeatureToggle,
|
||||
AgentOptionControl,
|
||||
AgentOptionSelectControl,
|
||||
AgentOptionToggleControl,
|
||||
AgentProviderNotice,
|
||||
AgentTaskItem,
|
||||
JsonValue,
|
||||
@@ -13,9 +13,9 @@ import type { AgentAttachment } from "@getpaseo/protocol/messages";
|
||||
import type { PaseoToolCatalog } from "./tools/types.js";
|
||||
|
||||
export type {
|
||||
AgentFeature,
|
||||
AgentFeatureSelect,
|
||||
AgentFeatureToggle,
|
||||
AgentOptionControl,
|
||||
AgentOptionSelectControl,
|
||||
AgentOptionToggleControl,
|
||||
AgentProviderNotice,
|
||||
AgentTaskItem,
|
||||
};
|
||||
@@ -148,7 +148,7 @@ export interface AgentCreateConfigParent {
|
||||
export interface ResolveAgentCreateConfigInput {
|
||||
provider: AgentProvider;
|
||||
requestedMode: string | undefined;
|
||||
featureValues: Record<string, unknown> | undefined;
|
||||
providerOptions: ProviderOptions | undefined;
|
||||
parent: AgentCreateConfigParent | null;
|
||||
unattended: boolean;
|
||||
availableModes: AgentMode[] | undefined;
|
||||
@@ -156,13 +156,13 @@ export interface ResolveAgentCreateConfigInput {
|
||||
|
||||
export interface ResolveAgentCreateConfigResult {
|
||||
modeId: string | undefined;
|
||||
featureValues: Record<string, unknown> | undefined;
|
||||
providerOptions: ProviderOptions | undefined;
|
||||
}
|
||||
|
||||
export interface AgentCreateConfigUnattendedInput {
|
||||
modeId: string | null;
|
||||
config: AgentSessionConfig;
|
||||
features?: AgentFeature[];
|
||||
controls?: AgentOptionControl[];
|
||||
availableModes: AgentMode[];
|
||||
}
|
||||
|
||||
@@ -429,6 +429,14 @@ export type AgentStreamEvent =
|
||||
provider: AgentProvider;
|
||||
thinkingOptionId: string | null;
|
||||
}
|
||||
/**
|
||||
* The provider changed options on its own: after `createSession`/`resumeSession` or
|
||||
* `applyOptions` it ended up different from what it was given, or later it changed a setting
|
||||
* itself. The daemon stores the patch and forwards it; it does not undo it. `null` removes the
|
||||
* agent's own value. Only for changes that happen on the provider's own initiative: the result
|
||||
* of opening goes in `openOptionsPatch` and the result of `applyOptions` is its return value.
|
||||
*/
|
||||
| { type: "options_changed"; provider: AgentProvider; patch: Record<string, unknown> }
|
||||
| {
|
||||
type: "turn_failed";
|
||||
provider: AgentProvider;
|
||||
@@ -610,7 +618,6 @@ export interface AgentSessionConfig {
|
||||
modeId?: string;
|
||||
model?: string;
|
||||
thinkingOptionId?: string;
|
||||
featureValues?: Record<string, unknown>;
|
||||
title?: string | null;
|
||||
providerOptions?: ProviderOptions;
|
||||
toolPolicy?: ToolPolicy;
|
||||
@@ -679,7 +686,14 @@ export interface AgentSession {
|
||||
readonly provider: AgentProvider;
|
||||
readonly id: string | null;
|
||||
readonly capabilities: AgentCapabilityFlags;
|
||||
readonly features?: AgentFeature[];
|
||||
/** Composer controls over top-level option keys. Values come from the agent's effective options. */
|
||||
readonly controls?: AgentOptionControl[];
|
||||
/**
|
||||
* How the session ended up different from the options it was opened with, as a patch (`null`
|
||||
* removes a key). Set by the time `createSession`/`resumeSession` resolves; the daemon stores it
|
||||
* before the agent is published.
|
||||
*/
|
||||
readonly openOptionsPatch?: Record<string, unknown>;
|
||||
/** New provider-owned rows to commit on registration. streamHistory must also
|
||||
* replay them at their original timestamps; restored sessions omit old rows. */
|
||||
readonly initialTimeline?: ImportedTimelineEntry[];
|
||||
@@ -714,7 +728,20 @@ export interface AgentSession {
|
||||
listCommands?(): Promise<AgentSlashCommand[]>;
|
||||
setModel?(modelId: string | null): Promise<void>;
|
||||
setThinkingOption?(thinkingOptionId: string | null): Promise<void | AgentProviderNotice>;
|
||||
setFeature?(featureId: string, value: unknown): Promise<void>;
|
||||
/**
|
||||
* Apply an options patch. `options` holds only the keys the patch touches, resolved against
|
||||
* the `config.json` defaults; `null` means nothing is set for the key, so return it to the
|
||||
* session's own default if that can be done. Leave every other setting alone. Throw to reject a
|
||||
* value, or a key the running session cannot apply (one the provider reads only when it
|
||||
* opens): the daemon stores the patch only when this resolves, so a stored option always
|
||||
* describes what runs, and the call is all-or-nothing.
|
||||
* Emit nothing from here. Return the options the session ended up with when they differ from
|
||||
* the request (a patch, `null` removes a key), for example a value it kept because it could not
|
||||
* be reverted; the daemon stores it together with the patch. When a throw leaves the session's
|
||||
* state moved anyway, report the moved values once as `options_changed` after the call has
|
||||
* ended, so the stored options still match what runs.
|
||||
*/
|
||||
applyOptions?(options: ProviderOptions): Promise<Record<string, unknown> | void>;
|
||||
revertConversation?(input: { messageId: string }): Promise<void>;
|
||||
revertFiles?(input: { messageId: string }): Promise<void>;
|
||||
revertBoth?(input: { messageId: string }): Promise<void>;
|
||||
@@ -764,11 +791,17 @@ export interface ResolveAgentDefaultModeInput {
|
||||
export interface AgentClient {
|
||||
readonly provider: AgentProvider;
|
||||
readonly capabilities: AgentCapabilityFlags;
|
||||
/**
|
||||
* Create the agent with `config.providerOptions` (defaults already merged in). Emit nothing
|
||||
* about options while creating. If the agent ended up different from the options, say so in the
|
||||
* session's `openOptionsPatch`.
|
||||
*/
|
||||
createSession(
|
||||
config: AgentSessionConfig,
|
||||
launchContext?: AgentLaunchContext,
|
||||
options?: AgentCreateSessionOptions,
|
||||
): Promise<AgentSession>;
|
||||
/** Same contract as `createSession`: open with the options, report any difference in `openOptionsPatch`. */
|
||||
resumeSession(
|
||||
handle: AgentPersistenceHandle,
|
||||
overrides?: Partial<AgentSessionConfig>,
|
||||
@@ -797,7 +830,9 @@ export interface AgentClient {
|
||||
resolveCreateConfig?(input: ResolveAgentCreateConfigInput): ResolveAgentCreateConfigResult;
|
||||
isCreateConfigUnattended?(input: AgentCreateConfigUnattendedInput): boolean;
|
||||
listCommands?(config: AgentSessionConfig): Promise<AgentSlashCommand[]>;
|
||||
listFeatures?(config: AgentSessionConfig): Promise<AgentFeature[]>;
|
||||
listControls?(config: AgentSessionConfig): Promise<AgentOptionControl[]>;
|
||||
/** Effective options: provider defaults from `config.json` deep-merged with the agent's own. */
|
||||
effectiveOptions?(own: ProviderOptions | undefined): ProviderOptions;
|
||||
listImportableSessions?(
|
||||
options?: ListImportableSessionsOptions,
|
||||
): Promise<ImportableProviderSession[]>;
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { describe, expect, test, beforeEach, afterEach } from "vitest";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { mkdtempSync, readdirSync, rmSync } from "node:fs";
|
||||
import { existsSync, mkdtempSync, readdirSync, rmSync } from "node:fs";
|
||||
import { promises as fs } from "node:fs";
|
||||
import { Session as InspectorSession } from "node:inspector/promises";
|
||||
import type { HeapProfiler } from "node:inspector";
|
||||
|
||||
import { createTestLogger } from "../../test-utils/test-logger.js";
|
||||
import { AgentStorage } from "./agent-storage.js";
|
||||
@@ -44,9 +46,6 @@ function buildManagedAgentConfig(
|
||||
systemPrompt: configOverrides.systemPrompt,
|
||||
mcpServers: configOverrides.mcpServers,
|
||||
};
|
||||
if (Object.prototype.hasOwnProperty.call(configOverrides, "featureValues")) {
|
||||
config.featureValues = configOverrides.featureValues;
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -132,6 +131,14 @@ function createManagedAgent(overrides: ManagedAgentOverrides = {}): ManagedAgent
|
||||
};
|
||||
}
|
||||
|
||||
function findRecordFile(baseDir: string, agentId: string): string {
|
||||
for (const entry of readdirSync(baseDir, { withFileTypes: true })) {
|
||||
const candidate = path.join(baseDir, entry.name, `${agentId}.json`);
|
||||
if (entry.isDirectory() && existsSync(candidate)) return candidate;
|
||||
}
|
||||
throw new Error(`No stored record for ${agentId}`);
|
||||
}
|
||||
|
||||
describe("AgentStorage", () => {
|
||||
let tmpDir: string;
|
||||
let storagePath: string;
|
||||
@@ -148,6 +155,101 @@ describe("AgentStorage", () => {
|
||||
rmSync(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
test("workspace and active queries follow updates, removal, and reload", async () => {
|
||||
const base = {
|
||||
provider: "codex",
|
||||
cwd: tmpDir,
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
updatedAt: "2026-01-01T00:00:00.000Z",
|
||||
labels: {},
|
||||
};
|
||||
await storage.upsert({
|
||||
...base,
|
||||
id: "a",
|
||||
workspaceId: "one",
|
||||
lastUserMessageAt: base.createdAt,
|
||||
});
|
||||
await storage.upsert({ ...base, id: "b", workspaceId: "two", archivedAt: base.createdAt });
|
||||
expect((await storage.listActive()).map((r) => r.id)).toEqual(["a"]);
|
||||
await storage.upsert({
|
||||
...base,
|
||||
id: "a",
|
||||
workspaceId: "two",
|
||||
lastUserMessageAt: base.updatedAt,
|
||||
});
|
||||
expect(await storage.listByWorkspaces(["one"])).toEqual([]);
|
||||
expect((await storage.listByWorkspaces(["two"])).map((r) => r.id)).toEqual(["a"]);
|
||||
expect(
|
||||
(await storage.listByWorkspaces(["two"], { includeArchived: true })).map((r) => r.id).sort(),
|
||||
).toEqual(["a", "b"]);
|
||||
expect(await storage.lastUserMessageAtByWorkspace(["one", "two"])).toEqual(
|
||||
new Map([["two", base.createdAt]]),
|
||||
);
|
||||
await storage.flush();
|
||||
const reloaded = new AgentStorage(storagePath, createTestLogger());
|
||||
expect((await reloaded.listActive()).map((r) => r.id)).toEqual(["a"]);
|
||||
expect(
|
||||
await reloaded.lastUserMessageAtByWorkspace(["two"], { excludeAgentIds: ["a"] }),
|
||||
).toEqual(new Map());
|
||||
await reloaded.remove("a");
|
||||
expect(await reloaded.listActive()).toEqual([]);
|
||||
expect(await reloaded.lastUserMessageAtByWorkspace(["two"])).toEqual(new Map());
|
||||
});
|
||||
|
||||
test("single-agent lookups keep allocations bounded with a large stored history", async () => {
|
||||
await fs.mkdir(storagePath, { recursive: true });
|
||||
const record = {
|
||||
id: "history-0",
|
||||
provider: "codex",
|
||||
cwd: tmpDir,
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
updatedAt: "2026-01-01T00:00:00.000Z",
|
||||
labels: {},
|
||||
lastStatus: "idle",
|
||||
};
|
||||
for (let offset = 0; offset < 2048; offset += 64) {
|
||||
await Promise.all(
|
||||
Array.from({ length: 64 }, (_, index) => {
|
||||
const id = `history-${offset + index}`;
|
||||
return fs.writeFile(
|
||||
path.join(storagePath, `${id}.json`),
|
||||
JSON.stringify({ ...record, id }),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
await storage.initialize();
|
||||
expect(await storage.listAll()).toHaveLength(2048);
|
||||
const expected = await storage.get(record.id);
|
||||
expect(expected).toMatchObject(record);
|
||||
|
||||
const inspector = new InspectorSession();
|
||||
inspector.connect();
|
||||
let allocatedBytes = 0;
|
||||
let matches = 0;
|
||||
try {
|
||||
await inspector.post("HeapProfiler.startSampling", {
|
||||
samplingInterval: 16384,
|
||||
includeObjectsCollectedByMajorGC: true,
|
||||
includeObjectsCollectedByMinorGC: true,
|
||||
});
|
||||
for (let index = 0; index < 1000; index++) {
|
||||
if ((await storage.get(record.id)) === expected) matches++;
|
||||
}
|
||||
const { profile } = await inspector.post("HeapProfiler.stopSampling");
|
||||
const sum = (node: HeapProfiler.SamplingHeapProfileNode): number =>
|
||||
node.selfSize + node.children.reduce((bytes, child) => bytes + sum(child), 0);
|
||||
allocatedBytes = sum(profile.head);
|
||||
} finally {
|
||||
inspector.disconnect();
|
||||
}
|
||||
|
||||
expect(matches).toBe(1000);
|
||||
// Copying this history on every lookup allocates >16 MiB. Allow generous
|
||||
// sampling/runtime overhead without relying on the host's execution speed.
|
||||
expect(allocatedBytes).toBeLessThan(4 * 1024 * 1024);
|
||||
});
|
||||
|
||||
test("applySnapshot persists configs and snapshot metadata", async () => {
|
||||
await storage.applySnapshot(
|
||||
createManagedAgent({
|
||||
@@ -172,7 +274,7 @@ describe("AgentStorage", () => {
|
||||
}),
|
||||
);
|
||||
|
||||
const records = await storage.list();
|
||||
const records = await storage.listAll();
|
||||
expect(records).toHaveLength(1);
|
||||
const [record] = records;
|
||||
expect(record.provider).toBe("claude");
|
||||
@@ -189,68 +291,83 @@ describe("AgentStorage", () => {
|
||||
expect(record.lastModeId).toBe("coding");
|
||||
expect(record.lastStatus).toBe("idle");
|
||||
|
||||
const reloaded = new AgentStorage(storagePath, logger);
|
||||
const [persisted] = await reloaded.list();
|
||||
const reloaded = new AgentStorage(storagePath, createTestLogger());
|
||||
const [persisted] = await reloaded.listAll();
|
||||
expect(persisted.cwd).toBe("/tmp/project");
|
||||
expect(persisted.config?.providerOptions).toEqual({ allowedTools: ["Read"] });
|
||||
});
|
||||
|
||||
test("applySnapshot stores and reloads featureValues when present", async () => {
|
||||
test("applySnapshot stores and reloads composer values as providerOptions", async () => {
|
||||
await storage.applySnapshot(
|
||||
createManagedAgent({
|
||||
id: "agent-feature-values",
|
||||
config: {
|
||||
featureValues: {
|
||||
fast_mode: true,
|
||||
},
|
||||
},
|
||||
id: "agent-provider-options",
|
||||
config: { providerOptions: { fast_mode: true } },
|
||||
}),
|
||||
);
|
||||
|
||||
const record = await storage.get("agent-feature-values");
|
||||
expect(record?.config?.featureValues).toEqual({ fast_mode: true });
|
||||
|
||||
const reloaded = new AgentStorage(storagePath, logger);
|
||||
const persisted = await reloaded.get("agent-feature-values");
|
||||
expect(persisted?.config?.featureValues).toEqual({ fast_mode: true });
|
||||
expect(buildSessionConfig(persisted!).featureValues).toEqual({ fast_mode: true });
|
||||
});
|
||||
|
||||
test("applySnapshot keeps featureValues absent when they were never set", async () => {
|
||||
await storage.applySnapshot(
|
||||
createManagedAgent({
|
||||
id: "agent-no-feature-values",
|
||||
}),
|
||||
);
|
||||
|
||||
const reloaded = new AgentStorage(storagePath, logger);
|
||||
const persisted = await reloaded.get("agent-no-feature-values");
|
||||
expect(persisted?.config?.featureValues).toBeUndefined();
|
||||
expect(buildSessionConfig(persisted!).featureValues).toBeUndefined();
|
||||
});
|
||||
|
||||
test("buildConfigOverrides includes featureValues when present in stored config", async () => {
|
||||
await storage.applySnapshot(
|
||||
createManagedAgent({
|
||||
id: "agent-resume-overrides",
|
||||
config: {
|
||||
featureValues: {
|
||||
fast_mode: true,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
const record = await storage.get("agent-resume-overrides");
|
||||
expect(record).not.toBeNull();
|
||||
expect(buildConfigOverrides(record!)).toMatchObject({
|
||||
const reloaded = new AgentStorage(storagePath, createTestLogger());
|
||||
const persisted = await reloaded.get("agent-provider-options");
|
||||
expect(persisted?.config?.providerOptions).toEqual({ fast_mode: true });
|
||||
expect(buildSessionConfig(persisted!).providerOptions).toEqual({ fast_mode: true });
|
||||
expect(buildConfigOverrides(persisted!)).toMatchObject({
|
||||
cwd: "/tmp/project",
|
||||
featureValues: {
|
||||
fast_mode: true,
|
||||
},
|
||||
providerOptions: { fast_mode: true },
|
||||
});
|
||||
});
|
||||
|
||||
test("a record stored with featureValues loads them in providerOptions", async () => {
|
||||
await storage.applySnapshot(createManagedAgent({ id: "agent-legacy" }));
|
||||
const file = findRecordFile(storagePath, "agent-legacy");
|
||||
const stored = JSON.parse(await fs.readFile(file, "utf8"));
|
||||
stored.config.providerOptions = { allowedTools: ["Read"], fast_mode: false };
|
||||
stored.config.featureValues = { fast_mode: true, service_tier: "fast" };
|
||||
delete stored.controls;
|
||||
stored.features = [
|
||||
{ type: "toggle", id: "fast_mode", label: "Fast mode", value: true },
|
||||
{
|
||||
type: "select",
|
||||
id: "service_tier",
|
||||
label: "Speed",
|
||||
value: "fast",
|
||||
options: [
|
||||
{ id: "default", label: "Normal", isDefault: true },
|
||||
{ id: "fast", label: "Fast" },
|
||||
],
|
||||
},
|
||||
];
|
||||
await fs.writeFile(file, JSON.stringify(stored));
|
||||
|
||||
const reloaded = new AgentStorage(storagePath, createTestLogger());
|
||||
const persisted = await reloaded.get("agent-legacy");
|
||||
|
||||
// An explicit providerOptions key wins over the same featureValues key.
|
||||
expect(persisted?.config?.providerOptions).toEqual({
|
||||
allowedTools: ["Read"],
|
||||
fast_mode: false,
|
||||
service_tier: "fast",
|
||||
});
|
||||
expect(persisted?.config).not.toHaveProperty("featureValues");
|
||||
expect(persisted).not.toHaveProperty("features");
|
||||
expect(persisted?.controls).toEqual([
|
||||
{ type: "toggle", key: "fast_mode", label: "Fast mode" },
|
||||
{
|
||||
type: "select",
|
||||
key: "service_tier",
|
||||
label: "Speed",
|
||||
defaultValue: "default",
|
||||
choices: [
|
||||
{ value: "default", label: "Normal" },
|
||||
{ value: "fast", label: "Fast" },
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
||||
await reloaded.applySnapshot(createManagedAgent({ id: "agent-legacy" }));
|
||||
const rewritten = JSON.parse(await fs.readFile(file, "utf8"));
|
||||
expect(rewritten.config).not.toHaveProperty("featureValues");
|
||||
expect(rewritten).not.toHaveProperty("features");
|
||||
});
|
||||
|
||||
test("applySnapshot preserves original createdAt timestamp", async () => {
|
||||
const agentId = "agent-created-at";
|
||||
const firstTimestamp = new Date("2025-01-01T00:00:00.000Z");
|
||||
@@ -312,7 +429,7 @@ describe("AgentStorage", () => {
|
||||
const current = await storage.get("agent-2");
|
||||
expect(current?.title).toBe("Fix Login Bug");
|
||||
|
||||
const reloaded = new AgentStorage(storagePath, logger);
|
||||
const reloaded = new AgentStorage(storagePath, createTestLogger());
|
||||
const persisted = await reloaded.get("agent-2");
|
||||
expect(persisted?.title).toBe("Fix Login Bug");
|
||||
});
|
||||
@@ -415,7 +532,7 @@ describe("AgentStorage", () => {
|
||||
);
|
||||
|
||||
// Registry should return all agents - filtering is done at the manager level
|
||||
const records = await storage.list();
|
||||
const records = await storage.listAll();
|
||||
expect(records).toHaveLength(2);
|
||||
});
|
||||
|
||||
@@ -486,12 +603,12 @@ describe("AgentStorage", () => {
|
||||
);
|
||||
|
||||
// Reload the registry from disk
|
||||
const reloaded = new AgentStorage(storagePath, logger);
|
||||
const reloaded = new AgentStorage(storagePath, createTestLogger());
|
||||
const record = await reloaded.get("internal-agent");
|
||||
expect(record?.internal).toBe(true);
|
||||
|
||||
// Registry returns all agents - filtering happens at manager level
|
||||
const records = await reloaded.list();
|
||||
const records = await reloaded.listAll();
|
||||
expect(records).toHaveLength(1);
|
||||
expect(records[0]?.internal).toBe(true);
|
||||
});
|
||||
@@ -543,8 +660,8 @@ describe("AgentStorage", () => {
|
||||
);
|
||||
|
||||
// Force a reload so the registry has to discover from disk (and may choose either copy).
|
||||
const reloaded = new AgentStorage(storagePath, logger);
|
||||
const before = await reloaded.list();
|
||||
const reloaded = new AgentStorage(storagePath, createTestLogger());
|
||||
const before = await reloaded.listAll();
|
||||
expect(before.map((r) => r.id)).toContain(agentId);
|
||||
|
||||
await reloaded.remove(agentId);
|
||||
@@ -571,8 +688,8 @@ describe("AgentStorage", () => {
|
||||
|
||||
expect(await hasAnyRecordFile()).toBe(false);
|
||||
|
||||
const afterReload = new AgentStorage(storagePath, logger);
|
||||
const after = await afterReload.list();
|
||||
const afterReload = new AgentStorage(storagePath, createTestLogger());
|
||||
const after = await afterReload.listAll();
|
||||
expect(after.some((r) => r.id === agentId)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,17 +4,20 @@ import { z } from "zod";
|
||||
import type { Logger } from "pino";
|
||||
|
||||
import { writeJsonFileAtomic } from "../atomic-file.js";
|
||||
import { AgentFeatureSchema, AgentStatusSchema } from "../messages.js";
|
||||
import { AgentFeatureSchema, AgentOptionControlSchema, AgentStatusSchema } from "../messages.js";
|
||||
import { toStoredAgentRecord } from "./agent-projections.js";
|
||||
import type { ManagedAgent } from "./agent-manager.js";
|
||||
import type { AgentSessionConfig } from "./agent-sdk-types.js";
|
||||
import { AgentOwnerSchema, daemonExecutionKey, type DaemonAgentOwner } from "./agent-owner.js";
|
||||
import { controlsFromFeatures } from "@getpaseo/protocol/option-controls";
|
||||
import { foldFeatureValues } from "./option-controls.js";
|
||||
|
||||
const SERIALIZABLE_CONFIG_SCHEMA = z
|
||||
.object({
|
||||
modeId: z.string().nullable().optional(),
|
||||
model: z.string().nullable().optional(),
|
||||
thinkingOptionId: z.string().nullable().optional(),
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01. Read-only; folded on parse.
|
||||
featureValues: z.record(z.string(), z.unknown()).nullable().optional(),
|
||||
providerOptions: z.record(z.string(), z.unknown()).nullable().optional(),
|
||||
toolPolicy: z
|
||||
@@ -42,7 +45,7 @@ const PERSISTENCE_HANDLE_SCHEMA = z
|
||||
.nullable()
|
||||
.optional();
|
||||
|
||||
const STORED_AGENT_SCHEMA = z.object({
|
||||
const RAW_STORED_AGENT_SCHEMA = z.object({
|
||||
id: z.string(),
|
||||
provider: z.string(),
|
||||
cwd: z.string(),
|
||||
@@ -68,6 +71,8 @@ const STORED_AGENT_SCHEMA = z.object({
|
||||
extra: z.record(z.string(), z.unknown()).optional(),
|
||||
})
|
||||
.optional(),
|
||||
controls: z.array(AgentOptionControlSchema).optional(),
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01. Read-only; becomes controls.
|
||||
features: z.array(AgentFeatureSchema).optional(),
|
||||
persistence: PERSISTENCE_HANDLE_SCHEMA,
|
||||
lastError: z.string().nullable().optional(),
|
||||
@@ -85,14 +90,32 @@ export type SerializableAgentConfig = Pick<
|
||||
| "modeId"
|
||||
| "model"
|
||||
| "thinkingOptionId"
|
||||
| "featureValues"
|
||||
| "providerOptions"
|
||||
| "toolPolicy"
|
||||
| "systemPrompt"
|
||||
| "mcpServers"
|
||||
>;
|
||||
|
||||
export type StoredAgentRecord = z.infer<typeof STORED_AGENT_SCHEMA>;
|
||||
type RawStoredAgentRecord = z.infer<typeof RAW_STORED_AGENT_SCHEMA>;
|
||||
type RawStoredAgentConfig = NonNullable<RawStoredAgentRecord["config"]>;
|
||||
|
||||
/** Records carry `providerOptions` and `controls` only; legacy fields are folded when read. */
|
||||
export type StoredAgentRecord = Omit<RawStoredAgentRecord, "config" | "features"> & {
|
||||
config?: Omit<RawStoredAgentConfig, "featureValues"> | null;
|
||||
};
|
||||
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01.
|
||||
function foldLegacyRecordFields(record: RawStoredAgentRecord): StoredAgentRecord {
|
||||
const { features, config, controls, ...rest } = record;
|
||||
return {
|
||||
...rest,
|
||||
...(config ? { config: foldFeatureValues(config) } : { config }),
|
||||
...((controls ?? features) ? { controls: controls ?? controlsFromFeatures(features) } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
const STORED_AGENT_SCHEMA = RAW_STORED_AGENT_SCHEMA.transform(foldLegacyRecordFields);
|
||||
|
||||
export function parseStoredAgentRecord(value: unknown): StoredAgentRecord {
|
||||
return STORED_AGENT_SCHEMA.parse(value);
|
||||
}
|
||||
@@ -105,9 +128,14 @@ export class AgentStorage {
|
||||
private deleting: Set<string> = new Set();
|
||||
private daemonAgentIdsByExecution: Map<string, string> = new Map();
|
||||
private daemonExecutionKeysByAgentId: Map<string, string> = new Map();
|
||||
private readonly idsByWorkspace = new Map<string, Set<string>>();
|
||||
private readonly workspaceById = new Map<string, string>();
|
||||
private readonly activeIds = new Set<string>();
|
||||
private readonly promptTimeByAgent = new Map<string, string>();
|
||||
private readonly promptTimes = new Map<string, string>();
|
||||
private loaded = false;
|
||||
private baseDir: string;
|
||||
private loadPromise: Promise<StoredAgentRecord[]> | null = null;
|
||||
private loadPromise: Promise<void> | null = null;
|
||||
private logger: Logger;
|
||||
|
||||
constructor(baseDir: string, logger: Logger) {
|
||||
@@ -119,11 +147,119 @@ export class AgentStorage {
|
||||
await this.load();
|
||||
}
|
||||
|
||||
async list(): Promise<StoredAgentRecord[]> {
|
||||
async listAll(): Promise<StoredAgentRecord[]> {
|
||||
await this.load();
|
||||
return Array.from(this.cache.values());
|
||||
}
|
||||
|
||||
async listActive(options?: { includeArchived?: boolean }): Promise<StoredAgentRecord[]> {
|
||||
await this.load();
|
||||
return Array.from(
|
||||
options?.includeArchived ? this.cache.keys() : this.activeIds,
|
||||
(id) => this.cache.get(id)!,
|
||||
);
|
||||
}
|
||||
|
||||
async listByWorkspaces(
|
||||
workspaceIds: Iterable<string>,
|
||||
options?: { includeArchived?: boolean },
|
||||
): Promise<StoredAgentRecord[]> {
|
||||
await this.load();
|
||||
const records: StoredAgentRecord[] = [];
|
||||
for (const workspaceId of new Set(workspaceIds)) {
|
||||
for (const id of this.idsByWorkspace.get(workspaceId) ?? []) {
|
||||
const record = this.cache.get(id)!;
|
||||
if (options?.includeArchived || !record.archivedAt) records.push(record);
|
||||
}
|
||||
}
|
||||
return records;
|
||||
}
|
||||
|
||||
async lastUserMessageAtByWorkspace(
|
||||
workspaceIds?: Iterable<string>,
|
||||
options?: { excludeAgentIds?: Iterable<string> },
|
||||
): Promise<ReadonlyMap<string, string>> {
|
||||
await this.load();
|
||||
const times = new Map<string, string>();
|
||||
const excluded = new Set(options?.excludeAgentIds);
|
||||
const affected = new Set(Array.from(excluded, (id) => this.workspaceById.get(id)));
|
||||
for (const id of workspaceIds ?? this.promptTimes.keys()) {
|
||||
let at = this.promptTimes.get(id);
|
||||
if (affected.has(id)) {
|
||||
at = undefined;
|
||||
for (const agentId of this.idsByWorkspace.get(id) ?? []) {
|
||||
const record = this.cache.get(agentId)!;
|
||||
if (
|
||||
!excluded.has(agentId) &&
|
||||
!record.internal &&
|
||||
!record.background &&
|
||||
record.lastUserMessageAt &&
|
||||
record.lastUserMessageAt > (at ?? "")
|
||||
) {
|
||||
at = record.lastUserMessageAt;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (at) times.set(id, at);
|
||||
}
|
||||
return times;
|
||||
}
|
||||
|
||||
private indexWorkspace(record: StoredAgentRecord): void {
|
||||
const previous = this.workspaceById.get(record.id);
|
||||
if (previous) this.idsByWorkspace.get(previous)?.delete(record.id);
|
||||
this.workspaceById.delete(record.id);
|
||||
this.activeIds.delete(record.id);
|
||||
if (!record.archivedAt) this.activeIds.add(record.id);
|
||||
if (record.workspaceId) {
|
||||
const ids = this.idsByWorkspace.get(record.workspaceId) ?? new Set<string>();
|
||||
ids.add(record.id);
|
||||
this.idsByWorkspace.set(record.workspaceId, ids);
|
||||
this.workspaceById.set(record.id, record.workspaceId);
|
||||
}
|
||||
this.indexPromptTime(record, previous);
|
||||
}
|
||||
|
||||
private indexPromptTime(record: StoredAgentRecord, previous: string | undefined): void {
|
||||
const previousTime = this.promptTimeByAgent.get(record.id);
|
||||
const nextTime =
|
||||
!record.internal && !record.background ? (record.lastUserMessageAt ?? undefined) : undefined;
|
||||
if (nextTime) this.promptTimeByAgent.set(record.id, nextTime);
|
||||
else this.promptTimeByAgent.delete(record.id);
|
||||
if (previous === record.workspaceId && previousTime === nextTime) return;
|
||||
if (
|
||||
previous &&
|
||||
previousTime &&
|
||||
this.promptTimes.get(previous) === previousTime &&
|
||||
(previous !== record.workspaceId || !nextTime || nextTime < previousTime)
|
||||
) {
|
||||
this.refreshPromptTime(previous);
|
||||
}
|
||||
if (
|
||||
record.workspaceId &&
|
||||
nextTime &&
|
||||
nextTime > (this.promptTimes.get(record.workspaceId) ?? "")
|
||||
) {
|
||||
this.promptTimes.set(record.workspaceId, nextTime);
|
||||
}
|
||||
}
|
||||
|
||||
private refreshPromptTime(workspaceId: string): void {
|
||||
this.promptTimes.delete(workspaceId);
|
||||
let latest = "";
|
||||
for (const id of this.idsByWorkspace.get(workspaceId) ?? []) {
|
||||
const record = this.cache.get(id)!;
|
||||
if (
|
||||
!record.internal &&
|
||||
!record.background &&
|
||||
record.lastUserMessageAt &&
|
||||
record.lastUserMessageAt > latest
|
||||
)
|
||||
latest = record.lastUserMessageAt;
|
||||
}
|
||||
if (latest) this.promptTimes.set(workspaceId, latest);
|
||||
}
|
||||
|
||||
async get(agentId: string): Promise<StoredAgentRecord | null> {
|
||||
await this.load();
|
||||
return this.cache.get(agentId) ?? null;
|
||||
@@ -143,8 +279,7 @@ export class AgentStorage {
|
||||
}
|
||||
|
||||
async listByWorkspace(workspaceId: string): Promise<StoredAgentRecord[]> {
|
||||
await this.load();
|
||||
return Array.from(this.cache.values()).filter((record) => record.workspaceId === workspaceId);
|
||||
return this.listByWorkspaces([workspaceId], { includeArchived: true });
|
||||
}
|
||||
|
||||
async findByDaemonExecution(owner: DaemonAgentOwner): Promise<StoredAgentRecord | null> {
|
||||
@@ -234,6 +369,14 @@ export class AgentStorage {
|
||||
}),
|
||||
);
|
||||
|
||||
const workspaceId = this.workspaceById.get(agentId);
|
||||
this.workspaceById.delete(agentId);
|
||||
this.promptTimeByAgent.delete(agentId);
|
||||
this.activeIds.delete(agentId);
|
||||
if (workspaceId) {
|
||||
this.idsByWorkspace.get(workspaceId)?.delete(agentId);
|
||||
this.refreshPromptTime(workspaceId);
|
||||
}
|
||||
this.cache.delete(agentId);
|
||||
this.removeOwnerIndex(agentId);
|
||||
this.pathById.delete(agentId);
|
||||
@@ -286,9 +429,9 @@ export class AgentStorage {
|
||||
await Promise.allSettled(writes);
|
||||
}
|
||||
|
||||
private async load(): Promise<StoredAgentRecord[]> {
|
||||
private async load(): Promise<void> {
|
||||
if (this.loaded) {
|
||||
return Array.from(this.cache.values());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.loadPromise) {
|
||||
@@ -298,7 +441,7 @@ export class AgentStorage {
|
||||
return this.loadPromise;
|
||||
}
|
||||
|
||||
private async doLoad(): Promise<StoredAgentRecord[]> {
|
||||
private async doLoad(): Promise<void> {
|
||||
this.cache.clear();
|
||||
this.pathById.clear();
|
||||
this.pathsById.clear();
|
||||
@@ -306,28 +449,25 @@ export class AgentStorage {
|
||||
this.daemonExecutionKeysByAgentId.clear();
|
||||
|
||||
try {
|
||||
const records = await this.scanDisk();
|
||||
await this.scanDisk();
|
||||
this.loaded = true;
|
||||
return records;
|
||||
} catch (error) {
|
||||
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
|
||||
this.loaded = true;
|
||||
return [];
|
||||
return;
|
||||
}
|
||||
this.logger.error({ err: error }, "Failed to load agents");
|
||||
this.loaded = true;
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
private async scanDisk(): Promise<StoredAgentRecord[]> {
|
||||
const records: StoredAgentRecord[] = [];
|
||||
private async scanDisk(): Promise<void> {
|
||||
let entries: Dirent[] = [];
|
||||
try {
|
||||
entries = await fs.readdir(this.baseDir, { withFileTypes: true });
|
||||
} catch (error) {
|
||||
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
|
||||
return [];
|
||||
return;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
@@ -364,14 +504,11 @@ export class AgentStorage {
|
||||
for (const item of loaded) {
|
||||
if (!item) continue;
|
||||
const { record, filePath } = item;
|
||||
records.push(record);
|
||||
this.cache.set(record.id, record);
|
||||
this.indexOwner(record);
|
||||
this.pathById.set(record.id, filePath);
|
||||
this.addIndexedPath(record.id, filePath);
|
||||
}
|
||||
|
||||
return records;
|
||||
}
|
||||
|
||||
private async readRecordFile(filePath: string): Promise<StoredAgentRecord | null> {
|
||||
@@ -408,6 +545,7 @@ export class AgentStorage {
|
||||
}
|
||||
|
||||
private indexOwner(record: StoredAgentRecord): void {
|
||||
this.indexWorkspace(record);
|
||||
this.removeOwnerIndex(record.id);
|
||||
if (record.owner?.kind === "daemon") {
|
||||
const key = daemonExecutionKey(record.owner);
|
||||
|
||||
@@ -94,7 +94,7 @@ export function resolveDefaultAgentCreateConfig(
|
||||
availableModes: availableModeIds,
|
||||
targetUnattendedMode: input.availableModes?.find(isUnattendedMode)?.id,
|
||||
}),
|
||||
featureValues: input.featureValues,
|
||||
providerOptions: input.providerOptions,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ test("session create applies the resolved mode from the provider create config",
|
||||
const stub = createProviderSnapshotManagerStub();
|
||||
stub.resolveCreateConfig.mockResolvedValue({
|
||||
modeId: "build",
|
||||
featureValues: { auto_accept: true },
|
||||
providerOptions: { auto_accept: true },
|
||||
});
|
||||
const dependencies: Parameters<typeof createAgentCommand>[0] = {
|
||||
agentManager: {
|
||||
@@ -171,7 +171,7 @@ test("session create applies the resolved mode from the provider create config",
|
||||
expect(createAgent).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
modeId: "build",
|
||||
featureValues: { auto_accept: true },
|
||||
providerOptions: { auto_accept: true },
|
||||
}),
|
||||
undefined,
|
||||
expect.anything(),
|
||||
|
||||
@@ -26,6 +26,8 @@ import {
|
||||
inheritWorkspaceBackground,
|
||||
resolveCreateAgentIntent,
|
||||
} from "./intent.js";
|
||||
import type { ProviderOptions } from "@getpaseo/protocol/agent-types";
|
||||
import { foldFeatureValues, type LegacyFeatureValues } from "../option-controls.js";
|
||||
|
||||
/** How a workspace this creation makes inherits its creator's visibility. */
|
||||
interface McpWorkspaceIntent {
|
||||
@@ -57,7 +59,8 @@ export interface CreateAgentFromSessionInput {
|
||||
kind: "session";
|
||||
onAgentReady?: (agent: ManagedAgent) => Promise<void>;
|
||||
agentId?: string;
|
||||
config: AgentSessionConfig;
|
||||
/** Wire configs from older clients can still carry `featureValues`; they are folded on entry. */
|
||||
config: AgentSessionConfig & LegacyFeatureValues;
|
||||
workspaceId: string;
|
||||
background: boolean;
|
||||
initialPrompt?: string;
|
||||
@@ -81,7 +84,7 @@ export interface CreateAgentFromMcpInput {
|
||||
cwd?: string;
|
||||
workspaceId?: string;
|
||||
thinking?: string;
|
||||
features?: Record<string, unknown>;
|
||||
providerOptions?: ProviderOptions;
|
||||
labels?: Record<string, string>;
|
||||
mode?: string;
|
||||
unattended?: boolean;
|
||||
@@ -231,19 +234,19 @@ async function resolveSessionCreateAgent(
|
||||
input: CreateAgentFromSessionInput,
|
||||
): Promise<ResolvedCreateAgent> {
|
||||
const trimmedPrompt = input.initialPrompt?.trim();
|
||||
const builtSessionConfig = input.config;
|
||||
const builtSessionConfig = foldFeatureValues(input.config);
|
||||
const resolvedCreateConfig = await dependencies.providerSnapshotManager.resolveCreateConfig({
|
||||
cwd: builtSessionConfig.cwd,
|
||||
provider: builtSessionConfig.provider,
|
||||
requestedMode: builtSessionConfig.modeId,
|
||||
featureValues: builtSessionConfig.featureValues,
|
||||
providerOptions: builtSessionConfig.providerOptions,
|
||||
parent: null,
|
||||
unattended: false,
|
||||
});
|
||||
const sessionConfig: AgentSessionConfig = {
|
||||
...builtSessionConfig,
|
||||
modeId: resolvedCreateConfig.modeId,
|
||||
featureValues: resolvedCreateConfig.featureValues,
|
||||
providerOptions: resolvedCreateConfig.providerOptions,
|
||||
};
|
||||
const prompt = buildAgentPrompt(trimmedPrompt ?? "", input.images, input.attachments);
|
||||
const hasPromptContent = Array.isArray(prompt) ? prompt.length > 0 : prompt.length > 0;
|
||||
@@ -341,7 +344,7 @@ async function resolveMcpCreateAgent(
|
||||
resolvedCwd: intent.cwd,
|
||||
trimmedPrompt,
|
||||
resolvedMode: resolvedCreateConfig.modeId,
|
||||
resolvedFeatures: resolvedCreateConfig.featureValues,
|
||||
resolvedProviderOptions: resolvedCreateConfig.providerOptions,
|
||||
}),
|
||||
createOptions: {
|
||||
...(Object.keys(intent.labels).length > 0 ? { labels: intent.labels } : {}),
|
||||
@@ -380,18 +383,23 @@ async function resolveMcpProviderCreateConfig(params: {
|
||||
provider: string;
|
||||
resolvedCwd: string;
|
||||
parentAgent: ManagedAgent | null;
|
||||
}): Promise<{ modeId?: string; featureValues?: Record<string, unknown> }> {
|
||||
}): Promise<{ modeId?: string; providerOptions?: ProviderOptions }> {
|
||||
const passthroughConfig = params.input.config;
|
||||
return params.dependencies.providerSnapshotManager.resolveCreateConfig({
|
||||
cwd: params.resolvedCwd,
|
||||
provider: params.provider,
|
||||
requestedMode: params.input.mode ?? passthroughConfig?.modeId,
|
||||
featureValues: params.input.features ?? passthroughConfig?.featureValues,
|
||||
providerOptions: mergeMcpProviderOptions(params.input),
|
||||
parent: params.parentAgent,
|
||||
unattended: params.input.unattended ?? false,
|
||||
});
|
||||
}
|
||||
|
||||
function mergeMcpProviderOptions(input: CreateAgentFromMcpInput): ProviderOptions | undefined {
|
||||
if (!input.providerOptions) return input.config?.providerOptions;
|
||||
return { ...input.config?.providerOptions, ...input.providerOptions };
|
||||
}
|
||||
|
||||
function buildMcpSessionConfig(params: {
|
||||
input: CreateAgentFromMcpInput;
|
||||
resolvedProviderModel: ResolvedProviderModel;
|
||||
@@ -399,14 +407,14 @@ function buildMcpSessionConfig(params: {
|
||||
resolvedCwd: string;
|
||||
trimmedPrompt: string;
|
||||
resolvedMode?: string;
|
||||
resolvedFeatures?: Record<string, unknown>;
|
||||
resolvedProviderOptions?: ProviderOptions;
|
||||
}): AgentSessionConfig {
|
||||
const passthroughConfig = params.input.config;
|
||||
const { provisionalTitle } = resolveCreateAgentTitles({
|
||||
configTitle: passthroughConfig?.title ?? params.input.title,
|
||||
initialPrompt: params.trimmedPrompt,
|
||||
});
|
||||
const featureValues = params.resolvedFeatures ?? passthroughConfig?.featureValues;
|
||||
const providerOptions = params.resolvedProviderOptions ?? mergeMcpProviderOptions(params.input);
|
||||
const config: AgentSessionConfig = {
|
||||
...passthroughConfig,
|
||||
provider: params.provider,
|
||||
@@ -419,8 +427,8 @@ function buildMcpSessionConfig(params: {
|
||||
if (provisionalTitle) {
|
||||
config.title = provisionalTitle;
|
||||
}
|
||||
if (featureValues) {
|
||||
config.featureValues = featureValues;
|
||||
if (providerOptions) {
|
||||
config.providerOptions = providerOptions;
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { resolveWorkspaceRootAgent } from "../workspace-directory.js";
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
@@ -50,12 +51,12 @@ beforeEach(async () => {
|
||||
manager: { listAgents: () => [] },
|
||||
workspaces: {
|
||||
get: async (id) => workspaces.find((entry) => entry.workspaceId === id) ?? null,
|
||||
list: async () => workspaces,
|
||||
},
|
||||
projectLive: () => {
|
||||
throw new Error("No live agents in this suite");
|
||||
},
|
||||
projectStored: (record) => buildStoredAgentPayload(record, ["codex"]),
|
||||
projectStored: (record) =>
|
||||
buildStoredAgentPayload(record, ["codex"], (_provider, own) => own ?? {}),
|
||||
isProviderVisible: () => true,
|
||||
isStoredProviderAvailable: () => true,
|
||||
});
|
||||
@@ -112,3 +113,28 @@ test("prompt recency ignores background agents", async () => {
|
||||
new Map([["open", "2026-03-02T00:00:00.000Z"]]),
|
||||
);
|
||||
});
|
||||
|
||||
test("scoped status queries retain cross-workspace parent context", async () => {
|
||||
const base = { provider: "codex", cwd: home, createdAt: NOW, updatedAt: NOW };
|
||||
await storage.upsert({ ...base, id: "parent", workspaceId: "open" });
|
||||
await storage.upsert({
|
||||
...base,
|
||||
id: "child",
|
||||
workspaceId: "hidden",
|
||||
labels: { "paseo.parent-agent-id": "parent" },
|
||||
lastStatus: "running",
|
||||
});
|
||||
const agents = await directory.list({
|
||||
workspaceIds: ["hidden"],
|
||||
includeBackground: true,
|
||||
includeAncestors: true,
|
||||
});
|
||||
const child = agents.find((agent) => agent.id === "child")!;
|
||||
expect(
|
||||
resolveWorkspaceRootAgent(child, new Map(agents.map((agent) => [agent.id, agent])))?.id,
|
||||
).toBe("child");
|
||||
expect(child.status).toBe("running");
|
||||
expect(
|
||||
(await directory.list({ workspaceIds: ["hidden"], includeBackground: true })).map((a) => a.id),
|
||||
).not.toContain("parent");
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { getParentAgentIdFromLabels } from "@getpaseo/protocol/agent-labels";
|
||||
import type { AgentSnapshotPayload } from "../messages.js";
|
||||
import type { WorkspaceRegistry } from "../workspace-registry.js";
|
||||
import type { AgentManager, ManagedAgent } from "./agent-manager.js";
|
||||
@@ -26,8 +27,11 @@ export class AgentDirectory {
|
||||
constructor(
|
||||
private readonly deps: {
|
||||
manager: Pick<AgentManager, "listAgents">;
|
||||
storage: Pick<AgentStorage, "list">;
|
||||
workspaces: Pick<WorkspaceRegistry, "get" | "list">;
|
||||
storage: Pick<
|
||||
AgentStorage,
|
||||
"get" | "listActive" | "listByWorkspaces" | "lastUserMessageAtByWorkspace"
|
||||
>;
|
||||
workspaces: Pick<WorkspaceRegistry, "get">;
|
||||
projectLive(agent: ManagedAgent): Promise<AgentSnapshotPayload>;
|
||||
projectStored(record: StoredAgentRecord): AgentSnapshotPayload;
|
||||
isProviderVisible(provider: string): boolean;
|
||||
@@ -36,22 +40,22 @@ export class AgentDirectory {
|
||||
) {}
|
||||
|
||||
/** Human prompt recency includes archived/unavailable agents without projecting their UI payloads. */
|
||||
async workspaceLastUserMessageTimes(): Promise<Map<string, string>> {
|
||||
async workspaceLastUserMessageTimes(
|
||||
workspaceIds?: Iterable<string>,
|
||||
): Promise<Map<string, string>> {
|
||||
const requested = workspaceIds ? new Set(workspaceIds) : undefined;
|
||||
const live = this.deps.manager.listAgents();
|
||||
const liveIds = new Set(live.map((agent) => agent.id));
|
||||
const times = new Map<string, string>();
|
||||
const record = (workspaceId: string | undefined, at: string | null | undefined) => {
|
||||
if (!workspaceId || !at) return;
|
||||
const previous = times.get(workspaceId);
|
||||
if (!previous || at > previous) times.set(workspaceId, at);
|
||||
};
|
||||
for (const agent of await this.deps.storage.list()) {
|
||||
if (!agent.internal && !agent.background && !liveIds.has(agent.id))
|
||||
record(agent.workspaceId, agent.lastUserMessageAt);
|
||||
}
|
||||
const times = new Map(
|
||||
await this.deps.storage.lastUserMessageAtByWorkspace(requested, {
|
||||
excludeAgentIds: live.map((agent) => agent.id),
|
||||
}),
|
||||
);
|
||||
for (const agent of live) {
|
||||
if (!agent.internal && !agent.background)
|
||||
record(agent.workspaceId, agent.lastUserMessageAt?.toISOString());
|
||||
if (agent.internal || agent.background || !agent.workspaceId || !agent.lastUserMessageAt)
|
||||
continue;
|
||||
if (requested && !requested.has(agent.workspaceId)) continue;
|
||||
const at = agent.lastUserMessageAt.toISOString();
|
||||
if (at > (times.get(agent.workspaceId) ?? "")) times.set(agent.workspaceId, at);
|
||||
}
|
||||
return times;
|
||||
}
|
||||
@@ -64,23 +68,67 @@ export class AgentDirectory {
|
||||
return admits(agent, workspace?.background === true, visibility);
|
||||
}
|
||||
|
||||
private async appendAncestors(
|
||||
live: ManagedAgent[],
|
||||
selectedLive: ManagedAgent[],
|
||||
records: StoredAgentRecord[],
|
||||
): Promise<void> {
|
||||
const selectedIds = new Set([...selectedLive, ...records].map((agent) => agent.id));
|
||||
const liveById = new Map(live.map((agent) => [agent.id, agent]));
|
||||
const pending = [...selectedLive, ...records];
|
||||
for (const agent of pending) {
|
||||
const parentId = getParentAgentIdFromLabels(agent.labels);
|
||||
if (!parentId || selectedIds.has(parentId)) continue;
|
||||
selectedIds.add(parentId);
|
||||
const liveParent = liveById.get(parentId);
|
||||
if (liveParent) {
|
||||
pending.push(liveParent);
|
||||
selectedLive.push(liveParent);
|
||||
} else {
|
||||
const storedParent = await this.deps.storage.get(parentId);
|
||||
if (storedParent) {
|
||||
pending.push(storedParent);
|
||||
records.push(storedParent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async list(filter?: {
|
||||
workspaceIds?: Iterable<string>;
|
||||
/** Include parent chains by ID for workspace root classification. */
|
||||
includeAncestors?: boolean;
|
||||
labels?: Record<string, string>;
|
||||
includeArchived?: boolean;
|
||||
includeBackground?: BackgroundVisibility;
|
||||
includeUnavailablePersisted?: boolean;
|
||||
}): Promise<AgentSnapshotPayload[]> {
|
||||
const requested = filter?.workspaceIds ? new Set(filter.workspaceIds) : null;
|
||||
const live = this.deps.manager.listAgents();
|
||||
const liveIds = new Set(live.map((agent) => agent.id));
|
||||
const labels = Object.entries(filter?.labels ?? {});
|
||||
const visibility = filter?.includeBackground ?? false;
|
||||
const backgroundWorkspaceIds = new Set(
|
||||
visibility === true
|
||||
? []
|
||||
: (await this.deps.workspaces.list())
|
||||
.filter((workspace) => workspace.background)
|
||||
.map((workspace) => workspace.workspaceId),
|
||||
const records = requested
|
||||
? await this.deps.storage.listByWorkspaces(requested, filter)
|
||||
: await this.deps.storage.listActive(filter);
|
||||
const selectedLive = requested
|
||||
? live.filter((agent) => requested.has(agent.workspaceId ?? ""))
|
||||
: live;
|
||||
if (filter?.includeAncestors && requested) {
|
||||
await this.appendAncestors(live, selectedLive, records);
|
||||
}
|
||||
|
||||
const workspaceIds = new Set(
|
||||
[...selectedLive, ...records].flatMap((agent) =>
|
||||
agent.workspaceId ? [agent.workspaceId] : [],
|
||||
),
|
||||
);
|
||||
const backgroundWorkspaceIds = new Set<string>();
|
||||
if (visibility !== true) {
|
||||
for (const id of workspaceIds) {
|
||||
if ((await this.deps.workspaces.get(id))?.background) backgroundWorkspaceIds.add(id);
|
||||
}
|
||||
}
|
||||
const matches = (
|
||||
agent: DiscoverableAgent & { archivedAt?: string | null; labels?: Record<string, string> },
|
||||
) =>
|
||||
@@ -91,7 +139,7 @@ export class AgentDirectory {
|
||||
visibility,
|
||||
) &&
|
||||
labels.every(([key, value]) => agent.labels?.[key] === value);
|
||||
const stored = (await this.deps.storage.list())
|
||||
const stored = records
|
||||
.filter((record) => !liveIds.has(record.id) && matches(record))
|
||||
.filter(
|
||||
(record) =>
|
||||
@@ -99,7 +147,7 @@ export class AgentDirectory {
|
||||
)
|
||||
.map((record) => this.deps.projectStored(record));
|
||||
const active = await Promise.all(
|
||||
live.filter(matches).map((agent) => this.deps.projectLive(agent)),
|
||||
selectedLive.filter(matches).map((agent) => this.deps.projectLive(agent)),
|
||||
);
|
||||
return [...active, ...stored]
|
||||
.filter(matches)
|
||||
|
||||
@@ -123,6 +123,7 @@ function outcome(status: "idle" | "running" | "closed" | "error" = "closed"): Wa
|
||||
lastStatus: status,
|
||||
},
|
||||
["codex"],
|
||||
(_provider, own) => own ?? {},
|
||||
),
|
||||
lastMessage: "Partial work saved",
|
||||
error: null,
|
||||
|
||||
+2
@@ -43,6 +43,7 @@ class Host implements HostObservation {
|
||||
updatedAt: "2026-01-01",
|
||||
},
|
||||
["codex"],
|
||||
(_provider, own) => own ?? {},
|
||||
),
|
||||
event,
|
||||
"Last response",
|
||||
@@ -133,6 +134,7 @@ test("late initial permission snapshot cannot resurrect an already resolved requ
|
||||
updatedAt: "2026-01-01",
|
||||
},
|
||||
["codex"],
|
||||
(_provider, own) => own ?? {},
|
||||
);
|
||||
if (requestEvent.type !== "permission_requested") throw new Error("Expected permission");
|
||||
final.pendingPermissions = [requestEvent.request];
|
||||
|
||||
@@ -34,7 +34,11 @@ export function createFinishObservation(input: {
|
||||
const stored = await agentStorage.get(agentId);
|
||||
return {
|
||||
status: stored?.lastStatus === "error" ? "error" : "idle",
|
||||
final: stored ? buildStoredAgentPayload(stored, [stored.provider]) : null,
|
||||
final: stored
|
||||
? buildStoredAgentPayload(stored, [stored.provider], (provider, own) =>
|
||||
agentManager.effectiveOptionsFor(provider, own),
|
||||
)
|
||||
: null,
|
||||
lastMessage: await agentManager.getLastAssistantMessage(agentId),
|
||||
error: stored?.lastError ?? null,
|
||||
};
|
||||
@@ -93,7 +97,14 @@ export function createFinishObservation(input: {
|
||||
type: "turn_started",
|
||||
provider: current.provider,
|
||||
});
|
||||
else publish(stored ? buildStoredAgentPayload(stored, [stored.provider]) : null);
|
||||
else
|
||||
publish(
|
||||
stored
|
||||
? buildStoredAgentPayload(stored, [stored.provider], (provider, own) =>
|
||||
agentManager.effectiveOptionsFor(provider, own),
|
||||
)
|
||||
: null,
|
||||
);
|
||||
const stop = () => unsubscribe();
|
||||
signal.addEventListener("abort", stop, { once: true });
|
||||
return async () => {
|
||||
|
||||
@@ -221,7 +221,7 @@ test("listImportableProviderSessions filters, sorts, limits, and projects import
|
||||
listImportableSessions,
|
||||
} satisfies Pick<AgentManager, "listAgents" | "listImportableSessions">;
|
||||
const agentStorage = {
|
||||
list: async () => [
|
||||
listAll: async () => [
|
||||
{
|
||||
provider: "codex",
|
||||
persistence: {
|
||||
@@ -231,7 +231,7 @@ test("listImportableProviderSessions filters, sorts, limits, and projects import
|
||||
},
|
||||
} as StoredAgentRecord,
|
||||
],
|
||||
} satisfies Pick<AgentStorage, "list">;
|
||||
} satisfies Pick<AgentStorage, "listAll">;
|
||||
|
||||
const result = await listImportableProviderSessions({
|
||||
request: makeRequest({
|
||||
@@ -303,7 +303,7 @@ test("listImportableProviderSessions looks past already-imported rows to fill th
|
||||
listImportableSessions,
|
||||
},
|
||||
agentStorage: {
|
||||
list: async () => [
|
||||
listAll: async () => [
|
||||
{
|
||||
provider: "claude",
|
||||
persistence: { provider: "claude", sessionId: "already-imported" },
|
||||
@@ -360,7 +360,7 @@ test("listImportableProviderSessions requests a bounded deep scan for search res
|
||||
const result = await listImportableProviderSessions({
|
||||
request: makeRequest({ query: "INVOICE", limit: 10 }),
|
||||
agentManager: { listAgents: () => [], listImportableSessions },
|
||||
agentStorage: { list: async () => [] },
|
||||
agentStorage: { listAll: async () => [] },
|
||||
providerSnapshotManager: { getProviderLabel: (provider) => provider },
|
||||
});
|
||||
|
||||
@@ -397,7 +397,7 @@ test("listImportableProviderSessions includes a provider session after its Paseo
|
||||
listImportableSessions: async () => makeImportableSessionsResult([archivedSession]),
|
||||
},
|
||||
agentStorage: {
|
||||
list: async () => [
|
||||
listAll: async () => [
|
||||
{
|
||||
provider: "claude",
|
||||
archivedAt: "2026-04-30T12:01:00.000Z",
|
||||
@@ -441,7 +441,7 @@ test("listImportableProviderSessions includes an archived provider session still
|
||||
listImportableSessions: async () => makeImportableSessionsResult([archivedSession]),
|
||||
},
|
||||
agentStorage: {
|
||||
list: async () => [
|
||||
listAll: async () => [
|
||||
{
|
||||
id: agentId,
|
||||
provider: "claude",
|
||||
@@ -489,8 +489,8 @@ test("listImportableProviderSessions filters out metadata generation sessions",
|
||||
listImportableSessions: async () => makeImportableSessionsResult(sessions),
|
||||
} satisfies Pick<AgentManager, "listAgents" | "listImportableSessions">,
|
||||
agentStorage: {
|
||||
list: async () => [],
|
||||
} satisfies Pick<AgentStorage, "list">,
|
||||
listAll: async () => [],
|
||||
} satisfies Pick<AgentStorage, "listAll">,
|
||||
providerSnapshotManager: { getProviderLabel: () => "Codex" },
|
||||
});
|
||||
|
||||
@@ -525,8 +525,8 @@ test("listImportableProviderSessions keeps realpath-equivalent cwd matches", asy
|
||||
]),
|
||||
} satisfies Pick<AgentManager, "listAgents" | "listImportableSessions">,
|
||||
agentStorage: {
|
||||
list: async () => [],
|
||||
} satisfies Pick<AgentStorage, "list">,
|
||||
listAll: async () => [],
|
||||
} satisfies Pick<AgentStorage, "listAll">,
|
||||
providerSnapshotManager: { getProviderLabel: () => "Pi" },
|
||||
});
|
||||
|
||||
@@ -542,8 +542,8 @@ test("listImportableProviderSessions rejects invalid since values", async () =>
|
||||
listImportableSessions: async () => makeImportableSessionsResult([]),
|
||||
} satisfies Pick<AgentManager, "listAgents" | "listImportableSessions">,
|
||||
agentStorage: {
|
||||
list: async () => [],
|
||||
} satisfies Pick<AgentStorage, "list">,
|
||||
listAll: async () => [],
|
||||
} satisfies Pick<AgentStorage, "listAll">,
|
||||
providerSnapshotManager: { getProviderLabel: () => "" },
|
||||
}),
|
||||
).rejects.toMatchObject(
|
||||
|
||||
@@ -64,7 +64,7 @@ export class ImportSessionsRequestError extends Error {
|
||||
export interface ListImportableProviderSessionsInput {
|
||||
request: FetchRecentProviderSessionsRequestMessage;
|
||||
agentManager: Pick<AgentManager, "listAgents" | "listImportableSessions">;
|
||||
agentStorage: Pick<AgentStorage, "list">;
|
||||
agentStorage: Pick<AgentStorage, "listAll">;
|
||||
providerSnapshotManager: Pick<ProviderSnapshotManager, "getProviderLabel">;
|
||||
}
|
||||
|
||||
@@ -342,12 +342,13 @@ function parseRecentProviderSessionsSince(since: string | undefined): number | n
|
||||
|
||||
async function collectImportedProviderSessions(
|
||||
agentManager: Pick<AgentManager, "listAgents">,
|
||||
agentStorage: Pick<AgentStorage, "list">,
|
||||
agentStorage: Pick<AgentStorage, "listAll">,
|
||||
providerFilter: Set<string> | undefined,
|
||||
): Promise<{ handles: Set<string>; count: number }> {
|
||||
const handles = new Set<string>();
|
||||
const sessions = new Set<string>();
|
||||
const records = await agentStorage.list();
|
||||
// Explicit provider-history import deduplicates against archived as well as active sessions.
|
||||
const records = await agentStorage.listAll();
|
||||
const storedRecordsById = new Map(records.map((record) => [record.id, record]));
|
||||
|
||||
const collect = (
|
||||
|
||||
@@ -186,8 +186,8 @@ function createRecordingAgentClients(): Record<AgentProvider, AgentClient> {
|
||||
if (client.listCommands) {
|
||||
wrappedClient.listCommands = async (config) => await client.listCommands!(config);
|
||||
}
|
||||
if (client.listFeatures) {
|
||||
wrappedClient.listFeatures = async (config) => await client.listFeatures!(config);
|
||||
if (client.listControls) {
|
||||
wrappedClient.listControls = async (config) => await client.listControls!(config);
|
||||
}
|
||||
if (client.listImportableSessions) {
|
||||
wrappedClient.listImportableSessions = async (options) =>
|
||||
|
||||
@@ -257,7 +257,7 @@ function buildAgentManagerSpies() {
|
||||
setAgentMode: vi.fn().mockResolvedValue(undefined),
|
||||
setAgentModel: vi.fn().mockResolvedValue(undefined),
|
||||
setAgentThinkingOption: vi.fn().mockResolvedValue(undefined),
|
||||
setAgentFeature: vi.fn().mockResolvedValue(undefined),
|
||||
setAgentOptions: vi.fn().mockResolvedValue(undefined),
|
||||
setLabels: vi.fn().mockResolvedValue(undefined),
|
||||
setTitle: vi.fn().mockResolvedValue(undefined),
|
||||
updateAgentMetadata: vi.fn().mockResolvedValue(undefined),
|
||||
@@ -271,6 +271,7 @@ function buildAgentManagerSpies() {
|
||||
appendTimelineItem: vi.fn().mockResolvedValue(undefined),
|
||||
emitLiveTimelineItem: vi.fn().mockResolvedValue(undefined),
|
||||
getPluginTools: () => [],
|
||||
effectiveOptionsFor: (_provider: string, own?: Record<string, unknown>) => own ?? {},
|
||||
reloadStalePluginSession: async () => {},
|
||||
hasInFlightRun: vi.fn().mockReturnValue(false),
|
||||
steerOrReplaceActiveTurn: async () => ({ status: "inactive" as const }),
|
||||
@@ -282,7 +283,7 @@ function buildAgentManagerSpies() {
|
||||
cancelAgentRun: vi.fn(),
|
||||
getPendingPermissions: vi.fn(),
|
||||
getRegisteredProviderIds: vi.fn().mockReturnValue(["claude"]),
|
||||
listDraftFeatures: vi.fn(),
|
||||
listDraftControls: vi.fn(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -292,7 +293,9 @@ function buildAgentStorageSpies() {
|
||||
setTitle: vi.fn().mockResolvedValue(undefined),
|
||||
upsert: vi.fn().mockResolvedValue(undefined),
|
||||
applySnapshot: vi.fn(),
|
||||
list: vi.fn().mockResolvedValue([]),
|
||||
listActive: vi.fn().mockResolvedValue([]),
|
||||
listByWorkspaces: vi.fn().mockResolvedValue([]),
|
||||
lastUserMessageAtByWorkspace: async () => new Map<string, string>(),
|
||||
remove: vi.fn(),
|
||||
};
|
||||
}
|
||||
@@ -472,9 +475,9 @@ function configureOpenCodeProviderStub(
|
||||
const opts = input as {
|
||||
provider: AgentProvider;
|
||||
requestedMode: string | undefined;
|
||||
featureValues: Record<string, unknown> | undefined;
|
||||
providerOptions: Record<string, unknown> | undefined;
|
||||
};
|
||||
return { modeId: opts.requestedMode, featureValues: opts.featureValues };
|
||||
return { modeId: opts.requestedMode, providerOptions: opts.providerOptions };
|
||||
});
|
||||
}
|
||||
|
||||
@@ -639,7 +642,16 @@ class BoundaryAgentManagerFake {
|
||||
}
|
||||
|
||||
class BoundaryAgentStorageFake {
|
||||
public async list(): Promise<StoredAgentRecord[]> {
|
||||
public async listActive(): Promise<StoredAgentRecord[]> {
|
||||
return [];
|
||||
}
|
||||
async listByWorkspaces() {
|
||||
return [];
|
||||
}
|
||||
async lastUserMessageAtByWorkspace() {
|
||||
return new Map<string, string>();
|
||||
}
|
||||
async listAll() {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -772,7 +784,8 @@ function createPaseoWorktreeForMcpTest(options: {
|
||||
initialize: async () => {},
|
||||
existsOnDisk: async () => true,
|
||||
get: async (workspaceId: string) => workspaces.get(workspaceId) ?? null,
|
||||
list: async () => Array.from(workspaces.values()),
|
||||
listAll: async () => Array.from(workspaces.values()),
|
||||
listActive: async () => Array.from(workspaces.values()).filter((w) => !w.archivedAt),
|
||||
update: async (workspaceId, updater) => {
|
||||
const workspace = workspaces.get(workspaceId);
|
||||
if (!workspace) return null;
|
||||
@@ -894,7 +907,11 @@ async function createAgentMcpServer(
|
||||
const server = await createAgentMcpServerWithDependencies({
|
||||
agentMessages: () => messages,
|
||||
finishSubscriptions: () => subscriptions,
|
||||
workspaceRegistry: { get: async () => null, list: async () => [], upsert: async () => {} },
|
||||
workspaceRegistry: {
|
||||
get: async () => null,
|
||||
listActive: async () => [],
|
||||
upsert: async () => {},
|
||||
},
|
||||
...options,
|
||||
});
|
||||
serverSubscriptionRecords.set(server, records);
|
||||
@@ -1802,7 +1819,7 @@ describe("create_agent MCP tool", () => {
|
||||
lifecycle: "idle",
|
||||
currentModeId: null,
|
||||
availableModes: [],
|
||||
config: { title: "Feature test", featureValues: { fast_mode: true } },
|
||||
config: { title: "Feature test", providerOptions: { fast_mode: true } },
|
||||
} as ManagedAgent);
|
||||
|
||||
const server = await createAgentMcpServer({
|
||||
@@ -1831,7 +1848,7 @@ describe("create_agent MCP tool", () => {
|
||||
expect.objectContaining({
|
||||
provider: "codex",
|
||||
model: "gpt-5.4",
|
||||
featureValues: { fast_mode: true },
|
||||
providerOptions: { fast_mode: true },
|
||||
}),
|
||||
undefined,
|
||||
{ workspaceId: "workspace-created", background: false },
|
||||
@@ -2697,7 +2714,7 @@ describe("create_agent MCP tool", () => {
|
||||
providerSnapshotManager: createOpenCodeManager().manager,
|
||||
workspaceRegistry: {
|
||||
get: vi.fn(async () => workspace),
|
||||
list: vi.fn(async () => [workspace]),
|
||||
listActive: vi.fn(async () => [workspace]),
|
||||
upsert: vi.fn(async () => undefined),
|
||||
},
|
||||
logger,
|
||||
@@ -2730,7 +2747,7 @@ describe("create_agent MCP tool", () => {
|
||||
providerSnapshotManager: createOpenCodeManager().manager,
|
||||
workspaceRegistry: {
|
||||
get: vi.fn(async () => backgroundWorkspace),
|
||||
list: vi.fn(async () => [backgroundWorkspace]),
|
||||
listActive: vi.fn(async () => [backgroundWorkspace]),
|
||||
upsert: vi.fn(async () => undefined),
|
||||
},
|
||||
createDirectoryWorkspace: async (cwd, _title, _projectId, context) => {
|
||||
@@ -3029,12 +3046,12 @@ describe("create_agent MCP tool", () => {
|
||||
lifecycle: "idle",
|
||||
currentModeId: null,
|
||||
availableModes: [],
|
||||
config: { title: "Child", featureValues: { fast_mode: true } },
|
||||
config: { title: "Child", providerOptions: { fast_mode: true } },
|
||||
} as ManagedAgent);
|
||||
const providerSnapshot = createOpenCodeManager();
|
||||
providerSnapshot.stub.resolveCreateConfig.mockImplementation(async (input) => {
|
||||
const opts = input as { featureValues: Record<string, unknown> | undefined };
|
||||
return { modeId: undefined, featureValues: opts.featureValues };
|
||||
const opts = input as { providerOptions: Record<string, unknown> | undefined };
|
||||
return { modeId: undefined, providerOptions: opts.providerOptions };
|
||||
});
|
||||
|
||||
const server = await createAgentMcpServer({
|
||||
@@ -3062,7 +3079,7 @@ describe("create_agent MCP tool", () => {
|
||||
expect.objectContaining({
|
||||
provider: "codex",
|
||||
model: "gpt-5.4",
|
||||
featureValues: { fast_mode: true },
|
||||
providerOptions: { fast_mode: true },
|
||||
}),
|
||||
undefined,
|
||||
{
|
||||
@@ -3265,7 +3282,7 @@ describe("create_agent MCP tool", () => {
|
||||
provStub.resolveCreateConfig.mockImplementation(async (input) => {
|
||||
const opts = input as { requestedMode: string | undefined };
|
||||
expect(opts.requestedMode).toBe("dynamic");
|
||||
return { modeId: "dynamic", featureValues: undefined };
|
||||
return { modeId: "dynamic", providerOptions: undefined };
|
||||
});
|
||||
const server = await createAgentMcpServer({
|
||||
agentManager,
|
||||
@@ -3299,12 +3316,12 @@ describe("create_agent MCP tool", () => {
|
||||
lifecycle: "idle",
|
||||
currentModeId: "build",
|
||||
availableModes: [],
|
||||
config: { title: "Child", featureValues: { auto_accept: true } },
|
||||
config: { title: "Child", providerOptions: { auto_accept: true } },
|
||||
} as ManagedAgent);
|
||||
const providerSnapshot = createOpenCodeManager();
|
||||
providerSnapshot.stub.resolveCreateConfig.mockResolvedValue({
|
||||
modeId: "build",
|
||||
featureValues: { auto_accept: true },
|
||||
providerOptions: { auto_accept: true },
|
||||
});
|
||||
const server = await createAgentMcpServer({
|
||||
agentManager,
|
||||
@@ -3324,7 +3341,7 @@ describe("create_agent MCP tool", () => {
|
||||
});
|
||||
|
||||
expect(spies.agentManager.createAgent).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ modeId: "build", featureValues: { auto_accept: true } }),
|
||||
expect.objectContaining({ modeId: "build", providerOptions: { auto_accept: true } }),
|
||||
undefined,
|
||||
{ workspaceId: "workspace-created", background: false },
|
||||
);
|
||||
@@ -3352,7 +3369,7 @@ describe("create_agent MCP tool", () => {
|
||||
const providerSnapshot = createOpenCodeManager();
|
||||
providerSnapshot.stub.resolveCreateConfig.mockResolvedValue({
|
||||
modeId: "resolver-mode",
|
||||
featureValues: { resolver_feature: true },
|
||||
providerOptions: { resolver_feature: true },
|
||||
});
|
||||
|
||||
const server = await createAgentMcpServer({
|
||||
@@ -3376,7 +3393,7 @@ describe("create_agent MCP tool", () => {
|
||||
expect(spies.agentManager.createAgent).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
modeId: "resolver-mode",
|
||||
featureValues: { resolver_feature: true },
|
||||
providerOptions: { resolver_feature: true },
|
||||
}),
|
||||
undefined,
|
||||
expect.any(Object),
|
||||
@@ -4709,7 +4726,7 @@ describe("update_agent MCP tool", () => {
|
||||
expect(spies.agentManager.setAgentMode).toHaveBeenCalledWith("agent-1", "full-access");
|
||||
expect(spies.agentManager.setAgentModel).toHaveBeenCalledWith("agent-1", "gpt-5.4");
|
||||
expect(spies.agentManager.setAgentThinkingOption).toHaveBeenCalledWith("agent-1", "high");
|
||||
expect(spies.agentManager.setAgentFeature).toHaveBeenCalledWith("agent-1", "fast_mode", true);
|
||||
expect(spies.agentManager.setAgentOptions).toHaveBeenCalledWith("agent-1", { fast_mode: true });
|
||||
expect(spies.agentManager.updateAgentMetadata).toHaveBeenCalledWith("agent-1", {
|
||||
title: "Updated agent",
|
||||
labels: { role: "worker" },
|
||||
@@ -4734,12 +4751,12 @@ describe("update_agent MCP tool", () => {
|
||||
expect(spies.agentManager.setAgentMode).not.toHaveBeenCalled();
|
||||
expect(spies.agentManager.setAgentModel).not.toHaveBeenCalled();
|
||||
expect(spies.agentManager.setAgentThinkingOption).not.toHaveBeenCalled();
|
||||
expect(spies.agentManager.setAgentFeature).not.toHaveBeenCalled();
|
||||
expect(spies.agentManager.setAgentOptions).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not update metadata when runtime settings fail", async () => {
|
||||
const { agentManager, agentStorage, spies } = createTestDeps();
|
||||
spies.agentManager.setAgentFeature.mockRejectedValue(new Error("unsupported feature"));
|
||||
spies.agentManager.setAgentOptions.mockRejectedValue(new Error("unsupported feature"));
|
||||
const server = await createAgentMcpServer({
|
||||
agentManager,
|
||||
agentStorage,
|
||||
@@ -5057,7 +5074,7 @@ describe("create_schedule MCP tool", () => {
|
||||
config: {
|
||||
title: "Parent agent",
|
||||
model: "openai/gpt-5.5",
|
||||
featureValues: { auto_accept: true },
|
||||
providerOptions: { auto_accept: true },
|
||||
},
|
||||
} as ManagedAgent);
|
||||
const createOrReplace = vi.fn(async (input: CreateScheduleInput) =>
|
||||
@@ -5085,7 +5102,7 @@ describe("create_schedule MCP tool", () => {
|
||||
cwd: REPO_CWD,
|
||||
modeId: "build",
|
||||
model: "openai/gpt-5.5",
|
||||
featureValues: { auto_accept: true },
|
||||
providerOptions: { auto_accept: true },
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -5859,7 +5876,7 @@ describe("agent profile listing MCP tool", () => {
|
||||
model: "claude-test-model",
|
||||
modeId: "bypassPermissions",
|
||||
thinkingOptionId: "high",
|
||||
featureValues: { fast_mode: true },
|
||||
options: { fast_mode: true },
|
||||
notes: "Use for UI work: components, layout, design tokens. Not for backend.",
|
||||
},
|
||||
];
|
||||
@@ -5874,7 +5891,21 @@ describe("agent profile listing MCP tool", () => {
|
||||
|
||||
const response = await tool.handler({});
|
||||
|
||||
expect(response.structuredContent).toEqual({ profiles });
|
||||
// The config store holds profiles with `options` only; the tool reports them as stored.
|
||||
expect(response.structuredContent).toEqual({
|
||||
profiles: [
|
||||
{
|
||||
id: "ui-profile",
|
||||
name: "UI work",
|
||||
provider: "claude",
|
||||
model: "claude-test-model",
|
||||
modeId: "bypassPermissions",
|
||||
thinkingOptionId: "high",
|
||||
options: { fast_mode: true },
|
||||
notes: "Use for UI work: components, layout, design tokens. Not for backend.",
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("returns an empty array when no profiles are configured", async () => {
|
||||
@@ -5926,14 +5957,10 @@ describe("provider MCP tools", () => {
|
||||
|
||||
it("inspects provider features for a draft agent configuration", async () => {
|
||||
const { agentManager, agentStorage, spies } = createTestDeps();
|
||||
spies.agentManager.listDraftFeatures.mockResolvedValue([
|
||||
{
|
||||
type: "toggle",
|
||||
id: "fast_mode",
|
||||
label: "Fast mode",
|
||||
value: false,
|
||||
},
|
||||
]);
|
||||
spies.agentManager.listDraftControls.mockResolvedValue({
|
||||
controls: [{ type: "toggle", key: "fast_mode", label: "Fast mode" }],
|
||||
options: { fast_mode: true },
|
||||
});
|
||||
const provStub = createProviderSnapshotManagerStub();
|
||||
provStub.listRegisteredProviderIds.mockReturnValue(["codex"]);
|
||||
const codexEntry = buildSnapshotEntry({
|
||||
@@ -5966,13 +5993,13 @@ describe("provider MCP tools", () => {
|
||||
|
||||
const response = await tool.handler(input);
|
||||
|
||||
expect(spies.agentManager.listDraftFeatures).toHaveBeenCalledWith({
|
||||
expect(spies.agentManager.listDraftControls).toHaveBeenCalledWith({
|
||||
provider: "codex",
|
||||
cwd: expect.stringContaining("repo"),
|
||||
modeId: "full-access",
|
||||
model: "gpt-5.4",
|
||||
thinkingOptionId: "high",
|
||||
featureValues: { fast_mode: true },
|
||||
providerOptions: { fast_mode: true },
|
||||
});
|
||||
expect(response.structuredContent).toEqual({
|
||||
provider: "codex",
|
||||
@@ -5987,7 +6014,7 @@ describe("provider MCP tools", () => {
|
||||
type: "toggle",
|
||||
id: "fast_mode",
|
||||
label: "Fast mode",
|
||||
value: false,
|
||||
value: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -6203,14 +6230,8 @@ describe("agent snapshot MCP serialization", () => {
|
||||
description: "Default coding mode",
|
||||
},
|
||||
],
|
||||
features: [
|
||||
{
|
||||
type: "toggle",
|
||||
id: "web-search",
|
||||
label: "Web search",
|
||||
value: true,
|
||||
},
|
||||
],
|
||||
controls: [{ type: "toggle", key: "web-search", label: "Web search" }],
|
||||
effectiveOptions: { "web-search": true },
|
||||
pendingPermissions: new Map(),
|
||||
persistence: {
|
||||
provider: "codex",
|
||||
@@ -6326,7 +6347,7 @@ describe("agent snapshot MCP serialization", () => {
|
||||
createManagedAgent({ id: "in-child-cwd", cwd: "/tmp/workspace/packages/server" }),
|
||||
createManagedAgent({ id: "other-cwd", cwd: "/tmp/other" }),
|
||||
]);
|
||||
spies.agentStorage.list.mockResolvedValue([
|
||||
spies.agentStorage.listActive.mockResolvedValue([
|
||||
createStoredRecord({
|
||||
id: "stored-in-cwd",
|
||||
cwd: "/tmp/workspace",
|
||||
@@ -6385,7 +6406,7 @@ describe("agent snapshot MCP serialization", () => {
|
||||
updatedAt: new Date(old),
|
||||
}),
|
||||
]);
|
||||
spies.agentStorage.list.mockResolvedValue([
|
||||
spies.agentStorage.listActive.mockResolvedValue([
|
||||
createStoredRecord({ id: "recent-archived", cwd: TARGET_CWD, archivedAt: recent }),
|
||||
createStoredRecord({ id: "old-archived", cwd: TARGET_CWD, archivedAt: old }),
|
||||
createStoredRecord({
|
||||
@@ -6426,7 +6447,7 @@ describe("agent snapshot MCP serialization", () => {
|
||||
archivedAt: new Date(now - index * 60 * 1000).toISOString(),
|
||||
}),
|
||||
);
|
||||
spies.agentStorage.list.mockResolvedValue([
|
||||
spies.agentStorage.listActive.mockResolvedValue([
|
||||
...recentArchivedRecords,
|
||||
createStoredRecord({
|
||||
id: "old-archived",
|
||||
@@ -6457,7 +6478,7 @@ describe("agent snapshot MCP serialization", () => {
|
||||
it("returns compact list items for stored archived agents", async () => {
|
||||
const { agentManager, agentStorage, spies } = createTestDeps();
|
||||
const now = new Date().toISOString();
|
||||
spies.agentStorage.list.mockResolvedValue([
|
||||
spies.agentStorage.listActive.mockResolvedValue([
|
||||
createStoredRecord({
|
||||
id: "stored-archived-compact",
|
||||
cwd: REPO_CWD,
|
||||
@@ -6576,7 +6597,7 @@ describe("agent snapshot MCP serialization", () => {
|
||||
const { agentManager, agentStorage, spies } = createTestDeps();
|
||||
const now = new Date().toISOString();
|
||||
spies.agentManager.listAgents.mockReturnValue([createManagedAgent()]);
|
||||
spies.agentStorage.list.mockResolvedValue([
|
||||
spies.agentStorage.listActive.mockResolvedValue([
|
||||
createStoredRecord({
|
||||
id: "stored-non-archived",
|
||||
updatedAt: now,
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { convertLegacyOptions, foldHookFeatureValues } from "./option-controls.js";
|
||||
|
||||
describe("convertLegacyOptions rejects a malformed Codex fast_mode", () => {
|
||||
test.each(["false", 1, {}])("%j", (value) => {
|
||||
expect(() =>
|
||||
convertLegacyOptions({ provider: "codex", options: { fast_mode: value } }),
|
||||
).toThrow(/fast_mode must be true, false or null/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("convertLegacyOptions", () => {
|
||||
test.each([
|
||||
{ legacy: true, tier: "fast" },
|
||||
{ legacy: false, tier: "default" },
|
||||
{ legacy: null, tier: null },
|
||||
])("Codex fast_mode: $legacy becomes service_tier: $tier", ({ legacy, tier }) => {
|
||||
expect(
|
||||
convertLegacyOptions({ provider: "codex", options: { fast_mode: legacy, plan_mode: true } }),
|
||||
).toEqual({ plan_mode: true, service_tier: tier });
|
||||
});
|
||||
|
||||
test("a service_tier in the same input wins", () => {
|
||||
expect(
|
||||
convertLegacyOptions({
|
||||
provider: "codex",
|
||||
options: { service_tier: "default", fast_mode: true },
|
||||
}),
|
||||
).toEqual({ service_tier: "default" });
|
||||
});
|
||||
|
||||
test("other providers keep fast_mode", () => {
|
||||
const options = { fast_mode: true };
|
||||
expect(convertLegacyOptions({ provider: "claude", options })).toBe(options);
|
||||
});
|
||||
});
|
||||
|
||||
describe("foldHookFeatureValues", () => {
|
||||
const convert = (options: Record<string, unknown>) =>
|
||||
convertLegacyOptions({ provider: "codex", options });
|
||||
|
||||
test("a hook that edits featureValues.fast_mode sets service_tier", () => {
|
||||
const sent = { providerOptions: {}, featureValues: {} };
|
||||
const returned = { providerOptions: {}, featureValues: { fast_mode: true } };
|
||||
|
||||
expect(foldHookFeatureValues({ returned, sent, convert }).providerOptions).toEqual({
|
||||
service_tier: "fast",
|
||||
});
|
||||
});
|
||||
|
||||
test("a hook that replaces the speed it was sent with fast_mode selects Fast", () => {
|
||||
const sent = {
|
||||
providerOptions: { service_tier: "default" },
|
||||
featureValues: { service_tier: "default" },
|
||||
};
|
||||
const returned = { ...sent, featureValues: { fast_mode: true } };
|
||||
|
||||
expect(foldHookFeatureValues({ returned, sent, convert }).providerOptions).toEqual({
|
||||
service_tier: "fast",
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,204 @@
|
||||
import { isDeepStrictEqual } from "node:util";
|
||||
import type { ProviderOptions } from "@getpaseo/protocol/agent-types";
|
||||
|
||||
/**
|
||||
* A patch over an agent's own options: top-level keys replace, `null` removes the key so the
|
||||
* `config.json` default (or the provider's own default) applies again.
|
||||
*/
|
||||
export type ProviderOptionsPatch = Record<string, unknown>;
|
||||
|
||||
export function applyProviderOptionsPatch(input: {
|
||||
options: ProviderOptions | undefined;
|
||||
patch: ProviderOptionsPatch;
|
||||
}): ProviderOptions {
|
||||
const { options, patch } = input;
|
||||
const next: ProviderOptions = { ...options };
|
||||
for (const [key, value] of Object.entries(patch)) {
|
||||
if (value === null) {
|
||||
delete next[key];
|
||||
} else if (value !== undefined) {
|
||||
next[key] = value;
|
||||
}
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
/** COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01. */
|
||||
export interface LegacyFeatureValues {
|
||||
featureValues?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
/**
|
||||
* COMPAT(codexFastPreference): added in v0.10.0, remove after 2027-03-29 once saved Fast
|
||||
* preferences have migrated. Codex used to take `fast_mode`; it takes `service_tier` now. Old
|
||||
* data (stored records, config.json defaults, profiles, older clients, hooks) is converted here
|
||||
* as it enters, so nothing past this point sees `fast_mode` for Codex. A `service_tier` in the
|
||||
* same input wins. A patch's `null` stays `null`, which removes the speed.
|
||||
*/
|
||||
interface LegacyOptionsInput<O> {
|
||||
provider: string | undefined;
|
||||
options: O;
|
||||
}
|
||||
|
||||
export function convertLegacyOptions(
|
||||
input: LegacyOptionsInput<Record<string, unknown>>,
|
||||
): Record<string, unknown>;
|
||||
export function convertLegacyOptions(
|
||||
input: LegacyOptionsInput<Record<string, unknown> | undefined>,
|
||||
): Record<string, unknown> | undefined;
|
||||
export function convertLegacyOptions(
|
||||
input: LegacyOptionsInput<Record<string, unknown> | undefined>,
|
||||
): Record<string, unknown> | undefined {
|
||||
const { provider, options } = input;
|
||||
if (provider !== "codex" || !options || !("fast_mode" in options)) return options;
|
||||
const { fast_mode: legacy, ...rest } = options;
|
||||
if (legacy !== undefined && legacy !== null && typeof legacy !== "boolean") {
|
||||
throw new Error("Codex fast_mode must be true, false or null");
|
||||
}
|
||||
if ("service_tier" in rest || legacy === undefined) return rest;
|
||||
if (legacy === null) return { ...rest, service_tier: null };
|
||||
return { ...rest, service_tier: legacy ? "fast" : "default" };
|
||||
}
|
||||
|
||||
/**
|
||||
* The built-in adapter a provider id runs on: a custom provider is named by the one it
|
||||
* `extends`, followed until a provider that extends nothing. `extendsOf` is where the caller
|
||||
* reads that link (the registry's definitions, or `config.json`'s `providers` section).
|
||||
*/
|
||||
export function resolveAdapter(input: {
|
||||
provider: string;
|
||||
extendsOf: (provider: string) => string | null | undefined;
|
||||
}): string {
|
||||
const seen = new Set<string>();
|
||||
let current = input.provider;
|
||||
for (;;) {
|
||||
seen.add(current);
|
||||
const base = input.extendsOf(current);
|
||||
if (!base || seen.has(base)) return current;
|
||||
current = base;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01.
|
||||
* Older clients, stored records, profiles, and plugin hooks carry composer values in
|
||||
* `featureValues`. This is the one place they become `providerOptions`; an explicit
|
||||
* `providerOptions` key wins over a `featureValues` key of the same name.
|
||||
*/
|
||||
export function foldFeatureValues<
|
||||
T extends {
|
||||
providerOptions?: ProviderOptions | null;
|
||||
featureValues?: Record<string, unknown> | null;
|
||||
},
|
||||
>(config: T): Omit<T, "featureValues"> {
|
||||
const { featureValues, ...rest } = config;
|
||||
if (!featureValues || Object.keys(featureValues).length === 0) return rest;
|
||||
return { ...rest, providerOptions: { ...featureValues, ...rest.providerOptions } };
|
||||
}
|
||||
|
||||
/**
|
||||
* COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01.
|
||||
* A plugin written against the previous SDK reads and edits `config.featureValues`, so a
|
||||
* hook sees a copy of the config's options there. What the hook did to that copy (set,
|
||||
* replaced or deleted a key, or dropped the field) is applied as a patch over the options it
|
||||
* returned; keys it left alone change nothing.
|
||||
*/
|
||||
export function exposeFeatureValuesToHook<
|
||||
T extends { providerOptions?: ProviderOptions | null; featureValues?: Record<string, unknown> },
|
||||
>(config: T): T {
|
||||
if (!config.providerOptions || Object.keys(config.providerOptions).length === 0) return config;
|
||||
return { ...config, featureValues: { ...config.providerOptions } };
|
||||
}
|
||||
|
||||
export function foldHookFeatureValues<
|
||||
T extends {
|
||||
providerOptions?: ProviderOptions | null;
|
||||
featureValues?: Record<string, unknown>;
|
||||
},
|
||||
>(input: {
|
||||
returned: T;
|
||||
sent: T;
|
||||
/** Brings what the hook returned to the form of the copy it was sent. */
|
||||
convert: (options: Record<string, unknown>) => Record<string, unknown>;
|
||||
}): Omit<T, "featureValues"> {
|
||||
const { returned, sent, convert } = input;
|
||||
const { featureValues, ...rest } = returned;
|
||||
const before = sent.featureValues;
|
||||
if (!before) {
|
||||
// No copy was sent, so everything the hook put in `featureValues` is new.
|
||||
return foldFeatureValues(returned);
|
||||
}
|
||||
// A hook may return an older key where it was sent the current one; comparing in the same
|
||||
// form keeps a replaced value from reading as a deletion.
|
||||
const after = convert(featureValues ?? {});
|
||||
const patch: ProviderOptionsPatch = {};
|
||||
for (const key of new Set([...Object.keys(before), ...Object.keys(after)])) {
|
||||
if (isDeepStrictEqual(after[key], before[key])) continue;
|
||||
patch[key] = key in after ? after[key] : null;
|
||||
}
|
||||
return {
|
||||
...rest,
|
||||
providerOptions: applyProviderOptionsPatch({
|
||||
options: rest.providerOptions ?? undefined,
|
||||
patch,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
type ConvertedOptions = Record<string, unknown> | undefined;
|
||||
|
||||
interface ProfileOptionFields {
|
||||
provider?: string;
|
||||
options?: Record<string, unknown>;
|
||||
featureValues?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
/**
|
||||
* COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01.
|
||||
* Profiles saved before options carry `featureValues`; when one comes from storage, `options`
|
||||
* wins over a stale `featureValues` key.
|
||||
*
|
||||
* A write that carries `options` is from a client that knows them: its `featureValues` fold
|
||||
* over those. A write without `options` is from the unchanged app, whose form only knows the
|
||||
* controls: its `featureValues` are a patch (`null` deletes) over the options stored for that
|
||||
* profile, so options the form never shows, such as `sandbox_mode`, survive an edit. A profile
|
||||
* moved to another provider starts from no options, because the old provider's keys mean
|
||||
* nothing to the new one.
|
||||
*/
|
||||
export function foldProfileFeatureValues<T extends ProfileOptionFields>(input: {
|
||||
profile: T;
|
||||
stored: ProfileOptionFields | undefined;
|
||||
source: "stored" | "client write";
|
||||
/** Renames old option keys for the adapter the profile's provider runs on. */
|
||||
convert: (provider: string, options: Record<string, unknown> | undefined) => ConvertedOptions;
|
||||
}): Omit<T, "featureValues"> {
|
||||
const { profile, stored, source, convert } = input;
|
||||
const { featureValues: legacyValues, ...rest } = profile;
|
||||
// A profile is stored in the current keys, so removal and merging below see one vocabulary.
|
||||
const provider = rest.provider ?? "";
|
||||
const featureValues = convert(provider, legacyValues);
|
||||
const ownOptions = convert(provider, rest.options);
|
||||
if (source === "stored") {
|
||||
if (featureValues) return { ...rest, options: { ...featureValues, ...ownOptions } };
|
||||
return ownOptions ? { ...rest, options: ownOptions } : rest;
|
||||
}
|
||||
const base =
|
||||
ownOptions ??
|
||||
(stored?.provider === rest.provider ? convert(provider, stored?.options) : undefined);
|
||||
// The form sends no `featureValues` when no control is set, which is still an edit of a
|
||||
// profile that may hold other options.
|
||||
if (!featureValues && !base) return rest;
|
||||
return {
|
||||
...rest,
|
||||
options: applyProviderOptionsPatch({ options: base, patch: featureValues ?? {} }),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01.
|
||||
* The unchanged app reads a profile's options from `featureValues`; the config API answers with
|
||||
* both fields.
|
||||
*/
|
||||
export function withLegacyProfileFeatureValues<T extends ProfileOptionFields>(profile: T): T {
|
||||
return profile.options ? { ...profile, featureValues: { ...profile.options } } : profile;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user