Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38f6a0b78a | ||
|
|
8b2adcc9fd | ||
|
|
4f0f24f055 |
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { assert, describe, expect, it } from "@effect/vitest";
|
||||
import { describe, expect, it } from "@effect/vitest";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
@@ -66,56 +66,6 @@ describe("ProcessDiagnostics", () => {
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("parses Windows process JSON through schemas", () =>
|
||||
Effect.sync(() => {
|
||||
const rows = ProcessDiagnostics.parseWindowsProcessRows(`
|
||||
[
|
||||
{
|
||||
"ProcessId": 4242,
|
||||
"ParentProcessId": 100,
|
||||
"CommandLine": "node server.js",
|
||||
"WorkingSetSize": 4096.7,
|
||||
"PercentProcessorTime": 2.5,
|
||||
"Status": "Running"
|
||||
},
|
||||
{
|
||||
"ProcessId": 0,
|
||||
"ParentProcessId": 100,
|
||||
"Name": "invalid.exe"
|
||||
},
|
||||
{
|
||||
"ProcessId": 4243,
|
||||
"ParentProcessId": 4242,
|
||||
"Name": "child.exe"
|
||||
}
|
||||
]
|
||||
`);
|
||||
|
||||
assert.deepEqual(rows, [
|
||||
{
|
||||
pid: 4242,
|
||||
ppid: 100,
|
||||
pgid: null,
|
||||
status: "Running",
|
||||
cpuPercent: 2.5,
|
||||
rssBytes: 4097,
|
||||
elapsed: "",
|
||||
command: "node server.js",
|
||||
},
|
||||
{
|
||||
pid: 4243,
|
||||
ppid: 4242,
|
||||
pgid: null,
|
||||
status: "Live",
|
||||
cpuPercent: 0,
|
||||
rssBytes: 0,
|
||||
elapsed: "",
|
||||
command: "child.exe",
|
||||
},
|
||||
]);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("aggregates only descendants of the server process", () =>
|
||||
Effect.sync(() => {
|
||||
const diagnostics = ProcessDiagnostics.aggregateProcessDiagnostics({
|
||||
|
||||
@@ -26,23 +26,9 @@ export interface ProcessRow {
|
||||
readonly command: string;
|
||||
}
|
||||
|
||||
const PROCESS_QUERY_TIMEOUT_MS = 1_000;
|
||||
const POSIX_PROCESS_QUERY_COMMAND = "pid=,ppid=,pgid=,stat=,pcpu=,rss=,etime=,command=";
|
||||
const PROCESS_QUERY_MAX_OUTPUT_BYTES = 2 * 1024 * 1024;
|
||||
const PROCESS_QUERY_TIMEOUT = Duration.seconds(1);
|
||||
|
||||
const WindowsProcessRecord = Schema.Struct({
|
||||
ProcessId: Schema.Number,
|
||||
ParentProcessId: Schema.Number,
|
||||
CommandLine: Schema.optional(Schema.String),
|
||||
Name: Schema.optional(Schema.String),
|
||||
WorkingSetSize: Schema.optional(Schema.Number),
|
||||
PercentProcessorTime: Schema.optional(Schema.Number),
|
||||
Status: Schema.optional(Schema.String),
|
||||
});
|
||||
type WindowsProcessRecord = typeof WindowsProcessRecord.Type;
|
||||
const WindowsProcessJson = Schema.fromJsonString(Schema.Unknown);
|
||||
const decodeWindowsProcessRecord = Schema.decodeUnknownOption(WindowsProcessRecord);
|
||||
const decodeWindowsProcessJson = Schema.decodeUnknownOption(WindowsProcessJson);
|
||||
|
||||
export interface ProcessDiagnosticsShape {
|
||||
readonly read: Effect.Effect<ServerProcessDiagnosticsResult>;
|
||||
@@ -88,9 +74,6 @@ function parseNumber(value: string): number | null {
|
||||
return Number.isFinite(parsed) ? parsed : null;
|
||||
}
|
||||
|
||||
const nonEmptyWindowsString = (value: string | undefined): Option.Option<string> =>
|
||||
Option.fromUndefinedOr(value).pipe(Option.filter((text) => text.trim().length > 0));
|
||||
|
||||
export function parsePosixProcessRows(output: string): ReadonlyArray<ProcessRow> {
|
||||
const rows: ProcessRow[] = [];
|
||||
const rowPattern =
|
||||
@@ -156,61 +139,51 @@ export function parsePosixProcessRows(output: string): ReadonlyArray<ProcessRow>
|
||||
return rows;
|
||||
}
|
||||
|
||||
function normalizeWindowsProcessRow(record: WindowsProcessRecord): Option.Option<ProcessRow> {
|
||||
const pid = Number.isInteger(record.ProcessId) ? Option.some(record.ProcessId) : Option.none();
|
||||
const ppid = Number.isInteger(record.ParentProcessId)
|
||||
? Option.some(record.ParentProcessId)
|
||||
: Option.none();
|
||||
const commandLine = nonEmptyWindowsString(record.CommandLine).pipe(
|
||||
Option.orElse(() => nonEmptyWindowsString(record.Name)),
|
||||
);
|
||||
function normalizeWindowsProcessRow(value: unknown): ProcessRow | null {
|
||||
if (typeof value !== "object" || value === null) return null;
|
||||
const record = value as Record<string, unknown>;
|
||||
const pid = typeof record.ProcessId === "number" ? record.ProcessId : null;
|
||||
const ppid = typeof record.ParentProcessId === "number" ? record.ParentProcessId : null;
|
||||
const commandLine =
|
||||
typeof record.CommandLine === "string" && record.CommandLine.trim().length > 0
|
||||
? record.CommandLine
|
||||
: typeof record.Name === "string"
|
||||
? record.Name
|
||||
: null;
|
||||
const workingSet =
|
||||
record.WorkingSetSize !== undefined && Number.isFinite(record.WorkingSetSize)
|
||||
typeof record.WorkingSetSize === "number" && Number.isFinite(record.WorkingSetSize)
|
||||
? Math.max(0, Math.round(record.WorkingSetSize))
|
||||
: 0;
|
||||
const cpuPercent =
|
||||
record.PercentProcessorTime !== undefined && Number.isFinite(record.PercentProcessorTime)
|
||||
typeof record.PercentProcessorTime === "number" && Number.isFinite(record.PercentProcessorTime)
|
||||
? Math.max(0, record.PercentProcessorTime)
|
||||
: 0;
|
||||
|
||||
if (
|
||||
Option.isNone(pid) ||
|
||||
pid.value <= 0 ||
|
||||
Option.isNone(ppid) ||
|
||||
ppid.value < 0 ||
|
||||
Option.isNone(commandLine)
|
||||
) {
|
||||
return Option.none<ProcessRow>();
|
||||
}
|
||||
return Option.some({
|
||||
pid: pid.value,
|
||||
ppid: ppid.value,
|
||||
if (!pid || pid <= 0 || ppid === null || ppid < 0 || !commandLine) return null;
|
||||
return {
|
||||
pid,
|
||||
ppid,
|
||||
pgid: null,
|
||||
status: record.Status !== undefined && record.Status.length > 0 ? record.Status : "Live",
|
||||
status: typeof record.Status === "string" && record.Status.length > 0 ? record.Status : "Live",
|
||||
cpuPercent,
|
||||
rssBytes: workingSet,
|
||||
elapsed: "",
|
||||
command: commandLine.value,
|
||||
});
|
||||
command: commandLine,
|
||||
};
|
||||
}
|
||||
|
||||
export function parseWindowsProcessRows(output: string): ReadonlyArray<ProcessRow> {
|
||||
function parseWindowsProcessRows(output: string): ReadonlyArray<ProcessRow> {
|
||||
if (output.trim().length === 0) return [];
|
||||
const parsed = decodeWindowsProcessJson(output);
|
||||
if (Option.isNone(parsed)) return [];
|
||||
|
||||
const records = Array.isArray(parsed.value) ? parsed.value : [parsed.value];
|
||||
return records.flatMap((record) => {
|
||||
const decoded = decodeWindowsProcessRecord(record);
|
||||
return Option.match(decoded, {
|
||||
onNone: () => [],
|
||||
onSome: (windowsRecord) =>
|
||||
Option.match(normalizeWindowsProcessRow(windowsRecord), {
|
||||
onNone: () => [],
|
||||
onSome: (row) => [row],
|
||||
}),
|
||||
try {
|
||||
const parsed = JSON.parse(output) as unknown;
|
||||
const records = Array.isArray(parsed) ? parsed : [parsed];
|
||||
return records.flatMap((record) => {
|
||||
const row = normalizeWindowsProcessRow(record);
|
||||
return row ? [row] : [];
|
||||
});
|
||||
});
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export function buildDescendantEntries(
|
||||
@@ -336,7 +309,7 @@ const runProcess = Effect.fn("runProcess")(
|
||||
(effect, input) =>
|
||||
effect.pipe(
|
||||
Effect.scoped,
|
||||
Effect.timeoutOption(PROCESS_QUERY_TIMEOUT),
|
||||
Effect.timeoutOption(Duration.millis(PROCESS_QUERY_TIMEOUT_MS)),
|
||||
Effect.flatMap((result) =>
|
||||
Option.match(result, {
|
||||
onNone: () => Effect.fail(toProcessDiagnosticsError(`${input.errorMessage} timed out.`)),
|
||||
|
||||
@@ -67,24 +67,4 @@ describe("VcsProjectConfig", () => {
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it.layer(TestLayer)("falls back to auto when config is invalid JSON", (it) => {
|
||||
it.effect("returns auto", () =>
|
||||
Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const root = yield* fileSystem.makeTempDirectoryScoped({
|
||||
prefix: "t3-vcs-config-test-",
|
||||
});
|
||||
const configDir = path.join(root, ".t3code");
|
||||
yield* fileSystem.makeDirectory(configDir, { recursive: true });
|
||||
yield* fileSystem.writeFileString(path.join(configDir, "vcs.json"), "{ nope");
|
||||
|
||||
const config = yield* VcsProjectConfig.VcsProjectConfig;
|
||||
const kind = yield* config.resolveKind({ cwd: root });
|
||||
|
||||
assert.equal(kind, "auto");
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -2,7 +2,6 @@ import * as Context from "effect/Context";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Schema from "effect/Schema";
|
||||
|
||||
@@ -16,10 +15,16 @@ const ProjectVcsConfig = Schema.Struct({
|
||||
),
|
||||
vcsKind: Schema.optional(VcsDriverKind),
|
||||
});
|
||||
const ProjectVcsConfigJson = Schema.fromJsonString(ProjectVcsConfig);
|
||||
const decodeProjectVcsConfigJson = Schema.decodeUnknownOption(ProjectVcsConfigJson);
|
||||
const isProjectVcsConfig = Schema.is(ProjectVcsConfig);
|
||||
|
||||
type ProjectVcsConfigFile = typeof ProjectVcsConfig.Type;
|
||||
interface ProjectVcsConfigFile {
|
||||
readonly vcs?:
|
||||
| {
|
||||
readonly kind?: VcsDriverKindType | undefined;
|
||||
}
|
||||
| undefined;
|
||||
readonly vcsKind?: VcsDriverKindType | undefined;
|
||||
}
|
||||
|
||||
export interface VcsProjectConfigResolveInput {
|
||||
readonly cwd: string;
|
||||
@@ -40,8 +45,13 @@ function configuredKind(config: ProjectVcsConfigFile): VcsDriverKindType | "auto
|
||||
return config.vcs?.kind ?? config.vcsKind ?? "auto";
|
||||
}
|
||||
|
||||
function parseConfig(raw: string): Option.Option<ProjectVcsConfigFile> {
|
||||
return decodeProjectVcsConfigJson(raw);
|
||||
function parseConfig(raw: string): ProjectVcsConfigFile | null {
|
||||
try {
|
||||
const parsed = JSON.parse(raw) as unknown;
|
||||
return isProjectVcsConfig(parsed) ? parsed : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
||||
@@ -53,12 +63,12 @@ export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
||||
while (true) {
|
||||
const candidate = path.join(current, ".t3code", "vcs.json");
|
||||
if (yield* fileSystem.exists(candidate).pipe(Effect.orElseSucceed(() => false))) {
|
||||
return Option.some(candidate);
|
||||
return candidate;
|
||||
}
|
||||
|
||||
const parent = path.dirname(current);
|
||||
if (parent === current) {
|
||||
return Option.none<string>();
|
||||
return null;
|
||||
}
|
||||
current = parent;
|
||||
}
|
||||
@@ -68,27 +78,26 @@ export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
||||
configPath: string,
|
||||
) {
|
||||
const raw = yield* fileSystem.readFileString(configPath).pipe(
|
||||
Effect.map(Option.some),
|
||||
Effect.catch((error) =>
|
||||
Effect.logWarning("failed to read VCS project config", {
|
||||
configPath,
|
||||
error,
|
||||
}).pipe(Effect.as(Option.none<string>())),
|
||||
}).pipe(Effect.as(null)),
|
||||
),
|
||||
);
|
||||
if (Option.isNone(raw)) {
|
||||
if (raw === null) {
|
||||
return "auto" as const;
|
||||
}
|
||||
|
||||
const parsed = parseConfig(raw.value);
|
||||
if (Option.isNone(parsed)) {
|
||||
const parsed = parseConfig(raw);
|
||||
if (parsed === null) {
|
||||
yield* Effect.logWarning("invalid VCS project config", {
|
||||
configPath,
|
||||
});
|
||||
return "auto" as const;
|
||||
}
|
||||
|
||||
return configuredKind(parsed.value);
|
||||
return configuredKind(parsed);
|
||||
});
|
||||
|
||||
const resolveKind: VcsProjectConfigShape["resolveKind"] = Effect.fn(
|
||||
@@ -99,10 +108,11 @@ export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
||||
}
|
||||
|
||||
const configPath = yield* findConfigPath(input.cwd);
|
||||
return yield* Option.match(configPath, {
|
||||
onNone: () => Effect.succeed("auto" as const),
|
||||
onSome: readConfiguredKind,
|
||||
});
|
||||
if (configPath === null) {
|
||||
return "auto";
|
||||
}
|
||||
|
||||
return yield* readConfiguredKind(configPath);
|
||||
});
|
||||
|
||||
return VcsProjectConfig.of({
|
||||
|
||||
@@ -727,9 +727,16 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
model: selectedModel,
|
||||
models: selectedProviderModels,
|
||||
prompt,
|
||||
modelOptions: composerModelOptions?.[selectedProvider],
|
||||
modelOptions: composerModelOptions?.[selectedInstanceId],
|
||||
}),
|
||||
[composerModelOptions, prompt, selectedModel, selectedProvider, selectedProviderModels],
|
||||
[
|
||||
composerModelOptions,
|
||||
prompt,
|
||||
selectedInstanceId,
|
||||
selectedModel,
|
||||
selectedProvider,
|
||||
selectedProviderModels,
|
||||
],
|
||||
);
|
||||
|
||||
const selectedPromptEffort = composerProviderState.promptEffort;
|
||||
@@ -1018,21 +1025,23 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
|
||||
const providerTraitsMenuContent = renderProviderTraitsMenuContent({
|
||||
provider: selectedProvider,
|
||||
instanceId: selectedInstanceId,
|
||||
...(routeKind === "server" ? { threadRef: routeThreadRef } : {}),
|
||||
...(routeKind === "draft" && draftId ? { draftId } : {}),
|
||||
model: selectedModel,
|
||||
models: selectedProviderModels,
|
||||
modelOptions: composerModelOptions?.[selectedProvider],
|
||||
modelOptions: composerModelOptions?.[selectedInstanceId],
|
||||
prompt,
|
||||
onPromptChange: setPromptFromTraits,
|
||||
});
|
||||
const providerTraitsPicker = renderProviderTraitsPicker({
|
||||
provider: selectedProvider,
|
||||
instanceId: selectedInstanceId,
|
||||
...(routeKind === "server" ? { threadRef: routeThreadRef } : {}),
|
||||
...(routeKind === "draft" && draftId ? { draftId } : {}),
|
||||
model: selectedModel,
|
||||
models: selectedProviderModels,
|
||||
modelOptions: composerModelOptions?.[selectedProvider],
|
||||
modelOptions: composerModelOptions?.[selectedInstanceId],
|
||||
prompt,
|
||||
onPromptChange: setPromptFromTraits,
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
type ProviderDriverKind,
|
||||
type ProviderInstanceId,
|
||||
type ProviderOptionDescriptor,
|
||||
type ProviderOptionSelection,
|
||||
type ScopedThreadRef,
|
||||
@@ -196,6 +197,7 @@ export function shouldRenderTraitsControls(input: {
|
||||
|
||||
export interface TraitsMenuContentProps {
|
||||
provider: ProviderDriverKind;
|
||||
instanceId?: ProviderInstanceId;
|
||||
models: ReadonlyArray<ServerProviderModel>;
|
||||
model: string | null | undefined;
|
||||
prompt: string;
|
||||
@@ -208,6 +210,7 @@ export interface TraitsMenuContentProps {
|
||||
|
||||
export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
|
||||
provider,
|
||||
instanceId,
|
||||
models,
|
||||
model,
|
||||
prompt,
|
||||
@@ -228,11 +231,12 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
|
||||
return;
|
||||
}
|
||||
setProviderModelOptions(threadTarget, provider, nextOptions, {
|
||||
...(instanceId ? { instanceId } : {}),
|
||||
model,
|
||||
persistSticky: true,
|
||||
});
|
||||
},
|
||||
[model, persistence, provider, setProviderModelOptions],
|
||||
[instanceId, model, persistence, provider, setProviderModelOptions],
|
||||
);
|
||||
const {
|
||||
descriptors,
|
||||
@@ -343,6 +347,7 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
|
||||
|
||||
export const TraitsPicker = memo(function TraitsPicker({
|
||||
provider,
|
||||
instanceId,
|
||||
models,
|
||||
model,
|
||||
prompt,
|
||||
@@ -431,6 +436,7 @@ export const TraitsPicker = memo(function TraitsPicker({
|
||||
<MenuPopup align="start">
|
||||
<TraitsMenuContent
|
||||
provider={provider}
|
||||
{...(instanceId ? { instanceId } : {})}
|
||||
models={models}
|
||||
model={model}
|
||||
prompt={prompt}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
type ProviderDriverKind,
|
||||
type ProviderInstanceId,
|
||||
type ProviderOptionSelection,
|
||||
type ScopedThreadRef,
|
||||
type ServerProviderModel,
|
||||
@@ -35,6 +36,7 @@ export type ComposerProviderState = {
|
||||
|
||||
type TraitsRenderInput = {
|
||||
provider: ProviderDriverKind;
|
||||
instanceId?: ProviderInstanceId;
|
||||
threadRef?: ScopedThreadRef;
|
||||
draftId?: DraftId;
|
||||
model: string;
|
||||
@@ -76,8 +78,17 @@ function renderTraitsControl(
|
||||
Component: typeof TraitsMenuContent | typeof TraitsPicker,
|
||||
input: TraitsRenderInput,
|
||||
): ReactNode {
|
||||
const { provider, threadRef, draftId, model, models, modelOptions, prompt, onPromptChange } =
|
||||
input;
|
||||
const {
|
||||
provider,
|
||||
instanceId,
|
||||
threadRef,
|
||||
draftId,
|
||||
model,
|
||||
models,
|
||||
modelOptions,
|
||||
prompt,
|
||||
onPromptChange,
|
||||
} = input;
|
||||
const hasTarget = threadRef !== undefined || draftId !== undefined;
|
||||
if (
|
||||
!hasTarget ||
|
||||
@@ -88,6 +99,7 @@ function renderTraitsControl(
|
||||
return (
|
||||
<Component
|
||||
provider={provider}
|
||||
{...(instanceId ? { instanceId } : {})}
|
||||
models={models}
|
||||
{...(threadRef ? { threadRef } : {})}
|
||||
{...(draftId ? { draftId } : {})}
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
import { useNavigate } from "@tanstack/react-router";
|
||||
import type { ServerProvider } from "@t3tools/contracts";
|
||||
import { CircleCheckIcon, DownloadIcon, LoaderIcon, TriangleAlertIcon, XIcon } from "lucide-react";
|
||||
import { useCallback, useEffect, useState, type CSSProperties } from "react";
|
||||
import {
|
||||
useCallback,
|
||||
useEffect,
|
||||
useRef,
|
||||
useState,
|
||||
type CSSProperties,
|
||||
type Dispatch,
|
||||
type SetStateAction,
|
||||
type TransitionEvent,
|
||||
} from "react";
|
||||
|
||||
import { useServerProviders } from "../../rpc/serverState";
|
||||
import {
|
||||
@@ -37,48 +46,36 @@ function latestProviderCheckedAt(
|
||||
);
|
||||
}
|
||||
|
||||
export function SidebarProviderUpdatePill() {
|
||||
const navigate = useNavigate();
|
||||
const providers = useServerProviders();
|
||||
const [dismissedKeys, setDismissedKeys] = useState<ReadonlySet<string>>(() => new Set());
|
||||
const [renderedView, setRenderedView] = useState<ProviderUpdateSidebarPillView | null>(null);
|
||||
const [pendingView, setPendingView] = useState<ProviderUpdateSidebarPillView | null>(null);
|
||||
function useProviderUpdateVisibleAfterIso(
|
||||
providers: ReadonlyArray<Pick<ServerProvider, "checkedAt">>,
|
||||
): string | undefined {
|
||||
const visibleAfterIsoRef = useRef<string | undefined>(undefined);
|
||||
|
||||
if (visibleAfterIsoRef.current === undefined) {
|
||||
visibleAfterIsoRef.current = latestProviderCheckedAt(providers);
|
||||
}
|
||||
|
||||
return visibleAfterIsoRef.current;
|
||||
}
|
||||
|
||||
function useDisplayedProviderUpdatePill(input: {
|
||||
view: ProviderUpdateSidebarPillView | null;
|
||||
setDismissedKeys: Dispatch<SetStateAction<ReadonlySet<string>>>;
|
||||
}) {
|
||||
const { view, setDismissedKeys } = input;
|
||||
const [renderedView, setRenderedView] = useState<ProviderUpdateSidebarPillView | null>(view);
|
||||
const [exitingKey, setExitingKey] = useState<string | null>(null);
|
||||
const [dismissAfterExitKey, setDismissAfterExitKey] = useState<string | null>(null);
|
||||
const [visibleAfterIso, setVisibleAfterIso] = useState<string | undefined>();
|
||||
const effectiveVisibleAfterIso = visibleAfterIso ?? latestProviderCheckedAt(providers);
|
||||
const view = getProviderUpdateSidebarPillView(providers, {
|
||||
...(effectiveVisibleAfterIso !== undefined
|
||||
? { visibleAfterIso: effectiveVisibleAfterIso }
|
||||
: {}),
|
||||
dismissedKeys,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (visibleAfterIso === undefined && effectiveVisibleAfterIso !== undefined) {
|
||||
setVisibleAfterIso(effectiveVisibleAfterIso);
|
||||
}
|
||||
}, [effectiveVisibleAfterIso, visibleAfterIso]);
|
||||
|
||||
const openProviderSettings = useCallback(() => {
|
||||
void navigate({ to: "/settings/providers" });
|
||||
}, [navigate]);
|
||||
const displayedView = renderedView ?? view;
|
||||
const dismissAfterVisibleMs = displayedView?.dismissAfterVisibleMs;
|
||||
const viewKey = displayedView?.key ?? null;
|
||||
const showDismissProgress =
|
||||
dismissAfterVisibleMs !== undefined &&
|
||||
displayedView?.tone !== "loading" &&
|
||||
exitingKey !== viewKey;
|
||||
const pendingViewRef = useRef<ProviderUpdateSidebarPillView | null>(null);
|
||||
const dismissAfterExitKeyRef = useRef<string | null>(null);
|
||||
|
||||
const startExit = useCallback(
|
||||
(key: string, nextView: ProviderUpdateSidebarPillView | null, dismissKey?: string) => {
|
||||
if (exitingKey === key) {
|
||||
return;
|
||||
}
|
||||
setPendingView(nextView);
|
||||
pendingViewRef.current = nextView;
|
||||
dismissAfterExitKeyRef.current = dismissKey ?? null;
|
||||
setExitingKey(key);
|
||||
setDismissAfterExitKey(dismissKey ?? null);
|
||||
},
|
||||
[exitingKey],
|
||||
);
|
||||
@@ -103,6 +100,46 @@ export function SidebarProviderUpdatePill() {
|
||||
}
|
||||
}, [exitingKey, renderedView, startExit, view]);
|
||||
|
||||
const displayedView = renderedView ?? view;
|
||||
const onTransitionEnd = useCallback(
|
||||
(event: TransitionEvent<HTMLDivElement>) => {
|
||||
if (event.target !== event.currentTarget) {
|
||||
return;
|
||||
}
|
||||
if (!displayedView || exitingKey !== displayedView.key) {
|
||||
return;
|
||||
}
|
||||
if (dismissAfterExitKeyRef.current === displayedView.key) {
|
||||
setDismissedKeys((previous) => new Set(previous).add(displayedView.key));
|
||||
}
|
||||
setRenderedView(pendingViewRef.current);
|
||||
pendingViewRef.current = null;
|
||||
dismissAfterExitKeyRef.current = null;
|
||||
setExitingKey(null);
|
||||
},
|
||||
[displayedView, exitingKey, setDismissedKeys],
|
||||
);
|
||||
|
||||
return {
|
||||
displayedView,
|
||||
exitingKey,
|
||||
onTransitionEnd,
|
||||
startExit,
|
||||
};
|
||||
}
|
||||
|
||||
function useProviderUpdateAutoDismiss(input: {
|
||||
dismissAfterVisibleMs: number | undefined;
|
||||
exitingKey: string | null;
|
||||
startExit: (
|
||||
key: string,
|
||||
nextView: ProviderUpdateSidebarPillView | null,
|
||||
dismissKey?: string,
|
||||
) => void;
|
||||
viewKey: string | null;
|
||||
}) {
|
||||
const { dismissAfterVisibleMs, exitingKey, startExit, viewKey } = input;
|
||||
|
||||
useEffect(() => {
|
||||
if (!dismissAfterVisibleMs || !viewKey) {
|
||||
return;
|
||||
@@ -116,6 +153,40 @@ export function SidebarProviderUpdatePill() {
|
||||
|
||||
return () => window.clearTimeout(timeoutId);
|
||||
}, [dismissAfterVisibleMs, exitingKey, startExit, viewKey]);
|
||||
}
|
||||
|
||||
export function SidebarProviderUpdatePill() {
|
||||
const navigate = useNavigate();
|
||||
const providers = useServerProviders();
|
||||
const [dismissedKeys, setDismissedKeys] = useState<ReadonlySet<string>>(() => new Set());
|
||||
const effectiveVisibleAfterIso = useProviderUpdateVisibleAfterIso(providers);
|
||||
const view = getProviderUpdateSidebarPillView(providers, {
|
||||
...(effectiveVisibleAfterIso !== undefined
|
||||
? { visibleAfterIso: effectiveVisibleAfterIso }
|
||||
: {}),
|
||||
dismissedKeys,
|
||||
});
|
||||
|
||||
const openProviderSettings = useCallback(() => {
|
||||
void navigate({ to: "/settings/providers" });
|
||||
}, [navigate]);
|
||||
const { displayedView, exitingKey, onTransitionEnd, startExit } = useDisplayedProviderUpdatePill({
|
||||
view,
|
||||
setDismissedKeys,
|
||||
});
|
||||
const dismissAfterVisibleMs = displayedView?.dismissAfterVisibleMs;
|
||||
const viewKey = displayedView?.key ?? null;
|
||||
const showDismissProgress =
|
||||
dismissAfterVisibleMs !== undefined &&
|
||||
displayedView?.tone !== "loading" &&
|
||||
exitingKey !== viewKey;
|
||||
|
||||
useProviderUpdateAutoDismiss({
|
||||
dismissAfterVisibleMs,
|
||||
exitingKey,
|
||||
startExit,
|
||||
viewKey,
|
||||
});
|
||||
|
||||
if (!displayedView) {
|
||||
return null;
|
||||
@@ -130,21 +201,7 @@ export function SidebarProviderUpdatePill() {
|
||||
? "pointer-events-none translate-y-1.5 opacity-0"
|
||||
: "translate-y-0 opacity-100"
|
||||
}`}
|
||||
onTransitionEnd={(event) => {
|
||||
if (event.target !== event.currentTarget) {
|
||||
return;
|
||||
}
|
||||
if (!displayedView || exitingKey !== displayedView.key) {
|
||||
return;
|
||||
}
|
||||
if (dismissAfterExitKey === displayedView.key) {
|
||||
setDismissedKeys((previous) => new Set(previous).add(displayedView.key));
|
||||
}
|
||||
setRenderedView(pendingView);
|
||||
setPendingView(null);
|
||||
setExitingKey(null);
|
||||
setDismissAfterExitKey(null);
|
||||
}}
|
||||
onTransitionEnd={onTransitionEnd}
|
||||
>
|
||||
{showDismissProgress ? (
|
||||
<div
|
||||
|
||||
@@ -21,6 +21,7 @@ import { createModelSelection } from "@t3tools/shared/model";
|
||||
// `stickyModelSelectionByProvider` maps are keyed by `ProviderInstanceId`
|
||||
// in production; these aliases keep the legacy-key migration tests concise.
|
||||
const CODEX_INSTANCE = ProviderInstanceId.make("codex");
|
||||
const CODEX_SECONDARY_INSTANCE = ProviderInstanceId.make("codex_secondary");
|
||||
const CLAUDE_AGENT_INSTANCE = ProviderInstanceId.make("claudeAgent");
|
||||
const CURSOR_INSTANCE = ProviderInstanceId.make("cursor");
|
||||
const CODEX_DRIVER = ProviderDriverKind.make("codex");
|
||||
@@ -1201,6 +1202,43 @@ describe("composerDraftStore modelSelection", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("stores provider option changes on a selected custom instance", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
|
||||
store.setProviderModelOptions(
|
||||
threadRef,
|
||||
CODEX_DRIVER,
|
||||
toSelections({ reasoningEffort: "low" }),
|
||||
{
|
||||
instanceId: CODEX_SECONDARY_INSTANCE,
|
||||
model: "gpt-5-codex",
|
||||
persistSticky: true,
|
||||
},
|
||||
);
|
||||
|
||||
expect(
|
||||
draftFor(threadId, TEST_ENVIRONMENT_ID)?.modelSelectionByProvider[CODEX_SECONDARY_INSTANCE],
|
||||
).toEqual(
|
||||
expect.objectContaining({
|
||||
instanceId: CODEX_SECONDARY_INSTANCE,
|
||||
options: [{ id: "reasoningEffort", value: "low" }],
|
||||
}),
|
||||
);
|
||||
expect(draftFor(threadId, TEST_ENVIRONMENT_ID)?.activeProvider).toBe(CODEX_SECONDARY_INSTANCE);
|
||||
expect(useComposerDraftStore.getState().stickyActiveProvider).toBe(CODEX_SECONDARY_INSTANCE);
|
||||
expect(useComposerDraftStore.getState().stickyModelSelectionByProvider[CODEX_INSTANCE]).toBe(
|
||||
undefined,
|
||||
);
|
||||
expect(
|
||||
useComposerDraftStore.getState().stickyModelSelectionByProvider[CODEX_SECONDARY_INSTANCE],
|
||||
).toEqual(
|
||||
expect.objectContaining({
|
||||
instanceId: CODEX_SECONDARY_INSTANCE,
|
||||
options: [{ id: "reasoningEffort", value: "low" }],
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("updates only the draft when sticky persistence is disabled", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
|
||||
|
||||
@@ -371,6 +371,7 @@ interface ComposerDraftStoreState {
|
||||
provider: ProviderDriverKind,
|
||||
nextProviderOptions: ReadonlyArray<ProviderOptionSelection> | null | undefined,
|
||||
options?: {
|
||||
instanceId?: ProviderInstanceId | null | undefined;
|
||||
model?: string | null | undefined;
|
||||
persistSticky?: boolean;
|
||||
},
|
||||
@@ -2456,7 +2457,7 @@ const composerDraftStore = create<ComposerDraftStoreState>()(
|
||||
if (normalizedProvider === null) {
|
||||
return;
|
||||
}
|
||||
const instanceKey = defaultInstanceIdForDriver(normalizedProvider);
|
||||
const instanceKey = options?.instanceId ?? defaultInstanceIdForDriver(normalizedProvider);
|
||||
const fallbackModel =
|
||||
normalizeModelSlug(options?.model, normalizedProvider) ??
|
||||
DEFAULT_MODEL_BY_PROVIDER[normalizedProvider] ??
|
||||
@@ -2501,7 +2502,9 @@ const composerDraftStore = create<ComposerDraftStoreState>()(
|
||||
const { options: _, ...rest } = stickyBase;
|
||||
nextStickyMap[instanceKey] = rest as ModelSelection;
|
||||
}
|
||||
nextStickyActiveProvider = base.activeProvider ?? instanceKey;
|
||||
nextStickyActiveProvider = options.instanceId
|
||||
? instanceKey
|
||||
: (base.activeProvider ?? instanceKey);
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -2514,6 +2517,7 @@ const composerDraftStore = create<ComposerDraftStoreState>()(
|
||||
|
||||
const nextDraft: ComposerThreadDraftState = {
|
||||
...base,
|
||||
...(options?.instanceId ? { activeProvider: instanceKey } : {}),
|
||||
modelSelectionByProvider: nextMap,
|
||||
};
|
||||
const nextDraftsByThreadKey = { ...state.draftsByThreadKey };
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user