Co-authored-by: codex <[email protected]> Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: Cursor Agent <[email protected]> Co-authored-by: cursor[bot] <206951365+cursor[bot]@users.noreply.github.com>
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import type { EnvironmentId, ExecutionEnvironmentDescriptor } from "@t3tools/contracts";
|
|
|
|
export interface KnownEnvironmentConnectionTarget {
|
|
readonly httpBaseUrl: string;
|
|
readonly wsBaseUrl: string;
|
|
}
|
|
|
|
export type KnownEnvironmentSource = "configured" | "desktop-managed" | "manual" | "window-origin";
|
|
|
|
export interface KnownEnvironment {
|
|
readonly id: string;
|
|
readonly label: string;
|
|
readonly source: KnownEnvironmentSource;
|
|
readonly environmentId?: EnvironmentId;
|
|
readonly target: KnownEnvironmentConnectionTarget;
|
|
}
|
|
|
|
export function createKnownEnvironment(input: {
|
|
readonly id?: string;
|
|
readonly label: string;
|
|
readonly source?: KnownEnvironmentSource;
|
|
readonly target: KnownEnvironmentConnectionTarget;
|
|
}): KnownEnvironment {
|
|
return {
|
|
id: input.id ?? `ws:${input.label}`,
|
|
label: input.label,
|
|
source: input.source ?? "manual",
|
|
target: input.target,
|
|
};
|
|
}
|
|
|
|
export function getKnownEnvironmentWsBaseUrl(
|
|
environment: KnownEnvironment | null | undefined,
|
|
): string | null {
|
|
return environment?.target.wsBaseUrl ?? null;
|
|
}
|
|
|
|
export function getKnownEnvironmentHttpBaseUrl(
|
|
environment: KnownEnvironment | null | undefined,
|
|
): string | null {
|
|
return environment?.target.httpBaseUrl ?? null;
|
|
}
|
|
|
|
export function attachEnvironmentDescriptor(
|
|
environment: KnownEnvironment,
|
|
descriptor: ExecutionEnvironmentDescriptor,
|
|
): KnownEnvironment {
|
|
return {
|
|
...environment,
|
|
environmentId: descriptor.environmentId,
|
|
label: descriptor.label,
|
|
};
|
|
}
|