The custom provider editor's Base URL has a fifth API, "Gemini compatible"
(Gemini 兼容 / Gemini 互換 / Gemini-kompatibel), beside OpenAI, Anthropic and
Responses; More endpoints has a Gemini URL; the CLI takes gemini=. A
Gemini URL is kept as its base (…/v1beta, a relay's path prefix kept, a
pasted models/…:generateContent cut off). Every client's request, Chat,
Messages, Responses or Gemini, streamed or not, goes upstream to
models/{model}:streamGenerateContent?alt=sse under it, with no model in
the body and the key in x-goog-api-key; models are listed from its
/models, a page at a time, keeping those that serve generateContent.
Detect doesn't ask a Gemini API and is hidden while it is picked.
Factory's Gemini route and Bearer token are unchanged.
With five APIs the pick no longer fits a 900px editor in English and
German, so it wraps to a second row, and its thumb now follows the
picked option onto that row.
Verified against fake httptest upstreams only; no real Gemini key or
relay was tried:
- TestCustomGeminiUpstream (gateway): chat, chat stream, messages, a
Gemini client's stream and non-stream, behind /proxy/v1beta. Fails with
"chat: 404" without the gateway.go change.
- TestCustomGeminiProvider, TestGeminiBase, TestFactoryGeminiUnchanged
(provider).
- go vet, HOME=$(mktemp -d) go test -tags nogui ./... (44 packages ok),
GOOS=linux and GOOS=windows go vet on the touched packages.
- provider-gemini.test.cjs (new, en/zh/ja/de, Chromium + WebKit, 8 pass;
fails with "900px: the thumb is 22px off" without the slide() fix),
and in both engines: provider-base-api, provider-detect,
provider-detect-models, provider-add-models, provider-output-picks,
provider-search, provider-url-each-api, seg-contrast, settings-groups,
menu-scroll, click-scroll, ledger-hscroll, strip-scrollbar,
view-scrollbar, usage-ledger-chart, system-one, gui-ja, gui-de,
gui-zh-tw: all pass.
34 lines
964 B
Go
34 lines
964 B
Go
package provider
|
|
|
|
import "net/url"
|
|
|
|
// SkipsRedaction says requests to p go unmasked: the user set Unredacted,
|
|
// and every address p has is on this machine or the local network. One
|
|
// edited to a vendor's afterwards is masked again. A signed-in account, a
|
|
// plugin's provider and another magpie are always masked: each reaches a
|
|
// vendor.
|
|
func (p Provider) SkipsRedaction() bool {
|
|
if !p.Unredacted || p.Account != nil || p.IsRemoteMagpie() {
|
|
return false
|
|
}
|
|
return LocalAddresses(p.Chat, p.Responses, p.Anthropic, p.Gemini, p.Decide)
|
|
}
|
|
|
|
// LocalAddresses says every non-empty base URL among bases is on this
|
|
// machine or the local network (localhost, *.local, a loopback or private
|
|
// IP), and there is at least one.
|
|
func LocalAddresses(bases ...string) bool {
|
|
n := 0
|
|
for _, b := range bases {
|
|
if b == "" {
|
|
continue
|
|
}
|
|
u, err := url.Parse(b)
|
|
if err != nil || u.Host == "" || !local(u.Hostname()) {
|
|
return false
|
|
}
|
|
n++
|
|
}
|
|
return n > 0
|
|
}
|