superlocalmemory 2.8.1 → 2.8.3
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.
- package/ATTRIBUTION.md +50 -0
- package/CHANGELOG.md +8 -0
- package/README.md +31 -20
- package/api_server.py +5 -0
- package/bin/aider-smart +2 -2
- package/bin/slm +18 -18
- package/bin/slm.bat +3 -3
- package/configs/continue-skills.yaml +4 -4
- package/docs/ARCHITECTURE.md +3 -3
- package/docs/CLI-COMMANDS-REFERENCE.md +18 -18
- package/docs/FRAMEWORK-INTEGRATIONS.md +4 -4
- package/docs/SECURITY-QUICK-REFERENCE.md +214 -0
- package/docs/UNIVERSAL-INTEGRATION.md +15 -15
- package/install.ps1 +11 -11
- package/install.sh +4 -4
- package/mcp_server.py +4 -4
- package/package.json +5 -3
- package/requirements-core.txt +16 -18
- package/requirements-learning.txt +8 -8
- package/requirements.txt +9 -7
- package/scripts/prepack.js +33 -0
- package/scripts/verify-v27.ps1 +301 -0
- package/src/agent_registry.py +32 -28
- package/src/auto_backup.py +12 -6
- package/src/cache_manager.py +2 -2
- package/src/compression/__init__.py +25 -0
- package/src/compression/cli.py +150 -0
- package/src/compression/cold_storage.py +217 -0
- package/src/compression/config.py +72 -0
- package/src/compression/orchestrator.py +133 -0
- package/src/compression/tier2_compressor.py +228 -0
- package/src/compression/tier3_compressor.py +153 -0
- package/src/compression/tier_classifier.py +148 -0
- package/src/db_connection_manager.py +5 -5
- package/src/event_bus.py +24 -22
- package/src/graph/graph_core.py +3 -3
- package/src/hnsw_index.py +3 -3
- package/src/learning/__init__.py +5 -4
- package/src/learning/adaptive_ranker.py +14 -265
- package/src/learning/bootstrap/__init__.py +69 -0
- package/src/learning/bootstrap/constants.py +93 -0
- package/src/learning/bootstrap/db_queries.py +316 -0
- package/src/learning/bootstrap/sampling.py +82 -0
- package/src/learning/bootstrap/text_utils.py +71 -0
- package/src/learning/cross_project_aggregator.py +58 -57
- package/src/learning/db/__init__.py +40 -0
- package/src/learning/db/constants.py +44 -0
- package/src/learning/db/schema.py +279 -0
- package/src/learning/learning_db.py +15 -234
- package/src/learning/ranking/__init__.py +33 -0
- package/src/learning/ranking/constants.py +84 -0
- package/src/learning/ranking/helpers.py +278 -0
- package/src/learning/source_quality_scorer.py +66 -65
- package/src/learning/synthetic_bootstrap.py +28 -310
- package/src/memory/__init__.py +36 -0
- package/src/memory/cli.py +205 -0
- package/src/memory/constants.py +39 -0
- package/src/memory/helpers.py +28 -0
- package/src/memory/schema.py +166 -0
- package/src/memory-profiles.py +94 -86
- package/src/memory-reset.py +187 -185
- package/src/memory_compression.py +2 -2
- package/src/memory_store_v2.py +40 -355
- package/src/migrate_v1_to_v2.py +11 -10
- package/src/patterns/analyzers.py +104 -100
- package/src/patterns/learner.py +17 -13
- package/src/patterns/scoring.py +25 -21
- package/src/patterns/store.py +40 -38
- package/src/patterns/terminology.py +53 -51
- package/src/provenance_tracker.py +2 -2
- package/src/qualixar_attribution.py +139 -0
- package/src/qualixar_watermark.py +78 -0
- package/src/search/engine.py +16 -14
- package/src/search/index_loader.py +13 -11
- package/src/setup_validator.py +162 -160
- package/src/subscription_manager.py +20 -18
- package/src/tree/builder.py +66 -64
- package/src/tree/nodes.py +103 -97
- package/src/tree/queries.py +142 -137
- package/src/tree/schema.py +46 -42
- package/src/webhook_dispatcher.py +3 -3
- package/ui_server.py +7 -4
- /package/bin/{superlocalmemoryv2:learning → superlocalmemoryv2-learning} +0 -0
- /package/bin/{superlocalmemoryv2:list → superlocalmemoryv2-list} +0 -0
- /package/bin/{superlocalmemoryv2:patterns → superlocalmemoryv2-patterns} +0 -0
- /package/bin/{superlocalmemoryv2:profile → superlocalmemoryv2-profile} +0 -0
- /package/bin/{superlocalmemoryv2:recall → superlocalmemoryv2-recall} +0 -0
- /package/bin/{superlocalmemoryv2:remember → superlocalmemoryv2-remember} +0 -0
- /package/bin/{superlocalmemoryv2:reset → superlocalmemoryv2-reset} +0 -0
- /package/bin/{superlocalmemoryv2:status → superlocalmemoryv2-status} +0 -0
package/src/tree/queries.py
CHANGED
|
@@ -28,60 +28,61 @@ class TreeQueriesMixin:
|
|
|
28
28
|
Nested dictionary representing tree structure
|
|
29
29
|
"""
|
|
30
30
|
conn = sqlite3.connect(self.db_path)
|
|
31
|
-
|
|
31
|
+
try:
|
|
32
|
+
cursor = conn.cursor()
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
cursor.execute('''
|
|
37
|
-
SELECT id, tree_path FROM memory_tree
|
|
38
|
-
WHERE node_type = 'project' AND name = ?
|
|
39
|
-
''', (project_name,))
|
|
40
|
-
result = cursor.fetchone()
|
|
41
|
-
|
|
42
|
-
if not result:
|
|
43
|
-
conn.close()
|
|
44
|
-
return {'error': f"Project '{project_name}' not found"}
|
|
45
|
-
|
|
46
|
-
project_id, project_path = result
|
|
47
|
-
|
|
48
|
-
# Get subtree
|
|
49
|
-
if max_depth is not None:
|
|
34
|
+
# Build query
|
|
35
|
+
if project_name:
|
|
36
|
+
# Find project node
|
|
50
37
|
cursor.execute('''
|
|
51
|
-
SELECT id,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
38
|
+
SELECT id, tree_path FROM memory_tree
|
|
39
|
+
WHERE node_type = 'project' AND name = ?
|
|
40
|
+
''', (project_name,))
|
|
41
|
+
result = cursor.fetchone()
|
|
42
|
+
|
|
43
|
+
if not result:
|
|
44
|
+
return {'error': f"Project '{project_name}' not found"}
|
|
45
|
+
|
|
46
|
+
project_id, project_path = result
|
|
47
|
+
|
|
48
|
+
# Get subtree
|
|
49
|
+
if max_depth is not None:
|
|
50
|
+
cursor.execute('''
|
|
51
|
+
SELECT id, node_type, name, description, parent_id, tree_path,
|
|
52
|
+
depth, memory_count, total_size, last_updated, memory_id
|
|
53
|
+
FROM memory_tree
|
|
54
|
+
WHERE (id = ? OR tree_path LIKE ?) AND depth <= ?
|
|
55
|
+
ORDER BY tree_path
|
|
56
|
+
''', (project_id, f"{project_path}.%", max_depth))
|
|
57
|
+
else:
|
|
58
|
+
cursor.execute('''
|
|
59
|
+
SELECT id, node_type, name, description, parent_id, tree_path,
|
|
60
|
+
depth, memory_count, total_size, last_updated, memory_id
|
|
61
|
+
FROM memory_tree
|
|
62
|
+
WHERE id = ? OR tree_path LIKE ?
|
|
63
|
+
ORDER BY tree_path
|
|
64
|
+
''', (project_id, f"{project_path}.%"))
|
|
57
65
|
else:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
depth, memory_count, total_size, last_updated, memory_id
|
|
79
|
-
FROM memory_tree
|
|
80
|
-
ORDER BY tree_path
|
|
81
|
-
''')
|
|
82
|
-
|
|
83
|
-
rows = cursor.fetchall()
|
|
84
|
-
conn.close()
|
|
66
|
+
# Get entire tree
|
|
67
|
+
if max_depth is not None:
|
|
68
|
+
cursor.execute('''
|
|
69
|
+
SELECT id, node_type, name, description, parent_id, tree_path,
|
|
70
|
+
depth, memory_count, total_size, last_updated, memory_id
|
|
71
|
+
FROM memory_tree
|
|
72
|
+
WHERE depth <= ?
|
|
73
|
+
ORDER BY tree_path
|
|
74
|
+
''', (max_depth,))
|
|
75
|
+
else:
|
|
76
|
+
cursor.execute('''
|
|
77
|
+
SELECT id, node_type, name, description, parent_id, tree_path,
|
|
78
|
+
depth, memory_count, total_size, last_updated, memory_id
|
|
79
|
+
FROM memory_tree
|
|
80
|
+
ORDER BY tree_path
|
|
81
|
+
''')
|
|
82
|
+
|
|
83
|
+
rows = cursor.fetchall()
|
|
84
|
+
finally:
|
|
85
|
+
conn.close()
|
|
85
86
|
|
|
86
87
|
if not rows:
|
|
87
88
|
return {'error': 'No tree nodes found'}
|
|
@@ -125,44 +126,45 @@ class TreeQueriesMixin:
|
|
|
125
126
|
List of descendant nodes
|
|
126
127
|
"""
|
|
127
128
|
conn = sqlite3.connect(self.db_path)
|
|
128
|
-
|
|
129
|
+
try:
|
|
130
|
+
cursor = conn.cursor()
|
|
131
|
+
|
|
132
|
+
# Get node's tree_path
|
|
133
|
+
cursor.execute('SELECT tree_path FROM memory_tree WHERE id = ?', (node_id,))
|
|
134
|
+
result = cursor.fetchone()
|
|
135
|
+
|
|
136
|
+
if not result:
|
|
137
|
+
return []
|
|
129
138
|
|
|
130
|
-
|
|
131
|
-
cursor.execute('SELECT tree_path FROM memory_tree WHERE id = ?', (node_id,))
|
|
132
|
-
result = cursor.fetchone()
|
|
139
|
+
tree_path = result[0]
|
|
133
140
|
|
|
134
|
-
|
|
141
|
+
# Get all descendants
|
|
142
|
+
cursor.execute('''
|
|
143
|
+
SELECT id, node_type, name, description, parent_id, tree_path,
|
|
144
|
+
depth, memory_count, total_size, last_updated, memory_id
|
|
145
|
+
FROM memory_tree
|
|
146
|
+
WHERE tree_path LIKE ?
|
|
147
|
+
ORDER BY tree_path
|
|
148
|
+
''', (f"{tree_path}.%",))
|
|
149
|
+
|
|
150
|
+
results = []
|
|
151
|
+
for row in cursor.fetchall():
|
|
152
|
+
results.append({
|
|
153
|
+
'id': row[0],
|
|
154
|
+
'type': row[1],
|
|
155
|
+
'name': row[2],
|
|
156
|
+
'description': row[3],
|
|
157
|
+
'parent_id': row[4],
|
|
158
|
+
'tree_path': row[5],
|
|
159
|
+
'depth': row[6],
|
|
160
|
+
'memory_count': row[7],
|
|
161
|
+
'total_size': row[8],
|
|
162
|
+
'last_updated': row[9],
|
|
163
|
+
'memory_id': row[10]
|
|
164
|
+
})
|
|
165
|
+
finally:
|
|
135
166
|
conn.close()
|
|
136
|
-
return []
|
|
137
|
-
|
|
138
|
-
tree_path = result[0]
|
|
139
|
-
|
|
140
|
-
# Get all descendants
|
|
141
|
-
cursor.execute('''
|
|
142
|
-
SELECT id, node_type, name, description, parent_id, tree_path,
|
|
143
|
-
depth, memory_count, total_size, last_updated, memory_id
|
|
144
|
-
FROM memory_tree
|
|
145
|
-
WHERE tree_path LIKE ?
|
|
146
|
-
ORDER BY tree_path
|
|
147
|
-
''', (f"{tree_path}.%",))
|
|
148
|
-
|
|
149
|
-
results = []
|
|
150
|
-
for row in cursor.fetchall():
|
|
151
|
-
results.append({
|
|
152
|
-
'id': row[0],
|
|
153
|
-
'type': row[1],
|
|
154
|
-
'name': row[2],
|
|
155
|
-
'description': row[3],
|
|
156
|
-
'parent_id': row[4],
|
|
157
|
-
'tree_path': row[5],
|
|
158
|
-
'depth': row[6],
|
|
159
|
-
'memory_count': row[7],
|
|
160
|
-
'total_size': row[8],
|
|
161
|
-
'last_updated': row[9],
|
|
162
|
-
'memory_id': row[10]
|
|
163
|
-
})
|
|
164
167
|
|
|
165
|
-
conn.close()
|
|
166
168
|
return results
|
|
167
169
|
|
|
168
170
|
def get_path_to_root(self, node_id: int) -> List[Dict[str, Any]]:
|
|
@@ -176,72 +178,75 @@ class TreeQueriesMixin:
|
|
|
176
178
|
List of nodes from root to target node
|
|
177
179
|
"""
|
|
178
180
|
conn = sqlite3.connect(self.db_path)
|
|
179
|
-
|
|
181
|
+
try:
|
|
182
|
+
cursor = conn.cursor()
|
|
180
183
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
+
# Get node's tree_path
|
|
185
|
+
cursor.execute('SELECT tree_path FROM memory_tree WHERE id = ?', (node_id,))
|
|
186
|
+
result = cursor.fetchone()
|
|
184
187
|
|
|
185
|
-
|
|
188
|
+
if not result:
|
|
189
|
+
return []
|
|
190
|
+
|
|
191
|
+
tree_path = result[0]
|
|
192
|
+
|
|
193
|
+
# Parse path to get all ancestor IDs
|
|
194
|
+
path_ids = [int(x) for x in tree_path.split('.')]
|
|
195
|
+
|
|
196
|
+
# Get all ancestor nodes
|
|
197
|
+
placeholders = ','.join('?' * len(path_ids))
|
|
198
|
+
cursor.execute(f'''
|
|
199
|
+
SELECT id, node_type, name, description, parent_id, tree_path,
|
|
200
|
+
depth, memory_count, total_size, last_updated, memory_id
|
|
201
|
+
FROM memory_tree
|
|
202
|
+
WHERE id IN ({placeholders})
|
|
203
|
+
ORDER BY depth
|
|
204
|
+
''', path_ids)
|
|
205
|
+
|
|
206
|
+
results = []
|
|
207
|
+
for row in cursor.fetchall():
|
|
208
|
+
results.append({
|
|
209
|
+
'id': row[0],
|
|
210
|
+
'type': row[1],
|
|
211
|
+
'name': row[2],
|
|
212
|
+
'description': row[3],
|
|
213
|
+
'parent_id': row[4],
|
|
214
|
+
'tree_path': row[5],
|
|
215
|
+
'depth': row[6],
|
|
216
|
+
'memory_count': row[7],
|
|
217
|
+
'total_size': row[8],
|
|
218
|
+
'last_updated': row[9],
|
|
219
|
+
'memory_id': row[10]
|
|
220
|
+
})
|
|
221
|
+
finally:
|
|
186
222
|
conn.close()
|
|
187
|
-
return []
|
|
188
|
-
|
|
189
|
-
tree_path = result[0]
|
|
190
|
-
|
|
191
|
-
# Parse path to get all ancestor IDs
|
|
192
|
-
path_ids = [int(x) for x in tree_path.split('.')]
|
|
193
|
-
|
|
194
|
-
# Get all ancestor nodes
|
|
195
|
-
placeholders = ','.join('?' * len(path_ids))
|
|
196
|
-
cursor.execute(f'''
|
|
197
|
-
SELECT id, node_type, name, description, parent_id, tree_path,
|
|
198
|
-
depth, memory_count, total_size, last_updated, memory_id
|
|
199
|
-
FROM memory_tree
|
|
200
|
-
WHERE id IN ({placeholders})
|
|
201
|
-
ORDER BY depth
|
|
202
|
-
''', path_ids)
|
|
203
|
-
|
|
204
|
-
results = []
|
|
205
|
-
for row in cursor.fetchall():
|
|
206
|
-
results.append({
|
|
207
|
-
'id': row[0],
|
|
208
|
-
'type': row[1],
|
|
209
|
-
'name': row[2],
|
|
210
|
-
'description': row[3],
|
|
211
|
-
'parent_id': row[4],
|
|
212
|
-
'tree_path': row[5],
|
|
213
|
-
'depth': row[6],
|
|
214
|
-
'memory_count': row[7],
|
|
215
|
-
'total_size': row[8],
|
|
216
|
-
'last_updated': row[9],
|
|
217
|
-
'memory_id': row[10]
|
|
218
|
-
})
|
|
219
223
|
|
|
220
|
-
conn.close()
|
|
221
224
|
return results
|
|
222
225
|
|
|
223
226
|
def get_stats(self) -> Dict[str, Any]:
|
|
224
227
|
"""Get tree statistics."""
|
|
225
228
|
conn = sqlite3.connect(self.db_path)
|
|
226
|
-
|
|
229
|
+
try:
|
|
230
|
+
cursor = conn.cursor()
|
|
227
231
|
|
|
228
|
-
|
|
229
|
-
|
|
232
|
+
cursor.execute('SELECT COUNT(*) FROM memory_tree')
|
|
233
|
+
total_nodes = cursor.fetchone()[0]
|
|
230
234
|
|
|
231
|
-
|
|
232
|
-
|
|
235
|
+
cursor.execute('SELECT node_type, COUNT(*) FROM memory_tree GROUP BY node_type')
|
|
236
|
+
by_type = dict(cursor.fetchall())
|
|
233
237
|
|
|
234
|
-
|
|
235
|
-
|
|
238
|
+
cursor.execute('SELECT MAX(depth) FROM memory_tree')
|
|
239
|
+
max_depth = cursor.fetchone()[0] or 0
|
|
236
240
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
241
|
+
cursor.execute('''
|
|
242
|
+
SELECT SUM(memory_count), SUM(total_size)
|
|
243
|
+
FROM memory_tree
|
|
244
|
+
WHERE node_type = 'root'
|
|
245
|
+
''')
|
|
246
|
+
total_memories, total_size = cursor.fetchone()
|
|
243
247
|
|
|
244
|
-
|
|
248
|
+
finally:
|
|
249
|
+
conn.close()
|
|
245
250
|
|
|
246
251
|
return {
|
|
247
252
|
'total_nodes': total_nodes,
|
package/src/tree/schema.py
CHANGED
|
@@ -20,57 +20,61 @@ class TreeSchemaMixin:
|
|
|
20
20
|
def _init_db(self):
|
|
21
21
|
"""Initialize memory_tree table."""
|
|
22
22
|
conn = sqlite3.connect(self.db_path)
|
|
23
|
-
|
|
23
|
+
try:
|
|
24
|
+
cursor = conn.cursor()
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
cursor.execute('''
|
|
27
|
+
CREATE TABLE IF NOT EXISTS memory_tree (
|
|
28
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
29
|
+
node_type TEXT NOT NULL,
|
|
30
|
+
name TEXT NOT NULL,
|
|
31
|
+
description TEXT,
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
parent_id INTEGER,
|
|
34
|
+
tree_path TEXT NOT NULL,
|
|
35
|
+
depth INTEGER DEFAULT 0,
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
memory_count INTEGER DEFAULT 0,
|
|
38
|
+
total_size INTEGER DEFAULT 0,
|
|
39
|
+
last_updated TIMESTAMP,
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
memory_id INTEGER,
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
FOREIGN KEY (parent_id) REFERENCES memory_tree(id) ON DELETE CASCADE,
|
|
44
|
+
FOREIGN KEY (memory_id) REFERENCES memories(id) ON DELETE CASCADE
|
|
45
|
+
)
|
|
46
|
+
''')
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
cursor.execute('CREATE INDEX IF NOT EXISTS idx_tree_path_layer2 ON memory_tree(tree_path)')
|
|
49
|
+
cursor.execute('CREATE INDEX IF NOT EXISTS idx_node_type ON memory_tree(node_type)')
|
|
50
|
+
cursor.execute('CREATE INDEX IF NOT EXISTS idx_parent_id_tree ON memory_tree(parent_id)')
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
conn.commit()
|
|
53
|
+
finally:
|
|
54
|
+
conn.close()
|
|
53
55
|
|
|
54
56
|
def _ensure_root(self) -> int:
|
|
55
57
|
"""Ensure root node exists and return its ID."""
|
|
56
58
|
conn = sqlite3.connect(self.db_path)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
59
|
+
try:
|
|
60
|
+
cursor = conn.cursor()
|
|
61
|
+
|
|
62
|
+
cursor.execute('SELECT id FROM memory_tree WHERE node_type = ? AND parent_id IS NULL', ('root',))
|
|
63
|
+
result = cursor.fetchone()
|
|
64
|
+
|
|
65
|
+
if result:
|
|
66
|
+
root_id = result[0]
|
|
67
|
+
else:
|
|
68
|
+
cursor.execute('''
|
|
69
|
+
INSERT INTO memory_tree (node_type, name, tree_path, depth, last_updated)
|
|
70
|
+
VALUES (?, ?, ?, ?, ?)
|
|
71
|
+
''', ('root', 'Root', '1', 0, datetime.now().isoformat()))
|
|
72
|
+
root_id = cursor.lastrowid
|
|
73
|
+
|
|
74
|
+
# Update tree_path with actual ID
|
|
75
|
+
cursor.execute('UPDATE memory_tree SET tree_path = ? WHERE id = ?', (str(root_id), root_id))
|
|
76
|
+
conn.commit()
|
|
77
|
+
|
|
78
|
+
finally:
|
|
79
|
+
conn.close()
|
|
76
80
|
return root_id
|
|
@@ -73,7 +73,7 @@ class WebhookDispatcher:
|
|
|
73
73
|
return cls._instances[name]
|
|
74
74
|
|
|
75
75
|
@classmethod
|
|
76
|
-
def reset_instance(cls, name: Optional[str] = None):
|
|
76
|
+
def reset_instance(cls, name: Optional[str] = None) -> None:
|
|
77
77
|
"""Remove singleton(s). Used for testing."""
|
|
78
78
|
with cls._instances_lock:
|
|
79
79
|
if name is None:
|
|
@@ -104,7 +104,7 @@ class WebhookDispatcher:
|
|
|
104
104
|
self._worker.start()
|
|
105
105
|
logger.info("WebhookDispatcher started")
|
|
106
106
|
|
|
107
|
-
def dispatch(self, event: dict, webhook_url: str):
|
|
107
|
+
def dispatch(self, event: dict, webhook_url: str) -> None:
|
|
108
108
|
"""
|
|
109
109
|
Enqueue a webhook delivery.
|
|
110
110
|
|
|
@@ -217,7 +217,7 @@ class WebhookDispatcher:
|
|
|
217
217
|
with self._stats_lock:
|
|
218
218
|
return dict(self._stats)
|
|
219
219
|
|
|
220
|
-
def close(self):
|
|
220
|
+
def close(self) -> None:
|
|
221
221
|
"""Shut down the dispatcher. Drains remaining items."""
|
|
222
222
|
if self._closed:
|
|
223
223
|
return
|
package/ui_server.py
CHANGED
|
@@ -33,6 +33,8 @@ except ImportError:
|
|
|
33
33
|
"Install with: pip install 'fastapi[all]' uvicorn websockets"
|
|
34
34
|
)
|
|
35
35
|
|
|
36
|
+
from security_middleware import SecurityHeadersMiddleware
|
|
37
|
+
|
|
36
38
|
# Add src/ and routes/ to path
|
|
37
39
|
sys.path.insert(0, str(Path(__file__).parent / "src"))
|
|
38
40
|
sys.path.insert(0, str(Path(__file__).parent))
|
|
@@ -51,7 +53,9 @@ app = FastAPI(
|
|
|
51
53
|
redoc_url="/api/redoc"
|
|
52
54
|
)
|
|
53
55
|
|
|
54
|
-
# Middleware
|
|
56
|
+
# Middleware (order matters: security headers should be outermost)
|
|
57
|
+
app.add_middleware(SecurityHeadersMiddleware)
|
|
58
|
+
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
|
55
59
|
app.add_middleware(
|
|
56
60
|
CORSMiddleware,
|
|
57
61
|
allow_origins=[
|
|
@@ -61,10 +65,9 @@ app.add_middleware(
|
|
|
61
65
|
"http://127.0.0.1:8417",
|
|
62
66
|
],
|
|
63
67
|
allow_credentials=True,
|
|
64
|
-
allow_methods=["
|
|
65
|
-
allow_headers=["
|
|
68
|
+
allow_methods=["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
|
|
69
|
+
allow_headers=["Content-Type", "Authorization", "X-SLM-API-Key"],
|
|
66
70
|
)
|
|
67
|
-
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
|
68
71
|
|
|
69
72
|
# Rate limiting (v2.6)
|
|
70
73
|
try:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|