SurfSense/surfsense_backend/app/automations/templating/context.py
CREDO23 7fb0707933 refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D)
Scoped codemod over surfsense_backend/app (excluding routes/, Wave E): renames
search_space_id -> workspace_id, search_space -> workspace, SearchSpace -> Workspace
across services, utils, tasks, agents, gateway, event_bus, notifications, podcasts,
automations, observability params, and prompt .md files. Also flips the camelCase
payload key searchSpaceId -> workspaceId (no backend reader; hard cutover).

Preserved carve-outs (verbatim): Celery task names "delete_search_space_background"
and "ai_sort_search_space" (wire names), and the OTel/metric key "search_space.id"
(dashboards depend on it). Enum values 'SEARCH_SPACE' and SearchSourceConnector
untouched.
2026-06-26 18:30:47 +02:00

41 lines
1.2 KiB
Python

"""Builder for the ``{run, inputs, steps}`` namespace exposed to every template."""
from __future__ import annotations
from collections.abc import Mapping
from datetime import datetime
from typing import Any
def build_run_context(
*,
run_id: int,
automation_id: int,
automation_name: str | None,
automation_version: int | None,
workspace_id: int | None,
creator_id: Any,
trigger_id: int | None,
trigger_type: str | None,
started_at: datetime | None,
attempt: int,
inputs: Mapping[str, Any],
step_outputs: Mapping[str, Any],
) -> dict[str, Any]:
"""Build the ``{run, inputs, steps}`` namespace exposed to every template."""
return {
"run": {
"id": run_id,
"automation_id": automation_id,
"automation_name": automation_name,
"automation_version": automation_version,
"workspace_id": workspace_id,
"creator_id": creator_id,
"trigger_id": trigger_id,
"trigger_type": trigger_type,
"started_at": started_at,
"attempt": attempt,
},
"inputs": dict(inputs),
"steps": dict(step_outputs),
}