feat: add plugin runtime and cross-device task orchestration

This commit is contained in:
chenmingxuan committed 2026-10-14 20:21:44 +08:00
1 parent 3ee4a5f7a8
commit 6663233ab8
82 files changed
+4147 -124

No files matched your search

+29 -2
View File
@@ -134,6 +134,14 @@ class StorageManager:
)
""")
conn.execute("""
CREATE TABLE IF NOT EXISTS plugin_image_references (
session_id TEXT NOT NULL,
image_name TEXT NOT NULL,
PRIMARY KEY (session_id, image_name)
)
""")
conn.execute("""
CREATE TABLE IF NOT EXISTS steps (
step_id TEXT PRIMARY KEY,
@@ -1102,6 +1110,7 @@ class StorageManager:
with self._get_connection() as conn:
conn.execute("PRAGMA foreign_keys = OFF")
tables = [
"plugin_image_references",
"video_analysis_observations",
"video_analysis_segments",
"failed_outputs",
@@ -1154,6 +1163,15 @@ class StorageManager:
except ValueError:
return False
def reference_plugin_image(self, session_id: UUID | str, image_name: str):
"""Keep tool-only images alive until their last owning task is deleted."""
with self._get_connection() as conn:
conn.execute(
"INSERT OR IGNORE INTO plugin_image_references VALUES (?, ?)",
(str(session_id), image_name),
)
conn.commit()
def delete_session(self, session_id: UUID):
"""Delete all data associated with a session, including files on disk."""
session_id_str = str(session_id)
@@ -1173,6 +1191,13 @@ class StorageManager:
for name in row
if name
}
image_names.update(
row[0]
for row in conn.execute(
"SELECT image_name FROM plugin_image_references WHERE session_id=?",
(session_id_str,),
)
)
cursor = conn.execute(
"SELECT video_id, local_video_path FROM video_recordings WHERE session_id = ?",
(session_id_str,),
@@ -1205,6 +1230,7 @@ class StorageManager:
except sqlite3.OperationalError as e:
logger.warning(f"Failed to delete video memory from {table}: {e}")
tables = [
"plugin_image_references",
"failed_outputs",
"traces",
"background_tasks",
@@ -1223,8 +1249,9 @@ class StorageManager:
raise
for name in image_names:
if not conn.execute(
"SELECT 1 FROM steps WHERE pre_image_name=? OR post_image_name=? LIMIT 1",
(name, name),
"SELECT 1 FROM steps WHERE pre_image_name=? OR post_image_name=? "
"UNION ALL SELECT 1 FROM plugin_image_references WHERE image_name=? LIMIT 1",
(name, name, name),
).fetchone():
conn.execute("DELETE FROM images WHERE image_name=?", (name,))
orphaned_images.append(name)