* feat: introduce hindsight-api-slim and hindsight-all-slim packages Closes #552 - Move all source code from hindsight-api/ to new hindsight-api-slim/ - hindsight-api-slim has heavy ML deps (torch, sentence-transformers, transformers, einops, flashrank, mlx, mlx-lm, safetensors) and pg0-embedded as optional extras: [local-ml], [embedded-db], [all] - hindsight-api becomes a zero-code meta-package depending on hindsight-api-slim[all] for full backward compatibility - Add hindsight-all-slim meta-package: hindsight-api-slim + client + embed - hindsight-all updated to depend on hindsight-api-slim[all] - pg0.py: lazy-import pg0 with clear ImportError pointing to [embedded-db] - Dockerfile: replace sed hack with proper uv sync --extra flags - Update release.yml, test.yml, lint.sh, release.sh, CLAUDE.md and all path references throughout the repo * refactor: rename hindsight/ directory to hindsight-all/ * docs: document hindsight-api-slim and hindsight-all-slim package variants Add package variants table and extras explanation to installation.md * docs: remove emojis from installation.md, use professional tone * docs: link Docker slim variant to pip package variants section * docs: consolidate Docker image variants into single table * ci: fix working-directory paths after package restructure - Replace all hindsight-api → hindsight-api-slim in test.yml - Replace hindsight → hindsight-all in test.yml - Add --extra embedded-db to test-embed API install step * ci: add local-ml and embedded-db extras to API sync steps These extras were previously implicit in the old hindsight-api package (which bundled everything). Now that hindsight-api-slim uses optional extras, we must explicitly request local-ml and embedded-db in CI. * ci: add API install step with embedded-db to test-embed smoke test The smoke test starts hindsight-api as a daemon, which requires pg0-embedded. Add a dedicated install step for hindsight-api-slim with embedded-db extra so the daemon can start successfully. * ci: remove --no-install-project when using optional extras When --no-install-project is combined with --extra, the optional deps are not installed because extras require the project to be active. Remove --no-install-project from steps that need local-ml or embedded-db. * ci: fix ordering of uv sync steps to preserve optional extras When uv sync runs for a different workspace member, it removes optional extras installed for other members. Fix by always running extra-requiring API sync last, after other workspace member syncs. Also remove --no-install-project from embedded-db sync in test-embed, as --no-install-project prevents optional extras from being active. * ci: add local-ml extra to test-embed API install for smoke test The smoke test starts the full API server which needs sentence-transformers for local embeddings (default provider). Add local-ml extra to the install. * ci: simplify extras with --all-extras and add slim pip smoke test - Replace explicit --extra local-ml --extra embedded-db with --all-extras for cleaner, more maintainable sync steps - Add test-pip-slim job: tests hindsight-api-slim[embedded-db] without local ML models, using Cohere for embeddings/reranking (mirrors Docker slim smoke test approach) * ci: simplify slim smoke test to health check only (mirrors Docker test)
193 lines
5.8 KiB
Python
193 lines
5.8 KiB
Python
"""
|
|
API namespace classes for organizing client methods.
|
|
|
|
These classes provide organized access to different parts of the Hindsight API
|
|
while ensuring the daemon is running before each call.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING, Any
|
|
|
|
if TYPE_CHECKING:
|
|
from .embedded import HindsightEmbedded
|
|
|
|
|
|
class BanksAPI:
|
|
"""Namespace for bank-related operations."""
|
|
|
|
def __init__(self, embedded: "HindsightEmbedded"):
|
|
self._embedded = embedded
|
|
|
|
def create(
|
|
self,
|
|
bank_id: str,
|
|
name: str | None = None,
|
|
mission: str | None = None,
|
|
disposition: dict[str, Any] | None = None,
|
|
):
|
|
"""Create a new bank."""
|
|
self._embedded._ensure_started()
|
|
return self._embedded._client.create_bank(
|
|
bank_id=bank_id,
|
|
name=name,
|
|
mission=mission,
|
|
disposition=disposition,
|
|
)
|
|
|
|
def delete(self, bank_id: str):
|
|
"""Delete a bank."""
|
|
self._embedded._ensure_started()
|
|
return self._embedded._client.delete_bank(bank_id=bank_id)
|
|
|
|
def set_mission(self, bank_id: str, mission: str):
|
|
"""Set or update the mission for a bank."""
|
|
self._embedded._ensure_started()
|
|
return self._embedded._client.set_mission(bank_id=bank_id, mission=mission)
|
|
|
|
def set_disposition(self, bank_id: str, disposition: dict[str, Any]):
|
|
"""Set or update the disposition for a bank."""
|
|
self._embedded._ensure_started()
|
|
return self._embedded._client.set_disposition(bank_id=bank_id, disposition=disposition)
|
|
|
|
|
|
class MentalModelsAPI:
|
|
"""Namespace for mental model operations."""
|
|
|
|
def __init__(self, embedded: "HindsightEmbedded"):
|
|
self._embedded = embedded
|
|
|
|
def create(
|
|
self,
|
|
bank_id: str,
|
|
name: str,
|
|
content: str,
|
|
tags: list[str] | None = None,
|
|
):
|
|
"""Create a new mental model."""
|
|
self._embedded._ensure_started()
|
|
return self._embedded._client.create_mental_model(
|
|
bank_id=bank_id,
|
|
name=name,
|
|
content=content,
|
|
tags=tags,
|
|
)
|
|
|
|
def list(self, bank_id: str, tags: list[str] | None = None):
|
|
"""List all mental models for a bank."""
|
|
self._embedded._ensure_started()
|
|
return self._embedded._client.list_mental_models(bank_id=bank_id, tags=tags)
|
|
|
|
def get(self, bank_id: str, mental_model_id: str):
|
|
"""Get a specific mental model."""
|
|
self._embedded._ensure_started()
|
|
return self._embedded._client.get_mental_model(bank_id=bank_id, mental_model_id=mental_model_id)
|
|
|
|
def refresh(self, bank_id: str, mental_model_id: str):
|
|
"""Refresh a mental model."""
|
|
self._embedded._ensure_started()
|
|
return self._embedded._client.refresh_mental_model(bank_id=bank_id, mental_model_id=mental_model_id)
|
|
|
|
def update(
|
|
self,
|
|
bank_id: str,
|
|
mental_model_id: str,
|
|
name: str | None = None,
|
|
content: str | None = None,
|
|
tags: list[str] | None = None,
|
|
):
|
|
"""Update a mental model."""
|
|
self._embedded._ensure_started()
|
|
return self._embedded._client.update_mental_model(
|
|
bank_id=bank_id,
|
|
mental_model_id=mental_model_id,
|
|
name=name,
|
|
content=content,
|
|
tags=tags,
|
|
)
|
|
|
|
def delete(self, bank_id: str, mental_model_id: str):
|
|
"""Delete a mental model."""
|
|
self._embedded._ensure_started()
|
|
return self._embedded._client.delete_mental_model(bank_id=bank_id, mental_model_id=mental_model_id)
|
|
|
|
|
|
class DirectivesAPI:
|
|
"""Namespace for directive operations."""
|
|
|
|
def __init__(self, embedded: "HindsightEmbedded"):
|
|
self._embedded = embedded
|
|
|
|
def create(
|
|
self,
|
|
bank_id: str,
|
|
name: str,
|
|
content: str,
|
|
tags: list[str] | None = None,
|
|
):
|
|
"""Create a new directive."""
|
|
self._embedded._ensure_started()
|
|
return self._embedded._client.create_directive(
|
|
bank_id=bank_id,
|
|
name=name,
|
|
content=content,
|
|
tags=tags,
|
|
)
|
|
|
|
def list(self, bank_id: str, tags: list[str] | None = None):
|
|
"""List all directives for a bank."""
|
|
self._embedded._ensure_started()
|
|
return self._embedded._client.list_directives(bank_id=bank_id, tags=tags)
|
|
|
|
def get(self, bank_id: str, directive_id: str):
|
|
"""Get a specific directive."""
|
|
self._embedded._ensure_started()
|
|
return self._embedded._client.get_directive(bank_id=bank_id, directive_id=directive_id)
|
|
|
|
def update(
|
|
self,
|
|
bank_id: str,
|
|
directive_id: str,
|
|
name: str | None = None,
|
|
content: str | None = None,
|
|
tags: list[str] | None = None,
|
|
):
|
|
"""Update a directive."""
|
|
self._embedded._ensure_started()
|
|
return self._embedded._client.update_directive(
|
|
bank_id=bank_id,
|
|
directive_id=directive_id,
|
|
name=name,
|
|
content=content,
|
|
tags=tags,
|
|
)
|
|
|
|
def delete(self, bank_id: str, directive_id: str):
|
|
"""Delete a directive."""
|
|
self._embedded._ensure_started()
|
|
return self._embedded._client.delete_directive(bank_id=bank_id, directive_id=directive_id)
|
|
|
|
|
|
class MemoriesAPI:
|
|
"""Namespace for memory operations."""
|
|
|
|
def __init__(self, embedded: "HindsightEmbedded"):
|
|
self._embedded = embedded
|
|
|
|
def list(
|
|
self,
|
|
bank_id: str,
|
|
type: str | None = None,
|
|
search_query: str | None = None,
|
|
limit: int = 100,
|
|
offset: int = 0,
|
|
):
|
|
"""List memories in a bank."""
|
|
self._embedded._ensure_started()
|
|
return self._embedded._client.list_memories(
|
|
bank_id=bank_id,
|
|
type=type,
|
|
search_query=search_query,
|
|
limit=limit,
|
|
offset=offset,
|
|
)
|