OpenPay (1 crate, 3751 LOC, 83 tests)
op-crypto-extra Extended crypto rails. Stablecoin catalog (USDC, USDT,
PYUSD, DAI, RLUSD, EURC, FDUSD — 26 deployments). L2
catalog (12 chains incl. Optimism, Arbitrum, Base,
zkSync Era, Polygon zkEVM, Linea, Scroll, Starknet).
CCTP v2 BurnMessage encode/decode + domain ids +
attestation. ERC-4337 UserOperation v0.7 +
PackedUserOperation. EIP-7702 set-EOA-code with RLP
signing preimage. Uniswap Permit2 single + batch
transfer EIP-712 hashes. EIP-2612 ERC-20 permit.
BOLT-11 bech32 invoices + LNURL decode. Bitcoin
PSBT v2 (BIP-370). Atomic-swap HTLC. Solana SPL /
Aleo / Aztec confidential-transfer sketches.
Smart Byte (1 crate, 2304 LOC, 30 tests)
smart-byte-acdc Authentic Chained Data Containers (KERI ecosystem).
Acdc + AcdcBuilder (targeted + untargeted) with SAID
derivation. JSON Schema 2020-12 validator with
oneOf partial-disclosure. TEL (RIP/VRT/ISS/REV)
with hash-chained verification. IPEX (apply/offer/
agree/grant/admit/spurn) chained by SAID. Edge
records (I2I/NI2I/DI2I) + EdgeGraph BFS traversal
with cycle detection. Selective disclosure with
full/none/subset plans + compact packing.
CredentialRegistry trait + InMemoryRegistry over
TEL. Composes with smart-byte-core + smart-byte-keri-witness.
EOC (1 crate, 1764 LOC, 16 tests)
eoc-memory Long-term memory primitives. Memory trait + MemoryKind +
EpisodeId. Episodic event log with TimeIndex range
queries. RDF-style Triple store with S/P/O indices.
Bounded attention-budget Scratchpad with
salience-weighted eviction. Rolling SummaryBuffer +
FIFO SlidingWindow. Dream-cycle consolidate()
(episodic → semantic). Ebbinghaus forgetting curve
with reinforcement. Retriever blending cosine
similarity + recency + saturating frequency.
MemGpt three-tier shape (Main/Recall/Archival).
Co-Authored-By: Claude Opus 4.7 <[email protected]>
94 lines
2.6 KiB
Rust
94 lines
2.6 KiB
Rust
//! Rolling summary buffer.
|
|
//!
|
|
//! When a conversation exceeds an in-context budget, older turns are
|
|
//! replaced by a natural-language summary. This module owns the
|
|
//! summary text plus the count of original turns it represents.
|
|
//!
|
|
//! The summarisation step itself is left to a caller-provided
|
|
//! closure so the crate stays dependency-light and deterministic
|
|
//! given the closure's output.
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::error::MemoryResult;
|
|
use crate::memory::{Memory, MemoryItem, MemoryKind, MemoryRef};
|
|
|
|
/// Rolling summary of conversation history.
|
|
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
|
pub struct SummaryBuffer {
|
|
summary: String,
|
|
represented_turns: u32,
|
|
updated_ms: u64,
|
|
}
|
|
|
|
impl SummaryBuffer {
|
|
/// New empty buffer.
|
|
#[must_use]
|
|
pub fn new() -> Self {
|
|
Self::default()
|
|
}
|
|
|
|
/// Replace the summary text with `new_summary`, incrementing the
|
|
/// represented-turn count by `added_turns`.
|
|
pub fn update(&mut self, new_summary: impl Into<String>, added_turns: u32, now_ms: u64) {
|
|
self.summary = new_summary.into();
|
|
self.represented_turns = self.represented_turns.saturating_add(added_turns);
|
|
self.updated_ms = now_ms;
|
|
}
|
|
|
|
/// Merge another buffer into this one by re-summarising via the
|
|
/// supplied closure.
|
|
pub fn merge<F>(&mut self, other: &SummaryBuffer, now_ms: u64, summariser: F)
|
|
where
|
|
F: FnOnce(&str, &str) -> String,
|
|
{
|
|
let merged = summariser(&self.summary, &other.summary);
|
|
self.summary = merged;
|
|
self.represented_turns = self
|
|
.represented_turns
|
|
.saturating_add(other.represented_turns);
|
|
self.updated_ms = now_ms;
|
|
}
|
|
|
|
/// Borrow the current summary text.
|
|
#[must_use]
|
|
pub fn text(&self) -> &str {
|
|
&self.summary
|
|
}
|
|
|
|
/// Number of original turns this summary represents.
|
|
#[must_use]
|
|
pub fn represented_turns(&self) -> u32 {
|
|
self.represented_turns
|
|
}
|
|
|
|
/// Timestamp (ms) of last update.
|
|
#[must_use]
|
|
pub fn updated_ms(&self) -> u64 {
|
|
self.updated_ms
|
|
}
|
|
}
|
|
|
|
impl Memory for SummaryBuffer {
|
|
fn kind(&self) -> MemoryKind {
|
|
MemoryKind::Summary
|
|
}
|
|
|
|
fn len(&self) -> usize {
|
|
usize::from(!self.summary.is_empty())
|
|
}
|
|
|
|
fn recent(&self, _n: usize) -> MemoryResult<Vec<MemoryItem>> {
|
|
if self.summary.is_empty() {
|
|
return Ok(Vec::new());
|
|
}
|
|
Ok(vec![MemoryItem::new(
|
|
MemoryRef {
|
|
kind: MemoryKind::Summary,
|
|
id: "summary".into(),
|
|
},
|
|
self.summary.clone(),
|
|
self.updated_ms,
|
|
)])
|
|
}
|
|
}
|