Migrate product-data exports to skill scripts

This commit is contained in:
wuyang6
2026-05-11 19:43:17 +08:00
parent a68302659d
commit 7dc7fa2e52
8 changed files with 112 additions and 52 deletions
@@ -1,7 +1,5 @@
from __future__ import annotations
from pathlib import Path
from product_data_portable import (
DEFAULT_REQUEST_ID,
DEFAULT_TIMESTAMP_STEP_MS,
@@ -9,6 +7,7 @@ from product_data_portable import (
emit_success,
load_json_payload,
normalize_dataset_draft,
resolve_portable_path,
)
@@ -17,15 +16,21 @@ def main() -> int:
payload = load_json_payload()
draft_text = str(payload.get("draft_text") or "")
if not draft_text and payload.get("draft_path"):
draft_text = Path(str(payload["draft_path"])).expanduser().read_text(encoding="utf-8")
draft_text = resolve_portable_path(str(payload["draft_path"])).read_text(encoding="utf-8")
source_type = str(payload.get("source_type") or "generated")
confirmed_plan_id = str(payload.get("confirmed_plan_id") or "").strip()
if source_type == "generated" and not confirmed_plan_id:
raise ValueError("confirmed_plan_id is required for generated data")
result = normalize_dataset_draft(
draft_text,
batch_id=str(payload.get("batch_id") or DEFAULT_REQUEST_ID),
source_type=str(payload.get("source_type") or "generated"),
source_type=source_type,
base_timestamp=payload.get("base_timestamp"),
timestamp_step_ms=int(payload.get("timestamp_step_ms") or DEFAULT_TIMESTAMP_STEP_MS),
default_request_id=str(payload.get("default_request_id") or DEFAULT_REQUEST_ID),
)
if confirmed_plan_id:
result["confirmed_plan_id"] = confirmed_plan_id
emit_success(result)
return 0
except Exception as exc: # noqa: BLE001 - CLI 需要把错误稳定转成 JSON