{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.sogni.ai/creative-agent/2026-04-27.1/workflows/durable-workflow-run.schema.json",
  "title": "Creative agent durable workflow run contract",
  "schemaVersion": "2026-04-27.1",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "workflowId": { "type": "string" },
    "status": { "type": "string", "enum": ["queued", "running", "completed", "partial_failure", "waiting_for_user", "failed", "cancelled"] },
    "backbone": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "schemaVersion": { "type": "string" },
        "modelKnowledgeVersion": { "type": "string" },
        "routingPolicyVersion": { "type": "string" }
      },
      "required": ["schemaVersion", "modelKnowledgeVersion", "routingPolicyVersion"]
    },
    "title": { "type": "string" },
    "input": { "type": "object", "additionalProperties": true },
    "steps": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": { "type": "string" },
          "sequence": { "type": "integer", "minimum": 0 },
          "toolName": {
            "type": "string",
            "enum": [
              "generate_image",
              "generate_video",
              "generate_music",
              "generate_speech",
              "edit_image",
              "apply_style",
              "restore_photo",
              "upscale_image",
              "image_to_3d",
              "remove_background",
              "segment_image",
              "upscale_video",
              "refine_result",
              "animate_photo",
              "change_angle",
              "video_to_video",
              "stitch_video",
              "orbit_video",
              "dance_montage",
              "sound_to_video",
              "extend_video",
              "replace_video_segment",
              "overlay_video",
              "add_subtitles",
              "analyze_image",
              "analyze_video",
              "extract_metadata",
              "ask_clarifying_question",
              "finalize_response",
              "create_asset_manifest",
              "inspect_asset",
              "label_asset",
              "map_assets_for_model",
              "validate_asset_references"
            ]
          },
          "arguments": { "type": "object", "additionalProperties": true },
          "dependsOn": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "sourceStepId": { "type": "string" },
                "targetArgument": { "type": "string" },
                "transform": {
                  "type": "string",
                  "enum": [
                    "artifact_url",
                    "artifact_data_uri",
                    "image_url",
                    "video_url",
                    "audio_url",
                    "image_index",
                    "video_index",
                    "audio_index",
                    "subtitle_cues",
                    "subtitle_srt",
                    "overlay_items",
                    "asset_ref"
                  ]
                },
                "sourceArtifactId": { "type": "string" },
                "sourceArtifactIndex": { "type": "integer", "minimum": 0 },
                "mediaType": { "type": "string", "enum": ["image", "video", "audio"] },
                "required": { "type": "boolean" }
              },
              "required": ["sourceStepId", "targetArgument", "transform"]
            }
          }
        },
        "required": ["id", "sequence", "toolName", "arguments"]
      }
    },
    "events": {
      "type": "array",
      "items": { "type": "object", "additionalProperties": true }
    },
    "artifacts": {
      "type": "array",
      "items": { "type": "object", "additionalProperties": true }
    },
    "lease": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "leaseId": { "type": "string" },
        "ownerId": { "type": "string" },
        "acquiredAt": { "type": "string", "format": "date-time" },
        "heartbeatAt": { "type": "string", "format": "date-time" },
        "expiresAt": { "type": "string", "format": "date-time" }
      },
      "required": ["leaseId", "ownerId", "acquiredAt", "heartbeatAt", "expiresAt"]
    },
    "recovery": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "resumeCount": { "type": "integer", "minimum": 0 },
        "lastResumeAt": { "type": "string", "format": "date-time" },
        "lastRecoveredAt": { "type": "string", "format": "date-time" },
        "reason": { "type": "string" }
      },
      "required": ["resumeCount"]
    },
    "quality": {
      "type": "object",
      "additionalProperties": true,
      "properties": {
        "postflightAudits": {
          "type": "array",
          "items": { "type": "object", "additionalProperties": true }
        }
      }
    },
    "timestamps": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "createdAt": { "type": "string", "format": "date-time" },
        "updatedAt": { "type": "string", "format": "date-time" },
        "completedAt": { "type": "string", "format": "date-time" }
      },
      "required": ["createdAt", "updatedAt"]
    }
  },
  "required": [
    "workflowId",
    "status",
    "backbone",
    "input",
    "steps",
    "events",
    "artifacts",
    "timestamps"
  ]
}
