2024-07-22 15:29:39 +08:00
|
|
|
from contextvars import ContextVar
|
2025-02-17 17:05:13 +08:00
|
|
|
from threading import Lock
|
2024-10-21 10:43:49 +08:00
|
|
|
from typing import TYPE_CHECKING
|
2024-07-22 15:29:39 +08:00
|
|
|
|
2025-02-25 12:20:47 +08:00
|
|
|
from contexts.wrapper import RecyclableContextVar
|
|
|
|
|
|
2024-10-21 10:43:49 +08:00
|
|
|
if TYPE_CHECKING:
|
2025-09-18 12:49:10 +08:00
|
|
|
from core.datasource.__base.datasource_provider import DatasourcePluginProviderController
|
2025-03-04 18:02:06 +08:00
|
|
|
from core.model_runtime.entities.model_entities import AIModelEntity
|
2025-02-17 17:05:13 +08:00
|
|
|
from core.plugin.entities.plugin_daemon import PluginModelProviderEntity
|
|
|
|
|
from core.tools.plugin_tool.provider import PluginToolProviderController
|
2025-11-12 17:59:37 +08:00
|
|
|
from core.trigger.provider import PluginTriggerProviderController
|
2024-08-15 10:53:05 +08:00
|
|
|
|
2025-02-17 17:05:13 +08:00
|
|
|
|
2025-02-25 12:20:47 +08:00
|
|
|
"""
|
|
|
|
|
To avoid race-conditions caused by gunicorn thread recycling, using RecyclableContextVar to replace with
|
|
|
|
|
"""
|
|
|
|
|
plugin_tool_providers: RecyclableContextVar[dict[str, "PluginToolProviderController"]] = RecyclableContextVar(
|
|
|
|
|
ContextVar("plugin_tool_providers")
|
|
|
|
|
)
|
2025-03-04 18:02:06 +08:00
|
|
|
|
2025-02-25 12:20:47 +08:00
|
|
|
plugin_tool_providers_lock: RecyclableContextVar[Lock] = RecyclableContextVar(ContextVar("plugin_tool_providers_lock"))
|
2025-02-17 17:05:13 +08:00
|
|
|
|
2025-02-25 12:20:47 +08:00
|
|
|
plugin_model_providers: RecyclableContextVar[list["PluginModelProviderEntity"] | None] = RecyclableContextVar(
|
|
|
|
|
ContextVar("plugin_model_providers")
|
|
|
|
|
)
|
2025-03-04 18:02:06 +08:00
|
|
|
|
2025-02-25 12:20:47 +08:00
|
|
|
plugin_model_providers_lock: RecyclableContextVar[Lock] = RecyclableContextVar(
|
|
|
|
|
ContextVar("plugin_model_providers_lock")
|
|
|
|
|
)
|
2025-03-04 18:02:06 +08:00
|
|
|
|
|
|
|
|
plugin_model_schema_lock: RecyclableContextVar[Lock] = RecyclableContextVar(ContextVar("plugin_model_schema_lock"))
|
|
|
|
|
|
|
|
|
|
plugin_model_schemas: RecyclableContextVar[dict[str, "AIModelEntity"]] = RecyclableContextVar(
|
|
|
|
|
ContextVar("plugin_model_schemas")
|
|
|
|
|
)
|
2025-09-18 12:49:10 +08:00
|
|
|
|
|
|
|
|
datasource_plugin_providers: RecyclableContextVar[dict[str, "DatasourcePluginProviderController"]] = (
|
|
|
|
|
RecyclableContextVar(ContextVar("datasource_plugin_providers"))
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
datasource_plugin_providers_lock: RecyclableContextVar[Lock] = RecyclableContextVar(
|
|
|
|
|
ContextVar("datasource_plugin_providers_lock")
|
|
|
|
|
)
|
2025-11-12 17:59:37 +08:00
|
|
|
|
|
|
|
|
plugin_trigger_providers: RecyclableContextVar[dict[str, "PluginTriggerProviderController"]] = RecyclableContextVar(
|
|
|
|
|
ContextVar("plugin_trigger_providers")
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
plugin_trigger_providers_lock: RecyclableContextVar[Lock] = RecyclableContextVar(
|
|
|
|
|
ContextVar("plugin_trigger_providers_lock")
|
|
|
|
|
)
|