Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc3c829cca | ||
|
|
67c8cd230e | ||
|
|
292e6ad7a2 | ||
|
|
4f0f24f055 |
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { assert, describe, it } from "@effect/vitest";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import { HttpClient } from "effect/unstable/http";
|
||||
import { ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
@@ -15,10 +16,7 @@ const unusedTailscaleExternalServicesLayer = Layer.mergeAll(
|
||||
HttpClient.HttpClient,
|
||||
HttpClient.make(() => Effect.die("unexpected Tailscale HTTPS probe")),
|
||||
),
|
||||
Layer.succeed(
|
||||
ChildProcessSpawner.ChildProcessSpawner,
|
||||
ChildProcessSpawner.make(() => Effect.die("unexpected tailscale status process")),
|
||||
),
|
||||
Layer.mock(ChildProcessSpawner.ChildProcessSpawner, {}),
|
||||
);
|
||||
|
||||
describe("tailscale endpoint provider", () => {
|
||||
@@ -34,8 +32,8 @@ describe("tailscale endpoint provider", () => {
|
||||
const dnsName = yield* parseTailscaleMagicDnsName(
|
||||
`{"Self":{"DNSName":"desktop.tail.ts.net."}}`,
|
||||
);
|
||||
assert.equal(dnsName, "desktop.tail.ts.net");
|
||||
assert.equal(yield* parseTailscaleMagicDnsName("{}"), null);
|
||||
assert.deepEqual(dnsName, Option.some("desktop.tail.ts.net"));
|
||||
assert.deepEqual(yield* parseTailscaleMagicDnsName("{}"), Option.none());
|
||||
const malformed = yield* Effect.result(parseTailscaleMagicDnsName("not-json"));
|
||||
assert.isTrue(malformed._tag === "Failure");
|
||||
}),
|
||||
|
||||
@@ -61,17 +61,17 @@ function resolveTailscaleIpAdvertisedEndpoints(input: {
|
||||
const resolveTailscaleMagicDnsAdvertisedEndpoint = Effect.fn(
|
||||
"resolveTailscaleMagicDnsAdvertisedEndpoint",
|
||||
)(function* (input: {
|
||||
readonly dnsName: string | null;
|
||||
readonly dnsName: Option.Option<string>;
|
||||
readonly serveEnabled: boolean;
|
||||
readonly servePort?: number;
|
||||
readonly probe?: (baseUrl: string) => Effect.Effect<boolean, never, HttpClient.HttpClient>;
|
||||
}): Effect.fn.Return<Option.Option<AdvertisedEndpoint>, never, HttpClient.HttpClient> {
|
||||
if (!input.dnsName) {
|
||||
if (Option.isNone(input.dnsName)) {
|
||||
return Option.none();
|
||||
}
|
||||
|
||||
const httpBaseUrl = buildTailscaleHttpsBaseUrl({
|
||||
magicDnsName: input.dnsName,
|
||||
magicDnsName: input.dnsName.value,
|
||||
...(input.servePort === undefined ? {} : { servePort: input.servePort }),
|
||||
});
|
||||
const probe =
|
||||
@@ -116,13 +116,13 @@ export const resolveTailscaleAdvertisedEndpoints = Effect.fn("resolveTailscaleAd
|
||||
input.statusJson === undefined
|
||||
? yield* readTailscaleStatus.pipe(
|
||||
Effect.map((status) => status.magicDnsName),
|
||||
Effect.catch(() => Effect.succeed(null)),
|
||||
Effect.catch(() => Effect.succeed(Option.none())),
|
||||
)
|
||||
: input.statusJson
|
||||
? yield* parseTailscaleMagicDnsName(input.statusJson).pipe(
|
||||
Effect.catch(() => Effect.succeed(null)),
|
||||
Effect.catch(() => Effect.succeed(Option.none())),
|
||||
)
|
||||
: null;
|
||||
: Option.none();
|
||||
const magicDnsEndpoint = yield* resolveTailscaleMagicDnsAdvertisedEndpoint({
|
||||
dnsName,
|
||||
serveEnabled: input.serveEnabled === true,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { describe, expect, it } from "@effect/vitest";
|
||||
import { assert, describe, it } from "@effect/vitest";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
@@ -41,7 +41,7 @@ describe("ProcessDiagnostics", () => {
|
||||
].join("\n"),
|
||||
);
|
||||
|
||||
expect(rows).toEqual([
|
||||
assert.deepEqual(rows, [
|
||||
{
|
||||
pid: 10,
|
||||
ppid: 1,
|
||||
@@ -66,6 +66,61 @@ describe("ProcessDiagnostics", () => {
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("parses Windows process JSON through schema decoding", () =>
|
||||
Effect.sync(() => {
|
||||
const rows = ProcessDiagnostics.parseWindowsProcessRows(
|
||||
JSON.stringify([
|
||||
{
|
||||
ProcessId: 10,
|
||||
ParentProcessId: 1,
|
||||
Name: "node.exe",
|
||||
CommandLine: "node server.js",
|
||||
Status: "Running",
|
||||
WorkingSetSize: 1024,
|
||||
PercentProcessorTime: 1.5,
|
||||
},
|
||||
{
|
||||
ProcessId: 11,
|
||||
ParentProcessId: 10,
|
||||
Name: "child.exe",
|
||||
CommandLine: "",
|
||||
WorkingSetSize: 2048.2,
|
||||
},
|
||||
{
|
||||
ProcessId: "bad",
|
||||
ParentProcessId: 10,
|
||||
Name: "ignored.exe",
|
||||
},
|
||||
]),
|
||||
);
|
||||
|
||||
assert.deepEqual(rows, [
|
||||
{
|
||||
pid: 10,
|
||||
ppid: 1,
|
||||
pgid: null,
|
||||
status: "Running",
|
||||
cpuPercent: 1.5,
|
||||
rssBytes: 1024,
|
||||
elapsed: "",
|
||||
command: "node server.js",
|
||||
},
|
||||
{
|
||||
pid: 11,
|
||||
ppid: 10,
|
||||
pgid: null,
|
||||
status: "Live",
|
||||
cpuPercent: 0,
|
||||
rssBytes: 2048,
|
||||
elapsed: "",
|
||||
command: "child.exe",
|
||||
},
|
||||
]);
|
||||
|
||||
assert.deepEqual(ProcessDiagnostics.parseWindowsProcessRows("not-json"), []);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("aggregates only descendants of the server process", () =>
|
||||
Effect.sync(() => {
|
||||
const diagnostics = ProcessDiagnostics.aggregateProcessDiagnostics({
|
||||
@@ -125,15 +180,21 @@ describe("ProcessDiagnostics", () => {
|
||||
],
|
||||
});
|
||||
|
||||
expect(diagnostics.serverPid).toBe(100);
|
||||
expect(DateTime.formatIso(diagnostics.readAt)).toBe("2026-05-05T10:00:00.000Z");
|
||||
expect(diagnostics.processCount).toBe(2);
|
||||
expect(diagnostics.totalRssBytes).toBe(6_000);
|
||||
expect(diagnostics.totalCpuPercent).toBe(4.75);
|
||||
expect(diagnostics.processes.map((process) => process.pid)).toEqual([101, 102]);
|
||||
expect(diagnostics.processes.map((process) => process.depth)).toEqual([0, 1]);
|
||||
expect(Option.getOrNull(diagnostics.processes[0]!.pgid)).toBe(100);
|
||||
expect(diagnostics.processes[0]?.childPids).toEqual([102]);
|
||||
assert.equal(diagnostics.serverPid, 100);
|
||||
assert.equal(DateTime.formatIso(diagnostics.readAt), "2026-05-05T10:00:00.000Z");
|
||||
assert.equal(diagnostics.processCount, 2);
|
||||
assert.equal(diagnostics.totalRssBytes, 6_000);
|
||||
assert.equal(diagnostics.totalCpuPercent, 4.75);
|
||||
assert.deepEqual(
|
||||
diagnostics.processes.map((process) => process.pid),
|
||||
[101, 102],
|
||||
);
|
||||
assert.deepEqual(
|
||||
diagnostics.processes.map((process) => process.depth),
|
||||
[0, 1],
|
||||
);
|
||||
assert.equal(Option.getOrNull(diagnostics.processes[0]!.pgid), 100);
|
||||
assert.deepEqual(diagnostics.processes[0]?.childPids, [102]);
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -176,7 +237,10 @@ describe("ProcessDiagnostics", () => {
|
||||
],
|
||||
});
|
||||
|
||||
expect(diagnostics.processes.map((process) => process.pid)).toEqual([101, 102, 103]);
|
||||
assert.deepEqual(
|
||||
diagnostics.processes.map((process) => process.pid),
|
||||
[101, 102, 103],
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -184,9 +248,8 @@ describe("ProcessDiagnostics", () => {
|
||||
Effect.gen(function* () {
|
||||
const commands: Array<{ readonly command: string; readonly args: ReadonlyArray<string> }> =
|
||||
[];
|
||||
const spawnerLayer = Layer.succeed(
|
||||
ChildProcessSpawner.ChildProcessSpawner,
|
||||
ChildProcessSpawner.make((command) => {
|
||||
const spawnerLayer = Layer.mock(ChildProcessSpawner.ChildProcessSpawner, {
|
||||
spawn: (command) => {
|
||||
const childProcess = command as unknown as {
|
||||
readonly command: string;
|
||||
readonly args: ReadonlyArray<string>;
|
||||
@@ -200,8 +263,8 @@ describe("ProcessDiagnostics", () => {
|
||||
].join("\n"),
|
||||
}),
|
||||
);
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
const layer = ProcessDiagnostics.layer.pipe(Layer.provide(spawnerLayer));
|
||||
|
||||
const diagnostics = yield* Effect.service(ProcessDiagnostics.ProcessDiagnostics).pipe(
|
||||
@@ -209,8 +272,11 @@ describe("ProcessDiagnostics", () => {
|
||||
Effect.provide(layer),
|
||||
);
|
||||
|
||||
expect(diagnostics.processes.map((process) => process.pid)).toEqual([4242]);
|
||||
expect(commands).toEqual([
|
||||
assert.deepEqual(
|
||||
diagnostics.processes.map((process) => process.pid),
|
||||
[4242],
|
||||
);
|
||||
assert.deepEqual(commands, [
|
||||
{
|
||||
command: "ps",
|
||||
args: ["-axo", "pid=,ppid=,pgid=,stat=,pcpu=,rss=,etime=,command="],
|
||||
@@ -221,9 +287,8 @@ describe("ProcessDiagnostics", () => {
|
||||
|
||||
it.effect("does not allow signaling the diagnostics query process", () =>
|
||||
Effect.gen(function* () {
|
||||
const spawnerLayer = Layer.succeed(
|
||||
ChildProcessSpawner.ChildProcessSpawner,
|
||||
ChildProcessSpawner.make(() =>
|
||||
const spawnerLayer = Layer.mock(ChildProcessSpawner.ChildProcessSpawner, {
|
||||
spawn: () =>
|
||||
Effect.succeed(
|
||||
mockHandle({
|
||||
stdout: [
|
||||
@@ -232,8 +297,7 @@ describe("ProcessDiagnostics", () => {
|
||||
].join("\n"),
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
const layer = ProcessDiagnostics.layer.pipe(Layer.provide(spawnerLayer));
|
||||
|
||||
const result = yield* Effect.service(ProcessDiagnostics.ProcessDiagnostics).pipe(
|
||||
@@ -241,7 +305,7 @@ describe("ProcessDiagnostics", () => {
|
||||
Effect.provide(layer),
|
||||
);
|
||||
|
||||
expect(result).toEqual({
|
||||
assert.deepEqual(result, {
|
||||
pid: 4242,
|
||||
signal: "SIGINT",
|
||||
signaled: false,
|
||||
|
||||
@@ -26,7 +26,7 @@ export interface ProcessRow {
|
||||
readonly command: string;
|
||||
}
|
||||
|
||||
const PROCESS_QUERY_TIMEOUT_MS = 1_000;
|
||||
const PROCESS_QUERY_TIMEOUT = Duration.seconds(1);
|
||||
const POSIX_PROCESS_QUERY_COMMAND = "pid=,ppid=,pgid=,stat=,pcpu=,rss=,etime=,command=";
|
||||
const PROCESS_QUERY_MAX_OUTPUT_BYTES = 2 * 1024 * 1024;
|
||||
|
||||
@@ -74,6 +74,22 @@ function parseNumber(value: string): number | null {
|
||||
return Number.isFinite(parsed) ? parsed : null;
|
||||
}
|
||||
|
||||
const WindowsProcessRecord = Schema.Struct({
|
||||
CommandLine: Schema.optional(Schema.Unknown),
|
||||
Name: Schema.optional(Schema.Unknown),
|
||||
ParentProcessId: Schema.optional(Schema.Unknown),
|
||||
PercentProcessorTime: Schema.optional(Schema.Unknown),
|
||||
ProcessId: Schema.optional(Schema.Unknown),
|
||||
Status: Schema.optional(Schema.Unknown),
|
||||
WorkingSetSize: Schema.optional(Schema.Unknown),
|
||||
});
|
||||
type WindowsProcessRecord = typeof WindowsProcessRecord.Type;
|
||||
|
||||
const WindowsProcessOutput = Schema.fromJsonString(
|
||||
Schema.Union([WindowsProcessRecord, Schema.Array(WindowsProcessRecord)]),
|
||||
);
|
||||
const decodeWindowsProcessOutput = Schema.decodeUnknownOption(WindowsProcessOutput);
|
||||
|
||||
export function parsePosixProcessRows(output: string): ReadonlyArray<ProcessRow> {
|
||||
const rows: ProcessRow[] = [];
|
||||
const rowPattern =
|
||||
@@ -139,9 +155,7 @@ export function parsePosixProcessRows(output: string): ReadonlyArray<ProcessRow>
|
||||
return rows;
|
||||
}
|
||||
|
||||
function normalizeWindowsProcessRow(value: unknown): ProcessRow | null {
|
||||
if (typeof value !== "object" || value === null) return null;
|
||||
const record = value as Record<string, unknown>;
|
||||
function normalizeWindowsProcessRow(record: WindowsProcessRecord): ProcessRow | null {
|
||||
const pid = typeof record.ProcessId === "number" ? record.ProcessId : null;
|
||||
const ppid = typeof record.ParentProcessId === "number" ? record.ParentProcessId : null;
|
||||
const commandLine =
|
||||
@@ -172,18 +186,18 @@ function normalizeWindowsProcessRow(value: unknown): ProcessRow | null {
|
||||
};
|
||||
}
|
||||
|
||||
function parseWindowsProcessRows(output: string): ReadonlyArray<ProcessRow> {
|
||||
export function parseWindowsProcessRows(output: string): ReadonlyArray<ProcessRow> {
|
||||
if (output.trim().length === 0) return [];
|
||||
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 {
|
||||
const parsed = decodeWindowsProcessOutput(output);
|
||||
if (Option.isNone(parsed)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const records = Array.isArray(parsed.value) ? parsed.value : [parsed.value];
|
||||
return records.flatMap((record) => {
|
||||
const row = normalizeWindowsProcessRow(record);
|
||||
return row ? [row] : [];
|
||||
});
|
||||
}
|
||||
|
||||
export function buildDescendantEntries(
|
||||
@@ -309,7 +323,7 @@ const runProcess = Effect.fn("runProcess")(
|
||||
(effect, input) =>
|
||||
effect.pipe(
|
||||
Effect.scoped,
|
||||
Effect.timeoutOption(Duration.millis(PROCESS_QUERY_TIMEOUT_MS)),
|
||||
Effect.timeoutOption(PROCESS_QUERY_TIMEOUT),
|
||||
Effect.flatMap((result) =>
|
||||
Option.match(result, {
|
||||
onNone: () => Effect.fail(toProcessDiagnosticsError(`${input.errorMessage} timed out.`)),
|
||||
|
||||
@@ -147,10 +147,7 @@ import { ExpandedImageDialog } from "./chat/ExpandedImageDialog";
|
||||
import { PullRequestThreadDialog } from "./PullRequestThreadDialog";
|
||||
import { MessagesTimeline } from "./chat/MessagesTimeline";
|
||||
import { ChatHeader } from "./chat/ChatHeader";
|
||||
import {
|
||||
getExpandedImagePreviewIdentityKey,
|
||||
type ExpandedImagePreview,
|
||||
} from "./chat/ExpandedImagePreview";
|
||||
import { type ExpandedImagePreview } from "./chat/ExpandedImagePreview";
|
||||
import { NoActiveThreadState } from "./NoActiveThreadState";
|
||||
import { resolveEffectiveEnvMode, resolveEnvironmentOptionLabel } from "./BranchToolbar.logic";
|
||||
import { ProviderStatusBanner } from "./chat/ProviderStatusBanner";
|
||||
@@ -3776,11 +3773,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
) : null}
|
||||
|
||||
{expandedImage && (
|
||||
<ExpandedImageDialog
|
||||
key={getExpandedImagePreviewIdentityKey(expandedImage)}
|
||||
preview={expandedImage}
|
||||
onClose={closeExpandedImage}
|
||||
/>
|
||||
<ExpandedImageDialog preview={expandedImage} onClose={closeExpandedImage} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -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,4 +1,4 @@
|
||||
import { memo, useCallback, useEffect, useEffectEvent, useState } from "react";
|
||||
import { memo, useCallback, useEffect, useState } from "react";
|
||||
import { ChevronLeftIcon, ChevronRightIcon, XIcon } from "lucide-react";
|
||||
import { Button } from "../ui/button";
|
||||
import type { ExpandedImagePreview } from "./ExpandedImagePreview";
|
||||
@@ -8,65 +8,52 @@ interface ExpandedImageDialogProps {
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
function useExpandedImageDialogKeyboardShortcuts(input: {
|
||||
readonly imageCount: number;
|
||||
readonly onClose: () => void;
|
||||
readonly onNavigate: (direction: -1 | 1) => void;
|
||||
}) {
|
||||
const close = useEffectEvent(input.onClose);
|
||||
const navigate = useEffectEvent(input.onNavigate);
|
||||
export const ExpandedImageDialog = memo(function ExpandedImageDialog({
|
||||
preview: initialPreview,
|
||||
onClose,
|
||||
}: ExpandedImageDialogProps) {
|
||||
const [preview, setPreview] = useState(initialPreview);
|
||||
|
||||
// Sync when the parent hands us a new preview reference.
|
||||
useEffect(() => {
|
||||
setPreview(initialPreview);
|
||||
}, [initialPreview]);
|
||||
|
||||
const navigateImage = useCallback((direction: -1 | 1) => {
|
||||
setPreview((existing) => {
|
||||
if (existing.images.length <= 1) return existing;
|
||||
const nextIndex =
|
||||
(existing.index + direction + existing.images.length) % existing.images.length;
|
||||
if (nextIndex === existing.index) return existing;
|
||||
return { ...existing, index: nextIndex };
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const onKeyDown = (event: globalThis.KeyboardEvent) => {
|
||||
if (event.key === "Escape") {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
close();
|
||||
onClose();
|
||||
return;
|
||||
}
|
||||
if (input.imageCount <= 1) return;
|
||||
if (preview.images.length <= 1) return;
|
||||
if (event.key === "ArrowLeft") {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
navigate(-1);
|
||||
navigateImage(-1);
|
||||
return;
|
||||
}
|
||||
if (event.key !== "ArrowRight") return;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
navigate(1);
|
||||
navigateImage(1);
|
||||
};
|
||||
window.addEventListener("keydown", onKeyDown);
|
||||
return () => window.removeEventListener("keydown", onKeyDown);
|
||||
}, [close, input.imageCount, navigate]);
|
||||
}
|
||||
}, [navigateImage, onClose, preview.images.length]);
|
||||
|
||||
export const ExpandedImageDialog = memo(function ExpandedImageDialog({
|
||||
preview,
|
||||
onClose,
|
||||
}: ExpandedImageDialogProps) {
|
||||
const [navigationOffset, setNavigationOffset] = useState(0);
|
||||
const imageCount = preview.images.length;
|
||||
const activeIndex =
|
||||
imageCount > 0 ? (preview.index + navigationOffset + imageCount) % imageCount : preview.index;
|
||||
|
||||
const navigateImage = useCallback(
|
||||
(direction: -1 | 1) => {
|
||||
setNavigationOffset((offset) => {
|
||||
if (imageCount <= 1) return offset;
|
||||
return offset + direction;
|
||||
});
|
||||
},
|
||||
[imageCount],
|
||||
);
|
||||
|
||||
useExpandedImageDialogKeyboardShortcuts({
|
||||
imageCount,
|
||||
onClose,
|
||||
onNavigate: navigateImage,
|
||||
});
|
||||
|
||||
const item = preview.images[activeIndex];
|
||||
const item = preview.images[preview.index];
|
||||
if (!item) return null;
|
||||
|
||||
return (
|
||||
@@ -82,7 +69,7 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
|
||||
aria-label="Close image preview"
|
||||
onClick={onClose}
|
||||
/>
|
||||
{imageCount > 1 && (
|
||||
{preview.images.length > 1 && (
|
||||
<Button
|
||||
type="button"
|
||||
size="icon"
|
||||
@@ -113,10 +100,10 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
|
||||
/>
|
||||
<p className="mt-2 max-w-[92vw] truncate text-center text-xs text-muted-foreground/80">
|
||||
{item.name}
|
||||
{imageCount > 1 ? ` (${activeIndex + 1}/${imageCount})` : ""}
|
||||
{preview.images.length > 1 ? ` (${preview.index + 1}/${preview.images.length})` : ""}
|
||||
</p>
|
||||
</div>
|
||||
{imageCount > 1 && (
|
||||
{preview.images.length > 1 && (
|
||||
<Button
|
||||
type="button"
|
||||
size="icon"
|
||||
|
||||
@@ -8,14 +8,6 @@ export interface ExpandedImagePreview {
|
||||
index: number;
|
||||
}
|
||||
|
||||
export function getExpandedImagePreviewIdentityKey(preview: ExpandedImagePreview): string {
|
||||
const selectedImage = preview.images[preview.index];
|
||||
const selectedImageKey = selectedImage
|
||||
? `${selectedImage.name.length}:${selectedImage.name}:${selectedImage.src.length}:${selectedImage.src}`
|
||||
: "missing";
|
||||
return `${preview.images.length}:${preview.index}:${selectedImageKey}`;
|
||||
}
|
||||
|
||||
export function buildExpandedImagePreview(
|
||||
images: ReadonlyArray<{ id: string; name: string; previewUrl?: string }>,
|
||||
selectedImageId: string,
|
||||
|
||||
@@ -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 };
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,7 @@
|
||||
import { assert, describe, it } from "@effect/vitest";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Sink from "effect/Sink";
|
||||
import * as Stream from "effect/Stream";
|
||||
import { ChildProcessSpawner } from "effect/unstable/process";
|
||||
@@ -41,16 +42,15 @@ function mockSpawnerLayer(
|
||||
args: ReadonlyArray<string>,
|
||||
) => { stdout?: string; stderr?: string; code?: number },
|
||||
) {
|
||||
return Layer.succeed(
|
||||
ChildProcessSpawner.ChildProcessSpawner,
|
||||
ChildProcessSpawner.make((command) => {
|
||||
return Layer.mock(ChildProcessSpawner.ChildProcessSpawner, {
|
||||
spawn: (command) => {
|
||||
const childProcess = command as unknown as {
|
||||
readonly command: string;
|
||||
readonly args: ReadonlyArray<string>;
|
||||
};
|
||||
return Effect.succeed(mockHandle(handler(childProcess.command, childProcess.args)));
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
describe("tailscale", () => {
|
||||
@@ -66,8 +66,8 @@ describe("tailscale", () => {
|
||||
it.effect("parses MagicDNS names from tailscale status", () =>
|
||||
Effect.gen(function* () {
|
||||
const dnsName = yield* parseTailscaleMagicDnsName(tailscaleStatusJson);
|
||||
assert.equal(dnsName, "desktop.tail.ts.net");
|
||||
assert.equal(yield* parseTailscaleMagicDnsName("{}"), null);
|
||||
assert.deepEqual(dnsName, Option.some("desktop.tail.ts.net"));
|
||||
assert.deepEqual(yield* parseTailscaleMagicDnsName("{}"), Option.none());
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -75,7 +75,7 @@ describe("tailscale", () => {
|
||||
Effect.gen(function* () {
|
||||
const status = yield* parseTailscaleStatus(tailscaleStatusJson);
|
||||
assert.deepEqual(status, {
|
||||
magicDnsName: "desktop.tail.ts.net",
|
||||
magicDnsName: Option.some("desktop.tail.ts.net"),
|
||||
tailnetIpv4Addresses: ["100.100.100.100"],
|
||||
});
|
||||
}),
|
||||
@@ -106,7 +106,7 @@ describe("tailscale", () => {
|
||||
return Effect.gen(function* () {
|
||||
const status = yield* readTailscaleStatus.pipe(Effect.provide(layer));
|
||||
assert.deepEqual(status, {
|
||||
magicDnsName: "desktop.tail.ts.net",
|
||||
magicDnsName: Option.some("desktop.tail.ts.net"),
|
||||
tailnetIpv4Addresses: ["100.90.1.2"],
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import * as Data from "effect/Data";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Schema from "effect/Schema";
|
||||
@@ -7,24 +7,33 @@ 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_MS = 1_500;
|
||||
export const TAILSCALE_SERVE_TIMEOUT_MS = 10_000;
|
||||
export const TAILSCALE_PROBE_TIMEOUT_MS = 2_500;
|
||||
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 class TailscaleCommandError extends Data.TaggedError("TailscaleCommandError")<{
|
||||
readonly command: readonly string[];
|
||||
readonly message: string;
|
||||
readonly exitCode: number | null;
|
||||
readonly stderr: string;
|
||||
}> {}
|
||||
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 TailscaleStatusParseError extends Data.TaggedError("TailscaleStatusParseError")<{
|
||||
readonly cause: unknown;
|
||||
}> {}
|
||||
export class TailscaleStatusParseError extends Schema.TaggedErrorClass<TailscaleStatusParseError>()(
|
||||
"TailscaleStatusParseError",
|
||||
{
|
||||
cause: Schema.Defect,
|
||||
},
|
||||
) {}
|
||||
|
||||
export class TailscaleUnavailableError extends Data.TaggedError("TailscaleUnavailableError")<{
|
||||
readonly reason: string;
|
||||
}> {}
|
||||
export class TailscaleUnavailableError extends Schema.TaggedErrorClass<TailscaleUnavailableError>()(
|
||||
"TailscaleUnavailableError",
|
||||
{
|
||||
reason: Schema.String,
|
||||
},
|
||||
) {}
|
||||
|
||||
const TailscaleStatusSelf = Schema.Struct({
|
||||
DNSName: Schema.optional(Schema.Unknown),
|
||||
@@ -39,7 +48,7 @@ export type TailscaleStatusSelf = typeof TailscaleStatusSelf.Type;
|
||||
export type TailscaleStatusJson = typeof TailscaleStatusJson.Type;
|
||||
|
||||
export interface TailscaleStatus {
|
||||
readonly magicDnsName: string | null;
|
||||
readonly magicDnsName: Option.Option<string>;
|
||||
readonly tailnetIpv4Addresses: readonly string[];
|
||||
}
|
||||
|
||||
@@ -69,19 +78,19 @@ const tailscaleCommandError = (
|
||||
|
||||
const decodeTailscaleStatusJson = Schema.decodeEffect(Schema.fromJsonString(TailscaleStatusJson));
|
||||
|
||||
function normalizeMagicDnsName(status: TailscaleStatusJson): string | null {
|
||||
function normalizeMagicDnsName(status: TailscaleStatusJson): Option.Option<string> {
|
||||
const dnsName = status.Self?.DNSName;
|
||||
if (typeof dnsName !== "string") {
|
||||
return null;
|
||||
return Option.none();
|
||||
}
|
||||
|
||||
const normalized = dnsName.trim().replace(/\.$/u, "");
|
||||
return normalized.length > 0 ? normalized : null;
|
||||
return normalized.length > 0 ? Option.some(normalized) : Option.none();
|
||||
}
|
||||
|
||||
export const parseTailscaleMagicDnsName = (
|
||||
rawStatusJson: string,
|
||||
): Effect.Effect<string | null, TailscaleStatusParseError> =>
|
||||
): Effect.Effect<Option.Option<string>, TailscaleStatusParseError> =>
|
||||
decodeTailscaleStatusJson(rawStatusJson).pipe(
|
||||
Effect.mapError((cause) => new TailscaleStatusParseError({ cause })),
|
||||
Effect.map(normalizeMagicDnsName),
|
||||
@@ -174,7 +183,7 @@ export const readTailscaleStatus: Effect.Effect<
|
||||
return yield* parseTailscaleStatus(stdout);
|
||||
}).pipe(
|
||||
Effect.scoped,
|
||||
Effect.timeoutOption(TAILSCALE_STATUS_TIMEOUT_MS),
|
||||
Effect.timeoutOption(TAILSCALE_STATUS_TIMEOUT),
|
||||
Effect.flatMap((result) =>
|
||||
Option.match(result, {
|
||||
onNone: () =>
|
||||
@@ -206,7 +215,7 @@ const runTailscaleCommand = (
|
||||
readonly runMessage: string;
|
||||
readonly exitMessage: (exitCode: number) => string;
|
||||
readonly timeoutMessage: string;
|
||||
readonly timeoutMs: number;
|
||||
readonly timeout: Duration.Duration;
|
||||
},
|
||||
): Effect.Effect<void, TailscaleCommandError, ChildProcessSpawner.ChildProcessSpawner> =>
|
||||
Effect.gen(function* () {
|
||||
@@ -243,7 +252,7 @@ const runTailscaleCommand = (
|
||||
}
|
||||
}).pipe(
|
||||
Effect.scoped,
|
||||
Effect.timeoutOption(input.timeoutMs),
|
||||
Effect.timeoutOption(input.timeout),
|
||||
Effect.flatMap((result) =>
|
||||
Option.match(result, {
|
||||
onNone: () => Effect.fail(tailscaleCommandError(args, input.timeoutMessage, null)),
|
||||
@@ -265,7 +274,7 @@ export const ensureTailscaleServe = (input: {
|
||||
runMessage: "Failed to run tailscale serve.",
|
||||
exitMessage: (exitCode) => `Tailscale serve exited with code ${exitCode}.`,
|
||||
timeoutMessage: "Tailscale serve timed out.",
|
||||
timeoutMs: TAILSCALE_SERVE_TIMEOUT_MS,
|
||||
timeout: TAILSCALE_SERVE_TIMEOUT,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -281,13 +290,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.",
|
||||
timeoutMs: TAILSCALE_SERVE_TIMEOUT_MS,
|
||||
timeout: TAILSCALE_SERVE_TIMEOUT,
|
||||
});
|
||||
});
|
||||
|
||||
export const probeTailscaleHttpsEndpoint = (input: {
|
||||
readonly baseUrl: string;
|
||||
readonly timeoutMs?: number;
|
||||
readonly timeout?: Duration.Duration;
|
||||
}): Effect.Effect<boolean, never, HttpClient.HttpClient> =>
|
||||
Effect.gen(function* () {
|
||||
const client = yield* HttpClient.HttpClient;
|
||||
@@ -295,7 +304,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.timeoutMs ?? TAILSCALE_PROBE_TIMEOUT_MS));
|
||||
}).pipe(Effect.timeoutOption(input.timeout ?? TAILSCALE_PROBE_TIMEOUT));
|
||||
|
||||
return Option.match(response, {
|
||||
onNone: () => false,
|
||||
@@ -308,17 +317,17 @@ export const resolveTailscaleHttpsBaseUrl = (
|
||||
readonly servePort?: number;
|
||||
} = {},
|
||||
): Effect.Effect<
|
||||
string | null,
|
||||
Option.Option<string>,
|
||||
TailscaleCommandError | TailscaleStatusParseError,
|
||||
ChildProcessSpawner.ChildProcessSpawner
|
||||
> =>
|
||||
readTailscaleStatus.pipe(
|
||||
Effect.map((status) =>
|
||||
status.magicDnsName
|
||||
? buildTailscaleHttpsBaseUrl({
|
||||
magicDnsName: status.magicDnsName,
|
||||
...(input.servePort === undefined ? {} : { servePort: input.servePort }),
|
||||
})
|
||||
: null,
|
||||
Option.map(status.magicDnsName, (magicDnsName) =>
|
||||
buildTailscaleHttpsBaseUrl({
|
||||
magicDnsName,
|
||||
...(input.servePort === undefined ? {} : { servePort: input.servePort }),
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
Reference in new issue
Block a user