import { releaseVersion } from "../config/version.js"; const ref = (name: string) => ({ $ref: `#/components/schemas/${name}` }); const jsonContent = (schema: Record, example?: unknown) => ({ "application/json": { schema, ...(example === undefined ? {} : { example }) } }); const jsonResponse = (description: string, schema: Record, example?: unknown) => ({ description, content: jsonContent(schema, example) }); const serverError = jsonResponse("Internal or upstream service error.", ref("Error")); export const openApiDocument = { openapi: "3.1.1", info: { title: "RAG Service API", version: releaseVersion, description: "HTTP API for ingesting, retrieving, answering from, and evaluating scoped RAG knowledge." }, jsonSchemaDialect: "https://json-schema.org/draft/2020-12/schema", servers: [ { url: "https://rag.por-correo.com", description: "Production" }, { url: "http://localhost:3000", description: "Local development" } ], tags: [ { name: "Discovery", description: "API contract and browser playground." }, { name: "Status", description: "Service capabilities and available resources." }, { name: "Ingestion", description: "Knowledge ingestion and cleanup." }, { name: "OCR Review", description: "Authenticated OCR progress, review, correction, and decisions." }, { name: "Lifecycle", description: "Knowledge source versions, activation, rollback, and purge." }, { name: "Retrieval", description: "Context retrieval and model-backed answers." }, { name: "Evaluation", description: "Evaluation log capture and review." } ], paths: { "/help": { get: { tags: ["Discovery"], summary: "Discover the API", description: "Returns a concise endpoint catalog generated from this OpenAPI document.", responses: { "200": jsonResponse("API discovery catalog.", ref("HelpResponse")) } } }, "/openapi.json": { get: { tags: ["Discovery"], summary: "Get the OpenAPI contract", responses: { "200": jsonResponse("OpenAPI 3.1.1 document.", { type: "object" }) } } }, "/playground": { get: { tags: ["Discovery"], summary: "Open the browser playground", responses: { "200": { description: "Playground HTML page.", content: { "text/html": { schema: { type: "string" } } } } } } }, "/health": { get: { tags: ["Status"], summary: "Check service health and capabilities", responses: { "200": jsonResponse("Current service status.", ref("HealthResponse")), "503": jsonResponse("One or more required services are unavailable.", ref("HealthResponse")) } } }, "/sources": { get: { tags: ["Status"], summary: "List available knowledge scopes", responses: { "200": jsonResponse("Scopes currently stored in the vector database.", { type: "array", items: ref("AvailableScope") }), "503": serverError, "500": serverError } } }, "/sources/{sourceId}": { get: { tags: ["Lifecycle"], summary: "Get a catalog source", parameters: [{ name: "sourceId", in: "path", required: true, schema: { type: "string" } }], responses: { "200": jsonResponse("Catalog source.", ref("AvailableScope")), "404": jsonResponse("Source not found.", ref("Error")), "503": serverError } } }, "/sources/{sourceId}/versions": { get: { tags: ["Lifecycle"], summary: "List source versions", parameters: [{ name: "sourceId", in: "path", required: true, schema: { type: "string" } }], responses: { "200": jsonResponse("Source versions.", { type: "array", items: ref("SourceVersion") }), "503": serverError } } }, "/sources/{sourceId}/versions/{versionId}": { get: { tags: ["Lifecycle"], summary: "Get one source version", parameters: [ { name: "sourceId", in: "path", required: true, schema: { type: "string" } }, { name: "versionId", in: "path", required: true, schema: { type: "string", format: "uuid" } } ], responses: { "200": jsonResponse("Source version.", ref("SourceVersion")), "404": jsonResponse("Version not found.", ref("Error")), "503": serverError } }, delete: { tags: ["Lifecycle"], summary: "Purge a non-active source version", security: [{ bearerAuth: [] }], parameters: [ { name: "sourceId", in: "path", required: true, schema: { type: "string" } }, { name: "versionId", in: "path", required: true, schema: { type: "string", format: "uuid" } } ], responses: { "200": jsonResponse("Version purged.", ref("PurgeResponse")), "401": jsonResponse("Missing or invalid lifecycle admin token.", ref("Error")), "409": jsonResponse("Active versions cannot be purged.", ref("Error")), "503": serverError } } }, "/sources/{sourceId}/versions/{versionId}/activate": { post: { tags: ["Lifecycle"], summary: "Activate a ready or superseded version", security: [{ bearerAuth: [] }], parameters: [ { name: "sourceId", in: "path", required: true, schema: { type: "string" } }, { name: "versionId", in: "path", required: true, schema: { type: "string", format: "uuid" } } ], requestBody: { required: true, content: jsonContent(ref("ActivateVersionRequest")) }, responses: { "200": jsonResponse("Activated source version.", ref("SourceVersion")), "401": jsonResponse("Missing or invalid lifecycle admin token.", ref("Error")), "409": jsonResponse("Active version precondition failed.", ref("Error")), "503": serverError } } }, "/sources/{sourceId}/rollback": { post: { tags: ["Lifecycle"], summary: "Rollback a source to a previous version", security: [{ bearerAuth: [] }], parameters: [{ name: "sourceId", in: "path", required: true, schema: { type: "string" } }], requestBody: { required: true, content: jsonContent(ref("RollbackRequest")) }, responses: { "200": jsonResponse("Rollback activated source version.", ref("SourceVersion")), "400": jsonResponse("Required rollback fields are missing.", ref("Error")), "401": jsonResponse("Missing or invalid lifecycle admin token.", ref("Error")), "409": jsonResponse("Active version precondition failed.", ref("Error")), "503": serverError } } }, "/sources/{sourceId}/versions/{versionId}/retry": { post: { tags: ["Lifecycle"], summary: "Explicitly retry a failed or orphaned version by re-submitting a durable source", security: [{ bearerAuth: [] }], parameters: [ { name: "sourceId", in: "path", required: true, schema: { type: "string" } }, { name: "versionId", in: "path", required: true, schema: { type: "string", format: "uuid" } } ], requestBody: { required: false, content: jsonContent(ref("RetryVersionRequest")) }, responses: { "201": jsonResponse("Replacement version created by explicit retry.", ref("IngestResponse")), "202": jsonResponse("Retry instructions returned because no durable source payload was supplied.", ref("RetryVersionResponse")), "401": jsonResponse("Missing or invalid lifecycle admin token.", ref("Error")), "409": jsonResponse("Version state is not retryable.", ref("Error")), "503": serverError } } }, "/models/answer": { get: { tags: ["Status"], summary: "List answer models", description: "Returns the configured default and up to 80 selectable answer models.", responses: { "200": jsonResponse("Available answer models.", ref("AnswerModelsResponse")), "500": serverError } } }, "/ingest": { post: { tags: ["Ingestion"], summary: "Ingest a server-accessible file or folder", requestBody: { required: true, content: jsonContent(ref("IngestRequest"), { sourceType: "folder", sourceRef: "/data/project-docs", mode: "mechanical", tags: ["project-docs"] }) }, responses: { "201": jsonResponse("Lifecycle ingestion completed and committed.", ref("IngestResponse")), "202": jsonResponse("OCR ingestion accepted, or legacy ingestion accepted while lifecycle enforcement is disabled.", { oneOf: [ref("OcrAccepted"), ref("IngestResponse")] }), "400": jsonResponse("Invalid lifecycle activation request.", ref("Error")), "409": jsonResponse("Concurrent active version change or reusable version in progress.", ref("Error")), "422": jsonResponse("Empty or unsupported source.", ref("Error")), "503": serverError, "500": serverError } } }, "/ingest/upload": { post: { tags: ["Ingestion"], summary: "Upload and ingest a file or ZIP folder", requestBody: { required: true, content: { "multipart/form-data": { schema: ref("UploadIngestRequest") } } }, responses: { "201": jsonResponse("Lifecycle upload ingested successfully.", ref("UploadIngestResponse")), "202": jsonResponse("OCR upload accepted, or legacy upload accepted while lifecycle enforcement is disabled.", { oneOf: [ref("OcrUploadAccepted"), ref("UploadIngestResponse")] }), "400": jsonResponse("The file field is missing.", ref("Error"), { ok: false, error: "Missing file upload" }), "409": jsonResponse("Concurrent active version change or reusable version in progress.", ref("Error")), "422": jsonResponse("Empty or unsupported source.", ref("Error")), "503": serverError, "500": serverError } } }, "/ingestions/{versionId}": { get: { tags: ["OCR Review"], summary: "Get OCR ingestion progress", security: [{ bearerAuth: [] }], parameters: [{ name: "versionId", in: "path", required: true, schema: { type: "string", format: "uuid" } }], responses: { "200": jsonResponse("Current document and page progress.", ref("IngestionStatus")), "401": jsonResponse("Missing or invalid lifecycle admin token.", ref("Error")), "404": jsonResponse("OCR is disabled or the ingestion does not exist.", ref("Error")), "503": serverError, "500": serverError } } }, "/ingestions/{versionId}/review": { get: { tags: ["OCR Review"], summary: "Inspect an OCR candidate", security: [{ bearerAuth: [] }], parameters: [{ name: "versionId", in: "path", required: true, schema: { type: "string", format: "uuid" } }], responses: { "200": jsonResponse("Review candidate with page evidence.", ref("OcrReview")), "401": jsonResponse("Missing or invalid lifecycle admin token.", ref("Error")), "404": jsonResponse("OCR is disabled or the candidate does not exist.", ref("Error")), "409": jsonResponse("The version is not awaiting review.", ref("Error")), "503": serverError, "500": serverError } } }, "/ingestions/{versionId}/recover": { post: { tags: ["OCR Review"], summary: "Close an unrecoverable OCR review candidate", security: [{ bearerAuth: [] }], parameters: [{ name: "versionId", in: "path", required: true, schema: { type: "string", format: "uuid" } }], requestBody: { required: true, content: jsonContent(ref("OcrRecoveryRequest")) }, responses: { "200": jsonResponse("Candidate was closed without approval, indexing, or activation.", ref("OcrRecoveryResponse")), "400": jsonResponse("Recovery actor and reason are required.", ref("Error")), "401": jsonResponse("Missing or invalid lifecycle admin token.", ref("Error")), "404": jsonResponse("OCR candidate does not exist.", ref("Error")), "409": jsonResponse("Candidate state or evidence precondition does not permit recovery.", ref("Error")), "422": jsonResponse("OCR artifact format or integrity is invalid.", ref("Error")), "503": serverError, "500": serverError } } }, "/ingestions/{versionId}/recover-indexing": { get: { tags: ["OCR Review"], summary: "Inspect CAS values for an approved OCR indexing recovery", security: [{ bearerAuth: [] }], parameters: [{ name: "versionId", in: "path", required: true, schema: { type: "string", format: "uuid" } }], responses: { "200": jsonResponse("Validated recovery hashes and lifecycle preconditions; no state is changed.", ref("OcrApprovedIndexingRecoveryEvidence")), "401": jsonResponse("Missing or invalid lifecycle admin token.", ref("Error")), "404": jsonResponse("OCR candidate does not exist.", ref("Error")), "409": jsonResponse("Candidate is not awaiting approved-indexing recovery or evidence is invalid.", ref("Error")), "503": serverError } }, post: { tags: ["OCR Review"], summary: "Restore an already-approved OCR candidate to its indexing coordinator", security: [{ bearerAuth: [] }], parameters: [{ name: "versionId", in: "path", required: true, schema: { type: "string", format: "uuid" } }], requestBody: { required: true, content: jsonContent(ref("OcrApprovedIndexingRecoveryRequest")) }, responses: { "202": jsonResponse("Approval state restored and audited; the existing reconciler resumes indexing.", ref("OcrApprovedIndexingRecoveryResponse")), "400": jsonResponse("Recovery request fields are invalid.", ref("Error")), "401": jsonResponse("Missing or invalid lifecycle admin token.", ref("Error")), "404": jsonResponse("OCR candidate does not exist.", ref("Error")), "409": jsonResponse("Expected approval state, artifact identity, or active-version precondition changed.", ref("Error")), "503": serverError } } }, "/ingestions/{versionId}/documents/{documentId}/pages/{page}/image": { get: { tags: ["OCR Review"], summary: "Get a private OCR review page image", security: [{ bearerAuth: [] }], parameters: [ { name: "versionId", in: "path", required: true, schema: { type: "string", format: "uuid" } }, { name: "documentId", in: "path", required: true, schema: { type: "string" } }, { name: "page", in: "path", required: true, schema: { type: "integer", minimum: 1 } } ], responses: { "200": { description: "Integrity-validated private PNG review image.", content: { "image/png": { schema: { type: "string", format: "binary" } } } }, "401": jsonResponse("Missing or invalid lifecycle admin token.", ref("Error")), "404": jsonResponse("OCR is disabled or the review image does not exist.", ref("Error")), "503": serverError, "500": serverError } } }, "/ingestions/{versionId}/approve": { post: { tags: ["OCR Review"], summary: "Correct and approve an OCR candidate", security: [{ bearerAuth: [] }], parameters: [{ name: "versionId", in: "path", required: true, schema: { type: "string", format: "uuid" } }], requestBody: { required: true, content: jsonContent(ref("OcrApprovalRequest")) }, responses: { "200": jsonResponse("Candidate indexed and settled according to activation intent.", ref("OcrDecisionResponse")), "401": jsonResponse("Missing or invalid lifecycle admin token.", ref("Error")), "404": jsonResponse("OCR is disabled or the candidate does not exist.", ref("Error")), "409": jsonResponse("Candidate, correction, state, or active-version precondition conflict.", ref("Error")), "503": serverError, "500": serverError } } }, "/ingestions/{versionId}/reject": { post: { tags: ["OCR Review"], summary: "Reject an OCR candidate", security: [{ bearerAuth: [] }], parameters: [{ name: "versionId", in: "path", required: true, schema: { type: "string", format: "uuid" } }], requestBody: { required: true, content: jsonContent(ref("OcrRejectionRequest")) }, responses: { "200": jsonResponse("Candidate rejected without indexing or activation.", ref("OcrDecisionResponse")), "400": jsonResponse("Required rejection fields are missing.", ref("Error")), "401": jsonResponse("Missing or invalid lifecycle admin token.", ref("Error")), "404": jsonResponse("OCR is disabled or the candidate does not exist.", ref("Error")), "409": jsonResponse("Candidate hash or review state conflict.", ref("Error")), "503": serverError, "500": serverError } } }, "/cleanup": { post: { tags: ["Ingestion"], summary: "Delete chunks matching a source scope", description: "Requires sourceId or sourceRef to prevent accidental mass deletion. Tags alone are not accepted.", requestBody: { required: true, content: jsonContent(ref("CleanupRequest"), { scope: { sourceId: "customer-a:manual:v1" } }) }, responses: { "200": jsonResponse("Matching chunks deleted.", ref("CleanupResponse")), "400": jsonResponse("Scope is missing or unsafe for cleanup.", ref("Error")), "401": jsonResponse("Missing or invalid lifecycle admin token when lifecycle enforcement is active.", ref("Error")), "410": jsonResponse("Legacy cleanup is disabled while lifecycle enforcement is active.", ref("Error")), "503": serverError, "500": serverError } } }, "/retrieve": { post: { tags: ["Retrieval"], summary: "Retrieve scoped context", description: "Returns retrieved chunks. Set useModelInRetrieve to true to also generate modelSummary.", requestBody: { required: true, content: jsonContent(ref("RetrieveRequest"), { mode: "documental", intent: "specific", query: "How is the service deployed?", scope: { sourceId: "project-docs" }, useModelInRetrieve: false }) }, responses: { "200": jsonResponse("Retrieved context.", ref("RetrieveResponse")), "500": serverError } } }, "/answer": { post: { tags: ["Retrieval"], summary: "Answer using retrieved RAG context", requestBody: { required: true, content: jsonContent(ref("AnswerRequest")) }, responses: { "200": jsonResponse("Model answer with retrieval citations.", ref("AnswerResponse")), "500": serverError } } }, "/answer/direct": { post: { tags: ["Retrieval"], summary: "Answer without retrieving RAG context", description: "Primarily used to compare direct model output with RAG-backed output.", requestBody: { required: true, content: jsonContent(ref("DirectAnswerRequest")) }, responses: { "200": jsonResponse("Direct model answer.", ref("DirectAnswerResponse")), "500": serverError } } }, "/chat": { post: { tags: ["Retrieval"], summary: "Chat with optional bootstrap and additional retrieval", requestBody: { required: true, content: jsonContent(ref("ChatRequest")) }, responses: { "200": jsonResponse("Chat response and retrieval usage metadata.", ref("ChatResponse")), "500": serverError } } }, "/logs/recent": { get: { tags: ["Evaluation"], summary: "List recent evaluation logs", parameters: [{ name: "limit", in: "query", required: false, description: "Maximum number of logs. Defaults to 20.", schema: { type: "integer", default: 20 } }], responses: { "200": jsonResponse("Recent evaluation logs.", { type: "array", items: ref("EvaluationLog") }), "500": serverError } } }, "/logs/manual": { post: { tags: ["Evaluation"], summary: "Create a manual evaluation log", requestBody: { required: true, content: jsonContent(ref("ManualLogRequest")) }, responses: { "201": jsonResponse("Evaluation log created.", ref("EvaluationLog")), "500": serverError } } }, "/logs/{id}": { patch: { tags: ["Evaluation"], summary: "Update evaluation log review status", parameters: [{ name: "id", in: "path", required: true, schema: { type: "string" } }], requestBody: { required: true, content: jsonContent(ref("UpdateLogRequest")) }, responses: { "200": jsonResponse("Updated evaluation log.", ref("EvaluationLog")), "404": jsonResponse("Evaluation log not found.", ref("Error"), { ok: false, error: "Log not found" }), "500": serverError } } } }, components: { securitySchemes: { bearerAuth: { type: "http", scheme: "bearer" } }, schemas: { Error: { type: "object", required: ["ok", "error"], properties: { ok: { type: "boolean", const: false }, error: { type: "string" }, code: { type: "string" }, action: { type: "string" } } }, Scope: { type: "object", properties: { sourceId: { type: "string" }, sourceRef: { type: "string" }, tags: { type: "array", items: { type: "string" } } } }, SourceVersionState: { type: "string", enum: ["pending", "indexing", "review_required", "ready", "active", "superseded", "failed", "rejected", "purging", "purged"] }, AvailableScope: { type: "object", required: ["sourceId", "sourceRef", "chunkModes", "tags"], properties: { sourceId: { type: "string" }, sourceRef: { type: "string" }, chunkModes: { type: "array", items: { $ref: "#/components/schemas/ChunkMode" } }, tags: { type: "array", items: { type: "string" } }, activeVersionId: { type: ["string", "null"], format: "uuid" }, activeVersionNumber: { type: ["integer", "null"] }, state: { ...ref("SourceVersionState"), nullable: true }, needsReingest: { type: "boolean" }, updatedAt: { type: "string", format: "date-time" } } }, ChunkMode: { type: "string", enum: ["documental", "codigo", "auto"] }, RetrieveIntent: { type: "string", enum: ["bootstrap", "specific"] }, IngestRequest: { type: "object", required: ["sourceType", "sourceRef"], properties: { sourceId: { type: "string" }, sourceType: { type: "string", enum: ["file", "folder"] }, sourceRef: { type: "string" }, readPath: { type: "string", description: "Internal filesystem path used when the logical sourceRef differs from the read location." }, mode: { type: "string", enum: ["mechanical", "interactive"], default: "mechanical" }, tags: { type: "array", items: { type: "string" } }, activate: { type: "boolean", default: true }, expectedActiveVersionId: { type: ["string", "null"], format: "uuid", description: "Required when activate is true. Use null for first activation." } } }, IngestResponse: { type: "object", required: ["accepted", "sourceId", "filesDiscovered", "documentsProcessed", "chunksStored", "collectionName"], properties: { accepted: { type: "boolean", const: true }, source: ref("IngestRequest"), sourceId: { type: "string" }, versionId: { type: "string", format: "uuid" }, versionNumber: { type: "integer" }, state: ref("SourceVersionState"), previousVersionId: { type: ["string", "null"], format: "uuid" }, filesDiscovered: { type: "integer" }, documentsProcessed: { type: "integer" }, chunksStored: { type: "integer" }, activated: { type: "boolean" }, noOp: { type: "boolean" }, collectionName: { type: "string" } } }, UploadIngestRequest: { type: "object", required: ["file"], properties: { file: { type: "string", format: "binary" }, sourceId: { type: "string" }, sourceRef: { type: "string", minLength: 1, description: "Optional logical source reference; trimmed and defaults to the uploaded filename. For individual files, its filename (without directories) is the presentation title; the temporary UUID remains internal." }, mode: { type: "string", enum: ["mechanical", "interactive"], default: "mechanical" }, tags: { type: "string", description: "Comma-separated tags." }, isZipFolder: { type: "string", enum: ["true", "false"], default: "false" }, activate: { type: "string", enum: ["true", "false"], default: "true" }, expectedActiveVersionId: { type: "string", description: "UUID or literal null when activate is true." } } }, UploadIngestResponse: { allOf: [ ref("IngestResponse"), { type: "object", required: ["uploadedResource"], properties: { uploadedResource: { type: "string" } } } ] }, OcrPhase: { type: "string", enum: ["native_extracting", "ocr_queued", "ocr_running", "review_required", "indexing", "indexing_paused", "ready", "active", "failed", "rejected"] }, OcrAccepted: { type: "object", required: ["accepted", "sourceId", "versionId", "versionNumber", "state", "phase", "statusUrl", "reviewUrl", "activated"], properties: { accepted: { type: "boolean", const: true }, sourceId: { type: "string" }, versionId: { type: "string", format: "uuid" }, versionNumber: { type: "integer" }, state: { type: "string", const: "indexing" }, phase: { type: "string", const: "ocr_queued" }, statusUrl: { type: "string" }, reviewUrl: { type: "null" }, activated: { type: "boolean", const: false } } }, OcrUploadAccepted: { allOf: [ref("OcrAccepted"), { type: "object", required: ["uploadedResource"], properties: { uploadedResource: { type: "string" } } }] }, IngestionStatus: { type: "object", required: ["sourceId", "versionId", "state", "phase", "activated", "documents", "error", "statusUrl", "reviewUrl"], properties: { sourceId: { type: "string" }, versionId: { type: "string", format: "uuid" }, state: ref("SourceVersionState"), phase: ref("OcrPhase"), activated: { type: "boolean" }, documents: { type: "array", items: ref("OcrProgressDocument") }, coverage: ref("OcrCoverage"), indexingTransfer: ref("IndexingTransferProgress"), error: { oneOf: [ref("OcrStatusError"), { type: "null" }] }, statusUrl: { type: "string" }, reviewUrl: { type: ["string", "null"] } } }, IndexingTransferProgress: { type: "object", description: "Durable transfer signals, not estimated network upload bytes. Completed batches are verified by point identity before their bytes/points count as confirmed.", required: ["heartbeatMs", "totalPoints", "confirmedPoints", "confirmedBytes", "paused", "documents"], properties: { heartbeatMs: { type: "integer", const: 5000 }, totalPoints: { type: "integer" }, confirmedPoints: { type: "integer" }, confirmedBytes: { type: "integer" }, paused: { type: "boolean" }, documents: { type: "array", items: ref("IndexingTransferDocument") } } }, IndexingTransferDocument: { type: "object", required: ["documentId", "stage", "phase", "lastSignalAt", "lastProgressAt", "signalStale", "attempt", "confirmedPoints", "confirmedBytes"], properties: { documentId: { type: "string" }, stage: { type: "string", enum: ["preparation", "transfer", "verification"] }, phase: { type: "string", enum: ["preparing_vectors", "verifying_version", "pending", "checking", "sending", "verifying", "retry_wait", "complete", "paused"] }, lastSignalAt: { type: "integer", description: "Unix epoch milliseconds of the last persisted signal." }, lastProgressAt: { type: "integer", description: "Changes on confirmed work, not on periodic activity signals." }, signalStale: { type: "boolean", description: "No fresh persisted activity signal for 15 seconds; not proof that a live source lock can be bypassed." }, totalPoints: { type: "integer" }, totalSourcePoints: { type: "integer" }, confirmedPoints: { type: "integer" }, confirmedBytes: { type: "integer" }, totalBytes: { type: "integer" }, batch: { type: "integer" }, batchCount: { type: "integer" }, attempt: { type: "integer", minimum: 0, maximum: 3 }, batchBytes: { type: "integer" }, deadlineAt: { type: ["integer", "null"] }, nextAttemptAt: { type: ["integer", "null"] }, failure: { oneOf: [ref("IndexingTransferFailure"), { type: "null" }] } } }, IndexingTransferFailure: { type: "object", required: ["kind", "code"], properties: { kind: { type: "string", enum: ["connection", "timeout", "overloaded", "server", "payload_size", "invalid", "unknown", "unconfirmed"] }, code: { type: "string" }, httpStatus: { type: "integer" }, retryAfterMs: { type: "integer" } } }, OcrProgressDocument: { type: "object", required: ["documentId", "state", "completedPages", "totalPages", "pages"], properties: { documentId: { type: "string" }, state: { type: "string", enum: ["native_complete", "ocr_queued", "ocr_running", "ocr_complete", "failed"] }, completedPages: { type: "integer" }, totalPages: { type: "integer" }, pages: { type: "array", items: ref("OcrProgressPage") } } }, OcrProgressPage: { type: "object", required: ["page", "method", "state"], properties: { page: { type: "integer" }, method: { type: "string", enum: ["native", "ocr", "blank"] }, state: { type: "string", enum: ["pending", "native_complete", "native_fallback", "content_unrecovered", "ocr_queued", "ocr_running", "ocr_complete", "blank", "failed"] }, errorCode: { type: "string" }, selection: { oneOf: [ref("OcrContentSelection"), { type: "null" }] }, qualityOutcome: { type: ["string", "null"], enum: ["accepted", "warning", "blocked", null] }, warnings: { type: "array", items: { type: "string" } }, blockingReasons: { type: "array", items: { type: "string" } } } }, OcrContentSelection: { type: "object", required: ["policyVersion", "source", "reason", "contentUnrecovered", "issue"], properties: { policyVersion: { type: "string", const: "page-best-effort-v1" }, source: { type: "string", enum: ["native", "ocr", "none"] }, reason: { type: "string", enum: ["native_only", "ocr_accepted", "native_fallback", "ocr_warning", "ocr_blocked", "blank_discrepancy", "verified_blank"] }, contentUnrecovered: { type: "boolean" }, issue: { type: ["string", "null"], enum: ["visual_content_not_incorporated", "ocr_warning", "content_not_recovered", "blank_native_discrepancy", null] } } }, OcrCoverage: { type: "object", description: "Known coverage limitations, not a guarantee of semantic accuracy. A null policyVersion means historical coverage was not assessed by this policy.", required: ["policyVersion", "totalPages", "pagesWithIssues", "unrecoveredPages", "nativeFallbackPages"], properties: { policyVersion: { type: ["string", "null"] }, totalPages: { type: "integer" }, pagesWithIssues: { type: "integer" }, unrecoveredPages: { type: "integer" }, nativeFallbackPages: { type: "integer" } } }, OcrStatusError: { type: "object", required: ["code", "message", "retryable"], properties: { code: { type: "string" }, message: { type: "string" }, retryable: { type: "boolean" } } }, OcrLine: { type: "object", required: ["lineId", "text", "confidence", "bbox", "lineSha256"], properties: { lineId: { type: "string" }, text: { type: "string" }, confidence: { type: "number" }, bbox: { type: "array", items: { type: "number" }, minItems: 4, maxItems: 4 }, lineSha256: { type: "string", pattern: "^[a-f0-9]{64}$" } } }, OcrReview: { type: "object", required: ["versionId", "sourceId", "state", "candidateSha256", "baseActiveVersionId", "currentActiveVersionId", "activateRequested", "processingFingerprint", "metadataHash", "documents"], properties: { versionId: { type: "string", format: "uuid" }, sourceId: { type: "string" }, state: { type: "string", const: "review_required" }, candidateSha256: { type: "string", pattern: "^[a-f0-9]{64}$" }, baseActiveVersionId: { type: ["string", "null"], format: "uuid" }, currentActiveVersionId: { type: ["string", "null"], format: "uuid" }, activateRequested: { type: "boolean" }, processingFingerprint: { type: "string" }, metadataHash: { type: "string" }, documents: { type: "array", items: ref("OcrReviewDocument") }, coverage: ref("OcrCoverage") } }, OcrReviewDocument: { type: "object", required: ["documentId", "pages"], properties: { documentId: { type: "string" }, pages: { type: "array", items: ref("OcrReviewPage") } } }, OcrReviewPage: { type: "object", required: ["page", "imageUrl", "nativeText", "ocr", "candidateText", "differences", "risks"], properties: { page: { type: "integer" }, imageUrl: { type: ["string", "null"] }, nativeText: { type: "string" }, ocr: { type: "object", required: ["text", "lines"], properties: { text: { type: "string" }, lines: { type: "array", items: ref("OcrLine") } } }, candidateText: { type: "string" }, differences: { type: "array", items: { type: "string" } }, risks: { type: "array", items: { type: "string" } }, selection: ref("OcrContentSelection"), qualityOutcome: { type: "string", enum: ["accepted", "warning", "blocked"] }, warnings: { type: "array", items: { type: "string" } }, blockingReasons: { type: "array", items: { type: "string" } } } }, OcrCorrection: { type: "object", required: ["documentId", "page", "lineId", "expectedLineSha256", "replacementText"], properties: { documentId: { type: "string" }, page: { type: "integer" }, lineId: { type: "string" }, expectedLineSha256: { type: "string", pattern: "^[a-f0-9]{64}$" }, replacementText: { type: "string" } } }, OcrApprovalRequest: { type: "object", required: ["candidateSha256", "expectedActiveVersionId", "reviewedBy", "corrections"], properties: { candidateSha256: { type: "string", pattern: "^[a-f0-9]{64}$" }, expectedActiveVersionId: { type: ["string", "null"], format: "uuid" }, reviewedBy: { type: "string" }, corrections: { type: "array", items: ref("OcrCorrection") } } }, OcrRejectionRequest: { type: "object", required: ["candidateSha256", "reviewedBy", "reason"], properties: { candidateSha256: { type: "string", pattern: "^[a-f0-9]{64}$" }, reviewedBy: { type: "string" }, reason: { type: "string" } } }, OcrRecoveryRequest: { type: "object", required: ["recoveredBy", "reason"], properties: { recoveredBy: { type: "string" }, reason: { type: "string" } } }, OcrRecoveryResponse: { type: "object", required: ["versionId", "state", "outcome"], properties: { versionId: { type: "string", format: "uuid" }, state: { type: "string", const: "failed" }, outcome: { type: "string", const: "closed_failed" } } }, OcrApprovedIndexingRecoveryRequest: { type: "object", required: ["expectedState", "candidateSha256", "reviewedTextSha256", "expectedReviewedAt", "expectedReviewedBy", "expectedActiveVersionId", "recoveredBy", "reason"], properties: { expectedState: { type: "string", const: "review_required" }, candidateSha256: { type: "string", pattern: "^[a-f0-9]{64}$" }, reviewedTextSha256: { type: "string", pattern: "^[a-f0-9]{64}$" }, expectedReviewedAt: { type: "string", format: "date-time" }, expectedReviewedBy: { type: "string", minLength: 1 }, expectedActiveVersionId: { type: ["string", "null"], format: "uuid" }, recoveredBy: { type: "string", minLength: 1 }, reason: { type: "string", minLength: 1 } } }, OcrApprovedIndexingRecoveryEvidence: { type: "object", required: ["versionId", "state", "candidateSha256", "reviewedTextSha256", "expectedReviewedAt", "expectedReviewedBy", "expectedActiveVersionId"], properties: { versionId: { type: "string", format: "uuid" }, state: { type: "string", const: "review_required" }, candidateSha256: { type: "string", pattern: "^[a-f0-9]{64}$" }, reviewedTextSha256: { type: "string", pattern: "^[a-f0-9]{64}$" }, expectedReviewedAt: { type: "string", format: "date-time" }, expectedReviewedBy: { type: "string" }, expectedActiveVersionId: { type: ["string", "null"], format: "uuid" } } }, OcrApprovedIndexingRecoveryResponse: { type: "object", required: ["versionId", "state", "outcome", "idempotent"], properties: { versionId: { type: "string", format: "uuid" }, state: { type: "string", enum: ["indexing", "ready", "active"] }, outcome: { type: "string", const: "resumed_indexing" }, idempotent: { type: "boolean" } } }, OcrDecisionResponse: { type: "object", required: ["versionId", "state", "activated"], properties: { versionId: { type: "string", format: "uuid" }, state: { type: "string", enum: ["ready", "active", "rejected"] }, activated: { type: "boolean" } } }, CleanupRequest: { type: "object", required: ["scope"], properties: { scope: ref("Scope") } }, CleanupResponse: { type: "object", required: ["ok", "deleted"], properties: { ok: { type: "boolean" }, deleted: { type: "integer" } } }, BootstrapMeta: { type: "object", properties: { query: { type: "string" }, mode: ref("ChunkMode"), scope: ref("Scope"), model: { type: "string" }, usedModelSummary: { type: "boolean" } } }, RetrieveRequest: { type: "object", required: ["query"], properties: { mode: { ...ref("ChunkMode"), default: "auto" }, intent: { ...ref("RetrieveIntent"), default: "specific" }, query: { type: "string" }, scope: ref("Scope"), model: { type: "string", description: "Model override used only when useModelInRetrieve is true." }, useModelInRetrieve: { type: "boolean", default: false }, bootstrapMeta: ref("BootstrapMeta") } }, RetrievedItem: { type: "object", description: "A complete retrieved chunk, not the entire document. New file ingestions use the logical filename as title; existing stored titles are preserved.", required: ["chunkId", "documentId", "sourceId", "title", "content", "score"], properties: { chunkId: { type: "string" }, documentId: { type: "string" }, sourceId: { type: "string" }, sourceVersionId: { type: "string", format: "uuid" }, sourceVersionNumber: { type: "integer" }, title: { type: "string" }, sectionTitle: { type: "string" }, content: { type: "string" }, score: { type: "number" }, chunkMode: ref("ChunkMode"), startLine: { type: "integer" }, endLine: { type: "integer" } } }, RetrieveResponse: { type: "object", required: ["mode", "intent", "summary", "topics", "criticalPoints", "items", "followUpRefs"], properties: { mode: ref("ChunkMode"), intent: ref("RetrieveIntent"), model: { type: "string" }, summary: { type: "string" }, modelSummary: { type: "string" }, topics: { type: "array", items: { type: "string" } }, criticalPoints: { type: "array", items: { type: "string" } }, items: { type: "array", items: ref("RetrievedItem") }, followUpRefs: { type: "array", items: { type: "string" } }, scope: ref("Scope") } }, AnswerRequest: { type: "object", required: ["query"], properties: { mode: { ...ref("ChunkMode"), default: "auto" }, intent: { ...ref("RetrieveIntent"), default: "specific" }, query: { type: "string" }, scope: ref("Scope"), model: { type: "string" }, preloadedContext: { type: "string" }, bootstrapMeta: ref("BootstrapMeta") } }, Citation: { type: "object", required: ["chunkId", "documentId", "title"], properties: { chunkId: { type: "string" }, documentId: { type: "string" }, sourceVersionId: { type: "string", format: "uuid" }, sourceVersionNumber: { type: "integer" }, title: { type: "string" }, sectionTitle: { type: "string" }, startLine: { type: "integer" }, endLine: { type: "integer" } } }, AnswerResponse: { type: "object", required: ["mode", "intent", "model", "answer", "summary", "topics", "criticalPoints", "citations"], properties: { mode: ref("ChunkMode"), intent: ref("RetrieveIntent"), model: { type: "string" }, answer: { type: "string" }, summary: { type: "string" }, topics: { type: "array", items: { type: "string" } }, criticalPoints: { type: "array", items: { type: "string" } }, citations: { type: "array", items: ref("Citation") }, scope: ref("Scope") } }, DirectAnswerRequest: { type: "object", required: ["query"], properties: { query: { type: "string" }, model: { type: "string" }, preloadedContext: { type: "string" } } }, DirectAnswerResponse: { type: "object", required: ["model", "answer"], properties: { model: { type: "string" }, answer: { type: "string" } } }, ChatMessage: { type: "object", required: ["role", "content"], properties: { role: { type: "string", enum: ["user", "assistant"] }, content: { type: "string" } } }, ChatRequest: { type: "object", required: ["message"], properties: { message: { type: "string" }, history: { type: "array", items: ref("ChatMessage") }, mode: { ...ref("ChunkMode"), default: "documental" }, model: { type: "string" }, preloadedContext: { type: "string" }, allowAdditionalRetrieve: { type: "boolean", default: false }, scope: ref("Scope"), bootstrapMeta: ref("BootstrapMeta") } }, ChatResponse: { type: "object", description: "Model answer. retrieved is present only when allowAdditionalRetrieve is true, and includes full chunk contents. Preloaded context is not echoed back as retrieved items.", required: ["model", "answer", "usedBootstrapContext", "usedAdditionalRetrieve"], properties: { model: { type: "string" }, answer: { type: "string" }, usedBootstrapContext: { type: "boolean" }, usedAdditionalRetrieve: { type: "boolean" }, retrieved: ref("RetrieveResponse") } }, EvaluationLog: { type: "object", required: ["id", "trigger", "operation", "reason", "query", "createdAt", "retrievedItemsCount", "chunkIds", "documentIds", "reviewStatus", "severity"], properties: { id: { type: "string" }, trigger: { type: "string", enum: ["automatic", "manual"] }, operation: { type: "string", enum: ["retrieve", "answer", "chat"] }, reason: { type: "string" }, query: { type: "string" }, mode: ref("ChunkMode"), intent: ref("RetrieveIntent"), scope: ref("Scope"), model: { type: "string" }, note: { type: "string" }, createdAt: { type: "string", format: "date-time" }, usedBootstrapContext: { type: "boolean" }, bootstrapQuery: { type: "string" }, bootstrapMode: ref("ChunkMode"), bootstrapScope: ref("Scope"), bootstrapModel: { type: "string" }, bootstrapUsedModelSummary: { type: "boolean" }, usedAdditionalRetrieve: { type: "boolean" }, responseSummary: { type: "string" }, retrievedItemsCount: { type: "integer" }, chunkIds: { type: "array", items: { type: "string" } }, documentIds: { type: "array", items: { type: "string" } }, reviewStatus: { type: "string", enum: ["pending", "in_progress", "resolved", "ignored"] }, severity: { type: "string", enum: ["low", "medium", "high"] }, reviewedAt: { type: "string", format: "date-time" }, reviewedBy: { type: "string" }, resolutionNote: { type: "string" }, fixReference: { type: "string" }, supersedesLogId: { type: "string" } } }, ManualLogRequest: { type: "object", required: ["query"], properties: { operation: { type: "string", enum: ["retrieve", "answer", "chat"], default: "answer" }, reason: { type: "string", default: "manual_review_requested" }, query: { type: "string" }, mode: ref("ChunkMode"), intent: ref("RetrieveIntent"), scope: ref("Scope"), model: { type: "string" }, note: { type: "string" }, usedBootstrapContext: { type: "boolean" }, bootstrapMeta: ref("BootstrapMeta"), usedAdditionalRetrieve: { type: "boolean" }, responseSummary: { type: "string" }, retrievedItems: { type: "array", items: ref("RetrievedItem") } } }, UpdateLogRequest: { type: "object", properties: { reviewStatus: { type: "string", enum: ["pending", "in_progress", "resolved", "ignored"] }, severity: { type: "string", enum: ["low", "medium", "high"] }, reviewedBy: { type: "string" }, resolutionNote: { type: "string" }, fixReference: { type: "string" }, supersedesLogId: { type: "string" } } }, HealthResponse: { type: "object", required: ["ok", "service", "version", "revision", "environment", "embeddings", "answer", "vectorStore", "postgres", "knowledgeLifecycle", "parsers", "chunking"], properties: { ok: { type: "boolean" }, service: { type: "string", const: "rag" }, version: { type: "string" }, revision: { type: "string" }, environment: { type: "string" }, embeddings: ref("ProviderModel"), answer: ref("ProviderModel"), vectorStore: { type: "object", additionalProperties: true }, postgres: { type: "object", additionalProperties: true }, knowledgeLifecycle: { type: "object", additionalProperties: true }, parsers: { type: "array", items: { type: "string" } }, chunking: { type: "object", additionalProperties: true } } }, SourceVersion: { type: "object", required: ["versionId", "sourceId", "versionNumber", "state", "tags", "embeddingProvider", "embeddingModel", "embeddingDimensions", "expectedDocumentCount", "expectedPointCount", "verifiedPointCount", "qdrantCollection"], properties: { versionId: { type: "string", format: "uuid" }, sourceId: { type: "string" }, versionNumber: { type: "integer" }, previousVersionId: { type: ["string", "null"], format: "uuid" }, state: ref("SourceVersionState"), tags: { type: "array", items: { type: "string" } }, sourceContentHash: { type: ["string", "null"] }, processingFingerprint: { type: "string" }, metadataHash: { type: "string" }, embeddingProvider: { type: "string" }, embeddingModel: { type: "string" }, embeddingDimensions: { type: "integer" }, expectedDocumentCount: { type: "integer" }, expectedPointCount: { type: "integer" }, verifiedPointCount: { type: "integer" }, qdrantCollection: { type: "string" } } }, ActivateVersionRequest: { type: "object", required: ["expectedActiveVersionId"], properties: { expectedActiveVersionId: { type: ["string", "null"], format: "uuid" } } }, RollbackRequest: { type: "object", required: ["targetVersionId", "expectedActiveVersionId"], properties: { targetVersionId: { type: "string", format: "uuid" }, expectedActiveVersionId: { type: "string", format: "uuid" } } }, RetryVersionRequest: { type: "object", properties: { sourceType: { type: "string", enum: ["file", "folder"] }, sourceRef: { type: "string" }, readPath: { type: "string" }, mode: { type: "string", enum: ["mechanical", "interactive"], default: "mechanical" }, tags: { type: "array", items: { type: "string" } }, activate: { type: "boolean", default: true }, expectedActiveVersionId: { type: ["string", "null"], format: "uuid" } } }, RetryVersionResponse: { type: "object", required: ["ok", "retryRequired", "sourceId", "versionId", "message"], properties: { ok: { type: "boolean", const: true }, retryRequired: { type: "boolean", const: true }, sourceId: { type: "string" }, versionId: { type: "string", format: "uuid" }, message: { type: "string" } } }, PurgeResponse: { type: "object", required: ["ok", "purged", "versionId"], properties: { ok: { type: "boolean", const: true }, purged: { type: "boolean", const: true }, versionId: { type: "string", format: "uuid" } } }, ProviderModel: { type: "object", required: ["provider", "model"], properties: { provider: { type: "string" }, model: { type: "string" } } }, AnswerModelsResponse: { type: "object", required: ["defaultModel", "models"], properties: { defaultModel: { type: "string" }, models: { type: "array", items: { type: "string" }, maxItems: 80 } } }, HelpEndpoint: { type: "object", required: ["method", "path", "summary", "tags"], properties: { method: { type: "string" }, path: { type: "string" }, summary: { type: "string" }, tags: { type: "array", items: { type: "string" } } } }, HelpStep: { type: "object", required: ["step", "title", "responsibility", "operations", "input", "expected", "next"], properties: { step: { type: "integer" }, title: { type: "string" }, responsibility: { type: "string" }, operations: { type: "array", items: { type: "object", required: ["method", "path", "authentication"], properties: { method: { type: "string" }, path: { type: "string" }, authentication: { type: "string" } } } }, input: { type: "string" }, expected: { type: "string" }, next: { type: "string" } } }, HelpQueryMode: { type: "object", required: ["path", "model", "output"], properties: { path: { type: "string" }, model: { type: "string" }, output: { type: "string" } } }, HelpResponse: { type: "object", required: ["service", "version", "description", "documentation", "authentication", "ingestionWorkflow", "queryModes", "retrieveExample", "endpoints"], properties: { service: { type: "string" }, version: { type: "string" }, description: { type: "string" }, documentation: { type: "object", required: ["openapi", "openapiPurpose", "playground"], properties: { openapi: { type: "string" }, openapiPurpose: { type: "string" }, playground: { type: "string" } } }, authentication: { type: "string" }, ingestionWorkflow: { type: "array", items: ref("HelpStep"), minItems: 5, maxItems: 5 }, queryModes: { type: "array", items: ref("HelpQueryMode") }, retrieveExample: ref("RetrieveRequest"), endpoints: { type: "array", items: ref("HelpEndpoint") } } } } } } as const; type OpenApiOperation = { summary?: string; tags?: readonly string[]; }; export function buildApiHelp() { const operation = (method: "get" | "post", route: keyof typeof openApiDocument.paths) => { const details = (openApiDocument.paths[route] as Record)[method]; return { method: method.toUpperCase(), path: route, authentication: details?.security ? "Bearer lifecycle admin token" : "Public" }; }; const endpoints = Object.entries(openApiDocument.paths).flatMap(([routePath, pathItem]) => Object.entries(pathItem).map(([method, operation]) => { const details = operation as OpenApiOperation; return { method: method.toUpperCase(), path: routePath, summary: details.summary ?? "", tags: details.tags ?? [] }; }) ); return { service: openApiDocument.info.title, version: openApiDocument.info.version, description: openApiDocument.info.description, documentation: { openapi: "/openapi.json", openapiPurpose: "Consult this contract for complete parameters, request bodies, responses, errors, and examples for every endpoint.", playground: "/playground" }, authentication: "Bearer authentication is required for lifecycle administration and all OCR candidate routes; other routes remain public.", ingestionWorkflow: [ { step: 1, title: "Upload", responsibility: "User", operations: [operation("post", "/ingest/upload")], input: "multipart/form-data: file, activate=false; optional sourceId, sourceRef and tags. The logical filename becomes the title; the temporary UUID stays internal. ZIPs use isZipFolder=true and retain individual document titles.", expected: "Native ingestion: 201 with ready (or an existing reusable version). OCR: 202 with versionId, phase=ocr_queued and statusUrl; not active.", next: "Keep sourceId/versionId. Inspect processing status; a native ready version can proceed directly to activation." }, { step: 2, title: "Process and monitor", responsibility: "Service processes; user monitors", operations: [operation("get", "/ingestions/{versionId}"), operation("get", "/sources/{sourceId}/versions/{versionId}")], input: "Use returned IDs. OCR status requires OCR enabled and Bearer authentication; source-version detail is public.", expected: "OCR moves from ocr_queued/ocr_running to review_required. Inspect page decisions, warnings and error. Native extraction does not require OCR review.", next: "Review OCR at review_required; activate native versions only once ready. On failed/rejected, inspect the error rather than repeating upload." }, { step: 3, title: "Review and approve OCR", responsibility: "User explicitly reviews and approves", operations: [operation("get", "/ingestions/{versionId}/review"), operation("get", "/ingestions/{versionId}/documents/{documentId}/pages/{page}/image"), operation("post", "/ingestions/{versionId}/approve"), operation("post", "/ingestions/{versionId}/reject")], input: "Approve JSON: candidateSha256 from review, expectedActiveVersionId (current UUID or null), reviewedBy, corrections (empty array when no edits). Corrections require documentId/page/lineId/expectedLineSha256/replacementText. Reject uses candidateSha256, reviewedBy and reason.", expected: "Review text against private images and page selections. Approval starts indexing automatically and waits for its result: ready or active; duplicate reuse can return rejected. With activate=false, a new version stops at ready. Inspect status if the request fails or disconnects.", next: "Monitor indexing. Do not repeat approval to resume a transfer or skip human review. This step is skipped for native-only extraction." }, { step: 4, title: "Index and verify", responsibility: "Service indexes; user monitors", operations: [operation("get", "/ingestions/{versionId}"), operation("get", "/sources/{sourceId}/versions/{versionId}")], input: "No additional indexing request is needed after approval. Poll status with the returned versionId.", expected: "ready means points were verified, not that the version is active. OCR indexingTransfer exposes progress, signals, attempts and errors. indexing_paused is not automatically reset by restart.", next: "Activate only after ready. Inspect pause/error evidence. recover-indexing is solely for already-approved candidates stranded in review_required, not a reset of modern transfer pauses." }, { step: 5, title: "Activate and query", responsibility: "User", operations: [operation("post", "/sources/{sourceId}/versions/{versionId}/activate"), operation("post", "/retrieve")], input: "Activation JSON: expectedActiveVersionId (current UUID or null for first activation), with Bearer token. Query JSON: query, mode, intent, useModelInRetrieve=false and scope.sourceId.", expected: "Activation returns active. Retrieval exposes only the active version and returns full items[].content, IDs, scores and line ranges.", next: "Verify sourceVersionId in returned items. Keep the full JSON to read every chunk; chunk text is not the entire document." } ], queryModes: [ { path: "/retrieve", model: "useModelInRetrieve=false disables generative synthesis, not search embeddings. true adds a model summary.", output: "Full items[].content with chunk IDs, scores and line ranges, plus summary/topics/criticalPoints/followUpRefs." }, { path: "/answer", model: "Generates an answer from retrieved context.", output: "answer and citation metadata; citations do not include full chunk content." }, { path: "/chat", model: "Generates an answer using optional preloadedContext/history. Set allowAdditionalRetrieve=true to search as well.", output: "answer and usage flags. retrieved.items includes full chunks only when additional retrieval is requested. Preloaded context is not echoed." } ], retrieveExample: { query: "What does this document describe?", mode: "documental", intent: "specific", useModelInRetrieve: false, scope: { sourceId: "example:book" } }, endpoints }; }