memra-local 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- memra_local/__init__.py +3 -0
- memra_local/__main__.py +6 -0
- memra_local/app.py +65 -0
- memra_local/cli.py +862 -0
- memra_local/config.py +87 -0
- memra_local/exceptions.py +14 -0
- memra_local/hooks/__init__.py +1 -0
- memra_local/hooks/extractor.py +93 -0
- memra_local/hooks/installer.py +102 -0
- memra_local/mcp_server.py +497 -0
- memra_local/models.py +236 -0
- memra_local/routes/__init__.py +0 -0
- memra_local/routes/bootstrap.py +21 -0
- memra_local/routes/memories.py +151 -0
- memra_local/routes/search.py +40 -0
- memra_local/services/__init__.py +0 -0
- memra_local/services/embedding_service.py +61 -0
- memra_local/services/factory.py +57 -0
- memra_local/services/memory_service.py +703 -0
- memra_local/services/migration_service.py +158 -0
- memra_local/services/pii_client.py +43 -0
- memra_local/services/sync_service.py +594 -0
- memra_local/storage/__init__.py +0 -0
- memra_local/storage/flat_file.py +107 -0
- memra_local/storage/sqlite_index.py +607 -0
- memra_local-0.2.0.dist-info/METADATA +98 -0
- memra_local-0.2.0.dist-info/RECORD +31 -0
- memra_local-0.2.0.dist-info/WHEEL +5 -0
- memra_local-0.2.0.dist-info/entry_points.txt +2 -0
- memra_local-0.2.0.dist-info/licenses/LICENSE +57 -0
- memra_local-0.2.0.dist-info/top_level.txt +1 -0
memra_local/__init__.py
ADDED
memra_local/__main__.py
ADDED
memra_local/app.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""FastAPI application factory with lifespan for memra-local."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from contextlib import asynccontextmanager
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import AsyncIterator
|
|
8
|
+
|
|
9
|
+
from fastapi import FastAPI
|
|
10
|
+
|
|
11
|
+
from memra_local import __version__
|
|
12
|
+
from memra_local.config import resolve_scope
|
|
13
|
+
from memra_local.routes import bootstrap, memories, search
|
|
14
|
+
from memra_local.services.factory import create_service
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def create_app(
|
|
18
|
+
scope: str = "auto",
|
|
19
|
+
storage_dir: Path | None = None,
|
|
20
|
+
) -> FastAPI:
|
|
21
|
+
"""Create and configure the FastAPI application.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
scope: Storage scope -- "global", "project", or "auto".
|
|
25
|
+
storage_dir: Override storage directory (used by tests).
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
Configured FastAPI app with service on app.state.service.
|
|
29
|
+
"""
|
|
30
|
+
resolved_scope = resolve_scope(scope) if storage_dir is None else scope
|
|
31
|
+
|
|
32
|
+
# Use shared factory for service creation (same as MCP server)
|
|
33
|
+
service = create_service(scope=scope, storage_dir=storage_dir)
|
|
34
|
+
|
|
35
|
+
@asynccontextmanager
|
|
36
|
+
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
|
|
37
|
+
"""Index is already initialized by factory; just handle shutdown."""
|
|
38
|
+
yield
|
|
39
|
+
service.index.close()
|
|
40
|
+
|
|
41
|
+
app = FastAPI(
|
|
42
|
+
title="Memra Local",
|
|
43
|
+
version=__version__,
|
|
44
|
+
description="Local memory server for AI agents",
|
|
45
|
+
lifespan=lifespan,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
# Store service on app state for route access
|
|
49
|
+
app.state.service = service
|
|
50
|
+
|
|
51
|
+
# Include routers with /v1 prefix
|
|
52
|
+
app.include_router(memories.router, prefix="/v1")
|
|
53
|
+
app.include_router(search.router, prefix="/v1")
|
|
54
|
+
app.include_router(bootstrap.router, prefix="/v1")
|
|
55
|
+
|
|
56
|
+
# Health endpoint (no prefix)
|
|
57
|
+
@app.get("/health")
|
|
58
|
+
def health():
|
|
59
|
+
return {
|
|
60
|
+
"status": "healthy",
|
|
61
|
+
"version": __version__,
|
|
62
|
+
"scope": resolved_scope,
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return app
|