The provider editor has a Redaction row, "Send requests unmasked", while
every address of the provider is on this computer or the local network
(localhost, *.local, a loopback or private IP): Ollama, LM Studio, a vLLM
box. Ticked (provider.Unredacted; CLI `magpie provider set <id>
unmasked=yes`), a request whose provider and fallbacks, or whose routing
group's models, all skip redaction (provider.SkipsRedaction) goes to them
as the agent wrote it; anything that may reach another provider stays
masked for all of them. An address edited to a vendor's masks it again; a
signed-in account, a plugin's provider and another magpie never skip. The
log and recent calls keep the masked body. count_tokens and embeddings
follow the same rule.
It is a per-provider choice, not automatic for local addresses, because
a local address isn't a local model: a relay run locally (new-api,
CLIProxyAPI) or Ollama's cloud models pass the request on to a vendor.
Verified: TestLocalUnredactedProviderGetsTheRequestWhole (set, unset,
fallback to a vendor, fallback to another local one, a group of it alone,
a group with a vendor; chat and count_tokens) and TestLocalUnredactedEmbeddings
fail without the gateway change ("sent whole false, want true: … my key is
{{API_KEY_…}}"; count_tokens alone: "counted whole false"); TestSkipsRedaction;
TestProviderSaveKeepsUnredacted fails without the preset save line.
provider-unmasked.test.cjs (Chromium+WebKit, en/zh, 900 and 440 wide) 32/32,
3 of 4 fail on the old app.js; gui-ja, gui-de, i18n-keys, provider-search
and the other provider editor suites pass. go test -race on gateway,
provider, redact, gui; -race -count=10 on the new tests; go vet,
GOOS=linux/windows builds. Real: a sandbox gateway in front of the local
Ollama (llama3 8B) through a logging proxy: unset, Ollama was sent
{{API_KEY_…}}; with unmasked=yes it was sent the key as written, and
answered both times.
34 lines
954 B
Go
34 lines
954 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.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
|
|
}
|