jessyoungyu on X: when a masking rule hits, send the request to a self-hosted model instead, so a prompt like 「百度这家公司怎么样」 gets an answer about Baidu, not about a placeholder. Settings › Privacy › Instead of masking, send to (settings redactRouteTo). It is Off by default, and nothing changes for a user who leaves it Off. It is picked in the app menu, and only models whose every route is unmasked can be chosen: the provider is set to Send requests unmasked, it is on this computer or the network, it has no account, and any fallback or group member is unmasked too (gateway.MaskRoute, the same rule as provider.SkipsRedaction). The setting is saved on its own with POST /api/settings/redact-route, which checks it with MaskRoute. The general settings save keeps the value. Decisions: - When a value would actually be masked on an agent's turn (maskHits.n > 0), serve sends the request to the chosen model unmasked. Warn-only hits don't count, and Block still answers 400. - If that model fails, the request fails. It is never masked and re-sent to the model the agent asked for, and never goes to a cloud model with the unmasked text. Falling back to a masked cloud request would answer a different question in the background. The user picked this route because masking breaks the answer. - Streaming works the same as on any route. - The route is checked again on every request. A model that is gone or no longer unmasked, or that the caller's gateway key may not use, means the request is masked as before. - Covered: agents' Messages, Chat, Responses and Gemini turns (serve, marked by serveAgent), count_tokens, Codex magpie-model turns, and Codex own-sign-in /responses (codexMaskRoute). - Not covered: magpie's own asks (ownAsk clears the mark), embeddings, audio, images and video. These stay masked. GUI: redactRouteRow lives in plugins/redact/settings.js and wraps renderRedact, so app.js is byte-for-byte unchanged and the core budget is not raised. Strings are added in zh, zh-TW, ja and de. Docs: gateway-routing.md, gui-shell.md, and site/public/docs masking (en, zh, ja). Tests: internal/gateway/mask_route_test.go (TestMaskedRequestGoesToTheModelSet: unset, set, streamed, nothing to mask, local fails, falls back to a vendor, no longer unmasked, count_tokens; TestCodexSigninTurnGoesToTheModelSet; TestMaskRouteTakesOnlyUnmaskedRoutes; TestMaskRouteOnlyForTheAgentsTurn); internal/gui/redact_route_test.go; settings_keep_test.go; internal/gui/tests/redact-route.test.cjs (every language, chromium and webkit, 1100 and 640 wide). Broken by hand, each red: - serveAgent without the agent mark; - MaskRoute taking any route (TestMaskedRequestGoesToTheModelSet, TestMaskRouteTakesOnlyUnmaskedRoutes; at the pushed head); - the codex hook removed; - count_tokens without the mark; - ownAsk not clearing it; - no key check; - no reroute in serve; - the GUI: no keep in the general save, no MaskRoute check on save, and the picker listing every model; - the plugin script left out of index.html (redact-route.test.cjs 22 of 24 red; at the pushed head). Run on mote: - at 221ede767's tree, this change onf5806ed21(pushed on44d697993, which adds only app.css lines and a Gateway page GUI test): go test -tags nogui ./internal/gui ./internal/settings ok (the core budget is green again since ec789445d; #4307, filed and closed); the mask-route tests in ./internal/gateway ok; GOOS=linux go vet -tags nogui ./internal/gui ./internal/gateway ok; GUI: node --test of redact-route, redact-*, privacy-*, mask-*, masking-*, settings-*, i18n-keys, account-discovery, sessions-reads and gui-de/ja/zh-tw: 643 pass, 0 fail. gofmt -l clean. - at the same change onaf8f3a939, one rebase back (the only difference is index.html's script order and main's own commits): go test -timeout 45m ./internal/gateway (488s) ./internal/redact ./internal/settings ./internal/provider ok; GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./..., go vet ./... ok. The whole Go suite was not run; every package this change touches was run above. Not tried: a real self-hosted model (Ollama) with a real agent. The local model is a fake Chat server in the tests.
48 lines
2.6 KiB
JavaScript
48 lines
2.6 KiB
JavaScript
// Settings › Privacy's Instead of masking, send to (the redact plugin's part
|
||
// of Settings). Run after app.js, whose helpers it shares (el, icon,
|
||
// openPicker, modelOpt, prefWrite, api), and before start.js draws
|
||
// Settings. It wraps renderRedact, so app.js carries none of it: the row
|
||
// shows while anything is masked, after the masked-words rows.
|
||
|
||
// redactRouteRow: where a request masking would change goes instead
|
||
// (redactRouteTo, jessyoungyu on X): Off masks it as before; a model whose
|
||
// provider the user set to Send requests unmasked (maskRouteModels, on
|
||
// this computer or the network) gets it as written, so 「百度这家公司怎么样」
|
||
// is answered about Baidu, not a placeholder. Picked in the app's menu,
|
||
// saved on its own (settings/redact-route).
|
||
function redactRouteRow(s) {
|
||
const models = s.maskRouteModels || [];
|
||
const v = s.redactRouteTo || "";
|
||
const b = el("button", "rt-cond on");
|
||
b.type = "button";
|
||
b.setAttribute("aria-label", t("Model for requests masking would change"));
|
||
const m = models.find((x) => x.id === v);
|
||
if (v) b.append(icon(m?.icon || "generic"), el("span", "", m ? `${m.name || m.id} · ${m.providerName}` : v));
|
||
else b.append(el("span", "", t("Off")));
|
||
b.disabled = !models.length && !v;
|
||
b.onclick = (ev) => openPicker({ id: "", name: "", fields: [] }, { key: "redactRouteTo", label: "model", value: v, options: [
|
||
{ value: "", label: t("Off"), note: t("Masked and sent to the model asked for, as before"), icon: "generic", reset: true },
|
||
...models.map(modelOpt)],
|
||
onPick: (id) => {
|
||
if (id === v) return;
|
||
prefWrite(api("settings/redact-route", { model: id }));
|
||
} }, b, ev);
|
||
const sub = models.length || v
|
||
? t("A request masking would change goes as written to this model, which you set to take requests unmasked, so it answers about the real names. If it fails, the request fails: it is never masked and sent elsewhere")
|
||
: t("Only a model you set to take requests unmasked can be picked: in the editor of a provider on this computer or your network, turn on Send requests unmasked");
|
||
const r = el("div", "row pref"), who = el("div", "who"), val = el("div", "val");
|
||
who.append(el("div", "name", t("Instead of masking, send to")), el("div", "sub", sub));
|
||
val.append(b);
|
||
r.append(who, val);
|
||
r.id = "redactRouteRow";
|
||
const after = $("#redactWordsWholeRow");
|
||
if (after) after.after(r); else $("#redactList").append(r);
|
||
}
|
||
{
|
||
const draw = renderRedact;
|
||
renderRedact = function (s, keep) {
|
||
draw(s, keep);
|
||
if (s.redact || s.redactPersonal || (s.redactWords || []).length) redactRouteRow(s);
|
||
};
|
||
}
|