cognee 0.3.0.dev0__py3-none-any.whl → 0.3.1__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.
- cognee/__init__.py +1 -0
- cognee/api/v1/ui/__init__.py +1 -0
- cognee/api/v1/ui/ui.py +529 -0
- cognee/cli/_cognee.py +93 -0
- {cognee-0.3.0.dev0.dist-info → cognee-0.3.1.dist-info}/METADATA +2 -2
- {cognee-0.3.0.dev0.dist-info → cognee-0.3.1.dist-info}/RECORD +11 -9
- distributed/pyproject.toml +1 -1
- {cognee-0.3.0.dev0.dist-info → cognee-0.3.1.dist-info}/WHEEL +0 -0
- {cognee-0.3.0.dev0.dist-info → cognee-0.3.1.dist-info}/entry_points.txt +0 -0
- {cognee-0.3.0.dev0.dist-info → cognee-0.3.1.dist-info}/licenses/LICENSE +0 -0
- {cognee-0.3.0.dev0.dist-info → cognee-0.3.1.dist-info}/licenses/NOTICE.md +0 -0
cognee/__init__.py
CHANGED
|
@@ -27,6 +27,7 @@ from .api.v1.visualize import visualize_graph, start_visualization_server
|
|
|
27
27
|
from cognee.modules.visualization.cognee_network_visualization import (
|
|
28
28
|
cognee_network_visualization,
|
|
29
29
|
)
|
|
30
|
+
from .api.v1.ui import start_ui
|
|
30
31
|
|
|
31
32
|
# Pipelines
|
|
32
33
|
from .modules import pipelines
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .ui import start_ui, stop_ui, ui
|
cognee/api/v1/ui/ui.py
ADDED
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import signal
|
|
3
|
+
import subprocess
|
|
4
|
+
import threading
|
|
5
|
+
import time
|
|
6
|
+
import webbrowser
|
|
7
|
+
import zipfile
|
|
8
|
+
import requests
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Optional, Tuple
|
|
11
|
+
import tempfile
|
|
12
|
+
import shutil
|
|
13
|
+
|
|
14
|
+
from cognee.shared.logging_utils import get_logger
|
|
15
|
+
from cognee.version import get_cognee_version
|
|
16
|
+
|
|
17
|
+
logger = get_logger()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def normalize_version_for_comparison(version: str) -> str:
|
|
21
|
+
"""
|
|
22
|
+
Normalize version string for comparison.
|
|
23
|
+
Handles development versions and edge cases.
|
|
24
|
+
"""
|
|
25
|
+
# Remove common development suffixes for comparison
|
|
26
|
+
normalized = (
|
|
27
|
+
version.replace("-local", "").replace("-dev", "").replace("-alpha", "").replace("-beta", "")
|
|
28
|
+
)
|
|
29
|
+
return normalized.strip()
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def get_frontend_cache_dir() -> Path:
|
|
33
|
+
"""
|
|
34
|
+
Get the directory where downloaded frontend assets are cached.
|
|
35
|
+
Uses user's home directory to persist across package updates.
|
|
36
|
+
Each cached frontend is version-specific and will be re-downloaded
|
|
37
|
+
when the cognee package version changes.
|
|
38
|
+
"""
|
|
39
|
+
cache_dir = Path.home() / ".cognee" / "ui-cache"
|
|
40
|
+
cache_dir.mkdir(parents=True, exist_ok=True)
|
|
41
|
+
return cache_dir
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def get_frontend_download_info() -> Tuple[str, str]:
|
|
45
|
+
"""
|
|
46
|
+
Get the download URL and version for the actual cognee-frontend source.
|
|
47
|
+
Downloads the real frontend from GitHub releases, matching the installed version.
|
|
48
|
+
"""
|
|
49
|
+
version = get_cognee_version()
|
|
50
|
+
|
|
51
|
+
# Clean up version string (remove -local suffix for development)
|
|
52
|
+
clean_version = version.replace("-local", "")
|
|
53
|
+
|
|
54
|
+
# Download from specific release tag to ensure version compatibility
|
|
55
|
+
download_url = f"https://github.com/topoteretes/cognee/archive/refs/tags/v{clean_version}.zip"
|
|
56
|
+
|
|
57
|
+
return download_url, version
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def download_frontend_assets(force: bool = False) -> bool:
|
|
61
|
+
"""
|
|
62
|
+
Download and cache frontend assets.
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
force: If True, re-download even if already cached
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
bool: True if successful, False otherwise
|
|
69
|
+
"""
|
|
70
|
+
cache_dir = get_frontend_cache_dir()
|
|
71
|
+
frontend_dir = cache_dir / "frontend"
|
|
72
|
+
version_file = cache_dir / "version.txt"
|
|
73
|
+
|
|
74
|
+
# Check if already downloaded and up to date
|
|
75
|
+
if not force and frontend_dir.exists() and version_file.exists():
|
|
76
|
+
try:
|
|
77
|
+
cached_version = version_file.read_text().strip()
|
|
78
|
+
current_version = get_cognee_version()
|
|
79
|
+
|
|
80
|
+
# Compare normalized versions to handle development versions
|
|
81
|
+
cached_normalized = normalize_version_for_comparison(cached_version)
|
|
82
|
+
current_normalized = normalize_version_for_comparison(current_version)
|
|
83
|
+
|
|
84
|
+
if cached_normalized == current_normalized:
|
|
85
|
+
logger.debug(f"Frontend assets already cached for version {current_version}")
|
|
86
|
+
return True
|
|
87
|
+
else:
|
|
88
|
+
logger.info(
|
|
89
|
+
f"Version mismatch detected: cached={cached_version}, current={current_version}"
|
|
90
|
+
)
|
|
91
|
+
logger.info("Updating frontend cache to match current cognee version...")
|
|
92
|
+
# Clear the old cached version
|
|
93
|
+
if frontend_dir.exists():
|
|
94
|
+
shutil.rmtree(frontend_dir)
|
|
95
|
+
if version_file.exists():
|
|
96
|
+
version_file.unlink()
|
|
97
|
+
except Exception as e:
|
|
98
|
+
logger.debug(f"Error checking cached version: {e}")
|
|
99
|
+
# Clear potentially corrupted cache
|
|
100
|
+
if frontend_dir.exists():
|
|
101
|
+
shutil.rmtree(frontend_dir)
|
|
102
|
+
if version_file.exists():
|
|
103
|
+
version_file.unlink()
|
|
104
|
+
|
|
105
|
+
download_url, version = get_frontend_download_info()
|
|
106
|
+
|
|
107
|
+
logger.info(f"Downloading cognee frontend assets for version {version}...")
|
|
108
|
+
logger.info("This will be cached and reused until the cognee version changes.")
|
|
109
|
+
|
|
110
|
+
try:
|
|
111
|
+
# Create a temporary directory for download
|
|
112
|
+
with tempfile.TemporaryDirectory() as temp_dir:
|
|
113
|
+
temp_path = Path(temp_dir)
|
|
114
|
+
archive_path = temp_path / "cognee-main.zip"
|
|
115
|
+
|
|
116
|
+
# Download the actual cognee repository from releases
|
|
117
|
+
logger.info(
|
|
118
|
+
f"Downloading cognee v{version.replace('-local', '')} from GitHub releases..."
|
|
119
|
+
)
|
|
120
|
+
logger.info(f"URL: {download_url}")
|
|
121
|
+
response = requests.get(download_url, stream=True, timeout=60)
|
|
122
|
+
response.raise_for_status()
|
|
123
|
+
|
|
124
|
+
with open(archive_path, "wb") as f:
|
|
125
|
+
for chunk in response.iter_content(chunk_size=8192):
|
|
126
|
+
f.write(chunk)
|
|
127
|
+
|
|
128
|
+
# Extract the archive and find the cognee-frontend directory
|
|
129
|
+
if frontend_dir.exists():
|
|
130
|
+
shutil.rmtree(frontend_dir)
|
|
131
|
+
|
|
132
|
+
with zipfile.ZipFile(archive_path, "r") as zip_file:
|
|
133
|
+
# Extract to temp directory first
|
|
134
|
+
extract_dir = temp_path / "extracted"
|
|
135
|
+
zip_file.extractall(extract_dir)
|
|
136
|
+
|
|
137
|
+
# Find the cognee-frontend directory in the extracted content
|
|
138
|
+
# The archive structure will be: cognee-{version}/cognee-frontend/
|
|
139
|
+
cognee_frontend_source = None
|
|
140
|
+
for root, dirs, files in os.walk(extract_dir):
|
|
141
|
+
if "cognee-frontend" in dirs:
|
|
142
|
+
cognee_frontend_source = Path(root) / "cognee-frontend"
|
|
143
|
+
break
|
|
144
|
+
|
|
145
|
+
if not cognee_frontend_source or not cognee_frontend_source.exists():
|
|
146
|
+
logger.error(
|
|
147
|
+
"Could not find cognee-frontend directory in downloaded release archive"
|
|
148
|
+
)
|
|
149
|
+
logger.error("This might indicate a version mismatch or missing release.")
|
|
150
|
+
return False
|
|
151
|
+
|
|
152
|
+
# Copy the cognee-frontend to our cache
|
|
153
|
+
shutil.copytree(cognee_frontend_source, frontend_dir)
|
|
154
|
+
logger.debug(f"Frontend extracted to: {frontend_dir}")
|
|
155
|
+
|
|
156
|
+
# Write version info for future cache validation
|
|
157
|
+
version_file.write_text(version)
|
|
158
|
+
logger.debug(f"Cached frontend for cognee version: {version}")
|
|
159
|
+
|
|
160
|
+
logger.info(
|
|
161
|
+
f"✓ Cognee frontend v{version.replace('-local', '')} downloaded and cached successfully!"
|
|
162
|
+
)
|
|
163
|
+
return True
|
|
164
|
+
|
|
165
|
+
except requests.exceptions.RequestException as e:
|
|
166
|
+
if "404" in str(e):
|
|
167
|
+
logger.error(f"Release v{version.replace('-local', '')} not found on GitHub.")
|
|
168
|
+
logger.error(
|
|
169
|
+
"This version might not have been released yet, or you're using a development version."
|
|
170
|
+
)
|
|
171
|
+
logger.error("Try using a stable release version of cognee.")
|
|
172
|
+
else:
|
|
173
|
+
logger.error(f"Failed to download from GitHub: {str(e)}")
|
|
174
|
+
logger.error("You can still use cognee without the UI functionality.")
|
|
175
|
+
return False
|
|
176
|
+
except Exception as e:
|
|
177
|
+
logger.error(f"Failed to download frontend assets: {str(e)}")
|
|
178
|
+
logger.error("You can still use cognee without the UI functionality.")
|
|
179
|
+
return False
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def find_frontend_path() -> Optional[Path]:
|
|
183
|
+
"""
|
|
184
|
+
Find the cognee-frontend directory.
|
|
185
|
+
Checks both development location and cached download location.
|
|
186
|
+
"""
|
|
187
|
+
current_file = Path(__file__)
|
|
188
|
+
|
|
189
|
+
# First, try development paths (for contributors/developers)
|
|
190
|
+
dev_search_paths = [
|
|
191
|
+
current_file.parents[4] / "cognee-frontend", # from cognee/api/v1/ui/ui.py to project root
|
|
192
|
+
current_file.parents[3] / "cognee-frontend", # fallback path
|
|
193
|
+
current_file.parents[2] / "cognee-frontend", # another fallback
|
|
194
|
+
]
|
|
195
|
+
|
|
196
|
+
for path in dev_search_paths:
|
|
197
|
+
if path.exists() and (path / "package.json").exists():
|
|
198
|
+
logger.debug(f"Found development frontend at: {path}")
|
|
199
|
+
return path
|
|
200
|
+
|
|
201
|
+
# Then try cached download location (for pip-installed users)
|
|
202
|
+
cache_dir = get_frontend_cache_dir()
|
|
203
|
+
cached_frontend = cache_dir / "frontend"
|
|
204
|
+
|
|
205
|
+
if cached_frontend.exists() and (cached_frontend / "package.json").exists():
|
|
206
|
+
logger.debug(f"Found cached frontend at: {cached_frontend}")
|
|
207
|
+
return cached_frontend
|
|
208
|
+
|
|
209
|
+
return None
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def check_node_npm() -> tuple[bool, str]:
|
|
213
|
+
"""
|
|
214
|
+
Check if Node.js and npm are available.
|
|
215
|
+
Returns (is_available, error_message)
|
|
216
|
+
"""
|
|
217
|
+
try:
|
|
218
|
+
# Check Node.js
|
|
219
|
+
result = subprocess.run(["node", "--version"], capture_output=True, text=True, timeout=10)
|
|
220
|
+
if result.returncode != 0:
|
|
221
|
+
return False, "Node.js is not installed or not in PATH"
|
|
222
|
+
|
|
223
|
+
node_version = result.stdout.strip()
|
|
224
|
+
logger.debug(f"Found Node.js version: {node_version}")
|
|
225
|
+
|
|
226
|
+
# Check npm
|
|
227
|
+
result = subprocess.run(["npm", "--version"], capture_output=True, text=True, timeout=10)
|
|
228
|
+
if result.returncode != 0:
|
|
229
|
+
return False, "npm is not installed or not in PATH"
|
|
230
|
+
|
|
231
|
+
npm_version = result.stdout.strip()
|
|
232
|
+
logger.debug(f"Found npm version: {npm_version}")
|
|
233
|
+
|
|
234
|
+
return True, f"Node.js {node_version}, npm {npm_version}"
|
|
235
|
+
|
|
236
|
+
except subprocess.TimeoutExpired:
|
|
237
|
+
return False, "Timeout checking Node.js/npm installation"
|
|
238
|
+
except FileNotFoundError:
|
|
239
|
+
return False, "Node.js/npm not found. Please install Node.js from https://nodejs.org/"
|
|
240
|
+
except Exception as e:
|
|
241
|
+
return False, f"Error checking Node.js/npm: {str(e)}"
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def install_frontend_dependencies(frontend_path: Path) -> bool:
|
|
245
|
+
"""
|
|
246
|
+
Install frontend dependencies if node_modules doesn't exist.
|
|
247
|
+
This is needed for both development and downloaded frontends since both use npm run dev.
|
|
248
|
+
"""
|
|
249
|
+
node_modules = frontend_path / "node_modules"
|
|
250
|
+
if node_modules.exists():
|
|
251
|
+
logger.debug("Frontend dependencies already installed")
|
|
252
|
+
return True
|
|
253
|
+
|
|
254
|
+
logger.info("Installing frontend dependencies (this may take a few minutes)...")
|
|
255
|
+
|
|
256
|
+
try:
|
|
257
|
+
result = subprocess.run(
|
|
258
|
+
["npm", "install"],
|
|
259
|
+
cwd=frontend_path,
|
|
260
|
+
capture_output=True,
|
|
261
|
+
text=True,
|
|
262
|
+
timeout=300, # 5 minutes timeout
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
if result.returncode == 0:
|
|
266
|
+
logger.info("Frontend dependencies installed successfully")
|
|
267
|
+
return True
|
|
268
|
+
else:
|
|
269
|
+
logger.error(f"Failed to install dependencies: {result.stderr}")
|
|
270
|
+
return False
|
|
271
|
+
|
|
272
|
+
except subprocess.TimeoutExpired:
|
|
273
|
+
logger.error("Timeout installing frontend dependencies")
|
|
274
|
+
return False
|
|
275
|
+
except Exception as e:
|
|
276
|
+
logger.error(f"Error installing frontend dependencies: {str(e)}")
|
|
277
|
+
return False
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def is_development_frontend(frontend_path: Path) -> bool:
|
|
281
|
+
"""
|
|
282
|
+
Check if this is a development frontend (has Next.js) vs downloaded assets.
|
|
283
|
+
"""
|
|
284
|
+
package_json_path = frontend_path / "package.json"
|
|
285
|
+
if not package_json_path.exists():
|
|
286
|
+
return False
|
|
287
|
+
|
|
288
|
+
try:
|
|
289
|
+
import json
|
|
290
|
+
|
|
291
|
+
with open(package_json_path) as f:
|
|
292
|
+
package_data = json.load(f)
|
|
293
|
+
|
|
294
|
+
# Development frontend has Next.js as dependency
|
|
295
|
+
dependencies = package_data.get("dependencies", {})
|
|
296
|
+
dev_dependencies = package_data.get("devDependencies", {})
|
|
297
|
+
|
|
298
|
+
return "next" in dependencies or "next" in dev_dependencies
|
|
299
|
+
except Exception:
|
|
300
|
+
return False
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
def prompt_user_for_download() -> bool:
|
|
304
|
+
"""
|
|
305
|
+
Ask user if they want to download the frontend assets.
|
|
306
|
+
Returns True if user consents, False otherwise.
|
|
307
|
+
"""
|
|
308
|
+
try:
|
|
309
|
+
print("\n" + "=" * 60)
|
|
310
|
+
print("🎨 Cognee UI Setup Required")
|
|
311
|
+
print("=" * 60)
|
|
312
|
+
print("The cognee frontend is not available on your system.")
|
|
313
|
+
print("This is required to use the web interface.")
|
|
314
|
+
print("\nWhat will happen:")
|
|
315
|
+
print("• Download the actual cognee-frontend from GitHub")
|
|
316
|
+
print("• Cache it in your home directory (~/.cognee/ui-cache/)")
|
|
317
|
+
print("• Install dependencies with npm (requires Node.js)")
|
|
318
|
+
print("• This is a one-time setup per cognee version")
|
|
319
|
+
print("\nThe frontend will then be available offline for future use.")
|
|
320
|
+
|
|
321
|
+
response = input("\nWould you like to download the frontend now? (y/N): ").strip().lower()
|
|
322
|
+
return response in ["y", "yes"]
|
|
323
|
+
except (KeyboardInterrupt, EOFError):
|
|
324
|
+
print("\nOperation cancelled by user.")
|
|
325
|
+
return False
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
def start_ui(
|
|
329
|
+
host: str = "localhost",
|
|
330
|
+
port: int = 3000,
|
|
331
|
+
open_browser: bool = True,
|
|
332
|
+
auto_download: bool = False,
|
|
333
|
+
) -> Optional[subprocess.Popen]:
|
|
334
|
+
"""
|
|
335
|
+
Start the cognee frontend UI server.
|
|
336
|
+
|
|
337
|
+
This function will:
|
|
338
|
+
1. Find the cognee-frontend directory (development) or download it (pip install)
|
|
339
|
+
2. Check if Node.js and npm are available (for development mode)
|
|
340
|
+
3. Install dependencies if needed (development mode)
|
|
341
|
+
4. Start the appropriate server
|
|
342
|
+
5. Optionally open the browser
|
|
343
|
+
|
|
344
|
+
Args:
|
|
345
|
+
host: Host to bind the server to (default: localhost)
|
|
346
|
+
port: Port to run the server on (default: 3000)
|
|
347
|
+
open_browser: Whether to open the browser automatically (default: True)
|
|
348
|
+
auto_download: If True, download frontend without prompting (default: False)
|
|
349
|
+
|
|
350
|
+
Returns:
|
|
351
|
+
subprocess.Popen object representing the running server, or None if failed
|
|
352
|
+
|
|
353
|
+
Example:
|
|
354
|
+
>>> import cognee
|
|
355
|
+
>>> server = cognee.start_ui()
|
|
356
|
+
>>> # UI will be available at http://localhost:3000
|
|
357
|
+
>>> # To stop the server later:
|
|
358
|
+
>>> server.terminate()
|
|
359
|
+
"""
|
|
360
|
+
logger.info("Starting cognee UI...")
|
|
361
|
+
|
|
362
|
+
# Find frontend directory
|
|
363
|
+
frontend_path = find_frontend_path()
|
|
364
|
+
|
|
365
|
+
if not frontend_path:
|
|
366
|
+
logger.info("Frontend not found locally. This is normal for pip-installed cognee.")
|
|
367
|
+
|
|
368
|
+
# Offer to download the frontend
|
|
369
|
+
if auto_download or prompt_user_for_download():
|
|
370
|
+
if download_frontend_assets():
|
|
371
|
+
frontend_path = find_frontend_path()
|
|
372
|
+
if not frontend_path:
|
|
373
|
+
logger.error(
|
|
374
|
+
"Download succeeded but frontend still not found. This is unexpected."
|
|
375
|
+
)
|
|
376
|
+
return None
|
|
377
|
+
else:
|
|
378
|
+
logger.error("Failed to download frontend assets.")
|
|
379
|
+
return None
|
|
380
|
+
else:
|
|
381
|
+
logger.info("Frontend download declined. UI functionality not available.")
|
|
382
|
+
logger.info("You can still use all other cognee features without the web interface.")
|
|
383
|
+
return None
|
|
384
|
+
|
|
385
|
+
# Check Node.js and npm
|
|
386
|
+
node_available, node_message = check_node_npm()
|
|
387
|
+
if not node_available:
|
|
388
|
+
logger.error(f"Cannot start UI: {node_message}")
|
|
389
|
+
logger.error("Please install Node.js from https://nodejs.org/ to use the UI functionality")
|
|
390
|
+
return None
|
|
391
|
+
|
|
392
|
+
logger.debug(f"Environment check passed: {node_message}")
|
|
393
|
+
|
|
394
|
+
# Install dependencies if needed
|
|
395
|
+
if not install_frontend_dependencies(frontend_path):
|
|
396
|
+
logger.error("Failed to install frontend dependencies")
|
|
397
|
+
return None
|
|
398
|
+
|
|
399
|
+
# Prepare environment variables
|
|
400
|
+
env = os.environ.copy()
|
|
401
|
+
env["HOST"] = host
|
|
402
|
+
env["PORT"] = str(port)
|
|
403
|
+
|
|
404
|
+
# Start the development server
|
|
405
|
+
logger.info(f"Starting frontend server at http://{host}:{port}")
|
|
406
|
+
logger.info("This may take a moment to compile and start...")
|
|
407
|
+
|
|
408
|
+
try:
|
|
409
|
+
# Use process group to ensure all child processes get terminated together
|
|
410
|
+
process = subprocess.Popen(
|
|
411
|
+
["npm", "run", "dev"],
|
|
412
|
+
cwd=frontend_path,
|
|
413
|
+
env=env,
|
|
414
|
+
stdout=subprocess.PIPE,
|
|
415
|
+
stderr=subprocess.PIPE,
|
|
416
|
+
text=True,
|
|
417
|
+
preexec_fn=os.setsid
|
|
418
|
+
if hasattr(os, "setsid")
|
|
419
|
+
else None, # Create new process group on Unix
|
|
420
|
+
)
|
|
421
|
+
|
|
422
|
+
# Give it a moment to start up
|
|
423
|
+
time.sleep(3)
|
|
424
|
+
|
|
425
|
+
# Check if process is still running
|
|
426
|
+
if process.poll() is not None:
|
|
427
|
+
stdout, stderr = process.communicate()
|
|
428
|
+
logger.error("Frontend server failed to start:")
|
|
429
|
+
logger.error(f"stdout: {stdout}")
|
|
430
|
+
logger.error(f"stderr: {stderr}")
|
|
431
|
+
return None
|
|
432
|
+
|
|
433
|
+
# Open browser if requested
|
|
434
|
+
if open_browser:
|
|
435
|
+
|
|
436
|
+
def open_browser_delayed():
|
|
437
|
+
time.sleep(5) # Give Next.js time to fully start
|
|
438
|
+
try:
|
|
439
|
+
webbrowser.open(f"http://{host}:{port}") # TODO: use dashboard url?
|
|
440
|
+
except Exception as e:
|
|
441
|
+
logger.warning(f"Could not open browser automatically: {e}")
|
|
442
|
+
|
|
443
|
+
browser_thread = threading.Thread(target=open_browser_delayed, daemon=True)
|
|
444
|
+
browser_thread.start()
|
|
445
|
+
|
|
446
|
+
logger.info("✓ Cognee UI is starting up...")
|
|
447
|
+
logger.info(f"✓ Open your browser to: http://{host}:{port}")
|
|
448
|
+
logger.info("✓ The UI will be available once Next.js finishes compiling")
|
|
449
|
+
|
|
450
|
+
return process
|
|
451
|
+
|
|
452
|
+
except Exception as e:
|
|
453
|
+
logger.error(f"Failed to start frontend server: {str(e)}")
|
|
454
|
+
return None
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
def stop_ui(process: subprocess.Popen) -> bool:
|
|
458
|
+
"""
|
|
459
|
+
Stop a running UI server process and all its children.
|
|
460
|
+
|
|
461
|
+
Args:
|
|
462
|
+
process: The subprocess.Popen object returned by start_ui()
|
|
463
|
+
|
|
464
|
+
Returns:
|
|
465
|
+
bool: True if stopped successfully, False otherwise
|
|
466
|
+
"""
|
|
467
|
+
if not process:
|
|
468
|
+
return False
|
|
469
|
+
|
|
470
|
+
try:
|
|
471
|
+
# Try to terminate the process group (includes child processes like Next.js)
|
|
472
|
+
if hasattr(os, "killpg"):
|
|
473
|
+
try:
|
|
474
|
+
# Kill the entire process group
|
|
475
|
+
os.killpg(os.getpgid(process.pid), signal.SIGTERM)
|
|
476
|
+
logger.debug("Sent SIGTERM to process group")
|
|
477
|
+
except (OSError, ProcessLookupError):
|
|
478
|
+
# Fall back to terminating just the main process
|
|
479
|
+
process.terminate()
|
|
480
|
+
logger.debug("Terminated main process only")
|
|
481
|
+
else:
|
|
482
|
+
process.terminate()
|
|
483
|
+
logger.debug("Terminated main process (Windows)")
|
|
484
|
+
|
|
485
|
+
try:
|
|
486
|
+
process.wait(timeout=10)
|
|
487
|
+
logger.info("UI server stopped gracefully")
|
|
488
|
+
except subprocess.TimeoutExpired:
|
|
489
|
+
logger.warning("Process didn't terminate gracefully, forcing kill")
|
|
490
|
+
|
|
491
|
+
# Force kill the process group
|
|
492
|
+
if hasattr(os, "killpg"):
|
|
493
|
+
try:
|
|
494
|
+
os.killpg(os.getpgid(process.pid), signal.SIGKILL)
|
|
495
|
+
logger.debug("Sent SIGKILL to process group")
|
|
496
|
+
except (OSError, ProcessLookupError):
|
|
497
|
+
process.kill()
|
|
498
|
+
logger.debug("Force killed main process only")
|
|
499
|
+
else:
|
|
500
|
+
process.kill()
|
|
501
|
+
logger.debug("Force killed main process (Windows)")
|
|
502
|
+
|
|
503
|
+
process.wait()
|
|
504
|
+
|
|
505
|
+
logger.info("UI server stopped")
|
|
506
|
+
return True
|
|
507
|
+
|
|
508
|
+
except Exception as e:
|
|
509
|
+
logger.error(f"Error stopping UI server: {str(e)}")
|
|
510
|
+
return False
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
# Convenience function similar to DuckDB's approach
|
|
514
|
+
def ui() -> Optional[subprocess.Popen]:
|
|
515
|
+
"""
|
|
516
|
+
Convenient alias for start_ui() with default parameters.
|
|
517
|
+
Similar to how DuckDB provides simple ui() function.
|
|
518
|
+
"""
|
|
519
|
+
return start_ui()
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
if __name__ == "__main__":
|
|
523
|
+
# Test the UI startup
|
|
524
|
+
server = start_ui()
|
|
525
|
+
if server:
|
|
526
|
+
try:
|
|
527
|
+
input("Press Enter to stop the server...")
|
|
528
|
+
finally:
|
|
529
|
+
stop_ui(server)
|
cognee/cli/_cognee.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import sys
|
|
2
2
|
import os
|
|
3
3
|
import argparse
|
|
4
|
+
import signal
|
|
5
|
+
import subprocess
|
|
4
6
|
from typing import Any, Sequence, Dict, Type, cast, List
|
|
5
7
|
import click
|
|
6
8
|
|
|
@@ -51,6 +53,31 @@ class DebugAction(argparse.Action):
|
|
|
51
53
|
fmt.note("Debug mode enabled. Full stack traces will be shown.")
|
|
52
54
|
|
|
53
55
|
|
|
56
|
+
class UiAction(argparse.Action):
|
|
57
|
+
def __init__(
|
|
58
|
+
self,
|
|
59
|
+
option_strings: Sequence[str],
|
|
60
|
+
dest: Any = argparse.SUPPRESS,
|
|
61
|
+
default: Any = argparse.SUPPRESS,
|
|
62
|
+
help: str = None,
|
|
63
|
+
) -> None:
|
|
64
|
+
super(UiAction, self).__init__(
|
|
65
|
+
option_strings=option_strings, dest=dest, default=default, nargs=0, help=help
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
def __call__(
|
|
69
|
+
self,
|
|
70
|
+
parser: argparse.ArgumentParser,
|
|
71
|
+
namespace: argparse.Namespace,
|
|
72
|
+
values: Any,
|
|
73
|
+
option_string: str = None,
|
|
74
|
+
) -> None:
|
|
75
|
+
# Set a flag to indicate UI should be started
|
|
76
|
+
global ACTION_EXECUTED
|
|
77
|
+
ACTION_EXECUTED = True
|
|
78
|
+
namespace.start_ui = True
|
|
79
|
+
|
|
80
|
+
|
|
54
81
|
# Debug functionality is now in cognee.cli.debug module
|
|
55
82
|
|
|
56
83
|
|
|
@@ -97,6 +124,11 @@ def _create_parser() -> tuple[argparse.ArgumentParser, Dict[str, SupportsCliComm
|
|
|
97
124
|
action=DebugAction,
|
|
98
125
|
help="Enable debug mode to show full stack traces on exceptions",
|
|
99
126
|
)
|
|
127
|
+
parser.add_argument(
|
|
128
|
+
"-ui",
|
|
129
|
+
action=UiAction,
|
|
130
|
+
help="Start the cognee web UI interface",
|
|
131
|
+
)
|
|
100
132
|
|
|
101
133
|
subparsers = parser.add_subparsers(title="Available commands", dest="command")
|
|
102
134
|
|
|
@@ -140,6 +172,67 @@ def main() -> int:
|
|
|
140
172
|
parser, installed_commands = _create_parser()
|
|
141
173
|
args = parser.parse_args()
|
|
142
174
|
|
|
175
|
+
# Handle UI flag
|
|
176
|
+
if hasattr(args, "start_ui") and args.start_ui:
|
|
177
|
+
server_process = None
|
|
178
|
+
|
|
179
|
+
def signal_handler(signum, frame):
|
|
180
|
+
"""Handle Ctrl+C and other termination signals"""
|
|
181
|
+
nonlocal server_process
|
|
182
|
+
fmt.echo("\nShutting down UI server...")
|
|
183
|
+
if server_process:
|
|
184
|
+
try:
|
|
185
|
+
# Try graceful termination first
|
|
186
|
+
server_process.terminate()
|
|
187
|
+
try:
|
|
188
|
+
server_process.wait(timeout=5)
|
|
189
|
+
fmt.success("UI server stopped gracefully.")
|
|
190
|
+
except subprocess.TimeoutExpired:
|
|
191
|
+
# If graceful termination fails, force kill
|
|
192
|
+
fmt.echo("Force stopping UI server...")
|
|
193
|
+
server_process.kill()
|
|
194
|
+
server_process.wait()
|
|
195
|
+
fmt.success("UI server stopped.")
|
|
196
|
+
except Exception as e:
|
|
197
|
+
fmt.warning(f"Error stopping server: {e}")
|
|
198
|
+
sys.exit(0)
|
|
199
|
+
|
|
200
|
+
# Set up signal handlers
|
|
201
|
+
signal.signal(signal.SIGINT, signal_handler) # Ctrl+C
|
|
202
|
+
signal.signal(signal.SIGTERM, signal_handler) # Termination request
|
|
203
|
+
|
|
204
|
+
try:
|
|
205
|
+
from cognee import start_ui
|
|
206
|
+
|
|
207
|
+
fmt.echo("Starting cognee UI...")
|
|
208
|
+
server_process = start_ui(host="localhost", port=3000, open_browser=True)
|
|
209
|
+
|
|
210
|
+
if server_process:
|
|
211
|
+
fmt.success("UI server started successfully!")
|
|
212
|
+
fmt.echo("The interface is available at: http://localhost:3000")
|
|
213
|
+
fmt.note("Press Ctrl+C to stop the server...")
|
|
214
|
+
|
|
215
|
+
try:
|
|
216
|
+
# Keep the server running
|
|
217
|
+
import time
|
|
218
|
+
|
|
219
|
+
while server_process.poll() is None: # While process is still running
|
|
220
|
+
time.sleep(1)
|
|
221
|
+
except KeyboardInterrupt:
|
|
222
|
+
# This shouldn't happen now due to signal handler, but kept for safety
|
|
223
|
+
signal_handler(signal.SIGINT, None)
|
|
224
|
+
|
|
225
|
+
return 0
|
|
226
|
+
else:
|
|
227
|
+
fmt.error("Failed to start UI server. Check the logs above for details.")
|
|
228
|
+
return 1
|
|
229
|
+
|
|
230
|
+
except Exception as ex:
|
|
231
|
+
fmt.error(f"Error starting UI: {str(ex)}")
|
|
232
|
+
if debug.is_debug_enabled():
|
|
233
|
+
raise ex
|
|
234
|
+
return 1
|
|
235
|
+
|
|
143
236
|
if cmd := installed_commands.get(args.command):
|
|
144
237
|
try:
|
|
145
238
|
cmd.execute(args)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cognee
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: Cognee - is a library for enriching LLM context with a semantic layer for better understanding and reasoning.
|
|
5
5
|
Project-URL: Homepage, https://www.cognee.ai
|
|
6
6
|
Project-URL: Repository, https://github.com/topoteretes/cognee
|
|
@@ -44,7 +44,7 @@ Requires-Dist: pydantic-settings<3,>=2.2.1
|
|
|
44
44
|
Requires-Dist: pydantic<3.0.0,>=2.10.5
|
|
45
45
|
Requires-Dist: pylance<1.0.0,>=0.22.0
|
|
46
46
|
Requires-Dist: pympler<2.0.0,>=1.1
|
|
47
|
-
Requires-Dist: pypdf<
|
|
47
|
+
Requires-Dist: pypdf<7.0.0,>=4.1.0
|
|
48
48
|
Requires-Dist: python-dotenv<2.0.0,>=1.0.1
|
|
49
49
|
Requires-Dist: python-magic-bin<0.5; platform_system == 'Windows'
|
|
50
50
|
Requires-Dist: python-multipart<1.0.0,>=0.0.20
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
cognee/__init__.py,sha256=
|
|
1
|
+
cognee/__init__.py,sha256=0KblJJ9tZI6zlsojrK9w-075uDGjDjbCGnB9tt5J0pY,1068
|
|
2
2
|
cognee/__main__.py,sha256=UDwkdKir_2m9z3DtOlWKc5wdBk_8AXGyu9k6PufY9Jg,75
|
|
3
3
|
cognee/base_config.py,sha256=safPCD_1LISzfiIl3i5TG46pXqhUgESwI0-03vPYrok,1540
|
|
4
4
|
cognee/context_global_variables.py,sha256=X0PDjVwwB8qaDTGtdjHRzKvUo9fv4ygmxLz6g0FM9bc,2679
|
|
@@ -63,6 +63,8 @@ cognee/api/v1/sync/__init__.py,sha256=hx2Af6GtX8soyHiYpWieWpAglLD05_7BK7PgdBqGbV
|
|
|
63
63
|
cognee/api/v1/sync/sync.py,sha256=zzCVJD1AvcSXtNsgLJr1iPMRxY6vRxGdkt7sVdJ8W2c,33905
|
|
64
64
|
cognee/api/v1/sync/routers/__init__.py,sha256=hZArat9DDyzBll8qej0_o16QhtQRciTB37b5rc3ckGM,76
|
|
65
65
|
cognee/api/v1/sync/routers/get_sync_router.py,sha256=7fD0QL0IIjyg9VBadNcLD7G7rypy_1glyWv8HVHBrao,9703
|
|
66
|
+
cognee/api/v1/ui/__init__.py,sha256=SKfmAWokGT3_ZGqDkEtQihrvXCog6WTP3UdZrD20DBc,38
|
|
67
|
+
cognee/api/v1/ui/ui.py,sha256=AgH7js_34rjW7Z_19Xv-oKBA1TBH5-t2beVtIzoAMAY,19215
|
|
66
68
|
cognee/api/v1/users/__init__.py,sha256=TMOZ_3puQxVqVIjWNA0yb16Tpp8yoNKAfwxIxoFpgus,37
|
|
67
69
|
cognee/api/v1/users/create_user.py,sha256=PRuc7aUhOpyb-g5nUGDKSegp3cxkZy5TDeX1sxX6jjM,324
|
|
68
70
|
cognee/api/v1/users/routers/__init__.py,sha256=_m3tyK2deFQCBjx6p-0t23e7qnnhAyx-2PBM7Wc6E7A,314
|
|
@@ -76,7 +78,7 @@ cognee/api/v1/visualize/__init__.py,sha256=TBk58R8cza6Qx7IP2r9RvAtE8Fmoo9vOh9VjC
|
|
|
76
78
|
cognee/api/v1/visualize/start_visualization_server.py,sha256=3esCKYYmBx9Sb2H5JWrliT47qNyt_rGrv1OvR0LJVAg,440
|
|
77
79
|
cognee/api/v1/visualize/visualize.py,sha256=xKhh1N-doIgFcnq9Tz1acwrS4fOqBFZlgif4prMBqP4,1077
|
|
78
80
|
cognee/cli/__init__.py,sha256=MaKUkdFaETdbuMFoV02V8BZNuYr7tZQJKt6y25CaUhk,243
|
|
79
|
-
cognee/cli/_cognee.py,sha256=
|
|
81
|
+
cognee/cli/_cognee.py,sha256=iupokPsdRXVQYzcUBzt-GDmn_E-Ts6enoCAhm89lNCY,8739
|
|
80
82
|
cognee/cli/config.py,sha256=8XhUqpkmNNzCFbnIpRvNQIO2Hvw0OD44zWYM0eADozA,998
|
|
81
83
|
cognee/cli/debug.py,sha256=-u3REG2xloCFLwOWQ3wVM7RpZRn06QlnfDyCRoxrrek,444
|
|
82
84
|
cognee/cli/echo.py,sha256=3G4qYcYn1cShTeIKaZMPD_TgoS7LBqyUnMnTFaj5dUE,1128
|
|
@@ -876,7 +878,7 @@ distributed/entrypoint.py,sha256=tLF8eEfW5oG6obyzBGhJsqy9SXm6xfr5HYU45sMtQEw,222
|
|
|
876
878
|
distributed/entrypoint.sh,sha256=6j9Lu_6sxws7E-XGOdtfMWmdm8D3awjtGblB0JsL1I0,94
|
|
877
879
|
distributed/modal_image.py,sha256=TSS0mF8-bjTiMHzyQu2xgq3AX74MRnJKyDgFroHvwiQ,320
|
|
878
880
|
distributed/poetry.lock,sha256=KcXMRPszF6A1SKWSqp1Kwg0CFuq4yJ7nn3TUWJ8LNrA,952845
|
|
879
|
-
distributed/pyproject.toml,sha256=
|
|
881
|
+
distributed/pyproject.toml,sha256=iUB51g4ujtz8ACWY8MVkom91PWng8a8vDpuvA96EnkA,4990
|
|
880
882
|
distributed/queues.py,sha256=FF2nyfu1rsDTNKEEC2IAn_A0sULudt4JFxdffSyRPb0,212
|
|
881
883
|
distributed/test.py,sha256=NftfFht_2TP898KwdyJNE6FRYeaDGt4l_74KPVVsGJc,552
|
|
882
884
|
distributed/utils.py,sha256=rW2s7xkMPbh6IANFRVaXPI1pJf9SKRufUw4SfIFIFME,586
|
|
@@ -886,9 +888,9 @@ distributed/tasks/queued_add_edges.py,sha256=kz1DHE05y-kNHORQJjYWHUi6Q1QWUp_v3Dl
|
|
|
886
888
|
distributed/tasks/queued_add_nodes.py,sha256=aqK4Ij--ADwUWknxYpiwbYrpa6CcvFfqHWbUZW4Kh3A,452
|
|
887
889
|
distributed/workers/data_point_saving_worker.py,sha256=jFmA0-P_0Ru2IUDrSug0wML-5goAKrGtlBm5BA5Ryw4,3229
|
|
888
890
|
distributed/workers/graph_saving_worker.py,sha256=oUYl99CdhlrPAIsUOHbHnS3d4XhGoV0_OIbCO8wYzRg,3648
|
|
889
|
-
cognee-0.3.
|
|
890
|
-
cognee-0.3.
|
|
891
|
-
cognee-0.3.
|
|
892
|
-
cognee-0.3.
|
|
893
|
-
cognee-0.3.
|
|
894
|
-
cognee-0.3.
|
|
891
|
+
cognee-0.3.1.dist-info/METADATA,sha256=FiH8UcAy24p0Fj79WChu6lznpJ4Ikn2Wa7RXn4yK7SQ,14753
|
|
892
|
+
cognee-0.3.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
893
|
+
cognee-0.3.1.dist-info/entry_points.txt,sha256=4Fe5PRV0e3j5MFUo7kYyRFa3MhMNbOu69pGBazTxPps,51
|
|
894
|
+
cognee-0.3.1.dist-info/licenses/LICENSE,sha256=pHHjSQj1DD8SDppW88MMs04TPk7eAanL1c5xj8NY7NQ,11344
|
|
895
|
+
cognee-0.3.1.dist-info/licenses/NOTICE.md,sha256=6L3saP3kSpcingOxDh-SGjMS8GY79Rlh2dBNLaO0o5c,339
|
|
896
|
+
cognee-0.3.1.dist-info/RECORD,,
|
distributed/pyproject.toml
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|