@smartmemory/sdk-js 0.5.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.
- package/README.md +266 -0
- package/dist/core-Ds7Kn35C.js +2476 -0
- package/dist/core.js +20 -0
- package/dist/fetch.js +43 -0
- package/dist/index.js +102 -0
- package/dist/progress.js +191 -0
- package/dist/react.js +77 -0
- package/package.json +68 -0
|
@@ -0,0 +1,2476 @@
|
|
|
1
|
+
var _ = (i) => {
|
|
2
|
+
throw TypeError(i);
|
|
3
|
+
};
|
|
4
|
+
var p = (i, e, t) => e.has(i) || _("Cannot " + t);
|
|
5
|
+
var u = (i, e, t) => (p(i, e, "read from private field"), t ? t.call(i) : e.get(i)), g = (i, e, t) => e.has(i) ? _("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(i) : e.set(i, t), d = (i, e, t, r) => (p(i, e, "write to private field"), r ? r.call(i, t) : e.set(i, t), t), $ = (i, e, t) => (p(i, e, "access private method"), t);
|
|
6
|
+
const b = {
|
|
7
|
+
access: "smart_memory_auth_token",
|
|
8
|
+
refresh: "smart_memory_refresh_token",
|
|
9
|
+
user: "smart_memory_user",
|
|
10
|
+
tenant: "smart_memory_tenant_id",
|
|
11
|
+
team: "smart_memory_team_id"
|
|
12
|
+
}, m = {
|
|
13
|
+
access: ["access_token", "sm_token"],
|
|
14
|
+
refresh: ["refresh_token", "sm_refresh_token"],
|
|
15
|
+
user: ["sm_user"],
|
|
16
|
+
tenant: ["tenant_id", "workspace_id", "sm_workspace_id"],
|
|
17
|
+
team: ["team_id", "sm_team_id"]
|
|
18
|
+
};
|
|
19
|
+
class I {
|
|
20
|
+
/**
|
|
21
|
+
* @param {Object} options
|
|
22
|
+
* @param {'localStorage' | 'sessionStorage' | 'memory'} [options.storage='localStorage']
|
|
23
|
+
* @param {Object} [options.keys] - Custom storage key names
|
|
24
|
+
*/
|
|
25
|
+
constructor({ storage: e = "localStorage", keys: t = {} } = {}) {
|
|
26
|
+
this.storageType = e, this.keys = { ...b, ...t }, this._memory = { access: null, refresh: null, user: null, tenant: null, team: null };
|
|
27
|
+
}
|
|
28
|
+
getAccessToken() {
|
|
29
|
+
return this.storageType === "memory" ? this._memory.access : this._getFromStorage(this.keys.access, m.access);
|
|
30
|
+
}
|
|
31
|
+
setAccessToken(e) {
|
|
32
|
+
if (this.storageType === "memory") {
|
|
33
|
+
this._memory.access = e;
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
this._setInStorage(this.keys.access, e);
|
|
37
|
+
}
|
|
38
|
+
getRefreshToken() {
|
|
39
|
+
return this.storageType === "memory" ? this._memory.refresh : this._getFromStorage(this.keys.refresh, m.refresh);
|
|
40
|
+
}
|
|
41
|
+
setRefreshToken(e) {
|
|
42
|
+
if (this.storageType === "memory") {
|
|
43
|
+
this._memory.refresh = e;
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
this._setInStorage(this.keys.refresh, e);
|
|
47
|
+
}
|
|
48
|
+
getUser() {
|
|
49
|
+
if (this.storageType === "memory") return this._memory.user;
|
|
50
|
+
const e = this._getFromStorage(this.keys.user, m.user);
|
|
51
|
+
if (!e) return null;
|
|
52
|
+
try {
|
|
53
|
+
return JSON.parse(e);
|
|
54
|
+
} catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
setUser(e) {
|
|
59
|
+
if (this.storageType === "memory") {
|
|
60
|
+
this._memory.user = e;
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
this._setInStorage(this.keys.user, e ? JSON.stringify(e) : null);
|
|
64
|
+
}
|
|
65
|
+
getTenantId() {
|
|
66
|
+
return this.storageType === "memory" ? this._memory.tenant : this._normalizeId(this._getFromStorage(this.keys.tenant, m.tenant));
|
|
67
|
+
}
|
|
68
|
+
setTenantId(e) {
|
|
69
|
+
const t = this._normalizeId(e);
|
|
70
|
+
if (this.storageType === "memory") {
|
|
71
|
+
this._memory.tenant = t;
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
this._setInStorage(this.keys.tenant, t);
|
|
75
|
+
}
|
|
76
|
+
getTeamId() {
|
|
77
|
+
return this.storageType === "memory" ? this._memory.team : this._normalizeId(this._getFromStorage(this.keys.team, m.team));
|
|
78
|
+
}
|
|
79
|
+
setTeamId(e) {
|
|
80
|
+
const t = this._normalizeId(e);
|
|
81
|
+
if (this.storageType === "memory") {
|
|
82
|
+
this._memory.team = t;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
this._setInStorage(this.keys.team, t);
|
|
86
|
+
}
|
|
87
|
+
clearAll() {
|
|
88
|
+
if (this.storageType === "memory") {
|
|
89
|
+
this._memory = { access: null, refresh: null, user: null, tenant: null, team: null };
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
for (const e of Object.values(this.keys))
|
|
93
|
+
try {
|
|
94
|
+
localStorage.removeItem(e), sessionStorage.removeItem(e);
|
|
95
|
+
} catch {
|
|
96
|
+
}
|
|
97
|
+
for (const e of Object.values(m))
|
|
98
|
+
for (const t of e)
|
|
99
|
+
try {
|
|
100
|
+
localStorage.removeItem(t), sessionStorage.removeItem(t);
|
|
101
|
+
} catch {
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/** @private */
|
|
105
|
+
_getFromStorage(e, t = []) {
|
|
106
|
+
try {
|
|
107
|
+
const r = this.storageType === "localStorage" ? localStorage : sessionStorage, s = this.storageType === "localStorage" ? sessionStorage : localStorage, n = r.getItem(e) || s.getItem(e);
|
|
108
|
+
if (n != null) return n;
|
|
109
|
+
for (const a of t) {
|
|
110
|
+
const c = r.getItem(a) || s.getItem(a);
|
|
111
|
+
if (c != null) {
|
|
112
|
+
this._setInStorage(e, c);
|
|
113
|
+
try {
|
|
114
|
+
r.removeItem(a), s.removeItem(a);
|
|
115
|
+
} catch {
|
|
116
|
+
}
|
|
117
|
+
return c;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return null;
|
|
121
|
+
} catch {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/** @private */
|
|
126
|
+
_setInStorage(e, t) {
|
|
127
|
+
try {
|
|
128
|
+
const r = this.storageType === "localStorage" ? localStorage : sessionStorage, s = this.storageType === "localStorage" ? sessionStorage : localStorage;
|
|
129
|
+
t != null ? (r.setItem(e, t), s.removeItem(e)) : (r.removeItem(e), s.removeItem(e));
|
|
130
|
+
} catch (r) {
|
|
131
|
+
console.error("Failed to write to storage:", r);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/** @private */
|
|
135
|
+
_normalizeId(e) {
|
|
136
|
+
if (e == null) return null;
|
|
137
|
+
const t = String(e).trim();
|
|
138
|
+
if (!t) return null;
|
|
139
|
+
const r = t.toLowerCase();
|
|
140
|
+
return r === "none" || r === "null" || r === "undefined" ? null : t;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
var l, y, k;
|
|
144
|
+
class T {
|
|
145
|
+
/**
|
|
146
|
+
* @param {Object} options
|
|
147
|
+
* @param {string} options.apiBaseUrl
|
|
148
|
+
* @param {string} options.refreshEndpoint
|
|
149
|
+
* @param {import('./TokenManager.js').TokenManager} options.tokenManager
|
|
150
|
+
* @param {boolean} [options.useCookieAuth=false]
|
|
151
|
+
* @param {function(string): void} options.onTokenRefreshed
|
|
152
|
+
* @param {function(): void} options.onRefreshFailed
|
|
153
|
+
*/
|
|
154
|
+
constructor({ apiBaseUrl: e, refreshEndpoint: t, tokenManager: r, useCookieAuth: s = !1, onTokenRefreshed: n, onRefreshFailed: a }) {
|
|
155
|
+
g(this, y);
|
|
156
|
+
g(this, l, null);
|
|
157
|
+
this.apiBaseUrl = e, this.refreshEndpoint = t, this.tokenManager = r, this.useCookieAuth = s, this.onTokenRefreshed = n, this.onRefreshFailed = a;
|
|
158
|
+
}
|
|
159
|
+
async refresh() {
|
|
160
|
+
if (u(this, l))
|
|
161
|
+
return u(this, l);
|
|
162
|
+
d(this, l, $(this, y, k).call(this));
|
|
163
|
+
try {
|
|
164
|
+
return await u(this, l);
|
|
165
|
+
} finally {
|
|
166
|
+
d(this, l, null);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
l = new WeakMap(), y = new WeakSet(), k = async function() {
|
|
171
|
+
const e = this.tokenManager.getRefreshToken();
|
|
172
|
+
if (!e && !this.useCookieAuth)
|
|
173
|
+
throw this.onRefreshFailed(), new Error("No refresh token");
|
|
174
|
+
const t = JSON.stringify(e ? { refresh_token: e } : {}), r = await fetch(`${this.apiBaseUrl}${this.refreshEndpoint}`, {
|
|
175
|
+
...this.useCookieAuth ? { credentials: "include" } : {},
|
|
176
|
+
method: "POST",
|
|
177
|
+
headers: { "Content-Type": "application/json" },
|
|
178
|
+
body: t
|
|
179
|
+
});
|
|
180
|
+
if (!r.ok)
|
|
181
|
+
throw this.onRefreshFailed(), new Error(`Refresh failed: ${r.status}`);
|
|
182
|
+
const s = await r.json();
|
|
183
|
+
return this.tokenManager.setAccessToken(s.access_token), s.refresh_token && this.tokenManager.setRefreshToken(s.refresh_token), this.onTokenRefreshed(s.access_token), s.access_token;
|
|
184
|
+
};
|
|
185
|
+
const f = "smart_memory_sso_redirect";
|
|
186
|
+
class S {
|
|
187
|
+
/**
|
|
188
|
+
* @param {Object} options
|
|
189
|
+
* @param {string} options.webAppUrl - Web app URL for login redirect
|
|
190
|
+
* @param {string[]} [options.allowedHosts=[]] - Allowed redirect hostnames
|
|
191
|
+
* @param {import('./TokenManager.js').TokenManager} options.tokenManager
|
|
192
|
+
*/
|
|
193
|
+
constructor({ webAppUrl: e, allowedHosts: t = [], tokenManager: r }) {
|
|
194
|
+
this.webAppUrl = e, this.allowedHosts = t, this.tokenManager = r;
|
|
195
|
+
}
|
|
196
|
+
getLoginUrl(e) {
|
|
197
|
+
const t = e || `${window.location.origin}/auth/callback`;
|
|
198
|
+
return `${this.webAppUrl}/login?redirect=${encodeURIComponent(t)}`;
|
|
199
|
+
}
|
|
200
|
+
isValidRedirectUrl(e) {
|
|
201
|
+
if (!this.allowedHosts.length) return !0;
|
|
202
|
+
try {
|
|
203
|
+
const t = new URL(e);
|
|
204
|
+
return this.allowedHosts.includes(t.hostname);
|
|
205
|
+
} catch {
|
|
206
|
+
return !1;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
storeRedirect(e) {
|
|
210
|
+
try {
|
|
211
|
+
sessionStorage.setItem(f, e);
|
|
212
|
+
} catch (t) {
|
|
213
|
+
console.warn("Failed to store redirect URL:", t);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
getAndClearRedirect() {
|
|
217
|
+
try {
|
|
218
|
+
const e = sessionStorage.getItem(f);
|
|
219
|
+
return sessionStorage.removeItem(f), e;
|
|
220
|
+
} catch {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
class v {
|
|
226
|
+
constructor(e) {
|
|
227
|
+
this.mode = e.mode, this.apiBaseUrl = e.apiBaseUrl, this.endpoints = e.endpoints || {}, this.listeners = /* @__PURE__ */ new Set(), this.useCookieAuth = e.useCookieAuth ?? this.mode === "sso", this.apiKey = e.apiKey || null, this.apiKey && (this.mode = "apiKey"), this.tokenManager = new I({
|
|
228
|
+
storage: e.storage || "localStorage",
|
|
229
|
+
keys: e.tokenKeys
|
|
230
|
+
}), this.mode !== "apiKey" ? this.refreshManager = new T({
|
|
231
|
+
apiBaseUrl: this.apiBaseUrl,
|
|
232
|
+
refreshEndpoint: this.endpoints.refresh || "/auth/refresh",
|
|
233
|
+
tokenManager: this.tokenManager,
|
|
234
|
+
useCookieAuth: this.useCookieAuth,
|
|
235
|
+
onTokenRefreshed: (t) => {
|
|
236
|
+
var r;
|
|
237
|
+
this.currentToken = t, this.notifyListeners(), (r = e.onTokenRefresh) == null || r.call(e, t);
|
|
238
|
+
},
|
|
239
|
+
onRefreshFailed: () => {
|
|
240
|
+
this.clearLocalAuth();
|
|
241
|
+
}
|
|
242
|
+
}) : this.refreshManager = null, this.mode === "sso" && (this.ssoManager = new S({
|
|
243
|
+
webAppUrl: e.webAppUrl,
|
|
244
|
+
allowedHosts: e.allowedRedirectHosts || [],
|
|
245
|
+
tokenManager: this.tokenManager
|
|
246
|
+
})), this.mode === "apiKey" ? (this.currentUser = null, this.currentToken = this.apiKey) : (this.currentUser = this.tokenManager.getUser(), this.currentToken = this.tokenManager.getAccessToken());
|
|
247
|
+
}
|
|
248
|
+
isAuthenticated() {
|
|
249
|
+
return !!this.currentToken || this.useCookieAuth && !!this.currentUser;
|
|
250
|
+
}
|
|
251
|
+
getCurrentUser() {
|
|
252
|
+
return this.currentUser;
|
|
253
|
+
}
|
|
254
|
+
getCurrentToken() {
|
|
255
|
+
return this.currentToken;
|
|
256
|
+
}
|
|
257
|
+
getTenantId() {
|
|
258
|
+
return this.tokenManager.getTenantId();
|
|
259
|
+
}
|
|
260
|
+
hasRole(e) {
|
|
261
|
+
var t, r;
|
|
262
|
+
return ((r = (t = this.currentUser) == null ? void 0 : t.roles) == null ? void 0 : r.includes(e)) || !1;
|
|
263
|
+
}
|
|
264
|
+
getAuthHeaders(e = {}) {
|
|
265
|
+
const t = { ...e };
|
|
266
|
+
this.currentToken && (t.Authorization = this.currentToken.startsWith("Bearer ") ? this.currentToken : `Bearer ${this.currentToken}`);
|
|
267
|
+
const r = this.tokenManager.getTeamId();
|
|
268
|
+
return r && (t["X-Workspace-Id"] = r), t;
|
|
269
|
+
}
|
|
270
|
+
getRequestOptions(e = {}) {
|
|
271
|
+
return this.useCookieAuth ? { credentials: "include", ...e } : { ...e };
|
|
272
|
+
}
|
|
273
|
+
addListener(e) {
|
|
274
|
+
return this.listeners.add(e), () => this.listeners.delete(e);
|
|
275
|
+
}
|
|
276
|
+
notifyListeners() {
|
|
277
|
+
const e = {
|
|
278
|
+
isAuthenticated: this.isAuthenticated(),
|
|
279
|
+
user: this.currentUser,
|
|
280
|
+
token: this.currentToken,
|
|
281
|
+
tenantId: this.tokenManager.getTenantId()
|
|
282
|
+
};
|
|
283
|
+
this.listeners.forEach((t) => {
|
|
284
|
+
try {
|
|
285
|
+
t(e);
|
|
286
|
+
} catch (r) {
|
|
287
|
+
console.error("Auth listener error:", r);
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
getLoginUrl(e) {
|
|
292
|
+
if (this.mode !== "sso")
|
|
293
|
+
throw new Error("getLoginUrl() only available in sso mode");
|
|
294
|
+
return this.ssoManager.getLoginUrl(e);
|
|
295
|
+
}
|
|
296
|
+
clearLocalAuth() {
|
|
297
|
+
if (this.mode === "apiKey") {
|
|
298
|
+
this.apiKey = null, this.currentToken = null, this.notifyListeners();
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
this.tokenManager.clearAll(), this.currentUser = null, this.currentToken = null, this.notifyListeners();
|
|
302
|
+
}
|
|
303
|
+
async logout() {
|
|
304
|
+
if (this.mode === "apiKey") {
|
|
305
|
+
this.clearLocalAuth();
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
if (this.endpoints.logout)
|
|
309
|
+
try {
|
|
310
|
+
await fetch(`${this.apiBaseUrl}${this.endpoints.logout}`, {
|
|
311
|
+
...this.getRequestOptions(),
|
|
312
|
+
method: "POST",
|
|
313
|
+
headers: this.getAuthHeaders()
|
|
314
|
+
});
|
|
315
|
+
} catch (e) {
|
|
316
|
+
console.warn("Logout request failed:", e);
|
|
317
|
+
}
|
|
318
|
+
this.clearLocalAuth();
|
|
319
|
+
}
|
|
320
|
+
async refreshToken() {
|
|
321
|
+
if (this.mode === "apiKey")
|
|
322
|
+
return this.apiKey;
|
|
323
|
+
if (!this.refreshManager)
|
|
324
|
+
throw new Error("Token refresh not available in this mode");
|
|
325
|
+
const e = await this.refreshManager.refresh();
|
|
326
|
+
return this.currentToken = e, e;
|
|
327
|
+
}
|
|
328
|
+
async bootstrapSession() {
|
|
329
|
+
if (this.mode === "apiKey" || !this.useCookieAuth)
|
|
330
|
+
return !1;
|
|
331
|
+
try {
|
|
332
|
+
const e = `${this.apiBaseUrl}/auth/me`;
|
|
333
|
+
let t = await fetch(
|
|
334
|
+
e,
|
|
335
|
+
this.getRequestOptions({ method: "GET", headers: this.getAuthHeaders() })
|
|
336
|
+
), r = !1;
|
|
337
|
+
if (!t.ok && (this.currentToken || this.tokenManager.getTeamId()) && (t = await fetch(
|
|
338
|
+
e,
|
|
339
|
+
this.getRequestOptions({ method: "GET", headers: {} })
|
|
340
|
+
), r = t.ok), !t.ok && t.status === 401 && this.refreshManager)
|
|
341
|
+
try {
|
|
342
|
+
await this.refreshManager.refresh(), t = await fetch(
|
|
343
|
+
e,
|
|
344
|
+
this.getRequestOptions({ method: "GET", headers: this.getAuthHeaders() })
|
|
345
|
+
);
|
|
346
|
+
} catch {
|
|
347
|
+
}
|
|
348
|
+
if (!t.ok) return !1;
|
|
349
|
+
const s = await t.json();
|
|
350
|
+
this.currentUser = s, this.tokenManager.setUser(s);
|
|
351
|
+
const n = (s == null ? void 0 : s.default_team_id) || this.tokenManager.getTeamId() || null;
|
|
352
|
+
return n && (this.tokenManager.setTeamId(n), this.tokenManager.setTenantId((s == null ? void 0 : s.tenant_id) || n)), r && (this.tokenManager.setAccessToken(null), this.currentToken = null, s != null && s.default_team_id && this.tokenManager.setTeamId(s.default_team_id)), this.notifyListeners(), !0;
|
|
353
|
+
} catch {
|
|
354
|
+
return !1;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
setTenantId(e) {
|
|
358
|
+
this.tokenManager.setTenantId(e), this.notifyListeners();
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
class h extends Error {
|
|
362
|
+
/**
|
|
363
|
+
* @param {string} message - Error message
|
|
364
|
+
* @param {number} [status=0] - HTTP status code (0 for network errors)
|
|
365
|
+
* @param {Object|null} [detail=null] - Error detail from API response
|
|
366
|
+
*/
|
|
367
|
+
constructor(e, t = 0, r = null) {
|
|
368
|
+
super(e), this.name = "APIError", this.status = t, this.detail = r;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
class A {
|
|
372
|
+
/**
|
|
373
|
+
* @param {import('../auth/AuthCore.js').AuthCore} authCore
|
|
374
|
+
* @param {{ fetchFn?: typeof globalThis.fetch }} [options]
|
|
375
|
+
*/
|
|
376
|
+
constructor(e, { fetchFn: t } = {}) {
|
|
377
|
+
this.auth = e, this.baseURL = e.apiBaseUrl, this._customFetchFn = t || null;
|
|
378
|
+
}
|
|
379
|
+
get fetchFn() {
|
|
380
|
+
return this._customFetchFn || globalThis.fetch;
|
|
381
|
+
}
|
|
382
|
+
async request(e, t = {}) {
|
|
383
|
+
var a, c;
|
|
384
|
+
const r = `${this.baseURL}${e}`, s = {
|
|
385
|
+
"Content-Type": "application/json",
|
|
386
|
+
...this.auth.getAuthHeaders(t.headers)
|
|
387
|
+
}, n = this.auth.getRequestOptions({ ...t, headers: s });
|
|
388
|
+
try {
|
|
389
|
+
let o = await this.fetchFn(r, n);
|
|
390
|
+
if (o.status === 401 && !t.__isRetry)
|
|
391
|
+
try {
|
|
392
|
+
await this.auth.refreshToken();
|
|
393
|
+
const w = {
|
|
394
|
+
"Content-Type": "application/json",
|
|
395
|
+
...this.auth.getAuthHeaders(t.headers)
|
|
396
|
+
};
|
|
397
|
+
o = await this.fetchFn(
|
|
398
|
+
r,
|
|
399
|
+
this.auth.getRequestOptions({ ...n, headers: w, __isRetry: !0 })
|
|
400
|
+
);
|
|
401
|
+
} catch {
|
|
402
|
+
}
|
|
403
|
+
if (o.status === 401)
|
|
404
|
+
throw (c = (a = this.auth).clearLocalAuth) == null || c.call(a), new h("Authentication required", 401, "auth_expired");
|
|
405
|
+
if (o.status === 204)
|
|
406
|
+
return null;
|
|
407
|
+
if (!o.ok)
|
|
408
|
+
throw await this._handleError(o);
|
|
409
|
+
return await o.json();
|
|
410
|
+
} catch (o) {
|
|
411
|
+
throw o instanceof h ? o : new h(o.message, 0, "network_error");
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
async get(e, t = {}) {
|
|
415
|
+
return this.request(e, { ...t, method: "GET" });
|
|
416
|
+
}
|
|
417
|
+
async post(e, t, r = {}) {
|
|
418
|
+
return this.request(e, {
|
|
419
|
+
...r,
|
|
420
|
+
method: "POST",
|
|
421
|
+
body: JSON.stringify(t)
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
async put(e, t, r = {}) {
|
|
425
|
+
return this.request(e, {
|
|
426
|
+
...r,
|
|
427
|
+
method: "PUT",
|
|
428
|
+
body: JSON.stringify(t)
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
async patch(e, t, r = {}) {
|
|
432
|
+
return this.request(e, {
|
|
433
|
+
...r,
|
|
434
|
+
method: "PATCH",
|
|
435
|
+
body: JSON.stringify(t)
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
async delete(e, t = {}) {
|
|
439
|
+
return this.request(e, { ...t, method: "DELETE" });
|
|
440
|
+
}
|
|
441
|
+
/** @private */
|
|
442
|
+
async _handleError(e) {
|
|
443
|
+
var s, n;
|
|
444
|
+
let t;
|
|
445
|
+
const r = (n = (s = e.headers) == null ? void 0 : s.get) == null ? void 0 : n.call(s, "content-type");
|
|
446
|
+
try {
|
|
447
|
+
r != null && r.includes("application/json") ? t = await e.json() : t = { message: await e.text() };
|
|
448
|
+
} catch {
|
|
449
|
+
t = { message: `HTTP ${e.status}` };
|
|
450
|
+
}
|
|
451
|
+
return new h(
|
|
452
|
+
t.detail || t.message || `HTTP ${e.status}`,
|
|
453
|
+
e.status,
|
|
454
|
+
t
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
class R {
|
|
459
|
+
constructor(e) {
|
|
460
|
+
this.api = e;
|
|
461
|
+
}
|
|
462
|
+
async create({ content: e, memoryType: t = "semantic", metadata: r = null, usePipeline: s = !0, profileName: n = null }) {
|
|
463
|
+
return this.api.post("/memory/add", {
|
|
464
|
+
content: e,
|
|
465
|
+
memory_type: t,
|
|
466
|
+
metadata: r,
|
|
467
|
+
use_pipeline: s,
|
|
468
|
+
profile_name: n
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
async get(e) {
|
|
472
|
+
const t = await this.api.get(`/memory/${e}`);
|
|
473
|
+
return { ...t, id: t.item_id || t.id };
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Update a memory item (CORE-CRUD-UPDATE-1 contract).
|
|
477
|
+
*
|
|
478
|
+
* @param {string} id - Memory item ID
|
|
479
|
+
* @param {Object} updates - Update fields
|
|
480
|
+
* @param {string} [updates.content] - Convenience — replaces content
|
|
481
|
+
* @param {Object} [updates.metadata] - Convenience — deep-merges with existing metadata
|
|
482
|
+
* @param {Object} [updates.properties] - Advanced — direct node-property dict.
|
|
483
|
+
* When provided, takes precedence over content/metadata conveniences.
|
|
484
|
+
* @param {'merge'|'replace'} [updates.write_mode] - Node-property write semantics.
|
|
485
|
+
* 'merge' (default) overlays new properties; 'replace' replaces all
|
|
486
|
+
* (preserving memory_type and node_category).
|
|
487
|
+
*/
|
|
488
|
+
async update(e, t) {
|
|
489
|
+
return this.api.patch(`/memory/${e}`, t);
|
|
490
|
+
}
|
|
491
|
+
async delete(e) {
|
|
492
|
+
return this.api.delete(`/memory/${e}`);
|
|
493
|
+
}
|
|
494
|
+
async list({ limit: e = 50, offset: t = 0, type: r = null } = {}) {
|
|
495
|
+
let s = `/memory/list?limit=${e}&offset=${t}`;
|
|
496
|
+
return r && (s += `&memory_type=${r}`), this.api.get(s);
|
|
497
|
+
}
|
|
498
|
+
async search(e, { topK: t = 5, enableHybrid: r = !0, memoryType: s = null } = {}) {
|
|
499
|
+
const n = { query: e, top_k: t, enable_hybrid: r };
|
|
500
|
+
return s && (n.memory_type = s), this.api.post("/memory/search", n);
|
|
501
|
+
}
|
|
502
|
+
async getWorkingContext(e, t, { k: r = 20, maxTokens: s = null, strategy: n = null } = {}) {
|
|
503
|
+
const a = {
|
|
504
|
+
session_id: e,
|
|
505
|
+
query: t,
|
|
506
|
+
k: r
|
|
507
|
+
};
|
|
508
|
+
return s != null && (a.max_tokens = s), n != null && (a.strategy = n), this.api.post("/memory/context", a);
|
|
509
|
+
}
|
|
510
|
+
async searchAdvanced(e, { algorithm: t = "query_traversal", maxResults: r = 15, useSSG: s = !0 } = {}) {
|
|
511
|
+
return this.api.post("/memory/search/advanced", {
|
|
512
|
+
query: e,
|
|
513
|
+
algorithm: t,
|
|
514
|
+
max_results: r,
|
|
515
|
+
use_ssg: s
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
async ingest(e, { profileName: t = null, extractorName: r = "llm", context: s = {} } = {}) {
|
|
519
|
+
return this.api.post("/memory/ingest", {
|
|
520
|
+
content: e,
|
|
521
|
+
profile_name: t,
|
|
522
|
+
extractor_name: r,
|
|
523
|
+
context: s
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
async getLineage(e) {
|
|
527
|
+
return this.api.get(`/memory/${e}/lineage`);
|
|
528
|
+
}
|
|
529
|
+
async getLinks(e) {
|
|
530
|
+
return this.api.get(`/memory/${e}/links`);
|
|
531
|
+
}
|
|
532
|
+
async searchByMetadata(e, t, { memoryType: r = null } = {}) {
|
|
533
|
+
const s = new URLSearchParams({ metadata_key: e, metadata_value: t });
|
|
534
|
+
return r && s.append("memory_type", r), this.api.get(`/memory/by-metadata?${s}`);
|
|
535
|
+
}
|
|
536
|
+
async getNeighbors(e) {
|
|
537
|
+
return this.api.get(`/memory/${e}/neighbors`);
|
|
538
|
+
}
|
|
539
|
+
async getSummary() {
|
|
540
|
+
return this.api.get("/memory/summary");
|
|
541
|
+
}
|
|
542
|
+
async ingestConversation(e, {
|
|
543
|
+
sessionBoundaries: t = null,
|
|
544
|
+
conversationId: r = null,
|
|
545
|
+
sessionDates: s = null,
|
|
546
|
+
turnsPerChunk: n = 15,
|
|
547
|
+
maxChunkChars: a = 12e3,
|
|
548
|
+
maxConcurrent: c = 4
|
|
549
|
+
} = {}) {
|
|
550
|
+
const o = { turns: e, turns_per_chunk: n, max_chunk_chars: a, max_concurrent: c };
|
|
551
|
+
return t && (o.session_boundaries = t), r && (o.conversation_id = r), s && (o.session_dates = s), this.api.post("/memory/ingest/conversation", o);
|
|
552
|
+
}
|
|
553
|
+
async ingestDocument(e, { title: t = null, source: r = null, chunkStrategy: s = null } = {}) {
|
|
554
|
+
const n = { content: e };
|
|
555
|
+
return t && (n.title = t), r && (n.source = r), s && (n.chunk_strategy = s), this.api.post("/memory/ingest/document", n);
|
|
556
|
+
}
|
|
557
|
+
async codeIndex(e, { repo: t = null, commit: r = null } = {}) {
|
|
558
|
+
const s = { path: e };
|
|
559
|
+
return t && (s.repo = t), r && (s.commit = r), this.api.post("/memory/code/index", s);
|
|
560
|
+
}
|
|
561
|
+
async codeSearch(e, { entityType: t = null, repo: r = null, limit: s = 20, semantic: n = !1 } = {}) {
|
|
562
|
+
const a = new URLSearchParams({ query: e, limit: s, semantic: n });
|
|
563
|
+
return t && a.append("entity_type", t), r && a.append("repo", r), this.api.get(`/memory/code/search?${a}`);
|
|
564
|
+
}
|
|
565
|
+
async codeContext(e, { repo: t = null } = {}) {
|
|
566
|
+
const r = new URLSearchParams({ entity_name: e });
|
|
567
|
+
return t && r.append("repo", t), this.api.get(`/memory/code/context?${r}`);
|
|
568
|
+
}
|
|
569
|
+
async codeDeadCode(e) {
|
|
570
|
+
return this.api.get(`/memory/code/dead-code?repo=${encodeURIComponent(e)}`);
|
|
571
|
+
}
|
|
572
|
+
async codeDependencies(e, { direction: t = "both", repo: r = null } = {}) {
|
|
573
|
+
const s = new URLSearchParams({ entity_name: e, direction: t });
|
|
574
|
+
return r && s.append("repo", r), this.api.get(`/memory/code/dependencies?${s}`);
|
|
575
|
+
}
|
|
576
|
+
async getPlan(e) {
|
|
577
|
+
return this.api.get(`/memory/plans/${e}`);
|
|
578
|
+
}
|
|
579
|
+
async updatePlanTask(e, { taskId: t, status: r }) {
|
|
580
|
+
return this.api.patch(`/memory/plans/${e}/task`, { task_id: t, status: r });
|
|
581
|
+
}
|
|
582
|
+
async completePlan(e, { graduate: t = !1 } = {}) {
|
|
583
|
+
return this.api.post(`/memory/plans/${e}/complete`, { graduate: t });
|
|
584
|
+
}
|
|
585
|
+
async failPlan(e, t) {
|
|
586
|
+
return this.api.post(`/memory/plans/${e}/fail`, { reason: t });
|
|
587
|
+
}
|
|
588
|
+
async link(e, t, r = "RELATED") {
|
|
589
|
+
return this.api.post("/memory/link", {
|
|
590
|
+
source_id: e,
|
|
591
|
+
target_id: t,
|
|
592
|
+
link_type: r
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
async enrich(e, t = []) {
|
|
596
|
+
return this.api.post(`/memory/${e}/enrich`, {
|
|
597
|
+
item_id: e,
|
|
598
|
+
routines: t
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
async personalize(e = {}, t = {}) {
|
|
602
|
+
return this.api.post("/memory/personalize", { traits: e, preferences: t });
|
|
603
|
+
}
|
|
604
|
+
async feedback(e, t = "semantic") {
|
|
605
|
+
return this.api.post("/memory/feedback", { feedback: e, memory_type: t });
|
|
606
|
+
}
|
|
607
|
+
async ground(e, t, r = null) {
|
|
608
|
+
return this.api.post(`/memory/${e}/ground`, {
|
|
609
|
+
item_id: e,
|
|
610
|
+
source_url: t,
|
|
611
|
+
validation: r
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
async clearAll(e = !1) {
|
|
615
|
+
return this.api.delete(`/memory/clear-all?nuclear=${e}`);
|
|
616
|
+
}
|
|
617
|
+
// --- Temporal ---
|
|
618
|
+
async getHistory(e, { startTime: t = null, endTime: r = null, limit: s = 100 } = {}) {
|
|
619
|
+
let n = `/memory/temporal/${e}/history?limit=${s}`;
|
|
620
|
+
return t && (n += `&start_time=${t}`), r && (n += `&end_time=${r}`), this.api.get(n);
|
|
621
|
+
}
|
|
622
|
+
async timeTravel(e, { query: t = null, limit: r = 100 } = {}) {
|
|
623
|
+
let s = `/memory/temporal/at/${e}?limit=${r}`;
|
|
624
|
+
return t && (s += `&query=${encodeURIComponent(t)}`), this.api.get(s);
|
|
625
|
+
}
|
|
626
|
+
async getItemAtTime(e, t) {
|
|
627
|
+
return this.api.get(`/memory/temporal/${e}/at/${t}`);
|
|
628
|
+
}
|
|
629
|
+
async getChanges(e, { since: t = null, until: r = null, changeType: s = null } = {}) {
|
|
630
|
+
let n = `/memory/temporal/${e}/changes`;
|
|
631
|
+
const a = [];
|
|
632
|
+
return t && a.push(`since=${t}`), r && a.push(`until=${r}`), s && a.push(`change_type=${s}`), a.length && (n += `?${a.join("&")}`), this.api.get(n);
|
|
633
|
+
}
|
|
634
|
+
async compareVersions(e, t, r) {
|
|
635
|
+
return this.api.post(`/memory/temporal/${e}/compare?v1=${t}&v2=${r}`);
|
|
636
|
+
}
|
|
637
|
+
async rollback(e, { toVersion: t = null, toTime: r = null } = {}) {
|
|
638
|
+
let s = `/memory/temporal/${e}/rollback`;
|
|
639
|
+
const n = [];
|
|
640
|
+
return t !== null && n.push(`to_version=${t}`), r && n.push(`to_time=${r}`), n.length && (s += `?${n.join("&")}`), this.api.post(s);
|
|
641
|
+
}
|
|
642
|
+
// --- Clustering ---
|
|
643
|
+
async runClustering(e = 0.1, t = !1) {
|
|
644
|
+
return this.api.post(`/memory/clustering/run?distance_threshold=${e}&dry_run=${t}`);
|
|
645
|
+
}
|
|
646
|
+
async getClusteringStats() {
|
|
647
|
+
return this.api.get("/memory/clustering/stats");
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
class U {
|
|
651
|
+
constructor(e) {
|
|
652
|
+
this.api = e;
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
* Create a new decision with provenance tracking.
|
|
656
|
+
* @param {Object} params
|
|
657
|
+
* @param {string} params.content
|
|
658
|
+
* @param {string} [params.decisionType='inference']
|
|
659
|
+
* @param {number} [params.confidence=0.8]
|
|
660
|
+
* @param {string} [params.sourceTraceId]
|
|
661
|
+
* @param {string} [params.sourceSessionId]
|
|
662
|
+
* @param {string[]} [params.evidenceIds]
|
|
663
|
+
* @param {string} [params.domain]
|
|
664
|
+
* @param {string[]} [params.tags]
|
|
665
|
+
*/
|
|
666
|
+
async create({
|
|
667
|
+
content: e,
|
|
668
|
+
decisionType: t = "inference",
|
|
669
|
+
confidence: r = 0.8,
|
|
670
|
+
sourceTraceId: s = null,
|
|
671
|
+
sourceSessionId: n = null,
|
|
672
|
+
evidenceIds: a = null,
|
|
673
|
+
domain: c = null,
|
|
674
|
+
tags: o = null
|
|
675
|
+
}) {
|
|
676
|
+
return this.api.post("/memory/decisions/create", {
|
|
677
|
+
content: e,
|
|
678
|
+
decision_type: t,
|
|
679
|
+
confidence: r,
|
|
680
|
+
source_trace_id: s,
|
|
681
|
+
source_session_id: n,
|
|
682
|
+
evidence_ids: a,
|
|
683
|
+
domain: c,
|
|
684
|
+
tags: o
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* List active decisions with optional filters.
|
|
689
|
+
* @param {Object} [params] - Query parameters (domain, decision_type, min_confidence, limit)
|
|
690
|
+
*/
|
|
691
|
+
async list(e = {}) {
|
|
692
|
+
const t = new URLSearchParams(e).toString();
|
|
693
|
+
return this.api.get(`/memory/decisions${t ? "?" + t : ""}`);
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* Search for active decisions related to a topic.
|
|
697
|
+
* @param {string} topic
|
|
698
|
+
* @param {number} [limit=20]
|
|
699
|
+
*/
|
|
700
|
+
async search(e, t = 20) {
|
|
701
|
+
return this.api.get(`/memory/decisions/search?topic=${encodeURIComponent(e)}&limit=${t}`);
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* List pending decisions (awaiting more data via residuation).
|
|
705
|
+
* @param {number} [limit=50]
|
|
706
|
+
*/
|
|
707
|
+
async listPending(e = 50) {
|
|
708
|
+
return this.api.get(`/memory/decisions/pending?limit=${e}`);
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* Retrieve a decision by ID.
|
|
712
|
+
* @param {string} decisionId
|
|
713
|
+
*/
|
|
714
|
+
async get(e) {
|
|
715
|
+
return this.api.get(`/memory/decisions/${e}`);
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* Replace a decision with a new one, marking the old as superseded.
|
|
719
|
+
* @param {string} decisionId
|
|
720
|
+
* @param {Object} data
|
|
721
|
+
* @param {string} data.new_content
|
|
722
|
+
* @param {string} [data.new_decision_type='inference']
|
|
723
|
+
* @param {number} [data.new_confidence=0.8]
|
|
724
|
+
* @param {string} data.reason
|
|
725
|
+
*/
|
|
726
|
+
async supersede(e, t = {}) {
|
|
727
|
+
return this.api.post(`/memory/decisions/${e}/supersede`, t);
|
|
728
|
+
}
|
|
729
|
+
/**
|
|
730
|
+
* Retract a decision (mark as no longer valid).
|
|
731
|
+
* @param {string} decisionId
|
|
732
|
+
* @param {string} reason
|
|
733
|
+
*/
|
|
734
|
+
async retract(e, t) {
|
|
735
|
+
return this.api.post(`/memory/decisions/${e}/retract`, {
|
|
736
|
+
reason: t
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* Record supporting evidence for a decision.
|
|
741
|
+
* @param {string} decisionId
|
|
742
|
+
* @param {string} evidenceId
|
|
743
|
+
*/
|
|
744
|
+
async reinforce(e, t) {
|
|
745
|
+
return this.api.post(`/memory/decisions/${e}/reinforce`, {
|
|
746
|
+
evidence_id: t
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
/**
|
|
750
|
+
* Record contradicting evidence against a decision.
|
|
751
|
+
* @param {string} decisionId
|
|
752
|
+
* @param {string} evidenceId
|
|
753
|
+
*/
|
|
754
|
+
async contradict(e, t) {
|
|
755
|
+
return this.api.post(`/memory/decisions/${e}/contradict`, {
|
|
756
|
+
evidence_id: t
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Get full provenance chain for a decision.
|
|
761
|
+
* @param {string} decisionId
|
|
762
|
+
*/
|
|
763
|
+
async getProvenance(e) {
|
|
764
|
+
return this.api.get(`/memory/decisions/${e}/provenance`);
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* Trace causal chain from a decision.
|
|
768
|
+
* @param {string} decisionId
|
|
769
|
+
* @param {Object} [options]
|
|
770
|
+
* @param {string} [options.direction='both'] - causes|effects|both
|
|
771
|
+
* @param {number} [options.maxDepth=3]
|
|
772
|
+
*/
|
|
773
|
+
async getCausalChain(e, { direction: t = "both", maxDepth: r = 3 } = {}) {
|
|
774
|
+
return this.api.get(`/memory/decisions/${e}/causal-chain?direction=${t}&max_depth=${r}`);
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* Find existing decisions that may conflict with this one.
|
|
778
|
+
* @param {string} decisionId
|
|
779
|
+
*/
|
|
780
|
+
async findConflicts(e) {
|
|
781
|
+
return this.api.post(`/memory/decisions/${e}/conflicts`);
|
|
782
|
+
}
|
|
783
|
+
// --- Legacy reasoning proxies (kept for backward compatibility) ---
|
|
784
|
+
/**
|
|
785
|
+
* Build an auditable proof tree for a decision.
|
|
786
|
+
* @param {string} decisionId
|
|
787
|
+
* @param {number} [maxDepth=5]
|
|
788
|
+
*/
|
|
789
|
+
async getProofTree(e, t = 5) {
|
|
790
|
+
return this.api.post("/memory/reasoning/proof", {
|
|
791
|
+
decision_id: e,
|
|
792
|
+
max_depth: t
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Get multi-dimensional confidence score for a decision.
|
|
797
|
+
* @param {string} decisionId
|
|
798
|
+
*/
|
|
799
|
+
async getFuzzyConfidence(e) {
|
|
800
|
+
return this.api.post("/memory/reasoning/fuzzy-confidence", {
|
|
801
|
+
decision_id: e
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
class C {
|
|
806
|
+
constructor(e) {
|
|
807
|
+
this.api = e;
|
|
808
|
+
}
|
|
809
|
+
async getNeighbors(e) {
|
|
810
|
+
return this.api.get(`/memory/${e}/neighbors`);
|
|
811
|
+
}
|
|
812
|
+
async addEdge(e, t, r, s = {}) {
|
|
813
|
+
return this.api.post("/memory/edge", {
|
|
814
|
+
source_id: e,
|
|
815
|
+
target_id: t,
|
|
816
|
+
relation_type: r,
|
|
817
|
+
properties: s
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
async getHealth() {
|
|
821
|
+
return this.api.get("/memory/graph/health");
|
|
822
|
+
}
|
|
823
|
+
async getInferenceRules() {
|
|
824
|
+
return this.api.get("/memory/validation/inference/rules");
|
|
825
|
+
}
|
|
826
|
+
async runInference(e = []) {
|
|
827
|
+
return this.api.post("/memory/validation/inference", {
|
|
828
|
+
rule_names: e
|
|
829
|
+
});
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* Find the shortest path between two graph nodes.
|
|
833
|
+
* @param {string} startId
|
|
834
|
+
* @param {string} endId
|
|
835
|
+
* @param {number} [maxHops=5]
|
|
836
|
+
*/
|
|
837
|
+
async findShortestPath(e, t, r = 5) {
|
|
838
|
+
return this.api.get(`/memory/graph/path?start_id=${encodeURIComponent(e)}&end_id=${encodeURIComponent(t)}&max_hops=${r}`);
|
|
839
|
+
}
|
|
840
|
+
/**
|
|
841
|
+
* Fetch the full knowledge graph.
|
|
842
|
+
* @param {number} [limit] - Optional client hint; backend enforces hard cap.
|
|
843
|
+
*/
|
|
844
|
+
async getFullGraph(e) {
|
|
845
|
+
return e == null ? this.api.get("/memory/graph/full") : this.api.get(`/memory/graph/full?limit=${encodeURIComponent(e)}`);
|
|
846
|
+
}
|
|
847
|
+
/**
|
|
848
|
+
* Fetch edges for multiple node IDs in bulk.
|
|
849
|
+
* @param {string[]} nodeIds
|
|
850
|
+
*/
|
|
851
|
+
async getEdgesBulk(e) {
|
|
852
|
+
return this.api.post("/memory/graph/edges", { node_ids: e });
|
|
853
|
+
}
|
|
854
|
+
/**
|
|
855
|
+
* Get Wikipedia grounding status for an entity node.
|
|
856
|
+
* @param {string} nodeId
|
|
857
|
+
*/
|
|
858
|
+
async getGroundingStatus(e) {
|
|
859
|
+
return this.api.get(`/memory/graph/nodes/${encodeURIComponent(e)}/grounding`);
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* Update an entity node's label or type. Triggers ontology self-learning.
|
|
863
|
+
* @param {string} nodeId
|
|
864
|
+
* @param {Object} updates - { label, entity_type }
|
|
865
|
+
*/
|
|
866
|
+
async updateEntityNode(e, t) {
|
|
867
|
+
return this.api.patch(`/memory/graph/nodes/${encodeURIComponent(e)}`, t);
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* Remove Wikipedia grounding from an entity node.
|
|
871
|
+
* @param {string} nodeId
|
|
872
|
+
*/
|
|
873
|
+
async removeGrounding(e) {
|
|
874
|
+
return this.api.delete(`/memory/graph/nodes/${encodeURIComponent(e)}/grounding`);
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
877
|
+
* Delete an entity graph node and all its edges.
|
|
878
|
+
* @param {string} nodeId
|
|
879
|
+
*/
|
|
880
|
+
async deleteEntityNode(e) {
|
|
881
|
+
return this.api.delete(`/memory/graph/nodes/${encodeURIComponent(e)}`);
|
|
882
|
+
}
|
|
883
|
+
/**
|
|
884
|
+
* Get links for a memory item.
|
|
885
|
+
* @param {string} itemId
|
|
886
|
+
*/
|
|
887
|
+
async getLinks(e) {
|
|
888
|
+
return this.api.get(`/memory/${encodeURIComponent(e)}/links`);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
class P {
|
|
892
|
+
constructor(e) {
|
|
893
|
+
this.api = e;
|
|
894
|
+
}
|
|
895
|
+
async list() {
|
|
896
|
+
return this.api.get("/memory/teams");
|
|
897
|
+
}
|
|
898
|
+
async create({ name: e, description: t = null, dataClassification: r = "internal", costCenter: s = null }) {
|
|
899
|
+
return this.api.post("/memory/teams", {
|
|
900
|
+
name: e,
|
|
901
|
+
description: t,
|
|
902
|
+
data_classification: r,
|
|
903
|
+
cost_center: s
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
async get(e) {
|
|
907
|
+
return this.api.get(`/memory/teams/${e}`);
|
|
908
|
+
}
|
|
909
|
+
async update(e, t) {
|
|
910
|
+
return this.api.patch(`/memory/teams/${e}`, t);
|
|
911
|
+
}
|
|
912
|
+
async delete(e) {
|
|
913
|
+
return this.api.delete(`/memory/teams/${e}`);
|
|
914
|
+
}
|
|
915
|
+
async getMembers(e) {
|
|
916
|
+
return this.api.get(`/memory/teams/${e}/members`);
|
|
917
|
+
}
|
|
918
|
+
async addMember(e, t, r = "member") {
|
|
919
|
+
return this.api.post(`/memory/teams/${e}/members`, {
|
|
920
|
+
user_id: t,
|
|
921
|
+
role: r
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
async updateMember(e, t, r) {
|
|
925
|
+
return this.api.patch(`/memory/teams/${e}/members/${t}`, { role: r });
|
|
926
|
+
}
|
|
927
|
+
async removeMember(e, t) {
|
|
928
|
+
return this.api.delete(`/memory/teams/${e}/members/${t}`);
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
class M {
|
|
932
|
+
constructor(e) {
|
|
933
|
+
this.api = e;
|
|
934
|
+
}
|
|
935
|
+
async list() {
|
|
936
|
+
return this.api.get("/memory/pipeline/profiles");
|
|
937
|
+
}
|
|
938
|
+
async get(e) {
|
|
939
|
+
return this.api.get(`/memory/pipeline/profiles/${e}`);
|
|
940
|
+
}
|
|
941
|
+
async getLLMKeys() {
|
|
942
|
+
return this.api.get("/auth/llm-keys");
|
|
943
|
+
}
|
|
944
|
+
async updateLLMKeys(e) {
|
|
945
|
+
return this.api.patch("/auth/llm-keys", e);
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
class L {
|
|
949
|
+
constructor(e) {
|
|
950
|
+
this.api = e;
|
|
951
|
+
}
|
|
952
|
+
async getCurrent() {
|
|
953
|
+
return this.api.get("/subscription/current");
|
|
954
|
+
}
|
|
955
|
+
async upgrade(e, t = null) {
|
|
956
|
+
return this.api.post("/subscription/upgrade", {
|
|
957
|
+
tier: e,
|
|
958
|
+
payment_method_id: t
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
async cancel(e = !1) {
|
|
962
|
+
return this.api.post(`/subscription/cancel?immediately=${e}`);
|
|
963
|
+
}
|
|
964
|
+
async createPortalSession() {
|
|
965
|
+
return this.api.post("/subscription/portal");
|
|
966
|
+
}
|
|
967
|
+
async createCheckoutSession(e, t = "monthly") {
|
|
968
|
+
return this.api.post("/subscription/checkout", {
|
|
969
|
+
tier: e,
|
|
970
|
+
billing_period: t
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
class z {
|
|
975
|
+
constructor(e) {
|
|
976
|
+
this.api = e;
|
|
977
|
+
}
|
|
978
|
+
async getCurrentUser() {
|
|
979
|
+
return this.api.get("/auth/me");
|
|
980
|
+
}
|
|
981
|
+
async createAPIKey(e, t, r = null) {
|
|
982
|
+
return this.api.post("/memory/api-keys", {
|
|
983
|
+
name: e,
|
|
984
|
+
scopes: t,
|
|
985
|
+
expires_in_days: r
|
|
986
|
+
});
|
|
987
|
+
}
|
|
988
|
+
async listAPIKeys() {
|
|
989
|
+
return this.api.get("/memory/api-keys");
|
|
990
|
+
}
|
|
991
|
+
async revokeAPIKey(e) {
|
|
992
|
+
return this.api.delete(`/memory/api-keys/${e}`);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
class E {
|
|
996
|
+
constructor(e) {
|
|
997
|
+
this.api = e;
|
|
998
|
+
}
|
|
999
|
+
async list() {
|
|
1000
|
+
return this.api.get("/memory/agents");
|
|
1001
|
+
}
|
|
1002
|
+
async create({ name: e, description: t = null, agentConfig: r = {}, roles: s = ["user"] }) {
|
|
1003
|
+
return this.api.post("/memory/agents", {
|
|
1004
|
+
name: e,
|
|
1005
|
+
description: t,
|
|
1006
|
+
agent_config: r,
|
|
1007
|
+
roles: s
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
async get(e) {
|
|
1011
|
+
return this.api.get(`/memory/agents/${e}`);
|
|
1012
|
+
}
|
|
1013
|
+
async delete(e) {
|
|
1014
|
+
return this.api.delete(`/memory/agents/${e}`);
|
|
1015
|
+
}
|
|
1016
|
+
async getRecallProfile(e) {
|
|
1017
|
+
return this.api.get(`/memory/agents/${e}/recall-profile`);
|
|
1018
|
+
}
|
|
1019
|
+
async setRecallProfile(e, t) {
|
|
1020
|
+
return this.api.put(`/memory/agents/${e}/recall-profile`, { recall_profile: t });
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
class x {
|
|
1024
|
+
constructor(e) {
|
|
1025
|
+
this.api = e;
|
|
1026
|
+
}
|
|
1027
|
+
async getDashboard() {
|
|
1028
|
+
return this.api.get("/usage/dashboard");
|
|
1029
|
+
}
|
|
1030
|
+
async getCurrent() {
|
|
1031
|
+
return this.api.get("/usage/current");
|
|
1032
|
+
}
|
|
1033
|
+
async getTiers() {
|
|
1034
|
+
return this.api.get("/usage/tiers");
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
class O {
|
|
1038
|
+
constructor(e) {
|
|
1039
|
+
this.api = e;
|
|
1040
|
+
}
|
|
1041
|
+
async getHealth() {
|
|
1042
|
+
return this.api.get("/memory/health");
|
|
1043
|
+
}
|
|
1044
|
+
async getReflection() {
|
|
1045
|
+
return this.api.get("/memory/reflect");
|
|
1046
|
+
}
|
|
1047
|
+
async getMaintenanceStatus() {
|
|
1048
|
+
return this.api.get("/memory/maintenance/status");
|
|
1049
|
+
}
|
|
1050
|
+
async getPlugins() {
|
|
1051
|
+
return this.api.get("/memory/plugins");
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
class q {
|
|
1055
|
+
constructor(e) {
|
|
1056
|
+
this.api = e;
|
|
1057
|
+
}
|
|
1058
|
+
/**
|
|
1059
|
+
* Get aggregated token usage history for the current workspace.
|
|
1060
|
+
* @param {Object} params - Query parameters
|
|
1061
|
+
* @param {string} [params.start_date] - ISO date string (inclusive)
|
|
1062
|
+
* @param {string} [params.end_date] - ISO date string (inclusive)
|
|
1063
|
+
* @param {string} [params.group_by] - Group by: "stage" | "profile" | "day"
|
|
1064
|
+
* @param {number} [params.limit=100] - Max records (1-1000)
|
|
1065
|
+
*/
|
|
1066
|
+
async getUsage(e = {}) {
|
|
1067
|
+
const t = new URLSearchParams(e).toString();
|
|
1068
|
+
return this.api.get(`/memory/token-usage${t ? "?" + t : ""}`);
|
|
1069
|
+
}
|
|
1070
|
+
/**
|
|
1071
|
+
* Get real-time token usage: cache stats + last 10 pipeline runs.
|
|
1072
|
+
*/
|
|
1073
|
+
async getCurrent() {
|
|
1074
|
+
return this.api.get("/memory/token-usage/current");
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
class F {
|
|
1078
|
+
constructor(e) {
|
|
1079
|
+
this.api = e;
|
|
1080
|
+
}
|
|
1081
|
+
// === VERSION HISTORY ===
|
|
1082
|
+
/**
|
|
1083
|
+
* Get complete version history of a memory item.
|
|
1084
|
+
* @param {string} itemId
|
|
1085
|
+
* @param {Object} [options]
|
|
1086
|
+
* @param {string} [options.startTime] - ISO start time
|
|
1087
|
+
* @param {string} [options.endTime] - ISO end time
|
|
1088
|
+
* @param {number} [options.limit=100]
|
|
1089
|
+
*/
|
|
1090
|
+
async getHistory(e, { startTime: t = null, endTime: r = null, limit: s = 100 } = {}) {
|
|
1091
|
+
let n = `/memory/temporal/${e}/history?limit=${s}`;
|
|
1092
|
+
return t && (n += `&start_time=${t}`), r && (n += `&end_time=${r}`), this.api.get(n);
|
|
1093
|
+
}
|
|
1094
|
+
// === TIME-TRAVEL QUERIES ===
|
|
1095
|
+
/**
|
|
1096
|
+
* Time-travel query - get state at specific time.
|
|
1097
|
+
* @param {string} timestamp - ISO timestamp
|
|
1098
|
+
* @param {Object} [options]
|
|
1099
|
+
* @param {string} [options.query]
|
|
1100
|
+
* @param {number} [options.limit=100]
|
|
1101
|
+
*/
|
|
1102
|
+
async timeTravel(e, { query: t = null, limit: r = 100 } = {}) {
|
|
1103
|
+
let s = `/memory/temporal/at/${e}?limit=${r}`;
|
|
1104
|
+
return t && (s += `&query=${encodeURIComponent(t)}`), this.api.get(s);
|
|
1105
|
+
}
|
|
1106
|
+
/**
|
|
1107
|
+
* Get specific item as it existed at timestamp.
|
|
1108
|
+
* @param {string} itemId
|
|
1109
|
+
* @param {string} timestamp - ISO timestamp
|
|
1110
|
+
*/
|
|
1111
|
+
async getItemAtTime(e, t) {
|
|
1112
|
+
return this.api.get(`/memory/temporal/${e}/at/${t}`);
|
|
1113
|
+
}
|
|
1114
|
+
// === CHANGE TRACKING ===
|
|
1115
|
+
/**
|
|
1116
|
+
* Get all changes to an item in time range.
|
|
1117
|
+
* @param {string} itemId
|
|
1118
|
+
* @param {Object} [options]
|
|
1119
|
+
* @param {string} [options.since]
|
|
1120
|
+
* @param {string} [options.until]
|
|
1121
|
+
* @param {string} [options.changeType]
|
|
1122
|
+
*/
|
|
1123
|
+
async getChanges(e, { since: t = null, until: r = null, changeType: s = null } = {}) {
|
|
1124
|
+
let n = `/memory/temporal/${e}/changes`;
|
|
1125
|
+
const a = [];
|
|
1126
|
+
return t && a.push(`since=${t}`), r && a.push(`until=${r}`), s && a.push(`change_type=${s}`), a.length && (n += `?${a.join("&")}`), this.api.get(n);
|
|
1127
|
+
}
|
|
1128
|
+
// === VERSION COMPARISON ===
|
|
1129
|
+
/**
|
|
1130
|
+
* Compare two versions of an item.
|
|
1131
|
+
* @param {string} itemId
|
|
1132
|
+
* @param {number} v1
|
|
1133
|
+
* @param {number} v2
|
|
1134
|
+
*/
|
|
1135
|
+
async compareVersions(e, t, r) {
|
|
1136
|
+
return this.api.post(`/memory/temporal/${e}/compare?v1=${t}&v2=${r}`);
|
|
1137
|
+
}
|
|
1138
|
+
// === ROLLBACK ===
|
|
1139
|
+
/**
|
|
1140
|
+
* Rollback item to previous version or timestamp.
|
|
1141
|
+
* @param {string} itemId
|
|
1142
|
+
* @param {Object} [options]
|
|
1143
|
+
* @param {number} [options.toVersion]
|
|
1144
|
+
* @param {string} [options.toTime]
|
|
1145
|
+
*/
|
|
1146
|
+
async rollback(e, { toVersion: t = null, toTime: r = null } = {}) {
|
|
1147
|
+
let s = `/memory/temporal/${e}/rollback`;
|
|
1148
|
+
const n = [];
|
|
1149
|
+
return t !== null && n.push(`to_version=${t}`), r && n.push(`to_time=${r}`), n.length && (s += `?${n.join("&")}`), this.api.post(s);
|
|
1150
|
+
}
|
|
1151
|
+
// === AUDIT TRAIL ===
|
|
1152
|
+
/**
|
|
1153
|
+
* Get complete audit trail for an item.
|
|
1154
|
+
* @param {string} itemId
|
|
1155
|
+
* @param {Object} [options]
|
|
1156
|
+
* @param {string} [options.changeType]
|
|
1157
|
+
* @param {string} [options.userId]
|
|
1158
|
+
* @param {string} [options.startTime]
|
|
1159
|
+
* @param {string} [options.endTime]
|
|
1160
|
+
*/
|
|
1161
|
+
async getAuditTrail(e, { changeType: t = null, userId: r = null, startTime: s = null, endTime: n = null } = {}) {
|
|
1162
|
+
let a = `/memory/temporal/${e}/audit`;
|
|
1163
|
+
const c = [];
|
|
1164
|
+
return t && c.push(`change_type=${t}`), r && c.push(`user_id=${r}`), s && c.push(`start_time=${s}`), n && c.push(`end_time=${n}`), c.length && (a += `?${c.join("&")}`), this.api.get(a);
|
|
1165
|
+
}
|
|
1166
|
+
// === TEMPORAL SEARCH ===
|
|
1167
|
+
/**
|
|
1168
|
+
* Search memories that existed during time range.
|
|
1169
|
+
* @param {string} query
|
|
1170
|
+
* @param {string} startTime
|
|
1171
|
+
* @param {string} endTime
|
|
1172
|
+
* @param {number} [limit=100]
|
|
1173
|
+
*/
|
|
1174
|
+
async searchDuringRange(e, t, r, s = 100) {
|
|
1175
|
+
const n = new URLSearchParams({
|
|
1176
|
+
query: e,
|
|
1177
|
+
start_time: t,
|
|
1178
|
+
end_time: r,
|
|
1179
|
+
limit: String(s)
|
|
1180
|
+
}).toString();
|
|
1181
|
+
return this.api.get(`/memory/temporal/search/during?${n}`);
|
|
1182
|
+
}
|
|
1183
|
+
// === COMPLIANCE REPORTING ===
|
|
1184
|
+
/**
|
|
1185
|
+
* Generate compliance report (HIPAA, GDPR, SOC2).
|
|
1186
|
+
* @param {string} startDate
|
|
1187
|
+
* @param {string} endDate
|
|
1188
|
+
* @param {Object} [options]
|
|
1189
|
+
* @param {string} [options.reportType='HIPAA']
|
|
1190
|
+
* @param {string[]} [options.itemIds]
|
|
1191
|
+
*/
|
|
1192
|
+
async complianceReport(e, t, { reportType: r = "HIPAA", itemIds: s = null } = {}) {
|
|
1193
|
+
let n = `/memory/temporal/compliance/report?start_date=${e}&end_date=${t}&report_type=${r}`;
|
|
1194
|
+
if (s && s.length)
|
|
1195
|
+
for (const a of s)
|
|
1196
|
+
n += `&item_ids=${encodeURIComponent(a)}`;
|
|
1197
|
+
return this.api.get(n);
|
|
1198
|
+
}
|
|
1199
|
+
// === TEMPORAL RELATIONSHIPS ===
|
|
1200
|
+
/**
|
|
1201
|
+
* Get history of a relationship.
|
|
1202
|
+
* @param {string} relId
|
|
1203
|
+
*/
|
|
1204
|
+
async getRelationshipHistory(e) {
|
|
1205
|
+
return this.api.get(`/memory/temporal/relationships/${e}/history`);
|
|
1206
|
+
}
|
|
1207
|
+
/**
|
|
1208
|
+
* Get all relationships that existed at specific time.
|
|
1209
|
+
* @param {string} timestamp
|
|
1210
|
+
* @param {number} [limit=100]
|
|
1211
|
+
*/
|
|
1212
|
+
async getRelationshipsAtTime(e, t = 100) {
|
|
1213
|
+
return this.api.get(`/memory/temporal/relationships/at/${e}?limit=${t}`);
|
|
1214
|
+
}
|
|
1215
|
+
/**
|
|
1216
|
+
* Get valid time periods for a relationship.
|
|
1217
|
+
* @param {string} relId
|
|
1218
|
+
*/
|
|
1219
|
+
async getRelationshipValidPeriods(e) {
|
|
1220
|
+
return this.api.get(`/memory/temporal/relationships/${e}/valid-periods`);
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
class H {
|
|
1224
|
+
constructor(e) {
|
|
1225
|
+
this.api = e;
|
|
1226
|
+
}
|
|
1227
|
+
/**
|
|
1228
|
+
* Run governance analysis.
|
|
1229
|
+
* @param {Object} [options]
|
|
1230
|
+
* @param {string} [options.query='*']
|
|
1231
|
+
* @param {number} [options.topK=100]
|
|
1232
|
+
* @param {Object[]} [options.memoryItems] - Direct items to analyze
|
|
1233
|
+
*/
|
|
1234
|
+
async runAnalysis({ query: e = "*", topK: t = 100, memoryItems: r = [] } = {}) {
|
|
1235
|
+
return this.api.post("/memory/governance/run-analysis", {
|
|
1236
|
+
query: e,
|
|
1237
|
+
top_k: t,
|
|
1238
|
+
memory_items: r
|
|
1239
|
+
});
|
|
1240
|
+
}
|
|
1241
|
+
/**
|
|
1242
|
+
* List violations available for review.
|
|
1243
|
+
* @param {Object} [options]
|
|
1244
|
+
* @param {string} [options.severity] - Filter: low|medium|high|critical
|
|
1245
|
+
* @param {boolean} [options.autoFixableOnly=false]
|
|
1246
|
+
*/
|
|
1247
|
+
async listViolations({ severity: e = null, autoFixableOnly: t = !1 } = {}) {
|
|
1248
|
+
const r = [];
|
|
1249
|
+
e && r.push(`severity=${e}`), t && r.push("auto_fixable_only=true");
|
|
1250
|
+
const s = r.length ? `?${r.join("&")}` : "";
|
|
1251
|
+
return this.api.get(`/memory/governance/violations${s}`);
|
|
1252
|
+
}
|
|
1253
|
+
/**
|
|
1254
|
+
* Get a specific violation by ID.
|
|
1255
|
+
* @param {string} violationId
|
|
1256
|
+
*/
|
|
1257
|
+
async getViolation(e) {
|
|
1258
|
+
return this.api.get(`/memory/governance/violations/${e}`);
|
|
1259
|
+
}
|
|
1260
|
+
/**
|
|
1261
|
+
* Apply a governance decision for a violation.
|
|
1262
|
+
* @param {Object} params
|
|
1263
|
+
* @param {string} params.violationId
|
|
1264
|
+
* @param {string} [params.action='approve'] - approve|reject|evolve_ontology|fix_data|ignore|review_later
|
|
1265
|
+
* @param {string} [params.rationale='']
|
|
1266
|
+
* @param {string} [params.decidedBy='human']
|
|
1267
|
+
*/
|
|
1268
|
+
async applyDecision({ violationId: e, action: t = "approve", rationale: r = "", decidedBy: s = "human" }) {
|
|
1269
|
+
return this.api.post("/memory/governance/apply-decision", {
|
|
1270
|
+
violation_id: e,
|
|
1271
|
+
action: t,
|
|
1272
|
+
rationale: r,
|
|
1273
|
+
decided_by: s
|
|
1274
|
+
});
|
|
1275
|
+
}
|
|
1276
|
+
/**
|
|
1277
|
+
* Run auto-fix for high-confidence violations.
|
|
1278
|
+
* @param {number} [confidenceThreshold=0.8]
|
|
1279
|
+
*/
|
|
1280
|
+
async autoFix(e = 0.8) {
|
|
1281
|
+
return this.api.post("/memory/governance/auto-fix", {
|
|
1282
|
+
confidence_threshold: e
|
|
1283
|
+
});
|
|
1284
|
+
}
|
|
1285
|
+
/**
|
|
1286
|
+
* Get a summary of governance state.
|
|
1287
|
+
*/
|
|
1288
|
+
async getSummary() {
|
|
1289
|
+
return this.api.get("/memory/governance/summary");
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
class j {
|
|
1293
|
+
constructor(e) {
|
|
1294
|
+
this.api = e;
|
|
1295
|
+
}
|
|
1296
|
+
/**
|
|
1297
|
+
* Manually trigger memory evolution processes.
|
|
1298
|
+
*/
|
|
1299
|
+
async trigger() {
|
|
1300
|
+
return this.api.post("/memory/evolution/trigger");
|
|
1301
|
+
}
|
|
1302
|
+
/**
|
|
1303
|
+
* Run a 'dream' phase: promote working memory to episodic/procedural.
|
|
1304
|
+
*/
|
|
1305
|
+
async dream() {
|
|
1306
|
+
return this.api.post("/memory/evolution/dream");
|
|
1307
|
+
}
|
|
1308
|
+
/**
|
|
1309
|
+
* Get status of memory evolution processes.
|
|
1310
|
+
*/
|
|
1311
|
+
async getStatus() {
|
|
1312
|
+
return this.api.get("/memory/evolution/status");
|
|
1313
|
+
}
|
|
1314
|
+
/**
|
|
1315
|
+
* Run opinion synthesis: detect patterns in episodic memories and form opinions.
|
|
1316
|
+
*/
|
|
1317
|
+
async synthesizeOpinions() {
|
|
1318
|
+
return this.api.post("/memory/evolution/synthesize/opinions");
|
|
1319
|
+
}
|
|
1320
|
+
/**
|
|
1321
|
+
* Run observation synthesis: create entity summaries from scattered facts.
|
|
1322
|
+
*/
|
|
1323
|
+
async synthesizeObservations() {
|
|
1324
|
+
return this.api.post("/memory/evolution/synthesize/observations");
|
|
1325
|
+
}
|
|
1326
|
+
/**
|
|
1327
|
+
* Run opinion reinforcement: update confidence scores based on new evidence.
|
|
1328
|
+
*/
|
|
1329
|
+
async reinforceOpinions() {
|
|
1330
|
+
return this.api.post("/memory/evolution/reinforce/opinions");
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
class K {
|
|
1334
|
+
constructor(e) {
|
|
1335
|
+
this.api = e;
|
|
1336
|
+
}
|
|
1337
|
+
// === ASSERTION CHALLENGING ===
|
|
1338
|
+
/**
|
|
1339
|
+
* Challenge an assertion against existing knowledge.
|
|
1340
|
+
* @param {Object} params
|
|
1341
|
+
* @param {string} params.assertion
|
|
1342
|
+
* @param {string} [params.memoryType='semantic']
|
|
1343
|
+
* @param {boolean} [params.useLlm=true]
|
|
1344
|
+
*/
|
|
1345
|
+
async challenge({ assertion: e, memoryType: t = "semantic", useLlm: r = !0 }) {
|
|
1346
|
+
return this.api.post("/memory/reasoning/challenge", {
|
|
1347
|
+
assertion: e,
|
|
1348
|
+
memory_type: t,
|
|
1349
|
+
use_llm: r
|
|
1350
|
+
});
|
|
1351
|
+
}
|
|
1352
|
+
/**
|
|
1353
|
+
* Resolve a conflict between assertions.
|
|
1354
|
+
* @param {Object} params
|
|
1355
|
+
* @param {string} params.existingItemId
|
|
1356
|
+
* @param {string} params.newFact
|
|
1357
|
+
* @param {boolean} [params.autoResolve=true]
|
|
1358
|
+
* @param {string} [params.strategy]
|
|
1359
|
+
* @param {boolean} [params.useWikipedia=true]
|
|
1360
|
+
* @param {boolean} [params.useLlm=true]
|
|
1361
|
+
*/
|
|
1362
|
+
async resolve({ existingItemId: e, newFact: t, autoResolve: r = !0, strategy: s = null, useWikipedia: n = !0, useLlm: a = !0 }) {
|
|
1363
|
+
return this.api.post("/memory/reasoning/resolve", {
|
|
1364
|
+
existing_item_id: e,
|
|
1365
|
+
new_fact: t,
|
|
1366
|
+
auto_resolve: r,
|
|
1367
|
+
strategy: s,
|
|
1368
|
+
use_wikipedia: n,
|
|
1369
|
+
use_llm: a
|
|
1370
|
+
});
|
|
1371
|
+
}
|
|
1372
|
+
// === CONFLICT QUERIES ===
|
|
1373
|
+
/**
|
|
1374
|
+
* List memory items that have unresolved conflicts.
|
|
1375
|
+
* @param {Object} [options]
|
|
1376
|
+
* @param {boolean} [options.needsReview=true]
|
|
1377
|
+
* @param {number} [options.limit=50]
|
|
1378
|
+
*/
|
|
1379
|
+
async listConflicts({ needsReview: e = !0, limit: t = 50 } = {}) {
|
|
1380
|
+
return this.api.get(`/memory/reasoning/conflicts?needs_review=${e}&limit=${t}`);
|
|
1381
|
+
}
|
|
1382
|
+
/**
|
|
1383
|
+
* Get items with confidence below threshold.
|
|
1384
|
+
* @param {Object} [options]
|
|
1385
|
+
* @param {number} [options.threshold=0.5]
|
|
1386
|
+
* @param {number} [options.limit=50]
|
|
1387
|
+
*/
|
|
1388
|
+
async getLowConfidence({ threshold: e = 0.5, limit: t = 50 } = {}) {
|
|
1389
|
+
return this.api.get(`/memory/reasoning/low-confidence?threshold=${e}&limit=${t}`);
|
|
1390
|
+
}
|
|
1391
|
+
/**
|
|
1392
|
+
* Get confidence decay history for a specific item.
|
|
1393
|
+
* @param {string} itemId
|
|
1394
|
+
*/
|
|
1395
|
+
async getConfidenceHistory(e) {
|
|
1396
|
+
return this.api.get(`/memory/reasoning/confidence-history/${e}`);
|
|
1397
|
+
}
|
|
1398
|
+
// === SYMBOLIC REASONING ===
|
|
1399
|
+
/**
|
|
1400
|
+
* Route a query through the symbolic/semantic router.
|
|
1401
|
+
* @param {string} query
|
|
1402
|
+
* @param {number} [topK=10]
|
|
1403
|
+
*/
|
|
1404
|
+
async query(e, t = 10) {
|
|
1405
|
+
return this.api.post("/memory/reasoning/query", {
|
|
1406
|
+
query: e,
|
|
1407
|
+
top_k: t
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1410
|
+
/**
|
|
1411
|
+
* Build an auditable proof tree for a decision.
|
|
1412
|
+
* @param {string} decisionId
|
|
1413
|
+
* @param {number} [maxDepth=5]
|
|
1414
|
+
*/
|
|
1415
|
+
async proof(e, t = 5) {
|
|
1416
|
+
return this.api.post("/memory/reasoning/proof", {
|
|
1417
|
+
decision_id: e,
|
|
1418
|
+
max_depth: t
|
|
1419
|
+
});
|
|
1420
|
+
}
|
|
1421
|
+
/**
|
|
1422
|
+
* Get multi-dimensional confidence score for a decision.
|
|
1423
|
+
* @param {string} decisionId
|
|
1424
|
+
*/
|
|
1425
|
+
async fuzzyConfidence(e) {
|
|
1426
|
+
return this.api.post("/memory/reasoning/fuzzy-confidence", {
|
|
1427
|
+
decision_id: e
|
|
1428
|
+
});
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
class B {
|
|
1432
|
+
constructor(e) {
|
|
1433
|
+
this.api = e;
|
|
1434
|
+
}
|
|
1435
|
+
/**
|
|
1436
|
+
* Extract reasoning traces from content.
|
|
1437
|
+
* @param {Object} params
|
|
1438
|
+
* @param {string} params.content
|
|
1439
|
+
* @param {number} [params.minSteps=2]
|
|
1440
|
+
* @param {number} [params.minQualityScore=0.4]
|
|
1441
|
+
* @param {boolean} [params.useLlmDetection=true]
|
|
1442
|
+
*/
|
|
1443
|
+
async extract({ content: e, minSteps: t = 2, minQualityScore: r = 0.4, useLlmDetection: s = !0 }) {
|
|
1444
|
+
return this.api.post("/memory/reasoning/traces/extract", {
|
|
1445
|
+
content: e,
|
|
1446
|
+
min_steps: t,
|
|
1447
|
+
min_quality_score: r,
|
|
1448
|
+
use_llm_detection: s
|
|
1449
|
+
});
|
|
1450
|
+
}
|
|
1451
|
+
/**
|
|
1452
|
+
* Store a reasoning trace as a memory item.
|
|
1453
|
+
* @param {Object} params
|
|
1454
|
+
* @param {Object} params.trace - ReasoningTrace object
|
|
1455
|
+
* @param {string[]} [params.artifactIds]
|
|
1456
|
+
*/
|
|
1457
|
+
async store({ trace: e, artifactIds: t = null }) {
|
|
1458
|
+
return this.api.post("/memory/reasoning/traces/store", {
|
|
1459
|
+
trace: e,
|
|
1460
|
+
artifact_ids: t
|
|
1461
|
+
});
|
|
1462
|
+
}
|
|
1463
|
+
/**
|
|
1464
|
+
* Query reasoning traces.
|
|
1465
|
+
* @param {Object} params
|
|
1466
|
+
* @param {string} params.query
|
|
1467
|
+
* @param {string} [params.artifactId]
|
|
1468
|
+
* @param {number} [params.limit=10]
|
|
1469
|
+
*/
|
|
1470
|
+
async query({ query: e, artifactId: t = null, limit: r = 10 }) {
|
|
1471
|
+
return this.api.post("/memory/reasoning/traces/query", {
|
|
1472
|
+
query: e,
|
|
1473
|
+
artifact_id: t,
|
|
1474
|
+
limit: r
|
|
1475
|
+
});
|
|
1476
|
+
}
|
|
1477
|
+
/**
|
|
1478
|
+
* Get a specific reasoning trace by ID.
|
|
1479
|
+
* @param {string} traceId
|
|
1480
|
+
*/
|
|
1481
|
+
async get(e) {
|
|
1482
|
+
return this.api.get(`/memory/reasoning/traces/${e}`);
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
class D {
|
|
1486
|
+
constructor(e) {
|
|
1487
|
+
this.api = e;
|
|
1488
|
+
}
|
|
1489
|
+
// === INFERENCE ===
|
|
1490
|
+
/**
|
|
1491
|
+
* Run ontology inference over provided raw text chunks.
|
|
1492
|
+
* @param {Object} params
|
|
1493
|
+
* @param {string} [params.registryId='default']
|
|
1494
|
+
* @param {Array<{docId: string, text: string}>} params.rawChunks
|
|
1495
|
+
* @param {Object} [params.params={}]
|
|
1496
|
+
*/
|
|
1497
|
+
async runInference({ registryId: e = "default", rawChunks: t, params: r = {} }) {
|
|
1498
|
+
return this.api.post("/memory/ontology/inference/run", {
|
|
1499
|
+
registry_id: e,
|
|
1500
|
+
raw_chunks: t.map((s) => ({ doc_id: s.docId, text: s.text })),
|
|
1501
|
+
params: r
|
|
1502
|
+
});
|
|
1503
|
+
}
|
|
1504
|
+
// === REGISTRY MANAGEMENT ===
|
|
1505
|
+
/**
|
|
1506
|
+
* List all ontology registries.
|
|
1507
|
+
*/
|
|
1508
|
+
async listRegistries() {
|
|
1509
|
+
return this.api.get("/memory/ontology/registries");
|
|
1510
|
+
}
|
|
1511
|
+
/**
|
|
1512
|
+
* Create a new ontology registry.
|
|
1513
|
+
* @param {Object} params
|
|
1514
|
+
* @param {string} params.name
|
|
1515
|
+
* @param {string} [params.description='']
|
|
1516
|
+
* @param {string} [params.domain='general']
|
|
1517
|
+
*/
|
|
1518
|
+
async createRegistry({ name: e, description: t = "", domain: r = "general" }) {
|
|
1519
|
+
return this.api.post("/memory/ontology/registries", {
|
|
1520
|
+
name: e,
|
|
1521
|
+
description: t,
|
|
1522
|
+
domain: r
|
|
1523
|
+
});
|
|
1524
|
+
}
|
|
1525
|
+
/**
|
|
1526
|
+
* Get a snapshot of a registry (current or specific version).
|
|
1527
|
+
* @param {string} registryId
|
|
1528
|
+
* @param {string} [version]
|
|
1529
|
+
*/
|
|
1530
|
+
async getSnapshot(e, t = null) {
|
|
1531
|
+
let r = `/memory/ontology/registry/${e}/snapshot`;
|
|
1532
|
+
return t && (r += `?version=${encodeURIComponent(t)}`), this.api.get(r);
|
|
1533
|
+
}
|
|
1534
|
+
/**
|
|
1535
|
+
* Apply a changeset to create a new version of the registry.
|
|
1536
|
+
* @param {string} registryId
|
|
1537
|
+
* @param {Object} params
|
|
1538
|
+
* @param {string} [params.baseVersion='']
|
|
1539
|
+
* @param {Object} params.changeset - OntologyIR changeset
|
|
1540
|
+
* @param {string} [params.message='']
|
|
1541
|
+
*/
|
|
1542
|
+
async applyChangeset(e, { baseVersion: t = "", changeset: r, message: s = "" }) {
|
|
1543
|
+
return this.api.post(`/memory/ontology/registry/${e}/apply`, {
|
|
1544
|
+
base_version: t,
|
|
1545
|
+
changeset: r,
|
|
1546
|
+
message: s
|
|
1547
|
+
});
|
|
1548
|
+
}
|
|
1549
|
+
/**
|
|
1550
|
+
* List snapshots for a registry.
|
|
1551
|
+
* @param {string} registryId
|
|
1552
|
+
* @param {number} [limit=50]
|
|
1553
|
+
*/
|
|
1554
|
+
async listSnapshots(e, t = 50) {
|
|
1555
|
+
return this.api.get(`/memory/ontology/registry/${e}/snapshots?limit=${t}`);
|
|
1556
|
+
}
|
|
1557
|
+
/**
|
|
1558
|
+
* Get change history for a registry.
|
|
1559
|
+
* @param {string} registryId
|
|
1560
|
+
* @param {number} [limit=50]
|
|
1561
|
+
*/
|
|
1562
|
+
async getChangelog(e, t = 50) {
|
|
1563
|
+
return this.api.get(`/memory/ontology/registry/${e}/changelog?limit=${t}`);
|
|
1564
|
+
}
|
|
1565
|
+
/**
|
|
1566
|
+
* Rollback registry to a previous version.
|
|
1567
|
+
* @param {string} registryId
|
|
1568
|
+
* @param {Object} params
|
|
1569
|
+
* @param {string} [params.targetVersion='']
|
|
1570
|
+
* @param {string} [params.message='']
|
|
1571
|
+
*/
|
|
1572
|
+
async rollbackRegistry(e, { targetVersion: t = "", message: r = "" }) {
|
|
1573
|
+
return this.api.post(`/memory/ontology/registry/${e}/rollback`, {
|
|
1574
|
+
target_version: t,
|
|
1575
|
+
message: r
|
|
1576
|
+
});
|
|
1577
|
+
}
|
|
1578
|
+
/**
|
|
1579
|
+
* Export a registry snapshot.
|
|
1580
|
+
* @param {string} registryId
|
|
1581
|
+
* @param {string} [version]
|
|
1582
|
+
*/
|
|
1583
|
+
async exportRegistry(e, t = null) {
|
|
1584
|
+
let r = `/memory/ontology/registry/${e}/export`;
|
|
1585
|
+
return t && (r += `?version=${encodeURIComponent(t)}`), this.api.get(r);
|
|
1586
|
+
}
|
|
1587
|
+
/**
|
|
1588
|
+
* Import data into a registry.
|
|
1589
|
+
* @param {string} registryId
|
|
1590
|
+
* @param {Object} params
|
|
1591
|
+
* @param {Object} params.data - Complete ontology data to import
|
|
1592
|
+
* @param {string} [params.message='']
|
|
1593
|
+
*/
|
|
1594
|
+
async importRegistry(e, { data: t, message: r = "" }) {
|
|
1595
|
+
return this.api.post(`/memory/ontology/registry/${e}/import`, {
|
|
1596
|
+
data: t,
|
|
1597
|
+
message: r
|
|
1598
|
+
});
|
|
1599
|
+
}
|
|
1600
|
+
// === ENRICHMENT & GROUNDING ===
|
|
1601
|
+
/**
|
|
1602
|
+
* List available enrichment providers.
|
|
1603
|
+
*/
|
|
1604
|
+
async listEnrichmentProviders() {
|
|
1605
|
+
return this.api.get("/memory/ontology/enrichment/providers");
|
|
1606
|
+
}
|
|
1607
|
+
/**
|
|
1608
|
+
* Run enrichment operation using specified provider.
|
|
1609
|
+
* @param {Object} params
|
|
1610
|
+
* @param {string} [params.provider='wikipedia']
|
|
1611
|
+
* @param {string[]} params.entities
|
|
1612
|
+
*/
|
|
1613
|
+
async runEnrichment({ provider: e = "wikipedia", entities: t }) {
|
|
1614
|
+
return this.api.post("/memory/ontology/enrichment/run", {
|
|
1615
|
+
provider: e,
|
|
1616
|
+
entities: t
|
|
1617
|
+
});
|
|
1618
|
+
}
|
|
1619
|
+
/**
|
|
1620
|
+
* Run grounding operation using specified grounder.
|
|
1621
|
+
* @param {Object} params
|
|
1622
|
+
* @param {string} [params.grounder='wikipedia']
|
|
1623
|
+
* @param {string} params.itemId
|
|
1624
|
+
* @param {string[]} params.candidates
|
|
1625
|
+
*/
|
|
1626
|
+
async runGrounding({ grounder: e = "wikipedia", itemId: t, candidates: r }) {
|
|
1627
|
+
return this.api.post("/memory/ontology/grounding/run", {
|
|
1628
|
+
grounder: e,
|
|
1629
|
+
item_id: t,
|
|
1630
|
+
candidates: r
|
|
1631
|
+
});
|
|
1632
|
+
}
|
|
1633
|
+
// === TEMPLATES ===
|
|
1634
|
+
/**
|
|
1635
|
+
* List all available ontology templates.
|
|
1636
|
+
*/
|
|
1637
|
+
async listTemplates() {
|
|
1638
|
+
return this.api.get("/memory/ontology/templates");
|
|
1639
|
+
}
|
|
1640
|
+
/**
|
|
1641
|
+
* Preview template details.
|
|
1642
|
+
* @param {string} templateId
|
|
1643
|
+
*/
|
|
1644
|
+
async getTemplate(e) {
|
|
1645
|
+
return this.api.get(`/memory/ontology/templates/${e}`);
|
|
1646
|
+
}
|
|
1647
|
+
/**
|
|
1648
|
+
* Clone a template into the workspace as an independent ontology.
|
|
1649
|
+
* @param {Object} params
|
|
1650
|
+
* @param {string} params.templateId
|
|
1651
|
+
* @param {string} params.targetName
|
|
1652
|
+
*/
|
|
1653
|
+
async cloneTemplate({ templateId: e, targetName: t }) {
|
|
1654
|
+
return this.api.post("/memory/ontology/templates/clone", {
|
|
1655
|
+
template_id: e,
|
|
1656
|
+
target_name: t
|
|
1657
|
+
});
|
|
1658
|
+
}
|
|
1659
|
+
/**
|
|
1660
|
+
* Save an existing ontology registry as a custom template.
|
|
1661
|
+
* @param {Object} params
|
|
1662
|
+
* @param {string} params.registryId
|
|
1663
|
+
* @param {string} params.name
|
|
1664
|
+
* @param {string} [params.description='']
|
|
1665
|
+
*/
|
|
1666
|
+
async saveAsTemplate({ registryId: e, name: t, description: r = "" }) {
|
|
1667
|
+
return this.api.post("/memory/ontology/templates", {
|
|
1668
|
+
registry_id: e,
|
|
1669
|
+
name: t,
|
|
1670
|
+
description: r
|
|
1671
|
+
});
|
|
1672
|
+
}
|
|
1673
|
+
/**
|
|
1674
|
+
* Delete a custom template.
|
|
1675
|
+
* @param {string} templateId
|
|
1676
|
+
*/
|
|
1677
|
+
async deleteTemplate(e) {
|
|
1678
|
+
return this.api.delete(`/memory/ontology/templates/${e}`);
|
|
1679
|
+
}
|
|
1680
|
+
// === PATTERNS ===
|
|
1681
|
+
/**
|
|
1682
|
+
* List entity patterns with stats for the current workspace.
|
|
1683
|
+
*/
|
|
1684
|
+
async listPatterns() {
|
|
1685
|
+
return this.api.get("/memory/ontology/patterns");
|
|
1686
|
+
}
|
|
1687
|
+
/**
|
|
1688
|
+
* Manually add an entity pattern.
|
|
1689
|
+
* @param {Object} params
|
|
1690
|
+
* @param {string} params.name
|
|
1691
|
+
* @param {string} params.entityType
|
|
1692
|
+
* @param {number} [params.confidence=0.9]
|
|
1693
|
+
* @param {boolean} [params.isGlobal=false]
|
|
1694
|
+
*/
|
|
1695
|
+
async createPattern({ name: e, entityType: t, confidence: r = 0.9, isGlobal: s = !1 }) {
|
|
1696
|
+
return this.api.post("/memory/ontology/patterns", {
|
|
1697
|
+
name: e,
|
|
1698
|
+
entity_type: t,
|
|
1699
|
+
confidence: r,
|
|
1700
|
+
is_global: s
|
|
1701
|
+
});
|
|
1702
|
+
}
|
|
1703
|
+
/**
|
|
1704
|
+
* Delete an entity pattern by name.
|
|
1705
|
+
* @param {string} patternName
|
|
1706
|
+
* @param {string} entityType
|
|
1707
|
+
*/
|
|
1708
|
+
async deletePattern(e, t) {
|
|
1709
|
+
return this.api.delete(`/memory/ontology/patterns/${e}?entity_type=${encodeURIComponent(t)}`);
|
|
1710
|
+
}
|
|
1711
|
+
// === STATUS & IMPORT/EXPORT ===
|
|
1712
|
+
/**
|
|
1713
|
+
* Get ontology convergence metrics.
|
|
1714
|
+
*/
|
|
1715
|
+
async getStatus() {
|
|
1716
|
+
return this.api.get("/memory/ontology/status");
|
|
1717
|
+
}
|
|
1718
|
+
/**
|
|
1719
|
+
* Import OntologyIR data to seed or migrate the ontology.
|
|
1720
|
+
* @param {Object} data
|
|
1721
|
+
*/
|
|
1722
|
+
async importOntology(e) {
|
|
1723
|
+
return this.api.post("/memory/ontology/import", { data: e });
|
|
1724
|
+
}
|
|
1725
|
+
/**
|
|
1726
|
+
* Export the full ontology as a portable dict.
|
|
1727
|
+
*/
|
|
1728
|
+
async exportOntology() {
|
|
1729
|
+
return this.api.get("/memory/ontology/export");
|
|
1730
|
+
}
|
|
1731
|
+
// === LAYER ENDPOINTS (ontology_layers.py) ===
|
|
1732
|
+
/**
|
|
1733
|
+
* Subscribe an overlay ontology to a base ontology.
|
|
1734
|
+
* @param {string} registryId
|
|
1735
|
+
* @param {Object} params
|
|
1736
|
+
* @param {string} params.baseRegistryId
|
|
1737
|
+
* @param {string} [params.pinnedVersion]
|
|
1738
|
+
*/
|
|
1739
|
+
async subscribe(e, { baseRegistryId: t, pinnedVersion: r = null }) {
|
|
1740
|
+
return this.api.post(`/memory/ontology/registry/${e}/subscribe`, {
|
|
1741
|
+
base_registry_id: t,
|
|
1742
|
+
pinned_version: r
|
|
1743
|
+
});
|
|
1744
|
+
}
|
|
1745
|
+
/**
|
|
1746
|
+
* Detach from base - flatten visible base types into overlay.
|
|
1747
|
+
* @param {string} registryId
|
|
1748
|
+
*/
|
|
1749
|
+
async unsubscribe(e) {
|
|
1750
|
+
return this.api.delete(`/memory/ontology/registry/${e}/subscribe`);
|
|
1751
|
+
}
|
|
1752
|
+
/**
|
|
1753
|
+
* Pin subscription to a specific base version.
|
|
1754
|
+
* @param {string} registryId
|
|
1755
|
+
* @param {string} version
|
|
1756
|
+
*/
|
|
1757
|
+
async pinVersion(e, t) {
|
|
1758
|
+
return this.api.put(`/memory/ontology/registry/${e}/subscribe/pin`, {
|
|
1759
|
+
version: t
|
|
1760
|
+
});
|
|
1761
|
+
}
|
|
1762
|
+
/**
|
|
1763
|
+
* Unpin - follow latest base version.
|
|
1764
|
+
* @param {string} registryId
|
|
1765
|
+
*/
|
|
1766
|
+
async unpinVersion(e) {
|
|
1767
|
+
return this.api.delete(`/memory/ontology/registry/${e}/subscribe/pin`);
|
|
1768
|
+
}
|
|
1769
|
+
/**
|
|
1770
|
+
* Get provenance map and layer counts for an ontology.
|
|
1771
|
+
* @param {string} registryId
|
|
1772
|
+
*/
|
|
1773
|
+
async getLayers(e) {
|
|
1774
|
+
return this.api.get(`/memory/ontology/registry/${e}/layers`);
|
|
1775
|
+
}
|
|
1776
|
+
/**
|
|
1777
|
+
* Compute diff between base and overlay layers.
|
|
1778
|
+
* @param {string} registryId
|
|
1779
|
+
*/
|
|
1780
|
+
async getLayerDiff(e) {
|
|
1781
|
+
return this.api.get(`/memory/ontology/registry/${e}/layer-diff`);
|
|
1782
|
+
}
|
|
1783
|
+
/**
|
|
1784
|
+
* Hide a base entity type from the merged view.
|
|
1785
|
+
* @param {string} registryId
|
|
1786
|
+
* @param {string} typeName
|
|
1787
|
+
*/
|
|
1788
|
+
async hideType(e, t) {
|
|
1789
|
+
return this.api.post(`/memory/ontology/registry/${e}/subscribe/hidden`, {
|
|
1790
|
+
type_name: t
|
|
1791
|
+
});
|
|
1792
|
+
}
|
|
1793
|
+
/**
|
|
1794
|
+
* Unhide a previously hidden base entity type.
|
|
1795
|
+
* @param {string} registryId
|
|
1796
|
+
* @param {string} typeName
|
|
1797
|
+
*/
|
|
1798
|
+
async unhideType(e, t) {
|
|
1799
|
+
return this.api.delete(`/memory/ontology/registry/${e}/subscribe/hidden/${t}`);
|
|
1800
|
+
}
|
|
1801
|
+
// === ONTOLOGY UPDATE (ontology_update.py) ===
|
|
1802
|
+
/**
|
|
1803
|
+
* Get the ontology update configuration for this workspace.
|
|
1804
|
+
*/
|
|
1805
|
+
async getUpdateConfig() {
|
|
1806
|
+
return this.api.get("/memory/ontology/updates/config");
|
|
1807
|
+
}
|
|
1808
|
+
/**
|
|
1809
|
+
* Update the ontology update configuration.
|
|
1810
|
+
* @param {Object} updates
|
|
1811
|
+
* @param {boolean} [updates.enabled]
|
|
1812
|
+
* @param {string} [updates.schedule] - hourly|daily|manual
|
|
1813
|
+
* @param {number} [updates.batchSize]
|
|
1814
|
+
* @param {string} [updates.model]
|
|
1815
|
+
*/
|
|
1816
|
+
async updateConfig(e) {
|
|
1817
|
+
const t = {};
|
|
1818
|
+
return e.enabled !== void 0 && (t.enabled = e.enabled), e.schedule !== void 0 && (t.schedule = e.schedule), e.batchSize !== void 0 && (t.batch_size = e.batchSize), e.model !== void 0 && (t.model = e.model), this.api.patch("/memory/ontology/updates/config", t);
|
|
1819
|
+
}
|
|
1820
|
+
/**
|
|
1821
|
+
* Trigger a batch ontology update run.
|
|
1822
|
+
* @param {Object} [options]
|
|
1823
|
+
* @param {number} [options.batchSize]
|
|
1824
|
+
*/
|
|
1825
|
+
async triggerUpdate({ batchSize: e = null } = {}) {
|
|
1826
|
+
const t = {};
|
|
1827
|
+
return e !== null && (t.batch_size = e), this.api.post("/memory/ontology/updates/trigger", t);
|
|
1828
|
+
}
|
|
1829
|
+
/**
|
|
1830
|
+
* Get the status of the latest batch run.
|
|
1831
|
+
*/
|
|
1832
|
+
async getUpdateStatus() {
|
|
1833
|
+
return this.api.get("/memory/ontology/updates/status");
|
|
1834
|
+
}
|
|
1835
|
+
/**
|
|
1836
|
+
* Get paginated history of batch runs.
|
|
1837
|
+
* @param {Object} [options]
|
|
1838
|
+
* @param {number} [options.page=1]
|
|
1839
|
+
* @param {number} [options.pageSize=10]
|
|
1840
|
+
*/
|
|
1841
|
+
async getUpdateHistory({ page: e = 1, pageSize: t = 10 } = {}) {
|
|
1842
|
+
return this.api.get(`/memory/ontology/updates/history?page=${e}&page_size=${t}`);
|
|
1843
|
+
}
|
|
1844
|
+
/**
|
|
1845
|
+
* Get ontology update statistics for this workspace.
|
|
1846
|
+
* @param {Object} [options]
|
|
1847
|
+
* @param {boolean} [options.history=false]
|
|
1848
|
+
*/
|
|
1849
|
+
async getUpdateStats({ history: e = !1 } = {}) {
|
|
1850
|
+
return this.api.get(`/memory/ontology/updates/stats?history=${e}`);
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
class G {
|
|
1854
|
+
constructor(e) {
|
|
1855
|
+
this.api = e;
|
|
1856
|
+
}
|
|
1857
|
+
/**
|
|
1858
|
+
* Get analytics feature status and environment capabilities.
|
|
1859
|
+
*/
|
|
1860
|
+
async getStatus() {
|
|
1861
|
+
return this.api.get("/memory/analytics/status");
|
|
1862
|
+
}
|
|
1863
|
+
/**
|
|
1864
|
+
* Run concept drift detection over the specified time window.
|
|
1865
|
+
* @param {number} [timeWindowDays=30]
|
|
1866
|
+
*/
|
|
1867
|
+
async detectDrift(e = 30) {
|
|
1868
|
+
return this.api.get(`/memory/analytics/drift?time_window_days=${e}`);
|
|
1869
|
+
}
|
|
1870
|
+
/**
|
|
1871
|
+
* Run bias detection with optional sentiment/topic analysis.
|
|
1872
|
+
* @param {Object} [options]
|
|
1873
|
+
* @param {string[]} [options.protectedAttributes]
|
|
1874
|
+
* @param {boolean} [options.sentimentAnalysis]
|
|
1875
|
+
* @param {boolean} [options.topicAnalysis]
|
|
1876
|
+
*/
|
|
1877
|
+
async detectBias({ protectedAttributes: e = null, sentimentAnalysis: t = null, topicAnalysis: r = null } = {}) {
|
|
1878
|
+
const s = {};
|
|
1879
|
+
return e !== null && (s.protected_attributes = e), t !== null && (s.sentiment_analysis = t), r !== null && (s.topic_analysis = r), this.api.post("/memory/analytics/bias", s);
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
class N {
|
|
1883
|
+
constructor(e) {
|
|
1884
|
+
this.api = e;
|
|
1885
|
+
}
|
|
1886
|
+
/**
|
|
1887
|
+
* Get graph health metrics: orphan ratio, type distribution, provenance coverage.
|
|
1888
|
+
*/
|
|
1889
|
+
async getHealth() {
|
|
1890
|
+
return this.api.get("/memory/graph/health");
|
|
1891
|
+
}
|
|
1892
|
+
/**
|
|
1893
|
+
* Validate a memory item against schema and semantic rules.
|
|
1894
|
+
* @param {string} itemId
|
|
1895
|
+
*/
|
|
1896
|
+
async validateItem(e) {
|
|
1897
|
+
return this.api.post("/memory/validation/validate", {
|
|
1898
|
+
item_id: e
|
|
1899
|
+
});
|
|
1900
|
+
}
|
|
1901
|
+
/**
|
|
1902
|
+
* Run inference engine to create inferred edges from rules.
|
|
1903
|
+
* @param {Object} [options]
|
|
1904
|
+
* @param {boolean} [options.dryRun=false]
|
|
1905
|
+
*/
|
|
1906
|
+
async runInference({ dryRun: e = !1 } = {}) {
|
|
1907
|
+
return this.api.post("/memory/validation/inference", {
|
|
1908
|
+
dry_run: e
|
|
1909
|
+
});
|
|
1910
|
+
}
|
|
1911
|
+
/**
|
|
1912
|
+
* List available inference rules.
|
|
1913
|
+
*/
|
|
1914
|
+
async getInferenceRules() {
|
|
1915
|
+
return this.api.get("/memory/validation/inference/rules");
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
class V {
|
|
1919
|
+
constructor(e) {
|
|
1920
|
+
this.api = e;
|
|
1921
|
+
}
|
|
1922
|
+
// === STAGE EXECUTION ===
|
|
1923
|
+
/**
|
|
1924
|
+
* Run extraction pipeline stage.
|
|
1925
|
+
* @param {Object} request - ExtractionRequest
|
|
1926
|
+
*/
|
|
1927
|
+
async runExtraction(e) {
|
|
1928
|
+
return this.api.post("/memory/pipeline/extraction", e);
|
|
1929
|
+
}
|
|
1930
|
+
/**
|
|
1931
|
+
* Run storage pipeline stage.
|
|
1932
|
+
* @param {Object} request - StorageRequest
|
|
1933
|
+
*/
|
|
1934
|
+
async runStorage(e) {
|
|
1935
|
+
return this.api.post("/memory/pipeline/storage", e);
|
|
1936
|
+
}
|
|
1937
|
+
/**
|
|
1938
|
+
* Run linking pipeline stage.
|
|
1939
|
+
* @param {Object} request - LinkingRequest
|
|
1940
|
+
*/
|
|
1941
|
+
async runLinking(e) {
|
|
1942
|
+
return this.api.post("/memory/pipeline/linking", e);
|
|
1943
|
+
}
|
|
1944
|
+
/**
|
|
1945
|
+
* Run enrichment pipeline stage.
|
|
1946
|
+
* @param {Object} request - EnrichmentRequest
|
|
1947
|
+
*/
|
|
1948
|
+
async runEnrichment(e) {
|
|
1949
|
+
return this.api.post("/memory/pipeline/enrichment", e);
|
|
1950
|
+
}
|
|
1951
|
+
/**
|
|
1952
|
+
* Run grounding pipeline stage.
|
|
1953
|
+
* @param {Object} request - GroundingRequest
|
|
1954
|
+
*/
|
|
1955
|
+
async runGrounding(e) {
|
|
1956
|
+
return this.api.post("/memory/pipeline/grounding", e);
|
|
1957
|
+
}
|
|
1958
|
+
// === STATE MANAGEMENT ===
|
|
1959
|
+
/**
|
|
1960
|
+
* Get pipeline state for a specific pipeline and optional run.
|
|
1961
|
+
* @param {string} pipelineId
|
|
1962
|
+
* @param {string} [runId]
|
|
1963
|
+
*/
|
|
1964
|
+
async getState(e, t = null) {
|
|
1965
|
+
let r = `/memory/pipeline/${e}/state`;
|
|
1966
|
+
return t && (r += `?run_id=${encodeURIComponent(t)}`), this.api.get(r);
|
|
1967
|
+
}
|
|
1968
|
+
/**
|
|
1969
|
+
* Reset a pipeline, clearing its state.
|
|
1970
|
+
* @param {string} pipelineId
|
|
1971
|
+
*/
|
|
1972
|
+
async reset(e) {
|
|
1973
|
+
return this.api.delete(`/memory/pipeline/${e}`);
|
|
1974
|
+
}
|
|
1975
|
+
/**
|
|
1976
|
+
* Clear all stage states for a specific pipeline run.
|
|
1977
|
+
* @param {string} pipelineId
|
|
1978
|
+
* @param {string} runId
|
|
1979
|
+
*/
|
|
1980
|
+
async clearRun(e, t) {
|
|
1981
|
+
return this.api.delete(`/memory/pipeline/${e}/run/${t}`);
|
|
1982
|
+
}
|
|
1983
|
+
// === CONFIG MANAGEMENT ===
|
|
1984
|
+
/**
|
|
1985
|
+
* List named pipeline configs for the current workspace.
|
|
1986
|
+
*/
|
|
1987
|
+
async listConfigs() {
|
|
1988
|
+
return this.api.get("/memory/pipeline/configs");
|
|
1989
|
+
}
|
|
1990
|
+
/**
|
|
1991
|
+
* Save a named pipeline config.
|
|
1992
|
+
* @param {Object} params
|
|
1993
|
+
* @param {string} params.name
|
|
1994
|
+
* @param {string} [params.description='']
|
|
1995
|
+
* @param {Object} params.config
|
|
1996
|
+
*/
|
|
1997
|
+
async createConfig({ name: e, description: t = "", config: r }) {
|
|
1998
|
+
return this.api.post("/memory/pipeline/configs", {
|
|
1999
|
+
name: e,
|
|
2000
|
+
description: t,
|
|
2001
|
+
config: r
|
|
2002
|
+
});
|
|
2003
|
+
}
|
|
2004
|
+
/**
|
|
2005
|
+
* Load a named pipeline config.
|
|
2006
|
+
* @param {string} configName
|
|
2007
|
+
*/
|
|
2008
|
+
async getConfig(e) {
|
|
2009
|
+
return this.api.get(`/memory/pipeline/configs/${e}`);
|
|
2010
|
+
}
|
|
2011
|
+
/**
|
|
2012
|
+
* Update an existing pipeline config.
|
|
2013
|
+
* @param {string} configName
|
|
2014
|
+
* @param {Object} params
|
|
2015
|
+
* @param {string} [params.name='']
|
|
2016
|
+
* @param {string} [params.description='']
|
|
2017
|
+
* @param {Object} [params.config={}]
|
|
2018
|
+
*/
|
|
2019
|
+
async updateConfig(e, { name: t = "", description: r = "", config: s = {} }) {
|
|
2020
|
+
return this.api.patch(`/memory/pipeline/configs/${e}`, {
|
|
2021
|
+
name: t,
|
|
2022
|
+
description: r,
|
|
2023
|
+
config: s
|
|
2024
|
+
});
|
|
2025
|
+
}
|
|
2026
|
+
/**
|
|
2027
|
+
* Delete a named pipeline config.
|
|
2028
|
+
* @param {string} configName
|
|
2029
|
+
*/
|
|
2030
|
+
async deleteConfig(e) {
|
|
2031
|
+
return this.api.delete(`/memory/pipeline/configs/${e}`);
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
class J {
|
|
2035
|
+
constructor(e) {
|
|
2036
|
+
this.api = e;
|
|
2037
|
+
}
|
|
2038
|
+
/**
|
|
2039
|
+
* Persist a conversation artifact and return its URI and content hash.
|
|
2040
|
+
* @param {Object} params
|
|
2041
|
+
* @param {string} params.conversationId
|
|
2042
|
+
* @param {Object} params.payload
|
|
2043
|
+
* @param {Object} [params.metadata={}]
|
|
2044
|
+
*/
|
|
2045
|
+
async store({ conversationId: e, payload: t, metadata: r = {} }) {
|
|
2046
|
+
return this.api.post("/memory/archive/store", {
|
|
2047
|
+
conversation_id: e,
|
|
2048
|
+
payload: t,
|
|
2049
|
+
metadata: r
|
|
2050
|
+
});
|
|
2051
|
+
}
|
|
2052
|
+
/**
|
|
2053
|
+
* Retrieve a previously stored archive artifact by URI.
|
|
2054
|
+
* @param {string} archiveUri
|
|
2055
|
+
*/
|
|
2056
|
+
async get(e) {
|
|
2057
|
+
return this.api.get(`/memory/archive/${e}`);
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
class W {
|
|
2061
|
+
constructor(e) {
|
|
2062
|
+
this.api = e;
|
|
2063
|
+
}
|
|
2064
|
+
// === BIDIRECTIONAL LINKING ===
|
|
2065
|
+
/**
|
|
2066
|
+
* Get notes that link TO this note (backlinks).
|
|
2067
|
+
* @param {string} noteId
|
|
2068
|
+
*/
|
|
2069
|
+
async getBacklinks(e) {
|
|
2070
|
+
return this.api.get(`/memory/zettel/${e}/backlinks`);
|
|
2071
|
+
}
|
|
2072
|
+
/**
|
|
2073
|
+
* Get notes this note links TO (forward links).
|
|
2074
|
+
* @param {string} noteId
|
|
2075
|
+
*/
|
|
2076
|
+
async getForwardLinks(e) {
|
|
2077
|
+
return this.api.get(`/memory/zettel/${e}/forward-links`);
|
|
2078
|
+
}
|
|
2079
|
+
/**
|
|
2080
|
+
* Get all connections (backlinks + forward links).
|
|
2081
|
+
* @param {string} noteId
|
|
2082
|
+
*/
|
|
2083
|
+
async getConnections(e) {
|
|
2084
|
+
return this.api.get(`/memory/zettel/${e}/connections`);
|
|
2085
|
+
}
|
|
2086
|
+
// === EMERGENT STRUCTURE ===
|
|
2087
|
+
/**
|
|
2088
|
+
* Detect knowledge clusters in your Zettelkasten.
|
|
2089
|
+
* @param {Object} [options]
|
|
2090
|
+
* @param {number} [options.minSize=3]
|
|
2091
|
+
* @param {string} [options.algorithm='louvain']
|
|
2092
|
+
*/
|
|
2093
|
+
async getClusters({ minSize: e = 3, algorithm: t = "louvain" } = {}) {
|
|
2094
|
+
return this.api.get(`/memory/zettel/clusters?min_size=${e}&algorithm=${t}`);
|
|
2095
|
+
}
|
|
2096
|
+
/**
|
|
2097
|
+
* Find hub notes (highly connected notes).
|
|
2098
|
+
* @param {Object} [options]
|
|
2099
|
+
* @param {number} [options.minConnections=5]
|
|
2100
|
+
* @param {number} [options.limit=20]
|
|
2101
|
+
*/
|
|
2102
|
+
async getHubs({ minConnections: e = 5, limit: t = 20 } = {}) {
|
|
2103
|
+
return this.api.get(`/memory/zettel/hubs?min_connections=${e}&limit=${t}`);
|
|
2104
|
+
}
|
|
2105
|
+
/**
|
|
2106
|
+
* Find bridge notes (notes connecting different clusters).
|
|
2107
|
+
* @param {number} [limit=20]
|
|
2108
|
+
*/
|
|
2109
|
+
async getBridges(e = 20) {
|
|
2110
|
+
return this.api.get(`/memory/zettel/bridges?limit=${e}`);
|
|
2111
|
+
}
|
|
2112
|
+
// === SERENDIPITOUS DISCOVERY ===
|
|
2113
|
+
/**
|
|
2114
|
+
* Find unexpected connections (serendipitous discovery).
|
|
2115
|
+
* @param {string} noteId
|
|
2116
|
+
* @param {Object} [options]
|
|
2117
|
+
* @param {number} [options.maxDistance=3]
|
|
2118
|
+
* @param {number} [options.minSurprise=0.5]
|
|
2119
|
+
*/
|
|
2120
|
+
async getDiscoveries(e, { maxDistance: t = 3, minSurprise: r = 0.5 } = {}) {
|
|
2121
|
+
return this.api.get(`/memory/zettel/${e}/discoveries?max_distance=${t}&min_surprise=${r}`);
|
|
2122
|
+
}
|
|
2123
|
+
/**
|
|
2124
|
+
* Find paths between two notes.
|
|
2125
|
+
* @param {string} noteId
|
|
2126
|
+
* @param {string} targetId
|
|
2127
|
+
* @param {number} [maxPaths=5]
|
|
2128
|
+
*/
|
|
2129
|
+
async getPath(e, t, r = 5) {
|
|
2130
|
+
return this.api.get(`/memory/zettel/${e}/path/${t}?max_paths=${r}`);
|
|
2131
|
+
}
|
|
2132
|
+
// === WIKILINK SUPPORT ===
|
|
2133
|
+
/**
|
|
2134
|
+
* Parse [[wikilinks]] in content.
|
|
2135
|
+
* @param {string} content
|
|
2136
|
+
* @param {boolean} [autoCreate=true]
|
|
2137
|
+
*/
|
|
2138
|
+
async parseWikilinks(e, t = !0) {
|
|
2139
|
+
return this.api.post(`/memory/zettel/wikilink/parse?auto_create=${t}`, e);
|
|
2140
|
+
}
|
|
2141
|
+
/**
|
|
2142
|
+
* Resolve a wikilink to a note.
|
|
2143
|
+
* @param {string} link
|
|
2144
|
+
*/
|
|
2145
|
+
async resolveWikilink(e) {
|
|
2146
|
+
return this.api.get(`/memory/zettel/wikilink/resolve?link=${encodeURIComponent(e)}`);
|
|
2147
|
+
}
|
|
2148
|
+
// === GRAPH VISUALIZATION ===
|
|
2149
|
+
/**
|
|
2150
|
+
* Get subgraph around a note (for visualization).
|
|
2151
|
+
* @param {string} noteId
|
|
2152
|
+
* @param {Object} [options]
|
|
2153
|
+
* @param {number} [options.depth=2]
|
|
2154
|
+
* @param {boolean} [options.includeMetadata=true]
|
|
2155
|
+
*/
|
|
2156
|
+
async getSubgraph(e, { depth: t = 2, includeMetadata: r = !0 } = {}) {
|
|
2157
|
+
return this.api.get(`/memory/zettel/${e}/graph?depth=${t}&include_metadata=${r}`);
|
|
2158
|
+
}
|
|
2159
|
+
// === ADDITIONAL DISCOVERY ===
|
|
2160
|
+
/**
|
|
2161
|
+
* Detect emerging concepts from connection patterns.
|
|
2162
|
+
* @param {number} [limit=20]
|
|
2163
|
+
*/
|
|
2164
|
+
async detectConceptEmergence(e = 20) {
|
|
2165
|
+
return this.api.get(`/memory/zettel/concept-emergence?limit=${e}`);
|
|
2166
|
+
}
|
|
2167
|
+
/**
|
|
2168
|
+
* Suggest related notes for serendipitous discovery.
|
|
2169
|
+
* @param {string} noteId
|
|
2170
|
+
* @param {number} [count=5]
|
|
2171
|
+
*/
|
|
2172
|
+
async suggestRelated(e, t = 5) {
|
|
2173
|
+
return this.api.get(`/memory/zettel/${e}/suggestions?count=${t}`);
|
|
2174
|
+
}
|
|
2175
|
+
/**
|
|
2176
|
+
* Perform random walk for serendipitous discovery.
|
|
2177
|
+
* @param {string} noteId
|
|
2178
|
+
* @param {number} [length=5]
|
|
2179
|
+
*/
|
|
2180
|
+
async randomWalk(e, t = 5) {
|
|
2181
|
+
return this.api.get(`/memory/zettel/${e}/random-walk?length=${t}`);
|
|
2182
|
+
}
|
|
2183
|
+
// === QUERY FEATURES ===
|
|
2184
|
+
/**
|
|
2185
|
+
* Find notes by tag.
|
|
2186
|
+
* @param {string} tag
|
|
2187
|
+
* @param {number} [limit=100]
|
|
2188
|
+
*/
|
|
2189
|
+
async findByTag(e, t = 100) {
|
|
2190
|
+
return this.api.get(`/memory/zettel/by-tag/${encodeURIComponent(e)}?limit=${t}`);
|
|
2191
|
+
}
|
|
2192
|
+
/**
|
|
2193
|
+
* Find notes by property.
|
|
2194
|
+
* @param {string} key
|
|
2195
|
+
* @param {string} value
|
|
2196
|
+
* @param {number} [limit=100]
|
|
2197
|
+
*/
|
|
2198
|
+
async findByProperty(e, t, r = 100) {
|
|
2199
|
+
return this.api.get(`/memory/zettel/by-property?key=${encodeURIComponent(e)}&value=${encodeURIComponent(t)}&limit=${r}`);
|
|
2200
|
+
}
|
|
2201
|
+
/**
|
|
2202
|
+
* Find notes mentioning an entity.
|
|
2203
|
+
* @param {string} entityId
|
|
2204
|
+
* @param {number} [limit=100]
|
|
2205
|
+
*/
|
|
2206
|
+
async findMentioning(e, t = 100) {
|
|
2207
|
+
return this.api.get(`/memory/zettel/mentioning/${e}?limit=${t}`);
|
|
2208
|
+
}
|
|
2209
|
+
/**
|
|
2210
|
+
* Query notes by dynamic relation type.
|
|
2211
|
+
* @param {string} sourceId
|
|
2212
|
+
* @param {string} relationType
|
|
2213
|
+
* @param {number} [limit=100]
|
|
2214
|
+
*/
|
|
2215
|
+
async queryByRelation(e, t, r = 100) {
|
|
2216
|
+
return this.api.get(`/memory/zettel/by-relation/${e}/${t}?limit=${r}`);
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
class Y {
|
|
2220
|
+
constructor(e) {
|
|
2221
|
+
this.api = e;
|
|
2222
|
+
}
|
|
2223
|
+
/**
|
|
2224
|
+
* List procedure match history for the current workspace.
|
|
2225
|
+
* @param {Object} params - Query parameters
|
|
2226
|
+
* @param {string} [params.start_date] - ISO date string (inclusive)
|
|
2227
|
+
* @param {string} [params.end_date] - ISO date string (inclusive)
|
|
2228
|
+
* @param {string} [params.procedure_id] - Filter by procedure ID
|
|
2229
|
+
* @param {string} [params.feedback] - Filter by feedback: "success" | "failure" | "neutral"
|
|
2230
|
+
* @param {number} [params.limit=100] - Max records (1-1000)
|
|
2231
|
+
*/
|
|
2232
|
+
async list(e = {}) {
|
|
2233
|
+
const t = Object.fromEntries(
|
|
2234
|
+
Object.entries(e).filter(([, s]) => s != null)
|
|
2235
|
+
), r = new URLSearchParams(t).toString();
|
|
2236
|
+
return this.api.get(`/memory/procedures/matches${r ? "?" + r : ""}`);
|
|
2237
|
+
}
|
|
2238
|
+
/**
|
|
2239
|
+
* Submit feedback for a procedure match.
|
|
2240
|
+
* @param {string} matchId - The match ID (uuid)
|
|
2241
|
+
* @param {string} feedback - One of "success", "failure", "neutral"
|
|
2242
|
+
* @param {string} [note] - Optional explanation
|
|
2243
|
+
*/
|
|
2244
|
+
async submitFeedback(e, t, r = null) {
|
|
2245
|
+
const s = { feedback: t };
|
|
2246
|
+
return r && (s.note = r), this.api.post(`/memory/procedures/matches/${e}/feedback`, s);
|
|
2247
|
+
}
|
|
2248
|
+
/**
|
|
2249
|
+
* Get aggregated procedure match statistics.
|
|
2250
|
+
*/
|
|
2251
|
+
async getStats() {
|
|
2252
|
+
return this.api.get("/memory/procedures/matches/stats");
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
class Z {
|
|
2256
|
+
constructor(e) {
|
|
2257
|
+
this.api = e;
|
|
2258
|
+
}
|
|
2259
|
+
/**
|
|
2260
|
+
* List procedure promotion candidates detected from working memory patterns.
|
|
2261
|
+
* @param {Object} params - Query parameters
|
|
2262
|
+
* @param {number} [params.min_score=0.6] - Minimum recommendation score (0-1)
|
|
2263
|
+
* @param {number} [params.min_cluster_size=3] - Minimum items in cluster
|
|
2264
|
+
* @param {number} [params.days_back=30] - Days to look back
|
|
2265
|
+
* @param {number} [params.limit=20] - Max candidates to return
|
|
2266
|
+
* @returns {Promise<Object>} Response containing candidates array
|
|
2267
|
+
*/
|
|
2268
|
+
async list(e = {}) {
|
|
2269
|
+
const t = Object.fromEntries(
|
|
2270
|
+
Object.entries(e).filter(([, s]) => s != null)
|
|
2271
|
+
), r = new URLSearchParams(t).toString();
|
|
2272
|
+
return this.api.get(`/memory/procedures/candidates${r ? "?" + r : ""}`);
|
|
2273
|
+
}
|
|
2274
|
+
/**
|
|
2275
|
+
* Promote a candidate cluster to a new procedure.
|
|
2276
|
+
* @param {string} clusterId - The cluster ID from list()
|
|
2277
|
+
* @param {Object} options - Promotion options
|
|
2278
|
+
* @param {string} [options.name] - Name for the procedure (uses suggested_name if omitted)
|
|
2279
|
+
* @param {string} [options.description] - Description for the procedure
|
|
2280
|
+
* @param {string} [options.procedure_type='extraction'] - Type of procedure
|
|
2281
|
+
* @param {string} [options.preferred_profile='quick_extract'] - Pipeline profile
|
|
2282
|
+
* @param {boolean} [options.remove_working_items=false] - Remove source items after promotion
|
|
2283
|
+
* @returns {Promise<Object>} Response with procedure_id and status
|
|
2284
|
+
*/
|
|
2285
|
+
async promote(e, t = {}) {
|
|
2286
|
+
const r = {
|
|
2287
|
+
name: t.name ?? null,
|
|
2288
|
+
description: t.description ?? null,
|
|
2289
|
+
procedure_type: t.procedure_type ?? "extraction",
|
|
2290
|
+
preferred_profile: t.preferred_profile ?? "quick_extract",
|
|
2291
|
+
remove_working_items: t.remove_working_items ?? !1
|
|
2292
|
+
};
|
|
2293
|
+
return this.api.post(`/memory/procedures/candidates/${e}/promote`, r);
|
|
2294
|
+
}
|
|
2295
|
+
/**
|
|
2296
|
+
* Dismiss a candidate cluster from future recommendations.
|
|
2297
|
+
* @param {string} clusterId - The cluster ID to dismiss
|
|
2298
|
+
* @returns {Promise<Object>} Response with status and message
|
|
2299
|
+
*/
|
|
2300
|
+
async dismiss(e) {
|
|
2301
|
+
return this.api.delete(`/memory/procedures/candidates/${e}/dismiss`);
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2304
|
+
class X {
|
|
2305
|
+
constructor(e) {
|
|
2306
|
+
this.api = e;
|
|
2307
|
+
}
|
|
2308
|
+
/**
|
|
2309
|
+
* List drift events with optional filters.
|
|
2310
|
+
* @param {Object} params
|
|
2311
|
+
* @param {string} [params.procedure_id] - Filter by procedure
|
|
2312
|
+
* @param {boolean} [params.resolved] - Filter by resolution status
|
|
2313
|
+
* @param {boolean} [params.breaking_only] - Only breaking changes
|
|
2314
|
+
* @param {string} [params.start_date] - ISO 8601 range start
|
|
2315
|
+
* @param {string} [params.end_date] - ISO 8601 range end
|
|
2316
|
+
* @param {number} [params.limit=100] - Max results (1-1000)
|
|
2317
|
+
* @returns {Promise<{workspace_id: string, record_count: number, records: Object[]}>}
|
|
2318
|
+
*/
|
|
2319
|
+
async list(e = {}) {
|
|
2320
|
+
const t = Object.fromEntries(
|
|
2321
|
+
Object.entries(e).filter(([, s]) => s != null)
|
|
2322
|
+
), r = new URLSearchParams(t).toString();
|
|
2323
|
+
return this.api.get(`/memory/procedures/drift${r ? "?" + r : ""}`);
|
|
2324
|
+
}
|
|
2325
|
+
/**
|
|
2326
|
+
* Get a single drift event with full change details.
|
|
2327
|
+
* @param {string} eventId - The drift event ID
|
|
2328
|
+
* @returns {Promise<Object>} DriftEventDetail
|
|
2329
|
+
*/
|
|
2330
|
+
async get(e) {
|
|
2331
|
+
return this.api.get(`/memory/procedures/drift/${e}`);
|
|
2332
|
+
}
|
|
2333
|
+
/**
|
|
2334
|
+
* Mark a drift event as resolved.
|
|
2335
|
+
* @param {string} eventId - The drift event ID
|
|
2336
|
+
* @param {string} [note] - Optional resolution note (max 500 chars)
|
|
2337
|
+
* @returns {Promise<{status: string, event_id: string, resolved: boolean}>}
|
|
2338
|
+
*/
|
|
2339
|
+
async resolve(e, t = null) {
|
|
2340
|
+
const r = {};
|
|
2341
|
+
return t != null && (r.note = t), this.api.post(`/memory/procedures/drift/${e}/resolve`, r);
|
|
2342
|
+
}
|
|
2343
|
+
/**
|
|
2344
|
+
* Trigger a drift sweep across all procedures in the workspace.
|
|
2345
|
+
* @returns {Promise<{workspace_id: string, procedures_checked: number, drift_detected: number, events_created: number}>}
|
|
2346
|
+
*/
|
|
2347
|
+
async sweep() {
|
|
2348
|
+
return this.api.post("/memory/procedures/drift/sweep", {});
|
|
2349
|
+
}
|
|
2350
|
+
/**
|
|
2351
|
+
* List schema snapshots for a procedure.
|
|
2352
|
+
* @param {string} procedureId - The procedure ID
|
|
2353
|
+
* @returns {Promise<{workspace_id: string, procedure_id: string, record_count: number, snapshots: Object[]}>}
|
|
2354
|
+
*/
|
|
2355
|
+
async listSnapshots(e) {
|
|
2356
|
+
return this.api.get(`/memory/procedures/schemas/${e}`);
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
class Q {
|
|
2360
|
+
constructor(e) {
|
|
2361
|
+
this.api = e;
|
|
2362
|
+
}
|
|
2363
|
+
/**
|
|
2364
|
+
* Fire a manual snapshot for the current workspace.
|
|
2365
|
+
* Throws on 409 lock_held — concurrent /generate from the same workspace.
|
|
2366
|
+
* @param {Object} [params]
|
|
2367
|
+
* @param {string} [params.windowStart] ISO 8601 datetime string
|
|
2368
|
+
* @param {boolean} [params.includeMarkdown=true]
|
|
2369
|
+
*/
|
|
2370
|
+
async generate({ windowStart: e = null, includeMarkdown: t = !0 } = {}) {
|
|
2371
|
+
return this.api.post("/memory/summary/generate", {
|
|
2372
|
+
window_start: e,
|
|
2373
|
+
include_markdown: t
|
|
2374
|
+
});
|
|
2375
|
+
}
|
|
2376
|
+
/** Most recent snapshot for the current workspace, or null on 404. */
|
|
2377
|
+
async latest() {
|
|
2378
|
+
try {
|
|
2379
|
+
return await this.api.get("/memory/summary/latest");
|
|
2380
|
+
} catch (e) {
|
|
2381
|
+
if ((e == null ? void 0 : e.status) === 404) return null;
|
|
2382
|
+
throw e;
|
|
2383
|
+
}
|
|
2384
|
+
}
|
|
2385
|
+
/** Specific snapshot by id, or null on 404. */
|
|
2386
|
+
async get(e) {
|
|
2387
|
+
try {
|
|
2388
|
+
return await this.api.get(`/memory/summary/${e}`);
|
|
2389
|
+
} catch (t) {
|
|
2390
|
+
if ((t == null ? void 0 : t.status) === 404) return null;
|
|
2391
|
+
throw t;
|
|
2392
|
+
}
|
|
2393
|
+
}
|
|
2394
|
+
/** Fast-path graph-only markdown for a snapshot. */
|
|
2395
|
+
async getMarkdown(e) {
|
|
2396
|
+
try {
|
|
2397
|
+
return await this.api.get(`/memory/summary/${e}/markdown`);
|
|
2398
|
+
} catch (t) {
|
|
2399
|
+
if ((t == null ? void 0 : t.status) === 404) return null;
|
|
2400
|
+
throw t;
|
|
2401
|
+
}
|
|
2402
|
+
}
|
|
2403
|
+
/**
|
|
2404
|
+
* List snapshots for the current workspace, newest first.
|
|
2405
|
+
* @param {Object} [params]
|
|
2406
|
+
* @param {boolean|null} [params.isHeartbeat]
|
|
2407
|
+
* @param {number} [params.limit=20]
|
|
2408
|
+
* @param {string} [params.before] ISO 8601 datetime
|
|
2409
|
+
*/
|
|
2410
|
+
async list({ isHeartbeat: e = null, limit: t = 20, before: r = null } = {}) {
|
|
2411
|
+
const s = { limit: t };
|
|
2412
|
+
return e !== null && (s.is_heartbeat = e), r !== null && (s.before = r), this.api.get("/memory/summary/list", s);
|
|
2413
|
+
}
|
|
2414
|
+
/** SnapshotDelta between two snapshots. Returns null on 404. */
|
|
2415
|
+
async delta({ from: e, to: t }) {
|
|
2416
|
+
try {
|
|
2417
|
+
return await this.api.get("/memory/summary/delta", {
|
|
2418
|
+
from: e,
|
|
2419
|
+
to: t
|
|
2420
|
+
});
|
|
2421
|
+
} catch (r) {
|
|
2422
|
+
if ((r == null ? void 0 : r.status) === 404) return null;
|
|
2423
|
+
throw r;
|
|
2424
|
+
}
|
|
2425
|
+
}
|
|
2426
|
+
/** Admin-only delete. Throws on 403/404/500. */
|
|
2427
|
+
async delete(e) {
|
|
2428
|
+
return this.api.delete(`/memory/summary/${e}`);
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
class te {
|
|
2432
|
+
constructor(e) {
|
|
2433
|
+
this.auth = new v(e);
|
|
2434
|
+
const t = new A(this.auth, { fetchFn: e.fetchFn });
|
|
2435
|
+
this.memories = new R(t), this.decisions = new U(t), this.graph = new C(t), this.teams = new P(t), this.profiles = new M(t), this.subscriptions = new L(t), this.authAPI = new z(t), this.agents = new E(t), this.usage = new x(t), this.insights = new O(t), this.tokenUsage = new q(t), this.temporal = new F(t), this.governance = new H(t), this.evolution = new j(t), this.reasoning = new K(t), this.reasoningTraces = new B(t), this.ontology = new D(t), this.analytics = new G(t), this.validation = new N(t), this.pipeline = new V(t), this.archive = new J(t), this.zettelkasten = new W(t), this.procedureMatches = new Y(t), this.procedureCandidates = new Z(t), this.procedureDrift = new X(t), this.summaries = new Q(t);
|
|
2436
|
+
}
|
|
2437
|
+
setTeamId(e) {
|
|
2438
|
+
this.auth.tokenManager.setTeamId(e), this.auth.notifyListeners();
|
|
2439
|
+
}
|
|
2440
|
+
getTeamId() {
|
|
2441
|
+
return this.auth.tokenManager.getTeamId();
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
export {
|
|
2445
|
+
h as A,
|
|
2446
|
+
A as B,
|
|
2447
|
+
U as D,
|
|
2448
|
+
j as E,
|
|
2449
|
+
H as G,
|
|
2450
|
+
O as I,
|
|
2451
|
+
R as M,
|
|
2452
|
+
D as O,
|
|
2453
|
+
V as P,
|
|
2454
|
+
K as R,
|
|
2455
|
+
te as S,
|
|
2456
|
+
P as T,
|
|
2457
|
+
x as U,
|
|
2458
|
+
N as V,
|
|
2459
|
+
W as Z,
|
|
2460
|
+
E as a,
|
|
2461
|
+
G as b,
|
|
2462
|
+
J as c,
|
|
2463
|
+
z as d,
|
|
2464
|
+
v as e,
|
|
2465
|
+
C as f,
|
|
2466
|
+
Z as g,
|
|
2467
|
+
Y as h,
|
|
2468
|
+
M as i,
|
|
2469
|
+
B as j,
|
|
2470
|
+
L as k,
|
|
2471
|
+
F as l,
|
|
2472
|
+
I as m,
|
|
2473
|
+
q as n,
|
|
2474
|
+
T as o,
|
|
2475
|
+
S as p
|
|
2476
|
+
};
|