system-prompts-and-models-o.../salesflow-saas/backend/app/openclaw/gateway.py
Claude 28e57ab2b5
feat(dealix): golden path service + correlation_id + stack recommendations
Golden Path — Partner Tier-1 verification flow:
  POST /api/v1/golden-path/run — executes complete partner lifecycle:
    1. PartnerDossier (structured output with Provenance)
    2. EconomicsModel (revenue_upside, cost, payback, sensitivity)
    3. ApprovalPacket (Class B enforcement, SLA, creates ApprovalRequest)
    4. EvidencePack (auto-assembled from steps 1-3, SHA256 hash)
  All steps linked by trace_id for end-to-end correlation.

  This is the FIRST flow that actually uses structured_outputs.py
  schemas in live code — PartnerDossier, EconomicsModel, ApprovalPacket
  all enforced with Pydantic validation + Provenance fields.

correlation_id propagation:
  OpenClaw gateway now generates/accepts correlation_id and injects
  it into payload as _correlation_id. Returned in all responses.
  This enables trace linking across decision → approval → execution.

NEXT_STEP_AND_STACK_RECOMMENDATIONS_AR.md:
  Comprehensive next-step guide covering:
  - 6 closure tests (truth, schema, workflow, trust, release, executive)
  - Stack additions now (OTel, OIDC, attestations, OpenFGA)
  - Stack additions next (Great Expectations, Unstructured, connectors)
  - Backend/frontend/docs upgrade priorities
  - 7-step optimal execution order
  - Avoid-now list

https://claude.ai/code/session_01W1rJthWDkasijTdXCfxVHs
2026-04-17 05:59:32 +00:00

54 lines
2.2 KiB
Python

from __future__ import annotations
import uuid
from typing import Any, Dict
from app.openclaw.approval_bridge import approval_bridge
from app.openclaw.observability_bridge import observability_bridge
from app.openclaw.task_router import task_router
class OpenClawGateway:
"""Single ingress for OpenClaw tasks: policy -> progress -> execute."""
async def execute(
self,
*,
tenant_id: str,
task_type: str,
action: str,
payload: Dict[str, Any],
model_provider: str = "auto",
cache_hint: str = "prompt-cache-reuse",
correlation_id: str | None = None,
) -> Dict[str, Any]:
corr_id = correlation_id or str(uuid.uuid4())
payload.setdefault("_correlation_id", corr_id)
gate = approval_bridge.evaluate(action=action, payload=payload, tenant_id=tenant_id)
run_id = observability_bridge.start_run(
tenant_id=tenant_id,
task_type=task_type,
model_provider=model_provider,
cache_hint=cache_hint,
approval_required=bool(gate.get("requires_approval")),
)
observability_bridge.step(run_id, "policy_gate", "ok" if gate["allowed"] else "blocked", {"gate": gate})
if not gate["allowed"]:
observability_bridge.finish(run_id, status="blocked", error=gate["reason"])
return {"run_id": run_id, "status": "blocked", "gate": gate}
try:
observability_bridge.step(run_id, "routing", "ok", {"task_type": task_type})
result = await task_router.route(task_type, tenant_id, payload)
observability_bridge.step(run_id, "execution", "ok")
observability_bridge.finish(run_id, status="completed")
return {"run_id": run_id, "correlation_id": corr_id, "status": "completed", "gate": gate, "result": result}
except Exception as e:
observability_bridge.step(run_id, "execution", "error", {"error": str(e)})
observability_bridge.finish(run_id, status="failed", error=str(e))
return {"run_id": run_id, "correlation_id": corr_id, "status": "failed", "gate": gate, "error": str(e)}
openclaw_gateway = OpenClawGateway()