import { env } from "./env.js";
import manageDbPool_default from "./data/db/manageDbPool.js";
import runDbClient_default from "./data/db/runDbClient.js";
import { createAgentsHono } from "./createApp.js";
import { CredentialStoreRegistry, createDefaultCredentialStores } from "@inkeep/agents-core";
import { createAuth } from "@inkeep/agents-core/auth";

//#region src/factory.ts
const defaultConfig = {
	port: 3002,
	serverOptions: {
		requestTimeout: 12e4,
		keepAliveTimeout: 6e4,
		keepAlive: true
	}
};
function createAgentsAuth(userAuthConfig, emailService) {
	return createAuth({
		baseURL: env.INKEEP_AGENTS_API_URL || `http://localhost:3002`,
		secret: env.BETTER_AUTH_SECRET || "development-secret-change-in-production",
		dbClient: runDbClient_default,
		manageDbPool: manageDbPool_default,
		...env.AUTH_COOKIE_DOMAIN && { cookieDomain: env.AUTH_COOKIE_DOMAIN },
		...userAuthConfig?.socialProviders && { socialProviders: userAuthConfig.socialProviders },
		...emailService && { emailService }
	});
}
function createAgentsApp(config) {
	return createAgentsHono({
		serverConfig: config?.serverConfig ?? defaultConfig,
		credentialStores: new CredentialStoreRegistry(config?.credentialStores ?? createDefaultCredentialStores()),
		auth: createAgentsAuth(config?.auth, config?.emailService),
		sandboxConfig: config?.sandboxConfig
	});
}

//#endregion
export { createAgentsApp, createAgentsAuth, createAgentsHono };