{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://logisa.invalid/design/2.0/contracts.schema.json",
  "title": "logiSA 2.0 design contracts (not live API)",
  "$defs": {
    "Assignment": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "taskType": {
          "type": "string",
          "minLength": 1
        },
        "roleCode": {
          "type": "string",
          "minLength": 1
        },
        "input": {
          "type": "object"
        },
        "ordinal": {
          "type": "integer",
          "minimum": 0
        }
      },
      "required": [
        "taskType",
        "roleCode",
        "input",
        "ordinal"
      ]
    },
    "Error": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "code": {
          "type": "string",
          "minLength": 1
        },
        "message": {
          "type": "string",
          "minLength": 1
        },
        "retryable": {
          "type": "boolean"
        },
        "details": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "path": {
                "type": "string",
                "minLength": 1
              },
              "code": {
                "type": "string",
                "minLength": 1
              }
            },
            "required": [
              "path",
              "code"
            ]
          }
        }
      },
      "required": [
        "code",
        "message",
        "retryable",
        "details"
      ]
    },
    "InboundEvent": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "schemaVersion": {
          "const": "2.0"
        },
        "tenantId": {
          "type": "string",
          "format": "uuid"
        },
        "traceId": {
          "type": "string",
          "minLength": 1
        },
        "eventId": {
          "type": "string",
          "format": "uuid"
        },
        "providerEventId": {
          "type": "string",
          "minLength": 1
        },
        "sessionId": {
          "type": "string",
          "minLength": 1
        },
        "channel": {
          "type": "string",
          "enum": [
            "zalo",
            "wechat",
            "sheet",
            "customs"
          ]
        },
        "threadId": {
          "type": "string",
          "minLength": 1
        },
        "senderId": {
          "type": "string",
          "minLength": 1
        },
        "text": {
          "type": "string",
          "maxLength": 32000
        },
        "evidenceIds": {
          "type": "array",
          "items": {
            "type": "string",
            "format": "uuid"
          }
        },
        "albumId": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1
            },
            {
              "type": "null"
            }
          ]
        },
        "occurredAt": {
          "type": "string",
          "format": "date-time"
        },
        "direction": {
          "type": "string",
          "enum": [
            "INBOUND",
            "OUTBOUND_ECHO",
            "SYSTEM"
          ]
        }
      },
      "required": [
        "schemaVersion",
        "tenantId",
        "traceId",
        "eventId",
        "providerEventId",
        "sessionId",
        "channel",
        "threadId",
        "senderId",
        "text",
        "evidenceIds",
        "albumId",
        "occurredAt",
        "direction"
      ]
    },
    "DispatchDecision": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "schemaVersion": {
          "const": "2.0"
        },
        "tenantId": {
          "type": "string",
          "format": "uuid"
        },
        "traceId": {
          "type": "string",
          "minLength": 1
        },
        "decisionId": {
          "type": "string",
          "format": "uuid"
        },
        "eventId": {
          "type": "string",
          "format": "uuid"
        },
        "action": {
          "type": "string",
          "enum": [
            "IGNORE",
            "ASSIGN",
            "ATTACH"
          ]
        },
        "reason": {
          "type": "string",
          "minLength": 1
        },
        "policyVersion": {
          "type": "integer",
          "minimum": 1
        },
        "assignments": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Assignment"
          }
        },
        "attachTaskId": {
          "anyOf": [
            {
              "type": "string",
              "format": "uuid"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "schemaVersion",
        "tenantId",
        "traceId",
        "decisionId",
        "eventId",
        "action",
        "reason",
        "policyVersion",
        "assignments",
        "attachTaskId"
      ],
      "allOf": [
        {
          "if": {
            "properties": {
              "action": {
                "const": "ASSIGN"
              }
            }
          },
          "then": {
            "properties": {
              "assignments": {
                "minItems": 1
              },
              "attachTaskId": {
                "type": "null"
              }
            }
          },
          "else": {
            "properties": {
              "assignments": {
                "maxItems": 0
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "action": {
                "const": "ATTACH"
              }
            }
          },
          "then": {
            "properties": {
              "attachTaskId": {
                "type": "string",
                "format": "uuid"
              }
            }
          },
          "else": {
            "properties": {
              "attachTaskId": {
                "type": "null"
              }
            }
          }
        }
      ]
    },
    "TaskEnvelope": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "schemaVersion": {
          "const": "2.0"
        },
        "tenantId": {
          "type": "string",
          "format": "uuid"
        },
        "traceId": {
          "type": "string",
          "minLength": 1
        },
        "taskId": {
          "type": "string",
          "format": "uuid"
        },
        "taskType": {
          "type": "string",
          "minLength": 1
        },
        "roleCode": {
          "type": "string",
          "minLength": 1
        },
        "roleVersion": {
          "type": "integer",
          "minimum": 1
        },
        "shipmentId": {
          "anyOf": [
            {
              "type": "string",
              "format": "uuid"
            },
            {
              "type": "null"
            }
          ]
        },
        "sourceEventIds": {
          "type": "array",
          "items": {
            "type": "string",
            "format": "uuid"
          },
          "minItems": 1,
          "uniqueItems": true
        },
        "evidenceIds": {
          "type": "array",
          "items": {
            "type": "string",
            "format": "uuid"
          }
        },
        "idempotencyKey": {
          "type": "string",
          "minLength": 1
        },
        "input": {
          "type": "object"
        },
        "parentTaskId": {
          "anyOf": [
            {
              "type": "string",
              "format": "uuid"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "schemaVersion",
        "tenantId",
        "traceId",
        "taskId",
        "taskType",
        "roleCode",
        "roleVersion",
        "shipmentId",
        "sourceEventIds",
        "evidenceIds",
        "idempotencyKey",
        "input",
        "parentTaskId"
      ]
    },
    "ContextBundle": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "schemaVersion": {
          "const": "2.0"
        },
        "tenantId": {
          "type": "string",
          "format": "uuid"
        },
        "traceId": {
          "type": "string",
          "minLength": 1
        },
        "taskId": {
          "type": "string",
          "format": "uuid"
        },
        "snapshotVersion": {
          "type": "integer",
          "minimum": 1
        },
        "facts": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "key": {
                "type": "string",
                "minLength": 1
              },
              "value": {},
              "source": {
                "type": "string",
                "minLength": 1
              },
              "observedAt": {
                "type": "string",
                "format": "date-time"
              }
            },
            "required": [
              "key",
              "value",
              "source",
              "observedAt"
            ]
          }
        },
        "references": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "missingFields": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "budget": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "maxTokens": {
              "type": "integer",
              "minimum": 1
            },
            "maxToolCalls": {
              "type": "integer",
              "minimum": 1
            },
            "maxImages": {
              "type": "integer",
              "minimum": 1
            }
          },
          "required": [
            "maxTokens",
            "maxToolCalls",
            "maxImages"
          ]
        }
      },
      "required": [
        "schemaVersion",
        "tenantId",
        "traceId",
        "taskId",
        "snapshotVersion",
        "facts",
        "references",
        "missingFields",
        "budget"
      ]
    },
    "ExecutionPlan": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "schemaVersion": {
          "const": "2.0"
        },
        "tenantId": {
          "type": "string",
          "format": "uuid"
        },
        "traceId": {
          "type": "string",
          "minLength": 1
        },
        "taskId": {
          "type": "string",
          "format": "uuid"
        },
        "planVersion": {
          "type": "integer",
          "minimum": 1
        },
        "mode": {
          "type": "string",
          "enum": [
            "SKILL",
            "FLOW"
          ]
        },
        "targetCode": {
          "type": "string",
          "minLength": 1
        },
        "targetVersion": {
          "type": "integer",
          "minimum": 1
        },
        "input": {
          "type": "object"
        },
        "reason": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "schemaVersion",
        "tenantId",
        "traceId",
        "taskId",
        "planVersion",
        "mode",
        "targetCode",
        "targetVersion",
        "input",
        "reason"
      ]
    },
    "ToolCall": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "schemaVersion": {
          "const": "2.0"
        },
        "tenantId": {
          "type": "string",
          "format": "uuid"
        },
        "traceId": {
          "type": "string",
          "minLength": 1
        },
        "executionId": {
          "type": "string",
          "format": "uuid"
        },
        "callId": {
          "type": "string",
          "format": "uuid"
        },
        "toolCode": {
          "type": "string",
          "minLength": 1
        },
        "toolVersion": {
          "type": "integer",
          "minimum": 1
        },
        "arguments": {
          "type": "object"
        },
        "idempotencyKey": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "schemaVersion",
        "tenantId",
        "traceId",
        "executionId",
        "callId",
        "toolCode",
        "toolVersion",
        "arguments",
        "idempotencyKey"
      ]
    },
    "ToolResult": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "schemaVersion": {
          "const": "2.0"
        },
        "tenantId": {
          "type": "string",
          "format": "uuid"
        },
        "traceId": {
          "type": "string",
          "minLength": 1
        },
        "executionId": {
          "type": "string",
          "format": "uuid"
        },
        "callId": {
          "type": "string",
          "format": "uuid"
        },
        "status": {
          "type": "string",
          "enum": [
            "SUCCESS",
            "ERROR",
            "UNKNOWN"
          ]
        },
        "data": {
          "type": "object"
        },
        "error": {
          "anyOf": [
            {
              "$ref": "#/$defs/Error"
            },
            {
              "type": "null"
            }
          ]
        },
        "receipt": {
          "anyOf": [
            {
              "type": "object"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "schemaVersion",
        "tenantId",
        "traceId",
        "executionId",
        "callId",
        "status",
        "data",
        "error",
        "receipt"
      ]
    },
    "TaskResult": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "schemaVersion": {
          "const": "2.0"
        },
        "tenantId": {
          "type": "string",
          "format": "uuid"
        },
        "traceId": {
          "type": "string",
          "minLength": 1
        },
        "resultId": {
          "type": "string",
          "format": "uuid"
        },
        "taskId": {
          "type": "string",
          "format": "uuid"
        },
        "executionId": {
          "type": "string",
          "format": "uuid"
        },
        "status": {
          "type": "string",
          "enum": [
            "SUCCESS",
            "NEEDS_INPUT",
            "NEEDS_REVIEW",
            "FAILED"
          ]
        },
        "data": {
          "type": "object"
        },
        "evidenceIds": {
          "type": "array",
          "items": {
            "type": "string",
            "format": "uuid"
          }
        },
        "proposedEvent": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1
            },
            {
              "type": "null"
            }
          ]
        },
        "errors": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Error"
          }
        }
      },
      "required": [
        "schemaVersion",
        "tenantId",
        "traceId",
        "resultId",
        "taskId",
        "executionId",
        "status",
        "data",
        "evidenceIds",
        "proposedEvent",
        "errors"
      ]
    },
    "ValidationDecision": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "schemaVersion": {
          "const": "2.0"
        },
        "tenantId": {
          "type": "string",
          "format": "uuid"
        },
        "traceId": {
          "type": "string",
          "minLength": 1
        },
        "resultId": {
          "type": "string",
          "format": "uuid"
        },
        "verdict": {
          "type": "string",
          "enum": [
            "ACCEPT",
            "REVIEW",
            "REJECT"
          ]
        },
        "ruleVersion": {
          "type": "integer",
          "minimum": 1
        },
        "violations": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "path": {
                "type": "string",
                "minLength": 1
              },
              "code": {
                "type": "string",
                "minLength": 1
              },
              "message": {
                "type": "string",
                "minLength": 1
              }
            },
            "required": [
              "path",
              "code",
              "message"
            ]
          }
        },
        "acceptedData": {
          "type": "object"
        }
      },
      "required": [
        "schemaVersion",
        "tenantId",
        "traceId",
        "resultId",
        "verdict",
        "ruleVersion",
        "violations",
        "acceptedData"
      ]
    },
    "WorkflowEvent": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "schemaVersion": {
          "const": "2.0"
        },
        "tenantId": {
          "type": "string",
          "format": "uuid"
        },
        "traceId": {
          "type": "string",
          "minLength": 1
        },
        "eventId": {
          "type": "string",
          "format": "uuid"
        },
        "instanceId": {
          "type": "string",
          "format": "uuid"
        },
        "aggregateVersion": {
          "type": "integer",
          "minimum": 1
        },
        "eventType": {
          "type": "string",
          "minLength": 1
        },
        "causationId": {
          "type": "string",
          "format": "uuid"
        },
        "data": {
          "type": "object"
        }
      },
      "required": [
        "schemaVersion",
        "tenantId",
        "traceId",
        "eventId",
        "instanceId",
        "aggregateVersion",
        "eventType",
        "causationId",
        "data"
      ]
    },
    "Destination": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "channel": {
          "type": "string",
          "enum": [
            "zalo",
            "wechat"
          ]
        },
        "sessionId": {
          "type": "string",
          "minLength": 1
        },
        "threadId": {
          "type": "string",
          "minLength": 1
        },
        "threadType": {
          "type": "string",
          "enum": [
            "group",
            "user"
          ]
        }
      },
      "required": [
        "channel",
        "sessionId",
        "threadId",
        "threadType"
      ]
    },
    "OutboundCommand": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "schemaVersion": {
          "const": "2.0"
        },
        "tenantId": {
          "type": "string",
          "format": "uuid"
        },
        "traceId": {
          "type": "string",
          "minLength": 1
        },
        "commandId": {
          "type": "string",
          "format": "uuid"
        },
        "taskId": {
          "type": "string",
          "format": "uuid"
        },
        "destination": {
          "$ref": "#/$defs/Destination"
        },
        "text": {
          "type": "string",
          "maxLength": 32000
        },
        "evidenceIds": {
          "type": "array",
          "items": {
            "type": "string",
            "format": "uuid"
          }
        }
      },
      "required": [
        "schemaVersion",
        "tenantId",
        "traceId",
        "commandId",
        "taskId",
        "destination",
        "text",
        "evidenceIds"
      ]
    },
    "DeliveryReceipt": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "schemaVersion": {
          "const": "2.0"
        },
        "tenantId": {
          "type": "string",
          "format": "uuid"
        },
        "traceId": {
          "type": "string",
          "minLength": 1
        },
        "commandId": {
          "type": "string",
          "format": "uuid"
        },
        "status": {
          "type": "string",
          "enum": [
            "ACCEPTED",
            "SENDING",
            "SENT",
            "UNKNOWN",
            "FAILED"
          ]
        },
        "providerMessageIds": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "error": {
          "anyOf": [
            {
              "$ref": "#/$defs/Error"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "schemaVersion",
        "tenantId",
        "traceId",
        "commandId",
        "status",
        "providerMessageIds",
        "error"
      ],
      "allOf": [
        {
          "if": {
            "properties": {
              "status": {
                "const": "SENT"
              }
            }
          },
          "then": {
            "properties": {
              "providerMessageIds": {
                "minItems": 1
              },
              "error": {
                "type": "null"
              }
            }
          }
        }
      ]
    },
    "ReviewDecision": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "reviewId": {
          "type": "string",
          "format": "uuid"
        },
        "expectedVersion": {
          "type": "integer",
          "minimum": 1
        },
        "decision": {
          "type": "string",
          "enum": [
            "APPROVE",
            "CORRECT",
            "REJECT"
          ]
        },
        "correctedData": {
          "type": "object"
        },
        "reason": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "reviewId",
        "expectedVersion",
        "decision",
        "correctedData",
        "reason"
      ]
    },
    "ContSealInput": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "submissionId": {
          "type": "string",
          "minLength": 1
        },
        "evidenceIds": {
          "type": "array",
          "items": {
            "type": "string",
            "format": "uuid"
          },
          "minItems": 1,
          "maxItems": 12
        },
        "caption": {
          "type": "string"
        },
        "shipmentId": {
          "anyOf": [
            {
              "type": "string",
              "format": "uuid"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "submissionId",
        "evidenceIds",
        "caption",
        "shipmentId"
      ]
    },
    "ContSealData": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "containerNumber": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^[A-Z]{4}[0-9]{7}$"
            },
            {
              "type": "null"
            }
          ]
        },
        "sealNumber": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1
            },
            {
              "type": "null"
            }
          ]
        },
        "shipmentId": {
          "anyOf": [
            {
              "type": "string",
              "format": "uuid"
            },
            {
              "type": "null"
            }
          ]
        },
        "matchStatus": {
          "type": "string",
          "enum": [
            "MATCH",
            "MISMATCH",
            "MISSING_EXPECTED",
            "AMBIGUOUS"
          ]
        },
        "fieldEvidence": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "field": {
                "type": "string",
                "enum": [
                  "containerNumber",
                  "sealNumber"
                ]
              },
              "evidenceId": {
                "type": "string",
                "format": "uuid"
              },
              "observedText": {
                "type": "string",
                "minLength": 1
              }
            },
            "required": [
              "field",
              "evidenceId",
              "observedText"
            ]
          }
        }
      },
      "required": [
        "containerNumber",
        "sealNumber",
        "shipmentId",
        "matchStatus",
        "fieldEvidence"
      ]
    },
    "FlowNode": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "id": {
              "type": "string",
              "minLength": 1
            },
            "type": {
              "const": "start"
            },
            "config": {
              "type": "object",
              "additionalProperties": false,
              "properties": {},
              "required": []
            },
            "inputMapping": {
              "type": "object",
              "additionalProperties": {
                "type": "string",
                "minLength": 1
              }
            }
          },
          "required": [
            "id",
            "type",
            "config"
          ]
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "id": {
              "type": "string",
              "minLength": 1
            },
            "type": {
              "const": "end"
            },
            "config": {
              "type": "object",
              "additionalProperties": false,
              "properties": {},
              "required": []
            },
            "inputMapping": {
              "type": "object",
              "additionalProperties": {
                "type": "string",
                "minLength": 1
              }
            }
          },
          "required": [
            "id",
            "type",
            "config"
          ]
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "id": {
              "type": "string",
              "minLength": 1
            },
            "type": {
              "const": "skill"
            },
            "config": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "skillCode": {
                  "type": "string",
                  "minLength": 1
                },
                "skillVersion": {
                  "type": "integer",
                  "minimum": 1
                },
                "timeoutSeconds": {
                  "type": "integer",
                  "minimum": 1
                },
                "maxAttempts": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 5
                }
              },
              "required": [
                "skillCode",
                "skillVersion"
              ]
            },
            "inputMapping": {
              "type": "object",
              "additionalProperties": {
                "type": "string",
                "minLength": 1
              }
            }
          },
          "required": [
            "id",
            "type",
            "config"
          ]
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "id": {
              "type": "string",
              "minLength": 1
            },
            "type": {
              "const": "condition"
            },
            "config": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "guards": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                      "outcome": {
                        "type": "string",
                        "minLength": 1
                      },
                      "test": {
                        "type": "object",
                        "additionalProperties": false,
                        "properties": {
                          "path": {
                            "type": "string",
                            "minLength": 1
                          },
                          "operator": {
                            "type": "string",
                            "enum": [
                              "eq",
                              "in",
                              "exists"
                            ]
                          },
                          "value": {}
                        },
                        "required": [
                          "path",
                          "operator",
                          "value"
                        ]
                      }
                    },
                    "required": [
                      "outcome",
                      "test"
                    ]
                  }
                },
                "defaultOutcome": {
                  "type": "string",
                  "minLength": 1
                }
              },
              "required": [
                "guards",
                "defaultOutcome"
              ]
            },
            "inputMapping": {
              "type": "object",
              "additionalProperties": {
                "type": "string",
                "minLength": 1
              }
            }
          },
          "required": [
            "id",
            "type",
            "config"
          ]
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "id": {
              "type": "string",
              "minLength": 1
            },
            "type": {
              "const": "delegate_task"
            },
            "config": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "taskType": {
                  "type": "string",
                  "minLength": 1
                },
                "roleCode": {
                  "type": "string",
                  "minLength": 1
                }
              },
              "required": [
                "taskType",
                "roleCode"
              ]
            },
            "inputMapping": {
              "type": "object",
              "additionalProperties": {
                "type": "string",
                "minLength": 1
              }
            }
          },
          "required": [
            "id",
            "type",
            "config"
          ]
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "id": {
              "type": "string",
              "minLength": 1
            },
            "type": {
              "const": "wait_input"
            },
            "config": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "correlationKey": {
                  "type": "string",
                  "minLength": 1
                },
                "timeoutSeconds": {
                  "type": "integer",
                  "minimum": 1
                },
                "timeoutOutcome": {
                  "type": "string",
                  "minLength": 1
                }
              },
              "required": [
                "correlationKey",
                "timeoutSeconds",
                "timeoutOutcome"
              ]
            },
            "inputMapping": {
              "type": "object",
              "additionalProperties": {
                "type": "string",
                "minLength": 1
              }
            }
          },
          "required": [
            "id",
            "type",
            "config"
          ]
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "id": {
              "type": "string",
              "minLength": 1
            },
            "type": {
              "const": "human_review"
            },
            "config": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "reviewPolicy": {
                  "type": "string",
                  "minLength": 1
                },
                "timeoutSeconds": {
                  "type": "integer",
                  "minimum": 1
                },
                "timeoutOutcome": {
                  "type": "string",
                  "minLength": 1
                }
              },
              "required": [
                "reviewPolicy",
                "timeoutSeconds",
                "timeoutOutcome"
              ]
            },
            "inputMapping": {
              "type": "object",
              "additionalProperties": {
                "type": "string",
                "minLength": 1
              }
            }
          },
          "required": [
            "id",
            "type",
            "config"
          ]
        }
      ]
    },
    "FlowGraph": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "schemaVersion": {
          "const": "2.0"
        },
        "nodes": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/FlowNode"
          },
          "minItems": 2,
          "maxItems": 100
        },
        "edges": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "from": {
                "type": "string",
                "minLength": 1
              },
              "to": {
                "type": "string",
                "minLength": 1
              },
              "outcome": {
                "type": "string",
                "minLength": 1
              }
            },
            "required": [
              "from",
              "to",
              "outcome"
            ]
          },
          "minItems": 1,
          "maxItems": 300
        }
      },
      "required": [
        "schemaVersion",
        "nodes",
        "edges"
      ]
    },
    "ModelProfile": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "capabilities": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": [
              "TEXT",
              "VISION",
              "STRUCTURED_OUTPUT"
            ]
          }
        },
        "route": {
          "type": "string",
          "minLength": 1
        },
        "fallbackRoutes": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "timeoutSeconds": {
          "type": "integer",
          "minimum": 1
        },
        "maxTokens": {
          "type": "integer",
          "minimum": 1
        }
      },
      "required": [
        "capabilities",
        "route",
        "fallbackRoutes",
        "timeoutSeconds",
        "maxTokens"
      ]
    },
    "RoleConfig": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "prompt": {
          "type": "string",
          "minLength": 1
        },
        "policies": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "toolPermissions": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "skillVersions": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "code": {
                "type": "string",
                "minLength": 1
              },
              "version": {
                "type": "integer",
                "minimum": 1
              }
            },
            "required": [
              "code",
              "version"
            ]
          }
        },
        "allowedFlows": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "code": {
                "type": "string",
                "minLength": 1
              },
              "version": {
                "type": "integer",
                "minimum": 1
              }
            },
            "required": [
              "code",
              "version"
            ]
          }
        },
        "taskTypes": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "contextProfile": {
          "type": "string",
          "minLength": 1
        },
        "memoryPolicy": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "ttlSeconds": {
              "type": "integer",
              "minimum": 1
            },
            "maxItems": {
              "type": "integer",
              "minimum": 1
            }
          },
          "required": [
            "ttlSeconds",
            "maxItems"
          ]
        },
        "ragCollections": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "modelProfile": {
          "anyOf": [
            {
              "$ref": "#/$defs/ModelProfile"
            },
            {
              "type": "null"
            }
          ]
        },
        "outputSchemaRef": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "prompt",
        "policies",
        "toolPermissions",
        "skillVersions",
        "allowedFlows",
        "taskTypes",
        "contextProfile",
        "memoryPolicy",
        "ragCollections",
        "modelProfile",
        "outputSchemaRef"
      ]
    },
    "SkillConfig": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "executor": {
          "type": "string",
          "enum": [
            "CODE",
            "AI",
            "HYBRID"
          ]
        },
        "executorRef": {
          "type": "string",
          "minLength": 1
        },
        "inputSchemaRef": {
          "type": "string",
          "minLength": 1
        },
        "outputSchemaRef": {
          "type": "string",
          "minLength": 1
        },
        "requiredTools": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "timeoutSeconds": {
          "type": "integer",
          "minimum": 1
        },
        "maxAttempts": {
          "type": "integer",
          "minimum": 1,
          "maximum": 5
        },
        "sideEffect": {
          "type": "string",
          "enum": [
            "NONE",
            "IDEMPOTENT",
            "RECONCILE"
          ]
        },
        "contextProfile": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "executor",
        "executorRef",
        "inputSchemaRef",
        "outputSchemaRef",
        "requiredTools",
        "timeoutSeconds",
        "maxAttempts",
        "sideEffect",
        "contextProfile"
      ]
    },
    "ContSealFlowSettings": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "sessionId": {
          "type": "string",
          "minLength": 1
        },
        "sourceGroups": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1
              },
              "name": {
                "type": "string",
                "minLength": 1
              }
            },
            "required": [
              "id",
              "name"
            ]
          },
          "minItems": 1
        },
        "resultGroup": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "id": {
              "type": "string",
              "minLength": 1
            },
            "name": {
              "type": "string",
              "minLength": 1
            }
          },
          "required": [
            "id",
            "name"
          ]
        },
        "integrationRefs": {
          "type": "array",
          "items": {
            "type": "string",
            "format": "uuid"
          }
        }
      },
      "required": [
        "sessionId",
        "sourceGroups",
        "resultGroup",
        "integrationRefs"
      ]
    },
    "FlowConfig": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "graph": {
          "$ref": "#/$defs/FlowGraph"
        },
        "taskTypes": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "allowedRoles": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "settingsSchemaRef": {
          "type": "string",
          "minLength": 1
        },
        "settings": {
          "type": "object"
        }
      },
      "required": [
        "graph",
        "taskTypes",
        "allowedRoles",
        "settingsSchemaRef",
        "settings"
      ]
    },
    "TaskDetail": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "envelope": {
          "$ref": "#/$defs/TaskEnvelope"
        },
        "state": {
          "type": "string",
          "enum": [
            "RECEIVED",
            "ROUTED",
            "PLANNED",
            "RUNNING",
            "WAITING_INPUT",
            "WAITING_REVIEW",
            "RETRY_WAIT",
            "SUCCEEDED",
            "FAILED",
            "CANCELLED"
          ]
        },
        "version": {
          "type": "integer",
          "minimum": 1
        },
        "plan": {
          "anyOf": [
            {
              "$ref": "#/$defs/ExecutionPlan"
            },
            {
              "type": "null"
            }
          ]
        },
        "executions": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "executionId": {
                "type": "string",
                "format": "uuid"
              },
              "nodeId": {
                "type": "string",
                "minLength": 1
              },
              "attempt": {
                "type": "integer",
                "minimum": 1
              },
              "state": {
                "type": "string",
                "enum": [
                  "CLAIMED",
                  "RUNNING",
                  "SUCCEEDED",
                  "FAILED",
                  "UNKNOWN"
                ]
              }
            },
            "required": [
              "executionId",
              "nodeId",
              "attempt",
              "state"
            ]
          }
        },
        "results": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/TaskResult"
          }
        },
        "reviewIds": {
          "type": "array",
          "items": {
            "type": "string",
            "format": "uuid"
          }
        },
        "deliveries": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/DeliveryReceipt"
          }
        }
      },
      "required": [
        "envelope",
        "state",
        "version",
        "plan",
        "executions",
        "results",
        "reviewIds",
        "deliveries"
      ]
    }
  },
  "oneOf": [
    {
      "$ref": "#/$defs/InboundEvent"
    },
    {
      "$ref": "#/$defs/DispatchDecision"
    },
    {
      "$ref": "#/$defs/TaskEnvelope"
    },
    {
      "$ref": "#/$defs/ContextBundle"
    },
    {
      "$ref": "#/$defs/ExecutionPlan"
    },
    {
      "$ref": "#/$defs/ToolCall"
    },
    {
      "$ref": "#/$defs/ToolResult"
    },
    {
      "$ref": "#/$defs/TaskResult"
    },
    {
      "$ref": "#/$defs/ValidationDecision"
    },
    {
      "$ref": "#/$defs/WorkflowEvent"
    },
    {
      "$ref": "#/$defs/OutboundCommand"
    },
    {
      "$ref": "#/$defs/DeliveryReceipt"
    },
    {
      "$ref": "#/$defs/ReviewDecision"
    },
    {
      "$ref": "#/$defs/ContSealInput"
    },
    {
      "$ref": "#/$defs/ContSealData"
    },
    {
      "$ref": "#/$defs/FlowGraph"
    }
  ]
}
