Skip to content

Commit f1f061e

Browse files
authored
feat: fix model nits (#1376)
## Problem Model IDs in the ACP connection configuration options display with provider prefixes (e.g., "anthropic/claude-3-sonnet") instead of user-friendly names, making them harder to read in the UI. ## Changes - Added `formatModelId` function to strip provider prefixes from model IDs for display purposes - Updated ACP connection adapter to format model option names using the new function while preserving original values - Improved type definitions for model options and groups with proper TypeScript interfaces - Fixed model sanitization logic to only apply default gateway model when not using codex adapter - Removed unused `close` capability from Claude agent initialization ## How did you test this? Manual testing of model selection UI to verify that model names display without provider prefixes while maintaining correct functionality for model selection and filtering. closes: #1320
1 parent c7916f8 commit f1f061e

4 files changed

Lines changed: 24 additions & 14 deletions

File tree

packages/agent/src/adapters/acp-connection.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { AgentSideConnection, ndJsonStream } from "@agentclientprotocol/sdk";
22
import { POSTHOG_NOTIFICATIONS } from "../acp-extensions";
3+
import { formatModelId } from "../gateway-models";
34
import type { SessionLogWriter } from "../session-log-writer";
45
import type { ProcessSpawnedCallback } from "../types";
56
import { Logger } from "../utils/logger";
@@ -36,21 +37,27 @@ export type AcpConnection = {
3637

3738
export type InProcessAcpConnection = AcpConnection;
3839

40+
type ModelOption = { value?: string; name?: string };
41+
type ModelGroup = { group?: string; name?: string; options?: ModelOption[] };
42+
3943
type ConfigOption = {
4044
id?: string;
4145
category?: string | null;
4246
currentValue?: string;
43-
options?: Array<
44-
{ value?: string } | { group?: string; options?: Array<{ value?: string }> }
45-
>;
47+
options?: Array<ModelOption | ModelGroup>;
4648
};
4749

4850
function isGroupedOptions(
4951
options: NonNullable<ConfigOption["options"]>,
50-
): options is Array<{ group?: string; options?: Array<{ value?: string }> }> {
52+
): options is ModelGroup[] {
5153
return options.length > 0 && "group" in options[0];
5254
}
5355

56+
function formatOption(o: ModelOption): ModelOption {
57+
if (!o.value) return o;
58+
return { ...o, name: formatModelId(o.value) };
59+
}
60+
5461
function filterModelConfigOptions(
5562
msg: Record<string, unknown>,
5663
allowedModelIds: Set<string>,
@@ -74,9 +81,9 @@ function filterModelConfigOptions(
7481
if (isGroupedOptions(options)) {
7582
const filteredOptions = options.map((group) => ({
7683
...group,
77-
options: (group.options ?? []).filter(
78-
(o) => o?.value && allowedModelIds.has(o.value),
79-
),
84+
options: (group.options ?? [])
85+
.filter((o) => o?.value && allowedModelIds.has(o.value))
86+
.map(formatOption),
8087
}));
8188
const flat = filteredOptions.flatMap((g) => g.options ?? []);
8289
const currentAllowed =
@@ -91,10 +98,10 @@ function filterModelConfigOptions(
9198
};
9299
}
93100

94-
const valueOptions = options as Array<{ value?: string }>;
95-
const filteredOptions = valueOptions.filter(
96-
(o) => o?.value && allowedModelIds.has(o.value),
97-
);
101+
const valueOptions = options as ModelOption[];
102+
const filteredOptions = valueOptions
103+
.filter((o) => o?.value && allowedModelIds.has(o.value))
104+
.map(formatOption);
98105
const currentAllowed =
99106
opt.currentValue && allowedModelIds.has(opt.currentValue);
100107
const nextCurrent =

packages/agent/src/adapters/claude/claude-agent.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
143143
list: {},
144144
fork: {},
145145
resume: {},
146-
close: {},
147146
},
148147
_meta: {
149148
posthog: {

packages/agent/src/agent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export class Agent {
107107
sanitizedModel = codexModelIds[0];
108108
}
109109
}
110-
if (!sanitizedModel) {
110+
if (!sanitizedModel && options.adapter !== "codex") {
111111
sanitizedModel = DEFAULT_GATEWAY_MODEL;
112112
}
113113

packages/agent/src/gateway-models.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ export function getProviderName(ownedBy: string): string {
146146
const PROVIDER_PREFIXES = ["anthropic/", "openai/", "google-vertex/"];
147147

148148
export function formatGatewayModelName(model: GatewayModel): string {
149-
let cleanId = model.id;
149+
return formatModelId(model.id);
150+
}
151+
152+
export function formatModelId(modelId: string): string {
153+
let cleanId = modelId;
150154
for (const prefix of PROVIDER_PREFIXES) {
151155
if (cleanId.startsWith(prefix)) {
152156
cleanId = cleanId.slice(prefix.length);

0 commit comments

Comments
 (0)