GeezerVison is showing github.com — fix(clients): honor project default models in new threads (#6011) · incognitojam/styal@8e9c647
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/NewTaskDraftScreen.tsx +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -897,6 +897,7 @@ export function NewTaskDraftScreen(props: { | 897 | 897 | flow.finishEditingPendingTask(); | 898 | 898 | } else { | 899 | 899 | clearComposerDraftContent(draftKey, { | | 900 | + clearModelSelection: true, | 900 | 901 | clearWorkspaceSelection: true, | 901 | 902 | deferAttachmentCleanup: true, | 902 | 903 | }); | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/new-task-flow-provider.tsx +27-11Lines changed: 27 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -33,6 +33,7 @@ import { | 33 | 33 | buildModelOptions, | 34 | 34 | groupByProvider, | 35 | 35 | resolveDefaultableModelSelection, | | 36 | + resolveNewTaskModelSelection, | 36 | 37 | resolveSelectableModelSelection, | 37 | 38 | } from "../../lib/modelOptions"; | 38 | 39 | import { scopedProjectKey } from "../../lib/scopedEntities"; | @@ -49,8 +50,10 @@ import { | 49 | 50 | replaceComposerDraftAttachments, | 50 | 51 | scheduleUnusedComposerAttachmentCleanup, | 51 | 52 | setComposerDraftText, | | 53 | + setStickyComposerModelSelection, | 52 | 54 | updateComposerDraftSettings, | 53 | 55 | useComposerDraft, | | 56 | + useStickyComposerModelSelection, | 54 | 57 | } from "../../state/use-composer-drafts"; | 55 | 58 | import { | 56 | 59 | capturePendingTaskEditorWriteBaseline, | @@ -430,21 +433,33 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) { | 430 | 433 | selectedEnvironmentServerConfig, | 431 | 434 | selectedProject?.defaultModelSelection ?? null, | 432 | 435 | ); | | 436 | + const storedStickyModelSelection = useStickyComposerModelSelection(); | | 437 | + const stickyModelSelection = resolveDefaultableModelSelection( | | 438 | + selectedEnvironmentServerConfig, | | 439 | + storedStickyModelSelection, | | 440 | + ); | 433 | 441 | const modelOptions = useMemo( | 434 | 442 | () => | 435 | 443 | buildModelOptions( | 436 | 444 | selectedEnvironmentServerConfig, | 437 | | - draftModelSelection ?? projectDefaultModelSelection, | | 445 | + draftModelSelection ?? projectDefaultModelSelection ?? stickyModelSelection, | 438 | 446 | ), | 439 | | - [selectedEnvironmentServerConfig, draftModelSelection, projectDefaultModelSelection], | | 447 | + [ | | 448 | + selectedEnvironmentServerConfig, | | 449 | + draftModelSelection, | | 450 | + projectDefaultModelSelection, | | 451 | + stickyModelSelection, | | 452 | + ], | 440 | 453 | ); | 441 | 454 |
| 442 | | - const selectedModel = | 443 | | - draftModelSelection ?? | 444 | | - projectDefaultModelSelection ?? | 445 | | - modelOptions.find((option) => option.isDefault)?.selection ?? | 446 | | - modelOptions[0]?.selection ?? | 447 | | - null; | | 455 | + // An unsent draft keeps its explicit pick. Fresh drafts resolve the project | | 456 | + // default before the last manual app-wide selection and provider default. | | 457 | + const selectedModel = resolveNewTaskModelSelection({ | | 458 | + draftSelection: draftModelSelection, | | 459 | + projectDefaultSelection: projectDefaultModelSelection, | | 460 | + stickySelection: stickyModelSelection, | | 461 | + modelOptions, | | 462 | + }); | 448 | 463 | const selectedModelKey = selectedModel | 449 | 464 | ? `${selectedModel.instanceId}:${selectedModel.model}` | 450 | 465 | : null; | @@ -474,9 +489,9 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) { | 474 | 489 | if (!option) { | 475 | 490 | return; | 476 | 491 | } | 477 | | - updateComposerDraftSettings(selectedProjectDraftKey, { | 478 | | - modelSelection: options ? { ...option.selection, options } : option.selection, | 479 | | - }); | | 492 | + const selection = options ? { ...option.selection, options } : option.selection; | | 493 | + updateComposerDraftSettings(selectedProjectDraftKey, { modelSelection: selection }); | | 494 | + setStickyComposerModelSelection(selection); | 480 | 495 | }, | 481 | 496 | [modelOptions, selectedProjectDraftKey], | 482 | 497 | ); | @@ -494,6 +509,7 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) { | 494 | 509 | updateComposerDraftSettings(selectedProjectDraftKey, { | 495 | 510 | modelSelection: nextSelection, | 496 | 511 | }); | | 512 | + setStickyComposerModelSelection(nextSelection); | 497 | 513 | }, | 498 | 514 | [selectedModel, selectedProjectDraftKey], | 499 | 515 | ); | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/lib/modelOptions.test.ts +29-1Lines changed: 29 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { describe, expect, it } from "vite-plus/test"; | 2 | 2 |
| 3 | | -import { ProviderInstanceId, type ServerConfig } from "@t3tools/contracts"; | | 3 | +import { ProviderInstanceId, type ModelSelection, type ServerConfig } from "@t3tools/contracts"; | 4 | 4 |
| 5 | 5 | import { | 6 | 6 | buildModelOptions, | 7 | 7 | groupByProvider, | 8 | 8 | resolveDefaultableModelSelection, | | 9 | + resolveNewTaskModelSelection, | 9 | 10 | resolveSelectableModelSelection, | | 11 | + type ModelOption, | 10 | 12 | } from "./modelOptions"; | 11 | 13 |
| 12 | 14 | describe("mobile model options", () => { | @@ -220,4 +222,30 @@ describe("mobile model options", () => { | 220 | 222 | // Offline: nothing to validate against, selection passes through. | 221 | 223 | expect(resolveDefaultableModelSelection(null, legacy)).toBe(legacy); | 222 | 224 | }); | | 225 | + | | 226 | + it("resolves new tasks from draft, project, sticky, then provider defaults", () => { | | 227 | + const draft = { instanceId: ProviderInstanceId.make("codex"), model: "draft" }; | | 228 | + const project = { instanceId: ProviderInstanceId.make("codex"), model: "project" }; | | 229 | + const sticky = { instanceId: ProviderInstanceId.make("codex"), model: "sticky" }; | | 230 | + const providerDefault = { | | 231 | + selection: { instanceId: ProviderInstanceId.make("codex"), model: "default" }, | | 232 | + isDefault: true, | | 233 | + } as ModelOption; | | 234 | + const resolve = ( | | 235 | + draftSelection: ModelSelection | null, | | 236 | + projectDefaultSelection: ModelSelection | null, | | 237 | + stickySelection: ModelSelection | null, | | 238 | + ) => | | 239 | + resolveNewTaskModelSelection({ | | 240 | + draftSelection, | | 241 | + projectDefaultSelection, | | 242 | + stickySelection, | | 243 | + modelOptions: [providerDefault], | | 244 | + }); | | 245 | + | | 246 | + expect(resolve(draft, project, sticky)).toBe(draft); | | 247 | + expect(resolve(null, project, sticky)).toBe(project); | | 248 | + expect(resolve(null, null, sticky)).toBe(sticky); | | 249 | + expect(resolve(null, null, null)).toBe(providerDefault.selection); | | 250 | + }); | 223 | 251 | }); |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/lib/modelOptions.ts +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -104,6 +104,22 @@ export function resolveDefaultableModelSelection( | 104 | 104 | return model?.isLegacy === true ? null : usable; | 105 | 105 | } | 106 | 106 |
| | 107 | +export function resolveNewTaskModelSelection(input: { | | 108 | + readonly draftSelection: ModelSelection | null; | | 109 | + readonly projectDefaultSelection: ModelSelection | null; | | 110 | + readonly stickySelection: ModelSelection | null; | | 111 | + readonly modelOptions: ReadonlyArray<ModelOption>; | | 112 | +}): ModelSelection | null { | | 113 | + return ( | | 114 | + input.draftSelection ?? | | 115 | + input.projectDefaultSelection ?? | | 116 | + input.stickySelection ?? | | 117 | + input.modelOptions.find((option) => option.isDefault)?.selection ?? | | 118 | + input.modelOptions[0]?.selection ?? | | 119 | + null | | 120 | + ); | | 121 | +} | | 122 | + | 107 | 123 | export function buildModelOptions( | 108 | 124 | config: T3ServerConfig | null | undefined, | 109 | 125 | fallbackModelSelection: ModelSelection | null, | |
|