fix(uploads): ignore mention references in new upload detection

This commit is contained in:
肖应宇 2026-04-15 15:43:46 +08:00
parent 3caa2d6ce1
commit 3d472761c8
2 changed files with 42 additions and 0 deletions

View File

@ -168,6 +168,9 @@ class UploadsMiddleware(AgentMiddleware[UploadsMiddlewareState]):
for f in kwargs_files:
if not isinstance(f, dict):
continue
# Mention references are context pointers, not newly uploaded files.
if f.get("ref_kind") == "mention":
continue
filename = f.get("filename") or ""
if not filename or Path(filename).name != filename:
continue

View File

@ -143,6 +143,45 @@ class TestFilesFromKwargs:
assert result is not None
assert result[0]["size"] == 0
def test_skips_mention_reference_entries(self, tmp_path):
mw = _middleware(tmp_path)
msg = _human(
"hi",
files=[
{
"filename": "mention.jpg",
"size": 123,
"path": "/mnt/user-data/uploads/mention.jpg",
"ref_kind": "mention",
"ref_source": "upload",
}
],
)
assert mw._files_from_kwargs(msg) is None
def test_mixed_list_keeps_uploads_but_skips_mentions(self, tmp_path):
mw = _middleware(tmp_path)
msg = _human(
"hi",
files=[
{
"filename": "uploaded.txt",
"size": 10,
"path": "/mnt/user-data/uploads/uploaded.txt",
},
{
"filename": "mentioned.txt",
"size": 8,
"path": "/mnt/user-data/uploads/mentioned.txt",
"ref_kind": "mention",
"ref_source": "upload",
},
],
)
result = mw._files_from_kwargs(msg)
assert result is not None
assert [f["filename"] for f in result] == ["uploaded.txt"]
# ---------------------------------------------------------------------------
# _create_files_message