aline-ai 0.5.11__py3-none-any.whl → 0.5.13__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.
- {aline_ai-0.5.11.dist-info → aline_ai-0.5.13.dist-info}/METADATA +1 -1
- {aline_ai-0.5.11.dist-info → aline_ai-0.5.13.dist-info}/RECORD +20 -18
- realign/__init__.py +1 -1
- realign/auth.py +539 -0
- realign/cli.py +23 -1
- realign/commands/auth.py +242 -0
- realign/commands/export_shares.py +44 -21
- realign/commands/import_shares.py +10 -10
- realign/commands/init.py +26 -40
- realign/commands/watcher.py +11 -16
- realign/config.py +12 -29
- realign/dashboard/widgets/config_panel.py +177 -1
- realign/db/base.py +28 -11
- realign/db/schema.py +102 -15
- realign/db/sqlite_db.py +108 -58
- realign/watcher_core.py +1 -9
- {aline_ai-0.5.11.dist-info → aline_ai-0.5.13.dist-info}/WHEEL +0 -0
- {aline_ai-0.5.11.dist-info → aline_ai-0.5.13.dist-info}/entry_points.txt +0 -0
- {aline_ai-0.5.11.dist-info → aline_ai-0.5.13.dist-info}/licenses/LICENSE +0 -0
- {aline_ai-0.5.11.dist-info → aline_ai-0.5.13.dist-info}/top_level.txt +0 -0
realign/db/sqlite_db.py
CHANGED
|
@@ -22,6 +22,7 @@ from .base import (
|
|
|
22
22
|
LockRecord,
|
|
23
23
|
AgentRecord,
|
|
24
24
|
AgentContextRecord,
|
|
25
|
+
UserRecord,
|
|
25
26
|
)
|
|
26
27
|
from .schema import (
|
|
27
28
|
INIT_SCRIPTS,
|
|
@@ -303,7 +304,7 @@ class SQLiteDatabase(DatabaseInterface):
|
|
|
303
304
|
if row:
|
|
304
305
|
return self._row_to_session(row)
|
|
305
306
|
|
|
306
|
-
# Get user identity from config
|
|
307
|
+
# Get user identity from config
|
|
307
308
|
from ..config import ReAlignConfig
|
|
308
309
|
|
|
309
310
|
config = ReAlignConfig.load()
|
|
@@ -316,8 +317,8 @@ class SQLiteDatabase(DatabaseInterface):
|
|
|
316
317
|
INSERT INTO sessions (
|
|
317
318
|
id, session_file_path, session_type, workspace_path,
|
|
318
319
|
started_at, last_activity_at, created_at, updated_at, metadata,
|
|
319
|
-
|
|
320
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?,
|
|
320
|
+
created_by
|
|
321
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
321
322
|
""",
|
|
322
323
|
(
|
|
323
324
|
session_id,
|
|
@@ -329,12 +330,18 @@ class SQLiteDatabase(DatabaseInterface):
|
|
|
329
330
|
now,
|
|
330
331
|
now,
|
|
331
332
|
metadata_json,
|
|
332
|
-
config.
|
|
333
|
-
config.user_id,
|
|
333
|
+
config.uid,
|
|
334
334
|
),
|
|
335
335
|
)
|
|
336
336
|
conn.commit()
|
|
337
337
|
|
|
338
|
+
# Upsert current user to users table
|
|
339
|
+
if config.uid:
|
|
340
|
+
try:
|
|
341
|
+
self.upsert_user(config.uid, config.user_name)
|
|
342
|
+
except Exception:
|
|
343
|
+
pass
|
|
344
|
+
|
|
338
345
|
return SessionRecord(
|
|
339
346
|
id=session_id,
|
|
340
347
|
session_file_path=session_file_path,
|
|
@@ -345,8 +352,7 @@ class SQLiteDatabase(DatabaseInterface):
|
|
|
345
352
|
updated_at=now,
|
|
346
353
|
metadata=metadata or {},
|
|
347
354
|
workspace_path=workspace_path,
|
|
348
|
-
|
|
349
|
-
creator_id=config.user_id,
|
|
355
|
+
created_by=config.uid,
|
|
350
356
|
)
|
|
351
357
|
|
|
352
358
|
def update_session_activity(self, session_id: str, last_activity_at: datetime) -> None:
|
|
@@ -659,15 +665,15 @@ class SQLiteDatabase(DatabaseInterface):
|
|
|
659
665
|
# Older schema without temp_title column.
|
|
660
666
|
pass
|
|
661
667
|
|
|
662
|
-
# Insert turn record (
|
|
668
|
+
# Insert turn record (V18: no user identity fields)
|
|
663
669
|
conn.execute(
|
|
664
670
|
"""
|
|
665
671
|
INSERT OR REPLACE INTO turns (
|
|
666
672
|
id, session_id, turn_number, user_message, assistant_summary,
|
|
667
673
|
turn_status, llm_title, temp_title, llm_description, model_name,
|
|
668
674
|
if_last_task, satisfaction, content_hash, timestamp,
|
|
669
|
-
created_at, git_commit_hash
|
|
670
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
|
675
|
+
created_at, git_commit_hash
|
|
676
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
671
677
|
""",
|
|
672
678
|
(
|
|
673
679
|
turn.id,
|
|
@@ -686,8 +692,6 @@ class SQLiteDatabase(DatabaseInterface):
|
|
|
686
692
|
turn.timestamp,
|
|
687
693
|
turn.created_at,
|
|
688
694
|
turn.git_commit_hash,
|
|
689
|
-
turn.creator_name,
|
|
690
|
-
turn.creator_id,
|
|
691
695
|
),
|
|
692
696
|
)
|
|
693
697
|
|
|
@@ -1495,13 +1499,13 @@ class SQLiteDatabase(DatabaseInterface):
|
|
|
1495
1499
|
conn = self._get_connection()
|
|
1496
1500
|
try:
|
|
1497
1501
|
for event in events:
|
|
1498
|
-
# Upsert Event (
|
|
1502
|
+
# Upsert Event (V18: created_by/shared_by)
|
|
1499
1503
|
conn.execute(
|
|
1500
1504
|
"""
|
|
1501
1505
|
INSERT INTO events (
|
|
1502
1506
|
id, title, description, event_type, status,
|
|
1503
1507
|
start_timestamp, end_timestamp, created_at, updated_at, metadata,
|
|
1504
|
-
|
|
1508
|
+
created_by, shared_by
|
|
1505
1509
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
1506
1510
|
ON CONFLICT(id) DO UPDATE SET
|
|
1507
1511
|
title=excluded.title,
|
|
@@ -1512,8 +1516,8 @@ class SQLiteDatabase(DatabaseInterface):
|
|
|
1512
1516
|
end_timestamp=excluded.end_timestamp,
|
|
1513
1517
|
updated_at=excluded.updated_at,
|
|
1514
1518
|
metadata=excluded.metadata,
|
|
1515
|
-
|
|
1516
|
-
|
|
1519
|
+
created_by=excluded.created_by,
|
|
1520
|
+
shared_by=excluded.shared_by
|
|
1517
1521
|
""",
|
|
1518
1522
|
(
|
|
1519
1523
|
event.id,
|
|
@@ -1526,8 +1530,8 @@ class SQLiteDatabase(DatabaseInterface):
|
|
|
1526
1530
|
event.created_at,
|
|
1527
1531
|
event.updated_at,
|
|
1528
1532
|
json.dumps(event.metadata),
|
|
1529
|
-
event.
|
|
1530
|
-
event.
|
|
1533
|
+
event.created_by,
|
|
1534
|
+
event.shared_by,
|
|
1531
1535
|
),
|
|
1532
1536
|
)
|
|
1533
1537
|
|
|
@@ -2063,11 +2067,11 @@ class SQLiteDatabase(DatabaseInterface):
|
|
|
2063
2067
|
from ..config import ReAlignConfig
|
|
2064
2068
|
|
|
2065
2069
|
config = ReAlignConfig.load()
|
|
2066
|
-
|
|
2067
|
-
|
|
2070
|
+
created_by = config.uid
|
|
2071
|
+
user_name_for_upsert = config.user_name
|
|
2068
2072
|
except Exception:
|
|
2069
|
-
|
|
2070
|
-
|
|
2073
|
+
created_by = None
|
|
2074
|
+
user_name_for_upsert = None
|
|
2071
2075
|
|
|
2072
2076
|
now = datetime.now()
|
|
2073
2077
|
cursor.execute(
|
|
@@ -2075,8 +2079,8 @@ class SQLiteDatabase(DatabaseInterface):
|
|
|
2075
2079
|
INSERT INTO agents (
|
|
2076
2080
|
id, provider, session_type, session_id, context_id,
|
|
2077
2081
|
transcript_path, cwd, project_dir, status, attention, source,
|
|
2078
|
-
created_at, updated_at,
|
|
2079
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
|
2082
|
+
created_at, updated_at, created_by
|
|
2083
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
2080
2084
|
""",
|
|
2081
2085
|
(
|
|
2082
2086
|
agent_id,
|
|
@@ -2092,12 +2096,18 @@ class SQLiteDatabase(DatabaseInterface):
|
|
|
2092
2096
|
source,
|
|
2093
2097
|
now,
|
|
2094
2098
|
now,
|
|
2095
|
-
|
|
2096
|
-
creator_id,
|
|
2099
|
+
created_by,
|
|
2097
2100
|
),
|
|
2098
2101
|
)
|
|
2099
2102
|
conn.commit()
|
|
2100
2103
|
|
|
2104
|
+
# Upsert current user to users table
|
|
2105
|
+
if created_by:
|
|
2106
|
+
try:
|
|
2107
|
+
self.upsert_user(created_by, user_name_for_upsert)
|
|
2108
|
+
except Exception:
|
|
2109
|
+
pass
|
|
2110
|
+
|
|
2101
2111
|
return AgentRecord(
|
|
2102
2112
|
id=agent_id,
|
|
2103
2113
|
provider=provider,
|
|
@@ -2112,8 +2122,7 @@ class SQLiteDatabase(DatabaseInterface):
|
|
|
2112
2122
|
source=source,
|
|
2113
2123
|
created_at=now,
|
|
2114
2124
|
updated_at=now,
|
|
2115
|
-
|
|
2116
|
-
creator_id=creator_id,
|
|
2125
|
+
created_by=created_by,
|
|
2117
2126
|
)
|
|
2118
2127
|
|
|
2119
2128
|
def update_agent(
|
|
@@ -2642,12 +2651,15 @@ class SQLiteDatabase(DatabaseInterface):
|
|
|
2642
2651
|
except (IndexError, KeyError):
|
|
2643
2652
|
pass
|
|
2644
2653
|
|
|
2645
|
-
#
|
|
2646
|
-
|
|
2647
|
-
|
|
2654
|
+
# V18: user identity fields
|
|
2655
|
+
created_by = None
|
|
2656
|
+
shared_by = None
|
|
2657
|
+
try:
|
|
2658
|
+
created_by = row["created_by"]
|
|
2659
|
+
except (IndexError, KeyError):
|
|
2660
|
+
pass
|
|
2648
2661
|
try:
|
|
2649
|
-
|
|
2650
|
-
creator_id = row["creator_id"]
|
|
2662
|
+
shared_by = row["shared_by"]
|
|
2651
2663
|
except (IndexError, KeyError):
|
|
2652
2664
|
pass
|
|
2653
2665
|
|
|
@@ -2681,21 +2693,13 @@ class SQLiteDatabase(DatabaseInterface):
|
|
|
2681
2693
|
summary_status=summary_status,
|
|
2682
2694
|
summary_locked_until=summary_locked_until,
|
|
2683
2695
|
summary_error=summary_error,
|
|
2684
|
-
|
|
2685
|
-
|
|
2696
|
+
created_by=created_by,
|
|
2697
|
+
shared_by=shared_by,
|
|
2686
2698
|
total_turns=total_turns,
|
|
2687
2699
|
total_turns_mtime=total_turns_mtime,
|
|
2688
2700
|
)
|
|
2689
2701
|
|
|
2690
2702
|
def _row_to_turn(self, row: sqlite3.Row) -> TurnRecord:
|
|
2691
|
-
# V9: creator fields (optional for backward compatibility)
|
|
2692
|
-
creator_name = None
|
|
2693
|
-
creator_id = None
|
|
2694
|
-
try:
|
|
2695
|
-
creator_name = row["creator_name"]
|
|
2696
|
-
creator_id = row["creator_id"]
|
|
2697
|
-
except (IndexError, KeyError):
|
|
2698
|
-
pass
|
|
2699
2703
|
temp_title = None
|
|
2700
2704
|
try:
|
|
2701
2705
|
temp_title = row["temp_title"]
|
|
@@ -2718,8 +2722,6 @@ class SQLiteDatabase(DatabaseInterface):
|
|
|
2718
2722
|
timestamp=self._parse_datetime(row["timestamp"]),
|
|
2719
2723
|
created_at=self._parse_datetime(row["created_at"]),
|
|
2720
2724
|
git_commit_hash=row["git_commit_hash"],
|
|
2721
|
-
creator_name=creator_name,
|
|
2722
|
-
creator_id=creator_id,
|
|
2723
2725
|
temp_title=temp_title,
|
|
2724
2726
|
)
|
|
2725
2727
|
|
|
@@ -2793,12 +2795,15 @@ class SQLiteDatabase(DatabaseInterface):
|
|
|
2793
2795
|
share_admin_token = None
|
|
2794
2796
|
share_expiry_at = None
|
|
2795
2797
|
|
|
2796
|
-
#
|
|
2797
|
-
|
|
2798
|
-
|
|
2798
|
+
# V18: user identity fields
|
|
2799
|
+
created_by = None
|
|
2800
|
+
shared_by = None
|
|
2801
|
+
try:
|
|
2802
|
+
created_by = row["created_by"]
|
|
2803
|
+
except KeyError:
|
|
2804
|
+
pass
|
|
2799
2805
|
try:
|
|
2800
|
-
|
|
2801
|
-
creator_id = row["creator_id"]
|
|
2806
|
+
shared_by = row["shared_by"]
|
|
2802
2807
|
except KeyError:
|
|
2803
2808
|
pass
|
|
2804
2809
|
|
|
@@ -2820,17 +2825,16 @@ class SQLiteDatabase(DatabaseInterface):
|
|
|
2820
2825
|
share_id=share_id,
|
|
2821
2826
|
share_admin_token=share_admin_token,
|
|
2822
2827
|
share_expiry_at=share_expiry_at,
|
|
2823
|
-
|
|
2824
|
-
|
|
2828
|
+
created_by=created_by,
|
|
2829
|
+
shared_by=shared_by,
|
|
2825
2830
|
)
|
|
2826
2831
|
|
|
2827
2832
|
def _row_to_agent(self, row: sqlite3.Row) -> AgentRecord:
|
|
2828
2833
|
"""Convert a database row to an AgentRecord."""
|
|
2829
|
-
|
|
2830
|
-
|
|
2834
|
+
# V18: user identity field
|
|
2835
|
+
created_by = None
|
|
2831
2836
|
try:
|
|
2832
|
-
|
|
2833
|
-
creator_id = row["creator_id"]
|
|
2837
|
+
created_by = row["created_by"]
|
|
2834
2838
|
except (IndexError, KeyError):
|
|
2835
2839
|
pass
|
|
2836
2840
|
|
|
@@ -2848,8 +2852,7 @@ class SQLiteDatabase(DatabaseInterface):
|
|
|
2848
2852
|
source=row["source"],
|
|
2849
2853
|
created_at=self._parse_datetime(row["created_at"]),
|
|
2850
2854
|
updated_at=self._parse_datetime(row["updated_at"]),
|
|
2851
|
-
|
|
2852
|
-
creator_id=creator_id,
|
|
2855
|
+
created_by=created_by,
|
|
2853
2856
|
)
|
|
2854
2857
|
|
|
2855
2858
|
def _row_to_agent_context(self, row: sqlite3.Row) -> AgentContextRecord:
|
|
@@ -2872,3 +2875,50 @@ class SQLiteDatabase(DatabaseInterface):
|
|
|
2872
2875
|
session_ids=None, # Populated separately
|
|
2873
2876
|
event_ids=None, # Populated separately
|
|
2874
2877
|
)
|
|
2878
|
+
|
|
2879
|
+
# -------------------------------------------------------------------------
|
|
2880
|
+
# Users table methods (Schema V18)
|
|
2881
|
+
# -------------------------------------------------------------------------
|
|
2882
|
+
|
|
2883
|
+
def upsert_user(self, uid: str, user_name: Optional[str] = None) -> None:
|
|
2884
|
+
"""Insert or update a user in the users table."""
|
|
2885
|
+
if not uid:
|
|
2886
|
+
return
|
|
2887
|
+
conn = self._get_connection()
|
|
2888
|
+
try:
|
|
2889
|
+
conn.execute(
|
|
2890
|
+
"""
|
|
2891
|
+
INSERT INTO users (uid, user_name, created_at, updated_at)
|
|
2892
|
+
VALUES (?, ?, datetime('now'), datetime('now'))
|
|
2893
|
+
ON CONFLICT(uid) DO UPDATE SET
|
|
2894
|
+
user_name = COALESCE(excluded.user_name, users.user_name),
|
|
2895
|
+
updated_at = datetime('now')
|
|
2896
|
+
""",
|
|
2897
|
+
(uid, user_name),
|
|
2898
|
+
)
|
|
2899
|
+
conn.commit()
|
|
2900
|
+
except sqlite3.OperationalError:
|
|
2901
|
+
# Older schema without users table
|
|
2902
|
+
try:
|
|
2903
|
+
conn.rollback()
|
|
2904
|
+
except Exception:
|
|
2905
|
+
pass
|
|
2906
|
+
|
|
2907
|
+
def get_user(self, uid: str) -> Optional[UserRecord]:
|
|
2908
|
+
"""Get a user by UID from the users table."""
|
|
2909
|
+
if not uid:
|
|
2910
|
+
return None
|
|
2911
|
+
conn = self._get_connection()
|
|
2912
|
+
try:
|
|
2913
|
+
cursor = conn.execute("SELECT * FROM users WHERE uid = ?", (uid,))
|
|
2914
|
+
row = cursor.fetchone()
|
|
2915
|
+
if row:
|
|
2916
|
+
return UserRecord(
|
|
2917
|
+
uid=row["uid"],
|
|
2918
|
+
user_name=row["user_name"],
|
|
2919
|
+
created_at=self._parse_datetime(row["created_at"]),
|
|
2920
|
+
updated_at=self._parse_datetime(row["updated_at"]),
|
|
2921
|
+
)
|
|
2922
|
+
except sqlite3.OperationalError:
|
|
2923
|
+
pass
|
|
2924
|
+
return None
|
realign/watcher_core.py
CHANGED
|
@@ -1509,8 +1509,6 @@ class DialogueWatcher:
|
|
|
1509
1509
|
timestamp=processing_created_at,
|
|
1510
1510
|
created_at=processing_created_at,
|
|
1511
1511
|
git_commit_hash=None,
|
|
1512
|
-
creator_name=config.user_name,
|
|
1513
|
-
creator_id=config.user_id,
|
|
1514
1512
|
)
|
|
1515
1513
|
try:
|
|
1516
1514
|
db.create_turn(processing_turn, content="")
|
|
@@ -1593,9 +1591,7 @@ class DialogueWatcher:
|
|
|
1593
1591
|
content_hash=turn_hash,
|
|
1594
1592
|
timestamp=datetime.now(),
|
|
1595
1593
|
created_at=datetime.now(),
|
|
1596
|
-
git_commit_hash=None,
|
|
1597
|
-
creator_name=config.user_name,
|
|
1598
|
-
creator_id=config.user_id,
|
|
1594
|
+
git_commit_hash=None,
|
|
1599
1595
|
)
|
|
1600
1596
|
db.create_turn(
|
|
1601
1597
|
new_turn,
|
|
@@ -1628,8 +1624,6 @@ class DialogueWatcher:
|
|
|
1628
1624
|
timestamp=datetime.now(),
|
|
1629
1625
|
created_at=processing_created_at,
|
|
1630
1626
|
git_commit_hash=None,
|
|
1631
|
-
creator_name=config.user_name,
|
|
1632
|
-
creator_id=config.user_id,
|
|
1633
1627
|
)
|
|
1634
1628
|
try:
|
|
1635
1629
|
db.create_turn(
|
|
@@ -1882,8 +1876,6 @@ class DialogueWatcher:
|
|
|
1882
1876
|
timestamp=now,
|
|
1883
1877
|
created_at=now,
|
|
1884
1878
|
git_commit_hash=None,
|
|
1885
|
-
creator_name=config.user_name,
|
|
1886
|
-
creator_id=config.user_id,
|
|
1887
1879
|
)
|
|
1888
1880
|
db.create_turn(temp_turn, content=turn_content or "", skip_session_summary=True)
|
|
1889
1881
|
except Exception as e:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|