@ai-matrx/desktop-protocol 0.21.66 → 0.21.68

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/client.cjs CHANGED
@@ -1982,7 +1982,7 @@ var AudioRecordParams = import_zod21.z.strictObject({
1982
1982
  path: AbsPath.optional(),
1983
1983
  /** (1.66) 1 (mono, the default) or 2 (stereo). */
1984
1984
  channels: import_zod21.z.int().min(1).max(2).optional(),
1985
- /** (1.66) Samples per second; the device's own rate when absent. */
1985
+ /** (1.66) Samples per second; 16000 when absent (the rate Whisper reads). */
1986
1986
  sample_rate: import_zod21.z.int().min(8e3).max(192e3).optional()
1987
1987
  });
1988
1988
  var AudioRecordResult = import_zod21.z.strictObject({
@@ -5013,6 +5013,13 @@ function createDesktopClient(options) {
5013
5013
  const listeners = /* @__PURE__ */ new Set();
5014
5014
  const readyWaiters = /* @__PURE__ */ new Set();
5015
5015
  const pending = /* @__PURE__ */ new Map();
5016
+ const abandoned = /* @__PURE__ */ new Set();
5017
+ const ABANDONED_MAX = 1024;
5018
+ function abandon(id) {
5019
+ if (!sendJson({ id, type: "cancel" })) return;
5020
+ abandoned.add(id);
5021
+ if (abandoned.size > ABANDONED_MAX) abandoned.delete(abandoned.values().next().value);
5022
+ }
5016
5023
  const streams = /* @__PURE__ */ new Map();
5017
5024
  const bySid = /* @__PURE__ */ new Map();
5018
5025
  const eventHandlers = /* @__PURE__ */ new Map();
@@ -5131,6 +5138,7 @@ function createDesktopClient(options) {
5131
5138
  const stopped = rule !== null && (rule.action === "stop" || rule.action === "reauth" && authRefusals >= 2);
5132
5139
  const terminal = stopped && rule ? rule : void 0;
5133
5140
  const lost = error ?? (terminal ? new DesktopProtocolError(terminal.error[0], terminal.error[1]) : rule && rule.action === "reauth" ? new DesktopProtocolError(rule.error[0], rule.error[1], { retryable: true }) : new DesktopProtocolError("DEVICE_OFFLINE", "Connection lost", { retryable: true }));
5141
+ abandoned.clear();
5134
5142
  for (const [id, p] of pending) {
5135
5143
  pending.delete(id);
5136
5144
  p.cleanup();
@@ -5234,7 +5242,10 @@ function createDesktopClient(options) {
5234
5242
  const s = streams.get(msg.id);
5235
5243
  if (s) return onStreamResult(s, msg.result);
5236
5244
  const p = pending.get(msg.id);
5237
- if (!p) return diagnose({ kind: "unknown_request", id: msg.id, type: msg.type });
5245
+ if (!p) {
5246
+ if (abandoned.delete(msg.id)) return;
5247
+ return diagnose({ kind: "unknown_request", id: msg.id, type: msg.type });
5248
+ }
5238
5249
  pending.delete(msg.id);
5239
5250
  p.cleanup();
5240
5251
  p.resolve(msg.result);
@@ -5251,7 +5262,10 @@ function createDesktopClient(options) {
5251
5262
  return endStream(s, null, error);
5252
5263
  }
5253
5264
  const p = pending.get(msg.id);
5254
- if (!p) return diagnose({ kind: "unknown_request", id: msg.id, type: msg.type });
5265
+ if (!p) {
5266
+ if (abandoned.delete(msg.id)) return;
5267
+ return diagnose({ kind: "unknown_request", id: msg.id, type: msg.type });
5268
+ }
5255
5269
  pending.delete(msg.id);
5256
5270
  p.cleanup();
5257
5271
  p.reject(error);
@@ -5482,13 +5496,13 @@ function createDesktopClient(options) {
5482
5496
  const timer = timers.setTimeout(() => {
5483
5497
  pending.delete(id);
5484
5498
  cleanup();
5485
- sendJson({ id, type: "cancel" });
5499
+ abandon(id);
5486
5500
  reject(new DesktopProtocolError("TIMEOUT", `${op} timed out`, { retryable: true }));
5487
5501
  }, timeoutMs);
5488
5502
  const onAbort = () => {
5489
5503
  pending.delete(id);
5490
5504
  cleanup();
5491
- sendJson({ id, type: "cancel" });
5505
+ abandon(id);
5492
5506
  reject(new DesktopProtocolError("CANCELLED", "Aborted"));
5493
5507
  };
5494
5508
  function cleanup() {