|
|
@@ -237,6 +237,9 @@ class DataReadRequest(BaseModel):
|
|
|
limit: int | None = None
|
|
|
offset: int = 0
|
|
|
aggregate: dict | None = None
|
|
|
+ #: 由 BFF 传入:把本次调用登记进数据面台账,call_id 与溯源令牌一致
|
|
|
+ call_id: str = ""
|
|
|
+ session_id: str = ""
|
|
|
|
|
|
|
|
|
@app.post("/tools/data_read")
|
|
|
@@ -256,6 +259,40 @@ def tool_data_read(payload: DataReadRequest) -> dict:
|
|
|
raise HTTPException(status_code=404, detail=str(error)) from error
|
|
|
except ReadError as error:
|
|
|
raise HTTPException(status_code=400, detail=str(error)) from error
|
|
|
+
|
|
|
+ if payload.call_id:
|
|
|
+ # 数据面台账:调用级记录 + 行级索引,供离线审计和"这个数从哪来"
|
|
|
+ ledger.record(
|
|
|
+ payload.call_id,
|
|
|
+ "data_read",
|
|
|
+ {
|
|
|
+ "object_id": payload.object_id,
|
|
|
+ "table": payload.table,
|
|
|
+ "filters": payload.filters,
|
|
|
+ "limit": payload.limit,
|
|
|
+ "offset": payload.offset,
|
|
|
+ "aggregate": payload.aggregate,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "columns": result["columns"],
|
|
|
+ "total": result.get("total"),
|
|
|
+ "returned": len(result["rows"]),
|
|
|
+ },
|
|
|
+ object_ids=[payload.object_id],
|
|
|
+ session_id=payload.session_id,
|
|
|
+ rows=[
|
|
|
+ {
|
|
|
+ "values": row["values"],
|
|
|
+ "_trace": {
|
|
|
+ "object_id": row["_trace"].get("object_id", payload.object_id),
|
|
|
+ "table": row["_trace"].get("table", payload.table),
|
|
|
+ "row_index": row["_trace"].get("row_index", -1),
|
|
|
+ "row_hash": row["_trace"].get("row_hash", ""),
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for row in result["rows"]
|
|
|
+ ],
|
|
|
+ )
|
|
|
return result
|
|
|
|
|
|
|
|
|
@@ -281,6 +318,8 @@ class ProcessRequest(BaseModel):
|
|
|
operation: str = "full_pipeline"
|
|
|
params: dict = Field(default_factory=dict)
|
|
|
output_filename: str | None = None
|
|
|
+ call_id: str = ""
|
|
|
+ session_id: str = ""
|
|
|
|
|
|
|
|
|
@app.post("/tools/customs_process")
|
|
|
@@ -297,6 +336,26 @@ def tool_customs_process(payload: ProcessRequest) -> dict:
|
|
|
content={"detail": run.get("error") or "处理失败", "run": run},
|
|
|
)
|
|
|
item = store.get_object(run["object_id"])
|
|
|
+ if payload.call_id:
|
|
|
+ ledger.record(
|
|
|
+ payload.call_id,
|
|
|
+ "customs_process",
|
|
|
+ {
|
|
|
+ "workspace_id": payload.workspace_id,
|
|
|
+ "input_object_id": payload.input_object_id,
|
|
|
+ "operation": payload.operation,
|
|
|
+ "params": payload.params,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "run_id": run["id"],
|
|
|
+ "object_id": item["id"],
|
|
|
+ "sheet_count": len(item["tables"]),
|
|
|
+ "rows": item["rows"],
|
|
|
+ "lineage": item["meta"].get("lineage", {}),
|
|
|
+ },
|
|
|
+ object_ids=[payload.input_object_id, item["id"]],
|
|
|
+ session_id=payload.session_id,
|
|
|
+ )
|
|
|
return {
|
|
|
"run_id": run["id"],
|
|
|
"object_id": item["id"],
|