mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-17 03:10:38 +09:00
Add cheap model profiles for local adapters (#4881)
## Thinking Path > - Paperclip is a control plane for autonomous AI companies, where adapters are the boundary between the board, agents, and execution runtimes. > - Local adapters currently expose a primary runtime configuration, but operators often need a cheaper model lane for routine or low-risk work. > - That cheap lane has to stay adapter-owned: runtime profile settings should not mutate the primary adapter config or bypass existing auth/secret mediation. > - Issue creation also needs an ergonomic way to request primary, cheap, or custom model behavior for a selected assignee. > - This pull request adds a first-class `cheap` model profile contract across adapter capabilities, heartbeat config resolution, agent configuration, and issue creation. > - The benefit is cheaper task execution can be configured and requested explicitly while preserving adapter boundaries, secret handling, and audit visibility. ## What Changed - Added adapter model-profile capability metadata and a `cheap` profile contract for supported local adapters. - Applied `runtimeConfig.modelProfiles.cheap.adapterConfig` during heartbeat config resolution, including requested/applied/fallback run metadata. - Added agent configuration UI for cheap model profile settings without writing those settings into primary `adapterConfig`. - Added New Issue assignee model lane controls for Primary / Cheap / Custom and request payload handling. - Added run ledger profile badges and Storybook stories for the new cheap-lane UI states. - Added tests for validators, heartbeat model profile application, permission/secret mediation, UI payload helpers, and run ledger rendering. - Added committed UI verification screenshots under `docs/pr-screenshots/pap-2837/`. - Addressed Greptile review feedback around cheap-profile defaults, shared profile types, and fallback test data. ## Verification Local: - `pnpm exec vitest run packages/shared/src/validators/issue.test.ts server/src/__tests__/adapter-registry.test.ts server/src/__tests__/agent-permissions-routes.test.ts server/src/__tests__/heartbeat-model-profile.test.ts ui/src/components/IssueRunLedger.test.tsx ui/src/lib/agent-config-patch.test.ts ui/src/lib/issue-assignee-overrides.test.ts ui/src/lib/new-agent-runtime-config.test.ts` — passed, 8 files / 103 tests. - `pnpm exec vitest run ui/src/lib/new-agent-runtime-config.test.ts ui/src/components/IssueRunLedger.test.tsx` — passed after Greptile/rebase follow-up, 2 files / 17 tests. - `pnpm --filter @paperclipai/ui typecheck` — passed after Greptile/rebase follow-up. - `pnpm -r typecheck` — passed. - `pnpm build` — passed. - `pnpm test:run` — did not complete successfully in this local worktree: it stopped in pre-existing `@paperclipai/adapter-utils` sandbox/SSH fixture suites outside this PR diff. Failures were 5s local timeouts plus `git init -b` unsupported by this machine's Git 2.21.0. The branch-specific targeted suites above passed. - Branch was fetched/rebased onto `public-gh/master`; `git rev-list --left-right --count public-gh/master...HEAD` reports `0 9`. Remote PR checks on latest head `e30bf399146451c86cee98ed528d51d33fa5af5a`: - `policy` — passed. - `verify` — passed. - `e2e` — passed. - `Greptile Review` — passed, confidence score 5/5; Greptile review threads resolved. - `security/snyk (cryppadotta)` — passed. Screenshots: - [New issue cheap lane desktop](https://github.com/paperclipai/paperclip/blob/PAP-2837-plan-cheap-model-for-adapters-that-can-support-it/docs/pr-screenshots/pap-2837/newissue-cheap-desktop.png) - [New issue custom lane desktop](https://github.com/paperclipai/paperclip/blob/PAP-2837-plan-cheap-model-for-adapters-that-can-support-it/docs/pr-screenshots/pap-2837/newissue-custom-desktop.png) - [New issue unsupported adapter desktop](https://github.com/paperclipai/paperclip/blob/PAP-2837-plan-cheap-model-for-adapters-that-can-support-it/docs/pr-screenshots/pap-2837/newissue-unsupported-desktop.png) - [Run ledger model profile badges desktop](https://github.com/paperclipai/paperclip/blob/PAP-2837-plan-cheap-model-for-adapters-that-can-support-it/docs/pr-screenshots/pap-2837/runledger-profile-badges-desktop.png) - Mobile variants are also in `docs/pr-screenshots/pap-2837/`. ## Risks - Medium: heartbeat config mediation now merges runtime model profiles into adapter configs, so adapter secret normalization and host-command restrictions must keep covering nested config paths. - Medium: the UI adds another issue creation choice; unsupported adapters must keep hiding the cheap lane and preserve primary behavior. - Low migration risk: no database migration is included. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used OpenAI Codex coding agent using GPT-5-class reasoning with repo tool use and command execution. Exact served model/context window was not exposed by the runtime. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [ ] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] If this change affects the UI, I have included before/after screenshots - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing> Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
1fe1067361
commit
a3de1d764d
60 changed files with 2216 additions and 151 deletions
|
|
@ -41,6 +41,7 @@ import {
|
|||
help,
|
||||
adapterLabels,
|
||||
} from "./agent-config-primitives";
|
||||
import { ToggleSwitch } from "@/components/ui/toggle-switch";
|
||||
import { defaultCreateValues } from "./agent-config-defaults";
|
||||
import { getUIAdapter } from "../adapters";
|
||||
import { ClaudeLocalAdvancedFields } from "../adapters/claude-local/config-fields";
|
||||
|
|
@ -117,7 +118,8 @@ function isOverlayDirty(o: AgentConfigOverlay): boolean {
|
|||
o.adapterType !== undefined ||
|
||||
Object.keys(o.adapterConfig).length > 0 ||
|
||||
Object.keys(o.heartbeat).length > 0 ||
|
||||
Object.keys(o.runtime).length > 0
|
||||
Object.keys(o.runtime).length > 0 ||
|
||||
o.modelProfiles?.cheap !== undefined
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -244,15 +246,17 @@ export function AgentConfigForm(props: AgentConfigFormProps) {
|
|||
|
||||
const isDirty = !isCreate && isOverlayDirty(overlay);
|
||||
|
||||
type RecordOverlayGroup = "identity" | "adapterConfig" | "heartbeat" | "runtime";
|
||||
|
||||
/** Read effective value: overlay if dirty, else original */
|
||||
function eff<T>(group: keyof Omit<AgentConfigOverlay, "adapterType">, field: string, original: T): T {
|
||||
function eff<T>(group: RecordOverlayGroup, field: string, original: T): T {
|
||||
const o = overlay[group];
|
||||
if (field in o) return o[field] as T;
|
||||
return original;
|
||||
}
|
||||
|
||||
/** Mark field dirty in overlay */
|
||||
function mark(group: keyof Omit<AgentConfigOverlay, "adapterType">, field: string, value: unknown) {
|
||||
function mark(group: RecordOverlayGroup, field: string, value: unknown) {
|
||||
setOverlay((prev) => ({
|
||||
...prev,
|
||||
[group]: { ...prev[group], [field]: value },
|
||||
|
|
@ -374,8 +378,30 @@ export function AgentConfigForm(props: AgentConfigFormProps) {
|
|||
const [runPolicyAdvancedOpen, setRunPolicyAdvancedOpen] = useState(false);
|
||||
// Popover states
|
||||
const [modelOpen, setModelOpen] = useState(false);
|
||||
const [cheapModelOpen, setCheapModelOpen] = useState(false);
|
||||
const [thinkingEffortOpen, setThinkingEffortOpen] = useState(false);
|
||||
|
||||
// Cheap model profile state — only relevant when the adapter advertises
|
||||
// `supportsModelProfiles`. Defaults are sourced from the adapter's
|
||||
// /model-profiles endpoint so the UI does not encode adapter-specific
|
||||
// cheap defaults.
|
||||
const supportsModelProfiles = adapterCaps.supportsModelProfiles;
|
||||
const { data: adapterCheapProfileDefinitions } = useQuery({
|
||||
queryKey: selectedCompanyId
|
||||
? queryKeys.agents.adapterModelProfiles(selectedCompanyId, adapterType)
|
||||
: ["agents", "none", "adapter-model-profiles", adapterType],
|
||||
queryFn: () => agentsApi.adapterModelProfiles(selectedCompanyId!, adapterType),
|
||||
enabled: Boolean(selectedCompanyId) && supportsModelProfiles,
|
||||
});
|
||||
const adapterCheapDefault = useMemo(() => {
|
||||
return (adapterCheapProfileDefinitions ?? []).find((profile) => profile.key === "cheap") ?? null;
|
||||
}, [adapterCheapProfileDefinitions]);
|
||||
const adapterCheapDefaultModel = useMemo(() => {
|
||||
const adapterConfig = adapterCheapDefault?.adapterConfig ?? {};
|
||||
const value = (adapterConfig as Record<string, unknown>).model;
|
||||
return typeof value === "string" ? value : "";
|
||||
}, [adapterCheapDefault]);
|
||||
|
||||
// Create mode helpers
|
||||
const val = isCreate ? props.values : null;
|
||||
const set = isCreate
|
||||
|
|
@ -516,6 +542,69 @@ export function AgentConfigForm(props: AgentConfigFormProps) {
|
|||
const codexSearchEnabled = adapterType === "codex_local"
|
||||
? (isCreate ? Boolean(val!.search) : eff("adapterConfig", "search", Boolean(config.search)))
|
||||
: false;
|
||||
// Cheap profile read/write helpers. Edit-mode values come from
|
||||
// runtimeConfig.modelProfiles.cheap with overlay overrides on top; create-mode
|
||||
// values come straight from CreateConfigValues (cheapModel + cheapModelEnabled).
|
||||
const cheapProfileFromAgent = useMemo(() => {
|
||||
const profiles = (runtimeConfig.modelProfiles ?? {}) as Record<string, unknown>;
|
||||
const cheap = (profiles.cheap ?? {}) as Record<string, unknown>;
|
||||
const cheapAdapterConfig = (cheap.adapterConfig ?? {}) as Record<string, unknown>;
|
||||
return {
|
||||
enabled: cheap.enabled !== false,
|
||||
model: typeof cheapAdapterConfig.model === "string" ? cheapAdapterConfig.model : "",
|
||||
};
|
||||
}, [runtimeConfig]);
|
||||
const cheapOverlay = !isCreate ? overlay.modelProfiles?.cheap : undefined;
|
||||
const currentCheapEnabled = isCreate
|
||||
? val!.cheapModelEnabled ?? false
|
||||
: cheapOverlay?.enabled ?? cheapProfileFromAgent.enabled;
|
||||
const currentCheapModel = isCreate
|
||||
? val!.cheapModel ?? ""
|
||||
: (() => {
|
||||
const overlayModel = (cheapOverlay?.adapterConfig as Record<string, unknown> | undefined)?.model;
|
||||
if (typeof overlayModel === "string") return overlayModel;
|
||||
return cheapProfileFromAgent.model;
|
||||
})();
|
||||
|
||||
function setCheapEnabled(next: boolean) {
|
||||
if (isCreate) {
|
||||
set!({ cheapModelEnabled: next });
|
||||
return;
|
||||
}
|
||||
setOverlay((prev) => ({
|
||||
...prev,
|
||||
modelProfiles: {
|
||||
cheap: {
|
||||
...(prev.modelProfiles?.cheap ?? {}),
|
||||
enabled: next,
|
||||
},
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
||||
function setCheapModel(next: string) {
|
||||
if (isCreate) {
|
||||
set!({ cheapModel: next });
|
||||
return;
|
||||
}
|
||||
setOverlay((prev) => {
|
||||
const existing = prev.modelProfiles?.cheap ?? {};
|
||||
const nextAdapterConfig = {
|
||||
...((existing.adapterConfig ?? {}) as Record<string, unknown>),
|
||||
model: next || undefined,
|
||||
};
|
||||
return {
|
||||
...prev,
|
||||
modelProfiles: {
|
||||
cheap: {
|
||||
...existing,
|
||||
adapterConfig: nextAdapterConfig,
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
const effectiveRuntimeConfig = useMemo(() => {
|
||||
if (isCreate) {
|
||||
return {
|
||||
|
|
@ -720,6 +809,7 @@ export function AgentConfigForm(props: AgentConfigFormProps) {
|
|||
setOverlay((prev) => ({
|
||||
...prev,
|
||||
adapterType: t,
|
||||
modelProfiles: { cheap: { cleared: true } },
|
||||
adapterConfig: {
|
||||
model:
|
||||
t === "codex_local"
|
||||
|
|
@ -832,6 +922,9 @@ export function AgentConfigForm(props: AgentConfigFormProps) {
|
|||
/>
|
||||
</Field>
|
||||
|
||||
{supportsModelProfiles && (
|
||||
<div className="text-[11px] uppercase tracking-wide text-muted-foreground">Primary model</div>
|
||||
)}
|
||||
<ModelDropdown
|
||||
models={models}
|
||||
value={currentModelId}
|
||||
|
|
@ -866,6 +959,20 @@ export function AgentConfigForm(props: AgentConfigFormProps) {
|
|||
</p>
|
||||
)}
|
||||
|
||||
{supportsModelProfiles && (
|
||||
<CheapModelSection
|
||||
enabled={currentCheapEnabled}
|
||||
model={currentCheapModel}
|
||||
models={models}
|
||||
adapterType={adapterType}
|
||||
adapterDefaultModel={adapterCheapDefaultModel}
|
||||
onEnabledChange={setCheapEnabled}
|
||||
onModelChange={setCheapModel}
|
||||
open={cheapModelOpen}
|
||||
onOpenChange={setCheapModelOpen}
|
||||
/>
|
||||
)}
|
||||
|
||||
{showThinkingEffort && (
|
||||
<>
|
||||
<ThinkingEffortDropdown
|
||||
|
|
@ -1201,6 +1308,7 @@ function ModelDropdown({
|
|||
refreshingModels,
|
||||
detectModelLabel,
|
||||
emptyDetectHint,
|
||||
defaultLabel,
|
||||
}: {
|
||||
models: AdapterModel[];
|
||||
value: string;
|
||||
|
|
@ -1218,6 +1326,7 @@ function ModelDropdown({
|
|||
refreshingModels?: boolean;
|
||||
detectModelLabel?: string;
|
||||
emptyDetectHint?: string;
|
||||
defaultLabel?: string;
|
||||
}) {
|
||||
const [modelSearch, setModelSearch] = useState("");
|
||||
const [detectingModel, setDetectingModel] = useState(false);
|
||||
|
|
@ -1304,7 +1413,8 @@ function ModelDropdown({
|
|||
<span className={cn(!value && "text-muted-foreground")}>
|
||||
{selected
|
||||
? selected.label
|
||||
: value || (allowDefault ? "Default" : required ? "Select model (required)" : "Select model")}
|
||||
: value
|
||||
|| (allowDefault ? (defaultLabel ?? "Default") : required ? "Select model (required)" : "Select model")}
|
||||
</span>
|
||||
<ChevronDown className="h-3 w-3 text-muted-foreground" />
|
||||
</button>
|
||||
|
|
@ -1500,6 +1610,72 @@ function ModelDropdown({
|
|||
);
|
||||
}
|
||||
|
||||
function CheapModelSection({
|
||||
enabled,
|
||||
model,
|
||||
models,
|
||||
adapterType,
|
||||
adapterDefaultModel,
|
||||
onEnabledChange,
|
||||
onModelChange,
|
||||
open,
|
||||
onOpenChange,
|
||||
}: {
|
||||
enabled: boolean;
|
||||
model: string;
|
||||
models: AdapterModel[];
|
||||
adapterType: string;
|
||||
adapterDefaultModel: string;
|
||||
onEnabledChange: (next: boolean) => void;
|
||||
onModelChange: (next: string) => void;
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
}) {
|
||||
const placeholderHint = adapterDefaultModel
|
||||
? `Adapter default · ${adapterDefaultModel}`
|
||||
: "No adapter default — choose a cheaper model";
|
||||
return (
|
||||
<div className="rounded-md border border-border/70 bg-muted/20 p-3 space-y-3">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<div className="text-[11px] uppercase tracking-wide text-muted-foreground">Cheap model</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Used when a run requests the cheap profile (e.g. routine summaries). The primary model stays unchanged.
|
||||
</p>
|
||||
</div>
|
||||
<ToggleSwitch checked={enabled} onCheckedChange={onEnabledChange} />
|
||||
</div>
|
||||
{enabled ? (
|
||||
<ModelDropdown
|
||||
models={models}
|
||||
value={model}
|
||||
onChange={onModelChange}
|
||||
open={open}
|
||||
onOpenChange={onOpenChange}
|
||||
allowDefault
|
||||
required={false}
|
||||
groupByProvider={adapterType === "opencode_local"}
|
||||
creatable
|
||||
detectedModel={null}
|
||||
detectedModelCandidates={[]}
|
||||
emptyDetectHint={placeholderHint}
|
||||
defaultLabel={placeholderHint}
|
||||
/>
|
||||
) : null}
|
||||
{enabled && !model && adapterDefaultModel ? (
|
||||
<p className="text-[11px] text-muted-foreground">
|
||||
No explicit cheap model selected — runtime falls back to <code>{adapterDefaultModel}</code>.
|
||||
</p>
|
||||
) : null}
|
||||
{enabled && !model && !adapterDefaultModel ? (
|
||||
<p className="text-[11px] text-amber-500">
|
||||
No cheap model selected and the adapter has no default. Cheap-lane runs will continue on the primary model with a fallback note.
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ThinkingEffortDropdown({
|
||||
value,
|
||||
options,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue