letschatty 0.4.280__py3-none-any.whl → 0.4.343__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- letschatty/models/ai_microservices/__init__.py +3 -3
- letschatty/models/ai_microservices/expected_output.py +35 -1
- letschatty/models/ai_microservices/lambda_events.py +85 -45
- letschatty/models/ai_microservices/lambda_invokation_types.py +6 -3
- letschatty/models/analytics/events/__init__.py +2 -3
- letschatty/models/analytics/events/chat_based_events/chat_funnel.py +69 -13
- letschatty/models/analytics/events/company_based_events/asset_events.py +9 -2
- letschatty/models/analytics/events/event_type_to_classes.py +6 -3
- letschatty/models/analytics/events/event_types.py +13 -50
- letschatty/models/chat/chat.py +14 -2
- letschatty/models/chat/chat_with_assets.py +6 -1
- letschatty/models/chat/client.py +0 -2
- letschatty/models/chat/continuous_conversation.py +1 -1
- letschatty/models/company/CRM/funnel.py +365 -33
- letschatty/models/company/__init__.py +3 -1
- letschatty/models/company/assets/ai_agents_v2/ai_agent_message_draft.py +58 -0
- letschatty/models/company/assets/ai_agents_v2/ai_agents_decision_output.py +1 -1
- letschatty/models/company/assets/ai_agents_v2/chain_of_thought_in_chat.py +5 -3
- letschatty/models/company/assets/ai_agents_v2/chatty_ai_agent.py +46 -2
- letschatty/models/company/assets/ai_agents_v2/chatty_ai_agent_in_chat.py +93 -1
- letschatty/models/company/assets/ai_agents_v2/pre_qualify_config.py +111 -0
- letschatty/models/company/assets/ai_agents_v2/statuses.py +33 -0
- letschatty/models/company/assets/assignment/__init__.py +14 -0
- letschatty/models/company/assets/assignment/assignment_assets.py +75 -0
- letschatty/models/company/assets/automation.py +10 -19
- letschatty/models/company/assets/chat_assets.py +12 -2
- letschatty/models/company/assets/company_assets.py +3 -0
- letschatty/models/company/assets/launch/__init__.py +12 -0
- letschatty/models/company/assets/launch/launch.py +128 -0
- letschatty/models/company/assets/launch/scheduled_communication.py +44 -0
- letschatty/models/company/assets/launch/subscription.py +63 -0
- letschatty/models/company/assets/sale.py +3 -3
- letschatty/models/company/assets/users/user.py +5 -1
- letschatty/models/company/company_messaging_settgins.py +2 -1
- letschatty/models/company/form_field.py +182 -12
- letschatty/models/data_base/collection_interface.py +29 -101
- letschatty/models/data_base/mongo_connection.py +9 -92
- letschatty/models/messages/chatty_messages/schema/chatty_content/content_document.py +4 -2
- letschatty/models/messages/chatty_messages/schema/chatty_content/content_media.py +4 -3
- letschatty/models/utils/custom_exceptions/custom_exceptions.py +24 -13
- letschatty/services/ai_agents/smart_follow_up_service_v2.py +10 -0
- letschatty/services/chat/chat_service.py +79 -14
- letschatty/services/chatty_assets/__init__.py +0 -12
- letschatty/services/chatty_assets/asset_service.py +13 -190
- letschatty/services/chatty_assets/base_container.py +2 -3
- letschatty/services/chatty_assets/base_container_with_collection.py +26 -35
- letschatty/services/continuous_conversation_service/continuous_conversation_helper.py +0 -11
- letschatty/services/events/events_manager.py +1 -218
- letschatty/services/factories/analytics/events_factory.py +6 -66
- letschatty/services/factories/lambda_ai_orchestrartor/lambda_events_factory.py +8 -23
- letschatty/services/users/user_factory.py +14 -8
- letschatty/services/validators/analytics_validator.py +11 -0
- {letschatty-0.4.280.dist-info → letschatty-0.4.343.dist-info}/METADATA +1 -1
- {letschatty-0.4.280.dist-info → letschatty-0.4.343.dist-info}/RECORD +56 -83
- {letschatty-0.4.280.dist-info → letschatty-0.4.343.dist-info}/WHEEL +1 -1
- letschatty/models/analytics/events/chat_based_events/ai_agent_execution_event.py +0 -71
- letschatty/services/chatty_assets/assets_collections.py +0 -137
- letschatty/services/chatty_assets/collections/__init__.py +0 -38
- letschatty/services/chatty_assets/collections/ai_agent_collection.py +0 -19
- letschatty/services/chatty_assets/collections/ai_agent_in_chat_collection.py +0 -32
- letschatty/services/chatty_assets/collections/ai_component_collection.py +0 -21
- letschatty/services/chatty_assets/collections/chain_of_thought_collection.py +0 -30
- letschatty/services/chatty_assets/collections/chat_collection.py +0 -21
- letschatty/services/chatty_assets/collections/contact_point_collection.py +0 -21
- letschatty/services/chatty_assets/collections/fast_answer_collection.py +0 -21
- letschatty/services/chatty_assets/collections/filter_criteria_collection.py +0 -18
- letschatty/services/chatty_assets/collections/flow_collection.py +0 -20
- letschatty/services/chatty_assets/collections/product_collection.py +0 -20
- letschatty/services/chatty_assets/collections/sale_collection.py +0 -20
- letschatty/services/chatty_assets/collections/source_collection.py +0 -21
- letschatty/services/chatty_assets/collections/tag_collection.py +0 -19
- letschatty/services/chatty_assets/collections/topic_collection.py +0 -21
- letschatty/services/chatty_assets/collections/user_collection.py +0 -20
- letschatty/services/chatty_assets/example_usage.py +0 -44
- letschatty/services/chatty_assets/services/__init__.py +0 -37
- letschatty/services/chatty_assets/services/ai_agent_in_chat_service.py +0 -73
- letschatty/services/chatty_assets/services/ai_agent_service.py +0 -23
- letschatty/services/chatty_assets/services/chain_of_thought_service.py +0 -70
- letschatty/services/chatty_assets/services/chat_service.py +0 -25
- letschatty/services/chatty_assets/services/contact_point_service.py +0 -29
- letschatty/services/chatty_assets/services/fast_answer_service.py +0 -32
- letschatty/services/chatty_assets/services/filter_criteria_service.py +0 -30
- letschatty/services/chatty_assets/services/flow_service.py +0 -25
- letschatty/services/chatty_assets/services/product_service.py +0 -30
- letschatty/services/chatty_assets/services/sale_service.py +0 -25
- letschatty/services/chatty_assets/services/source_service.py +0 -28
- letschatty/services/chatty_assets/services/tag_service.py +0 -32
- letschatty/services/chatty_assets/services/topic_service.py +0 -31
- letschatty/services/chatty_assets/services/user_service.py +0 -32
- letschatty/services/events/__init__.py +0 -6
- letschatty/services/factories/analytics/ai_agent_event_factory.py +0 -161
- {letschatty-0.4.280.dist-info → letschatty-0.4.343.dist-info}/LICENSE +0 -0
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"""AI Agent In Chat Service - Pre-configured AssetService for CRUD operations only"""
|
|
2
|
-
|
|
3
|
-
from datetime import datetime
|
|
4
|
-
from zoneinfo import ZoneInfo
|
|
5
|
-
from typing import Optional
|
|
6
|
-
from ..asset_service import AssetService, CacheConfig
|
|
7
|
-
from ..collections.ai_agent_in_chat_collection import AIAgentInChatCollection
|
|
8
|
-
from ....models.company.assets.ai_agents_v2.chatty_ai_agent_in_chat import ChattyAIAgentInChat
|
|
9
|
-
from ....models.data_base.mongo_connection import MongoConnection
|
|
10
|
-
from ....models.utils.types.identifier import StrObjectId
|
|
11
|
-
import logging
|
|
12
|
-
|
|
13
|
-
logger = logging.getLogger(__name__)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class AIAgentInChatService(AssetService[ChattyAIAgentInChat, ChattyAIAgentInChat]):
|
|
17
|
-
"""
|
|
18
|
-
Pre-configured service for AI Agent In Chat CRUD operations.
|
|
19
|
-
|
|
20
|
-
For business logic operations (set_to_processing, escalate, etc.),
|
|
21
|
-
use AIAgentInChatEditor instead.
|
|
22
|
-
|
|
23
|
-
No events needed - this is operational state, not a business asset.
|
|
24
|
-
"""
|
|
25
|
-
|
|
26
|
-
def __init__(
|
|
27
|
-
self,
|
|
28
|
-
connection: MongoConnection,
|
|
29
|
-
cache_config: CacheConfig = CacheConfig(
|
|
30
|
-
keep_items_always_in_memory=False,
|
|
31
|
-
keep_previews_always_in_memory=False
|
|
32
|
-
)
|
|
33
|
-
):
|
|
34
|
-
collection = AIAgentInChatCollection(connection)
|
|
35
|
-
super().__init__(
|
|
36
|
-
collection=collection,
|
|
37
|
-
cache_config=cache_config
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
collection: AIAgentInChatCollection # Type annotation for better type checking
|
|
41
|
-
|
|
42
|
-
async def get_by_chat_id(self, chat_id: StrObjectId) -> Optional[ChattyAIAgentInChat]:
|
|
43
|
-
"""Get AI agent state for a chat"""
|
|
44
|
-
return await self.collection.get_by_chat_id(chat_id)
|
|
45
|
-
|
|
46
|
-
async def update(self, ai_agent_in_chat: ChattyAIAgentInChat) -> ChattyAIAgentInChat:
|
|
47
|
-
"""Update AI agent state"""
|
|
48
|
-
ai_agent_in_chat.updated_at = datetime.now(ZoneInfo("UTC"))
|
|
49
|
-
ai_agent_dict = ai_agent_in_chat.model_dump(by_alias=True, exclude_none=False)
|
|
50
|
-
# Remove _id field as it's immutable in MongoDB
|
|
51
|
-
ai_agent_dict.pop('_id', None)
|
|
52
|
-
result = await self.collection.async_collection.update_one(
|
|
53
|
-
{"chat_id": ai_agent_in_chat.chat_id},
|
|
54
|
-
{"$set": ai_agent_dict}
|
|
55
|
-
)
|
|
56
|
-
if result.matched_count == 0:
|
|
57
|
-
raise ValueError(f"AI agent state for chat {ai_agent_in_chat.chat_id} not found")
|
|
58
|
-
return ai_agent_in_chat
|
|
59
|
-
|
|
60
|
-
async def create(self, ai_agent_in_chat: ChattyAIAgentInChat) -> ChattyAIAgentInChat:
|
|
61
|
-
"""Create new AI agent state"""
|
|
62
|
-
ai_agent_dict = ai_agent_in_chat.model_dump(by_alias=True, exclude_none=False)
|
|
63
|
-
result = await self.collection.async_collection.insert_one(ai_agent_dict)
|
|
64
|
-
if not result.inserted_id:
|
|
65
|
-
raise Exception(f"Failed to create AI agent state for chat {ai_agent_in_chat.chat_id}")
|
|
66
|
-
return ai_agent_in_chat
|
|
67
|
-
|
|
68
|
-
async def delete(self, chat_id: StrObjectId) -> None:
|
|
69
|
-
"""Delete AI agent state"""
|
|
70
|
-
result = await self.collection.async_collection.update_one({"chat_id": chat_id}, {"$set": {"deleted_at": datetime.now(ZoneInfo("UTC"))}})
|
|
71
|
-
if result.matched_count == 0:
|
|
72
|
-
raise ValueError(f"AI agent state for chat {chat_id} not found")
|
|
73
|
-
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"""AI Agent Service - Pre-configured AssetService for AI Agents"""
|
|
2
|
-
|
|
3
|
-
from ..asset_service import AssetService, CacheConfig
|
|
4
|
-
from ..collections import AiAgentCollection
|
|
5
|
-
from ....models.company.assets.ai_agents_v2.chatty_ai_agent import ChattyAIAgent, ChattyAIAgentPreview
|
|
6
|
-
from ....models.data_base.mongo_connection import MongoConnection
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class AiAgentService(AssetService[ChattyAIAgent, ChattyAIAgentPreview]):
|
|
10
|
-
"""Pre-configured service for AI Agent assets with sensible defaults"""
|
|
11
|
-
|
|
12
|
-
def __init__(self,
|
|
13
|
-
connection: MongoConnection,
|
|
14
|
-
cache_config: CacheConfig = CacheConfig(
|
|
15
|
-
keep_items_always_in_memory=False,
|
|
16
|
-
keep_previews_always_in_memory=True
|
|
17
|
-
)):
|
|
18
|
-
collection = AiAgentCollection(connection)
|
|
19
|
-
super().__init__(
|
|
20
|
-
collection=collection,
|
|
21
|
-
cache_config=cache_config
|
|
22
|
-
)
|
|
23
|
-
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"""Chain Of Thought Service - Pre-configured AssetService for CRUD operations only"""
|
|
2
|
-
|
|
3
|
-
from datetime import datetime
|
|
4
|
-
from zoneinfo import ZoneInfo
|
|
5
|
-
from typing import List, Optional
|
|
6
|
-
from ..asset_service import AssetService, CacheConfig
|
|
7
|
-
from ..collections.chain_of_thought_collection import ChainOfThoughtCollection
|
|
8
|
-
from ....models.company.assets.ai_agents_v2.chain_of_thought_in_chat import ChainOfThoughtInChat
|
|
9
|
-
from ....models.data_base.mongo_connection import MongoConnection
|
|
10
|
-
from ....models.utils.types.identifier import StrObjectId
|
|
11
|
-
from ....models.utils.types.serializer_type import SerializerType
|
|
12
|
-
from bson import ObjectId
|
|
13
|
-
import logging
|
|
14
|
-
|
|
15
|
-
logger = logging.getLogger(__name__)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class ChainOfThoughtService(AssetService[ChainOfThoughtInChat, ChainOfThoughtInChat]):
|
|
19
|
-
"""
|
|
20
|
-
Pre-configured service for Chain Of Thought CRUD operations.
|
|
21
|
-
|
|
22
|
-
For business logic operations (create for N8N, set as failed, etc.),
|
|
23
|
-
use ChainOfThoughtsEditor instead.
|
|
24
|
-
|
|
25
|
-
No events needed - this is execution state, not a business asset.
|
|
26
|
-
"""
|
|
27
|
-
|
|
28
|
-
def __init__(
|
|
29
|
-
self,
|
|
30
|
-
connection: MongoConnection,
|
|
31
|
-
cache_config: CacheConfig = CacheConfig(
|
|
32
|
-
keep_items_always_in_memory=False,
|
|
33
|
-
keep_previews_always_in_memory=False
|
|
34
|
-
)
|
|
35
|
-
):
|
|
36
|
-
collection = ChainOfThoughtCollection(connection)
|
|
37
|
-
super().__init__(
|
|
38
|
-
collection=collection,
|
|
39
|
-
cache_config=cache_config
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
collection: ChainOfThoughtCollection # Type annotation for better type checking
|
|
43
|
-
|
|
44
|
-
async def get_by_chat_id(self, chat_id: StrObjectId, skip: int = 0, limit: int = 10) -> List[ChainOfThoughtInChat]:
|
|
45
|
-
"""Get chain of thoughts by chat ID, sorted by created_at (newest first)"""
|
|
46
|
-
return await self.collection.get_by_chat_id(chat_id=chat_id, skip=skip, limit=limit)
|
|
47
|
-
|
|
48
|
-
async def get_by_id(self, cot_id: StrObjectId) -> Optional[ChainOfThoughtInChat]:
|
|
49
|
-
"""Get chain of thought by ID"""
|
|
50
|
-
return await self.collection.get_by_id(cot_id)
|
|
51
|
-
|
|
52
|
-
async def create(self, cot: ChainOfThoughtInChat) -> ChainOfThoughtInChat:
|
|
53
|
-
"""Create new chain of thought"""
|
|
54
|
-
cot_dict = cot.model_dump(by_alias=True, exclude_none=False)
|
|
55
|
-
result = await self.collection.async_collection.insert_one(cot_dict)
|
|
56
|
-
if not result.inserted_id:
|
|
57
|
-
raise Exception(f"Failed to create chain of thought {cot.id}")
|
|
58
|
-
return cot
|
|
59
|
-
|
|
60
|
-
async def update(self, cot: ChainOfThoughtInChat) -> ChainOfThoughtInChat:
|
|
61
|
-
"""Update chain of thought"""
|
|
62
|
-
cot.updated_at = datetime.now(ZoneInfo("UTC"))
|
|
63
|
-
cot_dict = cot.model_dump(by_alias=True, exclude_none=False)
|
|
64
|
-
result = await self.collection.async_collection.update_one(
|
|
65
|
-
{"_id": cot.id},
|
|
66
|
-
{"$set": cot_dict}
|
|
67
|
-
)
|
|
68
|
-
if result.matched_count == 0:
|
|
69
|
-
raise ValueError(f"Chain of thought {cot.id} not found")
|
|
70
|
-
return cot
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"""Chat Service - Pre-configured AssetService for Chats"""
|
|
2
|
-
|
|
3
|
-
from ..asset_service import AssetService, CacheConfig
|
|
4
|
-
from ..collections import ChatCollection
|
|
5
|
-
from ....models.chat.chat import Chat
|
|
6
|
-
from ....models.base_models import ChattyAssetPreview
|
|
7
|
-
from ....models.data_base.mongo_connection import MongoConnection
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class ChatService(AssetService[Chat, ChattyAssetPreview]):
|
|
11
|
-
"""
|
|
12
|
-
Pre-configured service for Chat assets with sensible defaults.
|
|
13
|
-
|
|
14
|
-
Note: No event configuration - Chat events are handled by ChatsEditor, not AssetService.
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
|
-
def __init__(self,
|
|
18
|
-
connection: MongoConnection,
|
|
19
|
-
cache_config: CacheConfig = CacheConfig.default()):
|
|
20
|
-
collection = ChatCollection(connection)
|
|
21
|
-
super().__init__(
|
|
22
|
-
collection=collection,
|
|
23
|
-
cache_config=cache_config
|
|
24
|
-
)
|
|
25
|
-
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"""Contact Point Service - Pre-configured AssetService for Contact Points"""
|
|
2
|
-
|
|
3
|
-
from ..asset_service import AssetService, CacheConfig
|
|
4
|
-
from ..collections import ContactPointCollection
|
|
5
|
-
from ....models.company.assets.contact_point import ContactPoint
|
|
6
|
-
from ....models.base_models import ChattyAssetPreview
|
|
7
|
-
from ....models.data_base.mongo_connection import MongoConnection
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class ContactPointService(AssetService[ContactPoint, ChattyAssetPreview]):
|
|
11
|
-
"""
|
|
12
|
-
Pre-configured service for ContactPoint assets with sensible defaults.
|
|
13
|
-
|
|
14
|
-
Note: No event configuration - ContactPoint events are managed separately by the contact points system.
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
|
-
def __init__(self,
|
|
18
|
-
connection: MongoConnection,
|
|
19
|
-
cache_config: CacheConfig = CacheConfig(
|
|
20
|
-
keep_items_always_in_memory=False,
|
|
21
|
-
keep_previews_always_in_memory=False,
|
|
22
|
-
cache_expiration_time=0
|
|
23
|
-
)):
|
|
24
|
-
collection = ContactPointCollection(connection)
|
|
25
|
-
super().__init__(
|
|
26
|
-
collection=collection,
|
|
27
|
-
cache_config=cache_config
|
|
28
|
-
)
|
|
29
|
-
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"""Fast Answer Service - Pre-configured AssetService for Fast Answers"""
|
|
2
|
-
|
|
3
|
-
from ..asset_service import AssetService, CacheConfig
|
|
4
|
-
from ..collections.fast_answer_collection import FastAnswerCollection
|
|
5
|
-
from ....models.company.assets import ChattyFastAnswer
|
|
6
|
-
from ....models.base_models import ChattyAssetPreview
|
|
7
|
-
from ....models.data_base.mongo_connection import MongoConnection
|
|
8
|
-
from ....models.analytics.events import CompanyAssetType, EventType
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class FastAnswerService(AssetService[ChattyFastAnswer, ChattyAssetPreview]):
|
|
12
|
-
"""Pre-configured service for Fast Answer assets with sensible defaults"""
|
|
13
|
-
|
|
14
|
-
# Event configuration - enables automatic event handling in API
|
|
15
|
-
asset_type_enum = CompanyAssetType.FAST_ANSWERS
|
|
16
|
-
event_type_created = EventType.FAST_ANSWER_CREATED
|
|
17
|
-
event_type_updated = EventType.FAST_ANSWER_UPDATED
|
|
18
|
-
event_type_deleted = EventType.FAST_ANSWER_DELETED
|
|
19
|
-
|
|
20
|
-
def __init__(self,
|
|
21
|
-
connection: MongoConnection,
|
|
22
|
-
cache_config: CacheConfig = CacheConfig(
|
|
23
|
-
keep_items_always_in_memory=False,
|
|
24
|
-
cache_expiration_time=60*30, # 30 minutes
|
|
25
|
-
keep_previews_always_in_memory=True
|
|
26
|
-
)):
|
|
27
|
-
collection = FastAnswerCollection(connection)
|
|
28
|
-
super().__init__(
|
|
29
|
-
collection=collection,
|
|
30
|
-
cache_config=cache_config
|
|
31
|
-
)
|
|
32
|
-
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"""Filter Criteria Service - Pre-configured AssetService for Filter Criterias"""
|
|
2
|
-
|
|
3
|
-
from ..asset_service import AssetService, CacheConfig
|
|
4
|
-
from ..collections import FilterCriteriaCollection
|
|
5
|
-
from ....models.company.assets.filter_criteria import FilterCriteria, FilterCriteriaPreview
|
|
6
|
-
from ....models.data_base.mongo_connection import MongoConnection
|
|
7
|
-
from ....models.analytics.events import CompanyAssetType, EventType
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class FilterCriteriaService(AssetService[FilterCriteria, FilterCriteriaPreview]):
|
|
11
|
-
"""Pre-configured service for Filter Criteria assets with sensible defaults"""
|
|
12
|
-
|
|
13
|
-
# Event configuration - enables automatic event handling in API
|
|
14
|
-
asset_type_enum = CompanyAssetType.FILTER_CRITERIA
|
|
15
|
-
event_type_created = EventType.FILTER_CRITERIA_CREATED
|
|
16
|
-
event_type_updated = EventType.FILTER_CRITERIA_UPDATED
|
|
17
|
-
event_type_deleted = EventType.FILTER_CRITERIA_DELETED
|
|
18
|
-
|
|
19
|
-
def __init__(self,
|
|
20
|
-
connection: MongoConnection,
|
|
21
|
-
cache_config: CacheConfig = CacheConfig(
|
|
22
|
-
keep_items_always_in_memory=False,
|
|
23
|
-
keep_previews_always_in_memory=True
|
|
24
|
-
)):
|
|
25
|
-
collection = FilterCriteriaCollection(connection)
|
|
26
|
-
super().__init__(
|
|
27
|
-
collection=collection,
|
|
28
|
-
cache_config=cache_config
|
|
29
|
-
)
|
|
30
|
-
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"""Flow Service - Pre-configured AssetService for Flows"""
|
|
2
|
-
|
|
3
|
-
from ..asset_service import AssetService, CacheConfig
|
|
4
|
-
from ..collections import FlowCollection
|
|
5
|
-
from ....models.company.assets.flow import FlowPreview
|
|
6
|
-
from ....models.base_models import ChattyAssetPreview
|
|
7
|
-
from ....models.data_base.mongo_connection import MongoConnection
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class FlowService(AssetService[FlowPreview, ChattyAssetPreview]):
|
|
11
|
-
"""
|
|
12
|
-
Pre-configured service for Flow assets with sensible defaults.
|
|
13
|
-
|
|
14
|
-
Note: No event configuration - Flows are previews only, not full assets with CRUD events.
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
|
-
def __init__(self,
|
|
18
|
-
connection: MongoConnection,
|
|
19
|
-
cache_config: CacheConfig = CacheConfig(keep_items_always_in_memory=True)):
|
|
20
|
-
collection = FlowCollection(connection)
|
|
21
|
-
super().__init__(
|
|
22
|
-
collection=collection,
|
|
23
|
-
cache_config=cache_config
|
|
24
|
-
)
|
|
25
|
-
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"""Product Service - Pre-configured AssetService for Products"""
|
|
2
|
-
|
|
3
|
-
from ..asset_service import AssetService, CacheConfig
|
|
4
|
-
from ..collections import ProductCollection
|
|
5
|
-
from ....models.company.assets.product import Product, ProductPreview
|
|
6
|
-
from ....models.data_base.mongo_connection import MongoConnection
|
|
7
|
-
from ....models.analytics.events import CompanyAssetType, EventType
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class ProductService(AssetService[Product, ProductPreview]):
|
|
11
|
-
"""Pre-configured service for Product assets with sensible defaults"""
|
|
12
|
-
|
|
13
|
-
# Event configuration - enables automatic event handling in API
|
|
14
|
-
asset_type_enum = CompanyAssetType.PRODUCTS
|
|
15
|
-
event_type_created = EventType.PRODUCT_CREATED
|
|
16
|
-
event_type_updated = EventType.PRODUCT_UPDATED
|
|
17
|
-
event_type_deleted = EventType.PRODUCT_DELETED
|
|
18
|
-
|
|
19
|
-
def __init__(self,
|
|
20
|
-
connection: MongoConnection,
|
|
21
|
-
cache_config: CacheConfig = CacheConfig(
|
|
22
|
-
keep_items_always_in_memory=False,
|
|
23
|
-
keep_previews_always_in_memory=True
|
|
24
|
-
)):
|
|
25
|
-
collection = ProductCollection(connection)
|
|
26
|
-
super().__init__(
|
|
27
|
-
collection=collection,
|
|
28
|
-
cache_config=cache_config
|
|
29
|
-
)
|
|
30
|
-
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"""Sale Service - Pre-configured AssetService for Sales"""
|
|
2
|
-
|
|
3
|
-
from ..asset_service import AssetService, CacheConfig
|
|
4
|
-
from ..collections import SaleCollection
|
|
5
|
-
from ....models.company.assets.sale import Sale
|
|
6
|
-
from ....models.base_models import ChattyAssetPreview
|
|
7
|
-
from ....models.data_base.mongo_connection import MongoConnection
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class SaleService(AssetService[Sale, ChattyAssetPreview]):
|
|
11
|
-
"""
|
|
12
|
-
Pre-configured service for Sale assets with sensible defaults.
|
|
13
|
-
|
|
14
|
-
Note: No event configuration - Sale events are managed by the sales editor, not AssetService.
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
|
-
def __init__(self,
|
|
18
|
-
connection: MongoConnection,
|
|
19
|
-
cache_config: CacheConfig = CacheConfig.default()):
|
|
20
|
-
collection = SaleCollection(connection)
|
|
21
|
-
super().__init__(
|
|
22
|
-
collection=collection,
|
|
23
|
-
cache_config=cache_config
|
|
24
|
-
)
|
|
25
|
-
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"""Source Service - Pre-configured AssetService for Sources"""
|
|
2
|
-
|
|
3
|
-
from ..asset_service import AssetService, CacheConfig
|
|
4
|
-
from ..collections import SourceCollection
|
|
5
|
-
from ....models.analytics.sources import SourceBase
|
|
6
|
-
from ....models.base_models import ChattyAssetPreview
|
|
7
|
-
from ....models.data_base.mongo_connection import MongoConnection
|
|
8
|
-
from ....models.analytics.events import CompanyAssetType, EventType
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class SourceService(AssetService[SourceBase, ChattyAssetPreview]):
|
|
12
|
-
"""Pre-configured service for Source assets with sensible defaults"""
|
|
13
|
-
|
|
14
|
-
# Event configuration - enables automatic event handling in API
|
|
15
|
-
asset_type_enum = CompanyAssetType.SOURCES
|
|
16
|
-
event_type_created = EventType.SOURCE_CREATED
|
|
17
|
-
event_type_updated = EventType.SOURCE_UPDATED
|
|
18
|
-
event_type_deleted = EventType.SOURCE_DELETED
|
|
19
|
-
|
|
20
|
-
def __init__(self,
|
|
21
|
-
connection: MongoConnection,
|
|
22
|
-
cache_config: CacheConfig = CacheConfig(keep_items_always_in_memory=True)):
|
|
23
|
-
collection = SourceCollection(connection)
|
|
24
|
-
super().__init__(
|
|
25
|
-
collection=collection,
|
|
26
|
-
cache_config=cache_config
|
|
27
|
-
)
|
|
28
|
-
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"""Tag Service - Pre-configured AssetService for Tags"""
|
|
2
|
-
|
|
3
|
-
from ..asset_service import AssetService, CacheConfig
|
|
4
|
-
from ..collections import TagCollection
|
|
5
|
-
from ....models.company.assets.tag import Tag, TagPreview
|
|
6
|
-
from ....models.data_base.mongo_connection import MongoConnection
|
|
7
|
-
from ....models.analytics.events import CompanyAssetType, EventType
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class TagService(AssetService[Tag, TagPreview]):
|
|
11
|
-
"""Pre-configured service for Tag assets with sensible defaults"""
|
|
12
|
-
|
|
13
|
-
# Event configuration - enables automatic event handling in API
|
|
14
|
-
asset_type_enum = CompanyAssetType.TAGS
|
|
15
|
-
event_type_created = EventType.TAG_CREATED
|
|
16
|
-
event_type_updated = EventType.TAG_UPDATED
|
|
17
|
-
event_type_deleted = EventType.TAG_DELETED
|
|
18
|
-
|
|
19
|
-
def __init__(self,
|
|
20
|
-
connection: MongoConnection,
|
|
21
|
-
cache_config: CacheConfig = CacheConfig(
|
|
22
|
-
keep_items_always_in_memory=False,
|
|
23
|
-
keep_previews_always_in_memory=True
|
|
24
|
-
)):
|
|
25
|
-
collection = TagCollection(connection)
|
|
26
|
-
super().__init__(
|
|
27
|
-
collection=collection,
|
|
28
|
-
cache_config=cache_config
|
|
29
|
-
)
|
|
30
|
-
# Load all tags into memory by default
|
|
31
|
-
self.load_from_db(company_id=None)
|
|
32
|
-
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"""Topic Service - Pre-configured AssetService for Topics"""
|
|
2
|
-
|
|
3
|
-
from ..asset_service import AssetService, CacheConfig
|
|
4
|
-
from ..collections.topic_collection import TopicCollection
|
|
5
|
-
from ....models.analytics.smart_messages.topic import Topic
|
|
6
|
-
from ....models.base_models import ChattyAssetPreview
|
|
7
|
-
from ....models.data_base.mongo_connection import MongoConnection
|
|
8
|
-
from ....models.analytics.events import CompanyAssetType, EventType
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class TopicService(AssetService[Topic, ChattyAssetPreview]):
|
|
12
|
-
"""Pre-configured service for Topic assets with sensible defaults"""
|
|
13
|
-
|
|
14
|
-
# Event configuration - enables automatic event handling in API
|
|
15
|
-
asset_type_enum = CompanyAssetType.TOPICS
|
|
16
|
-
event_type_created = EventType.TOPIC_CREATED
|
|
17
|
-
event_type_updated = EventType.TOPIC_UPDATED
|
|
18
|
-
event_type_deleted = EventType.TOPIC_DELETED
|
|
19
|
-
|
|
20
|
-
def __init__(self,
|
|
21
|
-
connection: MongoConnection,
|
|
22
|
-
cache_config: CacheConfig = CacheConfig(
|
|
23
|
-
keep_items_always_in_memory=True,
|
|
24
|
-
keep_previews_always_in_memory=True
|
|
25
|
-
)):
|
|
26
|
-
collection = TopicCollection(connection)
|
|
27
|
-
super().__init__(
|
|
28
|
-
collection=collection,
|
|
29
|
-
cache_config=cache_config
|
|
30
|
-
)
|
|
31
|
-
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"""User Service - Pre-configured AssetService for Users"""
|
|
2
|
-
|
|
3
|
-
from ..asset_service import AssetService, CacheConfig
|
|
4
|
-
from ..collections import UserCollection
|
|
5
|
-
from ....models.company.assets.users.user import User, UserPreview
|
|
6
|
-
from ....models.data_base.mongo_connection import MongoConnection
|
|
7
|
-
from ....models.analytics.events import CompanyAssetType, EventType
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class UserService(AssetService[User, UserPreview]):
|
|
11
|
-
"""Pre-configured service for User assets with sensible defaults"""
|
|
12
|
-
|
|
13
|
-
# Event configuration - enables automatic event handling in API
|
|
14
|
-
asset_type_enum = CompanyAssetType.USERS
|
|
15
|
-
event_type_created = EventType.USER_CREATED
|
|
16
|
-
event_type_updated = EventType.USER_UPDATED
|
|
17
|
-
event_type_deleted = EventType.USER_DELETED
|
|
18
|
-
|
|
19
|
-
def __init__(self,
|
|
20
|
-
connection: MongoConnection,
|
|
21
|
-
cache_config: CacheConfig = CacheConfig(
|
|
22
|
-
keep_items_always_in_memory=False,
|
|
23
|
-
cache_expiration_time_previews=300,
|
|
24
|
-
keep_previews_always_in_memory=True,
|
|
25
|
-
keep_deleted_previews_in_memory=True
|
|
26
|
-
)):
|
|
27
|
-
collection = UserCollection(connection)
|
|
28
|
-
super().__init__(
|
|
29
|
-
collection=collection,
|
|
30
|
-
cache_config=cache_config
|
|
31
|
-
)
|
|
32
|
-
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
AI Agent Event Factory - Helper for creating AI agent execution events
|
|
3
|
-
|
|
4
|
-
This factory simplifies event creation by providing a consistent interface
|
|
5
|
-
for generating both full analytics events and simplified UI events.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
from letschatty.models.analytics.events.chat_based_events.ai_agent_execution_event import (
|
|
9
|
-
AIAgentExecutionEvent,
|
|
10
|
-
AIAgentExecutionEventData
|
|
11
|
-
)
|
|
12
|
-
from letschatty.models.analytics.events.event_types import EventType
|
|
13
|
-
from datetime import datetime
|
|
14
|
-
from zoneinfo import ZoneInfo
|
|
15
|
-
from typing import Optional, Dict, Any
|
|
16
|
-
from letschatty.models.utils.types.identifier import StrObjectId
|
|
17
|
-
import logging
|
|
18
|
-
|
|
19
|
-
logger = logging.getLogger(__name__)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class AIAgentEventFactory:
|
|
23
|
-
"""
|
|
24
|
-
Factory for creating AI agent execution events with proper context.
|
|
25
|
-
|
|
26
|
-
Provides a simplified API for event creation while ensuring all required
|
|
27
|
-
fields are properly populated for analytics and monitoring.
|
|
28
|
-
"""
|
|
29
|
-
|
|
30
|
-
@staticmethod
|
|
31
|
-
def create_event(
|
|
32
|
-
event_type: EventType,
|
|
33
|
-
chat_id: StrObjectId,
|
|
34
|
-
company_id: StrObjectId,
|
|
35
|
-
frozen_company_name: str,
|
|
36
|
-
ai_agent_id: StrObjectId,
|
|
37
|
-
chain_of_thought_id: StrObjectId,
|
|
38
|
-
trigger: str,
|
|
39
|
-
source: str = "chatty.api",
|
|
40
|
-
decision_type: Optional[str] = None,
|
|
41
|
-
error_message: Optional[str] = None,
|
|
42
|
-
duration_ms: Optional[int] = None,
|
|
43
|
-
user_rating: Optional[int] = None,
|
|
44
|
-
metadata: Optional[Dict[str, Any]] = None,
|
|
45
|
-
trace_id: Optional[str] = None
|
|
46
|
-
) -> AIAgentExecutionEvent:
|
|
47
|
-
"""
|
|
48
|
-
Create a full AI agent execution event for EventBridge.
|
|
49
|
-
|
|
50
|
-
Args:
|
|
51
|
-
event_type: The type of event (from EventType enum)
|
|
52
|
-
chat_id: ID of the chat where the event occurred
|
|
53
|
-
company_id: ID of the company
|
|
54
|
-
frozen_company_name: Company name snapshot for analytics
|
|
55
|
-
ai_agent_id: ID of the AI agent asset
|
|
56
|
-
chain_of_thought_id: ID of the chain of thought execution
|
|
57
|
-
trigger: What triggered the execution (USER_MESSAGE, FOLLOW_UP, etc.)
|
|
58
|
-
source: Event source (e.g., 'chatty.api', 'chatty.lambda')
|
|
59
|
-
decision_type: Type of decision if applicable (send, suggest, escalate, skip)
|
|
60
|
-
error_message: Error message if this is an error event
|
|
61
|
-
duration_ms: Duration of the operation in milliseconds
|
|
62
|
-
user_rating: User rating (1-5 stars) if applicable
|
|
63
|
-
metadata: Additional event-specific data
|
|
64
|
-
trace_id: Trace ID for tracking event flows across systems
|
|
65
|
-
|
|
66
|
-
Returns:
|
|
67
|
-
AIAgentExecutionEvent ready to be queued to EventBridge
|
|
68
|
-
"""
|
|
69
|
-
return AIAgentExecutionEvent(
|
|
70
|
-
type=event_type,
|
|
71
|
-
time=datetime.now(ZoneInfo("UTC")),
|
|
72
|
-
source=source,
|
|
73
|
-
company_id=company_id,
|
|
74
|
-
frozen_company_name=frozen_company_name,
|
|
75
|
-
specversion="1.0",
|
|
76
|
-
trace_id=trace_id,
|
|
77
|
-
data=AIAgentExecutionEventData(
|
|
78
|
-
chat_id=chat_id,
|
|
79
|
-
ai_agent_id=ai_agent_id,
|
|
80
|
-
chain_of_thought_id=chain_of_thought_id,
|
|
81
|
-
trigger=trigger,
|
|
82
|
-
decision_type=decision_type,
|
|
83
|
-
error_message=error_message,
|
|
84
|
-
duration_ms=duration_ms,
|
|
85
|
-
user_rating=user_rating,
|
|
86
|
-
metadata=metadata
|
|
87
|
-
)
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
@staticmethod
|
|
91
|
-
def get_simplified_event_type(event_type: EventType) -> str:
|
|
92
|
-
"""
|
|
93
|
-
Convert full EventType to simplified event type string for UI.
|
|
94
|
-
|
|
95
|
-
Transforms 'chatty_ai_agent_in_chat.trigger.user_message' -> 'trigger.user_message'
|
|
96
|
-
This provides a cleaner format for embedded events in COT documents.
|
|
97
|
-
|
|
98
|
-
Args:
|
|
99
|
-
event_type: Full EventType enum value
|
|
100
|
-
|
|
101
|
-
Returns:
|
|
102
|
-
Simplified event type string (e.g., 'trigger.user_message')
|
|
103
|
-
"""
|
|
104
|
-
# Extract the last two parts after 'chatty_ai_agent_in_chat.'
|
|
105
|
-
parts = event_type.value.split('.')
|
|
106
|
-
if len(parts) >= 3 and parts[0] == 'chatty_ai_agent_in_chat':
|
|
107
|
-
return '.'.join(parts[1:]) # e.g., 'trigger.user_message'
|
|
108
|
-
return event_type.value # Fallback to full type if format doesn't match
|
|
109
|
-
|
|
110
|
-
@staticmethod
|
|
111
|
-
def get_user_friendly_message(event_type: EventType, **context) -> str:
|
|
112
|
-
"""
|
|
113
|
-
Generate a user-friendly message for an event type.
|
|
114
|
-
|
|
115
|
-
This provides human-readable descriptions for events that will be
|
|
116
|
-
displayed in the UI as part of the chain of thought timeline.
|
|
117
|
-
|
|
118
|
-
Args:
|
|
119
|
-
event_type: The type of event
|
|
120
|
-
**context: Additional context for message formatting (e.g., decision_type, error_message)
|
|
121
|
-
|
|
122
|
-
Returns:
|
|
123
|
-
User-friendly message string
|
|
124
|
-
"""
|
|
125
|
-
messages = {
|
|
126
|
-
EventType.CHATTY_AI_AGENT_IN_CHAT_TRIGGER_USER_MESSAGE: "Triggered by user message",
|
|
127
|
-
EventType.CHATTY_AI_AGENT_IN_CHAT_TRIGGER_FOLLOW_UP: "Triggered by smart follow-up",
|
|
128
|
-
EventType.CHATTY_AI_AGENT_IN_CHAT_TRIGGER_MANUAL: "Manually triggered",
|
|
129
|
-
EventType.CHATTY_AI_AGENT_IN_CHAT_TRIGGER_RETRY: "Retry triggered",
|
|
130
|
-
|
|
131
|
-
EventType.CHATTY_AI_AGENT_IN_CHAT_STATE_PROCESSING_STARTED: "Processing started",
|
|
132
|
-
EventType.CHATTY_AI_AGENT_IN_CHAT_STATE_CALL_STARTED: "AI agent call started",
|
|
133
|
-
EventType.CHATTY_AI_AGENT_IN_CHAT_STATE_ESCALATED: "Escalated to human agent",
|
|
134
|
-
EventType.CHATTY_AI_AGENT_IN_CHAT_STATE_UNESCALATED: "Returned to AI agent",
|
|
135
|
-
|
|
136
|
-
EventType.CHATTY_AI_AGENT_IN_CHAT_CALL_GET_CHAT_WITH_PROMPT: "Requesting chat context",
|
|
137
|
-
EventType.CHATTY_AI_AGENT_IN_CHAT_CALL_TAGGER: "Calling tagger service",
|
|
138
|
-
EventType.CHATTY_AI_AGENT_IN_CHAT_CALL_DOUBLE_CHECKER: "Calling double checker",
|
|
139
|
-
EventType.CHATTY_AI_AGENT_IN_CHAT_CALL_DEBUGGER: "Running debugger",
|
|
140
|
-
|
|
141
|
-
EventType.CHATTY_AI_AGENT_IN_CHAT_CALLBACK_GET_CHAT_WITH_PROMPT: "Chat context received",
|
|
142
|
-
EventType.CHATTY_AI_AGENT_IN_CHAT_CALLBACK_TAGGER: "Tagger response received",
|
|
143
|
-
EventType.CHATTY_AI_AGENT_IN_CHAT_CALLBACK_DOUBLE_CHECKER: "Double checker validation complete",
|
|
144
|
-
EventType.CHATTY_AI_AGENT_IN_CHAT_CALLBACK_OUTPUT_RECEIVED: "AI agent output received",
|
|
145
|
-
|
|
146
|
-
EventType.CHATTY_AI_AGENT_IN_CHAT_DECISION_SEND: "Decision: Send message",
|
|
147
|
-
EventType.CHATTY_AI_AGENT_IN_CHAT_DECISION_SUGGEST: "Decision: Suggest message",
|
|
148
|
-
EventType.CHATTY_AI_AGENT_IN_CHAT_DECISION_ESCALATE: "Decision: Escalate to human",
|
|
149
|
-
EventType.CHATTY_AI_AGENT_IN_CHAT_DECISION_SKIP: "Decision: Skip message",
|
|
150
|
-
EventType.CHATTY_AI_AGENT_IN_CHAT_DECISION_SENT_TO_API: "Decision sent to API",
|
|
151
|
-
EventType.CHATTY_AI_AGENT_IN_CHAT_DECISION_COMPLETED: "Decision completed successfully",
|
|
152
|
-
|
|
153
|
-
EventType.CHATTY_AI_AGENT_IN_CHAT_ERROR_CALL_FAILED: f"Call failed: {context.get('error_message', 'Unknown error')}",
|
|
154
|
-
EventType.CHATTY_AI_AGENT_IN_CHAT_ERROR_CALL_CANCELLED: "Call cancelled",
|
|
155
|
-
EventType.CHATTY_AI_AGENT_IN_CHAT_ERROR_VALIDATION_FAILED: f"Validation failed: {context.get('error_message', 'Invalid data')}",
|
|
156
|
-
|
|
157
|
-
EventType.CHATTY_AI_AGENT_IN_CHAT_RATING_RECEIVED: f"User rated: {context.get('user_rating', '?')}/5 stars",
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return messages.get(event_type, str(event_type))
|
|
161
|
-
|
|
File without changes
|