-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add Jungian Intelligence Layer service v3.2.0 #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,301 @@ | ||||||||||||||||||||||||||||||||||||||
| """Jungian Intelligence Layer service for Plugged.in SDK | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Provides access to the Jungian-inspired intelligence layer including | ||||||||||||||||||||||||||||||||||||||
| archetype-aware pattern search, individuation scoring, synchronicity | ||||||||||||||||||||||||||||||||||||||
| detection, and dream-cycle consolidation history. | ||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| from typing import TYPE_CHECKING, Any, Dict, List, Optional | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| from ..exceptions import PluggedInError | ||||||||||||||||||||||||||||||||||||||
| from ..types import ( | ||||||||||||||||||||||||||||||||||||||
| ArchetypedPattern, | ||||||||||||||||||||||||||||||||||||||
| ArchetypeSearchResponse, | ||||||||||||||||||||||||||||||||||||||
| DreamConsolidation, | ||||||||||||||||||||||||||||||||||||||
| IndividuationHistoryEntry, | ||||||||||||||||||||||||||||||||||||||
| IndividuationResponse, | ||||||||||||||||||||||||||||||||||||||
| SynchronicityPattern, | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if TYPE_CHECKING: | ||||||||||||||||||||||||||||||||||||||
| from ..client import AsyncPluggedInClient, PluggedInClient | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| # Shared Helper Functions | ||||||||||||||||||||||||||||||||||||||
| # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def _parse_archetype_search(data: Dict[str, Any]) -> ArchetypeSearchResponse: | ||||||||||||||||||||||||||||||||||||||
| """Parse the archetype search response into typed model.""" | ||||||||||||||||||||||||||||||||||||||
| patterns_raw = data.get("patterns", []) | ||||||||||||||||||||||||||||||||||||||
| patterns = [ArchetypedPattern(**p) for p in patterns_raw] | ||||||||||||||||||||||||||||||||||||||
| return ArchetypeSearchResponse(patterns=patterns) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def _parse_individuation(data: Dict[str, Any]) -> IndividuationResponse: | ||||||||||||||||||||||||||||||||||||||
| """Parse the individuation score response into typed model.""" | ||||||||||||||||||||||||||||||||||||||
| return IndividuationResponse(**data) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def _parse_individuation_history(data: Any) -> List[IndividuationHistoryEntry]: | ||||||||||||||||||||||||||||||||||||||
| """Parse the individuation history response into typed list.""" | ||||||||||||||||||||||||||||||||||||||
| if isinstance(data, list): | ||||||||||||||||||||||||||||||||||||||
| return [IndividuationHistoryEntry(**entry) for entry in data] | ||||||||||||||||||||||||||||||||||||||
| # If wrapped in an object, try the 'history' key | ||||||||||||||||||||||||||||||||||||||
| if isinstance(data, dict): | ||||||||||||||||||||||||||||||||||||||
| entries = data.get("history", data.get("entries", [])) | ||||||||||||||||||||||||||||||||||||||
| return [IndividuationHistoryEntry(**entry) for entry in entries] | ||||||||||||||||||||||||||||||||||||||
| return [] | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+43
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation is not fully robust. If the API returns an unexpected data type (e.g., items_raw = []
if isinstance(data, list):
items_raw = data
elif isinstance(data, dict):
items_raw = data.get("history")
if not isinstance(items_raw, list):
items_raw = data.get("entries")
if not isinstance(items_raw, list):
return []
return [IndividuationHistoryEntry(**entry) for entry in items_raw if isinstance(entry, dict)] |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def _parse_synchronicity_patterns(data: Any) -> List[SynchronicityPattern]: | ||||||||||||||||||||||||||||||||||||||
| """Parse synchronicity patterns response.""" | ||||||||||||||||||||||||||||||||||||||
| if isinstance(data, list): | ||||||||||||||||||||||||||||||||||||||
| return [SynchronicityPattern(**p) for p in data] | ||||||||||||||||||||||||||||||||||||||
| if isinstance(data, dict): | ||||||||||||||||||||||||||||||||||||||
| patterns = data.get("patterns", []) | ||||||||||||||||||||||||||||||||||||||
| return [SynchronicityPattern(**p) for p in patterns] | ||||||||||||||||||||||||||||||||||||||
| return [] | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+54
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the other parsing functions in this file, this implementation is not robust against unexpected API response formats. If
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def _parse_dream_history(data: Any) -> List[DreamConsolidation]: | ||||||||||||||||||||||||||||||||||||||
| """Parse dream consolidation history response.""" | ||||||||||||||||||||||||||||||||||||||
| if isinstance(data, list): | ||||||||||||||||||||||||||||||||||||||
| return [DreamConsolidation(**d) for d in data] | ||||||||||||||||||||||||||||||||||||||
| if isinstance(data, dict): | ||||||||||||||||||||||||||||||||||||||
| entries = data.get("history", data.get("consolidations", [])) | ||||||||||||||||||||||||||||||||||||||
| return [DreamConsolidation(**d) for d in entries] | ||||||||||||||||||||||||||||||||||||||
| return [] | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+64
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function has the same robustness issue as the other parsers. It can fail with a
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| # Synchronous Jungian Service | ||||||||||||||||||||||||||||||||||||||
| # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| class JungianService: | ||||||||||||||||||||||||||||||||||||||
| """Synchronous Jungian Intelligence Layer service for Plugged.in. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Provides archetype-aware pattern search, individuation scoring, | ||||||||||||||||||||||||||||||||||||||
| synchronicity detection, and dream-cycle consolidation history. | ||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def __init__(self, client: "PluggedInClient"): | ||||||||||||||||||||||||||||||||||||||
| self.client = client | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def search_with_context( | ||||||||||||||||||||||||||||||||||||||
| self, | ||||||||||||||||||||||||||||||||||||||
| query: str, | ||||||||||||||||||||||||||||||||||||||
| tool_name: Optional[str] = None, | ||||||||||||||||||||||||||||||||||||||
| outcome: Optional[str] = None, | ||||||||||||||||||||||||||||||||||||||
| ) -> ArchetypeSearchResponse: | ||||||||||||||||||||||||||||||||||||||
| """Search patterns with archetype context injection. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Sends a query to the archetype inject endpoint which returns | ||||||||||||||||||||||||||||||||||||||
| patterns enriched with Jungian archetype classifications. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Args: | ||||||||||||||||||||||||||||||||||||||
| query: Natural language search query | ||||||||||||||||||||||||||||||||||||||
| tool_name: Optional tool name for context | ||||||||||||||||||||||||||||||||||||||
| outcome: Optional outcome description for context | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Returns: | ||||||||||||||||||||||||||||||||||||||
| ArchetypeSearchResponse with classified patterns | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Raises: | ||||||||||||||||||||||||||||||||||||||
| PluggedInError: If the API request fails | ||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||
| payload: Dict[str, Any] = {"query": query} | ||||||||||||||||||||||||||||||||||||||
| if tool_name is not None: | ||||||||||||||||||||||||||||||||||||||
| payload["tool_name"] = tool_name | ||||||||||||||||||||||||||||||||||||||
| if outcome is not None: | ||||||||||||||||||||||||||||||||||||||
| payload["outcome"] = outcome | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| response = self.client.request( | ||||||||||||||||||||||||||||||||||||||
| "POST", "/api/memory/archetype/inject", json=payload | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
| return _parse_archetype_search(response.json()) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def get_individuation_score(self) -> IndividuationResponse: | ||||||||||||||||||||||||||||||||||||||
| """Get the current individuation score. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| The individuation score measures the agent's psychological | ||||||||||||||||||||||||||||||||||||||
| development across four components: memory depth, learning | ||||||||||||||||||||||||||||||||||||||
| velocity, collective contribution, and self-awareness. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Returns: | ||||||||||||||||||||||||||||||||||||||
| IndividuationResponse with score, level, trend, and components | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Raises: | ||||||||||||||||||||||||||||||||||||||
| PluggedInError: If the API request fails | ||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||
| response = self.client.request("GET", "/api/memory/individuation") | ||||||||||||||||||||||||||||||||||||||
| return _parse_individuation(response.json()) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def get_individuation_history( | ||||||||||||||||||||||||||||||||||||||
| self, days: int = 30 | ||||||||||||||||||||||||||||||||||||||
| ) -> List[IndividuationHistoryEntry]: | ||||||||||||||||||||||||||||||||||||||
| """Get individuation score history over a time period. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Args: | ||||||||||||||||||||||||||||||||||||||
| days: Number of days of history to retrieve (default: 30) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Returns: | ||||||||||||||||||||||||||||||||||||||
| List of IndividuationHistoryEntry ordered by date | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Raises: | ||||||||||||||||||||||||||||||||||||||
| PluggedInError: If the API request fails | ||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||
| response = self.client.request( | ||||||||||||||||||||||||||||||||||||||
| "GET", | ||||||||||||||||||||||||||||||||||||||
| "/api/memory/individuation", | ||||||||||||||||||||||||||||||||||||||
| params={"history": "true", "days": str(days)}, | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
| return _parse_individuation_history(response.json()) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def get_synchronicity_patterns(self) -> List[SynchronicityPattern]: | ||||||||||||||||||||||||||||||||||||||
| """Get detected synchronicity patterns. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Synchronicity patterns are meaningful coincidences detected | ||||||||||||||||||||||||||||||||||||||
| across multiple profiles in the collective unconscious layer. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Returns: | ||||||||||||||||||||||||||||||||||||||
| List of SynchronicityPattern instances | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Raises: | ||||||||||||||||||||||||||||||||||||||
| PluggedInError: If the API request fails | ||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||
| response = self.client.request("GET", "/api/memory/sync/patterns") | ||||||||||||||||||||||||||||||||||||||
| return _parse_synchronicity_patterns(response.json()) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def get_dream_history(self) -> List[DreamConsolidation]: | ||||||||||||||||||||||||||||||||||||||
| """Get dream-cycle consolidation history. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Dream consolidations represent periodic memory compression | ||||||||||||||||||||||||||||||||||||||
| cycles that merge similar patterns and reduce token usage. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Returns: | ||||||||||||||||||||||||||||||||||||||
| List of DreamConsolidation records | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Raises: | ||||||||||||||||||||||||||||||||||||||
| PluggedInError: If the API request fails | ||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||
| response = self.client.request("GET", "/api/memory/dream/history") | ||||||||||||||||||||||||||||||||||||||
| return _parse_dream_history(response.json()) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| # Asynchronous Jungian Service | ||||||||||||||||||||||||||||||||||||||
| # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| class AsyncJungianService: | ||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||||||||||||||||||||||||||||||||||||||
| """Asynchronous Jungian Intelligence Layer service for Plugged.in. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Provides archetype-aware pattern search, individuation scoring, | ||||||||||||||||||||||||||||||||||||||
| synchronicity detection, and dream-cycle consolidation history. | ||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def __init__(self, client: "AsyncPluggedInClient"): | ||||||||||||||||||||||||||||||||||||||
| self.client = client | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| async def search_with_context( | ||||||||||||||||||||||||||||||||||||||
| self, | ||||||||||||||||||||||||||||||||||||||
| query: str, | ||||||||||||||||||||||||||||||||||||||
| tool_name: Optional[str] = None, | ||||||||||||||||||||||||||||||||||||||
| outcome: Optional[str] = None, | ||||||||||||||||||||||||||||||||||||||
| ) -> ArchetypeSearchResponse: | ||||||||||||||||||||||||||||||||||||||
| """Search patterns with archetype context injection. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Sends a query to the archetype inject endpoint which returns | ||||||||||||||||||||||||||||||||||||||
| patterns enriched with Jungian archetype classifications. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Args: | ||||||||||||||||||||||||||||||||||||||
| query: Natural language search query | ||||||||||||||||||||||||||||||||||||||
| tool_name: Optional tool name for context | ||||||||||||||||||||||||||||||||||||||
| outcome: Optional outcome description for context | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Returns: | ||||||||||||||||||||||||||||||||||||||
| ArchetypeSearchResponse with classified patterns | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Raises: | ||||||||||||||||||||||||||||||||||||||
| PluggedInError: If the API request fails | ||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||
| payload: Dict[str, Any] = {"query": query} | ||||||||||||||||||||||||||||||||||||||
| if tool_name is not None: | ||||||||||||||||||||||||||||||||||||||
| payload["tool_name"] = tool_name | ||||||||||||||||||||||||||||||||||||||
| if outcome is not None: | ||||||||||||||||||||||||||||||||||||||
| payload["outcome"] = outcome | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| response = await self.client.request( | ||||||||||||||||||||||||||||||||||||||
| "POST", "/api/memory/archetype/inject", json=payload | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
| return _parse_archetype_search(response.json()) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| async def get_individuation_score(self) -> IndividuationResponse: | ||||||||||||||||||||||||||||||||||||||
| """Get the current individuation score. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| The individuation score measures the agent's psychological | ||||||||||||||||||||||||||||||||||||||
| development across four components: memory depth, learning | ||||||||||||||||||||||||||||||||||||||
| velocity, collective contribution, and self-awareness. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Returns: | ||||||||||||||||||||||||||||||||||||||
| IndividuationResponse with score, level, trend, and components | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Raises: | ||||||||||||||||||||||||||||||||||||||
| PluggedInError: If the API request fails | ||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||
| response = await self.client.request("GET", "/api/memory/individuation") | ||||||||||||||||||||||||||||||||||||||
| return _parse_individuation(response.json()) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| async def get_individuation_history( | ||||||||||||||||||||||||||||||||||||||
| self, days: int = 30 | ||||||||||||||||||||||||||||||||||||||
| ) -> List[IndividuationHistoryEntry]: | ||||||||||||||||||||||||||||||||||||||
| """Get individuation score history over a time period. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Args: | ||||||||||||||||||||||||||||||||||||||
| days: Number of days of history to retrieve (default: 30) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Returns: | ||||||||||||||||||||||||||||||||||||||
| List of IndividuationHistoryEntry ordered by date | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Raises: | ||||||||||||||||||||||||||||||||||||||
| PluggedInError: If the API request fails | ||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||
| response = await self.client.request( | ||||||||||||||||||||||||||||||||||||||
| "GET", | ||||||||||||||||||||||||||||||||||||||
| "/api/memory/individuation", | ||||||||||||||||||||||||||||||||||||||
| params={"history": "true", "days": str(days)}, | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
| return _parse_individuation_history(response.json()) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| async def get_synchronicity_patterns(self) -> List[SynchronicityPattern]: | ||||||||||||||||||||||||||||||||||||||
| """Get detected synchronicity patterns. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Synchronicity patterns are meaningful coincidences detected | ||||||||||||||||||||||||||||||||||||||
| across multiple profiles in the collective unconscious layer. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Returns: | ||||||||||||||||||||||||||||||||||||||
| List of SynchronicityPattern instances | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Raises: | ||||||||||||||||||||||||||||||||||||||
| PluggedInError: If the API request fails | ||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||
| response = await self.client.request("GET", "/api/memory/sync/patterns") | ||||||||||||||||||||||||||||||||||||||
| return _parse_synchronicity_patterns(response.json()) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| async def get_dream_history(self) -> List[DreamConsolidation]: | ||||||||||||||||||||||||||||||||||||||
| """Get dream-cycle consolidation history. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Dream consolidations represent periodic memory compression | ||||||||||||||||||||||||||||||||||||||
| cycles that merge similar patterns and reduce token usage. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Returns: | ||||||||||||||||||||||||||||||||||||||
| List of DreamConsolidation records | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Raises: | ||||||||||||||||||||||||||||||||||||||
| PluggedInError: If the API request fails | ||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||
| response = await self.client.request("GET", "/api/memory/dream/history") | ||||||||||||||||||||||||||||||||||||||
| return _parse_dream_history(response.json()) | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider extracting shared list-extraction and request-building helpers to reduce repeated parsing and wiring logic across the Jungian service functions.
You can trim complexity a bit in two focused areas without changing any behavior.
1. Centralize the “flexible shape” parsing
The three helpers
_parse_individuation_history,_parse_synchronicity_patterns, and_parse_dream_historyall repeat the same pattern: acceptAny, handlelistordictwith a couple of possible keys, and silently fall back to[].You can keep the same accepted shapes but centralize the logic so each parser is simpler and less branched:
Then the individual parsers become much narrower and easier to reason about:
If you want to make unexpected shapes more visible later, you can swap the
return []in_extract_list_payloadfor aPluggedInErrorwithout changing all call sites.2. Share sync/async request + parse wiring
The sync and async services mostly differ in:
requestis awaited.You can keep the separate public classes/signatures but factor out the “request + parse” pattern into a small helper to cut repetition. For example, for the individuation endpoints:
Usage in sync:
Usage in async:
You can apply the same approach for:
_build_search_with_context_payload(query, tool_name, outcome)"/api/memory/individuation"/"/api/memory/sync/patterns"/"/api/memory/dream/history"This keeps functionality identical while reducing duplicated literals and argument construction logic, and makes future changes (e.g., adding a param) less error-prone across sync/async variants.