chuk-ai-session-manager 0.4__py3-none-any.whl → 0.5__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.
- chuk_ai_session_manager/__init__.py +166 -34
- chuk_ai_session_manager/api/simple_api.py +276 -425
- chuk_ai_session_manager/models/session.py +11 -4
- chuk_ai_session_manager/models/session_event.py +185 -81
- chuk_ai_session_manager/session_manager.py +760 -0
- chuk_ai_session_manager/session_storage.py +19 -6
- chuk_ai_session_manager-0.5.dist-info/METADATA +896 -0
- {chuk_ai_session_manager-0.4.dist-info → chuk_ai_session_manager-0.5.dist-info}/RECORD +10 -9
- chuk_ai_session_manager-0.4.dist-info/METADATA +0 -354
- {chuk_ai_session_manager-0.4.dist-info → chuk_ai_session_manager-0.5.dist-info}/WHEEL +0 -0
- {chuk_ai_session_manager-0.4.dist-info → chuk_ai_session_manager-0.5.dist-info}/top_level.txt +0 -0
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
# chuk_ai_session_manager/__init__.py
|
|
1
|
+
# src/chuk_ai_session_manager/__init__.py
|
|
2
2
|
"""
|
|
3
3
|
CHUK AI Session Manager - Simple Developer API
|
|
4
4
|
|
|
5
|
+
A powerful session management system for AI applications that provides:
|
|
6
|
+
- Automatic conversation tracking
|
|
7
|
+
- Token usage monitoring
|
|
8
|
+
- Tool call logging
|
|
9
|
+
- Infinite context support with automatic summarization
|
|
10
|
+
- Hierarchical session relationships
|
|
11
|
+
- CHUK Sessions backend integration
|
|
12
|
+
|
|
5
13
|
Quick Start:
|
|
6
14
|
from chuk_ai_session_manager import track_conversation
|
|
7
15
|
|
|
@@ -13,61 +21,185 @@ Quick Start:
|
|
|
13
21
|
sm = SessionManager()
|
|
14
22
|
await sm.user_says("What's the weather?")
|
|
15
23
|
await sm.ai_responds("It's sunny and 72°F", model="gpt-4")
|
|
24
|
+
|
|
25
|
+
Infinite Context Example:
|
|
26
|
+
# Automatically handles long conversations with summarization
|
|
27
|
+
sm = SessionManager(infinite_context=True, token_threshold=4000)
|
|
28
|
+
await sm.user_says("Tell me about machine learning")
|
|
29
|
+
await sm.ai_responds("Machine learning is...", model="gpt-4")
|
|
30
|
+
# Session will auto-segment when limits are reached
|
|
16
31
|
"""
|
|
17
32
|
|
|
18
|
-
|
|
33
|
+
import logging
|
|
34
|
+
|
|
35
|
+
# Package version
|
|
36
|
+
__version__ = "0.4"
|
|
37
|
+
|
|
38
|
+
# Set up package-level logger
|
|
39
|
+
logger = logging.getLogger(__name__)
|
|
40
|
+
|
|
41
|
+
# Core enums and constants
|
|
19
42
|
from chuk_ai_session_manager.models.event_source import EventSource
|
|
20
43
|
from chuk_ai_session_manager.models.event_type import EventType
|
|
21
44
|
|
|
22
|
-
#
|
|
23
|
-
from chuk_ai_session_manager.
|
|
45
|
+
# Exception classes
|
|
46
|
+
from chuk_ai_session_manager.exceptions import (
|
|
47
|
+
SessionManagerError,
|
|
48
|
+
SessionNotFound,
|
|
49
|
+
SessionAlreadyExists,
|
|
50
|
+
InvalidSessionOperation,
|
|
51
|
+
TokenLimitExceeded,
|
|
52
|
+
StorageError,
|
|
53
|
+
ToolProcessingError
|
|
54
|
+
)
|
|
24
55
|
|
|
25
|
-
#
|
|
26
|
-
from chuk_ai_session_manager.models.
|
|
56
|
+
# Core models
|
|
57
|
+
from chuk_ai_session_manager.models.session_metadata import SessionMetadata
|
|
58
|
+
from chuk_ai_session_manager.models.session_run import SessionRun, RunStatus
|
|
59
|
+
from chuk_ai_session_manager.models.token_usage import TokenUsage, TokenSummary
|
|
27
60
|
from chuk_ai_session_manager.models.session_event import SessionEvent
|
|
61
|
+
from chuk_ai_session_manager.models.session import Session
|
|
62
|
+
|
|
63
|
+
# Storage backend
|
|
64
|
+
from chuk_ai_session_manager.session_storage import setup_chuk_sessions_storage
|
|
28
65
|
|
|
29
|
-
#
|
|
66
|
+
# High-level session manager
|
|
67
|
+
from chuk_ai_session_manager.session_manager import SessionManager
|
|
68
|
+
|
|
69
|
+
# Simple API - The main interface most users will use
|
|
30
70
|
from chuk_ai_session_manager.api.simple_api import (
|
|
31
|
-
SessionManager,
|
|
32
71
|
track_conversation,
|
|
33
72
|
track_llm_call,
|
|
34
73
|
quick_conversation,
|
|
35
|
-
track_infinite_conversation
|
|
74
|
+
track_infinite_conversation,
|
|
75
|
+
track_tool_use,
|
|
76
|
+
get_session_stats,
|
|
77
|
+
get_conversation_history
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
# Advanced components
|
|
81
|
+
from chuk_ai_session_manager.infinite_conversation import (
|
|
82
|
+
InfiniteConversationManager,
|
|
83
|
+
SummarizationStrategy
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
from chuk_ai_session_manager.session_aware_tool_processor import SessionAwareToolProcessor
|
|
87
|
+
|
|
88
|
+
from chuk_ai_session_manager.session_prompt_builder import (
|
|
89
|
+
build_prompt_from_session,
|
|
90
|
+
PromptStrategy,
|
|
91
|
+
truncate_prompt_to_token_limit
|
|
36
92
|
)
|
|
37
93
|
|
|
38
|
-
|
|
94
|
+
# Configuration functions
|
|
95
|
+
def configure_storage(sandbox_id: str = "chuk-ai-session-manager",
|
|
96
|
+
default_ttl_hours: int = 24) -> bool:
|
|
97
|
+
"""
|
|
98
|
+
Configure the storage backend.
|
|
99
|
+
|
|
100
|
+
Args:
|
|
101
|
+
sandbox_id: CHUK Sessions sandbox ID to use
|
|
102
|
+
default_ttl_hours: Default TTL for sessions
|
|
103
|
+
|
|
104
|
+
Returns:
|
|
105
|
+
True if configuration was successful, False otherwise
|
|
106
|
+
"""
|
|
107
|
+
try:
|
|
108
|
+
setup_chuk_sessions_storage(
|
|
109
|
+
sandbox_id=sandbox_id,
|
|
110
|
+
default_ttl_hours=default_ttl_hours
|
|
111
|
+
)
|
|
112
|
+
logger.info(f"Storage configured with sandbox_id='{sandbox_id}'")
|
|
113
|
+
return True
|
|
114
|
+
except Exception as e:
|
|
115
|
+
logger.error(f"Failed to configure storage: {e}")
|
|
116
|
+
return False
|
|
117
|
+
|
|
39
118
|
|
|
40
|
-
|
|
119
|
+
def get_version() -> str:
|
|
120
|
+
"""Get the package version."""
|
|
121
|
+
return __version__
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def is_available() -> dict:
|
|
125
|
+
"""
|
|
126
|
+
Check which components are available.
|
|
127
|
+
|
|
128
|
+
Returns:
|
|
129
|
+
Dictionary showing availability of each component
|
|
130
|
+
"""
|
|
131
|
+
return {
|
|
132
|
+
"core_enums": True,
|
|
133
|
+
"core_models": True,
|
|
134
|
+
"simple_api": True,
|
|
135
|
+
"storage": True,
|
|
136
|
+
"infinite_context": True,
|
|
137
|
+
"tool_processor": True,
|
|
138
|
+
"prompt_builder": True,
|
|
139
|
+
"token_tracking": True,
|
|
140
|
+
"exceptions": True,
|
|
141
|
+
"session_manager": True,
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
# Main exports - everything should be available
|
|
41
146
|
__all__ = [
|
|
42
|
-
#
|
|
147
|
+
# Version and utilities
|
|
148
|
+
"__version__",
|
|
149
|
+
"get_version",
|
|
150
|
+
"is_available",
|
|
151
|
+
"configure_storage",
|
|
152
|
+
|
|
153
|
+
# Core enums
|
|
154
|
+
"EventSource",
|
|
155
|
+
"EventType",
|
|
156
|
+
|
|
157
|
+
# Exception classes
|
|
158
|
+
"SessionManagerError",
|
|
159
|
+
"SessionNotFound",
|
|
160
|
+
"SessionAlreadyExists",
|
|
161
|
+
"InvalidSessionOperation",
|
|
162
|
+
"TokenLimitExceeded",
|
|
163
|
+
"StorageError",
|
|
164
|
+
"ToolProcessingError",
|
|
165
|
+
|
|
166
|
+
# Core models
|
|
167
|
+
"Session",
|
|
168
|
+
"SessionEvent",
|
|
169
|
+
"SessionMetadata",
|
|
170
|
+
"SessionRun",
|
|
171
|
+
"RunStatus",
|
|
172
|
+
"TokenUsage",
|
|
173
|
+
"TokenSummary",
|
|
174
|
+
|
|
175
|
+
# Storage
|
|
176
|
+
"setup_chuk_sessions_storage",
|
|
177
|
+
|
|
178
|
+
# Primary interfaces - what most users will use
|
|
43
179
|
"SessionManager",
|
|
44
180
|
"track_conversation",
|
|
45
181
|
"track_llm_call",
|
|
46
182
|
"quick_conversation",
|
|
47
183
|
"track_infinite_conversation",
|
|
184
|
+
"track_tool_use",
|
|
185
|
+
"get_session_stats",
|
|
186
|
+
"get_conversation_history",
|
|
48
187
|
|
|
49
|
-
#
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"setup_chuk_sessions_storage",
|
|
188
|
+
# Advanced components
|
|
189
|
+
"InfiniteConversationManager",
|
|
190
|
+
"SummarizationStrategy",
|
|
191
|
+
"SessionAwareToolProcessor",
|
|
192
|
+
"build_prompt_from_session",
|
|
193
|
+
"PromptStrategy",
|
|
194
|
+
"truncate_prompt_to_token_limit",
|
|
57
195
|
]
|
|
58
196
|
|
|
59
|
-
# Auto-setup
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
except Exception:
|
|
66
|
-
# Silently setup with defaults
|
|
67
|
-
setup_chuk_sessions_storage(
|
|
68
|
-
sandbox_id="chuk-ai-session-manager",
|
|
69
|
-
default_ttl_hours=24
|
|
70
|
-
)
|
|
197
|
+
# Auto-setup storage on import
|
|
198
|
+
try:
|
|
199
|
+
configure_storage()
|
|
200
|
+
logger.debug("Auto-configured storage backend")
|
|
201
|
+
except Exception as e:
|
|
202
|
+
logger.debug(f"Auto-setup skipped: {e}")
|
|
71
203
|
|
|
72
|
-
#
|
|
73
|
-
|
|
204
|
+
# Log successful import
|
|
205
|
+
logger.debug(f"CHUK AI Session Manager v{__version__} imported successfully")
|