mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-04 21:06:03 +00:00
refactor: improve component loading logic and add resource directory check
This commit is contained in:
@@ -241,12 +241,14 @@ class ComponentDiscoveryEngine:
|
||||
return
|
||||
|
||||
for file in importutil.list_resource_files(path):
|
||||
if (not os.path.isdir(os.path.join(path, file))) and (file.endswith('.yaml') or file.endswith('.yml')):
|
||||
comp = self.load_component_manifest(os.path.join(path, file), owner, no_save)
|
||||
file_path = os.path.join(path, file)
|
||||
is_dir = importutil.is_resource_dir(file_path)
|
||||
if (not is_dir) and (file.endswith('.yaml') or file.endswith('.yml')):
|
||||
comp = self.load_component_manifest(file_path, owner, no_save)
|
||||
if comp is not None:
|
||||
components.append(comp)
|
||||
elif os.path.isdir(os.path.join(path, file)):
|
||||
recursive_load_component_manifests_in_dir(os.path.join(path, file), depth + 1)
|
||||
elif is_dir:
|
||||
recursive_load_component_manifests_in_dir(file_path, depth + 1)
|
||||
|
||||
recursive_load_component_manifests_in_dir(path)
|
||||
return components
|
||||
|
||||
@@ -93,5 +93,5 @@ spec:
|
||||
|
||||
execution:
|
||||
python:
|
||||
path: pkg/platform/adapters/telegram/adapter.py
|
||||
path: ./adapter.py
|
||||
attr: TelegramAdapter
|
||||
|
||||
@@ -47,3 +47,10 @@ def read_resource_file_bytes(resource_path: str) -> bytes:
|
||||
|
||||
def list_resource_files(resource_path: str) -> list[str]:
|
||||
return [f.name for f in importlib.resources.files('langbot').joinpath(resource_path).iterdir()]
|
||||
|
||||
|
||||
def is_resource_dir(resource_path: str) -> bool:
|
||||
try:
|
||||
return importlib.resources.files('langbot').joinpath(resource_path).is_dir()
|
||||
except (TypeError, FileNotFoundError):
|
||||
return False
|
||||
|
||||
@@ -10,6 +10,8 @@ spec:
|
||||
MessagePlatformAdapter:
|
||||
fromDirs:
|
||||
- path: pkg/platform/sources/
|
||||
- path: pkg/platform/adapters/
|
||||
maxDepth: 3
|
||||
LLMAPIRequester:
|
||||
fromDirs:
|
||||
- path: pkg/provider/modelmgr/requesters/
|
||||
|
||||
Reference in New Issue
Block a user