Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38f6a0b78a | ||
|
|
8b2adcc9fd | ||
|
|
4f0f24f055 |
No files matched your search
@@ -17,7 +17,7 @@ import {
|
||||
SshLaunchError,
|
||||
SshPairingError,
|
||||
SshPasswordPromptError,
|
||||
type SshReadinessError,
|
||||
SshReadinessError,
|
||||
} from "@t3tools/ssh/errors";
|
||||
import { SshEnvironmentManager, type RemoteT3RunnerOptions } from "@t3tools/ssh/tunnel";
|
||||
import * as Context from "effect/Context";
|
||||
@@ -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";
|
||||
|
||||
@@ -80,13 +79,11 @@ function discoverDesktopSshHostsEffect(input?: { readonly homeDir?: string }) {
|
||||
return discoverSshHosts(input ?? {});
|
||||
}
|
||||
|
||||
const isSshPasswordPromptError = Schema.is(SshPasswordPromptError);
|
||||
|
||||
export function isDesktopSshPasswordPromptCancellation(
|
||||
error: unknown,
|
||||
): error is SshPasswordPromptError {
|
||||
return (
|
||||
isSshPasswordPromptError(error) &&
|
||||
error instanceof SshPasswordPromptError &&
|
||||
DesktopSshPasswordPrompts.isDesktopSshPasswordPromptCancellation(error.cause)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ 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";
|
||||
@@ -32,8 +31,6 @@ function makeLayer(
|
||||
);
|
||||
}
|
||||
|
||||
const isSshHttpBridgeError = Schema.is(SshHttpBridgeError);
|
||||
|
||||
describe("DesktopSshRemoteApi", () => {
|
||||
it.effect("fetches and decodes the remote environment descriptor", () => {
|
||||
const requestUrls: string[] = [];
|
||||
@@ -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));
|
||||
});
|
||||
});
|
||||
@@ -727,9 +727,16 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
model: selectedModel,
|
||||
models: selectedProviderModels,
|
||||
prompt,
|
||||
modelOptions: composerModelOptions?.[selectedProvider],
|
||||
modelOptions: composerModelOptions?.[selectedInstanceId],
|
||||
}),
|
||||
[composerModelOptions, prompt, selectedModel, selectedProvider, selectedProviderModels],
|
||||
[
|
||||
composerModelOptions,
|
||||
prompt,
|
||||
selectedInstanceId,
|
||||
selectedModel,
|
||||
selectedProvider,
|
||||
selectedProviderModels,
|
||||
],
|
||||
);
|
||||
|
||||
const selectedPromptEffort = composerProviderState.promptEffort;
|
||||
@@ -1018,21 +1025,23 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
|
||||
const providerTraitsMenuContent = renderProviderTraitsMenuContent({
|
||||
provider: selectedProvider,
|
||||
instanceId: selectedInstanceId,
|
||||
...(routeKind === "server" ? { threadRef: routeThreadRef } : {}),
|
||||
...(routeKind === "draft" && draftId ? { draftId } : {}),
|
||||
model: selectedModel,
|
||||
models: selectedProviderModels,
|
||||
modelOptions: composerModelOptions?.[selectedProvider],
|
||||
modelOptions: composerModelOptions?.[selectedInstanceId],
|
||||
prompt,
|
||||
onPromptChange: setPromptFromTraits,
|
||||
});
|
||||
const providerTraitsPicker = renderProviderTraitsPicker({
|
||||
provider: selectedProvider,
|
||||
instanceId: selectedInstanceId,
|
||||
...(routeKind === "server" ? { threadRef: routeThreadRef } : {}),
|
||||
...(routeKind === "draft" && draftId ? { draftId } : {}),
|
||||
model: selectedModel,
|
||||
models: selectedProviderModels,
|
||||
modelOptions: composerModelOptions?.[selectedProvider],
|
||||
modelOptions: composerModelOptions?.[selectedInstanceId],
|
||||
prompt,
|
||||
onPromptChange: setPromptFromTraits,
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
type ProviderDriverKind,
|
||||
type ProviderInstanceId,
|
||||
type ProviderOptionDescriptor,
|
||||
type ProviderOptionSelection,
|
||||
type ScopedThreadRef,
|
||||
@@ -196,6 +197,7 @@ export function shouldRenderTraitsControls(input: {
|
||||
|
||||
export interface TraitsMenuContentProps {
|
||||
provider: ProviderDriverKind;
|
||||
instanceId?: ProviderInstanceId;
|
||||
models: ReadonlyArray<ServerProviderModel>;
|
||||
model: string | null | undefined;
|
||||
prompt: string;
|
||||
@@ -208,6 +210,7 @@ export interface TraitsMenuContentProps {
|
||||
|
||||
export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
|
||||
provider,
|
||||
instanceId,
|
||||
models,
|
||||
model,
|
||||
prompt,
|
||||
@@ -228,11 +231,12 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
|
||||
return;
|
||||
}
|
||||
setProviderModelOptions(threadTarget, provider, nextOptions, {
|
||||
...(instanceId ? { instanceId } : {}),
|
||||
model,
|
||||
persistSticky: true,
|
||||
});
|
||||
},
|
||||
[model, persistence, provider, setProviderModelOptions],
|
||||
[instanceId, model, persistence, provider, setProviderModelOptions],
|
||||
);
|
||||
const {
|
||||
descriptors,
|
||||
@@ -343,6 +347,7 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
|
||||
|
||||
export const TraitsPicker = memo(function TraitsPicker({
|
||||
provider,
|
||||
instanceId,
|
||||
models,
|
||||
model,
|
||||
prompt,
|
||||
@@ -431,6 +436,7 @@ export const TraitsPicker = memo(function TraitsPicker({
|
||||
<MenuPopup align="start">
|
||||
<TraitsMenuContent
|
||||
provider={provider}
|
||||
{...(instanceId ? { instanceId } : {})}
|
||||
models={models}
|
||||
model={model}
|
||||
prompt={prompt}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
type ProviderDriverKind,
|
||||
type ProviderInstanceId,
|
||||
type ProviderOptionSelection,
|
||||
type ScopedThreadRef,
|
||||
type ServerProviderModel,
|
||||
@@ -35,6 +36,7 @@ export type ComposerProviderState = {
|
||||
|
||||
type TraitsRenderInput = {
|
||||
provider: ProviderDriverKind;
|
||||
instanceId?: ProviderInstanceId;
|
||||
threadRef?: ScopedThreadRef;
|
||||
draftId?: DraftId;
|
||||
model: string;
|
||||
@@ -76,8 +78,17 @@ function renderTraitsControl(
|
||||
Component: typeof TraitsMenuContent | typeof TraitsPicker,
|
||||
input: TraitsRenderInput,
|
||||
): ReactNode {
|
||||
const { provider, threadRef, draftId, model, models, modelOptions, prompt, onPromptChange } =
|
||||
input;
|
||||
const {
|
||||
provider,
|
||||
instanceId,
|
||||
threadRef,
|
||||
draftId,
|
||||
model,
|
||||
models,
|
||||
modelOptions,
|
||||
prompt,
|
||||
onPromptChange,
|
||||
} = input;
|
||||
const hasTarget = threadRef !== undefined || draftId !== undefined;
|
||||
if (
|
||||
!hasTarget ||
|
||||
@@ -88,6 +99,7 @@ function renderTraitsControl(
|
||||
return (
|
||||
<Component
|
||||
provider={provider}
|
||||
{...(instanceId ? { instanceId } : {})}
|
||||
models={models}
|
||||
{...(threadRef ? { threadRef } : {})}
|
||||
{...(draftId ? { draftId } : {})}
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
import { useNavigate } from "@tanstack/react-router";
|
||||
import type { ServerProvider } from "@t3tools/contracts";
|
||||
import { CircleCheckIcon, DownloadIcon, LoaderIcon, TriangleAlertIcon, XIcon } from "lucide-react";
|
||||
import { useCallback, useEffect, useState, type CSSProperties } from "react";
|
||||
import {
|
||||
useCallback,
|
||||
useEffect,
|
||||
useRef,
|
||||
useState,
|
||||
type CSSProperties,
|
||||
type Dispatch,
|
||||
type SetStateAction,
|
||||
type TransitionEvent,
|
||||
} from "react";
|
||||
|
||||
import { useServerProviders } from "../../rpc/serverState";
|
||||
import {
|
||||
@@ -37,48 +46,36 @@ function latestProviderCheckedAt(
|
||||
);
|
||||
}
|
||||
|
||||
export function SidebarProviderUpdatePill() {
|
||||
const navigate = useNavigate();
|
||||
const providers = useServerProviders();
|
||||
const [dismissedKeys, setDismissedKeys] = useState<ReadonlySet<string>>(() => new Set());
|
||||
const [renderedView, setRenderedView] = useState<ProviderUpdateSidebarPillView | null>(null);
|
||||
const [pendingView, setPendingView] = useState<ProviderUpdateSidebarPillView | null>(null);
|
||||
function useProviderUpdateVisibleAfterIso(
|
||||
providers: ReadonlyArray<Pick<ServerProvider, "checkedAt">>,
|
||||
): string | undefined {
|
||||
const visibleAfterIsoRef = useRef<string | undefined>(undefined);
|
||||
|
||||
if (visibleAfterIsoRef.current === undefined) {
|
||||
visibleAfterIsoRef.current = latestProviderCheckedAt(providers);
|
||||
}
|
||||
|
||||
return visibleAfterIsoRef.current;
|
||||
}
|
||||
|
||||
function useDisplayedProviderUpdatePill(input: {
|
||||
view: ProviderUpdateSidebarPillView | null;
|
||||
setDismissedKeys: Dispatch<SetStateAction<ReadonlySet<string>>>;
|
||||
}) {
|
||||
const { view, setDismissedKeys } = input;
|
||||
const [renderedView, setRenderedView] = useState<ProviderUpdateSidebarPillView | null>(view);
|
||||
const [exitingKey, setExitingKey] = useState<string | null>(null);
|
||||
const [dismissAfterExitKey, setDismissAfterExitKey] = useState<string | null>(null);
|
||||
const [visibleAfterIso, setVisibleAfterIso] = useState<string | undefined>();
|
||||
const effectiveVisibleAfterIso = visibleAfterIso ?? latestProviderCheckedAt(providers);
|
||||
const view = getProviderUpdateSidebarPillView(providers, {
|
||||
...(effectiveVisibleAfterIso !== undefined
|
||||
? { visibleAfterIso: effectiveVisibleAfterIso }
|
||||
: {}),
|
||||
dismissedKeys,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (visibleAfterIso === undefined && effectiveVisibleAfterIso !== undefined) {
|
||||
setVisibleAfterIso(effectiveVisibleAfterIso);
|
||||
}
|
||||
}, [effectiveVisibleAfterIso, visibleAfterIso]);
|
||||
|
||||
const openProviderSettings = useCallback(() => {
|
||||
void navigate({ to: "/settings/providers" });
|
||||
}, [navigate]);
|
||||
const displayedView = renderedView ?? view;
|
||||
const dismissAfterVisibleMs = displayedView?.dismissAfterVisibleMs;
|
||||
const viewKey = displayedView?.key ?? null;
|
||||
const showDismissProgress =
|
||||
dismissAfterVisibleMs !== undefined &&
|
||||
displayedView?.tone !== "loading" &&
|
||||
exitingKey !== viewKey;
|
||||
const pendingViewRef = useRef<ProviderUpdateSidebarPillView | null>(null);
|
||||
const dismissAfterExitKeyRef = useRef<string | null>(null);
|
||||
|
||||
const startExit = useCallback(
|
||||
(key: string, nextView: ProviderUpdateSidebarPillView | null, dismissKey?: string) => {
|
||||
if (exitingKey === key) {
|
||||
return;
|
||||
}
|
||||
setPendingView(nextView);
|
||||
pendingViewRef.current = nextView;
|
||||
dismissAfterExitKeyRef.current = dismissKey ?? null;
|
||||
setExitingKey(key);
|
||||
setDismissAfterExitKey(dismissKey ?? null);
|
||||
},
|
||||
[exitingKey],
|
||||
);
|
||||
@@ -103,6 +100,46 @@ export function SidebarProviderUpdatePill() {
|
||||
}
|
||||
}, [exitingKey, renderedView, startExit, view]);
|
||||
|
||||
const displayedView = renderedView ?? view;
|
||||
const onTransitionEnd = useCallback(
|
||||
(event: TransitionEvent<HTMLDivElement>) => {
|
||||
if (event.target !== event.currentTarget) {
|
||||
return;
|
||||
}
|
||||
if (!displayedView || exitingKey !== displayedView.key) {
|
||||
return;
|
||||
}
|
||||
if (dismissAfterExitKeyRef.current === displayedView.key) {
|
||||
setDismissedKeys((previous) => new Set(previous).add(displayedView.key));
|
||||
}
|
||||
setRenderedView(pendingViewRef.current);
|
||||
pendingViewRef.current = null;
|
||||
dismissAfterExitKeyRef.current = null;
|
||||
setExitingKey(null);
|
||||
},
|
||||
[displayedView, exitingKey, setDismissedKeys],
|
||||
);
|
||||
|
||||
return {
|
||||
displayedView,
|
||||
exitingKey,
|
||||
onTransitionEnd,
|
||||
startExit,
|
||||
};
|
||||
}
|
||||
|
||||
function useProviderUpdateAutoDismiss(input: {
|
||||
dismissAfterVisibleMs: number | undefined;
|
||||
exitingKey: string | null;
|
||||
startExit: (
|
||||
key: string,
|
||||
nextView: ProviderUpdateSidebarPillView | null,
|
||||
dismissKey?: string,
|
||||
) => void;
|
||||
viewKey: string | null;
|
||||
}) {
|
||||
const { dismissAfterVisibleMs, exitingKey, startExit, viewKey } = input;
|
||||
|
||||
useEffect(() => {
|
||||
if (!dismissAfterVisibleMs || !viewKey) {
|
||||
return;
|
||||
@@ -116,6 +153,40 @@ export function SidebarProviderUpdatePill() {
|
||||
|
||||
return () => window.clearTimeout(timeoutId);
|
||||
}, [dismissAfterVisibleMs, exitingKey, startExit, viewKey]);
|
||||
}
|
||||
|
||||
export function SidebarProviderUpdatePill() {
|
||||
const navigate = useNavigate();
|
||||
const providers = useServerProviders();
|
||||
const [dismissedKeys, setDismissedKeys] = useState<ReadonlySet<string>>(() => new Set());
|
||||
const effectiveVisibleAfterIso = useProviderUpdateVisibleAfterIso(providers);
|
||||
const view = getProviderUpdateSidebarPillView(providers, {
|
||||
...(effectiveVisibleAfterIso !== undefined
|
||||
? { visibleAfterIso: effectiveVisibleAfterIso }
|
||||
: {}),
|
||||
dismissedKeys,
|
||||
});
|
||||
|
||||
const openProviderSettings = useCallback(() => {
|
||||
void navigate({ to: "/settings/providers" });
|
||||
}, [navigate]);
|
||||
const { displayedView, exitingKey, onTransitionEnd, startExit } = useDisplayedProviderUpdatePill({
|
||||
view,
|
||||
setDismissedKeys,
|
||||
});
|
||||
const dismissAfterVisibleMs = displayedView?.dismissAfterVisibleMs;
|
||||
const viewKey = displayedView?.key ?? null;
|
||||
const showDismissProgress =
|
||||
dismissAfterVisibleMs !== undefined &&
|
||||
displayedView?.tone !== "loading" &&
|
||||
exitingKey !== viewKey;
|
||||
|
||||
useProviderUpdateAutoDismiss({
|
||||
dismissAfterVisibleMs,
|
||||
exitingKey,
|
||||
startExit,
|
||||
viewKey,
|
||||
});
|
||||
|
||||
if (!displayedView) {
|
||||
return null;
|
||||
@@ -130,21 +201,7 @@ export function SidebarProviderUpdatePill() {
|
||||
? "pointer-events-none translate-y-1.5 opacity-0"
|
||||
: "translate-y-0 opacity-100"
|
||||
}`}
|
||||
onTransitionEnd={(event) => {
|
||||
if (event.target !== event.currentTarget) {
|
||||
return;
|
||||
}
|
||||
if (!displayedView || exitingKey !== displayedView.key) {
|
||||
return;
|
||||
}
|
||||
if (dismissAfterExitKey === displayedView.key) {
|
||||
setDismissedKeys((previous) => new Set(previous).add(displayedView.key));
|
||||
}
|
||||
setRenderedView(pendingView);
|
||||
setPendingView(null);
|
||||
setExitingKey(null);
|
||||
setDismissAfterExitKey(null);
|
||||
}}
|
||||
onTransitionEnd={onTransitionEnd}
|
||||
>
|
||||
{showDismissProgress ? (
|
||||
<div
|
||||
|
||||
@@ -21,6 +21,7 @@ import { createModelSelection } from "@t3tools/shared/model";
|
||||
// `stickyModelSelectionByProvider` maps are keyed by `ProviderInstanceId`
|
||||
// in production; these aliases keep the legacy-key migration tests concise.
|
||||
const CODEX_INSTANCE = ProviderInstanceId.make("codex");
|
||||
const CODEX_SECONDARY_INSTANCE = ProviderInstanceId.make("codex_secondary");
|
||||
const CLAUDE_AGENT_INSTANCE = ProviderInstanceId.make("claudeAgent");
|
||||
const CURSOR_INSTANCE = ProviderInstanceId.make("cursor");
|
||||
const CODEX_DRIVER = ProviderDriverKind.make("codex");
|
||||
@@ -1201,6 +1202,43 @@ describe("composerDraftStore modelSelection", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("stores provider option changes on a selected custom instance", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
|
||||
store.setProviderModelOptions(
|
||||
threadRef,
|
||||
CODEX_DRIVER,
|
||||
toSelections({ reasoningEffort: "low" }),
|
||||
{
|
||||
instanceId: CODEX_SECONDARY_INSTANCE,
|
||||
model: "gpt-5-codex",
|
||||
persistSticky: true,
|
||||
},
|
||||
);
|
||||
|
||||
expect(
|
||||
draftFor(threadId, TEST_ENVIRONMENT_ID)?.modelSelectionByProvider[CODEX_SECONDARY_INSTANCE],
|
||||
).toEqual(
|
||||
expect.objectContaining({
|
||||
instanceId: CODEX_SECONDARY_INSTANCE,
|
||||
options: [{ id: "reasoningEffort", value: "low" }],
|
||||
}),
|
||||
);
|
||||
expect(draftFor(threadId, TEST_ENVIRONMENT_ID)?.activeProvider).toBe(CODEX_SECONDARY_INSTANCE);
|
||||
expect(useComposerDraftStore.getState().stickyActiveProvider).toBe(CODEX_SECONDARY_INSTANCE);
|
||||
expect(useComposerDraftStore.getState().stickyModelSelectionByProvider[CODEX_INSTANCE]).toBe(
|
||||
undefined,
|
||||
);
|
||||
expect(
|
||||
useComposerDraftStore.getState().stickyModelSelectionByProvider[CODEX_SECONDARY_INSTANCE],
|
||||
).toEqual(
|
||||
expect.objectContaining({
|
||||
instanceId: CODEX_SECONDARY_INSTANCE,
|
||||
options: [{ id: "reasoningEffort", value: "low" }],
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("updates only the draft when sticky persistence is disabled", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
|
||||
|
||||
@@ -371,6 +371,7 @@ interface ComposerDraftStoreState {
|
||||
provider: ProviderDriverKind,
|
||||
nextProviderOptions: ReadonlyArray<ProviderOptionSelection> | null | undefined,
|
||||
options?: {
|
||||
instanceId?: ProviderInstanceId | null | undefined;
|
||||
model?: string | null | undefined;
|
||||
persistSticky?: boolean;
|
||||
},
|
||||
@@ -2456,7 +2457,7 @@ const composerDraftStore = create<ComposerDraftStoreState>()(
|
||||
if (normalizedProvider === null) {
|
||||
return;
|
||||
}
|
||||
const instanceKey = defaultInstanceIdForDriver(normalizedProvider);
|
||||
const instanceKey = options?.instanceId ?? defaultInstanceIdForDriver(normalizedProvider);
|
||||
const fallbackModel =
|
||||
normalizeModelSlug(options?.model, normalizedProvider) ??
|
||||
DEFAULT_MODEL_BY_PROVIDER[normalizedProvider] ??
|
||||
@@ -2501,7 +2502,9 @@ const composerDraftStore = create<ComposerDraftStoreState>()(
|
||||
const { options: _, ...rest } = stickyBase;
|
||||
nextStickyMap[instanceKey] = rest as ModelSelection;
|
||||
}
|
||||
nextStickyActiveProvider = base.activeProvider ?? instanceKey;
|
||||
nextStickyActiveProvider = options.instanceId
|
||||
? instanceKey
|
||||
: (base.activeProvider ?? instanceKey);
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -2514,6 +2517,7 @@ const composerDraftStore = create<ComposerDraftStoreState>()(
|
||||
|
||||
const nextDraft: ComposerThreadDraftState = {
|
||||
...base,
|
||||
...(options?.instanceId ? { activeProvider: instanceKey } : {}),
|
||||
modelSelectionByProvider: nextMap,
|
||||
};
|
||||
const nextDraftsByThreadKey = { ...state.draftsByThreadKey };
|
||||
|
||||
Binary file not shown.
Binary file not shown.
+38
-95
@@ -1,103 +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 SshReadinessProbeFailedError extends Schema.TaggedErrorClass<SshReadinessProbeFailedError>()(
|
||||
"SshReadinessProbeFailedError",
|
||||
{
|
||||
message: Schema.String,
|
||||
requestUrl: Schema.String,
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
},
|
||||
) {}
|
||||
export class SshReadinessError extends Data.TaggedError("SshReadinessError")<{
|
||||
readonly message: string;
|
||||
readonly cause?: unknown;
|
||||
}> {}
|
||||
|
||||
export class SshReadinessProbeTimedOutError extends Schema.TaggedErrorClass<SshReadinessProbeTimedOutError>()(
|
||||
"SshReadinessProbeTimedOutError",
|
||||
{
|
||||
message: Schema.String,
|
||||
requestUrl: Schema.String,
|
||||
attempt: Schema.Number,
|
||||
probeTimeoutMs: Schema.Number,
|
||||
},
|
||||
) {}
|
||||
|
||||
export class SshReadinessTimedOutError extends Schema.TaggedErrorClass<SshReadinessTimedOutError>()(
|
||||
"SshReadinessTimedOutError",
|
||||
{
|
||||
message: Schema.String,
|
||||
baseUrl: Schema.String,
|
||||
requestUrl: Schema.String,
|
||||
timeoutMs: Schema.Number,
|
||||
intervalMs: Schema.Number,
|
||||
probeTimeoutMs: Schema.Number,
|
||||
attempts: Schema.Number,
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
},
|
||||
) {}
|
||||
|
||||
export type SshReadinessError =
|
||||
| SshReadinessProbeFailedError
|
||||
| SshReadinessProbeTimedOutError
|
||||
| SshReadinessTimedOutError;
|
||||
|
||||
const isSshReadinessProbeFailedError = Schema.is(SshReadinessProbeFailedError);
|
||||
const isSshReadinessProbeTimedOutError = Schema.is(SshReadinessProbeTimedOutError);
|
||||
const isSshReadinessTimedOutError = Schema.is(SshReadinessTimedOutError);
|
||||
|
||||
export function isSshReadinessError(cause: unknown): cause is SshReadinessError {
|
||||
return (
|
||||
isSshReadinessProbeFailedError(cause) ||
|
||||
isSshReadinessProbeTimedOutError(cause) ||
|
||||
isSshReadinessTimedOutError(cause)
|
||||
);
|
||||
}
|
||||
|
||||
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;
|
||||
}> {}
|
||||
@@ -242,9 +242,9 @@ describe("ssh tunnel scripts", () => {
|
||||
Effect.result(
|
||||
waitForHttpReady({
|
||||
baseUrl: "http://127.0.0.1:41773/",
|
||||
timeout: Duration.seconds(1),
|
||||
interval: Duration.millis(100),
|
||||
probeTimeout: Duration.millis(250),
|
||||
timeoutMs: 1_000,
|
||||
intervalMs: 100,
|
||||
probeTimeoutMs: 250,
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
+46
-86
@@ -45,20 +45,16 @@ import {
|
||||
SshLaunchError,
|
||||
SshPairingError,
|
||||
SshPasswordPromptError,
|
||||
SshReadinessProbeFailedError,
|
||||
SshReadinessProbeTimedOutError,
|
||||
SshReadinessTimedOutError,
|
||||
isSshReadinessError,
|
||||
type SshReadinessError,
|
||||
SshReadinessError,
|
||||
} from "./errors.ts";
|
||||
|
||||
export const DEFAULT_REMOTE_PORT = 3773;
|
||||
const REMOTE_PORT_SCAN_WINDOW = 200;
|
||||
const SSH_READY_TIMEOUT = Duration.seconds(20);
|
||||
const SSH_READY_PROBE_TIMEOUT = Duration.seconds(1);
|
||||
const TUNNEL_SHUTDOWN_TIMEOUT = Duration.seconds(2);
|
||||
const REMOTE_READY_TIMEOUT = Duration.seconds(15);
|
||||
const REMOTE_REUSE_READY_TIMEOUT = Duration.seconds(2);
|
||||
const SSH_READY_TIMEOUT_MS = 20_000;
|
||||
const SSH_READY_PROBE_TIMEOUT_MS = 1_000;
|
||||
const TUNNEL_SHUTDOWN_TIMEOUT_MS = 2_000;
|
||||
const REMOTE_READY_TIMEOUT_MS = 15_000;
|
||||
const REMOTE_REUSE_READY_TIMEOUT_MS = 2_000;
|
||||
|
||||
export interface RemoteT3RunnerOptions {
|
||||
readonly packageSpec?: string;
|
||||
@@ -241,37 +237,12 @@ function applyScriptPlaceholders(
|
||||
}
|
||||
|
||||
export function describeReadinessCause(cause: unknown): unknown {
|
||||
if (isSshReadinessError(cause)) {
|
||||
const base = {
|
||||
if (cause instanceof SshReadinessError) {
|
||||
return {
|
||||
_tag: cause._tag,
|
||||
message: cause.message,
|
||||
...(cause.cause === undefined ? {} : { cause: describeReadinessCause(cause.cause) }),
|
||||
};
|
||||
switch (cause._tag) {
|
||||
case "SshReadinessProbeFailedError":
|
||||
return {
|
||||
...base,
|
||||
requestUrl: cause.requestUrl,
|
||||
...(cause.cause === undefined ? {} : { cause: describeReadinessCause(cause.cause) }),
|
||||
};
|
||||
case "SshReadinessProbeTimedOutError":
|
||||
return {
|
||||
...base,
|
||||
requestUrl: cause.requestUrl,
|
||||
attempt: cause.attempt,
|
||||
probeTimeoutMs: cause.probeTimeoutMs,
|
||||
};
|
||||
case "SshReadinessTimedOutError":
|
||||
return {
|
||||
...base,
|
||||
baseUrl: cause.baseUrl,
|
||||
requestUrl: cause.requestUrl,
|
||||
timeoutMs: cause.timeoutMs,
|
||||
intervalMs: cause.intervalMs,
|
||||
probeTimeoutMs: cause.probeTimeoutMs,
|
||||
attempts: cause.attempts,
|
||||
...(cause.cause === undefined ? {} : { cause: describeReadinessCause(cause.cause) }),
|
||||
};
|
||||
}
|
||||
}
|
||||
if (cause instanceof Error) {
|
||||
return {
|
||||
@@ -715,9 +686,9 @@ export function buildRemoteLaunchScript(input?: RemoteT3RunnerOptions): string {
|
||||
T3_WAIT_READY_SCRIPT: stripTrailingNewlines(REMOTE_WAIT_READY_SCRIPT),
|
||||
T3_DEFAULT_REMOTE_PORT: String(DEFAULT_REMOTE_PORT),
|
||||
T3_REMOTE_PORT_SCAN_WINDOW: String(REMOTE_PORT_SCAN_WINDOW),
|
||||
T3_READY_TIMEOUT_MS: String(Duration.toMillis(REMOTE_READY_TIMEOUT)),
|
||||
T3_REUSE_READY_TIMEOUT_MS: String(Duration.toMillis(REMOTE_REUSE_READY_TIMEOUT)),
|
||||
T3_READY_PROBE_TIMEOUT_MS: String(Duration.toMillis(SSH_READY_PROBE_TIMEOUT)),
|
||||
T3_READY_TIMEOUT_MS: String(REMOTE_READY_TIMEOUT_MS),
|
||||
T3_REUSE_READY_TIMEOUT_MS: String(REMOTE_REUSE_READY_TIMEOUT_MS),
|
||||
T3_READY_PROBE_TIMEOUT_MS: String(SSH_READY_PROBE_TIMEOUT_MS),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -899,21 +870,20 @@ const readRemoteServerLogTail = Effect.fn("ssh/tunnel.readRemoteServerLogTail")(
|
||||
|
||||
export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(function* (input: {
|
||||
readonly baseUrl: string;
|
||||
readonly timeout?: Duration.Input;
|
||||
readonly interval?: Duration.Input;
|
||||
readonly probeTimeout?: Duration.Input;
|
||||
readonly timeoutMs?: number;
|
||||
readonly intervalMs?: number;
|
||||
readonly probeTimeoutMs?: number;
|
||||
readonly path?: string;
|
||||
}): Effect.fn.Return<void, SshReadinessError, HttpClient.HttpClient> {
|
||||
const timeout = Duration.fromInputUnsafe(input.timeout ?? Duration.seconds(30));
|
||||
const interval = Duration.fromInputUnsafe(input.interval ?? Duration.millis(100));
|
||||
const probeTimeout = Duration.fromInputUnsafe(input.probeTimeout ?? SSH_READY_PROBE_TIMEOUT);
|
||||
const timeoutMs = Duration.toMillis(timeout);
|
||||
const intervalMs = Duration.toMillis(interval);
|
||||
const probeTimeoutMs = Duration.toMillis(probeTimeout);
|
||||
const retryPolicy = Schedule.spaced(interval);
|
||||
const timeoutMs = input.timeoutMs ?? 30_000;
|
||||
const intervalMs = input.intervalMs ?? 100;
|
||||
const probeTimeoutMs = input.probeTimeoutMs ?? SSH_READY_PROBE_TIMEOUT_MS;
|
||||
const retryPolicy = Schedule.spaced(Duration.millis(intervalMs)).pipe(
|
||||
Schedule.take(Math.max(0, Math.ceil(timeoutMs / intervalMs))),
|
||||
);
|
||||
const requestUrl = new URL(input.path ?? "/", input.baseUrl).toString();
|
||||
const client = yield* HttpClient.HttpClient;
|
||||
const lastProbeFailure = yield* Ref.make<Option.Option<unknown>>(Option.none());
|
||||
const lastProbeFailure = yield* Ref.make<unknown>(null);
|
||||
let attempt = 0;
|
||||
|
||||
yield* Effect.logDebug("ssh.tunnel.httpReady.start", {
|
||||
@@ -930,12 +900,11 @@ export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(functio
|
||||
Effect.gen(function* () {
|
||||
attempt += 1;
|
||||
const responseOption = yield* effect.pipe(
|
||||
Effect.timeoutOption(probeTimeout),
|
||||
Effect.timeoutOption(Duration.millis(probeTimeoutMs)),
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new SshReadinessProbeFailedError({
|
||||
new SshReadinessError({
|
||||
message: `Backend readiness probe failed at ${requestUrl}.`,
|
||||
requestUrl,
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
@@ -944,32 +913,30 @@ export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(functio
|
||||
onSome: Effect.succeed,
|
||||
onNone: () =>
|
||||
Effect.fail(
|
||||
new SshReadinessProbeTimedOutError({
|
||||
new SshReadinessError({
|
||||
message: `Backend readiness probe exceeded ${probeTimeoutMs}ms at ${requestUrl}.`,
|
||||
requestUrl,
|
||||
attempt,
|
||||
probeTimeoutMs,
|
||||
cause: {
|
||||
kind: "probe-timeout",
|
||||
attempt,
|
||||
probeTimeoutMs,
|
||||
},
|
||||
}),
|
||||
),
|
||||
});
|
||||
}).pipe(
|
||||
Effect.mapError((cause) =>
|
||||
isSshReadinessError(cause)
|
||||
cause instanceof SshReadinessError
|
||||
? cause
|
||||
: new SshReadinessProbeFailedError({
|
||||
: new SshReadinessError({
|
||||
message: `Backend readiness probe failed at ${requestUrl}.`,
|
||||
requestUrl,
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
Effect.tapError((cause) =>
|
||||
Ref.set(
|
||||
lastProbeFailure,
|
||||
Option.some({
|
||||
attempt,
|
||||
cause: describeReadinessCause(cause),
|
||||
}),
|
||||
),
|
||||
Ref.set(lastProbeFailure, {
|
||||
attempt,
|
||||
cause: describeReadinessCause(cause),
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -979,15 +946,14 @@ 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 SshReadinessProbeFailedError({
|
||||
: new SshReadinessError({
|
||||
message: `Backend readiness probe failed at ${requestUrl}.`,
|
||||
requestUrl,
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
Effect.timeoutOption(timeout),
|
||||
Effect.timeoutOption(Duration.millis(timeoutMs)),
|
||||
);
|
||||
|
||||
return yield* Option.match(result, {
|
||||
@@ -1007,17 +973,11 @@ export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(functio
|
||||
intervalMs,
|
||||
probeTimeoutMs,
|
||||
attempts: attempt,
|
||||
lastFailure: Option.getOrUndefined(lastFailure),
|
||||
lastFailure,
|
||||
});
|
||||
return yield* new SshReadinessTimedOutError({
|
||||
return yield* new SshReadinessError({
|
||||
message: `Timed out waiting ${timeoutMs}ms for backend readiness at ${input.baseUrl}.`,
|
||||
baseUrl: input.baseUrl,
|
||||
requestUrl,
|
||||
timeoutMs,
|
||||
intervalMs,
|
||||
probeTimeoutMs,
|
||||
attempts: attempt,
|
||||
...(Option.isSome(lastFailure) ? { cause: lastFailure.value } : {}),
|
||||
cause: lastFailure,
|
||||
});
|
||||
}),
|
||||
});
|
||||
@@ -1276,7 +1236,7 @@ const startSshTunnel = Effect.fn("ssh/tunnel.startSshTunnel")(function* (input:
|
||||
yield* Effect.raceFirst(
|
||||
waitForHttpReady({
|
||||
baseUrl: input.httpBaseUrl,
|
||||
timeout: SSH_READY_TIMEOUT,
|
||||
timeoutMs: SSH_READY_TIMEOUT_MS,
|
||||
}),
|
||||
exitFailure,
|
||||
).pipe(
|
||||
@@ -1336,7 +1296,7 @@ const startSshTunnel = Effect.fn("ssh/tunnel.startSshTunnel")(function* (input:
|
||||
: child
|
||||
.kill({
|
||||
killSignal: "SIGTERM",
|
||||
forceKillAfter: Duration.toMillis(TUNNEL_SHUTDOWN_TIMEOUT),
|
||||
forceKillAfter: TUNNEL_SHUTDOWN_TIMEOUT_MS,
|
||||
})
|
||||
.pipe(Effect.ignore),
|
||||
),
|
||||
@@ -1580,7 +1540,7 @@ const makeSshEnvironmentManager = Effect.fn("ssh/tunnel.SshEnvironmentManager.ma
|
||||
[
|
||||
tunnelEntry.process.kill({
|
||||
killSignal: "SIGTERM",
|
||||
forceKillAfter: Duration.toMillis(TUNNEL_SHUTDOWN_TIMEOUT),
|
||||
forceKillAfter: TUNNEL_SHUTDOWN_TIMEOUT_MS,
|
||||
}),
|
||||
stopRemoteServer(
|
||||
tunnelEntry.target,
|
||||
@@ -1634,7 +1594,7 @@ const makeSshEnvironmentManager = Effect.fn("ssh/tunnel.SshEnvironmentManager.ma
|
||||
remotePort: entry.remotePort,
|
||||
});
|
||||
const readinessExit = yield* Effect.exit(
|
||||
waitForHttpReady({ baseUrl: entry.httpBaseUrl, timeout: Duration.seconds(2) }),
|
||||
waitForHttpReady({ baseUrl: entry.httpBaseUrl, timeoutMs: 2_000 }),
|
||||
);
|
||||
if (Exit.isSuccess(readinessExit)) {
|
||||
yield* Effect.logDebug("ssh.environment.tunnel.reused", {
|
||||
|
||||
Reference in new issue
Block a user