dtSpark 1.0.4__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.
- dtSpark/__init__.py +0 -0
- dtSpark/_description.txt +1 -0
- dtSpark/_full_name.txt +1 -0
- dtSpark/_licence.txt +21 -0
- dtSpark/_metadata.yaml +6 -0
- dtSpark/_name.txt +1 -0
- dtSpark/_version.txt +1 -0
- dtSpark/aws/__init__.py +7 -0
- dtSpark/aws/authentication.py +296 -0
- dtSpark/aws/bedrock.py +578 -0
- dtSpark/aws/costs.py +318 -0
- dtSpark/aws/pricing.py +580 -0
- dtSpark/cli_interface.py +2645 -0
- dtSpark/conversation_manager.py +3050 -0
- dtSpark/core/__init__.py +12 -0
- dtSpark/core/application.py +3355 -0
- dtSpark/core/context_compaction.py +735 -0
- dtSpark/daemon/__init__.py +104 -0
- dtSpark/daemon/__main__.py +10 -0
- dtSpark/daemon/action_monitor.py +213 -0
- dtSpark/daemon/daemon_app.py +730 -0
- dtSpark/daemon/daemon_manager.py +289 -0
- dtSpark/daemon/execution_coordinator.py +194 -0
- dtSpark/daemon/pid_file.py +169 -0
- dtSpark/database/__init__.py +482 -0
- dtSpark/database/autonomous_actions.py +1191 -0
- dtSpark/database/backends.py +329 -0
- dtSpark/database/connection.py +122 -0
- dtSpark/database/conversations.py +520 -0
- dtSpark/database/credential_prompt.py +218 -0
- dtSpark/database/files.py +205 -0
- dtSpark/database/mcp_ops.py +355 -0
- dtSpark/database/messages.py +161 -0
- dtSpark/database/schema.py +673 -0
- dtSpark/database/tool_permissions.py +186 -0
- dtSpark/database/usage.py +167 -0
- dtSpark/files/__init__.py +4 -0
- dtSpark/files/manager.py +322 -0
- dtSpark/launch.py +39 -0
- dtSpark/limits/__init__.py +10 -0
- dtSpark/limits/costs.py +296 -0
- dtSpark/limits/tokens.py +342 -0
- dtSpark/llm/__init__.py +17 -0
- dtSpark/llm/anthropic_direct.py +446 -0
- dtSpark/llm/base.py +146 -0
- dtSpark/llm/context_limits.py +438 -0
- dtSpark/llm/manager.py +177 -0
- dtSpark/llm/ollama.py +578 -0
- dtSpark/mcp_integration/__init__.py +5 -0
- dtSpark/mcp_integration/manager.py +653 -0
- dtSpark/mcp_integration/tool_selector.py +225 -0
- dtSpark/resources/config.yaml.template +631 -0
- dtSpark/safety/__init__.py +22 -0
- dtSpark/safety/llm_service.py +111 -0
- dtSpark/safety/patterns.py +229 -0
- dtSpark/safety/prompt_inspector.py +442 -0
- dtSpark/safety/violation_logger.py +346 -0
- dtSpark/scheduler/__init__.py +20 -0
- dtSpark/scheduler/creation_tools.py +599 -0
- dtSpark/scheduler/execution_queue.py +159 -0
- dtSpark/scheduler/executor.py +1152 -0
- dtSpark/scheduler/manager.py +395 -0
- dtSpark/tools/__init__.py +4 -0
- dtSpark/tools/builtin.py +833 -0
- dtSpark/web/__init__.py +20 -0
- dtSpark/web/auth.py +152 -0
- dtSpark/web/dependencies.py +37 -0
- dtSpark/web/endpoints/__init__.py +17 -0
- dtSpark/web/endpoints/autonomous_actions.py +1125 -0
- dtSpark/web/endpoints/chat.py +621 -0
- dtSpark/web/endpoints/conversations.py +353 -0
- dtSpark/web/endpoints/main_menu.py +547 -0
- dtSpark/web/endpoints/streaming.py +421 -0
- dtSpark/web/server.py +578 -0
- dtSpark/web/session.py +167 -0
- dtSpark/web/ssl_utils.py +195 -0
- dtSpark/web/static/css/dark-theme.css +427 -0
- dtSpark/web/static/js/actions.js +1101 -0
- dtSpark/web/static/js/chat.js +614 -0
- dtSpark/web/static/js/main.js +496 -0
- dtSpark/web/static/js/sse-client.js +242 -0
- dtSpark/web/templates/actions.html +408 -0
- dtSpark/web/templates/base.html +93 -0
- dtSpark/web/templates/chat.html +814 -0
- dtSpark/web/templates/conversations.html +350 -0
- dtSpark/web/templates/goodbye.html +81 -0
- dtSpark/web/templates/login.html +90 -0
- dtSpark/web/templates/main_menu.html +983 -0
- dtSpark/web/templates/new_conversation.html +191 -0
- dtSpark/web/web_interface.py +137 -0
- dtspark-1.0.4.dist-info/METADATA +187 -0
- dtspark-1.0.4.dist-info/RECORD +96 -0
- dtspark-1.0.4.dist-info/WHEEL +5 -0
- dtspark-1.0.4.dist-info/entry_points.txt +3 -0
- dtspark-1.0.4.dist-info/licenses/LICENSE +21 -0
- dtspark-1.0.4.dist-info/top_level.txt +1 -0
dtSpark/web/__init__.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Web interface module for Spark.
|
|
3
|
+
|
|
4
|
+
This module provides a FastAPI-based web interface as an alternative to the CLI,
|
|
5
|
+
with authentication, session management, and real-time streaming via SSE.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from .server import create_app, run_server, WebServer
|
|
11
|
+
from .auth import AuthManager
|
|
12
|
+
from .session import SessionManager
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
'create_app',
|
|
16
|
+
'run_server',
|
|
17
|
+
'WebServer',
|
|
18
|
+
'AuthManager',
|
|
19
|
+
'SessionManager',
|
|
20
|
+
]
|
dtSpark/web/auth.py
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Authentication manager for web interface.
|
|
3
|
+
|
|
4
|
+
Implements authentication code system with secure hashing.
|
|
5
|
+
Codes are reusable to allow re-authentication after session expiration.
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import secrets
|
|
10
|
+
import string
|
|
11
|
+
import hashlib
|
|
12
|
+
from typing import Optional
|
|
13
|
+
from datetime import datetime
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class AuthManager:
|
|
17
|
+
"""
|
|
18
|
+
Manages authentication for the web interface using authentication codes.
|
|
19
|
+
|
|
20
|
+
Security features:
|
|
21
|
+
- Generates cryptographically secure random codes
|
|
22
|
+
- Stores hashed codes (not plaintext)
|
|
23
|
+
- Code can be reused for session re-authentication (required for session expiry)
|
|
24
|
+
- Code generation logged with timestamp
|
|
25
|
+
- Use count tracked for audit purposes
|
|
26
|
+
|
|
27
|
+
Note:
|
|
28
|
+
Since this is a local-only application (127.0.0.1), the code can be
|
|
29
|
+
reused to allow users to re-authenticate after session expiration.
|
|
30
|
+
The code is displayed in the console and remains valid for the
|
|
31
|
+
lifetime of the application.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
def __init__(self):
|
|
35
|
+
"""Initialise the authentication manager."""
|
|
36
|
+
self._code_hash: Optional[str] = None
|
|
37
|
+
self._use_count: int = 0
|
|
38
|
+
self._generated_at: Optional[datetime] = None
|
|
39
|
+
self._last_used_at: Optional[datetime] = None
|
|
40
|
+
|
|
41
|
+
def generate_code(self, length: int = 8) -> str:
|
|
42
|
+
"""
|
|
43
|
+
Generate a new authentication code.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
length: Length of the code (default: 8 characters)
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
The generated code (plaintext, for display to user)
|
|
50
|
+
|
|
51
|
+
Note:
|
|
52
|
+
The code is stored as a SHA-256 hash internally for security.
|
|
53
|
+
"""
|
|
54
|
+
# Generate cryptographically secure random code
|
|
55
|
+
alphabet = string.ascii_uppercase + string.digits
|
|
56
|
+
code = ''.join(secrets.choice(alphabet) for _ in range(length))
|
|
57
|
+
|
|
58
|
+
# Store hash of code (not plaintext)
|
|
59
|
+
self._code_hash = self._hash_code(code)
|
|
60
|
+
self._use_count = 0
|
|
61
|
+
self._generated_at = datetime.now()
|
|
62
|
+
self._last_used_at = None
|
|
63
|
+
|
|
64
|
+
return code
|
|
65
|
+
|
|
66
|
+
def validate_code(self, code: str) -> bool:
|
|
67
|
+
"""
|
|
68
|
+
Validate an authentication code.
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
code: The code to validate
|
|
72
|
+
|
|
73
|
+
Returns:
|
|
74
|
+
True if code is valid, False otherwise
|
|
75
|
+
|
|
76
|
+
Note:
|
|
77
|
+
The code can be reused for session re-authentication after
|
|
78
|
+
session expiration. Use count is tracked for audit purposes.
|
|
79
|
+
"""
|
|
80
|
+
# Check if code exists
|
|
81
|
+
if self._code_hash is None:
|
|
82
|
+
return False
|
|
83
|
+
|
|
84
|
+
# Validate code by comparing hashes
|
|
85
|
+
if self._hash_code(code) == self._code_hash:
|
|
86
|
+
# Track usage for audit purposes
|
|
87
|
+
self._use_count += 1
|
|
88
|
+
self._last_used_at = datetime.now()
|
|
89
|
+
return True
|
|
90
|
+
|
|
91
|
+
return False
|
|
92
|
+
|
|
93
|
+
def is_code_used(self) -> bool:
|
|
94
|
+
"""
|
|
95
|
+
Check if the current code has been used at least once.
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
True if code has been used, False otherwise
|
|
99
|
+
"""
|
|
100
|
+
return self._use_count > 0
|
|
101
|
+
|
|
102
|
+
def get_use_count(self) -> int:
|
|
103
|
+
"""
|
|
104
|
+
Get the number of times the code has been used.
|
|
105
|
+
|
|
106
|
+
Returns:
|
|
107
|
+
Number of times the code has been used for authentication
|
|
108
|
+
"""
|
|
109
|
+
return self._use_count
|
|
110
|
+
|
|
111
|
+
def get_last_used_at(self) -> Optional[datetime]:
|
|
112
|
+
"""
|
|
113
|
+
Get the timestamp when the code was last used.
|
|
114
|
+
|
|
115
|
+
Returns:
|
|
116
|
+
Datetime when code was last used, or None if never used
|
|
117
|
+
"""
|
|
118
|
+
return self._last_used_at
|
|
119
|
+
|
|
120
|
+
def get_generated_at(self) -> Optional[datetime]:
|
|
121
|
+
"""
|
|
122
|
+
Get the timestamp when the code was generated.
|
|
123
|
+
|
|
124
|
+
Returns:
|
|
125
|
+
Datetime when code was generated, or None if no code exists
|
|
126
|
+
"""
|
|
127
|
+
return self._generated_at
|
|
128
|
+
|
|
129
|
+
def reset(self):
|
|
130
|
+
"""
|
|
131
|
+
Reset the authentication state.
|
|
132
|
+
|
|
133
|
+
This clears the current code and allows a new one to be generated.
|
|
134
|
+
Used when restarting the web server.
|
|
135
|
+
"""
|
|
136
|
+
self._code_hash = None
|
|
137
|
+
self._use_count = 0
|
|
138
|
+
self._generated_at = None
|
|
139
|
+
self._last_used_at = None
|
|
140
|
+
|
|
141
|
+
@staticmethod
|
|
142
|
+
def _hash_code(code: str) -> str:
|
|
143
|
+
"""
|
|
144
|
+
Hash a code using SHA-256.
|
|
145
|
+
|
|
146
|
+
Args:
|
|
147
|
+
code: The code to hash
|
|
148
|
+
|
|
149
|
+
Returns:
|
|
150
|
+
Hexadecimal string representation of the hash
|
|
151
|
+
"""
|
|
152
|
+
return hashlib.sha256(code.encode('utf-8')).hexdigest()
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Shared dependencies for web endpoints.
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Optional
|
|
8
|
+
from fastapi import Cookie, HTTPException, Request
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
async def get_current_session(
|
|
12
|
+
request: Request,
|
|
13
|
+
session_id: Optional[str] = Cookie(default=None)
|
|
14
|
+
) -> str:
|
|
15
|
+
"""
|
|
16
|
+
Dependency to validate the current session.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
request: FastAPI request object
|
|
20
|
+
session_id: Session ID from cookie
|
|
21
|
+
|
|
22
|
+
Returns:
|
|
23
|
+
Valid session ID
|
|
24
|
+
|
|
25
|
+
Raises:
|
|
26
|
+
HTTPException: If session is invalid or expired
|
|
27
|
+
"""
|
|
28
|
+
if session_id is None:
|
|
29
|
+
raise HTTPException(status_code=401, detail="Not authenticated")
|
|
30
|
+
|
|
31
|
+
# Get session manager from app state
|
|
32
|
+
session_manager = request.app.state.session_manager
|
|
33
|
+
|
|
34
|
+
if not session_manager.validate_session(session_id):
|
|
35
|
+
raise HTTPException(status_code=401, detail="Session expired or invalid")
|
|
36
|
+
|
|
37
|
+
return session_id
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""
|
|
2
|
+
API endpoints for the web interface.
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .main_menu import router as main_menu_router
|
|
8
|
+
from .conversations import router as conversations_router
|
|
9
|
+
from .chat import router as chat_router
|
|
10
|
+
from .streaming import router as streaming_router
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
'main_menu_router',
|
|
14
|
+
'conversations_router',
|
|
15
|
+
'chat_router',
|
|
16
|
+
'streaming_router',
|
|
17
|
+
]
|