From da8ffc090808d88a66942637528ee821650b6250 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Sun, 23 Aug 2026 02:48:12 +1000 Subject: [PATCH] feat(tools): add MultimodalResult.URLs for remote-hosted media MultimodalResult only modeled local bytes written under SubdirHint (Files). A tool whose media lives at a remote, already-hosted URL -- a generation API's result, for example -- had nowhere to put it. MediaRef{Type, URL} and the new URLs field give it one, reusing the existing envelope rather than forking a second convention for the same concept. --- internal/tools/multimodal.go | 15 +++++++++++++++ internal/tools/multimodal_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/internal/tools/multimodal.go b/internal/tools/multimodal.go index 15d3abb46..60670c4e7 100644 --- a/internal/tools/multimodal.go +++ b/internal/tools/multimodal.go @@ -22,4 +22,19 @@ type MultimodalResult struct { // Files lists the full paths written under SubdirHint, in the order // the source content blocks appeared. Files []string `json:"files,omitempty"` + // URLs lists media that lives at a remote, already-hosted URL rather + // than local bytes -- a generation API's result, for example, which + // has nowhere to go in Files: there is no SubdirHint to write it under + // because nothing was downloaded. + URLs []MediaRef `json:"urls,omitempty"` +} + +// MediaRef is one piece of remote-hosted media within a MultimodalResult. +type MediaRef struct { + // Type is "image", "video", "audio", or "document" -- the same + // vocabulary gateway.MediaAttachment.Type uses, so a caller can build + // one directly from this without translation. + Type string `json:"type"` + // URL is where the media is hosted. + URL string `json:"url"` } diff --git a/internal/tools/multimodal_test.go b/internal/tools/multimodal_test.go index 19e4109a5..c1c788091 100644 --- a/internal/tools/multimodal_test.go +++ b/internal/tools/multimodal_test.go @@ -47,4 +47,29 @@ func TestMultimodalResultOmitsEmptyOptionalFields(t *testing.T) { if _, ok := got["files"]; ok { t.Error("files should be omitted when empty") } + if _, ok := got["urls"]; ok { + t.Error("urls should be omitted when empty") + } +} + +// A tool whose media lives at a remote URL (a generation API's hosted +// result) rather than local bytes has nowhere to put it in Files, which is +// always a path under SubdirHint. URLs is that case. +func TestMultimodalResultURLsRoundTrip(t *testing.T) { + r := MultimodalResult{ + IsMultimodal: true, + Summary: "generated a video", + URLs: []MediaRef{{Type: "video", URL: "https://example.com/v.mp4"}}, + } + data, err := json.Marshal(r) + if err != nil { + t.Fatal(err) + } + var got MultimodalResult + if err := json.Unmarshal(data, &got); err != nil { + t.Fatal(err) + } + if len(got.URLs) != 1 || got.URLs[0].Type != "video" || got.URLs[0].URL != "https://example.com/v.mp4" { + t.Errorf("URLs round-trip = %+v, want [{video https://example.com/v.mp4}]", got.URLs) + } }