{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "allOf": [
    {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "contract": {
              "type": "string",
              "const": "AgentSessionCommand"
            },
            "commandId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "sessionId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "runId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "idempotencyKey": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "expectedSequence": {
              "type": "integer",
              "minimum": -1,
              "maximum": 9007199254740991
            },
            "issuedAt": {
              "type": "string",
              "format": "date-time",
              "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
            },
            "commandType": {
              "type": "string",
              "const": "stop"
            },
            "payload": {
              "type": "object",
              "properties": {
                "reason": {
                  "type": "string",
                  "minLength": 1
                }
              },
              "additionalProperties": false
            }
          },
          "required": [
            "contract",
            "commandId",
            "sessionId",
            "idempotencyKey",
            "expectedSequence",
            "issuedAt",
            "commandType",
            "payload"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "contract": {
              "type": "string",
              "const": "AgentSessionCommand"
            },
            "commandId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "sessionId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "runId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "idempotencyKey": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "expectedSequence": {
              "type": "integer",
              "minimum": -1,
              "maximum": 9007199254740991
            },
            "issuedAt": {
              "type": "string",
              "format": "date-time",
              "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
            },
            "commandType": {
              "type": "string",
              "const": "resume"
            },
            "payload": {
              "type": "object",
              "properties": {
                "resumeEventId": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 256
                }
              },
              "additionalProperties": false
            }
          },
          "required": [
            "contract",
            "commandId",
            "sessionId",
            "idempotencyKey",
            "expectedSequence",
            "issuedAt",
            "commandType",
            "payload"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "contract": {
              "type": "string",
              "const": "AgentSessionCommand"
            },
            "commandId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "sessionId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "runId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "idempotencyKey": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "expectedSequence": {
              "type": "integer",
              "minimum": -1,
              "maximum": 9007199254740991
            },
            "issuedAt": {
              "type": "string",
              "format": "date-time",
              "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
            },
            "commandType": {
              "type": "string",
              "const": "retry"
            },
            "payload": {
              "type": "object",
              "properties": {
                "sourceEventId": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 256
                }
              },
              "required": [
                "sourceEventId"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "contract",
            "commandId",
            "sessionId",
            "idempotencyKey",
            "expectedSequence",
            "issuedAt",
            "commandType",
            "payload"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "contract": {
              "type": "string",
              "const": "AgentSessionCommand"
            },
            "commandId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "sessionId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "runId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "idempotencyKey": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "expectedSequence": {
              "type": "integer",
              "minimum": -1,
              "maximum": 9007199254740991
            },
            "issuedAt": {
              "type": "string",
              "format": "date-time",
              "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
            },
            "commandType": {
              "type": "string",
              "const": "retry-summary"
            },
            "payload": {
              "type": "object",
              "properties": {
                "sourceEventId": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 256
                },
                "sourceRunId": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 256
                }
              },
              "required": [
                "sourceEventId",
                "sourceRunId"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "contract",
            "commandId",
            "sessionId",
            "idempotencyKey",
            "expectedSequence",
            "issuedAt",
            "commandType",
            "payload"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "contract": {
              "type": "string",
              "const": "AgentSessionCommand"
            },
            "commandId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "sessionId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "runId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "idempotencyKey": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "expectedSequence": {
              "type": "integer",
              "minimum": -1,
              "maximum": 9007199254740991
            },
            "issuedAt": {
              "type": "string",
              "format": "date-time",
              "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
            },
            "commandType": {
              "type": "string",
              "const": "approval"
            },
            "payload": {
              "type": "object",
              "properties": {
                "approvalId": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 256
                },
                "decision": {
                  "type": "string",
                  "enum": [
                    "approved",
                    "rejected"
                  ]
                },
                "reason": {
                  "type": "string",
                  "minLength": 1
                }
              },
              "required": [
                "approvalId",
                "decision"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "contract",
            "commandId",
            "sessionId",
            "idempotencyKey",
            "expectedSequence",
            "issuedAt",
            "commandType",
            "payload"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "contract": {
              "type": "string",
              "const": "AgentSessionCommand"
            },
            "commandId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "sessionId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "runId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "idempotencyKey": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "expectedSequence": {
              "type": "integer",
              "minimum": -1,
              "maximum": 9007199254740991
            },
            "issuedAt": {
              "type": "string",
              "format": "date-time",
              "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
            },
            "commandType": {
              "type": "string",
              "const": "fork"
            },
            "payload": {
              "type": "object",
              "properties": {
                "sourceThreadId": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 256
                },
                "sourceMessageId": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 256
                },
                "sourceRunId": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 256
                },
                "inheritance": {
                  "type": "object",
                  "properties": {
                    "messages": {
                      "type": "string",
                      "enum": [
                        "through-source-message",
                        "exclude"
                      ]
                    },
                    "attachments": {
                      "type": "string",
                      "enum": [
                        "inherit",
                        "exclude"
                      ]
                    },
                    "summaries": {
                      "type": "string",
                      "enum": [
                        "inherit",
                        "exclude"
                      ]
                    },
                    "toolResults": {
                      "type": "string",
                      "enum": [
                        "inherit",
                        "exclude"
                      ]
                    },
                    "codeChanges": {
                      "type": "string",
                      "enum": [
                        "inherit",
                        "exclude"
                      ]
                    }
                  },
                  "required": [
                    "messages",
                    "attachments",
                    "summaries",
                    "toolResults",
                    "codeChanges"
                  ],
                  "additionalProperties": false
                }
              },
              "required": [
                "sourceThreadId",
                "sourceMessageId",
                "sourceRunId",
                "inheritance"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "contract",
            "commandId",
            "sessionId",
            "idempotencyKey",
            "expectedSequence",
            "issuedAt",
            "commandType",
            "payload"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "contract": {
              "type": "string",
              "const": "AgentSessionCommand"
            },
            "commandId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "sessionId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "runId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "idempotencyKey": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "expectedSequence": {
              "type": "integer",
              "minimum": -1,
              "maximum": 9007199254740991
            },
            "issuedAt": {
              "type": "string",
              "format": "date-time",
              "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
            },
            "commandType": {
              "type": "string",
              "const": "edit-and-rerun"
            },
            "payload": {
              "type": "object",
              "properties": {
                "sourceThreadId": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 256
                },
                "sourceMessageId": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 256
                },
                "sourceRunId": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 256
                },
                "replacementParts": {
                  "minItems": 1,
                  "type": "array",
                  "items": {
                    "$ref": "#/$defs/__schema0"
                  }
                },
                "inheritance": {
                  "type": "object",
                  "properties": {
                    "messages": {
                      "type": "string",
                      "enum": [
                        "through-source-message",
                        "exclude"
                      ]
                    },
                    "attachments": {
                      "type": "string",
                      "enum": [
                        "inherit",
                        "exclude"
                      ]
                    },
                    "summaries": {
                      "type": "string",
                      "enum": [
                        "inherit",
                        "exclude"
                      ]
                    },
                    "toolResults": {
                      "type": "string",
                      "enum": [
                        "inherit",
                        "exclude"
                      ]
                    },
                    "codeChanges": {
                      "type": "string",
                      "enum": [
                        "inherit",
                        "exclude"
                      ]
                    }
                  },
                  "required": [
                    "messages",
                    "attachments",
                    "summaries",
                    "toolResults",
                    "codeChanges"
                  ],
                  "additionalProperties": false
                }
              },
              "required": [
                "sourceThreadId",
                "sourceMessageId",
                "sourceRunId",
                "replacementParts",
                "inheritance"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "contract",
            "commandId",
            "sessionId",
            "idempotencyKey",
            "expectedSequence",
            "issuedAt",
            "commandType",
            "payload"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "contract": {
              "type": "string",
              "const": "AgentSessionCommand"
            },
            "commandId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "sessionId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "runId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "idempotencyKey": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "expectedSequence": {
              "type": "integer",
              "minimum": -1,
              "maximum": 9007199254740991
            },
            "issuedAt": {
              "type": "string",
              "format": "date-time",
              "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
            },
            "commandType": {
              "type": "string",
              "const": "steer"
            },
            "payload": {
              "type": "object",
              "properties": {
                "targetRunId": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 256
                },
                "text": {
                  "type": "string",
                  "minLength": 1
                }
              },
              "required": [
                "targetRunId",
                "text"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "contract",
            "commandId",
            "sessionId",
            "idempotencyKey",
            "expectedSequence",
            "issuedAt",
            "commandType",
            "payload"
          ],
          "additionalProperties": false
        }
      ]
    },
    {
      "type": "object",
      "properties": {
        "runId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 256
        }
      },
      "required": [
        "runId"
      ],
      "additionalProperties": false
    }
  ],
  "$defs": {
    "__schema0": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "number"
        },
        {
          "type": "boolean"
        },
        {
          "type": "null"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema0"
          }
        },
        {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {
            "$ref": "#/$defs/__schema0"
          }
        }
      ]
    }
  },
  "$id": "https://schemas.infmonkeys.com/contracts/agent-session-targeted-command.schema.json",
  "title": "agent-session-targeted-command"
}
