fix(openviking): target-aware mirror subdir, drop private-attr access, dedupe URI builder
- on_memory_write: map target='memory' -> patterns/, 'user' -> preferences/ (was hardcoded to preferences/ for both) - Replace client._user with self._user (no private-attr leakage) - Extract _build_memory_uri() helper + module-level subdir maps - Restore on_memory_write signature parity with MemoryProvider base (metadata kwarg; eliminates Pyright incompatible-override warning) - AUTHOR_MAP entry for chrisdlc119@outlook.com
This commit is contained in:
@@ -47,6 +47,25 @@ _DEFAULT_ENDPOINT = "http://127.0.0.1:1933"
|
|||||||
_TIMEOUT = 30.0
|
_TIMEOUT = 30.0
|
||||||
_REMOTE_RESOURCE_PREFIXES = ("http://", "https://", "git@", "ssh://", "git://")
|
_REMOTE_RESOURCE_PREFIXES = ("http://", "https://", "git@", "ssh://", "git://")
|
||||||
|
|
||||||
|
# Maps the viking_remember `category` enum to a viking:// subdirectory.
|
||||||
|
# Keep in sync with REMEMBER_SCHEMA.parameters.properties.category.enum.
|
||||||
|
_CATEGORY_SUBDIR_MAP = {
|
||||||
|
"preference": "preferences",
|
||||||
|
"entity": "entities",
|
||||||
|
"event": "events",
|
||||||
|
"case": "cases",
|
||||||
|
"pattern": "patterns",
|
||||||
|
}
|
||||||
|
_DEFAULT_MEMORY_SUBDIR = "preferences"
|
||||||
|
|
||||||
|
# Maps the built-in memory tool's `target` ("user" vs "memory") to a subdir
|
||||||
|
# for on_memory_write mirroring. User profile facts → preferences; agent
|
||||||
|
# notes / observations → patterns. Anything unknown falls back to the default.
|
||||||
|
_MEMORY_WRITE_TARGET_SUBDIR_MAP = {
|
||||||
|
"user": "preferences",
|
||||||
|
"memory": "patterns",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Process-level atexit safety net — ensures pending sessions are committed
|
# Process-level atexit safety net — ensures pending sessions are committed
|
||||||
@@ -607,19 +626,31 @@ class OpenVikingMemoryProvider(MemoryProvider):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning("OpenViking session commit failed: %s", e)
|
logger.warning("OpenViking session commit failed: %s", e)
|
||||||
|
|
||||||
def on_memory_write(self, action: str, target: str, content: str) -> None:
|
def _build_memory_uri(self, subdir: str) -> str:
|
||||||
|
"""Build a viking:// memory URI under the configured user/subdir."""
|
||||||
|
slug = uuid.uuid4().hex[:12]
|
||||||
|
return f"viking://user/{self._user}/memories/{subdir}/mem_{slug}.md"
|
||||||
|
|
||||||
|
def on_memory_write(
|
||||||
|
self,
|
||||||
|
action: str,
|
||||||
|
target: str,
|
||||||
|
content: str,
|
||||||
|
metadata: Optional[Dict[str, Any]] = None,
|
||||||
|
) -> None:
|
||||||
"""Mirror built-in memory writes to OpenViking via content/write."""
|
"""Mirror built-in memory writes to OpenViking via content/write."""
|
||||||
if not self._client or action != "add" or not content:
|
if not self._client or action != "add" or not content:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
subdir = _MEMORY_WRITE_TARGET_SUBDIR_MAP.get(target, _DEFAULT_MEMORY_SUBDIR)
|
||||||
|
uri = self._build_memory_uri(subdir)
|
||||||
|
|
||||||
def _write():
|
def _write():
|
||||||
try:
|
try:
|
||||||
client = _VikingClient(
|
client = _VikingClient(
|
||||||
self._endpoint, self._api_key,
|
self._endpoint, self._api_key,
|
||||||
account=self._account, user=self._user, agent=self._agent,
|
account=self._account, user=self._user, agent=self._agent,
|
||||||
)
|
)
|
||||||
slug = uuid.uuid4().hex[:12]
|
|
||||||
uri = f"viking://user/{client._user}/memories/preferences/mem_{slug}.md"
|
|
||||||
client.post("/api/v1/content/write", {
|
client.post("/api/v1/content/write", {
|
||||||
"uri": uri,
|
"uri": uri,
|
||||||
"content": content,
|
"content": content,
|
||||||
@@ -858,21 +889,8 @@ class OpenVikingMemoryProvider(MemoryProvider):
|
|||||||
return tool_error("content is required")
|
return tool_error("content is required")
|
||||||
|
|
||||||
category = args.get("category", "")
|
category = args.get("category", "")
|
||||||
|
subdir = _CATEGORY_SUBDIR_MAP.get(category, _DEFAULT_MEMORY_SUBDIR)
|
||||||
# Map category to a viking:// subdirectory for organized storage
|
uri = self._build_memory_uri(subdir)
|
||||||
subdir_map = {
|
|
||||||
"preference": "preferences",
|
|
||||||
"entity": "entities",
|
|
||||||
"event": "events",
|
|
||||||
"case": "cases",
|
|
||||||
"pattern": "patterns",
|
|
||||||
}
|
|
||||||
subdir = subdir_map.get(category, "preferences")
|
|
||||||
|
|
||||||
# Build a deterministic URI with UUID to avoid collisions
|
|
||||||
usr = self._user
|
|
||||||
slug = uuid.uuid4().hex[:12]
|
|
||||||
uri = f"viking://user/{usr}/memories/{subdir}/mem_{slug}.md"
|
|
||||||
|
|
||||||
# Write directly via content/write API.
|
# Write directly via content/write API.
|
||||||
# This creates the file, stores the content, and queues vector indexing
|
# This creates the file, stores the content, and queues vector indexing
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ AUTHOR_MAP = {
|
|||||||
"nat@nthrow.io": "nthrow",
|
"nat@nthrow.io": "nthrow",
|
||||||
"m@mobrienv.dev": "mikeyobrien",
|
"m@mobrienv.dev": "mikeyobrien",
|
||||||
"saeed919@pm.me": "falasi",
|
"saeed919@pm.me": "falasi",
|
||||||
|
"chrisdlc119@outlook.com": "chdlc",
|
||||||
"omar@techdeveloper.site": "nycomar",
|
"omar@techdeveloper.site": "nycomar",
|
||||||
"qiyin.zuo@pcitc.com": "qiyin-code",
|
"qiyin.zuo@pcitc.com": "qiyin-code",
|
||||||
"mr.aashiz@gmail.com": "aashizpoudel",
|
"mr.aashiz@gmail.com": "aashizpoudel",
|
||||||
|
|||||||
Reference in New Issue
Block a user