export class ToolResultLedger {
    entries = new Map();
    plan(toolCalls) {
        for (const toolCall of toolCalls) {
            if (!this.entries.has(toolCall.id)) {
                this.entries.set(toolCall.id, { toolCall, emitted: false });
            }
        }
    }
    recordResult(toolCall, result) {
        const existing = this.entries.get(toolCall.id);
        if (existing) {
            existing.result = result;
            return;
        }
        this.entries.set(toolCall.id, { toolCall, result, emitted: false });
    }
    hasRecordedResult(toolCallId) {
        return this.entries.get(toolCallId)?.result !== undefined;
    }
    markEmitted(toolCallId) {
        const entry = this.entries.get(toolCallId);
        if (entry) {
            entry.emitted = true;
        }
    }
    isEmitted(toolCallId) {
        return this.entries.get(toolCallId)?.emitted === true;
    }
    resultFor(toolCallId) {
        return this.entries.get(toolCallId)?.result;
    }
    collectResultsInMessageOrder(toolCalls) {
        const ordered = [];
        for (const toolCall of toolCalls) {
            const result = this.entries.get(toolCall.id)?.result;
            if (result) {
                ordered.push(result);
            }
        }
        return ordered;
    }
}
//# sourceMappingURL=agent-loop-ledger.js.map