{
  "openapi": "3.1.0",
  "info": {
    "title": "u-FIR API",
    "version": "1.0.0",
    "summary": "Read-only results and the AI helper endpoints of the u-FIR case workspace (AP Prohibition & Excise).",
    "description": "Results are shared through GET /api/v1/results in shared mode (the department's Supabase project, signed-in members only, scope enforced by row-level security) and through Settings → Results export in local mode. The AI endpoints return suggestions for officer review; nothing they return is a decision, a final legal section or a filing."
  },
  "servers": [
    {
      "url": "/"
    }
  ],
  "tags": [
    {
      "name": "Results"
    },
    {
      "name": "AI helpers"
    },
    {
      "name": "Workspace"
    }
  ],
  "components": {
    "securitySchemes": {
      "supabaseSession": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "The access token of an invited, email-confirmed member of the department's Supabase project."
      }
    },
    "schemas": {
      "Results": {
        "title": "u-FIR results",
        "type": "object",
        "required": [
          "schema",
          "schemaVersion",
          "generatedAt",
          "source",
          "scope",
          "firs",
          "facts",
          "network",
          "hotspots",
          "risk",
          "audit",
          "pilotMetrics",
          "notes"
        ],
        "properties": {
          "schema": {
            "const": "https://ufir.app/schemas/results/v1.json"
          },
          "schemaVersion": {
            "const": "1.0.0"
          },
          "generatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "source": {
            "enum": [
              "local-export",
              "shared-api"
            ]
          },
          "scope": {
            "type": "object",
            "required": [
              "role",
              "roleLabel",
              "coverage",
              "district",
              "station",
              "firCount",
              "summaryOnlyCount",
              "redactions"
            ],
            "properties": {
              "role": {
                "enum": [
                  "investigating_officer",
                  "station_house_officer",
                  "district_supervisor",
                  "state_analyst"
                ]
              },
              "roleLabel": {
                "type": "string"
              },
              "coverage": {
                "enum": [
                  "station",
                  "district",
                  "state"
                ]
              },
              "district": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "station": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "firCount": {
                "type": "integer",
                "minimum": 0
              },
              "summaryOnlyCount": {
                "type": "integer",
                "minimum": 0
              },
              "redactions": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          },
          "firs": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "access",
                "reference",
                "district",
                "station",
                "status",
                "occurredOn",
                "redactions"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "serverCaseId": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "access": {
                  "enum": [
                    "record",
                    "summary"
                  ]
                },
                "reference": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "crimeNumber": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "title": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "district": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "station": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "status": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "occurredOn": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "createdAt": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "updatedAt": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "officer": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "people": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "required": [
                      "name",
                      "role"
                    ],
                    "properties": {
                      "name": {
                        "type": "string"
                      },
                      "role": {
                        "type": "string"
                      }
                    }
                  }
                },
                "vehicles": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "required": [
                      "registration"
                    ],
                    "properties": {
                      "registration": {
                        "type": "string"
                      },
                      "type": {
                        "type": [
                          "string",
                          "null"
                        ]
                      }
                    }
                  }
                },
                "seizures": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "required": [
                      "item"
                    ],
                    "properties": {
                      "item": {
                        "type": "string"
                      },
                      "quantity": {
                        "type": [
                          "number",
                          "null"
                        ]
                      },
                      "unit": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "seal": {
                        "type": [
                          "string",
                          "null"
                        ]
                      }
                    }
                  }
                },
                "sources": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "required": [
                      "id",
                      "name",
                      "sha256"
                    ],
                    "properties": {
                      "id": {
                        "type": "string"
                      },
                      "name": {
                        "type": "string"
                      },
                      "type": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "size": {
                        "type": [
                          "number",
                          "null"
                        ]
                      },
                      "sha256": {
                        "type": [
                          "string",
                          "null"
                        ]
                      }
                    }
                  }
                },
                "legalSections": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "required": [
                      "candidateId",
                      "status"
                    ],
                    "properties": {
                      "candidateId": {
                        "type": "string"
                      },
                      "status": {
                        "type": "string"
                      },
                      "reviewedAt": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "reviewedBy": {
                        "type": [
                          "string",
                          "null"
                        ]
                      }
                    }
                  }
                },
                "counts": {
                  "type": "object"
                },
                "redactions": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              }
            }
          },
          "facts": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "caseId",
                "factId",
                "field",
                "value",
                "status",
                "quote",
                "quoteSha256",
                "quoteRedacted",
                "sourceId",
                "sourceSha256"
              ],
              "properties": {
                "caseId": {
                  "type": "string"
                },
                "factId": {
                  "type": "string"
                },
                "field": {
                  "type": "string"
                },
                "value": {
                  "type": "string"
                },
                "status": {
                  "const": "verified"
                },
                "quote": {
                  "type": "string"
                },
                "quoteSha256": {
                  "type": "string",
                  "pattern": "^[a-f0-9]{64}$"
                },
                "quoteRedacted": {
                  "type": "boolean"
                },
                "sourceId": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "sourceName": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "sourceSha256": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "origin": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              }
            }
          },
          "network": {
            "type": "object",
            "required": [
              "nodes",
              "edges"
            ],
            "properties": {
              "nodes": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "id",
                    "type",
                    "label",
                    "caseIds"
                  ],
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "type": {
                      "type": "string"
                    },
                    "label": {
                      "type": "string"
                    },
                    "caseIds": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              },
              "edges": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "id",
                    "source",
                    "target",
                    "kind",
                    "status"
                  ],
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "source": {
                      "type": "string"
                    },
                    "target": {
                      "type": "string"
                    },
                    "kind": {
                      "type": "string"
                    },
                    "status": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "hotspots": {
            "type": "object",
            "required": [
              "total",
              "places",
              "districts"
            ],
            "properties": {
              "total": {
                "type": "integer",
                "minimum": 0
              },
              "places": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "place",
                    "district",
                    "count",
                    "open"
                  ],
                  "properties": {
                    "place": {
                      "type": "string"
                    },
                    "station": {
                      "type": "string"
                    },
                    "district": {
                      "type": "string"
                    },
                    "count": {
                      "type": "integer"
                    },
                    "open": {
                      "type": "integer"
                    },
                    "latest": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "caseIds": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              },
              "districts": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "district",
                    "count",
                    "open"
                  ],
                  "properties": {
                    "district": {
                      "type": "string"
                    },
                    "count": {
                      "type": "integer"
                    },
                    "open": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "risk": {
            "type": "object",
            "required": [
              "modelVersion",
              "asOf",
              "method",
              "scores",
              "predictionModel"
            ],
            "properties": {
              "modelVersion": {
                "type": "string"
              },
              "asOf": {
                "type": "string"
              },
              "method": {
                "const": "rules"
              },
              "predictionModel": {
                "type": [
                  "object",
                  "null"
                ],
                "required": [
                  "version",
                  "method",
                  "target",
                  "horizonDays"
                ],
                "properties": {
                  "version": {
                    "type": "string"
                  },
                  "method": {
                    "const": "logistic-regression"
                  },
                  "target": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "horizonDays": {
                    "type": "integer"
                  },
                  "trainedOn": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                }
              },
              "scores": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "caseId",
                    "score",
                    "level",
                    "factors",
                    "prediction"
                  ],
                  "properties": {
                    "caseId": {
                      "type": "string"
                    },
                    "reference": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "score": {
                      "type": "number"
                    },
                    "level": {
                      "type": "string"
                    },
                    "prediction": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "required": [
                        "probability",
                        "percent",
                        "level",
                        "horizonDays",
                        "modelVersion",
                        "factors"
                      ],
                      "properties": {
                        "probability": {
                          "type": "number"
                        },
                        "percent": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "level": {
                          "enum": [
                            "High",
                            "Medium",
                            "Low"
                          ]
                        },
                        "horizonDays": {
                          "type": "integer"
                        },
                        "modelVersion": {
                          "type": "string"
                        },
                        "factors": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "id",
                              "effect",
                              "direction",
                              "label"
                            ],
                            "properties": {
                              "id": {
                                "type": "string"
                              },
                              "effect": {
                                "type": "number"
                              },
                              "direction": {
                                "enum": [
                                  "raises",
                                  "lowers"
                                ]
                              },
                              "label": {
                                "type": "string"
                              },
                              "detail": {
                                "type": [
                                  "string",
                                  "null"
                                ]
                              },
                              "linkedCaseIds": {
                                "type": "array",
                                "items": {
                                  "type": "string"
                                }
                              }
                            }
                          }
                        }
                      }
                    },
                    "factors": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "id",
                          "points",
                          "label"
                        ],
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "points": {
                            "type": "number"
                          },
                          "label": {
                            "type": "string"
                          },
                          "detail": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "linkedCaseIds": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "audit": {
            "type": "object",
            "required": [
              "entries",
              "chain"
            ],
            "properties": {
              "chain": {
                "type": "object",
                "required": [
                  "ok",
                  "checked"
                ],
                "properties": {
                  "ok": {
                    "type": [
                      "boolean",
                      "null"
                    ]
                  },
                  "checked": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "brokenAt": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                }
              },
              "entries": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "id",
                    "at",
                    "kind",
                    "method",
                    "caseId",
                    "outcome",
                    "hash"
                  ],
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "at": {
                      "type": "string"
                    },
                    "kind": {
                      "type": "string"
                    },
                    "method": {
                      "type": "string"
                    },
                    "caseId": {
                      "type": "string"
                    },
                    "caseRef": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "role": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "actor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "question": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "outcome": {
                      "type": "string"
                    },
                    "counts": {
                      "type": "object"
                    },
                    "model": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "citations": {
                      "type": "array"
                    },
                    "requestSha256": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "responseSha256": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "previousHash": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "hash": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "pilotMetrics": {
            "type": [
              "object",
              "null"
            ]
          },
          "notes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "$id": "https://ufir.app/schemas/results/v1.json"
      },
      "Error": {
        "type": "object",
        "required": [
          "ok",
          "error"
        ],
        "properties": {
          "ok": {
            "const": false
          },
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          },
          "mode": {
            "type": "string"
          },
          "export": {
            "type": "string"
          },
          "docs": {
            "type": "string"
          },
          "schemaVersion": {
            "type": "string"
          }
        }
      },
      "ServiceError": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        }
      },
      "WorkspaceConfig": {
        "oneOf": [
          {
            "type": "object",
            "required": [
              "mode",
              "configured"
            ],
            "properties": {
              "mode": {
                "const": "local"
              },
              "configured": {
                "const": false
              }
            }
          },
          {
            "type": "object",
            "required": [
              "mode",
              "configured",
              "url",
              "publishableKey",
              "sourceFinalizerConfigured"
            ],
            "properties": {
              "mode": {
                "const": "shared"
              },
              "configured": {
                "const": true
              },
              "url": {
                "type": "string",
                "format": "uri"
              },
              "publishableKey": {
                "type": "string"
              },
              "sourceFinalizerConfigured": {
                "type": "boolean"
              }
            }
          }
        ]
      },
      "Quote": {
        "type": "string",
        "description": "Exact text copied from the source; the server keeps an item only when this text occurs in the source."
      },
      "ExtractRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "sourceId",
          "sourceName",
          "text"
        ],
        "properties": {
          "caseRef": {
            "type": "string",
            "maxLength": 200
          },
          "sourceId": {
            "type": "string",
            "maxLength": 160
          },
          "sourceName": {
            "type": "string",
            "maxLength": 500
          },
          "text": {
            "type": "string",
            "maxLength": 60000
          },
          "language": {
            "enum": [
              "auto",
              "en",
              "te"
            ]
          }
        }
      },
      "ExtractResponse": {
        "type": "object",
        "required": [
          "sourceId",
          "sourceName",
          "counts",
          "model",
          "generatedAt"
        ],
        "properties": {
          "caseRef": {
            "type": "string"
          },
          "sourceId": {
            "type": "string"
          },
          "sourceName": {
            "type": "string"
          },
          "summary": {
            "type": "string"
          },
          "people": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "role": {
                  "type": "string"
                },
                "quote": {
                  "$ref": "#/components/schemas/Quote"
                }
              }
            }
          },
          "vehicles": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "registration": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                },
                "quote": {
                  "$ref": "#/components/schemas/Quote"
                }
              }
            }
          },
          "seizures": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "item": {
                  "type": "string"
                },
                "quantity": {
                  "type": "string"
                },
                "unit": {
                  "type": "string"
                },
                "quote": {
                  "$ref": "#/components/schemas/Quote"
                }
              }
            }
          },
          "places": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "quote": {
                  "$ref": "#/components/schemas/Quote"
                }
              }
            }
          },
          "dates": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "value": {
                  "type": "string"
                },
                "what": {
                  "type": "string"
                },
                "quote": {
                  "$ref": "#/components/schemas/Quote"
                }
              }
            }
          },
          "sections": {
            "type": "array",
            "description": "Candidate sections for the officer to decide; never final.",
            "items": {
              "type": "object",
              "properties": {
                "act": {
                  "type": "string"
                },
                "section": {
                  "type": "string"
                },
                "reason": {
                  "type": "string"
                },
                "quote": {
                  "$ref": "#/components/schemas/Quote"
                }
              }
            }
          },
          "firFields": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "field": {
                  "type": "string"
                },
                "value": {
                  "type": "string"
                },
                "quote": {
                  "$ref": "#/components/schemas/Quote"
                }
              }
            }
          },
          "counts": {
            "type": "object",
            "properties": {
              "kept": {
                "type": "integer"
              },
              "dropped": {
                "type": "integer"
              }
            }
          },
          "model": {
            "type": "string"
          },
          "generatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "serverCaseId": {
            "type": "string"
          },
          "serverCaseVersion": {
            "type": "integer"
          }
        }
      },
      "AssistantRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "question"
        ],
        "properties": {
          "question": {
            "type": "string",
            "maxLength": 500
          },
          "record": {
            "type": "object",
            "description": "The case record (scope \"case\")."
          },
          "sources": {
            "type": "array",
            "maxItems": 12,
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "text": {
                  "type": "string"
                }
              }
            }
          },
          "role": {
            "enum": [
              "investigating_officer",
              "station_house_officer",
              "district_supervisor",
              "state_analyst"
            ]
          },
          "scope": {
            "enum": [
              "case",
              "cases",
              "law"
            ]
          },
          "passages": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "partialContext": {
            "type": "boolean"
          },
          "sourceChunks": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "language": {
            "enum": [
              "en",
              "te"
            ]
          }
        }
      },
      "AssistantResponse": {
        "type": "object",
        "required": [
          "role",
          "title",
          "paragraphs",
          "citations",
          "unanswered",
          "grounded"
        ],
        "properties": {
          "role": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "paragraphs": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "citations": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "sourceId": {
                  "type": "string"
                },
                "sourceName": {
                  "type": "string"
                },
                "quote": {
                  "$ref": "#/components/schemas/Quote"
                }
              }
            }
          },
          "unanswered": {
            "type": "boolean"
          },
          "grounded": {
            "type": "boolean"
          },
          "model": {
            "type": "string"
          },
          "partialContext": {
            "type": "boolean"
          },
          "contextNotice": {
            "type": "string"
          },
          "scope": {
            "type": "string"
          }
        }
      },
      "EmbedRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "inputs"
        ],
        "properties": {
          "inputs": {
            "type": "array",
            "minItems": 1,
            "maxItems": 48,
            "items": {
              "type": "string",
              "maxLength": 2400
            }
          },
          "purpose": {
            "enum": [
              "query",
              "document"
            ]
          },
          "role": {
            "enum": [
              "investigating_officer",
              "station_house_officer",
              "district_supervisor",
              "state_analyst"
            ]
          },
          "withheldNames": {
            "type": "array",
            "maxItems": 50,
            "items": {
              "type": "string"
            }
          }
        }
      },
      "EmbedResponse": {
        "type": "object",
        "required": [
          "model",
          "dims",
          "purpose",
          "embeddings",
          "masked"
        ],
        "properties": {
          "model": {
            "type": "string"
          },
          "dims": {
            "type": "integer"
          },
          "purpose": {
            "type": "string"
          },
          "embeddings": {
            "type": "array",
            "items": {
              "type": "array",
              "items": {
                "type": "number"
              }
            }
          },
          "masked": {
            "type": "boolean"
          }
        }
      }
    }
  },
  "paths": {
    "/api/v1/results": {
      "get": {
        "tags": [
          "Results"
        ],
        "operationId": "getResults",
        "summary": "Results for the caller's permitted scope",
        "description": "Structured FIRs, verified facts with exact quotes and SHA-256 hashes, network links, hotspots, rule-based risk scores and the case audit trail. Row-level security limits the cases to the caller's station (full records) or district/state (summaries); informant identities and notes are redacted by role. Read-only.",
        "security": [
          {
            "supabaseSession": []
          }
        ],
        "parameters": [
          {
            "name": "format",
            "in": "query",
            "required": false,
            "schema": {
              "enum": [
                "json",
                "csv"
              ],
              "default": "json"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The results document.",
            "headers": {
              "X-Ufir-Schema-Version": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Results"
                }
              },
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Unsupported format.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No valid department session.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Cross-site request, missing membership or denied access.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "Only GET is allowed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "501": {
            "description": "Local mode: records stay in each officer's browser. Export results from the dashboard (Settings → Results export).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Shared service misconfigured or unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/extract": {
      "post": {
        "tags": [
          "AI helpers"
        ],
        "operationId": "extractSource",
        "summary": "Suggest facts from one source text",
        "description": "Returns people, vehicles, seizures, places, dates, FIR fields and candidate sections, each with a quote that occurs in the text. Suggestions only; the officer accepts, corrects or rejects each one. Without an AI key the workspace reads sources with on-device rules instead.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ExtractRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Checked suggestions.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ExtractResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "403": {
            "description": "Cross-site request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "405": {
            "description": "Only POST.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "413": {
            "description": "Too large.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "415": {
            "description": "JSON required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "502": {
            "description": "AI service error.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "503": {
            "description": "AI service not configured.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          }
        }
      }
    },
    "/api/assistant": {
      "post": {
        "tags": [
          "AI helpers"
        ],
        "operationId": "askAssistant",
        "summary": "Answer a question from the case sources",
        "description": "Answers only from the sources and passages sent, with verified citations; names withheld for the role stay masked. Without an AI key the workspace answers by quoting matching passages.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AssistantRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A cited answer, or unanswered.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AssistantResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "403": {
            "description": "Cross-site request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "405": {
            "description": "Only POST.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "413": {
            "description": "Too large.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "415": {
            "description": "JSON required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "502": {
            "description": "AI service error.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "503": {
            "description": "AI service not configured.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          }
        }
      }
    },
    "/api/embed": {
      "post": {
        "tags": [
          "AI helpers"
        ],
        "operationId": "embedTexts",
        "summary": "Search vectors for passages or a query",
        "description": "Embeds up to 48 short texts for meaning search. Withheld names are masked before the texts leave the server.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EmbedRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Vectors.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EmbedResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "403": {
            "description": "Cross-site request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "405": {
            "description": "Only POST.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "413": {
            "description": "Too large.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "415": {
            "description": "JSON required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "502": {
            "description": "Upstream error.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          },
          "503": {
            "description": "Not configured.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceError"
                }
              }
            }
          }
        }
      }
    },
    "/api/workspace-config": {
      "get": {
        "tags": [
          "Workspace"
        ],
        "operationId": "getWorkspaceConfig",
        "summary": "Local or shared mode",
        "description": "Public configuration only: the Supabase URL and publishable key in shared mode. Never returns a server key.",
        "responses": {
          "200": {
            "description": "Mode and public configuration.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WorkspaceConfig"
                }
              }
            }
          },
          "405": {
            "description": "Only GET.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Partial or invalid shared configuration.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  }
}
