mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-14 08:26:07 +00:00
feat: preliminary migration of events entities
This commit is contained in:
@@ -11,11 +11,12 @@ from ..entity.persistence import pipeline as persistence_pipeline
|
|||||||
from . import stage
|
from . import stage
|
||||||
import langbot_plugin.api.entities.builtin.platform.message as platform_message
|
import langbot_plugin.api.entities.builtin.platform.message as platform_message
|
||||||
import langbot_plugin.api.entities.builtin.platform.events as platform_events
|
import langbot_plugin.api.entities.builtin.platform.events as platform_events
|
||||||
from ..plugin import events
|
import langbot_plugin.api.entities.events as events
|
||||||
from ..utils import importutil
|
from ..utils import importutil
|
||||||
|
|
||||||
import langbot_plugin.api.entities.builtin.provider.session as provider_session
|
import langbot_plugin.api.entities.builtin.provider.session as provider_session
|
||||||
import langbot_plugin.api.entities.builtin.pipeline.query as pipeline_query
|
import langbot_plugin.api.entities.builtin.pipeline.query as pipeline_query
|
||||||
|
import langbot_plugin.api.entities.context as event_context
|
||||||
|
|
||||||
from . import (
|
from . import (
|
||||||
resprule,
|
resprule,
|
||||||
@@ -183,16 +184,27 @@ class RuntimePipeline:
|
|||||||
else events.GroupMessageReceived
|
else events.GroupMessageReceived
|
||||||
)
|
)
|
||||||
|
|
||||||
event_ctx = await self.ap.plugin_mgr.emit_event(
|
print(query)
|
||||||
event=event_type(
|
print(query.model_dump(exclude_none=True))
|
||||||
launcher_type=query.launcher_type.value,
|
|
||||||
launcher_id=query.launcher_id,
|
event_obj = event_type(
|
||||||
sender_id=query.sender_id,
|
launcher_type=query.launcher_type.value,
|
||||||
message_chain=query.message_chain,
|
launcher_id=query.launcher_id,
|
||||||
query=query,
|
sender_id=query.sender_id,
|
||||||
)
|
message_chain=query.message_chain,
|
||||||
|
query=query,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
event_ctx = event_context.EventContext(
|
||||||
|
event=event_obj,
|
||||||
|
)
|
||||||
|
|
||||||
|
event_ctx_result = await self.ap.plugin_connector.handler.emit_event(
|
||||||
|
event_ctx.model_dump(exclude_none=True)
|
||||||
|
)
|
||||||
|
|
||||||
|
event_ctx.update(**event_ctx_result)
|
||||||
|
|
||||||
if event_ctx.is_prevented_default():
|
if event_ctx.is_prevented_default():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
+1
-104
@@ -3,10 +3,10 @@ from __future__ import annotations
|
|||||||
import typing
|
import typing
|
||||||
import abc
|
import abc
|
||||||
|
|
||||||
from . import events
|
|
||||||
from ..core import app
|
from ..core import app
|
||||||
import langbot_plugin.api.entities.builtin.platform.message as platform_message
|
import langbot_plugin.api.entities.builtin.platform.message as platform_message
|
||||||
import langbot_plugin.api.definition.abstract.platform.adapter as abstract_platform_adapter
|
import langbot_plugin.api.definition.abstract.platform.adapter as abstract_platform_adapter
|
||||||
|
import langbot_plugin.api.entities.events as events
|
||||||
|
|
||||||
|
|
||||||
def register(
|
def register(
|
||||||
@@ -279,106 +279,3 @@ class EventContext:
|
|||||||
self.__prevent_postorder__ = False
|
self.__prevent_postorder__ = False
|
||||||
self.__return_value__ = {}
|
self.__return_value__ = {}
|
||||||
EventContext.eid += 1
|
EventContext.eid += 1
|
||||||
|
|
||||||
|
|
||||||
# class RuntimeContainerStatus(enum.Enum):
|
|
||||||
# """插件容器状态"""
|
|
||||||
|
|
||||||
# MOUNTED = 'mounted'
|
|
||||||
# """已加载进内存,所有位于运行时记录中的 RuntimeContainer 至少是这个状态"""
|
|
||||||
|
|
||||||
# INITIALIZED = 'initialized'
|
|
||||||
# """已初始化"""
|
|
||||||
|
|
||||||
|
|
||||||
# class RuntimeContainer(pydantic.BaseModel):
|
|
||||||
# """运行时的插件容器
|
|
||||||
|
|
||||||
# 运行期间存储单个插件的信息
|
|
||||||
# """
|
|
||||||
|
|
||||||
# plugin_name: str
|
|
||||||
# """插件名称"""
|
|
||||||
|
|
||||||
# plugin_label: discover_engine.I18nString
|
|
||||||
# """插件标签"""
|
|
||||||
|
|
||||||
# plugin_description: discover_engine.I18nString
|
|
||||||
# """插件描述"""
|
|
||||||
|
|
||||||
# plugin_version: str
|
|
||||||
# """插件版本"""
|
|
||||||
|
|
||||||
# plugin_author: str
|
|
||||||
# """插件作者"""
|
|
||||||
|
|
||||||
# plugin_repository: str
|
|
||||||
# """插件源码地址"""
|
|
||||||
|
|
||||||
# main_file: str
|
|
||||||
# """插件主文件路径"""
|
|
||||||
|
|
||||||
# pkg_path: str
|
|
||||||
# """插件包路径"""
|
|
||||||
|
|
||||||
# plugin_class: typing.Type[BasePlugin] = None
|
|
||||||
# """插件类"""
|
|
||||||
|
|
||||||
# enabled: typing.Optional[bool] = True
|
|
||||||
# """是否启用"""
|
|
||||||
|
|
||||||
# priority: typing.Optional[int] = 0
|
|
||||||
# """优先级"""
|
|
||||||
|
|
||||||
# config_schema: typing.Optional[list[dict]] = []
|
|
||||||
# """插件配置模板"""
|
|
||||||
|
|
||||||
# plugin_config: typing.Optional[dict] = {}
|
|
||||||
# """插件配置"""
|
|
||||||
|
|
||||||
# plugin_inst: typing.Optional[BasePlugin] = None
|
|
||||||
# """插件实例"""
|
|
||||||
|
|
||||||
# event_handlers: dict[
|
|
||||||
# typing.Type[events.BaseEventModel],
|
|
||||||
# typing.Callable[[BasePlugin, EventContext], typing.Awaitable[None]],
|
|
||||||
# ] = {}
|
|
||||||
# """事件处理器"""
|
|
||||||
|
|
||||||
# tools: list[tools_entities.LLMFunction] = []
|
|
||||||
# """内容函数"""
|
|
||||||
|
|
||||||
# status: RuntimeContainerStatus = RuntimeContainerStatus.MOUNTED
|
|
||||||
# """插件状态"""
|
|
||||||
|
|
||||||
# class Config:
|
|
||||||
# arbitrary_types_allowed = True
|
|
||||||
|
|
||||||
# def model_dump(self, *args, **kwargs):
|
|
||||||
# return {
|
|
||||||
# 'name': self.plugin_name,
|
|
||||||
# 'label': self.plugin_label.to_dict(),
|
|
||||||
# 'description': self.plugin_description.to_dict(),
|
|
||||||
# 'version': self.plugin_version,
|
|
||||||
# 'author': self.plugin_author,
|
|
||||||
# 'repository': self.plugin_repository,
|
|
||||||
# 'main_file': self.main_file,
|
|
||||||
# 'pkg_path': self.pkg_path,
|
|
||||||
# 'enabled': self.enabled,
|
|
||||||
# 'priority': self.priority,
|
|
||||||
# 'config_schema': self.config_schema,
|
|
||||||
# 'event_handlers': {
|
|
||||||
# event_name.__name__: handler.__name__ for event_name, handler in self.event_handlers.items()
|
|
||||||
# },
|
|
||||||
# 'tools': [
|
|
||||||
# {
|
|
||||||
# 'name': function.name,
|
|
||||||
# 'human_desc': function.human_desc,
|
|
||||||
# 'description': function.description,
|
|
||||||
# 'parameters': function.parameters,
|
|
||||||
# 'func': function.func.__name__,
|
|
||||||
# }
|
|
||||||
# for function in self.tools
|
|
||||||
# ],
|
|
||||||
# 'status': self.status.value,
|
|
||||||
# }
|
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ import pkgutil
|
|||||||
import importlib
|
import importlib
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from .. import loader, events, context, models
|
from .. import loader, context, models
|
||||||
from langbot_plugin.api.entities.builtin.resource import tool as resource_tool
|
from langbot_plugin.api.entities.builtin.resource import tool as resource_tool
|
||||||
from ...utils import funcschema
|
from ...utils import funcschema
|
||||||
from ...discover import engine as discover_engine
|
from ...discover import engine as discover_engine
|
||||||
import langbot_plugin.api.entities.builtin.pipeline.query as pipeline_query
|
import langbot_plugin.api.entities.builtin.pipeline.query as pipeline_query
|
||||||
|
import langbot_plugin.api.entities.events as events
|
||||||
|
|
||||||
|
|
||||||
class PluginLoader(loader.PluginLoader):
|
class PluginLoader(loader.PluginLoader):
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ import os
|
|||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from ...core import app
|
from ...core import app
|
||||||
from .. import context, events
|
from .. import context
|
||||||
from .. import loader
|
from .. import loader
|
||||||
from ...utils import funcschema
|
from ...utils import funcschema
|
||||||
import langbot_plugin.api.entities.builtin.resource.tool as resource_tool
|
import langbot_plugin.api.entities.builtin.resource.tool as resource_tool
|
||||||
|
import langbot_plugin.api.entities.events as events
|
||||||
|
|
||||||
|
|
||||||
class PluginManifestLoader(loader.PluginLoader):
|
class PluginManifestLoader(loader.PluginLoader):
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import typing
|
|||||||
|
|
||||||
from .context import BasePlugin as Plugin
|
from .context import BasePlugin as Plugin
|
||||||
from .events import *
|
from .events import *
|
||||||
|
import langbot_plugin.api.entities.events as events
|
||||||
|
|
||||||
|
|
||||||
def register(
|
def register(
|
||||||
@@ -17,7 +18,7 @@ def register(
|
|||||||
|
|
||||||
|
|
||||||
def on(
|
def on(
|
||||||
event: typing.Type[BaseEventModel],
|
event: typing.Type[events.BaseEventModel],
|
||||||
) -> typing.Callable[[typing.Callable], typing.Callable]:
|
) -> typing.Callable[[typing.Callable], typing.Callable]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user