mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-25 05:52:34 +00:00
feat(yuanbao): prioritize quote media refs over history backfill in DispatchMiddleware
This commit is contained in:
parent
80efe664ce
commit
3df26b925c
1 changed files with 50 additions and 19 deletions
|
|
@ -2510,26 +2510,57 @@ class DispatchMiddleware(InboundMiddleware):
|
||||||
media_urls = list(ctx.media_urls)
|
media_urls = list(ctx.media_urls)
|
||||||
media_types = list(ctx.media_types)
|
media_types = list(ctx.media_types)
|
||||||
|
|
||||||
# Backfill observed media from recent transcript history
|
# If user quoted a message (reply_to_message_id is set), resolve only
|
||||||
extra_img_urls: List[str] = []
|
# quote_media_refs to avoid injecting unrelated history media.
|
||||||
extra_img_mimes: List[str] = []
|
# Otherwise, backfill observed media from recent transcript history.
|
||||||
try:
|
if ctx.reply_to_message_id is not None:
|
||||||
extra_img_urls, extra_img_mimes = await MediaResolveMiddleware._collect_observed_media(
|
# User quoted a message — resolve only media from the quote
|
||||||
adapter, ctx.source,
|
for rid, kind, filename in ctx.quote_media_refs:
|
||||||
)
|
if kind not in ("image", "file"):
|
||||||
except Exception as exc:
|
|
||||||
logger.warning(
|
|
||||||
"[%s] observed-image hydration raised, continuing anyway: %s",
|
|
||||||
adapter.name, exc,
|
|
||||||
)
|
|
||||||
if extra_img_urls:
|
|
||||||
current = set(media_urls)
|
|
||||||
for u, m in zip(extra_img_urls, extra_img_mimes):
|
|
||||||
if u in current:
|
|
||||||
continue
|
continue
|
||||||
media_urls.append(u)
|
try:
|
||||||
media_types.append(m)
|
fresh_url = await MediaResolveMiddleware._resolve_by_resource_id(adapter, rid)
|
||||||
current.add(u)
|
except Exception as exc:
|
||||||
|
logger.warning(
|
||||||
|
"[%s] quote media resolve failed: rid=%s kind=%s err=%s",
|
||||||
|
adapter.name, rid, kind, exc,
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
cached = await MediaResolveMiddleware._download_and_cache(
|
||||||
|
adapter,
|
||||||
|
fetch_url=fresh_url,
|
||||||
|
kind=kind,
|
||||||
|
file_name=filename or None,
|
||||||
|
log_tag=f"quote rid={rid}",
|
||||||
|
)
|
||||||
|
if cached is None:
|
||||||
|
continue
|
||||||
|
path, mime = cached
|
||||||
|
# Avoid duplicates
|
||||||
|
if path not in media_urls:
|
||||||
|
media_urls.append(path)
|
||||||
|
media_types.append(mime)
|
||||||
|
else:
|
||||||
|
# No quote — backfill observed media from recent transcript history
|
||||||
|
extra_img_urls: List[str] = []
|
||||||
|
extra_img_mimes: List[str] = []
|
||||||
|
try:
|
||||||
|
extra_img_urls, extra_img_mimes = await MediaResolveMiddleware._collect_observed_media(
|
||||||
|
adapter, ctx.source,
|
||||||
|
)
|
||||||
|
except Exception as exc:
|
||||||
|
logger.warning(
|
||||||
|
"[%s] observed-image hydration raised, continuing anyway: %s",
|
||||||
|
adapter.name, exc,
|
||||||
|
)
|
||||||
|
if extra_img_urls:
|
||||||
|
current = set(media_urls)
|
||||||
|
for u, m in zip(extra_img_urls, extra_img_mimes):
|
||||||
|
if u in current:
|
||||||
|
continue
|
||||||
|
media_urls.append(u)
|
||||||
|
media_types.append(m)
|
||||||
|
current.add(u)
|
||||||
|
|
||||||
# Replace [kind|ybres:xxx] anchors with local cache paths so
|
# Replace [kind|ybres:xxx] anchors with local cache paths so
|
||||||
# the transcript records usable paths for the model.
|
# the transcript records usable paths for the model.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue