fix(web): keep the composer footer still while thread data loads (#10768)
Co-authored-by: Claude Fable 5.1 <[email protected]>
This commit is contained in:
1 parent
de545c4173
commit
7fbc545ae8
11 files changed
+263
-11
No files matched your search
@@ -55,6 +55,7 @@ const DEFAULT_CLAUDE_MODEL_CAPABILITIES: ModelCapabilities = createModelCapabili
|
||||
const CLAUDE_PRESENTATION = {
|
||||
displayName: "Claude",
|
||||
showInteractionModeToggle: true,
|
||||
reportsContextWindow: true,
|
||||
} as const;
|
||||
function toTitleCaseWords(value: string): string {
|
||||
const parts: Array<string> = [];
|
||||
|
||||
@@ -62,6 +62,7 @@ const CODEX_APP_SERVER_PROBE_FORCE_KILL_AFTER = "2 seconds" as const;
|
||||
const CODEX_PRESENTATION = {
|
||||
displayName: "Codex",
|
||||
showInteractionModeToggle: true,
|
||||
reportsContextWindow: true,
|
||||
} as const;
|
||||
|
||||
export interface CodexAppServerProviderSnapshot {
|
||||
|
||||
@@ -64,6 +64,7 @@ export interface ServerProviderPresentation {
|
||||
readonly displayName: string;
|
||||
readonly badgeLabel?: string;
|
||||
readonly showInteractionModeToggle?: boolean;
|
||||
readonly reportsContextWindow?: boolean;
|
||||
readonly requiresNewThreadForModelChange?: boolean;
|
||||
}
|
||||
|
||||
@@ -212,6 +213,9 @@ export function buildServerProvider(input: {
|
||||
...(typeof input.presentation.showInteractionModeToggle === "boolean"
|
||||
? { showInteractionModeToggle: input.presentation.showInteractionModeToggle }
|
||||
: {}),
|
||||
...(typeof input.presentation.reportsContextWindow === "boolean"
|
||||
? { reportsContextWindow: input.presentation.reportsContextWindow }
|
||||
: {}),
|
||||
...(typeof input.presentation.requiresNewThreadForModelChange === "boolean"
|
||||
? { requiresNewThreadForModelChange: input.presentation.requiresNewThreadForModelChange }
|
||||
: {}),
|
||||
|
||||
@@ -47,6 +47,8 @@ import {
|
||||
isBranchMismatchDismissedForSession,
|
||||
reconcileMountedTerminalThreadIds,
|
||||
reconcileRetainedMountedThreadIds,
|
||||
recallCheckoutIsRepo,
|
||||
rememberCheckoutIsRepo,
|
||||
resolveBackgroundDraftWorkspaceOptions,
|
||||
resolveComposerInteractionMode,
|
||||
resolveComposerProviderSelection,
|
||||
@@ -55,6 +57,7 @@ import {
|
||||
resolveProactiveTurnDiffAction,
|
||||
resolveThreadMetadataUpdateForNextTurn,
|
||||
resolveSendEnvMode,
|
||||
threadShellHasStarted,
|
||||
resolveDraftHeroState,
|
||||
scheduleEnvironmentReconnectWarning,
|
||||
startNewThreadForProject,
|
||||
@@ -1958,3 +1961,62 @@ describe("shouldRefocusComposerOnWindowFocus", () => {
|
||||
expect(shouldRefocusComposerOnWindowFocus(element("BUTTON", { within: "-popup" }))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("checkout Git memory", () => {
|
||||
it("answers from the last status seen for the same checkout", () => {
|
||||
rememberCheckoutIsRepo(environmentId, "/repo/plain-folder", false);
|
||||
expect(recallCheckoutIsRepo(environmentId, "/repo/plain-folder")).toBe(false);
|
||||
rememberCheckoutIsRepo(environmentId, "/repo/plain-folder", true);
|
||||
expect(recallCheckoutIsRepo(environmentId, "/repo/plain-folder")).toBe(true);
|
||||
});
|
||||
|
||||
it("does not answer for a checkout it has not seen", () => {
|
||||
expect(recallCheckoutIsRepo(environmentId, "/repo/never-opened")).toBeUndefined();
|
||||
expect(recallCheckoutIsRepo(environmentId, null)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("keeps environments apart", () => {
|
||||
rememberCheckoutIsRepo(environmentId, "/repo/shared-path", false);
|
||||
expect(
|
||||
recallCheckoutIsRepo(EnvironmentId.make("env-other"), "/repo/shared-path"),
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("does not confuse an environment id containing the separator with a path", () => {
|
||||
rememberCheckoutIsRepo(EnvironmentId.make("env"), "a:b", false);
|
||||
expect(recallCheckoutIsRepo(EnvironmentId.make("env:a"), "b")).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("threadShellHasStarted", () => {
|
||||
it("counts a thread that has a user message but no latest turn", () => {
|
||||
expect(
|
||||
threadShellHasStarted({ latestTurn: null, latestUserMessageAt: now, session: null }),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("counts a thread with a live session and nothing else", () => {
|
||||
expect(
|
||||
threadShellHasStarted({
|
||||
latestTurn: null,
|
||||
latestUserMessageAt: null,
|
||||
session: {
|
||||
threadId,
|
||||
status: "starting",
|
||||
providerName: "codex",
|
||||
runtimeMode: "full-access",
|
||||
activeTurnId: null,
|
||||
lastError: null,
|
||||
updatedAt: now,
|
||||
},
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("does not count a thread that never sent anything", () => {
|
||||
expect(
|
||||
threadShellHasStarted({ latestTurn: null, latestUserMessageAt: null, session: null }),
|
||||
).toBe(false);
|
||||
expect(threadShellHasStarted(null)).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -794,12 +794,55 @@ export function isBranchMismatchDismissedForSession(key: string | null): boolean
|
||||
return key !== null && sessionDismissedBranchMismatchKeys.has(key);
|
||||
}
|
||||
|
||||
// Git status for a checkout arrives after the composer paints, and the branch
|
||||
// strip mounts on the assumption that a project is a Git repo. Without a
|
||||
// memory, a non-Git project would mount the strip and drop it on every visit.
|
||||
// Keyed by environment and checkout for the session; never persisted.
|
||||
const sessionCheckoutIsRepo = new Map<string, boolean>();
|
||||
|
||||
function checkoutIsRepoKey(environmentId: EnvironmentId, cwd: string): string {
|
||||
return JSON.stringify([environmentId, cwd]);
|
||||
}
|
||||
|
||||
export function rememberCheckoutIsRepo(
|
||||
environmentId: EnvironmentId,
|
||||
cwd: string,
|
||||
isRepo: boolean,
|
||||
): void {
|
||||
sessionCheckoutIsRepo.set(checkoutIsRepoKey(environmentId, cwd), isRepo);
|
||||
}
|
||||
|
||||
export function recallCheckoutIsRepo(
|
||||
environmentId: EnvironmentId,
|
||||
cwd: string | null,
|
||||
): boolean | undefined {
|
||||
return cwd === null
|
||||
? undefined
|
||||
: sessionCheckoutIsRepo.get(checkoutIsRepoKey(environmentId, cwd));
|
||||
}
|
||||
|
||||
export function threadHasStarted(thread: Thread | null | undefined): boolean {
|
||||
return Boolean(
|
||||
thread && (thread.latestTurn !== null || thread.messages.length > 0 || thread.session !== null),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a thread ran at least one turn, judged from its shell alone.
|
||||
*
|
||||
* `threadHasStarted` needs the detail: a thread whose latest turn was cleared
|
||||
* still has messages, and the loading shell carries none. The shell records
|
||||
* when the last user message landed, which every started thread has.
|
||||
*/
|
||||
export function threadShellHasStarted(
|
||||
shell: Pick<ThreadShell, "latestTurn" | "latestUserMessageAt" | "session"> | null | undefined,
|
||||
): boolean {
|
||||
return Boolean(
|
||||
shell &&
|
||||
(shell.latestTurn !== null || shell.latestUserMessageAt !== null || shell.session !== null),
|
||||
);
|
||||
}
|
||||
|
||||
// Imported history has no session until its first prompt. Resolve its instance
|
||||
// through the environment's provider catalog before locking to a driver.
|
||||
export function deriveLockedProvider(input: {
|
||||
|
||||
@@ -403,6 +403,8 @@ import {
|
||||
readFileAsDataUrl,
|
||||
resolveFileAttachmentUrl,
|
||||
reconcileMountedTerminalThreadIds,
|
||||
recallCheckoutIsRepo,
|
||||
rememberCheckoutIsRepo,
|
||||
resolveBackgroundDraftWorkspaceOptions,
|
||||
resolveComposerInteractionMode,
|
||||
resolveComposerProviderSelection,
|
||||
@@ -3327,8 +3329,17 @@ export default function ChatView(props: ChatViewProps) {
|
||||
const activeWorkspaceRoot = activeThreadWorktreePath ?? activeProjectCwd ?? undefined;
|
||||
const activeTerminalLaunchContext =
|
||||
terminalUiLaunchContext?.threadId === activeThreadId ? terminalUiLaunchContext : null;
|
||||
// Default true while loading to avoid toolbar flicker.
|
||||
const isGitRepo = gitStatusQuery.data?.isRepo ?? true;
|
||||
// Git status arrives after the composer paints. A checkout seen earlier in
|
||||
// this session answers from memory, so a non-Git project does not mount the
|
||||
// branch strip and then drop it. A never-seen checkout assumes Git, which
|
||||
// is what nearly every project is.
|
||||
const liveIsGitRepo = gitStatusQuery.data?.isRepo;
|
||||
useEffect(() => {
|
||||
if (gitStatusCwd !== null && liveIsGitRepo !== undefined) {
|
||||
rememberCheckoutIsRepo(environmentId, gitStatusCwd, liveIsGitRepo);
|
||||
}
|
||||
}, [environmentId, gitStatusCwd, liveIsGitRepo]);
|
||||
const isGitRepo = liveIsGitRepo ?? recallCheckoutIsRepo(environmentId, gitStatusCwd) ?? true;
|
||||
// Keep a hidden, off-flow strip mounted for existing threads so the composer
|
||||
// can measure whether its relocated controls fit. The visible chrome remains
|
||||
// content-driven: Git/environment context or controls that actually fit.
|
||||
@@ -8341,6 +8352,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
activeThreadId={activeThreadId}
|
||||
activeThreadEnvironmentId={activeThread?.environmentId}
|
||||
activeThread={activeThread}
|
||||
activeThreadShell={routeServerThreadShell}
|
||||
promptHistoryMessages={timelineMessages}
|
||||
isServerThread={isServerThread}
|
||||
isLocalDraftThread={isLocalDraftThread}
|
||||
@@ -8386,6 +8398,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
interactionMode={interactionMode}
|
||||
lockedProvider={lockedProvider}
|
||||
providerStatuses={providerStatuses as ServerProvider[]}
|
||||
providerCatalogKnown={serverConfig !== null}
|
||||
activeProjectDefaultModelSelection={activeProjectDefaultModelSelection}
|
||||
activeThreadModelSelection={activeThread?.modelSelection}
|
||||
activeContextWindow={activeContextWindow}
|
||||
|
||||
@@ -63,6 +63,7 @@ import {
|
||||
readFileAsDataUrl,
|
||||
resolveComposerInteractionMode,
|
||||
resolveComposerProviderSelection,
|
||||
threadShellHasStarted,
|
||||
} from "../ChatView.logic";
|
||||
import {
|
||||
dataTransferHasComposerMention,
|
||||
@@ -198,10 +199,11 @@ import {
|
||||
renderProviderTraitsMenuContent,
|
||||
renderProviderTraitsPicker,
|
||||
} from "./composerProviderState";
|
||||
import { ContextWindowMeter } from "./ContextWindowMeter";
|
||||
import { ContextWindowMeter, ContextWindowMeterPlaceholder } from "./ContextWindowMeter";
|
||||
import {
|
||||
providerSupportsManualCompaction,
|
||||
resolveContextWindowModelDisplayName,
|
||||
shouldReserveContextWindowMeter,
|
||||
} from "./ContextWindowMeter.logic";
|
||||
import {
|
||||
attachVideoThumbnail,
|
||||
@@ -866,7 +868,13 @@ import {
|
||||
} from "../../providerInstances";
|
||||
import { type AppModelOption, getAppModelOptionsForInstance } from "../../modelSelection";
|
||||
import type { UnifiedSettings } from "@t3tools/contracts/settings";
|
||||
import { type ChatMessage, type SessionPhase, type Thread, videoMimeType } from "../../types";
|
||||
import {
|
||||
type ChatMessage,
|
||||
type SessionPhase,
|
||||
type Thread,
|
||||
type ThreadShell,
|
||||
videoMimeType,
|
||||
} from "../../types";
|
||||
import {
|
||||
buildComposerPromptHistoryEntries,
|
||||
stepComposerPromptHistory,
|
||||
@@ -1107,6 +1115,7 @@ const ComposerFooterModeControls = memo(function ComposerFooterModeControls(prop
|
||||
const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryActions(props: {
|
||||
compact: boolean;
|
||||
activeContextWindow: ContextWindowSnapshot | null;
|
||||
reserveContextWindowMeter: boolean;
|
||||
activeThreadModelDisplayName: string | null;
|
||||
isPreparingWorktree: boolean;
|
||||
pendingAction: {
|
||||
@@ -1143,6 +1152,8 @@ const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryActions(
|
||||
compactDisabled={props.compactDisabled}
|
||||
compactDisabledReason={props.compactDisabledReason}
|
||||
/>
|
||||
) : props.reserveContextWindowMeter ? (
|
||||
<ContextWindowMeterPlaceholder />
|
||||
) : null}
|
||||
<ComposerPrimaryActions
|
||||
compact={props.compact}
|
||||
@@ -1242,6 +1253,8 @@ export interface ChatComposerProps {
|
||||
activeThreadId: ThreadId | null;
|
||||
activeThreadEnvironmentId: EnvironmentId | undefined;
|
||||
activeThread: Thread | undefined;
|
||||
/** The routed server thread's shell, present before its detail loads. */
|
||||
activeThreadShell: ThreadShell | null;
|
||||
/** Timeline messages including optimistic sends, for ArrowUp prompt recall. */
|
||||
promptHistoryMessages: ReadonlyArray<ChatMessage>;
|
||||
isServerThread: boolean;
|
||||
@@ -1298,6 +1311,8 @@ export interface ChatComposerProps {
|
||||
// Provider / model
|
||||
lockedProvider: ProviderDriverKind | null;
|
||||
providerStatuses: ServerProvider[];
|
||||
/** False until the environment's server config has arrived at least once. */
|
||||
providerCatalogKnown: boolean;
|
||||
activeProjectDefaultModelSelection: ModelSelection | null | undefined;
|
||||
activeThreadModelSelection: ModelSelection | null | undefined;
|
||||
|
||||
@@ -1416,6 +1431,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
interactionMode: requestedInteractionMode,
|
||||
lockedProvider,
|
||||
providerStatuses,
|
||||
providerCatalogKnown,
|
||||
activeProjectDefaultModelSelection,
|
||||
activeThreadModelSelection,
|
||||
activeContextWindow,
|
||||
@@ -1712,6 +1728,12 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
const selectedInstanceId =
|
||||
selectedProviderEntry?.instanceId ?? NO_PROVIDER_MODEL_SELECTION.instanceId;
|
||||
const noProviderAvailable = selectedProviderEntry === undefined;
|
||||
// Before the catalog arrives, every thread resolves to "no provider". Send
|
||||
// stays blocked either way; only the chrome waits, keeping the picker with
|
||||
// the thread's own selection instead of swapping in the setup button and
|
||||
// back once the catalog lands.
|
||||
const providerCatalogPending = noProviderAvailable && !providerCatalogKnown;
|
||||
const showProviderUnavailable = noProviderAvailable && !providerCatalogPending;
|
||||
const providerSetupInstanceId = noProviderAvailable
|
||||
? (unavailableProviderInstanceId ??
|
||||
(lockedProvider === null
|
||||
@@ -1887,6 +1909,14 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
() => resolveContextWindowModelDisplayName(activeThreadModelSelection, modelOptionsByInstance),
|
||||
[activeThreadModelSelection, modelOptionsByInstance],
|
||||
);
|
||||
const reserveContextWindowMeter = shouldReserveContextWindowMeter({
|
||||
meterEnabled: settings.contextWindowMeterEnabled,
|
||||
detailLoading: props.threadSyncPhase === "loading",
|
||||
threadStarted: threadShellHasStarted(props.activeThreadShell),
|
||||
providerReportsContextWindow: selectedProviderStatus
|
||||
? selectedProviderStatus.reportsContextWindow === true
|
||||
: null,
|
||||
});
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Composer-local state
|
||||
@@ -3843,7 +3873,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
isStashMenuOpen ||
|
||||
isDragOverComposer ||
|
||||
isPreparingWorktree ||
|
||||
noProviderAvailable ||
|
||||
showProviderUnavailable ||
|
||||
projectSelectionRequired ||
|
||||
environmentUnavailable !== null ||
|
||||
composerSubmissionError !== null ||
|
||||
@@ -4088,7 +4118,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
const hiddenRestingBlockIds = restingBlockDefs
|
||||
.slice(restingBlockDefs.length - restingHiddenBlockCount)
|
||||
.map((def) => def.id);
|
||||
const composerControls = noProviderAvailable ? (
|
||||
const composerControls = showProviderUnavailable ? (
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
@@ -4117,8 +4147,17 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
<ProviderModelPicker
|
||||
isComposerOwned
|
||||
compact={composerControlsCompact}
|
||||
activeInstanceId={selectedInstanceId}
|
||||
model={selectedModelForPickerWithCustomFallback}
|
||||
disabled={providerCatalogPending}
|
||||
activeInstanceId={
|
||||
providerCatalogPending
|
||||
? (activeThreadModelSelection?.instanceId ?? selectedInstanceId)
|
||||
: selectedInstanceId
|
||||
}
|
||||
model={
|
||||
providerCatalogPending
|
||||
? (activeThreadModelSelection?.model ?? selectedModelForPickerWithCustomFallback)
|
||||
: selectedModelForPickerWithCustomFallback
|
||||
}
|
||||
lockedProvider={lockedProvider}
|
||||
lockedContinuationGroupKey={lockedContinuationGroupKey}
|
||||
instanceEntries={providerInstanceEntries}
|
||||
@@ -5172,7 +5211,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
: activePendingProgress.customAnswer ||
|
||||
"Type your own answer, or leave this blank to use the selected option"
|
||||
: prompt.trim() ||
|
||||
(noProviderAvailable ? "Enable a provider in Settings" : "Ask anything...")}
|
||||
(showProviderUnavailable
|
||||
? "Enable a provider in Settings"
|
||||
: "Ask anything...")}
|
||||
</button>
|
||||
{collapsedComposerImagePreviews}
|
||||
<button
|
||||
@@ -5631,7 +5672,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
"relative",
|
||||
isComposerResting && "flex min-w-0 items-center gap-1",
|
||||
isComposerResting &&
|
||||
(settings.contextWindowMeterEnabled && activeContextWindow
|
||||
((settings.contextWindowMeterEnabled && activeContextWindow) ||
|
||||
reserveContextWindowMeter
|
||||
? "pr-28"
|
||||
: showComposerAttachAction
|
||||
? "pr-20"
|
||||
@@ -5685,7 +5727,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
? "Add feedback to refine the plan, or leave this blank to implement it"
|
||||
: projectSelectionRequired
|
||||
? "Choose a project above to start a thread"
|
||||
: noProviderAvailable
|
||||
: showProviderUnavailable
|
||||
? "Enable a provider in Settings to send a message"
|
||||
: phase === "disconnected"
|
||||
? DISCONNECTED_COMPOSER_PLACEHOLDER
|
||||
@@ -5808,6 +5850,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
activeContextWindow={
|
||||
settings.contextWindowMeterEnabled ? activeContextWindow : null
|
||||
}
|
||||
reserveContextWindowMeter={reserveContextWindowMeter}
|
||||
activeThreadModelDisplayName={activeThreadModelDisplayName}
|
||||
pendingAction={pendingPrimaryAction}
|
||||
isRunning={phase === "running"}
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
hasDismissedResumeCompaction,
|
||||
resolveContextWindowModelDisplayName,
|
||||
shouldOfferResumeCompaction,
|
||||
shouldReserveContextWindowMeter,
|
||||
} from "./ContextWindowMeter.logic";
|
||||
|
||||
function claudeProvider(input: {
|
||||
@@ -236,3 +237,52 @@ describe("hasDismissedResumeCompaction", () => {
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("shouldReserveContextWindowMeter", () => {
|
||||
const loadingStartedThread = {
|
||||
meterEnabled: true,
|
||||
detailLoading: true,
|
||||
threadStarted: true,
|
||||
providerReportsContextWindow: true,
|
||||
};
|
||||
|
||||
it("holds the meter's slot while a started thread's detail loads", () => {
|
||||
expect(shouldReserveContextWindowMeter(loadingStartedThread)).toBe(true);
|
||||
});
|
||||
|
||||
it("reserves nothing once the detail is in", () => {
|
||||
expect(shouldReserveContextWindowMeter({ ...loadingStartedThread, detailLoading: false })).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
it("reserves nothing for a thread that never ran a turn", () => {
|
||||
expect(shouldReserveContextWindowMeter({ ...loadingStartedThread, threadStarted: false })).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
it("reserves while the thread's provider is not in the catalog yet", () => {
|
||||
expect(
|
||||
shouldReserveContextWindowMeter({
|
||||
...loadingStartedThread,
|
||||
providerReportsContextWindow: null,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("reserves nothing for a provider that does not stream usage", () => {
|
||||
expect(
|
||||
shouldReserveContextWindowMeter({
|
||||
...loadingStartedThread,
|
||||
providerReportsContextWindow: false,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("reserves nothing while the meter is switched off", () => {
|
||||
expect(shouldReserveContextWindowMeter({ ...loadingStartedThread, meterEnabled: false })).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -108,3 +108,30 @@ export function formatContextWindowCompactionMessage(
|
||||
? `Context for ${modelDisplayName} compacts automatically when needed.`
|
||||
: "Context compacts automatically when needed.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the footer should hold the meter's slot before a snapshot exists.
|
||||
*
|
||||
* The snapshot comes from thread activities, which load after the shell.
|
||||
* Reserving the slot while the detail loads, for a started thread, keeps the
|
||||
* attach button still until the meter mounts. Once the detail is in, a
|
||||
* missing snapshot means there is no usage to show and nothing is reserved.
|
||||
*
|
||||
* The meter renders from stored activities whatever the provider's state, so
|
||||
* only a provider known not to stream usage skips the reservation. An unknown
|
||||
* provider (catalog still loading, or the thread's provider disabled) reserves.
|
||||
*/
|
||||
export function shouldReserveContextWindowMeter(input: {
|
||||
readonly meterEnabled: boolean;
|
||||
readonly detailLoading: boolean;
|
||||
readonly threadStarted: boolean;
|
||||
/** `null` while the thread's provider is not in the catalog. */
|
||||
readonly providerReportsContextWindow: boolean | null;
|
||||
}): boolean {
|
||||
return (
|
||||
input.meterEnabled &&
|
||||
input.detailLoading &&
|
||||
input.threadStarted &&
|
||||
input.providerReportsContextWindow !== false
|
||||
);
|
||||
}
|
||||
@@ -161,3 +161,8 @@ export function ContextWindowMeter(props: {
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
|
||||
/** Holds the meter's footprint while a thread's activities are still loading. */
|
||||
export function ContextWindowMeterPlaceholder() {
|
||||
return <span aria-hidden="true" className="size-7 shrink-0" />;
|
||||
}
|
||||
@@ -197,6 +197,9 @@ export const ServerProvider = Schema.Struct({
|
||||
badgeLabel: Schema.optional(TrimmedNonEmptyString),
|
||||
continuation: Schema.optional(ServerProviderContinuation),
|
||||
showInteractionModeToggle: Schema.optional(Schema.Boolean),
|
||||
// The driver streams context window usage, so a started thread will have a
|
||||
// meter once its activities load. Clients reserve the meter's space on it.
|
||||
reportsContextWindow: Schema.optional(Schema.Boolean),
|
||||
requiresNewThreadForModelChange: Schema.optional(Schema.Boolean),
|
||||
supportsConversationRollback: Schema.optional(Schema.Boolean),
|
||||
supportsTextGeneration: Schema.optional(Schema.Boolean),
|
||||
|
||||
Reference in new issue
Block a user