Fix: add codeexec attachments output (#14787)

### What problem does this PR solve?

add codeexec attachments output

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
buua436
2026-05-11 19:16:33 +08:00
committed by GitHub
parent 39ee2fb120
commit daf8a58c4b
5 changed files with 37 additions and 6 deletions

View File

@ -37,6 +37,7 @@ SYSTEM_OUTPUT_KEYS = frozenset(
{
"content",
"actual_type",
"attachments",
"_ERROR",
"_ARTIFACTS",
"_ATTACHMENT_CONTENT",
@ -312,7 +313,10 @@ module.exports = { main };
self.lang = Language.PYTHON.value
self.script = 'def main(arg1: str, arg2: str) -> dict: return {"result": arg1 + arg2}'
self.arguments = {}
self.outputs = {"result": {"value": "", "type": "object"}}
self.outputs = {
"result": {"value": "", "type": "object"},
"attachments": {"value": [], "type": "Array<String>"},
}
def check(self):
self.check_valid_value(self.lang, "Support languages", ["python", "python3", "nodejs", "javascript"])
@ -468,11 +472,13 @@ class CodeExec(ToolBase, ABC):
self.set_output("_ARTIFACTS", artifact_urls or None)
attachment_text = self._build_attachment_content(artifacts, artifact_urls)
self.set_output("_ATTACHMENT_CONTENT", attachment_text)
self.set_output("attachments", self._build_attachment_markdown_list(artifact_urls))
if attachment_text:
content_parts.append(attachment_text)
else:
self.set_output("_ARTIFACTS", None)
self.set_output("_ATTACHMENT_CONTENT", "")
self.set_output("attachments", [])
self.set_output("content", "\n\n".join([part for part in content_parts if part]).strip())
@ -641,6 +647,23 @@ class CodeExec(ToolBase, ABC):
return f"attachment_count: {len(sections)}\n\n" + "\n\n".join(sections)
return "attachment_count: 0"
def _build_attachment_markdown_list(self, artifact_urls: list[dict]) -> list[str]:
markdown_items = []
for art in artifact_urls:
name = _art_field(art, "name")
url = _art_field(art, "url")
mime_type = str(_art_field(art, "mime_type") or "").strip().lower()
if not name:
continue
if mime_type.startswith("image/") and url:
markdown_items.append(f"![{name}]({url})")
elif url:
markdown_items.append(f"[Download {name}]({url})")
else:
markdown_items.append(name)
return markdown_items
def _normalize_attachment_type(self, name: str, mime_type: str) -> str:
mime_type = str(mime_type or "").strip().lower()
if mime_type.startswith("image/"):