/**
 * Owns agent-loop state snapshots and checkpoint conversion.
 */
export class AgentLoopCheckpointService {
    static createFinishedState(args) {
        return {
            status: 'finished',
            runId: args.runId,
            goal: args.goal,
            model: args.model,
            provider: args.provider,
            workspaceRoot: args.workspaceRoot,
            startedAt: args.startedAt,
            finishedAt: args.finishedAt,
            outcome: args.result.outcome,
            summary: args.result.summary,
            usage: args.result.usage,
            transcript: args.result.transcript,
            trace: args.result.trace,
        };
    }
    static createCheckpoint(state, options = {}) {
        return {
            version: 1,
            runId: state.runId,
            createdAt: options.createdAt ?? new Date().toISOString(),
            state,
        };
    }
    static generateRunId() {
        const timestamp = Date.now().toString(36);
        const random = Math.random().toString(36).slice(2, 6);
        return `run_${timestamp}_${random}`;
    }
    static historyFromState(state) {
        return state.transcript;
    }
    static historyFromCheckpoint(checkpoint) {
        return this.historyFromState(checkpoint.state);
    }
    static resolveHistory(options) {
        if (options.history) {
            return options.history;
        }
        if (!options.resumeFrom) {
            return undefined;
        }
        if ('version' in options.resumeFrom) {
            return this.historyFromCheckpoint(options.resumeFrom);
        }
        return this.historyFromState(options.resumeFrom);
    }
    static resolveResumeMetadata(resumeFrom) {
        if (!resumeFrom) {
            return undefined;
        }
        if ('version' in resumeFrom) {
            return {
                checkpointRunId: resumeFrom.runId,
                priorTraceEvents: resumeFrom.state.trace.length,
            };
        }
        return {
            checkpointRunId: resumeFrom.runId,
            priorTraceEvents: resumeFrom.trace.length,
        };
    }
}
//# sourceMappingURL=checkpoint.js.map