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
@@ -21,7 +21,7 @@ from nanobot.security.workspace_access import WorkspaceScopeResolver
|
||||
from nanobot.session.keys import last_channel_from_metadata
|
||||
from nanobot.session.manager import Session
|
||||
from nanobot.session.summary import SessionSummary
|
||||
from nanobot.utils.helpers import detect_image_mime, load_bundled_template
|
||||
from nanobot.utils.helpers import detect_image_mime, image_placeholder_text, load_bundled_template
|
||||
from nanobot.utils.prompt_templates import render_template
|
||||
|
||||
|
||||
@@ -328,7 +328,7 @@ class ContextBuilder:
|
||||
if not image_paths:
|
||||
return text
|
||||
|
||||
image_blocks: list[dict[str, Any]] = []
|
||||
media_blocks: list[dict[str, Any]] = []
|
||||
for path in image_paths:
|
||||
p = Path(path)
|
||||
if not p.is_file():
|
||||
@@ -340,12 +340,13 @@ class ContextBuilder:
|
||||
if not mime or not mime.startswith("image/"):
|
||||
continue
|
||||
b64 = base64.b64encode(raw).decode()
|
||||
image_blocks.append({
|
||||
media_blocks.append({"type": "text", "text": image_placeholder_text(str(p))})
|
||||
media_blocks.append({
|
||||
"type": "image_url",
|
||||
"image_url": {"url": f"data:{mime};base64,{b64}"},
|
||||
"_meta": {"path": str(p)},
|
||||
})
|
||||
|
||||
if not image_blocks:
|
||||
if not media_blocks:
|
||||
return text
|
||||
return image_blocks + [{"type": "text", "text": text}]
|
||||
return media_blocks + [{"type": "text", "text": text}]
|
||||
@@ -46,6 +46,7 @@ from nanobot.agent.turn_delivery import (
|
||||
from nanobot.agent.turn_delivery import TurnRoute as TurnRoute
|
||||
from nanobot.agent.turn_hooks import AgentTurnHookSpec, build_agent_turn_hook
|
||||
from nanobot.bus.events import (
|
||||
INBOUND_META_LOCAL_MEDIA,
|
||||
INBOUND_META_RUNTIME_CONTROL,
|
||||
INBOUND_META_TURN_ID,
|
||||
INBOUND_META_USER_SHELL,
|
||||
@@ -712,6 +713,9 @@ class AgentLoop:
|
||||
turn_id = msg.metadata.get(INBOUND_META_TURN_ID)
|
||||
if isinstance(turn_id, str) and turn_id:
|
||||
extra[INBOUND_META_TURN_ID] = turn_id
|
||||
local_media = msg.metadata.get(INBOUND_META_LOCAL_MEDIA)
|
||||
if isinstance(local_media, list) and local_media:
|
||||
extra[INBOUND_META_LOCAL_MEDIA] = [path for path in cast(list[object], local_media) if isinstance(path, str)]
|
||||
return extra
|
||||
|
||||
async def _persist_user_message_early(
|
||||
@@ -2447,9 +2451,9 @@ class AgentLoop:
|
||||
).startswith("data:image/"):
|
||||
internal_meta = cast(dict[str, Any], block_data.get("_meta") or {})
|
||||
path = cast(str, internal_meta.get("path", ""))
|
||||
filtered.append(
|
||||
{"type": "text", "text": image_placeholder_text(path)}
|
||||
)
|
||||
reference = {"type": "text", "text": image_placeholder_text(path)}
|
||||
if not filtered or filtered[-1] != reference:
|
||||
filtered.append(reference)
|
||||
continue
|
||||
|
||||
filtered.append(block_data)
|
||||
|
||||
Reference in new issue
Block a user