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

// src/rest/handlers/get-session-turns-handler.ts
var get_session_turns_handler_default = defineHandler({
  async execute(ctx, input) {
    const params = input.params;
    const sessionId = params?.sessionId;
    const query = input.query;
    if (!sessionId) {
      throw new Error("Session ID is required");
    }
    const sessionManager = new SessionManager(ctx.cwd);
    ctx.platform.logger.info(`[get-session-turns] cwd: ${ctx.cwd}, sessionId: ${sessionId}`);
    ctx.platform.logger.info(`[get-session-turns] turnsPath: ${sessionManager.getTurnsPath(sessionId)}`);
    const session = await sessionManager.loadSession(sessionId);
    if (!session) {
      throw new Error(`Session not found: ${sessionId}`);
    }
    let turns = await sessionManager.getTurns(sessionId);
    ctx.platform.logger.info(`[get-session-turns] Found ${turns.length} turns`);
    const total = turns.length;
    if (query?.offset) {
      turns = turns.slice(query.offset);
    }
    if (query?.limit) {
      turns = turns.slice(0, query.limit);
    }
    return { turns, total };
  }
});

export { get_session_turns_handler_default as default };
//# sourceMappingURL=get-session-turns-handler.js.map
//# sourceMappingURL=get-session-turns-handler.js.map