Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Python
__pycache__/
*.py[cod]
*.egg-info/
build/
dist/
.venv/
venv/
.pytest_cache/

# Local data / secrets
*.sqlite
*.sqlite-journal
.env
*.key
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dynamic = ["version"]
description = "Desktop GUI for visualizing and managing agent requests"
readme = "README.md"
requires-python = ">=3.10"
licese = {text = "GPLv3"}
license = {text = "GPLv3"}
dependencies = [
"PyQt6>=6.4.0",
"httpx>=0.24.0",
Expand Down
70 changes: 60 additions & 10 deletions src/request_visualization/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,25 @@
DEFAULT_API_KEY_FILE = Path.home() / ".claude" / "azure.key"
DEFAULT_EMBEDDING_MODEL = "text-embedding-3-small"

# Valid request statuses
VALID_STATUSES = ("pending", "approved", "rejected", "implemented", "completed", "cancelled")

# Inactive statuses (requests that don't need attention)
INACTIVE_STATUSES = ("completed", "rejected", "cancelled")
# Valid request statuses (aligned with the canonical schema in
# odda_utils/src/odda_utils/static/schema.sql).
VALID_STATUSES = (
"pending",
"approved",
"rejected",
"in_progress",
"implemented",
"incomplete",
"completed",
"cancelled",
)

# Inactive statuses (requests that no longer need attention). These are the
# terminal states: an accepted implementation (completed), a rejected request,
# a cancelled request, or an implementation that could not be finished
# (incomplete). Active requests are everything else: pending, approved,
# in_progress, and implemented.
INACTIVE_STATUSES = ("completed", "rejected", "cancelled", "incomplete")


def get_connection(db_path: Path = DEFAULT_DB_PATH) -> sqlite3.Connection:
Expand All @@ -44,11 +58,16 @@ def get_connection(db_path: Path = DEFAULT_DB_PATH) -> sqlite3.Connection:
def ensure_table_exists(db_path: Path = DEFAULT_DB_PATH) -> None:
"""Create the agent_requests table if it doesn't exist.

The table supports the following statuses:
The schema matches the canonical definition in
``odda_utils/src/odda_utils/static/schema.sql`` and supports the following
statuses:

- pending: Initial state, awaiting review
- approved: Approved for implementation
- rejected: Rejected with a reason
- in_progress: Implementation is underway
- implemented: Implementation completed, awaiting verification
- incomplete: Implementation attempted but could not be finished
- completed: Implementation verified and accepted
- cancelled: Cancelled after implementation

Expand All @@ -67,8 +86,9 @@ def ensure_table_exists(db_path: Path = DEFAULT_DB_PATH) -> None:
request TEXT NOT NULL,
reason_for_request TEXT,
request_status TEXT DEFAULT 'pending'
CHECK (request_status IN ('pending', 'approved', 'rejected', 'implemented', 'completed', 'cancelled')),
CHECK (request_status IN ('pending', 'approved', 'rejected', 'in_progress', 'implemented', 'incomplete', 'completed', 'cancelled')),
status_reason TEXT,
assigned_time TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
embedding BLOB,
embedding_model VARCHAR(100)
Expand All @@ -86,6 +106,10 @@ def ensure_table_exists(db_path: Path = DEFAULT_DB_PATH) -> None:
"CREATE INDEX IF NOT EXISTS idx_agent_requests_agent "
"ON agent_requests(agent_name)"
)
conn.execute(
"CREATE INDEX IF NOT EXISTS idx_agent_requests_assigned "
"ON agent_requests(assigned_time)"
)
conn.commit()
finally:
conn.close()
Expand Down Expand Up @@ -170,7 +194,7 @@ def get_all_requests(
Path to the SQLite database file.
status_filter : str | None
Optional status to filter by ('pending', 'approved', 'rejected',
'implemented', 'completed', 'cancelled').
'in_progress', 'implemented', 'incomplete', 'completed', 'cancelled').

Returns
-------
Expand Down Expand Up @@ -510,6 +534,9 @@ def _embedding_to_blob(embedding: list[float]) -> bytes:
return struct.pack(f"{len(embedding)}f", *embedding)


# TODO: Consolidate this credential reader and get_text_embedding with the
# shared model layer being built in odda_utils; kept local for now so the GUI
# continues to work standalone.
def _get_azure_credentials(
endpoint_file: Path | None = None,
api_key_file: Path | None = None,
Expand Down Expand Up @@ -577,8 +604,31 @@ def get_text_embedding(
Raises
------
httpx.HTTPError
If the API request fails.
If the API request fails (standalone fallback path only).

Notes
-----
When the ``odda_utils`` package is importable (the normal deployment), this
delegates to the shared bring-your-own-key model layer so the GUI honours the
same provider configuration as the rest of ODDA. If ``odda_utils`` is not
available, it falls back to a self-contained Azure OpenAI request so the GUI
still works standalone.
"""
try:
from odda_utils.utils import get_text_embedding as _shared_embedding
except ImportError:
_shared_embedding = None

if _shared_embedding is not None:
return _shared_embedding(
text,
endpoint_file=endpoint_file,
api_key_file=api_key_file,
deployment_name=deployment_name,
api_version=api_version,
)

# Standalone fallback: direct Azure OpenAI embeddings request.
endpoint, api_key = _get_azure_credentials(endpoint_file, api_key_file)

url = f"{endpoint}/openai/deployments/{deployment_name}/embeddings"
Expand Down Expand Up @@ -662,7 +712,7 @@ def set_request_status(
ID of the request to update.
status : str
New status value. Must be one of: 'pending', 'approved', 'rejected',
'implemented', 'completed', 'cancelled'.
'in_progress', 'implemented', 'incomplete', 'completed', 'cancelled'.
reason : str | None
Optional reason for the status change.
db_path : Path
Expand Down
Loading