INNER CODE UNIT · Python

_make_handler

tomascupr/sandstorm · src/sandstorm/main.py:175

        def _make_handler(t: TriggerDefinition):
            async def _handler(request: Request) -> JSONResponse:
                header = request.headers.get("x-sandstorm-trigger-secret")
                if not verify_webhook_secret(t.secret, header):
                    return JSONResponse({"error": "invalid trigger secret"}, status_code=401)
                try:
                    body = await request.json()
                except Exception:
                    # Malformed / non-JSON payloads don't silently become {}:
                    # the prompt template likely expects {{body.*}} and we'd
                    # fire the agent with mostly-empty context, which is
                    # surprising. Return 400 so the caller fixes the request.
                    return JSONResponse({"error": "invalid JSON body"}, status_code=400)
                rendered = render_prompt(
                    t.prompt,
                    body=body if isinstance(body, dict) else {"raw": body},
                    headers=dict(request.headers),
                )

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…