mengram-ai 2.14.3 → 2.14.5

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.
Files changed (2) hide show
  1. package/index.js +52 -26
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -45,31 +45,54 @@ class MengramClient {
45
45
  'Content-Type': 'application/json',
46
46
  };
47
47
 
48
- const controller = new AbortController();
49
- const timer = setTimeout(() => controller.abort(), this.timeout);
48
+ let lastErr;
49
+ for (let attempt = 0; attempt < 3; attempt++) {
50
+ const controller = new AbortController();
51
+ const timer = setTimeout(() => controller.abort(), this.timeout);
50
52
 
51
- try {
52
- const res = await fetch(url, {
53
- method,
54
- headers,
55
- body: body ? JSON.stringify(body) : undefined,
56
- signal: controller.signal,
57
- });
58
-
59
- const data = await res.json();
60
- if (!res.ok) {
61
- throw new MengramError(data.detail || `HTTP ${res.status}`, res.status);
62
- }
63
- return data;
64
- } catch (err) {
65
- if (err instanceof MengramError) throw err;
66
- if (err.name === 'AbortError') {
67
- throw new MengramError(`Request timeout after ${this.timeout}ms`, 408);
53
+ try {
54
+ const res = await fetch(url, {
55
+ method,
56
+ headers,
57
+ body: body ? JSON.stringify(body) : undefined,
58
+ signal: controller.signal,
59
+ });
60
+
61
+ const data = await res.json();
62
+ if (!res.ok) {
63
+ // Retry on transient errors
64
+ if ([429, 502, 503, 504].includes(res.status) && attempt < 2) {
65
+ lastErr = new MengramError(data.detail || `HTTP ${res.status}`, res.status);
66
+ await new Promise(r => setTimeout(r, 1000 * (attempt + 1)));
67
+ continue;
68
+ }
69
+ throw new MengramError(data.detail || `HTTP ${res.status}`, res.status);
70
+ }
71
+ return data;
72
+ } catch (err) {
73
+ if (err instanceof MengramError) {
74
+ if ([429, 502, 503, 504].includes(err.status) && attempt < 2) {
75
+ lastErr = err;
76
+ await new Promise(r => setTimeout(r, 1000 * (attempt + 1)));
77
+ continue;
78
+ }
79
+ throw err;
80
+ }
81
+ if (err.name === 'AbortError') {
82
+ throw new MengramError(`Request timeout after ${this.timeout}ms`, 408);
83
+ }
84
+ // Retry on network errors
85
+ if (attempt < 2) {
86
+ lastErr = err;
87
+ await new Promise(r => setTimeout(r, 1000 * (attempt + 1)));
88
+ continue;
89
+ }
90
+ throw new MengramError(err.message, 0);
91
+ } finally {
92
+ clearTimeout(timer);
68
93
  }
69
- throw new MengramError(err.message, 0);
70
- } finally {
71
- clearTimeout(timer);
72
94
  }
95
+ throw lastErr || new MengramError('Request failed after 3 attempts', 0);
73
96
  }
74
97
 
75
98
  // ---- Memory ----
@@ -104,16 +127,19 @@ class MengramClient {
104
127
  * @param {string} [options.agentId]
105
128
  * @param {string} [options.runId]
106
129
  * @param {string} [options.appId]
130
+ * @param {string} [options.expirationDate] - ISO datetime when memories expire
107
131
  * @returns {Promise<{status: string}>}
108
132
  */
109
133
  async addText(text, options = {}) {
110
- return this._request('POST', '/v1/add_text', {
134
+ const body = {
111
135
  text,
112
136
  user_id: options.userId || 'default',
113
137
  agent_id: options.agentId || null,
114
138
  run_id: options.runId || null,
115
139
  app_id: options.appId || null,
116
- });
140
+ };
141
+ if (options.expirationDate) body.expiration_date = options.expirationDate;
142
+ return this._request('POST', '/v1/add_text', body);
117
143
  }
118
144
 
119
145
  /**
@@ -193,7 +219,7 @@ class MengramClient {
193
219
  try {
194
220
  const params = {};
195
221
  if (options.userId && options.userId !== 'default') params.sub_user_id = options.userId;
196
- await this._request('DELETE', `/v1/entity/${encodeURIComponent(name)}`, null, params);
222
+ await this._request('DELETE', `/v1/memory/${encodeURIComponent(name)}`, null, params);
197
223
  return true;
198
224
  } catch {
199
225
  return false;
@@ -748,7 +774,7 @@ class MengramClient {
748
774
  * @returns {Promise<Array>}
749
775
  */
750
776
  async feed(options = {}) {
751
- const params = { limit: options.limit || 20 };
777
+ const params = { limit: options.limit || 50 };
752
778
  if (options.userId && options.userId !== 'default') params.sub_user_id = options.userId;
753
779
  const data = await this._request('GET', '/v1/feed', null, params);
754
780
  return data.feed || [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mengram-ai",
3
- "version": "2.14.3",
3
+ "version": "2.14.5",
4
4
  "description": "Human-like memory for AI — semantic, episodic & procedural memory. Experience-driven procedures, Cognitive Profile, unified search, memory agents. Free Mem0 alternative.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",