This repository was archived by the owner on Aug 6, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
fix(pi): preserve cloud model selection #4032
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
packages/ui/src/features/pi-sessions/PiSessionModelControls.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| import type { | ||
| PiModelSelection, | ||
| PiSessionController, | ||
| PiThinkingLevel, | ||
| } from "@posthog/core/pi-runtime/piSessionController"; | ||
| import type { PiControllerSessionState } from "@posthog/core/pi-runtime/piSessionStore"; | ||
| import { Skeleton } from "@posthog/quill"; | ||
| import { isTerminalStatus } from "@posthog/shared/domain-types"; | ||
| import { useCallback } from "react"; | ||
| import { PiModelSelector, PiThinkingLevelSelector } from "./PiSessionControls"; | ||
| import { | ||
| getPiPendingConfig, | ||
| usePiPendingConfigStore, | ||
| } from "./piPendingConfigStore"; | ||
| import { usePiModelCatalog } from "./usePiModelCatalog"; | ||
|
|
||
| interface PiSessionModelControlsProps { | ||
| taskId: string; | ||
| taskRunId?: string; | ||
| session: PiControllerSessionState; | ||
| controller: PiSessionController; | ||
| isOnline: boolean; | ||
| onError: (error: unknown, fallback: string) => void; | ||
| } | ||
|
|
||
| export function PiSessionModelControls({ | ||
| taskId, | ||
| taskRunId, | ||
| session, | ||
| controller, | ||
| isOnline, | ||
| onError, | ||
| }: PiSessionModelControlsProps) { | ||
| const isCloudSession = session.cloudStatus !== undefined; | ||
| const isTerminalCloudRun = | ||
| isCloudSession && isTerminalStatus(session.cloudStatus); | ||
| const pendingConfig = usePiPendingConfigStore((state) => | ||
| getPiPendingConfig(state, taskId, taskRunId), | ||
| ); | ||
| const setPendingConfig = usePiPendingConfigStore((state) => state.setConfig); | ||
| const { data: catalog = [], isPending: catalogLoading } = | ||
| usePiModelCatalog(isCloudSession); | ||
| const controlsDisabled = | ||
| session.status?.isStreaming || | ||
| session.status?.isCompacting || | ||
| session.isBashRunning || | ||
| session.connectionState !== "connected"; | ||
| const currentModel = pendingConfig?.model ?? session.status?.model; | ||
| const models = isCloudSession ? catalog : session.models; | ||
| const modelsLoaded = isCloudSession ? !catalogLoading : session.modelsLoaded; | ||
| const catalogModel = catalog.find( | ||
| (model) => | ||
| model.provider === currentModel?.provider && model.id === currentModel.id, | ||
| ); | ||
| const thinkingLevels = isCloudSession | ||
| ? (catalogModel?.thinkingLevels ?? []) | ||
| : session.thinkingLevels; | ||
| const requestedThinkingLevel = | ||
| pendingConfig?.thinkingLevel ?? session.status?.thinkingLevel; | ||
| const currentThinkingLevel = | ||
| requestedThinkingLevel && thinkingLevels.includes(requestedThinkingLevel) | ||
| ? requestedThinkingLevel | ||
| : thinkingLevels[0]; | ||
| const thinkingLevelsLoaded = isCloudSession | ||
| ? !catalogLoading | ||
| : session.thinkingLevelsLoaded; | ||
| const disabled = isTerminalCloudRun ? !isOnline : controlsDisabled; | ||
| const setModel = useCallback( | ||
| (model: PiModelSelection) => { | ||
| if (taskRunId && isTerminalCloudRun) { | ||
| const nextThinkingLevels = | ||
| catalog.find( | ||
| (candidate) => | ||
| candidate.provider === model.provider && | ||
| candidate.id === model.id, | ||
| )?.thinkingLevels ?? []; | ||
| const requestedThinkingLevel = | ||
| pendingConfig?.thinkingLevel ?? session.status?.thinkingLevel; | ||
| const thinkingLevel = | ||
| requestedThinkingLevel && | ||
| nextThinkingLevels.includes(requestedThinkingLevel) | ||
| ? requestedThinkingLevel | ||
| : nextThinkingLevels[0]; | ||
| setPendingConfig(taskId, taskRunId, { model, thinkingLevel }); | ||
| return; | ||
| } | ||
|
|
||
| void controller | ||
| .setModel(taskId, model) | ||
| .catch((error) => onError(error, "Failed to change Pi model")); | ||
| }, | ||
| [ | ||
| catalog, | ||
| controller, | ||
| isTerminalCloudRun, | ||
| onError, | ||
| pendingConfig?.thinkingLevel, | ||
| session.status?.thinkingLevel, | ||
| setPendingConfig, | ||
| taskId, | ||
| taskRunId, | ||
| ], | ||
| ); | ||
| const setThinkingLevel = useCallback( | ||
| (level: PiThinkingLevel) => { | ||
| if (taskRunId && isTerminalCloudRun) { | ||
| setPendingConfig(taskId, taskRunId, { thinkingLevel: level }); | ||
| return; | ||
| } | ||
|
|
||
| void controller | ||
| .setThinkingLevel(taskId, level) | ||
| .catch((error) => onError(error, "Failed to change Pi thinking level")); | ||
| }, | ||
| [ | ||
| controller, | ||
| isTerminalCloudRun, | ||
| onError, | ||
| setPendingConfig, | ||
| taskId, | ||
| taskRunId, | ||
| ], | ||
| ); | ||
|
|
||
| if (!modelsLoaded) { | ||
| return <Skeleton className="h-7 w-32 bg-foreground/15" />; | ||
| } | ||
|
|
||
| const supportsThinking = thinkingLevels.some((level) => level !== "off"); | ||
| return ( | ||
| <span className="flex gap-1"> | ||
| <PiModelSelector | ||
| models={models} | ||
| currentModel={currentModel} | ||
| disabled={disabled} | ||
| onChange={setModel} | ||
| /> | ||
| {currentThinkingLevel && thinkingLevelsLoaded && supportsThinking && ( | ||
| <PiThinkingLevelSelector | ||
| level={currentThinkingLevel} | ||
| levels={thinkingLevels} | ||
| disabled={disabled} | ||
| onChange={setThinkingLevel} | ||
| /> | ||
| )} | ||
| </span> | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The web production build resolves workspace subpaths through
posthogSrcAliasesbecause their fallback exports do not resolve under Rollup, but the new@posthog/harnessimport has no corresponding alias. As a result, the web build cannot resolve this module.Context Used: CLAUDE.md (source)
Knowledge Base Used:
hog/harnessCLI)Prompt To Fix With AI