diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/workspace/$workspaceId/types.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/workspace/$workspaceId/types.ts index 148bd7e8577..0746e1ff7be 100644 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/workspace/$workspaceId/types.ts +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/workspace/$workspaceId/types.ts @@ -103,6 +103,7 @@ export interface PendingCloudLaunchPaneData { launchPrompt?: string; queuedPrompts?: UserContent[][]; chatModelId?: string; + chatEffortId?: string; chatModeId?: string; } diff --git a/apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/components/DashboardNewWorkspaceForm/PromptGroup/hooks/useSubmitWorkspace/useSubmitWorkspace.ts b/apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/components/DashboardNewWorkspaceForm/PromptGroup/hooks/useSubmitWorkspace/useSubmitWorkspace.ts index 4ba2ee2a241..57648894cb1 100644 --- a/apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/components/DashboardNewWorkspaceForm/PromptGroup/hooks/useSubmitWorkspace/useSubmitWorkspace.ts +++ b/apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/components/DashboardNewWorkspaceForm/PromptGroup/hooks/useSubmitWorkspace/useSubmitWorkspace.ts @@ -20,6 +20,7 @@ import { useDashboardNewWorkspaceDraft } from "../../../../../DashboardNewWorksp import type { WorkspaceCreateAgent } from "../../types"; import type { UseUploadAttachmentsApi } from "../useUploadAttachments"; import { resolveNames } from "./resolveNames"; +import { launchEffort } from "./utils/launchEffort"; interface Overrides { cloudEnvironmentId?: string; @@ -46,6 +47,7 @@ export function useSubmitWorkspace( cloudEnvironmentId: string | null = null, hostId: string | null = null, isSession = false, + hostLaunchesChatWithEffort = false, ) { const { t } = useLingui(); const navigate = useNavigate(); @@ -221,6 +223,7 @@ export function useSubmitWorkspace( { prompt: userPrompt.trim(), modelId: isSelectedAgent ? selectedModel : null, + effortId: isSelectedAgent ? selectedEffort : null, modeId: isSelectedAgent ? selectedMode : null, }, ); @@ -293,7 +296,10 @@ export function useSubmitWorkspace( attachmentIds: attachmentIds.length > 0 ? attachmentIds : undefined, model: selectedModel ?? undefined, - effort: openAsChat ? undefined : (selectedEffort ?? undefined), + effort: launchEffort(selectedEffort, { + openAsChat, + hostLaunchesChatWithEffort, + }), mode: selectedMode ?? undefined, ...(openAsChat ? { surface: "chat" as const } : {}), }, @@ -423,6 +429,7 @@ export function useSubmitWorkspace( t, uploadAttachments, cloudEnvironmentId, + hostLaunchesChatWithEffort, ], ); diff --git a/apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/components/DashboardNewWorkspaceForm/PromptGroup/hooks/useSubmitWorkspace/utils/launchEffort/index.ts b/apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/components/DashboardNewWorkspaceForm/PromptGroup/hooks/useSubmitWorkspace/utils/launchEffort/index.ts new file mode 100644 index 00000000000..1058c7ef884 --- /dev/null +++ b/apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/components/DashboardNewWorkspaceForm/PromptGroup/hooks/useSubmitWorkspace/utils/launchEffort/index.ts @@ -0,0 +1 @@ +export { launchEffort } from "./launchEffort"; diff --git a/apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/components/DashboardNewWorkspaceForm/PromptGroup/hooks/useSubmitWorkspace/utils/launchEffort/launchEffort.test.ts b/apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/components/DashboardNewWorkspaceForm/PromptGroup/hooks/useSubmitWorkspace/utils/launchEffort/launchEffort.test.ts new file mode 100644 index 00000000000..ccac13062ef --- /dev/null +++ b/apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/components/DashboardNewWorkspaceForm/PromptGroup/hooks/useSubmitWorkspace/utils/launchEffort/launchEffort.test.ts @@ -0,0 +1,40 @@ +import { describe, expect, test } from "bun:test"; +import { launchEffort } from "./launchEffort"; + +describe("launchEffort", () => { + test("a chat launch carries the picked effort to a host that applies it", () => { + expect( + launchEffort("high", { + openAsChat: true, + hostLaunchesChatWithEffort: true, + }), + ).toBe("high"); + }); + + test("a chat launch drops the effort for an older host, which would open a terminal", () => { + expect( + launchEffort("high", { + openAsChat: true, + hostLaunchesChatWithEffort: false, + }), + ).toBeUndefined(); + }); + + test("a terminal launch always carries the effort", () => { + expect( + launchEffort("max", { + openAsChat: false, + hostLaunchesChatWithEffort: false, + }), + ).toBe("max"); + }); + + test("no pick sends no effort", () => { + expect( + launchEffort(null, { + openAsChat: true, + hostLaunchesChatWithEffort: true, + }), + ).toBeUndefined(); + }); +}); diff --git a/apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/components/DashboardNewWorkspaceForm/PromptGroup/hooks/useSubmitWorkspace/utils/launchEffort/launchEffort.ts b/apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/components/DashboardNewWorkspaceForm/PromptGroup/hooks/useSubmitWorkspace/utils/launchEffort/launchEffort.ts new file mode 100644 index 00000000000..b510317e847 --- /dev/null +++ b/apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/components/DashboardNewWorkspaceForm/PromptGroup/hooks/useSubmitWorkspace/utils/launchEffort/launchEffort.ts @@ -0,0 +1,7 @@ +export function launchEffort( + selectedEffort: string | null, + launch: { openAsChat: boolean; hostLaunchesChatWithEffort: boolean }, +): string | undefined { + if (launch.openAsChat && !launch.hostLaunchesChatWithEffort) return undefined; + return selectedEffort ?? undefined; +} diff --git a/apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/components/NewWorkspaceScreen/NewWorkspaceScreen.tsx b/apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/components/NewWorkspaceScreen/NewWorkspaceScreen.tsx index 607b3156586..44d17aebcf5 100644 --- a/apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/components/NewWorkspaceScreen/NewWorkspaceScreen.tsx +++ b/apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/components/NewWorkspaceScreen/NewWorkspaceScreen.tsx @@ -13,6 +13,7 @@ import { isCloudUsageRefusal } from "@superset/shared/billing"; import { startableCloudEnvironments } from "@superset/shared/cloud-environments"; import { FEATURE_FLAGS } from "@superset/shared/constants"; import { CLOUD_HOST_ID } from "@superset/shared/host-routing"; +import { hostLaunchesChatWithEffort } from "@superset/shared/host-version"; import { Button } from "@superset/ui/button"; import { isEnterSubmit } from "@superset/ui/lib/keyboard"; import { toast } from "@superset/ui/sonner"; @@ -26,6 +27,7 @@ import { LuGitPullRequest } from "react-icons/lu"; import { GitHubStarPill } from "renderer/components/GitHubStarPill"; import { env } from "renderer/env.renderer"; import { useHostProjects } from "renderer/hooks/host-projects/useHostProjects"; +import { useHostServiceInfo } from "renderer/hooks/host-service/useHostServiceInfo"; import { resolveHostUrl } from "renderer/hooks/host-service/useHostTargetUrl"; import { useAcpChatEnabled } from "renderer/hooks/useAcpChatEnabled"; import { useActiveOrganizationId } from "renderer/hooks/useActiveOrganizationId"; @@ -467,6 +469,7 @@ export function NewWorkspaceScreen({ }) ?? null ); }, [hostId, machineId, activeHostUrl, activeOrganizationId, relayUrl]); + const launchHostInfo = useHostServiceInfo(isCloudHost ? null : launchHostUrl); const githubProviders = useGitHubMentionProviders( useMemo( () => @@ -797,6 +800,7 @@ export function NewWorkspaceScreen({ resolvedEnvironment?.id ?? null, hostId, isSession, + hostLaunchesChatWithEffort(launchHostInfo.data?.version), ); const submitBlocker = useMemo(() => { diff --git a/apps/desktop/src/renderer/stores/workspace-creates/pendingCloudLaunch/pendingCloudLaunch.test.ts b/apps/desktop/src/renderer/stores/workspace-creates/pendingCloudLaunch/pendingCloudLaunch.test.ts index b17fbf0a615..ff6b1d07b2f 100644 --- a/apps/desktop/src/renderer/stores/workspace-creates/pendingCloudLaunch/pendingCloudLaunch.test.ts +++ b/apps/desktop/src/renderer/stores/workspace-creates/pendingCloudLaunch/pendingCloudLaunch.test.ts @@ -190,13 +190,14 @@ test("seeding twice from either source opens one waiting pane", () => { expect(withPendingCloudLaunch(layoutWith([]), null)).toBeNull(); }); -test("attaching preserves the pane, tab, draft, queued messages and model without replaying the initial prompt", () => { +test("attaching preserves the pane, tab, draft, queued messages, model and effort without replaying the initial prompt", () => { const state = collections(); seedPendingCloudLaunch({ collections: state.collections, workspaceId: "handoff", launch, modelId: "chosen-model", + effortId: "high", modeId: "plan", }); const layout = state.rows.get("handoff")?.paneLayout; @@ -226,6 +227,7 @@ test("attaching preserves the pane, tab, draft, queued messages and model withou draftId: pending.data.draftId, queuedPrompts: pending.data.queuedPrompts, chatModelId: "chosen-model", + chatEffortId: "high", chatModeId: "plan", }); expect(data).not.toHaveProperty("pendingPrompt"); diff --git a/apps/desktop/src/renderer/stores/workspace-creates/pendingCloudLaunch/pendingCloudLaunch.ts b/apps/desktop/src/renderer/stores/workspace-creates/pendingCloudLaunch/pendingCloudLaunch.ts index 8cd1f74bfa3..d6341663285 100644 --- a/apps/desktop/src/renderer/stores/workspace-creates/pendingCloudLaunch/pendingCloudLaunch.ts +++ b/apps/desktop/src/renderer/stores/workspace-creates/pendingCloudLaunch/pendingCloudLaunch.ts @@ -47,6 +47,7 @@ export function pendingLaunchSurface( export interface PendingCloudLaunchContext { prompt?: string; modelId?: string | null; + effortId?: string | null; modeId?: string | null; } @@ -79,7 +80,7 @@ function isTerminalClaimed( export function withPendingCloudLaunch( layout: WorkspaceState, launch: CloudAgentLaunchDescriptor | null | undefined, - { prompt, modelId, modeId }: PendingCloudLaunchContext = {}, + { prompt, modelId, effortId, modeId }: PendingCloudLaunchContext = {}, otherLayouts: readonly WorkspaceState[] = [], ): WorkspaceState | null { const terminalId = launch?.terminalId; @@ -99,6 +100,7 @@ export function withPendingCloudLaunch( terminalId, ...(prompt ? { launchPrompt: prompt } : {}), ...(modelId ? { chatModelId: modelId } : {}), + ...(effortId ? { chatEffortId: effortId } : {}), ...(modeId ? { chatModeId: modeId } : {}), } satisfies PendingCloudLaunchPaneData, }, @@ -174,6 +176,7 @@ function carriedOver(data: PendingCloudLaunchPaneData) { draftId: data.draftId, ...(data.queuedPrompts ? { queuedPrompts: data.queuedPrompts } : {}), ...(data.chatModelId ? { chatModelId: data.chatModelId } : {}), + ...(data.chatEffortId ? { chatEffortId: data.chatEffortId } : {}), ...(data.chatModeId ? { chatModeId: data.chatModeId } : {}), }; } diff --git a/packages/shared/src/host-version.test.ts b/packages/shared/src/host-version.test.ts index 636ce6669ca..1d73e19f035 100644 --- a/packages/shared/src/host-version.test.ts +++ b/packages/shared/src/host-version.test.ts @@ -1,8 +1,10 @@ import { describe, expect, test } from "bun:test"; import { ATTACHMENT_PARTS_MIN_HOST_VERSION } from "./attachment-limits"; import { + CHAT_LAUNCH_EFFORT_MIN_HOST_VERSION, CHAT_SELECTIONS_MIN_HOST_VERSION, deriveHostVersionState, + hostLaunchesChatWithEffort, hostNeedsUpdate, hostReadsAttachmentParts, hostRemembersChatSelections, @@ -106,3 +108,13 @@ describe("hostRemembersChatSelections", () => { expect(hostRemembersChatSelections(undefined)).toBe(false); }); }); + +describe("hostLaunchesChatWithEffort", () => { + test("a host at or above the floor starts a chat on its effort; an older or unknown one does not", () => { + expect( + hostLaunchesChatWithEffort(CHAT_LAUNCH_EFFORT_MIN_HOST_VERSION), + ).toBe(true); + expect(hostLaunchesChatWithEffort("2.0.8")).toBe(false); + expect(hostLaunchesChatWithEffort(null)).toBe(false); + }); +}); diff --git a/packages/shared/src/host-version.ts b/packages/shared/src/host-version.ts index 33cb72913d0..e5164fb5b76 100644 --- a/packages/shared/src/host-version.ts +++ b/packages/shared/src/host-version.ts @@ -121,6 +121,19 @@ export function hostReadsAttachmentParts( ); } +/** The first host that starts a chat on the effort a launch asks for. Older hosts open a terminal instead. */ +export const CHAT_LAUNCH_EFFORT_MIN_HOST_VERSION = "2.0.9"; + +/** Whether a chat launch can carry an effort without the host falling back to a terminal. */ +export function hostLaunchesChatWithEffort( + hostVersion: string | null | undefined, +): boolean { + const version = semver.coerce(hostVersion ?? ""); + return ( + version !== null && semver.gte(version, CHAT_LAUNCH_EFFORT_MIN_HOST_VERSION) + ); +} + /** The first host that remembers the model, effort and mode a user picks in a chat. */ export const CHAT_SELECTIONS_MIN_HOST_VERSION = "2.0.6";