Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions apps/server/src/provider/acp/AcpProviderModels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,125 @@ describe("GENERIC_ACP_MODEL_OPTION_MAPPING", () => {
]),
).toEqual([{ configId: "provider", value: "codex" }]);
});

it("keeps recognized thought_level ids and normalizes custom ACP thought_level ids onto reasoningEffort", () => {
const antigravityOptions = [
{
id: "model",
name: "Model",
category: "model",
type: "select",
currentValue: "gemini-4-neon",
options: [{ value: "gemini-4-neon", name: "Gemini 4 Neon" }],
},
{
id: "thought_level",
name: "Thinking Level",
category: "thought_level",
type: "select",
currentValue: "high",
options: [
{ value: "xhigh", name: "Extra" },
{ value: "high", name: "High" },
{ value: "medium", name: "Medium" },
{ value: "low", name: "Low" },
],
},
] satisfies ReadonlyArray<EffectAcpSchema.SessionConfigOption>;

const capabilities =
GENERIC_ACP_MODEL_OPTION_MAPPING.capabilitiesFromConfigOptions(antigravityOptions);
const descriptor = capabilities.optionDescriptors?.[0];
expect(descriptor).toEqual({
id: "thought_level",
label: "Thinking Level",
type: "select",
currentValue: "high",
options: [
{ id: "low", label: "Low" },
{ id: "medium", label: "Medium" },
{ id: "high", label: "High", isDefault: true },
{ id: "xhigh", label: "Extra" },
],
});
expect(
GENERIC_ACP_MODEL_OPTION_MAPPING.configUpdatesFromSelections(antigravityOptions, [
{ id: "thought_level", value: "xhigh" },
]),
).toEqual([{ configId: "thought_level", value: "xhigh" }]);

const vendorEffortOptions = [
{
id: "reasoning_effort",
name: "Reasoning Effort",
category: "thought_level",
type: "select",
currentValue: "high",
options: [
{ value: "high", name: "High" },
{ value: "low", name: "Low" },
],
},
] satisfies ReadonlyArray<EffectAcpSchema.SessionConfigOption>;
expect(
GENERIC_ACP_MODEL_OPTION_MAPPING.capabilitiesFromConfigOptions(
vendorEffortOptions,
).optionDescriptors?.map((entry) => entry.id),
).toEqual(["reasoningEffort"]);
expect(
GENERIC_ACP_MODEL_OPTION_MAPPING.configUpdatesFromSelections(vendorEffortOptions, [
{ id: "reasoningEffort", value: "low" },
]),
).toEqual([{ configId: "reasoning_effort", value: "low" }]);
// Saved selections written under the raw vendor id still apply.
expect(
GENERIC_ACP_MODEL_OPTION_MAPPING.configUpdatesFromSelections(vendorEffortOptions, [
{ id: "reasoning_effort", value: "high" },
]),
).toEqual([{ configId: "reasoning_effort", value: "high" }]);
});

it("drops a single-choice thought_level option and keeps already-known reasoning ids", () => {
const singleChoice = [
{
id: "thought_level",
name: "Thinking Level",
category: "thought_level",
type: "select",
currentValue: "high",
options: [{ value: "high", name: "High" }],
},
] satisfies ReadonlyArray<EffectAcpSchema.SessionConfigOption>;
expect(
GENERIC_ACP_MODEL_OPTION_MAPPING.capabilitiesFromConfigOptions(singleChoice)
.optionDescriptors,
).toEqual([]);

const customCommunity = [
{
id: "thinking_budget",
name: "Thinking",
category: "thought_level",
type: "select",
currentValue: "medium",
options: [
{ value: "low", name: "Low" },
{ value: "medium", name: "Medium" },
{ value: "high", name: "High" },
],
},
] satisfies ReadonlyArray<EffectAcpSchema.SessionConfigOption>;
expect(
NATIVE_ACP_MODEL_OPTION_MAPPING.capabilitiesFromConfigOptions(
customCommunity,
).optionDescriptors?.map((d) => d.id),
).toEqual(["reasoningEffort"]);
expect(
NATIVE_ACP_MODEL_OPTION_MAPPING.configUpdatesFromSelections(customCommunity, [
{ id: "reasoningEffort", value: "high" },
]),
).toEqual([{ configId: "thinking_budget", value: "high" }]);
});
});

describe("buildAcpModelsFromConfigOptions", () => {
Expand Down
75 changes: 67 additions & 8 deletions apps/server/src/provider/acp/AcpProviderModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import type {
ServerProviderModel,
} from "@threadlines/contracts";
import {
CANONICAL_REASONING_OPTION_ID,
createModelCapabilities,
getProviderOptionSelectionValue,
isReasoningOptionId,
} from "@threadlines/shared/model";
import type * as EffectAcpSchema from "effect-acp/schema";

Expand All @@ -27,7 +29,11 @@ import type {
AcpProviderDescriptor,
AcpProviderSettings,
} from "./AcpProviderDescriptor.ts";
import { findModelConfigOption, isModeConfigOption } from "./AcpRuntimeModel.ts";
import {
findModelConfigOption,
findThoughtLevelConfigOption,
isModeConfigOption,
} from "./AcpRuntimeModel.ts";

export const EMPTY_ACP_MODEL_CAPABILITIES: ModelCapabilities = createModelCapabilities({
optionDescriptors: [],
Expand Down Expand Up @@ -64,17 +70,54 @@ export function selectConfigOptionCurrentValue(
}

/**
* Mirrors every option but the model one-to-one. `modeOptions: "hidden"`
* leaves out mode-style options (driven by the runtime mode, never by the
* model picker); `"shown"` keeps them, for agents driven through their own
* controls.
* Descriptor id for an ACP `thought_level` select option. Keeps ids Threadlines
* already recognizes as reasoning (`effort`, `reasoning`, `reasoningEffort`,
* `variant`, `thought_level`), and maps any other id (`reasoning_effort` or a
* community agent's custom id) to `reasoningEffort` so the EffortMeter and
* reasoning helpers recognize it.
*/
export function acpThoughtLevelDescriptorId(
optionId: string,
otherOptionIds?: ReadonlySet<string>,
): string {
if (isReasoningOptionId(optionId) || otherOptionIds?.has(CANONICAL_REASONING_OPTION_ID)) {
return optionId;
}
return CANONICAL_REASONING_OPTION_ID;
}

/**
* Mirrors every option but the model one-to-one, normalizing an ACP
* `thought_level` select onto a recognized reasoning id so the EffortMeter
* handles it. `modeOptions: "hidden"` leaves out mode-style options (driven by
* the runtime mode, never by the model picker); `"shown"` keeps them, for
* agents driven through their own controls.
*/
const makeAcpModelOptionMapping = (modeOptions: "hidden" | "shown"): AcpModelOptionMapping => {
const isSessionControlOption = (option: EffectAcpSchema.SessionConfigOption) =>
modeOptions === "hidden" && isModeConfigOption(option);
const descriptorIdFor = (
option: EffectAcpSchema.SessionConfigOption,
thoughtLevelOption: EffectAcpSchema.SessionConfigOption | undefined,
otherOptionIds: ReadonlySet<string>,
) =>
option === thoughtLevelOption
? acpThoughtLevelDescriptorId(option.id, otherOptionIds)
: option.id;
return {
capabilitiesFromConfigOptions: (configOptions) => {
const modelOption = findModelConfigOption(configOptions);
const thoughtLevelOption = findThoughtLevelConfigOption(configOptions);
const otherOptionIds = new Set(
configOptions
.filter(
(candidate) =>
candidate !== modelOption &&
candidate !== thoughtLevelOption &&
!isSessionControlOption(candidate),
)
.map((candidate) => candidate.id),
);
const optionDescriptors: Array<ProviderOptionDescriptor> = [];
for (const option of configOptions) {
if (option === modelOption || isSessionControlOption(option)) {
Expand All @@ -97,13 +140,13 @@ const makeAcpModelOptionMapping = (modeOptions: "hidden" | "shown"): AcpModelOpt
continue;
}
const choices = flattenSessionConfigSelectOptions(option);
if (choices.length === 0) {
if (choices.length === 0 || (option === thoughtLevelOption && choices.length < 2)) {
continue;
}
const currentValue = selectConfigOptionCurrentValue(option);
optionDescriptors.push(
buildSelectOptionDescriptor({
id: option.id,
id: descriptorIdFor(option, thoughtLevelOption, otherOptionIds),
label,
options: choices.map((choice) => ({
value: choice.value,
Expand All @@ -121,12 +164,28 @@ const makeAcpModelOptionMapping = (modeOptions: "hidden" | "shown"): AcpModelOpt
return [];
}
const modelOption = findModelConfigOption(configOptions);
const thoughtLevelOption = findThoughtLevelConfigOption(configOptions);
const otherOptionIds = new Set(
configOptions
.filter(
(candidate) =>
candidate !== modelOption &&
candidate !== thoughtLevelOption &&
!isSessionControlOption(candidate),
)
.map((candidate) => candidate.id),
);
const updates: Array<AcpConfigUpdate> = [];
for (const option of configOptions) {
if (option === modelOption || isSessionControlOption(option)) {
continue;
}
const requested = getProviderOptionSelectionValue(selections, option.id);
const descriptorId = descriptorIdFor(option, thoughtLevelOption, otherOptionIds);
const requested =
getProviderOptionSelectionValue(selections, descriptorId) ??
(descriptorId !== option.id
? getProviderOptionSelectionValue(selections, option.id)
: undefined);
if (requested === undefined) {
continue;
}
Expand Down
16 changes: 16 additions & 0 deletions apps/server/src/provider/acp/AcpRuntimeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,22 @@ export function isModeConfigOption(option: EffectAcpSchema.SessionConfigOption):
return option.category === "mode" || option.id.trim().toLowerCase() === LEGACY_MODE_OPTION_ID;
}

/**
* The config option that selects the agent's reasoning / thinking level, by
* ACP's standard `thought_level` category. Only select options qualify.
*/
export function findThoughtLevelConfigOption(
configOptions: ReadonlyArray<EffectAcpSchema.SessionConfigOption> | null | undefined,
): EffectAcpSchema.SessionConfigOption | undefined {
if (!configOptions) return undefined;
return configOptions.find(
(option) =>
option.category === "thought_level" &&
option.type === "select" &&
option.id.trim().length > 0,
);
}

/**
* The older `modes` and `models` session fields as config options, each only
* where the agent lists no option of its own for it. Agents driven through
Expand Down
52 changes: 52 additions & 0 deletions apps/server/src/provider/acp/AntigravityAcpSupport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,58 @@ describe("Antigravity reasoning levels", () => {
expect(levels("gpt-6-1")).toBeUndefined();
});

it("does not mistake a single parenthesized model name like GPT-OSS 120B (Medium) for a legacy effort-in-name catalog", async () => {
const choices = [
{ value: "gemini-4-neon", name: "Gemini 4 Neon" },
{ value: "gpt-oss-120b-medium", name: "GPT-OSS 120B (Medium)" },
];
expect(
isAntigravityCatalogComplete({
choices,
currentValue: "gemini-4-neon",
thoughtLevels: {
"gemini-4-neon": {
configId: "thought_level",
name: "Thinking Level",
currentValue: "high",
options: [
{ value: "low", name: "Low" },
{ value: "high", name: "High" },
],
},
},
}),
).toBe(false);

let current = "gemini-4-neon";
const optionsFor = (slug: string): ReadonlyArray<EffectAcpSchema.SessionConfigOption> => [
{
id: "model",
name: "Model",
category: "model",
type: "select",
currentValue: slug,
options: choices,
},
...(slug === "gemini-4-neon" ? [thought("high", ["low", "high"])] : []),
];
const probed = await Effect.runPromise(
probeAntigravityModelOptions({
getConfigOptions: Effect.sync(() => optionsFor(current)),
setConfigOption: (_configId, value) =>
Effect.sync(() => {
current = String(value);
return { configOptions: [...optionsFor(current)] };
}),
}),
);
expect(probed?.thoughtLevels["gemini-4-neon"]?.options.map((o) => o.value)).toEqual([
"low",
"high",
]);
expect(probed?.thoughtLevels["gpt-oss-120b-medium"]).toBeNull();
});

it("falls back to folding names when the agent names the level in the model", () => {
const next = nextAntigravityCatalog(undefined, configOptions);
expect(next?.thoughtLevels).toBeUndefined();
Expand Down
Loading
Loading