@smartmemory/sdk-js 1.4.119 → 1.4.120

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/dist/core.js CHANGED
@@ -1,22 +1,23 @@
1
- import { A as e, a as r, d as A, e as I, B as P, D as o, f as n, I as t, M as g, O as i, j as m, q as M, r as h, l as f, m as l, T as p, o as S, U as c, W as u } from "./core-BLQpDtod.js";
1
+ import { A as e, a as r, d as A, e as o, B as I, D as P, f as n, I as t, M as g, O as i, j as m, q as M, l as f, m as h, T as p, o as l, U as S, W as c } from "./core-DUg_hHl8.js";
2
+ import { R as y } from "./index-BKI1h_Wn.js";
2
3
  export {
3
4
  e as APIError,
4
5
  r as AgentAPI,
5
6
  A as AuthAPI,
6
- I as AuthCore,
7
- P as BaseAPI,
8
- o as DecisionAPI,
7
+ o as AuthCore,
8
+ I as BaseAPI,
9
+ P as DecisionAPI,
9
10
  n as GraphAPI,
10
11
  t as InsightsAPI,
11
12
  g as MemoryAPI,
12
13
  i as OntologyAPI,
13
14
  m as ProfileAPI,
14
- M as RefreshManager,
15
- h as SSOManager,
15
+ y as RefreshManager,
16
+ M as SSOManager,
16
17
  f as SmartMemoryClient,
17
- l as SubscriptionAPI,
18
+ h as SubscriptionAPI,
18
19
  p as TeamAPI,
19
- S as TokenManager,
20
- c as UsageAPI,
21
- u as WorkspaceAPI
20
+ l as TokenManager,
21
+ S as UsageAPI,
22
+ c as WorkspaceAPI
22
23
  };
package/dist/fetch.js CHANGED
@@ -1,43 +1,24 @@
1
- function l(e) {
2
- return async function(s, t = {}) {
3
- var c;
4
- const i = {
5
- "Content-Type": "application/json",
6
- ...e.getAuthHeaders(t.headers)
7
- }, n = await fetch(s, e.getRequestOptions({ ...t, headers: i }));
8
- if (n.status === 401 && !t.__isRetry)
9
- try {
10
- await e.refreshToken();
11
- const a = {
12
- "Content-Type": "application/json",
13
- ...e.getAuthHeaders(t.headers)
14
- };
15
- return fetch(
16
- s,
17
- e.getRequestOptions({ ...t, headers: a, __isRetry: !0 })
18
- );
19
- } catch {
20
- throw (c = e.clearLocalAuth) == null || c.call(e), new Error("Authentication required");
21
- }
22
- return n;
1
+ import { r as u, i as m, f as R } from "./recovery-JyUr2KHh.js";
2
+ function b(c, { fetchFn: a, apiBases: h = [] } = {}) {
3
+ return async function(t, n = {}) {
4
+ const s = a || globalThis.fetch.bind(globalThis), r = u(t);
5
+ if (!m(c, r, h) || /\/auth(?:\/|$)/.test(r.pathname))
6
+ return s(t, n);
7
+ const e = t instanceof Request ? new Request(t, n) : null, l = (e == null ? void 0 : e.headers) || n.headers, d = (e == null ? void 0 : e.signal) || n.signal;
8
+ return R(c, (i) => {
9
+ const f = c.getAuthHeaders(l), g = c.getRequestOptions({ ...n, method: (e == null ? void 0 : e.method) || n.method, headers: f, ...i ? { __isRetry: !0 } : {} });
10
+ return s(e ? e.clone() : t, g);
11
+ }, { source: r.href, signal: d });
23
12
  };
24
13
  }
25
- function f(e, { urlPatterns: r = [] } = {}) {
26
- const s = globalThis.fetch, t = s.bind(globalThis);
27
- return globalThis.fetch = async function(n, c = {}) {
28
- const a = typeof n == "string" ? n : n.toString();
29
- if (!(r.length === 0 || r.some((o) => a.includes(o))))
30
- return t(n, c);
31
- const h = {
32
- ...c.headers,
33
- ...e.getAuthHeaders()
34
- };
35
- return t(n, { ...c, headers: h });
36
- }, function() {
37
- globalThis.fetch = s;
14
+ function F(c, { urlPatterns: a = [], fetchFn: h, apiBases: o = [] } = {}) {
15
+ const t = h || globalThis.fetch.bind(globalThis), n = b(c, { fetchFn: t, apiBases: o });
16
+ return (s, r) => {
17
+ const e = s instanceof Request ? s.url : String(s);
18
+ return !a.length || a.some((l) => e.includes(l)) ? n(s, r) : t(s, r);
38
19
  };
39
20
  }
40
21
  export {
41
- l as createAuthFetch,
42
- f as installInterceptor
22
+ b as createAuthFetch,
23
+ F as installInterceptor
43
24
  };
@@ -0,0 +1,107 @@
1
+ var _ = (t) => {
2
+ throw TypeError(t);
3
+ };
4
+ var O = (t, e, s) => e.has(t) || _("Cannot " + s);
5
+ var i = (t, e, s) => (O(t, e, "read from private field"), s ? s.call(t) : e.get(t)), f = (t, e, s) => e.has(t) ? _("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, s), d = (t, e, s, o) => (O(t, e, "write to private field"), o ? o.call(t, s) : e.set(t, s), s), k = (t, e, s) => (O(t, e, "access private method"), s);
6
+ var l, h, a, u, S;
7
+ class M {
8
+ constructor() {
9
+ f(this, u);
10
+ f(this, l, /* @__PURE__ */ new Set());
11
+ f(this, h, /* @__PURE__ */ new Map());
12
+ f(this, a, !1);
13
+ }
14
+ get snapshot() {
15
+ return Object.freeze({
16
+ status: i(this, a) ? "signed_out" : i(this, h).size ? "reconnecting" : "connected",
17
+ reason: i(this, a) ? "Authentication required" : [...i(this, h).values()].at(-1) || null
18
+ });
19
+ }
20
+ subscribe(e) {
21
+ return i(this, l).add(e), e(this.snapshot), () => i(this, l).delete(e);
22
+ }
23
+ report(e, s) {
24
+ s ? i(this, h).set(e, s) : i(this, h).delete(e), k(this, u, S).call(this);
25
+ }
26
+ signedOut() {
27
+ d(this, a, !0), k(this, u, S).call(this);
28
+ }
29
+ authenticated() {
30
+ i(this, a) && i(this, h).clear(), d(this, a, !1), k(this, u, S).call(this);
31
+ }
32
+ }
33
+ l = new WeakMap(), h = new WeakMap(), a = new WeakMap(), u = new WeakSet(), S = function() {
34
+ const e = this.snapshot;
35
+ for (const s of i(this, l))
36
+ try {
37
+ s(e);
38
+ } catch (o) {
39
+ console.warn("[connection] Listener failed", o);
40
+ }
41
+ };
42
+ class g extends Error {
43
+ constructor(e, s = 0, o = !0) {
44
+ super(e), this.name = "SessionRefreshError", this.status = s, this.recoverable = o;
45
+ }
46
+ }
47
+ var c, b, E;
48
+ class C {
49
+ /**
50
+ * @param {Object} options
51
+ * @param {string} options.apiBaseUrl
52
+ * @param {string} options.refreshEndpoint
53
+ * @param {import('./TokenManager.js').TokenManager} options.tokenManager
54
+ * @param {boolean} [options.useCookieAuth=false]
55
+ * @param {function(string): void} options.onTokenRefreshed
56
+ * @param {function(): void} options.onRefreshFailed
57
+ */
58
+ constructor({ apiBaseUrl: e, refreshEndpoint: s, tokenManager: o, useCookieAuth: T = !1, onTokenRefreshed: p, onRefreshFailed: w, getRequestOptions: R, fetchFn: n, connection: r, getSessionKey: y }) {
59
+ f(this, b);
60
+ f(this, c, null);
61
+ this.getRequestOptions = R || ((m) => m), this.fetchFn = n, this.getSessionKey = y, this.connection = r, this.apiBaseUrl = e, this.refreshEndpoint = s, this.tokenManager = o, this.useCookieAuth = T, this.onTokenRefreshed = p, this.onRefreshFailed = w;
62
+ }
63
+ async refresh() {
64
+ if (i(this, c))
65
+ return i(this, c);
66
+ d(this, c, k(this, b, E).call(this));
67
+ try {
68
+ return await i(this, c);
69
+ } finally {
70
+ d(this, c, null);
71
+ }
72
+ }
73
+ }
74
+ c = new WeakMap(), b = new WeakSet(), E = async function() {
75
+ var p, w, R;
76
+ const e = (p = this.getSessionKey) == null ? void 0 : p.call(this), s = () => {
77
+ var n;
78
+ if (((n = this.getSessionKey) == null ? void 0 : n.call(this)) !== e) throw new DOMException("Session changed during refresh", "AbortError");
79
+ }, o = this.tokenManager.getRefreshToken();
80
+ if (!o && !this.useCookieAuth)
81
+ throw console.warn("[auth] No refresh token available; authentication required"), this.onRefreshFailed(), new g("No refresh token", 401, !1);
82
+ const T = JSON.stringify(o ? { refresh_token: o } : {});
83
+ try {
84
+ const n = await (this.fetchFn || globalThis.fetch.bind(globalThis))(`${this.apiBaseUrl}${this.refreshEndpoint}`, this.getRequestOptions({
85
+ ...this.useCookieAuth ? { credentials: "include" } : {},
86
+ method: "POST",
87
+ headers: { "Content-Type": "application/json" },
88
+ body: T
89
+ }));
90
+ if (s(), !n.ok) {
91
+ const y = n.status === 401 || n.status === 403;
92
+ throw y && this.onRefreshFailed(), new g(`Refresh failed: ${n.status}`, n.status, !y);
93
+ }
94
+ const r = await n.json();
95
+ if (s(), typeof r.access_token != "string" || !r.access_token) throw new g("Refresh response has no access token");
96
+ return this.tokenManager.setAccessToken(r.access_token), r.refresh_token && this.tokenManager.setRefreshToken(r.refresh_token), this.onTokenRefreshed(r.access_token), (w = this.connection) == null || w.report("refresh", null), r.access_token;
97
+ } catch (n) {
98
+ if (n.name === "AbortError") throw n;
99
+ const r = n instanceof g ? n : new g(n.message);
100
+ throw console.warn("[auth] Session refresh failed", r), r.recoverable && ((R = this.connection) == null || R.report("refresh", r.message)), r;
101
+ }
102
+ };
103
+ export {
104
+ M as C,
105
+ C as R,
106
+ g as S
107
+ };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { A as f, a as u, b as A, c as P, d as b, e as I, D as h, E as g, G as x, f as p, I as w, L as k, M as m, O as v, g as T, P as B, h as y, i as C, j as S, R as E, k as R, S as F, l as L, m as M, T as O, n as G, o as U, p as W, U as $, V as D, W as V, Z } from "./core-BLQpDtod.js";
1
+ import { A as f, a as u, b as A, c as P, d as b, e as I, D as h, E as g, G as x, f as p, I as w, L as k, M as m, O as v, g as T, P as B, h as y, i as C, j as S, R as E, k as R, S as F, l as L, m as M, T as O, n as G, o as U, p as W, U as $, V as D, W as V, Z } from "./core-DUg_hHl8.js";
2
2
  const i = {
3
3
  variables: {
4
4
  colorBackground: "transparent",
package/dist/progress.js CHANGED
@@ -1,68 +1,68 @@
1
- async function _(r, n) {
2
- const t = r.getReader();
3
- let e;
4
- for (; !(e = await t.read()).done; )
5
- n(e.value);
1
+ async function _(e, t) {
2
+ const r = e.getReader();
3
+ let n;
4
+ for (; !(n = await r.read()).done; )
5
+ t(n.value);
6
6
  }
7
- function R(r) {
8
- let n, t, e, o = !1;
9
- return function(s) {
10
- n === void 0 ? (n = s, t = 0, e = -1) : n = L(n, s);
11
- const i = n.length;
12
- let a = 0;
13
- for (; t < i; ) {
14
- o && (n[t] === 10 && (a = ++t), o = !1);
7
+ function $(e) {
8
+ let t, r, n, i = !1;
9
+ return function(d) {
10
+ t === void 0 ? (t = d, r = 0, n = -1) : t = D(t, d);
11
+ const o = t.length;
12
+ let s = 0;
13
+ for (; r < o; ) {
14
+ i && (t[r] === 10 && (s = ++r), i = !1);
15
15
  let c = -1;
16
- for (; t < i && c === -1; ++t)
17
- switch (n[t]) {
16
+ for (; r < o && c === -1; ++r)
17
+ switch (t[r]) {
18
18
  case 58:
19
- e === -1 && (e = t - a);
19
+ n === -1 && (n = r - s);
20
20
  break;
21
21
  case 13:
22
- o = !0;
22
+ i = !0;
23
23
  case 10:
24
- c = t;
24
+ c = r;
25
25
  break;
26
26
  }
27
27
  if (c === -1)
28
28
  break;
29
- r(n.subarray(a, c), e), a = t, e = -1;
29
+ e(t.subarray(s, c), n), s = r, n = -1;
30
30
  }
31
- a === i ? n = void 0 : a !== 0 && (n = n.subarray(a), t -= a);
31
+ s === o ? t = void 0 : s !== 0 && (t = t.subarray(s), r -= s);
32
32
  };
33
33
  }
34
- function P(r, n, t) {
35
- let e = A();
36
- const o = new TextDecoder();
37
- return function(s, i) {
38
- if (s.length === 0)
39
- t == null || t(e), e = A();
40
- else if (i > 0) {
41
- const a = o.decode(s.subarray(0, i)), c = i + (s[i + 1] === 32 ? 2 : 1), d = o.decode(s.subarray(c));
42
- switch (a) {
34
+ function N(e, t, r) {
35
+ let n = C();
36
+ const i = new TextDecoder();
37
+ return function(d, o) {
38
+ if (d.length === 0)
39
+ r == null || r(n), n = C();
40
+ else if (o > 0) {
41
+ const s = i.decode(d.subarray(0, o)), c = o + (d[o + 1] === 32 ? 2 : 1), y = i.decode(d.subarray(c));
42
+ switch (s) {
43
43
  case "data":
44
- e.data = e.data ? e.data + `
45
- ` + d : d;
44
+ n.data = n.data ? n.data + `
45
+ ` + y : y;
46
46
  break;
47
47
  case "event":
48
- e.event = d;
48
+ n.event = y;
49
49
  break;
50
50
  case "id":
51
- r(e.id = d);
51
+ e(n.id = y);
52
52
  break;
53
53
  case "retry":
54
- const u = parseInt(d, 10);
55
- isNaN(u) || n(e.retry = u);
54
+ const b = parseInt(y, 10);
55
+ isNaN(b) || t(n.retry = b);
56
56
  break;
57
57
  }
58
58
  }
59
59
  };
60
60
  }
61
- function L(r, n) {
62
- const t = new Uint8Array(r.length + n.length);
63
- return t.set(r), t.set(n, r.length), t;
61
+ function D(e, t) {
62
+ const r = new Uint8Array(e.length + t.length);
63
+ return r.set(e), r.set(t, e.length), r;
64
64
  }
65
- function A() {
65
+ function C() {
66
66
  return {
67
67
  data: "",
68
68
  event: "",
@@ -70,125 +70,149 @@ function A() {
70
70
  retry: void 0
71
71
  };
72
72
  }
73
- var j = function(r, n) {
74
- var t = {};
75
- for (var e in r) Object.prototype.hasOwnProperty.call(r, e) && n.indexOf(e) < 0 && (t[e] = r[e]);
76
- if (r != null && typeof Object.getOwnPropertySymbols == "function")
77
- for (var o = 0, e = Object.getOwnPropertySymbols(r); o < e.length; o++)
78
- n.indexOf(e[o]) < 0 && Object.prototype.propertyIsEnumerable.call(r, e[o]) && (t[e[o]] = r[e[o]]);
79
- return t;
73
+ var K = function(e, t) {
74
+ var r = {};
75
+ for (var n in e) Object.prototype.hasOwnProperty.call(e, n) && t.indexOf(n) < 0 && (r[n] = e[n]);
76
+ if (e != null && typeof Object.getOwnPropertySymbols == "function")
77
+ for (var i = 0, n = Object.getOwnPropertySymbols(e); i < n.length; i++)
78
+ t.indexOf(n[i]) < 0 && Object.prototype.propertyIsEnumerable.call(e, n[i]) && (r[n[i]] = e[n[i]]);
79
+ return r;
80
80
  };
81
- const k = "text/event-stream", x = 1e3, I = "last-event-id";
82
- function C(r, n) {
83
- var { signal: t, headers: e, onopen: o, onmessage: E, onclose: s, onerror: i, openWhenHidden: a, fetch: c } = n, d = j(n, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
84
- return new Promise((u, S) => {
85
- const b = Object.assign({}, e);
86
- b.accept || (b.accept = k);
87
- let p;
88
- function y() {
89
- p.abort(), document.hidden || m();
81
+ const P = "text/event-stream", M = 1e3, W = "last-event-id";
82
+ function U(e, t) {
83
+ var { signal: r, headers: n, onopen: i, onmessage: u, onclose: d, onerror: o, openWhenHidden: s, fetch: c } = t, y = K(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
84
+ return new Promise((b, T) => {
85
+ const h = Object.assign({}, n);
86
+ h.accept || (h.accept = P);
87
+ let w;
88
+ function k() {
89
+ w.abort(), document.hidden || I();
90
90
  }
91
- a || document.addEventListener("visibilitychange", y);
92
- let w = x, l = 0;
93
- function f() {
94
- document.removeEventListener("visibilitychange", y), window.clearTimeout(l), p.abort();
91
+ s || document.addEventListener("visibilitychange", k);
92
+ let L = M, E = 0;
93
+ function S() {
94
+ document.removeEventListener("visibilitychange", k), window.clearTimeout(E), w.abort();
95
95
  }
96
- t == null || t.addEventListener("abort", () => {
97
- f(), u();
96
+ r == null || r.addEventListener("abort", () => {
97
+ S(), b();
98
98
  });
99
- const v = c ?? window.fetch, g = o ?? N;
100
- async function m() {
101
- var T;
102
- p = new AbortController();
99
+ const m = c ?? window.fetch, O = i ?? X;
100
+ async function I() {
101
+ var v;
102
+ w = new AbortController();
103
103
  try {
104
- const O = await v(r, Object.assign(Object.assign({}, d), { headers: b, signal: p.signal }));
105
- await g(O), await _(O.body, R(P((h) => {
106
- h ? b[I] = h : delete b[I];
107
- }, (h) => {
108
- w = h;
109
- }, E))), s == null || s(), f(), u();
110
- } catch (O) {
111
- if (!p.signal.aborted)
104
+ const l = await m(e, Object.assign(Object.assign({}, y), { headers: h, signal: w.signal }));
105
+ await O(l), await _(l.body, $(N((f) => {
106
+ f ? h[W] = f : delete h[W];
107
+ }, (f) => {
108
+ L = f;
109
+ }, u))), d == null || d(), S(), b();
110
+ } catch (l) {
111
+ if (!w.signal.aborted)
112
112
  try {
113
- const h = (T = i == null ? void 0 : i(O)) !== null && T !== void 0 ? T : w;
114
- window.clearTimeout(l), l = window.setTimeout(m, h);
115
- } catch (h) {
116
- f(), S(h);
113
+ const f = (v = o == null ? void 0 : o(l)) !== null && v !== void 0 ? v : L;
114
+ window.clearTimeout(E), E = window.setTimeout(I, f);
115
+ } catch (f) {
116
+ S(), T(f);
117
117
  }
118
118
  }
119
119
  }
120
- m();
120
+ I();
121
121
  });
122
122
  }
123
- function N(r) {
124
- const n = r.headers.get("content-type");
125
- if (!(n != null && n.startsWith(k)))
126
- throw new Error(`Expected content-type to be ${k}, Actual: ${n}`);
123
+ function X(e) {
124
+ const t = e.headers.get("content-type");
125
+ if (!(t != null && t.startsWith(P)))
126
+ throw new Error(`Expected content-type to be ${P}, Actual: ${t}`);
127
127
  }
128
- const $ = "/memory/progress/stream", H = 3, W = 1e3, q = /* @__PURE__ */ new Set([401, 403, 404]);
129
- function U(r) {
130
- const {
131
- baseUrl: n = "",
132
- token: t,
133
- apiKey: e,
134
- workspaceId: o,
135
- runId: E,
136
- fromSeq: s,
137
- since: i,
138
- useCookieAuth: a = !1,
139
- onEvent: c,
140
- onError: d,
141
- onReconnect: u
142
- } = r, S = new URLSearchParams();
143
- E !== void 0 && S.set("run_id", E), s !== void 0 && S.set("from_seq", String(s)), i !== void 0 && S.set("since", i);
144
- const b = S.toString(), p = `${n}${$}${b ? "?" + b : ""}`, y = {
145
- Accept: "text/event-stream"
146
- };
147
- t ? y.Authorization = `Bearer ${t}` : e && (y["X-API-Key"] = e), o && (y["X-Workspace-Id"] = o);
148
- const w = new AbortController();
149
- let l = !1, f = 0;
150
- return C(p, {
151
- headers: y,
152
- signal: w.signal,
153
- openWhenHidden: !0,
154
- ...a && !t && !e ? { credentials: "include" } : {},
155
- async onopen(v) {
156
- if (v.ok) {
157
- f = 0;
128
+ function z(e) {
129
+ const { auth: t, onEvent: r, onError: n, onReconnect: i } = e, u = e.connection || (t == null ? void 0 : t.connection), d = Symbol("progress");
130
+ let o = !1, s = 0, c, y, b = 0, T = !1, h = e.fromSeq, w = e.since, k;
131
+ function L() {
132
+ s++, clearTimeout(y), c == null || c.abort();
133
+ }
134
+ function E() {
135
+ o || (o = !0, L(), typeof window < "u" && window.removeEventListener("online", O), typeof document < "u" && document.removeEventListener("visibilitychange", O), u == null || u.report(d, null));
136
+ }
137
+ function S(v) {
138
+ console.warn("[progress] Stream cannot recover", v), E(), n(v);
139
+ }
140
+ function m(v, l) {
141
+ o || (L(), console.warn("[progress] Stream interrupted; reconnecting", v), u == null || u.report(d, v instanceof Error ? v.message : String(v)), y = setTimeout(I, l ?? Math.min(1e3 * 2 ** Math.min(b++, 5), 3e4)), i == null || i());
142
+ }
143
+ function O() {
144
+ o || typeof document < "u" && document.visibilityState === "hidden" || m(new Error("Resuming after visibility/network return"), 0);
145
+ }
146
+ function I() {
147
+ var j;
148
+ if (o) return;
149
+ const v = ++s, l = () => !o && v === s;
150
+ c = new AbortController();
151
+ const f = new URLSearchParams();
152
+ e.runId !== void 0 ? (f.set("run_id", e.runId), h !== void 0 && f.set("from_seq", String(h))) : w !== void 0 && f.set("since", w);
153
+ const R = `${e.baseUrl || ""}/memory/progress/stream${f.size ? "?" + f : ""}`;
154
+ try {
155
+ const g = { Accept: "text/event-stream" };
156
+ !t && !e.getHeaders && (e.token ? g.Authorization = `Bearer ${e.token}` : e.apiKey && (g["X-API-Key"] = e.apiKey), e.workspaceId && (g["X-Workspace-Id"] = e.workspaceId)), Object.assign(g, t == null ? void 0 : t.getAuthHeaders(), (j = e.getHeaders) == null ? void 0 : j.call(e));
157
+ const q = new Headers(g).get("X-Workspace-Id");
158
+ if (k !== void 0 && q !== k) {
159
+ S(new Error("Progress workspace changed; create a new subscription"));
158
160
  return;
159
161
  }
160
- const g = v.status, m = new Error(`SSE connection failed: HTTP ${g}`);
161
- throw q.has(g) && (l = !0, d(m), w.abort()), m;
162
- },
163
- onmessage(v) {
164
- if (l || !v.data) return;
165
- f = 0;
166
- let g;
167
- try {
168
- g = JSON.parse(v.data);
169
- } catch {
170
- return;
171
- }
172
- c(g);
173
- },
174
- onerror(v) {
175
- if (!l) {
176
- if (f += 1, f >= H) {
177
- d(v), l = !0, w.abort();
178
- return;
162
+ k = q, w && e.runId === void 0 && (g["Last-Event-ID"] = w);
163
+ const x = (t == null ? void 0 : t.getRequestOptions({ headers: g })) || {
164
+ headers: g,
165
+ ...e.useCookieAuth ? { credentials: "include" } : {}
166
+ }, H = U(R, {
167
+ ...x,
168
+ headers: x.headers,
169
+ fetch: e.fetchFn,
170
+ signal: c.signal,
171
+ openWhenHidden: !0,
172
+ async onopen(a) {
173
+ if (!l()) return;
174
+ if (a.ok) {
175
+ T = !1, u == null || u.report(d, null);
176
+ return;
177
+ }
178
+ const p = new Error(`SSE connection failed: HTTP ${a.status}`);
179
+ if (a.status === 401 && t && !T)
180
+ try {
181
+ await t.refreshToken(), l() && (T = !0, m(p, 0));
182
+ } catch (A) {
183
+ l() && (A.recoverable === !1 ? S(A) : m(A));
184
+ }
185
+ else a.status >= 400 && a.status < 500 && a.status !== 429 && a.status !== 408 && (a.status === 401 && (t == null || t.clearLocalAuth()), S(p));
186
+ throw p;
187
+ },
188
+ onmessage(a) {
189
+ if (!l() || !a.data) return;
190
+ let p;
191
+ try {
192
+ p = JSON.parse(a.data);
193
+ } catch (A) {
194
+ console.warn("[progress] Skipping malformed SSE frame", A);
195
+ return;
196
+ }
197
+ r(p), b = 0, e.runId !== void 0 && typeof p.seq == "number" ? h = Math.max(h ?? 0, p.seq + 1) : a.id && (w = a.id);
198
+ },
199
+ onerror(a) {
200
+ throw l() && m(a), a;
201
+ },
202
+ onclose() {
203
+ var a;
204
+ l() && (e.reconnect === !1 ? (E(), (a = e.onComplete) == null || a.call(e)) : m(new Error("SSE connection closed by server")));
179
205
  }
180
- return u == null || u(), W * f;
181
- }
182
- },
183
- onclose() {
184
- l || (l = !0, d(new Error("SSE connection closed by server")));
206
+ });
207
+ H == null || H.catch((a) => {
208
+ l() && m(a);
209
+ });
210
+ } catch (g) {
211
+ l() && m(g);
185
212
  }
186
- }), {
187
- close() {
188
- l || (l = !0, w.abort());
189
- }
190
- };
213
+ }
214
+ return typeof window < "u" && window.addEventListener("online", O), typeof document < "u" && document.addEventListener("visibilitychange", O), I(), { close: E };
191
215
  }
192
216
  export {
193
- U as subscribeProgress
217
+ z as subscribeProgress
194
218
  };
package/dist/react.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import h, { createContext as d, useRef as I, useState as S, useEffect as C, useCallback as c, useContext as g } from "react";
2
- import { l as y } from "./core-BLQpDtod.js";
2
+ import { l as y } from "./core-DUg_hHl8.js";
3
3
  const f = d(null), m = d(null);
4
4
  function b({ children: e, ...r }) {
5
5
  const n = I(null);
@@ -0,0 +1,34 @@
1
+ async function A(e, n, { source: o, signal: t, retry: i = !0 } = {}) {
2
+ var c, f, p, d, w, l;
3
+ const s = () => new Headers(e.getAuthHeaders()).get("X-Workspace-Id"), h = s(), u = new Headers(e.getAuthHeaders()).get("Authorization"), a = () => {
4
+ if (s() !== h) throw new DOMException("Workspace changed during request", "AbortError");
5
+ };
6
+ try {
7
+ let r = await n(!1);
8
+ if (r.status === 401 && i) {
9
+ if (console.warn("[session] Unauthorized; refreshing and retrying once"), (c = e.connection) == null || c.report(o, "Refreshing session"), a(), t != null && t.aborted) throw new DOMException("Request aborted", "AbortError");
10
+ if (new Headers(e.getAuthHeaders()).get("Authorization") === u && await e.refreshToken(), a(), t != null && t.aborted) throw new DOMException("Request aborted", "AbortError");
11
+ r = await n(!0);
12
+ }
13
+ return r.status === 401 ? (console.warn("[session] Authentication required after recovery"), (f = e.clearLocalAuth) == null || f.call(e)) : r.status === 429 || r.status >= 500 ? (console.warn(`[session] Service unavailable: HTTP ${r.status}`), (p = e.connection) == null || p.report(o, `HTTP ${r.status}`)) : (d = e.connection) == null || d.report(o, null), r;
14
+ } catch (r) {
15
+ throw r.name === "AbortError" && ((w = e.connection) == null || w.report(o, null)), r.name !== "AbortError" && r.recoverable !== !1 && (console.warn("[session] Connection interrupted", r), (l = e.connection) == null || l.report(o, r.message)), r;
16
+ }
17
+ }
18
+ function b(e) {
19
+ return new URL(
20
+ e instanceof Request ? e.url : String(e),
21
+ typeof location < "u" ? location.href : "http://localhost"
22
+ );
23
+ }
24
+ function E(e, n, o = []) {
25
+ return [e.apiBaseUrl || "/", ...o].some((t) => {
26
+ const i = b(t), s = i.pathname.replace(/\/$/, "");
27
+ return n.origin === i.origin && (!s || n.pathname === s || n.pathname.startsWith(`${s}/`));
28
+ });
29
+ }
30
+ export {
31
+ A as f,
32
+ E as i,
33
+ b as r
34
+ };