import { d as defineEventHandler, a as useOrchestrator, g as getRouterParam, i as isValidSessionId, c as createError, b as getQuery, p as parsePositiveInt, f as fetchSessionMessages } from '../../../../../../index.mjs';
import '@anthropic-ai/claude-agent-sdk';
import '@octokit/webhooks';
import 'node:events';
import 'node:buffer';
import 'node:fs';
import 'node:path';
import 'node:crypto';
import 'node:process';
import 'consola';
import '@octokit/graphql';
import 'zod';
import '@octokit/auth-app';
import 'node:os';
import '@libsql/client';
import 'liquidjs';
import 'js-yaml';
import 'node:child_process';
import '@chat-adapter/github';
import '@chat-adapter/slack';
import 'chat';
import 'chat-adapter-asana';
import 'better-auth';
import 'better-auth/plugins';
import 'bun:sqlite';
import 'better-auth/db/migration';
import 'node:url';
import '@iconify/utils';
import 'rou3';

const messages_get = defineEventHandler(async (event) => {
  var _a;
  const orchestrator = useOrchestrator();
  const sessionId = (_a = getRouterParam(event, "sessionId")) != null ? _a : "";
  if (!sessionId || !isValidSessionId(sessionId)) {
    throw createError({ statusCode: 400, statusMessage: "Invalid session ID" });
  }
  const config = orchestrator.getConfig();
  const query = getQuery(event);
  const limit = parsePositiveInt(typeof query.limit === "string" ? query.limit : null);
  const offset = parsePositiveInt(typeof query.offset === "string" ? query.offset : null);
  try {
    return await fetchSessionMessages(sessionId, config.workspace.root, { limit, offset });
  } catch (err) {
    const code = err && typeof err === "object" && "code" in err ? err.code : void 0;
    const msg = err instanceof Error ? err.message : String(err);
    if (code === "ENOENT" || msg.toLowerCase().includes("not found"))
      return [];
    console.error("[server] sessionMessagesResponse error:", err);
    throw createError({ statusCode: 500, statusMessage: "Failed to load session messages" });
  }
});

export { messages_get as default };
//# sourceMappingURL=messages.get.mjs.map
