letschatty 0.4.350__py3-none-any.whl → 0.4.352__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.

Potentially problematic release.


This version of letschatty might be problematic. Click here for more details.

Files changed (92) hide show
  1. letschatty/models/ai_microservices/__init__.py +4 -4
  2. letschatty/models/ai_microservices/expected_output.py +2 -29
  3. letschatty/models/ai_microservices/lambda_events.py +28 -155
  4. letschatty/models/ai_microservices/lambda_invokation_types.py +1 -4
  5. letschatty/models/ai_microservices/n8n_ai_agents_payload.py +1 -3
  6. letschatty/models/analytics/events/__init__.py +3 -3
  7. letschatty/models/analytics/events/chat_based_events/chat_client.py +19 -0
  8. letschatty/models/analytics/events/chat_based_events/chat_funnel.py +69 -13
  9. letschatty/models/analytics/events/company_based_events/asset_events.py +9 -2
  10. letschatty/models/analytics/events/event_type_to_classes.py +7 -3
  11. letschatty/models/analytics/events/event_types.py +11 -50
  12. letschatty/models/chat/chat.py +13 -2
  13. letschatty/models/chat/chat_with_assets.py +6 -1
  14. letschatty/models/chat/client.py +0 -2
  15. letschatty/models/chat/continuous_conversation.py +1 -1
  16. letschatty/models/company/CRM/funnel.py +365 -33
  17. letschatty/models/company/__init__.py +10 -1
  18. letschatty/models/company/assets/ai_agents_v2/ai_agents_decision_output.py +1 -1
  19. letschatty/models/company/assets/ai_agents_v2/chatty_ai_agent_in_chat.py +0 -4
  20. letschatty/models/company/assets/ai_agents_v2/chatty_ai_mode.py +2 -2
  21. letschatty/models/company/assets/ai_agents_v2/get_chat_with_prompt_response.py +0 -1
  22. letschatty/models/company/assets/ai_agents_v2/pre_qualify_config.py +1 -29
  23. letschatty/models/company/assets/automation.py +10 -19
  24. letschatty/models/company/assets/chat_assets.py +3 -2
  25. letschatty/models/company/assets/company_assets.py +2 -0
  26. letschatty/models/company/assets/sale.py +3 -3
  27. letschatty/models/company/empresa.py +4 -1
  28. letschatty/models/company/integrations/product_sync_status.py +28 -0
  29. letschatty/models/company/integrations/shopify/company_shopify_integration.py +62 -0
  30. letschatty/models/company/integrations/shopify/shopify_product_sync_status.py +18 -0
  31. letschatty/models/company/integrations/shopify/shopify_webhook_topics.py +40 -0
  32. letschatty/models/company/integrations/sync_status_enum.py +9 -0
  33. letschatty/models/company/integrations/tienda_nube/company_tienda_nube_integration.py +62 -0
  34. letschatty/models/company/integrations/tienda_nube/tienda_nube_product_sync_status.py +18 -0
  35. letschatty/models/company/integrations/tienda_nube/tienda_nube_webhook_topics.py +46 -0
  36. letschatty/models/data_base/collection_interface.py +29 -101
  37. letschatty/models/data_base/mongo_connection.py +9 -92
  38. letschatty/models/messages/chatty_messages/schema/chatty_content/content_document.py +4 -2
  39. letschatty/models/messages/chatty_messages/schema/chatty_content/content_media.py +4 -3
  40. letschatty/models/utils/custom_exceptions/custom_exceptions.py +1 -14
  41. letschatty/services/ai_agents/smart_follow_up_context_builder_v2.py +2 -5
  42. letschatty/services/chat/chat_service.py +47 -11
  43. letschatty/services/chatty_assets/__init__.py +0 -12
  44. letschatty/services/chatty_assets/asset_service.py +13 -190
  45. letschatty/services/chatty_assets/base_container.py +2 -3
  46. letschatty/services/chatty_assets/base_container_with_collection.py +26 -35
  47. letschatty/services/continuous_conversation_service/continuous_conversation_helper.py +0 -11
  48. letschatty/services/events/events_manager.py +1 -218
  49. letschatty/services/factories/analytics/events_factory.py +30 -66
  50. letschatty/services/factories/lambda_ai_orchestrartor/lambda_events_factory.py +8 -46
  51. letschatty/services/messages_helpers/get_caption_or_body_or_preview.py +4 -6
  52. letschatty/services/validators/analytics_validator.py +11 -0
  53. {letschatty-0.4.350.dist-info → letschatty-0.4.352.dist-info}/METADATA +1 -1
  54. {letschatty-0.4.350.dist-info → letschatty-0.4.352.dist-info}/RECORD +56 -83
  55. letschatty/models/analytics/events/chat_based_events/ai_agent_execution_event.py +0 -71
  56. letschatty/services/chatty_assets/assets_collections.py +0 -137
  57. letschatty/services/chatty_assets/collections/__init__.py +0 -38
  58. letschatty/services/chatty_assets/collections/ai_agent_collection.py +0 -19
  59. letschatty/services/chatty_assets/collections/ai_agent_in_chat_collection.py +0 -32
  60. letschatty/services/chatty_assets/collections/ai_component_collection.py +0 -21
  61. letschatty/services/chatty_assets/collections/chain_of_thought_collection.py +0 -30
  62. letschatty/services/chatty_assets/collections/chat_collection.py +0 -21
  63. letschatty/services/chatty_assets/collections/contact_point_collection.py +0 -21
  64. letschatty/services/chatty_assets/collections/fast_answer_collection.py +0 -21
  65. letschatty/services/chatty_assets/collections/filter_criteria_collection.py +0 -18
  66. letschatty/services/chatty_assets/collections/flow_collection.py +0 -20
  67. letschatty/services/chatty_assets/collections/product_collection.py +0 -20
  68. letschatty/services/chatty_assets/collections/sale_collection.py +0 -20
  69. letschatty/services/chatty_assets/collections/source_collection.py +0 -21
  70. letschatty/services/chatty_assets/collections/tag_collection.py +0 -19
  71. letschatty/services/chatty_assets/collections/topic_collection.py +0 -21
  72. letschatty/services/chatty_assets/collections/user_collection.py +0 -20
  73. letschatty/services/chatty_assets/example_usage.py +0 -44
  74. letschatty/services/chatty_assets/services/__init__.py +0 -37
  75. letschatty/services/chatty_assets/services/ai_agent_in_chat_service.py +0 -73
  76. letschatty/services/chatty_assets/services/ai_agent_service.py +0 -23
  77. letschatty/services/chatty_assets/services/chain_of_thought_service.py +0 -70
  78. letschatty/services/chatty_assets/services/chat_service.py +0 -25
  79. letschatty/services/chatty_assets/services/contact_point_service.py +0 -29
  80. letschatty/services/chatty_assets/services/fast_answer_service.py +0 -32
  81. letschatty/services/chatty_assets/services/filter_criteria_service.py +0 -30
  82. letschatty/services/chatty_assets/services/flow_service.py +0 -25
  83. letschatty/services/chatty_assets/services/product_service.py +0 -30
  84. letschatty/services/chatty_assets/services/sale_service.py +0 -25
  85. letschatty/services/chatty_assets/services/source_service.py +0 -28
  86. letschatty/services/chatty_assets/services/tag_service.py +0 -32
  87. letschatty/services/chatty_assets/services/topic_service.py +0 -31
  88. letschatty/services/chatty_assets/services/user_service.py +0 -32
  89. letschatty/services/events/__init__.py +0 -6
  90. letschatty/services/factories/analytics/ai_agent_event_factory.py +0 -161
  91. {letschatty-0.4.350.dist-info → letschatty-0.4.352.dist-info}/LICENSE +0 -0
  92. {letschatty-0.4.350.dist-info → letschatty-0.4.352.dist-info}/WHEEL +0 -0
@@ -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,6 +0,0 @@
1
- """Events management services"""
2
-
3
- from .events_manager import EventsManager, events_manager
4
-
5
- __all__ = ['EventsManager', 'events_manager']
6
-
@@ -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
-