cognee cli - add "-ui" flag to start ui server
This commit is contained in:
parent
e91d225cb1
commit
527db2abdf
1 changed files with 68 additions and 0 deletions
|
|
@ -51,6 +51,31 @@ class DebugAction(argparse.Action):
|
|||
fmt.note("Debug mode enabled. Full stack traces will be shown.")
|
||||
|
||||
|
||||
class UiAction(argparse.Action):
|
||||
def __init__(
|
||||
self,
|
||||
option_strings: Sequence[str],
|
||||
dest: Any = argparse.SUPPRESS,
|
||||
default: Any = argparse.SUPPRESS,
|
||||
help: str = None,
|
||||
) -> None:
|
||||
super(UiAction, self).__init__(
|
||||
option_strings=option_strings, dest=dest, default=default, nargs=0, help=help
|
||||
)
|
||||
|
||||
def __call__(
|
||||
self,
|
||||
parser: argparse.ArgumentParser,
|
||||
namespace: argparse.Namespace,
|
||||
values: Any,
|
||||
option_string: str = None,
|
||||
) -> None:
|
||||
# Set a flag to indicate UI should be started
|
||||
global ACTION_EXECUTED
|
||||
ACTION_EXECUTED = True
|
||||
namespace.start_ui = True
|
||||
|
||||
|
||||
# Debug functionality is now in cognee.cli.debug module
|
||||
|
||||
|
||||
|
|
@ -97,6 +122,11 @@ def _create_parser() -> tuple[argparse.ArgumentParser, Dict[str, SupportsCliComm
|
|||
action=DebugAction,
|
||||
help="Enable debug mode to show full stack traces on exceptions",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-ui",
|
||||
action=UiAction,
|
||||
help="Start the cognee web UI interface",
|
||||
)
|
||||
|
||||
subparsers = parser.add_subparsers(title="Available commands", dest="command")
|
||||
|
||||
|
|
@ -140,6 +170,44 @@ def main() -> int:
|
|||
parser, installed_commands = _create_parser()
|
||||
args = parser.parse_args()
|
||||
|
||||
# Handle UI flag
|
||||
if hasattr(args, 'start_ui') and args.start_ui:
|
||||
try:
|
||||
from cognee import start_ui
|
||||
fmt.echo("Starting cognee UI...")
|
||||
server = start_ui(
|
||||
host="localhost",
|
||||
port=3001,
|
||||
open_browser=True
|
||||
)
|
||||
|
||||
if server:
|
||||
fmt.success("UI server started successfully!")
|
||||
fmt.echo("The interface is available at: http://localhost:3001")
|
||||
fmt.note("Press Ctrl+C to stop the server...")
|
||||
|
||||
try:
|
||||
# Keep the server running
|
||||
import time
|
||||
while server.poll() is None: # While process is still running
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
fmt.echo("\nStopping UI server...")
|
||||
server.terminate()
|
||||
server.wait()
|
||||
fmt.success("UI server stopped.")
|
||||
|
||||
return 0
|
||||
else:
|
||||
fmt.error("Failed to start UI server. Check the logs above for details.")
|
||||
return 1
|
||||
|
||||
except Exception as ex:
|
||||
fmt.error(f"Error starting UI: {str(ex)}")
|
||||
if debug.is_debug_enabled():
|
||||
raise ex
|
||||
return 1
|
||||
|
||||
if cmd := installed_commands.get(args.command):
|
||||
try:
|
||||
cmd.execute(args)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue