更新
This commit is contained in:
@@ -3460,20 +3460,61 @@ def _merge_stream_meta(meta: dict[str, Any], payload: Mapping[str, Any]) -> None
|
||||
"""Keep observed transfer results when completion only repeats preparation.
|
||||
|
||||
Progress describes the latest actual request attempt, including a retry
|
||||
without files. Completion may instead carry the original prepared manifest;
|
||||
it is reply metadata and must not undo those observed transfer results.
|
||||
without files. Terminal metadata may repeat preparation, but an explicit
|
||||
failure receipt must still correct an earlier reference-sent event.
|
||||
"""
|
||||
|
||||
live_fields = ("items", "attachment_count", "attachment_transfer", "required_sections")
|
||||
terminal = str(payload.get("event") or "").lower() == "done"
|
||||
event = str(payload.get("event") or "").lower()
|
||||
terminal = event in {"done", "error"}
|
||||
observed = meta.get("_transfer_progress_observed") is True
|
||||
update = dict(payload)
|
||||
sections = _required_transfer_sections(payload)
|
||||
if sections is not None:
|
||||
update["required_sections"] = sections
|
||||
required_failure = str(payload.get("code") or payload.get("error_code") or "").startswith("REQUIRED_FILES_")
|
||||
if required_failure:
|
||||
update.setdefault("phase", "attachments")
|
||||
update.setdefault("status", "failed")
|
||||
failed_submission = required_failure or (
|
||||
payload.get("phase") == "attachments" and payload.get("status") == "failed"
|
||||
)
|
||||
if failed_submission:
|
||||
# Older servers report only the failed columns/code. That is a failed
|
||||
# attachment submission, not a later generation failure. Correct known
|
||||
# items without inventing sources or changing explicitly omitted files.
|
||||
for key in ("items", "required_sections"):
|
||||
entries = update.get(key)
|
||||
if isinstance(entries, list) and (
|
||||
entries or payload.get("transfer_manifest_final") is True
|
||||
):
|
||||
continue
|
||||
previous = meta.get(key) if key == "items" else _required_transfer_sections(meta)
|
||||
if isinstance(previous, list):
|
||||
update[key] = [
|
||||
{**item, "status": "failed"}
|
||||
if isinstance(item, Mapping) and item.get("status") in {
|
||||
"prepared", "uploading", "uploaded", "submitting", "submitted",
|
||||
} else item
|
||||
for item in previous
|
||||
]
|
||||
error_receipt_fields: set[str] = set()
|
||||
if event == "error":
|
||||
for key in ("items", "required_sections"):
|
||||
entries = update.get(key)
|
||||
if isinstance(entries, list) and any(
|
||||
isinstance(item, Mapping) and item.get("status") in {"submitted", "failed", "omitted"}
|
||||
and (key == "items" or str(item.get("key")) in dict(_REQUIRED_TRANSFER_SECTIONS))
|
||||
for item in entries
|
||||
):
|
||||
error_receipt_fields.add(key)
|
||||
if "items" in error_receipt_fields:
|
||||
error_receipt_fields.update(("attachment_count", "attachment_transfer"))
|
||||
if terminal and observed and payload.get("transfer_manifest_final") is not True:
|
||||
for key in live_fields:
|
||||
if key in meta:
|
||||
if key in error_receipt_fields:
|
||||
continue
|
||||
if key == "required_sections" and not any(
|
||||
isinstance(item, Mapping)
|
||||
and str(item.get("key")) in dict(_REQUIRED_TRANSFER_SECTIONS)
|
||||
@@ -3545,7 +3586,12 @@ def _transfer_description(meta: Mapping[str, Any], state: str) -> str:
|
||||
visible_items: list[Mapping[str, Any]] = []
|
||||
if isinstance(items, list):
|
||||
kinds = {"image": "图片", "document": "文档", "audio": "音频", "custom": "附件"}
|
||||
statuses = {"submitting": "提交中", "submitted": "引用已提交", "omitted": "未提交", "failed": "提交失败"}
|
||||
statuses = {
|
||||
"prepared": "等待上传", "uploading": "上传中", "uploaded": "已上传,待提交",
|
||||
"submitting": "提交中", "submitted": "引用已提交", "omitted": "未提交", "failed": "提交失败",
|
||||
}
|
||||
if meta.get("attachment_transfer") == "uploaded_files":
|
||||
statuses["submitted"] = "已上传并提交"
|
||||
visible_items = [item for item in items if isinstance(item, Mapping)
|
||||
and not _is_video_transfer_item(item)]
|
||||
for index, item in enumerate(visible_items, 1):
|
||||
@@ -6590,6 +6636,11 @@ class AiConsultDialog(QDialog):
|
||||
"upstream": "资料已提交,正在等待 AI 正文…",
|
||||
"cancelled": "本次请求已取消;上游是否停止尚未确认。",
|
||||
}.get(phase, "正在处理本请求资料…")
|
||||
if phase == "attachments" and payload.get("status") == "uploading":
|
||||
index, total = payload.get("upload_index"), payload.get("upload_total")
|
||||
state = f"正在上传附件({index}/{total})…" if (
|
||||
type(index) is int and type(total) is int and 0 < index <= total
|
||||
) else "正在上传附件…"
|
||||
if phase == "attachments" and payload.get("status") == "submitted":
|
||||
items = payload.get("items")
|
||||
visible = [item for item in items if isinstance(item, Mapping)
|
||||
@@ -6702,12 +6753,12 @@ class AiConsultDialog(QDialog):
|
||||
self._flush_stream_chunks()
|
||||
message = friendly_error(error)
|
||||
error_data = getattr(error, "data", None)
|
||||
if isinstance(error_data, Mapping):
|
||||
_merge_stream_meta(self._stream_meta, {**error_data, "event": "error"})
|
||||
cancelled = self._stream_meta.get("phase") == "cancelled" or (
|
||||
isinstance(error_data, Mapping) and error_data.get("code") == "AI_ASSISTANT_CANCELLED"
|
||||
)
|
||||
if cancelled:
|
||||
if isinstance(error_data, Mapping):
|
||||
self._stream_meta.update(error_data)
|
||||
self._stream_meta["phase"] = "cancelled"
|
||||
message = _cancel_description(self._stream_meta)
|
||||
if self._stream_worker is not None:
|
||||
|
||||
Reference in New Issue
Block a user