openvideo-server 0.1.0__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/AGENTS.md +13 -1
  2. openvideo_server-0.2.0/DOWNLOAD_CLIENT.md +179 -0
  3. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/PKG-INFO +2 -1
  4. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/README.md +1 -0
  5. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/ROADMAP.md +10 -12
  6. openvideo_server-0.2.0/contracts/CHANGELOG.md +251 -0
  7. openvideo_server-0.2.0/contracts/README.md +82 -0
  8. openvideo_server-0.2.0/contracts/deviations.md +19 -0
  9. openvideo_server-0.2.0/contracts/implementation-status.md +79 -0
  10. openvideo_server-0.2.0/contracts/open-questions.md +3 -0
  11. openvideo_server-0.2.0/contracts/openapi.yaml +1692 -0
  12. openvideo_server-0.2.0/contracts/types.ts +240 -0
  13. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/docs/access.md +2 -2
  14. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/docs/api.md +45 -8
  15. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/example.yaml +1 -1
  16. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/_version.py +2 -2
  17. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/api/capabilities.py +6 -1
  18. openvideo_server-0.2.0/openvideo_server/api/openapi.py +400 -0
  19. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/api/routes_auth.py +2 -48
  20. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/api/routes_downloads.py +86 -10
  21. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/api/routes_history.py +38 -22
  22. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/api/routes_media.py +63 -5
  23. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/api/routes_playback.py +29 -1
  24. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/api/routes_server.py +1 -1
  25. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/api/routes_sources.py +34 -12
  26. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/api/routes_subtitles.py +20 -2
  27. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/core/browser.py +15 -0
  28. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/core/download_manager.py +20 -3
  29. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/core/session_manager.py +6 -21
  30. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/main.py +131 -4
  31. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/storage/db.py +14 -0
  32. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/storage/migrations.py +1 -1
  33. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/storage/repository.py +40 -42
  34. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_auth_routes.py +60 -7
  35. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_database.py +61 -0
  36. openvideo_server-0.2.0/tests/unit/test_download_routes.py +379 -0
  37. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_history_routes.py +119 -13
  38. openvideo_server-0.2.0/tests/unit/test_openapi.py +186 -0
  39. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_playback_routes.py +43 -0
  40. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_session_manager.py +1 -1
  41. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_sources_route.py +32 -6
  42. openvideo_server-0.1.0/tests/unit/test_download_routes.py +0 -192
  43. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/.github/ISSUE_TEMPLATE/bug_report.yml +0 -0
  44. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/.github/ISSUE_TEMPLATE/feature_request.yml +0 -0
  45. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/.github/dependabot.yml +0 -0
  46. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/.github/workflows/ci.yml +0 -0
  47. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/.github/workflows/docs.yml +0 -0
  48. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/.github/workflows/integration.yml +0 -0
  49. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/.github/workflows/release.yml +0 -0
  50. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/.gitignore +0 -0
  51. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/.python-version +0 -0
  52. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/CONTRIBUTING.md +0 -0
  53. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/LICENSE +0 -0
  54. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/NOTICE +0 -0
  55. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/SECURITY.md +0 -0
  56. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/docs/architecture.md +0 -0
  57. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/docs/configuration.md +0 -0
  58. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/docs/index.md +0 -0
  59. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/docs/install.md +0 -0
  60. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/docs/license.md +0 -0
  61. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/docs/requirements.txt +0 -0
  62. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/__init__.py +0 -0
  63. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/admin/__init__.py +0 -0
  64. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/admin/bridge.py +0 -0
  65. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/admin/client.py +0 -0
  66. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/admin/server.py +0 -0
  67. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/admin/service.py +0 -0
  68. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/admin/ui.py +0 -0
  69. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/api/__init__.py +0 -0
  70. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/api/dependencies.py +0 -0
  71. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/api/ranges.py +0 -0
  72. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/cli.py +0 -0
  73. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/config.py +0 -0
  74. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/core/__init__.py +0 -0
  75. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/core/security.py +0 -0
  76. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/discovery/__init__.py +0 -0
  77. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/discovery/bonjour.py +0 -0
  78. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/macos/__init__.py +0 -0
  79. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/macos/launch_agent.py +0 -0
  80. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/media/__init__.py +0 -0
  81. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/media/binaries.py +0 -0
  82. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/media/cache.py +0 -0
  83. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/media/downloads.py +0 -0
  84. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/media/probe.py +0 -0
  85. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/media/subtitles.py +0 -0
  86. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/media/thumbnails.py +0 -0
  87. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/redaction.py +0 -0
  88. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/runtime.py +0 -0
  89. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/storage/__init__.py +0 -0
  90. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/openvideo_server/storage/disk.py +0 -0
  91. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/pyproject.toml +0 -0
  92. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/conftest.py +0 -0
  93. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/packaging/test_wheel.py +0 -0
  94. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/support.py +0 -0
  95. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_admin_client.py +0 -0
  96. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_admin_service.py +0 -0
  97. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_admin_ui.py +0 -0
  98. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_app.py +0 -0
  99. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_auth_dependency.py +0 -0
  100. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_binaries.py +0 -0
  101. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_bonjour.py +0 -0
  102. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_browser.py +0 -0
  103. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_cli.py +0 -0
  104. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_config.py +0 -0
  105. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_disk.py +0 -0
  106. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_download_manager.py +0 -0
  107. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_download_profiles.py +0 -0
  108. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_download_repository.py +0 -0
  109. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_launch_agent.py +0 -0
  110. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_media_metadata_route.py +0 -0
  111. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_media_streaming.py +0 -0
  112. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_probe.py +0 -0
  113. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_redaction.py +0 -0
  114. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_runtime.py +0 -0
  115. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_security.py +0 -0
  116. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_server_endpoints_route.py +0 -0
  117. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_server_info_route.py +0 -0
  118. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_subtitle_routes.py +0 -0
  119. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_subtitles.py +0 -0
  120. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_thumbnail_route.py +0 -0
  121. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/tests/unit/test_thumbnails.py +0 -0
  122. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/uv.lock +0 -0
  123. {openvideo_server-0.1.0 → openvideo_server-0.2.0}/zensical.toml +0 -0
@@ -97,7 +97,9 @@ openvideo-server/
97
97
  ├── pyproject.toml # Dependencies, Ruff, and pytest configs
98
98
  ├── AGENTS.md # This instruction file
99
99
  ├── README.md # Product summary and documentation link
100
+ ├── DOWNLOAD_CLIENT.md # Client contract for offline conversion jobs
100
101
  ├── zensical.toml # Zensical site configuration
102
+ ├── contracts/ # Canonical OpenAPI, TypeScript mirror, changelog
101
103
  ├── docs/ # User-facing documentation site
102
104
  ├── openvideo_server/
103
105
  │ ├── __init__.py
@@ -193,7 +195,7 @@ async with db.execute(
193
195
  - Every interested client is a polling client. Return the job JSON and let it poll; do not hold a request open for the conversion. `POST /downloads` returns `202` for a new job and `200` when it reuses an active one.
194
196
  - Conversions write to a `.part` file and atomically replace the final artifact only after the process exits successfully. Check the configured disk-buffer percentage before launching, and return `DISK_LOW`/`FFMPEG_UNAVAILABLE` as `503` instead of starting a doomed encode.
195
197
  - The sweeper is the only component that deletes expired artifacts, and it must skip artifacts with an open byte-range stream (`stream_opened`/`stream_closed`). Acknowledging shortens the expiry to `download.ack_grace_seconds`; TTL and ack grace are "whichever comes first", not additive. Admin cache clearing must expire ready jobs whose artifact vanished.
196
- - Changing the download HTTP or job-state contract requires updating `docs/api.md`, `DOWNLOAD_CLIENT.md`, and `capability_version` together.
198
+ - Changing the download HTTP or job-state contract requires updating `contracts/openapi.yaml`, `contracts/types.ts`, `docs/api.md`, `DOWNLOAD_CLIENT.md`, and `contracts/CHANGELOG.md` together, plus `capability_version` when clients must gate the change.
197
199
 
198
200
  4.4. Error Handling & HTTP Responses
199
201
 
@@ -233,6 +235,16 @@ async with db.execute(
233
235
  - `network.advertised_urls` entries are validated by `_normalize_advertised_url` in `config.py`: absolute `http`/`https`, host required, no credentials, query, or fragment, trailing slash stripped, and exact duplicates after normalization rejected. Do not verify reachability from the server; hairpin NAT makes self-checks misleading.
234
236
  - `server_id` is derived from the server name and hostname. Renaming either invalidates saved pairings; document that behavior, and if it must change, persist an ID instead and describe the migration.
235
237
 
238
+ 4.8. Public API Contract and Documentation
239
+
240
+ - `contracts/openapi.yaml` is the canonical public API contract. `contracts/types.ts` mirrors its schemas, `contracts/CHANGELOG.md` records contract versions and decisions, and `contracts/open-questions.md` tracks unresolved gaps. `docs/api.md` is the human-readable reference; `DOWNLOAD_CLIENT.md` is the client-facing download contract.
241
+ - Every public API change ships in the same commit as its contract update. Do not merge a route, schema, status code, header, auth rule, error code, or advertised capability change while the canonical spec or `docs/api.md` still describes the old behavior.
242
+ - Update `contracts/types.ts` whenever a request, response, or shared schema changes. Update `DOWNLOAD_CLIENT.md` whenever the download job lifecycle, status codes, retry behavior, or artifact behavior changes.
243
+ - Add a `contracts/CHANGELOG.md` section for every contract revision, and keep `info.version` in `openapi.yaml` equal to the top changelog heading. Use PATCH for documentation-only clarifications.
244
+ - Bump `capability_version` in `api/routes_server.py` only when clients must gate a feature on the new behavior. A contract change that is backward-compatible and requires no client gate does not bump it.
245
+ - Remove resolved items from `contracts/open-questions.md`; add new unresolved questions there instead of leaving them only in chat or commit messages.
246
+ - Run `uv run pytest tests/unit/test_openapi.py -q` after changing the contract. `contracts/README.md` has the full artifact roles, checklist, and versioning rules.
247
+
236
248
  5. Testing Requirements for Agents
237
249
 
238
250
  1. Unit Tests (tests/unit/):
@@ -0,0 +1,179 @@
1
+ # Download Client Contract
2
+
3
+ This document defines the client-visible behavior of the offline conversion
4
+ API. The canonical machine-readable contract is
5
+ [`contracts/openapi.yaml`](contracts/openapi.yaml); this page explains the job
6
+ lifecycle and the decisions a client must make. If the two disagree, the
7
+ OpenAPI document wins.
8
+
9
+ All download routes require `Authorization: Bearer <device-token>`. Jobs are
10
+ owned by the authenticated device and are never shared between devices.
11
+
12
+ ## Job lifecycle
13
+
14
+ `POST /api/v1/downloads` accepts:
15
+
16
+ ```json
17
+ {
18
+ "media_id": "opaque-media-id",
19
+ "quality": "medium",
20
+ "client_capabilities": {
21
+ "video_codecs": ["h264"],
22
+ "audio_codecs": ["aac"],
23
+ "containers": ["mp4"]
24
+ }
25
+ }
26
+ ```
27
+
28
+ `media_id` is required. `quality` is optional and is one of `low`, `medium`, or
29
+ `high`. `client_capabilities` is optional; omitted arrays mean the client
30
+ declared no support for that category. Capability values are normalized the
31
+ same way as playback sessions: surrounding whitespace is stripped, values are
32
+ casefolded, leading dots are removed, and duplicates are collapsed. Send
33
+ lowercase values without a leading dot.
34
+
35
+ The response is a `DownloadJobResponse` with either status:
36
+
37
+ | Status | Meaning |
38
+ |---|---|
39
+ | `202` | A new conversion job was queued. |
40
+ | `200` | An active job for the same device, media, source fingerprint, and resolved profile was reused. |
41
+
42
+ Both responses carry the same body shape and a relative `Location` header
43
+ pointing at the job resource, for example
44
+ `Location: /api/v1/downloads/6f1c...`. Clients should treat the response body as
45
+ authoritative and use the returned `id`.
46
+
47
+ The server probes the source and prefers a remux when the declared client
48
+ capabilities match the source container and tracks. It re-encodes only
49
+ incompatible tracks. Video artifacts are H.264/AAC MP4; audio-only artifacts
50
+ are M4A. A job is deduplicated only while it is non-terminal. After a job is
51
+ acknowledged, canceled, failed, or expired, a later request starts a new
52
+ conversion.
53
+
54
+ `status` is a closed enum:
55
+
56
+ - `queued`
57
+ - `converting`
58
+ - `ready`
59
+ - `failed`
60
+ - `canceled`
61
+ - `expired`
62
+
63
+ Clients may switch exhaustively on these values. An unknown value is a server
64
+ defect, not a new wire value.
65
+
66
+ `progress` is `null` before conversion starts and otherwise a fraction from
67
+ `0` to `1`. `size_bytes`, `ready_at`, and `expires_at` are `null` until they are
68
+ known. `file_url` is non-null only while the job is `ready`. `created_at`,
69
+ `updated_at`, `ready_at`, and `expires_at` are Unix epoch seconds.
70
+
71
+ ## Polling
72
+
73
+ Poll `GET /api/v1/downloads/{job_id}` until the job reaches a terminal state.
74
+ The server never holds the request open for conversion, so every client is a
75
+ polling client.
76
+
77
+ - `200` returns the current job.
78
+ - `401` means the bearer token is missing or invalid.
79
+ - `404` means the job does not exist for this device.
80
+ - `410` means the job has expired.
81
+
82
+ Use a short interval while `queued` or `converting` (one to two seconds is
83
+ reasonable) and back off after repeated errors. `GET /api/v1/downloads` lists
84
+ this device's jobs with `limit` and `offset` and returns a `DownloadListing`
85
+ envelope (`items`, `total`, `offset`, `limit`, `has_more`).
86
+
87
+ ## Downloading the artifact
88
+
89
+ Request `GET /api/v1/downloads/{job_id}/file` only after the job is `ready`.
90
+
91
+ | Status | Meaning |
92
+ |---|---|
93
+ | `200` | Full artifact body. |
94
+ | `206` | Partial body for a valid `Range` request; `Content-Range` is set. |
95
+ | `401` | Missing or invalid bearer token. |
96
+ | `404` | Job not found for this device. |
97
+ | `409` | Artifact is not ready. `error.code` is the job's `error_code` or `NOT_READY`. |
98
+ | `410` | The job or artifact has expired. |
99
+ | `416` | The requested byte range is not satisfiable; `Content-Range` is `bytes */<size>`. |
100
+
101
+ While a job is `queued` or `converting`, the `409` response includes
102
+ `Retry-After: 2`. Clients may resume downloads with byte ranges. Artifact
103
+ responses include `Accept-Ranges: bytes` and `Content-Disposition: attachment;
104
+ filename="<media_id>.<extension>"`. Video is served as `video/mp4`; audio-only
105
+ is served as `audio/mp4`.
106
+
107
+ Do not construct artifact URLs from local paths or assume `file_url` is
108
+ absolute. Resolve it relative to the server base URL and send the bearer token.
109
+
110
+ ## Acknowledging and canceling
111
+
112
+ After the artifact has been saved durably, call
113
+ `POST /api/v1/downloads/{job_id}/acknowledge`:
114
+
115
+ - `204` means the acknowledgement was recorded.
116
+ - `401` means the bearer token is missing or invalid.
117
+ - `404` means the job does not exist for this device.
118
+ - `409` means the job is not `ready` and cannot be acknowledged.
119
+ - `410` means the job has expired.
120
+
121
+ Acknowledging shortens the artifact's expiry to
122
+ `download.ack_grace_seconds` from the acknowledgement, or the original
123
+ `download.ttl_hours` deadline, whichever comes first. It is not additive.
124
+
125
+ To abandon a job, call `DELETE /api/v1/downloads/{job_id}`:
126
+
127
+ - `204` means the job was canceled and its artifact removed.
128
+ - `401` means the bearer token is missing or invalid.
129
+ - `404` means the job does not exist for this device.
130
+
131
+ Deleting removes the job record as well as the artifact, so a later request
132
+ starts a fresh conversion. Do not require the user to delete a local copy
133
+ first.
134
+
135
+ ## Expiry
136
+
137
+ A `ready` job remains downloadable until `expires_at`. The background sweeper
138
+ removes expired artifacts and marks jobs `expired`; it does not remove an
139
+ artifact while a byte-range response is streaming. Clients should treat `410`
140
+ as a normal expired-download outcome and request a new job if the media is
141
+ still needed.
142
+
143
+ ## Request errors
144
+
145
+ `POST /api/v1/downloads` can fail before a job exists:
146
+
147
+ | Status | `error.code` | Meaning |
148
+ |---|---|---|
149
+ | `401` | `unauthorized` | Missing or invalid bearer token. |
150
+ | `403` | `forbidden` | The resolved media path is outside the configured source. |
151
+ | `404` | `not_found` | The media was not found or its source is unavailable. |
152
+ | `415` | `unsupported_media_type` | The media type cannot be converted. |
153
+ | `422` | `unprocessable_entity` | The media cannot be inspected or no compatible profile exists. |
154
+ | `429` | `QUEUE_FULL`, `DEVICE_LIMIT` | The global queue or this device's active-job limit is reached. `Retry-After: 10` is set. |
155
+ | `503` | `FFMPEG_UNAVAILABLE`, `DISK_LOW` | Conversion cannot start because FFmpeg is unavailable or free disk space is below the configured buffer. |
156
+
157
+ All non-2xx responses use the standard error envelope:
158
+
159
+ ```json
160
+ {
161
+ "error": {
162
+ "code": "NOT_READY",
163
+ "message": "Download is not ready",
164
+ "details": null
165
+ }
166
+ }
167
+ ```
168
+
169
+ `details` is `null` unless the server has structured validation detail to add.
170
+ Clients should display `message` when present and may branch on `code` for
171
+ retry or user-facing behavior.
172
+
173
+ ## Contract maintenance
174
+
175
+ When the download HTTP contract, job-state enum, status codes, headers, or
176
+ error codes change, update `contracts/openapi.yaml`, `contracts/types.ts`,
177
+ `docs/api.md`, this file, and `contracts/CHANGELOG.md` together. Bump
178
+ `capability_version` only when clients must gate the change. See
179
+ [`contracts/README.md`](contracts/README.md) for the full checklist.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: openvideo-server
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: A lightweight personal media streaming server
5
5
  Project-URL: Homepage, https://isaiah1112.github.io/openvideo-server/
6
6
  Project-URL: Documentation, https://isaiah1112.github.io/openvideo-server/
@@ -117,6 +117,7 @@ openvideo-server --version
117
117
  | [Architecture](https://isaiah1112.github.io/openvideo-server/architecture/) | Components, runtime layout, database schema |
118
118
  | [Configuration](https://isaiah1112.github.io/openvideo-server/configuration/) | `config.yaml` sample and full reference |
119
119
  | [API](https://isaiah1112.github.io/openvideo-server/api/) | REST endpoints, playback sessions, downloads |
120
+ | [Download client contract](DOWNLOAD_CLIENT.md) | Job lifecycle, polling, byte ranges, retries, and error handling |
120
121
  | [Access & Security](https://isaiah1112.github.io/openvideo-server/access/) | Pairing, admin window, TLS and remote access |
121
122
 
122
123
  ## Development
@@ -81,6 +81,7 @@ openvideo-server --version
81
81
  | [Architecture](https://isaiah1112.github.io/openvideo-server/architecture/) | Components, runtime layout, database schema |
82
82
  | [Configuration](https://isaiah1112.github.io/openvideo-server/configuration/) | `config.yaml` sample and full reference |
83
83
  | [API](https://isaiah1112.github.io/openvideo-server/api/) | REST endpoints, playback sessions, downloads |
84
+ | [Download client contract](DOWNLOAD_CLIENT.md) | Job lifecycle, polling, byte ranges, retries, and error handling |
84
85
  | [Access & Security](https://isaiah1112.github.io/openvideo-server/access/) | Pairing, admin window, TLS and remote access |
85
86
 
86
87
  ## Development
@@ -37,7 +37,7 @@ in the previous roadmap, which was stale:
37
37
  notes, prerelease marking, and the post-publish install check.
38
38
  - **Runtime and features (done).** Sandboxed browser, ffprobe cache, thumbnails,
39
39
  Direct Play/remux/HLS, subtitles as WebVTT, pairing, advertised endpoints,
40
- Bonjour, and per-device convert-and-download jobs (`capability_version = 4`).
40
+ Bonjour, and per-device convert-and-download jobs (`capability_version = 5`).
41
41
  - **HLS today is single-rendition.** `core/session_manager.py` selects one
42
42
  `HlsRendition` per session (`auto`/`360p`/`480p`/`720p`/`1080p`) and serves a
43
43
  one-variant `master.m3u8`; `quality_selection`/`hls_variants` describe the
@@ -169,17 +169,15 @@ guarded workflow and add a manual rehearsal before the first real tag.
169
169
 
170
170
  ### 2.7 API and client contract
171
171
 
172
- - [ ] **Add `DOWNLOAD_CLIENT.md`.** The file is referenced by `AGENTS.md` and
173
- this roadmap but is missing from the repo. Document the download job
174
- contract: `POST /api/v1/downloads` returns `202` for a new job and `200`
175
- for a reused active one with the same `DownloadJobResponse` and a
176
- `Location` header; polling `GET /api/v1/downloads/{id}`; `GET
177
- /api/v1/downloads/{id}/file` (206 on range, 416 unsatisfiable, 409
178
- `NOT_READY` with `Retry-After`, 410 expired); `POST .../acknowledge`
179
- (204/409); cancel is `DELETE /api/v1/downloads/{id}` (204/404); plus 429
180
- queue/device limit, 503 `FFMPEG_UNAVAILABLE`/`DISK_LOW`, 415 not
181
- convertible, 422 probe/profile error. Link it from the README and
182
- `docs/api.md`.
172
+ - [x] **Document the download client contract.** `DOWNLOAD_CLIENT.md` covers
173
+ `POST /api/v1/downloads` (202 for a new job, 200 for a reused active one,
174
+ with the same `DownloadJobResponse` and a `Location` header), polling
175
+ `GET /api/v1/downloads/{id}`, `GET /api/v1/downloads/{id}/file` (206 on
176
+ range, 416 unsatisfiable, 409 `NOT_READY` with `Retry-After`, 410
177
+ expired), `POST .../acknowledge` (204/409), cancel via `DELETE
178
+ /api/v1/downloads/{id}` (204/404), 429 queue/device limits, 503
179
+ `FFMPEG_UNAVAILABLE`/`DISK_LOW`, 415 not convertible, and 422
180
+ probe/profile errors. Linked from `README.md` and `docs/api.md`.
183
181
  - [ ] **Echo `server_id` from the pairing routes.** Add `server_id` to the
184
182
  `POST /api/v1/auth/pin` and `POST /api/v1/auth/pair` responses, computed
185
183
  with the same `server_id_for(config.server.name)` used by `/info`,
@@ -0,0 +1,251 @@
1
+ # Changelog
2
+
3
+ Contract versioning: MAJOR.MINOR.PATCH following SemVer pre-1.0 conventions.
4
+ While the major is 0, MINOR bumps may contain breaking changes to request
5
+ and response shapes. PATCH is always backward-compatible. Version 1.0.0 was
6
+ the initial contract; 2.0.0 is the first breaking revision.
7
+
8
+
9
+ ## 11.0.2 - 2026-12-04
10
+
11
+ PATCH: tightened `BrowseListing.limit` to match the HTTP wire behavior.
12
+
13
+ - Changed `BrowseListing.limit` from nullable to a non-null integer with `default: 200`, matching `HistoryListing` and `DownloadListing`.
14
+ - Tightened the server `BrowseListing` model to `int = 200` and made each browse handler pass its validated `limit` explicitly.
15
+ - Mirrored the non-null type in `contracts/types.ts`.
16
+ - No breaking wire change: every browse HTTP handler already required `limit` as an integer query parameter and returned it.
17
+
18
+ ### Decisions
19
+
20
+ - D2 (`BrowseListing.limit` nullable only in the spec): SPEC BUG. The internal browser can hold `None`, but no HTTP path exposes that state.
21
+
22
+ ## 11.0.1 - 2026-12-04
23
+
24
+ PATCH: documentation clarifications and the download client contract.
25
+
26
+ - Added `DOWNLOAD_CLIENT.md` with the job lifecycle, polling, byte-range, acknowledgement, cancellation, expiry, and error-handling rules.
27
+ - Added `contracts/README.md` with artifact roles, the per-change checklist, versioning rules, and verification commands.
28
+ - Linked the canonical spec and changelog from `docs/api.md`, and linked the download client contract from `README.md` and `docs/api.md`.
29
+ - Documented source `read_only` and every browse `kind` in `docs/api.md`.
30
+ - Documented client capability normalization in the `ClientCapabilities` description and `docs/api.md`.
31
+ - Removed unreachable global-history branches; no public API or wire change.
32
+ - No wire schema, public behavior, or `capability_version` change.
33
+
34
+ ### Decisions
35
+
36
+ - Kept the contract version separate from `capability_version`; this is documentation only, so clients need no new gate.
37
+ - Documented the existing download behavior rather than changing the API to fit the missing guide.
38
+
39
+ ## 11.0.0 - 2026-12-03
40
+
41
+ BREAKING: removed the undocumented `GET /pair` browser page.
42
+
43
+ - `GET /pair` and `_PAIRING_PAGE_HTML` are gone; clients must use `POST /api/v1/auth/pin` and `POST /api/v1/auth/pair`. A regression test asserts the route returns `404`.
44
+ - Marked the legacy thumbnail and download aliases deprecated in FastAPI and the canonical spec; they remain hidden and callable.
45
+ - Renamed the internal `download_jobs.bytes` column to `size_bytes` with an idempotent migration; API field names are unchanged.
46
+ - Documented `GET /api/v1/playback/{session_id}/stream.m3u8`, the sidecar subtitle route, the empty-capability HLS fallback, and playback-progress validation in `docs/api.md`.
47
+ - No wire schema or `capability_version` change beyond the `/pair` removal.
48
+
49
+ ### Decisions
50
+
51
+ - Removed `/pair` instead of adding tests because the page only duplicated the PIN flow and had no client contract.
52
+ - Kept the legacy media aliases for one more deprecation window rather than removing them in the same release.
53
+
54
+ ## 10.0.2 - 2026-12-03
55
+
56
+ PATCH: generated OpenAPI now documents explicit binary media types and range headers.
57
+
58
+ - The canonical contract already declared binary media types and range headers, but FastAPI's generated document emitted `application/json` with an empty schema for `FileResponse`/`StreamingResponse` routes and no content for HLS playlist and segment routes.
59
+ - Added response metadata to thumbnail, media download/stream, download artifact, HLS playlist/segment, and subtitle routes. Generated OpenAPI now matches the canonical 200/206 responses.
60
+ - Documented that media, download-artifact, and HLS segment responses infer a concrete `Content-Type` from the file extension; the contract keeps `application/octet-stream` as the conservative type.
61
+ - No wire behavior, request/response schema, or `capability_version` change.
62
+
63
+ ### Decisions
64
+
65
+ - Kept `application/octet-stream` as the documented contract type because the served type varies by extension, and listed the common concrete types in endpoint descriptions.
66
+
67
+ ## 10.0.1 - 2026-12-03
68
+
69
+ PATCH: generated OpenAPI now documents both `POST /api/v1/downloads` success statuses.
70
+
71
+ - The canonical contract already listed 200 (reused active job) and 202 (new job), but FastAPI's generated document listed only 202.
72
+ - Added response metadata so generated OpenAPI includes both statuses with `DownloadJobResponse` and the `Location` header.
73
+ - No wire behavior, request/response schema, or `capability_version` change.
74
+
75
+ ### Decisions
76
+
77
+ - Kept the shipped 200/202 distinction instead of collapsing to 202, because clients already rely on it and it exposes reuse without an extra field.
78
+
79
+ ## 10.0.0 - 2026-12-03
80
+
81
+ BREAKING: `GET /api/v1/history` now includes rows whose media is unavailable.
82
+
83
+ - Old: `HistoryItem` always had `name: string`; unavailable rows were silently omitted and `total` counted only the returned rows.
84
+ - New: every stored row is returned. `HistoryItem` adds required `available: boolean`; `name` is `string | null`; unavailable rows use `name: null`, `kind: "other"`, and stay in `total`/offset pagination.
85
+ - `kind` remains `"video" | "audio" | "other"`; `"other"` is the fallback when the file cannot be resolved.
86
+
87
+ ### Decisions
88
+
89
+ - Kept identity and pagination stable across temporary source outages instead of adding a `skipped` count that cannot identify omitted rows.
90
+ - No database migration: the stored row already has the media id, progress, and timestamp; only display metadata is missing.
91
+ - `capability_version` remains `5`; this corrects the history response shape without adding an advertised capability.
92
+
93
+ ## 9.0.0 - 2026-12-03
94
+
95
+ BREAKING: `DownloadJobResponse.status` is now a closed six-value string enum instead of an open string.
96
+
97
+ - Old: `status: string`, with `queued`, `converting`, `ready`, `failed`, `canceled`, and `expired` listed only in the description.
98
+ - New: `status: "queued" | "converting" | "ready" | "failed" | "canceled" | "expired"`.
99
+ - A persisted row with any other value now fails response validation (`500`) instead of leaking an unknown state to the client.
100
+ - `GET /api/v1/server/info` reports `capability_version: 5` (was `4`) because the download job-state contract changed.
101
+
102
+ ### Decisions
103
+
104
+ - Closed the download state machine because every status write uses one of the six literals; Swift clients can now switch exhaustively.
105
+ - Kept the wire values unchanged for valid jobs; the break is schema narrowing, not a value rename.
106
+
107
+ ## 8.0.0 - 2026-12-03
108
+
109
+ BREAKING: `GET /api/v1/downloads` now returns a `DownloadListing` envelope instead of a bare array. Both list endpoints accept `limit` and `offset`.
110
+
111
+ - Old: `GET /api/v1/downloads` returned `DownloadJobResponse[]`; `GET /api/v1/history` returned `{items}`.
112
+ - New: `GET /api/v1/downloads` returns `{items, total, offset, limit, has_more}`. `GET /api/v1/history` returns the same fields with `items`.
113
+ - Both endpoints accept `limit` (default `200`, `1..1000`) and `offset` (default `0`, minimum `0`). Values outside those bounds return `422`.
114
+ - `GET /api/v1/history` filters entries whose media no longer resolves before computing `total`, so `total` and `has_more` describe the returned list.
115
+
116
+ ### Decisions
117
+
118
+ - Reused the browse pagination shape so clients have one envelope convention. Downloads keeps its newest-first order; history keeps newest-first order and applies the page after filtering unavailable media.
119
+
120
+ ## 7.0.0 - 2026-12-03
121
+
122
+ BREAKING: `POST /api/v1/playback/session` now accepts only the shared `low|medium|high` quality enum or `null`; all other strings return `422`.
123
+
124
+ - Old: `PlaybackSessionRequest.quality` was any string up to 32 characters. Unknown values silently selected `auto`, and aliases such as `720p`, `4k`, `hd`, and `source` were accepted.
125
+ - New: `PlaybackSessionRequest.quality` uses the shared `Quality` schema (`low`, `medium`, `high`) or `null`. `low` selects 480p, `medium` selects 720p, `high` selects 1080p, and `null` selects automatic rendition selection.
126
+ - `DownloadCreateRequest.quality` keeps the same `low|medium|high|null` values and now references the same `Quality` schema.
127
+
128
+ ### Decisions
129
+
130
+ - Unified playback and download quality on one closed enum. Playback aliases and silent fallback to `auto` were removed so a typo fails with `422` instead of changing the stream.
131
+
132
+ ## 6.0.0 - 2026-12-03
133
+
134
+ BREAKING: `PUT /api/v1/history/{media_id}` now returns `updated_at` as an RFC 3339 UTC string instead of integer Unix epoch seconds.
135
+
136
+ - Old: `PlaybackProgressResponse.updated_at: integer` (`2023-11-14T22:13:20Z` was represented as `1700000000`).
137
+ - New: `PlaybackProgressResponse.updated_at: string` with `format: date-time` (`2023-11-14T22:13:20Z`).
138
+ - `GET /api/v1/history` already returned RFC 3339 and is unchanged.
139
+
140
+ ### Decisions
141
+
142
+ - Unified history timestamps on RFC 3339 UTC because the list endpoint and its test already use that encoding, while the update response was the outlier. The database column remains `INTEGER`.
143
+
144
+ ## 5.0.0 - 2026-12-03
145
+
146
+ BREAKING: all three browse endpoints now return `BrowseListing` with `items`/`total`, `path`, `parent_path`, nullable `source_id`/`directory_id`, and `BrowseItem` entries.
147
+
148
+ - `/api/v1/sources/{source_id}/browse` old: `{source_id, directory_id, entries, total_entries, ...}` with `DirectoryEntry` (`kind: directory|video|audio|image|file`, `modified_at` Unix seconds).
149
+ - `/api/v1/sources/{source_id}/browse` new: `{path, parent_path, source_id, directory_id, items, total, ...}` with `BrowseItem` (`kind: folder|video|audio|image|other`, `modified_at` RFC 3339 or null).
150
+ - `/api/v1/browse/{directory_id}` changes the same way.
151
+ - `/api/v1/browse?path=/` gains `source_id: null` and `directory_id: null` at the virtual root.
152
+
153
+ ### Decisions
154
+
155
+ - Unified the public listing envelope on `BrowseListing`; `Browser` keeps its internal `DirectoryListing` and the routes convert at the boundary.
156
+ - Settled the item kind enum on `folder|video|audio|image|other`; `EntryKind.FILE` maps to `other`.
157
+ - Settled browse timestamps on RFC 3339 UTC, nullable for virtual root items.
158
+ - Removed `DirectoryEntry`, `DirectoryListing`, and `EntryKind` from the public contract because no endpoint returns them after this change.
159
+
160
+ ## 4.0.0 - 2026-12-03
161
+
162
+ BREAKING: `GET /api/v1/browse?path=/` now returns the source root's opaque directory identifier in `BrowseItem.id` instead of the configured source ID.
163
+
164
+ - Old: `{"id": "films", "name": "Films", "path": "/films", ...}`
165
+ - New: `{"id": "<source-root directory id>", "name": "Films", "path": "/films", ...}`
166
+
167
+ ### Decisions
168
+
169
+ - Made root `BrowseItem.id` usable as the `directory_id` for `GET /api/v1/browse/{directory_id}` so clients can navigate a listing without switching to `path`.
170
+ - Kept `BrowseItem.path` as `/source_id` because it remains the stable logical client path.
171
+ - Reused the root identifier already registered by `Browser` at startup; no identifier-store format change.
172
+
173
+ ## 3.0.0 - 2026-12-03
174
+
175
+ BREAKING: `POST /api/v1/auth/pair` now returns the device identifier as `id`.
176
+
177
+ - Old: `{"device_id": "...", "device_name": "...", "client_token": "...", "paired_at": 0}`
178
+ - New: `{"id": "...", "device_name": "...", "client_token": "...", "paired_at": 0}`
179
+
180
+ ### Decisions
181
+
182
+ - Renamed `PairedDeviceResponse.device_id` to `id` so pairing and `GET /api/v1/auth/devices` share one device identity field.
183
+ - Kept `DELETE /api/v1/auth/devices/{device_id}` unchanged because the path parameter already names the target unambiguously.
184
+ - Chose `id` over `device_id` because `SourceSummary` and `DeviceInfo` already use `id`, and `paired_devices.id` is the persisted primary key.
185
+
186
+ ## 2.0.1 - 2026-12-03
187
+
188
+ Generated `/openapi.json` now matches the canonical contract's auth and error metadata.
189
+
190
+ ### Decisions
191
+
192
+ - Added a custom OpenAPI transform that publishes `bearerAuth`, per-operation `security`, and the canonical non-2xx responses while removing the optional `authorization` header parameter produced by `Header()`.
193
+ - Kept this as a PATCH because the wire contract is unchanged; only the generated schema now reflects the documented security and error behavior.
194
+ - Added a parity test against `contracts/openapi.yaml` so future routes cannot silently drop their security or failure responses.
195
+
196
+ ## 2.0.0 - 2026-12-03
197
+
198
+ BREAKING: every non-2xx response now uses one error envelope.
199
+
200
+ - Old: `{"detail": "..."}`, `{"detail": {"code": "...", "message": "..."}}`, or `{"detail": [{...}]}`.
201
+ - New: `{"error": {"code": "...", "message": "...", "details": null | ValidationError[]}}`.
202
+
203
+ ### Decisions
204
+
205
+ - Adopted a single `error` envelope because the previous `detail` union forced Swift clients to branch on status before decoding.
206
+ - Mapped HTTP failures to lowercase status-derived codes such as `unauthorized`, `not_found`, and `too_many_requests` so clients can switch on one stable string.
207
+ - Preserved uppercase download domain codes such as `QUEUE_FULL` and `FFMPEG_UNAVAILABLE` in `error.code` so existing download semantics stay visible.
208
+ - Returned request-validation failures as `validation_error` with the FastAPI error list in `error.details`.
209
+ - Added a 500 fallback that logs the exception and returns `internal_error`, keeping unhandled failures inside the same envelope.
210
+ - Kept `details` required and `null` when absent so Swift can decode it without an optional-key distinction.
211
+
212
+ ## 1.0.0 - 2026-12-03
213
+
214
+ Initial canonical contract for OpenVideo Server `0.0.1.dev114+gb4237f1aa`.
215
+
216
+ ### Decisions
217
+
218
+ - Adopted OpenAPI 3.1.0 because the generated baseline is 3.1.0 and uses 3.1 nullable and `const` constructs.
219
+ - Set the contract version to `1.0.0` while preserving the runtime server version in `info.x-server-version`.
220
+ - Counted 34 operations across 30 paths, including the 31 operations present in the generated baseline and the three `include_in_schema=False` routes.
221
+ - Documented `GET /pair`, `GET /api/v1/download/{media_id}`, and `GET /api/v1/thumbnails/{media_id}` with `x-hidden: true` and `deprecated: true` because they are callable but omitted from the generated spec.
222
+ - Excluded the private Unix-socket admin application because it is not reachable through the public HTTP API.
223
+ - Applied `bearerAuth` globally and overrode `security: []` only for `GET /api/v1/server/info`, `POST /api/v1/auth/pin`, `POST /api/v1/auth/pair`, and `GET /pair`.
224
+ - Used an opaque `http` bearer scheme rather than a JWT or OAuth scheme because the server stores SHA-256 token digests and issues random URL-safe tokens.
225
+ - Documented 401 for missing, malformed, or unknown bearer tokens, with `WWW-Authenticate: Bearer`, matching the shared auth dependency.
226
+ - Documented 403 separately for loopback-only PIN/page requests, the remote-access middleware, and path-sandbox violations because those are authorization failures after or outside bearer authentication.
227
+ - Stated the remote-access middleware rule in `info.description` because it can reject any non-loopback request before routing, including public routes.
228
+ - Modeled the device-name trim and blank rejection as `x-validation` instead of a regex because OpenAPI cannot express `str.strip()`.
229
+ - Modeled the current error body as `ErrorResponse.detail` being a string, a download `{code,message}` object, or a FastAPI validation array because there is no single error envelope.
230
+ - Left `HTTPValidationError.detail` as an array of `ValidationError` for standard request-validation failures and did not force all failures into that shape.
231
+ - Chose RFC 3339 UTC strings with a `Z` suffix for every `datetime` response field because FastAPI serializes timezone-aware UTC datetimes that way.
232
+ - Kept `PlaybackProgressResponse.updated_at`, `DeviceInfo.paired_at`, `DeviceInfo.last_seen_at`, `PairedDeviceResponse.paired_at`, and download timestamps as integer Unix epoch seconds because those Pydantic models use `int`.
233
+ - Made every response field required and nullable where the server can emit `null` because Pydantic serializes absent optional response values as explicit `null`.
234
+ - Declared that clients should ignore unknown response fields because the server does not promise closed response objects.
235
+ - Kept `additionalProperties: false` only on request models that set `extra="forbid"` and left query extras ignored, matching FastAPI/Pydantic behavior.
236
+ - Encoded all enums as JSON strings because the code uses `Literal` string values and `StrEnum`.
237
+ - Preserved the two distinct quality domains: playback `quality` remains an unconstrained nullable string, while download `quality` remains `low|medium|high`.
238
+ - Preserved the two different quality alias tables in open questions rather than normalizing them silently.
239
+ - Preserved `BrowseItem.kind` as `folder|video|audio|image|other` and `DirectoryEntry.kind` as `directory|video|audio|image|file` because the route conversion deliberately maps between them.
240
+ - Preserved `BrowseItem.modified_at` as an RFC 3339 datetime and `DirectoryEntry.modified_at` as epoch seconds because the route converts one into the other.
241
+ - Documented `POST /api/v1/downloads` returning both 202 for a new job and 200 for a reused active job, including the `Location` header.
242
+ - Left `DownloadJobResponse.status` as `string` because the Pydantic model is `str`; known values are listed in the field description.
243
+ - Documented byte-range responses as `200` and `206` with `Accept-Ranges` and `Content-Range`, and `416` with `Content-Range: bytes */<size>`.
244
+ - Used `application/octet-stream` for direct media and download artifacts, with open questions noting that the actual response `Content-Type` is guessed from the file extension.
245
+ - Used `application/vnd.apple.mpegurl` for both HLS playlists and `text/vtt` for subtitles because those media types are set explicitly in the handlers.
246
+ - Documented the HLS playlist readiness contract as `503` with `Retry-After`, matching the session manager wait and retry behavior.
247
+ - Documented browse pagination as `limit` (1-1000, default 200) plus `offset` (minimum 0), and left history/download lists unpaginated because the code exposes no cursor or page parameters.
248
+ - Kept media, job, session, source, and directory identifiers as plain strings because the server treats them as opaque and does not constrain their format at the HTTP boundary.
249
+ - Represented `ClientCapabilities` arrays as string arrays with `uniqueItems: true` because the model uses `set[str]` and normalizes values.
250
+ - Generated `contracts/types.ts` from the finalized schemas with required nullable response fields and optional defaulted request fields to match Pydantic serialization and input behavior.
251
+ - Left the `PlaybackProgressUpdate` cross-field rule as `x-validation` because OpenAPI cannot express `position_seconds <= duration_seconds`.
@@ -0,0 +1,82 @@
1
+ # API Contract
2
+
3
+ This directory owns the public HTTP contract for OpenVideo Server. The local
4
+ admin application runs on a private Unix domain socket and is intentionally not
5
+ part of this contract.
6
+
7
+ ## Artifacts
8
+
9
+ | File | Role |
10
+ |---|---|
11
+ | `openapi.yaml` | Canonical OpenAPI 3.1 contract. This is the source of truth. |
12
+ | `types.ts` | TypeScript mirror of the request, response, and shared schemas. |
13
+ | `CHANGELOG.md` | Contract version history and the decisions behind each change. |
14
+ | `open-questions.md` | Unresolved contract gaps and questions. Remove an item when it is settled. |
15
+ | `../docs/api.md` | Human-readable API reference. It must agree with the canonical spec. |
16
+ | `../DOWNLOAD_CLIENT.md` | Client-facing download job lifecycle and retry guidance. |
17
+
18
+ The running server serves its generated document at `/openapi.json`, with
19
+ interactive documentation at `/docs` and `/redoc`. The generated document is not
20
+ the source of truth; `contracts/openapi.yaml` is.
21
+
22
+ ## When to update the contract
23
+
24
+ Update the contract in the same change as any public API change, including:
25
+
26
+ - adding, removing, or renaming a route;
27
+ - changing a request or response field, type, nullability, default, or enum;
28
+ - changing an authentication or authorization requirement;
29
+ - adding or changing a status code, response header, or error `code`;
30
+ - changing a capability advertised by `GET /api/v1/server/info`;
31
+ - changing a client-visible job state, retry rule, or expiry rule.
32
+
33
+ Documentation-only clarifications that do not change the wire contract still
34
+ get a `contracts/CHANGELOG.md` entry so clients can tell which revision of the
35
+ document they are reading.
36
+
37
+ ## Change checklist
38
+
39
+ 1. Update `openapi.yaml`.
40
+ 2. Update `types.ts` when a schema changed.
41
+ 3. Update `docs/api.md` when behavior or usage changed.
42
+ 4. Update `../DOWNLOAD_CLIENT.md` when the download contract changed.
43
+ 5. Add a `contracts/CHANGELOG.md` section with the new contract version, date,
44
+ summary, and decisions.
45
+ 6. Remove resolved entries from `open-questions.md` and add new ones as needed.
46
+ 7. Bump `capability_version` only when clients must gate a feature on the new
47
+ behavior. Do not bump it for documentation-only changes.
48
+ 8. Run the contract parity test.
49
+
50
+ ## Versioning
51
+
52
+ `info.version` in `openapi.yaml` is the contract version and must match the
53
+ top `CHANGELOG.md` heading. Use:
54
+
55
+ - **MAJOR** for a breaking wire or schema change;
56
+ - **MINOR** for a backward-compatible addition;
57
+ - **PATCH** for documentation, descriptions, or other clarifications that do
58
+ not change the wire contract.
59
+
60
+ `info.x-server-version` records the server package version used when the
61
+ document was generated. It is informational and is not the contract version.
62
+
63
+ `capability_version` is separate from the contract version. It is the value
64
+ clients compare to decide whether the server supports a feature. Bump it only
65
+ when the client must change behavior, not for every contract edit.
66
+
67
+ ## Verification
68
+
69
+ Run the OpenAPI parity test:
70
+
71
+ ```bash
72
+ uv run pytest tests/unit/test_openapi.py -q
73
+ ```
74
+
75
+ For broader confidence, run the unit suite:
76
+
77
+ ```bash
78
+ uv run pytest tests/unit -q
79
+ ```
80
+
81
+ The parity test compares the generated `/openapi.json` against
82
+ `contracts/openapi.yaml` for security, error responses, and documented schemas.
@@ -0,0 +1,19 @@
1
+ # Contract Deviations and Ambiguities — API v11.0.2
2
+
3
+ ## D1 — Playback response is a discriminated `oneOf` union — RESOLVED (OUT OF SCOPE)
4
+
5
+ - Spec location: `contracts/openapi.yaml:505-512` (`POST /api/v1/playback/session` 201 response), schemas at `contracts/openapi.yaml:1312-1329` (`DirectPlaybackResponse`) and `contracts/openapi.yaml:1451-1472` (`HlsPlaybackResponse`).
6
+ - Problem: The 201 response is a `oneOf` with an explicit `mode` discriminator. This is valid OpenAPI and unambiguous on the wire, but it is not representable as one synthesized Swift `Codable` struct. A client must inspect `mode` before choosing the concrete shape.
7
+ - Evidence: `mode` is `const: direct` or `const: hls`, and the response mapping names both schemas. The client therefore decodes a private mode envelope and then decodes the matching public response model.
8
+ - Proposed spec change: None required for correctness. If generated-client ergonomics matter to the server team, publish one response object with `mode` plus optional mode-specific fields, or keep the union and treat the envelope as an expected client responsibility.
9
+ - Client impact: `Packages/OpenVideoKit/Sources/OpenVideoNetwork/OpenVideoAPIClient.swift:6` and `:214` handle the envelope and expose `PlaybackSession`. No server-side fix is needed for this item.
10
+ - Recommendation: OUT OF SCOPE
11
+ - Rationale: The server declares `PlaybackSessionResponse` as a Pydantic discriminated union over `DirectPlaybackResponse | HlsPlaybackResponse` with `Field(discriminator="mode")` (`openvideo_server/api/routes_playback.py:111-114`) and uses it as the 201 `response_model` (`:128-132`). The concrete models declare `Literal["direct"]` and `Literal["hls"]` (`:90-108`), matching the spec's `oneOf` plus discriminator at `contracts/openapi.yaml:505-512`. The limitation is Swift `Codable` synthesis, not a wire or spec mismatch.
12
+ - Proposed spec change: None; keep the discriminated union as-is.
13
+ - Impact: No server or contract change. Other clients already receive an unambiguous `mode`-tagged payload. Flattening the response would be a breaking wire change with no server benefit.
14
+ - Default: Leave D1 OPEN with no code or spec change.
15
+ - Resolution: OUT OF SCOPE (2026-12-04). Closed with no server or spec change; the client handles the valid discriminated union.
16
+
17
+ ## No other open deviations
18
+
19
+ D2 (`BrowseListing.limit` nullable) was resolved by contract v11.0.2 and removed. No additional undocumented endpoint, field, enum, request body, response schema, or status code is used by the client. Closed enums fail decoding, open capability strings remain strings, and error responses use the single documented envelope.