mengram-ai 2.14.5 → 2.15.0
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/index.d.ts +22 -0
- package/index.js +51 -2
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -155,11 +155,28 @@ export interface Webhook {
|
|
|
155
155
|
last_error: string | null;
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
+
export interface BillingInfo {
|
|
159
|
+
plan: 'free' | 'pro' | 'business';
|
|
160
|
+
status: string;
|
|
161
|
+
current_period_end: string | null;
|
|
162
|
+
usage: Record<string, number>;
|
|
163
|
+
quotas: Record<string, number>;
|
|
164
|
+
rate_limit: number;
|
|
165
|
+
}
|
|
166
|
+
|
|
158
167
|
export declare class MengramError extends Error {
|
|
159
168
|
statusCode: number;
|
|
160
169
|
constructor(message: string, statusCode: number);
|
|
161
170
|
}
|
|
162
171
|
|
|
172
|
+
export declare class QuotaExceededError extends MengramError {
|
|
173
|
+
action: string;
|
|
174
|
+
limit: number;
|
|
175
|
+
current: number;
|
|
176
|
+
plan: string;
|
|
177
|
+
constructor(detail: { action: string; limit: number; current: number; plan: string });
|
|
178
|
+
}
|
|
179
|
+
|
|
163
180
|
export declare class MengramClient {
|
|
164
181
|
constructor(apiKey: string, options?: MengramOptions);
|
|
165
182
|
|
|
@@ -241,6 +258,11 @@ export declare class MengramClient {
|
|
|
241
258
|
dismissTrigger(triggerId: number): Promise<{ status: string; id: number }>;
|
|
242
259
|
detectTriggers(userId: string, options?: { userId?: string }): Promise<any>;
|
|
243
260
|
|
|
261
|
+
// Billing
|
|
262
|
+
getBilling(): Promise<BillingInfo>;
|
|
263
|
+
createCheckout(plan: 'pro' | 'business'): Promise<{ checkout_url: string; transaction_id: string }>;
|
|
264
|
+
createPortal(): Promise<{ portal_url: string }>;
|
|
265
|
+
|
|
244
266
|
// Import (v2.9)
|
|
245
267
|
importChatgpt(zipPath: string, options?: { chunkSize?: number; onProgress?: (current: number, total: number, title: string) => void }): Promise<ImportResult>;
|
|
246
268
|
importObsidian(vaultPath: string, options?: { chunkChars?: number; onProgress?: (current: number, total: number, title: string) => void }): Promise<ImportResult>;
|
package/index.js
CHANGED
|
@@ -66,12 +66,16 @@ class MengramClient {
|
|
|
66
66
|
await new Promise(r => setTimeout(r, 1000 * (attempt + 1)));
|
|
67
67
|
continue;
|
|
68
68
|
}
|
|
69
|
+
// Quota exceeded — structured error
|
|
70
|
+
if (res.status === 402 && data.detail && typeof data.detail === 'object') {
|
|
71
|
+
throw new QuotaExceededError(data.detail);
|
|
72
|
+
}
|
|
69
73
|
throw new MengramError(data.detail || `HTTP ${res.status}`, res.status);
|
|
70
74
|
}
|
|
71
75
|
return data;
|
|
72
76
|
} catch (err) {
|
|
73
77
|
if (err instanceof MengramError) {
|
|
74
|
-
if ([429, 502, 503, 504].includes(err.
|
|
78
|
+
if ([429, 502, 503, 504].includes(err.statusCode) && attempt < 2) {
|
|
75
79
|
lastErr = err;
|
|
76
80
|
await new Promise(r => setTimeout(r, 1000 * (attempt + 1)));
|
|
77
81
|
continue;
|
|
@@ -864,6 +868,33 @@ class MengramClient {
|
|
|
864
868
|
return this._request('POST', `/v1/triggers/detect/${userId}`, null, params);
|
|
865
869
|
}
|
|
866
870
|
|
|
871
|
+
// ---- Billing ----
|
|
872
|
+
|
|
873
|
+
/**
|
|
874
|
+
* Get current subscription plan, usage, and quotas.
|
|
875
|
+
* @returns {Promise<{plan: string, status: string, usage: object, quotas: object, rate_limit: number}>}
|
|
876
|
+
*/
|
|
877
|
+
async getBilling() {
|
|
878
|
+
return this._request('GET', '/v1/billing');
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
/**
|
|
882
|
+
* Create Paddle checkout session for plan upgrade.
|
|
883
|
+
* @param {string} plan - 'pro' or 'business'
|
|
884
|
+
* @returns {Promise<{checkout_url: string, transaction_id: string}>}
|
|
885
|
+
*/
|
|
886
|
+
async createCheckout(plan) {
|
|
887
|
+
return this._request('POST', '/v1/billing/checkout', null, { plan });
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* Create Paddle customer portal session for managing subscription.
|
|
892
|
+
* @returns {Promise<{portal_url: string}>}
|
|
893
|
+
*/
|
|
894
|
+
async createPortal() {
|
|
895
|
+
return this._request('POST', '/v1/billing/portal');
|
|
896
|
+
}
|
|
897
|
+
|
|
867
898
|
// ---- Import ----
|
|
868
899
|
|
|
869
900
|
/**
|
|
@@ -1152,6 +1183,24 @@ class MengramError extends Error {
|
|
|
1152
1183
|
}
|
|
1153
1184
|
}
|
|
1154
1185
|
|
|
1186
|
+
class QuotaExceededError extends MengramError {
|
|
1187
|
+
constructor(detail) {
|
|
1188
|
+
const action = detail.action || 'unknown';
|
|
1189
|
+
const limit = detail.limit || 0;
|
|
1190
|
+
const current = detail.used || 0;
|
|
1191
|
+
const plan = detail.plan || 'free';
|
|
1192
|
+
super(
|
|
1193
|
+
`Quota exceeded for '${action}': ${current}/${limit} (plan: ${plan}). Upgrade at https://mengram.io/dashboard`,
|
|
1194
|
+
402
|
|
1195
|
+
);
|
|
1196
|
+
this.name = 'QuotaExceededError';
|
|
1197
|
+
this.action = action;
|
|
1198
|
+
this.limit = limit;
|
|
1199
|
+
this.current = current;
|
|
1200
|
+
this.plan = plan;
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1155
1204
|
// Export for both CommonJS and ESM
|
|
1156
|
-
module.exports = { MengramClient, MengramError };
|
|
1205
|
+
module.exports = { MengramClient, MengramError, QuotaExceededError };
|
|
1157
1206
|
module.exports.default = MengramClient;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mengram-ai",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.15.0",
|
|
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",
|