elephantine 0.3.5__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.
- elephantine/__init__.py +4 -0
- elephantine/api/app.py +43 -0
- elephantine/api/middleware/auth.py +66 -0
- elephantine/api/routes/dashboard.py +574 -0
- elephantine/api/routes/health.py +17 -0
- elephantine/api/routes/memory.py +495 -0
- elephantine/api/schemas.py +143 -0
- elephantine/cli.py +350 -0
- elephantine/client/__init__.py +4 -0
- elephantine/client/adapters/langchain_adapter.py +67 -0
- elephantine/client/client.py +230 -0
- elephantine/config.py +54 -0
- elephantine/core/auth_interface.py +44 -0
- elephantine/core/buffer.py +102 -0
- elephantine/core/conflict.py +64 -0
- elephantine/core/consolidator.py +48 -0
- elephantine/core/embedder.py +111 -0
- elephantine/core/extractor.py +99 -0
- elephantine/core/gguf_extractor.py +114 -0
- elephantine/core/governor.py +30 -0
- elephantine/core/graph_extractor.py +36 -0
- elephantine/core/proactive.py +179 -0
- elephantine/core/project.py +36 -0
- elephantine/core/scoring.py +116 -0
- elephantine/core/structured_extractor.py +124 -0
- elephantine/enterprise/__init__.py +43 -0
- elephantine/enterprise/rbac.py +84 -0
- elephantine/mcp/server.py +87 -0
- elephantine/sdk/client.py +76 -0
- elephantine/storage/lancedb_store.py +112 -0
- elephantine/storage/procedural_store.py +142 -0
- elephantine/storage/sqlite_store.py +665 -0
- elephantine-0.3.5.dist-info/METADATA +466 -0
- elephantine-0.3.5.dist-info/RECORD +37 -0
- elephantine-0.3.5.dist-info/WHEEL +4 -0
- elephantine-0.3.5.dist-info/entry_points.txt +2 -0
- elephantine-0.3.5.dist-info/licenses/LICENSE +202 -0
elephantine/__init__.py
ADDED
elephantine/api/app.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from fastapi import FastAPI
|
|
2
|
+
from fastapi.middleware.cors import CORSMiddleware
|
|
3
|
+
from elephantine.config import settings
|
|
4
|
+
from elephantine.api.routes.health import router as health_router
|
|
5
|
+
from elephantine.api.routes.memory import router as memory_router
|
|
6
|
+
from elephantine.api.routes.dashboard import router as dashboard_router
|
|
7
|
+
|
|
8
|
+
from contextlib import asynccontextmanager
|
|
9
|
+
from elephantine.api.routes.memory import get_container
|
|
10
|
+
|
|
11
|
+
@asynccontextmanager
|
|
12
|
+
async def lifespan(app: FastAPI):
|
|
13
|
+
# Startup: Start proactive background evaluator daemon
|
|
14
|
+
container = get_container()
|
|
15
|
+
await container.proactive_engine.start()
|
|
16
|
+
yield
|
|
17
|
+
# Shutdown: Stop proactive background evaluator daemon
|
|
18
|
+
await container.proactive_engine.stop()
|
|
19
|
+
|
|
20
|
+
def create_app() -> FastAPI:
|
|
21
|
+
app = FastAPI(
|
|
22
|
+
title="MemAgent Core",
|
|
23
|
+
description="Local-First, CPU-Native Cognitive AI Memory Engine",
|
|
24
|
+
version="0.1.0",
|
|
25
|
+
debug=settings.DEBUG,
|
|
26
|
+
lifespan=lifespan
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
app.add_middleware(
|
|
30
|
+
CORSMiddleware,
|
|
31
|
+
allow_origins=["*"],
|
|
32
|
+
allow_credentials=True,
|
|
33
|
+
allow_methods=["*"],
|
|
34
|
+
allow_headers=["*"],
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
app.include_router(health_router, tags=["Health"])
|
|
38
|
+
app.include_router(memory_router, tags=["Memory Primitives"])
|
|
39
|
+
app.include_router(dashboard_router, tags=["Dashboard & Inspector"])
|
|
40
|
+
|
|
41
|
+
return app
|
|
42
|
+
|
|
43
|
+
app = create_app()
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
from fastapi import Header, HTTPException, Security, Depends
|
|
3
|
+
from fastapi.security import APIKeyHeader, HTTPBearer, HTTPAuthorizationCredentials
|
|
4
|
+
from elephantine.config import settings
|
|
5
|
+
from elephantine.core.auth_interface import TenantContext
|
|
6
|
+
from elephantine.enterprise.rbac import api_key_manager, rbac_auth_engine
|
|
7
|
+
|
|
8
|
+
api_key_header = APIKeyHeader(name="X-API-Key", auto_error=False)
|
|
9
|
+
bearer_scheme = HTTPBearer(auto_error=False)
|
|
10
|
+
|
|
11
|
+
async def get_current_tenant_context(
|
|
12
|
+
api_key: Optional[str] = Security(api_key_header),
|
|
13
|
+
bearer: Optional[HTTPAuthorizationCredentials] = Security(bearer_scheme)
|
|
14
|
+
) -> TenantContext:
|
|
15
|
+
"""
|
|
16
|
+
Resolves the calling agent's tenant and security context.
|
|
17
|
+
If settings.AUTH_ENABLED is False (Community mode), grants full local access with zero configuration.
|
|
18
|
+
If True, verifies the API key or Bearer token.
|
|
19
|
+
"""
|
|
20
|
+
if not settings.AUTH_ENABLED:
|
|
21
|
+
return TenantContext(
|
|
22
|
+
tenant_id="default_tenant",
|
|
23
|
+
agent_id="local",
|
|
24
|
+
roles=["admin"],
|
|
25
|
+
is_enterprise=False
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
token = api_key or (bearer.credentials if bearer else None)
|
|
29
|
+
if not token:
|
|
30
|
+
raise HTTPException(
|
|
31
|
+
status_code=401,
|
|
32
|
+
detail="Unauthorized: Missing API Key. Provide via 'X-API-Key' header or 'Authorization: Bearer <key>'."
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
context = api_key_manager.authenticate(token)
|
|
36
|
+
if not context:
|
|
37
|
+
raise HTTPException(
|
|
38
|
+
status_code=401,
|
|
39
|
+
detail="Unauthorized: Invalid Elephantine API Key."
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
return context
|
|
43
|
+
|
|
44
|
+
async def require_write_permission(
|
|
45
|
+
context: TenantContext = Depends(get_current_tenant_context)
|
|
46
|
+
) -> TenantContext:
|
|
47
|
+
"""Ensures the caller has write authorization."""
|
|
48
|
+
can_write = await rbac_auth_engine.authorize_write(context)
|
|
49
|
+
if not can_write:
|
|
50
|
+
raise HTTPException(
|
|
51
|
+
status_code=403,
|
|
52
|
+
detail="Forbidden: Caller role has insufficient permissions to write memories."
|
|
53
|
+
)
|
|
54
|
+
return context
|
|
55
|
+
|
|
56
|
+
async def require_read_permission(
|
|
57
|
+
context: TenantContext = Depends(get_current_tenant_context)
|
|
58
|
+
) -> TenantContext:
|
|
59
|
+
"""Ensures the caller has read authorization."""
|
|
60
|
+
can_read = await rbac_auth_engine.authorize_read(context)
|
|
61
|
+
if not can_read:
|
|
62
|
+
raise HTTPException(
|
|
63
|
+
status_code=403,
|
|
64
|
+
detail="Forbidden: Caller role has insufficient permissions to read memories."
|
|
65
|
+
)
|
|
66
|
+
return context
|