refactor(server): the legacy featureValues folds take one named-input object

This commit is contained in:
Mohamed Boudra
2026-11-01 15:34:06 +01:00
parent 3a3300b69e
commit fd2315495f
3 changed files with 15 additions and 10 deletions
@@ -1377,7 +1377,10 @@ export class AgentManager {
});
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01. A plugin written
// against the previous SDK edits `config.featureValues`.
config = { ...foldHookFeatureValues(request.config, sent), internal: config.internal };
config = {
...foldHookFeatureValues({ returned: request.config, sent }),
internal: config.internal,
};
options = { ...options, env: request.env };
}
await this.deleteAgentState(resolvedAgentId);
@@ -67,7 +67,8 @@ export function exposeFeatureValuesToHook<
export function foldHookFeatureValues<
T extends { providerOptions?: ProviderOptions | null; featureValues?: Record<string, unknown> },
>(returned: T, sent: T): Omit<T, "featureValues"> {
>(input: { returned: T; sent: T }): Omit<T, "featureValues"> {
const { returned, sent } = input;
const { featureValues, ...rest } = returned;
const before = sent.featureValues;
if (!before) {
@@ -104,11 +105,12 @@ interface ProfileOptionFields {
* 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>(
profile: T,
stored: ProfileOptionFields | undefined,
source: "stored" | "client write" = "stored",
): Omit<T, "featureValues"> {
export function foldProfileFeatureValues<T extends ProfileOptionFields>(input: {
profile: T;
stored: ProfileOptionFields | undefined;
source: "stored" | "client write";
}): Omit<T, "featureValues"> {
const { profile, stored, source } = input;
const { featureValues, ...rest } = profile;
if (source === "stored") {
return featureValues ? { ...rest, options: { ...featureValues, ...rest.options } } : rest;
@@ -183,11 +183,11 @@ function foldConfigProfiles<T extends { agentProfiles?: AgentProfile[] }>(
return {
...config,
agentProfiles: config.agentProfiles.map((profile) =>
foldProfileFeatureValues(
foldProfileFeatureValues({
profile,
held.find((candidate) => candidate.id === profile.id),
stored: held.find((candidate) => candidate.id === profile.id),
source,
),
}),
),
};
}