/**
 * Composition root for in-process ("local") agent sessions: wires file-backed
 * defaults for auth, settings, models, sessions, and resource loading on top
 * of the embedded runtime session factory.
 */
import { join } from 'node:path';
import { createAgentSessionRuntimeAdapter } from '../app/agent-session-runtime-adapter.js';
import { SessionAutoApproveState } from '../app/approvals/session-auto-approve.js';
import { AuthStorage } from '../app/auth/auth-storage.js';
import { ModelRegistry } from '../app/providers/model-registry.js';
import { DefaultResourceLoader } from '../app/resources/index.js';
import { createSessionManager as createManagedSession } from '../app/session/session-factory.js';
import { SettingsManager } from '../app/settings-manager.js';
import { configureAgentTempDir, getAgentDir } from '../config.js';
/** Build an embedded agent session backed by on-disk auth, settings, and session storage. */
export async function createLocalAgentSession(options = {}) {
    const cwd = options.cwd ?? process.cwd();
    const agentDir = options.agentDir ?? getAgentDir();
    const settingsManager = options.settingsManager ?? SettingsManager.create(cwd, agentDir);
    const authPath = options.agentDir ? join(agentDir, 'auth.json') : undefined;
    const modelsPath = options.agentDir ? join(agentDir, 'models.json') : undefined;
    const authStorage = options.authStorage ??
        AuthStorage.create({
            authPath
        });
    const modelRegistry = options.modelRegistry ?? new ModelRegistry(authStorage, modelsPath);
    const sessionManager = options.sessionManager ?? createManagedSession(cwd);
    const approvalState = options.approvalState ?? new SessionAutoApproveState(settingsManager);
    configureAgentTempDir(cwd, sessionManager.getSessionId());
    let resourceLoader = options.resourceLoader;
    if (!resourceLoader) {
        resourceLoader = new DefaultResourceLoader({
            cwd,
            agentDir,
            settingsManager
        });
        await resourceLoader.reload();
    }
    return createAgentSessionRuntimeAdapter({
        ...options,
        approvalState,
        cwd,
        modelRegistry,
        resourceLoader,
        sessionManager,
        settingsManager
    });
}
//# sourceMappingURL=index.js.map