@ably/ai-transport 0.0.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +114 -116
- package/dist/ably-ai-transport.js +1743 -961
- package/dist/ably-ai-transport.js.map +1 -1
- package/dist/ably-ai-transport.umd.cjs +1 -1
- package/dist/ably-ai-transport.umd.cjs.map +1 -1
- package/dist/constants.d.ts +117 -39
- package/dist/core/agent.d.ts +29 -0
- package/dist/core/codec/decoder.d.ts +20 -23
- package/dist/core/codec/encoder.d.ts +11 -8
- package/dist/core/codec/index.d.ts +1 -2
- package/dist/core/codec/lifecycle-tracker.d.ts +10 -9
- package/dist/core/codec/types.d.ts +410 -101
- package/dist/core/transport/agent-session.d.ts +10 -0
- package/dist/core/transport/branch-chain.d.ts +43 -0
- package/dist/core/transport/client-session.d.ts +13 -0
- package/dist/core/transport/decode-fold.d.ts +47 -0
- package/dist/core/transport/headers.d.ts +97 -17
- package/dist/core/transport/index.d.ts +5 -3
- package/dist/core/transport/internal/bounded-map.d.ts +20 -0
- package/dist/core/transport/invocation.d.ts +74 -0
- package/dist/core/transport/load-conversation.d.ts +128 -0
- package/dist/core/transport/load-history.d.ts +39 -0
- package/dist/core/transport/pipe-stream.d.ts +9 -8
- package/dist/core/transport/run-manager.d.ts +78 -0
- package/dist/core/transport/tree.d.ts +435 -0
- package/dist/core/transport/types/agent.d.ts +353 -0
- package/dist/core/transport/types/client.d.ts +168 -0
- package/dist/core/transport/types/shared.d.ts +24 -0
- package/dist/core/transport/types/tree.d.ts +315 -0
- package/dist/core/transport/types/view.d.ts +222 -0
- package/dist/core/transport/types.d.ts +13 -402
- package/dist/core/transport/view.d.ts +354 -0
- package/dist/errors.d.ts +37 -9
- package/dist/index.d.ts +6 -6
- package/dist/logger.d.ts +12 -0
- package/dist/react/ably-ai-transport-react.js +1164 -645
- package/dist/react/ably-ai-transport-react.js.map +1 -1
- package/dist/react/ably-ai-transport-react.umd.cjs +1 -1
- package/dist/react/ably-ai-transport-react.umd.cjs.map +1 -1
- package/dist/react/contexts/client-session-context.d.ts +36 -0
- package/dist/react/contexts/client-session-provider.d.ts +53 -0
- package/dist/react/create-session-hooks.d.ts +116 -0
- package/dist/react/index.d.ts +16 -10
- package/dist/react/internal/use-resolved-session.d.ts +36 -0
- package/dist/react/use-ably-messages.d.ts +20 -11
- package/dist/react/use-client-session.d.ts +81 -0
- package/dist/react/use-create-view.d.ts +23 -0
- package/dist/react/use-tree.d.ts +35 -0
- package/dist/react/use-view.d.ts +110 -0
- package/dist/utils.d.ts +32 -23
- package/dist/vercel/ably-ai-transport-vercel.js +2748 -1625
- package/dist/vercel/ably-ai-transport-vercel.js.map +1 -1
- package/dist/vercel/ably-ai-transport-vercel.umd.cjs +1 -1
- package/dist/vercel/ably-ai-transport-vercel.umd.cjs.map +1 -1
- package/dist/vercel/codec/decoder.d.ts +5 -18
- package/dist/vercel/codec/encoder.d.ts +6 -36
- package/dist/vercel/codec/events.d.ts +51 -0
- package/dist/vercel/codec/index.d.ts +24 -12
- package/dist/vercel/codec/reducer.d.ts +144 -0
- package/dist/vercel/codec/tool-transitions.d.ts +50 -0
- package/dist/vercel/index.d.ts +4 -2
- package/dist/vercel/react/ably-ai-transport-vercel-react.js +10298 -1410
- package/dist/vercel/react/ably-ai-transport-vercel-react.js.map +1 -1
- package/dist/vercel/react/ably-ai-transport-vercel-react.umd.cjs +70 -1
- package/dist/vercel/react/ably-ai-transport-vercel-react.umd.cjs.map +1 -1
- package/dist/vercel/react/contexts/chat-transport-context.d.ts +33 -0
- package/dist/vercel/react/contexts/chat-transport-provider.d.ts +96 -0
- package/dist/vercel/react/index.d.ts +4 -0
- package/dist/vercel/react/use-chat-transport.d.ts +66 -21
- package/dist/vercel/react/use-message-sync.d.ts +31 -12
- package/dist/vercel/run-end-reason.d.ts +29 -0
- package/dist/vercel/transport/chat-transport.d.ts +71 -30
- package/dist/vercel/transport/index.d.ts +25 -18
- package/dist/vercel/transport/run-output-stream.d.ts +56 -0
- package/dist/version.d.ts +2 -0
- package/package.json +47 -34
- package/src/constants.ts +126 -47
- package/src/core/agent.ts +68 -0
- package/src/core/codec/decoder.ts +71 -98
- package/src/core/codec/encoder.ts +115 -58
- package/src/core/codec/index.ts +13 -6
- package/src/core/codec/lifecycle-tracker.ts +10 -9
- package/src/core/codec/types.ts +438 -106
- package/src/core/transport/agent-session.ts +1344 -0
- package/src/core/transport/branch-chain.ts +58 -0
- package/src/core/transport/client-session.ts +775 -0
- package/src/core/transport/decode-fold.ts +91 -0
- package/src/core/transport/headers.ts +182 -19
- package/src/core/transport/index.ts +29 -22
- package/src/core/transport/internal/bounded-map.ts +27 -0
- package/src/core/transport/invocation.ts +98 -0
- package/src/core/transport/load-conversation.ts +355 -0
- package/src/core/transport/load-history.ts +269 -0
- package/src/core/transport/pipe-stream.ts +58 -40
- package/src/core/transport/run-manager.ts +249 -0
- package/src/core/transport/tree.ts +1167 -0
- package/src/core/transport/types/agent.ts +407 -0
- package/src/core/transport/types/client.ts +211 -0
- package/src/core/transport/types/shared.ts +27 -0
- package/src/core/transport/types/tree.ts +344 -0
- package/src/core/transport/types/view.ts +259 -0
- package/src/core/transport/types.ts +13 -527
- package/src/core/transport/view.ts +1271 -0
- package/src/errors.ts +42 -9
- package/src/event-emitter.ts +3 -2
- package/src/index.ts +55 -39
- package/src/logger.ts +14 -1
- package/src/react/contexts/client-session-context.ts +41 -0
- package/src/react/contexts/client-session-provider.tsx +186 -0
- package/src/react/create-session-hooks.ts +141 -0
- package/src/react/index.ts +27 -10
- package/src/react/internal/use-resolved-session.ts +63 -0
- package/src/react/use-ably-messages.ts +47 -19
- package/src/react/use-client-session.ts +201 -0
- package/src/react/use-create-view.ts +72 -0
- package/src/react/use-tree.ts +84 -0
- package/src/react/use-view.ts +275 -0
- package/src/react/vite.config.ts +4 -1
- package/src/utils.ts +63 -45
- package/src/vercel/codec/decoder.ts +336 -255
- package/src/vercel/codec/encoder.ts +348 -196
- package/src/vercel/codec/events.ts +87 -0
- package/src/vercel/codec/index.ts +59 -14
- package/src/vercel/codec/reducer.ts +977 -0
- package/src/vercel/codec/tool-transitions.ts +122 -0
- package/src/vercel/index.ts +7 -3
- package/src/vercel/react/contexts/chat-transport-context.ts +41 -0
- package/src/vercel/react/contexts/chat-transport-provider.tsx +150 -0
- package/src/vercel/react/index.ts +13 -1
- package/src/vercel/react/use-chat-transport.ts +162 -42
- package/src/vercel/react/use-message-sync.ts +121 -22
- package/src/vercel/react/vite.config.ts +4 -2
- package/src/vercel/run-end-reason.ts +78 -0
- package/src/vercel/transport/chat-transport.ts +553 -113
- package/src/vercel/transport/index.ts +40 -28
- package/src/vercel/transport/run-output-stream.ts +170 -0
- package/src/version.ts +2 -0
- package/dist/core/transport/client-transport.d.ts +0 -10
- package/dist/core/transport/conversation-tree.d.ts +0 -9
- package/dist/core/transport/decode-history.d.ts +0 -41
- package/dist/core/transport/server-transport.d.ts +0 -7
- package/dist/core/transport/stream-router.d.ts +0 -19
- package/dist/core/transport/turn-manager.d.ts +0 -34
- package/dist/react/use-active-turns.d.ts +0 -8
- package/dist/react/use-client-transport.d.ts +0 -7
- package/dist/react/use-conversation-tree.d.ts +0 -20
- package/dist/react/use-edit.d.ts +0 -7
- package/dist/react/use-history.d.ts +0 -19
- package/dist/react/use-messages.d.ts +0 -7
- package/dist/react/use-regenerate.d.ts +0 -7
- package/dist/react/use-send.d.ts +0 -7
- package/dist/vercel/codec/accumulator.d.ts +0 -21
- package/src/core/transport/client-transport.ts +0 -959
- package/src/core/transport/conversation-tree.ts +0 -434
- package/src/core/transport/decode-history.ts +0 -337
- package/src/core/transport/server-transport.ts +0 -458
- package/src/core/transport/stream-router.ts +0 -118
- package/src/core/transport/turn-manager.ts +0 -147
- package/src/react/use-active-turns.ts +0 -61
- package/src/react/use-client-transport.ts +0 -37
- package/src/react/use-conversation-tree.ts +0 -71
- package/src/react/use-edit.ts +0 -24
- package/src/react/use-history.ts +0 -111
- package/src/react/use-messages.ts +0 -32
- package/src/react/use-regenerate.ts +0 -24
- package/src/react/use-send.ts +0 -25
- package/src/vercel/codec/accumulator.ts +0 -603
|
@@ -1,93 +1,70 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return
|
|
7
|
-
|
|
8
|
-
})), [e]), n;
|
|
9
|
-
}, o = "x-ably-turn-id", s = "x-ably-msg-id", c = "x-ably-turn-client-id", l = "x-ably-role", u = "x-ably-cancel-turn-id", d = "x-ably-cancel-own", f = "x-ably-cancel-all", p = "x-ably-cancel-client-id", m = "x-ably-parent", h = "x-ably-fork-of", g = "x-ably-cancel", _ = "x-ably-turn-start", v = "x-ably-turn-end", y = (e) => {
|
|
10
|
-
let [n, i] = r(() => /* @__PURE__ */ new Map());
|
|
11
|
-
return t(() => {
|
|
12
|
-
if (e) return i(e.getActiveTurnIds()), e.on("turn", (e) => {
|
|
13
|
-
i((t) => {
|
|
14
|
-
let n = new Map(t);
|
|
15
|
-
if (e.type === "x-ably-turn-start") {
|
|
16
|
-
let t = new Set(n.get(e.clientId) ?? []);
|
|
17
|
-
t.add(e.turnId), n.set(e.clientId, t);
|
|
18
|
-
} else {
|
|
19
|
-
let t = n.get(e.clientId);
|
|
20
|
-
t && (t.delete(e.turnId), t.size === 0 ? n.delete(e.clientId) : n.set(e.clientId, new Set(t)));
|
|
21
|
-
}
|
|
22
|
-
return n;
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
}, [e]), n;
|
|
26
|
-
}, b = /* @__PURE__ */ function(e) {
|
|
27
|
-
return e[e.BadRequest = 4e4] = "BadRequest", e[e.InvalidArgument = 40003] = "InvalidArgument", e[e.EncoderRecoveryFailed = 104e3] = "EncoderRecoveryFailed", e[e.TransportSubscriptionError = 104001] = "TransportSubscriptionError", e[e.CancelListenerError = 104002] = "CancelListenerError", e[e.TurnLifecycleError = 104003] = "TurnLifecycleError", e[e.TransportClosed = 104004] = "TransportClosed", e[e.TransportSendFailed = 104005] = "TransportSendFailed", e;
|
|
28
|
-
}({}), x = (e) => ({
|
|
1
|
+
import * as e from "ably";
|
|
2
|
+
import { useAbly as t } from "ably/react";
|
|
3
|
+
import { createContext as n, useCallback as r, useContext as i, useEffect as a, useMemo as o, useRef as s, useState as c } from "react";
|
|
4
|
+
import { jsx as l } from "react/jsx-runtime";
|
|
5
|
+
var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-message-id", h = "run-client-id", g = "input-client-id", _ = "role", v = "parent", y = "fork-of", b = "msg-regenerate", x = "input-codec-message-id", S = "error-code", ee = "ai-cancel", C = /* @__PURE__ */ function(e) {
|
|
6
|
+
return e[e.BadRequest = 4e4] = "BadRequest", e[e.InvalidArgument = 40003] = "InvalidArgument", e[e.InsufficientCapability = 40160] = "InsufficientCapability", e[e.EncoderRecoveryFailed = 104e3] = "EncoderRecoveryFailed", e[e.SessionSubscriptionError = 104001] = "SessionSubscriptionError", e[e.CancelListenerError = 104002] = "CancelListenerError", e[e.RunLifecycleError = 104003] = "RunLifecycleError", e[e.SessionClosed = 104004] = "SessionClosed", e[e.SessionSendFailed = 104005] = "SessionSendFailed", e[e.ChannelContinuityLost = 104006] = "ChannelContinuityLost", e[e.ChannelNotReady = 104007] = "ChannelNotReady", e[e.StreamError = 104008] = "StreamError", e[e.InputEventNotFound = 104010] = "InputEventNotFound", e;
|
|
7
|
+
}({}), te = (e) => ({
|
|
29
8
|
logAction: (t, n, r) => {
|
|
30
9
|
e.error(n, { detail: r });
|
|
31
10
|
},
|
|
32
11
|
shouldLog: () => !0
|
|
33
|
-
}),
|
|
12
|
+
}), ne = e.Realtime.EventEmitter, w = class extends ne {
|
|
34
13
|
constructor(e) {
|
|
35
|
-
super(
|
|
14
|
+
super(te(e));
|
|
36
15
|
}
|
|
37
|
-
},
|
|
16
|
+
}, T = /* @__PURE__ */ function(e) {
|
|
38
17
|
return e.Trace = "trace", e.Debug = "debug", e.Info = "info", e.Warn = "warn", e.Error = "error", e.Silent = "silent", e;
|
|
39
|
-
}({}),
|
|
18
|
+
}({}), re = (e, t, n) => {
|
|
40
19
|
let r = n ? `, context: ${JSON.stringify(n)}` : "", i = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${t.valueOf().toUpperCase()} ably-ai-transport: ${e}${r}`;
|
|
41
20
|
switch (t) {
|
|
42
|
-
case
|
|
43
|
-
case
|
|
21
|
+
case "trace":
|
|
22
|
+
case "debug":
|
|
44
23
|
console.log(i);
|
|
45
24
|
break;
|
|
46
|
-
case
|
|
25
|
+
case "info":
|
|
47
26
|
console.info(i);
|
|
48
27
|
break;
|
|
49
|
-
case
|
|
28
|
+
case "warn":
|
|
50
29
|
console.warn(i);
|
|
51
30
|
break;
|
|
52
|
-
case
|
|
31
|
+
case "error":
|
|
53
32
|
console.error(i);
|
|
54
33
|
break;
|
|
55
|
-
case
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
[
|
|
61
|
-
[
|
|
62
|
-
[
|
|
63
|
-
[
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (r === void 0) throw new i.ErrorInfo(`unable to create logger; invalid log level: ${t}`, b.InvalidArgument, 400);
|
|
71
|
-
this._levelNumber = r;
|
|
34
|
+
case "silent": break;
|
|
35
|
+
}
|
|
36
|
+
}, ie = (e) => new ae(e.logHandler ?? re, e.logLevel), E = new Map([
|
|
37
|
+
["trace", 0],
|
|
38
|
+
["debug", 1],
|
|
39
|
+
["info", 2],
|
|
40
|
+
["warn", 3],
|
|
41
|
+
["error", 4],
|
|
42
|
+
["silent", 5]
|
|
43
|
+
]), ae = class t {
|
|
44
|
+
constructor(t, n, r) {
|
|
45
|
+
this._handler = t, this._context = r;
|
|
46
|
+
let i = E.get(n);
|
|
47
|
+
if (i === void 0) throw new e.ErrorInfo(`unable to create logger; invalid log level: ${n}`, C.InvalidArgument, 400);
|
|
48
|
+
this._levelNumber = i;
|
|
72
49
|
}
|
|
73
50
|
trace(e, t) {
|
|
74
|
-
this._write(e,
|
|
51
|
+
this._write(e, "trace", 0, t);
|
|
75
52
|
}
|
|
76
53
|
debug(e, t) {
|
|
77
|
-
this._write(e,
|
|
54
|
+
this._write(e, "debug", 1, t);
|
|
78
55
|
}
|
|
79
56
|
info(e, t) {
|
|
80
|
-
this._write(e,
|
|
57
|
+
this._write(e, "info", 2, t);
|
|
81
58
|
}
|
|
82
59
|
warn(e, t) {
|
|
83
|
-
this._write(e,
|
|
60
|
+
this._write(e, "warn", 3, t);
|
|
84
61
|
}
|
|
85
62
|
error(e, t) {
|
|
86
|
-
this._write(e,
|
|
63
|
+
this._write(e, "error", 4, t);
|
|
87
64
|
}
|
|
88
|
-
withContext(
|
|
89
|
-
let n = [...
|
|
90
|
-
return new
|
|
65
|
+
withContext(e) {
|
|
66
|
+
let n = [...E.entries()].find(([, e]) => e === this._levelNumber)?.[0] ?? "error";
|
|
67
|
+
return new t(this._handler, n, this._mergeContext(e));
|
|
91
68
|
}
|
|
92
69
|
_write(e, t, n, r) {
|
|
93
70
|
n >= this._levelNumber && this._handler(e, t, this._mergeContext(r));
|
|
@@ -98,726 +75,1268 @@ var a = (e) => {
|
|
|
98
75
|
...e
|
|
99
76
|
} : this._context : e ?? void 0;
|
|
100
77
|
}
|
|
101
|
-
},
|
|
102
|
-
let
|
|
103
|
-
if (!
|
|
104
|
-
let
|
|
105
|
-
|
|
106
|
-
|
|
78
|
+
}, oe = (e, t) => {
|
|
79
|
+
let n = e.extras;
|
|
80
|
+
if (!n || typeof n != "object") return {};
|
|
81
|
+
let r = n.ai;
|
|
82
|
+
if (!r || typeof r != "object") return {};
|
|
83
|
+
let i = r[t];
|
|
84
|
+
return !i || typeof i != "object" ? {} : i;
|
|
85
|
+
}, D = (e) => oe(e, "transport"), O = "0.2.0", k = "ai-transport-js", se = (e, t) => {
|
|
86
|
+
let n = e;
|
|
87
|
+
return n.options.agents = {
|
|
88
|
+
...n.options.agents,
|
|
89
|
+
...t
|
|
90
|
+
}, { params: { agent: Object.entries(t).map(([e, t]) => `${e}/${t}`).join(" ") } };
|
|
91
|
+
}, ce = (e, t) => {
|
|
92
|
+
let n = t?.adapterTag, r = { [k]: O };
|
|
93
|
+
return n && (r[n] = O), se(e, r);
|
|
94
|
+
}, le = (e) => {
|
|
95
|
+
let t = {
|
|
96
|
+
[_]: e.role,
|
|
97
|
+
[m]: e.codecMessageId
|
|
98
|
+
};
|
|
99
|
+
return e.runId !== void 0 && (t[d] = e.runId), e.runClientId !== void 0 && (t[h] = e.runClientId), e.parent && (t[v] = e.parent), e.forkOf && (t[y] = e.forkOf), e.regenerates && (t[b] = e.regenerates), e.invocationId && (t[f] = e.invocationId), e.inputClientId !== void 0 && (t[g] = e.inputClientId), e.inputCodecMessageId !== void 0 && (t[x] = e.inputCodecMessageId), e.inputEventId && (t[p] = e.inputEventId), t;
|
|
100
|
+
}, A = (e) => e === "ai-run-start" || e === "ai-run-suspend" || e === "ai-run-resume" || e === "ai-run-end", j = (e, t, n) => {
|
|
101
|
+
let r = t[d];
|
|
102
|
+
if (!r) return;
|
|
103
|
+
let i = t["run-client-id"] ?? "";
|
|
104
|
+
if (e === "ai-run-start") {
|
|
105
|
+
let e = t[v], a = t[y], o = t[b];
|
|
106
|
+
return {
|
|
107
|
+
type: "start",
|
|
108
|
+
runId: r,
|
|
109
|
+
clientId: i,
|
|
110
|
+
serial: n,
|
|
111
|
+
invocationId: t["invocation-id"] ?? "",
|
|
112
|
+
...e !== void 0 && { parent: e },
|
|
113
|
+
...a !== void 0 && { forkOf: a },
|
|
114
|
+
...o !== void 0 && { regenerates: o }
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
if (e === "ai-run-suspend") return {
|
|
118
|
+
type: "suspend",
|
|
119
|
+
runId: r,
|
|
120
|
+
clientId: i,
|
|
121
|
+
serial: n,
|
|
122
|
+
invocationId: t["invocation-id"] ?? ""
|
|
123
|
+
};
|
|
124
|
+
if (e === "ai-run-resume") return {
|
|
125
|
+
type: "resume",
|
|
126
|
+
runId: r,
|
|
127
|
+
clientId: i,
|
|
128
|
+
serial: n,
|
|
129
|
+
invocationId: t["invocation-id"] ?? ""
|
|
130
|
+
};
|
|
131
|
+
if (e === "ai-run-end") {
|
|
132
|
+
let e = t["run-reason"] ?? "complete";
|
|
133
|
+
return {
|
|
134
|
+
type: "end",
|
|
135
|
+
runId: r,
|
|
136
|
+
clientId: i,
|
|
137
|
+
serial: n,
|
|
138
|
+
invocationId: t["invocation-id"] ?? "",
|
|
139
|
+
reason: e
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}, M = (e, t, n) => {
|
|
143
|
+
let r = D(n), i = n.serial;
|
|
144
|
+
if (A(n.name)) {
|
|
145
|
+
let t = j(n.name, r, i);
|
|
146
|
+
return t && e.applyRunLifecycle(t), t;
|
|
147
|
+
}
|
|
148
|
+
let { inputs: a, outputs: o } = t.decode(n);
|
|
149
|
+
(a.length > 0 || o.length > 0 || r["run-id"]) && e.applyMessage({
|
|
150
|
+
inputs: a,
|
|
151
|
+
outputs: o
|
|
152
|
+
}, r, i);
|
|
153
|
+
}, ue = class e {
|
|
154
|
+
constructor(e) {
|
|
155
|
+
this.inputEventId = e.inputEventId, this.sessionName = e.sessionName;
|
|
156
|
+
}
|
|
157
|
+
static fromJSON(t) {
|
|
158
|
+
return new e(t);
|
|
159
|
+
}
|
|
160
|
+
toJSON() {
|
|
161
|
+
return {
|
|
162
|
+
inputEventId: this.inputEventId,
|
|
163
|
+
sessionName: this.sessionName
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}, N = (e) => e.kind === "run" ? e.runId : e.codecMessageId, P = (e) => e.kind === "run" ? e.startSerial : e.serial, F = (e, t, n) => {
|
|
167
|
+
let r = e.get(t);
|
|
168
|
+
r || (r = /* @__PURE__ */ new Set(), e.set(t, r)), r.add(n);
|
|
169
|
+
}, I = (e, t, n) => {
|
|
170
|
+
let r = e.get(t);
|
|
171
|
+
r && (r.delete(n), r.size === 0 && e.delete(t));
|
|
172
|
+
}, L = class {
|
|
107
173
|
constructor(e, t) {
|
|
108
|
-
this._nodeIndex = /* @__PURE__ */ new Map(), this.
|
|
174
|
+
this._nodeIndex = /* @__PURE__ */ new Map(), this._codecMessageIdToNodeKey = /* @__PURE__ */ new Map(), this._sortedNodes = [], this._parentIndex = /* @__PURE__ */ new Map(), this._replyRunsByInput = /* @__PURE__ */ new Map(), this._seqCounter = 0, this._structuralVersion = 0, this._siblingCache = /* @__PURE__ */ new Map(), this._siblingCacheVersion = -1, this._codec = e, this._logger = t, this._emitter = new w(t);
|
|
109
175
|
}
|
|
110
176
|
_compareNodes(e, t) {
|
|
111
|
-
let n = e.node
|
|
177
|
+
let n = P(e.node), r = P(t.node);
|
|
112
178
|
return n === void 0 && r === void 0 ? e.insertSeq - t.insertSeq : n === void 0 ? 1 : r === void 0 || n < r ? -1 : n > r ? 1 : e.insertSeq - t.insertSeq;
|
|
113
179
|
}
|
|
114
|
-
|
|
115
|
-
if (e.node
|
|
116
|
-
this.
|
|
180
|
+
_insertSortedNode(e) {
|
|
181
|
+
if (P(e.node) === void 0) {
|
|
182
|
+
this._sortedNodes.push(e);
|
|
117
183
|
return;
|
|
118
184
|
}
|
|
119
|
-
let t = 0, n = this.
|
|
185
|
+
let t = 0, n = this._sortedNodes.length;
|
|
120
186
|
for (; t < n;) {
|
|
121
|
-
let r = t + n >>> 1, i = this.
|
|
187
|
+
let r = t + n >>> 1, i = this._sortedNodes[r];
|
|
122
188
|
if (!i) break;
|
|
123
189
|
this._compareNodes(i, e) <= 0 ? t = r + 1 : n = r;
|
|
124
190
|
}
|
|
125
|
-
this.
|
|
191
|
+
this._sortedNodes.splice(t, 0, e);
|
|
192
|
+
}
|
|
193
|
+
_removeSortedNode(e) {
|
|
194
|
+
let t = this._sortedNodes.indexOf(e);
|
|
195
|
+
t !== -1 && this._sortedNodes.splice(t, 1);
|
|
196
|
+
}
|
|
197
|
+
_insertNode(e, t, n) {
|
|
198
|
+
this._nodeIndex.set(e, t), this._addToParentIndex(n, e), this._insertSortedNode(t), this._structuralVersion++;
|
|
126
199
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
200
|
+
_promoteSerial(e) {
|
|
201
|
+
this._removeSortedNode(e), this._insertSortedNode(e), this._structuralVersion++;
|
|
202
|
+
}
|
|
203
|
+
_foldInto(e, t, n, r) {
|
|
204
|
+
for (let i of t) try {
|
|
205
|
+
e.node.projection = this._codec.fold(e.node.projection, i, {
|
|
206
|
+
serial: n ?? "",
|
|
207
|
+
messageId: r
|
|
208
|
+
});
|
|
209
|
+
} catch (t) {
|
|
210
|
+
this._logger.error("Tree._foldInto(); fold threw", {
|
|
211
|
+
key: N(e.node),
|
|
212
|
+
messageId: r,
|
|
213
|
+
err: t
|
|
214
|
+
});
|
|
215
|
+
}
|
|
130
216
|
}
|
|
131
217
|
_addToParentIndex(e, t) {
|
|
132
|
-
|
|
133
|
-
n || (n = /* @__PURE__ */ new Set(), this._parentIndex.set(e, n)), n.add(t);
|
|
218
|
+
F(this._parentIndex, e, t);
|
|
134
219
|
}
|
|
135
220
|
_removeFromParentIndex(e, t) {
|
|
136
|
-
|
|
137
|
-
|
|
221
|
+
I(this._parentIndex, e, t);
|
|
222
|
+
}
|
|
223
|
+
_parentKeyOf(e) {
|
|
224
|
+
let t = e.parentCodecMessageId;
|
|
225
|
+
return t === void 0 ? void 0 : this._codecMessageIdToNodeKey.get(t);
|
|
226
|
+
}
|
|
227
|
+
_inputGroupRoot(e) {
|
|
228
|
+
let t = e, n = new Set([N(t)]);
|
|
229
|
+
for (; t.forkOf !== void 0 && !n.has(t.forkOf);) {
|
|
230
|
+
let e = this._nodeIndex.get(t.forkOf);
|
|
231
|
+
if (e?.node.kind !== "input" || e.node.parentCodecMessageId !== t.parentCodecMessageId) break;
|
|
232
|
+
t = e.node, n.add(N(t));
|
|
233
|
+
}
|
|
234
|
+
return t;
|
|
138
235
|
}
|
|
139
236
|
_getSiblingGroup(e) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
if (s) for (let e of s) {
|
|
237
|
+
this._siblingCacheVersion !== this._structuralVersion && (this._siblingCache.clear(), this._siblingCacheVersion = this._structuralVersion);
|
|
238
|
+
let t = this._siblingCache.get(e);
|
|
239
|
+
if (t) return t;
|
|
240
|
+
let n = this._nodeIndex.get(e);
|
|
241
|
+
if (!n) return [];
|
|
242
|
+
let r = n.node;
|
|
243
|
+
r.kind === "input" && (r = this._inputGroupRoot(r));
|
|
244
|
+
let i = r.parentCodecMessageId, a = [], o = this._parentIndex.get(i);
|
|
245
|
+
if (o) for (let e of o) {
|
|
150
246
|
let t = this._nodeIndex.get(e);
|
|
151
|
-
t && this._isSiblingOf(t.node,
|
|
247
|
+
t && this._isSiblingOf(t.node, r) && a.push(t);
|
|
152
248
|
}
|
|
153
|
-
|
|
249
|
+
a.sort((e, t) => this._compareNodes(e, t));
|
|
250
|
+
for (let e of a) this._siblingCache.set(N(e.node), a);
|
|
251
|
+
return this._siblingCache.set(e, a), a;
|
|
154
252
|
}
|
|
155
253
|
_isSiblingOf(e, t) {
|
|
156
|
-
if (e.
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
254
|
+
if (e.kind !== t.kind || e.parentCodecMessageId !== t.parentCodecMessageId) return !1;
|
|
255
|
+
if (e.kind === "run") return !0;
|
|
256
|
+
let n = N(t);
|
|
257
|
+
if (N(e) === n) return !0;
|
|
258
|
+
let r = e, i = new Set([N(r)]);
|
|
259
|
+
for (; r.kind === "input" && r.forkOf !== void 0;) {
|
|
260
|
+
if (r.forkOf === n) return !0;
|
|
261
|
+
if (i.has(r.forkOf)) break;
|
|
262
|
+
let e = this._nodeIndex.get(r.forkOf);
|
|
162
263
|
if (!e) break;
|
|
163
|
-
|
|
264
|
+
r = e.node, i.add(N(r));
|
|
164
265
|
}
|
|
165
266
|
return !1;
|
|
166
267
|
}
|
|
167
|
-
|
|
268
|
+
getGroupRoot(e) {
|
|
168
269
|
let t = this._nodeIndex.get(e);
|
|
169
270
|
if (!t) return e;
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
271
|
+
if (t.node.kind === "input") return N(this._inputGroupRoot(t.node));
|
|
272
|
+
let n = this._getSiblingGroup(e)[0]?.node;
|
|
273
|
+
return n ? N(n) : e;
|
|
274
|
+
}
|
|
275
|
+
visibleNodes(e = /* @__PURE__ */ new Map()) {
|
|
276
|
+
this._logger.trace("DefaultTree.visibleNodes();");
|
|
277
|
+
let t = [], n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Map();
|
|
278
|
+
for (let i of this._sortedNodes) {
|
|
279
|
+
let a = i.node, o = N(a), s = this._parentKeyOf(a);
|
|
280
|
+
if (s !== void 0 && !n.has(s)) continue;
|
|
281
|
+
let c = this._getSiblingGroup(o);
|
|
282
|
+
if (c.length > 1) {
|
|
283
|
+
let t = this.getGroupRoot(o), n = r.get(t);
|
|
284
|
+
if (n === void 0) {
|
|
285
|
+
let i = e.get(t);
|
|
286
|
+
if (i !== void 0 && c.some((e) => N(e.node) === i)) n = i;
|
|
287
|
+
else {
|
|
288
|
+
let e = c.at(-1);
|
|
289
|
+
if (!e) break;
|
|
290
|
+
n = N(e.node);
|
|
291
|
+
}
|
|
292
|
+
r.set(t, n);
|
|
190
293
|
}
|
|
191
|
-
if (
|
|
294
|
+
if (o !== n) continue;
|
|
192
295
|
}
|
|
193
|
-
|
|
296
|
+
n.add(o), t.push(a);
|
|
194
297
|
}
|
|
195
|
-
return
|
|
298
|
+
return t;
|
|
196
299
|
}
|
|
197
|
-
|
|
198
|
-
|
|
300
|
+
getRunNode(e) {
|
|
301
|
+
this._logger.trace("DefaultTree.getRunNode();", { runId: e });
|
|
302
|
+
let t = this._nodeIndex.get(e)?.node;
|
|
303
|
+
return t?.kind === "run" ? t : void 0;
|
|
199
304
|
}
|
|
200
|
-
|
|
201
|
-
return this.
|
|
305
|
+
getNode(e) {
|
|
306
|
+
return this._logger.trace("DefaultTree.getNode();", { key: e }), this._nodeIndex.get(e)?.node;
|
|
202
307
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
return r === void 0 ? t.length - 1 : Math.max(0, Math.min(r, t.length - 1));
|
|
308
|
+
getNodeByCodecMessageId(e) {
|
|
309
|
+
this._logger.trace("DefaultTree.getNodeByCodecMessageId();", { codecMessageId: e });
|
|
310
|
+
let t = this._codecMessageIdToNodeKey.get(e);
|
|
311
|
+
return t === void 0 ? void 0 : this._nodeIndex.get(t)?.node;
|
|
208
312
|
}
|
|
209
|
-
|
|
210
|
-
this.
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
313
|
+
getReplyRuns(e) {
|
|
314
|
+
let t = this._replyRunsByInput.get(e);
|
|
315
|
+
if (!t) return [];
|
|
316
|
+
let n = [];
|
|
317
|
+
for (let e of t) {
|
|
318
|
+
let t = this._nodeIndex.get(e)?.node;
|
|
319
|
+
t?.kind === "run" && n.push(t);
|
|
320
|
+
}
|
|
321
|
+
return n;
|
|
218
322
|
}
|
|
219
|
-
|
|
220
|
-
return this.
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
let t =
|
|
224
|
-
if (
|
|
225
|
-
|
|
226
|
-
getHeaders(e) {
|
|
227
|
-
return this._nodeIndex.get(e)?.node.headers;
|
|
228
|
-
}
|
|
229
|
-
upsert(e, t, n, r) {
|
|
230
|
-
let i = n["x-ably-parent"] ?? void 0, a = n["x-ably-fork-of"] ?? void 0;
|
|
231
|
-
this._codecKeyIndex.set(this._getKey(t), e);
|
|
232
|
-
let o = this._nodeIndex.get(e);
|
|
233
|
-
if (o) {
|
|
234
|
-
o.node.message = t, Object.keys(n).length > 0 && (o.node.headers = { ...n }), r && !o.node.serial && (this._logger.debug("ConversationTree.upsert(); promoting serial", {
|
|
235
|
-
msgId: e,
|
|
236
|
-
serial: r
|
|
237
|
-
}), o.node.serial = r, this._removeSorted(o), this._insertSorted(o));
|
|
323
|
+
getSiblingNodes(e) {
|
|
324
|
+
return this._logger.trace("DefaultTree.getSiblingNodes();", { key: e }), this._getSiblingGroup(e).map((e) => e.node);
|
|
325
|
+
}
|
|
326
|
+
applyMessage(e, t, n) {
|
|
327
|
+
let r = t[d], i = t[m], a = r === void 0 && i !== void 0 && t.role === "user" && e.inputs.length > 0 ? i : void 0;
|
|
328
|
+
if (r === void 0 && a === void 0) {
|
|
329
|
+
this._logger.warn("Tree.applyMessage(); message has no run-id and is not a user input; skipping");
|
|
238
330
|
return;
|
|
239
331
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
332
|
+
let o = [...e.inputs, ...e.outputs], s = a ?? r;
|
|
333
|
+
if (o.length === 0 && s !== void 0 && !this._nodeIndex.has(s)) return;
|
|
334
|
+
let c = this._structuralVersion;
|
|
335
|
+
a === void 0 ? r !== void 0 && this._applyRunMessage(r, e, t, n) : this._applyInputMessage(a, t, n, o), this._structuralVersion !== c && this._emitter.emit("update");
|
|
336
|
+
}
|
|
337
|
+
_applyInputMessage(e, t, n, r) {
|
|
338
|
+
let i = this._nodeIndex.get(e);
|
|
339
|
+
i ? i.node.kind === "input" && n && !i.node.serial && (this._logger.debug("Tree.applyMessage(); promoting input serial", {
|
|
340
|
+
codecMessageId: e,
|
|
341
|
+
serial: n
|
|
342
|
+
}), i.node.serial = n, this._promoteSerial(i)) : (i = this._createInputNodeFromHeaders(e, t, n), this._insertNode(e, i, i.node.parentCodecMessageId), this._codecMessageIdToNodeKey.set(e, e), this._logger.debug("Tree.applyMessage(); created input node", { codecMessageId: e })), this._foldInto(i, r, n, e), this._emitter.emit("output", {
|
|
343
|
+
runId: void 0,
|
|
344
|
+
inputCodecMessageId: e,
|
|
345
|
+
codecMessageId: e,
|
|
346
|
+
serial: n,
|
|
347
|
+
events: []
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
_applyRunMessage(e, t, n, r) {
|
|
351
|
+
let i = n[m], a = n[x], o = [...t.inputs, ...t.outputs], s = t.outputs, c = this._nodeIndex.get(e);
|
|
352
|
+
if (!c && i !== void 0) {
|
|
353
|
+
let e = this._codecMessageIdToNodeKey.get(i), t = e === void 0 ? void 0 : this._nodeIndex.get(e);
|
|
354
|
+
t?.node.kind === "run" && t.node.startSerial === void 0 && (c = t);
|
|
355
|
+
}
|
|
356
|
+
c ? r && c.node.kind === "run" && !c.node.startSerial && (this._logger.debug("Tree.applyMessage(); promoting startSerial", {
|
|
357
|
+
runId: e,
|
|
358
|
+
serial: r
|
|
359
|
+
}), c.node.startSerial = r, this._promoteSerial(c)) : (c = this._createRunFromHeaders(e, n, r), this._insertNode(e, c, c.node.parentCodecMessageId), this._indexReplyRun(c.node, e), this._logger.debug("Tree.applyMessage(); created new Run", { runId: e }));
|
|
360
|
+
let l = N(c.node);
|
|
361
|
+
i && this._codecMessageIdToNodeKey.set(i, l), this._foldInto(c, o, r, i), this._emitter.emit("output", {
|
|
362
|
+
runId: l,
|
|
363
|
+
inputCodecMessageId: a,
|
|
364
|
+
codecMessageId: i,
|
|
365
|
+
serial: r,
|
|
366
|
+
events: s
|
|
244
367
|
});
|
|
245
|
-
|
|
368
|
+
}
|
|
369
|
+
_indexReplyRun(e, t) {
|
|
370
|
+
e.parentCodecMessageId !== void 0 && F(this._replyRunsByInput, e.parentCodecMessageId, t);
|
|
371
|
+
}
|
|
372
|
+
applyRunLifecycle(e) {
|
|
373
|
+
this._logger.trace("DefaultTree.applyRunLifecycle();", {
|
|
374
|
+
type: e.type,
|
|
375
|
+
runId: e.runId
|
|
376
|
+
});
|
|
377
|
+
let t = this._structuralVersion;
|
|
378
|
+
switch (e.type) {
|
|
379
|
+
case "start":
|
|
380
|
+
this._applyRunStart(e);
|
|
381
|
+
break;
|
|
382
|
+
case "suspend":
|
|
383
|
+
this._applyRunSuspend(e);
|
|
384
|
+
break;
|
|
385
|
+
case "resume":
|
|
386
|
+
this._applyRunResume(e);
|
|
387
|
+
break;
|
|
388
|
+
case "end":
|
|
389
|
+
this._applyRunEnd(e);
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
392
|
+
this._emitter.emit("run", e), this._structuralVersion !== t && this._emitter.emit("update");
|
|
393
|
+
}
|
|
394
|
+
_applyRunStart(e) {
|
|
395
|
+
let t = this._nodeIndex.get(e.runId);
|
|
396
|
+
if (t?.node.kind === "run") {
|
|
397
|
+
let n = t.node;
|
|
398
|
+
if (n.status !== "active" && (n.status = "active"), e.serial && !n.startSerial && (n.startSerial = e.serial, this._promoteSerial(t)), n.parentCodecMessageId === void 0 && e.parent !== void 0 && (n.parentCodecMessageId = e.parent, this._removeFromParentIndex(void 0, e.runId), this._addToParentIndex(n.parentCodecMessageId, e.runId), this._indexReplyRun(n, e.runId), this._structuralVersion++), n.forkOf === void 0 && e.forkOf !== void 0) {
|
|
399
|
+
let t = this._codecMessageIdToNodeKey.get(e.forkOf);
|
|
400
|
+
t !== void 0 && t !== e.runId && (n.forkOf = t, this._structuralVersion++);
|
|
401
|
+
}
|
|
402
|
+
n.regeneratesCodecMessageId === void 0 && e.regenerates !== void 0 && (n.regeneratesCodecMessageId = e.regenerates, this._structuralVersion++), n.invocationId === "" && e.invocationId !== "" && (n.invocationId = e.invocationId);
|
|
403
|
+
} else if (!t) {
|
|
404
|
+
let t = this._createRunFromLifecycle(e);
|
|
405
|
+
this._insertNode(e.runId, t, t.node.parentCodecMessageId), this._indexReplyRun(t.node, e.runId);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
_applyRunSuspend(e) {
|
|
409
|
+
let t = this._nodeIndex.get(e.runId);
|
|
410
|
+
t?.node.kind === "run" && (t.node.status = "suspended", t.node.endSerial = e.serial);
|
|
411
|
+
}
|
|
412
|
+
_applyRunResume(e) {
|
|
413
|
+
let t = this._nodeIndex.get(e.runId);
|
|
414
|
+
t?.node.kind === "run" && t.node.status === "suspended" && (t.node.status = "active");
|
|
415
|
+
}
|
|
416
|
+
_applyRunEnd(e) {
|
|
417
|
+
let t = this._nodeIndex.get(e.runId);
|
|
418
|
+
t?.node.kind === "run" && (t.node.status = e.reason, t.node.endSerial = e.serial);
|
|
419
|
+
}
|
|
420
|
+
delete(e) {
|
|
421
|
+
let t = this._nodeIndex.get(e);
|
|
422
|
+
t && (this._logger.debug("Tree.delete();", { key: e }), this._removeFromParentIndex(t.node.parentCodecMessageId, e), this._removeSortedNode(t), this._nodeIndex.delete(e), t.node.kind === "run" && t.node.parentCodecMessageId !== void 0 && I(this._replyRunsByInput, t.node.parentCodecMessageId, e), this._structuralVersion++, this._emitter.emit("update"));
|
|
423
|
+
}
|
|
424
|
+
_createRunFromHeaders(e, t, n) {
|
|
425
|
+
let r = t[y];
|
|
426
|
+
return this._buildRunNode({
|
|
427
|
+
runId: e,
|
|
428
|
+
parentCodecMessageId: t[v],
|
|
429
|
+
forkOf: r ? this._codecMessageIdToNodeKey.get(r) : void 0,
|
|
430
|
+
regeneratesCodecMessageId: t[b],
|
|
431
|
+
clientId: t["run-client-id"] ?? "",
|
|
432
|
+
invocationId: t["invocation-id"] ?? "",
|
|
433
|
+
startSerial: n
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
_buildRunNode(e) {
|
|
437
|
+
return {
|
|
246
438
|
node: {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
forkOf:
|
|
251
|
-
|
|
252
|
-
|
|
439
|
+
kind: "run",
|
|
440
|
+
runId: e.runId,
|
|
441
|
+
parentCodecMessageId: e.parentCodecMessageId,
|
|
442
|
+
forkOf: e.forkOf,
|
|
443
|
+
regeneratesCodecMessageId: e.regeneratesCodecMessageId,
|
|
444
|
+
clientId: e.clientId,
|
|
445
|
+
invocationId: e.invocationId,
|
|
446
|
+
status: "active",
|
|
447
|
+
projection: this._codec.init(),
|
|
448
|
+
startSerial: e.startSerial,
|
|
449
|
+
endSerial: void 0
|
|
253
450
|
},
|
|
254
451
|
insertSeq: this._seqCounter++
|
|
255
452
|
};
|
|
256
|
-
this._nodeIndex.set(e, s), this._addToParentIndex(i, e), this._insertSorted(s);
|
|
257
453
|
}
|
|
258
|
-
|
|
259
|
-
let
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
for (let n of t) if (n.kind === "message") {
|
|
283
|
-
let t = e.getMessageKey(n.message), r = c.get(t);
|
|
284
|
-
r ? Object.keys(d).length > 0 && Object.assign(r, d) : (c.set(t, { ...d }), m && l.set(t, m));
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
let u = [];
|
|
288
|
-
for (let t of i.completedMessages) {
|
|
289
|
-
let n = e.getMessageKey(t);
|
|
290
|
-
u.push({
|
|
291
|
-
message: t,
|
|
292
|
-
headers: c.get(n) ?? {},
|
|
293
|
-
serial: l.get(n) ?? ""
|
|
454
|
+
_createInputNodeFromHeaders(e, t, n) {
|
|
455
|
+
let r = t[y];
|
|
456
|
+
return {
|
|
457
|
+
node: {
|
|
458
|
+
kind: "input",
|
|
459
|
+
codecMessageId: e,
|
|
460
|
+
parentCodecMessageId: t[v],
|
|
461
|
+
forkOf: r,
|
|
462
|
+
projection: this._codec.init(),
|
|
463
|
+
serial: n
|
|
464
|
+
},
|
|
465
|
+
insertSeq: this._seqCounter++
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
_createRunFromLifecycle(e) {
|
|
469
|
+
let t = e.forkOf;
|
|
470
|
+
return this._buildRunNode({
|
|
471
|
+
runId: e.runId,
|
|
472
|
+
parentCodecMessageId: e.parent,
|
|
473
|
+
forkOf: t ? this._codecMessageIdToNodeKey.get(t) : void 0,
|
|
474
|
+
regeneratesCodecMessageId: e.regenerates,
|
|
475
|
+
clientId: e.clientId,
|
|
476
|
+
invocationId: e.invocationId,
|
|
477
|
+
startSerial: e.serial
|
|
294
478
|
});
|
|
295
479
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
if (o) {
|
|
302
|
-
r.set(t, o);
|
|
303
|
-
let e = l.get(t);
|
|
304
|
-
e && i.set(t, e);
|
|
305
|
-
let a = o[s];
|
|
306
|
-
a && n.add(a);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
let a = [...t.msgHeaders.entries()].filter(([e]) => !n.has(e)), o = 0;
|
|
310
|
-
for (let n of t.accumulator.completedMessages) {
|
|
311
|
-
let s = e.getMessageKey(n), c = a[o];
|
|
312
|
-
if (!r.has(s) && c) {
|
|
313
|
-
let [e, n] = c;
|
|
314
|
-
r.set(s, n);
|
|
315
|
-
let a = t.msgSerials.get(e);
|
|
316
|
-
a && i.set(s, a), o++;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
for (let n of t.accumulator.completedMessages) {
|
|
320
|
-
let t = e.getMessageKey(n);
|
|
321
|
-
u.push({
|
|
322
|
-
message: n,
|
|
323
|
-
headers: r.get(t) ?? {},
|
|
324
|
-
serial: i.get(t) ?? ""
|
|
325
|
-
});
|
|
326
|
-
}
|
|
480
|
+
on(e, t) {
|
|
481
|
+
let n = t;
|
|
482
|
+
return this._emitter.on(e, n), () => {
|
|
483
|
+
this._emitter.off(e, n);
|
|
484
|
+
};
|
|
327
485
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
for (
|
|
333
|
-
|
|
486
|
+
emitAblyMessage(e) {
|
|
487
|
+
this._logger.trace("DefaultTree.emitAblyMessage();"), this._emitter.emit("ably-message", e);
|
|
488
|
+
}
|
|
489
|
+
}, R = (e, t) => new L(e, t), z = (e, t) => {
|
|
490
|
+
for (let n of t) {
|
|
491
|
+
let t = D(n), r = t[m];
|
|
492
|
+
if (!r) continue;
|
|
493
|
+
let i = n.action, a = i === "message.create" && "discrete" in t, o = t.stream === "true" && (i === "message.create" || i === "message.update" || i === "message.append"), s = t[u], c = s === "complete" || s === "cancelled";
|
|
494
|
+
(a || o) && e.startedCodecMessageIds.add(r), (a || c) && e.terminatedCodecMessageIds.add(r), e.startedCodecMessageIds.has(r) && e.terminatedCodecMessageIds.has(r) && e.completedCodecMessageIds.add(r);
|
|
495
|
+
}
|
|
496
|
+
}, B = async (e, t, n) => {
|
|
497
|
+
e.rawMessages.push(...t.items), e.lastAblyPage = t, z(e, t.items);
|
|
498
|
+
let r = e.returnedCount + n;
|
|
499
|
+
for (; e.completedCodecMessageIds.size < r && t.hasNext();) {
|
|
500
|
+
e.logger.debug("loadHistory.fetchUntilLimit(); fetching next page", {
|
|
334
501
|
collected: e.rawMessages.length,
|
|
335
|
-
|
|
502
|
+
completed: e.completedCodecMessageIds.size
|
|
336
503
|
});
|
|
337
504
|
let n = await t.next();
|
|
338
505
|
if (!n) break;
|
|
339
|
-
t = n, e.rawMessages.push(...n.items), e.lastAblyPage = n,
|
|
506
|
+
t = n, e.rawMessages.push(...n.items), e.lastAblyPage = n, z(e, n.items);
|
|
340
507
|
}
|
|
341
|
-
},
|
|
342
|
-
let n =
|
|
343
|
-
e.returnedCount += r
|
|
344
|
-
let
|
|
508
|
+
}, V = (e, t) => {
|
|
509
|
+
let n = e.completedCodecMessageIds.size, r = Math.min(t, Math.max(0, n - e.returnedCount));
|
|
510
|
+
e.returnedCount += r;
|
|
511
|
+
let i = n > e.returnedCount, a = e.lastAblyPage?.hasNext() ?? !1, o = e.rawMessages.length - e.returnedRawCount > 0 ? e.rawMessages.slice(e.returnedRawCount).toReversed() : [];
|
|
345
512
|
return e.returnedRawCount = e.rawMessages.length, {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
itemSerials: i.map((e) => e.serial),
|
|
349
|
-
rawMessages: s,
|
|
350
|
-
hasNext: () => a || o,
|
|
513
|
+
rawMessages: o,
|
|
514
|
+
hasNext: () => i || a,
|
|
351
515
|
next: async () => {
|
|
352
|
-
if (
|
|
353
|
-
if (!
|
|
516
|
+
if (i) return V(e, t);
|
|
517
|
+
if (!a || !e.lastAblyPage) return;
|
|
354
518
|
let n = await e.lastAblyPage.next();
|
|
355
|
-
if (n) return await
|
|
519
|
+
if (n) return await B(e, n, t), V(e, t);
|
|
356
520
|
}
|
|
357
521
|
};
|
|
358
|
-
},
|
|
359
|
-
let
|
|
360
|
-
codec: t,
|
|
522
|
+
}, H = async (e, t, n) => {
|
|
523
|
+
let r = t?.limit ?? 100, i = {
|
|
361
524
|
rawMessages: [],
|
|
362
525
|
returnedCount: 0,
|
|
363
526
|
returnedRawCount: 0,
|
|
364
527
|
lastAblyPage: void 0,
|
|
365
|
-
|
|
366
|
-
|
|
528
|
+
startedCodecMessageIds: /* @__PURE__ */ new Set(),
|
|
529
|
+
terminatedCodecMessageIds: /* @__PURE__ */ new Set(),
|
|
530
|
+
completedCodecMessageIds: /* @__PURE__ */ new Set(),
|
|
531
|
+
logger: n
|
|
367
532
|
};
|
|
368
|
-
|
|
369
|
-
let
|
|
370
|
-
return await e.attach(), await
|
|
533
|
+
n.trace("loadHistory();", { limit: r });
|
|
534
|
+
let a = r * 10;
|
|
535
|
+
return await e.attach(), await B(i, await e.history({
|
|
371
536
|
untilAttach: !0,
|
|
372
|
-
limit:
|
|
373
|
-
}),
|
|
374
|
-
},
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
},
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
}
|
|
390
|
-
if (!t.controller) throw new i.ErrorInfo("unable to create stream; ReadableStream start() was not called synchronously", b.TransportSubscriptionError, 500);
|
|
391
|
-
return this._turns.set(e, {
|
|
392
|
-
controller: t.controller,
|
|
393
|
-
turnId: e
|
|
394
|
-
}), n;
|
|
395
|
-
}
|
|
396
|
-
closeStream(e) {
|
|
397
|
-
let t = this._turns.get(e);
|
|
398
|
-
if (!t) return !1;
|
|
399
|
-
this._logger.debug("StreamRouter.closeStream(); closing stream", { turnId: e });
|
|
400
|
-
try {
|
|
401
|
-
t.controller.close();
|
|
402
|
-
} catch {}
|
|
403
|
-
return this._turns.delete(e), !0;
|
|
537
|
+
limit: a
|
|
538
|
+
}), r), V(i, r);
|
|
539
|
+
}, de = (e) => Array.isArray(e) ? e : [e], fe = 3, U = (e) => ({
|
|
540
|
+
runId: e.runId,
|
|
541
|
+
clientId: e.clientId,
|
|
542
|
+
status: e.status,
|
|
543
|
+
invocationId: e.invocationId
|
|
544
|
+
}), pe = class {
|
|
545
|
+
constructor(e) {
|
|
546
|
+
this._branchSelections = /* @__PURE__ */ new Map(), this._regenSelections = /* @__PURE__ */ new Map(), this._withheldRunIds = /* @__PURE__ */ new Set(), this._lastVisibleNodeKeys = [], this._lastVisibleProjections = [], this._lastVisibleMessagePairs = [], this._lastVisibleNodeKeySet = /* @__PURE__ */ new Set(), this._hasMoreHistory = !1, this._withheldBuffer = [], this._unsubs = [], this._cachedNodes = [], this._loadingOlder = !1, this._processingHistory = !1, this._closed = !1, this._tree = e.tree, this._channel = e.channel, this._codec = e.codec, this._sendDelegate = e.sendDelegate, this._onClose = e.onClose, this._logger = e.logger.withContext({ component: "View" }), this._logger.trace("DefaultView();"), this._emitter = new w(this._logger), this._cachedNodes = this._computeFlatNodes(), this._updateVisibleSnapshot(this._cachedNodes), this._unsubs.push(this._tree.on("update", () => {
|
|
547
|
+
this._onTreeUpdate();
|
|
548
|
+
}), this._tree.on("ably-message", (e) => {
|
|
549
|
+
this._onTreeAblyMessage(e);
|
|
550
|
+
}), this._tree.on("run", (e) => {
|
|
551
|
+
this._onTreeRun(e);
|
|
552
|
+
}), this._tree.on("output", (e) => {
|
|
553
|
+
this._onTreeOutput(e);
|
|
554
|
+
}));
|
|
404
555
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
if (!n) return !1;
|
|
408
|
-
try {
|
|
409
|
-
n.controller.enqueue(t);
|
|
410
|
-
} catch {
|
|
411
|
-
return this._turns.delete(e), !1;
|
|
412
|
-
}
|
|
413
|
-
return this._isTerminal(t) && this.closeStream(e), !0;
|
|
556
|
+
_onTreeOutput(e) {
|
|
557
|
+
this._processingHistory || (e.runId !== void 0 && this._lastVisibleNodeKeySet.has(e.runId) || e.inputCodecMessageId !== void 0 && this._lastVisibleNodeKeySet.has(e.inputCodecMessageId)) && (this._lastVisibleProjections = this._cachedNodes.map((e) => e.projection), this._lastVisibleMessagePairs = this._extractMessages(this._cachedNodes), this._emitter.emit("update"));
|
|
414
558
|
}
|
|
415
|
-
|
|
416
|
-
return this.
|
|
559
|
+
getMessages() {
|
|
560
|
+
return this._lastVisibleMessagePairs;
|
|
417
561
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
if (this._ownMsgIds = /* @__PURE__ */ new Set(), this._ownTurnIds = /* @__PURE__ */ new Set(), this._turnClientIds = /* @__PURE__ */ new Map(), this._turnMsgIds = /* @__PURE__ */ new Map(), this._turnObservers = /* @__PURE__ */ new Map(), this._ablyMessages = [], this._withheldKeys = /* @__PURE__ */ new Set(), this._closed = !1, this._channel = e.channel, this._codec = e.codec, this._clientId = e.clientId, this._api = e.api ?? "/api/chat", this._credentials = e.credentials, this._headersFn = typeof e.headers == "function" ? e.headers : e.headers ? () => e.headers : void 0, this._bodyFn = typeof e.body == "function" ? e.body : e.body ? () => e.body : void 0, this._fetchFn = e.fetch ?? globalThis.fetch.bind(globalThis), this._logger = (e.logger ?? E({ logLevel: w.Silent })).withContext({ component: "ClientTransport" }), this._emitter = new C(this._logger), this._tree = M(this._codec.getMessageKey.bind(this._codec), this._logger), this._router = z(this._codec.isTerminal.bind(this._codec), this._logger), this._decoder = this._codec.createDecoder(), e.messages) {
|
|
421
|
-
let t;
|
|
422
|
-
for (let n of e.messages) {
|
|
423
|
-
let e = this._codec.getMessageKey(n), r = {};
|
|
424
|
-
t && (r[m] = t), this._tree.upsert(e, n, r), t = e;
|
|
425
|
-
}
|
|
426
|
-
this._emitter.emit("message");
|
|
427
|
-
}
|
|
428
|
-
this._onMessage = (e) => {
|
|
429
|
-
this._handleMessage(e);
|
|
430
|
-
}, this._attachPromise = this._channel.subscribe(this._onMessage);
|
|
562
|
+
runs() {
|
|
563
|
+
return this._cachedNodes.filter((e) => e.kind === "run").map((e) => U(e));
|
|
431
564
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
565
|
+
_computeFlatNodes() {
|
|
566
|
+
let e = this._treeVisibleNodes();
|
|
567
|
+
return this._withheldRunIds.size === 0 ? e : e.filter((e) => !this._withheldRunIds.has(N(e)));
|
|
568
|
+
}
|
|
569
|
+
_recomputeAndEmit() {
|
|
570
|
+
this._cachedNodes = this._computeFlatNodes(), this._updateVisibleSnapshot(this._cachedNodes), this._emitter.emit("update");
|
|
571
|
+
}
|
|
572
|
+
_recomputeAndEmitIfChanged() {
|
|
573
|
+
let e = this._computeFlatNodes();
|
|
574
|
+
this._visibleChanged(e) && (this._cachedNodes = e, this._updateVisibleSnapshot(e), this._emitter.emit("update"));
|
|
575
|
+
}
|
|
576
|
+
_runByCodecMessageId(e) {
|
|
577
|
+
let t = this._tree.getNodeByCodecMessageId(e);
|
|
578
|
+
return t?.kind === "run" ? t : void 0;
|
|
579
|
+
}
|
|
580
|
+
_extractMessages(e) {
|
|
581
|
+
let t = [];
|
|
582
|
+
for (let n of e) for (let e of this._codec.getMessages(n.projection)) t.push(e);
|
|
583
|
+
return t;
|
|
584
|
+
}
|
|
585
|
+
hasOlder() {
|
|
586
|
+
return this._withheldBuffer.length > 0 || this._hasMoreHistory;
|
|
587
|
+
}
|
|
588
|
+
async loadOlder(e = 100) {
|
|
589
|
+
if (!(this._closed || this._loadingOlder)) {
|
|
590
|
+
this._loadingOlder = !0, this._logger.trace("DefaultView.loadOlder();", { limit: e });
|
|
435
591
|
try {
|
|
436
|
-
if (
|
|
437
|
-
let t =
|
|
438
|
-
|
|
439
|
-
type: _,
|
|
440
|
-
turnId: n,
|
|
441
|
-
clientId: r
|
|
442
|
-
}));
|
|
592
|
+
if (this._withheldBuffer.length > 0) {
|
|
593
|
+
let t = this._withheldBuffer.splice(-e, e);
|
|
594
|
+
this._releaseWithheld(t);
|
|
443
595
|
return;
|
|
444
596
|
}
|
|
445
|
-
if (
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
this._turnMsgIds.delete(n);
|
|
453
|
-
}
|
|
454
|
-
this._ownTurnIds.delete(n), this._emitter.emit("turn", {
|
|
455
|
-
type: v,
|
|
456
|
-
turnId: n,
|
|
457
|
-
clientId: r,
|
|
458
|
-
reason: i
|
|
459
|
-
});
|
|
460
|
-
}
|
|
597
|
+
if (!this._hasMoreHistory && !this._lastHistoryPage) {
|
|
598
|
+
await this._loadFirstPage(e);
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
if (!this._hasMoreHistory) return;
|
|
602
|
+
if (!this._lastHistoryPage?.hasNext()) {
|
|
603
|
+
this._hasMoreHistory = !1;
|
|
461
604
|
return;
|
|
462
605
|
}
|
|
463
|
-
let t = this.
|
|
464
|
-
|
|
465
|
-
|
|
606
|
+
let t = await this._lastHistoryPage.next();
|
|
607
|
+
if (this._closed || !t) {
|
|
608
|
+
t || (this._hasMoreHistory = !1);
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
await this._revealFromPage(t, e);
|
|
466
612
|
} catch (e) {
|
|
467
|
-
|
|
468
|
-
|
|
613
|
+
throw this._logger.error("DefaultView.loadOlder(); failed", { error: e }), e;
|
|
614
|
+
} finally {
|
|
615
|
+
this._loadingOlder = !1;
|
|
469
616
|
}
|
|
470
617
|
}
|
|
471
618
|
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
619
|
+
runOf(e) {
|
|
620
|
+
this._logger.trace("DefaultView.runOf();", { codecMessageId: e });
|
|
621
|
+
let t = this._tree.getNodeByCodecMessageId(e);
|
|
622
|
+
if (!t) return;
|
|
623
|
+
if (t.kind === "run") return U(t);
|
|
624
|
+
let n = this._selectedReplyRun(t.codecMessageId);
|
|
625
|
+
return n ? U(n) : void 0;
|
|
626
|
+
}
|
|
627
|
+
_selectedReplyRun(e) {
|
|
628
|
+
let t = this._tree.getReplyRuns(e);
|
|
629
|
+
if (t.length === 0) return;
|
|
630
|
+
if (t.length === 1) return t[0];
|
|
631
|
+
let n = this._tree.getGroupRoot(t[0]?.runId ?? ""), r = this._regenSelections.get(n), i = r && r.kind !== "pending" ? r.selectedRunId : void 0;
|
|
632
|
+
if (i !== void 0) {
|
|
633
|
+
let e = t.find((e) => e.runId === i);
|
|
634
|
+
if (e) return e;
|
|
477
635
|
}
|
|
478
|
-
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
let
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
636
|
+
return t.toSorted((e, t) => (e.startSerial ?? "").localeCompare(t.startSerial ?? "")).at(-1);
|
|
637
|
+
}
|
|
638
|
+
run(e) {
|
|
639
|
+
this._logger.trace("DefaultView.run();", { runId: e });
|
|
640
|
+
let t = this._tree.getRunNode(e);
|
|
641
|
+
return t ? U(t) : void 0;
|
|
642
|
+
}
|
|
643
|
+
branchSelection(e) {
|
|
644
|
+
let t = this._resolveMessageBranchPoint(e);
|
|
645
|
+
if (t) {
|
|
646
|
+
let e = t.siblings.flatMap((e) => {
|
|
647
|
+
let t = this._codec.getMessages(e.projection).at(0);
|
|
648
|
+
return t ? [t.message] : [];
|
|
649
|
+
});
|
|
650
|
+
if (e.length > 0) {
|
|
651
|
+
let n = this._resolveSelectedIndex(t), r = Math.max(0, Math.min(n, e.length - 1)), i = e[r];
|
|
652
|
+
return {
|
|
653
|
+
hasSiblings: e.length > 1,
|
|
654
|
+
siblings: e,
|
|
655
|
+
index: r,
|
|
656
|
+
selected: i
|
|
657
|
+
};
|
|
487
658
|
}
|
|
488
|
-
this._ownTurnIds.has(r) && !this._turnObservers.has(r) || (this._accumulateAndEmit(r, e), this._codec.isTerminal(n) && this._turnObservers.delete(r));
|
|
489
659
|
}
|
|
660
|
+
let n = this._tree.getNodeByCodecMessageId(e);
|
|
661
|
+
if (n) {
|
|
662
|
+
let t = this._codec.getMessages(n.projection).find((t) => t.codecMessageId === e);
|
|
663
|
+
if (t !== void 0) return {
|
|
664
|
+
hasSiblings: !1,
|
|
665
|
+
siblings: [t.message],
|
|
666
|
+
index: 0,
|
|
667
|
+
selected: t.message
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
return {
|
|
671
|
+
hasSiblings: !1,
|
|
672
|
+
siblings: [],
|
|
673
|
+
index: 0,
|
|
674
|
+
selected: void 0
|
|
675
|
+
};
|
|
490
676
|
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
_updateTurnObserverHeaders(e, t, n) {
|
|
496
|
-
let r = this._turnObservers.get(e);
|
|
497
|
-
r ? (Object.keys(t).length > 0 && Object.assign(r.headers, t), n !== void 0 && (r.serial = n)) : this._turnObservers.set(e, {
|
|
498
|
-
headers: { ...t },
|
|
499
|
-
serial: n,
|
|
500
|
-
accumulator: this._codec.createAccumulator()
|
|
677
|
+
selectSibling(e, t) {
|
|
678
|
+
this._logger.trace("DefaultView.selectSibling();", {
|
|
679
|
+
codecMessageId: e,
|
|
680
|
+
index: t
|
|
501
681
|
});
|
|
502
|
-
|
|
503
|
-
_accumulateAndEmit(e, t) {
|
|
504
|
-
let n = this._turnObservers.get(e);
|
|
682
|
+
let n = this._resolveMessageBranchPoint(e);
|
|
505
683
|
if (!n) return;
|
|
506
|
-
n.
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
684
|
+
let r = Math.max(0, Math.min(t, n.siblings.length - 1)), i = n.siblings[r];
|
|
685
|
+
i && (n.kind === "fork-of" ? (this._branchSelections.set(n.groupRoot, {
|
|
686
|
+
kind: "user",
|
|
687
|
+
selectedKey: N(i)
|
|
688
|
+
}), this._logger.debug("DefaultView.selectSibling(); fork-of", {
|
|
689
|
+
codecMessageId: e,
|
|
690
|
+
index: r,
|
|
691
|
+
selectedKey: N(i)
|
|
692
|
+
})) : (this._regenSelections.set(n.groupRoot, {
|
|
693
|
+
kind: "user",
|
|
694
|
+
selectedRunId: N(i)
|
|
695
|
+
}), this._logger.debug("DefaultView.selectSibling(); regenerate", {
|
|
696
|
+
codecMessageId: e,
|
|
697
|
+
index: r,
|
|
698
|
+
selectedRunId: N(i),
|
|
699
|
+
groupRoot: n.groupRoot
|
|
700
|
+
})), this._recomputeAndEmit());
|
|
701
|
+
}
|
|
702
|
+
_resolveSelectedIndex(e) {
|
|
703
|
+
if (e.kind === "fork-of") {
|
|
704
|
+
let t = this._branchSelections.get(e.groupRoot);
|
|
705
|
+
if (!t) return e.siblings.length - 1;
|
|
706
|
+
let n = e.siblings.findIndex((e) => N(e) === t.selectedKey);
|
|
707
|
+
return n === -1 ? e.siblings.length - 1 : n;
|
|
514
708
|
}
|
|
515
|
-
|
|
709
|
+
let t = this._regenSelections.get(e.groupRoot);
|
|
710
|
+
if (!t || t.kind === "pending") return e.siblings.length - 1;
|
|
711
|
+
let n = e.siblings.findIndex((e) => N(e) === t.selectedRunId);
|
|
712
|
+
return n === -1 ? e.siblings.length - 1 : n;
|
|
516
713
|
}
|
|
517
|
-
|
|
518
|
-
this.
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
714
|
+
_resolveMessageBranchPoint(e) {
|
|
715
|
+
let t = this._tree.getNodeByCodecMessageId(e);
|
|
716
|
+
if (!t) return;
|
|
717
|
+
if (t.kind === "input") {
|
|
718
|
+
let e = this._tree.getSiblingNodes(t.codecMessageId);
|
|
719
|
+
return e.length > 1 ? {
|
|
720
|
+
kind: "fork-of",
|
|
721
|
+
groupRoot: this._tree.getGroupRoot(t.codecMessageId),
|
|
722
|
+
siblings: e
|
|
723
|
+
} : void 0;
|
|
724
|
+
}
|
|
725
|
+
let n = this._tree.getSiblingNodes(t.runId);
|
|
726
|
+
if (n.length > 1 && this._codec.getMessages(t.projection).at(0)?.codecMessageId === e) return {
|
|
727
|
+
kind: "regen",
|
|
728
|
+
groupRoot: this._tree.getGroupRoot(t.runId),
|
|
729
|
+
siblings: n
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
async send(t, n) {
|
|
733
|
+
if (this._logger.trace("DefaultView.send();"), this._closed) throw new e.ErrorInfo("unable to send; view is closed", C.InvalidArgument, 400);
|
|
734
|
+
let r = de(t), i = this._lastVisibleMessagePairs.at(-1)?.codecMessageId, a = await this._sendDelegate(r, n, i);
|
|
735
|
+
return this._applyForkAutoSelect(a, n), a;
|
|
736
|
+
}
|
|
737
|
+
_applyForkAutoSelect(e, t) {
|
|
738
|
+
if (!t?.forkOf) return;
|
|
739
|
+
let n = e.optimisticCodecMessageIds.at(0);
|
|
740
|
+
if (n === void 0) return;
|
|
741
|
+
let r = this._tree.getGroupRoot(n);
|
|
742
|
+
this._branchSelections.set(r, {
|
|
743
|
+
kind: "auto",
|
|
744
|
+
selectedKey: n
|
|
745
|
+
}), this._recomputeAndEmit();
|
|
746
|
+
}
|
|
747
|
+
_applyRegenerateAutoSelect(e, t) {
|
|
748
|
+
let n = this._runByCodecMessageId(t);
|
|
749
|
+
if (!n) return;
|
|
750
|
+
let r = this._tree.getGroupRoot(n.runId);
|
|
751
|
+
this._regenSelections.set(r, {
|
|
752
|
+
kind: "pending",
|
|
753
|
+
carrierCodecMessageId: e.inputCodecMessageId
|
|
754
|
+
}), this._logger.debug("DefaultView._applyRegenerateAutoSelect(); deferring regenerate selection", {
|
|
755
|
+
anchorCodecMessageId: t,
|
|
756
|
+
groupRoot: r,
|
|
757
|
+
carrier: e.inputCodecMessageId
|
|
758
|
+
}), this._resolvePendingRegenSelections(), this._recomputeAndEmitIfChanged();
|
|
759
|
+
}
|
|
760
|
+
async regenerate(t, n) {
|
|
761
|
+
if (this._logger.trace("DefaultView.regenerate();", { messageId: t }), this._closed) throw new e.ErrorInfo("unable to regenerate; view is closed", C.InvalidArgument, 400);
|
|
762
|
+
let r = this._runByCodecMessageId(t);
|
|
763
|
+
if (!r) throw new e.ErrorInfo(`unable to regenerate; message not found in tree: ${t}`, C.InvalidArgument, 400);
|
|
764
|
+
let i = this._findParentMsgId(r, t);
|
|
765
|
+
if (!i) throw new e.ErrorInfo(`unable to regenerate; parent user message not found for ${t}`, C.InvalidArgument, 400);
|
|
766
|
+
let a = t;
|
|
767
|
+
r.regeneratesCodecMessageId !== void 0 && this._codec.getMessages(r.projection).at(0)?.codecMessageId === t && (a = r.regeneratesCodecMessageId);
|
|
768
|
+
let o = {
|
|
769
|
+
...n,
|
|
770
|
+
parent: i
|
|
771
|
+
}, s = this._codec.createRegenerate(a, i), c = await this._sendDelegate([s], o, i);
|
|
772
|
+
return this._applyRegenerateAutoSelect(c, a), c;
|
|
773
|
+
}
|
|
774
|
+
async edit(t, n, r) {
|
|
775
|
+
if (this._logger.trace("DefaultView.edit();", { messageId: t }), this._closed) throw new e.ErrorInfo("unable to edit; view is closed", C.InvalidArgument, 400);
|
|
776
|
+
let i = this._tree.getNodeByCodecMessageId(t);
|
|
777
|
+
if (!i) throw new e.ErrorInfo(`unable to edit; message not found in tree: ${t}`, C.InvalidArgument, 400);
|
|
778
|
+
let a = this._findParentMsgId(i, t);
|
|
779
|
+
return this.send(n, {
|
|
780
|
+
...r,
|
|
781
|
+
forkOf: t,
|
|
782
|
+
parent: a
|
|
523
783
|
});
|
|
524
784
|
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
else if (e.clientId) for (let [n, r] of this._turnClientIds) r === e.clientId && t.add(n);
|
|
536
|
-
else e.turnId && this._turnClientIds.has(e.turnId) && t.add(e.turnId);
|
|
537
|
-
return t;
|
|
785
|
+
_findParentMsgId(e, t) {
|
|
786
|
+
let n = this._lastVisibleMessagePairs, r = n.findIndex((e) => e.codecMessageId === t);
|
|
787
|
+
if (r > 0) return n[r - 1]?.codecMessageId;
|
|
788
|
+
if (r === 0) return;
|
|
789
|
+
let i = this._codec.getMessages(e.projection), a = i.findIndex((e) => e.codecMessageId === t);
|
|
790
|
+
if (a > 0) return i[a - 1]?.codecMessageId;
|
|
791
|
+
if (a === 0 && e.parentCodecMessageId !== void 0) {
|
|
792
|
+
let t = this._tree.getNodeByCodecMessageId(e.parentCodecMessageId);
|
|
793
|
+
if (t) return this._codec.getMessages(t.projection).at(-1)?.codecMessageId;
|
|
794
|
+
}
|
|
538
795
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
}
|
|
796
|
+
on(e, t) {
|
|
797
|
+
let n = t;
|
|
798
|
+
return this._emitter.on(e, n), () => {
|
|
799
|
+
this._emitter.off(e, n);
|
|
800
|
+
};
|
|
544
801
|
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
802
|
+
close() {
|
|
803
|
+
if (!this._closed) {
|
|
804
|
+
this._logger.info("DefaultView.close();"), this._closed = !0, this._loadingOlder = !1;
|
|
805
|
+
for (let e of this._unsubs) e();
|
|
806
|
+
this._unsubs.length = 0, this._emitter.off(), this._branchSelections.clear(), this._regenSelections.clear(), this._withheldRunIds.clear(), this._withheldBuffer.length = 0, this._onClose?.();
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
async _loadFirstPage(e) {
|
|
810
|
+
let t = e * fe, n = await H(this._channel, { limit: t }, this._logger);
|
|
811
|
+
this._closed || await this._revealFromPage(n, e);
|
|
812
|
+
}
|
|
813
|
+
async _revealFromPage(e, t) {
|
|
814
|
+
let n = new Set(this._treeVisibleNodes().map((e) => N(e))), { newVisible: r, lastPage: i } = await this._loadUntilVisible(e, t, n);
|
|
815
|
+
this._closed || (this._lastHistoryPage = i, this._hasMoreHistory = i.hasNext(), this._splitReveal(r, t));
|
|
816
|
+
}
|
|
817
|
+
_splitReveal(e, t) {
|
|
818
|
+
let n = 0, r = e.length;
|
|
819
|
+
for (let i = e.length - 1; i >= 0; i--) {
|
|
820
|
+
if (e[i]?.kind === "run") {
|
|
821
|
+
if (n === t) break;
|
|
822
|
+
n++;
|
|
823
|
+
}
|
|
824
|
+
r = i;
|
|
825
|
+
}
|
|
826
|
+
let i = e.slice(r), a = e.slice(0, r);
|
|
827
|
+
for (let e of a) this._withheldRunIds.add(N(e));
|
|
828
|
+
this._withheldBuffer.push(...a), this._releaseWithheld(i);
|
|
548
829
|
}
|
|
549
830
|
_processHistoryPage(e) {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
this.
|
|
831
|
+
this._processingHistory = !0;
|
|
832
|
+
try {
|
|
833
|
+
let t = this._codec.createDecoder();
|
|
834
|
+
for (let n of e.rawMessages) M(this._tree, t, n);
|
|
835
|
+
for (let t of e.rawMessages) this._tree.emitAblyMessage(t);
|
|
836
|
+
} finally {
|
|
837
|
+
this._processingHistory = !1;
|
|
553
838
|
}
|
|
554
|
-
this._emitter.emit("message"), e.rawMessages && e.rawMessages.length > 0 && (this._ablyMessages.unshift(...e.rawMessages), this._emitter.emit("ably-message"));
|
|
555
839
|
}
|
|
556
840
|
async _loadUntilVisible(e, t, n) {
|
|
557
841
|
this._processHistoryPage(e);
|
|
558
842
|
let r = e, i = () => {
|
|
559
843
|
let e = 0;
|
|
560
|
-
for (let t of this.
|
|
844
|
+
for (let t of this._treeVisibleNodes()) t.kind === "run" && !n.has(N(t)) && e++;
|
|
561
845
|
return e;
|
|
562
846
|
};
|
|
563
847
|
for (; i() < t && r.hasNext();) {
|
|
564
848
|
let e = await r.next();
|
|
565
|
-
if (!e) break;
|
|
849
|
+
if (!e || this._closed) break;
|
|
566
850
|
this._processHistoryPage(e), r = e;
|
|
567
851
|
}
|
|
568
852
|
return {
|
|
569
|
-
newVisible: this.
|
|
853
|
+
newVisible: this._treeVisibleNodes().filter((e) => !n.has(N(e))),
|
|
570
854
|
lastPage: r
|
|
571
855
|
};
|
|
572
856
|
}
|
|
573
857
|
_releaseWithheld(e) {
|
|
574
|
-
for (let t of e) this.
|
|
575
|
-
e.length > 0 && this.
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
this.
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
858
|
+
for (let t of e) this._withheldRunIds.delete(N(t));
|
|
859
|
+
e.length > 0 && this._recomputeAndEmit();
|
|
860
|
+
}
|
|
861
|
+
_updateVisibleSnapshot(e) {
|
|
862
|
+
let t = e ?? this._cachedNodes;
|
|
863
|
+
this._lastVisibleNodeKeys = t.map((e) => N(e)), this._lastVisibleNodeKeySet = new Set(this._lastVisibleNodeKeys), this._lastVisibleProjections = t.map((e) => e.projection), this._lastVisibleMessagePairs = this._extractMessages(t);
|
|
864
|
+
}
|
|
865
|
+
_onTreeUpdate() {
|
|
866
|
+
this._processingHistory || (this._pinBranchSelections(), this._resolvePendingRegenSelections(), this._recomputeAndEmitIfChanged());
|
|
867
|
+
}
|
|
868
|
+
_resolveSelections() {
|
|
869
|
+
let e = /* @__PURE__ */ new Map();
|
|
870
|
+
for (let [t, n] of this._branchSelections) e.set(t, n.selectedKey);
|
|
871
|
+
for (let [t, n] of this._regenSelections) n.kind !== "pending" && e.set(t, n.selectedRunId);
|
|
872
|
+
return e;
|
|
873
|
+
}
|
|
874
|
+
_treeVisibleNodes() {
|
|
875
|
+
return this._tree.visibleNodes(this._resolveSelections());
|
|
876
|
+
}
|
|
877
|
+
_pinBranchSelections() {
|
|
878
|
+
for (let e of this._lastVisibleNodeKeys) {
|
|
879
|
+
if (this._tree.getNode(e)?.kind !== "input" || this._tree.getSiblingNodes(e).length <= 1) continue;
|
|
880
|
+
let t = this._tree.getGroupRoot(e);
|
|
881
|
+
this._branchSelections.get(t) || this._branchSelections.set(t, {
|
|
882
|
+
kind: "pinned",
|
|
883
|
+
selectedKey: e
|
|
884
|
+
});
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
_resolvePendingRegenSelections() {
|
|
888
|
+
for (let [e, t] of this._regenSelections) {
|
|
889
|
+
if (t.kind === "user") continue;
|
|
890
|
+
let n = this._tree.getSiblingNodes(e).filter((e) => e.kind === "run");
|
|
891
|
+
if (n.length <= 1) continue;
|
|
892
|
+
let r = n.at(-1);
|
|
893
|
+
r && this._regenSelections.set(e, {
|
|
894
|
+
kind: "auto",
|
|
895
|
+
selectedRunId: r.runId
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
_onTreeAblyMessage(e) {
|
|
900
|
+
let t = D(e), n = t[m], r = t[d];
|
|
901
|
+
if (!n && !r) {
|
|
902
|
+
this._emitter.emit("ably-message", e);
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
r && this._lastVisibleNodeKeySet.has(r) && this._emitter.emit("ably-message", e);
|
|
906
|
+
}
|
|
907
|
+
_onTreeRun(e) {
|
|
908
|
+
if (this._lastVisibleNodeKeySet.has(e.runId)) {
|
|
909
|
+
this._emitter.emit("run", e);
|
|
910
|
+
return;
|
|
911
|
+
}
|
|
912
|
+
e.type === "start" && this._isRunStartVisible(e) && (this._lastVisibleNodeKeySet.add(e.runId), this._emitter.emit("run", e));
|
|
913
|
+
}
|
|
914
|
+
_isRunStartVisible(e) {
|
|
915
|
+
let { parent: t } = e;
|
|
916
|
+
if (t === void 0) return !0;
|
|
917
|
+
let n = this._tree.getNodeByCodecMessageId(t);
|
|
918
|
+
return n ? this._lastVisibleNodeKeySet.has(N(n)) : !0;
|
|
919
|
+
}
|
|
920
|
+
_visibleChanged(e) {
|
|
921
|
+
if (e.length !== this._lastVisibleNodeKeys.length) return !0;
|
|
922
|
+
for (let [t, n] of e.entries()) if (N(n) !== this._lastVisibleNodeKeys[t] || n.projection !== this._lastVisibleProjections[t]) return !0;
|
|
923
|
+
return !1;
|
|
924
|
+
}
|
|
925
|
+
}, W = (e) => new pe(e), me = () => {}, he = class {
|
|
926
|
+
constructor(e) {
|
|
927
|
+
this._views = /* @__PURE__ */ new Set(), this._state = "ready", this._pendingRunStarts = /* @__PURE__ */ new Map();
|
|
928
|
+
let t = ce(e.client, e.codec);
|
|
929
|
+
if (this._channel = e.client.channels.get(e.channelName, t), this._codec = e.codec, this._clientId = e.clientId, this._logger = (e.logger ?? ie({ logLevel: T.Silent })).withContext({ component: "ClientSession" }), this._emitter = new w(this._logger), this._hasAttachedOnce = this._channel.state === "attached", this._tree = R(this._codec, this._logger), this._view = W({
|
|
930
|
+
tree: this._tree,
|
|
931
|
+
channel: this._channel,
|
|
932
|
+
codec: this._codec,
|
|
933
|
+
sendDelegate: this._internalSend.bind(this),
|
|
934
|
+
logger: this._logger,
|
|
935
|
+
onClose: () => this._views.delete(this._view)
|
|
936
|
+
}), this._decoder = this._codec.createDecoder(), this._encoder = this._codec.createEncoder(this._channel, this._clientId === void 0 ? void 0 : { clientId: this._clientId }), this._views.add(this._view), this.tree = this._tree, this.view = this._view, e.messages) {
|
|
937
|
+
let t;
|
|
938
|
+
for (let n of e.messages) {
|
|
939
|
+
let e = crypto.randomUUID(), r = {
|
|
940
|
+
[m]: e,
|
|
941
|
+
[_]: "user"
|
|
942
|
+
};
|
|
943
|
+
t && (r[v] = t), this._tree.applyMessage({
|
|
944
|
+
inputs: [this._codec.createUserMessage(n)],
|
|
945
|
+
outputs: []
|
|
946
|
+
}, r), t = e;
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
this._onMessage = (e) => {
|
|
950
|
+
this._handleMessage(e);
|
|
951
|
+
}, this._onChannelStateChange = (e) => {
|
|
952
|
+
this._handleChannelStateChange(e);
|
|
953
|
+
}, this._channel.on(this._onChannelStateChange);
|
|
954
|
+
}
|
|
955
|
+
connect() {
|
|
956
|
+
return this._state === "closed" ? Promise.reject(new e.ErrorInfo("unable to connect; session is closed", C.SessionClosed, 400)) : this._connectPromise ? this._connectPromise : (this._logger.trace("DefaultClientSession.connect();"), this._connectPromise = this._channel.subscribe(this._onMessage).then(() => {
|
|
957
|
+
this._logger.debug("DefaultClientSession.connect(); subscribed and attached");
|
|
958
|
+
}, (t) => {
|
|
959
|
+
let n = new e.ErrorInfo(`unable to subscribe to channel; ${t instanceof Error ? t.message : String(t)}`, C.SessionSubscriptionError, 500, t instanceof e.ErrorInfo ? t : void 0);
|
|
960
|
+
throw this._logger.error("DefaultClientSession.connect(); subscribe failed"), this._emitter.emit("error", n), n;
|
|
961
|
+
}), this._connectPromise);
|
|
962
|
+
}
|
|
963
|
+
async _requireConnected(t) {
|
|
964
|
+
if (!this._connectPromise) throw new e.ErrorInfo(`unable to ${t}; connect() must be called before ${t}()`, C.InvalidArgument, 400);
|
|
965
|
+
return this._connectPromise;
|
|
966
|
+
}
|
|
967
|
+
_handleMessage(t) {
|
|
968
|
+
if (this._state !== "closed") try {
|
|
969
|
+
if (t.name === "ai-run-end") {
|
|
970
|
+
let n = D(t);
|
|
971
|
+
if ((n["run-reason"] ?? "complete") === "error") {
|
|
972
|
+
let t = n[S], r = t === void 0 ? NaN : Number(t), i = Number.isFinite(r) ? r : C.SessionSubscriptionError, a = n["error-message"] ?? "agent reported an error", o = i >= 1e4 && i < 6e4 ? Math.floor(i / 100) : 500, s = new e.ErrorInfo(a, i, o);
|
|
973
|
+
this._logger.error("ClientSession._handleMessage(); agent error received", {
|
|
974
|
+
runId: n[d],
|
|
975
|
+
invocationId: n[f],
|
|
976
|
+
code: i
|
|
977
|
+
}), this._emitter.emit("error", s);
|
|
590
978
|
}
|
|
591
979
|
}
|
|
980
|
+
let n = M(this._tree, this._decoder, t);
|
|
981
|
+
if (n && (n.type === "start" || n.type === "resume")) {
|
|
982
|
+
let e = D(t)[x];
|
|
983
|
+
if (e !== void 0) {
|
|
984
|
+
let t = this._pendingRunStarts.get(e);
|
|
985
|
+
t && (this._pendingRunStarts.delete(e), t.resolve(n.runId));
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
this._tree.emitAblyMessage(t);
|
|
989
|
+
} catch (t) {
|
|
990
|
+
let n = t instanceof e.ErrorInfo ? t : void 0;
|
|
991
|
+
this._emitter.emit("error", new e.ErrorInfo(`unable to process channel message; ${t instanceof Error ? t.message : String(t)}`, C.SessionSubscriptionError, 500, n));
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
_handleChannelStateChange(t) {
|
|
995
|
+
if (this._state === "closed") return;
|
|
996
|
+
let { current: n, resumed: r } = t;
|
|
997
|
+
if (n === "attached" && !this._hasAttachedOnce) {
|
|
998
|
+
this._hasAttachedOnce = !0;
|
|
999
|
+
return;
|
|
1000
|
+
}
|
|
1001
|
+
if (!(n === "failed" || n === "suspended" || n === "detached" || n === "attached" && !r)) return;
|
|
1002
|
+
this._logger.error("ClientSession._handleChannelStateChange(); channel continuity lost", {
|
|
1003
|
+
current: n,
|
|
1004
|
+
resumed: r,
|
|
1005
|
+
previous: t.previous
|
|
1006
|
+
});
|
|
1007
|
+
let i = new e.ErrorInfo(`unable to deliver events; channel continuity lost (${n}${n === "attached" ? ", resumed: false" : ""})`, C.ChannelContinuityLost, 500, t.reason);
|
|
1008
|
+
this._emitter.emit("error", i);
|
|
1009
|
+
}
|
|
1010
|
+
_cleanupFailedSend(e) {
|
|
1011
|
+
for (let t of e) {
|
|
1012
|
+
let e = this._tree.getNodeByCodecMessageId(t);
|
|
1013
|
+
e?.kind === "input" && e.serial === void 0 && this._tree.delete(e.codecMessageId);
|
|
592
1014
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
1015
|
+
}
|
|
1016
|
+
createView() {
|
|
1017
|
+
if (this._state === "closed") throw new e.ErrorInfo("unable to create view; session is closed", C.SessionClosed, 400);
|
|
1018
|
+
this._logger.trace("DefaultClientSession.createView();");
|
|
1019
|
+
let t = W({
|
|
1020
|
+
tree: this._tree,
|
|
1021
|
+
channel: this._channel,
|
|
1022
|
+
codec: this._codec,
|
|
1023
|
+
sendDelegate: this._internalSend.bind(this),
|
|
1024
|
+
logger: this._logger,
|
|
1025
|
+
onClose: () => this._views.delete(t)
|
|
1026
|
+
});
|
|
1027
|
+
return this._views.add(t), t;
|
|
1028
|
+
}
|
|
1029
|
+
async _internalSend(t, n, r) {
|
|
1030
|
+
if (this._state === "closed" || (await this._requireConnected("send"), this._state === "closed")) throw new e.ErrorInfo("unable to send; session is closed", C.SessionClosed, 400);
|
|
1031
|
+
let i = this._channel.state;
|
|
1032
|
+
if (i !== "attached" && i !== "attaching") throw new e.ErrorInfo(`unable to send; channel is ${i}`, C.ChannelNotReady, 400);
|
|
1033
|
+
this._logger.trace("ClientSession._internalSend();");
|
|
1034
|
+
let a = n?.runId !== void 0, o = n?.runId, s;
|
|
1035
|
+
n?.parent === void 0 && !n?.forkOf && (s = r);
|
|
1036
|
+
let c = /* @__PURE__ */ new Set(), l = [];
|
|
1037
|
+
for (let e of t) {
|
|
1038
|
+
let t = crypto.randomUUID(), r = e.codecMessageId ?? crypto.randomUUID();
|
|
1039
|
+
c.add(r);
|
|
1040
|
+
let i = e.kind !== "user-message" && (e.kind === "regenerate" || e.codecMessageId !== void 0), a = e.parent ?? (n?.parent === void 0 ? s : n.parent), u = n?.forkOf, d = e.kind === "regenerate" ? e.target : void 0, f = le({
|
|
598
1041
|
role: "user",
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
parent:
|
|
603
|
-
forkOf:
|
|
1042
|
+
runId: o,
|
|
1043
|
+
codecMessageId: r,
|
|
1044
|
+
runClientId: this._clientId,
|
|
1045
|
+
...a !== void 0 && { parent: a },
|
|
1046
|
+
...u !== void 0 && { forkOf: u },
|
|
1047
|
+
...d !== void 0 && { regenerates: d },
|
|
1048
|
+
inputEventId: t
|
|
604
1049
|
});
|
|
605
|
-
this.
|
|
606
|
-
|
|
607
|
-
[
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
headers:
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
let
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
"
|
|
633
|
-
...
|
|
1050
|
+
i || this._tree.applyMessage({
|
|
1051
|
+
inputs: [e],
|
|
1052
|
+
outputs: []
|
|
1053
|
+
}, f), l.push({
|
|
1054
|
+
input: e,
|
|
1055
|
+
codecMessageId: r,
|
|
1056
|
+
inputEventId: t,
|
|
1057
|
+
headers: f,
|
|
1058
|
+
isWireOnly: i
|
|
1059
|
+
}), !i && n?.parent === void 0 && !n?.forkOf && e.parent === void 0 && (s = r);
|
|
1060
|
+
}
|
|
1061
|
+
let u = l.at(-1);
|
|
1062
|
+
if (u === void 0) throw new e.ErrorInfo("unable to send; inputs array is empty (include at least one input)", C.InvalidArgument, 400);
|
|
1063
|
+
let d = u.inputEventId, f = u.codecMessageId, p = new Promise((e, t) => {
|
|
1064
|
+
this._pendingRunStarts.set(f, {
|
|
1065
|
+
resolve: e,
|
|
1066
|
+
reject: t
|
|
1067
|
+
});
|
|
1068
|
+
});
|
|
1069
|
+
return p.catch(() => {}), await (async () => {
|
|
1070
|
+
try {
|
|
1071
|
+
for (let e of l) await this._encoder.publishInput(e.input, {
|
|
1072
|
+
extras: { headers: e.headers },
|
|
1073
|
+
messageId: e.codecMessageId,
|
|
1074
|
+
...this._clientId !== void 0 && { clientId: this._clientId }
|
|
1075
|
+
});
|
|
1076
|
+
} catch (t) {
|
|
1077
|
+
let n = t instanceof e.ErrorInfo ? t : void 0, r = n?.statusCode === 401 || n?.statusCode === 403, i = new e.ErrorInfo(r ? "unable to publish events; missing publish capability on the channel" : `unable to publish events; ${t instanceof Error ? t.message : String(t)}`, r ? C.InsufficientCapability : C.SessionSendFailed, r ? 401 : 500, n);
|
|
1078
|
+
throw this._emitter.emit("error", i), this._pendingRunStarts.delete(f), a || this._cleanupFailedSend([...c]), i;
|
|
1079
|
+
}
|
|
1080
|
+
})(), {
|
|
1081
|
+
inputCodecMessageId: f,
|
|
1082
|
+
runId: p,
|
|
1083
|
+
inputEventId: d,
|
|
1084
|
+
cancel: async () => {
|
|
1085
|
+
await this._publishCancel({
|
|
1086
|
+
inputCodecMessageId: f,
|
|
1087
|
+
...o !== void 0 && { runId: o }
|
|
1088
|
+
});
|
|
634
1089
|
},
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
let t = e instanceof i.ErrorInfo ? e : void 0;
|
|
641
|
-
this._emitter.emit("error", new i.ErrorInfo(`unable to send; HTTP POST to ${this._api} failed: ${e instanceof Error ? e.message : String(e)}`, b.TransportSendFailed, 500, t)), this._router.closeStream(r);
|
|
642
|
-
}), {
|
|
643
|
-
stream: f,
|
|
644
|
-
turnId: r,
|
|
645
|
-
cancel: async () => this.cancel({ turnId: r })
|
|
1090
|
+
optimisticCodecMessageIds: [...c],
|
|
1091
|
+
toInvocation: () => ue.fromJSON({
|
|
1092
|
+
inputEventId: d,
|
|
1093
|
+
sessionName: this._channel.name
|
|
1094
|
+
})
|
|
646
1095
|
};
|
|
647
1096
|
}
|
|
648
|
-
async
|
|
649
|
-
this.
|
|
650
|
-
let n = this._tree.getNode(e)?.parentId;
|
|
651
|
-
return this.send([], {
|
|
652
|
-
...t,
|
|
653
|
-
body: {
|
|
654
|
-
history: this._getHistoryBefore(e),
|
|
655
|
-
...t?.body
|
|
656
|
-
},
|
|
657
|
-
forkOf: e,
|
|
658
|
-
parent: n
|
|
659
|
-
});
|
|
1097
|
+
async cancel(e) {
|
|
1098
|
+
return this._publishCancel({ runId: e });
|
|
660
1099
|
}
|
|
661
|
-
async
|
|
662
|
-
this.
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
body: {
|
|
667
|
-
history: this._getHistoryBefore(e),
|
|
668
|
-
...n?.body
|
|
669
|
-
},
|
|
670
|
-
forkOf: e,
|
|
671
|
-
parent: r
|
|
1100
|
+
async _publishCancel(e) {
|
|
1101
|
+
if (this._state === "closed" || (await this._requireConnected("cancel"), this._state === "closed")) return;
|
|
1102
|
+
this._logger.debug("ClientSession._publishCancel();", {
|
|
1103
|
+
runId: e.runId,
|
|
1104
|
+
inputCodecMessageId: e.inputCodecMessageId
|
|
672
1105
|
});
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
this._logger.debug("ClientTransport.cancel();", { filter: t }), await this._publishCancel(t), this._closeMatchingTurnStreams(t);
|
|
678
|
-
}
|
|
679
|
-
async waitForTurn(e) {
|
|
680
|
-
if (this._closed) return;
|
|
681
|
-
let t = e ?? { own: !0 }, n = this._getMatchingTurnIds(t);
|
|
682
|
-
if (n.size !== 0) return this._logger.debug("ClientTransport.waitForTurn();", { turnIds: [...n] }), new Promise((e) => {
|
|
683
|
-
let t = (r) => {
|
|
684
|
-
r.type === "x-ably-turn-end" && (n.delete(r.turnId), n.size === 0 && (this._emitter.off("turn", t), e()));
|
|
685
|
-
};
|
|
686
|
-
this._emitter.on("turn", t);
|
|
1106
|
+
let t = { [p]: crypto.randomUUID() };
|
|
1107
|
+
e.runId !== void 0 && (t[d] = e.runId), e.inputCodecMessageId !== void 0 && (t[x] = e.inputCodecMessageId), await this._channel.publish({
|
|
1108
|
+
name: ee,
|
|
1109
|
+
extras: { ai: { transport: t } }
|
|
687
1110
|
});
|
|
688
1111
|
}
|
|
689
1112
|
on(e, t) {
|
|
690
|
-
if (this.
|
|
1113
|
+
if (this._state === "closed") return me;
|
|
691
1114
|
let n = t;
|
|
692
1115
|
return this._emitter.on(e, n), () => {
|
|
693
1116
|
this._emitter.off(e, n);
|
|
694
1117
|
};
|
|
695
1118
|
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
1119
|
+
async close() {
|
|
1120
|
+
if (this._state !== "closed") {
|
|
1121
|
+
this._state = "closed", this._logger.info("ClientSession.close();"), this._connectPromise && this._channel.unsubscribe(this._onMessage), this._channel.off(this._onChannelStateChange), this._emitter.off();
|
|
1122
|
+
for (let e of this._views) e.close();
|
|
1123
|
+
if (this._views.clear(), this._pendingRunStarts.size > 0) {
|
|
1124
|
+
let t = new e.ErrorInfo("unable to await run-start; session closed", C.SessionClosed, 400);
|
|
1125
|
+
for (let e of this._pendingRunStarts.values()) e.reject(t);
|
|
1126
|
+
this._pendingRunStarts.clear();
|
|
1127
|
+
}
|
|
1128
|
+
try {
|
|
1129
|
+
await this._encoder.close();
|
|
1130
|
+
} catch {}
|
|
1131
|
+
if (this._connectPromise) try {
|
|
1132
|
+
await this._channel.detach();
|
|
1133
|
+
} catch (e) {
|
|
1134
|
+
this._logger.debug("ClientSession.close(); channel detach failed", { error: e });
|
|
1135
|
+
}
|
|
704
1136
|
}
|
|
705
|
-
return e;
|
|
706
1137
|
}
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
1138
|
+
}, ge = (e) => new he(e), G = n({
|
|
1139
|
+
nearest: void 0,
|
|
1140
|
+
providers: {}
|
|
1141
|
+
}), K = ({ children: n, ...r }) => {
|
|
1142
|
+
let c = t(), { channelName: u } = r, d = s(void 0), f = s(u), p = s([]), m = s(!1), h = s(void 0);
|
|
1143
|
+
if (!(d.current || h.current) || f.current !== u) {
|
|
1144
|
+
f.current = u, d.current && p.current.push(d.current);
|
|
1145
|
+
try {
|
|
1146
|
+
d.current = ge({
|
|
1147
|
+
...r,
|
|
1148
|
+
client: c
|
|
1149
|
+
}), h.current = void 0;
|
|
1150
|
+
} catch (t) {
|
|
1151
|
+
d.current = void 0, h.current = t instanceof e.ErrorInfo ? t : new e.ErrorInfo("Unknown error while creating client session", C.BadRequest, 400);
|
|
1152
|
+
}
|
|
710
1153
|
}
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
for (let e of
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
1154
|
+
let g = i(G), _ = d.current, v = h.current, y = o(() => ({
|
|
1155
|
+
session: _,
|
|
1156
|
+
sessionError: v
|
|
1157
|
+
}), [_, v]), b = o(() => ({
|
|
1158
|
+
nearest: y,
|
|
1159
|
+
providers: {
|
|
1160
|
+
...g.providers,
|
|
1161
|
+
[u]: y
|
|
1162
|
+
}
|
|
1163
|
+
}), [
|
|
1164
|
+
u,
|
|
1165
|
+
g,
|
|
1166
|
+
y
|
|
1167
|
+
]);
|
|
1168
|
+
return a(() => () => {
|
|
1169
|
+
for (let e of p.current) e.close();
|
|
1170
|
+
}, [u]), a(() => {
|
|
1171
|
+
d.current?.connect();
|
|
1172
|
+
}, [u]), a(() => (m.current = !1, () => {
|
|
1173
|
+
m.current = !0, Promise.resolve().then(() => {
|
|
1174
|
+
m.current && d.current?.close();
|
|
1175
|
+
});
|
|
1176
|
+
}), []), /* @__PURE__ */ l(G.Provider, {
|
|
1177
|
+
value: b,
|
|
1178
|
+
children: n
|
|
1179
|
+
});
|
|
1180
|
+
}, q = ({ session: e, skip: t } = {}) => {
|
|
1181
|
+
let { nearest: n } = i(G), r = n?.session;
|
|
1182
|
+
if (!t && e !== null) return e ?? r;
|
|
1183
|
+
}, J = ({ session: e, skip: t } = {}) => {
|
|
1184
|
+
let n = q({
|
|
1185
|
+
session: e,
|
|
1186
|
+
skip: t
|
|
1187
|
+
}), [r, i] = c([]), o = s([]);
|
|
1188
|
+
return a(() => {
|
|
1189
|
+
if (o.current = [], i([]), n) return n.tree.on("ably-message", (e) => {
|
|
1190
|
+
let t = [...o.current, e];
|
|
1191
|
+
o.current = t, i(t);
|
|
749
1192
|
});
|
|
750
|
-
|
|
1193
|
+
}, [n]), r;
|
|
1194
|
+
}, Y = {
|
|
1195
|
+
get tree() {
|
|
1196
|
+
throw new e.ErrorInfo("unable to access tree; hook is skipped", C.InvalidArgument, 400);
|
|
1197
|
+
},
|
|
1198
|
+
get view() {
|
|
1199
|
+
throw new e.ErrorInfo("unable to access view; hook is skipped", C.InvalidArgument, 400);
|
|
1200
|
+
},
|
|
1201
|
+
connect: () => {
|
|
1202
|
+
throw new e.ErrorInfo("unable to connect; hook is skipped", C.InvalidArgument, 400);
|
|
1203
|
+
},
|
|
1204
|
+
createView: () => {
|
|
1205
|
+
throw new e.ErrorInfo("unable to create view; hook is skipped", C.InvalidArgument, 400);
|
|
1206
|
+
},
|
|
1207
|
+
cancel: () => {
|
|
1208
|
+
throw new e.ErrorInfo("unable to cancel; hook is skipped", C.InvalidArgument, 400);
|
|
1209
|
+
},
|
|
1210
|
+
on: () => {
|
|
1211
|
+
throw new e.ErrorInfo("unable to subscribe; hook is skipped", C.InvalidArgument, 400);
|
|
1212
|
+
},
|
|
1213
|
+
close: () => {
|
|
1214
|
+
throw new e.ErrorInfo("unable to close; hook is skipped", C.InvalidArgument, 400);
|
|
1215
|
+
}
|
|
1216
|
+
}, X = ({ channelName: t, skip: n, onError: r } = {}) => {
|
|
1217
|
+
let { nearest: o, providers: c } = i(G), l = s(r);
|
|
1218
|
+
l.current = r;
|
|
1219
|
+
let u = n ? void 0 : t === void 0 ? o?.session : c[t]?.session;
|
|
1220
|
+
if (a(() => {
|
|
1221
|
+
if (u) return u.on("error", (e) => {
|
|
1222
|
+
l.current?.(e);
|
|
1223
|
+
});
|
|
1224
|
+
}, [u]), n) return { session: Y };
|
|
1225
|
+
if (t !== void 0) {
|
|
1226
|
+
let n = c[t];
|
|
1227
|
+
return n ? n.session ? { session: n.session } : {
|
|
1228
|
+
session: Y,
|
|
1229
|
+
sessionError: n.sessionError
|
|
1230
|
+
} : {
|
|
1231
|
+
session: Y,
|
|
1232
|
+
sessionError: new e.ErrorInfo(`unable to use session; no ClientSessionProvider found for channelName "${t}"`, C.BadRequest, 400)
|
|
1233
|
+
};
|
|
751
1234
|
}
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
this._closeMatchingTurnStreams(e.cancel);
|
|
759
|
-
}
|
|
760
|
-
this._channel.unsubscribe(this._onMessage);
|
|
761
|
-
for (let e of this._ownTurnIds) this._router.closeStream(e);
|
|
762
|
-
this._turnObservers.clear(), this._emitter.off(), this._ownTurnIds.clear(), this._ownMsgIds.clear(), this._turnMsgIds.clear(), this._turnClientIds.clear(), this._withheldKeys.clear(), this._ablyMessages.length = 0;
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
}, H = (e) => new V(e), U = (e) => {
|
|
766
|
-
let t = n(null);
|
|
767
|
-
return t.current === null && (t.current = H(e)), t.current;
|
|
768
|
-
}, W = (n) => {
|
|
769
|
-
let [i, a] = r(() => n.getMessages());
|
|
770
|
-
return t(() => (a(n.getMessages()), n.on("message", () => {
|
|
771
|
-
a(n.getMessages());
|
|
772
|
-
})), [n]), {
|
|
773
|
-
messages: i,
|
|
774
|
-
getSiblings: e((e) => n.getTree().getSiblings(e), [n]),
|
|
775
|
-
hasSiblings: e((e) => n.getTree().hasSiblings(e), [n]),
|
|
776
|
-
getSelectedIndex: e((e) => n.getTree().getSelectedIndex(e), [n]),
|
|
777
|
-
selectSibling: e((e, t) => {
|
|
778
|
-
n.getTree().select(e, t), a(n.getMessages());
|
|
779
|
-
}, [n])
|
|
1235
|
+
return o ? o.session ? { session: o.session } : {
|
|
1236
|
+
session: Y,
|
|
1237
|
+
sessionError: o.sessionError
|
|
1238
|
+
} : {
|
|
1239
|
+
session: Y,
|
|
1240
|
+
sessionError: new e.ErrorInfo("unable to use session; no ClientSessionProvider found in the tree", C.BadRequest, 400)
|
|
780
1241
|
};
|
|
781
|
-
},
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
1242
|
+
}, _e = {
|
|
1243
|
+
hasSiblings: !1,
|
|
1244
|
+
siblings: [],
|
|
1245
|
+
index: 0,
|
|
1246
|
+
selected: void 0
|
|
1247
|
+
}, Z = ({ session: t, view: n, limit: i, skip: o } = {}) => {
|
|
1248
|
+
let l = q({
|
|
1249
|
+
session: t,
|
|
1250
|
+
skip: o
|
|
1251
|
+
}), u = o ? void 0 : n ?? l?.view, [d, f] = c(() => u?.getMessages() ?? []), [p, m] = c(() => u?.hasOlder() ?? !1), [h, g] = c(!1), [_, v] = c(), y = s(!1), b = i !== void 0, x = s(!1);
|
|
1252
|
+
a(() => {
|
|
1253
|
+
if (!u) {
|
|
1254
|
+
f([]), m(!1), v(void 0);
|
|
1255
|
+
return;
|
|
793
1256
|
}
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
1257
|
+
return x.current = !1, f(u.getMessages()), m(u.hasOlder()), v(void 0), u.on("update", () => {
|
|
1258
|
+
f(u.getMessages()), m(u.hasOlder());
|
|
1259
|
+
});
|
|
1260
|
+
}, [u]);
|
|
1261
|
+
let S = r(async () => {
|
|
1262
|
+
if (!(!u || y.current)) {
|
|
1263
|
+
y.current = !0, g(!0);
|
|
798
1264
|
try {
|
|
799
|
-
|
|
800
|
-
|
|
1265
|
+
await u.loadOlder(i), v(void 0);
|
|
1266
|
+
} catch (t) {
|
|
1267
|
+
t instanceof e.ErrorInfo ? v(t) : v(new e.ErrorInfo("Unknown error loading older messages", C.BadRequest, 400));
|
|
801
1268
|
} finally {
|
|
802
|
-
|
|
1269
|
+
y.current = !1, g(!1);
|
|
803
1270
|
}
|
|
804
1271
|
}
|
|
805
|
-
}, [
|
|
806
|
-
return
|
|
807
|
-
!
|
|
808
|
-
}, [
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
1272
|
+
}, [u, i]);
|
|
1273
|
+
return a(() => {
|
|
1274
|
+
!b || x.current || !u || (x.current = !0, S());
|
|
1275
|
+
}, [
|
|
1276
|
+
b,
|
|
1277
|
+
u,
|
|
1278
|
+
S
|
|
1279
|
+
]), {
|
|
1280
|
+
messages: d,
|
|
1281
|
+
hasOlder: p,
|
|
1282
|
+
loading: h,
|
|
1283
|
+
loadError: _,
|
|
1284
|
+
loadOlder: S,
|
|
1285
|
+
runOf: r((e) => u?.runOf(e), [u]),
|
|
1286
|
+
run: r((e) => u?.run(e), [u]),
|
|
1287
|
+
runs: r(() => u?.runs() ?? [], [u]),
|
|
1288
|
+
branchSelection: r((e) => u?.branchSelection(e) ?? _e, [u]),
|
|
1289
|
+
selectSibling: r((e, t) => {
|
|
1290
|
+
u?.selectSibling(e, t);
|
|
1291
|
+
}, [u]),
|
|
1292
|
+
send: r(async (t, n) => {
|
|
1293
|
+
if (!u) throw new e.ErrorInfo("unable to send; view is not available", C.InvalidArgument, 400);
|
|
1294
|
+
return u.send(t, n);
|
|
1295
|
+
}, [u]),
|
|
1296
|
+
regenerate: r(async (t, n) => {
|
|
1297
|
+
if (!u) throw new e.ErrorInfo("unable to regenerate; view is not available", C.InvalidArgument, 400);
|
|
1298
|
+
return u.regenerate(t, n);
|
|
1299
|
+
}, [u]),
|
|
1300
|
+
edit: r(async (t, n, r) => {
|
|
1301
|
+
if (!u) throw new e.ErrorInfo("unable to edit; view is not available", C.InvalidArgument, 400);
|
|
1302
|
+
return u.edit(t, n, r);
|
|
1303
|
+
}, [u])
|
|
1304
|
+
};
|
|
1305
|
+
}, Q = ({ session: e, limit: t, skip: n } = {}) => {
|
|
1306
|
+
let r = q({
|
|
1307
|
+
session: e,
|
|
1308
|
+
skip: n
|
|
1309
|
+
}), [i, o] = c();
|
|
1310
|
+
return a(() => {
|
|
1311
|
+
if (!r) {
|
|
1312
|
+
o(void 0);
|
|
1313
|
+
return;
|
|
1314
|
+
}
|
|
1315
|
+
let e = r.createView();
|
|
1316
|
+
return o(e), () => {
|
|
1317
|
+
e.close();
|
|
1318
|
+
};
|
|
1319
|
+
}, [r]), Z({
|
|
1320
|
+
view: i,
|
|
1321
|
+
limit: t,
|
|
1322
|
+
skip: n
|
|
1323
|
+
});
|
|
1324
|
+
}, $ = ({ session: e } = {}) => {
|
|
1325
|
+
let t = q({ session: e });
|
|
1326
|
+
return {
|
|
1327
|
+
getRunNode: r((e) => t?.tree.getRunNode(e), [t]),
|
|
1328
|
+
getNodeByCodecMessageId: r((e) => t?.tree.getNodeByCodecMessageId(e), [t]),
|
|
1329
|
+
getSiblingNodes: r((e) => t?.tree.getSiblingNodes(e) ?? [], [t])
|
|
813
1330
|
};
|
|
814
|
-
},
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
1331
|
+
}, ve = () => ({
|
|
1332
|
+
ClientSessionProvider: K,
|
|
1333
|
+
useClientSession: (e) => X(e ?? {}),
|
|
1334
|
+
useView: (e) => Z(e ?? {}),
|
|
1335
|
+
useTree: (e) => $(e ?? {}),
|
|
1336
|
+
useAblyMessages: (e) => J(e ?? {}),
|
|
1337
|
+
useCreateView: (e) => Q(e ?? {})
|
|
1338
|
+
});
|
|
820
1339
|
//#endregion
|
|
821
|
-
export {
|
|
1340
|
+
export { K as ClientSessionProvider, ve as createSessionHooks, J as useAblyMessages, X as useClientSession, Q as useCreateView, $ as useTree, Z as useView };
|
|
822
1341
|
|
|
823
1342
|
//# sourceMappingURL=ably-ai-transport-react.js.map
|