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.
Files changed (96) hide show
  1. dtSpark/__init__.py +0 -0
  2. dtSpark/_description.txt +1 -0
  3. dtSpark/_full_name.txt +1 -0
  4. dtSpark/_licence.txt +21 -0
  5. dtSpark/_metadata.yaml +6 -0
  6. dtSpark/_name.txt +1 -0
  7. dtSpark/_version.txt +1 -0
  8. dtSpark/aws/__init__.py +7 -0
  9. dtSpark/aws/authentication.py +296 -0
  10. dtSpark/aws/bedrock.py +578 -0
  11. dtSpark/aws/costs.py +318 -0
  12. dtSpark/aws/pricing.py +580 -0
  13. dtSpark/cli_interface.py +2645 -0
  14. dtSpark/conversation_manager.py +3050 -0
  15. dtSpark/core/__init__.py +12 -0
  16. dtSpark/core/application.py +3355 -0
  17. dtSpark/core/context_compaction.py +735 -0
  18. dtSpark/daemon/__init__.py +104 -0
  19. dtSpark/daemon/__main__.py +10 -0
  20. dtSpark/daemon/action_monitor.py +213 -0
  21. dtSpark/daemon/daemon_app.py +730 -0
  22. dtSpark/daemon/daemon_manager.py +289 -0
  23. dtSpark/daemon/execution_coordinator.py +194 -0
  24. dtSpark/daemon/pid_file.py +169 -0
  25. dtSpark/database/__init__.py +482 -0
  26. dtSpark/database/autonomous_actions.py +1191 -0
  27. dtSpark/database/backends.py +329 -0
  28. dtSpark/database/connection.py +122 -0
  29. dtSpark/database/conversations.py +520 -0
  30. dtSpark/database/credential_prompt.py +218 -0
  31. dtSpark/database/files.py +205 -0
  32. dtSpark/database/mcp_ops.py +355 -0
  33. dtSpark/database/messages.py +161 -0
  34. dtSpark/database/schema.py +673 -0
  35. dtSpark/database/tool_permissions.py +186 -0
  36. dtSpark/database/usage.py +167 -0
  37. dtSpark/files/__init__.py +4 -0
  38. dtSpark/files/manager.py +322 -0
  39. dtSpark/launch.py +39 -0
  40. dtSpark/limits/__init__.py +10 -0
  41. dtSpark/limits/costs.py +296 -0
  42. dtSpark/limits/tokens.py +342 -0
  43. dtSpark/llm/__init__.py +17 -0
  44. dtSpark/llm/anthropic_direct.py +446 -0
  45. dtSpark/llm/base.py +146 -0
  46. dtSpark/llm/context_limits.py +438 -0
  47. dtSpark/llm/manager.py +177 -0
  48. dtSpark/llm/ollama.py +578 -0
  49. dtSpark/mcp_integration/__init__.py +5 -0
  50. dtSpark/mcp_integration/manager.py +653 -0
  51. dtSpark/mcp_integration/tool_selector.py +225 -0
  52. dtSpark/resources/config.yaml.template +631 -0
  53. dtSpark/safety/__init__.py +22 -0
  54. dtSpark/safety/llm_service.py +111 -0
  55. dtSpark/safety/patterns.py +229 -0
  56. dtSpark/safety/prompt_inspector.py +442 -0
  57. dtSpark/safety/violation_logger.py +346 -0
  58. dtSpark/scheduler/__init__.py +20 -0
  59. dtSpark/scheduler/creation_tools.py +599 -0
  60. dtSpark/scheduler/execution_queue.py +159 -0
  61. dtSpark/scheduler/executor.py +1152 -0
  62. dtSpark/scheduler/manager.py +395 -0
  63. dtSpark/tools/__init__.py +4 -0
  64. dtSpark/tools/builtin.py +833 -0
  65. dtSpark/web/__init__.py +20 -0
  66. dtSpark/web/auth.py +152 -0
  67. dtSpark/web/dependencies.py +37 -0
  68. dtSpark/web/endpoints/__init__.py +17 -0
  69. dtSpark/web/endpoints/autonomous_actions.py +1125 -0
  70. dtSpark/web/endpoints/chat.py +621 -0
  71. dtSpark/web/endpoints/conversations.py +353 -0
  72. dtSpark/web/endpoints/main_menu.py +547 -0
  73. dtSpark/web/endpoints/streaming.py +421 -0
  74. dtSpark/web/server.py +578 -0
  75. dtSpark/web/session.py +167 -0
  76. dtSpark/web/ssl_utils.py +195 -0
  77. dtSpark/web/static/css/dark-theme.css +427 -0
  78. dtSpark/web/static/js/actions.js +1101 -0
  79. dtSpark/web/static/js/chat.js +614 -0
  80. dtSpark/web/static/js/main.js +496 -0
  81. dtSpark/web/static/js/sse-client.js +242 -0
  82. dtSpark/web/templates/actions.html +408 -0
  83. dtSpark/web/templates/base.html +93 -0
  84. dtSpark/web/templates/chat.html +814 -0
  85. dtSpark/web/templates/conversations.html +350 -0
  86. dtSpark/web/templates/goodbye.html +81 -0
  87. dtSpark/web/templates/login.html +90 -0
  88. dtSpark/web/templates/main_menu.html +983 -0
  89. dtSpark/web/templates/new_conversation.html +191 -0
  90. dtSpark/web/web_interface.py +137 -0
  91. dtspark-1.0.4.dist-info/METADATA +187 -0
  92. dtspark-1.0.4.dist-info/RECORD +96 -0
  93. dtspark-1.0.4.dist-info/WHEEL +5 -0
  94. dtspark-1.0.4.dist-info/entry_points.txt +3 -0
  95. dtspark-1.0.4.dist-info/licenses/LICENSE +21 -0
  96. dtspark-1.0.4.dist-info/top_level.txt +1 -0
@@ -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
+ ]