Skip to content

HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.

feat(media): a picture the person already has can be put into a video

richard-epsilla673c03d8db11
diff --git a/gateway/app.py b/gateway/app.py
index d2b31deb..c63ce5be 100644
--- a/gateway/app.py
+++ b/gateway/app.py
@@ -10265,6 +10265,44 @@ async def post_media_export(hid: str, eid: str, sid: str, request: Request) -> d
"total_seconds": job.get("planned_seconds"), "status": job["status"]}
[email protected]("/v1/harnesses/{hid}/servers/{eid}/sessions/{sid}/media")
+async def post_media_import(hid: str, eid: str, sid: str, request: Request) -> dict:
+ """Put a picture the person already has into this video, as media the agent can work from.
+
+ EVERYTHING ELSE IN A SESSION ARRIVED BY BEING RENDERED, which meant a reference image — the
+ frame a template starts from, a photograph of the actual product — had nowhere to live. It
+ could be shown in the app and never used, which is decoration, or not offered at all.
+
+ It goes through the same door a render does: `_media_store` verifies the bytes really are
+ what they claim before anything is kept, so an import cannot put a file into a timeline that
+ the exporter will later refuse. The kind is read from the bytes, not from what the caller
+ says they sent.
+ """
+ org, entry, _sv = await _media_route(hid, sid, eid, request)
+ data = await request.body()
+ if not data:
+ raise uhp_error(400, "empty_upload", "There were no bytes in that upload.")
+ if len(data) > media_plane.MAX_BYTES:
+ raise uhp_error(413, "too_large",
+ f"That file is {len(data)} bytes and the limit here is "
+ f"{media_plane.MAX_BYTES}.")
+ mime, _ext = media_plane.sniff(data)
+ kind = {"image": "image", "video": "video", "audio": "audio"}.get(
+ str(mime or "").split("/")[0] or "", "")
+ if not kind:
+ raise uhp_error(415, "not_media",
+ "That file is not a picture, a clip or a sound this can read.")
+ try:
+ rec = await _media_store(sid, kind, data, {
+ "model": "", "capability": "import", "job_id": "",
+ "prompt": (request.headers.get("x-media-label") or "")[:200]})
+ except media_plane.MediaError as e:
+ raise uhp_error(400, "import_refused", str(e)) from e
+ return {"media_id": rec["media_id"], "kind": rec["kind"], "mime": rec["mime"],
+ "bytes": rec["bytes"], "width": rec["width"], "height": rec["height"],
+ "seconds": rec["seconds"]}
+
+
@app.get("/v1/harnesses/{hid}/servers/{eid}/sessions/{sid}/media/{med}")
async def get_media_bytes(hid: str, eid: str, sid: str, med: str, request: Request) -> Response:
"""The bytes, with Range support.
diff --git a/gateway/media_plane.py b/gateway/media_plane.py
index f7f5957f..6041a746 100644
--- a/gateway/media_plane.py
+++ b/gateway/media_plane.py
@@ -1458,9 +1458,12 @@ def verify(kind: str, data: bytes) -> dict:
if not mime.startswith(want + "/"):
raise MediaEmpty(f"the provider returned {mime} where a {want} was expected")
out = {"mime": mime, "ext": ext, "bytes": len(data), "width": 0, "height": 0, "seconds": 0.0}
- if want in ("video", "audio"):
+ if want in ("video", "audio", "image"):
+ # A PICTURE HAS A SIZE AND IT IS MEASURABLE, so it is measured — an imported reference
+ # used to report 0x0, which is a number nobody can act on standing in for one anybody
+ # could have read off the file.
probed = probe(data, ext)
- if not probed.get("seconds"):
+ if want != "image" and not probed.get("seconds"):
# A file whose duration cannot be read cannot be cut, timed or summed. Refusing is the
# honest answer; a zero-length shot in a timeline is not.
#
diff --git a/gateway/tests/test_media_mcp.py b/gateway/tests/test_media_mcp.py
index 6be0a476..38e48ba1 100644
--- a/gateway/tests/test_media_mcp.py
+++ b/gateway/tests/test_media_mcp.py
@@ -3186,3 +3186,40 @@ def test_streamed_audio_deltas_are_decoded_one_by_one_and_joined_as_bytes():
got = media_plane._read_stream_audio({"format": "wav"}, frames)
assert got.data == want, (len(got.data), len(want))
assert got.transcript == "one two three"
+
+
+@needs_ffmpeg
+def test_a_picture_can_be_imported_and_then_animated_from(api, client, harness, session,
+ provider):
+ """A reference image the person already has becomes media the agent can render FROM.
+
+ Everything else in a session arrived by being rendered, so a template's reference frame had
+ nowhere to live: shown in the app and unusable, or not offered. The import goes through the
+ same verification a render does — and what comes back is a media id like any other, which is
+ the whole point: `from_image` takes it without knowing where it came from.
+ """
+ tok = _cred(harness, session)
+ png = _still("png")
+ base = f"/v1/harnesses/{harness}/servers/{ENTRY_ID}/sessions/{session}/media"
+ r = api.post(base, content=png, headers={"x-media-label": "Reference"})
+ assert r.status_code == 200, r.text
+ rec = r.json()
+ assert rec["kind"] == "image" and rec["media_id"].startswith("med_"), rec
+ assert rec["width"] and rec["height"], rec
+
+ # It reads back through the ordinary media route, byte for byte.
+ got = api.get(f"{base}/{rec['media_id']}")
+ assert got.status_code == 200 and got.content == png
+
+ # And it is a legal input to a render, exactly like a generated still.
+ out = _ok(_call(client, tok, "generate_video",
+ {"prompt": "animate this", "seconds": 6, "from_image": rec["media_id"]}))
+ assert out.get("job_id"), out
+
+
+def test_an_import_that_is_not_media_is_refused_rather_than_stored(api, harness, session):
+ """The kind is read from the bytes, never from what the caller claims to be sending."""
+ base = f"/v1/harnesses/{harness}/servers/{ENTRY_ID}/sessions/{session}/media"
+ r = api.post(base, content=b"this is not a picture")
+ assert r.status_code == 415, r.text
+ assert api.post(base, content=b"").status_code == 400