solrouter 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solrouter",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Local privacy router for coding tools: pseudonymises every request before it leaves your machine, and sends work a frontier model would refuse to an uncensored open-weight model you control.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/auth.js CHANGED
@@ -27,7 +27,7 @@ function openBrowser(url) {
27
27
 
28
28
  /** Loopback browser login. Resolves once the callback delivers a token.
29
29
  * `open` is injectable for testing (defaults to launching the real browser). */
30
- export function browserLogin({ timeoutMs = 180000, open = openBrowser } = {}) {
30
+ export function browserLogin({ timeoutMs = 180000, open = openBrowser, save = saveAuth } = {}) {
31
31
  return new Promise((resolve, reject) => {
32
32
  const state = randomBytes(16).toString("hex");
33
33
  const server = createServer((req, res) => {
@@ -45,7 +45,7 @@ export function browserLogin({ timeoutMs = 180000, open = openBrowser } = {}) {
45
45
  res.end("<h2>SolRouter proxy connected.</h2><p>You can close this tab and return to the terminal.</p>");
46
46
  server.close();
47
47
  if (!token.access_token) return reject(new Error("no token in callback"));
48
- saveAuth(token);
48
+ save(token);
49
49
  resolve(token);
50
50
  });
51
51
  server.listen(0, "127.0.0.1", () => {
package/src/index.js CHANGED
@@ -120,11 +120,11 @@ export async function handleStream(body, ctx = {}, cfg) {
120
120
  kind, mode, maskedPrompt: extractText(masked, kind) };
121
121
  }
122
122
 
123
- /** Call the private leg for a (masked) prompt. Returns { reply, ok }. */
123
+ /** Call the private leg for a (masked) prompt. Returns { reply, ok, status }. */
124
124
  export async function privateReply(cfg, maskedPrompt) {
125
125
  const { callSolrouterAgent } = await import("./providers.js");
126
126
  const r = await callSolrouterAgent(cfg.private, maskedPrompt);
127
- return { reply: r.reply || "", ok: r.ok };
127
+ return { reply: r.reply || "", ok: r.ok, status: r.status };
128
128
  }
129
129
 
130
130
  export { createMasker } from "./mask.js";
package/src/server.js CHANGED
@@ -102,7 +102,7 @@ export function startServer(cfg) {
102
102
  // stream live. If the whole short response is a refusal and mode is auto,
103
103
  // we discard it and reroute to the private/uncensored leg.
104
104
  const COMMIT_AT = 380; // chars of answer text that means "real answer"
105
- let committed = false, held = "", acc = "";
105
+ let committed = false, held = "", acc = "", refusalLikely = false;
106
106
  for (;;) {
107
107
  const { done, value } = await reader.read();
108
108
  if (done) break;
@@ -110,11 +110,14 @@ export function startServer(cfg) {
110
110
  acc += extractSseText(chunk);
111
111
  if (committed) { emit(chunk); continue; }
112
112
  held += chunk;
113
- if (acc.replace(/\s/g, "").length >= COMMIT_AT) { committed = true; emit(held); held = ""; }
113
+ // Lock onto a refusal as soon as its opening matches — then never commit,
114
+ // so even a long, multi-paragraph refusal gets fully buffered and rerouted.
115
+ if (!refusalLikely && isRefusal(acc)) refusalLikely = true;
116
+ if (!refusalLikely && acc.replace(/\s/g, "").length >= COMMIT_AT) { committed = true; emit(held); held = ""; }
114
117
  }
115
118
 
116
119
  let leg = s.leg, refused = false, model = s.model;
117
- if (!committed && s.mode === "auto" && isRefusal(acc)) {
120
+ if (!committed && s.mode === "auto" && refusalLikely) {
118
121
  // Streamed refusal → reroute to the uncensored private leg.
119
122
  const pr = await privateReply(cfg, s.maskedPrompt);
120
123
  if (pr.ok && pr.reply) {
@@ -126,7 +129,18 @@ export function startServer(cfg) {
126
129
  leg, reason: "reactive-refusal", model, entities: s.masker.entities(), refused: true, sentToProvider: s.sent });
127
130
  return;
128
131
  }
129
- // private leg unavailable → fall through and just relay the refusal
132
+ // Reroute was needed but the uncensored leg failed — say so LOUDLY instead
133
+ // of silently relaying Claude's refusal (this is almost always "not logged
134
+ // in" / an invalid SolRouter key).
135
+ res.write(synthAnthropicSse(
136
+ `⚠️ [solrouter] Claude refused this, and the uncensored leg couldn't be reached (${pr.status || "error"}). ` +
137
+ `Run \`solrouter login --token sk_solrouter_…\` with a valid key from solrouter.com/sdk, then retry.`,
138
+ cfg.private.model));
139
+ res.end();
140
+ if (cfg.receipt?.enabled) writeReceipt(cfg.receipt.path, {
141
+ leg: "private", reason: "reroute-failed", model: cfg.private.model,
142
+ entities: s.masker.entities(), refused: true, sentToProvider: s.sent });
143
+ return;
130
144
  }
131
145
  if (!committed) emit(held); // short non-refusal: flush the buffer
132
146
  if (restorer) res.write(restorer.flush());