Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f6f1b9c4a3 | ||
|
|
d283d94ad3 | ||
|
|
63a9c85c26 | ||
|
|
4f0f24f055 |
No files matched your search
@@ -25,7 +25,6 @@ import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Schema from "effect/Schema";
|
||||
import { HttpClient } from "effect/unstable/http";
|
||||
import { ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
@@ -76,8 +75,6 @@ export interface DesktopSshEnvironmentLayerOptions {
|
||||
readonly resolveCliRunner?: Effect.Effect<RemoteT3RunnerOptions>;
|
||||
}
|
||||
|
||||
const isSshPasswordPromptError = Schema.is(SshPasswordPromptError);
|
||||
|
||||
function discoverDesktopSshHostsEffect(input?: { readonly homeDir?: string }) {
|
||||
return discoverSshHosts(input ?? {});
|
||||
}
|
||||
@@ -86,7 +83,7 @@ export function isDesktopSshPasswordPromptCancellation(
|
||||
error: unknown,
|
||||
): error is SshPasswordPromptError {
|
||||
return (
|
||||
isSshPasswordPromptError(error) &&
|
||||
error instanceof SshPasswordPromptError &&
|
||||
DesktopSshPasswordPrompts.isDesktopSshPasswordPromptCancellation(error.cause)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,13 +2,10 @@ import { assert, describe, it } from "@effect/vitest";
|
||||
import { SshHttpBridgeError } from "@t3tools/ssh/errors";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Schema from "effect/Schema";
|
||||
import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/unstable/http";
|
||||
|
||||
import * as DesktopSshRemoteApi from "./DesktopSshRemoteApi.ts";
|
||||
|
||||
const isSshHttpBridgeError = Schema.is(SshHttpBridgeError);
|
||||
|
||||
function jsonResponse(request: HttpClientRequest.HttpClientRequest, body: unknown, status = 200) {
|
||||
return HttpClientResponse.fromWeb(
|
||||
request,
|
||||
@@ -76,7 +73,7 @@ describe("DesktopSshRemoteApi", () => {
|
||||
|
||||
assert.instanceOf(error, DesktopSshRemoteApi.DesktopSshRemoteApiError);
|
||||
assert.equal(error.operation, "fetch-environment-descriptor");
|
||||
assert.equal(isSshHttpBridgeError(error.cause), false);
|
||||
assert.equal(error.cause instanceof SshHttpBridgeError, false);
|
||||
}).pipe(Effect.provide(layer));
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
import fsPromises from "node:fs/promises";
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { it, afterEach, describe, expect, vi } from "@effect/vitest";
|
||||
import { assert, describe, expect, it } from "@effect/vitest";
|
||||
import * as Deferred from "effect/Deferred";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Fiber from "effect/Fiber";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
@@ -13,7 +13,7 @@ import { ServerConfig } from "../../config.ts";
|
||||
import * as VcsDriverRegistry from "../../vcs/VcsDriverRegistry.ts";
|
||||
import * as VcsProcess from "../../vcs/VcsProcess.ts";
|
||||
import { WorkspaceEntries } from "../Services/WorkspaceEntries.ts";
|
||||
import { WorkspaceEntriesLive } from "./WorkspaceEntries.ts";
|
||||
import { makeWorkspaceEntries, WorkspaceEntriesLive } from "./WorkspaceEntries.ts";
|
||||
import { WorkspacePathsLive } from "./WorkspacePaths.ts";
|
||||
|
||||
const TestLayer = Layer.empty.pipe(
|
||||
@@ -29,6 +29,28 @@ const TestLayer = Layer.empty.pipe(
|
||||
Layer.provideMerge(NodeServices.layer),
|
||||
);
|
||||
|
||||
const makeWorkspaceEntriesWithFileSystem = (
|
||||
makeFileSystem: (fileSystem: FileSystem.FileSystem) => FileSystem.FileSystem,
|
||||
) =>
|
||||
Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
return yield* makeWorkspaceEntries.pipe(
|
||||
Effect.provideService(FileSystem.FileSystem, makeFileSystem(fileSystem)),
|
||||
);
|
||||
});
|
||||
|
||||
const makeWorkspaceEntriesWithReadDirectory = (
|
||||
onReadDirectory: (
|
||||
path: string,
|
||||
run: () => Effect.Effect<Array<string>, PlatformError.PlatformError>,
|
||||
) => Effect.Effect<Array<string>, PlatformError.PlatformError>,
|
||||
) =>
|
||||
makeWorkspaceEntriesWithFileSystem((fileSystem) => ({
|
||||
...fileSystem,
|
||||
readDirectory: (inputPath, options) =>
|
||||
onReadDirectory(inputPath, () => fileSystem.readDirectory(inputPath, options)),
|
||||
}));
|
||||
|
||||
const makeTempDir = Effect.fn(function* (opts?: { prefix?: string; git?: boolean }) {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const dir = yield* fileSystem.makeTempDirectoryScoped({
|
||||
@@ -80,10 +102,6 @@ const appendSeparator = (input: string) =>
|
||||
: `${input}${process.platform === "win32" ? "\\" : "/"}`;
|
||||
|
||||
it.layer(TestLayer)("WorkspaceEntriesLive", (it) => {
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe("search", () => {
|
||||
it.effect("returns files and directories relative to cwd", () =>
|
||||
Effect.gen(function* () {
|
||||
@@ -227,26 +245,22 @@ it.layer(TestLayer)("WorkspaceEntriesLive", (it) => {
|
||||
yield* writeTextFile(cwd, "src/components/Composer.tsx");
|
||||
|
||||
let rootReadCount = 0;
|
||||
let releaseRootRead: (() => void) | undefined;
|
||||
const rootReadGate = new Promise<void>((resolve) => {
|
||||
releaseRootRead = resolve;
|
||||
});
|
||||
const originalReaddir = fsPromises.readdir.bind(fsPromises);
|
||||
vi.spyOn(fsPromises, "readdir").mockImplementation((async (
|
||||
...args: Parameters<typeof fsPromises.readdir>
|
||||
) => {
|
||||
if (args[0] === cwd) {
|
||||
rootReadCount += 1;
|
||||
await rootReadGate;
|
||||
}
|
||||
return originalReaddir(...args);
|
||||
}) as typeof fsPromises.readdir);
|
||||
const rootReadGate = yield* Deferred.make<void>();
|
||||
const workspaceEntries = yield* makeWorkspaceEntriesWithReadDirectory((inputPath, run) =>
|
||||
inputPath === cwd
|
||||
? Effect.gen(function* () {
|
||||
rootReadCount += 1;
|
||||
yield* Deferred.await(rootReadGate);
|
||||
return yield* run();
|
||||
})
|
||||
: run(),
|
||||
);
|
||||
|
||||
const searches = yield* Effect.all(
|
||||
[
|
||||
searchWorkspaceEntries({ cwd, query: "", limit: 100 }),
|
||||
searchWorkspaceEntries({ cwd, query: "comp", limit: 100 }),
|
||||
searchWorkspaceEntries({ cwd, query: "src", limit: 100 }),
|
||||
workspaceEntries.search({ cwd, query: "", limit: 100 }),
|
||||
workspaceEntries.search({ cwd, query: "comp", limit: 100 }),
|
||||
workspaceEntries.search({ cwd, query: "src", limit: 100 }),
|
||||
],
|
||||
{ concurrency: "unbounded" },
|
||||
).pipe(Effect.forkScoped);
|
||||
@@ -256,10 +270,10 @@ it.layer(TestLayer)("WorkspaceEntriesLive", (it) => {
|
||||
}
|
||||
yield* Effect.yieldNow;
|
||||
}
|
||||
releaseRootRead?.();
|
||||
yield* Deferred.succeed(rootReadGate, undefined);
|
||||
yield* Fiber.join(searches);
|
||||
|
||||
expect(rootReadCount).toBe(1);
|
||||
assert.equal(rootReadCount, 1);
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -274,41 +288,37 @@ it.layer(TestLayer)("WorkspaceEntriesLive", (it) => {
|
||||
|
||||
let activeReads = 0;
|
||||
let peakReads = 0;
|
||||
let releaseReads: (() => void) | undefined;
|
||||
const readsGate = new Promise<void>((resolve) => {
|
||||
releaseReads = resolve;
|
||||
});
|
||||
const originalReaddir = fsPromises.readdir.bind(fsPromises);
|
||||
vi.spyOn(fsPromises, "readdir").mockImplementation((async (
|
||||
...args: Parameters<typeof fsPromises.readdir>
|
||||
) => {
|
||||
const target = args[0];
|
||||
if (typeof target === "string" && target.startsWith(cwd)) {
|
||||
activeReads += 1;
|
||||
peakReads = Math.max(peakReads, activeReads);
|
||||
await readsGate;
|
||||
try {
|
||||
return await originalReaddir(...args);
|
||||
} finally {
|
||||
activeReads -= 1;
|
||||
}
|
||||
}
|
||||
return originalReaddir(...args);
|
||||
}) as typeof fsPromises.readdir);
|
||||
|
||||
const search = yield* searchWorkspaceEntries({ cwd, query: "", limit: 200 }).pipe(
|
||||
Effect.forkScoped,
|
||||
const readsGate = yield* Deferred.make<void>();
|
||||
const workspaceEntries = yield* makeWorkspaceEntriesWithReadDirectory((inputPath, run) =>
|
||||
inputPath !== cwd && inputPath.startsWith(cwd)
|
||||
? Effect.gen(function* () {
|
||||
activeReads += 1;
|
||||
peakReads = Math.max(peakReads, activeReads);
|
||||
yield* Deferred.await(readsGate);
|
||||
return yield* run().pipe(
|
||||
Effect.ensuring(
|
||||
Effect.sync(() => {
|
||||
activeReads -= 1;
|
||||
}),
|
||||
),
|
||||
);
|
||||
})
|
||||
: run(),
|
||||
);
|
||||
|
||||
const search = yield* workspaceEntries
|
||||
.search({ cwd, query: "", limit: 200 })
|
||||
.pipe(Effect.forkScoped);
|
||||
for (let attempt = 0; attempt < 50; attempt += 1) {
|
||||
if (activeReads > 0) {
|
||||
break;
|
||||
}
|
||||
yield* Effect.yieldNow;
|
||||
}
|
||||
releaseReads?.();
|
||||
yield* Deferred.succeed(readsGate, undefined);
|
||||
yield* Fiber.join(search);
|
||||
|
||||
expect(peakReads).toBeLessThanOrEqual(32);
|
||||
assert.isAtMost(peakReads, 32);
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
import * as OS from "node:os";
|
||||
import fsPromises from "node:fs/promises";
|
||||
import type { Dirent } from "node:fs";
|
||||
|
||||
import * as Cache from "effect/Cache";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Exit from "effect/Exit";
|
||||
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 { type FilesystemBrowseInput, type ProjectEntry } from "@t3tools/contracts";
|
||||
@@ -56,6 +56,11 @@ interface SearchableWorkspaceEntry extends ProjectEntry {
|
||||
normalizedName: string;
|
||||
}
|
||||
|
||||
interface DirectoryEntry {
|
||||
readonly name: string;
|
||||
readonly kind: ProjectEntry["kind"];
|
||||
}
|
||||
|
||||
type RankedWorkspaceEntry = RankedSearchResult<SearchableWorkspaceEntry>;
|
||||
|
||||
function toPosixPath(input: string): string {
|
||||
@@ -180,6 +185,7 @@ const resolveBrowseTarget = (
|
||||
});
|
||||
|
||||
export const makeWorkspaceEntries = Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const vcsRegistry = yield* VcsDriverRegistry;
|
||||
const workspacePaths = yield* WorkspacePaths;
|
||||
@@ -269,30 +275,64 @@ export const makeWorkspaceEntries = Effect.gen(function* () {
|
||||
},
|
||||
);
|
||||
|
||||
const readDirectoryEntry = Effect.fn("WorkspaceEntries.readDirectoryEntry")(function* (
|
||||
absoluteDir: string,
|
||||
name: string,
|
||||
): Effect.fn.Return<Option.Option<DirectoryEntry>, never> {
|
||||
const absolutePath = path.join(absoluteDir, name);
|
||||
const linkTarget = yield* fileSystem.readLink(absolutePath).pipe(Effect.option);
|
||||
if (Option.isSome(linkTarget)) {
|
||||
return Option.none();
|
||||
}
|
||||
|
||||
return yield* fileSystem.stat(absolutePath).pipe(
|
||||
Effect.map((info) =>
|
||||
info.type === "Directory"
|
||||
? Option.some({ name, kind: "directory" as const })
|
||||
: info.type === "File"
|
||||
? Option.some({ name, kind: "file" as const })
|
||||
: Option.none<DirectoryEntry>(),
|
||||
),
|
||||
Effect.catch(() => Effect.succeed(Option.none<DirectoryEntry>())),
|
||||
);
|
||||
});
|
||||
|
||||
const readDirectoryEntries = Effect.fn("WorkspaceEntries.readDirectoryEntries")(function* (
|
||||
cwd: string,
|
||||
relativeDir: string,
|
||||
): Effect.fn.Return<
|
||||
{ readonly relativeDir: string; readonly dirents: Dirent[] | null },
|
||||
{
|
||||
readonly relativeDir: string;
|
||||
readonly entries: Option.Option<ReadonlyArray<DirectoryEntry>>;
|
||||
},
|
||||
WorkspaceEntriesError
|
||||
> {
|
||||
return yield* Effect.tryPromise({
|
||||
try: async () => {
|
||||
const absoluteDir = relativeDir ? path.join(cwd, relativeDir) : cwd;
|
||||
const dirents = await fsPromises.readdir(absoluteDir, { withFileTypes: true });
|
||||
return { relativeDir, dirents };
|
||||
},
|
||||
catch: (cause) =>
|
||||
new WorkspaceEntriesError({
|
||||
cwd,
|
||||
operation: "workspaceEntries.readDirectoryEntries",
|
||||
detail: cause instanceof Error ? cause.message : String(cause),
|
||||
cause,
|
||||
}),
|
||||
}).pipe(
|
||||
const absoluteDir = relativeDir ? path.join(cwd, relativeDir) : cwd;
|
||||
return yield* fileSystem.readDirectory(absoluteDir).pipe(
|
||||
Effect.flatMap((names) =>
|
||||
Effect.forEach(
|
||||
names.toSorted((left, right) => left.localeCompare(right)),
|
||||
(name) => readDirectoryEntry(absoluteDir, name),
|
||||
{ concurrency: "unbounded" },
|
||||
),
|
||||
),
|
||||
Effect.map((entries) => ({
|
||||
relativeDir,
|
||||
entries: Option.some(entries.filter(Option.isSome).map((entry) => entry.value)),
|
||||
})),
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new WorkspaceEntriesError({
|
||||
cwd,
|
||||
operation: "workspaceEntries.readDirectoryEntries",
|
||||
detail: cause.message,
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
Effect.catchIf(
|
||||
() => relativeDir.length > 0,
|
||||
() => Effect.succeed({ relativeDir, dirents: null }),
|
||||
() =>
|
||||
Effect.succeed({ relativeDir, entries: Option.none<ReadonlyArray<DirectoryEntry>>() }),
|
||||
),
|
||||
);
|
||||
});
|
||||
@@ -317,29 +357,26 @@ export const makeWorkspaceEntries = Effect.gen(function* () {
|
||||
);
|
||||
|
||||
const candidateEntriesByDirectory = directoryEntries.map((directoryEntry) => {
|
||||
const { relativeDir, dirents } = directoryEntry;
|
||||
if (!dirents) return [] as Array<{ dirent: Dirent; relativePath: string }>;
|
||||
const { relativeDir, entries } = directoryEntry;
|
||||
if (Option.isNone(entries))
|
||||
return [] as Array<{ entry: DirectoryEntry; relativePath: string }>;
|
||||
|
||||
dirents.sort((left, right) => left.name.localeCompare(right.name));
|
||||
const candidates: Array<{ dirent: Dirent; relativePath: string }> = [];
|
||||
for (const dirent of dirents) {
|
||||
if (!dirent.name || dirent.name === "." || dirent.name === "..") {
|
||||
const candidates: Array<{ entry: DirectoryEntry; relativePath: string }> = [];
|
||||
for (const entry of entries.value) {
|
||||
if (!entry.name || entry.name === "." || entry.name === "..") {
|
||||
continue;
|
||||
}
|
||||
if (dirent.isDirectory() && IGNORED_DIRECTORY_NAMES.has(dirent.name)) {
|
||||
continue;
|
||||
}
|
||||
if (!dirent.isDirectory() && !dirent.isFile()) {
|
||||
if (entry.kind === "directory" && IGNORED_DIRECTORY_NAMES.has(entry.name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const relativePath = toPosixPath(
|
||||
relativeDir ? path.join(relativeDir, dirent.name) : dirent.name,
|
||||
relativeDir ? path.join(relativeDir, entry.name) : entry.name,
|
||||
);
|
||||
if (isPathInIgnoredDirectory(relativePath)) {
|
||||
continue;
|
||||
}
|
||||
candidates.push({ dirent, relativePath });
|
||||
candidates.push({ entry, relativePath });
|
||||
}
|
||||
return candidates;
|
||||
});
|
||||
@@ -359,12 +396,12 @@ export const makeWorkspaceEntries = Effect.gen(function* () {
|
||||
|
||||
const entry = toSearchableWorkspaceEntry({
|
||||
path: candidate.relativePath,
|
||||
kind: candidate.dirent.isDirectory() ? "directory" : "file",
|
||||
kind: candidate.entry.kind,
|
||||
parentPath: parentPathOf(candidate.relativePath),
|
||||
});
|
||||
entries.push(entry);
|
||||
|
||||
if (candidate.dirent.isDirectory()) {
|
||||
if (candidate.entry.kind === "directory") {
|
||||
pendingDirectories.push(candidate.relativePath);
|
||||
}
|
||||
|
||||
@@ -442,33 +479,40 @@ export const makeWorkspaceEntries = Effect.gen(function* () {
|
||||
const parentPath = endsWithSeparator ? resolvedInputPath : path.dirname(resolvedInputPath);
|
||||
const prefix = endsWithSeparator ? "" : path.basename(resolvedInputPath);
|
||||
|
||||
const dirents = yield* Effect.tryPromise({
|
||||
try: () => fsPromises.readdir(parentPath, { withFileTypes: true }),
|
||||
catch: (cause) =>
|
||||
new WorkspaceEntriesBrowseError({
|
||||
cwd: input.cwd,
|
||||
partialPath: input.partialPath,
|
||||
operation: "workspaceEntries.browse.readDirectory",
|
||||
detail: `Unable to browse '${parentPath}': ${cause instanceof Error ? cause.message : String(cause)}`,
|
||||
cause,
|
||||
const entries = yield* fileSystem.readDirectory(parentPath).pipe(
|
||||
Effect.flatMap((names) =>
|
||||
Effect.forEach(names, (name) => readDirectoryEntry(parentPath, name), {
|
||||
concurrency: "unbounded",
|
||||
}),
|
||||
});
|
||||
),
|
||||
Effect.map((entries) => entries.filter(Option.isSome).map((entry) => entry.value)),
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new WorkspaceEntriesBrowseError({
|
||||
cwd: input.cwd,
|
||||
partialPath: input.partialPath,
|
||||
operation: "workspaceEntries.browse.readDirectory",
|
||||
detail: `Unable to browse '${parentPath}': ${cause.message}`,
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
const showHidden = endsWithSeparator || prefix.startsWith(".");
|
||||
const lowerPrefix = prefix.toLowerCase();
|
||||
|
||||
return {
|
||||
parentPath,
|
||||
entries: dirents
|
||||
entries: entries
|
||||
.filter(
|
||||
(dirent) =>
|
||||
dirent.isDirectory() &&
|
||||
dirent.name.toLowerCase().startsWith(lowerPrefix) &&
|
||||
(showHidden || !dirent.name.startsWith(".")),
|
||||
(entry) =>
|
||||
entry.kind === "directory" &&
|
||||
entry.name.toLowerCase().startsWith(lowerPrefix) &&
|
||||
(showHidden || !entry.name.startsWith(".")),
|
||||
)
|
||||
.map((dirent) => ({
|
||||
name: dirent.name,
|
||||
fullPath: path.join(parentPath, dirent.name),
|
||||
.map((entry) => ({
|
||||
name: entry.name,
|
||||
fullPath: path.join(parentPath, entry.name),
|
||||
}))
|
||||
.toSorted((left, right) => left.name.localeCompare(right.name)),
|
||||
};
|
||||
|
||||
@@ -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 } : {})}
|
||||
|
||||
@@ -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 };
|
||||
|
||||
+38
-53
@@ -1,61 +1,46 @@
|
||||
import * as Schema from "effect/Schema";
|
||||
import * as Data from "effect/Data";
|
||||
|
||||
export class SshHostDiscoveryError extends Schema.TaggedErrorClass<SshHostDiscoveryError>()(
|
||||
"SshHostDiscoveryError",
|
||||
{
|
||||
message: Schema.String,
|
||||
cause: Schema.Defect,
|
||||
},
|
||||
) {}
|
||||
export class SshHostDiscoveryError extends Data.TaggedError("SshHostDiscoveryError")<{
|
||||
readonly message: string;
|
||||
readonly cause: unknown;
|
||||
}> {}
|
||||
|
||||
export class SshInvalidTargetError extends Schema.TaggedErrorClass<SshInvalidTargetError>()(
|
||||
"SshInvalidTargetError",
|
||||
{
|
||||
message: Schema.String,
|
||||
},
|
||||
) {}
|
||||
export class SshInvalidTargetError extends Data.TaggedError("SshInvalidTargetError")<{
|
||||
readonly message: string;
|
||||
}> {}
|
||||
|
||||
export class SshCommandError extends Schema.TaggedErrorClass<SshCommandError>()("SshCommandError", {
|
||||
message: Schema.String,
|
||||
command: Schema.Array(Schema.String),
|
||||
exitCode: Schema.NullOr(Schema.Number),
|
||||
stderr: Schema.String,
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
}) {}
|
||||
export class SshCommandError extends Data.TaggedError("SshCommandError")<{
|
||||
readonly message: string;
|
||||
readonly command: readonly string[];
|
||||
readonly exitCode: number | null;
|
||||
readonly stderr: string;
|
||||
readonly cause?: unknown;
|
||||
}> {}
|
||||
|
||||
export class SshLaunchError extends Schema.TaggedErrorClass<SshLaunchError>()("SshLaunchError", {
|
||||
message: Schema.String,
|
||||
stdout: Schema.String,
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
}) {}
|
||||
export class SshLaunchError extends Data.TaggedError("SshLaunchError")<{
|
||||
readonly message: string;
|
||||
readonly stdout: string;
|
||||
readonly cause?: unknown;
|
||||
}> {}
|
||||
|
||||
export class SshPairingError extends Schema.TaggedErrorClass<SshPairingError>()("SshPairingError", {
|
||||
message: Schema.String,
|
||||
stdout: Schema.String,
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
}) {}
|
||||
export class SshPairingError extends Data.TaggedError("SshPairingError")<{
|
||||
readonly message: string;
|
||||
readonly stdout: string;
|
||||
readonly cause?: unknown;
|
||||
}> {}
|
||||
|
||||
export class SshHttpBridgeError extends Schema.TaggedErrorClass<SshHttpBridgeError>()(
|
||||
"SshHttpBridgeError",
|
||||
{
|
||||
message: Schema.String,
|
||||
status: Schema.optional(Schema.Number),
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
},
|
||||
) {}
|
||||
export class SshHttpBridgeError extends Data.TaggedError("SshHttpBridgeError")<{
|
||||
readonly message: string;
|
||||
readonly status?: number;
|
||||
readonly cause?: unknown;
|
||||
}> {}
|
||||
|
||||
export class SshReadinessError extends Schema.TaggedErrorClass<SshReadinessError>()(
|
||||
"SshReadinessError",
|
||||
{
|
||||
message: Schema.String,
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
},
|
||||
) {}
|
||||
export class SshReadinessError extends Data.TaggedError("SshReadinessError")<{
|
||||
readonly message: string;
|
||||
readonly cause?: unknown;
|
||||
}> {}
|
||||
|
||||
export class SshPasswordPromptError extends Schema.TaggedErrorClass<SshPasswordPromptError>()(
|
||||
"SshPasswordPromptError",
|
||||
{
|
||||
message: Schema.String,
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
},
|
||||
) {}
|
||||
export class SshPasswordPromptError extends Data.TaggedError("SshPasswordPromptError")<{
|
||||
readonly message: string;
|
||||
readonly cause?: unknown;
|
||||
}> {}
|
||||
@@ -167,7 +167,6 @@ const RemoteHttpError = Schema.Struct({
|
||||
const decodeRemoteLaunchResult = Schema.decodeEffect(fromLenientJson(RemoteLaunchResult));
|
||||
const decodeRemotePairingResult = Schema.decodeEffect(fromLenientJson(RemotePairingResult));
|
||||
const decodeRemoteHttpError = Schema.decodeEffect(Schema.fromJsonString(RemoteHttpError));
|
||||
const isSshReadinessError = Schema.is(SshReadinessError);
|
||||
|
||||
const decodeRemoteJsonOutput = <A, E>(
|
||||
stdout: string,
|
||||
@@ -238,7 +237,7 @@ function applyScriptPlaceholders(
|
||||
}
|
||||
|
||||
export function describeReadinessCause(cause: unknown): unknown {
|
||||
if (isSshReadinessError(cause)) {
|
||||
if (cause instanceof SshReadinessError) {
|
||||
return {
|
||||
_tag: cause._tag,
|
||||
message: cause.message,
|
||||
@@ -926,7 +925,7 @@ export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(functio
|
||||
});
|
||||
}).pipe(
|
||||
Effect.mapError((cause) =>
|
||||
isSshReadinessError(cause)
|
||||
cause instanceof SshReadinessError
|
||||
? cause
|
||||
: new SshReadinessError({
|
||||
message: `Backend readiness probe failed at ${requestUrl}.`,
|
||||
@@ -947,7 +946,7 @@ export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(functio
|
||||
|
||||
const result = yield* readinessClient.execute(HttpClientRequest.get(requestUrl)).pipe(
|
||||
Effect.mapError((cause) =>
|
||||
isSshReadinessError(cause)
|
||||
cause instanceof SshReadinessError
|
||||
? cause
|
||||
: new SshReadinessError({
|
||||
message: `Backend readiness probe failed at ${requestUrl}.`,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Data from "effect/Data";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Schema from "effect/Schema";
|
||||
@@ -7,36 +7,24 @@ import { HttpClient, HttpClientRequest } from "effect/unstable/http";
|
||||
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
export const DEFAULT_TAILSCALE_SERVE_PORT = 443;
|
||||
export const TAILSCALE_STATUS_TIMEOUT = Duration.millis(1_500);
|
||||
export const TAILSCALE_SERVE_TIMEOUT = Duration.seconds(10);
|
||||
export const TAILSCALE_PROBE_TIMEOUT = Duration.millis(2_500);
|
||||
export const TAILSCALE_STATUS_TIMEOUT_MS = Duration.toMillis(TAILSCALE_STATUS_TIMEOUT);
|
||||
export const TAILSCALE_SERVE_TIMEOUT_MS = Duration.toMillis(TAILSCALE_SERVE_TIMEOUT);
|
||||
export const TAILSCALE_PROBE_TIMEOUT_MS = Duration.toMillis(TAILSCALE_PROBE_TIMEOUT);
|
||||
export const TAILSCALE_STATUS_TIMEOUT_MS = 1_500;
|
||||
export const TAILSCALE_SERVE_TIMEOUT_MS = 10_000;
|
||||
export const TAILSCALE_PROBE_TIMEOUT_MS = 2_500;
|
||||
|
||||
export class TailscaleCommandError extends Schema.TaggedErrorClass<TailscaleCommandError>()(
|
||||
"TailscaleCommandError",
|
||||
{
|
||||
command: Schema.Array(Schema.String),
|
||||
message: Schema.String,
|
||||
exitCode: Schema.NullOr(Schema.Number),
|
||||
stderr: Schema.String,
|
||||
},
|
||||
) {}
|
||||
export class TailscaleCommandError extends Data.TaggedError("TailscaleCommandError")<{
|
||||
readonly command: readonly string[];
|
||||
readonly message: string;
|
||||
readonly exitCode: number | null;
|
||||
readonly stderr: string;
|
||||
}> {}
|
||||
|
||||
export class TailscaleStatusParseError extends Schema.TaggedErrorClass<TailscaleStatusParseError>()(
|
||||
"TailscaleStatusParseError",
|
||||
{
|
||||
cause: Schema.Defect,
|
||||
},
|
||||
) {}
|
||||
export class TailscaleStatusParseError extends Data.TaggedError("TailscaleStatusParseError")<{
|
||||
readonly cause: unknown;
|
||||
}> {}
|
||||
|
||||
export class TailscaleUnavailableError extends Schema.TaggedErrorClass<TailscaleUnavailableError>()(
|
||||
"TailscaleUnavailableError",
|
||||
{
|
||||
reason: Schema.String,
|
||||
},
|
||||
) {}
|
||||
export class TailscaleUnavailableError extends Data.TaggedError("TailscaleUnavailableError")<{
|
||||
readonly reason: string;
|
||||
}> {}
|
||||
|
||||
const TailscaleStatusSelf = Schema.Struct({
|
||||
DNSName: Schema.optional(Schema.Unknown),
|
||||
@@ -186,7 +174,7 @@ export const readTailscaleStatus: Effect.Effect<
|
||||
return yield* parseTailscaleStatus(stdout);
|
||||
}).pipe(
|
||||
Effect.scoped,
|
||||
Effect.timeoutOption(TAILSCALE_STATUS_TIMEOUT),
|
||||
Effect.timeoutOption(TAILSCALE_STATUS_TIMEOUT_MS),
|
||||
Effect.flatMap((result) =>
|
||||
Option.match(result, {
|
||||
onNone: () =>
|
||||
@@ -218,7 +206,7 @@ const runTailscaleCommand = (
|
||||
readonly runMessage: string;
|
||||
readonly exitMessage: (exitCode: number) => string;
|
||||
readonly timeoutMessage: string;
|
||||
readonly timeout: Duration.Input;
|
||||
readonly timeoutMs: number;
|
||||
},
|
||||
): Effect.Effect<void, TailscaleCommandError, ChildProcessSpawner.ChildProcessSpawner> =>
|
||||
Effect.gen(function* () {
|
||||
@@ -255,7 +243,7 @@ const runTailscaleCommand = (
|
||||
}
|
||||
}).pipe(
|
||||
Effect.scoped,
|
||||
Effect.timeoutOption(input.timeout),
|
||||
Effect.timeoutOption(input.timeoutMs),
|
||||
Effect.flatMap((result) =>
|
||||
Option.match(result, {
|
||||
onNone: () => Effect.fail(tailscaleCommandError(args, input.timeoutMessage, null)),
|
||||
@@ -277,7 +265,7 @@ export const ensureTailscaleServe = (input: {
|
||||
runMessage: "Failed to run tailscale serve.",
|
||||
exitMessage: (exitCode) => `Tailscale serve exited with code ${exitCode}.`,
|
||||
timeoutMessage: "Tailscale serve timed out.",
|
||||
timeout: TAILSCALE_SERVE_TIMEOUT,
|
||||
timeoutMs: TAILSCALE_SERVE_TIMEOUT_MS,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -293,13 +281,13 @@ export const disableTailscaleServe = (
|
||||
runMessage: "Failed to run tailscale serve off.",
|
||||
exitMessage: (exitCode) => `Tailscale serve off exited with code ${exitCode}.`,
|
||||
timeoutMessage: "Tailscale serve off timed out.",
|
||||
timeout: TAILSCALE_SERVE_TIMEOUT,
|
||||
timeoutMs: TAILSCALE_SERVE_TIMEOUT_MS,
|
||||
});
|
||||
});
|
||||
|
||||
export const probeTailscaleHttpsEndpoint = (input: {
|
||||
readonly baseUrl: string;
|
||||
readonly timeout?: Duration.Input;
|
||||
readonly timeoutMs?: number;
|
||||
}): Effect.Effect<boolean, never, HttpClient.HttpClient> =>
|
||||
Effect.gen(function* () {
|
||||
const client = yield* HttpClient.HttpClient;
|
||||
@@ -307,7 +295,7 @@ export const probeTailscaleHttpsEndpoint = (input: {
|
||||
const url = new URL("/.well-known/t3/environment", input.baseUrl);
|
||||
const request = HttpClientRequest.get(url.toString());
|
||||
return yield* client.execute(request);
|
||||
}).pipe(Effect.timeoutOption(input.timeout ?? TAILSCALE_PROBE_TIMEOUT));
|
||||
}).pipe(Effect.timeoutOption(input.timeoutMs ?? TAILSCALE_PROBE_TIMEOUT_MS));
|
||||
|
||||
return Option.match(response, {
|
||||
onNone: () => false,
|
||||
|
||||
Reference in new issue
Block a user