Skip to content

The agent that grows with you

refactor(desktop): desktopSessionCreateParams moves to session-create-request

alt-glitch9ee344cbb234
diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/index.ts b/apps/desktop/src/app/session/hooks/use-session-actions/index.ts
index 712eb332baf..32f42ef42fc 100644
--- a/apps/desktop/src/app/session/hooks/use-session-actions/index.ts
+++ b/apps/desktop/src/app/session/hooks/use-session-actions/index.ts
@@ -74,17 +74,10 @@ import {
$activeSessionStoredIdRotation,
$connection,
$currentCwd,
- $currentCwdExplicit,
- $currentFastMode,
- $currentModel,
- $currentProvider,
- $currentReasoningEffort,
- $currentServiceTier,
$messages,
$newChatWorkspaceTarget,
$sessions,
$yoloActive,
- getCurrentModelSource,
idsShareLineage,
type NewChatWorkspaceTarget,
resolveComposerSessionKey,
@@ -178,7 +171,7 @@ import { rememberedOwnerForResume } from './remembered-owner'
import { restorePendingApproval } from './restore-pending-approval'
import { pendingClarifyToolPayload, restorePendingClarifyFromSnapshot } from './restore-pending-clarify'
import { projectPendingConnection, restorePendingConnectionFromSnapshot } from './restore-pending-connection'
-import { createGatewaySession } from './session-create-request'
+import { createGatewaySession, desktopSessionCreateParams } from './session-create-request'
import {
createPersistedDisplayTranscriptProvenance,
hasPersistedDisplayTranscriptProvenance,
@@ -299,80 +292,6 @@ function reconcileAuthoritativeMessages(
)
}
-// `session.create` params from the current profile + sticky-UI model/effort/fast,
-// ensuring the gateway is on that profile first. Shared by the primary send path
-// and the "open in split" tile path; `cwd` is the one thing that differs (the
-// live composer cwd for a send, the resolved new-session cwd for a fresh tile).
-//
-// Resolving null profile to the active gateway's is load-bearing: in global-remote
-// mode one backend serves every profile, so an omitted profile silently lands the
-// chat on the launch (default) profile — the "rubberbands back to default" bug.
-// A no-op for single-profile/local-pooled users (a backend resolves its own launch
-// profile to None). Effort/fast still ride as per-session overrides. Model and
-// provider only ride when the composer source is 'manual' — a default-sourced
-// value is a mirror of Settings → Model and must not pin the new chat.
-async function desktopSessionCreateParams(
- cwd: string,
- capturedRoute = resolveNewChatOwnerRoute(),
- requestedProfile?: string,
- legacyProfileIntent = false,
- includeComposerSelection = true
-): Promise<Record<string, unknown>> {
- // Treat Send as the linearization point for the visible selector state. The
- // profile handshake below can yield long enough for background config/model
- // refreshes to finish; reading atoms afterward would silently create the
- // session with a different selection than the one the user submitted.
- // Settings → Model while a session is live leaves $currentModel painted with
- // the live agent (applySavedMainModel) and only flips the source to 'default'.
- // Shipping that stale value as an override pins every new chat to the old
- // model. Omit model/provider unless the source is 'manual'.
- const isManualSelection = getCurrentModelSource() === 'manual'
-
- const selection = {
- effort: $currentReasoningEffort.get().trim(),
- fast: $currentFastMode.get(),
- serviceTier: $currentServiceTier.get().trim(),
- model: isManualSelection ? $currentModel.get().trim() : '',
- provider: isManualSelection ? $currentProvider.get().trim() : ''
- }
-
- const profile =
- capturedRoute?.profile ||
- requestedProfile ||
- $newChatProfile.get() ||
- normalizeProfileKey($activeGatewayProfile.get())
-
- if (capturedRoute) {
- await ensureGatewayAgent(capturedRoute.connectionId, profile)
- } else if (legacyProfileIntent) {
- await ensureGatewayProfile(profile, { forceLegacyRoute: true })
- } else {
- await ensureGatewayProfile(profile)
- }
-
- return {
- cols: 96,
- source: 'desktop',
- ...(cwd && { cwd }),
- // #52589: explicit provenance for the shipped cwd — an inherited app-global
- // workspace must not override the target profile's configured terminal.cwd.
- ...(cwd && { cwd_explicit: $currentCwdExplicit.get() }),
- ...(profile ? { profile: capturedRoute?.targetProfile || profile } : {}),
- ...(includeComposerSelection
- ? {
- ...(selection.model
- ? { model: selection.model, ...(selection.provider ? { provider: selection.provider } : {}) }
- : {}),
- ...(selection.effort ? { reasoning_effort: selection.effort } : {}),
- fast: selection.fast,
- // Only Ultrafast needs the tier: `fast` already pins Priority/normal, and a
- // pre-Ultrafast backend rejects the field (createGatewaySession drops it).
- ...(selection.serviceTier === 'ultrafast' ? { service_tier: 'ultrafast' } : {})
- }
- : {})
- }
-}
-
interface FreshSessionDraftOptions {
preserveRoute?: boolean
replaceRoute?: boolean
diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/session-create-request.ts b/apps/desktop/src/app/session/hooks/use-session-actions/session-create-request.ts
index fcc281d077a..2b95e3fcbf7 100644
--- a/apps/desktop/src/app/session/hooks/use-session-actions/session-create-request.ts
+++ b/apps/desktop/src/app/session/hooks/use-session-actions/session-create-request.ts
@@ -1,5 +1,22 @@
import { requestGatewayForAgent } from '@/store/gateway'
-import type { AgentProfileRoute } from '@/store/profile'
+import {
+ $activeGatewayProfile,
+ $newChatProfile,
+ type AgentProfileRoute,
+ ensureGatewayAgent,
+ ensureGatewayProfile,
+ normalizeProfileKey,
+ resolveNewChatOwnerRoute
+} from '@/store/profile'
+import {
+ $currentCwdExplicit,
+ $currentFastMode,
+ $currentModel,
+ $currentProvider,
+ $currentReasoningEffort,
+ $currentServiceTier,
+ getCurrentModelSource
+} from '@/store/session'
import type { SessionCreateResponse } from '@/types/hermes'
type RequestGateway = <T>(method: string, params?: Record<string, unknown>) => Promise<T>
@@ -61,3 +78,77 @@ export async function createGatewaySession(
return create(params)
}
+
+// `session.create` params from the current profile + sticky-UI model/effort/fast,
+// ensuring the gateway is on that profile first. Shared by the primary send path
+// and the "open in split" tile path; `cwd` is the one thing that differs (the
+// live composer cwd for a send, the resolved new-session cwd for a fresh tile).
+//
+// Resolving null profile to the active gateway's is load-bearing: in global-remote
+// mode one backend serves every profile, so an omitted profile silently lands the
+// chat on the launch (default) profile — the "rubberbands back to default" bug.
+// A no-op for single-profile/local-pooled users (a backend resolves its own launch
+// profile to None). Effort/fast still ride as per-session overrides. Model and
+// provider only ride when the composer source is 'manual' — a default-sourced
+// value is a mirror of Settings → Model and must not pin the new chat.
+export async function desktopSessionCreateParams(
+ cwd: string,
+ capturedRoute = resolveNewChatOwnerRoute(),
+ requestedProfile?: string,
+ legacyProfileIntent = false,
+ includeComposerSelection = true
+): Promise<Record<string, unknown>> {
+ // Treat Send as the linearization point for the visible selector state. The
+ // profile handshake below can yield long enough for background config/model
+ // refreshes to finish; reading atoms afterward would silently create the
+ // session with a different selection than the one the user submitted.
+ // Settings → Model while a session is live leaves $currentModel painted with
+ // the live agent (applySavedMainModel) and only flips the source to 'default'.
+ // Shipping that stale value as an override pins every new chat to the old
+ // model. Omit model/provider unless the source is 'manual'.
+ const isManualSelection = getCurrentModelSource() === 'manual'
+
+ const selection = {
+ effort: $currentReasoningEffort.get().trim(),
+ fast: $currentFastMode.get(),
+ serviceTier: $currentServiceTier.get().trim(),
+ model: isManualSelection ? $currentModel.get().trim() : '',
+ provider: isManualSelection ? $currentProvider.get().trim() : ''
+ }
+
+ const profile =
+ capturedRoute?.profile ||
+ requestedProfile ||
+ $newChatProfile.get() ||
+ normalizeProfileKey($activeGatewayProfile.get())
+
+ if (capturedRoute) {
+ await ensureGatewayAgent(capturedRoute.connectionId, profile)
+ } else if (legacyProfileIntent) {
+ await ensureGatewayProfile(profile, { forceLegacyRoute: true })
+ } else {
+ await ensureGatewayProfile(profile)
+ }
+
+ return {
+ cols: 96,
+ source: 'desktop',
+ ...(cwd && { cwd }),
+ // #52589: explicit provenance for the shipped cwd — an inherited app-global
+ // workspace must not override the target profile's configured terminal.cwd.
+ ...(cwd && { cwd_explicit: $currentCwdExplicit.get() }),
+ ...(profile ? { profile: capturedRoute?.targetProfile || profile } : {}),
+ ...(includeComposerSelection
+ ? {
+ ...(selection.model
+ ? { model: selection.model, ...(selection.provider ? { provider: selection.provider } : {}) }
+ : {}),
+ ...(selection.effort ? { reasoning_effort: selection.effort } : {}),
+ fast: selection.fast,
+ // Only Ultrafast needs the tier: `fast` already pins Priority/normal, and a
+ // pre-Ultrafast backend rejects the field (createGatewaySession drops it).
+ ...(selection.serviceTier === 'ultrafast' ? { service_tier: 'ultrafast' } : {})
+ }
+ : {})
+ }
+}