mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
feat(cli_api): implement CLI API for external sandbox interactions, including session management and request handling
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
from .inner_api import InnerApiSession, InnerApiSessionManager
|
||||
from .cli_api import CliApiSession, CliApiSessionManager
|
||||
from .session import BaseSession, RedisSessionStorage, SessionManager, SessionStorage
|
||||
|
||||
__all__ = [
|
||||
"BaseSession",
|
||||
"InnerApiSession",
|
||||
"InnerApiSessionManager",
|
||||
"CliApiSession",
|
||||
"CliApiSessionManager",
|
||||
"RedisSessionStorage",
|
||||
"SessionManager",
|
||||
"SessionStorage",
|
||||
|
||||
21
api/core/session/cli_api.py
Normal file
21
api/core/session/cli_api.py
Normal file
@ -0,0 +1,21 @@
|
||||
import secrets
|
||||
from typing import Any
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from .session import BaseSession, SessionManager
|
||||
|
||||
|
||||
class CliApiSession(BaseSession):
|
||||
secret: str = Field(default_factory=lambda: secrets.token_urlsafe(32))
|
||||
secret: str = Field(default_factory=lambda: secrets.token_urlsafe(32))
|
||||
|
||||
|
||||
class CliApiSessionManager(SessionManager[CliApiSession]):
|
||||
def __init__(self, ttl: int | None = None):
|
||||
super().__init__(key_prefix="cli_api_session", session_class=CliApiSession, ttl=ttl)
|
||||
|
||||
def create(self, tenant_id: str, user_id: str, context: dict[str, Any] | None = None) -> CliApiSession:
|
||||
session = CliApiSession(tenant_id=tenant_id, user_id=user_id, context=context or {})
|
||||
self.save(session)
|
||||
return session
|
||||
@ -1,19 +0,0 @@
|
||||
from typing import Any
|
||||
|
||||
from .session import BaseSession, SessionManager
|
||||
|
||||
|
||||
class InnerApiSession(BaseSession):
|
||||
"""Inner API Session"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class InnerApiSessionManager(SessionManager[InnerApiSession]):
|
||||
def __init__(self, ttl: int | None = None):
|
||||
super().__init__(key_prefix="inner_api_session", session_class=InnerApiSession, ttl=ttl)
|
||||
|
||||
def create(self, tenant_id: str, user_id: str, context: dict[str, Any] | None = None) -> InnerApiSession:
|
||||
session = InnerApiSession(tenant_id=tenant_id, user_id=user_id, context=context or {})
|
||||
self.save(session)
|
||||
return session
|
||||
Reference in New Issue
Block a user