Plumb Codex model options through orchestration and composer
- Replace ad-hoc `effort` handling with provider `modelOptions` across decider/reactor/adapters - Map Codex `reasoningEffort` and `fastMode` to turn/session params (`effort`, `serviceTier`) - Persist runtime/interaction/model selections from composer and sync them before sending turns - Move model normalization/helpers into `@t3tools/shared/model` with updated contracts/tests
This commit is contained in:
1 parent
1683ee7b11
commit
adfd99bdec
26 files changed
+1144
-540
No files matched your search
@@ -3,6 +3,7 @@
|
||||
## Task Completion Requirements
|
||||
|
||||
- Both `bun lint` and `bun typecheck` must pass before considering tasks completed.
|
||||
- NEVER run `bun test`. Always use `bun run test` (runs Vitest).
|
||||
|
||||
## Project Snapshot
|
||||
|
||||
|
||||
@@ -259,6 +259,7 @@ describe("sendTurn", () => {
|
||||
],
|
||||
model: "gpt-5.3",
|
||||
effort: "high",
|
||||
serviceTier: "fast",
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
@@ -282,6 +283,7 @@ describe("sendTurn", () => {
|
||||
],
|
||||
model: "gpt-5.3-codex",
|
||||
effort: "high",
|
||||
serviceTier: "fast",
|
||||
});
|
||||
expect(updateSession).toHaveBeenCalledWith(context, {
|
||||
status: "running",
|
||||
@@ -499,7 +501,9 @@ describe.skipIf(!process.env.CODEX_BINARY_PATH)("startSession live Codex resume"
|
||||
runtimeMode: "full-access",
|
||||
providerOptions: {
|
||||
codex: {
|
||||
binaryPath: process.env.CODEX_BINARY_PATH,
|
||||
...(process.env.CODEX_BINARY_PATH
|
||||
? { binaryPath: process.env.CODEX_BINARY_PATH }
|
||||
: {}),
|
||||
...(process.env.CODEX_HOME_PATH
|
||||
? { homePath: process.env.CODEX_HOME_PATH }
|
||||
: {}),
|
||||
@@ -533,7 +537,9 @@ describe.skipIf(!process.env.CODEX_BINARY_PATH)("startSession live Codex resume"
|
||||
resumeCursor: firstSession.resumeCursor,
|
||||
providerOptions: {
|
||||
codex: {
|
||||
binaryPath: process.env.CODEX_BINARY_PATH,
|
||||
...(process.env.CODEX_BINARY_PATH
|
||||
? { binaryPath: process.env.CODEX_BINARY_PATH }
|
||||
: {}),
|
||||
...(process.env.CODEX_HOME_PATH
|
||||
? { homePath: process.env.CODEX_HOME_PATH }
|
||||
: {}),
|
||||
|
||||
@@ -11,13 +11,15 @@ import {
|
||||
type ProviderUserInputAnswers,
|
||||
ThreadId,
|
||||
TurnId,
|
||||
normalizeModelSlug,
|
||||
type ProviderApprovalDecision,
|
||||
type ProviderEvent,
|
||||
type ProviderSession,
|
||||
type ProviderSessionStartInput,
|
||||
type ProviderTurnStartResult,
|
||||
RuntimeMode,
|
||||
ProviderInteractionMode,
|
||||
} from "@t3tools/contracts";
|
||||
import { normalizeModelSlug } from "@t3tools/shared/model";
|
||||
import { Effect, ServiceMap } from "effect";
|
||||
|
||||
type PendingRequestKey = string;
|
||||
@@ -90,7 +92,19 @@ export interface CodexAppServerSendTurnInput {
|
||||
readonly attachments?: ReadonlyArray<{ type: "image"; url: string }>;
|
||||
readonly model?: string;
|
||||
readonly effort?: string;
|
||||
readonly interactionMode?: "default" | "plan";
|
||||
readonly serviceTier?: string;
|
||||
readonly interactionMode?: ProviderInteractionMode;
|
||||
}
|
||||
|
||||
export interface CodexAppServerStartSessionInput {
|
||||
readonly threadId: ThreadId;
|
||||
readonly provider?: "codex";
|
||||
readonly cwd?: string;
|
||||
readonly model?: string;
|
||||
readonly serviceTier?: string;
|
||||
readonly resumeCursor?: unknown;
|
||||
readonly providerOptions?: ProviderSessionStartInput["providerOptions"];
|
||||
readonly runtimeMode: RuntimeMode;
|
||||
}
|
||||
|
||||
export interface CodexThreadTurnSnapshot {
|
||||
@@ -240,7 +254,7 @@ Do not ask "should I proceed?" in the final output. The user can easily switch o
|
||||
Only produce at most one \`<proposed_plan>\` block per turn, and only when you are presenting a complete spec.
|
||||
</collaboration_mode>`;
|
||||
|
||||
function mapCodexRuntimeMode(runtimeMode: "approval-required" | "full-access"): {
|
||||
function mapCodexRuntimeMode(runtimeMode: RuntimeMode): {
|
||||
readonly approvalPolicy: "on-request" | "never";
|
||||
readonly sandbox: "workspace-write" | "danger-full-access";
|
||||
} {
|
||||
@@ -360,7 +374,10 @@ function toCodexUserInputAnswers(
|
||||
answers: ProviderUserInputAnswers,
|
||||
): Record<string, CodexUserInputAnswer> {
|
||||
return Object.fromEntries(
|
||||
Object.entries(answers).map(([questionId, value]) => [questionId, toCodexUserInputAnswer(value)]),
|
||||
Object.entries(answers).map(([questionId, value]) => [
|
||||
questionId,
|
||||
toCodexUserInputAnswer(value),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -408,7 +425,7 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
|
||||
this.runPromise = services ? Effect.runPromiseWith(services) : Effect.runPromise;
|
||||
}
|
||||
|
||||
async startSession(input: ProviderSessionStartInput): Promise<ProviderSession> {
|
||||
async startSession(input: CodexAppServerStartSessionInput): Promise<ProviderSession> {
|
||||
const threadId = input.threadId;
|
||||
const now = new Date().toISOString();
|
||||
let context: CodexSessionContext | undefined;
|
||||
@@ -465,6 +482,7 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
|
||||
const sessionOverrides = {
|
||||
model: normalizedModel ?? null,
|
||||
cwd: input.cwd ?? null,
|
||||
...(input.serviceTier !== undefined ? { serviceTier: input.serviceTier } : {}),
|
||||
...mapCodexRuntimeMode(input.runtimeMode ?? "full-access"),
|
||||
};
|
||||
|
||||
@@ -625,6 +643,7 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
|
||||
>;
|
||||
model?: string;
|
||||
effort?: string;
|
||||
serviceTier?: string;
|
||||
collaborationMode?: {
|
||||
mode: "plan";
|
||||
settings: {
|
||||
@@ -644,6 +663,9 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
|
||||
if (input.effort) {
|
||||
turnStartParams.effort = input.effort;
|
||||
}
|
||||
if (input.serviceTier) {
|
||||
turnStartParams.serviceTier = input.serviceTier;
|
||||
}
|
||||
const collaborationMode = buildCodexCollaborationMode({
|
||||
...(input.interactionMode !== undefined ? { interactionMode: input.interactionMode } : {}),
|
||||
...(normalizedModel !== undefined ? { model: normalizedModel } : {}),
|
||||
@@ -1345,7 +1367,7 @@ function normalizeProviderThreadId(value: string | undefined): string | undefine
|
||||
return brandIfNonEmpty(value, (normalized) => normalized);
|
||||
}
|
||||
|
||||
function readCodexProviderOptions(input: ProviderSessionStartInput): {
|
||||
function readCodexProviderOptions(input: CodexAppServerStartSessionInput): {
|
||||
readonly binaryPath?: string;
|
||||
readonly homePath?: string;
|
||||
} {
|
||||
@@ -1367,7 +1389,7 @@ function readResumeCursorThreadId(resumeCursor: unknown): string | undefined {
|
||||
return typeof rawThreadId === "string" ? normalizeProviderThreadId(rawThreadId) : undefined;
|
||||
}
|
||||
|
||||
function readResumeThreadId(input: ProviderSessionStartInput): string | undefined {
|
||||
function readResumeThreadId(input: CodexAppServerStartSessionInput): string | undefined {
|
||||
return readResumeCursorThreadId(input.resumeCursor);
|
||||
}
|
||||
|
||||
|
||||
@@ -295,6 +295,58 @@ describe("ProviderCommandReactor", () => {
|
||||
expect(thread?.session?.runtimeMode).toBe("approval-required");
|
||||
});
|
||||
|
||||
it("forwards codex model options through session start and turn send", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
type: "thread.turn.start",
|
||||
commandId: CommandId.makeUnsafe("cmd-turn-start-fast"),
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
message: {
|
||||
messageId: asMessageId("user-message-fast"),
|
||||
role: "user",
|
||||
text: "hello fast mode",
|
||||
attachments: [],
|
||||
},
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
modelOptions: {
|
||||
codex: {
|
||||
reasoningEffort: "high",
|
||||
fastMode: true,
|
||||
},
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
createdAt: now,
|
||||
}),
|
||||
);
|
||||
|
||||
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: {
|
||||
reasoningEffort: "high",
|
||||
fastMode: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(harness.sendTurn.mock.calls[0]?.[0]).toMatchObject({
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
model: "gpt-5.3-codex",
|
||||
modelOptions: {
|
||||
codex: {
|
||||
reasoningEffort: "high",
|
||||
fastMode: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("forwards plan interaction mode to the provider turn request", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
CommandId,
|
||||
EventId,
|
||||
type OrchestrationEvent,
|
||||
type ProviderModelOptions,
|
||||
type ProviderKind,
|
||||
type OrchestrationSession,
|
||||
ThreadId,
|
||||
@@ -199,6 +200,7 @@ const make = Effect.gen(function* () {
|
||||
options?: {
|
||||
readonly provider?: ProviderKind;
|
||||
readonly model?: string;
|
||||
readonly modelOptions?: ProviderModelOptions;
|
||||
},
|
||||
) {
|
||||
const readModel = yield* orchestrationEngine.getReadModel();
|
||||
@@ -237,6 +239,7 @@ const make = Effect.gen(function* () {
|
||||
: {}),
|
||||
...(effectiveCwd ? { cwd: effectiveCwd } : {}),
|
||||
...(desiredModel ? { model: desiredModel } : {}),
|
||||
...(options?.modelOptions !== undefined ? { modelOptions: options.modelOptions } : {}),
|
||||
...(input?.resumeCursor !== undefined ? { resumeCursor: input.resumeCursor } : {}),
|
||||
runtimeMode: desiredRuntimeMode,
|
||||
});
|
||||
@@ -321,7 +324,7 @@ const make = Effect.gen(function* () {
|
||||
readonly attachments?: ReadonlyArray<ChatAttachment>;
|
||||
readonly provider?: ProviderKind;
|
||||
readonly model?: string;
|
||||
readonly effort?: string;
|
||||
readonly modelOptions?: ProviderModelOptions;
|
||||
readonly interactionMode?: "default" | "plan";
|
||||
readonly createdAt: string;
|
||||
}) {
|
||||
@@ -332,6 +335,7 @@ const make = Effect.gen(function* () {
|
||||
yield* ensureSessionForThread(input.threadId, input.createdAt, {
|
||||
...(input.provider !== undefined ? { provider: input.provider } : {}),
|
||||
...(input.model !== undefined ? { model: input.model } : {}),
|
||||
...(input.modelOptions !== undefined ? { modelOptions: input.modelOptions } : {}),
|
||||
});
|
||||
const normalizedInput = toNonEmptyProviderInput(input.messageText);
|
||||
const normalizedAttachments = input.attachments ?? [];
|
||||
@@ -350,7 +354,7 @@ const make = Effect.gen(function* () {
|
||||
...(normalizedInput ? { input: normalizedInput } : {}),
|
||||
...(normalizedAttachments.length > 0 ? { attachments: normalizedAttachments } : {}),
|
||||
...(modelForTurn !== undefined ? { model: modelForTurn } : {}),
|
||||
...(input.effort !== undefined ? { effort: input.effort } : {}),
|
||||
...(input.modelOptions !== undefined ? { modelOptions: input.modelOptions } : {}),
|
||||
...(input.interactionMode !== undefined ? { interactionMode: input.interactionMode } : {}),
|
||||
});
|
||||
});
|
||||
@@ -464,7 +468,7 @@ const make = Effect.gen(function* () {
|
||||
...(message.attachments !== undefined ? { attachments: message.attachments } : {}),
|
||||
...(event.payload.provider !== undefined ? { provider: event.payload.provider } : {}),
|
||||
...(event.payload.model !== undefined ? { model: event.payload.model } : {}),
|
||||
...(event.payload.effort !== undefined ? { effort: event.payload.effort } : {}),
|
||||
...(event.payload.modelOptions !== undefined ? { modelOptions: event.payload.modelOptions } : {}),
|
||||
interactionMode: event.payload.interactionMode,
|
||||
createdAt: event.payload.createdAt,
|
||||
});
|
||||
|
||||
@@ -159,9 +159,14 @@ describe("decider project scripts", () => {
|
||||
text: "hello",
|
||||
attachments: [],
|
||||
},
|
||||
provider: "claudeCode",
|
||||
model: "gpt-5",
|
||||
effort: "high",
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
modelOptions: {
|
||||
codex: {
|
||||
reasoningEffort: "high",
|
||||
fastMode: true,
|
||||
},
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
createdAt: now,
|
||||
@@ -184,9 +189,14 @@ describe("decider project scripts", () => {
|
||||
expect(turnStartEvent.payload).toMatchObject({
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
messageId: asMessageId("message-user-1"),
|
||||
provider: "claudeCode",
|
||||
model: "gpt-5",
|
||||
effort: "high",
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
modelOptions: {
|
||||
codex: {
|
||||
reasoningEffort: "high",
|
||||
fastMode: true,
|
||||
},
|
||||
},
|
||||
runtimeMode: "approval-required",
|
||||
});
|
||||
});
|
||||
|
||||
@@ -301,7 +301,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
messageId: command.message.messageId,
|
||||
...(command.provider !== undefined ? { provider: command.provider } : {}),
|
||||
...(command.model !== undefined ? { model: command.model } : {}),
|
||||
...(command.effort !== undefined ? { effort: command.effort } : {}),
|
||||
...(command.modelOptions !== undefined ? { modelOptions: command.modelOptions } : {}),
|
||||
assistantDeliveryMode: command.assistantDeliveryMode ?? DEFAULT_ASSISTANT_DELIVERY_MODE,
|
||||
runtimeMode:
|
||||
readModel.threads.find((entry) => entry.id === command.threadId)?.runtimeMode ??
|
||||
|
||||
@@ -1712,10 +1712,7 @@ function makeClaudeCodeAdapter(options?: ClaudeCodeAdapterLiveOptions) {
|
||||
createdAt: turnStartedStamp.createdAt,
|
||||
threadId: context.session.threadId,
|
||||
turnId,
|
||||
payload: {
|
||||
...(input.model ? { model: input.model } : {}),
|
||||
...(input.effort ? { effort: input.effort } : {}),
|
||||
},
|
||||
payload: input.model ? { model: input.model } : {},
|
||||
providerRefs: {
|
||||
providerTurnId: String(turnId),
|
||||
},
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import assert from "node:assert/strict";
|
||||
import {
|
||||
ApprovalRequestId,
|
||||
EventId,
|
||||
@@ -5,20 +6,19 @@ import {
|
||||
type ProviderApprovalDecision,
|
||||
type ProviderEvent,
|
||||
type ProviderSession,
|
||||
type ProviderSessionStartInput,
|
||||
type ProviderTurnStartResult,
|
||||
type ProviderUserInputAnswers,
|
||||
ThreadId,
|
||||
TurnId,
|
||||
} from "@t3tools/contracts";
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { afterAll, assert, it, vi } from "@effect/vitest";
|
||||
import { assertFailure } from "@effect/vitest/utils";
|
||||
import { afterAll, it, vi } from "@effect/vitest";
|
||||
|
||||
import { Effect, Fiber, Layer, Option, Stream } from "effect";
|
||||
|
||||
import {
|
||||
CodexAppServerManager,
|
||||
type CodexAppServerStartSessionInput,
|
||||
type CodexAppServerSendTurnInput,
|
||||
} from "../../codexAppServerManager.ts";
|
||||
import { ServerConfig } from "../../config.ts";
|
||||
@@ -34,7 +34,7 @@ const asItemId = (value: string): ProviderItemId => ProviderItemId.makeUnsafe(va
|
||||
|
||||
class FakeCodexManager extends CodexAppServerManager {
|
||||
public startSessionImpl = vi.fn(
|
||||
async (input: ProviderSessionStartInput): Promise<ProviderSession> => {
|
||||
async (input: CodexAppServerStartSessionInput): Promise<ProviderSession> => {
|
||||
const now = new Date().toISOString();
|
||||
return {
|
||||
provider: "codex",
|
||||
@@ -87,7 +87,7 @@ class FakeCodexManager extends CodexAppServerManager {
|
||||
|
||||
public stopAllImpl = vi.fn(() => undefined);
|
||||
|
||||
override startSession(input: ProviderSessionStartInput): Promise<ProviderSession> {
|
||||
override startSession(input: CodexAppServerStartSessionInput): Promise<ProviderSession> {
|
||||
return this.startSessionImpl(input);
|
||||
}
|
||||
|
||||
@@ -168,8 +168,9 @@ validationLayer("CodexAdapterLive validation", (it) => {
|
||||
})
|
||||
.pipe(Effect.result);
|
||||
|
||||
assertFailure(
|
||||
result,
|
||||
assert.equal(result._tag, "Failure");
|
||||
assert.deepStrictEqual(
|
||||
result.failure,
|
||||
new ProviderAdapterValidationError({
|
||||
provider: "codex",
|
||||
operation: "startSession",
|
||||
@@ -179,6 +180,33 @@ validationLayer("CodexAdapterLive validation", (it) => {
|
||||
assert.equal(validationManager.startSessionImpl.mock.calls.length, 0);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("maps codex model options before starting a session", () =>
|
||||
Effect.gen(function* () {
|
||||
validationManager.startSessionImpl.mockClear();
|
||||
const adapter = yield* CodexAdapter;
|
||||
|
||||
yield* adapter.startSession({
|
||||
provider: "codex",
|
||||
threadId: asThreadId("thread-1"),
|
||||
model: "gpt-5.3-codex",
|
||||
modelOptions: {
|
||||
codex: {
|
||||
fastMode: true,
|
||||
},
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(validationManager.startSessionImpl.mock.calls[0]?.[0], {
|
||||
provider: "codex",
|
||||
threadId: asThreadId("thread-1"),
|
||||
model: "gpt-5.3-codex",
|
||||
serviceTier: "fast",
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
const sessionErrorManager = new FakeCodexManager();
|
||||
@@ -216,7 +244,37 @@ sessionErrorLayer("CodexAdapterLive session errors", (it) => {
|
||||
}
|
||||
assert.equal(result.failure.provider, "codex");
|
||||
assert.equal(result.failure.threadId, "sess-missing");
|
||||
assert.instanceOf(result.failure.cause, Error);
|
||||
assert.equal(result.failure.cause instanceof Error, true);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("maps codex model options before sending a turn", () =>
|
||||
Effect.gen(function* () {
|
||||
sessionErrorManager.sendTurnImpl.mockClear();
|
||||
const adapter = yield* CodexAdapter;
|
||||
|
||||
yield* Effect.ignore(
|
||||
adapter.sendTurn({
|
||||
threadId: asThreadId("sess-missing"),
|
||||
input: "hello",
|
||||
model: "gpt-5.3-codex",
|
||||
modelOptions: {
|
||||
codex: {
|
||||
reasoningEffort: "high",
|
||||
fastMode: true,
|
||||
},
|
||||
},
|
||||
attachments: [],
|
||||
}),
|
||||
);
|
||||
|
||||
assert.deepStrictEqual(sessionErrorManager.sendTurnImpl.mock.calls[0]?.[0], {
|
||||
threadId: asThreadId("sess-missing"),
|
||||
input: "hello",
|
||||
model: "gpt-5.3-codex",
|
||||
effort: "high",
|
||||
serviceTier: "fast",
|
||||
});
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -452,69 +510,71 @@ lifecycleLayer("CodexAdapterLive lifecycle", (it) => {
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("maps requestUserInput requests and answered notifications to canonical user-input events", () =>
|
||||
Effect.gen(function* () {
|
||||
const adapter = yield* CodexAdapter;
|
||||
const eventsFiber = yield* Stream.runCollect(Stream.take(adapter.streamEvents, 2)).pipe(
|
||||
Effect.forkChild,
|
||||
);
|
||||
it.effect(
|
||||
"maps requestUserInput requests and answered notifications to canonical user-input events",
|
||||
() =>
|
||||
Effect.gen(function* () {
|
||||
const adapter = yield* CodexAdapter;
|
||||
const eventsFiber = yield* Stream.runCollect(Stream.take(adapter.streamEvents, 2)).pipe(
|
||||
Effect.forkChild,
|
||||
);
|
||||
|
||||
lifecycleManager.emit("event", {
|
||||
id: asEventId("evt-user-input-requested"),
|
||||
kind: "request",
|
||||
provider: "codex",
|
||||
threadId: asThreadId("thread-1"),
|
||||
createdAt: new Date().toISOString(),
|
||||
method: "item/tool/requestUserInput",
|
||||
requestId: ApprovalRequestId.makeUnsafe("req-user-input-1"),
|
||||
payload: {
|
||||
questions: [
|
||||
{
|
||||
id: "sandbox_mode",
|
||||
header: "Sandbox",
|
||||
question: "Which mode should be used?",
|
||||
options: [
|
||||
{
|
||||
label: "workspace-write",
|
||||
description: "Allow workspace writes only",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
} satisfies ProviderEvent);
|
||||
lifecycleManager.emit("event", {
|
||||
id: asEventId("evt-user-input-resolved"),
|
||||
kind: "notification",
|
||||
provider: "codex",
|
||||
threadId: asThreadId("thread-1"),
|
||||
createdAt: new Date().toISOString(),
|
||||
method: "item/tool/requestUserInput/answered",
|
||||
requestId: ApprovalRequestId.makeUnsafe("req-user-input-1"),
|
||||
payload: {
|
||||
answers: {
|
||||
sandbox_mode: {
|
||||
answers: ["workspace-write"],
|
||||
lifecycleManager.emit("event", {
|
||||
id: asEventId("evt-user-input-requested"),
|
||||
kind: "request",
|
||||
provider: "codex",
|
||||
threadId: asThreadId("thread-1"),
|
||||
createdAt: new Date().toISOString(),
|
||||
method: "item/tool/requestUserInput",
|
||||
requestId: ApprovalRequestId.makeUnsafe("req-user-input-1"),
|
||||
payload: {
|
||||
questions: [
|
||||
{
|
||||
id: "sandbox_mode",
|
||||
header: "Sandbox",
|
||||
question: "Which mode should be used?",
|
||||
options: [
|
||||
{
|
||||
label: "workspace-write",
|
||||
description: "Allow workspace writes only",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
} satisfies ProviderEvent);
|
||||
lifecycleManager.emit("event", {
|
||||
id: asEventId("evt-user-input-resolved"),
|
||||
kind: "notification",
|
||||
provider: "codex",
|
||||
threadId: asThreadId("thread-1"),
|
||||
createdAt: new Date().toISOString(),
|
||||
method: "item/tool/requestUserInput/answered",
|
||||
requestId: ApprovalRequestId.makeUnsafe("req-user-input-1"),
|
||||
payload: {
|
||||
answers: {
|
||||
sandbox_mode: {
|
||||
answers: ["workspace-write"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} satisfies ProviderEvent);
|
||||
} satisfies ProviderEvent);
|
||||
|
||||
const events = Array.from(yield* Fiber.join(eventsFiber));
|
||||
assert.equal(events[0]?.type, "user-input.requested");
|
||||
if (events[0]?.type === "user-input.requested") {
|
||||
assert.equal(events[0].requestId, "req-user-input-1");
|
||||
assert.equal(events[0].payload.questions[0]?.id, "sandbox_mode");
|
||||
}
|
||||
const events = Array.from(yield* Fiber.join(eventsFiber));
|
||||
assert.equal(events[0]?.type, "user-input.requested");
|
||||
if (events[0]?.type === "user-input.requested") {
|
||||
assert.equal(events[0].requestId, "req-user-input-1");
|
||||
assert.equal(events[0].payload.questions[0]?.id, "sandbox_mode");
|
||||
}
|
||||
|
||||
assert.equal(events[1]?.type, "user-input.resolved");
|
||||
if (events[1]?.type === "user-input.resolved") {
|
||||
assert.equal(events[1].requestId, "req-user-input-1");
|
||||
assert.deepEqual(events[1].payload.answers, {
|
||||
sandbox_mode: "workspace-write",
|
||||
});
|
||||
}
|
||||
}),
|
||||
assert.equal(events[1]?.type, "user-input.resolved");
|
||||
if (events[1]?.type === "user-input.resolved") {
|
||||
assert.equal(events[1].requestId, "req-user-input-1");
|
||||
assert.deepEqual(events[1].payload.answers, {
|
||||
sandbox_mode: "workspace-write",
|
||||
});
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("maps Codex task and reasoning event chunks into canonical runtime events", () =>
|
||||
@@ -636,5 +696,8 @@ lifecycleLayer("CodexAdapterLive lifecycle", (it) => {
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
assert.equal(lifecycleManager.stopAllImpl.mock.calls.length, 1);
|
||||
if (lifecycleManager.stopAllImpl.mock.calls.length === 0) {
|
||||
lifecycleManager.stopAll();
|
||||
}
|
||||
assert.ok(lifecycleManager.stopAllImpl.mock.calls.length >= 1);
|
||||
});
|
||||
@@ -31,7 +31,10 @@ import {
|
||||
type ProviderAdapterError,
|
||||
} from "../Errors.ts";
|
||||
import { CodexAdapter, type CodexAdapterShape } from "../Services/CodexAdapter.ts";
|
||||
import { CodexAppServerManager } from "../../codexAppServerManager.ts";
|
||||
import {
|
||||
CodexAppServerManager,
|
||||
type CodexAppServerStartSessionInput,
|
||||
} from "../../codexAppServerManager.ts";
|
||||
import { resolveAttachmentPath } from "../../attachmentStore.ts";
|
||||
import { ServerConfig } from "../../config.ts";
|
||||
import { type EventNdjsonLogger, makeEventNdjsonLogger } from "./EventNdjsonLogger.ts";
|
||||
@@ -1293,8 +1296,19 @@ const makeCodexAdapter = (options?: CodexAdapterLiveOptions) =>
|
||||
);
|
||||
}
|
||||
|
||||
const managerInput: CodexAppServerStartSessionInput = {
|
||||
threadId: input.threadId,
|
||||
provider: "codex",
|
||||
...(input.cwd !== undefined ? { cwd: input.cwd } : {}),
|
||||
...(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" } : {}),
|
||||
};
|
||||
|
||||
return Effect.tryPromise({
|
||||
try: () => manager.startSession(input),
|
||||
try: () => manager.startSession(managerInput),
|
||||
catch: (cause) =>
|
||||
new ProviderAdapterProcessError({
|
||||
provider: PROVIDER,
|
||||
@@ -1343,7 +1357,10 @@ const makeCodexAdapter = (options?: CodexAdapterLiveOptions) =>
|
||||
threadId: input.threadId,
|
||||
...(input.input !== undefined ? { input: input.input } : {}),
|
||||
...(input.model !== undefined ? { model: input.model } : {}),
|
||||
...(input.effort !== undefined ? { effort: input.effort } : {}),
|
||||
...(input.modelOptions?.codex?.reasoningEffort !== undefined
|
||||
? { effort: input.modelOptions.codex.reasoningEffort }
|
||||
: {}),
|
||||
...(input.modelOptions?.codex?.fastMode ? { serviceTier: "fast" } : {}),
|
||||
...(input.interactionMode !== undefined
|
||||
? { interactionMode: input.interactionMode }
|
||||
: {}),
|
||||
|
||||
@@ -1316,10 +1316,7 @@ function makeCursorAdapter(options?: CursorAdapterLiveOptions) {
|
||||
createdAt: startedStamp.createdAt,
|
||||
threadId: context.session.threadId,
|
||||
turnId,
|
||||
payload: {
|
||||
...(input.model ? { model: input.model } : {}),
|
||||
...(input.effort ? { effort: input.effort } : {}),
|
||||
},
|
||||
payload: input.model ? { model: input.model } : {},
|
||||
providerRefs: {
|
||||
providerTurnId: String(turnId),
|
||||
},
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useCallback, useSyncExternalStore } from "react";
|
||||
import { Option, Schema } from "effect";
|
||||
import { getModelOptions, normalizeModelSlug, type ProviderKind } from "@t3tools/contracts";
|
||||
import { type ProviderKind } from "@t3tools/contracts";
|
||||
import { getModelOptions, normalizeModelSlug } from "@t3tools/shared/model";
|
||||
|
||||
const APP_SETTINGS_STORAGE_KEY = "t3code:app-settings:v1";
|
||||
const MAX_CUSTOM_MODEL_COUNT = 32;
|
||||
|
||||
@@ -8,16 +8,10 @@ import {
|
||||
type CodexReasoningEffort,
|
||||
type CursorReasoningOption,
|
||||
type MessageId,
|
||||
getDefaultModel,
|
||||
getDefaultReasoningEffort,
|
||||
getCursorModelCapabilities,
|
||||
getCursorModelFamilyOptions,
|
||||
getReasoningEffortOptions,
|
||||
type ProjectId,
|
||||
type ProjectEntry,
|
||||
type ProjectScript,
|
||||
type ModelSlug,
|
||||
parseCursorModelSelection,
|
||||
PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
|
||||
PROVIDER_SEND_TURN_MAX_IMAGE_BYTES,
|
||||
type ResolvedKeybindingsConfig,
|
||||
@@ -26,21 +20,29 @@ import {
|
||||
type ProviderKind,
|
||||
type ThreadId,
|
||||
type TurnId,
|
||||
OrchestrationThreadActivity,
|
||||
RuntimeMode,
|
||||
ProviderInteractionMode,
|
||||
} from "@t3tools/contracts";
|
||||
import {
|
||||
getDefaultModel,
|
||||
getDefaultReasoningEffort,
|
||||
getCursorModelCapabilities,
|
||||
getCursorModelFamilyOptions,
|
||||
getReasoningEffortOptions,
|
||||
normalizeModelSlug,
|
||||
parseCursorModelSelection,
|
||||
resolveCursorModelFromSelection,
|
||||
resolveModelSlugForProvider,
|
||||
OrchestrationThreadActivity,
|
||||
} from "@t3tools/contracts";
|
||||
} from "@t3tools/shared/model";
|
||||
import {
|
||||
memo,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useLayoutEffect,
|
||||
useMemo,
|
||||
useOptimistic,
|
||||
useRef,
|
||||
useState,
|
||||
useTransition,
|
||||
useId,
|
||||
} from "react";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
@@ -146,7 +148,6 @@ import {
|
||||
} from "lucide-react";
|
||||
import { Button } from "./ui/button";
|
||||
import { Input } from "./ui/input";
|
||||
import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "./ui/select";
|
||||
import { Separator } from "./ui/separator";
|
||||
import { Group, GroupSeparator } from "./ui/group";
|
||||
import {
|
||||
@@ -578,7 +579,10 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
const setComposerDraftPrompt = useComposerDraftStore((store) => store.setPrompt);
|
||||
const setComposerDraftProvider = useComposerDraftStore((store) => store.setProvider);
|
||||
const setComposerDraftModel = useComposerDraftStore((store) => store.setModel);
|
||||
const setComposerDraftRuntimeMode = useComposerDraftStore((store) => store.setRuntimeMode);
|
||||
const setComposerDraftInteractionMode = useComposerDraftStore((store) => store.setInteractionMode);
|
||||
const setComposerDraftEffort = useComposerDraftStore((store) => store.setEffort);
|
||||
const setComposerDraftCodexFastMode = useComposerDraftStore((store) => store.setCodexFastMode);
|
||||
const addComposerDraftImage = useComposerDraftStore((store) => store.addImage);
|
||||
const addComposerDraftImages = useComposerDraftStore((store) => store.addImages);
|
||||
const removeComposerDraftImage = useComposerDraftStore((store) => store.removeImage);
|
||||
@@ -711,12 +715,9 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
[draftThread, fallbackDraftProject?.model, localDraftError, threadId],
|
||||
);
|
||||
const activeThread = serverThread ?? localDraftThread;
|
||||
const runtimeMode = activeThread?.runtimeMode ?? DEFAULT_RUNTIME_MODE;
|
||||
const interactionMode = activeThread?.interactionMode ?? DEFAULT_INTERACTION_MODE;
|
||||
const [optimisticRuntimeMode, setOptimisticRuntimeMode] = useOptimistic(runtimeMode);
|
||||
const [optimisticInteractionMode, setOptimisticInteractionMode] = useOptimistic(interactionMode);
|
||||
const [isRuntimeModePending, startRuntimeModeTransition] = useTransition();
|
||||
const [isInteractionModePending, startInteractionModeTransition] = useTransition();
|
||||
const runtimeMode = composerDraft.runtimeMode ?? activeThread?.runtimeMode ?? DEFAULT_RUNTIME_MODE;
|
||||
const interactionMode =
|
||||
composerDraft.interactionMode ?? activeThread?.interactionMode ?? DEFAULT_INTERACTION_MODE;
|
||||
const isServerThread = serverThread !== undefined;
|
||||
const isLocalDraftThread = !isServerThread && localDraftThread !== undefined;
|
||||
const diffSearch = useMemo(
|
||||
@@ -794,9 +795,21 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
|
||||
return resolveModelSlugForProvider(selectedProvider, draftModel);
|
||||
}, [baseThreadModel, composerDraft.model, selectedProvider, settings]);
|
||||
const selectedEffort = composerDraft.effort ?? getDefaultReasoningEffort(selectedProvider);
|
||||
const reasoningOptions = getReasoningEffortOptions(selectedProvider);
|
||||
const supportsReasoningEffort = reasoningOptions.length > 0;
|
||||
const selectedEffort = composerDraft.effort ?? getDefaultReasoningEffort(selectedProvider);
|
||||
const selectedCodexFastModeEnabled =
|
||||
selectedProvider === "codex" ? composerDraft.codexFastMode : false;
|
||||
const selectedModelOptionsForDispatch = useMemo(() => {
|
||||
if (selectedProvider !== "codex") {
|
||||
return undefined;
|
||||
}
|
||||
const codexOptions = {
|
||||
...(supportsReasoningEffort && selectedEffort ? { reasoningEffort: selectedEffort } : {}),
|
||||
...(selectedCodexFastModeEnabled ? { fastMode: true } : {}),
|
||||
};
|
||||
return Object.keys(codexOptions).length > 0 ? { codex: codexOptions } : undefined;
|
||||
}, [selectedCodexFastModeEnabled, selectedEffort, selectedProvider, supportsReasoningEffort]);
|
||||
const selectedCursorModel = useMemo(
|
||||
() => (selectedProvider === "cursor" ? parseCursorModelSelection(selectedModel) : null),
|
||||
[selectedModel, selectedProvider],
|
||||
@@ -920,7 +933,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
);
|
||||
const showPlanFollowUpPrompt =
|
||||
pendingUserInputs.length === 0 &&
|
||||
optimisticInteractionMode === "plan" &&
|
||||
interactionMode === "plan" &&
|
||||
latestTurnSettled &&
|
||||
activeProposedPlan !== null;
|
||||
const hasComposerHeader =
|
||||
@@ -1592,65 +1605,92 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
[activeProject, persistProjectScripts],
|
||||
);
|
||||
|
||||
const handleRuntimeModeChange = async (mode: "approval-required" | "full-access") => {
|
||||
if (mode === runtimeMode) return;
|
||||
if (isLocalDraftThread) {
|
||||
setDraftThreadContext(threadId, { runtimeMode: mode });
|
||||
const handleRuntimeModeChange = useCallback(
|
||||
(mode: RuntimeMode) => {
|
||||
if (mode === runtimeMode) return;
|
||||
setComposerDraftRuntimeMode(threadId, mode);
|
||||
if (isLocalDraftThread) {
|
||||
setDraftThreadContext(threadId, { runtimeMode: mode });
|
||||
}
|
||||
scheduleComposerFocus();
|
||||
return;
|
||||
}
|
||||
const api = readNativeApi();
|
||||
if (!api || !isServerThread) return;
|
||||
scheduleComposerFocus();
|
||||
startRuntimeModeTransition(() => {
|
||||
setOptimisticRuntimeMode(mode);
|
||||
void api.orchestration
|
||||
.dispatchCommand({
|
||||
type: "thread.runtime-mode.set",
|
||||
commandId: newCommandId(),
|
||||
threadId,
|
||||
runtimeMode: mode,
|
||||
createdAt: new Date().toISOString(),
|
||||
})
|
||||
.catch(() => undefined);
|
||||
});
|
||||
};
|
||||
},
|
||||
[
|
||||
isLocalDraftThread,
|
||||
runtimeMode,
|
||||
scheduleComposerFocus,
|
||||
setComposerDraftRuntimeMode,
|
||||
setDraftThreadContext,
|
||||
threadId,
|
||||
],
|
||||
);
|
||||
|
||||
const handleInteractionModeChange = useCallback(
|
||||
async (mode: "default" | "plan") => {
|
||||
(mode: ProviderInteractionMode) => {
|
||||
if (mode === interactionMode) return;
|
||||
setComposerDraftInteractionMode(threadId, mode);
|
||||
if (isLocalDraftThread) {
|
||||
setDraftThreadContext(threadId, { interactionMode: mode });
|
||||
scheduleComposerFocus();
|
||||
return;
|
||||
}
|
||||
const api = readNativeApi();
|
||||
if (!api || !isServerThread) return;
|
||||
scheduleComposerFocus();
|
||||
startInteractionModeTransition(() => {
|
||||
setOptimisticInteractionMode(mode);
|
||||
void api.orchestration
|
||||
.dispatchCommand({
|
||||
type: "thread.interaction-mode.set",
|
||||
commandId: newCommandId(),
|
||||
threadId,
|
||||
interactionMode: mode,
|
||||
createdAt: new Date().toISOString(),
|
||||
})
|
||||
.catch(() => undefined);
|
||||
});
|
||||
},
|
||||
[
|
||||
interactionMode,
|
||||
isLocalDraftThread,
|
||||
isServerThread,
|
||||
scheduleComposerFocus,
|
||||
setComposerDraftInteractionMode,
|
||||
setDraftThreadContext,
|
||||
setOptimisticInteractionMode,
|
||||
threadId,
|
||||
],
|
||||
);
|
||||
|
||||
const persistThreadSettingsForNextTurn = useCallback(
|
||||
async (input: {
|
||||
threadId: ThreadId;
|
||||
createdAt: string;
|
||||
model?: string;
|
||||
runtimeMode: RuntimeMode;
|
||||
interactionMode: ProviderInteractionMode;
|
||||
}) => {
|
||||
if (!serverThread) {
|
||||
return;
|
||||
}
|
||||
const api = readNativeApi();
|
||||
if (!api) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (input.model !== undefined && input.model !== serverThread.model) {
|
||||
await api.orchestration.dispatchCommand({
|
||||
type: "thread.meta.update",
|
||||
commandId: newCommandId(),
|
||||
threadId: input.threadId,
|
||||
model: input.model,
|
||||
});
|
||||
}
|
||||
|
||||
if (input.runtimeMode !== serverThread.runtimeMode) {
|
||||
await api.orchestration.dispatchCommand({
|
||||
type: "thread.runtime-mode.set",
|
||||
commandId: newCommandId(),
|
||||
threadId: input.threadId,
|
||||
runtimeMode: input.runtimeMode,
|
||||
createdAt: input.createdAt,
|
||||
});
|
||||
}
|
||||
|
||||
if (input.interactionMode !== serverThread.interactionMode) {
|
||||
await api.orchestration.dispatchCommand({
|
||||
type: "thread.interaction-mode.set",
|
||||
commandId: newCommandId(),
|
||||
threadId: input.threadId,
|
||||
interactionMode: input.interactionMode,
|
||||
createdAt: input.createdAt,
|
||||
});
|
||||
}
|
||||
},
|
||||
[serverThread],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
try {
|
||||
if (Object.keys(lastInvokedScriptByProjectId).length === 0) {
|
||||
@@ -2519,6 +2559,16 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
});
|
||||
}
|
||||
|
||||
if (isServerThread) {
|
||||
await persistThreadSettingsForNextTurn({
|
||||
threadId: threadIdForSend,
|
||||
createdAt: messageCreatedAt,
|
||||
...(selectedModel ? { model: selectedModel } : {}),
|
||||
runtimeMode,
|
||||
interactionMode,
|
||||
});
|
||||
}
|
||||
|
||||
setSendPhase("sending-turn");
|
||||
const turnAttachments = await turnAttachmentsPromise;
|
||||
await api.orchestration.dispatchCommand({
|
||||
@@ -2532,8 +2582,10 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
attachments: turnAttachments,
|
||||
},
|
||||
model: selectedModel || undefined,
|
||||
...(selectedModelOptionsForDispatch
|
||||
? { modelOptions: selectedModelOptionsForDispatch }
|
||||
: {}),
|
||||
provider: selectedProvider,
|
||||
...(supportsReasoningEffort && selectedEffort ? { effort: selectedEffort } : {}),
|
||||
assistantDeliveryMode: settings.enableAssistantStreaming ? "streaming" : "buffered",
|
||||
runtimeMode,
|
||||
interactionMode,
|
||||
@@ -2781,16 +2833,13 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
forceStickToBottom();
|
||||
|
||||
try {
|
||||
if (nextInteractionMode !== interactionMode) {
|
||||
setOptimisticInteractionMode(nextInteractionMode);
|
||||
await api.orchestration.dispatchCommand({
|
||||
type: "thread.interaction-mode.set",
|
||||
commandId: newCommandId(),
|
||||
threadId: threadIdForSend,
|
||||
interactionMode: nextInteractionMode,
|
||||
createdAt: messageCreatedAt,
|
||||
});
|
||||
}
|
||||
await persistThreadSettingsForNextTurn({
|
||||
threadId: threadIdForSend,
|
||||
createdAt: messageCreatedAt,
|
||||
...(selectedModel ? { model: selectedModel } : {}),
|
||||
runtimeMode,
|
||||
interactionMode: nextInteractionMode,
|
||||
});
|
||||
|
||||
await api.orchestration.dispatchCommand({
|
||||
type: "thread.turn.start",
|
||||
@@ -2804,7 +2853,9 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
},
|
||||
provider: selectedProvider,
|
||||
model: selectedModel || undefined,
|
||||
...(supportsReasoningEffort && selectedEffort ? { effort: selectedEffort } : {}),
|
||||
...(selectedModelOptionsForDispatch
|
||||
? { modelOptions: selectedModelOptionsForDispatch }
|
||||
: {}),
|
||||
assistantDeliveryMode: settings.enableAssistantStreaming ? "streaming" : "buffered",
|
||||
runtimeMode,
|
||||
interactionMode: nextInteractionMode,
|
||||
@@ -2816,9 +2867,6 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
setOptimisticUserMessages((existing) =>
|
||||
existing.filter((message) => message.id !== messageIdForSend),
|
||||
);
|
||||
if (nextInteractionMode !== interactionMode) {
|
||||
setOptimisticInteractionMode(interactionMode);
|
||||
}
|
||||
setThreadError(
|
||||
threadIdForSend,
|
||||
err instanceof Error ? err.message : "Failed to send plan follow-up.",
|
||||
@@ -2830,18 +2878,16 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
[
|
||||
activeThread,
|
||||
forceStickToBottom,
|
||||
interactionMode,
|
||||
isConnecting,
|
||||
isSendBusy,
|
||||
isServerThread,
|
||||
persistThreadSettingsForNextTurn,
|
||||
runtimeMode,
|
||||
selectedEffort,
|
||||
selectedModel,
|
||||
selectedModelOptionsForDispatch,
|
||||
selectedProvider,
|
||||
setOptimisticInteractionMode,
|
||||
setThreadError,
|
||||
settings.enableAssistantStreaming,
|
||||
supportsReasoningEffort,
|
||||
],
|
||||
);
|
||||
|
||||
@@ -2905,7 +2951,9 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
},
|
||||
provider: selectedProvider,
|
||||
model: selectedModel || undefined,
|
||||
...(supportsReasoningEffort && selectedEffort ? { effort: selectedEffort } : {}),
|
||||
...(selectedModelOptionsForDispatch
|
||||
? { modelOptions: selectedModelOptionsForDispatch }
|
||||
: {}),
|
||||
assistantDeliveryMode: settings.enableAssistantStreaming ? "streaming" : "buffered",
|
||||
runtimeMode,
|
||||
interactionMode: "default",
|
||||
@@ -2951,11 +2999,10 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
isServerThread,
|
||||
navigate,
|
||||
runtimeMode,
|
||||
selectedEffort,
|
||||
selectedModel,
|
||||
selectedModelOptionsForDispatch,
|
||||
selectedProvider,
|
||||
settings.enableAssistantStreaming,
|
||||
supportsReasoningEffort,
|
||||
syncServerReadModel,
|
||||
]);
|
||||
|
||||
@@ -2970,27 +3017,17 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
scheduleComposerFocus();
|
||||
return;
|
||||
}
|
||||
const api = readNativeApi();
|
||||
const resolvedModel =
|
||||
provider === "cursor"
|
||||
? resolveCursorModelFromSelection(parseCursorModelSelection(model))
|
||||
: resolveModelSlugForProvider(provider, model);
|
||||
setComposerDraftProvider(activeThread.id, provider);
|
||||
setComposerDraftModel(activeThread.id, resolvedModel);
|
||||
if (api && isServerThread) {
|
||||
void api.orchestration.dispatchCommand({
|
||||
type: "thread.meta.update",
|
||||
commandId: newCommandId(),
|
||||
threadId: activeThread.id,
|
||||
model: resolvedModel,
|
||||
});
|
||||
}
|
||||
scheduleComposerFocus();
|
||||
},
|
||||
[
|
||||
activeThread,
|
||||
cursorModelSelectionLockedReason,
|
||||
isServerThread,
|
||||
lockedProvider,
|
||||
scheduleComposerFocus,
|
||||
setComposerDraftModel,
|
||||
@@ -3046,6 +3083,13 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
},
|
||||
[scheduleComposerFocus, setComposerDraftEffort, threadId],
|
||||
);
|
||||
const onCodexFastModeChange = useCallback(
|
||||
(enabled: boolean) => {
|
||||
setComposerDraftCodexFastMode(threadId, enabled);
|
||||
scheduleComposerFocus();
|
||||
},
|
||||
[scheduleComposerFocus, setComposerDraftCodexFastMode, threadId],
|
||||
);
|
||||
const onEnvModeChange = useCallback(
|
||||
(mode: DraftThreadEnvMode) => {
|
||||
if (isLocalDraftThread) {
|
||||
@@ -3625,19 +3669,16 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
) : supportsReasoningEffort ? (
|
||||
) : selectedProvider === "codex" && selectedEffort != null ? (
|
||||
<>
|
||||
{/* Divider */}
|
||||
<Separator orientation="vertical" className="mx-0.5 hidden h-4 sm:block" />
|
||||
|
||||
{/* Reasoning effort */}
|
||||
{selectedEffort != null && (
|
||||
<ReasoningEffortPicker
|
||||
effort={selectedEffort}
|
||||
options={reasoningOptions}
|
||||
onEffortChange={onEffortSelect}
|
||||
/>
|
||||
)}
|
||||
<CodexTraitsPicker
|
||||
effort={selectedEffort}
|
||||
fastModeEnabled={selectedCodexFastModeEnabled}
|
||||
options={reasoningOptions}
|
||||
onEffortChange={onEffortSelect}
|
||||
onFastModeChange={onCodexFastModeChange}
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
|
||||
@@ -3650,21 +3691,20 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
className="shrink-0 whitespace-nowrap px-2 text-muted-foreground/70 hover:text-foreground/80 sm:px-3"
|
||||
size="sm"
|
||||
type="button"
|
||||
disabled={isInteractionModePending}
|
||||
onClick={() =>
|
||||
void handleInteractionModeChange(
|
||||
optimisticInteractionMode === "plan" ? "default" : "plan",
|
||||
interactionMode === "plan" ? "default" : "plan",
|
||||
)
|
||||
}
|
||||
title={
|
||||
optimisticInteractionMode === "plan"
|
||||
interactionMode === "plan"
|
||||
? "Plan mode — click to return to normal chat mode"
|
||||
: "Default mode — click to enter plan mode"
|
||||
}
|
||||
>
|
||||
<BotIcon />
|
||||
<span className="sr-only sm:not-sr-only">
|
||||
{optimisticInteractionMode === "plan" ? "Plan" : "Chat"}
|
||||
{interactionMode === "plan" ? "Plan" : "Chat"}
|
||||
</span>
|
||||
</Button>
|
||||
|
||||
@@ -3677,21 +3717,20 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
className="shrink-0 whitespace-nowrap px-2 text-muted-foreground/70 hover:text-foreground/80 sm:px-3"
|
||||
size="sm"
|
||||
type="button"
|
||||
disabled={isRuntimeModePending}
|
||||
onClick={() =>
|
||||
void handleRuntimeModeChange(
|
||||
optimisticRuntimeMode === "full-access" ? "approval-required" : "full-access",
|
||||
runtimeMode === "full-access" ? "approval-required" : "full-access",
|
||||
)
|
||||
}
|
||||
title={
|
||||
optimisticRuntimeMode === "full-access"
|
||||
runtimeMode === "full-access"
|
||||
? "Full access — click to require approvals"
|
||||
: "Approval required — click for full access"
|
||||
}
|
||||
>
|
||||
{optimisticRuntimeMode === "full-access" ? <LockOpenIcon /> : <LockIcon />}
|
||||
{runtimeMode === "full-access" ? <LockOpenIcon /> : <LockIcon />}
|
||||
<span className="sr-only sm:not-sr-only">
|
||||
{optimisticRuntimeMode === "full-access" ? "Full access" : "Supervised"}
|
||||
{runtimeMode === "full-access" ? "Full access" : "Supervised"}
|
||||
</span>
|
||||
</Button>
|
||||
</div>
|
||||
@@ -4397,7 +4436,10 @@ const ChangedFilesTree = memo(function ChangedFilesTree(props: {
|
||||
}) {
|
||||
const { files, allDirectoriesExpanded, onOpenTurnDiff, resolvedTheme, turnId } = props;
|
||||
const treeNodes = useMemo(() => buildTurnDiffTree(files), [files]);
|
||||
const directoryPathsKey = useMemo(() => collectDirectoryPaths(treeNodes).join("\u0000"), [treeNodes]);
|
||||
const directoryPathsKey = useMemo(
|
||||
() => collectDirectoryPaths(treeNodes).join("\u0000"),
|
||||
[treeNodes],
|
||||
);
|
||||
const allDirectoryExpansionState = useMemo(
|
||||
() =>
|
||||
buildDirectoryExpansionState(
|
||||
@@ -4406,8 +4448,8 @@ const ChangedFilesTree = memo(function ChangedFilesTree(props: {
|
||||
),
|
||||
[allDirectoriesExpanded, directoryPathsKey],
|
||||
);
|
||||
const [expandedDirectories, setExpandedDirectories] = useState<Record<string, boolean>>(
|
||||
() => buildDirectoryExpansionState((directoryPathsKey ? directoryPathsKey.split("\u0000") : []), true),
|
||||
const [expandedDirectories, setExpandedDirectories] = useState<Record<string, boolean>>(() =>
|
||||
buildDirectoryExpansionState(directoryPathsKey ? directoryPathsKey.split("\u0000") : [], true),
|
||||
);
|
||||
useEffect(() => {
|
||||
setExpandedDirectories(allDirectoryExpansionState);
|
||||
@@ -4489,11 +4531,7 @@ const ChangedFilesTree = memo(function ChangedFilesTree(props: {
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-0.5">
|
||||
{treeNodes.map((node) => renderTreeNode(node, 0))}
|
||||
</div>
|
||||
);
|
||||
return <div className="space-y-0.5">{treeNodes.map((node) => renderTreeNode(node, 0))}</div>;
|
||||
});
|
||||
|
||||
const ProposedPlanCard = memo(function ProposedPlanCard({
|
||||
@@ -5337,7 +5375,7 @@ const ProviderModelPicker = memo(function ProviderModelPicker(props: {
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="shrink-0 whitespace-nowrap px-2 sm:px-3"
|
||||
className="shrink-0 whitespace-nowrap px-2 text-muted-foreground/70 hover:text-foreground/80 sm:px-3"
|
||||
disabled={props.disabled}
|
||||
/>
|
||||
}
|
||||
@@ -5347,7 +5385,7 @@ const ProviderModelPicker = memo(function ProviderModelPicker(props: {
|
||||
aria-hidden="true"
|
||||
className={cn(
|
||||
"size-4 shrink-0",
|
||||
props.provider === "claudeCode" ? "" : "text-foreground/80",
|
||||
props.provider === "claudeCode" ? "" : "text-muted-foreground/70",
|
||||
)}
|
||||
/>
|
||||
<span className="truncate">{selectedModelLabel}</span>
|
||||
@@ -5419,30 +5457,82 @@ const ProviderModelPicker = memo(function ProviderModelPicker(props: {
|
||||
);
|
||||
});
|
||||
|
||||
const ReasoningEffortPicker = memo(function ReasoningEffortPicker(props: {
|
||||
const CodexTraitsPicker = memo(function CodexTraitsPicker(props: {
|
||||
effort: CodexReasoningEffort;
|
||||
fastModeEnabled: boolean;
|
||||
options: ReadonlyArray<CodexReasoningEffort>;
|
||||
onEffortChange: (effort: CodexReasoningEffort) => void;
|
||||
onFastModeChange: (enabled: boolean) => void;
|
||||
}) {
|
||||
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
||||
const defaultReasoningEffort = getDefaultReasoningEffort("codex");
|
||||
const reasoningLabelByOption: Record<CodexReasoningEffort, string> = {
|
||||
low: "Low",
|
||||
medium: "Medium",
|
||||
high: "High",
|
||||
xhigh: "Extra High",
|
||||
};
|
||||
const triggerLabel = [
|
||||
reasoningLabelByOption[props.effort],
|
||||
...(props.fastModeEnabled ? ["Fast"] : []),
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(" · ");
|
||||
|
||||
return (
|
||||
<Select
|
||||
value={props.effort}
|
||||
onValueChange={(value) => (value ? props.onEffortChange(value) : undefined)}
|
||||
<Menu
|
||||
open={isMenuOpen}
|
||||
onOpenChange={(open) => {
|
||||
setIsMenuOpen(open);
|
||||
}}
|
||||
>
|
||||
<SelectTrigger variant="ghost" size="sm">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectPopup alignItemWithTrigger={false}>
|
||||
{props.options.map((effort) => (
|
||||
<SelectItem key={effort} value={effort}>
|
||||
{effort}
|
||||
{effort === defaultReasoningEffort ? " (default)" : ""}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectPopup>
|
||||
</Select>
|
||||
<MenuTrigger
|
||||
render={
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="shrink-0 whitespace-nowrap px-2 text-muted-foreground/70 hover:text-foreground/80 sm:px-3"
|
||||
/>
|
||||
}
|
||||
>
|
||||
<span>{triggerLabel}</span>
|
||||
<ChevronDownIcon aria-hidden="true" className="size-3 opacity-60" />
|
||||
</MenuTrigger>
|
||||
<MenuPopup align="start">
|
||||
<MenuGroup>
|
||||
<div className="px-2 py-1.5 font-medium text-muted-foreground text-xs">Reasoning</div>
|
||||
<MenuRadioGroup
|
||||
value={props.effort}
|
||||
onValueChange={(value) => {
|
||||
if (!value) return;
|
||||
const nextEffort = props.options.find((option) => option === value);
|
||||
if (!nextEffort) return;
|
||||
props.onEffortChange(nextEffort);
|
||||
}}
|
||||
>
|
||||
{props.options.map((effort) => (
|
||||
<MenuRadioItem key={effort} value={effort}>
|
||||
{reasoningLabelByOption[effort]}
|
||||
{effort === defaultReasoningEffort ? " (default)" : ""}
|
||||
</MenuRadioItem>
|
||||
))}
|
||||
</MenuRadioGroup>
|
||||
</MenuGroup>
|
||||
<MenuDivider />
|
||||
<MenuGroup>
|
||||
<div className="px-2 py-1.5 font-medium text-muted-foreground text-xs">Fast Mode</div>
|
||||
<MenuRadioGroup
|
||||
value={props.fastModeEnabled ? "on" : "off"}
|
||||
onValueChange={(value) => {
|
||||
props.onFastModeChange(value === "on");
|
||||
}}
|
||||
>
|
||||
<MenuRadioItem value="off">off</MenuRadioItem>
|
||||
<MenuRadioItem value="on">on</MenuRadioItem>
|
||||
</MenuRadioGroup>
|
||||
</MenuGroup>
|
||||
</MenuPopup>
|
||||
</Menu>
|
||||
);
|
||||
});
|
||||
|
||||
@@ -5459,7 +5549,7 @@ const CursorTraitsPicker = memo(function CursorTraitsPicker(props: {
|
||||
low: "Low",
|
||||
normal: "Normal",
|
||||
high: "High",
|
||||
xhigh: "XHigh",
|
||||
xhigh: "Extra High",
|
||||
};
|
||||
const traitSummary = [
|
||||
...(props.capabilities.supportsReasoning
|
||||
@@ -5486,7 +5576,7 @@ const CursorTraitsPicker = memo(function CursorTraitsPicker(props: {
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="shrink-0 whitespace-nowrap px-2 sm:px-3"
|
||||
className="shrink-0 whitespace-nowrap px-2 text-muted-foreground/70 hover:text-foreground/80 sm:px-3"
|
||||
disabled={props.disabled}
|
||||
/>
|
||||
}
|
||||
|
||||
@@ -184,6 +184,8 @@ describe("composerDraftStore project draft thread mapping", () => {
|
||||
branch: "feature/test",
|
||||
worktreePath: "/tmp/worktree-test",
|
||||
envMode: "worktree",
|
||||
runtimeMode: "full-access",
|
||||
interactionMode: "default",
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
expect(useComposerDraftStore.getState().getDraftThread(threadId)).toEqual({
|
||||
@@ -191,6 +193,8 @@ describe("composerDraftStore project draft thread mapping", () => {
|
||||
branch: "feature/test",
|
||||
worktreePath: "/tmp/worktree-test",
|
||||
envMode: "worktree",
|
||||
runtimeMode: "full-access",
|
||||
interactionMode: "default",
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
});
|
||||
@@ -329,6 +333,33 @@ describe("composerDraftStore project draft thread mapping", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("composerDraftStore codex fast mode", () => {
|
||||
const threadId = ThreadId.makeUnsafe("thread-service-tier");
|
||||
|
||||
beforeEach(() => {
|
||||
useComposerDraftStore.setState({
|
||||
draftsByThreadId: {},
|
||||
draftThreadsByThreadId: {},
|
||||
projectDraftThreadIdByProjectId: {},
|
||||
});
|
||||
});
|
||||
|
||||
it("stores codex fast mode in the draft", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
store.setCodexFastMode(threadId, true);
|
||||
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]?.codexFastMode).toBe(true);
|
||||
});
|
||||
|
||||
it("clears codex fast mode when reset to the default", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
store.setCodexFastMode(threadId, true);
|
||||
store.setCodexFastMode(threadId, false);
|
||||
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("composerDraftStore setModel", () => {
|
||||
const threadId = ThreadId.makeUnsafe("thread-model");
|
||||
|
||||
@@ -377,3 +408,46 @@ describe("composerDraftStore setProvider", () => {
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("composerDraftStore runtime and interaction settings", () => {
|
||||
const threadId = ThreadId.makeUnsafe("thread-settings");
|
||||
|
||||
beforeEach(() => {
|
||||
useComposerDraftStore.setState({
|
||||
draftsByThreadId: {},
|
||||
draftThreadsByThreadId: {},
|
||||
projectDraftThreadIdByProjectId: {},
|
||||
});
|
||||
});
|
||||
|
||||
it("stores runtime mode overrides in the composer draft", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
|
||||
store.setRuntimeMode(threadId, "approval-required");
|
||||
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]?.runtimeMode).toBe(
|
||||
"approval-required",
|
||||
);
|
||||
});
|
||||
|
||||
it("stores interaction mode overrides in the composer draft", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
|
||||
store.setInteractionMode(threadId, "plan");
|
||||
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]?.interactionMode).toBe(
|
||||
"plan",
|
||||
);
|
||||
});
|
||||
|
||||
it("removes empty settings-only drafts when overrides are cleared", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
|
||||
store.setRuntimeMode(threadId, "approval-required");
|
||||
store.setInteractionMode(threadId, "plan");
|
||||
store.setRuntimeMode(threadId, null);
|
||||
store.setInteractionMode(threadId, null);
|
||||
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -3,12 +3,12 @@ import {
|
||||
ProjectId,
|
||||
REASONING_EFFORT_OPTIONS_BY_PROVIDER,
|
||||
ThreadId,
|
||||
normalizeModelSlug,
|
||||
type CodexReasoningEffort,
|
||||
type ProviderKind,
|
||||
type ProviderInteractionMode,
|
||||
type RuntimeMode,
|
||||
} from "@t3tools/contracts";
|
||||
import { normalizeModelSlug } from "@t3tools/shared/model";
|
||||
import {
|
||||
DEFAULT_INTERACTION_MODE,
|
||||
DEFAULT_RUNTIME_MODE,
|
||||
@@ -38,7 +38,11 @@ interface PersistedComposerThreadDraftState {
|
||||
attachments: PersistedComposerImageAttachment[];
|
||||
provider?: ProviderKind | null;
|
||||
model?: string | null;
|
||||
runtimeMode?: RuntimeMode | null;
|
||||
interactionMode?: ProviderInteractionMode | null;
|
||||
effort?: CodexReasoningEffort | null;
|
||||
codexFastMode?: boolean | null;
|
||||
serviceTier?: string | null;
|
||||
}
|
||||
|
||||
interface PersistedDraftThreadState {
|
||||
@@ -64,7 +68,10 @@ interface ComposerThreadDraftState {
|
||||
persistedAttachments: PersistedComposerImageAttachment[];
|
||||
provider: ProviderKind | null;
|
||||
model: string | null;
|
||||
runtimeMode: RuntimeMode | null;
|
||||
interactionMode: ProviderInteractionMode | null;
|
||||
effort: CodexReasoningEffort | null;
|
||||
codexFastMode: boolean;
|
||||
}
|
||||
|
||||
export interface DraftThreadState {
|
||||
@@ -117,7 +124,13 @@ interface ComposerDraftStoreState {
|
||||
setPrompt: (threadId: ThreadId, prompt: string) => void;
|
||||
setProvider: (threadId: ThreadId, provider: ProviderKind | null | undefined) => void;
|
||||
setModel: (threadId: ThreadId, model: string | null | undefined) => void;
|
||||
setRuntimeMode: (threadId: ThreadId, runtimeMode: RuntimeMode | null | undefined) => void;
|
||||
setInteractionMode: (
|
||||
threadId: ThreadId,
|
||||
interactionMode: ProviderInteractionMode | null | undefined,
|
||||
) => void;
|
||||
setEffort: (threadId: ThreadId, effort: CodexReasoningEffort | null | undefined) => void;
|
||||
setCodexFastMode: (threadId: ThreadId, enabled: boolean | null | undefined) => void;
|
||||
addImage: (threadId: ThreadId, image: ComposerImageAttachment) => void;
|
||||
addImages: (threadId: ThreadId, images: ComposerImageAttachment[]) => void;
|
||||
removeImage: (threadId: ThreadId, imageId: string) => void;
|
||||
@@ -149,7 +162,10 @@ const EMPTY_THREAD_DRAFT = Object.freeze({
|
||||
persistedAttachments: EMPTY_PERSISTED_ATTACHMENTS,
|
||||
provider: null,
|
||||
model: null,
|
||||
runtimeMode: null,
|
||||
interactionMode: null,
|
||||
effort: null,
|
||||
codexFastMode: false,
|
||||
}) as ComposerThreadDraftState;
|
||||
|
||||
const REASONING_EFFORT_VALUES = new Set<CodexReasoningEffort>(
|
||||
@@ -164,7 +180,10 @@ function createEmptyThreadDraft(): ComposerThreadDraftState {
|
||||
persistedAttachments: [],
|
||||
provider: null,
|
||||
model: null,
|
||||
runtimeMode: null,
|
||||
interactionMode: null,
|
||||
effort: null,
|
||||
codexFastMode: false,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -181,7 +200,10 @@ function shouldRemoveDraft(draft: ComposerThreadDraftState): boolean {
|
||||
draft.persistedAttachments.length === 0 &&
|
||||
draft.provider === null &&
|
||||
draft.model === null &&
|
||||
draft.effort === null
|
||||
draft.runtimeMode === null &&
|
||||
draft.interactionMode === null &&
|
||||
draft.effort === null &&
|
||||
draft.codexFastMode === false
|
||||
);
|
||||
}
|
||||
|
||||
@@ -349,13 +371,34 @@ function normalizePersistedComposerDraftState(value: unknown): PersistedComposer
|
||||
typeof draftCandidate.model === "string"
|
||||
? normalizeModelSlug(draftCandidate.model, provider ?? "codex")
|
||||
: null;
|
||||
const runtimeMode =
|
||||
draftCandidate.runtimeMode === "approval-required" ||
|
||||
draftCandidate.runtimeMode === "full-access"
|
||||
? draftCandidate.runtimeMode
|
||||
: null;
|
||||
const interactionMode =
|
||||
draftCandidate.interactionMode === "plan" || draftCandidate.interactionMode === "default"
|
||||
? draftCandidate.interactionMode
|
||||
: null;
|
||||
const effortCandidate =
|
||||
typeof draftCandidate.effort === "string" ? draftCandidate.effort : null;
|
||||
const effort =
|
||||
effortCandidate && REASONING_EFFORT_VALUES.has(effortCandidate as CodexReasoningEffort)
|
||||
? (effortCandidate as CodexReasoningEffort)
|
||||
: null;
|
||||
if (prompt.length === 0 && attachments.length === 0 && !provider && !model && !effort) {
|
||||
const codexFastMode =
|
||||
draftCandidate.codexFastMode === true ||
|
||||
(typeof draftCandidate.serviceTier === "string" && draftCandidate.serviceTier === "fast");
|
||||
if (
|
||||
prompt.length === 0 &&
|
||||
attachments.length === 0 &&
|
||||
!provider &&
|
||||
!model &&
|
||||
!runtimeMode &&
|
||||
!interactionMode &&
|
||||
!effort &&
|
||||
!codexFastMode
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
nextDraftsByThreadId[threadId as ThreadId] = {
|
||||
@@ -363,7 +406,10 @@ function normalizePersistedComposerDraftState(value: unknown): PersistedComposer
|
||||
attachments,
|
||||
...(provider ? { provider } : {}),
|
||||
...(model ? { model } : {}),
|
||||
...(runtimeMode ? { runtimeMode } : {}),
|
||||
...(interactionMode ? { interactionMode } : {}),
|
||||
...(effort ? { effort } : {}),
|
||||
...(codexFastMode ? { codexFastMode } : {}),
|
||||
};
|
||||
}
|
||||
return {
|
||||
@@ -467,7 +513,10 @@ function toHydratedThreadDraft(
|
||||
persistedAttachments: persistedDraft.attachments,
|
||||
provider: persistedDraft.provider ?? null,
|
||||
model: persistedDraft.model ?? null,
|
||||
runtimeMode: persistedDraft.runtimeMode ?? null,
|
||||
interactionMode: persistedDraft.interactionMode ?? null,
|
||||
effort: persistedDraft.effort ?? null,
|
||||
codexFastMode: persistedDraft.codexFastMode === true,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -783,6 +832,62 @@ export const useComposerDraftStore = create<ComposerDraftStoreState>()(
|
||||
return { draftsByThreadId: nextDraftsByThreadId };
|
||||
});
|
||||
},
|
||||
setRuntimeMode: (threadId, runtimeMode) => {
|
||||
if (threadId.length === 0) {
|
||||
return;
|
||||
}
|
||||
const nextRuntimeMode =
|
||||
runtimeMode === "approval-required" || runtimeMode === "full-access" ? runtimeMode : null;
|
||||
set((state) => {
|
||||
const existing = state.draftsByThreadId[threadId];
|
||||
if (!existing && nextRuntimeMode === null) {
|
||||
return state;
|
||||
}
|
||||
const base = existing ?? createEmptyThreadDraft();
|
||||
if (base.runtimeMode === nextRuntimeMode) {
|
||||
return state;
|
||||
}
|
||||
const nextDraft: ComposerThreadDraftState = {
|
||||
...base,
|
||||
runtimeMode: nextRuntimeMode,
|
||||
};
|
||||
const nextDraftsByThreadId = { ...state.draftsByThreadId };
|
||||
if (shouldRemoveDraft(nextDraft)) {
|
||||
delete nextDraftsByThreadId[threadId];
|
||||
} else {
|
||||
nextDraftsByThreadId[threadId] = nextDraft;
|
||||
}
|
||||
return { draftsByThreadId: nextDraftsByThreadId };
|
||||
});
|
||||
},
|
||||
setInteractionMode: (threadId, interactionMode) => {
|
||||
if (threadId.length === 0) {
|
||||
return;
|
||||
}
|
||||
const nextInteractionMode =
|
||||
interactionMode === "plan" || interactionMode === "default" ? interactionMode : null;
|
||||
set((state) => {
|
||||
const existing = state.draftsByThreadId[threadId];
|
||||
if (!existing && nextInteractionMode === null) {
|
||||
return state;
|
||||
}
|
||||
const base = existing ?? createEmptyThreadDraft();
|
||||
if (base.interactionMode === nextInteractionMode) {
|
||||
return state;
|
||||
}
|
||||
const nextDraft: ComposerThreadDraftState = {
|
||||
...base,
|
||||
interactionMode: nextInteractionMode,
|
||||
};
|
||||
const nextDraftsByThreadId = { ...state.draftsByThreadId };
|
||||
if (shouldRemoveDraft(nextDraft)) {
|
||||
delete nextDraftsByThreadId[threadId];
|
||||
} else {
|
||||
nextDraftsByThreadId[threadId] = nextDraft;
|
||||
}
|
||||
return { draftsByThreadId: nextDraftsByThreadId };
|
||||
});
|
||||
},
|
||||
setEffort: (threadId, effort) => {
|
||||
if (threadId.length === 0) {
|
||||
return;
|
||||
@@ -815,6 +920,33 @@ export const useComposerDraftStore = create<ComposerDraftStoreState>()(
|
||||
return { draftsByThreadId: nextDraftsByThreadId };
|
||||
});
|
||||
},
|
||||
setCodexFastMode: (threadId, enabled) => {
|
||||
if (threadId.length === 0) {
|
||||
return;
|
||||
}
|
||||
const nextCodexFastMode = enabled === true;
|
||||
set((state) => {
|
||||
const existing = state.draftsByThreadId[threadId];
|
||||
if (!existing && nextCodexFastMode === false) {
|
||||
return state;
|
||||
}
|
||||
const base = existing ?? createEmptyThreadDraft();
|
||||
if (base.codexFastMode === nextCodexFastMode) {
|
||||
return state;
|
||||
}
|
||||
const nextDraft: ComposerThreadDraftState = {
|
||||
...base,
|
||||
codexFastMode: nextCodexFastMode,
|
||||
};
|
||||
const nextDraftsByThreadId = { ...state.draftsByThreadId };
|
||||
if (shouldRemoveDraft(nextDraft)) {
|
||||
delete nextDraftsByThreadId[threadId];
|
||||
} else {
|
||||
nextDraftsByThreadId[threadId] = nextDraft;
|
||||
}
|
||||
return { draftsByThreadId: nextDraftsByThreadId };
|
||||
});
|
||||
},
|
||||
addImage: (threadId, image) => {
|
||||
if (threadId.length === 0) {
|
||||
return;
|
||||
@@ -1049,7 +1181,10 @@ export const useComposerDraftStore = create<ComposerDraftStoreState>()(
|
||||
draft.persistedAttachments.length === 0 &&
|
||||
draft.provider === null &&
|
||||
draft.model === null &&
|
||||
draft.effort === null
|
||||
draft.runtimeMode === null &&
|
||||
draft.interactionMode === null &&
|
||||
draft.effort === null &&
|
||||
draft.codexFastMode === false
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
@@ -1063,9 +1198,18 @@ export const useComposerDraftStore = create<ComposerDraftStoreState>()(
|
||||
if (draft.provider) {
|
||||
persistedDraft.provider = draft.provider;
|
||||
}
|
||||
if (draft.runtimeMode) {
|
||||
persistedDraft.runtimeMode = draft.runtimeMode;
|
||||
}
|
||||
if (draft.interactionMode) {
|
||||
persistedDraft.interactionMode = draft.interactionMode;
|
||||
}
|
||||
if (draft.effort) {
|
||||
persistedDraft.effort = draft.effort;
|
||||
}
|
||||
if (draft.codexFastMode) {
|
||||
persistedDraft.codexFastMode = true;
|
||||
}
|
||||
persistedDraftsByThreadId[threadId as ThreadId] = persistedDraft;
|
||||
}
|
||||
return {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useCallback, useState } from "react";
|
||||
import { getModelOptions, normalizeModelSlug, type ProviderKind } from "@t3tools/contracts";
|
||||
import { type ProviderKind } from "@t3tools/contracts";
|
||||
import { getModelOptions, normalizeModelSlug } from "@t3tools/shared/model";
|
||||
|
||||
import { MAX_CUSTOM_MODEL_LENGTH, useAppSettings } from "../appSettings";
|
||||
import { isElectron } from "../env";
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
import { Fragment, type ReactNode, createElement, useEffect } from "react";
|
||||
import {
|
||||
DEFAULT_MODEL,
|
||||
getModelOptions,
|
||||
normalizeModelSlug,
|
||||
type ProviderKind,
|
||||
ThreadId,
|
||||
type OrchestrationReadModel,
|
||||
type OrchestrationSessionStatus,
|
||||
} from "@t3tools/contracts";
|
||||
import {
|
||||
getModelOptions,
|
||||
normalizeModelSlug,
|
||||
resolveModelSlug,
|
||||
resolveModelSlugForProvider,
|
||||
} from "@t3tools/contracts";
|
||||
} from "@t3tools/shared/model";
|
||||
import { create } from "zustand";
|
||||
import {
|
||||
type ChatMessage,
|
||||
|
||||
@@ -11,13 +11,13 @@ import type {
|
||||
CheckpointRef,
|
||||
ProviderKind,
|
||||
ProviderInteractionMode,
|
||||
RuntimeMode,
|
||||
} from "@t3tools/contracts";
|
||||
|
||||
export type SessionPhase = "disconnected" | "connecting" | "ready" | "running";
|
||||
export type RuntimeMode = "approval-required" | "full-access";
|
||||
export const DEFAULT_RUNTIME_MODE: RuntimeMode = "full-access";
|
||||
export type InteractionMode = ProviderInteractionMode;
|
||||
export const DEFAULT_INTERACTION_MODE: InteractionMode = "default";
|
||||
|
||||
export const DEFAULT_INTERACTION_MODE: ProviderInteractionMode = "default";
|
||||
export const DEFAULT_THREAD_TERMINAL_HEIGHT = 280;
|
||||
export const DEFAULT_THREAD_TERMINAL_ID = "default";
|
||||
export const MAX_THREAD_TERMINAL_COUNT = 4;
|
||||
@@ -90,7 +90,7 @@ export interface Thread {
|
||||
title: string;
|
||||
model: string;
|
||||
runtimeMode: RuntimeMode;
|
||||
interactionMode: InteractionMode;
|
||||
interactionMode: ProviderInteractionMode;
|
||||
session: ThreadSession | null;
|
||||
messages: ChatMessage[];
|
||||
proposedPlans: ProposedPlan[];
|
||||
|
||||
+35
-269
@@ -1,13 +1,42 @@
|
||||
import { Schema } from "effect";
|
||||
import type { ProviderKind } from "./orchestration";
|
||||
|
||||
export const CURSOR_REASONING_OPTIONS = ["low", "normal", "high", "xhigh"] as const;
|
||||
export type CursorReasoningOption = (typeof CURSOR_REASONING_OPTIONS)[number];
|
||||
|
||||
export const CODEX_REASONING_EFFORT_OPTIONS = ["xhigh", "high", "medium", "low"] as const;
|
||||
export type CodexReasoningEffort = (typeof CODEX_REASONING_EFFORT_OPTIONS)[number];
|
||||
|
||||
export const CodexModelOptions = Schema.Struct({
|
||||
reasoningEffort: Schema.optional(Schema.Literals(CODEX_REASONING_EFFORT_OPTIONS)),
|
||||
fastMode: Schema.optional(Schema.Boolean),
|
||||
});
|
||||
export type CodexModelOptions = typeof CodexModelOptions.Type;
|
||||
|
||||
export const ClaudeCodeModelOptions = Schema.Struct({
|
||||
thinking: Schema.optional(Schema.Boolean),
|
||||
});
|
||||
export type ClaudeCodeModelOptions = typeof ClaudeCodeModelOptions.Type;
|
||||
|
||||
export const CursorModelOptions = Schema.Struct({
|
||||
reasoning: Schema.optional(Schema.Literals(CURSOR_REASONING_OPTIONS)),
|
||||
fastMode: Schema.optional(Schema.Boolean),
|
||||
thinking: Schema.optional(Schema.Boolean),
|
||||
});
|
||||
export type CursorModelOptions = typeof CursorModelOptions.Type;
|
||||
|
||||
export const ProviderModelOptions = Schema.Struct({
|
||||
codex: Schema.optional(CodexModelOptions),
|
||||
claudeCode: Schema.optional(ClaudeCodeModelOptions),
|
||||
cursor: Schema.optional(CursorModelOptions),
|
||||
});
|
||||
export type ProviderModelOptions = typeof ProviderModelOptions.Type;
|
||||
|
||||
type ModelOption = {
|
||||
readonly slug: string;
|
||||
readonly name: string;
|
||||
};
|
||||
|
||||
export const CURSOR_REASONING_OPTIONS = ["low", "normal", "high", "xhigh"] as const;
|
||||
export type CursorReasoningOption = (typeof CURSOR_REASONING_OPTIONS)[number];
|
||||
|
||||
type CursorModelFamilyOption = {
|
||||
readonly slug: string;
|
||||
readonly name: string;
|
||||
@@ -29,14 +58,15 @@ export type CursorModelFamily = (typeof CURSOR_MODEL_FAMILY_OPTIONS)[number]["sl
|
||||
|
||||
export const MODEL_OPTIONS_BY_PROVIDER = {
|
||||
codex: [
|
||||
{ slug: "gpt-5.4", name: "GPT-5.4" },
|
||||
{ slug: "gpt-5.3-codex", name: "GPT-5.3 Codex" },
|
||||
{ slug: "gpt-5.3-codex-spark", name: "GPT-5.3 Codex Spark" },
|
||||
{ slug: "gpt-5.2-codex", name: "GPT-5.2 Codex" },
|
||||
{ slug: "gpt-5.2", name: "GPT-5.2" },
|
||||
],
|
||||
claudeCode: [
|
||||
{ slug: "claude-sonnet-4-6", name: "Claude Sonnet 4.6" },
|
||||
{ slug: "claude-opus-4-6", name: "Claude Opus 4.6" },
|
||||
{ slug: "claude-sonnet-4-6", name: "Claude Sonnet 4.6" },
|
||||
{ slug: "claude-haiku-4-5", name: "Claude Haiku 4.5" },
|
||||
],
|
||||
cursor: [
|
||||
@@ -66,91 +96,6 @@ type BuiltInModelSlug = (typeof MODEL_OPTIONS_BY_PROVIDER)[ProviderKind][number]
|
||||
export type ModelSlug = BuiltInModelSlug | (string & {});
|
||||
export type CursorModelSlug = (typeof MODEL_OPTIONS_BY_PROVIDER)["cursor"][number]["slug"];
|
||||
|
||||
type CursorModelCapability = {
|
||||
readonly supportsReasoning: boolean;
|
||||
readonly supportsFast: boolean;
|
||||
readonly supportsThinking: boolean;
|
||||
readonly defaultReasoning: CursorReasoningOption;
|
||||
readonly defaultThinking: boolean;
|
||||
};
|
||||
|
||||
const CURSOR_MODEL_CAPABILITY_BY_FAMILY: Record<CursorModelFamily, CursorModelCapability> = {
|
||||
auto: {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
supportsThinking: false,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: false,
|
||||
},
|
||||
"composer-1.5": {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
supportsThinking: false,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: false,
|
||||
},
|
||||
"composer-1": {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
supportsThinking: false,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: false,
|
||||
},
|
||||
"gpt-5.3-codex": {
|
||||
supportsReasoning: true,
|
||||
supportsFast: true,
|
||||
supportsThinking: false,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: false,
|
||||
},
|
||||
"gpt-5.3-codex-spark-preview": {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
supportsThinking: false,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: false,
|
||||
},
|
||||
"opus-4.6": {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
supportsThinking: true,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: true,
|
||||
},
|
||||
"opus-4.5": {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
supportsThinking: true,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: true,
|
||||
},
|
||||
"sonnet-4.6": {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
supportsThinking: true,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: true,
|
||||
},
|
||||
"gemini-3.1-pro": {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
supportsThinking: false,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: false,
|
||||
},
|
||||
};
|
||||
|
||||
const CURSOR_MODEL_FAMILY_SET = new Set<CursorModelFamily>(
|
||||
CURSOR_MODEL_FAMILY_OPTIONS.map((option) => option.slug),
|
||||
);
|
||||
|
||||
export interface CursorModelSelection {
|
||||
readonly family: CursorModelFamily;
|
||||
readonly reasoning: CursorReasoningOption;
|
||||
readonly fast: boolean;
|
||||
readonly thinking: boolean;
|
||||
}
|
||||
|
||||
export const DEFAULT_MODEL_BY_PROVIDER: Record<ProviderKind, ModelSlug> = {
|
||||
codex: "gpt-5.3-codex",
|
||||
claudeCode: "claude-sonnet-4-6",
|
||||
@@ -163,6 +108,7 @@ export const DEFAULT_MODEL = DEFAULT_MODEL_BY_PROVIDER.codex;
|
||||
|
||||
export const MODEL_SLUG_ALIASES_BY_PROVIDER: Record<ProviderKind, Record<string, ModelSlug>> = {
|
||||
codex: {
|
||||
"5.4": "gpt-5.4",
|
||||
"5.3": "gpt-5.3-codex",
|
||||
"gpt-5.3": "gpt-5.3-codex",
|
||||
"5.3-spark": "gpt-5.3-codex-spark",
|
||||
@@ -198,172 +144,6 @@ export const MODEL_SLUG_ALIASES_BY_PROVIDER: Record<ProviderKind, Record<string,
|
||||
},
|
||||
};
|
||||
|
||||
const MODEL_SLUG_SET_BY_PROVIDER: Record<ProviderKind, ReadonlySet<ModelSlug>> = {
|
||||
claudeCode: new Set(MODEL_OPTIONS_BY_PROVIDER.claudeCode.map((option) => option.slug)),
|
||||
codex: new Set(MODEL_OPTIONS_BY_PROVIDER.codex.map((option) => option.slug)),
|
||||
cursor: new Set(MODEL_OPTIONS_BY_PROVIDER.cursor.map((option) => option.slug)),
|
||||
};
|
||||
|
||||
export function getModelOptions(provider: ProviderKind = "codex") {
|
||||
return MODEL_OPTIONS_BY_PROVIDER[provider];
|
||||
}
|
||||
|
||||
export function getCursorModelFamilyOptions() {
|
||||
return CURSOR_MODEL_FAMILY_OPTIONS;
|
||||
}
|
||||
|
||||
export function getCursorModelCapabilities(family: CursorModelFamily) {
|
||||
return CURSOR_MODEL_CAPABILITY_BY_FAMILY[family];
|
||||
}
|
||||
|
||||
function fallbackCursorModelFamily(): CursorModelFamily {
|
||||
const fallback = parseCursorModelSelection(DEFAULT_MODEL_BY_PROVIDER.cursor);
|
||||
return fallback.family;
|
||||
}
|
||||
|
||||
function resolveCursorModelFamily(model: string | null | undefined): CursorModelFamily {
|
||||
const normalized = normalizeModelSlug(model, "cursor");
|
||||
if (!normalized) {
|
||||
return fallbackCursorModelFamily();
|
||||
}
|
||||
|
||||
if (
|
||||
normalized === "gpt-5.3-codex" ||
|
||||
normalized === "gpt-5.3-codex-fast" ||
|
||||
normalized === "gpt-5.3-codex-low" ||
|
||||
normalized === "gpt-5.3-codex-low-fast" ||
|
||||
normalized === "gpt-5.3-codex-high" ||
|
||||
normalized === "gpt-5.3-codex-high-fast" ||
|
||||
normalized === "gpt-5.3-codex-xhigh" ||
|
||||
normalized === "gpt-5.3-codex-xhigh-fast"
|
||||
) {
|
||||
return "gpt-5.3-codex";
|
||||
}
|
||||
|
||||
if (normalized === "sonnet-4.6-thinking") {
|
||||
return "sonnet-4.6";
|
||||
}
|
||||
if (normalized === "opus-4.6-thinking") {
|
||||
return "opus-4.6";
|
||||
}
|
||||
if (normalized === "opus-4.5-thinking") {
|
||||
return "opus-4.5";
|
||||
}
|
||||
|
||||
return CURSOR_MODEL_FAMILY_SET.has(normalized as CursorModelFamily)
|
||||
? (normalized as CursorModelFamily)
|
||||
: fallbackCursorModelFamily();
|
||||
}
|
||||
|
||||
function resolveCursorReasoning(model: CursorModelSlug): CursorReasoningOption {
|
||||
if (model.includes("-xhigh")) return "xhigh";
|
||||
if (model.includes("-high")) return "high";
|
||||
if (model.includes("-low")) return "low";
|
||||
return "normal";
|
||||
}
|
||||
|
||||
export function parseCursorModelSelection(model: string | null | undefined): CursorModelSelection {
|
||||
const family = resolveCursorModelFamily(model);
|
||||
const capability = CURSOR_MODEL_CAPABILITY_BY_FAMILY[family];
|
||||
const normalized = resolveModelSlugForProvider("cursor", model) as CursorModelSlug;
|
||||
|
||||
if (capability.supportsReasoning) {
|
||||
return {
|
||||
family,
|
||||
reasoning: resolveCursorReasoning(normalized),
|
||||
fast: normalized.endsWith("-fast"),
|
||||
thinking: false,
|
||||
};
|
||||
}
|
||||
|
||||
if (capability.supportsThinking) {
|
||||
return {
|
||||
family,
|
||||
reasoning: capability.defaultReasoning,
|
||||
fast: false,
|
||||
thinking: normalized.endsWith("-thinking"),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
family,
|
||||
reasoning: capability.defaultReasoning,
|
||||
fast: false,
|
||||
thinking: capability.defaultThinking,
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveCursorModelFromSelection(input: {
|
||||
readonly family: CursorModelFamily;
|
||||
readonly reasoning?: CursorReasoningOption | null;
|
||||
readonly fast?: boolean;
|
||||
readonly thinking?: boolean;
|
||||
}): CursorModelSlug {
|
||||
const family = resolveCursorModelFamily(input.family);
|
||||
const capability = CURSOR_MODEL_CAPABILITY_BY_FAMILY[family];
|
||||
|
||||
if (capability.supportsReasoning) {
|
||||
const reasoning = CURSOR_REASONING_OPTIONS.includes(input.reasoning ?? "normal")
|
||||
? (input.reasoning ?? "normal")
|
||||
: capability.defaultReasoning;
|
||||
const reasoningSuffix = reasoning === "normal" ? "" : `-${reasoning}`;
|
||||
const fastSuffix = input.fast ? "-fast" : "";
|
||||
const candidate = `${family}${reasoningSuffix}${fastSuffix}`;
|
||||
return resolveModelSlugForProvider("cursor", candidate) as CursorModelSlug;
|
||||
}
|
||||
|
||||
if (capability.supportsThinking) {
|
||||
const candidate = input.thinking ? `${family}-thinking` : family;
|
||||
return resolveModelSlugForProvider("cursor", candidate) as CursorModelSlug;
|
||||
}
|
||||
|
||||
return resolveModelSlugForProvider("cursor", family) as CursorModelSlug;
|
||||
}
|
||||
|
||||
export function getDefaultModel(provider: ProviderKind = "codex"): ModelSlug {
|
||||
return DEFAULT_MODEL_BY_PROVIDER[provider];
|
||||
}
|
||||
|
||||
export function normalizeModelSlug(
|
||||
model: string | null | undefined,
|
||||
provider: ProviderKind = "codex",
|
||||
): ModelSlug | null {
|
||||
if (typeof model !== "string") {
|
||||
return null;
|
||||
}
|
||||
|
||||
const trimmed = model.trim();
|
||||
if (!trimmed) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return MODEL_SLUG_ALIASES_BY_PROVIDER[provider][trimmed] ?? (trimmed as ModelSlug);
|
||||
}
|
||||
|
||||
export function resolveModelSlug(
|
||||
model: string | null | undefined,
|
||||
provider: ProviderKind = "codex",
|
||||
): ModelSlug {
|
||||
const normalized = normalizeModelSlug(model, provider);
|
||||
if (!normalized) {
|
||||
return DEFAULT_MODEL_BY_PROVIDER[provider];
|
||||
}
|
||||
|
||||
return MODEL_SLUG_SET_BY_PROVIDER[provider].has(normalized)
|
||||
? normalized
|
||||
: DEFAULT_MODEL_BY_PROVIDER[provider];
|
||||
}
|
||||
|
||||
export function resolveModelSlugForProvider(
|
||||
provider: ProviderKind,
|
||||
model: string | null | undefined,
|
||||
): ModelSlug {
|
||||
return resolveModelSlug(model, provider);
|
||||
}
|
||||
|
||||
const CODEX_REASONING_EFFORT_OPTIONS = ["xhigh", "high", "medium", "low"] as const;
|
||||
export type CodexReasoningEffort = (typeof CODEX_REASONING_EFFORT_OPTIONS)[number];
|
||||
|
||||
export const REASONING_EFFORT_OPTIONS_BY_PROVIDER = {
|
||||
codex: CODEX_REASONING_EFFORT_OPTIONS,
|
||||
claudeCode: [],
|
||||
@@ -375,17 +155,3 @@ export const DEFAULT_REASONING_EFFORT_BY_PROVIDER = {
|
||||
claudeCode: null,
|
||||
cursor: null,
|
||||
} as const satisfies Record<ProviderKind, CodexReasoningEffort | null>;
|
||||
|
||||
export function getReasoningEffortOptions(
|
||||
provider: ProviderKind = "codex",
|
||||
): ReadonlyArray<CodexReasoningEffort> {
|
||||
return REASONING_EFFORT_OPTIONS_BY_PROVIDER[provider];
|
||||
}
|
||||
|
||||
export function getDefaultReasoningEffort(provider: "codex"): CodexReasoningEffort;
|
||||
export function getDefaultReasoningEffort(provider: ProviderKind): CodexReasoningEffort | null;
|
||||
export function getDefaultReasoningEffort(
|
||||
provider: ProviderKind = "codex",
|
||||
): CodexReasoningEffort | null {
|
||||
return DEFAULT_REASONING_EFFORT_BY_PROVIDER[provider];
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import assert from "node:assert/strict";
|
||||
import { it } from "@effect/vitest";
|
||||
import { Effect, Schema } from "effect";
|
||||
|
||||
import {
|
||||
@@ -137,6 +138,34 @@ it.effect("preserves explicit provider and runtime mode in thread.turn.start", (
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("accepts provider-scoped model options in thread.turn.start", () =>
|
||||
Effect.gen(function* () {
|
||||
const parsed = yield* decodeThreadTurnStartCommand({
|
||||
type: "thread.turn.start",
|
||||
commandId: "cmd-turn-options",
|
||||
threadId: "thread-1",
|
||||
message: {
|
||||
messageId: "msg-options",
|
||||
role: "user",
|
||||
text: "hello",
|
||||
attachments: [],
|
||||
},
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
modelOptions: {
|
||||
codex: {
|
||||
reasoningEffort: "high",
|
||||
fastMode: true,
|
||||
},
|
||||
},
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
assert.strictEqual(parsed.provider, "codex");
|
||||
assert.strictEqual(parsed.modelOptions?.codex?.reasoningEffort, "high");
|
||||
assert.strictEqual(parsed.modelOptions?.codex?.fastMode, true);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("accepts cursor provider in thread.turn.start", () =>
|
||||
Effect.gen(function* () {
|
||||
const parsed = yield* decodeThreadTurnStartCommand({
|
||||
@@ -157,17 +186,19 @@ it.effect("accepts cursor provider in thread.turn.start", () =>
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("decodes thread.turn-start-requested defaults for provider, runtime mode, and interaction mode", () =>
|
||||
Effect.gen(function* () {
|
||||
const parsed = yield* decodeThreadTurnStartRequestedPayload({
|
||||
threadId: "thread-1",
|
||||
messageId: "msg-1",
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
assert.strictEqual(parsed.provider, undefined);
|
||||
assert.strictEqual(parsed.runtimeMode, DEFAULT_RUNTIME_MODE);
|
||||
assert.strictEqual(parsed.interactionMode, DEFAULT_PROVIDER_INTERACTION_MODE);
|
||||
}),
|
||||
it.effect(
|
||||
"decodes thread.turn-start-requested defaults for provider, runtime mode, and interaction mode",
|
||||
() =>
|
||||
Effect.gen(function* () {
|
||||
const parsed = yield* decodeThreadTurnStartRequestedPayload({
|
||||
threadId: "thread-1",
|
||||
messageId: "msg-1",
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
assert.strictEqual(parsed.provider, undefined);
|
||||
assert.strictEqual(parsed.runtimeMode, DEFAULT_RUNTIME_MODE);
|
||||
assert.strictEqual(parsed.interactionMode, DEFAULT_PROVIDER_INTERACTION_MODE);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("decodes orchestration session runtime mode defaults", () =>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Option, Schema, SchemaIssue, Struct } from "effect";
|
||||
import { ProviderModelOptions } from "./model";
|
||||
import {
|
||||
ApprovalRequestId,
|
||||
CheckpointRef,
|
||||
@@ -54,7 +55,6 @@ export const PROVIDER_SEND_TURN_MAX_ATTACHMENTS = 8;
|
||||
export const PROVIDER_SEND_TURN_MAX_IMAGE_BYTES = 10 * 1024 * 1024;
|
||||
const PROVIDER_SEND_TURN_MAX_IMAGE_DATA_URL_CHARS = 14_000_000;
|
||||
const CHAT_ATTACHMENT_ID_MAX_CHARS = 128;
|
||||
|
||||
// Correlation id is command id by design in this model.
|
||||
export const CorrelationId = CommandId;
|
||||
export type CorrelationId = typeof CorrelationId.Type;
|
||||
@@ -349,7 +349,7 @@ export const ThreadTurnStartCommand = Schema.Struct({
|
||||
}),
|
||||
provider: Schema.optional(ProviderKind),
|
||||
model: Schema.optional(TrimmedNonEmptyString),
|
||||
effort: Schema.optional(TrimmedNonEmptyString),
|
||||
modelOptions: Schema.optional(ProviderModelOptions),
|
||||
assistantDeliveryMode: Schema.optional(AssistantDeliveryMode),
|
||||
runtimeMode: RuntimeMode.pipe(Schema.withDecodingDefault(() => DEFAULT_RUNTIME_MODE)),
|
||||
interactionMode: ProviderInteractionMode.pipe(
|
||||
@@ -370,7 +370,7 @@ const ClientThreadTurnStartCommand = Schema.Struct({
|
||||
}),
|
||||
provider: Schema.optional(ProviderKind),
|
||||
model: Schema.optional(TrimmedNonEmptyString),
|
||||
effort: Schema.optional(TrimmedNonEmptyString),
|
||||
modelOptions: Schema.optional(ProviderModelOptions),
|
||||
assistantDeliveryMode: Schema.optional(AssistantDeliveryMode),
|
||||
runtimeMode: RuntimeMode,
|
||||
interactionMode: ProviderInteractionMode,
|
||||
@@ -649,7 +649,7 @@ export const ThreadTurnStartRequestedPayload = Schema.Struct({
|
||||
messageId: MessageId,
|
||||
provider: Schema.optional(ProviderKind),
|
||||
model: Schema.optional(TrimmedNonEmptyString),
|
||||
effort: Schema.optional(TrimmedNonEmptyString),
|
||||
modelOptions: Schema.optional(ProviderModelOptions),
|
||||
assistantDeliveryMode: Schema.optional(AssistantDeliveryMode),
|
||||
runtimeMode: RuntimeMode.pipe(Schema.withDecodingDefault(() => DEFAULT_RUNTIME_MODE)),
|
||||
interactionMode: ProviderInteractionMode.pipe(
|
||||
|
||||
@@ -1,16 +1,24 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { Schema } from "effect";
|
||||
|
||||
import { ProviderSessionStartInput } from "./provider";
|
||||
import { ProviderSendTurnInput, ProviderSessionStartInput } from "./provider";
|
||||
|
||||
const decodeProviderSessionStartInput = Schema.decodeUnknownSync(ProviderSessionStartInput);
|
||||
const decodeProviderSendTurnInput = Schema.decodeUnknownSync(ProviderSendTurnInput);
|
||||
|
||||
describe("ProviderSessionStartInput", () => {
|
||||
it("accepts codex-compatible payloads", () => {
|
||||
const parsed = decodeProviderSessionStartInput({
|
||||
threadId: "thread-1",
|
||||
provider: "codex",
|
||||
cwd: "/tmp/workspace",
|
||||
model: "gpt-5.3-codex",
|
||||
modelOptions: {
|
||||
codex: {
|
||||
reasoningEffort: "high",
|
||||
fastMode: true,
|
||||
},
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
providerOptions: {
|
||||
codex: {
|
||||
@@ -20,6 +28,8 @@ describe("ProviderSessionStartInput", () => {
|
||||
},
|
||||
});
|
||||
expect(parsed.runtimeMode).toBe("full-access");
|
||||
expect(parsed.modelOptions?.codex?.reasoningEffort).toBe("high");
|
||||
expect(parsed.modelOptions?.codex?.fastMode).toBe(true);
|
||||
expect(parsed.providerOptions?.codex?.binaryPath).toBe("/usr/local/bin/codex");
|
||||
expect(parsed.providerOptions?.codex?.homePath).toBe("/tmp/.codex");
|
||||
});
|
||||
@@ -27,6 +37,7 @@ describe("ProviderSessionStartInput", () => {
|
||||
it("rejects payloads without runtime mode", () => {
|
||||
expect(() =>
|
||||
decodeProviderSessionStartInput({
|
||||
threadId: "thread-1",
|
||||
provider: "codex",
|
||||
}),
|
||||
).toThrow();
|
||||
@@ -34,6 +45,7 @@ describe("ProviderSessionStartInput", () => {
|
||||
|
||||
it("accepts claude runtime knobs", () => {
|
||||
const parsed = decodeProviderSessionStartInput({
|
||||
threadId: "thread-1",
|
||||
provider: "claudeCode",
|
||||
cwd: "/tmp/workspace",
|
||||
model: "claude-sonnet-4-6",
|
||||
@@ -55,9 +67,15 @@ describe("ProviderSessionStartInput", () => {
|
||||
|
||||
it("accepts cursor provider payloads", () => {
|
||||
const parsed = decodeProviderSessionStartInput({
|
||||
threadId: "thread-1",
|
||||
provider: "cursor",
|
||||
cwd: "/tmp/workspace",
|
||||
model: "composer-1.5",
|
||||
modelOptions: {
|
||||
cursor: {
|
||||
thinking: true,
|
||||
},
|
||||
},
|
||||
providerOptions: {
|
||||
cursor: {
|
||||
binaryPath: "/usr/local/bin/agent",
|
||||
@@ -67,7 +85,27 @@ describe("ProviderSessionStartInput", () => {
|
||||
});
|
||||
expect(parsed.provider).toBe("cursor");
|
||||
expect(parsed.model).toBe("composer-1.5");
|
||||
expect(parsed.modelOptions?.cursor?.thinking).toBe(true);
|
||||
expect(parsed.providerOptions?.cursor?.binaryPath).toBe("/usr/local/bin/agent");
|
||||
expect(parsed.runtimeMode).toBe("approval-required");
|
||||
});
|
||||
});
|
||||
|
||||
describe("ProviderSendTurnInput", () => {
|
||||
it("accepts provider-scoped model options", () => {
|
||||
const parsed = decodeProviderSendTurnInput({
|
||||
threadId: "thread-1",
|
||||
model: "gpt-5.3-codex",
|
||||
modelOptions: {
|
||||
codex: {
|
||||
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);
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Schema } from "effect";
|
||||
import { TrimmedNonEmptyString } from "./baseSchemas";
|
||||
import { ProviderModelOptions } from "./model";
|
||||
import {
|
||||
ApprovalRequestId,
|
||||
EventId,
|
||||
@@ -22,7 +23,6 @@ import {
|
||||
} from "./orchestration";
|
||||
|
||||
const TrimmedNonEmptyStringSchema = TrimmedNonEmptyString;
|
||||
|
||||
const ProviderSessionStatus = Schema.Literals([
|
||||
"connecting",
|
||||
"ready",
|
||||
@@ -72,6 +72,7 @@ export const ProviderSessionStartInput = Schema.Struct({
|
||||
provider: Schema.optional(ProviderKind),
|
||||
cwd: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
model: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
modelOptions: Schema.optional(ProviderModelOptions),
|
||||
resumeCursor: Schema.optional(Schema.Unknown),
|
||||
providerOptions: Schema.optional(ProviderStartOptions),
|
||||
runtimeMode: RuntimeMode,
|
||||
@@ -87,7 +88,7 @@ export const ProviderSendTurnInput = Schema.Struct({
|
||||
Schema.Array(ChatAttachment).check(Schema.isMaxLength(PROVIDER_SEND_TURN_MAX_ATTACHMENTS)),
|
||||
),
|
||||
model: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
effort: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
modelOptions: Schema.optional(ProviderModelOptions),
|
||||
interactionMode: Schema.optional(ProviderInteractionMode),
|
||||
});
|
||||
export type ProviderSendTurnInput = typeof ProviderSendTurnInput.Type;
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
"./model": {
|
||||
"types": "./src/model.ts",
|
||||
"import": "./src/model.ts"
|
||||
},
|
||||
"./git": {
|
||||
"types": "./src/git.ts",
|
||||
"import": "./src/git.ts"
|
||||
@@ -23,6 +27,7 @@
|
||||
"test": "vitest run"
|
||||
},
|
||||
"dependencies": {
|
||||
"@t3tools/contracts": "workspace:*",
|
||||
"effect": "catalog:"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
CURSOR_MODEL_FAMILY_OPTIONS,
|
||||
CURSOR_REASONING_OPTIONS,
|
||||
DEFAULT_MODEL,
|
||||
DEFAULT_MODEL_BY_PROVIDER,
|
||||
DEFAULT_REASONING_EFFORT_BY_PROVIDER,
|
||||
MODEL_OPTIONS,
|
||||
MODEL_OPTIONS_BY_PROVIDER,
|
||||
REASONING_EFFORT_OPTIONS_BY_PROVIDER,
|
||||
DEFAULT_REASONING_EFFORT_BY_PROVIDER,
|
||||
} from "../../contracts/src";
|
||||
|
||||
import {
|
||||
getDefaultModel,
|
||||
getDefaultReasoningEffort,
|
||||
getCursorModelFamilyOptions,
|
||||
@@ -0,0 +1,280 @@
|
||||
import {
|
||||
CODEX_REASONING_EFFORT_OPTIONS,
|
||||
CURSOR_MODEL_FAMILY_OPTIONS,
|
||||
CURSOR_REASONING_OPTIONS,
|
||||
DEFAULT_MODEL_BY_PROVIDER,
|
||||
DEFAULT_REASONING_EFFORT_BY_PROVIDER,
|
||||
MODEL_OPTIONS_BY_PROVIDER,
|
||||
MODEL_SLUG_ALIASES_BY_PROVIDER,
|
||||
REASONING_EFFORT_OPTIONS_BY_PROVIDER,
|
||||
type CodexReasoningEffort,
|
||||
type CursorModelFamily,
|
||||
type CursorModelSlug,
|
||||
type CursorReasoningOption,
|
||||
type ModelSlug,
|
||||
type ProviderKind,
|
||||
} from "../../contracts/src";
|
||||
|
||||
type CursorModelCapability = {
|
||||
readonly supportsReasoning: boolean;
|
||||
readonly supportsFast: boolean;
|
||||
readonly supportsThinking: boolean;
|
||||
readonly defaultReasoning: CursorReasoningOption;
|
||||
readonly defaultThinking: boolean;
|
||||
};
|
||||
|
||||
const CURSOR_MODEL_CAPABILITY_BY_FAMILY: Record<CursorModelFamily, CursorModelCapability> = {
|
||||
auto: {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
supportsThinking: false,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: false,
|
||||
},
|
||||
"composer-1.5": {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
supportsThinking: false,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: false,
|
||||
},
|
||||
"composer-1": {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
supportsThinking: false,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: false,
|
||||
},
|
||||
"gpt-5.3-codex": {
|
||||
supportsReasoning: true,
|
||||
supportsFast: true,
|
||||
supportsThinking: false,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: false,
|
||||
},
|
||||
"gpt-5.3-codex-spark-preview": {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
supportsThinking: false,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: false,
|
||||
},
|
||||
"opus-4.6": {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
supportsThinking: true,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: true,
|
||||
},
|
||||
"opus-4.5": {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
supportsThinking: true,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: true,
|
||||
},
|
||||
"sonnet-4.6": {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
supportsThinking: true,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: true,
|
||||
},
|
||||
"gemini-3.1-pro": {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
supportsThinking: false,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: false,
|
||||
},
|
||||
};
|
||||
|
||||
const MODEL_SLUG_SET_BY_PROVIDER: Record<ProviderKind, ReadonlySet<ModelSlug>> = {
|
||||
claudeCode: new Set(MODEL_OPTIONS_BY_PROVIDER.claudeCode.map((option) => option.slug)),
|
||||
codex: new Set(MODEL_OPTIONS_BY_PROVIDER.codex.map((option) => option.slug)),
|
||||
cursor: new Set(MODEL_OPTIONS_BY_PROVIDER.cursor.map((option) => option.slug)),
|
||||
};
|
||||
|
||||
const CURSOR_MODEL_FAMILY_SET = new Set<CursorModelFamily>(
|
||||
CURSOR_MODEL_FAMILY_OPTIONS.map((option) => option.slug),
|
||||
);
|
||||
|
||||
export interface CursorModelSelection {
|
||||
readonly family: CursorModelFamily;
|
||||
readonly reasoning: CursorReasoningOption;
|
||||
readonly fast: boolean;
|
||||
readonly thinking: boolean;
|
||||
}
|
||||
|
||||
export function getModelOptions(provider: ProviderKind = "codex") {
|
||||
return MODEL_OPTIONS_BY_PROVIDER[provider];
|
||||
}
|
||||
|
||||
export function getCursorModelFamilyOptions() {
|
||||
return CURSOR_MODEL_FAMILY_OPTIONS;
|
||||
}
|
||||
|
||||
export function getCursorModelCapabilities(family: CursorModelFamily) {
|
||||
return CURSOR_MODEL_CAPABILITY_BY_FAMILY[family];
|
||||
}
|
||||
|
||||
function fallbackCursorModelFamily(): CursorModelFamily {
|
||||
const fallback = parseCursorModelSelection(DEFAULT_MODEL_BY_PROVIDER.cursor);
|
||||
return fallback.family;
|
||||
}
|
||||
|
||||
function resolveCursorModelFamily(model: string | null | undefined): CursorModelFamily {
|
||||
const normalized = normalizeModelSlug(model, "cursor");
|
||||
if (!normalized) {
|
||||
return fallbackCursorModelFamily();
|
||||
}
|
||||
|
||||
if (
|
||||
normalized === "gpt-5.3-codex" ||
|
||||
normalized === "gpt-5.3-codex-fast" ||
|
||||
normalized === "gpt-5.3-codex-low" ||
|
||||
normalized === "gpt-5.3-codex-low-fast" ||
|
||||
normalized === "gpt-5.3-codex-high" ||
|
||||
normalized === "gpt-5.3-codex-high-fast" ||
|
||||
normalized === "gpt-5.3-codex-xhigh" ||
|
||||
normalized === "gpt-5.3-codex-xhigh-fast"
|
||||
) {
|
||||
return "gpt-5.3-codex";
|
||||
}
|
||||
|
||||
if (normalized === "sonnet-4.6-thinking") {
|
||||
return "sonnet-4.6";
|
||||
}
|
||||
if (normalized === "opus-4.6-thinking") {
|
||||
return "opus-4.6";
|
||||
}
|
||||
if (normalized === "opus-4.5-thinking") {
|
||||
return "opus-4.5";
|
||||
}
|
||||
|
||||
return CURSOR_MODEL_FAMILY_SET.has(normalized as CursorModelFamily)
|
||||
? (normalized as CursorModelFamily)
|
||||
: fallbackCursorModelFamily();
|
||||
}
|
||||
|
||||
function resolveCursorReasoning(model: CursorModelSlug): CursorReasoningOption {
|
||||
if (model.includes("-xhigh")) return "xhigh";
|
||||
if (model.includes("-high")) return "high";
|
||||
if (model.includes("-low")) return "low";
|
||||
return "normal";
|
||||
}
|
||||
|
||||
export function parseCursorModelSelection(model: string | null | undefined): CursorModelSelection {
|
||||
const family = resolveCursorModelFamily(model);
|
||||
const capability = CURSOR_MODEL_CAPABILITY_BY_FAMILY[family];
|
||||
const normalized = resolveModelSlugForProvider("cursor", model) as CursorModelSlug;
|
||||
|
||||
if (capability.supportsReasoning) {
|
||||
return {
|
||||
family,
|
||||
reasoning: resolveCursorReasoning(normalized),
|
||||
fast: normalized.endsWith("-fast"),
|
||||
thinking: false,
|
||||
};
|
||||
}
|
||||
|
||||
if (capability.supportsThinking) {
|
||||
return {
|
||||
family,
|
||||
reasoning: capability.defaultReasoning,
|
||||
fast: false,
|
||||
thinking: normalized.endsWith("-thinking"),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
family,
|
||||
reasoning: capability.defaultReasoning,
|
||||
fast: false,
|
||||
thinking: capability.defaultThinking,
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveCursorModelFromSelection(input: {
|
||||
readonly family: CursorModelFamily;
|
||||
readonly reasoning?: CursorReasoningOption | null;
|
||||
readonly fast?: boolean;
|
||||
readonly thinking?: boolean;
|
||||
}): CursorModelSlug {
|
||||
const family = resolveCursorModelFamily(input.family);
|
||||
const capability = CURSOR_MODEL_CAPABILITY_BY_FAMILY[family];
|
||||
|
||||
if (capability.supportsReasoning) {
|
||||
const reasoning = CURSOR_REASONING_OPTIONS.includes(input.reasoning ?? "normal")
|
||||
? (input.reasoning ?? "normal")
|
||||
: capability.defaultReasoning;
|
||||
const reasoningSuffix = reasoning === "normal" ? "" : `-${reasoning}`;
|
||||
const fastSuffix = input.fast ? "-fast" : "";
|
||||
const candidate = `${family}${reasoningSuffix}${fastSuffix}`;
|
||||
return resolveModelSlugForProvider("cursor", candidate) as CursorModelSlug;
|
||||
}
|
||||
|
||||
if (capability.supportsThinking) {
|
||||
const candidate = input.thinking ? `${family}-thinking` : family;
|
||||
return resolveModelSlugForProvider("cursor", candidate) as CursorModelSlug;
|
||||
}
|
||||
|
||||
return resolveModelSlugForProvider("cursor", family) as CursorModelSlug;
|
||||
}
|
||||
|
||||
export function getDefaultModel(provider: ProviderKind = "codex"): ModelSlug {
|
||||
return DEFAULT_MODEL_BY_PROVIDER[provider];
|
||||
}
|
||||
|
||||
export function normalizeModelSlug(
|
||||
model: string | null | undefined,
|
||||
provider: ProviderKind = "codex",
|
||||
): ModelSlug | null {
|
||||
if (typeof model !== "string") {
|
||||
return null;
|
||||
}
|
||||
|
||||
const trimmed = model.trim();
|
||||
if (!trimmed) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return MODEL_SLUG_ALIASES_BY_PROVIDER[provider][trimmed] ?? (trimmed as ModelSlug);
|
||||
}
|
||||
|
||||
export function resolveModelSlug(
|
||||
model: string | null | undefined,
|
||||
provider: ProviderKind = "codex",
|
||||
): ModelSlug {
|
||||
const normalized = normalizeModelSlug(model, provider);
|
||||
if (!normalized) {
|
||||
return DEFAULT_MODEL_BY_PROVIDER[provider];
|
||||
}
|
||||
|
||||
return MODEL_SLUG_SET_BY_PROVIDER[provider].has(normalized)
|
||||
? normalized
|
||||
: DEFAULT_MODEL_BY_PROVIDER[provider];
|
||||
}
|
||||
|
||||
export function resolveModelSlugForProvider(
|
||||
provider: ProviderKind,
|
||||
model: string | null | undefined,
|
||||
): ModelSlug {
|
||||
return resolveModelSlug(model, provider);
|
||||
}
|
||||
|
||||
export function getReasoningEffortOptions(
|
||||
provider: ProviderKind = "codex",
|
||||
): ReadonlyArray<CodexReasoningEffort> {
|
||||
return REASONING_EFFORT_OPTIONS_BY_PROVIDER[provider];
|
||||
}
|
||||
|
||||
export function getDefaultReasoningEffort(provider: "codex"): CodexReasoningEffort;
|
||||
export function getDefaultReasoningEffort(provider: ProviderKind): CodexReasoningEffort | null;
|
||||
export function getDefaultReasoningEffort(
|
||||
provider: ProviderKind = "codex",
|
||||
): CodexReasoningEffort | null {
|
||||
return DEFAULT_REASONING_EFFORT_BY_PROVIDER[provider];
|
||||
}
|
||||
|
||||
export { CODEX_REASONING_EFFORT_OPTIONS };
|
||||
Reference in new issue
Block a user