{
    "openapi": "3.0.3",
    "info": {
        "title": "API сервиса «Артефакты»",
        "version": "1.0.0",
        "description": "API для создания и публикации веб-артефактов, управления файлами, состоянием и доступом. Токены владельцев выпускаются основным сервисом. Для браузерных запросов используются сессии и проверки доступа."
    },
    "servers": [
        {
            "url": "https://artifacts.delimer.ru"
        }
    ],
    "paths": {
        "/api/v1/health": {
            "get": {
                "summary": "Проверить доступность приложения",
                "responses": {
                    "200": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "service": {
                                            "type": "string"
                                        },
                                        "status": {
                                            "type": "string"
                                        },
                                        "api_version": {
                                            "type": "string"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": []
            }
        },
        "/api/v1/status": {
            "get": {
                "summary": "Проверить подключение к базе данных",
                "responses": {
                    "200": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "status": {
                                            "type": "string"
                                        },
                                        "database": {
                                            "type": "string"
                                        },
                                        "php_version": {
                                            "type": "string"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "OwnerToken": []
                    },
                    {
                        "BrowserSession": []
                    }
                ]
            }
        },
        "/api/v1/owner-tokens": {
            "post": {
                "summary": "Выпустить токен владельца; email должен быть подтверждён основным сервисом",
                "responses": {
                    "201": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "owner_id": {
                                            "type": "string"
                                        },
                                        "token_id": {
                                            "type": "string"
                                        },
                                        "token": {
                                            "type": "string"
                                        }
                                    },
                                    "required": [
                                        "owner_id",
                                        "token_id",
                                        "token"
                                    ]
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "MasterToken": []
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "owner_id": {
                                        "type": "string",
                                        "minLength": 1,
                                        "maxLength": 190
                                    },
                                    "email": {
                                        "type": "string",
                                        "format": "email"
                                    }
                                },
                                "required": [
                                    "owner_id"
                                ]
                            }
                        }
                    }
                }
            }
        },
        "/api/v1/owner-tokens/{token_id}": {
            "delete": {
                "summary": "Отозвать токен владельца",
                "responses": {
                    "204": {
                        "description": "Успешный ответ"
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "MasterToken": []
                    }
                ],
                "parameters": [
                    {
                        "name": "token_id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    }
                ]
            }
        },
        "/api/v1/share-contacts": {
            "get": {
                "summary": "Получить список контактов, которым ранее предоставлялся доступ",
                "responses": {
                    "200": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "emails": {
                                            "type": "array",
                                            "items": {
                                                "type": "string"
                                            }
                                        },
                                        "contacts": {
                                            "type": "array",
                                            "items": {
                                                "type": "object",
                                                "properties": {
                                                    "email": {
                                                        "type": "string",
                                                        "nullable": true
                                                    },
                                                    "telegram_username": {
                                                        "type": "string",
                                                        "nullable": true
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "OwnerToken": []
                    },
                    {
                        "BrowserSession": []
                    }
                ]
            }
        },
        "/api/v1/artifacts": {
            "get": {
                "summary": "Получить список своих артефактов и доступных по приглашению",
                "responses": {
                    "200": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "artifacts": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/Artifact"
                                            }
                                        },
                                        "pagination": {
                                            "type": "object",
                                            "properties": {
                                                "limit": {
                                                    "type": "integer"
                                                },
                                                "offset": {
                                                    "type": "integer"
                                                },
                                                "total": {
                                                    "type": "integer"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "OwnerToken": []
                    },
                    {
                        "BrowserSession": []
                    }
                ],
                "parameters": [
                    {
                        "name": "limit",
                        "in": "query",
                        "schema": {
                            "type": "integer",
                            "minimum": 1,
                            "maximum": 100,
                            "default": 20
                        }
                    },
                    {
                        "name": "offset",
                        "in": "query",
                        "schema": {
                            "type": "integer",
                            "minimum": 0,
                            "default": 0
                        }
                    },
                    {
                        "name": "status",
                        "in": "query",
                        "schema": {
                            "type": "string",
                            "enum": [
                                "draft",
                                "published"
                            ]
                        }
                    }
                ]
            },
            "post": {
                "summary": "Создать черновик артефакта от имени текущего владельца",
                "responses": {
                    "201": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "artifact": {
                                            "$ref": "#/components/schemas/Artifact"
                                        }
                                    },
                                    "required": [
                                        "artifact"
                                    ]
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "OwnerToken": []
                    },
                    {
                        "BrowserSession": []
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/CreateArtifact"
                            }
                        }
                    }
                }
            }
        },
        "/api/v1/artifacts/{id}": {
            "get": {
                "summary": "Получить сведения об артефакте",
                "responses": {
                    "200": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "artifact": {
                                            "$ref": "#/components/schemas/Artifact"
                                        }
                                    },
                                    "required": [
                                        "artifact"
                                    ]
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "OwnerToken": []
                    },
                    {
                        "BrowserSession": []
                    }
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    }
                ]
            },
            "patch": {
                "summary": "Изменить сведения об артефакте; режим доступа меняет только владелец",
                "responses": {
                    "200": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "artifact": {
                                            "$ref": "#/components/schemas/Artifact"
                                        }
                                    },
                                    "required": [
                                        "artifact"
                                    ]
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "OwnerToken": []
                    },
                    {
                        "BrowserSession": []
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "title": {
                                        "type": "string",
                                        "minLength": 1,
                                        "maxLength": 255
                                    },
                                    "description": {
                                        "type": "string"
                                    },
                                    "access_mode": {
                                        "$ref": "#/components/schemas/AccessMode"
                                    }
                                }
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    }
                ]
            },
            "delete": {
                "summary": "Удалить артефакт, его файлы и состояние (только владелец)",
                "responses": {
                    "204": {
                        "description": "Успешный ответ"
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "OwnerToken": []
                    },
                    {
                        "BrowserSession": []
                    }
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    }
                ]
            }
        },
        "/api/v1/artifacts/{id}/publish": {
            "post": {
                "summary": "Опубликовать артефакт (владелец или редактор)",
                "responses": {
                    "200": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "artifact": {
                                            "$ref": "#/components/schemas/Artifact"
                                        }
                                    },
                                    "required": [
                                        "artifact"
                                    ]
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "OwnerToken": []
                    },
                    {
                        "BrowserSession": []
                    }
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    }
                ]
            }
        },
        "/api/v1/artifacts/{id}/files": {
            "get": {
                "summary": "Получить список файлов артефакта",
                "responses": {
                    "200": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "files": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/File"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "OwnerToken": []
                    },
                    {
                        "BrowserSession": []
                    }
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    }
                ]
            }
        },
        "/api/v1/artifacts/{id}/files/{path}": {
            "get": {
                "summary": "Получить содержимое и версию файла",
                "responses": {
                    "200": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "file": {
                                            "$ref": "#/components/schemas/File"
                                        }
                                    },
                                    "required": [
                                        "file"
                                    ]
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "OwnerToken": []
                    },
                    {
                        "BrowserSession": []
                    }
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    },
                    {
                        "name": "path",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Relative file path; may contain directory separators."
                    }
                ]
            },
            "put": {
                "summary": "Создать или заменить файл (версия 0 создаёт новый файл)",
                "responses": {
                    "200": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "file": {
                                            "$ref": "#/components/schemas/File"
                                        }
                                    },
                                    "required": [
                                        "file"
                                    ]
                                }
                            }
                        }
                    },
                    "201": {
                        "description": "Файл создан",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "file": {
                                            "$ref": "#/components/schemas/File"
                                        }
                                    },
                                    "required": [
                                        "file"
                                    ]
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "OwnerToken": []
                    },
                    {
                        "BrowserSession": []
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "version": {
                                        "type": "integer",
                                        "minimum": 0
                                    },
                                    "content": {
                                        "type": "string",
                                        "description": "Maximum 512 KiB UTF-8"
                                    }
                                },
                                "required": [
                                    "version",
                                    "content"
                                ]
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    },
                    {
                        "name": "path",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Relative file path; may contain directory separators."
                    }
                ]
            },
            "delete": {
                "summary": "Удалить файл (кроме index.html; владелец или редактор)",
                "responses": {
                    "204": {
                        "description": "Успешный ответ"
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "OwnerToken": []
                    },
                    {
                        "BrowserSession": []
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "version": {
                                        "type": "integer",
                                        "minimum": 1
                                    }
                                },
                                "required": [
                                    "version"
                                ]
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    },
                    {
                        "name": "path",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Relative file path; may contain directory separators."
                    }
                ]
            }
        },
        "/api/v1/artifacts/{id}/state": {
            "get": {
                "summary": "Прочитать состояние артефакта",
                "responses": {
                    "200": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/State"
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "OwnerToken": []
                    },
                    {
                        "BrowserSession": []
                    }
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    }
                ]
            },
            "put": {
                "summary": "Атомарно заменить состояние артефакта (владелец или редактор)",
                "responses": {
                    "200": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/State"
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "OwnerToken": []
                    },
                    {
                        "BrowserSession": []
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "version": {
                                        "type": "integer",
                                        "minimum": 1
                                    },
                                    "data": {
                                        "oneOf": [
                                            {
                                                "type": "object"
                                            },
                                            {
                                                "type": "array",
                                                "items": {}
                                            }
                                        ]
                                    }
                                },
                                "required": [
                                    "version",
                                    "data"
                                ]
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    }
                ]
            },
            "patch": {
                "summary": "Атомарно изменить состояние артефакта (владелец или редактор)",
                "responses": {
                    "200": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/State"
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "OwnerToken": []
                    },
                    {
                        "BrowserSession": []
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "version": {
                                        "type": "integer",
                                        "minimum": 1
                                    },
                                    "operations": {
                                        "oneOf": [
                                            {
                                                "$ref": "#/components/schemas/PatchOperation"
                                            },
                                            {
                                                "type": "array",
                                                "minItems": 1,
                                                "maxItems": 100,
                                                "items": {
                                                    "$ref": "#/components/schemas/PatchOperation"
                                                }
                                            }
                                        ]
                                    }
                                },
                                "required": [
                                    "version",
                                    "operations"
                                ]
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    }
                ]
            }
        },
        "/runtime/{id}/state": {
            "get": {
                "summary": "Получить состояние опубликованного артефакта с проверкой доступа",
                "responses": {
                    "200": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/State"
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    },
                    {
                        "name": "X-Artifact-Runtime",
                        "in": "header",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "enum": [
                                "1"
                            ]
                        }
                    }
                ]
            },
            "put": {
                "summary": "Заменить состояние опубликованного артефакта с проверкой доступа",
                "responses": {
                    "200": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/State"
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "version": {
                                        "type": "integer",
                                        "minimum": 1
                                    },
                                    "data": {
                                        "oneOf": [
                                            {
                                                "type": "object"
                                            },
                                            {
                                                "type": "array",
                                                "items": {}
                                            }
                                        ]
                                    }
                                },
                                "required": [
                                    "version",
                                    "data"
                                ]
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    },
                    {
                        "name": "X-Artifact-Runtime",
                        "in": "header",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "enum": [
                                "1"
                            ]
                        }
                    },
                    {
                        "name": "X-CSRF-Token",
                        "in": "header",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ]
            },
            "patch": {
                "summary": "Изменить состояние опубликованного артефакта с проверкой доступа",
                "responses": {
                    "200": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/State"
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "version": {
                                        "type": "integer",
                                        "minimum": 1
                                    },
                                    "operations": {
                                        "oneOf": [
                                            {
                                                "$ref": "#/components/schemas/PatchOperation"
                                            },
                                            {
                                                "type": "array",
                                                "minItems": 1,
                                                "maxItems": 100,
                                                "items": {
                                                    "$ref": "#/components/schemas/PatchOperation"
                                                }
                                            }
                                        ]
                                    }
                                },
                                "required": [
                                    "version",
                                    "operations"
                                ]
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    },
                    {
                        "name": "X-Artifact-Runtime",
                        "in": "header",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "enum": [
                                "1"
                            ]
                        }
                    },
                    {
                        "name": "X-CSRF-Token",
                        "in": "header",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ]
            }
        },
        "/runtime/{id}/state/version": {
            "get": {
                "summary": "Получить версию состояния опубликованного артефакта",
                "responses": {
                    "200": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "version": {
                                            "type": "integer",
                                            "minimum": 1
                                        }
                                    },
                                    "required": [
                                        "version"
                                    ]
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    },
                    {
                        "name": "X-Artifact-Runtime",
                        "in": "header",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "enum": [
                                "1"
                            ]
                        }
                    }
                ]
            }
        },
        "/api/v1/artifacts/{id}/permissions": {
            "get": {
                "summary": "Получить список участников и ожидающих приглашений (только владелец)",
                "responses": {
                    "200": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "owner_id": {
                                            "type": "string"
                                        },
                                        "permissions": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/Permission"
                                            }
                                        },
                                        "pending_permissions": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/PendingPermission"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "OwnerToken": []
                    },
                    {
                        "BrowserSession": []
                    }
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    }
                ]
            },
            "post": {
                "summary": "Выдать или изменить роль доступа по ID, email или имени Telegram",
                "responses": {
                    "200": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "oneOf": [
                                        {
                                            "$ref": "#/components/schemas/Permission"
                                        },
                                        {
                                            "$ref": "#/components/schemas/PendingPermission"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "OwnerToken": []
                    },
                    {
                        "BrowserSession": []
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "owner_id": {
                                        "type": "string"
                                    },
                                    "email": {
                                        "type": "string",
                                        "format": "email"
                                    },
                                    "telegram_username": {
                                        "type": "string",
                                        "description": "@username or username; case-insensitive"
                                    },
                                    "role": {
                                        "type": "string",
                                        "enum": [
                                            "editor",
                                            "viewer"
                                        ]
                                    }
                                },
                                "required": [
                                    "role"
                                ]
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    }
                ]
            }
        },
        "/api/v1/artifacts/{id}/permissions/telegram/{username}": {
            "delete": {
                "summary": "Отозвать ожидающее подтверждения приглашение Telegram",
                "responses": {
                    "204": {
                        "description": "Успешный ответ"
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "OwnerToken": []
                    },
                    {
                        "BrowserSession": []
                    }
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    },
                    {
                        "name": "username",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ]
            }
        },
        "/api/v1/artifacts/{id}/permissions/{owner_id}": {
            "delete": {
                "summary": "Отозвать роль участника",
                "responses": {
                    "204": {
                        "description": "Успешный ответ"
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "OwnerToken": []
                    },
                    {
                        "BrowserSession": []
                    }
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    },
                    {
                        "name": "owner_id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ]
            }
        },
        "/auth/me": {
            "get": {
                "summary": "Получить текущую сессию браузера; вход не требуется",
                "responses": {
                    "200": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "owner_id": {
                                            "type": "string",
                                            "nullable": true
                                        },
                                        "email": {
                                            "type": "string",
                                            "nullable": true
                                        },
                                        "csrf_token": {
                                            "type": "string"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": []
            }
        },
        "/auth/magic-link": {
            "post": {
                "summary": "Запросить ссылку для входа по email (действует 15 минут)",
                "responses": {
                    "202": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "message": {
                                            "type": "string"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "email": {
                                        "type": "string",
                                        "format": "email"
                                    },
                                    "next": {
                                        "type": "string"
                                    }
                                },
                                "required": [
                                    "email"
                                ]
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "X-CSRF-Token",
                        "in": "header",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ]
            }
        },
        "/auth/telegram/start": {
            "post": {
                "summary": "Начать вход через Telegram или привязку Telegram к аккаунту",
                "responses": {
                    "200": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "url": {
                                            "type": "string",
                                            "format": "uri"
                                        }
                                    },
                                    "required": [
                                        "url"
                                    ]
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "mode": {
                                        "type": "string",
                                        "enum": [
                                            "login",
                                            "link"
                                        ],
                                        "default": "login"
                                    },
                                    "next": {
                                        "type": "string"
                                    }
                                }
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "X-CSRF-Token",
                        "in": "header",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ]
            }
        },
        "/auth/telegram/confirm": {
            "post": {
                "summary": "Подтвердить подключение Telegram к аккаунту",
                "responses": {
                    "200": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "status": {
                                            "type": "string"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "OwnerToken": []
                    },
                    {
                        "BrowserSession": []
                    }
                ],
                "parameters": [
                    {
                        "name": "X-CSRF-Token",
                        "in": "header",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ]
            }
        },
        "/auth/telegram/unlink": {
            "post": {
                "summary": "Отключить Telegram от аккаунта",
                "responses": {
                    "200": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "status": {
                                            "type": "string"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "OwnerToken": []
                    },
                    {
                        "BrowserSession": []
                    }
                ],
                "parameters": [
                    {
                        "name": "X-CSRF-Token",
                        "in": "header",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ]
            }
        },
        "/auth/telegram/email": {
            "post": {
                "summary": "Связать аккаунт Telegram с email",
                "responses": {
                    "200": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "status": {
                                            "type": "string"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "OwnerToken": []
                    },
                    {
                        "BrowserSession": []
                    }
                ],
                "parameters": [
                    {
                        "name": "X-CSRF-Token",
                        "in": "header",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ]
            }
        },
        "/auth/telegram/callback": {
            "get": {
                "summary": "Завершить вход через Telegram и проверить ответ провайдера",
                "security": [],
                "parameters": [
                    {
                        "name": "state",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "code",
                        "in": "query",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "error",
                        "in": "query",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Страница отмены входа"
                    },
                    "303": {
                        "description": "Перенаправление к аккаунту, артефакту или привязке email"
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/account/security": {
            "get": {
                "summary": "Открыть настройки аккаунта и подключённых способов входа",
                "security": [
                    {
                        "BrowserSession": []
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Страница настроек"
                    },
                    "303": {
                        "description": "Перенаправление на страницу входа"
                    }
                }
            }
        },
        "/auth/logout": {
            "post": {
                "summary": "Завершить сессию браузера",
                "responses": {
                    "200": {
                        "description": "Успешный ответ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "status": {
                                            "type": "string"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "security": [],
                "parameters": [
                    {
                        "name": "X-CSRF-Token",
                        "in": "header",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ]
            }
        },
        "/auth/verify": {
            "get": {
                "summary": "Показать подтверждение входа, не активируя ссылку",
                "security": [],
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "next",
                        "in": "query",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Страница подтверждения"
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            },
            "post": {
                "summary": "Подтвердить ссылку входа и создать новую сессию",
                "security": [],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/x-www-form-urlencoded": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "token": {
                                        "type": "string"
                                    },
                                    "csrf": {
                                        "type": "string"
                                    },
                                    "next": {
                                        "type": "string"
                                    }
                                },
                                "required": [
                                    "token",
                                    "csrf"
                                ]
                            }
                        }
                    }
                },
                "responses": {
                    "303": {
                        "description": "Перенаправление к аккаунту или артефакту"
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/login": {
            "get": {
                "summary": "Открыть страницу входа",
                "security": [],
                "parameters": [],
                "responses": {
                    "200": {
                        "description": "Страница в браузере"
                    },
                    "303": {
                        "description": "Перенаправление на вход, если требуется"
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/account": {
            "get": {
                "summary": "Открыть список своих и доступных артефактов",
                "security": [],
                "parameters": [],
                "responses": {
                    "200": {
                        "description": "Страница в браузере"
                    },
                    "303": {
                        "description": "Перенаправление на вход, если требуется"
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/a/{id}": {
            "get": {
                "summary": "Просмотреть опубликованный артефакт с проверкой прав доступа",
                "security": [],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Страница в браузере"
                    },
                    "303": {
                        "description": "Перенаправление на вход, если требуется"
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/account/artifacts/{id}/access": {
            "get": {
                "summary": "Открыть страницу управления доступом к артефакту (только владелец)",
                "security": [
                    {
                        "BrowserSession": []
                    }
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Страница управления доступом"
                    },
                    "303": {
                        "description": "Перенаправление на страницу входа"
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/render/{id}": {
            "post": {
                "summary": "Отобразить опубликованный артефакт в изолированном iframe",
                "servers": [
                    {
                        "url": "https://data.artifacts.delimer.ru"
                    }
                ],
                "security": [],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/x-www-form-urlencoded": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "ticket": {
                                        "type": "string",
                                        "pattern": "^[a-f0-9]{64}$"
                                    }
                                },
                                "required": [
                                    "ticket"
                                ]
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Изолированная HTML-страница с доступом к микрофону"
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/api/v1/artifacts/{id}/mcp-servers": {
            "get": {
                "summary": "Получить список MCP-серверов артефакта (только владелец)",
                "security": [],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Enabled connections and tool names",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "connections": {
                                            "type": "array",
                                            "items": {
                                                "type": "object",
                                                "properties": {
                                                    "id": {
                                                        "type": "string"
                                                    },
                                                    "type": {
                                                        "type": "string"
                                                    },
                                                    "url": {
                                                        "type": "string",
                                                        "format": "uri",
                                                        "nullable": true
                                                    },
                                                    "auth": {
                                                        "type": "string"
                                                    },
                                                    "tools": {
                                                        "type": "array",
                                                        "items": {
                                                            "type": "string"
                                                        }
                                                    },
                                                    "created_at": {
                                                        "type": "string"
                                                    },
                                                    "updated_at": {
                                                        "type": "string"
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/api/v1/artifacts/{id}/mcp-servers/{server}": {
            "put": {
                "summary": "Настроить HTTPS MCP-сервер для артефакта (только владелец)",
                "security": [],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    },
                    {
                        "name": "server",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-z][a-z0-9_-]{0,63}$"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "url": {
                                        "type": "string",
                                        "format": "uri"
                                    },
                                    "type": {
                                        "type": "string",
                                        "enum": [
                                            "https"
                                        ]
                                    },
                                    "auth": {
                                        "type": "string",
                                        "enum": [
                                            "oauth",
                                            "none"
                                        ]
                                    },
                                    "tools": {
                                        "type": "array",
                                        "items": {
                                            "type": "string"
                                        }
                                    }
                                },
                                "required": [
                                    "url",
                                    "type",
                                    "auth"
                                ]
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Connection saved"
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            },
            "delete": {
                "summary": "Отключить MCP-сервер артефакта (только владелец)",
                "security": [],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    },
                    {
                        "name": "server",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-z][a-z0-9_-]{0,63}$"
                        }
                    }
                ],
                "responses": {
                    "204": {
                        "description": "Connection removed"
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/runtime/{id}/mcp/tools": {
            "get": {
                "summary": "Получить список разрешённых инструментов MCP",
                "security": [],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    },
                    {
                        "name": "server",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "X-Artifact-Runtime",
                        "in": "header",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "enum": [
                                "1"
                            ]
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Allowed tool names and input schemas"
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/runtime/{id}/mcp/call": {
            "post": {
                "summary": "Вызвать разрешённый инструмент MCP с проверкой доступа",
                "security": [],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    },
                    {
                        "name": "X-Artifact-Runtime",
                        "in": "header",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "enum": [
                                "1"
                            ]
                        }
                    },
                    {
                        "name": "X-CSRF-Token",
                        "in": "header",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "server": {
                                        "type": "string"
                                    },
                                    "tool": {
                                        "type": "string"
                                    },
                                    "arguments": {
                                        "type": "object"
                                    }
                                },
                                "required": [
                                    "server",
                                    "tool",
                                    "arguments"
                                ]
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "MCP tool result"
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/runtime/{id}/mcp/servers": {
            "post": {
                "summary": "Подключить HTTPS MCP-сервер к опубликованному артефакту (только владелец)",
                "security": [],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{32}$"
                        }
                    },
                    {
                        "name": "X-Artifact-Runtime",
                        "in": "header",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "enum": [
                                "1"
                            ]
                        }
                    },
                    {
                        "name": "X-CSRF-Token",
                        "in": "header",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "id": {
                                        "type": "string",
                                        "pattern": "^[a-z][a-z0-9_-]{0,63}$"
                                    },
                                    "type": {
                                        "type": "string",
                                        "enum": [
                                            "https"
                                        ]
                                    },
                                    "url": {
                                        "type": "string",
                                        "format": "uri"
                                    },
                                    "auth": {
                                        "type": "string",
                                        "enum": [
                                            "oauth",
                                            "none"
                                        ]
                                    },
                                    "tools": {
                                        "type": "array",
                                        "items": {
                                            "type": "string"
                                        }
                                    }
                                },
                                "required": [
                                    "id",
                                    "type",
                                    "url",
                                    "auth"
                                ]
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Registered MCP server"
                    },
                    "default": {
                        "description": "Ошибка",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "securitySchemes": {
            "MasterToken": {
                "type": "http",
                "scheme": "bearer"
            },
            "OwnerToken": {
                "type": "http",
                "scheme": "bearer"
            },
            "BrowserSession": {
                "type": "apiKey",
                "in": "cookie",
                "name": "__Host-artifact_session"
            }
        },
        "schemas": {
            "Error": {
                "type": "object",
                "properties": {
                    "error": {
                        "type": "object",
                        "properties": {
                            "code": {
                                "type": "string"
                            },
                            "message": {
                                "type": "string"
                            }
                        },
                        "required": [
                            "code",
                            "message"
                        ]
                    }
                },
                "required": [
                    "error"
                ]
            },
            "AccessMode": {
                "type": "string",
                "enum": [
                    "public",
                    "authenticated",
                    "private"
                ],
                "default": "private"
            },
            "Artifact": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "string"
                    },
                    "owner_id": {
                        "type": "string"
                    },
                    "title": {
                        "type": "string"
                    },
                    "description": {
                        "type": "string"
                    },
                    "status": {
                        "type": "string",
                        "enum": [
                            "draft",
                            "published"
                        ]
                    },
                    "access_mode": {
                        "$ref": "#/components/schemas/AccessMode"
                    },
                    "role": {
                        "type": "string",
                        "enum": [
                            "owner",
                            "editor",
                            "viewer"
                        ]
                    },
                    "url": {
                        "type": "string",
                        "format": "uri"
                    },
                    "created_at": {
                        "type": "string"
                    },
                    "updated_at": {
                        "type": "string"
                    },
                    "published_at": {
                        "type": "string",
                        "nullable": true
                    }
                }
            },
            "CreateArtifact": {
                "type": "object",
                "properties": {
                    "title": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 255
                    },
                    "description": {
                        "type": "string"
                    },
                    "access_mode": {
                        "$ref": "#/components/schemas/AccessMode"
                    },
                    "files": {
                        "type": "object",
                        "maxProperties": 50,
                        "additionalProperties": {
                            "type": "string"
                        },
                        "description": "index.html required; HTML/CSS/JS; 1 MiB total"
                    },
                    "initial_state": {
                        "oneOf": [
                            {
                                "type": "object"
                            },
                            {
                                "type": "array",
                                "items": {}
                            }
                        ]
                    }
                },
                "required": [
                    "title",
                    "files"
                ]
            },
            "File": {
                "type": "object",
                "properties": {
                    "path": {
                        "type": "string"
                    },
                    "version": {
                        "type": "integer",
                        "minimum": 1
                    },
                    "content": {
                        "type": "string"
                    },
                    "created_at": {
                        "type": "string"
                    },
                    "updated_at": {
                        "type": "string"
                    }
                }
            },
            "State": {
                "type": "object",
                "properties": {
                    "data": {
                        "oneOf": [
                            {
                                "type": "object"
                            },
                            {
                                "type": "array",
                                "items": {}
                            }
                        ]
                    },
                    "version": {
                        "type": "integer",
                        "minimum": 1
                    }
                },
                "required": [
                    "data",
                    "version"
                ]
            },
            "PatchOperation": {
                "type": "object",
                "properties": {
                    "op": {
                        "type": "string",
                        "enum": [
                            "add",
                            "remove",
                            "replace"
                        ]
                    },
                    "path": {
                        "type": "string"
                    },
                    "value": {}
                },
                "required": [
                    "op",
                    "path"
                ]
            },
            "PendingPermission": {
                "type": "object",
                "properties": {
                    "owner_id": {
                        "type": "string",
                        "nullable": true
                    },
                    "telegram_username": {
                        "type": "string"
                    },
                    "role": {
                        "type": "string",
                        "enum": [
                            "editor",
                            "viewer"
                        ]
                    },
                    "pending": {
                        "type": "boolean"
                    },
                    "created_at": {
                        "type": "string"
                    }
                }
            },
            "Permission": {
                "type": "object",
                "properties": {
                    "owner_id": {
                        "type": "string"
                    },
                    "email": {
                        "type": "string",
                        "nullable": true
                    },
                    "telegram_username": {
                        "type": "string",
                        "nullable": true
                    },
                    "role": {
                        "type": "string",
                        "enum": [
                            "editor",
                            "viewer"
                        ]
                    },
                    "created_at": {
                        "type": "string"
                    }
                }
            }
        }
    }
}
