Files
magpie/docs
yetone 3ad5b93d41 provider: a Gemini model id with a slash keeps it in the request path (#6695)
A custom Gemini compatible provider's namespaced model id
(example/model-demo) was asked at /models/example%2Fmodel-demo, since
GeminiPath escaped the whole id. A relay that routes by literal path
segments answered 403 Invalid URL (POPOBE97 in #6695, LuoRuiyao on X).
GeminiModelPath now escapes each segment and keeps the slashes, so the
request goes to /models/example/model-demo:streamGenerateContent. An id
with an empty, . or .. segment, which a server could clean into a path
outside models/, still goes as one escaped segment. Google's own ids
(no slash) give the same bytes as before.

Siblings made to agree: Vertex AI's VertexPath, VertexWholePath, its
model test and the Claude rawPredict path (a slash id there goes to
partner chat completions, so only the pinned test changed), the
plugin Code Assist path in plugins.go and Gemini image generation in
draw.go, both of which put the id in raw before (a ? or space broke
the URL).

Run (on mote):
- red on the old code (old provider/gateway files, a shim for the new
  helper): TestGeminiModelPathKeepsSlashes FAIL
  `GeminiModelPath("example/model-demo") = "example%2Fmodel-demo"`;
  TestGeminiNamespacedModelKeepsItsSlash FAIL `status 403, asked
  [/v1beta/models/example%2Fmodel-demo:streamGenerateContent?alt=sse]`.
  Both pass with the change.
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./..., go build for darwin, linux (nogui), windows.
- go test -tags nogui -timeout 45m ./...: all 101 packages ok.

Not tried: a real relay that routes by namespaced id, or a real call to
Google's endpoint (its paths for slash-free ids are byte-identical, held
by the test).
2026-11-16 13:17:46 +08:00
..