Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions apps/web/src/hooks/useHandleNewThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ export function useHandleNewThread() {
const hasBranchOption = options?.branch !== undefined;
const hasWorktreePathOption = options?.worktreePath !== undefined;
const hasEnvModeOption = options?.envMode !== undefined;
const applyStickyModel = (threadId: ThreadId, draftModel?: string | null) => {
if (stickyModel && !draftModel) {
setProvider(threadId, inferProviderForModel(stickyModel));
setModel(threadId, stickyModel);
}
if (!draftModel && Object.keys(stickyModelOptions).length > 0) {
setModelOptions(threadId, stickyModelOptions);
}
};

const storedDraftThread = getDraftThreadByProjectId(projectId);
const latestActiveDraftThread: DraftThreadState | null = routeThreadId
? getDraftThread(routeThreadId)
Expand All @@ -64,6 +74,9 @@ export function useHandleNewThread() {
});
}
setProjectDraftThreadId(projectId, storedDraftThread.threadId);
const existingDraft =
useComposerDraftStore.getState().draftsByThreadId[storedDraftThread.threadId];
applyStickyModel(storedDraftThread.threadId, existingDraft?.model);
if (routeThreadId === storedDraftThread.threadId) {
return;
}
Expand All @@ -89,6 +102,8 @@ export function useHandleNewThread() {
});
}
setProjectDraftThreadId(projectId, routeThreadId);
const existingDraft = useComposerDraftStore.getState().draftsByThreadId[routeThreadId];
applyStickyModel(routeThreadId, existingDraft?.model);
return Promise.resolve();
}

Expand All @@ -102,13 +117,7 @@ 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);
}
applyStickyModel(threadId);

await navigate({
to: "/$threadId",
Expand Down