@smartmemory/sdk-js 1.4.53 → 1.4.59

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 CHANGED
@@ -79,6 +79,40 @@ function Dashboard() {
79
79
  }
80
80
  ```
81
81
 
82
+ ### Browser analytics (optional)
83
+
84
+ The analytics entry point is browser-only and intentionally separate from the core and React bindings. Install its optional `posthog-js` peer only in apps that use analytics:
85
+
86
+ ```bash
87
+ npm install posthog-js
88
+ ```
89
+
90
+ ```jsx
91
+ import { PostHogProvider } from 'posthog-js/react';
92
+ import {
93
+ AnalyticsIdentity,
94
+ createAnalyticsConfig,
95
+ } from '@smartmemory/sdk-js/react/analytics';
96
+
97
+ const analytics = createAnalyticsConfig({
98
+ app: 'web',
99
+ apiKey: import.meta.env.VITE_PUBLIC_POSTHOG_KEY,
100
+ apiHost: import.meta.env.VITE_PUBLIC_POSTHOG_HOST,
101
+ });
102
+
103
+ // Keep the existing child passthrough when analytics.apiKey is null.
104
+ const root = analytics.apiKey
105
+ ? <PostHogProvider apiKey={analytics.apiKey} options={analytics.options}><App /></PostHogProvider>
106
+ : <App />;
107
+
108
+ function IdentityAdapter() {
109
+ const { user, isAuthenticated, workspaceId } = useAuth();
110
+ return <AnalyticsIdentity {...{ user, isAuthenticated, workspaceId }} />;
111
+ }
112
+ ```
113
+
114
+ This subpath also exports `captureProductEvent`, `captureException`, and `resetAnalytics`. It is not re-exported from `@smartmemory/sdk-js/react`, so non-browser consumers never load PostHog.
115
+
82
116
  ## Entry Points
83
117
 
84
118
  | Import | Contents |
@@ -86,6 +120,7 @@ function Dashboard() {
86
120
  | `@smartmemory/sdk-js` | SmartMemoryClient, AuthCore, TokenManager, all domain APIs, APIError |
87
121
  | `@smartmemory/sdk-js/core` | Everything above + BaseAPI, RefreshManager, SSOManager (internal access) |
88
122
  | `@smartmemory/sdk-js/react` | SmartMemoryProvider, useAuth, useAuthState, useAuthActions, useSmartMemory, AuthWrapper |
123
+ | `@smartmemory/sdk-js/react/analytics` | Browser-only strict PostHog config, identity, product-event, exception, and reset helpers (optional `posthog-js` peer) |
89
124
  | `@smartmemory/sdk-js/fetch` | createAuthFetch, installInterceptor |
90
125
 
91
126
  ## Configuration
@@ -1,9 +1,9 @@
1
- var R = (a) => {
1
+ var S = (a) => {
2
2
  throw TypeError(a);
3
3
  };
4
- var k = (a, e, t) => e.has(a) || R("Cannot " + t);
5
- var g = (a, e, t) => (k(a, e, "read from private field"), t ? t.call(a) : e.get(a)), w = (a, e, t) => e.has(a) ? R("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(a) : e.set(a, t), b = (a, e, t, s) => (k(a, e, "write to private field"), s ? s.call(a, t) : e.set(a, t), t), S = (a, e, t) => (k(a, e, "access private method"), t);
6
- const U = {
4
+ var w = (a, e, t) => e.has(a) || S("Cannot " + t);
5
+ var d = (a, e, t) => (w(a, e, "read from private field"), t ? t.call(a) : e.get(a)), b = (a, e, t) => e.has(a) ? S("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(a) : e.set(a, t), I = (a, e, t, s) => (w(a, e, "write to private field"), s ? s.call(a, t) : e.set(a, t), t), v = (a, e, t) => (w(a, e, "access private method"), t);
6
+ const P = {
7
7
  access: "smart_memory_auth_token",
8
8
  refresh: "smart_memory_refresh_token",
9
9
  user: "smart_memory_user",
@@ -16,14 +16,14 @@ const U = {
16
16
  tenant: ["tenant_id", "workspace_id", "sm_workspace_id"],
17
17
  team: ["team_id", "sm_team_id"]
18
18
  };
19
- class C {
19
+ class L {
20
20
  /**
21
21
  * @param {Object} options
22
22
  * @param {'localStorage' | 'sessionStorage' | 'memory'} [options.storage='localStorage']
23
23
  * @param {Object} [options.keys] - Custom storage key names
24
24
  */
25
25
  constructor({ storage: e = "localStorage", keys: t = {} } = {}) {
26
- this.storageType = e, this.keys = { ...U, ...t }, this._memory = { access: null, refresh: null, user: null, tenant: null, team: null };
26
+ this.storageType = e, this.keys = { ...P, ...t }, this._memory = { access: null, refresh: null, user: null, tenant: null, team: null };
27
27
  }
28
28
  getAccessToken() {
29
29
  return this.storageType === "memory" ? this._memory.access : this._getFromStorage(this.keys.access, y.access);
@@ -148,8 +148,8 @@ class C {
148
148
  return s === "none" || s === "null" || s === "undefined" ? null : t;
149
149
  }
150
150
  }
151
- var l, f, v;
152
- class P {
151
+ var l, _, T;
152
+ class q {
153
153
  /**
154
154
  * @param {Object} options
155
155
  * @param {string} options.apiBaseUrl
@@ -160,22 +160,22 @@ class P {
160
160
  * @param {function(): void} options.onRefreshFailed
161
161
  */
162
162
  constructor({ apiBaseUrl: e, refreshEndpoint: t, tokenManager: s, useCookieAuth: r = !1, onTokenRefreshed: n, onRefreshFailed: i }) {
163
- w(this, f);
164
- w(this, l, null);
163
+ b(this, _);
164
+ b(this, l, null);
165
165
  this.apiBaseUrl = e, this.refreshEndpoint = t, this.tokenManager = s, this.useCookieAuth = r, this.onTokenRefreshed = n, this.onRefreshFailed = i;
166
166
  }
167
167
  async refresh() {
168
- if (g(this, l))
169
- return g(this, l);
170
- b(this, l, S(this, f, v).call(this));
168
+ if (d(this, l))
169
+ return d(this, l);
170
+ I(this, l, v(this, _, T).call(this));
171
171
  try {
172
- return await g(this, l);
172
+ return await d(this, l);
173
173
  } finally {
174
- b(this, l, null);
174
+ I(this, l, null);
175
175
  }
176
176
  }
177
177
  }
178
- l = new WeakMap(), f = new WeakSet(), v = async function() {
178
+ l = new WeakMap(), _ = new WeakSet(), T = async function() {
179
179
  const e = this.tokenManager.getRefreshToken();
180
180
  if (!e && !this.useCookieAuth)
181
181
  throw this.onRefreshFailed(), new Error("No refresh token");
@@ -190,8 +190,8 @@ l = new WeakMap(), f = new WeakSet(), v = async function() {
190
190
  const r = await s.json();
191
191
  return this.tokenManager.setAccessToken(r.access_token), r.refresh_token && this.tokenManager.setRefreshToken(r.refresh_token), this.onTokenRefreshed(r.access_token), r.access_token;
192
192
  };
193
- const I = "smart_memory_sso_redirect";
194
- class q {
193
+ const R = "smart_memory_sso_redirect";
194
+ class M {
195
195
  /**
196
196
  * @param {Object} options
197
197
  * @param {string} options.webAppUrl - Web app URL for login redirect
@@ -216,26 +216,26 @@ class q {
216
216
  }
217
217
  storeRedirect(e) {
218
218
  try {
219
- sessionStorage.setItem(I, e);
219
+ sessionStorage.setItem(R, e);
220
220
  } catch (t) {
221
221
  console.warn("Failed to store redirect URL:", t);
222
222
  }
223
223
  }
224
224
  getAndClearRedirect() {
225
225
  try {
226
- const e = sessionStorage.getItem(I);
227
- return sessionStorage.removeItem(I), e;
226
+ const e = sessionStorage.getItem(R);
227
+ return sessionStorage.removeItem(R), e;
228
228
  } catch {
229
229
  return null;
230
230
  }
231
231
  }
232
232
  }
233
- class L {
233
+ class z {
234
234
  constructor(e) {
235
- 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 C({
235
+ 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 L({
236
236
  storage: e.storage || "localStorage",
237
237
  keys: e.tokenKeys
238
- }), this.mode !== "apiKey" ? this.refreshManager = new P({
238
+ }), this.mode !== "apiKey" ? this.refreshManager = new q({
239
239
  apiBaseUrl: this.apiBaseUrl,
240
240
  refreshEndpoint: this.endpoints.refresh || "/auth/refresh",
241
241
  tokenManager: this.tokenManager,
@@ -247,7 +247,7 @@ class L {
247
247
  onRefreshFailed: () => {
248
248
  this.clearLocalAuth();
249
249
  }
250
- }) : this.refreshManager = null, this.mode === "sso" && (this.ssoManager = new q({
250
+ }) : this.refreshManager = null, this.mode === "sso" && (this.ssoManager = new M({
251
251
  webAppUrl: e.webAppUrl,
252
252
  allowedHosts: e.allowedRedirectHosts || [],
253
253
  tokenManager: this.tokenManager
@@ -286,7 +286,8 @@ class L {
286
286
  isAuthenticated: this.isAuthenticated(),
287
287
  user: this.currentUser,
288
288
  token: this.currentToken,
289
- tenantId: this.tokenManager.getTenantId()
289
+ tenantId: this.tokenManager.getTenantId(),
290
+ workspaceId: this.tokenManager.getTeamId()
290
291
  };
291
292
  this.listeners.forEach((t) => {
292
293
  try {
@@ -376,10 +377,10 @@ class h extends Error {
376
377
  super(e), this.name = "APIError", this.status = t, this.detail = s;
377
378
  }
378
379
  }
379
- function d(a) {
380
+ function f(a) {
380
381
  return typeof FormData < "u" && a instanceof FormData;
381
382
  }
382
- class M {
383
+ class E {
383
384
  /**
384
385
  * @param {import('../auth/AuthCore.js').AuthCore} authCore
385
386
  * @param {{ fetchFn?: typeof globalThis.fetch }} [options]
@@ -393,7 +394,7 @@ class M {
393
394
  async request(e, t = {}) {
394
395
  var i, o;
395
396
  const s = `${this.baseURL}${e}`, r = {
396
- ...d(t.body) ? {} : { "Content-Type": "application/json" },
397
+ ...f(t.body) ? {} : { "Content-Type": "application/json" },
397
398
  ...this.auth.getAuthHeaders(t.headers)
398
399
  }, n = this.auth.getRequestOptions({ ...t, headers: r });
399
400
  try {
@@ -401,13 +402,13 @@ class M {
401
402
  if (c.status === 401 && !t.__isRetry)
402
403
  try {
403
404
  await this.auth.refreshToken();
404
- const u = {
405
- ...d(t.body) ? {} : { "Content-Type": "application/json" },
405
+ const m = {
406
+ ...f(t.body) ? {} : { "Content-Type": "application/json" },
406
407
  ...this.auth.getAuthHeaders(t.headers)
407
408
  };
408
409
  c = await this.fetchFn(
409
410
  s,
410
- this.auth.getRequestOptions({ ...n, headers: u, __isRetry: !0 })
411
+ this.auth.getRequestOptions({ ...n, headers: m, __isRetry: !0 })
411
412
  );
412
413
  } catch {
413
414
  }
@@ -435,7 +436,7 @@ class M {
435
436
  async requestBinary(e, t = {}) {
436
437
  var i, o;
437
438
  const s = `${this.baseURL}${e}`, r = {
438
- ...d(t.body) ? {} : { "Content-Type": "application/json" },
439
+ ...f(t.body) ? {} : { "Content-Type": "application/json" },
439
440
  ...this.auth.getAuthHeaders(t.headers)
440
441
  }, n = this.auth.getRequestOptions({ ...t, headers: r });
441
442
  try {
@@ -443,13 +444,13 @@ class M {
443
444
  if (c.status === 401 && !t.__isRetry)
444
445
  try {
445
446
  await this.auth.refreshToken();
446
- const u = {
447
- ...d(t.body) ? {} : { "Content-Type": "application/json" },
447
+ const m = {
448
+ ...f(t.body) ? {} : { "Content-Type": "application/json" },
448
449
  ...this.auth.getAuthHeaders(t.headers)
449
450
  };
450
451
  c = await this.fetchFn(
451
452
  s,
452
- this.auth.getRequestOptions({ ...n, headers: u, __isRetry: !0 })
453
+ this.auth.getRequestOptions({ ...n, headers: m, __isRetry: !0 })
453
454
  );
454
455
  } catch {
455
456
  }
@@ -526,10 +527,25 @@ class M {
526
527
  return typeof (e == null ? void 0 : e.message) == "string" ? e.message : `HTTP ${t}`;
527
528
  }
528
529
  }
529
- class z {
530
+ class x {
530
531
  constructor(e) {
531
532
  this.api = e;
532
533
  }
534
+ /**
535
+ * Create a memory item.
536
+ *
537
+ * Provenance like `retrieved_context_ids` travels inside `metadata` — the storage
538
+ * layer lifts it onto the server-side MemoryItem; no dedicated option exists
539
+ * (GRAPH-API-1i wire field added then removed 2026-08-02).
540
+ *
541
+ * @param {Object} options
542
+ * @param {string} options.content - Memory content
543
+ * @param {string} [options.memoryType='semantic'] - Memory type
544
+ * @param {Object} [options.metadata] - Additional metadata
545
+ * @param {boolean} [options.usePipeline=true] - Run the full extraction pipeline
546
+ * @param {string} [options.profileName] - Pipeline profile, routed server-side
547
+ * @param {Object} [options.conversationContext] - Conversation-aware extraction context
548
+ */
533
549
  async create({
534
550
  content: e,
535
551
  memoryType: t = "semantic",
@@ -578,9 +594,31 @@ class z {
578
594
  async delete(e) {
579
595
  return this.api.delete(`/memory/${e}`);
580
596
  }
581
- async list({ limit: e = 50, offset: t = 0, type: s = null } = {}) {
582
- let r = `/memory/list?limit=${e}&offset=${t}`;
583
- return s && (r += `&memory_type=${s}`), this.api.get(r);
597
+ /**
598
+ * List memory items, optionally filtered by an exact metadata match.
599
+ *
600
+ * @param {object} [options]
601
+ * @param {number} [options.limit=50]
602
+ * @param {number} [options.offset=0]
603
+ * @param {string|null} [options.type=null] - NOTE: sent as `memory_type`, which the
604
+ * `/memory/list` route does not declare and therefore ignores. Pre-existing; kept as-is
605
+ * so nothing silently changes behaviour for callers already passing it.
606
+ * @param {string|null} [options.metadataKey=null] - GRAPH-API-1l. Metadata key to filter
607
+ * on. Nested keys use dot syntax (`profile.tier`). Must be paired with `metadataValue`;
608
+ * sending only one half is a 422.
609
+ * @param {string|null} [options.metadataValue=null] - Value the key must equal.
610
+ * @returns {Promise<{items: object[], total: number, limit: number, offset: number}>}
611
+ * `total` counts the filtered set, so it drives pagination directly.
612
+ */
613
+ async list({
614
+ limit: e = 50,
615
+ offset: t = 0,
616
+ type: s = null,
617
+ metadataKey: r = null,
618
+ metadataValue: n = null
619
+ } = {}) {
620
+ const i = new URLSearchParams({ limit: e, offset: t });
621
+ return s && i.append("memory_type", s), r != null && i.append("metadata_key", r), n != null && i.append("metadata_value", n), this.api.get(`/memory/list?${i}`);
584
622
  }
585
623
  /**
586
624
  * Search for memory items.
@@ -599,6 +637,11 @@ class z {
599
637
  * @param {boolean} [options.consolidationFirst=false] - When true (NEURO-1d), surface a
600
638
  * consolidated summary above the scattered source memories it consolidates — best for
601
639
  * synthesis queries. Opt-in; implies includeConsolidated.
640
+ * @param {string|Date|null} [options.asOfDate=null] - Transaction-time travel
641
+ * (PLAT-AUDITABLE-MEMORY-1): return what the system believed at this
642
+ * ISO-8601 instant. Date objects serialize to ISO automatically.
643
+ * @param {boolean} [options.includeSuperseded=false] - Keep superseded items
644
+ * visible in results (PLAT-AUDITABLE-MEMORY-1).
602
645
  * @param {boolean} [options.cite=false] - When true (RECALL-CITATIONS-1), the
603
646
  * envelope gains a `citations` array of `{n, item_id, item_type, preview, score, footnote_marker}`.
604
647
  * Empty `citations: []` when no results — distinguishes "no results" from "no citations requested".
@@ -611,9 +654,25 @@ class z {
611
654
  * present only under `cite: true`. Pre-LINEAGE-1 callers who indexed into a
612
655
  * bare array must read `response.results` instead.
613
656
  */
614
- async search(e, { topK: t = 5, enableHybrid: s = !0, memoryType: r = null, expertise: n = !1, cite: i = !1, decompose: o = !1, multiHop: c = !1, maxHops: u = 3, budgetMs: p = 1500, semanticHops: _ = !1, includeReference: $ = !1, includeConsolidated: T = !1, consolidationFirst: A = !1 } = {}) {
615
- const m = { query: e, top_k: t, enable_hybrid: s };
616
- return r && (m.memory_type = r), n && (m.expertise = !0), i && (m.cite = !0), o && (m.decompose = !0), c && (m.multi_hop = !0), c && u !== 3 && (m.max_hops = u), c && p !== 1500 && (m.budget_ms = p), c && _ && (m.semantic_hops = !0), $ && (m.include_reference = !0), T && (m.include_consolidated = !0), A && (m.consolidation_first = !0), this.api.post("/memory/search", m);
657
+ async search(e, { topK: t = 5, enableHybrid: s = !0, memoryType: r = null, expertise: n = !1, cite: i = !1, decompose: o = !1, multiHop: c = !1, maxHops: m = 3, budgetMs: p = 1500, semanticHops: $ = !1, includeReference: k = !1, includeConsolidated: U = !1, consolidationFirst: A = !1, asOfDate: g = null, includeSuperseded: C = !1 } = {}) {
658
+ const u = { query: e, top_k: t, enable_hybrid: s };
659
+ return r && (u.memory_type = r), n && (u.expertise = !0), i && (u.cite = !0), o && (u.decompose = !0), c && (u.multi_hop = !0), c && m !== 3 && (u.max_hops = m), c && p !== 1500 && (u.budget_ms = p), c && $ && (u.semantic_hops = !0), k && (u.include_reference = !0), U && (u.include_consolidated = !0), A && (u.consolidation_first = !0), g && (u.as_of_date = g instanceof Date ? g.toISOString() : g), C && (u.include_superseded = !0), this.api.post("/memory/search", u);
660
+ }
661
+ /**
662
+ * Get the complete audit answer for one memory (PLAT-AUDITABLE-MEMORY-1).
663
+ *
664
+ * Returns the explain-contract shape: identity + origin tier, every belief
665
+ * the system held over time (with chain hashes), supersession in both
666
+ * directions, lineage roots, decision provenance, and chain verification.
667
+ * A `chain_verified` of `null` means nothing to verify (legacy or
668
+ * unversioned) — it is NOT a tamper warning.
669
+ *
670
+ * @param {string} memoryId - Memory item ID.
671
+ * @returns {Promise<object>} Explain response
672
+ * (docs/features/PLAT-AUDITABLE-MEMORY-1/explain-contract.json).
673
+ */
674
+ async explain(e) {
675
+ return this.api.get(`/memory/${encodeURIComponent(e)}/explain`);
617
676
  }
618
677
  async getWorkingContext(e, t, { k: s = 20, maxTokens: r = null, strategy: n = null } = {}) {
619
678
  const i = {
@@ -645,9 +704,22 @@ class z {
645
704
  async getLinks(e) {
646
705
  return this.api.get(`/memory/${e}/links`);
647
706
  }
648
- async searchByMetadata(e, t, { memoryType: s = null } = {}) {
649
- const r = new URLSearchParams({ metadata_key: e, metadata_value: t });
650
- return s && r.append("memory_type", s), this.api.get(`/memory/by-metadata?${r}`);
707
+ /**
708
+ * Find memory items by exact metadata match.
709
+ *
710
+ * @deprecated GRAPH-API-1l — use {@link MemoryAPI#list} with `metadataKey` /
711
+ * `metadataValue` instead. It applies the same filter but adds pagination and an
712
+ * exact `total`. This method still works and its behaviour is unchanged; the two
713
+ * endpoints return slightly different item shapes, so migrate deliberately rather
714
+ * than by find-and-replace.
715
+ */
716
+ async searchByMetadata(e, t, { memoryType: s = null, limit: r = 25 } = {}) {
717
+ const n = new URLSearchParams({
718
+ metadata_key: e,
719
+ metadata_value: t,
720
+ limit: r
721
+ });
722
+ return s && n.append("memory_type", s), this.api.get(`/memory/by-metadata?${n}`);
651
723
  }
652
724
  async getNeighbors(e) {
653
725
  return this.api.get(`/memory/${e}/neighbors`);
@@ -776,7 +848,7 @@ class z {
776
848
  return this.api.get("/memory/clustering/stats");
777
849
  }
778
850
  }
779
- class E {
851
+ class O {
780
852
  constructor(e) {
781
853
  this.api = e;
782
854
  }
@@ -804,10 +876,10 @@ class E {
804
876
  evidenceIds: i = null,
805
877
  domain: o = null,
806
878
  tags: c = null,
807
- rejectedAlternatives: u = null,
879
+ rejectedAlternatives: m = null,
808
880
  rationale: p = null,
809
- constraints: _ = null,
810
- agentId: $ = null
881
+ constraints: $ = null,
882
+ agentId: k = null
811
883
  }) {
812
884
  return this.api.post("/memory/decisions/create", {
813
885
  content: e,
@@ -818,10 +890,10 @@ class E {
818
890
  evidence_ids: i,
819
891
  domain: o,
820
892
  tags: c,
821
- rejected_alternatives: u,
893
+ rejected_alternatives: m,
822
894
  rationale: p,
823
- constraints: _,
824
- agent_id: $
895
+ constraints: $,
896
+ agent_id: k
825
897
  });
826
898
  }
827
899
  /**
@@ -965,9 +1037,12 @@ class E {
965
1037
  /**
966
1038
  * Find existing decisions that may conflict with this one.
967
1039
  * @param {string} decisionId
1040
+ * @param {number} [minContest=0] - Minimum pairwise contest severity (0..1).
968
1041
  */
969
- async findConflicts(e) {
970
- return this.api.post(`/memory/decisions/${e}/conflicts`);
1042
+ async findConflicts(e, t = 0) {
1043
+ return this.api.post(
1044
+ `/memory/decisions/${e}/conflicts?min_contest=${encodeURIComponent(t)}`
1045
+ );
971
1046
  }
972
1047
  // --- Legacy reasoning proxies (kept for backward compatibility) ---
973
1048
  /**
@@ -991,7 +1066,7 @@ class E {
991
1066
  });
992
1067
  }
993
1068
  }
994
- class x {
1069
+ class F {
995
1070
  constructor(e) {
996
1071
  this.api = e;
997
1072
  }
@@ -1013,7 +1088,7 @@ class x {
1013
1088
  return t.confidence !== void 0 && (s.confidence = t.confidence), t.subject !== void 0 && (s.subject = t.subject), t.subjectType !== void 0 && (s.subject_type = t.subjectType), t.disposition !== void 0 && (s.disposition = t.disposition), t.formedFrom !== void 0 && (s.formed_from = t.formedFrom), t.domain !== void 0 && (s.domain = t.domain), t.agentId !== void 0 && (s.agent_id = t.agentId), this.api.post("/memory/opinions/create", s);
1014
1089
  }
1015
1090
  }
1016
- class O {
1091
+ class j {
1017
1092
  constructor(e) {
1018
1093
  this.api = e;
1019
1094
  }
@@ -1059,8 +1134,20 @@ class O {
1059
1134
  * Fetch edges for multiple node IDs in bulk.
1060
1135
  * @param {string[]} nodeIds
1061
1136
  */
1062
- async getEdgesBulk(e) {
1063
- return this.api.post("/memory/graph/edges", { node_ids: e });
1137
+ async getEdgesBulk(e, { includeProperties: t = !1 } = {}) {
1138
+ const s = t ? "?include_properties=true" : "";
1139
+ return this.api.post(`/memory/graph/edges${s}`, { node_ids: e });
1140
+ }
1141
+ /**
1142
+ * Bulk upsert graph nodes and edges, optionally replacing a node-ID prefix.
1143
+ * @param {Object} [params]
1144
+ * @param {Array<Object>} [params.nodes=[]] - Nodes with item_id, label, and properties.
1145
+ * @param {Array<Object>} [params.edges=[]] - Edges with source_id, target_id, edge_type, and properties.
1146
+ * @param {string|null} [params.deletePrefix=null] - Scoped node-ID prefix to delete before writing.
1147
+ */
1148
+ async bulkUpsert({ nodes: e = [], edges: t = [], deletePrefix: s = null } = {}) {
1149
+ const r = { nodes: e, edges: t };
1150
+ return s !== null && (r.delete_prefix = s), this.api.post("/memory/graph/bulk", r);
1064
1151
  }
1065
1152
  /**
1066
1153
  * Get Wikipedia grounding status for an entity node.
@@ -1136,7 +1223,7 @@ class O {
1136
1223
  );
1137
1224
  }
1138
1225
  }
1139
- class F {
1226
+ class H {
1140
1227
  constructor(e) {
1141
1228
  this.api = e;
1142
1229
  }
@@ -1178,7 +1265,7 @@ class F {
1178
1265
  return this.api.delete(`/memory/teams/${e}/members/${t}`);
1179
1266
  }
1180
1267
  }
1181
- class j {
1268
+ class B {
1182
1269
  constructor(e) {
1183
1270
  this.api = e;
1184
1271
  }
@@ -1200,7 +1287,7 @@ class j {
1200
1287
  return this.api.patch("/auth/llm-keys", e);
1201
1288
  }
1202
1289
  }
1203
- class H {
1290
+ class K {
1204
1291
  constructor(e) {
1205
1292
  this.api = e;
1206
1293
  }
@@ -1226,7 +1313,7 @@ class H {
1226
1313
  });
1227
1314
  }
1228
1315
  }
1229
- class B {
1316
+ class G {
1230
1317
  constructor(e) {
1231
1318
  this.api = e;
1232
1319
  }
@@ -1247,7 +1334,7 @@ class B {
1247
1334
  return this.api.delete(`/memory/api-keys/${e}`);
1248
1335
  }
1249
1336
  }
1250
- class K {
1337
+ class N {
1251
1338
  constructor(e) {
1252
1339
  this.api = e;
1253
1340
  }
@@ -1306,7 +1393,7 @@ class K {
1306
1393
  return this.api.get(`/memory/agents/${e}/evaluation/history${n ? "?" + n : ""}`);
1307
1394
  }
1308
1395
  }
1309
- class G {
1396
+ class D {
1310
1397
  constructor(e) {
1311
1398
  this.api = e;
1312
1399
  }
@@ -1320,7 +1407,7 @@ class G {
1320
1407
  return this.api.get("/usage/tiers");
1321
1408
  }
1322
1409
  }
1323
- class D {
1410
+ class J {
1324
1411
  constructor(e) {
1325
1412
  this.api = e;
1326
1413
  }
@@ -1337,7 +1424,7 @@ class D {
1337
1424
  return this.api.get("/memory/plugins");
1338
1425
  }
1339
1426
  }
1340
- class N {
1427
+ class W {
1341
1428
  constructor(e) {
1342
1429
  this.api = e;
1343
1430
  }
@@ -1360,7 +1447,7 @@ class N {
1360
1447
  return this.api.get("/memory/token-usage/current");
1361
1448
  }
1362
1449
  }
1363
- class J {
1450
+ class V {
1364
1451
  constructor(e) {
1365
1452
  this.api = e;
1366
1453
  }
@@ -1506,7 +1593,7 @@ class J {
1506
1593
  return this.api.get(`/memory/temporal/relationships/${e}/valid-periods`);
1507
1594
  }
1508
1595
  }
1509
- class V {
1596
+ class Y {
1510
1597
  constructor(e) {
1511
1598
  this.api = e;
1512
1599
  }
@@ -1575,7 +1662,7 @@ class V {
1575
1662
  return this.api.get("/memory/governance/summary");
1576
1663
  }
1577
1664
  }
1578
- class W {
1665
+ class Z {
1579
1666
  constructor(e) {
1580
1667
  this.api = e;
1581
1668
  }
@@ -1616,7 +1703,7 @@ class W {
1616
1703
  return this.api.post("/memory/evolution/reinforce/opinions");
1617
1704
  }
1618
1705
  }
1619
- class Y {
1706
+ class Q {
1620
1707
  constructor(e) {
1621
1708
  this.api = e;
1622
1709
  }
@@ -1714,7 +1801,7 @@ class Y {
1714
1801
  });
1715
1802
  }
1716
1803
  }
1717
- class Z {
1804
+ class X {
1718
1805
  constructor(e) {
1719
1806
  this.api = e;
1720
1807
  }
@@ -1768,7 +1855,7 @@ class Z {
1768
1855
  return this.api.get(`/memory/reasoning/traces/${e}`);
1769
1856
  }
1770
1857
  }
1771
- class Q {
1858
+ class ee {
1772
1859
  constructor(e) {
1773
1860
  this.api = e;
1774
1861
  }
@@ -2338,7 +2425,7 @@ class Q {
2338
2425
  return r !== void 0 && (n.expected_tier = r), this.api.post("/memory/ontology/queue/bulk", n);
2339
2426
  }
2340
2427
  }
2341
- class X {
2428
+ class te {
2342
2429
  constructor(e) {
2343
2430
  this.api = e;
2344
2431
  }
@@ -2367,7 +2454,7 @@ class X {
2367
2454
  return e !== null && (r.protected_attributes = e), t !== null && (r.sentiment_analysis = t), s !== null && (r.topic_analysis = s), this.api.post("/memory/analytics/bias", r);
2368
2455
  }
2369
2456
  }
2370
- class ee {
2457
+ class se {
2371
2458
  constructor(e) {
2372
2459
  this.api = e;
2373
2460
  }
@@ -2403,7 +2490,7 @@ class ee {
2403
2490
  return this.api.get("/memory/inference/rules");
2404
2491
  }
2405
2492
  }
2406
- class te {
2493
+ class re {
2407
2494
  constructor(e) {
2408
2495
  this.api = e;
2409
2496
  }
@@ -2519,7 +2606,7 @@ class te {
2519
2606
  return this.api.delete(`/memory/pipeline/configs/${e}`);
2520
2607
  }
2521
2608
  }
2522
- class se {
2609
+ class ne {
2523
2610
  constructor(e) {
2524
2611
  this.api = e;
2525
2612
  }
@@ -2545,7 +2632,7 @@ class se {
2545
2632
  return this.api.get(`/memory/archive/${e}`);
2546
2633
  }
2547
2634
  }
2548
- class re {
2635
+ class ie {
2549
2636
  constructor(e) {
2550
2637
  this.api = e;
2551
2638
  }
@@ -2704,7 +2791,7 @@ class re {
2704
2791
  return this.api.get(`/memory/zettel/by-relation/${e}/${t}?limit=${s}`);
2705
2792
  }
2706
2793
  }
2707
- class ne {
2794
+ class ae {
2708
2795
  constructor(e) {
2709
2796
  this.api = e;
2710
2797
  }
@@ -2740,7 +2827,7 @@ class ne {
2740
2827
  return this.api.get("/memory/procedures/matches/stats");
2741
2828
  }
2742
2829
  }
2743
- class ie {
2830
+ class oe {
2744
2831
  constructor(e) {
2745
2832
  this.api = e;
2746
2833
  }
@@ -2789,7 +2876,7 @@ class ie {
2789
2876
  return this.api.delete(`/memory/procedures/candidates/${e}/dismiss`);
2790
2877
  }
2791
2878
  }
2792
- class ae {
2879
+ class ce {
2793
2880
  constructor(e) {
2794
2881
  this.api = e;
2795
2882
  }
@@ -2844,7 +2931,7 @@ class ae {
2844
2931
  return this.api.get(`/memory/procedures/schemas/${e}`);
2845
2932
  }
2846
2933
  }
2847
- class oe {
2934
+ class ue {
2848
2935
  constructor(e) {
2849
2936
  this.api = e;
2850
2937
  }
@@ -2916,11 +3003,11 @@ class oe {
2916
3003
  return this.api.delete(`/memory/summary/${e}`);
2917
3004
  }
2918
3005
  }
2919
- class me {
3006
+ class le {
2920
3007
  constructor(e) {
2921
- this.auth = new L(e);
2922
- const t = new M(this.auth, { fetchFn: e.fetchFn });
2923
- this._api = t, this.memories = new z(t), this.decisions = new E(t), this.opinions = new x(t), this.graph = new O(t), this.teams = new F(t), this.profiles = new j(t), this.subscriptions = new H(t), this.authAPI = new B(t), this.agents = new K(t), this.usage = new G(t), this.insights = new D(t), this.tokenUsage = new N(t), this.temporal = new J(t), this.governance = new V(t), this.evolution = new W(t), this.reasoning = new Y(t), this.reasoningTraces = new Z(t), this.ontology = new Q(t), this.analytics = new X(t), this.validation = new ee(t), this.pipeline = new te(t), this.archive = new se(t), this.zettelkasten = new re(t), this.procedureMatches = new ne(t), this.procedureCandidates = new ie(t), this.procedureDrift = new ae(t), this.summaries = new oe(t);
3008
+ this.auth = new z(e);
3009
+ const t = new E(this.auth, { fetchFn: e.fetchFn });
3010
+ this._api = t, this.memories = new x(t), this.decisions = new O(t), this.opinions = new F(t), this.graph = new j(t), this.teams = new H(t), this.profiles = new B(t), this.subscriptions = new K(t), this.authAPI = new G(t), this.agents = new N(t), this.usage = new D(t), this.insights = new J(t), this.tokenUsage = new W(t), this.temporal = new V(t), this.governance = new Y(t), this.evolution = new Z(t), this.reasoning = new Q(t), this.reasoningTraces = new X(t), this.ontology = new ee(t), this.analytics = new te(t), this.validation = new se(t), this.pipeline = new re(t), this.archive = new ne(t), this.zettelkasten = new ie(t), this.procedureMatches = new ae(t), this.procedureCandidates = new oe(t), this.procedureDrift = new ce(t), this.summaries = new ue(t);
2924
3011
  }
2925
3012
  setTeamId(e) {
2926
3013
  this.auth.tokenManager.setTeamId(e), this.auth.notifyListeners();
@@ -2947,35 +3034,35 @@ class me {
2947
3034
  }
2948
3035
  export {
2949
3036
  h as A,
2950
- M as B,
2951
- E as D,
2952
- W as E,
2953
- V as G,
2954
- D as I,
2955
- z as M,
2956
- Q as O,
2957
- te as P,
2958
- Y as R,
2959
- me as S,
2960
- F as T,
2961
- G as U,
2962
- ee as V,
2963
- re as Z,
2964
- K as a,
2965
- X as b,
2966
- se as c,
2967
- B as d,
2968
- L as e,
2969
- O as f,
2970
- x as g,
2971
- ie as h,
2972
- ne as i,
2973
- j,
2974
- Z as k,
2975
- H as l,
2976
- J as m,
2977
- C as n,
2978
- N as o,
2979
- P as p,
2980
- q
3037
+ E as B,
3038
+ O as D,
3039
+ Z as E,
3040
+ Y as G,
3041
+ J as I,
3042
+ x as M,
3043
+ ee as O,
3044
+ re as P,
3045
+ Q as R,
3046
+ le as S,
3047
+ H as T,
3048
+ D as U,
3049
+ se as V,
3050
+ ie as Z,
3051
+ N as a,
3052
+ te as b,
3053
+ ne as c,
3054
+ G as d,
3055
+ z as e,
3056
+ j as f,
3057
+ F as g,
3058
+ oe as h,
3059
+ ae as i,
3060
+ B as j,
3061
+ X as k,
3062
+ K as l,
3063
+ V as m,
3064
+ L as n,
3065
+ W as o,
3066
+ q as p,
3067
+ M as q
2981
3068
  };
package/dist/core.js CHANGED
@@ -1,4 +1,4 @@
1
- import { A as e, a as r, d as A, e as I, B as P, D as n, f as o, I as t, M as i, j as g, p as M, q as h, S as m, l as S, T as f, n as p, U as l } from "./core-D1Y88paM.js";
1
+ import { A as e, a as r, d as A, e as I, B as P, D as n, f as o, I as t, M as i, j as g, p as M, q as h, S as m, l as S, T as f, n as p, U as l } from "./core-BEScfRuq.js";
2
2
  export {
3
3
  e as APIError,
4
4
  r as AgentAPI,
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { A as f, a as u, b as A, c as b, d as P, e as h, D as I, E as g, G as x, f as p, I as w, M as m, O as k, g as v, P as T, h as B, i as y, j as C, R as E, k as S, S as R, l as F, T as M, m as L, n as O, o as G, U, V as $, Z as D } from "./core-D1Y88paM.js";
1
+ import { A as f, a as u, b as A, c as b, d as P, e as h, D as I, E as g, G as x, f as p, I as w, M as m, O as k, g as v, P as T, h as B, i as y, j as C, R as E, k as S, S as R, l as F, T as M, m as L, n as O, o as G, U, V as $, Z as D } from "./core-BEScfRuq.js";
2
2
  const i = {
3
3
  variables: {
4
4
  colorBackground: "transparent",
@@ -0,0 +1,228 @@
1
+ import { useEffect as m } from "react";
2
+ import u from "posthog-js";
3
+ function y() {
4
+ var e;
5
+ if (typeof import.meta < "u")
6
+ return "production";
7
+ if (typeof process < "u")
8
+ return (e = process.env) == null ? void 0 : e.NODE_ENV;
9
+ }
10
+ function E(e) {
11
+ return e === "production" || e === "test" ? e : "development";
12
+ }
13
+ const g = /(url|referrer|href)/i;
14
+ function b(e) {
15
+ if (typeof e != "string" || !/^https?:\/\//i.test(e))
16
+ return e;
17
+ try {
18
+ const t = new URL(e);
19
+ return `${t.origin}${t.pathname}`;
20
+ } catch {
21
+ return null;
22
+ }
23
+ }
24
+ function p(e) {
25
+ if (!e || typeof e != "object")
26
+ return e;
27
+ const t = Array.isArray(e) ? [...e] : { ...e };
28
+ for (const [r, n] of Object.entries(t))
29
+ n && typeof n == "object" ? t[r] = p(n) : g.test(r) && (t[r] = b(n));
30
+ return t;
31
+ }
32
+ function h(e) {
33
+ return !e || typeof e != "object" ? e : { ...e, properties: p(e.properties) };
34
+ }
35
+ function U({ app: e, apiKey: t, apiHost: r }) {
36
+ const n = typeof t == "string" && t.trim() ? t.trim() : null, c = E(y());
37
+ return {
38
+ apiKey: n,
39
+ options: {
40
+ api_host: r,
41
+ autocapture: !1,
42
+ // PostHog's exception autocapture hooks window.onerror / unhandledrejection
43
+ // and ships the raw message, stack, and filenames — it never passes through
44
+ // our sanitized captureException seam, so an error string built from a search
45
+ // query or memory content would be sent verbatim. Explicit capture only.
46
+ capture_exceptions: !1,
47
+ capture_pageview: "history_change",
48
+ cross_subdomain_cookie: !0,
49
+ defaults: "2025-05-24",
50
+ // Session replay is ON but fully masked (D3 revision 2026-07-22):
51
+ // layout/navigation are visible, memory content, search queries, and
52
+ // chat text are not.
53
+ //
54
+ // maskTextSelector: '*' is the load-bearing flag. The top-level
55
+ // mask_all_text / mask_all_element_attributes options do NOT reach the
56
+ // recorder — posthog-js reads them only in autocapture.js and
57
+ // dead-clicks-autocapture.js (see their `maskAllText:` usage). The replay
58
+ // recorder resolves masking solely from session_recording.{maskAllInputs,
59
+ // maskTextSelector, blockSelector}. They are kept here as defense in depth
60
+ // for the autocapture surfaces, which remote config can switch on.
61
+ disable_session_recording: !1,
62
+ mask_all_text: !0,
63
+ mask_all_element_attributes: !0,
64
+ session_recording: {
65
+ maskAllInputs: !0,
66
+ maskTextSelector: "*"
67
+ },
68
+ // The PostHog project has consoleLogRecordingEnabled: true server-side, which
69
+ // pipes console output into the replay. Apps log raw payloads while debugging
70
+ // (Maya logs recalled memory content), so that is a content channel masking
71
+ // does not cover. Pin it off from the client, which takes precedence.
72
+ enable_recording_console_log: !1,
73
+ // $current_url / $referrer and their $initial_* variants are attached by
74
+ // PostHog to every event, replay snapshot, and identify — outside the
75
+ // product-event allowlist. Strip query strings and fragments so record
76
+ // identifiers cannot ride along.
77
+ before_send: h,
78
+ loaded: (i) => {
79
+ if (!(!n || typeof (i == null ? void 0 : i.register) != "function"))
80
+ try {
81
+ i.register({ app: e, environment: c });
82
+ } catch {
83
+ }
84
+ }
85
+ }
86
+ };
87
+ }
88
+ function v() {
89
+ return !u || u.__loaded !== !0 ? null : u;
90
+ }
91
+ function x({ user: e, isAuthenticated: t, workspaceId: r }) {
92
+ const n = e == null ? void 0 : e.id, c = e == null ? void 0 : e.email, i = e == null ? void 0 : e.subscription_tier, s = e == null ? void 0 : e.tenant_id;
93
+ return m(() => {
94
+ var f, _, l, d;
95
+ const o = v();
96
+ if (o)
97
+ try {
98
+ if (!t || !n) {
99
+ (f = o.unregister) == null || f.call(o, "workspace_id");
100
+ return;
101
+ }
102
+ r ? (_ = o.register) == null || _.call(o, { workspace_id: r }) : (l = o.unregister) == null || l.call(o, "workspace_id"), (d = o.identify) == null || d.call(o, n, {
103
+ email: c,
104
+ plan: i,
105
+ tenant_id: s
106
+ });
107
+ } catch {
108
+ }
109
+ }, [c, t, i, s, n, r]), null;
110
+ }
111
+ const z = Object.freeze({
112
+ evolution_triggered: Object.freeze(["error_count", "evolver_count", "evolver_keys", "executed_count", "profile_present", "skipped_count", "stop_on_error"]),
113
+ memories_cleared: Object.freeze(["deleted_count", "nuclear"]),
114
+ memory_created: Object.freeze(["created_count", "failed_count", "has_collection", "memory_type", "profile_present", "source", "tag_count", "use_pipeline"]),
115
+ memory_deleted: Object.freeze(["memory_type", "operation", "source"]),
116
+ memory_edited: Object.freeze(["changed_fields", "has_collection", "memory_type", "tag_count", "write_mode"]),
117
+ search_performed: Object.freeze(["budget_bucket", "cite", "decompose", "hybrid", "max_hops", "memory_type", "min_score_bucket", "multi_hop", "result_count", "semantic_hops", "surface", "top_k"]),
118
+ studio_pipeline_saved: Object.freeze(["enricher_count", "evolver_count", "grounder_count", "override_key_count", "save_surface", "stage_count", "storage"])
119
+ }), O = Object.freeze({
120
+ memory_deleted: Object.freeze({
121
+ source: Object.freeze(["user", "cli", "api", "import", "signup", "managed", "mcp", "pipeline", "hook", "lifecycle", "observe", "evolver", "code", "enricher", "conversation", "structured", "version", "snapshot", "unknown"])
122
+ }),
123
+ search_performed: Object.freeze({
124
+ min_score_bucket: Object.freeze(["lt50", "lt80", "gte80"])
125
+ })
126
+ }), j = /* @__PURE__ */ new Set([
127
+ "body",
128
+ "content",
129
+ "context",
130
+ "error",
131
+ "message",
132
+ "query",
133
+ "response",
134
+ "result",
135
+ "tag_values",
136
+ "tags",
137
+ "url"
138
+ ]), k = /* @__PURE__ */ new Set([
139
+ "AggregateError",
140
+ "Error",
141
+ "EvalError",
142
+ "RangeError",
143
+ "ReferenceError",
144
+ "SyntaxError",
145
+ "TypeError",
146
+ "URIError"
147
+ ]), R = ["source", "component", "operation", "method"];
148
+ function a() {
149
+ return !u || u.__loaded !== !0 ? null : u;
150
+ }
151
+ function A(e) {
152
+ return j.has(e) ? !0 : /(^|_)(id|ids|name|names|tag|tags)$/.test(e);
153
+ }
154
+ function S(e, t, r) {
155
+ var c;
156
+ const n = (c = O[e]) == null ? void 0 : c[t];
157
+ return !n || n.includes(r);
158
+ }
159
+ function w(e) {
160
+ try {
161
+ return k.has(e == null ? void 0 : e.name) ? e.name : "Error";
162
+ } catch {
163
+ return "Error";
164
+ }
165
+ }
166
+ function N(e) {
167
+ const t = new Error();
168
+ return delete t.message, delete t.stack, Object.defineProperty(t, "name", {
169
+ configurable: !0,
170
+ enumerable: !0,
171
+ value: w(e)
172
+ }), t;
173
+ }
174
+ function T(e) {
175
+ const t = {};
176
+ if (!e || typeof e != "object")
177
+ return t;
178
+ for (const r of R)
179
+ typeof e[r] == "string" && (t[r] = e[r]);
180
+ return typeof e.status == "number" && Number.isFinite(e.status) && (t.status = e.status), t;
181
+ }
182
+ function I(e, t = {}) {
183
+ const r = z[e], n = a();
184
+ if (!r || !n || typeof n.capture != "function")
185
+ return !1;
186
+ try {
187
+ const c = {};
188
+ for (const i of r) {
189
+ if (A(i))
190
+ continue;
191
+ const s = t == null ? void 0 : t[i];
192
+ s === void 0 || !S(e, i, s) || (c[i] = s);
193
+ }
194
+ return n.capture(e, c), !0;
195
+ } catch {
196
+ return !1;
197
+ }
198
+ }
199
+ function D(e, t = {}) {
200
+ const r = a();
201
+ if (!r || typeof r.captureException != "function")
202
+ return !1;
203
+ try {
204
+ return r.captureException(
205
+ N(e),
206
+ T(t)
207
+ ), !0;
208
+ } catch {
209
+ return !1;
210
+ }
211
+ }
212
+ function K() {
213
+ const e = a();
214
+ if (!e || typeof e.reset != "function")
215
+ return !1;
216
+ try {
217
+ return e.reset(), !0;
218
+ } catch {
219
+ return !1;
220
+ }
221
+ }
222
+ export {
223
+ x as AnalyticsIdentity,
224
+ D as captureException,
225
+ I as captureProductEvent,
226
+ U as createAnalyticsConfig,
227
+ K as resetAnalytics
228
+ };
package/dist/react.js CHANGED
@@ -1,64 +1,66 @@
1
- import h, { createContext as d, useRef as y, useState as v, useEffect as b, useCallback as c, useContext as f } from "react";
2
- import { S as x } from "./core-D1Y88paM.js";
3
- const m = d(null), g = d(null);
4
- function U({ children: e, ...r }) {
5
- const n = y(null);
6
- n.current || (n.current = new x(r));
7
- const t = n.current, [u, o] = v({
1
+ import h, { createContext as d, useRef as I, useState as p, useEffect as C, useCallback as c, useContext as g } from "react";
2
+ import { S as y } from "./core-BEScfRuq.js";
3
+ const m = d(null), f = d(null);
4
+ function b({ children: e, ...r }) {
5
+ const n = I(null);
6
+ n.current || (n.current = new y(r));
7
+ const t = n.current, [o, u] = p({
8
8
  isAuthenticated: t.auth.isAuthenticated(),
9
9
  user: t.auth.getCurrentUser(),
10
10
  token: t.auth.getCurrentToken(),
11
11
  tenantId: t.auth.getTenantId(),
12
+ workspaceId: t.auth.tokenManager.getTeamId(),
12
13
  loading: !1,
13
14
  error: null
14
15
  });
15
- b(() => t.auth.addListener((a) => {
16
- o((C) => ({
17
- ...C,
18
- isAuthenticated: a.isAuthenticated,
19
- user: a.user,
20
- token: a.token,
21
- tenantId: a.tenantId
16
+ C(() => t.auth.addListener((i) => {
17
+ u((k) => ({
18
+ ...k,
19
+ isAuthenticated: i.isAuthenticated,
20
+ user: i.user,
21
+ token: i.token,
22
+ tenantId: i.tenantId,
23
+ workspaceId: i.workspaceId
22
24
  }));
23
25
  }), [t]);
24
- const s = c(async () => {
26
+ const a = c(async () => {
25
27
  await t.auth.logout();
26
- }, [t]), A = c((i) => t.auth.hasRole(i), [t]), S = c((i) => t.auth.getLoginUrl(i), [t]), w = {
27
- ...u,
28
- logout: s,
29
- hasRole: A,
30
- getLoginUrl: S
28
+ }, [t]), w = c((s) => t.auth.hasRole(s), [t]), A = c((s) => t.auth.getLoginUrl(s), [t]), S = {
29
+ ...o,
30
+ logout: a,
31
+ hasRole: w,
32
+ getLoginUrl: A
31
33
  };
32
- return /* @__PURE__ */ h.createElement(m.Provider, { value: w }, /* @__PURE__ */ h.createElement(g.Provider, { value: t }, e));
34
+ return /* @__PURE__ */ h.createElement(m.Provider, { value: S }, /* @__PURE__ */ h.createElement(f.Provider, { value: t }, e));
33
35
  }
34
36
  function l() {
35
- const e = f(m);
37
+ const e = g(m);
36
38
  if (!e)
37
39
  throw new Error("useAuth must be used within a SmartMemoryProvider");
38
40
  return e;
39
41
  }
40
- function k() {
41
- const { isAuthenticated: e, user: r, token: n, tenantId: t, loading: u, error: o } = l();
42
- return { isAuthenticated: e, user: r, token: n, tenantId: t, loading: u, error: o };
42
+ function x() {
43
+ const { isAuthenticated: e, user: r, token: n, tenantId: t, workspaceId: o, loading: u, error: a } = l();
44
+ return { isAuthenticated: e, user: r, token: n, tenantId: t, workspaceId: o, loading: u, error: a };
43
45
  }
44
- function p() {
46
+ function R() {
45
47
  const { login: e, logout: r, hasRole: n, getLoginUrl: t } = l();
46
48
  return { login: e, logout: r, hasRole: n, getLoginUrl: t };
47
49
  }
48
- function E() {
49
- const e = f(g);
50
+ function U() {
51
+ const e = g(f);
50
52
  if (!e)
51
53
  throw new Error("useSmartMemory must be used within a SmartMemoryProvider");
52
54
  return e;
53
55
  }
54
- function I({ children: e, fallback: r = null, redirectToLogin: n = !1 }) {
55
- const { isAuthenticated: t, loading: u, getLoginUrl: o } = l();
56
- if (u) return r;
56
+ function E({ children: e, fallback: r = null, redirectToLogin: n = !1 }) {
57
+ const { isAuthenticated: t, loading: o, getLoginUrl: u } = l();
58
+ if (o) return r;
57
59
  if (!t) {
58
60
  if (n)
59
61
  try {
60
- const s = o();
61
- window.location.href = s;
62
+ const a = u();
63
+ window.location.href = a;
62
64
  } catch {
63
65
  }
64
66
  return r;
@@ -67,11 +69,11 @@ function I({ children: e, fallback: r = null, redirectToLogin: n = !1 }) {
67
69
  }
68
70
  export {
69
71
  m as AuthContext,
70
- I as AuthWrapper,
71
- g as ClientContext,
72
- U as SmartMemoryProvider,
72
+ E as AuthWrapper,
73
+ f as ClientContext,
74
+ b as SmartMemoryProvider,
73
75
  l as useAuth,
74
- p as useAuthActions,
75
- k as useAuthState,
76
- E as useSmartMemory
76
+ R as useAuthActions,
77
+ x as useAuthState,
78
+ U as useSmartMemory
77
79
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartmemory/sdk-js",
3
- "version": "1.4.53",
3
+ "version": "1.4.59",
4
4
  "description": "Unified JavaScript SDK for SmartMemory API — auth + API client for all frontends",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -18,6 +18,10 @@
18
18
  "development": "./src/react/index.js",
19
19
  "default": "./dist/react.js"
20
20
  },
21
+ "./react/analytics": {
22
+ "development": "./src/react/analytics/index.js",
23
+ "default": "./dist/react/analytics.js"
24
+ },
21
25
  "./fetch": {
22
26
  "development": "./src/fetch/index.js",
23
27
  "default": "./dist/fetch.js"
@@ -35,13 +39,17 @@
35
39
  "test": "vitest run",
36
40
  "test:watch": "vitest",
37
41
  "test:coverage": "vitest run --coverage",
38
- "lint": "eslint src/ tests/"
42
+ "lint": "eslint src/ tests/ scripts/"
39
43
  },
40
44
  "peerDependencies": {
45
+ "posthog-js": "^1.313.0",
41
46
  "react": ">=18.0.0",
42
47
  "react-dom": ">=18.0.0"
43
48
  },
44
49
  "peerDependenciesMeta": {
50
+ "posthog-js": {
51
+ "optional": true
52
+ },
45
53
  "react": {
46
54
  "optional": true
47
55
  },
@@ -57,6 +65,7 @@
57
65
  "eslint": "^9.0.0",
58
66
  "globals": "^16.0.0",
59
67
  "jsdom": "^25.0.0",
68
+ "posthog-js": "^1.313.0",
60
69
  "react": "^18.3.0",
61
70
  "react-dom": "^18.3.0",
62
71
  "vite": "^6.0.0",