Skip to content

Commit 7791dd1

Browse files
committed
fix(plugin): tolerate older runtime sdk without vector list
1 parent 5cbd604 commit 7791dd1

2 files changed

Lines changed: 33 additions & 13 deletions

File tree

src/langbot/pkg/plugin/handler.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -555,19 +555,19 @@ async def vector_delete(data: dict[str, Any]) -> handler.ActionResponse:
555555
except Exception as e:
556556
return _make_rag_error_response(e, 'VectorStoreError', collection_id=collection_id)
557557

558-
@self.action(PluginToRuntimeAction.VECTOR_LIST)
559-
async def vector_list(data: dict[str, Any]) -> handler.ActionResponse:
560-
collection_id = data['collection_id']
561-
filters = data.get('filters')
562-
limit = data.get('limit', 20)
563-
offset = data.get('offset', 0)
564-
try:
565-
items, total = await self.ap.rag_runtime_service.vector_list(
566-
collection_id, filters, limit, offset
567-
)
568-
return handler.ActionResponse.success(data={'items': items, 'total': total})
569-
except Exception as e:
570-
return _make_rag_error_response(e, 'VectorStoreError', collection_id=collection_id)
558+
if hasattr(PluginToRuntimeAction, 'VECTOR_LIST'):
559+
560+
@self.action(PluginToRuntimeAction.VECTOR_LIST)
561+
async def vector_list(data: dict[str, Any]) -> handler.ActionResponse:
562+
collection_id = data['collection_id']
563+
filters = data.get('filters')
564+
limit = data.get('limit', 20)
565+
offset = data.get('offset', 0)
566+
try:
567+
items, total = await self.ap.rag_runtime_service.vector_list(collection_id, filters, limit, offset)
568+
return handler.ActionResponse.success(data={'items': items, 'total': total})
569+
except Exception as e:
570+
return _make_rag_error_response(e, 'VectorStoreError', collection_id=collection_id)
571571

572572
@self.action(PluginToRuntimeAction.GET_KNOWLEDEGE_FILE_STREAM)
573573
async def get_knowledge_file_stream(data: dict[str, Any]) -> handler.ActionResponse:
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from unittest.mock import AsyncMock, MagicMock
2+
3+
4+
def test_runtime_handler_allows_missing_vector_list_action_for_older_plugin_sdk():
5+
from langbot_plugin.entities.io.actions.enums import PluginToRuntimeAction
6+
from src.langbot.pkg.plugin.handler import RuntimeConnectionHandler
7+
8+
assert not hasattr(PluginToRuntimeAction, 'VECTOR_LIST')
9+
10+
mock_connection = MagicMock()
11+
mock_app = MagicMock()
12+
mock_app.logger = MagicMock()
13+
14+
handler = RuntimeConnectionHandler(
15+
connection=mock_connection,
16+
disconnect_callback=AsyncMock(return_value=False),
17+
ap=mock_app,
18+
)
19+
20+
assert handler is not None

0 commit comments

Comments
 (0)