import openviking as ov
import os
from datetime import datetime
from pathlib import Path

os.environ['OPENVIKING_CONFIG_FILE'] = 'C:/Users/forsa/Desktop/nyonic/1.conf'

client = ov.OpenViking(path="./data")
# client = ov.SyncHTTPClient(url="http://localhost:1933")  # HTTP mode: connect to OpenViking Server

try:
    client.initialize()

    # Add resource (URL, file, or directory)
    res = client.add_resource(
        path="./diag3",
        preserve_structure = True
    )
    root_uri = res["root_uri"]
    res = client.ls(root_uri)  # Explore resource tree
    print(f"Directory structure:\n{res}\n")

    res = client.glob(pattern="**/*.md", uri=root_uri)  # use glob to find markdown files
    if res["matches"]:
        content = client.read(res["matches"][0])
        print(f"Content preview: {content[:200]}...\n")

    print(" Wait for semantic processing...")
    client.wait_processed()

    abstract = client.abstract(root_uri)  # Get abstract
    overview = client.overview(root_uri)  # Get overview
    print(f"Abstract:\n{abstract}\n\nOverview:\n{overview}\n")

    results = client.find("how to config", target_uri=root_uri)  # Semantic search
    print("Search results:")
    for r in results.resources:
        print(f"  {r.uri} (score: {r.score:.4f})")

    client.close()

except Exception as e:
    print(f"Error: {e}")



# python -m openviking.console.bootstrap --host localhost --port 8000 --openviking-url http://127.0.0.1:1933