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

// src/rest/handlers/sessions-handler.ts
var listSessionsHandler = defineHandler({
  async execute(ctx, input) {
    const query = input.query;
    const sessionManager = new SessionManager(ctx.cwd);
    const result = await sessionManager.listSessions({
      agentId: query?.agentId,
      status: query?.status,
      limit: query?.limit ?? 50,
      offset: query?.offset ?? 0
    });
    return {
      sessions: result.sessions,
      total: result.total
    };
  }
});
var getSessionHandler = defineHandler({
  async execute(ctx, input) {
    const params = input.params;
    const sessionId = params?.sessionId;
    if (!sessionId) {
      throw new Error("Session ID is required");
    }
    const sessionManager = new SessionManager(ctx.cwd);
    const session = await sessionManager.getSessionInfo(sessionId);
    if (!session) {
      throw new Error(`Session not found: ${sessionId}`);
    }
    return { session };
  }
});
var createSessionHandler = defineHandler({
  async execute(ctx, input) {
    const body = input.body;
    if (!body?.agentId) {
      throw new Error("Agent ID is required");
    }
    const sessionManager = new SessionManager(ctx.cwd);
    const session = await sessionManager.createSession({
      mode: "execute",
      task: body.task ?? "",
      agentId: body.agentId,
      name: body.name
    });
    ctx.platform.logger.info(`[sessions-handler] Created session ${session.id} for agent ${body.agentId}`);
    return { session };
  }
});

export { createSessionHandler, getSessionHandler, listSessionsHandler };
//# sourceMappingURL=sessions-handler.js.map
//# sourceMappingURL=sessions-handler.js.map