{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "SlideStory agent contract",
  "description": "Runtime validation also checks revision, image IDs, unique slide IDs, and caption count. Batch changes are atomic.",
  "$defs": {
    "scriptImport": {
      "type": "object",
      "properties": {
        "expectedRevision": {
          "type": "integer",
          "minimum": 0
        },
        "script": {
          "type": "string",
          "minLength": 1,
          "maxLength": 90000
        }
      },
      "required": [
        "expectedRevision",
        "script"
      ],
      "additionalProperties": false
    },
    "queue": {
      "type": "object",
      "properties": {
        "expectedRevision": {
          "type": "integer",
          "minimum": 0
        },
        "plans": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "version": {
                "const": 1,
                "type": "number"
              },
              "name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 120
              },
              "format": {
                "type": "string",
                "enum": [
                  "9:16",
                  "4:5",
                  "1:1",
                  "16:9"
                ]
              },
              "style": {
                "type": "string",
                "enum": [
                  "cinematic",
                  "clean",
                  "bold",
                  "postcard"
                ]
              },
              "slides": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "assetId": {
                      "type": "string",
                      "minLength": 1
                    },
                    "caption": {
                      "type": "string",
                      "maxLength": 1500
                    },
                    "settings": {
                      "type": "object",
                      "properties": {
                        "style": {
                          "type": "string",
                          "enum": [
                            "cinematic",
                            "clean",
                            "bold",
                            "postcard"
                          ]
                        },
                        "size": {
                          "type": "number",
                          "minimum": 32,
                          "maximum": 140
                        },
                        "color": {
                          "type": "string",
                          "pattern": "^#[a-fA-F0-9]{6}$"
                        },
                        "position": {
                          "type": "string",
                          "enum": [
                            "top",
                            "center",
                            "bottom"
                          ]
                        },
                        "align": {
                          "type": "string",
                          "enum": [
                            "left",
                            "center",
                            "right"
                          ]
                        },
                        "overlay": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 0.8
                        },
                        "zoom": {
                          "type": "number",
                          "minimum": 1,
                          "maximum": 2
                        },
                        "focalX": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 1
                        },
                        "focalY": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 1
                        },
                        "duration": {
                          "type": "number",
                          "minimum": 1,
                          "maximum": 60
                        },
                        "clipStart": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 600
                        },
                        "clipVolume": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 1
                        }
                      },
                      "required": [],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "assetId",
                    "caption"
                  ],
                  "additionalProperties": false
                },
                "minItems": 1,
                "maxItems": 60
              }
            },
            "required": [
              "version",
              "slides"
            ],
            "additionalProperties": false
          },
          "minItems": 1,
          "maxItems": 10
        }
      },
      "required": [
        "expectedRevision",
        "plans"
      ],
      "additionalProperties": false
    },
    "linkImport": {
      "type": "object",
      "properties": {
        "expectedRevision": {
          "type": "integer",
          "minimum": 0
        },
        "images": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "pageUrl": {
                "type": "string",
                "maxLength": 4096,
                "pattern": "^https?:\\/\\/"
              },
              "imageUrl": {
                "type": "string",
                "maxLength": 4096,
                "pattern": "^https?:\\/\\/"
              },
              "title": {
                "type": "string",
                "maxLength": 300
              },
              "alt": {
                "type": "string",
                "maxLength": 300
              },
              "mediaType": {
                "type": "string",
                "enum": [
                  "image",
                  "video"
                ]
              }
            },
            "required": [
              "pageUrl",
              "imageUrl",
              "title",
              "alt"
            ],
            "additionalProperties": false
          },
          "minItems": 1,
          "maxItems": 60
        }
      },
      "required": [
        "expectedRevision",
        "images"
      ],
      "additionalProperties": false
    },
    "operation": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "set_captions",
              "type": "string"
            },
            "captions": {
              "type": "array",
              "items": {
                "type": "string",
                "maxLength": 1500
              },
              "minItems": 1,
              "maxItems": 60
            },
            "autoTiming": {
              "type": "boolean"
            }
          },
          "required": [
            "type",
            "captions"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "update_slides",
              "type": "string"
            },
            "updates": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 1500
                  },
                  "settings": {
                    "type": "object",
                    "properties": {
                      "style": {
                        "type": "string",
                        "enum": [
                          "cinematic",
                          "clean",
                          "bold",
                          "postcard"
                        ]
                      },
                      "size": {
                        "type": "number",
                        "minimum": 32,
                        "maximum": 140
                      },
                      "color": {
                        "type": "string",
                        "pattern": "^#[a-fA-F0-9]{6}$"
                      },
                      "position": {
                        "type": "string",
                        "enum": [
                          "top",
                          "center",
                          "bottom"
                        ]
                      },
                      "align": {
                        "type": "string",
                        "enum": [
                          "left",
                          "center",
                          "right"
                        ]
                      },
                      "overlay": {
                        "type": "number",
                        "minimum": 0,
                        "maximum": 0.8
                      },
                      "zoom": {
                        "type": "number",
                        "minimum": 1,
                        "maximum": 2
                      },
                      "focalX": {
                        "type": "number",
                        "minimum": 0,
                        "maximum": 1
                      },
                      "focalY": {
                        "type": "number",
                        "minimum": 0,
                        "maximum": 1
                      },
                      "duration": {
                        "type": "number",
                        "minimum": 1,
                        "maximum": 60
                      },
                      "clipStart": {
                        "type": "number",
                        "minimum": 0,
                        "maximum": 600
                      },
                      "clipVolume": {
                        "type": "number",
                        "minimum": 0,
                        "maximum": 1
                      }
                    },
                    "required": [],
                    "additionalProperties": false
                  }
                },
                "required": [
                  "id"
                ],
                "additionalProperties": false
              },
              "minItems": 1,
              "maxItems": 60
            }
          },
          "required": [
            "type",
            "updates"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "apply_settings",
              "type": "string"
            },
            "ids": {
              "type": "array",
              "items": {
                "type": "string"
              },
              "minItems": 1,
              "maxItems": 60
            },
            "settings": {
              "type": "object",
              "properties": {
                "style": {
                  "type": "string",
                  "enum": [
                    "cinematic",
                    "clean",
                    "bold",
                    "postcard"
                  ]
                },
                "size": {
                  "type": "number",
                  "minimum": 32,
                  "maximum": 140
                },
                "color": {
                  "type": "string",
                  "pattern": "^#[a-fA-F0-9]{6}$"
                },
                "position": {
                  "type": "string",
                  "enum": [
                    "top",
                    "center",
                    "bottom"
                  ]
                },
                "align": {
                  "type": "string",
                  "enum": [
                    "left",
                    "center",
                    "right"
                  ]
                },
                "overlay": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 0.8
                },
                "zoom": {
                  "type": "number",
                  "minimum": 1,
                  "maximum": 2
                },
                "focalX": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 1
                },
                "focalY": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 1
                },
                "duration": {
                  "type": "number",
                  "minimum": 1,
                  "maximum": 60
                },
                "clipStart": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 600
                },
                "clipVolume": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 1
                }
              },
              "required": [],
              "additionalProperties": false
            }
          },
          "required": [
            "type",
            "settings"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "set_style",
              "type": "string"
            },
            "style": {
              "type": "string",
              "enum": [
                "cinematic",
                "clean",
                "bold",
                "postcard"
              ]
            }
          },
          "required": [
            "type",
            "style"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "set_format",
              "type": "string"
            },
            "format": {
              "type": "string",
              "enum": [
                "9:16",
                "4:5",
                "1:1",
                "16:9"
              ]
            }
          },
          "required": [
            "type",
            "format"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "rename",
              "type": "string"
            },
            "name": {
              "type": "string",
              "minLength": 1,
              "maxLength": 120
            }
          },
          "required": [
            "type",
            "name"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "reorder",
              "type": "string"
            },
            "ids": {
              "type": "array",
              "items": {
                "type": "string"
              },
              "maxItems": 60
            }
          },
          "required": [
            "type",
            "ids"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "remove_slides",
              "type": "string"
            },
            "ids": {
              "type": "array",
              "items": {
                "type": "string"
              },
              "minItems": 1,
              "maxItems": 60
            }
          },
          "required": [
            "type",
            "ids"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "duplicate_slide",
              "type": "string"
            },
            "id": {
              "type": "string"
            }
          },
          "required": [
            "type",
            "id"
          ],
          "additionalProperties": false
        }
      ]
    },
    "plan": {
      "type": "object",
      "properties": {
        "version": {
          "const": 1,
          "type": "number"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "format": {
          "type": "string",
          "enum": [
            "9:16",
            "4:5",
            "1:1",
            "16:9"
          ]
        },
        "style": {
          "type": "string",
          "enum": [
            "cinematic",
            "clean",
            "bold",
            "postcard"
          ]
        },
        "slides": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "assetId": {
                "type": "string",
                "minLength": 1
              },
              "caption": {
                "type": "string",
                "maxLength": 1500
              },
              "settings": {
                "type": "object",
                "properties": {
                  "style": {
                    "type": "string",
                    "enum": [
                      "cinematic",
                      "clean",
                      "bold",
                      "postcard"
                    ]
                  },
                  "size": {
                    "type": "number",
                    "minimum": 32,
                    "maximum": 140
                  },
                  "color": {
                    "type": "string",
                    "pattern": "^#[a-fA-F0-9]{6}$"
                  },
                  "position": {
                    "type": "string",
                    "enum": [
                      "top",
                      "center",
                      "bottom"
                    ]
                  },
                  "align": {
                    "type": "string",
                    "enum": [
                      "left",
                      "center",
                      "right"
                    ]
                  },
                  "overlay": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 0.8
                  },
                  "zoom": {
                    "type": "number",
                    "minimum": 1,
                    "maximum": 2
                  },
                  "focalX": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 1
                  },
                  "focalY": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 1
                  },
                  "duration": {
                    "type": "number",
                    "minimum": 1,
                    "maximum": 60
                  },
                  "clipStart": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 600
                  },
                  "clipVolume": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 1
                  }
                },
                "required": [],
                "additionalProperties": false
              }
            },
            "required": [
              "assetId",
              "caption"
            ],
            "additionalProperties": false
          },
          "minItems": 1,
          "maxItems": 60
        }
      },
      "required": [
        "version",
        "slides"
      ],
      "additionalProperties": false
    },
    "settings": {
      "type": "object",
      "properties": {
        "style": {
          "type": "string",
          "enum": [
            "cinematic",
            "clean",
            "bold",
            "postcard"
          ]
        },
        "size": {
          "type": "number",
          "minimum": 32,
          "maximum": 140
        },
        "color": {
          "type": "string",
          "pattern": "^#[a-fA-F0-9]{6}$"
        },
        "position": {
          "type": "string",
          "enum": [
            "top",
            "center",
            "bottom"
          ]
        },
        "align": {
          "type": "string",
          "enum": [
            "left",
            "center",
            "right"
          ]
        },
        "overlay": {
          "type": "number",
          "minimum": 0,
          "maximum": 0.8
        },
        "zoom": {
          "type": "number",
          "minimum": 1,
          "maximum": 2
        },
        "focalX": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "focalY": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "duration": {
          "type": "number",
          "minimum": 1,
          "maximum": 60
        },
        "clipStart": {
          "type": "number",
          "minimum": 0,
          "maximum": 600
        },
        "clipVolume": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        }
      },
      "required": [
        "style",
        "size",
        "color",
        "position",
        "align",
        "overlay",
        "zoom",
        "focalX",
        "focalY",
        "duration"
      ],
      "additionalProperties": false
    },
    "batch": {
      "type": "object",
      "properties": {
        "expectedRevision": {
          "type": "integer",
          "minimum": 0
        },
        "operations": {
          "type": "array",
          "items": {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "type": {
                    "const": "set_captions",
                    "type": "string"
                  },
                  "captions": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "maxLength": 1500
                    },
                    "minItems": 1,
                    "maxItems": 60
                  },
                  "autoTiming": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "type",
                  "captions"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "const": "update_slides",
                    "type": "string"
                  },
                  "updates": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "caption": {
                          "type": "string",
                          "maxLength": 1500
                        },
                        "settings": {
                          "type": "object",
                          "properties": {
                            "style": {
                              "type": "string",
                              "enum": [
                                "cinematic",
                                "clean",
                                "bold",
                                "postcard"
                              ]
                            },
                            "size": {
                              "type": "number",
                              "minimum": 32,
                              "maximum": 140
                            },
                            "color": {
                              "type": "string",
                              "pattern": "^#[a-fA-F0-9]{6}$"
                            },
                            "position": {
                              "type": "string",
                              "enum": [
                                "top",
                                "center",
                                "bottom"
                              ]
                            },
                            "align": {
                              "type": "string",
                              "enum": [
                                "left",
                                "center",
                                "right"
                              ]
                            },
                            "overlay": {
                              "type": "number",
                              "minimum": 0,
                              "maximum": 0.8
                            },
                            "zoom": {
                              "type": "number",
                              "minimum": 1,
                              "maximum": 2
                            },
                            "focalX": {
                              "type": "number",
                              "minimum": 0,
                              "maximum": 1
                            },
                            "focalY": {
                              "type": "number",
                              "minimum": 0,
                              "maximum": 1
                            },
                            "duration": {
                              "type": "number",
                              "minimum": 1,
                              "maximum": 60
                            },
                            "clipStart": {
                              "type": "number",
                              "minimum": 0,
                              "maximum": 600
                            },
                            "clipVolume": {
                              "type": "number",
                              "minimum": 0,
                              "maximum": 1
                            }
                          },
                          "required": [],
                          "additionalProperties": false
                        }
                      },
                      "required": [
                        "id"
                      ],
                      "additionalProperties": false
                    },
                    "minItems": 1,
                    "maxItems": 60
                  }
                },
                "required": [
                  "type",
                  "updates"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "const": "apply_settings",
                    "type": "string"
                  },
                  "ids": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "minItems": 1,
                    "maxItems": 60
                  },
                  "settings": {
                    "type": "object",
                    "properties": {
                      "style": {
                        "type": "string",
                        "enum": [
                          "cinematic",
                          "clean",
                          "bold",
                          "postcard"
                        ]
                      },
                      "size": {
                        "type": "number",
                        "minimum": 32,
                        "maximum": 140
                      },
                      "color": {
                        "type": "string",
                        "pattern": "^#[a-fA-F0-9]{6}$"
                      },
                      "position": {
                        "type": "string",
                        "enum": [
                          "top",
                          "center",
                          "bottom"
                        ]
                      },
                      "align": {
                        "type": "string",
                        "enum": [
                          "left",
                          "center",
                          "right"
                        ]
                      },
                      "overlay": {
                        "type": "number",
                        "minimum": 0,
                        "maximum": 0.8
                      },
                      "zoom": {
                        "type": "number",
                        "minimum": 1,
                        "maximum": 2
                      },
                      "focalX": {
                        "type": "number",
                        "minimum": 0,
                        "maximum": 1
                      },
                      "focalY": {
                        "type": "number",
                        "minimum": 0,
                        "maximum": 1
                      },
                      "duration": {
                        "type": "number",
                        "minimum": 1,
                        "maximum": 60
                      },
                      "clipStart": {
                        "type": "number",
                        "minimum": 0,
                        "maximum": 600
                      },
                      "clipVolume": {
                        "type": "number",
                        "minimum": 0,
                        "maximum": 1
                      }
                    },
                    "required": [],
                    "additionalProperties": false
                  }
                },
                "required": [
                  "type",
                  "settings"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "const": "set_style",
                    "type": "string"
                  },
                  "style": {
                    "type": "string",
                    "enum": [
                      "cinematic",
                      "clean",
                      "bold",
                      "postcard"
                    ]
                  }
                },
                "required": [
                  "type",
                  "style"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "const": "set_format",
                    "type": "string"
                  },
                  "format": {
                    "type": "string",
                    "enum": [
                      "9:16",
                      "4:5",
                      "1:1",
                      "16:9"
                    ]
                  }
                },
                "required": [
                  "type",
                  "format"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "const": "rename",
                    "type": "string"
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120
                  }
                },
                "required": [
                  "type",
                  "name"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "const": "reorder",
                    "type": "string"
                  },
                  "ids": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "maxItems": 60
                  }
                },
                "required": [
                  "type",
                  "ids"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "const": "remove_slides",
                    "type": "string"
                  },
                  "ids": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "minItems": 1,
                    "maxItems": 60
                  }
                },
                "required": [
                  "type",
                  "ids"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "const": "duplicate_slide",
                    "type": "string"
                  },
                  "id": {
                    "type": "string"
                  }
                },
                "required": [
                  "type",
                  "id"
                ],
                "additionalProperties": false
              }
            ]
          },
          "minItems": 1,
          "maxItems": 100
        }
      },
      "required": [
        "operations"
      ],
      "additionalProperties": false
    }
  }
}
