mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-09 04:40:45 +08:00
重构仓库目录为统一的 runtime 分层并清理历史 openclaw 残留。
本次迁移将网关/通道/工具/技能/脚本与协议资源集中到新结构,统一路径常量与脚本转发机制,减少顶层噪音并保证运行与测试行为一致。 Made-with: Cursor
This commit is contained in:
parent
ba3836f00f
commit
4a23b715a2
498 changed files with 2760 additions and 2200 deletions
41
interfaces/gateway/server_methods/attachment_normalize.py
Normal file
41
interfaces/gateway/server_methods/attachment_normalize.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
from typing import Any
|
||||
|
||||
|
||||
def _normalize_attachment_content(content: Any) -> str | None:
|
||||
if isinstance(content, str):
|
||||
return content
|
||||
if isinstance(content, (bytes, bytearray, memoryview)):
|
||||
b = bytes(content)
|
||||
return base64.b64encode(b).decode("ascii")
|
||||
return None
|
||||
|
||||
|
||||
def normalize_rpc_attachments_to_chat_attachments(attachments: list[dict[str, Any]] | None) -> list[dict[str, Any]]:
|
||||
out: list[dict[str, Any]] = []
|
||||
for a in attachments or []:
|
||||
if not isinstance(a, dict):
|
||||
continue
|
||||
source = a.get("source")
|
||||
source_mime = None
|
||||
source_content = None
|
||||
if isinstance(source, dict):
|
||||
st = source.get("type")
|
||||
if isinstance(st, str) and st == "base64":
|
||||
media_type = source.get("media_type")
|
||||
if isinstance(media_type, str):
|
||||
source_mime = media_type
|
||||
source_content = _normalize_attachment_content(source.get("data"))
|
||||
|
||||
item = {
|
||||
"type": a.get("type") if isinstance(a.get("type"), str) else None,
|
||||
"mimeType": a.get("mimeType") if isinstance(a.get("mimeType"), str) else source_mime,
|
||||
"fileName": a.get("fileName") if isinstance(a.get("fileName"), str) else None,
|
||||
"content": _normalize_attachment_content(a.get("content")) or source_content,
|
||||
}
|
||||
if item.get("content"):
|
||||
out.append(item)
|
||||
return out
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue