Skip to content

Commit e0f5c02

Browse files
committed
fix: deduplicate toProviderModelOptions and store SQL NULL for absent model options
- Extract toProviderModelOptions into @t3tools/shared/model to eliminate duplicate definitions in ChatView.tsx and ProviderCommandReactor.ts - Fix ProjectionProjects.ts and ProjectionThreads.ts to store SQL NULL instead of JSON string "null" when model options are absent
1 parent 340634e commit e0f5c02

File tree

5 files changed

+17
-23
lines changed

5 files changed

+17
-23
lines changed

apps/server/src/orchestration/Layers/ProviderCommandReactor.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
} from "@t3tools/contracts";
1717
import { Cache, Cause, Duration, Effect, Layer, Option, Schema, Stream } from "effect";
1818
import { makeDrainableWorker } from "@t3tools/shared/DrainableWorker";
19+
import { toProviderModelOptions } from "@t3tools/shared/model";
1920

2021
import { resolveThreadWorkspaceCwd } from "../../checkpointing/Utils.ts";
2122
import { GitCore } from "../../git/Services/GitCore.ts";
@@ -81,17 +82,6 @@ const sameModelOptions = (
8182
right: ProviderModelOptions | undefined,
8283
): boolean => JSON.stringify(left ?? null) === JSON.stringify(right ?? null);
8384

84-
function toProviderModelOptions(
85-
modelSelection: ModelSelection | undefined,
86-
): ProviderModelOptions | undefined {
87-
if (!modelSelection?.options) {
88-
return undefined;
89-
}
90-
return modelSelection.provider === "codex"
91-
? { codex: modelSelection.options }
92-
: { claudeAgent: modelSelection.options };
93-
}
94-
9585
function isUnknownPendingApprovalRequestError(cause: Cause.Cause<ProviderServiceError>): boolean {
9686
const error = Cause.squash(cause);
9787
if (Schema.is(ProviderAdapterRequestError)(error)) {

apps/server/src/persistence/Layers/ProjectionProjects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const makeProjectionProjectRepository = Effect.gen(function* () {
7777
${row.workspaceRoot},
7878
${row.defaultModelSelection?.provider ?? null},
7979
${row.defaultModelSelection?.model ?? null},
80-
${JSON.stringify(row.defaultModelSelection?.options ?? null)},
80+
${row.defaultModelSelection?.options != null ? JSON.stringify(row.defaultModelSelection.options) : null},
8181
${JSON.stringify(row.scripts)},
8282
${row.createdAt},
8383
${row.updatedAt},

apps/server/src/persistence/Layers/ProjectionThreads.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const makeProjectionThreadRepository = Effect.gen(function* () {
8989
${row.title},
9090
${row.modelSelection.provider},
9191
${row.modelSelection.model},
92-
${JSON.stringify(row.modelSelection.options ?? null)},
92+
${row.modelSelection.options != null ? JSON.stringify(row.modelSelection.options) : null},
9393
${row.runtimeMode},
9494
${row.interactionMode},
9595
${row.branch},

apps/web/src/components/ChatView.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
getDefaultModel,
2929
normalizeModelSlug,
3030
resolveModelSlugForProvider,
31+
toProviderModelOptions,
3132
} from "@t3tools/shared/model";
3233
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
3334
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
@@ -211,16 +212,6 @@ function extractModelSelectionOptions(
211212
return provider === "codex" ? modelOptions?.codex : modelOptions?.claudeAgent;
212213
}
213214

214-
function toProviderModelOptions(
215-
modelSelection: ModelSelection | null | undefined,
216-
): ProviderModelOptions | undefined {
217-
if (!modelSelection?.options) {
218-
return undefined;
219-
}
220-
return modelSelection.provider === "codex"
221-
? { codex: modelSelection.options }
222-
: { claudeAgent: modelSelection.options };
223-
}
224215
const COMPOSER_PATH_QUERY_DEBOUNCE_MS = 120;
225216
const SCRIPT_TERMINAL_COLS = 120;
226217
const SCRIPT_TERMINAL_ROWS = 30;

packages/shared/src/model.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import {
1010
type ClaudeCodeEffort,
1111
type CodexModelOptions,
1212
type CodexReasoningEffort,
13+
type ModelSelection,
1314
type ModelSlug,
15+
type ProviderModelOptions,
1416
type ProviderReasoningEffort,
1517
type ProviderKind,
1618
} from "@t3tools/contracts";
@@ -266,4 +268,15 @@ export function applyClaudePromptEffortPrefix(
266268
return `Ultrathink:\n${trimmed}`;
267269
}
268270

271+
export function toProviderModelOptions(
272+
modelSelection: ModelSelection | null | undefined,
273+
): ProviderModelOptions | undefined {
274+
if (!modelSelection?.options) {
275+
return undefined;
276+
}
277+
return modelSelection.provider === "codex"
278+
? { codex: modelSelection.options }
279+
: { claudeAgent: modelSelection.options };
280+
}
281+
269282
export { CLAUDE_CODE_EFFORT_OPTIONS, CODEX_REASONING_EFFORT_OPTIONS };

0 commit comments

Comments
 (0)