Files
moltbot/src/shared/runtime-import.ts
Peter Steinberger cf499101a2 fix(agents): normalize Windows runtime imports (#72731)
* fix(agents): normalize Windows runtime imports

* test(providers): align manifest contract coverage
2026-04-27 10:34:25 +01:00

21 lines
729 B
TypeScript

import { toSafeImportPath } from "./import-specifier.js";
export { toSafeImportPath as toSafeRuntimeImportPath } from "./import-specifier.js";
export function resolveRuntimeImportSpecifier(baseUrl: string, parts: readonly string[]): string {
const joined = parts.join("");
const safeJoined = toSafeImportPath(joined);
if (safeJoined !== joined) {
return safeJoined;
}
return new URL(joined, toSafeImportPath(baseUrl)).href;
}
export async function importRuntimeModule<T>(
baseUrl: string,
parts: readonly string[],
importModule: (specifier: string) => Promise<unknown> = (specifier) => import(specifier),
): Promise<T> {
return (await importModule(resolveRuntimeImportSpecifier(baseUrl, parts))) as T;
}