Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.

Commit 5a95631

Browse files
refactor(core): extract composer model policy
Generated-By: PostHog Code Task-Id: c1bbe3cf-742b-4b24-bf96-d11a18b4cf22
1 parent 602324f commit 5a95631

2 files changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {
2+
type Adapter,
3+
type CloudTaskConfigOption,
4+
DEFAULT_GATEWAY_MODEL,
5+
restrictedModelMeta,
6+
type SupportedReasoningEffort,
7+
} from "@posthog/shared";
8+
import { expect, it } from "vitest";
9+
import { resolveCloudComposerModelChange } from "./composerModelPolicy";
10+
11+
const modelOption: CloudTaskConfigOption = {
12+
id: "model",
13+
name: "Model",
14+
type: "select",
15+
currentValue: DEFAULT_GATEWAY_MODEL,
16+
options: [
17+
{ value: DEFAULT_GATEWAY_MODEL, name: "Claude" },
18+
{ value: "restricted", name: "Restricted", _meta: restrictedModelMeta() },
19+
{ value: "gpt-5.3-codex", name: "Codex" },
20+
],
21+
category: "model",
22+
description: "Choose a model",
23+
};
24+
25+
it.each([
26+
["claude", DEFAULT_GATEWAY_MODEL, "high", DEFAULT_GATEWAY_MODEL, "high"],
27+
["claude", "restricted", "high", DEFAULT_GATEWAY_MODEL, "high"],
28+
["claude", "missing", "high", DEFAULT_GATEWAY_MODEL, "high"],
29+
["codex", "gpt-5.3-codex", "xhigh", "gpt-5.3-codex", "high"],
30+
] as const)(
31+
"resolves %s model %s with %s reasoning",
32+
(adapter, requestedModel, reasoning, expectedModel, expectedReasoning) => {
33+
expect(
34+
resolveCloudComposerModelChange({
35+
adapter: adapter as Adapter,
36+
modelOption,
37+
requestedModel,
38+
reasoning: reasoning as SupportedReasoningEffort,
39+
}),
40+
).toEqual({ model: expectedModel, reasoning: expectedReasoning });
41+
},
42+
);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import {
2+
type Adapter,
3+
type CloudTaskConfigOption,
4+
DEFAULT_REASONING_EFFORT,
5+
isRestrictedModelOption,
6+
isSupportedReasoningEffort,
7+
type SupportedReasoningEffort,
8+
} from "@posthog/shared";
9+
10+
export function resolveCloudComposerModelChange({
11+
adapter,
12+
modelOption,
13+
requestedModel,
14+
reasoning,
15+
}: {
16+
adapter: Adapter;
17+
modelOption: CloudTaskConfigOption;
18+
requestedModel: string;
19+
reasoning: SupportedReasoningEffort;
20+
}): { model: string; reasoning: SupportedReasoningEffort } {
21+
const selected = modelOption.options.find(
22+
(option) => option.value === requestedModel,
23+
);
24+
const model =
25+
selected && !isRestrictedModelOption(selected._meta)
26+
? requestedModel
27+
: modelOption.currentValue;
28+
29+
return {
30+
model,
31+
reasoning: isSupportedReasoningEffort(adapter, model, reasoning)
32+
? reasoning
33+
: DEFAULT_REASONING_EFFORT,
34+
};
35+
}

0 commit comments

Comments
 (0)