friend-assistant 0.1.106 → 0.1.107

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "friend-assistant",
3
- "version": "0.1.106",
4
- "builtAt": "2026-11-27T16:09:23.863Z"
3
+ "version": "0.1.107",
4
+ "builtAt": "2026-11-27T16:37:14.588Z"
5
5
  }
package/dist/friend.mjs CHANGED
@@ -4635,9 +4635,30 @@ function mentions(text5, names) {
4635
4635
  }
4636
4636
  return false;
4637
4637
  }
4638
- function isAddressed(line4, names, selfName) {
4638
+ function isAddressed(line4, names, selfName, fuzzy = false) {
4639
4639
  if (line4.speaker.trim().toLowerCase() === selfName.trim().toLowerCase()) return false;
4640
- return mentions(line4.text, names);
4640
+ return mentions(line4.text, names) || fuzzy && soundsLike(line4.text, names);
4641
+ }
4642
+ var within1 = (a, b) => {
4643
+ if (Math.abs(a.length - b.length) > 1) return false;
4644
+ let i = 0;
4645
+ while (i < a.length && i < b.length && a[i] === b[i]) i++;
4646
+ if (i === a.length && i === b.length) return true;
4647
+ const rest = (s, from) => s.slice(from);
4648
+ return rest(a, i + 1) === rest(b, i + 1) || rest(a, i + 1) === rest(b, i) || rest(a, i) === rest(b, i + 1);
4649
+ };
4650
+ function soundsLike(text5, names) {
4651
+ const words = text5.toLowerCase().match(/[\p{L}]+/gu) ?? [];
4652
+ for (const n2 of names) {
4653
+ const name = n2.trim().toLowerCase();
4654
+ if (name.length < 4 || /\s/.test(name)) continue;
4655
+ for (const w of words) {
4656
+ if (w.length < name.length) continue;
4657
+ if (within1(w, name)) return true;
4658
+ for (let i = 1; i + name.length <= w.length; i++) if (within1(w.slice(i, i + name.length), name)) return true;
4659
+ }
4660
+ }
4661
+ return false;
4641
4662
  }
4642
4663
  function concernsOwner(line4, ownerNames, keywords) {
4643
4664
  if (mentions(line4.speaker, ownerNames)) return false;
@@ -24748,6 +24769,8 @@ var MeetingSession = class {
24748
24769
  lastChat = 0;
24749
24770
  cool = new Cooldown(6e4);
24750
24771
  pending = null;
24772
+ /** For a little while after it was called or answered, the next thing said is most likely meant for it too, whether or not it says its name again. */
24773
+ conversationUntil = 0;
24751
24774
  linesSinceNotes = 0;
24752
24775
  lastNotes;
24753
24776
  done = null;
@@ -24755,6 +24778,8 @@ var MeetingSession = class {
24755
24778
  audioMode = false;
24756
24779
  lastHeard = 0;
24757
24780
  lastSpoke = 0;
24781
+ /** Sound that arrives while it speaks (and just after) is its own voice coming back through someone's speakers: not listened to. */
24782
+ deafUntil = 0;
24758
24783
  now = () => (this.d.now ?? Date.now)();
24759
24784
  sleep = (ms2) => (this.d.sleep ?? ((n2) => new Promise((r) => setTimeout(r, n2))))(ms2);
24760
24785
  start() {
@@ -24788,14 +24813,18 @@ var MeetingSession = class {
24788
24813
  if (!d.speech || !d.page.speak || !d.page.mic) return { ok: false, message: "Speaking aloud is not switched on here." };
24789
24814
  if (this.now() - this.lastSpoke < 2e4) return { ok: false, message: "It spoke a moment ago: wait twenty seconds between spoken answers." };
24790
24815
  this.lastSpoke = this.now();
24791
- for (let w = 0; this.now() - this.lastHeard < 1500 && w < 20; w++) await this.sleep(400);
24816
+ const quietFor = () => d.hearing && this.audioMode ? Date.now() - d.hearing.lastVoiceAt : this.now() - this.lastHeard;
24817
+ for (let w = 0; quietFor() < (this.audioMode ? 500 : 1500) && w < 40; w++) await this.sleep(150);
24792
24818
  const wav = await d.speech(text5.slice(0, 400)).catch(() => null);
24793
24819
  if (!wav) return { ok: false, message: "This PC has no voice to speak with." };
24794
24820
  if (!await d.page.mic(true).catch(() => false)) return { ok: false, message: "It could not switch the microphone on in the meeting." };
24795
24821
  let ok4 = false;
24822
+ this.deafUntil = Number.MAX_SAFE_INTEGER;
24796
24823
  try {
24797
24824
  ok4 = await d.page.speak(wav).catch(() => false);
24798
24825
  } finally {
24826
+ this.deafUntil = this.now() + 3e3;
24827
+ this.conversationUntil = this.now() + 45e3;
24799
24828
  await d.page.mic(false).catch(() => false);
24800
24829
  }
24801
24830
  return ok4 ? { ok: true, message: "Said aloud." } : { ok: false, message: "It could not play the sound into the meeting." };
@@ -24852,7 +24881,7 @@ var MeetingSession = class {
24852
24881
  this.set("failed", reason);
24853
24882
  return void await d.page.close();
24854
24883
  }
24855
- await this.sleep(poll);
24884
+ await this.sleep(this.audioMode ? Math.min(poll, 300) : poll);
24856
24885
  }
24857
24886
  if (this.stopped) reason = this.stopped;
24858
24887
  } finally {
@@ -24907,7 +24936,7 @@ var MeetingSession = class {
24907
24936
  d.events.problem("Live captions are off in this meeting, so it is listening to the sound instead. It cannot tell who is speaking.");
24908
24937
  }
24909
24938
  const pcm = await d.page.audio?.().catch(() => null);
24910
- if (pcm) d.hearing?.push(pcm);
24939
+ if (pcm && this.now() >= this.deafUntil) d.hearing?.push(pcm);
24911
24940
  const lines = d.hearing?.take() ?? [];
24912
24941
  if (lines.length) this.take(lines);
24913
24942
  }
@@ -24923,21 +24952,28 @@ var MeetingSession = class {
24923
24952
  this.linesSinceNotes += lines.length;
24924
24953
  d.events.lines(lines);
24925
24954
  for (const l of lines) {
24926
- if (isAddressed(l, d.names(), d.selfName)) {
24927
- const due = this.now() + (d.replyDelayMs ?? 1500);
24928
- this.pending = this.pending && this.pending.line.speaker === l.speaker ? { line: l, due: Math.min(due, this.pending.limit), limit: this.pending.limit } : { line: l, due, limit: this.now() + 8e3 };
24955
+ const byName = isAddressed(l, d.names(), d.selfName, this.audioMode);
24956
+ const follow = !byName && this.now() < this.conversationUntil && l.speaker.trim().toLowerCase() !== d.selfName.trim().toLowerCase() && l.text.trim().split(/\s+/).length >= 3;
24957
+ if (byName || follow) {
24958
+ if (byName) this.conversationUntil = this.now() + 45e3;
24959
+ const due = this.now() + this.replyDelay();
24960
+ this.pending = this.pending && this.pending.line.speaker === l.speaker ? { line: l, due: Math.min(due, this.pending.limit), limit: this.pending.limit, ...follow && this.pending.follow ? { follow } : {} } : { line: l, due, limit: this.now() + 8e3, ...follow ? { follow } : {} };
24929
24961
  } else if (this.pending && this.pending.line.speaker === l.speaker) {
24930
- this.pending = { ...this.pending, due: Math.min(this.now() + (d.replyDelayMs ?? 1500), this.pending.limit) };
24962
+ this.pending = { ...this.pending, due: Math.min(this.now() + this.replyDelay(), this.pending.limit) };
24931
24963
  } else if (concernsOwner(l, prefs.ownerNames, prefs.keywords) && this.cool.take("owner", this.now())) {
24932
24964
  d.events.ownerRelevant(l, this.transcript());
24933
24965
  }
24934
24966
  }
24935
24967
  }
24968
+ /** How long it waits after someone stops before it answers: captions arrive a while after the speech, sound is cut at the pause already. */
24969
+ replyDelay() {
24970
+ return this.d.replyDelayMs ?? (this.audioMode ? 300 : 1500);
24971
+ }
24936
24972
  tick() {
24937
24973
  const p = this.pending;
24938
24974
  if (p && this.now() >= p.due) {
24939
24975
  this.pending = null;
24940
- this.d.events.addressed(p.line, this.transcript());
24976
+ this.d.events.addressed(p.line, this.transcript(), p.follow);
24941
24977
  }
24942
24978
  const every = this.d.prefs().notesEveryMinutes * 6e4;
24943
24979
  if (this.linesSinceNotes >= 4 && this.now() - this.lastNotes >= every) {
@@ -25075,9 +25111,11 @@ var MeetingService = class {
25075
25111
  if (s === "failed") this.d.tellOwner(`I could not stay in the meeting${m.title ? ` "${m.title}"` : ""}: ${detail}`, "Meeting");
25076
25112
  },
25077
25113
  lines: (lines) => this.d.store.addLines(id3, lines, this.now()),
25078
- addressed: (line4, ctx) => void this.turn(id3, "reply", `${line4.speaker} called you by name just now: "${line4.text}".
25114
+ addressed: (line4, ctx, followUp) => void this.turn(id3, "reply", `${followUp ? `You were talking with the people here a moment ago, and ${line4.speaker} just said: "${line4.text}". It did not use your name, so first decide whether it is meant for you (a follow-up to what you said, or a question to you). If it is clearly people talking among themselves or about something else, do nothing at all and write nothing.
25079
25115
 
25080
- If you can answer in a sentence or two from what you know, ${prefs().speak ? "say it aloud with meeting.speak (one or two short spoken sentences, no lists, in the language they used; the chat is the fallback)" : "write it with meeting.chat (short, polite, in the language they used)"}. If it needs the owner or you are not sure, write in the chat that you will check with them, and use meeting.tell_owner with the question. Do not promise anything for the owner and do not reveal anything private.`, ctx),
25116
+ If it is for you and you can answer` : `${line4.speaker} called you by name just now: "${line4.text}".
25117
+
25118
+ If you can answer`} in a sentence or two from what you know, ${prefs().speak ? "say it aloud with meeting.speak (one or two short spoken sentences, no lists, in the language they used; the chat is the fallback)" : "write it with meeting.chat (short, polite, in the language they used)"}. If it needs the owner or you are not sure, write in the chat that you will check with them, and use meeting.tell_owner with the question. Do not promise anything for the owner and do not reveal anything private.`, ctx),
25081
25119
  ownerRelevant: (line4, ctx) => void this.turn(id3, "suggest", `Something was said that may concern the owner (${line4.speaker}: "${line4.text}"). Use meeting.tell_owner with one or two short sentences: what was said, and a suggested answer if they are asked something. Do not write in the meeting chat.`, ctx),
25082
25120
  notesDue: () => void this.notes(id3, "notes"),
25083
25121
  problem: (text5) => this.d.tellOwner(text5, "Meeting"),
@@ -25253,7 +25291,10 @@ var rms = (pcm, from, to) => {
25253
25291
  function cleanTranscript(raw) {
25254
25292
  const t = raw.replace(/\[[^\]]*\]|\([^)]*\)|\*[^*]*\*|[♪♫]+/g, " ").replace(/\s+/g, " ").trim();
25255
25293
  if (!/[\p{L}\p{N}]/u.test(t)) return "";
25256
- if (/^(thanks for watching|thank you for watching|please subscribe|you|bye)[.!]?$/i.test(t)) return "";
25294
+ if (/^(thanks for watching|thank you for watching|please subscribe|you|bye|thank you|thanks|you'?re welcome|okay|ok)[.!]?$/i.test(t)) return "";
25295
+ if (/(for watching|like,? (share|comment)|subscribe|subtitles by|amara\.org|see you (in the )?next)/i.test(t)) return "";
25296
+ const words = t.toLowerCase().match(/[\p{L}\p{N}']+/gu) ?? [];
25297
+ if (words.length >= 4 && new Set(words).size <= Math.ceil(words.length / 4)) return "";
25257
25298
  return t;
25258
25299
  }
25259
25300
  var AudioHearing = class {
@@ -25263,10 +25304,18 @@ var AudioHearing = class {
25263
25304
  ready = [];
25264
25305
  o;
25265
25306
  constructor(o) {
25266
- this.o = { speaker: "Someone", silence: 0.012, minSeconds: 4, maxSeconds: 14, ...o };
25307
+ this.o = { speaker: "Someone", silence: 0.012, minSeconds: 1.2, maxSeconds: 10, ...o };
25267
25308
  }
25309
+ /** When someone was last heard talking (milliseconds, Date.now): it never starts to speak over them. */
25310
+ lastVoiceAt = 0;
25311
+ floor = 4e-3;
25268
25312
  push(pcm) {
25269
25313
  if (!pcm.length) return;
25314
+ for (let i = 0; i + FRAME * 2 <= pcm.length; i += FRAME * 2) {
25315
+ const e = rms(pcm, i, i + FRAME * 2);
25316
+ this.floor = e < this.floor ? e * 0.5 + this.floor * 0.5 : this.floor * 0.995 + e * 5e-3;
25317
+ if (e >= Math.max(this.o.silence, this.floor * 3)) this.lastVoiceAt = Date.now();
25318
+ }
25270
25319
  this.buf = Buffer.concat([this.buf, pcm]);
25271
25320
  const seconds2 = this.buf.length / 2 / RATE;
25272
25321
  if (seconds2 < this.o.minSeconds) return;
@@ -25287,13 +25336,12 @@ var AudioHearing = class {
25287
25336
  cut() {
25288
25337
  const chunk = this.buf;
25289
25338
  this.buf = Buffer.alloc(0);
25290
- let voiced = 0;
25291
- let frames = 0;
25292
- for (let i = 0; i + FRAME * 2 <= chunk.length; i += FRAME * 2) {
25293
- frames++;
25294
- if (rms(chunk, i, i + FRAME * 2) >= this.o.silence) voiced++;
25295
- }
25296
- if (frames < 8 || voiced / frames < 0.12) return;
25339
+ const energy = [];
25340
+ for (let i = 0; i + FRAME * 2 <= chunk.length; i += FRAME * 2) energy.push(rms(chunk, i, i + FRAME * 2));
25341
+ if (energy.length < 8) return;
25342
+ const bar = Math.max(this.o.silence, this.floor * 3);
25343
+ const voiced = energy.filter((e) => e >= bar).length;
25344
+ if (voiced / energy.length < 0.12) return;
25297
25345
  this.queue.push(chunk);
25298
25346
  if (this.queue.length > 3) this.queue.shift();
25299
25347
  void this.work();
@@ -25303,8 +25351,9 @@ var AudioHearing = class {
25303
25351
  this.busy = true;
25304
25352
  try {
25305
25353
  for (let c = this.queue.shift(); c; c = this.queue.shift()) {
25306
- const text5 = cleanTranscript(await this.o.transcribe(c).catch(() => ""));
25307
- if (text5) this.ready.push({ speaker: this.o.speaker, text: text5 });
25354
+ const heard = await this.o.transcribe(c).catch(() => "");
25355
+ const text5 = cleanTranscript(typeof heard === "string" ? heard : heard.text);
25356
+ if (text5) this.ready.push({ speaker: typeof heard === "object" && heard.speaker || this.o.speaker, text: text5 });
25308
25357
  }
25309
25358
  } finally {
25310
25359
  this.busy = false;
@@ -29407,7 +29456,7 @@ function currentSelf() {
29407
29456
  // ../server/src/system/npm.ts
29408
29457
  import { spawn as spawn11 } from "node:child_process";
29409
29458
  var PACKAGE = "friend-assistant";
29410
- var runningVersion = () => true ? "0.1.106" : "development";
29459
+ var runningVersion = () => true ? "0.1.107" : "development";
29411
29460
  async function npmLatest(fetchFn = fetch, timeoutMs = 1e4) {
29412
29461
  try {
29413
29462
  const res = await fetchFn(`https://registry.npmjs.org/${PACKAGE}/latest`, { headers: { accept: "application/json" }, signal: AbortSignal.timeout(timeoutMs) });
@@ -31033,7 +31082,19 @@ First check the work: read the whole report (office.report) and, when it changed
31033
31082
  if (opts.meetingVoice?.hearing) return opts.meetingVoice.hearing();
31034
31083
  const v = opts.voice;
31035
31084
  if (!v?.available()) return null;
31036
- return new AudioHearing({ transcribe: async (pcm) => (await v.transcribe(pcmToWav(pcm, 16e3), "audio/wav", config.voice.language)).text });
31085
+ return new AudioHearing({
31086
+ transcribe: async (pcm) => {
31087
+ const t = await v.transcribe(pcmToWav(pcm, 16e3), "audio/wav", config.voice.language, { embed: true });
31088
+ let speaker2;
31089
+ try {
31090
+ const who = judge(t.embedding ?? null);
31091
+ if (who.trust === "owner") speaker2 = meetingStore.prefs().ownerNames[0] || "Owner";
31092
+ else if (who.trust === "member" && who.person) speaker2 = who.person.name;
31093
+ } catch {
31094
+ }
31095
+ return { text: t.text, ...speaker2 ? { speaker: speaker2 } : {} };
31096
+ }
31097
+ });
31037
31098
  },
31038
31099
  tellOwner: (text5, title2) => void tellOwner(text5, title2 ?? "Meeting"),
31039
31100
  runTurn: async (prompt, c) => {
@@ -35382,7 +35443,7 @@ import { appendFileSync } from "node:fs";
35382
35443
  import { join as join44 } from "node:path";
35383
35444
  var PACKAGE2 = "friend-assistant";
35384
35445
  var real2 = {
35385
- current: () => true ? "0.1.106" : "development",
35446
+ current: () => true ? "0.1.107" : "development",
35386
35447
  latest: () => new Promise((resolve13) => {
35387
35448
  const child = crossSpawn5("npm", ["view", PACKAGE2, "version", "--prefer-online"], { stdio: ["ignore", "pipe", "ignore"] });
35388
35449
  let out = "";
@@ -35700,7 +35761,7 @@ async function run2(argv, io2) {
35700
35761
  case "version":
35701
35762
  case "--version":
35702
35763
  case "-v":
35703
- io2.out(true ? "0.1.106" : "development");
35764
+ io2.out(true ? "0.1.107" : "development");
35704
35765
  return 0;
35705
35766
  case "lan":
35706
35767
  return await lanCommand(rest, io2);
@@ -30931,7 +30931,7 @@ function toTask(r) {
30931
30931
  }
30932
30932
 
30933
30933
  // ../pc-agent/src/main.ts
30934
- var VERSION = "0.1.106";
30934
+ var VERSION = "0.1.107";
30935
30935
  var TASK = "Friend PC Agent";
30936
30936
  function parse3(argv) {
30937
30937
  const out = {};
@@ -1 +1 @@
1
- 1f944f730bad40f2422f3ce48fb9cae1e0676752ef1d70bf9217faf68dccdb6a
1
+ 65f87957b673c69104bece851b1d4998eba71d80e0e5aec3becc57b49130ab96
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "friend-assistant",
3
- "version": "0.1.106",
3
+ "version": "0.1.107",
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",