mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-02 16:58:52 +01:00
Land the approved Cloud configuration and release-image package stack.
Includes the separately reviewed adapter settings (#18335), external adapters (#18333), bundled plugins (#18336), startup configuration (#18339), and migration/package checks (#18341).
Includes the final image-owned loader and linked-dependency inventory corrections.
Verified stack head: 462716170d.
Co-Authored-By: Paperclip <noreply@paperclip.ing>
38 lines
1.6 KiB
TypeScript
38 lines
1.6 KiB
TypeScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
export function resolveBundledPluginRuntimeLoader(
|
|
moduleDirectory = path.dirname(fileURLToPath(import.meta.url)),
|
|
): string {
|
|
let directory = fs.realpathSync(moduleDirectory);
|
|
let imageRoot: string | undefined;
|
|
for (let depth = 0; depth < 5; depth++) {
|
|
const metadataPath = path.join(directory, "package.json");
|
|
const metadata = fs.lstatSync(metadataPath, { throwIfNoEntry: false });
|
|
if (metadata?.isFile() && metadata.size <= 128 * 1024
|
|
&& JSON.parse(fs.readFileSync(metadataPath, "utf8")).name === "@paperclipai/server") {
|
|
imageRoot = path.dirname(directory);
|
|
break;
|
|
}
|
|
const parent = path.dirname(directory);
|
|
if (parent === directory) break;
|
|
directory = parent;
|
|
}
|
|
if (!imageRoot) throw new Error("Managed plugin server package is missing from the current image");
|
|
const declared = path.join(imageRoot, "cli/node_modules/tsx/dist/loader.mjs");
|
|
let loader: string;
|
|
try {
|
|
loader = fs.realpathSync(declared);
|
|
if (!fs.statSync(loader).isFile()) throw new Error("not a file");
|
|
} catch {
|
|
throw new Error("Managed plugin runtime loader is missing from the current image");
|
|
}
|
|
const roots = [path.join(imageRoot, "cli"), path.join(imageRoot, "node_modules")];
|
|
if (!roots.some((root) => {
|
|
const relative = path.relative(root, loader);
|
|
return relative !== "" && !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
})) throw new Error("Managed plugin runtime loader escapes the current image");
|
|
return loader;
|
|
}
|