{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/callidus-legal-ai/json-schema/callidus-legal-ai-draft-request-schema.json",
  "title": "DraftRequest",
  "description": "Everything the draft endpoint needs to write one reply.",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/callidus-legal-ai-addin-outlook-api-openapi.yml#/components/schemas/DraftRequest",
  "properties": {
    "matter_id": {
      "type": "string",
      "title": "Matter Id"
    },
    "instruction": {
      "type": "string",
      "maxLength": 500,
      "minLength": 1,
      "title": "Instruction"
    },
    "conversation_id": {
      "anyOf": [
        {
          "type": "string",
          "maxLength": 1024
        },
        {
          "type": "null"
        }
      ],
      "title": "Conversation Id",
      "description": "Graph conversation id of the open thread. When present the server fetches the thread from Graph, which yields real sender, recipient, date and body fields; ``thread`` below is then only a fallback."
    },
    "thread": {
      "$ref": "#/$defs/DraftThread",
      "description": "The thread as the pane read it out of the compose window. Used only when Graph cannot supply it — the quoted block's shape differs per Outlook client, so it is the less reliable of the two sources.",
      "default": {
        "subject": "",
        "messages": []
      }
    },
    "context": {
      "$ref": "#/$defs/DraftContextSelection",
      "default": {
        "thread": true,
        "matter_files": true,
        "matter_emails": true
      }
    },
    "sender": {
      "$ref": "#/$defs/DraftSender",
      "default": {}
    },
    "refine": {
      "anyOf": [
        {
          "$ref": "#/$defs/DraftRefine"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "type": "object",
  "required": [
    "matter_id",
    "instruction"
  ],
  "$defs": {
    "DraftContextSelection": {
      "properties": {
        "thread": {
          "type": "boolean",
          "title": "Thread",
          "default": true
        },
        "matter_files": {
          "type": "boolean",
          "title": "Matter Files",
          "default": true
        },
        "matter_emails": {
          "type": "boolean",
          "title": "Matter Emails",
          "default": true
        }
      },
      "type": "object",
      "title": "DraftContextSelection",
      "description": "Which sources the user left checked in the pane."
    },
    "DraftRefine": {
      "properties": {
        "mode": {
          "type": "string",
          "enum": [
            "shorter",
            "more_formal",
            "more_direct",
            "custom"
          ],
          "title": "Mode"
        },
        "instruction": {
          "anyOf": [
            {
              "type": "string",
              "maxLength": 500
            },
            {
              "type": "null"
            }
          ],
          "title": "Instruction",
          "description": "The user's own wording. Required when mode is custom."
        },
        "previous_draft": {
          "type": "string",
          "maxLength": 30000,
          "minLength": 1,
          "title": "Previous Draft"
        }
      },
      "type": "object",
      "required": [
        "mode",
        "previous_draft"
      ],
      "title": "DraftRefine",
      "description": "A follow-up instruction applied to a draft the user already has.\n\n``previous_draft`` is sent by the pane rather than held server-side: the pane\nowns the draft the user is looking at, including one they refined and then\nrestored with Original, so it is the only reliable source of what to change."
    },
    "DraftSender": {
      "properties": {
        "name": {
          "anyOf": [
            {
              "type": "string",
              "maxLength": 200
            },
            {
              "type": "null"
            }
          ],
          "title": "Name"
        },
        "email": {
          "anyOf": [
            {
              "type": "string",
              "maxLength": 320
            },
            {
              "type": "null"
            }
          ],
          "title": "Email"
        }
      },
      "type": "object",
      "title": "DraftSender",
      "description": "Who the draft is signed as, taken from the Outlook account."
    },
    "DraftThread": {
      "properties": {
        "subject": {
          "type": "string",
          "maxLength": 1000,
          "title": "Subject",
          "default": ""
        },
        "messages": {
          "items": {
            "$ref": "#/$defs/ThreadMessage"
          },
          "type": "array",
          "maxItems": 40,
          "title": "Messages"
        }
      },
      "type": "object",
      "title": "DraftThread",
      "description": "The email thread the reply belongs to. The first message is the one being replied to."
    },
    "ThreadMessage": {
      "properties": {
        "from": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "From",
          "description": "Sender, formatted as the pane displays it."
        },
        "to": {
          "items": {
            "type": "string"
          },
          "type": "array",
          "maxItems": 50,
          "title": "To"
        },
        "sent_at": {
          "anyOf": [
            {
              "type": "string",
              "maxLength": 64
            },
            {
              "type": "null"
            }
          ],
          "title": "Sent At"
        },
        "body_text": {
          "type": "string",
          "maxLength": 50000,
          "title": "Body Text",
          "default": ""
        }
      },
      "type": "object",
      "title": "ThreadMessage",
      "description": "One message of the open Outlook thread, as the pane read it."
    }
  }
}