Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
de26297249 | ||
|
|
0288ac4599 | ||
|
|
f928ba2c65 | ||
|
|
8d271c0e85 | ||
|
|
d6585f6314 |
No files matched your search
@@ -208,6 +208,44 @@ type EnvironmentUnavailableState = {
|
||||
readonly connectionState: "connecting" | "disconnected" | "error";
|
||||
};
|
||||
|
||||
function modelSelectionOptionsEqual(
|
||||
left: ModelSelection["options"] | undefined,
|
||||
right: ModelSelection["options"] | undefined,
|
||||
): boolean {
|
||||
if (left === right) return true;
|
||||
if (left === undefined || right === undefined) return false;
|
||||
return JSON.stringify(left) === JSON.stringify(right);
|
||||
}
|
||||
|
||||
function modelSelectionsEqual(
|
||||
left: ModelSelection | null | undefined,
|
||||
right: ModelSelection | null | undefined,
|
||||
): boolean {
|
||||
if (left === right) return true;
|
||||
if (left == null || right == null) return left === right;
|
||||
return (
|
||||
left.instanceId === right.instanceId &&
|
||||
left.model === right.model &&
|
||||
modelSelectionOptionsEqual(left.options, right.options)
|
||||
);
|
||||
}
|
||||
|
||||
function useStableModelSelection<T extends ModelSelection | null | undefined>(selection: T): T {
|
||||
const stableSelectionRef = useRef<T>(selection);
|
||||
if (!modelSelectionsEqual(stableSelectionRef.current, selection)) {
|
||||
stableSelectionRef.current = selection;
|
||||
}
|
||||
return stableSelectionRef.current;
|
||||
}
|
||||
|
||||
function useEventCallback<TArgs extends unknown[], TResult>(
|
||||
callback: (...args: TArgs) => TResult,
|
||||
): (...args: TArgs) => TResult {
|
||||
const callbackRef = useRef(callback);
|
||||
callbackRef.current = callback;
|
||||
return useCallback((...args: TArgs) => callbackRef.current(...args), []);
|
||||
}
|
||||
|
||||
type ThreadPlanCatalogEntry = Pick<Thread, "id" | "proposedPlans">;
|
||||
|
||||
function useThreadPlanCatalog(threadIds: readonly ThreadId[]): ThreadPlanCatalogEntry[] {
|
||||
@@ -962,6 +1000,8 @@ export default function ChatView(props: ChatViewProps) {
|
||||
);
|
||||
const isServerThread = routeKind === "server" && serverThread !== undefined;
|
||||
const activeThread = isServerThread ? serverThread : localDraftThread;
|
||||
const activeThreadModelSelection = useStableModelSelection(activeThread?.modelSelection);
|
||||
const activeThreadProviderInstanceId = activeThread?.session?.providerInstanceId;
|
||||
const runtimeMode = composerRuntimeMode ?? activeThread?.runtimeMode ?? DEFAULT_RUNTIME_MODE;
|
||||
const interactionMode =
|
||||
composerInteractionMode ?? activeThread?.interactionMode ?? DEFAULT_INTERACTION_MODE;
|
||||
@@ -1327,7 +1367,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
|
||||
const selectedProviderByThreadId = composerActiveProvider ?? null;
|
||||
const threadProvider =
|
||||
activeThread?.modelSelection.instanceId ??
|
||||
activeThreadModelSelection?.instanceId ??
|
||||
activeProject?.defaultModelSelection?.instanceId ??
|
||||
null;
|
||||
const lockedProvider = deriveLockedProvider({
|
||||
@@ -1467,7 +1507,14 @@ export default function ChatView(props: ChatViewProps) {
|
||||
);
|
||||
const selectedProvider: ProviderDriverKind = lockedProvider ?? unlockedSelectedProvider;
|
||||
const phase = derivePhase(activeThread?.session ?? null);
|
||||
const threadActivities = activeThread?.activities ?? EMPTY_ACTIVITIES;
|
||||
const threadActivities =
|
||||
activeThread?.activities && activeThread.activities.length > 0
|
||||
? activeThread.activities
|
||||
: EMPTY_ACTIVITIES;
|
||||
const proposedPlans =
|
||||
activeThread?.proposedPlans && activeThread.proposedPlans.length > 0
|
||||
? activeThread.proposedPlans
|
||||
: EMPTY_PROPOSED_PLANS;
|
||||
const workLogEntries = useMemo(
|
||||
() => deriveWorkLogEntries(threadActivities, activeLatestTurn?.turnId ?? undefined),
|
||||
[activeLatestTurn?.turnId, threadActivities],
|
||||
@@ -1521,11 +1568,8 @@ export default function ChatView(props: ChatViewProps) {
|
||||
if (!latestTurnSettled) {
|
||||
return null;
|
||||
}
|
||||
return findLatestProposedPlan(
|
||||
activeThread?.proposedPlans ?? [],
|
||||
activeLatestTurn?.turnId ?? null,
|
||||
);
|
||||
}, [activeLatestTurn?.turnId, activeThread?.proposedPlans, latestTurnSettled]);
|
||||
return findLatestProposedPlan(proposedPlans, activeLatestTurn?.turnId ?? null);
|
||||
}, [activeLatestTurn?.turnId, latestTurnSettled, proposedPlans]);
|
||||
const sidebarProposedPlan = useMemo(
|
||||
() =>
|
||||
findSidebarProposedPlan({
|
||||
@@ -1763,9 +1807,8 @@ export default function ChatView(props: ChatViewProps) {
|
||||
return [...serverMessagesWithPreviewHandoff, ...pendingMessages];
|
||||
}, [serverMessages, attachmentPreviewHandoffByMessageId, optimisticUserMessages]);
|
||||
const timelineEntries = useMemo(
|
||||
() =>
|
||||
deriveTimelineEntries(timelineMessages, activeThread?.proposedPlans ?? [], workLogEntries),
|
||||
[activeThread?.proposedPlans, timelineMessages, workLogEntries],
|
||||
() => deriveTimelineEntries(timelineMessages, proposedPlans, workLogEntries),
|
||||
[proposedPlans, timelineMessages, workLogEntries],
|
||||
);
|
||||
const { turnDiffSummaries, inferredCheckpointTurnCountByTurnId } =
|
||||
useTurnDiffSummaries(activeThread);
|
||||
@@ -1843,8 +1886,8 @@ export default function ChatView(props: ChatViewProps) {
|
||||
// than the default Codex's. Falls back to first-match-by-kind when no
|
||||
// saved instance id is available or the instance no longer exists.
|
||||
const activeProviderInstanceId =
|
||||
activeThread?.session?.providerInstanceId ??
|
||||
activeThread?.modelSelection.instanceId ??
|
||||
activeThreadProviderInstanceId ??
|
||||
activeThreadModelSelection?.instanceId ??
|
||||
activeProject?.defaultModelSelection?.instanceId ??
|
||||
null;
|
||||
const activeProviderStatus = useMemo(() => {
|
||||
@@ -2832,7 +2875,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
],
|
||||
);
|
||||
|
||||
const onSend = async (e?: { preventDefault: () => void }) => {
|
||||
const onSend = useEventCallback(async (e?: { preventDefault: () => void }) => {
|
||||
e?.preventDefault();
|
||||
const api = readEnvironmentApi(environmentId);
|
||||
if (
|
||||
@@ -3133,9 +3176,9 @@ export default function ChatView(props: ChatViewProps) {
|
||||
if (!turnStartSucceeded) {
|
||||
resetLocalDispatch();
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
const onInterrupt = async () => {
|
||||
const onInterrupt = useEventCallback(async () => {
|
||||
const api = readEnvironmentApi(environmentId);
|
||||
if (!api || !activeThread) return;
|
||||
await api.orchestration.dispatchCommand({
|
||||
@@ -3144,7 +3187,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
threadId: activeThread.id,
|
||||
createdAt: new Date().toISOString(),
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
const onRespondToApproval = useCallback(
|
||||
async (requestId: ApprovalRequestId, decision: ProviderApprovalDecision) => {
|
||||
@@ -3715,6 +3758,27 @@ export default function ChatView(props: ChatViewProps) {
|
||||
void onRevertToTurnCountRef.current(targetTurnCount);
|
||||
}, []);
|
||||
|
||||
const onImplementPlanInNewThreadForComposer = useEventCallback(onImplementPlanInNewThread);
|
||||
const onRespondToApprovalForComposer = useEventCallback(onRespondToApproval);
|
||||
const onSelectActivePendingUserInputOptionForComposer = useEventCallback(
|
||||
onSelectActivePendingUserInputOption,
|
||||
);
|
||||
const onAdvanceActivePendingUserInputForComposer = useEventCallback(
|
||||
onAdvanceActivePendingUserInput,
|
||||
);
|
||||
const onPreviousActivePendingUserInputQuestionForComposer = useEventCallback(
|
||||
onPreviousActivePendingUserInputQuestion,
|
||||
);
|
||||
const onChangeActivePendingUserInputCustomAnswerForComposer = useEventCallback(
|
||||
onChangeActivePendingUserInputCustomAnswer,
|
||||
);
|
||||
const onProviderModelSelectForComposer = useEventCallback(onProviderModelSelect);
|
||||
const toggleInteractionModeForComposer = useEventCallback(toggleInteractionMode);
|
||||
const handleRuntimeModeChangeForComposer = useEventCallback(handleRuntimeModeChange);
|
||||
const handleInteractionModeChangeForComposer = useEventCallback(handleInteractionModeChange);
|
||||
const togglePlanSidebarForComposer = useEventCallback(togglePlanSidebar);
|
||||
const setThreadErrorForComposer = useEventCallback(setThreadError);
|
||||
|
||||
// Empty state: no active thread
|
||||
if (!activeThread) {
|
||||
return <NoActiveThreadState />;
|
||||
@@ -3839,7 +3903,6 @@ export default function ChatView(props: ChatViewProps) {
|
||||
draftId={draftId}
|
||||
activeThreadId={activeThreadId}
|
||||
activeThreadEnvironmentId={activeThread?.environmentId}
|
||||
activeThread={activeThread}
|
||||
isServerThread={isServerThread}
|
||||
isLocalDraftThread={isLocalDraftThread}
|
||||
phase={phase}
|
||||
@@ -3867,8 +3930,9 @@ export default function ChatView(props: ChatViewProps) {
|
||||
lockedProvider={lockedProvider}
|
||||
providerStatuses={providerStatuses as ServerProvider[]}
|
||||
activeProjectDefaultModelSelection={activeProject?.defaultModelSelection}
|
||||
activeThreadModelSelection={activeThread?.modelSelection}
|
||||
activeThreadActivities={activeThread?.activities}
|
||||
activeThreadModelSelection={activeThreadModelSelection}
|
||||
activeThreadProviderInstanceId={activeThreadProviderInstanceId}
|
||||
activeThreadActivities={threadActivities}
|
||||
resolvedTheme={resolvedTheme}
|
||||
settings={settings}
|
||||
keybindings={keybindings}
|
||||
@@ -3881,24 +3945,26 @@ export default function ChatView(props: ChatViewProps) {
|
||||
scheduleStickToBottom={scrollToEnd}
|
||||
onSend={onSend}
|
||||
onInterrupt={onInterrupt}
|
||||
onImplementPlanInNewThread={onImplementPlanInNewThread}
|
||||
onRespondToApproval={onRespondToApproval}
|
||||
onSelectActivePendingUserInputOption={onSelectActivePendingUserInputOption}
|
||||
onAdvanceActivePendingUserInput={onAdvanceActivePendingUserInput}
|
||||
onImplementPlanInNewThread={onImplementPlanInNewThreadForComposer}
|
||||
onRespondToApproval={onRespondToApprovalForComposer}
|
||||
onSelectActivePendingUserInputOption={
|
||||
onSelectActivePendingUserInputOptionForComposer
|
||||
}
|
||||
onAdvanceActivePendingUserInput={onAdvanceActivePendingUserInputForComposer}
|
||||
onPreviousActivePendingUserInputQuestion={
|
||||
onPreviousActivePendingUserInputQuestion
|
||||
onPreviousActivePendingUserInputQuestionForComposer
|
||||
}
|
||||
onChangeActivePendingUserInputCustomAnswer={
|
||||
onChangeActivePendingUserInputCustomAnswer
|
||||
onChangeActivePendingUserInputCustomAnswerForComposer
|
||||
}
|
||||
onProviderModelSelect={onProviderModelSelect}
|
||||
toggleInteractionMode={toggleInteractionMode}
|
||||
handleRuntimeModeChange={handleRuntimeModeChange}
|
||||
handleInteractionModeChange={handleInteractionModeChange}
|
||||
togglePlanSidebar={togglePlanSidebar}
|
||||
onProviderModelSelect={onProviderModelSelectForComposer}
|
||||
toggleInteractionMode={toggleInteractionModeForComposer}
|
||||
handleRuntimeModeChange={handleRuntimeModeChangeForComposer}
|
||||
handleInteractionModeChange={handleInteractionModeChangeForComposer}
|
||||
togglePlanSidebar={togglePlanSidebarForComposer}
|
||||
focusComposer={focusComposer}
|
||||
scheduleComposerFocus={scheduleComposerFocus}
|
||||
setThreadError={setThreadError}
|
||||
setThreadError={setThreadErrorForComposer}
|
||||
onExpandImage={onExpandTimelineImage}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -380,7 +380,6 @@ export interface ChatComposerProps {
|
||||
// Thread context
|
||||
activeThreadId: ThreadId | null;
|
||||
activeThreadEnvironmentId: EnvironmentId | undefined;
|
||||
activeThread: Thread | undefined;
|
||||
isServerThread: boolean;
|
||||
isLocalDraftThread: boolean;
|
||||
|
||||
@@ -428,6 +427,7 @@ export interface ChatComposerProps {
|
||||
providerStatuses: ServerProvider[];
|
||||
activeProjectDefaultModelSelection: ModelSelection | null | undefined;
|
||||
activeThreadModelSelection: ModelSelection | null | undefined;
|
||||
activeThreadProviderInstanceId: ProviderInstanceId | undefined;
|
||||
|
||||
// Context window
|
||||
activeThreadActivities: Thread["activities"] | undefined;
|
||||
@@ -493,7 +493,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
draftId,
|
||||
activeThreadId,
|
||||
activeThreadEnvironmentId: _activeThreadEnvironmentId,
|
||||
activeThread,
|
||||
isServerThread: _isServerThread,
|
||||
isLocalDraftThread: _isLocalDraftThread,
|
||||
phase,
|
||||
@@ -522,6 +521,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
providerStatuses,
|
||||
activeProjectDefaultModelSelection,
|
||||
activeThreadModelSelection,
|
||||
activeThreadProviderInstanceId,
|
||||
activeThreadActivities,
|
||||
resolvedTheme,
|
||||
settings,
|
||||
@@ -595,7 +595,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
);
|
||||
const selectedProviderByThreadId = composerDraft.activeProvider ?? null;
|
||||
const threadProvider =
|
||||
activeThread?.session?.providerInstanceId ??
|
||||
activeThreadProviderInstanceId ??
|
||||
activeThreadModelSelection?.instanceId ??
|
||||
activeProjectDefaultModelSelection?.instanceId ??
|
||||
null;
|
||||
@@ -609,16 +609,16 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
) ?? ProviderDriverKind.make("codex");
|
||||
const selectedProvider: ProviderDriverKind = lockedProvider ?? unlockedSelectedProvider;
|
||||
const lockedContinuationGroupKey = useMemo((): string | null => {
|
||||
if (!lockedProvider || !activeThread) return null;
|
||||
if (!lockedProvider) return null;
|
||||
const lockedInstanceId =
|
||||
activeThread.session?.providerInstanceId ?? activeThreadModelSelection?.instanceId;
|
||||
activeThreadProviderInstanceId ?? activeThreadModelSelection?.instanceId;
|
||||
if (!lockedInstanceId) return null;
|
||||
return (
|
||||
providerInstanceEntries.find((entry) => entry.instanceId === lockedInstanceId)
|
||||
?.continuationGroupKey ?? null
|
||||
);
|
||||
}, [
|
||||
activeThread,
|
||||
activeThreadProviderInstanceId,
|
||||
activeThreadModelSelection?.instanceId,
|
||||
lockedProvider,
|
||||
providerInstanceEntries,
|
||||
@@ -637,7 +637,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
const selectedInstanceId = useMemo<ProviderInstanceId>(() => {
|
||||
const candidates: Array<string | null | undefined> = [
|
||||
composerDraft.activeProvider,
|
||||
activeThread?.session?.providerInstanceId,
|
||||
activeThreadProviderInstanceId,
|
||||
activeThreadModelSelection?.instanceId,
|
||||
activeProjectDefaultModelSelection?.instanceId,
|
||||
];
|
||||
@@ -679,7 +679,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
);
|
||||
}, [
|
||||
activeProjectDefaultModelSelection?.instanceId,
|
||||
activeThread?.session?.providerInstanceId,
|
||||
activeThreadProviderInstanceId,
|
||||
activeThreadModelSelection?.instanceId,
|
||||
composerDraft.activeProvider,
|
||||
explicitSelectedInstanceId,
|
||||
@@ -1863,7 +1863,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
);
|
||||
},
|
||||
addTerminalContext: (selection: TerminalContextSelection) => {
|
||||
if (!activeThread) return;
|
||||
if (!activeThreadId) return;
|
||||
const snapshot = composerEditorRef.current?.readSnapshot() ?? {
|
||||
value: promptRef.current,
|
||||
cursor: composerCursor,
|
||||
@@ -1883,7 +1883,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
insertion.prompt,
|
||||
{
|
||||
id: randomUUID(),
|
||||
threadId: activeThread.id,
|
||||
threadId: activeThreadId,
|
||||
createdAt: new Date().toISOString(),
|
||||
...selection,
|
||||
},
|
||||
@@ -1910,7 +1910,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
}),
|
||||
}),
|
||||
[
|
||||
activeThread,
|
||||
activeThreadId,
|
||||
composerDraftTarget,
|
||||
composerCursor,
|
||||
composerTerminalContexts,
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user