import { handleError } from './chunk-ONN5EA7E.js';
import { createRoute } from './chunk-OQ5GQJAS.js';
import { readFileSync } from 'fs';
import { z } from 'zod';

var mastraPackageSchema = z.object({
  name: z.string(),
  version: z.string()
});
var systemPackagesResponseSchema = z.object({
  packages: z.array(mastraPackageSchema)
});

// src/server/handlers/system.ts
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 () => {
    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 };
    } catch (error) {
      return handleError(error, "Error getting system packages");
    }
  }
});

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