Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion src/web-ui/src/flow_chat/components/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ import type { SessionPermissionMode } from '@/infrastructure/api/service-api/Age
import { isSessionInUseError } from '@/infrastructure/api/errors/TauriCommandError';
import { isPeerDeviceModeActive } from '@/infrastructure/peer-device/peerModeFlag';
import { usePeerDeviceModeOptional } from '@/infrastructure/peer-device/peerDeviceContextState';
import { isBtwSessionDraft } from '../utils/modelSelectionTarget';
import { isBtwParentBackedSession, isBtwSessionDraft } from '../utils/modelSelectionTarget';
import { hasSessionStarted, isSessionBindingLocked } from '../utils/sessionLifecycle';
import {
canTreatMissingPermissionModeAsDefault,
Expand Down Expand Up @@ -724,6 +724,7 @@ export const ChatInput: React.FC<ChatInputProps> = ({
const hasEffectiveTargetSession = effectiveTargetSession !== undefined;
const peer = usePeerDeviceModeOptional();
const isBtwDraftTarget = isBtwSessionDraft(effectiveTargetSession);
const isBtwParentBackedTarget = isBtwParentBackedSession(effectiveTargetSession);
const btwDraftSettingsInherited = isBtwDraftTarget && Boolean(peer?.peerMode.active)
&& (effectiveTargetSession?.config.modelPoolId
? peer?.currentPeerCapabilities?.btwModelPoolSelectionV1 !== true
Expand Down Expand Up @@ -2613,6 +2614,7 @@ export const ChatInput: React.FC<ChatInputProps> = ({
void (async () => {
try {
const permissionSessionId = isBtwDraftTarget
|| isBtwParentBackedTarget
? effectiveTargetSession?.parentSessionId : effectiveTargetSessionId;
if (!permissionSessionId) return;
const response = await readComposerPermissionMode({
Expand Down Expand Up @@ -2692,6 +2694,7 @@ export const ChatInput: React.FC<ChatInputProps> = ({
effectiveTargetSession?.externalHistory,
effectiveTargetSession?.externalContinuationPermissionMode,
isBtwDraftTarget,
isBtwParentBackedTarget,
isAcpTargetSession,
t,
hasEffectiveTargetSession,
Expand Down
25 changes: 25 additions & 0 deletions src/web-ui/src/flow_chat/utils/modelSelectionTarget.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { describe, expect, it } from 'vitest';
import { isBtwParentBackedSession, isBtwSessionDraft } from './modelSelectionTarget';

describe('BTW session target classification', () => {
it('keeps a transient BTW child parent-backed after a provisional turn exists', () => {
const child = {
sessionKind: 'btw',
parentSessionId: 'parent-1',
isTransient: true,
isHistorical: false,
dialogTurns: [{ id: 'provisional-turn' }],
};

expect(isBtwSessionDraft(child)).toBe(false);
expect(isBtwParentBackedSession(child)).toBe(true);
});

it.each([
['a historical BTW child', { sessionKind: 'btw', parentSessionId: 'parent-1', isTransient: true, isHistorical: true }],
['a durable child', { sessionKind: 'btw', parentSessionId: 'parent-1', isTransient: false, isHistorical: false }],
['a BTW child without a parent', { sessionKind: 'btw', isTransient: true, isHistorical: false }],
])('does not mark %s as parent-backed', (_label, session) => {
expect(isBtwParentBackedSession(session)).toBe(false);
});
});
9 changes: 9 additions & 0 deletions src/web-ui/src/flow_chat/utils/modelSelectionTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export type SessionModelSelectionTarget = {
isTransient?: boolean;
agentBackedTransient?: boolean;
sessionKind?: string;
parentSessionId?: string;
isHistorical?: boolean;
lastSubmittedMode?: string;
dialogTurns?: readonly unknown[];
Expand All @@ -14,6 +15,14 @@ export function isBtwSessionDraft(session: SessionModelSelectionTarget | undefin
&& !session.lastSubmittedMode && session.dialogTurns?.length === 0);
}

/** Temporary BTW children execute through their parent until they are saved as a fork. */
export function isBtwParentBackedSession(session: SessionModelSelectionTarget | undefined): boolean {
return Boolean(session?.sessionKind === 'btw'
&& session.isTransient === true
&& !session.isHistorical
&& session.parentSessionId);
}

/** Whether the visible selector has a real runtime session to update. */
export function shouldSyncSessionModelSelection<T extends SessionModelSelectionTarget>(
session: T | undefined,
Expand Down
Loading