feat(attachments): support local files and video attachments (#6321)
* feat(attachments): support local files and video attachments Share gateway inspection and send validation for borrowed local paths while preserving binary uploads, original-file ownership, and existing limits. Related to NAN-284. Native provider video input remains outside this change. * test: make cross-platform verification fixtures self-contained * test(webui): align typed fixtures with runtime contracts * fix(webui): preserve uploaded video playback during history sync * test(tui): preserve local attachment drafts across resizes * perf(attachments): preserve upload caches and release video previews * docs(webui): keep attachment guidance user-focused * chore: remove redundant dependency comment * test(providers): make stream idle renewal timing deterministic * fix(attachments): keep upload byte limits out of local references Validate common format/count rules separately from upload byte budgets. Keep local inspection and send-time checks metadata-only, and exclude local references from composer and pending-upload totals. Explain upload size rejections with actual size and maximum in all ten locales. Related to NAN-284. * fix(attachments): retain image references and draft order * fix(attachments): close local reference UX and authorization gaps * fix(attachments): preserve focus during asynchronous path confirmation
This commit is contained in:
1 parent
7dfeff9ddf
commit
254f94b068
65 files changed
+1816
-292
No files matched your search
@@ -213,3 +213,52 @@ def test_attachment_references_canonicalize_existing_relative_paths(
|
||||
|
||||
assert media == [str(image_path.resolve())]
|
||||
assert f"[Attachment: {doc_path.resolve()}]" in content
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_borrowed_image_origin_survives_canonical_reload(tmp_path: Path) -> None:
|
||||
from nanobot.webui.transcript import build_session_thread_response
|
||||
|
||||
source = tmp_path / "borrowed.png"
|
||||
source.write_bytes(base64.b64decode(
|
||||
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+yF9kAAAAASUVORK5CYII="
|
||||
))
|
||||
loop = _make_loop(tmp_path)
|
||||
loop._run_agent_loop = AsyncMock(side_effect=RuntimeError("interrupt"))
|
||||
message = InboundMessage(
|
||||
channel="websocket", sender_id="u", chat_id="borrowed-origin", content="look",
|
||||
media=[str(source)], metadata={"local_media_paths": [str(source)]},
|
||||
)
|
||||
with pytest.raises(RuntimeError, match="interrupt"):
|
||||
await loop._process_message(message)
|
||||
loop.sessions.invalidate(message.session_key)
|
||||
persisted = loop.sessions.get_or_create(message.session_key)
|
||||
assert persisted.messages[0]["local_media_paths"] == [str(source)]
|
||||
augment = MagicMock(return_value=[{"kind": "image", "url": "/borrowed"}])
|
||||
response = build_session_thread_response(persisted, augment_user_media=augment)
|
||||
augment.assert_called_once_with([str(source)], [str(source)])
|
||||
assert response["events"][0]["media_urls"][0]["url"] == "/borrowed"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_image_path_remains_visible_once_after_session_reload(tmp_path: Path) -> None:
|
||||
image = tmp_path / "original.png"
|
||||
image.write_bytes(base64.b64decode(
|
||||
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+yF9kAAAAASUVORK5CYII="
|
||||
))
|
||||
loop = _make_loop(tmp_path)
|
||||
loop.provider.aclose = AsyncMock()
|
||||
try:
|
||||
await loop.process_direct("edit this image", session_key="websocket:image-reference", channel="websocket", chat_id="image-reference", media=[str(image)])
|
||||
initial = loop.provider.chat_stream_with_retry.call_args.kwargs["messages"]
|
||||
current = initial[-1]["content"]
|
||||
assert any(block.get("type") == "image_url" for block in current)
|
||||
assert sum(block.get("text", "").count(str(image)) for block in current) == 1
|
||||
loop.sessions.invalidate("websocket:image-reference")
|
||||
await loop.process_direct("which file was that?", session_key="websocket:image-reference", channel="websocket", chat_id="image-reference")
|
||||
following = loop.provider.chat_stream_with_retry.call_args.kwargs["messages"]
|
||||
previous = next(message["content"] for message in following if message["role"] == "user")
|
||||
previous_text = previous if isinstance(previous, str) else "\n".join(block.get("text", "") for block in previous)
|
||||
assert previous_text.count(str(image)) == 1
|
||||
finally:
|
||||
await loop.aclose()
|
||||
Reference in new issue
Block a user