{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "format": "framed-package/1",
  "description": "Result types Framed hands a client, and the typed shapes a client sends back. A result carries its type in `schema_ref` and its version in `schema_version`; `schema` validates its `payload` (record, list) or its `file_ref` (file). A type Framed has no schema for is the workspace's own label and is passed through unvalidated (`validated: false`).",
  "types": {
    "framed:document/*": {
      "version": "1",
      "kind": "file",
      "checks": "file_ref",
      "title": "Document",
      "description": "A document a run wrote (memo, report, presentation, ...), kept in Files and served as a file with a signed link.",
      "schema": {
        "type": "object",
        "required": [
          "id",
          "kind",
          "name",
          "media_type",
          "url",
          "url_expires_at"
        ],
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^document:.+"
          },
          "kind": {
            "const": "document"
          },
          "name": {
            "type": "string",
            "minLength": 1
          },
          "media_type": {
            "enum": [
              "text/markdown",
              "text/html",
              "application/json"
            ]
          },
          "url": {
            "type": [
              "string",
              "null"
            ]
          },
          "url_expires_at": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      }
    },
    "framed:upload": {
      "version": "1",
      "kind": "file",
      "checks": "file_ref",
      "title": "Uploaded file",
      "description": "A file someone uploaded to the workspace that the run referenced.",
      "schema": {
        "type": "object",
        "required": [
          "id",
          "kind",
          "name",
          "media_type",
          "url",
          "url_expires_at"
        ],
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^upload:.+"
          },
          "kind": {
            "const": "upload"
          },
          "name": {
            "type": "string",
            "minLength": 1
          },
          "media_type": {
            "type": "string",
            "minLength": 1
          },
          "size_bytes": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0
          },
          "url": {
            "type": [
              "string",
              "null"
            ]
          },
          "url_expires_at": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      }
    },
    "framed:research_table": {
      "version": "1",
      "kind": "list",
      "checks": "payload",
      "title": "Research table",
      "description": "Rows a research step found, one flat object per row, with its columns.",
      "schema": {
        "type": "object",
        "required": [
          "found",
          "columns",
          "rows"
        ],
        "additionalProperties": false,
        "properties": {
          "query": {
            "type": [
              "string",
              "null"
            ]
          },
          "entity_type": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": [
              "string",
              "null"
            ]
          },
          "found": {
            "type": "integer",
            "minimum": 0
          },
          "target": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0
          },
          "truncated_to": {
            "type": "integer",
            "minimum": 1
          },
          "columns": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "key",
                "label",
                "kind"
              ],
              "additionalProperties": false,
              "properties": {
                "key": {
                  "type": "string",
                  "minLength": 1
                },
                "label": {
                  "type": "string"
                },
                "kind": {
                  "type": "string",
                  "minLength": 1
                }
              }
            }
          },
          "rows": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "name",
                "criteria_satisfied",
                "criteria_total"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "url": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "entity_type": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "criteria_satisfied": {
                  "type": "integer",
                  "minimum": 0
                },
                "criteria_total": {
                  "type": "integer",
                  "minimum": 0
                }
              },
              "additionalProperties": true
            }
          }
        }
      }
    },
    "framed:insight/*": {
      "version": "1",
      "kind": "record",
      "checks": "payload",
      "title": "Finding",
      "description": "A finding a run wrote: a title and markdown. A finding cut off at the length limit does not validate.",
      "schema": {
        "type": "object",
        "required": [
          "title",
          "content_md"
        ],
        "additionalProperties": false,
        "properties": {
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "type": {
            "type": [
              "string",
              "null"
            ]
          },
          "snippet": {
            "type": [
              "string",
              "null"
            ]
          },
          "content_md": {
            "type": "string",
            "minLength": 1,
            "maxLength": 60000
          }
        }
      }
    },
    "framed:step_conclusion": {
      "version": "1",
      "kind": "record",
      "checks": "payload",
      "title": "Step conclusion",
      "description": "What one step of the run concluded.",
      "schema": {
        "type": "object",
        "required": [
          "summary"
        ],
        "additionalProperties": false,
        "properties": {
          "summary": {
            "type": [
              "string",
              "null"
            ]
          },
          "extract": {
            "type": "string"
          },
          "confidence": {
            "type": "number"
          },
          "flags": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      }
    },
    "framed:approval/*": {
      "version": "1",
      "kind": "record",
      "checks": "payload",
      "title": "Approval card",
      "description": "A card the run raised. The payload is the card's own and is open by design.",
      "schema": {
        "type": "object"
      }
    },
    "framed:message_draft": {
      "version": "1",
      "kind": "record",
      "checks": "payload",
      "title": "Message draft",
      "description": "A message waiting for a person: to, subject, body and attachments as references. It can be approved, edited and approved, or declined over the API.",
      "schema": {
        "type": "object",
        "required": [
          "channel",
          "effect",
          "to",
          "subject",
          "body",
          "body_format",
          "attachments"
        ],
        "additionalProperties": false,
        "properties": {
          "channel": {
            "enum": [
              "gmail",
              "resend",
              "workspace_mail"
            ]
          },
          "effect": {
            "enum": [
              "creates_draft",
              "sends"
            ]
          },
          "from": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": false,
            "properties": {
              "address": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "mailbox": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "connection_id": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "to": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "object",
              "required": [
                "address"
              ],
              "additionalProperties": false,
              "properties": {
                "address": {
                  "type": "string",
                  "minLength": 3
                },
                "name": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              }
            }
          },
          "cc": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "address"
              ],
              "additionalProperties": false,
              "properties": {
                "address": {
                  "type": "string",
                  "minLength": 3
                },
                "name": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              }
            }
          },
          "subject": {
            "type": "string",
            "minLength": 1,
            "maxLength": 300
          },
          "body": {
            "type": "string",
            "minLength": 1,
            "maxLength": 60000
          },
          "body_format": {
            "enum": [
              "text",
              "html"
            ]
          },
          "attachments": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "type": "object",
              "required": [
                "ref"
              ],
              "additionalProperties": false,
              "properties": {
                "ref": {
                  "type": "string",
                  "pattern": "^(document|upload):.+"
                },
                "name": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "media_type": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              }
            }
          },
          "editable": {
            "type": "boolean"
          },
          "decidable": {
            "type": "boolean"
          },
          "not_decidable_because": {
            "type": [
              "string",
              "null"
            ]
          },
          "decided": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": false,
            "properties": {
              "outcome": {
                "enum": [
                  "approved",
                  "declined",
                  "closed"
                ]
              },
              "by": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "at": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "reason": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "edited": {
                "type": "boolean"
              }
            }
          }
        }
      }
    },
    "framed:decision_request": {
      "version": "1",
      "kind": "record",
      "checks": "payload",
      "title": "Decision request",
      "description": "A question waiting for a person, with its options. An answer, or a decline, is submitted over the API and recorded with who decided.",
      "schema": {
        "type": "object",
        "required": [
          "question",
          "card_kind",
          "questions",
          "outcomes"
        ],
        "additionalProperties": false,
        "properties": {
          "question": {
            "type": "string",
            "minLength": 1
          },
          "summary": {
            "type": [
              "string",
              "null"
            ]
          },
          "card_kind": {
            "type": "string",
            "minLength": 1
          },
          "effect": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "questions": {
            "type": "array",
            "maxItems": 6,
            "items": {
              "type": "object",
              "required": [
                "id",
                "kind",
                "prompt",
                "required"
              ],
              "additionalProperties": false,
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 80
                },
                "kind": {
                  "enum": [
                    "single",
                    "multi",
                    "text"
                  ]
                },
                "prompt": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 200
                },
                "help": {
                  "type": "string",
                  "maxLength": 200
                },
                "label": {
                  "type": "string",
                  "maxLength": 60
                },
                "required": {
                  "type": "boolean"
                },
                "options": {
                  "type": "array",
                  "maxItems": 12,
                  "items": {
                    "type": "object",
                    "required": [
                      "id",
                      "label"
                    ],
                    "additionalProperties": false,
                    "properties": {
                      "id": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 80
                      },
                      "label": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 160
                      },
                      "detail": {
                        "type": "string",
                        "maxLength": 160
                      },
                      "recommended": {
                        "type": "boolean"
                      },
                      "disabled": {
                        "type": "string",
                        "maxLength": 120
                      }
                    }
                  }
                },
                "other": {
                  "type": [
                    "boolean",
                    "string"
                  ]
                },
                "max_length": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 1000
                }
              }
            }
          },
          "outcomes": {
            "type": "array",
            "items": {
              "enum": [
                "approve",
                "decline"
              ]
            },
            "minItems": 2,
            "maxItems": 2
          },
          "decidable": {
            "type": "boolean"
          },
          "not_decidable_because": {
            "type": [
              "string",
              "null"
            ]
          },
          "decided": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": false,
            "properties": {
              "outcome": {
                "enum": [
                  "approved",
                  "declined",
                  "closed"
                ]
              },
              "by": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "at": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "reason": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "answers": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "question_id",
                    "question",
                    "skipped"
                  ],
                  "additionalProperties": false,
                  "properties": {
                    "question_id": {
                      "type": "string"
                    },
                    "question": {
                      "type": "string"
                    },
                    "answer": {
                      "type": "string"
                    },
                    "option_ids": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "other": {
                      "type": "string"
                    },
                    "text": {
                      "type": "string"
                    },
                    "skipped": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "inputs": {
    "framed:run_input": {
      "version": "1",
      "title": "Run input",
      "schema": {
        "type": "object",
        "properties": {
          "input": {
            "type": [
              "object",
              "null"
            ]
          },
          "files": {
            "type": [
              "array",
              "null"
            ],
            "maxItems": 10,
            "items": {
              "type": "object",
              "required": [
                "ref"
              ],
              "additionalProperties": false,
              "properties": {
                "ref": {
                  "type": "string",
                  "pattern": "^(document|upload):[A-Za-z0-9_-]+$"
                },
                "name": {
                  "type": "string",
                  "maxLength": 200
                }
              }
            }
          },
          "from_result": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 300
          },
          "reason": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      }
    },
    "framed:decision_answer": {
      "version": "1",
      "title": "Decision answer",
      "schema": {
        "type": "object",
        "required": [
          "question_id"
        ],
        "additionalProperties": false,
        "properties": {
          "question_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "option_ids": {
            "type": "array",
            "maxItems": 12,
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 80
            }
          },
          "other": {
            "type": "string",
            "maxLength": 240
          },
          "text": {
            "type": "string",
            "maxLength": 1000
          },
          "skipped": {
            "type": "boolean"
          }
        }
      }
    },
    "framed:message_edit": {
      "version": "1",
      "title": "Message edit",
      "schema": {
        "type": "object",
        "additionalProperties": false,
        "minProperties": 1,
        "properties": {
          "subject": {
            "type": "string",
            "minLength": 1,
            "maxLength": 300
          },
          "body": {
            "type": "string",
            "minLength": 1,
            "maxLength": 60000
          }
        }
      }
    },
    "framed:action_proposal": {
      "version": "1",
      "title": "Action proposal",
      "schema": {
        "type": "object",
        "required": [
          "kind",
          "to",
          "subject",
          "body"
        ],
        "additionalProperties": false,
        "properties": {
          "kind": {
            "enum": [
              "message_draft"
            ]
          },
          "to": {
            "type": "string",
            "minLength": 1,
            "maxLength": 320
          },
          "subject": {
            "type": "string",
            "minLength": 1,
            "maxLength": 300
          },
          "body": {
            "type": "string",
            "minLength": 1,
            "maxLength": 20000
          },
          "connection_id": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 200
          },
          "reason": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      }
    }
  }
}
