Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc3c829cca | ||
|
|
67c8cd230e | ||
|
|
292e6ad7a2 | ||
|
|
4f0f24f055 | ||
|
|
d1e85c4e8f |
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@t3tools/desktop",
|
||||
"version": "0.0.23",
|
||||
"version": "0.0.24",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "dist-electron/main.cjs",
|
||||
|
||||
@@ -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,6 +1,6 @@
|
||||
{
|
||||
"name": "t3",
|
||||
"version": "0.0.23",
|
||||
"version": "0.0.24",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -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.`)),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@t3tools/web",
|
||||
"version": "0.0.23",
|
||||
"version": "0.0.24",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -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 } : {})}
|
||||
|
||||
@@ -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,
|
||||
@@ -114,21 +114,6 @@ interface AddProviderInstanceDialogProps {
|
||||
}
|
||||
|
||||
export function AddProviderInstanceDialog({ open, onOpenChange }: AddProviderInstanceDialogProps) {
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<AddProviderInstanceDialogContent
|
||||
key={open ? "add-provider-open" : "add-provider-closed"}
|
||||
onOpenChange={onOpenChange}
|
||||
/>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
interface AddProviderInstanceDialogContentProps {
|
||||
onOpenChange: (open: boolean) => void;
|
||||
}
|
||||
|
||||
function AddProviderInstanceDialogContent({ onOpenChange }: AddProviderInstanceDialogContentProps) {
|
||||
const settings = useSettings();
|
||||
const { updateSettings } = useUpdateSettings();
|
||||
|
||||
@@ -136,7 +121,8 @@ function AddProviderInstanceDialogContent({ onOpenChange }: AddProviderInstanceD
|
||||
const [driver, setDriver] = useState<ProviderDriverKind>(DEFAULT_DRIVER_KIND);
|
||||
const [label, setLabel] = useState("");
|
||||
const [accentColor, setAccentColor] = useState<string>("");
|
||||
const [customInstanceId, setCustomInstanceId] = useState<string | null>(null);
|
||||
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.
|
||||
const [configByDriver, setConfigByDriver] = useState<Record<string, Record<string, unknown>>>({});
|
||||
@@ -149,12 +135,32 @@ function AddProviderInstanceDialogContent({ onOpenChange }: AddProviderInstanceD
|
||||
[settings.providerInstances],
|
||||
);
|
||||
|
||||
// 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(
|
||||
() => deriveProviderSettingsFields(driverOption),
|
||||
[driverOption],
|
||||
);
|
||||
const instanceId = customInstanceId ?? deriveInstanceId(driver, label);
|
||||
const instanceIdError = validateInstanceId(instanceId, existingIds);
|
||||
const showInstanceIdError = hasAttemptedSubmit && instanceIdError !== null;
|
||||
const previewLabel = label.trim() || `${driverOption.label} Workspace`;
|
||||
@@ -230,250 +236,256 @@ function AddProviderInstanceDialogContent({ onOpenChange }: AddProviderInstanceD
|
||||
]);
|
||||
|
||||
return (
|
||||
<DialogPopup className="max-w-xl overflow-hidden">
|
||||
<div className="flex min-h-0 flex-col overflow-hidden border-foreground/10 bg-background shadow-2xl">
|
||||
<DialogHeader className="border-b border-border/70 bg-background">
|
||||
<DialogTitle>Add provider instance</DialogTitle>
|
||||
<DialogDescription>
|
||||
Configure an additional provider instance — for example, a second Codex install pointed
|
||||
at a different workspace.
|
||||
</DialogDescription>
|
||||
<div className="grid grid-cols-3 gap-2">
|
||||
{wizardSteps.map((step, index) => (
|
||||
<button
|
||||
key={step}
|
||||
type="button"
|
||||
className={cn(
|
||||
"grid min-w-0 grid-cols-[1rem_minmax(0,1fr)] gap-x-2 rounded-lg border px-3 py-2 text-left",
|
||||
index === wizardStep
|
||||
? "border-primary bg-primary/10 ring-1 ring-primary/25"
|
||||
: index < wizardStep
|
||||
? "border-border bg-background"
|
||||
: "border-border bg-muted/40",
|
||||
)}
|
||||
onClick={() => setWizardStep(index)}
|
||||
>
|
||||
<span
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogPopup className="max-w-xl overflow-hidden">
|
||||
<div className="flex min-h-0 flex-col overflow-hidden border-foreground/10 bg-background shadow-2xl">
|
||||
<DialogHeader className="border-b border-border/70 bg-background">
|
||||
<DialogTitle>Add provider instance</DialogTitle>
|
||||
<DialogDescription>
|
||||
Configure an additional provider instance — for example, a second Codex install
|
||||
pointed at a different workspace.
|
||||
</DialogDescription>
|
||||
<div className="grid grid-cols-3 gap-2">
|
||||
{wizardSteps.map((step, index) => (
|
||||
<button
|
||||
key={step}
|
||||
type="button"
|
||||
className={cn(
|
||||
"row-span-2 mt-0.5 grid size-4 place-items-center rounded-full border",
|
||||
index < wizardStep
|
||||
? "border-primary bg-primary text-primary-foreground"
|
||||
: index === wizardStep
|
||||
? "border-primary bg-background"
|
||||
: "border-muted-foreground/35 bg-background",
|
||||
"grid min-w-0 grid-cols-[1rem_minmax(0,1fr)] gap-x-2 rounded-lg border px-3 py-2 text-left",
|
||||
index === wizardStep
|
||||
? "border-primary bg-primary/10 ring-1 ring-primary/25"
|
||||
: index < wizardStep
|
||||
? "border-border bg-background"
|
||||
: "border-border bg-muted/40",
|
||||
)}
|
||||
aria-hidden
|
||||
onClick={() => setWizardStep(index)}
|
||||
>
|
||||
{index < wizardStep ? <CheckIcon className="size-3" /> : null}
|
||||
</span>
|
||||
<span className="text-[10px] font-medium uppercase text-muted-foreground">
|
||||
Step {index + 1}
|
||||
</span>
|
||||
<span className="truncate text-xs font-semibold text-foreground">
|
||||
{step}
|
||||
{index < wizardStep && wizardStepSummaries[index]
|
||||
? `: ${wizardStepSummaries[index]}`
|
||||
: ""}
|
||||
</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</DialogHeader>
|
||||
|
||||
<div
|
||||
data-slot="dialog-panel"
|
||||
className="space-y-4 border-b border-border/70 bg-muted/20 px-6 py-5"
|
||||
>
|
||||
<AnimatedHeight>
|
||||
<div className={cn("grid gap-2", wizardStep !== 0 && "hidden")}>
|
||||
<span id="add-instance-driver-label" className="text-xs font-medium text-foreground">
|
||||
Driver
|
||||
</span>
|
||||
<RadioGroup
|
||||
value={driver}
|
||||
onValueChange={(value) => setDriver(ProviderDriverKind.make(value))}
|
||||
aria-labelledby="add-instance-driver-label"
|
||||
className="grid grid-cols-2 gap-2.5"
|
||||
>
|
||||
{DRIVER_OPTIONS.map((option) => {
|
||||
const IconComponent = option.icon;
|
||||
const isSelected = option.value === driver;
|
||||
return (
|
||||
<RadioPrimitive.Root
|
||||
key={option.value}
|
||||
value={option.value}
|
||||
className={cn(
|
||||
"relative flex cursor-pointer items-center gap-3 rounded-lg border px-3 py-3 text-left outline-none transition-[background-color,border-color,box-shadow]",
|
||||
"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",
|
||||
isSelected
|
||||
? "border-primary bg-background shadow-sm ring-2 ring-primary/35"
|
||||
: "border-border bg-background hover:border-foreground/20 hover:bg-muted/50",
|
||||
)}
|
||||
>
|
||||
<IconComponent className="size-5 shrink-0" aria-hidden />
|
||||
<span className="min-w-0 flex-1 truncate text-sm font-medium text-foreground">
|
||||
{option.label}
|
||||
</span>
|
||||
{option.badgeLabel ? (
|
||||
<Badge variant="warning" size="sm">
|
||||
{option.badgeLabel}
|
||||
</Badge>
|
||||
) : null}
|
||||
</RadioPrimitive.Root>
|
||||
);
|
||||
})}
|
||||
{COMING_SOON_DRIVER_OPTIONS.map((option) => {
|
||||
const IconComponent = option.icon;
|
||||
return (
|
||||
<RadioPrimitive.Root
|
||||
key={option.value}
|
||||
value={option.value}
|
||||
disabled
|
||||
className={cn(
|
||||
"relative flex cursor-not-allowed items-center gap-3 rounded-lg border border-border bg-background px-3 py-3 text-left opacity-55 outline-none",
|
||||
)}
|
||||
>
|
||||
<IconComponent
|
||||
className="size-5 shrink-0 text-muted-foreground"
|
||||
aria-hidden
|
||||
/>
|
||||
<span className="min-w-0 flex-1 truncate text-sm font-medium text-foreground">
|
||||
{option.label}
|
||||
</span>
|
||||
<Badge variant="warning" size="sm">
|
||||
Coming Soon
|
||||
</Badge>
|
||||
</RadioPrimitive.Root>
|
||||
);
|
||||
})}
|
||||
</RadioGroup>
|
||||
<span
|
||||
className={cn(
|
||||
"row-span-2 mt-0.5 grid size-4 place-items-center rounded-full border",
|
||||
index < wizardStep
|
||||
? "border-primary bg-primary text-primary-foreground"
|
||||
: index === wizardStep
|
||||
? "border-primary bg-background"
|
||||
: "border-muted-foreground/35 bg-background",
|
||||
)}
|
||||
aria-hidden
|
||||
>
|
||||
{index < wizardStep ? <CheckIcon className="size-3" /> : null}
|
||||
</span>
|
||||
<span className="text-[10px] font-medium uppercase text-muted-foreground">
|
||||
Step {index + 1}
|
||||
</span>
|
||||
<span className="truncate text-xs font-semibold text-foreground">
|
||||
{step}
|
||||
{index < wizardStep && wizardStepSummaries[index]
|
||||
? `: ${wizardStepSummaries[index]}`
|
||||
: ""}
|
||||
</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</DialogHeader>
|
||||
|
||||
<label className={cn("grid gap-2", wizardStep !== 1 && "hidden")}>
|
||||
<span className="text-xs font-medium text-foreground">Label</span>
|
||||
<Input
|
||||
className="bg-background"
|
||||
placeholder="e.g. Work"
|
||||
value={label}
|
||||
onChange={(event) => setLabel(event.target.value)}
|
||||
/>
|
||||
<span className="text-[11px] text-muted-foreground">
|
||||
Shown in the provider list. Optional.
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<label className={cn("grid gap-2", wizardStep !== 1 && "hidden")}>
|
||||
<span className="text-xs font-medium text-foreground">Instance ID</span>
|
||||
<Input
|
||||
className="bg-background"
|
||||
placeholder={`${driver}_work`}
|
||||
value={instanceId}
|
||||
onChange={(event) => {
|
||||
setCustomInstanceId(event.target.value);
|
||||
}}
|
||||
aria-invalid={showInstanceIdError}
|
||||
/>
|
||||
{showInstanceIdError ? (
|
||||
<span className="text-[11px] text-destructive">{instanceIdError}</span>
|
||||
) : (
|
||||
<span className="text-[11px] text-muted-foreground">
|
||||
Routing key used by threads and sessions. Letters, digits, '-', or '_'.
|
||||
<div
|
||||
data-slot="dialog-panel"
|
||||
className="space-y-4 border-b border-border/70 bg-muted/20 px-6 py-5"
|
||||
>
|
||||
<AnimatedHeight>
|
||||
<div className={cn("grid gap-2", wizardStep !== 0 && "hidden")}>
|
||||
<span
|
||||
id="add-instance-driver-label"
|
||||
className="text-xs font-medium text-foreground"
|
||||
>
|
||||
Driver
|
||||
</span>
|
||||
)}
|
||||
</label>
|
||||
|
||||
<div className={cn("grid gap-2", wizardStep !== 1 && "hidden")}>
|
||||
<span className="text-xs font-medium text-foreground">Accent color</span>
|
||||
<div className="flex min-w-0 flex-wrap items-center gap-2">
|
||||
<input
|
||||
type="color"
|
||||
value={normalizeProviderAccentColor(accentColor) ?? PROVIDER_ACCENT_SWATCHES[0]}
|
||||
onChange={(event) => setAccentColor(event.target.value)}
|
||||
aria-label="Provider instance accent color"
|
||||
className="h-8 w-10 cursor-pointer rounded-xl border border-input bg-background p-0.5"
|
||||
/>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{PROVIDER_ACCENT_SWATCHES.map((swatch) => {
|
||||
const selected = accentColor.toLowerCase() === swatch;
|
||||
<RadioGroup
|
||||
value={driver}
|
||||
onValueChange={(value) => setDriver(ProviderDriverKind.make(value))}
|
||||
aria-labelledby="add-instance-driver-label"
|
||||
className="grid grid-cols-2 gap-2.5"
|
||||
>
|
||||
{DRIVER_OPTIONS.map((option) => {
|
||||
const IconComponent = option.icon;
|
||||
const isSelected = option.value === driver;
|
||||
return (
|
||||
<button
|
||||
key={swatch}
|
||||
type="button"
|
||||
<RadioPrimitive.Root
|
||||
key={option.value}
|
||||
value={option.value}
|
||||
className={cn(
|
||||
"size-6 cursor-pointer rounded-full border transition",
|
||||
selected
|
||||
? "scale-110 border-foreground ring-2 ring-ring ring-offset-1 ring-offset-background"
|
||||
: "border-black/10 hover:scale-105 dark:border-white/20",
|
||||
"relative flex cursor-pointer items-center gap-3 rounded-lg border px-3 py-3 text-left outline-none transition-[background-color,border-color,box-shadow]",
|
||||
"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",
|
||||
isSelected
|
||||
? "border-primary bg-background shadow-sm ring-2 ring-primary/35"
|
||||
: "border-border bg-background hover:border-foreground/20 hover:bg-muted/50",
|
||||
)}
|
||||
style={{ backgroundColor: swatch }}
|
||||
onClick={() => setAccentColor(swatch)}
|
||||
aria-label={`Use ${swatch} accent`}
|
||||
/>
|
||||
>
|
||||
<IconComponent className="size-5 shrink-0" aria-hidden />
|
||||
<span className="min-w-0 flex-1 truncate text-sm font-medium text-foreground">
|
||||
{option.label}
|
||||
</span>
|
||||
{option.badgeLabel ? (
|
||||
<Badge variant="warning" size="sm">
|
||||
{option.badgeLabel}
|
||||
</Badge>
|
||||
) : null}
|
||||
</RadioPrimitive.Root>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
{accentColor ? (
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-7 px-2 text-xs text-muted-foreground"
|
||||
onClick={() => setAccentColor("")}
|
||||
>
|
||||
Clear
|
||||
</Button>
|
||||
) : null}
|
||||
{COMING_SOON_DRIVER_OPTIONS.map((option) => {
|
||||
const IconComponent = option.icon;
|
||||
return (
|
||||
<RadioPrimitive.Root
|
||||
key={option.value}
|
||||
value={option.value}
|
||||
disabled
|
||||
className={cn(
|
||||
"relative flex cursor-not-allowed items-center gap-3 rounded-lg border border-border bg-background px-3 py-3 text-left opacity-55 outline-none",
|
||||
)}
|
||||
>
|
||||
<IconComponent
|
||||
className="size-5 shrink-0 text-muted-foreground"
|
||||
aria-hidden
|
||||
/>
|
||||
<span className="min-w-0 flex-1 truncate text-sm font-medium text-foreground">
|
||||
{option.label}
|
||||
</span>
|
||||
<Badge variant="warning" size="sm">
|
||||
Coming Soon
|
||||
</Badge>
|
||||
</RadioPrimitive.Root>
|
||||
);
|
||||
})}
|
||||
</RadioGroup>
|
||||
</div>
|
||||
<span className="text-[11px] text-muted-foreground">
|
||||
Optional marker shown in the picker.
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{driverSettingsFields.length > 0 ? (
|
||||
<div className={cn("grid gap-4", wizardStep !== 2 && "hidden")}>
|
||||
<ProviderSettingsForm
|
||||
definition={driverOption}
|
||||
value={configDraft}
|
||||
idPrefix={`add-provider-${driver}`}
|
||||
variant="dialog"
|
||||
onChange={setConfigDraft}
|
||||
<label className={cn("grid gap-2", wizardStep !== 1 && "hidden")}>
|
||||
<span className="text-xs font-medium text-foreground">Label</span>
|
||||
<Input
|
||||
className="bg-background"
|
||||
placeholder="e.g. Work"
|
||||
value={label}
|
||||
onChange={(event) => setLabel(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
) : wizardStep === 2 ? (
|
||||
<div className="grid gap-2">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
This driver has no required configuration. You can add the instance now.
|
||||
</p>
|
||||
</div>
|
||||
) : null}
|
||||
</AnimatedHeight>
|
||||
</div>
|
||||
<span className="text-[11px] text-muted-foreground">
|
||||
Shown in the provider list. Optional.
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<DialogFooter className="border-t bg-background">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
if (wizardStep === 0) {
|
||||
onOpenChange(false);
|
||||
return;
|
||||
}
|
||||
setWizardStep((step) => Math.max(0, step - 1));
|
||||
}}
|
||||
>
|
||||
{wizardStep === 0 ? "Cancel" : "Back"}
|
||||
</Button>
|
||||
{wizardStep < wizardSteps.length - 1 ? (
|
||||
<Button size="sm" onClick={() => setWizardStep((step) => Math.min(2, step + 1))}>
|
||||
Next
|
||||
<label className={cn("grid gap-2", wizardStep !== 1 && "hidden")}>
|
||||
<span className="text-xs font-medium text-foreground">Instance ID</span>
|
||||
<Input
|
||||
className="bg-background"
|
||||
placeholder={`${driver}_work`}
|
||||
value={instanceId}
|
||||
onChange={(event) => {
|
||||
setInstanceIdDirty(true);
|
||||
setInstanceId(event.target.value);
|
||||
}}
|
||||
aria-invalid={showInstanceIdError}
|
||||
/>
|
||||
{showInstanceIdError ? (
|
||||
<span className="text-[11px] text-destructive">{instanceIdError}</span>
|
||||
) : (
|
||||
<span className="text-[11px] text-muted-foreground">
|
||||
Routing key used by threads and sessions. Letters, digits, '-', or '_'.
|
||||
</span>
|
||||
)}
|
||||
</label>
|
||||
|
||||
<div className={cn("grid gap-2", wizardStep !== 1 && "hidden")}>
|
||||
<span className="text-xs font-medium text-foreground">Accent color</span>
|
||||
<div className="flex min-w-0 flex-wrap items-center gap-2">
|
||||
<input
|
||||
type="color"
|
||||
value={normalizeProviderAccentColor(accentColor) ?? PROVIDER_ACCENT_SWATCHES[0]}
|
||||
onChange={(event) => setAccentColor(event.target.value)}
|
||||
aria-label="Provider instance accent color"
|
||||
className="h-8 w-10 cursor-pointer rounded-xl border border-input bg-background p-0.5"
|
||||
/>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{PROVIDER_ACCENT_SWATCHES.map((swatch) => {
|
||||
const selected = accentColor.toLowerCase() === swatch;
|
||||
return (
|
||||
<button
|
||||
key={swatch}
|
||||
type="button"
|
||||
className={cn(
|
||||
"size-6 cursor-pointer rounded-full border transition",
|
||||
selected
|
||||
? "scale-110 border-foreground ring-2 ring-ring ring-offset-1 ring-offset-background"
|
||||
: "border-black/10 hover:scale-105 dark:border-white/20",
|
||||
)}
|
||||
style={{ backgroundColor: swatch }}
|
||||
onClick={() => setAccentColor(swatch)}
|
||||
aria-label={`Use ${swatch} accent`}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
{accentColor ? (
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-7 px-2 text-xs text-muted-foreground"
|
||||
onClick={() => setAccentColor("")}
|
||||
>
|
||||
Clear
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
<span className="text-[11px] text-muted-foreground">
|
||||
Optional marker shown in the picker.
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{driverSettingsFields.length > 0 ? (
|
||||
<div className={cn("grid gap-4", wizardStep !== 2 && "hidden")}>
|
||||
<ProviderSettingsForm
|
||||
definition={driverOption}
|
||||
value={configDraft}
|
||||
idPrefix={`add-provider-${driver}`}
|
||||
variant="dialog"
|
||||
onChange={setConfigDraft}
|
||||
/>
|
||||
</div>
|
||||
) : wizardStep === 2 ? (
|
||||
<div className="grid gap-2">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
This driver has no required configuration. You can add the instance now.
|
||||
</p>
|
||||
</div>
|
||||
) : null}
|
||||
</AnimatedHeight>
|
||||
</div>
|
||||
|
||||
<DialogFooter className="border-t bg-background">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
if (wizardStep === 0) {
|
||||
onOpenChange(false);
|
||||
return;
|
||||
}
|
||||
setWizardStep((step) => Math.max(0, step - 1));
|
||||
}}
|
||||
>
|
||||
{wizardStep === 0 ? "Cancel" : "Back"}
|
||||
</Button>
|
||||
) : (
|
||||
<Button size="sm" onClick={handleSave}>
|
||||
Add instance
|
||||
</Button>
|
||||
)}
|
||||
</DialogFooter>
|
||||
</div>
|
||||
</DialogPopup>
|
||||
{wizardStep < wizardSteps.length - 1 ? (
|
||||
<Button size="sm" onClick={() => setWizardStep((step) => Math.min(2, step + 1))}>
|
||||
Next
|
||||
</Button>
|
||||
) : (
|
||||
<Button size="sm" onClick={handleSave}>
|
||||
Add instance
|
||||
</Button>
|
||||
)}
|
||||
</DialogFooter>
|
||||
</div>
|
||||
</DialogPopup>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -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,6 @@
|
||||
{
|
||||
"name": "@t3tools/contracts",
|
||||
"version": "0.0.23",
|
||||
"version": "0.0.24",
|
||||
"private": true,
|
||||
"files": [
|
||||
"dist"
|
||||
|
||||
@@ -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