import { systemPackagesResponseSchema } from './chunk-QIP5UCDX.js';
import { handleError } from './chunk-NA7LKQPZ.js';
import { createRoute } from './chunk-OLKVMPNB.js';
import { readFileSync } from 'fs';

var GET_SYSTEM_PACKAGES_ROUTE = createRoute({
  method: "GET",
  path: "/system/packages",
  responseType: "json",
  responseSchema: systemPackagesResponseSchema,
  summary: "Get installed Mastra packages",
  description: "Returns a list of all installed Mastra packages and their versions from the project",
  tags: ["System"],
  requiresAuth: true,
  handler: async ({ mastra }) => {
    try {
      const packagesFilePath = process.env.MASTRA_PACKAGES_FILE;
      let packages = [];
      if (packagesFilePath) {
        try {
          const fileContent = readFileSync(packagesFilePath, "utf-8");
          packages = JSON.parse(fileContent);
        } catch {
          packages = [];
        }
      }
      return { packages, isDev: process.env.MASTRA_DEV === "true", cmsEnabled: !!mastra.getEditor() };
    } catch (error) {
      return handleError(error, "Error getting system packages");
    }
  }
});

export { GET_SYSTEM_PACKAGES_ROUTE };
//# sourceMappingURL=chunk-2OBRONRW.js.map
//# sourceMappingURL=chunk-2OBRONRW.js.map