feat: 完成三角色工作台及金租对公Skills全流程演示
This commit is contained in:
@@ -7,7 +7,7 @@ import time
|
||||
from datetime import datetime, timezone, timedelta
|
||||
from copy import deepcopy
|
||||
|
||||
from services.assistant_store import get, put, listing, event, uid, now, digest
|
||||
from services.assistant_store import get, put, listing, event, uid, now, digest, finish_time_event
|
||||
from services.assistant_data import read_cards
|
||||
from services.skill_executor import execute_skill, execute_rules
|
||||
from services.assistant_experiences import apply_experiences
|
||||
@@ -22,6 +22,8 @@ def authorized(identity, project_id):
|
||||
configured = os.getenv("XINGBANG_AUTH_USERS", "")
|
||||
if identity.get("preview"):
|
||||
return not configured and os.getenv("XINGBANG_REQUIRE_AUTH") != "1"
|
||||
if identity.get("demo"):
|
||||
return os.getenv("XINGBANG_DEMO_ROLE_LOGIN") == "1" and identity.get("role") in ("manager", "reviewer", "admin") and project_id in identity.get("projects", [])
|
||||
try:
|
||||
account = next((u for u in json.loads(configured or "[]") if u.get("id") == identity["id"]), None)
|
||||
except ValueError:
|
||||
@@ -163,7 +165,8 @@ class DurableWorker:
|
||||
if not run:
|
||||
return False
|
||||
done = threading.Event()
|
||||
threading.Thread(target=self.heartbeat, args=(run, done), daemon=True).start()
|
||||
heartbeat_thread = threading.Thread(target=self.heartbeat, args=(run, done), daemon=True)
|
||||
heartbeat_thread.start()
|
||||
try:
|
||||
if not authorized(run["identity"], run["project_id"]):
|
||||
raise PermissionError("项目权限已撤销")
|
||||
@@ -176,9 +179,11 @@ class DurableWorker:
|
||||
current.update(status="failed", ended_at=now(), error="运行未完成:" + type(exc).__name__)
|
||||
put(db, "run", current)
|
||||
db.execute("UPDATE assistant_jobs SET state='failed' WHERE id=? AND owner=?", (run["id"], self.owner))
|
||||
finish_time_event(db, "run", run["id"])
|
||||
event(db, run["project_id"], "run.failed", self.owner, {"error_type": type(exc).__name__}, run["id"])
|
||||
finally:
|
||||
done.set()
|
||||
heartbeat_thread.join(timeout=2)
|
||||
return True
|
||||
|
||||
def execute(self, run):
|
||||
@@ -288,6 +293,7 @@ class DurableWorker:
|
||||
for application in applications:
|
||||
put(db, "experience_application", application, immutable=True)
|
||||
db.execute("UPDATE assistant_jobs SET state=? WHERE id=? AND owner=?", (current["status"], run["id"], self.owner))
|
||||
finish_time_event(db, "run", run["id"])
|
||||
self.service.mark_stale(db, run["project_id"], ["*"])
|
||||
# A new result invalidates existing drafts, not the findings just reconciled.
|
||||
for finding in findings:
|
||||
|
||||
Reference in New Issue
Block a user