Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): resolve dev schedule loader at build time (#761)

Ruie0f09b4da329
diff --git a/.changeset/fix-windows-dev-schedule-dispatch.md b/.changeset/fix-windows-dev-schedule-dispatch.md
new file mode 100644
index 000000000..0b79985ff
--- /dev/null
+++ b/.changeset/fix-windows-dev-schedule-dispatch.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+The `eve dev` schedule dispatch route now reuses the module loader path resolved when the server is built, preventing module resolution failures in the bundled Windows dev server.
diff --git a/packages/eve/src/internal/nitro/host/configure-nitro-routes.test.ts b/packages/eve/src/internal/nitro/host/configure-nitro-routes.test.ts
index 1676858eb..f4c84fb57 100644
--- a/packages/eve/src/internal/nitro/host/configure-nitro-routes.test.ts
+++ b/packages/eve/src/internal/nitro/host/configure-nitro-routes.test.ts
@@ -85,7 +85,8 @@ vi.mock("../../application/paths.js", () => ({
}));
const { configureNitroRoutes } = await import("./configure-nitro-routes.js");
-const { EVE_HEALTH_ROUTE_PATH, EVE_INFO_ROUTE_PATH } = await import("#protocol/routes.js");
+const { EVE_DEV_DISPATCH_SCHEDULE_ROUTE_PATTERN, EVE_HEALTH_ROUTE_PATH, EVE_INFO_ROUTE_PATH } =
+ await import("#protocol/routes.js");
function createNitroStub(
input: { buildDir?: string; dev?: boolean; rootDir?: string } = {},
@@ -310,6 +311,18 @@ describe("configureNitroRoutes", () => {
);
});
+ it("bakes the module map loader into the dev schedule handler", async () => {
+ const nitro = createNitroStub({ dev: true });
+
+ await configureNitroRoutes(nitro, createPreparedHost(), {
+ surface: "app",
+ });
+
+ const source = nitro.options.virtual[`#eve-route${EVE_DEV_DISPATCH_SCHEDULE_ROUTE_PATTERN}`];
+ expect(source).toContain('"moduleMapLoaderPath"');
+ expect(source).toContain("authored-module-map-loader.js");
+ });
+
it("registers the agent info route for dev and production app builds", async () => {
const devNitro = createNitroStub({ dev: true });
const prodNitro = createNitroStub({ dev: false });
diff --git a/packages/eve/src/internal/nitro/host/configure-nitro-routes.ts b/packages/eve/src/internal/nitro/host/configure-nitro-routes.ts
index ffe216806..d9634f214 100644
--- a/packages/eve/src/internal/nitro/host/configure-nitro-routes.ts
+++ b/packages/eve/src/internal/nitro/host/configure-nitro-routes.ts
@@ -373,7 +373,7 @@ export async function configureNitroRoutes(
route: EVE_DEV_RUNTIME_ARTIFACTS_ROUTE_PATH,
});
addFrameworkVirtualHandler(nitro, {
- args: JSON.stringify({ appRoot: artifactsConfig.appRoot }),
+ args: JSON.stringify(artifactsConfig),
handlerExport: "handleDevScheduleDispatchRequest",
method: "POST",
modulePath: resolvePackageSourceFilePath(
diff --git a/packages/eve/src/internal/nitro/host/dispatch-schedule-in-dev.ts b/packages/eve/src/internal/nitro/host/dispatch-schedule-in-dev.ts
index d5a9cc121..0bc67c8f3 100644
--- a/packages/eve/src/internal/nitro/host/dispatch-schedule-in-dev.ts
+++ b/packages/eve/src/internal/nitro/host/dispatch-schedule-in-dev.ts
@@ -1,5 +1,5 @@
-import { createNitroArtifactsConfig } from "#internal/nitro/host/artifacts-config.js";
-import { createAuthoredSourceRuntimeCompiledArtifactsSource } from "#internal/application/runtime-compiled-artifacts-source.js";
+import type { NitroArtifactsConfigInput } from "#internal/nitro/host/artifacts-config.js";
+import { createDiskRuntimeCompiledArtifactsSource } from "#runtime/compiled-artifacts-source.js";
import { createScheduleRegistrations } from "#runtime/schedules/register.js";
import { loadResolvedCompiledSchedules } from "#runtime/schedules/resolve-schedule.js";
@@ -51,12 +51,25 @@ export class UnknownDevScheduleError extends Error {
* Re-resolves authored schedule registrations from disk on every call so
* the route picks up edits made by the authored-source watcher without a
* dev-server restart.
+ *
+ * The artifacts config is resolved before Nitro bundles this module and
+ * baked into the virtual handler. Re-deriving its loader path here would
+ * resolve relative to the app instead of the installed eve package.
*/
export async function dispatchScheduleInDev(input: {
- readonly appRoot: string;
+ readonly artifactsConfig: NitroArtifactsConfigInput;
readonly scheduleId: string;
}): Promise<DispatchScheduleInDevResult> {
- const compiledArtifactsSource = createAuthoredSourceRuntimeCompiledArtifactsSource(input.appRoot);
+ const { appRoot, moduleMapLoaderPath } = input.artifactsConfig;
+ if (appRoot === undefined || moduleMapLoaderPath === undefined) {
+ throw new Error(
+ 'Dev schedule dispatch requires "appRoot" and "moduleMapLoaderPath" in the artifacts config.',
+ );
+ }
+
+ const compiledArtifactsSource = createDiskRuntimeCompiledArtifactsSource(appRoot, {
+ moduleMapLoaderPath,
+ });
const schedules = await loadResolvedCompiledSchedules({ compiledArtifactsSource });
const registrations = createScheduleRegistrations(schedules);
const registration = registrations.find((candidate) => candidate.scheduleId === input.scheduleId);
@@ -69,11 +82,7 @@ export async function dispatchScheduleInDev(input: {
}
const { dispatchScheduleTask } = await import("#internal/nitro/routes/schedule-task.js");
- const artifactsConfig = createNitroArtifactsConfig({
- appRoot: input.appRoot,
- dev: true,
- });
- const result = await dispatchScheduleTask(registration.taskName, artifactsConfig);
+ const result = await dispatchScheduleTask(registration.taskName, input.artifactsConfig);
return {
scheduleId: result.scheduleId,
diff --git a/packages/eve/src/internal/nitro/routes/dev-schedule-dispatch.test.ts b/packages/eve/src/internal/nitro/routes/dev-schedule-dispatch.test.ts
index fe98b0433..bf1e9e2d1 100644
--- a/packages/eve/src/internal/nitro/routes/dev-schedule-dispatch.test.ts
+++ b/packages/eve/src/internal/nitro/routes/dev-schedule-dispatch.test.ts
@@ -15,6 +15,11 @@ vi.mock("#internal/nitro/host/dispatch-schedule-in-dev.js", async () => {
});
const APP_ROOT = "/tmp/eve-test";
+const ARTIFACTS_CONFIG = {
+ appRoot: APP_ROOT,
+ dev: true,
+ moduleMapLoaderPath: "/tmp/eve-test/module-map-loader.js",
+};
async function importHandler() {
return await import("#internal/nitro/routes/dev-schedule-dispatch.js");
@@ -25,7 +30,7 @@ async function postSchedule(scheduleIdInUrl: string): Promise<Response> {
const request = new Request(`http://localhost:3000/eve/v1/dev/schedules/${scheduleIdInUrl}`, {
method: "POST",
});
- return await handleDevScheduleDispatchRequest({ appRoot: APP_ROOT }, request);
+ return await handleDevScheduleDispatchRequest(ARTIFACTS_CONFIG, request);
}
describe("handleDevScheduleDispatchRequest", () => {
@@ -44,7 +49,7 @@ describe("handleDevScheduleDispatchRequest", () => {
sessionIds: ["sess-1", "sess-2"],
});
expect(mocks.dispatchScheduleInDev).toHaveBeenCalledWith({
- appRoot: APP_ROOT,
+ artifactsConfig: ARTIFACTS_CONFIG,
scheduleId: "heartbeat",
});
});
@@ -59,7 +64,7 @@ describe("handleDevScheduleDispatchRequest", () => {
expect(response.status).toBe(200);
expect(mocks.dispatchScheduleInDev).toHaveBeenCalledWith({
- appRoot: APP_ROOT,
+ artifactsConfig: ARTIFACTS_CONFIG,
scheduleId: "weird/name",
});
});
diff --git a/packages/eve/src/internal/nitro/routes/dev-schedule-dispatch.ts b/packages/eve/src/internal/nitro/routes/dev-schedule-dispatch.ts
index 320d63ba5..d4e0eb90c 100644
--- a/packages/eve/src/internal/nitro/routes/dev-schedule-dispatch.ts
+++ b/packages/eve/src/internal/nitro/routes/dev-schedule-dispatch.ts
@@ -2,6 +2,7 @@ import {
dispatchScheduleInDev,
UnknownDevScheduleError,
} from "#internal/nitro/host/dispatch-schedule-in-dev.js";
+import type { NitroArtifactsConfigInput } from "#internal/nitro/host/artifacts-config.js";
import { EVE_ROUTE_PREFIX } from "#protocol/routes.js";
/**
@@ -29,7 +30,7 @@ const DEV_DISPATCH_SCHEDULE_PATH_PATTERN = new RegExp(
* Auth: none. The dev server is local-only and the route is dev-only.
*/
export async function handleDevScheduleDispatchRequest(
- input: { appRoot: string },
+ input: NitroArtifactsConfigInput,
request: Request,
): Promise<Response> {
const url = new URL(request.url);
@@ -52,7 +53,7 @@ export async function handleDevScheduleDispatchRequest(
try {
const result = await dispatchScheduleInDev({
- appRoot: input.appRoot,
+ artifactsConfig: input,
scheduleId,
});
return Response.json({