File size: 3,232 Bytes
bbfbcdd
 
2c8368f
 
bbfbcdd
2c8368f
 
bbfbcdd
2c8368f
 
 
 
 
 
 
 
 
 
bbfbcdd
2c8368f
 
 
 
 
 
 
 
bbfbcdd
2c8368f
 
 
 
a98a368
2c8368f
 
 
 
 
 
 
 
 
bbfbcdd
a98a368
2c8368f
bbfbcdd
2c8368f
a98a368
2c8368f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bbfbcdd
2c8368f
 
 
 
 
 
bbfbcdd
2c8368f
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
from __future__ import annotations

from typing import Any, Optional, List
from datetime import datetime, timezone
from pydantic import BaseModel, Field, ConfigDict


# ---------- CloudEvent (Pydantic v2 model) ----------
class CloudEvent(BaseModel):
    specversion: str = "1.0"
    id: str
    type: str
    source: str
    time: datetime
    datacontenttype: str = "application/json"
    data: Optional[Any] = None

    @staticmethod
    def now_utc() -> datetime:
        return datetime.now(timezone.utc)

    @classmethod
    def wrap(cls, *, event_id: str, event_type: str, source: str, data: Any) -> "CloudEvent":
        return cls(
            id=event_id,
            type=event_type or ("NullOrEmpty" if data is None else type(data).__name__),
            source=source,
            time=cls.now_utc(),
            data=data,
        )


# ---------- Permissive ancillary types ----------
class FunctionState(BaseModel):
    IsFunctionCall: bool = False
    IsFunctionCallResponse: bool = False
    IsFunctionCallError: bool = False
    IsFunctionCallStatus: bool = False
    IsFunctionStillRunning: bool = False


class FunctionCallData(BaseModel):
    # Accept arbitrary keys so we mirror your .NET payloads without schema fights
    model_config = ConfigDict(extra="allow")


class UserInfo(BaseModel):
    model_config = ConfigDict(extra="allow")


# ---------- LLMServiceObj (field names match C# exactly) ----------
class LLMServiceObj(BaseModel):
    # strings
    SessionId: str = ""
    JsonFunction: str = ""
    LlmMessage: str = ""
    ResultMessage: str = ""
    UserInput: str = ""
    RequestSessionId: str = ""
    FunctionName: str = ""
    TimeZone: str = ""
    LLMRunnerType: str = "TurboLLM"
    SourceLlm: str = ""
    DestinationLlm: str = ""
    MessageID: str = ""
    LlmSessionStartName: str = ""
    SwapFunctionName: str = ""
    ChatAgentLocation: str = ""
    ToolsDefinitionId: Optional[str] = None
    JsonToolsBuilderSpec: Optional[str] = None

    # ints / bools
    TokensUsed: int = 0
    IsUserLoggedIn: bool = False
    IsFuncAck: bool = False
    IsProcessed: bool = False
    IsSystemLlm: bool = False
    Timeout: Optional[int] = None

    # complex
    FunctionCallId: str = ""
    FunctionCallData: FunctionCallData = Field(default_factory=FunctionCallData)
    UserInfo: UserInfo = Field(default_factory=UserInfo)
    StartTimeUTC: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))

    # stacks (arrays; C# Stack<T> will deserialize fine)
    LlmStack: List[str] = Field(default_factory=list)
    FunctionCallIdStack: List[str] = Field(default_factory=list)
    FunctionNameStack: List[str] = Field(default_factory=list)
    IsProcessedStack: List[bool] = Field(default_factory=list)
    MessageIDStack: List[str] = Field(default_factory=list)

    # function state flags (since your C# exposes these via methods/flags)
    IsFunctionCall: bool = False
    IsFunctionCallResponse: bool = False
    IsFunctionCallError: bool = False
    IsFunctionCallStatus: bool = False
    IsFunctionStillRunning: bool = False


# ---------- ResultObj ----------
class ResultObj(BaseModel):
    Message: str = ""
    Success: bool = False
    Data: Optional[Any] = None