{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://github.com/andrewhuot/headless-chat-sdk/schemas/computer-use.schema.json",
  "title": "Computer-use protocol",
  "description": "Wire envelopes for the `computer_use` server tool, the proxy SSE stream, and the per-action decision channel. Mirrors packages/gecx-chat/src/tools/computerUse.ts and apps/proxy-reference/src/computerUse/. The proxy is the authoritative enforcement point for allowlist + duration + action limits; this schema describes only the transport shapes.",
  "definitions": {
    "ComputerUseInput": {
      "type": "object",
      "required": ["goal", "urls"],
      "additionalProperties": false,
      "properties": {
        "goal": { "type": "string", "minLength": 1, "maxLength": 1000 },
        "urls": {
          "type": "array",
          "minItems": 1,
          "maxItems": 16,
          "items": { "type": "string", "format": "uri", "minLength": 1, "maxLength": 2048 }
        },
        "maxActions": { "type": "integer", "minimum": 1, "maximum": 200 },
        "maxDurationMs": { "type": "integer", "minimum": 1000, "maximum": 1800000 },
        "hints": { "type": "object" }
      }
    },
    "ComputerUseOutput": {
      "type": "object",
      "required": ["computerUseSessionId", "status", "summary", "actionsExecuted", "durationMs"],
      "additionalProperties": true,
      "properties": {
        "computerUseSessionId": { "type": "string", "minLength": 1 },
        "status": {
          "type": "string",
          "enum": ["completed", "aborted", "duration_exceeded", "action_limit_exceeded"]
        },
        "summary": { "type": "string" },
        "lastUrl": { "type": "string" },
        "actionsExecuted": { "type": "integer", "minimum": 0 },
        "durationMs": { "type": "integer", "minimum": 0 },
        "evidence": { "type": "object" }
      }
    },
    "ComputerUseStreamEvent": {
      "oneOf": [
        {
          "type": "object",
          "required": ["type", "computerUseSessionId", "timestamp"],
          "additionalProperties": false,
          "properties": {
            "type": { "const": "session.started" },
            "computerUseSessionId": { "type": "string" },
            "timestamp": { "type": "string", "format": "date-time" }
          }
        },
        {
          "type": "object",
          "required": ["type", "actionId", "actionType", "riskLevel", "summary", "timestamp"],
          "additionalProperties": false,
          "properties": {
            "type": { "const": "action" },
            "actionId": { "type": "string" },
            "actionType": { "$ref": "governance.schema.json#/definitions/ComputerUseActionType" },
            "riskLevel": { "$ref": "governance.schema.json#/definitions/ComputerUseActionRiskLevel" },
            "url": { "type": "string" },
            "summary": { "type": "string" },
            "timestamp": { "type": "string", "format": "date-time" }
          }
        },
        {
          "type": "object",
          "required": ["type", "url", "timestamp"],
          "additionalProperties": false,
          "properties": {
            "type": { "const": "screenshot" },
            "url": { "type": "string" },
            "width": { "type": "integer", "minimum": 1 },
            "height": { "type": "integer", "minimum": 1 },
            "timestamp": { "type": "string", "format": "date-time" }
          }
        },
        {
          "type": "object",
          "required": ["type", "actionId", "actionType", "summary", "timestamp"],
          "additionalProperties": false,
          "properties": {
            "type": { "const": "approval_required" },
            "actionId": { "type": "string" },
            "actionType": { "$ref": "governance.schema.json#/definitions/ComputerUseActionType" },
            "summary": { "type": "string" },
            "url": { "type": "string" },
            "timestamp": { "type": "string", "format": "date-time" }
          }
        },
        {
          "type": "object",
          "required": ["type", "actionId", "decision", "timestamp"],
          "additionalProperties": false,
          "properties": {
            "type": { "const": "approval_resolved" },
            "actionId": { "type": "string" },
            "decision": { "type": "string", "enum": ["approve", "deny"] },
            "timestamp": { "type": "string", "format": "date-time" }
          }
        },
        {
          "type": "object",
          "required": ["type", "status", "summary", "timestamp"],
          "additionalProperties": false,
          "properties": {
            "type": { "const": "session.ended" },
            "status": {
              "type": "string",
              "enum": ["completed", "aborted", "duration_exceeded", "action_limit_exceeded", "failed"]
            },
            "summary": { "type": "string" },
            "timestamp": { "type": "string", "format": "date-time" }
          }
        },
        {
          "type": "object",
          "required": ["type", "code", "message", "timestamp"],
          "additionalProperties": false,
          "properties": {
            "type": { "const": "error" },
            "code": { "type": "string" },
            "message": { "type": "string" },
            "timestamp": { "type": "string", "format": "date-time" }
          }
        }
      ]
    },
    "ComputerUseControlRequest": {
      "oneOf": [
        {
          "type": "object",
          "required": ["action", "computerUseSessionId"],
          "additionalProperties": false,
          "properties": {
            "action": { "const": "abort" },
            "computerUseSessionId": { "type": "string" },
            "reason": { "type": "string" }
          }
        },
        {
          "type": "object",
          "required": ["action", "computerUseSessionId", "actionId", "decision"],
          "additionalProperties": false,
          "properties": {
            "action": { "const": "decision" },
            "computerUseSessionId": { "type": "string" },
            "actionId": { "type": "string" },
            "decision": { "type": "string", "enum": ["approve", "deny"] }
          }
        }
      ]
    }
  }
}
