mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-10 12:07:09 +02:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work.
> - Agent configuration includes adapter-specific model settings and a
built-in adapter test action so operators can verify runtime
configuration before saving changes.
> - Cody/Codex-style local adapters can use an adapter default model
when the user clears the explicit model field.
> - The adapter test path still passed an object containing `model:
undefined` in some create/edit flows, which is different from omitting
the model and can break default-model behavior.
> - The previous fix was reverted because it also included an unrelated
skill documentation edit.
> - This pull request reapplies only the UI default-model test-config
fix, with no doc or skill changes.
> - The benefit is that testing Cody/Codex adapter settings with the
default model follows the same contract as saving default model
settings: no explicit model key is sent.
## Linked Issues or Issue Description
Bug report:
- Summary: Testing a Cody/Codex local agent after selecting the default
model could send an adapter config with an undefined model value instead
of omitting the model key.
- Expected behavior: Clearing the model to use the adapter default
should test with `adapterConfig: {}` unless another model is explicitly
selected.
- Actual behavior: The UI test-config path could preserve `model:
undefined`, causing the adapter test to fail instead of exercising the
default model.
- Related PRs: Reapplies the UI-only portion of #9361 after #9363
reverted the original PR.
## What Changed
- Exported and reused `omitUndefinedEntries` so adapter test config
payloads drop undefined adapter config entries before calling the test
endpoint.
- Hardened the current model display value so create-mode values that
are nullish or non-string do not crash the model selector/test flow.
- Added render coverage for editing a Codex agent back to the default
model and for testing a create form with the default model.
## Verification
- `pnpm exec vitest run
ui/src/components/AgentConfigForm.render.test.tsx`
- `pnpm check:token-gates`
- Confirmed `git diff origin/master --name-only` contains only:
- `ui/src/components/AgentConfigForm.render.test.tsx`
- `ui/src/components/AgentConfigForm.tsx`
- `ui/src/lib/agent-config-patch.ts`
## Risks
Low risk. The change only removes `undefined` adapter config entries
from the UI adapter-test payload and adds focused render coverage.
Explicit model values and other adapter config fields are preserved.
> 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, GPT-5 coding agent, tool-use enabled. Context window size
not exposed in this 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
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
Co-authored-by: Paperclip <noreply@paperclip.ing>
109 lines
3.5 KiB
TypeScript
109 lines
3.5 KiB
TypeScript
import { ADAPTER_AGNOSTIC_KEYS, type Agent } from "@paperclipai/shared";
|
|
|
|
export interface AgentModelProfileOverlay {
|
|
enabled?: boolean;
|
|
adapterConfig?: Record<string, unknown>;
|
|
/**
|
|
* Mark the cheap profile for clearing. When true, the patch removes
|
|
* `runtimeConfig.modelProfiles.cheap` instead of merging into it.
|
|
*/
|
|
cleared?: boolean;
|
|
}
|
|
|
|
export interface AgentConfigOverlay {
|
|
identity: Record<string, unknown>;
|
|
adapterType?: string;
|
|
adapterConfig: Record<string, unknown>;
|
|
heartbeat: Record<string, unknown>;
|
|
runtime: Record<string, unknown>;
|
|
modelProfiles?: { cheap?: AgentModelProfileOverlay };
|
|
}
|
|
|
|
export function omitUndefinedEntries(value: Record<string, unknown>) {
|
|
return Object.fromEntries(
|
|
Object.entries(value).filter(([, entryValue]) => entryValue !== undefined),
|
|
);
|
|
}
|
|
|
|
export function buildAgentUpdatePatch(agent: Agent, overlay: AgentConfigOverlay) {
|
|
const patch: Record<string, unknown> = {};
|
|
|
|
if (Object.keys(overlay.identity).length > 0) {
|
|
Object.assign(patch, overlay.identity);
|
|
}
|
|
|
|
if (overlay.adapterType !== undefined) {
|
|
patch.adapterType = overlay.adapterType;
|
|
}
|
|
|
|
if (overlay.adapterType !== undefined || Object.keys(overlay.adapterConfig).length > 0) {
|
|
const existing = (agent.adapterConfig ?? {}) as Record<string, unknown>;
|
|
const nextAdapterConfig =
|
|
overlay.adapterType !== undefined
|
|
? {
|
|
...Object.fromEntries(
|
|
ADAPTER_AGNOSTIC_KEYS
|
|
.filter((key) => existing[key] !== undefined)
|
|
.map((key) => [key, existing[key]]),
|
|
),
|
|
...overlay.adapterConfig,
|
|
}
|
|
: {
|
|
...existing,
|
|
...overlay.adapterConfig,
|
|
};
|
|
|
|
patch.adapterConfig = omitUndefinedEntries(nextAdapterConfig);
|
|
patch.replaceAdapterConfig = true;
|
|
}
|
|
|
|
const cheapOverlay = overlay.modelProfiles?.cheap;
|
|
const hasModelProfileChange = cheapOverlay !== undefined;
|
|
|
|
if (Object.keys(overlay.heartbeat).length > 0 || hasModelProfileChange) {
|
|
const existingRc = (agent.runtimeConfig ?? {}) as Record<string, unknown>;
|
|
const nextRuntimeConfig: Record<string, unknown> = (patch.runtimeConfig as Record<string, unknown> | undefined)
|
|
?? { ...existingRc };
|
|
|
|
if (Object.keys(overlay.heartbeat).length > 0) {
|
|
const existingHb = (existingRc.heartbeat ?? {}) as Record<string, unknown>;
|
|
nextRuntimeConfig.heartbeat = { ...existingHb, ...overlay.heartbeat };
|
|
}
|
|
|
|
if (hasModelProfileChange) {
|
|
const existingProfiles = ((existingRc.modelProfiles ?? {}) as Record<string, unknown>);
|
|
const existingCheap = ((existingProfiles.cheap ?? {}) as Record<string, unknown>);
|
|
const nextProfiles = { ...existingProfiles };
|
|
|
|
if (cheapOverlay?.cleared) {
|
|
delete nextProfiles.cheap;
|
|
} else if (cheapOverlay) {
|
|
const mergedAdapterConfig = {
|
|
...((existingCheap.adapterConfig ?? {}) as Record<string, unknown>),
|
|
...(cheapOverlay.adapterConfig ?? {}),
|
|
};
|
|
const enabled = cheapOverlay.enabled ?? (existingCheap.enabled !== false);
|
|
nextProfiles.cheap = {
|
|
...existingCheap,
|
|
enabled,
|
|
adapterConfig: mergedAdapterConfig,
|
|
};
|
|
}
|
|
|
|
if (Object.keys(nextProfiles).length === 0) {
|
|
delete nextRuntimeConfig.modelProfiles;
|
|
} else {
|
|
nextRuntimeConfig.modelProfiles = nextProfiles;
|
|
}
|
|
}
|
|
|
|
patch.runtimeConfig = nextRuntimeConfig;
|
|
}
|
|
|
|
if (Object.keys(overlay.runtime).length > 0) {
|
|
Object.assign(patch, overlay.runtime);
|
|
}
|
|
|
|
return patch;
|
|
}
|