Repository navigation
🤖 feat: add a resolver for workspace model, thinking and reasoning picks #5895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
ibetitsmike
wants to merge
3
commits into
mike/server-side-ai-backend
from
mike/server-side-ai-resolver
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
ef91658
feat: add a resolver for workspace model, thinking and reasoning picks
ibetitsmike a97db95
test: cover the unsent reasoning pick and a default model that loads …
ibetitsmike 86e280c
fix: resolve legacy workspace ids that start with __ as workspaces
ibetitsmike File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| import { afterEach, beforeEach, describe, expect, test } from "bun:test"; | ||
| import { act, cleanup, renderHook } from "@testing-library/react"; | ||
| import { GlobalWindow } from "happy-dom"; | ||
| import { restoreDomGlobals, saveDomGlobals } from "../../../tests/ui/domGlobals"; | ||
|
|
||
| import { updatePersistedState } from "@/browser/hooks/usePersistedState"; | ||
| import { getAppConfigStore } from "@/browser/stores/AppConfigStore"; | ||
| import { | ||
| markAiSelectionIntent, | ||
| resetAiSelectionIntentForTests, | ||
| setWorkspaceAiMetadata, | ||
| } from "@/browser/utils/aiSelectionIntent"; | ||
| import { | ||
| getWorkspaceAiSelection, | ||
| useWorkspaceAiSelection, | ||
| type WorkspaceAiSelection, | ||
| } from "@/browser/utils/workspaceAiSettingsSync"; | ||
| import { getProjectScopeId, getReasoningModeKey } from "@/common/constants/storage"; | ||
| import type { OpenAIReasoningMode, ThinkingLevel } from "@/common/types/thinking"; | ||
|
|
||
| const WS = "resolver-ws"; | ||
| const PROJECT = "/repo"; | ||
|
|
||
| type Tier = "pick" | "saved" | "legacy" | "configured" | "project"; | ||
|
|
||
| function seed(tiers: readonly Tier[]): void { | ||
| const has = (tier: Tier) => tiers.includes(tier); | ||
| getAppConfigStore().updateOptimistically({ | ||
| defaultModel: "openai:global", | ||
| agentAiDefaults: has("configured") | ||
| ? { exec: { modelString: "openai:configured", thinkingLevel: "high", reasoningMode: "pro" } } | ||
| : {}, | ||
| userPreferences: { | ||
| ai: { | ||
| globalDefaults: { thinkingLevel: "low" }, | ||
| projectDefaults: has("project") | ||
| ? { [PROJECT]: { model: "openai:project", thinkingLevel: "medium" } } | ||
| : undefined, | ||
| }, | ||
| }, | ||
| }); | ||
| setWorkspaceAiMetadata(WS, { | ||
| projectPath: PROJECT, | ||
| aiSettings: has("legacy") ? { model: "openai:legacy", thinkingLevel: "xhigh" } : undefined, | ||
| aiSettingsByAgent: has("saved") | ||
| ? { exec: { model: "openai:saved", thinkingLevel: "xhigh" } } | ||
| : undefined, | ||
| }); | ||
| if (has("pick")) { | ||
| markAiSelectionIntent(WS, "model", "openai:picked"); | ||
| markAiSelectionIntent(WS, "thinkingLevel", "max"); | ||
| markAiSelectionIntent(WS, "reasoningMode", "pro"); | ||
| } | ||
| } | ||
|
|
||
| describe("getWorkspaceAiSelection", () => { | ||
| beforeEach(() => { | ||
| saveDomGlobals(); | ||
| globalThis.window = new GlobalWindow() as unknown as Window & typeof globalThis; | ||
| globalThis.document = globalThis.window.document; | ||
| globalThis.localStorage = globalThis.window.localStorage; | ||
| resetAiSelectionIntentForTests(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| cleanup(); | ||
| resetAiSelectionIntentForTests(); | ||
| getAppConfigStore().updateOptimistically({ | ||
| defaultModel: undefined, | ||
| agentAiDefaults: undefined, | ||
| userPreferences: undefined, | ||
| }); | ||
| restoreDomGlobals(); | ||
| }); | ||
|
|
||
| test("each field falls through the unsent pick, saved settings, agent and project defaults", () => { | ||
| const cases: Array<{ | ||
| tiers: Tier[]; | ||
| model: string; | ||
| thinkingLevel: ThinkingLevel; | ||
| reasoning: OpenAIReasoningMode; | ||
| }> = [ | ||
| { | ||
| tiers: ["pick", "saved", "legacy", "configured", "project"], | ||
| model: "openai:picked", | ||
| thinkingLevel: "max", | ||
| reasoning: "pro", | ||
| }, | ||
| { | ||
| tiers: ["saved", "legacy", "configured", "project"], | ||
| model: "openai:saved", | ||
| thinkingLevel: "xhigh", | ||
| // A saved bucket owns reasoning: its absent mode means standard. | ||
| reasoning: "standard", | ||
| }, | ||
| { | ||
| tiers: ["legacy", "configured", "project"], | ||
| model: "openai:legacy", | ||
| thinkingLevel: "xhigh", | ||
| reasoning: "standard", | ||
| }, | ||
| { | ||
| tiers: ["configured", "project"], | ||
| model: "openai:configured", | ||
| thinkingLevel: "high", | ||
| reasoning: "pro", | ||
| }, | ||
| { | ||
| tiers: ["project"], | ||
| model: "openai:project", | ||
| thinkingLevel: "medium", | ||
| reasoning: "standard", | ||
| }, | ||
| { tiers: [], model: "openai:global", thinkingLevel: "low", reasoning: "standard" }, | ||
| ]; | ||
|
|
||
| for (const testCase of cases) { | ||
| resetAiSelectionIntentForTests(); | ||
| seed(testCase.tiers); | ||
| expect({ tiers: testCase.tiers, ...getWorkspaceAiSelection(WS, "exec") }).toEqual({ | ||
| tiers: testCase.tiers, | ||
| model: testCase.model, | ||
| thinkingLevel: testCase.thinkingLevel, | ||
| reasoningMode: testCase.reasoning, | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| test("the hook follows a default model that loads after it rendered", () => { | ||
| setWorkspaceAiMetadata(WS, { | ||
| projectPath: PROJECT, | ||
| aiSettings: undefined, | ||
| aiSettingsByAgent: undefined, | ||
| }); | ||
| const { result } = renderHook(() => useWorkspaceAiSelection(WS, "exec")); | ||
|
|
||
| act(() => getAppConfigStore().updateOptimistically({ defaultModel: "openai:loaded-later" })); | ||
|
|
||
| expect(result.current.model).toBe("openai:loaded-later"); | ||
| }); | ||
|
|
||
| test("a legacy workspace id that starts with __ resolves its saved settings", () => { | ||
| const legacyId = "__proj-main"; | ||
| setWorkspaceAiMetadata(legacyId, { | ||
| projectPath: PROJECT, | ||
| aiSettings: undefined, | ||
| aiSettingsByAgent: { exec: { model: "openai:saved", thinkingLevel: "high" } }, | ||
| }); | ||
|
|
||
| const { result } = renderHook(() => useWorkspaceAiSelection(legacyId, "exec")); | ||
| expect(result.current.model).toBe("openai:saved"); | ||
| expect(getWorkspaceAiSelection(legacyId, "exec").model).toBe("openai:saved"); | ||
| }); | ||
|
|
||
| test("a creation scope resolves its own defaults in the hook and the plain reader", () => { | ||
| const scopeId = getProjectScopeId(PROJECT); | ||
| // Workspace resolution would apply the configured Exec model here instead. | ||
| getAppConfigStore().updateOptimistically({ | ||
| defaultModel: "openai:global", | ||
| agentAiDefaults: { exec: { modelString: "openai:configured" } }, | ||
| userPreferences: { | ||
| ai: { | ||
| projectDefaults: { [PROJECT]: { model: "openai:project", thinkingLevel: "medium" } }, | ||
| }, | ||
| }, | ||
| }); | ||
| updatePersistedState(getReasoningModeKey(scopeId), "pro"); | ||
|
|
||
| const expected: WorkspaceAiSelection = { | ||
| model: "openai:project", | ||
| thinkingLevel: "medium", | ||
| reasoningMode: "pro", | ||
| }; | ||
| const { result } = renderHook(() => useWorkspaceAiSelection(scopeId)); | ||
| expect(result.current).toEqual(expected); | ||
| expect(getWorkspaceAiSelection(scopeId)).toEqual(expected); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.