AI Update: الان کجاییم؟

This commit is contained in:
Antigravity Bot
2026-08-30 16:19:39 +03:30
parent 1f3a4250d3
commit fd26e4e0a8
3 changed files with 81 additions and 78 deletions
+55 -38
View File
@@ -856,51 +856,81 @@ class SessionManager:
def switch_conversation(self, chat_id: int, conv_id: str) -> tuple[bool, str, Dict[str, Any]]:
session = self.get_or_create(chat_id)
curr = self.get_current_project(chat_id)
if not curr:
return False, "⚠️ پروژه‌ای یافت نشد.", {}
clean_id = str(conv_id).strip()
convs = self.get_project_conversations(chat_id)
matched_cid = None
target_proj = curr
if clean_id.isdigit():
idx = int(clean_id) - 1
if 0 <= idx < len(convs):
matched_cid = convs[idx]["id"]
# 1. First check if it's a numeric index or ID in current project's conversation list
if curr:
convs = self.get_project_conversations(chat_id)
if clean_id.isdigit():
idx = int(clean_id) - 1
if 0 <= idx < len(convs):
matched_cid = convs[idx]["id"]
if not matched_cid:
for c in convs:
if c["id"] == clean_id or c["id"].lower().startswith(clean_id.lower()):
matched_cid = c["id"]
break
if not matched_cid:
for c_id in curr.conversation_history:
if c_id == clean_id or (c_id and c_id.lower().startswith(clean_id.lower())):
matched_cid = c_id
break
# 2. If not found in current project, search across all accessible projects of this user
if not matched_cid:
for c in convs:
if c["id"] == clean_id or c["id"].lower().startswith(clean_id.lower()):
matched_cid = c["id"]
break
if not matched_cid:
for c_id in curr.conversation_history:
if c_id == clean_id or (c_id and c_id.lower().startswith(clean_id.lower())):
matched_cid = c_id
accessible = self.get_all_accessible_projects(chat_id)
for p_name, p_obj in accessible.items():
all_p_cids = list(p_obj.conversation_history)
if p_obj.conversation_id and p_obj.conversation_id not in all_p_cids:
all_p_cids.append(p_obj.conversation_id)
for c_id in all_p_cids:
if c_id == clean_id or (c_id and c_id.lower().startswith(clean_id.lower())):
matched_cid = c_id
target_proj = p_obj
break
if matched_cid:
break
# 3. Fallback: check if valid conversation exists on disk
if not matched_cid:
meta = get_conversation_metadata(clean_id)
if meta.get("file_exists"):
matched_cid = clean_id
target_proj = curr
if not matched_cid:
if not matched_cid or not target_proj:
return False, f"⚠️ گفتگویی با شناسه یا شماره «{clean_id}» یافت نشد.", {}
# If switching to a conversation belonging to another project, automatically switch active project
project_switched = False
if session.active_project != target_proj.name:
session.active_project = target_proj.name
project_switched = True
meta = get_conversation_metadata(matched_cid)
if curr.conversation_id and curr.conversation_id != matched_cid and curr.conversation_id not in curr.conversation_history:
curr.conversation_history.append(curr.conversation_id)
if target_proj.conversation_id and target_proj.conversation_id != matched_cid and target_proj.conversation_id not in target_proj.conversation_history:
target_proj.conversation_history.append(target_proj.conversation_id)
curr.conversation_id = matched_cid
if matched_cid not in curr.conversation_history:
curr.conversation_history.append(matched_cid)
target_proj.conversation_id = matched_cid
if matched_cid not in target_proj.conversation_history:
target_proj.conversation_history.append(matched_cid)
output_data = get_conversation_last_output(matched_cid)
curr.last_response = output_data.get("text") or meta.get("last_response")
target_proj.last_response = output_data.get("text") or meta.get("last_response")
self.save()
return True, f"✅ با موفقیت به گفتگوی <code>{matched_cid[:8]}...</code> سوییچ کردید.", meta
if project_switched:
msg = f"✅ با موفقیت به گفتگوی <code>{matched_cid[:8]}...</code> در پروژه <b>{escape_html(target_proj.name)}</b> سوییچ کردید."
else:
msg = f"✅ با موفقیت به گفتگوی <code>{matched_cid[:8]}...</code> سوییچ کردید."
return True, msg, meta
def delete_conversation(self, chat_id: int, conv_id: str) -> tuple[bool, str]:
session = self.get_or_create(chat_id)
@@ -1069,19 +1099,6 @@ class SessionManager:
if curr.conversation_id and curr.conversation_id not in conv_ids:
conv_ids.append(curr.conversation_id)
# For admin or default project, also discover existing brain directories if list is small
is_admin_user = settings.is_admin(chat_id)
if is_admin_user or curr.name == "default" or len(conv_ids) < 3:
try:
brain_p = Path("/root/.gemini/antigravity-cli/brain")
if brain_p.exists():
for d in brain_p.iterdir():
if d.is_dir() and len(d.name) > 30 and (d / ".system_generated/logs/transcript.jsonl").exists():
if d.name not in conv_ids:
conv_ids.append(d.name)
except Exception as e:
logger.debug(f"Error scanning brain dir: {e}")
result = []
titles_map = getattr(curr, "conversation_titles", {}) or {}
for cid in conv_ids: