Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e7ae3f40f4 | ||
|
|
97ff0ac4a9 | ||
|
|
07e86e938b | ||
|
|
71ff626e3e | ||
|
|
8cad01a57b | ||
|
|
340634eeee | ||
|
|
fa0a1c1567 | ||
|
|
01358d1006 |
No files matched your search
@@ -115,7 +115,10 @@ const seedProjectAndThread = (harness: OrchestrationIntegrationHarness) =>
|
||||
projectId: PROJECT_ID,
|
||||
title: "Integration Project",
|
||||
workspaceRoot: harness.workspaceDir,
|
||||
defaultModel,
|
||||
defaultModelSelection: {
|
||||
provider,
|
||||
model: defaultModel,
|
||||
},
|
||||
createdAt,
|
||||
});
|
||||
|
||||
@@ -125,7 +128,10 @@ const seedProjectAndThread = (harness: OrchestrationIntegrationHarness) =>
|
||||
threadId: THREAD_ID,
|
||||
projectId: PROJECT_ID,
|
||||
title: "Integration Thread",
|
||||
model: defaultModel,
|
||||
modelSelection: {
|
||||
provider,
|
||||
model: defaultModel,
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
branch: null,
|
||||
@@ -151,7 +157,14 @@ const startTurn = (input: {
|
||||
text: input.text,
|
||||
attachments: [],
|
||||
},
|
||||
...(input.provider !== undefined ? { provider: input.provider } : {}),
|
||||
...(input.provider !== undefined
|
||||
? {
|
||||
modelSelection: {
|
||||
provider: input.provider,
|
||||
model: DEFAULT_MODEL_BY_PROVIDER[input.provider],
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
createdAt: nowIso(),
|
||||
@@ -254,7 +267,10 @@ it.live.skipIf(!process.env.CODEX_BINARY_PATH)(
|
||||
projectId: PROJECT_ID,
|
||||
title: "Integration Project",
|
||||
workspaceRoot: harness.workspaceDir,
|
||||
defaultModel: "gpt-5.3-codex",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
},
|
||||
createdAt,
|
||||
});
|
||||
|
||||
@@ -264,7 +280,10 @@ it.live.skipIf(!process.env.CODEX_BINARY_PATH)(
|
||||
threadId: THREAD_ID,
|
||||
projectId: PROJECT_ID,
|
||||
title: "Integration Thread",
|
||||
model: "gpt-5.3-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
|
||||
@@ -31,7 +31,7 @@ function makeSnapshot(input: {
|
||||
id: input.projectId,
|
||||
title: "Project",
|
||||
workspaceRoot: input.workspaceRoot,
|
||||
defaultModel: null,
|
||||
defaultModelSelection: null,
|
||||
scripts: [],
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
updatedAt: "2026-01-01T00:00:00.000Z",
|
||||
@@ -43,7 +43,10 @@ function makeSnapshot(input: {
|
||||
id: input.threadId,
|
||||
projectId: input.projectId,
|
||||
title: "Thread",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
|
||||
@@ -282,7 +282,10 @@ describe("CheckpointReactor", () => {
|
||||
projectId: asProjectId("project-1"),
|
||||
title: "Test Project",
|
||||
workspaceRoot: options?.projectWorkspaceRoot ?? cwd,
|
||||
defaultModel: "gpt-5-codex",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
createdAt,
|
||||
}),
|
||||
);
|
||||
@@ -293,7 +296,10 @@ describe("CheckpointReactor", () => {
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
projectId: asProjectId("project-1"),
|
||||
title: "Thread",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
branch: null,
|
||||
|
||||
@@ -72,7 +72,10 @@ describe("OrchestrationEngine", () => {
|
||||
projectId: asProjectId("project-1"),
|
||||
title: "Project 1",
|
||||
workspaceRoot: "/tmp/project-1",
|
||||
defaultModel: "gpt-5-codex",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
createdAt,
|
||||
}),
|
||||
);
|
||||
@@ -83,7 +86,10 @@ describe("OrchestrationEngine", () => {
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
projectId: asProjectId("project-1"),
|
||||
title: "Thread",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
branch: null,
|
||||
@@ -126,7 +132,10 @@ describe("OrchestrationEngine", () => {
|
||||
projectId: asProjectId("project-replay"),
|
||||
title: "Replay Project",
|
||||
workspaceRoot: "/tmp/project-replay",
|
||||
defaultModel: "gpt-5-codex",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
createdAt,
|
||||
}),
|
||||
);
|
||||
@@ -137,7 +146,10 @@ describe("OrchestrationEngine", () => {
|
||||
threadId: ThreadId.makeUnsafe("thread-replay"),
|
||||
projectId: asProjectId("project-replay"),
|
||||
title: "replay",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
branch: null,
|
||||
@@ -178,7 +190,10 @@ describe("OrchestrationEngine", () => {
|
||||
projectId: asProjectId("project-stream"),
|
||||
title: "Stream Project",
|
||||
workspaceRoot: "/tmp/project-stream",
|
||||
defaultModel: "gpt-5-codex",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
createdAt,
|
||||
}),
|
||||
);
|
||||
@@ -199,7 +214,10 @@ describe("OrchestrationEngine", () => {
|
||||
threadId: ThreadId.makeUnsafe("thread-stream"),
|
||||
projectId: asProjectId("project-stream"),
|
||||
title: "domain-stream",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
branch: null,
|
||||
@@ -233,7 +251,10 @@ describe("OrchestrationEngine", () => {
|
||||
projectId: asProjectId("project-turn-diff"),
|
||||
title: "Turn Diff Project",
|
||||
workspaceRoot: "/tmp/project-turn-diff",
|
||||
defaultModel: "gpt-5-codex",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
createdAt,
|
||||
}),
|
||||
);
|
||||
@@ -244,7 +265,10 @@ describe("OrchestrationEngine", () => {
|
||||
threadId: ThreadId.makeUnsafe("thread-turn-diff"),
|
||||
projectId: asProjectId("project-turn-diff"),
|
||||
title: "Turn diff thread",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
branch: null,
|
||||
@@ -344,7 +368,10 @@ describe("OrchestrationEngine", () => {
|
||||
projectId: asProjectId("project-flaky"),
|
||||
title: "Flaky Project",
|
||||
workspaceRoot: "/tmp/project-flaky",
|
||||
defaultModel: "gpt-5-codex",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
createdAt,
|
||||
}),
|
||||
);
|
||||
@@ -357,7 +384,10 @@ describe("OrchestrationEngine", () => {
|
||||
threadId: ThreadId.makeUnsafe("thread-flaky-fail"),
|
||||
projectId: asProjectId("project-flaky"),
|
||||
title: "flaky-fail",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
branch: null,
|
||||
@@ -374,7 +404,10 @@ describe("OrchestrationEngine", () => {
|
||||
threadId: ThreadId.makeUnsafe("thread-flaky-ok"),
|
||||
projectId: asProjectId("project-flaky"),
|
||||
title: "flaky-ok",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
branch: null,
|
||||
@@ -428,7 +461,10 @@ describe("OrchestrationEngine", () => {
|
||||
projectId: asProjectId("project-atomic"),
|
||||
title: "Atomic Project",
|
||||
workspaceRoot: "/tmp/project-atomic",
|
||||
defaultModel: "gpt-5-codex",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
createdAt,
|
||||
}),
|
||||
);
|
||||
@@ -439,7 +475,10 @@ describe("OrchestrationEngine", () => {
|
||||
threadId: ThreadId.makeUnsafe("thread-atomic"),
|
||||
projectId: asProjectId("project-atomic"),
|
||||
title: "atomic",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
branch: null,
|
||||
@@ -563,7 +602,10 @@ describe("OrchestrationEngine", () => {
|
||||
projectId: asProjectId("project-sync"),
|
||||
title: "Sync Project",
|
||||
workspaceRoot: "/tmp/project-sync",
|
||||
defaultModel: "gpt-5-codex",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
createdAt,
|
||||
}),
|
||||
);
|
||||
@@ -574,7 +616,10 @@ describe("OrchestrationEngine", () => {
|
||||
threadId: ThreadId.makeUnsafe("thread-sync"),
|
||||
projectId: asProjectId("project-sync"),
|
||||
title: "sync-before",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
branch: null,
|
||||
@@ -642,7 +687,10 @@ describe("OrchestrationEngine", () => {
|
||||
projectId: asProjectId("project-duplicate"),
|
||||
title: "Duplicate Project",
|
||||
workspaceRoot: "/tmp/project-duplicate",
|
||||
defaultModel: "gpt-5-codex",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
createdAt,
|
||||
}),
|
||||
);
|
||||
@@ -654,7 +702,10 @@ describe("OrchestrationEngine", () => {
|
||||
threadId: ThreadId.makeUnsafe("thread-duplicate"),
|
||||
projectId: asProjectId("project-duplicate"),
|
||||
title: "duplicate",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
branch: null,
|
||||
@@ -671,7 +722,10 @@ describe("OrchestrationEngine", () => {
|
||||
threadId: ThreadId.makeUnsafe("thread-duplicate"),
|
||||
projectId: asProjectId("project-duplicate"),
|
||||
title: "duplicate",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
branch: null,
|
||||
|
||||
@@ -68,7 +68,7 @@ it.layer(BaseTestLayer)("OrchestrationProjectionPipeline", (it) => {
|
||||
projectId: ProjectId.makeUnsafe("project-1"),
|
||||
title: "Project 1",
|
||||
workspaceRoot: "/tmp/project-1",
|
||||
defaultModel: null,
|
||||
defaultModelSelection: null,
|
||||
scripts: [],
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
@@ -89,7 +89,10 @@ it.layer(BaseTestLayer)("OrchestrationProjectionPipeline", (it) => {
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
projectId: ProjectId.makeUnsafe("project-1"),
|
||||
title: "Thread 1",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
@@ -337,7 +340,7 @@ it.layer(BaseTestLayer)("OrchestrationProjectionPipeline", (it) => {
|
||||
projectId: ProjectId.makeUnsafe("project-clear-attachments"),
|
||||
title: "Project Clear Attachments",
|
||||
workspaceRoot: "/tmp/project-clear-attachments",
|
||||
defaultModel: null,
|
||||
defaultModelSelection: null,
|
||||
scripts: [],
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
@@ -358,7 +361,10 @@ it.layer(BaseTestLayer)("OrchestrationProjectionPipeline", (it) => {
|
||||
threadId: ThreadId.makeUnsafe("thread-clear-attachments"),
|
||||
projectId: ProjectId.makeUnsafe("project-clear-attachments"),
|
||||
title: "Thread Clear Attachments",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
@@ -462,7 +468,7 @@ it.layer(
|
||||
projectId: ProjectId.makeUnsafe("project-overwrite"),
|
||||
title: "Project Overwrite",
|
||||
workspaceRoot: "/tmp/project-overwrite",
|
||||
defaultModel: null,
|
||||
defaultModelSelection: null,
|
||||
scripts: [],
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
@@ -483,7 +489,10 @@ it.layer(
|
||||
threadId: ThreadId.makeUnsafe("thread-overwrite"),
|
||||
projectId: ProjectId.makeUnsafe("project-overwrite"),
|
||||
title: "Thread Overwrite",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
@@ -607,7 +616,7 @@ it.layer(
|
||||
projectId: ProjectId.makeUnsafe("project-rollback"),
|
||||
title: "Project Rollback",
|
||||
workspaceRoot: "/tmp/project-rollback",
|
||||
defaultModel: null,
|
||||
defaultModelSelection: null,
|
||||
scripts: [],
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
@@ -628,7 +637,10 @@ it.layer(
|
||||
threadId: ThreadId.makeUnsafe("thread-rollback"),
|
||||
projectId: ProjectId.makeUnsafe("project-rollback"),
|
||||
title: "Thread Rollback",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
@@ -733,7 +745,7 @@ it.layer(
|
||||
projectId: ProjectId.makeUnsafe("project-revert-files"),
|
||||
title: "Project Revert Files",
|
||||
workspaceRoot: "/tmp/project-revert-files",
|
||||
defaultModel: null,
|
||||
defaultModelSelection: null,
|
||||
scripts: [],
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
@@ -754,7 +766,10 @@ it.layer(
|
||||
threadId,
|
||||
projectId: ProjectId.makeUnsafe("project-revert-files"),
|
||||
title: "Thread Revert Files",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
@@ -938,7 +953,7 @@ it.layer(Layer.fresh(makeProjectionPipelinePrefixedTestLayer("t3-projection-atta
|
||||
projectId: ProjectId.makeUnsafe("project-delete-files"),
|
||||
title: "Project Delete Files",
|
||||
workspaceRoot: "/tmp/project-delete-files",
|
||||
defaultModel: null,
|
||||
defaultModelSelection: null,
|
||||
scripts: [],
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
@@ -959,7 +974,10 @@ it.layer(Layer.fresh(makeProjectionPipelinePrefixedTestLayer("t3-projection-atta
|
||||
threadId,
|
||||
projectId: ProjectId.makeUnsafe("project-delete-files"),
|
||||
title: "Thread Delete Files",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
@@ -1098,7 +1116,7 @@ it.layer(BaseTestLayer)("OrchestrationProjectionPipeline", (it) => {
|
||||
projectId: ProjectId.makeUnsafe("project-a"),
|
||||
title: "Project A",
|
||||
workspaceRoot: "/tmp/project-a",
|
||||
defaultModel: null,
|
||||
defaultModelSelection: null,
|
||||
scripts: [],
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
@@ -1119,7 +1137,10 @@ it.layer(BaseTestLayer)("OrchestrationProjectionPipeline", (it) => {
|
||||
threadId: ThreadId.makeUnsafe("thread-a"),
|
||||
projectId: ProjectId.makeUnsafe("project-a"),
|
||||
title: "Thread A",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
@@ -1222,7 +1243,7 @@ it.layer(BaseTestLayer)("OrchestrationProjectionPipeline", (it) => {
|
||||
projectId: ProjectId.makeUnsafe("project-empty"),
|
||||
title: "Project Empty",
|
||||
workspaceRoot: "/tmp/project-empty",
|
||||
defaultModel: null,
|
||||
defaultModelSelection: null,
|
||||
scripts: [],
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
@@ -1243,7 +1264,10 @@ it.layer(BaseTestLayer)("OrchestrationProjectionPipeline", (it) => {
|
||||
threadId: ThreadId.makeUnsafe("thread-empty"),
|
||||
projectId: ProjectId.makeUnsafe("project-empty"),
|
||||
title: "Thread Empty",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
@@ -1359,7 +1383,7 @@ it.layer(BaseTestLayer)("OrchestrationProjectionPipeline", (it) => {
|
||||
projectId: ProjectId.makeUnsafe("project-conflict"),
|
||||
title: "Project Conflict",
|
||||
workspaceRoot: "/tmp/project-conflict",
|
||||
defaultModel: null,
|
||||
defaultModelSelection: null,
|
||||
scripts: [],
|
||||
createdAt: "2026-02-26T13:00:00.000Z",
|
||||
updatedAt: "2026-02-26T13:00:00.000Z",
|
||||
@@ -1380,7 +1404,10 @@ it.layer(BaseTestLayer)("OrchestrationProjectionPipeline", (it) => {
|
||||
threadId: ThreadId.makeUnsafe("thread-conflict"),
|
||||
projectId: ProjectId.makeUnsafe("project-conflict"),
|
||||
title: "Thread Conflict",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
@@ -1500,7 +1527,7 @@ it.layer(BaseTestLayer)("OrchestrationProjectionPipeline", (it) => {
|
||||
projectId: ProjectId.makeUnsafe("project-revert"),
|
||||
title: "Project Revert",
|
||||
workspaceRoot: "/tmp/project-revert",
|
||||
defaultModel: null,
|
||||
defaultModelSelection: null,
|
||||
scripts: [],
|
||||
createdAt: "2026-02-26T12:00:00.000Z",
|
||||
updatedAt: "2026-02-26T12:00:00.000Z",
|
||||
@@ -1521,7 +1548,10 @@ it.layer(BaseTestLayer)("OrchestrationProjectionPipeline", (it) => {
|
||||
threadId: ThreadId.makeUnsafe("thread-revert"),
|
||||
projectId: ProjectId.makeUnsafe("project-revert"),
|
||||
title: "Thread Revert",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
@@ -1837,7 +1867,10 @@ engineLayer("OrchestrationProjectionPipeline via engine dispatch", (it) => {
|
||||
projectId: ProjectId.makeUnsafe("project-live"),
|
||||
title: "Live Project",
|
||||
workspaceRoot: "/tmp/project-live",
|
||||
defaultModel: "gpt-5-codex",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
createdAt,
|
||||
});
|
||||
|
||||
@@ -1872,7 +1905,10 @@ engineLayer("OrchestrationProjectionPipeline via engine dispatch", (it) => {
|
||||
projectId: ProjectId.makeUnsafe("project-scripts"),
|
||||
title: "Scripts Project",
|
||||
workspaceRoot: "/tmp/project-scripts",
|
||||
defaultModel: "gpt-5-codex",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
createdAt,
|
||||
});
|
||||
|
||||
@@ -1889,7 +1925,10 @@ engineLayer("OrchestrationProjectionPipeline via engine dispatch", (it) => {
|
||||
runOnWorktreeCreate: false,
|
||||
},
|
||||
],
|
||||
defaultModel: "gpt-5",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5",
|
||||
},
|
||||
});
|
||||
|
||||
const projectRows = yield* sql<{
|
||||
|
||||
@@ -362,7 +362,7 @@ const makeOrchestrationProjectionPipeline = Effect.gen(function* () {
|
||||
projectId: event.payload.projectId,
|
||||
title: event.payload.title,
|
||||
workspaceRoot: event.payload.workspaceRoot,
|
||||
defaultModel: event.payload.defaultModel,
|
||||
defaultModelSelection: event.payload.defaultModelSelection,
|
||||
scripts: event.payload.scripts,
|
||||
createdAt: event.payload.createdAt,
|
||||
updatedAt: event.payload.updatedAt,
|
||||
@@ -383,8 +383,8 @@ const makeOrchestrationProjectionPipeline = Effect.gen(function* () {
|
||||
...(event.payload.workspaceRoot !== undefined
|
||||
? { workspaceRoot: event.payload.workspaceRoot }
|
||||
: {}),
|
||||
...(event.payload.defaultModel !== undefined
|
||||
? { defaultModel: event.payload.defaultModel }
|
||||
...(event.payload.defaultModelSelection !== undefined
|
||||
? { defaultModelSelection: event.payload.defaultModelSelection }
|
||||
: {}),
|
||||
...(event.payload.scripts !== undefined ? { scripts: event.payload.scripts } : {}),
|
||||
updatedAt: event.payload.updatedAt,
|
||||
@@ -420,7 +420,7 @@ const makeOrchestrationProjectionPipeline = Effect.gen(function* () {
|
||||
threadId: event.payload.threadId,
|
||||
projectId: event.payload.projectId,
|
||||
title: event.payload.title,
|
||||
model: event.payload.model,
|
||||
modelSelection: event.payload.modelSelection,
|
||||
runtimeMode: event.payload.runtimeMode,
|
||||
interactionMode: event.payload.interactionMode,
|
||||
branch: event.payload.branch,
|
||||
@@ -442,7 +442,9 @@ const makeOrchestrationProjectionPipeline = Effect.gen(function* () {
|
||||
yield* projectionThreadRepository.upsert({
|
||||
...existingRow.value,
|
||||
...(event.payload.title !== undefined ? { title: event.payload.title } : {}),
|
||||
...(event.payload.model !== undefined ? { model: event.payload.model } : {}),
|
||||
...(event.payload.modelSelection !== undefined
|
||||
? { modelSelection: event.payload.modelSelection }
|
||||
: {}),
|
||||
...(event.payload.branch !== undefined ? { branch: event.payload.branch } : {}),
|
||||
...(event.payload.worktreePath !== undefined
|
||||
? { worktreePath: event.payload.worktreePath }
|
||||
|
||||
@@ -34,6 +34,7 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
|
||||
project_id,
|
||||
title,
|
||||
workspace_root,
|
||||
default_provider,
|
||||
default_model,
|
||||
scripts_json,
|
||||
created_at,
|
||||
@@ -44,6 +45,7 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
|
||||
'project-1',
|
||||
'Project 1',
|
||||
'/tmp/project-1',
|
||||
'codex',
|
||||
'gpt-5-codex',
|
||||
'[{"id":"script-1","name":"Build","command":"bun run build","icon":"build","runOnWorktreeCreate":false}]',
|
||||
'2026-02-24T00:00:00.000Z',
|
||||
@@ -57,6 +59,7 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
|
||||
thread_id,
|
||||
project_id,
|
||||
title,
|
||||
provider,
|
||||
model,
|
||||
branch,
|
||||
worktree_path,
|
||||
@@ -69,6 +72,7 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
|
||||
'thread-1',
|
||||
'project-1',
|
||||
'Thread 1',
|
||||
'codex',
|
||||
'gpt-5-codex',
|
||||
NULL,
|
||||
NULL,
|
||||
@@ -234,7 +238,10 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
|
||||
id: asProjectId("project-1"),
|
||||
title: "Project 1",
|
||||
workspaceRoot: "/tmp/project-1",
|
||||
defaultModel: "gpt-5-codex",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
scripts: [
|
||||
{
|
||||
id: "script-1",
|
||||
@@ -254,7 +261,10 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
|
||||
id: ThreadId.makeUnsafe("thread-1"),
|
||||
projectId: asProjectId("project-1"),
|
||||
title: "Thread 1",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
interactionMode: "default",
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
ChatAttachment,
|
||||
IsoDateTime,
|
||||
ModelSelection,
|
||||
MessageId,
|
||||
NonNegativeInt,
|
||||
OrchestrationCheckpointFile,
|
||||
@@ -43,11 +44,18 @@ import {
|
||||
} from "../Services/ProjectionSnapshotQuery.ts";
|
||||
|
||||
const decodeReadModel = Schema.decodeUnknownEffect(OrchestrationReadModel);
|
||||
const ProjectionProjectDbRowSchema = ProjectionProject.mapFields(
|
||||
Struct.assign({
|
||||
scripts: Schema.fromJsonString(Schema.Array(ProjectScript)),
|
||||
}),
|
||||
);
|
||||
const ProjectionProjectDbRowSchema = Schema.Struct({
|
||||
projectId: ProjectionProject.fields.projectId,
|
||||
title: ProjectionProject.fields.title,
|
||||
workspaceRoot: ProjectionProject.fields.workspaceRoot,
|
||||
defaultProvider: Schema.NullOr(Schema.Literals(["codex", "claudeAgent"])),
|
||||
defaultModel: Schema.NullOr(Schema.String),
|
||||
defaultModelOptions: Schema.NullOr(Schema.fromJsonString(Schema.Unknown)),
|
||||
scripts: Schema.fromJsonString(Schema.Array(ProjectScript)),
|
||||
createdAt: ProjectionProject.fields.createdAt,
|
||||
updatedAt: ProjectionProject.fields.updatedAt,
|
||||
deletedAt: ProjectionProject.fields.deletedAt,
|
||||
});
|
||||
const ProjectionThreadMessageDbRowSchema = ProjectionThreadMessage.mapFields(
|
||||
Struct.assign({
|
||||
isStreaming: Schema.Number,
|
||||
@@ -55,7 +63,22 @@ const ProjectionThreadMessageDbRowSchema = ProjectionThreadMessage.mapFields(
|
||||
}),
|
||||
);
|
||||
const ProjectionThreadProposedPlanDbRowSchema = ProjectionThreadProposedPlan;
|
||||
const ProjectionThreadDbRowSchema = ProjectionThread;
|
||||
const ProjectionThreadDbRowSchema = Schema.Struct({
|
||||
threadId: ProjectionThread.fields.threadId,
|
||||
projectId: ProjectionThread.fields.projectId,
|
||||
title: ProjectionThread.fields.title,
|
||||
provider: Schema.Literals(["codex", "claudeAgent"]),
|
||||
model: Schema.String,
|
||||
modelOptions: Schema.NullOr(Schema.fromJsonString(Schema.Unknown)),
|
||||
runtimeMode: ProjectionThread.fields.runtimeMode,
|
||||
interactionMode: ProjectionThread.fields.interactionMode,
|
||||
branch: ProjectionThread.fields.branch,
|
||||
worktreePath: ProjectionThread.fields.worktreePath,
|
||||
latestTurnId: ProjectionThread.fields.latestTurnId,
|
||||
createdAt: ProjectionThread.fields.createdAt,
|
||||
updatedAt: ProjectionThread.fields.updatedAt,
|
||||
deletedAt: ProjectionThread.fields.deletedAt,
|
||||
});
|
||||
const ProjectionThreadActivityDbRowSchema = ProjectionThreadActivity.mapFields(
|
||||
Struct.assign({
|
||||
payload: Schema.fromJsonString(Schema.Unknown),
|
||||
@@ -80,6 +103,7 @@ const ProjectionLatestTurnDbRowSchema = Schema.Struct({
|
||||
sourceProposedPlanId: Schema.NullOr(OrchestrationProposedPlanId),
|
||||
});
|
||||
const ProjectionStateDbRowSchema = ProjectionState;
|
||||
const decodeModelSelectionSchema = Schema.decodeUnknownEffect(ModelSelection);
|
||||
|
||||
const REQUIRED_SNAPSHOT_PROJECTORS = [
|
||||
ORCHESTRATION_PROJECTOR_NAMES.projects,
|
||||
@@ -129,6 +153,19 @@ function toPersistenceSqlOrDecodeError(sqlOperation: string, decodeOperation: st
|
||||
: toPersistenceSqlError(sqlOperation)(cause);
|
||||
}
|
||||
|
||||
const decodeModelSelection = (input: {
|
||||
readonly provider: "codex" | "claudeAgent";
|
||||
readonly model: string;
|
||||
readonly options: unknown;
|
||||
}) =>
|
||||
decodeModelSelectionSchema({
|
||||
provider: input.provider,
|
||||
model: input.model,
|
||||
...(input.options !== null && input.options !== undefined ? { options: input.options } : {}),
|
||||
}).pipe(
|
||||
Effect.mapError(toPersistenceDecodeError("ProjectionSnapshotQuery.decodeModelSelection")),
|
||||
);
|
||||
|
||||
const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
|
||||
@@ -141,7 +178,9 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
project_id AS "projectId",
|
||||
title,
|
||||
workspace_root AS "workspaceRoot",
|
||||
default_provider AS "defaultProvider",
|
||||
default_model AS "defaultModel",
|
||||
default_model_options_json AS "defaultModelOptions",
|
||||
scripts_json AS "scripts",
|
||||
created_at AS "createdAt",
|
||||
updated_at AS "updatedAt",
|
||||
@@ -160,7 +199,9 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
thread_id AS "threadId",
|
||||
project_id AS "projectId",
|
||||
title,
|
||||
provider,
|
||||
model,
|
||||
model_options_json AS "modelOptions",
|
||||
runtime_mode AS "runtimeMode",
|
||||
interaction_mode AS "interactionMode",
|
||||
branch,
|
||||
@@ -531,36 +572,65 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
});
|
||||
}
|
||||
|
||||
const projects: Array<OrchestrationProject> = projectRows.map((row) => ({
|
||||
id: row.projectId,
|
||||
title: row.title,
|
||||
workspaceRoot: row.workspaceRoot,
|
||||
defaultModel: row.defaultModel,
|
||||
scripts: row.scripts,
|
||||
createdAt: row.createdAt,
|
||||
updatedAt: row.updatedAt,
|
||||
deletedAt: row.deletedAt,
|
||||
}));
|
||||
const projects: ReadonlyArray<OrchestrationProject> = yield* Effect.forEach(
|
||||
projectRows,
|
||||
(row) => {
|
||||
const defaultModelSelectionEffect: Effect.Effect<
|
||||
OrchestrationProject["defaultModelSelection"],
|
||||
ProjectionRepositoryError
|
||||
> =
|
||||
row.defaultProvider === null || row.defaultModel === null
|
||||
? Effect.succeed(null)
|
||||
: decodeModelSelection({
|
||||
provider: row.defaultProvider,
|
||||
model: row.defaultModel,
|
||||
options: row.defaultModelOptions,
|
||||
});
|
||||
|
||||
const threads: Array<OrchestrationThread> = threadRows.map((row) => ({
|
||||
id: row.threadId,
|
||||
projectId: row.projectId,
|
||||
title: row.title,
|
||||
model: row.model,
|
||||
runtimeMode: row.runtimeMode,
|
||||
interactionMode: row.interactionMode,
|
||||
branch: row.branch,
|
||||
worktreePath: row.worktreePath,
|
||||
latestTurn: latestTurnByThread.get(row.threadId) ?? null,
|
||||
createdAt: row.createdAt,
|
||||
updatedAt: row.updatedAt,
|
||||
deletedAt: row.deletedAt,
|
||||
messages: messagesByThread.get(row.threadId) ?? [],
|
||||
proposedPlans: proposedPlansByThread.get(row.threadId) ?? [],
|
||||
activities: activitiesByThread.get(row.threadId) ?? [],
|
||||
checkpoints: checkpointsByThread.get(row.threadId) ?? [],
|
||||
session: sessionsByThread.get(row.threadId) ?? null,
|
||||
}));
|
||||
return defaultModelSelectionEffect.pipe(
|
||||
Effect.map((defaultModelSelection) => ({
|
||||
id: row.projectId,
|
||||
title: row.title,
|
||||
workspaceRoot: row.workspaceRoot,
|
||||
defaultModelSelection,
|
||||
scripts: row.scripts,
|
||||
createdAt: row.createdAt,
|
||||
updatedAt: row.updatedAt,
|
||||
deletedAt: row.deletedAt,
|
||||
})),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
const threads: ReadonlyArray<OrchestrationThread> = yield* Effect.forEach(
|
||||
threadRows,
|
||||
(row) =>
|
||||
decodeModelSelection({
|
||||
provider: row.provider,
|
||||
model: row.model,
|
||||
options: row.modelOptions,
|
||||
}).pipe(
|
||||
Effect.map((modelSelection) => ({
|
||||
id: row.threadId,
|
||||
projectId: row.projectId,
|
||||
title: row.title,
|
||||
modelSelection,
|
||||
runtimeMode: row.runtimeMode,
|
||||
interactionMode: row.interactionMode,
|
||||
branch: row.branch,
|
||||
worktreePath: row.worktreePath,
|
||||
latestTurn: latestTurnByThread.get(row.threadId) ?? null,
|
||||
createdAt: row.createdAt,
|
||||
updatedAt: row.updatedAt,
|
||||
deletedAt: row.deletedAt,
|
||||
messages: messagesByThread.get(row.threadId) ?? [],
|
||||
proposedPlans: proposedPlansByThread.get(row.threadId) ?? [],
|
||||
activities: activitiesByThread.get(row.threadId) ?? [],
|
||||
checkpoints: checkpointsByThread.get(row.threadId) ?? [],
|
||||
session: sessionsByThread.get(row.threadId) ?? null,
|
||||
})),
|
||||
),
|
||||
);
|
||||
|
||||
const snapshot = {
|
||||
snapshotSequence: computeSnapshotSequence(stateRows),
|
||||
|
||||
@@ -63,6 +63,9 @@ async function waitFor(
|
||||
return poll();
|
||||
}
|
||||
|
||||
const inferTestProviderForModel = (model: string): "codex" | "claudeAgent" =>
|
||||
model.startsWith("claude-") ? "claudeAgent" : "codex";
|
||||
|
||||
describe("ProviderCommandReactor", () => {
|
||||
let runtime: ManagedRuntime.ManagedRuntime<
|
||||
OrchestrationEngineService | ProviderCommandReactor,
|
||||
@@ -101,6 +104,7 @@ describe("ProviderCommandReactor", () => {
|
||||
const { stateDir } = deriveServerPathsSync(baseDir, undefined);
|
||||
createdStateDirs.add(stateDir);
|
||||
const threadModel = input?.threadModel ?? "gpt-5-codex";
|
||||
const threadProvider = inferTestProviderForModel(threadModel);
|
||||
const runtimeEventPubSub = Effect.runSync(PubSub.unbounded<ProviderRuntimeEvent>());
|
||||
let nextSessionIndex = 1;
|
||||
const runtimeSessions: Array<ProviderSession> = [];
|
||||
@@ -242,7 +246,10 @@ describe("ProviderCommandReactor", () => {
|
||||
projectId: asProjectId("project-1"),
|
||||
title: "Provider Project",
|
||||
workspaceRoot: "/tmp/provider-project",
|
||||
defaultModel: threadModel,
|
||||
defaultModelSelection: {
|
||||
provider: threadProvider,
|
||||
model: threadModel,
|
||||
},
|
||||
createdAt: now,
|
||||
}),
|
||||
);
|
||||
@@ -253,7 +260,10 @@ describe("ProviderCommandReactor", () => {
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
projectId: asProjectId("project-1"),
|
||||
title: "Thread",
|
||||
model: threadModel,
|
||||
modelSelection: {
|
||||
provider: threadProvider,
|
||||
model: threadModel,
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
branch: null,
|
||||
@@ -328,10 +338,10 @@ describe("ProviderCommandReactor", () => {
|
||||
text: "hello fast mode",
|
||||
attachments: [],
|
||||
},
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
modelOptions: {
|
||||
codex: {
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
options: {
|
||||
reasoningEffort: "high",
|
||||
fastMode: true,
|
||||
},
|
||||
@@ -380,10 +390,10 @@ describe("ProviderCommandReactor", () => {
|
||||
text: "hello with effort",
|
||||
attachments: [],
|
||||
},
|
||||
provider: "claudeAgent",
|
||||
model: "claude-sonnet-4-6",
|
||||
modelOptions: {
|
||||
claudeAgent: {
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-sonnet-4-6",
|
||||
options: {
|
||||
effort: "max",
|
||||
},
|
||||
},
|
||||
@@ -430,10 +440,10 @@ describe("ProviderCommandReactor", () => {
|
||||
text: "hello with fast mode",
|
||||
attachments: [],
|
||||
},
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
modelOptions: {
|
||||
claudeAgent: {
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
options: {
|
||||
fastMode: true,
|
||||
},
|
||||
},
|
||||
@@ -518,7 +528,10 @@ describe("ProviderCommandReactor", () => {
|
||||
text: "hello claude",
|
||||
attachments: [],
|
||||
},
|
||||
provider: "claudeAgent",
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
createdAt: now,
|
||||
@@ -552,50 +565,41 @@ describe("ProviderCommandReactor", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects a turn when the requested model belongs to a different provider", async () => {
|
||||
it("allows custom model strings on the thread's explicit provider", 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-model-provider-mismatch"),
|
||||
commandId: CommandId.makeUnsafe("cmd-turn-start-custom-model"),
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
message: {
|
||||
messageId: asMessageId("user-message-model-provider-mismatch"),
|
||||
messageId: asMessageId("user-message-custom-model"),
|
||||
role: "user",
|
||||
text: "hello",
|
||||
attachments: [],
|
||||
},
|
||||
model: "claude-sonnet-4-6",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "claude-sonnet-4-6",
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
createdAt: now,
|
||||
}),
|
||||
);
|
||||
|
||||
await waitFor(async () => {
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const thread = readModel.threads.find(
|
||||
(entry) => entry.id === ThreadId.makeUnsafe("thread-1"),
|
||||
);
|
||||
return (
|
||||
thread?.activities.some((activity) => activity.kind === "provider.turn.start.failed") ??
|
||||
false
|
||||
);
|
||||
await waitFor(() => harness.startSession.mock.calls.length === 1);
|
||||
await waitFor(() => harness.sendTurn.mock.calls.length === 1);
|
||||
|
||||
expect(harness.startSession.mock.calls[0]?.[1]).toMatchObject({
|
||||
provider: "codex",
|
||||
model: "claude-sonnet-4-6",
|
||||
});
|
||||
|
||||
expect(harness.startSession).not.toHaveBeenCalled();
|
||||
expect(harness.sendTurn).not.toHaveBeenCalled();
|
||||
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.makeUnsafe("thread-1"));
|
||||
expect(
|
||||
thread?.activities.find((activity) => activity.kind === "provider.turn.start.failed"),
|
||||
).toMatchObject({
|
||||
payload: {
|
||||
detail: expect.stringContaining("does not belong to provider 'codex'"),
|
||||
},
|
||||
expect(harness.sendTurn.mock.calls[0]?.[0]).toMatchObject({
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
model: "claude-sonnet-4-6",
|
||||
});
|
||||
});
|
||||
|
||||
@@ -660,10 +664,10 @@ describe("ProviderCommandReactor", () => {
|
||||
text: "first claude turn",
|
||||
attachments: [],
|
||||
},
|
||||
provider: "claudeAgent",
|
||||
model: "claude-sonnet-4-6",
|
||||
modelOptions: {
|
||||
claudeAgent: {
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-sonnet-4-6",
|
||||
options: {
|
||||
effort: "medium",
|
||||
},
|
||||
},
|
||||
@@ -687,10 +691,10 @@ describe("ProviderCommandReactor", () => {
|
||||
text: "second claude turn",
|
||||
attachments: [],
|
||||
},
|
||||
provider: "claudeAgent",
|
||||
model: "claude-sonnet-4-6",
|
||||
modelOptions: {
|
||||
claudeAgent: {
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-sonnet-4-6",
|
||||
options: {
|
||||
effort: "max",
|
||||
},
|
||||
},
|
||||
@@ -800,6 +804,50 @@ describe("ProviderCommandReactor", () => {
|
||||
expect(thread?.session?.runtimeMode).toBe("approval-required");
|
||||
});
|
||||
|
||||
it("does not inject derived model options when restarting claude on runtime mode changes", async () => {
|
||||
const harness = await createHarness({
|
||||
threadModel: "claude-opus-4-6",
|
||||
});
|
||||
const now = new Date().toISOString();
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
type: "thread.session.set",
|
||||
commandId: CommandId.makeUnsafe("cmd-session-set-runtime-mode-claude"),
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
session: {
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
status: "ready",
|
||||
providerName: "claudeAgent",
|
||||
runtimeMode: "full-access",
|
||||
activeTurnId: null,
|
||||
lastError: null,
|
||||
updatedAt: now,
|
||||
},
|
||||
createdAt: now,
|
||||
}),
|
||||
);
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
type: "thread.runtime-mode.set",
|
||||
commandId: CommandId.makeUnsafe("cmd-runtime-mode-set-claude-no-options"),
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
runtimeMode: "approval-required",
|
||||
createdAt: now,
|
||||
}),
|
||||
);
|
||||
|
||||
await waitFor(() => harness.startSession.mock.calls.length === 1);
|
||||
|
||||
expect(harness.startSession.mock.calls[0]?.[1]).toMatchObject({
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
runtimeMode: "approval-required",
|
||||
});
|
||||
expect(harness.startSession.mock.calls[0]?.[1]).not.toHaveProperty("modelOptions");
|
||||
});
|
||||
|
||||
it("rejects provider changes after a thread is already bound to a session provider", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
@@ -835,7 +883,10 @@ describe("ProviderCommandReactor", () => {
|
||||
text: "second",
|
||||
attachments: [],
|
||||
},
|
||||
provider: "claudeAgent",
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
createdAt: now,
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
CommandId,
|
||||
DEFAULT_GIT_TEXT_GENERATION_MODEL,
|
||||
EventId,
|
||||
type ModelSelection,
|
||||
type OrchestrationEvent,
|
||||
type ProviderModelOptions,
|
||||
ProviderKind,
|
||||
@@ -15,6 +16,7 @@ import {
|
||||
} from "@t3tools/contracts";
|
||||
import { Cache, Cause, Duration, Effect, Layer, Option, Schema, Stream } from "effect";
|
||||
import { makeDrainableWorker } from "@t3tools/shared/DrainableWorker";
|
||||
import { toProviderModelOptions } from "@t3tools/shared/model";
|
||||
|
||||
import { resolveThreadWorkspaceCwd } from "../../checkpointing/Utils.ts";
|
||||
import { GitCore } from "../../git/Services/GitCore.ts";
|
||||
@@ -26,7 +28,6 @@ import {
|
||||
ProviderCommandReactor,
|
||||
type ProviderCommandReactorShape,
|
||||
} from "../Services/ProviderCommandReactor.ts";
|
||||
import { inferProviderForModel } from "@t3tools/shared/model";
|
||||
|
||||
type ProviderIntentEvent = Extract<
|
||||
OrchestrationEvent,
|
||||
@@ -215,8 +216,7 @@ const make = Effect.gen(function* () {
|
||||
threadId: ThreadId,
|
||||
createdAt: string,
|
||||
options?: {
|
||||
readonly provider?: ProviderKind;
|
||||
readonly model?: string;
|
||||
readonly modelSelection?: ModelSelection;
|
||||
readonly modelOptions?: ProviderModelOptions;
|
||||
readonly providerOptions?: ProviderStartOptions;
|
||||
},
|
||||
@@ -233,26 +233,23 @@ const make = Effect.gen(function* () {
|
||||
)
|
||||
? thread.session.providerName
|
||||
: undefined;
|
||||
const threadProvider: ProviderKind = currentProvider ?? inferProviderForModel(thread.model);
|
||||
if (options?.provider !== undefined && options.provider !== threadProvider) {
|
||||
return yield* new ProviderAdapterRequestError({
|
||||
provider: threadProvider,
|
||||
method: "thread.turn.start",
|
||||
detail: `Thread '${threadId}' is bound to provider '${threadProvider}' and cannot switch to '${options.provider}'.`,
|
||||
});
|
||||
}
|
||||
const requestedModelSelection = options?.modelSelection;
|
||||
const threadProvider: ProviderKind = currentProvider ?? thread.modelSelection.provider;
|
||||
if (
|
||||
options?.model !== undefined &&
|
||||
inferProviderForModel(options.model, threadProvider) !== threadProvider
|
||||
requestedModelSelection !== undefined &&
|
||||
requestedModelSelection.provider !== threadProvider
|
||||
) {
|
||||
return yield* new ProviderAdapterRequestError({
|
||||
provider: threadProvider,
|
||||
method: "thread.turn.start",
|
||||
detail: `Model '${options.model}' does not belong to provider '${threadProvider}' for thread '${threadId}'.`,
|
||||
detail: `Thread '${threadId}' is bound to provider '${threadProvider}' and cannot switch to '${requestedModelSelection.provider}'.`,
|
||||
});
|
||||
}
|
||||
const preferredProvider: ProviderKind = currentProvider ?? threadProvider;
|
||||
const desiredModel = options?.model ?? thread.model;
|
||||
const desiredModelSelection = requestedModelSelection ?? thread.modelSelection;
|
||||
const desiredModel = desiredModelSelection.model;
|
||||
const desiredModelOptions =
|
||||
options?.modelOptions ?? toProviderModelOptions(desiredModelSelection);
|
||||
const effectiveCwd = resolveThreadWorkspaceCwd({
|
||||
thread,
|
||||
projects: readModel.projects,
|
||||
@@ -263,18 +260,13 @@ const make = Effect.gen(function* () {
|
||||
.listSessions()
|
||||
.pipe(Effect.map((sessions) => sessions.find((session) => session.threadId === threadId)));
|
||||
|
||||
const startProviderSession = (input?: {
|
||||
readonly resumeCursor?: unknown;
|
||||
readonly provider?: ProviderKind;
|
||||
}) =>
|
||||
const startProviderSession = (input?: { readonly resumeCursor?: unknown }) =>
|
||||
providerService.startSession(threadId, {
|
||||
threadId,
|
||||
...((input?.provider ?? preferredProvider)
|
||||
? { provider: input?.provider ?? preferredProvider }
|
||||
: {}),
|
||||
...(preferredProvider ? { provider: preferredProvider } : {}),
|
||||
...(effectiveCwd ? { cwd: effectiveCwd } : {}),
|
||||
...(desiredModel ? { model: desiredModel } : {}),
|
||||
...(options?.modelOptions !== undefined ? { modelOptions: options.modelOptions } : {}),
|
||||
...(desiredModelOptions !== undefined ? { modelOptions: desiredModelOptions } : {}),
|
||||
...(options?.providerOptions !== undefined
|
||||
? { providerOptions: options.providerOptions }
|
||||
: {}),
|
||||
@@ -303,13 +295,16 @@ const make = Effect.gen(function* () {
|
||||
if (existingSessionThreadId) {
|
||||
const runtimeModeChanged = thread.runtimeMode !== thread.session?.runtimeMode;
|
||||
const providerChanged =
|
||||
options?.provider !== undefined && options.provider !== currentProvider;
|
||||
requestedModelSelection !== undefined &&
|
||||
requestedModelSelection.provider !== currentProvider;
|
||||
const activeSession = yield* resolveActiveSession(existingSessionThreadId);
|
||||
const sessionModelSwitch =
|
||||
currentProvider === undefined
|
||||
? "in-session"
|
||||
: (yield* providerService.getCapabilities(currentProvider)).sessionModelSwitch;
|
||||
const modelChanged = options?.model !== undefined && options.model !== activeSession?.model;
|
||||
const modelChanged =
|
||||
requestedModelSelection !== undefined &&
|
||||
requestedModelSelection.model !== activeSession?.model;
|
||||
const shouldRestartForModelChange = modelChanged && sessionModelSwitch === "restart-session";
|
||||
const previousModelOptions = threadModelOptions.get(threadId);
|
||||
const shouldRestartForModelOptionsChange =
|
||||
@@ -334,7 +329,7 @@ const make = Effect.gen(function* () {
|
||||
threadId,
|
||||
existingSessionThreadId,
|
||||
currentProvider,
|
||||
desiredProvider: options?.provider ?? currentProvider,
|
||||
desiredProvider: desiredModelSelection.provider,
|
||||
currentRuntimeMode: thread.session?.runtimeMode,
|
||||
desiredRuntimeMode: thread.runtimeMode,
|
||||
runtimeModeChanged,
|
||||
@@ -344,10 +339,9 @@ const make = Effect.gen(function* () {
|
||||
shouldRestartForModelOptionsChange,
|
||||
hasResumeCursor: resumeCursor !== undefined,
|
||||
});
|
||||
const restartedSession = yield* startProviderSession({
|
||||
...(resumeCursor !== undefined ? { resumeCursor } : {}),
|
||||
...(options?.provider !== undefined ? { provider: options.provider } : {}),
|
||||
});
|
||||
const restartedSession = yield* startProviderSession(
|
||||
resumeCursor !== undefined ? { resumeCursor } : undefined,
|
||||
);
|
||||
yield* Effect.logInfo("provider command reactor restarted provider session", {
|
||||
threadId,
|
||||
previousSessionId: existingSessionThreadId,
|
||||
@@ -359,9 +353,7 @@ const make = Effect.gen(function* () {
|
||||
return restartedSession.threadId;
|
||||
}
|
||||
|
||||
const startedSession = yield* startProviderSession(
|
||||
options?.provider !== undefined ? { provider: options.provider } : undefined,
|
||||
);
|
||||
const startedSession = yield* startProviderSession(undefined);
|
||||
yield* bindSessionToThread(startedSession);
|
||||
return startedSession.threadId;
|
||||
});
|
||||
@@ -370,8 +362,7 @@ const make = Effect.gen(function* () {
|
||||
readonly threadId: ThreadId;
|
||||
readonly messageText: string;
|
||||
readonly attachments?: ReadonlyArray<ChatAttachment>;
|
||||
readonly provider?: ProviderKind;
|
||||
readonly model?: string;
|
||||
readonly modelSelection?: ModelSelection;
|
||||
readonly modelOptions?: ProviderModelOptions;
|
||||
readonly providerOptions?: ProviderStartOptions;
|
||||
readonly interactionMode?: "default" | "plan";
|
||||
@@ -382,8 +373,7 @@ const make = Effect.gen(function* () {
|
||||
return;
|
||||
}
|
||||
yield* ensureSessionForThread(input.threadId, input.createdAt, {
|
||||
...(input.provider !== undefined ? { provider: input.provider } : {}),
|
||||
...(input.model !== undefined ? { model: input.model } : {}),
|
||||
...(input.modelSelection !== undefined ? { modelSelection: input.modelSelection } : {}),
|
||||
...(input.modelOptions !== undefined ? { modelOptions: input.modelOptions } : {}),
|
||||
...(input.providerOptions !== undefined ? { providerOptions: input.providerOptions } : {}),
|
||||
});
|
||||
@@ -404,7 +394,8 @@ const make = Effect.gen(function* () {
|
||||
activeSession === undefined
|
||||
? "in-session"
|
||||
: (yield* providerService.getCapabilities(activeSession.provider)).sessionModelSwitch;
|
||||
const modelForTurn = sessionModelSwitch === "unsupported" ? activeSession?.model : input.model;
|
||||
const modelForTurn =
|
||||
sessionModelSwitch === "unsupported" ? activeSession?.model : input.modelSelection?.model;
|
||||
|
||||
yield* providerService.sendTurn({
|
||||
threadId: input.threadId,
|
||||
@@ -520,15 +511,18 @@ const make = Effect.gen(function* () {
|
||||
...(message.attachments !== undefined ? { attachments: message.attachments } : {}),
|
||||
}).pipe(Effect.forkScoped);
|
||||
|
||||
const requestedModelOptions = event.payload.modelSelection
|
||||
? toProviderModelOptions(event.payload.modelSelection)
|
||||
: undefined;
|
||||
|
||||
yield* sendTurnForThread({
|
||||
threadId: event.payload.threadId,
|
||||
messageText: message.text,
|
||||
...(message.attachments !== undefined ? { attachments: message.attachments } : {}),
|
||||
...(event.payload.provider !== undefined ? { provider: event.payload.provider } : {}),
|
||||
...(event.payload.model !== undefined ? { model: event.payload.model } : {}),
|
||||
...(event.payload.modelOptions !== undefined
|
||||
? { modelOptions: event.payload.modelOptions }
|
||||
...(event.payload.modelSelection !== undefined
|
||||
? { modelSelection: event.payload.modelSelection }
|
||||
: {}),
|
||||
...(requestedModelOptions !== undefined ? { modelOptions: requestedModelOptions } : {}),
|
||||
...(event.payload.providerOptions !== undefined
|
||||
? { providerOptions: event.payload.providerOptions }
|
||||
: {}),
|
||||
|
||||
@@ -187,7 +187,10 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
projectId: asProjectId("project-1"),
|
||||
title: "Provider Project",
|
||||
workspaceRoot,
|
||||
defaultModel: "gpt-5-codex",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
createdAt,
|
||||
}),
|
||||
);
|
||||
@@ -198,7 +201,10 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
projectId: asProjectId("project-1"),
|
||||
title: "Thread",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
branch: null,
|
||||
@@ -724,7 +730,10 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
threadId: sourceThreadId,
|
||||
projectId: asProjectId("project-1"),
|
||||
title: "Plan Source",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
interactionMode: "plan",
|
||||
runtimeMode: "approval-required",
|
||||
branch: null,
|
||||
@@ -756,7 +765,10 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
threadId: targetThreadId,
|
||||
projectId: asProjectId("project-1"),
|
||||
title: "Plan Target",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
branch: null,
|
||||
@@ -905,7 +917,10 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
threadId: sourceThreadId,
|
||||
projectId: asProjectId("project-1"),
|
||||
title: "Plan Source",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
interactionMode: "plan",
|
||||
runtimeMode: "approval-required",
|
||||
branch: null,
|
||||
@@ -1055,7 +1070,10 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
threadId: sourceThreadId,
|
||||
projectId: asProjectId("project-1"),
|
||||
title: "Plan Source",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
interactionMode: "plan",
|
||||
runtimeMode: "approval-required",
|
||||
branch: null,
|
||||
@@ -1087,7 +1105,10 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
threadId: targetThreadId,
|
||||
projectId: asProjectId("project-1"),
|
||||
title: "Plan Target",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
branch: null,
|
||||
|
||||
@@ -28,7 +28,10 @@ const readModel: OrchestrationReadModel = {
|
||||
id: ProjectId.makeUnsafe("project-a"),
|
||||
title: "Project A",
|
||||
workspaceRoot: "/tmp/project-a",
|
||||
defaultModel: "gpt-5-codex",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
scripts: [],
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
@@ -38,7 +41,10 @@ const readModel: OrchestrationReadModel = {
|
||||
id: ProjectId.makeUnsafe("project-b"),
|
||||
title: "Project B",
|
||||
workspaceRoot: "/tmp/project-b",
|
||||
defaultModel: "gpt-5-codex",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
scripts: [],
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
@@ -50,7 +56,10 @@ const readModel: OrchestrationReadModel = {
|
||||
id: ThreadId.makeUnsafe("thread-1"),
|
||||
projectId: ProjectId.makeUnsafe("project-a"),
|
||||
title: "Thread A",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
@@ -69,7 +78,10 @@ const readModel: OrchestrationReadModel = {
|
||||
id: ThreadId.makeUnsafe("thread-2"),
|
||||
projectId: ProjectId.makeUnsafe("project-b"),
|
||||
title: "Thread B",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
@@ -144,7 +156,10 @@ describe("commandInvariants", () => {
|
||||
threadId: ThreadId.makeUnsafe("thread-3"),
|
||||
projectId: ProjectId.makeUnsafe("project-a"),
|
||||
title: "new",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
@@ -165,7 +180,10 @@ describe("commandInvariants", () => {
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
projectId: ProjectId.makeUnsafe("project-a"),
|
||||
title: "dup",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
|
||||
@@ -59,7 +59,7 @@ describe("decider project scripts", () => {
|
||||
projectId: asProjectId("project-scripts"),
|
||||
title: "Scripts",
|
||||
workspaceRoot: "/tmp/scripts",
|
||||
defaultModel: null,
|
||||
defaultModelSelection: null,
|
||||
scripts: [],
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
@@ -113,7 +113,7 @@ describe("decider project scripts", () => {
|
||||
projectId: asProjectId("project-1"),
|
||||
title: "Project",
|
||||
workspaceRoot: "/tmp/project",
|
||||
defaultModel: null,
|
||||
defaultModelSelection: null,
|
||||
scripts: [],
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
@@ -136,7 +136,10 @@ describe("decider project scripts", () => {
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
projectId: asProjectId("project-1"),
|
||||
title: "Thread",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
branch: null,
|
||||
@@ -159,10 +162,10 @@ describe("decider project scripts", () => {
|
||||
text: "hello",
|
||||
attachments: [],
|
||||
},
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
modelOptions: {
|
||||
codex: {
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
options: {
|
||||
reasoningEffort: "high",
|
||||
fastMode: true,
|
||||
},
|
||||
@@ -189,10 +192,10 @@ describe("decider project scripts", () => {
|
||||
expect(turnStartEvent.payload).toMatchObject({
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
messageId: asMessageId("message-user-1"),
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
modelOptions: {
|
||||
codex: {
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
options: {
|
||||
reasoningEffort: "high",
|
||||
fastMode: true,
|
||||
},
|
||||
@@ -220,7 +223,7 @@ describe("decider project scripts", () => {
|
||||
projectId: asProjectId("project-1"),
|
||||
title: "Project",
|
||||
workspaceRoot: "/tmp/project",
|
||||
defaultModel: null,
|
||||
defaultModelSelection: null,
|
||||
scripts: [],
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
@@ -243,7 +246,10 @@ describe("decider project scripts", () => {
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
projectId: asProjectId("project-1"),
|
||||
title: "Thread",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
@@ -299,7 +305,7 @@ describe("decider project scripts", () => {
|
||||
projectId: asProjectId("project-1"),
|
||||
title: "Project",
|
||||
workspaceRoot: "/tmp/project",
|
||||
defaultModel: null,
|
||||
defaultModelSelection: null,
|
||||
scripts: [],
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
@@ -322,7 +328,10 @@ describe("decider project scripts", () => {
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
projectId: asProjectId("project-1"),
|
||||
title: "Thread",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
branch: null,
|
||||
|
||||
@@ -77,7 +77,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
projectId: command.projectId,
|
||||
title: command.title,
|
||||
workspaceRoot: command.workspaceRoot,
|
||||
defaultModel: command.defaultModel ?? null,
|
||||
defaultModelSelection: command.defaultModelSelection ?? null,
|
||||
scripts: [],
|
||||
createdAt: command.createdAt,
|
||||
updatedAt: command.createdAt,
|
||||
@@ -104,7 +104,9 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
projectId: command.projectId,
|
||||
...(command.title !== undefined ? { title: command.title } : {}),
|
||||
...(command.workspaceRoot !== undefined ? { workspaceRoot: command.workspaceRoot } : {}),
|
||||
...(command.defaultModel !== undefined ? { defaultModel: command.defaultModel } : {}),
|
||||
...(command.defaultModelSelection !== undefined
|
||||
? { defaultModelSelection: command.defaultModelSelection }
|
||||
: {}),
|
||||
...(command.scripts !== undefined ? { scripts: command.scripts } : {}),
|
||||
updatedAt: occurredAt,
|
||||
},
|
||||
@@ -156,7 +158,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
threadId: command.threadId,
|
||||
projectId: command.projectId,
|
||||
title: command.title,
|
||||
model: command.model,
|
||||
modelSelection: command.modelSelection,
|
||||
runtimeMode: command.runtimeMode,
|
||||
interactionMode: command.interactionMode,
|
||||
branch: command.branch,
|
||||
@@ -207,7 +209,9 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
payload: {
|
||||
threadId: command.threadId,
|
||||
...(command.title !== undefined ? { title: command.title } : {}),
|
||||
...(command.model !== undefined ? { model: command.model } : {}),
|
||||
...(command.modelSelection !== undefined
|
||||
? { modelSelection: command.modelSelection }
|
||||
: {}),
|
||||
...(command.branch !== undefined ? { branch: command.branch } : {}),
|
||||
...(command.worktreePath !== undefined ? { worktreePath: command.worktreePath } : {}),
|
||||
updatedAt: occurredAt,
|
||||
@@ -323,9 +327,9 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
payload: {
|
||||
threadId: command.threadId,
|
||||
messageId: command.message.messageId,
|
||||
...(command.provider !== undefined ? { provider: command.provider } : {}),
|
||||
...(command.model !== undefined ? { model: command.model } : {}),
|
||||
...(command.modelOptions !== undefined ? { modelOptions: command.modelOptions } : {}),
|
||||
...(command.modelSelection !== undefined
|
||||
? { modelSelection: command.modelSelection }
|
||||
: {}),
|
||||
...(command.providerOptions !== undefined
|
||||
? { providerOptions: command.providerOptions }
|
||||
: {}),
|
||||
|
||||
@@ -56,7 +56,10 @@ describe("orchestration projector", () => {
|
||||
threadId: "thread-1",
|
||||
projectId: "project-1",
|
||||
title: "demo",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
@@ -73,7 +76,10 @@ describe("orchestration projector", () => {
|
||||
id: "thread-1",
|
||||
projectId: "project-1",
|
||||
title: "demo",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
interactionMode: "default",
|
||||
branch: null,
|
||||
@@ -110,7 +116,10 @@ describe("orchestration projector", () => {
|
||||
// missing required threadId
|
||||
projectId: "project-1",
|
||||
title: "demo",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
createdAt: now,
|
||||
@@ -170,7 +179,10 @@ describe("orchestration projector", () => {
|
||||
threadId: "thread-1",
|
||||
projectId: "project-1",
|
||||
title: "demo",
|
||||
model: "gpt-5.3-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
@@ -233,7 +245,10 @@ describe("orchestration projector", () => {
|
||||
threadId: "thread-1",
|
||||
projectId: "project-1",
|
||||
title: "demo",
|
||||
model: "gpt-5.3-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
@@ -287,7 +302,10 @@ describe("orchestration projector", () => {
|
||||
threadId: "thread-1",
|
||||
projectId: "project-1",
|
||||
title: "demo",
|
||||
model: "gpt-5.3-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
@@ -371,7 +389,10 @@ describe("orchestration projector", () => {
|
||||
threadId: "thread-1",
|
||||
projectId: "project-1",
|
||||
title: "demo",
|
||||
model: "gpt-5.3-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
@@ -583,7 +604,10 @@ describe("orchestration projector", () => {
|
||||
threadId: "thread-revert",
|
||||
projectId: "project-1",
|
||||
title: "demo",
|
||||
model: "gpt-5.3-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
@@ -733,7 +757,10 @@ describe("orchestration projector", () => {
|
||||
threadId: "thread-capped",
|
||||
projectId: "project-1",
|
||||
title: "capped",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
|
||||
@@ -181,7 +181,7 @@ export function projectEvent(
|
||||
id: payload.projectId,
|
||||
title: payload.title,
|
||||
workspaceRoot: payload.workspaceRoot,
|
||||
defaultModel: payload.defaultModel,
|
||||
defaultModelSelection: payload.defaultModelSelection,
|
||||
scripts: payload.scripts,
|
||||
createdAt: payload.createdAt,
|
||||
updatedAt: payload.updatedAt,
|
||||
@@ -211,8 +211,8 @@ export function projectEvent(
|
||||
...(payload.workspaceRoot !== undefined
|
||||
? { workspaceRoot: payload.workspaceRoot }
|
||||
: {}),
|
||||
...(payload.defaultModel !== undefined
|
||||
? { defaultModel: payload.defaultModel }
|
||||
...(payload.defaultModelSelection !== undefined
|
||||
? { defaultModelSelection: payload.defaultModelSelection }
|
||||
: {}),
|
||||
...(payload.scripts !== undefined ? { scripts: payload.scripts } : {}),
|
||||
updatedAt: payload.updatedAt,
|
||||
@@ -252,7 +252,7 @@ export function projectEvent(
|
||||
id: payload.threadId,
|
||||
projectId: payload.projectId,
|
||||
title: payload.title,
|
||||
model: payload.model,
|
||||
modelSelection: payload.modelSelection,
|
||||
runtimeMode: payload.runtimeMode,
|
||||
interactionMode: payload.interactionMode,
|
||||
branch: payload.branch,
|
||||
@@ -295,7 +295,9 @@ export function projectEvent(
|
||||
...nextBase,
|
||||
threads: updateThread(nextBase.threads, payload.threadId, {
|
||||
...(payload.title !== undefined ? { title: payload.title } : {}),
|
||||
...(payload.model !== undefined ? { model: payload.model } : {}),
|
||||
...(payload.modelSelection !== undefined
|
||||
? { modelSelection: payload.modelSelection }
|
||||
: {}),
|
||||
...(payload.branch !== undefined ? { branch: payload.branch } : {}),
|
||||
...(payload.worktreePath !== undefined ? { worktreePath: payload.worktreePath } : {}),
|
||||
updatedAt: payload.updatedAt,
|
||||
|
||||
@@ -35,7 +35,7 @@ layer("OrchestrationEventStore", (it) => {
|
||||
projectId: ProjectId.makeUnsafe("project-roundtrip"),
|
||||
title: "Roundtrip Project",
|
||||
workspaceRoot: "/tmp/project-roundtrip",
|
||||
defaultModel: null,
|
||||
defaultModelSelection: null,
|
||||
scripts: [],
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
||||
import * as SqlSchema from "effect/unstable/sql/SqlSchema";
|
||||
import { Effect, Layer, Option, Schema, Struct } from "effect";
|
||||
|
||||
import { toPersistenceDecodeError, toPersistenceSqlError } from "../Errors.ts";
|
||||
import { Effect, Layer, Option, Schema } from "effect";
|
||||
|
||||
import { ModelSelection, ProjectScript } from "@t3tools/contracts";
|
||||
import {
|
||||
PersistenceDecodeError,
|
||||
toPersistenceDecodeError,
|
||||
toPersistenceSqlError,
|
||||
} from "../Errors.ts";
|
||||
import {
|
||||
DeleteProjectionProjectInput,
|
||||
GetProjectionProjectInput,
|
||||
@@ -11,69 +15,104 @@ import {
|
||||
ProjectionProjectRepository,
|
||||
type ProjectionProjectRepositoryShape,
|
||||
} from "../Services/ProjectionProjects.ts";
|
||||
import { ProjectScript } from "@t3tools/contracts";
|
||||
|
||||
// Makes sure that the scripts are parsed from the JSON string the DB returns
|
||||
const ProjectionProjectDbRowSchema = ProjectionProject.mapFields(
|
||||
Struct.assign({ scripts: Schema.fromJsonString(Schema.Array(ProjectScript)) }),
|
||||
);
|
||||
const ProjectionProjectDbRow = Schema.Struct({
|
||||
projectId: ProjectionProject.fields.projectId,
|
||||
title: ProjectionProject.fields.title,
|
||||
workspaceRoot: ProjectionProject.fields.workspaceRoot,
|
||||
defaultProvider: Schema.NullOr(Schema.Literals(["codex", "claudeAgent"])),
|
||||
defaultModel: Schema.NullOr(Schema.String),
|
||||
defaultModelOptions: Schema.NullOr(Schema.fromJsonString(Schema.Unknown)),
|
||||
scripts: Schema.fromJsonString(Schema.Array(ProjectScript)),
|
||||
createdAt: ProjectionProject.fields.createdAt,
|
||||
updatedAt: ProjectionProject.fields.updatedAt,
|
||||
deletedAt: ProjectionProject.fields.deletedAt,
|
||||
});
|
||||
type ProjectionProjectDbRow = typeof ProjectionProjectDbRow.Type;
|
||||
|
||||
function toPersistenceSqlOrDecodeError(sqlOperation: string, decodeOperation: string) {
|
||||
return (cause: unknown) =>
|
||||
Schema.isSchemaError(cause)
|
||||
? toPersistenceDecodeError(decodeOperation)(cause)
|
||||
: toPersistenceSqlError(sqlOperation)(cause);
|
||||
const decodeModelSelectionSync = Schema.decodeUnknownSync(ModelSelection);
|
||||
|
||||
function decodeDefaultModelSelection(
|
||||
row: ProjectionProjectDbRow,
|
||||
): Effect.Effect<ProjectionProject["defaultModelSelection"], PersistenceDecodeError> {
|
||||
if (row.defaultProvider === null || row.defaultModel === null) {
|
||||
return Effect.succeed(null);
|
||||
}
|
||||
return Effect.try({
|
||||
try: () =>
|
||||
decodeModelSelectionSync({
|
||||
provider: row.defaultProvider,
|
||||
model: row.defaultModel,
|
||||
...(row.defaultModelOptions !== null ? { options: row.defaultModelOptions } : {}),
|
||||
}),
|
||||
catch: (error) =>
|
||||
toPersistenceDecodeError("ProjectionProjectRepository.decodeDefaultModelSelection")(
|
||||
error as Schema.SchemaError,
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
const makeProjectionProjectRepository = Effect.gen(function* () {
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
|
||||
const upsertProjectionProjectRow = SqlSchema.void({
|
||||
Request: ProjectionProjectDbRowSchema,
|
||||
Request: ProjectionProject,
|
||||
execute: (row) =>
|
||||
sql`
|
||||
INSERT INTO projection_projects (
|
||||
project_id,
|
||||
title,
|
||||
workspace_root,
|
||||
default_model,
|
||||
scripts_json,
|
||||
created_at,
|
||||
updated_at,
|
||||
deleted_at
|
||||
)
|
||||
VALUES (
|
||||
${row.projectId},
|
||||
${row.title},
|
||||
${row.workspaceRoot},
|
||||
${row.defaultModel},
|
||||
${row.scripts},
|
||||
${row.createdAt},
|
||||
${row.updatedAt},
|
||||
${row.deletedAt}
|
||||
)
|
||||
ON CONFLICT (project_id)
|
||||
DO UPDATE SET
|
||||
title = excluded.title,
|
||||
workspace_root = excluded.workspace_root,
|
||||
default_model = excluded.default_model,
|
||||
scripts_json = excluded.scripts_json,
|
||||
created_at = excluded.created_at,
|
||||
updated_at = excluded.updated_at,
|
||||
deleted_at = excluded.deleted_at
|
||||
`,
|
||||
INSERT INTO projection_projects (
|
||||
project_id,
|
||||
title,
|
||||
workspace_root,
|
||||
default_provider,
|
||||
default_model,
|
||||
default_model_options_json,
|
||||
scripts_json,
|
||||
created_at,
|
||||
updated_at,
|
||||
deleted_at
|
||||
)
|
||||
VALUES (
|
||||
${row.projectId},
|
||||
${row.title},
|
||||
${row.workspaceRoot},
|
||||
${row.defaultModelSelection?.provider ?? null},
|
||||
${row.defaultModelSelection?.model ?? null},
|
||||
${
|
||||
row.defaultModelSelection?.options != null
|
||||
? JSON.stringify(row.defaultModelSelection.options)
|
||||
: null
|
||||
},
|
||||
${JSON.stringify(row.scripts)},
|
||||
${row.createdAt},
|
||||
${row.updatedAt},
|
||||
${row.deletedAt}
|
||||
)
|
||||
ON CONFLICT (project_id)
|
||||
DO UPDATE SET
|
||||
title = excluded.title,
|
||||
workspace_root = excluded.workspace_root,
|
||||
default_provider = excluded.default_provider,
|
||||
default_model = excluded.default_model,
|
||||
default_model_options_json = excluded.default_model_options_json,
|
||||
scripts_json = excluded.scripts_json,
|
||||
created_at = excluded.created_at,
|
||||
updated_at = excluded.updated_at,
|
||||
deleted_at = excluded.deleted_at
|
||||
`,
|
||||
});
|
||||
|
||||
const getProjectionProjectRow = SqlSchema.findOneOption({
|
||||
Request: GetProjectionProjectInput,
|
||||
Result: ProjectionProjectDbRowSchema,
|
||||
Result: ProjectionProjectDbRow,
|
||||
execute: ({ projectId }) =>
|
||||
sql`
|
||||
SELECT
|
||||
project_id AS "projectId",
|
||||
title,
|
||||
workspace_root AS "workspaceRoot",
|
||||
default_provider AS "defaultProvider",
|
||||
default_model AS "defaultModel",
|
||||
default_model_options_json AS "defaultModelOptions",
|
||||
scripts_json AS "scripts",
|
||||
created_at AS "createdAt",
|
||||
updated_at AS "updatedAt",
|
||||
@@ -85,14 +124,16 @@ const makeProjectionProjectRepository = Effect.gen(function* () {
|
||||
|
||||
const listProjectionProjectRows = SqlSchema.findAll({
|
||||
Request: Schema.Void,
|
||||
Result: ProjectionProjectDbRowSchema,
|
||||
Result: ProjectionProjectDbRow,
|
||||
execute: () =>
|
||||
sql`
|
||||
SELECT
|
||||
project_id AS "projectId",
|
||||
title,
|
||||
workspace_root AS "workspaceRoot",
|
||||
default_provider AS "defaultProvider",
|
||||
default_model AS "defaultModel",
|
||||
default_model_options_json AS "defaultModelOptions",
|
||||
scripts_json AS "scripts",
|
||||
created_at AS "createdAt",
|
||||
updated_at AS "updatedAt",
|
||||
@@ -113,40 +154,53 @@ const makeProjectionProjectRepository = Effect.gen(function* () {
|
||||
|
||||
const upsert: ProjectionProjectRepositoryShape["upsert"] = (row) =>
|
||||
upsertProjectionProjectRow(row).pipe(
|
||||
Effect.mapError(
|
||||
toPersistenceSqlOrDecodeError(
|
||||
"ProjectionProjectRepository.upsert:query",
|
||||
"ProjectionProjectRepository.upsert:encodeRequest",
|
||||
),
|
||||
),
|
||||
Effect.mapError(toPersistenceSqlError("ProjectionProjectRepository.upsert:query")),
|
||||
);
|
||||
|
||||
const getById: ProjectionProjectRepositoryShape["getById"] = (input) =>
|
||||
getProjectionProjectRow(input).pipe(
|
||||
Effect.mapError(
|
||||
toPersistenceSqlOrDecodeError(
|
||||
"ProjectionProjectRepository.getById:query",
|
||||
"ProjectionProjectRepository.getById:decodeRow",
|
||||
),
|
||||
),
|
||||
Effect.flatMap((rowOption) =>
|
||||
Option.match(rowOption, {
|
||||
Effect.mapError(toPersistenceSqlError("ProjectionProjectRepository.getById:query")),
|
||||
Effect.flatMap(
|
||||
Option.match({
|
||||
onNone: () => Effect.succeed(Option.none()),
|
||||
onSome: (row) =>
|
||||
Effect.succeed(Option.some(row as Schema.Schema.Type<typeof ProjectionProject>)),
|
||||
decodeDefaultModelSelection(row).pipe(
|
||||
Effect.map((defaultModelSelection) =>
|
||||
Option.some({
|
||||
projectId: row.projectId,
|
||||
title: row.title,
|
||||
workspaceRoot: row.workspaceRoot,
|
||||
defaultModelSelection,
|
||||
scripts: row.scripts,
|
||||
createdAt: row.createdAt,
|
||||
updatedAt: row.updatedAt,
|
||||
deletedAt: row.deletedAt,
|
||||
}),
|
||||
),
|
||||
),
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
const listAll: ProjectionProjectRepositoryShape["listAll"] = () =>
|
||||
listProjectionProjectRows().pipe(
|
||||
Effect.mapError(
|
||||
toPersistenceSqlOrDecodeError(
|
||||
"ProjectionProjectRepository.listAll:query",
|
||||
"ProjectionProjectRepository.listAll:decodeRows",
|
||||
Effect.mapError(toPersistenceSqlError("ProjectionProjectRepository.listAll:query")),
|
||||
Effect.flatMap((rows) =>
|
||||
Effect.forEach(rows, (row) =>
|
||||
decodeDefaultModelSelection(row).pipe(
|
||||
Effect.map((defaultModelSelection) => ({
|
||||
projectId: row.projectId,
|
||||
title: row.title,
|
||||
workspaceRoot: row.workspaceRoot,
|
||||
defaultModelSelection,
|
||||
scripts: row.scripts,
|
||||
createdAt: row.createdAt,
|
||||
updatedAt: row.updatedAt,
|
||||
deletedAt: row.deletedAt,
|
||||
})),
|
||||
),
|
||||
),
|
||||
),
|
||||
Effect.map((rows) => rows as ReadonlyArray<Schema.Schema.Type<typeof ProjectionProject>>),
|
||||
);
|
||||
|
||||
const deleteById: ProjectionProjectRepositoryShape["deleteById"] = (input) =>
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
import { ProjectId, ThreadId } from "@t3tools/contracts";
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import { Effect, Layer, Option } from "effect";
|
||||
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
||||
|
||||
import { SqlitePersistenceMemory } from "./Sqlite.ts";
|
||||
import { ProjectionProjectRepositoryLive } from "./ProjectionProjects.ts";
|
||||
import { ProjectionThreadRepositoryLive } from "./ProjectionThreads.ts";
|
||||
import { ProjectionProjectRepository } from "../Services/ProjectionProjects.ts";
|
||||
import { ProjectionThreadRepository } from "../Services/ProjectionThreads.ts";
|
||||
|
||||
const projectionRepositoriesLayer = it.layer(
|
||||
Layer.mergeAll(
|
||||
ProjectionProjectRepositoryLive.pipe(Layer.provideMerge(SqlitePersistenceMemory)),
|
||||
ProjectionThreadRepositoryLive.pipe(Layer.provideMerge(SqlitePersistenceMemory)),
|
||||
SqlitePersistenceMemory,
|
||||
),
|
||||
);
|
||||
|
||||
projectionRepositoriesLayer("Projection repositories", (it) => {
|
||||
it.effect("stores SQL NULL for missing project model options", () =>
|
||||
Effect.gen(function* () {
|
||||
const projects = yield* ProjectionProjectRepository;
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
|
||||
yield* projects.upsert({
|
||||
projectId: ProjectId.makeUnsafe("project-null-options"),
|
||||
title: "Null options project",
|
||||
workspaceRoot: "/tmp/project-null-options",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.4",
|
||||
},
|
||||
scripts: [],
|
||||
createdAt: "2026-03-24T00:00:00.000Z",
|
||||
updatedAt: "2026-03-24T00:00:00.000Z",
|
||||
deletedAt: null,
|
||||
});
|
||||
|
||||
const rows = yield* sql<{
|
||||
readonly defaultModelOptions: string | null;
|
||||
}>`
|
||||
SELECT default_model_options_json AS "defaultModelOptions"
|
||||
FROM projection_projects
|
||||
WHERE project_id = 'project-null-options'
|
||||
`;
|
||||
const row = rows[0];
|
||||
if (!row) {
|
||||
return yield* Effect.fail(new Error("Expected projection_projects row to exist."));
|
||||
}
|
||||
|
||||
assert.strictEqual(row.defaultModelOptions, null);
|
||||
|
||||
const persisted = yield* projects.getById({
|
||||
projectId: ProjectId.makeUnsafe("project-null-options"),
|
||||
});
|
||||
assert.deepStrictEqual(Option.getOrNull(persisted)?.defaultModelSelection, {
|
||||
provider: "codex",
|
||||
model: "gpt-5.4",
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("stores SQL NULL for missing thread model options", () =>
|
||||
Effect.gen(function* () {
|
||||
const threads = yield* ProjectionThreadRepository;
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
|
||||
yield* threads.upsert({
|
||||
threadId: ThreadId.makeUnsafe("thread-null-options"),
|
||||
projectId: ProjectId.makeUnsafe("project-null-options"),
|
||||
title: "Null options thread",
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
interactionMode: "default",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
latestTurnId: null,
|
||||
createdAt: "2026-03-24T00:00:00.000Z",
|
||||
updatedAt: "2026-03-24T00:00:00.000Z",
|
||||
deletedAt: null,
|
||||
});
|
||||
|
||||
const rows = yield* sql<{
|
||||
readonly modelOptions: string | null;
|
||||
}>`
|
||||
SELECT model_options_json AS "modelOptions"
|
||||
FROM projection_threads
|
||||
WHERE thread_id = 'thread-null-options'
|
||||
`;
|
||||
const row = rows[0];
|
||||
if (!row) {
|
||||
return yield* Effect.fail(new Error("Expected projection_threads row to exist."));
|
||||
}
|
||||
|
||||
assert.strictEqual(row.modelOptions, null);
|
||||
|
||||
const persisted = yield* threads.getById({
|
||||
threadId: ThreadId.makeUnsafe("thread-null-options"),
|
||||
});
|
||||
assert.deepStrictEqual(Option.getOrNull(persisted)?.modelSelection, {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
});
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -1,8 +1,9 @@
|
||||
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
||||
import * as SqlSchema from "effect/unstable/sql/SqlSchema";
|
||||
import { Effect, Layer } from "effect";
|
||||
import { Effect, Layer, Option, Schema } from "effect";
|
||||
|
||||
import { toPersistenceSqlError } from "../Errors.ts";
|
||||
import { ModelSelection } from "@t3tools/contracts";
|
||||
import { toPersistenceDecodeError, toPersistenceSqlError } from "../Errors.ts";
|
||||
import {
|
||||
DeleteProjectionThreadInput,
|
||||
GetProjectionThreadInput,
|
||||
@@ -12,6 +13,53 @@ import {
|
||||
type ProjectionThreadRepositoryShape,
|
||||
} from "../Services/ProjectionThreads.ts";
|
||||
|
||||
const ProjectionThreadDbRow = Schema.Struct({
|
||||
threadId: ProjectionThread.fields.threadId,
|
||||
projectId: ProjectionThread.fields.projectId,
|
||||
title: ProjectionThread.fields.title,
|
||||
provider: Schema.Literals(["codex", "claudeAgent"]),
|
||||
model: Schema.String,
|
||||
modelOptions: Schema.NullOr(Schema.fromJsonString(Schema.Unknown)),
|
||||
runtimeMode: ProjectionThread.fields.runtimeMode,
|
||||
interactionMode: ProjectionThread.fields.interactionMode,
|
||||
branch: ProjectionThread.fields.branch,
|
||||
worktreePath: ProjectionThread.fields.worktreePath,
|
||||
latestTurnId: ProjectionThread.fields.latestTurnId,
|
||||
createdAt: ProjectionThread.fields.createdAt,
|
||||
updatedAt: ProjectionThread.fields.updatedAt,
|
||||
deletedAt: ProjectionThread.fields.deletedAt,
|
||||
});
|
||||
type ProjectionThreadDbRow = typeof ProjectionThreadDbRow.Type;
|
||||
|
||||
const decodeModelSelectionSync = Schema.decodeUnknownSync(ModelSelection);
|
||||
|
||||
function decodeProjectionThread(row: ProjectionThreadDbRow) {
|
||||
return Effect.try({
|
||||
try: () => ({
|
||||
threadId: row.threadId,
|
||||
projectId: row.projectId,
|
||||
title: row.title,
|
||||
modelSelection: decodeModelSelectionSync({
|
||||
provider: row.provider,
|
||||
model: row.model,
|
||||
...(row.modelOptions !== null ? { options: row.modelOptions } : {}),
|
||||
}),
|
||||
runtimeMode: row.runtimeMode,
|
||||
interactionMode: row.interactionMode,
|
||||
branch: row.branch,
|
||||
worktreePath: row.worktreePath,
|
||||
latestTurnId: row.latestTurnId,
|
||||
createdAt: row.createdAt,
|
||||
updatedAt: row.updatedAt,
|
||||
deletedAt: row.deletedAt,
|
||||
}),
|
||||
catch: (error) =>
|
||||
toPersistenceDecodeError("ProjectionThreadRepository.decodeProjectionThread")(
|
||||
error as Schema.SchemaError,
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
const makeProjectionThreadRepository = Effect.gen(function* () {
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
|
||||
@@ -23,7 +71,9 @@ const makeProjectionThreadRepository = Effect.gen(function* () {
|
||||
thread_id,
|
||||
project_id,
|
||||
title,
|
||||
provider,
|
||||
model,
|
||||
model_options_json,
|
||||
runtime_mode,
|
||||
interaction_mode,
|
||||
branch,
|
||||
@@ -37,7 +87,9 @@ const makeProjectionThreadRepository = Effect.gen(function* () {
|
||||
${row.threadId},
|
||||
${row.projectId},
|
||||
${row.title},
|
||||
${row.model},
|
||||
${row.modelSelection.provider},
|
||||
${row.modelSelection.model},
|
||||
${row.modelSelection.options != null ? JSON.stringify(row.modelSelection.options) : null},
|
||||
${row.runtimeMode},
|
||||
${row.interactionMode},
|
||||
${row.branch},
|
||||
@@ -51,7 +103,9 @@ const makeProjectionThreadRepository = Effect.gen(function* () {
|
||||
DO UPDATE SET
|
||||
project_id = excluded.project_id,
|
||||
title = excluded.title,
|
||||
provider = excluded.provider,
|
||||
model = excluded.model,
|
||||
model_options_json = excluded.model_options_json,
|
||||
runtime_mode = excluded.runtime_mode,
|
||||
interaction_mode = excluded.interaction_mode,
|
||||
branch = excluded.branch,
|
||||
@@ -65,14 +119,16 @@ const makeProjectionThreadRepository = Effect.gen(function* () {
|
||||
|
||||
const getProjectionThreadRow = SqlSchema.findOneOption({
|
||||
Request: GetProjectionThreadInput,
|
||||
Result: ProjectionThread,
|
||||
Result: ProjectionThreadDbRow,
|
||||
execute: ({ threadId }) =>
|
||||
sql`
|
||||
SELECT
|
||||
thread_id AS "threadId",
|
||||
project_id AS "projectId",
|
||||
title,
|
||||
provider,
|
||||
model,
|
||||
model_options_json AS "modelOptions",
|
||||
runtime_mode AS "runtimeMode",
|
||||
interaction_mode AS "interactionMode",
|
||||
branch,
|
||||
@@ -88,14 +144,16 @@ const makeProjectionThreadRepository = Effect.gen(function* () {
|
||||
|
||||
const listProjectionThreadRows = SqlSchema.findAll({
|
||||
Request: ListProjectionThreadsByProjectInput,
|
||||
Result: ProjectionThread,
|
||||
Result: ProjectionThreadDbRow,
|
||||
execute: ({ projectId }) =>
|
||||
sql`
|
||||
SELECT
|
||||
thread_id AS "threadId",
|
||||
project_id AS "projectId",
|
||||
title,
|
||||
provider,
|
||||
model,
|
||||
model_options_json AS "modelOptions",
|
||||
runtime_mode AS "runtimeMode",
|
||||
interaction_mode AS "interactionMode",
|
||||
branch,
|
||||
@@ -127,11 +185,18 @@ const makeProjectionThreadRepository = Effect.gen(function* () {
|
||||
const getById: ProjectionThreadRepositoryShape["getById"] = (input) =>
|
||||
getProjectionThreadRow(input).pipe(
|
||||
Effect.mapError(toPersistenceSqlError("ProjectionThreadRepository.getById:query")),
|
||||
Effect.flatMap(
|
||||
Option.match({
|
||||
onNone: () => Effect.succeed(Option.none()),
|
||||
onSome: (row) => decodeProjectionThread(row).pipe(Effect.map(Option.some)),
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
const listByProjectId: ProjectionThreadRepositoryShape["listByProjectId"] = (input) =>
|
||||
listProjectionThreadRows(input).pipe(
|
||||
Effect.mapError(toPersistenceSqlError("ProjectionThreadRepository.listByProjectId:query")),
|
||||
Effect.flatMap((rows) => Effect.forEach(rows, decodeProjectionThread)),
|
||||
);
|
||||
|
||||
const deleteById: ProjectionThreadRepositoryShape["deleteById"] = (input) =>
|
||||
|
||||
@@ -27,6 +27,9 @@ import Migration0012 from "./Migrations/012_ProjectionThreadsInteractionMode.ts"
|
||||
import Migration0013 from "./Migrations/013_ProjectionThreadProposedPlans.ts";
|
||||
import Migration0014 from "./Migrations/014_ProjectionThreadProposedPlanImplementation.ts";
|
||||
import Migration0015 from "./Migrations/015_ProjectionTurnsSourceProposedPlan.ts";
|
||||
import Migration0016 from "./Migrations/016_ProjectionProviders.ts";
|
||||
import Migration0017 from "./Migrations/017_ProjectionModelSelectionOptions.ts";
|
||||
import Migration0018 from "./Migrations/018_CanonicalizeLegacyModelSelections.ts";
|
||||
import { Effect } from "effect";
|
||||
|
||||
/**
|
||||
@@ -55,6 +58,9 @@ const loader = Migrator.fromRecord({
|
||||
"13_ProjectionThreadProposedPlans": Migration0013,
|
||||
"14_ProjectionThreadProposedPlanImplementation": Migration0014,
|
||||
"15_ProjectionTurnsSourceProposedPlan": Migration0015,
|
||||
"16_ProjectionProviders": Migration0016,
|
||||
"17_ProjectionModelSelectionOptions": Migration0017,
|
||||
"18_CanonicalizeLegacyModelSelections": Migration0018,
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
||||
|
||||
export default Effect.gen(function* () {
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
|
||||
yield* sql`
|
||||
ALTER TABLE projection_projects
|
||||
ADD COLUMN default_provider TEXT
|
||||
`;
|
||||
|
||||
yield* sql`
|
||||
UPDATE projection_projects
|
||||
SET default_provider = CASE
|
||||
WHEN default_model IS NULL THEN NULL
|
||||
ELSE 'codex'
|
||||
END
|
||||
WHERE default_provider IS NULL
|
||||
`;
|
||||
|
||||
yield* sql`
|
||||
ALTER TABLE projection_threads
|
||||
ADD COLUMN provider TEXT
|
||||
`;
|
||||
|
||||
yield* sql`
|
||||
UPDATE projection_threads
|
||||
SET provider = COALESCE(
|
||||
(
|
||||
SELECT provider_name
|
||||
FROM projection_thread_sessions
|
||||
WHERE projection_thread_sessions.thread_id = projection_threads.thread_id
|
||||
),
|
||||
'codex'
|
||||
)
|
||||
WHERE provider IS NULL
|
||||
`;
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
||||
|
||||
export default Effect.gen(function* () {
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
|
||||
yield* sql`
|
||||
ALTER TABLE projection_projects
|
||||
ADD COLUMN default_model_options_json TEXT
|
||||
`;
|
||||
|
||||
yield* sql`
|
||||
UPDATE projection_projects
|
||||
SET default_model_options_json = NULL
|
||||
WHERE default_model_options_json IS NULL
|
||||
`;
|
||||
|
||||
yield* sql`
|
||||
ALTER TABLE projection_threads
|
||||
ADD COLUMN model_options_json TEXT
|
||||
`;
|
||||
|
||||
yield* sql`
|
||||
UPDATE projection_threads
|
||||
SET model_options_json = NULL
|
||||
WHERE model_options_json IS NULL
|
||||
`;
|
||||
});
|
||||
@@ -0,0 +1,180 @@
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import { Effect, Layer } from "effect";
|
||||
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
||||
|
||||
import Migration0018 from "./018_CanonicalizeLegacyModelSelections.ts";
|
||||
import * as NodeSqliteClient from "../NodeSqliteClient.ts";
|
||||
|
||||
const layer = it.layer(Layer.mergeAll(NodeSqliteClient.layerMemory()));
|
||||
|
||||
layer("018_CanonicalizeLegacyModelSelections", (it) => {
|
||||
it.effect("canonicalizes legacy projection rows and orchestration event payloads", () =>
|
||||
Effect.gen(function* () {
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
|
||||
yield* sql`
|
||||
CREATE TABLE projection_projects (
|
||||
project_id TEXT PRIMARY KEY,
|
||||
default_provider TEXT,
|
||||
default_model TEXT,
|
||||
default_model_options_json TEXT
|
||||
)
|
||||
`;
|
||||
yield* sql`
|
||||
CREATE TABLE projection_threads (
|
||||
thread_id TEXT PRIMARY KEY,
|
||||
provider TEXT,
|
||||
model TEXT NOT NULL,
|
||||
model_options_json TEXT
|
||||
)
|
||||
`;
|
||||
yield* sql`
|
||||
CREATE TABLE orchestration_events (
|
||||
event_type TEXT NOT NULL,
|
||||
payload_json TEXT NOT NULL
|
||||
)
|
||||
`;
|
||||
|
||||
yield* sql`
|
||||
INSERT INTO projection_projects (
|
||||
project_id,
|
||||
default_provider,
|
||||
default_model,
|
||||
default_model_options_json
|
||||
)
|
||||
VALUES (
|
||||
'project-1',
|
||||
'codex',
|
||||
'claude-opus-4-6',
|
||||
'{"codex":{"reasoningEffort":"high"},"claudeAgent":{"effort":"max","thinking":false}}'
|
||||
)
|
||||
`;
|
||||
yield* sql`
|
||||
INSERT INTO projection_threads (
|
||||
thread_id,
|
||||
provider,
|
||||
model,
|
||||
model_options_json
|
||||
)
|
||||
VALUES (
|
||||
'thread-1',
|
||||
'codex',
|
||||
'claude-opus-4-6',
|
||||
'{"codex":{"reasoningEffort":"high"},"claudeAgent":{"effort":"max"}}'
|
||||
)
|
||||
`;
|
||||
yield* sql`
|
||||
INSERT INTO orchestration_events (
|
||||
event_type,
|
||||
payload_json
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
'project.created',
|
||||
'{"projectId":"project-1","title":"Project","workspaceRoot":"/tmp/project","defaultModel":"claude-opus-4-6","defaultModelOptions":{"codex":{"reasoningEffort":"high"},"claudeAgent":{"effort":"max"}},"scripts":[],"createdAt":"2026-01-01T00:00:00.000Z","updatedAt":"2026-01-01T00:00:00.000Z"}'
|
||||
),
|
||||
(
|
||||
'thread.created',
|
||||
'{"threadId":"thread-1","projectId":"project-1","title":"Thread","model":"claude-opus-4-6","modelOptions":{"codex":{"reasoningEffort":"high"},"claudeAgent":{"effort":"max","thinking":false}},"runtimeMode":"full-access","interactionMode":"default","branch":null,"worktreePath":null,"createdAt":"2026-01-01T00:00:00.000Z","updatedAt":"2026-01-01T00:00:00.000Z"}'
|
||||
),
|
||||
(
|
||||
'thread.turn-start-requested',
|
||||
'{"threadId":"thread-1","turnId":"turn-1","input":"hi","model":"gpt-5.4","modelOptions":{"codex":{"fastMode":true},"claudeAgent":{"effort":"max"}},"deliveryMode":"buffered"}'
|
||||
)
|
||||
`;
|
||||
|
||||
yield* Migration0018;
|
||||
|
||||
const projectRows = yield* sql<{
|
||||
readonly defaultProvider: string | null;
|
||||
readonly defaultModelOptions: string | null;
|
||||
}>`
|
||||
SELECT
|
||||
default_provider AS "defaultProvider",
|
||||
default_model_options_json AS "defaultModelOptions"
|
||||
FROM projection_projects
|
||||
WHERE project_id = 'project-1'
|
||||
`;
|
||||
assert.deepStrictEqual(projectRows[0], {
|
||||
defaultProvider: "claudeAgent",
|
||||
defaultModelOptions: '{"effort":"max","thinking":false}',
|
||||
});
|
||||
|
||||
const threadRows = yield* sql<{
|
||||
readonly provider: string | null;
|
||||
readonly modelOptions: string | null;
|
||||
}>`
|
||||
SELECT
|
||||
provider,
|
||||
model_options_json AS "modelOptions"
|
||||
FROM projection_threads
|
||||
WHERE thread_id = 'thread-1'
|
||||
`;
|
||||
assert.deepStrictEqual(threadRows[0], {
|
||||
provider: "claudeAgent",
|
||||
modelOptions: '{"effort":"max"}',
|
||||
});
|
||||
|
||||
const eventRows = yield* sql<{
|
||||
readonly eventType: string;
|
||||
readonly payloadJson: string;
|
||||
}>`
|
||||
SELECT
|
||||
event_type AS "eventType",
|
||||
payload_json AS "payloadJson"
|
||||
FROM orchestration_events
|
||||
ORDER BY rowid ASC
|
||||
`;
|
||||
|
||||
assert.deepStrictEqual(JSON.parse(eventRows[0]!.payloadJson), {
|
||||
projectId: "project-1",
|
||||
title: "Project",
|
||||
workspaceRoot: "/tmp/project",
|
||||
defaultModelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
options: {
|
||||
effort: "max",
|
||||
},
|
||||
},
|
||||
scripts: [],
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
updatedAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(JSON.parse(eventRows[1]!.payloadJson), {
|
||||
threadId: "thread-1",
|
||||
projectId: "project-1",
|
||||
title: "Thread",
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
options: {
|
||||
effort: "max",
|
||||
thinking: false,
|
||||
},
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
interactionMode: "default",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
updatedAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(JSON.parse(eventRows[2]!.payloadJson), {
|
||||
threadId: "thread-1",
|
||||
turnId: "turn-1",
|
||||
input: "hi",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.4",
|
||||
options: {
|
||||
fastMode: true,
|
||||
},
|
||||
},
|
||||
deliveryMode: "buffered",
|
||||
});
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,172 @@
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
||||
|
||||
export default Effect.gen(function* () {
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
|
||||
yield* sql`
|
||||
UPDATE projection_projects
|
||||
SET
|
||||
default_provider = CASE
|
||||
WHEN default_model IS NULL THEN NULL
|
||||
WHEN lower(default_model) LIKE '%claude%' THEN 'claudeAgent'
|
||||
ELSE 'codex'
|
||||
END,
|
||||
default_model_options_json = CASE
|
||||
WHEN default_model_options_json IS NULL THEN NULL
|
||||
WHEN json_valid(default_model_options_json) = 0 THEN default_model_options_json
|
||||
WHEN json_type(default_model_options_json, '$.codex') IS NOT NULL
|
||||
OR json_type(default_model_options_json, '$.claudeAgent') IS NOT NULL
|
||||
THEN CASE
|
||||
WHEN lower(default_model) LIKE '%claude%' THEN json_extract(
|
||||
default_model_options_json,
|
||||
'$.claudeAgent'
|
||||
)
|
||||
ELSE json_extract(default_model_options_json, '$.codex')
|
||||
END
|
||||
ELSE default_model_options_json
|
||||
END
|
||||
WHERE default_model IS NOT NULL
|
||||
`;
|
||||
|
||||
yield* sql`
|
||||
UPDATE projection_threads
|
||||
SET
|
||||
provider = CASE
|
||||
WHEN lower(model) LIKE '%claude%' THEN 'claudeAgent'
|
||||
ELSE 'codex'
|
||||
END,
|
||||
model_options_json = CASE
|
||||
WHEN model_options_json IS NULL THEN NULL
|
||||
WHEN json_valid(model_options_json) = 0 THEN model_options_json
|
||||
WHEN json_type(model_options_json, '$.codex') IS NOT NULL
|
||||
OR json_type(model_options_json, '$.claudeAgent') IS NOT NULL
|
||||
THEN CASE
|
||||
WHEN lower(model) LIKE '%claude%' THEN json_extract(model_options_json, '$.claudeAgent')
|
||||
ELSE json_extract(model_options_json, '$.codex')
|
||||
END
|
||||
ELSE model_options_json
|
||||
END
|
||||
`;
|
||||
|
||||
yield* sql`
|
||||
UPDATE orchestration_events
|
||||
SET payload_json = CASE
|
||||
WHEN json_type(payload_json, '$.defaultModel') = 'null' THEN json_remove(
|
||||
json_set(payload_json, '$.defaultModelSelection', json('null')),
|
||||
'$.defaultProvider',
|
||||
'$.defaultModel',
|
||||
'$.defaultModelOptions'
|
||||
)
|
||||
ELSE json_remove(
|
||||
json_set(
|
||||
payload_json,
|
||||
'$.defaultModelSelection',
|
||||
json_patch(
|
||||
json_object(
|
||||
'provider',
|
||||
CASE
|
||||
WHEN json_extract(payload_json, '$.defaultProvider') IS NOT NULL
|
||||
THEN json_extract(payload_json, '$.defaultProvider')
|
||||
WHEN lower(json_extract(payload_json, '$.defaultModel')) LIKE '%claude%'
|
||||
THEN 'claudeAgent'
|
||||
ELSE 'codex'
|
||||
END,
|
||||
'model',
|
||||
json_extract(payload_json, '$.defaultModel')
|
||||
),
|
||||
CASE
|
||||
WHEN json_type(payload_json, '$.defaultModelOptions') IS NULL THEN '{}'
|
||||
WHEN json_type(payload_json, '$.defaultModelOptions.codex') IS NOT NULL
|
||||
OR json_type(payload_json, '$.defaultModelOptions.claudeAgent') IS NOT NULL
|
||||
THEN CASE
|
||||
WHEN (
|
||||
CASE
|
||||
WHEN json_extract(payload_json, '$.defaultProvider') IS NOT NULL
|
||||
THEN json_extract(payload_json, '$.defaultProvider')
|
||||
WHEN lower(json_extract(payload_json, '$.defaultModel')) LIKE '%claude%'
|
||||
THEN 'claudeAgent'
|
||||
ELSE 'codex'
|
||||
END
|
||||
) = 'claudeAgent'
|
||||
THEN json_object(
|
||||
'options',
|
||||
json(json_extract(payload_json, '$.defaultModelOptions.claudeAgent'))
|
||||
)
|
||||
ELSE json_object(
|
||||
'options',
|
||||
json(json_extract(payload_json, '$.defaultModelOptions.codex'))
|
||||
)
|
||||
END
|
||||
ELSE json_object(
|
||||
'options',
|
||||
json(json_extract(payload_json, '$.defaultModelOptions'))
|
||||
)
|
||||
END
|
||||
)
|
||||
),
|
||||
'$.defaultProvider',
|
||||
'$.defaultModel',
|
||||
'$.defaultModelOptions'
|
||||
)
|
||||
END
|
||||
WHERE event_type IN ('project.created', 'project.meta-updated')
|
||||
AND json_type(payload_json, '$.defaultModelSelection') IS NULL
|
||||
AND json_type(payload_json, '$.defaultModel') IS NOT NULL
|
||||
`;
|
||||
|
||||
yield* sql`
|
||||
UPDATE orchestration_events
|
||||
SET payload_json = json_remove(
|
||||
json_set(
|
||||
payload_json,
|
||||
'$.modelSelection',
|
||||
json_patch(
|
||||
json_object(
|
||||
'provider',
|
||||
CASE
|
||||
WHEN json_extract(payload_json, '$.provider') IS NOT NULL
|
||||
THEN json_extract(payload_json, '$.provider')
|
||||
WHEN lower(json_extract(payload_json, '$.model')) LIKE '%claude%'
|
||||
THEN 'claudeAgent'
|
||||
ELSE 'codex'
|
||||
END,
|
||||
'model',
|
||||
json_extract(payload_json, '$.model')
|
||||
),
|
||||
CASE
|
||||
WHEN json_type(payload_json, '$.modelOptions') IS NULL THEN '{}'
|
||||
WHEN json_type(payload_json, '$.modelOptions.codex') IS NOT NULL
|
||||
OR json_type(payload_json, '$.modelOptions.claudeAgent') IS NOT NULL
|
||||
THEN CASE
|
||||
WHEN (
|
||||
CASE
|
||||
WHEN json_extract(payload_json, '$.provider') IS NOT NULL
|
||||
THEN json_extract(payload_json, '$.provider')
|
||||
WHEN lower(json_extract(payload_json, '$.model')) LIKE '%claude%'
|
||||
THEN 'claudeAgent'
|
||||
ELSE 'codex'
|
||||
END
|
||||
) = 'claudeAgent'
|
||||
THEN json_object(
|
||||
'options',
|
||||
json(json_extract(payload_json, '$.modelOptions.claudeAgent'))
|
||||
)
|
||||
ELSE json_object(
|
||||
'options',
|
||||
json(json_extract(payload_json, '$.modelOptions.codex'))
|
||||
)
|
||||
END
|
||||
ELSE json_object('options', json(json_extract(payload_json, '$.modelOptions')))
|
||||
END
|
||||
)
|
||||
),
|
||||
'$.provider',
|
||||
'$.model',
|
||||
'$.modelOptions'
|
||||
)
|
||||
WHERE event_type IN ('thread.created', 'thread.meta-updated', 'thread.turn-start-requested')
|
||||
AND json_type(payload_json, '$.modelSelection') IS NULL
|
||||
AND json_type(payload_json, '$.model') IS NOT NULL
|
||||
`;
|
||||
});
|
||||
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* @module ProjectionProjectRepository
|
||||
*/
|
||||
import { IsoDateTime, ProjectId, ProjectScript } from "@t3tools/contracts";
|
||||
import { IsoDateTime, ModelSelection, ProjectId, ProjectScript } from "@t3tools/contracts";
|
||||
import { Option, Schema, ServiceMap } from "effect";
|
||||
import type { Effect } from "effect";
|
||||
|
||||
@@ -16,7 +16,7 @@ export const ProjectionProject = Schema.Struct({
|
||||
projectId: ProjectId,
|
||||
title: Schema.String,
|
||||
workspaceRoot: Schema.String,
|
||||
defaultModel: Schema.NullOr(Schema.String),
|
||||
defaultModelSelection: Schema.NullOr(ModelSelection),
|
||||
scripts: Schema.Array(ProjectScript),
|
||||
createdAt: IsoDateTime,
|
||||
updatedAt: IsoDateTime,
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
import {
|
||||
IsoDateTime,
|
||||
ModelSelection,
|
||||
ProjectId,
|
||||
ProviderInteractionMode,
|
||||
RuntimeMode,
|
||||
@@ -23,7 +24,7 @@ export const ProjectionThread = Schema.Struct({
|
||||
threadId: ThreadId,
|
||||
projectId: ProjectId,
|
||||
title: Schema.String,
|
||||
model: Schema.String,
|
||||
modelSelection: ModelSelection,
|
||||
runtimeMode: RuntimeMode,
|
||||
interactionMode: ProviderInteractionMode,
|
||||
branch: Schema.NullOr(Schema.String),
|
||||
|
||||
@@ -703,13 +703,19 @@ describe("WebSocket Server", () => {
|
||||
id: string;
|
||||
workspaceRoot: string;
|
||||
title: string;
|
||||
defaultModel: string | null;
|
||||
defaultModelSelection: {
|
||||
provider: string;
|
||||
model: string;
|
||||
} | null;
|
||||
}>;
|
||||
threads: Array<{
|
||||
id: string;
|
||||
projectId: string;
|
||||
title: string;
|
||||
model: string;
|
||||
modelSelection: {
|
||||
provider: string;
|
||||
model: string;
|
||||
};
|
||||
branch: string | null;
|
||||
worktreePath: string | null;
|
||||
}>;
|
||||
@@ -725,7 +731,10 @@ describe("WebSocket Server", () => {
|
||||
id: bootstrapProjectId,
|
||||
workspaceRoot: "/test/bootstrap-workspace",
|
||||
title: "bootstrap-workspace",
|
||||
defaultModel: "gpt-5-codex",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
}),
|
||||
]),
|
||||
);
|
||||
@@ -735,7 +744,10 @@ describe("WebSocket Server", () => {
|
||||
id: bootstrapThreadId,
|
||||
projectId: bootstrapProjectId,
|
||||
title: "New thread",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
}),
|
||||
@@ -1192,7 +1204,10 @@ describe("WebSocket Server", () => {
|
||||
projectId: "project-diff",
|
||||
title: "Diff Project",
|
||||
workspaceRoot,
|
||||
defaultModel: "gpt-5-codex",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
createdAt,
|
||||
});
|
||||
expect(createProjectResponse.error).toBeUndefined();
|
||||
@@ -1202,7 +1217,10 @@ describe("WebSocket Server", () => {
|
||||
threadId: "thread-diff",
|
||||
projectId: "project-diff",
|
||||
title: "Diff Thread",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
interactionMode: "default",
|
||||
branch: null,
|
||||
@@ -1270,7 +1288,10 @@ describe("WebSocket Server", () => {
|
||||
projectId: "project-1",
|
||||
title: "WS Project",
|
||||
workspaceRoot,
|
||||
defaultModel: "gpt-5-codex",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
createdAt,
|
||||
});
|
||||
expect(createProjectResponse.error).toBeUndefined();
|
||||
@@ -1280,7 +1301,10 @@ describe("WebSocket Server", () => {
|
||||
threadId: "thread-1",
|
||||
projectId: "project-1",
|
||||
title: "Thread 1",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
interactionMode: "default",
|
||||
branch: null,
|
||||
|
||||
@@ -631,25 +631,31 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return<
|
||||
(project) => project.workspaceRoot === cwd && project.deletedAt === null,
|
||||
);
|
||||
let bootstrapProjectId: ProjectId;
|
||||
let bootstrapProjectDefaultModel: string;
|
||||
let bootstrapProjectDefaultModelSelection;
|
||||
|
||||
if (!existingProject) {
|
||||
const createdAt = new Date().toISOString();
|
||||
bootstrapProjectId = ProjectId.makeUnsafe(crypto.randomUUID());
|
||||
const bootstrapProjectTitle = path.basename(cwd) || "project";
|
||||
bootstrapProjectDefaultModel = "gpt-5-codex";
|
||||
bootstrapProjectDefaultModelSelection = {
|
||||
provider: "codex" as const,
|
||||
model: "gpt-5-codex",
|
||||
};
|
||||
yield* orchestrationEngine.dispatch({
|
||||
type: "project.create",
|
||||
commandId: CommandId.makeUnsafe(crypto.randomUUID()),
|
||||
projectId: bootstrapProjectId,
|
||||
title: bootstrapProjectTitle,
|
||||
workspaceRoot: cwd,
|
||||
defaultModel: bootstrapProjectDefaultModel,
|
||||
defaultModelSelection: bootstrapProjectDefaultModelSelection,
|
||||
createdAt,
|
||||
});
|
||||
} else {
|
||||
bootstrapProjectId = existingProject.id;
|
||||
bootstrapProjectDefaultModel = existingProject.defaultModel ?? "gpt-5-codex";
|
||||
bootstrapProjectDefaultModelSelection = existingProject.defaultModelSelection ?? {
|
||||
provider: "codex" as const,
|
||||
model: "gpt-5-codex",
|
||||
};
|
||||
}
|
||||
|
||||
const existingThread = snapshot.threads.find(
|
||||
@@ -664,7 +670,7 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return<
|
||||
threadId,
|
||||
projectId: bootstrapProjectId,
|
||||
title: "New thread",
|
||||
model: bootstrapProjectDefaultModel,
|
||||
modelSelection: bootstrapProjectDefaultModelSelection,
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
|
||||
@@ -221,7 +221,10 @@ function createSnapshotForTargetUser(options: {
|
||||
id: PROJECT_ID,
|
||||
title: "Project",
|
||||
workspaceRoot: "/repo/project",
|
||||
defaultModel: "gpt-5",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5",
|
||||
},
|
||||
scripts: [],
|
||||
createdAt: NOW_ISO,
|
||||
updatedAt: NOW_ISO,
|
||||
@@ -233,7 +236,10 @@ function createSnapshotForTargetUser(options: {
|
||||
id: THREAD_ID,
|
||||
projectId: PROJECT_ID,
|
||||
title: "Browser test thread",
|
||||
model: "gpt-5",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5",
|
||||
},
|
||||
interactionMode: "default",
|
||||
runtimeMode: "full-access",
|
||||
branch: "main",
|
||||
@@ -287,7 +293,10 @@ function addThreadToSnapshot(
|
||||
id: threadId,
|
||||
projectId: PROJECT_ID,
|
||||
title: "New thread",
|
||||
model: "gpt-5",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5",
|
||||
},
|
||||
interactionMode: "default",
|
||||
runtimeMode: "full-access",
|
||||
branch: "main",
|
||||
@@ -817,8 +826,7 @@ describe("ChatView timeline estimator parity (full app)", () => {
|
||||
draftsByThreadId: {},
|
||||
draftThreadsByThreadId: {},
|
||||
projectDraftThreadIdByProjectId: {},
|
||||
stickyModel: null,
|
||||
stickyModelOptions: {},
|
||||
stickyModelSelection: null,
|
||||
});
|
||||
useStore.setState({
|
||||
projects: [],
|
||||
@@ -1483,9 +1491,10 @@ describe("ChatView timeline estimator parity (full app)", () => {
|
||||
|
||||
it("snapshots sticky codex settings into a new draft thread", async () => {
|
||||
useComposerDraftStore.setState({
|
||||
stickyModel: "gpt-5.3-codex",
|
||||
stickyModelOptions: {
|
||||
codex: {
|
||||
stickyModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
options: {
|
||||
reasoningEffort: "medium",
|
||||
fastMode: true,
|
||||
},
|
||||
@@ -1514,10 +1523,10 @@ describe("ChatView timeline estimator parity (full app)", () => {
|
||||
const newThreadId = newThreadPath.slice(1) as ThreadId;
|
||||
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[newThreadId]).toMatchObject({
|
||||
model: "gpt-5.3-codex",
|
||||
provider: "codex",
|
||||
modelOptions: {
|
||||
codex: {
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
options: {
|
||||
fastMode: true,
|
||||
},
|
||||
},
|
||||
@@ -1529,9 +1538,10 @@ describe("ChatView timeline estimator parity (full app)", () => {
|
||||
|
||||
it("hydrates the provider alongside a sticky claude model", async () => {
|
||||
useComposerDraftStore.setState({
|
||||
stickyModel: "claude-opus-4-6",
|
||||
stickyModelOptions: {
|
||||
claudeAgent: {
|
||||
stickyModelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
options: {
|
||||
effort: "max",
|
||||
fastMode: true,
|
||||
},
|
||||
@@ -1560,10 +1570,10 @@ describe("ChatView timeline estimator parity (full app)", () => {
|
||||
const newThreadId = newThreadPath.slice(1) as ThreadId;
|
||||
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[newThreadId]).toMatchObject({
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
modelOptions: {
|
||||
claudeAgent: {
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
options: {
|
||||
effort: "max",
|
||||
fastMode: true,
|
||||
},
|
||||
@@ -1605,9 +1615,10 @@ describe("ChatView timeline estimator parity (full app)", () => {
|
||||
|
||||
it("prefers draft state over sticky composer settings and defaults", async () => {
|
||||
useComposerDraftStore.setState({
|
||||
stickyModel: "gpt-5.3-codex",
|
||||
stickyModelOptions: {
|
||||
codex: {
|
||||
stickyModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
options: {
|
||||
reasoningEffort: "medium",
|
||||
fastMode: true,
|
||||
},
|
||||
@@ -1636,17 +1647,19 @@ describe("ChatView timeline estimator parity (full app)", () => {
|
||||
const threadId = threadPath.slice(1) as ThreadId;
|
||||
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]).toMatchObject({
|
||||
model: "gpt-5.3-codex",
|
||||
modelOptions: {
|
||||
codex: {
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
options: {
|
||||
fastMode: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
useComposerDraftStore.getState().setModel(threadId, "gpt-5.4");
|
||||
useComposerDraftStore.getState().setModelOptions(threadId, {
|
||||
codex: {
|
||||
useComposerDraftStore.getState().setModelSelection(threadId, {
|
||||
provider: "codex",
|
||||
model: "gpt-5.4",
|
||||
options: {
|
||||
reasoningEffort: "low",
|
||||
fastMode: true,
|
||||
},
|
||||
@@ -1660,9 +1673,10 @@ describe("ChatView timeline estimator parity (full app)", () => {
|
||||
"New-thread should reuse the existing project draft thread.",
|
||||
);
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]).toMatchObject({
|
||||
model: "gpt-5.4",
|
||||
modelOptions: {
|
||||
codex: {
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.4",
|
||||
options: {
|
||||
reasoningEffort: "low",
|
||||
fastMode: true,
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ProjectId, type ThreadId } from "@t3tools/contracts";
|
||||
import { ProjectId, type ModelSelection, type ThreadId } from "@t3tools/contracts";
|
||||
import { type ChatMessage, type Thread } from "../types";
|
||||
import { randomUUID } from "~/lib/utils";
|
||||
import { type ComposerImageAttachment, type DraftThreadState } from "../composerDraftStore";
|
||||
@@ -17,7 +17,7 @@ export const LastInvokedScriptByProjectSchema = Schema.Record(ProjectId, Schema.
|
||||
export function buildLocalDraftThread(
|
||||
threadId: ThreadId,
|
||||
draftThread: DraftThreadState,
|
||||
fallbackModel: string,
|
||||
fallbackModelSelection: ModelSelection,
|
||||
error: string | null,
|
||||
): Thread {
|
||||
return {
|
||||
@@ -25,7 +25,7 @@ export function buildLocalDraftThread(
|
||||
codexThreadId: null,
|
||||
projectId: draftThread.projectId,
|
||||
title: "New thread",
|
||||
model: fallbackModel,
|
||||
modelSelection: fallbackModelSelection,
|
||||
runtimeMode: draftThread.runtimeMode,
|
||||
interactionMode: draftThread.interactionMode,
|
||||
session: null,
|
||||
|
||||
@@ -3,9 +3,11 @@ import {
|
||||
DEFAULT_MODEL_BY_PROVIDER,
|
||||
type ClaudeCodeEffort,
|
||||
type MessageId,
|
||||
type ModelSelection,
|
||||
type ProjectScript,
|
||||
type ModelSlug,
|
||||
type ProviderKind,
|
||||
type ProviderModelOptions,
|
||||
type ProjectEntry,
|
||||
type ProjectId,
|
||||
type ProviderApprovalDecision,
|
||||
@@ -26,6 +28,7 @@ import {
|
||||
getDefaultModel,
|
||||
normalizeModelSlug,
|
||||
resolveModelSlugForProvider,
|
||||
toProviderModelOptions,
|
||||
} from "@t3tools/shared/model";
|
||||
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
@@ -202,6 +205,12 @@ function formatOutgoingPrompt(params: {
|
||||
}
|
||||
return params.text;
|
||||
}
|
||||
function extractModelSelectionOptions(
|
||||
provider: ProviderKind,
|
||||
modelOptions: ProviderModelOptions | undefined,
|
||||
): ModelSelection["options"] | undefined {
|
||||
return provider === "codex" ? modelOptions?.codex : modelOptions?.claudeAgent;
|
||||
}
|
||||
const COMPOSER_PATH_QUERY_DEBOUNCE_MS = 120;
|
||||
const SCRIPT_TERMINAL_COLS = 120;
|
||||
const SCRIPT_TERMINAL_ROWS = 30;
|
||||
@@ -246,7 +255,9 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
const setStoreThreadError = useStore((store) => store.setError);
|
||||
const setStoreThreadBranch = useStore((store) => store.setThreadBranch);
|
||||
const { settings } = useAppSettings();
|
||||
const setStickyComposerModel = useComposerDraftStore((store) => store.setStickyModel);
|
||||
const setStickyComposerModelSelection = useComposerDraftStore(
|
||||
(store) => store.setStickyModelSelection,
|
||||
);
|
||||
const timestampFormat = settings.timestampFormat;
|
||||
const navigate = useNavigate();
|
||||
const rawSearch = useSearch({
|
||||
@@ -271,8 +282,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
);
|
||||
const nonPersistedComposerImageIds = composerDraft.nonPersistedImageIds;
|
||||
const setComposerDraftPrompt = useComposerDraftStore((store) => store.setPrompt);
|
||||
const setComposerDraftProvider = useComposerDraftStore((store) => store.setProvider);
|
||||
const setComposerDraftModel = useComposerDraftStore((store) => store.setModel);
|
||||
const setComposerDraftModelSelection = useComposerDraftStore((store) => store.setModelSelection);
|
||||
const setComposerDraftRuntimeMode = useComposerDraftStore((store) => store.setRuntimeMode);
|
||||
const setComposerDraftInteractionMode = useComposerDraftStore(
|
||||
(store) => store.setInteractionMode,
|
||||
@@ -465,11 +475,14 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
? buildLocalDraftThread(
|
||||
threadId,
|
||||
draftThread,
|
||||
fallbackDraftProject?.model ?? DEFAULT_MODEL_BY_PROVIDER.codex,
|
||||
fallbackDraftProject?.defaultModelSelection ?? {
|
||||
provider: "codex",
|
||||
model: DEFAULT_MODEL_BY_PROVIDER.codex,
|
||||
},
|
||||
localDraftError,
|
||||
)
|
||||
: undefined,
|
||||
[draftThread, fallbackDraftProject?.model, localDraftError, threadId],
|
||||
[draftThread, fallbackDraftProject?.defaultModelSelection, localDraftError, threadId],
|
||||
);
|
||||
const activeThread = serverThread ?? localDraftThread;
|
||||
const runtimeMode =
|
||||
@@ -584,7 +597,9 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
]);
|
||||
|
||||
const sessionProvider = activeThread?.session?.provider ?? null;
|
||||
const selectedProviderByThreadId = composerDraft.provider;
|
||||
const selectedProviderByThreadId = composerDraft.modelSelection?.provider ?? null;
|
||||
const threadProvider =
|
||||
activeThread?.modelSelection.provider ?? activeProject?.defaultModelSelection?.provider ?? null;
|
||||
const hasThreadStarted = Boolean(
|
||||
activeThread &&
|
||||
(activeThread.latestTurn !== null ||
|
||||
@@ -592,22 +607,30 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
activeThread.session !== null),
|
||||
);
|
||||
const lockedProvider: ProviderKind | null = hasThreadStarted
|
||||
? (sessionProvider ?? selectedProviderByThreadId ?? null)
|
||||
? (sessionProvider ?? threadProvider ?? selectedProviderByThreadId ?? null)
|
||||
: null;
|
||||
const selectedProvider: ProviderKind = lockedProvider ?? selectedProviderByThreadId ?? "codex";
|
||||
const selectedProvider: ProviderKind =
|
||||
lockedProvider ?? selectedProviderByThreadId ?? threadProvider ?? "codex";
|
||||
const baseThreadModel = resolveModelSlugForProvider(
|
||||
selectedProvider,
|
||||
activeThread?.model ?? activeProject?.model ?? getDefaultModel(selectedProvider),
|
||||
activeThread?.modelSelection.model ??
|
||||
activeProject?.defaultModelSelection?.model ??
|
||||
getDefaultModel(selectedProvider),
|
||||
);
|
||||
const customModelsByProvider = useMemo(() => getCustomModelsByProvider(settings), [settings]);
|
||||
const selectedModel = useMemo(() => {
|
||||
const draftModel = composerDraft.model;
|
||||
const draftModel = composerDraft.modelSelection?.model;
|
||||
if (!draftModel) {
|
||||
return baseThreadModel;
|
||||
}
|
||||
return resolveAppModelSelection(selectedProvider, customModelsByProvider, draftModel);
|
||||
}, [baseThreadModel, composerDraft.model, customModelsByProvider, selectedProvider]);
|
||||
const draftModelOptions = composerDraft.modelOptions;
|
||||
}, [
|
||||
baseThreadModel,
|
||||
composerDraft.modelSelection?.model,
|
||||
customModelsByProvider,
|
||||
selectedProvider,
|
||||
]);
|
||||
const draftModelOptions = toProviderModelOptions(composerDraft.modelSelection);
|
||||
const composerProviderState = useMemo(
|
||||
() =>
|
||||
getComposerProviderState({
|
||||
@@ -620,6 +643,21 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
);
|
||||
const selectedPromptEffort = composerProviderState.promptEffort;
|
||||
const selectedModelOptionsForDispatch = composerProviderState.modelOptionsForDispatch;
|
||||
const selectedModelSelection = useMemo<ModelSelection>(
|
||||
() => ({
|
||||
provider: selectedProvider,
|
||||
model: selectedModel,
|
||||
...(extractModelSelectionOptions(selectedProvider, selectedModelOptionsForDispatch)
|
||||
? {
|
||||
options: extractModelSelectionOptions(
|
||||
selectedProvider,
|
||||
selectedModelOptionsForDispatch,
|
||||
),
|
||||
}
|
||||
: {}),
|
||||
}),
|
||||
[selectedModel, selectedModelOptionsForDispatch, selectedProvider],
|
||||
);
|
||||
const providerOptionsForDispatch = useMemo(() => getProviderStartOptions(settings), [settings]);
|
||||
const selectedModelForPicker = selectedModel;
|
||||
const modelOptionsByProvider = useMemo(
|
||||
@@ -1588,7 +1626,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
async (input: {
|
||||
threadId: ThreadId;
|
||||
createdAt: string;
|
||||
model?: string;
|
||||
modelSelection?: ModelSelection;
|
||||
runtimeMode: RuntimeMode;
|
||||
interactionMode: ProviderInteractionMode;
|
||||
}) => {
|
||||
@@ -1600,12 +1638,18 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (input.model !== undefined && input.model !== serverThread.model) {
|
||||
if (
|
||||
input.modelSelection !== undefined &&
|
||||
(input.modelSelection.model !== serverThread.modelSelection.model ||
|
||||
input.modelSelection.provider !== serverThread.modelSelection.provider ||
|
||||
JSON.stringify(input.modelSelection.options ?? null) !==
|
||||
JSON.stringify(serverThread.modelSelection.options ?? null))
|
||||
) {
|
||||
await api.orchestration.dispatchCommand({
|
||||
type: "thread.meta.update",
|
||||
commandId: newCommandId(),
|
||||
threadId: input.threadId,
|
||||
model: input.model,
|
||||
modelSelection: input.modelSelection,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2536,8 +2580,14 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
}
|
||||
}
|
||||
const title = truncateTitle(titleSeed);
|
||||
let threadCreateModel: ModelSlug =
|
||||
selectedModel || (activeProject.model as ModelSlug) || DEFAULT_MODEL_BY_PROVIDER.codex;
|
||||
const threadCreateModelSelection: ModelSelection = {
|
||||
provider: selectedProvider,
|
||||
model:
|
||||
selectedModel ||
|
||||
activeProject.defaultModelSelection?.model ||
|
||||
DEFAULT_MODEL_BY_PROVIDER.codex,
|
||||
...(selectedModelSelection.options ? { options: selectedModelSelection.options } : {}),
|
||||
};
|
||||
|
||||
if (isLocalDraftThread) {
|
||||
await api.orchestration.dispatchCommand({
|
||||
@@ -2546,7 +2596,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
threadId: threadIdForSend,
|
||||
projectId: activeProject.id,
|
||||
title,
|
||||
model: threadCreateModel,
|
||||
modelSelection: threadCreateModelSelection,
|
||||
runtimeMode,
|
||||
interactionMode,
|
||||
branch: nextThreadBranch,
|
||||
@@ -2595,7 +2645,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
await persistThreadSettingsForNextTurn({
|
||||
threadId: threadIdForSend,
|
||||
createdAt: messageCreatedAt,
|
||||
...(selectedModel ? { model: selectedModel } : {}),
|
||||
...(selectedModel ? { modelSelection: selectedModelSelection } : {}),
|
||||
runtimeMode,
|
||||
interactionMode,
|
||||
});
|
||||
@@ -2613,12 +2663,8 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
text: outgoingMessageText,
|
||||
attachments: turnAttachments,
|
||||
},
|
||||
model: selectedModel || undefined,
|
||||
...(selectedModelOptionsForDispatch
|
||||
? { modelOptions: selectedModelOptionsForDispatch }
|
||||
: {}),
|
||||
modelSelection: selectedModelSelection,
|
||||
...(providerOptionsForDispatch ? { providerOptions: providerOptionsForDispatch } : {}),
|
||||
provider: selectedProvider,
|
||||
assistantDeliveryMode: settings.enableAssistantStreaming ? "streaming" : "buffered",
|
||||
runtimeMode,
|
||||
interactionMode,
|
||||
@@ -2879,7 +2925,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
await persistThreadSettingsForNextTurn({
|
||||
threadId: threadIdForSend,
|
||||
createdAt: messageCreatedAt,
|
||||
...(selectedModel ? { model: selectedModel } : {}),
|
||||
modelSelection: selectedModelSelection,
|
||||
runtimeMode,
|
||||
interactionMode: nextInteractionMode,
|
||||
});
|
||||
@@ -2898,11 +2944,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
text: outgoingMessageText,
|
||||
attachments: [],
|
||||
},
|
||||
provider: selectedProvider,
|
||||
model: selectedModel || undefined,
|
||||
...(selectedModelOptionsForDispatch
|
||||
? { modelOptions: selectedModelOptionsForDispatch }
|
||||
: {}),
|
||||
modelSelection: selectedModelSelection,
|
||||
...(providerOptionsForDispatch ? { providerOptions: providerOptionsForDispatch } : {}),
|
||||
assistantDeliveryMode: settings.enableAssistantStreaming ? "streaming" : "buffered",
|
||||
runtimeMode,
|
||||
@@ -2949,8 +2991,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
resetSendPhase,
|
||||
runtimeMode,
|
||||
selectedPromptEffort,
|
||||
selectedModel,
|
||||
selectedModelOptionsForDispatch,
|
||||
selectedModelSelection,
|
||||
providerOptionsForDispatch,
|
||||
selectedProvider,
|
||||
setComposerDraftInteractionMode,
|
||||
@@ -2984,11 +3025,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
text: implementationPrompt,
|
||||
});
|
||||
const nextThreadTitle = truncateTitle(buildPlanImplementationThreadTitle(planMarkdown));
|
||||
const nextThreadModel: ModelSlug =
|
||||
selectedModel ||
|
||||
(activeThread.model as ModelSlug) ||
|
||||
(activeProject.model as ModelSlug) ||
|
||||
DEFAULT_MODEL_BY_PROVIDER.codex;
|
||||
const nextThreadModelSelection: ModelSelection = selectedModelSelection;
|
||||
|
||||
sendInFlightRef.current = true;
|
||||
beginSendPhase("sending-turn");
|
||||
@@ -3004,7 +3041,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
threadId: nextThreadId,
|
||||
projectId: activeProject.id,
|
||||
title: nextThreadTitle,
|
||||
model: nextThreadModel,
|
||||
modelSelection: nextThreadModelSelection,
|
||||
runtimeMode,
|
||||
interactionMode: "default",
|
||||
branch: activeThread.branch,
|
||||
@@ -3022,11 +3059,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
text: outgoingImplementationPrompt,
|
||||
attachments: [],
|
||||
},
|
||||
provider: selectedProvider,
|
||||
model: selectedModel || undefined,
|
||||
...(selectedModelOptionsForDispatch
|
||||
? { modelOptions: selectedModelOptionsForDispatch }
|
||||
: {}),
|
||||
modelSelection: selectedModelSelection,
|
||||
...(providerOptionsForDispatch ? { providerOptions: providerOptionsForDispatch } : {}),
|
||||
assistantDeliveryMode: settings.enableAssistantStreaming ? "streaming" : "buffered",
|
||||
runtimeMode,
|
||||
@@ -3078,8 +3111,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
resetSendPhase,
|
||||
runtimeMode,
|
||||
selectedPromptEffort,
|
||||
selectedModel,
|
||||
selectedModelOptionsForDispatch,
|
||||
selectedModelSelection,
|
||||
providerOptionsForDispatch,
|
||||
selectedProvider,
|
||||
settings.enableAssistantStreaming,
|
||||
@@ -3094,18 +3126,26 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
return;
|
||||
}
|
||||
const resolvedModel = resolveAppModelSelection(provider, customModelsByProvider, model);
|
||||
setComposerDraftProvider(activeThread.id, provider);
|
||||
setComposerDraftModel(activeThread.id, resolvedModel);
|
||||
setStickyComposerModel(resolvedModel);
|
||||
const existingModelSelection = composerDraft.modelSelection;
|
||||
const preserveOptions =
|
||||
existingModelSelection?.provider === provider &&
|
||||
existingModelSelection.options !== undefined;
|
||||
const nextModelSelection: ModelSelection = {
|
||||
provider,
|
||||
model: resolvedModel,
|
||||
...(preserveOptions ? { options: existingModelSelection.options } : {}),
|
||||
};
|
||||
setComposerDraftModelSelection(activeThread.id, nextModelSelection);
|
||||
setStickyComposerModelSelection(nextModelSelection);
|
||||
scheduleComposerFocus();
|
||||
},
|
||||
[
|
||||
activeThread,
|
||||
composerDraft.modelSelection,
|
||||
lockedProvider,
|
||||
scheduleComposerFocus,
|
||||
setComposerDraftModel,
|
||||
setComposerDraftProvider,
|
||||
setStickyComposerModel,
|
||||
setComposerDraftModelSelection,
|
||||
setStickyComposerModelSelection,
|
||||
customModelsByProvider,
|
||||
],
|
||||
);
|
||||
|
||||
@@ -64,7 +64,10 @@ function createMinimalSnapshot(): OrchestrationReadModel {
|
||||
id: PROJECT_ID,
|
||||
title: "Project",
|
||||
workspaceRoot: "/repo/project",
|
||||
defaultModel: "gpt-5",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5",
|
||||
},
|
||||
scripts: [],
|
||||
createdAt: NOW_ISO,
|
||||
updatedAt: NOW_ISO,
|
||||
@@ -76,7 +79,10 @@ function createMinimalSnapshot(): OrchestrationReadModel {
|
||||
id: THREAD_ID,
|
||||
projectId: PROJECT_ID,
|
||||
title: "Test thread",
|
||||
model: "gpt-5",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5",
|
||||
},
|
||||
interactionMode: "default",
|
||||
runtimeMode: "full-access",
|
||||
branch: "main",
|
||||
|
||||
@@ -434,7 +434,10 @@ export default function Sidebar() {
|
||||
projectId,
|
||||
title,
|
||||
workspaceRoot: cwd,
|
||||
defaultModel: DEFAULT_MODEL_BY_PROVIDER.codex,
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: DEFAULT_MODEL_BY_PROVIDER.codex,
|
||||
},
|
||||
createdAt,
|
||||
});
|
||||
await handleNewThread(projectId, {
|
||||
|
||||
@@ -25,10 +25,10 @@ async function mountPicker(props?: {
|
||||
nonPersistedImageIds: [],
|
||||
persistedAttachments: [],
|
||||
terminalContexts: [],
|
||||
provider: "claudeAgent",
|
||||
model: props?.model ?? "claude-opus-4-6",
|
||||
modelOptions: {
|
||||
claudeAgent: {
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: props?.model ?? "claude-opus-4-6",
|
||||
options: {
|
||||
...(props?.effort ? { effort: props.effort } : {}),
|
||||
...(props?.thinkingEnabled === false ? { thinking: false } : {}),
|
||||
...(props?.fastModeEnabled ? { fastMode: true } : {}),
|
||||
@@ -185,8 +185,9 @@ describe("ClaudeTraitsPicker", () => {
|
||||
await page.getByRole("button").click();
|
||||
await page.getByRole("menuitemradio", { name: "Max" }).click();
|
||||
|
||||
expect(useComposerDraftStore.getState().stickyModelOptions).toMatchObject({
|
||||
claudeAgent: {
|
||||
expect(useComposerDraftStore.getState().stickyModelSelection).toMatchObject({
|
||||
provider: "claudeAgent",
|
||||
options: {
|
||||
effort: "max",
|
||||
},
|
||||
});
|
||||
|
||||
@@ -93,7 +93,8 @@ export const ClaudeTraitsMenuContent = memo(function ClaudeTraitsMenuContentImpl
|
||||
}: ClaudeTraitsMenuContentProps) {
|
||||
const draft = useComposerThreadDraft(threadId);
|
||||
const prompt = draft.prompt;
|
||||
const modelOptions = draft.modelOptions?.[PROVIDER];
|
||||
const modelOptions =
|
||||
draft.modelSelection?.provider === PROVIDER ? draft.modelSelection.options : null;
|
||||
const setProviderModelOptions = useComposerDraftStore((store) => store.setProviderModelOptions);
|
||||
const {
|
||||
effort,
|
||||
@@ -225,7 +226,8 @@ export const ClaudeTraitsPicker = memo(function ClaudeTraitsPicker({
|
||||
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
||||
const draft = useComposerThreadDraft(threadId);
|
||||
const prompt = draft.prompt;
|
||||
const modelOptions = draft.modelOptions?.[PROVIDER];
|
||||
const modelOptions =
|
||||
draft.modelSelection?.provider === PROVIDER ? draft.modelSelection.options : null;
|
||||
const { effort, thinkingEnabled, fastModeEnabled, ultrathinkPromptControlled, supportsFastMode } =
|
||||
getSelectedClaudeTraits(model, prompt, modelOptions);
|
||||
const triggerLabel = [
|
||||
|
||||
@@ -22,10 +22,10 @@ async function mountPicker(props: {
|
||||
nonPersistedImageIds: [],
|
||||
persistedAttachments: [],
|
||||
terminalContexts: [],
|
||||
provider: "codex",
|
||||
model: null,
|
||||
modelOptions: {
|
||||
codex: {
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.4",
|
||||
options: {
|
||||
...(props.reasoningEffort ? { reasoningEffort: props.reasoningEffort } : {}),
|
||||
...(props.fastModeEnabled ? { fastMode: true } : {}),
|
||||
},
|
||||
@@ -125,8 +125,9 @@ describe("CodexTraitsPicker", () => {
|
||||
await page.getByRole("button").click();
|
||||
await page.getByRole("menuitemradio", { name: "on" }).click();
|
||||
|
||||
expect(useComposerDraftStore.getState().stickyModelOptions).toMatchObject({
|
||||
codex: {
|
||||
expect(useComposerDraftStore.getState().stickyModelSelection).toMatchObject({
|
||||
provider: "codex",
|
||||
options: {
|
||||
fastMode: true,
|
||||
},
|
||||
});
|
||||
@@ -145,6 +146,7 @@ describe("CodexTraitsPicker", () => {
|
||||
[threadId]: {
|
||||
prompt: "",
|
||||
attachments: [],
|
||||
modelSelection: null,
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
effort: "xhigh",
|
||||
@@ -173,12 +175,16 @@ describe("CodexTraitsPicker", () => {
|
||||
|
||||
await vi.waitFor(() => {
|
||||
expect(document.body.textContent ?? "").toContain("Extra High · Fast");
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]?.modelOptions).toEqual({
|
||||
codex: {
|
||||
reasoningEffort: "xhigh",
|
||||
fastMode: true,
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]?.modelSelection).toEqual(
|
||||
{
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
options: {
|
||||
reasoningEffort: "xhigh",
|
||||
fastMode: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
);
|
||||
});
|
||||
} finally {
|
||||
await screen.unmount();
|
||||
|
||||
@@ -48,7 +48,8 @@ function getSelectedCodexTraits(modelOptions: CodexModelOptions | null | undefin
|
||||
|
||||
function CodexTraitsMenuContentImpl(props: { threadId: ThreadId }) {
|
||||
const draft = useComposerThreadDraft(props.threadId);
|
||||
const modelOptions = draft.modelOptions?.[PROVIDER];
|
||||
const modelOptions =
|
||||
draft.modelSelection?.provider === PROVIDER ? draft.modelSelection.options : null;
|
||||
const setProviderModelOptions = useComposerDraftStore((store) => store.setProviderModelOptions);
|
||||
const options = getReasoningEffortOptions(PROVIDER);
|
||||
const defaultReasoningEffort = getDefaultReasoningEffort(PROVIDER);
|
||||
@@ -112,7 +113,9 @@ export const CodexTraitsMenuContent = memo(CodexTraitsMenuContentImpl);
|
||||
|
||||
export const CodexTraitsPicker = memo(function CodexTraitsPicker(props: { threadId: ThreadId }) {
|
||||
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
||||
const modelOptions = useComposerThreadDraft(props.threadId).modelOptions?.codex;
|
||||
const draft = useComposerThreadDraft(props.threadId);
|
||||
const modelOptions =
|
||||
draft.modelSelection?.provider === PROVIDER ? draft.modelSelection.options : null;
|
||||
const { effort, fastModeEnabled } = getSelectedCodexTraits(modelOptions);
|
||||
const triggerLabel = [CODEX_REASONING_LABELS[effort], ...(fastModeEnabled ? ["Fast"] : [])]
|
||||
.filter(Boolean)
|
||||
|
||||
@@ -27,9 +27,16 @@ async function mountMenu(props?: {
|
||||
nonPersistedImageIds: [],
|
||||
persistedAttachments: [],
|
||||
terminalContexts: [],
|
||||
provider,
|
||||
model: props?.model ?? "claude-opus-4-6",
|
||||
modelOptions: props?.modelOptions ?? null,
|
||||
modelSelection: {
|
||||
provider,
|
||||
model: props?.model ?? "claude-opus-4-6",
|
||||
...(props?.modelOptions
|
||||
? {
|
||||
options:
|
||||
provider === "codex" ? props.modelOptions.codex : props.modelOptions.claudeAgent,
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
runtimeMode: null,
|
||||
interactionMode: null,
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as Schema from "effect/Schema";
|
||||
import { ProjectId, ThreadId } from "@t3tools/contracts";
|
||||
import { ProjectId, ThreadId, type ModelSelection } from "@t3tools/contracts";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import {
|
||||
@@ -67,11 +67,22 @@ function resetComposerDraftStore() {
|
||||
draftsByThreadId: {},
|
||||
draftThreadsByThreadId: {},
|
||||
projectDraftThreadIdByProjectId: {},
|
||||
stickyModel: null,
|
||||
stickyModelOptions: {},
|
||||
stickyModelSelection: null,
|
||||
});
|
||||
}
|
||||
|
||||
function modelSelection(
|
||||
provider: "codex" | "claudeAgent",
|
||||
model: string,
|
||||
options?: ModelSelection["options"],
|
||||
): ModelSelection {
|
||||
return {
|
||||
provider,
|
||||
model,
|
||||
...(options ? { options } : {}),
|
||||
} as ModelSelection;
|
||||
}
|
||||
|
||||
describe("composerDraftStore addImages", () => {
|
||||
const threadId = ThreadId.makeUnsafe("thread-dedupe");
|
||||
let originalRevokeObjectUrl: typeof URL.revokeObjectURL;
|
||||
@@ -595,62 +606,56 @@ describe("composerDraftStore project draft thread mapping", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("composerDraftStore modelOptions", () => {
|
||||
describe("composerDraftStore modelSelection", () => {
|
||||
const threadId = ThreadId.makeUnsafe("thread-model-options");
|
||||
|
||||
beforeEach(() => {
|
||||
resetComposerDraftStore();
|
||||
});
|
||||
|
||||
it("stores provider-scoped model options in the draft", () => {
|
||||
it("stores a model selection in the draft", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
store.setModelOptions(threadId, {
|
||||
codex: {
|
||||
store.setModelSelection(
|
||||
threadId,
|
||||
modelSelection("codex", "gpt-5.3-codex", {
|
||||
reasoningEffort: "xhigh",
|
||||
fastMode: true,
|
||||
},
|
||||
claudeAgent: {
|
||||
thinking: false,
|
||||
},
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]?.modelOptions).toEqual({
|
||||
codex: {
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]?.modelSelection).toEqual(
|
||||
modelSelection("codex", "gpt-5.3-codex", {
|
||||
reasoningEffort: "xhigh",
|
||||
fastMode: true,
|
||||
},
|
||||
claudeAgent: {
|
||||
thinking: false,
|
||||
},
|
||||
});
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("drops default-only model options from the draft", () => {
|
||||
it("keeps default-only model selections on the draft", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
store.setModelOptions(threadId, {
|
||||
codex: {
|
||||
reasoningEffort: "high",
|
||||
},
|
||||
claudeAgent: {
|
||||
thinking: true,
|
||||
},
|
||||
});
|
||||
store.setModelSelection(threadId, modelSelection("codex", "gpt-5.4"));
|
||||
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]).toBeUndefined();
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]?.modelSelection).toEqual(
|
||||
modelSelection("codex", "gpt-5.4"),
|
||||
);
|
||||
});
|
||||
|
||||
it("replaces only the targeted provider model options", () => {
|
||||
it("replaces only the targeted provider options on the current model selection", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
|
||||
store.setModelOptions(threadId, {
|
||||
codex: {
|
||||
reasoningEffort: "xhigh",
|
||||
},
|
||||
claudeAgent: {
|
||||
store.setModelSelection(
|
||||
threadId,
|
||||
modelSelection("claudeAgent", "claude-opus-4-6", {
|
||||
effort: "max",
|
||||
fastMode: true,
|
||||
},
|
||||
});
|
||||
}),
|
||||
);
|
||||
store.setStickyModelSelection(
|
||||
modelSelection("claudeAgent", "claude-opus-4-6", {
|
||||
effort: "max",
|
||||
fastMode: true,
|
||||
}),
|
||||
);
|
||||
|
||||
store.setProviderModelOptions(
|
||||
threadId,
|
||||
@@ -661,114 +666,109 @@ describe("composerDraftStore modelOptions", () => {
|
||||
{ persistSticky: true },
|
||||
);
|
||||
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]?.modelOptions).toEqual({
|
||||
codex: {
|
||||
reasoningEffort: "xhigh",
|
||||
},
|
||||
claudeAgent: {
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]?.modelSelection).toEqual(
|
||||
modelSelection("claudeAgent", "claude-opus-4-6", {
|
||||
thinking: false,
|
||||
},
|
||||
});
|
||||
expect(useComposerDraftStore.getState().stickyModelOptions).toEqual({
|
||||
codex: {
|
||||
reasoningEffort: "xhigh",
|
||||
},
|
||||
claudeAgent: {
|
||||
}),
|
||||
);
|
||||
expect(useComposerDraftStore.getState().stickyModelSelection).toEqual(
|
||||
modelSelection("claudeAgent", "claude-opus-4-6", {
|
||||
thinking: false,
|
||||
},
|
||||
});
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("removes only the targeted provider entry when next options normalize empty", () => {
|
||||
it("removes selection options when the patched provider options normalize empty", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
|
||||
store.setModelOptions(threadId, {
|
||||
codex: {
|
||||
reasoningEffort: "xhigh",
|
||||
},
|
||||
claudeAgent: {
|
||||
store.setModelSelection(
|
||||
threadId,
|
||||
modelSelection("claudeAgent", "claude-opus-4-6", {
|
||||
effort: "max",
|
||||
},
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
store.setProviderModelOptions(threadId, "claudeAgent", {
|
||||
thinking: true,
|
||||
});
|
||||
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]?.modelOptions).toEqual({
|
||||
codex: {
|
||||
reasoningEffort: "xhigh",
|
||||
},
|
||||
});
|
||||
expect(useComposerDraftStore.getState().stickyModelOptions).toEqual({});
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]?.modelSelection).toEqual(
|
||||
modelSelection("claudeAgent", "claude-opus-4-6"),
|
||||
);
|
||||
expect(useComposerDraftStore.getState().stickyModelSelection).toBeNull();
|
||||
});
|
||||
|
||||
it("removes model options entirely when the last provider entry normalizes empty", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
|
||||
store.setModelOptions(threadId, {
|
||||
codex: {
|
||||
fastMode: true,
|
||||
},
|
||||
});
|
||||
store.setModelSelection(threadId, modelSelection("codex", "gpt-5.4", { fastMode: true }));
|
||||
|
||||
store.setProviderModelOptions(threadId, "codex", {
|
||||
reasoningEffort: "high",
|
||||
fastMode: false,
|
||||
});
|
||||
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]).toBeUndefined();
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]?.modelSelection).toEqual(
|
||||
modelSelection("codex", "gpt-5.4"),
|
||||
);
|
||||
});
|
||||
|
||||
it("updates only the draft when sticky persistence is omitted", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
|
||||
store.setStickyModelOptions({
|
||||
codex: {
|
||||
fastMode: true,
|
||||
},
|
||||
});
|
||||
store.setModelOptions(threadId, {
|
||||
codex: {
|
||||
fastMode: true,
|
||||
},
|
||||
claudeAgent: {
|
||||
effort: "max",
|
||||
},
|
||||
});
|
||||
store.setStickyModelSelection(
|
||||
modelSelection("claudeAgent", "claude-opus-4-6", { effort: "max" }),
|
||||
);
|
||||
store.setModelSelection(
|
||||
threadId,
|
||||
modelSelection("claudeAgent", "claude-opus-4-6", { effort: "max" }),
|
||||
);
|
||||
|
||||
store.setProviderModelOptions(threadId, "claudeAgent", {
|
||||
thinking: false,
|
||||
});
|
||||
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]?.modelOptions).toEqual({
|
||||
codex: {
|
||||
fastMode: true,
|
||||
},
|
||||
claudeAgent: {
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]?.modelSelection).toEqual(
|
||||
modelSelection("claudeAgent", "claude-opus-4-6", {
|
||||
thinking: false,
|
||||
},
|
||||
});
|
||||
expect(useComposerDraftStore.getState().stickyModelOptions).toEqual({
|
||||
codex: {
|
||||
}),
|
||||
);
|
||||
expect(useComposerDraftStore.getState().stickyModelSelection).toEqual(
|
||||
modelSelection("claudeAgent", "claude-opus-4-6", { effort: "max" }),
|
||||
);
|
||||
});
|
||||
|
||||
it("creates the first sticky snapshot from provider option changes", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
|
||||
store.setModelSelection(threadId, modelSelection("codex", "gpt-5.4"));
|
||||
|
||||
store.setProviderModelOptions(
|
||||
threadId,
|
||||
"codex",
|
||||
{
|
||||
fastMode: true,
|
||||
},
|
||||
});
|
||||
{ persistSticky: true },
|
||||
);
|
||||
|
||||
expect(useComposerDraftStore.getState().stickyModelSelection).toEqual(
|
||||
modelSelection("codex", "gpt-5.4", {
|
||||
fastMode: true,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("updates only the draft when sticky persistence is disabled", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
|
||||
store.setStickyModelOptions({
|
||||
claudeAgent: {
|
||||
effort: "max",
|
||||
},
|
||||
});
|
||||
store.setModelOptions(threadId, {
|
||||
claudeAgent: {
|
||||
effort: "max",
|
||||
},
|
||||
});
|
||||
store.setStickyModelSelection(
|
||||
modelSelection("claudeAgent", "claude-opus-4-6", { effort: "max" }),
|
||||
);
|
||||
store.setModelSelection(
|
||||
threadId,
|
||||
modelSelection("claudeAgent", "claude-opus-4-6", { effort: "max" }),
|
||||
);
|
||||
|
||||
store.setProviderModelOptions(
|
||||
threadId,
|
||||
@@ -779,33 +779,31 @@ describe("composerDraftStore modelOptions", () => {
|
||||
{ persistSticky: false },
|
||||
);
|
||||
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]?.modelOptions).toEqual({
|
||||
claudeAgent: {
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]?.modelSelection).toEqual(
|
||||
modelSelection("claudeAgent", "claude-opus-4-6", {
|
||||
thinking: false,
|
||||
},
|
||||
});
|
||||
expect(useComposerDraftStore.getState().stickyModelOptions).toEqual({
|
||||
claudeAgent: {
|
||||
effort: "max",
|
||||
},
|
||||
});
|
||||
}),
|
||||
);
|
||||
expect(useComposerDraftStore.getState().stickyModelSelection).toEqual(
|
||||
modelSelection("claudeAgent", "claude-opus-4-6", { effort: "max" }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("composerDraftStore setModel", () => {
|
||||
describe("composerDraftStore setModelSelection", () => {
|
||||
const threadId = ThreadId.makeUnsafe("thread-model");
|
||||
|
||||
beforeEach(() => {
|
||||
resetComposerDraftStore();
|
||||
});
|
||||
|
||||
it("keeps explicit DEFAULT_MODEL overrides instead of coercing to null", () => {
|
||||
it("keeps explicit model overrides instead of coercing to null", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
|
||||
store.setModel(threadId, "gpt-5.3-codex");
|
||||
store.setModelSelection(threadId, modelSelection("codex", "gpt-5.3-codex"));
|
||||
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]?.model).toBe(
|
||||
"gpt-5.3-codex",
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]?.modelSelection).toEqual(
|
||||
modelSelection("codex", "gpt-5.3-codex"),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -815,21 +813,21 @@ describe("composerDraftStore sticky composer settings", () => {
|
||||
resetComposerDraftStore();
|
||||
});
|
||||
|
||||
it("stores sticky model and codex model options", () => {
|
||||
it("stores a sticky model selection", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
|
||||
store.setStickyModel("gpt-5.3-codex");
|
||||
store.setStickyModelOptions({
|
||||
codex: {
|
||||
store.setStickyModelSelection(
|
||||
modelSelection("codex", "gpt-5.3-codex", {
|
||||
reasoningEffort: "medium",
|
||||
fastMode: true,
|
||||
},
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
expect(useComposerDraftStore.getState()).toMatchObject({
|
||||
stickyModel: "gpt-5.3-codex",
|
||||
stickyModelOptions: {
|
||||
codex: {
|
||||
stickyModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
options: {
|
||||
reasoningEffort: "medium",
|
||||
fastMode: true,
|
||||
},
|
||||
@@ -837,41 +835,38 @@ describe("composerDraftStore sticky composer settings", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("normalizes empty sticky model options", () => {
|
||||
it("normalizes empty sticky model options by dropping selection options", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
|
||||
store.setStickyModelOptions({
|
||||
codex: {
|
||||
fastMode: false,
|
||||
},
|
||||
});
|
||||
store.setStickyModelSelection(modelSelection("codex", "gpt-5.4"));
|
||||
|
||||
expect(useComposerDraftStore.getState().stickyModelOptions).toEqual({});
|
||||
expect(useComposerDraftStore.getState().stickyModelSelection).toEqual(
|
||||
modelSelection("codex", "gpt-5.4"),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("composerDraftStore setProvider", () => {
|
||||
describe("composerDraftStore provider-scoped option updates", () => {
|
||||
const threadId = ThreadId.makeUnsafe("thread-provider");
|
||||
|
||||
beforeEach(() => {
|
||||
resetComposerDraftStore();
|
||||
});
|
||||
|
||||
it("persists provider-only selection even when prompt/model are empty", () => {
|
||||
it("does not patch provider options when the draft selection is on another provider", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
|
||||
store.setProvider(threadId, "codex");
|
||||
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]?.provider).toBe("codex");
|
||||
});
|
||||
|
||||
it("removes empty provider-only draft when provider is reset", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
|
||||
store.setProvider(threadId, "codex");
|
||||
store.setProvider(threadId, null);
|
||||
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]).toBeUndefined();
|
||||
store.setModelSelection(
|
||||
threadId,
|
||||
modelSelection("codex", "gpt-5.3-codex", {
|
||||
reasoningEffort: "medium",
|
||||
}),
|
||||
);
|
||||
store.setProviderModelOptions(threadId, "claudeAgent", { effort: "max" });
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]?.modelSelection).toEqual(
|
||||
modelSelection("codex", "gpt-5.3-codex", {
|
||||
reasoningEffort: "medium",
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+128
-186
@@ -3,6 +3,7 @@ import {
|
||||
type ClaudeCodeEffort,
|
||||
type CodexReasoningEffort,
|
||||
DEFAULT_REASONING_EFFORT_BY_PROVIDER,
|
||||
type ModelSelection,
|
||||
ProjectId,
|
||||
ProviderInteractionMode,
|
||||
ProviderKind,
|
||||
@@ -73,9 +74,7 @@ const PersistedComposerThreadDraftState = Schema.Struct({
|
||||
prompt: Schema.String,
|
||||
attachments: Schema.Array(PersistedComposerImageAttachment),
|
||||
terminalContexts: Schema.optionalKey(Schema.Array(PersistedTerminalContextDraft)),
|
||||
provider: Schema.optionalKey(ProviderKind),
|
||||
model: Schema.optionalKey(Schema.String),
|
||||
modelOptions: Schema.optionalKey(ProviderModelOptions),
|
||||
modelSelection: Schema.optionalKey(Schema.NullOr(Schema.Unknown)),
|
||||
runtimeMode: Schema.optionalKey(RuntimeMode),
|
||||
interactionMode: Schema.optionalKey(ProviderInteractionMode),
|
||||
});
|
||||
@@ -89,6 +88,11 @@ const LegacyCodexFields = Schema.Struct({
|
||||
type LegacyCodexFields = typeof LegacyCodexFields.Type;
|
||||
|
||||
type LegacyPersistedCodexThreadDraftState = PersistedComposerThreadDraftState & LegacyCodexFields;
|
||||
type LegacyPersistedComposerThreadDraftState = LegacyPersistedCodexThreadDraftState & {
|
||||
provider?: ProviderKind;
|
||||
model?: string;
|
||||
modelOptions?: ProviderModelOptions | null;
|
||||
};
|
||||
|
||||
const PersistedDraftThreadState = Schema.Struct({
|
||||
projectId: ProjectId,
|
||||
@@ -105,8 +109,7 @@ const PersistedComposerDraftStoreState = Schema.Struct({
|
||||
draftsByThreadId: Schema.Record(ThreadId, PersistedComposerThreadDraftState),
|
||||
draftThreadsByThreadId: Schema.Record(ThreadId, PersistedDraftThreadState),
|
||||
projectDraftThreadIdByProjectId: Schema.Record(ProjectId, ThreadId),
|
||||
stickyModel: Schema.NullOr(Schema.String),
|
||||
stickyModelOptions: ProviderModelOptions,
|
||||
stickyModelSelection: Schema.NullOr(Schema.Unknown),
|
||||
});
|
||||
type PersistedComposerDraftStoreState = typeof PersistedComposerDraftStoreState.Type;
|
||||
|
||||
@@ -121,9 +124,7 @@ interface ComposerThreadDraftState {
|
||||
nonPersistedImageIds: string[];
|
||||
persistedAttachments: PersistedComposerImageAttachment[];
|
||||
terminalContexts: TerminalContextDraft[];
|
||||
provider: ProviderKind | null;
|
||||
model: string | null;
|
||||
modelOptions: ProviderModelOptions | null;
|
||||
modelSelection: ModelSelection | null;
|
||||
runtimeMode: RuntimeMode | null;
|
||||
interactionMode: ProviderInteractionMode | null;
|
||||
}
|
||||
@@ -146,8 +147,7 @@ interface ComposerDraftStoreState {
|
||||
draftsByThreadId: Record<ThreadId, ComposerThreadDraftState>;
|
||||
draftThreadsByThreadId: Record<ThreadId, DraftThreadState>;
|
||||
projectDraftThreadIdByProjectId: Record<ProjectId, ThreadId>;
|
||||
stickyModel: string | null;
|
||||
stickyModelOptions: ProviderModelOptions;
|
||||
stickyModelSelection: ModelSelection | null;
|
||||
getDraftThreadByProjectId: (projectId: ProjectId) => ProjectDraftThread | null;
|
||||
getDraftThread: (threadId: ThreadId) => DraftThreadState | null;
|
||||
setProjectDraftThreadId: (
|
||||
@@ -177,15 +177,12 @@ interface ComposerDraftStoreState {
|
||||
clearProjectDraftThreadId: (projectId: ProjectId) => void;
|
||||
clearProjectDraftThreadById: (projectId: ProjectId, threadId: ThreadId) => void;
|
||||
clearDraftThread: (threadId: ThreadId) => void;
|
||||
setStickyModel: (model: string | null | undefined) => void;
|
||||
setStickyModelOptions: (modelOptions: ProviderModelOptions | null | undefined) => void;
|
||||
setStickyModelSelection: (modelSelection: ModelSelection | null | undefined) => void;
|
||||
setPrompt: (threadId: ThreadId, prompt: string) => void;
|
||||
setTerminalContexts: (threadId: ThreadId, contexts: TerminalContextDraft[]) => void;
|
||||
setProvider: (threadId: ThreadId, provider: ProviderKind | null | undefined) => void;
|
||||
setModel: (threadId: ThreadId, model: string | null | undefined) => void;
|
||||
setModelOptions: (
|
||||
setModelSelection: (
|
||||
threadId: ThreadId,
|
||||
modelOptions: ProviderModelOptions | null | undefined,
|
||||
modelSelection: ModelSelection | null | undefined,
|
||||
) => void;
|
||||
setProviderModelOptions: (
|
||||
threadId: ThreadId,
|
||||
@@ -221,14 +218,11 @@ interface ComposerDraftStoreState {
|
||||
clearComposerContent: (threadId: ThreadId) => void;
|
||||
}
|
||||
|
||||
const EMPTY_PROVIDER_MODEL_OPTIONS = Object.freeze<ProviderModelOptions>({});
|
||||
|
||||
const EMPTY_PERSISTED_DRAFT_STORE_STATE = Object.freeze<PersistedComposerDraftStoreState>({
|
||||
draftsByThreadId: {},
|
||||
draftThreadsByThreadId: {},
|
||||
projectDraftThreadIdByProjectId: {},
|
||||
stickyModel: null,
|
||||
stickyModelOptions: EMPTY_PROVIDER_MODEL_OPTIONS,
|
||||
stickyModelSelection: null,
|
||||
});
|
||||
|
||||
const EMPTY_IMAGES: ComposerImageAttachment[] = [];
|
||||
@@ -244,9 +238,7 @@ const EMPTY_THREAD_DRAFT = Object.freeze<ComposerThreadDraftState>({
|
||||
nonPersistedImageIds: EMPTY_IDS,
|
||||
persistedAttachments: EMPTY_PERSISTED_ATTACHMENTS,
|
||||
terminalContexts: EMPTY_TERMINAL_CONTEXTS,
|
||||
provider: null,
|
||||
model: null,
|
||||
modelOptions: null,
|
||||
modelSelection: null,
|
||||
runtimeMode: null,
|
||||
interactionMode: null,
|
||||
});
|
||||
@@ -258,9 +250,7 @@ function createEmptyThreadDraft(): ComposerThreadDraftState {
|
||||
nonPersistedImageIds: [],
|
||||
persistedAttachments: [],
|
||||
terminalContexts: [],
|
||||
provider: null,
|
||||
model: null,
|
||||
modelOptions: null,
|
||||
modelSelection: null,
|
||||
runtimeMode: null,
|
||||
interactionMode: null,
|
||||
};
|
||||
@@ -329,9 +319,7 @@ function shouldRemoveDraft(draft: ComposerThreadDraftState): boolean {
|
||||
draft.images.length === 0 &&
|
||||
draft.persistedAttachments.length === 0 &&
|
||||
draft.terminalContexts.length === 0 &&
|
||||
draft.provider === null &&
|
||||
draft.model === null &&
|
||||
draft.modelOptions === null &&
|
||||
draft.modelSelection === null &&
|
||||
draft.runtimeMode === null &&
|
||||
draft.interactionMode === null
|
||||
);
|
||||
@@ -415,6 +403,41 @@ function normalizeProviderModelOptions(
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeModelSelection(
|
||||
value: unknown,
|
||||
legacy?: {
|
||||
provider?: unknown;
|
||||
model?: unknown;
|
||||
modelOptions?: unknown;
|
||||
legacyCodex?: LegacyCodexFields;
|
||||
},
|
||||
): ModelSelection | null {
|
||||
const candidate = value && typeof value === "object" ? (value as Record<string, unknown>) : null;
|
||||
const provider = normalizeProviderKind(candidate?.provider ?? legacy?.provider);
|
||||
if (provider === null) {
|
||||
return null;
|
||||
}
|
||||
const rawModel = candidate?.model ?? legacy?.model;
|
||||
if (typeof rawModel !== "string") {
|
||||
return null;
|
||||
}
|
||||
const model = normalizeModelSlug(rawModel, provider);
|
||||
if (!model) {
|
||||
return null;
|
||||
}
|
||||
const modelOptions = normalizeProviderModelOptions(
|
||||
candidate?.options ? { [provider]: candidate.options } : legacy?.modelOptions,
|
||||
provider,
|
||||
provider === "codex" ? legacy?.legacyCodex : undefined,
|
||||
);
|
||||
const options = provider === "codex" ? modelOptions?.codex : modelOptions?.claudeAgent;
|
||||
return {
|
||||
provider,
|
||||
model,
|
||||
...(options ? { options } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
function replaceProviderModelOptions(
|
||||
currentModelOptions: ProviderModelOptions | null | undefined,
|
||||
provider: ProviderKind,
|
||||
@@ -619,10 +642,6 @@ function normalizePersistedDraftThreads(
|
||||
|
||||
function normalizePersistedDraftsByThreadId(
|
||||
rawDraftMap: unknown,
|
||||
resolveModelOptions: (
|
||||
draftCandidate: PersistedComposerThreadDraftState | LegacyPersistedCodexThreadDraftState,
|
||||
provider: ProviderKind | null,
|
||||
) => ProviderModelOptions | null,
|
||||
): PersistedComposerDraftStoreState["draftsByThreadId"] {
|
||||
if (!rawDraftMap || typeof rawDraftMap !== "object") {
|
||||
return {};
|
||||
@@ -653,11 +672,6 @@ function normalizePersistedDraftsByThreadId(
|
||||
return normalized ? [normalized] : [];
|
||||
})
|
||||
: [];
|
||||
const provider = normalizeProviderKind(draftCandidate.provider);
|
||||
const model =
|
||||
typeof draftCandidate.model === "string"
|
||||
? normalizeModelSlug(draftCandidate.model, provider ?? "codex")
|
||||
: null;
|
||||
const runtimeMode =
|
||||
draftCandidate.runtimeMode === "approval-required" ||
|
||||
draftCandidate.runtimeMode === "full-access"
|
||||
@@ -667,18 +681,22 @@ function normalizePersistedDraftsByThreadId(
|
||||
draftCandidate.interactionMode === "plan" || draftCandidate.interactionMode === "default"
|
||||
? draftCandidate.interactionMode
|
||||
: null;
|
||||
const modelOptions = resolveModelOptions(draftCandidate, provider);
|
||||
const prompt = ensureInlineTerminalContextPlaceholders(
|
||||
promptCandidate,
|
||||
terminalContexts.length,
|
||||
);
|
||||
const legacyDraftCandidate = draftCandidate as LegacyPersistedComposerThreadDraftState;
|
||||
const modelSelection = normalizeModelSelection(draftCandidate.modelSelection, {
|
||||
provider: legacyDraftCandidate.provider,
|
||||
model: legacyDraftCandidate.model,
|
||||
modelOptions: legacyDraftCandidate.modelOptions,
|
||||
legacyCodex: legacyDraftCandidate,
|
||||
});
|
||||
if (
|
||||
promptCandidate.length === 0 &&
|
||||
attachments.length === 0 &&
|
||||
terminalContexts.length === 0 &&
|
||||
!provider &&
|
||||
!model &&
|
||||
modelOptions === null &&
|
||||
modelSelection === null &&
|
||||
!runtimeMode &&
|
||||
!interactionMode
|
||||
) {
|
||||
@@ -688,9 +706,7 @@ function normalizePersistedDraftsByThreadId(
|
||||
prompt,
|
||||
attachments,
|
||||
...(terminalContexts.length > 0 ? { terminalContexts } : {}),
|
||||
...(provider ? { provider } : {}),
|
||||
...(model ? { model } : {}),
|
||||
...(modelOptions ? { modelOptions } : {}),
|
||||
...(modelSelection ? { modelSelection } : {}),
|
||||
...(runtimeMode ? { runtimeMode } : {}),
|
||||
...(interactionMode ? { interactionMode } : {}),
|
||||
};
|
||||
@@ -701,7 +717,6 @@ function normalizePersistedDraftsByThreadId(
|
||||
|
||||
function migratePersistedComposerDraftStoreState(
|
||||
persistedState: unknown,
|
||||
persistedVersion: number,
|
||||
): PersistedComposerDraftStoreState {
|
||||
if (!persistedState || typeof persistedState !== "object") {
|
||||
return EMPTY_PERSISTED_DRAFT_STORE_STATE;
|
||||
@@ -710,31 +725,19 @@ function migratePersistedComposerDraftStoreState(
|
||||
const rawDraftMap = candidate.draftsByThreadId;
|
||||
const rawDraftThreadsByThreadId = candidate.draftThreadsByThreadId;
|
||||
const rawProjectDraftThreadIdByProjectId = candidate.projectDraftThreadIdByProjectId;
|
||||
const stickyModel =
|
||||
typeof candidate.stickyModel === "string"
|
||||
? (normalizeModelSlug(candidate.stickyModel, "codex") ?? null)
|
||||
: null;
|
||||
const stickyModelOptions =
|
||||
normalizeProviderModelOptions(candidate.stickyModelOptions) ?? EMPTY_PROVIDER_MODEL_OPTIONS;
|
||||
const stickyModelSelection = normalizeModelSelection(candidate.stickyModelSelection, {
|
||||
provider: candidate.stickyProvider ?? "codex",
|
||||
model: candidate.stickyModel,
|
||||
modelOptions: candidate.stickyModelOptions,
|
||||
});
|
||||
const { draftThreadsByThreadId, projectDraftThreadIdByProjectId } =
|
||||
normalizePersistedDraftThreads(rawDraftThreadsByThreadId, rawProjectDraftThreadIdByProjectId);
|
||||
const draftsByThreadId = normalizePersistedDraftsByThreadId(
|
||||
rawDraftMap,
|
||||
(draftCandidate, provider) =>
|
||||
persistedVersion >= COMPOSER_DRAFT_STORAGE_VERSION
|
||||
? normalizeProviderModelOptions(draftCandidate.modelOptions, provider)
|
||||
: normalizeProviderModelOptions(
|
||||
draftCandidate.modelOptions,
|
||||
provider,
|
||||
draftCandidate as LegacyPersistedCodexThreadDraftState,
|
||||
),
|
||||
);
|
||||
const draftsByThreadId = normalizePersistedDraftsByThreadId(rawDraftMap);
|
||||
return {
|
||||
draftsByThreadId,
|
||||
draftThreadsByThreadId,
|
||||
projectDraftThreadIdByProjectId,
|
||||
stickyModel,
|
||||
stickyModelOptions,
|
||||
stickyModelSelection,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -752,9 +755,7 @@ function partializeComposerDraftStoreState(
|
||||
draft.prompt.length === 0 &&
|
||||
draft.persistedAttachments.length === 0 &&
|
||||
draft.terminalContexts.length === 0 &&
|
||||
draft.provider === null &&
|
||||
draft.model === null &&
|
||||
draft.modelOptions === null &&
|
||||
draft.modelSelection === null &&
|
||||
draft.runtimeMode === null &&
|
||||
draft.interactionMode === null
|
||||
) {
|
||||
@@ -776,9 +777,7 @@ function partializeComposerDraftStoreState(
|
||||
})),
|
||||
}
|
||||
: {}),
|
||||
...(draft.model ? { model: draft.model } : {}),
|
||||
...(draft.modelOptions ? { modelOptions: draft.modelOptions } : {}),
|
||||
...(draft.provider ? { provider: draft.provider } : {}),
|
||||
...(draft.modelSelection ? { modelSelection: draft.modelSelection } : {}),
|
||||
...(draft.runtimeMode ? { runtimeMode: draft.runtimeMode } : {}),
|
||||
...(draft.interactionMode ? { interactionMode: draft.interactionMode } : {}),
|
||||
};
|
||||
@@ -788,8 +787,7 @@ function partializeComposerDraftStoreState(
|
||||
draftsByThreadId: persistedDraftsByThreadId,
|
||||
draftThreadsByThreadId: state.draftThreadsByThreadId,
|
||||
projectDraftThreadIdByProjectId: state.projectDraftThreadIdByProjectId,
|
||||
stickyModel: state.stickyModel,
|
||||
stickyModelOptions: state.stickyModelOptions,
|
||||
stickyModelSelection: state.stickyModelSelection,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -805,23 +803,19 @@ function normalizeCurrentPersistedComposerDraftStoreState(
|
||||
normalizedPersistedState.draftThreadsByThreadId,
|
||||
normalizedPersistedState.projectDraftThreadIdByProjectId,
|
||||
);
|
||||
const stickyModel =
|
||||
typeof normalizedPersistedState.stickyModel === "string"
|
||||
? (normalizeModelSlug(normalizedPersistedState.stickyModel, "codex") ?? null)
|
||||
: null;
|
||||
const stickyModelOptions =
|
||||
normalizeProviderModelOptions(normalizedPersistedState.stickyModelOptions) ??
|
||||
EMPTY_PROVIDER_MODEL_OPTIONS;
|
||||
const stickyModelSelection = normalizeModelSelection(
|
||||
normalizedPersistedState.stickyModelSelection,
|
||||
{
|
||||
provider: normalizedPersistedState.stickyProvider,
|
||||
model: normalizedPersistedState.stickyModel,
|
||||
modelOptions: normalizedPersistedState.stickyModelOptions,
|
||||
},
|
||||
);
|
||||
return {
|
||||
draftsByThreadId: normalizePersistedDraftsByThreadId(
|
||||
normalizedPersistedState.draftsByThreadId,
|
||||
(draftCandidate, provider) =>
|
||||
normalizeProviderModelOptions(draftCandidate.modelOptions, provider),
|
||||
),
|
||||
draftsByThreadId: normalizePersistedDraftsByThreadId(normalizedPersistedState.draftsByThreadId),
|
||||
draftThreadsByThreadId,
|
||||
projectDraftThreadIdByProjectId,
|
||||
stickyModel,
|
||||
stickyModelOptions,
|
||||
stickyModelSelection,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -958,9 +952,12 @@ function toHydratedThreadDraft(
|
||||
...context,
|
||||
text: "",
|
||||
})) ?? [],
|
||||
provider: persistedDraft.provider ?? null,
|
||||
model: persistedDraft.model ?? null,
|
||||
modelOptions: persistedDraft.modelOptions ?? null,
|
||||
modelSelection: normalizeModelSelection(persistedDraft.modelSelection, {
|
||||
provider: (persistedDraft as LegacyPersistedComposerThreadDraftState).provider,
|
||||
model: (persistedDraft as LegacyPersistedComposerThreadDraftState).model,
|
||||
modelOptions: (persistedDraft as LegacyPersistedComposerThreadDraftState).modelOptions,
|
||||
legacyCodex: persistedDraft as LegacyPersistedComposerThreadDraftState,
|
||||
}),
|
||||
runtimeMode: persistedDraft.runtimeMode ?? null,
|
||||
interactionMode: persistedDraft.interactionMode ?? null,
|
||||
};
|
||||
@@ -972,8 +969,7 @@ export const useComposerDraftStore = create<ComposerDraftStoreState>()(
|
||||
draftsByThreadId: {},
|
||||
draftThreadsByThreadId: {},
|
||||
projectDraftThreadIdByProjectId: {},
|
||||
stickyModel: null,
|
||||
stickyModelOptions: EMPTY_PROVIDER_MODEL_OPTIONS,
|
||||
stickyModelSelection: null,
|
||||
getDraftThreadByProjectId: (projectId) => {
|
||||
if (projectId.length === 0) {
|
||||
return null;
|
||||
@@ -1219,28 +1215,13 @@ export const useComposerDraftStore = create<ComposerDraftStoreState>()(
|
||||
};
|
||||
});
|
||||
},
|
||||
setStickyModel: (model) => {
|
||||
const normalizedModel = normalizeModelSlug(model, "codex") ?? null;
|
||||
set((state) => {
|
||||
if (state.stickyModel === normalizedModel) {
|
||||
return state;
|
||||
}
|
||||
return {
|
||||
stickyModel: normalizedModel,
|
||||
};
|
||||
});
|
||||
},
|
||||
setStickyModelOptions: (modelOptions) => {
|
||||
const normalizedModelOptions =
|
||||
normalizeProviderModelOptions(modelOptions) ?? EMPTY_PROVIDER_MODEL_OPTIONS;
|
||||
set((state) => {
|
||||
if (Equal.equals(state.stickyModelOptions, normalizedModelOptions)) {
|
||||
return state;
|
||||
}
|
||||
return {
|
||||
stickyModelOptions: normalizedModelOptions,
|
||||
};
|
||||
});
|
||||
setStickyModelSelection: (modelSelection) => {
|
||||
const normalizedModelSelection = normalizeModelSelection(modelSelection);
|
||||
set((state) =>
|
||||
Equal.equals(state.stickyModelSelection, normalizedModelSelection)
|
||||
? state
|
||||
: { stickyModelSelection: normalizedModelSelection },
|
||||
);
|
||||
},
|
||||
setPrompt: (threadId, prompt) => {
|
||||
if (threadId.length === 0) {
|
||||
@@ -1285,78 +1266,23 @@ export const useComposerDraftStore = create<ComposerDraftStoreState>()(
|
||||
return { draftsByThreadId: nextDraftsByThreadId };
|
||||
});
|
||||
},
|
||||
setProvider: (threadId, provider) => {
|
||||
setModelSelection: (threadId, modelSelection) => {
|
||||
if (threadId.length === 0) {
|
||||
return;
|
||||
}
|
||||
const normalizedProvider = normalizeProviderKind(provider);
|
||||
const normalizedModelSelection = normalizeModelSelection(modelSelection);
|
||||
set((state) => {
|
||||
const existing = state.draftsByThreadId[threadId];
|
||||
if (!existing && normalizedProvider === null) {
|
||||
if (!existing && normalizedModelSelection === null) {
|
||||
return state;
|
||||
}
|
||||
const base = existing ?? createEmptyThreadDraft();
|
||||
if (base.provider === normalizedProvider) {
|
||||
if (Equal.equals(base.modelSelection, normalizedModelSelection)) {
|
||||
return state;
|
||||
}
|
||||
const nextDraft: ComposerThreadDraftState = {
|
||||
...base,
|
||||
provider: normalizedProvider,
|
||||
};
|
||||
const nextDraftsByThreadId = { ...state.draftsByThreadId };
|
||||
if (shouldRemoveDraft(nextDraft)) {
|
||||
delete nextDraftsByThreadId[threadId];
|
||||
} else {
|
||||
nextDraftsByThreadId[threadId] = nextDraft;
|
||||
}
|
||||
return { draftsByThreadId: nextDraftsByThreadId };
|
||||
});
|
||||
},
|
||||
setModel: (threadId, model) => {
|
||||
if (threadId.length === 0) {
|
||||
return;
|
||||
}
|
||||
set((state) => {
|
||||
const existing = state.draftsByThreadId[threadId];
|
||||
const normalizedModel = normalizeModelSlug(model, existing?.provider ?? "codex") ?? null;
|
||||
if (!existing && normalizedModel === null) {
|
||||
return state;
|
||||
}
|
||||
const base = existing ?? createEmptyThreadDraft();
|
||||
if (base.model === normalizedModel) {
|
||||
return state;
|
||||
}
|
||||
const nextDraft: ComposerThreadDraftState = {
|
||||
...base,
|
||||
model: normalizedModel,
|
||||
};
|
||||
const nextDraftsByThreadId = { ...state.draftsByThreadId };
|
||||
if (shouldRemoveDraft(nextDraft)) {
|
||||
delete nextDraftsByThreadId[threadId];
|
||||
} else {
|
||||
nextDraftsByThreadId[threadId] = nextDraft;
|
||||
}
|
||||
return { draftsByThreadId: nextDraftsByThreadId };
|
||||
});
|
||||
},
|
||||
setModelOptions: (threadId, modelOptions) => {
|
||||
if (threadId.length === 0) {
|
||||
return;
|
||||
}
|
||||
set((state) => {
|
||||
const existing = state.draftsByThreadId[threadId];
|
||||
const provider = existing?.provider ?? null;
|
||||
const nextModelOptions = normalizeProviderModelOptions(modelOptions, provider);
|
||||
if (!existing && nextModelOptions === null) {
|
||||
return state;
|
||||
}
|
||||
const base = existing ?? createEmptyThreadDraft();
|
||||
if (Equal.equals(base.modelOptions, nextModelOptions)) {
|
||||
return state;
|
||||
}
|
||||
const nextDraft: ComposerThreadDraftState = {
|
||||
...base,
|
||||
modelOptions: nextModelOptions,
|
||||
modelSelection: normalizedModelSelection,
|
||||
};
|
||||
const nextDraftsByThreadId = { ...state.draftsByThreadId };
|
||||
if (shouldRemoveDraft(nextDraft)) {
|
||||
@@ -1378,26 +1304,43 @@ export const useComposerDraftStore = create<ComposerDraftStoreState>()(
|
||||
set((state) => {
|
||||
const existing = state.draftsByThreadId[threadId];
|
||||
const base = existing ?? createEmptyThreadDraft();
|
||||
const nextModelOptions = replaceProviderModelOptions(
|
||||
base.modelOptions,
|
||||
if (base.modelSelection?.provider !== normalizedProvider) {
|
||||
return state;
|
||||
}
|
||||
const nextProviderModelOptions = replaceProviderModelOptions(
|
||||
base.modelSelection?.options
|
||||
? { [normalizedProvider]: base.modelSelection.options }
|
||||
: null,
|
||||
normalizedProvider,
|
||||
nextProviderOptions,
|
||||
);
|
||||
const nextStickyModelOptions =
|
||||
options?.persistSticky === true
|
||||
? (nextModelOptions ?? EMPTY_PROVIDER_MODEL_OPTIONS)
|
||||
: state.stickyModelOptions;
|
||||
const nextOptions =
|
||||
normalizedProvider === "codex"
|
||||
? nextProviderModelOptions?.codex
|
||||
: nextProviderModelOptions?.claudeAgent;
|
||||
const nextModelSelection =
|
||||
base.modelSelection === null
|
||||
? null
|
||||
: {
|
||||
provider: base.modelSelection.provider,
|
||||
model: base.modelSelection.model,
|
||||
...(nextOptions ? { options: nextOptions } : {}),
|
||||
};
|
||||
const nextStickyModelSelection =
|
||||
options?.persistSticky === true && nextModelSelection !== null
|
||||
? nextModelSelection
|
||||
: state.stickyModelSelection;
|
||||
|
||||
if (
|
||||
Equal.equals(base.modelOptions, nextModelOptions) &&
|
||||
Equal.equals(state.stickyModelOptions, nextStickyModelOptions)
|
||||
Equal.equals(base.modelSelection, nextModelSelection) &&
|
||||
Equal.equals(state.stickyModelSelection, nextStickyModelSelection)
|
||||
) {
|
||||
return state;
|
||||
}
|
||||
|
||||
const nextDraft: ComposerThreadDraftState = {
|
||||
...base,
|
||||
modelOptions: nextModelOptions,
|
||||
modelSelection: nextModelSelection,
|
||||
};
|
||||
const nextDraftsByThreadId = { ...state.draftsByThreadId };
|
||||
if (shouldRemoveDraft(nextDraft)) {
|
||||
@@ -1409,7 +1352,7 @@ export const useComposerDraftStore = create<ComposerDraftStoreState>()(
|
||||
return {
|
||||
draftsByThreadId: nextDraftsByThreadId,
|
||||
...(options?.persistSticky === true
|
||||
? { stickyModelOptions: nextStickyModelOptions }
|
||||
? { stickyModelSelection: nextStickyModelSelection }
|
||||
: {}),
|
||||
};
|
||||
});
|
||||
@@ -1768,8 +1711,7 @@ export const useComposerDraftStore = create<ComposerDraftStoreState>()(
|
||||
draftsByThreadId,
|
||||
draftThreadsByThreadId: normalizedPersisted.draftThreadsByThreadId,
|
||||
projectDraftThreadIdByProjectId: normalizedPersisted.projectDraftThreadIdByProjectId,
|
||||
stickyModel: normalizedPersisted.stickyModel,
|
||||
stickyModelOptions: normalizedPersisted.stickyModelOptions,
|
||||
stickyModelSelection: normalizedPersisted.stickyModelSelection as ModelSelection | null,
|
||||
};
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { DEFAULT_RUNTIME_MODE, type ProjectId, ThreadId } from "@t3tools/contracts";
|
||||
import { useNavigate, useParams } from "@tanstack/react-router";
|
||||
import { useCallback } from "react";
|
||||
import { inferProviderForModel } from "@t3tools/shared/model";
|
||||
import {
|
||||
type DraftThreadEnvMode,
|
||||
type DraftThreadState,
|
||||
@@ -13,8 +12,7 @@ import { useStore } from "../store";
|
||||
export function useHandleNewThread() {
|
||||
const projects = useStore((store) => store.projects);
|
||||
const threads = useStore((store) => store.threads);
|
||||
const stickyModel = useComposerDraftStore((store) => store.stickyModel);
|
||||
const stickyModelOptions = useComposerDraftStore((store) => store.stickyModelOptions);
|
||||
const stickyModelSelection = useComposerDraftStore((store) => store.stickyModelSelection);
|
||||
const navigate = useNavigate();
|
||||
const routeThreadId = useParams({
|
||||
strict: false,
|
||||
@@ -41,9 +39,7 @@ export function useHandleNewThread() {
|
||||
clearProjectDraftThreadId,
|
||||
getDraftThread,
|
||||
getDraftThreadByProjectId,
|
||||
setModel,
|
||||
setModelOptions,
|
||||
setProvider,
|
||||
setModelSelection,
|
||||
setDraftThreadContext,
|
||||
setProjectDraftThreadId,
|
||||
} = useComposerDraftStore.getState();
|
||||
@@ -102,12 +98,8 @@ export function useHandleNewThread() {
|
||||
envMode: options?.envMode ?? "local",
|
||||
runtimeMode: DEFAULT_RUNTIME_MODE,
|
||||
});
|
||||
if (stickyModel) {
|
||||
setProvider(threadId, inferProviderForModel(stickyModel));
|
||||
setModel(threadId, stickyModel);
|
||||
}
|
||||
if (Object.keys(stickyModelOptions).length > 0) {
|
||||
setModelOptions(threadId, stickyModelOptions);
|
||||
if (stickyModelSelection) {
|
||||
setModelSelection(threadId, stickyModelSelection);
|
||||
}
|
||||
|
||||
await navigate({
|
||||
@@ -116,7 +108,7 @@ export function useHandleNewThread() {
|
||||
});
|
||||
})();
|
||||
},
|
||||
[navigate, routeThreadId, stickyModel, stickyModelOptions],
|
||||
[navigate, routeThreadId, stickyModelSelection],
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
+50
-14
@@ -16,7 +16,10 @@ function makeThread(overrides: Partial<Thread> = {}): Thread {
|
||||
codexThreadId: null,
|
||||
projectId: ProjectId.makeUnsafe("project-1"),
|
||||
title: "Thread",
|
||||
model: "gpt-5-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
runtimeMode: DEFAULT_RUNTIME_MODE,
|
||||
interactionMode: DEFAULT_INTERACTION_MODE,
|
||||
session: null,
|
||||
@@ -40,7 +43,10 @@ function makeState(thread: Thread): AppState {
|
||||
id: ProjectId.makeUnsafe("project-1"),
|
||||
name: "Project",
|
||||
cwd: "/tmp/project",
|
||||
model: "gpt-5-codex",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
expanded: true,
|
||||
scripts: [],
|
||||
},
|
||||
@@ -55,7 +61,10 @@ function makeReadModelThread(overrides: Partial<OrchestrationReadModel["threads"
|
||||
id: ThreadId.makeUnsafe("thread-1"),
|
||||
projectId: ProjectId.makeUnsafe("project-1"),
|
||||
title: "Thread",
|
||||
model: "gpt-5.3-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
},
|
||||
runtimeMode: DEFAULT_RUNTIME_MODE,
|
||||
interactionMode: DEFAULT_INTERACTION_MODE,
|
||||
branch: null,
|
||||
@@ -82,7 +91,10 @@ function makeReadModel(thread: OrchestrationReadModel["threads"][number]): Orche
|
||||
id: ProjectId.makeUnsafe("project-1"),
|
||||
title: "Project",
|
||||
workspaceRoot: "/tmp/project",
|
||||
defaultModel: "gpt-5.3-codex",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
},
|
||||
createdAt: "2026-02-27T00:00:00.000Z",
|
||||
updatedAt: "2026-02-27T00:00:00.000Z",
|
||||
deletedAt: null,
|
||||
@@ -100,7 +112,10 @@ function makeReadModelProject(
|
||||
id: ProjectId.makeUnsafe("project-1"),
|
||||
title: "Project",
|
||||
workspaceRoot: "/tmp/project",
|
||||
defaultModel: "gpt-5.3-codex",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
},
|
||||
createdAt: "2026-02-27T00:00:00.000Z",
|
||||
updatedAt: "2026-02-27T00:00:00.000Z",
|
||||
deletedAt: null,
|
||||
@@ -159,7 +174,10 @@ describe("store pure functions", () => {
|
||||
id: project1,
|
||||
name: "Project 1",
|
||||
cwd: "/tmp/project-1",
|
||||
model: DEFAULT_MODEL_BY_PROVIDER.codex,
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: DEFAULT_MODEL_BY_PROVIDER.codex,
|
||||
},
|
||||
expanded: true,
|
||||
scripts: [],
|
||||
},
|
||||
@@ -167,7 +185,10 @@ describe("store pure functions", () => {
|
||||
id: project2,
|
||||
name: "Project 2",
|
||||
cwd: "/tmp/project-2",
|
||||
model: DEFAULT_MODEL_BY_PROVIDER.codex,
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: DEFAULT_MODEL_BY_PROVIDER.codex,
|
||||
},
|
||||
expanded: true,
|
||||
scripts: [],
|
||||
},
|
||||
@@ -175,7 +196,10 @@ describe("store pure functions", () => {
|
||||
id: project3,
|
||||
name: "Project 3",
|
||||
cwd: "/tmp/project-3",
|
||||
model: DEFAULT_MODEL_BY_PROVIDER.codex,
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: DEFAULT_MODEL_BY_PROVIDER.codex,
|
||||
},
|
||||
expanded: true,
|
||||
scripts: [],
|
||||
},
|
||||
@@ -195,20 +219,26 @@ describe("store read model sync", () => {
|
||||
const initialState = makeState(makeThread());
|
||||
const readModel = makeReadModel(
|
||||
makeReadModelThread({
|
||||
model: "claude-opus-4-6",
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
const next = syncServerReadModel(initialState, readModel);
|
||||
|
||||
expect(next.threads[0]?.model).toBe("claude-opus-4-6");
|
||||
expect(next.threads[0]?.modelSelection.model).toBe("claude-opus-4-6");
|
||||
});
|
||||
|
||||
it("resolves claude aliases when session provider is claudeAgent", () => {
|
||||
const initialState = makeState(makeThread());
|
||||
const readModel = makeReadModel(
|
||||
makeReadModelThread({
|
||||
model: "sonnet",
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "sonnet",
|
||||
},
|
||||
session: {
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
status: "ready",
|
||||
@@ -223,7 +253,7 @@ describe("store read model sync", () => {
|
||||
|
||||
const next = syncServerReadModel(initialState, readModel);
|
||||
|
||||
expect(next.threads[0]?.model).toBe("claude-sonnet-4-6");
|
||||
expect(next.threads[0]?.modelSelection.model).toBe("claude-sonnet-4-6");
|
||||
});
|
||||
|
||||
it("preserves the current project order when syncing incoming read model updates", () => {
|
||||
@@ -236,7 +266,10 @@ describe("store read model sync", () => {
|
||||
id: project2,
|
||||
name: "Project 2",
|
||||
cwd: "/tmp/project-2",
|
||||
model: DEFAULT_MODEL_BY_PROVIDER.codex,
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: DEFAULT_MODEL_BY_PROVIDER.codex,
|
||||
},
|
||||
expanded: true,
|
||||
scripts: [],
|
||||
},
|
||||
@@ -244,7 +277,10 @@ describe("store read model sync", () => {
|
||||
id: project1,
|
||||
name: "Project 1",
|
||||
cwd: "/tmp/project-1",
|
||||
model: DEFAULT_MODEL_BY_PROVIDER.codex,
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: DEFAULT_MODEL_BY_PROVIDER.codex,
|
||||
},
|
||||
expanded: true,
|
||||
scripts: [],
|
||||
},
|
||||
|
||||
+40
-25
@@ -1,16 +1,13 @@
|
||||
import { Fragment, type ReactNode, createElement, useEffect } from "react";
|
||||
import {
|
||||
DEFAULT_MODEL_BY_PROVIDER,
|
||||
type ModelSelection,
|
||||
type ProviderKind,
|
||||
ThreadId,
|
||||
type OrchestrationReadModel,
|
||||
type OrchestrationSessionStatus,
|
||||
} from "@t3tools/contracts";
|
||||
import {
|
||||
inferProviderForModel,
|
||||
resolveModelSlug,
|
||||
resolveModelSlugForProvider,
|
||||
} from "@t3tools/shared/model";
|
||||
import { resolveModelSlugForProvider } from "@t3tools/shared/model";
|
||||
import { create } from "zustand";
|
||||
import { type ChatMessage, type Project, type Thread } from "./types";
|
||||
import { Debouncer } from "@tanstack/react-pacer";
|
||||
@@ -137,9 +134,17 @@ function mapProjectsFromReadModel(
|
||||
id: project.id,
|
||||
name: project.title,
|
||||
cwd: project.workspaceRoot,
|
||||
model:
|
||||
existing?.model ??
|
||||
resolveModelSlug(project.defaultModel ?? DEFAULT_MODEL_BY_PROVIDER.codex),
|
||||
defaultModelSelection:
|
||||
existing?.defaultModelSelection ??
|
||||
(project.defaultModelSelection
|
||||
? {
|
||||
...project.defaultModelSelection,
|
||||
model: resolveModelSlugForProvider(
|
||||
project.defaultModelSelection.provider,
|
||||
project.defaultModelSelection.model,
|
||||
),
|
||||
}
|
||||
: null),
|
||||
expanded:
|
||||
existing?.expanded ??
|
||||
(persistedExpandedProjectCwds.size > 0
|
||||
@@ -194,16 +199,6 @@ function toLegacyProvider(providerName: string | null): ProviderKind {
|
||||
return "codex";
|
||||
}
|
||||
|
||||
function inferProviderForThreadModel(input: {
|
||||
readonly model: string;
|
||||
readonly sessionProviderName: string | null;
|
||||
}): ProviderKind {
|
||||
if (input.sessionProviderName === "codex" || input.sessionProviderName === "claudeAgent") {
|
||||
return input.sessionProviderName;
|
||||
}
|
||||
return inferProviderForModel(input.model);
|
||||
}
|
||||
|
||||
function resolveWsHttpOrigin(): string {
|
||||
if (typeof window === "undefined") return "";
|
||||
const bridgeWsUrl = window.desktopBridge?.getWsUrl?.();
|
||||
@@ -253,13 +248,13 @@ export function syncServerReadModel(state: AppState, readModel: OrchestrationRea
|
||||
codexThreadId: null,
|
||||
projectId: thread.projectId,
|
||||
title: thread.title,
|
||||
model: resolveModelSlugForProvider(
|
||||
inferProviderForThreadModel({
|
||||
model: thread.model,
|
||||
sessionProviderName: thread.session?.providerName ?? null,
|
||||
}),
|
||||
thread.model,
|
||||
),
|
||||
modelSelection: {
|
||||
...thread.modelSelection,
|
||||
model: resolveModelSlugForProvider(
|
||||
thread.modelSelection.provider,
|
||||
thread.modelSelection.model,
|
||||
),
|
||||
},
|
||||
runtimeMode: thread.runtimeMode,
|
||||
interactionMode: thread.interactionMode,
|
||||
session: thread.session
|
||||
@@ -328,6 +323,26 @@ export function syncServerReadModel(state: AppState, readModel: OrchestrationRea
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveModelSelection(
|
||||
modelSelection: ModelSelection | null | undefined,
|
||||
fallbackProvider: ProviderKind,
|
||||
fallbackModel?: string | null,
|
||||
): ModelSelection {
|
||||
if (modelSelection) {
|
||||
return {
|
||||
...modelSelection,
|
||||
model: resolveModelSlugForProvider(modelSelection.provider, modelSelection.model),
|
||||
};
|
||||
}
|
||||
return {
|
||||
provider: fallbackProvider,
|
||||
model: resolveModelSlugForProvider(
|
||||
fallbackProvider,
|
||||
fallbackModel ?? DEFAULT_MODEL_BY_PROVIDER[fallbackProvider],
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
export function markThreadVisited(
|
||||
state: AppState,
|
||||
threadId: ThreadId,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type {
|
||||
ModelSelection,
|
||||
OrchestrationLatestTurn,
|
||||
OrchestrationProposedPlanId,
|
||||
OrchestrationSessionStatus,
|
||||
@@ -8,8 +9,8 @@ import type {
|
||||
ProjectId,
|
||||
TurnId,
|
||||
MessageId,
|
||||
CheckpointRef,
|
||||
ProviderKind,
|
||||
CheckpointRef,
|
||||
ProviderInteractionMode,
|
||||
RuntimeMode,
|
||||
} from "@t3tools/contracts";
|
||||
@@ -80,7 +81,7 @@ export interface Project {
|
||||
id: ProjectId;
|
||||
name: string;
|
||||
cwd: string;
|
||||
model: string;
|
||||
defaultModelSelection: ModelSelection | null;
|
||||
expanded: boolean;
|
||||
scripts: ProjectScript[];
|
||||
}
|
||||
@@ -90,7 +91,7 @@ export interface Thread {
|
||||
codexThreadId: string | null;
|
||||
projectId: ProjectId;
|
||||
title: string;
|
||||
model: string;
|
||||
modelSelection: ModelSelection;
|
||||
runtimeMode: RuntimeMode;
|
||||
interactionMode: ProviderInteractionMode;
|
||||
session: ThreadSession | null;
|
||||
|
||||
@@ -10,7 +10,10 @@ function makeThread(overrides: Partial<Thread> = {}): Thread {
|
||||
codexThreadId: null,
|
||||
projectId: ProjectId.makeUnsafe("project-1"),
|
||||
title: "Thread",
|
||||
model: "gpt-5.3-codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
},
|
||||
runtimeMode: DEFAULT_RUNTIME_MODE,
|
||||
interactionMode: DEFAULT_INTERACTION_MODE,
|
||||
session: null,
|
||||
|
||||
@@ -269,7 +269,7 @@ describe("wsNativeApi", () => {
|
||||
projectId: ProjectId.makeUnsafe("project-1"),
|
||||
title: "Project",
|
||||
workspaceRoot: "/tmp/workspace",
|
||||
defaultModel: null,
|
||||
defaultModelSelection: null,
|
||||
scripts: [],
|
||||
createdAt: "2026-02-24T00:00:00.000Z",
|
||||
updatedAt: "2026-02-24T00:00:00.000Z",
|
||||
@@ -311,7 +311,10 @@ describe("wsNativeApi", () => {
|
||||
projectId: ProjectId.makeUnsafe("project-1"),
|
||||
title: "Project",
|
||||
workspaceRoot: "/tmp/project",
|
||||
defaultModel: "gpt-5-codex",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5-codex",
|
||||
},
|
||||
createdAt: "2026-02-24T00:00:00.000Z",
|
||||
} as const;
|
||||
await api.orchestration.dispatchCommand(command);
|
||||
|
||||
@@ -7,9 +7,12 @@ import {
|
||||
DEFAULT_RUNTIME_MODE,
|
||||
OrchestrationGetTurnDiffInput,
|
||||
OrchestrationLatestTurn,
|
||||
ProjectCreatedPayload,
|
||||
ProjectMetaUpdatedPayload,
|
||||
OrchestrationProposedPlan,
|
||||
OrchestrationSession,
|
||||
ProjectCreateCommand,
|
||||
ThreadMetaUpdatedPayload,
|
||||
ThreadTurnStartCommand,
|
||||
ThreadCreatedPayload,
|
||||
ThreadTurnDiff,
|
||||
@@ -19,6 +22,8 @@ import {
|
||||
const decodeTurnDiffInput = Schema.decodeUnknownEffect(OrchestrationGetTurnDiffInput);
|
||||
const decodeThreadTurnDiff = Schema.decodeUnknownEffect(ThreadTurnDiff);
|
||||
const decodeProjectCreateCommand = Schema.decodeUnknownEffect(ProjectCreateCommand);
|
||||
const decodeProjectCreatedPayload = Schema.decodeUnknownEffect(ProjectCreatedPayload);
|
||||
const decodeProjectMetaUpdatedPayload = Schema.decodeUnknownEffect(ProjectMetaUpdatedPayload);
|
||||
const decodeThreadTurnStartCommand = Schema.decodeUnknownEffect(ThreadTurnStartCommand);
|
||||
const decodeThreadTurnStartRequestedPayload = Schema.decodeUnknownEffect(
|
||||
ThreadTurnStartRequestedPayload,
|
||||
@@ -27,6 +32,7 @@ const decodeOrchestrationLatestTurn = Schema.decodeUnknownEffect(OrchestrationLa
|
||||
const decodeOrchestrationProposedPlan = Schema.decodeUnknownEffect(OrchestrationProposedPlan);
|
||||
const decodeOrchestrationSession = Schema.decodeUnknownEffect(OrchestrationSession);
|
||||
const decodeThreadCreatedPayload = Schema.decodeUnknownEffect(ThreadCreatedPayload);
|
||||
const decodeThreadMetaUpdatedPayload = Schema.decodeUnknownEffect(ThreadMetaUpdatedPayload);
|
||||
|
||||
it.effect("parses turn diff input when fromTurnCount <= toTurnCount", () =>
|
||||
Effect.gen(function* () {
|
||||
@@ -75,14 +81,85 @@ it.effect("trims branded ids and command string fields at decode boundaries", ()
|
||||
projectId: " project-1 ",
|
||||
title: " Project Title ",
|
||||
workspaceRoot: " /tmp/workspace ",
|
||||
defaultModel: " gpt-5.2 ",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: " gpt-5.2 ",
|
||||
},
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
assert.strictEqual(parsed.commandId, "cmd-1");
|
||||
assert.strictEqual(parsed.projectId, "project-1");
|
||||
assert.strictEqual(parsed.title, "Project Title");
|
||||
assert.strictEqual(parsed.workspaceRoot, "/tmp/workspace");
|
||||
assert.strictEqual(parsed.defaultModel, "gpt-5.2");
|
||||
assert.deepStrictEqual(parsed.defaultModelSelection, {
|
||||
provider: "codex",
|
||||
model: "gpt-5.2",
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("decodes historical project.created payloads with a default provider", () =>
|
||||
Effect.gen(function* () {
|
||||
const parsed = yield* decodeProjectCreatedPayload({
|
||||
projectId: "project-1",
|
||||
title: "Project Title",
|
||||
workspaceRoot: "/tmp/workspace",
|
||||
defaultModelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.4",
|
||||
},
|
||||
scripts: [],
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
updatedAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
assert.strictEqual(parsed.defaultModelSelection?.provider, "codex");
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("decodes legacy project.created payloads into defaultModelSelection", () =>
|
||||
Effect.gen(function* () {
|
||||
const parsed = yield* decodeProjectCreatedPayload({
|
||||
projectId: "project-legacy-1",
|
||||
title: "Project Title",
|
||||
workspaceRoot: "/tmp/workspace",
|
||||
defaultModel: "gpt-5.4",
|
||||
scripts: [],
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
updatedAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
assert.deepStrictEqual(parsed.defaultModelSelection, {
|
||||
provider: "codex",
|
||||
model: "gpt-5.4",
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("decodes project.meta-updated payloads with explicit default provider", () =>
|
||||
Effect.gen(function* () {
|
||||
const parsed = yield* decodeProjectMetaUpdatedPayload({
|
||||
projectId: "project-1",
|
||||
defaultModelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
},
|
||||
updatedAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
assert.strictEqual(parsed.defaultModelSelection?.provider, "claudeAgent");
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("decodes legacy project.meta-updated payloads into defaultModelSelection", () =>
|
||||
Effect.gen(function* () {
|
||||
const parsed = yield* decodeProjectMetaUpdatedPayload({
|
||||
projectId: "project-legacy-2",
|
||||
defaultProvider: "claudeAgent",
|
||||
defaultModel: "claude-opus-4-6",
|
||||
updatedAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
assert.deepStrictEqual(parsed.defaultModelSelection, {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -116,7 +193,7 @@ it.effect("decodes thread.turn.start defaults for provider and runtime mode", ()
|
||||
},
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
assert.strictEqual(parsed.provider, undefined);
|
||||
assert.strictEqual(parsed.modelSelection, undefined);
|
||||
assert.strictEqual(parsed.runtimeMode, DEFAULT_RUNTIME_MODE);
|
||||
assert.strictEqual(parsed.interactionMode, DEFAULT_PROVIDER_INTERACTION_MODE);
|
||||
}),
|
||||
@@ -134,11 +211,14 @@ it.effect("preserves explicit provider and runtime mode in thread.turn.start", (
|
||||
text: "hello",
|
||||
attachments: [],
|
||||
},
|
||||
provider: "codex",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.4",
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
assert.strictEqual(parsed.provider, "codex");
|
||||
assert.strictEqual(parsed.modelSelection?.provider, "codex");
|
||||
assert.strictEqual(parsed.runtimeMode, "full-access");
|
||||
assert.strictEqual(parsed.interactionMode, DEFAULT_PROVIDER_INTERACTION_MODE);
|
||||
}),
|
||||
@@ -150,7 +230,10 @@ it.effect("decodes thread.created runtime mode for historical events", () =>
|
||||
threadId: "thread-1",
|
||||
projectId: "project-1",
|
||||
title: "Thread title",
|
||||
model: "gpt-5.4",
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.4",
|
||||
},
|
||||
interactionMode: "default",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
@@ -159,6 +242,58 @@ it.effect("decodes thread.created runtime mode for historical events", () =>
|
||||
});
|
||||
|
||||
assert.strictEqual(parsed.runtimeMode, DEFAULT_RUNTIME_MODE);
|
||||
assert.strictEqual(parsed.modelSelection.provider, "codex");
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("decodes legacy thread.created payloads into modelSelection", () =>
|
||||
Effect.gen(function* () {
|
||||
const parsed = yield* decodeThreadCreatedPayload({
|
||||
threadId: "thread-legacy-1",
|
||||
projectId: "project-1",
|
||||
title: "Thread title",
|
||||
model: "claude-opus-4-6",
|
||||
provider: "claudeAgent",
|
||||
interactionMode: "default",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
updatedAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(parsed.modelSelection, {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
});
|
||||
assert.strictEqual(parsed.runtimeMode, DEFAULT_RUNTIME_MODE);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("decodes thread.meta-updated payloads with explicit provider", () =>
|
||||
Effect.gen(function* () {
|
||||
const parsed = yield* decodeThreadMetaUpdatedPayload({
|
||||
threadId: "thread-1",
|
||||
modelSelection: {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
},
|
||||
updatedAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
assert.strictEqual(parsed.modelSelection?.provider, "claudeAgent");
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("decodes legacy thread.meta-updated payloads into modelSelection", () =>
|
||||
Effect.gen(function* () {
|
||||
const parsed = yield* decodeThreadMetaUpdatedPayload({
|
||||
threadId: "thread-legacy-2",
|
||||
model: "gpt-5.4",
|
||||
updatedAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
assert.deepStrictEqual(parsed.modelSelection, {
|
||||
provider: "codex",
|
||||
model: "gpt-5.4",
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -174,19 +309,19 @@ it.effect("accepts provider-scoped model options in thread.turn.start", () =>
|
||||
text: "hello",
|
||||
attachments: [],
|
||||
},
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
modelOptions: {
|
||||
codex: {
|
||||
modelSelection: {
|
||||
provider: "codex",
|
||||
model: "gpt-5.3-codex",
|
||||
options: {
|
||||
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);
|
||||
assert.strictEqual(parsed.modelSelection?.provider, "codex");
|
||||
assert.strictEqual(parsed.modelSelection?.options?.reasoningEffort, "high");
|
||||
assert.strictEqual(parsed.modelSelection?.options?.fastMode, true);
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -224,7 +359,7 @@ it.effect(
|
||||
messageId: "msg-1",
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
assert.strictEqual(parsed.provider, undefined);
|
||||
assert.strictEqual(parsed.modelSelection, undefined);
|
||||
assert.strictEqual(parsed.runtimeMode, DEFAULT_RUNTIME_MODE);
|
||||
assert.strictEqual(parsed.interactionMode, DEFAULT_PROVIDER_INTERACTION_MODE);
|
||||
assert.strictEqual(parsed.sourceProposedPlan, undefined);
|
||||
@@ -249,6 +384,21 @@ it.effect("decodes thread.turn-start-requested source proposed plan metadata whe
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("decodes legacy thread.turn-start-requested payloads into modelSelection", () =>
|
||||
Effect.gen(function* () {
|
||||
const parsed = yield* decodeThreadTurnStartRequestedPayload({
|
||||
threadId: "thread-legacy-3",
|
||||
messageId: "msg-legacy-3",
|
||||
model: "gpt-5.4",
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
assert.deepStrictEqual(parsed.modelSelection, {
|
||||
provider: "codex",
|
||||
model: "gpt-5.4",
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("decodes latest turn source proposed plan metadata when present", () =>
|
||||
Effect.gen(function* () {
|
||||
const parsed = yield* decodeOrchestrationLatestTurn({
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Option, Schema, SchemaIssue, Struct } from "effect";
|
||||
import { ProviderModelOptions } from "./model";
|
||||
import { Effect, Option, Schema, SchemaIssue, SchemaTransformation, Struct } from "effect";
|
||||
import { ClaudeModelOptions, CodexModelOptions } from "./model";
|
||||
import {
|
||||
ApprovalRequestId,
|
||||
CheckpointRef,
|
||||
@@ -44,6 +44,113 @@ export const ProviderSandboxMode = Schema.Literals([
|
||||
export type ProviderSandboxMode = typeof ProviderSandboxMode.Type;
|
||||
export const DEFAULT_PROVIDER_KIND: ProviderKind = "codex";
|
||||
|
||||
export const CodexModelSelection = Schema.Struct({
|
||||
provider: Schema.Literal("codex"),
|
||||
model: TrimmedNonEmptyString,
|
||||
options: Schema.optional(CodexModelOptions),
|
||||
});
|
||||
export type CodexModelSelection = typeof CodexModelSelection.Type;
|
||||
|
||||
export const ClaudeModelSelection = Schema.Struct({
|
||||
provider: Schema.Literal("claudeAgent"),
|
||||
model: TrimmedNonEmptyString,
|
||||
options: Schema.optional(ClaudeModelOptions),
|
||||
});
|
||||
export type ClaudeModelSelection = typeof ClaudeModelSelection.Type;
|
||||
|
||||
export const ModelSelection = Schema.Union([CodexModelSelection, ClaudeModelSelection]);
|
||||
export type ModelSelection = typeof ModelSelection.Type;
|
||||
const decodeModelSelectionSync = Schema.decodeUnknownSync(ModelSelection);
|
||||
|
||||
const LegacyDefaultModelSelectionFields = {
|
||||
defaultProvider: Schema.optional(ProviderKind),
|
||||
defaultModel: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
defaultModelOptions: Schema.optional(Schema.NullOr(Schema.Unknown)),
|
||||
} as const;
|
||||
|
||||
const LegacyThreadModelSelectionFields = {
|
||||
provider: Schema.optional(ProviderKind),
|
||||
model: Schema.optional(TrimmedNonEmptyString),
|
||||
modelOptions: Schema.optional(Schema.NullOr(Schema.Unknown)),
|
||||
} as const;
|
||||
|
||||
function invalidLegacyModelSelectionIssue(
|
||||
value: unknown,
|
||||
title: string,
|
||||
cause: unknown,
|
||||
): SchemaIssue.InvalidValue {
|
||||
return new SchemaIssue.InvalidValue(Option.some(value), {
|
||||
title,
|
||||
...(Schema.isSchemaError(cause)
|
||||
? { description: SchemaIssue.makeFormatterDefault()(cause.issue) }
|
||||
: {}),
|
||||
});
|
||||
}
|
||||
|
||||
type LegacyDefaultModelSelectionInput = {
|
||||
readonly defaultModelSelection?: ModelSelection | null | undefined;
|
||||
readonly defaultProvider?: ProviderKind | undefined;
|
||||
readonly defaultModel?: string | null | undefined;
|
||||
readonly defaultModelOptions?: unknown | null | undefined;
|
||||
};
|
||||
|
||||
type LegacyThreadModelSelectionInput = {
|
||||
readonly modelSelection?: ModelSelection | undefined;
|
||||
readonly provider?: ProviderKind | undefined;
|
||||
readonly model?: string | undefined;
|
||||
readonly modelOptions?: unknown | null | undefined;
|
||||
};
|
||||
|
||||
function normalizeLegacyDefaultModelSelection(
|
||||
input: LegacyDefaultModelSelectionInput,
|
||||
): Effect.Effect<ModelSelection | null, SchemaIssue.InvalidValue> {
|
||||
if (input.defaultModelSelection !== undefined) {
|
||||
return Effect.succeed(input.defaultModelSelection);
|
||||
}
|
||||
if (input.defaultModel === undefined || input.defaultModel === null) {
|
||||
return Effect.succeed(null);
|
||||
}
|
||||
return Effect.try({
|
||||
try: () =>
|
||||
decodeModelSelectionSync({
|
||||
provider: input.defaultProvider ?? DEFAULT_PROVIDER_KIND,
|
||||
model: input.defaultModel,
|
||||
...(input.defaultModelOptions != null ? { options: input.defaultModelOptions } : {}),
|
||||
}),
|
||||
catch: (cause) =>
|
||||
invalidLegacyModelSelectionIssue(
|
||||
input,
|
||||
"Invalid legacy default model selection payload",
|
||||
cause,
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
function normalizeLegacyThreadModelSelection(
|
||||
input: LegacyThreadModelSelectionInput,
|
||||
): Effect.Effect<ModelSelection | undefined, SchemaIssue.InvalidValue> {
|
||||
if (input.modelSelection !== undefined) {
|
||||
return Effect.succeed(input.modelSelection);
|
||||
}
|
||||
if (input.model === undefined) {
|
||||
return Effect.succeed(undefined);
|
||||
}
|
||||
return Effect.try({
|
||||
try: () =>
|
||||
decodeModelSelectionSync({
|
||||
provider: input.provider ?? DEFAULT_PROVIDER_KIND,
|
||||
model: input.model,
|
||||
...(input.modelOptions != null ? { options: input.modelOptions } : {}),
|
||||
}),
|
||||
catch: (cause) =>
|
||||
invalidLegacyModelSelectionIssue(
|
||||
input,
|
||||
"Invalid legacy thread model selection payload",
|
||||
cause,
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
export const CodexProviderStartOptions = Schema.Struct({
|
||||
binaryPath: Schema.optional(TrimmedNonEmptyString),
|
||||
homePath: Schema.optional(TrimmedNonEmptyString),
|
||||
@@ -144,7 +251,7 @@ export const OrchestrationProject = Schema.Struct({
|
||||
id: ProjectId,
|
||||
title: TrimmedNonEmptyString,
|
||||
workspaceRoot: TrimmedNonEmptyString,
|
||||
defaultModel: Schema.NullOr(TrimmedNonEmptyString),
|
||||
defaultModelSelection: Schema.NullOr(ModelSelection),
|
||||
scripts: Schema.Array(ProjectScript),
|
||||
createdAt: IsoDateTime,
|
||||
updatedAt: IsoDateTime,
|
||||
@@ -273,7 +380,7 @@ export const OrchestrationThread = Schema.Struct({
|
||||
id: ThreadId,
|
||||
projectId: ProjectId,
|
||||
title: TrimmedNonEmptyString,
|
||||
model: TrimmedNonEmptyString,
|
||||
modelSelection: ModelSelection,
|
||||
runtimeMode: RuntimeMode,
|
||||
interactionMode: ProviderInteractionMode.pipe(
|
||||
Schema.withDecodingDefault(() => DEFAULT_PROVIDER_INTERACTION_MODE),
|
||||
@@ -306,7 +413,7 @@ export const ProjectCreateCommand = Schema.Struct({
|
||||
projectId: ProjectId,
|
||||
title: TrimmedNonEmptyString,
|
||||
workspaceRoot: TrimmedNonEmptyString,
|
||||
defaultModel: Schema.optional(TrimmedNonEmptyString),
|
||||
defaultModelSelection: Schema.optional(Schema.NullOr(ModelSelection)),
|
||||
createdAt: IsoDateTime,
|
||||
});
|
||||
|
||||
@@ -316,7 +423,7 @@ const ProjectMetaUpdateCommand = Schema.Struct({
|
||||
projectId: ProjectId,
|
||||
title: Schema.optional(TrimmedNonEmptyString),
|
||||
workspaceRoot: Schema.optional(TrimmedNonEmptyString),
|
||||
defaultModel: Schema.optional(TrimmedNonEmptyString),
|
||||
defaultModelSelection: Schema.optional(Schema.NullOr(ModelSelection)),
|
||||
scripts: Schema.optional(Schema.Array(ProjectScript)),
|
||||
});
|
||||
|
||||
@@ -332,7 +439,7 @@ const ThreadCreateCommand = Schema.Struct({
|
||||
threadId: ThreadId,
|
||||
projectId: ProjectId,
|
||||
title: TrimmedNonEmptyString,
|
||||
model: TrimmedNonEmptyString,
|
||||
modelSelection: ModelSelection,
|
||||
runtimeMode: RuntimeMode,
|
||||
interactionMode: ProviderInteractionMode.pipe(
|
||||
Schema.withDecodingDefault(() => DEFAULT_PROVIDER_INTERACTION_MODE),
|
||||
@@ -353,7 +460,7 @@ const ThreadMetaUpdateCommand = Schema.Struct({
|
||||
commandId: CommandId,
|
||||
threadId: ThreadId,
|
||||
title: Schema.optional(TrimmedNonEmptyString),
|
||||
model: Schema.optional(TrimmedNonEmptyString),
|
||||
modelSelection: Schema.optional(ModelSelection),
|
||||
branch: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
worktreePath: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
});
|
||||
@@ -384,9 +491,7 @@ export const ThreadTurnStartCommand = Schema.Struct({
|
||||
text: Schema.String,
|
||||
attachments: Schema.Array(ChatAttachment),
|
||||
}),
|
||||
provider: Schema.optional(ProviderKind),
|
||||
model: Schema.optional(TrimmedNonEmptyString),
|
||||
modelOptions: Schema.optional(ProviderModelOptions),
|
||||
modelSelection: Schema.optional(ModelSelection),
|
||||
providerOptions: Schema.optional(ProviderStartOptions),
|
||||
assistantDeliveryMode: Schema.optional(AssistantDeliveryMode),
|
||||
runtimeMode: RuntimeMode.pipe(Schema.withDecodingDefault(() => DEFAULT_RUNTIME_MODE)),
|
||||
@@ -407,9 +512,7 @@ const ClientThreadTurnStartCommand = Schema.Struct({
|
||||
text: Schema.String,
|
||||
attachments: Schema.Array(UploadChatAttachment),
|
||||
}),
|
||||
provider: Schema.optional(ProviderKind),
|
||||
model: Schema.optional(TrimmedNonEmptyString),
|
||||
modelOptions: Schema.optional(ProviderModelOptions),
|
||||
modelSelection: Schema.optional(ModelSelection),
|
||||
providerOptions: Schema.optional(ProviderStartOptions),
|
||||
assistantDeliveryMode: Schema.optional(AssistantDeliveryMode),
|
||||
runtimeMode: RuntimeMode,
|
||||
@@ -606,35 +709,122 @@ export const OrchestrationAggregateKind = Schema.Literals(["project", "thread"])
|
||||
export type OrchestrationAggregateKind = typeof OrchestrationAggregateKind.Type;
|
||||
export const OrchestrationActorKind = Schema.Literals(["client", "server", "provider"]);
|
||||
|
||||
export const ProjectCreatedPayload = Schema.Struct({
|
||||
const ProjectCreatedPayloadCanonical = Schema.Struct({
|
||||
projectId: ProjectId,
|
||||
title: TrimmedNonEmptyString,
|
||||
workspaceRoot: TrimmedNonEmptyString,
|
||||
defaultModel: Schema.NullOr(TrimmedNonEmptyString),
|
||||
defaultModelSelection: Schema.NullOr(ModelSelection),
|
||||
scripts: Schema.Array(ProjectScript),
|
||||
createdAt: IsoDateTime,
|
||||
updatedAt: IsoDateTime,
|
||||
});
|
||||
const ProjectCreatedPayloadSource = Schema.Struct({
|
||||
projectId: ProjectId,
|
||||
title: TrimmedNonEmptyString,
|
||||
workspaceRoot: TrimmedNonEmptyString,
|
||||
defaultModelSelection: Schema.optional(Schema.NullOr(ModelSelection)),
|
||||
...LegacyDefaultModelSelectionFields,
|
||||
scripts: Schema.Array(ProjectScript),
|
||||
createdAt: IsoDateTime,
|
||||
updatedAt: IsoDateTime,
|
||||
});
|
||||
type ProjectCreatedPayloadSource = typeof ProjectCreatedPayloadSource.Type;
|
||||
export const ProjectCreatedPayload = ProjectCreatedPayloadSource.pipe(
|
||||
Schema.decodeTo(
|
||||
Schema.toType(ProjectCreatedPayloadCanonical),
|
||||
SchemaTransformation.transformOrFail({
|
||||
decode: (input) =>
|
||||
normalizeLegacyDefaultModelSelection(input).pipe(
|
||||
Effect.map((defaultModelSelection) => ({
|
||||
projectId: input.projectId,
|
||||
title: input.title,
|
||||
workspaceRoot: input.workspaceRoot,
|
||||
defaultModelSelection,
|
||||
scripts: input.scripts,
|
||||
createdAt: input.createdAt,
|
||||
updatedAt: input.updatedAt,
|
||||
})),
|
||||
),
|
||||
encode: (canonical) =>
|
||||
Effect.succeed({
|
||||
projectId: canonical.projectId,
|
||||
title: canonical.title,
|
||||
workspaceRoot: canonical.workspaceRoot,
|
||||
defaultModelSelection: canonical.defaultModelSelection,
|
||||
scripts: canonical.scripts,
|
||||
createdAt: canonical.createdAt,
|
||||
updatedAt: canonical.updatedAt,
|
||||
} as ProjectCreatedPayloadSource),
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
export const ProjectMetaUpdatedPayload = Schema.Struct({
|
||||
const ProjectMetaUpdatedPayloadCanonical = Schema.Struct({
|
||||
projectId: ProjectId,
|
||||
title: Schema.optional(TrimmedNonEmptyString),
|
||||
workspaceRoot: Schema.optional(TrimmedNonEmptyString),
|
||||
defaultModel: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
defaultModelSelection: Schema.optional(Schema.NullOr(ModelSelection)),
|
||||
scripts: Schema.optional(Schema.Array(ProjectScript)),
|
||||
updatedAt: IsoDateTime,
|
||||
});
|
||||
type ProjectMetaUpdatedPayloadCanonical = typeof ProjectMetaUpdatedPayloadCanonical.Type;
|
||||
const ProjectMetaUpdatedPayloadSource = Schema.Struct({
|
||||
projectId: ProjectId,
|
||||
title: Schema.optional(TrimmedNonEmptyString),
|
||||
workspaceRoot: Schema.optional(TrimmedNonEmptyString),
|
||||
defaultModelSelection: Schema.optional(Schema.NullOr(ModelSelection)),
|
||||
...LegacyDefaultModelSelectionFields,
|
||||
scripts: Schema.optional(Schema.Array(ProjectScript)),
|
||||
updatedAt: IsoDateTime,
|
||||
});
|
||||
type ProjectMetaUpdatedPayloadSource = typeof ProjectMetaUpdatedPayloadSource.Type;
|
||||
export const ProjectMetaUpdatedPayload = ProjectMetaUpdatedPayloadSource.pipe(
|
||||
Schema.decodeTo(
|
||||
Schema.toType(ProjectMetaUpdatedPayloadCanonical),
|
||||
SchemaTransformation.transformOrFail({
|
||||
decode: (input: ProjectMetaUpdatedPayloadSource) =>
|
||||
normalizeLegacyDefaultModelSelection(input).pipe(
|
||||
Effect.map((defaultModelSelection) => ({
|
||||
projectId: input.projectId,
|
||||
...(input.title !== undefined ? { title: input.title } : {}),
|
||||
...(input.workspaceRoot !== undefined ? { workspaceRoot: input.workspaceRoot } : {}),
|
||||
...(input.defaultModelSelection !== undefined ||
|
||||
input.defaultModel !== undefined ||
|
||||
input.defaultProvider !== undefined ||
|
||||
input.defaultModelOptions !== undefined
|
||||
? { defaultModelSelection }
|
||||
: {}),
|
||||
...(input.scripts !== undefined ? { scripts: input.scripts } : {}),
|
||||
updatedAt: input.updatedAt,
|
||||
})),
|
||||
),
|
||||
encode: (canonical: ProjectMetaUpdatedPayloadCanonical) =>
|
||||
Effect.succeed({
|
||||
projectId: canonical.projectId,
|
||||
...(canonical.title !== undefined ? { title: canonical.title } : {}),
|
||||
...(canonical.workspaceRoot !== undefined
|
||||
? { workspaceRoot: canonical.workspaceRoot }
|
||||
: {}),
|
||||
...(canonical.defaultModelSelection !== undefined
|
||||
? { defaultModelSelection: canonical.defaultModelSelection }
|
||||
: {}),
|
||||
...(canonical.scripts !== undefined ? { scripts: canonical.scripts } : {}),
|
||||
updatedAt: canonical.updatedAt,
|
||||
} as ProjectMetaUpdatedPayloadSource),
|
||||
} as any),
|
||||
),
|
||||
);
|
||||
|
||||
export const ProjectDeletedPayload = Schema.Struct({
|
||||
projectId: ProjectId,
|
||||
deletedAt: IsoDateTime,
|
||||
});
|
||||
|
||||
export const ThreadCreatedPayload = Schema.Struct({
|
||||
const ThreadCreatedPayloadCanonical = Schema.Struct({
|
||||
threadId: ThreadId,
|
||||
projectId: ProjectId,
|
||||
title: TrimmedNonEmptyString,
|
||||
model: TrimmedNonEmptyString,
|
||||
modelSelection: ModelSelection,
|
||||
runtimeMode: RuntimeMode.pipe(Schema.withDecodingDefault(() => DEFAULT_RUNTIME_MODE)),
|
||||
interactionMode: ProviderInteractionMode.pipe(
|
||||
Schema.withDecodingDefault(() => DEFAULT_PROVIDER_INTERACTION_MODE),
|
||||
@@ -644,20 +834,119 @@ export const ThreadCreatedPayload = Schema.Struct({
|
||||
createdAt: IsoDateTime,
|
||||
updatedAt: IsoDateTime,
|
||||
});
|
||||
const ThreadCreatedPayloadSource = Schema.Struct({
|
||||
threadId: ThreadId,
|
||||
projectId: ProjectId,
|
||||
title: TrimmedNonEmptyString,
|
||||
modelSelection: Schema.optional(ModelSelection),
|
||||
...LegacyThreadModelSelectionFields,
|
||||
runtimeMode: RuntimeMode.pipe(Schema.withDecodingDefault(() => DEFAULT_RUNTIME_MODE)),
|
||||
interactionMode: ProviderInteractionMode.pipe(
|
||||
Schema.withDecodingDefault(() => DEFAULT_PROVIDER_INTERACTION_MODE),
|
||||
),
|
||||
branch: Schema.NullOr(TrimmedNonEmptyString),
|
||||
worktreePath: Schema.NullOr(TrimmedNonEmptyString),
|
||||
createdAt: IsoDateTime,
|
||||
updatedAt: IsoDateTime,
|
||||
});
|
||||
type ThreadCreatedPayloadSource = typeof ThreadCreatedPayloadSource.Type;
|
||||
export const ThreadCreatedPayload = ThreadCreatedPayloadSource.pipe(
|
||||
Schema.decodeTo(
|
||||
Schema.toType(ThreadCreatedPayloadCanonical),
|
||||
SchemaTransformation.transformOrFail({
|
||||
decode: (input) =>
|
||||
normalizeLegacyThreadModelSelection(input).pipe(
|
||||
Effect.flatMap((modelSelection) =>
|
||||
modelSelection === undefined
|
||||
? Effect.fail(
|
||||
new SchemaIssue.InvalidValue(Option.some(input), {
|
||||
title: "Legacy thread.created payload is missing a model selection",
|
||||
}),
|
||||
)
|
||||
: Effect.succeed({
|
||||
threadId: input.threadId,
|
||||
projectId: input.projectId,
|
||||
title: input.title,
|
||||
modelSelection,
|
||||
runtimeMode: input.runtimeMode,
|
||||
interactionMode: input.interactionMode,
|
||||
branch: input.branch,
|
||||
worktreePath: input.worktreePath,
|
||||
createdAt: input.createdAt,
|
||||
updatedAt: input.updatedAt,
|
||||
}),
|
||||
),
|
||||
),
|
||||
encode: (canonical) =>
|
||||
Effect.succeed({
|
||||
threadId: canonical.threadId,
|
||||
projectId: canonical.projectId,
|
||||
title: canonical.title,
|
||||
modelSelection: canonical.modelSelection,
|
||||
runtimeMode: canonical.runtimeMode,
|
||||
interactionMode: canonical.interactionMode,
|
||||
branch: canonical.branch,
|
||||
worktreePath: canonical.worktreePath,
|
||||
createdAt: canonical.createdAt,
|
||||
updatedAt: canonical.updatedAt,
|
||||
} as ThreadCreatedPayloadSource),
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
export const ThreadDeletedPayload = Schema.Struct({
|
||||
threadId: ThreadId,
|
||||
deletedAt: IsoDateTime,
|
||||
});
|
||||
|
||||
export const ThreadMetaUpdatedPayload = Schema.Struct({
|
||||
const ThreadMetaUpdatedPayloadCanonical = Schema.Struct({
|
||||
threadId: ThreadId,
|
||||
title: Schema.optional(TrimmedNonEmptyString),
|
||||
model: Schema.optional(TrimmedNonEmptyString),
|
||||
modelSelection: Schema.optional(ModelSelection),
|
||||
branch: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
worktreePath: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
updatedAt: IsoDateTime,
|
||||
});
|
||||
type ThreadMetaUpdatedPayloadCanonical = typeof ThreadMetaUpdatedPayloadCanonical.Type;
|
||||
const ThreadMetaUpdatedPayloadSource = Schema.Struct({
|
||||
threadId: ThreadId,
|
||||
title: Schema.optional(TrimmedNonEmptyString),
|
||||
modelSelection: Schema.optional(ModelSelection),
|
||||
...LegacyThreadModelSelectionFields,
|
||||
branch: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
worktreePath: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
updatedAt: IsoDateTime,
|
||||
});
|
||||
type ThreadMetaUpdatedPayloadSource = typeof ThreadMetaUpdatedPayloadSource.Type;
|
||||
export const ThreadMetaUpdatedPayload = ThreadMetaUpdatedPayloadSource.pipe(
|
||||
Schema.decodeTo(
|
||||
Schema.toType(ThreadMetaUpdatedPayloadCanonical),
|
||||
SchemaTransformation.transformOrFail({
|
||||
decode: (input: ThreadMetaUpdatedPayloadSource) =>
|
||||
normalizeLegacyThreadModelSelection(input).pipe(
|
||||
Effect.map((modelSelection) => ({
|
||||
threadId: input.threadId,
|
||||
...(input.title !== undefined ? { title: input.title } : {}),
|
||||
...(modelSelection !== undefined ? { modelSelection } : {}),
|
||||
...(input.branch !== undefined ? { branch: input.branch } : {}),
|
||||
...(input.worktreePath !== undefined ? { worktreePath: input.worktreePath } : {}),
|
||||
updatedAt: input.updatedAt,
|
||||
})),
|
||||
),
|
||||
encode: (canonical: ThreadMetaUpdatedPayloadCanonical) =>
|
||||
Effect.succeed({
|
||||
threadId: canonical.threadId,
|
||||
...(canonical.title !== undefined ? { title: canonical.title } : {}),
|
||||
...(canonical.modelSelection !== undefined
|
||||
? { modelSelection: canonical.modelSelection }
|
||||
: {}),
|
||||
...(canonical.branch !== undefined ? { branch: canonical.branch } : {}),
|
||||
...(canonical.worktreePath !== undefined ? { worktreePath: canonical.worktreePath } : {}),
|
||||
updatedAt: canonical.updatedAt,
|
||||
} as ThreadMetaUpdatedPayloadSource),
|
||||
} as any),
|
||||
),
|
||||
);
|
||||
|
||||
export const ThreadRuntimeModeSetPayload = Schema.Struct({
|
||||
threadId: ThreadId,
|
||||
@@ -685,12 +974,10 @@ export const ThreadMessageSentPayload = Schema.Struct({
|
||||
updatedAt: IsoDateTime,
|
||||
});
|
||||
|
||||
export const ThreadTurnStartRequestedPayload = Schema.Struct({
|
||||
const ThreadTurnStartRequestedPayloadCanonical = Schema.Struct({
|
||||
threadId: ThreadId,
|
||||
messageId: MessageId,
|
||||
provider: Schema.optional(ProviderKind),
|
||||
model: Schema.optional(TrimmedNonEmptyString),
|
||||
modelOptions: Schema.optional(ProviderModelOptions),
|
||||
modelSelection: Schema.optional(ModelSelection),
|
||||
providerOptions: Schema.optional(ProviderStartOptions),
|
||||
assistantDeliveryMode: Schema.optional(AssistantDeliveryMode),
|
||||
runtimeMode: RuntimeMode.pipe(Schema.withDecodingDefault(() => DEFAULT_RUNTIME_MODE)),
|
||||
@@ -700,6 +987,70 @@ export const ThreadTurnStartRequestedPayload = Schema.Struct({
|
||||
sourceProposedPlan: Schema.optional(SourceProposedPlanReference),
|
||||
createdAt: IsoDateTime,
|
||||
});
|
||||
type ThreadTurnStartRequestedPayloadCanonical =
|
||||
typeof ThreadTurnStartRequestedPayloadCanonical.Type;
|
||||
const ThreadTurnStartRequestedPayloadSource = Schema.Struct({
|
||||
threadId: ThreadId,
|
||||
messageId: MessageId,
|
||||
modelSelection: Schema.optional(ModelSelection),
|
||||
...LegacyThreadModelSelectionFields,
|
||||
providerOptions: Schema.optional(ProviderStartOptions),
|
||||
assistantDeliveryMode: Schema.optional(AssistantDeliveryMode),
|
||||
runtimeMode: RuntimeMode.pipe(Schema.withDecodingDefault(() => DEFAULT_RUNTIME_MODE)),
|
||||
interactionMode: ProviderInteractionMode.pipe(
|
||||
Schema.withDecodingDefault(() => DEFAULT_PROVIDER_INTERACTION_MODE),
|
||||
),
|
||||
sourceProposedPlan: Schema.optional(SourceProposedPlanReference),
|
||||
createdAt: IsoDateTime,
|
||||
});
|
||||
type ThreadTurnStartRequestedPayloadSource = typeof ThreadTurnStartRequestedPayloadSource.Type;
|
||||
export const ThreadTurnStartRequestedPayload = ThreadTurnStartRequestedPayloadSource.pipe(
|
||||
Schema.decodeTo(
|
||||
Schema.toType(ThreadTurnStartRequestedPayloadCanonical),
|
||||
SchemaTransformation.transformOrFail({
|
||||
decode: (input: ThreadTurnStartRequestedPayloadSource) =>
|
||||
normalizeLegacyThreadModelSelection(input).pipe(
|
||||
Effect.map((modelSelection) => ({
|
||||
threadId: input.threadId,
|
||||
messageId: input.messageId,
|
||||
...(modelSelection !== undefined ? { modelSelection } : {}),
|
||||
...(input.providerOptions !== undefined
|
||||
? { providerOptions: input.providerOptions }
|
||||
: {}),
|
||||
...(input.assistantDeliveryMode !== undefined
|
||||
? { assistantDeliveryMode: input.assistantDeliveryMode }
|
||||
: {}),
|
||||
runtimeMode: input.runtimeMode,
|
||||
interactionMode: input.interactionMode,
|
||||
...(input.sourceProposedPlan !== undefined
|
||||
? { sourceProposedPlan: input.sourceProposedPlan }
|
||||
: {}),
|
||||
createdAt: input.createdAt,
|
||||
})),
|
||||
),
|
||||
encode: (canonical: ThreadTurnStartRequestedPayloadCanonical) =>
|
||||
Effect.succeed({
|
||||
threadId: canonical.threadId,
|
||||
messageId: canonical.messageId,
|
||||
...(canonical.modelSelection !== undefined
|
||||
? { modelSelection: canonical.modelSelection }
|
||||
: {}),
|
||||
...(canonical.providerOptions !== undefined
|
||||
? { providerOptions: canonical.providerOptions }
|
||||
: {}),
|
||||
...(canonical.assistantDeliveryMode !== undefined
|
||||
? { assistantDeliveryMode: canonical.assistantDeliveryMode }
|
||||
: {}),
|
||||
runtimeMode: canonical.runtimeMode,
|
||||
interactionMode: canonical.interactionMode,
|
||||
...(canonical.sourceProposedPlan !== undefined
|
||||
? { sourceProposedPlan: canonical.sourceProposedPlan }
|
||||
: {}),
|
||||
createdAt: canonical.createdAt,
|
||||
} as ThreadTurnStartRequestedPayloadSource),
|
||||
} as any),
|
||||
),
|
||||
);
|
||||
|
||||
export const ThreadTurnInterruptRequestedPayload = Schema.Struct({
|
||||
threadId: ThreadId,
|
||||
|
||||
@@ -15,7 +15,6 @@ import {
|
||||
getDefaultReasoningEffort,
|
||||
getModelOptions,
|
||||
getReasoningEffortOptions,
|
||||
inferProviderForModel,
|
||||
isClaudeUltrathinkPrompt,
|
||||
normalizeClaudeModelOptions,
|
||||
normalizeCodexModelOptions,
|
||||
@@ -28,6 +27,7 @@ import {
|
||||
supportsClaudeFastMode,
|
||||
supportsClaudeMaxEffort,
|
||||
supportsClaudeThinkingToggle,
|
||||
toProviderModelOptions,
|
||||
supportsClaudeUltrathinkKeyword,
|
||||
} from "./model";
|
||||
|
||||
@@ -188,23 +188,6 @@ describe("getReasoningEffortOptions", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("inferProviderForModel", () => {
|
||||
it("detects known provider model slugs", () => {
|
||||
expect(inferProviderForModel("gpt-5.3-codex")).toBe("codex");
|
||||
expect(inferProviderForModel("claude-sonnet-4-6")).toBe("claudeAgent");
|
||||
expect(inferProviderForModel("sonnet")).toBe("claudeAgent");
|
||||
});
|
||||
|
||||
it("falls back when the model is unknown", () => {
|
||||
expect(inferProviderForModel("custom/internal-model")).toBe("codex");
|
||||
expect(inferProviderForModel("custom/internal-model", "claudeAgent")).toBe("claudeAgent");
|
||||
});
|
||||
|
||||
it("treats claude-prefixed custom slugs as claude", () => {
|
||||
expect(inferProviderForModel("claude-custom-internal")).toBe("claudeAgent");
|
||||
});
|
||||
});
|
||||
|
||||
describe("getDefaultReasoningEffort", () => {
|
||||
it("returns provider-scoped defaults", () => {
|
||||
expect(getDefaultReasoningEffort("codex")).toBe(DEFAULT_REASONING_EFFORT_BY_PROVIDER.codex);
|
||||
@@ -290,6 +273,45 @@ describe("normalizeClaudeModelOptions", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("toProviderModelOptions", () => {
|
||||
it("returns undefined when no model options exist", () => {
|
||||
expect(toProviderModelOptions({ provider: "codex", model: "gpt-5.4" })).toBeUndefined();
|
||||
expect(toProviderModelOptions(null)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("scopes codex options under the codex provider key", () => {
|
||||
expect(
|
||||
toProviderModelOptions({
|
||||
provider: "codex",
|
||||
model: "gpt-5.4",
|
||||
options: {
|
||||
fastMode: true,
|
||||
},
|
||||
}),
|
||||
).toEqual({
|
||||
codex: {
|
||||
fastMode: true,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("scopes claude options under the claudeAgent provider key", () => {
|
||||
expect(
|
||||
toProviderModelOptions({
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
options: {
|
||||
effort: "max",
|
||||
},
|
||||
}),
|
||||
).toEqual({
|
||||
claudeAgent: {
|
||||
effort: "max",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("supportsClaudeAdaptiveReasoning", () => {
|
||||
it("only enables adaptive reasoning for Opus 4.6 and Sonnet 4.6", () => {
|
||||
expect(supportsClaudeAdaptiveReasoning("claude-opus-4-6")).toBe(true);
|
||||
|
||||
@@ -10,7 +10,9 @@ import {
|
||||
type ClaudeCodeEffort,
|
||||
type CodexModelOptions,
|
||||
type CodexReasoningEffort,
|
||||
type ModelSelection,
|
||||
type ModelSlug,
|
||||
type ProviderModelOptions,
|
||||
type ProviderReasoningEffort,
|
||||
type ProviderKind,
|
||||
} from "@t3tools/contracts";
|
||||
@@ -136,23 +138,6 @@ export function resolveModelSlugForProvider(
|
||||
return resolveModelSlug(model, provider);
|
||||
}
|
||||
|
||||
export function inferProviderForModel(
|
||||
model: string | null | undefined,
|
||||
fallback: ProviderKind = "codex",
|
||||
): ProviderKind {
|
||||
const normalizedClaude = normalizeModelSlug(model, "claudeAgent");
|
||||
if (normalizedClaude && MODEL_SLUG_SET_BY_PROVIDER.claudeAgent.has(normalizedClaude)) {
|
||||
return "claudeAgent";
|
||||
}
|
||||
|
||||
const normalizedCodex = normalizeModelSlug(model, "codex");
|
||||
if (normalizedCodex && MODEL_SLUG_SET_BY_PROVIDER.codex.has(normalizedCodex)) {
|
||||
return "codex";
|
||||
}
|
||||
|
||||
return typeof model === "string" && model.trim().startsWith("claude-") ? "claudeAgent" : fallback;
|
||||
}
|
||||
|
||||
export function getReasoningEffortOptions(provider: "codex"): ReadonlyArray<CodexReasoningEffort>;
|
||||
export function getReasoningEffortOptions(
|
||||
provider: "claudeAgent",
|
||||
@@ -283,4 +268,15 @@ export function applyClaudePromptEffortPrefix(
|
||||
return `Ultrathink:\n${trimmed}`;
|
||||
}
|
||||
|
||||
export function toProviderModelOptions(
|
||||
modelSelection: ModelSelection | null | undefined,
|
||||
): ProviderModelOptions | undefined {
|
||||
if (!modelSelection?.options) {
|
||||
return undefined;
|
||||
}
|
||||
return modelSelection.provider === "codex"
|
||||
? { codex: modelSelection.options }
|
||||
: { claudeAgent: modelSelection.options };
|
||||
}
|
||||
|
||||
export { CLAUDE_CODE_EFFORT_OPTIONS, CODEX_REASONING_EFFORT_OPTIONS };
|
||||
Reference in new issue
Block a user