{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "apiVersion": {
      "type": "number",
      "const": 1
    },
    "minHostVersion": {
      "type": "integer",
      "exclusiveMinimum": 0,
      "maximum": 9007199254740991
    },
    "localizations": {
      "type": "object",
      "propertyNames": {
        "type": "string",
        "enum": [
          "zh-Hans",
          "zh-Hant",
          "en",
          "ja",
          "ko"
        ]
      },
      "additionalProperties": {
        "type": "object",
        "properties": {
          "roles": {
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 60
                },
                "description": {
                  "type": "string",
                  "maxLength": 300
                }
              },
              "additionalProperties": false
            }
          },
          "fields": {
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {
              "type": "object",
              "properties": {
                "label": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 80
                },
                "help": {
                  "type": "string",
                  "maxLength": 500
                },
                "options": {
                  "type": "object",
                  "propertyNames": {
                    "type": "string",
                    "maxLength": 80
                  },
                  "additionalProperties": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  }
                }
              },
              "additionalProperties": false
            }
          },
          "actions": {
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {
              "type": "object",
              "properties": {
                "title": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 80
                },
                "description": {
                  "type": "string",
                  "maxLength": 500
                },
                "parameters": {
                  "type": "object",
                  "propertyNames": {
                    "type": "string"
                  },
                  "additionalProperties": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  }
                }
              },
              "additionalProperties": false
            }
          }
        },
        "additionalProperties": false
      }
    },
    "ui": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "web"
            },
            "entryUrl": {
              "type": "string",
              "maxLength": 2048,
              "format": "uri"
            },
            "bridgeApi": {
              "type": "number",
              "const": 1
            },
            "externalOrigins": {
              "maxItems": 8,
              "type": "array",
              "items": {
                "type": "string",
                "maxLength": 2048,
                "format": "uri"
              }
            },
            "legacyFallback": {
              "type": "string",
              "enum": [
                "actions",
                "unavailable"
              ]
            },
            "navigationBar": {
              "type": "boolean"
            },
            "launchTicket": {
              "type": "boolean"
            }
          },
          "required": [
            "type",
            "entryUrl",
            "bridgeApi",
            "externalOrigins",
            "legacyFallback"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "bundled"
            },
            "entryPath": {
              "default": "index.html",
              "type": "string",
              "pattern": "^(?!\\/)(?!.*\\.\\.)[A-Za-z0-9._/-]{1,200}\\.html$"
            },
            "bridgeApi": {
              "type": "number",
              "const": 1
            },
            "externalOrigins": {
              "maxItems": 8,
              "type": "array",
              "items": {
                "type": "string",
                "maxLength": 2048,
                "format": "uri"
              }
            },
            "legacyFallback": {
              "type": "string",
              "const": "unavailable"
            }
          },
          "required": [
            "type",
            "bridgeApi",
            "externalOrigins",
            "legacyFallback"
          ],
          "additionalProperties": false
        }
      ]
    },
    "connectionProviders": {
      "maxItems": 1,
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "ringhi-core"
        ]
      }
    },
    "voiceProvider": {
      "type": "string",
      "enum": [
        "core-voice-agent",
        "webhook"
      ]
    },
    "roles": {
      "default": [
        {
          "key": "viewer",
          "name": "查看",
          "description": "查看应用内容和结果",
          "permissions": [
            "app.view"
          ]
        },
        {
          "key": "operator",
          "name": "使用",
          "description": "查看内容并使用应用",
          "permissions": [
            "app.view",
            "app.use"
          ]
        },
        {
          "key": "manager",
          "name": "管理",
          "description": "使用应用并管理应用配置",
          "permissions": [
            "app.view",
            "app.use",
            "app.configure"
          ]
        }
      ],
      "minItems": 1,
      "maxItems": 20,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9.-]{0,39}$"
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 60
          },
          "description": {
            "default": "",
            "type": "string",
            "maxLength": 300
          },
          "permissions": {
            "minItems": 1,
            "maxItems": 50,
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9.-]{0,79}$"
            }
          }
        },
        "required": [
          "key",
          "name",
          "permissions"
        ],
        "additionalProperties": false
      }
    },
    "conversationModes": {
      "default": [],
      "maxItems": 2,
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "voice",
          "text"
        ]
      }
    },
    "textAction": {
      "type": "string",
      "maxLength": 64
    },
    "actions": {
      "default": [],
      "maxItems": 20,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9.-]{0,63}$"
          },
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "description": {
            "type": "string",
            "maxLength": 500
          },
          "requiredPermission": {
            "default": "app.use",
            "type": "string",
            "pattern": "^[a-z][a-z0-9.-]{0,79}$"
          },
          "parameters": {
            "maxItems": 20,
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string",
                  "pattern": "^[a-zA-Z][a-zA-Z0-9_]{0,39}$"
                },
                "title": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 80
                },
                "type": {
                  "type": "string",
                  "enum": [
                    "string",
                    "number",
                    "boolean"
                  ]
                },
                "required": {
                  "default": false,
                  "type": "boolean"
                }
              },
              "required": [
                "name",
                "title",
                "type"
              ],
              "additionalProperties": false
            }
          },
          "confirm": {
            "type": "boolean"
          }
        },
        "required": [
          "name",
          "title",
          "description",
          "parameters"
        ],
        "additionalProperties": false
      }
    },
    "mode": {
      "type": "string",
      "enum": [
        "observer",
        "transform",
        "answer",
        "workspace"
      ]
    },
    "runtime": {
      "type": "string",
      "enum": [
        "builtin",
        "webhook",
        "web",
        "hosted"
      ]
    },
    "handler": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9.-]{1,99}$"
    },
    "permissions": {
      "maxItems": 24,
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "sim.vowifi.manage",
          "transcript.read",
          "audio.read",
          "audio.transform",
          "ui.write",
          "summary.write",
          "calls.answer",
          "recordings.manage",
          "recordings.read",
          "notes.read",
          "notes.write",
          "actions.invoke",
          "sms.read",
          "sms.send",
          "sms.messages.read",
          "sms.messages.send",
          "calls.read",
          "calls.control",
          "audio.stream",
          "sim.read",
          "sim.manage",
          "device.read",
          "device.configure",
          "network.custom"
        ]
      }
    },
    "optionalPermissions": {
      "maxItems": 24,
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "sim.vowifi.manage",
          "transcript.read",
          "audio.read",
          "audio.transform",
          "ui.write",
          "summary.write",
          "calls.answer",
          "recordings.manage",
          "recordings.read",
          "notes.read",
          "notes.write",
          "actions.invoke",
          "sms.read",
          "sms.send",
          "sms.messages.read",
          "sms.messages.send",
          "calls.read",
          "calls.control",
          "audio.stream",
          "sim.read",
          "sim.manage",
          "device.read",
          "device.configure",
          "network.custom"
        ]
      }
    },
    "events": {
      "maxItems": 4,
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "sms.received",
          "call.incoming",
          "call.outgoing",
          "call.ended"
        ]
      }
    },
    "schedules": {
      "maxItems": 5,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9.-]{0,63}$"
          },
          "everyMinutes": {
            "type": "integer",
            "minimum": 5,
            "maximum": 1440
          }
        },
        "required": [
          "name",
          "everyMinutes"
        ],
        "additionalProperties": false
      }
    },
    "network": {
      "type": "object",
      "properties": {
        "origins": {
          "maxItems": 20,
          "type": "array",
          "items": {
            "type": "string",
            "maxLength": 2048,
            "format": "uri"
          }
        }
      },
      "required": [
        "origins"
      ],
      "additionalProperties": false
    },
    "userProfile": {
      "type": "boolean",
      "const": true
    },
    "triggers": {
      "maxItems": 3,
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "call.connected",
          "transcript.final",
          "call.ended"
        ]
      }
    },
    "fields": {
      "maxItems": 20,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string",
            "pattern": "^[a-zA-Z][a-zA-Z0-9]{0,39}$"
          },
          "label": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "type": {
            "type": "string",
            "enum": [
              "text",
              "secret",
              "select",
              "model"
            ]
          },
          "required": {
            "default": false,
            "type": "boolean"
          },
          "options": {
            "default": [],
            "maxItems": 30,
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "value": {
                  "type": "string",
                  "maxLength": 80
                },
                "label": {
                  "type": "string",
                  "maxLength": 80
                }
              },
              "required": [
                "value",
                "label"
              ]
            }
          },
          "defaultValue": {
            "default": "",
            "type": "string",
            "maxLength": 1000
          },
          "help": {
            "default": "",
            "type": "string",
            "maxLength": 500
          }
        },
        "required": [
          "key",
          "label",
          "type"
        ],
        "additionalProperties": false
      }
    },
    "systemFields": {
      "maxItems": 20,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string",
            "pattern": "^[a-zA-Z][a-zA-Z0-9]{0,39}$"
          },
          "label": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "type": {
            "type": "string",
            "enum": [
              "text",
              "secret",
              "select",
              "model"
            ]
          },
          "required": {
            "default": false,
            "type": "boolean"
          },
          "options": {
            "default": [],
            "maxItems": 30,
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "value": {
                  "type": "string",
                  "maxLength": 80
                },
                "label": {
                  "type": "string",
                  "maxLength": 80
                }
              },
              "required": [
                "value",
                "label"
              ]
            }
          },
          "defaultValue": {
            "default": "",
            "type": "string",
            "maxLength": 1000
          },
          "help": {
            "default": "",
            "type": "string",
            "maxLength": 500
          }
        },
        "required": [
          "key",
          "label",
          "type"
        ],
        "additionalProperties": false
      }
    },
    "endpoint": {
      "type": "string",
      "maxLength": 2048,
      "format": "uri"
    },
    "privacyUrl": {
      "type": "string",
      "maxLength": 2048,
      "format": "uri"
    },
    "pricing": {
      "type": "object",
      "properties": {
        "model": {
          "type": "string",
          "const": "free"
        },
        "currency": {
          "type": "string",
          "const": "CNY"
        },
        "unitAmountMinor": {
          "type": "number",
          "const": 0
        },
        "providerBilledSeparately": {
          "default": false,
          "type": "boolean"
        }
      },
      "required": [
        "model",
        "currency",
        "unitAmountMinor"
      ],
      "additionalProperties": false
    }
  },
  "required": [
    "apiVersion",
    "mode",
    "runtime",
    "handler",
    "permissions",
    "triggers",
    "fields",
    "pricing"
  ],
  "additionalProperties": false,
  "$comment": "Structural input validation only. Cross-field permissions, public URL/DNS approval, origin binding and runtime capabilities are enforced by the server.",
  "title": "RingHi Manifest input, permission tiers and hosted runtime (API v1)"
}
