friend-assistant 0.1.72 → 0.1.73
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/dist/BUILD.json +2 -2
- package/dist/friend.mjs +38 -7
- package/package.json +1 -1
package/dist/BUILD.json
CHANGED
package/dist/friend.mjs
CHANGED
|
@@ -8724,15 +8724,24 @@ var LockoutError = class extends Error {
|
|
|
8724
8724
|
}
|
|
8725
8725
|
retryAfterMs;
|
|
8726
8726
|
};
|
|
8727
|
+
var FORGET_AFTER_MS = 24 * 3600 * 1e3;
|
|
8727
8728
|
var RateLimiter = class {
|
|
8728
|
-
constructor(clock2, maxFails = 5, baseLockMs = 6e4) {
|
|
8729
|
+
constructor(clock2, maxFails = 5, baseLockMs = 6e4, store2) {
|
|
8729
8730
|
this.clock = clock2;
|
|
8730
8731
|
this.maxFails = maxFails;
|
|
8731
8732
|
this.baseLockMs = baseLockMs;
|
|
8733
|
+
this.store = store2;
|
|
8734
|
+
if (!store2) return;
|
|
8735
|
+
const now = clock2();
|
|
8736
|
+
for (const r of store2.load()) {
|
|
8737
|
+
if (now - r.updatedAt > FORGET_AFTER_MS) store2.remove(r.key);
|
|
8738
|
+
else this.entries.set(r.key, { fails: r.fails, lockedUntil: r.lockedUntil, updatedAt: r.updatedAt });
|
|
8739
|
+
}
|
|
8732
8740
|
}
|
|
8733
8741
|
clock;
|
|
8734
8742
|
maxFails;
|
|
8735
8743
|
baseLockMs;
|
|
8744
|
+
store;
|
|
8736
8745
|
entries = /* @__PURE__ */ new Map();
|
|
8737
8746
|
check(key2) {
|
|
8738
8747
|
const e = this.entries.get(key2);
|
|
@@ -8746,7 +8755,9 @@ var RateLimiter = class {
|
|
|
8746
8755
|
const over = e.fails - this.maxFails;
|
|
8747
8756
|
e.lockedUntil = this.clock() + Math.min(this.baseLockMs * 2 ** over, 36e5);
|
|
8748
8757
|
}
|
|
8758
|
+
e.updatedAt = this.clock();
|
|
8749
8759
|
this.entries.set(key2, e);
|
|
8760
|
+
this.store?.save(key2, { fails: e.fails, lockedUntil: e.lockedUntil, updatedAt: e.updatedAt });
|
|
8750
8761
|
}
|
|
8751
8762
|
/** Wrong tries left before the next lock. Once locked before, one wrong try is enough to lock again, for longer. */
|
|
8752
8763
|
triesLeft(key2) {
|
|
@@ -8761,6 +8772,7 @@ var RateLimiter = class {
|
|
|
8761
8772
|
}
|
|
8762
8773
|
reset(key2) {
|
|
8763
8774
|
this.entries.delete(key2);
|
|
8775
|
+
this.store?.remove(key2);
|
|
8764
8776
|
}
|
|
8765
8777
|
};
|
|
8766
8778
|
|
|
@@ -8768,6 +8780,20 @@ var RateLimiter = class {
|
|
|
8768
8780
|
var SESSION_TTL_MS = 7 * 24 * 3600 * 1e3;
|
|
8769
8781
|
var LOGIN_TRIES = 3;
|
|
8770
8782
|
var PAIR_TTL_MS = 5 * 60 * 1e3;
|
|
8783
|
+
function lockoutStore(db, scope) {
|
|
8784
|
+
const upsert = db.prepare("insert or replace into lockouts (scope, key, fails, locked_until, updated_at) values (?, ?, ?, ?, ?)");
|
|
8785
|
+
const del = db.prepare("delete from lockouts where scope = ? and key = ?");
|
|
8786
|
+
return {
|
|
8787
|
+
load: () => db.prepare("select key, fails, locked_until, updated_at from lockouts where scope = ?").all(scope).map((r) => ({
|
|
8788
|
+
key: r.key,
|
|
8789
|
+
fails: r.fails,
|
|
8790
|
+
lockedUntil: r.locked_until,
|
|
8791
|
+
updatedAt: r.updated_at
|
|
8792
|
+
})),
|
|
8793
|
+
save: (key2, e) => void upsert.run(scope, key2, e.fails, e.lockedUntil, e.updatedAt),
|
|
8794
|
+
remove: (key2) => void del.run(scope, key2)
|
|
8795
|
+
};
|
|
8796
|
+
}
|
|
8771
8797
|
var sha256 = (s) => createHash6("sha256").update(s).digest("hex");
|
|
8772
8798
|
var SCRYPT_N = 131072;
|
|
8773
8799
|
var LEGACY_N = 16384;
|
|
@@ -8805,8 +8831,9 @@ var Auth = class _Auth {
|
|
|
8805
8831
|
this.db = db;
|
|
8806
8832
|
this.audit = audit;
|
|
8807
8833
|
this.clock = clock2;
|
|
8808
|
-
|
|
8809
|
-
this.
|
|
8834
|
+
db.exec("create table if not exists lockouts (scope text not null, key text not null, fails integer not null, locked_until integer not null, updated_at integer not null, primary key (scope, key))");
|
|
8835
|
+
this.limiter = new RateLimiter(clock2, LOGIN_TRIES, 6e4, lockoutStore(db, "address"));
|
|
8836
|
+
this.accountLimiter = new RateLimiter(clock2, 20, 6e4, lockoutStore(db, "account"));
|
|
8810
8837
|
}
|
|
8811
8838
|
db;
|
|
8812
8839
|
audit;
|
|
@@ -8814,6 +8841,10 @@ var Auth = class _Auth {
|
|
|
8814
8841
|
limiter;
|
|
8815
8842
|
/** Account-wide limits, so rotating source addresses does not multiply the guesses. */
|
|
8816
8843
|
accountLimiter;
|
|
8844
|
+
/** A limiter whose counts are kept in the database (for example the pairing codes), so a restart does not reset it. */
|
|
8845
|
+
persistentLimiter(scope, maxFails = 5) {
|
|
8846
|
+
return new RateLimiter(this.clock, maxFails, 6e4, lockoutStore(this.db, scope));
|
|
8847
|
+
}
|
|
8817
8848
|
/** Where a sign-in stands for this address: the wrong tries left, and how long it is locked. Safe to show the visitor. */
|
|
8818
8849
|
loginState(ip) {
|
|
8819
8850
|
const key2 = `login:${ip}`;
|
|
@@ -17026,7 +17057,7 @@ function createGateway(deps) {
|
|
|
17026
17057
|
return reply.code(400).send({ error: e.message });
|
|
17027
17058
|
}
|
|
17028
17059
|
});
|
|
17029
|
-
const pairLimiter =
|
|
17060
|
+
const pairLimiter = auth.persistentLimiter("pair");
|
|
17030
17061
|
app.post("/api/pair", async (req, reply) => {
|
|
17031
17062
|
const body = z14.object({ code: z14.string().min(1).max(64), name: z14.string().min(1).max(64) }).safeParse(req.body);
|
|
17032
17063
|
if (!body.success) return reply.code(400).send({ error: "Invalid input" });
|
|
@@ -20375,7 +20406,7 @@ function currentSelf() {
|
|
|
20375
20406
|
// ../server/src/system/npm.ts
|
|
20376
20407
|
import { spawn as spawn9 } from "node:child_process";
|
|
20377
20408
|
var PACKAGE = "friend-assistant";
|
|
20378
|
-
var runningVersion = () => true ? "0.1.
|
|
20409
|
+
var runningVersion = () => true ? "0.1.73" : "development";
|
|
20379
20410
|
async function npmLatest(fetchFn = fetch, timeoutMs = 1e4) {
|
|
20380
20411
|
try {
|
|
20381
20412
|
const res = await fetchFn(`https://registry.npmjs.org/${PACKAGE}/latest`, { headers: { accept: "application/json" }, signal: AbortSignal.timeout(timeoutMs) });
|
|
@@ -25664,7 +25695,7 @@ import { appendFileSync } from "node:fs";
|
|
|
25664
25695
|
import { join as join35 } from "node:path";
|
|
25665
25696
|
var PACKAGE2 = "friend-assistant";
|
|
25666
25697
|
var real2 = {
|
|
25667
|
-
current: () => true ? "0.1.
|
|
25698
|
+
current: () => true ? "0.1.73" : "development",
|
|
25668
25699
|
latest: () => new Promise((resolve13) => {
|
|
25669
25700
|
const child = crossSpawn5("npm", ["view", PACKAGE2, "version", "--prefer-online"], { stdio: ["ignore", "pipe", "ignore"] });
|
|
25670
25701
|
let out = "";
|
|
@@ -25982,7 +26013,7 @@ async function run(argv, io2) {
|
|
|
25982
26013
|
case "version":
|
|
25983
26014
|
case "--version":
|
|
25984
26015
|
case "-v":
|
|
25985
|
-
io2.out(true ? "0.1.
|
|
26016
|
+
io2.out(true ? "0.1.73" : "development");
|
|
25986
26017
|
return 0;
|
|
25987
26018
|
case "lan":
|
|
25988
26019
|
return await lanCommand(rest, io2);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "friend-assistant",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.73",
|
|
4
4
|
"description": "A self-hosted personal AI assistant for your own PC: a full-screen stage, voice, tools with your approval, and your Claude subscription or a local model.",
|
|
5
5
|
"keywords": ["ai", "assistant", "jarvis", "voice", "claude", "ollama", "mcp", "self-hosted"],
|
|
6
6
|
"license": "UNLICENSED",
|