mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-21 11:56:09 +00:00
fix(tools): support skill mount root discovery
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import fnmatch
|
||||
import json
|
||||
import os
|
||||
|
||||
@@ -908,6 +909,23 @@ else:
|
||||
path = str(parameters.get('path', '/workspace') or '/workspace')
|
||||
self.ap.logger.info(f'glob tool invoked: query_id={query.query_id} pattern={pattern} path={path}')
|
||||
|
||||
if path.rstrip('/') == skill_loader.SKILL_MOUNT_PREFIX:
|
||||
skill_names = set(skill_loader.get_visible_skills(self.ap, query))
|
||||
skill_names.update(skill_loader.get_activated_skills(query))
|
||||
matches = [
|
||||
skill_loader.get_virtual_skill_mount_path(skill_name)
|
||||
for skill_name in sorted(skill_names)
|
||||
if fnmatch.fnmatchcase(skill_name, pattern)
|
||||
]
|
||||
return {
|
||||
'ok': True,
|
||||
'matches': matches,
|
||||
'preview': '\n'.join(matches),
|
||||
'total': len(matches),
|
||||
'truncated': False,
|
||||
'truncated_by': None,
|
||||
}
|
||||
|
||||
host_path, selected_skill = self._resolve_host_path(
|
||||
query,
|
||||
path,
|
||||
|
||||
@@ -563,6 +563,45 @@ class TestSkillToolLoader:
|
||||
|
||||
|
||||
class TestNativeToolLoaderSkillPaths:
|
||||
@pytest.mark.asyncio
|
||||
async def test_glob_skill_root_lists_visible_and_activated_mounts(self):
|
||||
from langbot.pkg.provider.tools.loaders.native import NativeToolLoader
|
||||
from langbot.pkg.provider.tools.loaders.skill import PIPELINE_BOUND_SKILLS_KEY, register_activated_skill
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
ap = _make_ap()
|
||||
ap.box_service = SimpleNamespace(available=True, default_workspace=tmpdir)
|
||||
ap.skill_mgr = SimpleNamespace(
|
||||
skills={
|
||||
'visible-skill': _make_skill_data(name='visible-skill', package_root=tmpdir),
|
||||
'hidden-skill': _make_skill_data(name='hidden-skill', package_root=tmpdir),
|
||||
}
|
||||
)
|
||||
loader = NativeToolLoader(ap)
|
||||
query = SimpleNamespace(
|
||||
query_id='q1',
|
||||
variables={PIPELINE_BOUND_SKILLS_KEY: ['visible-skill']},
|
||||
)
|
||||
register_activated_skill(query, _make_skill_data(name='activated-skill', package_root=tmpdir))
|
||||
|
||||
result = await loader.invoke_tool(
|
||||
'glob',
|
||||
{'path': '/workspace/.skills', 'pattern': '*'},
|
||||
query,
|
||||
)
|
||||
|
||||
assert result == {
|
||||
'ok': True,
|
||||
'matches': [
|
||||
'/workspace/.skills/activated-skill',
|
||||
'/workspace/.skills/visible-skill',
|
||||
],
|
||||
'preview': '/workspace/.skills/activated-skill\n/workspace/.skills/visible-skill',
|
||||
'total': 2,
|
||||
'truncated': False,
|
||||
'truncated_by': None,
|
||||
}
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_read_visible_skill_file(self):
|
||||
from langbot.pkg.provider.tools.loaders.native import NativeToolLoader
|
||||
|
||||
Reference in New Issue
Block a user