rusticai-api 0.0.1__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.
- rustic_ai/api_server/__init__.py +0 -0
- rustic_ai/api_server/api_dependency_manager.py +103 -0
- rustic_ai/api_server/catalog/__init__.py +4 -0
- rustic_ai/api_server/catalog/catalog_store.py +607 -0
- rustic_ai/api_server/catalog/models.py +338 -0
- rustic_ai/api_server/catalog/router.py +423 -0
- rustic_ai/api_server/guilds/__init__.py +4 -0
- rustic_ai/api_server/guilds/comms_manager.py +256 -0
- rustic_ai/api_server/guilds/router.py +426 -0
- rustic_ai/api_server/guilds/schema.py +5 -0
- rustic_ai/api_server/guilds/service.py +30 -0
- rustic_ai/api_server/guilds/socket.py +52 -0
- rustic_ai/api_server/guilds/system_comms_manager.py +238 -0
- rustic_ai/api_server/logging/__init__.py +4 -0
- rustic_ai/api_server/logging/config.py +35 -0
- rustic_ai/api_server/logging/format.py +24 -0
- rustic_ai/api_server/main.py +95 -0
- rustic_ai/api_server/main_debug.py +17 -0
- rusticai_api-0.0.1.dist-info/METADATA +87 -0
- rusticai_api-0.0.1.dist-info/RECORD +21 -0
- rusticai_api-0.0.1.dist-info/WHEEL +4 -0
|
File without changes
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
from typing import Dict, Optional
|
|
2
|
+
|
|
3
|
+
from fastapi import HTTPException
|
|
4
|
+
from sqlalchemy import Engine
|
|
5
|
+
|
|
6
|
+
from rustic_ai.core.guild.agent_ext.depends.dependency_resolver import (
|
|
7
|
+
DependencyResolver,
|
|
8
|
+
)
|
|
9
|
+
from rustic_ai.core.guild.builders import GuildHelper
|
|
10
|
+
from rustic_ai.core.guild.dsl import DependencySpec
|
|
11
|
+
from rustic_ai.core.guild.metastore.guild_store import GuildStore
|
|
12
|
+
from rustic_ai.core.utils.basic_class_utils import get_class_from_name
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ApiDependencyManager:
|
|
16
|
+
"""Singleton class to access dependencies for a guild from the API server."""
|
|
17
|
+
|
|
18
|
+
__instance: Optional["ApiDependencyManager"] = None
|
|
19
|
+
|
|
20
|
+
def __new__(cls):
|
|
21
|
+
if cls.__instance is None:
|
|
22
|
+
cls.__instance = super(ApiDependencyManager, cls).__new__(cls)
|
|
23
|
+
return cls.__instance
|
|
24
|
+
|
|
25
|
+
def __init__(self):
|
|
26
|
+
if not hasattr(self, "initialized"):
|
|
27
|
+
self.dependency_map_cache: Dict[str, Dict[str, DependencySpec]] = {}
|
|
28
|
+
self.dependency_resolver_cache: Dict[str, Dict[str, DependencyResolver]] = {}
|
|
29
|
+
self.initialized = True
|
|
30
|
+
|
|
31
|
+
def get_dependency(self, dependency_name: str, engine: Engine, guild_id: str, agent_id: Optional[str] = None):
|
|
32
|
+
"""
|
|
33
|
+
Gets the dependency resolver for the given dependency name.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
dependency_name (str): The name of the dependency.
|
|
37
|
+
engine (Engine): The database engine.
|
|
38
|
+
guild_id (str): The guild id.
|
|
39
|
+
agent_id (str): The agent id.
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
Any: The dependency.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
if (
|
|
46
|
+
guild_id not in self.dependency_resolver_cache
|
|
47
|
+
or dependency_name not in self.dependency_resolver_cache[guild_id]
|
|
48
|
+
):
|
|
49
|
+
if guild_id not in self.dependency_map_cache:
|
|
50
|
+
|
|
51
|
+
guild_store = GuildStore(engine)
|
|
52
|
+
guild_model = guild_store.get_guild(guild_id)
|
|
53
|
+
|
|
54
|
+
if not guild_model:
|
|
55
|
+
raise HTTPException(status_code=404, detail="Guild not found")
|
|
56
|
+
|
|
57
|
+
guild_spec = guild_model.to_guild_spec()
|
|
58
|
+
|
|
59
|
+
self.dependency_map_cache[guild_id] = GuildHelper.get_guild_dependency_map(guild_spec)
|
|
60
|
+
|
|
61
|
+
if dependency_name not in self.dependency_map_cache[guild_id]: # pragma: no cover
|
|
62
|
+
raise HTTPException(
|
|
63
|
+
status_code=404, detail=f"Dependency for {dependency_name} not configured for guild {guild_id}"
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
if guild_id not in self.dependency_resolver_cache:
|
|
67
|
+
self.dependency_resolver_cache[guild_id] = {}
|
|
68
|
+
|
|
69
|
+
self.dependency_resolver_cache[guild_id][dependency_name] = self._load_dependency_resolver(
|
|
70
|
+
guild_id, dependency_name
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
resolver = self.dependency_resolver_cache[guild_id][dependency_name]
|
|
74
|
+
dependency = resolver.get_or_resolve(guild_id, agent_id)
|
|
75
|
+
|
|
76
|
+
return dependency
|
|
77
|
+
|
|
78
|
+
def _load_dependency_resolver(self, guild_id: str, name: str) -> DependencyResolver:
|
|
79
|
+
"""
|
|
80
|
+
Loads the dependency resolver for the given name.
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
guild_id (str): The guild id.
|
|
84
|
+
name (str): The name of the dependency resolver.
|
|
85
|
+
|
|
86
|
+
Returns:
|
|
87
|
+
DependencyResolver: The dependency resolver for the agent.
|
|
88
|
+
"""
|
|
89
|
+
dependencies = self.dependency_map_cache[guild_id]
|
|
90
|
+
if name in dependencies:
|
|
91
|
+
resolver_spec = dependencies[name]
|
|
92
|
+
resolver_class = get_class_from_name(resolver_spec.class_name)
|
|
93
|
+
if issubclass(resolver_class, DependencyResolver):
|
|
94
|
+
return resolver_class(**resolver_spec.properties)
|
|
95
|
+
else: # pragma: no cover
|
|
96
|
+
raise ValueError(f"Dependency resolver {resolver_spec} is not a valid dependency resolver.")
|
|
97
|
+
else: # pragma: no cover
|
|
98
|
+
raise ValueError(f"Dependency {name} not found in agent dependencies.")
|
|
99
|
+
|
|
100
|
+
@classmethod
|
|
101
|
+
def get_instance(cls) -> "ApiDependencyManager":
|
|
102
|
+
api_dependency_manager = ApiDependencyManager()
|
|
103
|
+
return api_dependency_manager
|