Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:24kchengYe MemoMind OperationValidatorExtension

From Leeroopedia
Knowledge Sources
Domains Validation, SaaS
Last Updated 2026-10-28 00:00 GMT

Overview

Operation validation extension ABC defining pre-operation hooks for credit/billing/quota validation before expensive LLM operations execute.

Description

The OperationValidatorExtension ABC defines validation hooks per operation type: `validate_retain()`, `validate_recall()`, `validate_reflect()`, `validate_bank_write()`, `validate_consolidate()`, `validate_mental_model_refresh()`, `validate_file_convert()`. Each receives a typed context object (e.g., `RetainContext`, `RecallContext`) with all user-provided parameters. Returns `ValidationResult.accept()` or `ValidationResult.reject()`. Raises `OperationValidationError` to reject. Critical for SaaS deployments to enforce per-tenant resource limits.

Usage

Subclass this when building a billing or quota system. Configure via `HINDSIGHT_API_OPERATION_VALIDATOR_EXTENSION`.

Code Reference

Source Location

  • Repository: MemoMind
  • File: engine/hindsight_api/extensions/operation_validator.py
  • Lines: L1-682

Signature

class OperationValidatorExtension(Extension, ABC):
    @abstractmethod
    async def validate_retain(self, context: RetainContext) -> ValidationResult: ...
    @abstractmethod
    async def validate_recall(self, context: RecallContext) -> ValidationResult: ...
    @abstractmethod
    async def validate_reflect(self, context: ReflectContext) -> ValidationResult: ...
    @abstractmethod
    async def validate_bank_write(self, context: BankWriteContext) -> ValidationResult: ...
    @abstractmethod
    async def validate_consolidate(self, context: ConsolidateContext) -> ValidationResult: ...
    # ... plus mental_model_refresh, file_convert

@dataclass
class ValidationResult:
    allowed: bool
    reason: str | None = None
    status_code: int = 403

    @classmethod
    def accept(cls) -> ValidationResult: ...
    @classmethod
    def reject(cls, reason: str, status_code: int = 403) -> ValidationResult: ...

Import

from hindsight_api.extensions.operation_validator import (
    OperationValidatorExtension, OperationValidationError, ValidationResult,
    RetainContext, RecallContext, ReflectContext,
)

I/O Contract

Inputs

Name Type Required Description
context RetainContext / RecallContext / ... Yes Operation-specific context with all parameters

Outputs

Name Type Description
validate_*() returns ValidationResult Accepted or rejected with reason

Usage Examples

Implementing a Credit Validator

from hindsight_api.extensions.operation_validator import (
    OperationValidatorExtension, ValidationResult,
)

class CreditValidator(OperationValidatorExtension):
    async def validate_retain(self, context):
        credits = await self._get_credits(context.request_context)
        if credits < len(context.contents):
            return ValidationResult.reject("Insufficient credits")
        return ValidationResult.accept()

    async def validate_recall(self, context):
        return ValidationResult.accept()

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment