Unify provider model selection across orchestration and UI
- Replace provider-specific model options with typed modelSelection - Persist and replay selected provider, model, and options end to end - Update adapter, service, and chat composer tests for the new shape
This commit is contained in:
1 parent
97ff0ac4a9
commit
96d6160ea5
16 files changed
+287
-320
No files matched your search
@@ -313,7 +313,10 @@ describe("ProviderCommandReactor", () => {
|
||||
expect(harness.startSession.mock.calls[0]?.[0]).toEqual(ThreadId.makeUnsafe("thread-1"));
|
||||
expect(harness.startSession.mock.calls[0]?.[1]).toMatchObject({
|
||||
cwd: "/tmp/provider-project",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
runtimeMode: "approval-required",
|
||||
});
|
||||
|
||||
@@ -355,9 +358,10 @@ describe("ProviderCommandReactor", () => {
|
||||
await waitFor(() => harness.startSession.mock.calls.length === 1);
|
||||
await waitFor(() => harness.sendTurn.mock.calls.length === 1);
|
||||
expect(harness.startSession.mock.calls[0]?.[1]).toMatchObject({
|
||||
model: "gpt-5.3-codex",
|
||||
modelOptions: {
|
||||
codex: {
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
options: {
|
||||
reasoningEffort: "high",
|
||||
fastMode: true,
|
||||
},
|
||||
@@ -365,9 +369,10 @@ describe("ProviderCommandReactor", () => {
|
||||
});
|
||||
expect(harness.sendTurn.mock.calls[0]?.[0]).toMatchObject({
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
model: "gpt-5.3-codex",
|
||||
modelOptions: {
|
||||
codex: {
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
options: {
|
||||
reasoningEffort: "high",
|
||||
fastMode: true,
|
||||
},
|
||||
@@ -406,19 +411,20 @@ describe("ProviderCommandReactor", () => {
|
||||
await waitFor(() => harness.startSession.mock.calls.length === 1);
|
||||
await waitFor(() => harness.sendTurn.mock.calls.length === 1);
|
||||
expect(harness.startSession.mock.calls[0]?.[1]).toMatchObject({
|
||||
provider: "claudeAgent",
|
||||
model: "claude-sonnet-4-6",
|
||||
modelOptions: {
|
||||
claudeAgent: {
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-sonnet-4-6",
|
||||
options: {
|
||||
effort: "max",
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(harness.sendTurn.mock.calls[0]?.[0]).toMatchObject({
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
model: "claude-sonnet-4-6",
|
||||
modelOptions: {
|
||||
claudeAgent: {
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-sonnet-4-6",
|
||||
options: {
|
||||
effort: "max",
|
||||
},
|
||||
},
|
||||
@@ -456,19 +462,20 @@ describe("ProviderCommandReactor", () => {
|
||||
await waitFor(() => harness.startSession.mock.calls.length === 1);
|
||||
await waitFor(() => harness.sendTurn.mock.calls.length === 1);
|
||||
expect(harness.startSession.mock.calls[0]?.[1]).toMatchObject({
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
modelOptions: {
|
||||
claudeAgent: {
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
options: {
|
||||
fastMode: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(harness.sendTurn.mock.calls[0]?.[0]).toMatchObject({
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
model: "claude-opus-4-6",
|
||||
modelOptions: {
|
||||
claudeAgent: {
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
options: {
|
||||
fastMode: true,
|
||||
},
|
||||
},
|
||||
@@ -594,12 +601,17 @@ describe("ProviderCommandReactor", () => {
|
||||
await waitFor(() => harness.sendTurn.mock.calls.length === 1);
|
||||
|
||||
expect(harness.startSession.mock.calls[0]?.[1]).toMatchObject({
|
||||
provider: "codex",
|
||||
model: "claude-sonnet-4-6",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "claude-sonnet-4-6",
|
||||
},
|
||||
});
|
||||
expect(harness.sendTurn.mock.calls[0]?.[0]).toMatchObject({
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
model: "claude-sonnet-4-6",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "claude-sonnet-4-6",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -707,10 +719,11 @@ describe("ProviderCommandReactor", () => {
|
||||
await waitFor(() => harness.startSession.mock.calls.length === 2);
|
||||
await waitFor(() => harness.sendTurn.mock.calls.length === 2);
|
||||
expect(harness.startSession.mock.calls[1]?.[1]).toMatchObject({
|
||||
provider: "claudeAgent",
|
||||
resumeCursor: { opaque: "resume-1" },
|
||||
modelOptions: {
|
||||
claudeAgent: {
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-sonnet-4-6",
|
||||
options: {
|
||||
effort: "max",
|
||||
},
|
||||
},
|
||||
@@ -841,11 +854,12 @@ describe("ProviderCommandReactor", () => {
|
||||
await waitFor(() => harness.startSession.mock.calls.length === 1);
|
||||
|
||||
expect(harness.startSession.mock.calls[0]?.[1]).toMatchObject({
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
},
|
||||
runtimeMode: "approval-required",
|
||||
});
|
||||
expect(harness.startSession.mock.calls[0]?.[1]).not.toHaveProperty("modelOptions");
|
||||
});
|
||||
|
||||
it("rejects provider changes after a thread is already bound to a session provider", async () => {
|
||||
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
EventId,
|
||||
type ModelSelection,
|
||||
type OrchestrationEvent,
|
||||
type ProviderModelOptions,
|
||||
ProviderKind,
|
||||
type ProviderStartOptions,
|
||||
type OrchestrationSession,
|
||||
@@ -16,7 +15,6 @@ import {
|
||||
} from "@t3tools/contracts";
|
||||
import { Cache, Cause, Duration, Effect, Layer, Option, Schema, Stream } from "effect";
|
||||
import { makeDrainableWorker } from "@t3tools/shared/DrainableWorker";
|
||||
import { toProviderModelOptions } from "@t3tools/shared/model";
|
||||
|
||||
import { resolveThreadWorkspaceCwd } from "../../checkpointing/Utils.ts";
|
||||
import { GitCore } from "../../git/Services/GitCore.ts";
|
||||
@@ -77,9 +75,9 @@ const DEFAULT_RUNTIME_MODE: RuntimeMode = "full-access";
|
||||
const WORKTREE_BRANCH_PREFIX = "t3code";
|
||||
const TEMP_WORKTREE_BRANCH_PATTERN = new RegExp(`^${WORKTREE_BRANCH_PREFIX}\\/[0-9a-f]{8}$`);
|
||||
|
||||
const sameModelOptions = (
|
||||
left: ProviderModelOptions | undefined,
|
||||
right: ProviderModelOptions | undefined,
|
||||
const sameModelSelectionOptions = (
|
||||
left: ModelSelection | undefined,
|
||||
right: ModelSelection | undefined,
|
||||
): boolean => JSON.stringify(left ?? null) === JSON.stringify(right ?? null);
|
||||
|
||||
function isUnknownPendingApprovalRequestError(cause: Cause.Cause<ProviderServiceError>): boolean {
|
||||
@@ -159,7 +157,7 @@ const make = Effect.gen(function* () {
|
||||
);
|
||||
|
||||
const threadProviderOptions = new Map<string, ProviderStartOptions>();
|
||||
const threadModelOptions = new Map<string, ProviderModelOptions>();
|
||||
const threadModelSelections = new Map<string, ModelSelection>();
|
||||
|
||||
const appendProviderFailureActivity = (input: {
|
||||
readonly threadId: ThreadId;
|
||||
@@ -217,7 +215,6 @@ const make = Effect.gen(function* () {
|
||||
createdAt: string,
|
||||
options?: {
|
||||
readonly modelSelection?: ModelSelection;
|
||||
readonly modelOptions?: ProviderModelOptions;
|
||||
readonly providerOptions?: ProviderStartOptions;
|
||||
},
|
||||
) {
|
||||
@@ -247,9 +244,6 @@ const make = Effect.gen(function* () {
|
||||
}
|
||||
const preferredProvider: ProviderKind = currentProvider ?? threadProvider;
|
||||
const desiredModelSelection = requestedModelSelection ?? thread.modelSelection;
|
||||
const desiredModel = desiredModelSelection.model;
|
||||
const desiredModelOptions =
|
||||
options?.modelOptions ?? toProviderModelOptions(desiredModelSelection);
|
||||
const effectiveCwd = resolveThreadWorkspaceCwd({
|
||||
thread,
|
||||
projects: readModel.projects,
|
||||
@@ -268,8 +262,7 @@ const make = Effect.gen(function* () {
|
||||
threadId,
|
||||
...(preferredProvider ? { provider: preferredProvider } : {}),
|
||||
...(effectiveCwd ? { cwd: effectiveCwd } : {}),
|
||||
...(desiredModel ? { model: desiredModel } : {}),
|
||||
...(desiredModelOptions !== undefined ? { modelOptions: desiredModelOptions } : {}),
|
||||
modelSelection: desiredModelSelection,
|
||||
...(options?.providerOptions !== undefined
|
||||
? { providerOptions: options.providerOptions }
|
||||
: {}),
|
||||
@@ -309,17 +302,17 @@ const make = Effect.gen(function* () {
|
||||
requestedModelSelection !== undefined &&
|
||||
requestedModelSelection.model !== activeSession?.model;
|
||||
const shouldRestartForModelChange = modelChanged && sessionModelSwitch === "restart-session";
|
||||
const previousModelOptions = threadModelOptions.get(threadId);
|
||||
const shouldRestartForModelOptionsChange =
|
||||
const previousModelSelection = threadModelSelections.get(threadId);
|
||||
const shouldRestartForModelSelectionChange =
|
||||
currentProvider === "claudeAgent" &&
|
||||
options?.modelOptions !== undefined &&
|
||||
!sameModelOptions(previousModelOptions, options.modelOptions);
|
||||
requestedModelSelection !== undefined &&
|
||||
!sameModelSelectionOptions(previousModelSelection, requestedModelSelection);
|
||||
|
||||
if (
|
||||
!runtimeModeChanged &&
|
||||
!providerChanged &&
|
||||
!shouldRestartForModelChange &&
|
||||
!shouldRestartForModelOptionsChange
|
||||
!shouldRestartForModelSelectionChange
|
||||
) {
|
||||
return existingSessionThreadId;
|
||||
}
|
||||
@@ -339,7 +332,7 @@ const make = Effect.gen(function* () {
|
||||
providerChanged,
|
||||
modelChanged,
|
||||
shouldRestartForModelChange,
|
||||
shouldRestartForModelOptionsChange,
|
||||
shouldRestartForModelSelectionChange,
|
||||
hasResumeCursor: resumeCursor !== undefined,
|
||||
});
|
||||
const restartedSession = yield* startProviderSession(
|
||||
@@ -366,7 +359,6 @@ const make = Effect.gen(function* () {
|
||||
readonly messageText: string;
|
||||
readonly attachments?: ReadonlyArray<ChatAttachment>;
|
||||
readonly modelSelection?: ModelSelection;
|
||||
readonly modelOptions?: ProviderModelOptions;
|
||||
readonly providerOptions?: ProviderStartOptions;
|
||||
readonly interactionMode?: "default" | "plan";
|
||||
readonly createdAt: string;
|
||||
@@ -377,14 +369,13 @@ const make = Effect.gen(function* () {
|
||||
}
|
||||
yield* ensureSessionForThread(input.threadId, input.createdAt, {
|
||||
...(input.modelSelection !== undefined ? { modelSelection: input.modelSelection } : {}),
|
||||
...(input.modelOptions !== undefined ? { modelOptions: input.modelOptions } : {}),
|
||||
...(input.providerOptions !== undefined ? { providerOptions: input.providerOptions } : {}),
|
||||
});
|
||||
if (input.providerOptions !== undefined) {
|
||||
threadProviderOptions.set(input.threadId, input.providerOptions);
|
||||
}
|
||||
if (input.modelOptions !== undefined) {
|
||||
threadModelOptions.set(input.threadId, input.modelOptions);
|
||||
if (input.modelSelection !== undefined) {
|
||||
threadModelSelections.set(input.threadId, input.modelSelection);
|
||||
}
|
||||
const normalizedInput = toNonEmptyProviderInput(input.messageText);
|
||||
const normalizedAttachments = input.attachments ?? [];
|
||||
@@ -398,14 +389,20 @@ const make = Effect.gen(function* () {
|
||||
? "in-session"
|
||||
: (yield* providerService.getCapabilities(activeSession.provider)).sessionModelSwitch;
|
||||
const modelForTurn =
|
||||
sessionModelSwitch === "unsupported" ? activeSession?.model : input.modelSelection?.model;
|
||||
sessionModelSwitch === "unsupported"
|
||||
? input.modelSelection
|
||||
? {
|
||||
...input.modelSelection,
|
||||
model: activeSession?.model ?? input.modelSelection.model,
|
||||
}
|
||||
: undefined
|
||||
: input.modelSelection;
|
||||
|
||||
yield* providerService.sendTurn({
|
||||
threadId: input.threadId,
|
||||
...(normalizedInput ? { input: normalizedInput } : {}),
|
||||
...(normalizedAttachments.length > 0 ? { attachments: normalizedAttachments } : {}),
|
||||
...(modelForTurn !== undefined ? { model: modelForTurn } : {}),
|
||||
...(input.modelOptions !== undefined ? { modelOptions: input.modelOptions } : {}),
|
||||
...(modelForTurn !== undefined ? { modelSelection: modelForTurn } : {}),
|
||||
...(input.interactionMode !== undefined ? { interactionMode: input.interactionMode } : {}),
|
||||
});
|
||||
});
|
||||
@@ -514,10 +511,6 @@ const make = Effect.gen(function* () {
|
||||
...(message.attachments !== undefined ? { attachments: message.attachments } : {}),
|
||||
}).pipe(Effect.forkScoped);
|
||||
|
||||
const requestedModelOptions = event.payload.modelSelection
|
||||
? toProviderModelOptions(event.payload.modelSelection)
|
||||
: undefined;
|
||||
|
||||
yield* sendTurnForThread({
|
||||
threadId: event.payload.threadId,
|
||||
messageText: message.text,
|
||||
@@ -525,7 +518,6 @@ const make = Effect.gen(function* () {
|
||||
...(event.payload.modelSelection !== undefined
|
||||
? { modelSelection: event.payload.modelSelection }
|
||||
: {}),
|
||||
...(requestedModelOptions !== undefined ? { modelOptions: requestedModelOptions } : {}),
|
||||
...(event.payload.providerOptions !== undefined
|
||||
? { providerOptions: event.payload.providerOptions }
|
||||
: {}),
|
||||
@@ -695,12 +687,12 @@ const make = Effect.gen(function* () {
|
||||
return;
|
||||
}
|
||||
const cachedProviderOptions = threadProviderOptions.get(event.payload.threadId);
|
||||
const cachedModelOptions = threadModelOptions.get(event.payload.threadId);
|
||||
const cachedModelSelection = threadModelSelections.get(event.payload.threadId);
|
||||
yield* ensureSessionForThread(event.payload.threadId, event.occurredAt, {
|
||||
...(cachedProviderOptions !== undefined
|
||||
? { providerOptions: cachedProviderOptions }
|
||||
: {}),
|
||||
...(cachedModelOptions !== undefined ? { modelOptions: cachedModelOptions } : {}),
|
||||
...(cachedModelSelection !== undefined ? { modelSelection: cachedModelSelection } : {}),
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -332,13 +332,14 @@ describe("ClaudeAdapterLive", () => {
|
||||
yield* adapter.startSession({
|
||||
threadId: THREAD_ID,
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
runtimeMode: "full-access",
|
||||
modelOptions: {
|
||||
claudeAgent: {
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
options: {
|
||||
effort: "max",
|
||||
},
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
|
||||
const createInput = harness.getLastCreateQueryInput();
|
||||
@@ -356,13 +357,14 @@ describe("ClaudeAdapterLive", () => {
|
||||
yield* adapter.startSession({
|
||||
threadId: THREAD_ID,
|
||||
provider: "claudeAgent",
|
||||
model: "claude-sonnet-4-6",
|
||||
runtimeMode: "full-access",
|
||||
modelOptions: {
|
||||
claudeAgent: {
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-sonnet-4-6",
|
||||
options: {
|
||||
effort: "max",
|
||||
},
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
|
||||
const createInput = harness.getLastCreateQueryInput();
|
||||
@@ -380,13 +382,14 @@ describe("ClaudeAdapterLive", () => {
|
||||
yield* adapter.startSession({
|
||||
threadId: THREAD_ID,
|
||||
provider: "claudeAgent",
|
||||
model: "claude-haiku-4-5",
|
||||
runtimeMode: "full-access",
|
||||
modelOptions: {
|
||||
claudeAgent: {
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-haiku-4-5",
|
||||
options: {
|
||||
effort: "high",
|
||||
},
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
|
||||
const createInput = harness.getLastCreateQueryInput();
|
||||
@@ -404,13 +407,14 @@ describe("ClaudeAdapterLive", () => {
|
||||
yield* adapter.startSession({
|
||||
threadId: THREAD_ID,
|
||||
provider: "claudeAgent",
|
||||
model: "claude-haiku-4-5",
|
||||
runtimeMode: "full-access",
|
||||
modelOptions: {
|
||||
claudeAgent: {
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-haiku-4-5",
|
||||
options: {
|
||||
thinking: false,
|
||||
},
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
|
||||
const createInput = harness.getLastCreateQueryInput();
|
||||
@@ -430,13 +434,14 @@ describe("ClaudeAdapterLive", () => {
|
||||
yield* adapter.startSession({
|
||||
threadId: THREAD_ID,
|
||||
provider: "claudeAgent",
|
||||
model: "claude-sonnet-4-6",
|
||||
runtimeMode: "full-access",
|
||||
modelOptions: {
|
||||
claudeAgent: {
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-sonnet-4-6",
|
||||
options: {
|
||||
thinking: false,
|
||||
},
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
|
||||
const createInput = harness.getLastCreateQueryInput();
|
||||
@@ -454,13 +459,14 @@ describe("ClaudeAdapterLive", () => {
|
||||
yield* adapter.startSession({
|
||||
threadId: THREAD_ID,
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
runtimeMode: "full-access",
|
||||
modelOptions: {
|
||||
claudeAgent: {
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
options: {
|
||||
fastMode: true,
|
||||
},
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
|
||||
const createInput = harness.getLastCreateQueryInput();
|
||||
@@ -480,13 +486,14 @@ describe("ClaudeAdapterLive", () => {
|
||||
yield* adapter.startSession({
|
||||
threadId: THREAD_ID,
|
||||
provider: "claudeAgent",
|
||||
model: "claude-sonnet-4-6",
|
||||
runtimeMode: "full-access",
|
||||
modelOptions: {
|
||||
claudeAgent: {
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-sonnet-4-6",
|
||||
options: {
|
||||
fastMode: true,
|
||||
},
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
|
||||
const createInput = harness.getLastCreateQueryInput();
|
||||
@@ -504,22 +511,24 @@ describe("ClaudeAdapterLive", () => {
|
||||
const session = yield* adapter.startSession({
|
||||
threadId: THREAD_ID,
|
||||
provider: "claudeAgent",
|
||||
model: "claude-sonnet-4-6",
|
||||
runtimeMode: "full-access",
|
||||
modelOptions: {
|
||||
claudeAgent: {
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-sonnet-4-6",
|
||||
options: {
|
||||
effort: "ultrathink",
|
||||
},
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
|
||||
yield* adapter.sendTurn({
|
||||
threadId: session.threadId,
|
||||
input: "Investigate the edge cases",
|
||||
attachments: [],
|
||||
model: "claude-sonnet-4-6",
|
||||
modelOptions: {
|
||||
claudeAgent: {
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-sonnet-4-6",
|
||||
options: {
|
||||
effort: "ultrathink",
|
||||
},
|
||||
},
|
||||
@@ -613,7 +622,10 @@ describe("ClaudeAdapterLive", () => {
|
||||
const session = yield* adapter.startSession({
|
||||
threadId: THREAD_ID,
|
||||
provider: "claudeAgent",
|
||||
model: "claude-sonnet-4-5",
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-sonnet-4-5",
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
|
||||
@@ -2239,7 +2251,10 @@ describe("ClaudeAdapterLive", () => {
|
||||
yield* adapter.sendTurn({
|
||||
threadId: session.threadId,
|
||||
input: "hello",
|
||||
model: "claude-opus-4-6",
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
},
|
||||
attachments: [],
|
||||
});
|
||||
|
||||
|
||||
@@ -436,11 +436,17 @@ const CLAUDE_SETTING_SOURCES = [
|
||||
function buildPromptText(input: ProviderSendTurnInput): string {
|
||||
const requestedEffort = resolveReasoningEffortForProvider(
|
||||
"claudeAgent",
|
||||
input.modelOptions?.claudeAgent?.effort ?? null,
|
||||
input.modelSelection?.provider === "claudeAgent" ? input.modelSelection.options?.effort : null,
|
||||
);
|
||||
const supportedEffortOptions = getReasoningEffortOptions(
|
||||
"claudeAgent",
|
||||
input.modelSelection?.provider === "claudeAgent" ? input.modelSelection.model : undefined,
|
||||
);
|
||||
const supportedEffortOptions = getReasoningEffortOptions("claudeAgent", input.model);
|
||||
const promptEffort =
|
||||
requestedEffort === "ultrathink" && supportsClaudeUltrathinkKeyword(input.model)
|
||||
requestedEffort === "ultrathink" &&
|
||||
supportsClaudeUltrathinkKeyword(
|
||||
input.modelSelection?.provider === "claudeAgent" ? input.modelSelection.model : undefined,
|
||||
)
|
||||
? "ultrathink"
|
||||
: requestedEffort && supportedEffortOptions.includes(requestedEffort)
|
||||
? requestedEffort
|
||||
@@ -2542,21 +2548,27 @@ function makeClaudeAdapter(options?: ClaudeAdapterLiveOptions) {
|
||||
);
|
||||
|
||||
const providerOptions = input.providerOptions?.claudeAgent;
|
||||
const modelSelection =
|
||||
input.modelSelection?.provider === "claudeAgent" ? input.modelSelection : undefined;
|
||||
const requestedEffort = resolveReasoningEffortForProvider(
|
||||
"claudeAgent",
|
||||
input.modelOptions?.claudeAgent?.effort ?? null,
|
||||
modelSelection?.options?.effort ?? null,
|
||||
);
|
||||
const supportedEffortOptions = getReasoningEffortOptions(
|
||||
"claudeAgent",
|
||||
modelSelection?.model,
|
||||
);
|
||||
const supportedEffortOptions = getReasoningEffortOptions("claudeAgent", input.model);
|
||||
const effort =
|
||||
requestedEffort && supportedEffortOptions.includes(requestedEffort)
|
||||
? requestedEffort
|
||||
: null;
|
||||
const fastMode =
|
||||
input.modelOptions?.claudeAgent?.fastMode === true && supportsClaudeFastMode(input.model);
|
||||
modelSelection?.options?.fastMode === true &&
|
||||
supportsClaudeFastMode(modelSelection?.model);
|
||||
const thinking =
|
||||
typeof input.modelOptions?.claudeAgent?.thinking === "boolean" &&
|
||||
supportsClaudeThinkingToggle(input.model)
|
||||
? input.modelOptions.claudeAgent.thinking
|
||||
typeof modelSelection?.options?.thinking === "boolean" &&
|
||||
supportsClaudeThinkingToggle(modelSelection?.model)
|
||||
? modelSelection.options.thinking
|
||||
: undefined;
|
||||
const effectiveEffort = getEffectiveClaudeCodeEffort(effort);
|
||||
const permissionMode =
|
||||
@@ -2569,7 +2581,7 @@ function makeClaudeAdapter(options?: ClaudeAdapterLiveOptions) {
|
||||
|
||||
const queryOptions: ClaudeQueryOptions = {
|
||||
...(input.cwd ? { cwd: input.cwd } : {}),
|
||||
...(input.model ? { model: input.model } : {}),
|
||||
...(modelSelection?.model ? { model: modelSelection.model } : {}),
|
||||
pathToClaudeCodeExecutable: providerOptions?.binaryPath ?? "claude",
|
||||
settingSources: [...CLAUDE_SETTING_SOURCES],
|
||||
...(effectiveEffort ? { effort: effectiveEffort } : {}),
|
||||
@@ -2610,7 +2622,7 @@ function makeClaudeAdapter(options?: ClaudeAdapterLiveOptions) {
|
||||
status: "ready",
|
||||
runtimeMode: input.runtimeMode,
|
||||
...(input.cwd ? { cwd: input.cwd } : {}),
|
||||
...(input.model ? { model: input.model } : {}),
|
||||
...(modelSelection?.model ? { model: modelSelection.model } : {}),
|
||||
...(threadId ? { threadId } : {}),
|
||||
resumeCursor: {
|
||||
...(threadId ? { threadId } : {}),
|
||||
@@ -2664,7 +2676,7 @@ function makeClaudeAdapter(options?: ClaudeAdapterLiveOptions) {
|
||||
threadId,
|
||||
payload: {
|
||||
config: {
|
||||
...(input.model ? { model: input.model } : {}),
|
||||
...(modelSelection?.model ? { model: modelSelection.model } : {}),
|
||||
...(input.cwd ? { cwd: input.cwd } : {}),
|
||||
...(effectiveEffort ? { effort: effectiveEffort } : {}),
|
||||
...(permissionMode ? { permissionMode } : {}),
|
||||
@@ -2710,6 +2722,8 @@ function makeClaudeAdapter(options?: ClaudeAdapterLiveOptions) {
|
||||
const sendTurn: ClaudeAdapterShape["sendTurn"] = (input) =>
|
||||
Effect.gen(function* () {
|
||||
const context = yield* requireSession(input.threadId);
|
||||
const modelSelection =
|
||||
input.modelSelection?.provider === "claudeAgent" ? input.modelSelection : undefined;
|
||||
|
||||
if (context.turnState) {
|
||||
// Auto-close a stale synthetic turn (from background agent responses
|
||||
@@ -2717,9 +2731,9 @@ function makeClaudeAdapter(options?: ClaudeAdapterLiveOptions) {
|
||||
yield* completeTurn(context, "completed");
|
||||
}
|
||||
|
||||
if (input.model) {
|
||||
if (modelSelection?.model) {
|
||||
yield* Effect.tryPromise({
|
||||
try: () => context.query.setModel(input.model),
|
||||
try: () => context.query.setModel(modelSelection.model),
|
||||
catch: (cause) => toRequestError(input.threadId, "turn/setModel", cause),
|
||||
});
|
||||
}
|
||||
@@ -2769,7 +2783,7 @@ function makeClaudeAdapter(options?: ClaudeAdapterLiveOptions) {
|
||||
createdAt: turnStartedStamp.createdAt,
|
||||
threadId: context.session.threadId,
|
||||
turnId,
|
||||
payload: input.model ? { model: input.model } : {},
|
||||
payload: modelSelection?.model ? { model: modelSelection.model } : {},
|
||||
providerRefs: {},
|
||||
});
|
||||
|
||||
|
||||
@@ -188,9 +188,10 @@ validationLayer("CodexAdapterLive validation", (it) => {
|
||||
yield* adapter.startSession({
|
||||
provider: "codex",
|
||||
threadId: asThreadId("thread-1"),
|
||||
model: "gpt-5.3-codex",
|
||||
modelOptions: {
|
||||
codex: {
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
options: {
|
||||
fastMode: true,
|
||||
},
|
||||
},
|
||||
@@ -256,9 +257,10 @@ sessionErrorLayer("CodexAdapterLive session errors", (it) => {
|
||||
adapter.sendTurn({
|
||||
threadId: asThreadId("sess-missing"),
|
||||
input: "hello",
|
||||
model: "gpt-5.3-codex",
|
||||
modelOptions: {
|
||||
codex: {
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
options: {
|
||||
reasoningEffort: "high",
|
||||
fastMode: true,
|
||||
},
|
||||
|
||||
@@ -1313,8 +1313,12 @@ const makeCodexAdapter = (options?: CodexAdapterLiveOptions) =>
|
||||
...(input.resumeCursor !== undefined ? { resumeCursor: input.resumeCursor } : {}),
|
||||
...(input.providerOptions !== undefined ? { providerOptions: input.providerOptions } : {}),
|
||||
runtimeMode: input.runtimeMode,
|
||||
...(input.model !== undefined ? { model: input.model } : {}),
|
||||
...(input.modelOptions?.codex?.fastMode ? { serviceTier: "fast" } : {}),
|
||||
...(input.modelSelection?.provider === "codex"
|
||||
? { model: input.modelSelection.model }
|
||||
: {}),
|
||||
...(input.modelSelection?.provider === "codex" && input.modelSelection.options?.fastMode
|
||||
? { serviceTier: "fast" }
|
||||
: {}),
|
||||
};
|
||||
|
||||
return Effect.tryPromise({
|
||||
@@ -1370,11 +1374,17 @@ const makeCodexAdapter = (options?: CodexAdapterLiveOptions) =>
|
||||
const managerInput = {
|
||||
threadId: input.threadId,
|
||||
...(input.input !== undefined ? { input: input.input } : {}),
|
||||
...(input.model !== undefined ? { model: input.model } : {}),
|
||||
...(input.modelOptions?.codex?.reasoningEffort !== undefined
|
||||
? { effort: input.modelOptions.codex.reasoningEffort }
|
||||
...(input.modelSelection?.provider === "codex"
|
||||
? { model: input.modelSelection.model }
|
||||
: {}),
|
||||
...(input.modelSelection?.provider === "codex" &&
|
||||
input.modelSelection.options?.reasoningEffort !== undefined
|
||||
? { effort: input.modelSelection.options.reasoningEffort }
|
||||
: {}),
|
||||
...(input.modelSelection?.provider === "codex" &&
|
||||
input.modelSelection.options?.fastMode
|
||||
? { serviceTier: "fast" }
|
||||
: {}),
|
||||
...(input.modelOptions?.codex?.fastMode ? { serviceTier: "fast" } : {}),
|
||||
...(input.interactionMode !== undefined
|
||||
? { interactionMode: input.interactionMode }
|
||||
: {}),
|
||||
|
||||
@@ -633,8 +633,10 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
provider: "claudeAgent",
|
||||
threadId: asThreadId("thread-claude-send-turn"),
|
||||
cwd: "/tmp/project-claude-send-turn",
|
||||
modelOptions: {
|
||||
claudeAgent: {
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
options: {
|
||||
effort: "max",
|
||||
},
|
||||
},
|
||||
@@ -658,14 +660,16 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
const startPayload = resumedStartInput as {
|
||||
provider?: string;
|
||||
cwd?: string;
|
||||
modelOptions?: unknown;
|
||||
modelSelection?: unknown;
|
||||
resumeCursor?: unknown;
|
||||
threadId?: string;
|
||||
};
|
||||
assert.equal(startPayload.provider, "claudeAgent");
|
||||
assert.equal(startPayload.cwd, "/tmp/project-claude-send-turn");
|
||||
assert.deepEqual(startPayload.modelOptions, {
|
||||
claudeAgent: {
|
||||
assert.deepEqual(startPayload.modelSelection, {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
options: {
|
||||
effort: "max",
|
||||
},
|
||||
});
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
* @module ProviderServiceLive
|
||||
*/
|
||||
import {
|
||||
ModelSelection,
|
||||
NonNegativeInt,
|
||||
ThreadId,
|
||||
ProviderInterruptTurnInput,
|
||||
@@ -89,7 +90,7 @@ function toRuntimeStatus(session: ProviderSession): "starting" | "running" | "st
|
||||
function toRuntimePayloadFromSession(
|
||||
session: ProviderSession,
|
||||
extra?: {
|
||||
readonly modelOptions?: unknown;
|
||||
readonly modelSelection?: unknown;
|
||||
readonly providerOptions?: unknown;
|
||||
readonly lastRuntimeEvent?: string;
|
||||
readonly lastRuntimeEventAt?: string;
|
||||
@@ -100,7 +101,7 @@ function toRuntimePayloadFromSession(
|
||||
model: session.model ?? null,
|
||||
activeTurnId: session.activeTurnId ?? null,
|
||||
lastError: session.lastError ?? null,
|
||||
...(extra?.modelOptions !== undefined ? { modelOptions: extra.modelOptions } : {}),
|
||||
...(extra?.modelSelection !== undefined ? { modelSelection: extra.modelSelection } : {}),
|
||||
...(extra?.providerOptions !== undefined ? { providerOptions: extra.providerOptions } : {}),
|
||||
...(extra?.lastRuntimeEvent !== undefined ? { lastRuntimeEvent: extra.lastRuntimeEvent } : {}),
|
||||
...(extra?.lastRuntimeEventAt !== undefined
|
||||
@@ -109,15 +110,14 @@ function toRuntimePayloadFromSession(
|
||||
};
|
||||
}
|
||||
|
||||
function readPersistedModelOptions(
|
||||
function readPersistedModelSelection(
|
||||
runtimePayload: ProviderRuntimeBinding["runtimePayload"],
|
||||
): Record<string, unknown> | undefined {
|
||||
): ModelSelection | undefined {
|
||||
if (!runtimePayload || typeof runtimePayload !== "object" || Array.isArray(runtimePayload)) {
|
||||
return undefined;
|
||||
}
|
||||
const raw = "modelOptions" in runtimePayload ? runtimePayload.modelOptions : undefined;
|
||||
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return undefined;
|
||||
return raw as Record<string, unknown>;
|
||||
const raw = "modelSelection" in runtimePayload ? runtimePayload.modelSelection : undefined;
|
||||
return Schema.is(ModelSelection)(raw) ? raw : undefined;
|
||||
}
|
||||
|
||||
function readPersistedProviderOptions(
|
||||
@@ -172,7 +172,7 @@ const makeProviderService = (options?: ProviderServiceLiveOptions) =>
|
||||
session: ProviderSession,
|
||||
threadId: ThreadId,
|
||||
extra?: {
|
||||
readonly modelOptions?: unknown;
|
||||
readonly modelSelection?: unknown;
|
||||
readonly providerOptions?: unknown;
|
||||
readonly lastRuntimeEvent?: string;
|
||||
readonly lastRuntimeEventAt?: string;
|
||||
@@ -238,14 +238,14 @@ const makeProviderService = (options?: ProviderServiceLiveOptions) =>
|
||||
}
|
||||
|
||||
const persistedCwd = readPersistedCwd(input.binding.runtimePayload);
|
||||
const persistedModelOptions = readPersistedModelOptions(input.binding.runtimePayload);
|
||||
const persistedModelSelection = readPersistedModelSelection(input.binding.runtimePayload);
|
||||
const persistedProviderOptions = readPersistedProviderOptions(input.binding.runtimePayload);
|
||||
|
||||
const resumed = yield* adapter.startSession({
|
||||
threadId: input.binding.threadId,
|
||||
provider: input.binding.provider,
|
||||
...(persistedCwd ? { cwd: persistedCwd } : {}),
|
||||
...(persistedModelOptions ? { modelOptions: persistedModelOptions } : {}),
|
||||
...(persistedModelSelection ? { modelSelection: persistedModelSelection } : {}),
|
||||
...(persistedProviderOptions ? { providerOptions: persistedProviderOptions } : {}),
|
||||
...(hasResumeCursor ? { resumeCursor: input.binding.resumeCursor } : {}),
|
||||
runtimeMode: input.binding.runtimeMode ?? "full-access",
|
||||
@@ -328,7 +328,7 @@ const makeProviderService = (options?: ProviderServiceLiveOptions) =>
|
||||
}
|
||||
|
||||
yield* upsertSessionBinding(session, threadId, {
|
||||
modelOptions: input.modelOptions,
|
||||
modelSelection: input.modelSelection,
|
||||
providerOptions: input.providerOptions,
|
||||
});
|
||||
yield* analytics.record("provider.session.started", {
|
||||
@@ -336,7 +336,9 @@ const makeProviderService = (options?: ProviderServiceLiveOptions) =>
|
||||
runtimeMode: input.runtimeMode,
|
||||
hasResumeCursor: session.resumeCursor !== undefined,
|
||||
hasCwd: typeof input.cwd === "string" && input.cwd.trim().length > 0,
|
||||
hasModel: typeof input.model === "string" && input.model.trim().length > 0,
|
||||
hasModel:
|
||||
typeof input.modelSelection?.model === "string" &&
|
||||
input.modelSelection.model.trim().length > 0,
|
||||
});
|
||||
|
||||
return session;
|
||||
@@ -372,6 +374,7 @@ const makeProviderService = (options?: ProviderServiceLiveOptions) =>
|
||||
status: "running",
|
||||
...(turn.resumeCursor !== undefined ? { resumeCursor: turn.resumeCursor } : {}),
|
||||
runtimePayload: {
|
||||
...(input.modelSelection !== undefined ? { modelSelection: input.modelSelection } : {}),
|
||||
activeTurnId: turn.turnId,
|
||||
lastRuntimeEvent: "provider.sendTurn",
|
||||
lastRuntimeEventAt: new Date().toISOString(),
|
||||
@@ -379,7 +382,7 @@ const makeProviderService = (options?: ProviderServiceLiveOptions) =>
|
||||
});
|
||||
yield* analytics.record("provider.turn.sent", {
|
||||
provider: routed.adapter.provider,
|
||||
model: input.model,
|
||||
model: input.modelSelection?.model,
|
||||
interactionMode: input.interactionMode,
|
||||
attachmentCount: input.attachments.length,
|
||||
hasInput: typeof input.input === "string" && input.input.trim().length > 0,
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
type ProjectScript,
|
||||
type ModelSlug,
|
||||
type ProviderKind,
|
||||
type ProviderModelOptions,
|
||||
type ProjectEntry,
|
||||
type ProjectId,
|
||||
type ProviderApprovalDecision,
|
||||
@@ -28,7 +27,6 @@ import {
|
||||
getDefaultModel,
|
||||
normalizeModelSlug,
|
||||
resolveModelSlugForProvider,
|
||||
toProviderModelOptions,
|
||||
} from "@t3tools/shared/model";
|
||||
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
@@ -205,12 +203,6 @@ function formatOutgoingPrompt(params: {
|
||||
}
|
||||
return params.text;
|
||||
}
|
||||
function extractModelSelectionOptions(
|
||||
provider: ProviderKind,
|
||||
modelOptions: ProviderModelOptions | undefined,
|
||||
): ModelSelection["options"] | undefined {
|
||||
return provider === "codex" ? modelOptions?.codex : modelOptions?.claudeAgent;
|
||||
}
|
||||
const COMPOSER_PATH_QUERY_DEBOUNCE_MS = 120;
|
||||
const SCRIPT_TERMINAL_COLS = 120;
|
||||
const SCRIPT_TERMINAL_ROWS = 30;
|
||||
@@ -630,16 +622,15 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
customModelsByProvider,
|
||||
selectedProvider,
|
||||
]);
|
||||
const draftModelOptions = toProviderModelOptions(composerDraft.modelSelection);
|
||||
const composerProviderState = useMemo(
|
||||
() =>
|
||||
getComposerProviderState({
|
||||
provider: selectedProvider,
|
||||
model: selectedModel,
|
||||
prompt,
|
||||
modelOptions: draftModelOptions,
|
||||
modelOptions: composerDraft.modelSelection?.options,
|
||||
}),
|
||||
[draftModelOptions, prompt, selectedModel, selectedProvider],
|
||||
[composerDraft.modelSelection?.options, prompt, selectedModel, selectedProvider],
|
||||
);
|
||||
const selectedPromptEffort = composerProviderState.promptEffort;
|
||||
const selectedModelOptionsForDispatch = composerProviderState.modelOptionsForDispatch;
|
||||
@@ -647,14 +638,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
() => ({
|
||||
provider: selectedProvider,
|
||||
model: selectedModel,
|
||||
...(extractModelSelectionOptions(selectedProvider, selectedModelOptionsForDispatch)
|
||||
? {
|
||||
options: extractModelSelectionOptions(
|
||||
selectedProvider,
|
||||
selectedModelOptionsForDispatch,
|
||||
),
|
||||
}
|
||||
: {}),
|
||||
...(selectedModelOptionsForDispatch ? { options: selectedModelOptionsForDispatch } : {}),
|
||||
}),
|
||||
[selectedModel, selectedModelOptionsForDispatch, selectedProvider],
|
||||
);
|
||||
|
||||
@@ -23,10 +23,8 @@ describe("getComposerProviderState", () => {
|
||||
model: "gpt-5.4",
|
||||
prompt: "",
|
||||
modelOptions: {
|
||||
codex: {
|
||||
reasoningEffort: "low",
|
||||
fastMode: true,
|
||||
},
|
||||
reasoningEffort: "low",
|
||||
fastMode: true,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -34,10 +32,8 @@ describe("getComposerProviderState", () => {
|
||||
provider: "codex",
|
||||
promptEffort: "low",
|
||||
modelOptionsForDispatch: {
|
||||
codex: {
|
||||
reasoningEffort: "low",
|
||||
fastMode: true,
|
||||
},
|
||||
reasoningEffort: "low",
|
||||
fastMode: true,
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -63,9 +59,7 @@ describe("getComposerProviderState", () => {
|
||||
model: "claude-sonnet-4-6",
|
||||
prompt: "Ultrathink:\nInvestigate this failure",
|
||||
modelOptions: {
|
||||
claudeAgent: {
|
||||
effort: "medium",
|
||||
},
|
||||
effort: "medium",
|
||||
},
|
||||
});
|
||||
|
||||
@@ -73,9 +67,7 @@ describe("getComposerProviderState", () => {
|
||||
provider: "claudeAgent",
|
||||
promptEffort: "medium",
|
||||
modelOptionsForDispatch: {
|
||||
claudeAgent: {
|
||||
effort: "medium",
|
||||
},
|
||||
effort: "medium",
|
||||
},
|
||||
composerFrameClassName: "ultrathink-frame",
|
||||
composerSurfaceClassName: "shadow-[0_0_0_1px_rgba(255,255,255,0.04)_inset]",
|
||||
@@ -89,10 +81,8 @@ describe("getComposerProviderState", () => {
|
||||
model: "claude-haiku-4-5",
|
||||
prompt: "",
|
||||
modelOptions: {
|
||||
claudeAgent: {
|
||||
effort: "max",
|
||||
thinking: false,
|
||||
},
|
||||
effort: "max",
|
||||
thinking: false,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -100,50 +90,8 @@ describe("getComposerProviderState", () => {
|
||||
provider: "claudeAgent",
|
||||
promptEffort: null,
|
||||
modelOptionsForDispatch: {
|
||||
claudeAgent: {
|
||||
thinking: false,
|
||||
},
|
||||
thinking: false,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("ignores codex options while resolving Claude state", () => {
|
||||
const state = getComposerProviderState({
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
prompt: "",
|
||||
modelOptions: {
|
||||
codex: {
|
||||
reasoningEffort: "low",
|
||||
fastMode: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(state).toEqual({
|
||||
provider: "claudeAgent",
|
||||
promptEffort: "high",
|
||||
modelOptionsForDispatch: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it("ignores Claude options while resolving codex state", () => {
|
||||
const state = getComposerProviderState({
|
||||
provider: "codex",
|
||||
model: "gpt-5.4",
|
||||
prompt: "Ultrathink:\nThis should not matter",
|
||||
modelOptions: {
|
||||
claudeAgent: {
|
||||
effort: "max",
|
||||
fastMode: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(state).toEqual({
|
||||
provider: "codex",
|
||||
promptEffort: "high",
|
||||
modelOptionsForDispatch: undefined,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,9 @@
|
||||
import {
|
||||
type ClaudeModelOptions,
|
||||
type CodexModelOptions,
|
||||
type ModelSlug,
|
||||
type ModelSelection,
|
||||
type ProviderKind,
|
||||
type ProviderModelOptions,
|
||||
type ThreadId,
|
||||
} from "@t3tools/contracts";
|
||||
import {
|
||||
@@ -21,13 +23,13 @@ export type ComposerProviderStateInput = {
|
||||
provider: ProviderKind;
|
||||
model: ModelSlug;
|
||||
prompt: string;
|
||||
modelOptions: ProviderModelOptions | null | undefined;
|
||||
modelOptions: ModelSelection["options"] | null | undefined;
|
||||
};
|
||||
|
||||
export type ComposerProviderState = {
|
||||
provider: ProviderKind;
|
||||
promptEffort: string | null;
|
||||
modelOptionsForDispatch: ProviderModelOptions | undefined;
|
||||
modelOptionsForDispatch: ModelSelection["options"] | undefined;
|
||||
composerFrameClassName?: string;
|
||||
composerSurfaceClassName?: string;
|
||||
modelPickerIconClassName?: string;
|
||||
@@ -47,20 +49,33 @@ type ProviderRegistryEntry = {
|
||||
}) => ReactNode;
|
||||
};
|
||||
|
||||
function asCodexModelOptions(
|
||||
modelOptions: ModelSelection["options"] | null | undefined,
|
||||
): CodexModelOptions | undefined {
|
||||
return modelOptions && "reasoningEffort" in modelOptions ? modelOptions : undefined;
|
||||
}
|
||||
|
||||
function asClaudeModelOptions(
|
||||
modelOptions: ModelSelection["options"] | null | undefined,
|
||||
): ClaudeModelOptions | undefined {
|
||||
return modelOptions && ("effort" in modelOptions || "thinking" in modelOptions)
|
||||
? modelOptions
|
||||
: undefined;
|
||||
}
|
||||
|
||||
const composerProviderRegistry: Record<ProviderKind, ProviderRegistryEntry> = {
|
||||
codex: {
|
||||
getState: ({ modelOptions }) => {
|
||||
const codexModelOptions = asCodexModelOptions(modelOptions);
|
||||
const promptEffort =
|
||||
resolveReasoningEffortForProvider("codex", modelOptions?.codex?.reasoningEffort) ??
|
||||
resolveReasoningEffortForProvider("codex", codexModelOptions?.reasoningEffort) ??
|
||||
getDefaultReasoningEffort("codex");
|
||||
const normalizedCodexOptions = normalizeCodexModelOptions(modelOptions?.codex);
|
||||
const normalizedCodexOptions = normalizeCodexModelOptions(codexModelOptions);
|
||||
|
||||
return {
|
||||
provider: "codex",
|
||||
promptEffort,
|
||||
modelOptionsForDispatch: normalizedCodexOptions
|
||||
? { codex: normalizedCodexOptions }
|
||||
: undefined,
|
||||
modelOptionsForDispatch: normalizedCodexOptions,
|
||||
};
|
||||
},
|
||||
renderTraitsMenuContent: ({ threadId }) => <CodexTraitsMenuContent threadId={threadId} />,
|
||||
@@ -68,10 +83,11 @@ const composerProviderRegistry: Record<ProviderKind, ProviderRegistryEntry> = {
|
||||
},
|
||||
claudeAgent: {
|
||||
getState: ({ model, prompt, modelOptions }) => {
|
||||
const claudeModelOptions = asClaudeModelOptions(modelOptions);
|
||||
const reasoningOptions = getReasoningEffortOptions("claudeAgent", model);
|
||||
const draftEffort = resolveReasoningEffortForProvider(
|
||||
"claudeAgent",
|
||||
modelOptions?.claudeAgent?.effort,
|
||||
claudeModelOptions?.effort,
|
||||
);
|
||||
const defaultEffort = getDefaultReasoningEffort("claudeAgent");
|
||||
const promptEffort =
|
||||
@@ -80,16 +96,14 @@ const composerProviderRegistry: Record<ProviderKind, ProviderRegistryEntry> = {
|
||||
: reasoningOptions.includes(defaultEffort)
|
||||
? defaultEffort
|
||||
: null;
|
||||
const normalizedClaudeOptions = normalizeClaudeModelOptions(model, modelOptions?.claudeAgent);
|
||||
const normalizedClaudeOptions = normalizeClaudeModelOptions(model, claudeModelOptions);
|
||||
const ultrathinkActive =
|
||||
supportsClaudeUltrathinkKeyword(model) && isClaudeUltrathinkPrompt(prompt);
|
||||
|
||||
return {
|
||||
provider: "claudeAgent",
|
||||
promptEffort,
|
||||
modelOptionsForDispatch: normalizedClaudeOptions
|
||||
? { claudeAgent: normalizedClaudeOptions }
|
||||
: undefined,
|
||||
modelOptionsForDispatch: normalizedClaudeOptions,
|
||||
...(ultrathinkActive ? { composerFrameClassName: "ultrathink-frame" } : {}),
|
||||
...(ultrathinkActive
|
||||
? { composerSurfaceClassName: "shadow-[0_0_0_1px_rgba(255,255,255,0.04)_inset]" }
|
||||
|
||||
@@ -133,7 +133,7 @@ function normalizeLegacyThreadModelSelection(
|
||||
return Effect.succeed(input.modelSelection);
|
||||
}
|
||||
if (input.model === undefined) {
|
||||
return Effect.succeed(undefined);
|
||||
return Effect.succeed<ModelSelection | undefined>(undefined);
|
||||
}
|
||||
return Effect.try({
|
||||
try: () =>
|
||||
|
||||
@@ -12,9 +12,10 @@ describe("ProviderSessionStartInput", () => {
|
||||
threadId: "thread-1",
|
||||
provider: "codex",
|
||||
cwd: "/tmp/workspace",
|
||||
model: "gpt-5.3-codex",
|
||||
modelOptions: {
|
||||
codex: {
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
options: {
|
||||
reasoningEffort: "high",
|
||||
fastMode: true,
|
||||
},
|
||||
@@ -28,8 +29,13 @@ describe("ProviderSessionStartInput", () => {
|
||||
},
|
||||
});
|
||||
expect(parsed.runtimeMode).toBe("full-access");
|
||||
expect(parsed.modelOptions?.codex?.reasoningEffort).toBe("high");
|
||||
expect(parsed.modelOptions?.codex?.fastMode).toBe(true);
|
||||
expect(parsed.modelSelection?.provider).toBe("codex");
|
||||
expect(parsed.modelSelection?.model).toBe("gpt-5.3-codex");
|
||||
if (parsed.modelSelection?.provider !== "codex") {
|
||||
throw new Error("Expected codex modelSelection");
|
||||
}
|
||||
expect(parsed.modelSelection.options?.reasoningEffort).toBe("high");
|
||||
expect(parsed.modelSelection.options?.fastMode).toBe(true);
|
||||
expect(parsed.providerOptions?.codex?.binaryPath).toBe("/usr/local/bin/codex");
|
||||
expect(parsed.providerOptions?.codex?.homePath).toBe("/tmp/.codex");
|
||||
});
|
||||
@@ -48,9 +54,10 @@ describe("ProviderSessionStartInput", () => {
|
||||
threadId: "thread-1",
|
||||
provider: "claudeAgent",
|
||||
cwd: "/tmp/workspace",
|
||||
model: "claude-sonnet-4-6",
|
||||
modelOptions: {
|
||||
claudeAgent: {
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-sonnet-4-6",
|
||||
options: {
|
||||
thinking: true,
|
||||
effort: "max",
|
||||
fastMode: true,
|
||||
@@ -66,9 +73,14 @@ describe("ProviderSessionStartInput", () => {
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
expect(parsed.provider).toBe("claudeAgent");
|
||||
expect(parsed.modelOptions?.claudeAgent?.thinking).toBe(true);
|
||||
expect(parsed.modelOptions?.claudeAgent?.effort).toBe("max");
|
||||
expect(parsed.modelOptions?.claudeAgent?.fastMode).toBe(true);
|
||||
expect(parsed.modelSelection?.provider).toBe("claudeAgent");
|
||||
expect(parsed.modelSelection?.model).toBe("claude-sonnet-4-6");
|
||||
if (parsed.modelSelection?.provider !== "claudeAgent") {
|
||||
throw new Error("Expected claude modelSelection");
|
||||
}
|
||||
expect(parsed.modelSelection.options?.thinking).toBe(true);
|
||||
expect(parsed.modelSelection.options?.effort).toBe("max");
|
||||
expect(parsed.modelSelection.options?.fastMode).toBe(true);
|
||||
expect(parsed.providerOptions?.claudeAgent?.binaryPath).toBe("/usr/local/bin/claude");
|
||||
expect(parsed.providerOptions?.claudeAgent?.permissionMode).toBe("plan");
|
||||
expect(parsed.providerOptions?.claudeAgent?.maxThinkingTokens).toBe(12_000);
|
||||
@@ -77,36 +89,46 @@ describe("ProviderSessionStartInput", () => {
|
||||
});
|
||||
|
||||
describe("ProviderSendTurnInput", () => {
|
||||
it("accepts provider-scoped model options", () => {
|
||||
it("accepts codex modelSelection", () => {
|
||||
const parsed = decodeProviderSendTurnInput({
|
||||
threadId: "thread-1",
|
||||
model: "gpt-5.3-codex",
|
||||
modelOptions: {
|
||||
codex: {
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
options: {
|
||||
reasoningEffort: "xhigh",
|
||||
fastMode: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(parsed.model).toBe("gpt-5.3-codex");
|
||||
expect(parsed.modelOptions?.codex?.reasoningEffort).toBe("xhigh");
|
||||
expect(parsed.modelOptions?.codex?.fastMode).toBe(true);
|
||||
expect(parsed.modelSelection?.provider).toBe("codex");
|
||||
expect(parsed.modelSelection?.model).toBe("gpt-5.3-codex");
|
||||
if (parsed.modelSelection?.provider !== "codex") {
|
||||
throw new Error("Expected codex modelSelection");
|
||||
}
|
||||
expect(parsed.modelSelection.options?.reasoningEffort).toBe("xhigh");
|
||||
expect(parsed.modelSelection.options?.fastMode).toBe(true);
|
||||
});
|
||||
|
||||
it("accepts claude provider effort options including ultrathink", () => {
|
||||
it("accepts claude modelSelection including ultrathink", () => {
|
||||
const parsed = decodeProviderSendTurnInput({
|
||||
threadId: "thread-1",
|
||||
model: "claude-sonnet-4-6",
|
||||
modelOptions: {
|
||||
claudeAgent: {
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-sonnet-4-6",
|
||||
options: {
|
||||
effort: "ultrathink",
|
||||
fastMode: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(parsed.modelOptions?.claudeAgent?.effort).toBe("ultrathink");
|
||||
expect(parsed.modelOptions?.claudeAgent?.fastMode).toBe(true);
|
||||
expect(parsed.modelSelection?.provider).toBe("claudeAgent");
|
||||
if (parsed.modelSelection?.provider !== "claudeAgent") {
|
||||
throw new Error("Expected claude modelSelection");
|
||||
}
|
||||
expect(parsed.modelSelection.options?.effort).toBe("ultrathink");
|
||||
expect(parsed.modelSelection.options?.fastMode).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Schema } from "effect";
|
||||
import { TrimmedNonEmptyString } from "./baseSchemas";
|
||||
import { ProviderModelOptions } from "./model";
|
||||
import {
|
||||
ApprovalRequestId,
|
||||
EventId,
|
||||
@@ -11,6 +10,7 @@ import {
|
||||
} from "./baseSchemas";
|
||||
import {
|
||||
ChatAttachment,
|
||||
ModelSelection,
|
||||
PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
|
||||
PROVIDER_SEND_TURN_MAX_INPUT_CHARS,
|
||||
ProviderApprovalDecision,
|
||||
@@ -51,8 +51,7 @@ export const ProviderSessionStartInput = Schema.Struct({
|
||||
threadId: ThreadId,
|
||||
provider: Schema.optional(ProviderKind),
|
||||
cwd: Schema.optional(TrimmedNonEmptyString),
|
||||
model: Schema.optional(TrimmedNonEmptyString),
|
||||
modelOptions: Schema.optional(ProviderModelOptions),
|
||||
modelSelection: Schema.optional(ModelSelection),
|
||||
resumeCursor: Schema.optional(Schema.Unknown),
|
||||
approvalPolicy: Schema.optional(ProviderApprovalPolicy),
|
||||
sandboxMode: Schema.optional(ProviderSandboxMode),
|
||||
@@ -69,8 +68,7 @@ export const ProviderSendTurnInput = Schema.Struct({
|
||||
attachments: Schema.optional(
|
||||
Schema.Array(ChatAttachment).check(Schema.isMaxLength(PROVIDER_SEND_TURN_MAX_ATTACHMENTS)),
|
||||
),
|
||||
model: Schema.optional(TrimmedNonEmptyString),
|
||||
modelOptions: Schema.optional(ProviderModelOptions),
|
||||
modelSelection: Schema.optional(ModelSelection),
|
||||
interactionMode: Schema.optional(ProviderInteractionMode),
|
||||
});
|
||||
export type ProviderSendTurnInput = typeof ProviderSendTurnInput.Type;
|
||||
|
||||
@@ -27,7 +27,6 @@ import {
|
||||
supportsClaudeFastMode,
|
||||
supportsClaudeMaxEffort,
|
||||
supportsClaudeThinkingToggle,
|
||||
toProviderModelOptions,
|
||||
supportsClaudeUltrathinkKeyword,
|
||||
} from "./model";
|
||||
|
||||
@@ -273,45 +272,6 @@ describe("normalizeClaudeModelOptions", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("toProviderModelOptions", () => {
|
||||
it("returns undefined when no model options exist", () => {
|
||||
expect(toProviderModelOptions({ provider: "codex", model: "gpt-5.4" })).toBeUndefined();
|
||||
expect(toProviderModelOptions(null)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("scopes codex options under the codex provider key", () => {
|
||||
expect(
|
||||
toProviderModelOptions({
|
||||
provider: "codex",
|
||||
model: "gpt-5.4",
|
||||
options: {
|
||||
fastMode: true,
|
||||
},
|
||||
}),
|
||||
).toEqual({
|
||||
codex: {
|
||||
fastMode: true,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("scopes claude options under the claudeAgent provider key", () => {
|
||||
expect(
|
||||
toProviderModelOptions({
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
options: {
|
||||
effort: "max",
|
||||
},
|
||||
}),
|
||||
).toEqual({
|
||||
claudeAgent: {
|
||||
effort: "max",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("supportsClaudeAdaptiveReasoning", () => {
|
||||
it("only enables adaptive reasoning for Opus 4.6 and Sonnet 4.6", () => {
|
||||
expect(supportsClaudeAdaptiveReasoning("claude-opus-4-6")).toBe(true);
|
||||
|
||||
@@ -10,9 +10,7 @@ import {
|
||||
type ClaudeCodeEffort,
|
||||
type CodexModelOptions,
|
||||
type CodexReasoningEffort,
|
||||
type ModelSelection,
|
||||
type ModelSlug,
|
||||
type ProviderModelOptions,
|
||||
type ProviderReasoningEffort,
|
||||
type ProviderKind,
|
||||
} from "@t3tools/contracts";
|
||||
@@ -268,15 +266,4 @@ export function applyClaudePromptEffortPrefix(
|
||||
return `Ultrathink:\n${trimmed}`;
|
||||
}
|
||||
|
||||
export function toProviderModelOptions(
|
||||
modelSelection: ModelSelection | null | undefined,
|
||||
): ProviderModelOptions | undefined {
|
||||
if (!modelSelection?.options) {
|
||||
return undefined;
|
||||
}
|
||||
return modelSelection.provider === "codex"
|
||||
? { codex: modelSelection.options }
|
||||
: { claudeAgent: modelSelection.options };
|
||||
}
|
||||
|
||||
export { CLAUDE_CODE_EFFORT_OPTIONS, CODEX_REASONING_EFFORT_OPTIONS };
|
||||
Reference in new issue
Block a user