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

Commit cd0509a

Browse files
authored
fix(models): include Kimi in preview picker (#3883)
1 parent 5dd41ee commit cd0509a

2 files changed

Lines changed: 49 additions & 5 deletions

File tree

packages/workspace-server/src/services/agent/agent.test.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,15 @@ vi.mock("@posthog/agent/gateway-models", () => ({
125125
DEFAULT_GATEWAY_MODEL: "claude-opus-4-8",
126126
DEFAULT_CODEX_MODEL: "gpt-5.5",
127127
fetchGatewayModels: vi.fn().mockResolvedValue([]),
128-
formatGatewayModelName: vi.fn(),
128+
formatGatewayModelName: vi.fn((model) => model.id),
129+
getClaudeModelRecency: vi.fn(() => 0),
129130
getProviderName: vi.fn(),
131+
isAnthropicModel: vi.fn((model) => model.owned_by === "anthropic"),
130132
isBlockedModelId: vi.fn().mockReturnValue(false),
133+
isCloudflareModel: vi.fn((model) => model.owned_by === "cloudflare"),
134+
isModalModel: vi.fn((model) => model.owned_by === "modal"),
135+
isOpenAIModel: vi.fn((model) => model.owned_by === "openai"),
136+
pickAllowedModel: vi.fn((_models, preferredModelId) => preferredModelId),
131137
}));
132138

133139
vi.mock("@posthog/agent/adapters/claude/session/jsonl-hydration", () => ({
@@ -151,6 +157,7 @@ vi.mock("node:fs", async (importOriginal) => {
151157
});
152158

153159
// --- Import after mocks ---
160+
import { fetchGatewayModels } from "@posthog/agent/gateway-models";
154161
import type { RegisteredFolder } from "../folders/schemas";
155162
import {
156163
AgentService,
@@ -183,6 +190,7 @@ function createMockDependencies() {
183190
},
184191
agentAuthAdapter: {
185192
getCurrentCredentials: vi.fn().mockResolvedValue(null),
193+
gatewayAuthToken: vi.fn().mockResolvedValue("gateway-token"),
186194
ensureGatewayProxy: vi.fn().mockResolvedValue("http://127.0.0.1:9999"),
187195
configureProcessEnv: vi.fn().mockResolvedValue(undefined),
188196
createPosthogConfig: vi.fn((credentials) => ({
@@ -296,6 +304,40 @@ describe("AgentService", () => {
296304
vi.unstubAllGlobals();
297305
});
298306

307+
it("includes Modal models in Claude preview options", async () => {
308+
vi.mocked(fetchGatewayModels).mockResolvedValueOnce([
309+
{
310+
id: "claude-opus-4-8",
311+
owned_by: "anthropic",
312+
context_window: 1_000_000,
313+
supports_streaming: true,
314+
supports_vision: true,
315+
allowed: true,
316+
},
317+
{
318+
id: "moonshotai/kimi-k3",
319+
owned_by: "modal",
320+
context_window: 262_144,
321+
supports_streaming: true,
322+
supports_vision: false,
323+
allowed: true,
324+
},
325+
]);
326+
327+
const options = await service.getPreviewConfigOptions(
328+
"https://us.posthog.com",
329+
"claude",
330+
);
331+
332+
const modelOption = options.find((option) => option.id === "model");
333+
expect(modelOption).toMatchObject({
334+
type: "select",
335+
options: expect.arrayContaining([
336+
expect.objectContaining({ value: "moonshotai/kimi-k3" }),
337+
]),
338+
});
339+
});
340+
299341
describe("mcp-apps config resolver", () => {
300342
function registeredResolver(): (serverName: string) => Promise<void> {
301343
const call = deps.mcpAppsService.setConfigResolver.mock.calls[0];

packages/workspace-server/src/services/agent/agent.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
getProviderName,
3737
isAnthropicModel,
3838
isCloudflareModel,
39+
isModalModel,
3940
isOpenAIModel,
4041
pickAllowedModel,
4142
} from "@posthog/agent/gateway-models";
@@ -2402,14 +2403,15 @@ For git operations while detached:
24022403
authToken: (await this.agentAuthAdapter.gatewayAuthToken()) ?? undefined,
24032404
});
24042405

2405-
// The Claude adapter can also drive Cloudflare `@cf/` models the gateway serves over its
2406-
// Anthropic-Messages surface, so the preview/default-model path must offer them too — otherwise an
2407-
// advertised `@cf/*` model is dropped here and the pre-session run falls back to Opus.
2406+
// The Claude adapter can drive non-Anthropic models that the gateway exposes through its
2407+
// Anthropic-Messages surface, so preview filtering must match the session adapter.
24082408
const modelFilter =
24092409
adapter === "codex"
24102410
? isOpenAIModel
24112411
: (model: GatewayModel) =>
2412-
isAnthropicModel(model) || isCloudflareModel(model);
2412+
isAnthropicModel(model) ||
2413+
isCloudflareModel(model) ||
2414+
isModalModel(model);
24132415

24142416
const adapterModels = gatewayModels.filter((model) => modelFilter(model));
24152417
const modelOptions = adapterModels.map((model) => ({

0 commit comments

Comments
 (0)