openedx_ai_extensions.api.v1.workflows package

Contents

openedx_ai_extensions.api.v1.workflows package#

Submodules#

openedx_ai_extensions.api.v1.workflows.permissions module#

DRF permission classes and shared request utilities for AI Workflows API.

class openedx_ai_extensions.api.v1.workflows.permissions.CourseStaffPermission#

Bases: BasePermission

Restricts access to users who are authorised to manage advanced settings for a course.

  • Staff and superusers are always allowed.

  • Otherwise, requires a valid course_id in the context query param and delegates to the configured STUDENT_MODULE_BACKEND to check whether the user holds a course-level staff or instructor role.

has_permission(request, view)#

Return True if permission is granted, False otherwise.

openedx_ai_extensions.api.v1.workflows.permissions.get_context_from_request(request)#

Extract and validate context from request query parameters.

Validates course_id and location_id formats using Open edX opaque_keys. Returns a dict with snake_case keys.

Parameters:

request – Django request object with query parameters

Returns:

Context with validated course_id and location_id in snake_case

Return type:

dict

Raises:

ValidationError – If course_id or location_id are invalid

openedx_ai_extensions.api.v1.workflows.serializers module#

Serializers for AI Workflows API

class openedx_ai_extensions.api.v1.workflows.serializers.AIWorkflowProfileListSerializer(*args, **kwargs)#

Bases: Serializer

Serializer for a single AIWorkflowProfile in the profiles list endpoint.

Exposes the profile’s identity fields, its complete effective configuration with sensitive values redacted, the list of scopes that link to it in the current request context, and a usage object with the total scope count across all courses and contexts.

create(validated_data)#

Read-only serializer — creation not supported.

get_effective_config(obj)#

Return effective config with sensitive values redacted.

get_scopes(obj)#

Return all scopes that matched this profile in the request context.

get_usage(obj)#

Return total number of scopes pointing to this profile across all contexts.

update(instance, validated_data)#

Read-only serializer — update not supported.

class openedx_ai_extensions.api.v1.workflows.serializers.AIWorkflowProfileSerializer(*args, **kwargs)#

Bases: Serializer

Serializer for AIWorkflowProfile data Simple serializer to pass profile config from backend to frontend Exposes only the UIComponents dict from the profile

create(validated_data)#

Read-only serializer — creation not supported.

get_ui_components(obj)#

Extract UIComponents from actuator_config

update(instance, validated_data)#

Read-only serializer — update not supported.

class openedx_ai_extensions.api.v1.workflows.serializers.AIWorkflowScopeSerializer(*args, **kwargs)#

Bases: Serializer

Serializer for an AIWorkflowScope instance in the profiles list endpoint.

Exposes the routing fields that caused a scope to match the request context.

create(validated_data)#

Read-only serializer — creation not supported.

update(instance, validated_data)#

Read-only serializer — update not supported.

class openedx_ai_extensions.api.v1.workflows.serializers.PromptTemplateSerializer(*args, **kwargs)#

Bases: Serializer

Serializer for a PromptTemplate instance.

Exposes all public fields of the template plus a usage object that counts how many AIWorkflowProfile configs reference this template.

create(validated_data)#

Read-only serializer — creation not supported.

get_usage(obj)#

Count how many AIWorkflowProfile configs reference this template.

Phase 1 — DB text search: filter profiles whose content_patch contains the template slug or UUID string (fast LIKE/ILIKE, no disk reads). Phase 2 — effective-config check: compute the merged config only for those candidates and confirm the reference is in processor_config.

Returns {"profile_count": None} if the count cannot be determined, so callers can distinguish “zero uses” from “unknown” without a 500.

update(instance, validated_data)#

Read-only serializer — update not supported.

class openedx_ai_extensions.api.v1.workflows.serializers.PromptTemplateUpdateSerializer(*args, **kwargs)#

Bases: ModelSerializer

Write serializer for PromptTemplate — only body may be changed.

Any field other than body in the request payload is rejected with a validation error. created_at and updated_at are managed by Django automatically and are never accepted as input.

class Meta#

Bases: object

Serializer metadata.

fields = ['body']#
model#

alias of PromptTemplate

validate(attrs)#

Reject any field not in the allowed set.

openedx_ai_extensions.api.v1.workflows.serializers.redact_sensitive_config(config)#

Return a deep copy of config with sensitive leaf values redacted.

Recursively walks nested dicts and lists. Any dict key that matches a name in _SENSITIVE_KEYS (case-insensitive) has its value replaced with the string "[REDACTED]".

Parameters:

config (dict) – Workflow effective configuration dict.

Returns:

New dict with sensitive values replaced.

Return type:

dict

openedx_ai_extensions.api.v1.workflows.views module#

AI Workflows API Views Refactored to use Django models and workflow orchestrators

class openedx_ai_extensions.api.v1.workflows.views.AIGenericWorkflowView(**kwargs)#

Bases: View

AI Workflow API endpoint

dispatch(request, *args, **kwargs)#
post(request)#

Common handler for GET and POST requests

class openedx_ai_extensions.api.v1.workflows.views.AIWorkflowProfileView(**kwargs)#

Bases: APIView

API endpoint to retrieve workflow profile configuration

get(request)#

Retrieve workflow configuration for a given action and context

permission_classes = [<class 'rest_framework.permissions.IsAuthenticated'>]#
class openedx_ai_extensions.api.v1.workflows.views.AIWorkflowProfilesListView(**kwargs)#

Bases: APIView

API endpoint to list all AI Workflow Profiles matching a given context.

Returns every distinct AIWorkflowProfile reachable for the requested course_id / location_id / ui_slot_selector_id / service_variant combination. Effective configurations are included with all sensitive values redacted.

When no uiSlotSelectorId is provided, profiles for all slots are returned — the intended call pattern for the Studio settings panel.

get(request)#

List workflow profiles for the given context.

Accepts the same context JSON query param as profile/, with optional courseId, locationId, uiSlotSelectorId, and serviceVariant keys. When serviceVariant is omitted, profiles for all service variants are returned.

Returns:

{“profiles”: […], “count”: N, “timestamp”: “…”} 400: Validation error (malformed course or location key) 500: Unexpected server error

Return type:

200

permission_classes = [<class 'openedx_ai_extensions.api.v1.workflows.permissions.CourseStaffPermission'>]#
class openedx_ai_extensions.api.v1.workflows.views.PromptTemplateDetailView(**kwargs)#

Bases: APIView

API endpoint to retrieve a single PromptTemplate by slug or UUID.

Accepts either form as the identifier URL segment: GET /v1/prompts/<slug>/ GET /v1/prompts/<uuid>/

get(request, identifier)#

Retrieve a prompt template by slug or UUID.

Parameters:

identifier (str) – Slug or UUID of the prompt template.

Returns:

Serialized prompt template. 404: No template found for the given identifier.

Return type:

200

patch(request, identifier)#

Update the body of a prompt template.

Only the body field may be changed. Any other field in the request payload is rejected with HTTP 400.

Parameters:

identifier (str) – Slug or UUID of the prompt template.

Returns:

Updated serialized prompt template. 400: Payload contains fields other than body, or body is blank. 404: No template found for the given identifier.

Return type:

200

permission_classes = [<class 'openedx_ai_extensions.api.v1.workflows.permissions.CourseStaffPermission'>]#

Module contents#