agentcomply / tree / src/store.js ยท raw (this view has old GitHub links rewritten for the mirror; raw is byte-exact)
// Receipt ledgers. head() -> {seq, hash} | null ; append(receipt) ; list()
export class MemoryStore {
  constructor() { this.items = []; }
  async head() { const r = this.items.at(-1); return r ? { seq: r.chain.seq, hash: r.integrity.hash } : null; }
  async append(r) { this.items.push(r); }
  async list() { return [...this.items]; }
}

// Cloudflare KV (optional binding RECEIPTS). Note: KV is eventually consistent; a production
// deployment should serialize appends through a Durable Object. Fine for a demo.
export class KVStore {
  constructor(kv) { this.kv = kv; }
  async head() { return (await this.kv.get('head', 'json')) || null; }
  async append(r) {
    await this.kv.put('r:' + String(r.chain.seq).padStart(10, '0'), JSON.stringify(r));
    await this.kv.put('head', JSON.stringify({ seq: r.chain.seq, hash: r.integrity.hash }));
  }
  async list() {
    const { keys } = await this.kv.list({ prefix: 'r:' });
    return Promise.all(keys.map((k) => this.kv.get(k.name, 'json')));
  }
}

agentgate-source: code mirror on Cloudflare Pages. All repos