diff --git a/cli/src/commands/run.ts b/cli/src/commands/run.ts index d96b010c..4657ac89 100644 --- a/cli/src/commands/run.ts +++ b/cli/src/commands/run.ts @@ -84,6 +84,14 @@ function isModuleNotFoundError(err: unknown): boolean { return err.message.includes("Cannot find module"); } +function maybeEnableUiDevMiddleware(entrypoint: string): void { + if (process.env.PAPERCLIP_UI_DEV_MIDDLEWARE !== undefined) return; + const normalized = entrypoint.replaceAll("\\", "/"); + if (normalized.endsWith("/server/src/index.ts") || normalized.endsWith("@paperclipai/server/src/index.ts")) { + process.env.PAPERCLIP_UI_DEV_MIDDLEWARE = "true"; + } +} + async function importServerEntry(): Promise { const projectRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../.."); const fileCandidates = [ @@ -94,6 +102,7 @@ async function importServerEntry(): Promise { if (existingFileCandidates.length > 0) { for (const filePath of existingFileCandidates) { try { + maybeEnableUiDevMiddleware(filePath); await import(pathToFileURL(filePath).href); return; } catch (err) { @@ -106,6 +115,7 @@ async function importServerEntry(): Promise { const missingErrors: string[] = []; for (const specifier of specifierCandidates) { try { + maybeEnableUiDevMiddleware(specifier); await import(specifier); return; } catch (err) {