{
  "version": 0,
  "requires": [
    {
      "id": "agent.provider",
      "structuredOutput": "json-schema"
    }
  ],
  "execution": {
    "transactionMode": "SAFE_AUTO_COMMIT"
  },
  "entry": "b1",
  "blocks": {
    "b1": {
      "type": "setVar",
      "inputs": {
        "name": "selectedItems",
        "value": {
          "type": "prListProjectItems",
          "inputs": {
            "onlySelected": true,
            "includeSubbins": "BIN_AND_SUBBINS"
          }
        }
      },
      "next": "b2"
    },
    "b2": {
      "type": "setVar",
      "inputs": {
        "name": "selectedCount",
        "value": {
          "type": "listLength",
          "inputs": {
            "list": {
              "var": "selectedItems"
            }
          }
        }
      },
      "next": "b3"
    },
    "b3": {
      "type": "if",
      "inputs": {
        "branches": [
          {
            "condition": {
              "type": "logicCompare",
              "inputs": {
                "op": "EQ",
                "a": {
                  "var": "selectedCount"
                },
                "b": 0
              }
            },
            "body": [
              {
                "type": "fail",
                "inputs": {
                  "message": "Select one clip project item with an existing transcript before running this experimental whole-transcript JSON proofread shape example."
                }
              }
            ]
          }
        ]
      },
      "next": "b4"
    },
    "b4": {
      "type": "setVar",
      "inputs": {
        "name": "itemRef",
        "value": {
          "type": "listGet",
          "inputs": {
            "list": {
              "var": "selectedItems"
            },
            "where": "FIRST"
          }
        }
      },
      "next": "b5"
    },
    "b5": {
      "type": "setVar",
      "inputs": {
        "name": "itemName",
        "value": {
          "type": "prGetProjectItemProperty",
          "inputs": {
            "item": {
              "var": "itemRef"
            },
            "property": "NAME"
          }
        }
      },
      "next": "b6"
    },
    "b6": {
      "type": "setVar",
      "inputs": {
        "name": "hasTranscript",
        "value": {
          "type": "prGetProjectItemProperty",
          "inputs": {
            "item": {
              "var": "itemRef"
            },
            "property": "HAS_TRANSCRIPT"
          }
        }
      },
      "next": "b7"
    },
    "b7": {
      "type": "if",
      "inputs": {
        "branches": [
          {
            "condition": {
              "type": "logicNegate",
              "inputs": {
                "value": {
                  "var": "hasTranscript"
                }
              }
            },
            "body": [
              {
                "type": "fail",
                "inputs": {
                  "message": "The selected project item does not report an available transcript. Generate or import a transcript first, then run this experimental whole-transcript JSON proofread shape example again."
                }
              }
            ]
          }
        ]
      },
      "next": "b8"
    },
    "b8": {
      "type": "setVar",
      "inputs": {
        "name": "transcriptJson",
        "value": {
          "type": "prExportTranscriptJson",
          "inputs": {
            "item": {
              "var": "itemRef"
            }
          }
        }
      },
      "next": "b9"
    },
    "b9": {
      "type": "setVar",
      "inputs": {
        "name": "transcriptSchema",
        "value": "{\"type\":\"object\",\"properties\":{\"language\":{\"type\":\"string\"},\"segments\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"start\":{\"type\":\"number\"},\"duration\":{\"type\":\"number\"},\"language\":{\"type\":\"string\"},\"speaker\":{\"type\":\"string\"},\"words\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"text\":{\"type\":\"string\"},\"start\":{\"type\":\"number\"},\"duration\":{\"type\":\"number\"},\"confidence\":{\"type\":\"number\"},\"eos\":{\"type\":\"boolean\"},\"type\":{\"type\":\"string\"},\"tags\":{\"type\":\"array\"}},\"required\":[\"text\"],\"additionalProperties\":true}}},\"required\":[\"words\"],\"additionalProperties\":true}},\"speakers\":{\"type\":\"array\"}},\"required\":[\"segments\"],\"additionalProperties\":true}"
      },
      "next": "b10"
    },
    "b10": {
      "type": "askAgent",
      "inputs": {
        "providerRequirement": "agent.provider",
        "task": "Proofread the Premiere transcript JSON. Preserve the JSON object structure, all timing fields, speaker identifiers, word ordering, and non-text metadata. Edit only transcript word text for obvious spelling, capitalization, and punctuation fixes. Return the complete corrected transcript JSON object and no prose.",
        "inputText": {
          "var": "transcriptJson"
        },
        "contextText": {
          "type": "textJoin",
          "inputs": {
            "items": [
              "Selected project item: ",
              {
                "var": "itemName"
              },
              ". Keep all timestamps and structure stable."
            ]
          }
        },
        "outputSchemaJson": {
          "var": "transcriptSchema"
        },
        "repairAttempts": 2,
        "timeoutMs": 120000,
        "maxOutputChars": 200000,
        "onFailure": "STOP",
        "storeOkIn": "proofreadOk",
        "storeErrorIn": "proofreadError",
        "storeTextIn": "proofreadText",
        "storeRawPathIn": "proofreadRawPath",
        "storeResultJsonPathIn": "proofreadJsonPath"
      },
      "next": "b11"
    },
    "b11": {
      "type": "if",
      "inputs": {
        "branches": [
          {
            "condition": {
              "type": "uiConfirm",
              "inputs": {
                "message": {
                  "type": "textJoin",
                  "inputs": {
                    "items": [
                      "Workflow AI returned validated transcript JSON for:\n\n",
                      {
                        "var": "itemName"
                      },
                      "\n\nThis example demonstrates the safe askAgent handoff pattern, but its whole-transcript JSON proofreading roundtrip is experimental. Schema validation checks JSON shape, not editorial quality or every timing/word-structure detail.\n\nImport this corrected transcript back into the selected project item?\n\nValidated JSON artifact:\n",
                      {
                        "var": "proofreadJsonPath"
                      }
                    ]
                  }
                }
              }
            },
            "body": [
              {
                "type": "prImportTranscriptJson",
                "inputs": {
                  "item": {
                    "var": "itemRef"
                  },
                  "jsonText": {
                    "var": "proofreadText"
                  },
                  "storeResultIn": "importOk"
                }
              }
            ]
          }
        ],
        "elseBody": [
          {
            "type": "fail",
            "inputs": {
              "message": "Transcript import cancelled. The validated Workflow AI JSON artifact was left in the run-scoped diagnostic path for this workflow run."
            }
          }
        ]
      },
      "next": "b12"
    },
    "b12": {
      "type": "esConsoleLog",
      "inputs": {
        "message": {
          "type": "textJoin",
          "inputs": {
            "items": [
              "Workflow AI transcript proofread complete. Imported=",
              {
                "var": "importOk"
              },
              " rawArtifact=",
              {
                "var": "proofreadRawPath"
              },
              " jsonArtifact=",
              {
                "var": "proofreadJsonPath"
              }
            ]
          }
        }
      },
      "next": null
    }
  }
}
