@pyxmate/memory 0.11.0 → 0.12.1

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.
@@ -11,24 +11,31 @@ var MemoryServerError = class extends Error {
11
11
  return this.status === 404;
12
12
  }
13
13
  };
14
+ var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
14
15
  var MemoryClient = class {
15
16
  baseUrl;
16
17
  _authHeaders;
18
+ _requestTimeoutMs;
17
19
  constructor(memoryUrl, apiKeyOrOptions) {
18
20
  this.baseUrl = memoryUrl.replace(/\/$/, "");
19
21
  let apiKey;
20
22
  let defaultHeaders = {};
23
+ let requestTimeoutMs = DEFAULT_REQUEST_TIMEOUT_MS;
21
24
  if (typeof apiKeyOrOptions === "string") {
22
25
  apiKey = apiKeyOrOptions;
23
26
  } else if (apiKeyOrOptions) {
24
27
  apiKey = apiKeyOrOptions.apiKey;
25
28
  defaultHeaders = apiKeyOrOptions.defaultHeaders ?? {};
29
+ if (apiKeyOrOptions.requestTimeoutMs !== void 0) {
30
+ requestTimeoutMs = apiKeyOrOptions.requestTimeoutMs;
31
+ }
26
32
  }
27
33
  const trimmed = apiKey?.trim();
28
34
  this._authHeaders = {
29
35
  ...trimmed ? { Authorization: `Bearer ${trimmed}` } : {},
30
36
  ...defaultHeaders
31
37
  };
38
+ this._requestTimeoutMs = requestTimeoutMs;
32
39
  }
33
40
  /** Encode a path segment to prevent URL injection */
34
41
  encodePathSegment(segment) {
@@ -335,16 +342,44 @@ var MemoryClient = class {
335
342
  return result.entries;
336
343
  }
337
344
  async fetchApi(path, options) {
338
- const res = await fetch(`${this.baseUrl}${path}`, {
339
- ...options,
340
- headers: {
341
- "Content-Type": "application/json",
342
- ...options?.headers,
343
- ...this._authHeaders
344
- }
345
- });
345
+ const signal = options?.signal ?? AbortSignal.timeout(this._requestTimeoutMs);
346
+ let res;
347
+ try {
348
+ res = await fetch(`${this.baseUrl}${path}`, {
349
+ ...options,
350
+ headers: {
351
+ "Content-Type": "application/json",
352
+ ...options?.headers,
353
+ ...this._authHeaders
354
+ },
355
+ signal
356
+ });
357
+ } catch (err) {
358
+ throw this.translateFetchError(err, path);
359
+ }
346
360
  return this.parseApiResponse(res);
347
361
  }
362
+ /**
363
+ * Map fetch-layer rejections into a typed `MemoryServerError` so callers
364
+ * can react uniformly. AbortSignal.timeout fires a `TimeoutError`; the
365
+ * caller's signal generally fires an `AbortError`. Anything else (DNS,
366
+ * TCP reset, TLS) becomes a wrapped error with status 0.
367
+ */
368
+ translateFetchError(err, path) {
369
+ if (err instanceof Error) {
370
+ if (err.name === "TimeoutError") {
371
+ return new MemoryServerError(
372
+ `Memory server request timed out after ${this._requestTimeoutMs}ms (${path})`,
373
+ 504
374
+ );
375
+ }
376
+ if (err.name === "AbortError") {
377
+ return new MemoryServerError(`Memory server request aborted (${path})`, 499);
378
+ }
379
+ return new MemoryServerError(`Memory server request failed: ${err.message} (${path})`, 0);
380
+ }
381
+ return new MemoryServerError(`Memory server request failed: ${String(err)} (${path})`, 0);
382
+ }
348
383
  /** Parse and validate a JSON API response, throwing MemoryServerError on any failure. */
349
384
  async parseApiResponse(res) {
350
385
  let body;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  MemoryClient
3
- } from "./chunk-5IERAVVW.mjs";
3
+ } from "./chunk-4YIKI2BA.mjs";
4
4
 
5
5
  // ../dashboard/src/aggregations/consolidation-analytics.ts
6
6
  function analyzeConsolidationLog(entries) {
@@ -11,8 +11,8 @@ import {
11
11
  toGraphologyFormat,
12
12
  transformGraphData,
13
13
  unreachableHealth
14
- } from "./chunk-DGVOXKYV.mjs";
15
- import "./chunk-5IERAVVW.mjs";
14
+ } from "./chunk-DZZHJ66P.mjs";
15
+ import "./chunk-4YIKI2BA.mjs";
16
16
  export {
17
17
  DashboardClient,
18
18
  Poller,
package/dist/index.d.ts CHANGED
@@ -128,10 +128,26 @@ interface MemoryClientOptions {
128
128
  apiKey?: string;
129
129
  /** Additional headers to send with every request (e.g., X-Caller-Access-Level). */
130
130
  defaultHeaders?: Record<string, string>;
131
+ /**
132
+ * Default per-request timeout in milliseconds. Without this, a wedged
133
+ * memory server (e.g. event-loop blocked by inference) makes every
134
+ * caller hang forever — that was the Korens demo wedge in 2026-04 where
135
+ * a 161-second pyx-memory stall propagated through the runtime to the
136
+ * browser. Defaults to 30 s, which is high enough that normal
137
+ * `/search` and `/stats` requests never hit it but low enough that a
138
+ * stuck server fails loudly.
139
+ *
140
+ * Only applied when the caller does NOT pass their own `signal` via
141
+ * RequestInit. Long-running operations (large `consolidate`, `reindex`,
142
+ * file ingest with enrichment) should pass their own AbortSignal —
143
+ * that signal fully replaces the default ceiling.
144
+ */
145
+ requestTimeoutMs?: number;
131
146
  }
132
147
  declare class MemoryClient implements ExtendedMemoryInterface {
133
148
  protected baseUrl: string;
134
149
  private readonly _authHeaders;
150
+ private readonly _requestTimeoutMs;
135
151
  constructor(memoryUrl: string, apiKeyOrOptions?: string | MemoryClientOptions);
136
152
  /** Encode a path segment to prevent URL injection */
137
153
  private encodePathSegment;
@@ -191,6 +207,13 @@ declare class MemoryClient implements ExtendedMemoryInterface {
191
207
  queryAsOf(asOfDate: string, filters?: TemporalQueryFilters): Promise<MemoryEntry$1[]>;
192
208
  queryByEventTime(startTime: string, endTime: string, filters?: TemporalQueryFilters): Promise<MemoryEntry$1[]>;
193
209
  protected fetchApi<T>(path: string, options?: RequestInit): Promise<T>;
210
+ /**
211
+ * Map fetch-layer rejections into a typed `MemoryServerError` so callers
212
+ * can react uniformly. AbortSignal.timeout fires a `TimeoutError`; the
213
+ * caller's signal generally fires an `AbortError`. Anything else (DNS,
214
+ * TCP reset, TLS) becomes a wrapped error with status 0.
215
+ */
216
+ private translateFetchError;
194
217
  /** Parse and validate a JSON API response, throwing MemoryServerError on any failure. */
195
218
  private parseApiResponse;
196
219
  }
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  MemoryClient,
3
3
  MemoryServerError
4
- } from "./chunk-5IERAVVW.mjs";
4
+ } from "./chunk-4YIKI2BA.mjs";
5
5
 
6
6
  // ../shared/src/constants/defaults.ts
7
7
  var DEFAULTS = {
package/dist/react.mjs CHANGED
@@ -11,8 +11,8 @@ import {
11
11
  toGraphologyFormat,
12
12
  transformGraphData,
13
13
  unreachableHealth
14
- } from "./chunk-DGVOXKYV.mjs";
15
- import "./chunk-5IERAVVW.mjs";
14
+ } from "./chunk-DZZHJ66P.mjs";
15
+ import "./chunk-4YIKI2BA.mjs";
16
16
 
17
17
  // ../dashboard/src/hooks/use-consolidation-log.ts
18
18
  import { useCallback as useCallback2, useMemo } from "react";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pyxmate/memory",
3
- "version": "0.11.0",
3
+ "version": "0.12.1",
4
4
  "type": "module",
5
5
  "description": "SDK for pyx-memory — Memory as a Service for AI agents",
6
6
  "license": "MIT",