@smartmemory/sdk-js 1.4.119 → 1.4.121
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 +69 -9
- package/dist/connection.js +5 -0
- package/dist/{core-BLQpDtod.js → core-DUg_hHl8.js} +538 -583
- package/dist/core.js +11 -10
- package/dist/fetch.js +18 -37
- package/dist/index-BKI1h_Wn.js +107 -0
- package/dist/index.js +1 -1
- package/dist/progress.js +166 -142
- package/dist/react.js +1 -1
- package/dist/recovery-JyUr2KHh.js +34 -0
- package/package.json +10 -2
- package/types/connection.d.ts +30 -0
- package/types/fetch.d.ts +12 -0
- package/types/progress.d.ts +48 -0
package/dist/core.js
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
import { A as e, a as r, d as A, e as
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
15
|
-
|
|
15
|
+
y as RefreshManager,
|
|
16
|
+
M as SSOManager,
|
|
16
17
|
f as SmartMemoryClient,
|
|
17
|
-
|
|
18
|
+
h as SubscriptionAPI,
|
|
18
19
|
p as TeamAPI,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
l as TokenManager,
|
|
21
|
+
S as UsageAPI,
|
|
22
|
+
c as WorkspaceAPI
|
|
22
23
|
};
|
package/dist/fetch.js
CHANGED
|
@@ -1,43 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
|
26
|
-
const
|
|
27
|
-
return
|
|
28
|
-
const
|
|
29
|
-
|
|
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
|
-
|
|
42
|
-
|
|
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-
|
|
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 _(
|
|
2
|
-
const
|
|
3
|
-
let
|
|
4
|
-
for (; !(
|
|
5
|
-
n
|
|
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
|
|
8
|
-
let
|
|
9
|
-
return function(
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
let
|
|
13
|
-
for (;
|
|
14
|
-
|
|
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 (;
|
|
17
|
-
switch (
|
|
16
|
+
for (; r < o && c === -1; ++r)
|
|
17
|
+
switch (t[r]) {
|
|
18
18
|
case 58:
|
|
19
|
-
|
|
19
|
+
n === -1 && (n = r - s);
|
|
20
20
|
break;
|
|
21
21
|
case 13:
|
|
22
|
-
|
|
22
|
+
i = !0;
|
|
23
23
|
case 10:
|
|
24
|
-
c =
|
|
24
|
+
c = r;
|
|
25
25
|
break;
|
|
26
26
|
}
|
|
27
27
|
if (c === -1)
|
|
28
28
|
break;
|
|
29
|
-
|
|
29
|
+
e(t.subarray(s, c), n), s = r, n = -1;
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
s === o ? t = void 0 : s !== 0 && (t = t.subarray(s), r -= s);
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
-
function
|
|
35
|
-
let
|
|
36
|
-
const
|
|
37
|
-
return function(
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
else if (
|
|
41
|
-
const
|
|
42
|
-
switch (
|
|
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
|
-
|
|
45
|
-
` +
|
|
44
|
+
n.data = n.data ? n.data + `
|
|
45
|
+
` + y : y;
|
|
46
46
|
break;
|
|
47
47
|
case "event":
|
|
48
|
-
|
|
48
|
+
n.event = y;
|
|
49
49
|
break;
|
|
50
50
|
case "id":
|
|
51
|
-
|
|
51
|
+
e(n.id = y);
|
|
52
52
|
break;
|
|
53
53
|
case "retry":
|
|
54
|
-
const
|
|
55
|
-
isNaN(
|
|
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
|
|
62
|
-
const
|
|
63
|
-
return
|
|
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
|
|
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
|
|
74
|
-
var
|
|
75
|
-
for (var
|
|
76
|
-
if (
|
|
77
|
-
for (var
|
|
78
|
-
|
|
79
|
-
return
|
|
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
|
|
82
|
-
function
|
|
83
|
-
var { signal:
|
|
84
|
-
return new Promise((
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
let
|
|
88
|
-
function
|
|
89
|
-
|
|
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
|
-
|
|
92
|
-
let
|
|
93
|
-
function
|
|
94
|
-
document.removeEventListener("visibilitychange",
|
|
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
|
-
|
|
97
|
-
|
|
96
|
+
r == null || r.addEventListener("abort", () => {
|
|
97
|
+
S(), b();
|
|
98
98
|
});
|
|
99
|
-
const
|
|
100
|
-
async function
|
|
101
|
-
var
|
|
102
|
-
|
|
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
|
|
105
|
-
await
|
|
106
|
-
|
|
107
|
-
}, (
|
|
108
|
-
|
|
109
|
-
},
|
|
110
|
-
} catch (
|
|
111
|
-
if (!
|
|
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
|
|
114
|
-
window.clearTimeout(
|
|
115
|
-
} catch (
|
|
116
|
-
|
|
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
|
-
|
|
120
|
+
I();
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
|
-
function
|
|
124
|
-
const
|
|
125
|
-
if (!(
|
|
126
|
-
throw new Error(`Expected content-type to be ${
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
206
|
+
});
|
|
207
|
+
H == null || H.catch((a) => {
|
|
208
|
+
l() && m(a);
|
|
209
|
+
});
|
|
210
|
+
} catch (g) {
|
|
211
|
+
l() && m(g);
|
|
185
212
|
}
|
|
186
|
-
}
|
|
187
|
-
|
|
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
|
-
|
|
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-
|
|
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
|
+
};
|