feat: 深度研究支持独立新报告与原文改写,并完善沙箱、模型管理与全文改写
新报告不再覆盖当前文件卡片,写入时打开沙箱;步骤条仅在改写原文时位于卡片上方。同时补齐改写本地回退、模型管理与会商第三步相关改动。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
11f928bc95
commit
a5a9c952e8
63 files changed
+4113
-929
No files matched your search
+27
-60
@@ -1,29 +1,20 @@
|
||||
"""Canonical owner resolution for a thread's filesystem paths.
|
||||
|
||||
Task-deeplink conversations (those whose ``threads_meta.metadata.taskId`` is
|
||||
set — rwfx / 3qfx / xdfx) are **shared across all users**: any logged-in
|
||||
account may open the same conversation (enforced by the ``taskId`` escape
|
||||
branches in :mod:`deerflow.persistence.thread_meta.sql`). But the agent's
|
||||
generated files (md / artifacts) and uploads live under a *per-user* directory::
|
||||
The agent's generated files (md / artifacts) and uploads live under a
|
||||
*per-user* directory::
|
||||
|
||||
{base_dir}/users/{user_id}/threads/{thread_id}/user-data/...
|
||||
|
||||
If that ``{user_id}`` were the **current login**, account B opening a shared
|
||||
task conversation would resolve to an empty ``users/B/...`` directory and 404
|
||||
on every file account A generated — which is exactly the "切换账号后生成的 md
|
||||
文件找不到" bug.
|
||||
Using the request context alone is not reliable for filesystem lookup: an
|
||||
internal call or a context propagation edge case resolves to ``users/default``
|
||||
even though the authenticated route has already verified access to a persisted
|
||||
thread. The thread creator is an immutable, stable filesystem bucket, so all
|
||||
persisted threads resolve to ``threads_meta.user_id``. Task-deeplink and
|
||||
roundtable threads additionally need this because they can intentionally be
|
||||
reopened by another account.
|
||||
|
||||
To keep the *file* layer consistent with the *conversation-sharing* layer, all
|
||||
path resolution for a task-shared thread must use one stable user bucket: the
|
||||
thread's **creator** (``threads_meta.user_id``). That value is fixed at thread
|
||||
creation and never changes, so every account resolves to the same physical
|
||||
directory.
|
||||
|
||||
Personal (non-task) threads are unaffected: their creator is always the only /
|
||||
current user, so :func:`resolve_path_user_id` returns exactly what
|
||||
``get_effective_user_id`` would have. On any failure (no DB, missing row,
|
||||
memory-mode store) it falls back to the current login, so behaviour degrades
|
||||
safely to the pre-fix semantics.
|
||||
For missing metadata rows (legacy/memory-mode threads), resolution safely falls
|
||||
back to the current login.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -35,10 +26,9 @@ from deerflow.runtime.user_context import get_effective_user_id
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# thread_id -> creator user_id, populated only for task-shared threads. The
|
||||
# (taskId, creator) pair is immutable for a thread, so positive results are
|
||||
# cached forever; the fallback (current login) is never cached because a row may
|
||||
# appear after the first lookup.
|
||||
# thread_id -> creator user_id. The pair is immutable for a persisted thread,
|
||||
# so positive results are cached forever; the fallback (current login) is never
|
||||
# cached because a row may appear after the first lookup.
|
||||
_owner_cache: dict[str, str] = {}
|
||||
_owner_cache_lock = threading.Lock()
|
||||
_OWNER_CACHE_MAX = 4096
|
||||
@@ -64,11 +54,11 @@ def _cache_put(thread_id: str, owner: str) -> None:
|
||||
_owner_cache[thread_id] = owner
|
||||
|
||||
|
||||
async def _fetch_task_owner(thread_id: str) -> str | None:
|
||||
"""Return the creator user_id iff *thread_id* is a task-shared thread.
|
||||
async def _fetch_thread_owner(thread_id: str) -> str | None:
|
||||
"""Return the persisted creator user_id for *thread_id*.
|
||||
|
||||
Returns ``None`` for personal threads, untracked threads, the memory-mode
|
||||
store, or any DB error — callers then fall back to the current login.
|
||||
Returns ``None`` for untracked threads, the memory-mode store, or any DB
|
||||
error — callers then fall back to the current login.
|
||||
"""
|
||||
from deerflow.persistence.engine import get_session_factory
|
||||
from deerflow.persistence.thread_meta import ThreadMetaRepository
|
||||
@@ -81,42 +71,19 @@ async def _fetch_task_owner(thread_id: str) -> str | None:
|
||||
row = await store.get(thread_id, user_id=None)
|
||||
if not row:
|
||||
return None
|
||||
metadata = row.get("metadata") or {}
|
||||
owner = row.get("user_id")
|
||||
if owner and _is_creator_shared_thread(metadata):
|
||||
if owner:
|
||||
return str(owner)
|
||||
return None
|
||||
|
||||
|
||||
def _is_creator_shared_thread(metadata: dict) -> bool:
|
||||
"""True iff a thread's files should resolve to its **creator** (shared bucket).
|
||||
|
||||
Two kinds of threads are shared to one stable directory rather than the
|
||||
current login:
|
||||
|
||||
- **Task-deeplink conversations** (``metadata.taskId``) — rwfx / 3qfx / xdfx,
|
||||
explicitly shared across all users;
|
||||
- **Roundtable 会商 system threads** (``metadata.thread_type == "roundtable"``)
|
||||
— the Step 2 seats / coordinator and Step 3 report / summary / dashboard /
|
||||
structure threads. Their sandbox artifacts (md / 流程图 / 报告) live under the
|
||||
creator's directory, but a历史草稿 reopened later — or a taskId会商 draft opened
|
||||
by **another account** — must still be able to view them. Resolving to the
|
||||
creator keeps the *file* layer consistent with the *draft-sharing* layer.
|
||||
|
||||
Roundtable thread ids are random UUIDs surfaced only inside the owner's draft
|
||||
(personal drafts are owner-scoped; taskId drafts are already shared), so this
|
||||
does not let an unrelated account *discover* another user's 会商 files — it only
|
||||
lets a caller that already holds the thread id read the creator's bucket.
|
||||
"""
|
||||
return bool(metadata.get("taskId")) or metadata.get("thread_type") == "roundtable"
|
||||
|
||||
|
||||
def resolve_path_user_id(thread_id: str | None) -> str:
|
||||
"""Canonical user bucket for *thread_id*'s files (sync).
|
||||
|
||||
For a task-shared thread this is the thread creator, so all accounts that
|
||||
share the conversation read/write the same physical directory. For every
|
||||
other case it is the current login (``get_effective_user_id``).
|
||||
A persisted thread always uses its creator's stable directory. This is the
|
||||
same bucket as the current user for ordinary owned threads, and also keeps
|
||||
file lookup correct when request context is unavailable. Legacy/untracked
|
||||
threads use the current login (``get_effective_user_id``).
|
||||
"""
|
||||
if not thread_id or _is_local_only_thread(thread_id):
|
||||
return get_effective_user_id()
|
||||
@@ -126,9 +93,9 @@ def resolve_path_user_id(thread_id: str | None) -> str:
|
||||
try:
|
||||
from deerflow.persistence.engine import run_db_blocking
|
||||
|
||||
owner = run_db_blocking(_fetch_task_owner(thread_id))
|
||||
owner = run_db_blocking(_fetch_thread_owner(thread_id))
|
||||
except Exception:
|
||||
logger.debug("Failed to resolve task-shared owner for thread %s", thread_id, exc_info=True)
|
||||
logger.debug("Failed to resolve creator for thread %s", thread_id, exc_info=True)
|
||||
owner = None
|
||||
if owner:
|
||||
_cache_put(thread_id, owner)
|
||||
@@ -144,9 +111,9 @@ async def aresolve_path_user_id(thread_id: str | None) -> str:
|
||||
if cached is not None:
|
||||
return cached
|
||||
try:
|
||||
owner = await _fetch_task_owner(thread_id)
|
||||
owner = await _fetch_thread_owner(thread_id)
|
||||
except Exception:
|
||||
logger.debug("Failed to resolve task-shared owner for thread %s", thread_id, exc_info=True)
|
||||
logger.debug("Failed to resolve creator for thread %s", thread_id, exc_info=True)
|
||||
owner = None
|
||||
if owner:
|
||||
_cache_put(thread_id, owner)
|
||||
|
||||
Reference in new issue
Block a user