{
  "openapi": "3.1.0",
  "info": {
    "title": "i2x encrypted source storage consent API",
    "version": "1.4.0",
    "description": "Manage separate permission for encrypted retention of an observed source snapshot. These operations do not upload source or start execution."
  },
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/api/runs/{runId}/storage-consents": {
      "parameters": [
        {
          "in": "path",
          "name": "runId",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "listStorageConsents",
        "responses": {
          "200": {
            "description": "Redacted storage permissions",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/History"
                }
              }
            }
          },
          "400": {
            "description": "Request refused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Request refused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Request refused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Request refused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Request refused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "grantStorageConsent",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateConsent"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Storage permission",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "consent"
                  ],
                  "properties": {
                    "consent": {
                      "$ref": "#/components/schemas/Consent"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Request refused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Request refused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Request refused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Request refused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Request refused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/runs/{runId}/storage-consents/{storageConsentDigest}/revoke": {
      "parameters": [
        {
          "in": "path",
          "name": "runId",
          "required": true,
          "schema": {
            "type": "string"
          }
        },
        {
          "in": "path",
          "name": "storageConsentDigest",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          }
        }
      ],
      "post": {
        "operationId": "revokeStorageConsent",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "maxProperties": 0
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Revoked permission",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "consent"
                  ],
                  "properties": {
                    "consent": {
                      "$ref": "#/components/schemas/Consent"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Request refused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Request refused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Request refused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Request refused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Request refused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/runs/{runId}/storage-consents/{storageConsentDigest}/stage": {
      "parameters": [
        {
          "in": "path",
          "name": "runId",
          "required": true,
          "schema": {
            "type": "string"
          }
        },
        {
          "in": "path",
          "name": "storageConsentDigest",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          }
        }
      ],
      "post": {
        "operationId": "stageConsentedSource",
        "description": "Encrypt and retain the current session memory snapshot using separate storage consent. No source upload is accepted.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "maxProperties": 0
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Storage receipt",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "consent",
                    "transfer"
                  ],
                  "properties": {
                    "consent": {
                      "$ref": "#/components/schemas/Consent"
                    },
                    "transfer": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "sourcePackageId",
                        "expiresAtEpochSeconds",
                        "executionAuthorized"
                      ],
                      "properties": {
                        "sourcePackageId": {
                          "type": "string"
                        },
                        "expiresAtEpochSeconds": {
                          "type": "integer"
                        },
                        "executionAuthorized": {
                          "const": false
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Request refused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Request refused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Request refused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Request refused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Request refused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Request refused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Request refused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Consent": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "storageConsentDigest",
          "sourceConsentDigest",
          "runId",
          "projectId",
          "snapshotDigest",
          "sourceDigest",
          "packageDigest",
          "retentionSeconds",
          "issuedAtEpochSeconds",
          "expiresAtEpochSeconds",
          "status",
          "revoked",
          "expired",
          "consumed",
          "stored",
          "failureReason",
          "cleanupRequired",
          "scope",
          "executionAuthorized",
          "backupAuthorized",
          "storageState",
          "cleanupEvidence",
          "stageAvailable",
          "memoryExpiresAtEpochSeconds"
        ],
        "properties": {
          "storageConsentDigest": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "sourceConsentDigest": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "runId": {
            "type": "string"
          },
          "projectId": {
            "type": "string"
          },
          "snapshotDigest": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "sourceDigest": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "packageDigest": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "retentionSeconds": {
            "type": "integer",
            "minimum": 3600,
            "maximum": 86400
          },
          "issuedAtEpochSeconds": {
            "type": "integer"
          },
          "expiresAtEpochSeconds": {
            "type": "integer"
          },
          "status": {
            "type": "string",
            "enum": [
              "authorized",
              "started",
              "stored",
              "failed"
            ]
          },
          "revoked": {
            "type": "boolean"
          },
          "expired": {
            "type": "boolean"
          },
          "consumed": {
            "type": "boolean"
          },
          "stored": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "sourcePackageId",
                  "expiresAtEpochSeconds"
                ],
                "properties": {
                  "sourcePackageId": {
                    "type": "string"
                  },
                  "expiresAtEpochSeconds": {
                    "type": "integer"
                  }
                }
              }
            ]
          },
          "failureReason": {
            "type": [
              "string",
              "null"
            ]
          },
          "cleanupRequired": {
            "type": "boolean"
          },
          "scope": {
            "const": "encrypted_source_storage_only"
          },
          "executionAuthorized": {
            "const": false
          },
          "backupAuthorized": {
            "const": false
          },
          "storageState": {
            "enum": [
              "not_stored",
              "unverified",
              "available",
              "deleted"
            ]
          },
          "cleanupEvidence": {
            "$ref": "#/components/schemas/CleanupEvidence"
          },
          "stageAvailable": {
            "type": "boolean"
          },
          "memoryExpiresAtEpochSeconds": {
            "type": [
              "integer",
              "null"
            ]
          }
        }
      },
      "CreateConsent": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "sourceConsentDigest",
          "retentionSeconds",
          "idempotencyKey",
          "acknowledgement"
        ],
        "properties": {
          "sourceConsentDigest": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "accountId": {
            "type": "string",
            "description": "Optional. Defaults to the workspace account used by the current usage ledger."
          },
          "retentionSeconds": {
            "type": "integer",
            "minimum": 3600,
            "maximum": 86400
          },
          "idempotencyKey": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{16,128}$"
          },
          "acknowledgement": {
            "const": "ALLOW_ENCRYPTED_SOURCE_STAGING_FOR_THIS_RUN"
          }
        }
      },
      "History": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "version",
          "runId",
          "consents",
          "sourceUploadEndpointAvailable",
          "executionAuthorized",
          "backupAuthorized",
          "projectionDigest",
          "grantContext",
          "sourceStageEndpointAvailable"
        ],
        "properties": {
          "version": {
            "const": "i2x-storage-consents/1.4.0"
          },
          "runId": {
            "type": "string"
          },
          "consents": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Consent"
            }
          },
          "sourceUploadEndpointAvailable": {
            "const": false
          },
          "executionAuthorized": {
            "const": false
          },
          "backupAuthorized": {
            "const": false
          },
          "projectionDigest": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "grantContext": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "canGrant",
              "canRevoke",
              "reasonCode",
              "maximumLifetimeSeconds",
              "storageAvailableBytes",
              "retentionOptionsSeconds",
              "snapshots"
            ],
            "properties": {
              "canGrant": {
                "type": "boolean"
              },
              "canRevoke": {
                "type": "boolean"
              },
              "reasonCode": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "maximumLifetimeSeconds": {
                "type": "integer",
                "minimum": 0,
                "maximum": 300
              },
              "storageAvailableBytes": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0
              },
              "retentionOptionsSeconds": {
                "type": "array",
                "items": {
                  "type": "integer",
                  "enum": [
                    3600,
                    21600,
                    86400
                  ]
                }
              },
              "snapshots": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "sourceConsentDigest",
                    "snapshotDigest",
                    "commitSha",
                    "fileCount",
                    "totalBytes"
                  ],
                  "properties": {
                    "sourceConsentDigest": {
                      "type": "string",
                      "pattern": "^[a-f0-9]{64}$"
                    },
                    "snapshotDigest": {
                      "type": "string",
                      "pattern": "^[a-f0-9]{64}$"
                    },
                    "commitSha": {
                      "type": "string",
                      "pattern": "^[a-f0-9]{40}$"
                    },
                    "fileCount": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "totalBytes": {
                      "type": "integer",
                      "minimum": 0
                    }
                  }
                }
              }
            }
          },
          "sourceStageEndpointAvailable": {
            "type": "boolean"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          }
        }
      },
      "CleanupEvidence": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "status",
          "kind",
          "receiptDigest",
          "observedAtEpochSeconds",
          "physicalRemoval",
          "assurance",
          "independentVerification"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "not_started",
              "not_requested",
              "required",
              "unverified",
              "confirmed"
            ]
          },
          "kind": {
            "enum": [
              null,
              "artifact_deletion",
              "local_orphan_absence"
            ]
          },
          "receiptDigest": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^[a-f0-9]{64}$"
          },
          "observedAtEpochSeconds": {
            "type": [
              "integer",
              "null"
            ]
          },
          "physicalRemoval": {
            "enum": [
              null,
              "confirmed",
              "shared_blob_retained"
            ]
          },
          "assurance": {
            "enum": [
              "none",
              "runtime_observation"
            ]
          },
          "independentVerification": {
            "const": false
          }
        }
      }
    }
  }
}
