Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0593260f66 | ||
|
|
9e8e6e9abd |
No files matched your search
@@ -41,8 +41,7 @@ describe("VcsProjectConfig", () => {
|
||||
yield* fileSystem.makeDirectory(nested, { recursive: true });
|
||||
yield* fileSystem.writeFileString(
|
||||
path.join(configDir, "vcs.json"),
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify({ vcs: { kind: "jj" } }),
|
||||
'{"vcs":{"kind":"jj"}}',
|
||||
);
|
||||
|
||||
const config = yield* VcsProjectConfig.VcsProjectConfig;
|
||||
@@ -53,6 +52,26 @@ describe("VcsProjectConfig", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it.layer(TestLayer)("ignores malformed .t3code/vcs.json files", (it) => {
|
||||
it.effect("falls back to 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"), "{ not-json");
|
||||
|
||||
const config = yield* VcsProjectConfig.VcsProjectConfig;
|
||||
const kind = yield* config.resolveKind({ cwd: root });
|
||||
|
||||
assert.equal(kind, "auto");
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it.layer(TestLayer)("falls back to auto when no config exists", (it) => {
|
||||
it.effect("returns auto", () =>
|
||||
Effect.gen(function* () {
|
||||
|
||||
@@ -2,6 +2,7 @@ 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";
|
||||
|
||||
@@ -15,16 +16,10 @@ const ProjectVcsConfig = Schema.Struct({
|
||||
),
|
||||
vcsKind: Schema.optional(VcsDriverKind),
|
||||
});
|
||||
const isProjectVcsConfig = Schema.is(ProjectVcsConfig);
|
||||
const ProjectVcsConfigJson = Schema.fromJsonString(ProjectVcsConfig);
|
||||
const decodeProjectVcsConfig = Schema.decodeUnknownOption(ProjectVcsConfigJson);
|
||||
|
||||
interface ProjectVcsConfigFile {
|
||||
readonly vcs?:
|
||||
| {
|
||||
readonly kind?: VcsDriverKindType | undefined;
|
||||
}
|
||||
| undefined;
|
||||
readonly vcsKind?: VcsDriverKindType | undefined;
|
||||
}
|
||||
type ProjectVcsConfigFile = Schema.Schema.Type<typeof ProjectVcsConfig>;
|
||||
|
||||
export interface VcsProjectConfigResolveInput {
|
||||
readonly cwd: string;
|
||||
@@ -45,13 +40,8 @@ function configuredKind(config: ProjectVcsConfigFile): VcsDriverKindType | "auto
|
||||
return config.vcs?.kind ?? config.vcsKind ?? "auto";
|
||||
}
|
||||
|
||||
function parseConfig(raw: string): ProjectVcsConfigFile | null {
|
||||
try {
|
||||
const parsed = JSON.parse(raw) as unknown;
|
||||
return isProjectVcsConfig(parsed) ? parsed : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
function parseConfig(raw: string): Option.Option<ProjectVcsConfigFile> {
|
||||
return decodeProjectVcsConfig(raw);
|
||||
}
|
||||
|
||||
export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
||||
@@ -63,12 +53,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 candidate;
|
||||
return Option.some(candidate);
|
||||
}
|
||||
|
||||
const parent = path.dirname(current);
|
||||
if (parent === current) {
|
||||
return null;
|
||||
return Option.none<string>();
|
||||
}
|
||||
current = parent;
|
||||
}
|
||||
@@ -78,26 +68,27 @@ 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(null)),
|
||||
}).pipe(Effect.as(Option.none<string>())),
|
||||
),
|
||||
);
|
||||
if (raw === null) {
|
||||
if (Option.isNone(raw)) {
|
||||
return "auto" as const;
|
||||
}
|
||||
|
||||
const parsed = parseConfig(raw);
|
||||
if (parsed === null) {
|
||||
const parsed = parseConfig(raw.value);
|
||||
if (Option.isNone(parsed)) {
|
||||
yield* Effect.logWarning("invalid VCS project config", {
|
||||
configPath,
|
||||
});
|
||||
return "auto" as const;
|
||||
}
|
||||
|
||||
return configuredKind(parsed);
|
||||
return configuredKind(parsed.value);
|
||||
});
|
||||
|
||||
const resolveKind: VcsProjectConfigShape["resolveKind"] = Effect.fn(
|
||||
@@ -108,11 +99,11 @@ export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
||||
}
|
||||
|
||||
const configPath = yield* findConfigPath(input.cwd);
|
||||
if (configPath === null) {
|
||||
if (Option.isNone(configPath)) {
|
||||
return "auto";
|
||||
}
|
||||
|
||||
return yield* readConfiguredKind(configPath);
|
||||
return yield* readConfiguredKind(configPath.value);
|
||||
});
|
||||
|
||||
return VcsProjectConfig.of({
|
||||
|
||||
@@ -29,7 +29,7 @@ import {
|
||||
} from "../Services/WorkspaceEntries.ts";
|
||||
import { WorkspacePaths } from "../Services/WorkspacePaths.ts";
|
||||
|
||||
const WORKSPACE_CACHE_TTL_MS = 15_000;
|
||||
const WORKSPACE_CACHE_TTL = Duration.seconds(15);
|
||||
const WORKSPACE_CACHE_MAX_KEYS = 4;
|
||||
const WORKSPACE_INDEX_MAX_ENTRIES = 25_000;
|
||||
const WORKSPACE_SCAN_READDIR_CONCURRENCY = 32;
|
||||
@@ -402,8 +402,7 @@ export const makeWorkspaceEntries = Effect.gen(function* () {
|
||||
buildWorkspaceIndex,
|
||||
{
|
||||
capacity: WORKSPACE_CACHE_MAX_KEYS,
|
||||
timeToLive: (exit) =>
|
||||
Exit.isSuccess(exit) ? Duration.millis(WORKSPACE_CACHE_TTL_MS) : Duration.zero,
|
||||
timeToLive: (exit) => (Exit.isSuccess(exit) ? WORKSPACE_CACHE_TTL : Duration.zero),
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -727,16 +727,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
model: selectedModel,
|
||||
models: selectedProviderModels,
|
||||
prompt,
|
||||
modelOptions: composerModelOptions?.[selectedInstanceId],
|
||||
modelOptions: composerModelOptions?.[selectedProvider],
|
||||
}),
|
||||
[
|
||||
composerModelOptions,
|
||||
prompt,
|
||||
selectedInstanceId,
|
||||
selectedModel,
|
||||
selectedProvider,
|
||||
selectedProviderModels,
|
||||
],
|
||||
[composerModelOptions, prompt, selectedModel, selectedProvider, selectedProviderModels],
|
||||
);
|
||||
|
||||
const selectedPromptEffort = composerProviderState.promptEffort;
|
||||
@@ -1025,23 +1018,21 @@ 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?.[selectedInstanceId],
|
||||
modelOptions: composerModelOptions?.[selectedProvider],
|
||||
prompt,
|
||||
onPromptChange: setPromptFromTraits,
|
||||
});
|
||||
const providerTraitsPicker = renderProviderTraitsPicker({
|
||||
provider: selectedProvider,
|
||||
instanceId: selectedInstanceId,
|
||||
...(routeKind === "server" ? { threadRef: routeThreadRef } : {}),
|
||||
...(routeKind === "draft" && draftId ? { draftId } : {}),
|
||||
model: selectedModel,
|
||||
models: selectedProviderModels,
|
||||
modelOptions: composerModelOptions?.[selectedInstanceId],
|
||||
modelOptions: composerModelOptions?.[selectedProvider],
|
||||
prompt,
|
||||
onPromptChange: setPromptFromTraits,
|
||||
});
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {
|
||||
type ProviderDriverKind,
|
||||
type ProviderInstanceId,
|
||||
type ProviderOptionDescriptor,
|
||||
type ProviderOptionSelection,
|
||||
type ScopedThreadRef,
|
||||
@@ -197,7 +196,6 @@ export function shouldRenderTraitsControls(input: {
|
||||
|
||||
export interface TraitsMenuContentProps {
|
||||
provider: ProviderDriverKind;
|
||||
instanceId?: ProviderInstanceId;
|
||||
models: ReadonlyArray<ServerProviderModel>;
|
||||
model: string | null | undefined;
|
||||
prompt: string;
|
||||
@@ -210,7 +208,6 @@ export interface TraitsMenuContentProps {
|
||||
|
||||
export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
|
||||
provider,
|
||||
instanceId,
|
||||
models,
|
||||
model,
|
||||
prompt,
|
||||
@@ -231,12 +228,11 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
|
||||
return;
|
||||
}
|
||||
setProviderModelOptions(threadTarget, provider, nextOptions, {
|
||||
...(instanceId ? { instanceId } : {}),
|
||||
model,
|
||||
persistSticky: true,
|
||||
});
|
||||
},
|
||||
[instanceId, model, persistence, provider, setProviderModelOptions],
|
||||
[model, persistence, provider, setProviderModelOptions],
|
||||
);
|
||||
const {
|
||||
descriptors,
|
||||
@@ -347,7 +343,6 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
|
||||
|
||||
export const TraitsPicker = memo(function TraitsPicker({
|
||||
provider,
|
||||
instanceId,
|
||||
models,
|
||||
model,
|
||||
prompt,
|
||||
@@ -436,7 +431,6 @@ export const TraitsPicker = memo(function TraitsPicker({
|
||||
<MenuPopup align="start">
|
||||
<TraitsMenuContent
|
||||
provider={provider}
|
||||
{...(instanceId ? { instanceId } : {})}
|
||||
models={models}
|
||||
model={model}
|
||||
prompt={prompt}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {
|
||||
type ProviderDriverKind,
|
||||
type ProviderInstanceId,
|
||||
type ProviderOptionSelection,
|
||||
type ScopedThreadRef,
|
||||
type ServerProviderModel,
|
||||
@@ -36,7 +35,6 @@ export type ComposerProviderState = {
|
||||
|
||||
type TraitsRenderInput = {
|
||||
provider: ProviderDriverKind;
|
||||
instanceId?: ProviderInstanceId;
|
||||
threadRef?: ScopedThreadRef;
|
||||
draftId?: DraftId;
|
||||
model: string;
|
||||
@@ -78,17 +76,8 @@ function renderTraitsControl(
|
||||
Component: typeof TraitsMenuContent | typeof TraitsPicker,
|
||||
input: TraitsRenderInput,
|
||||
): ReactNode {
|
||||
const {
|
||||
provider,
|
||||
instanceId,
|
||||
threadRef,
|
||||
draftId,
|
||||
model,
|
||||
models,
|
||||
modelOptions,
|
||||
prompt,
|
||||
onPromptChange,
|
||||
} = input;
|
||||
const { provider, threadRef, draftId, model, models, modelOptions, prompt, onPromptChange } =
|
||||
input;
|
||||
const hasTarget = threadRef !== undefined || draftId !== undefined;
|
||||
if (
|
||||
!hasTarget ||
|
||||
@@ -99,7 +88,6 @@ function renderTraitsControl(
|
||||
return (
|
||||
<Component
|
||||
provider={provider}
|
||||
{...(instanceId ? { instanceId } : {})}
|
||||
models={models}
|
||||
{...(threadRef ? { threadRef } : {})}
|
||||
{...(draftId ? { draftId } : {})}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { CheckIcon } from "lucide-react";
|
||||
import { Radio as RadioPrimitive } from "@base-ui/react/radio";
|
||||
import { useCallback, useMemo, useState } from "react";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import {
|
||||
ProviderInstanceId,
|
||||
ProviderDriverKind,
|
||||
@@ -121,7 +121,7 @@ export function AddProviderInstanceDialog({ open, onOpenChange }: AddProviderIns
|
||||
const [driver, setDriver] = useState<ProviderDriverKind>(DEFAULT_DRIVER_KIND);
|
||||
const [label, setLabel] = useState("");
|
||||
const [accentColor, setAccentColor] = useState<string>("");
|
||||
const [customInstanceId, setCustomInstanceId] = useState("");
|
||||
const [instanceId, setInstanceId] = useState("");
|
||||
const [instanceIdDirty, setInstanceIdDirty] = useState(false);
|
||||
// Driver-specific config drafts keyed by driver so toggling between drivers
|
||||
// during the same dialog session does not lose in-progress input.
|
||||
@@ -134,7 +134,27 @@ export function AddProviderInstanceDialog({ open, onOpenChange }: AddProviderIns
|
||||
() => new Set(Object.keys(settings.providerInstances ?? {})),
|
||||
[settings.providerInstances],
|
||||
);
|
||||
const instanceId = instanceIdDirty ? customInstanceId : deriveInstanceId(driver, label);
|
||||
|
||||
// Reset the form every time the dialog opens so each creation starts
|
||||
// from a clean slate.
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
setDriver(DEFAULT_DRIVER_KIND);
|
||||
setLabel("");
|
||||
setAccentColor("");
|
||||
setInstanceId("");
|
||||
setWizardStep(0);
|
||||
setInstanceIdDirty(false);
|
||||
setConfigByDriver({});
|
||||
setHasAttemptedSubmit(false);
|
||||
}, [open]);
|
||||
|
||||
// Auto-derive the instance id from driver + label until the user types
|
||||
// in the Instance ID field directly (after which they own its value).
|
||||
useEffect(() => {
|
||||
if (instanceIdDirty) return;
|
||||
setInstanceId(deriveInstanceId(driver, label));
|
||||
}, [driver, label, instanceIdDirty]);
|
||||
|
||||
const driverOption = DRIVER_OPTION_BY_VALUE[driver] ?? DEFAULT_DRIVER_OPTION;
|
||||
const driverSettingsFields = useMemo(
|
||||
@@ -360,7 +380,7 @@ export function AddProviderInstanceDialog({ open, onOpenChange }: AddProviderIns
|
||||
value={instanceId}
|
||||
onChange={(event) => {
|
||||
setInstanceIdDirty(true);
|
||||
setCustomInstanceId(event.target.value);
|
||||
setInstanceId(event.target.value);
|
||||
}}
|
||||
aria-invalid={showInstanceIdError}
|
||||
/>
|
||||
|
||||
@@ -920,15 +920,10 @@ export function ProviderSettingsPanel() {
|
||||
const serverProviders = useServerProviders();
|
||||
const [isRefreshingProviders, setIsRefreshingProviders] = useState(false);
|
||||
const [isAddInstanceDialogOpen, setIsAddInstanceDialogOpen] = useState(false);
|
||||
const [addInstanceDialogSession, setAddInstanceDialogSession] = useState(0);
|
||||
const [updatingProviderDrivers, setUpdatingProviderDrivers] = useState<
|
||||
ReadonlySet<ProviderDriverKind>
|
||||
>(() => new Set());
|
||||
const [openInstanceDetails, setOpenInstanceDetails] = useState<Record<string, boolean>>({});
|
||||
const openAddInstanceDialog = useCallback(() => {
|
||||
setAddInstanceDialogSession((session) => session + 1);
|
||||
setIsAddInstanceDialogOpen(true);
|
||||
}, []);
|
||||
const refreshingRef = useRef(false);
|
||||
|
||||
const providerUpdateCandidates = useMemo(
|
||||
@@ -1195,7 +1190,7 @@ export function ProviderSettingsPanel() {
|
||||
size="icon-xs"
|
||||
variant="ghost"
|
||||
className="size-5 rounded-sm p-0 text-muted-foreground hover:text-foreground"
|
||||
onClick={openAddInstanceDialog}
|
||||
onClick={() => setIsAddInstanceDialogOpen(true)}
|
||||
aria-label="Add provider instance"
|
||||
>
|
||||
<PlusIcon className="size-3" />
|
||||
@@ -1329,7 +1324,6 @@ export function ProviderSettingsPanel() {
|
||||
</SettingsSection>
|
||||
|
||||
<AddProviderInstanceDialog
|
||||
key={addInstanceDialogSession}
|
||||
open={isAddInstanceDialogOpen}
|
||||
onOpenChange={setIsAddInstanceDialogOpen}
|
||||
/>
|
||||
|
||||
@@ -21,7 +21,6 @@ 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");
|
||||
@@ -1202,43 +1201,6 @@ 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,7 +371,6 @@ interface ComposerDraftStoreState {
|
||||
provider: ProviderDriverKind,
|
||||
nextProviderOptions: ReadonlyArray<ProviderOptionSelection> | null | undefined,
|
||||
options?: {
|
||||
instanceId?: ProviderInstanceId | null | undefined;
|
||||
model?: string | null | undefined;
|
||||
persistSticky?: boolean;
|
||||
},
|
||||
@@ -2457,7 +2456,7 @@ const composerDraftStore = create<ComposerDraftStoreState>()(
|
||||
if (normalizedProvider === null) {
|
||||
return;
|
||||
}
|
||||
const instanceKey = options?.instanceId ?? defaultInstanceIdForDriver(normalizedProvider);
|
||||
const instanceKey = defaultInstanceIdForDriver(normalizedProvider);
|
||||
const fallbackModel =
|
||||
normalizeModelSlug(options?.model, normalizedProvider) ??
|
||||
DEFAULT_MODEL_BY_PROVIDER[normalizedProvider] ??
|
||||
@@ -2502,9 +2501,7 @@ const composerDraftStore = create<ComposerDraftStoreState>()(
|
||||
const { options: _, ...rest } = stickyBase;
|
||||
nextStickyMap[instanceKey] = rest as ModelSelection;
|
||||
}
|
||||
nextStickyActiveProvider = options.instanceId
|
||||
? instanceKey
|
||||
: (base.activeProvider ?? instanceKey);
|
||||
nextStickyActiveProvider = base.activeProvider ?? instanceKey;
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -2517,7 +2514,6 @@ 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