import { defineHandler } from '@kb-labs/sdk';
import { SessionManager } from '@kb-labs/agent-core';
import { promises } from 'fs';

// src/rest/handlers/get-spec-handler.ts
async function loadSpec(specPath) {
  try {
    const content = await promises.readFile(specPath, "utf-8");
    return JSON.parse(content);
  } catch {
    return null;
  }
}
var get_spec_handler_default = defineHandler({
  async execute(ctx, input) {
    const params = input.params;
    const sessionId = params?.sessionId;
    if (!sessionId) {
      throw new Error("Session ID is required");
    }
    const baseManager = new SessionManager(ctx.cwd);
    const session = await baseManager.loadSession(sessionId);
    if (!session) {
      throw new Error(`Session not found: ${sessionId}`);
    }
    const workingDir = session.workingDir || ctx.cwd;
    const manager = new SessionManager(workingDir);
    const specPath = manager.getSessionSpecPath(sessionId);
    const spec = await loadSpec(specPath);
    return {
      sessionId,
      spec
    };
  }
});

export { get_spec_handler_default as default };
//# sourceMappingURL=get-spec-handler.js.map
//# sourceMappingURL=get-spec-handler.js.map