- Added telemetry utility to capture application events and metrics. - Integrated PostHog for event tracking with distinct user identification. - Implemented telemetry initialization, event capturing, and shutdown procedures. feat: add UV environment setup for Python management - Created utilities to manage Python installation and configuration. - Implemented network optimization checks for Python installation mirrors. - Added functions to set up managed Python environments with error handling. feat: enhance host API communication with token management - Introduced host API token retrieval and management for secure requests. - Updated host API fetch functions to include token in headers. - Added support for creating event sources with authentication. test: add comprehensive tests for gateway protocol and startup helpers - Implemented unit tests for gateway protocol helpers, event dispatching, and state management. - Added tests for startup recovery strategies and process policies. - Ensured coverage for connection monitoring and restart governance logic.
57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
type EnvMap = Record<string, string | undefined>;
|
|
|
|
function isPathKey(key: string): boolean {
|
|
return key.toLowerCase() === 'path';
|
|
}
|
|
|
|
function preferredPathKey(): string {
|
|
return process.platform === 'win32' ? 'Path' : 'PATH';
|
|
}
|
|
|
|
function pathDelimiter(): string {
|
|
return process.platform === 'win32' ? ';' : ':';
|
|
}
|
|
|
|
export function getPathEnvKey(env: EnvMap): string {
|
|
const keys = Object.keys(env).filter(isPathKey);
|
|
if (keys.length === 0) return preferredPathKey();
|
|
|
|
if (process.platform === 'win32') {
|
|
if (keys.includes('Path')) return 'Path';
|
|
if (keys.includes('PATH')) return 'PATH';
|
|
return keys[0];
|
|
}
|
|
|
|
if (keys.includes('PATH')) return 'PATH';
|
|
return keys[0];
|
|
}
|
|
|
|
export function getPathEnvValue(env: EnvMap): string {
|
|
const key = getPathEnvKey(env);
|
|
return env[key] ?? '';
|
|
}
|
|
|
|
export function setPathEnvValue(env: EnvMap, nextPath: string): EnvMap {
|
|
const nextEnv: EnvMap = { ...env };
|
|
for (const key of Object.keys(nextEnv)) {
|
|
if (isPathKey(key)) {
|
|
delete nextEnv[key];
|
|
}
|
|
}
|
|
|
|
nextEnv[getPathEnvKey(env)] = nextPath;
|
|
return nextEnv;
|
|
}
|
|
|
|
export function prependPathEntry(
|
|
env: EnvMap,
|
|
entry: string,
|
|
): { env: EnvMap; path: string } {
|
|
const current = getPathEnvValue(env);
|
|
const nextPath = current ? `${entry}${pathDelimiter()}${current}` : entry;
|
|
return {
|
|
env: setPathEnvValue(env, nextPath),
|
|
path: nextPath,
|
|
};
|
|
}
|