Public declaration syntax from forge-rs/crates/forge-contracts/src/memory.rs Original source SHA-256: 16cfc8a37e876cfdc39b672a1fcbb1dbbbde1baa37890dd165f913e25782e530 Function bodies and constant values are omitted. This is not the complete implementation. Source line 60 pub const CONTRACT_VERSION: &str; Source line 79 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum MemoryScope { /// Organization-wide scope (all agents can read). Organization { /// The organization identifier. org_id: String, }, /// Department-level scope. Department { /// The organization identifier. org_id: String, /// The department identifier. department_id: String, }, /// Team-level scope. Team { /// The organization identifier. org_id: String, /// The department identifier. department_id: String, /// The team identifier. team_id: String, }, /// Agent-private scope. Agent { /// The agent's DID. agent_did: String, }, } Source line 110 pub fn org_id(&self) -> Option<&str>; Source line 120 pub fn display_scope(&self) -> String; Source line 139 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum MemoryType { /// Temporal events and interaction histories. Episodic, /// Facts, relationships, and knowledge. Semantic, /// Workflows, runbooks, and procedures. Procedural, /// Documents, artifacts, and code snippets. Resource, } Source line 172 #[derive(Debug, Clone, Serialize, Deserialize)] pub struct MemoryRecord { /// The scope where this record should be stored. pub scope: MemoryScope, /// The type of memory. pub memory_type: MemoryType, /// A unique key within the scope (for retrieval and updates). pub key: String, /// The memory content as JSON. pub content: serde_json::Value, /// Tags for discovery and filtering. pub tags: Vec, /// The DID of the agent that authored this record. pub author_did: String } Source line 194 #[derive(Debug, Clone, Default, Serialize, Deserialize)] pub struct MemoryQuery { /// The scope to query. The query also includes all parent scopes /// (unless `include_parents` is `false`). pub scope: Option, /// Filter by memory type. pub memory_type: Option, /// Filter by key prefix. pub key_prefix: Option, /// Filter by tags (records must have ALL specified tags). pub tags: Vec, /// Semantic search query (uses vector similarity). pub semantic_query: Option, /// Maximum results to return. pub limit: Option, /// Whether to include records from parent scopes. Default: true. pub include_parents: bool } Source line 220 #[derive(Debug, Clone, Serialize, Deserialize)] pub struct MemoryResult { /// The record's unique key. pub key: String, /// The scope this record belongs to. pub scope: MemoryScope, /// The memory type. pub memory_type: MemoryType, /// The record content. pub content: serde_json::Value, /// Tags on this record. pub tags: Vec, /// Who authored this record. pub author_did: String, /// When this record was created. pub created_at: DateTime, /// When this record was last updated. pub updated_at: DateTime, /// Similarity score (0.0 to 1.0) when using semantic search. pub similarity: Option } Source line 251 #[derive(Debug, Clone, Serialize, Deserialize)] pub struct MemoryWritePolicy { /// The scope this policy applies to. pub scope: MemoryScope, /// Whether writes are allowed to this scope. pub writes_allowed: bool, /// DIDs allowed to write (empty = all agents in scope can write). pub allowed_writers: Vec, /// Memory types that are writable (empty = all types). pub writable_types: Vec, /// Whether writes require approval from a parent scope agent. pub requires_approval: bool, /// Maximum record size in bytes. pub max_record_size_bytes: Option } Source line 292 #[async_trait] pub trait MemoryContract: Send + Sync { /// Stores a memory record. /// /// # Arguments /// /// * `record` - The record to store. /// /// # Errors /// /// - `ContractError::MemoryAccessDenied` if the author lacks write /// access to the specified scope. /// - `ContractError::MemoryError` if storage fails. async fn store(&self, record: MemoryRecord) -> ContractResult<()>; /// Retrieves memory records matching a query. /// /// # Arguments /// /// * `query` - The query criteria. /// * `requester_did` - The agent requesting the records (for access /// control). /// /// # Returns /// /// Matching records ordered by relevance (semantic search) or /// recency (non-semantic queries). /// /// # Errors /// /// - `ContractError::MemoryAccessDenied` if the requester lacks /// read access. async fn retrieve( &self, query: MemoryQuery, requester_did: &str, ) -> ContractResult>; /// Deletes a memory record. /// /// # Arguments /// /// * `scope` - The scope containing the record. /// * `key` - The record key. /// * `requester_did` - The agent requesting deletion (for access /// control). /// /// # Errors /// /// - `ContractError::MemoryAccessDenied` if the requester lacks /// write access. async fn delete( &self, scope: &MemoryScope, key: &str, requester_did: &str, ) -> ContractResult<()>; /// Sets the write policy for a memory scope. /// /// # Arguments /// /// * `policy` - The write policy to set. /// /// # Errors /// /// - `ContractError::AuthorizationDenied` if the caller lacks /// authority to set policies for this scope. async fn set_write_policy(&self, policy: MemoryWritePolicy) -> ContractResult<()>; /// Returns the current write policy for a scope. /// /// # Arguments /// /// * `scope` - The scope to query. async fn get_write_policy( &self, scope: &MemoryScope, ) -> ContractResult>; }