refactor: improve component loading logic and add resource directory check

This commit is contained in:
RockChinQ
2026-03-23 01:39:14 +08:00
committed by Junyan Qin
parent d1b7d56392
commit eb475245ab
4 changed files with 16 additions and 5 deletions

View File

@@ -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

View File

@@ -93,5 +93,5 @@ spec:
execution:
python:
path: pkg/platform/adapters/telegram/adapter.py
path: ./adapter.py
attr: TelegramAdapter

View File

@@ -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

View File

@@ -10,6 +10,8 @@ spec:
MessagePlatformAdapter:
fromDirs:
- path: pkg/platform/sources/
- path: pkg/platform/adapters/
maxDepth: 3
LLMAPIRequester:
fromDirs:
- path: pkg/provider/modelmgr/requesters/